@elytracms/studio 0.0.92 → 0.0.93

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.
Files changed (241) hide show
  1. package/convex/asset-alt-migration.test.ts +127 -0
  2. package/convex/asset-replace.test.ts +168 -0
  3. package/convex/asset-revalidate.test.ts +6 -6
  4. package/convex/assets.ts +41 -5
  5. package/convex/cms.ts +25 -11
  6. package/convex/contract-parity.test.ts +18 -3
  7. package/convex/document-revalidate.test.ts +10 -12
  8. package/convex/orphan-hydration.test.ts +116 -0
  9. package/convex/rail-write-parity.test.ts +11 -8
  10. package/convex/schema.ts +6 -0
  11. package/dist/components/ai/proposal-card.js +2 -1
  12. package/dist/components/ai/proposal-card.js.map +1 -1
  13. package/dist/components/ai/translate-document-dialog.js +4 -2
  14. package/dist/components/ai/translate-document-dialog.js.map +1 -1
  15. package/dist/components/ai/translate-skipped.d.ts +19 -0
  16. package/dist/components/ai/translate-skipped.js +46 -0
  17. package/dist/components/ai/translate-skipped.js.map +1 -0
  18. package/dist/components/assets/asset-detail.js +18 -8
  19. package/dist/components/assets/asset-detail.js.map +1 -1
  20. package/dist/components/assets/asset-metadata.d.ts +15 -4
  21. package/dist/components/assets/asset-metadata.js +15 -2
  22. package/dist/components/assets/asset-metadata.js.map +1 -1
  23. package/dist/components/assets/asset-search.js +4 -1
  24. package/dist/components/assets/asset-search.js.map +1 -1
  25. package/dist/components/assets/asset-selection.d.ts +0 -8
  26. package/dist/components/assets/asset-selection.js +4 -23
  27. package/dist/components/assets/asset-selection.js.map +1 -1
  28. package/dist/components/assets/asset-thumb.js +3 -2
  29. package/dist/components/assets/asset-thumb.js.map +1 -1
  30. package/dist/components/assets/assets-collection-view-source.d.ts +3 -3
  31. package/dist/components/assets/assets-collection-view-source.js +9 -5
  32. package/dist/components/assets/assets-collection-view-source.js.map +1 -1
  33. package/dist/components/assets/assets-store.d.ts +14 -0
  34. package/dist/components/assets/assets-store.js +23 -1
  35. package/dist/components/assets/assets-store.js.map +1 -1
  36. package/dist/components/assets/replace-file.d.ts +22 -0
  37. package/dist/components/assets/replace-file.js +59 -0
  38. package/dist/components/assets/replace-file.js.map +1 -0
  39. package/dist/components/builder/blocks-model.d.ts +14 -26
  40. package/dist/components/builder/blocks-model.js +35 -41
  41. package/dist/components/builder/blocks-model.js.map +1 -1
  42. package/dist/components/builder/blocks-panel.d.ts +7 -3
  43. package/dist/components/builder/blocks-panel.js +6 -5
  44. package/dist/components/builder/blocks-panel.js.map +1 -1
  45. package/dist/components/builder/builder-store.d.ts +104 -15
  46. package/dist/components/builder/builder-store.js +156 -31
  47. package/dist/components/builder/builder-store.js.map +1 -1
  48. package/dist/components/builder/canvas-body.d.ts +30 -0
  49. package/dist/components/builder/canvas-body.js +38 -0
  50. package/dist/components/builder/canvas-body.js.map +1 -0
  51. package/dist/components/builder/canvas-chrome-css.js +7 -0
  52. package/dist/components/builder/canvas-chrome-css.js.map +1 -1
  53. package/dist/components/builder/canvas-dnd.d.ts +7 -7
  54. package/dist/components/builder/canvas-dnd.js +5 -5
  55. package/dist/components/builder/canvas-dnd.js.map +1 -1
  56. package/dist/components/builder/canvas-render-context.d.ts +27 -19
  57. package/dist/components/builder/canvas-render-context.js +42 -43
  58. package/dist/components/builder/canvas-render-context.js.map +1 -1
  59. package/dist/components/builder/canvas-runs.d.ts +45 -0
  60. package/dist/components/builder/canvas-runs.js +51 -0
  61. package/dist/components/builder/canvas-runs.js.map +1 -0
  62. package/dist/components/builder/canvas.js +32 -5
  63. package/dist/components/builder/canvas.js.map +1 -1
  64. package/dist/components/builder/clipboard-actions.d.ts +15 -0
  65. package/dist/components/builder/clipboard-actions.js +44 -7
  66. package/dist/components/builder/clipboard-actions.js.map +1 -1
  67. package/dist/components/builder/composition-field-editor.d.ts +3 -15
  68. package/dist/components/builder/composition-field-editor.js +29 -40
  69. package/dist/components/builder/composition-field-editor.js.map +1 -1
  70. package/dist/components/builder/delete-key.d.ts +5 -0
  71. package/dist/components/builder/delete-key.js +4 -0
  72. package/dist/components/builder/delete-key.js.map +1 -1
  73. package/dist/components/builder/insert-context.d.ts +17 -25
  74. package/dist/components/builder/insert-context.js +45 -92
  75. package/dist/components/builder/insert-context.js.map +1 -1
  76. package/dist/components/builder/page-tree.d.ts +3 -3
  77. package/dist/components/builder/page-tree.js +3 -3
  78. package/dist/components/builder/page-tree.js.map +1 -1
  79. package/dist/components/builder/placement-refusal.d.ts +18 -0
  80. package/dist/components/builder/placement-refusal.js +46 -0
  81. package/dist/components/builder/placement-refusal.js.map +1 -0
  82. package/dist/components/builder/property-inspector.js +4 -0
  83. package/dist/components/builder/property-inspector.js.map +1 -1
  84. package/dist/components/builder/reuse-context.js +65 -27
  85. package/dist/components/builder/reuse-context.js.map +1 -1
  86. package/dist/components/builder/reuse.d.ts +79 -1
  87. package/dist/components/builder/reuse.js +69 -2
  88. package/dist/components/builder/reuse.js.map +1 -1
  89. package/dist/components/builder/run-inspector.d.ts +11 -0
  90. package/dist/components/builder/run-inspector.js +33 -0
  91. package/dist/components/builder/run-inspector.js.map +1 -0
  92. package/dist/components/cms/asset-field.d.ts +38 -1
  93. package/dist/components/cms/asset-field.js +182 -58
  94. package/dist/components/cms/asset-field.js.map +1 -1
  95. package/dist/components/cms/asset-picker-core.d.ts +16 -0
  96. package/dist/components/cms/asset-picker-core.js +20 -0
  97. package/dist/components/cms/asset-picker-core.js.map +1 -1
  98. package/dist/components/cms/asset-picker.js +12 -18
  99. package/dist/components/cms/asset-picker.js.map +1 -1
  100. package/dist/components/cms/bulk-actions.d.ts +3 -19
  101. package/dist/components/cms/bulk-actions.js +3 -24
  102. package/dist/components/cms/bulk-actions.js.map +1 -1
  103. package/dist/components/cms/cell.js.map +1 -1
  104. package/dist/components/cms/cms-store.d.ts +5 -4
  105. package/dist/components/cms/cms-store.js +16 -36
  106. package/dist/components/cms/cms-store.js.map +1 -1
  107. package/dist/components/cms/detail-editor.js +0 -1
  108. package/dist/components/cms/detail-editor.js.map +1 -1
  109. package/dist/components/cms/document-diff-view.d.ts +3 -1
  110. package/dist/components/cms/document-diff-view.js +12 -7
  111. package/dist/components/cms/document-diff-view.js.map +1 -1
  112. package/dist/components/cms/field-anchors.d.ts +7 -4
  113. package/dist/components/cms/field-anchors.js +9 -7
  114. package/dist/components/cms/field-anchors.js.map +1 -1
  115. package/dist/components/cms/field-control-lib.d.ts +15 -1
  116. package/dist/components/cms/field-control-lib.js +22 -3
  117. package/dist/components/cms/field-control-lib.js.map +1 -1
  118. package/dist/components/cms/gate-validation.d.ts +21 -30
  119. package/dist/components/cms/gate-validation.js +11 -32
  120. package/dist/components/cms/gate-validation.js.map +1 -1
  121. package/dist/components/cms/object-array-field.js +4 -4
  122. package/dist/components/cms/object-array-field.js.map +1 -1
  123. package/dist/components/cms/prop-fields.d.ts +7 -2
  124. package/dist/components/cms/prop-fields.js +13 -6
  125. package/dist/components/cms/prop-fields.js.map +1 -1
  126. package/dist/components/cms/rich-text/embed-picker.d.ts +1 -1
  127. package/dist/components/cms/rich-text/embed-picker.js.map +1 -1
  128. package/dist/components/cms/rich-text/insert.d.ts +20 -9
  129. package/dist/components/cms/rich-text/insert.js +25 -17
  130. package/dist/components/cms/rich-text/insert.js.map +1 -1
  131. package/dist/components/cms/use-publish-controller.d.ts +1 -2
  132. package/dist/components/cms/use-publish-controller.js +7 -19
  133. package/dist/components/cms/use-publish-controller.js.map +1 -1
  134. package/dist/components/cms/versions-pane.js +8 -1
  135. package/dist/components/cms/versions-pane.js.map +1 -1
  136. package/dist/components/collection-view/cms-collection-view-source.js +3 -1
  137. package/dist/components/collection-view/cms-collection-view-source.js.map +1 -1
  138. package/dist/components/components/transfer-dialog.js +2 -1
  139. package/dist/components/components/transfer-dialog.js.map +1 -1
  140. package/dist/components/components/transfer.d.ts +10 -10
  141. package/dist/components/components/transfer.js +13 -12
  142. package/dist/components/components/transfer.js.map +1 -1
  143. package/dist/lib/ai/apply-content.js +56 -116
  144. package/dist/lib/ai/apply-content.js.map +1 -1
  145. package/dist/lib/ai/chat-context.d.ts +8 -0
  146. package/dist/lib/ai/chat-context.js +37 -6
  147. package/dist/lib/ai/chat-context.js.map +1 -1
  148. package/dist/lib/ai/chat-state.d.ts +6 -0
  149. package/dist/lib/ai/chat-state.js.map +1 -1
  150. package/dist/lib/ai/constraints.d.ts +20 -5
  151. package/dist/lib/ai/constraints.js +125 -33
  152. package/dist/lib/ai/constraints.js.map +1 -1
  153. package/dist/lib/ai/fake-provider.d.ts +16 -3
  154. package/dist/lib/ai/fake-provider.js +22 -6
  155. package/dist/lib/ai/fake-provider.js.map +1 -1
  156. package/dist/lib/ai/index.d.ts +2 -0
  157. package/dist/lib/ai/index.js +2 -0
  158. package/dist/lib/ai/index.js.map +1 -1
  159. package/dist/lib/ai/leash.d.ts +34 -0
  160. package/dist/lib/ai/leash.js +28 -0
  161. package/dist/lib/ai/leash.js.map +1 -0
  162. package/dist/lib/ai/rich-text-input.d.ts +8 -8
  163. package/dist/lib/ai/rich-text-input.js +2 -1
  164. package/dist/lib/ai/rich-text-input.js.map +1 -1
  165. package/dist/lib/ai/rich-text-translate.d.ts +27 -4
  166. package/dist/lib/ai/rich-text-translate.js +28 -10
  167. package/dist/lib/ai/rich-text-translate.js.map +1 -1
  168. package/dist/lib/ai/shape.d.ts +13 -13
  169. package/dist/lib/ai/shape.js +69 -93
  170. package/dist/lib/ai/shape.js.map +1 -1
  171. package/dist/lib/ai/tools.d.ts +36 -41
  172. package/dist/lib/ai/tools.js +83 -87
  173. package/dist/lib/ai/tools.js.map +1 -1
  174. package/dist/lib/ai/translate-document.d.ts +32 -4
  175. package/dist/lib/ai/translate-document.js +144 -46
  176. package/dist/lib/ai/translate-document.js.map +1 -1
  177. package/dist/lib/ai/types.d.ts +34 -23
  178. package/dist/lib/ai/types.js.map +1 -1
  179. package/dist/lib/ai/update-fields.d.ts +15 -12
  180. package/dist/lib/ai/update-fields.js +112 -188
  181. package/dist/lib/ai/update-fields.js.map +1 -1
  182. package/dist/lib/ai/writer-form.d.ts +116 -0
  183. package/dist/lib/ai/writer-form.js +429 -0
  184. package/dist/lib/ai/writer-form.js.map +1 -0
  185. package/dist/lib/assets/upload.d.ts +31 -2
  186. package/dist/lib/assets/upload.js +61 -6
  187. package/dist/lib/assets/upload.js.map +1 -1
  188. package/dist/lib/clipboard/os-clipboard.d.ts +10 -2
  189. package/dist/lib/clipboard/os-clipboard.js +8 -4
  190. package/dist/lib/clipboard/os-clipboard.js.map +1 -1
  191. package/dist/lib/clipboard/paste-target.d.ts +18 -9
  192. package/dist/lib/clipboard/paste-target.js +8 -7
  193. package/dist/lib/clipboard/paste-target.js.map +1 -1
  194. package/dist/lib/cms/field-patch.d.ts +0 -10
  195. package/dist/lib/cms/field-patch.js +4 -30
  196. package/dist/lib/cms/field-patch.js.map +1 -1
  197. package/dist/lib/cms-views/view-model.d.ts +3 -3
  198. package/dist/lib/collection-view/collection-view-source.d.ts +7 -3
  199. package/dist/lib/collection-view/collection-view-source.js.map +1 -1
  200. package/dist/lib/data/collection-content.js +3 -2
  201. package/dist/lib/data/collection-content.js.map +1 -1
  202. package/dist/lib/dnd/drop-rules.d.ts +25 -31
  203. package/dist/lib/dnd/drop-rules.js +53 -59
  204. package/dist/lib/dnd/drop-rules.js.map +1 -1
  205. package/dist/lib/engine-version.d.ts +1 -1
  206. package/dist/lib/engine-version.js +1 -1
  207. package/dist/lib/engine-version.js.map +1 -1
  208. package/dist/lib/i18n/messages.de.js +40 -3
  209. package/dist/lib/i18n/messages.de.js.map +1 -1
  210. package/dist/lib/i18n/messages.en.d.ts +34 -2
  211. package/dist/lib/i18n/messages.en.js +43 -3
  212. package/dist/lib/i18n/messages.en.js.map +1 -1
  213. package/dist/lib/operations/project-runtime-config.d.ts +25 -6
  214. package/dist/lib/operations/project-runtime-config.js +37 -10
  215. package/dist/lib/operations/project-runtime-config.js.map +1 -1
  216. package/dist/lib/operations/publish-with-revision.d.ts +33 -1
  217. package/dist/lib/operations/publish-with-revision.js +32 -0
  218. package/dist/lib/operations/publish-with-revision.js.map +1 -1
  219. package/dist/lib/operations/runtime-validator.d.ts +19 -68
  220. package/dist/lib/operations/runtime-validator.js +12 -138
  221. package/dist/lib/operations/runtime-validator.js.map +1 -1
  222. package/dist/lib/operations/studio-operations.d.ts +9 -2
  223. package/dist/lib/operations/studio-operations.js +13 -11
  224. package/dist/lib/operations/studio-operations.js.map +1 -1
  225. package/dist/lib/persistence/convex-adapter.js +6 -1
  226. package/dist/lib/persistence/convex-adapter.js.map +1 -1
  227. package/dist/lib/persona/labels.js +3 -1
  228. package/dist/lib/persona/labels.js.map +1 -1
  229. package/dist/lib/workspace/index.d.ts +8 -11
  230. package/dist/lib/workspace/index.js +12 -24
  231. package/dist/lib/workspace/index.js.map +1 -1
  232. package/package.json +3 -3
  233. package/dist/components/cms/cms-composition-validators.d.ts +0 -16
  234. package/dist/components/cms/cms-composition-validators.js +0 -133
  235. package/dist/components/cms/cms-composition-validators.js.map +0 -1
  236. package/dist/components/cms/publish-clean.d.ts +0 -28
  237. package/dist/components/cms/publish-clean.js +0 -38
  238. package/dist/components/cms/publish-clean.js.map +0 -1
  239. package/dist/lib/assets/asset-placements.d.ts +0 -28
  240. package/dist/lib/assets/asset-placements.js +0 -83
  241. package/dist/lib/assets/asset-placements.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import type { ReactNode } from 'react';
