efficient-easel 0.96.0 → 0.97.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -399,6 +399,99 @@ Key order is not part of the saved format — the backend stores these in
399
399
  Postgres `jsonb` — but an edited key keeps its place and a new one goes on the
400
400
  end, so a save diffs as the lines that changed.
401
401
 
402
+ ### A page in more than one language — the translation overlay
403
+
404
+ Added in 0.97.0, in the same entry. A page is written once, in a base
405
+ language; each other language is an **overlay** the host stores beside the
406
+ document, never inside it:
407
+
408
+ ```ts
409
+ type TranslationOverlay = Record<string /* node id, or "root" */, Record<string /* prop path */, TranslatedValue>>;
410
+ interface TranslatedValue { v: unknown; src: string } // src: a fingerprint of the BASE value it translates
411
+ ```
412
+
413
+ **The document format is unchanged**, and a page with one language stores no
414
+ overlay: `applyTranslation(data, config)` returns the object it was given.
415
+ `Render` knows nothing of languages. It is handed a document that has already
416
+ been localised.
417
+
418
+ ```ts
419
+ import { applyTranslation, extractTranslation, translationStatus } from 'efficient-easel/data';
420
+
421
+ // Draw the page in German. A value with no entry is the base language's.
422
+ <Render config={config} data={applyTranslation(page, config, german)} />
423
+
424
+ // A translator typed over that page: what to save for German.
425
+ const next = extractTranslation(page, edited, config, german);
426
+
427
+ // How far German has got.
428
+ const { total, missing, stale } = translationStatus(page, config, next);
429
+ ```
430
+
431
+ **A block's fields say what is translated**, with `translatable`:
432
+
433
+ ```ts
434
+ fields: {
435
+ title: { type: 'text' }, // text and textarea: translated
436
+ slug: { type: 'text', translatable: false }, // … unless the field says not
437
+ heading: { type: 'custom', translatable: true, render }, // anything else: only when it says so
438
+ banner: { type: 'custom', translatable: true, render }, // a picture with words in it: one whole value
439
+ height: { type: 'number' }, // never, unless flagged
440
+ items: { type: 'array', arrayFields: { q: { type: 'text' }, href: { type: 'text', translatable: false } } },
441
+ content: { type: 'slot' }, // never: a child block has its own id
442
+ }
443
+ ```
444
+
445
+ An `object` or `array` field is a container: the fields inside it are read by
446
+ the same rule, and a flag on the container is the default for them. A path is
447
+ the prop's keys joined by dots, with an array index as a key: `title`,
448
+ `cta.label`, `items.2.q`. The root's props are translated under the id
449
+ `"root"`.
450
+
451
+ | Export | Notes |
452
+ |---|---|
453
+ | `applyTranslation(data, config, overlay?)` | The document in one language. No overlay (or an empty one): **the same object**. Otherwise only the nodes that took a value are copied. An entry for a node that is not there, or a path that is not words, is passed over. |
454
+ | `extractTranslation(base, edited, config, previous?)` | The overlay a language's edit comes to: an entry for every translatable value that differs from the base. A value equal to the base's makes no entry. Anything else that differs (a block added or moved, a number) is passed over. With `previous`, an entry the edit did not touch is kept as it was, old `src` and all. |
455
+ | `translationStatus(data, config, overlay?)` | `{ total, missing, stale }`, the two lists as `{ id, path }` in document order. A value the base leaves blank wants nothing. |
456
+ | `translatablePaths(node, config)` | `{ path, value }[]` for a node, or for the root (`data.root`). |
457
+ | `rebaseTranslation(previousBase, nextBase, config, overlay)` | Carries an overlay across an edit of the base that moved, added, copied or removed **array items**. |
458
+ | `mapIds(source, copy, config)`, `copyTranslation(overlay, ids)` | For `duplicate` and `copyNode`, which give every copied node a new id: old id → new id, then the copies' entries (only those; lay them over the overlay). |
459
+ | `pruneTranslation(data, config, overlay)` | Drops the entries of nodes that are gone and of paths that no longer exist. Nothing else drops anything. |
460
+ | `translationFingerprint(value)` | What `src` holds. |
461
+
462
+ **Stale.** `src` is the fingerprint of the base value a translation was made
463
+ from (`s<length>.<hash>` of a string; of anything else, its JSON with the keys
464
+ sorted). When the base value changes, the translation is stale:
465
+ `translationStatus` reports it, and it is **still drawn**, because an
466
+ out-of-date translation beats the wrong language. An emptied or removed base
467
+ value is a changed one.
468
+
469
+ **Arrays.** An array item has no id, and the format does not allow one, so its
470
+ entries are stored under its index (`items.2.q`). When the base value at that
471
+ index no longer has the entry's `src`, the entry is looked for among the other
472
+ items of the same array, in the same field, and drawn **there**: the item
473
+ moved. Found nowhere, it is not drawn (the item at that index may be another
474
+ item now) and is reported stale. Two items with the same base words can only be
475
+ told apart by position: an entry that still matches where it stands stays, and
476
+ a displaced one takes the first free match.
477
+
478
+ **What a host does when the base is edited:**
479
+
480
+ | Edit of the base | The host calls |
481
+ |---|---|
482
+ | `move` | nothing: ids do not change |
483
+ | `remove` | nothing. The entries stay, unread, so undoing the delete brings the translations back. `pruneTranslation` when they should go for good. |
484
+ | `duplicate`, `copyNode` | `mapIds(source, copy, config)`, then for each language `{ ...overlay, ...copyTranslation(overlay, ids) }` |
485
+ | `setProps`, `setRoot`, `replaceNode` | nothing: a changed value is stale |
486
+ | an array value changed (an item moved, added, copied, removed) | `rebaseTranslation(before, after, config, overlay)` for each language. It sees both sides, so stale entries travel with their item, a copied item starts with its original's translations, and the saved overlay has the right indices. It drops the entries of an item that was removed: keep the overlay in the same undo step as the base to get them back. |
487
+
488
+ A block type the config does not know keeps its entries for as long as the
489
+ block is in the document.
490
+
491
+ Not here yet: the editor's side (a language switch, the Inspector showing the
492
+ base words under a translation, markers on untranslated rows). Routing and
493
+ `<html lang>` are the host's.
494
+
402
495
  ## Block writing — `efficient-easel/blocks`
403
496
 
404
497
  `efficient-easel/blocks` (added in 0.92.0) holds the types a block is written
@@ -406,7 +499,9 @@ with: Puck 0.20's `Config`, `ComponentConfig`, `Fields`, `Field`,
406
499
  `CustomField`, `ComponentData`, `Data`, `Slot` and `SlotComponent`, with the
407
500
  same generics. An app that typed its blocks with Puck's imports them from here
408
501
  instead, and no block changes. It is types only: nothing in it exists at
409
- runtime.
502
+ runtime. One key is the engine's own: `translatable` on a field (0.97.0),
503
+ which says whether the prop is written again per language (the translation
504
+ overlay, above). It is optional, so a field written for Puck is still a field.
410
505
 
