cladogram 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +30 -2
  2. package/bin/clado.js +55 -3
  3. package/docs/plugin-development.md +135 -0
  4. package/docs/plugin-ui.md +43 -0
  5. package/docs/release.md +26 -0
  6. package/package.json +8 -1
  7. package/plugins/agent/index.js +181 -0
  8. package/plugins/agent/style.css +105 -0
  9. package/plugins/brand/index.js +262 -0
  10. package/plugins/brand/style.css +162 -0
  11. package/plugins/directory/capabilities.json +27 -0
  12. package/plugins/directory/index.js +146 -0
  13. package/plugins/directory/style.css +48 -0
  14. package/plugins/view-controls/index.js +58 -0
  15. package/plugins/view-controls/style.css +46 -0
  16. package/skills/clado/SKILL.md +31 -17
  17. package/src/html/app-css.js +11 -42
  18. package/src/html/canvas-chain.js +5 -6
  19. package/src/html/canvas-focus.js +3 -4
  20. package/src/html/canvas-screenshot.js +199 -0
  21. package/src/html/canvas-ui.css +37 -9
  22. package/src/html/canvas-ui.js +35 -27
  23. package/src/html/page.js +11 -37
  24. package/src/html/plugin-assets.js +33 -0
  25. package/src/html/plugin-ui.css +176 -0
  26. package/src/html/plugin-ui.js +45 -0
  27. package/src/html/runtime-api.js +47 -0
  28. package/src/html/runtime.js +15 -12
  29. package/src/server/agent.js +222 -0
  30. package/src/server/assets/clado-plugin-sdk.js +111 -0
  31. package/src/server/assets/library-canvas.js +72 -11
  32. package/src/server/assets/library-plugin-bridge.js +84 -0
  33. package/src/server/assets/library-plugins.css +39 -0
  34. package/src/server/assets/library-plugins.js +200 -0
  35. package/src/server/assets/library.css +3 -6
  36. package/src/server/assets/library.html +2 -12
  37. package/src/server/assets/library.js +280 -44
  38. package/src/server/canvas-capture.js +47 -0
  39. package/src/server/export.js +5 -2
  40. package/src/server/mcp.js +44 -19
  41. package/src/server/plugin-capabilities.js +172 -0
  42. package/src/server/plugin-settings.js +117 -0
  43. package/src/server/plugins.js +236 -0
  44. package/src/server/workspace.js +157 -12
  45. package/src/skill/targets.js +1 -1
  46. package/src/util/update.js +58 -0
  47. package/src/vendor/html-to-image.min.js +24 -0
  48. package/src/workspace/content.js +3 -2
  49. package/src/workspace/service.js +81 -21
  50. package/src/workspace/tree.js +38 -0
  51. package/src/server/assets/tree.js +0 -26
