Skip to content

Build your personal knowledge base with Trilium Notes

refactor(mind-map): gather the pieces under one roof

Elian Doran29934fa7f3b3
diff --git a/apps/client/src/widgets/note_types.tsx b/apps/client/src/widgets/note_types.tsx
index 23afbcb44c..e9baab6f9e 100644
--- a/apps/client/src/widgets/note_types.tsx
+++ b/apps/client/src/widgets/note_types.tsx
@@ -94,7 +94,7 @@ export const TYPE_MAPPINGS: Record<ExtendedNoteType, NoteTypeMapping> = {
isFullHeight: true
},
mindMap: {
- view: () => import("./type_widgets/MindMap"),
+ view: () => import("./type_widgets/mind_map/MindMap"),
className: "note-detail-mind-map",
printable: true,
isFullHeight: true
diff --git a/apps/client/src/widgets/type_widgets/MindMap.css b/apps/client/src/widgets/type_widgets/mind_map/MindMap.css
similarity index 93%
rename from apps/client/src/widgets/type_widgets/MindMap.css
rename to apps/client/src/widgets/type_widgets/mind_map/MindMap.css
index 512844e49f..0fb3a1a8ab 100644
--- a/apps/client/src/widgets/type_widgets/MindMap.css
+++ b/apps/client/src/widgets/type_widgets/mind_map/MindMap.css
@@ -19,7 +19,7 @@
}
/*
- * The node backgrounds the panel offers are tints (see MindMapNodePanel), which take on whatever
+ * The node backgrounds the panel offers are tints (see NodePanel), which take on whatever
* the canvas is. The branch lines are drawn underneath the nodes, so a tint on its own composites
* against them and lets them show through the node — give a tinted node an opaque copy of the
* canvas to sit on instead. Only nodes carrying a background of their own get one, so that the
@@ -41,7 +41,7 @@
}
/*
- * The first icon of a node leads its text, as a note's icon leads its title (see mind_map_icons).
+ * The first icon of a node leads its text, as a note's icon leads its title (see icons.ts).
* The ones after it follow the text a little smaller: the first says what the node is, the rest are
* marks upon it.
*/
diff --git a/apps/client/src/widgets/type_widgets/MindMap.spec.ts b/apps/client/src/widgets/type_widgets/mind_map/MindMap.spec.ts
similarity index 100%
rename from apps/client/src/widgets/type_widgets/MindMap.spec.ts
rename to apps/client/src/widgets/type_widgets/mind_map/MindMap.spec.ts
diff --git a/apps/client/src/widgets/type_widgets/MindMap.tsx b/apps/client/src/widgets/type_widgets/mind_map/MindMap.tsx
similarity index 95%
rename from apps/client/src/widgets/type_widgets/MindMap.tsx
rename to apps/client/src/widgets/type_widgets/mind_map/MindMap.tsx
index 6d0ae5dd1f..36928b6617 100644
--- a/apps/client/src/widgets/type_widgets/MindMap.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/MindMap.tsx
@@ -9,16 +9,16 @@ import { ComponentChildren, HTMLAttributes, RefObject } from "preact";
import { createPortal } from "preact/compat";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
-import { sanitizeNoteContentHtml } from "../../services/sanitize_content";
-import toast from "../../services/toast";
-import utils from "../../services/utils";
-import { useColorScheme, useEditorSpacedUpdate, useEffectiveReadOnly, useSyncedRef, useTriliumEvent, useTriliumEvents, useTriliumOption } from "../react/hooks";
-import { refToJQuerySelector } from "../react/react_utils";
-import { renderMindMapPreviewSvg } from "./helpers/mind_map_export";
-import { renderIconClasses } from "./helpers/mind_map_icons";
-import { renderNodeLinks } from "./helpers/mind_map_links";
-import MindMapNodePanel from "./MindMapNodePanel";
-import { TypeWidgetProps } from "./type_widget";
+import { sanitizeNoteContentHtml } from "../../../services/sanitize_content";
+import toast from "../../../services/toast";
+import utils from "../../../services/utils";
+import { useColorScheme, useEditorSpacedUpdate, useEffectiveReadOnly, useSyncedRef, useTriliumEvent, useTriliumEvents, useTriliumOption } from "../../react/hooks";
+import { refToJQuerySelector } from "../../react/react_utils";
+import { TypeWidgetProps } from "../type_widget";
+import { renderMindMapPreviewSvg } from "./export";
+import { renderIconClasses } from "./icons";
+import { renderNodeLinks } from "./links";
+import NodePanel from "./NodePanel";
const NEW_TOPIC_NAME = "";
@@ -191,7 +191,7 @@ export default function MindMap({ note, ntxId, noteContext }: TypeWidgetProps) {
}}
>
{!isReadOnly && selectedNodes.length > 0 && apiRef.current &&
- <MindMapNodePanel mind={apiRef.current} noteId={note.noteId} nodes={selectedNodes} />}
+ <NodePanel mind={apiRef.current} noteId={note.noteId} nodes={selectedNodes} />}
</MindElixir>
);
}
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodeMemo.css b/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.css
similarity index 100%
rename from apps/client/src/widgets/type_widgets/MindMapNodeMemo.css
rename to apps/client/src/widgets/type_widgets/mind_map/NodeMemo.css
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodeMemo.spec.ts b/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.spec.ts
similarity index 96%
rename from apps/client/src/widgets/type_widgets/MindMapNodeMemo.spec.ts
rename to apps/client/src/widgets/type_widgets/mind_map/NodeMemo.spec.ts
index 0299fac232..0e8802d3bd 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodeMemo.spec.ts
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.spec.ts
@@ -1,7 +1,7 @@
import type { NodeObj } from "mind-elixir";
import { describe, expect, it } from "vitest";
-import { getNodeMemo, toMemoHtml } from "./MindMapNodeMemo";
+import { getNodeMemo, toMemoHtml } from "./NodeMemo";
function buildNode(node: Partial<NodeObj> = {}): NodeObj {
return { id: "n1", topic: "Node", ...node };
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodeMemo.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.tsx
similarity index 96%
rename from apps/client/src/widgets/type_widgets/MindMapNodeMemo.tsx
rename to apps/client/src/widgets/type_widgets/mind_map/NodeMemo.tsx
index 92535df6b6..a435dfd0a3 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodeMemo.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodeMemo.tsx
@@ -1,11 +1,11 @@
-import "./MindMapNodeMemo.css";
+import "./NodeMemo.css";
import { AttributeEditor, CHAT_INPUT_PLUGINS, type CKTextEditor, type EditorConfig } from "@triliumnext/ckeditor5";
import type { NodeObj } from "mind-elixir";
import { useEffect, useLayoutEffect, useRef } from "preact/hooks";
-import { escapeHtml } from "../../services/utils";
-import CKEditor, { type CKEditorApi } from "../react/CKEditor";
+import { escapeHtml } from "../../../services/utils";
+import CKEditor, { type CKEditorApi } from "../../react/CKEditor";
/**
* The memo a node carries: text kept about it, which the map itself never shows.
@@ -14,7 +14,7 @@ import CKEditor, { type CKEditorApi } from "../react/CKEditor";
* did: a memo is written a paragraph at a time, and taking every keystroke would mean a copy of the
* whole map in the undo stack for each of them.
*/
-export default function MindMapNodeMemo({ selectionKey, memo, readOnly, onCommit }: {
+export default function NodeMemo({ selectionKey, memo, readOnly, onCommit }: {
/**
* What the panel currently stands for. The field is one editor for however many nodes are
* selected over its lifetime, so it is told when that changes: the memo shown is the memo of
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.css b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
similarity index 100%
rename from apps/client/src/widgets/type_widgets/MindMapNodePanel.css
rename to apps/client/src/widgets/type_widgets/mind_map/NodePanel.css
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
similarity index 88%
rename from apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx
rename to apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
index 5d0433cf1c..a280e248b9 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.spec.tsx
@@ -3,15 +3,15 @@ import { render } from "preact";
import { act } from "preact/test-utils";
import { describe, expect, it, vi } from "vitest";
-import { buildNotes } from "../../test/easy-froca";
-import { renderInto } from "../../test/render";
-import { uploadNodeImage } from "./helpers/mind_map_images";
-import MindMapNodePanel, { applyTagTexts, DEFAULT_FONT_SIZE, gatherTags, getCommonValue, MIXED, NODE_BACKGROUND_COLORS, NODE_COLORS, withIconAt } from "./MindMapNodePanel";
+import { buildNotes } from "../../../test/easy-froca";
+import { renderInto } from "../../../test/render";
+import { uploadNodeImage } from "./images";
+import NodePanel, { applyTagTexts, DEFAULT_FONT_SIZE, gatherTags, getCommonValue, MIXED, NODE_BACKGROUND_COLORS, NODE_COLORS, withIconAt } from "./NodePanel";
// Storing a picture is the one thing the panel does that leaves the browser; the rest of the module
// (the sizes, the proportions) is the real one, being what the panel is checked against here.
-vi.mock("./helpers/mind_map_images", async (importOriginal) => ({
- ...await importOriginal<typeof import("./helpers/mind_map_images")>(),
+vi.mock("./images", async (importOriginal) => ({
+ ...await importOriginal<typeof import("./images")>(),
uploadNodeImage: vi.fn()
}));
@@ -22,7 +22,7 @@ vi.mock("./helpers/mind_map_images", async (importOriginal) => ({
let memoEditor: MemoEditorProps = { className: "" };
/** What the stand-in is showing, which outlives the props it was last handed. */
let shownMemoText: string | undefined;
-vi.mock("../react/CKEditor", async () => {
+vi.mock("../../react/CKEditor", async () => {
const { useEffect, useImperativeHandle } = await import("preact/hooks");
return {
@@ -250,7 +250,7 @@ describe("the memo field of the panel", () => {
let container: HTMLElement | undefined;
await act(async () => {
- container = renderInto(<MindMapNodePanel mind={buildMind([withMemo]).mind} noteId="map" nodes={[withMemo]} />);
+ container = renderInto(<NodePanel mind={buildMind([withMemo]).mind} noteId="map" nodes={[withMemo]} />);
});
if (!container) throw new Error("render produced no container");
const panel = container;
@@ -258,12 +258,12 @@ describe("the memo field of the panel", () => {
// Rendered into the same container, so the panel is updated rather than built anew.
await act(async () => {
- render(<MindMapNodePanel mind={buildMind([without]).mind} noteId="map" nodes={[without]} />, panel);
+ render(<NodePanel mind={buildMind([without]).mind} noteId="map" nodes={[without]} />, panel);
});
expect(shownMemo(panel)).toBe("");
await act(async () => {
- render(<MindMapNodePanel mind={buildMind([withMemo]).mind} noteId="map" nodes={[withMemo]} />, panel);
+ render(<NodePanel mind={buildMind([withMemo]).mind} noteId="map" nodes={[withMemo]} />, panel);
});
expect(shownMemo(panel)).toBe("<p>About A</p>");
});
@@ -277,7 +277,7 @@ describe("the memo field of the panel", () => {
let container: HTMLElement | undefined;
await act(async () => {
- container = renderInto(<MindMapNodePanel mind={buildMind([first]).mind} noteId="map" nodes={[first]} />);
+ container = renderInto(<NodePanel mind={buildMind([first]).mind} noteId="map" nodes={[first]} />);
});
if (!container) throw new Error("render produced no container");
const panel = container;
@@ -286,7 +286,7 @@ describe("the memo field of the panel", () => {
expect(shownMemoText).toBe("<p>Typed for A</p>");
await act(async () => {
- render(<MindMapNodePanel mind={buildMind([second]).mind} noteId="map" nodes={[second]} />, panel);
+ render(<NodePanel mind={buildMind([second]).mind} noteId="map" nodes={[second]} />, panel);
});
expect(shownMemoText).toBe("");
});
@@ -298,7 +298,7 @@ describe("the memo field of the panel", () => {
let container: HTMLElement | undefined;
await act(async () => {
- container = renderInto(<MindMapNodePanel mind={firstMind.mind} noteId="map" nodes={[first]} />);
+ container = renderInto(<NodePanel mind={firstMind.mind} noteId="map" nodes={[first]} />);
});
if (!container) throw new Error("render produced no container");
const panel = container;
@@ -308,7 +308,7 @@ describe("the memo field of the panel", () => {
// Selecting another node writes what was typed for the first back to the first...
const secondMind = buildMind([second]);
await act(async () => {
- render(<MindMapNodePanel mind={secondMind.mind} noteId="map" nodes={[second]} />, panel);
+ render(<NodePanel mind={secondMind.mind} noteId="map" nodes={[second]} />, panel);
});
expect(firstMind.reshapeNode).toHaveBeenCalledWith(firstMind.mind.currentNodes[0], { memo: "<p>About A, at length</p>" });
@@ -332,12 +332,12 @@ describe("applyTagTexts", () => {
});
});
-describe("MindMapNodePanel", () => {
+describe("NodePanel", () => {
it("offers every row on a single line, backgrounds as translucent variants of the same hues", () => {
const nodes = [buildNode()];
const { mind } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
for (const index of [TEXT, BACKGROUND, BRANCH]) {
// A row is the presets plus the clear and custom cells; more would wrap in the panel.
@@ -351,7 +351,7 @@ describe("MindMapNodePanel", () => {
const nodes = [buildNode({ id: "a" }), buildNode({ id: "b" })];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
expect(sizeButtons(container)).toHaveLength(4);
expect(activeSize(container)).toBe(1);
@@ -371,11 +371,11 @@ describe("MindMapNodePanel", () => {
it("shows the size the selection already carries, and none when the nodes disagree", () => {
const large = { style: { fontSize: "24px" } };
const { mind } = buildMind([buildNode(large)]);
- expect(activeSize(renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={[buildNode(large)]} />))).toBe(2);
+ expect(activeSize(renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={[buildNode(large)]} />))).toBe(2);
const mixed = [buildNode({ id: "a", ...large }), buildNode({ id: "b", style: { fontSize: "32px" } })];
const mixedMind = buildMind(mixed);
- expect(activeSize(renderInto(<MindMapNodePanel mind={mixedMind.mind} noteId="mapNote" nodes={mixed} />))).toBe(-1);
+ expect(activeSize(renderInto(<NodePanel mind={mixedMind.mind} noteId="mapNote" nodes={mixed} />))).toBe(-1);
});
it("shows the colors the selection already carries", () => {
@@ -385,7 +385,7 @@ describe("MindMapNodePanel", () => {
})];
const { mind } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
const selectedIn = (index: number) => presetCells(section(container, index))
.findIndex((cell) => cell.classList.contains("selected"));
@@ -402,7 +402,7 @@ describe("MindMapNodePanel", () => {
];
const { mind } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
const textCells = Array.from(section(container, TEXT).querySelectorAll(".color-cell"));
expect(textCells.some((cell) => cell.classList.contains("selected"))).toBe(false);
@@ -415,7 +415,7 @@ describe("MindMapNodePanel", () => {
const nodes = [buildNode({ id: "a" }), buildNode({ id: "b" })];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
presetCells(section(container, TEXT))[3].click();
expect(reshapeNode).toHaveBeenCalledTimes(2);
@@ -438,12 +438,12 @@ describe("MindMapNodePanel", () => {
it("shows every icon the selection wears, and a button for one more", () => {
const nodes = [buildNode({ icons: ["bx bx-star", "bx bx-cube"] })];
- const container = renderInto(<MindMapNodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
// The icons themselves, then the button adding another.
expect(iconFaces(container)).toEqual(["bx bx-star", "bx bx-cube", "bx bx-plus"]);
// A node wearing none is the adding button alone, which is invitation enough.
- expect(iconFaces(renderInto(<MindMapNodePanel mind={buildMind([buildNode()]).mind} noteId="mapNote" nodes={[buildNode()]} />)))
+ expect(iconFaces(renderInto(<NodePanel mind={buildMind([buildNode()]).mind} noteId="mapNote" nodes={[buildNode()]} />)))
.toEqual(["bx bx-plus"]);
});
@@ -453,7 +453,7 @@ describe("MindMapNodePanel", () => {
buildNode({ id: "b", icons: ["bx bx-cube"] })
];
- const container = renderInto(<MindMapNodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
// Everything they carry, and no way to add: a pick could only overwrite what each has.
expect(iconFaces(container)).toEqual(["bx bx-star", "bx bx-cube"]);
@@ -463,7 +463,7 @@ describe("MindMapNodePanel", () => {
it("offers what can be done with the picture a node carries, and only takes one in without", () => {
const nodes = [buildNode({ image: { url: "api/attachments/att1/image/a.png", width: 240, height: 180 } })];
- const container = renderInto(<MindMapNodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
// The picture is on the node itself; the row says how large it is drawn and offers the way
// to another one or to none.
@@ -473,7 +473,7 @@ describe("MindMapNodePanel", () => {
// A node carrying none offers to take one in, and nothing else: there is no size to set and
// nothing to remove.
- const empty = renderInto(<MindMapNodePanel mind={buildMind([buildNode()]).mind} noteId="mapNote" nodes={[buildNode()]} />);
+ const empty = renderInto(<NodePanel mind={buildMind([buildNode()]).mind} noteId="mapNote" nodes={[buildNode()]} />);
expect(imageWidthButtons(empty)).toHaveLength(0);
expect(imageAction(empty, "bx-trash")).toBeNull();
expect(imageAction(empty, "bx-image-add")).toBeTruthy();
@@ -486,7 +486,7 @@ describe("MindMapNodePanel", () => {
];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
imageWidthButtons(container)[2].click();
expect(reshapeNode).toHaveBeenNthCalledWith(1, mind.currentNodes[0], { image: { url: "a.png", width: 400, height: 300 } });
@@ -506,7 +506,7 @@ describe("MindMapNodePanel", () => {
];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
// Both carry their own shape, which is the one shown; the widths they disagree on are not.
expect(imageShapeButtons(container)).toHaveLength(3);
@@ -526,7 +526,7 @@ describe("MindMapNodePanel", () => {
buildNode({ id: "b", image: { url: "b.png", width: 120, height: 90 } })
];
- const container = renderInto(<MindMapNodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />);
// One picture cannot take the place of them all — that is a removal in all but name. What
// it would take, removing them and taking one in, is what the row still offers. (The
@@ -545,7 +545,7 @@ describe("MindMapNodePanel", () => {
const nodes = [buildNode({ id: "a" }), buildNode({ id: "b" })];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
chooseImage(container, new File([""], "photo.png", { type: "image/png" }));
await vi.waitFor(() => expect(reshapeNode).toHaveBeenCalledTimes(2));
@@ -559,7 +559,7 @@ describe("MindMapNodePanel", () => {
const nodes = [buildNode()];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
chooseImage(container, new File([""], "photo.png", { type: "image/png" }));
await vi.waitFor(() => expect(uploadNodeImage).toHaveBeenCalled());
@@ -569,7 +569,7 @@ describe("MindMapNodePanel", () => {
it("says what the selection is linked to, and what it would take to link it", async () => {
const [ noteId ] = buildNotes([ { title: "Linked note", "#iconClass": "bx bx-cube" } ]);
const linkFace = (nodes: NodeObj[]) =>
- renderInto(<MindMapNodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />)
+ renderInto(<NodePanel mind={buildMind(nodes).mind} noteId="mapNote" nodes={nodes} />)
.querySelector<HTMLElement>(`.mind-map-node-panel-section:nth-child(${LINK + 1}) button`);
// Nothing yet, and a selection that disagrees, each say so in their own words.
@@ -594,7 +594,7 @@ describe("MindMapNodePanel", () => {
const nodes = [buildNode({ tags: [styled, "later"] })];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
expect(tagTexts(container)).toEqual(["urgent", "later"]);
@@ -612,7 +612,7 @@ describe("MindMapNodePanel", () => {
];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
expect(tagTexts(container)).toEqual(["urgent"]);
expect(container.querySelector<HTMLInputElement>(".tn-field input")?.disabled).toBe(false);
@@ -630,7 +630,7 @@ describe("MindMapNodePanel", () => {
];
const { mind, reshapeNode } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
expect(tagTexts(container)).toEqual(["one", "shared", "two"]);
expect(container.querySelector<HTMLInputElement>(".tn-field input")?.disabled).toBe(true);
@@ -645,7 +645,7 @@ describe("MindMapNodePanel", () => {
const nodes = [buildNode()];
const { mind } = buildMind(nodes);
- const container = renderInto(<MindMapNodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
+ const container = renderInto(<NodePanel mind={mind} noteId="mapNote" nodes={nodes} />);
const panel = container.querySelector(".mind-map-node-panel");
for (const event of [
diff --git a/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
similarity index 95%
rename from apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx
rename to apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
index 3244482d69..2a45143f2a 100644
--- a/apps/client/src/widgets/type_widgets/MindMapNodePanel.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/NodePanel.tsx
@@ -1,4 +1,4 @@
-import "./MindMapNodePanel.css";
+import "./NodePanel.css";
import { parseMindMapNoteLink } from "@triliumnext/commons";
import { Dropdown as BootstrapDropdown } from "bootstrap";
@@ -6,24 +6,24 @@ import type { MindElixirInstance, NodeObj, TagObj } from "mind-elixir";
import { ComponentChildren } from "preact";
import { useEffect, useRef, useState } from "preact/hooks";
-import { t } from "../../services/i18n";
-import note_autocomplete from "../../services/note_autocomplete";
-import tree from "../../services/tree";
-import ValuesInput from "../attribute_widgets/values_input";
-import ActionButton from "../react/ActionButton";
-import ColorPicker, { DEFAULT_COLOR_PALETTE } from "../react/ColorPicker";
-import Dropdown from "../react/Dropdown";
-import { FormFileUploadActionButton } from "../react/FormFileUpload";
-import { FormListItem } from "../react/FormList";
-import { useNote, useNoteIcon, useNoteTitle } from "../react/hooks";
-import Icon from "../react/Icon";
-import IconPicker from "../react/IconPicker";
-import NoteAutocomplete from "../react/NoteAutocomplete";
-import { refToJQuerySelector } from "../react/react_utils";
-import SegmentedChoice from "../react/SegmentedChoice";
-import MindMapNodeMemo, { getNodeMemo } from "./MindMapNodeMemo";
-import { fitNodeImage, getNodeImageShape, nearestNodeImageWidth, NODE_IMAGE_SHAPES, NODE_IMAGE_WIDTHS, type NodeImage as NodeImageData, type NodeImageShape, shapeNodeImage, uploadNodeImage } from "./helpers/mind_map_images";
-import { describeExternalLink, linkFromSuggestion } from "./helpers/mind_map_links";
+import { t } from "../../../services/i18n";
+import note_autocomplete from "../../../services/note_autocomplete";
+import tree from "../../../services/tree";
+import ValuesInput from "../../attribute_widgets/values_input";
+import ActionButton from "../../react/ActionButton";
+import ColorPicker, { DEFAULT_COLOR_PALETTE } from "../../react/ColorPicker";
+import Dropdown from "../../react/Dropdown";
+import { FormFileUploadActionButton } from "../../react/FormFileUpload";
+import { FormListItem } from "../../react/FormList";
+import { useNote, useNoteIcon, useNoteTitle } from "../../react/hooks";
+import Icon from "../../react/Icon";
+import IconPicker from "../../react/IconPicker";
+import NoteAutocomplete from "../../react/NoteAutocomplete";
+import { refToJQuerySelector } from "../../react/react_utils";
+import SegmentedChoice from "../../react/SegmentedChoice";
+import { fitNodeImage, getNodeImageShape, nearestNodeImageWidth, NODE_IMAGE_SHAPES, NODE_IMAGE_WIDTHS, type NodeImage as NodeImageData, type NodeImageShape, shapeNodeImage, uploadNodeImage } from "./images";
+import { describeExternalLink, linkFromSuggestion } from "./links";
+import NodeMemo, { getNodeMemo } from "./NodeMemo";
/**
* The hues offered by the panel: as many of the shared palette as fit on a single row next to the
@@ -38,7 +38,7 @@ export const NODE_COLORS = [0, 1, 2, 4, 7, 9].map((index) => DEFAULT_COLOR_PALET
*/
export const NODE_BACKGROUND_COLORS = NODE_COLORS.map((color) => `${color}40`);
-interface MindMapNodePanelProps {
+interface NodePanelProps {
mind: MindElixirInstance;
/** The note the map belongs to, which is where a picture put on a node is stored. */
noteId: string;
@@ -50,7 +50,7 @@ interface MindMapNodePanelProps {
* Floating panel displayed over a mind map while at least one node is selected, holding the
* formatting controls for the selection.
*/
-export default function MindMapNodePanel({ mind, noteId, nodes }: MindMapNodePanelProps) {
+export default function NodePanel({ mind, noteId, nodes }: NodePanelProps) {
const fontSize = getCommonValue(nodes, (node) => node.style?.fontSize);
const textColor = getCommonValue(nodes, (node) => node.style?.color);
const backgroundColor = getCommonValue(nodes, (node) => node.style?.background);
@@ -225,7 +225,7 @@ export default function MindMapNodePanel({ mind, noteId, nodes }: MindMapNodePan
label={t("mind-map.memo")}
title={memo === MIXED ? t("mind-map.memos-differ") : undefined}
>
- <MindMapNodeMemo
+ <NodeMemo
selectionKey={nodes.map((node) => node.id).join(" ")}
memo={memo !== MIXED ? memo : null}
readOnly={memo === MIXED}
@@ -629,7 +629,7 @@ export const MIXED = Symbol("mixed");
/**
* Reads one property off every given node, returning the value they share, `null` if none of them
* has one, or {@link MIXED} if they disagree. Values that are unset and values that were blanked
- * out (see {@link MindMapNodePanel}) count as the same thing.
+ * out (see {@link NodePanel}) count as the same thing.
*/
export function getCommonValue(nodes: NodeObj[], read: (node: NodeObj) => string | undefined): string | null | typeof MIXED {
let common: string | null | undefined;
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_export.spec.ts b/apps/client/src/widgets/type_widgets/mind_map/export.spec.ts
similarity index 99%
rename from apps/client/src/widgets/type_widgets/helpers/mind_map_export.spec.ts
rename to apps/client/src/widgets/type_widgets/mind_map/export.spec.ts
index 798289e064..9a4ec4cb0b 100644
--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_export.spec.ts
+++ b/apps/client/src/widgets/type_widgets/mind_map/export.spec.ts
@@ -5,7 +5,7 @@
import MindElixir, { type MindElixirData, type MindElixirInstance } from "mind-elixir";
import { describe, expect, it, vi } from "vitest";
-import { inlineExportedImages, postProcessExportedSvg, renderMindMapPreviewSvg } from "./mind_map_export";
+import { inlineExportedImages, postProcessExportedSvg, renderMindMapPreviewSvg } from "./export";
// mind-elixir touches these browser APIs at construction time; jsdom lacks them.
window.matchMedia = window.matchMedia ?? ((query: string) => ({
@@ -228,7 +228,7 @@ describe("renderMindMapPreviewSvg", () => {
* Non-regression tests against a real mind-elixir instance, guarding the internals the
* label injection depends on (labels as `.svg-label` divs inside `mind.nodes`, the
* nested-svg export structure). If these fail after a mind-elixir upgrade, re-verify
- * mind_map_export.ts against the new internals — see the module comment there.
+ * export.ts against the new internals — see the module comment there.
*/
describe("renderMindMapPreviewSvg (real mind-elixir)", () => {
function initRealMindMap(data: MindElixirData): MindElixirInstance {
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_export.ts b/apps/client/src/widgets/type_widgets/mind_map/export.ts
similarity index 98%
rename from apps/client/src/widgets/type_widgets/helpers/mind_map_export.ts
rename to apps/client/src/widgets/type_widgets/mind_map/export.ts
index 118b941dcd..ba0f7cb5ae 100644
--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_export.ts
+++ b/apps/client/src/widgets/type_widgets/mind_map/export.ts
@@ -1,7 +1,7 @@
import type { MindElixirInstance } from "mind-elixir";
import { sanitizeNoteContentHtml } from "../../../services/sanitize_content";
-import { loadImageData } from "./mind_map_images";
+import { loadImageData } from "./images";
const SVG_NS = "http://www.w3.org/2000/svg";
const XHTML_NS = "http://www.w3.org/1999/xhtml";
@@ -135,7 +135,7 @@ export function postProcessExportedSvg(mind: MindElixirInstance, svgText: string
/**
* Paints an opaque copy of the map canvas behind every translucent node box.
*
- * The node backgrounds the editor offers are tints (see MindMapNodePanel) meant to composite
+ * The node backgrounds the editor offers are tints (see NodePanel) meant to composite
* against the canvas, but the exporter draws the branch lines first and the node boxes over them
* (each box being a direct `<rect>` child of the map layers, filled with the node's computed
* background), so a tint alone would show the lines through the node. Nodes with no background of
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.spec.ts b/apps/client/src/widgets/type_widgets/mind_map/icons.spec.ts
similarity index 98%
rename from apps/client/src/widgets/type_widgets/helpers/mind_map_icons.spec.ts
rename to apps/client/src/widgets/type_widgets/mind_map/icons.spec.ts
index 1f2a583764..9d4f5c89be 100644
--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.spec.ts
+++ b/apps/client/src/widgets/type_widgets/mind_map/icons.spec.ts
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
-import { LEAD_ICON_CLASS, renderIconClasses } from "./mind_map_icons";
+import { LEAD_ICON_CLASS, renderIconClasses } from "./icons";
const uncheckedWindow = window as unknown as { glob: { iconRegistry?: unknown } };
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.ts b/apps/client/src/widgets/type_widgets/mind_map/icons.ts
similarity index 100%
rename from apps/client/src/widgets/type_widgets/helpers/mind_map_icons.ts
rename to apps/client/src/widgets/type_widgets/mind_map/icons.ts
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_images.spec.ts b/apps/client/src/widgets/type_widgets/mind_map/images.spec.ts
similarity index 99%
rename from apps/client/src/widgets/type_widgets/helpers/mind_map_images.spec.ts
rename to apps/client/src/widgets/type_widgets/mind_map/images.spec.ts
index cb9fc8fe86..3e6b0f39bb 100644
--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_images.spec.ts
+++ b/apps/client/src/widgets/type_widgets/mind_map/images.spec.ts
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import server from "../../../services/server";
import toast from "../../../services/toast";
-import { DEFAULT_NODE_IMAGE_WIDTH, fitNodeImage, getNodeImageShape, loadImageData, measureImage, nearestNodeImageWidth, NODE_IMAGE_WIDTHS, shapeNodeImage, uploadNodeImage } from "./mind_map_images";
+import { DEFAULT_NODE_IMAGE_WIDTH, fitNodeImage, getNodeImageShape, loadImageData, measureImage, nearestNodeImageWidth, NODE_IMAGE_WIDTHS, shapeNodeImage, uploadNodeImage } from "./images";
vi.mock("../../../services/server", () => ({ default: { upload: vi.fn() } }));
vi.mock("../../../services/toast", () => ({ default: { showError: vi.fn() } }));
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_images.ts b/apps/client/src/widgets/type_widgets/mind_map/images.ts
similarity index 99%
rename from apps/client/src/widgets/type_widgets/helpers/mind_map_images.ts
rename to apps/client/src/widgets/type_widgets/mind_map/images.ts
index 10d064c6be..c759fbcab4 100644
--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_images.ts
+++ b/apps/client/src/widgets/type_widgets/mind_map/images.ts
@@ -145,7 +145,7 @@ export function getNodeImageShape(image: NodeImage): NodeImageShape {
/**
* A picture of the map, fetched from where a node points at it and redrawn at about the size it is
- * shown at, as data that can be carried inside the exported SVG (see `mind_map_export`).
+ * shown at, as data that can be carried inside the exported SVG (see `export`).
*
* What has been fetched once is kept: the SVG is written again at every pause in the editing, and
* an address names one picture for good — a picture put in the place of another is stored anew and
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_links.spec.ts b/apps/client/src/widgets/type_widgets/mind_map/links.spec.ts
similarity index 98%
rename from apps/client/src/widgets/type_widgets/helpers/mind_map_links.spec.ts
rename to apps/client/src/widgets/type_widgets/mind_map/links.spec.ts
index f8af77e81b..4059597778 100644
--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_links.spec.ts
+++ b/apps/client/src/widgets/type_widgets/mind_map/links.spec.ts
@@ -1,7 +1,7 @@
import type { Suggestion } from "../../../services/note_autocomplete";
import { describe, expect, it } from "vitest";
-import { describeExternalLink, getNodeLinkHref, linkFromSuggestion, renderNodeLinks } from "./mind_map_links";
+import { describeExternalLink, getNodeLinkHref, linkFromSuggestion, renderNodeLinks } from "./links";
/** Builds the anchor Mind Elixir gives a node that carries a link. */
function buildNodes(...links: string[]) {
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_links.ts b/apps/client/src/widgets/type_widgets/mind_map/links.ts
similarity index 100%
rename from apps/client/src/widgets/type_widgets/helpers/mind_map_links.ts
rename to apps/client/src/widgets/type_widgets/mind_map/links.ts