efficient-easel 24.0.0 → 24.2.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.
Files changed (32) hide show
  1. package/README.md +10 -0
  2. package/dist/{chunk-CMMR6CJS.js → chunk-4ESG53BH.js} +1 -1
  3. package/dist/{chunk-PDJ5ZALV.js → chunk-75C6WFNF.js} +1 -1
  4. package/dist/chunk-7RSE6KKY.js +1 -0
  5. package/dist/{chunk-4RJBW7VC.js → chunk-CMPFUJ26.js} +6 -6
  6. package/dist/chunk-FJTCSQWK.js +16 -0
  7. package/dist/{chunk-2AV62DEP.js → chunk-G67G63O5.js} +1 -1
  8. package/dist/{chunk-ZYHKXEND.js → chunk-JMAOCKB2.js} +3 -3
  9. package/dist/{chunk-D5GQEUKM.js → chunk-OITNWE52.js} +1 -1
  10. package/dist/{chunk-Z5BPY2VG.js → chunk-QORC32JO.js} +5 -5
  11. package/dist/chunk-UKPZ2YWE.js +64 -0
  12. package/dist/easel/index.d.ts +20 -1
  13. package/dist/easel/index.js +1 -1
  14. package/dist/screen/components/AddBlockRow.js +1 -1
  15. package/dist/screen/components/AddSidePanel.js +1 -1
  16. package/dist/screen/components/ScreenChrome.js +1 -1
  17. package/dist/screen/components/ScreenMount.js +1 -1
  18. package/dist/screen/components/ScreenStoreProvider.js +1 -1
  19. package/dist/screen/components/SectionScreenShell.js +17 -17
  20. package/dist/screen/components/usePartBridge.js +1 -1
  21. package/dist/screen/index.d.ts +1 -1
  22. package/dist/screen/index.js +1 -1
  23. package/dist/screen/lib/document/box-fields.js +9 -9
  24. package/dist/screen/lib/document/use-section-ops.js +1 -1
  25. package/dist/screen/lib/key-scope.js +1 -1
  26. package/dist/screen/lib/screen-parts.d.ts +15 -2
  27. package/dist/screen/lib/screen-parts.js +1 -1
  28. package/dist/strings/index.js +1 -1
  29. package/package.json +1 -1
  30. package/dist/chunk-7BW74Y55.js +0 -1
  31. package/dist/chunk-HHQZB6IE.js +0 -64
  32. package/dist/chunk-VBOSOH5M.js +0 -16
