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.
- package/README.md +30 -2
- package/bin/clado.js +55 -3
- package/docs/plugin-development.md +135 -0
- package/docs/plugin-ui.md +43 -0
- package/docs/release.md +26 -0
- package/package.json +8 -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 +31 -17
- package/src/html/app-css.js +11 -42
- package/src/html/canvas-chain.js +5 -6
- package/src/html/canvas-focus.js +3 -4
- package/src/html/canvas-screenshot.js +199 -0
- package/src/html/canvas-ui.css +37 -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 +47 -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 +72 -11
- 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 +280 -44
- package/src/server/canvas-capture.js +47 -0
- package/src/server/export.js +5 -2
- package/src/server/mcp.js +44 -19
- 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 +157 -12
- package/src/skill/targets.js +1 -1
- package/src/util/update.js +58 -0
- package/src/vendor/html-to-image.min.js +24 -0
- package/src/workspace/content.js +3 -2
- package/src/workspace/service.js +81 -21
- package/src/workspace/tree.js +38 -0
- package/src/server/assets/tree.js +0 -26
package/src/workspace/tree.js
CHANGED
|
@@ -24,6 +24,44 @@ export function records(tree) {
|
|
|
24
24
|
}
|
|
25
25
|
export const samePath = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
26
26
|
export const insidePath = (a, parent) => parent.length <= a.length && parent.every((x, i) => a[i] === x);
|
|
27
|
+
export function replaceNodeBody(tree, node, content) {
|
|
28
|
+
const { source } = tree;
|
|
29
|
+
const { headingLine, bodyStartLine } = node.location;
|
|
30
|
+
const next = content.trim();
|
|
31
|
+
if (next === node.content) return source;
|
|
32
|
+
|
|
33
|
+
const breaks = [...source.matchAll(/\r?\n/g)];
|
|
34
|
+
const eol = breaks[headingLine - 1]?.[0] || breaks[0]?.[0] || '\n';
|
|
35
|
+
const lineStart = line => line === 1 ? 0 : breaks[line - 2].index + breaks[line - 2][0].length;
|
|
36
|
+
if (bodyStartLine === null) {
|
|
37
|
+
const afterHeading = breaks[headingLine - 1] ? lineStart(headingLine + 1) : source.length;
|
|
38
|
+
const separator = breaks[headingLine - 1] ? eol : eol + eol;
|
|
39
|
+
const following = source.slice(afterHeading);
|
|
40
|
+
return source.slice(0, afterHeading) + separator + next.replaceAll('\n', eol) + eol + (following && !/^\s*\r?\n/.test(following) ? eol : '') + following;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const old = node.content;
|
|
44
|
+
// 解析后的正文统一使用 LF;把变化范围映射回原始行,保留改动外的格式。
|
|
45
|
+
let start = 0, oldEnd = old.length, nextEnd = next.length;
|
|
46
|
+
while (start < oldEnd && start < nextEnd && old[start] === next[start]) start++;
|
|
47
|
+
while (start < oldEnd && start < nextEnd && old[oldEnd - 1] === next[nextEnd - 1]) { oldEnd--; nextEnd--; }
|
|
48
|
+
const bodyStart = lineStart(bodyStartLine);
|
|
49
|
+
const indentation = source.slice(bodyStart).match(/^[^\S\r\n]*/)[0].length;
|
|
50
|
+
const sourceOffset = offset => {
|
|
51
|
+
const lines = old.slice(0, offset).split('\n');
|
|
52
|
+
return lines.length === 1 ? bodyStart + indentation + offset : lineStart(bodyStartLine + lines.length - 1) + lines.at(-1).length;
|
|
53
|
+
};
|
|
54
|
+
const replacement = next.slice(start, nextEnd).replaceAll('\n', eol);
|
|
55
|
+
if (start === oldEnd && start === old.length && replacement.startsWith(eol)) {
|
|
56
|
+
const end = sourceOffset(start);
|
|
57
|
+
const trailingSpaces = source.slice(end).match(/^[^\S\r\n]*/)[0].length;
|
|
58
|
+
return source.slice(0, end + trailingSpaces) + replacement + source.slice(end + trailingSpaces);
|
|
59
|
+
}
|
|
60
|
+
if (start === 0 && oldEnd === 0 && replacement.endsWith(eol)) {
|
|
61
|
+
return source.slice(0, bodyStart) + replacement + source.slice(bodyStart);
|
|
62
|
+
}
|
|
63
|
+
return source.slice(0, sourceOffset(start)) + replacement + source.slice(sourceOffset(oldEnd));
|
|
64
|
+
}
|
|
27
65
|
export function findNode(tree, path) {
|
|
28
66
|
if (!Array.isArray(path) || !path.length || path.some(x => typeof x !== 'string' || !x)) throw new DocumentError('node 必须为非空标题数组,使用读取结果里的 path。');
|
|
29
67
|
const hits = records(tree).filter(r => samePath(r.path, path));
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
window.CladoDocumentTree = function (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='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
|
-
})();
|