2
- import type { ComponentNode, InsertTarget, LayoutContainerIds, PropValue } from '@elytracms/core/project-graph';
2
+ import type { AllowList, ComponentLookup, ComponentNode, InsertTarget, LayoutContainerIds, PlacementScope, PlacementVerdict, PropValue } from '@elytracms/core/project-graph';
3
3
  import type { IdFactory } from '@elytracms/core/persistence';
4
+ import type { PreservedItem } from './canvas-runs.js';
4
5
  /**
5
6
  * A canvas preview-width key (EC-250): `'full'` (unconstrained) or a configured
6
7
  * breakpoint name (`'sm'`, `'md'`, …). Dynamic because the set is sourced from
@@ -93,17 +94,72 @@ export type BuilderAction = {
93
94
  type: 'removeProp';
94
95
  id: string;
95
96
  name: string;
97
+ }
98
+ /** EC-584: the editor dismissed the visible refusal ({@link BuilderState.refusal}). */
99
+ | {
100
+ type: 'clearRefusal';
101
+ }
102
+ /**
103
+ * EC-549 — select a typography RUN by its key (`canvas-runs.ts`: the index of its
104
+ * first preserved item); `null` clears it. A run and a node are never both selected.
105
+ */
106
+ | {
107
+ type: 'selectRun';
108
+ run: number | null;
109
+ }
110
+ /** EC-549 — delete a typography run: a real, undoable edit of the preserved list. */
111
+ | {
112
+ type: 'removeRun';
113
+ run: number;
114
+ }
115
+ /**
116
+ * EC-549 — replace a run's typography with `content` (the inspector's rich-text
117
+ * editor on that run; consecutive same-key edits coalesce into one undo step). Empty
118
+ * `content` deletes the run.
119
+ */
120
+ | {
121
+ type: 'setRun';
122
+ run: number;
123
+ content: readonly unknown[];
124
+ coalesceKey?: string;
96
125
  };
126
+ /** The structural actions the placement judge rules on (EC-584): every node that enters or moves. */
127
+ export type PlacingAction = Extract<BuilderAction, {
128
+ type: 'insert' | 'replace' | 'move' | 'wrap' | 'duplicate';
129
+ }>;
130
+ /** A refused placement (EC-584): the judge's verdict and the action it refused. */
131
+ export interface PlacementRefusal {
132
+ action: PlacingAction['type'];
133
+ verdict: PlacementVerdict;
134
+ }
135
+ /**
136
+ * One history entry (EC-549): the component tree AND the preserved typography — so a
137
+ * run's deletion or edit is undone exactly like a block's.
138
+ */
139
+ export interface CanvasSnapshot {
140
+ root: ComponentNode;
141
+ preserved: readonly PreservedItem[];
142
+ }
97
143
  export interface BuilderState {
98
144
  /**
99
145
  * The edited composition: one root-bearing component tree (EC-287). The canvas
100
146
  * wraps a page document's `body` blocks into a synthetic root and edits it
101
- * directly — no page/layout wrapper. Undo/redo snapshot this root.
147
+ * directly — no page/layout wrapper. Undo/redo snapshot it with the preserved
148
+ * typography ({@link CanvasSnapshot}).
102
149
  */
103
- past: ComponentNode[];
150
+ past: CanvasSnapshot[];
104
151
  present: ComponentNode;
105
- future: ComponentNode[];
152
+ future: CanvasSnapshot[];
153
+ /**
154
+ * EC-549 — the field value's typography items (no ids, EC-500 D1), each anchored by
155
+ * how many component roots preceded it (`componentPrefix`); the field value is
156
+ * `mergeBlockRoots(present's roots, preserved)`. In the store, so selecting,
157
+ * deleting and editing a run is a real action with truthful undo.
158
+ */
159
+ preserved: readonly PreservedItem[];
106
160
  selectedId: string | null;
161
+ /** EC-549 — the selected typography run's key, or `null` (exclusive with {@link selectedId}). */
162
+ selectedRun: number | null;
107
163
  hoveredId: string | null;
108
164
  viewport: Viewport;
109
165
  /**
@@ -121,14 +177,36 @@ export interface BuilderState {
121
177
  * Stack/Grid, and the Grid the wrap gesture builds. No hardcoded engine id.
122
178
  */
123
179
  layout: LayoutContainerIds;
180
+ /**
181
+ * EC-584 — the last REFUSED placement, with its reason: the reducer judged an
182
+ * `insert`/`replace`/`move`/`wrap`/`duplicate` against the field and slot
183
+ * vocabularies and canvas eligibility (the core placement judge) and left the
184
+ * composition unchanged. Transient — the next edit, selection, undo or redo clears
185
+ * it — and never silent: the canvas shows it (`PlacementRefusalNotice`). A refused
186
+ * action changes no tree, so it adds no history entry and emits no canvas patch.
187
+ */
188
+ refusal: PlacementRefusal | null;
124
189
  }