411
506
  ```ts
412
507
  import type { Config, CustomField, Slot } from 'efficient-easel/blocks';
@@ -1,9 +1,9 @@
1
1
  import { ReactElement, FC, CSSProperties, ReactNode, JSX } from 'react';
2
- import { P as Permissions, A as AppState } from '../types-_Vayx8ov.js';
2
+ import { P as Permissions, A as AppState } from '../types-Dy6oR6Z2.js';
3
3
  import '../data/index.js';
4
- import '../types-DziKCwsN.js';
5
- import '../resolve-DpH8YQOA.js';
6
- import '../plan-DtNw2VuI.js';
4
+ import '../types-41704JE4.js';
5
+ import '../resolve-D68pb3Bx.js';
6
+ import '../plan-DChbUXdS.js';
7
7
 
8
8
  /**
9
9
  * efficient-easel/blocks — how a block is WRITTEN: its config, its fields, the
@@ -48,6 +48,17 @@ type BaseField = {
48
48
  labelIcon?: ReactElement;
49
49
  metadata?: Metadata;
50
50
  visible?: boolean;
51
+ /**
52
+ * NOT PUCK'S — the engine's (0.97.0). Whether this prop is written again in
53
+ * each language of a multilingual page (`efficient-easel/data`, the
54
+ * translation overlay). Left out, a `text` or `textarea` field is and every
55
+ * other type is not, so a `custom` field that edits words, or a picture with
56
+ * words in it, says `translatable: true`, and a `text` field that holds an
57
+ * address or a code says `false`. On an `object` or `array` field it is the
58
+ * default for the fields inside it. A `slot` is never translated: its
59
+ * children are blocks with ids of their own.
60
+ */
61
+ translatable?: boolean;
51
62
  };
52
63
  type TextField = BaseField & {
53
64
  type: 'text';
@@ -1 +1 @@
1
- import{zoneKey as e}from"./chunk-LPRQDDQO.js";import{useRef as t,useEffect as n,useState as r,useSyncExternalStore as o,useCallback as i}from"react";var c=56,l=16;function u(e){const t=Math.max(e,0);return t>=c?0:Math.ceil(16*(1-t/c))}function a(e,t,n){if(e<t-c||e>n+c)return 0;const r=e-t,o=n-e;return r<c&&r<=o?-u(r):o<c?u(o):0}function s(e){const t=e?.ownerDocument?.defaultView;for(let n=e?.parentElement??null;n;n=n.parentElement){const e=t?.getComputedStyle(n).overflowY;if(("auto"===e||"scroll"===e)&&n.scrollHeight>n.clientHeight)return n}return null}function f(e){const t=e?.ownerDocument?.defaultView?.getComputedStyle(e).overflowY;return e&&("auto"===t||"scroll"===t)&&e.scrollHeight>e.clientHeight?e:s(e)}function d(e){const t=e.ownerDocument,n=t.defaultView;if(!n)return()=>{};let r=null,o=0;const i=e=>{r=e.clientY},c=()=>{if(null!==r){const t=e.getBoundingClientRect(),n=a(r,t.top,t.bottom);n&&(e.scrollTop+=n)}o=n.requestAnimationFrame(c)};return t.addEventListener("dragover",i,!0),o=n.requestAnimationFrame(c),()=>{t.removeEventListener("dragover",i,!0),n.cancelAnimationFrame(o)}}function g(){let e=null,t=null;const n=/* @__PURE__ */new Set,r=()=>{if(t!==e){t=e;for(const e of[...n])e()}};return{get:()=>e,shown:()=>t,start(t){e=t,globalThis.setTimeout(r,0)},end(){null===e&&null===t||(e=null,r())},subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function p(e,t,n,r){if(e.into)return{side:"into",to:e.into};return"first"===e.pinned||"last"!==e.pinned&&t>n+r/2?{side:"after",to:{...e.place,index:e.place.index+1}}:{side:"before",to:{...e.place,index:e.place.index}}}var m=(t,n)=>e(t)===e(n);function v(e,t){return m(e,t)&&(t.index===e.index||t.index===e.index+1)}function D(e,t){return m(e,t)&&e.index<t.index?t.index-1:t.index}function y(e,t){return{...e,index:t<0?e.index-1:e.index+2}}function w(e,t){if(!t)return e;const n={...t,...e};for(const[r,o]of Object.entries(e)){const e=t[r];"function"==typeof o&&"function"==typeof e&&(n[r]=t=>{o(t),e(t)})}return n}function x(c){const l=t(c);n(()=>{l.current=c});const[u]=r(()=>g()),a=c.session??u,m=o(a.subscribe,a.shown,a.shown),[D,y]=r(null),x=t(null),b=i(()=>{x.current?.(),x.current=null},[]),h=i(()=>{b(),a.end(),y(null)},[a,b]);n(()=>a.subscribe(()=>{a.get()||(b(),y(null))}),[a,b]),n(()=>b,[b]);const T=i((e,t)=>{y(n=>n&&n.key===e&&n.side===t?n:{key:e,side:t})},[]),k=i(e=>{y(t=>t&&t.key===e?null:t)},[]),E=(e,t,n,r)=>!("into"===n?r===e.key:void 0!==e.from&&v(e.from,t))&&l.current.canDrop(e.item,t);return{dragging:m?.item??null,row:(e,t)=>{const{keyOf:n,readOnly:r}=l.current,o=n(e.item),i=!r&&!e.pinned&&!1!==e.canDrag,c=t=>{const n=t.currentTarget.getBoundingClientRect();return p(e,t.clientY,n.top,n.height)},u={draggable:i||void 0,onDragStart:i?t=>{const n=t.currentTarget;a.start({key:o,item:e.item,from:e.place}),t.dataTransfer.effectAllowed="move";try{t.dataTransfer.setData("text/plain",o)}catch{}n.classList.add("is-lifting");const r=n.getBoundingClientRect();t.dataTransfer.setDragImage?.(n,t.clientX-r.left,t.clientY-r.top),n.ownerDocument.defaultView?.setTimeout(()=>n.classList.remove("is-lifting"),0);const i=s(n);b(),x.current=i?d(i):null}:void 0,onDragEnd:i?()=>h():void 0,onDragOver:e=>{const t=a.get();if(!t)return;const n=c(e);E(t,n.to,n.side,o)?(e.preventDefault(),e.dataTransfer.dropEffect="move",T(o,n.side)):k(o)},onDrop:e=>{const t=a.get();if(!t)return;const n=c(e);E(t,n.to,n.side,o)&&(e.preventDefault(),h(),l.current.onDrop(t.item,n.to))},onKeyDown:t=>{if("ArrowUp"!==t.key&&"ArrowDown"!==t.key)return;if(!t.altKey||t.ctrlKey||t.metaKey||t.shiftKey)return;if(t.preventDefault(),t.repeat||!i)return;const{onStep:n,canStep:r}=l.current,o="ArrowUp"===t.key?-1:1;n&&!1!==r?.(e.item,o)&&n(e.item,o)}};return{draggable:i,dragging:m?.key===o,drop:D?.key===o?D.side:void 0,rowProps:w(u,t)}},seam:(t,n)=>{const r=(o=t.place,`seam:${e(o)}:${o.index}`);var o;const i={onDragOver:e=>{const n=a.get();n&&(E(n,t.place,"before",r)?(e.preventDefault(),e.dataTransfer.dropEffect="move",T(r,"before")):k(r))},onDrop:e=>{const n=a.get();n&&E(n,t.place,"before",r)&&(e.preventDefault(),h(),l.current.onDrop(n.item,t.place))}};return{drop:D?.key===r,seamProps:w(i,n)}},rootProps:e=>w({onDragEnter:e=>{if(!a.get()||x.current)return;const t=f(e.currentTarget);x.current=t?d(t):null},onDragLeave:e=>{const t=e.relatedTarget;t&&e.currentTarget.contains(t)||y(null)}},e)}}export{c as AUTO_SCROLL_EDGE,l as AUTO_SCROLL_MAX_SPEED,a as autoScrollDelta,u as autoScrollSpeed,g as createDragSession,p as dropOnRow,D as gapToMoveIndex,v as isNoOpDrop,f as scrollBoxOf,s as scrollParent,d as startAutoScroll,y as stepGap,x as useTreeDrag};
1
+ import{zoneKey as e}from"./chunk-KRXQM65X.js";import{useRef as t,useEffect as n,useState as r,useSyncExternalStore as o,useCallback as i}from"react";var c=56,l=16;function u(e){const t=Math.max(e,0);return t>=c?0:Math.ceil(16*(1-t/c))}function a(e,t,n){if(e<t-c||e>n+c)return 0;const r=e-t,o=n-e;return r<c&&r<=o?-u(r):o<c?u(o):0}function s(e){const t=e?.ownerDocument?.defaultView;for(let n=e?.parentElement??null;n;n=n.parentElement){const e=t?.getComputedStyle(n).overflowY;if(("auto"===e||"scroll"===e)&&n.scrollHeight>n.clientHeight)return n}return null}function f(e){const t=e?.ownerDocument?.defaultView?.getComputedStyle(e).overflowY;return e&&("auto"===t||"scroll"===t)&&e.scrollHeight>e.clientHeight?e:s(e)}function d(e){const t=e.ownerDocument,n=t.defaultView;if(!n)return()=>{};let r=null,o=0;const i=e=>{r=e.clientY},c=()=>{if(null!==r){const t=e.getBoundingClientRect(),n=a(r,t.top,t.bottom);n&&(e.scrollTop+=n)}o=n.requestAnimationFrame(c)};return t.addEventListener("dragover",i,!0),o=n.requestAnimationFrame(c),()=>{t.removeEventListener("dragover",i,!0),n.cancelAnimationFrame(o)}}function g(){let e=null,t=null;const n=/* @__PURE__ */new Set,r=()=>{if(t!==e){t=e;for(const e of[...n])e()}};return{get:()=>e,shown:()=>t,start(t){e=t,globalThis.setTimeout(r,0)},end(){null===e&&null===t||(e=null,r())},subscribe:e=>(n.add(e),()=>{n.delete(e)})}}function p(e,t,n,r){if(e.into)return{side:"into",to:e.into};return"first"===e.pinned||"last"!==e.pinned&&t>n+r/2?{side:"after",to:{...e.place,index:e.place.index+1}}:{side:"before",to:{...e.place,index:e.place.index}}}var m=(t,n)=>e(t)===e(n);function v(e,t){return m(e,t)&&(t.index===e.index||t.index===e.index+1)}function D(e,t){return m(e,t)&&e.index<t.index?t.index-1:t.index}function y(e,t){return{...e,index:t<0?e.index-1:e.index+2}}function w(e,t){if(!t)return e;const n={...t,...e};for(const[r,o]of Object.entries(e)){const e=t[r];"function"==typeof o&&"function"==typeof e&&(n[r]=t=>{o(t),e(t)})}return n}function x(c){const l=t(c);n(()=>{l.current=c});const[u]=r(()=>g()),a=c.session??u,m=o(a.subscribe,a.shown,a.shown),[D,y]=r(null),x=t(null),b=i(()=>{x.current?.(),x.current=null},[]),h=i(()=>{b(),a.end(),y(null)},[a,b]);n(()=>a.subscribe(()=>{a.get()||(b(),y(null))}),[a,b]),n(()=>b,[b]);const T=i((e,t)=>{y(n=>n&&n.key===e&&n.side===t?n:{key:e,side:t})},[]),k=i(e=>{y(t=>t&&t.key===e?null:t)},[]),E=(e,t,n,r)=>!("into"===n?r===e.key:void 0!==e.from&&v(e.from,t))&&l.current.canDrop(e.item,t);return{dragging:m?.item??null,row:(e,t)=>{const{keyOf:n,readOnly:r}=l.current,o=n(e.item),i=!r&&!e.pinned&&!1!==e.canDrag,c=t=>{const n=t.currentTarget.getBoundingClientRect();return p(e,t.clientY,n.top,n.height)},u={draggable:i||void 0,onDragStart:i?t=>{const n=t.currentTarget;a.start({key:o,item:e.item,from:e.place}),t.dataTransfer.effectAllowed="move";try{t.dataTransfer.setData("text/plain",o)}catch{}n.classList.add("is-lifting");const r=n.getBoundingClientRect();t.dataTransfer.setDragImage?.(n,t.clientX-r.left,t.clientY-r.top),n.ownerDocument.defaultView?.setTimeout(()=>n.classList.remove("is-lifting"),0);const i=s(n);b(),x.current=i?d(i):null}:void 0,onDragEnd:i?()=>h():void 0,onDragOver:e=>{const t=a.get();if(!t)return;const n=c(e);E(t,n.to,n.side,o)?(e.preventDefault(),e.dataTransfer.dropEffect="move",T(o,n.side)):k(o)},onDrop:e=>{const t=a.get();if(!t)return;const n=c(e);E(t,n.to,n.side,o)&&(e.preventDefault(),h(),l.current.onDrop(t.item,n.to))},onKeyDown:t=>{if("ArrowUp"!==t.key&&"ArrowDown"!==t.key)return;if(!t.altKey||t.ctrlKey||t.metaKey||t.shiftKey)return;if(t.preventDefault(),t.repeat||!i)return;const{onStep:n,canStep:r}=l.current,o="ArrowUp"===t.key?-1:1;n&&!1!==r?.(e.item,o)&&n(e.item,o)}};return{draggable:i,dragging:m?.key===o,drop:D?.key===o?D.side:void 0,rowProps:w(u,t)}},seam:(t,n)=>{const r=(o=t.place,`seam:${e(o)}:${o.index}`);var o;const i={onDragOver:e=>{const n=a.get();n&&(E(n,t.place,"before",r)?(e.preventDefault(),e.dataTransfer.dropEffect="move",T(r,"before")):k(r))},onDrop:e=>{const n=a.get();n&&E(n,t.place,"before",r)&&(e.preventDefault(),h(),l.current.onDrop(n.item,t.place))}};return{drop:D?.key===r,seamProps:w(i,n)}},rootProps:e=>w({onDragEnter:e=>{if(!a.get()||x.current)return;const t=f(e.currentTarget);x.current=t?d(t):null},onDragLeave:e=>{const t=e.relatedTarget;t&&e.currentTarget.contains(t)||y(null)}},e)}}export{c as AUTO_SCROLL_EDGE,l as AUTO_SCROLL_MAX_SPEED,a as autoScrollDelta,u as autoScrollSpeed,g as createDragSession,p as dropOnRow,D as gapToMoveIndex,v as isNoOpDrop,f as scrollBoxOf,s as scrollParent,d as startAutoScroll,y as stepGap,x as useTreeDrag};
@@ -1 +1 @@
1
- import{find as t,remove as e,getList as n,newId as r,duplicate as o,move as a,copyNode as c,insert as l,setProps as d}from"./chunk-LPRQDDQO.js";import{useRef as s,useSyncExternalStore as i,useCallback as p,useMemo as u}from"react";var f=t=>({kind:"node",id:t});function m(r,o,a,c="none"){const l=t(r,o,a),d=e(r,o,a);if("none"===c||!l)return{data:d,select:null};const s=n(r,o,l.place)??[],i=s[l.place.index+1]??s[l.place.index-1];return i?.props?.id?{data:d,select:f(i.props.id)}:"root"!==l.place.parentId?{data:d,select:f(l.place.parentId)}:{data:d,select:null}}function x(e,n,a,c={}){const l=t(e,n,a)?.node,d=c.id??r(l?.type??"Node");return{data:o(e,n,a,{strip:c.strip,id:d}),select:f(d)}}function I(t,e,n,r){return{data:a(t,e,n,r),select:f(n)}}var v=(t,e)=>({min:0,max:e-1});function b(e,r,o,a,c=v){const l=t(e,r,o);if(!l)return!1;const d=n(e,r,l.place)?.length??0,{min:s,max:i}=c(l.place,d),p=l.place.index+a;return l.place.index>=s&&l.place.index<=i&&p>=s&&p<=i}function g(e,n,r,o,a=v){if(!b(e,n,r,o,a))return null;const c=t(e,n,r);return I(e,n,r,{...c.place,index:c.place.index+o})}function k(t,e,n,r,o={}){const a=c(n,e,{strip:o.strip});return{data:l(t,e,r,a),select:f(a.props.id)}}function y(t,e,n,r){return{data:d(t,e,n,r),select:void 0}}function O(e,n,r,o=()=>!1){if(!r)return null;if("slot"===r.kind)return t(e,n,r.parentId)?f(r.parentId):null;const a=t(e,n,r.id);if(!a||"root"===a.place.parentId)return null;const c=t(e,n,a.place.parentId);return c?o(c.node,a.place.slot)?{kind:"slot",parentId:c.node.props.id,slot:a.place.slot}:f(c.node.props.id):null}function h(e,n,r){if(!r||"node"!==r.kind)return null;const o=t(e,n,r.id);return o?{zone:`${o.place.parentId}:${o.place.slot}`,index:o.place.index}:null}function z(t,e,r){if(!r)return null;const[o,a]=(r.zone??"root:default-zone").split(/:(.*)/s),c={parentId:o,slot:a},l=n(t,e,c)?.[r.index];return l?.props?.id?f(l.props.id):null}var R={get:()=>null,set:()=>{},subscribe:()=>()=>{}};function B(e){const n=s(e);n.current=e;const r=e.clipboard??R,o=i(r.subscribe,r.get,r.get),a=p(t=>{const e=n.current;if(e.readOnly)return!1;const r=t(e.data,e.config);return!!r&&((r.data!==e.data||void 0!==r.select)&&(e.commit(r.data,{select:r.select}),n.current={...e,data:r.data},!0))},[]);return u(()=>{const e=()=>n.current,r=(n,r)=>{const o=t(e().data,e().config,n);return o?{node:o.node,label:r,from:{parentId:o.place.parentId,slot:o.place.slot}}:null};return{held:o,remove:t=>a((n,r)=>m(n,r,t,e().afterRemove)),duplicate:t=>a((n,r)=>x(n,r,t,{strip:e().strip})),move:(t,e)=>a((n,r)=>I(n,r,t,e)),step:(t,n)=>a((r,o)=>g(r,o,t,n,e().stepBounds)),canStep:(t,n)=>b(e().data,e().config,t,n,e().stepBounds),setProps:(t,e)=>a((n,r)=>y(n,r,t,e)),copy:(t,n)=>{const o=r(t,n);return o&&(e().clipboard??R).set(o),!!o},cut:(t,n)=>{if(e().readOnly)return!1;const o=r(t,n);return!!o&&((e().clipboard??R).set(o),a((n,r)=>m(n,r,t,e().afterRemove)))},paste:t=>{const n=(e().clipboard??R).get();return!!n&&a((r,o)=>k(r,o,n.node,t,{strip:e().strip}))},parentOf:t=>O(e().data,e().config,t,e().slotIsLevel)}},[o,a])}export{b as canStep,z as fromItemSelector,O as parentStep,x as planDuplicate,I as planMove,k as planPaste,m as planRemove,y as planSetProps,g as planStep,h as toItemSelector,B as useNodeOps};
1
+ import{find as t,remove as e,getList as n,newId as r,duplicate as o,move as a,copyNode as c,insert as l,setProps as d}from"./chunk-KRXQM65X.js";import{useRef as s,useSyncExternalStore as i,useCallback as p,useMemo as u}from"react";var f=t=>({kind:"node",id:t});function m(r,o,a,c="none"){const l=t(r,o,a),d=e(r,o,a);if("none"===c||!l)return{data:d,select:null};const s=n(r,o,l.place)??[],i=s[l.place.index+1]??s[l.place.index-1];return i?.props?.id?{data:d,select:f(i.props.id)}:"root"!==l.place.parentId?{data:d,select:f(l.place.parentId)}:{data:d,select:null}}function x(e,n,a,c={}){const l=t(e,n,a)?.node,d=c.id??r(l?.type??"Node");return{data:o(e,n,a,{strip:c.strip,id:d}),select:f(d)}}function I(t,e,n,r){return{data:a(t,e,n,r),select:f(n)}}var v=(t,e)=>({min:0,max:e-1});function b(e,r,o,a,c=v){const l=t(e,r,o);if(!l)return!1;const d=n(e,r,l.place)?.length??0,{min:s,max:i}=c(l.place,d),p=l.place.index+a;return l.place.index>=s&&l.place.index<=i&&p>=s&&p<=i}function g(e,n,r,o,a=v){if(!b(e,n,r,o,a))return null;const c=t(e,n,r);return I(e,n,r,{...c.place,index:c.place.index+o})}function k(t,e,n,r,o={}){const a=c(n,e,{strip:o.strip});return{data:l(t,e,r,a),select:f(a.props.id)}}function y(t,e,n,r){return{data:d(t,e,n,r),select:void 0}}function h(e,n,r,o=()=>!1){if(!r)return null;if("slot"===r.kind)return t(e,n,r.parentId)?f(r.parentId):null;const a=t(e,n,r.id);if(!a||"root"===a.place.parentId)return null;const c=t(e,n,a.place.parentId);return c?o(c.node,a.place.slot)?{kind:"slot",parentId:c.node.props.id,slot:a.place.slot}:f(c.node.props.id):null}function z(e,n,r){if(!r||"node"!==r.kind)return null;const o=t(e,n,r.id);return o?{zone:`${o.place.parentId}:${o.place.slot}`,index:o.place.index}:null}function O(t,e,r){if(!r)return null;const[o,a]=(r.zone??"root:default-zone").split(/:(.*)/s),c={parentId:o,slot:a},l=n(t,e,c)?.[r.index];return l?.props?.id?f(l.props.id):null}var R={get:()=>null,set:()=>{},subscribe:()=>()=>{}};function B(e){const n=s(e);n.current=e;const r=e.clipboard??R,o=i(r.subscribe,r.get,r.get),a=p(t=>{const e=n.current;if(e.readOnly)return!1;const r=t(e.data,e.config);return!!r&&((r.data!==e.data||void 0!==r.select)&&(e.commit(r.data,{select:r.select}),n.current={...e,data:r.data},!0))},[]);return u(()=>{const e=()=>n.current,r=(n,r)=>{const o=t(e().data,e().config,n);return o?{node:o.node,label:r,from:{parentId:o.place.parentId,slot:o.place.slot}}:null};return{held:o,remove:t=>a((n,r)=>m(n,r,t,e().afterRemove)),duplicate:t=>a((n,r)=>x(n,r,t,{strip:e().strip})),move:(t,e)=>a((n,r)=>I(n,r,t,e)),step:(t,n)=>a((r,o)=>g(r,o,t,n,e().stepBounds)),canStep:(t,n)=>b(e().data,e().config,t,n,e().stepBounds),setProps:(t,e)=>a((n,r)=>y(n,r,t,e)),copy:(t,n)=>{const o=r(t,n);return o&&(e().clipboard??R).set(o),!!o},cut:(t,n)=>{if(e().readOnly)return!1;const o=r(t,n);return!!o&&((e().clipboard??R).set(o),a((n,r)=>m(n,r,t,e().afterRemove)))},paste:t=>{const n=(e().clipboard??R).get();return!!n&&a((r,o)=>k(r,o,n.node,t,{strip:e().strip}))},parentOf:t=>h(e().data,e().config,t,e().slotIsLevel)}},[o,a])}export{b as canStep,O as fromItemSelector,h as parentStep,x as planDuplicate,I as planMove,k as planPaste,m as planRemove,y as planSetProps,g as planStep,z as toItemSelector,B as useNodeOps};
@@ -0,0 +1 @@
1
+ import{isRecord as t,fieldsFrom as n,blockOf as o,topLevelSlotKeys as e,slotLocations as r,setIn as s,fieldsOf as i,isNode as c,defaultsFrom as p}from"./chunk-NKB3KVAB.js";var f=()=>({lastChange:{}});function a(t,n){if(t===n)return!0;if(!t||!n||"object"!=typeof t||"object"!=typeof n)return t!=t&&n!=n;if(Array.isArray(t)!==Array.isArray(n))return!1;if(Array.isArray(t)){const o=n;if(t.length!==o.length)return!1;for(let n=0;n<t.length;n++)if(!a(t[n],o[n]))return!1;return!0}const o=Object.keys(t),e=Object.keys(n);if(o.length!==e.length)return!1;for(const e of o){if(!Object.prototype.hasOwnProperty.call(n,e))return!1;if(!a(t[e],n[e]))return!1}return!0}function l(t,n){if(!t)return{};const o=t.props??{},e=n?.props??{},r={};for(const t of Object.keys(o))r[t]=!a(e[t],o[t]);return r}async function u(i,c,p={}){const{metadata:d={},trigger:h="replace",cache:y=f(),onResolveStart:g,onResolveEnd:m}=p,w=function(t,n){return t.type&&"root"!==t.type?n.components[t.type]:n.root}(i,c);let b={...i};const v=Boolean(w?.resolveData&&i.props),j=t(i.props)&&"id"in i.props?String(i.props.id):"root";if(v){const t=y.lastChange[j];if("force"!==h&&t&&a(i,t.item))return{node:t.resolved,didChange:!1};const n=l(i,t?.item??null);g?.(i);const o=await w.resolveData(i,{changed:n,lastData:t?.item??null,metadata:{...d,...w.metadata??{}},trigger:h})??{};b.props={...i.props,...o.props??{}},o.readOnly&&Object.keys(o.readOnly).length&&(b.readOnly=o.readOnly)}const $=n(i.type&&"root"!==i.type?o(c,i.type):c.root);if(w)for(const t of e($))void 0===b.props[t]&&(b={...b,props:{...b.props,[t]:[]}});for(const t of r(b.props,$)){if(!t.present)continue;const n=await Promise.all(t.content.map(async t=>(await u(t,c,{metadata:d,trigger:h,cache:y,onResolveStart:g,onResolveEnd:m})).node));b={...b,props:s(b.props,t.segments,n)}}return v&&m?.(b),y.lastChange[j]={item:i,resolved:b},{node:b,didChange:!a(i,b)}}var d="root";function h(t){if(void 0===t)return"u";if("string"==typeof t)return`s${t.length.toString(36)}.${y(t)}`;const n=g(t);return`j${n.length.toString(36)}.${y(n)}`}function y(t){let n=2166136261;for(let o=0;o<t.length;o++)n^=t.charCodeAt(o),n=Math.imul(n,16777619);return(n>>>0).toString(36)}function g(t){if(null===t||"object"!=typeof t)return JSON.stringify(t)??"null";if(Array.isArray(t))return`[${t.map(g).join(",")}]`;const n=t;return`{${Object.keys(n).filter(t=>void 0!==n[t]).sort().map(t=>`${JSON.stringify(t)}:${g(n[t])}`).join(",")}}`}var m=(t,n)=>Object.prototype.hasOwnProperty.call(t,n);function w(t,n){return t&&m(t,n)?t[n]:void 0}var b=t=>Object.keys(t).length>0,v=n=>t(n)&&"string"==typeof n.src&&void 0!==n.v,j=t=>null==t||"string"==typeof t&&""===t.trim(),$=t=>"text"===t||"textarea"===t,O=(t,n)=>"boolean"==typeof t.translatable?t.translatable:n;function k(n,o){const e=w(n,o);return t(e)?e:void 0}function A(t,n){const o=[];return x(t,n,[],[],[],void 0,o),o}function x(n,o,e,r,s,i,c){for(const p of Object.keys(o)){const f=o[p];if(!f||"slot"===f.type)continue;if(0===e.length&&"id"===p)continue;const a=[...e,p],l=[...r,p],u=w(n,p),d=O(f,i);if("object"===f.type&&f.objectFields)null==u?x({},f.objectFields,a,l,s,d,c):t(u)&&x(u,f.objectFields,a,l,s,d,c);else if("array"===f.type&&f.arrayFields){if(!Array.isArray(u))continue;const n=f.arrayFields;u.forEach((o,e)=>{t(o)&&x(o,n,[...a,e],[...l,"*"],[...s,e],d,c)})}else(d??$(f.type))&&c.push({path:a.join("."),segments:a,pattern:l.join("."),indices:s,value:u})}}function z(t,n){const o=t.split("."),e=[],r=[];let s,i=n,c=0;for(;c<o.length;){const t=w(i,o[c]);if(!t||"slot"===t.type)return null;if(0===c&&"id"===o[c])return null;e.push(o[c]),c+=1;const n=O(t,s);if("object"===t.type&&t.objectFields)i=t.objectFields,s=n;else{if("array"!==t.type||!t.arrayFields)return c!==o.length?null:n??$(t.type)?{pattern:e.join("."),indices:r}:null;{const p=o[c];if(void 0===p||!/^(0|[1-9]\d*)$/.test(p))return null;r.push(Number(p)),e.push("*"),c+=1,i=t.arrayFields,s=n}}}return null}function I(n,o){return A(t(n?.props)?n.props:{},i(o,n?.type??d)).map(({path:t,value:n})=>({path:t,value:n}))}function S(t,n,o){const e=A(t,n),r=/* @__PURE__ */new Map,s=[],i=[];if(!o)return{positions:e,hits:r,orphans:s,beaten:i};const c=/* @__PURE__ */new Map;for(const t of e)c.set(t.path,t);const p=/* @__PURE__ */new Map,f=t=>{let n=p.get(t);return void 0===n&&(n=h(t.value),p.set(t,n)),n},a=[];for(const t of Object.keys(o)){const e=o[t],p=c.get(t);if(!v(e)){(p?i:s).push(t);continue}if(p&&f(p)===e.src){r.set(t,{position:p,entry:e,from:t,stale:!1,applied:!0});continue}const l=p??z(t,n);l?l.indices.length>0?a.push({path:t,entry:e,own:p,pattern:l.pattern,indices:l.indices}):p?r.set(t,{position:p,entry:e,from:t,stale:!0,applied:!0}):s.push(t):s.push(t)}a.sort((t,n)=>function(t,n){const o=Math.min(t.length,n.length);for(let e=0;e<o;e++)if(t[e]!==n[e])return t[e]-n[e];return t.length-n.length}(t.indices,n.indices)||(t.path<n.path?-1:t.path>n.path?1:0));const l=[];for(const t of a){let n,o=-1;for(const s of e){if(s.pattern!==t.pattern||r.has(s.path))continue;if(f(s)!==t.entry.src)continue;const e=F(s.indices,t.indices);e>o&&(n=s,o=e)}n?r.set(n.path,{position:n,entry:t.entry,from:t.path,stale:!1,applied:!0}):l.push(t)}for(const t of l)t.own?r.has(t.path)?i.push(t.path):r.set(t.path,{position:t.own,entry:t.entry,from:t.path,stale:!0,applied:!1}):s.push(t.path);return{positions:e,hits:r,orphans:s,beaten:i}}function F(t,n){let o=0;for(;o<t.length&&o<n.length&&t[o]===n[o];)o+=1;return o}function M(n,o,e){const p=t=>{if(!Array.isArray(t))return t;let n=null;return t.forEach((o,r)=>{if(!c(o))return;const s=f(e(o.props.id,o.type,o.props),o.type);s!==o.props&&(n??=[...t],n[r]={...o,props:s})}),n??t},f=(t,n)=>{let e=t;for(const c of r(t,i(o,n))){if(!c.present)continue;const t=p(c.content);t!==c.content&&(e=s(e,c.segments,t))}return e};let a=n;const l=t(n.root?.props)?n.root.props:{},u=e(d,d,l),h=p(n.content);h!==n.content&&(a={...a,content:h});const y=f(u,d);y!==l&&(a={...a,root:{...a.root,props:y}});const g=n.zones;if(t(g)){let t=g;for(const n of Object.keys(g)){if(-1===n.indexOf(":"))continue;const o=p(g[n]);o!==g[n]&&(t={...t,[n]:o})}t!==g&&(a={...a,zones:t})}return a}function N(t,n){const o=/* @__PURE__ */new Map;return M(t,n,(t,n,e)=>(o.has(t)||o.set(t,{type:n,props:e}),e)),o}function E(t,n,o){return o&&b(o)?M(t,n,(t,e,r)=>{const c=k(o,t);if(!c)return r;const p=S(r,i(n,e),c);let f=r;for(const t of p.positions){const n=p.hits.get(t.path);n&&n.applied&&!a(t.value,n.entry.v)&&(f=s(f,t.segments,n.entry.v))}return f}):t}function D(t,n,o){const e={total:0,missing:[],stale:[]};return M(t,n,(t,r,s)=>{const c=S(s,i(n,r),k(o,t));for(const n of c.positions){const o=c.hits.get(n.path);!o&&j(n.value)||(e.total+=1,o?o.stale&&e.stale.push({id:t,path:n.path}):e.missing.push({id:t,path:n.path}))}return s}),e}function C(n,o){let e=n;for(let n=0;n<o.length-1;n++){const r=o[n];if("number"==typeof r){if(!Array.isArray(e)||r>=e.length)return{held:!1,value:void 0};e=e[r]}else{if(!t(e))return{held:!1,value:void 0};e=w(e,r)}}return t(e)?{held:!0,value:w(e,String(o[o.length-1]))}:{held:!1,value:void 0}}function J(n,e,r,s){const c=N(e,r),p={},f=/* @__PURE__ */new Set;if(M(n,r,(t,n,e)=>{if(f.has(t))return e;f.add(t);const l=k(s,t),u=c.get(t);if(!u||u.type!==n||!o(r,n))return l&&(p[t]=l),e;const d=S(e,i(r,n),l),y={};for(const t of d.positions){const n=d.hits.get(t.path),{held:o,value:e}=C(u.props,t.segments),r=n&&n.applied?n.entry.v:t.value;!o||void 0!==e&&a(e,r)?n&&(y[t.path]=n.entry):void 0===e||a(e,t.value)||(y[t.path]={v:e,src:h(t.value)})}if(l)for(const t of d.orphans)m(y,t)||(y[t]=l[t]);return b(y)&&(p[t]=l&&P(y,l)?l:y),e}),!s)return p;for(const n of Object.keys(s))f.has(n)||m(p,n)||!t(s[n])||(p[n]=s[n]);return P(p,s)?s:p}function P(t,n){const o=Object.keys(t);return o.length===Object.keys(n).length&&o.every(o=>m(n,o)&&t[o]===n[o])}function R(t,n,e){const r={},s=/* @__PURE__ */new Set;let c=!1;M(t,n,(t,p,f)=>{if(m(r,t))return f;const a=k(e,t);if(!o(n,p))return U(f,s),a&&(r[t]=a),f;if(!a)return f;const l=function(t,n){let o=0===t.orphans.length&&0===t.beaten.length;const e={};for(const n of t.positions){const r=t.hits.get(n.path);r&&(e[n.path]=r.entry,r.from!==n.path&&(o=!1))}return o?n:e}(S(f,i(n,p),a),a);return l!==a&&(c=!0),b(l)&&(r[t]=l),f});for(const t of s){const n=k(e,t);n&&!m(r,t)&&(r[t]=n)}return c||Object.keys(r).length!==Object.keys(e).length?r:e}function U(n,o){if(Array.isArray(n))for(const t of n)U(t,o);else if(t(n)){c(n)&&"string"==typeof n.props.id&&o.add(n.props.id);for(const t of Object.keys(n))U(n[t],o)}}function B(n,e,r,s){if(!t(s)||!b(s))return s;const c=N(e,r),p=/* @__PURE__ */new Map;if(M(n,r,(t,n,e)=>{if(p.has(t))return e;const f=k(s,t),a=c.get(t);if(!f||!a||a.type!==n||!o(r,n))return e;const l=function(t,n,o,e){const r=S(t,o,e),s=/* @__PURE__ */new Map,i=/* @__PURE__ */new Map;K(t,n,o,"","",void 0,s,i);const c={};let p=0===r.beaten.length;for(const t of r.positions){const n=r.hits.get(t.path);if(!n)continue;const o=s.get(t.path)?.[0];void 0!==o?(c[o]=n.entry,o!==n.from&&(p=!1)):p=!1}for(const t of r.positions){const n=r.hits.get(t.path);if(n)for(const o of i.get(t.path)??[])m(c,o)||(c[o]=n.entry,p=!1)}for(const t of[...r.orphans].sort())m(c,t)?p=!1:c[t]=e[t];return p?e:c}(e,a.props,i(r,n),f);return l!==f&&p.set(t,l),e}),0===p.size)return s;const f={};for(const t of Object.keys(s)){const n=p.get(t);n?b(n)&&(f[t]=n):f[t]=s[t]}return f}function K(n,o,e,r,s,i,c,p){for(const f of Object.keys(e)){const a=e[f];if(!a||"slot"===a.type)continue;if(""===r&&"id"===f)continue;const l=""===r?f:`${r}.${f}`,u=""===s?f:`${s}.${f}`,d=w(n,f),h=w(o,f),y=O(a,i);if("object"===a.type&&a.objectFields){if(null!=d&&!t(d))continue;K(t(d)?d:{},t(h)?h:{},a.objectFields,l,u,y,c,p)}else if("array"===a.type&&a.arrayFields){if(!Array.isArray(d))continue;const n=Array.isArray(h)?h:[];for(const o of T(d,n)){const e=d[o.from];if(!t(e))continue;const r="edited"===o.kind?n[o.to]:e;K(e,t(r)?r:{},a.arrayFields,`${l}.${o.from}`,`${u}.${o.to}`,y,"copy"===o.kind?p:c,p)}}else if(y??$(a.type)){const t=c.get(l);t?t.push(u):c.set(l,[u])}}}function T(t,n){const o=t.map(g),e=n.map(g),r=o.map(()=>!1),s=e.map(()=>!1),i=[],c=Math.min(o.length,e.length);for(let t=0;t<c;t++)o[t]===e[t]&&(i.push({from:t,to:t,kind:"same"}),r[t]=s[t]=!0);for(let t=0;t<e.length;t++){if(s[t])continue;const n=o.findIndex((n,o)=>!r[o]&&n===e[t]);-1!==n&&(i.push({from:n,to:t,kind:"same"}),r[n]=s[t]=!0)}for(let t=0;t<c;t++)r[t]||s[t]||(i.push({from:t,to:t,kind:"edited"}),r[t]=s[t]=!0);for(let t=0;t<e.length;t++){if(s[t])continue;const n=o.indexOf(e[t]);-1!==n&&i.push({from:n,to:t,kind:"copy"})}return i}function V(t,n,o){const e={},s=(t,n)=>{if(t.type!==n.type)return;e[t.props.id]=n.props.id;const p=r(n.props,i(o,n.type));for(const n of r(t.props,i(o,t.type))){const t=p.find(t=>t.slot===n.slot);t&&n.content.forEach((n,o)=>{const e=t.content[o];c(n)&&c(e)&&s(n,e)})}};return c(t)&&c(n)&&s(t,n),e}function q(t,n){const o={};if(!t)return o;for(const e of Object.keys(n)){const r=k(t,e),s=n[e];r&&b(r)&&"string"==typeof s&&(o[s]={...r})}return o}var G="root",H="default-zone",L={parentId:G,slot:H},Q=({parentId:t,slot:n})=>`${t}:${n}`;function W(t){const n=t.indexOf(":");if(-1===n)throw new Y("no-slot",`"${t}" is not a zone key`);return{parentId:t.slice(0,n),slot:t.slice(n+1)}}var X=t=>t.parentId===G&&t.slot===H,Y=class extends Error{code;constructor(t,n){super(n),this.name="DataError",this.code=t}};function Z(t){try{const n=globalThis.crypto;if(n&&"function"==typeof n.randomUUID)return`${t}-${n.randomUUID()}`}catch{}return`${t}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function _(t,n){return r(t.props,i(n,t.type)).map(({slot:t,content:n})=>({slot:t,content:n}))}function tt(t,o){return r(nt(t),n(o.root))}function nt(n){return t(n.root?.props)?n.root.props:{}}function ot(t,n,o){const e=(t,n,e,r,s)=>{if(!Array.isArray(t))return t;const i=[...e,n];let f=null;return t.forEach((e,a)=>{if(!c(e))return;const l={place:{...n,index:a},path:i,parent:r,depth:s};let u=o(e,l)??e;if(u!==e&&u.props.id!==e.props.id)throw new Y("id-change",`walk: ${e.props.id} came back as ${u.props.id}`);u=p(u,i,s+1),u!==e&&(f??=[...t],f[a]=u)}),f??t},p=(t,o,c)=>{let p=t.props;for(const f of r(t.props,i(n,t.type))){if(!f.present)continue;const n=e(f.content,{parentId:t.props.id,slot:f.slot},o,t,c);n!==f.content&&(p=s(p,f.segments,n))}return p===t.props?t:{...t,props:p}};let f=t;const a=e(t.content,L,[],null,0);a!==t.content&&(f={...f,content:a});let l=nt(f);for(const t of tt(f,n)){if(!t.present)continue;const n=e(t.content,{parentId:G,slot:t.slot},[],null,0);n!==t.content&&(l=s(l,t.segments,n))}l!==nt(f)&&(f={...f,root:{...f.root,props:l}});const u=f.zones;if(u){let t=u;for(const n of Object.keys(u)){const o=et(n);if(!o)continue;const r=e(u[n],o,[],null,0);r!==u[n]&&(t={...t,[n]:r})}t!==u&&(f={...f,zones:t})}return f}function et(t){const n=t.indexOf(":");return-1===n?null:{parentId:t.slice(0,n),slot:t.slice(n+1)}}function rt(t,n,o){let e=null;const r={};try{ot(t,n,(t,n)=>{if(t.props.id===o)throw e={node:t,place:n.place,path:n.path},r})}catch(t){if(t!==r)throw t}return e}function st(t,n,o){if(X(o))return Array.isArray(t.content)?t.content:[];const e=t.zones?.[Q(o)];if(o.parentId===G){const r=tt(t,n).find(t=>t.slot===o.slot);return r?r.content:e??null}const s=rt(t,n,o.parentId);if(s){const t=r(s.node.props,i(n,s.node.type)).find(t=>t.slot===o.slot);if(t)return t.content}return e??null}function it(t,n){const o=/* @__PURE__ */new Set;return ot(t,n,t=>{o.add(t.props.id)}),o}function ct(t,n){const o=/* @__PURE__ */new Set([t.props.id]),e=t=>{for(const{content:r}of _(t,n))for(const t of r)c(t)&&(o.add(t.props.id),e(t))};return e(t),o}function pt(t,n,o,e){if(X(o)){const n=Array.isArray(t.content)?t.content:[];return{...t,content:e(n)}}const c=Q(o),p=!!t.zones&&Array.isArray(t.zones[c]);if(o.parentId===G){const r=tt(t,n).find(t=>t.slot===o.slot);if(r){const n=s(nt(t),r.segments,e(r.content));return{...t,root:{...t.root,props:n}}}}else{const c=rt(t,n,o.parentId);if(c){const p=r(c.node.props,i(n,c.node.type)).find(t=>t.slot===o.slot);if(p)return ft(t,n,c,t=>({...t,props:s(t.props,p.segments,e(p.content))}))}else if(!p)throw new Y("not-found",`no node ${o.parentId}`)}if(p)return{...t,zones:{...t.zones,[c]:e(t.zones[c])}};throw new Y("no-slot",`no slot "${o.slot}" on ${o.parentId}`)}function ft(t,n,o,e){return pt(t,n,o.place,t=>{const n=[...t];return n[o.place.index]=e(t[o.place.index]),n})}function at(t,n,o){const e=rt(t,n,o);if(!e)throw new Y("not-found",`no node ${o}`);return e}function lt(t,n,o){const e=st(t,n,o);if(e)return e;if(o.parentId!==G&&!rt(t,n,o.parentId))throw new Y("not-found",`no node ${o.parentId}`);throw new Y("no-slot",`no slot "${o.slot}" on ${o.parentId}`)}function ut(t,n,o){if(!Number.isInteger(t)||t<0||t>n)throw new Y("bad-index",`${o}: index ${t} is outside 0…${n}`)}function dt(t,i){const c=o(i,t.type);if(!c)return t;const p=n(c);let f=t.props;for(const t of e(p))null==f[t]&&(f={...f,[t]:[]});for(const t of r(f,p)){if(!t.present)continue;const n=ht(t.content,i);n!==t.content&&(f=s(f,t.segments,n))}return f===t.props?t:{...t,props:f}}function ht(n,o){let e=null;return n.forEach((r,s)=>{if(!t(r)||"string"!=typeof r.type)return;let i=r;if(t(i.props)){if("string"!=typeof i.props.id||""===i.props.id){const{id:t,...n}=i.props;i={...i,props:{id:Z(i.type),...n}}}}else i={...i,props:{id:Z(i.type)}};const c=dt(i,o);c!==r&&(e??=[...n],e[s]=c)}),e??n}function yt(t,o){const i=n(o.root);let c=t.props;for(const t of e(i))null==c[t]&&(c={...c,[t]:[]});for(const t of r(c,i)){if(!t.present)continue;const n=ht(t.content,o);n!==t.content&&(c=s(c,t.segments,n))}return c===t.props?t:{...t,props:c}}function gt(n,o){let e=t(n)?n:{};const r=e.root;if(t(r)){if(!t(r.props)){const t=Object.keys(r).filter(t=>"props"!==t);e={...e,root:t.length?{props:{...wt(r,t)}}:{props:{}}}}}else e={...e,root:{props:{}}};const s=p(o.root);if(s){const t=Object.keys(s).filter(t=>!(t in e.root.props));if(t.length){const n=bt(wt(s,t));e={...e,root:{...e.root,props:{...e.root.props,...n}}}}}const i=yt(e.root,o);i!==e.root&&(e={...e,root:i}),Array.isArray(e.content)||(e={...e,content:[]});const c=ht(e.content,o);return c!==e.content&&(e={...e,content:c}),e=t(e.zones)?function(t,n){let o=t;for(const e of Object.keys(t.zones??{})){const t=o.zones[e];if(!Array.isArray(t)||0===t.length)continue;const r=et(e);if(!r||X(r))continue;const s=mt(o,n,r);if(!s||s.content.length>0)continue;const{[e]:i,...c}=o.zones;o=pt({...o,zones:c},n,r,()=>ht(t,n))}const e=o.zones;let r=e;for(const t of Object.keys(e)){if(!Array.isArray(e[t]))continue;const o=ht(e[t],n);o!==e[t]&&(r={...r,[t]:o})}return r===e?o:{...o,zones:r}}(e,o):{...e,zones:{}},e}function mt(t,n,o){if(o.parentId===G)return tt(t,n).find(t=>t.slot===o.slot);const e=rt(t,n,o.parentId);return e?r(e.node.props,i(n,e.node.type)).find(t=>t.slot===o.slot):void 0}function wt(t,n){const o={};for(const e of n)o[e]=t[e];return o}function bt(t){return void 0===t?t:JSON.parse(JSON.stringify(t))}function vt(t,n,o={},e={}){const r=t.components[n];if(!r)throw new Y("unknown-type",`no block type "${n}" in the config`);return dt({type:n,props:{...bt(p(r)??{}),...bt(o),id:e.id??Z(n)}},t)}function jt(n,o,e,r){if(!c(r))throw new Y("unknown-type","insert: not a node");const s=lt(n,o,e);ut(e.index,s.length,"insert");const i=dt(t(r.props)&&"string"==typeof r.props.id&&r.props.id?r:{...r,props:{...r.props,id:Z(r.type)}},o),p=it(n,o);for(const t of ct(i,o))if(p.has(t))throw new Y("duplicate-id",`insert: ${t} is already in the document`);return pt(n,o,e,t=>[...t.slice(0,e.index),i,...t.slice(e.index)])}function $t(t,n,o){const e=at(t,n,o);let r=pt(t,n,e.place,t=>[...t.slice(0,e.place.index),...t.slice(e.place.index+1)]);if(r.zones&&Object.keys(r.zones).length){const t=ct(e.node,n),o=Object.keys(r.zones).filter(n=>!t.has(n.split(":")[0]));o.length!==Object.keys(r.zones).length&&(r={...r,zones:wt(r.zones,o)})}return r}function Ot(t,n,o,e){const r=at(t,n,o);if(ct(r.node,n).has(e.parentId))throw new Y("cycle",`move: ${o} cannot go inside itself`);if(r.place.parentId===e.parentId&&r.place.slot===e.slot){const o=lt(t,n,e);return ut(e.index,o.length-1,"move"),e.index===r.place.index?t:pt(t,n,e,t=>{const n=[...t],[o]=n.splice(r.place.index,1);return n.splice(e.index,0,o),n})}ut(e.index,lt(t,n,e).length,"move");const s=pt(t,n,r.place,t=>[...t.slice(0,r.place.index),...t.slice(r.place.index+1)]);return pt(s,n,e,t=>[...t.slice(0,e.index),r.node,...t.slice(e.index)])}function kt(t,n,o,e={}){const r=at(t,n,o),s=xt(bt(r.node),n,e.strip,e.id);return pt(t,n,r.place,t=>[...t.slice(0,r.place.index+1),s,...t.slice(r.place.index+1)])}function At(t,n,o={}){return xt(bt(t),n,o.strip,o.id)}function xt(t,n,o,e){let p={...t,props:{...t.props,id:e??Z(t.type)}};if(o){const t=o(p);if(t.props.id!==p.props.id)throw new Y("id-change","duplicate: strip must not change the id");p=t}let f=p.props;for(const t of r(f,i(n,p.type))){if(!t.present)continue;const e=t.content.map(t=>c(t)?xt(t,n,o):t);f=s(f,t.segments,e)}return dt({...p,props:f},n)}function zt(t,n,o,e){if("id"in e&&e.id!==o)throw new Y("id-change",`setProps: ${o} cannot become ${String(e.id)}`);const r=at(t,n,o);return Ft(r.node.props,e)?ft(t,n,r,t=>dt({...t,props:{...t.props,...e,id:o}},n)):t}function It(t,n,o,e){if(!c(e))throw new Y("unknown-type","replaceNode: not a node");if(e.props.id!==o)throw new Y("id-change",`replaceNode: ${o} cannot become ${String(e.props.id)}`);const r=at(t,n,o),s=dt(e,n),i=it(t,n);for(const t of ct(r.node,n))i.delete(t);for(const t of ct(s,n))if(i.has(t))throw new Y("duplicate-id",`replaceNode: ${t} is already in the document`);return ft(t,n,r,()=>s)}function St(t,n,o){const e=nt(t);if(!Ft(e,o))return t;const r=yt({...t.root,props:{...e,...o}},n);return{...t,root:r}}function Ft(t,n){return Object.keys(n).some(o=>!(o in t)||!Object.is(t[o],n[o]))}export{Y as DataError,G as ROOT_ID,L as ROOT_LIST,H as ROOT_SLOT,E as applyTranslation,l as changedProps,At as copyNode,q as copyTranslation,vt as createNode,f as createResolveCache,a as deepEqual,kt as duplicate,J as extractTranslation,rt as find,st as getList,jt as insert,V as mapIds,Ot as move,Z as newId,gt as normalizeData,W as parseZoneKey,R as pruneTranslation,B as rebaseTranslation,$t as remove,It as replaceNode,u as resolveNodeData,zt as setProps,St as setRoot,_ as slotsOf,I as translatablePaths,h as translationFingerprint,D as translationStatus,ot as walk,Q as zoneKey};
@@ -1 +1 @@
1
- import{changedProps as e}from"./chunk-LPRQDDQO.js";import{useState as t,useRef as r,useEffect as n}from"react";function i({id:i,node:l,block:d,parent:o=null,appState:a=null}){const u=d?.fields??{},[s,c]=t(()=>({id:i,fields:u,loading:!1})),p=r(null),f=r(null),g=r({parent:o,appState:a,id:i});return g.current={parent:o,appState:a,id:i},n(()=>{if(!l||!d)return;const t=f.current!==i;f.current=i;let r=s.fields;t&&(r=u,p.current=null,c({id:i,fields:u,loading:!1}));const n=d.resolveFields;if(!n)return void(t||c(e=>({...e,fields:u})));let o=!1;const a=p.current&&(p.current.props?.id??"root")===(l.props?.id??"root")?p.current:null,m=setTimeout(()=>{o||c(e=>e.id===i?{...e,loading:!0}:e)},50);return Promise.resolve(n(l,{changed:e(l,a),fields:u,lastFields:r,lastData:a,appState:g.current.appState,parent:g.current.parent})).then(e=>{clearTimeout(m),o||g.current.id!==i||(p.current=l,c({id:i,fields:e,loading:!1}))}),()=>{o=!0,clearTimeout(m)}},[i,l,d]),s.id===i?{fields:s.fields,loading:s.loading}:{fields:u,loading:!1}}export{i as useResolvedFields};
1
+ import{changedProps as e}from"./chunk-KRXQM65X.js";import{useState as t,useRef as r,useEffect as n}from"react";function i({id:i,node:l,block:d,parent:o=null,appState:a=null}){const u=d?.fields??{},[s,c]=t(()=>({id:i,fields:u,loading:!1})),p=r(null),f=r(null),g=r({parent:o,appState:a,id:i});return g.current={parent:o,appState:a,id:i},n(()=>{if(!l||!d)return;const t=f.current!==i;f.current=i;let r=s.fields;t&&(r=u,p.current=null,c({id:i,fields:u,loading:!1}));const n=d.resolveFields;if(!n)return void(t||c(e=>({...e,fields:u})));let o=!1;const a=p.current&&(p.current.props?.id??"root")===(l.props?.id??"root")?p.current:null,m=setTimeout(()=>{o||c(e=>e.id===i?{...e,loading:!0}:e)},50);return Promise.resolve(n(l,{changed:e(l,a),fields:u,lastFields:r,lastData:a,appState:g.current.appState,parent:g.current.parent})).then(e=>{clearTimeout(m),o||g.current.id!==i||(p.current=l,c({id:i,fields:e,loading:!1}))}),()=>{o=!0,clearTimeout(m)}},[i,l,d]),s.id===i?{fields:s.fields,loading:s.loading}:{fields:u,loading:!1}}export{i as useResolvedFields};
@@ -1,6 +1,6 @@
1
- import { S as SlotAddress, N as Node, a as DataConfig, D as Data, F as Found, P as Place, b as SlotEntry, W as WalkInfo } from '../types-DziKCwsN.js';
2
- export { B as BlockShape, c as FieldShape, d as FieldsShape, e as NodeProps, R as RootData } from '../types-DziKCwsN.js';
3
- export { R as ResolvableItem, a as ResolveCache, b as ResolveOptions, c as ResolveTrigger, d as changedProps, e as createResolveCache, f as deepEqual, r as resolveNodeData } from '../resolve-DpH8YQOA.js';
1
+ import { D as Data, a as DataConfig, N as Node, S as SlotAddress, F as Found, P as Place, b as SlotEntry, W as WalkInfo } from '../types-41704JE4.js';
2
+ export { B as BlockShape, c as FieldShape, d as FieldsShape, e as NodeProps, R as RootData } from '../types-41704JE4.js';
3
+ export { R as ResolvableItem, a as ResolveCache, b as ResolveOptions, c as ResolveTrigger, d as changedProps, e as createResolveCache, f as deepEqual, r as resolveNodeData } from '../resolve-D68pb3Bx.js';
4
4
 
