Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(diagram): streamline editing feedback

tianma-ifcc73ff417042
diff --git a/apps/web/src/components/DiagramEditorPane.test.mjs b/apps/web/src/components/DiagramEditorPane.test.mjs
index baff7383..21063c7c 100644
--- a/apps/web/src/components/DiagramEditorPane.test.mjs
+++ b/apps/web/src/components/DiagramEditorPane.test.mjs
@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
const source = readFileSync(new URL("./DiagramEditorPane.tsx", import.meta.url), "utf8");
+const globalStyles = readFileSync(new URL("../styles/globals.css", import.meta.url), "utf8");
describe("diagram editor keyboard workflow", () => {
test("supports direct node editing without routing keystrokes through the side panel", () => {
@@ -36,6 +37,15 @@ describe("diagram editor keyboard workflow", () => {
});
describe("diagram editor canvas surface", () => {
+ test("autosaves diagram changes without a persistent save button", () => {
+ expect(source).toContain("EDITOR_LOCAL_SAVE_DELAY_MS");
+ expect(source).toContain("window.setTimeout(() => saveRef.current(), EDITOR_LOCAL_SAVE_DELAY_MS)");
+ expect(source).toContain("[dirty, dirtyVersion, editSessionReady, readOnly, saveFailed, saving]");
+ expect(source).toContain("!readOnly && saveFailed");
+ expect(source).toContain('t("diagram.retrySave")');
+ expect(source).not.toContain('<Save className="h-4 w-4" />');
+ });
+
test("uses a clean grid-free canvas for both diagram types", () => {
expect(source).toContain("grid: false");
expect(source).toContain("graph.clearGrid();");
@@ -62,6 +72,13 @@ describe("diagram editor canvas surface", () => {
expect(source).toContain("data-diagram-kind={document.kind}");
});
+ test("shows connection handles only on selected flowchart nodes", () => {
+ expect(globalStyles).toContain('.edgeever-diagram-canvas[data-diagram-kind="flowchart"] .x6-node.x6-node-selected .x6-port-body');
+ expect(globalStyles).toContain("pointer-events: none");
+ expect(globalStyles).toContain("pointer-events: auto");
+ expect(globalStyles).not.toContain('.edgeever-diagram-canvas[data-diagram-kind="flowchart"] .x6-node:hover .x6-port-body');
+ });
+
test("turns a connection dropped on blank canvas into a connected-node picker", () => {
expect(source).toContain('graph.on("edge:connected"');
expect(source).toContain('role="dialog"');
diff --git a/apps/web/src/components/DiagramEditorPane.tsx b/apps/web/src/components/DiagramEditorPane.tsx
index 68e7abb0..22b3ba4c 100644
--- a/apps/web/src/components/DiagramEditorPane.tsx
+++ b/apps/web/src/components/DiagramEditorPane.tsx
@@ -13,7 +13,7 @@ import {
Link2,
Maximize2,
Redo2,
- Save,
+ RefreshCw,
Trash2,
Undo2,
ZoomIn,
@@ -47,6 +47,7 @@ import { isLocalMemoId } from "@/lib/local-mirror";
import { isBrowserOffline } from "@/lib/network-status";
import type { EdgeEverRepository } from "@/lib/repository";
import { cn } from "@/lib/utils";
+import { EDITOR_LOCAL_SAVE_DELAY_MS } from "@/lib/app-helpers";
type DiagramEditorPaneProps = {
memo: MemoDetail;
@@ -375,9 +376,11 @@ export const DiagramEditorPane = ({ memo, repository, readOnly, onBackToList, on
const [selectedNodeLabel, setSelectedNodeLabel] = useState("");
const [hasSelection, setHasSelection] = useState(false);
const [dirty, setDirty] = useState(false);
+ const [dirtyVersion, setDirtyVersion] = useState(0);
const [saving, setSaving] = useState(false);
const [editSessionReady, setEditSessionReady] = useState(false);
const [saveError, setSaveError] = useState<string | null>(null);
+ const [saveFailed, setSaveFailed] = useState(false);
const [confirmDiscardOpen, setConfirmDiscardOpen] = useState(false);
const [historyState, setHistoryState] = useState({ undo: false, redo: false });
const [nodeEditor, setNodeEditor] = useState<NodeEditorState | null>(null);
@@ -446,6 +449,7 @@ export const DiagramEditorPane = ({ memo, repository, readOnly, onBackToList, on
savedSnapshotRef.current = document ? diagramEditorSnapshot(memo.title ?? "", document) : "";
setDirty(false);
setSaveError(null);
+ setSaveFailed(false);
editSessionRef.current = null;
setEditSessionReady(false);
if (readOnly || isLocalMemoId(memo.id) || isBrowserOffline() || window.edgeeverDesktop?.isAvailable) {
@@ -551,7 +555,9 @@ export const DiagramEditorPane = ({ memo, repository, readOnly, onBackToList, on
const markDirty = () => {
if (!readOnly) {
const currentDocument = graphToDocument(graph, document.kind, themeRef.current);
- setDirty(savedSnapshotRef.current !== diagramEditorSnapshot(titleRef.current, currentDocument));
+ const hasChanges = savedSnapshotRef.current !== diagramEditorSnapshot(titleRef.current, currentDocument);
+ setDirty(hasChanges);
+ if (hasChanges) setDirtyVersion((current) => current + 1);
}
updateHistory();
};
@@ -1143,10 +1149,12 @@ export const DiagramEditorPane = ({ memo, repository, readOnly, onBackToList, on
if (!graph || !document || !editSession || readOnly || saving) return;
setSaving(true);
setSaveError(null);
+ setSaveFailed(false);
try {
const nextDocument = graphToDocument(graph, document.kind, themeRef.current);
const markdown = serializeDiagramDocument(nextDocument);
const nextTitle = titleRef.current;
+ const nextSnapshot = diagramEditorSnapshot(nextTitle, nextDocument);
const result = await repository.updateMemo(currentMemo, {
expectedRevision: currentMemo.revision,
expectedContentHash: currentMemo.contentHash,
@@ -1157,12 +1165,20 @@ export const DiagramEditorPane = ({ memo, repository, readOnly, onBackToList, on
tags: currentMemo.tags,
});
memoRef.current = result.memo;
- savedSnapshotRef.current = diagramEditorSnapshot(nextTitle, nextDocument);
- setDirty(false);
- graph.cleanHistory();
- setHistoryState({ undo: false, redo: false });
- await onSaved(result.memo);
+ savedSnapshotRef.current = nextSnapshot;
+ const currentSnapshot = diagramEditorSnapshot(
+ titleRef.current,
+ graphToDocument(graph, document.kind, themeRef.current),
+ );
+ const hasNewChanges = currentSnapshot !== nextSnapshot;
+ setDirty(hasNewChanges);
+ if (!hasNewChanges) {
+ graph.cleanHistory();
+ setHistoryState({ undo: false, redo: false });
+ await onSaved(result.memo);
+ }
} catch (error) {
+ setSaveFailed(true);
setSaveError(error instanceof Error ? error.message : t("diagram.saveError"));
} finally {
setSaving(false);
@@ -1170,6 +1186,12 @@ export const DiagramEditorPane = ({ memo, repository, readOnly, onBackToList, on
};
saveRef.current = () => { void save(); };
+ useEffect(() => {
+ if (readOnly || !dirty || saving || !editSessionReady || saveFailed) return;
+ const timer = window.setTimeout(() => saveRef.current(), EDITOR_LOCAL_SAVE_DELAY_MS);
+ return () => window.clearTimeout(timer);
+ }, [dirty, dirtyVersion, editSessionReady, readOnly, saveFailed, saving]);
+
if (!document) return null;
const kindLabel = document.kind === "mind-map" ? t("diagram.mindMap") : t("diagram.flowchart");
@@ -1197,6 +1219,7 @@ export const DiagramEditorPane = ({ memo, repository, readOnly, onBackToList, on
const nextTitle = event.target.value;
titleRef.current = nextTitle;
setTitle(nextTitle);
+ setDirtyVersion((current) => current + 1);
const graph = graphRef.current;
if (graph) {
setDirty(savedSnapshotRef.current !== diagramEditorSnapshot(
@@ -1206,12 +1229,12 @@ export const DiagramEditorPane = ({ memo, repository, readOnly, onBackToList, on
}
}}
/>
- <span className={cn("hidden text-xs sm:block", saveError ? "text-rose-600" : dirty ? "text-amber-600" : "text-slate-400")}>{saveError ?? (dirty ? t("diagram.unsaved") : t("diagram.saved"))}</span>
+ <span className={cn("hidden text-xs sm:block", saveError ? "text-rose-600" : "text-slate-400")}>{saveError ?? (dirty || saving ? t("diagram.saving") : t("diagram.saved"))}</span>
<ThemeToggle />
- {!readOnly && (
- <Button variant="solid" size="sm" disabled={!dirty || saving || !editSessionReady} onClick={() => void save()}>
- <Save className="h-4 w-4" />
- {saving ? t("diagram.saving") : t("diagram.save")}
+ {!readOnly && saveFailed && (
+ <Button variant="soft" size="sm" disabled={saving || !editSessionReady} onClick={() => void save()}>
+ <RefreshCw className="h-4 w-4" />
+ {t("diagram.retrySave")}
</Button>
)}
</header>
diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.css
index 3c6217ab..1cddf831 100644
--- a/apps/web/src/styles/globals.css
+++ b/apps/web/src/styles/globals.css
@@ -506,10 +506,14 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {
.edgeever-diagram-canvas[data-diagram-kind="flowchart"] .x6-port-body {
cursor: crosshair;
- opacity: 0.88;
+ pointer-events: none;
+}
+
+.edgeever-diagram-canvas[data-diagram-kind="flowchart"] .x6-node.x6-node-selected .x6-port-body {
+ opacity: 1;
+ pointer-events: auto;
}
-.edgeever-diagram-canvas[data-diagram-kind="flowchart"] .x6-node:hover .x6-port-body,
.edgeever-diagram-canvas[data-diagram-kind="flowchart"] .x6-port-body:hover,
.edgeever-diagram-canvas[data-diagram-kind="flowchart"] .x6-available-magnet {
filter: drop-shadow(0 1px 3px rgb(var(--brand-green-rgb) / 0.28));
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 3831fe1a..b5b1cf2f 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -270,7 +270,7 @@ export const enUS = {
fit: "Fit diagram",
autoLayout: "Auto-arrange",
theme: "Diagram theme",
- themeBrand: "EdgeEver",
+ themeBrand: "Forest Green",
themeOcean: "Mint paper",
themeInk: "Deep forest",
export: "Export",
@@ -278,6 +278,7 @@ export const enUS = {
exportSvg: "Export SVG",
exportError: "Could not export the diagram",
save: "Save",
+ retrySave: "Retry save",
saving: "Saving",
saved: "Saved",
unsaved: "Unsaved changes",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 920e4569..39fa5f13 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -270,7 +270,7 @@ export const zhCN = {
fit: "适应画布",
autoLayout: "自动整理布局",
theme: "图表主题",
- themeBrand: "EdgeEver",
+ themeBrand: "森绿",
themeOcean: "薄荷纸",
themeInk: "深林",
export: "导出",
@@ -278,6 +278,7 @@ export const zhCN = {
exportSvg: "导出 SVG",
exportError: "图表导出失败",
save: "保存",
+ retrySave: "重试保存",
saving: "保存中",
saved: "已保存",
unsaved: "有未保存的修改",