@bettercms-ai/sdk 1.46.0 → 1.47.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/dist/editable.cjs +229 -0
- package/dist/editable.cjs.map +1 -0
- package/dist/editable.d.cts +5 -0
- package/dist/editable.d.ts +5 -0
- package/dist/editable.js +202 -0
- package/dist/editable.js.map +1 -0
- package/dist/index.cjs +164 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -13
- package/dist/index.d.ts +84 -13
- package/dist/index.js +162 -23
- package/dist/index.js.map +1 -1
- package/dist/{read-B2lJr72F.d.ts → read-CpX17LTf.d.ts} +1 -1
- package/dist/{read-BZq0vVvs.d.cts → read-DlLBgPVS.d.cts} +1 -1
- package/dist/{read-client-DQhWuKf4.d.cts → read-client-D5jzCGEc.d.cts} +8 -1
- package/dist/{read-client-DQhWuKf4.d.ts → read-client-D5jzCGEc.d.ts} +8 -1
- package/dist/read.cjs +8 -5
- package/dist/read.cjs.map +1 -1
- package/dist/read.d.cts +2 -2
- package/dist/read.d.ts +2 -2
- package/dist/read.js +8 -5
- package/dist/read.js.map +1 -1
- package/dist/sections.cjs +8 -5
- package/dist/sections.cjs.map +1 -1
- package/dist/sections.d.cts +1 -1
- package/dist/sections.d.ts +1 -1
- package/dist/sections.js +8 -5
- package/dist/sections.js.map +1 -1
- package/dist/seo.cjs +26 -1
- package/dist/seo.cjs.map +1 -1
- package/dist/seo.d.cts +1 -1
- package/dist/seo.d.ts +1 -1
- package/dist/seo.js +24 -1
- package/dist/seo.js.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/editable.ts
|
|
21
|
+
var editable_exports = {};
|
|
22
|
+
__export(editable_exports, {
|
|
23
|
+
watchEditable: () => watchEditable
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(editable_exports);
|
|
26
|
+
|
|
27
|
+
// src/stega.ts
|
|
28
|
+
var ZERO = "\u200B";
|
|
29
|
+
var ONE = "\u200C";
|
|
30
|
+
var START = "\u2060";
|
|
31
|
+
var END = "\u2061";
|
|
32
|
+
var FRAMES = new RegExp(`${START}([${ZERO}${ONE}]*)${END}`, "g");
|
|
33
|
+
function fromBits(bits) {
|
|
34
|
+
const bytes = [];
|
|
35
|
+
for (let i = 0; i + 8 <= bits.length; i += 8) {
|
|
36
|
+
let b = 0;
|
|
37
|
+
for (let j = 0; j < 8; j++) b = b << 1 | (bits[i + j] === ONE ? 1 : 0);
|
|
38
|
+
bytes.push(b);
|
|
39
|
+
}
|
|
40
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
41
|
+
}
|
|
42
|
+
var V2_TYPES = { e: "entry", p: "page", l: "layout", c: "component" };
|
|
43
|
+
function payloadOf(bits) {
|
|
44
|
+
try {
|
|
45
|
+
const raw = JSON.parse(fromBits(bits));
|
|
46
|
+
if (typeof raw.t === "string" && raw.t in V2_TYPES && typeof raw.id === "string" && typeof raw.f === "string") {
|
|
47
|
+
return { ws: "", type: V2_TYPES[raw.t], id: raw.id, slug: "", field: raw.f };
|
|
48
|
+
}
|
|
49
|
+
return raw;
|
|
50
|
+
} catch {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var TARGETS = { entry: 1, page: 1, layout: 1, component: 1 };
|
|
55
|
+
var stegaRef = (payload) => typeof payload.type === "string" && payload.type in TARGETS && typeof payload.id === "string" && typeof payload.field === "string" ? `${payload.type}:${payload.id}:${payload.field}` : null;
|
|
56
|
+
var STEGA_OPEN = `${START}${END}`;
|
|
57
|
+
function stegaClean(value) {
|
|
58
|
+
if (typeof value === "string") return value.includes(START) ? value.replace(FRAMES, "") : value;
|
|
59
|
+
if (Array.isArray(value)) {
|
|
60
|
+
const out = value.map((v) => stegaClean(v));
|
|
61
|
+
return out.some((v, i) => v !== value[i]) ? out : value;
|
|
62
|
+
}
|
|
63
|
+
if (value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
|
|
64
|
+
const entries = Object.entries(value).map(([k, v]) => [k, stegaClean(v)]);
|
|
65
|
+
return entries.some(([k, v]) => v !== value[k]) ? Object.fromEntries(entries) : value;
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
function stegaFrames(text) {
|
|
70
|
+
return [...text.matchAll(FRAMES)].map((m) => ({ index: m.index, end: m.index + m[0].length, payload: m[1] ? payloadOf(m[1]) : null, open: !m[1] }));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/mark-editable.ts
|
|
74
|
+
var BOUND = ["data-bcms-field", "data-bcms-layout-field", "data-bcms-entry-field"];
|
|
75
|
+
var NOT_PROSE = { SCRIPT: "script", STYLE: "style", NOSCRIPT: "script", TEMPLATE: "script", TITLE: "head", TEXTAREA: "form" };
|
|
76
|
+
var INLINE_BREAKS = /* @__PURE__ */ new Set(["BR", "WBR"]);
|
|
77
|
+
var SVG = "http://www.w3.org/2000/svg";
|
|
78
|
+
var START2 = "\u2060";
|
|
79
|
+
var isBound = (el) => BOUND.some((name) => el.hasAttribute(name));
|
|
80
|
+
function refIn(text) {
|
|
81
|
+
const payload = stegaFrames(text).find((frame) => frame.payload)?.payload;
|
|
82
|
+
return payload ? stegaRef(payload) : null;
|
|
83
|
+
}
|
|
84
|
+
function stampOf(ref, pageId) {
|
|
85
|
+
const [target, id] = ref.split(":", 2);
|
|
86
|
+
const path = ref.slice(`${target}:${id}:`.length);
|
|
87
|
+
if (!path) return null;
|
|
88
|
+
if (target === "entry") return ["data-bcms-entry-field", ref];
|
|
89
|
+
if (target === "layout") return ["data-bcms-layout-field", ref];
|
|
90
|
+
if (target === "page" && pageId && id === pageId) return ["data-bcms-field", path];
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
function markEditable(root, opts) {
|
|
94
|
+
const leaks = [];
|
|
95
|
+
const texts = [];
|
|
96
|
+
const all = [];
|
|
97
|
+
const leak = (kind, where, text) => leaks.push({ kind, ref: refIn(text), where });
|
|
98
|
+
const visit = (el, skip) => {
|
|
99
|
+
for (const attr of Array.from(el.attributes)) {
|
|
100
|
+
if (!attr.value.includes(START2)) continue;
|
|
101
|
+
leak("attribute", `${el.tagName.toLowerCase()}[${attr.name}]`, attr.value);
|
|
102
|
+
el.setAttribute(attr.name, stegaClean(attr.value));
|
|
103
|
+
}
|
|
104
|
+
const own = el.tagName === "HEAD" ? "head" : NOT_PROSE[el.tagName];
|
|
105
|
+
const next = skip ?? own ?? (el.namespaceURI === SVG ? "bound" : null) ?? (el !== root && isBound(el) ? "bound" : null);
|
|
106
|
+
for (const node of [...Array.from(el.childNodes), ...Array.from(el.content?.childNodes ?? [])]) {
|
|
107
|
+
if (node.nodeType === 1) visit(node, next);
|
|
108
|
+
else if (node.nodeType === 8 && node.data.includes(START2)) {
|
|
109
|
+
const comment = node;
|
|
110
|
+
leak("comment", el.tagName.toLowerCase(), comment.data);
|
|
111
|
+
comment.data = stegaClean(comment.data);
|
|
112
|
+
} else if (node.nodeType === 3) {
|
|
113
|
+
const text = node;
|
|
114
|
+
all.push(text);
|
|
115
|
+
if (next === null) texts.push(text);
|
|
116
|
+
else if (next !== "bound" && text.data.includes(START2)) {
|
|
117
|
+
leak(next, el.tagName.toLowerCase(), text.data);
|
|
118
|
+
text.data = stegaClean(text.data);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
visit(root, null);
|
|
124
|
+
const starts = [];
|
|
125
|
+
let full = "";
|
|
126
|
+
for (const text of texts) {
|
|
127
|
+
starts.push(full.length);
|
|
128
|
+
full += text.data;
|
|
129
|
+
}
|
|
130
|
+
const nodeAt = (offset) => {
|
|
131
|
+
let lo = 0;
|
|
132
|
+
let hi = starts.length - 1;
|
|
133
|
+
while (lo < hi) {
|
|
134
|
+
const mid = lo + hi + 1 >> 1;
|
|
135
|
+
if (starts[mid] <= offset) lo = mid;
|
|
136
|
+
else hi = mid - 1;
|
|
137
|
+
}
|
|
138
|
+
return lo;
|
|
139
|
+
};
|
|
140
|
+
let stamped = 0;
|
|
141
|
+
let unresolved = 0;
|
|
142
|
+
const opens = [];
|
|
143
|
+
for (const frame of stegaFrames(full)) {
|
|
144
|
+
if (frame.open) {
|
|
145
|
+
opens.push(frame.index);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const start = opens.pop() ?? starts[nodeAt(frame.index)];
|
|
149
|
+
if (!frame.payload) continue;
|
|
150
|
+
const first = texts[nodeAt(start)];
|
|
151
|
+
const last = texts[nodeAt(frame.end - 1)];
|
|
152
|
+
const holder = commonElement(first, last);
|
|
153
|
+
const ref = stegaRef(frame.payload);
|
|
154
|
+
const stamp = ref ? stampOf(ref, opts.pageId) : null;
|
|
155
|
+
if (!holder || holder === root || !stamp || !holdsOnly(holder, stegaClean(full.slice(start, frame.end)))) {
|
|
156
|
+
unresolved += 1;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
holder.setAttribute(stamp[0], stamp[1]);
|
|
160
|
+
holder.setAttribute("data-bcms-kind", "text");
|
|
161
|
+
holder.setAttribute("data-bcms-match", "stega");
|
|
162
|
+
stamped += 1;
|
|
163
|
+
}
|
|
164
|
+
if (opts.strip) {
|
|
165
|
+
for (const text of all) if (text.data.includes(START2)) text.data = stegaClean(text.data);
|
|
166
|
+
}
|
|
167
|
+
return { stamped, leaks, unresolved };
|
|
168
|
+
}
|
|
169
|
+
function commonElement(a, b) {
|
|
170
|
+
const above = /* @__PURE__ */ new Set();
|
|
171
|
+
for (let n = a.parentNode; n; n = n.parentNode) above.add(n);
|
|
172
|
+
for (let n = b.parentNode; n; n = n.parentNode) if (above.has(n) && n.nodeType === 1) return n;
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
function holdsOnly(el, value) {
|
|
176
|
+
if (stegaClean(el.textContent ?? "").trim() !== value.trim()) return false;
|
|
177
|
+
return el.childElementCount === 0 || Array.from(el.querySelectorAll("*")).every((child) => INLINE_BREAKS.has(child.tagName) || stegaClean(child.textContent ?? "").trim() !== "");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/content-applied.ts
|
|
181
|
+
var CONTENT_APPLIED = "bcms:content-applied";
|
|
182
|
+
function onContentApplied(handler, target = globalThis.window) {
|
|
183
|
+
if (!target) return () => {
|
|
184
|
+
};
|
|
185
|
+
const listener = (event) => {
|
|
186
|
+
const data = event.data;
|
|
187
|
+
if (!data || typeof data !== "object" || data.type !== CONTENT_APPLIED) return;
|
|
188
|
+
handler({ type: CONTENT_APPLIED, fields: Array.isArray(data.fields) ? data.fields.filter((f) => typeof f === "string") : [] });
|
|
189
|
+
};
|
|
190
|
+
target.addEventListener("message", listener);
|
|
191
|
+
return () => target.removeEventListener("message", listener);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/editable.ts
|
|
195
|
+
var SETTLE_MS = 50;
|
|
196
|
+
var WATCHED = { childList: true, characterData: true, subtree: true };
|
|
197
|
+
function watchEditable(root, opts = {}) {
|
|
198
|
+
if (typeof window === "undefined") return () => {
|
|
199
|
+
};
|
|
200
|
+
let stopped = false;
|
|
201
|
+
let timer;
|
|
202
|
+
const run = () => {
|
|
203
|
+
if (stopped) return;
|
|
204
|
+
observer.disconnect();
|
|
205
|
+
markEditable(root, { ...opts.pageId ? { pageId: opts.pageId } : {}, strip: false });
|
|
206
|
+
observer.observe(root, WATCHED);
|
|
207
|
+
};
|
|
208
|
+
const later = () => {
|
|
209
|
+
clearTimeout(timer);
|
|
210
|
+
timer = setTimeout(run, SETTLE_MS);
|
|
211
|
+
};
|
|
212
|
+
const observer = new MutationObserver(later);
|
|
213
|
+
const idle = typeof window.requestIdleCallback === "function" ? window.requestIdleCallback.bind(window) : (fn) => setTimeout(fn, 1);
|
|
214
|
+
const cancelIdle = typeof window.cancelIdleCallback === "function" ? window.cancelIdleCallback.bind(window) : (id) => clearTimeout(id);
|
|
215
|
+
const first = idle(run);
|
|
216
|
+
const stopApplied = onContentApplied(later);
|
|
217
|
+
return () => {
|
|
218
|
+
stopped = true;
|
|
219
|
+
cancelIdle(first);
|
|
220
|
+
clearTimeout(timer);
|
|
221
|
+
observer.disconnect();
|
|
222
|
+
stopApplied();
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
226
|
+
0 && (module.exports = {
|
|
227
|
+
watchEditable
|
|
228
|
+
});
|
|
229
|
+
//# sourceMappingURL=editable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/editable.ts","../src/stega.ts","../src/mark-editable.ts","../src/content-applied.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n/**\n * watchEditable — the browser half of every adapter's `BcmsEditable`: turn the stega frames a\n * draft render carries into click-to-edit stamps, and keep doing it while the page changes.\n *\n * One function, so the React component, the SvelteKit action and the Nuxt directive cannot drift.\n * Each imports this module DYNAMICALLY behind its own draft check, so a published page neither\n * downloads nor runs any of it.\n *\n * - First pass after hydration, when the browser is idle: the stamps are attributes added to\n * the hydrated DOM, never server markup, so nothing can mismatch.\n * - Again, debounced, when the scope's children or text change (a client fetch, a route change\n * inside the scope) and after each edit the editor applies (`bcms:content-applied`).\n * - `strip: false`: the frames stay, so the editor's resolver still finds a value that a splitter\n * cut into many nodes. markEditable only adds attributes; a frame where no text belongs (an\n * attribute, a script) is still taken out, as it always is.\n *\n * Returns the function that stops watching.\n */\nimport { markEditable, type MarkElement } from \"./mark-editable.js\";\nimport { onContentApplied } from \"./content-applied.js\";\n\n/** How long the page must be quiet before a change is stamped again. */\nconst SETTLE_MS = 50;\n/** Children and text only: the stamps this adds are attributes, so they never wake it again. */\nconst WATCHED: MutationObserverInit = { childList: true, characterData: true, subtree: true };\n\nexport function watchEditable(root: Element, opts: { pageId?: string } = {}): () => void {\n if (typeof window === \"undefined\") return () => {};\n let stopped = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const run = () => {\n if (stopped) return;\n // A leak markEditable takes out of a text node is a change of its own: not watched while it runs.\n observer.disconnect();\n markEditable(root as unknown as MarkElement, { ...(opts.pageId ? { pageId: opts.pageId } : {}), strip: false });\n observer.observe(root, WATCHED);\n };\n const later = () => {\n clearTimeout(timer);\n timer = setTimeout(run, SETTLE_MS);\n };\n const observer = new MutationObserver(later);\n const idle = typeof window.requestIdleCallback === \"function\" ? window.requestIdleCallback.bind(window) : (fn: () => void) => setTimeout(fn, 1) as unknown as number;\n const cancelIdle = typeof window.cancelIdleCallback === \"function\" ? window.cancelIdleCallback.bind(window) : (id: number) => clearTimeout(id);\n const first = idle(run);\n const stopApplied = onContentApplied(later);\n return () => {\n stopped = true;\n cancelIdle(first);\n clearTimeout(timer);\n observer.disconnect();\n stopApplied();\n };\n}\n","/**\n * Stega — embed invisible content-provenance into string values for visual\n * editing, then decode it in the browser overlay to open the right dashboard\n * editor. Uses zero-width characters so the payload is invisible and copy-safe.\n *\n * Scheme: `<clean text><START><bits…><END>` where each byte of the UTF-8 JSON\n * payload is 8 zero-width bits (ZERO=U+200B, ONE=U+200C), framed by START\n * (U+2060) and END (U+2061). The backend encodes draft responses; the overlay\n * decodes. Both sides MUST share this module's scheme.\n */\nconst ZERO = \"\";\nconst ONE = \"\";\nconst START = \"\";\nconst END = \"\";\nconst FRAMES = new RegExp(`${START}([${ZERO}${ONE}]*)${END}`, \"g\");\n\n/**\n * Provenance describing where a string came from, for editor deep-linking. A `stega=2` payload\n * (`{t, id, f}`) is read into this same shape: `type` from `t`, `field` from `f`, and `ws`/`slug`\n * empty, because v2 does not carry them.\n */\nexport interface StegaPayload {\n /** Workspace slug (v1 only; \"\" from a v2 payload). */\n ws: string;\n type: \"entry\" | \"page\" | \"layout\" | \"component\";\n /** Entry/page id. */\n id: string;\n /** v1 only; \"\" from a v2 payload. */\n slug: string;\n /** Field key (or block id) the value belongs to. */\n field: string;\n /** The binding kind (`text`), where the encoder knows it. */\n kind?: string;\n}\n\nfunction toBits(s: string): string {\n const bytes = new TextEncoder().encode(s);\n let out = \"\";\n for (const b of bytes) {\n for (let i = 7; i >= 0; i--) out += (b >> i) & 1 ? ONE : ZERO;\n }\n return out;\n}\n\nfunction fromBits(bits: string): string {\n const bytes: number[] = [];\n for (let i = 0; i + 8 <= bits.length; i += 8) {\n let b = 0;\n for (let j = 0; j < 8; j++) b = (b << 1) | (bits[i + j] === ONE ? 1 : 0);\n bytes.push(b);\n }\n return new TextDecoder().decode(new Uint8Array(bytes));\n}\n\n/** Append an invisible provenance payload to a string (the v1 frame). */\nexport function encodeStega(clean: string, payload: StegaPayload): string {\n return `${clean}${START}${toBits(JSON.stringify(payload))}${END}`;\n}\n\nconst V2_TYPES = { e: \"entry\", p: \"page\", l: \"layout\", c: \"component\" } as const;\n\n/**\n * A frame's bits as a payload, or null when they are not JSON. A v2 payload is read into the v1\n * shape; any other JSON is returned as it decodes (v1, or the convert helper's source-map payload).\n */\nfunction payloadOf(bits: string): StegaPayload | null {\n try {\n const raw = JSON.parse(fromBits(bits)) as Record<string, unknown>;\n if (typeof raw.t === \"string\" && raw.t in V2_TYPES && typeof raw.id === \"string\" && typeof raw.f === \"string\") {\n return { ws: \"\", type: V2_TYPES[raw.t as keyof typeof V2_TYPES], id: raw.id, slug: \"\", field: raw.f };\n }\n return raw as unknown as StegaPayload;\n } catch {\n return null;\n }\n}\n\n/**\n * The field ref a payload addresses, `<target>:<id>:<path>`, the one address grammar every writer\n * reads; null for a payload that names no document (the convert helper's source map).\n */\nconst TARGETS = { entry: 1, page: 1, layout: 1, component: 1 };\nexport const stegaRef = (payload: StegaPayload): string | null =>\n typeof payload.type === \"string\" && payload.type in TARGETS && typeof payload.id === \"string\" && typeof payload.field === \"string\"\n ? `${payload.type}:${payload.id}:${payload.field}`\n : null;\n\n/**\n * Extract `{ clean, payload }` from a stega-encoded string (v1 or v2), or null if absent. `ref` is\n * the field ref, present when the payload names a document.\n */\nexport function decodeStega(value: string): { clean: string; payload: StegaPayload; ref?: string } | null {\n for (const frame of value.matchAll(FRAMES)) {\n // An empty frame is a v2 open marker, not a payload.\n if (!frame[1]) continue;\n const payload = payloadOf(frame[1]);\n if (!payload) return null;\n const ref = stegaRef(payload);\n return { clean: stegaClean(value), payload, ...(ref ? { ref } : {}) };\n }\n return null;\n}\n\n/**\n * A value's clean text and the field ref it carries (`entry:e_1:title`, `page:pg_1:hero.title`,\n * `layout:nav:brand`), or `ref: null` when it carries none. What a template uses when it needs both\n * the string to compare and the address to bind.\n */\nexport function stegaSplit(value: string): { clean: string; ref: string | null } {\n const decoded = decodeStega(value);\n return { clean: decoded?.clean ?? stegaClean(value), ref: decoded?.ref ?? null };\n}\n\n/**\n * Where a value BEGINS in a rendered page: an empty frame. The canvas brackets every bound\n * string with it and the payload frame, so a text node can be told inside a value from text\n * that merely precedes one. @see resolveStega\n */\nexport const STEGA_OPEN = `${START}${END}`;\n\n/**\n * A value with EVERY stega frame taken out, markers included, from every string in it at any depth\n * (arrays and plain objects). The SAME value back when it holds none. What a value passes through\n * before it is compared, used as a key or attribute, saved or published.\n */\nexport function stegaClean<T>(value: T): T {\n if (typeof value === \"string\") return (value.includes(START) ? value.replace(FRAMES, \"\") : value) as T;\n if (Array.isArray(value)) {\n const out = value.map((v) => stegaClean(v));\n return (out.some((v, i) => v !== value[i]) ? out : value) as T;\n }\n if (value && typeof value === \"object\" && Object.getPrototypeOf(value) === Object.prototype) {\n const entries = Object.entries(value).map(([k, v]) => [k, stegaClean(v)] as const);\n return (entries.some(([k, v]) => v !== (value as Record<string, unknown>)[k]) ? Object.fromEntries(entries) : value) as T;\n }\n return value;\n}\n\n/**\n * Remove every stega frame. An alias of {@link stegaClean}: it used to remove only the FIRST frame,\n * which left the payload behind on a `stega=2` value (an open marker, then the payload).\n */\nexport const stripStega = stegaClean;\n\n/** Each frame in `text`, in order: where it starts and ends, and its payload (null for an open marker or bits that are not one). */\nexport function stegaFrames(text: string): Array<{ index: number; end: number; payload: StegaPayload | null; open: boolean }> {\n return [...text.matchAll(FRAMES)].map((m) => ({ index: m.index, end: m.index + m[0].length, payload: m[1] ? payloadOf(m[1]) : null, open: !m[1] }));\n}\n\n/** The least of a DOM node this needs: a real `Node` satisfies it, and so does a test's plain object. */\nexport interface StegaNode {\n textContent: string | null;\n parentNode: StegaNode | null;\n childNodes?: ArrayLike<StegaNode>;\n}\n\n/**\n * Which value does this node render? Its payload and the nearest ancestor that holds the whole\n * value, or null when the node's text belongs to none.\n *\n * By CONTENT, not by attribute: a splitting library cuts a heading into one element per\n * character, a marquee clones its track, a component redraws its children, and the element a\n * build stamped is gone or copied. The string survives all of that, in order, across however\n * many text nodes: climbing from the clicked node, the first ancestor whose text holds a value\n * (its open marker to its payload frame) that overlaps the node is the value's extent.\n * Every copy of a value resolves to the same payload.\n */\nexport function resolveStega(node: StegaNode): { payload: StegaPayload; element: StegaNode } | null {\n let offset = 0;\n const length = node.textContent?.length ?? 0;\n for (let cur = node, up = node.parentNode; up; cur = up, up = up.parentNode) {\n for (const sibling of Array.from(up.childNodes ?? [])) {\n if (sibling === cur) break;\n offset += sibling.textContent?.length ?? 0;\n }\n const text = up.textContent ?? \"\";\n // Values nest (a field inside a field), so the open markers are a stack and a payload closes the last.\n const opens: number[] = [];\n for (const frame of stegaFrames(text)) {\n if (frame.open) {\n opens.push(frame.index);\n continue;\n }\n const open = opens.pop();\n // A value overlaps the node when it ends after the node starts and begins before the node\n // ends: the node that holds a value's first characters holds its open marker too.\n if (frame.end <= offset || open === undefined || open >= offset + length) continue;\n if (!frame.payload) break;\n return { payload: frame.payload, element: up };\n }\n }\n return null;\n}\n","/**\n * markEditable — turn the stega frames in a rendered subtree into the `data-bcms-*` stamps every\n * reader already understands, so a site whose templates only RENDER CMS values is click-to-edit\n * with no per-field binding code.\n *\n * Stega is the locator, the stamps stay the contract: this adds attributes and nothing else. It\n * never creates, moves or removes an element. One pass per root:\n *\n * - Each value is found by its open marker and its payload frame, across however many text nodes\n * a splitter or a framework cut it into (the pairing `resolveStega` does, run forward).\n * - The smallest element that holds the WHOLE value, and nothing else, is stamped with the\n * attribute its field ref maps to: `data-bcms-field` (this page), `data-bcms-entry-field`,\n * `data-bcms-layout-field`, plus `data-bcms-kind=\"text\"` and `data-bcms-match=\"stega\"`.\n * - A value that shares its element with other content (an icon beside a label) is not stamped:\n * its frame stays for the text-node resolver. An element that already carries a binding keeps\n * it, and nothing under it is stamped: an explicit stamp always wins.\n * - A frame where no visible text belongs (an attribute, `<head>`, `<script>`, `<style>`, a form\n * value, a `<template>`'s content, a comment) is a leak: reported, and stripped from the DOM\n * whatever `strip` says.\n * - `strip: true` removes every frame afterwards (a release: nothing framed may be written);\n * `strip: false` keeps them for the editor's resolver (a canvas, a draft render).\n */\nimport { stegaClean, stegaFrames, stegaRef } from \"./stega.js\";\n\n/** A frame found where no rendered text belongs, which a template should have cleaned. */\nexport interface StegaLeak {\n kind: \"head\" | \"attribute\" | \"script\" | \"style\" | \"form\" | \"comment\";\n /** The field ref the leaked frame carries, when it carries one. */\n ref: string | null;\n /** `tag` for text, `tag[attribute]` for an attribute. */\n where: string;\n}\n\nexport interface MarkEditableResult {\n /** Elements stamped from a frame. */\n stamped: number;\n leaks: StegaLeak[];\n /** Values found and left unstamped: sharing their element, or a ref this page cannot stamp. */\n unresolved: number;\n}\n\n/**\n * The least of the DOM this needs, so the SDK's types never pull the DOM library into a consumer\n * that runs on a server: a real `Element` satisfies it, and so does a JSDOM one.\n */\ninterface MarkNode {\n nodeType: number;\n parentNode: MarkNode | null;\n}\ninterface MarkText extends MarkNode {\n data: string;\n}\nexport interface MarkElement extends MarkNode {\n tagName: string;\n namespaceURI: string | null;\n textContent: string | null;\n childElementCount: number;\n attributes: ArrayLike<{ name: string; value: string }>;\n childNodes: ArrayLike<MarkNode>;\n /** A `<template>`'s parsed children live here, not in `childNodes`. */\n content?: { childNodes: ArrayLike<MarkNode> };\n hasAttribute(name: string): boolean;\n setAttribute(name: string, value: string): void;\n querySelectorAll(selector: string): ArrayLike<MarkElement>;\n}\n\nconst BOUND = [\"data-bcms-field\", \"data-bcms-layout-field\", \"data-bcms-entry-field\"];\n/** Elements whose text is not rendered prose, and the leak kind a frame inside one is. */\nconst NOT_PROSE: Record<string, StegaLeak[\"kind\"]> = { SCRIPT: \"script\", STYLE: \"style\", NOSCRIPT: \"script\", TEMPLATE: \"script\", TITLE: \"head\", TEXTAREA: \"form\" };\n/** Elements a whole value may wrap around: a line break is part of the value it sits in. */\nconst INLINE_BREAKS = new Set([\"BR\", \"WBR\"]);\nconst SVG = \"http://www.w3.org/2000/svg\";\nconst START = \"\";\n\nconst isBound = (el: MarkElement) => BOUND.some((name) => el.hasAttribute(name));\n\n/** The ref of the first payload in `text`, or null. */\nfunction refIn(text: string): string | null {\n const payload = stegaFrames(text).find((frame) => frame.payload)?.payload;\n return payload ? stegaRef(payload) : null;\n}\n\n/** The attribute and value a ref stamps on this page, or null when it has no stamp here. */\nfunction stampOf(ref: string, pageId: string | undefined): [string, string] | null {\n const [target, id] = ref.split(\":\", 2);\n const path = ref.slice(`${target}:${id}:`.length);\n if (!path) return null;\n if (target === \"entry\") return [\"data-bcms-entry-field\", ref];\n if (target === \"layout\") return [\"data-bcms-layout-field\", ref];\n // Another page's value has no in-page address; a component default is written to its definition.\n if (target === \"page\" && pageId && id === pageId) return [\"data-bcms-field\", path];\n return null;\n}\n\nexport function markEditable(root: MarkElement, opts: { pageId?: string; strip: boolean }): MarkEditableResult {\n const leaks: StegaLeak[] = [];\n const texts: MarkText[] = [];\n const all: MarkText[] = [];\n\n const leak = (kind: StegaLeak[\"kind\"], where: string, text: string) => leaks.push({ kind, ref: refIn(text), where });\n // One walk: leaks reported and stripped, every text node kept for the final strip, and the\n // text nodes a value may be read from kept in document order.\n const visit = (el: MarkElement, skip: StegaLeak[\"kind\"] | \"bound\" | null) => {\n for (const attr of Array.from(el.attributes)) {\n if (!attr.value.includes(START)) continue;\n leak(\"attribute\", `${el.tagName.toLowerCase()}[${attr.name}]`, attr.value);\n el.setAttribute(attr.name, stegaClean(attr.value));\n }\n const own = el.tagName === \"HEAD\" ? \"head\" : NOT_PROSE[el.tagName];\n const next = skip ?? own ?? (el.namespaceURI === SVG ? \"bound\" : null) ?? (el !== root && isBound(el) ? \"bound\" : null);\n for (const node of [...Array.from(el.childNodes), ...Array.from(el.content?.childNodes ?? [])]) {\n if (node.nodeType === 1) visit(node as MarkElement, next);\n else if (node.nodeType === 8 && (node as MarkText).data.includes(START)) {\n const comment = node as MarkText;\n leak(\"comment\", el.tagName.toLowerCase(), comment.data);\n comment.data = stegaClean(comment.data);\n } else if (node.nodeType === 3) {\n const text = node as MarkText;\n all.push(text);\n if (next === null) texts.push(text);\n else if (next !== \"bound\" && text.data.includes(START)) {\n leak(next, el.tagName.toLowerCase(), text.data);\n text.data = stegaClean(text.data);\n }\n }\n }\n };\n visit(root, null);\n\n // The value pass runs over the text the reader sees, in order: one string, each node's offset in it.\n const starts: number[] = [];\n let full = \"\";\n for (const text of texts) {\n starts.push(full.length);\n full += text.data;\n }\n const nodeAt = (offset: number) => {\n let lo = 0;\n let hi = starts.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (starts[mid]! <= offset) lo = mid;\n else hi = mid - 1;\n }\n return lo;\n };\n\n let stamped = 0;\n let unresolved = 0;\n const opens: number[] = [];\n for (const frame of stegaFrames(full)) {\n if (frame.open) {\n opens.push(frame.index);\n continue;\n }\n // A v1 frame has no open marker: its value is the text node the frame closes.\n const start = opens.pop() ?? starts[nodeAt(frame.index)]!;\n if (!frame.payload) continue;\n const first = texts[nodeAt(start)]!;\n const last = texts[nodeAt(frame.end - 1)]!;\n const holder = commonElement(first, last);\n const ref = stegaRef(frame.payload);\n const stamp = ref ? stampOf(ref, opts.pageId) : null;\n if (!holder || holder === root || !stamp || !holdsOnly(holder, stegaClean(full.slice(start, frame.end)))) {\n unresolved += 1;\n continue;\n }\n holder.setAttribute(stamp[0], stamp[1]);\n holder.setAttribute(\"data-bcms-kind\", \"text\");\n holder.setAttribute(\"data-bcms-match\", \"stega\");\n stamped += 1;\n }\n\n if (opts.strip) for (const text of all) if (text.data.includes(START)) text.data = stegaClean(text.data);\n return { stamped, leaks, unresolved };\n}\n\n/** The nearest element that contains both nodes. */\nfunction commonElement(a: MarkNode, b: MarkNode): MarkElement | null {\n const above = new Set<MarkNode>();\n for (let n: MarkNode | null = a.parentNode; n; n = n.parentNode) above.add(n);\n for (let n: MarkNode | null = b.parentNode; n; n = n.parentNode) if (above.has(n) && n.nodeType === 1) return n as MarkElement;\n return null;\n}\n\n/**\n * Whether `el` renders exactly `value` and nothing beside it: the same visible text, and no child\n * element without text of its own (an icon, an image) sharing it. A line break inside the value is\n * part of it.\n */\nfunction holdsOnly(el: MarkElement, value: string): boolean {\n if (stegaClean(el.textContent ?? \"\").trim() !== value.trim()) return false;\n return el.childElementCount === 0 || Array.from(el.querySelectorAll(\"*\")).every((child) => INLINE_BREAKS.has(child.tagName) || stegaClean(child.textContent ?? \"\").trim() !== \"\");\n}\n","/**\n * `bcms:content-applied` — what the visual editor tells a page after it has applied an edit to\n * the page's DOM.\n *\n * An edit changes how tall a heading is. Everything on the page that measured the layout once\n * (ScrollTrigger's start and end positions, Lenis's scroll limit, a carousel's slide widths, a\n * text splitter's lines) is now wrong, and only the page's own code can measure again. So the\n * editor posts one message to the frame's window after each applied edit, and the site listens:\n *\n * onContentApplied(() => ScrollTrigger.refresh());\n *\n * A published page receives no such message: nothing there posts it, and the listener is inert.\n */\n\n/** The `type` of the message. */\nexport const CONTENT_APPLIED = \"bcms:content-applied\";\n\nexport interface ContentAppliedMessage {\n type: typeof CONTENT_APPLIED;\n /** The field addresses whose rendering changed; empty when the editor does not say. */\n fields: string[];\n}\n\n/** The message the editor posts: `frame.contentWindow.postMessage(contentApplied(fields), origin)`. */\nexport const contentApplied = (fields: readonly string[] = []): ContentAppliedMessage => ({ type: CONTENT_APPLIED, fields: [...fields] });\n\n/** The least of `window` this needs. */\ninterface MessageTarget {\n addEventListener(type: \"message\", listener: (event: { data: unknown }) => void): void;\n removeEventListener(type: \"message\", listener: (event: { data: unknown }) => void): void;\n}\n\n/**\n * Run `handler` after every edit the editor applies to this page. Returns the function that\n * stops listening. Safe to call where there is no window (a server render): it does nothing.\n */\nexport function onContentApplied(\n handler: (message: ContentAppliedMessage) => void,\n target: MessageTarget | undefined = (globalThis as { window?: MessageTarget }).window,\n): () => void {\n if (!target) return () => {};\n const listener = (event: { data: unknown }) => {\n const data = event.data as Partial<ContentAppliedMessage> | null;\n if (!data || typeof data !== \"object\" || data.type !== CONTENT_APPLIED) return;\n handler({ type: CONTENT_APPLIED, fields: Array.isArray(data.fields) ? data.fields.filter((f): f is string => typeof f === \"string\") : [] });\n };\n target.addEventListener(\"message\", listener);\n return () => target.removeEventListener(\"message\", listener);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,QAAQ;AACd,IA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aAAa,EAAE;AAC7I,QAAM,QAAQ,KAAK,GAAG;AACtB,QAAM,cAAc,iBAAiB,KAAK;AAC1C,SAAO,MAAM;AACX,cAAU;AACV,eAAW,KAAK;AAChB,iBAAa,KAAK;AAClB,aAAS,WAAW;AACpB,gBAAY;AAAA,EACd;AACF;","names":["START"]}
|
package/dist/editable.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// src/stega.ts
|
|
2
|
+
var ZERO = "\u200B";
|
|
3
|
+
var ONE = "\u200C";
|
|
4
|
+
var START = "\u2060";
|
|
5
|
+
var END = "\u2061";
|
|
6
|
+
var FRAMES = new RegExp(`${START}([${ZERO}${ONE}]*)${END}`, "g");
|
|
7
|
+
function fromBits(bits) {
|
|
8
|
+
const bytes = [];
|
|
9
|
+
for (let i = 0; i + 8 <= bits.length; i += 8) {
|
|
10
|
+
let b = 0;
|
|
11
|
+
for (let j = 0; j < 8; j++) b = b << 1 | (bits[i + j] === ONE ? 1 : 0);
|
|
12
|
+
bytes.push(b);
|
|
13
|
+
}
|
|
14
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
15
|
+
}
|
|
16
|
+
var V2_TYPES = { e: "entry", p: "page", l: "layout", c: "component" };
|
|
17
|
+
function payloadOf(bits) {
|
|
18
|
+
try {
|
|
19
|
+
const raw = JSON.parse(fromBits(bits));
|
|
20
|
+
if (typeof raw.t === "string" && raw.t in V2_TYPES && typeof raw.id === "string" && typeof raw.f === "string") {
|
|
21
|
+
return { ws: "", type: V2_TYPES[raw.t], id: raw.id, slug: "", field: raw.f };
|
|
22
|
+
}
|
|
23
|
+
return raw;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
var TARGETS = { entry: 1, page: 1, layout: 1, component: 1 };
|
|
29
|
+
var stegaRef = (payload) => typeof payload.type === "string" && payload.type in TARGETS && typeof payload.id === "string" && typeof payload.field === "string" ? `${payload.type}:${payload.id}:${payload.field}` : null;
|
|
30
|
+
var STEGA_OPEN = `${START}${END}`;
|
|
31
|
+
function stegaClean(value) {
|
|
32
|
+
if (typeof value === "string") return value.includes(START) ? value.replace(FRAMES, "") : value;
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
const out = value.map((v) => stegaClean(v));
|
|
35
|
+
return out.some((v, i) => v !== value[i]) ? out : value;
|
|
36
|
+
}
|
|
37
|
+
if (value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
|
|
38
|
+
const entries = Object.entries(value).map(([k, v]) => [k, stegaClean(v)]);
|
|
39
|
+
return entries.some(([k, v]) => v !== value[k]) ? Object.fromEntries(entries) : value;
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function stegaFrames(text) {
|
|
44
|
+
return [...text.matchAll(FRAMES)].map((m) => ({ index: m.index, end: m.index + m[0].length, payload: m[1] ? payloadOf(m[1]) : null, open: !m[1] }));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/mark-editable.ts
|
|
48
|
+
var BOUND = ["data-bcms-field", "data-bcms-layout-field", "data-bcms-entry-field"];
|
|
49
|
+
var NOT_PROSE = { SCRIPT: "script", STYLE: "style", NOSCRIPT: "script", TEMPLATE: "script", TITLE: "head", TEXTAREA: "form" };
|
|
50
|
+
var INLINE_BREAKS = /* @__PURE__ */ new Set(["BR", "WBR"]);
|
|
51
|
+
var SVG = "http://www.w3.org/2000/svg";
|
|
52
|
+
var START2 = "\u2060";
|
|
53
|
+
var isBound = (el) => BOUND.some((name) => el.hasAttribute(name));
|
|
54
|
+
function refIn(text) {
|
|
55
|
+
const payload = stegaFrames(text).find((frame) => frame.payload)?.payload;
|
|
56
|
+
return payload ? stegaRef(payload) : null;
|
|
57
|
+
}
|
|
58
|
+
function stampOf(ref, pageId) {
|
|
59
|
+
const [target, id] = ref.split(":", 2);
|
|
60
|
+
const path = ref.slice(`${target}:${id}:`.length);
|
|
61
|
+
if (!path) return null;
|
|
62
|
+
if (target === "entry") return ["data-bcms-entry-field", ref];
|
|
63
|
+
if (target === "layout") return ["data-bcms-layout-field", ref];
|
|
64
|
+
if (target === "page" && pageId && id === pageId) return ["data-bcms-field", path];
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function markEditable(root, opts) {
|
|
68
|
+
const leaks = [];
|
|
69
|
+
const texts = [];
|
|
70
|
+
const all = [];
|
|
71
|
+
const leak = (kind, where, text) => leaks.push({ kind, ref: refIn(text), where });
|
|
72
|
+
const visit = (el, skip) => {
|
|
73
|
+
for (const attr of Array.from(el.attributes)) {
|
|
74
|
+
if (!attr.value.includes(START2)) continue;
|
|
75
|
+
leak("attribute", `${el.tagName.toLowerCase()}[${attr.name}]`, attr.value);
|
|
76
|
+
el.setAttribute(attr.name, stegaClean(attr.value));
|
|
77
|
+
}
|
|
78
|
+
const own = el.tagName === "HEAD" ? "head" : NOT_PROSE[el.tagName];
|
|
79
|
+
const next = skip ?? own ?? (el.namespaceURI === SVG ? "bound" : null) ?? (el !== root && isBound(el) ? "bound" : null);
|
|
80
|
+
for (const node of [...Array.from(el.childNodes), ...Array.from(el.content?.childNodes ?? [])]) {
|
|
81
|
+
if (node.nodeType === 1) visit(node, next);
|
|
82
|
+
else if (node.nodeType === 8 && node.data.includes(START2)) {
|
|
83
|
+
const comment = node;
|
|
84
|
+
leak("comment", el.tagName.toLowerCase(), comment.data);
|
|
85
|
+
comment.data = stegaClean(comment.data);
|
|
86
|
+
} else if (node.nodeType === 3) {
|
|
87
|
+
const text = node;
|
|
88
|
+
all.push(text);
|
|
89
|
+
if (next === null) texts.push(text);
|
|
90
|
+
else if (next !== "bound" && text.data.includes(START2)) {
|
|
91
|
+
leak(next, el.tagName.toLowerCase(), text.data);
|
|
92
|
+
text.data = stegaClean(text.data);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
visit(root, null);
|
|
98
|
+
const starts = [];
|
|
99
|
+
let full = "";
|
|
100
|
+
for (const text of texts) {
|
|
101
|
+
starts.push(full.length);
|
|
102
|
+
full += text.data;
|
|
103
|
+
}
|
|
104
|
+
const nodeAt = (offset) => {
|
|
105
|
+
let lo = 0;
|
|
106
|
+
let hi = starts.length - 1;
|
|
107
|
+
while (lo < hi) {
|
|
108
|
+
const mid = lo + hi + 1 >> 1;
|
|
109
|
+
if (starts[mid] <= offset) lo = mid;
|
|
110
|
+
else hi = mid - 1;
|
|
111
|
+
}
|
|
112
|
+
return lo;
|
|
113
|
+
};
|
|
114
|
+
let stamped = 0;
|
|
115
|
+
let unresolved = 0;
|
|
116
|
+
const opens = [];
|
|
117
|
+
for (const frame of stegaFrames(full)) {
|
|
118
|
+
if (frame.open) {
|
|
119
|
+
opens.push(frame.index);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const start = opens.pop() ?? starts[nodeAt(frame.index)];
|
|
123
|
+
if (!frame.payload) continue;
|
|
124
|
+
const first = texts[nodeAt(start)];
|
|
125
|
+
const last = texts[nodeAt(frame.end - 1)];
|
|
126
|
+
const holder = commonElement(first, last);
|
|
127
|
+
const ref = stegaRef(frame.payload);
|
|
128
|
+
const stamp = ref ? stampOf(ref, opts.pageId) : null;
|
|
129
|
+
if (!holder || holder === root || !stamp || !holdsOnly(holder, stegaClean(full.slice(start, frame.end)))) {
|
|
130
|
+
unresolved += 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
holder.setAttribute(stamp[0], stamp[1]);
|
|
134
|
+
holder.setAttribute("data-bcms-kind", "text");
|
|
135
|
+
holder.setAttribute("data-bcms-match", "stega");
|
|
136
|
+
stamped += 1;
|
|
137
|
+
}
|
|
138
|
+
if (opts.strip) {
|
|
139
|
+
for (const text of all) if (text.data.includes(START2)) text.data = stegaClean(text.data);
|
|
140
|
+
}
|
|
141
|
+
return { stamped, leaks, unresolved };
|
|
142
|
+
}
|
|
143
|
+
function commonElement(a, b) {
|
|
144
|
+
const above = /* @__PURE__ */ new Set();
|
|
145
|
+
for (let n = a.parentNode; n; n = n.parentNode) above.add(n);
|
|
146
|
+
for (let n = b.parentNode; n; n = n.parentNode) if (above.has(n) && n.nodeType === 1) return n;
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
function holdsOnly(el, value) {
|
|
150
|
+
if (stegaClean(el.textContent ?? "").trim() !== value.trim()) return false;
|
|
151
|
+
return el.childElementCount === 0 || Array.from(el.querySelectorAll("*")).every((child) => INLINE_BREAKS.has(child.tagName) || stegaClean(child.textContent ?? "").trim() !== "");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/content-applied.ts
|
|
155
|
+
var CONTENT_APPLIED = "bcms:content-applied";
|
|
156
|
+
function onContentApplied(handler, target = globalThis.window) {
|
|
157
|
+
if (!target) return () => {
|
|
158
|
+
};
|
|
159
|
+
const listener = (event) => {
|
|
160
|
+
const data = event.data;
|
|
161
|
+
if (!data || typeof data !== "object" || data.type !== CONTENT_APPLIED) return;
|
|
162
|
+
handler({ type: CONTENT_APPLIED, fields: Array.isArray(data.fields) ? data.fields.filter((f) => typeof f === "string") : [] });
|
|
163
|
+
};
|
|
164
|
+
target.addEventListener("message", listener);
|
|
165
|
+
return () => target.removeEventListener("message", listener);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/editable.ts
|
|
169
|
+
var SETTLE_MS = 50;
|
|
170
|
+
var WATCHED = { childList: true, characterData: true, subtree: true };
|
|
171
|
+
function watchEditable(root, opts = {}) {
|
|
172
|
+
if (typeof window === "undefined") return () => {
|
|
173
|
+
};
|
|
174
|
+
let stopped = false;
|
|
175
|
+
let timer;
|
|
176
|
+
const run = () => {
|
|
177
|
+
if (stopped) return;
|
|
178
|
+
observer.disconnect();
|
|
179
|
+
markEditable(root, { ...opts.pageId ? { pageId: opts.pageId } : {}, strip: false });
|
|
180
|
+
observer.observe(root, WATCHED);
|
|
181
|
+
};
|
|
182
|
+
const later = () => {
|
|
183
|
+
clearTimeout(timer);
|
|
184
|
+
timer = setTimeout(run, SETTLE_MS);
|
|
185
|
+
};
|
|
186
|
+
const observer = new MutationObserver(later);
|
|
187
|
+
const idle = typeof window.requestIdleCallback === "function" ? window.requestIdleCallback.bind(window) : (fn) => setTimeout(fn, 1);
|
|
188
|
+
const cancelIdle = typeof window.cancelIdleCallback === "function" ? window.cancelIdleCallback.bind(window) : (id) => clearTimeout(id);
|
|
189
|
+
const first = idle(run);
|
|
190
|
+
const stopApplied = onContentApplied(later);
|
|
191
|
+
return () => {
|
|
192
|
+
stopped = true;
|
|
193
|
+
cancelIdle(first);
|
|
194
|
+
clearTimeout(timer);
|
|
195
|
+
observer.disconnect();
|
|
196
|
+
stopApplied();
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
export {
|
|
200
|
+
watchEditable
|
|
201
|
+
};
|
|
202
|
+
//# sourceMappingURL=editable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/stega.ts","../src/mark-editable.ts","../src/content-applied.ts","../src/editable.ts"],"sourcesContent":["/**\n * Stega — embed invisible content-provenance into string values for visual\n * editing, then decode it in the browser overlay to open the right dashboard\n * editor. Uses zero-width characters so the payload is invisible and copy-safe.\n *\n * Scheme: `<clean text><START><bits…><END>` where each byte of the UTF-8 JSON\n * payload is 8 zero-width bits (ZERO=U+200B, ONE=U+200C), framed by START\n * (U+2060) and END (U+2061). The backend encodes draft responses; the overlay\n * decodes. Both sides MUST share this module's scheme.\n */\nconst ZERO = \"\";\nconst ONE = \"\";\nconst START = \"\";\nconst END = \"\";\nconst FRAMES = new RegExp(`${START}([${ZERO}${ONE}]*)${END}`, \"g\");\n\n/**\n * Provenance describing where a string came from, for editor deep-linking. A `stega=2` payload\n * (`{t, id, f}`) is read into this same shape: `type` from `t`, `field` from `f`, and `ws`/`slug`\n * empty, because v2 does not carry them.\n */\nexport interface StegaPayload {\n /** Workspace slug (v1 only; \"\" from a v2 payload). */\n ws: string;\n type: \"entry\" | \"page\" | \"layout\" | \"component\";\n /** Entry/page id. */\n id: string;\n /** v1 only; \"\" from a v2 payload. */\n slug: string;\n /** Field key (or block id) the value belongs to. */\n field: string;\n /** The binding kind (`text`), where the encoder knows it. */\n kind?: string;\n}\n\nfunction toBits(s: string): string {\n const bytes = new TextEncoder().encode(s);\n let out = \"\";\n for (const b of bytes) {\n for (let i = 7; i >= 0; i--) out += (b >> i) & 1 ? ONE : ZERO;\n }\n return out;\n}\n\nfunction fromBits(bits: string): string {\n const bytes: number[] = [];\n for (let i = 0; i + 8 <= bits.length; i += 8) {\n let b = 0;\n for (let j = 0; j < 8; j++) b = (b << 1) | (bits[i + j] === ONE ? 1 : 0);\n bytes.push(b);\n }\n return new TextDecoder().decode(new Uint8Array(bytes));\n}\n\n/** Append an invisible provenance payload to a string (the v1 frame). */\nexport function encodeStega(clean: string, payload: StegaPayload): string {\n return `${clean}${START}${toBits(JSON.stringify(payload))}${END}`;\n}\n\nconst V2_TYPES = { e: \"entry\", p: \"page\", l: \"layout\", c: \"component\" } as const;\n\n/**\n * A frame's bits as a payload, or null when they are not JSON. A v2 payload is read into the v1\n * shape; any other JSON is returned as it decodes (v1, or the convert helper's source-map payload).\n */\nfunction payloadOf(bits: string): StegaPayload | null {\n try {\n const raw = JSON.parse(fromBits(bits)) as Record<string, unknown>;\n if (typeof raw.t === \"string\" && raw.t in V2_TYPES && typeof raw.id === \"string\" && typeof raw.f === \"string\") {\n return { ws: \"\", type: V2_TYPES[raw.t as keyof typeof V2_TYPES], id: raw.id, slug: \"\", field: raw.f };\n }\n return raw as unknown as StegaPayload;\n } catch {\n return null;\n }\n}\n\n/**\n * The field ref a payload addresses, `<target>:<id>:<path>`, the one address grammar every writer\n * reads; null for a payload that names no document (the convert helper's source map).\n */\nconst TARGETS = { entry: 1, page: 1, layout: 1, component: 1 };\nexport const stegaRef = (payload: StegaPayload): string | null =>\n typeof payload.type === \"string\" && payload.type in TARGETS && typeof payload.id === \"string\" && typeof payload.field === \"string\"\n ? `${payload.type}:${payload.id}:${payload.field}`\n : null;\n\n/**\n * Extract `{ clean, payload }` from a stega-encoded string (v1 or v2), or null if absent. `ref` is\n * the field ref, present when the payload names a document.\n */\nexport function decodeStega(value: string): { clean: string; payload: StegaPayload; ref?: string } | null {\n for (const frame of value.matchAll(FRAMES)) {\n // An empty frame is a v2 open marker, not a payload.\n if (!frame[1]) continue;\n const payload = payloadOf(frame[1]);\n if (!payload) return null;\n const ref = stegaRef(payload);\n return { clean: stegaClean(value), payload, ...(ref ? { ref } : {}) };\n }\n return null;\n}\n\n/**\n * A value's clean text and the field ref it carries (`entry:e_1:title`, `page:pg_1:hero.title`,\n * `layout:nav:brand`), or `ref: null` when it carries none. What a template uses when it needs both\n * the string to compare and the address to bind.\n */\nexport function stegaSplit(value: string): { clean: string; ref: string | null } {\n const decoded = decodeStega(value);\n return { clean: decoded?.clean ?? stegaClean(value), ref: decoded?.ref ?? null };\n}\n\n/**\n * Where a value BEGINS in a rendered page: an empty frame. The canvas brackets every bound\n * string with it and the payload frame, so a text node can be told inside a value from text\n * that merely precedes one. @see resolveStega\n */\nexport const STEGA_OPEN = `${START}${END}`;\n\n/**\n * A value with EVERY stega frame taken out, markers included, from every string in it at any depth\n * (arrays and plain objects). The SAME value back when it holds none. What a value passes through\n * before it is compared, used as a key or attribute, saved or published.\n */\nexport function stegaClean<T>(value: T): T {\n if (typeof value === \"string\") return (value.includes(START) ? value.replace(FRAMES, \"\") : value) as T;\n if (Array.isArray(value)) {\n const out = value.map((v) => stegaClean(v));\n return (out.some((v, i) => v !== value[i]) ? out : value) as T;\n }\n if (value && typeof value === \"object\" && Object.getPrototypeOf(value) === Object.prototype) {\n const entries = Object.entries(value).map(([k, v]) => [k, stegaClean(v)] as const);\n return (entries.some(([k, v]) => v !== (value as Record<string, unknown>)[k]) ? Object.fromEntries(entries) : value) as T;\n }\n return value;\n}\n\n/**\n * Remove every stega frame. An alias of {@link stegaClean}: it used to remove only the FIRST frame,\n * which left the payload behind on a `stega=2` value (an open marker, then the payload).\n */\nexport const stripStega = stegaClean;\n\n/** Each frame in `text`, in order: where it starts and ends, and its payload (null for an open marker or bits that are not one). */\nexport function stegaFrames(text: string): Array<{ index: number; end: number; payload: StegaPayload | null; open: boolean }> {\n return [...text.matchAll(FRAMES)].map((m) => ({ index: m.index, end: m.index + m[0].length, payload: m[1] ? payloadOf(m[1]) : null, open: !m[1] }));\n}\n\n/** The least of a DOM node this needs: a real `Node` satisfies it, and so does a test's plain object. */\nexport interface StegaNode {\n textContent: string | null;\n parentNode: StegaNode | null;\n childNodes?: ArrayLike<StegaNode>;\n}\n\n/**\n * Which value does this node render? Its payload and the nearest ancestor that holds the whole\n * value, or null when the node's text belongs to none.\n *\n * By CONTENT, not by attribute: a splitting library cuts a heading into one element per\n * character, a marquee clones its track, a component redraws its children, and the element a\n * build stamped is gone or copied. The string survives all of that, in order, across however\n * many text nodes: climbing from the clicked node, the first ancestor whose text holds a value\n * (its open marker to its payload frame) that overlaps the node is the value's extent.\n * Every copy of a value resolves to the same payload.\n */\nexport function resolveStega(node: StegaNode): { payload: StegaPayload; element: StegaNode } | null {\n let offset = 0;\n const length = node.textContent?.length ?? 0;\n for (let cur = node, up = node.parentNode; up; cur = up, up = up.parentNode) {\n for (const sibling of Array.from(up.childNodes ?? [])) {\n if (sibling === cur) break;\n offset += sibling.textContent?.length ?? 0;\n }\n const text = up.textContent ?? \"\";\n // Values nest (a field inside a field), so the open markers are a stack and a payload closes the last.\n const opens: number[] = [];\n for (const frame of stegaFrames(text)) {\n if (frame.open) {\n opens.push(frame.index);\n continue;\n }\n const open = opens.pop();\n // A value overlaps the node when it ends after the node starts and begins before the node\n // ends: the node that holds a value's first characters holds its open marker too.\n if (frame.end <= offset || open === undefined || open >= offset + length) continue;\n if (!frame.payload) break;\n return { payload: frame.payload, element: up };\n }\n }\n return null;\n}\n","/**\n * markEditable — turn the stega frames in a rendered subtree into the `data-bcms-*` stamps every\n * reader already understands, so a site whose templates only RENDER CMS values is click-to-edit\n * with no per-field binding code.\n *\n * Stega is the locator, the stamps stay the contract: this adds attributes and nothing else. It\n * never creates, moves or removes an element. One pass per root:\n *\n * - Each value is found by its open marker and its payload frame, across however many text nodes\n * a splitter or a framework cut it into (the pairing `resolveStega` does, run forward).\n * - The smallest element that holds the WHOLE value, and nothing else, is stamped with the\n * attribute its field ref maps to: `data-bcms-field` (this page), `data-bcms-entry-field`,\n * `data-bcms-layout-field`, plus `data-bcms-kind=\"text\"` and `data-bcms-match=\"stega\"`.\n * - A value that shares its element with other content (an icon beside a label) is not stamped:\n * its frame stays for the text-node resolver. An element that already carries a binding keeps\n * it, and nothing under it is stamped: an explicit stamp always wins.\n * - A frame where no visible text belongs (an attribute, `<head>`, `<script>`, `<style>`, a form\n * value, a `<template>`'s content, a comment) is a leak: reported, and stripped from the DOM\n * whatever `strip` says.\n * - `strip: true` removes every frame afterwards (a release: nothing framed may be written);\n * `strip: false` keeps them for the editor's resolver (a canvas, a draft render).\n */\nimport { stegaClean, stegaFrames, stegaRef } from \"./stega.js\";\n\n/** A frame found where no rendered text belongs, which a template should have cleaned. */\nexport interface StegaLeak {\n kind: \"head\" | \"attribute\" | \"script\" | \"style\" | \"form\" | \"comment\";\n /** The field ref the leaked frame carries, when it carries one. */\n ref: string | null;\n /** `tag` for text, `tag[attribute]` for an attribute. */\n where: string;\n}\n\nexport interface MarkEditableResult {\n /** Elements stamped from a frame. */\n stamped: number;\n leaks: StegaLeak[];\n /** Values found and left unstamped: sharing their element, or a ref this page cannot stamp. */\n unresolved: number;\n}\n\n/**\n * The least of the DOM this needs, so the SDK's types never pull the DOM library into a consumer\n * that runs on a server: a real `Element` satisfies it, and so does a JSDOM one.\n */\ninterface MarkNode {\n nodeType: number;\n parentNode: MarkNode | null;\n}\ninterface MarkText extends MarkNode {\n data: string;\n}\nexport interface MarkElement extends MarkNode {\n tagName: string;\n namespaceURI: string | null;\n textContent: string | null;\n childElementCount: number;\n attributes: ArrayLike<{ name: string; value: string }>;\n childNodes: ArrayLike<MarkNode>;\n /** A `<template>`'s parsed children live here, not in `childNodes`. */\n content?: { childNodes: ArrayLike<MarkNode> };\n hasAttribute(name: string): boolean;\n setAttribute(name: string, value: string): void;\n querySelectorAll(selector: string): ArrayLike<MarkElement>;\n}\n\nconst BOUND = [\"data-bcms-field\", \"data-bcms-layout-field\", \"data-bcms-entry-field\"];\n/** Elements whose text is not rendered prose, and the leak kind a frame inside one is. */\nconst NOT_PROSE: Record<string, StegaLeak[\"kind\"]> = { SCRIPT: \"script\", STYLE: \"style\", NOSCRIPT: \"script\", TEMPLATE: \"script\", TITLE: \"head\", TEXTAREA: \"form\" };\n/** Elements a whole value may wrap around: a line break is part of the value it sits in. */\nconst INLINE_BREAKS = new Set([\"BR\", \"WBR\"]);\nconst SVG = \"http://www.w3.org/2000/svg\";\nconst START = \"\";\n\nconst isBound = (el: MarkElement) => BOUND.some((name) => el.hasAttribute(name));\n\n/** The ref of the first payload in `text`, or null. */\nfunction refIn(text: string): string | null {\n const payload = stegaFrames(text).find((frame) => frame.payload)?.payload;\n return payload ? stegaRef(payload) : null;\n}\n\n/** The attribute and value a ref stamps on this page, or null when it has no stamp here. */\nfunction stampOf(ref: string, pageId: string | undefined): [string, string] | null {\n const [target, id] = ref.split(\":\", 2);\n const path = ref.slice(`${target}:${id}:`.length);\n if (!path) return null;\n if (target === \"entry\") return [\"data-bcms-entry-field\", ref];\n if (target === \"layout\") return [\"data-bcms-layout-field\", ref];\n // Another page's value has no in-page address; a component default is written to its definition.\n if (target === \"page\" && pageId && id === pageId) return [\"data-bcms-field\", path];\n return null;\n}\n\nexport function markEditable(root: MarkElement, opts: { pageId?: string; strip: boolean }): MarkEditableResult {\n const leaks: StegaLeak[] = [];\n const texts: MarkText[] = [];\n const all: MarkText[] = [];\n\n const leak = (kind: StegaLeak[\"kind\"], where: string, text: string) => leaks.push({ kind, ref: refIn(text), where });\n // One walk: leaks reported and stripped, every text node kept for the final strip, and the\n // text nodes a value may be read from kept in document order.\n const visit = (el: MarkElement, skip: StegaLeak[\"kind\"] | \"bound\" | null) => {\n for (const attr of Array.from(el.attributes)) {\n if (!attr.value.includes(START)) continue;\n leak(\"attribute\", `${el.tagName.toLowerCase()}[${attr.name}]`, attr.value);\n el.setAttribute(attr.name, stegaClean(attr.value));\n }\n const own = el.tagName === \"HEAD\" ? \"head\" : NOT_PROSE[el.tagName];\n const next = skip ?? own ?? (el.namespaceURI === SVG ? \"bound\" : null) ?? (el !== root && isBound(el) ? \"bound\" : null);\n for (const node of [...Array.from(el.childNodes), ...Array.from(el.content?.childNodes ?? [])]) {\n if (node.nodeType === 1) visit(node as MarkElement, next);\n else if (node.nodeType === 8 && (node as MarkText).data.includes(START)) {\n const comment = node as MarkText;\n leak(\"comment\", el.tagName.toLowerCase(), comment.data);\n comment.data = stegaClean(comment.data);\n } else if (node.nodeType === 3) {\n const text = node as MarkText;\n all.push(text);\n if (next === null) texts.push(text);\n else if (next !== \"bound\" && text.data.includes(START)) {\n leak(next, el.tagName.toLowerCase(), text.data);\n text.data = stegaClean(text.data);\n }\n }\n }\n };\n visit(root, null);\n\n // The value pass runs over the text the reader sees, in order: one string, each node's offset in it.\n const starts: number[] = [];\n let full = \"\";\n for (const text of texts) {\n starts.push(full.length);\n full += text.data;\n }\n const nodeAt = (offset: number) => {\n let lo = 0;\n let hi = starts.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (starts[mid]! <= offset) lo = mid;\n else hi = mid - 1;\n }\n return lo;\n };\n\n let stamped = 0;\n let unresolved = 0;\n const opens: number[] = [];\n for (const frame of stegaFrames(full)) {\n if (frame.open) {\n opens.push(frame.index);\n continue;\n }\n // A v1 frame has no open marker: its value is the text node the frame closes.\n const start = opens.pop() ?? starts[nodeAt(frame.index)]!;\n if (!frame.payload) continue;\n const first = texts[nodeAt(start)]!;\n const last = texts[nodeAt(frame.end - 1)]!;\n const holder = commonElement(first, last);\n const ref = stegaRef(frame.payload);\n const stamp = ref ? stampOf(ref, opts.pageId) : null;\n if (!holder || holder === root || !stamp || !holdsOnly(holder, stegaClean(full.slice(start, frame.end)))) {\n unresolved += 1;\n continue;\n }\n holder.setAttribute(stamp[0], stamp[1]);\n holder.setAttribute(\"data-bcms-kind\", \"text\");\n holder.setAttribute(\"data-bcms-match\", \"stega\");\n stamped += 1;\n }\n\n if (opts.strip) for (const text of all) if (text.data.includes(START)) text.data = stegaClean(text.data);\n return { stamped, leaks, unresolved };\n}\n\n/** The nearest element that contains both nodes. */\nfunction commonElement(a: MarkNode, b: MarkNode): MarkElement | null {\n const above = new Set<MarkNode>();\n for (let n: MarkNode | null = a.parentNode; n; n = n.parentNode) above.add(n);\n for (let n: MarkNode | null = b.parentNode; n; n = n.parentNode) if (above.has(n) && n.nodeType === 1) return n as MarkElement;\n return null;\n}\n\n/**\n * Whether `el` renders exactly `value` and nothing beside it: the same visible text, and no child\n * element without text of its own (an icon, an image) sharing it. A line break inside the value is\n * part of it.\n */\nfunction holdsOnly(el: MarkElement, value: string): boolean {\n if (stegaClean(el.textContent ?? \"\").trim() !== value.trim()) return false;\n return el.childElementCount === 0 || Array.from(el.querySelectorAll(\"*\")).every((child) => INLINE_BREAKS.has(child.tagName) || stegaClean(child.textContent ?? \"\").trim() !== \"\");\n}\n","/**\n * `bcms:content-applied` — what the visual editor tells a page after it has applied an edit to\n * the page's DOM.\n *\n * An edit changes how tall a heading is. Everything on the page that measured the layout once\n * (ScrollTrigger's start and end positions, Lenis's scroll limit, a carousel's slide widths, a\n * text splitter's lines) is now wrong, and only the page's own code can measure again. So the\n * editor posts one message to the frame's window after each applied edit, and the site listens:\n *\n * onContentApplied(() => ScrollTrigger.refresh());\n *\n * A published page receives no such message: nothing there posts it, and the listener is inert.\n */\n\n/** The `type` of the message. */\nexport const CONTENT_APPLIED = \"bcms:content-applied\";\n\nexport interface ContentAppliedMessage {\n type: typeof CONTENT_APPLIED;\n /** The field addresses whose rendering changed; empty when the editor does not say. */\n fields: string[];\n}\n\n/** The message the editor posts: `frame.contentWindow.postMessage(contentApplied(fields), origin)`. */\nexport const contentApplied = (fields: readonly string[] = []): ContentAppliedMessage => ({ type: CONTENT_APPLIED, fields: [...fields] });\n\n/** The least of `window` this needs. */\ninterface MessageTarget {\n addEventListener(type: \"message\", listener: (event: { data: unknown }) => void): void;\n removeEventListener(type: \"message\", listener: (event: { data: unknown }) => void): void;\n}\n\n/**\n * Run `handler` after every edit the editor applies to this page. Returns the function that\n * stops listening. Safe to call where there is no window (a server render): it does nothing.\n */\nexport function onContentApplied(\n handler: (message: ContentAppliedMessage) => void,\n target: MessageTarget | undefined = (globalThis as { window?: MessageTarget }).window,\n): () => void {\n if (!target) return () => {};\n const listener = (event: { data: unknown }) => {\n const data = event.data as Partial<ContentAppliedMessage> | null;\n if (!data || typeof data !== \"object\" || data.type !== CONTENT_APPLIED) return;\n handler({ type: CONTENT_APPLIED, fields: Array.isArray(data.fields) ? data.fields.filter((f): f is string => typeof f === \"string\") : [] });\n };\n target.addEventListener(\"message\", listener);\n return () => target.removeEventListener(\"message\", listener);\n}\n","/// <reference lib=\"dom\" />\n/**\n * watchEditable — the browser half of every adapter's `BcmsEditable`: turn the stega frames a\n * draft render carries into click-to-edit stamps, and keep doing it while the page changes.\n *\n * One function, so the React component, the SvelteKit action and the Nuxt directive cannot drift.\n * Each imports this module DYNAMICALLY behind its own draft check, so a published page neither\n * downloads nor runs any of it.\n *\n * - First pass after hydration, when the browser is idle: the stamps are attributes added to\n * the hydrated DOM, never server markup, so nothing can mismatch.\n * - Again, debounced, when the scope's children or text change (a client fetch, a route change\n * inside the scope) and after each edit the editor applies (`bcms:content-applied`).\n * - `strip: false`: the frames stay, so the editor's resolver still finds a value that a splitter\n * cut into many nodes. markEditable only adds attributes; a frame where no text belongs (an\n * attribute, a script) is still taken out, as it always is.\n *\n * Returns the function that stops watching.\n */\nimport { markEditable, type MarkElement } from \"./mark-editable.js\";\nimport { onContentApplied } from \"./content-applied.js\";\n\n/** How long the page must be quiet before a change is stamped again. */\nconst SETTLE_MS = 50;\n/** Children and text only: the stamps this adds are attributes, so they never wake it again. */\nconst WATCHED: MutationObserverInit = { childList: true, characterData: true, subtree: true };\n\nexport function watchEditable(root: Element, opts: { pageId?: string } = {}): () => void {\n if (typeof window === \"undefined\") return () => {};\n let stopped = false;\n let timer: ReturnType<typeof setTimeout> | undefined;\n const run = () => {\n if (stopped) return;\n // A leak markEditable takes out of a text node is a change of its own: not watched while it runs.\n observer.disconnect();\n markEditable(root as unknown as MarkElement, { ...(opts.pageId ? { pageId: opts.pageId } : {}), strip: false });\n observer.observe(root, WATCHED);\n };\n const later = () => {\n clearTimeout(timer);\n timer = setTimeout(run, SETTLE_MS);\n };\n const observer = new MutationObserver(later);\n const idle = typeof window.requestIdleCallback === \"function\" ? window.requestIdleCallback.bind(window) : (fn: () => void) => setTimeout(fn, 1) as unknown as number;\n const cancelIdle = typeof window.cancelIdleCallback === \"function\" ? window.cancelIdleCallback.bind(window) : (id: number) => clearTimeout(id);\n const first = idle(run);\n const stopApplied = onContentApplied(later);\n return () => {\n stopped = true;\n cancelIdle(first);\n clearTimeout(timer);\n observer.disconnect();\n stopApplied();\n };\n}\n"],"mappings":";AAUA,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,QAAQ;AACd,IAAM,MAAM;AACZ,IAAM,SAAS,IAAI,OAAO,GAAG,KAAK,KAAK,IAAI,GAAG,GAAG,MAAM,GAAG,IAAI,GAAG;AA8BjE,SAAS,SAAS,MAAsB;AACtC,QAAM,QAAkB,CAAC;AACzB,WAAS,IAAI,GAAG,IAAI,KAAK,KAAK,QAAQ,KAAK,GAAG;AAC5C,QAAI,IAAI;AACR,aAAS,IAAI,GAAG,IAAI,GAAG,IAAK,KAAK,KAAK,KAAM,KAAK,IAAI,CAAC,MAAM,MAAM,IAAI;AACtE,UAAM,KAAK,CAAC;AAAA,EACd;AACA,SAAO,IAAI,YAAY,EAAE,OAAO,IAAI,WAAW,KAAK,CAAC;AACvD;AAOA,IAAM,WAAW,EAAE,GAAG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