5
5
  /**
6
6
  * Finding a node's slots, and reading or writing a value at a prop path.
@@ -26,6 +26,172 @@ export { R as ResolvableItem, a as ResolveCache, b as ResolveOptions, c as Resol
26
26
  type Segment = string | number;
27
27
  declare function getIn(value: unknown, segments: readonly Segment[]): unknown;
28
28
 
29
+ /** One translated value, and the fingerprint of the base value it was made from. */
30
+ interface TranslatedValue {
31
+ v: unknown;
32
+ src: string;
33
+ }
34
+ /** One node's translated values, by prop path. */
35
+ type TranslationEntries = Record<string, TranslatedValue>;
36
+ /** One language's values, beside the document — never inside it. Keyed by node id, or `"root"`. */
37
+ type TranslationOverlay = Record<string, TranslationEntries>;
38
+ /** One translatable value in a document: whose it is, and where in its props. */
39
+ interface TranslationRef {
40
+ id: string;
41
+ path: string;
42
+ }
43
+ interface TranslationStatus {
44
+ /** Values that want a translation (the base is not blank) or have one. */
45
+ total: number;
46
+ /** Values with words in the base and no translation: drawn in the base language. */
47
+ missing: TranslationRef[];
48
+ /** Values whose translation was made from a base value that has since changed. */
49
+ stale: TranslationRef[];
50
+ }
51
+ interface TranslatablePath {
52
+ path: string;
53
+ /** The value there now; `undefined` when the props hold none. */
54
+ value: unknown;
55
+ }
56
+ /** A node, or the root (`{ props }`, no type) — what `resolveNodeData` takes too. */
57
+ interface TranslatableItem {
58
+ type?: string;
59
+ props: Record<string, unknown>;
60
+ }
61
+ /**
62
+ * A short, stable mark of a base value, kept beside its translation as `src`.
63
+ *
64
+ * a string `s<length>.<hash>` the string itself is hashed
65
+ * anything else `j<length>.<hash>` its JSON is hashed, keys sorted at
66
+ * every level, because a document's key
67
+ * order is not kept by the database
68
+ * no value `u`
69
+ *
70
+ * `<length>` is in UTF-16 code units and `<hash>` is FNV-1a (32 bits) over
71
+ * those units, both written in base 36. It is not a secret and not a proof:
72
+ * two values of the same length and the same 32-bit hash read as one, which is
73
+ * enough to notice that words were edited.
74
+ *
75
+ * The first letter names the scheme. These marks are STORED, so the function
76
+ * must go on giving the same answer for the same value; a better scheme takes
77
+ * a new letter rather than changing what `s` and `j` mean.
78
+ */
79
+ declare function translationFingerprint(value: unknown): string;
80
+ /**
81
+ * The props of a node (or of the root) that may be translated, in the order
82
+ * the fields declare them, each with the value it holds now.
83
+ *
84
+ * A top-level value, and one inside an `object` field, is listed whether or
85
+ * not the props hold it (`value: undefined`). One inside an `array` field is
86
+ * listed per item that is there.
87
+ */
88
+ declare function translatablePaths(item: TranslatableItem, config: DataConfig): TranslatablePath[];
89
+ /**
90
+ * The document in one language: every translated value laid over the base,
91
+ * every other value the base's.
92
+ *
93
+ * With no overlay, or an empty one, it is `data` ITSELF. Otherwise only the
94
+ * nodes that took a value are copied, along with what holds them; a block
95
+ * nothing was translated in is the same object before and after, and so is a
96
+ * document no entry lands in.
97
+ *
98
+ * An entry for a node that is not in the document (deleted, or not on this
99
+ * page), for a path the fields no longer declare, or for a block type the
100
+ * config does not know, is passed over — never an error.
101
+ */
102
+ declare function applyTranslation(data: Data, config: DataConfig, overlay?: TranslationOverlay | null): Data;
103
+ /**
104
+ * How far a language has got: how many values want a translation, which have
105
+ * none (`missing`) and which were translated from words that have since
106
+ * changed (`stale`). Both lists are in document order — the root, then the
107
+ * nodes as `walk` visits them — and name the place in the BASE document.
108
+ *
109
+ * A value the base leaves blank wants nothing and is not counted, unless the
110
+ * language has an entry for it. A stale entry under an array that was not
111
+ * found again is reported at the index it is stored under.
112
+ */
113
+ declare function translationStatus(data: Data, config: DataConfig, overlay?: TranslationOverlay | null): TranslationStatus;
114
+ /**
115
+ * The overlay a language's edit comes to. `edited` is the page as it was
116
+ * changed while it was shown in that language — `applyTranslation(base,
117
+ * previous)`, then words typed over it — and the answer holds an entry for
118
+ * every translatable value that differs from the base, with `src` the base
119
+ * value's fingerprint as it is now.
120
+ *
121
+ * - A value equal to the base's makes NO entry: falling back is the absence
122
+ * of one. So does a value that is not there (`undefined`).
123
+ * - Only translatable values are read. A block added, removed or moved in
124
+ * `edited`, an array of another length, a changed number or colour — the
125
+ * structure is the base's alone while a language is being written, and a
126
+ * difference there is passed over, never an error.
127
+ * - `previous` is the overlay the edit started from. An entry the edit did
128
+ * not touch is kept AS IT WAS, old `src` and all, so a save does not
129
+ * quietly turn a stale translation into a current one; and what `previous`
130
+ * holds for nodes that are not on the page is carried over (only
131
+ * `pruneTranslation` drops). Where nothing changed, the answer is
132
+ * `previous` itself.
133
+ */
134
+ declare function extractTranslation(base: Data, edited: Data, config: DataConfig, previous?: TranslationOverlay | null): TranslationOverlay;
135
+ /**
136
+ * Drop what no longer has a place: the entries of a node that is not in the
137
+ * document, and — in a node whose type the config knows — an entry at a path
138
+ * its fields no longer declare or its props no longer reach. An entry whose
139
+ * array item moved is written at the index it is drawn at.
140
+ *
141
+ * A node whose type the config does NOT know keeps its entries untouched for
142
+ * as long as the node is there, and so does any node found inside it: with no
143
+ * fields there is no telling which of its paths are gone, and a block's
144
+ * content is allowed to land before its code.
145
+ *
146
+ * Until a host calls this, the entries of a deleted node stay in the overlay —
147
+ * which is what lets undoing the delete bring its translations back. An
148
+ * overlay with nothing to drop comes back as itself.
149
+ */
150
+ declare function pruneTranslation(data: Data, config: DataConfig, overlay: TranslationOverlay): TranslationOverlay;
151
+ /**
152
+ * Carry an overlay across an edit of the BASE. `previousBase` is the document
153
+ * the overlay was in step with, `nextBase` the document after the edit.
154
+ *
155
+ * Only arrays need it. A node keeps its id wherever it goes, so moving one
156
+ * changes nothing here, and a node that was deleted keeps its entries (see
157
+ * `pruneTranslation`). An array item has no id, so its entries are stored
158
+ * under its INDEX, and this moves them to where the item went:
159
+ *
160
+ * - an item that reads the same before and after keeps its entries, at its
161
+ * new index (in place first; then the lowest unclaimed index before to the
162
+ * lowest after, so identical items keep their order);
163
+ * - an item that is at the same index on both sides but reads differently
164
+ * was edited where it stands: its entries stay, and are stale wherever a
165
+ * base value changed;
166
+ * - an item that is new but reads the same as one that was there (a
167
+ * duplicate) takes a COPY of that item's entries;
168
+ * - an item that is gone takes its entries with it. An item cannot be
169
+ * recognised again once it is out of the array, so a host that must bring
170
+ * them back on undo keeps the overlay in the same history step as the base.
171
+ *
172
+ * Stale entries travel with their item, which reading the overlay later, with
173
+ * `nextBase` alone, could not do: it finds a moved item by its base
174
+ * fingerprint, and a stale entry no longer has one that matches.
175
+ *
176
+ * An overlay the edit does not disturb comes back as itself.
177
+ */
178
+ declare function rebaseTranslation(previousBase: Data, nextBase: Data, config: DataConfig, overlay: TranslationOverlay): TranslationOverlay;
179
+ /**
180
+ * Old id → new id, for a node and its copy: `duplicate` and `copyNode` give
181
+ * every copied node a fresh id, and an overlay is keyed by id. The two are
182
+ * walked side by side, slot by slot and child by child, for as far as they
183
+ * keep the same shape (a `strip` that drops a child ends the pairing there).
184
+ */
185
+ declare function mapIds(source: Node, copy: Node, config: DataConfig): Record<string, string>;
186
+ /**
187
+ * The entries a copied subtree starts with: for every old id in `ids` that the
188
+ * overlay has entries for, the same entries under the new id. ONLY those — lay
189
+ * them over the language's overlay (`{ ...overlay, ...copyTranslation(overlay,
190
+ * ids) }`), or carry them to another page with the clipboard. An entry whose
191
+ * base value the copy changed (`strip`) is stale there, as it should be.
192
+ */
193
+ declare function copyTranslation(overlay: TranslationOverlay | null | undefined, ids: Record<string, string>): TranslationOverlay;
194
+
29
195
  /**
30
196
  * efficient-easel/data — the document, as pure functions.
31
197
  *
@@ -40,6 +206,7 @@ declare function getIn(value: unknown, segments: readonly Segment[]): unknown;
40
206
  * setProps · setRoot change one node's props, or the root's
41
207
  * normalizeData what the editor does to a document it opens
42
208
  * createNode · newId make a block the way the Add panel does
209
+ * applyTranslation · … a page's other languages, kept beside it (./translate)
43
210
  *
44
211
  * THE FORMAT DOES NOT CHANGE. A document goes in and comes out in exactly the
45
212
  * shape Puck 0.20 saves (see ./types). Four rules keep it that way, and the
@@ -205,4 +372,4 @@ declare function replaceNode(data: Data, config: DataConfig, id: string, node: N
205
372
  /** Merge `patch` into the root's props, the same way `setProps` does. */
206
373
  declare function setRoot(data: Data, config: DataConfig, patch: Record<string, unknown>): Data;
207
374
 
208
- export { Data, DataConfig, DataError, type DataErrorCode, type DataInput, Found, Node, Place, ROOT_ID, ROOT_LIST, ROOT_SLOT, type Segment, SlotAddress, SlotEntry, WalkInfo, copyNode, createNode, duplicate, find, getIn, getList, insert, move, newId, normalizeData, parseZoneKey, remove, replaceNode, setProps, setRoot, slotsOf, walk, zoneKey };
375
+ export { Data, DataConfig, DataError, type DataErrorCode, type DataInput, Found, Node, Place, ROOT_ID, ROOT_LIST, ROOT_SLOT, type Segment, SlotAddress, SlotEntry, type TranslatableItem, type TranslatablePath, type TranslatedValue, type TranslationEntries, type TranslationOverlay, type TranslationRef, type TranslationStatus, WalkInfo, applyTranslation, copyNode, copyTranslation, createNode, duplicate, extractTranslation, find, getIn, getList, insert, mapIds, move, newId, normalizeData, parseZoneKey, pruneTranslation, rebaseTranslation, remove, replaceNode, setProps, setRoot, slotsOf, translatablePaths, translationFingerprint, translationStatus, walk, zoneKey };
@@ -1 +1 @@
1
- export{DataError,ROOT_ID,ROOT_LIST,ROOT_SLOT,changedProps,copyNode,createNode,createResolveCache,deepEqual,duplicate,find,getList,insert,move,newId,normalizeData,parseZoneKey,remove,replaceNode,resolveNodeData,setProps,setRoot,slotsOf,walk,zoneKey}from"../chunk-LPRQDDQO.js";export{getIn}from"../chunk-NKB3KVAB.js";
1
+ export{DataError,ROOT_ID,ROOT_LIST,ROOT_SLOT,applyTranslation,changedProps,copyNode,copyTranslation,createNode,createResolveCache,deepEqual,duplicate,extractTranslation,find,getList,insert,mapIds,move,newId,normalizeData,parseZoneKey,pruneTranslation,rebaseTranslation,remove,replaceNode,resolveNodeData,setProps,setRoot,slotsOf,translatablePaths,translationFingerprint,translationStatus,walk,zoneKey}from"../chunk-KRXQM65X.js";export{getIn}from"../chunk-NKB3KVAB.js";
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { HTMLAttributes, ReactNode } from 'react';
3
- import { P as Place, S as SlotAddress } from '../types-DziKCwsN.js';
3
+ import { P as Place, S as SlotAddress } from '../types-41704JE4.js';
4
4
  import { C as CanvasTarget$1 } from '../watch-DmasQA61.js';
5
5
  import { D as DragWords } from '../words-D9ChvbNC.js';
6
6
 
