easel-canvas 0.1.1 → 0.2.0
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 +62 -18
- package/bin/mcp.mjs +143 -40
- package/bin/server.mjs +67 -5
- package/dist/assets/index-BZFSkKqU.css +1 -0
- package/dist/assets/index-BwyrrnkP.js +65 -0
- package/dist/index.html +3 -3
- package/dist/viewer/viewer.css +1 -0
- package/dist/viewer/viewer.js +49 -0
- package/package.json +2 -2
- package/server/activity.mjs +370 -0
- package/server/agents.mjs +20 -0
- package/server/args.mjs +22 -2
- package/server/board.mjs +4 -16
- package/server/boards.mjs +46 -21
- package/server/browser.mjs +68 -0
- package/server/chat.mjs +364 -54
- package/server/connect.mjs +94 -0
- package/server/copies.mjs +105 -0
- package/server/custom.mjs +101 -0
- package/server/export.mjs +627 -0
- package/server/forks.mjs +214 -0
- package/server/fsutil.mjs +8 -0
- package/server/history.mjs +152 -24
- package/server/html.mjs +11 -1
- package/server/index.mjs +153 -16
- package/server/occupancy.mjs +183 -0
- package/server/permissions.mjs +141 -0
- package/server/place.mjs +87 -0
- package/server/registry.mjs +110 -0
- package/server/routes.mjs +23 -54
- package/server/runs.mjs +167 -0
- package/server/snapshot.mjs +21 -9
- package/server/tokens.mjs +4 -1
- package/server/update.mjs +63 -0
- package/server/watch.mjs +12 -1
- package/dist/assets/index-DXUYTbPc.js +0 -55
- package/dist/assets/index-lfQlW-DC.css +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easel-canvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Easel: an HTML design canvas for AI agents. Shows screens/*.html as boards and edits the source directly, with Claude Code / Codex via MCP",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Hyun Park",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"start": "node bin/server.mjs",
|
|
22
22
|
"demo": "node bin/server.mjs --dir examples/demo --open",
|
|
23
|
-
"build": "vite build app --config vite.config.mjs",
|
|
23
|
+
"build": "vite build app --config vite.config.mjs && vite build app --config vite.config.mjs --mode viewer",
|
|
24
24
|
"prepack": "npm run build",
|
|
25
25
|
"mcp": "node bin/mcp.mjs",
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
// AI-generated with Claude Code, 2026-11-12, reviewed by Hyun Park
|
|
2
|
+
// Who changed what: the elements a change touched (pure, on the two HTML texts with parse5; board scripts never run), a short name for
|
|
3
|
+
// every history step, board tags (one per author per board, only someone else's changes), and the routes behind the tags and History.
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import { isTrackedRel } from "./copies.mjs";
|
|
7
|
+
import { toPosix } from "./fsutil.mjs";
|
|
8
|
+
import { fileList } from "./history.mjs";
|
|
9
|
+
import { elementChildren, findBody, parseHtml, textOf } from "./html.mjs";
|
|
10
|
+
import { readBody, safeJoin, sendJson } from "./index.mjs";
|
|
11
|
+
import { dropMissingAutoPlaced, mergeSteps, undoChanges, withBase } from "./runs.mjs";
|
|
12
|
+
|
|
13
|
+
/** More changed elements than this: no outline, only the tag */
|
|
14
|
+
export const MAX_OUTLINE = 5;
|
|
15
|
+
/** The diff stops collecting past this many items (a rewritten screen) */
|
|
16
|
+
const CAP = 60;
|
|
17
|
+
/** Elements that are never drawn: a change to them is not outlined */
|
|
18
|
+
const HIDDEN = new Set(["script", "style", "template", "meta", "link", "noscript", "title", "base"]);
|
|
19
|
+
|
|
20
|
+
const norm = (s) => String(s ?? "").replace(/\s+/g, " ").trim();
|
|
21
|
+
const clip = (s, n = 80) => (s.length > n ? s.slice(0, n - 1) + "…" : s);
|
|
22
|
+
const srcOf = (html, n) => {
|
|
23
|
+
const l = n?.sourceCodeLocation;
|
|
24
|
+
return l ? html.slice(l.startOffset, l.endOffset) : null;
|
|
25
|
+
};
|
|
26
|
+
const ownText = (n) => norm((n.childNodes ?? []).filter((c) => c.nodeName === "#text").map((c) => c.value).join(" "));
|
|
27
|
+
const attrsOf = (n) => new Map((n.attrs ?? []).map((a) => [a.name, a.value]));
|
|
28
|
+
const clsOf = (n) => n.attrs?.find((a) => a.name === "class")?.value.trim().split(/\s+/)[0] || undefined;
|
|
29
|
+
/** <head> as text (an implied <head> has no source range of its own, its children do) */
|
|
30
|
+
const headText = (doc, html) => {
|
|
31
|
+
const head = doc.childNodes.find((n) => n.tagName === "html")?.childNodes.find((n) => n.tagName === "head");
|
|
32
|
+
return (head?.childNodes ?? []).map((n) => srcOf(html, n) ?? n.value ?? "").join("");
|
|
33
|
+
};
|
|
34
|
+
const parseJson = (t) => {
|
|
35
|
+
try {
|
|
36
|
+
return t ? JSON.parse(t) : {};
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Elements that differ between two versions of a screen, by the path /api/outline, /api/element and comments use (element indexes
|
|
44
|
+
* from the children of <body>, in the after version). Children are matched by equal source at both ends; the rest pairs up in order
|
|
45
|
+
* and the surplus is added (paths in after) or removed (the parent's path). items: { path, kind: text|style|attr|added|removed|replaced,
|
|
46
|
+
* tag, cls?, from?, to? }; head: the <head> changed (styles, title). full: more than CAP items, the list is cut
|
|
47
|
+
*/
|
|
48
|
+
export function changedElements(before, after) {
|
|
49
|
+
const a = parseHtml(before);
|
|
50
|
+
const b = parseHtml(after);
|
|
51
|
+
const items = [];
|
|
52
|
+
const same = (x, y) => {
|
|
53
|
+
const sx = srcOf(before, x);
|
|
54
|
+
return sx != null && sx === srcOf(after, y);
|
|
55
|
+
};
|
|
56
|
+
const walk = (x, y, p) => {
|
|
57
|
+
if (items.length >= CAP || same(x, y)) return;
|
|
58
|
+
const at = (i) => (p ? `${p}/${i}` : String(i));
|
|
59
|
+
if (x.tagName !== y.tagName) return void items.push({ path: p, kind: "replaced", tag: y.tagName, cls: clsOf(y) });
|
|
60
|
+
const ax = attrsOf(x);
|
|
61
|
+
const ay = attrsOf(y);
|
|
62
|
+
const names = [...new Set([...ax.keys(), ...ay.keys()])].filter((k) => ax.get(k) !== ay.get(k));
|
|
63
|
+
if (names.length) items.push({ path: p, kind: names.every((k) => k === "style") ? "style" : "attr", tag: y.tagName, cls: clsOf(y) });
|
|
64
|
+
if (HIDDEN.has(y.tagName)) {
|
|
65
|
+
// A <style> or <script> inside body: its text is code, not copy
|
|
66
|
+
if (!names.length && (srcOf(before, x) ?? "") !== (srcOf(after, y) ?? "")) items.push({ path: p, kind: y.tagName === "style" ? "style" : "attr", tag: y.tagName });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (ownText(x) !== ownText(y)) items.push({ path: p, kind: "text", tag: y.tagName, cls: clsOf(y), from: clip(norm(textOf(x))), to: clip(norm(textOf(y))) });
|
|
70
|
+
const cx = elementChildren(x);
|
|
71
|
+
const cy = elementChildren(y);
|
|
72
|
+
let s = 0;
|
|
73
|
+
while (s < cx.length && s < cy.length && same(cx[s], cy[s])) s++;
|
|
74
|
+
let e = 0;
|
|
75
|
+
while (e < cx.length - s && e < cy.length - s && same(cx[cx.length - 1 - e], cy[cy.length - 1 - e])) e++;
|
|
76
|
+
const mx = cx.slice(s, cx.length - e);
|
|
77
|
+
const my = cy.slice(s, cy.length - e);
|
|
78
|
+
const k = Math.min(mx.length, my.length);
|
|
79
|
+
for (let i = 0; i < k; i++) walk(mx[i], my[i], at(s + i));
|
|
80
|
+
for (let i = k; i < my.length && items.length < CAP; i++) items.push({ path: at(s + i), kind: "added", tag: my[i].tagName, cls: clsOf(my[i]) });
|
|
81
|
+
if (mx.length > k) items.push({ path: p, kind: "removed", tag: mx[k].tagName, cls: clsOf(mx[k]), count: mx.length - k });
|
|
82
|
+
};
|
|
83
|
+
const bx = findBody(a);
|
|
84
|
+
const by = findBody(b);
|
|
85
|
+
if (bx && by) walk(bx, by, "");
|
|
86
|
+
return { items, head: headText(a, before) !== headText(b, after), full: items.length >= CAP };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* One change to one screen in a few fields for the tag popover: kind (text, style, attr, added, removed, replaced, many, page: only
|
|
91
|
+
* <head>, source: only whitespace or comments, new: the board was created, deleted), count of changed elements, the element (tag, cls),
|
|
92
|
+
* from/to for a text change, and paths to outline — none when it cannot be pinned to at most MAX_OUTLINE elements
|
|
93
|
+
*/
|
|
94
|
+
export function describeChange(before, after) {
|
|
95
|
+
if (before == null) return { kind: "new", count: 1, paths: [] };
|
|
96
|
+
if (after == null) return { kind: "deleted", count: 1, paths: [] };
|
|
97
|
+
const { items, head, full } = changedElements(before, after);
|
|
98
|
+
if (!items.length) return { kind: head ? "page" : "source", count: 0, paths: [] };
|
|
99
|
+
const els = [...new Set(items.map((i) => i.path))];
|
|
100
|
+
const shown = els.filter((p) => p !== "" && !items.some((i) => i.path === p && HIDDEN.has(i.tag)));
|
|
101
|
+
const paths = !full && shown.length <= MAX_OUTLINE ? shown : [];
|
|
102
|
+
if (full || els.length > 1) return { kind: "many", count: els.length, ...(full ? { more: true } : {}), paths };
|
|
103
|
+
const first = items[0];
|
|
104
|
+
if (items.length === 1 && first.kind === "text") return { kind: "text", count: 1, tag: first.tag, cls: first.cls, from: first.from, to: first.to, paths };
|
|
105
|
+
// One element, several kinds of change (its text and its style): "edited"
|
|
106
|
+
const kind = items.every((i) => i.kind === "style") ? "style" : items.length === 1 ? first.kind : "edited";
|
|
107
|
+
return { kind, count: first.count ?? 1, tag: first.tag, cls: first.cls, paths };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** board.json boards entries that a change added, removed, moved, resized, renamed or otherwise changed (board files) */
|
|
111
|
+
export function boardEntries(beforeText, afterText) {
|
|
112
|
+
const a = parseJson(beforeText)?.boards ?? {};
|
|
113
|
+
const b = parseJson(afterText)?.boards ?? {};
|
|
114
|
+
const out = { added: [], removed: [], moved: [], resized: [], renamed: [], changed: [] };
|
|
115
|
+
for (const f of new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
116
|
+
const x = a[f];
|
|
117
|
+
const y = b[f];
|
|
118
|
+
if (!x && y) out.added.push(f);
|
|
119
|
+
else if (x && !y) out.removed.push(f);
|
|
120
|
+
else if (JSON.stringify(x) !== JSON.stringify(y)) {
|
|
121
|
+
if (x.w !== y.w || x.h !== y.h) out.resized.push(f);
|
|
122
|
+
else if (x.x !== y.x || x.y !== y.y) out.moved.push(f);
|
|
123
|
+
else if (x.title !== y.title) out.renamed.push(f);
|
|
124
|
+
else out.changed.push(f);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* ---------- Step names ---------- */
|
|
131
|
+
const EDIT_OPS = { setText: "Change text on", setStyle: "Change style on", setAttr: "Change attribute on", delete: "Delete element on", duplicate: "Duplicate element on", move: "Move element on", insert: "Add element on", setTweaks: "Change tweaks on", batch: "Edit", wrap: "Group elements on" };
|
|
132
|
+
/** App labels for board.json steps that are about some boards: named after them */
|
|
133
|
+
const BOARD_LABELS = new Set(["Move board", "Resize board", "Board options", "Bring to front", "Send to back", "Move to page", "Set launch screen"]);
|
|
134
|
+
/** What the text of an element is called in a step name */
|
|
135
|
+
const copyNoun = (tag) => (tag === "button" ? "button copy" : tag === "a" ? "link text" : /^h[1-6]$/.test(tag) ? "heading" : tag === "label" ? "label" : "text");
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A short human name for a history step: "Change button copy on Welcome", "Move board Inbox", "Add board Pricing", "Add note".
|
|
139
|
+
* Steps the app labels by file and operation, board operations and changes made outside the app (or by a run) are named after the
|
|
140
|
+
* boards; the text wording only when the diff really is one text node. env: { screensDir, boardPath, titles: { file: title } }
|
|
141
|
+
*/
|
|
142
|
+
export function stepName(step, env, describe = describeChange) {
|
|
143
|
+
const label = step.label ?? "";
|
|
144
|
+
// A board this step removed (a version "Use this" sent to trash) is named as board.json had it before the step
|
|
145
|
+
const was = () => parseJson(step.changes.find((c) => c.path === env.boardPath)?.before)?.boards ?? {};
|
|
146
|
+
const title = (f) => env.titles?.[f] || was()[f]?.title || f.replace(/\.html$/, "");
|
|
147
|
+
const rel = (p) => toPosix(path.relative(env.screensDir, p));
|
|
148
|
+
const html = step.changes.filter((c) => c.path.endsWith(".html") && !rel(c.path).startsWith(".."));
|
|
149
|
+
const textOf1 = (c) => {
|
|
150
|
+
const d = c && c.before != null && c.after != null ? describe(c.before, c.after) : null;
|
|
151
|
+
return d?.kind === "text" ? d : null;
|
|
152
|
+
};
|
|
153
|
+
const boardsIn = () => {
|
|
154
|
+
const bj = step.changes.find((c) => c.path === env.boardPath);
|
|
155
|
+
const d = bj ? boardEntries(bj.before, bj.after) : null;
|
|
156
|
+
return d ? [...new Set([...d.moved, ...d.resized, ...d.renamed, ...d.changed])] : [];
|
|
157
|
+
};
|
|
158
|
+
const several = (verb, n) => `${verb} ${n} boards`;
|
|
159
|
+
let m = /^(.+\.html) (\w+)$/.exec(label);
|
|
160
|
+
if (m && EDIT_OPS[m[2]]) {
|
|
161
|
+
const t = html.length === 1 ? textOf1(html[0]) : null;
|
|
162
|
+
return t ? `Change ${copyNoun(t.tag)} on ${title(m[1])}` : `${EDIT_OPS[m[2]]} ${title(m[1])}`;
|
|
163
|
+
}
|
|
164
|
+
if ((m = /^Create board (.+)$/.exec(label))) return `Add board ${title(m[1])}`;
|
|
165
|
+
// One writer per board, and picking a version (server/forks.mjs)
|
|
166
|
+
if ((m = /^Fork (.+\.html) for (.+)$/.exec(label))) return `Fork ${title(m[1])} for ${m[2]}`;
|
|
167
|
+
if ((m = /^Use (.+\.html) for (.+\.html)$/.exec(label))) return `Use ${title(m[1]).replace(/:.*$/, "")} for ${title(m[2])}`;
|
|
168
|
+
if ((m = /^Keep (.+\.html), trash (.+)$/.exec(label))) return `Keep ${title(m[1])}, trash ${fileList(m[2].split(", ").map(title))}`;
|
|
169
|
+
if ((m = /^Keep all (variants|versions) of (.+\.html)$/.exec(label))) return `Keep all ${m[1]} of ${title(m[2])}`;
|
|
170
|
+
if ((m = /^Write board (.+\.html)$/.exec(label))) {
|
|
171
|
+
if (html.length === 1 && html[0].before == null) return `Add board ${title(m[1])}`;
|
|
172
|
+
const t = html.length === 1 ? textOf1(html[0]) : null;
|
|
173
|
+
return t ? `Change ${copyNoun(t.tag)} on ${title(m[1])}` : `Change ${title(m[1])}`;
|
|
174
|
+
}
|
|
175
|
+
if ((m = /^Duplicate board (.+)$/.exec(label))) return `Duplicate board ${title(m[1])}`;
|
|
176
|
+
if ((m = /^Delete board (.+)$/.exec(label))) {
|
|
177
|
+
const files = m[1].split(", ");
|
|
178
|
+
return files.length === 1 ? `Delete board ${title(files[0])}` : several("Delete", files.length);
|
|
179
|
+
}
|
|
180
|
+
if ((m = /^Rename (?!file )(.+\.html)$/.exec(label))) return `Rename board ${title(m[1])}`;
|
|
181
|
+
if (BOARD_LABELS.has(label)) {
|
|
182
|
+
const files = boardsIn();
|
|
183
|
+
if (files.length === 1) return `${label} ${title(files[0])}`;
|
|
184
|
+
if (files.length > 1) return /^(Move|Resize) board$/.test(label) ? several(label.split(" ")[0], files.length) : `${label} · ${files.length} boards`;
|
|
185
|
+
return label;
|
|
186
|
+
}
|
|
187
|
+
if (!step.outside) return label;
|
|
188
|
+
// Changes found on disk (an agent's own file tools, an editor, an in-app run): named after the boards
|
|
189
|
+
const added = html.filter((c) => c.before == null);
|
|
190
|
+
const removed = html.filter((c) => c.after == null);
|
|
191
|
+
const changed = html.filter((c) => c.before != null && c.after != null);
|
|
192
|
+
const fileOf = (c) => rel(c.path);
|
|
193
|
+
if (!html.length) {
|
|
194
|
+
const files = boardsIn();
|
|
195
|
+
return files.length === 1 ? `Change board ${title(files[0])}` : files.length ? several("Change", files.length) : "Change board.json";
|
|
196
|
+
}
|
|
197
|
+
if (added.length === html.length) return added.length === 1 ? `Add board ${title(fileOf(added[0]))}` : several("Add", added.length);
|
|
198
|
+
if (removed.length === html.length) return removed.length === 1 ? `Delete board ${title(fileOf(removed[0]))}` : several("Delete", removed.length);
|
|
199
|
+
if (changed.length === 1 && html.length === 1) {
|
|
200
|
+
const t = textOf1(changed[0]);
|
|
201
|
+
return t ? `Change ${copyNoun(t.tag)} on ${title(fileOf(changed[0]))}` : `Change ${title(fileOf(changed[0]))}`;
|
|
202
|
+
}
|
|
203
|
+
return `Change ${fileList(html.map((c) => title(fileOf(c))))}`;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Boards a step touched, for its tags: screens it changed, added or removed (with the change described) and boards it moved or resized */
|
|
207
|
+
export function stepBoards(step, env, describe = describeChange) {
|
|
208
|
+
const out = new Map();
|
|
209
|
+
for (const c of step.changes) {
|
|
210
|
+
if (c.path === env.boardPath) continue;
|
|
211
|
+
const rel = toPosix(path.relative(env.screensDir, c.path));
|
|
212
|
+
if (!c.path.endsWith(".html") || rel.startsWith("..")) continue;
|
|
213
|
+
out.set(rel, { file: rel, kind: c.before == null ? "added" : c.after == null ? "removed" : "changed", change: describe(c.before, c.after), path: c.path, after: c.after });
|
|
214
|
+
}
|
|
215
|
+
const bj = step.changes.find((c) => c.path === env.boardPath);
|
|
216
|
+
if (bj) {
|
|
217
|
+
const d = boardEntries(bj.before, bj.after);
|
|
218
|
+
for (const kind of ["moved", "resized", "renamed", "changed"])
|
|
219
|
+
for (const f of d[kind]) if (!out.has(f)) out.set(f, { file: f, kind: "board", change: { kind: kind === "changed" ? "options" : kind, count: 1, paths: [] } });
|
|
220
|
+
}
|
|
221
|
+
return [...out.values()];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Board tags from the applied steps (oldest first): per board, one tag per author, newest first. Leaves out steps made in the browser
|
|
226
|
+
* asking (client) and steps an applied undo took back (undid, or undoOf for a chat run). Each tag: who (by, person, outside), its step ids (newest first),
|
|
227
|
+
* count, at (newest), newBoard (its oldest step created the board), the newest change and its paths when that change is still on disk (fresh)
|
|
228
|
+
*/
|
|
229
|
+
export function boardTags(steps, client) {
|
|
230
|
+
// Taken back: steps a tag Undo undid, and chat runs undone by Undo this run (until a later Redo of that run)
|
|
231
|
+
const taken = new Set();
|
|
232
|
+
for (const s of steps) {
|
|
233
|
+
for (const id of s.undid ?? []) taken.add(id);
|
|
234
|
+
if (s.undoOf) taken.add(`run:${s.undoOf}`);
|
|
235
|
+
if (s.redoOf) taken.delete(`run:${s.redoOf}`);
|
|
236
|
+
}
|
|
237
|
+
const tags = {};
|
|
238
|
+
for (const s of steps) {
|
|
239
|
+
if (taken.has(s.id) || (s.run && taken.has(`run:${s.run}`)) || (client && s.client === client)) continue;
|
|
240
|
+
const key = s.by ? `a:${s.by}` : s.person ? `p:${s.person}` : s.outside ? "outside" : "app";
|
|
241
|
+
for (const b of s.boards) {
|
|
242
|
+
const list = (tags[b.file] ??= []);
|
|
243
|
+
let t = list.find((x) => x.key === key);
|
|
244
|
+
if (!t) {
|
|
245
|
+
t = { key, ...(s.by ? { by: s.by } : s.person ? { person: s.person } : {}), outside: key === "outside", steps: [], count: 0, at: 0, newBoard: b.kind === "added", change: null, paths: [], runs: new Set() };
|
|
246
|
+
list.push(t);
|
|
247
|
+
}
|
|
248
|
+
t.steps.unshift(s.id);
|
|
249
|
+
t.count++;
|
|
250
|
+
t.at = Math.max(t.at, s.lastAt ?? s.at);
|
|
251
|
+
t.change = b.change;
|
|
252
|
+
t.paths = b.fresh ? (b.change?.paths ?? []) : [];
|
|
253
|
+
t.runs.add(s.run ?? null);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
for (const f of Object.keys(tags)) {
|
|
257
|
+
// A board that is gone again has nothing to hang a tag on
|
|
258
|
+
if (tags[f].every((t) => t.change?.kind === "deleted")) delete tags[f];
|
|
259
|
+
else tags[f] = tags[f].sort((a, b) => b.at - a.at).map(({ runs, ...t }) => ({ ...t, run: runs.size === 1 ? [...runs][0] : null }));
|
|
260
|
+
}
|
|
261
|
+
return tags;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* ---------- What the app reads ---------- */
|
|
265
|
+
const cache = new WeakMap(); // step → { rev, boards }
|
|
266
|
+
|
|
267
|
+
/** Per step: its name, author and boards (cached while the step is unchanged), as the tags and the History menu need them */
|
|
268
|
+
function stepInfo(ctx, step, env) {
|
|
269
|
+
let c = cache.get(step);
|
|
270
|
+
if (!c || c.rev !== (step.rev ?? 0)) cache.set(step, (c = { rev: step.rev ?? 0, boards: stepBoards(step, env) }));
|
|
271
|
+
const describe = (before, after) => c.boards.find((b) => b.after === after)?.change ?? describeChange(before, after);
|
|
272
|
+
return {
|
|
273
|
+
id: step.id,
|
|
274
|
+
name: stepName(step, env, describe),
|
|
275
|
+
label: step.label,
|
|
276
|
+
...(step.by ? { by: step.by } : step.person ? { person: step.person } : {}),
|
|
277
|
+
...(step.client ? { client: step.client } : {}),
|
|
278
|
+
outside: !!step.outside,
|
|
279
|
+
...(step.run ? { run: step.run } : {}),
|
|
280
|
+
...(step.undid ? { undid: step.undid } : {}),
|
|
281
|
+
...(step.undoOf ? { undoOf: step.undoOf } : {}),
|
|
282
|
+
...(step.redoOf ? { redoOf: step.redoOf } : {}),
|
|
283
|
+
at: step.lastAt ?? step.at,
|
|
284
|
+
boards: c.boards.map(({ path: p, after, ...b }) => ({ ...b, fresh: !!p && ctx.history.current(p) === after })),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** What step names need: where the screens and board.json are, and the board titles now */
|
|
289
|
+
async function envOf(ctx) {
|
|
290
|
+
const board = await ctx.store.readBoard();
|
|
291
|
+
return { screensDir: ctx.store.screensDir, boardPath: ctx.store.boardPath, titles: Object.fromEntries(Object.entries(board.boards).map(([f, b]) => [f, b.title])) };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Steps for the History menu (newest first, with Now) and board tags for the browser asking (client) */
|
|
295
|
+
export async function activity(ctx, client) {
|
|
296
|
+
const env = await envOf(ctx);
|
|
297
|
+
const { undo, redo } = ctx.history.entries();
|
|
298
|
+
const applied = undo.map((s) => stepInfo(ctx, s, env));
|
|
299
|
+
const undone = redo.map((s) => stepInfo(ctx, s, env));
|
|
300
|
+
const row = ({ boards, client: c, ...s }) => ({ ...s, mine: !!client && c === client });
|
|
301
|
+
return {
|
|
302
|
+
boot: ctx.boot,
|
|
303
|
+
// History menu, newest first: undone steps (the next redo last), then the applied ones; "now" is the newest applied step
|
|
304
|
+
steps: [...undone.map((s) => ({ ...row(s), undone: true })), ...[...applied].reverse().map((s, i) => ({ ...row(s), ...(i === 0 ? { now: true } : {}) }))],
|
|
305
|
+
tags: boardTags(applied, client),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function activityRoutes() {
|
|
310
|
+
return [
|
|
311
|
+
["GET", "/api/activity", async (req, res, url, ctx) => sendJson(res, 200, await activity(ctx, url.searchParams.get("client") ?? ""))],
|
|
312
|
+
// History › Go back to here: a walk along the undo stack, so Redo brings everything back
|
|
313
|
+
[
|
|
314
|
+
"POST",
|
|
315
|
+
"/api/history/goto",
|
|
316
|
+
async (req, res, url, ctx) => {
|
|
317
|
+
const { id } = await readBody(req);
|
|
318
|
+
try {
|
|
319
|
+
const moved = await ctx.history.goTo(String(id ?? ""));
|
|
320
|
+
await dropMissingAutoPlaced(ctx);
|
|
321
|
+
await ctx.store.syncBoardNow();
|
|
322
|
+
sendJson(res, 200, { ok: true, moved });
|
|
323
|
+
} finally {
|
|
324
|
+
ctx.broadcast({ type: "board-changed", source: "server:goto" });
|
|
325
|
+
ctx.broadcast({ type: "history-changed" });
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
// Undo from a board tag: the tag's steps, a plain undo when they are the newest, else only their files (409 with the boards changed
|
|
330
|
+
// since unless mode is "rest" or "all") — the rule of Undo this run, through the same helper
|
|
331
|
+
[
|
|
332
|
+
"POST",
|
|
333
|
+
"/api/history/undo-steps",
|
|
334
|
+
async (req, res, url, ctx) => {
|
|
335
|
+
const b = await readBody(req);
|
|
336
|
+
const ids = [...new Set((Array.isArray(b.ids) ? b.ids : []).map(String))].slice(0, 100);
|
|
337
|
+
await ctx.history.observe();
|
|
338
|
+
const { undo } = ctx.history.entries();
|
|
339
|
+
const steps = undo.filter((s) => ids.includes(s.id));
|
|
340
|
+
if (!steps.length || steps.length !== ids.length) return sendJson(res, 409, { error: "These changes are no longer in the undo history" });
|
|
341
|
+
const top = undo.slice(-steps.length);
|
|
342
|
+
const onTop = top.every((s) => steps.includes(s)) ? steps.length : 0;
|
|
343
|
+
const label = steps.length === 1 ? `Undo ${stepName(steps[0], await envOf(ctx))}` : `Undo ${steps.length} changes`;
|
|
344
|
+
const r = await undoChanges(ctx, { onTop, changes: mergeSteps(steps), mode: b.mode, label, mark: { undid: steps.map((s) => s.id) } });
|
|
345
|
+
if (r.conflicts) return sendJson(res, 409, { conflicts: r.conflicts, error: "Some boards changed since" });
|
|
346
|
+
await ctx.store.syncBoardNow();
|
|
347
|
+
ctx.broadcast({ type: "board-changed", source: "server:undo-steps" });
|
|
348
|
+
ctx.broadcast({ type: "history-changed" });
|
|
349
|
+
sendJson(res, 200, { ok: true, changed: r.changed });
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
// Read-only: a screen as it was before a history step (Compare's "before" for a tag), from the history in memory
|
|
353
|
+
[
|
|
354
|
+
"GET",
|
|
355
|
+
"/api/history/step-file",
|
|
356
|
+
async (req, res, url, ctx) => {
|
|
357
|
+
const f = url.searchParams.get("f") ?? "";
|
|
358
|
+
const id = url.searchParams.get("id") ?? "";
|
|
359
|
+
const p = isTrackedRel(`screens/${f}`) ? safeJoin(ctx.store.screensDir, f) : null;
|
|
360
|
+
const { undo, redo } = ctx.history.entries();
|
|
361
|
+
const step = p && [...undo, ...redo].find((s) => s.id === id);
|
|
362
|
+
const c = step?.changes.find((x) => x.path === p);
|
|
363
|
+
if (!c || c.before == null) return sendJson(res, 404, { error: "No earlier version of that screen in this step" });
|
|
364
|
+
const out = withBase(c.before, f);
|
|
365
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Content-Length": Buffer.byteLength(out), "Cache-Control": "no-store" });
|
|
366
|
+
res.end(out);
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
];
|
|
370
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// AI-generated with Claude Code, 2026-11-10, reviewed by Hyun Park
|
|
2
|
+
// Who is calling: MCP client names → display labels used as comment authors and undo-step authors (X-Easel-Agent).
|
|
3
|
+
|
|
4
|
+
/** MCP client name (claude-code, codex-mcp-client, cursor-vscode, gemini-cli-mcp-client, …) → label; unknown names pass through, none is "AI" */
|
|
5
|
+
export function agentLabel(clientName) {
|
|
6
|
+
const n = String(clientName ?? "").trim();
|
|
7
|
+
const l = n.toLowerCase();
|
|
8
|
+
if (l.includes("claude")) return "Claude Code";
|
|
9
|
+
if (l.includes("codex")) return "Codex";
|
|
10
|
+
if (l.includes("cursor")) return "Cursor";
|
|
11
|
+
if (l.includes("gemini")) return "Gemini CLI";
|
|
12
|
+
return cleanAgent(n) || "AI";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Header value safe to store and show: printable, single line, at most 60 chars */
|
|
16
|
+
export const cleanAgent = (v) =>
|
|
17
|
+
String(v ?? "")
|
|
18
|
+
.replace(/[\u0000-\u001f\u007f]+/g, " ")
|
|
19
|
+
.trim()
|
|
20
|
+
.slice(0, 60);
|
package/server/args.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// AI-generated with Claude Code, 2026-10-09, reviewed by Hyun Park
|
|
2
|
-
// Command-line args: [--dir <design folder>] [--port 4317] [--open] [--demo] [--init] [--help] [--version]
|
|
2
|
+
// Command-line args: [connect] [--dir <design folder>] [--port 4317] [--open] [--demo] [--init] [--help] [--version],
|
|
3
|
+
// plus --agents a,b and --dry-run for connect, --out, --page, --boards a,b, --single-file, --pdf, --png for export,
|
|
4
|
+
// and --permission for easel-mcp (only the permission tool of an in-app chat run).
|
|
3
5
|
// Default design folder: <repo>/docs/design when Easel lives in <repo>/tools/<name> (submodule); otherwise
|
|
4
6
|
// ./docs/design or the current folder if it has screens/ (npx).
|
|
5
7
|
import { existsSync } from "node:fs";
|
|
@@ -23,7 +25,7 @@ export const DEFAULT_DIR = defaultDir();
|
|
|
23
25
|
const expand = (p) => path.resolve(p.replace(/^~(?=\/)/, process.env.HOME ?? "~"));
|
|
24
26
|
|
|
25
27
|
export function parseArgs(argv = process.argv.slice(2)) {
|
|
26
|
-
const out = { dir: null, port: DEFAULT_PORT, open: false, noOpen: false, demo: false, init: false, help: false, version: false, prod: false };
|
|
28
|
+
const out = { command: null, dir: null, port: DEFAULT_PORT, portGiven: false, dirGiven: false, agents: null, dryRun: false, out: null, page: null, boards: null, singleFile: false, pdf: false, png: false, permission: false, open: false, noOpen: false, demo: false, init: false, help: false, version: false, prod: false };
|
|
27
29
|
for (let i = 0; i < argv.length; i++) {
|
|
28
30
|
const a = argv[i];
|
|
29
31
|
const next = () => argv[++i];
|
|
@@ -31,14 +33,32 @@ export function parseArgs(argv = process.argv.slice(2)) {
|
|
|
31
33
|
else if (a.startsWith("--dir=")) out.dir = expand(a.slice(6));
|
|
32
34
|
else if (a === "--port") out.port = Number(next());
|
|
33
35
|
else if (a.startsWith("--port=")) out.port = Number(a.slice(7));
|
|
36
|
+
else if (a === "--agents") out.agents = next();
|
|
37
|
+
else if (a.startsWith("--agents=")) out.agents = a.slice(9);
|
|
38
|
+
else if (a === "--dry-run") out.dryRun = true;
|
|
39
|
+
else if (a === "--out") out.out = argv[i + 1] ? expand(next()) : null;
|
|
40
|
+
else if (a.startsWith("--out=")) out.out = expand(a.slice(6));
|
|
41
|
+
else if (a === "--page") out.page = next();
|
|
42
|
+
else if (a.startsWith("--page=")) out.page = a.slice(7);
|
|
43
|
+
else if (a === "--boards") out.boards = next();
|
|
44
|
+
else if (a.startsWith("--boards=")) out.boards = a.slice(9);
|
|
45
|
+
else if (a === "--single-file") out.singleFile = true;
|
|
46
|
+
else if (a === "--pdf") out.pdf = true;
|
|
47
|
+
else if (a === "--png") out.png = true;
|
|
48
|
+
else if (i === 0 && (a === "connect" || a === "export")) out.command = a;
|
|
34
49
|
else if (a === "--open") out.open = true;
|
|
35
50
|
else if (a === "--no-open") out.noOpen = true;
|
|
36
51
|
else if (a === "--demo") out.demo = true;
|
|
37
52
|
else if (a === "--init") out.init = true;
|
|
38
53
|
else if (a === "--prod") out.prod = true;
|
|
54
|
+
else if (a === "--permission") out.permission = true;
|
|
39
55
|
else if (a === "-h" || a === "--help") out.help = true;
|
|
40
56
|
else if (a === "-v" || a === "--version") out.version = true;
|
|
41
57
|
}
|
|
58
|
+
out.portGiven = argv.some((a) => a === "--port" || a.startsWith("--port="));
|
|
59
|
+
out.dirGiven = out.dir != null;
|
|
60
|
+
out.agents = out.agents ? out.agents.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean) : null;
|
|
61
|
+
out.boards = out.boards ? out.boards.split(",").map((s) => s.trim()).filter(Boolean) : null;
|
|
42
62
|
out.dir ??= DEFAULT_DIR;
|
|
43
63
|
return out;
|
|
44
64
|
}
|
package/server/board.mjs
CHANGED
|
@@ -5,10 +5,9 @@ import path from "node:path";
|
|
|
5
5
|
|
|
6
6
|
import { formatBoard } from "./boardFormat.mjs";
|
|
7
7
|
import { htmlTitle, projectName, writeAtomic } from "./fsutil.mjs";
|
|
8
|
+
import { placeNew } from "./place.mjs";
|
|
8
9
|
|
|
9
10
|
const DEFAULT_SIZE = { w: 390, h: 844 };
|
|
10
|
-
const GAP_X = 80;
|
|
11
|
-
const GAP_Y = 120;
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* order lists each board exactly once: duplicates and names missing from boards are dropped, boards missing from order
|
|
@@ -22,7 +21,8 @@ export function normalizeOrder(order, boards) {
|
|
|
22
21
|
return out;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
/** onWrite(path, text) runs after every board.json save (the undo history keeps it as known content) */
|
|
25
|
+
export function createBoardStore(dir, { onWrite } = {}) {
|
|
26
26
|
const boardPath = path.join(dir, "board.json");
|
|
27
27
|
const screensDir = path.join(dir, "screens");
|
|
28
28
|
|
|
@@ -57,6 +57,7 @@ export function createBoardStore(dir) {
|
|
|
57
57
|
lastWritten = text;
|
|
58
58
|
writing = writing.then(() => writeAtomic(boardPath, text));
|
|
59
59
|
await writing;
|
|
60
|
+
onWrite?.(boardPath, text);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/** .html files under screens/ (including subfolders, ignoring .icloud placeholders) */
|
|
@@ -89,19 +90,6 @@ export function createBoardStore(dir) {
|
|
|
89
90
|
}
|
|
90
91
|
const readBoardSize = async (file) => (await readBoardInfo(file)).size;
|
|
91
92
|
|
|
92
|
-
/** Row for new screens: right of the last auto-placed board, otherwise below everything + 120 */
|
|
93
|
-
function placeNew(board, size) {
|
|
94
|
-
const all = Object.values(board.boards);
|
|
95
|
-
const auto = all.filter((b) => b.autoPlaced);
|
|
96
|
-
if (auto.length) {
|
|
97
|
-
const last = auto.reduce((a, b) => (b.x > a.x ? b : a));
|
|
98
|
-
return { x: last.x + last.w + GAP_X, y: last.y, ...size };
|
|
99
|
-
}
|
|
100
|
-
const bottom = all.reduce((m, b) => Math.max(m, b.y + b.h), 0);
|
|
101
|
-
const left = all.reduce((m, b) => Math.min(m, b.x), 0);
|
|
102
|
-
return { x: left, y: bottom + GAP_Y, ...size };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
93
|
// Queue board/file-changing requests and auto-placement in a single line. If auto-placement slipped in while an undo
|
|
106
94
|
// is writing board.json and deleting files, the deleted board would come back.
|
|
107
95
|
let chain = Promise.resolve();
|
package/server/boards.mjs
CHANGED
|
@@ -6,12 +6,14 @@ import path from "node:path";
|
|
|
6
6
|
import { formatBoard } from "./boardFormat.mjs";
|
|
7
7
|
import { writeAtomic } from "./fsutil.mjs";
|
|
8
8
|
import { readBody, safeJoin, sendJson } from "./index.mjs";
|
|
9
|
+
import { freeSpot, GAP_X, placeNew } from "./place.mjs";
|
|
10
|
+
import { SYSTEM_FONT } from "./tokens.mjs";
|
|
9
11
|
|
|
10
12
|
const read = (p) => fs.readFile(p, "utf8").catch(() => null);
|
|
11
13
|
const FILE_RE = /^[a-z0-9][a-z0-9._-]*\.html$/i;
|
|
12
14
|
|
|
13
|
-
// System font stack only: no web font download, nothing language- or brand-specific
|
|
14
|
-
const BASE_CSS = `body{margin:0;color-scheme:light;font-family
|
|
15
|
+
// System font stack only (the same as the default tokens): no web font download, nothing language- or brand-specific
|
|
16
|
+
const BASE_CSS = `body{margin:0;color-scheme:light;font-family:${SYSTEM_FONT.replace(/, /g, ",")};color:#111111;background:#FFFFFF;-webkit-font-smoothing:antialiased;font-variant-numeric:tabular-nums}`;
|
|
15
17
|
|
|
16
18
|
/** New board templates. The size is written both in the board-size meta and on the outermost div */
|
|
17
19
|
export const TEMPLATES = {
|
|
@@ -74,7 +76,7 @@ ${bodies[template] ?? bodies.blank}
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
/** A file name that does not collide */
|
|
77
|
-
async function uniqueName(screensDir, base) {
|
|
79
|
+
export async function uniqueName(screensDir, base) {
|
|
78
80
|
const stem = base.replace(/\.html$/i, "");
|
|
79
81
|
for (let i = 0; i < 1000; i++) {
|
|
80
82
|
const name = `${stem}${i ? `-${i + 1}` : ""}.html`;
|
|
@@ -109,7 +111,7 @@ function repage(board, pages, map = (pid) => pid) {
|
|
|
109
111
|
if (board.launch?.page && !pages.some((p) => p.id === board.launch.page)) delete board.launch.page;
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
/** Creates several boards as one history step. items: [{file, html, x, y, w, h, title, page}] → list of actual file names */
|
|
114
|
+
/** Creates several boards as one history step. items: [{file, html, x, y, w, h, title, page, origin}] → list of actual file names */
|
|
113
115
|
export async function createBoards(ctx, items, label) {
|
|
114
116
|
const changes = [];
|
|
115
117
|
const made = [];
|
|
@@ -125,7 +127,7 @@ export async function createBoards(ctx, items, label) {
|
|
|
125
127
|
label,
|
|
126
128
|
(board) => {
|
|
127
129
|
for (const it of made) {
|
|
128
|
-
board.boards[it.file] = { x: Math.round(it.x ?? 0), y: Math.round(it.y ?? 0), w: it.w, h: it.h, title: it.title, ...(it.page ? { page: it.page } : {}) };
|
|
130
|
+
board.boards[it.file] = { x: Math.round(it.x ?? 0), y: Math.round(it.y ?? 0), w: it.w, h: it.h, title: it.title, ...(it.page ? { page: it.page } : {}), ...(it.origin ? { origin: it.origin } : {}) };
|
|
129
131
|
board.order = [...board.order.filter((f) => f !== it.file), it.file];
|
|
130
132
|
}
|
|
131
133
|
},
|
|
@@ -147,6 +149,31 @@ export async function commitBoard(ctx, label, mutate, fileChanges = []) {
|
|
|
147
149
|
return after;
|
|
148
150
|
}
|
|
149
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Moves board files to the trash (<design dir>/.trash/<time>/, gitignored) and deletes them; Undo brings them back from the history.
|
|
154
|
+
* Returns the history changes for the files that were there
|
|
155
|
+
*/
|
|
156
|
+
export async function trashFiles(ctx, files) {
|
|
157
|
+
const trash = path.join(ctx.dir, ".trash", new Date().toISOString().replace(/[:.]/g, "-"));
|
|
158
|
+
await fs.mkdir(trash, { recursive: true });
|
|
159
|
+
await fs.writeFile(path.join(ctx.dir, ".trash", ".gitignore"), "*\n").catch(() => {});
|
|
160
|
+
const changes = [];
|
|
161
|
+
for (const f of files) {
|
|
162
|
+
const p = safeJoin(ctx.store.screensDir, f);
|
|
163
|
+
const html = p && (await read(p));
|
|
164
|
+
if (html == null) continue;
|
|
165
|
+
await fs.writeFile(path.join(trash, path.basename(f)), html);
|
|
166
|
+
await fs.rm(p);
|
|
167
|
+
changes.push({ path: p, before: html, after: null });
|
|
168
|
+
}
|
|
169
|
+
return { changes, trash };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Boards that came from a deleted board (its variants and forks) become ordinary boards: the link would point at nothing */
|
|
173
|
+
export function unlinkOrigins(board, gone) {
|
|
174
|
+
for (const b of Object.values(board.boards)) if (b.origin && gone.includes(b.origin.of)) delete b.origin;
|
|
175
|
+
}
|
|
176
|
+
|
|
150
177
|
export function boardRoutes() {
|
|
151
178
|
return [
|
|
152
179
|
[
|
|
@@ -178,8 +205,11 @@ export function boardRoutes() {
|
|
|
178
205
|
const h = Math.max(40, Math.min(8000, Math.round(b.h ?? TEMPLATES[tpl].h)));
|
|
179
206
|
const wanted = b.file && FILE_RE.test(b.file) ? b.file : `${tpl === "blank" ? "board" : tpl}.html`;
|
|
180
207
|
const title = b.title || (tpl === "blank" ? wanted.replace(/\.html$/, "") : TEMPLATES[tpl].label);
|
|
181
|
-
const
|
|
182
|
-
const
|
|
208
|
+
const board0 = await ctx.store.readBoard();
|
|
209
|
+
const html = b.html ?? newBoardHtml({ title, w, h, template: tpl, brand: board0.title });
|
|
210
|
+
// No position given (an agent's create_board): the first free spot, never on top of a board or a note
|
|
211
|
+
const at = Number.isFinite(b.x) && Number.isFinite(b.y) ? { x: b.x, y: b.y } : placeNew(board0, { w, h }, b.page);
|
|
212
|
+
const [file] = await createBoards(ctx, [{ file: wanted, html, x: at.x, y: at.y, w, h, title, page: b.page }], `Create board ${wanted}`);
|
|
183
213
|
sendJson(res, 200, { file });
|
|
184
214
|
},
|
|
185
215
|
],
|
|
@@ -192,27 +222,18 @@ export function boardRoutes() {
|
|
|
192
222
|
const files = (b.files ?? []).filter((f) => FILE_RE.test(path.basename(f)));
|
|
193
223
|
if (!files.length) return sendJson(res, 400, { error: "files is required" });
|
|
194
224
|
// Also copy to the trash (docs/design/.trash/). Undo restores from the history
|
|
195
|
-
const
|
|
196
|
-
await fs.mkdir(trash, { recursive: true });
|
|
197
|
-
await fs.writeFile(path.join(ctx.dir, ".trash", ".gitignore"), "*\n").catch(() => {});
|
|
198
|
-
const changes = [];
|
|
199
|
-
for (const f of files) {
|
|
200
|
-
const p = safeJoin(ctx.store.screensDir, f);
|
|
201
|
-
const html = p && (await read(p));
|
|
202
|
-
if (html == null) continue;
|
|
203
|
-
await fs.writeFile(path.join(trash, path.basename(f)), html);
|
|
204
|
-
await fs.rm(p);
|
|
205
|
-
changes.push({ path: p, before: html, after: null });
|
|
206
|
-
}
|
|
225
|
+
const { changes, trash } = await trashFiles(ctx, files);
|
|
207
226
|
await commitBoard(
|
|
208
227
|
ctx,
|
|
209
228
|
`Delete board ${files.join(", ")}`,
|
|
210
229
|
(board) => {
|
|
211
230
|
for (const f of files) delete board.boards[f];
|
|
212
231
|
board.order = board.order.filter((f) => !files.includes(f));
|
|
232
|
+
unlinkOrigins(board, files);
|
|
213
233
|
},
|
|
214
234
|
changes,
|
|
215
235
|
);
|
|
236
|
+
for (const f of files) ctx.occupancy?.forget(f);
|
|
216
237
|
sendJson(res, 200, { ok: true, trash: path.relative(ctx.dir, trash) });
|
|
217
238
|
},
|
|
218
239
|
],
|
|
@@ -228,12 +249,14 @@ export function boardRoutes() {
|
|
|
228
249
|
const p = path.join(ctx.store.screensDir, file);
|
|
229
250
|
await writeAtomic(p, html);
|
|
230
251
|
const board0 = await ctx.store.readBoard();
|
|
231
|
-
|
|
252
|
+
// The copy is an ordinary board: it is not a variant or fork of anything
|
|
253
|
+
const { origin, autoPlaced, ...it } = board0.boards[b.file] ?? { x: 0, y: 0, w: 390, h: 844 };
|
|
254
|
+
const at = freeSpot(board0, { x: it.x + it.w + GAP_X, y: it.y, w: it.w, h: it.h }, { page: it.page });
|
|
232
255
|
await commitBoard(
|
|
233
256
|
ctx,
|
|
234
257
|
`Duplicate board ${b.file}`,
|
|
235
258
|
(board) => {
|
|
236
|
-
board.boards[file] = { ...it, x:
|
|
259
|
+
board.boards[file] = { ...it, x: at.x, y: at.y, title: `${it.title ?? b.file.replace(/\.html$/, "")} copy` };
|
|
237
260
|
const i = board.order.indexOf(b.file);
|
|
238
261
|
board.order.splice(i < 0 ? board.order.length : i + 1, 0, file);
|
|
239
262
|
},
|
|
@@ -293,6 +316,8 @@ export function boardRoutes() {
|
|
|
293
316
|
board.boards[b.newFile] = { ...board.boards[b.file], ...(b.title ? { title: b.title } : {}) };
|
|
294
317
|
delete board.boards[b.file];
|
|
295
318
|
board.order = board.order.map((f) => (f === b.file ? b.newFile : f));
|
|
319
|
+
// Its variants and forks follow the new name
|
|
320
|
+
for (const o of Object.values(board.boards)) if (o.origin?.of === b.file) o.origin = { ...o.origin, of: b.newFile };
|
|
296
321
|
},
|
|
297
322
|
changes,
|
|
298
323
|
);
|