frameboard 0.12.0 → 0.14.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 +6 -3
- package/dist/cli.js +987 -208
- package/dist/client/assets/index-D6XyJYZH.css +2 -0
- package/dist/client/assets/index-RAnQsb-L.js +110 -0
- package/dist/client/index.html +2 -2
- package/dist/hook.js +3 -2
- package/package.json +1 -1
- package/dist/client/assets/index-C-i2pm1f.js +0 -110
- package/dist/client/assets/index-eTwqW6cj.css +0 -2
package/dist/cli.js
CHANGED
|
@@ -3037,12 +3037,15 @@ const EXIT_CODES = {
|
|
|
3037
3037
|
"stale-layout": 11,
|
|
3038
3038
|
"asset-type-refused": 2,
|
|
3039
3039
|
"asset-too-large": 2,
|
|
3040
|
+
"image-type-refused": 2,
|
|
3040
3041
|
"undo-overtaken": 12,
|
|
3041
3042
|
"nothing-to-undo": 12,
|
|
3042
3043
|
"frame-claimed": 4,
|
|
3043
3044
|
"claims-invalid": 5,
|
|
3044
3045
|
"client-not-built": 3,
|
|
3045
|
-
"tokens-exist": 4
|
|
3046
|
+
"tokens-exist": 4,
|
|
3047
|
+
"dispatch-unavailable": 3,
|
|
3048
|
+
"dispatch-failed": 13
|
|
3046
3049
|
};
|
|
3047
3050
|
var FrameboardError = class extends Error {
|
|
3048
3051
|
code;
|
|
@@ -9330,7 +9333,7 @@ async function isDirectory(path) {
|
|
|
9330
9333
|
}
|
|
9331
9334
|
}
|
|
9332
9335
|
// package.json
|
|
9333
|
-
var version$1 = "0.
|
|
9336
|
+
var version$1 = "0.14.0";
|
|
9334
9337
|
var dependencies = { "playwright-core": "1.64.1" };
|
|
9335
9338
|
// src/shared/version.ts
|
|
9336
9339
|
const version = version$1;
|
|
@@ -26771,6 +26774,16 @@ function serializeDocumentTypeNode(node, { treeAdapter }) {
|
|
|
26771
26774
|
function parse$3(html, options) {
|
|
26772
26775
|
return Parser.parse(html, options);
|
|
26773
26776
|
}
|
|
26777
|
+
function parseFragment(fragmentContext, html, options) {
|
|
26778
|
+
if (typeof fragmentContext === "string") {
|
|
26779
|
+
options = html;
|
|
26780
|
+
html = fragmentContext;
|
|
26781
|
+
fragmentContext = null;
|
|
26782
|
+
}
|
|
26783
|
+
const parser = Parser.getFragmentParser(fragmentContext, options);
|
|
26784
|
+
parser.tokenizer.write(html, true);
|
|
26785
|
+
return parser.getFragment();
|
|
26786
|
+
}
|
|
26774
26787
|
// node_modules/domelementtype/dist/index.js
|
|
26775
26788
|
/** Types of elements found in htmlparser2's DOM */
|
|
26776
26789
|
var ElementType;
|
|
@@ -28935,14 +28948,80 @@ function applyEdit(source, address, change) {
|
|
|
28935
28948
|
span
|
|
28936
28949
|
};
|
|
28937
28950
|
}
|
|
28951
|
+
// src/shared/starter-tokens.ts
|
|
28952
|
+
/**
|
|
28953
|
+
* The looks a new project can start from, each accent paired by hand with a
|
|
28954
|
+
* dark value, so both themes hold without a derived color. The keys are the
|
|
28955
|
+
* values `project tokens --accent` and the route take.
|
|
28956
|
+
*/
|
|
28957
|
+
const STARTER_ACCENTS = {
|
|
28958
|
+
blue: {
|
|
28959
|
+
light: "#2f7bf0",
|
|
28960
|
+
dark: "#4e92f6"
|
|
28961
|
+
},
|
|
28962
|
+
red: {
|
|
28963
|
+
light: "#e5484d",
|
|
28964
|
+
dark: "#ff6369"
|
|
28965
|
+
},
|
|
28966
|
+
green: {
|
|
28967
|
+
light: "#30a46c",
|
|
28968
|
+
dark: "#3dd68c"
|
|
28969
|
+
},
|
|
28970
|
+
orange: {
|
|
28971
|
+
light: "#f76b15",
|
|
28972
|
+
dark: "#ff801f"
|
|
28973
|
+
},
|
|
28974
|
+
purple: {
|
|
28975
|
+
light: "#8e4ec6",
|
|
28976
|
+
dark: "#9a5cd0"
|
|
28977
|
+
}
|
|
28978
|
+
};
|
|
28979
|
+
/** The served faces a starter sheet may name, keyed by their face folder. */
|
|
28980
|
+
const STARTER_FONTS = {
|
|
28981
|
+
geist: {
|
|
28982
|
+
family: "Geist",
|
|
28983
|
+
stack: "Geist, sans-serif"
|
|
28984
|
+
},
|
|
28985
|
+
"geist-mono": {
|
|
28986
|
+
family: "Geist Mono",
|
|
28987
|
+
stack: "'Geist Mono', monospace"
|
|
28988
|
+
}
|
|
28989
|
+
};
|
|
28990
|
+
const DEFAULT_LOOK = {
|
|
28991
|
+
accent: "blue",
|
|
28992
|
+
font: "geist"
|
|
28993
|
+
};
|
|
28994
|
+
/** A project token sheet setting the names the fixture sheets use, light then dark. */
|
|
28995
|
+
function starterSheet({ accent, font }) {
|
|
28996
|
+
const pair = STARTER_ACCENTS[accent];
|
|
28997
|
+
return `:root {
|
|
28998
|
+
--accent: ${pair.light};
|
|
28999
|
+
--surface: #ffffff;
|
|
29000
|
+
--text: #111111;
|
|
29001
|
+
--muted: #6b7280;
|
|
29002
|
+
--border: #e5e7eb;
|
|
29003
|
+
--radius: 10px;
|
|
29004
|
+
--font-text: ${STARTER_FONTS[font].stack};
|
|
29005
|
+
}
|
|
29006
|
+
|
|
29007
|
+
[data-theme='dark'] {
|
|
29008
|
+
--accent: ${pair.dark};
|
|
29009
|
+
--surface: #111111;
|
|
29010
|
+
--text: #ededed;
|
|
29011
|
+
--muted: #9ca3af;
|
|
29012
|
+
--border: #2e2e2e;
|
|
29013
|
+
}
|
|
29014
|
+
`;
|
|
29015
|
+
}
|
|
28938
29016
|
// src/server/edit/insert.ts
|
|
28939
|
-
const SHAPE_SIZE =
|
|
29017
|
+
const SHAPE_SIZE = 100;
|
|
28940
29018
|
const FILL_TOKENS = [
|
|
28941
29019
|
"--muted",
|
|
28942
29020
|
"--secondary",
|
|
28943
29021
|
"--accent"
|
|
28944
29022
|
];
|
|
28945
29023
|
const LINE_TOKEN = "--border";
|
|
29024
|
+
const TEXT_FONT_TOKEN = "--font-text";
|
|
28946
29025
|
/** Raw on purpose, so the check names it once the project sets no color token. */
|
|
28947
29026
|
const RAW_GREY = "#d9d9d9";
|
|
28948
29027
|
const PAINT_VALUE = /^(?:var\(--[\w-]+\)|#[0-9a-f]{6})$/i;
|
|
@@ -28986,15 +29065,25 @@ function shapePaint(tokens) {
|
|
|
28986
29065
|
line: paint(names.has(LINE_TOKEN) ? LINE_TOKEN : firstColor)
|
|
28987
29066
|
};
|
|
28988
29067
|
}
|
|
28989
|
-
/**
|
|
28990
|
-
|
|
29068
|
+
/**
|
|
29069
|
+
* The family placed text sets, being the project's text font token, else
|
|
29070
|
+
* Geist, so a frame with no font of its own still passes `default-font`.
|
|
29071
|
+
*/
|
|
29072
|
+
function textFont(tokens) {
|
|
29073
|
+
return tokens.some((row) => row.name === TEXT_FONT_TOKEN) ? `var(${TEXT_FONT_TOKEN})` : STARTER_FONTS.geist.stack;
|
|
29074
|
+
}
|
|
29075
|
+
/** Every byte an insert of `element` writes, with its `data-name` and size. */
|
|
29076
|
+
function elementMarkup(element, paint, font) {
|
|
28991
29077
|
const { fill, line } = paint;
|
|
28992
29078
|
if (!PAINT_VALUE.test(fill) || !PAINT_VALUE.test(line)) throw new Error(`Unexpected shape paint ${fill} ${line}`);
|
|
28993
|
-
const box =
|
|
29079
|
+
const box = ({ width = SHAPE_SIZE, height = SHAPE_SIZE }) => {
|
|
29080
|
+
if (!Number.isInteger(width) || !Number.isInteger(height)) throw new Error(`Unexpected shape size ${width} ${height}`);
|
|
29081
|
+
return `width: ${width}px; height: ${height}px; background: ${fill}`;
|
|
29082
|
+
};
|
|
28994
29083
|
switch (element.kind) {
|
|
28995
|
-
case "text": return
|
|
28996
|
-
case "rectangle": return `<div data-name="Rectangle" style="${box}"></div>`;
|
|
28997
|
-
case "ellipse": return `<div data-name="Ellipse" style="${box}; border-radius: 50%"></div>`;
|
|
29084
|
+
case "text": return `<p data-name="Text" style="font-family: ${font}">Text</p>`;
|
|
29085
|
+
case "rectangle": return `<div data-name="Rectangle" style="${box(element)}"></div>`;
|
|
29086
|
+
case "ellipse": return `<div data-name="Ellipse" style="${box(element)}; border-radius: 50%"></div>`;
|
|
28998
29087
|
case "divider": return `<hr data-name="Divider" style="align-self: stretch; margin: 0; border: 0; ${element.vertical ? "border-left" : "border-top"}: 1px solid ${line}">`;
|
|
28999
29088
|
}
|
|
29000
29089
|
}
|
|
@@ -29038,18 +29127,24 @@ function gapOffset(tree, placement) {
|
|
|
29038
29127
|
* the input's with that one element added under the parent, so a tag the
|
|
29039
29128
|
* parser would move, as a `<div>` closing a `<p>`, is refused rather than
|
|
29040
29129
|
* written somewhere else.
|
|
29130
|
+
*
|
|
29131
|
+
* A `lead` lands the element that many bytes ahead of the gap, once they
|
|
29132
|
+
* read as given, so an element put back lands where it stood and not past
|
|
29133
|
+
* the whitespace that followed it.
|
|
29041
29134
|
*/
|
|
29042
|
-
function insertElement(source, placement, markup) {
|
|
29135
|
+
function insertElement(source, placement, markup, lead = "") {
|
|
29043
29136
|
const before = parseFrame(source);
|
|
29044
29137
|
const gap = gapOffset(before, placement);
|
|
29045
29138
|
if ("ok" in gap) return gap;
|
|
29046
|
-
const { parent
|
|
29139
|
+
const { parent } = gap;
|
|
29140
|
+
const offset = gap.offset - lead.length;
|
|
29141
|
+
if (offset < 0 || source.slice(offset, gap.offset) !== lead) return refuse$1("address-mismatch", `the bytes ahead of the gap in the <${parent.tagName}> at ${placement.parent} changed`);
|
|
29047
29142
|
const written = source.slice(0, offset) + markup + source.slice(offset);
|
|
29048
29143
|
const after = parseFrame(written);
|
|
29049
29144
|
const index = after.elements.findIndex((element) => element.sourceCodeLocation?.startOffset === offset);
|
|
29050
29145
|
const added = after.elements[index];
|
|
29051
|
-
if (!added || after.elements.length !== before.elements.length + 1 || added.parentNode !== after.elements[placement.parent] || spanText(written, added, "element") !== markup || !addsOnly(before, after, added)) return refuse$1("verify-failed", `a <${added?.tagName ?? "new element"}> there would change more than the <${parent.tagName}> it goes in, so nothing was written`);
|
|
29052
|
-
const next = children(parent).find((child) => child.sourceCodeLocation?.startOffset === offset);
|
|
29146
|
+
if (!added || after.elements.length !== before.elements.length + 1 + descendants(added) || added.parentNode !== after.elements[placement.parent] || spanText(written, added, "element") !== markup || !addsOnly(before, after, added)) return refuse$1("verify-failed", `a <${added?.tagName ?? "new element"}> there would change more than the <${parent.tagName}> it goes in, so nothing was written`);
|
|
29147
|
+
const next = children(parent).find((child) => child.sourceCodeLocation?.startOffset === gap.offset);
|
|
29053
29148
|
return {
|
|
29054
29149
|
ok: true,
|
|
29055
29150
|
html: written,
|
|
@@ -29063,10 +29158,15 @@ function insertElement(source, placement, markup) {
|
|
|
29063
29158
|
tagName: parent.tagName,
|
|
29064
29159
|
tag: startTag(source, parent)
|
|
29065
29160
|
},
|
|
29066
|
-
next: next ? startTag(source, next) : null
|
|
29161
|
+
next: next ? startTag(source, next) : null,
|
|
29162
|
+
lead
|
|
29067
29163
|
}
|
|
29068
29164
|
};
|
|
29069
29165
|
}
|
|
29166
|
+
/** How many elements `element` holds, at any depth. */
|
|
29167
|
+
function descendants(element) {
|
|
29168
|
+
return children(element).reduce((count, child) => count + 1 + descendants(child), 0);
|
|
29169
|
+
}
|
|
29070
29170
|
/** Whether `after` is `before` with `added` alone added, compared once it is taken out. */
|
|
29071
29171
|
function addsOnly(before, after, added) {
|
|
29072
29172
|
const parent = added.parentNode;
|
|
@@ -29087,7 +29187,8 @@ function locateInserted(source, tree, span) {
|
|
|
29087
29187
|
/** The gap the span goes back into, read off its anchors where the frame now stands. */
|
|
29088
29188
|
function locateGap(source, tree, span) {
|
|
29089
29189
|
const reads = (element) => element !== void 0 && element.tagName === span.parent.tagName && startTag(source, element) === span.parent.tag;
|
|
29090
|
-
const
|
|
29190
|
+
const held = tree.elements.length === span.count - markupSize(span.markup);
|
|
29191
|
+
const candidates = held && reads(tree.elements[span.placement.parent]) ? [span.placement.parent] : tree.elements.flatMap((element, index) => reads(element) ? [index] : []);
|
|
29091
29192
|
const parentIndex = candidates.length === 1 ? candidates[0] : void 0;
|
|
29092
29193
|
const parent = parentIndex === void 0 ? void 0 : tree.elements[parentIndex];
|
|
29093
29194
|
if (parentIndex === void 0 || !parent) return void 0;
|
|
@@ -29095,6 +29196,11 @@ function locateGap(source, tree, span) {
|
|
|
29095
29196
|
parent: parentIndex,
|
|
29096
29197
|
before: null
|
|
29097
29198
|
};
|
|
29199
|
+
const recorded = span.placement.before === null ? void 0 : tree.elements[span.placement.before];
|
|
29200
|
+
if (held && recorded && recorded.parentNode === parent && startTag(source, recorded) === span.next) return {
|
|
29201
|
+
parent: parentIndex,
|
|
29202
|
+
before: span.placement.before
|
|
29203
|
+
};
|
|
29098
29204
|
const next = children(parent).filter((child) => startTag(source, child) === span.next);
|
|
29099
29205
|
const [sibling] = next;
|
|
29100
29206
|
return next.length === 1 && sibling ? {
|
|
@@ -29102,6 +29208,11 @@ function locateGap(source, tree, span) {
|
|
|
29102
29208
|
before: tree.elements.indexOf(sibling)
|
|
29103
29209
|
} : void 0;
|
|
29104
29210
|
}
|
|
29211
|
+
/** How many elements `markup` holds, itself and everything inside it. */
|
|
29212
|
+
function markupSize(markup) {
|
|
29213
|
+
const count = (node) => node.childNodes.reduce((total, child) => total + (hasTag(child) ? 1 + count(child) : 0), 0);
|
|
29214
|
+
return count(parseFragment(markup));
|
|
29215
|
+
}
|
|
29105
29216
|
/** Whether the frame stands as `side` of the insert left it, with the element or with its gap. */
|
|
29106
29217
|
function holdsInserted(source, span, side) {
|
|
29107
29218
|
const tree = parseFrame(source);
|
|
@@ -29115,16 +29226,29 @@ function holdsInserted(source, span, side) {
|
|
|
29115
29226
|
function removeInserted(source, span) {
|
|
29116
29227
|
const tree = parseFrame(source);
|
|
29117
29228
|
const index = locateInserted(source, tree, span);
|
|
29118
|
-
|
|
29229
|
+
return index === void 0 ? void 0 : takeOut$1(source, tree, index);
|
|
29230
|
+
}
|
|
29231
|
+
/**
|
|
29232
|
+
* Takes the element at `index` out with its descendants and answers the span
|
|
29233
|
+
* that puts it back, holding the bytes that stood between it and its gap.
|
|
29234
|
+
* Answers undefined when the element is not stated, or when putting it back
|
|
29235
|
+
* would not give `source` again, since the removal then reached past it.
|
|
29236
|
+
*/
|
|
29237
|
+
function takeOut$1(source, tree, index) {
|
|
29238
|
+
const element = tree.elements[index];
|
|
29119
29239
|
const at = element?.sourceCodeLocation;
|
|
29120
29240
|
const parent = element?.parentNode;
|
|
29121
|
-
if (
|
|
29241
|
+
if (!element || !at?.startTag || !parent || !hasTag(parent)) return void 0;
|
|
29122
29242
|
const removed = source.slice(0, at.startOffset) + source.slice(at.endOffset);
|
|
29123
29243
|
const next = children(parent)[children(parent).indexOf(element) + 1];
|
|
29124
|
-
const
|
|
29244
|
+
const placement = {
|
|
29125
29245
|
parent: tree.elements.indexOf(parent),
|
|
29126
29246
|
before: next ? index : null
|
|
29127
|
-
}
|
|
29247
|
+
};
|
|
29248
|
+
const gap = gapOffset(parseFrame(removed), placement);
|
|
29249
|
+
if ("ok" in gap || gap.offset < at.startOffset) return void 0;
|
|
29250
|
+
const lead = removed.slice(at.startOffset, gap.offset);
|
|
29251
|
+
const back = insertElement(removed, placement, source.slice(at.startOffset, at.endOffset), lead);
|
|
29128
29252
|
if (!back.ok || back.html !== source) return void 0;
|
|
29129
29253
|
return {
|
|
29130
29254
|
html: removed,
|
|
@@ -29132,6 +29256,44 @@ function removeInserted(source, span) {
|
|
|
29132
29256
|
};
|
|
29133
29257
|
}
|
|
29134
29258
|
/**
|
|
29259
|
+
* Takes out the element at `index`, with everything it holds, and answers
|
|
29260
|
+
* the span `restoreInserted` puts it back by, so a delete is an insert run
|
|
29261
|
+
* backwards. Only an element under `body` is taken, and the removal is
|
|
29262
|
+
* refused as `verify-failed` unless the result parses as the source with
|
|
29263
|
+
* that element alone gone, and its bytes go back as that one element.
|
|
29264
|
+
* Putting it back lands it
|
|
29265
|
+
* before the same sibling, so the whitespace around it may sit on its other
|
|
29266
|
+
* side.
|
|
29267
|
+
*/
|
|
29268
|
+
function removeElement$1(source, index) {
|
|
29269
|
+
const tree = parseFrame(source);
|
|
29270
|
+
if (tree.unstated) return refuse$1("address-mismatch", `the browser builds a <${tree.unstated.tagName}> the file does not state, so indices after it disagree`);
|
|
29271
|
+
const element = tree.elements[index];
|
|
29272
|
+
if (!element || !underBody(element)) return refuse$1("invalid-address", `${index} names no element under the frame's body`);
|
|
29273
|
+
const at = element.sourceCodeLocation;
|
|
29274
|
+
const parent = element.parentNode;
|
|
29275
|
+
if (!at || !parent || !hasTag(parent)) return refuse$1("address-mismatch", `the <${element.tagName}> at ${index} is not stated in the file`);
|
|
29276
|
+
const removed = source.slice(0, at.startOffset) + source.slice(at.endOffset);
|
|
29277
|
+
const next = children(parent)[children(parent).indexOf(element) + 1];
|
|
29278
|
+
const back = insertElement(removed, {
|
|
29279
|
+
parent: tree.elements.indexOf(parent),
|
|
29280
|
+
before: next ? index : null
|
|
29281
|
+
}, source.slice(at.startOffset, at.endOffset));
|
|
29282
|
+
parent.childNodes = parent.childNodes.filter((node) => node !== element);
|
|
29283
|
+
const removesOnly = serialize(tree.document) === serialize(parseFrame(removed).document);
|
|
29284
|
+
if (!back.ok || !removesOnly) return refuse$1("verify-failed", `taking out the <${element.tagName}> at ${index} would change more than it, so nothing was written`);
|
|
29285
|
+
if (!holdsInserted(removed, back.span, "before")) return refuse$1("verify-failed", `the <${element.tagName}> at ${index} could not be put back once taken out, so nothing was written`);
|
|
29286
|
+
return {
|
|
29287
|
+
ok: true,
|
|
29288
|
+
html: removed,
|
|
29289
|
+
span: back.span
|
|
29290
|
+
};
|
|
29291
|
+
}
|
|
29292
|
+
function underBody(element) {
|
|
29293
|
+
for (let node = element.parentNode; node && hasTag(node); node = node.parentNode) if (node.tagName === "body") return true;
|
|
29294
|
+
return false;
|
|
29295
|
+
}
|
|
29296
|
+
/**
|
|
29135
29297
|
* Writes the element back into its gap, found by the parent's and the next
|
|
29136
29298
|
* sibling's start tags, and answers the span as it now stands. Answers
|
|
29137
29299
|
* undefined when the gap is not found or the write is refused.
|
|
@@ -29139,12 +29301,68 @@ function removeInserted(source, span) {
|
|
|
29139
29301
|
function restoreInserted(source, span) {
|
|
29140
29302
|
const placement = locateGap(source, parseFrame(source), span);
|
|
29141
29303
|
if (!placement) return void 0;
|
|
29142
|
-
const inserted = insertElement(source, placement, span.markup);
|
|
29304
|
+
const inserted = insertElement(source, placement, span.markup, span.lead);
|
|
29143
29305
|
return inserted.ok ? {
|
|
29144
29306
|
html: inserted.html,
|
|
29145
29307
|
span: inserted.span
|
|
29146
29308
|
} : void 0;
|
|
29147
29309
|
}
|
|
29310
|
+
/**
|
|
29311
|
+
* Takes the element at `index` out by its bytes and writes them into the gap
|
|
29312
|
+
* `placement` names, both read in the frame as it stands, leaving every other
|
|
29313
|
+
* byte. A gap in the element or under it is refused as `invalid-container`,
|
|
29314
|
+
* since the element would be written inside itself, and the gap it already
|
|
29315
|
+
* sits in as `invalid-address`. Each half is checked as `insertElement`
|
|
29316
|
+
* checks a placement, so a move the parser would rebuild is refused whole.
|
|
29317
|
+
*/
|
|
29318
|
+
function moveElement(source, index, placement) {
|
|
29319
|
+
const tree = parseFrame(source);
|
|
29320
|
+
const element = Number.isInteger(index) ? tree.elements[index] : void 0;
|
|
29321
|
+
if (!element?.sourceCodeLocation?.startTag) return refuse$1("invalid-address", `${index} names no element the file states`);
|
|
29322
|
+
const end = index + 1 + descendants(element);
|
|
29323
|
+
const shift = (at) => at < end ? at : at - (end - index);
|
|
29324
|
+
if (placement.parent >= index && placement.parent < end) return refuse$1("invalid-container", `the <${element.tagName}> at ${index} cannot go inside itself`);
|
|
29325
|
+
const taken = takeOut$1(source, tree, index);
|
|
29326
|
+
if (!taken) return refuse$1("verify-failed", `taking the <${element.tagName}> at ${index} out would change more than it, so nothing was written`);
|
|
29327
|
+
const target = {
|
|
29328
|
+
parent: shift(placement.parent),
|
|
29329
|
+
before: placement.before === null ? null : shift(placement.before)
|
|
29330
|
+
};
|
|
29331
|
+
if (target.parent === taken.span.placement.parent && target.before === taken.span.placement.before) return refuse$1("invalid-address", `the <${element.tagName}> at ${index} already sits in that gap`);
|
|
29332
|
+
const moved = insertElement(taken.html, target, taken.span.markup);
|
|
29333
|
+
if (!moved.ok) return moved;
|
|
29334
|
+
return {
|
|
29335
|
+
ok: true,
|
|
29336
|
+
html: moved.html,
|
|
29337
|
+
index: moved.index,
|
|
29338
|
+
span: {
|
|
29339
|
+
from: taken.span,
|
|
29340
|
+
to: moved.span
|
|
29341
|
+
}
|
|
29342
|
+
};
|
|
29343
|
+
}
|
|
29344
|
+
/**
|
|
29345
|
+
* Writes the moved element back to `side` of the move, taking it out of the
|
|
29346
|
+
* other gap by its bytes and into this one by its anchors, and answers the
|
|
29347
|
+
* span as the frame then stands. Answers undefined when either half is not
|
|
29348
|
+
* found, so a step the frame no longer allows is refused rather than guessed.
|
|
29349
|
+
*/
|
|
29350
|
+
function relocateMoved(source, span, side) {
|
|
29351
|
+
const [leave, land] = side === "before" ? [span.to, span.from] : [span.from, span.to];
|
|
29352
|
+
const removed = removeInserted(source, leave);
|
|
29353
|
+
const written = removed && restoreInserted(removed.html, land);
|
|
29354
|
+
if (!removed || !written) return void 0;
|
|
29355
|
+
return {
|
|
29356
|
+
html: written.html,
|
|
29357
|
+
span: side === "before" ? {
|
|
29358
|
+
from: written.span,
|
|
29359
|
+
to: removed.span
|
|
29360
|
+
} : {
|
|
29361
|
+
from: removed.span,
|
|
29362
|
+
to: written.span
|
|
29363
|
+
}
|
|
29364
|
+
};
|
|
29365
|
+
}
|
|
29148
29366
|
// src/server/edit/frame-file.ts
|
|
29149
29367
|
function stale(path) {
|
|
29150
29368
|
return refuse$1("stale-address", `${basename(path)} changed after this edit was made, so nothing was written`);
|
|
@@ -29214,6 +29432,43 @@ function insertFrameFile(path, hash, placement, markup) {
|
|
|
29214
29432
|
};
|
|
29215
29433
|
}
|
|
29216
29434
|
/**
|
|
29435
|
+
* Takes one element out of a frame file the way `insertFrameFile` writes one
|
|
29436
|
+
* in, refusing a hash the file no longer has as stale, so a retried delete
|
|
29437
|
+
* takes out at most one element.
|
|
29438
|
+
*/
|
|
29439
|
+
function removeFrameFile(path, hash, index) {
|
|
29440
|
+
const read = readSource(path);
|
|
29441
|
+
if (!read.ok) return read;
|
|
29442
|
+
if (read.hash !== hash) return stale(path);
|
|
29443
|
+
const removed = removeElement$1(read.source, index);
|
|
29444
|
+
if (!removed.ok) return removed;
|
|
29445
|
+
if (!replaceFile(path, hash, removed.html)) return stale(path);
|
|
29446
|
+
return {
|
|
29447
|
+
ok: true,
|
|
29448
|
+
hash: contentHash(removed.html),
|
|
29449
|
+
span: removed.span
|
|
29450
|
+
};
|
|
29451
|
+
}
|
|
29452
|
+
/**
|
|
29453
|
+
* Moves one element of a frame file into another gap, written as
|
|
29454
|
+
* `insertFrameFile` writes, and refused as stale on a hash the file no longer
|
|
29455
|
+
* has, since both indices name nothing once the file moved.
|
|
29456
|
+
*/
|
|
29457
|
+
function moveFrameFile(path, hash, index, placement) {
|
|
29458
|
+
const read = readSource(path);
|
|
29459
|
+
if (!read.ok) return read;
|
|
29460
|
+
if (read.hash !== hash) return stale(path);
|
|
29461
|
+
const moved = moveElement(read.source, index, placement);
|
|
29462
|
+
if (!moved.ok) return moved;
|
|
29463
|
+
if (!replaceFile(path, hash, moved.html)) return stale(path);
|
|
29464
|
+
return {
|
|
29465
|
+
ok: true,
|
|
29466
|
+
hash: contentHash(moved.html),
|
|
29467
|
+
index: moved.index,
|
|
29468
|
+
span: moved.span
|
|
29469
|
+
};
|
|
29470
|
+
}
|
|
29471
|
+
/**
|
|
29217
29472
|
* A frame file's text and hash. Bytes that do not survive a UTF-8 round trip
|
|
29218
29473
|
* are refused, since decoding would rewrite every invalid byte.
|
|
29219
29474
|
*/
|
|
@@ -29288,6 +29543,8 @@ async function parseBody$1(request, schema) {
|
|
|
29288
29543
|
// src/server/routes/edit.ts
|
|
29289
29544
|
const value = string$1().max(1e4);
|
|
29290
29545
|
const name$1 = string$1().min(1).max(256);
|
|
29546
|
+
/** A dragged shape's side in CSS pixels. */
|
|
29547
|
+
const side = int$1().min(1).max(1e4);
|
|
29291
29548
|
const editSchema = object$1({
|
|
29292
29549
|
ref: string$1().min(1).max(1024),
|
|
29293
29550
|
index: int$1().min(0),
|
|
@@ -29316,16 +29573,36 @@ const insertSchema = object$1({
|
|
|
29316
29573
|
before: int$1().min(0).nullable(),
|
|
29317
29574
|
element: discriminatedUnion("kind", [
|
|
29318
29575
|
object$1({ kind: literal("text") }),
|
|
29319
|
-
object$1({
|
|
29320
|
-
|
|
29576
|
+
object$1({
|
|
29577
|
+
kind: literal("rectangle"),
|
|
29578
|
+
width: side.optional(),
|
|
29579
|
+
height: side.optional()
|
|
29580
|
+
}),
|
|
29581
|
+
object$1({
|
|
29582
|
+
kind: literal("ellipse"),
|
|
29583
|
+
width: side.optional(),
|
|
29584
|
+
height: side.optional()
|
|
29585
|
+
}),
|
|
29321
29586
|
object$1({
|
|
29322
29587
|
kind: literal("divider"),
|
|
29323
29588
|
vertical: boolean$1()
|
|
29324
29589
|
})
|
|
29325
29590
|
])
|
|
29326
29591
|
});
|
|
29592
|
+
const removeSchema = object$1({
|
|
29593
|
+
ref: string$1().min(1).max(1024),
|
|
29594
|
+
index: int$1().min(0),
|
|
29595
|
+
hash: string$1().regex(/^[0-9a-f]{64}$/)
|
|
29596
|
+
});
|
|
29597
|
+
const moveSchema$1 = object$1({
|
|
29598
|
+
ref: string$1().min(1).max(1024),
|
|
29599
|
+
hash: string$1().regex(/^[0-9a-f]{64}$/),
|
|
29600
|
+
index: int$1().min(0),
|
|
29601
|
+
parent: int$1().min(0),
|
|
29602
|
+
before: int$1().min(0).nullable()
|
|
29603
|
+
});
|
|
29327
29604
|
/**
|
|
29328
|
-
* A hand edit of one element
|
|
29605
|
+
* A hand edit of one element, a placed element, and a deleted one, each behind
|
|
29329
29606
|
* `requireWriter` and refused on a frame another session holds.
|
|
29330
29607
|
*
|
|
29331
29608
|
* The edit's body mirrors
|
|
@@ -29342,6 +29619,18 @@ const insertSchema = object$1({
|
|
|
29342
29619
|
* the new element's index, and the hash written. A hash the file no longer
|
|
29343
29620
|
* has answers 409 `stale-address` with nothing written, since the gap's
|
|
29344
29621
|
* indices name nothing past an agent's write, and a retried insert lands once.
|
|
29622
|
+
* A rectangle or an ellipse takes an optional width and height a drag drew.
|
|
29623
|
+
*
|
|
29624
|
+
* The remove takes out the element at `index`, with what it holds, from the
|
|
29625
|
+
* bytes `hash` names, and records it as one step whose undo puts it back
|
|
29626
|
+
* under its parent. It answers the frame and the hash written, and refuses a
|
|
29627
|
+
* moved file as `stale-address` the way the insert does.
|
|
29628
|
+
*
|
|
29629
|
+
* The move takes one element by index and the gap it goes into, both read
|
|
29630
|
+
* in the frame as the hash names it, and records it as one step an undo
|
|
29631
|
+
* puts back byte for byte. It answers the element's new index and the hash
|
|
29632
|
+
* written, and refuses as the insert does, with `invalid-container` for a
|
|
29633
|
+
* gap inside the element itself.
|
|
29345
29634
|
*/
|
|
29346
29635
|
function editRoutes(root, access, history, version, sheets) {
|
|
29347
29636
|
const app = new Hono();
|
|
@@ -29397,7 +29686,7 @@ function editRoutes(root, access, history, version, sheets) {
|
|
|
29397
29686
|
const result = insertFrameFile(frame.path, body.hash, {
|
|
29398
29687
|
parent: body.parent,
|
|
29399
29688
|
before: body.before
|
|
29400
|
-
}, elementMarkup(body.element, shapePaint(tokens)));
|
|
29689
|
+
}, elementMarkup(body.element, shapePaint(tokens), textFont(tokens)));
|
|
29401
29690
|
if (!result.ok) return c.json({
|
|
29402
29691
|
ok: false,
|
|
29403
29692
|
error: {
|
|
@@ -29427,6 +29716,79 @@ function editRoutes(root, access, history, version, sheets) {
|
|
|
29427
29716
|
data
|
|
29428
29717
|
});
|
|
29429
29718
|
});
|
|
29719
|
+
app.post("/api/frames/remove", requireWriter(access), async (c) => {
|
|
29720
|
+
const body = await parseBody$1(c.req.raw, removeSchema);
|
|
29721
|
+
const frame = await resolveFrameRef(root, body.ref, { cwd: root });
|
|
29722
|
+
const ref = `${frame.project}/${frame.page}/${frame.name}`;
|
|
29723
|
+
await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
|
|
29724
|
+
const result = removeFrameFile(frame.path, body.hash, body.index);
|
|
29725
|
+
if (!result.ok) return c.json({
|
|
29726
|
+
ok: false,
|
|
29727
|
+
error: {
|
|
29728
|
+
code: result.reason,
|
|
29729
|
+
message: result.detail,
|
|
29730
|
+
details: {
|
|
29731
|
+
ref,
|
|
29732
|
+
index: body.index
|
|
29733
|
+
}
|
|
29734
|
+
}
|
|
29735
|
+
}, 409);
|
|
29736
|
+
const journal = history.journal();
|
|
29737
|
+
journal.deletedElement(frame.path, ref, result.span);
|
|
29738
|
+
history.record({
|
|
29739
|
+
id: journal.id,
|
|
29740
|
+
changes: journal.changes,
|
|
29741
|
+
page: null,
|
|
29742
|
+
frames: [ref]
|
|
29743
|
+
});
|
|
29744
|
+
const data = {
|
|
29745
|
+
ref,
|
|
29746
|
+
hash: result.hash
|
|
29747
|
+
};
|
|
29748
|
+
return c.json({
|
|
29749
|
+
ok: true,
|
|
29750
|
+
data
|
|
29751
|
+
});
|
|
29752
|
+
});
|
|
29753
|
+
app.post("/api/frames/move", requireWriter(access), async (c) => {
|
|
29754
|
+
const body = await parseBody$1(c.req.raw, moveSchema$1);
|
|
29755
|
+
const frame = await resolveFrameRef(root, body.ref, { cwd: root });
|
|
29756
|
+
const ref = `${frame.project}/${frame.page}/${frame.name}`;
|
|
29757
|
+
await refuseClaimed(root, [ref], /* @__PURE__ */ new Date());
|
|
29758
|
+
const result = moveFrameFile(frame.path, body.hash, body.index, {
|
|
29759
|
+
parent: body.parent,
|
|
29760
|
+
before: body.before
|
|
29761
|
+
});
|
|
29762
|
+
if (!result.ok) return c.json({
|
|
29763
|
+
ok: false,
|
|
29764
|
+
error: {
|
|
29765
|
+
code: result.reason,
|
|
29766
|
+
message: result.detail,
|
|
29767
|
+
details: {
|
|
29768
|
+
ref,
|
|
29769
|
+
index: body.index,
|
|
29770
|
+
parent: body.parent
|
|
29771
|
+
}
|
|
29772
|
+
}
|
|
29773
|
+
}, 409);
|
|
29774
|
+
const journal = history.journal();
|
|
29775
|
+
journal.relocated(frame.path, ref, result.span);
|
|
29776
|
+
history.record({
|
|
29777
|
+
id: journal.id,
|
|
29778
|
+
changes: journal.changes,
|
|
29779
|
+
page: null,
|
|
29780
|
+
frames: [ref]
|
|
29781
|
+
});
|
|
29782
|
+
const data = {
|
|
29783
|
+
ref,
|
|
29784
|
+
index: result.index,
|
|
29785
|
+
hash: result.hash
|
|
29786
|
+
};
|
|
29787
|
+
return c.json({
|
|
29788
|
+
ok: true,
|
|
29789
|
+
data
|
|
29790
|
+
});
|
|
29791
|
+
});
|
|
29430
29792
|
app.onError(answerRefusal);
|
|
29431
29793
|
return app;
|
|
29432
29794
|
}
|
|
@@ -29473,63 +29835,6 @@ function tokenSheets(root, project, tokens) {
|
|
|
29473
29835
|
offset: 0
|
|
29474
29836
|
}));
|
|
29475
29837
|
}
|
|
29476
|
-
// src/server/edit/elements.ts
|
|
29477
|
-
/** How long a text-only element's text may run as its name. */
|
|
29478
|
-
const NAME_LENGTH = 40;
|
|
29479
|
-
/**
|
|
29480
|
-
* A frame's elements under `body` in index order, each with its parent and
|
|
29481
|
-
* name, read from the same parse and the same index `edit` addresses. A
|
|
29482
|
-
* frame where the browser builds an element the file does not state is
|
|
29483
|
-
* refused, since every index after it would name another element.
|
|
29484
|
-
*/
|
|
29485
|
-
function elementTree(source) {
|
|
29486
|
-
const tree = parseFrame(source);
|
|
29487
|
-
if (tree.unstated) return refuse$1("address-mismatch", `the browser builds a <${tree.unstated.tagName}> the file does not state, so indices after it disagree`);
|
|
29488
|
-
const index = new Map(tree.elements.map((element, at) => [element, at]));
|
|
29489
|
-
const body = tree.elements.find((element) => element.tagName === "body");
|
|
29490
|
-
const listed = [];
|
|
29491
|
-
const inBody = /* @__PURE__ */ new Set();
|
|
29492
|
-
for (const [at, element] of tree.elements.entries()) {
|
|
29493
|
-
const parent = element.parentNode;
|
|
29494
|
-
if (!body || !parent || !hasTag(parent)) continue;
|
|
29495
|
-
if (parent !== body && !inBody.has(parent)) continue;
|
|
29496
|
-
inBody.add(element);
|
|
29497
|
-
listed.push({
|
|
29498
|
-
index: at,
|
|
29499
|
-
parent: parent === body ? null : index.get(parent) ?? null,
|
|
29500
|
-
tag: element.tagName,
|
|
29501
|
-
name: elementName(element),
|
|
29502
|
-
textOnly: ownText$2(element) !== null
|
|
29503
|
-
});
|
|
29504
|
-
}
|
|
29505
|
-
return listed;
|
|
29506
|
-
}
|
|
29507
|
-
/**
|
|
29508
|
-
* What an element is called in the layers rows, the inspector, and the
|
|
29509
|
-
* `selection` verb: its `data-name`, else a text-only element's text, else
|
|
29510
|
-
* an `img`'s `alt`, else its tag. `id` and `aria-label` already mean
|
|
29511
|
-
* something to a frame's CSS, scripts, and readers, so neither names it.
|
|
29512
|
-
*/
|
|
29513
|
-
function elementName(element) {
|
|
29514
|
-
const named = attribute(element, "data-name")?.trim();
|
|
29515
|
-
if (named) return named;
|
|
29516
|
-
const text = ownText$2(element);
|
|
29517
|
-
if (text !== null) return text.slice(0, NAME_LENGTH);
|
|
29518
|
-
return (element.tagName === "img" ? attribute(element, "alt")?.trim() : "") || element.tagName;
|
|
29519
|
-
}
|
|
29520
|
-
/** The whitespace-collapsed text of an element holding text alone, else null. */
|
|
29521
|
-
function ownText$2(element) {
|
|
29522
|
-
const texts = element.childNodes.filter(isText);
|
|
29523
|
-
if (texts.length === 0 || texts.length !== element.childNodes.length) return null;
|
|
29524
|
-
const text = texts.map((node) => node.value).join("").replace(/\s+/g, " ").trim();
|
|
29525
|
-
return text === "" ? null : text;
|
|
29526
|
-
}
|
|
29527
|
-
function isText(node) {
|
|
29528
|
-
return node.nodeName === "#text";
|
|
29529
|
-
}
|
|
29530
|
-
function attribute(element, name) {
|
|
29531
|
-
return element.attrs.find((attr) => attr.name === name)?.value;
|
|
29532
|
-
}
|
|
29533
29838
|
// node_modules/@bramus/specificity/dist/index.js
|
|
29534
29839
|
var Jn = Object.create;
|
|
29535
29840
|
var te = Object.defineProperty;
|
|
@@ -34305,7 +34610,8 @@ const READ = /* @__PURE__ */ new Set([
|
|
|
34305
34610
|
const SHORTHANDS = {
|
|
34306
34611
|
font: ["font-family"],
|
|
34307
34612
|
background: ["background-color"],
|
|
34308
|
-
border: ["border-color", "border-width"]
|
|
34613
|
+
border: ["border-color", "border-width"],
|
|
34614
|
+
"flex-flow": ["flex-direction", "flex-wrap"]
|
|
34309
34615
|
};
|
|
34310
34616
|
/** The properties an element takes from its parent when no rule sets them. */
|
|
34311
34617
|
const INHERITED = /* @__PURE__ */ new Set([
|
|
@@ -34545,7 +34851,7 @@ function inlineDeclarations(element, reads) {
|
|
|
34545
34851
|
0,
|
|
34546
34852
|
0
|
|
34547
34853
|
],
|
|
34548
|
-
order:
|
|
34854
|
+
order: declarations.length
|
|
34549
34855
|
});
|
|
34550
34856
|
});
|
|
34551
34857
|
return declarations;
|
|
@@ -34615,6 +34921,110 @@ function shorthandFamily(value) {
|
|
|
34615
34921
|
const family = tokens.slice(familyAt).join(" ");
|
|
34616
34922
|
return family === "" ? null : family;
|
|
34617
34923
|
}
|
|
34924
|
+
// src/server/edit/elements.ts
|
|
34925
|
+
/** How long a text-only element's text may run as its name. */
|
|
34926
|
+
const NAME_LENGTH = 40;
|
|
34927
|
+
/** What the layout read takes from the cascade, with the shorthand that sets the direction. */
|
|
34928
|
+
const LAYOUT_PROPERTIES = /* @__PURE__ */ new Set([
|
|
34929
|
+
"display",
|
|
34930
|
+
"flex-direction",
|
|
34931
|
+
"flex-flow"
|
|
34932
|
+
]);
|
|
34933
|
+
const ROUND_PROPERTIES = /* @__PURE__ */ new Set(["border-radius"]);
|
|
34934
|
+
/**
|
|
34935
|
+
* A frame's elements under `body` in index order, each with its parent and
|
|
34936
|
+
* name, read from the same parse and the same index `edit` addresses. A
|
|
34937
|
+
* frame where the browser builds an element the file does not state is
|
|
34938
|
+
* refused, since every index after it would name another element.
|
|
34939
|
+
* `layouts` is `elementLayouts`'s read by the same index, and an element it
|
|
34940
|
+
* does not reach reads as `block`. `rounds` is `elementRounds`'s read, which
|
|
34941
|
+
* marks an element round only while it holds nothing.
|
|
34942
|
+
*/
|
|
34943
|
+
function elementTree(source, layouts = [], rounds = []) {
|
|
34944
|
+
const tree = parseFrame(source);
|
|
34945
|
+
if (tree.unstated) return refuse$1("address-mismatch", `the browser builds a <${tree.unstated.tagName}> the file does not state, so indices after it disagree`);
|
|
34946
|
+
const index = new Map(tree.elements.map((element, at) => [element, at]));
|
|
34947
|
+
const body = tree.elements.find((element) => element.tagName === "body");
|
|
34948
|
+
const listed = [];
|
|
34949
|
+
const inBody = /* @__PURE__ */ new Set();
|
|
34950
|
+
for (const [at, element] of tree.elements.entries()) {
|
|
34951
|
+
const parent = element.parentNode;
|
|
34952
|
+
if (!body || !parent || !hasTag(parent)) continue;
|
|
34953
|
+
if (parent !== body && !inBody.has(parent)) continue;
|
|
34954
|
+
inBody.add(element);
|
|
34955
|
+
listed.push({
|
|
34956
|
+
index: at,
|
|
34957
|
+
parent: parent === body ? null : index.get(parent) ?? null,
|
|
34958
|
+
tag: element.tagName,
|
|
34959
|
+
name: elementName(element),
|
|
34960
|
+
textOnly: ownText$2(element) !== null,
|
|
34961
|
+
layout: layouts[at] ?? "block",
|
|
34962
|
+
round: (rounds[at] ?? false) && isEmpty(element)
|
|
34963
|
+
});
|
|
34964
|
+
}
|
|
34965
|
+
return listed;
|
|
34966
|
+
}
|
|
34967
|
+
/**
|
|
34968
|
+
* Every element's layout by the edit index, read from the static cascade
|
|
34969
|
+
* over the token sheets and the frame's own, as `frameStyles` reads colors,
|
|
34970
|
+
* so a culled frame with no iframe still answers. Every media query counts
|
|
34971
|
+
* as applying, so a frame that flips its direction at a breakpoint reads as
|
|
34972
|
+
* whichever rule wins statically.
|
|
34973
|
+
*/
|
|
34974
|
+
function elementLayouts(source, tokens) {
|
|
34975
|
+
const cascade = buildCascade(source, tokens, { properties: LAYOUT_PROPERTIES });
|
|
34976
|
+
return source.elements.map((element) => layoutOf(cascade, element));
|
|
34977
|
+
}
|
|
34978
|
+
/**
|
|
34979
|
+
* Whether each element's corners round by half its size or more, read from
|
|
34980
|
+
* the same static cascade by the edit index, as a placed ellipse sets them.
|
|
34981
|
+
*/
|
|
34982
|
+
function elementRounds(source, tokens) {
|
|
34983
|
+
const cascade = buildCascade(source, tokens, { properties: ROUND_PROPERTIES });
|
|
34984
|
+
return source.elements.map((element) => {
|
|
34985
|
+
const percent = (cascade.specified(element, "border-radius")?.value.trim())?.match(/^(\d+(?:\.\d+)?)%$/)?.[1];
|
|
34986
|
+
return percent !== void 0 && Number(percent) >= 50;
|
|
34987
|
+
});
|
|
34988
|
+
}
|
|
34989
|
+
function layoutOf(cascade, element) {
|
|
34990
|
+
const display = words(cascade.specified(element, "display")?.value);
|
|
34991
|
+
if (display.includes("grid") || display.includes("inline-grid")) return "grid";
|
|
34992
|
+
if (!display.includes("flex") && !display.includes("inline-flex")) return "block";
|
|
34993
|
+
return words(cascade.specified(element, "flex-direction")?.value).some((word) => word.startsWith("column")) ? "column" : "row";
|
|
34994
|
+
}
|
|
34995
|
+
function words(value) {
|
|
34996
|
+
return value?.trim().toLowerCase().split(/\s+/) ?? [];
|
|
34997
|
+
}
|
|
34998
|
+
/**
|
|
34999
|
+
* What an element is called in the layers rows, the inspector, and the
|
|
35000
|
+
* `selection` verb: its `data-name`, else a text-only element's text, else
|
|
35001
|
+
* an `img`'s `alt`, else its tag. `id` and `aria-label` already mean
|
|
35002
|
+
* something to a frame's CSS, scripts, and readers, so neither names it.
|
|
35003
|
+
*/
|
|
35004
|
+
function elementName(element) {
|
|
35005
|
+
const named = attribute(element, "data-name")?.trim();
|
|
35006
|
+
if (named) return named;
|
|
35007
|
+
const text = ownText$2(element);
|
|
35008
|
+
if (text !== null) return text.slice(0, NAME_LENGTH);
|
|
35009
|
+
return (element.tagName === "img" ? attribute(element, "alt")?.trim() : "") || element.tagName;
|
|
35010
|
+
}
|
|
35011
|
+
/** The whitespace-collapsed text of an element holding text alone, else null. */
|
|
35012
|
+
function ownText$2(element) {
|
|
35013
|
+
const texts = element.childNodes.filter(isText);
|
|
35014
|
+
if (texts.length === 0 || texts.length !== element.childNodes.length) return null;
|
|
35015
|
+
const text = texts.map((node) => node.value).join("").replace(/\s+/g, " ").trim();
|
|
35016
|
+
return text === "" ? null : text;
|
|
35017
|
+
}
|
|
35018
|
+
/** True when the element holds no element and no text past whitespace. */
|
|
35019
|
+
function isEmpty(element) {
|
|
35020
|
+
return element.childNodes.every((node) => isText(node) && node.value.trim() === "");
|
|
35021
|
+
}
|
|
35022
|
+
function isText(node) {
|
|
35023
|
+
return node.nodeName === "#text";
|
|
35024
|
+
}
|
|
35025
|
+
function attribute(element, name) {
|
|
35026
|
+
return element.attrs.find((attr) => attr.name === name)?.value;
|
|
35027
|
+
}
|
|
34618
35028
|
// src/server/look/colors.ts
|
|
34619
35029
|
/** What the inspector reads, with the shorthands that set it. */
|
|
34620
35030
|
const PROPERTIES = /* @__PURE__ */ new Set([
|
|
@@ -34815,7 +35225,8 @@ const STATUS$2 = {
|
|
|
34815
35225
|
};
|
|
34816
35226
|
/**
|
|
34817
35227
|
* A frame's element tree, read from the file rather than a live iframe so a
|
|
34818
|
-
* culled frame lists the indices `edit` addresses,
|
|
35228
|
+
* culled frame lists the indices `edit` addresses, with each element's
|
|
35229
|
+
* layout read from the static cascade over `tokens`, and the selection the
|
|
34819
35230
|
* writing tab last reported, which `POST /api/selection` takes behind
|
|
34820
35231
|
* `requireWriter` and `GET /api/selection` answers as the `selection` record.
|
|
34821
35232
|
* `GET /api/frames/styles` answers a frame's or an element's colors from the
|
|
@@ -34827,7 +35238,9 @@ function elementsRoutes(root, access, selection, tokens = null) {
|
|
|
34827
35238
|
const readTree = async (ref) => {
|
|
34828
35239
|
const frame = await resolveFrameRef(root, ref, { cwd: root });
|
|
34829
35240
|
const bytes = await readFile(frame.path);
|
|
34830
|
-
const
|
|
35241
|
+
const source = readFrame(frame);
|
|
35242
|
+
const sheets = tokenSheets(root, frame.project, tokens);
|
|
35243
|
+
const elements = elementTree(bytes.toString("utf8"), elementLayouts(source, sheets), elementRounds(source, sheets));
|
|
34831
35244
|
if (!Array.isArray(elements)) throw new FrameboardError(elements.reason, elements.detail, { ref });
|
|
34832
35245
|
return {
|
|
34833
35246
|
ref: `${frame.project}/${frame.page}/${frame.name}`,
|
|
@@ -35419,6 +35832,141 @@ async function hashOf(path) {
|
|
|
35419
35832
|
throw error;
|
|
35420
35833
|
}
|
|
35421
35834
|
}
|
|
35835
|
+
// src/server/notes/dispatch.ts
|
|
35836
|
+
/** The `serve` environment variable holding the command a dispatched note runs. */
|
|
35837
|
+
const DISPATCH_ENV = "FRAMEBOARD_DISPATCH";
|
|
35838
|
+
const DISPATCH_LOG = "dispatch.log";
|
|
35839
|
+
/**
|
|
35840
|
+
* How long a command has to fail before it counts as started. A command that
|
|
35841
|
+
* backgrounds its session and exits 0, as `claude --bg` does, counts at once.
|
|
35842
|
+
* `claude --bg` refusing an untrusted folder exits 1 near 700 ms, so the
|
|
35843
|
+
* window sits well past that.
|
|
35844
|
+
*/
|
|
35845
|
+
const START_WINDOW_MS = 2e3;
|
|
35846
|
+
/**
|
|
35847
|
+
* Starts a session for a note by running the developer's command detached,
|
|
35848
|
+
* its output appended to `.run/dispatch.log`. The note reaches the command as
|
|
35849
|
+
* environment variables alone, never spliced into the command string, so its
|
|
35850
|
+
* text is data to the shell. Resolves once the command exits 0 or outlives
|
|
35851
|
+
* the window, and refuses `dispatch-failed` when it exits otherwise inside it.
|
|
35852
|
+
*/
|
|
35853
|
+
function createDispatcher({ command, cwd, root, env, windowMs = START_WINDOW_MS }) {
|
|
35854
|
+
return async ({ session, id, line }) => {
|
|
35855
|
+
const log = await open(join(await ensureRunFolder(root), DISPATCH_LOG), "a");
|
|
35856
|
+
try {
|
|
35857
|
+
await started(spawn("sh", ["-c", command], {
|
|
35858
|
+
cwd,
|
|
35859
|
+
detached: true,
|
|
35860
|
+
stdio: [
|
|
35861
|
+
"ignore",
|
|
35862
|
+
log.fd,
|
|
35863
|
+
log.fd
|
|
35864
|
+
],
|
|
35865
|
+
env: {
|
|
35866
|
+
...env,
|
|
35867
|
+
FRAMEBOARD_SESSION: session,
|
|
35868
|
+
FRAMEBOARD_NOTE: line,
|
|
35869
|
+
FRAMEBOARD_NOTE_ID: id,
|
|
35870
|
+
FRAMEBOARD_ROOT: root
|
|
35871
|
+
}
|
|
35872
|
+
}), windowMs);
|
|
35873
|
+
} finally {
|
|
35874
|
+
await log.close();
|
|
35875
|
+
}
|
|
35876
|
+
};
|
|
35877
|
+
}
|
|
35878
|
+
function started(child, windowMs) {
|
|
35879
|
+
return new Promise((resolve, reject) => {
|
|
35880
|
+
const timer = setTimeout(() => {
|
|
35881
|
+
child.unref();
|
|
35882
|
+
resolve();
|
|
35883
|
+
}, windowMs);
|
|
35884
|
+
child.once("error", (error) => {
|
|
35885
|
+
clearTimeout(timer);
|
|
35886
|
+
reject(new FrameboardError("dispatch-failed", `The ${DISPATCH_ENV} command did not start: ${error.message}`, {}, { cause: error }));
|
|
35887
|
+
});
|
|
35888
|
+
child.once("exit", (code, signal) => {
|
|
35889
|
+
clearTimeout(timer);
|
|
35890
|
+
if (code === 0) {
|
|
35891
|
+
resolve();
|
|
35892
|
+
return;
|
|
35893
|
+
}
|
|
35894
|
+
reject(new FrameboardError("dispatch-failed", `The ${DISPATCH_ENV} command exited ${code ?? signal} within ${windowMs} ms. Its output is in .run/${DISPATCH_LOG}.`, {
|
|
35895
|
+
code,
|
|
35896
|
+
signal
|
|
35897
|
+
}));
|
|
35898
|
+
});
|
|
35899
|
+
});
|
|
35900
|
+
}
|
|
35901
|
+
// src/server/notes/images.ts
|
|
35902
|
+
/** A page's folder of note images, dot-named so the board never reads it as content. */
|
|
35903
|
+
const NOTES_FOLDER = ".notes";
|
|
35904
|
+
/** A stored image as a note records it, relative to its page. */
|
|
35905
|
+
const STORED = /^\.notes\/[0-9a-f]{12}\.(png|jpg|gif|webp)$/;
|
|
35906
|
+
const IMAGE_CONTENT_TYPES = {
|
|
35907
|
+
png: "image/png",
|
|
35908
|
+
jpg: "image/jpeg",
|
|
35909
|
+
gif: "image/gif",
|
|
35910
|
+
webp: "image/webp"
|
|
35911
|
+
};
|
|
35912
|
+
/**
|
|
35913
|
+
* The extension an image's bytes declare, or null for anything but PNG,
|
|
35914
|
+
* JPEG, GIF, and WebP. SVG is left out on purpose, since it can carry script
|
|
35915
|
+
* and the thumbnails render in the board's own page.
|
|
35916
|
+
*/
|
|
35917
|
+
function imageExtension(bytes) {
|
|
35918
|
+
const ascii = (from, to) => String.fromCharCode(...bytes.subarray(from, to));
|
|
35919
|
+
if (bytes[0] === 137 && ascii(1, 4) === "PNG") return "png";
|
|
35920
|
+
if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return "jpg";
|
|
35921
|
+
if (ascii(0, 4) === "GIF8") return "gif";
|
|
35922
|
+
if (ascii(0, 4) === "RIFF" && ascii(8, 12) === "WEBP") return "webp";
|
|
35923
|
+
return null;
|
|
35924
|
+
}
|
|
35925
|
+
/**
|
|
35926
|
+
* Saves each image to `<page>/.notes/` under a fresh random name and answers
|
|
35927
|
+
* the page-relative paths in order. Every image is checked before any is
|
|
35928
|
+
* written, so a refusal leaves the folder as it was.
|
|
35929
|
+
*/
|
|
35930
|
+
async function saveImages(pageDir, images) {
|
|
35931
|
+
const typed = images.map((bytes, index) => {
|
|
35932
|
+
const extension = imageExtension(bytes);
|
|
35933
|
+
if (extension === null) throw new FrameboardError("image-type-refused", "A note takes PNG, JPEG, GIF, or WebP images. Nothing was saved.", { index });
|
|
35934
|
+
return {
|
|
35935
|
+
bytes,
|
|
35936
|
+
extension
|
|
35937
|
+
};
|
|
35938
|
+
});
|
|
35939
|
+
const folder = join(pageDir, NOTES_FOLDER);
|
|
35940
|
+
await mkdir(folder, { recursive: true });
|
|
35941
|
+
return Promise.all(typed.map(async ({ bytes, extension }) => {
|
|
35942
|
+
const name = `${randomBytes(6).toString("hex")}.${extension}`;
|
|
35943
|
+
await writeFile(join(folder, name), bytes, { flag: "wx" });
|
|
35944
|
+
return `${NOTES_FOLDER}/${name}`;
|
|
35945
|
+
}));
|
|
35946
|
+
}
|
|
35947
|
+
/**
|
|
35948
|
+
* The absolute path of a stored image in a page, or null when the path is
|
|
35949
|
+
* not one `saveImages` writes, the file is gone, or its real path leaves the
|
|
35950
|
+
* page's `.notes/`.
|
|
35951
|
+
*/
|
|
35952
|
+
async function storedImage(pageDir, stored) {
|
|
35953
|
+
if (!STORED.test(stored)) return null;
|
|
35954
|
+
try {
|
|
35955
|
+
const folder = await realpath(join(pageDir, NOTES_FOLDER));
|
|
35956
|
+
const file = await realpath(join(pageDir, stored));
|
|
35957
|
+
if (!file.startsWith(folder + sep)) return null;
|
|
35958
|
+
return (await stat(file)).isFile() ? file : null;
|
|
35959
|
+
} catch (error) {
|
|
35960
|
+
if (isCode(error, "ENOENT") || isCode(error, "ENOTDIR")) return null;
|
|
35961
|
+
throw error;
|
|
35962
|
+
}
|
|
35963
|
+
}
|
|
35964
|
+
/** Refuses a note naming an image its page does not hold, before anything is written. */
|
|
35965
|
+
async function assertStored(pageDir, images) {
|
|
35966
|
+
const found = await Promise.all(images.map((image) => storedImage(pageDir, image)));
|
|
35967
|
+
const missing = images.filter((_, index) => found[index] === null);
|
|
35968
|
+
if (missing.length > 0) throw new FrameboardError("usage", `The note names images its page does not hold: ${missing.join(", ")}. Upload each one first.`, { missing });
|
|
35969
|
+
}
|
|
35422
35970
|
// src/shared/records/notes.ts
|
|
35423
35971
|
/** Where a note on one element points, in the edit address's terms. */
|
|
35424
35972
|
const noteAnchorSchema = looseObject({
|
|
@@ -35437,6 +35985,8 @@ const noteSchema = looseObject({
|
|
|
35437
35985
|
/** Null for a note on the whole frame. */
|
|
35438
35986
|
anchor: noteAnchorSchema.nullable(),
|
|
35439
35987
|
text: string$1(),
|
|
35988
|
+
/** Images saved with the message, relative to its page, as `.notes/<file>`. Absent on a note with none. */
|
|
35989
|
+
images: array$1(string$1()).optional(),
|
|
35440
35990
|
from: _enum$1(["developer", "agent"]),
|
|
35441
35991
|
/** Who signed it, as git names them, stamped by the server. */
|
|
35442
35992
|
author: string$1().nullable(),
|
|
@@ -35472,15 +36022,21 @@ const listenerSchema = object$1({
|
|
|
35472
36022
|
* The one line a follower prints per note. It opens with `frameboard note`,
|
|
35473
36023
|
* which the skill tells the agent to act on, and names the verbs that answer
|
|
35474
36024
|
* it. Text is collapsed onto one line, stripped of control characters so it
|
|
35475
|
-
* cannot drive the terminal, and cut at 200 characters.
|
|
36025
|
+
* cannot drive the terminal, and cut at 200 characters. Image paths sit
|
|
36026
|
+
* between the text and the hints, so the prefix and the hints never move.
|
|
35476
36027
|
*/
|
|
35477
|
-
function noteLine({ id, ref, element, text }) {
|
|
35478
|
-
|
|
36028
|
+
function noteLine({ id, ref, element, text, images = [] }) {
|
|
36029
|
+
const where = element === null ? ref : `${ref} element ${element}`;
|
|
36030
|
+
const attached = images.length === 0 ? "" : ` (images: ${images.map(flatten).join(", ")})`;
|
|
36031
|
+
return `frameboard note ${id} on ${where}: ${collapse(text)}${attached} (reply: frameboard notes reply ${id} "<text>", close: frameboard notes done ${id})`;
|
|
35479
36032
|
}
|
|
35480
36033
|
function collapse(text) {
|
|
35481
|
-
const flat = text
|
|
36034
|
+
const flat = flatten(text);
|
|
35482
36035
|
return flat.length > 200 ? `${flat.slice(0, 200)}...` : flat;
|
|
35483
36036
|
}
|
|
36037
|
+
function flatten(text) {
|
|
36038
|
+
return text.replace(/\s+/g, " ").replace(/[\u0000-\u001f\u007f-\u009f]/g, "").trim();
|
|
36039
|
+
}
|
|
35484
36040
|
// src/server/notes/store.ts
|
|
35485
36041
|
const NOTES_FILE$1 = "notes.json";
|
|
35486
36042
|
const notesSpec = {
|
|
@@ -35557,6 +36113,7 @@ function addRoot(file, fields, { now, id }) {
|
|
|
35557
36113
|
frame: fields.frame,
|
|
35558
36114
|
anchor: fields.anchor,
|
|
35559
36115
|
text: fields.text,
|
|
36116
|
+
...withImages(fields.images),
|
|
35560
36117
|
from: "developer",
|
|
35561
36118
|
author: fields.author,
|
|
35562
36119
|
session: null,
|
|
@@ -35581,6 +36138,7 @@ function addReply(file, replyTo, fields, { now, id }) {
|
|
|
35581
36138
|
frame: root.frame,
|
|
35582
36139
|
anchor: root.anchor,
|
|
35583
36140
|
text: fields.text,
|
|
36141
|
+
...withImages(fields.images),
|
|
35584
36142
|
from: fields.from,
|
|
35585
36143
|
author: fields.author,
|
|
35586
36144
|
session: fields.session,
|
|
@@ -35601,6 +36159,10 @@ function addReply(file, replyTo, fields, { now, id }) {
|
|
|
35601
36159
|
notes: [...notes, reply]
|
|
35602
36160
|
};
|
|
35603
36161
|
}
|
|
36162
|
+
/** A note with no images carries no key, so it reads as one written before images. */
|
|
36163
|
+
function withImages(images) {
|
|
36164
|
+
return images === void 0 || images.length === 0 ? {} : { images };
|
|
36165
|
+
}
|
|
35604
36166
|
/** Sets the state of the thread `id` belongs to, and its addressee when one is given. */
|
|
35605
36167
|
function setState(file, id, state, now, to) {
|
|
35606
36168
|
const root = rootOf(file, id);
|
|
@@ -35614,6 +36176,13 @@ function setState(file, id, state, now, to) {
|
|
|
35614
36176
|
} : note)
|
|
35615
36177
|
};
|
|
35616
36178
|
}
|
|
36179
|
+
/** Takes one message out, for a write whose send failed after it landed. */
|
|
36180
|
+
function removeNote(file, id) {
|
|
36181
|
+
return {
|
|
36182
|
+
...file,
|
|
36183
|
+
notes: file.notes.filter((note) => note.id !== id)
|
|
36184
|
+
};
|
|
36185
|
+
}
|
|
35617
36186
|
/** A page's notes as the board draws them, an unreadable file reading as none. */
|
|
35618
36187
|
async function pageView(root, place) {
|
|
35619
36188
|
let file;
|
|
@@ -35645,23 +36214,36 @@ async function queuedFor(root, session) {
|
|
|
35645
36214
|
for (const note of notes) {
|
|
35646
36215
|
if (note.thread !== null || note.state !== "queued") continue;
|
|
35647
36216
|
if (note.to !== session) continue;
|
|
35648
|
-
|
|
35649
|
-
const newest = notes.filter((each) => (each.id === note.id || each.thread === note.id) && each.from === "developer").at(-1);
|
|
35650
|
-
const { element, ...stored } = note;
|
|
35651
|
-
deliveries.push({
|
|
35652
|
-
note: stored,
|
|
35653
|
-
ref,
|
|
35654
|
-
line: noteLine({
|
|
35655
|
-
id: note.id,
|
|
35656
|
-
ref,
|
|
35657
|
-
element,
|
|
35658
|
-
text: (newest ?? note).text
|
|
35659
|
-
})
|
|
35660
|
-
});
|
|
36217
|
+
deliveries.push(toDelivery(place, notes, note));
|
|
35661
36218
|
}
|
|
35662
36219
|
}
|
|
35663
36220
|
return deliveries;
|
|
35664
36221
|
}
|
|
36222
|
+
/** A root note as a follower would receive it, read from its page whatever its state. */
|
|
36223
|
+
async function deliveryOf(root, place, rootId) {
|
|
36224
|
+
const notes = await pageView(root, place);
|
|
36225
|
+
const note = notes.find((each) => each.id === rootId && each.thread === null);
|
|
36226
|
+
if (!note) throw new FrameboardError("note-not-found", `No note ${rootId} in this page.`, { id: rootId });
|
|
36227
|
+
return toDelivery(place, notes, note);
|
|
36228
|
+
}
|
|
36229
|
+
function toDelivery(place, notes, note) {
|
|
36230
|
+
const ref = `${place.project}/${place.page}/${note.frame}`;
|
|
36231
|
+
const newest = notes.filter((each) => (each.id === note.id || each.thread === note.id) && each.from === "developer").at(-1);
|
|
36232
|
+
const { element, ...stored } = note;
|
|
36233
|
+
const message = newest ?? note;
|
|
36234
|
+
const pageDir = dirname(place.path);
|
|
36235
|
+
return {
|
|
36236
|
+
note: stored,
|
|
36237
|
+
ref,
|
|
36238
|
+
line: noteLine({
|
|
36239
|
+
id: note.id,
|
|
36240
|
+
ref,
|
|
36241
|
+
element,
|
|
36242
|
+
text: message.text,
|
|
36243
|
+
images: message.images?.map((image) => join(pageDir, image))
|
|
36244
|
+
})
|
|
36245
|
+
};
|
|
36246
|
+
}
|
|
35665
36247
|
/** Marks a root note delivered, while it is still queued to that session. */
|
|
35666
36248
|
async function markDelivered(root, id, session, now) {
|
|
35667
36249
|
await updateNotes((await findNote(root, id)).path, (file) => {
|
|
@@ -35678,33 +36260,64 @@ const STATUS$1 = {
|
|
|
35678
36260
|
"frame-not-found": 404,
|
|
35679
36261
|
"note-not-found": 404,
|
|
35680
36262
|
"stale-address": 409,
|
|
36263
|
+
"dispatch-unavailable": 409,
|
|
35681
36264
|
"notes-invalid": 422,
|
|
36265
|
+
"image-type-refused": 415,
|
|
36266
|
+
"dispatch-failed": 502,
|
|
35682
36267
|
"lock-timeout": 503
|
|
35683
36268
|
};
|
|
35684
36269
|
const text = string$1().trim().min(1).max(1e5);
|
|
35685
36270
|
const session = string$1().min(1).max(256);
|
|
36271
|
+
/** Page-relative paths an upload answered, each checked against the page on write. */
|
|
36272
|
+
const images = array$1(string$1().max(256)).max(32).optional();
|
|
36273
|
+
/** Asks for a new session in place of `to`. */
|
|
36274
|
+
const dispatch = literal(true).optional();
|
|
36275
|
+
const oneAddressee = {
|
|
36276
|
+
check: (body) => body.to === void 0 || body.dispatch === void 0,
|
|
36277
|
+
message: { message: "names a session or asks to start one, never both" }
|
|
36278
|
+
};
|
|
35686
36279
|
const pinSchema = object$1({
|
|
35687
36280
|
/** The frame ref, `<project>/<page>/<frame>`. */
|
|
35688
36281
|
frame: string$1().min(1).max(1024),
|
|
35689
36282
|
text,
|
|
36283
|
+
images,
|
|
35690
36284
|
/** The element's index, given with the `modifiedAt` the board rendered it at. */
|
|
35691
36285
|
element: int$1().min(0).optional(),
|
|
35692
36286
|
renderedAt: string$1().optional(),
|
|
35693
|
-
to: session.optional()
|
|
35694
|
-
|
|
36287
|
+
to: session.optional(),
|
|
36288
|
+
dispatch
|
|
36289
|
+
}).refine(oneAddressee.check, oneAddressee.message);
|
|
35695
36290
|
const replySchema = object$1({
|
|
35696
36291
|
text,
|
|
35697
|
-
|
|
35698
|
-
|
|
35699
|
-
|
|
36292
|
+
images,
|
|
36293
|
+
to: session.optional(),
|
|
36294
|
+
dispatch
|
|
36295
|
+
}).refine(oneAddressee.check, oneAddressee.message);
|
|
36296
|
+
const sendSchema = object$1({
|
|
36297
|
+
to: session.optional(),
|
|
36298
|
+
dispatch
|
|
36299
|
+
}).refine((body) => body.to === void 0 !== (body.dispatch === void 0), { message: "names a session to send to or asks to start one" });
|
|
35700
36300
|
/**
|
|
35701
36301
|
* The board's note writes, each behind `requireWriter`: pin a note, reply in
|
|
35702
36302
|
* its thread, send it to a listening session, and mark it done. Each answers
|
|
35703
36303
|
* the CLI's `{ ok, data }` envelope with the note it wrote, and a refusal its
|
|
35704
36304
|
* `{ ok, error }`. A write offers the queue to delivery at once rather than
|
|
35705
36305
|
* waiting on the watcher.
|
|
35706
|
-
|
|
35707
|
-
|
|
36306
|
+
*
|
|
36307
|
+
* Pin, reply, and send take `dispatch: true` in place of `to`, which starts a
|
|
36308
|
+
* session through `dispatch` under an id minted here and marks the thread's
|
|
36309
|
+
* root delivered to it, so the started session's inbox never prints it a
|
|
36310
|
+
* second time. A failed start takes back the message the request added, and
|
|
36311
|
+
* no `dispatch` refuses before anything is written.
|
|
36312
|
+
*
|
|
36313
|
+
* A note's images go up first, as multipart `files` with the `page` ref, to
|
|
36314
|
+
* `/api/notes/images`, which saves them to the page's `.notes/` and answers
|
|
36315
|
+
* their page-relative paths for pin and reply to carry. A write naming an
|
|
36316
|
+
* image its page does not hold is refused. `/api/note-images/...` reads one
|
|
36317
|
+
* back with no writer check, as the frames route reads a page's files, since
|
|
36318
|
+
* an `<img>` sends no `Origin`.
|
|
36319
|
+
*/
|
|
36320
|
+
function notesRoutes(root, access, delivery, dispatch, imageLimit = ASSET_BODY_LIMIT) {
|
|
35708
36321
|
const app = new Hono();
|
|
35709
36322
|
app.use("/api/notes", requireWriter(access));
|
|
35710
36323
|
app.use("/api/notes/*", requireWriter(access));
|
|
@@ -35713,35 +36326,106 @@ function notesRoutes(root, access, delivery) {
|
|
|
35713
36326
|
delivery?.offer().catch(() => {});
|
|
35714
36327
|
return file.notes.find((note) => note.id === id);
|
|
35715
36328
|
};
|
|
36329
|
+
const dispatcher = (asked) => {
|
|
36330
|
+
if (asked === void 0) return void 0;
|
|
36331
|
+
if (!dispatch) throw new FrameboardError("dispatch-unavailable", `No session can be started, since serve was started without ${DISPATCH_ENV}.`);
|
|
36332
|
+
return dispatch;
|
|
36333
|
+
};
|
|
36334
|
+
/**
|
|
36335
|
+
* Starts a session on a thread already on disk, then hands the root to it
|
|
36336
|
+
* as delivered, answering the note `answer` names.
|
|
36337
|
+
*/
|
|
36338
|
+
const startSession = async (run, place, rootId, added, answer) => {
|
|
36339
|
+
const minted = randomUUID();
|
|
36340
|
+
try {
|
|
36341
|
+
const { line } = await deliveryOf(root, place, rootId);
|
|
36342
|
+
await run({
|
|
36343
|
+
session: minted,
|
|
36344
|
+
id: rootId,
|
|
36345
|
+
line
|
|
36346
|
+
});
|
|
36347
|
+
} catch (error) {
|
|
36348
|
+
if (added !== null) await updateNotes(place.path, (file) => removeNote(file, added));
|
|
36349
|
+
throw error;
|
|
36350
|
+
}
|
|
36351
|
+
return write(place.path, (file) => setState(file, rootId, "delivered", /* @__PURE__ */ new Date(), minted), answer);
|
|
36352
|
+
};
|
|
36353
|
+
app.post("/api/notes/images", bodyLimit({
|
|
36354
|
+
maxSize: imageLimit,
|
|
36355
|
+
onError: (c) => c.json({
|
|
36356
|
+
ok: false,
|
|
36357
|
+
error: {
|
|
36358
|
+
code: "asset-too-large",
|
|
36359
|
+
message: `A note's images may carry ${imageLimit / 1024 / 1024} MiB at most. Nothing was saved.`
|
|
36360
|
+
}
|
|
36361
|
+
}, 413)
|
|
36362
|
+
}), async (c) => {
|
|
36363
|
+
const form = await c.req.parseBody({ all: true }).catch(() => ({}));
|
|
36364
|
+
const sent = [form.files].flat().filter((v) => v instanceof File);
|
|
36365
|
+
if (typeof form.page !== "string" || sent.length === 0) throw new FrameboardError("usage", "Send multipart/form-data with the page ref in \"page\" and images in \"files\".");
|
|
36366
|
+
const page = await resolvePageRef(root, form.page, { cwd: root });
|
|
36367
|
+
const bytes = await Promise.all(sent.map(async (file) => new Uint8Array(await file.arrayBuffer())));
|
|
36368
|
+
return c.json({
|
|
36369
|
+
ok: true,
|
|
36370
|
+
data: { images: await saveImages(page.path, bytes) }
|
|
36371
|
+
});
|
|
36372
|
+
});
|
|
36373
|
+
app.get("/api/note-images/:project/:page/:name", async (c) => {
|
|
36374
|
+
const { project, page, name } = c.req.param();
|
|
36375
|
+
const found = await resolvePageRef(root, `${project}/${page}`, { cwd: root }).catch(() => null);
|
|
36376
|
+
const file = found && await storedImage(found.path, `.notes/${name}`);
|
|
36377
|
+
if (!file) return c.notFound();
|
|
36378
|
+
return c.body(new Uint8Array(await readFile(file)), 200, {
|
|
36379
|
+
"Content-Type": IMAGE_CONTENT_TYPES[extname(file).slice(1)] ?? "application/octet-stream",
|
|
36380
|
+
"Cache-Control": "no-store"
|
|
36381
|
+
});
|
|
36382
|
+
});
|
|
35716
36383
|
app.post("/api/notes", async (c) => {
|
|
35717
36384
|
const body = await parseBody(c.req.raw, pinSchema);
|
|
36385
|
+
const run = dispatcher(body.dispatch);
|
|
35718
36386
|
const frame = await resolveFrameRef(root, body.frame, { cwd: root });
|
|
36387
|
+
await assertStored(dirname(frame.path), body.images ?? []);
|
|
35719
36388
|
if (body.element !== void 0 && body.renderedAt === void 0) throw new FrameboardError("usage", "An element note needs the renderedAt the board showed it at.");
|
|
35720
36389
|
const anchor = body.element === void 0 ? null : await anchorFor(frame.path, body.element, body.renderedAt ?? "");
|
|
35721
36390
|
const id = newNoteId();
|
|
35722
36391
|
const author = await readAuthor(root);
|
|
35723
|
-
const
|
|
36392
|
+
const place = {
|
|
36393
|
+
project: frame.project,
|
|
36394
|
+
page: frame.page,
|
|
36395
|
+
path: notesPath(root, frame.project, frame.page)
|
|
36396
|
+
};
|
|
36397
|
+
const note = await write(place.path, (file) => addRoot(file, {
|
|
35724
36398
|
frame: frame.name,
|
|
35725
36399
|
anchor,
|
|
35726
36400
|
text: body.text,
|
|
36401
|
+
images: body.images,
|
|
35727
36402
|
author,
|
|
35728
36403
|
to: body.to ?? null
|
|
35729
36404
|
}, {
|
|
35730
36405
|
now: /* @__PURE__ */ new Date(),
|
|
35731
36406
|
id
|
|
35732
36407
|
}), id);
|
|
35733
|
-
return c.json({
|
|
36408
|
+
if (!run) return c.json({
|
|
35734
36409
|
ok: true,
|
|
35735
36410
|
data: { note }
|
|
35736
36411
|
});
|
|
36412
|
+
const started = await startSession(run, place, id, id, id);
|
|
36413
|
+
return c.json({
|
|
36414
|
+
ok: true,
|
|
36415
|
+
data: { note: started }
|
|
36416
|
+
});
|
|
35737
36417
|
});
|
|
35738
36418
|
app.post("/api/notes/:id/replies", async (c) => {
|
|
35739
36419
|
const body = await parseBody(c.req.raw, replySchema);
|
|
36420
|
+
const run = dispatcher(body.dispatch);
|
|
35740
36421
|
const found = await findNote(root, c.req.param("id"));
|
|
36422
|
+
await assertStored(dirname(found.path), body.images ?? []);
|
|
36423
|
+
const rootId = found.note.thread ?? found.note.id;
|
|
35741
36424
|
const id = newNoteId();
|
|
35742
36425
|
const author = await readAuthor(root);
|
|
35743
36426
|
const note = await write(found.path, (file) => addReply(file, found.note.id, {
|
|
35744
36427
|
text: body.text,
|
|
36428
|
+
images: body.images,
|
|
35745
36429
|
from: "developer",
|
|
35746
36430
|
author,
|
|
35747
36431
|
session: null,
|
|
@@ -35750,15 +36434,28 @@ function notesRoutes(root, access, delivery) {
|
|
|
35750
36434
|
now: /* @__PURE__ */ new Date(),
|
|
35751
36435
|
id
|
|
35752
36436
|
}), id);
|
|
35753
|
-
return c.json({
|
|
36437
|
+
if (!run) return c.json({
|
|
35754
36438
|
ok: true,
|
|
35755
36439
|
data: { note }
|
|
35756
36440
|
});
|
|
36441
|
+
const started = await startSession(run, found, rootId, id, id);
|
|
36442
|
+
return c.json({
|
|
36443
|
+
ok: true,
|
|
36444
|
+
data: { note: started }
|
|
36445
|
+
});
|
|
35757
36446
|
});
|
|
35758
36447
|
app.post("/api/notes/:id/send", async (c) => {
|
|
35759
36448
|
const body = await parseBody(c.req.raw, sendSchema);
|
|
36449
|
+
const run = dispatcher(body.dispatch);
|
|
35760
36450
|
const found = await findNote(root, c.req.param("id"));
|
|
35761
36451
|
const rootId = found.note.thread ?? found.note.id;
|
|
36452
|
+
if (run) {
|
|
36453
|
+
const note = await startSession(run, found, rootId, null, rootId);
|
|
36454
|
+
return c.json({
|
|
36455
|
+
ok: true,
|
|
36456
|
+
data: { note }
|
|
36457
|
+
});
|
|
36458
|
+
}
|
|
35762
36459
|
const note = await write(found.path, (file) => setState(file, rootId, "queued", /* @__PURE__ */ new Date(), body.to), rootId);
|
|
35763
36460
|
return c.json({
|
|
35764
36461
|
ok: true,
|
|
@@ -35841,8 +36538,8 @@ function isTheme(value) {
|
|
|
35841
36538
|
return value === "light" || value === "dark";
|
|
35842
36539
|
}
|
|
35843
36540
|
// src/server/board/pages.ts
|
|
35844
|
-
/** Notes belong to the page they were pinned on, so a copy starts without them. */
|
|
35845
|
-
const NOT_COPIED = /* @__PURE__ */ new Set(["notes.json"]);
|
|
36541
|
+
/** Notes and their images belong to the page they were pinned on, so a copy starts without them. */
|
|
36542
|
+
const NOT_COPIED = /* @__PURE__ */ new Set(["notes.json", ".notes"]);
|
|
35846
36543
|
async function addPage(root, ref, { index, ...options }) {
|
|
35847
36544
|
const page = await resolvePageRef(root, ref, {
|
|
35848
36545
|
...options,
|
|
@@ -36098,71 +36795,6 @@ async function assertFree(root, name, self) {
|
|
|
36098
36795
|
taken
|
|
36099
36796
|
});
|
|
36100
36797
|
}
|
|
36101
|
-
// src/shared/starter-tokens.ts
|
|
36102
|
-
/**
|
|
36103
|
-
* The looks a new project can start from, each accent paired by hand with a
|
|
36104
|
-
* dark value, so both themes hold without a derived color. The keys are the
|
|
36105
|
-
* values `project tokens --accent` and the route take.
|
|
36106
|
-
*/
|
|
36107
|
-
const STARTER_ACCENTS = {
|
|
36108
|
-
blue: {
|
|
36109
|
-
light: "#2f7bf0",
|
|
36110
|
-
dark: "#4e92f6"
|
|
36111
|
-
},
|
|
36112
|
-
red: {
|
|
36113
|
-
light: "#e5484d",
|
|
36114
|
-
dark: "#ff6369"
|
|
36115
|
-
},
|
|
36116
|
-
green: {
|
|
36117
|
-
light: "#30a46c",
|
|
36118
|
-
dark: "#3dd68c"
|
|
36119
|
-
},
|
|
36120
|
-
orange: {
|
|
36121
|
-
light: "#f76b15",
|
|
36122
|
-
dark: "#ff801f"
|
|
36123
|
-
},
|
|
36124
|
-
purple: {
|
|
36125
|
-
light: "#8e4ec6",
|
|
36126
|
-
dark: "#9a5cd0"
|
|
36127
|
-
}
|
|
36128
|
-
};
|
|
36129
|
-
/** The served faces a starter sheet may name, keyed by their face folder. */
|
|
36130
|
-
const STARTER_FONTS = {
|
|
36131
|
-
geist: {
|
|
36132
|
-
family: "Geist",
|
|
36133
|
-
stack: "Geist, sans-serif"
|
|
36134
|
-
},
|
|
36135
|
-
"geist-mono": {
|
|
36136
|
-
family: "Geist Mono",
|
|
36137
|
-
stack: "'Geist Mono', monospace"
|
|
36138
|
-
}
|
|
36139
|
-
};
|
|
36140
|
-
const DEFAULT_LOOK = {
|
|
36141
|
-
accent: "blue",
|
|
36142
|
-
font: "geist"
|
|
36143
|
-
};
|
|
36144
|
-
/** A project token sheet setting the names the fixture sheets use, light then dark. */
|
|
36145
|
-
function starterSheet({ accent, font }) {
|
|
36146
|
-
const pair = STARTER_ACCENTS[accent];
|
|
36147
|
-
return `:root {
|
|
36148
|
-
--accent: ${pair.light};
|
|
36149
|
-
--surface: #ffffff;
|
|
36150
|
-
--text: #111111;
|
|
36151
|
-
--muted: #6b7280;
|
|
36152
|
-
--border: #e5e7eb;
|
|
36153
|
-
--radius: 10px;
|
|
36154
|
-
--font-text: ${STARTER_FONTS[font].stack};
|
|
36155
|
-
}
|
|
36156
|
-
|
|
36157
|
-
[data-theme='dark'] {
|
|
36158
|
-
--accent: ${pair.dark};
|
|
36159
|
-
--surface: #111111;
|
|
36160
|
-
--text: #ededed;
|
|
36161
|
-
--muted: #9ca3af;
|
|
36162
|
-
--border: #2e2e2e;
|
|
36163
|
-
}
|
|
36164
|
-
`;
|
|
36165
|
-
}
|
|
36166
36798
|
// src/server/look/starter.ts
|
|
36167
36799
|
/**
|
|
36168
36800
|
* Writes a starter `tokens.css` into a project that renders with no token
|
|
@@ -36222,6 +36854,8 @@ const coordinate = int$1();
|
|
|
36222
36854
|
const frameAddSchema = object$1({
|
|
36223
36855
|
ref,
|
|
36224
36856
|
size: _enum$1(Object.keys(FRAME_SIZES)).optional(),
|
|
36857
|
+
width: int$1().min(1).optional(),
|
|
36858
|
+
height: int$1().min(1).optional(),
|
|
36225
36859
|
x: coordinate.optional(),
|
|
36226
36860
|
y: coordinate.optional()
|
|
36227
36861
|
});
|
|
@@ -36348,7 +36982,11 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
36348
36982
|
before: `${source.project}/${source.name}`,
|
|
36349
36983
|
after: renamed.ref
|
|
36350
36984
|
},
|
|
36351
|
-
frames: []
|
|
36985
|
+
frames: [],
|
|
36986
|
+
renamed: {
|
|
36987
|
+
before: `${source.project}/${source.name}`,
|
|
36988
|
+
after: renamed.ref
|
|
36989
|
+
}
|
|
36352
36990
|
}));
|
|
36353
36991
|
return c.json({
|
|
36354
36992
|
ok: true,
|
|
@@ -36564,8 +37202,15 @@ function structureRoutes(root, access, history, measure, tokens = null) {
|
|
|
36564
37202
|
});
|
|
36565
37203
|
app.post("/api/project/rename", async (c) => {
|
|
36566
37204
|
const body = await parseBody$1(c.req.raw, renameSchema);
|
|
36567
|
-
|
|
36568
|
-
|
|
37205
|
+
const source = await resolveProject(root, body.ref);
|
|
37206
|
+
await refuseHeld([source.name]);
|
|
37207
|
+
const project = await recorded((journal) => renameProject(root, body.ref, body.name, { journal }), async (renamed) => ({
|
|
37208
|
+
...await onHome(),
|
|
37209
|
+
renamed: {
|
|
37210
|
+
before: source.name,
|
|
37211
|
+
after: renamed.name
|
|
37212
|
+
}
|
|
37213
|
+
}));
|
|
36569
37214
|
return c.json({
|
|
36570
37215
|
ok: true,
|
|
36571
37216
|
data: project
|
|
@@ -36690,7 +37335,7 @@ function boardHostGuard(port) {
|
|
|
36690
37335
|
await next();
|
|
36691
37336
|
};
|
|
36692
37337
|
}
|
|
36693
|
-
function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, history, selection, checks, thumbnails, measure, frameVersion, settledVersion }) {
|
|
37338
|
+
function createApp({ clientDir, root, port, actions, tickets, renderFrame, facesDir, tokens, delivery, dispatch, history, selection, checks, thumbnails, measure, frameVersion, settledVersion }) {
|
|
36694
37339
|
const app = new Hono();
|
|
36695
37340
|
const given = tokens ?? null;
|
|
36696
37341
|
app.use("*", async (c, next) => {
|
|
@@ -36712,7 +37357,7 @@ function createApp({ clientDir, root, port, actions, tickets, renderFrame, faces
|
|
|
36712
37357
|
app.route("/", apiRoutes(root, actions, frames.look, history));
|
|
36713
37358
|
app.route("/", structureRoutes(root, actions.access, history, measure, given));
|
|
36714
37359
|
app.route("/", historyRoutes(actions.access, history));
|
|
36715
|
-
app.route("/", notesRoutes(root, actions.access, delivery));
|
|
37360
|
+
app.route("/", notesRoutes(root, actions.access, delivery, dispatch));
|
|
36716
37361
|
app.route("/", assetsRoutes(root, actions.access));
|
|
36717
37362
|
app.route("/", elementsRoutes(root, actions.access, selection, given));
|
|
36718
37363
|
app.route("/", findRoutes(root));
|
|
@@ -38761,7 +39406,27 @@ object$1({
|
|
|
38761
39406
|
index: int$1().min(0),
|
|
38762
39407
|
hash
|
|
38763
39408
|
});
|
|
39409
|
+
object$1({
|
|
39410
|
+
ref: string$1(),
|
|
39411
|
+
hash
|
|
39412
|
+
});
|
|
39413
|
+
object$1({
|
|
39414
|
+
ref: string$1(),
|
|
39415
|
+
index: int$1().min(0),
|
|
39416
|
+
hash
|
|
39417
|
+
});
|
|
38764
39418
|
// src/shared/records/elements.ts
|
|
39419
|
+
/**
|
|
39420
|
+
* How an element lays out what it holds, read from the frame's static
|
|
39421
|
+
* cascade: a flex by its main axis, a grid, or `block` for anything else,
|
|
39422
|
+
* including a flex or grid set through an unresolved `var()`.
|
|
39423
|
+
*/
|
|
39424
|
+
const layoutSchema = _enum$1([
|
|
39425
|
+
"row",
|
|
39426
|
+
"column",
|
|
39427
|
+
"grid",
|
|
39428
|
+
"block"
|
|
39429
|
+
]);
|
|
38765
39430
|
/** One element under a frame's `body`, addressed by the index `edit --index` takes. */
|
|
38766
39431
|
const treeElementSchema = object$1({
|
|
38767
39432
|
index: int$1().min(0),
|
|
@@ -38771,7 +39436,11 @@ const treeElementSchema = object$1({
|
|
|
38771
39436
|
/** `data-name`, else a text-only element's text cut to 40 characters, else an `img`'s `alt`, else the tag. */
|
|
38772
39437
|
name: string$1(),
|
|
38773
39438
|
/** True when the element holds text and nothing else. */
|
|
38774
|
-
textOnly: boolean$1()
|
|
39439
|
+
textOnly: boolean$1(),
|
|
39440
|
+
/** Its layout, which a culled frame's Layers rows draw from without an iframe. */
|
|
39441
|
+
layout: layoutSchema,
|
|
39442
|
+
/** True when it holds nothing and its corners round by half or more, so it draws as an ellipse. */
|
|
39443
|
+
round: boolean$1()
|
|
38775
39444
|
});
|
|
38776
39445
|
/** What `GET /api/frames/elements` answers: a frame's elements under `body` in index order, and the hash they were read from. */
|
|
38777
39446
|
const elementTreeSchema = object$1({
|
|
@@ -38925,7 +39594,7 @@ function contentFormat() {
|
|
|
38925
39594
|
`A project is any folder in the board whose name does not open with a dot. Its ${PROJECT_FILE} lists page names in display order, and pages it does not list follow by name.`,
|
|
38926
39595
|
`A page is any folder in a project except ${ASSETS_FOLDER}/ and dot-named ones. Its ${LAYOUT_FILE} holds each frame's box, stacking order, and flags.`,
|
|
38927
39596
|
`A frame is any *${FRAME_EXTENSION} file directly in a page, named by its stem.`,
|
|
38928
|
-
`A page's notes sit in its ${NOTES_FILE$1}, never in a frame. A note pins to a frame or to one element by index and the frame file's hash, and reads at the frame once the file changes. Read them with notes, answer with notes reply, and close them with notes done.`,
|
|
39597
|
+
`A page's notes sit in its ${NOTES_FILE$1}, never in a frame. A note pins to a frame or to one element by index and the frame file's hash, and reads at the frame once the file changes. Read them with notes, answer with notes reply, and close them with notes done. A note's images sit in its page's ${NOTES_FOLDER}/ folder, and its images field lists them relative to the page.`,
|
|
38929
39598
|
`serve reuses a board the walk finds, and otherwise creates ${DEFAULT_BOARD_FOLDER}/ in the working folder with project ${START_PROJECT} and empty page ${START_PAGE}, and records its address in ${RUN_FOLDER}/${ADDRESS_FILE}.`,
|
|
38930
39599
|
`Dot-named folders, *${LOCK_SUFFIX} files, and *${TEMP_SUFFIX} files belong to Frameboard and are never content.`
|
|
38931
39600
|
],
|
|
@@ -39197,7 +39866,7 @@ function registerFrame(program, context) {
|
|
|
39197
39866
|
data: record,
|
|
39198
39867
|
human: `${what} ${record.ref}`
|
|
39199
39868
|
});
|
|
39200
|
-
act(withPosition(withSize(verb("add", "Place a frame past every frame,
|
|
39869
|
+
act(withPosition(withSize(verb("add", "Place a frame past every frame, as written when its file exists and with a skeleton file only when none does, so write the file first to show no empty box. Each axis no size names hugs its content, so a preset or --width fixes the width and the height hugs."))), context, async ([ref = ""], options) => done(await addFrame(await boardOf(options, io), ref, {
|
|
39201
39870
|
...options,
|
|
39202
39871
|
cwd: io.cwd
|
|
39203
39872
|
}), "Added"));
|
|
@@ -43103,11 +43772,13 @@ function registerNotes(program, context) {
|
|
|
43103
43772
|
const file = await readNotes(place.path);
|
|
43104
43773
|
const done = new Set(file.notes.filter((n) => n.state === "done").map((n) => n.id));
|
|
43105
43774
|
const kept = byThread(file.notes).filter((note) => (options.all || !done.has(note.thread ?? note.id)) && (!frame || note.frame === frame.name));
|
|
43106
|
-
const
|
|
43775
|
+
const pageDir = join(root, place.project, place.page);
|
|
43776
|
+
const elements = await resolveAnchors(pageDir, kept);
|
|
43107
43777
|
listed.push(...kept.map((note) => ({
|
|
43108
43778
|
...note,
|
|
43109
43779
|
ref: `${place.project}/${place.page}/${note.frame}`,
|
|
43110
|
-
element: elements[note.id] ?? null
|
|
43780
|
+
element: elements[note.id] ?? null,
|
|
43781
|
+
...note.images?.length ? { imagePaths: note.images.map((image) => join(pageDir, image)) } : {}
|
|
43111
43782
|
})));
|
|
43112
43783
|
}
|
|
43113
43784
|
return {
|
|
@@ -43175,7 +43846,7 @@ function byThread(notes) {
|
|
|
43175
43846
|
function describe$1(notes) {
|
|
43176
43847
|
if (notes.length === 0) return "No open notes";
|
|
43177
43848
|
return notes.map((note) => {
|
|
43178
|
-
const text = note.text.replace(/\s+/g, " ").trim()
|
|
43849
|
+
const text = `${note.text.replace(/\s+/g, " ").trim()}${(note.imagePaths ?? []).map((path) => `\n image: ${path}`).join("")}`;
|
|
43179
43850
|
if (note.thread) return ` ${note.from === "agent" ? "agent" : note.author ?? "developer"}: ${text}`;
|
|
43180
43851
|
const where = note.element === null ? note.ref : `${note.ref} element ${note.element}`;
|
|
43181
43852
|
return `${note.id} Note ${note.number} on ${where} ${note.state}${note.to ? ` to ${note.to}` : ""}\n ${note.author ?? "developer"}: ${text}`;
|
|
@@ -43682,7 +44353,7 @@ function versionKey(ref, hash) {
|
|
|
43682
44353
|
/** The files and folders a step wrote, being every rewrite, creation, removal, and move. */
|
|
43683
44354
|
function writtenPaths(step) {
|
|
43684
44355
|
return step.changes.flatMap((change) => {
|
|
43685
|
-
if (change.kind === "element" || change.kind === "inserted" || change.kind === "path") return [change.path];
|
|
44356
|
+
if (change.kind === "element" || change.kind === "inserted" || change.kind === "relocated" || change.kind === "path") return [change.path];
|
|
43686
44357
|
if (change.kind === "moved") return [change.from, change.to];
|
|
43687
44358
|
return [];
|
|
43688
44359
|
});
|
|
@@ -43878,7 +44549,8 @@ async function reads(change, side) {
|
|
|
43878
44549
|
}
|
|
43879
44550
|
case "path": return change.present === side ? await exists(change.path) && await hashPath(change.path) === change.hash : !await exists(change.path) && await exists(change.slot);
|
|
43880
44551
|
case "element": return await exists(change.path) && holdsSpan(await readFile(change.path, "utf8"), change.span, side);
|
|
43881
|
-
case "inserted": return await exists(change.path) && holdsInserted(await readFile(change.path, "utf8"), change.span, side);
|
|
44552
|
+
case "inserted": return await exists(change.path) && holdsInserted(await readFile(change.path, "utf8"), change.span, side === change.present ? "after" : "before");
|
|
44553
|
+
case "relocated": return await exists(change.path) && relocateMoved(await readFile(change.path, "utf8"), change.span, OTHER[side]) !== void 0;
|
|
43882
44554
|
}
|
|
43883
44555
|
}
|
|
43884
44556
|
/**
|
|
@@ -43947,7 +44619,16 @@ async function restore(change, side) {
|
|
|
43947
44619
|
};
|
|
43948
44620
|
});
|
|
43949
44621
|
case "inserted": return rewriteFrame(change, (source) => {
|
|
43950
|
-
const written = side ===
|
|
44622
|
+
const written = side === change.present ? restoreInserted(source, change.span) : removeInserted(source, change.span);
|
|
44623
|
+
return written && {
|
|
44624
|
+
html: written.html,
|
|
44625
|
+
keep: () => {
|
|
44626
|
+
change.span = written.span;
|
|
44627
|
+
}
|
|
44628
|
+
};
|
|
44629
|
+
});
|
|
44630
|
+
case "relocated": return rewriteFrame(change, (source) => {
|
|
44631
|
+
const written = relocateMoved(source, change.span, side);
|
|
43951
44632
|
return written && {
|
|
43952
44633
|
html: written.html,
|
|
43953
44634
|
keep: () => {
|
|
@@ -44044,6 +44725,26 @@ var StepJournal = class {
|
|
|
44044
44725
|
kind: "inserted",
|
|
44045
44726
|
path,
|
|
44046
44727
|
ref,
|
|
44728
|
+
span,
|
|
44729
|
+
present: "after"
|
|
44730
|
+
});
|
|
44731
|
+
}
|
|
44732
|
+
/** The element a hand delete took out of a frame file, which this journal does not write. */
|
|
44733
|
+
deletedElement(path, ref, span) {
|
|
44734
|
+
this.changes.push({
|
|
44735
|
+
kind: "inserted",
|
|
44736
|
+
path,
|
|
44737
|
+
ref,
|
|
44738
|
+
span,
|
|
44739
|
+
present: "before"
|
|
44740
|
+
});
|
|
44741
|
+
}
|
|
44742
|
+
/** The element a hand move took to another gap of a frame file, which this journal does not write. */
|
|
44743
|
+
relocated(path, ref, span) {
|
|
44744
|
+
this.changes.push({
|
|
44745
|
+
kind: "relocated",
|
|
44746
|
+
path,
|
|
44747
|
+
ref,
|
|
44047
44748
|
span
|
|
44048
44749
|
});
|
|
44049
44750
|
}
|
|
@@ -44147,7 +44848,7 @@ var History = class {
|
|
|
44147
44848
|
if (this.#undo.length > 100) this.#undo.shift();
|
|
44148
44849
|
this.#redo = [];
|
|
44149
44850
|
this.onChange(this.counts());
|
|
44150
|
-
this.onWrite(step);
|
|
44851
|
+
this.onWrite(step, "after");
|
|
44151
44852
|
}
|
|
44152
44853
|
/**
|
|
44153
44854
|
* The refs the top undo or redo step would write, without popping it, so a
|
|
@@ -44208,7 +44909,7 @@ var History = class {
|
|
|
44208
44909
|
}
|
|
44209
44910
|
onto.push(step);
|
|
44210
44911
|
this.onChange(this.counts());
|
|
44211
|
-
this.onWrite(step);
|
|
44912
|
+
this.onWrite(step, to);
|
|
44212
44913
|
const answer = {
|
|
44213
44914
|
page: step.page?.[to] ?? null,
|
|
44214
44915
|
frames: step.frames
|
|
@@ -47516,6 +48217,24 @@ function reloadRefs(root, paths, board, tokens = null) {
|
|
|
47516
48217
|
return named;
|
|
47517
48218
|
}
|
|
47518
48219
|
/**
|
|
48220
|
+
* `refs` less each frame that only moved with a folder the board renamed,
|
|
48221
|
+
* being one under a moved folder whose file carries the stamp `last`, the
|
|
48222
|
+
* board sent before the move, showed at its old path. It renders what the
|
|
48223
|
+
* tab already shows, so a reload would restart it for nothing, while a file
|
|
48224
|
+
* written before or after the move that `last` never showed still reloads.
|
|
48225
|
+
*/
|
|
48226
|
+
function unmovedRefs(refs, board, moved, last) {
|
|
48227
|
+
if (moved.length === 0 || !last) return refs;
|
|
48228
|
+
const shown = new Map(last.projects.flatMap((project) => project.pages.flatMap((page) => page.frames.map((frame) => [frame.path, frame.modifiedAt]))));
|
|
48229
|
+
const onlyMoved = /* @__PURE__ */ new Set();
|
|
48230
|
+
for (const project of board.projects) for (const page of project.pages) for (const frame of page.frames) {
|
|
48231
|
+
const folder = moved.find(({ path }) => frame.path.startsWith(`${path}${sep}`));
|
|
48232
|
+
const before = folder && `${folder.from}${frame.path.slice(folder.path.length)}`;
|
|
48233
|
+
if (before && shown.get(before) === frame.modifiedAt) onlyMoved.add(frame.ref);
|
|
48234
|
+
}
|
|
48235
|
+
return refs.filter((ref) => !onlyMoved.has(ref));
|
|
48236
|
+
}
|
|
48237
|
+
/**
|
|
47519
48238
|
* The frame a page-folder file belongs to: `hero.html` itself, or a temp file
|
|
47520
48239
|
* an editor or atomic writer saves it through, such as `hero.html.swap`.
|
|
47521
48240
|
*/
|
|
@@ -47614,7 +48333,7 @@ function checkOne(root, frame, context) {
|
|
|
47614
48333
|
* it never counts as a tab, and taken only from a socket upgraded with the
|
|
47615
48334
|
* address token as a bearer, since a browser page must never register one.
|
|
47616
48335
|
*/
|
|
47617
|
-
function createHub({ tabs, port, access, snapshot, findings, notes, delivery, history, claims, changes, closeTab }) {
|
|
48336
|
+
function createHub({ tabs, port, access, snapshot, findings, notes, delivery, history, claims, changes, closeTab, dispatch = false }) {
|
|
47618
48337
|
const server = new import_websocket_server.default({ noServer: true });
|
|
47619
48338
|
const boards = /* @__PURE__ */ new Map();
|
|
47620
48339
|
const inboxes = /* @__PURE__ */ new Map();
|
|
@@ -47656,7 +48375,8 @@ function createHub({ tabs, port, access, snapshot, findings, notes, delivery, hi
|
|
|
47656
48375
|
});
|
|
47657
48376
|
send(socket, {
|
|
47658
48377
|
type: "access",
|
|
47659
|
-
write: writer
|
|
48378
|
+
write: writer,
|
|
48379
|
+
dispatch: writer && dispatch
|
|
47660
48380
|
});
|
|
47661
48381
|
if (history) send(socket, {
|
|
47662
48382
|
type: "history",
|
|
@@ -47761,6 +48481,7 @@ function createHug({ root, measure }) {
|
|
|
47761
48481
|
let closed = false;
|
|
47762
48482
|
const run = async (board, refs) => {
|
|
47763
48483
|
const pages = /* @__PURE__ */ new Map();
|
|
48484
|
+
let stale = false;
|
|
47764
48485
|
for (const frame of huggingFrames(board, refs)) {
|
|
47765
48486
|
if (closed) return false;
|
|
47766
48487
|
let size;
|
|
@@ -47771,6 +48492,7 @@ function createHug({ root, measure }) {
|
|
|
47771
48492
|
continue;
|
|
47772
48493
|
}
|
|
47773
48494
|
if (size.empty) continue;
|
|
48495
|
+
stale ||= frame.hugWidth && size.width !== frame.box.width || frame.hugHeight && size.height !== frame.box.height;
|
|
47774
48496
|
const page = `${frame.project}/${frame.page}`;
|
|
47775
48497
|
pages.set(page, {
|
|
47776
48498
|
...pages.get(page),
|
|
@@ -47787,7 +48509,7 @@ function createHug({ root, measure }) {
|
|
|
47787
48509
|
if (!(error instanceof FrameboardError)) throw error;
|
|
47788
48510
|
}
|
|
47789
48511
|
}
|
|
47790
|
-
return written;
|
|
48512
|
+
return written || stale;
|
|
47791
48513
|
};
|
|
47792
48514
|
return {
|
|
47793
48515
|
now: (board, refs) => run(board, refs),
|
|
@@ -48042,6 +48764,11 @@ const HOSTNAME = "127.0.0.1";
|
|
|
48042
48764
|
*/
|
|
48043
48765
|
const OWN_GRACE_MS = 1e3;
|
|
48044
48766
|
/**
|
|
48767
|
+
* How long a folder the board's own rename moved keeps its unchanged frames
|
|
48768
|
+
* from reloading, well past the watcher reporting the move under load.
|
|
48769
|
+
*/
|
|
48770
|
+
const MOVED_MS = 1e4;
|
|
48771
|
+
/**
|
|
48045
48772
|
* The board tabs holding a live connection to this server, counting apart the
|
|
48046
48773
|
* ones that can write. The route a tab connects through calls `open` and
|
|
48047
48774
|
* `close`, and `serve` waits on a writer before deciding to open a tab of its
|
|
@@ -48094,7 +48821,7 @@ async function startServer({ strictPort = true, port, ...options }) {
|
|
|
48094
48821
|
});
|
|
48095
48822
|
}
|
|
48096
48823
|
}
|
|
48097
|
-
async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch }) {
|
|
48824
|
+
async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch, dispatch }) {
|
|
48098
48825
|
const tabs = new BoardTabs();
|
|
48099
48826
|
const tickets = createTickets();
|
|
48100
48827
|
let bound = 0;
|
|
@@ -48123,6 +48850,10 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
48123
48850
|
}),
|
|
48124
48851
|
now: () => /* @__PURE__ */ new Date()
|
|
48125
48852
|
});
|
|
48853
|
+
const dispatcher = dispatch ? createDispatcher({
|
|
48854
|
+
...dispatch,
|
|
48855
|
+
root
|
|
48856
|
+
}) : void 0;
|
|
48126
48857
|
await emptyTrash(root);
|
|
48127
48858
|
const tracker = createChangeTracker(root);
|
|
48128
48859
|
const settling = /* @__PURE__ */ new Set();
|
|
@@ -48139,23 +48870,51 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
48139
48870
|
}, OWN_GRACE_MS);
|
|
48140
48871
|
settling.add(timer);
|
|
48141
48872
|
};
|
|
48873
|
+
const shown = { board: null };
|
|
48874
|
+
let moved = [];
|
|
48875
|
+
const recentlyMoved = () => {
|
|
48876
|
+
moved = moved.filter(({ at }) => Date.now() - at < MOVED_MS);
|
|
48877
|
+
return moved;
|
|
48878
|
+
};
|
|
48142
48879
|
const history = new History(root, (counts) => hub.broadcast({
|
|
48143
48880
|
type: "history",
|
|
48144
48881
|
...counts
|
|
48145
|
-
}), (step
|
|
48882
|
+
}), (step, side) => {
|
|
48883
|
+
if (step.renamed) {
|
|
48884
|
+
for (const change of step.changes) {
|
|
48885
|
+
if (change.kind !== "moved") continue;
|
|
48886
|
+
moved = [...recentlyMoved(), {
|
|
48887
|
+
from: side === "after" ? change.from : change.to,
|
|
48888
|
+
path: side === "after" ? change.to : change.from,
|
|
48889
|
+
at: Date.now()
|
|
48890
|
+
}];
|
|
48891
|
+
}
|
|
48892
|
+
const from = side === "after" ? "before" : "after";
|
|
48893
|
+
hub.broadcast({
|
|
48894
|
+
type: "renamed",
|
|
48895
|
+
before: step.renamed[from],
|
|
48896
|
+
after: step.renamed[side]
|
|
48897
|
+
});
|
|
48898
|
+
}
|
|
48899
|
+
inTurn(() => tracker.own(step));
|
|
48900
|
+
});
|
|
48146
48901
|
const selection = createSelectionHolder(() => tabs.writers);
|
|
48147
48902
|
const hub = createHub({
|
|
48148
48903
|
tabs,
|
|
48149
48904
|
port: boundPort,
|
|
48150
48905
|
access,
|
|
48151
|
-
snapshot: () => inTurn(() =>
|
|
48906
|
+
snapshot: () => inTurn(async () => {
|
|
48907
|
+
shown.board = await scanBoard(root);
|
|
48908
|
+
return shown.board;
|
|
48909
|
+
}),
|
|
48152
48910
|
findings: () => inTurn(async () => findings.all()),
|
|
48153
48911
|
notes: () => inTurn(() => boardView(root)),
|
|
48154
48912
|
delivery,
|
|
48155
48913
|
history: () => history.counts(),
|
|
48156
48914
|
claims: () => inTurn(() => claims.read()),
|
|
48157
48915
|
changes: () => inTurn(async () => tracker.log()),
|
|
48158
|
-
closeTab: selection.closeTab
|
|
48916
|
+
closeTab: selection.closeTab,
|
|
48917
|
+
dispatch: dispatcher !== void 0
|
|
48159
48918
|
});
|
|
48160
48919
|
const claims = createClaimsPush(root, {
|
|
48161
48920
|
broadcast: (list) => hub.broadcast({
|
|
@@ -48235,6 +48994,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
48235
48994
|
port: boundPort,
|
|
48236
48995
|
tickets,
|
|
48237
48996
|
delivery,
|
|
48997
|
+
dispatch: dispatcher,
|
|
48238
48998
|
history,
|
|
48239
48999
|
selection,
|
|
48240
49000
|
renderFrame,
|
|
@@ -48305,7 +49065,9 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
48305
49065
|
claims,
|
|
48306
49066
|
thumbnails,
|
|
48307
49067
|
hug,
|
|
48308
|
-
settleLater
|
|
49068
|
+
settleLater,
|
|
49069
|
+
moved: recentlyMoved,
|
|
49070
|
+
shown
|
|
48309
49071
|
}));
|
|
48310
49072
|
});
|
|
48311
49073
|
return {
|
|
@@ -48343,7 +49105,7 @@ async function listen({ clientDir, facesDir, root, tokens, port, openUrl, launch
|
|
|
48343
49105
|
* notes or frames it touched, whose queue it offers to delivery. The frames
|
|
48344
49106
|
* an agent changed wait out the grace before the board hears of them.
|
|
48345
49107
|
*/
|
|
48346
|
-
async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, hug, settleLater }) {
|
|
49108
|
+
async function pushBatch(root, tokens, paths, { hub, findings, rendered, delivery, tracker, claims, thumbnails, hug, settleLater, moved, shown }) {
|
|
48347
49109
|
let board;
|
|
48348
49110
|
let own;
|
|
48349
49111
|
try {
|
|
@@ -48357,12 +49119,15 @@ async function pushBatch(root, tokens, paths, { hub, findings, rendered, deliver
|
|
|
48357
49119
|
type: "board",
|
|
48358
49120
|
data: board
|
|
48359
49121
|
});
|
|
49122
|
+
const last = shown.board;
|
|
49123
|
+
shown.board = board;
|
|
48360
49124
|
const refs = reloadRefs(root, paths, board, tokens);
|
|
48361
49125
|
hug.later(board, refs.filter((ref) => !own.includes(ref)));
|
|
48362
49126
|
if (refs.length > 0) {
|
|
48363
|
-
|
|
49127
|
+
const reloads = unmovedRefs(refs, board, moved(), last);
|
|
49128
|
+
if (reloads.length > 0) hub.broadcast({
|
|
48364
49129
|
type: "reload",
|
|
48365
|
-
refs
|
|
49130
|
+
refs: reloads
|
|
48366
49131
|
});
|
|
48367
49132
|
thumbnails.invalidate(refs);
|
|
48368
49133
|
const stale = Object.fromEntries(refs.map((ref) => [ref, null]));
|
|
@@ -48431,7 +49196,7 @@ const DEFAULT_PORT = 4173;
|
|
|
48431
49196
|
const RECONNECT_WAIT_MS = 1e3;
|
|
48432
49197
|
function registerServe(program, context) {
|
|
48433
49198
|
const { io } = context;
|
|
48434
|
-
act(addVerb(program, "serve",
|
|
49199
|
+
act(addVerb(program, "serve", `Serve the board in a local browser. A note sent to a new session runs the shell command in ${DISPATCH_ENV}, read once at start, with the note in FRAMEBOARD_NOTE, FRAMEBOARD_NOTE_ID, FRAMEBOARD_SESSION, and FRAMEBOARD_ROOT`).option("-p, --port <port>", "port to listen on, falling back to a free one when the default is taken", parsePort, DEFAULT_PORT).option("--no-open", "leave the browser alone").option("--tokens <path>", "a token sheet another tool manages, standing in for the board's tokens.css"), context, async (_args, options, self) => {
|
|
48435
49200
|
const tokens = options.tokens === void 0 ? void 0 : resolve(io.cwd, options.tokens);
|
|
48436
49201
|
if (tokens !== void 0 && !isFile(tokens)) throw new FrameboardError("tokens-not-found", `No token sheet at ${tokens}.`, { tokens });
|
|
48437
49202
|
const existing = await resolveBoard({
|
|
@@ -48467,7 +49232,8 @@ function registerServe(program, context) {
|
|
|
48467
49232
|
tokens,
|
|
48468
49233
|
port: options.port,
|
|
48469
49234
|
strictPort: self.getOptionValueSource("port") !== "default",
|
|
48470
|
-
openUrl: io.openUrl
|
|
49235
|
+
openUrl: io.openUrl,
|
|
49236
|
+
dispatch: dispatchCommand(io.cwd)
|
|
48471
49237
|
});
|
|
48472
49238
|
const address = newAddress({
|
|
48473
49239
|
root,
|
|
@@ -48499,6 +49265,19 @@ function registerServe(program, context) {
|
|
|
48499
49265
|
};
|
|
48500
49266
|
});
|
|
48501
49267
|
}
|
|
49268
|
+
/**
|
|
49269
|
+
* The developer's dispatch command, read from this process's environment
|
|
49270
|
+
* alone, never from a file a repository carries, so a cloned board cannot
|
|
49271
|
+
* make Send run anything.
|
|
49272
|
+
*/
|
|
49273
|
+
function dispatchCommand(cwd) {
|
|
49274
|
+
const command = process.env[DISPATCH_ENV]?.trim();
|
|
49275
|
+
return command ? {
|
|
49276
|
+
command,
|
|
49277
|
+
cwd,
|
|
49278
|
+
env: process.env
|
|
49279
|
+
} : void 0;
|
|
49280
|
+
}
|
|
48502
49281
|
/** True for a file, and false for a folder or a path that does not exist. */
|
|
48503
49282
|
function isFile(path) {
|
|
48504
49283
|
return statSync(path, { throwIfNoEntry: false })?.isFile() ?? false;
|