@@ -1,18 +1,18 @@
1
- import{DEFAULT_DRAG_WORDS as e}from"../chunk-O2NLQBFX.js";import{scrollBoxOf as t,startAutoScroll as n,isNoOpDrop as l}from"../chunk-6JDII7N3.js";export{AUTO_SCROLL_EDGE,AUTO_SCROLL_MAX_SPEED,autoScrollDelta,autoScrollSpeed,createDragSession,dropOnRow,gapToMoveIndex,isNoOpDrop,scrollBoxOf,scrollParent,startAutoScroll,stepGap,useTreeDrag}from"../chunk-6JDII7N3.js";import{useCanvasLayout as a,useCanvasEvent as r}from"../chunk-MCLBHENY.js";import{framePointToHost as o,elementScale as s,frameRectToLayer as i,clientPointToLayer as c}from"../chunk-ZNCEOSXO.js";import{CloseIcon as d,SearchIcon as u}from"../chunk-YNZZYHA4.js";import{parseZoneKey as h}from"../chunk-LPRQDDQO.js";import"../chunk-NKB3KVAB.js";import{useRef as p,useEffect as m,useState as f,useCallback as g,useMemo as b,useSyncExternalStore as y,useId as v}from"react";import{jsxs as x,jsx as N}from"react/jsx-runtime";var k=(e,t,n)=>t>=e.left&&t<=e.left+e.width&&n>=e.top&&n<=e.top+e.height,w=e=>e.width*e.height;function D(e,t,n){let l=null;for(const a of e)k(a.box,t,n)&&(!l||w(a.box)<=w(l.box))&&(l=a);return l}function A(e,t,n){const l="x"===e.axis?t:n;let a=0;for(const t of e.children){l>("x"===e.axis?t.left+t.width/2:t.top+t.height/2)&&(a+=1)}return a}function z(e,t){const n=e.children;if("x"===e.axis){const l=n[t-1],a=n[t],r=l&&a?(l.left+l.width+a.left)/2:l?l.left+l.width:a?a.left:e.box.left,o=a??l??e.box;return{left:r-1,top:o.top,width:2,height:o.height}}const l=n[t-1],a=n[t],r=l&&a?(l.top+l.height+a.top)/2:l?l.top+l.height:a?a.top:e.box.top;return{left:e.box.left,top:r-1,width:e.box.width,height:2}}function S(e,t,n,l,a=()=>!1){const r=e.filter(e=>k(e.box,t,n)).sort((e,t)=>w(e.box)-w(t.box));for(const e of r){const r=A(e,t,n),o={...e.list,index:r};if(a(o))return null;if(l(o))return{zone:e,to:o,line:z(e,r)}}return null}function C(e,t=e.key){const n=[];for(let l=1;l<e.children.length;l++){const a=e.children[l-1],r=e.children[l],o=a.top+a.height;n.push({key:`${t}:${l}`,place:{...e.list,index:l},box:{left:e.box.left,top:o,width:e.box.width,height:Math.max(r.top-o,0)}})}return n}var T={nodes:[],zones:[]},E="data-puck-dropzone",L="data-puck-component";function O(e,t){if(e.length>=2){const[t,n]=e;return Math.abs(n.top-t.top)<Math.min(t.height,n.height)/2&&n.left>t.left?"x":"y"}const n=t.ownerDocument.defaultView?.getComputedStyle(t);return n&&n.display.includes("flex")&&n.flexDirection.startsWith("row")?"x":"y"}function j(e,t){const{frame:n,document:l}=e,a=e=>i(n,function(e){const t=e.getBoundingClientRect();return{left:t.left,top:t.top,width:t.width,height:t.height}}(e),t),r=[],o=[];for(const e of l.querySelectorAll(`[${E}]`)){const t=e.getAttribute(E)??"";let n;try{n=h(t)}catch{continue}const l=[...e.querySelectorAll(`[${L}]`)].filter(t=>t.parentElement?.closest(`[${E}]`)===e),s=l.map(a);o.push({key:t,list:n,box:a(e),axis:O(s,e),children:s}),l.forEach((e,t)=>{const l=e.getAttribute(L);l&&r.push({id:l,place:{...n,index:t},box:s[t]})})}return{nodes:r,zones:o}}var B=140,M=e=>({left:e.left,top:e.top,width:e.width,height:e.height});function K(i){const{canvas:d,session:u,readOnly:h,words:v=e.canvas}=i,k=p(i);m(()=>{k.current=i});const w=p(null),A=a(d),[z,C]=f(0),E=g(()=>C(e=>e+1),[]),[L,O]=f(T);m(()=>{const e=w.current;d&&e&&O((k.current.measure??j)(d,e))},[d,A,i.revision,z]);const B=i.model,K=b(()=>B(L),[B,L]),$=y(u.subscribe,u.shown,u.shown),[I,P]=f(null),[R,X]=f(null),Y=p(null),Z=()=>{Y.current&&clearTimeout(Y.current),Y.current=null},_=()=>{Z(),Y.current=setTimeout(()=>{u.get()||P(null)},140)};m(()=>Z,[]),r(d,"mousemove",e=>{const t=w.current;if(!d||!t||k.current.readOnly||u.get())return;Z();const n=o(d.frame,e.clientX,e.clientY,t),l=s(t),a=D(K.sources,n.x/l,n.y/l);P(e=>e?.key===a?.key&&e?.box===a?.box?e:a)}),r(d,"mouseout",e=>{e.relatedTarget||_()}),r(d,"mouseover",e=>{e.relatedTarget||E()});const q=p(null),Q=g(()=>{q.current?.(),q.current=null,X(null)},[]);m(()=>u.subscribe(()=>{u.get()?E():Q()}),[u,Q,E]),m(()=>Q,[Q]);const F=e=>{const t=u.get(),n=w.current;if(!t||!n)return null;const a=c(n,e.clientX,e.clientY),r=S(K.zones,a.x,a.y,e=>k.current.canDrop(t.item,e),e=>!!t.from&&l(t.from,e));return r?{h:t,t:r}:null},G={onDragEnter:e=>{if(q.current)return;const l=t(e.currentTarget.parentElement?.parentElement??null);q.current=l?n(l):null},onDragOver:e=>{const t=F(e);if(!t)return void X(null);e.preventDefault(),e.dataTransfer.dropEffect=/move|all|uninitialized/i.test(e.dataTransfer.effectAllowed)?"move":"copy";const n={zoneKey:t.t.zone.key,line:t.t.line,axis:t.t.zone.axis};X(e=>e&&e.zoneKey===n.zoneKey&&e.line.left===n.line.left&&e.line.top===n.line.top?e:n)},onDragLeave:e=>{const t=e.relatedTarget;t&&e.currentTarget.contains(t)||X(null)},onDrop:e=>{const t=F(e);t&&(e.preventDefault(),u.end(),Q(),k.current.onDrop(t.h.item,t.t.to))}},H={draggable:!h&&!!I,onMouseEnter:Z,onMouseLeave:()=>!u.get()&&_(),onDragStart:e=>{if(I&&!h){u.start({key:I.key,item:I.item,from:I.from}),e.dataTransfer.effectAllowed="move";try{e.dataTransfer.setData("text/plain",I.key)}catch{}}else e.preventDefault()},onDragEnd:()=>{u.end(),Q()},onClick:()=>{I&&!h&&k.current.onPick?.(I.item)}},{seams:J=[]}=K,U=K.zones.filter(e=>0===e.children.length);/* @__PURE__ */
2
- return x("div",{ref:w,className:"es-canvas-layer",children:[$||!i.onSeamAdd||h?null:J.map(e=>/* @__PURE__ */N("div",{className:"es-canvas-seam",style:{left:e.box.left,top:e.box.top+e.box.height/2-8,width:e.box.width,height:16},children:/* @__PURE__ */N("button",{type:"button",className:"es-canvas-seam-add",onClick:()=>i.onSeamAdd?.(e.place),children:v.addButton({label:i.seamLabel??v.addSection})})},e.key)),i.onZoneAdd&&!h?U.map(e=>/* @__PURE__ */N("button",{type:"button",className:R?.zoneKey===e.key?"es-canvas-empty is-over":"es-canvas-empty",style:M(e.box),onClick:()=>i.onZoneAdd?.({...e.list,index:0}),children:v.addButton({label:i.zoneAddLabel??v.addBlock})},e.key)):null,$?/* @__PURE__ */N("div",{className:"es-canvas-catch",...G}):null,R&&!U.some(e=>e.key===R.zoneKey)?/* @__PURE__ */N("div",{className:`es-canvas-line is-${R.axis}`,style:M(R.line)}):null,
3
- /* @__PURE__ */x("div",{className:["es-canvas-handle",I&&!h?"is-shown":"",$?"is-dragging":""].filter(Boolean).join(" "),style:I?{left:I.box.left+2,top:Math.max(I.box.top-11,0)}:void 0,title:I?I.title??v.handle({label:I.label}):void 0,...H,children:[
4
- /* @__PURE__ */N("span",{className:"es-canvas-grip","aria-hidden":"true",children:"⋮⋮"}),I?.label]})]})}var $=e=>e.tiles.length>0&&e.tiles.every(e=>null!=e.cover);function I({groups:t,session:n,itemFor:l,onInsert:a,at:r,hint:o,searchLabel:s,readOnly:i,words:c=e.add}){const h=o??c.hint,p=s??c.search,[m,g]=f(""),b=v(),y=m.trim().toLowerCase(),k=t.map(e=>({...e,tiles:y?e.tiles.filter(e=>((e,t)=>e.label.toLowerCase().includes(t)||(e.keywords??[]).some(e=>e.toLowerCase().includes(t)))(e,y)):e.tiles})).filter(e=>e.tiles.length>0);/* @__PURE__ */
1
+ import{DEFAULT_DRAG_WORDS as e}from"../chunk-O2NLQBFX.js";import{scrollBoxOf as t,startAutoScroll as n,isNoOpDrop as l}from"../chunk-6PS6STGA.js";export{AUTO_SCROLL_EDGE,AUTO_SCROLL_MAX_SPEED,autoScrollDelta,autoScrollSpeed,createDragSession,dropOnRow,gapToMoveIndex,isNoOpDrop,scrollBoxOf,scrollParent,startAutoScroll,stepGap,useTreeDrag}from"../chunk-6PS6STGA.js";import{useCanvasLayout as a,useCanvasEvent as r}from"../chunk-MCLBHENY.js";import{framePointToHost as o,elementScale as s,frameRectToLayer as i,clientPointToLayer as c}from"../chunk-ZNCEOSXO.js";import{CloseIcon as d,SearchIcon as u}from"../chunk-YNZZYHA4.js";import{parseZoneKey as h}from"../chunk-KRXQM65X.js";import"../chunk-NKB3KVAB.js";import{useRef as p,useEffect as m,useState as f,useCallback as g,useMemo as b,useSyncExternalStore as y,useId as v}from"react";import{jsxs as x,jsx as k}from"react/jsx-runtime";var w=(e,t,n)=>t>=e.left&&t<=e.left+e.width&&n>=e.top&&n<=e.top+e.height,N=e=>e.width*e.height;function D(e,t,n){let l=null;for(const a of e)w(a.box,t,n)&&(!l||N(a.box)<=N(l.box))&&(l=a);return l}function S(e,t,n){const l="x"===e.axis?t:n;let a=0;for(const t of e.children){l>("x"===e.axis?t.left+t.width/2:t.top+t.height/2)&&(a+=1)}return a}function A(e,t){const n=e.children;if("x"===e.axis){const l=n[t-1],a=n[t],r=l&&a?(l.left+l.width+a.left)/2:l?l.left+l.width:a?a.left:e.box.left,o=a??l??e.box;return{left:r-1,top:o.top,width:2,height:o.height}}const l=n[t-1],a=n[t],r=l&&a?(l.top+l.height+a.top)/2:l?l.top+l.height:a?a.top:e.box.top;return{left:e.box.left,top:r-1,width:e.box.width,height:2}}function T(e,t,n,l,a=()=>!1){const r=e.filter(e=>w(e.box,t,n)).sort((e,t)=>N(e.box)-N(t.box));for(const e of r){const r=S(e,t,n),o={...e.list,index:r};if(a(o))return null;if(l(o))return{zone:e,to:o,line:A(e,r)}}return null}function z(e,t=e.key){const n=[];for(let l=1;l<e.children.length;l++){const a=e.children[l-1],r=e.children[l],o=a.top+a.height;n.push({key:`${t}:${l}`,place:{...e.list,index:l},box:{left:e.box.left,top:o,width:e.box.width,height:Math.max(r.top-o,0)}})}return n}var C={nodes:[],zones:[]},E="data-puck-dropzone",L="data-puck-component";function O(e,t){if(e.length>=2){const[t,n]=e;return Math.abs(n.top-t.top)<Math.min(t.height,n.height)/2&&n.left>t.left?"x":"y"}const n=t.ownerDocument.defaultView?.getComputedStyle(t);return n&&n.display.includes("flex")&&n.flexDirection.startsWith("row")?"x":"y"}function j(e,t){const{frame:n,document:l}=e,a=e=>i(n,function(e){const t=e.getBoundingClientRect();return{left:t.left,top:t.top,width:t.width,height:t.height}}(e),t),r=[],o=[];for(const e of l.querySelectorAll(`[${E}]`)){const t=e.getAttribute(E)??"";let n;try{n=h(t)}catch{continue}const l=[...e.querySelectorAll(`[${L}]`)].filter(t=>t.parentElement?.closest(`[${E}]`)===e),s=l.map(a);o.push({key:t,list:n,box:a(e),axis:O(s,e),children:s}),l.forEach((e,t)=>{const l=e.getAttribute(L);l&&r.push({id:l,place:{...n,index:t},box:s[t]})})}return{nodes:r,zones:o}}var B=140,M=e=>({left:e.left,top:e.top,width:e.width,height:e.height});function K(i){const{canvas:d,session:u,readOnly:h,words:v=e.canvas}=i,w=p(i);m(()=>{w.current=i});const N=p(null),S=a(d),[A,z]=f(0),E=g(()=>z(e=>e+1),[]),[L,O]=f(C);m(()=>{const e=N.current;d&&e&&O((w.current.measure??j)(d,e))},[d,S,i.revision,A]);const B=i.model,K=b(()=>B(L),[B,L]),X=y(u.subscribe,u.shown,u.shown),[$,P]=f(null),[R,Y]=f(null),Z=p(null),_=()=>{Z.current&&clearTimeout(Z.current),Z.current=null},G=()=>{_(),Z.current=setTimeout(()=>{u.get()||P(null)},140)};m(()=>_,[]),r(d,"mousemove",e=>{const t=N.current;if(!d||!t||w.current.readOnly||u.get())return;_();const n=o(d.frame,e.clientX,e.clientY,t),l=s(t),a=D(K.sources,n.x/l,n.y/l);P(e=>e?.key===a?.key&&e?.box===a?.box?e:a)}),r(d,"mouseout",e=>{e.relatedTarget||G()}),r(d,"mouseover",e=>{e.relatedTarget||E()});const q=p(null),F=g(()=>{q.current?.(),q.current=null,Y(null)},[]);m(()=>u.subscribe(()=>{u.get()?E():F()}),[u,F,E]),m(()=>F,[F]);const H=e=>{const t=u.get(),n=N.current;if(!t||!n)return null;const a=c(n,e.clientX,e.clientY),r=T(K.zones,a.x,a.y,e=>w.current.canDrop(t.item,e),e=>!!t.from&&l(t.from,e));return r?{h:t,t:r}:null},I={onDragEnter:e=>{if(q.current)return;const l=t(e.currentTarget.parentElement?.parentElement??null);q.current=l?n(l):null},onDragOver:e=>{const t=H(e);if(!t)return void Y(null);e.preventDefault(),e.dataTransfer.dropEffect=/move|all|uninitialized/i.test(e.dataTransfer.effectAllowed)?"move":"copy";const n={zoneKey:t.t.zone.key,line:t.t.line,axis:t.t.zone.axis};Y(e=>e&&e.zoneKey===n.zoneKey&&e.line.left===n.line.left&&e.line.top===n.line.top?e:n)},onDragLeave:e=>{const t=e.relatedTarget;t&&e.currentTarget.contains(t)||Y(null)},onDrop:e=>{const t=H(e);t&&(e.preventDefault(),u.end(),F(),w.current.onDrop(t.h.item,t.t.to))}},Q={draggable:!h&&!!$,onMouseEnter:_,onMouseLeave:()=>!u.get()&&G(),onDragStart:e=>{if($&&!h){u.start({key:$.key,item:$.item,from:$.from}),e.dataTransfer.effectAllowed="move";try{e.dataTransfer.setData("text/plain",$.key)}catch{}}else e.preventDefault()},onDragEnd:()=>{u.end(),F()},onClick:()=>{$&&!h&&w.current.onPick?.($.item)}},{seams:U=[]}=K,V=K.zones.filter(e=>0===e.children.length);/* @__PURE__ */
2
+ return x("div",{ref:N,className:"es-canvas-layer",children:[X||!i.onSeamAdd||h?null:U.map(e=>/* @__PURE__ */k("div",{className:"es-canvas-seam",style:{left:e.box.left,top:e.box.top+e.box.height/2-8,width:e.box.width,height:16},children:/* @__PURE__ */k("button",{type:"button",className:"es-canvas-seam-add",onClick:()=>i.onSeamAdd?.(e.place),children:v.addButton({label:i.seamLabel??v.addSection})})},e.key)),i.onZoneAdd&&!h?V.map(e=>/* @__PURE__ */k("button",{type:"button",className:R?.zoneKey===e.key?"es-canvas-empty is-over":"es-canvas-empty",style:M(e.box),onClick:()=>i.onZoneAdd?.({...e.list,index:0}),children:v.addButton({label:i.zoneAddLabel??v.addBlock})},e.key)):null,X?/* @__PURE__ */k("div",{className:"es-canvas-catch",...I}):null,R&&!V.some(e=>e.key===R.zoneKey)?/* @__PURE__ */k("div",{className:`es-canvas-line is-${R.axis}`,style:M(R.line)}):null,
3
+ /* @__PURE__ */x("div",{className:["es-canvas-handle",$&&!h?"is-shown":"",X?"is-dragging":""].filter(Boolean).join(" "),style:$?{left:$.box.left+2,top:Math.max($.box.top-11,0)}:void 0,title:$?$.title??v.handle({label:$.label}):void 0,...Q,children:[
4
+ /* @__PURE__ */k("span",{className:"es-canvas-grip","aria-hidden":"true",children:"⋮⋮"}),$?.label]})]})}var X=e=>e.tiles.length>0&&e.tiles.every(e=>null!=e.cover);function $({groups:t,session:n,itemFor:l,onInsert:a,at:r,hint:o,searchLabel:s,readOnly:i,words:c=e.add}){const h=o??c.hint,p=s??c.search,[m,g]=f(""),b=v(),y=m.trim().toLowerCase(),w=t.map(e=>({...e,tiles:y?e.tiles.filter(e=>((e,t)=>e.label.toLowerCase().includes(t)||(e.keywords??[]).some(e=>e.toLowerCase().includes(t)))(e,y)):e.tiles})).filter(e=>e.tiles.length>0);/* @__PURE__ */
5
5
  return x("div",{className:"es-add",children:[r?/* @__PURE__ */x("div",{className:"es-add-at",role:"status",children:[
6
- /* @__PURE__ */N("span",{children:r.label}),
7
- /* @__PURE__ */N("button",{type:"button",className:"es-add-at-clear","aria-label":c.stop,title:c.stop,onClick:r.onClear,children:/* @__PURE__ */N(d,{size:12,"aria-hidden":"true"})})]}):null,
8
- /* @__PURE__ */N("p",{className:"es-add-hint",children:h}),
6
+ /* @__PURE__ */k("span",{children:r.label}),
7
+ /* @__PURE__ */k("button",{type:"button",className:"es-add-at-clear","aria-label":c.stop,title:c.stop,onClick:r.onClear,children:/* @__PURE__ */k(d,{size:12,"aria-hidden":"true"})})]}):null,
8
+ /* @__PURE__ */k("p",{className:"es-add-hint",children:h}),
9
9
  /* @__PURE__ */x("div",{className:"es-add-search",children:[
10
- /* @__PURE__ */N(u,{size:16,"aria-hidden":"true"}),
11
- /* @__PURE__ */N("input",{id:b,type:"search","aria-label":p,placeholder:c.searchPlaceholder({label:p}),value:m,onChange:e=>g(e.target.value)}),m?/* @__PURE__ */N("button",{type:"button",className:"es-add-search-clear","aria-label":c.clearSearch,onClick:()=>g(""),children:/* @__PURE__ */N(d,{size:12,"aria-hidden":"true"})}):null]}),0===k.length?/* @__PURE__ */x("div",{className:"es-add-empty",role:"status",children:[
12
- /* @__PURE__ */N("div",{className:"es-add-empty-title",children:c.nothing({query:m.trim()})}),
13
- /* @__PURE__ */N("div",{className:"es-add-empty-sub",children:c.tryAnother})]}):k.map(e=>/* @__PURE__ */x("section",{className:"es-add-group","aria-label":e.title,children:[
10
+ /* @__PURE__ */k(u,{size:16,"aria-hidden":"true"}),
11
+ /* @__PURE__ */k("input",{id:b,type:"search","aria-label":p,placeholder:c.searchPlaceholder({label:p}),value:m,onChange:e=>g(e.target.value)}),m?/* @__PURE__ */k("button",{type:"button",className:"es-add-search-clear","aria-label":c.clearSearch,onClick:()=>g(""),children:/* @__PURE__ */k(d,{size:12,"aria-hidden":"true"})}):null]}),0===w.length?/* @__PURE__ */x("div",{className:"es-add-empty",role:"status",children:[
12
+ /* @__PURE__ */k("div",{className:"es-add-empty-title",children:c.nothing({query:m.trim()})}),
13
+ /* @__PURE__ */k("div",{className:"es-add-empty-sub",children:c.tryAnother})]}):w.map(e=>/* @__PURE__ */x("section",{className:"es-add-group","aria-label":e.title,children:[
14
14
  /* @__PURE__ */x("div",{className:"es-add-group-head",children:[
15
- /* @__PURE__ */N("span",{className:"es-add-group-title",children:e.title}),
16
- /* @__PURE__ */N("span",{className:"es-add-group-count",children:e.tiles.length})]}),
17
- /* @__PURE__ */N("div",{className:$(e)?"es-add-grid is-cards":"es-add-grid",children:e.tiles.map(e=>{/* @__PURE__ */return x("button",{type:"button",className:null!=e.cover?"es-add-tile has-cover":"es-add-tile",draggable:!i,"aria-disabled":i||void 0,"aria-label":c.tile({label:e.label}),title:i?void 0:e.title??c.tile({label:e.label}),onDragStart:(t=e.type,e=>{if(i)e.preventDefault();else{n.start({key:`new:${t}`,item:l(t)}),e.dataTransfer.effectAllowed="copy";try{e.dataTransfer.setData("text/plain",t)}catch{}}}),onDragEnd:()=>n.end(),onClick:()=>!i&&a(e.type),children:[null!=e.cover?/* @__PURE__ */N("span",{className:"es-add-tile-cover","aria-hidden":"true",children:e.cover}):e.icon?/* @__PURE__ */N("span",{className:"es-add-tile-glyph","aria-hidden":"true",children:e.icon}):null,
18
- /* @__PURE__ */N("span",{className:"es-add-tile-label",children:e.label})]},e.type);var t})})]},e.title))]})}export{I as AddPanel,K as CanvasDragLayer,T as EMPTY_MEASURE,B as HANDLE_GRACE_MS,S as canvasTarget,k as contains,A as gapInZone,z as gapLine,j as measureCanvas,D as pickSource,C as seamsBetween};
15
+ /* @__PURE__ */k("span",{className:"es-add-group-title",children:e.title}),
16
+ /* @__PURE__ */k("span",{className:"es-add-group-count",children:e.tiles.length})]}),
17
+ /* @__PURE__ */k("div",{className:X(e)?"es-add-grid is-cards":"es-add-grid",children:e.tiles.map(e=>{/* @__PURE__ */return x("button",{type:"button",className:null!=e.cover?"es-add-tile has-cover":"es-add-tile",draggable:!i,"aria-disabled":i||void 0,"aria-label":c.tile({label:e.label}),title:i?void 0:e.title??c.tile({label:e.label}),onDragStart:(t=e.type,e=>{if(i)e.preventDefault();else{n.start({key:`new:${t}`,item:l(t)}),e.dataTransfer.effectAllowed="copy";try{e.dataTransfer.setData("text/plain",t)}catch{}}}),onDragEnd:()=>n.end(),onClick:()=>!i&&a(e.type),children:[null!=e.cover?/* @__PURE__ */k("span",{className:"es-add-tile-cover","aria-hidden":"true",children:e.cover}):e.icon?/* @__PURE__ */k("span",{className:"es-add-tile-glyph","aria-hidden":"true",children:e.icon}):null,
18
+ /* @__PURE__ */k("span",{className:"es-add-tile-label",children:e.label})]},e.type);var t})})]},e.title))]})}export{$ as AddPanel,K as CanvasDragLayer,C as EMPTY_MEASURE,B as HANDLE_GRACE_MS,T as canvasTarget,w as contains,S as gapInZone,A as gapLine,j as measureCanvas,D as pickSource,z as seamsBetween};
@@ -1,13 +1,13 @@
1
1
  import { DataInput } from '../data/index.js';
2
- import { N as NodeSelection } from '../plan-DtNw2VuI.js';
3
- export { I as ItemSelector } from '../plan-DtNw2VuI.js';
4
- import { E as EditorConfig, a as EditorView, b as EditorAction, P as Permissions, c as EditorCore, d as EditorUi } from '../types-_Vayx8ov.js';
5
- export { A as AppState, e as EditorHistory, H as HistoryEntry, S as SetDataPatch } from '../types-_Vayx8ov.js';
6
- import { S as SlotAddress, D as Data, P as Place } from '../types-DziKCwsN.js';
7
- import { c as ResolveTrigger, a as ResolveCache, R as ResolvableItem } from '../resolve-DpH8YQOA.js';
2
+ import { N as NodeSelection } from '../plan-DChbUXdS.js';
3
+ export { I as ItemSelector } from '../plan-DChbUXdS.js';
4
+ import { E as EditorConfig, a as EditorView, b as EditorAction, P as Permissions, c as EditorCore, d as EditorUi } from '../types-Dy6oR6Z2.js';
5
+ export { A as AppState, e as EditorHistory, H as HistoryEntry, S as SetDataPatch } from '../types-Dy6oR6Z2.js';
6
+ import { S as SlotAddress, D as Data, P as Place } from '../types-41704JE4.js';
7
+ import { c as ResolveTrigger, a as ResolveCache, R as ResolvableItem } from '../resolve-D68pb3Bx.js';
8
8
  import * as react from 'react';
9
9
  import { ReactNode, CSSProperties, ComponentType, ReactElement } from 'react';
10
- import { b as NodeOpsHost, C as ClipboardEntry } from '../useNodeOps-6IAej9jy.js';
10
+ import { b as NodeOpsHost, C as ClipboardEntry } from '../useNodeOps-BF0fQsif.js';
11
11
  import { I as InspectorFields } from '../types-CEqUFH2j.js';
12
12
  import '../buckets-1vRlQceY.js';
13
13
 
