From 0ccf91721d71060808c0a21c67b8ce885cae51a1 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sat, 18 Jan 2025 19:12:50 +0100 Subject: [PATCH 1/8] test(services/data_dir): simplify getPlatformAppDataDir use the new available mocks to make tests a tiny bit more simpler :-) --- spec-es6/data_dir.spec.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/spec-es6/data_dir.spec.ts b/spec-es6/data_dir.spec.ts index ded078cb8..57abac8d3 100644 --- a/spec-es6/data_dir.spec.ts +++ b/spec-es6/data_dir.spec.ts @@ -61,27 +61,28 @@ describe("data_dir.ts unit tests", async () => { }; describe("#getPlatformAppDataDir()", () => { - type TestCaseGetPlatformAppDataDir = [description: string, fnValue: Parameters, expectedValueFn: (val: ReturnType) => boolean]; + type TestCaseGetPlatformAppDataDir = [description: string, fnValue: Parameters, expectedValue: string | null, osHomedirMockValue: string | null]; + const testCases: TestCaseGetPlatformAppDataDir[] = [ - ["w/ unsupported OS it should return 'null'", ["aix", undefined], (val) => val === null], + ["w/ unsupported OS it should return 'null'", ["aix", undefined], null, null], - ["w/ win32 and no APPDATA set it should return 'null'", ["win32", undefined], (val) => val === null], + ["w/ win32 and no APPDATA set it should return 'null'", ["win32", undefined], null, null], - ["w/ win32 and set APPDATA it should return set 'APPDATA'", ["win32", "AppData"], (val) => val === "AppData"], + ["w/ win32 and set APPDATA it should return set 'APPDATA'", ["win32", "AppData"], "AppData", null], - ["w/ linux it should return '/.local/share'", ["linux", undefined], (val) => val !== null && val.endsWith("/.local/share")], + ["w/ linux it should return '~/.local/share'", ["linux", undefined], "/home/mock/.local/share", "/home/mock"], - ["w/ linux and wrongly set APPDATA it should ignore APPDATA and return /.local/share", ["linux", "FakeAppData"], (val) => val !== null && val.endsWith("/.local/share")], + ["w/ linux and wrongly set APPDATA it should ignore APPDATA and return '~/.local/share'", ["linux", "FakeAppData"], "/home/mock/.local/share", "/home/mock"], - ["w/ darwin it should return /Library/Application Support", ["darwin", undefined], (val) => val !== null && val.endsWith("/Library/Application Support")] + ["w/ darwin it should return '~/Library/Application Support'", ["darwin", undefined], "/Users/mock/Library/Application Support", "/Users/mock"] ]; testCases.forEach((testCase) => { - const [testDescription, value, isExpected] = testCase; + const [testDescription, fnValues, expected, osHomedirMockValue] = testCase; return it(testDescription, () => { - const actual = getPlatformAppDataDir(...value); - const result = isExpected(actual); - expect(result).toBeTruthy(); + mockFn.osHomedirMock.mockReturnValue(osHomedirMockValue); + const actual = getPlatformAppDataDir(...fnValues); + expect(actual).toEqual(expected); }); }); }); From 6443b2ea66f44aa1075407fadcbb56229904d9da Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 19 Jan 2025 00:46:36 +0000 Subject: [PATCH 2/8] fix(deps): update dependency better-sqlite3 to v11.8.1 --- dump-db/package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dump-db/package-lock.json b/dump-db/package-lock.json index fdccf601a..8c04cbd8b 100644 --- a/dump-db/package-lock.json +++ b/dump-db/package-lock.json @@ -464,9 +464,9 @@ "license": "MIT" }, "node_modules/better-sqlite3": { - "version": "11.8.0", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.8.0.tgz", - "integrity": "sha512-aKv9s2dir7bsEX5RIjL9HHWB9uQ+f6Vch5B4qmeAOop4Y9OYHX+PNKLr+mpv6+d8L/ZYh4l7H8zPuVMbWkVMLw==", + "version": "11.8.1", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.8.1.tgz", + "integrity": "sha512-9BxNaBkblMjhJW8sMRZxnxVTRgbRmssZW0Oxc1MPBTfiR+WW21e2Mk4qu8CzrcZb1LwPCnFsfDEzq+SNcBU8eg==", "hasInstallScript": true, "dependencies": { "bindings": "^1.5.0", @@ -1516,9 +1516,9 @@ "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" }, "better-sqlite3": { - "version": "11.8.0", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.8.0.tgz", - "integrity": "sha512-aKv9s2dir7bsEX5RIjL9HHWB9uQ+f6Vch5B4qmeAOop4Y9OYHX+PNKLr+mpv6+d8L/ZYh4l7H8zPuVMbWkVMLw==", + "version": "11.8.1", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.8.1.tgz", + "integrity": "sha512-9BxNaBkblMjhJW8sMRZxnxVTRgbRmssZW0Oxc1MPBTfiR+WW21e2Mk4qu8CzrcZb1LwPCnFsfDEzq+SNcBU8eg==", "requires": { "bindings": "^1.5.0", "prebuild-install": "^7.1.1" From 66ad3779df364179cbe4322c187bad1022062081 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 19 Jan 2025 00:47:03 +0000 Subject: [PATCH 3/8] fix(deps): update react monorepo --- package-lock.json | 23 +++++++++++++---------- package.json | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index f441eb0d3..251313c5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "@mermaid-js/layout-elk": "0.1.7", "@mind-elixir/node-menu": "1.0.3", "@triliumnext/express-partial-content": "1.0.1", - "@types/react-dom": "18.3.1", + "@types/react-dom": "18.3.5", "archiver": "7.0.1", "async-mutex": "0.5.0", "autocomplete.js": "0.38.1", @@ -134,7 +134,7 @@ "@types/mime-types": "2.1.4", "@types/multer": "1.4.12", "@types/node": "22.10.7", - "@types/react": "18.3.1", + "@types/react": "18.3.18", "@types/safe-compare": "1.1.2", "@types/sanitize-html": "2.13.0", "@types/sax": "1.2.7", @@ -3918,6 +3918,7 @@ "version": "15.7.14", "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.14.tgz", "integrity": "sha512-gNMvNH49DJ7OJYv+KAKn0Xp45p8PLl6zo2YnvDIbTd4J6MER2BmWN49TG7n9LvkyihINxeKW8+3bfS2yDC9dzQ==", + "dev": true, "license": "MIT" }, "node_modules/@types/qs": { @@ -3935,9 +3936,10 @@ "license": "MIT" }, "node_modules/@types/react": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.1.tgz", - "integrity": "sha512-V0kuGBX3+prX+DQ/7r2qsv1NsdfnCLnTgnRJ1pYnxykBhGMz+qj+box5lq7XsO5mtZsBqpjwwTu/7wszPfMBcw==", + "version": "18.3.18", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.18.tgz", + "integrity": "sha512-t4yC+vtgnkYjNSKlFx1jkAhH8LgTo2N/7Qvi83kdEaUtMDiwpbLAktKDaAMlRcJ5eSxZkH74eEGt1ky31d7kfQ==", + "dev": true, "license": "MIT", "dependencies": { "@types/prop-types": "*", @@ -3945,12 +3947,12 @@ } }, "node_modules/@types/react-dom": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.1.tgz", - "integrity": "sha512-qW1Mfv8taImTthu4KoXgDfLuk4bydU6Q/TkADnDWWHwi4NX4BR+LWfTp2sVmTqRrsHvyDDTelgelxJ+SsejKKQ==", + "version": "18.3.5", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.5.tgz", + "integrity": "sha512-P4t6saawp+b/dFrUr2cvkVsfvPguwsxtH6dNIYRllMsefqFzkZk5UIjzyDOv5g1dXIPdG4Sp1yCR4Z6RCUsG/Q==", "license": "MIT", - "dependencies": { - "@types/react": "*" + "peerDependencies": { + "@types/react": "^18.0.0" } }, "node_modules/@types/readdir-glob": { @@ -6683,6 +6685,7 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", + "dev": true, "license": "MIT" }, "node_modules/cytoscape": { diff --git a/package.json b/package.json index 044343879..f20a670aa 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@mermaid-js/layout-elk": "0.1.7", "@mind-elixir/node-menu": "1.0.3", "@triliumnext/express-partial-content": "1.0.1", - "@types/react-dom": "18.3.1", + "@types/react-dom": "18.3.5", "archiver": "7.0.1", "async-mutex": "0.5.0", "autocomplete.js": "0.38.1", @@ -176,7 +176,7 @@ "@types/mime-types": "2.1.4", "@types/multer": "1.4.12", "@types/node": "22.10.7", - "@types/react": "18.3.1", + "@types/react": "18.3.18", "@types/safe-compare": "1.1.2", "@types/sanitize-html": "2.13.0", "@types/sax": "1.2.7", From 5ddd88ee550583c37937faf58cc89bff5fd43f74 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 19 Jan 2025 04:47:01 +0000 Subject: [PATCH 4/8] fix(deps): update dependency better-sqlite3 to v11.8.1 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f441eb0d3..f0a10fec9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "async-mutex": "0.5.0", "autocomplete.js": "0.38.1", "axios": "1.7.9", - "better-sqlite3": "11.8.0", + "better-sqlite3": "11.8.1", "bootstrap": "5.3.3", "boxicons": "2.1.4", "cheerio": "1.0.0", @@ -5140,9 +5140,9 @@ "license": "MIT" }, "node_modules/better-sqlite3": { - "version": "11.8.0", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.8.0.tgz", - "integrity": "sha512-aKv9s2dir7bsEX5RIjL9HHWB9uQ+f6Vch5B4qmeAOop4Y9OYHX+PNKLr+mpv6+d8L/ZYh4l7H8zPuVMbWkVMLw==", + "version": "11.8.1", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.8.1.tgz", + "integrity": "sha512-9BxNaBkblMjhJW8sMRZxnxVTRgbRmssZW0Oxc1MPBTfiR+WW21e2Mk4qu8CzrcZb1LwPCnFsfDEzq+SNcBU8eg==", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 044343879..61b5c4e6e 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "async-mutex": "0.5.0", "autocomplete.js": "0.38.1", "axios": "1.7.9", - "better-sqlite3": "11.8.0", + "better-sqlite3": "11.8.1", "bootstrap": "5.3.3", "boxicons": "2.1.4", "cheerio": "1.0.0", From fb0dda982f75e969418f473b2b688cff558efa9d Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 19 Jan 2025 23:30:07 +0200 Subject: [PATCH 5/8] fix(mindmap): restore direction --- src/public/app/widgets/type_widgets/mind_map.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/public/app/widgets/type_widgets/mind_map.ts b/src/public/app/widgets/type_widgets/mind_map.ts index 3bd72836a..ef8fdaf27 100644 --- a/src/public/app/widgets/type_widgets/mind_map.ts +++ b/src/public/app/widgets/type_widgets/mind_map.ts @@ -179,7 +179,6 @@ export default class MindMapWidget extends TypeWidget { return; } - this.#initLibrary(); await this.#loadData(note); } @@ -191,16 +190,18 @@ export default class MindMapWidget extends TypeWidget { const blob = await note.getBlob(); const content = blob?.getJsonContent() || MindElixir.new(NEW_TOPIC_NAME); - if (this.mind) { - this.mind.refresh(content); - this.mind.toCenter(); + if (!this.mind) { + this.#initLibrary(content.direction ?? MindElixir.LEFT); } + + this.mind.refresh(content); + this.mind.toCenter(); } - #initLibrary() { + #initLibrary(direction: unknown) { const mind = new MindElixir({ el: this.$content[0], - direction: MindElixir.LEFT + direction }); mind.install(nodeMenu); From 9820e8aa12b0e5e2311e28fd4d0dda272568f0cf Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 19 Jan 2025 23:34:57 +0200 Subject: [PATCH 6/8] fix(mindmap): use dynamic import instead of static one --- src/public/app/entities/fblob.ts | 2 +- .../app/widgets/type_widgets/mind_map.ts | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/public/app/entities/fblob.ts b/src/public/app/entities/fblob.ts index fc00e1d1f..739027d4d 100644 --- a/src/public/app/entities/fblob.ts +++ b/src/public/app/entities/fblob.ts @@ -27,7 +27,7 @@ export default class FBlob { /** * @throws Error in case of invalid JSON */ - getJsonContent(): unknown { + getJsonContent(): T | null { if (!this.content || !this.content.trim()) { return null; } diff --git a/src/public/app/widgets/type_widgets/mind_map.ts b/src/public/app/widgets/type_widgets/mind_map.ts index ef8fdaf27..91aabda79 100644 --- a/src/public/app/widgets/type_widgets/mind_map.ts +++ b/src/public/app/widgets/type_widgets/mind_map.ts @@ -1,6 +1,6 @@ import TypeWidget from "./type_widget.js"; import utils from "../../services/utils.js"; -import MindElixir, { type MindElixirCtor } from "mind-elixir"; +import type { MindElixirCtor } from "mind-elixir"; import nodeMenu from "@mind-elixir/node-menu"; import type FNote from "../../entities/fnote.js"; import type { EventData } from "../../components/app_context.js"; @@ -141,11 +141,16 @@ const TPL = ` `; +interface MindmapModel { + direction: number; +} + export default class MindMapWidget extends TypeWidget { private $content!: JQuery; private triggeredByUserOperation?: boolean; private mind?: ReturnType; + private MindElixir: any; // TODO: Fix type static getType() { return "mindMap"; @@ -188,25 +193,27 @@ export default class MindMapWidget extends TypeWidget { async #loadData(note: FNote) { const blob = await note.getBlob(); - const content = blob?.getJsonContent() || MindElixir.new(NEW_TOPIC_NAME); + const content = blob?.getJsonContent(); if (!this.mind) { - this.#initLibrary(content.direction ?? MindElixir.LEFT); + await this.#initLibrary(content?.direction ?? this.MindElixir.LEFT); } - this.mind.refresh(content); + this.mind.refresh(content ?? this.MindElixir.new(NEW_TOPIC_NAME)); this.mind.toCenter(); } - #initLibrary(direction: unknown) { - const mind = new MindElixir({ + async #initLibrary(direction: unknown) { + this.MindElixir = (await import("mind-elixir")).default; + + const mind = new this.MindElixir({ el: this.$content[0], direction }); mind.install(nodeMenu); this.mind = mind; - mind.init(MindElixir.new(NEW_TOPIC_NAME)); + mind.init(this.MindElixir.new(NEW_TOPIC_NAME)); // TODO: See why the typeof mindmap is not correct. mind.bus.addListener("operation", (operation: { name: string }) => { this.triggeredByUserOperation = true; From b47dc13ff1106bb94b037f3de7b95b2dbea33b13 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 19 Jan 2025 23:38:20 +0200 Subject: [PATCH 7/8] fix(mindmap): regression on new mindmap --- src/public/app/widgets/type_widgets/mind_map.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/public/app/widgets/type_widgets/mind_map.ts b/src/public/app/widgets/type_widgets/mind_map.ts index 91aabda79..37ca7545b 100644 --- a/src/public/app/widgets/type_widgets/mind_map.ts +++ b/src/public/app/widgets/type_widgets/mind_map.ts @@ -196,19 +196,19 @@ export default class MindMapWidget extends TypeWidget { const content = blob?.getJsonContent(); if (!this.mind) { - await this.#initLibrary(content?.direction ?? this.MindElixir.LEFT); + await this.#initLibrary(content?.direction); } this.mind.refresh(content ?? this.MindElixir.new(NEW_TOPIC_NAME)); this.mind.toCenter(); } - async #initLibrary(direction: unknown) { + async #initLibrary(direction?: number) { this.MindElixir = (await import("mind-elixir")).default; const mind = new this.MindElixir({ el: this.$content[0], - direction + direction: direction ?? this.MindElixir.LEFT }); mind.install(nodeMenu); From 7f15f8a7de9428736bff1489887b74d2e3a573dc Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 19 Jan 2025 23:48:30 +0200 Subject: [PATCH 8/8] fix(mindmap): save direction as soon as it is changed (closes #986) --- src/public/app/widgets/type_widgets/mind_map.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/public/app/widgets/type_widgets/mind_map.ts b/src/public/app/widgets/type_widgets/mind_map.ts index 37ca7545b..afa34df06 100644 --- a/src/public/app/widgets/type_widgets/mind_map.ts +++ b/src/public/app/widgets/type_widgets/mind_map.ts @@ -175,6 +175,11 @@ export default class MindMapWidget extends TypeWidget { } }); + // Save the mind map if the user changes the layout direction. + this.$content.on("click", ".mind-elixir-toolbar.lt", () => { + this.spacedUpdate.scheduleUpdate(); + }); + super.doRender(); }