Skip to content

Commit e18ab21

Browse files
committed
feat: single column mode
1 parent fd04ef3 commit e18ab21

42 files changed

Lines changed: 8597 additions & 8361 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 8113 additions & 8182 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
11
{
2-
"name": "lineage",
3-
"version": "0.7.0-beta",
4-
"description": "",
5-
"scripts": {
6-
"dev": "node esbuild.config.mjs",
7-
"build": "tsc -noEmit -skipLibCheck && svelte-check --workspace src && node esbuild.config.mjs production",
8-
"version": "node version-bump.mjs && git add manifest.json versions.json",
9-
"test:watch": "vitest",
10-
"test": "vitest run",
11-
"test:e2e": "playwright test",
12-
"prepare": "husky install"
13-
},
14-
"keywords": [],
15-
"author": "",
16-
"license": "MIT",
17-
"devDependencies": {
18-
"@codemirror/language": "6.9.1",
19-
"@commitlint/cli": "17.4.0",
20-
"@commitlint/config-conventional": "17.4.0",
21-
"@playwright/test": "1.42.1",
22-
"@tsconfig/svelte": "5.0.2",
23-
"@types/electron": "1.6.10",
24-
"@types/node": "20.11.24",
25-
"@types/uniqid": "5.3.4",
26-
"@typescript-eslint/eslint-plugin": "7.1.0",
27-
"@typescript-eslint/parser": "7.1.0",
28-
"builtin-modules": "3.3.0",
29-
"classnames": "2.5.1",
30-
"dotenv": "16.4.5",
31-
"esbuild": "0.20.1",
32-
"esbuild-plugin-inline-worker": "0.1.1",
33-
"esbuild-svelte": "0.8.0",
34-
"eslint": "8.57.0",
35-
"eslint-plugin-svelte": "2.35.1",
36-
"fuse.js": "7.0.0",
37-
"husky": "8.0.3",
38-
"jsdom": "24.0.0",
39-
"lint-staged": "13.3.0",
40-
"lucide-svelte": "0.344.0",
41-
"monkey-around": "3.0.0",
42-
"nanoid": "5.0.6",
43-
"obsidian": "1.5.7-1",
44-
"prettier": "3.2.5",
45-
"prettier-plugin-svelte": "3.2.2",
46-
"svelte": "4.2.12",
47-
"svelte-check": "3.6.7",
48-
"svelte-eslint-parser": "0.33.1",
49-
"svelte-preprocess": "5.1.3",
50-
"tiny-invariant": "1.3.3",
51-
"tslib": "2.6.2",
52-
"typescript": "5.3.3",
53-
"vitest": "1.3.1",
54-
"@types/diff": "^5.2.1",
55-
"diff": "^5.2.0"
56-
}
2+
"name": "lineage",
3+
"version": "0.7.0-beta",
4+
"description": "",
5+
"scripts": {
6+
"dev": "node esbuild.config.mjs",
7+
"build": "tsc -noEmit -skipLibCheck && svelte-check --workspace src && node esbuild.config.mjs production",
8+
"version": "node version-bump.mjs && git add manifest.json versions.json",
9+
"test:watch": "vitest",
10+
"test": "vitest run",
11+
"test:e2e": "playwright test",
12+
"prepare": "husky install"
13+
},
14+
"keywords": [],
15+
"author": "",
16+
"license": "MIT",
17+
"devDependencies": {
18+
"@commitlint/cli": "17.4.0",
19+
"@commitlint/config-conventional": "17.4.0",
20+
"@playwright/test": "1.42.1",
21+
"@tsconfig/svelte": "5.0.2",
22+
"@types/diff": "5.2.1",
23+
"@types/electron": "1.6.10",
24+
"@types/node": "20.11.24",
25+
"@types/uniqid": "5.3.4",
26+
"@typescript-eslint/eslint-plugin": "7.1.0",
27+
"@typescript-eslint/parser": "7.1.0",
28+
"builtin-modules": "3.3.0",
29+
"dotenv": "16.4.5",
30+
"esbuild": "0.20.1",
31+
"esbuild-plugin-inline-worker": "0.1.1",
32+
"esbuild-svelte": "0.8.0",
33+
"eslint": "8.57.0",
34+
"eslint-plugin-svelte": "2.35.1",
35+
"husky": "8.0.3",
36+
"jsdom": "24.0.0",
37+
"lint-staged": "13.3.0",
38+
"prettier": "3.2.5",
39+
"prettier-plugin-svelte": "3.2.2",
40+
"svelte": "4.2.12",
41+
"svelte-check": "3.6.7",
42+
"svelte-eslint-parser": "0.33.1",
43+
"svelte-preprocess": "5.1.3",
44+
"tslib": "2.6.2",
45+
"typescript": "5.3.3",
46+
"vitest": "1.3.1"
47+
},
48+
"dependencies": {
49+
"classnames": "2.5.1",
50+
"diff": "5.2.0",
51+
"fuse.js": "7.0.0",
52+
"lucide-svelte": "0.344.0",
53+
"monkey-around": "3.0.0",
54+
"nanoid": "5.0.6",
55+
"obsidian": "1.7.2",
56+
"tiny-invariant": "1.3.3"
57+
}
5758
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Column } from 'src/stores/document/document-state-type';
2+
3+
/** maps an array of columns into a single nodes array that is sorted logically (1, 1.1, 2 ...) */
4+
export const sortTreeNodes = (columns: Column[]): string[] => {
5+
const sortedNodes: string[] = [];
6+
const stack: { nodeId: string; columnIndex: number }[] = [];
7+
8+
for (const group of columns[0].groups) {
9+
for (let i = group.nodes.length - 1; i >= 0; i--) {
10+
stack.push({ nodeId: group.nodes[i], columnIndex: 0 });
11+
}
12+
}
13+
14+
while (stack.length > 0) {
15+
const item = stack.pop()!;
16+
sortedNodes.push(item.nodeId);
17+
18+
if (item.columnIndex + 1 < columns.length) {
19+
const nextColumn = columns[item.columnIndex + 1];
20+
for (const group of nextColumn.groups) {
21+
if (group.parentId === item.nodeId) {
22+
for (let i = group.nodes.length - 1; i >= 0; i--) {
23+
stack.push({
24+
nodeId: group.nodes[i],
25+
columnIndex: item.columnIndex + 1,
26+
});
27+
}
28+
}
29+
}
30+
}
31+
}
32+
33+
return sortedNodes;
34+
};