@@ -1,9 +1,9 @@
1
- import{DEFAULT_CANVAS_WORDS as e}from"../chunk-GGTPNGFJ.js";import{useResolvedFields as t}from"../chunk-FJE4IDBQ.js";import{toItemSelector as n,fromItemSelector as o,useNodeOps as r}from"../chunk-EFTTSIMK.js";import{useWords as i}from"../chunk-MFIRYGHW.js";import{setCanvasNonce as a}from"../chunk-ZNCEOSXO.js";import{find as s,ROOT_ID as l,getList as d,remove as c,parseZoneKey as u,move as p,duplicate as h,replaceNode as f,createNode as m,insert as v,normalizeData as y,createResolveCache as g,resolveNodeData as k,ROOT_SLOT as b}from"../chunk-LPRQDDQO.js";import{topLevelSlotKeys as w,fieldsFrom as I,defaultsFrom as S}from"../chunk-NKB3KVAB.js";import{createContext as C,useEffect as D,useContext as E,useRef as O,useSyncExternalStore as x,useState as A,useLayoutEffect as z,useMemo as M,useCallback as Z}from"react";import{jsx as $,jsxs as N}from"react/jsx-runtime";import{createPortal as B}from"react-dom";function P(e){return!["setData","setUi","set"].includes(e.type)}var R=(e,t,n,o)=>{const r=d(e,t,u(n));return r?.[o]??null},j=(e,t,n,o,r)=>{const i=R(e,t,n,o);if(!i)throw new Error(`${r}: nothing at ${n}[${o}]`);return i};function F(e,t){const{selection:o}=e;return{...e.ui,itemSelector:n(e.data,t,o),selectedSlot:o&&"slot"===o.kind?{parentId:o.parentId,slot:o.slot}:null}}function K(e,t,n){return n?"node"===n.kind?s(e,t,n.id)?n:null:n.parentId===l?d(e,t,n)?n:null:s(e,t,n.parentId)&&d(e,t,n)?n:null:null}function L(e,t,n,r=!1){const{itemSelector:i,selectedSlot:a,...s}=n;let l=e.selection;var d;return"itemSelector"in n&&(l=o(e.data,t,i??null)),"selectedSlot"in n&&(a?l=(d=a)?{kind:"slot",parentId:d.parentId,slot:d.slot}:null:"slot"===l?.kind&&(l=null)),{...e,selection:l,ui:r?s:{...e.ui,...s}}}function T(e,t,n){const o=V(e,t,n);if(o===e)return e;const r=K(o.data,n,o.selection);return r===o.selection?o:{...o,selection:r}}function V(e,t,n){const{data:o}=e;switch(t.type){case"setData":{const n="function"==typeof t.data?t.data(o):t.data;return{...e,data:{...o,...n}}}case"setUi":return L(e,n,"function"==typeof t.ui?t.ui(F(e,n)):t.ui);case"set":{const r={data:o,ui:F(e,n)},i="function"==typeof t.state?t.state(r):t.state;let a=i.data?{...e,data:i.data}:e;return i.ui&&(a=L(a,n,i.ui,!0)),a}case"insert":{const r={...u(t.destinationZone),index:t.destinationIndex},i=m(n,t.componentType,{},t.id?{id:t.id}:{});return{...e,data:v(o,n,r,i)}}case"replace":{const r=j(o,n,t.destinationZone,t.destinationIndex,"replace");if(r.props.id!==t.data.props.id)throw new Error("Can't change the id during a replace action. Use remove and insert for a new node.");return{...e,data:f(o,n,r.props.id,t.data)}}case"replaceRoot":{const n={...o.root,props:{...o.root.props,...t.root.props},readOnly:t.root.readOnly};return{...e,data:{...o,root:n}}}case"duplicate":{const r=j(o,n,t.sourceZone,t.sourceIndex,"duplicate"),i=h(o,n,r.props.id),a=R(i,n,t.sourceZone,t.sourceIndex+1);return{...e,data:i,selection:a?{kind:"node",id:a.props.id}:e.selection}}case"reorder":return V(e,{...t,type:"move",sourceZone:t.destinationZone},n);case"move":{if(t.sourceZone===t.destinationZone&&t.sourceIndex===t.destinationIndex)return e;const r=R(o,n,t.sourceZone,t.sourceIndex);if(!r)return e;const i={...u(t.destinationZone),index:t.destinationIndex};return{...e,data:p(o,n,r.props.id,i)}}case"remove":{const r=j(o,n,t.zone,t.index,"remove");return{...e,data:c(o,n,r.props.id)}}default:return e}}var H={drag:!0,duplicate:!0,delete:!0,edit:!0,insert:!0},q={leftSideBarVisible:!0,rightSideBarVisible:!0,arrayState:{},componentList:{},isDragging:!1,previewMode:"edit",viewports:{current:{width:360,height:"auto"},options:[],controlsVisible:!0},field:{focus:null}},G=0,Q=()=>`history-${G+=1}`;function U(e){let t=e.config;const r=e.now??(()=>Date.now()),i=e.historyCoalesceMs??250;let a=e.permissions??{};const l=y(e.data,t);let c={data:l,selection:null,ui:{...q}};if(e.ui){const{itemSelector:n,selectedSlot:r,...i}=e.ui;c={data:l,selection:r?{kind:"slot",...r}:o(l,t,n??null),ui:{...q,...i}}}let u=[{core:c,at:-1/0,sealed:!0,id:Q()}],p=0;const h=e=>{const t=u[p],n=r();!e&&p===u.length-1&&p>0&&!t.sealed&&n-t.at<i?u=[...u.slice(0,p),{...t,core:c,at:n}]:(u=[...u.slice(0,p+1),{core:c,at:n,sealed:e,id:Q()}],p=u.length-1)},m=/* @__PURE__ */new Set;let v=null,b=null,w=0,I=null,S=!1;const C=()=>{for(const e of[...m])e()},D=()=>{u=[...u.slice(0,p),{...u[p],core:c},...u.slice(p+1)]},E=(t,n)=>{w>0?S=S||n:(n?h(!1):c!==t&&D(),c.data!==t.data&&e.onChange?.(c.data),c!==t&&C())},O=e=>{const n=c;if(c=T(c,e,t),c===n)return;const o=e.recordHistory??P(e);E(n,o&&c.data!==n.data)},x=t=>{0===w&&(I=c,S=!1),w+=1;try{t()}catch(e){throw w-=1,0===w&&I&&(c=I,I=null),e}if(w-=1,w>0||!I)return;const n=I;I=null,S&&c.data!==n.data?h(!0):c!==n&&D(),c.data!==n.data&&e.onChange?.(c.data),c!==n&&C()},A=e=>{const n=c,o=K(c.data,t,e);var r,i;(r=o,i=c.selection,r===i||r&&i&&r.kind===i.kind&&("node"===r.kind&&"node"===i.kind?r.id===i.id:"slot"===r.kind&&"slot"===i.kind&&r.parentId===i.parentId&&r.slot===i.slot))||(c={...c,selection:o},E(n,!1))},z=t=>{const n=c;p=t,c=u[p].core,c.data!==n.data&&e.onChange?.(c.data),c!==n&&C()},M=(e={})=>{const n=e.root?t.root?.permissions:t.components[e.item?.type??e.type??""]?.permissions;return{...H,...a,...n}},Z=g(),$={resolveCache:Z,async resolveAll({trigger:e="load",metadata:n}={}){const o=c.data,r={type:"root",props:{...o.root.props??{}}},i=[...o.content,...Object.values(o.zones??{}).flat()],[a,...l]=await Promise.all([k(r,t,{cache:Z,trigger:e,metadata:n}),...i.map(o=>k(o,t,{cache:Z,trigger:e,metadata:n}))]);x(()=>{const e=c;let n=c.data;l.forEach((e,r)=>{if(!e.didChange)return;const a=i[r].props.id,l=s(n,t,a)?.node;l&&l===s(o,t,a)?.node&&(n=f(n,t,a,e.node))}),a.didChange&&n.root===o.root&&(n={...n,root:{...n.root,props:a.node.props,readOnly:a.node.readOnly??n.root.readOnly}}),n!==c.data&&(c={...c,data:n,selection:K(n,t,c.selection)},E(e,!1))})},get config(){return t},getState(){if(v&&b===c)return v;const e=c,o={data:e.data,ui:F(e,t)},r="node"===e.selection?.kind?s(e.data,t,e.selection.id)?.node??null:null;return v={appState:o,selection:e.selection,selectedItem:r,config:t,dispatch:O,history:{back:()=>$.undo(),forward:()=>$.redo(),hasPast:p>0,hasFuture:p<u.length-1,histories:u.map(e=>({id:e.id,state:{data:e.core.data,ui:F(e.core,t)}})),index:p,setHistoryIndex:e=>{e>=0&&e<u.length&&e!==p&&z(e)}},getPermissions:M,getItemById:n=>s(e.data,t,n)?.node,getItemBySelector:n=>function(e,t,n){const[o,r]=(n.zone??"root:default-zone").split(/:(.*)/s);return d(e,t,{parentId:o,slot:r})?.[n.index]}(e.data,t,n),getSelectorForId:o=>{const r=n(e.data,t,{kind:"node",id:o});return r?{index:r.index,zone:r.zone??"root:default-zone"}:void 0}},b=e,v},subscribe:e=>(m.add(e),()=>{m.delete(e)}),dispatch:O,batch:x,select:e=>A(e?{kind:"node",id:e}:null),selectSlot:e=>A(e?{kind:"slot",parentId:e.parentId,slot:e.slot}:null),run(e){x(()=>{const n=c,o=void 0===e.select?c.selection:e.select;c={...c,data:e.data,selection:K(e.data,t,o)},E(n,e.data!==n.data)})},load(e,n={}){const o=c,r=y(e,t);c={...c,data:r,selection:K(r,t,n.selection??c.selection)},n.keepHistory||(u=[{core:c,at:-1/0,sealed:!0,id:Q()}],p=0),c!==o&&C()},undo(){p>0&&z(p-1)},redo(){p<u.length-1&&z(p+1)},setPermissions(e){a=e,v=null,C()},setConfig(e){e!==t&&(t=e,v=null,C())}};return $}function Y(e,t){const n=e=>{if(e.altKey)return;e.metaKey!==e.ctrlKey&&("KeyZ"===e.code?(e.preventDefault(),e.shiftKey?t.redo():t.undo()):"KeyY"!==e.code||e.shiftKey||(e.preventDefault(),t.redo()))};return e.addEventListener("keydown",n),()=>e.removeEventListener("keydown",n)}var J=C(null);function W({editor:e,hotkeys:t=!0,resolveOnMount:n=!0,children:o}){return D(()=>{n&&e.resolveAll()},[e,n]),D(()=>{if(t&&"undefined"!=typeof document)return Y(document,e)},[e,t]),/* @__PURE__ */$(J.Provider,{value:e,children:o})}function X(){const e=E(J);if(!e)throw new Error("useEditor: no <EditorProvider> above this component");return e}function _(e){const t=X(),n=O({view:null,selector:null,value:void 0,has:!1}),o=()=>{const o=t.getState(),r=n.current;if(r.has&&r.view===o&&r.selector===e)return r.value;const i=e(o);return r.has&&Object.is(r.value,i)?(n.current={view:o,selector:e,value:r.value,has:!0},r.value):(n.current={view:o,selector:e,value:i,has:!0},i)};return x(t.subscribe,o,o)}function ee(){return function(e){return _(e)}}var te="data-puck-component",ne="data-puck-dropzone",oe={},re="data-es-mirror";function ie(e,t,n){for(const e of Array.from(t.head.querySelectorAll(`[${re}]`)))e.remove();for(const o of Array.from(e.head.querySelectorAll('style, link[rel="stylesheet"]'))){const e=o.cloneNode(!0);e.setAttribute(re,""),n&&e.setAttribute("nonce",n),t.head.appendChild(e)}}function ae({children:t,id:n="preview-frame",title:o,className:r,style:s,mirrorStyles:l=!0,onDocument:d,height:c="auto",nonce:u}){const p=i("canvas",e),h=O(null),[f,m]=A(null);return z(()=>{const e=h.current,t=f?.ownerDocument.defaultView;if("auto"!==c||!e||!f||!t)return;const n=()=>{e.style.height=`${Math.ceil(f.getBoundingClientRect().height)}px`};n();const o=t.ResizeObserver,r=o?new o(n):null;return r?.observe(f),()=>r?.disconnect()},[f,c]),z(()=>{let e=h.current?.contentDocument;if(!e)return;"CSS1Compat"!==e.compatMode&&(e.open(),e.write("<!DOCTYPE html><html><head></head><body></body></html>"),e.close(),e=h.current?.contentDocument??e),e.body||e.documentElement.appendChild(e.createElement("body")),e.body.style.margin="0";const t=e.createElement("div");t.setAttribute("data-puck-entry",""),t.id="frame-root","fill"===c&&t.classList.add("es-frame-fill"),e.body.appendChild(t),a(e,u),m(t),d?.(e);let n=null;const o=h.current?.ownerDocument;if(l&&o){ie(o,e,u);const t=o.defaultView;t&&"MutationObserver"in t&&(n=new t.MutationObserver(()=>ie(o,e,u)),n.observe(o.head,{childList:!0,subtree:!0,characterData:!0}))}return()=>{n?.disconnect(),t.remove(),m(null),d?.(null)}},[]),/* @__PURE__ */$("iframe",{ref:h,id:n,title:o??p.frame,className:r,style:{border:0,width:"100%",display:"block",..."fill"===c?{height:"100%"}:null,...s},children:f?B(t,f):null})}var se=C(null),le=C(oe),de=[];function ce({parentId:e,slot:t,className:n,style:o,minEmptyHeight:r=128}){const i=X(),a=_(n=>d(n.appState.data,i.config,{parentId:e,slot:t})??de),s=_(t=>"node"===t.selection?.kind&&t.selection.id===e&&e!==l),c=_(n=>"slot"===n.selection?.kind&&n.selection.parentId===e&&n.selection.slot===t),u=E(se),p=["es-zone"];return a.length&&p.push("has-children"),e===l&&p.push("is-root"),(s||c)&&p.push("is-area-selected"),null!==u&&u===e&&e!==l&&p.push("is-hovering-area"),n&&p.push(n),/* @__PURE__ */$("div",{className:p.join(" "),[ne]:`${e}:${t}`,style:{...o,"--min-empty-height":`${r}px`},children:a.map(e=>/* @__PURE__ */$(he,{node:e},e.props.id))})}function ue(e,t,n,o){const r="root"===t?e.root:e.components[t],i={...o};for(const e of w(I(r)))i[e]=function(t={}){/* @__PURE__ */
1
+ import{DEFAULT_CANVAS_WORDS as e}from"../chunk-GGTPNGFJ.js";import{useResolvedFields as t}from"../chunk-YRLPFZW3.js";import{toItemSelector as n,fromItemSelector as o,useNodeOps as r}from"../chunk-D2BCHTQR.js";import{useWords as i}from"../chunk-MFIRYGHW.js";import{setCanvasNonce as a}from"../chunk-ZNCEOSXO.js";import{find as s,ROOT_ID as l,getList as d,remove as c,parseZoneKey as u,move as p,duplicate as h,replaceNode as f,createNode as m,insert as v,normalizeData as y,createResolveCache as g,resolveNodeData as k,ROOT_SLOT as b}from"../chunk-KRXQM65X.js";import{topLevelSlotKeys as w,fieldsFrom as S,defaultsFrom as I}from"../chunk-NKB3KVAB.js";import{createContext as C,useEffect as x,useContext as O,useRef as D,useSyncExternalStore as E,useState as A,useLayoutEffect as z,useMemo as M,useCallback as Z}from"react";import{jsx as $,jsxs as R}from"react/jsx-runtime";import{createPortal as N}from"react-dom";function B(e){return!["setData","setUi","set"].includes(e.type)}var P=(e,t,n,o)=>{const r=d(e,t,u(n));return r?.[o]??null},j=(e,t,n,o,r)=>{const i=P(e,t,n,o);if(!i)throw new Error(`${r}: nothing at ${n}[${o}]`);return i};function K(e,t){const{selection:o}=e;return{...e.ui,itemSelector:n(e.data,t,o),selectedSlot:o&&"slot"===o.kind?{parentId:o.parentId,slot:o.slot}:null}}function L(e,t,n){return n?"node"===n.kind?s(e,t,n.id)?n:null:n.parentId===l?d(e,t,n)?n:null:s(e,t,n.parentId)&&d(e,t,n)?n:null:null}function F(e,t,n,r=!1){const{itemSelector:i,selectedSlot:a,...s}=n;let l=e.selection;var d;return"itemSelector"in n&&(l=o(e.data,t,i??null)),"selectedSlot"in n&&(a?l=(d=a)?{kind:"slot",parentId:d.parentId,slot:d.slot}:null:"slot"===l?.kind&&(l=null)),{...e,selection:l,ui:r?s:{...e.ui,...s}}}function H(e,t,n){const o=V(e,t,n);if(o===e)return e;const r=L(o.data,n,o.selection);return r===o.selection?o:{...o,selection:r}}function V(e,t,n){const{data:o}=e;switch(t.type){case"setData":{const n="function"==typeof t.data?t.data(o):t.data;return{...e,data:{...o,...n}}}case"setUi":return F(e,n,"function"==typeof t.ui?t.ui(K(e,n)):t.ui);case"set":{const r={data:o,ui:K(e,n)},i="function"==typeof t.state?t.state(r):t.state;let a=i.data?{...e,data:i.data}:e;return i.ui&&(a=F(a,n,i.ui,!0)),a}case"insert":{const r={...u(t.destinationZone),index:t.destinationIndex},i=m(n,t.componentType,{},t.id?{id:t.id}:{});return{...e,data:v(o,n,r,i)}}case"replace":{const r=j(o,n,t.destinationZone,t.destinationIndex,"replace");if(r.props.id!==t.data.props.id)throw new Error("Can't change the id during a replace action. Use remove and insert for a new node.");return{...e,data:f(o,n,r.props.id,t.data)}}case"replaceRoot":{const n={...o.root,props:{...o.root.props,...t.root.props},readOnly:t.root.readOnly};return{...e,data:{...o,root:n}}}case"duplicate":{const r=j(o,n,t.sourceZone,t.sourceIndex,"duplicate"),i=h(o,n,r.props.id),a=P(i,n,t.sourceZone,t.sourceIndex+1);return{...e,data:i,selection:a?{kind:"node",id:a.props.id}:e.selection}}case"reorder":return V(e,{...t,type:"move",sourceZone:t.destinationZone},n);case"move":{if(t.sourceZone===t.destinationZone&&t.sourceIndex===t.destinationIndex)return e;const r=P(o,n,t.sourceZone,t.sourceIndex);if(!r)return e;const i={...u(t.destinationZone),index:t.destinationIndex};return{...e,data:p(o,n,r.props.id,i)}}case"remove":{const r=j(o,n,t.zone,t.index,"remove");return{...e,data:c(o,n,r.props.id)}}default:return e}}var T={drag:!0,duplicate:!0,delete:!0,edit:!0,insert:!0},q={leftSideBarVisible:!0,rightSideBarVisible:!0,arrayState:{},componentList:{},isDragging:!1,previewMode:"edit",viewports:{current:{width:360,height:"auto"},options:[],controlsVisible:!0},field:{focus:null}},G=0,Y=()=>`history-${G+=1}`;function U(e){let t=e.config;const r=e.now??(()=>Date.now()),i=e.historyCoalesceMs??250;let a=e.permissions??{};const l=y(e.data,t);let c={data:l,selection:null,ui:{...q}};if(e.ui){const{itemSelector:n,selectedSlot:r,...i}=e.ui;c={data:l,selection:r?{kind:"slot",...r}:o(l,t,n??null),ui:{...q,...i}}}let u=[{core:c,at:-1/0,sealed:!0,id:Y()}],p=0;const h=e=>{const t=u[p],n=r();!e&&p===u.length-1&&p>0&&!t.sealed&&n-t.at<i?u=[...u.slice(0,p),{...t,core:c,at:n}]:(u=[...u.slice(0,p+1),{core:c,at:n,sealed:e,id:Y()}],p=u.length-1)},m=/* @__PURE__ */new Set;let v=null,b=null,w=0,S=null,I=!1;const C=()=>{for(const e of[...m])e()},x=()=>{u=[...u.slice(0,p),{...u[p],core:c},...u.slice(p+1)]},O=(t,n)=>{w>0?I=I||n:(n?h(!1):c!==t&&x(),c.data!==t.data&&e.onChange?.(c.data),c!==t&&C())},D=e=>{const n=c;if(c=H(c,e,t),c===n)return;const o=e.recordHistory??B(e);O(n,o&&c.data!==n.data)},E=t=>{0===w&&(S=c,I=!1),w+=1;try{t()}catch(e){throw w-=1,0===w&&S&&(c=S,S=null),e}if(w-=1,w>0||!S)return;const n=S;S=null,I&&c.data!==n.data?h(!0):c!==n&&x(),c.data!==n.data&&e.onChange?.(c.data),c!==n&&C()},A=e=>{const n=c,o=L(c.data,t,e);var r,i;(r=o,i=c.selection,r===i||r&&i&&r.kind===i.kind&&("node"===r.kind&&"node"===i.kind?r.id===i.id:"slot"===r.kind&&"slot"===i.kind&&r.parentId===i.parentId&&r.slot===i.slot))||(c={...c,selection:o},O(n,!1))},z=t=>{const n=c;p=t,c=u[p].core,c.data!==n.data&&e.onChange?.(c.data),c!==n&&C()},M=(e={})=>{const n=e.root?t.root?.permissions:t.components[e.item?.type??e.type??""]?.permissions;return{...T,...a,...n}},Z=g(),$={resolveCache:Z,async resolveAll({trigger:e="load",metadata:n}={}){const o=c.data,r={type:"root",props:{...o.root.props??{}}},i=[...o.content,...Object.values(o.zones??{}).flat()],[a,...l]=await Promise.all([k(r,t,{cache:Z,trigger:e,metadata:n}),...i.map(o=>k(o,t,{cache:Z,trigger:e,metadata:n}))]);E(()=>{const e=c;let n=c.data;l.forEach((e,r)=>{if(!e.didChange)return;const a=i[r].props.id,l=s(n,t,a)?.node;l&&l===s(o,t,a)?.node&&(n=f(n,t,a,e.node))}),a.didChange&&n.root===o.root&&(n={...n,root:{...n.root,props:a.node.props,readOnly:a.node.readOnly??n.root.readOnly}}),n!==c.data&&(c={...c,data:n,selection:L(n,t,c.selection)},O(e,!1))})},get config(){return t},getState(){if(v&&b===c)return v;const e=c,o={data:e.data,ui:K(e,t)},r="node"===e.selection?.kind?s(e.data,t,e.selection.id)?.node??null:null;return v={appState:o,selection:e.selection,selectedItem:r,config:t,dispatch:D,history:{back:()=>$.undo(),forward:()=>$.redo(),hasPast:p>0,hasFuture:p<u.length-1,histories:u.map(e=>({id:e.id,state:{data:e.core.data,ui:K(e.core,t)}})),index:p,setHistoryIndex:e=>{e>=0&&e<u.length&&e!==p&&z(e)}},getPermissions:M,getItemById:n=>s(e.data,t,n)?.node,getItemBySelector:n=>function(e,t,n){const[o,r]=(n.zone??"root:default-zone").split(/:(.*)/s);return d(e,t,{parentId:o,slot:r})?.[n.index]}(e.data,t,n),getSelectorForId:o=>{const r=n(e.data,t,{kind:"node",id:o});return r?{index:r.index,zone:r.zone??"root:default-zone"}:void 0}},b=e,v},subscribe:e=>(m.add(e),()=>{m.delete(e)}),dispatch:D,batch:E,select:e=>A(e?{kind:"node",id:e}:null),selectSlot:e=>A(e?{kind:"slot",parentId:e.parentId,slot:e.slot}:null),run(e){E(()=>{const n=c,o=void 0===e.select?c.selection:e.select;c={...c,data:e.data,selection:L(e.data,t,o)},O(n,e.data!==n.data)})},load(e,n={}){const o=c,r=y(e,t);c={...c,data:r,selection:L(r,t,n.selection??c.selection)},n.keepHistory||(u=[{core:c,at:-1/0,sealed:!0,id:Y()}],p=0),c!==o&&C()},undo(){p>0&&z(p-1)},redo(){p<u.length-1&&z(p+1)},setPermissions(e){a=e,v=null,C()},setConfig(e){e!==t&&(t=e,v=null,C())}};return $}function W(e,t){const n=e=>{if(e.altKey)return;e.metaKey!==e.ctrlKey&&("KeyZ"===e.code?(e.preventDefault(),e.shiftKey?t.redo():t.undo()):"KeyY"!==e.code||e.shiftKey||(e.preventDefault(),t.redo()))};return e.addEventListener("keydown",n),()=>e.removeEventListener("keydown",n)}var X=C(null);function Q({editor:e,hotkeys:t=!0,resolveOnMount:n=!0,children:o}){return x(()=>{n&&e.resolveAll()},[e,n]),x(()=>{if(t&&"undefined"!=typeof document)return W(document,e)},[e,t]),/* @__PURE__ */$(X.Provider,{value:e,children:o})}function J(){const e=O(X);if(!e)throw new Error("useEditor: no <EditorProvider> above this component");return e}function _(e){const t=J(),n=D({view:null,selector:null,value:void 0,has:!1}),o=()=>{const o=t.getState(),r=n.current;if(r.has&&r.view===o&&r.selector===e)return r.value;const i=e(o);return r.has&&Object.is(r.value,i)?(n.current={view:o,selector:e,value:r.value,has:!0},r.value):(n.current={view:o,selector:e,value:i,has:!0},i)};return E(t.subscribe,o,o)}function ee(){return function(e){return _(e)}}var te="data-puck-component",ne="data-puck-dropzone",oe={},re="data-es-mirror";function ie(e,t,n){for(const e of Array.from(t.head.querySelectorAll(`[${re}]`)))e.remove();for(const o of Array.from(e.head.querySelectorAll('style, link[rel="stylesheet"]'))){const e=o.cloneNode(!0);e.setAttribute(re,""),n&&e.setAttribute("nonce",n),t.head.appendChild(e)}}function ae({children:t,id:n="preview-frame",title:o,className:r,style:s,mirrorStyles:l=!0,onDocument:d,height:c="auto",nonce:u}){const p=i("canvas",e),h=D(null),[f,m]=A(null);return z(()=>{const e=h.current,t=f?.ownerDocument.defaultView;if("auto"!==c||!e||!f||!t)return;const n=()=>{e.style.height=`${Math.ceil(f.getBoundingClientRect().height)}px`};n();const o=t.ResizeObserver,r=o?new o(n):null;return r?.observe(f),()=>r?.disconnect()},[f,c]),z(()=>{let e=h.current?.contentDocument;if(!e)return;"CSS1Compat"!==e.compatMode&&(e.open(),e.write("<!DOCTYPE html><html><head></head><body></body></html>"),e.close(),e=h.current?.contentDocument??e),e.body||e.documentElement.appendChild(e.createElement("body")),e.body.style.margin="0";const t=e.createElement("div");t.setAttribute("data-puck-entry",""),t.id="frame-root","fill"===c&&t.classList.add("es-frame-fill"),e.body.appendChild(t),a(e,u),m(t),d?.(e);let n=null;const o=h.current?.ownerDocument;if(l&&o){ie(o,e,u);const t=o.defaultView;t&&"MutationObserver"in t&&(n=new t.MutationObserver(()=>ie(o,e,u)),n.observe(o.head,{childList:!0,subtree:!0,characterData:!0}))}return()=>{n?.disconnect(),t.remove(),m(null),d?.(null)}},[]),/* @__PURE__ */$("iframe",{ref:h,id:n,title:o??p.frame,className:r,style:{border:0,width:"100%",display:"block",..."fill"===c?{height:"100%"}:null,...s},children:f?N(t,f):null})}var se=C(null),le=C(oe),de=[];function ce({parentId:e,slot:t,className:n,style:o,minEmptyHeight:r=128}){const i=J(),a=_(n=>d(n.appState.data,i.config,{parentId:e,slot:t})??de),s=_(t=>"node"===t.selection?.kind&&t.selection.id===e&&e!==l),c=_(n=>"slot"===n.selection?.kind&&n.selection.parentId===e&&n.selection.slot===t),u=O(se),p=["es-zone"];return a.length&&p.push("has-children"),e===l&&p.push("is-root"),(s||c)&&p.push("is-area-selected"),null!==u&&u===e&&e!==l&&p.push("is-hovering-area"),n&&p.push(n),/* @__PURE__ */$("div",{className:p.join(" "),[ne]:`${e}:${t}`,style:{...o,"--min-empty-height":`${r}px`},children:a.map(e=>/* @__PURE__ */$(he,{node:e},e.props.id))})}function ue(e,t,n,o){const r="root"===t?e.root:e.components[t],i={...o};for(const e of w(S(r)))i[e]=function(t={}){/* @__PURE__ */
2
2
  return $(ce,{parentId:n,slot:e,...t})};return i}function pe(e){return function({zone:t,...n}){/* @__PURE__ */
3
- return $(ce,{parentId:e,slot:t,...n})}}function he({node:e}){const t=X().config,n=t.components[e.type],o=e.props.id,r=function(e){const t=O(null);return M(()=>n=>{const o=t.current;o&&o!==n&&(o.removeAttribute(te),o.removeAttribute("data-puck-dnd")),t.current=n,n&&(n.setAttribute(te,e),n.setAttribute("data-puck-dnd",e),n.style.position="relative")},[e])}(o),i=E(le);if(!n?.render)return null;const a=n.render,s=ue(t,e.type,o,{...S(n),...e.props}),l={renderDropZone:pe(o),isEditing:!0,dragRef:n.inline?r:null,metadata:{...i,...n.metadata}};return n.inline?/* @__PURE__ */$(a,{...s,puck:l,editMode:!0}):/* @__PURE__ */$("div",{[te]:o,"data-puck-dnd":o,style:{position:"relative"},children:/* @__PURE__ */$(a,{...s,puck:l,editMode:!0})})}function fe({metadata:e}){const t=_(e=>e.config),n=_(e=>e.appState.data.root).props??{},o=t.root?.render,r=/* @__PURE__ */$(ce,{parentId:l,slot:b}),i=o?/* @__PURE__ */$(o,{id:"puck-root",...ue(t,"root",l,n),puck:{renderDropZone:pe(l),isEditing:!0,dragRef:null,metadata:e??{}},editMode:!0,children:r}):r;/* @__PURE__ */
4
- return $(le.Provider,{value:e??oe,children:i})}function me({id:e,kind:t,overlay:n}){const o=O(null),[r,i]=A(null);z(()=>{const t=o.current?.ownerDocument,n=t?.defaultView;if(!t||!n||!e)return void i(null);let r=0;const a=()=>{r=0;const a=function(e,t){if(!e||!t)return null;const n=e.getBoundingClientRect(),o=t.getBoundingClientRect();return{top:n.top-o.top,left:n.left-o.left,width:n.width,height:n.height}}(t.querySelector(`[${te}="${n.CSS?.escape?n.CSS.escape(e):e}"]`),o.current?.parentElement??null);i(e=>{return(t=e)===(n=a)||t&&n&&t.top===n.top&&t.left===n.left&&t.width===n.width&&t.height===n.height?e:a;var t,n})},s=()=>{r||(r=(n.requestAnimationFrame??(e=>n.setTimeout(e,16)))(a))};a();const l="MutationObserver"in n?new n.MutationObserver(s):null;l?.observe(t.body,{childList:!0,subtree:!0,attributes:!0,characterData:!0});const d="ResizeObserver"in n?new n.ResizeObserver(s):null;return d?.observe(t.documentElement),n.addEventListener("resize",s),()=>{l?.disconnect(),d?.disconnect(),n.removeEventListener("resize",s),r&&(n.cancelAnimationFrame??n.clearTimeout)(r)}},[e]);const a=/* @__PURE__ */$("div",{ref:o,"aria-hidden":"true",className:`es-canvas-outline is-${t}`,style:r?{position:"absolute",top:r.top,left:r.left,width:r.width,height:r.height}:{display:"none"}});return n&&e?/* @__PURE__ */$(n,{componentId:e,kind:t,children:a}):a}function ve({frame:e=!0,className:t,style:n,metadata:o,mirrorStyles:r,onDocument:i,height:a,title:s,nonce:l,frameWrapper:d,overlay:c,children:u}){const p=X(),[h,f]=A(void 0),m=_(e=>"node"===e.selection?.kind?e.selection.id:null),[v,y]=A(null),g=/* @__PURE__ */N("div",{className:"es-canvas-content",style:{position:"relative"},onClick:e=>{const t=e.target;t.closest?.("a[href]")&&e.preventDefault();const n=t.closest?.(`[${te}]`);n?p.select(n.getAttribute(te)):t.hasAttribute?.(ne)||p.select(null)},onMouseOver:e=>{const t=e.target.closest?.(`[${te}]`),n=t?.getAttribute(te)??null;n!==v&&y(n)},onMouseLeave:()=>y(null),children:[
3
+ return $(ce,{parentId:e,slot:t,...n})}}function he({node:e}){const t=J().config,n=t.components[e.type],o=e.props.id,r=function(e){const t=D(null);return M(()=>n=>{const o=t.current;o&&o!==n&&(o.removeAttribute(te),o.removeAttribute("data-puck-dnd")),t.current=n,n&&(n.setAttribute(te,e),n.setAttribute("data-puck-dnd",e),n.style.position="relative")},[e])}(o),i=O(le);if(!n?.render)return null;const a=n.render,s=ue(t,e.type,o,{...I(n),...e.props}),l={renderDropZone:pe(o),isEditing:!0,dragRef:n.inline?r:null,metadata:{...i,...n.metadata}};return n.inline?/* @__PURE__ */$(a,{...s,puck:l,editMode:!0}):/* @__PURE__ */$("div",{[te]:o,"data-puck-dnd":o,style:{position:"relative"},children:/* @__PURE__ */$(a,{...s,puck:l,editMode:!0})})}function fe({metadata:e}){const t=_(e=>e.config),n=_(e=>e.appState.data.root).props??{},o=t.root?.render,r=/* @__PURE__ */$(ce,{parentId:l,slot:b}),i=o?/* @__PURE__ */$(o,{id:"puck-root",...ue(t,"root",l,n),puck:{renderDropZone:pe(l),isEditing:!0,dragRef:null,metadata:e??{}},editMode:!0,children:r}):r;/* @__PURE__ */
4
+ return $(le.Provider,{value:e??oe,children:i})}function me({id:e,kind:t,overlay:n}){const o=D(null),[r,i]=A(null);z(()=>{const t=o.current?.ownerDocument,n=t?.defaultView;if(!t||!n||!e)return void i(null);let r=0;const a=()=>{r=0;const a=function(e,t){if(!e||!t)return null;const n=e.getBoundingClientRect(),o=t.getBoundingClientRect();return{top:n.top-o.top,left:n.left-o.left,width:n.width,height:n.height}}(t.querySelector(`[${te}="${n.CSS?.escape?n.CSS.escape(e):e}"]`),o.current?.parentElement??null);i(e=>{return(t=e)===(n=a)||t&&n&&t.top===n.top&&t.left===n.left&&t.width===n.width&&t.height===n.height?e:a;var t,n})},s=()=>{r||(r=(n.requestAnimationFrame??(e=>n.setTimeout(e,16)))(a))};a();const l="MutationObserver"in n?new n.MutationObserver(s):null;l?.observe(t.body,{childList:!0,subtree:!0,attributes:!0,characterData:!0});const d="ResizeObserver"in n?new n.ResizeObserver(s):null;return d?.observe(t.documentElement),n.addEventListener("resize",s),()=>{l?.disconnect(),d?.disconnect(),n.removeEventListener("resize",s),r&&(n.cancelAnimationFrame??n.clearTimeout)(r)}},[e]);const a=/* @__PURE__ */$("div",{ref:o,"aria-hidden":"true",className:`es-canvas-outline is-${t}`,style:r?{position:"absolute",top:r.top,left:r.left,width:r.width,height:r.height}:{display:"none"}});return n&&e?/* @__PURE__ */$(n,{componentId:e,kind:t,children:a}):a}function ve({frame:e=!0,className:t,style:n,metadata:o,mirrorStyles:r,onDocument:i,height:a,title:s,nonce:l,frameWrapper:d,overlay:c,children:u}){const p=J(),[h,f]=A(void 0),m=_(e=>"node"===e.selection?.kind?e.selection.id:null),[v,y]=A(null),g=/* @__PURE__ */R("div",{className:"es-canvas-content",style:{position:"relative"},onClick:e=>{const t=e.target;t.closest?.("a[href]")&&e.preventDefault();const n=t.closest?.(`[${te}]`);n?p.select(n.getAttribute(te)):t.hasAttribute?.(ne)||p.select(null)},onMouseOver:e=>{const t=e.target.closest?.(`[${te}]`),n=t?.getAttribute(te)??null;n!==v&&y(n)},onMouseLeave:()=>y(null),children:[
5
5
  /* @__PURE__ */$(se.Provider,{value:v,children:/* @__PURE__ */$(fe,{metadata:o})}),
6
- /* @__PURE__ */N("div",{className:"es-canvas-outlines",style:{position:"absolute",top:0,left:0,pointerEvents:"none"},children:[
6
+ /* @__PURE__ */R("div",{className:"es-canvas-outlines",style:{position:"absolute",top:0,left:0,pointerEvents:"none"},children:[
7
7
  /* @__PURE__ */$(me,{id:v&&v!==m?v:null,kind:"hover",overlay:c}),
8
- /* @__PURE__ */$(me,{id:m,kind:"selected",overlay:c})]}),u]}),k=d?/* @__PURE__ */$(d,{document:h,children:g}):g,b=O(null);/* @__PURE__ */
9
- return $("div",{className:"es-canvas"+(t?` ${t}`:""),style:n,"data-puck-preview":"",children:e?/* @__PURE__ */$(ae,{mirrorStyles:r,onDocument:e=>{b.current?.(),b.current=e?Y(e,p):null,f(e??void 0),i?.(e)},height:a,title:s,nonce:l,children:k}):/* @__PURE__ */$("div",{id:"preview-frame","data-puck-entry":"",children:k})})}function ye(e={}){const t=X(),n=_(e=>e.appState.data);return r({...e,data:n,config:t.config,commit:(e,{select:n})=>t.run({data:e,select:n})})}function ge(){const e=X(),n=_(e=>e.config),o=e.resolveCache,r=_(e=>e.selectedItem),i=_(e=>e.appState.data.root),a=r?r.props.id:"root",l=i.props??{},d=M(()=>r||{type:"root",props:l},[r,l]),c=r?n.components[r.type]:n.root,u=e.getState(),p=r?s(u.appState.data,n,a):null,h=p&&"root"!==p.place.parentId?p.place.parentId:null,f=h?u.getItemById(h)??null:null,{fields:m}=t({id:a,node:d,block:c,parent:f,appState:u.appState}),v=u.getPermissions(r?{item:r}:{root:!0}),y=Z((t,r)=>{(async()=>{const i=e.getState();if("root"!==a){const s=i.getItemById(a),l=i.getSelectorForId(a);if(!s||!l)return;const d={...s,props:{...s.props,[t]:r}},{node:c}=await k(d,n,{cache:o,trigger:"replace"}),u=e.getState().getSelectorForId(a);if(!u)return;return void e.dispatch({type:"replace",destinationZone:u.zone??"root:default-zone",destinationIndex:u.index,data:c})}const s=i.appState.data.root.props??{},{node:l}=await k({type:"root",props:{...s,[t]:r}},n,{cache:o,trigger:"replace"});e.dispatch({type:"replaceRoot",root:{props:l.props,readOnly:l.readOnly},recordHistory:!0})})()},[e,n,o,a]);return{id:a,node:d,fields:m,values:d.props,readOnly:!1===v.edit,onChange:y}}export{ae as CanvasFrame,q as DEFAULT_UI,fe as EditDocument,ve as EditorCanvas,W as EditorProvider,Y as bindUndoKeys,U as createEditor,ee as createUseEditor,P as recordsByDefault,T as reduce,F as uiView,_ as useEditor,X as useEditorApi,ye as useEditorNodeOps,ge as useSelectedFields,K as validSelection};
8
+ /* @__PURE__ */$(me,{id:m,kind:"selected",overlay:c})]}),u]}),k=d?/* @__PURE__ */$(d,{document:h,children:g}):g,b=D(null);/* @__PURE__ */
9
+ return $("div",{className:"es-canvas"+(t?` ${t}`:""),style:n,"data-puck-preview":"",children:e?/* @__PURE__ */$(ae,{mirrorStyles:r,onDocument:e=>{b.current?.(),b.current=e?W(e,p):null,f(e??void 0),i?.(e)},height:a,title:s,nonce:l,children:k}):/* @__PURE__ */$("div",{id:"preview-frame","data-puck-entry":"",children:k})})}function ye(e={}){const t=J(),n=_(e=>e.appState.data);return r({...e,data:n,config:t.config,commit:(e,{select:n})=>t.run({data:e,select:n})})}function ge(){const e=J(),n=_(e=>e.config),o=e.resolveCache,r=_(e=>e.selectedItem),i=_(e=>e.appState.data.root),a=r?r.props.id:"root",l=i.props??{},d=M(()=>r||{type:"root",props:l},[r,l]),c=r?n.components[r.type]:n.root,u=e.getState(),p=r?s(u.appState.data,n,a):null,h=p&&"root"!==p.place.parentId?p.place.parentId:null,f=h?u.getItemById(h)??null:null,{fields:m}=t({id:a,node:d,block:c,parent:f,appState:u.appState}),v=u.getPermissions(r?{item:r}:{root:!0}),y=Z((t,r)=>{(async()=>{const i=e.getState();if("root"!==a){const s=i.getItemById(a),l=i.getSelectorForId(a);if(!s||!l)return;const d={...s,props:{...s.props,[t]:r}},{node:c}=await k(d,n,{cache:o,trigger:"replace"}),u=e.getState().getSelectorForId(a);if(!u)return;return void e.dispatch({type:"replace",destinationZone:u.zone??"root:default-zone",destinationIndex:u.index,data:c})}const s=i.appState.data.root.props??{},{node:l}=await k({type:"root",props:{...s,[t]:r}},n,{cache:o,trigger:"replace"});e.dispatch({type:"replaceRoot",root:{props:l.props,readOnly:l.readOnly},recordHistory:!0})})()},[e,n,o,a]);return{id:a,node:d,fields:m,values:d.props,readOnly:!1===v.edit,onChange:y}}export{ae as CanvasFrame,q as DEFAULT_UI,fe as EditDocument,ve as EditorCanvas,Q as EditorProvider,W as bindUndoKeys,U as createEditor,ee as createUseEditor,B as recordsByDefault,H as reduce,K as uiView,_ as useEditor,J as useEditorApi,ye as useEditorNodeOps,ge as useSelectedFields,L as validSelection};
@@ -3,9 +3,9 @@ import { ReactNode } from 'react';
3
3
  import { S as SettingsBucket } from '../buckets-1vRlQceY.js';