125
190
  type Action = BuilderAction;
126
191
  /**
127
- * The pure state transition. Exported (with `initialBuilderState`) for unit
128
- * tests — gesture determinism and normalization lockstep are reducer-level
129
- * properties, not render behavior.
192
+ * The builder's pure state transition, CONSTRUCTED with the placement scope it judges
193
+ * by (EC-584, owner-ratified 4a): the field's effective top-level vocabulary and the
194
+ * manifest lookup. The scope is static per store and deliberately not reducer STATE
195
+ * (it is the declaration the tree is judged against, not part of the tree) — the
196
+ * reducer RECEIVES it, so there is no `(state, action)` to call without it.
197
+ *
198
+ * Every structural action that places a node — `insert`, `replace`, `move`, `wrap`,
199
+ * `duplicate` — runs the ONE core judge (`subtreePlacementRefusal`) over every node
200
+ * that enters or moves, BEFORE committing. A refusal returns the composition
201
+ * unchanged, with the verdict in {@link BuilderState.refusal}: so no gesture — a
202
+ * forgotten pre-check, promote, detach, a fixture's `slotChildren`, a server-only
203
+ * paste — can place what the field, a slot or canvas eligibility forbids, and the
204
+ * publish gate (which calls the same judge) cannot disagree with the canvas.
205
+ *
206
+ * Exported (with `initialBuilderState`) for unit tests — gesture determinism and
207
+ * normalization lockstep are reducer-level properties, not render behavior.
130
208
  */
131
- export declare function builderReducer(state: BuilderState, action: Action): BuilderState;
209
+ export declare function createBuilderReducer(placement: PlacementScope): (state: BuilderState, action: Action) => BuilderState;
132
210
  /**
133
211
  * The composition FIELD whose value the store edits (EC-554). Static for the
134
212
  * store's lifetime and deliberately NOT reducer state: it is the declaration the
@@ -142,12 +220,11 @@ export interface CompositionFieldScope {
142
220
  /** The field's display label — what a refusal notice names (e.g. "Canvas"). */
143
221
  label: string;
144
222
  /**
145
- * The field's top-level `allow` vocabulary (EC-188; a closed set per EC-544),
146
- * or `undefined` when the field declares none (any registered component).
147
- * Applied only through `fieldAllowAt` (`lib/dnd/drop-rules`), which scopes it
148
- * to direct children of the composition root.
223
+ * The field's EFFECTIVE top-level vocabulary (EC-188; EC-584 — `fieldAllowList(field)`:
224
+ * its `allow`, else the `blocks` type's default). The judge applies it only to
225
+ * direct children of the composition root (`allowAt`, core `placement.ts`).
149
226
  */
150
- allow: readonly string[] | undefined;
227
+ allow: AllowList;
151
228
  }