@@ -0,0 +1,146 @@
1
+ (() => {
2
+ function renderTree(container, documents, { selected='', query='', onOpen=()=>{}, folders=new Set() } = {}) {
3
+ const needle=query.trim().toLocaleLowerCase(), root={folders:new Map(),files:[]};
4
+ for(const doc of documents) {
5
+ if(needle && !(doc.title+' '+doc.file).toLocaleLowerCase().includes(needle))continue;
6
+ const parts=doc.file.split('/');let node=root;
7
+ parts.slice(0,-1).forEach((name,i)=>{const path=parts.slice(0,i+1).join('/');if(!node.folders.has(name))node.folders.set(name,{path,folders:new Map(),files:[]});node=node.folders.get(name);});node.files.push(doc);
8
+ }
9
+ container.replaceChildren();
10
+ function render(node, parent) {
11
+ for(const [name,folder] of node.folders) {
12
+ const details=document.createElement('details');details.className='tree-folder';details.open=!!needle||!folders.has('closed:'+folder.path);
13
+ const summary=document.createElement('summary');summary.textContent=name;details.append(summary);
14
+ details.addEventListener('toggle',()=>{if(!needle){if(details.open)folders.delete('closed:'+folder.path);else folders.add('closed:'+folder.path);}});
15
+ const children=document.createElement('div');children.className='tree-children';details.append(children);render(folder,children);parent.append(details);
16
+ }
17
+ for(const doc of node.files) {
18
+ const button=document.createElement('button');button.className='clado-ui-button document-button';button.dataset.file=doc.file;if(doc.file===selected)button.setAttribute('aria-current','page');
19
+ const strong=document.createElement('strong');strong.textContent=doc.title;
20
+ const small=document.createElement('small');small.textContent=doc.file.split('/').pop();button.append(strong,small);button.onclick=()=>onOpen(doc.file);parent.append(button);
21
+ }
22
+ }
23
+ render(root,container);
24
+ if(!container.childElementCount){const empty=document.createElement('p');empty.className='tree-empty';empty.textContent=needle?'没有匹配的文档':'还没有可展示的文档';container.append(empty);}
25
+ }
26
+
27
+ window.CladoDirectoryPlugin = (host, actions) => {
28
+ const content = document.createElement('div');
29
+ content.className = 'clado-directory-plugin';
30
+ content.innerHTML = `
31
+ <button type="button" id="directoryButton" class="clado-ui-glass clado-ui-button directory-toggle" aria-expanded="false" aria-controls="directory" title="切换 Markdown 画布">
32
+ <svg aria-hidden="true" viewBox="0 0 24 24"><path d="M4 7a2 2 0 0 1 2-2h4l2 2h6a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2Z"/></svg>
33
+ 文档 <span id="fileCount">…</span><span id="currentFileName" hidden></span>
34
+ </button>
35
+ <aside id="directory" class="clado-ui-glass clado-ui-glass-panel" aria-label="Markdown 画布目录" hidden>
36
+ <div class="directory-scroll">
37
+ <div class="directory-heading"><strong>Markdown/</strong></div>
38
+ <label class="directory-search"><input id="documentSearch" type="search" aria-label="搜索文档" placeholder="搜索名称或路径…"></label>
39
+ <nav id="documentList" aria-label="可用 Markdown"></nav>
40
+ <div class="directory-current"><span id="syncStatus" role="status">连接本地目录</span></div>
41
+ <div class="directory-actions"><button class="clado-ui-button" id="backButton" disabled>← 返回</button><button class="clado-ui-button" id="refreshButton" title="重新扫描目录并刷新当前文档">刷新</button><button class="clado-ui-button" id="sourceButton">源文</button></div>
42
+ <button id="skippedButton" class="clado-ui-button skipped" hidden></button>
43
+ </div>
44
+ </aside>
45
+ <dialog id="details" class="clado-ui-dialog"><header><strong id="detailsTitle"></strong><button id="closeDetails" class="clado-ui-button" aria-label="关闭详情">×</button></header><div id="detailsBody"></div></dialog>`;
46
+ host.mount('bottom-left', content, 'clado.directory');
47
+ host.capabilities('clado.directory', 'directory')?.provide(
48
+ ({ input }) => actions.openFromCapability(input.file)).catch(error => console.warn('Clado 目录能力注册失败', error));
49
+ const $ = selector => content.querySelector(selector);
50
+ const trigger = $('#directoryButton'), directory = $('#directory'), search = $('#documentSearch'), dialog = $('#details');
51
+ const fileName = $('#currentFileName');
52
+ const folders = new Set();
53
+ let index = { documents: [], skipped: [] }, selected = '', canGoBack = false, signature = '', request = 0;
54
+ function setOpen(open) {
55
+ if (open && actions.isLocked()) return;
56
+ directory.hidden = !open;
57
+ trigger.setAttribute('aria-expanded', String(open));
58
+ if (open) search.focus();
59
+ }
60
+ function details(title, elements) {
61
+ if (actions.isLocked() || !content.isConnected) return;
62
+ $('#detailsTitle').textContent = title;
63
+ $('#detailsBody').replaceChildren(...elements);
64
+ if (!dialog.open) dialog.showModal();
65
+ }
66
+ function text(tag, value) {
67
+ const item = document.createElement(tag);
68
+ item.textContent = value;
69
+ return item;
70
+ }
71
+ function showMessage(title, message) { details(title, [text('p', message)]); }
72
+ function render() {
73
+ const query = search.value;
74
+ const next = JSON.stringify([index.documents.map(doc => [doc.file, doc.title]), index.skipped.length, selected, query, canGoBack, index.root]);
75
+ if (next === signature) return;
76
+ signature = next;
77
+ $('#fileCount').textContent = index.documents.length;
78
+ $('.directory-heading strong').textContent = index.root || 'Markdown';
79
+ renderTree($('#documentList'), index.documents, {
80
+ selected, query, folders, onOpen: file => { setOpen(false); actions.open(file); },
81
+ });
82
+ $('#skippedButton').hidden = !index.skipped.length;
83
+ $('#skippedButton').textContent = index.skipped.length + ' 份文档未收录 · 查看原因';
84
+ $('#backButton').disabled = actions.isLocked() || !canGoBack;
85
+ $('#sourceButton').disabled = actions.isLocked() || !selected;
86
+ }
87
+ trigger.onclick = () => setOpen(directory.hidden);
88
+ search.oninput = render;
89
+ document.addEventListener('pointerdown', event => {
90
+ if (!content.contains(event.target)) setOpen(false);
91
+ });
92
+ document.addEventListener('keydown', event => {
93
+ if (event.key === 'Escape' && !directory.hidden && !dialog.open) { setOpen(false); trigger.focus(); }
94
+ });
95
+ $('#refreshButton').onclick = actions.refresh;
96
+ $('#backButton').onclick = actions.back;
97
+ $('#closeDetails').onclick = () => dialog.close();
98
+ $('#skippedButton').onclick = () => details('扫描后未收录的 Markdown', index.skipped.map(item => {
99
+ const section = document.createElement('section');
100
+ section.className = 'skip-item';
101
+ section.append(text('strong', item.file), ...item.diagnostics.map(d => text('p', d.code + ' · ' + d.message)));
102
+ return section;
103
+ }));
104
+ $('#sourceButton').onclick = async () => {
105
+ if (actions.isLocked()) return;
106
+ const current = ++request;
107
+ try {
108
+ const result = await actions.readSource();
109
+ if (current !== request || selected !== result.file) return;
110
+ const note = result.offline ? '这是 HTML 内嵌的只读源文。通过 MCP 修改工作区后重新构建以更新交付文件。' : '源文只读预览。通过 Clado MCP 修改内容,当前画布会自动同步。';
111
+ details(result.file, [text('p', note), text('pre', result.source)]);
112
+ } catch {
113
+ if (current === request) showMessage('暂时读不到源文', '请检查文档是否已删除,或是否出现解析错误。');
114
+ }
115
+ };
116
+ return {
117
+ close: () => setOpen(false),
118
+ showMessage,
119
+ update(next, file, hasHistory) {
120
+ if (file !== selected) {
121
+ request++;
122
+ fileName.textContent = file.split('/').pop();
123
+ fileName.title = file;
124
+ fileName.hidden = !file || actions.showFilename === false;
125
+ }
126
+ index = next; selected = file; canGoBack = hasHistory;
127
+ render();
128
+ },
129
+ status(message, error = false) {
130
+ const indicator = $('#syncStatus');
131
+ if (indicator.textContent !== message) indicator.textContent = message;
132
+ indicator.className = error ? 'sync-error' : 'sync-good';
133
+ trigger.dataset.sync = error ? 'error' : 'ok';
134
+ trigger.title = '切换 Markdown 画布 · ' + message;
135
+ },
136
+ setLocked(locked) {
137
+ if (locked) { setOpen(false); if (dialog.open) dialog.close(); request++; }
138
+ trigger.disabled = locked;
139
+ $('#refreshButton').disabled = locked;
140
+ $('#backButton').disabled = locked || !canGoBack;
141
+ $('#sourceButton').disabled = locked || !selected;
142
+ $('#skippedButton').disabled = locked;
143
+ },
144
+ };
145
+ };
146
+ })();
@@ -0,0 +1,48 @@
1
+ .clado-directory-plugin { position: relative; }
2
+ .directory-toggle { display: inline-flex; align-items: center; gap: 8px; height: 42px; max-width: min(400px, calc(100vw - 32px)); padding: 7px 13px; border-radius: 15px; color: var(--clado-ui-text); font-size: 13px; }
3
+ .directory-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; width: 16px; height: 16px; flex: none; }
4
+ #fileCount { flex: none; font-size: 11px; color: var(--clado-ui-muted); }
5
+ #currentFileName { min-width: 0; padding-inline-start: 8px; border-inline-start: 1px solid var(--clado-ui-edge); color: var(--clado-ui-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
6
+ .directory-toggle[data-sync="error"] #fileCount { color: #a45900; }
7
+ [data-theme="dark"] .directory-toggle[data-sync="error"] #fileCount { color: #f1ba73; }
8
+ #directory { position: absolute; left: 0; bottom: calc(100% + 8px); width: min(308px, calc(100vw - 32px)); }
9
+ .directory-scroll { max-height: calc(100dvh - 94px); overflow: auto; border-radius: inherit; padding: 14px 10px 10px; }
10
+ .directory-heading{padding:0 9px 13px}.directory-heading strong{font-size:12px;font-weight:600}.directory-heading span{display:block;font-size:10px;color:var(--muted);margin-top:5px}#documentList{display:flex;flex-direction:column;gap:4px}.document-button{display:block;text-align:left;padding:9px 10px;white-space:normal;width:100%}.document-button strong{font-size:11px;font-weight:500;display:block;color:var(--ink)}.document-button small{font-size:9px;color:var(--muted);display:block;margin-top:4px;overflow-wrap:anywhere}.directory-current{padding:12px 10px 8px;margin-top:10px;border-top:1px solid var(--line)}.directory-current strong{font-size:10px;font-weight:500;display:block;color:var(--muted)}.directory-current span{display:block;color:var(--muted);font-size:9px;margin-top:4px;overflow-wrap:anywhere}.directory-actions{display:flex;gap:7px;padding:0 10px}.directory-actions button{min-height:28px;font-size:10px;padding:4px 7px}.directory-actions #sourceButton{margin-left:auto}.skipped{margin-top:10px;border:0;border-top:1px solid var(--line);border-radius:0;width:100%;text-align:left;padding:11px 10px 2px;font-size:9px;color:var(--muted);white-space:normal}
11
+ .document-button[aria-current="page"] strong {
12
+ color: var(--clado-ui-accent);
13
+ font-weight: 600;
14
+ }
15
+
16
+ .sync-error{color:#b88628!important}.sync-good:before{content:'';display:inline-block;width:4px;height:4px;border-radius:50%;background:#69a57f;vertical-align:middle;margin-right:5px}
17
+ .clado-directory-plugin dialog {
18
+ position: fixed;
19
+ width: min(660px, calc(100vw - 32px));
20
+ max-height: calc(100vh - 36px);
21
+ border: 1px solid var(--line);
22
+ border-radius: var(--clado-ui-radius);
23
+ padding: 0;
24
+ }
25
+ .clado-directory-plugin dialog > header {
26
+ display: flex;
27
+ align-items: center;
28
+ gap: 12px;
29
+ padding: 15px 20px;
30
+ border-bottom: 1px solid var(--line);
31
+ }
32
+ .clado-directory-plugin dialog > header strong { font-size: 13px; font-weight: 600; }
33
+ .clado-directory-plugin dialog > header button {
34
+ margin-left: auto;
35
+ font-size: 19px;
36
+ line-height: 1;
37
+ border: 0;
38
+ }
39
+ #detailsBody { padding: 18px 20px; max-height: calc(100vh - 130px); overflow: auto; }
40
+ #detailsBody p { font-size: 11px; color: var(--muted); line-height: 1.8; margin: 0 0 14px; }
41
+ #detailsBody pre {
42
+ font: 11px/1.9 ui-monospace, SFMono-Regular, Menlo, monospace;
43
+ white-space: pre-wrap;
44
+ overflow-wrap: anywhere;
45
+ margin: 0;
46
+ }
47
+ .skip-item{padding:10px 0;border-bottom:1px solid var(--line)}.skip-item strong{font-size:12px}.skip-item p{margin:5px 0!important}.skip-item code{font-size:10px}
48
+ .directory-search{display:block;padding:0 9px 10px}.directory-search input{box-sizing:border-box;width:100%;border:1px solid var(--line);border-radius:7px;background:var(--clado-ui-well);color:var(--ink);font:inherit;padding:8px 10px;outline-color:var(--accent)}.tree-folder>summary{cursor:pointer;padding:8px;color:var(--ink);font-size:12px;font-weight:550}.tree-children{margin-left:11px;padding-left:5px;border-left:1px solid var(--line)}.tree-empty{padding:8px;color:var(--muted);font-size:12px}
@@ -0,0 +1,58 @@
1
+ (() => {
2
+ const modes = [['mindmap', '脑图'], ['cards', '卡片'], ['doc', '文档']];
3
+ const button = (className, text) => {
4
+ const element = document.createElement('button');
5
+ element.type = 'button';
6
+ element.className = className;
7
+ element.textContent = text;
8
+ return element;
9
+ };
10
+
11
+ function mountViewControls(host, actions) {
12
+ const controls = document.createElement('div');
13
+ controls.className = 'clado-view-controls';
14
+ const bar = document.createElement('div');
15
+ bar.className = 'clado-ui-glass clado-view-bar';
16
+ const group = document.createElement('div');
17
+ group.className = 'clado-view-modes';
18
+ group.setAttribute('role', 'group');
19
+ group.setAttribute('aria-label', '画布视图');
20
+ const thumb = document.createElement('span');
21
+ thumb.className = 'clado-view-thumb';
22
+ thumb.setAttribute('aria-hidden', 'true');
23
+ group.append(thumb);
24
+ const modeButtons = modes.map(([mode, label]) => {
25
+ const item = button('clado-ui-button', label);
26
+ item.dataset.mode = mode;
27
+ item.onclick = () => actions.setMode(mode);
28
+ group.append(item);
29
+ return item;
30
+ });
31
+ bar.append(group);
32
+
33
+ const statuses = document.createElement('div');
34
+ statuses.className = 'clado-view-status';
35
+ const issues = button('clado-ui-glass clado-ui-button clado-issue-count', '');
36
+ issues.onclick = actions.showDiagnostics;
37
+ const exit = button('clado-ui-glass clado-ui-button', '退出聚焦');
38
+ exit.onclick = actions.clearFocus;
39
+ statuses.append(issues, exit);
40
+ controls.append(bar, statuses);
41
+ host.mount('top-right', controls, 'clado.view-controls');
42
+ return ({ mode, focused = false, errors = 0, warnings = 0 }) => {
43
+ group.style.setProperty('--clado-view-index', String(Math.max(0, modes.findIndex(entry => entry[0] === mode))));
44
+ for (const item of modeButtons) item.setAttribute('aria-pressed', String(item.dataset.mode === mode));
45
+ issues.hidden = errors + warnings === 0;
46
+ if (!issues.hidden) {
47
+ issues.textContent = errors + warnings + ' 项问题';
48
+ issues.title = errors + ' 个错误 · ' + warnings + ' 个警告';
49
+ issues.setAttribute('aria-label', issues.title + ',查看诊断');
50
+ issues.classList.toggle('has-errors', errors > 0);
51
+ }
52
+ exit.hidden = !focused;
53
+ statuses.hidden = issues.hidden && exit.hidden;
54
+ };
55
+ }
56
+
57
+ window.CladoPluginUI.mountViewControls = mountViewControls;
58
+ })();
@@ -0,0 +1,46 @@
1
+ .clado-view-controls { display: flex; flex-direction: column; align-items: end; gap: 7px; pointer-events: none; }
2
+ .clado-view-bar { padding: 4px; }
3
+ .clado-view-modes {
4
+ position: relative;
5
+ display: grid;
6
+ grid-template-columns: repeat(3, 1fr);
7
+ }
8
+ .clado-view-modes .clado-ui-button {
9
+ position: relative;
10
+ min-height: 34px;
11
+ padding-inline: 12px;
12
+ background: transparent;
13
+ border-color: transparent;
14
+ border-radius: calc(var(--clado-ui-radius) - 5px);
15
+ }
16
+ .clado-view-modes .clado-ui-button[aria-pressed="true"] { font-weight: 650; }
17
+ .clado-view-thumb {
18
+ position: absolute;
19
+ inset: 0 auto 0 0;
20
+ width: calc(100% / 3);
21
+ border-radius: calc(var(--clado-ui-radius) - 5px);
22
+ border: 1px solid color-mix(in srgb, var(--clado-ui-accent) 19%, transparent);
23
+ background: linear-gradient(155deg, var(--clado-ui-highlight), transparent 75%),
24
+ color-mix(in srgb, var(--clado-ui-accent) 11%, transparent);
25
+ box-shadow: 0 1px 5px color-mix(in srgb, var(--clado-ui-accent) 12%, transparent);
26
+ transform: translateX(calc(var(--clado-view-index, 0) * 100%));
27
+ transition: transform 240ms cubic-bezier(.22,.75,.24,1);
28
+ pointer-events: none;
29
+ }
30
+ @media (prefers-reduced-motion: reduce) {
31
+ .clado-view-thumb { transition: none; }
32
+ }
33
+ @media (prefers-reduced-transparency: reduce) {
34
+ .clado-view-thumb { background: var(--clado-ui-active); }
35
+ }
36
+ .clado-view-status { display: flex; gap: 6px; }
37
+ .clado-view-bar, .clado-view-status > * { pointer-events: auto; }
38
+ .clado-view-status .clado-ui-button { border-radius: 12px; font-size: 12px; }
39
+ .clado-view-status .clado-issue-count { color: #8a5000; }
40
+ .clado-view-status .has-errors { color: #b72e3c; }
41
+ [data-theme="dark"] .clado-view-status .clado-issue-count { color: #efb860; }
42
+ [data-theme="dark"] .clado-view-status .has-errors { color: #ffacb6; }
43
+
44
+ @media (max-width: 460px) {
45
+ .clado-view-modes .clado-ui-button { padding-inline: 7px; }
46
+ }
@@ -27,6 +27,8 @@ Clado 将本地 Markdown/MDC 内容展示为脑图、卡片和文档三个视图
27
27
  | 命令 | 用途与常用参数 |
28
28
  | --- | --- |
29
29
  | `clado version` / `clado help` | 查看当前安装版本和全部选项 |
30
+ | `clado update --check` / `clado changelog` | 查询 npm 稳定版和阅读已安装版本的更新说明 |
31
+ | `clado update` / `clado upgrade` | 升级全局 npm 安装。更新项目的 Skill 仍用 `clado install` |
30
32
  | `clado install /项目路径 --list` | 列出支持的 AI 客户端与安装位置 |
31
33
  | `clado install /项目路径 --to zcode` | 给该业务项目的指定客户端安装 Skill,准备用户模板库;也可交互选择其它客户端 |
32
34
  | `clado init /项目路径` | 准备工作区,首次复制上级项目和用户模板,近处同名优先 |
@@ -35,7 +37,7 @@ Clado 将本地 Markdown/MDC 内容展示为脑图、卡片和文档三个视图
35
37
 
36
38
  CLI 的 `--dry-run` 只预览安装,`--force` 仅在确认允许替换现有目标时使用。`--theme light/dark` 设置初始主题,build 的 `--strict` 将警告视为错误,`--json` 输出结构化结果,`--quiet` 减少构建输出。`--entry` 相对本次文档目录。
37
39
 
38
- 源码运行先在 Clado 仓库执行 `npm install`,再用 `node /Clado源码/bin/clado.js serve /项目路径`。安装全局源码命令用 `npm install -g . --install-links`,将依赖一起安装。安装器从0.5.1开始固定只安装一份 `SKILL.md`,重装会清理原来受管理的 Skill 目录;业务场景示例不随 Skill 复制。
40
+ 源码运行先在 Clado 仓库执行 `npm install`,再用 `node /Clado源码/bin/clado.js serve /项目路径`。安装全局源码命令用 `npm install -g . --install-links`,将依赖一起安装。安装器只安装一份 `SKILL.md`,重装会清理原来受管理的 Skill 目录;业务场景示例不随 Skill 复制。
39
41
 
40
42
  全局命令在 Clado 源码仓库安装或更新;Skill 安装目标是业务项目,明确传入项目路径。安装后核对 `clado version` 和安装输出中的版本,不重复运行仍指向旧安装的命令。
41
43
 
@@ -45,13 +47,15 @@ CLI 的 `--dry-run` 只预览安装,`--force` 仅在确认允许替换现有
45
47
 
46
48
  ## 3. 从没有上下文开始
47
49
 
48
- 1. 取得服务输出的 `workspace` 绝对路径,调用 `clado_workspace inspect`。新子工作区先用 `init`。读取 `documentRoot`、文档清单、项目和用户模板目录及版本。
50
+ 1. 使用服务输出的 `workspace` 绝对路径。需要查目录时用 `clado_workspace inspect`;新子工作区用 `init`。用户说“改我选的卡片”时直接查 `selection`。
49
51
  2. 用 `clado_documents list/read` 查看相关旧文档,保留已有内容。读节点与位置可选 `view:"nodes"`,全文改写前选 `view:"source"`,只看概要选 `view:"summary"`;默认 `full` 兼容全部字段。若任务涉及实际代码,另外读取用户业务项目的真实材料;Clado 范例不能作为实现证据。
50
52
  3. `clado_templates list` 按用途选模板,再 `read` 提示词。默认只返回 `prompt`;编辑模板用 `view:"source"`,确实需要所有字段才用 `view:"full"`。
51
53
  4. 新文档用 `clado_documents create` 指定 `.mdc` 路径、标题和 `templateId`。`source` 可直接传多行正文,不能带 front matter;模板头由服务写入。省略正文时得到模板起始内容,之后须补充完整。
52
54
  5. 通过节点、正文和链接工具逐步细化。每次处理返回的全量错误和警告,确认实际插入位置;必要时用 `dryRun:true` 先看候选结果。
53
55
  6. 调用 `clado_workspace validate`,实际沿网页阅读关键路径,再按需要 `build`。归档依据实际交付,不能把提案完成写成系统已上线。
54
56
 
57
+ 评审调用链布局时,打开刚生成的文档,用 `clado_screenshot` 的 `mode:"cards"` 和 `scope:"full"` 查看整图。沿入口向右看分支和汇聚。如果业务上有并列调用,图上却排成一条长线,核对这些卡片是否误连成了依次调用。按真实关系修正后再截图确认。
58
+
55
59
  | 模板 | 当前任务 |
56
60
  | --- | --- |
57
61
  | `requirement-overview` | 本期范围与需求概览,先浅层展开 |
@@ -67,7 +71,9 @@ CLI 的 `--dry-run` 只预览安装,`--force` 仅在确认允许替换现有
67
71
 
68
72
  | 工具 | action 与使用方式 |
69
73
  | --- | --- |
70
- | `clado_workspace` | `init/inspect/search/validate`;搜索用 `query`,可给 `offset/limit/includeContent` |
74
+ | `clado_workspace` | `init/inspect/search/validate/selection`;搜索用 `query`,可给 `offset/limit/includeContent` |
75
+ | `clado_capabilities` | `list/call` 实时发现、调用在线能力。用 `clado.directory/directory.open` 打开目标文档 |
76
+ | `clado_screenshot` | 返回当前画布 PNG,默认保留展开和聚焦状态。支持 `mode`、`scope:"full"` 和 `source:"latest"`。多标签页时用能力列表返回的 `viewId` |
71
77
  | `clado_templates` | `list/read/create/update/delete/pull/push`;定位用 `templateId`,默认项目级,用户库加 `scope:"user"` |
72
78
  | `clado_documents` | `list/read/create/copy/update/rename/delete`;定位用 `file`;复制、改名用 `newFile`;全文更新传完整 `source`,可用 `metadata` 替换头部 |
73
79
  | `clado_nodes` | `read/query/create/insert/update/rename/move/delete`;定位用 `file/node`;新增用 `title/parent/content/index`;移动用 `parent/index/targetFile` |
@@ -80,9 +86,14 @@ CLI 的 `--dry-run` 只预览安装,`--force` 仅在确认允许替换现有
80
86
 
81
87
  `connect` 省略 `targetFile` 表示同文档,此时必须给 `targetNode`;跨文档可以省略 `targetNode`,跳转整份文档。省略 `label` 时取目标标题。跨文档导航不代替当前画布的跨卡关系线。
82
88
 
83
- ## 5. 段落、插入位置与返回结果
89
+ ## 5. 选中的卡片与正文定位
90
+
91
+ 在线画布上,Mac 用 Command 加左键点标题,其他平台用 Ctrl 加左键。可多选,再点同一标题取消,按住修饰键点画布空白清空。三种模式共用选区。内容刷新后,只保留标题路径仍可唯一定位的选中项。切换文档清空。标题下的正文和后代属于同一选中范围。
92
+
93
+ 用户提到选区时,调用 `clado_workspace` 的 `action:"selection"`。`ready` 返回 `file`、文档 `version` 和所选节点的 `path/content/paragraphs/nodeVersion/descendants`,按用户点选的顺序排列。根据用户指示定位到具体节点,修改一句用所给正文作原文锚点,整段替换可带该节点的 `nodeVersion`。`empty/stale` 时请用户选中或重新选择。选区以最近更新选区的标签页为准。
84
94
 
85
- `read` 返回每个节点的 `location` 和 `paragraphs`。段落编号从 **1** 开始,以空行分块;代码围栏包含内部空行整体算一块,表格通常也是一块。先读当前结果,再使用段落编号或唯一原文定位。
95
+
96
+ `read` 返回每个节点的 `location` 和 `paragraphs`。段落编号从 **1** 开始,以空行分块;代码围栏包含内部空行整体算一块,表格通常也是一块。段落编号用读取结果。已知原文可以直接用 `anchor`。
86
97
 
87
98
  | 需求 | 参数 |
88
99
  | --- | --- |
@@ -100,7 +111,7 @@ CLI 的 `--dry-run` 只预览安装,`--force` 仅在确认允许替换现有
100
111
 
101
112
  批量断开同一目标时指定 `targetFile/targetNode`;只断一处时用刚读取的 `linkIndex`。`connect` 的 `contentLocation` 对应实际链接所在的位置,`insert` 则对应新增正文的范围。
102
113
 
103
- 写入后的 `results` 返回最终文件、节点路径、同级位置、段落和行号。文件整体写入还返回节点位置摘要。批量内后续改名/移动会更新定位;内容被覆盖或删除会标明。`contentLocationStatus:"exact"` 表示能唯一定位;`multiple_matches` 或 `changed_by_later_operation` 时重新读取,不声称已经有唯一坐标。行号和编号只对对应文件 `version` 的快照有效。
114
+ 写入后的 `results` 返回最终文件、节点路径、同级位置、段落和行号。文件整体写入还返回节点位置摘要。批量内后续改名/移动会更新定位;内容被覆盖或删除会标明。`contentLocationStatus:"exact"` 表示能唯一定位;`multiple_matches` 或 `changed_by_later_operation` 时重新读取,不声称已经有唯一坐标。行号和编号只对对应文件 `version` 的快照有效。`nodeVersion` 用于后续覆盖或删除同一节点。
104
115
 
105
116
  精确连线用 `clado_links connect` 的 `sourcePoint`,跟普通的 `file/node/targetNode` 一起传。代码、表格、Mermaid 保持连续。标注可以写在代码注释里,链接用工具挂到具体行上。点击画布中起点处的圆点可跳到目标。
106
117
 
@@ -114,30 +125,30 @@ CLI 的 `--dry-run` 只预览安装,`--force` 仅在确认允许替换现有
114
125
 
115
126
  ## 6. 一个完整操作示例
116
127
 
117
- 以下是 MCP 参数,**不是 Shell 命令**。路径、标题和版本需换成实际值;每次写入使用刚读取或上次成功返回的新版本。本例演示工具操作,正式内容仍须按模板补齐,不能交付占位符。
128
+ 以下是 MCP 参数,**不是 Shell 命令**。路径、标题和原文需换成实际值。本例演示工具操作,正式内容仍须按模板补齐,不能交付占位符。
118
129
 
119
- 先 `inspect`、读 `call-chain` 提示词,按模板创建文档:
130
+ 读 `call-chain` 提示词,按模板创建文档。
120
131
 
121
132
  ```json
122
- {"workspace":"/项目绝对路径","action":"create","file":"api/create.mdc","title":"OrderFacade#create","templateId":"call-chain","expectedWorkspaceVersion":"刚读取的workspaceVersion"}
133
+ {"workspace":"/项目绝对路径","action":"create","file":"api/create.mdc","title":"OrderFacade#create","templateId":"call-chain"}
123
134
  ```
124
135
 
125
136
  用 `documents.read view:"nodes"` 确认节点路径。默认模板中有 `OrderFacade#create / 处理步骤`。通过 `clado_nodes` 增加另一张方法卡:
126
137
 
127
138
  ```json
128
- {"workspace":"/项目绝对路径","action":"create","file":"api/create.mdc","title":"OrderApplicationService#create","content":"假设示例:接收已校验命令,在本地事务中保存订单,返回订单标识;错误交由调用方处理。","expectedWorkspaceVersion":"上次返回的新workspaceVersion"}
139
+ {"workspace":"/项目绝对路径","action":"create","file":"api/create.mdc","title":"OrderApplicationService#create","content":"假设示例:接收已校验命令,在本地事务中保存订单,返回订单标识;错误交由调用方处理。"}
129
140
  ```
130
141
 
131
142
  此时两卡尚未连线,写入成功后仍会报孤立卡片;继续用 `clado_nodes insert` 补调用所在的逻辑段:
132
143
 
133
144
  ```json
134
- {"workspace":"/项目绝对路径","action":"insert","file":"api/create.mdc","node":["OrderFacade#create","处理步骤"],"content":"校验通过后调用 OrderApplicationService#create;取得已提交结果再返回。","expectedWorkspaceVersion":"上次返回的新workspaceVersion"}
145
+ {"workspace":"/项目绝对路径","action":"insert","file":"api/create.mdc","node":["OrderFacade#create","处理步骤"],"content":"校验通过后调用 OrderApplicationService#create;取得已提交结果再返回。"}
135
146
  ```
136
147
 
137
148
  再调用 `clado_links connect`,在刚写的原句中建立真实引用:
138
149
 
139
150
  ```json
140
- {"workspace":"/项目绝对路径","action":"connect","file":"api/create.mdc","node":["OrderFacade#create","处理步骤"],"targetNode":["OrderApplicationService#create"],"label":"OrderApplicationService#create","position":{"mode":"replace","anchor":"OrderApplicationService#create"},"expectedWorkspaceVersion":"上次返回的新workspaceVersion"}
151
+ {"workspace":"/项目绝对路径","action":"connect","file":"api/create.mdc","node":["OrderFacade#create","处理步骤"],"targetNode":["OrderApplicationService#create"],"label":"OrderApplicationService#create","position":{"mode":"replace","anchor":"OrderApplicationService#create"}}
141
152
  ```
142
153
 
143
154
  查看 `results` 的实际段落与行号,再用 `nodes.read/links.list` 确认。孤立错误应消失;仍要替换模板占位说明、展开方法内部逻辑、核对成功和失败出口,不能只凭结构校验宣布业务设计完整。
@@ -146,9 +157,9 @@ CLI 的 `--dry-run` 只预览安装,`--force` 仅在确认允许替换现有
146
157
 
147
158
  ```json
148
159
  {
149
- "workspace":"/项目绝对路径","expectedWorkspaceVersion":"刚读取的workspaceVersion",
160
+ "workspace":"/项目绝对路径",
150
161
  "operations":[
151
- {"type":"node.rename","file":"api/create.mdc","node":["OrderFacade#create","处理步骤"],"title":"校验并提交"},
162
+ {"type":"node.rename","file":"api/create.mdc","node":["OrderFacade#create","处理步骤"],"title":"校验并提交","expectedNodeVersion":"节点读取返回的nodeVersion"},
152
163
  {"type":"node.insert","file":"api/create.mdc","node":["OrderFacade#create","校验并提交"],"content":"依赖失败时按错误契约返回,不提前宣布成功。"}
153
164
  ]
154
165
  }
@@ -165,14 +176,17 @@ CLI 的 `--dry-run` 只预览安装,`--force` 仅在确认允许替换现有
165
176
  - 参数不合法返回 `INVALID_ARGUMENTS` 和具体 `issues`;不要把工具名、action或字段拼错后继续盲试。锚点不唯一时改用更完整原文或段落定位。
166
177
  - 常见待修项:`MD_CARD_ISOLATED` 需要真实跨卡关系,`MD_LINK_UNRESOLVED` 需要修复目标,`MD_FENCE_UNCLOSED` 需要闭合代码围栏;模板损坏用 `read` 的错误信息及 `update` 修复完整规则头。
167
178
 
179
+ 新建文档或副本、新增同级末尾卡片、追加正文或链接、按唯一原文编辑,都可以直接提交。文档覆盖、改名、删除用文件版本。节点覆盖、改名、删除和按段落编号修改用节点或文件版本。指定同级 `index` 或精确连线的目标表格行用文件版本,跨文档按 `index` 移动用工作区版本。
180
+
168
181
  | 读取返回的版本 | 写入参数 / 含义 |
169
182
  | --- | --- |
170
- | `workspaceVersion` | 项目写入用 `expectedWorkspaceVersion` |
183
+ | `workspaceVersion` | 可用 `expectedWorkspaceVersion` 保护整个工作区,项目模板写入必填 |
171
184
  | `userTemplateVersion` | 用户库写入用 `expectedUserTemplateVersion`;push同时带两个整体版本 |
172
185
  | `templateVersion` | 模板规则的业务版本,完整视图中为 `metadata.version`,不用于并发校验 |
173
- | `version` | 单文件或单模板的内容hash,不替代整体版本 |
186
+ | 文档 `version` | `expectedFileVersion` 校验目标文件 |
187
+ | `nodeVersion` | `expectedNodeVersion` 校验目标节点及其后代 |
174
188
 
175
- 409冲突后重新读取相应工作区或用户库,合并再提交,不原样无限重试;422表示本次结构校验失败,批次不保存。批次按顺序解释后续节点路径,改名后用新名字。不同工作区分别提交,用户库写入不放进项目批次。
189
+ 409 时按错误定位重新读取节点、文件或模板库再提交。原文出现多次时补充上下文。422 表示结构校验失败。批次按前序操作后的路径和内容校验每步,任一操作失败则整批不保存。对同一位置的连续修改可合成一步,或者为整批传 `expectedWorkspaceVersion`。
176
190
 
177
191
  ## 8. 创建、定制和复用模板
178
192
 
@@ -23,13 +23,13 @@ export const APP_CSS = String.raw`
23
23
  正文的样子交给 vendor 里那套(github-markdown-css + highlight.js),
24
24
  这里只管:顶栏、画布、卡片外壳、缩进、线、放大镜。 */
25
25
  [data-theme="light"]{
26
- --bg:#f6f8fa; --panel:#ffffff; --line:#d1d9e0; --line-2:#e4e8ee;
26
+ --bg:#f9fafc; --panel:#ffffff; --line:#d1d9e0; --line-2:#e4e8ee;
27
27
  --fg:#1f2328; --fg-2:#59636e; --accent:#0969da; --accent-soft:#ddf4ff;
28
28
  --shadow:0 1px 2px rgba(31,35,40,.08), 0 8px 24px rgba(31,35,40,.08);
29
29
  --dot:#dfe3e8;
30
30
  }
31
31
  [data-theme="dark"]{
32
- --bg:#0d1117; --panel:#161b22; --line:#30363d; --line-2:#21262d;
32
+ --bg:#10151c; --panel:#161b22; --line:#30363d; --line-2:#21262d;
33
33
  --fg:#e6edf3; --fg-2:#9198a1; --accent:#58a6ff; --accent-soft:#12283f;
34
34
  --shadow:0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
35
35
  --dot:#1b2027;
@@ -64,36 +64,8 @@ html,body,#doc,#article,.body,.tscroll,#lensInner{
64
64
  scrollbar-color:color-mix(in srgb, var(--fg-2) 30%, transparent) transparent;
65
65
  }
66
66
 
67
- /* ── 顶栏 ───────────────────────────────────────────────── */
68
- .top{
69
- height:48px; display:flex; align-items:center; gap:14px; padding:0 14px;
70
- background:var(--panel); border-bottom:1px solid var(--line); position:relative; z-index:30;
71
- }
72
- .brand{font-weight:700; letter-spacing:.3px; color:var(--fg)}
73
- .brand span{color:var(--fg-2); font-weight:500; margin-left:6px}
74
- .seg{display:flex; background:var(--bg); border:1px solid var(--line); border-radius:8px; padding:2px}
75
- .seg button{
76
- border:0; background:transparent; color:var(--fg-2); font:inherit; font-size:12.5px;
77
- padding:4px 11px; border-radius:6px; cursor:pointer;
78
- }
79
- .seg button.on{background:var(--panel); color:var(--accent); box-shadow:0 1px 2px rgba(0,0,0,.08); font-weight:600}
80
- .diag{display:flex; gap:6px; margin-left:auto}
81
- .chip{
82
- font-size:12px; padding:4px 10px; border-radius:999px; border:1px solid var(--line);
83
- background:var(--bg); color:var(--fg-2); cursor:default;
84
- }
85
- .chip.warn{color:#9a6700; border-color:#d4a72c66; background:#fff8c5; cursor:pointer}
86
- .chip.bad{color:#cf222e; border-color:#cf222e66; background:#ffebe9}
87
- [data-theme="dark"] .chip.bad{color:#f85149; background:#3a1518; border-color:#f8514966}
88
- [data-theme="dark"] .chip.warn{color:#d29922; background:#2d2612; border-color:#9e6a0366}
89
- .icon{
90
- width:30px; height:30px; border-radius:8px; border:1px solid var(--line);
91
- background:var(--bg); color:var(--fg-2); font-size:14px; cursor:pointer; line-height:1;
92
- }
93
- .icon:hover{color:var(--accent); border-color:var(--accent)}
94
-
95
67
  /* ── 画布 ───────────────────────────────────────────────── */
96
- #stage{position:absolute; inset:48px 0 0 0; overflow:hidden;
68
+ #stage{position:absolute; inset:0; overflow:hidden;
97
69
  background-image:radial-gradient(circle, var(--dot) 1px, transparent 1px);
98
70
  background-size:22px 22px; cursor:grab}
99
71
  #stage.drag{cursor:grabbing}
@@ -320,11 +292,12 @@ body.dragging, body.dragging *{user-select:none; -webkit-user-select:none}
320
292
  #lensInner .markdown-body table th,#lensInner .markdown-body table td{padding:7px 14px !important; border:1px solid var(--line) !important; white-space:nowrap}
321
293
 
322
294
  /* ── 文档模式 ───────────────────────────────────────────── */
323
- #doc{position:absolute; inset:48px 0 0 0; display:none; overflow:auto; background:var(--panel)}
295
+ #doc{position:absolute; inset:0; display:none; overflow:auto; background:var(--panel)}
324
296
  [data-mode="doc"] #doc{display:block}
325
297
  [data-mode="doc"] #stage{display:none}
326
- .docwrap{display:grid; grid-template-columns:198px minmax(0,1fr); gap:28px; max-width:1000px; margin:0 auto; padding:26px 26px 90px}
327
- .toc{position:sticky; top:0; align-self:start; padding-top:6px; min-width:0}
298
+ .docwrap{display:grid; grid-template-columns:198px minmax(0,1fr); gap:28px; max-width:1000px; margin:0 auto; padding:82px 26px 90px}
299
+ .toc{position:sticky; top:76px; align-self:start; padding-top:6px; min-width:0; max-height:calc(100dvh - 142px); overflow:auto}
300
+ .slice-head{scroll-margin-top:72px}
328
301
  .toc h4{margin:0 0 10px; font-size:11px; letter-spacing:.12em; color:var(--fg-2); font-weight:600}
329
302
  .toc a{
330
303
  display:block; color:var(--fg-2); text-decoration:none; font-size:12.5px;
@@ -377,23 +350,19 @@ body.dragging, body.dragging *{user-select:none; -webkit-user-select:none}
377
350
  #mwires path.edge{stroke-opacity:.45; stroke-width:1.4; stroke-dasharray:5 4}
378
351
 
379
352
  /* ── 放大镜:点 Mermaid 图 / 图片都走这里 ─────────────────── */
380
- #lens{position:fixed; inset:0; z-index:80; display:none; background:rgba(20,24,30,.55); backdrop-filter:blur(3px)}
353
+ #lens{position:fixed; inset:0; z-index:80; display:none; background:transparent}
381
354
  #lens.open{display:block}
382
355
  .lensbar{
383
356
  position:absolute; top:14px; left:50%; transform:translateX(-50%); z-index:2;
384
357
  display:flex; align-items:center; gap:8px; padding:6px 8px 6px 14px;
385
- background:var(--panel); border:1px solid var(--line); border-radius:10px; box-shadow:var(--shadow);
386
- font-size:12px; color:var(--fg-2);
358
+ font-size:12px;
387
359
  }
388
360
  .lensbar button{
389
- width:28px; height:26px; border-radius:7px; border:1px solid var(--line);
390
- background:var(--bg); color:var(--fg); font-size:14px; cursor:pointer; line-height:1;
361
+ width:28px; min-height:26px; padding:0; border-radius:7px; font-size:14px;
391
362
  }
392
- .lensbar button:hover{color:var(--accent); border-color:var(--accent)}
393
363
  #lensStage{position:absolute; inset:0; overflow:hidden; cursor:grab}
394
364
  #lensStage.drag{cursor:grabbing}
395
- #lensInner{position:absolute; left:0; top:0; transform-origin:0 0; background:var(--panel);
396
- border:1px solid var(--line); border-radius:10px; padding:18px}
365
+ #lensInner{position:absolute; left:0; top:0; transform-origin:0 0; padding:18px}
397
366
  #lensInner svg,#lensInner img{display:block}
398
367
  #lensInner :is(pre,table,svg text,svg foreignObject){cursor:text}
399
368
  body:not(.dragging) #lensInner :is(pre,table,svg text,svg foreignObject){user-select:text;-webkit-user-select:text}
@@ -53,14 +53,13 @@ function canvasChainDocument(subset, selected) {
53
53
  var viewport = child.createElement('meta'); viewport.name = 'viewport'; viewport.content = 'width=device-width,initial-scale=1'; child.head.appendChild(viewport);
54
54
  var base = child.createElement('base'); base.href = document.baseURI; child.head.appendChild(base);
55
55
  $$('style').forEach(function (style) { child.head.appendChild(style.cloneNode(true)); });
56
- var style = child.createElement('style'); style.textContent = '.top{display:none!important}#stage,#doc{top:0!important}.zoomable{cursor:default!important}'; child.head.appendChild(style);
56
+ var style = child.createElement('style'); style.textContent = '.docwrap{padding-top:26px}.toc{top:0;max-height:calc(100dvh - 26px)}.zoomable{cursor:default!important}'; child.head.appendChild(style);
57
57
  var mode = document.body.dataset.mode;
58
58
  if (['cards','mindmap','doc'].indexOf(mode) < 0) mode = 'cards';
59
59
  child.body.dataset.mode = mode;
60
- child.body.innerHTML = '<header class="top"><div class="brand">clado</div><div class="seg" id="modes"><button data-mode="doc">doc</button><button data-mode="cards">cards</button><button data-mode="mindmap">mindmap</button></div><div class="diag"></div><button id="theme"></button></header>' +
61
- '<div id="stage"><div id="world"><svg id="wires"></svg><div id="mind"><svg id="mwires"></svg></div></div></div>' +
60
+ child.body.innerHTML = '<div id="stage"><div id="world"><svg id="wires"></svg><div id="mind"><svg id="mwires"></svg></div></div></div>' +
62
61
  '<div id="doc"><div class="docwrap"><nav class="toc" id="toc"></nav><article id="article"></article></div></div>' +
63
- '<div id="lens"><div class="lensbar"><span id="lensLabel"></span><button id="lensOut"></button><span id="lensPct"></span><button id="lensIn"></button><button id="lensFit"></button><button id="lensClose"></button></div><div id="lensStage"><div id="lensInner"></div></div></div><div id="hint"></div>';
62
+ '<div id="lens"><div class="lensbar clado-ui-glass"><span id="lensLabel"></span><button id="lensOut" class="clado-ui-button"></button><span id="lensPct"></span><button id="lensIn" class="clado-ui-button"></button><button id="lensFit" class="clado-ui-button"></button><button id="lensClose" class="clado-ui-button"></button></div><div id="lensStage"><div id="lensInner" class="clado-ui-glass clado-ui-glass-panel"></div></div></div><div id="hint"></div>';
64
63
  var data = child.createElement('script');
65
64
  var values = { __CLADO__: subset, __CLADO_CHAIN__: { id: selected, mode: mode }, __CLADO_LIVE__: true,
66
65
  __CLADO_DIAGNOSTICS__: [], __CLADO_FILE__: window.__CLADO_FILE__ || '',
@@ -74,9 +73,9 @@ function canvasOpenChain(record, trigger) {
74
73
  if (window.__CLADO_CHAIN__ || canvasChainIsOpen() || !record) return;
75
74
  var ids = canvasFocusSet(record.id), source = canvasChainDocument(canvasChainSubset(ids, record.id), record.id);
76
75
  if (!source) return;
77
- var dialog = document.createElement('dialog'); dialog.className = 'canvas-chain-dialog';
76
+ var dialog = document.createElement('dialog'); dialog.className = 'canvas-chain-dialog clado-ui-dialog';
78
77
  dialog.setAttribute('aria-labelledby', 'canvas-chain-label');
79
- dialog.innerHTML = '<div class="canvas-chain-bar"><div class="canvas-chain-heading"><strong id="canvas-chain-label"></strong><span class="canvas-chain-meta"></span></div><div class="canvas-chain-controls"><button type="button" data-chain-action="out" aria-label="缩小链路画布">−</button><button type="button" data-chain-action="in" aria-label="放大链路画布">+</button><button type="button" data-chain-action="center" aria-label="回到选中节点">◎</button><button type="button" data-chain-action="close" aria-label="关闭链路画布">✕</button></div></div><iframe title="独立链路画布"></iframe>';
78
+ dialog.innerHTML = '<div class="canvas-chain-bar"><div class="canvas-chain-heading"><strong id="canvas-chain-label"></strong><span class="canvas-chain-meta"></span></div><div class="canvas-chain-controls"><button type="button" class="clado-ui-button" data-chain-action="out" aria-label="缩小链路画布">−</button><button type="button" class="clado-ui-button" data-chain-action="in" aria-label="放大链路画布">+</button><button type="button" class="clado-ui-button" data-chain-action="center" aria-label="回到选中节点">◎</button><button type="button" class="clado-ui-button" data-chain-action="close" aria-label="关闭链路画布">✕</button></div></div><iframe title="独立链路画布"></iframe>';
80
79
  $('.canvas-chain-heading strong', dialog).textContent = record.id === '__document' ? DOC.title : record.title;
81
80
  $('.canvas-chain-meta', dialog).textContent = canvasFocusCards(ids).size + (document.body.dataset.mode === 'doc' ? ' 张关联卡片 · 滚动阅读' : ' 张关联卡片 · 拖动空白平移,滚轮缩放');
82
81
  var frame = $('iframe', dialog), previousFocus = document.activeElement;
@@ -2,7 +2,8 @@
2
2
  var canvasRecords = {}, canvasDocPaths = {}, canvasMindPaths = {}, canvasFocusId = null;
3
3
  (function () {
4
4
  function add(n, docPath, parent, card) {
5
- var r = { id: n.id, title: n.title, parent: parent, card: card, docPath: docPath, mindPath: '0.' + docPath, kids: [] };
5
+ var r = { id: n.id, title: n.title, markdown: n.md, parent: parent, card: card, docPath: docPath, mindPath: '0.' + docPath, kids: [] };
6
+ r.titlePath = parent ? canvasRecords[parent].titlePath.concat(n.title) : [n.title];
6
7
  r.fullPath = parent ? canvasRecords[parent].fullPath + '.' + n.title : n.title;
7
8
  canvasRecords[r.id] = r; canvasDocPaths[docPath] = r; canvasMindPaths[r.mindPath] = r;
8
9
  (n.nodes || n.kids || []).forEach(function (child, i) { r.kids.push(child.id); add(child, docPath + '.' + i, r.id, card); });
@@ -76,8 +77,6 @@ function canvasApplyFocus() {
76
77
  path.classList.toggle('focus-line', related || hierarchy);
77
78
  path.classList.toggle('focus-hidden', !!lit && !related && !hierarchy);
78
79
  });
79
- var exit = $('#exit-focus');
80
- if (exit) exit.hidden = !lit;
81
80
  }
82
81
  var canvasClearLit = clearLit;
83
82
  function canvasSetFocus(id) {
@@ -95,6 +94,7 @@ function canvasSetFocus(id) {
95
94
  } else drawWires();
96
95
  }
97
96
  canvasApplyFocus();
97
+ if (typeof CustomEvent === 'function') document.dispatchEvent(new CustomEvent('clado:view-state'));
98
98
  }
99
99
  clearLit = function () { canvasSetFocus(null); };
100
100
  function canvasFocusContent(id) {
@@ -130,7 +130,6 @@ function canvasRecordForTarget(target) {
130
130
  var card = target.closest('#world > .card'); return card ? canvasRecords[card.dataset.id] : null;
131
131
  }
132
132
  document.addEventListener('click', function (event) {
133
- if (event.target.closest('#exit-focus')) { clearLit(); return; }
134
133
  var toc = event.target.closest('#toc a[data-path]');
135
134
  if (!toc) return;
136
135
  event.preventDefault();