4
4
  import { I as InspectorFields, a as InspectorFieldDef, F as FieldRenderer, b as FieldTextProps, c as FieldNumberProps, d as FieldSelectProps, e as FieldOption } from '../types-CEqUFH2j.js';
5
5
  export { A as ArrayFieldDef, C as CustomFieldDef, f as CustomFieldRenderProps, N as NumberFieldDef, O as ObjectFieldDef, R as RadioFieldDef, S as SelectFieldDef, g as SlotFieldDef, T as TextFieldDef, h as TextareaFieldDef } from '../types-CEqUFH2j.js';
6
- import { R as ResolvableItem } from '../resolve-DpH8YQOA.js';
6
+ import { R as ResolvableItem } from '../resolve-D68pb3Bx.js';
7
7
  export { F as FieldsWords } from '../words-CD3WADyb.js';
8
- import '../types-DziKCwsN.js';
8
+ import '../types-41704JE4.js';
9
9
 
10
10
  interface InspectorProps {
11
11
  /** The selected node's fields, already resolved by the host. */
@@ -1,46 +1,46 @@
1
- import{LayersTree as e,TreeSeam as n,TreeRow as t,TreeRowAction as l}from"../chunk-STFMZJKU.js";import{SettingsField as a,SETTINGS_BUCKETS as r,SettingsTabs as i,SettingsGroup as s}from"../chunk-67VZRQLG.js";import{DEFAULT_FIELDS_WORDS as o}from"../chunk-SUO5627P.js";import{DEFAULT_TREE_WORDS as c}from"../chunk-H4B72XCJ.js";import{DEFAULT_PANEL_WORDS as d}from"../chunk-7A7O2JWQ.js";export{useResolvedFields}from"../chunk-FJE4IDBQ.js";import{SettingsSegmented as u}from"../chunk-QB3BZIRA.js";import{useWords as m}from"../chunk-MFIRYGHW.js";import"../chunk-BZ5ASXOL.js";import{useTreeDrag as h,gapToMoveIndex as p}from"../chunk-6JDII7N3.js";import"../chunk-YNZZYHA4.js";import"../chunk-LPRQDDQO.js";import"../chunk-NKB3KVAB.js";import{useState as b,useEffect as f,useId as v,useRef as y}from"react";import{jsxs as g,jsx as k,Fragment as x}from"react/jsx-runtime";function N(e,n,t){let l=e;return"number"==typeof n&&l<n&&(l=n),"number"==typeof t&&l>t&&(l=t),l}function w(e){const n=e.trim().replace(",",".");if(""===n||"-"===n||"."===n||"-."===n)return null;const t=Number(n);return Number.isFinite(t)?t:null}function O(e){const n=String(e),t=n.indexOf(".");return t<0?0:n.length-t-1}function C({id:e,value:n,onChange:t,min:l,max:a,step:r=1,unit:i,steppers:s=!1,placeholder:c,readOnly:d=!1,ariaLabel:u,ariaLabelledBy:h}){const p=m("fields",o),v="number"==typeof n&&Number.isFinite(n)?String(n):"",[y,x]=b(v);f(()=>{x(e=>w(e)===("number"==typeof n?n:null)?e:v)},[n,v]);const C=e=>{d||t(e)},I=e=>{const t=N(function(e,n){const t=Math.max(O(e),O(n));return Number((e+n).toFixed(t))}("number"==typeof n&&Number.isFinite(n)?n:l??0,e*r),l,a);x(String(t)),C(t)};/* @__PURE__ */
1
+ import{LayersTree as e,TreeSeam as n,TreeRow as t,TreeRowAction as l}from"../chunk-STFMZJKU.js";import{SettingsField as a,SETTINGS_BUCKETS as r,SettingsTabs as i,SettingsGroup as s}from"../chunk-67VZRQLG.js";import{DEFAULT_FIELDS_WORDS as o}from"../chunk-SUO5627P.js";import{DEFAULT_TREE_WORDS as c}from"../chunk-H4B72XCJ.js";import{DEFAULT_PANEL_WORDS as d}from"../chunk-7A7O2JWQ.js";export{useResolvedFields}from"../chunk-YRLPFZW3.js";import{SettingsSegmented as u}from"../chunk-QB3BZIRA.js";import{useWords as m}from"../chunk-MFIRYGHW.js";import"../chunk-BZ5ASXOL.js";import{useTreeDrag as h,gapToMoveIndex as p}from"../chunk-6PS6STGA.js";import"../chunk-YNZZYHA4.js";import"../chunk-KRXQM65X.js";import"../chunk-NKB3KVAB.js";import{useState as b,useEffect as f,useId as v,useRef as y}from"react";import{jsxs as g,jsx as k,Fragment as x}from"react/jsx-runtime";function N(e,n,t){let l=e;return"number"==typeof n&&l<n&&(l=n),"number"==typeof t&&l>t&&(l=t),l}function w(e){const n=e.trim().replace(",",".");if(""===n||"-"===n||"."===n||"-."===n)return null;const t=Number(n);return Number.isFinite(t)?t:null}function C(e){const n=String(e),t=n.indexOf(".");return t<0?0:n.length-t-1}function O({id:e,value:n,onChange:t,min:l,max:a,step:r=1,unit:i,steppers:s=!1,placeholder:c,readOnly:d=!1,ariaLabel:u,ariaLabelledBy:h}){const p=m("fields",o),v="number"==typeof n&&Number.isFinite(n)?String(n):"",[y,x]=b(v);f(()=>{x(e=>w(e)===("number"==typeof n?n:null)?e:v)},[n,v]);const O=e=>{d||t(e)},$=e=>{const t=N(function(e,n){const t=Math.max(C(e),C(n));return Number((e+n).toFixed(t))}("number"==typeof n&&Number.isFinite(n)?n:l??0,e*r),l,a);x(String(t)),O(t)};/* @__PURE__ */
2
2
  return g("div",{className:"es-fnum",children:[
3
- /* @__PURE__ */k("input",{id:e,type:"text",inputMode:"decimal",className:"es-fin es-fnum-box",value:y,placeholder:c,readOnly:d,"aria-label":u,"aria-labelledby":h,onChange:e=>{const n=e.target.value;if(x(n),""===n.trim())C(void 0);else{const e=w(n);null!==e&&C(e)}},onBlur:()=>{const e=w(y);if(null===e)return void x(v);const t=N(e,l,a);x(String(t)),t!==n&&C(t)},onKeyDown:e=>{"ArrowUp"!==e.key&&"ArrowDown"!==e.key||(e.preventDefault(),I("ArrowUp"===e.key?1:-1))}}),i?/* @__PURE__ */k("span",{className:"es-fnum-unit",children:i}):null,s?/* @__PURE__ */g("span",{className:"es-fnum-steps",children:[
4
- /* @__PURE__ */k("button",{type:"button",className:"es-fbtn","aria-label":p.less,disabled:d,onClick:()=>I(-1),children:"−"}),
5
- /* @__PURE__ */k("button",{type:"button",className:"es-fbtn","aria-label":p.more,disabled:d,onClick:()=>I(1),children:"+"})]}):null]})}function I(e,n){return e.find(e=>Object.is(e.value,n))}function $({id:e,value:n,options:t,onChange:l,placeholder:a,readOnly:r=!1,ariaLabel:i,ariaLabelledBy:s}){const c=m("fields",o),d=v(),[u,h]=b(!1),[p,x]=b(0),N=y(null),w=y(null),O=y(null),C=I(t,n),$=C?t.indexOf(C):-1,j=()=>{r||0===t.length||(x($>=0?$:0),h(!0))},D=e=>{h(!1),e&&w.current?.focus()},L=e=>{const a=t[e];a&&!a.disabled&&(Object.is(a.value,n)||l(a.value),D(!0))};f(()=>{if(!u)return;O.current?.focus();const e=N.current?.ownerDocument;if(!e)return;const n=e=>{N.current&&!N.current.contains(e.target)&&h(!1)};return e.addEventListener("click",n,!0),()=>e.removeEventListener("click",n,!0)},[u]);const S=e=>{const n=t.length;if(0===n)return;let l=(e%n+n)%n;for(let a=0;a<n&&t[l]?.disabled;a++)l=(l+(e>=p?1:-1)+n)%n;x(l)};/* @__PURE__ */
3
+ /* @__PURE__ */k("input",{id:e,type:"text",inputMode:"decimal",className:"es-fin es-fnum-box",value:y,placeholder:c,readOnly:d,"aria-label":u,"aria-labelledby":h,onChange:e=>{const n=e.target.value;if(x(n),""===n.trim())O(void 0);else{const e=w(n);null!==e&&O(e)}},onBlur:()=>{const e=w(y);if(null===e)return void x(v);const t=N(e,l,a);x(String(t)),t!==n&&O(t)},onKeyDown:e=>{"ArrowUp"!==e.key&&"ArrowDown"!==e.key||(e.preventDefault(),$("ArrowUp"===e.key?1:-1))}}),i?/* @__PURE__ */k("span",{className:"es-fnum-unit",children:i}):null,s?/* @__PURE__ */g("span",{className:"es-fnum-steps",children:[
4
+ /* @__PURE__ */k("button",{type:"button",className:"es-fbtn","aria-label":p.less,disabled:d,onClick:()=>$(-1),children:"−"}),
5
+ /* @__PURE__ */k("button",{type:"button",className:"es-fbtn","aria-label":p.more,disabled:d,onClick:()=>$(1),children:"+"})]}):null]})}function $(e,n){return e.find(e=>Object.is(e.value,n))}function j({id:e,value:n,options:t,onChange:l,placeholder:a,readOnly:r=!1,ariaLabel:i,ariaLabelledBy:s}){const c=m("fields",o),d=v(),[u,h]=b(!1),[p,x]=b(0),N=y(null),w=y(null),C=y(null),O=$(t,n),j=O?t.indexOf(O):-1,I=()=>{r||0===t.length||(x(j>=0?j:0),h(!0))},S=e=>{h(!1),e&&w.current?.focus()},L=e=>{const a=t[e];a&&!a.disabled&&(Object.is(a.value,n)||l(a.value),S(!0))};f(()=>{if(!u)return;C.current?.focus();const e=N.current?.ownerDocument;if(!e)return;const n=e=>{N.current&&!N.current.contains(e.target)&&h(!1)};return e.addEventListener("click",n,!0),()=>e.removeEventListener("click",n,!0)},[u]);const D=e=>{const n=t.length;if(0===n)return;let l=(e%n+n)%n;for(let a=0;a<n&&t[l]?.disabled;a++)l=(l+(e>=p?1:-1)+n)%n;x(l)};/* @__PURE__ */
6
6
  return g("div",{className:"es-fsel",ref:N,children:[
7
- /* @__PURE__ */g("button",{ref:w,id:e,type:"button",className:"es-fin es-fsel-button","aria-haspopup":"listbox","aria-expanded":u,"aria-controls":u?d:void 0,"aria-label":i,"aria-labelledby":s,disabled:r,onClick:()=>u?D(!1):j(),onKeyDown:e=>{"ArrowDown"!==e.key&&"ArrowUp"!==e.key||(e.preventDefault(),j())},children:[
8
- /* @__PURE__ */k("span",{className:C?"es-fsel-value":"es-fsel-value is-empty",children:C?C.label:a??c.choose}),
9
- /* @__PURE__ */k("span",{className:"es-fsel-chev","aria-hidden":"true"})]}),u?/* @__PURE__ */k("ul",{ref:O,id:d,role:"listbox",tabIndex:-1,className:"es-fsel-list","aria-activedescendant":`${d}-${p}`,"aria-labelledby":s,"aria-label":s?void 0:i,onKeyDown:e=>{switch(e.key){case"ArrowDown":return e.preventDefault(),void S(p+1);case"ArrowUp":return e.preventDefault(),void S(p-1);case"Home":return e.preventDefault(),void S(0);case"End":return e.preventDefault(),void S(t.length-1);case"Enter":case" ":return e.preventDefault(),void L(p);case"Escape":return e.preventDefault(),e.stopPropagation(),void D(!0);case"Tab":return void D(!1);default:if(1===e.key.length&&/\S/.test(e.key)){const n=e.key.toLowerCase(),l=t.length;for(let e=1;e<=l;e++){const a=(p+e)%l;if(!t[a]?.disabled&&t[a]?.label.toLowerCase().startsWith(n))return void x(a)}}}},children:t.map((e,n)=>/* @__PURE__ */k("li",{id:`${d}-${n}`,role:"option","aria-selected":n===$,"aria-disabled":e.disabled||void 0,className:`es-fsel-option${n===p?" is-active":""}${n===$?" is-chosen":""}`,onMouseEnter:()=>x(n),onClick:()=>L(n),children:e.label},`${n}-${String(e.value)}`))}):null]})}function j({id:e,value:n,onChange:t,placeholder:l,multiline:a=!1,rows:r=3,readOnly:i=!1,ariaLabel:s,ariaLabelledBy:o}){const c=n??"";return a?/* @__PURE__ */k("textarea",{id:e,className:"es-fin es-fin--area",value:c,rows:r,placeholder:l,readOnly:i,"aria-label":s,"aria-labelledby":o,onChange:e=>t(e.target.value)}):/* @__PURE__ */k("input",{id:e,type:"text",className:"es-fin",value:c,placeholder:l,readOnly:i,"aria-label":s,"aria-labelledby":o,onChange:e=>t(e.target.value)})}function D(e,n,t){const l=e.slice();return l.splice(Math.max(0,Math.min(n,l.length)),0,t),l}function L(e,n,t){const l=e.slice(),[a]=l.splice(n,1);return l.splice(Math.max(0,Math.min(t,l.length)),0,a),l}function S(e,n){return e.filter((e,t)=>t!==n)}function M(e){return null===e||"object"!=typeof e?e:JSON.parse(JSON.stringify(e))}function A(){/* @__PURE__ */
7
+ /* @__PURE__ */g("button",{ref:w,id:e,type:"button",className:"es-fin es-fsel-button","aria-haspopup":"listbox","aria-expanded":u,"aria-controls":u?d:void 0,"aria-label":i,"aria-labelledby":s,disabled:r,onClick:()=>u?S(!1):I(),onKeyDown:e=>{"ArrowDown"!==e.key&&"ArrowUp"!==e.key||(e.preventDefault(),I())},children:[
8
+ /* @__PURE__ */k("span",{className:O?"es-fsel-value":"es-fsel-value is-empty",children:O?O.label:a??c.choose}),
9
+ /* @__PURE__ */k("span",{className:"es-fsel-chev","aria-hidden":"true"})]}),u?/* @__PURE__ */k("ul",{ref:C,id:d,role:"listbox",tabIndex:-1,className:"es-fsel-list","aria-activedescendant":`${d}-${p}`,"aria-labelledby":s,"aria-label":s?void 0:i,onKeyDown:e=>{switch(e.key){case"ArrowDown":return e.preventDefault(),void D(p+1);case"ArrowUp":return e.preventDefault(),void D(p-1);case"Home":return e.preventDefault(),void D(0);case"End":return e.preventDefault(),void D(t.length-1);case"Enter":case" ":return e.preventDefault(),void L(p);case"Escape":return e.preventDefault(),e.stopPropagation(),void S(!0);case"Tab":return void S(!1);default:if(1===e.key.length&&/\S/.test(e.key)){const n=e.key.toLowerCase(),l=t.length;for(let e=1;e<=l;e++){const a=(p+e)%l;if(!t[a]?.disabled&&t[a]?.label.toLowerCase().startsWith(n))return void x(a)}}}},children:t.map((e,n)=>/* @__PURE__ */k("li",{id:`${d}-${n}`,role:"option","aria-selected":n===j,"aria-disabled":e.disabled||void 0,className:`es-fsel-option${n===p?" is-active":""}${n===j?" is-chosen":""}`,onMouseEnter:()=>x(n),onClick:()=>L(n),children:e.label},`${n}-${String(e.value)}`))}):null]})}function I({id:e,value:n,onChange:t,placeholder:l,multiline:a=!1,rows:r=3,readOnly:i=!1,ariaLabel:s,ariaLabelledBy:o}){const c=n??"";return a?/* @__PURE__ */k("textarea",{id:e,className:"es-fin es-fin--area",value:c,rows:r,placeholder:l,readOnly:i,"aria-label":s,"aria-labelledby":o,onChange:e=>t(e.target.value)}):/* @__PURE__ */k("input",{id:e,type:"text",className:"es-fin",value:c,placeholder:l,readOnly:i,"aria-label":s,"aria-labelledby":o,onChange:e=>t(e.target.value)})}function S(e,n,t){const l=e.slice();return l.splice(Math.max(0,Math.min(n,l.length)),0,t),l}function L(e,n,t){const l=e.slice(),[a]=l.splice(n,1);return l.splice(Math.max(0,Math.min(t,l.length)),0,a),l}function D(e,n){return e.filter((e,t)=>t!==n)}function M(e){return null===e||"object"!=typeof e?e:JSON.parse(JSON.stringify(e))}function A(){/* @__PURE__ */
10
10
  return g("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[
11
11
  /* @__PURE__ */k("circle",{cx:"9",cy:"6",r:"1.6"}),
12
12
  /* @__PURE__ */k("circle",{cx:"15",cy:"6",r:"1.6"}),
13
13
  /* @__PURE__ */k("circle",{cx:"9",cy:"12",r:"1.6"}),
14
14
  /* @__PURE__ */k("circle",{cx:"15",cy:"12",r:"1.6"}),
15
15
  /* @__PURE__ */k("circle",{cx:"9",cy:"18",r:"1.6"}),
16
- /* @__PURE__ */k("circle",{cx:"15",cy:"18",r:"1.6"})]})}var B={parentId:"list",slot:"items"};function F({label:a,icon:r,noun:i,items:s,onChange:d,newItem:u,summary:b,itemName:f,thumb:v,min:y=0,max:N,readOnly:w=!1,open:O,onOpen:C,renderItem:I}){const $=m("fields",o).list,j=m("tree",c),F=i??$.item,P=!w&&("number"!=typeof N||s.length<N),E=!w&&s.length>y,J=(e,n)=>f?f(e,n):$.itemName({noun:F,n:n+1}),K=h({keyOf:e=>String(e),canDrop:(e,n)=>n.parentId===B.parentId&&n.slot===B.slot,onDrop:(e,n)=>{const t=p({...B,index:e},n);t!==e&&d(L(s,e,t))},onStep:(e,n)=>d(L(s,e,e+n)),canStep:(e,n)=>e+n>=0&&e+n<s.length,readOnly:w}),Q=e=>{P&&d(D(s,e,u()))},U=e=>{P&&d(D(s,e+1,M(s[e])))},Z=e=>{E&&(d(S(s,e)),null!==O&&C(null))};if(null!==O&&O>=0&&O<s.length){const e=s[O];/* @__PURE__ */
16
+ /* @__PURE__ */k("circle",{cx:"15",cy:"18",r:"1.6"})]})}var B={parentId:"list",slot:"items"};function F({label:a,icon:r,noun:i,items:s,onChange:d,newItem:u,summary:b,itemName:f,thumb:v,min:y=0,max:N,readOnly:w=!1,open:C,onOpen:O,renderItem:$}){const j=m("fields",o).list,I=m("tree",c),F=i??j.item,P=!w&&("number"!=typeof N||s.length<N),K=!w&&s.length>y,Z=(e,n)=>f?f(e,n):j.itemName({noun:F,n:n+1}),E=h({keyOf:e=>String(e),canDrop:(e,n)=>n.parentId===B.parentId&&n.slot===B.slot,onDrop:(e,n)=>{const t=p({...B,index:e},n);t!==e&&d(L(s,e,t))},onStep:(e,n)=>d(L(s,e,e+n)),canStep:(e,n)=>e+n>=0&&e+n<s.length,readOnly:w}),R=e=>{P&&d(S(s,e,u()))},U=e=>{P&&d(S(s,e+1,M(s[e])))},W=e=>{K&&(d(D(s,e)),null!==C&&O(null))};if(null!==C&&C>=0&&C<s.length){const e=s[C];/* @__PURE__ */
17
17
  return g("div",{className:"es-list is-open",children:[
18
- /* @__PURE__ */g("button",{type:"button",className:"es-list-back",onClick:()=>C(null),children:[
18
+ /* @__PURE__ */g("button",{type:"button",className:"es-list-back",onClick:()=>O(null),children:[
19
19
  /* @__PURE__ */k("span",{className:"es-list-back-chev","aria-hidden":"true"}),a]}),
20
20
  /* @__PURE__ */g("div",{className:"es-list-title",children:[
21
- /* @__PURE__ */k("span",{className:"es-list-name",children:J(e,O)}),
22
- /* @__PURE__ */k("span",{className:"es-list-count",children:$.position({n:O+1,total:s.length})})]}),
23
- /* @__PURE__ */k("div",{className:"es-list-item",children:I(e,O,e=>{const n=s.slice();n[O]=e,d(n)})}),w?null:/* @__PURE__ */g("div",{className:"es-list-item-actions",children:[
24
- /* @__PURE__ */k("button",{type:"button",className:"es-fbtn",disabled:!P,onClick:()=>U(O),children:$.duplicate}),
25
- /* @__PURE__ */k("button",{type:"button",className:"es-fbtn es-fbtn--danger",disabled:!E,onClick:()=>Z(O),children:$.deleteItem({noun:F})})]})]})}/* @__PURE__ */
21
+ /* @__PURE__ */k("span",{className:"es-list-name",children:Z(e,C)}),
22
+ /* @__PURE__ */k("span",{className:"es-list-count",children:j.position({n:C+1,total:s.length})})]}),
23
+ /* @__PURE__ */k("div",{className:"es-list-item",children:$(e,C,e=>{const n=s.slice();n[C]=e,d(n)})}),w?null:/* @__PURE__ */g("div",{className:"es-list-item-actions",children:[
24
+ /* @__PURE__ */k("button",{type:"button",className:"es-fbtn",disabled:!P,onClick:()=>U(C),children:j.duplicate}),
25
+ /* @__PURE__ */k("button",{type:"button",className:"es-fbtn es-fbtn--danger",disabled:!K,onClick:()=>W(C),children:j.deleteItem({noun:F})})]})]})}/* @__PURE__ */
26
26
  return g("div",{className:"es-list",children:[
27
27
  /* @__PURE__ */g("div",{className:"es-list-head",children:[
28
28
  /* @__PURE__ */g("span",{className:"es-list-label",children:[r?/* @__PURE__ */k("span",{className:"es-field-icon","aria-hidden":"true",children:r}):null,a]}),
29
- /* @__PURE__ */k("span",{className:"es-list-count",children:s.length})]}),s.length?/* @__PURE__ */g(e,{className:"es-list-tree",rootProps:K.rootProps(),children:[s.map((e,a)=>{const r={...B,index:a},i=K.row({item:a,place:r});/* @__PURE__ */
30
- return g("div",{className:"es-list-entry",children:[a>0?/* @__PURE__ */k(n,{...K.seam({place:r}),onAdd:P?()=>Q(a):void 0,label:$.addHere({noun:F})}):null,
31
- /* @__PURE__ */k(t,{icon:v?v(e,a):/* @__PURE__ */k(A,{}),name:J(e,a),preview:b?b(e,a):void 0,draggable:i.draggable,dragging:i.dragging,drop:i.drop,rowProps:i.rowProps,words:j,onSelect:()=>C(a),actions:w?void 0:/* @__PURE__ */g(x,{children:[
32
- /* @__PURE__ */k(l,{kind:"plain",label:$.duplicateItem({noun:F}),disabled:!P,onClick:()=>U(a),children:/* @__PURE__ */g("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[
29
+ /* @__PURE__ */k("span",{className:"es-list-count",children:s.length})]}),s.length?/* @__PURE__ */g(e,{className:"es-list-tree",rootProps:E.rootProps(),children:[s.map((e,a)=>{const r={...B,index:a},i=E.row({item:a,place:r});/* @__PURE__ */
30
+ return g("div",{className:"es-list-entry",children:[a>0?/* @__PURE__ */k(n,{...E.seam({place:r}),onAdd:P?()=>R(a):void 0,label:j.addHere({noun:F})}):null,
31
+ /* @__PURE__ */k(t,{icon:v?v(e,a):/* @__PURE__ */k(A,{}),name:Z(e,a),preview:b?b(e,a):void 0,draggable:i.draggable,dragging:i.dragging,drop:i.drop,rowProps:i.rowProps,words:I,onSelect:()=>O(a),actions:w?void 0:/* @__PURE__ */g(x,{children:[
32
+ /* @__PURE__ */k(l,{kind:"plain",label:j.duplicateItem({noun:F}),disabled:!P,onClick:()=>U(a),children:/* @__PURE__ */g("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[
33
33
  /* @__PURE__ */k("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2"}),
34
34
  /* @__PURE__ */k("path",{d:"M5 15V6a2 2 0 0 1 2-2h9"})]})}),
35
- /* @__PURE__ */k(l,{kind:"delete",label:$.deleteItem({noun:F}),disabled:!E,onClick:()=>Z(a),children:/* @__PURE__ */k("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:/* @__PURE__ */k("path",{d:"M4 7h16M10 11v6M14 11v6M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 7V4h6v3"})})})]})})]},a)}),
36
- /* @__PURE__ */k(n,{...K.seam({place:{...B,index:s.length}})})]}):null,w?null:/* @__PURE__ */k("button",{type:"button",className:"es-list-add",disabled:!P,onClick:()=>Q(s.length),children:$.add({noun:F})})]})}var P=(e,n)=>"string"==typeof e.label&&e.label?e.label:n;function E({field:e,name:n,id:t,value:l,onChange:a,readOnly:r,context:i,renderers:o}){const[c,d]=b(!0),u=l&&"object"==typeof l?l:{};/* @__PURE__ */
37
- return k(s,{id:`${t}-group`,title:P(e,n),open:c,onToggle:d,children:Object.entries(e.objectFields).map(([e,l])=>/* @__PURE__ */k(K,{field:l,name:`${n}.${e}`,id:`${t}-${e}`,value:u[e],onChange:n=>a({...u,[e]:n}),readOnly:r,context:i,renderers:o},e))})}function J({field:e,name:n,id:t,value:l,onChange:a,readOnly:r,context:i,renderers:s,openItem:o,onOpenItem:c}){const[d,u]=b(null),m=c?o??null:d,h=c??u,p=Array.isArray(l)?l:[],f=e.getItemSummary;/* @__PURE__ */
38
- return k(F,{label:P(e,n),icon:e.icon,noun:"string"==typeof e.noun?e.noun:void 0,items:p,onChange:a,newItem:()=>M({...e.defaultItemProps??{}}),summary:f?(e,n)=>f(e,n):void 0,min:e.min,max:e.max,readOnly:r,open:m,onOpen:h,renderItem:(l,a,o)=>Object.entries(e.arrayFields).map(([e,c])=>/* @__PURE__ */k(K,{field:c,name:`${n}[${a}].${e}`,id:`${t}-${a}-${e}`,value:l?.[e],onChange:n=>o({...l,[e]:n}),readOnly:r,context:i,renderers:s},e))})}function K(e){const{field:n,name:t,id:l,value:r,onChange:i,readOnly:s,context:o,renderers:c}=e;if(!n||n.marker||!1===n.visible)return null;const d=c?.[n.type];if(d)return d({field:n,name:t,id:l,value:r,onChange:i,readOnly:s});switch(n.type){case"custom":{const e={...o,field:n,name:t,id:l,value:r,onChange:i,readOnly:s};return n.render(e)}case"text":case"textarea":/* @__PURE__ */
39
- return k(a,{label:P(n,t),htmlFor:l,icon:n.icon,hint:n.hint,children:/* @__PURE__ */k(j,{id:l,value:"string"==typeof r?r:null==r?"":String(r),onChange:i,placeholder:n.placeholder,multiline:"textarea"===n.type,readOnly:s})});case"number":/* @__PURE__ */
40
- return k(a,{label:P(n,t),htmlFor:l,icon:n.icon,hint:n.hint,children:/* @__PURE__ */k(C,{id:l,value:"number"==typeof r?r:void 0,onChange:i,min:n.min,max:n.max,step:n.step,placeholder:n.placeholder,readOnly:s})});case"select":/* @__PURE__ */
41
- return k(a,{label:P(n,t),htmlFor:l,icon:n.icon,hint:n.hint,children:/* @__PURE__ */k($,{id:l,value:r,options:n.options,onChange:i,readOnly:s})});case"radio":/* @__PURE__ */
35
+ /* @__PURE__ */k(l,{kind:"delete",label:j.deleteItem({noun:F}),disabled:!K,onClick:()=>W(a),children:/* @__PURE__ */k("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round","aria-hidden":"true",children:/* @__PURE__ */k("path",{d:"M4 7h16M10 11v6M14 11v6M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 7V4h6v3"})})})]})})]},a)}),
36
+ /* @__PURE__ */k(n,{...E.seam({place:{...B,index:s.length}})})]}):null,w?null:/* @__PURE__ */k("button",{type:"button",className:"es-list-add",disabled:!P,onClick:()=>R(s.length),children:j.add({noun:F})})]})}var P=(e,n)=>"string"==typeof e.label&&e.label?e.label:n;function K({field:e,name:n,id:t,value:l,onChange:a,readOnly:r,context:i,renderers:o}){const[c,d]=b(!0),u=l&&"object"==typeof l?l:{};/* @__PURE__ */
37
+ return k(s,{id:`${t}-group`,title:P(e,n),open:c,onToggle:d,children:Object.entries(e.objectFields).map(([e,l])=>/* @__PURE__ */k(E,{field:l,name:`${n}.${e}`,id:`${t}-${e}`,value:u[e],onChange:n=>a({...u,[e]:n}),readOnly:r,context:i,renderers:o},e))})}function Z({field:e,name:n,id:t,value:l,onChange:a,readOnly:r,context:i,renderers:s,openItem:o,onOpenItem:c}){const[d,u]=b(null),m=c?o??null:d,h=c??u,p=Array.isArray(l)?l:[],f=e.getItemSummary;/* @__PURE__ */
38
+ return k(F,{label:P(e,n),icon:e.icon,noun:"string"==typeof e.noun?e.noun:void 0,items:p,onChange:a,newItem:()=>M({...e.defaultItemProps??{}}),summary:f?(e,n)=>f(e,n):void 0,min:e.min,max:e.max,readOnly:r,open:m,onOpen:h,renderItem:(l,a,o)=>Object.entries(e.arrayFields).map(([e,c])=>/* @__PURE__ */k(E,{field:c,name:`${n}[${a}].${e}`,id:`${t}-${a}-${e}`,value:l?.[e],onChange:n=>o({...l,[e]:n}),readOnly:r,context:i,renderers:s},e))})}function E(e){const{field:n,name:t,id:l,value:r,onChange:i,readOnly:s,context:o,renderers:c}=e;if(!n||n.marker||!1===n.visible)return null;const d=c?.[n.type];if(d)return d({field:n,name:t,id:l,value:r,onChange:i,readOnly:s});switch(n.type){case"custom":{const e={...o,field:n,name:t,id:l,value:r,onChange:i,readOnly:s};return n.render(e)}case"text":case"textarea":/* @__PURE__ */
39
+ return k(a,{label:P(n,t),htmlFor:l,icon:n.icon,hint:n.hint,children:/* @__PURE__ */k(I,{id:l,value:"string"==typeof r?r:null==r?"":String(r),onChange:i,placeholder:n.placeholder,multiline:"textarea"===n.type,readOnly:s})});case"number":/* @__PURE__ */
40
+ return k(a,{label:P(n,t),htmlFor:l,icon:n.icon,hint:n.hint,children:/* @__PURE__ */k(O,{id:l,value:"number"==typeof r?r:void 0,onChange:i,min:n.min,max:n.max,step:n.step,placeholder:n.placeholder,readOnly:s})});case"select":/* @__PURE__ */
41
+ return k(a,{label:P(n,t),htmlFor:l,icon:n.icon,hint:n.hint,children:/* @__PURE__ */k(j,{id:l,value:r,options:n.options,onChange:i,readOnly:s})});case"radio":/* @__PURE__ */
42
42
  return k(a,{label:P(n,t),icon:n.icon,hint:n.hint,children:/* @__PURE__ */k(u,{ariaLabel:P(n,t),value:r,options:n.options.map(e=>({id:e.value,label:e.label,icon:e.icon,disabled:e.disabled||s})),onChange:e=>{s||i(e)}})});case"object":/* @__PURE__ */
43
- return k(E,{...e,field:n});case"array":/* @__PURE__ */
44
- return k(J,{...e,field:n});case"slot":return null}}var Q=e=>r.includes(e);function U(e){let n=r[0];const t=[],l=/* @__PURE__ */new Set;for(const[a,r]of Object.entries(e))r&&(Q(r.bucket)&&(n=r.bucket),r.marker||!1===r.visible||(t.push({name:a,field:r,bucket:n}),"slot"!==r.type&&l.add(n)));return{rows:t,buckets:r.filter(e=>l.has(e))}}function Z(e){return new Map(U(e).rows.map(e=>[e.name,e.bucket]))}function H({fields:e,values:n,onChange:t,readOnly:l=!1,context:a,tab:r,onTab:s,tabs:o=!0,tabIcons:c,renderers:u,idPrefix:h,ariaLabel:p,children:f}){const y=m("panel",d),x=v(),N=h??`es-insp${x.replace(/:/g,"")}`,w=U(e),[O,C]=b(void 0),I=r??O,$=I&&w.buckets.includes(I)?I:w.buckets[0],[j,D]=b(null),L=j&&j.panel===N&&w.rows.some(e=>e.name===j.name)?j:null,S=o&&w.buckets.length>1&&!L,M=`${N}-rows`,A=e=>`${N}-tab-${e.toLowerCase()}`;/* @__PURE__ */
45
- return g("div",{className:"es-insp",children:[S?/* @__PURE__ */k("div",{className:"es-insp-tabs",children:/* @__PURE__ */k(i,{ariaLabel:p??y.settings,activeId:$,onSelect:e=>{const n=e;void 0===r&&C(n),s?.(n)},items:w.buckets.map(e=>({id:e,label:y.buckets[e],icon:c?.[e],htmlId:A(e),panelId:M}))})}):null,
46
- /* @__PURE__ */g("div",{className:"es-insp-rows",id:M,role:S?"tabpanel":void 0,"aria-labelledby":S&&$?A($):void 0,children:[w.rows.map(({name:e,field:r,bucket:i})=>/* @__PURE__ */k("div",{className:"es-insp-row","data-field":e,"data-bucket":i,hidden:!!(L?L.name!==e:S&&i!==$)||void 0,children:/* @__PURE__ */k(K,{field:r,name:e,id:`${N}-${e}`,value:n[e],onChange:n=>t(e,n),readOnly:l,context:a,renderers:u,openItem:L&&L.name===e?L.index:null,onOpenItem:n=>D(null===n?null:{panel:N,name:e,index:n})})},e)),L?null:f]})]})}export{C as FieldNumber,$ as FieldSelect,j as FieldText,H as Inspector,K as InspectorField,F as ListField,Z as bucketsOf,N as clampNumber,M as copyItem,D as insertAt,P as labelOf,L as moveTo,I as optionFor,w as parseTyped,U as planFields,S as removeAt};
43
+ return k(K,{...e,field:n});case"array":/* @__PURE__ */
44
+ return k(Z,{...e,field:n});case"slot":return null}}var R=e=>r.includes(e);function U(e){let n=r[0];const t=[],l=/* @__PURE__ */new Set;for(const[a,r]of Object.entries(e))r&&(R(r.bucket)&&(n=r.bucket),r.marker||!1===r.visible||(t.push({name:a,field:r,bucket:n}),"slot"!==r.type&&l.add(n)));return{rows:t,buckets:r.filter(e=>l.has(e))}}function W(e){return new Map(U(e).rows.map(e=>[e.name,e.bucket]))}function H({fields:e,values:n,onChange:t,readOnly:l=!1,context:a,tab:r,onTab:s,tabs:o=!0,tabIcons:c,renderers:u,idPrefix:h,ariaLabel:p,children:f}){const y=m("panel",d),x=v(),N=h??`es-insp${x.replace(/:/g,"")}`,w=U(e),[C,O]=b(void 0),$=r??C,j=$&&w.buckets.includes($)?$:w.buckets[0],[I,S]=b(null),L=I&&I.panel===N&&w.rows.some(e=>e.name===I.name)?I:null,D=o&&w.buckets.length>1&&!L,M=`${N}-rows`,A=e=>`${N}-tab-${e.toLowerCase()}`;/* @__PURE__ */
45
+ return g("div",{className:"es-insp",children:[D?/* @__PURE__ */k("div",{className:"es-insp-tabs",children:/* @__PURE__ */k(i,{ariaLabel:p??y.settings,activeId:j,onSelect:e=>{const n=e;void 0===r&&O(n),s?.(n)},items:w.buckets.map(e=>({id:e,label:y.buckets[e],icon:c?.[e],htmlId:A(e),panelId:M}))})}):null,
46
+ /* @__PURE__ */g("div",{className:"es-insp-rows",id:M,role:D?"tabpanel":void 0,"aria-labelledby":D&&j?A(j):void 0,children:[w.rows.map(({name:e,field:r,bucket:i})=>/* @__PURE__ */k("div",{className:"es-insp-row","data-field":e,"data-bucket":i,hidden:!!(L?L.name!==e:D&&i!==j)||void 0,children:/* @__PURE__ */k(E,{field:r,name:e,id:`${N}-${e}`,value:n[e],onChange:n=>t(e,n),readOnly:l,context:a,renderers:u,openItem:L&&L.name===e?L.index:null,onOpenItem:n=>S(null===n?null:{panel:N,name:e,index:n})})},e)),L?null:f]})]})}export{O as FieldNumber,j as FieldSelect,I as FieldText,H as Inspector,E as InspectorField,F as ListField,W as bucketsOf,N as clampNumber,M as copyItem,S as insertAt,P as labelOf,L as moveTo,$ as optionFor,w as parseTyped,U as planFields,D as removeAt};
@@ -1,9 +1,9 @@
1
- export { A as AfterRemove, I as ItemSelector, N as NodeSelection, P as Planned, S as StepBounds, c as canStep, f as fromItemSelector, p as parentStep, a as planDuplicate, b as planMove, d as planPaste, e as planRemove, g as planSetProps, h as planStep, t as toItemSelector } from '../plan-DtNw2VuI.js';
2
- export { C as ClipboardEntry, N as NodeClipboard, a as NodeOps, b as NodeOpsHost, c as createNodeClipboard, u as useNodeOps } from '../useNodeOps-6IAej9jy.js';
1
+ export { A as AfterRemove, I as ItemSelector, N as NodeSelection, P as Planned, S as StepBounds, c as canStep, f as fromItemSelector, p as parentStep, a as planDuplicate, b as planMove, d as planPaste, e as planRemove, g as planSetProps, h as planStep, t as toItemSelector } from '../plan-DChbUXdS.js';
2
+ export { C as ClipboardEntry, N as NodeClipboard, a as NodeOps, b as NodeOpsHost, c as createNodeClipboard, u as useNodeOps } from '../useNodeOps-BF0fQsif.js';
3
3
  import { ReactNode } from 'react';
4
4
  import { E as EditorContextMenuItem } from '../types-pGBXevBU.js';
5
5
  import { N as NodeMenuWords } from '../words-DOhF-4D4.js';
6
- import '../types-DziKCwsN.js';
6
+ import '../types-41704JE4.js';
7
7
 
8
8
  /**
9
9
  * nodeMenuItems — the right-click rows for a block, ONE list for both editors.
@@ -1 +1 @@
1
- import{DEFAULT_NODE_MENU_WORDS as e}from"../chunk-WK3AFPXY.js";export{canStep,fromItemSelector,parentStep,planDuplicate,planMove,planPaste,planRemove,planSetProps,planStep,toItemSelector,useNodeOps}from"../chunk-EFTTSIMK.js";import{TrashIcon as n,EyeIcon as t,EyeOffIcon as o,RenameIcon as p,PasteIcon as l,CopyIcon as c,MoveDownIcon as s,MoveUpIcon as a,DuplicateIcon as i,AddIcon as r,LayersIcon as u}from"../chunk-YNZZYHA4.js";import"../chunk-LPRQDDQO.js";import"../chunk-NKB3KVAB.js";import{jsx as h}from"react/jsx-runtime";function d(){let e=null;const n=/* @__PURE__ */new Set;return{get:()=>e,set(t){e=t;for(const e of[...n])e()},subscribe:e=>(n.add(e),()=>n.delete(e))}}var m={layer:{icon:/* @__PURE__ */h(u,{})},addInside:{icon:/* @__PURE__ */h(r,{})},duplicate:{icon:/* @__PURE__ */h(i,{})},moveUp:{icon:/* @__PURE__ */h(a,{})},moveDown:{icon:/* @__PURE__ */h(s,{})},copy:{icon:/* @__PURE__ */h(c,{}),shortcut:"⌘C"},cut:{icon:/* @__PURE__ */h(c,{}),shortcut:"⌘X"},paste:{icon:/* @__PURE__ */h(l,{}),shortcut:"⌘V"},rename:{icon:/* @__PURE__ */h(p,{})},hide:{icon:/* @__PURE__ */h(o,{})},show:{icon:/* @__PURE__ */h(t,{})},upLevel:{},delete:{icon:/* @__PURE__ */h(n,{}),danger:!0}};function v(n){const{actions:t,rows:o={},extras:p={},words:l=e}=n,c=e=>({...m[e],label:l[e],...o[e]}),s=(e,n,t)=>{const o=c(e),p={label:t??o.label??e,onClick:n};return o.icon&&(p.icon=o.icon),o.shortcut&&(p.shortcut=o.shortcut),o.danger&&(p.danger=!0),p},a=()=>{const e=c("layer"),t={label:e.label??l.layer,onClick:()=>{},children:n.layer.items};return e.icon&&(t.icon=e.icon),t},i=[],r=[],u=[],h=[],d=!!n.layer&&n.layer.items.length>1;if(d&&"pick"===(n.layer.group??"pick")&&i.push(a()),t.addInside&&r.push(s("addInside",t.addInside)),t.duplicate&&r.push(s("duplicate",t.duplicate)),t.moveUp&&r.push(s("moveUp",t.moveUp)),t.moveDown&&r.push(s("moveDown",t.moveDown)),t.copy&&r.push(s("copy",t.copy)),t.cut&&r.push(s("cut",t.cut)),t.paste){const e=c("paste").label??l.paste;r.push(s("paste",t.paste.run,l.pasteNamed({paste:e,label:t.paste.label})))}t.rename&&u.push(s("rename",t.rename)),t.hide&&u.push(t.hide.hidden?s("show",t.hide.run):s("hide",t.hide.run)),d&&"change"===n.layer.group&&u.push(a()),t.upLevel&&u.push(s("upLevel",t.upLevel)),t.delete&&h.push(s("delete",t.delete)),i.push(...p.pick??[]),r.push(...p.make??[]),u.push(...p.change??[]),h.push(...p.remove??[]);const v=[i,r,n.style??[],u,h].filter(e=>e.length>0),g=i.length+r.length+u.length+h.length===0,k=[{label:n.title,header:!0,onClick:()=>{}}];return g&&n.pinnedLine&&k.push({label:n.pinnedLine,header:!0,onClick:()=>{}}),v.forEach((e,t)=>{(t>0||g&&n.pinnedLine)&&k.push({label:"—",onClick:()=>{}}),k.push(...e)}),k}export{d as createNodeClipboard,v as nodeMenuItems};
1
+ import{DEFAULT_NODE_MENU_WORDS as e}from"../chunk-WK3AFPXY.js";export{canStep,fromItemSelector,parentStep,planDuplicate,planMove,planPaste,planRemove,planSetProps,planStep,toItemSelector,useNodeOps}from"../chunk-D2BCHTQR.js";import{TrashIcon as n,EyeIcon as t,EyeOffIcon as o,RenameIcon as p,PasteIcon as l,CopyIcon as c,MoveDownIcon as s,MoveUpIcon as a,DuplicateIcon as i,AddIcon as r,LayersIcon as u}from"../chunk-YNZZYHA4.js";import"../chunk-KRXQM65X.js";import"../chunk-NKB3KVAB.js";import{jsx as h}from"react/jsx-runtime";function d(){let e=null;const n=/* @__PURE__ */new Set;return{get:()=>e,set(t){e=t;for(const e of[...n])e()},subscribe:e=>(n.add(e),()=>n.delete(e))}}var m={layer:{icon:/* @__PURE__ */h(u,{})},addInside:{icon:/* @__PURE__ */h(r,{})},duplicate:{icon:/* @__PURE__ */h(i,{})},moveUp:{icon:/* @__PURE__ */h(a,{})},moveDown:{icon:/* @__PURE__ */h(s,{})},copy:{icon:/* @__PURE__ */h(c,{}),shortcut:"⌘C"},cut:{icon:/* @__PURE__ */h(c,{}),shortcut:"⌘X"},paste:{icon:/* @__PURE__ */h(l,{}),shortcut:"⌘V"},rename:{icon:/* @__PURE__ */h(p,{})},hide:{icon:/* @__PURE__ */h(o,{})},show:{icon:/* @__PURE__ */h(t,{})},upLevel:{},delete:{icon:/* @__PURE__ */h(n,{}),danger:!0}};function v(n){const{actions:t,rows:o={},extras:p={},words:l=e}=n,c=e=>({...m[e],label:l[e],...o[e]}),s=(e,n,t)=>{const o=c(e),p={label:t??o.label??e,onClick:n};return o.icon&&(p.icon=o.icon),o.shortcut&&(p.shortcut=o.shortcut),o.danger&&(p.danger=!0),p},a=()=>{const e=c("layer"),t={label:e.label??l.layer,onClick:()=>{},children:n.layer.items};return e.icon&&(t.icon=e.icon),t},i=[],r=[],u=[],h=[],d=!!n.layer&&n.layer.items.length>1;if(d&&"pick"===(n.layer.group??"pick")&&i.push(a()),t.addInside&&r.push(s("addInside",t.addInside)),t.duplicate&&r.push(s("duplicate",t.duplicate)),t.moveUp&&r.push(s("moveUp",t.moveUp)),t.moveDown&&r.push(s("moveDown",t.moveDown)),t.copy&&r.push(s("copy",t.copy)),t.cut&&r.push(s("cut",t.cut)),t.paste){const e=c("paste").label??l.paste;r.push(s("paste",t.paste.run,l.pasteNamed({paste:e,label:t.paste.label})))}t.rename&&u.push(s("rename",t.rename)),t.hide&&u.push(t.hide.hidden?s("show",t.hide.run):s("hide",t.hide.run)),d&&"change"===n.layer.group&&u.push(a()),t.upLevel&&u.push(s("upLevel",t.upLevel)),t.delete&&h.push(s("delete",t.delete)),i.push(...p.pick??[]),r.push(...p.make??[]),u.push(...p.change??[]),h.push(...p.remove??[]);const v=[i,r,n.style??[],u,h].filter(e=>e.length>0),g=i.length+r.length+u.length+h.length===0,k=[{label:n.title,header:!0,onClick:()=>{}}];return g&&n.pinnedLine&&k.push({label:n.pinnedLine,header:!0,onClick:()=>{}}),v.forEach((e,t)=>{(t>0||g&&n.pinnedLine)&&k.push({label:"—",onClick:()=>{}}),k.push(...e)}),k}export{d as createNodeClipboard,v as nodeMenuItems};
@@ -1,4 +1,4 @@
1
- import { P as Place, D as Data, a as DataConfig, N as Node } from './types-DziKCwsN.js';
1
+ import { P as Place, D as Data, a as DataConfig, N as Node } from './types-41704JE4.js';
2
2
 
3
3
  /**
4
4
  * Every node operation the two editors offer, as ONE pure step: a document in,
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties, ReactNode, ReactElement } from 'react';
2
- import { B as BlockShape, D as Data } from '../types-DziKCwsN.js';
2
+ import { B as BlockShape, D as Data } from '../types-41704JE4.js';
3
3
 
4
4
  /**
5
5
  * efficient-easel/render — draw a saved document, the published way.
@@ -1,4 +1,4 @@
1
- import { a as DataConfig } from './types-DziKCwsN.js';
1
+ import { a as DataConfig } from './types-41704JE4.js';
2
2
 
3
3
  /**
4
4
  * A BLOCK'S `resolveData`, RUN AS PUCK RUNS IT — `resolveComponentData` in Puck
@@ -51,13 +51,20 @@ interface Place extends SlotAddress {
51
51
  index: number;
52
52
  }
53
53
  /**
54
- * The part of a field definition the data layer needs: which props are slots.
54
+ * The part of a field definition the data layer needs: which props are slots,
55
+ * and (./translate) which hold words that are written again per language.
55
56
  * A Puck `Field` satisfies it, so an app hands in the config it already has.
56
57
  */
57
58
  interface FieldShape {
58
59
  type: string;
59
60
  objectFields?: Record<string, FieldShape>;
60
61
  arrayFields?: Record<string, FieldShape>;
62
+ /**
63
+ * Whether the value is translated. Left out, `text` and `textarea` are and
64
+ * nothing else is; on an `object` or `array` field it is the default for the
65
+ * fields inside it. A `slot` never is: its children have ids of their own.
66
+ */
67
+ translatable?: boolean;
61
68
  }
62
69
  type FieldsShape = Record<string, FieldShape>;
63
70
  /**
@@ -1,6 +1,6 @@
1
1
  import { DataInput } from './data/index.js';
2
- import { I as ItemSelector, N as NodeSelection } from './plan-DtNw2VuI.js';
3
- import { D as Data, S as SlotAddress, a as DataConfig, N as Node } from './types-DziKCwsN.js';
2
+ import { I as ItemSelector, N as NodeSelection } from './plan-DChbUXdS.js';
3
+ import { D as Data, S as SlotAddress, a as DataConfig, N as Node } from './types-41704JE4.js';
4
4
 
5
5
  /**
6
6
  * The editor's UI state, in Puck's shape so the apps' `appState.ui` reads move
@@ -1,5 +1,5 @@
1
- import { N as Node, S as SlotAddress, D as Data, a as DataConfig, P as Place } from './types-DziKCwsN.js';
2
- import { N as NodeSelection, A as AfterRemove, S as StepBounds } from './plan-DtNw2VuI.js';
1
+ import { N as Node, S as SlotAddress, D as Data, a as DataConfig, P as Place } from './types-41704JE4.js';
2
+ import { N as NodeSelection, A as AfterRemove, S as StepBounds } from './plan-DChbUXdS.js';
3
3
 
4
4
  /**
5
5
  * The node clipboard — what Copy and Cut hold, and Paste reads.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efficient-easel",
3
- "version": "0.96.0",
3
+ "version": "0.97.0",
4
4
  "description": "Efficient Easel: the EFFICIENT editors' shared engine and chrome: the saved document as pure functions, the published renderer, and the editor frame, panels, Layers tree, text grammar and type-in-place box. Published as editor-shell up to 0.66.0 and as efficient-editor up to 0.95.0.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Efficient Pty Ltd",
@@ -1 +0,0 @@
1
- import{isRecord as n,fieldsFrom as t,blockOf as o,topLevelSlotKeys as e,slotLocations as r,setIn as s,fieldsOf as c,defaultsFrom as i,isNode as p}from"./chunk-NKB3KVAB.js";var f=()=>({lastChange:{}});function l(n,t){if(n===t)return!0;if(!n||!t||"object"!=typeof n||"object"!=typeof t)return n!=n&&t!=t;if(Array.isArray(n)!==Array.isArray(t))return!1;if(Array.isArray(n)){const o=t;if(n.length!==o.length)return!1;for(let t=0;t<n.length;t++)if(!l(n[t],o[t]))return!1;return!0}const o=Object.keys(n),e=Object.keys(t);if(o.length!==e.length)return!1;for(const e of o){if(!Object.prototype.hasOwnProperty.call(t,e))return!1;if(!l(n[e],t[e]))return!1}return!0}function a(n,t){if(!n)return{};const o=n.props??{},e=t?.props??{},r={};for(const n of Object.keys(o))r[n]=!l(e[n],o[n]);return r}async function d(c,i,p={}){const{metadata:u={},trigger:y="replace",cache:h=f(),onResolveStart:g,onResolveEnd:w}=p,m=function(n,t){return n.type&&"root"!==n.type?t.components[n.type]:t.root}(c,i);let $={...c};const x=Boolean(m?.resolveData&&c.props),I=n(c.props)&&"id"in c.props?String(c.props.id):"root";if(x){const n=h.lastChange[I];if("force"!==y&&n&&l(c,n.item))return{node:n.resolved,didChange:!1};const t=a(c,n?.item??null);g?.(c);const o=await m.resolveData(c,{changed:t,lastData:n?.item??null,metadata:{...u,...m.metadata??{}},trigger:y})??{};$.props={...c.props,...o.props??{}},o.readOnly&&Object.keys(o.readOnly).length&&($.readOnly=o.readOnly)}const b=t(c.type&&"root"!==c.type?o(i,c.type):i.root);if(m)for(const n of e(b))void 0===$.props[n]&&($={...$,props:{...$.props,[n]:[]}});for(const n of r($.props,b)){if(!n.present)continue;const t=await Promise.all(n.content.map(async n=>(await d(n,i,{metadata:u,trigger:y,cache:h,onResolveStart:g,onResolveEnd:w})).node));$={...$,props:s($.props,n.segments,t)}}return x&&w?.($),h.lastChange[I]={item:c,resolved:$},{node:$,didChange:!l(c,$)}}var u="root",y="default-zone",h={parentId:u,slot:y},g=({parentId:n,slot:t})=>`${n}:${t}`;function w(n){const t=n.indexOf(":");if(-1===t)throw new $("no-slot",`"${n}" is not a zone key`);return{parentId:n.slice(0,t),slot:n.slice(t+1)}}var m=n=>n.parentId===u&&n.slot===y,$=class extends Error{code;constructor(n,t){super(t),this.name="DataError",this.code=n}};function x(n){try{const t=globalThis.crypto;if(t&&"function"==typeof t.randomUUID)return`${n}-${t.randomUUID()}`}catch{}return`${n}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function I(n,t){return r(n.props,c(t,n.type)).map(({slot:n,content:t})=>({slot:n,content:t}))}function b(n,o){return r(z(n),t(o.root))}function z(t){return n(t.root?.props)?t.root.props:{}}function O(n,t,o){const e=(n,t,e,r,s)=>{if(!Array.isArray(n))return n;const c=[...e,t];let f=null;return n.forEach((e,l)=>{if(!p(e))return;const a={place:{...t,index:l},path:c,parent:r,depth:s};let d=o(e,a)??e;if(d!==e&&d.props.id!==e.props.id)throw new $("id-change",`walk: ${e.props.id} came back as ${d.props.id}`);d=i(d,c,s+1),d!==e&&(f??=[...n],f[l]=d)}),f??n},i=(n,o,i)=>{let p=n.props;for(const f of r(n.props,c(t,n.type))){if(!f.present)continue;const t=e(f.content,{parentId:n.props.id,slot:f.slot},o,n,i);t!==f.content&&(p=s(p,f.segments,t))}return p===n.props?n:{...n,props:p}};let f=n;const l=e(n.content,h,[],null,0);l!==n.content&&(f={...f,content:l});let a=z(f);for(const n of b(f,t)){if(!n.present)continue;const t=e(n.content,{parentId:u,slot:n.slot},[],null,0);t!==n.content&&(a=s(a,n.segments,t))}a!==z(f)&&(f={...f,root:{...f.root,props:a}});const d=f.zones;if(d){let n=d;for(const t of Object.keys(d)){const o=k(t);if(!o)continue;const r=e(d[t],o,[],null,0);r!==d[t]&&(n={...n,[t]:r})}n!==d&&(f={...f,zones:n})}return f}function k(n){const t=n.indexOf(":");return-1===t?null:{parentId:n.slice(0,t),slot:n.slice(t+1)}}function A(n,t,o){let e=null;const r={};try{O(n,t,(n,t)=>{if(n.props.id===o)throw e={node:n,place:t.place,path:t.path},r})}catch(n){if(n!==r)throw n}return e}function j(n,t,o){if(m(o))return Array.isArray(n.content)?n.content:[];const e=n.zones?.[g(o)];if(o.parentId===u){const r=b(n,t).find(n=>n.slot===o.slot);return r?r.content:e??null}const s=A(n,t,o.parentId);if(s){const n=r(s.node.props,c(t,s.node.type)).find(n=>n.slot===o.slot);if(n)return n.content}return e??null}function v(n,t){const o=/* @__PURE__ */new Set;return O(n,t,n=>{o.add(n.props.id)}),o}function S(n,t){const o=/* @__PURE__ */new Set([n.props.id]),e=n=>{for(const{content:r}of I(n,t))for(const n of r)p(n)&&(o.add(n.props.id),e(n))};return e(n),o}function D(n,t,o,e){if(m(o)){const t=Array.isArray(n.content)?n.content:[];return{...n,content:e(t)}}const i=g(o),p=!!n.zones&&Array.isArray(n.zones[i]);if(o.parentId===u){const r=b(n,t).find(n=>n.slot===o.slot);if(r){const t=s(z(n),r.segments,e(r.content));return{...n,root:{...n.root,props:t}}}}else{const i=A(n,t,o.parentId);if(i){const p=r(i.node.props,c(t,i.node.type)).find(n=>n.slot===o.slot);if(p)return N(n,t,i,n=>({...n,props:s(n.props,p.segments,e(p.content))}))}else if(!p)throw new $("not-found",`no node ${o.parentId}`)}if(p)return{...n,zones:{...n.zones,[i]:e(n.zones[i])}};throw new $("no-slot",`no slot "${o.slot}" on ${o.parentId}`)}function N(n,t,o,e){return D(n,t,o.place,n=>{const t=[...n];return t[o.place.index]=e(n[o.place.index]),t})}function E(n,t,o){const e=A(n,t,o);if(!e)throw new $("not-found",`no node ${o}`);return e}function C(n,t,o){const e=j(n,t,o);if(e)return e;if(o.parentId!==u&&!A(n,t,o.parentId))throw new $("not-found",`no node ${o.parentId}`);throw new $("no-slot",`no slot "${o.slot}" on ${o.parentId}`)}function R(n,t,o){if(!Number.isInteger(n)||n<0||n>t)throw new $("bad-index",`${o}: index ${n} is outside 0…${t}`)}function U(n,c){const i=o(c,n.type);if(!i)return n;const p=t(i);let f=n.props;for(const n of e(p))null==f[n]&&(f={...f,[n]:[]});for(const n of r(f,p)){if(!n.present)continue;const t=B(n.content,c);t!==n.content&&(f=s(f,n.segments,t))}return f===n.props?n:{...n,props:f}}function B(t,o){let e=null;return t.forEach((r,s)=>{if(!n(r)||"string"!=typeof r.type)return;let c=r;if(n(c.props)){if("string"!=typeof c.props.id||""===c.props.id){const{id:n,...t}=c.props;c={...c,props:{id:x(c.type),...t}}}}else c={...c,props:{id:x(c.type)}};const i=U(c,o);i!==r&&(e??=[...t],e[s]=i)}),e??t}function P(n,o){const c=t(o.root);let i=n.props;for(const n of e(c))null==i[n]&&(i={...i,[n]:[]});for(const n of r(i,c)){if(!n.present)continue;const t=B(n.content,o);t!==n.content&&(i=s(i,n.segments,t))}return i===n.props?n:{...n,props:i}}function J(t,o){let e=n(t)?t:{};const r=e.root;if(n(r)){if(!n(r.props)){const n=Object.keys(r).filter(n=>"props"!==n);e={...e,root:n.length?{props:{...M(r,n)}}:{props:{}}}}}else e={...e,root:{props:{}}};const s=i(o.root);if(s){const n=Object.keys(s).filter(n=>!(n in e.root.props));if(n.length){const t=T(M(s,n));e={...e,root:{...e.root,props:{...e.root.props,...t}}}}}const c=P(e.root,o);c!==e.root&&(e={...e,root:c}),Array.isArray(e.content)||(e={...e,content:[]});const p=B(e.content,o);return p!==e.content&&(e={...e,content:p}),e=n(e.zones)?function(n,t){let o=n;for(const e of Object.keys(n.zones??{})){const n=o.zones[e];if(!Array.isArray(n)||0===n.length)continue;const r=k(e);if(!r||m(r))continue;const s=K(o,t,r);if(!s||s.content.length>0)continue;const{[e]:c,...i}=o.zones;o=D({...o,zones:i},t,r,()=>B(n,t))}const e=o.zones;let r=e;for(const n of Object.keys(e)){if(!Array.isArray(e[n]))continue;const o=B(e[n],t);o!==e[n]&&(r={...r,[n]:o})}return r===e?o:{...o,zones:r}}(e,o):{...e,zones:{}},e}function K(n,t,o){if(o.parentId===u)return b(n,t).find(n=>n.slot===o.slot);const e=A(n,t,o.parentId);return e?r(e.node.props,c(t,e.node.type)).find(n=>n.slot===o.slot):void 0}function M(n,t){const o={};for(const e of t)o[e]=n[e];return o}function T(n){return void 0===n?n:JSON.parse(JSON.stringify(n))}function V(n,t,o={},e={}){const r=n.components[t];if(!r)throw new $("unknown-type",`no block type "${t}" in the config`);return U({type:t,props:{...T(i(r)??{}),...T(o),id:e.id??x(t)}},n)}function q(t,o,e,r){if(!p(r))throw new $("unknown-type","insert: not a node");const s=C(t,o,e);R(e.index,s.length,"insert");const c=U(n(r.props)&&"string"==typeof r.props.id&&r.props.id?r:{...r,props:{...r.props,id:x(r.type)}},o),i=v(t,o);for(const n of S(c,o))if(i.has(n))throw new $("duplicate-id",`insert: ${n} is already in the document`);return D(t,o,e,n=>[...n.slice(0,e.index),c,...n.slice(e.index)])}function F(n,t,o){const e=E(n,t,o);let r=D(n,t,e.place,n=>[...n.slice(0,e.place.index),...n.slice(e.place.index+1)]);if(r.zones&&Object.keys(r.zones).length){const n=S(e.node,t),o=Object.keys(r.zones).filter(t=>!n.has(t.split(":")[0]));o.length!==Object.keys(r.zones).length&&(r={...r,zones:M(r.zones,o)})}return r}function G(n,t,o,e){const r=E(n,t,o);if(S(r.node,t).has(e.parentId))throw new $("cycle",`move: ${o} cannot go inside itself`);if(r.place.parentId===e.parentId&&r.place.slot===e.slot){const o=C(n,t,e);return R(e.index,o.length-1,"move"),e.index===r.place.index?n:D(n,t,e,n=>{const t=[...n],[o]=t.splice(r.place.index,1);return t.splice(e.index,0,o),t})}R(e.index,C(n,t,e).length,"move");const s=D(n,t,r.place,n=>[...n.slice(0,r.place.index),...n.slice(r.place.index+1)]);return D(s,t,e,n=>[...n.slice(0,e.index),r.node,...n.slice(e.index)])}function H(n,t,o,e={}){const r=E(n,t,o),s=Q(T(r.node),t,e.strip,e.id);return D(n,t,r.place,n=>[...n.slice(0,r.place.index+1),s,...n.slice(r.place.index+1)])}function L(n,t,o={}){return Q(T(n),t,o.strip,o.id)}function Q(n,t,o,e){let i={...n,props:{...n.props,id:e??x(n.type)}};if(o){const n=o(i);if(n.props.id!==i.props.id)throw new $("id-change","duplicate: strip must not change the id");i=n}let f=i.props;for(const n of r(f,c(t,i.type))){if(!n.present)continue;const e=n.content.map(n=>p(n)?Q(n,t,o):n);f=s(f,n.segments,e)}return U({...i,props:f},t)}function W(n,t,o,e){if("id"in e&&e.id!==o)throw new $("id-change",`setProps: ${o} cannot become ${String(e.id)}`);const r=E(n,t,o);return Z(r.node.props,e)?N(n,t,r,n=>U({...n,props:{...n.props,...e,id:o}},t)):n}function X(n,t,o,e){if(!p(e))throw new $("unknown-type","replaceNode: not a node");if(e.props.id!==o)throw new $("id-change",`replaceNode: ${o} cannot become ${String(e.props.id)}`);const r=E(n,t,o),s=U(e,t),c=v(n,t);for(const n of S(r.node,t))c.delete(n);for(const n of S(s,t))if(c.has(n))throw new $("duplicate-id",`replaceNode: ${n} is already in the document`);return N(n,t,r,()=>s)}function Y(n,t,o){const e=z(n);if(!Z(e,o))return n;const r=P({...n.root,props:{...e,...o}},t);return{...n,root:r}}function Z(n,t){return Object.keys(t).some(o=>!(o in n)||!Object.is(n[o],t[o]))}export{$ as DataError,u as ROOT_ID,h as ROOT_LIST,y as ROOT_SLOT,a as changedProps,L as copyNode,V as createNode,f as createResolveCache,l as deepEqual,H as duplicate,A as find,j as getList,q as insert,G as move,x as newId,J as normalizeData,w as parseZoneKey,F as remove,X as replaceNode,d as resolveNodeData,W as setProps,Y as setRoot,I as slotsOf,O as walk,g as zoneKey};