@@ -1,16 +0,0 @@
1
- import{DEFAULT_CANVAS_WORDS as e}from"./chunk-TBY3DFKS.js";import{useResolvedFields as t}from"./chunk-AGWKB77Q.js";import{toItemSelector as n,fromItemSelector as o,useNodeOps as r,parentStep as i,clickPickPart as l,clickPick as s}from"./chunk-RPMSET77.js";import{selectionBox as a,placeWindow as c,offsetOrigin as d,colorRunOf as u,ColorWindow as p,startCanvasTyping as f,textMap as h}from"./chunk-HZSZT3BE.js";import{DEFAULT_COPY_WORDS as m}from"./chunk-KRL3IUV3.js";import{useWords as g}from"./chunk-MFIRYGHW.js";import{setCanvasNonce as v,CANVAS_TYPABLE_EVENT as y,related as w,isTypingTarget as b,upsertCanvasStyle as k,removeCanvasStyle as S,WORDS_CLEAR as C,frameRectToHost as I,CANVAS_TYPING_EVENT as D,drawnBox as E}from"./chunk-YU3WHLGI.js";import{queryAllCopies as x}from"./chunk-LF3FUSCQ.js";import{find as O,ROOT_ID as M,getList as A,remove as R,parseZoneKey as z,move as P,duplicate as $,replaceNode as V,createNode as L,insert as j,normalizeData as N,createResolveCache as B,slotsOf as K,resolveNodeData as Z,ROOT_SLOT as F}from"./chunk-TGZCD6IP.js";import{topLevelSlotKeys as T,fieldsFrom as H,drawnBlockCount as W,defaultsFrom as Y}from"./chunk-KXM6YRG2.js";import{createContext as U,useEffect as q,useContext as G,useRef as Q,useSyncExternalStore as X,useState as J,useReducer as _,useMemo as ee,useCallback as te,useLayoutEffect as ne}from"react";import{jsx as oe,jsxs as re,Fragment as ie}from"react/jsx-runtime";import{createPortal as le}from"react-dom";import{registerModalEscapeInterceptor as se,FloatingBar as ae,TextToolbar as ce,LinkPicker as de}from"efficient-shell/ui";function ue(e){return!["setData","setUi","set"].includes(e.type)}var pe=(e,t,n,o)=>{const r=A(e,t,z(n));return r?.[o]??null},fe=(e,t,n,o,r)=>{const i=pe(e,t,n,o);if(!i)throw new Error(`${r}: nothing at ${n}[${o}]`);return i};function he(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 me(e,t,n){return n?"node"===n.kind?O(e,t,n.id)?n:null:n.parentId===M?A(e,t,n)?n:null:O(e,t,n.parentId)&&A(e,t,n)?n:null:null}function ge(e,t,n,r=!1){const{itemSelector:i,selectedSlot:l,...s}=n;let a=e.selection;var c;return"itemSelector"in n&&(a=o(e.data,t,i??null)),"selectedSlot"in n&&(l?a=(c=l)?{kind:"slot",parentId:c.parentId,slot:c.slot}:null:"slot"===a?.kind&&(a=null)),{...e,selection:a,ui:r?s:{...e.ui,...s}}}function ve(e,t,n){const o=ye(e,t,n);if(o===e)return e;const r=me(o.data,n,o.selection);return r===o.selection?o:{...o,selection:r}}function ye(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 ge(e,n,"function"==typeof t.ui?t.ui(he(e,n)):t.ui);case"set":{const r={data:o,ui:he(e,n)},i="function"==typeof t.state?t.state(r):t.state;let l=i.data?{...e,data:i.data}:e;return i.ui&&(l=ge(l,n,i.ui,!0)),l}case"insert":{const r={...z(t.destinationZone),index:t.destinationIndex},i=L(n,t.componentType,{},t.id?{id:t.id}:{});return{...e,data:j(o,n,r,i)}}case"replace":{const r=fe(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:V(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=fe(o,n,t.sourceZone,t.sourceIndex,"duplicate"),i=$(o,n,r.props.id),l=pe(i,n,t.sourceZone,t.sourceIndex+1);return{...e,data:i,selection:l?{kind:"node",id:l.props.id}:e.selection}}case"reorder":return ye(e,{...t,type:"move",sourceZone:t.destinationZone},n);case"move":{if(t.sourceZone===t.destinationZone&&t.sourceIndex===t.destinationIndex)return e;const r=pe(o,n,t.sourceZone,t.sourceIndex);if(!r)return e;const i={...z(t.destinationZone),index:t.destinationIndex};return{...e,data:P(o,n,r.props.id,i)}}case"remove":{const r=fe(o,n,t.zone,t.index,"remove");return{...e,data:R(o,n,r.props.id)}}default:return e}}var we={drag:!0,duplicate:!0,delete:!0,edit:!0,insert:!0},be={leftSideBarVisible:!0,rightSideBarVisible:!0,arrayState:{},componentList:{},isDragging:!1,previewMode:"edit",viewports:{current:{width:360,height:"auto"},options:[],controlsVisible:!0},field:{focus:null}},ke=0,Se=()=>`history-${ke+=1}`;function Ce(e){let t=e.config;const r=e.now??(()=>Date.now()),i=e.historyCoalesceMs??250;let l=e.permissions??{};const s=N(e.data,t);let a=s,c={data:s,selection:null,ui:{...be}};if(e.ui){const{itemSelector:n,selectedSlot:r,...i}=e.ui;c={data:s,selection:r?{kind:"slot",...r}:o(s,t,n??null),ui:{...be,...i}}}let d=[{core:c,at:-1/0,sealed:!0,id:Se()}],u=0;const p=e=>{const t=d[u],n=r();!e&&u===d.length-1&&u>0&&!t.sealed&&n-t.at<i?d=[...d.slice(0,u),{...t,core:c,at:n}]:(d=[...d.slice(0,u+1),{core:c,at:n,sealed:e,id:Se()}],u=d.length-1)},f=/* @__PURE__ */new Set;let h=null,m=null,g=0,v=null,y=!1;const w=()=>{for(const e of[...f])e()},b=()=>{d=[...d.slice(0,u),{...d[u],core:c},...d.slice(u+1)]},k=(t,n)=>{g>0?y=y||n:(n?p(!1):c!==t&&b(),c.data!==t.data&&e.onChange?.(c.data),c!==t&&w())},S=e=>{const n=c;if(c=ve(c,e,t),c===n)return;const o=e.recordHistory??ue(e);k(n,o&&c.data!==n.data)},C=t=>{0===g&&(v=c,y=!1),g+=1;try{t()}catch(e){throw g-=1,0===g&&v&&(c=v,v=null),e}if(g-=1,g>0||!v)return;const n=v;v=null,y&&c.data!==n.data?p(!0):c!==n&&b(),c.data!==n.data&&e.onChange?.(c.data),c!==n&&w()},I=e=>{const n=c,o=me(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},k(n,!1))},D=t=>{const n=c;u=t,c=d[u].core,c.data!==n.data&&e.onChange?.(c.data),c!==n&&w()},E=()=>(e={})=>{const n=e.root?t.root?.permissions:t.components[e.item?.type??e.type??""]?.permissions;return{...we,...l,...n}};let x=E();const M=B(),R={resolveCache:M,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()],[l,...s]=await Promise.all([Z(r,t,{cache:M,trigger:e,metadata:n}),...i.map(o=>Z(o,t,{cache:M,trigger:e,metadata:n}))]);C(()=>{const n=c;let r=c.data;s.forEach((e,n)=>{if(!e.didChange)return;const l=i[n].props.id,s=O(r,t,l)?.node;s&&s===O(o,t,l)?.node&&(r=V(r,t,l,e.node))}),l.didChange&&r.root===o.root&&(r={...r,root:{...r.root,props:l.node.props,readOnly:l.node.readOnly??r.root.readOnly}}),r!==c.data&&("load"===e&&c.data===a&&(a=r),c={...c,data:r,selection:me(r,t,c.selection)},k(n,!1))})},async resolveNode(e,{trigger:n="replace",metadata:o}={}){const r=O(c.data,t,e)?.node;if(!r)return!1;const i=await Z(r,t,{cache:M,trigger:n,metadata:o});if(!i.didChange)return!1;let l=!1;return C(()=>{const n=c;if(O(c.data,t,e)?.node!==r)return;const o=V(c.data,t,e,i.node);o!==c.data&&(c={...c,data:o,selection:me(o,t,c.selection)},k(n,!1),l=!0)}),l},get config(){return t},get loaded(){return a},getState(){if(h&&m===c)return h;const e=c,o={data:e.data,ui:he(e,t)},r="node"===e.selection?.kind?O(e.data,t,e.selection.id)?.node??null:null;return h={appState:o,selection:e.selection,selectedItem:r,config:t,dispatch:S,history:{back:()=>R.undo(),forward:()=>R.redo(),hasPast:u>0,hasFuture:u<d.length-1,histories:d.map(e=>({id:e.id,state:{data:e.core.data,ui:he(e.core,t)}})),index:u,setHistoryIndex:e=>{e>=0&&e<d.length&&e!==u&&D(e)}},getPermissions:x,getItemById:n=>O(e.data,t,n)?.node,getItemBySelector:n=>function(e,t,n){const[o,r]=(n.zone??"root:default-zone").split(/:(.*)/s);return A(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}},m=e,h},subscribe:e=>(f.add(e),()=>{f.delete(e)}),dispatch:S,batch:C,group:()=>{const e=u,t=d[e].id;let n=!0;return{close:()=>{if(!n)return;if(n=!1,d[e]?.id!==t)return;if(u<=e+1)return void(u===e+1&&(d=[...d.slice(0,u),{...d[u],sealed:!0},...d.slice(u+1)]));const o=d[u];d=[...d.slice(0,e+1),{...o,sealed:!0},...d.slice(u+1)],u=e+1}}},select:e=>I(e?{kind:"node",id:e}:null),selectSlot:e=>I(e?{kind:"slot",parentId:e.parentId,slot:e.slot}:null),run(e){C(()=>{const n=c,o=void 0===e.select?c.selection:e.select;c={...c,data:e.data,selection:me(e.data,t,o)},k(n,e.data!==n.data)})},load(e,n={}){const o=c,r=N(e,t);c={...c,data:r,selection:me(r,t,n.selection??c.selection)},a=r,n.keepHistory||(d=[{core:c,at:-1/0,sealed:!0,id:Se()}],u=0),c!==o&&w()},undo(){u>0&&D(u-1)},redo(){u<d.length-1&&D(u+1)},setPermissions(e){(function(e,t){if(e===t)return!0;const n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])})(e,l)||(l=e,x=E(),h=null,w())},setConfig(e){e!==t&&(t=e,x=E(),h=null,w())}};return R}function Ie(e,t,n={}){const o=e=>{if(e.altKey)return;if(!(e.metaKey!==e.ctrlKey))return;const o="KeyZ"===e.code,r="KeyY"===e.code&&!e.shiftKey;(o||r)&&(n.leaveTyping&&b(e.target)||!1!==t.getState?.().getPermissions().edit&&(e.preventDefault(),r||e.shiftKey?t.redo():t.undo()))};return e.addEventListener("keydown",o),()=>e.removeEventListener("keydown",o)}var De=U(null),Ee=U(!0);function xe({easel:e,hotkeys:t=!0,resolveOnMount:n=!0,children:o}){return q(()=>{n&&e.resolveAll()},[e,n]),q(()=>{if(t&&"undefined"!=typeof document)return Ie(document,e)},[e,t]),/* @__PURE__ */oe(De.Provider,{value:e,children:/* @__PURE__ */oe(Ee.Provider,{value:t,children:o})})}function Oe(){const e=G(De);if(!e)throw new Error("useEasel: no <EaselProvider> above this component");return e}function Me(e){const t=Oe(),n=Q({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 Ae(){return function(e){return Me(e)}}var Re=["--es-accent","--es-accent-tint","--es-accent-tint-strong","--es-accent-line","--es-accent-text","--es-accent-ring","--es-accent-shadow","--es-on-accent","--status-success-solid","--elevation-panel"],ze="host-tokens";function Pe(e,t){const n=function(e){const t=e.ownerDocument.defaultView;if(!t)return"";const n=t.getComputedStyle(e),o=[];for(const e of Re){const t=n.getPropertyValue(e).trim();t&&o.push(`${e}: ${t};`)}return o.length?`:root { ${o.join(" ")} }`:""}(e);n?k(t,ze,n):S(t,ze)}var $e="data-easel-block",Ve="data-easel-dropzone",Le={},je="data-es-mirror",Ne="undefined"==typeof window?q:ne;function Be(e,t,n){for(const e of Array.from(t.head.querySelectorAll(`[${je}]`)))e.remove();for(const o of Array.from(e.head.querySelectorAll('style, link[rel="stylesheet"]'))){const e=o.cloneNode(!0);e.setAttribute(je,""),n&&e.setAttribute("nonce",n),t.head.appendChild(e)}}function Ke({children:t,id:n="preview-frame",title:o,className:r,style:i,mirrorStyles:l=!0,onDocument:s,height:a="auto",nonce:c}){const d=g("canvas",e),u=Q(null),[p,f]=J(null);return Ne(()=>{const e=u.current,t=p?.ownerDocument.defaultView;if("auto"!==a||!e||!p||!t)return;const n=()=>{e.style.height=`${Math.ceil(p.getBoundingClientRect().height)}px`};n();const o=t.ResizeObserver,r=o?new o(n):null;return r?.observe(p),()=>r?.disconnect()},[p,a]),Ne(()=>{let e=u.current?.contentDocument;if(!e)return;"CSS1Compat"!==e.compatMode&&(e.open(),e.write("<!DOCTYPE html><html><head></head><body></body></html>"),e.close(),e=u.current?.contentDocument??e),e.body||e.documentElement.appendChild(e.createElement("body")),e.body.style.margin="0";const t=e.createElement("div");t.setAttribute("data-easel-entry",""),t.id="frame-root","fill"===a&&t.classList.add("es-frame-fill"),e.body.appendChild(t),v(e,c),f(t),s?.(e);let n=null;const o=u.current?.ownerDocument;if(l&&o){Be(o,e,c);const t=o.defaultView;t&&"MutationObserver"in t&&(n=new t.MutationObserver(()=>Be(o,e,c)),n.observe(o.head,{childList:!0,subtree:!0,characterData:!0}))}let r=null;const i=u.current;if(i&&o){Pe(i,e);const t=o.defaultView;if(t&&"MutationObserver"in t){r=new t.MutationObserver(()=>Pe(i,e)),r.observe(o.head,{childList:!0,subtree:!0,characterData:!0});const n={attributes:!0,attributeFilter:["class","style","data-theme"]};for(const e of[o.documentElement,o.body,i.closest(".es-editor")])e&&r.observe(e,n)}}return()=>{n?.disconnect(),r?.disconnect(),t.remove(),f(null),s?.(null)}},[]),/* @__PURE__ */oe("iframe",{ref:u,id:n,title:o??d.frame,className:["es-canvas-frame","fill"===a?"is-fill":"",r??""].filter(Boolean).join(" "),style:i,children:p?le(t,p):null})}var Ze=U(null),Fe=U(Le),Te=[];function He({parentId:e,slot:t,className:n,style:o,minEmptyHeight:r=128,minEmptyWidth:i=120}){const l=Oe(),s=Me(n=>A(n.appState.data,l.config,{parentId:e,slot:t})??Te),a=Me(t=>"node"===t.selection?.kind&&t.selection.id===e&&e!==M),c=Me(n=>"slot"===n.selection?.kind&&n.selection.parentId===e&&n.selection.slot===t),d=G(Ze),u=["es-zone"];return s.length&&u.push("has-children"),e===M&&u.push("is-root"),(a||c)&&u.push("is-area-selected"),null!==d&&d===e&&e!==M&&u.push("is-hovering-area"),n&&u.push(n),/* @__PURE__ */oe("div",{className:u.join(" "),[Ve]:`${e}:${t}`,style:{...o,"--min-empty-height":`${r}px`,"--min-empty-width":`${i}px`},children:s.map(e=>/* @__PURE__ */oe(Je,{node:e},e.props.id))})}function We(e,t,n,o){const r=ee(()=>{const n={};for(const o of T(H(e)))n[o]=Object.assign(function(e={}){/* @__PURE__ */
2
- return oe(He,{parentId:t,slot:o,...e})},{blockCount:0});return n},[e,t]);for(const e of Object.keys(r))r[e].blockCount=W(n[e],o);return r}function Ye(e){return ee(()=>function({zone:t,...n}){/* @__PURE__ */
3
- return oe(He,{parentId:e,slot:t,...n})},[e])}var Ue=["top","bottom","zIndex"];function qe(e,t,n){e.style[t]!==n&&(e.style[t]=n)}function Ge(e){const t=function(e){const t=e?.ownerDocument.defaultView?.getComputedStyle(e);if(!t||"sticky"!==t.position)return null;const n=e=>"auto"===e?"":e;return{top:n(t.top),bottom:n(t.bottom),zIndex:n(t.zIndex)}}(function(e){const t=e.ownerDocument.defaultView;let n=null;for(const o of Array.from(e.children))if("none"!==t?.getComputedStyle(o).display){if(n)return null;n=o}return n}(e));qe(e,"position",t?"sticky":"relative");for(const n of Ue)qe(e,n,t?.[n]??"");return!!t}var Qe="data-es-canvas-relative";function Xe(e){e.hasAttribute(Qe)&&("relative"===e.style.position&&(e.style.position=""),e.removeAttribute(Qe));const t=e.ownerDocument.defaultView?.getComputedStyle(e).position;return t&&"static"!==t?"sticky"===t:(e.style.position||(e.style.position="relative",e.setAttribute(Qe,"")),!1)}function Je({node:e}){const t=Oe().config,n=t.components[e.type],o=e.props.id,r=Q(null),i=function(e,t){return ee(()=>n=>{const o=t.current;o&&o!==n&&(o.removeAttribute($e),o.removeAttribute("data-easel-dnd")),t.current=n,n&&(n.setAttribute($e,e),n.setAttribute("data-easel-dnd",e),Xe(n))},[e,t])}(o,r),l=Q(null),s=!!n?.inline;!function(e,t){const n=Q(!1),o=Q(()=>{});o.current=()=>{const o=e(),i=n.current;n.current=!!o&&t(o),i!==n.current&&r.current()};const r=Q(()=>{});Ne(()=>o.current()),Ne(()=>{const t=e(),i=t?.ownerDocument.defaultView;if(!t||!i)return;const l=()=>o.current();i.addEventListener("resize",l);const s=i.ResizeObserver,a=s?new s(l):null;a?.observe(t);let c=null;return r.current=()=>{c?.disconnect(),c=null;const e=t.ownerDocument.documentElement;n.current&&e&&i.MutationObserver&&(c=new i.MutationObserver(l),c.observe(e,{attributes:!0}))},r.current(),()=>{i.removeEventListener("resize",l),a?.disconnect(),c?.disconnect(),r.current=()=>{}}},[])}(()=>s?r.current:l.current,e=>s?Xe(e):Ge(e));const a=G(Fe),c=We(n,o,e.props,t.components),d=Ye(o);if(!n?.render)return null;const u=n.render,p={...Y(n),...e.props,...c},f={renderDropZone:d,isEditing:!0,dragRef:n.inline?i:null,metadata:{...a,...n.metadata}};return n.inline?/* @__PURE__ */oe(u,{...p,editor:f,editMode:!0}):
4
- /* @__PURE__ */oe("div",{ref:l,[$e]:o,"data-easel-dnd":o,style:{position:"relative"},children:/* @__PURE__ */oe(u,{...p,editor:f,editMode:!0})})}function _e({metadata:e}){const t=Me(e=>e.config),n=Me(e=>e.appState.data.root).props??{},o=t.root?.render,r=We(t.root,M,n,t.components),i=Ye(M),l=/* @__PURE__ */oe(He,{parentId:M,slot:F}),s=o?/* @__PURE__ */oe(o,{id:"page-root",...n,...r,editor:{renderDropZone:i,isEditing:!0,dragRef:null,metadata:e??{}},editMode:!0,children:l}):l;/* @__PURE__ */
5
- return oe(Fe.Provider,{value:e??Le,children:s})}var et=U(void 0),tt=U(void 0);function nt(e,t,n,o){const r=O(e,t,n);return!!r&&(K(r.node,t).length>0||!1===o.whole)}var ot=U(void 0);function rt({element:e}){const t=Q(null),n=st(t,e?()=>e:null,e);/* @__PURE__ */
6
- return oe("div",{ref:t,"aria-hidden":"true",className:"es-canvas-outline is-hover is-hover-part",style:n?{position:"absolute",top:n.top,left:n.left,width:n.width,height:n.height}:{display:"none"}})}var it={"--es-words-clear":`${C}px`};function lt({element:e,words:t=!1}){const n=Q(null),o=st(n,e?()=>e:null,e);/* @__PURE__ */
7
- return oe("div",{ref:n,"aria-hidden":"true",className:"es-canvas-outline is-selected is-selected-part"+(t?" is-words":""),style:o?{position:"absolute",top:o.top,left:o.left,width:o.width,height:o.height,...it}:{display:"none"}})}function st(e,t,n){return ct(e,t?e=>{const n=t(e);return n?[n]:[]}:null,n)[0]??null}var at=[];function ct(e,t,n){const[o,r]=J(at),i=Q(t);return i.current=t,Ne(()=>{const t=e.current?.ownerDocument,n=t?.defaultView;if(!t||!n||!i.current)return void r(at);let o=0;const l=()=>{o=0;const n=e.current?.parentElement??null,l=(i.current?i.current(t):[]).map(e=>function(e,t){if(!e||!t)return null;const n=E(e),o=t.getBoundingClientRect();return{top:n.top-o.top,left:n.left-o.left,width:n.width,height:n.height}}(e,n)).filter(e=>null!==e);r(e=>{return(t=e)===(n=l)||t.length===n.length&&t.every((e,t)=>function(e,t){return e===t||!!e&&!!t&&e.top===t.top&&e.left===t.left&&e.width===t.width&&e.height===t.height}(e,n[t]))?e:l.length?l:at;var t,n})},s=()=>{o||(o=(n.requestAnimationFrame??(e=>n.setTimeout(e,16)))(l))};l();const a="MutationObserver"in n?new n.MutationObserver(s):null;a?.observe(t.body,{childList:!0,subtree:!0,attributes:!0,characterData:!0});const c="ResizeObserver"in n?new n.ResizeObserver(s):null;return c?.observe(t.documentElement),n.addEventListener("resize",s),()=>{a?.disconnect(),c?.disconnect(),n.removeEventListener("resize",s),o&&(n.cancelAnimationFrame??n.clearTimeout)(o)}},[n]),o}function dt({id:e,kind:t,overlay:n}){const o=Q(null),r=G(tt),i=null!==e&&!0===r?.(e),l=ct(o,e?t=>x(t,`[${$e}="${t.defaultView?.CSS?.escape?t.defaultView.CSS.escape(e):e}"]`):null,e),[s,...a]=l,c=`es-canvas-outline is-${t}${i?" is-shared":""}`,d=e=>({position:"absolute",top:e.top,left:e.left,width:e.width,height:e.height}),u=/* @__PURE__ */re(ie,{children:[
8
- /* @__PURE__ */oe("div",{ref:o,"aria-hidden":"true",className:c,style:s?d(s):{display:"none"}}),a.map((e,t)=>/* @__PURE__ */oe("div",{"aria-hidden":"true",className:c,style:d(e)},t))]});return n&&e?/* @__PURE__ */oe(n,{componentId:e,kind:t,children:u}):u}function ut(e,t,n){const o=h(e,n),r=o.text.length,i=e.ownerDocument;if(!t)return[r,r];let l=null;const s=i.caretPositionFromPoint?.(t.x,t.y);if(s&&e.contains(s.offsetNode))l=o.at(s.offsetNode,s.offset);else{const n=i.caretRangeFromPoint?.(t.x,t.y);n&&e.contains(n.startContainer)&&(l=o.at(n.startContainer,n.startOffset))}if(null===l)return[r,r];const a=o.text;let c=l,d=l;for(;c>0&&!/\s/.test(a[c-1]);)c-=1;for(;d<a.length&&!/\s/.test(a[d]);)d+=1;return[c,d]}function pt({s:e,element:t,toolbar:n,label:o,keys:r}){const i=g("copy",m),l=e.pressed(),s=new Set(n.offered),f=n.colors&&n.colors.length>0?n.colors:null,h=Q(null),[v,y]=J(!1),[w,b]=J(null),k=v||null!==w,S=()=>{e.hold(),y(!1),b({href:e.pressed().href})},C=()=>{y(!1),b(null),e.resume()};ne(()=>{r.current={escape:()=>!!k&&(C(),!0),link:()=>!!s.has("link")&&(S(),!0)}}),ne(()=>()=>{r.current=null},[r]);const D=Q(C);D.current=C,q(()=>{if(v)return se(e=>{const t=h.current;return!!("Escape"===e.key&&t&&e.target instanceof Node&&t.contains(e.target))&&(D.current(),!0)},()=>h.current?.querySelector(".es-copy-colors"))},[v]),q(()=>{const n=h.current;if(!k||!n)return;const o=/* @__PURE__ */new Set([n.ownerDocument]),r=t();r&&o.add(r.ownerDocument);const i=o=>{const r=o.target;if(r&&n.contains(r))return;y(!1),b(null);const i=t();r&&i&&i.contains(r)?e.release():e.stop("outside")};for(const e of o)e.addEventListener("pointerdown",i,!0);return()=>{for(const e of o)e.removeEventListener("pointerdown",i,!0)}},[k,e,t]),ne(()=>{const e=h.current,n=e?.querySelector(".rosh-tb-wrap > .es-copy-pop"),o=t();if(!(k&&e&&n&&o))return;const r=o.ownerDocument.defaultView?.getSelection()??null,i=r&&r.rangeCount>0&&o.contains(r.getRangeAt(0).startContainer)?r.getRangeAt(0):null,l=(i?a(i,o):null)??(()=>{const e=o.getBoundingClientRect();return{left:e.left,top:e.top,right:e.right,bottom:e.bottom}})(),s=o.ownerDocument.defaultView?.frameElement,u=s?I(s,{left:l.left,top:l.top,width:l.right-l.left,height:l.bottom-l.top}):{left:l.left,top:l.top,width:l.right-l.left,height:l.bottom-l.top},p=o.getBoundingClientRect(),f=s?I(s,{left:p.left,top:p.top,width:p.width,height:p.height}):{left:p.left,top:p.top,width:p.width,height:p.height},m=(e.closest("[data-floating-bar]")??e).getBoundingClientRect(),g={left:u.left,right:u.left+u.width,top:Math.min(u.top,f.top-6,m.top),bottom:Math.max(u.top+u.height,f.top+f.height+6,m.bottom)},v=e.ownerDocument.documentElement,y=(s??o.closest(".es-canvas")??o).getBoundingClientRect(),w={left:Math.max(0,y.left),top:Math.max(0,y.top),right:Math.min(v.clientWidth||y.right,y.right),bottom:Math.min(v.clientHeight||y.bottom,y.bottom)};if(w.right<=w.left||w.bottom<=w.top||0===n.offsetWidth)return;const b=c({anchor:g,size:{width:n.offsetWidth,height:n.offsetHeight},within:{left:y.left,top:y.top,right:y.right,bottom:y.bottom},clip:w,parent:d(n)});n.style.top=`${b.top}px`,n.style.left=`${b.left}px`,n.style.setProperty("--es-pop-point",`${b.point}px`),n.dataset.side=b.above?"above":"below"});const E=f?{run:u(l.color,f),open:v,onToggle:()=>{b(null),v?C():(e.hold(),y(!0))}}:void 0;/* @__PURE__ */
9
- return oe(ae,{anchor:()=>{const e=t();if(!e)return null;const n=e.getBoundingClientRect(),o=e.ownerDocument.defaultView?.frameElement,r=o?I(o,{left:n.left,top:n.top,width:n.width,height:n.height}):{left:n.left,top:n.top,width:n.width,height:n.height};return{left:r.left-6,top:r.top-6,right:r.left+r.width+6,bottom:r.top+r.height+6}},bounds:()=>{const e=t(),n=e?.ownerDocument.defaultView?.frameElement,o=(n??e?.closest(".es-canvas")??e)?.getBoundingClientRect();return o?{left:o.left,top:o.top,right:o.right,bottom:o.bottom}:{left:0,top:0,right:window.innerWidth,bottom:window.innerHeight}},"aria-label":o,children:/* @__PURE__ */oe("div",{ref:h,children:/* @__PURE__ */oe(ce,{layout:"row",offered:s,pressed:l.marks,onMark:t=>{"link"===t?S():e.press(t)},color:E,linkOpen:null!==w,list:{pressed:l.list,onList:t=>e.list(t)},clear:l.clearable?{onClear:()=>e.clear()}:void 0,alignment:n.alignment,letterCase:n.letterCase,last:n.lastTool?.({className:"rosh-tb-btn",disabled:!1,selected:l.selected,keepCaret:t=>{t.preventDefault(),e.hold()},insert:t=>e.insert(t)}),windows:/* @__PURE__ */re(ie,{children:[v&&f?/* @__PURE__ */oe(p,{colors:f,current:l.color,words:i.colors??m.colors,onPick:t=>e.color(t)}):null,w?
10
- /* @__PURE__ */oe(de,{className:"es-copy-link es-copy-pop",value:w.href??"",onApply:t=>{b(null),e.link(t)},onRemove:null!==w.href?()=>{b(null),e.link(null)}:void 0,onCancel:C}):null]})})})})}function ft({element:e,which:t}){const n=Q(null),o=st(n,()=>e(),t);/* @__PURE__ */
11
- return oe("div",{ref:n,"aria-hidden":"true",className:"es-canvas-outline is-typing",style:o?{position:"absolute",top:o.top,left:o.left,width:o.width,height:o.height,...it}:{display:"none"}})}function ht({frame:t=!0,className:n,style:o,metadata:r,mirrorStyles:a,onDocument:c,height:d,title:u,nonce:p,hotkeys:h,frameWrapper:m,overlay:v,children:b,typing:k,passThrough:S}){const C=Oe(),I=G(et),E=S??I,x=G(Ee),M=g("canvas",e),A=h??x,[R,z]=J(void 0),P=Me(e=>"node"===e.selection?.kind?e.selection.id:null),[$,V]=J(null),[L,j]=J(null),N=G(ot),[,B]=_(e=>e+1,0),Z=e=>{N?.select(e),B()},[F,T]=J(null),H=Q(null),[,W]=J(0),Y=Q(k);Y.current=k;const U=Q(null),X=Q(null),ee=()=>{if(!P)return null;const e=Y.current?.atSelection?.()?.element()??null;if(!e)return null;const t=X.current?.ownerDocument;if(N){const n=N.selected()&&t?N.selectedPart?.(t)??null:null;return n&&w(n.element,e)?n.element:null}const n=O(C.getState().appState.data,C.config,P);return n&&0===K(n.node,C.config).length?e:null},te=Me(e=>e.appState.data),ne=N?.selected()??null;q(()=>{const e=X.current?.ownerDocument,t=e?.defaultView?.CustomEvent;if(!e||!t)return;const n=P&&!F&&Y.current?.atSelection?.()?P:null,o=n?ee():null;e.dispatchEvent(new t(y,{detail:o?{id:n,words:o}:{id:n}}))},[P,F,te,ne]);const ie=e=>{const t=X.current?.ownerDocument,n=t?.defaultView?.CustomEvent;t&&n&&t.dispatchEvent(new n(D,{detail:{typing:e}}))},le=(e,t)=>{H.current?.s.stop("stop");const n=e.element();if(!n)return!1;const o=C.group(),r=e.element,i=f({element:r,value:e.value,rules:e.rules,multiline:e.multiline,skip:e.skip,caret:ut(n,t,e.skip),write:e.write,remount:e.remount,onSelect:()=>W(e=>e+1),onEscape:()=>U.current?.escape()??!1,onLinkKey:()=>U.current?.link()??!1,end:e=>{o.close(),H.current?.element===r&&(H.current=null),T(null),ie(!1),Y.current?.onChange?.({typing:!1,why:e})}});if(!i)return o.close(),!1;const l=n.closest?.(`[${$e}]`)?.getAttribute($e);return l&&C.select(l),H.current={s:i,element:r,target:e},T(()=>r),V(null),ie(!0),Y.current?.onChange?.({typing:!0,element:n}),!0};q(()=>()=>H.current?.s.stop("stop"),[]);const se=e=>{const t=H.current?.element();return Boolean(t&&t.contains(e))},ae=(e,t)=>nt(C.getState().appState.data,C.config,e,t),ce=e=>{const t=e.closest?.(`[${$e}]`)?.getAttribute($e);if(!t)return;const n=C.getState(),o="node"===n.selection?.kind?n.selection.id:null,r=N?.partAt(e,t)??null;if(r){const e=l(n.appState.data,C.config,t,r.id,o,N?.selected()??null,E);if(e)return{node:e.node,part:e.part?r:null}}return{node:s(n.appState.data,C.config,t,o,E)??t,part:null}},de=e=>{if("Enter"!==e.key||e.defaultPrevented||e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)return;if(H.current)return;const t=e.target;if(t?.isContentEditable||t?.closest?.("input, textarea, select, button"))return;const n=Y.current?.atSelection?.();n&&le(n,null)&&e.preventDefault()},ue=X.current?.ownerDocument??null,pe=N?.selected()&&ue&&P?N.selectedPart?.(ue)??null:null,fe=pe&&P&&ae(P,pe)?pe.element:null,he=F?null:ee(),me=/* @__PURE__ */re("div",{ref:X,className:"es-canvas-content",style:{position:"relative"},onClick:e=>{const t=e.target;if(t.closest?.("a[href]")&&e.preventDefault(),H.current){if(se(t))return;H.current.s.stop("outside")}const n=t.ownerDocument?.getSelection?.();n&&n.rangeCount>0&&n.isCollapsed&&n.removeAllRanges();const o=ce(t);if(void 0!==o)return C.select(o.node),void(N&&(o.part?.id??null)!==N.selected()&&Z(o.part?.id??null));t.hasAttribute?.(Ve)||(C.select(null),N?.selected()&&Z(null))},onDoubleClick:e=>{const t=Y.current;if(!t||se(e.target))return;const n=t.at(e.target);n&&le(n,{x:e.clientX,y:e.clientY})&&e.preventDefault()},onKeyDown:e=>de(e),onMouseOver:e=>{if(H.current)return;const t=ce(e.target),n=!!t?.part&&ae(t.node,t.part),o=t?.part&&n&&t.part.id!==N?.selected()?t.part:null,r=!t||t.part&&n?null:t.node;r!==$&&V(r),o?.id===L?.id&&o?.element===L?.element||j(o)},onMouseLeave:()=>{V(null),j(null)},children:[
12
- /* @__PURE__ */oe(Ze.Provider,{value:$,children:/* @__PURE__ */oe(_e,{metadata:r})}),
13
- /* @__PURE__ */re("div",{className:"es-canvas-outlines",style:{position:"absolute",top:0,left:0,pointerEvents:"none"},children:[
14
- /* @__PURE__ */oe(dt,{id:!F&&$&&$!==P?$:null,kind:"hover",overlay:v}),N?/* @__PURE__ */oe(rt,{element:F||!L||L.id===N.selected()?null:L.element}):null,he||fe?/* @__PURE__ */oe(lt,{element:F?null:he??fe,words:null!==he}):null,
15
- /* @__PURE__ */oe(dt,{id:F||fe||he?null:P,kind:"selected",overlay:v}),F?/* @__PURE__ */oe(ft,{element:()=>{const e=F?.()??null;return e?pe&&w(pe.element,e)?pe.element:e:null},which:pe?.element??F}):null]}),b]}),ge=m?/* @__PURE__ */oe(m,{document:R,children:me}):me;q(()=>{if(R&&A)return Ie(R,C)},[R,A,C]),q(()=>{if(!R)return;const e=e=>{if("Enter"===e.key)return void de(e);if("Escape"!==e.key||e.defaultPrevented)return;const t=e.target;if(t?.isContentEditable||t?.closest?.("input, textarea, select"))return;const n=C.getState();if("node"!==n.selection?.kind)return;if(N?.selected())return void Z(null);const o=i(n.appState.data,C.config,n.selection);"node"===o?.kind&&C.select(o.id)};return R.addEventListener("keydown",e),()=>R.removeEventListener("keydown",e)},[R,C,N]);/* @__PURE__ */
16
- return re("div",{className:"es-canvas"+(n?` ${n}`:""),style:o,"data-easel-preview":"","data-es-typing":F?"":void 0,children:[F&&H.current?.target.toolbar?/* @__PURE__ */oe(pt,{s:H.current.s,element:H.current.element,toolbar:H.current.target.toolbar,label:M.textTools,keys:U}):null,t?/* @__PURE__ */oe(Ke,{mirrorStyles:a,onDocument:e=>{z(e??void 0),c?.(e)},height:d,title:u,nonce:p,children:ge}):/* @__PURE__ */oe("div",{id:"preview-frame","data-easel-entry":"",children:ge})]})}function mt(e={}){const t=Oe(),n=Me(e=>e.appState.data);return r({...e,data:n,config:t.config,commit:(e,{select:n})=>t.run({data:e,select:n})})}function gt(){return yt(Me(e=>e.selectedItem))}function vt(){return yt(null)}function yt(e){const n=Oe(),o=Me(e=>e.config),r=n.resolveCache,i=Me(e=>e.appState.data.root),l=e?e.props.id:"root",s=i.props??{},a=ee(()=>e||{type:"root",props:s},[e,s]),c=e?o.components[e.type]:o.root,d=n.getState(),u=e?O(d.appState.data,o,l):null,p=u&&"root"!==u.place.parentId?u.place.parentId:null,f=p?d.getItemById(p)??null:null,{fields:h}=t({id:l,node:a,block:c,parent:f,appState:d.appState}),m=Me(t=>!1===t.getPermissions(e?{item:e}:{root:!0}).edit),g=te(e=>{(async()=>{const t=n.getState();if("root"!==l){const i=t.getItemById(l),s=t.getSelectorForId(l);if(!i||!s)return;const a={...i,props:{...i.props,...e}},{node:c}=await Z(a,o,{cache:r,trigger:"replace"}),d=n.getState().getSelectorForId(l);if(!d)return;return void n.dispatch({type:"replace",destinationZone:d.zone??"root:default-zone",destinationIndex:d.index,data:c})}const i=t.appState.data.root.props??{},{node:s}=await Z({type:"root",props:{...i,...e}},o,{cache:r,trigger:"replace"});n.dispatch({type:"replaceRoot",root:{props:s.props,readOnly:s.readOnly},recordHistory:!0})})()},[n,o,r,l]),v=te((e,t)=>g({[e]:t}),[g]);return{id:l,node:a,fields:h,values:a.props,readOnly:m,onChange:v,onChangeMany:g}}export{Ke as CanvasFrame,ot as CanvasPartsContext,et as CanvasPassThroughContext,tt as CanvasSharedContext,be as DEFAULT_UI,ht as EaselCanvas,xe as EaselProvider,_e as EditDocument,Ie as bindUndoKeys,Ce as createEasel,Ae as createUseEasel,nt as partHasOwnBox,ue as recordsByDefault,ve as reduce,he as uiView,Me as useEasel,Oe as useEaselApi,mt as useEaselNodeOps,vt as useRootFields,gt as useSelectedFields,me as validSelection};