text: import e,{createContext as t,useContext as n,useMemo as r,useState as o,useEffect as a,useRef as d,Fragment as i,Children as s}from"react";import{defineEventListener as u,Handlers as c,useCollector as l,RenderIndicator as f,getDOMInfo as p,deprecationWarning as v,useEffectOnce as m,ERROR_TOP_LEVEL_ELEMENT_NO_ID as h,ROOT_NODE as y,ERROR_DELETE_TOP_LEVEL_NODE as g,ERROR_INVALID_NODEID as N,ERROR_NOPARENT as E,DEPRECATED_ROOT_NODE as b,ERROR_MOVE_TOP_LEVEL_NODE as O,ERROR_MOVE_NONCANVAS_CHILD as C,ERROR_CANNOT_DRAG as k,ERROR_MOVE_TO_NONCANVAS_PARENT as T,ERROR_MOVE_INCOMING_PARENT as P,ERROR_MOVE_CANNOT_DROP as j,ERROR_MOVE_TO_DESCENDANT as w,ERROR_DUPLICATE_NODEID as x,ERROR_MOVE_OUTGOING_PARENT as I,ERROR_INVALID_NODE_ID as D,ERROR_NOT_IN_RESOLVER as q,useMethods as L}from"@craftjs/utils";export{ROOT_NODE}from"@craftjs/utils";import R from"tiny-invariant";import{produce as S}from"immer";import z from"shortid";
  /*! *****************************************************************************
  Copyright (c) Microsoft Corporation.
  
  Permission to use, copy, modify, and/or distribute this software for any
  purpose with or without fee is hereby granted.
  
  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  PERFORMANCE OF THIS SOFTWARE.
  ***************************************************************************** */var _=function(e,t){return(_=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function A(e,t){function n(){this.constructor=e}_(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var F=function(){return(F=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function M(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function H(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var a=arguments[t],d=0,i=a.length;d<i;d++,o++)r[o]=a[d];return r}var W=t(null),J=function(){return n(W)},B=function(e){var t=e.target.cloneNode(!0),n=e.target.getBoundingClientRect(),r=n.height;return t.style.width=n.width+"px",t.style.height=r+"px",t.style.position="fixed",t.style.left="-100%",t.style.top="-100%",document.body.appendChild(t),e.dataTransfer.setDragImage(t,0,0),t},V=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return A(t,e),t.prototype.handlers=function(){var e=this;return{select:{init:function(){return function(){return e.store.actions.setNodeEvent("selected",null)}},events:[u("mousedown",(function(t,n){t.craft.stopPropagation(),e.store.actions.setNodeEvent("selected",n)}))]},hover:{init:function(){return function(){return e.store.actions.setNodeEvent("hovered",null)}},events:[u("mouseover",(function(t,n){t.craft.stopPropagation(),e.store.actions.setNodeEvent("hovered",n)}))]},drop:{events:[u("dragover",(function(e){e.craft.stopPropagation(),e.preventDefault()})),u("dragenter",(function(n,r){n.craft.stopPropagation(),n.preventDefault();var o=t.draggedElement;if(o){var a=e.store.query.getDropPlaceholder(o.rootNodeId?o.nodes[o.rootNodeId]:o,r,{x:n.clientX,y:n.clientY});a&&(e.store.actions.setIndicator(a),t.events={indicator:a})}}))]},drag:{init:function(t,n){return e.store.query.node(n).isDraggable()?(t.setAttribute("draggable","true"),function(){return t.setAttribute("draggable","false")}):function(){}},events:[u("dragstart",(function(n,r){n.craft.stopPropagation(),e.store.actions.setNodeEvent("dragged",r),t.draggedElementShadow=B(n),t.draggedElement=r})),u("dragend",(function(t){t.craft.stopPropagation(),e.dropElement((function(t,n){return e.store.actions.move(t,n.parent.id,n.index+("after"===n.where?1:0))}))}))]},create:{init:function(e){return e.setAttribute("draggable","true"),function(){return e.removeAttribute("draggable")}},events:[u("dragstart",(function(n,r){n.craft.stopPropagation();var o=e.store.query.parseReactElement(r).toNodeTree();t.draggedElementShadow=B(n),t.draggedElement=o})),u("dragend",(function(t){t.craft.stopPropagation(),e.dropElement((function(t,n){e.store.actions.addNodeTree(t,n.parent.id,n.index+("after"===n.where?1:0))}))}))]}}},t.prototype.dropElement=function(e){var n=t.draggedElement,r=t.draggedElementShadow,o=t.events;n&&o.indicator&&!o.indicator.error&&e(n,o.indicator.placement),r&&(r.parentNode.removeChild(r),t.draggedElementShadow=null),t.draggedElement=null,t.events.indicator=null,this.store.actions.setIndicator(null),this.store.actions.setNodeEvent("dragged",null)},t.prototype.derive=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return new(e.bind.apply(e,H([void 0,this.store,this],t)))},t.events={indicator:null},t}(c),X=function(e){function t(t,n){var r=e.call(this,t)||this;return r.derived=n,r}return A(t,e),t}(c),Y=t({});function G(e){var t=J(),o=n(Y),a=l(o,e),d=r((function(){return t&&t.connectors()}),[t]);return F(F({},a),{connectors:d||{},inContext:!!o,store:o})}var K=function(t){var n,o,a,d,i,s,u,c,l=t.children,v=G((function(e){return{events:e.events,indicator:e.options.indicator}})),m=v.events,h=v.indicator,y=v.store,g=r((function(){return new V(y)}),[y]);return e.createElement(W.Provider,{value:g},m.indicator&&e.createElement(f,{style:F(F({},(n=m.indicator.placement,o=p(m.indicator.placement.parent.dom),a=m.indicator.placement.currentNode&&p(m.indicator.placement.currentNode.dom),d=0,i=0,s=0,u=0,c=n.where,a?a.inFlow?(s=a.outerWidth,u=2,d="before"===c?a.top:a.bottom,i=a.left):(s=2,u=a.outerHeight,d=a.top,i="before"===c?a.left:a.left+a.outerWidth):o&&(d=o.top+o.padding.top,i=o.left,s=o.outerWidth,u=2),{top:d+"px",left:i+"px",width:s+"px",height:u+"px"})),{backgroundColor:m.indicator.error?h.error:h.success,transition:"0.2s ease-in"})}),l)},Q=function(e){function t(t,n,r){var o=e.call(this,t,n)||this;return o.id=r,o}return A(t,e),t.prototype.handlers=function(){var e=this,t=this.derived.connectors();return{connect:{init:function(n){t.select(n,e.id),t.hover(n,e.id),t.drop(n,e.id),e.store.actions.setDOM(e.id,n)}},drag:{init:function(n){t.drag(n,e.id)}}}},t}(X),U=e.createContext(null),Z=function(t){var n=t.id,o=t.related,a=void 0!==o&&o,d=t.children,i=J(),s=G((function(e){return{hydrationTimestamp:e.nodes[n]&&e.nodes[n]._hydrationTimestamp}})).hydrationTimestamp,u=r((function(){return i.derive(Q,n).connectors()}),[i,s,n]);return e.createElement(U.Provider,{value:{id:n,related:a,connectors:u}},d)};function $(e){var t=n(U),o=t.id,a=t.related,d=t.connectors,i=G((function(t){return o&&t.nodes[o]&&e&&e(t.nodes[o])})),s=i.actions,u=M(i,["actions","query"]),c=r((function(){return{setProp:function(e){return s.setProp(o,e)},setCustom:function(e){return s.setCustom(o,e)},setHidden:function(e){return s.setHidden(o,e)}}}),[s,o]);return F(F({},u),{id:o,related:a,inNodeContext:!!t,actions:c,connectors:d})}function ee(e){var t=$(e),n=t.id,r=t.related,o=t.actions,a=t.inNodeContext,d=t.connectors,i=M(t,["id","related","actions","inNodeContext","connectors"]);return F(F({},i),{actions:o,id:n,related:r,setProp:function(e){return v("useNode().setProp()",{suggest:"useNode().actions.setProp()"}),o.setProp(e)},inNodeContext:a,connectors:d})}var te=function(t){var n=t.render,r=ee().connectors;return"string"==typeof n.type?(0,r.connect)((0,r.drag)(e.cloneElement(n))):n},ne=function(){var t=$((function(e){return{type:e.data.type,props:e.data.props,nodes:e.data.nodes,hydrationTimestamp:e._hydrationTimestamp}})),n=t.type,o=t.props,a=t.nodes;return r((function(){var t=e.createElement(n,o,e.createElement(e.Fragment,null,a?a.map((function(t){return e.createElement(oe,{id:t,key:t})})):o&&o.children));return"string"==typeof n?e.createElement(te,{render:t}):t}),[n,o,t.hydrationTimestamp,a])},re=function(){var t=$((function(e){return{hidden:e.data.hidden}})).hidden,n=G((function(e){return{onRender:e.options.onRender}})).onRender;return t?null:e.createElement(n,{render:e.createElement(ne,null)})},oe=e.memo((function(t){return e.createElement(Z,{id:t.id},e.createElement(re,null))})),ae={is:"div",canvas:!1,custom:{},hidden:!1},de={is:"type",canvas:"isCanvas"};function ie(t){var n=t.id,r=t.children,a=M(t,["id","children"]),d=F(F({},ae),a),i=d.is,s=M(d,["is","custom","canvas"]),u=G(),c=u.query,l=u.actions,f=$((function(e){return{node:{id:e.id,data:e.data}}})),p=f.node,v=f.inNodeContext,y=o(null),g=y[0],N=y[1];return m((function(){R(!!n,h);var t=p.id,o=p.data;if(v){var d,u=o.linkedNodes&&o.linkedNodes[n]&&c.node(o.linkedNodes[n]).get();if(u&&u.data.type===i){d=u.id;var f=F(F({},u.data.props),s);l.setProp(d,(function(e){return Object.keys(f).forEach((function(t){return e[t]=f[t]}))}))}else{var m=e.createElement(ie,a,r),y=c.parseReactElement(m).toNodeTree();d=y.rootNodeId,l.addLinkedNodeFromTree(y,t,n)}N(d)}})),g?e.createElement(oe,{id:g}):null}var se=function(){return v("<Canvas />",{suggest:"<Element canvas={true} />"})};function Canvas(t){var n=M(t,[]);return a((function(){return se()}),[]),e.createElement(ie,F({},n,{canvas:!0}))}var ue=function(t){var n=t.children,r=t.json,i=t.data,s=G(),u=s.actions,c=s.query,l=o(null),f=l[0],p=l[1];r&&v("<Frame json={...} />",{suggest:"<Frame data={...} />"});var m=d({initialChildren:n,initialData:i||r});return a((function(){var t=m.current,n=t.initialChildren,r=t.initialData;if(r)(0,u.deserialize)(r);else if(n){var o=e.Children.only(n),a=c.parseReactElement(o).toNodeTree((function(e,t){return t===o&&(e.id=y),e}));u.addNodeTree(a)}p(e.createElement(oe,{id:y}))}),[u,c]),f};function ce(e){var t=G(e),n=t.connectors,o=t.actions,a=o.setNodeEvent,d=M(o,["addLinkedNodeFromTree","setDOM","setNodeEvent","replaceNodes","reset"]),i=M(t.query,["deserialize"]),s=M(t,["connectors","actions","query","store"]),u=r((function(){return F(F({},d),{selectNode:function(e){a("selected",e),a("hovered",null)}})}),[d,a]);return F({connectors:n,actions:u,query:i},s)}function le(t){return function(n){return function(r){var o=t?ce(t):ce();return e.createElement(n,F({},o,r))}}}function fe(t){return function(n){return function(r){var o=ee(t);return e.createElement(n,F({},o,r))}}}var pe=function(e){return Object.fromEntries?Object.fromEntries(e):e.reduce((function(e,t){var n,r=t[0],o=t[1];return F(F({},e),((n={})[r]=o,n))}),{})},ve=function(e,t){var n=function(t,n,r){var a=o(n);a.data.nodes||(a.data.nodes=[]),a.data.props.children&&delete a.data.props.children,null!=r?a.data.nodes.splice(r,0,t.id):a.data.nodes.push(t.id),t.data.parent=a.id,e.nodes[t.id]=t},r=function(t,o,a){var d=t.nodes[t.rootNodeId];if(null!=o&&n(d,o,a),d.data.nodes){var i=H(d.data.nodes);d.data.nodes=[],i.forEach((function(e,n){return r({rootNodeId:e,nodes:t.nodes},d.id,n)}))}d.data.linkedNodes&&Object.keys(d.data.linkedNodes).forEach((function(n){var o=d.data.linkedNodes[n];e.nodes[o]=t.nodes[o],r({rootNodeId:o,nodes:t.nodes})}))},o=function(t){R(t,E);var n=e.nodes[t];return R(n,N),n},a=function(t,n){void 0===n&&(n=!1);var r=e.nodes[t],o=e.nodes[r.data.parent];if(r.data.nodes&&H(r.data.nodes).forEach((function(e){return a(e)})),n&&o.data.linkedNodes){var d=Object.keys(o.data.linkedNodes).filter((function(e){return o.data.linkedNodes[e]===e}))[0];d&&delete o.data.linkedNodes[d]}else{var i=o.data.nodes;i.splice(i.indexOf(t),1)}!function(e,t,n){Object.keys(e.events).forEach((function(n){e.events[n]&&e.events[n]===t&&(e.events[n]=null)}))}(e,t),delete e.nodes[t]};return{addLinkedNodeFromTree:function(t,n,d){var i=o(n);i.data.linkedNodes||(i.data.linkedNodes={});var s=i.data.linkedNodes[d];s&&a(s,!0),i.data.linkedNodes[d]=t.rootNodeId,t.nodes[t.rootNodeId].data.parent=n,e.nodes[t.rootNodeId]=t.nodes[t.rootNodeId],r(t)},add:function(e,t,r){var o=[e];Array.isArray(e)&&(v("actions.add(node: Node[])",{suggest:"actions.add(node: Node)"}),o=e),o.forEach((function(e){n(e,t,r)}))},addNodeTree:function(t,n,o){var a=t.nodes[t.rootNodeId];n||(R(t.rootNodeId===y,"Cannot add non-root Node without a parent"),e.nodes[t.rootNodeId]=a),r(t,n,o)},delete:function(n){e.nodes[n]&&(R(!t.node(n).isTopLevelNode(),g),a(n))},deserialize:function(e){var n="string"==typeof e?JSON.parse(e):e,r=Object.keys(n).map((function(e){var r=e;return e===b&&(r=y),[r,t.parseSerializedNode(n[e]).toNode((function(e){return e.id=r}))]}));this.replaceNodes(pe(r))},move:function(n,r,o){var a=e.nodes[n],d=a.data.parent,i=e.nodes[r],s=i.data.nodes;t.node(r).isDroppable(a,(function(e){throw new Error(e)}));var u=e.nodes[d].data.nodes;u[u.indexOf(n)]="marked",s?s.splice(o,0,n):i.data.nodes=[n],e.nodes[n].data.parent=r,e.nodes[n].data.index=o,u.splice(u.indexOf("marked"),1)},replaceNodes:function(t){e.nodes=t,this.clearEvents()},clearEvents:function(){e.events=Pe.events},reset:function(){this.replaceNodes({}),this.clearEvents()},setOptions:function(t){t(e.options)},setNodeEvent:function(t,n){var r=e.events[t];r&&n!==r&&(e.nodes[r].events[t]=!1),n?(e.nodes[n].events[t]=!0,e.events[t]=n):e.events[t]=null},setCustom:function(t,n){n(e.nodes[t].data.custom)},setDOM:function(t,n){R(e.nodes[t],N),e.nodes[t].dom=n},setIndicator:function(t){t&&(!t.placement.parent.dom||t.placement.currentNode&&!t.placement.currentNode.dom)||(e.events.indicator=t)},setHidden:function(t,n){e.nodes[t].data.hidden=n},setProp:function(t,n){R(e.nodes[t],N),n(e.nodes[t].data.props)}}},me=z;function he(t,n){var r=t.data.type,o=t.id||me();return S({},(function(a){if(a.id=o,a._hydrationTimestamp=Date.now(),a.data=F({type:r,props:F({},t.data.props),name:"string"==typeof r?r:r.name,displayName:"string"==typeof r?r:r.name,custom:{},isCanvas:!1,hidden:!1},t.data),a.related={},a.events={selected:!1,dragged:!1,hovered:!1},a.rules=F({canDrag:function(){return!0},canDrop:function(){return!0},canMoveIn:function(){return!0},canMoveOut:function(){return!0}},r.craft&&r.craft.rules||{}),a.data.type===ie||a.data.type===Canvas){var d=a.data.type===Canvas,i=F(F({},ae),a.data.props);Object.keys(ae).forEach((function(e){a.data[de[e]||e]=i[e],delete a.data.props[e]})),r=a.data.type,d&&(a.data.isCanvas=!0,se())}if(n&&n(a),r.craft){a.data.props=F(F({},r.craft.props||r.craft.defaultProps||{}),a.data.props);var s=r.craft.displayName||r.craft.name;if(s&&(a.data.displayName=s),r.craft.isCanvas&&(a.data.isCanvas=a.data.isCanvas||r.craft.isCanvas),r.craft.rules&&Object.keys(r.craft.rules).forEach((function(e){["canDrag","canDrop","canMoveIn","canMoveOut"].includes(e)&&(a.rules[e]=r.craft.rules[e])})),r.craft.custom&&(a.data.custom=F(F({},r.craft.custom),a.data.custom)),r.craft.related){a.related={};var u={id:a.id,related:!0};Object.keys(r.craft.related).forEach((function(t){a.related[t]=function(){return e.createElement(Z,u,e.createElement(r.craft.related[t]))}}))}}}))}var ye=function(e,t){var n,r;if(t.length<1)return(n={})[e.id]=e,n;var o=t.map((function(e){return e.rootNodeId})),a=F(F({},e),{data:F(F({},e.data),{nodes:o})}),d=((r={})[e.id]=a,r);return t.reduce((function(t,n){var r,o=n.nodes[n.rootNodeId];return F(F(F({},t),n.nodes),((r={})[o.id]=F(F({},o),{data:F(F({},o.data),{parent:e.id})}),r))}),d)},ge=function(e,t){return{rootNodeId:e.id,nodes:ye(e,t)}},Ne=function(e,t){var n=t.name||t.displayName;if(t===Canvas)return"Canvas";if(e[n])return n;for(var r=0;r<Object.keys(e).length;r++){var o=Object.keys(e)[r];if(e[o]===t)return o}return"string"==typeof t?t:void 0},Ee=function(t,n,r){var o=t.props,a=function(e,t){return"object"==typeof e&&e.resolvedName?"Canvas"===e.resolvedName?Canvas:t[e.resolvedName]:"string"==typeof e?e:null}(t.type,n);if(a){o=Object.keys(o).reduce((function(e,t){var r=o[t];return e[t]="object"==typeof r&&r.resolvedName?Ee(r,n):"children"===t&&Array.isArray(r)?r.map((function(e){return"string"==typeof e?e:Ee(e,n)})):r,e}),{}),r&&(o.key=r);var d=F({},e.createElement(a,F({},o)));return F(F({},d),{name:Ne(n,d.type)})}},be=function(e,t){var n=M(e,["type","props"]),r=Ee(e,t),o=r.name,a=n.parent,d=n.nodes,i=n.linkedNodes||n._childCanvas;return F(F(F({type:r.type,name:o,displayName:n.displayName||o,props:r.props,custom:n.custom||{},isCanvas:!!n.isCanvas,hidden:!!n.hidden},a?{parent:a}:{}),i?{linkedNodes:i}:{}),d?{nodes:d}:{})},Oe=function(e,t){return"string"==typeof e?e:{resolvedName:Ne(t,e)}},Ce=function(e,t){var n=e.type,r=e.isCanvas,o=e.props;return o=Object.keys(o).reduce((function(e,n){var r=o[n];return r?(e[n]="children"===n&&"string"!=typeof r?s.map(r,(function(e){return"string"==typeof e?e:Ce(e,t)})):r.type?Ce(r,t):r,e):e}),{}),F(F({type:Oe(n,t)},r&&{isCanvas:r}),{props:o})},ke=function(e,t){var n=e.type,r=e.props,o=e.isCanvas,a=M(e,["type","props","isCanvas","name"]),d=Ce({type:n,isCanvas:o,props:r},t);return F(F({},d),a)};function Te(t){var n=t&&t.options,r=function(){return Te(t)};return{getDropPlaceholder:function(e,n,o,a){if(void 0===a&&(a=function(e){return t.nodes[e.id].dom}),e!==n){var d="string"==typeof e&&t.nodes[e],i=t.nodes[n],s=r().node(i.id).isCanvas()?i:t.nodes[i.data.parent];if(s){var u=s.data.nodes||[],c=function(e,t,n,r){for(var o={parent:e,index:0,where:"before"},a=0,d=0,i=0,s=0,u=0,c=0,l=0,f=t.length;l<f;l++){var p=t[l];if(c=p.top+p.outerHeight,s=p.left+p.outerWidth/2,u=p.top+p.outerHeight/2,!(d&&p.left>d||i&&u>=i||a&&p.left+p.outerWidth<a))if(o.index=l,p.inFlow){if(r<u){o.where="before";break}o.where="after"}else r<c&&(i=c),n<s?(d=s,o.where="before"):(a=s,o.where="after")}return o}(s,u?u.reduce((function(e,n){var r=a(t.nodes[n]);if(r){var o=F({id:n},p(r));e.push(o)}return e}),[]):[],o.x,o.y),l=u.length&&t.nodes[u[c.index]],f={placement:F(F({},c),{currentNode:l}),error:!1};return d&&r().node(d.id).isDraggable((function(e){return f.error=e})),r().node(s.id).isDroppable(e,(function(e){return f.error=e})),f}}},getOptions:function(){return n},node:function(e){return function e(t,n){R("string"==typeof n,D);var r=t.nodes[n],o=function(n){return e(t,n)};return{isCanvas:function(){return!!r.data.isCanvas},isRoot:function(){return r.id===y},isLinkedNode:function(){return r.data.parent&&o(r.data.parent).linkedNodes().includes(r.id)},isTopLevelNode:function(){return this.isRoot()||this.isLinkedNode()},isDeletable:function(){return!this.isTopLevelNode()},isParentOfTopLevelNodes:function(){return!!r.data.linkedNodes},isParentOfTopLevelCanvas:function(){return v("query.node(id).isParentOfTopLevelCanvas",{suggest:"query.node(id).isParentOfTopLevelNodes"}),this.isParentOfTopLevelNodes()},get:function(){return r},ancestors:function(e){return void 0===e&&(e=!1),function n(r,o,a){void 0===o&&(o=[]),void 0===a&&(a=0);var d=t.nodes[r];return d?(o.push(r),d.data.parent?((e||!e&&0===a)&&(o=n(d.data.parent,o,a+1)),o):o):o}(r.data.parent)},descendants:function(e,r){return void 0===e&&(e=!1),function n(a,d,i){if(void 0===d&&(d=[]),void 0===i&&(i=0),e||!e&&0===i){var s=t.nodes[a];if(!s)return d;if("childNodes"!==r&&o(a).linkedNodes().forEach((function(e){d.push(e),d=n(e,d,i+1)})),"linkedNodes"!==r){var u=s.data.nodes;u&&u.forEach((function(e){d.push(e),d=n(e,d,i+1)}))}return d}return d}(n)},linkedNodes:function(){return Object.values(r.data.linkedNodes||{})},isDraggable:function(n){try{var a=r;return R(!this.isTopLevelNode(),O),R(e(t,a.data.parent).isCanvas(),C),R(a.rules.canDrag(a,o),k),!0}catch(e){return n&&n(e),!1}},isDroppable:function(e,n){var a="object"==typeof e&&!t.nodes[e.id],d=function(e){return"string"==typeof e?t.nodes[e]:e}(e),i=r;try{if("string"==typeof e&&R(!o(e).isTopLevelNode(),O),R(this.isCanvas(),T),R(i.rules.canMoveIn(d,i,o),P),R(d.rules.canDrop(i,d,o),j),a)return!0;var s=o(d.id).descendants(!0);R(!s.includes(i.id)&&i.id!==d.id,w);var u=d.data.parent&&t.nodes[d.data.parent];return R(u.data.isCanvas,C),R(u||!u&&!t.nodes[d.id],x),r!==u&&R(u.rules.canMoveOut(d,u,o),I),!0}catch(e){return n&&n(e),!1}},toSerializedNode:function(){return ke(r.data,t.options.resolver)},toNodeTree:function(e){var t=H([n],this.descendants(!0,e)).reduce((function(e,t){return e[t]=o(t).get(),e}),{});return{rootNodeId:n,nodes:t}},decendants:function(e){return void 0===e&&(e=!1),v("query.node(id).decendants",{suggest:"query.node(id).descendants"}),this.descendants(e)},isTopLevelCanvas:function(){return!this.isRoot()&&!r.data.parent}}}(t,e)},getSerializedNodes:function(){var e=this,n=Object.keys(t.nodes).map((function(t){return[t,e.node(t).toSerializedNode()]}));return pe(n)},serialize:function(){return JSON.stringify(this.getSerializedNodes())},parseReactElement:function(n){return{toNodeTree:function(o){var a=function(t,n){var r=t;return"string"==typeof r&&(r=e.createElement(i,{},r)),he({data:{type:r.type,props:F({},r.props)}},(function(e){n&&n(e,r)}))}(n,(function(e,n){var r=Ne(t.options.resolver,e.data.type);R(null!==r,q),e.data.displayName=e.data.displayName||r,e.data.name=r,o&&o(e,n)})),d=[];return n.props&&n.props.children&&(d=e.Children.toArray(n.props.children).reduce((function(t,n){return e.isValidElement(n)&&t.push(r().parseReactElement(n).toNodeTree(o)),t}),[])),ge(a,d)}}},parseSerializedNode:function(e){return{toNode:function(n){var o=be(e,t.options.resolver);R(o.type,q);var a="string"==typeof n&&n;return a&&v("query.parseSerializedNode(...).toNode(id)",{suggest:"query.parseSerializedNode(...).toNode(node => node.id = id)"}),r().parseFreshNode(F(F({},a?{id:a}:{}),{data:o})).toNode(!a&&n)}}},parseFreshNode:function(e){return{toNode:function(n){return he(e,(function(e){e.data.parent===b&&(e.data.parent=y);var r=Ne(t.options.resolver,e.data.type);R(null!==r,q),e.data.displayName=e.data.displayName||r,e.data.name=r,n&&n(e)}))}}},createNode:function(e,t){v("query.createNode("+e+")",{suggest:"query.parseReactElement("+e+").toNodeTree()"});var n=this.parseReactElement(e).toNodeTree(),r=n.nodes[n.rootNodeId];return t?(t.id&&(r.id=t.id),t.data&&(r.data=F(F({},r.data),t.data)),r):r}}}var Pe={nodes:{},events:{dragged:null,selected:null,hovered:null,indicator:null}},je=function(e){return void 0===e&&(e={}),F({onNodesChange:function(){return null},onRender:function(e){return e.render},resolver:{},nodes:null,enabled:!0,indicator:{error:"red",success:"rgb(98, 196, 98)"}},e)},we=function(t){var n=t.children,r=M(t,["children"]),o=function(e){return L(ve,F(F({},Pe),{options:e}),Te)}(je(r));return a((function(){o&&r&&o.actions.setOptions((function(e){}))}),[o,r]),a((function(){o.subscribe((function(e){return{json:o.query.serialize()}}),(function(){o.query.getOptions().onNodesChange(o.query)}))}),[o]),o?e.createElement(Y.Provider,{value:o},e.createElement(K,null,n)):null};export{Canvas,X as DerivedEventHandlers,we as Editor,ie as Element,K as Events,ue as Frame,U as NodeContext,Z as NodeProvider,le as connectEditor,fe as connectNode,ae as defaultElementProps,se as deprecateCanvasComponent,de as elementPropToNodeData,ce as useEditor,J as useEventHandler,ee as useNode,je as withDefaults};
  