152
229
  export interface BuilderStore extends BuilderState {
153
230
  canUndo: boolean;
@@ -155,10 +232,18 @@ export interface BuilderStore extends BuilderState {
155
232
  selectedNode: ComponentNode | null;
156
233
  /** The composition field being edited (EC-554) — see {@link CompositionFieldScope}. */
157
234
  field: CompositionFieldScope;
235
+ /**
236
+ * EC-584 — what the reducer judges every placement by: the manifest lookup and the
237
+ * field's vocabulary. The gestures' own pre-checks (drag-and-drop, paste, the insert
238
+ * offer, the reuse preflight) read the SAME scope, so an indicator and the sink agree.
239
+ */
240
+ placement: PlacementScope;
158
241
  dispatch: (action: Action) => void;
159
242
  }
160
243
  declare const useBuilder: () => BuilderStore;
161
- export declare function initialBuilderState(composition: ComponentNode, layout: LayoutContainerIds, newId: IdFactory): BuilderState;
244
+ export declare function initialBuilderState(composition: ComponentNode, layout: LayoutContainerIds, newId: IdFactory,
245
+ /** EC-549 — the field value's typography items with their anchors (`splitBlockRoots`). */
246
+ preserved?: readonly PreservedItem[]): BuilderState;
162
247
  /**
163
248
  * Undo/redo design (EC-141): the history stack is *UI state* — an in-memory
164
249
  * stack of composition-root snapshots. EC-287 retired the DB-resident project
@@ -167,11 +252,15 @@ export declare function initialBuilderState(composition: ComponentNode, layout:
167
252
  * its committed composition into the open CMS document via `onChange`
168
253
  * (`composition-field-editor`); the document's own Save persists it as content.
169
254
  */
170
- export declare function BuilderProvider({ composition, field, layout, idFactory, children, }: {
255
+ export declare function BuilderProvider({ composition, preserved, field, components, layout, idFactory, children, }: {
171
256
  /** The composition root to edit (the composition-field editor's synthetic root). */
172
257
  composition: ComponentNode;
258
+ /** EC-549 — the field value's typography items (`splitBlockRoots(value).preserved`). */
259
+ preserved?: readonly PreservedItem[];
173
260
  /** The field the composition is the value of (EC-554) — required, never defaulted. */
174
261
  field: CompositionFieldScope;
262
+ /** The manifest lookup the placement judge reads (EC-584, `registry.lookup`) — required. */
263
+ components: ComponentLookup;
175
264
  /** The layout-role component ids (EC-591, `ComponentRegistry.layout`) — required. */
176
265
  layout: LayoutContainerIds;
177
266
  /**
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useMemo, useReducer, useState } from 'react';
3
- import { cloneWithNewIds, duplicateNode, getNode, getParentInfo, insertNode, moveNode, normalizeContainers, removeNode, removeNodeProp, reorderNode, replaceNode, setNodeProp, } from '@elytracms/core/project-graph';
3
+ import { DEFAULT_SLOT, cloneWithNewIds, duplicateNode, getNode, getParentInfo, gridContainerNode, insertNode, moveNode, normalizeContainers, removeNode, removeNodeProp, reorderNode, replaceNode, replacePlacementRefusal, setNodeProp, subtreePlacementRefusal, } from '@elytracms/core/project-graph';
4
4
  import { createUuidIdFactory } from '@elytracms/core/persistence';
5
- import { applyWrap } from '@elytracms/studio/lib/dnd/drop-rules';
5
+ import { WRAP_GRID_OPTIONS, applyWrap } from '@elytracms/studio/lib/dnd/drop-rules';
6
+ import { replaceRun, runByKey } from './canvas-runs.js';
6
7
  import { createRequiredContext } from '@elytracms/studio/lib/required-context';
7
8
  const HISTORY_LIMIT = 100;
8
9
  /**
@@ -19,62 +20,128 @@ const HISTORY_LIMIT = 100;
19
20
  function commit(state, root, opts = {}) {
20
21
  const normalized = normalizeContainers(root, state.layout);
21
22
  const present = normalized;
23
+ const preserved = opts.preserved ?? state.preserved;
22
24
  const coalesce = opts.coalesceKey != null && opts.coalesceKey === state.lastCoalesceKey;
23
25
  // Normalization can dissolve the node a caller wanted selected (e.g. the
24
26
  // parent container of a removed child) — selection never points at a ghost.
25
27
  const desired = opts.selectedId !== undefined ? opts.selectedId : state.selectedId;
26
28
  const selectedId = desired !== null && getNode(normalized, desired) ? desired : null;
29
+ const desiredRun = opts.selectedRun !== undefined ? opts.selectedRun : state.selectedRun;
27
30
  return {
28
31
  ...state,
29
- past: coalesce ? state.past : [...state.past, state.present].slice(-HISTORY_LIMIT),
32
+ past: coalesce ? state.past : [...state.past, snapshotOf(state)].slice(-HISTORY_LIMIT),
30
33
  present,
34
+ preserved,
31
35
  future: [],
32
36
  lastCoalesceKey: opts.coalesceKey ?? null,
33
37
  selectedId,
38
+ selectedRun: liveRun(present, preserved, desiredRun),
39
+ refusal: null,
34
40
  };
35
41
  }
42
+ function snapshotOf(state) {
43
+ return { root: state.present, preserved: state.preserved };
44
+ }
45
+ /** The run key if that run still exists in this state, else `null` (never a ghost selection). */
46
+ function liveRun(root, preserved, run) {
47
+ if (run === null)
48
+ return null;
49
+ return runByKey(rootCount(root), preserved, run) ? run : null;
50
+ }
51
+ /** How many component roots the composition has (the synthetic root's children). */
52
+ function rootCount(root) {
53
+ return root.slots?.[DEFAULT_SLOT]?.length ?? 0;
54
+ }
55
+ /** Restore a history entry (undo/redo), keeping a selection only where it still exists. */
56
+ function restore(state, to, past, future) {
57
+ return {
58
+ ...state,
59
+ past,
60
+ present: to.root,
61
+ preserved: to.preserved,
62
+ future,
63
+ lastCoalesceKey: null,
64
+ selectedId: getNode(to.root, state.selectedId ?? '') ? state.selectedId : null,
65
+ selectedRun: liveRun(to.root, to.preserved, state.selectedRun),
66
+ refusal: null,
67
+ };
68
+ }
69
+ /** Leave the composition untouched and say why (EC-584 — never a silent no-op). */
70
+ function refuse(state, action, verdict) {
71
+ return { ...state, refusal: { action: action.type, verdict } };
72
+ }
36
73
  /**
37
- * The pure state transition. Exported (with `initialBuilderState`) for unit
38
- * tests — gesture determinism and normalization lockstep are reducer-level
39
- * properties, not render behavior.
74
+ * The builder's pure state transition, CONSTRUCTED with the placement scope it judges
75
+ * by (EC-584, owner-ratified 4a): the field's effective top-level vocabulary and the
76
+ * manifest lookup. The scope is static per store and deliberately not reducer STATE
77
+ * (it is the declaration the tree is judged against, not part of the tree) — the
78
+ * reducer RECEIVES it, so there is no `(state, action)` to call without it.
79
+ *
80
+ * Every structural action that places a node — `insert`, `replace`, `move`, `wrap`,
81
+ * `duplicate` — runs the ONE core judge (`subtreePlacementRefusal`) over every node
82
+ * that enters or moves, BEFORE committing. A refusal returns the composition
83
+ * unchanged, with the verdict in {@link BuilderState.refusal}: so no gesture — a
84
+ * forgotten pre-check, promote, detach, a fixture's `slotChildren`, a server-only
85
+ * paste — can place what the field, a slot or canvas eligibility forbids, and the
86
+ * publish gate (which calls the same judge) cannot disagree with the canvas.
87
+ *
88
+ * Exported (with `initialBuilderState`) for unit tests — gesture determinism and
89
+ * normalization lockstep are reducer-level properties, not render behavior.
40
90
  */
41
- export function builderReducer(state, action) {
91
+ export function createBuilderReducer(placement) {
92
+ return (state, action) => transition(state, action, placement);
93
+ }
94
+ function transition(state, action, placement) {
42
95
  const root = state.present;
43
96
  switch (action.type) {
44
97
  case 'select':
45
- return { ...state, selectedId: action.id };
98
+ return { ...state, selectedId: action.id, selectedRun: action.id === null ? state.selectedRun : null, refusal: null };
99
+ case 'selectRun':
100
+ return {
101
+ ...state,
102
+ selectedRun: liveRun(root, state.preserved, action.run),
103
+ selectedId: action.run === null ? state.selectedId : null,
104
+ refusal: null,
105
+ };
106
+ case 'removeRun': {
107
+ const run = runByKey(rootCount(root), state.preserved, action.run);
108
+ if (!run)
109
+ return state;
110
+ return commit(state, root, { preserved: replaceRun(state.preserved, run, []), selectedRun: null });
111
+ }
112
+ case 'setRun': {
113
+ const run = runByKey(rootCount(root), state.preserved, action.run);
114
+ if (!run)
115
+ return state;
116
+ return commit(state, root, {
117
+ preserved: replaceRun(state.preserved, run, action.content),
118
+ coalesceKey: action.coalesceKey,
119
+ selectedRun: action.content.length > 0 ? action.run : null,
120
+ });
121
+ }
46
122
  case 'hover':
47
123
  return state.hoveredId === action.id ? state : { ...state, hoveredId: action.id };
48
124
  case 'viewport':
49
125
  return { ...state, viewport: action.viewport };
126
+ case 'clearRefusal':
127
+ return state.refusal === null ? state : { ...state, refusal: null };
50
128
  case 'undo': {
51
129
  const prev = state.past.at(-1);
52
130
  if (!prev)
53
131
  return state;
54
- return {
55
- ...state,
56
- past: state.past.slice(0, -1),
57
- present: prev,
58
- future: [state.present, ...state.future],
59
- lastCoalesceKey: null,
60
- selectedId: getNode(prev, state.selectedId ?? '') ? state.selectedId : null,
61
- };
132
+ return restore(state, prev, state.past.slice(0, -1), [snapshotOf(state), ...state.future]);
62
133
  }
63
134
  case 'redo': {
64
135
  const next = state.future[0];
65
136
  if (!next)
66
137
  return state;
67
- return {
68
- ...state,
69
- past: [...state.past, state.present],
70
- present: next,
71
- future: state.future.slice(1),
72
- lastCoalesceKey: null,
73
- selectedId: getNode(next, state.selectedId ?? '') ? state.selectedId : null,
74
- };
138
+ return restore(state, next, [...state.past, snapshotOf(state)], state.future.slice(1));
75
139
  }
76
140
  case 'insert': {
77
141
  const node = action.minted ? action.node : cloneWithNewIds(action.node, state.newId);
142
+ const verdict = subtreePlacementRefusal(root, node, landingOf(action.target), placement);
143
+ if (verdict)
144
+ return refuse(state, action, verdict);
78
145
  const next = insertNode(root, action.target, node);
79
146
  return commit(state, next, {
80
147
  selectedId: action.select === false ? state.selectedId : node.id,
@@ -87,18 +154,45 @@ export function builderReducer(state, action) {
87
154
  return commit(state, next, { selectedId });
88
155
  }
89
156
  case 'duplicate': {
157
+ // The copy (and every node of its subtree) ENTERS beside the original.
158
+ const info = getParentInfo(root, action.id);
159
+ const source = getNode(root, action.id);
160
+ if (info && source) {
161
+ const verdict = subtreePlacementRefusal(root, source, { parentId: info.parent.id, slot: info.slot }, placement);
162
+ if (verdict)
163
+ return refuse(state, action, verdict);
164
+ }
90
165
  const { root: next, newId } = duplicateNode(root, action.id, state.newId);
91
166
  return commit(state, next, { selectedId: newId ?? state.selectedId });
92
167
  }
93
168
  case 'reorder':
169
+ // Same parent, same slot: the placement does not change — nothing to judge.
94
170
  return commit(state, reorderNode(root, action.id, action.delta));
95
- case 'move':
171
+ case 'move': {
172
+ // A node that changes parent or slot lands somewhere new (its descendants keep
173
+ // their own slots, so only it is judged); a move within its own slot is a
174
+ // reorder and leaves the placement as it was.
175
+ const info = getParentInfo(root, action.id);
176
+ const node = getNode(root, action.id);
177
+ const relocates = !info || info.parent.id !== action.target.parentId || info.slot !== action.target.slot;
178
+ if (node && relocates) {
179
+ const verdict = subtreePlacementRefusal(root, withoutSlots(node), landingOf(action.target), placement);
180
+ if (verdict)
181
+ return refuse(state, action, verdict);
182
+ }
96
183
  return commit(state, moveNode(root, action.id, action.target));
184
+ }
97
185
  case 'replace': {
98
186
  // Mint fresh ids for the incoming nodes (page-local namespace) so a detached
99
187
  // copy never collides with the page, and a promoted block's source subtree
100
188
  // (kept for the new reusable document) stays untouched.
101
189
  const cloned = action.nodes.map((n) => cloneWithNewIds(n, state.newId));
190
+ // EC-560: promote (one embed) and detach (the reusable's content) land where the
191
+ // replaced node was — judged there like any insert (the reuse preflight asks the
192
+ // same `replacePlacementRefusal` before any side effect).
193
+ const verdict = replacePlacementRefusal(root, action.id, cloned, placement);
194
+ if (verdict)
195
+ return refuse(state, action, verdict);
102
196
  const next = replaceNode(root, action.id, cloned);
103
197
  if (next === root)
104
198
  return state; // root or absent id — no-op
@@ -119,6 +213,19 @@ export function builderReducer(state, action) {
119
213
  const gridComponentId = state.layout.grid;
120
214
  if (gridComponentId === undefined)
121
215
  return state;
216
+ // EC-584: the Grid lands where the reference is; the reference and the partner
217
+ // land in the Grid's column slot. A moved partner keeps its own subtree (only it
218
+ // relocates); a new one (a blocks-panel tile) enters whole.
219
+ const reference = getNode(root, action.referenceId);
220
+ const referenceInfo = getParentInfo(root, action.referenceId);
221
+ const partnerNode = partner.kind === 'node' ? getNode(root, partner.nodeId) : partner.node;
222
+ if (reference && referenceInfo && partnerNode) {
223
+ const columns = [withoutSlots(reference), partner.kind === 'node' ? withoutSlots(partnerNode) : partnerNode];
224
+ const probe = gridContainerNode(gridComponentId, 'wrap', WRAP_GRID_OPTIONS, columns);
225
+ const verdict = subtreePlacementRefusal(root, probe, { parentId: referenceInfo.parent.id, slot: referenceInfo.slot }, placement);
226
+ if (verdict)
227
+ return refuse(state, action, verdict);
228
+ }
122
229
  const containerId = state.newId();
123
230
  const wrapped = applyWrap({
124
231
  root,
@@ -142,8 +249,18 @@ export function builderReducer(state, action) {
142
249
  return state;
143
250
  }
144
251
  }
252
+ function landingOf(target) {
253
+ return { parentId: target.parentId, slot: target.slot };
254
+ }
255
+ /** The node alone — a move relocates it; its descendants keep their own slots. */
256
+ function withoutSlots(node) {
257
+ const { slots: _slots, ...rest } = node;
258
+ return rest;
259
+ }
145
260
  const { Context: BuilderContext, useRequired: useBuilder } = createRequiredContext('Builder');
146
- export function initialBuilderState(composition, layout, newId) {
261
+ export function initialBuilderState(composition, layout, newId,
262
+ /** EC-549 — the field value's typography items with their anchors (`splitBlockRoots`). */
263
+ preserved = []) {
147
264
  // Start container-normal (idempotent on healthy trees) so the session and the
148
265
  // lifted baseline agree from the first edit.
149
266
  const present = normalizeContainers(composition, layout);
@@ -151,7 +268,9 @@ export function initialBuilderState(composition, layout, newId) {
151
268
  past: [],
152
269
  present,
153
270
  future: [],
271
+ preserved,
154
272
  selectedId: present.id,
273
+ selectedRun: null,
155
274
  hoveredId: null,
156
275
  viewport: 'full',
157
276
  // EC-578: fresh ids come from the injected factory — never a counter seeded past
@@ -159,6 +278,7 @@ export function initialBuilderState(composition, layout, newId) {
159
278
  newId,
160
279
  lastCoalesceKey: null,
161
280
  layout,
281
+ refusal: null,
162
282
  };
163
283
  }
164
284
  /**
@@ -169,13 +289,17 @@ export function initialBuilderState(composition, layout, newId) {
169
289
  * its committed composition into the open CMS document via `onChange`
170
290
  * (`composition-field-editor`); the document's own Save persists it as content.
171
291
  */
172
- export function BuilderProvider({ composition, field, layout, idFactory, children, }) {
292
+ export function BuilderProvider({ composition, preserved, field, components, layout, idFactory, children, }) {
173
293
  const [newId] = useState(() => idFactory ?? createUuidIdFactory());
294
+ // EC-584: the reducer is constructed ONCE with the scope it judges by — the field
295
+ // and the lookup are static for the store's lifetime (a remount re-reads them).
296
+ const [placement] = useState(() => ({ components, fieldAllow: field.allow }));
297
+ const [reducer] = useState(() => createBuilderReducer(placement));
174
298
  // EC-287: nothing persists a graph — committed edits are lifted into the CMS
175
299
  // document by the composition-field editor's `onChange`. `useReducer` drives the
176
- // pure `builderReducer` (consecutive dispatches in one gesture apply in sequence);
177
- // the store below decorates the state with the derived undo/redo + selection flags.
178
- const [state, dispatch] = useReducer(builderReducer, { composition, layout, newId }, (init) => initialBuilderState(init.composition, init.layout, init.newId));
300
+ // pure reducer (consecutive dispatches in one gesture apply in sequence); the
301
+ // store below decorates the state with the derived undo/redo + selection flags.
302
+ const [state, dispatch] = useReducer(reducer, { composition, layout, newId, preserved }, (init) => initialBuilderState(init.composition, init.layout, init.newId, init.preserved));
179
303
  const store = useMemo(() => {
180
304
  const selectedNode = state.selectedId
181
305
  ? (getNode(state.present, state.selectedId) ?? null)
@@ -186,9 +310,10 @@ export function BuilderProvider({ composition, field, layout, idFactory, childre
186
310
  canRedo: state.future.length > 0,
187
311
  selectedNode,
188
312
  field,
313
+ placement,
189
314
  dispatch,
190
315
  };
191
- }, [state, field, dispatch]);
316
+ }, [state, field, placement, dispatch]);
192
317
  return _jsx(BuilderContext.Provider, { value: store, children: children });
193
318
  }
194
319
  export { useBuilder };
@@ -1 +1 @@
1
- {"version":3,"file":"builder-store.js","sourceRoot":"","sources":["../../../src/components/builder/builder-store.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,EACL,eAAe,EACf,aAAa,EACb,OAAO,EACP,aAAa,EACb,UAAU,EACV,QAAQ,EACR,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,EACX,WAAW,GACZ,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAE9E,MAAM,aAAa,GAAG,GAAG,CAAA;AAqFzB;;;;;;;;;;GAUG;AACH,SAAS,MAAM,CACb,KAAmB,EACnB,IAAmB,EACnB,OAA6D,EAAE;IAE/D,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1D,MAAM,OAAO,GAAG,UAAU,CAAA;IAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,IAAI,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC,eAAe,CAAA;IACvF,yEAAyE;IACzE,4EAA4E;IAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,K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port {\n cloneWithNewIds,\n duplicateNode,\n getNode,\n getParentInfo,\n insertNode,\n moveNode,\n normalizeContainers,\n removeNode,\n removeNodeProp,\n reorderNode,\n replaceNode,\n setNodeProp,\n} from '@elytracms/core/project-graph'\nimport type { ComponentNode, InsertTarget, LayoutContainerIds, PropValue } from '@elytracms/core/project-graph'\nimport { createUuidIdFactory } from '@elytracms/core/persistence'\nimport type { IdFactory } from '@elytracms/core/persistence'\nimport { applyWrap } from '@elytracms/studio/lib/dnd/drop-rules'\nimport { createRequiredContext } from '@elytracms/studio/lib/required-context'\n\nconst HISTORY_LIMIT = 100\n\n/**\n * A canvas preview-width key (EC-250): `'full'` (unconstrained) or a configured\n * breakpoint name (`'sm'`, `'md'`, …). Dynamic because the set is sourced from\n * the consuming site's breakpoints, so it is a string, not a fixed union — the\n * switcher resolves the available options via {@link resolveCanvasViewports}.\n */\nexport type Viewport = string\n\n/**\n * The builder store's action union. EC-287 retired the DB-resident project graph\n * and its persistence mirror, so these actions are pure in-memory editor state —\n * no action maps to a persisted `graph.*` command anymore. The block-field editor\n * lifts committed edits into the CMS document via `onChange`\n * (`composition-field-editor`); nothing persists a graph.\n */\nexport type BuilderAction =\n | { type: 'select'; id: string | null }\n | { type: 'hover'; id: string | null }\n | { type: 'viewport'; viewport: Viewport }\n | { type: 'undo' }\n | { type: 'redo' }\n /**\n * Insert a node (its subtree re-id'd from the store's id factory). `minted` — the\n * node ALREADY carries fresh ids from the same factory (the paste path mints first\n * so its issue deep links name exactly the ids that land); the reducer then inserts\n * it as given.\n */\n | { type: 'insert'; target: InsertTarget; node: ComponentNode; select?: boolean; minted?: true }\n | { type: 'remove'; id: string }\n | { type: 'duplicate'; id: string }\n | { type: 'reorder'; id: string; delta: -1 | 1 }\n | { type: 'move'; id: string; target: InsertTarget }\n /**\n * EC-282 reuse gesture: replace a node with zero or more nodes at its\n * position (clone-with-fresh-ids, like `insert`). Promote → 1 embed node;\n * detach → the referenced element's inline blocks. One atomic structural\n * edit, one undo step.\n */\n | { type: 'replace'; id: string; nodes: ComponentNode[]; select?: boolean }\n /**\n * EC-162 layout gesture: wrap the reference node and the dragged subject in\n * a two-column Grid container as ONE atomic structural edit (one undo step).\n */\n | {\n type: 'wrap'\n referenceId: string\n side: 'left' | 'right'\n subject: { kind: 'node'; nodeId: string } | { kind: 'component'; node: ComponentNode }\n }\n | { type: 'setProp'; id: string; name: string; value: PropValue; coalesceKey?: string }\n | { type: 'removeProp'; id: string; name: string }\n\nexport interface BuilderState {\n /**\n * The edited composition: one root-bearing component tree (EC-287). The canvas\n * wraps a page document's `body` blocks into a synthetic root and edits it\n * directly — no page/layout wrapper. Undo/redo snapshot this root.\n */\n past: ComponentNode[]\n present: ComponentNode\n future: ComponentNode[]\n selectedId: string | null\n hoveredId: string | null\n viewport: Viewport\n /**\n * EC-578 / EC-595 A2 — THE node-id factory (injected; UUIDs in the studio, a\n * sequential factory in fixtures). It replaced the per-session `node-<n>` counter,\n * which two sessions editing one page advanced identically — both minted the same\n * next id, a `duplicate-node-id` on the second save. Stored ids are untouched.\n */\n newId: IdFactory\n /** Coalescing key of the last edit (consecutive same-key edits don't stack history). */\n lastCoalesceKey: string | null\n /**\n * The components filling the layout roles (EC-591, `ComponentRegistry.layout`),\n * fixed for the store's lifetime: which nodes container normalization treats as\n * Stack/Grid, and the Grid the wrap gesture builds. No hardcoded engine id.\n */\n layout: LayoutContainerIds\n}\n\ntype Action = BuilderAction\n\n/**\n * Push a new graph onto history, coalescing consecutive edits with the same key.\n *\n * Every commit normalizes layout containers (EC-162 ledger fix): the\n * operations layer normalizes every persisted `graph.*` write (EC-161), so\n * the optimistic working graph must apply the same `normalizeContainers` pass\n * or the UI state diverges from the persisted revision after\n * container-emptying moves/removes. The mirrored command stays un-normalized\n * (`graphInvocationFor` sees the raw action); both sides normalize\n * identically, so they land on the same graph.\n */\nfunction commit(\n state: BuilderState,\n root: ComponentNode,\n opts: { coalesceKey?: string; selectedId?: string | null } = {},\n): BuilderState {\n const normalized = normalizeContainers(root, state.layout)\n const present = normalized\n const coalesce = opts.coalesceKey != null && opts.coalesceKey === state.lastCoalesceKey\n // Normalization can dissolve the node a caller wanted selected (e.g. the\n // parent container of a removed child) — selection never points at a ghost.\n const desired = opts.selectedId !== undefined ? opts.selectedId : state.selectedId\n const selectedId = desired !== null && getNode(normalized, desired) ? desired : null\n return {\n ...state,\n past: coalesce ? state.past : [...state.past, state.present].slice(-HISTORY_LIMIT),\n present,\n future: [],\n lastCoalesceKey: opts.coalesceKey ?? null,\n selectedId,\n }\n}\n\n/**\n * The pure state transition. Exported (with `initialBuilderState`) for unit\n * tests — gesture determinism and normalization lockstep are reducer-level\n * properties, not render behavior.\n */\nexport function builderReducer(state: BuilderState, action: Action): BuilderState {\n const root = state.present\n switch (action.type) {\n case 'select':\n return { ...state, selectedId: action.id }\n case 'hover':\n return state.hoveredId === action.id ? state : { ...state, hoveredId: action.id }\n case 'viewport':\n return { ...state, viewport: action.viewport }\n\n case 'undo': {\n const prev = state.past.at(-1)\n if (!prev) return state\n return {\n ...state,\n past: state.past.slice(0, -1),\n present: prev,\n future: [state.present, ...state.future],\n lastCoalesceKey: null,\n selectedId: getNode(prev, state.selectedId ?? '') ? state.selectedId : null,\n }\n }\n case 'redo': {\n const next = state.future[0]\n if (!next) return state\n return {\n ...state,\n past: [...state.past, state.present],\n present: next,\n future: state.future.slice(1),\n lastCoalesceKey: null,\n selectedId: getNode(next, state.selectedId ?? '') ? state.selectedId : null,\n }\n }\n\n case 'insert': {\n const node = action.minted ? action.node : cloneWithNewIds(action.node, state.newId)\n const next = insertNode(root, action.target, node)\n return commit(state, next, {\n selectedId: action.select === false ? state.selectedId : node.id,\n })\n }\n case 'remove': {\n const parent = getParentInfo(root, action.id)\n const next = removeNode(root, action.id)\n const selectedId =\n state.selectedId === action.id ? (parent?.parent.id ?? null) : state.selectedId\n return commit(state, next, { selectedId })\n }\n case 'duplicate': {\n const { root: next, newId } = duplicateNode(root, action.id, state.newId)\n return commit(state, next, { selectedId: newId ?? state.selectedId })\n }\n case 'reorder':\n return commit(state, reorderNode(root, action.id, action.delta))\n case 'move':\n return commit(state, moveNode(root, action.id, action.target))\n case 'replace': {\n // Mint fresh ids for the incoming nodes (page-local namespace) so a detached\n // copy never collides with the page, and a promoted block's source subtree\n // (kept for the new reusable document) stays untouched.\n const cloned = action.nodes.map((n) => cloneWithNewIds(n, state.newId))\n const next = replaceNode(root, action.id, cloned)\n if (next === root) return state // root or absent id — no-op\n return commit(state, next, {\n selectedId: action.select === false ? state.selectedId : (cloned[0]?.id ?? state.selectedId),\n })\n }\n case 'wrap': {\n // Layout gesture (EC-162): the reference and the dragged subject become\n // the two columns of a new Grid container — ONE structural edit, one\n // history entry, one mirrored command, so a single undo dissolves the\n // whole gesture.\n const partner =\n action.subject.kind === 'node'\n ? { kind: 'node' as const, nodeId: action.subject.nodeId }\n : { kind: 'subtree' as const, node: cloneWithNewIds(action.subject.node, state.newId) }\n // EC-591: the gesture builds the `layout.grid` component; with none, it is off\n // (the drop rules refuse it before dispatch — this guard keeps the reducer total).\n const gridComponentId = state.layout.grid\n if (gridComponentId === undefined) return state\n const containerId = state.newId()\n const wrapped = applyWrap({\n root,\n gridComponentId,\n referenceId: action.referenceId,\n side: action.side,\n partner,\n containerId,\n })\n if (!wrapped) return state\n return commit(state, wrapped.root, { selectedId: containerId })\n }\n case 'setProp':\n return commit(state, setNodeProp(root, action.id, action.name, action.value), {\n coalesceKey: action.coalesceKey,\n })\n case 'removeProp':\n return commit(state, removeNodeProp(root, action.id, action.name))\n default:\n return state\n }\n}\n\n/**\n * The composition FIELD whose value the store edits (EC-554). Static for the\n * store's lifetime and deliberately NOT reducer state: it is the declaration the\n * edited tree is judged against, not part of the tree. It travels WITH the store\n * so every placement surface under the provider — the canvas and page-tree\n * drag-and-drop, paste (canvas, tree, keyboard), and the insert offer — reads the\n * same value from the one context it already requires; none can be mounted\n * without it, and `BuilderProvider` cannot be mounted without declaring it.\n */\nexport interface CompositionFieldScope {\n /** The field's display label — what a refusal notice names (e.g. \"Canvas\"). */\n label: string\n /**\n * The field's top-level `allow` vocabulary (EC-188; a closed set per EC-544),\n * or `undefined` when the field declares none (any registered component).\n * Applied only through `fieldAllowAt` (`lib/dnd/drop-rules`), which scopes it\n * to direct children of the composition root.\n */\n allow: readonly string[] | undefined\n}\n\nexport interface BuilderStore extends BuilderState {\n canUndo: boolean\n canRedo: boolean\n selectedNode: ComponentNode | null\n /** The composition field being edited (EC-554) — see {@link CompositionFieldScope}. */\n field: CompositionFieldScope\n dispatch: (action: Action) => void\n}\n\nconst { Context: BuilderContext, useRequired: useBuilder } =\n createRequiredContext<BuilderStore>('Builder')\n\nexport function initialBuilderState(\n composition: ComponentNode,\n layout: LayoutContainerIds,\n newId: IdFactory,\n): BuilderState {\n // Start container-normal (idempotent on healthy trees) so the session and the\n // lifted baseline agree from the first edit.\n const present = normalizeContainers(composition, layout)\n return {\n past: [],\n present,\n future: [],\n selectedId: present.id,\n hoveredId: null,\n viewport: 'full',\n // EC-578: fresh ids come from the injected factory — never a counter seeded past\n // the tree's `node-<n>` ids (EC-203), which two sessions advanced identically.\n newId,\n lastCoalesceKey: null,\n layout,\n }\n}\n\n/**\n * Undo/redo design (EC-141): the history stack is *UI state* — an in-memory\n * stack of composition-root snapshots. EC-287 retired the DB-resident project\n * graph and its append-only revision log, so the store no longer mirrors edits onto a\n * persistence layer: it is a pure in-memory editor. The block-field editor lifts\n * its committed composition into the open CMS document via `onChange`\n * (`composition-field-editor`); the document's own Save persists it as content.\n */\nexport function BuilderProvider({\n composition,\n field,\n layout,\n idFactory,\n children,\n}: {\n /** The composition root to edit (the composition-field editor's synthetic root). */\n composition: ComponentNode\n /** The field the composition is the value of (EC-554) — required, never defaulted. */\n field: CompositionFieldScope\n /** The layout-role component ids (EC-591, `ComponentRegistry.layout`) — required. */\n layout: LayoutContainerIds\n /**\n * EC-578 — the node-id factory. Defaults to UUIDs (`createUuidIdFactory`, one per\n * store); fixtures inject a deterministic factory.\n */\n idFactory?: IdFactory\n children: ReactNode\n}) {\n const [newId] = useState<IdFactory>(() => idFactory ?? createUuidIdFactory())\n // EC-287: nothing persists a graph — committed edits are lifted into the CMS\n // document by the composition-field editor's `onChange`. `useReducer` drives the\n // pure `builderReducer` (consecutive dispatches in one gesture apply in sequence);\n // the store below decorates the state with the derived undo/redo + selection flags.\n const [state, dispatch] = useReducer(builderReducer, { composition, layout, newId }, (init) =>\n initialBuilderState(init.composition, init.layout, init.newId),\n )\n\n const store = useMemo<BuilderStore>(() => {\n const selectedNode = state.selectedId\n ? (getNode(state.present, state.selectedId) ?? null)\n : null\n return {\n ...state,\n canUndo: state.past.length > 0,\n canRedo: state.future.length > 0,\n selectedNode,\n field,\n dispatch,\n }\n }, [state, field, dispatch])\n\n return <BuilderContext.Provider value={store}>{children}</BuilderContext.Provider>\n}\n\nexport { useBuilder }\n"]}
1
+ {"version":3,"file":"builder-store.js","sourceRoot":"","sources":["../../../src/components/builder/builder-store.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,EACL,YAAY,EACZ,eAAe,EACf,aAAa,EACb,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,QAAQ,EACR,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,WAAW,EACX,WAAW,EACX,uBAAuB,EACvB,WAAW,EACX,uBAAuB,GACxB,MAAM,+BAA+B,CAAA;AAWtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAEjE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACnF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAEpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAE9E,MAAM,aAAa,GAAG,GAAG,CAAA;AAyIzB;;;;;;;;;;GAUG;AACH,SAAS,MA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AAI,CAAA;QACR,OAAO;YACL,GAAG,KAAK;YACR,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;YAC9B,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YAChC,YAAY;YACZ,KAAK;YACL,SAAS;YACT,QAAQ;SACT,CAAA;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAA;IAEvC,OAAO,KAAC,cAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA2B,CAAA;AACpF,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,CAAA","sourcesContent":["import { useMemo, useReducer, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport {\n DEFAULT_SLOT,\n cloneWithNewIds,\n duplicateNode,\n getNode,\n getParentInfo,\n gridContainerNode,\n insertNode,\n moveNode,\n normalizeContainers,\n removeNode,\n removeNodeProp,\n reorderNode,\n replaceNode,\n replacePlacementRefusal,\n setNodeProp,\n subtreePlacementRefusal,\n} from '@elytracms/core/project-graph'\nimport type {\n AllowList,\n ComponentLookup,\n ComponentNode,\n InsertTarget,\n LayoutContainerIds,\n PlacementScope,\n PlacementVerdict,\n PropValue,\n} from '@elytracms/core/project-graph'\nimport { createUuidIdFactory } from '@elytracms/core/persistence'\nimport type { IdFactory } from '@elytracms/core/persistence'\nimport { WRAP_GRID_OPTIONS, applyWrap } from '@elytracms/studio/lib/dnd/drop-rules'\nimport { replaceRun, runByKey } from './canvas-runs'\nimport type { PreservedItem } from './canvas-runs'\nimport { createRequiredContext } from '@elytracms/studio/lib/required-context'\n\nconst HISTORY_LIMIT = 100\n\n/**\n * A canvas preview-width key (EC-250): `'full'` (unconstrained) or a configured\n * breakpoint name (`'sm'`, `'md'`, …). Dynamic because the set is sourced from\n * the consuming site's breakpoints, so it is a string, not a fixed union — the\n * switcher resolves the available options via {@link resolveCanvasViewports}.\n */\nexport type Viewport = string\n\n/**\n * The builder store's action union. EC-287 retired the DB-resident project graph\n * and its persistence mirror, so these actions are pure in-memory editor state —\n * no action maps to a persisted `graph.*` command anymore. The block-field editor\n * lifts committed edits into the CMS document via `onChange`\n * (`composition-field-editor`); nothing persists a graph.\n */\nexport type BuilderAction =\n | { type: 'select'; id: string | null }\n | { type: 'hover'; id: string | null }\n | { type: 'viewport'; viewport: Viewport }\n | { type: 'undo' }\n | { type: 'redo' }\n /**\n * Insert a node (its subtree re-id'd from the store's id factory). `minted` — the\n * node ALREADY carries fresh ids from the same factory (the paste path mints first\n * so its issue deep links name exactly the ids that land); the reducer then inserts\n * it as given.\n */\n | { type: 'insert'; target: InsertTarget; node: ComponentNode; select?: boolean; minted?: true }\n | { type: 'remove'; id: string }\n | { type: 'duplicate'; id: string }\n | { type: 'reorder'; id: string; delta: -1 | 1 }\n | { type: 'move'; id: string; target: InsertTarget }\n /**\n * EC-282 reuse gesture: replace a node with zero or more nodes at its\n * position (clone-with-fresh-ids, like `insert`). Promote → 1 embed node;\n * detach → the referenced element's inline blocks. One atomic structural\n * edit, one undo step.\n */\n | { type: 'replace'; id: string; nodes: ComponentNode[]; select?: boolean }\n /**\n * EC-162 layout gesture: wrap the reference node and the dragged subject in\n * a two-column Grid container as ONE atomic structural edit (one undo step).\n */\n | {\n type: 'wrap'\n referenceId: string\n side: 'left' | 'right'\n subject: { kind: 'node'; nodeId: string } | { kind: 'component'; node: ComponentNode }\n }\n | { type: 'setProp'; id: string; name: string; value: PropValue; coalesceKey?: string }\n | { type: 'removeProp'; id: string; name: string }\n /** EC-584: the editor dismissed the visible refusal ({@link BuilderState.refusal}). */\n | { type: 'clearRefusal' }\n /**\n * EC-549 — select a typography RUN by its key (`canvas-runs.ts`: the index of its\n * first preserved item); `null` clears it. A run and a node are never both selected.\n */\n | { type: 'selectRun'; run: number | null }\n /** EC-549 — delete a typography run: a real, undoable edit of the preserved list. */\n | { type: 'removeRun'; run: number }\n /**\n * EC-549 — replace a run's typography with `content` (the inspector's rich-text\n * editor on that run; consecutive same-key edits coalesce into one undo step). Empty\n * `content` deletes the run.\n */\n | { type: 'setRun'; run: number; content: readonly unknown[]; coalesceKey?: string }\n\n/** The structural actions the placement judge rules on (EC-584): every node that enters or moves. */\nexport type PlacingAction = Extract<BuilderAction, { type: 'insert' | 'replace' | 'move' | 'wrap' | 'duplicate' }>\n\n/** A refused placement (EC-584): the judge's verdict and the action it refused. */\nexport interface PlacementRefusal {\n action: PlacingAction['type']\n verdict: PlacementVerdict\n}\n\n/**\n * One history entry (EC-549): the component tree AND the preserved typography — so a\n * run's deletion or edit is undone exactly like a block's.\n */\nexport interface CanvasSnapshot {\n root: ComponentNode\n preserved: readonly PreservedItem[]\n}\n\nexport interface BuilderState {\n /**\n * The edited composition: one root-bearing component tree (EC-287). The canvas\n * wraps a page document's `body` blocks into a synthetic root and edits it\n * directly — no page/layout wrapper. Undo/redo snapshot it with the preserved\n * typography ({@link CanvasSnapshot}).\n */\n past: CanvasSnapshot[]\n present: ComponentNode\n future: CanvasSnapshot[]\n /**\n * EC-549 — the field value's typography items (no ids, EC-500 D1), each anchored by\n * how many component roots preceded it (`componentPrefix`); the field value is\n * `mergeBlockRoots(present's roots, preserved)`. In the store, so selecting,\n * deleting and editing a run is a real action with truthful undo.\n */\n preserved: readonly PreservedItem[]\n selectedId: string | null\n /** EC-549 — the selected typography run's key, or `null` (exclusive with {@link selectedId}). */\n selectedRun: number | null\n hoveredId: string | null\n viewport: Viewport\n /**\n * EC-578 / EC-595 A2 — THE node-id factory (injected; UUIDs in the studio, a\n * sequential factory in fixtures). It replaced the per-session `node-<n>` counter,\n * which two sessions editing one page advanced identically — both minted the same\n * next id, a `duplicate-node-id` on the second save. Stored ids are untouched.\n */\n newId: IdFactory\n /** Coalescing key of the last edit (consecutive same-key edits don't stack history). */\n lastCoalesceKey: string | null\n /**\n * The components filling the layout roles (EC-591, `ComponentRegistry.layout`),\n * fixed for the store's lifetime: which nodes container normalization treats as\n * Stack/Grid, and the Grid the wrap gesture builds. No hardcoded engine id.\n */\n layout: LayoutContainerIds\n /**\n * EC-584 — the last REFUSED placement, with its reason: the reducer judged an\n * `insert`/`replace`/`move`/`wrap`/`duplicate` against the field and slot\n * vocabularies and canvas eligibility (the core placement judge) and left the\n * composition unchanged. Transient — the next edit, selection, undo or redo clears\n * it — and never silent: the canvas shows it (`PlacementRefusalNotice`). A refused\n * action changes no tree, so it adds no history entry and emits no canvas patch.\n */\n refusal: PlacementRefusal | null\n}\n\ntype Action = BuilderAction\n\n/**\n * Push a new graph onto history, coalescing consecutive edits with the same key.\n *\n * Every commit normalizes layout containers (EC-162 ledger fix): the\n * operations layer normalizes every persisted `graph.*` write (EC-161), so\n * the optimistic working graph must apply the same `normalizeContainers` pass\n * or the UI state diverges from the persisted revision after\n * container-emptying moves/removes. The mirrored command stays un-normalized\n * (`graphInvocationFor` sees the raw action); both sides normalize\n * identically, so they land on the same graph.\n */\nfunction commit(\n state: BuilderState,\n root: ComponentNode,\n opts: {\n coalesceKey?: string\n selectedId?: string | null\n preserved?: readonly PreservedItem[]\n selectedRun?: number | null\n } = {},\n): BuilderState {\n const normalized = normalizeContainers(root, state.layout)\n const present = normalized\n const preserved = opts.preserved ?? state.preserved\n const coalesce = opts.coalesceKey != null && opts.coalesceKey === state.lastCoalesceKey\n // Normalization can dissolve the node a caller wanted selected (e.g. the\n // parent container of a removed child) — selection never points at a ghost.\n const desired = opts.selectedId !== undefined ? opts.selectedId : state.selectedId\n const selectedId = desired !== null && getNode(normalized, desired) ? desired : null\n const desiredRun = opts.selectedRun !== undefined ? opts.selectedRun : state.selectedRun\n return {\n ...state,\n past: coalesce ? state.past : [...state.past, snapshotOf(state)].slice(-HISTORY_LIMIT),\n present,\n preserved,\n future: [],\n lastCoalesceKey: opts.coalesceKey ?? null,\n selectedId,\n selectedRun: liveRun(present, preserved, desiredRun),\n refusal: null,\n }\n}\n\nfunction snapshotOf(state: BuilderState): CanvasSnapshot {\n return { root: state.present, preserved: state.preserved }\n}\n\n/** The run key if that run still exists in this state, else `null` (never a ghost selection). */\nfunction liveRun(root: ComponentNode, preserved: readonly PreservedItem[], run: number | null): number | null {\n if (run === null) return null\n return runByKey(rootCount(root), preserved, run) ? run : null\n}\n\n/** How many component roots the composition has (the synthetic root's children). */\nfunction rootCount(root: ComponentNode): number {\n return root.slots?.[DEFAULT_SLOT]?.length ?? 0\n}\n\n/** Restore a history entry (undo/redo), keeping a selection only where it still exists. */\nfunction restore(state: BuilderState, to: CanvasSnapshot, past: CanvasSnapshot[], future: CanvasSnapshot[]): BuilderState {\n return {\n ...state,\n past,\n present: to.root,\n preserved: to.preserved,\n future,\n lastCoalesceKey: null,\n selectedId: getNode(to.root, state.selectedId ?? '') ? state.selectedId : null,\n selectedRun: liveRun(to.root, to.preserved, state.selectedRun),\n refusal: null,\n }\n}\n\n/** Leave the composition untouched and say why (EC-584 — never a silent no-op). */\nfunction refuse(state: BuilderState, action: PlacingAction, verdict: PlacementVerdict): BuilderState {\n return { ...state, refusal: { action: action.type, verdict } }\n}\n\n/**\n * The builder's pure state transition, CONSTRUCTED with the placement scope it judges\n * by (EC-584, owner-ratified 4a): the field's effective top-level vocabulary and the\n * manifest lookup. The scope is static per store and deliberately not reducer STATE\n * (it is the declaration the tree is judged against, not part of the tree) — the\n * reducer RECEIVES it, so there is no `(state, action)` to call without it.\n *\n * Every structural action that places a node — `insert`, `replace`, `move`, `wrap`,\n * `duplicate` — runs the ONE core judge (`subtreePlacementRefusal`) over every node\n * that enters or moves, BEFORE committing. A refusal returns the composition\n * unchanged, with the verdict in {@link BuilderState.refusal}: so no gesture — a\n * forgotten pre-check, promote, detach, a fixture's `slotChildren`, a server-only\n * paste — can place what the field, a slot or canvas eligibility forbids, and the\n * publish gate (which calls the same judge) cannot disagree with the canvas.\n *\n * Exported (with `initialBuilderState`) for unit tests — gesture determinism and\n * normalization lockstep are reducer-level properties, not render behavior.\n */\nexport function createBuilderReducer(\n placement: PlacementScope,\n): (state: BuilderState, action: Action) => BuilderState {\n return (state, action) => transition(state, action, placement)\n}\n\nfunction transition(state: BuilderState, action: Action, placement: PlacementScope): BuilderState {\n const root = state.present\n switch (action.type) {\n case 'select':\n return { ...state, selectedId: action.id, selectedRun: action.id === null ? state.selectedRun : null, refusal: null }\n case 'selectRun':\n return {\n ...state,\n selectedRun: liveRun(root, state.preserved, action.run),\n selectedId: action.run === null ? state.selectedId : null,\n refusal: null,\n }\n case 'removeRun': {\n const run = runByKey(rootCount(root), state.preserved, action.run)\n if (!run) return state\n return commit(state, root, { preserved: replaceRun(state.preserved, run, []), selectedRun: null })\n }\n case 'setRun': {\n const run = runByKey(rootCount(root), state.preserved, action.run)\n if (!run) return state\n return commit(state, root, {\n preserved: replaceRun(state.preserved, run, action.content),\n coalesceKey: action.coalesceKey,\n selectedRun: action.content.length > 0 ? action.run : null,\n })\n }\n case 'hover':\n return state.hoveredId === action.id ? state : { ...state, hoveredId: action.id }\n case 'viewport':\n return { ...state, viewport: action.viewport }\n case 'clearRefusal':\n return state.refusal === null ? state : { ...state, refusal: null }\n\n case 'undo': {\n const prev = state.past.at(-1)\n if (!prev) return state\n return restore(state, prev, state.past.slice(0, -1), [snapshotOf(state), ...state.future])\n }\n case 'redo': {\n const next = state.future[0]\n if (!next) return state\n return restore(state, next, [...state.past, snapshotOf(state)], state.future.slice(1))\n }\n\n case 'insert': {\n const node = action.minted ? action.node : cloneWithNewIds(action.node, state.newId)\n const verdict = subtreePlacementRefusal(root, node, landingOf(action.target), placement)\n if (verdict) return refuse(state, action, verdict)\n const next = insertNode(root, action.target, node)\n return commit(state, next, {\n selectedId: action.select === false ? state.selectedId : node.id,\n })\n }\n case 'remove': {\n const parent = getParentInfo(root, action.id)\n const next = removeNode(root, action.id)\n const selectedId =\n state.selectedId === action.id ? (parent?.parent.id ?? null) : state.selectedId\n return commit(state, next, { selectedId })\n }\n case 'duplicate': {\n // The copy (and every node of its subtree) ENTERS beside the original.\n const info = getParentInfo(root, action.id)\n const source = getNode(root, action.id)\n if (info && source) {\n const verdict = subtreePlacementRefusal(root, source, { parentId: info.parent.id, slot: info.slot }, placement)\n if (verdict) return refuse(state, action, verdict)\n }\n const { root: next, newId } = duplicateNode(root, action.id, state.newId)\n return commit(state, next, { selectedId: newId ?? state.selectedId })\n }\n case 'reorder':\n // Same parent, same slot: the placement does not change — nothing to judge.\n return commit(state, reorderNode(root, action.id, action.delta))\n case 'move': {\n // A node that changes parent or slot lands somewhere new (its descendants keep\n // their own slots, so only it is judged); a move within its own slot is a\n // reorder and leaves the placement as it was.\n const info = getParentInfo(root, action.id)\n const node = getNode(root, action.id)\n const relocates = !info || info.parent.id !== action.target.parentId || info.slot !== action.target.slot\n if (node && relocates) {\n const verdict = subtreePlacementRefusal(root, withoutSlots(node), landingOf(action.target), placement)\n if (verdict) return refuse(state, action, verdict)\n }\n return commit(state, moveNode(root, action.id, action.target))\n }\n case 'replace': {\n // Mint fresh ids for the incoming nodes (page-local namespace) so a detached\n // copy never collides with the page, and a promoted block's source subtree\n // (kept for the new reusable document) stays untouched.\n const cloned = action.nodes.map((n) => cloneWithNewIds(n, state.newId))\n // EC-560: promote (one embed) and detach (the reusable's content) land where the\n // replaced node was — judged there like any insert (the reuse preflight asks the\n // same `replacePlacementRefusal` before any side effect).\n const verdict = replacePlacementRefusal(root, action.id, cloned, placement)\n if (verdict) return refuse(state, action, verdict)\n const next = replaceNode(root, action.id, cloned)\n if (next === root) return state // root or absent id — no-op\n return commit(state, next, {\n selectedId: action.select === false ? state.selectedId : (cloned[0]?.id ?? state.selectedId),\n })\n }\n case 'wrap': {\n // Layout gesture (EC-162): the reference and the dragged subject become\n // the two columns of a new Grid container — ONE structural edit, one\n // history entry, one mirrored command, so a single undo dissolves the\n // whole gesture.\n const partner =\n action.subject.kind === 'node'\n ? { kind: 'node' as const, nodeId: action.subject.nodeId }\n : { kind: 'subtree' as const, node: cloneWithNewIds(action.subject.node, state.newId) }\n // EC-591: the gesture builds the `layout.grid` component; with none, it is off\n // (the drop rules refuse it before dispatch — this guard keeps the reducer total).\n const gridComponentId = state.layout.grid\n if (gridComponentId === undefined) return state\n // EC-584: the Grid lands where the reference is; the reference and the partner\n // land in the Grid's column slot. A moved partner keeps its own subtree (only it\n // relocates); a new one (a blocks-panel tile) enters whole.\n const reference = getNode(root, action.referenceId)\n const referenceInfo = getParentInfo(root, action.referenceId)\n const partnerNode = partner.kind === 'node' ? getNode(root, partner.nodeId) : partner.node\n if (reference && referenceInfo && partnerNode) {\n const columns = [withoutSlots(reference), partner.kind === 'node' ? withoutSlots(partnerNode) : partnerNode]\n const probe = gridContainerNode(gridComponentId, 'wrap', WRAP_GRID_OPTIONS, columns)\n const verdict = subtreePlacementRefusal(\n root,\n probe,\n { parentId: referenceInfo.parent.id, slot: referenceInfo.slot },\n placement,\n )\n if (verdict) return refuse(state, action, verdict)\n }\n const containerId = state.newId()\n const wrapped = applyWrap({\n root,\n gridComponentId,\n referenceId: action.referenceId,\n side: action.side,\n partner,\n containerId,\n })\n if (!wrapped) return state\n return commit(state, wrapped.root, { selectedId: containerId })\n }\n case 'setProp':\n return commit(state, setNodeProp(root, action.id, action.name, action.value), {\n coalesceKey: action.coalesceKey,\n })\n case 'removeProp':\n return commit(state, removeNodeProp(root, action.id, action.name))\n default:\n return state\n }\n}\n\nfunction landingOf(target: InsertTarget): { parentId: string; slot?: string } {\n return { parentId: target.parentId, slot: target.slot }\n}\n\n/** The node alone — a move relocates it; its descendants keep their own slots. */\nfunction withoutSlots(node: ComponentNode): ComponentNode {\n const { slots: _slots, ...rest } = node\n return rest\n}\n\n/**\n * The composition FIELD whose value the store edits (EC-554). Static for the\n * store's lifetime and deliberately NOT reducer state: it is the declaration the\n * edited tree is judged against, not part of the tree. It travels WITH the store\n * so every placement surface under the provider — the canvas and page-tree\n * drag-and-drop, paste (canvas, tree, keyboard), and the insert offer — reads the\n * same value from the one context it already requires; none can be mounted\n * without it, and `BuilderProvider` cannot be mounted without declaring it.\n */\nexport interface CompositionFieldScope {\n /** The field's display label — what a refusal notice names (e.g. \"Canvas\"). */\n label: string\n /**\n * The field's EFFECTIVE top-level vocabulary (EC-188; EC-584 — `fieldAllowList(field)`:\n * its `allow`, else the `blocks` type's default). The judge applies it only to\n * direct children of the composition root (`allowAt`, core `placement.ts`).\n */\n allow: AllowList\n}\n\nexport interface BuilderStore extends BuilderState {\n canUndo: boolean\n canRedo: boolean\n selectedNode: ComponentNode | null\n /** The composition field being edited (EC-554) — see {@link CompositionFieldScope}. */\n field: CompositionFieldScope\n /**\n * EC-584 — what the reducer judges every placement by: the manifest lookup and the\n * field's vocabulary. The gestures' own pre-checks (drag-and-drop, paste, the insert\n * offer, the reuse preflight) read the SAME scope, so an indicator and the sink agree.\n */\n placement: PlacementScope\n dispatch: (action: Action) => void\n}\n\nconst { Context: BuilderContext, useRequired: useBuilder } =\n createRequiredContext<BuilderStore>('Builder')\n\nexport function initialBuilderState(\n composition: ComponentNode,\n layout: LayoutContainerIds,\n newId: IdFactory,\n /** EC-549 — the field value's typography items with their anchors (`splitBlockRoots`). */\n preserved: readonly PreservedItem[] = [],\n): BuilderState {\n // Start container-normal (idempotent on healthy trees) so the session and the\n // lifted baseline agree from the first edit.\n const present = normalizeContainers(composition, layout)\n return {\n past: [],\n present,\n future: [],\n preserved,\n selectedId: present.id,\n selectedRun: null,\n hoveredId: null,\n viewport: 'full',\n // EC-578: fresh ids come from the injected factory — never a counter seeded past\n // the tree's `node-<n>` ids (EC-203), which two sessions advanced identically.\n newId,\n lastCoalesceKey: null,\n layout,\n refusal: null,\n }\n}\n\n/**\n * Undo/redo design (EC-141): the history stack is *UI state* — an in-memory\n * stack of composition-root snapshots. EC-287 retired the DB-resident project\n * graph and its append-only revision log, so the store no longer mirrors edits onto a\n * persistence layer: it is a pure in-memory editor. The block-field editor lifts\n * its committed composition into the open CMS document via `onChange`\n * (`composition-field-editor`); the document's own Save persists it as content.\n */\nexport function BuilderProvider({\n composition,\n preserved,\n field,\n components,\n layout,\n idFactory,\n children,\n}: {\n /** The composition root to edit (the composition-field editor's synthetic root). */\n composition: ComponentNode\n /** EC-549 — the field value's typography items (`splitBlockRoots(value).preserved`). */\n preserved?: readonly PreservedItem[]\n /** The field the composition is the value of (EC-554) — required, never defaulted. */\n field: CompositionFieldScope\n /** The manifest lookup the placement judge reads (EC-584, `registry.lookup`) — required. */\n components: ComponentLookup\n /** The layout-role component ids (EC-591, `ComponentRegistry.layout`) — required. */\n layout: LayoutContainerIds\n /**\n * EC-578 — the node-id factory. Defaults to UUIDs (`createUuidIdFactory`, one per\n * store); fixtures inject a deterministic factory.\n */\n idFactory?: IdFactory\n children: ReactNode\n}) {\n const [newId] = useState<IdFactory>(() => idFactory ?? createUuidIdFactory())\n // EC-584: the reducer is constructed ONCE with the scope it judges by — the field\n // and the lookup are static for the store's lifetime (a remount re-reads them).\n const [placement] = useState<PlacementScope>(() => ({ components, fieldAllow: field.allow }))\n const [reducer] = useState(() => createBuilderReducer(placement))\n // EC-287: nothing persists a graph — committed edits are lifted into the CMS\n // document by the composition-field editor's `onChange`. `useReducer` drives the\n // pure reducer (consecutive dispatches in one gesture apply in sequence); the\n // store below decorates the state with the derived undo/redo + selection flags.\n const [state, dispatch] = useReducer(reducer, { composition, layout, newId, preserved }, (init) =>\n initialBuilderState(init.composition, init.layout, init.newId, init.preserved),\n )\n\n const store = useMemo<BuilderStore>(() => {\n const selectedNode = state.selectedId\n ? (getNode(state.present, state.selectedId) ?? null)\n : null\n return {\n ...state,\n canUndo: state.past.length > 0,\n canRedo: state.future.length > 0,\n selectedNode,\n field,\n placement,\n dispatch,\n }\n }, [state, field, placement, dispatch])\n\n return <BuilderContext.Provider value={store}>{children}</BuilderContext.Provider>\n}\n\nexport { useBuilder }\n"]}