@particle-academy/fancy-cms-ui 0.3.1 → 0.5.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/{chunk-6Q7DKNDZ.js → chunk-5VNXIAHG.js} +10 -54
- package/dist/chunk-5VNXIAHG.js.map +1 -0
- package/dist/{chunk-GOXVGEKU.js → chunk-FDCP3LVR.js} +78 -49
- package/dist/chunk-FDCP3LVR.js.map +1 -0
- package/dist/{chunk-QYNWSECG.js → chunk-Z2X7B6YL.js} +3 -3
- package/dist/{chunk-QYNWSECG.js.map → chunk-Z2X7B6YL.js.map} +1 -1
- package/dist/editor.cjs +85 -111
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.d.cts +3 -2
- package/dist/editor.d.ts +3 -2
- package/dist/editor.js +22 -23
- package/dist/editor.js.map +1 -1
- package/dist/index.cjs +87 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -35
- package/dist/index.d.ts +23 -35
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +46 -12
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +5 -4
- package/dist/react.d.ts +5 -4
- package/dist/react.js +2 -2
- package/dist/{registry-D5y5IgCR.d.cts → registry-CvzbUd5E.d.cts} +89 -12
- package/dist/{registry-D5y5IgCR.d.ts → registry-CvzbUd5E.d.ts} +89 -12
- package/dist/{useEditor-BQtAHLHl.d.cts → useEditor-BGKnLQuK.d.ts} +13 -3
- package/dist/{useEditor-CpX-LbfH.d.ts → useEditor-Dr_Gg7gu.d.cts} +13 -3
- package/package.json +14 -8
- package/dist/chunk-6Q7DKNDZ.js.map +0 -1
- package/dist/chunk-GOXVGEKU.js.map +0 -1
|
@@ -1,52 +1,10 @@
|
|
|
1
|
-
import { reduce, CmsPage, childrenOf, emptyDoc } from './chunk-
|
|
1
|
+
import { migrateDoc, reduce, CmsPage, rootIds, childrenOf, lastRootId, emptyDoc } from './chunk-FDCP3LVR.js';
|
|
2
2
|
import { useReducer, useCallback, useMemo, useRef, useState, useLayoutEffect, Fragment, useId, useEffect } from 'react';
|
|
3
3
|
import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
4
|
+
import { fractionalKey } from '@particle-academy/fancy-doc-commons';
|
|
4
5
|
|
|
5
|
-
// src/document/fractional.ts
|
|
6
|
-
var BASE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
7
|
-
var RADIX = BASE.length;
|
|
8
|
-
var MID = Math.floor(RADIX / 2);
|
|
9
|
-
function val(c) {
|
|
10
|
-
const i = BASE.indexOf(c);
|
|
11
|
-
return i < 0 ? 0 : i;
|
|
12
|
-
}
|
|
13
|
-
function keyBetween(a, b) {
|
|
14
|
-
if (a === null) a = "";
|
|
15
|
-
if (b === null) {
|
|
16
|
-
return a + BASE[MID];
|
|
17
|
-
}
|
|
18
|
-
if (a >= b) {
|
|
19
|
-
throw new Error(`keyBetween: lower bound "${a}" is not below upper bound "${b}"`);
|
|
20
|
-
}
|
|
21
|
-
let result = "";
|
|
22
|
-
let i = 0;
|
|
23
|
-
for (; ; ) {
|
|
24
|
-
const ca = i < a.length ? val(a[i]) : 0;
|
|
25
|
-
const cb = i < b.length ? val(b[i]) : RADIX;
|
|
26
|
-
if (cb - ca > 1) {
|
|
27
|
-
result += BASE[ca + Math.floor((cb - ca) / 2)];
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
if (ca === cb) {
|
|
31
|
-
result += BASE[ca];
|
|
32
|
-
i++;
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
result += BASE[ca];
|
|
36
|
-
i++;
|
|
37
|
-
for (; ; ) {
|
|
38
|
-
const da = i < a.length ? val(a[i]) : 0;
|
|
39
|
-
if (RADIX - da > 1) {
|
|
40
|
-
result += BASE[da + Math.floor((RADIX - da) / 2)];
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
result += BASE[da];
|
|
44
|
-
i++;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
6
|
function initEditor(doc) {
|
|
49
|
-
return { doc, past: [], future: [], selection: null };
|
|
7
|
+
return { doc: migrateDoc(doc), past: [], future: [], selection: null };
|
|
50
8
|
}
|
|
51
9
|
function editorReduce(state, action) {
|
|
52
10
|
switch (action.type) {
|
|
@@ -204,7 +162,7 @@ function isAncestorOrSelf(doc, id, maybeAncestor) {
|
|
|
204
162
|
}
|
|
205
163
|
function LayersPanel({ doc, selection, onSelect, onMove }) {
|
|
206
164
|
const [overId, setOverId] = useState(null);
|
|
207
|
-
return /* @__PURE__ */ jsx("div", { style: { overflow: "auto", padding: 8, fontSize: 13, fontFamily: "system-ui, sans-serif" }, children: doc.
|
|
165
|
+
return /* @__PURE__ */ jsx("div", { style: { overflow: "auto", padding: 8, fontSize: 13, fontFamily: "system-ui, sans-serif" }, children: rootIds(doc).map((id) => /* @__PURE__ */ jsx(LayerRow, { doc, id, depth: 0, selection, onSelect, onMove, overId, setOverId }, id)) });
|
|
208
166
|
}
|
|
209
167
|
function LayerRow({ doc, id, depth, selection, onSelect, onMove, overId, setOverId }) {
|
|
210
168
|
const node = doc.nodes[id];
|
|
@@ -221,7 +179,7 @@ function LayerRow({ doc, id, depth, selection, onSelect, onMove, overId, setOver
|
|
|
221
179
|
const siblings = childrenOf(doc, node.parent);
|
|
222
180
|
const idx = siblings.findIndex((n) => n.id === id);
|
|
223
181
|
const next = siblings[idx + 1];
|
|
224
|
-
onMove(dragId, node.parent,
|
|
182
|
+
onMove(dragId, node.parent, fractionalKey(node.order, next ? next.order : null));
|
|
225
183
|
};
|
|
226
184
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
227
185
|
/* @__PURE__ */ jsxs(
|
|
@@ -389,8 +347,6 @@ function Inspector({ doc, selection, apply }) {
|
|
|
389
347
|
)
|
|
390
348
|
] });
|
|
391
349
|
}
|
|
392
|
-
|
|
393
|
-
// src/editor/insert.ts
|
|
394
350
|
var CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
395
351
|
"section",
|
|
396
352
|
"frame",
|
|
@@ -438,12 +394,12 @@ function resolveInsertParent(doc, selectedId) {
|
|
|
438
394
|
if (selected) {
|
|
439
395
|
return CONTAINER_TYPES.has(selected.type) ? selected.id : selected.parent;
|
|
440
396
|
}
|
|
441
|
-
return doc
|
|
397
|
+
return lastRootId(doc);
|
|
442
398
|
}
|
|
443
399
|
function buildInsertOp(doc, kind, selectedId, targetId) {
|
|
444
400
|
const parent = targetId !== void 0 ? targetId && doc.nodes[targetId] ? CONTAINER_TYPES.has(doc.nodes[targetId].type) ? targetId : doc.nodes[targetId].parent : null : resolveInsertParent(doc, selectedId);
|
|
445
401
|
const siblings = childrenOf(doc, parent);
|
|
446
|
-
const order =
|
|
402
|
+
const order = fractionalKey(siblings.length ? siblings[siblings.length - 1].order : null, null);
|
|
447
403
|
const id = `n${doc.seq + 1}-${Math.floor(performance.now())}`;
|
|
448
404
|
const def = ADD_DEFAULTS[kind];
|
|
449
405
|
return {
|
|
@@ -617,6 +573,6 @@ var DARK_VARS = "color-scheme:dark;--fcms-bg:#0b0f19;--fcms-fg:#e5e7eb;--fcms-mu
|
|
|
617
573
|
var LIGHT_VARS = "color-scheme:light;--fcms-bg:#ffffff;--fcms-fg:#0f172a;--fcms-muted:#64748b;--fcms-border:#e2e8f0;--fcms-canvas:#f8fafc;--fcms-input-bg:#ffffff;--fcms-row-fg:#334155;--fcms-sel-bg:#ede9fe;--fcms-sel-fg:#5b21b6;--fcms-drop:#db2777;--fcms-danger:#dc2626;";
|
|
618
574
|
var CHROME_CSS = `.fancy-cms-editor{--fcms-accent:#8b5cf6;${LIGHT_VARS}}@media (prefers-color-scheme:dark){.fancy-cms-editor{${DARK_VARS}}}:where(.light,[data-theme="light"]) .fancy-cms-editor{${LIGHT_VARS}}:where(.dark,[data-theme="dark"]) .fancy-cms-editor{${DARK_VARS}}`;
|
|
619
575
|
|
|
620
|
-
export { ADD_DEFAULTS, ADD_MENU, CONTAINER_TYPES, Canvas, Editor, Inspector, LayersPanel, buildInsertOp, editorReduce, initEditor,
|
|
621
|
-
//# sourceMappingURL=chunk-
|
|
622
|
-
//# sourceMappingURL=chunk-
|
|
576
|
+
export { ADD_DEFAULTS, ADD_MENU, CONTAINER_TYPES, Canvas, Editor, Inspector, LayersPanel, buildInsertOp, editorReduce, initEditor, resolveInsertParent, useEditor, useLatestRef };
|
|
577
|
+
//# sourceMappingURL=chunk-5VNXIAHG.js.map
|
|
578
|
+
//# sourceMappingURL=chunk-5VNXIAHG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/editor/state.ts","../src/editor/useEditor.ts","../src/editor/Canvas.tsx","../src/editor/LayersPanel.tsx","../src/editor/Inspector.tsx","../src/editor/insert.ts","../src/editor/useLatestRef.ts","../src/editor/Editor.tsx"],"names":["useState","jsx","keyBetween","jsxs","Fragment","useRef","useMemo","useEffect"],"mappings":";;;;;AAqCO,SAAS,WAAW,GAAA,EAA2C;AACpE,EAAA,OAAO,EAAE,GAAA,EAAK,UAAA,CAAW,GAAG,CAAA,EAAG,IAAA,EAAM,EAAC,EAAG,MAAA,EAAQ,EAAC,EAAG,SAAA,EAAW,IAAA,EAAK;AACvE;AAEO,SAAS,YAAA,CAAa,OAAoB,MAAA,EAAmC;AAClF,EAAA,QAAQ,OAAO,IAAA;AAAM,IACnB,KAAK,OAAA,EAAS;AACZ,MAAA,MAAM,IAAA,GAAO,MAAA,CAAO,KAAA,CAAM,GAAA,EAAK,OAAO,EAAE,CAAA;AACxC,MAAA,IAAI,IAAA,KAAS,KAAA,CAAM,GAAA,EAAK,OAAO,KAAA;AAC/B,MAAA,OAAO;AAAA,QACL,GAAG,KAAA;AAAA,QACH,GAAA,EAAK,IAAA;AAAA,QACL,IAAA,EAAM,CAAC,GAAG,KAAA,CAAM,IAAA,EAAM,MAAM,GAAG,CAAA,CA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AA,UAdD,IAAA,CAAK;AAAA,SAgBb;AAAA;AAAA;AACH,GAAA,EAEJ,CAAA;AAEJ;AASA,IAAM,SAAA,GACJ,mSAAA;AAIF,IAAM,UAAA,GACJ,8PAAA;AAGF,IAAM,UAAA,GACJ,2CAA2C,UAAU,CAAA,sDAAA,EACG,SAAS,CAAA,wDAAA,EACR,UAAU,wDACZ,SAAS,CAAA,CAAA,CAAA","file":"chunk-5VNXIAHG.js","sourcesContent":["/**\n * Editor state engine — pure and framework-agnostic so it's unit-testable.\n * `useEditor` wraps this with `useReducer`. Undo/redo uses document snapshots\n * (simple + robust); the op-level `invert` in the spine is for collab/op-stream\n * undo.\n */\nimport { migrateDoc, type LegacyPageDoc } from \"../document/migrate\";\nimport type { PageDoc } from \"../document/types\";\nimport type { PageOp } from \"../document/ops\";\nimport { reduce } from \"../document/reduce\";\n\nexport interface EditorState {\n doc: PageDoc;\n past: PageDoc[];\n future: PageDoc[];\n selection: string | null;\n}\n\nexport type EditorAction =\n | { type: \"apply\"; op: PageOp }\n | { type: \"undo\" }\n | { type: \"redo\" }\n | { type: \"select\"; id: string | null }\n | { type: \"replace\"; doc: PageDoc };\n\nconst HISTORY_LIMIT = 100;\n\n/**\n * Seed the editor from a document.\n *\n * Migrates a pre-`sections[]` document on the way in. Doing it here rather than\n * leaving it to the host is deliberate: the legacy failure is SILENT — a page\n * whose sections were ever reordered would simply open in the wrong order, with\n * nothing thrown and nothing logged — so a host that has not heard of the\n * migration is exactly the one that needs it. Already-migrated documents pass\n * through by reference.\n */\nexport function initEditor(doc: LegacyPageDoc | PageDoc): EditorState {\n return { doc: migrateDoc(doc), past: [], future: [], selection: null };\n}\n\nexport function editorReduce(state: EditorState, action: EditorAction): EditorState {\n switch (action.type) {\n case \"apply\": {\n const next = reduce(state.doc, action.op);\n if (next === state.doc) return state; // invalid op → no-op, no history entry\n return {\n ...state,\n doc: next,\n past: [...state.past, state.doc].slice(-HISTORY_LIMIT),\n future: [],\n };\n }\n case \"undo\": {\n if (state.past.length === 0) return state;\n const prev = state.past[state.past.length - 1]!;\n return {\n ...state,\n doc: prev,\n past: state.past.slice(0, -1),\n future: [state.doc, ...state.future],\n };\n }\n case \"redo\": {\n if (state.future.length === 0) return state;\n const next = state.future[0]!;\n return {\n ...state,\n doc: next,\n past: [...state.past, state.doc],\n future: state.future.slice(1),\n };\n }\n case \"select\":\n return state.selection === action.id ? state : { ...state, selection: action.id };\n case \"replace\":\n return state.doc === action.doc ? state : { ...state, doc: action.doc, future: [] };\n default:\n return state;\n }\n}\n","import { useCallback, useMemo, useReducer } from \"react\";\nimport type { PageDoc } from \"../document/types\";\nimport type { PageOp } from \"../document/ops\";\nimport { editorReduce, initEditor, type EditorState } from \"./state\";\n\nexport interface EditorApi {\n state: EditorState;\n /** Dispatch a mutation through the op-spine (records an undo snapshot). */\n apply: (op: PageOp) => void;\n undo: () => void;\n redo: () => void;\n select: (id: string | null) => void;\n /** Replace the document wholesale (e.g. a controlled `value` change). */\n replace: (doc: PageDoc) => void;\n canUndo: boolean;\n canRedo: boolean;\n}\n\nexport function useEditor(initialDoc: PageDoc): EditorApi {\n const [state, dispatch] = useReducer(editorReduce, initialDoc, initEditor);\n const apply = useCallback((op: PageOp) => dispatch({ type: \"apply\", op }), []);\n const undo = useCallback(() => dispatch({ type: \"undo\" }), []);\n const redo = useCallback(() => dispatch({ type: \"redo\" }), []);\n const select = useCallback((id: string | null) => dispatch({ type: \"select\", id }), []);\n const replace = useCallback((doc: PageDoc) => dispatch({ type: \"replace\", doc }), []);\n\n return useMemo(\n () => ({\n state,\n apply,\n undo,\n redo,\n select,\n replace,\n canUndo: state.past.length > 0,\n canRedo: state.future.length > 0,\n }),\n [state, apply, undo, redo, select, replace],\n );\n}\n","import {\n useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n type ReactElement,\n} from \"react\";\nimport type { PageDoc } from \"../document/types\";\nimport type { PageOp } from \"../document/ops\";\nimport type { DataContext, ElementRegistry } from \"../react/registry\";\nimport { CmsPage } from \"../react/CmsPage\";\n\nexport interface CanvasProps {\n doc: PageDoc;\n selection: string | null;\n onSelect: (id: string | null) => void;\n apply: (op: PageOp) => void;\n /** Custom element registry so custom node types render on the canvas (not a blank placeholder). */\n registry?: ElementRegistry;\n /** Data context for `{ $bind }` props + repeaters previewed on the canvas. */\n data?: DataContext;\n}\n\ninterface Box {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\n/**\n * The edit surface: renders the live page and overlays a selection box. Click to\n * select; drag the box to move (px constraints). Phase 1 cut: free-parent\n * move + resize handles, stack/grid reordering, and snapping come next.\n */\nexport function Canvas({ doc, selection, onSelect, apply, registry, data }: CanvasProps): ReactElement {\n const ref = useRef<HTMLDivElement>(null);\n const [box, setBox] = useState<Box | null>(null);\n const drag = useRef<{ x: number; y: number; left: number; top: number } | null>(null);\n\n useLayoutEffect(() => {\n const root = ref.current;\n if (!root || !selection) {\n setBox(null);\n return;\n }\n const el = root.querySelector(`[data-cms=\"${cssEscape(selection)}\"]`);\n if (!el) {\n setBox(null);\n return;\n }\n const r = el.getBoundingClientRect();\n const rootRect = root.getBoundingClientRect();\n setBox({\n x: r.left - rootRect.left + root.scrollLeft,\n y: r.top - rootRect.top + root.scrollTop,\n w: r.width,\n h: r.height,\n });\n }, [selection, doc]);\n\n const handleClick = (e: ReactMouseEvent<HTMLDivElement>) => {\n const target = (e.target as HTMLElement).closest(\"[data-cms]\");\n onSelect(target ? target.getAttribute(\"data-cms\") : null);\n };\n\n const handlePointerDown = (e: ReactPointerEvent<HTMLDivElement>) => {\n if (!selection) return;\n const c = doc.nodes[selection]?.constraints?.base;\n const left = c && c.left && typeof c.left === \"object\" ? c.left.value : 0;\n const top = c && c.top && typeof c.top === \"object\" ? c.top.value : 0;\n drag.current = { x: e.clientX, y: e.clientY, left, top };\n e.currentTarget.setPointerCapture(e.pointerId);\n e.stopPropagation();\n };\n\n const handlePointerMove = (e: ReactPointerEvent<HTMLDivElement>) => {\n const d = drag.current;\n if (!d || !selection) return;\n apply({\n t: \"set_constraints\",\n id: selection,\n breakpoint: \"base\",\n patch: {\n left: { value: Math.round(d.left + (e.clientX - d.x)), unit: \"px\" },\n top: { value: Math.round(d.top + (e.clientY - d.y)), unit: \"px\" },\n },\n });\n };\n\n const handlePointerUp = () => {\n drag.current = null;\n };\n\n const surface: CSSProperties = {\n position: \"relative\",\n overflow: \"auto\",\n height: \"100%\",\n background: \"var(--fcms-canvas)\",\n };\n const overlay: CSSProperties = box\n ? {\n position: \"absolute\",\n left: box.x,\n top: box.y,\n width: box.w,\n height: box.h,\n outline: \"2px solid var(--fcms-accent, #8b5cf6)\",\n outlineOffset: -1,\n cursor: \"move\",\n touchAction: \"none\",\n }\n : { display: \"none\" };\n\n return (\n <div ref={ref} onClick={handleClick} style={surface}>\n <CmsPage doc={doc} registry={registry} data={data} />\n <div\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerUp={handlePointerUp}\n style={overlay}\n />\n </div>\n );\n}\n\nfunction cssEscape(value: string): string {\n return value.replace(/[\"\\\\]/g, \"\\\\$&\");\n}\n","import { Fragment, useState, type DragEvent as ReactDragEvent, type ReactElement } from \"react\";\nimport type { NodeId, PageDoc } from \"../document/types\";\nimport { childrenOf, rootIds } from \"../document/reduce\";\nimport { fractionalKey as keyBetween } from \"@particle-academy/fancy-doc-commons\";\n\nexport interface LayersPanelProps {\n doc: PageDoc;\n selection: string | null;\n onSelect: (id: string) => void;\n /** Reparent/reorder a node (drag-to-reorder). Omit to disable dragging. */\n onMove?: (id: NodeId, parent: NodeId | null, order: string) => void;\n}\n\nconst MIME = \"application/x-cms-node\";\n\n/** True when `maybeAncestor` is `id` itself or one of its ancestors. */\nfunction isAncestorOrSelf(doc: PageDoc, id: string, maybeAncestor: string): boolean {\n for (let cur: string | null = id; cur; cur = doc.nodes[cur]?.parent ?? null) {\n if (cur === maybeAncestor) return true;\n }\n return false;\n}\n\n/** The section/layer tree. Click a row to select; drag a row onto another to reorder. */\nexport function LayersPanel({ doc, selection, onSelect, onMove }: LayersPanelProps): ReactElement {\n const [overId, setOverId] = useState<string | null>(null);\n\n return (\n <div style={{ overflow: \"auto\", padding: 8, fontSize: 13, fontFamily: \"system-ui, sans-serif\" }}>\n {rootIds(doc).map((id: string) => (\n <LayerRow key={id} doc={doc} id={id} depth={0} selection={selection} onSelect={onSelect} onMove={onMove} overId={overId} setOverId={setOverId} />\n ))}\n </div>\n );\n}\n\ninterface LayerRowProps {\n doc: PageDoc;\n id: string;\n depth: number;\n selection: string | null;\n onSelect: (id: string) => void;\n onMove?: (id: NodeId, parent: NodeId | null, order: string) => void;\n overId: string | null;\n setOverId: (id: string | null) => void;\n}\n\nfunction LayerRow({ doc, id, depth, selection, onSelect, onMove, overId, setOverId }: LayerRowProps): ReactElement | null {\n const node = doc.nodes[id];\n if (!node) return null;\n const selected = selection === id;\n const draggable = Boolean(onMove);\n\n const drop = (e: ReactDragEvent) => {\n e.preventDefault();\n e.stopPropagation();\n setOverId(null);\n if (!onMove) return;\n const dragId = e.dataTransfer.getData(MIME);\n // Reject no-op + any move that would drop a node into its own subtree.\n if (!dragId || dragId === id || isAncestorOrSelf(doc, id, dragId)) return;\n // Place the dragged node immediately after this row, among this row's siblings.\n const siblings = childrenOf(doc, node.parent);\n const idx = siblings.findIndex((n) => n.id === id);\n const next = siblings[idx + 1];\n onMove(dragId, node.parent, keyBetween(node.order, next ? next.order : null));\n };\n\n return (\n <Fragment>\n <button\n type=\"button\"\n draggable={draggable}\n onClick={() => onSelect(id)}\n onDragStart={(e) => {\n e.dataTransfer.setData(MIME, id);\n e.dataTransfer.effectAllowed = \"move\";\n }}\n onDragOver={(e) => {\n if (!onMove) return;\n e.preventDefault();\n e.dataTransfer.dropEffect = \"move\";\n if (overId !== id) setOverId(id);\n }}\n onDragLeave={() => overId === id && setOverId(null)}\n onDrop={drop}\n style={{\n display: \"block\",\n width: \"100%\",\n textAlign: \"left\",\n border: \"none\",\n borderRadius: 6,\n cursor: draggable ? \"grab\" : \"pointer\",\n padding: \"4px 8px\",\n paddingLeft: 8 + depth * 14,\n background: selected ? \"var(--fcms-sel-bg)\" : \"transparent\",\n color: selected ? \"var(--fcms-sel-fg)\" : \"var(--fcms-row-fg)\",\n font: \"inherit\",\n boxShadow: overId === id ? \"inset 0 -2px 0 0 var(--fcms-accent, #8b5cf6)\" : \"none\",\n }}\n >\n <span style={{ opacity: 0.6 }}>{node.type}</span> · {id}\n </button>\n {childrenOf(doc, id).map((child) => (\n <LayerRow key={child.id} doc={doc} id={child.id} depth={depth + 1} selection={selection} onSelect={onSelect} onMove={onMove} overId={overId} setOverId={setOverId} />\n ))}\n </Fragment>\n );\n}\n","import { useId, type CSSProperties, type ReactElement } from \"react\";\nimport type { PageDoc, StyleProps } from \"../document/types\";\nimport type { PageOp } from \"../document/ops\";\n\nexport interface InspectorProps {\n doc: PageDoc;\n selection: string | null;\n apply: (op: PageOp) => void;\n}\n\nconst label: CSSProperties = {\n display: \"block\",\n fontSize: 11,\n textTransform: \"uppercase\",\n letterSpacing: \"0.04em\",\n color: \"var(--fcms-muted)\",\n margin: \"10px 0 4px\",\n};\nconst input: CSSProperties = {\n width: \"100%\",\n boxSizing: \"border-box\",\n padding: \"6px 8px\",\n borderRadius: 6,\n border: \"1px solid var(--fcms-border)\",\n background: \"var(--fcms-input-bg)\",\n color: \"var(--fcms-fg)\",\n font: \"inherit\",\n fontSize: 13,\n};\n\n/**\n * Contextual property editor for the selected node. Every change is one op.\n *\n * Each `<label>` here is a SIBLING of its control rather than wrapping it, so\n * none of them were associated: clicking a label focused nothing and a screen\n * reader announced the panel as unlabelled boxes. (`NodeInspector` wraps its\n * controls, which associates them implicitly — these did not.)\n *\n * `htmlFor`/`id` fixes that, and `data-cms-field` gives each control the stable\n * handle the Human+ contract asks for so an agent addresses a field by name\n * instead of guessing at the DOM.\n */\nexport function Inspector({ doc, selection, apply }: InspectorProps): ReactElement {\n // Before the early return — every hook must run on every render. fancy-flow\n // shipped a blank-editor crash by getting this wrong in the same shape of\n // component.\n const uid = useId();\n const fieldId = (key: string) => `${uid}-${key}`;\n\n const node = selection ? doc.nodes[selection] : null;\n if (!node) {\n return (\n <div style={{ padding: 16, color: \"var(--fcms-muted)\", fontFamily: \"system-ui, sans-serif\", fontSize: 13 }}>\n Select an element to edit.\n </div>\n );\n }\n\n const s = node.style.base;\n const setStyle = (patch: Partial<StyleProps>) =>\n apply({ t: \"set_style\", id: node.id, breakpoint: \"base\", patch });\n const setProp = (key: string, value: unknown) =>\n apply({ t: \"set_props\", id: node.id, patch: { [key]: value } });\n\n return (\n <div style={{ overflow: \"auto\", padding: 16, fontFamily: \"system-ui, sans-serif\", height: \"100%\", boxSizing: \"border-box\" }}>\n <div style={{ fontSize: 13, fontWeight: 600, color: \"var(--fcms-fg)\" }}>{node.type}</div>\n <div style={{ fontSize: 11, color: \"var(--fcms-muted)\", marginBottom: 8 }}>{node.id}</div>\n\n {node.type === \"text\" ? (\n <>\n <label style={label} htmlFor={fieldId(\"content\")}>Content</label>\n <textarea\n id={fieldId(\"content\")}\n data-cms-field=\"content\"\n style={{ ...input, minHeight: 64, resize: \"vertical\" }}\n value={typeof node.props.content === \"string\" ? node.props.content : \"\"}\n onChange={(e) => setProp(\"content\", e.target.value)}\n />\n </>\n ) : null}\n\n {node.type === \"image\" ? (\n <>\n <label style={label} htmlFor={fieldId(\"src\")}>Source</label>\n <input\n id={fieldId(\"src\")}\n data-cms-field=\"src\"\n style={input}\n value={typeof node.props.src === \"string\" ? node.props.src : \"\"}\n onChange={(e) => setProp(\"src\", e.target.value)}\n />\n </>\n ) : null}\n\n <label style={label} htmlFor={fieldId(\"background\")}>Background</label>\n <input\n id={fieldId(\"background\")}\n data-cms-field=\"background\"\n style={input}\n placeholder=\"#ffffff | gradient | url(…)\"\n value={s.background ?? \"\"}\n onChange={(e) => setStyle({ background: e.target.value })}\n />\n\n <label style={label} htmlFor={fieldId(\"color\")}>Text color</label>\n <input\n id={fieldId(\"color\")}\n data-cms-field=\"color\"\n style={input}\n placeholder=\"#0f172a\"\n value={s.color ?? \"\"}\n onChange={(e) => setStyle({ color: e.target.value })}\n />\n\n <label style={label} htmlFor={fieldId(\"fontSize\")}>Font size (px)</label>\n <input\n id={fieldId(\"fontSize\")}\n data-cms-field=\"fontSize\"\n type=\"number\"\n style={input}\n value={s.fontSize?.value ?? \"\"}\n onChange={(e) => setStyle({ fontSize: { value: Number(e.target.value) || 0, unit: \"px\" } })}\n />\n\n <label style={label} htmlFor={fieldId(\"padding\")}>Padding (px)</label>\n <input\n id={fieldId(\"padding\")}\n data-cms-field=\"padding\"\n type=\"number\"\n style={input}\n value={s.padding?.value ?? \"\"}\n onChange={(e) => setStyle({ padding: { value: Number(e.target.value) || 0, unit: \"px\" } })}\n />\n\n <label style={label} htmlFor={fieldId(\"opacity\")}>Opacity</label>\n <input\n id={fieldId(\"opacity\")}\n data-cms-field=\"opacity\"\n type=\"number\"\n step=\"0.1\"\n min=\"0\"\n max=\"1\"\n style={input}\n value={s.opacity ?? \"\"}\n onChange={(e) => setStyle({ opacity: Number(e.target.value) })}\n />\n </div>\n );\n}\n","import type { Json, LayoutMode, NodeId, PageDoc, StyleProps } from \"../document/types\";\nimport type { PageOp } from \"../document/ops\";\nimport { childrenOf, lastRootId } from \"../document/reduce\";\nimport { fractionalKey as keyBetween } from \"@particle-academy/fancy-doc-commons\";\n\n/**\n * Element insertion — shared by `EditablePage` (inline editing) and `Editor`\n * (the standalone WYSIWYG shell).\n *\n * This used to live entirely inside EditablePage, which meant the embeddable\n * `Editor` had no way to add an element at all: starting from `emptyDoc()` gave\n * a blank canvas with nothing to select and no control to insert anything, so\n * a host embedding `Editor` could not author a page from scratch (#3).\n * EditablePage had the menu but no `onChange` to hand the document back —\n * each surface had half of what an embedding host needs.\n */\n\n/** Node types that accept children, so an insert lands *inside* them. */\nexport const CONTAINER_TYPES = new Set([\n \"section\",\n \"frame\",\n \"stack\",\n \"grid\",\n \"shape\",\n \"card\",\n \"device\",\n \"repeater\",\n]);\n\nexport type AddKind =\n | \"text\"\n | \"heading\"\n | \"button\"\n | \"link\"\n | \"image\"\n | \"box\"\n | \"stack\"\n | \"grid\"\n | \"card\"\n | \"callout\"\n | \"divider\"\n | \"code\"\n | \"richtext\"\n | \"repeater\";\n\nexport const ADD_DEFAULTS: Record<\n AddKind,\n { type: string; props: Record<string, Json>; style: StyleProps; layout?: LayoutMode }\n> = {\n text: { type: \"text\", props: { content: \"New text\" }, style: { color: \"inherit\" } },\n heading: { type: \"heading\", props: { content: \"New heading\" }, style: { fontSize: { value: 28, unit: \"px\" }, fontWeight: 700 } },\n button: { type: \"button\", props: { label: \"Button\", href: \"#\", variant: \"primary\" }, style: {} },\n link: { type: \"link\", props: { content: \"link text\", href: \"#\" }, style: { color: \"#7c3aed\" } },\n image: { type: \"image\", props: { src: \"\", alt: \"\" }, style: {} },\n box: { type: \"frame\", props: {}, style: { padding: { value: 16, unit: \"px\" } } },\n stack: { type: \"stack\", props: {}, style: { gap: { value: 12, unit: \"px\" } }, layout: \"stack\" },\n grid: { type: \"grid\", props: {}, style: { gap: { value: 12, unit: \"px\" } }, layout: \"grid\" },\n card: { type: \"card\", props: {}, style: { padding: { value: 16, unit: \"px\" }, radius: { value: 12, unit: \"px\" }, border: \"1px solid #e2e8f0\" } },\n callout: { type: \"callout\", props: { content: \"Heads up — this is a callout.\", variant: \"info\" }, style: {} },\n divider: { type: \"divider\", props: {}, style: {} },\n code: { type: \"code\", props: { content: \"npm install @particle-academy/react-fancy\", lang: \"bash\" }, style: {} },\n richtext: { type: \"richtext\", props: { html: \"<p>Rich <strong>text</strong> with <em>inline</em> formatting.</p>\" }, style: {} },\n repeater: { type: \"repeater\", props: { items: \"\" }, style: { gap: { value: 12, unit: \"px\" } }, layout: \"stack\" },\n};\n\nexport const ADD_MENU: Array<{ kind: AddKind; label: string }> = [\n { kind: \"heading\", label: \"Heading\" },\n { kind: \"text\", label: \"Text\" },\n { kind: \"button\", label: \"Button\" },\n { kind: \"link\", label: \"Link\" },\n { kind: \"image\", label: \"Image\" },\n { kind: \"card\", label: \"Card\" },\n { kind: \"callout\", label: \"Callout\" },\n { kind: \"stack\", label: \"Stack\" },\n { kind: \"grid\", label: \"Grid\" },\n { kind: \"box\", label: \"Box\" },\n { kind: \"divider\", label: \"Divider\" },\n { kind: \"code\", label: \"Code\" },\n { kind: \"richtext\", label: \"Rich text\" },\n { kind: \"repeater\", label: \"Repeater\" },\n];\n\n/**\n * Where a new node of `kind` should land, given the current selection.\n *\n * Into the selected container; else alongside the selected node; else the last\n * section — and when the page has no sections at all, at the top level, which\n * is what makes authoring from `emptyDoc()` possible.\n */\nexport function resolveInsertParent(doc: PageDoc, selectedId: NodeId | null): NodeId | null {\n const selected = selectedId ? doc.nodes[selectedId] : null;\n if (selected) {\n return CONTAINER_TYPES.has(selected.type) ? selected.id : selected.parent;\n }\n return lastRootId(doc);\n}\n\n/**\n * Build the `insert_node` op for adding `kind` to `doc`.\n *\n * Pure — returns the op plus the new id so the caller can select it. Callers\n * apply the op through their own editor state.\n */\nexport function buildInsertOp(\n doc: PageDoc,\n kind: AddKind,\n selectedId: NodeId | null,\n /** Explicit target, overriding selection — used by drag-and-drop. */\n targetId?: NodeId | null,\n): { op: PageOp; id: NodeId } {\n const parent =\n targetId !== undefined\n ? targetId && doc.nodes[targetId]\n ? CONTAINER_TYPES.has(doc.nodes[targetId]!.type)\n ? targetId\n : doc.nodes[targetId]!.parent\n : null\n : resolveInsertParent(doc, selectedId);\n\n const siblings = childrenOf(doc, parent);\n const order = keyBetween(siblings.length ? siblings[siblings.length - 1]!.order : null, null);\n const id = `n${doc.seq + 1}-${Math.floor(performance.now())}`;\n const def = ADD_DEFAULTS[kind];\n\n return {\n id,\n op: {\n t: \"insert_node\",\n node: {\n id,\n type: def.type,\n parent,\n order,\n layout: def.layout,\n props: { ...def.props },\n style: { base: { ...def.style } },\n },\n } as PageOp,\n };\n}\n","import { useEffect, useRef, type RefObject } from \"react\";\n\n/**\n * Hold the latest `value` in a ref, synced in an effect after every render.\n *\n * Notify effects read `ref.current` instead of closing over a callback prop, so\n * their dependency arrays stay data-only (`doc`, `selection`, …). A consumer\n * passing an inline closure — new identity every render, the most natural\n * usage — can then never re-trigger the notify: without this, notify → consumer\n * setState → render → new closure identity → effect re-fires → notify → … loops\n * unbounded (#1). Standard uncontrolled-with-notify hygiene.\n */\nexport function useLatestRef<T>(value: T): RefObject<T> {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n });\n return ref;\n}\n","import { useEffect, useMemo, useRef, useState, type CSSProperties, type ReactElement } from \"react\";\nimport type { PageDoc } from \"../document/types\";\nimport type { DataContext, ElementRegistry } from \"../react/registry\";\nimport { useEditor, type EditorApi } from \"./useEditor\";\nimport { useLatestRef } from \"./useLatestRef\";\nimport { Canvas } from \"./Canvas\";\nimport { LayersPanel } from \"./LayersPanel\";\nimport { Inspector } from \"./Inspector\";\nimport { ADD_MENU, buildInsertOp, type AddKind } from \"./insert\";\nimport { emptyDoc } from \"../document/types\";\n\nexport interface EditorProps {\n /**\n * Initial document; edits are surfaced via {@link EditorProps.onChange}.\n * Omit to start from an empty page.\n */\n defaultValue?: PageDoc;\n onChange?: (doc: PageDoc) => void;\n /**\n * Custom element registry — mirrors {@link CmsPageProps.registry} so the edit\n * canvas renders your own node types instead of a blank placeholder. Pass the\n * same registry you give `CmsPage` at runtime.\n */\n registry?: ElementRegistry;\n /** Data context that `{ $bind: \"…\" }` props + repeaters preview against on the canvas. */\n data?: DataContext;\n}\n\n/**\n * The fancy-cms editor: layers · canvas · inspector over the op-spine.\n *\n * The chrome is plain markup **deliberately**, and stays that way. It themes\n * through the `--fcms-*` layer defined at the bottom of this file — light by\n * default, dark under `prefers-color-scheme` or a `.dark` ancestor — and\n * react-fancy's primitives are hardcoded Tailwind palette classes that read no\n * custom properties, so swapping them in would ignore `--fcms-accent` and strand\n * a themed host with a half-themed editor.\n *\n * An earlier revision of this comment said the chrome \"graduates to react-fancy\n * next\". That predates the token layer by three weeks and is no longer the\n * plan; it is recorded here because it is the kind of note that gets acted on\n * long after it stopped being true.\n */\nexport function Editor({ defaultValue, onChange, registry, data }: EditorProps): ReactElement {\n // Render an empty page rather than throwing on a missing document. Reading\n // `.sections` off undefined crashed the entire editor, which is a hostile way\n // to tell a host \"you haven't passed a doc yet\" (#3).\n const initial = useMemo(() => defaultValue ?? emptyDoc(\"untitled\"), [defaultValue]);\n const ed = useEditor(initial);\n const first = useRef(true);\n\n // Notify depends ONLY on the doc — the latest onChange lives in a ref, so an\n // inline-closure consumer (whose handler identity changes every render) can't\n // re-trigger the notify and loop it (#1).\n const onChangeRef = useLatestRef(onChange);\n useEffect(() => {\n if (first.current) {\n first.current = false;\n return;\n }\n onChangeRef.current?.(ed.state.doc);\n }, [ed.state.doc, onChangeRef]);\n\n const shell: CSSProperties = {\n display: \"grid\",\n gridTemplateColumns: \"220px 1fr 300px\",\n height: \"100%\",\n minHeight: 0,\n background: \"var(--fcms-bg)\",\n color: \"var(--fcms-fg)\",\n border: \"1px solid var(--fcms-border)\",\n borderRadius: 12,\n overflow: \"hidden\",\n };\n\n return (\n <div className=\"fancy-cms-editor\" style={shell}>\n <style>{CHROME_CSS}</style>\n <div style={{ borderRight: \"1px solid var(--fcms-border)\", display: \"flex\", flexDirection: \"column\", minHeight: 0 }}>\n <Toolbar ed={ed} />\n <LayersPanel\n doc={ed.state.doc}\n selection={ed.state.selection}\n onSelect={ed.select}\n onMove={(id, parent, order) => ed.apply({ t: \"move_node\", id, parent, order })}\n />\n </div>\n <Canvas doc={ed.state.doc} selection={ed.state.selection} onSelect={ed.select} apply={ed.apply} registry={registry} data={data} />\n <div style={{ borderLeft: \"1px solid var(--fcms-border)\", minHeight: 0 }}>\n <Inspector doc={ed.state.doc} selection={ed.state.selection} apply={ed.apply} />\n </div>\n </div>\n );\n}\n\nfunction Toolbar({ ed }: { ed: EditorApi }): ReactElement {\n const btn: CSSProperties = {\n font: \"inherit\",\n fontSize: 12,\n padding: \"4px 10px\",\n borderRadius: 6,\n border: \"1px solid var(--fcms-border)\",\n background: \"var(--fcms-bg)\",\n color: \"var(--fcms-fg)\",\n cursor: \"pointer\",\n };\n return (\n <div\n style={{\n display: \"flex\",\n gap: 6,\n padding: 8,\n borderBottom: \"1px solid var(--fcms-border)\",\n fontFamily: \"system-ui, sans-serif\",\n }}\n >\n <button type=\"button\" style={{ ...btn, opacity: ed.canUndo ? 1 : 0.4 }} disabled={!ed.canUndo} onClick={ed.undo}>\n Undo\n </button>\n <button type=\"button\" style={{ ...btn, opacity: ed.canRedo ? 1 : 0.4 }} disabled={!ed.canRedo} onClick={ed.redo}>\n Redo\n </button>\n <AddElementMenu ed={ed} btn={btn} />\n </div>\n );\n}\n\n/**\n * Insert control for the standalone editor.\n *\n * Without this, `Editor` could not add an element at all: a host starting from\n * `emptyDoc()` got a blank canvas with nothing to select and no way to put\n * anything on it (#3). The palette itself was only ever wired into\n * `EditablePage`, which has no `onChange` to hand the document back — so\n * neither surface alone was embeddable.\n */\nfunction AddElementMenu({ ed, btn }: { ed: EditorApi; btn: CSSProperties }): ReactElement {\n const [open, setOpen] = useState(false);\n\n // Dismiss on any outside click or Escape.\n useEffect(() => {\n if (!open) return;\n const close = () => setOpen(false);\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n window.addEventListener(\"click\", close);\n window.addEventListener(\"keydown\", onKey);\n return () => {\n window.removeEventListener(\"click\", close);\n window.removeEventListener(\"keydown\", onKey);\n };\n }, [open]);\n\n const add = (kind: AddKind) => {\n const { op, id } = buildInsertOp(ed.state.doc, kind, ed.state.selection);\n ed.apply(op);\n ed.select(id);\n setOpen(false);\n };\n\n return (\n <div style={{ position: \"relative\", marginLeft: \"auto\" }} onClick={(e) => e.stopPropagation()}>\n <button\n type=\"button\"\n style={{ ...btn, borderColor: \"var(--fcms-accent, #7c3aed)\" }}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n data-cms-add-trigger=\"\"\n onClick={() => setOpen((v) => !v)}\n >\n + Add\n </button>\n {open && (\n <div\n role=\"menu\"\n data-cms-add-menu=\"\"\n style={{\n position: \"absolute\",\n top: \"calc(100% + 4px)\",\n left: 0,\n zIndex: 20,\n minWidth: 150,\n maxHeight: 280,\n overflowY: \"auto\",\n padding: 4,\n borderRadius: 8,\n border: \"1px solid var(--fcms-border)\",\n background: \"var(--fcms-bg)\",\n boxShadow: \"0 12px 32px rgba(0,0,0,.28)\",\n }}\n >\n {ADD_MENU.map((item) => (\n <button\n key={item.kind}\n type=\"button\"\n role=\"menuitem\"\n data-cms-add={item.kind}\n style={{\n ...btn,\n display: \"block\",\n width: \"100%\",\n textAlign: \"left\",\n border: 0,\n background: \"transparent\",\n }}\n onClick={() => add(item.kind)}\n >\n {item.label}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n}\n\n/**\n * Editor chrome tokens. Light by default; dark under `@media (prefers-color-scheme:\n * dark)` OR an ancestor `.dark` / `[data-theme=\"dark\"]` (Tailwind/class strategy),\n * with an explicit `.light` / `[data-theme=\"light\"]` ancestor forcing light back.\n * The panels below read `var(--fcms-*)`, so the whole editor embeds cleanly in a\n * dark app. `color-scheme` flips native inputs + scrollbars too.\n */\nconst DARK_VARS =\n \"color-scheme:dark;--fcms-bg:#0b0f19;--fcms-fg:#e5e7eb;--fcms-muted:#94a3b8;--fcms-border:#27272a;\" +\n \"--fcms-canvas:#0f141f;--fcms-input-bg:#111827;--fcms-row-fg:#cbd5e1;\" +\n \"--fcms-sel-bg:color-mix(in oklab, #8b5cf6 24%, transparent);--fcms-sel-fg:#ddd6fe;\" +\n \"--fcms-drop:#ec4899;--fcms-danger:#fca5a5;\";\nconst LIGHT_VARS =\n \"color-scheme:light;--fcms-bg:#ffffff;--fcms-fg:#0f172a;--fcms-muted:#64748b;--fcms-border:#e2e8f0;\" +\n \"--fcms-canvas:#f8fafc;--fcms-input-bg:#ffffff;--fcms-row-fg:#334155;--fcms-sel-bg:#ede9fe;--fcms-sel-fg:#5b21b6;\" +\n \"--fcms-drop:#db2777;--fcms-danger:#dc2626;\";\nconst CHROME_CSS =\n `.fancy-cms-editor{--fcms-accent:#8b5cf6;${LIGHT_VARS}}` +\n `@media (prefers-color-scheme:dark){.fancy-cms-editor{${DARK_VARS}}}` +\n `:where(.light,[data-theme=\"light\"]) .fancy-cms-editor{${LIGHT_VARS}}` +\n `:where(.dark,[data-theme=\"dark\"]) .fancy-cms-editor{${DARK_VARS}}`;\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { childrenOf as childrenOf$1, descendantsOf, fractionalKey } from '@particle-academy/fancy-doc-commons';
|
|
1
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { Fragment } from 'react';
|
|
3
|
+
import { useMemo, Fragment } from 'react';
|
|
3
4
|
|
|
4
5
|
// src/document/types.ts
|
|
5
6
|
function isBinding(v) {
|
|
@@ -17,38 +18,21 @@ function emptyDoc(id, slug = "/") {
|
|
|
17
18
|
meta: { title: "Untitled", slug, scrollMode: "smooth" },
|
|
18
19
|
theme: { name: "default" },
|
|
19
20
|
breakpoints: ["base", "md", "lg"],
|
|
20
|
-
sections: [],
|
|
21
21
|
nodes: {}
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
// src/document/reduce.ts
|
|
26
24
|
function childrenOf(doc, parent) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
out.sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0);
|
|
36
|
-
return out;
|
|
25
|
+
return childrenOf$1(doc, parent);
|
|
26
|
+
}
|
|
27
|
+
function rootIds(doc) {
|
|
28
|
+
return childrenOf(doc, null).map((n) => n.id);
|
|
29
|
+
}
|
|
30
|
+
function lastRootId(doc) {
|
|
31
|
+
const r = rootIds(doc);
|
|
32
|
+
return r[r.length - 1] ?? null;
|
|
37
33
|
}
|
|
38
34
|
function descendantIds(doc, id) {
|
|
39
|
-
|
|
40
|
-
const stack = [id];
|
|
41
|
-
while (stack.length) {
|
|
42
|
-
const current = stack.pop();
|
|
43
|
-
for (const childId of Object.keys(doc.nodes)) {
|
|
44
|
-
const n = doc.nodes[childId];
|
|
45
|
-
if (n.parent === current) {
|
|
46
|
-
out.push(childId);
|
|
47
|
-
stack.push(childId);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return out;
|
|
35
|
+
return descendantsOf(doc, id);
|
|
52
36
|
}
|
|
53
37
|
function patchNode(doc, id, patch) {
|
|
54
38
|
const node = doc.nodes[id];
|
|
@@ -70,7 +54,6 @@ function reduce(doc, op, opts = {}) {
|
|
|
70
54
|
return {
|
|
71
55
|
...doc,
|
|
72
56
|
nodes: { ...doc.nodes, [op.node.id]: op.node },
|
|
73
|
-
sections: op.node.parent === null ? [...doc.sections, op.node.id] : doc.sections,
|
|
74
57
|
seq: doc.seq + 1
|
|
75
58
|
};
|
|
76
59
|
}
|
|
@@ -84,7 +67,6 @@ function reduce(doc, op, opts = {}) {
|
|
|
84
67
|
return {
|
|
85
68
|
...doc,
|
|
86
69
|
nodes,
|
|
87
|
-
sections: doc.sections.filter((s) => !dead.has(s)),
|
|
88
70
|
seq: doc.seq + 1
|
|
89
71
|
};
|
|
90
72
|
}
|
|
@@ -96,15 +78,9 @@ function reduce(doc, op, opts = {}) {
|
|
|
96
78
|
if (op.parent !== null && descendantIds(doc, op.id).includes(op.parent)) {
|
|
97
79
|
return invalid("move would create a cycle");
|
|
98
80
|
}
|
|
99
|
-
const wasTop = node.parent === null;
|
|
100
|
-
const nowTop = op.parent === null;
|
|
101
|
-
let sections = doc.sections;
|
|
102
|
-
if (wasTop && !nowTop) sections = sections.filter((s) => s !== op.id);
|
|
103
|
-
else if (!wasTop && nowTop) sections = [...sections, op.id];
|
|
104
81
|
return {
|
|
105
82
|
...doc,
|
|
106
83
|
nodes: { ...doc.nodes, [op.id]: { ...node, parent: op.parent, order: op.order } },
|
|
107
|
-
sections,
|
|
108
84
|
seq: doc.seq + 1
|
|
109
85
|
};
|
|
110
86
|
}
|
|
@@ -165,11 +141,18 @@ function reduce(doc, op, opts = {}) {
|
|
|
165
141
|
return { ...doc, meta: { ...doc.meta, ...op.patch }, seq: doc.seq + 1 };
|
|
166
142
|
case "set_theme":
|
|
167
143
|
return { ...doc, theme: { ...doc.theme, ...op.patch }, seq: doc.seq + 1 };
|
|
168
|
-
case "
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
return
|
|
144
|
+
case "reorder_roots": {
|
|
145
|
+
const currentRoots = childrenOf(doc, null);
|
|
146
|
+
const current = new Set(currentRoots.map((n) => n.id));
|
|
147
|
+
const same = op.order.length === currentRoots.length && op.order.every((id) => current.has(id));
|
|
148
|
+
if (!same) return invalid("reorder must be a permutation of the current roots");
|
|
149
|
+
const nodes = { ...doc.nodes };
|
|
150
|
+
let prev = null;
|
|
151
|
+
for (const id of op.order) {
|
|
152
|
+
prev = fractionalKey(prev, null);
|
|
153
|
+
nodes[id] = { ...nodes[id], order: prev };
|
|
154
|
+
}
|
|
155
|
+
return { ...doc, nodes, seq: doc.seq + 1 };
|
|
173
156
|
}
|
|
174
157
|
default:
|
|
175
158
|
return invalid(`unknown op "${op.t}"`);
|
|
@@ -187,14 +170,18 @@ function invert(doc, op) {
|
|
|
187
170
|
if (!node) return [];
|
|
188
171
|
const ids = [op.id, ...descendantIds(doc, op.id)];
|
|
189
172
|
const inserts = ids.map((id) => ({ t: "insert_node", node: doc.nodes[id] }));
|
|
190
|
-
if (node.parent === null)
|
|
173
|
+
if (node.parent === null) {
|
|
174
|
+
inserts.push({ t: "reorder_roots", order: childrenOf(doc, null).map((n) => n.id) });
|
|
175
|
+
}
|
|
191
176
|
return inserts;
|
|
192
177
|
}
|
|
193
178
|
case "move_node": {
|
|
194
179
|
const node = doc.nodes[op.id];
|
|
195
180
|
if (!node) return [];
|
|
196
181
|
const back = [{ t: "move_node", id: op.id, parent: node.parent, order: node.order }];
|
|
197
|
-
if (node.parent === null)
|
|
182
|
+
if (node.parent === null) {
|
|
183
|
+
back.push({ t: "reorder_roots", order: childrenOf(doc, null).map((n) => n.id) });
|
|
184
|
+
}
|
|
198
185
|
return back;
|
|
199
186
|
}
|
|
200
187
|
case "set_props": {
|
|
@@ -221,8 +208,8 @@ function invert(doc, op) {
|
|
|
221
208
|
return [{ t: "set_meta", patch: pick(doc.meta, Object.keys(op.patch)) }];
|
|
222
209
|
case "set_theme":
|
|
223
210
|
return [{ t: "set_theme", patch: pick(doc.theme, Object.keys(op.patch)) }];
|
|
224
|
-
case "
|
|
225
|
-
return [{ t: "
|
|
211
|
+
case "reorder_roots":
|
|
212
|
+
return [{ t: "reorder_roots", order: childrenOf(doc, null).map((n) => n.id) }];
|
|
226
213
|
default:
|
|
227
214
|
return [];
|
|
228
215
|
}
|
|
@@ -232,6 +219,47 @@ function pick(obj, keys) {
|
|
|
232
219
|
for (const k of keys) out[k] = obj[k];
|
|
233
220
|
return out;
|
|
234
221
|
}
|
|
222
|
+
function migrateDocVerbose(input) {
|
|
223
|
+
const legacy = input;
|
|
224
|
+
const sections = legacy.sections;
|
|
225
|
+
if (!Array.isArray(sections)) {
|
|
226
|
+
return { doc: input, migrated: false, danglingIds: [], unlistedRootIds: [] };
|
|
227
|
+
}
|
|
228
|
+
const danglingIds = [];
|
|
229
|
+
const ordered = [];
|
|
230
|
+
const seen = /* @__PURE__ */ new Set();
|
|
231
|
+
for (const id of sections) {
|
|
232
|
+
if (!input.nodes[id]) {
|
|
233
|
+
danglingIds.push(id);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (seen.has(id)) continue;
|
|
237
|
+
seen.add(id);
|
|
238
|
+
ordered.push(id);
|
|
239
|
+
}
|
|
240
|
+
const unlistedRootIds = Object.values(input.nodes).filter((n) => n.parent === null && !seen.has(n.id)).sort((a, b) => a.order < b.order ? -1 : a.order > b.order ? 1 : 0).map((n) => n.id);
|
|
241
|
+
const finalOrder = [...ordered, ...unlistedRootIds];
|
|
242
|
+
const nodes = { ...input.nodes };
|
|
243
|
+
let prev = null;
|
|
244
|
+
for (const id of finalOrder) {
|
|
245
|
+
const key = fractionalKey(prev, null);
|
|
246
|
+
nodes[id] = { ...nodes[id], order: key };
|
|
247
|
+
prev = key;
|
|
248
|
+
}
|
|
249
|
+
const { sections: _dropped, ...rest } = legacy;
|
|
250
|
+
return {
|
|
251
|
+
doc: { ...rest, nodes },
|
|
252
|
+
migrated: true,
|
|
253
|
+
danglingIds,
|
|
254
|
+
unlistedRootIds
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function migrateDoc(input) {
|
|
258
|
+
return migrateDocVerbose(input).doc;
|
|
259
|
+
}
|
|
260
|
+
function needsMigration(input) {
|
|
261
|
+
return Array.isArray(input.sections);
|
|
262
|
+
}
|
|
235
263
|
|
|
236
264
|
// src/render/css.ts
|
|
237
265
|
var selectorFor = (id) => `[data-cms="${id}"]`;
|
|
@@ -436,17 +464,18 @@ function RenderNode({ doc, id, registry = defaultRegistry, data }) {
|
|
|
436
464
|
return /* @__PURE__ */ jsx("div", { "data-cms": node.id, "data-cms-island": node.island ? node.type : void 0, className: node.className, children: inner });
|
|
437
465
|
}
|
|
438
466
|
function CmsPage({
|
|
439
|
-
doc,
|
|
467
|
+
doc: input,
|
|
440
468
|
registry = defaultRegistry,
|
|
441
469
|
data,
|
|
442
470
|
includeStyles = true
|
|
443
471
|
}) {
|
|
472
|
+
const doc = useMemo(() => migrateDoc(input), [input]);
|
|
444
473
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
445
474
|
includeStyles ? /* @__PURE__ */ jsx("style", { "data-cms-styles": "", children: emitDocCss(doc) }) : null,
|
|
446
|
-
doc.
|
|
475
|
+
rootIds(doc).map((id) => /* @__PURE__ */ jsx(RenderNode, { doc, id, registry, data }, id))
|
|
447
476
|
] });
|
|
448
477
|
}
|
|
449
478
|
|
|
450
|
-
export { CmsPage, DEFAULT_BREAKPOINTS, RenderNode, childrenOf, defaultRegistry, descendantIds, emitDocCss, emptyDoc, getPath, invert, isBinding, reduce, reduceAll, resolveValue };
|
|
451
|
-
//# sourceMappingURL=chunk-
|
|
452
|
-
//# sourceMappingURL=chunk-
|
|
479
|
+
export { CmsPage, DEFAULT_BREAKPOINTS, RenderNode, childrenOf, defaultRegistry, descendantIds, emitDocCss, emptyDoc, getPath, invert, isBinding, lastRootId, migrateDoc, migrateDocVerbose, needsMigration, reduce, reduceAll, resolveValue, rootIds };
|
|
480
|
+
//# sourceMappingURL=chunk-FDCP3LVR.js.map
|
|
481
|
+
//# sourceMappingURL=chunk-FDCP3LVR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/document/types.ts","../src/document/reduce.ts","../src/document/migrate.ts","../src/render/css.ts","../src/react/registry.tsx","../src/react/RenderNode.tsx","../src/react/CmsPage.tsx"],"names":["docChildrenOf","fractionalKey","jsx"],"mappings":";;;;;AA2BO,SAAS,UAAU,CAAA,EAA0B;AAClD,EAAA,OAAO,OAAO,CAAA,KAAM,QAAA,IAAY,MAAM,IAAA,IAAQ,OAAQ,EAAc,KAAA,KAAU,QAAA;AAChF;AAqKO,IAAM,mBAAA,GAA8C;AAAA,EACzD,IAAA,EAAM,CAAA;AAAA,EACN,EAAA,EAAI,GAAA;AAAA,EACJ,EAAA,EAAI;AACN;AAGO,SAAS,QAAA,CAAS,EAAA,EAAY,IAAA,GAAO,GAAA,EAAc;AACxD,EAAA,OAAO;AAAA,IACL,EAAA;AAAA,IACA,GAAA,EAAK,CAAA;AAAA,IACL,MAAM,EAAE,KAAA,EAAO,UAAA,EAAY,IAAA,EAAM,YAAY,QAAA,EAAS;AAAA,IACtD,KAAA,EAAO,EAAE,IAAA,EAAM,SAAA,EAAU;AAAA,IACzB,WAAA,EAAa,CAAC,MAAA,EAAQ,IAAA,EAA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EAAiB,IAAA,CAAK,MAAA,GAAS,KAAK,IAAA,GAAO,MAAA,EAAW,SAAA,EAAW,IAAA,CAAK,WAC3F,QAAA,EAAA,KAAA,EACH,CAAA;AAEJ;AC1CO,SAAS,OAAA,CAAQ;AAAA,EACtB,GAAA,EAAK,KAAA;AAAA,EACL,QAAA,GAAW,eAAA;AAAA,EACX,IAAA;AAAA,EACA,aAAA,GAAgB;AAClB,CAAA,EAA+B;AAK7B,EAAA,MAAM,GAAA,GAAM,QAAQ,MAAM,UAAA,CAAW,KAAK,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AAEpD,EAAA,4BACG,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,IAAA,aAAA,mBAAgBA,IAAC,OAAA,EAAA,EAAM,iBAAA,EAAgB,IAAI,QAAA,EAAA,UAAA,CAAW,GAAG,GAAE,CAAA,GAAW,IAAA;AAAA,IACtE,OAAA,CAAQ,GAAG,CAAA,CAAE,GAAA,CAAI,CAAC,EAAA,qBACjBA,GAAAA,CAAC,UAAA,EAAA,EAAoB,GAAA,EAAU,EAAA,EAAQ,QAAA,EAAoB,IAAA,EAAA,EAA1C,EAAsD,CACxE;AAAA,GAAA,EACH,CAAA;AAEJ","file":"chunk-FDCP3LVR.js","sourcesContent":["/**\n * Stages document model — see `fancy-ui/docs/fancy-cms.md` §4.\n *\n * A page is a vertical stack of full-bleed **sections**; inside each, **layers**\n * are positioned by constraints (free + bold stays responsive), with stack/grid\n * containers where structure is wanted. Nodes live in a **flat map** keyed by id\n * (Figma-style) so ops target a stable identity and collab merges stay clean.\n */\n\nimport type { DocNode, DocTree } from \"@particle-academy/fancy-doc-commons\";\n\n/** A node id. Alias of doc-commons' `DocId`, kept for readability in CMS code. */\nexport type NodeId = string;\n\nexport type ScrollMode = \"snap\" | \"smooth\";\n\n/** Ordered, mobile-first. Convention: `\"base\" | \"md\" | \"lg\"`. */\nexport type Breakpoint = string;\n\nexport type Json = string | number | boolean | null | Json[] | { [key: string]: Json };\n\n/** A literal value OR a binding into the page's data context (`{ $bind: \"profile.coins\" }`). */\nexport interface Binding {\n $bind: string;\n}\nexport type Bound<T> = T | Binding;\n\nexport function isBinding(v: unknown): v is Binding {\n return typeof v === \"object\" && v !== null && typeof (v as Binding).$bind === \"string\";\n}\n\n// ── Sizing ────────────────────────────────────────────────────────────────\n\nexport type LengthUnit = \"px\" | \"%\" | \"vw\" | \"vh\" | \"rem\" | \"fr\";\nexport interface Length {\n value: number;\n unit: LengthUnit;\n}\nexport type SizeMode = Length | \"fill\" | \"hug\";\n\nexport interface Constraints {\n /** Pinned offsets within a `free` parent (null = unpinned). */\n left?: Length | null;\n right?: Length | null;\n top?: Length | null;\n bottom?: Length | null;\n centerX?: boolean;\n centerY?: boolean;\n width: SizeMode;\n height: SizeMode;\n}\n\nexport type LayoutMode = \"free\" | \"stack\" | \"grid\";\n\n// ── Style (compiles deterministically to CSS in both emitters) ──────────────\n\nexport interface StyleProps {\n // box\n padding?: Length;\n margin?: Length;\n radius?: Length;\n // color / surface\n background?: string; // color | gradient | url(...)\n color?: string;\n opacity?: number;\n // typography\n fontFamily?: string;\n fontSize?: Length;\n fontWeight?: number;\n lineHeight?: number;\n textAlign?: \"left\" | \"center\" | \"right\" | \"justify\";\n letterSpacing?: Length;\n // border / shadow / effects (static)\n border?: string;\n boxShadow?: string;\n transform?: string;\n filter?: string;\n // container knobs (when layout = stack | grid)\n gap?: Length;\n direction?: \"row\" | \"column\";\n columns?: number;\n align?: \"start\" | \"center\" | \"end\" | \"stretch\";\n justify?: \"start\" | \"center\" | \"end\" | \"between\" | \"around\";\n}\n\n/** Per-breakpoint overrides; `base` is required, others cascade mobile-first. */\nexport type PerBreakpoint<T> = { base: T } & Partial<Record<Breakpoint, Partial<T>>>;\n\n// ── Animation (typed for Phase 2; ignored by the static CSS emitter) ────────\n\nexport type AnimDriver = \"enter\" | \"scroll\" | \"loop\" | \"hover\" | \"click\" | \"drag\";\nexport interface Keyframe {\n at: number; // 0..1\n props: Record<string, number | string>;\n}\nexport interface Anim {\n id: string;\n driver: AnimDriver;\n keyframes: Keyframe[];\n range?: { start: number; end: number };\n ease?: string;\n duration?: number;\n delay?: number;\n stagger?: number;\n once?: boolean;\n emit?: \"css\" | \"js\";\n}\n\n// ── Actions (typed for Phase 3/4) ───────────────────────────────────────────\n\nexport type ActionEvent = \"click\" | \"submit\" | \"change\" | \"load\" | \"timer\" | \"scroll-into\" | \"hover\";\nexport type ActionHandler =\n | { kind: \"navigate\"; href: Bound<string> }\n | { kind: \"submitForm\"; endpoint: string; method?: \"post\" | \"put\" }\n | { kind: \"mutate\"; target: string; value: Bound<Json> }\n | { kind: \"callEndpoint\"; endpoint: string; method?: string }\n | { kind: \"runFlow\"; flow: string }\n | { kind: \"openModal\"; node: NodeId }\n | { kind: \"openDrawer\"; node: NodeId }\n | { kind: \"playTimeline\"; section: NodeId }\n | { kind: \"toggleNode\"; node: NodeId };\nexport interface Action {\n on: ActionEvent;\n do: ActionHandler;\n}\n\n// ── Nodes & document ────────────────────────────────────────────────────────\n\n/**\n * A page node.\n *\n * Extends {@link DocNode} from `fancy-doc-commons` rather than redeclaring it:\n * id / type / parent / order / props are the shared substrate every Fancy\n * document surface uses, and the CMS adds its own domain fields on top. That\n * is what lets `registerDocBridge` drive a CMS page and a fancy-screens screen\n * through the same tools, with no CMS-specific bridge.\n */\nexport interface Node extends DocNode<Record<string, Bound<Json>>> {\n /** Addon key: `section | text | image | shape | stack | grid | frame | <addon>`. */\n type: string;\n /** How this node arranges its children. */\n layout?: LayoutMode;\n /** How this node positions itself within its parent. */\n constraints?: PerBreakpoint<Constraints>;\n style: PerBreakpoint<StyleProps>;\n animations?: Anim[];\n actions?: Action[];\n /** Repeater: render this node once per item of a bound array. */\n repeat?: { each: Binding; as: string };\n /**\n * Host CSS class(es) applied to the node's element. The migration enabler:\n * reuse the host site's existing stylesheet for pixel-perfect reproduction\n * instead of re-deriving every rule through {@link StyleProps}.\n */\n className?: string;\n /** Derived from the addon manifest — interactive/3rd-party ⇒ hydration island. */\n island?: boolean;\n}\n\nexport interface ThemeTokens {\n name?: string;\n [key: string]: Json | undefined;\n}\n\nexport interface PageMeta {\n title: string;\n slug: string;\n scrollMode: ScrollMode;\n seo?: Record<string, string>;\n}\n\nexport interface PageDoc {\n id: string;\n /** Op counter — collab ordering + revision checkpoints. */\n seq: number;\n meta: PageMeta;\n theme: ThemeTokens;\n /** Ordered, mobile-first. */\n breakpoints: Breakpoint[];\n /**\n * Flat map — not a nested tree. This is a {@link DocTree}, so every\n * doc-commons walk (`childrenOf`, `roots`, `descendantsOf`) works on it\n * directly.\n *\n * There is no separate `sections[]` any more. Top-level order used to live in\n * its own array while every other level used fractional `order` keys, which\n * meant two ordering mechanisms that could disagree — a node could be a root\n * by `parent === null` and absent from `sections`, and then simply not\n * render. Roots are now ordered exactly like any other sibling group.\n */\n nodes: Record<NodeId, Node>;\n}\n\n/** Default breakpoint → min-width (px) map. `base` has no media query. */\nexport const DEFAULT_BREAKPOINTS: Record<string, number> = {\n base: 0,\n md: 768,\n lg: 1024,\n};\n\n/** A minimal empty document. */\nexport function emptyDoc(id: string, slug = \"/\"): PageDoc {\n return {\n id,\n seq: 0,\n meta: { title: \"Untitled\", slug, scrollMode: \"smooth\" },\n theme: { name: \"default\" },\n breakpoints: [\"base\", \"md\", \"lg\"],\n nodes: {},\n };\n}\n","/**\n * The pure, total reducer. `reduce(doc, op)` returns a new document; an invalid\n * op is a **logged no-op** (returns the same doc, `seq` unchanged). That single\n * property is what makes undo, revisions, collaboration, and agent edits all\n * flow through one spine.\n *\n * Ordering: EVERY level uses the fractional `order` field among siblings,\n * including the roots. Top-level order used to live in a separate `sections`\n * array, which meant two mechanisms that could disagree — a node could be a\n * root by `parent === null` and missing from `sections`, and then simply not\n * render, with nothing reporting it.\n */\nimport {\n childrenOf as docChildrenOf,\n descendantsOf,\n fractionalKey,\n} from \"@particle-academy/fancy-doc-commons\";\nimport type { Action, Node, NodeId, PageDoc, StyleProps } from \"./types\";\nimport type { PageOp } from \"./ops\";\n\nexport interface ReduceOptions {\n /** Called when an op can't apply. Default: silent. */\n onInvalid?: (op: PageOp, reason: string) => void;\n}\n\n/**\n * Children of a node (or the roots when `parent` is null), in order.\n *\n * Delegates to doc-commons so the CMS, fancy-screens and any future surface\n * walk a document the same way. Roots are no longer a special case.\n */\nexport function childrenOf(doc: PageDoc, parent: NodeId | null): Node[] {\n return docChildrenOf<Node>(doc, parent);\n}\n\n/**\n * The top-level node ids, in order.\n *\n * Replaces the old `doc.sections` array. Kept as a named helper because the two\n * things callers actually wanted from that array — \"list the roots\" and \"the\n * last root\" — read badly as `childrenOf(doc, null).map(n => n.id)` at every\n * call site.\n */\nexport function rootIds(doc: PageDoc): NodeId[] {\n return childrenOf(doc, null).map((n) => n.id);\n}\n\n/** The last top-level node, or null — the default parent for a new insert. */\nexport function lastRootId(doc: PageDoc): NodeId | null {\n const r = rootIds(doc);\n return r[r.length - 1] ?? null;\n}\n\n/** Every transitive descendant id of `id` (excludes `id`). */\nexport function descendantIds(doc: PageDoc, id: NodeId): NodeId[] {\n return descendantsOf<Node>(doc, id);\n}\n\nfunction patchNode(doc: PageDoc, id: NodeId, patch: Partial<Node>): PageDoc {\n const node = doc.nodes[id]!;\n return {\n ...doc,\n nodes: { ...doc.nodes, [id]: { ...node, ...patch } },\n seq: doc.seq + 1,\n };\n}\n\nexport function reduce(doc: PageDoc, op: PageOp, opts: ReduceOptions = {}): PageDoc {\n const invalid = (reason: string): PageDoc => {\n opts.onInvalid?.(op, reason);\n return doc;\n };\n\n switch (op.t) {\n case \"insert_node\": {\n if (doc.nodes[op.node.id]) return invalid(\"node id already exists\");\n if (op.node.parent !== null && !doc.nodes[op.node.parent]) return invalid(\"parent not found\");\n return {\n ...doc,\n nodes: { ...doc.nodes, [op.node.id]: op.node },\n seq: doc.seq + 1,\n };\n }\n\n case \"remove_node\": {\n if (!doc.nodes[op.id]) return invalid(\"node not found\");\n const dead = new Set<NodeId>([op.id, ...descendantIds(doc, op.id)]);\n const nodes: Record<NodeId, Node> = {};\n for (const id of Object.keys(doc.nodes)) {\n if (!dead.has(id)) nodes[id] = doc.nodes[id]!;\n }\n return {\n ...doc,\n nodes,\n seq: doc.seq + 1,\n };\n }\n\n case \"move_node\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n if (op.parent === op.id) return invalid(\"cannot parent a node to itself\");\n if (op.parent !== null && !doc.nodes[op.parent]) return invalid(\"new parent not found\");\n if (op.parent !== null && descendantIds(doc, op.id).includes(op.parent)) {\n return invalid(\"move would create a cycle\");\n }\n return {\n ...doc,\n nodes: { ...doc.nodes, [op.id]: { ...node, parent: op.parent, order: op.order } },\n seq: doc.seq + 1,\n };\n }\n\n case \"set_props\": {\n if (!doc.nodes[op.id]) return invalid(\"node not found\");\n return patchNode(doc, op.id, {\n props: { ...doc.nodes[op.id]!.props, ...op.patch } as unknown as Node[\"props\"],\n });\n }\n\n case \"set_layout\": {\n if (!doc.nodes[op.id]) return invalid(\"node not found\");\n return patchNode(doc, op.id, { layout: op.layout });\n }\n\n case \"set_style\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n const prev = node.style[op.breakpoint] ?? {};\n return patchNode(doc, op.id, {\n style: { ...node.style, [op.breakpoint]: { ...prev, ...op.patch } } as Node[\"style\"],\n });\n }\n\n case \"set_constraints\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n const base = node.constraints ?? { base: { width: \"hug\", height: \"hug\" } };\n const prev = base[op.breakpoint] ?? {};\n return patchNode(doc, op.id, {\n constraints: { ...base, [op.breakpoint]: { ...prev, ...op.patch } } as Node[\"constraints\"],\n });\n }\n\n case \"set_animation\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n const list = node.animations ?? [];\n const idx = list.findIndex((a) => a.id === op.anim.id);\n return patchNode(doc, op.id, {\n animations: idx >= 0 ? list.map((a, i) => (i === idx ? op.anim : a)) : [...list, op.anim],\n });\n }\n\n case \"remove_animation\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n return patchNode(doc, op.id, {\n animations: (node.animations ?? []).filter((a) => a.id !== op.animId),\n });\n }\n\n case \"set_action\": {\n const node = doc.nodes[op.id];\n if (!node) return invalid(\"node not found\");\n const list = node.actions ?? [];\n let actions: Action[];\n if (op.action === null) actions = list.filter((_, i) => i !== op.index);\n else if (op.index >= list.length) actions = [...list, op.action];\n else actions = list.map((a, i) => (i === op.index ? op.action! : a));\n return patchNode(doc, op.id, { actions });\n }\n\n case \"set_meta\":\n return { ...doc, meta: { ...doc.meta, ...op.patch }, seq: doc.seq + 1 };\n\n case \"set_theme\":\n return { ...doc, theme: { ...doc.theme, ...op.patch }, seq: doc.seq + 1 };\n\n case \"reorder_roots\": {\n // Roots are ordered by their own fractional keys now, so a reorder\n // REWRITES those keys rather than replacing a list. Still validated as a\n // permutation: a partial list would silently drop roots out of the page.\n const currentRoots = childrenOf(doc, null);\n const current = new Set(currentRoots.map((n) => n.id));\n const same =\n op.order.length === currentRoots.length && op.order.every((id) => current.has(id));\n if (!same) return invalid(\"reorder must be a permutation of the current roots\");\n\n const nodes = { ...doc.nodes };\n let prev: string | null = null;\n for (const id of op.order) {\n prev = fractionalKey(prev, null);\n nodes[id] = { ...nodes[id]!, order: prev };\n }\n return { ...doc, nodes, seq: doc.seq + 1 };\n }\n\n default:\n return invalid(`unknown op \"${(op as PageOp).t}\"`);\n }\n}\n\n/** Apply a sequence of ops, threading the document. */\nexport function reduceAll(doc: PageDoc, ops: PageOp[], opts?: ReduceOptions): PageDoc {\n return ops.reduce((d, op) => reduce(d, op, opts), doc);\n}\n\n/**\n * Inverse op(s) for undo, computed against the **pre-op** document. Structural\n * ops invert cleanly; merge-style ops (`set_props`/`set_style`/`set_constraints`)\n * restore the previous values of the touched keys (keys that did not previously\n * exist can't be deleted via a merge — a known Phase-0 limitation).\n */\nexport function invert(doc: PageDoc, op: PageOp): PageOp[] {\n switch (op.t) {\n case \"insert_node\":\n return [{ t: \"remove_node\", id: op.node.id }];\n\n case \"remove_node\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n // Re-insert the subtree parent-first, then restore section order.\n const ids = [op.id, ...descendantIds(doc, op.id)];\n const inserts: PageOp[] = ids.map((id) => ({ t: \"insert_node\", node: doc.nodes[id]! }));\n if (node.parent === null) {\n inserts.push({ t: \"reorder_roots\", order: childrenOf(doc, null).map((n) => n.id) });\n }\n return inserts;\n }\n\n case \"move_node\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n const back: PageOp[] = [{ t: \"move_node\", id: op.id, parent: node.parent, order: node.order }];\n if (node.parent === null) {\n back.push({ t: \"reorder_roots\", order: childrenOf(doc, null).map((n) => n.id) });\n }\n return back;\n }\n\n case \"set_props\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n const prev: Record<string, unknown> = {};\n for (const k of Object.keys(op.patch)) prev[k] = node.props[k];\n return [{ t: \"set_props\", id: op.id, patch: prev }];\n }\n\n case \"set_layout\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n return [{ t: \"set_layout\", id: op.id, layout: node.layout }];\n }\n\n case \"set_style\": {\n const node = doc.nodes[op.id];\n if (!node) return [];\n const prevBp = (node.style[op.breakpoint] ?? {}) as Record<string, unknown>;\n const prev: Partial<StyleProps> = {};\n for (const k of Object.keys(op.patch)) (prev as Record<string, unknown>)[k] = prevBp[k];\n return [{ t: \"set_style\", id: op.id, breakpoint: op.breakpoint, patch: prev }];\n }\n\n case \"set_meta\":\n return [{ t: \"set_meta\", patch: pick(doc.meta, Object.keys(op.patch)) }];\n\n case \"set_theme\":\n return [{ t: \"set_theme\", patch: pick(doc.theme, Object.keys(op.patch)) }];\n\n case \"reorder_roots\":\n return [{ t: \"reorder_roots\", order: childrenOf(doc, null).map((n) => n.id) }];\n\n default:\n return [];\n }\n}\n\nfunction pick<T extends object>(obj: T, keys: string[]): Partial<T> {\n const out: Partial<T> = {};\n for (const k of keys) (out as Record<string, unknown>)[k] = (obj as Record<string, unknown>)[k];\n return out;\n}\n","/**\n * Forward migration for documents saved before roots were ordered like every\n * other sibling group.\n *\n * ## Why this cannot be skipped\n *\n * The old model carried top-level order TWICE: a `sections: NodeId[]` array, and\n * an `order` key on every node like any other sibling. The old `reorder_sections`\n * op permuted the array and **left the order keys untouched** — so the moment a\n * user dragged a section, the two disagreed, and `sections[]` was the one that\n * won (it was what the renderer walked).\n *\n * Which means: dropping `sections[]` and falling back to the order keys does not\n * merely lose a redundant field. On every page whose sections were ever\n * rearranged, it silently reverts them to the order they were first created in.\n * The page still loads, nothing throws, and the layout is wrong.\n *\n * So the migration rewrites root `order` keys to agree with `sections[]` before\n * the array is discarded. `sections[]` is treated as authoritative for exactly\n * the reason above.\n *\n * ## Idempotent, and safe on already-migrated documents\n *\n * A doc with no `sections` is returned unchanged (same reference). Running this\n * twice is a no-op, so a host can call it unconditionally on load rather than\n * tracking a schema version.\n */\n\nimport { fractionalKey } from \"@particle-academy/fancy-doc-commons\";\nimport type { NodeId, PageDoc } from \"./types\";\n\n/** A `PageDoc` as persisted before this change — with the extra array. */\nexport type LegacyPageDoc = PageDoc & { sections?: NodeId[] };\n\nexport interface MigrateResult {\n doc: PageDoc;\n /** True when the input actually carried `sections[]` and was rewritten. */\n migrated: boolean;\n /**\n * Ids listed in `sections[]` with no matching node. Skipped rather than\n * faulted — a dangling id is a stale write, and refusing to open the document\n * over it would be a worse outcome than dropping it.\n */\n danglingIds: NodeId[];\n /**\n * Roots present in `nodes` but missing from `sections[]`. Under the old model\n * these did not render at all. They are appended after the listed sections, in\n * their existing order-key order, because making a node visible is recoverable\n * and deleting one is not.\n */\n unlistedRootIds: NodeId[];\n}\n\n/**\n * Migrate a possibly-legacy document, reporting what was found.\n *\n * Use {@link migrateDoc} unless you want the diagnostics.\n */\nexport function migrateDocVerbose(input: LegacyPageDoc | PageDoc): MigrateResult {\n const legacy = input as LegacyPageDoc;\n const sections = legacy.sections;\n\n if (!Array.isArray(sections)) {\n return { doc: input as PageDoc, migrated: false, danglingIds: [], unlistedRootIds: [] };\n }\n\n const danglingIds: NodeId[] = [];\n const ordered: NodeId[] = [];\n const seen = new Set<NodeId>();\n\n for (const id of sections) {\n if (!input.nodes[id]) {\n danglingIds.push(id);\n continue;\n }\n // A duplicate id in the array would otherwise be minted two order keys, and\n // the second would overwrite the first — take the first occurrence.\n if (seen.has(id)) continue;\n seen.add(id);\n ordered.push(id);\n }\n\n // Roots that the array never mentioned. Sorted by their existing key so their\n // relative order is at least stable rather than dependent on object insertion.\n const unlistedRootIds = Object.values(input.nodes)\n .filter((n) => n.parent === null && !seen.has(n.id))\n .sort((a, b) => (a.order < b.order ? -1 : a.order > b.order ? 1 : 0))\n .map((n) => n.id);\n\n const finalOrder = [...ordered, ...unlistedRootIds];\n\n const nodes = { ...input.nodes };\n let prev: string | null = null;\n\n for (const id of finalOrder) {\n const key = fractionalKey(prev, null);\n nodes[id] = { ...nodes[id]!, order: key };\n prev = key;\n }\n\n const { sections: _dropped, ...rest } = legacy;\n\n return {\n doc: { ...rest, nodes } as PageDoc,\n migrated: true,\n danglingIds,\n unlistedRootIds,\n };\n}\n\n/**\n * Migrate a possibly-legacy document. Safe to call on every load — an\n * already-migrated document is returned unchanged, by reference.\n */\nexport function migrateDoc(input: LegacyPageDoc | PageDoc): PageDoc {\n return migrateDocVerbose(input).doc;\n}\n\n/** True when the document still carries the pre-migration `sections[]` array. */\nexport function needsMigration(input: LegacyPageDoc | PageDoc): boolean {\n return Array.isArray((input as LegacyPageDoc).sections);\n}\n","/**\n * The JS style → CSS emitter (one half of the dual-emitter pair; the PHP\n * `particle-academy/fancy-cms` mirrors it byte-for-byte). Output is\n * **deterministic**: declarations are sorted, selectors and media blocks use a\n * fixed format, and nodes are emitted in sorted-id order — so the parity harness\n * can diff the two engines' CSS exactly.\n *\n * Phase 0 covers the static subset (layout / constraints / style). Motion lands\n * in Phase 2.\n */\nimport {\n DEFAULT_BREAKPOINTS,\n type Constraints,\n type Length,\n type Node,\n type PageDoc,\n type SizeMode,\n type StyleProps,\n} from \"../document/types\";\n\nconst selectorFor = (id: string): string => `[data-cms=\"${id}\"]`;\n\nfunction lengthToCss(len: Length): string {\n return `${len.value}${len.unit}`;\n}\n\nfunction sizeToCss(size: SizeMode): string {\n if (size === \"fill\") return \"100%\";\n if (size === \"hug\") return \"auto\";\n return lengthToCss(size);\n}\n\nconst ALIGN: Record<string, string> = {\n start: \"flex-start\",\n center: \"center\",\n end: \"flex-end\",\n stretch: \"stretch\",\n};\nconst JUSTIFY: Record<string, string> = {\n start: \"flex-start\",\n center: \"center\",\n end: \"flex-end\",\n between: \"space-between\",\n around: \"space-around\",\n};\n\n/** Map StyleProps → CSS declarations (property → value). */\nfunction styleDecls(style: Partial<StyleProps>): Record<string, string> {\n const d: Record<string, string> = {};\n if (style.padding) d[\"padding\"] = lengthToCss(style.padding);\n if (style.margin) d[\"margin\"] = lengthToCss(style.margin);\n if (style.radius) d[\"border-radius\"] = lengthToCss(style.radius);\n if (style.background !== undefined) d[\"background\"] = style.background;\n if (style.color !== undefined) d[\"color\"] = style.color;\n if (style.opacity !== undefined) d[\"opacity\"] = String(style.opacity);\n if (style.fontFamily !== undefined) d[\"font-family\"] = style.fontFamily;\n if (style.fontSize) d[\"font-size\"] = lengthToCss(style.fontSize);\n if (style.fontWeight !== undefined) d[\"font-weight\"] = String(style.fontWeight);\n if (style.lineHeight !== undefined) d[\"line-height\"] = String(style.lineHeight);\n if (style.textAlign !== undefined) d[\"text-align\"] = style.textAlign;\n if (style.letterSpacing) d[\"letter-spacing\"] = lengthToCss(style.letterSpacing);\n if (style.border !== undefined) d[\"border\"] = style.border;\n if (style.boxShadow !== undefined) d[\"box-shadow\"] = style.boxShadow;\n if (style.transform !== undefined) d[\"transform\"] = style.transform;\n if (style.filter !== undefined) d[\"filter\"] = style.filter;\n if (style.gap) d[\"gap\"] = lengthToCss(style.gap);\n if (style.align !== undefined) d[\"align-items\"] = ALIGN[style.align] ?? style.align;\n if (style.justify !== undefined) d[\"justify-content\"] = JUSTIFY[style.justify] ?? style.justify;\n return d;\n}\n\n/** Container behaviour from `node.layout`. */\nfunction layoutDecls(node: Node): Record<string, string> {\n const d: Record<string, string> = {};\n if (node.layout === \"stack\") {\n d[\"display\"] = \"flex\";\n d[\"flex-direction\"] = node.style.base.direction ?? \"column\";\n } else if (node.layout === \"grid\") {\n d[\"display\"] = \"grid\";\n d[\"grid-template-columns\"] = `repeat(${node.style.base.columns ?? 1}, 1fr)`;\n } else if (node.layout === \"free\") {\n d[\"position\"] = \"relative\";\n }\n return d;\n}\n\n/** Self-positioning from constraints (absolute pins only inside a `free` parent). */\nfunction constraintDecls(c: Partial<Constraints>, parentFree: boolean): Record<string, string> {\n const d: Record<string, string> = {};\n const transforms: string[] = [];\n if (parentFree) {\n d[\"position\"] = \"absolute\";\n if (c.left) d[\"left\"] = lengthToCss(c.left);\n if (c.right) d[\"right\"] = lengthToCss(c.right);\n if (c.top) d[\"top\"] = lengthToCss(c.top);\n if (c.bottom) d[\"bottom\"] = lengthToCss(c.bottom);\n if (c.centerX) {\n d[\"left\"] = \"50%\";\n transforms.push(\"translateX(-50%)\");\n }\n if (c.centerY) {\n d[\"top\"] = \"50%\";\n transforms.push(\"translateY(-50%)\");\n }\n if (transforms.length) d[\"transform\"] = transforms.join(\" \");\n }\n if (c.width) d[\"width\"] = sizeToCss(c.width);\n if (c.height) d[\"height\"] = sizeToCss(c.height);\n return d;\n}\n\nfunction isParentFree(doc: PageDoc, node: Node): boolean {\n if (node.parent === null) return false; // sections stack in the page flow\n const parent = doc.nodes[node.parent];\n return !parent || parent.layout === undefined || parent.layout === \"free\";\n}\n\nfunction serializeRule(selector: string, decls: Record<string, string>, indent: string): string {\n const props = Object.keys(decls).sort();\n if (props.length === 0) return \"\";\n const body = props.map((p) => `${indent} ${p}: ${decls[p]};`).join(\"\\n\");\n return `${indent}${selector} {\\n${body}\\n${indent}}`;\n}\n\n/** Emit the full stylesheet for a document. Deterministic. */\nexport function emitDocCss(doc: PageDoc): string {\n const breakpointPx = DEFAULT_BREAKPOINTS;\n const blocks: string[] = [];\n\n for (const id of Object.keys(doc.nodes).sort()) {\n const node = doc.nodes[id]!;\n const selector = selectorFor(id);\n const parentFree = isParentFree(doc, node);\n\n // base = style.base + layout + constraints.base\n const base: Record<string, string> = {\n ...layoutDecls(node),\n ...(node.constraints ? constraintDecls(node.constraints.base, parentFree) : {}),\n ...styleDecls(node.style.base),\n };\n const baseRule = serializeRule(selector, base, \"\");\n if (baseRule) blocks.push(baseRule);\n\n // per-breakpoint overrides (mobile-first, in doc order, skipping base)\n for (const bp of doc.breakpoints) {\n if (bp === \"base\") continue;\n const px = breakpointPx[bp];\n if (px === undefined) continue;\n const decls: Record<string, string> = {\n ...(node.constraints?.[bp] ? constraintDecls(node.constraints[bp]!, parentFree) : {}),\n ...(node.style[bp] ? styleDecls(node.style[bp]!) : {}),\n };\n const inner = serializeRule(selector, decls, \" \");\n if (inner) blocks.push(`@media (min-width: ${px}px) {\\n${inner}\\n}`);\n }\n }\n\n return blocks.join(\"\\n\\n\") + (blocks.length ? \"\\n\" : \"\");\n}\n","import type { ReactNode } from \"react\";\nimport { isBinding, type Bound, type Json, type Node, type PageDoc } from \"../document/types\";\n\n/** The page data context bindings resolve against (e.g. server props, repeater `item`). */\nexport type DataContext = Record<string, unknown>;\n\nexport interface ElementContext {\n node: Node;\n doc: PageDoc;\n /** Pre-rendered child nodes, in order. */\n children: ReactNode;\n /** The data context this node renders in (page data + any repeater scope). */\n data?: DataContext;\n /** Resolve a (possibly bound) value to its raw resolved value. */\n resolve: (v: Bound<Json> | undefined) => unknown;\n /** Resolve a (possibly bound) value to a display string. */\n text: (v: Bound<Json> | undefined) => string;\n}\n\n/**\n * Renders the INNER content of a node. The outer `[data-cms]` wrapper is added\n * by {@link RenderNode}, so a renderer only returns what goes inside.\n */\nexport type ElementRenderer = (ctx: ElementContext) => ReactNode;\n\nexport type ElementRegistry = Record<string, ElementRenderer>;\n\n/** Read a dotted path (`a.b.c`) out of the data context. */\nexport function getPath(data: DataContext | undefined, path: string): unknown {\n return path.split(\".\").reduce<unknown>((o, k) => (o == null ? undefined : (o as Record<string, unknown>)[k]), data);\n}\n\n/** Resolve a value: a `{ $bind }` reads from the data context; anything else is literal. */\nexport function resolveValue(v: Bound<Json> | undefined, data?: DataContext): unknown {\n if (v === undefined || v === null) return v;\n if (isBinding(v)) return getPath(data, v.$bind);\n return v;\n}\n\n/** Built-in native elements. Containers render their children; leaves render content. */\nexport const defaultRegistry: ElementRegistry = {\n section: ({ children }) => children,\n stack: ({ children }) => children,\n grid: ({ children }) => children,\n frame: ({ children }) => children,\n shape: ({ children }) => children,\n card: ({ children }) => children,\n text: ({ node, text }) => text(node.props.content),\n heading: ({ node, text }) => text(node.props.content) || \"Heading\",\n // Rich text — inline-formatted HTML (gradient spans, links, <code>, …) that\n // plain `text` can't express. The author owns the markup (it's their content).\n richtext: ({ node, text }) => <div dangerouslySetInnerHTML={{ __html: text(node.props.html) }} />,\n link: ({ node, text }) => (\n <a href={text(node.props.href) || \"#\"} style={{ color: \"inherit\", textDecoration: \"underline\" }}>\n {text(node.props.content) || \"link\"}\n </a>\n ),\n divider: () => <hr style={{ border: \"none\", borderTop: \"1px solid #e2e8f0\", margin: 0 }} />,\n callout: ({ node, text }) => {\n const tone = ({ info: \"#3b82f6\", success: \"#10b981\", warning: \"#f59e0b\", danger: \"#ef4444\" } as Record<string, string>)[text(node.props.variant)] ?? \"#3b82f6\";\n return (\n <div style={{ display: \"flex\", gap: 10, padding: \"12px 14px\", borderRadius: 10, background: `${tone}14`, borderLeft: `3px solid ${tone}` }}>\n <span style={{ fontSize: 13 }}>{text(node.props.content) || \"Callout\"}</span>\n </div>\n );\n },\n code: ({ node, text }) => (\n <pre style={{ margin: 0, padding: \"12px 14px\", borderRadius: 10, background: \"#0b1220\", color: \"#e2e8f0\", fontFamily: \"ui-monospace, monospace\", fontSize: 13, overflowX: \"auto\" }}>\n <code>{text(node.props.content)}</code>\n </pre>\n ),\n button: ({ node, text }) => {\n const label = text(node.props.label) || text(node.props.content) || \"Button\";\n const variant = text(node.props.variant) || \"primary\";\n return <span data-cms-button={variant} style={buttonStyle(variant)}>{label}</span>;\n },\n image: ({ node, text }) => (\n <img\n src={text(node.props.src)}\n alt={text(node.props.alt)}\n style={{ width: \"100%\", height: \"100%\", objectFit: \"cover\", display: \"block\" }}\n />\n ),\n};\n\n/**\n * A self-contained button look so the `button` primitive renders sensibly with\n * zero host CSS. Hosts that want their own button classes override the `button`\n * renderer in their registry (e.g. the sandbox maps it to `.btn .btn-primary`).\n */\nfunction buttonStyle(variant: string): import(\"react\").CSSProperties {\n const base: import(\"react\").CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n gap: 6,\n padding: \"9px 16px\",\n borderRadius: 8,\n fontWeight: 600,\n fontSize: 14,\n lineHeight: 1,\n cursor: \"pointer\",\n userSelect: \"none\",\n };\n if (variant === \"ghost\") return { ...base, background: \"transparent\", color: \"inherit\", border: \"1px solid currentColor\" };\n if (variant === \"outline\") return { ...base, background: \"transparent\", color: \"#7c3aed\", border: \"1px solid #7c3aed\" };\n return { ...base, background: \"#7c3aed\", color: \"#fff\", border: \"1px solid #7c3aed\" };\n}\n","import type { ReactElement } from \"react\";\nimport type { Bound, Json, PageDoc } from \"../document/types\";\nimport { childrenOf } from \"../document/reduce\";\nimport { defaultRegistry, resolveValue, type DataContext, type ElementRegistry } from \"./registry\";\n\nexport interface RenderNodeProps {\n doc: PageDoc;\n id: string;\n registry?: ElementRegistry;\n /** Data context bindings resolve against (page data + any repeater scope). */\n data?: DataContext;\n}\n\n/**\n * Render one node (and its subtree) to a `[data-cms]`-tagged element. The CSS\n * emitted by `emitDocCss` targets these `data-cms` handles. Interactive /\n * 3rd-party **islands** with no registered renderer become an empty, sized\n * placeholder the host hydrates client-side — mirroring the PHP renderer.\n *\n * `repeater` nodes are special-cased: their first child is a template rendered\n * once per item of the bound `items` array, each in a scope that exposes `item`\n * and `index` to nested `{ $bind: \"item.…\" }` bindings.\n */\nexport function RenderNode({ doc, id, registry = defaultRegistry, data }: RenderNodeProps): ReactElement | null {\n const node = doc.nodes[id];\n if (!node) return null;\n\n if (node.type === \"repeater\") {\n const arr = resolveValue(node.props.items as Bound<Json> | undefined, data);\n const items = Array.isArray(arr) ? arr : [];\n const template = childrenOf(doc, id)[0];\n return (\n <div data-cms={node.id} className={node.className}>\n {template\n ? items.map((item, index) => (\n <RenderNode key={index} doc={doc} id={template.id} registry={registry} data={{ ...data, item, index }} />\n ))\n : null}\n </div>\n );\n }\n\n const kids = childrenOf(doc, id).map((child) => (\n <RenderNode key={child.id} doc={doc} id={child.id} registry={registry} data={data} />\n ));\n\n const resolve = (v: Bound<Json> | undefined) => resolveValue(v, data);\n const text = (v: Bound<Json> | undefined): string => {\n const r = resolve(v);\n return r === undefined || r === null ? \"\" : String(r);\n };\n\n const renderer = registry[node.type];\n const inner = renderer ? renderer({ node, doc, children: kids, data, resolve, text }) : node.island ? null : kids;\n\n return (\n <div data-cms={node.id} data-cms-island={node.island ? node.type : undefined} className={node.className}>\n {inner}\n </div>\n );\n}\n","import { Fragment, useMemo, type ReactElement } from \"react\";\nimport type { PageDoc } from \"../document/types\";\nimport { rootIds } from \"../document/reduce\";\nimport { migrateDoc, type LegacyPageDoc } from \"../document/migrate\";\nimport { emitDocCss } from \"../render/css\";\nimport { RenderNode } from \"./RenderNode\";\nimport { defaultRegistry, type DataContext, type ElementRegistry } from \"./registry\";\n\nexport interface CmsPageProps {\n doc: LegacyPageDoc | PageDoc;\n registry?: ElementRegistry;\n /** Data context that `{ $bind: \"…\" }` props + repeaters resolve against. */\n data?: DataContext;\n /** Inject the compiled stylesheet. Set false when the host emits CSS itself. */\n includeStyles?: boolean;\n}\n\n/** Render a full page document: the compiled stylesheet + every section. */\nexport function CmsPage({\n doc: input,\n registry = defaultRegistry,\n data,\n includeStyles = true,\n}: CmsPageProps): ReactElement {\n // Renders a pre-`sections[]` document correctly rather than in whatever order\n // its stale order keys happen to imply. The check is an `Array.isArray`, and\n // an already-migrated document comes back by reference, so the memo costs a\n // migrated host nothing.\n const doc = useMemo(() => migrateDoc(input), [input]);\n\n return (\n <Fragment>\n {includeStyles ? <style data-cms-styles=\"\">{emitDocCss(doc)}</style> : null}\n {rootIds(doc).map((id: string) => (\n <RenderNode key={id} doc={doc} id={id} registry={registry} data={data} />\n ))}\n </Fragment>\n );\n}\n"]}
|