cladogram 0.5.3 → 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.
- package/README.md +19 -0
- package/bin/clado.js +13 -2
- package/docs/plugin-development.md +135 -0
- package/docs/plugin-ui.md +43 -0
- package/docs/release.md +7 -0
- package/package.json +7 -1
- package/plugins/agent/index.js +181 -0
- package/plugins/agent/style.css +105 -0
- package/plugins/brand/index.js +262 -0
- package/plugins/brand/style.css +162 -0
- package/plugins/directory/capabilities.json +27 -0
- package/plugins/directory/index.js +146 -0
- package/plugins/directory/style.css +48 -0
- package/plugins/view-controls/index.js +58 -0
- package/plugins/view-controls/style.css +46 -0
- package/skills/clado/SKILL.md +4 -0
- package/src/html/app-css.js +9 -40
- package/src/html/canvas-chain.js +5 -6
- package/src/html/canvas-focus.js +2 -4
- package/src/html/canvas-screenshot.js +199 -0
- package/src/html/canvas-ui.css +5 -9
- package/src/html/canvas-ui.js +35 -27
- package/src/html/page.js +11 -37
- package/src/html/plugin-assets.js +33 -0
- package/src/html/plugin-ui.css +176 -0
- package/src/html/plugin-ui.js +45 -0
- package/src/html/runtime-api.js +41 -0
- package/src/html/runtime.js +15 -12
- package/src/server/agent.js +222 -0
- package/src/server/assets/clado-plugin-sdk.js +111 -0
- package/src/server/assets/library-canvas.js +12 -9
- package/src/server/assets/library-plugin-bridge.js +84 -0
- package/src/server/assets/library-plugins.css +39 -0
- package/src/server/assets/library-plugins.js +200 -0
- package/src/server/assets/library.css +3 -6
- package/src/server/assets/library.html +2 -12
- package/src/server/assets/library.js +227 -44
- package/src/server/canvas-capture.js +47 -0
- package/src/server/export.js +5 -2
- package/src/server/mcp.js +29 -6
- package/src/server/plugin-capabilities.js +172 -0
- package/src/server/plugin-settings.js +117 -0
- package/src/server/plugins.js +236 -0
- package/src/server/workspace.js +127 -11
- package/src/vendor/html-to-image.min.js +24 -0
- package/src/server/assets/tree.js +0 -26
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const maxMessageBytes = 262144;
|
|
3
|
+
const maxPart = value => Number.isSafeInteger(value) && value >= 0;
|
|
4
|
+
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
|
+
const sameList = (value, expected) => Array.isArray(value) && value.length === expected.length &&
|
|
6
|
+
new Set(value).size === value.length && value.every(item => expected.includes(item));
|
|
7
|
+
const byteLength = value => new TextEncoder().encode(value).length;
|
|
8
|
+
|
|
9
|
+
window.CladoPluginHost = ({ host, readView, capabilities, isEnabled }) => {
|
|
10
|
+
const viewId = capabilities.viewId;
|
|
11
|
+
let catalog;
|
|
12
|
+
const tickets = new Map(), registered = new Set();
|
|
13
|
+
const theme = () => document.documentElement.dataset.theme || 'light';
|
|
14
|
+
function syncTheme(instance) {
|
|
15
|
+
instance.port.postMessage(JSON.stringify({ jsonrpc: '2.0', method: 'clado.ui.theme', params: { theme: theme() } }));
|
|
16
|
+
}
|
|
17
|
+
const observeTheme = new MutationObserver(() => {
|
|
18
|
+
for (const instance of registered) syncTheme(instance);
|
|
19
|
+
});
|
|
20
|
+
observeTheme.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });
|
|
21
|
+
function remove(instance) {
|
|
22
|
+
clearTimeout(instance.timer);
|
|
23
|
+
instance.port?.close();
|
|
24
|
+
tickets.delete(instance.ticket);
|
|
25
|
+
instance.unmount();
|
|
26
|
+
}
|
|
27
|
+
function mount(plugin, contribution) {
|
|
28
|
+
const surface = document.createElement('div');
|
|
29
|
+
surface.className = 'clado-plugin-window clado-ui-glass';
|
|
30
|
+
if (['sidebar', 'canvas-overlay'].includes(contribution.slot)) surface.classList.add('clado-ui-glass-panel');
|
|
31
|
+
surface.hidden = true;
|
|
32
|
+
const frame = document.createElement('iframe');
|
|
33
|
+
frame.className = 'clado-plugin-frame';
|
|
34
|
+
frame.title = plugin.name + ' · ' + contribution.id;
|
|
35
|
+
frame.dataset.mountId = contribution.id;
|
|
36
|
+
frame.setAttribute('sandbox', 'allow-scripts');
|
|
37
|
+
frame.referrerPolicy = 'no-referrer';
|
|
38
|
+
const ticket = crypto.randomUUID();
|
|
39
|
+
const instance = { plugin, contribution, frame, surface, ticket, instanceId: crypto.randomUUID(), state: 'connecting', pending: new Map() };
|
|
40
|
+
tickets.set(ticket, instance);
|
|
41
|
+
instance.timer = setTimeout(() => {
|
|
42
|
+
console.warn('Clado 插件启动超时', plugin.id, contribution.id);
|
|
43
|
+
remove(instance);
|
|
44
|
+
}, 10000);
|
|
45
|
+
frame.src = plugin.entry + '#' + new URLSearchParams({ ticket, mount: contribution.id, theme: theme() });
|
|
46
|
+
surface.append(frame);
|
|
47
|
+
instance.unmount = host.mount(contribution.slot, surface, plugin.id);
|
|
48
|
+
}
|
|
49
|
+
function context(instance, params) {
|
|
50
|
+
const { to, scope, input } = params;
|
|
51
|
+
if (!isObject(scope) || scope.workspaceId !== catalog.workspaceId || scope.viewId !== viewId) {
|
|
52
|
+
return error(-32001, 'FORBIDDEN', '工作区或视图不属于当前插件实例。');
|
|
53
|
+
}
|
|
54
|
+
if (!isObject(to) || to.capability !== 'canvas.context.get' ||
|
|
55
|
+
(to.pluginId !== undefined && to.pluginId !== 'clado.host') || to.instanceId !== undefined) {
|
|
56
|
+
return error(-32002, 'NO_PROVIDER', '能力未注册。');
|
|
57
|
+
}
|
|
58
|
+
if (to.major !== 1) return error(-32004, 'UNSUPPORTED_VERSION', '仅支持能力版本 1。');
|
|
59
|
+
if (!isObject(input) || !Array.isArray(input.fields) || !input.fields.length ||
|
|
60
|
+
!input.fields.every(field => catalog.fields.includes(field)) ||
|
|
61
|
+
new Set(input.fields).size !== input.fields.length) return invalidParams();
|
|
62
|
+
const { fields, offset = 0, limit = 100, revision } = input;
|
|
63
|
+
if (!fields.every(field => instance.plugin.permissions.includes('canvas.' + field + '.read'))) {
|
|
64
|
+
return error(-32001, 'FORBIDDEN', '插件未声明所请求字段的读取权限。');
|
|
65
|
+
}
|
|
66
|
+
if (!maxPart(offset) || !maxPart(limit) || limit < 1 || limit > 200 ||
|
|
67
|
+
(offset > 0 && (!fields.includes('graph') || typeof revision !== 'string')) ||
|
|
68
|
+
(revision !== undefined && (!fields.includes('graph') || typeof revision !== 'string'))) return invalidParams();
|
|
69
|
+
const view = readView();
|
|
70
|
+
// File identity matters when distinct documents have identical source bytes.
|
|
71
|
+
const graphRevision = view ? JSON.stringify([view.file, view.revision]) : null;
|
|
72
|
+
if (revision !== undefined && revision !== graphRevision) {
|
|
73
|
+
return error(-32005, 'STALE_CONTEXT', '文档已变化,请从第一页重新读取。', { revision: graphRevision });
|
|
74
|
+
}
|
|
75
|
+
const output = view?.runtime.readPluginContext(fields, view.selection, { offset, limit }) ||
|
|
76
|
+
Object.fromEntries(fields.map(field => [field, field === 'selection' ? [] : null]));
|
|
77
|
+
if (output.document) Object.assign(output.document, { file: view.file, revision: view.revision });
|
|
78
|
+
if (output.graph) output.graph.revision = graphRevision;
|
|
79
|
+
return { result: { provider: { pluginId: 'clado.host' }, version: '1.0.0', output } };
|
|
80
|
+
}
|
|
81
|
+
function error(code, kind, message, data) {
|
|
82
|
+
return { error: { code, message, data: { kind, ...data } } };
|
|
83
|
+
}
|
|
84
|
+
const invalidParams = () => error(-32602, 'INVALID_PARAMS', '参数无效。');
|
|
85
|
+
function invokePlugin(instance, call) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const timeout = setTimeout(() => {
|
|
88
|
+
instance.pending.delete(call.id);
|
|
89
|
+
reject(new Error('插件挂载未在时限内响应。'));
|
|
90
|
+
}, 7000);
|
|
91
|
+
instance.pending.set(call.id, { resolve, reject, timeout });
|
|
92
|
+
instance.port.postMessage(JSON.stringify({ jsonrpc: '2.0', method: 'clado.invoke', id: call.id, params: call }));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function handleReply(instance, response) {
|
|
96
|
+
if (response?.jsonrpc !== '2.0' || response.method !== undefined) return false;
|
|
97
|
+
const pending = instance.pending.get(response.id);
|
|
98
|
+
if (!pending) return false;
|
|
99
|
+
instance.pending.delete(response.id);
|
|
100
|
+
clearTimeout(pending.timeout);
|
|
101
|
+
if (response.error) pending.reject(new Error(String(response.error.message || '插件执行失败。').slice(0, 500)));
|
|
102
|
+
else pending.resolve(response.result);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
async function dispatch(instance, method, params) {
|
|
106
|
+
if (!isObject(params)) return invalidParams();
|
|
107
|
+
if (method === 'clado.hello' && instance.state === 'connecting') {
|
|
108
|
+
if (params.ticket !== instance.ticket || params.entrypoint !== 'ui') return error(-32001, 'FORBIDDEN', '握手凭据无效。');
|
|
109
|
+
if (!Array.isArray(params.protocols) || !params.protocols.includes(catalog.protocol)) {
|
|
110
|
+
return error(-32004, 'UNSUPPORTED_VERSION', '无法协商插件协议。');
|
|
111
|
+
}
|
|
112
|
+
instance.state = 'identified';
|
|
113
|
+
return { result: {
|
|
114
|
+
protocol: catalog.protocol, instanceId: instance.instanceId, grants: instance.plugin.permissions,
|
|
115
|
+
settings: instance.plugin.settings,
|
|
116
|
+
scope: { workspaceId: catalog.workspaceId, viewId }, limits: { maxMessageBytes },
|
|
117
|
+
} };
|
|
118
|
+
}
|
|
119
|
+
if (method === 'clado.register' && instance.state === 'identified') {
|
|
120
|
+
if (params.entrypoint !== 'ui' || !sameList(params.mounts, [instance.contribution.id]) ||
|
|
121
|
+
!sameList(params.capabilities, []) || !sameList(params.events, [])) return invalidParams();
|
|
122
|
+
instance.state = 'registered';
|
|
123
|
+
clearTimeout(instance.timer);
|
|
124
|
+
registered.add(instance);
|
|
125
|
+
syncTheme(instance);
|
|
126
|
+
instance.surface.hidden = false;
|
|
127
|
+
return { result: { mounts: params.mounts, capabilities: [], events: [] } };
|
|
128
|
+
}
|
|
129
|
+
if (instance.state === 'registered') {
|
|
130
|
+
if (method === 'clado.call' && params.to?.capability === 'canvas.context.get' &&
|
|
131
|
+
(params.to.pluginId === undefined || params.to.pluginId === 'clado.host')) return context(instance, params);
|
|
132
|
+
if (['clado.capabilities.register', 'clado.capabilities.list', 'clado.call'].includes(method)) {
|
|
133
|
+
if (params.scope?.workspaceId !== catalog.workspaceId || params.scope.viewId !== viewId) {
|
|
134
|
+
return error(-32001, 'FORBIDDEN', '工作区或视图不属于当前插件实例。');
|
|
135
|
+
}
|
|
136
|
+
const identity = { pluginId: instance.plugin.id, mountId: instance.contribution.id };
|
|
137
|
+
if (method === 'clado.capabilities.register') {
|
|
138
|
+
const expected = instance.plugin.capabilities
|
|
139
|
+
.filter(provider => provider.mountId === identity.mountId)
|
|
140
|
+
.map(provider => provider.capability + '@' + provider.major);
|
|
141
|
+
if (instance.provided || !expected.length || !sameList(params.capabilities, expected)) return invalidParams();
|
|
142
|
+
instance.provided = true;
|
|
143
|
+
try { return { result: await capabilities.provide(identity, call => invokePlugin(instance, call)) || {} }; }
|
|
144
|
+
catch (cause) { instance.provided = false; throw cause; }
|
|
145
|
+
}
|
|
146
|
+
if (method === 'clado.capabilities.list') return { result: await capabilities.list(identity, params.query) };
|
|
147
|
+
return { result: await capabilities.call(identity, params.to, params.input) };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return error(-32601, 'METHOD_NOT_FOUND', '方法不可用。');
|
|
151
|
+
}
|
|
152
|
+
function accept(event) {
|
|
153
|
+
const { type, ticket } = event.data || {};
|
|
154
|
+
if (type !== 'clado-plugin:connect' || event.origin !== 'null') return;
|
|
155
|
+
const instance = tickets.get(ticket);
|
|
156
|
+
if (!instance || event.source !== instance.frame.contentWindow || event.ports.length) return;
|
|
157
|
+
tickets.delete(ticket);
|
|
158
|
+
const channel = new MessageChannel();
|
|
159
|
+
instance.port = channel.port1;
|
|
160
|
+
channel.port1.onmessage = async ({ data }) => {
|
|
161
|
+
if (typeof data !== 'string' || data.length > maxMessageBytes || byteLength(data) > maxMessageBytes) return;
|
|
162
|
+
let request, response;
|
|
163
|
+
try { request = JSON.parse(data); }
|
|
164
|
+
catch { response = error(-32700, 'PARSE_ERROR', '消息不是有效 JSON。'); }
|
|
165
|
+
if (handleReply(instance, request)) return;
|
|
166
|
+
const valid = isObject(request) && request.jsonrpc === '2.0' && typeof request.method === 'string' &&
|
|
167
|
+
typeof request.id === 'string' && request.id.length > 0 && request.id.length <= 128;
|
|
168
|
+
try {
|
|
169
|
+
response ||= valid ? await dispatch(instance, request.method, request.params)
|
|
170
|
+
: error(-32600, 'INVALID_REQUEST', '需要 JSON-RPC 请求和字符串 ID。');
|
|
171
|
+
} catch (cause) {
|
|
172
|
+
response = error(cause.data?.kind === 'FORBIDDEN' || cause.data?.code === 'FORBIDDEN' ? -32001 : -32000,
|
|
173
|
+
cause.data?.code || 'INTERNAL_ERROR', cause.message || '宿主暂时无法处理请求。',
|
|
174
|
+
cause.data?.issues && { issues: cause.data.issues });
|
|
175
|
+
}
|
|
176
|
+
const id = valid ? request.id : null;
|
|
177
|
+
let reply = JSON.stringify({ jsonrpc: '2.0', id, ...response });
|
|
178
|
+
const provider = response.result?.provider;
|
|
179
|
+
const replyLimit = provider?.pluginId === 'clado.host' && provider.capability === 'canvas.capture'
|
|
180
|
+
? Math.ceil(4 * 1024 * 1024 / 3) * 4 + 65536 : maxMessageBytes;
|
|
181
|
+
if (byteLength(reply) > replyLimit) {
|
|
182
|
+
reply = JSON.stringify({ jsonrpc: '2.0', id, ...error(-32009, 'MESSAGE_TOO_LARGE', '响应过大,请减少字段或分页大小。') });
|
|
183
|
+
}
|
|
184
|
+
channel.port1.postMessage(reply);
|
|
185
|
+
};
|
|
186
|
+
event.source.postMessage({ type: 'clado-plugin:port', ticket }, '*', [channel.port2]);
|
|
187
|
+
}
|
|
188
|
+
addEventListener('message', accept);
|
|
189
|
+
fetch('/library/plugins.json', { cache: 'no-store' }).then(response => {
|
|
190
|
+
if (!response.ok) throw new Error('插件清单读取失败。');
|
|
191
|
+
return response.json();
|
|
192
|
+
}).then(data => {
|
|
193
|
+
catalog = data;
|
|
194
|
+
for (const plugin of catalog.plugins) {
|
|
195
|
+
if (isEnabled(plugin.id)) for (const mountPoint of plugin.mounts) mount(plugin, mountPoint);
|
|
196
|
+
}
|
|
197
|
+
}).catch(error => console.error('Clado 插件加载失败', error));
|
|
198
|
+
|
|
199
|
+
};
|
|
200
|
+
})();
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
:root{color-scheme:light;--panel:#fff;--bg:#f6f8fb;--ink:#263140;--muted:#8290a0;--line:#e2e7ef;--accent:#0969da;--soft:#edf4ff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;font-size:12px}
|
|
2
|
-
*{box-sizing:border-box}body{margin:0;height:100vh;overflow:hidden;color:var(--ink);background:var(--panel)}
|
|
3
|
-
.viewer,.viewer main{position:absolute;inset:0}iframe{height:100%;width:100%;display:block;border:0}
|
|
4
|
-
#directory{position:fixed;left:18px;bottom:68px;width:288px;max-height:calc(100vh - 94px);overflow:auto;padding:17px 10px 10px;border:1px solid var(--line);border-radius:12px;background:var(--panel);z-index:25;box-shadow:0 12px 40px #15243b24}.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;border-color:transparent;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}.document-button[aria-current="page"]{background:var(--soft);border-color:var(--soft)}.document-button[aria-current="page"] strong{color:var(--accent)}.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{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}
|
|
2
|
+
*{box-sizing:border-box}body{margin:0;height:100vh;overflow:hidden;color:var(--ink);background:var(--panel)}
|
|
3
|
+
.viewer,.viewer main{position:absolute;inset:0}iframe{height:100%;width:100%;display:block;border:0}
|
|
5
4
|
.canvas-loading{position:absolute;inset:0;background:var(--panel);color:var(--muted);display:grid;place-items:center;font-size:12px;z-index:2}.canvas-loading[hidden],#directory[hidden],.update-error[hidden],.empty-state[hidden],.skipped[hidden]{display:none}.update-error{position:absolute;top:60px;left:16px;right:16px;z-index:5;background:#fff6dd;color:#896213;border:1px solid #ecd9a6;border-radius:7px;padding:10px 13px;font-size:11px;box-shadow:0 3px 12px #0001}.empty-state{position:absolute;inset:0;background:var(--panel);padding:70px 35px;text-align:center}.empty-state h1{font-size:17px;font-weight:550}.empty-state p{font-size:12px;line-height:1.9;color:var(--muted);max-width:360px;margin:15px auto}
|
|
6
|
-
|
|
7
|
-
[data-theme="dark"]{color-scheme:dark;--panel:#1c222b;--bg:#151a22;--ink:#dfe7ef;--muted:#9ba8b8;--line:#343e4c;--soft:#203753}@media(max-width:450px){.directory-toggle{left:12px;bottom:12px;padding:8px 12px}#directory{left:12px;bottom:58px;width:min(288px,calc(100vw - 24px));max-height:calc(100vh - 80px)}}
|
|
5
|
+
[data-theme="dark"]{color-scheme:dark;--panel:#1c222b;--bg:#151a22;--ink:#dfe7ef;--muted:#9ba8b8;--line:#343e4c;--soft:#203753}
|
|
8
6
|
[hidden]{display:none!important}
|
|
9
|
-
.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(--bg);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}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="zh-CN" data-theme="light">
|
|
3
|
-
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Clado · Markdown 目录预览</title><link rel="stylesheet" href="library.css"
|
|
3
|
+
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Clado · Markdown 目录预览</title><link rel="stylesheet" href="library.css"><!--CLADO-PLUGIN-STYLES--></head>
|
|
4
4
|
<body>
|
|
5
|
-
<button id="directoryButton" class="directory-toggle" aria-expanded="false" aria-controls="directory" title="切换 Markdown 画布">文档 <span id="fileCount">…</span></button>
|
|
6
|
-
<aside id="directory" aria-label="Markdown 画布目录" hidden>
|
|
7
|
-
<div class="directory-heading"><strong>Markdown/</strong><span>选择文档,打开对应画布</span></div>
|
|
8
|
-
<label class="directory-search"><input id="documentSearch" type="search" aria-label="搜索文档" placeholder="搜索名称或路径…"></label>
|
|
9
|
-
<nav id="documentList" aria-label="可用 Markdown"></nav>
|
|
10
|
-
<div class="directory-current"><strong id="currentTitle" hidden>正在扫描 Markdown…</strong><span id="currentPath" hidden>Markdown/</span><span id="syncStatus" role="status">连接本地目录</span></div>
|
|
11
|
-
<div class="directory-actions"><button id="backButton" disabled>← 返回</button><button id="refreshButton" title="重新扫描目录并刷新当前文档">刷新</button><button id="sourceButton">源文</button></div>
|
|
12
|
-
<button id="skippedButton" class="skipped" hidden></button>
|
|
13
|
-
</aside>
|
|
14
5
|
<div class="viewer">
|
|
15
6
|
<main><div id="updateError" class="update-error" role="alert" hidden></div><iframe id="canvas" title="当前 Markdown 的脑图、卡片与文档"></iframe><div id="canvasLoading" class="canvas-loading">正在读取 Markdown…</div><div id="emptyState" class="empty-state" hidden><h1>目录中还没有可展示的画布</h1><p>让 AI 连接当前服务的 MCP,读取模板并创建 .mdc 文档,保存后会自动出现在这里。</p></div></main>
|
|
16
7
|
</div>
|
|
17
|
-
|
|
18
|
-
<script src="/tree.js"></script>
|
|
8
|
+
<!--CLADO-PLUGIN-SCRIPTS-->
|
|
19
9
|
<script src="library.js"></script>
|
|
20
10
|
</body></html>
|
|
@@ -1,11 +1,152 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
const $ = selector => document.querySelector(selector);
|
|
3
3
|
let frame = $('#canvas');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const config
|
|
4
|
+
let index = { documents: [], skipped: [] }, selected = '', mode = window.__CLADO_WORKSPACE__?.mode || 'mindmap', version = '', history = [], busy = false, design = { theme: window.__CLADO_WORKSPACE__?.theme || 'light' }, pendingView = null, pendingOpen = null, pendingAnchor = '', chainModal = false, deferredRefresh = false;
|
|
5
|
+
const config = window.__CLADO_WORKSPACE__ || {}, offline = config.offline;
|
|
6
|
+
const settings = config.pluginSettings || {};
|
|
7
|
+
mode = settings['clado.view-controls']?.defaultMode || mode;
|
|
8
|
+
const pluginKey = 'clado-disabled-plugins:' + (config.pluginPreferenceKey || location.pathname);
|
|
9
|
+
let disabledPlugins = new Set();
|
|
10
|
+
try {
|
|
11
|
+
const saved = JSON.parse(localStorage.getItem(pluginKey) || '[]');
|
|
12
|
+
if (Array.isArray(saved)) disabledPlugins = new Set(saved);
|
|
13
|
+
} catch {}
|
|
14
|
+
const items = [
|
|
15
|
+
{ id: 'clado.brand', name: 'Clado 设置', reason: '管理入口,始终启用' },
|
|
16
|
+
{ id: 'clado.view-controls', name: '视图切换', detail: '脑图、卡片和文档视图' },
|
|
17
|
+
{ id: 'clado.directory', name: '文档目录', detail: '查找和打开工作区文档' },
|
|
18
|
+
{ id: 'clado.agent', name: '灵感', detail: '与 Agent 对话并协作修改画布', ...(!config.agent && { reason: offline ? '需要在线服务' : '当前服务已关闭聊天' }) },
|
|
19
|
+
...(config.pluginCatalog || []),
|
|
20
|
+
];
|
|
21
|
+
const isEnabled = id => id === 'clado.brand' || !items.some(item => item.id === id && item.reason) && !disabledPlugins.has(id);
|
|
22
|
+
const ui = window.CladoPluginUI;
|
|
23
|
+
const capabilities = window.CladoCapabilityBridge?.();
|
|
24
|
+
const host = ui.createHost(capabilities, isEnabled);
|
|
25
|
+
const screenshot = window.CladoScreenshot?.();
|
|
26
|
+
let lensOpen = false;
|
|
27
|
+
function reloadWithMode(preserve) {
|
|
28
|
+
try {
|
|
29
|
+
if (preserve) sessionStorage.setItem(pluginKey + ':mode', mode);
|
|
30
|
+
else sessionStorage.removeItem(pluginKey + ':mode');
|
|
31
|
+
} catch {}
|
|
32
|
+
location.reload();
|
|
33
|
+
}
|
|
34
|
+
async function editPluginSettings(id, value, expected) {
|
|
35
|
+
const write = arguments.length > 1;
|
|
36
|
+
const response = await fetch('/library/plugin-settings?id=' + encodeURIComponent(id), write ? {
|
|
37
|
+
method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ value, expected }),
|
|
38
|
+
} : { cache: 'no-store' });
|
|
39
|
+
const result = await response.json();
|
|
40
|
+
if (!response.ok) throw new Error(result.error);
|
|
41
|
+
if (write) reloadWithMode(id !== 'clado.view-controls');
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
const brand = ui.mountBrand(host, {
|
|
45
|
+
plugins: {
|
|
46
|
+
items, isEnabled,
|
|
47
|
+
edit: config.hasPluginSettings ? editPluginSettings : null,
|
|
48
|
+
install: config.canInstallPlugins && (async files => {
|
|
49
|
+
const response = await fetch('/library/install-plugin', {
|
|
50
|
+
method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ files }),
|
|
51
|
+
});
|
|
52
|
+
const result = await response.json();
|
|
53
|
+
if (!response.ok) throw new Error(result.error);
|
|
54
|
+
return result;
|
|
55
|
+
}),
|
|
56
|
+
refresh: () => reloadWithMode(true),
|
|
57
|
+
save(disabled) {
|
|
58
|
+
const next = new Set(disabledPlugins);
|
|
59
|
+
for (const plugin of items) {
|
|
60
|
+
if (plugin.reason) continue;
|
|
61
|
+
if (disabled.includes(plugin.id)) next.add(plugin.id);
|
|
62
|
+
else next.delete(plugin.id);
|
|
63
|
+
}
|
|
64
|
+
localStorage.setItem(pluginKey, JSON.stringify([...next]));
|
|
65
|
+
reloadWithMode(true);
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
setTheme: theme => {
|
|
69
|
+
if (modalLocked()) return;
|
|
70
|
+
try { localStorage.setItem('clado-theme', theme); } catch {}
|
|
71
|
+
setDesign({ theme });
|
|
72
|
+
post('theme', { theme });
|
|
73
|
+
},
|
|
74
|
+
capture: screenshot && settings['clado.brand']?.showScreenshot !== false && (async () => {
|
|
75
|
+
try { await screenshot.download(await screenshot.capture({}, readScreenshotCanvas)); }
|
|
76
|
+
catch (error) { directory.showMessage('截图失败', error.message); }
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
const updateControls = ui.mountViewControls(host, {
|
|
80
|
+
setMode: next => {
|
|
81
|
+
if (modalLocked() || next === mode) return;
|
|
82
|
+
mode = next;
|
|
83
|
+
saveView();
|
|
84
|
+
syncChrome();
|
|
85
|
+
frame.contentWindow.CladoPrototype?.setMode?.(next);
|
|
86
|
+
},
|
|
87
|
+
clearFocus: () => frame.contentWindow.CladoRuntime?.clearFocus(),
|
|
88
|
+
showDiagnostics: () => frame.contentWindow.CladoCanvasControls?.showDiagnostics(),
|
|
89
|
+
});
|
|
90
|
+
const directory = window.CladoDirectoryPlugin(host, {
|
|
91
|
+
showFilename: settings['clado.directory']?.showFilename !== false,
|
|
92
|
+
open: file => open(file),
|
|
93
|
+
openFromCapability,
|
|
94
|
+
refresh: () => scan(true),
|
|
95
|
+
back: () => {
|
|
96
|
+
if (modalLocked()) return;
|
|
97
|
+
const previous = history.pop();
|
|
98
|
+
if (previous) open(previous, '', { back: true });
|
|
99
|
+
},
|
|
100
|
+
readSource: async () => {
|
|
101
|
+
if (!selected) throw new Error('no document');
|
|
102
|
+
if (offline) return { file: selected, source: offline.sources[selected], offline: true };
|
|
103
|
+
const file = selected;
|
|
104
|
+
const response = await fetch('/library/source.mdc?file=' + encodeURIComponent(file), { cache: 'no-store' });
|
|
105
|
+
if (!response.ok) throw new Error('source');
|
|
106
|
+
return { file, source: await response.text() };
|
|
107
|
+
},
|
|
108
|
+
isLocked: modalLocked,
|
|
109
|
+
});
|
|
110
|
+
function syncChrome() {
|
|
111
|
+
brand.sync(design.theme);
|
|
112
|
+
updateControls({ ...frame.contentWindow.CladoCanvasControls?.state(), mode });
|
|
113
|
+
}
|
|
7
114
|
const selectionTab = config.selection ? crypto.randomUUID() : null;
|
|
8
115
|
let aiSelection = null, selectionRequest = Promise.resolve(), pageHidden = false;
|
|
116
|
+
let readyCanvas = null;
|
|
117
|
+
const canvasWaiters = new Set();
|
|
118
|
+
function readScreenshotCanvas() {
|
|
119
|
+
if (!selected || !frame.contentWindow.CladoRuntime || !$('#canvasLoading').hidden ||
|
|
120
|
+
(!offline && readyCanvas?.frame !== frame)) return null;
|
|
121
|
+
return { frame, file: selected, revision: version, mode, design };
|
|
122
|
+
}
|
|
123
|
+
if (screenshot && capabilities) {
|
|
124
|
+
host.capabilities('clado.host', 'canvas')?.provide(
|
|
125
|
+
({ input }) => screenshot.capture(input, readScreenshotCanvas),
|
|
126
|
+
).catch(error => console.warn('Clado 截图能力注册失败', error));
|
|
127
|
+
}
|
|
128
|
+
if (isEnabled('clado.agent')) window.CladoAgentPlugin(host, {
|
|
129
|
+
placeholder: settings['clado.agent']?.placeholder,
|
|
130
|
+
agentName: config.agentProfile === 'codex' ? 'Codex' : settings['clado.agent']?.name,
|
|
131
|
+
readCanvas() {
|
|
132
|
+
if (readyCanvas?.frame !== frame) return undefined;
|
|
133
|
+
const { file, revision } = readyCanvas;
|
|
134
|
+
const selection = aiSelection?.file === file && aiSelection.version === revision ? aiSelection.nodes : [];
|
|
135
|
+
return { file, revision, selection };
|
|
136
|
+
},
|
|
137
|
+
viewId: capabilities?.viewId,
|
|
138
|
+
});
|
|
139
|
+
if (!['light', 'dark'].includes(design.theme)) design.theme = 'light';
|
|
140
|
+
try { const savedTheme = localStorage.getItem('clado-theme'); if (['light', 'dark'].includes(savedTheme)) design.theme = savedTheme; } catch {}
|
|
141
|
+
if (config.plugins) window.CladoPluginHost({
|
|
142
|
+
host, capabilities, isEnabled,
|
|
143
|
+
readView() {
|
|
144
|
+
if (readyCanvas?.frame !== frame) return null;
|
|
145
|
+
const { file, revision } = readyCanvas;
|
|
146
|
+
const selection = aiSelection?.file === file && aiSelection.version === revision ? aiSelection.nodes : [];
|
|
147
|
+
return { file, revision, selection, runtime: frame.contentWindow.CladoRuntime };
|
|
148
|
+
},
|
|
149
|
+
});
|
|
9
150
|
function showSelection() {
|
|
10
151
|
if (selectionTab) frame.contentWindow.postMessage({ type: 'clado-workspace:selection', nodes: aiSelection?.nodes || [] }, location.origin);
|
|
11
152
|
}
|
|
@@ -43,6 +184,11 @@
|
|
|
43
184
|
const storageKey='clado-library-view:v2:'+location.pathname;
|
|
44
185
|
const post = (type, extra = {}) => { if (parent !== window) parent.postMessage({ type: 'clado-prototype:' + type, board: 'library', ...extra }, location.origin); };
|
|
45
186
|
try { const saved = JSON.parse(sessionStorage.getItem(storageKey) || '{}'); selected = saved.file || ''; if (!config.mode && ['mindmap','cards','doc'].includes(saved.mode)) mode = saved.mode; } catch {}
|
|
187
|
+
try {
|
|
188
|
+
const restoredMode = sessionStorage.getItem(pluginKey + ':mode');
|
|
189
|
+
if (['mindmap','cards','doc'].includes(restoredMode)) mode = restoredMode;
|
|
190
|
+
if (restoredMode) sessionStorage.removeItem(pluginKey + ':mode');
|
|
191
|
+
} catch {}
|
|
46
192
|
const requestedFile = new URLSearchParams(location.search).get('file');
|
|
47
193
|
if (requestedFile || config.entry) selected = requestedFile || config.entry;
|
|
48
194
|
pendingAnchor = new URLSearchParams(location.search).get('anchor') || '';
|
|
@@ -50,35 +196,57 @@
|
|
|
50
196
|
function modalLocked() { try { return chainModal || !!frame.contentWindow.CladoPrototype?.isChainOpen?.(); } catch { return chainModal; } }
|
|
51
197
|
function chainLock(value, currentMode) {
|
|
52
198
|
chainModal=!!value;
|
|
199
|
+
if (chainModal) brand.close();
|
|
200
|
+
host.setHidden(chainModal || lensOpen);
|
|
201
|
+
directory.setLocked(chainModal);
|
|
202
|
+
syncChrome();
|
|
53
203
|
if(['cards','mindmap','doc'].includes(currentMode)) { mode=currentMode;saveView(); }
|
|
54
|
-
if(chainModal) { directory(false);if($('#details').open)$('#details').close(); }
|
|
55
|
-
['#directoryButton','#backButton','#refreshButton','#sourceButton','#skippedButton'].forEach(selector=>{const button=$(selector);button.disabled=chainModal || (selector==='#backButton' && history.length===0);});
|
|
56
204
|
if(!chainModal) { const force=deferredRefresh;deferredRefresh=false;scan(force); }
|
|
57
205
|
}
|
|
58
|
-
function
|
|
59
|
-
function details(title, html) { if(modalLocked())return; $('#detailsTitle').textContent = title; $('#detailsBody').innerHTML = html; if (!$('#details').open) $('#details').showModal(); }
|
|
60
|
-
function renderDirectory() {
|
|
61
|
-
const signature = JSON.stringify({ documents: index.documents, skipped: index.skipped, selected, query:$('#documentSearch').value, history: history.length });
|
|
62
|
-
if (signature === directorySignature) return;
|
|
63
|
-
directorySignature = signature;
|
|
64
|
-
$('#fileCount').textContent = index.documents.length;
|
|
65
|
-
document.querySelector('.directory-heading strong').textContent = index.root || 'Markdown';
|
|
66
|
-
CladoDocumentTree($('#documentList'),index.documents,{selected,query:$('#documentSearch').value,folders,onOpen:file=>{open(file);directory(false);}});
|
|
67
|
-
$('#skippedButton').hidden = !index.skipped.length; $('#skippedButton').textContent = index.skipped.length + ' 份文档未收录 · 查看原因';
|
|
68
|
-
$('#backButton').disabled = modalLocked() || history.length === 0;
|
|
69
|
-
}
|
|
206
|
+
function renderDirectory() { directory.update(index, selected, history.length > 0); }
|
|
70
207
|
let renderRequest = 0;
|
|
208
|
+
async function openFromCapability(file) {
|
|
209
|
+
const failure = (kind, message) => Object.assign(new Error(message), { kind });
|
|
210
|
+
if (modalLocked() || lensOpen) throw failure('VIEW_LOCKED', '请先关闭链路或内容放大窗口。');
|
|
211
|
+
let targetDocument = index.documents.find(entry => entry.file === file);
|
|
212
|
+
if (!targetDocument) {
|
|
213
|
+
const response = await fetch('/library/index.json', { cache: 'no-store' });
|
|
214
|
+
if (!response.ok) throw failure('NAVIGATION_FAILED', '读取文档目录失败,请重试。');
|
|
215
|
+
const latest = await response.json();
|
|
216
|
+
targetDocument = latest.documents.find(entry => entry.file === file);
|
|
217
|
+
if (!targetDocument) throw failure('DOCUMENT_NOT_FOUND', '找不到可展示的画布:' + file);
|
|
218
|
+
index = latest;
|
|
219
|
+
}
|
|
220
|
+
if (readyCanvas?.file === file && readyCanvas.frame === frame && selected === file) return { file, title: targetDocument.title, mode };
|
|
221
|
+
directory.close();
|
|
222
|
+
if (!await open(file)) throw failure('NAVIGATION_FAILED', '未能打开目标画布。');
|
|
223
|
+
const target = frame;
|
|
224
|
+
if (readyCanvas?.frame !== target) await new Promise((resolve, reject) => {
|
|
225
|
+
const timeout = setTimeout(() => {
|
|
226
|
+
canvasWaiters.delete(onReady);
|
|
227
|
+
reject(failure('NAVIGATION_FAILED', '等待目标画布加载超时。'));
|
|
228
|
+
}, 6500);
|
|
229
|
+
function onReady(canvas) {
|
|
230
|
+
canvasWaiters.delete(onReady);
|
|
231
|
+
clearTimeout(timeout);
|
|
232
|
+
if (canvas.frame === target && canvas.file === file) resolve();
|
|
233
|
+
else reject(failure('NAVIGATION_FAILED', '目标画布已被另一次导航替换。'));
|
|
234
|
+
}
|
|
235
|
+
canvasWaiters.add(onReady);
|
|
236
|
+
});
|
|
237
|
+
if (readyCanvas?.frame !== frame || readyCanvas?.file !== file) throw failure('NAVIGATION_FAILED', '目标画布已被另一次导航替换。');
|
|
238
|
+
return { file, title: targetDocument.title, mode };
|
|
239
|
+
}
|
|
71
240
|
async function open(file, anchor = '', options = {}) {
|
|
72
241
|
if(modalLocked()) { if(options.update)deferredRefresh=true;return; }
|
|
73
242
|
pendingAnchor=anchor;
|
|
74
243
|
const doc = index.documents.find(d => d.file === file);
|
|
75
|
-
if (!doc) {
|
|
244
|
+
if (!doc) { directory.showMessage('这个 Markdown 暂未收录', file + ' 不在有效画布目录中。可以让 AI 检查文件路径和解析状态。'); return; }
|
|
76
245
|
if (selected && file !== selected && !options.back) history.push(selected);
|
|
77
|
-
if (options.update) { try { pendingView = frame.contentWindow.CladoPrototype?.captureView?.(); } catch {} }
|
|
246
|
+
if (options.update && readyCanvas?.frame === frame && readyCanvas.file === file) { try { pendingView = frame.contentWindow.CladoPrototype?.captureView?.(); } catch {} }
|
|
78
247
|
else pendingView = null;
|
|
79
248
|
const request = ++renderRequest, previousVersion = version, requestedMode = mode;
|
|
80
|
-
selected = file; version = doc.version; saveView(); renderDirectory();
|
|
81
|
-
$('#currentTitle').textContent = doc.title; $('#currentPath').textContent = (index.root || '') + file;
|
|
249
|
+
selected = file; version = doc.version; saveView(); renderDirectory(); syncChrome();
|
|
82
250
|
$('#updateError').hidden = true; $('#emptyState').hidden = true; $('#canvasLoading').hidden = false;
|
|
83
251
|
// Give each render its own browsing context. A late ready/message from the
|
|
84
252
|
// previous document must never complete a newer render or restore its view.
|
|
@@ -86,25 +254,29 @@
|
|
|
86
254
|
let html;
|
|
87
255
|
if(offline) html=offline.canvases[file].replace(/<!--CLADO-ASSET:(\d+)-->/g,(_,id)=>offline.shared?.[id] || '');
|
|
88
256
|
else {
|
|
89
|
-
const response = await fetch('/library/canvas?file=' + encodeURIComponent(file) + '&mode=' + mode + '&revision=' + version + (anchor ? '&anchor=' + encodeURIComponent(anchor) : ''), {cache:'no-store'});
|
|
257
|
+
const response = await fetch('/library/canvas?file=' + encodeURIComponent(file) + '&mode=' + mode + '&theme=' + design.theme + '&chrome=workspace&revision=' + version + (anchor ? '&anchor=' + encodeURIComponent(anchor) : ''), {cache:'no-store'});
|
|
90
258
|
if(!response.ok)throw new Error('render');
|
|
91
259
|
html = await response.text();
|
|
92
260
|
}
|
|
93
261
|
if(request !== renderRequest)return;
|
|
94
262
|
if(modalLocked()) { deferredRefresh=true;version=previousVersion;$('#canvasLoading').hidden=true;return; }
|
|
95
|
-
if(mode !== requestedMode) { version=previousVersion;open(file,anchor,{...options,update:true});
|
|
263
|
+
if(mode !== requestedMode) { version=previousVersion;return open(file,anchor,{...options,update:true}); }
|
|
96
264
|
const nextFrame = document.createElement('iframe');
|
|
97
265
|
nextFrame.id = 'canvas'; nextFrame.title = frame.title;
|
|
98
266
|
nextFrame.srcdoc = html;
|
|
99
267
|
if (aiSelection && aiSelection.file !== file) setSelection(null);
|
|
100
268
|
frame.replaceWith(nextFrame); frame = nextFrame;
|
|
269
|
+
lensOpen = false;
|
|
270
|
+
host.setHidden(false);
|
|
271
|
+
syncChrome();
|
|
272
|
+
return true;
|
|
101
273
|
} catch {
|
|
102
274
|
if(request !== renderRequest)return;
|
|
103
275
|
version = previousVersion; $('#canvasLoading').hidden = true;
|
|
104
276
|
$('#updateError').textContent = '画布读取失败,保留上次画面并自动重试。'; $('#updateError').hidden = false; status('当前画布未更新', true);
|
|
105
277
|
}
|
|
106
278
|
}
|
|
107
|
-
|
|
279
|
+
const status = (message, error) => directory.status(message, error);
|
|
108
280
|
async function scan(force = false) {
|
|
109
281
|
if (busy) return; busy = true;
|
|
110
282
|
try {
|
|
@@ -121,7 +293,7 @@
|
|
|
121
293
|
if (pendingOpen && index.documents.some(d=>d.file===pendingOpen)) { const file=pendingOpen;pendingOpen=null;open(file); }
|
|
122
294
|
if (selected && !version && !index.documents.some(d=>d.file===selected)) { selected='';saveView(); }
|
|
123
295
|
if (!selected && index.documents.length) open(index.documents[0].file);
|
|
124
|
-
else if (!selected) { $('#canvasLoading').hidden = true; $('#emptyState').hidden = false;
|
|
296
|
+
else if (!selected) { $('#canvasLoading').hidden = true; $('#emptyState').hidden = false; syncChrome(); status('目录已扫描'); post('ready'); }
|
|
125
297
|
else {
|
|
126
298
|
const doc = index.documents.find(d => d.file === selected);
|
|
127
299
|
if (!doc && !version && index.documents.length) open(index.documents[0].file);
|
|
@@ -144,14 +316,31 @@
|
|
|
144
316
|
setSelection(nodes.length ? { file: selected, version, nodes } : null);
|
|
145
317
|
return;
|
|
146
318
|
}
|
|
147
|
-
if(data?.type === 'clado-library:chain-modal') { chainLock(data.value,data.mode);return; }
|
|
148
|
-
if(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
319
|
+
if (data?.type === 'clado-library:chain-modal') { chainLock(data.value, data.mode); return; }
|
|
320
|
+
if (data?.type === 'clado-library:lens-modal') {
|
|
321
|
+
lensOpen = !!data.value;
|
|
322
|
+
if (lensOpen) { brand.close(); directory.close(); }
|
|
323
|
+
host.setHidden(chainModal || lensOpen);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if(modalLocked() && ['clado-library:open','clado-library:ready','clado-library:missing'].includes(data?.type))return;
|
|
327
|
+
if (data?.type === 'clado-library:open') { directory.close(); open(data.target, data.anchor); }
|
|
328
|
+
else if (data?.type === 'clado-library:dismiss-directory') { brand.close(); directory.close(); }
|
|
329
|
+
else if (data?.type === 'clado-library:missing') directory.showMessage('链接超出当前目录', '请选择当前工作区中的文档。链接:' + data.target);
|
|
330
|
+
else if (data?.type === 'clado-library:view-state') syncChrome();
|
|
154
331
|
else if (data?.type === 'clado-library:ready') {
|
|
332
|
+
if (data.file === selected && data.version === version) {
|
|
333
|
+
readyCanvas = { frame, file: data.file, revision: data.version };
|
|
334
|
+
if (!offline && window.history) {
|
|
335
|
+
const url = new URL(location.href);
|
|
336
|
+
if (url.searchParams.get('file') !== data.file) {
|
|
337
|
+
url.searchParams.set('file', data.file);
|
|
338
|
+
url.searchParams.delete('anchor');
|
|
339
|
+
window.history.replaceState(window.history.state, '', url);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
for (const notify of canvasWaiters) notify(readyCanvas);
|
|
343
|
+
}
|
|
155
344
|
if (selectionTab && data.file === selected && data.version && aiSelection && aiSelection.version !== data.version) {
|
|
156
345
|
const api = frame.contentWindow.CladoRuntime;
|
|
157
346
|
const nodes = aiSelection.nodes.filter(node => api?.hasSelectionPath(node));
|
|
@@ -159,22 +348,16 @@
|
|
|
159
348
|
}
|
|
160
349
|
showSelection();
|
|
161
350
|
if(offline){frame.contentWindow.postMessage({type:'clado-workspace:display',mode,theme:design.theme,anchor:pendingAnchor},'*');pendingAnchor='';}
|
|
162
|
-
else mode
|
|
351
|
+
else if (mode !== data.mode) frame.contentWindow.CladoPrototype?.setMode?.(mode);
|
|
352
|
+
saveView(); $('#canvasLoading').hidden = true; syncChrome();
|
|
163
353
|
try{frame.contentWindow.CladoPrototype?.setDesign(design);}catch{}
|
|
164
354
|
if (!offline && pendingView) { const view = pendingView; pendingView = null; requestAnimationFrame(() => requestAnimationFrame(() => frame.contentWindow.CladoPrototype?.restoreView?.(view))); }
|
|
165
355
|
status('已同步 ' + new Date(index.documents.find(d => d.file === selected)?.modified || Date.now()).toLocaleTimeString('zh-CN', { hour12: false })); post('ready');
|
|
166
356
|
}
|
|
167
357
|
});
|
|
168
|
-
function setDesign(next) { design = { ...design, ...next }; document.documentElement.dataset.theme = design.theme || 'light'; if (design.accent) document.documentElement.style.setProperty('--accent', design.accent); try { frame.contentWindow.CladoPrototype?.setDesign(design); } catch {} }
|
|
358
|
+
function setDesign(next) { design = { ...design, ...next }; document.documentElement.dataset.theme = design.theme || 'light'; if (design.accent) document.documentElement.style.setProperty('--accent', design.accent); try { frame.contentWindow.CladoPrototype?.setDesign(design); } catch {} syncChrome(); }
|
|
169
359
|
window.CladoPrototype = { setDesign, fit: () => frame.contentWindow.CladoPrototype?.fit(), closeLens: () => frame.contentWindow.CladoPrototype?.closeLens() };
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
document.addEventListener('keydown', event => { if (event.key === 'Escape' && !$('#directory').hidden) { directory(false); $('#directoryButton').focus(); } });
|
|
174
|
-
$('#refreshButton').onclick = () => scan(true);
|
|
175
|
-
$('#backButton').onclick = () => { if(modalLocked())return;const previous = history.pop(); if (previous) open(previous, '', { back: true }); };
|
|
176
|
-
$('#closeDetails').onclick = () => $('#details').close();
|
|
177
|
-
$('#skippedButton').onclick = () => details('扫描后未收录的 Markdown', '<p>目录只显示能通过解析的画布。解析失败可能来自普通说明文档,也可能需要修正内容;具体原因如下。</p>' + index.skipped.map(item => '<section class="skip-item"><strong>' + esc(item.file) + '</strong>' + item.diagnostics.map(d => '<p><code>' + esc(d.code) + '</code> · ' + esc(d.message) + '</p>').join('') + '</section>').join(''));
|
|
178
|
-
$('#sourceButton').onclick = async () => { if(modalLocked())return;try { const response = offline ? {ok:true,text:async()=>offline.sources[selected]} : await fetch('/library/source.mdc?file=' + encodeURIComponent(selected), { cache: 'no-store' }); if (!response.ok) throw new Error('source'); details(selected, (offline?'<p>这是 HTML 内嵌的只读源文。通过 MCP 修改工作区后重新构建以更新交付文件。</p><pre>':'<p>源文只读预览。请通过 Clado MCP 修改内容,保存后当前画布自动同步。</p><pre>') + esc(await response.text()) + '</pre>'); } catch { details('暂时读不到源文', '<p>请检查文档是否已删除,或是否出现解析错误。</p>'); } };
|
|
179
|
-
directory(false); scan(); if(!offline)setInterval(() => scan(), 1200);
|
|
360
|
+
setDesign(design);
|
|
361
|
+
scan();
|
|
362
|
+
if (!offline) setInterval(() => scan(), 1200);
|
|
180
363
|
})();
|