Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:lipstick: Compact mind map toolbars and prioritize six color pairs https://github.com/siyuan-note/siyuan/issues/20856

Danieldc407a553d35
diff --git a/app/src/assets/scss/business/_color.scss b/app/src/assets/scss/business/_color.scss
index 3bfe3abf5a..222bba7059 100644
--- a/app/src/assets/scss/business/_color.scss
+++ b/app/src/assets/scss/business/_color.scss
@@ -22,6 +22,10 @@
margin: 0 8px 0 0;
}
+ &--compact {
+ margin: 0;
+ }
+
&:hover:not(.color__square--list):not(.color__square--current) {
box-shadow: 0 0 0 1px var(--b3-border-color) inset, 0 0 0 3px var(--b3-list-hover);
}
diff --git a/app/src/assets/scss/protyle/_mindmap-view.scss b/app/src/assets/scss/protyle/_mindmap-view.scss
index de430be4f9..d2a0d2706c 100644
--- a/app/src/assets/scss/protyle/_mindmap-view.scss
+++ b/app/src/assets/scss/protyle/_mindmap-view.scss
@@ -921,7 +921,7 @@
transform: translateX(-50%);
bottom: 8px;
z-index: 6;
- width: max-content;
+ width: 244px;
min-width: 0;
max-width: calc(100% - 16px);
padding: 4px;
@@ -946,9 +946,9 @@
}
&__inspector--node {
- .color__square {
- flex-shrink: 0;
- }
+ display: grid;
+ grid-template-columns: repeat(8, minmax(0, 1fr));
+ justify-items: center;
}
&__inspector--line {
@@ -959,6 +959,20 @@
.mindmap-view__palette {
margin: 0;
}
+
+ > .b3-select {
+ max-width: 100px;
+ min-width: 0;
+ }
+ }
+
+ &__inspector--relation {
+ width: max-content;
+
+ .mindmap-view__palette-row {
+ width: 176px;
+ flex-shrink: 0;
+ }
}
&__node-more {
@@ -983,17 +997,22 @@
}
&__palette-row {
- display: flex;
- align-items: flex-start;
+ display: grid;
+ grid-template-columns: repeat(var(--mindmap-toolbar-columns, 8), minmax(0, 1fr));
+ align-items: start;
+ justify-items: center;
min-width: 0;
+ width: 100%;
.mindmap-view__palette {
- flex: 1;
+ display: grid;
+ grid-auto-flow: column;
+ grid-auto-columns: calc(100% / var(--mindmap-palette-columns));
+ grid-column: span var(--mindmap-palette-columns);
+ justify-items: center;
+ width: 100%;
order: 0;
- }
-
- > .color__square {
- flex-shrink: 0;
+ scrollbar-width: none;
}
}
@@ -1011,19 +1030,23 @@
}
&__node-width {
- display: flex;
+ display: grid;
+ grid-template-columns: repeat(8, minmax(0, 1fr));
align-items: center;
- gap: 4px;
+ justify-items: center;
+ width: 100%;
flex-shrink: 0;
.b3-text-field {
- width: 80px;
+ grid-column: span 2;
+ width: 100%;
+ min-width: 0;
}
.b3-slider {
- width: 100px;
- min-width: 48px;
- flex: 1;
+ grid-column: span 4;
+ width: 100%;
+ min-width: 0;
}
.color__square {
@@ -1040,7 +1063,7 @@
width: max-content;
max-width: calc(100% - 16px);
gap: 4px;
- padding: 8px;
+ padding: 4px;
box-sizing: border-box;
overflow: auto;
@@ -1051,7 +1074,6 @@
.mindmap-view__node-width {
min-width: 0;
flex-shrink: 1;
- flex-wrap: wrap;
}
}
diff --git a/app/src/protyle/render/listMindmap/arrows.test.ts b/app/src/protyle/render/listMindmap/arrows.test.ts
index 00a58c1b74..6f9b8f2fd9 100644
--- a/app/src/protyle/render/listMindmap/arrows.test.ts
+++ b/app/src/protyle/render/listMindmap/arrows.test.ts
@@ -13,9 +13,9 @@ const source = createSourceFile("view.ts", readFileSync("src/protyle/render/list
const view = source.statements.find(item => isClassDeclaration(item) && item.name?.text === "ListMindmapView");
assert.ok(view && isClassDeclaration(view));
const methods = view.members.filter(item => ["relationPath", "draw", "resizeViewport", "getViewportAnchorY",
- "updateDocumentViewport", "rememberViewport", "findLine", "renderInspector"]
+ "updateDocumentViewport", "rememberViewport", "findLine", "renderInspector", "makePaletteRow"]
.includes(item.name?.getText(source)));
-assert.equal(methods.length, 8);
+assert.equal(methods.length, 9);
const compiled = transpileModule(`class View {
${methods.map(item => item.getText(source)).join("\n")}
}
@@ -287,7 +287,7 @@ test("the shared direction selector preserves focus and only patches arrow direc
class Control {
public children: Control[] = [];
public attributes = new Map<string, string>();
- public style: Record<string, string> = {};
+ public style = {setProperty: (name: string, value: string) => this.attributes.set(name, value)};
public classList = {add: () => {}, toggle: () => {}};
public events = new Map<string, () => void>();
public hidden = false;
diff --git a/app/src/protyle/render/listMindmap/clipboard.test.ts b/app/src/protyle/render/listMindmap/clipboard.test.ts
index 4bad0e653f..9c6c42d3d0 100644
--- a/app/src/protyle/render/listMindmap/clipboard.test.ts
+++ b/app/src/protyle/render/listMindmap/clipboard.test.ts
@@ -184,6 +184,9 @@ const browserCases = async (source: string, css: string) => {
view.renderInspector();
await wait();
const inspector = host.querySelector<HTMLElement>(".mindmap-view__inspector");
+ check.deepEqual(Array.from(inspector.children).map(item => item.getAttribute("aria-label")),
+ ["connect", "listMindmapSummary", "color", "width", "copy", "paste", "delete", "more"],
+ "the compact bar keeps eight actions in visual and keyboard order");
const more = inspector.querySelector<HTMLButtonElement>('[aria-label="more"]');
check.equal(inspector.lastElementChild, more, "More follows the node actions in keyboard order");
const right = more.getBoundingClientRect().right;
@@ -199,14 +202,15 @@ const browserCases = async (source: string, css: string) => {
pointer(a.id);
await checkNodeMenu();
const action = (key: string) => host.querySelector<HTMLButtonElement>(`.mindmap-view__inspector > [aria-label="${key}"]`);
- for (const key of ["copy", "cut", "paste"]) {
+ for (const key of ["copy", "paste"]) {
check.ok(action(key), `${key} is directly available on the bottom bar`);
check.equal(action(key).disabled, false);
action(key).dispatchEvent(new PointerEvent("pointerdown", {bubbles: true, pointerType: "touch", pointerId: 12}));
check.deepEqual(view.getSelectedIds(), [a.id], "touching a clipboard button keeps the node selection");
action(key).click();
}
- check.deepEqual(copied.map(item => item.cut), [false, true]);
+ check.equal(action("cut"), null, "cut remains available through More and clipboard shortcuts");
+ check.deepEqual(copied.map(item => item.cut), [false]);
check.deepEqual(pasted, [{id: a.id, kind: "child"}]);
copied.length = 0;
pasted.length = 0;
@@ -214,7 +218,6 @@ const browserCases = async (source: string, css: string) => {
await checkNodeMenu();
check.equal(action("paste").disabled, true, "multiple targets cannot receive a paste");
view.focusNode(model.root.id);
- check.equal(action("cut").disabled, true, "the map root cannot be cut away");
check.equal(action("delete").disabled, true, "the map root cannot be deleted");
pointer(a.id);
pointer(b.id, {ctrlKey: true});
diff --git a/app/src/protyle/render/listMindmap/clipboardMenu.test.ts b/app/src/protyle/render/listMindmap/clipboardMenu.test.ts
new file mode 100644
index 0000000000..24a6ce44a5
--- /dev/null
+++ b/app/src/protyle/render/listMindmap/clipboardMenu.test.ts
@@ -0,0 +1,74 @@
+import * as assert from "node:assert/strict";
+import {readFileSync} from "node:fs";
+import test from "node:test";
+import {runInNewContext} from "node:vm";
+import {createSourceFile, isPropertyAssignment, ScriptTarget, transpileModule} from "typescript";
+
+test("desktop and mobile More menus keep cut first and preserve paste restrictions and task status actions", () => {
+ const source = createSourceFile("index.ts", readFileSync("src/protyle/render/listMindmap/index.ts", "utf8"),
+ ScriptTarget.ES2021, true);
+ let callback = "";
+ const visit = (node: import("typescript").Node) => {
+ if (isPropertyAssignment(node) && node.name.getText(source) === "onClipboardMenu") {
+ callback = node.initializer.getText(source);
+ }
+ node.forEachChild(visit);
+ };
+ visit(source);
+ assert.ok(callback);
+ const compiled = transpileModule(`class Controller {openMore = ${callback};} globalThis.Controller = Controller;`,
+ {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
+ for (const mobile of [false, true]) {
+ for (const ids of [["child"], ["root"], ["child", "second"]]) {
+ for (const editable of [true, false]) {
+ const entries: IMenu[] = [];
+ const actions: unknown[] = [];
+ const placements: unknown[] = [];
+ const anchor = {getBoundingClientRect: () => ({left: 20, bottom: 100, height: 26})};
+ const model = {nodes: new Map([["root", {virtual: true}], ["child", {taskMarker: " "}], ["second", {}]])};
+ const context: any = {
+ owner: {}, list: {}, canEdit: () => editable, readListMindmap: () => model,
+ canCutMindmapBranches: (_model: unknown, selected: string[]) => !selected.includes("root"),
+ window: {siyuan: {languages: new Proxy({}, {get: (_target, key) => String(key)})}},
+ isMobile: () => mobile,
+ getTaskStatusItems: (marker: string, set: (marker: string) => void) => {
+ assert.equal(marker, " ");
+ return [{label: "Done", click: () => set("X")}];
+ },
+ toggleMenu: ({target, build}: {target: unknown, build: (menu: unknown, session: unknown) => void}) => {
+ assert.equal(target, anchor);
+ build(undefined, {show: (open: () => void) => open()});
+ },
+ Menu: class {
+ addItem(item: IMenu) { entries.push(item); }
+ open(position: unknown) { placements.push(position); }
+ fullscreen(position: unknown) { placements.push(position); }
+ },
+ };
+ runInNewContext(compiled, context);
+ const target = new context.Controller();
+ Object.assign(target, {model,
+ copyNodes: (...args: unknown[]) => actions.push(args),
+ pasteNodes: (...args: unknown[]) => actions.push(args),
+ setTask: (id: string, next: () => string) => actions.push([id, next()]),
+ });
+ target.openMore(anchor, ids);
+ assert.deepEqual(JSON.parse(JSON.stringify(placements)), [mobile ? "bottom" : {x: 20, y: 100, h: 26}]);
+ const expected = [...(editable && !ids.includes("root") ? ["cut"] : []), "copy",
+ ...(editable && ids.length === 1 ? ["mindmapPasteChild", ...(ids[0] === "root" ? [] : ["mindmapPasteSibling"])] : []),
+ ...(editable && ids.length === 1 && ids[0] === "child" ? ["checkToggle"] : [])];
+ assert.deepEqual(entries.map(item => item.label), expected);
+ assert.equal(actions.length, 0, "opening More does not modify document content");
+ entries.find(item => item.label === "cut")?.click(undefined, undefined);
+ if (expected.includes("cut")) {
+ assert.equal(JSON.stringify(actions.shift()), JSON.stringify([ids, true]));
+ }
+ const task = entries.find(item => item.label === "checkToggle");
+ if (task) {
+ (task.submenu as IMenu[])[0].click(undefined, undefined);
+ assert.deepEqual(actions.pop(), ["child", "X"]);
+ }
+ }
+ }
+ }
+});
diff --git a/app/src/protyle/render/listMindmap/colors.test.ts b/app/src/protyle/render/listMindmap/colors.test.ts
index 563cbc1bc1..5620c327ec 100644
--- a/app/src/protyle/render/listMindmap/colors.test.ts
+++ b/app/src/protyle/render/listMindmap/colors.test.ts
@@ -26,7 +26,7 @@ test("default node and line palettes have thirteen colors and retain existing se
assert.equal(JSON.stringify(data), before, "reading palettes does not migrate or overwrite workspace colors");
});
-test("workspace custom colors, hidden entries, ordering and light/dark values remain effective", () => {
+test("six built-in pairs precede scrolling colors while preserving hidden entries, custom ordering and mode values", () => {
const combinedID = "20260821120000-abcdefg";
const hiddenID = "20260821120000-bcdefgh";
const lineID = "20260821120000-cdefghi";
@@ -47,16 +47,17 @@ test("workspace custom colors, hidden entries, ordering and light/dark values re
const before = JSON.stringify(data);
for (const mode of ["light", "dark"] as const) {
const nodes = getListMindmapNodeColors(data, labels, mode);
- assert.deepEqual(nodes.slice(0, 4).map(item => item.label), ["Custom pair", "Success", "Info", "Error"]);
+ assert.deepEqual(nodes.slice(0, 5).map(item => item.label), ["Error", "Info", "Success", "Color 5", "Custom pair"]);
assert.equal(nodes.some(item => item.label === "Hidden pair" || item.label === "Warning"), false);
- assert.deepEqual(nodes.slice(4, 6).map(item => item.label), ["Color 13", "Color 5"]);
+ assert.equal(nodes[5].label, "Color 13", "remaining built-in colors retain their configured relative order");
assert.equal(nodes.some(item => item.backgroundColor === "var(--b3-font-background6)"), false);
- assert.deepEqual(nodes[2].preview, mode === "light" ?
+ assert.deepEqual(nodes[1].preview, mode === "light" ?
{color: "#112233", backgroundColor: "#ddeeff"} : {color: "#abcdef", backgroundColor: "#223344"});
- assert.match(nodes[0].color, new RegExp(mode === "light" ? "#112233" : "#abcdef"));
+ assert.match(nodes[4].color, new RegExp(mode === "light" ? "#112233" : "#abcdef"));
const lines = getListMindmapLineColors(data, labels, mode);
- assert.deepEqual(lines.slice(0, 3).map(item => item.label), ["Custom line", "Color 13", "Color 1"]);
- assert.match(lines[0].value, new RegExp(mode === "light" ? "#123456" : "#fedcba"));
+ assert.deepEqual(lines.slice(0, 7).map(item => item.label),
+ ["Color 1", "Color 3", "Color 4", "Color 5", "Color 6", "Custom line", "Color 13"]);
+ assert.match(lines[5].value, new RegExp(mode === "light" ? "#123456" : "#fedcba"));
assert.equal(lines.some(item => item.value === "var(--b3-font-color2)"), false);
}
assert.equal(JSON.stringify(data), before);
diff --git a/app/src/protyle/render/listMindmap/colors.ts b/app/src/protyle/render/listMindmap/colors.ts
index 5a5e78bba5..c7f57c66ea 100644
--- a/app/src/protyle/render/listMindmap/colors.ts
+++ b/app/src/protyle/render/listMindmap/colors.ts
@@ -5,14 +5,19 @@ import {
} from "../../toolbar/inlineStyle";
import type {IInlineStyles, TBuiltinInlineStyleID, TInlineStyleMode, TInlineStyleType} from "../../toolbar/inlineStyle";
+const prioritizeColors = <T>(items: {key: string, value: T}[], keys: readonly string[]): T[] => [
+ ...keys.flatMap(key => items.filter(item => item.key === key)),
+ ...items.filter(item => !keys.includes(item.key)),
+].map(item => item.value);
+
export const getListMindmapLineColors = (data: IInlineStyles, labels: Record<string, string>, mode: TInlineStyleMode) =>
- getVisibleOrderedStyleKeys("color", data).map(key => {
+ prioritizeColors(getVisibleOrderedStyleKeys("color", data).map(key => {
if (isBuiltinOrderKey("color", key)) {
- return {label: `${labels.color} ${key}`, value: getBuiltinColorPropertyValue(Number(key), "color")};
+ return {key, value: {label: `${labels.color} ${key}`, value: getBuiltinColorPropertyValue(Number(key), "color")}};
}
const style = getInlineStyleByID(key, data);
- return {label: style.name, value: getInlineStylePropertyValue(style, "color", mode)};
- });
+ return {key, value: {label: style.name, value: getInlineStylePropertyValue(style, "color", mode)}};
+ }), ["1", "2", "3", "4", "5", "6"]);
export const getListMindmapNodeColors = (data: IInlineStyles, labels: Record<string, string>, mode: TInlineStyleMode): {
label: string, color: string, backgroundColor: string, preview?: {color: string, backgroundColor: string},
@@ -20,22 +25,21 @@ export const getListMindmapNodeColors = (data: IInlineStyles, labels: Record<str
const combined = getVisibleOrderedStyleKeys("style1", data).map(key => {
if (isBuiltinOrderKey("style1", key)) {
const id = key as TBuiltinInlineStyleID;
- return {label: labels[`${key}Style`],
+ return {key, value: {label: labels[`${key}Style`],
color: getBuiltinInlineStylePropertyValue(id, "color"),
backgroundColor: getBuiltinInlineStylePropertyValue(id, "backgroundColor"),
- preview: getBuiltinInlineStylePreview(id, mode, data)};
+ preview: getBuiltinInlineStylePreview(id, mode, data)}};
}
const style = getInlineStyleByID(key, data);
- return {label: style.name, ...getInlineStylePreview(style, mode)};
+ return {key, value: {label: style.name, ...getInlineStylePreview(style, mode)}};
});
- // The first four font colors already have semantic combined styles. Complete the
- // remaining pairs without changing their variables or the workspace configuration.
+ // 前四组使用语义组合样式,其余组合沿用现有文字和背景变量,不改写工作空间配置。
const remaining = getVisibleOrderedStyleKeys("backgroundColor", data)
.filter(key => isBuiltinOrderKey("backgroundColor", key) && Number(key) > BUILTIN_INLINE_STYLE_IDS.length)
- .map(key => ({label: `${labels.color} ${key}`,
+ .map(key => ({key, value: {label: `${labels.color} ${key}`,
color: getBuiltinColorPropertyValue(Number(key), "color"),
- backgroundColor: getBuiltinColorPropertyValue(Number(key), "backgroundColor")}));
- return [...combined, ...remaining];
+ backgroundColor: getBuiltinColorPropertyValue(Number(key), "backgroundColor")}}));
+ return prioritizeColors([...combined, ...remaining], [...BUILTIN_INLINE_STYLE_IDS, "5", "6"]);
};
export const getListMindmapNodeColorMenu = (labels: Record<string, string>, select: (type: TInlineStyleType) => void): IMenu[] =>
diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.ts
index 3cddf96ee6..28d3b09031 100644
--- a/app/src/protyle/render/listMindmap/index.ts
+++ b/app/src/protyle/render/listMindmap/index.ts
@@ -406,12 +406,12 @@ class ListMindmapController {
onClipboardMenu: (anchor, ids) => {
toggleMenu({target: anchor, build: (_menu, session) => {
const menu = new Menu();
- menu.addItem({label: window.siyuan.languages.copy, icon: "iconCopy",
- click: () => void this.copyNodes(ids, false)});
if (canEdit(owner, list) && canCutMindmapBranches(readListMindmap(list), ids)) {
menu.addItem({label: window.siyuan.languages.cut, icon: "iconCut",
click: () => void this.copyNodes(ids, true)});
}
+ menu.addItem({label: window.siyuan.languages.copy, icon: "iconCopy",
+ click: () => void this.copyNodes(ids, false)});
if (ids.length === 1 && canEdit(owner, list)) {
menu.addItem({label: window.siyuan.languages.mindmapPasteChild, icon: "iconPaste",
click: () => void this.pasteNodes(ids[0], "child")});
@@ -420,8 +420,17 @@ class ListMindmapController {
click: () => void this.pasteNodes(ids[0], "sibling")});
}
}
+ const marker = ids.length === 1 ? this.model.nodes.get(ids[0])?.taskMarker : undefined;
+ if (marker !== undefined && canEdit(owner, list)) {
+ menu.addItem({label: window.siyuan.languages.checkToggle, icon: "iconCheck",
+ submenu: getTaskStatusItems(marker, next => this.setTask(ids[0], () => next))});
+ }
const rect = anchor.getBoundingClientRect();
- session.show(() => menu.open({x: rect.left, y: rect.bottom, h: rect.height}));
+ if (isMobile()) {
+ session.show(() => menu.fullscreen("bottom"));
+ } else {
+ session.show(() => menu.open({x: rect.left, y: rect.bottom, h: rect.height}));
+ }
}});
},
isAddSiblingShortcut: event => {
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index 8ac4efe5ed..e53f85bc56 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -2230,6 +2230,9 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
const popup = host.querySelector<HTMLElement>(".mindmap-view__inspector-popover");
const palettes = popup.querySelectorAll<HTMLElement>(".mindmap-view__palette");
check.equal(palettes.length, 2);
+ check.equal(popup.getBoundingClientRect().width, inspector.getBoundingClientRect().width,
+ "the palette popup matches the eight-action toolbar at every canvas width");
+ check.equal(popup.getBoundingClientRect().left, inspector.getBoundingClientRect().left);
check.equal(palettes[0].getAttribute("aria-label"), "listMindmapNodeColor");
check.equal(palettes[1].getAttribute("aria-label"), "listMindmapLineColor");
check.equal(popup.children.length, 2, "the popup has only two compact rows without visible headings");
@@ -2248,13 +2251,11 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
const buttons = Array.from(palette.children) as HTMLElement[];
check.equal(new Set(buttons.map(button => button.offsetTop)).size, 1, "each palette keeps one row");
check.ok(palette.getBoundingClientRect().right <= palette.nextElementSibling.getBoundingClientRect().left);
- if (width < 760) {
- check.ok(palette.scrollWidth > palette.clientWidth, "narrow palettes scroll horizontally");
- }
- }
- if (width === 760) {
- check.equal(palettes[1].scrollWidth, palettes[1].clientWidth,
- "the normal line palette fits one row on a wide canvas");
+ check.ok(palette.scrollWidth > palette.clientWidth, "additional colors scroll even on wide canvases");
+ check.ok(buttons[6].getBoundingClientRect().right <= palette.getBoundingClientRect().right + 1,
+ "default and six colors fit before the fixed settings column");
+ check.ok(buttons[7].getBoundingClientRect().left >= palette.getBoundingClientRect().right - 1,
+ "the next color stays outside the first page");
}
const beforeSettings = nodeStyles.length;
managers[0].focus();
@@ -2296,6 +2297,22 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(host.querySelector<HTMLElement>(".mindmap-view__inspector-popover").hidden, false,
"a native touch tap opens the same compact two-row palette");
check.deepEqual(view.getSelectedIds(), paletteSelection, "opening the palette by touch preserves the selected nodes");
+ const touchPalette = host.querySelector<HTMLElement>(".mindmap-view__inspector-popover .mindmap-view__palette");
+ const touchBounds = touchPalette.getBoundingClientRect();
+ const touchManager = touchPalette.nextElementSibling;
+ const managerPosition = touchManager.getBoundingClientRect().left;
+ const beforeColorSwipe = nodeStyles.length;
+ const swipeStart = {x: Math.round(touchBounds.right - 12), y: Math.round(touchBounds.top + touchBounds.height / 2)};
+ await require("electron").ipcRenderer.invoke("mindmap-view-native-touch", [
+ {type: "touchStart", touchPoints: [{id: 1, ...swipeStart}]},
+ ...[20, 40, 60, 80, 100, 120].map(delta => ({type: "touchMove",
+ touchPoints: [{id: 1, x: swipeStart.x - delta, y: swipeStart.y}]})),
+ {type: "touchEnd", touchPoints: []},
+ ]);
+ await settle();
+ check.ok(touchPalette.scrollLeft > 0, "a native horizontal swipe reaches colors beyond the first six groups");
+ check.equal(touchManager.getBoundingClientRect().left, managerPosition, "swiping the palette keeps color settings fixed");
+ check.equal(nodeStyles.length, beforeColorSwipe, "swiping colors does not apply a color or alter document styles");
options.colors = originalLineColors;
view.focusNode(beta);
host.style.cssText = originalHostStyle;
@@ -2311,6 +2328,13 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
inspector.querySelector<HTMLButtonElement>('[aria-label="width"]').click();
const nodePopup = host.querySelector<HTMLElement>(".mindmap-view__inspector-popover");
const widthInput = () => nodePopup.querySelector<HTMLInputElement>('input[type="number"]');
+ check.equal(nodePopup.getBoundingClientRect().width, inspector.getBoundingClientRect().width);
+ const widthControls = nodePopup.querySelector(".mindmap-view__node-width");
+ check.deepEqual(Array.from(widthControls.children).map(control => control.tagName === "INPUT" ?
+ control.getAttribute("type") : control.getAttribute("aria-label")),
+ ["number", "range", "listMindmapRestoreWidth", "default"], "the width input precedes the centered slider and reset controls");
+ check.ok(Math.abs(widthInput().getBoundingClientRect().width - inspector.getBoundingClientRect().width / 4 + 2) < 2,
+ "the numeric input occupies two of the eight columns");
widthInput().value = "640";
widthInput().dispatchEvent(new Event("change", {bubbles: true}));
await settle();
@@ -4892,6 +4916,8 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
let summaryView: any;
summaryView = new api.ListMindmapView({host: summaryHost, model: summaryModel, onExit: () => {},
labels: new Proxy({}, {get: (_target, key) => String(key)}),
+ colors: () => Array.from({length: 13}, (_, i) => ({label: `Summary color ${i}`, value: `rgb(${i}, 0, 0)`})),
+ onManageLineColors: () => {},
onSummaryBatchAdd: async (ranges: any[], expected: string) => {
const model = api.readListMindmap(summaryList);
check.equal(api.getListMindmapSummarySnapshot(model), expected);
@@ -5050,6 +5076,30 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(summaryView.pointer, undefined, "selecting a summary does not start canvas or node dragging");
summaryLabel.click();
check.equal(summaryView.selectedSummary, "summary", "touching the summary selects it");
+ const summaryInspector = summaryHost.querySelector<HTMLElement>(".mindmap-view__inspector");
+ let summaryEdit = summaryInspector.querySelector<HTMLButtonElement>('[aria-label="edit"]');
+ check.ok(summaryEdit, "summary editing retains its explicit toolbar entry");
+ for (const width of [240, 320, 700]) {
+ summaryHost.style.width = `${width}px`;
+ summaryView.renderInspector();
+ await settle();
+ const summaryPalette = summaryInspector.querySelector<HTMLElement>(".mindmap-view__palette");
+ const fixed = ["edit", "delete", "listMindmapManageLineColors"]
+ .map(key => summaryInspector.querySelector<HTMLElement>(`[aria-label="${key}"]`));
+ const positions = fixed.map(control => control.getBoundingClientRect().left);
+ summaryPalette.scrollLeft = summaryPalette.scrollWidth;
+ check.deepEqual(fixed.map(control => control.getBoundingClientRect().left), positions,
+ "summary edit, delete and color settings stay fixed while colors scroll");
+ const bounds = summaryInspector.getBoundingClientRect();
+ fixed.forEach(control => check.ok(control.getBoundingClientRect().right <= bounds.right));
+ check.equal(summaryPalette.children.length, 14, "all existing summary colors remain accessible");
+ }
+ summaryHost.style.width = "700px";
+ summaryEdit = summaryInspector.querySelector<HTMLButtonElement>('[aria-label="edit"]');
+ summaryEdit.click();
+ check.ok(summaryHost.querySelector(".mindmap-view__summary-editor"), "the retained edit button opens summary text editing");
+ summaryHost.querySelector<HTMLInputElement>(".mindmap-view__summary-editor")
+ .dispatchEvent(new KeyboardEvent("keydown", {key: "Escape", bubbles: true}));
summaryLabel.dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
const reopenedSummary = summaryHost.querySelector<HTMLInputElement>(".mindmap-view__summary-editor");
check.ok(reopenedSummary);
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index 92d89dd643..4a62311c34 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -23,7 +23,6 @@ import {getListMindmapSummarySelection, getListMindmapSummarySnapshot,
import type {ListMindmapSummary, ListMindmapSummaryPosition, ListMindmapSummaryRange} from "./summary";
import {buildListMindmapConnectors, buildListMindmapSummaryConnector} from "./connectors";
import {getMindmapLineColor, getMindmapTextColor, isMindmapColor, resolveListMindmapColors} from "./appearance";
-import {canCutMindmapBranches} from "./clipboard";
import type {ListMindmapViewport} from "./viewport";
export interface ListMindmapViewOptions {
@@ -3726,7 +3725,6 @@ export class ListMindmapView {
}
const host = this.options.host.getBoundingClientRect();
const visible = this.getVisibleViewportBounds();
- const anchor = this.inspectorPanel.anchor.getBoundingClientRect();
const scaleX = host.width / this.options.host.offsetWidth || 1;
const scaleY = host.height / this.options.host.offsetHeight || 1;
const bar = this.inspector.getBoundingClientRect();
@@ -3734,6 +3732,7 @@ export class ListMindmapView {
const below = (visible.bottom - bar.bottom) / scaleY - 12;
const width = Math.max(0, (visible.right - visible.left) / scaleX - 16);
this.inspectorPopover.style.maxWidth = `${width}px`;
+ this.inspectorPopover.style.width = `${Math.min(width, bar.width / scaleX)}px`;
const height = this.inspectorPopover.scrollHeight +
this.inspectorPopover.offsetHeight - this.inspectorPopover.clientHeight;
const placeAbove = above >= height || above >= below;
@@ -3741,8 +3740,7 @@ export class ListMindmapView {
this.inspectorPopover.style.maxHeight = `${available}px`;
this.inspectorPopover.style.visibility = this.inspector.style.visibility === "hidden" ||
!width || !available ? "hidden" : "";
- const left = (anchor.left + anchor.width / 2 - host.left) / scaleX -
- this.options.host.clientLeft - this.inspectorPopover.offsetWidth / 2;
+ const left = (bar.left - host.left) / scaleX - this.options.host.clientLeft;
const minLeft = (visible.left - host.left) / scaleX - this.options.host.clientLeft + 8;
this.inspectorPopover.style.left = `${Math.max(minLeft,
Math.min(left, minLeft + width - this.inspectorPopover.offsetWidth))}px`;
@@ -3790,6 +3788,14 @@ export class ListMindmapView {
}
}
+ private makePaletteRow(palette: HTMLElement, controls: HTMLElement[], columns = 8) {
+ const row = createElement("div", "mindmap-view__palette-row");
+ row.style.setProperty("--mindmap-palette-columns", String(columns - controls.length));
+ row.style.setProperty("--mindmap-toolbar-columns", String(columns));
+ row.append(palette, ...controls);
+ return row;
+ }
+
private renderInspectorPanel() {
const panel = this.inspectorPanel;
if (!panel) {
@@ -3804,7 +3810,7 @@ export class ListMindmapView {
JSON.stringify(panel.ids) === JSON.stringify(this.getSelectedIds());
const button = (key: string, icon: string, action: () => void) => {
const control = this.makeButton(key, icon, () => { if (current()) { action(); } });
- control.className = "color__square";
+ control.className = "color__square color__square--compact";
control.querySelector("svg")?.classList.add("svg--mid");
return control;
};
@@ -3836,14 +3842,13 @@ export class ListMindmapView {
control.style.backgroundColor = item.preview?.backgroundColor ?? item.backgroundColor;
palette.append(control);
});
- const row = createElement("div", "mindmap-view__palette-row");
- row.append(palette);
+ const controls: HTMLElement[] = [];
if (this.options.onManageNodeColors) {
const manage = button("listMindmapManageNodeColors", "iconFont", () => this.options.onManageNodeColors(manage));
manage.setAttribute("aria-haspopup", "menu");
- row.append(manage);
+ controls.push(manage);
}
- this.inspectorPopover.append(row);
+ this.inspectorPopover.append(this.makePaletteRow(palette, controls));
if (panel.ids.length > 1) {
const lines = createElement("div", "mindmap-view__palette");
lines.setAttribute("role", "group");
@@ -3854,12 +3859,11 @@ export class ListMindmapView {
control.style.backgroundColor = item.value || "var(--b3-theme-background)";
lines.append(control);
});
- const lineRow = createElement("div", "mindmap-view__palette-row");
- lineRow.append(lines);
+ const lineControls = [];
if (this.options.onManageLineColors) {
- lineRow.append(button("listMindmapManageLineColors", "iconLine", this.options.onManageLineColors));
+ lineControls.push(button("listMindmapManageLineColors", "iconLine", this.options.onManageLineColors));
}
- this.inspectorPopover.append(lineRow);
+ this.inspectorPopover.append(this.makePaletteRow(lines, lineControls));
}
} else {
const row = createElement("div", "mindmap-view__node-width");
@@ -3871,7 +3875,7 @@ export class ListMindmapView {
slider.value = String(panel.slider);
slider.setAttribute("aria-label", this.label("width"));
slider.dataset.widthControl = "slider";
- const width = createElement("input", "b3-text-field");
+ const width = createElement("input", "b3-text-field b3-text-field--size");
width.type = "number";
width.min = "32";
width.step = "1";
@@ -3914,7 +3918,7 @@ export class ListMindmapView {
void this.commitInspectorWidths(panel.ids.map(id => ({id, width: 0})));
});
[slider, width, restore, automatic].forEach(control => control.disabled = this.widthPending);
- row.append(slider, width, restore, automatic);
+ row.append(width, slider, restore, automatic);
this.inspectorPopover.append(row);
if (focus) {
this.inspectorPopover.querySelector<HTMLInputElement>(`[data-width-control="${focus}"]`)?.focus({preventScroll: true});
@@ -3934,15 +3938,16 @@ export class ListMindmapView {
const lineSelected = !!this.selectedRelation || !!this.selectedEdge || !!this.selectedSummary;
this.inspector.classList.toggle("mindmap-view__inspector--node", !lineSelected);
this.inspector.classList.toggle("mindmap-view__inspector--line", lineSelected);
+ this.inspector.classList.toggle("mindmap-view__inspector--relation", !!this.selectedRelation);
this.inspector.style.left = "";
this.inspector.style.top = "";
const squareButton = (key: string, icon: string, action: () => void) => {
const button = this.makeButton(key, icon, action);
- button.className = "color__square";
+ button.className = "color__square color__square--compact";
button.querySelector("svg").classList.add("svg--mid");
return button;
};
- const color = (value: string, action: (value: string) => void, key = "color") => {
+ const color = (value: string, action: (value: string) => void, controls: HTMLElement[] = [], key = "color") => {
const palette = createElement("div", "mindmap-view__palette");
palette.setAttribute("role", "group");
palette.setAttribute("aria-label", this.label(key));
@@ -3950,23 +3955,23 @@ export class ListMindmapView {
colors.forEach(item => {
const button = this.makeButton("color", "", () => action(item.value));
const selected = (value || "") === item.value;
- button.className = "color__square" + (selected ? " color__square--current" : "");
+ button.className = "color__square color__square--compact" + (selected ? " color__square--current" : "");
button.setAttribute("aria-label", item.label);
button.setAttribute("aria-pressed", String(selected));
button.style.backgroundColor = item.value || "var(--b3-theme-background)";
palette.append(button);
});
if (this.options.onManageLineColors) {
- palette.append(squareButton("listMindmapManageLineColors", "iconLine", this.options.onManageLineColors));
+ controls.push(squareButton("listMindmapManageLineColors", "iconLine", this.options.onManageLineColors));
}
- this.inspector.append(palette);
+ this.inspector.append(this.makePaletteRow(palette, controls, this.selectedRelation ? 6 : 8));
};
if (this.selectedSummary) {
const summary = this.model.metadata.summaries?.find(item => item.id === this.selectedSummary);
if (summary) {
- color(summary.color, value => this.options.onSummaryChange?.(summary.id, {color: value}));
- this.inspector.append(squareButton("edit", "iconEdit", () => this.editSummaryLabel(summary.id)),
- squareButton("delete", "iconTrashcan", () => this.options.onSummaryDelete?.(summary.id)));
+ color(summary.color, value => this.options.onSummaryChange?.(summary.id, {color: value}),
+ [squareButton("edit", "iconEdit", () => this.editSummaryLabel(summary.id)),
+ squareButton("delete", "iconTrashcan", () => this.options.onSummaryDelete?.(summary.id))]);
}
return;
}
@@ -4024,20 +4029,14 @@ export class ListMindmapView {
const remove = squareButton("delete", "iconTrashcan", () => this.deleteSelection());
remove.disabled = ids.includes(this.model.root.id) ||
this.model.root.virtual && this.model.root.children.every(node => ids.includes(node.id));
- this.inspector.append(remove);
+ const clipboard: HTMLButtonElement[] = [];
if (this.options.onCopy) {
const copy = squareButton("copy", "iconCopy", () => {
if (sameSelection()) {
this.options.onCopy(ids, false);
}
});
- const cut = squareButton("cut", "iconCut", () => {
- if (sameSelection() && canCutMindmapBranches(this.model, ids)) {
- this.options.onCopy(ids, true);
- }
- });
- cut.disabled = !canCutMindmapBranches(this.model, ids);
- this.inspector.append(copy, cut);
+ clipboard.push(copy);
}
if (this.options.onPaste) {
const paste = squareButton("paste", "iconPaste", () => {
@@ -4047,9 +4046,13 @@ export class ListMindmapView {
});
paste.disabled = multiple;
paste.dataset.tooltip = this.label("mindmapPasteChild");
- this.inspector.append(paste);
+ clipboard.push(paste);
}
- this.inspector.append(this.buttons.get("relation"), this.buttons.get("summary"));
+ const relation = this.buttons.get("relation");
+ const summary = this.buttons.get("summary");
+ relation.classList.add("color__square--compact");
+ summary.classList.add("color__square--compact");
+ this.inspector.append(relation, summary);
for (const [kind, key, icon] of [["color", "color", "iconFont"], ["width", "width", "iconWidth"]] as const) {
const button = squareButton(key, icon, () => this.openInspectorPanel(kind, button));
button.setAttribute("aria-expanded", String(this.inspectorPanel?.kind === kind));
@@ -4065,15 +4068,7 @@ export class ListMindmapView {
this.renderInspectorPanel();
}
}
- if (multiple) {
- appendMore();
- return;
- }
- const node = this.model.nodes.get(id);
- if (node?.taskMarker !== undefined && this.options.onTaskMenu) {
- const task = squareButton("checkToggle", "iconCheck", () => this.openTaskMenu(id, task));
- this.inspector.append(task);
- }
+ this.inspector.append(...clipboard, remove);
appendMore();
}