src/obsidian/commands/add-commands.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,19 @@ const createCommands = (plugin: Lineage) => {
192192
});
193193
},
194194
});
195-
195+
commands.push({
196+
name: 'Toggle single column mode',
197+
icon: 'rectangle-vertical',
198+
checkCallback: (checking) => {
199+
const view = getActiveLineageView(plugin);
200+
if (checking) {
201+
return Boolean(view);
202+
}
203+
view!.plugin.settings.dispatch({
204+
type: 'settings/view/modes/toggle-single-column',
205+
});
206+
},
207+
});
196208
return commands;
197209
};
198210

src/obsidian/patches/set-view-state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export function setViewState(next: (...params: unknown[]) => unknown) {
99
const path = state?.state?.file;
1010
if (
1111
isMarkdownView &&
12+
// @ts-ignore
1213
fileViewTypeCache[path]?.viewType === LINEAGE_VIEW_TYPE &&
14+
// @ts-ignore
1315
!state.state.inlineEditor
1416
) {
1517
const newState = {

src/stores/document/derived/columns-store.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ import { derived } from 'src/lib/store/derived';
33

44
export const columnsStore = (view: LineageView) =>
55
derived(view.documentStore, (state) => state.document.columns);
6+
7+
export const singleColumnStore = (view: LineageView) =>
8+
derived(view.documentStore, (state) => {
9+
return [state.document.columns[0]];
10+
});

src/stores/document/derived/groups-store.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ export const groupsStore = (view: LineageView, columnId: string) => {
1818
return column.groups;
1919
});
2020
};
21+
22+
export const singleColumnGroupStore = (view: LineageView) => {
23+
return derived(view.documentStore, (state) => {
24+
return state.document.columns[0].groups;
25+
});
26+
};

src/stores/document/derived/nodes-store.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { LineageView } from 'src/view/view';
22
import { derived } from 'src/lib/store/derived';
33
import { Column, NodeGroup } from 'src/stores/document/document-state-type';
44
import { findColumn } from 'src/stores/document/derived/groups-store';
5+
import { sortTreeNodes } from 'src/lib/tree-utils/sort/sort-tree-nodes';
56

67
export const findGroup = (
78
columns: Column[],
@@ -30,3 +31,9 @@ export const nodesStore = (
3031
return group.nodes;
3132
});
3233
};
34+
35+
export const singleColumnNodesStore = (view: LineageView) => {
36+
return derived(view.documentStore, (state) => {
37+
return sortTreeNodes(state.document.columns);
38+
});
39+
};

src/stores/settings/default-settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Settings } from './settings-type';
33
export const DEFAULT_CARD_WIDTH = 550;
44
export const DEFAULT_COLUMNS_GAP = 150;
55
export const DEFAULT_CARDS_GAP = 150;
6+
export const DEFAULT_INDENTATION_WIDTH = 60;
67
export const DEFAULT_SETTINGS = (): Settings => ({
78
documents: {},
89
hotkeys: {
@@ -25,6 +26,8 @@ export const DEFAULT_SETTINGS = (): Settings => ({
2526
leftSidebarWidth: 500,
2627
leftSidebarActiveTab: 'pinned-cards',
2728
applyGapBetweenCards: false,
29+
singleColumnMode: false,
30+
nodeIndentationWidth: DEFAULT_INDENTATION_WIDTH,
2831
},
2932
general: {
3033
defaultDocumentFormat: 'sections',

src/stores/settings/derived/view-settings-store.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ export const LeftSidebarActiveTabStore = (view: LineageView) =>
1515

1616
export const ApplyGapBetweenCardsStore = (view: LineageView) =>
1717
derived(view.plugin.settings, (state) => state.view.applyGapBetweenCards);
18+
19+
export const SingleColumnMode = (view: LineageView) =>
20+
derived(view.plugin.settings, (state) => state.view.singleColumnMode);

0 commit comments

Comments
 (0)