Socket
Socket
Sign inDemoInstall

@craftjs/utils

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@craftjs/utils - npm Package Compare versions

Comparing version 0.1.0-beta.20 to 0.1.0

lib/platform.d.ts

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [0.1.0](https://github.com/prevwong/craft.js/compare/v0.1.0-beta.20...v0.1.0) (2021-11-15)
**Note:** Version bump only for package @craftjs/utils
# [0.1.0-beta.20](https://github.com/prevwong/craft.js/compare/v0.1.0-beta.19...v0.1.0-beta.20) (2021-08-02)

@@ -8,0 +16,0 @@

2

dist/cjs/index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var produce=require("immer"),isEqualWith=require("lodash/isEqualWith"),React=require("react"),isEqual=require("shallowequal"),nanoid=require("nanoid"),invariant=require("tiny-invariant"),ReactDOM=require("react-dom");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var produce__default=_interopDefaultLegacy(produce),isEqualWith__default=_interopDefaultLegacy(isEqualWith),React__default=_interopDefaultLegacy(React),isEqual__default=_interopDefaultLegacy(isEqual),invariant__default=_interopDefaultLegacy(invariant),ReactDOM__default=_interopDefaultLegacy(ReactDOM),ROOT_NODE="ROOT",DEPRECATED_ROOT_NODE="canvas-ROOT",ERROR_NOPARENT="Parent id cannot be ommited",ERROR_DUPLICATE_NODEID="Attempting to add a node with duplicated id",ERROR_INVALID_NODEID="Node does not exist, it may have been removed",ERROR_TOP_LEVEL_ELEMENT_NO_ID='A <Element /> that is used inside a User Component must specify an `id` prop, eg: <Element id="text_element">...</Element> ',ERROR_MISSING_PLACEHOLDER_PLACEMENT="Placeholder required placement info (parent, index, or where) is missing",ERROR_MOVE_CANNOT_DROP="Node cannot be dropped into target parent",ERROR_MOVE_INCOMING_PARENT="Target parent rejects incoming node",ERROR_MOVE_OUTGOING_PARENT="Current parent rejects outgoing node",ERROR_MOVE_NONCANVAS_CHILD="Cannot move node that is not a direct child of a Canvas node",ERROR_MOVE_TO_NONCANVAS_PARENT="Cannot move node into a non-Canvas parent",ERROR_MOVE_TOP_LEVEL_NODE="A top-level Node cannot be moved",ERROR_MOVE_ROOT_NODE="Root Node cannot be moved",ERROR_MOVE_TO_DESCENDANT="Cannot move node into a descendant",ERROR_NOT_IN_RESOLVER="The component type specified for this node does not exist in the resolver",ERROR_INFINITE_CANVAS="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",ERROR_CANNOT_DRAG="The node has specified a canDrag() rule that prevents it from being dragged",ERROR_INVALID_NODE_ID="Invalid parameter Node Id specified",ERROR_DELETE_TOP_LEVEL_NODE="Attempting to delete a top-level Node",ERROR_RESOLVER_NOT_AN_OBJECT="Resolver in <Editor /> has to be an object. For (de)serialization Craft.js needs a list of all the User Components. \n \nMore info: https://craft.js.org/r/docs/api/editor#props",ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER="An Error occurred while deserializing components: Cannot find component <%displayName% /> in resolver map. Please check your resolver in <Editor />\n\nAvailable components in resolver: %availableComponents%\n\nMore info: https://craft.js.org/r/docs/api/editor#props",ERROR_USE_EDITOR_OUTSIDE_OF_EDITOR_CONTEXT="You can only use useEditor in the context of <Editor />. \n\nPlease only use useEditor in components that are children of the <Editor /> component.",ERROR_USE_NODE_OUTSIDE_OF_EDITOR_CONTEXT="You can only use useNode in the context of <Editor />. \n\nPlease only use useNode in components that are children of the <Editor /> component.",_extendStatics=function(e,t){return(_extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function __extends(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}_extendStatics(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var _assign=function(){return(_assign=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 __spreadArrays(){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 i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}var HISTORY_ACTIONS={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE",MERGE:"HISTORY_MERGE",CLEAR:"HISTORY_CLEAR"},History=function(){function e(){this.timeline=[],this.pointer=-1}return e.prototype.add=function(e,t){0===e.length&&0===t.length||(this.pointer=this.pointer+1,this.timeline.length=this.pointer,this.timeline[this.pointer]={patches:e,inversePatches:t,timestamp:Date.now()})},e.prototype.throttleAdd=function(e,t,n){if(void 0===n&&(n=500),0!==e.length||0!==t.length){if(this.timeline.length&&this.pointer>=0){var r=this.timeline[this.pointer],o=r.patches,i=r.inversePatches,a=r.timestamp;if((new Date).getTime()-a<n)return void(this.timeline[this.pointer]={timestamp:a,patches:__spreadArrays(o,e),inversePatches:__spreadArrays(t,i)})}this.add(e,t)}},e.prototype.merge=function(e,t){if(0!==e.length||0!==t.length)if(this.timeline.length&&this.pointer>=0){var n=this.timeline[this.pointer],r=n.inversePatches;this.timeline[this.pointer]={timestamp:n.timestamp,patches:__spreadArrays(n.patches,e),inversePatches:__spreadArrays(t,r)}}else this.add(e,t)},e.prototype.clear=function(){this.timeline=[],this.pointer=-1},e.prototype.canUndo=function(){return this.pointer>=0},e.prototype.canRedo=function(){return this.pointer<this.timeline.length-1},e.prototype.undo=function(e){if(this.canUndo()){var t=this.timeline[this.pointer].inversePatches;return this.pointer=this.pointer-1,produce.applyPatches(e,t)}},e.prototype.redo=function(e){if(this.canRedo())return this.pointer=this.pointer+1,produce.applyPatches(e,this.timeline[this.pointer].patches)},e}();function useMethods(e,t,n,r){var o,i=React.useMemo((function(){return new History}),[]),a=React.useRef([]),s=React.useRef();"function"==typeof e?o=e:(o=e.methods,a.current=e.ignoreHistoryForActions,s.current=e.normalizeHistory);var c=React.useRef(r);c.current=r;var u=React.useMemo((function(){var e=s.current,t=a.current,r=c.current;return[function(a,s){var c,u=n&&createQuery(n,(function(){return a}),i),R=produce.produceWithPatches(a,(function(e){var t,n;switch(s.type){case HISTORY_ACTIONS.UNDO:return i.undo(e);case HISTORY_ACTIONS.REDO:return i.redo(e);case HISTORY_ACTIONS.CLEAR:return i.clear(),_assign({},e);case HISTORY_ACTIONS.IGNORE:case HISTORY_ACTIONS.MERGE:case HISTORY_ACTIONS.THROTTLE:var r=s.payload,a=r[0],c=r.slice(1);(t=o(e,u))[a].apply(t,c);break;default:(n=o(e,u))[s.type].apply(n,s.payload)}})),p=R[0],d=R[1],l=R[2];return c=p,r&&r(p,a,{type:s.type,params:s.payload,patches:d},u,(function(e){var t=produce.produceWithPatches(p,e);c=t[0],d=__spreadArrays(d,t[1]),l=__spreadArrays(t[2],l)})),[HISTORY_ACTIONS.UNDO,HISTORY_ACTIONS.REDO].includes(s.type)&&e&&(c=produce__default.default(c,e)),__spreadArrays(t,[HISTORY_ACTIONS.UNDO,HISTORY_ACTIONS.REDO,HISTORY_ACTIONS.IGNORE,HISTORY_ACTIONS.CLEAR]).includes(s.type)||(s.type===HISTORY_ACTIONS.THROTTLE?i.throttleAdd(d,l,s.config&&s.config.rate):s.type===HISTORY_ACTIONS.MERGE?i.merge(d,l):i.add(d,l)),c},o]}),[i,o,n]),R=u[1],p=React.useReducer(u[0],t),d=p[0],l=p[1],E=React.useRef();E.current=d;var _=React.useMemo((function(){return n?createQuery(n,(function(){return E.current}),i):[]}),[i,n]),O=React.useMemo((function(){var e=Object.keys(R(null,null)),t=a.current;return _assign(_assign({},e.reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return l({type:t,payload:e})},e}),{})),{history:{undo:function(){return l({type:HISTORY_ACTIONS.UNDO})},redo:function(){return l({type:HISTORY_ACTIONS.REDO})},clear:function(){return l({type:HISTORY_ACTIONS.CLEAR})},throttle:function(n){return _assign({},e.filter((function(e){return!t.includes(e)})).reduce((function(e,t){return e[t]=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return l({type:HISTORY_ACTIONS.THROTTLE,payload:__spreadArrays([t],e),config:{rate:n}})},e}),{}))},ignore:function(){return _assign({},e.filter((function(e){return!t.includes(e)})).reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return l({type:HISTORY_ACTIONS.IGNORE,payload:__spreadArrays([t],e)})},e}),{}))},merge:function(){return _assign({},e.filter((function(e){return!t.includes(e)})).reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return l({type:HISTORY_ACTIONS.MERGE,payload:__spreadArrays([t],e)})},e}),{}))}}})}),[R]),f=React.useCallback((function(){return E.current}),[]),h=React.useMemo((function(){return new Watcher(f)}),[f]);return React.useEffect((function(){E.current=d,h.notify()}),[d,h]),React.useMemo((function(){return{getState:f,subscribe:function(e,t,n){return h.subscribe(e,t,n)},actions:O,query:_,history:i}}),[O,_,h,f,i])}function createQuery(e,t,n){var r=Object.keys(e()).reduce((function(n,r){var o;return _assign(_assign({},n),((o={})[r]=function(){for(var n,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return(n=e(t()))[r].apply(n,o)},o))}),{});return _assign(_assign({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}produce.enableMapSet(),produce.enablePatches();var Watcher=function(){function e(e){this.subscribers=[],this.getState=e}return e.prototype.subscribe=function(e,t,n){var r=this,o=new Subscriber((function(){return e(r.getState())}),t,n);return this.subscribers.push(o),this.unsubscribe.bind(this,o)},e.prototype.unsubscribe=function(e){if(this.subscribers.length){var t=this.subscribers.indexOf(e);if(t>-1)return this.subscribers.splice(t,1)}},e.prototype.notify=function(){this.subscribers.forEach((function(e){return e.collect()}))},e}(),Subscriber=function(){function e(e,t,n){void 0===n&&(n=!1),this.collector=e,this.onChange=t,n&&this.collect()}return e.prototype.collect=function(){try{var e=this.collector();isEqualWith__default.default(e,this.collected)||(this.collected=e,this.onChange&&this.onChange(this.collected))}catch(e){console.warn(e)}},e}(),getComputedStyle=function(e){return window.getComputedStyle(e)},getDOMPadding=function(e){return{left:parseInt(getComputedStyle(e).paddingLeft),right:parseInt(getComputedStyle(e).paddingRight),bottom:parseInt(getComputedStyle(e).paddingTop),top:parseInt(getComputedStyle(e).paddingBottom)}},getDOMMargin=function(e){return{left:parseInt(getComputedStyle(e).marginLeft),right:parseInt(getComputedStyle(e).marginRight),bottom:parseInt(getComputedStyle(e).marginTop),top:parseInt(getComputedStyle(e).marginBottom)}},getDOMInfo=function(e){var t=e.getBoundingClientRect(),n=t.x,r=t.y,o=t.top,i=t.left,a=t.bottom,s=t.right,c=t.width,u=t.height,R=getDOMMargin(e),p=getDOMPadding(e);return{x:Math.round(n),y:Math.round(r),top:Math.round(o),left:Math.round(i),bottom:Math.round(a),right:Math.round(s),width:Math.round(c),height:Math.round(u),outerWidth:Math.round(c+R.left+R.right),outerHeight:Math.round(u+R.top+R.bottom),margin:R,padding:p,inFlow:e&&e.parentElement&&!!styleInFlow(e,e.parentElement)}},styleInFlow=function(e,t){var n=getComputedStyle(e),r=getComputedStyle(t);if(!(n.overflow&&"visible"!==n.overflow||"none"!==r.float||t&&"grid"===r.display||t&&"flex"===r.display&&"column"!==r["flex-direction"])){switch(n.position){case"static":case"relative":break;default:return}switch(e.tagName){case"TR":case"TBODY":case"THEAD":case"TFOOT":return!0}switch(n.display){case"block":case"list-item":case"table":case"flex":case"grid":return!0}}};function useCollector(e,t){var n=e.subscribe,r=e.getState,o=e.actions,i=e.query,a=React.useRef(!0),s=React.useRef(null),c=React.useRef(t);c.current=t;var u=React.useCallback((function(e){return _assign(_assign({},e),{actions:o,query:i})}),[o,i]);a.current&&t&&(s.current=t(r(),i),a.current=!1);var R=React.useState(u(s.current)),p=R[0],d=R[1];return React.useEffect((function(){var e;return c.current&&(e=n((function(e){return c.current(e,i)}),(function(e){d(u(e))}))),function(){e&&e()}}),[u,i,n]),p}var getRandomId=function(e){return void 0===e&&(e=10),nanoid.nanoid(e)},ConnectorRegistry=function(){function e(){this.elementIdMap=new WeakMap,this.registry=new Map}return e.prototype.getElementId=function(e){var t=this.elementIdMap.get(e);if(t)return t;var n=getRandomId();return this.elementIdMap.set(e,n),n},e.prototype.getConnectorId=function(e,t){return t+"--"+this.getElementId(e)},e.prototype.register=function(e,t){if(this.get(e,t.name)){if(isEqual__default.default(t.required,this.get(e,t.name).required))return;this.get(e,t.name).disable()}var n=null;this.registry.set(this.getConnectorId(e,t.name),{required:t.required,enable:function(){n&&n(),n=t.connector(e,t.required,t.options)},disable:function(){n&&n()}}),this.registry.get(this.getConnectorId(e,t.name)).enable()},e.prototype.get=function(e,t){return this.registry.get(this.getConnectorId(e,t))},e.prototype.enable=function(){this.registry.forEach((function(e){e.enable()}))},e.prototype.disable=function(){this.registry.forEach((function(e){e.disable()}))},e.prototype.clear=function(){this.elementIdMap=new WeakMap,this.registry.clear()},e}();function isEventBlockedByDescendant(e,t,n){e.craft||(e.craft={stopPropagation:function(){},blockedEvents:{}});for(var r=e.craft&&e.craft.blockedEvents[t]||[],o=0;o<r.length;o++){var i=r[o];if(n!==i&&n.contains(i))return!0}return!1}exports.EventHandlerUpdates=void 0,function(e){e[e.HandlerDisabled=0]="HandlerDisabled",e[e.HandlerEnabled=1]="HandlerEnabled"}(exports.EventHandlerUpdates||(exports.EventHandlerUpdates={}));var EventHandlers=function(){function e(e){this.registry=new ConnectorRegistry,this.subscribers=new Set,this.options=e}return e.prototype.listen=function(e){var t=this;return this.subscribers.add(e),function(){return t.subscribers.delete(e)}},e.prototype.disable=function(){this.registry.disable(),this.subscribers.forEach((function(e){e(exports.EventHandlerUpdates.HandlerDisabled)}))},e.prototype.enable=function(){this.registry.enable(),this.subscribers.forEach((function(e){e(exports.EventHandlerUpdates.HandlerEnabled)}))},e.prototype.cleanup=function(){this.disable(),this.subscribers.clear(),this.registry.clear()},e.prototype.addCraftEventListener=function(e,t,n,r){var o=function(r){isEventBlockedByDescendant(r,t,e)||(r.craft.stopPropagation=function(){r.craft.blockedEvents[t]||(r.craft.blockedEvents[t]=[]),r.craft.blockedEvents[t].push(e)},n(r))};return e.addEventListener(t,o,r),function(){return e.removeEventListener(t,o,r)}},Object.defineProperty(e.prototype,"connectors",{get:function(){var e=this,t=this.handlers();return Object.keys(t).reduce((function(n,r){var o;return _assign(_assign({},n),((o={})[r]=function(n,o,i){return e.registry.register(n,{required:o,name:r,options:i,connector:t[r]}),n},o))}),{})},enumerable:!0,configurable:!0}),e.prototype.derive=function(e,t){return new e(this,t)},e.prototype.createProxyHandlers=function(e,t){var n=[],r=e.handlers();return t(new Proxy(r,{get:function(e,t,o){return t in r==0?Reflect.get(e,t,o):function(e){for(var o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];var a=r[t].apply(r,__spreadArrays([e],o));a&&n.push(a)}}})),function(){n.forEach((function(e){e()}))}},e.prototype.reflect=function(e){return this.createProxyHandlers(this,e)},e}(),DerivedEventHandlers=function(e){function t(t,n){var r=e.call(this,n)||this;return r.derived=t,r.options=n,r.unsubscribeParentHandlerListener=r.derived.listen((function(e){switch(e){case exports.EventHandlerUpdates.HandlerEnabled:return r.enable();case exports.EventHandlerUpdates.HandlerDisabled:return r.disable();default:return}})),r}return __extends(t,e),t.prototype.inherit=function(e){return this.createProxyHandlers(this.derived,e)},t.prototype.cleanup=function(){e.prototype.cleanup.call(this),this.unsubscribeParentHandlerListener()},t}(EventHandlers);function setRef(e,t){t&&("function"==typeof e?e(t):e.current=t)}function cloneWithRef(e,t){var n=e.ref;return invariant__default.default("string"!=typeof n,"Cannot connect to an element with an existing string ref. Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. Read more: https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute"),React.cloneElement(e,n?{ref:function(e){setRef(n,e),setRef(t,e)}}:{ref:t})}function throwIfCompositeComponentElement(e){if("string"!=typeof e.type)throw new Error}function wrapHookToRecognizeElement(e){return function(t){void 0===t&&(t=null);for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(!React.isValidElement(t)){if(!t)return;var o=t;return o&&e.apply(void 0,__spreadArrays([o],n)),o}var i=t;return throwIfCompositeComponentElement(i),cloneWithRef(i,e)}}function wrapConnectorHooks(e){return Object.keys(e).reduce((function(t,n){return t[n]=wrapHookToRecognizeElement((function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e[n].apply(e,t)})),t}),{})}var RenderIndicator=function(e){var t=e.parentDom,n=React__default.default.createElement("div",{style:_assign({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},e.style)});return t&&t.ownerDocument!==document?ReactDOM__default.default.createPortal(n,t.ownerDocument.body):n},useEffectOnce=function(e){React.useEffect(e,[])},deprecationWarning=function(e,t){var n="Deprecation warning: "+e+" will be deprecated in future relases.",r=t.suggest,o=t.doc;r&&(n+=" Please use "+r+" instead."),o&&(n+="("+o+")"),console.warn(n)};exports.DEPRECATED_ROOT_NODE=DEPRECATED_ROOT_NODE,exports.DerivedEventHandlers=DerivedEventHandlers,exports.ERROR_CANNOT_DRAG=ERROR_CANNOT_DRAG,exports.ERROR_DELETE_TOP_LEVEL_NODE=ERROR_DELETE_TOP_LEVEL_NODE,exports.ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER=ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER,exports.ERROR_DUPLICATE_NODEID=ERROR_DUPLICATE_NODEID,exports.ERROR_INFINITE_CANVAS=ERROR_INFINITE_CANVAS,exports.ERROR_INVALID_NODEID=ERROR_INVALID_NODEID,exports.ERROR_INVALID_NODE_ID=ERROR_INVALID_NODE_ID,exports.ERROR_MISSING_PLACEHOLDER_PLACEMENT=ERROR_MISSING_PLACEHOLDER_PLACEMENT,exports.ERROR_MOVE_CANNOT_DROP=ERROR_MOVE_CANNOT_DROP,exports.ERROR_MOVE_INCOMING_PARENT=ERROR_MOVE_INCOMING_PARENT,exports.ERROR_MOVE_NONCANVAS_CHILD=ERROR_MOVE_NONCANVAS_CHILD,exports.ERROR_MOVE_OUTGOING_PARENT=ERROR_MOVE_OUTGOING_PARENT,exports.ERROR_MOVE_ROOT_NODE=ERROR_MOVE_ROOT_NODE,exports.ERROR_MOVE_TOP_LEVEL_NODE=ERROR_MOVE_TOP_LEVEL_NODE,exports.ERROR_MOVE_TO_DESCENDANT=ERROR_MOVE_TO_DESCENDANT,exports.ERROR_MOVE_TO_NONCANVAS_PARENT=ERROR_MOVE_TO_NONCANVAS_PARENT,exports.ERROR_NOPARENT=ERROR_NOPARENT,exports.ERROR_NOT_IN_RESOLVER=ERROR_NOT_IN_RESOLVER,exports.ERROR_RESOLVER_NOT_AN_OBJECT=ERROR_RESOLVER_NOT_AN_OBJECT,exports.ERROR_TOP_LEVEL_ELEMENT_NO_ID=ERROR_TOP_LEVEL_ELEMENT_NO_ID,exports.ERROR_USE_EDITOR_OUTSIDE_OF_EDITOR_CONTEXT=ERROR_USE_EDITOR_OUTSIDE_OF_EDITOR_CONTEXT,exports.ERROR_USE_NODE_OUTSIDE_OF_EDITOR_CONTEXT=ERROR_USE_NODE_OUTSIDE_OF_EDITOR_CONTEXT,exports.EventHandlers=EventHandlers,exports.HISTORY_ACTIONS=HISTORY_ACTIONS,exports.History=History,exports.ROOT_NODE=ROOT_NODE,exports.RenderIndicator=RenderIndicator,exports.cloneWithRef=cloneWithRef,exports.createQuery=createQuery,exports.deprecationWarning=deprecationWarning,exports.getComputedStyle=getComputedStyle,exports.getDOMInfo=getDOMInfo,exports.getDOMMargin=getDOMMargin,exports.getDOMPadding=getDOMPadding,exports.getRandomId=getRandomId,exports.styleInFlow=styleInFlow,exports.useCollector=useCollector,exports.useEffectOnce=useEffectOnce,exports.useMethods=useMethods,exports.wrapConnectorHooks=wrapConnectorHooks,exports.wrapHookToRecognizeElement=wrapHookToRecognizeElement;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var produce=require("immer"),isEqualWith=require("lodash/isEqualWith"),React=require("react"),isEqual=require("shallowequal"),nanoid=require("nanoid"),invariant=require("tiny-invariant"),ReactDOM=require("react-dom");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var produce__default=_interopDefaultLegacy(produce),isEqualWith__default=_interopDefaultLegacy(isEqualWith),React__default=_interopDefaultLegacy(React),isEqual__default=_interopDefaultLegacy(isEqual),invariant__default=_interopDefaultLegacy(invariant),ReactDOM__default=_interopDefaultLegacy(ReactDOM),ROOT_NODE="ROOT",DEPRECATED_ROOT_NODE="canvas-ROOT",ERROR_NOPARENT="Parent id cannot be ommited",ERROR_DUPLICATE_NODEID="Attempting to add a node with duplicated id",ERROR_INVALID_NODEID="Node does not exist, it may have been removed",ERROR_TOP_LEVEL_ELEMENT_NO_ID='A <Element /> that is used inside a User Component must specify an `id` prop, eg: <Element id="text_element">...</Element> ',ERROR_MISSING_PLACEHOLDER_PLACEMENT="Placeholder required placement info (parent, index, or where) is missing",ERROR_MOVE_CANNOT_DROP="Node cannot be dropped into target parent",ERROR_MOVE_INCOMING_PARENT="Target parent rejects incoming node",ERROR_MOVE_OUTGOING_PARENT="Current parent rejects outgoing node",ERROR_MOVE_NONCANVAS_CHILD="Cannot move node that is not a direct child of a Canvas node",ERROR_MOVE_TO_NONCANVAS_PARENT="Cannot move node into a non-Canvas parent",ERROR_MOVE_TOP_LEVEL_NODE="A top-level Node cannot be moved",ERROR_MOVE_ROOT_NODE="Root Node cannot be moved",ERROR_MOVE_TO_DESCENDANT="Cannot move node into a descendant",ERROR_NOT_IN_RESOLVER="The component type specified for this node (%node_type%) does not exist in the resolver",ERROR_INFINITE_CANVAS="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",ERROR_CANNOT_DRAG="The node has specified a canDrag() rule that prevents it from being dragged",ERROR_INVALID_NODE_ID="Invalid parameter Node Id specified",ERROR_DELETE_TOP_LEVEL_NODE="Attempting to delete a top-level Node",ERROR_RESOLVER_NOT_AN_OBJECT="Resolver in <Editor /> has to be an object. For (de)serialization Craft.js needs a list of all the User Components. \n \nMore info: https://craft.js.org/r/docs/api/editor#props",ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER="An Error occurred while deserializing components: Cannot find component <%displayName% /> in resolver map. Please check your resolver in <Editor />\n\nAvailable components in resolver: %availableComponents%\n\nMore info: https://craft.js.org/r/docs/api/editor#props",ERROR_USE_EDITOR_OUTSIDE_OF_EDITOR_CONTEXT="You can only use useEditor in the context of <Editor />. \n\nPlease only use useEditor in components that are children of the <Editor /> component.",ERROR_USE_NODE_OUTSIDE_OF_EDITOR_CONTEXT="You can only use useNode in the context of <Editor />. \n\nPlease only use useNode in components that are children of the <Editor /> component.",_extendStatics=function(e,t){return(_extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)};function __extends(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}_extendStatics(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var _assign=function(){return(_assign=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 __spreadArrays(){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 i=arguments[t],s=0,a=i.length;s<a;s++,o++)r[o]=i[s];return r}var HISTORY_ACTIONS={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE",MERGE:"HISTORY_MERGE",CLEAR:"HISTORY_CLEAR"},History=function(){function e(){this.timeline=[],this.pointer=-1}return e.prototype.add=function(e,t){0===e.length&&0===t.length||(this.pointer=this.pointer+1,this.timeline.length=this.pointer,this.timeline[this.pointer]={patches:e,inversePatches:t,timestamp:Date.now()})},e.prototype.throttleAdd=function(e,t,n){if(void 0===n&&(n=500),0!==e.length||0!==t.length){if(this.timeline.length&&this.pointer>=0){var r=this.timeline[this.pointer],o=r.patches,i=r.inversePatches,s=r.timestamp;if((new Date).getTime()-s<n)return void(this.timeline[this.pointer]={timestamp:s,patches:__spreadArrays(o,e),inversePatches:__spreadArrays(t,i)})}this.add(e,t)}},e.prototype.merge=function(e,t){if(0!==e.length||0!==t.length)if(this.timeline.length&&this.pointer>=0){var n=this.timeline[this.pointer],r=n.inversePatches;this.timeline[this.pointer]={timestamp:n.timestamp,patches:__spreadArrays(n.patches,e),inversePatches:__spreadArrays(t,r)}}else this.add(e,t)},e.prototype.clear=function(){this.timeline=[],this.pointer=-1},e.prototype.canUndo=function(){return this.pointer>=0},e.prototype.canRedo=function(){return this.pointer<this.timeline.length-1},e.prototype.undo=function(e){if(this.canUndo()){var t=this.timeline[this.pointer].inversePatches;return this.pointer=this.pointer-1,produce.applyPatches(e,t)}},e.prototype.redo=function(e){if(this.canRedo())return this.pointer=this.pointer+1,produce.applyPatches(e,this.timeline[this.pointer].patches)},e}();function useMethods(e,t,n,r){var o,i=React.useMemo((function(){return new History}),[]),s=React.useRef([]),a=React.useRef();"function"==typeof e?o=e:(o=e.methods,s.current=e.ignoreHistoryForActions,a.current=e.normalizeHistory);var c=React.useRef(r);c.current=r;var u=React.useMemo((function(){var e=a.current,t=s.current,r=c.current;return[function(s,a){var c,u=n&&createQuery(n,(function(){return s}),i),R=produce.produceWithPatches(s,(function(e){var t,n;switch(a.type){case HISTORY_ACTIONS.UNDO:return i.undo(e);case HISTORY_ACTIONS.REDO:return i.redo(e);case HISTORY_ACTIONS.CLEAR:return i.clear(),_assign({},e);case HISTORY_ACTIONS.IGNORE:case HISTORY_ACTIONS.MERGE:case HISTORY_ACTIONS.THROTTLE:var r=a.payload,s=r[0],c=r.slice(1);(t=o(e,u))[s].apply(t,c);break;default:(n=o(e,u))[a.type].apply(n,a.payload)}})),p=R[0],d=R[1],E=R[2];return c=p,r&&r(p,s,{type:a.type,params:a.payload,patches:d},u,(function(e){var t=produce.produceWithPatches(p,e);c=t[0],d=__spreadArrays(d,t[1]),E=__spreadArrays(t[2],E)})),[HISTORY_ACTIONS.UNDO,HISTORY_ACTIONS.REDO].includes(a.type)&&e&&(c=produce__default.default(c,e)),__spreadArrays(t,[HISTORY_ACTIONS.UNDO,HISTORY_ACTIONS.REDO,HISTORY_ACTIONS.IGNORE,HISTORY_ACTIONS.CLEAR]).includes(a.type)||(a.type===HISTORY_ACTIONS.THROTTLE?i.throttleAdd(d,E,a.config&&a.config.rate):a.type===HISTORY_ACTIONS.MERGE?i.merge(d,E):i.add(d,E)),c},o]}),[i,o,n]),R=u[1],p=React.useReducer(u[0],t),d=p[0],E=p[1],l=React.useRef();l.current=d;var _=React.useMemo((function(){return n?createQuery(n,(function(){return l.current}),i):[]}),[i,n]),O=React.useMemo((function(){var e=Object.keys(R(null,null)),t=s.current;return _assign(_assign({},e.reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return E({type:t,payload:e})},e}),{})),{history:{undo:function(){return E({type:HISTORY_ACTIONS.UNDO})},redo:function(){return E({type:HISTORY_ACTIONS.REDO})},clear:function(){return E({type:HISTORY_ACTIONS.CLEAR})},throttle:function(n){return _assign({},e.filter((function(e){return!t.includes(e)})).reduce((function(e,t){return e[t]=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return E({type:HISTORY_ACTIONS.THROTTLE,payload:__spreadArrays([t],e),config:{rate:n}})},e}),{}))},ignore:function(){return _assign({},e.filter((function(e){return!t.includes(e)})).reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return E({type:HISTORY_ACTIONS.IGNORE,payload:__spreadArrays([t],e)})},e}),{}))},merge:function(){return _assign({},e.filter((function(e){return!t.includes(e)})).reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return E({type:HISTORY_ACTIONS.MERGE,payload:__spreadArrays([t],e)})},e}),{}))}}})}),[R]),f=React.useCallback((function(){return l.current}),[]),h=React.useMemo((function(){return new Watcher(f)}),[f]);return React.useEffect((function(){l.current=d,h.notify()}),[d,h]),React.useMemo((function(){return{getState:f,subscribe:function(e,t,n){return h.subscribe(e,t,n)},actions:O,query:_,history:i}}),[O,_,h,f,i])}function createQuery(e,t,n){var r=Object.keys(e()).reduce((function(n,r){var o;return _assign(_assign({},n),((o={})[r]=function(){for(var n,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return(n=e(t()))[r].apply(n,o)},o))}),{});return _assign(_assign({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}produce.enableMapSet(),produce.enablePatches();var Watcher=function(){function e(e){this.subscribers=[],this.getState=e}return e.prototype.subscribe=function(e,t,n){var r=this,o=new Subscriber((function(){return e(r.getState())}),t,n);return this.subscribers.push(o),this.unsubscribe.bind(this,o)},e.prototype.unsubscribe=function(e){if(this.subscribers.length){var t=this.subscribers.indexOf(e);if(t>-1)return this.subscribers.splice(t,1)}},e.prototype.notify=function(){this.subscribers.forEach((function(e){return e.collect()}))},e}(),Subscriber=function(){function e(e,t,n){void 0===n&&(n=!1),this.collector=e,this.onChange=t,n&&this.collect()}return e.prototype.collect=function(){try{var e=this.collector();isEqualWith__default.default(e,this.collected)||(this.collected=e,this.onChange&&this.onChange(this.collected))}catch(e){console.warn(e)}},e}(),getDOMInfo=function(e){var t=e.getBoundingClientRect(),n=t.x,r=t.y,o=t.top,i=t.left,s=t.bottom,a=t.right,c=t.width,u=t.height,R=window.getComputedStyle(e),p={left:parseInt(R.marginLeft),right:parseInt(R.marginRight),bottom:parseInt(R.marginBottom),top:parseInt(R.marginTop)},d={left:parseInt(R.paddingLeft),right:parseInt(R.paddingRight),bottom:parseInt(R.paddingBottom),top:parseInt(R.paddingTop)};return{x:n,y:r,top:o,left:i,bottom:s,right:a,width:c,height:u,outerWidth:Math.round(c+p.left+p.right),outerHeight:Math.round(u+p.top+p.bottom),margin:p,padding:d,inFlow:e.parentElement&&!!function(t){var n=getComputedStyle(t);if(!(R.overflow&&"visible"!==R.overflow||"none"!==n.float||"grid"===n.display||"flex"===n.display&&"column"!==n["flex-direction"])){switch(R.position){case"static":case"relative":break;default:return}switch(e.tagName){case"TR":case"TBODY":case"THEAD":case"TFOOT":return!0}switch(R.display){case"block":case"list-item":case"table":case"flex":case"grid":return!0}}}(e.parentElement)}};function useCollector(e,t){var n=e.subscribe,r=e.getState,o=e.actions,i=e.query,s=React.useRef(!0),a=React.useRef(null),c=React.useRef(t);c.current=t;var u=React.useCallback((function(e){return _assign(_assign({},e),{actions:o,query:i})}),[o,i]);s.current&&t&&(a.current=t(r(),i),s.current=!1);var R=React.useState(u(a.current)),p=R[0],d=R[1];return React.useEffect((function(){var e;return c.current&&(e=n((function(e){return c.current(e,i)}),(function(e){d(u(e))}))),function(){e&&e()}}),[u,i,n]),p}var getRandomId=function(e){return void 0===e&&(e=10),nanoid.nanoid(e)},ConnectorRegistry=function(){function e(){this.elementIdMap=new WeakMap,this.registry=new Map}return e.prototype.getElementId=function(e){var t=this.elementIdMap.get(e);if(t)return t;var n=getRandomId();return this.elementIdMap.set(e,n),n},e.prototype.getConnectorId=function(e,t){return t+"--"+this.getElementId(e)},e.prototype.register=function(e,t){var n=this,r=this.getByElement(e,t.name);if(r){if(isEqual__default.default(t.required,r.required))return r;this.getByElement(e,t.name).disable()}var o=null,i=this.getConnectorId(e,t.name);return this.registry.set(i,{id:i,required:t.required,enable:function(){o&&o(),o=t.connector(e,t.required,t.options)},disable:function(){o&&o()},remove:function(){return n.remove(i)}}),this.registry.get(i).enable(),this.registry.get(i)},e.prototype.get=function(e){return this.registry.get(e)},e.prototype.remove=function(e){var t=this.get(e);t&&(t.disable(),this.registry.delete(t.id))},e.prototype.enable=function(){this.registry.forEach((function(e){e.enable()}))},e.prototype.disable=function(){this.registry.forEach((function(e){e.disable()}))},e.prototype.getByElement=function(e,t){return this.get(this.getConnectorId(e,t))},e.prototype.removeByElement=function(e,t){return this.remove(this.getConnectorId(e,t))},e.prototype.clear=function(){this.disable(),this.elementIdMap=new WeakMap,this.registry=new Map},e}();function isEventBlockedByDescendant(e,t,n){e.craft||(e.craft={stopPropagation:function(){},blockedEvents:{}});for(var r=e.craft&&e.craft.blockedEvents[t]||[],o=0;o<r.length;o++){var i=r[o];if(n!==i&&n.contains(i))return!0}return!1}exports.EventHandlerUpdates=void 0,function(e){e[e.HandlerDisabled=0]="HandlerDisabled",e[e.HandlerEnabled=1]="HandlerEnabled"}(exports.EventHandlerUpdates||(exports.EventHandlerUpdates={}));var EventHandlers=function(){function e(e){this.registry=new ConnectorRegistry,this.subscribers=new Set,this.options=e}return e.prototype.listen=function(e){var t=this;return this.subscribers.add(e),function(){return t.subscribers.delete(e)}},e.prototype.disable=function(){this.onDisable&&this.onDisable(),this.registry.disable(),this.subscribers.forEach((function(e){e(exports.EventHandlerUpdates.HandlerDisabled)}))},e.prototype.enable=function(){this.onEnable&&this.onEnable(),this.registry.enable(),this.subscribers.forEach((function(e){e(exports.EventHandlerUpdates.HandlerEnabled)}))},e.prototype.cleanup=function(){this.disable(),this.subscribers.clear(),this.registry.clear()},e.prototype.addCraftEventListener=function(e,t,n,r){var o=function(r){isEventBlockedByDescendant(r,t,e)||(r.craft.stopPropagation=function(){r.craft.blockedEvents[t]||(r.craft.blockedEvents[t]=[]),r.craft.blockedEvents[t].push(e)},n(r))};return e.addEventListener(t,o,r),function(){return e.removeEventListener(t,o,r)}},e.prototype.createConnectorsUsage=function(){var e=this,t=this.handlers(),n=new Set;return{connectors:Object.entries(t).reduce((function(t,r){var o,i=r[0],s=r[1];return _assign(_assign({},t),((o={})[i]=function(t,r,o){var a=e.registry.register(t,{required:r,name:i,options:o,connector:s});return n.add(a.id),t},o))}),{}),cleanup:function(){n.forEach((function(t){return e.registry.remove(t)}))}}},e.prototype.derive=function(e,t){return new e(this,t)},e.prototype.createProxyHandlers=function(e,t){var n=[],r=e.handlers();return t(new Proxy(r,{get:function(e,t,o){return t in r==0?Reflect.get(e,t,o):function(e){for(var o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];var s=r[t].apply(r,__spreadArrays([e],o));s&&n.push(s)}}})),function(){n.forEach((function(e){e()}))}},e.prototype.reflect=function(e){return this.createProxyHandlers(this,e)},e}(),DerivedEventHandlers=function(e){function t(t,n){var r=e.call(this,n)||this;return r.derived=t,r.options=n,r.unsubscribeParentHandlerListener=r.derived.listen((function(e){switch(e){case exports.EventHandlerUpdates.HandlerEnabled:return r.enable();case exports.EventHandlerUpdates.HandlerDisabled:return r.disable();default:return}})),r}return __extends(t,e),t.prototype.inherit=function(e){return this.createProxyHandlers(this.derived,e)},t.prototype.cleanup=function(){e.prototype.cleanup.call(this),this.unsubscribeParentHandlerListener()},t}(EventHandlers);function setRef(e,t){t&&("function"==typeof e?e(t):e.current=t)}function cloneWithRef(e,t){var n=e.ref;return invariant__default.default("string"!=typeof n,"Cannot connect to an element with an existing string ref. Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. Read more: https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute"),React.cloneElement(e,n?{ref:function(e){setRef(n,e),setRef(t,e)}}:{ref:t})}function throwIfCompositeComponentElement(e){if("string"!=typeof e.type)throw new Error}function wrapHookToRecognizeElement(e){return function(t){void 0===t&&(t=null);for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(!React.isValidElement(t)){if(!t)return;var o=t;return o&&e.apply(void 0,__spreadArrays([o],n)),o}var i=t;return throwIfCompositeComponentElement(i),cloneWithRef(i,e)}}function wrapConnectorHooks(e){return Object.keys(e).reduce((function(t,n){return t[n]=wrapHookToRecognizeElement((function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e[n].apply(e,t)})),t}),{})}var RenderIndicator=function(e){var t=e.parentDom,n=React__default.default.createElement("div",{style:_assign({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},e.style)});return t&&t.ownerDocument!==document?ReactDOM__default.default.createPortal(n,t.ownerDocument.body):n},useEffectOnce=function(e){React.useEffect(e,[])},deprecationWarning=function(e,t){var n="Deprecation warning: "+e+" will be deprecated in future relases.",r=t.suggest,o=t.doc;r&&(n+=" Please use "+r+" instead."),o&&(n+="("+o+")"),console.warn(n)},isClientSide=function(){return"undefined"!=typeof window},isLinux=function(){return isClientSide()&&/Linux/i.test(window.navigator.userAgent)},isChromium=function(){return isClientSide()&&/Chrome/i.test(window.navigator.userAgent)};exports.DEPRECATED_ROOT_NODE=DEPRECATED_ROOT_NODE,exports.DerivedEventHandlers=DerivedEventHandlers,exports.ERROR_CANNOT_DRAG=ERROR_CANNOT_DRAG,exports.ERROR_DELETE_TOP_LEVEL_NODE=ERROR_DELETE_TOP_LEVEL_NODE,exports.ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER=ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER,exports.ERROR_DUPLICATE_NODEID=ERROR_DUPLICATE_NODEID,exports.ERROR_INFINITE_CANVAS=ERROR_INFINITE_CANVAS,exports.ERROR_INVALID_NODEID=ERROR_INVALID_NODEID,exports.ERROR_INVALID_NODE_ID=ERROR_INVALID_NODE_ID,exports.ERROR_MISSING_PLACEHOLDER_PLACEMENT=ERROR_MISSING_PLACEHOLDER_PLACEMENT,exports.ERROR_MOVE_CANNOT_DROP=ERROR_MOVE_CANNOT_DROP,exports.ERROR_MOVE_INCOMING_PARENT=ERROR_MOVE_INCOMING_PARENT,exports.ERROR_MOVE_NONCANVAS_CHILD=ERROR_MOVE_NONCANVAS_CHILD,exports.ERROR_MOVE_OUTGOING_PARENT=ERROR_MOVE_OUTGOING_PARENT,exports.ERROR_MOVE_ROOT_NODE=ERROR_MOVE_ROOT_NODE,exports.ERROR_MOVE_TOP_LEVEL_NODE=ERROR_MOVE_TOP_LEVEL_NODE,exports.ERROR_MOVE_TO_DESCENDANT=ERROR_MOVE_TO_DESCENDANT,exports.ERROR_MOVE_TO_NONCANVAS_PARENT=ERROR_MOVE_TO_NONCANVAS_PARENT,exports.ERROR_NOPARENT=ERROR_NOPARENT,exports.ERROR_NOT_IN_RESOLVER=ERROR_NOT_IN_RESOLVER,exports.ERROR_RESOLVER_NOT_AN_OBJECT=ERROR_RESOLVER_NOT_AN_OBJECT,exports.ERROR_TOP_LEVEL_ELEMENT_NO_ID=ERROR_TOP_LEVEL_ELEMENT_NO_ID,exports.ERROR_USE_EDITOR_OUTSIDE_OF_EDITOR_CONTEXT=ERROR_USE_EDITOR_OUTSIDE_OF_EDITOR_CONTEXT,exports.ERROR_USE_NODE_OUTSIDE_OF_EDITOR_CONTEXT=ERROR_USE_NODE_OUTSIDE_OF_EDITOR_CONTEXT,exports.EventHandlers=EventHandlers,exports.HISTORY_ACTIONS=HISTORY_ACTIONS,exports.History=History,exports.ROOT_NODE=ROOT_NODE,exports.RenderIndicator=RenderIndicator,exports.cloneWithRef=cloneWithRef,exports.createQuery=createQuery,exports.deprecationWarning=deprecationWarning,exports.getDOMInfo=getDOMInfo,exports.getRandomId=getRandomId,exports.isChromium=isChromium,exports.isClientSide=isClientSide,exports.isLinux=isLinux,exports.useCollector=useCollector,exports.useEffectOnce=useEffectOnce,exports.useMethods=useMethods,exports.wrapConnectorHooks=wrapConnectorHooks,exports.wrapHookToRecognizeElement=wrapHookToRecognizeElement;

@@ -1,1 +0,1 @@

import t,{applyPatches as e,enableMapSet as n,enablePatches as r,produceWithPatches as o}from"immer";import i from"lodash/isEqualWith";import a,{useMemo as s,useRef as c,useReducer as u,useCallback as l,useEffect as p,useState as f,cloneElement as d,isValidElement as h}from"react";import y from"shallowequal";import{nanoid as g}from"nanoid";import m from"tiny-invariant";import v from"react-dom";var b="ROOT",E="canvas-ROOT",O="Parent id cannot be ommited",R="Attempting to add a node with duplicated id",w="Node does not exist, it may have been removed",T='A <Element /> that is used inside a User Component must specify an `id` prop, eg: <Element id="text_element">...</Element> ',I="Placeholder required placement info (parent, index, or where) is missing",C="Node cannot be dropped into target parent",H="Target parent rejects incoming node",P="Current parent rejects outgoing node",D="Cannot move node that is not a direct child of a Canvas node",M="Cannot move node into a non-Canvas parent",x="A top-level Node cannot be moved",N="Root Node cannot be moved",k="Cannot move node into a descendant",A="The component type specified for this node does not exist in the resolver",L="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",j="The node has specified a canDrag() rule that prevents it from being dragged",_="Invalid parameter Node Id specified",S="Attempting to delete a top-level Node",q="Resolver in <Editor /> has to be an object. For (de)serialization Craft.js needs a list of all the User Components. \n \nMore info: https://craft.js.org/r/docs/api/editor#props",U="An Error occurred while deserializing components: Cannot find component <%displayName% /> in resolver map. Please check your resolver in <Editor />\n\nAvailable components in resolver: %availableComponents%\n\nMore info: https://craft.js.org/r/docs/api/editor#props",G="You can only use useEditor in the context of <Editor />. \n\nPlease only use useEditor in components that are children of the <Editor /> component.",Y="You can only use useNode in the context of <Editor />. \n\nPlease only use useNode in components that are children of the <Editor /> component.",W=function(t,e){return(W=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)},z=function(){return(z=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function B(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}var F={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE",MERGE:"HISTORY_MERGE",CLEAR:"HISTORY_CLEAR"},J=function(){function t(){this.timeline=[],this.pointer=-1}return t.prototype.add=function(t,e){0===t.length&&0===e.length||(this.pointer=this.pointer+1,this.timeline.length=this.pointer,this.timeline[this.pointer]={patches:t,inversePatches:e,timestamp:Date.now()})},t.prototype.throttleAdd=function(t,e,n){if(void 0===n&&(n=500),0!==t.length||0!==e.length){if(this.timeline.length&&this.pointer>=0){var r=this.timeline[this.pointer],o=r.patches,i=r.inversePatches,a=r.timestamp;if((new Date).getTime()-a<n)return void(this.timeline[this.pointer]={timestamp:a,patches:B(o,t),inversePatches:B(e,i)})}this.add(t,e)}},t.prototype.merge=function(t,e){if(0!==t.length||0!==e.length)if(this.timeline.length&&this.pointer>=0){var n=this.timeline[this.pointer],r=n.inversePatches;this.timeline[this.pointer]={timestamp:n.timestamp,patches:B(n.patches,t),inversePatches:B(e,r)}}else this.add(t,e)},t.prototype.clear=function(){this.timeline=[],this.pointer=-1},t.prototype.canUndo=function(){return this.pointer>=0},t.prototype.canRedo=function(){return this.pointer<this.timeline.length-1},t.prototype.undo=function(t){if(this.canUndo()){var n=this.timeline[this.pointer].inversePatches;return this.pointer=this.pointer-1,e(t,n)}},t.prototype.redo=function(t){if(this.canRedo())return this.pointer=this.pointer+1,e(t,this.timeline[this.pointer].patches)},t}();function K(e,n,r,i){var a,f=s((function(){return new J}),[]),d=c([]),h=c();"function"==typeof e?a=e:(a=e.methods,d.current=e.ignoreHistoryForActions,h.current=e.normalizeHistory);var y=c(i);y.current=i;var g=s((function(){var e=h.current,n=d.current,i=y.current;return[function(s,c){var u,l=r&&Q(r,(function(){return s}),f),p=o(s,(function(t){var e,n;switch(c.type){case F.UNDO:return f.undo(t);case F.REDO:return f.redo(t);case F.CLEAR:return f.clear(),z({},t);case F.IGNORE:case F.MERGE:case F.THROTTLE:var r=c.payload,o=r[0],i=r.slice(1);(e=a(t,l))[o].apply(e,i);break;default:(n=a(t,l))[c.type].apply(n,c.payload)}})),d=p[0],h=p[1],y=p[2];return u=d,i&&i(d,s,{type:c.type,params:c.payload,patches:h},l,(function(t){var e=o(d,t);u=e[0],h=B(h,e[1]),y=B(e[2],y)})),[F.UNDO,F.REDO].includes(c.type)&&e&&(u=t(u,e)),B(n,[F.UNDO,F.REDO,F.IGNORE,F.CLEAR]).includes(c.type)||(c.type===F.THROTTLE?f.throttleAdd(h,y,c.config&&c.config.rate):c.type===F.MERGE?f.merge(h,y):f.add(h,y)),u},a]}),[f,a,r]),m=g[1],v=u(g[0],n),b=v[0],E=v[1],O=c();O.current=b;var R=s((function(){return r?Q(r,(function(){return O.current}),f):[]}),[f,r]),w=s((function(){var t=Object.keys(m(null,null)),e=d.current;return z(z({},t.reduce((function(t,e){return t[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return E({type:e,payload:t})},t}),{})),{history:{undo:function(){return E({type:F.UNDO})},redo:function(){return E({type:F.REDO})},clear:function(){return E({type:F.CLEAR})},throttle:function(n){return z({},t.filter((function(t){return!e.includes(t)})).reduce((function(t,e){return t[e]=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return E({type:F.THROTTLE,payload:B([e],t),config:{rate:n}})},t}),{}))},ignore:function(){return z({},t.filter((function(t){return!e.includes(t)})).reduce((function(t,e){return t[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return E({type:F.IGNORE,payload:B([e],t)})},t}),{}))},merge:function(){return z({},t.filter((function(t){return!e.includes(t)})).reduce((function(t,e){return t[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return E({type:F.MERGE,payload:B([e],t)})},t}),{}))}}})}),[m]),T=l((function(){return O.current}),[]),I=s((function(){return new V(T)}),[T]);return p((function(){O.current=b,I.notify()}),[b,I]),s((function(){return{getState:T,subscribe:function(t,e,n){return I.subscribe(t,e,n)},actions:w,query:R,history:f}}),[w,R,I,T,f])}function Q(t,e,n){var r=Object.keys(t()).reduce((function(n,r){var o;return z(z({},n),((o={})[r]=function(){for(var n,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return(n=t(e()))[r].apply(n,o)},o))}),{});return z(z({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}n(),r();var V=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e,n){var r=this,o=new X((function(){return t(r.getState())}),e,n);return this.subscribers.push(o),this.unsubscribe.bind(this,o)},t.prototype.unsubscribe=function(t){if(this.subscribers.length){var e=this.subscribers.indexOf(t);if(e>-1)return this.subscribers.splice(e,1)}},t.prototype.notify=function(){this.subscribers.forEach((function(t){return t.collect()}))},t}(),X=function(){function t(t,e,n){void 0===n&&(n=!1),this.collector=t,this.onChange=e,n&&this.collect()}return t.prototype.collect=function(){try{var t=this.collector();i(t,this.collected)||(this.collected=t,this.onChange&&this.onChange(this.collected))}catch(t){console.warn(t)}},t}(),Z=function(t){return window.getComputedStyle(t)},$=function(t){return{left:parseInt(Z(t).paddingLeft),right:parseInt(Z(t).paddingRight),bottom:parseInt(Z(t).paddingTop),top:parseInt(Z(t).paddingBottom)}},tt=function(t){return{left:parseInt(Z(t).marginLeft),right:parseInt(Z(t).marginRight),bottom:parseInt(Z(t).marginTop),top:parseInt(Z(t).marginBottom)}},et=function(t){var e=t.getBoundingClientRect(),n=e.x,r=e.y,o=e.top,i=e.left,a=e.bottom,s=e.right,c=e.width,u=e.height,l=tt(t),p=$(t);return{x:Math.round(n),y:Math.round(r),top:Math.round(o),left:Math.round(i),bottom:Math.round(a),right:Math.round(s),width:Math.round(c),height:Math.round(u),outerWidth:Math.round(c+l.left+l.right),outerHeight:Math.round(u+l.top+l.bottom),margin:l,padding:p,inFlow:t&&t.parentElement&&!!nt(t,t.parentElement)}},nt=function(t,e){var n=Z(t),r=Z(e);if(!(n.overflow&&"visible"!==n.overflow||"none"!==r.float||e&&"grid"===r.display||e&&"flex"===r.display&&"column"!==r["flex-direction"])){switch(n.position){case"static":case"relative":break;default:return}switch(t.tagName){case"TR":case"TBODY":case"THEAD":case"TFOOT":return!0}switch(n.display){case"block":case"list-item":case"table":case"flex":case"grid":return!0}}};function rt(t,e){var n=t.subscribe,r=t.getState,o=t.actions,i=t.query,a=c(!0),s=c(null),u=c(e);u.current=e;var d=l((function(t){return z(z({},t),{actions:o,query:i})}),[o,i]);a.current&&e&&(s.current=e(r(),i),a.current=!1);var h=f(d(s.current)),y=h[0],g=h[1];return p((function(){var t;return u.current&&(t=n((function(t){return u.current(t,i)}),(function(t){g(d(t))}))),function(){t&&t()}}),[d,i,n]),y}var ot,it=function(t){return void 0===t&&(t=10),g(t)},at=function(){function t(){this.elementIdMap=new WeakMap,this.registry=new Map}return t.prototype.getElementId=function(t){var e=this.elementIdMap.get(t);if(e)return e;var n=it();return this.elementIdMap.set(t,n),n},t.prototype.getConnectorId=function(t,e){return e+"--"+this.getElementId(t)},t.prototype.register=function(t,e){if(this.get(t,e.name)){if(y(e.required,this.get(t,e.name).required))return;this.get(t,e.name).disable()}var n=null;this.registry.set(this.getConnectorId(t,e.name),{required:e.required,enable:function(){n&&n(),n=e.connector(t,e.required,e.options)},disable:function(){n&&n()}}),this.registry.get(this.getConnectorId(t,e.name)).enable()},t.prototype.get=function(t,e){return this.registry.get(this.getConnectorId(t,e))},t.prototype.enable=function(){this.registry.forEach((function(t){t.enable()}))},t.prototype.disable=function(){this.registry.forEach((function(t){t.disable()}))},t.prototype.clear=function(){this.elementIdMap=new WeakMap,this.registry.clear()},t}();!function(t){t[t.HandlerDisabled=0]="HandlerDisabled",t[t.HandlerEnabled=1]="HandlerEnabled"}(ot||(ot={}));var st=function(){function t(t){this.registry=new at,this.subscribers=new Set,this.options=t}return t.prototype.listen=function(t){var e=this;return this.subscribers.add(t),function(){return e.subscribers.delete(t)}},t.prototype.disable=function(){this.registry.disable(),this.subscribers.forEach((function(t){t(ot.HandlerDisabled)}))},t.prototype.enable=function(){this.registry.enable(),this.subscribers.forEach((function(t){t(ot.HandlerEnabled)}))},t.prototype.cleanup=function(){this.disable(),this.subscribers.clear(),this.registry.clear()},t.prototype.addCraftEventListener=function(t,e,n,r){var o=function(r){(function(t,e,n){t.craft||(t.craft={stopPropagation:function(){},blockedEvents:{}});for(var r=t.craft&&t.craft.blockedEvents[e]||[],o=0;o<r.length;o++){var i=r[o];if(n!==i&&n.contains(i))return!0}return!1})(r,e,t)||(r.craft.stopPropagation=function(){r.craft.blockedEvents[e]||(r.craft.blockedEvents[e]=[]),r.craft.blockedEvents[e].push(t)},n(r))};return t.addEventListener(e,o,r),function(){return t.removeEventListener(e,o,r)}},Object.defineProperty(t.prototype,"connectors",{get:function(){var t=this,e=this.handlers();return Object.keys(e).reduce((function(n,r){var o;return z(z({},n),((o={})[r]=function(n,o,i){return t.registry.register(n,{required:o,name:r,options:i,connector:e[r]}),n},o))}),{})},enumerable:!0,configurable:!0}),t.prototype.derive=function(t,e){return new t(this,e)},t.prototype.createProxyHandlers=function(t,e){var n=[],r=t.handlers();return e(new Proxy(r,{get:function(t,e,o){return e in r==0?Reflect.get(t,e,o):function(t){for(var o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];var a=r[e].apply(r,B([t],o));a&&n.push(a)}}})),function(){n.forEach((function(t){t()}))}},t.prototype.reflect=function(t){return this.createProxyHandlers(this,t)},t}(),ct=function(t){function e(e,n){var r=t.call(this,n)||this;return r.derived=e,r.options=n,r.unsubscribeParentHandlerListener=r.derived.listen((function(t){switch(t){case ot.HandlerEnabled:return r.enable();case ot.HandlerDisabled:return r.disable();default:return}})),r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}W(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e.prototype.inherit=function(t){return this.createProxyHandlers(this.derived,t)},e.prototype.cleanup=function(){t.prototype.cleanup.call(this),this.unsubscribeParentHandlerListener()},e}(st);function ut(t,e){e&&("function"==typeof t?t(e):t.current=e)}function lt(t,e){var n=t.ref;return m("string"!=typeof n,"Cannot connect to an element with an existing string ref. Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. Read more: https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute"),d(t,n?{ref:function(t){ut(n,t),ut(e,t)}}:{ref:e})}function pt(t){if("string"!=typeof t.type)throw new Error}function ft(t){return function(e){void 0===e&&(e=null);for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(!h(e)){if(!e)return;var o=e;return o&&t.apply(void 0,B([o],n)),o}var i=e;return pt(i),lt(i,t)}}function dt(t){return Object.keys(t).reduce((function(e,n){return e[n]=ft((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t[n].apply(t,e)})),e}),{})}var ht=function(t){var e=t.parentDom,n=a.createElement("div",{style:z({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},t.style)});return e&&e.ownerDocument!==document?v.createPortal(n,e.ownerDocument.body):n},yt=function(t){p(t,[])},gt=function(t,e){var n="Deprecation warning: "+t+" will be deprecated in future relases.",r=e.suggest,o=e.doc;r&&(n+=" Please use "+r+" instead."),o&&(n+="("+o+")"),console.warn(n)};export{E as DEPRECATED_ROOT_NODE,ct as DerivedEventHandlers,j as ERROR_CANNOT_DRAG,S as ERROR_DELETE_TOP_LEVEL_NODE,U as ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER,R as ERROR_DUPLICATE_NODEID,L as ERROR_INFINITE_CANVAS,w as ERROR_INVALID_NODEID,_ as ERROR_INVALID_NODE_ID,I as ERROR_MISSING_PLACEHOLDER_PLACEMENT,C as ERROR_MOVE_CANNOT_DROP,H as ERROR_MOVE_INCOMING_PARENT,D as ERROR_MOVE_NONCANVAS_CHILD,P as ERROR_MOVE_OUTGOING_PARENT,N as ERROR_MOVE_ROOT_NODE,x as ERROR_MOVE_TOP_LEVEL_NODE,k as ERROR_MOVE_TO_DESCENDANT,M as ERROR_MOVE_TO_NONCANVAS_PARENT,O as ERROR_NOPARENT,A as ERROR_NOT_IN_RESOLVER,q as ERROR_RESOLVER_NOT_AN_OBJECT,T as ERROR_TOP_LEVEL_ELEMENT_NO_ID,G as ERROR_USE_EDITOR_OUTSIDE_OF_EDITOR_CONTEXT,Y as ERROR_USE_NODE_OUTSIDE_OF_EDITOR_CONTEXT,ot as EventHandlerUpdates,st as EventHandlers,F as HISTORY_ACTIONS,J as History,b as ROOT_NODE,ht as RenderIndicator,lt as cloneWithRef,Q as createQuery,gt as deprecationWarning,Z as getComputedStyle,et as getDOMInfo,tt as getDOMMargin,$ as getDOMPadding,it as getRandomId,nt as styleInFlow,rt as useCollector,yt as useEffectOnce,K as useMethods,dt as wrapConnectorHooks,ft as wrapHookToRecognizeElement};
import t,{applyPatches as e,enableMapSet as n,enablePatches as r,produceWithPatches as i}from"immer";import o from"lodash/isEqualWith";import a,{useMemo as s,useRef as c,useReducer as u,useCallback as l,useEffect as p,useState as f,cloneElement as d,isValidElement as h}from"react";import y from"shallowequal";import{nanoid as g}from"nanoid";import m from"tiny-invariant";import v from"react-dom";var b="ROOT",E="canvas-ROOT",w="Parent id cannot be ommited",O="Attempting to add a node with duplicated id",R="Node does not exist, it may have been removed",T='A <Element /> that is used inside a User Component must specify an `id` prop, eg: <Element id="text_element">...</Element> ',C="Placeholder required placement info (parent, index, or where) is missing",I="Node cannot be dropped into target parent",H="Target parent rejects incoming node",D="Current parent rejects outgoing node",P="Cannot move node that is not a direct child of a Canvas node",x="Cannot move node into a non-Canvas parent",N="A top-level Node cannot be moved",A="Root Node cannot be moved",k="Cannot move node into a descendant",L="The component type specified for this node (%node_type%) does not exist in the resolver",M="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",S="The node has specified a canDrag() rule that prevents it from being dragged",_="Invalid parameter Node Id specified",j="Attempting to delete a top-level Node",U="Resolver in <Editor /> has to be an object. For (de)serialization Craft.js needs a list of all the User Components. \n \nMore info: https://craft.js.org/r/docs/api/editor#props",q="An Error occurred while deserializing components: Cannot find component <%displayName% /> in resolver map. Please check your resolver in <Editor />\n\nAvailable components in resolver: %availableComponents%\n\nMore info: https://craft.js.org/r/docs/api/editor#props",G="You can only use useEditor in the context of <Editor />. \n\nPlease only use useEditor in components that are children of the <Editor /> component.",Y="You can only use useNode in the context of <Editor />. \n\nPlease only use useNode in components that are children of the <Editor /> component.",B=function(t,e){return(B=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)},W=function(){return(W=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function z(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),i=0;for(e=0;e<n;e++)for(var o=arguments[e],a=0,s=o.length;a<s;a++,i++)r[i]=o[a];return r}var F={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE",MERGE:"HISTORY_MERGE",CLEAR:"HISTORY_CLEAR"},J=function(){function t(){this.timeline=[],this.pointer=-1}return t.prototype.add=function(t,e){0===t.length&&0===e.length||(this.pointer=this.pointer+1,this.timeline.length=this.pointer,this.timeline[this.pointer]={patches:t,inversePatches:e,timestamp:Date.now()})},t.prototype.throttleAdd=function(t,e,n){if(void 0===n&&(n=500),0!==t.length||0!==e.length){if(this.timeline.length&&this.pointer>=0){var r=this.timeline[this.pointer],i=r.patches,o=r.inversePatches,a=r.timestamp;if((new Date).getTime()-a<n)return void(this.timeline[this.pointer]={timestamp:a,patches:z(i,t),inversePatches:z(e,o)})}this.add(t,e)}},t.prototype.merge=function(t,e){if(0!==t.length||0!==e.length)if(this.timeline.length&&this.pointer>=0){var n=this.timeline[this.pointer],r=n.inversePatches;this.timeline[this.pointer]={timestamp:n.timestamp,patches:z(n.patches,t),inversePatches:z(e,r)}}else this.add(t,e)},t.prototype.clear=function(){this.timeline=[],this.pointer=-1},t.prototype.canUndo=function(){return this.pointer>=0},t.prototype.canRedo=function(){return this.pointer<this.timeline.length-1},t.prototype.undo=function(t){if(this.canUndo()){var n=this.timeline[this.pointer].inversePatches;return this.pointer=this.pointer-1,e(t,n)}},t.prototype.redo=function(t){if(this.canRedo())return this.pointer=this.pointer+1,e(t,this.timeline[this.pointer].patches)},t}();function K(e,n,r,o){var a,f=s((function(){return new J}),[]),d=c([]),h=c();"function"==typeof e?a=e:(a=e.methods,d.current=e.ignoreHistoryForActions,h.current=e.normalizeHistory);var y=c(o);y.current=o;var g=s((function(){var e=h.current,n=d.current,o=y.current;return[function(s,c){var u,l=r&&Q(r,(function(){return s}),f),p=i(s,(function(t){var e,n;switch(c.type){case F.UNDO:return f.undo(t);case F.REDO:return f.redo(t);case F.CLEAR:return f.clear(),W({},t);case F.IGNORE:case F.MERGE:case F.THROTTLE:var r=c.payload,i=r[0],o=r.slice(1);(e=a(t,l))[i].apply(e,o);break;default:(n=a(t,l))[c.type].apply(n,c.payload)}})),d=p[0],h=p[1],y=p[2];return u=d,o&&o(d,s,{type:c.type,params:c.payload,patches:h},l,(function(t){var e=i(d,t);u=e[0],h=z(h,e[1]),y=z(e[2],y)})),[F.UNDO,F.REDO].includes(c.type)&&e&&(u=t(u,e)),z(n,[F.UNDO,F.REDO,F.IGNORE,F.CLEAR]).includes(c.type)||(c.type===F.THROTTLE?f.throttleAdd(h,y,c.config&&c.config.rate):c.type===F.MERGE?f.merge(h,y):f.add(h,y)),u},a]}),[f,a,r]),m=g[1],v=u(g[0],n),b=v[0],E=v[1],w=c();w.current=b;var O=s((function(){return r?Q(r,(function(){return w.current}),f):[]}),[f,r]),R=s((function(){var t=Object.keys(m(null,null)),e=d.current;return W(W({},t.reduce((function(t,e){return t[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return E({type:e,payload:t})},t}),{})),{history:{undo:function(){return E({type:F.UNDO})},redo:function(){return E({type:F.REDO})},clear:function(){return E({type:F.CLEAR})},throttle:function(n){return W({},t.filter((function(t){return!e.includes(t)})).reduce((function(t,e){return t[e]=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return E({type:F.THROTTLE,payload:z([e],t),config:{rate:n}})},t}),{}))},ignore:function(){return W({},t.filter((function(t){return!e.includes(t)})).reduce((function(t,e){return t[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return E({type:F.IGNORE,payload:z([e],t)})},t}),{}))},merge:function(){return W({},t.filter((function(t){return!e.includes(t)})).reduce((function(t,e){return t[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return E({type:F.MERGE,payload:z([e],t)})},t}),{}))}}})}),[m]),T=l((function(){return w.current}),[]),C=s((function(){return new V(T)}),[T]);return p((function(){w.current=b,C.notify()}),[b,C]),s((function(){return{getState:T,subscribe:function(t,e,n){return C.subscribe(t,e,n)},actions:R,query:O,history:f}}),[R,O,C,T,f])}function Q(t,e,n){var r=Object.keys(t()).reduce((function(n,r){var i;return W(W({},n),((i={})[r]=function(){for(var n,i=[],o=0;o<arguments.length;o++)i[o]=arguments[o];return(n=t(e()))[r].apply(n,i)},i))}),{});return W(W({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}n(),r();var V=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e,n){var r=this,i=new X((function(){return t(r.getState())}),e,n);return this.subscribers.push(i),this.unsubscribe.bind(this,i)},t.prototype.unsubscribe=function(t){if(this.subscribers.length){var e=this.subscribers.indexOf(t);if(e>-1)return this.subscribers.splice(e,1)}},t.prototype.notify=function(){this.subscribers.forEach((function(t){return t.collect()}))},t}(),X=function(){function t(t,e,n){void 0===n&&(n=!1),this.collector=t,this.onChange=e,n&&this.collect()}return t.prototype.collect=function(){try{var t=this.collector();o(t,this.collected)||(this.collected=t,this.onChange&&this.onChange(this.collected))}catch(t){console.warn(t)}},t}(),Z=function(t){var e=t.getBoundingClientRect(),n=e.x,r=e.y,i=e.top,o=e.left,a=e.bottom,s=e.right,c=e.width,u=e.height,l=window.getComputedStyle(t),p={left:parseInt(l.marginLeft),right:parseInt(l.marginRight),bottom:parseInt(l.marginBottom),top:parseInt(l.marginTop)},f={left:parseInt(l.paddingLeft),right:parseInt(l.paddingRight),bottom:parseInt(l.paddingBottom),top:parseInt(l.paddingTop)};return{x:n,y:r,top:i,left:o,bottom:a,right:s,width:c,height:u,outerWidth:Math.round(c+p.left+p.right),outerHeight:Math.round(u+p.top+p.bottom),margin:p,padding:f,inFlow:t.parentElement&&!!function(e){var n=getComputedStyle(e);if(!(l.overflow&&"visible"!==l.overflow||"none"!==n.float||"grid"===n.display||"flex"===n.display&&"column"!==n["flex-direction"])){switch(l.position){case"static":case"relative":break;default:return}switch(t.tagName){case"TR":case"TBODY":case"THEAD":case"TFOOT":return!0}switch(l.display){case"block":case"list-item":case"table":case"flex":case"grid":return!0}}}(t.parentElement)}};function $(t,e){var n=t.subscribe,r=t.getState,i=t.actions,o=t.query,a=c(!0),s=c(null),u=c(e);u.current=e;var d=l((function(t){return W(W({},t),{actions:i,query:o})}),[i,o]);a.current&&e&&(s.current=e(r(),o),a.current=!1);var h=f(d(s.current)),y=h[0],g=h[1];return p((function(){var t;return u.current&&(t=n((function(t){return u.current(t,o)}),(function(t){g(d(t))}))),function(){t&&t()}}),[d,o,n]),y}var tt,et=function(t){return void 0===t&&(t=10),g(t)},nt=function(){function t(){this.elementIdMap=new WeakMap,this.registry=new Map}return t.prototype.getElementId=function(t){var e=this.elementIdMap.get(t);if(e)return e;var n=et();return this.elementIdMap.set(t,n),n},t.prototype.getConnectorId=function(t,e){return e+"--"+this.getElementId(t)},t.prototype.register=function(t,e){var n=this,r=this.getByElement(t,e.name);if(r){if(y(e.required,r.required))return r;this.getByElement(t,e.name).disable()}var i=null,o=this.getConnectorId(t,e.name);return this.registry.set(o,{id:o,required:e.required,enable:function(){i&&i(),i=e.connector(t,e.required,e.options)},disable:function(){i&&i()},remove:function(){return n.remove(o)}}),this.registry.get(o).enable(),this.registry.get(o)},t.prototype.get=function(t){return this.registry.get(t)},t.prototype.remove=function(t){var e=this.get(t);e&&(e.disable(),this.registry.delete(e.id))},t.prototype.enable=function(){this.registry.forEach((function(t){t.enable()}))},t.prototype.disable=function(){this.registry.forEach((function(t){t.disable()}))},t.prototype.getByElement=function(t,e){return this.get(this.getConnectorId(t,e))},t.prototype.removeByElement=function(t,e){return this.remove(this.getConnectorId(t,e))},t.prototype.clear=function(){this.disable(),this.elementIdMap=new WeakMap,this.registry=new Map},t}();!function(t){t[t.HandlerDisabled=0]="HandlerDisabled",t[t.HandlerEnabled=1]="HandlerEnabled"}(tt||(tt={}));var rt=function(){function t(t){this.registry=new nt,this.subscribers=new Set,this.options=t}return t.prototype.listen=function(t){var e=this;return this.subscribers.add(t),function(){return e.subscribers.delete(t)}},t.prototype.disable=function(){this.onDisable&&this.onDisable(),this.registry.disable(),this.subscribers.forEach((function(t){t(tt.HandlerDisabled)}))},t.prototype.enable=function(){this.onEnable&&this.onEnable(),this.registry.enable(),this.subscribers.forEach((function(t){t(tt.HandlerEnabled)}))},t.prototype.cleanup=function(){this.disable(),this.subscribers.clear(),this.registry.clear()},t.prototype.addCraftEventListener=function(t,e,n,r){var i=function(r){(function(t,e,n){t.craft||(t.craft={stopPropagation:function(){},blockedEvents:{}});for(var r=t.craft&&t.craft.blockedEvents[e]||[],i=0;i<r.length;i++){var o=r[i];if(n!==o&&n.contains(o))return!0}return!1})(r,e,t)||(r.craft.stopPropagation=function(){r.craft.blockedEvents[e]||(r.craft.blockedEvents[e]=[]),r.craft.blockedEvents[e].push(t)},n(r))};return t.addEventListener(e,i,r),function(){return t.removeEventListener(e,i,r)}},t.prototype.createConnectorsUsage=function(){var t=this,e=this.handlers(),n=new Set;return{connectors:Object.entries(e).reduce((function(e,r){var i,o=r[0],a=r[1];return W(W({},e),((i={})[o]=function(e,r,i){var s=t.registry.register(e,{required:r,name:o,options:i,connector:a});return n.add(s.id),e},i))}),{}),cleanup:function(){n.forEach((function(e){return t.registry.remove(e)}))}}},t.prototype.derive=function(t,e){return new t(this,e)},t.prototype.createProxyHandlers=function(t,e){var n=[],r=t.handlers();return e(new Proxy(r,{get:function(t,e,i){return e in r==0?Reflect.get(t,e,i):function(t){for(var i=[],o=1;o<arguments.length;o++)i[o-1]=arguments[o];var a=r[e].apply(r,z([t],i));a&&n.push(a)}}})),function(){n.forEach((function(t){t()}))}},t.prototype.reflect=function(t){return this.createProxyHandlers(this,t)},t}(),it=function(t){function e(e,n){var r=t.call(this,n)||this;return r.derived=e,r.options=n,r.unsubscribeParentHandlerListener=r.derived.listen((function(t){switch(t){case tt.HandlerEnabled:return r.enable();case tt.HandlerDisabled:return r.disable();default:return}})),r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}B(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e.prototype.inherit=function(t){return this.createProxyHandlers(this.derived,t)},e.prototype.cleanup=function(){t.prototype.cleanup.call(this),this.unsubscribeParentHandlerListener()},e}(rt);function ot(t,e){e&&("function"==typeof t?t(e):t.current=e)}function at(t,e){var n=t.ref;return m("string"!=typeof n,"Cannot connect to an element with an existing string ref. Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. Read more: https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute"),d(t,n?{ref:function(t){ot(n,t),ot(e,t)}}:{ref:e})}function st(t){if("string"!=typeof t.type)throw new Error}function ct(t){return function(e){void 0===e&&(e=null);for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(!h(e)){if(!e)return;var i=e;return i&&t.apply(void 0,z([i],n)),i}var o=e;return st(o),at(o,t)}}function ut(t){return Object.keys(t).reduce((function(e,n){return e[n]=ct((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t[n].apply(t,e)})),e}),{})}var lt=function(t){var e=t.parentDom,n=a.createElement("div",{style:W({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},t.style)});return e&&e.ownerDocument!==document?v.createPortal(n,e.ownerDocument.body):n},pt=function(t){p(t,[])},ft=function(t,e){var n="Deprecation warning: "+t+" will be deprecated in future relases.",r=e.suggest,i=e.doc;r&&(n+=" Please use "+r+" instead."),i&&(n+="("+i+")"),console.warn(n)},dt=function(){return"undefined"!=typeof window},ht=function(){return dt()&&/Linux/i.test(window.navigator.userAgent)},yt=function(){return dt()&&/Chrome/i.test(window.navigator.userAgent)};export{E as DEPRECATED_ROOT_NODE,it as DerivedEventHandlers,S as ERROR_CANNOT_DRAG,j as ERROR_DELETE_TOP_LEVEL_NODE,q as ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER,O as ERROR_DUPLICATE_NODEID,M as ERROR_INFINITE_CANVAS,R as ERROR_INVALID_NODEID,_ as ERROR_INVALID_NODE_ID,C as ERROR_MISSING_PLACEHOLDER_PLACEMENT,I as ERROR_MOVE_CANNOT_DROP,H as ERROR_MOVE_INCOMING_PARENT,P as ERROR_MOVE_NONCANVAS_CHILD,D as ERROR_MOVE_OUTGOING_PARENT,A as ERROR_MOVE_ROOT_NODE,N as ERROR_MOVE_TOP_LEVEL_NODE,k as ERROR_MOVE_TO_DESCENDANT,x as ERROR_MOVE_TO_NONCANVAS_PARENT,w as ERROR_NOPARENT,L as ERROR_NOT_IN_RESOLVER,U as ERROR_RESOLVER_NOT_AN_OBJECT,T as ERROR_TOP_LEVEL_ELEMENT_NO_ID,G as ERROR_USE_EDITOR_OUTSIDE_OF_EDITOR_CONTEXT,Y as ERROR_USE_NODE_OUTSIDE_OF_EDITOR_CONTEXT,tt as EventHandlerUpdates,rt as EventHandlers,F as HISTORY_ACTIONS,J as History,b as ROOT_NODE,lt as RenderIndicator,at as cloneWithRef,Q as createQuery,ft as deprecationWarning,Z as getDOMInfo,et as getRandomId,yt as isChromium,dt as isClientSide,ht as isLinux,$ as useCollector,pt as useEffectOnce,K as useMethods,ut as wrapConnectorHooks,ct as wrapHookToRecognizeElement};

@@ -16,3 +16,3 @@ export declare const ROOT_NODE = "ROOT";

export declare const ERROR_MOVE_TO_DESCENDANT = "Cannot move node into a descendant";
export declare const ERROR_NOT_IN_RESOLVER = "The component type specified for this node does not exist in the resolver";
export declare const ERROR_NOT_IN_RESOLVER = "The component type specified for this node (%node_type%) does not exist in the resolver";
export declare const ERROR_INFINITE_CANVAS = "The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.";

@@ -19,0 +19,0 @@ export declare const ERROR_CANNOT_DRAG = "The node has specified a canDrag() rule that prevents it from being dragged";

@@ -1,13 +0,2 @@

import { Connector } from './interfaces';
declare type ConnectorToRegister = {
name: string;
required: any;
options?: Record<string, any>;
connector: Connector;
};
declare type RegisteredConnector = {
required: any;
enable: () => void;
disable: () => void;
};
import { ConnectorToRegister, RegisteredConnector } from './interfaces';
/**

@@ -22,8 +11,10 @@ * Stores all connected DOM elements and their connectors here

private getConnectorId;
register(element: HTMLElement, toRegister: ConnectorToRegister): void;
get(element: HTMLElement, name: string): RegisteredConnector;
register(element: HTMLElement, connectorPayload: ConnectorToRegister): RegisteredConnector;
get(id: string): RegisteredConnector;
remove(id: string): void;
enable(): void;
disable(): void;
getByElement(element: HTMLElement, connectorName: string): RegisteredConnector;
removeByElement(element: HTMLElement, connectorName: string): void;
clear(): void;
}
export {};
import { EventHandlers } from './EventHandlers';
import { EventHandlerConnectors } from './interfaces';
export declare abstract class DerivedEventHandlers<P extends EventHandlers, O extends Record<string, any> = {}> extends EventHandlers {
export declare abstract class DerivedEventHandlers<P extends EventHandlers, O extends Record<string, any> = {}> extends EventHandlers<O> {
derived: P;
options: O;
unsubscribeParentHandlerListener: () => void;

@@ -7,0 +6,0 @@ constructor(derived: P, options?: O);

@@ -1,2 +0,2 @@

import { EventHandlerUpdates, CraftEventListener, EventHandlerConnectors } from './interfaces';
import { EventHandlerUpdates, CraftEventListener, EventHandlerConnectors, ConnectorsUsage } from './interfaces';
export declare abstract class EventHandlers<O extends Record<string, any> = {}> {

@@ -6,2 +6,4 @@ options: O;

private subscribers;
onEnable?(): void;
onDisable?(): void;
constructor(options?: O);

@@ -14,3 +16,6 @@ listen(cb: (msg: EventHandlerUpdates) => void): () => boolean;

abstract handlers(): Record<string, (el: HTMLElement, ...args: any[]) => any>;
readonly connectors: EventHandlerConnectors<this>;
/**
* Creates a record of chainable connectors and tracks their usages
*/
createConnectorsUsage(): ConnectorsUsage<this>;
derive<C extends EventHandlers>(type: {

@@ -17,0 +22,0 @@ new (...args: any[]): C;

@@ -15,3 +15,7 @@ import { EventHandlers } from './EventHandlers';

export declare type CraftEventListener<K extends keyof HTMLElementEventMap> = (ev: CraftDOMEvent<HTMLElementEventMap[K]>) => any;
export declare type EventHandlerConnectors<H extends EventHandlers> = ChainableConnectors<ReturnType<H['handlers']>>;
export declare type EventHandlerConnectors<H extends EventHandlers, E extends any = HTMLElement> = ChainableConnectors<ReturnType<H['handlers']>, E>;
export declare type ConnectorsUsage<H extends EventHandlers> = {
cleanup: () => void;
connectors: EventHandlerConnectors<H>;
};
export declare enum EventHandlerUpdates {

@@ -21,1 +25,14 @@ HandlerDisabled = 0,

}
export declare type ConnectorToRegister = {
name: string;
required: any;
connector: Connector;
options?: Record<string, any>;
};
export declare type RegisteredConnector = {
id: string;
required: any;
enable: () => void;
disable: () => void;
remove: () => void;
};

@@ -1,15 +0,2 @@

export declare const getComputedStyle: (dom: HTMLElement) => CSSStyleDeclaration;
export declare const getDOMPadding: (dom: HTMLElement) => {
left: number;
right: number;
bottom: number;
top: number;
};
export declare const getDOMMargin: (dom: HTMLElement) => {
left: number;
right: number;
bottom: number;
top: number;
};
export declare const getDOMInfo: (dom: HTMLElement) => {
export declare const getDOMInfo: (el: HTMLElement) => {
x: number;

@@ -39,2 +26,1 @@ y: number;

};
export declare const styleInFlow: (el: HTMLElement, parent: HTMLElement) => boolean;

@@ -12,1 +12,2 @@ export * from './constants';

export * from './getRandomId';
export * from './platform';
{
"name": "@craftjs/utils",
"description": "Utilities used internally across the craft.js monorepo",
"version": "0.1.0-beta.20",
"version": "0.1.0",
"author": "Prev Wong <prevwong@gmail.com>",

@@ -29,5 +29,5 @@ "license": "MIT",

"peerDependencies": {
"react": "^16.8.0"
"react": ">=16.8.0"
},
"gitHead": "56b560de76759a70862524ef7e08f9c30c28d636"
"gitHead": "9d04edf369a9320bb8dc9fd93c51445059362568"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc