@craftjs/utils
Advanced tools
Comparing version 0.2.0-alpha.23 to 0.2.0-alpha.24
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.2.0-alpha.24](https://github.com/prevwong/craft.js/compare/v0.2.0-alpha.23...v0.2.0-alpha.24) (2021-05-22) | ||
### Bug Fixes | ||
* types ([bd726c7](https://github.com/prevwong/craft.js/commit/bd726c7ddb43a26381785687ff5ce11c222b2033)) | ||
# 0.2.0-alpha.23 (2021-05-14) | ||
@@ -8,0 +19,0 @@ |
@@ -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"),shortid=require("shortid"),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),shortid__default=_interopDefaultLegacy(shortid),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",_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)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function __extends(e,t){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"},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.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),d=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.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=d[0],l=d[1],R=d[2];return c=p,r&&r(p,a,{type:s.type,params:s.payload,patches:l},u,(function(e){var t=produce.produceWithPatches(p,e);c=t[0],l=__spreadArrays(l,t[1]),R=__spreadArrays(t[2],R)})),[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]).includes(s.type)||(s.type===HISTORY_ACTIONS.THROTTLE?i.throttleAdd(l,R,s.config&&s.config.rate):s.type===HISTORY_ACTIONS.MERGE?i.merge(l,R):i.add(l,R)),c},o]}),[i,o,n]),d=u[1],p=React.useReducer(u[0],t),l=p[0],R=p[1],E=React.useRef();E.current=l;var _=React.useMemo((function(){return n?createQuery(n,(function(){return E.current}),i):[]}),[i,n]),O=React.useMemo((function(){var e=Object.keys(d(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 R({type:t,payload:e})},e}),{})),{history:{undo:function(){return R({type:HISTORY_ACTIONS.UNDO})},redo:function(){return R({type:HISTORY_ACTIONS.REDO})},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 R({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 R({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 R({type:HISTORY_ACTIONS.MERGE,payload:__spreadArrays([t],e)})},e}),{}))}}})}),[d]),f=React.useCallback((function(){return E.current}),[]),h=React.useMemo((function(){return new Watcher(f)}),[f]);return React.useEffect((function(){E.current=l,h.notify()}),[l,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}(),getDOMPadding=function(e){return{left:parseInt(window.getComputedStyle(e).paddingLeft),right:parseInt(window.getComputedStyle(e).paddingRight),bottom:parseInt(window.getComputedStyle(e).paddingTop),top:parseInt(window.getComputedStyle(e).paddingBottom)}},getDOMMargin=function(e){return{left:parseInt(window.getComputedStyle(e).marginLeft),right:parseInt(window.getComputedStyle(e).marginRight),bottom:parseInt(window.getComputedStyle(e).marginTop),top:parseInt(window.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,d=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+d.left+d.right),outerHeight:Math.round(u+d.top+d.bottom),margin:d,padding:p,inFlow:e&&e.parentElement&&!!styleInFlow(e,e.parentElement)}},getComputedStyle=function(e){return window.getComputedStyle(e)},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 d=React.useState(u(s.current)),p=d[0],l=d[1];return React.useEffect((function(){var e;return c.current&&(e=n((function(e){return c.current(e,i)}),(function(e){l(u(e))}))),function(){e&&e()}}),[u,i,n]),p}var 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=shortid__default.default();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.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.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"),shortid=require("shortid"),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),shortid__default=_interopDefaultLegacy(shortid),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",_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"},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.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),d=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.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=d[0],l=d[1],R=d[2];return c=p,r&&r(p,a,{type:s.type,params:s.payload,patches:l},u,(function(e){var t=produce.produceWithPatches(p,e);c=t[0],l=__spreadArrays(l,t[1]),R=__spreadArrays(t[2],R)})),[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]).includes(s.type)||(s.type===HISTORY_ACTIONS.THROTTLE?i.throttleAdd(l,R,s.config&&s.config.rate):s.type===HISTORY_ACTIONS.MERGE?i.merge(l,R):i.add(l,R)),c},o]}),[i,o,n]),d=u[1],p=React.useReducer(u[0],t),l=p[0],R=p[1],E=React.useRef();E.current=l;var _=React.useMemo((function(){return n?createQuery(n,(function(){return E.current}),i):[]}),[i,n]),f=React.useMemo((function(){var e=Object.keys(d(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 R({type:t,payload:e})},e}),{})),{history:{undo:function(){return R({type:HISTORY_ACTIONS.UNDO})},redo:function(){return R({type:HISTORY_ACTIONS.REDO})},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 R({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 R({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 R({type:HISTORY_ACTIONS.MERGE,payload:__spreadArrays([t],e)})},e}),{}))}}})}),[d]),O=React.useCallback((function(){return E.current}),[]),h=React.useMemo((function(){return new Watcher(O)}),[O]);return React.useEffect((function(){E.current=l,h.notify()}),[l,h]),React.useMemo((function(){return{getState:O,subscribe:function(e,t,n){return h.subscribe(e,t,n)},actions:f,query:_,history:i}}),[f,_,h,O,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}(),getDOMPadding=function(e){return{left:parseInt(window.getComputedStyle(e).paddingLeft),right:parseInt(window.getComputedStyle(e).paddingRight),bottom:parseInt(window.getComputedStyle(e).paddingTop),top:parseInt(window.getComputedStyle(e).paddingBottom)}},getDOMMargin=function(e){return{left:parseInt(window.getComputedStyle(e).marginLeft),right:parseInt(window.getComputedStyle(e).marginRight),bottom:parseInt(window.getComputedStyle(e).marginTop),top:parseInt(window.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,d=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+d.left+d.right),outerHeight:Math.round(u+d.top+d.bottom),margin:d,padding:p,inFlow:e&&e.parentElement&&!!styleInFlow(e,e.parentElement)}},getComputedStyle=function(e){return window.getComputedStyle(e)},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 d=React.useState(u(s.current)),p=d[0],l=d[1];return React.useEffect((function(){var e;return c.current&&(e=n((function(e){return c.current(e,i)}),(function(e){l(u(e))}))),function(){e&&e()}}),[u,i,n]),p}var 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=shortid__default.default();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.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.styleInFlow=styleInFlow,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 i}from"immer";import o from"lodash/isEqualWith";import a,{useMemo as s,useRef as c,useReducer as u,useCallback as p,useEffect as d,useState as l,cloneElement as f,isValidElement as h}from"react";import g from"shallowequal";import y from"shortid";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",M="Cannot move node that is not a direct child of a Canvas node",P="Cannot move node into a non-Canvas parent",S="A top-level Node cannot be moved",k="Root Node cannot be moved",x="Cannot move node into a descendant",N="The component type specified for this node does not exist in the resolver",j="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",_="The node has specified a canDrag() rule that prevents it from being dragged",q="Invalid parameter Node Id specified",A="Attempting to delete a top-level Node",L="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=function(t,e){return(G=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)},Y=function(){return(Y=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 W(){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 z={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE",MERGE:"HISTORY_MERGE"},B=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:W(i,t),inversePatches:W(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:W(n.patches,t),inversePatches:W(e,r)}}else this.add(t,e)},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 F(e,n,r,o){var a,l=s((function(){return new B}),[]),f=c([]),h=c();"function"==typeof e?a=e:(a=e.methods,f.current=e.ignoreHistoryForActions,h.current=e.normalizeHistory);var g=c(o);g.current=o;var y=s((function(){var e=h.current,n=f.current,o=g.current;return[function(s,c){var u,p=r&&J(r,(function(){return s}),l),d=i(s,(function(t){var e,n;switch(c.type){case z.UNDO:return l.undo(t);case z.REDO:return l.redo(t);case z.IGNORE:case z.MERGE:case z.THROTTLE:var r=c.payload,i=r[0],o=r.slice(1);(e=a(t,p))[i].apply(e,o);break;default:(n=a(t,p))[c.type].apply(n,c.payload)}})),f=d[0],h=d[1],g=d[2];return u=f,o&&o(f,s,{type:c.type,params:c.payload,patches:h},p,(function(t){var e=i(f,t);u=e[0],h=W(h,e[1]),g=W(e[2],g)})),[z.UNDO,z.REDO].includes(c.type)&&e&&(u=t(u,e)),W(n,[z.UNDO,z.REDO,z.IGNORE]).includes(c.type)||(c.type===z.THROTTLE?l.throttleAdd(h,g,c.config&&c.config.rate):c.type===z.MERGE?l.merge(h,g):l.add(h,g)),u},a]}),[l,a,r]),m=y[1],v=u(y[0],n),b=v[0],E=v[1],w=c();w.current=b;var O=s((function(){return r?J(r,(function(){return w.current}),l):[]}),[l,r]),R=s((function(){var t=Object.keys(m(null,null)),e=f.current;return Y(Y({},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:z.UNDO})},redo:function(){return E({type:z.REDO})},throttle:function(n){return Y({},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:z.THROTTLE,payload:W([e],t),config:{rate:n}})},t}),{}))},ignore:function(){return Y({},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:z.IGNORE,payload:W([e],t)})},t}),{}))},merge:function(){return Y({},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:z.MERGE,payload:W([e],t)})},t}),{}))}}})}),[m]),T=p((function(){return w.current}),[]),C=s((function(){return new K(T)}),[T]);return d((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:l}}),[R,O,C,T,l])}function J(t,e,n){var r=Object.keys(t()).reduce((function(n,r){var i;return Y(Y({},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 Y(Y({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}n(),r();var K=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e,n){var r=this,i=new Q((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}(),Q=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}(),V=function(t){return{left:parseInt(window.getComputedStyle(t).paddingLeft),right:parseInt(window.getComputedStyle(t).paddingRight),bottom:parseInt(window.getComputedStyle(t).paddingTop),top:parseInt(window.getComputedStyle(t).paddingBottom)}},X=function(t){return{left:parseInt(window.getComputedStyle(t).marginLeft),right:parseInt(window.getComputedStyle(t).marginRight),bottom:parseInt(window.getComputedStyle(t).marginTop),top:parseInt(window.getComputedStyle(t).marginBottom)}},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,p=X(t),d=V(t);return{x:Math.round(n),y:Math.round(r),top:Math.round(i),left:Math.round(o),bottom:Math.round(a),right:Math.round(s),width:Math.round(c),height:Math.round(u),outerWidth:Math.round(c+p.left+p.right),outerHeight:Math.round(u+p.top+p.bottom),margin:p,padding:d,inFlow:t&&t.parentElement&&!!tt(t,t.parentElement)}},$=function(t){return window.getComputedStyle(t)},tt=function(t,e){var n=$(t),r=$(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 et(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 f=p((function(t){return Y(Y({},t),{actions:i,query:o})}),[i,o]);a.current&&e&&(s.current=e(r(),o),a.current=!1);var h=l(f(s.current)),g=h[0],y=h[1];return d((function(){var t;return u.current&&(t=n((function(t){return u.current(t,o)}),(function(t){y(f(t))}))),function(){t&&t()}}),[f,o,n]),g}var nt,rt=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=y();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(g(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"}(nt||(nt={}));var it=function(){function t(t){this.registry=new rt,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(nt.HandlerDisabled)}))},t.prototype.enable=function(){this.registry.enable(),this.subscribers.forEach((function(t){t(nt.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)}},Object.defineProperty(t.prototype,"connectors",{get:function(){var t=this,e=this.handlers();return Object.keys(e).reduce((function(n,r){var i;return Y(Y({},n),((i={})[r]=function(n,i,o){return t.registry.register(n,{required:i,name:r,options:o,connector:e[r]}),n},i))}),{})},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,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,W([t],i));a&&n.push(a)}}})),function(){n.forEach((function(t){t()}))}},t.prototype.reflect=function(t){return this.createProxyHandlers(this,t)},t}(),ot=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 nt.HandlerEnabled:return r.enable();case nt.HandlerDisabled:return r.disable();default:return}})),r}return function(t,e){function n(){this.constructor=t}G(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}(it);function at(t,e){e&&("function"==typeof t?t(e):t.current=e)}function st(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"),f(t,n?{ref:function(t){at(n,t),at(e,t)}}:{ref:e})}function ct(t){if("string"!=typeof t.type)throw new Error}function ut(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,W([i],n)),i}var o=e;return ct(o),st(o,t)}}function pt(t){return Object.keys(t).reduce((function(e,n){return e[n]=ut((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t[n].apply(t,e)})),e}),{})}var dt=function(t){var e=t.parentDom,n=a.createElement("div",{style:Y({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},lt=function(t){d(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)};export{E as DEPRECATED_ROOT_NODE,ot as DerivedEventHandlers,_ as ERROR_CANNOT_DRAG,A as ERROR_DELETE_TOP_LEVEL_NODE,U as ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER,O as ERROR_DUPLICATE_NODEID,j as ERROR_INFINITE_CANVAS,R as ERROR_INVALID_NODEID,q as ERROR_INVALID_NODE_ID,C as ERROR_MISSING_PLACEHOLDER_PLACEMENT,I as ERROR_MOVE_CANNOT_DROP,H as ERROR_MOVE_INCOMING_PARENT,M as ERROR_MOVE_NONCANVAS_CHILD,D as ERROR_MOVE_OUTGOING_PARENT,k as ERROR_MOVE_ROOT_NODE,S as ERROR_MOVE_TOP_LEVEL_NODE,x as ERROR_MOVE_TO_DESCENDANT,P as ERROR_MOVE_TO_NONCANVAS_PARENT,w as ERROR_NOPARENT,N as ERROR_NOT_IN_RESOLVER,L as ERROR_RESOLVER_NOT_AN_OBJECT,T as ERROR_TOP_LEVEL_ELEMENT_NO_ID,nt as EventHandlerUpdates,it as EventHandlers,z as HISTORY_ACTIONS,B as History,b as ROOT_NODE,dt as RenderIndicator,st as cloneWithRef,J as createQuery,ft as deprecationWarning,$ as getComputedStyle,Z as getDOMInfo,X as getDOMMargin,V as getDOMPadding,tt as styleInFlow,et as useCollector,lt as useEffectOnce,F as useMethods,pt as wrapConnectorHooks,ut as wrapHookToRecognizeElement}; | ||
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 p,useEffect as l,useState as d,cloneElement as f,isValidElement as h}from"react";import g from"shallowequal";import y from"shortid";import m from"tiny-invariant";import v from"react-dom";var b="ROOT",w="canvas-ROOT",E="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",M="Cannot move node that is not a direct child of a Canvas node",P="Cannot move node into a non-Canvas parent",S="A top-level Node cannot be moved",x="Root Node cannot be moved",k="Cannot move node into a descendant",N="The component type specified for this node does not exist in the resolver",j="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",_="The node has specified a canDrag() rule that prevents it from being dragged",q="Invalid parameter Node Id specified",A="Attempting to delete a top-level Node",L="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=function(t,e){return(G=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)},Y=function(){return(Y=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 W(){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 z={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE",MERGE:"HISTORY_MERGE"},B=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:W(o,t),inversePatches:W(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:W(n.patches,t),inversePatches:W(e,r)}}else this.add(t,e)},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 F(e,n,r,i){var a,d=s((function(){return new B}),[]),f=c([]),h=c();"function"==typeof e?a=e:(a=e.methods,f.current=e.ignoreHistoryForActions,h.current=e.normalizeHistory);var g=c(i);g.current=i;var y=s((function(){var e=h.current,n=f.current,i=g.current;return[function(s,c){var u,p=r&&J(r,(function(){return s}),d),l=o(s,(function(t){var e,n;switch(c.type){case z.UNDO:return d.undo(t);case z.REDO:return d.redo(t);case z.IGNORE:case z.MERGE:case z.THROTTLE:var r=c.payload,o=r[0],i=r.slice(1);(e=a(t,p))[o].apply(e,i);break;default:(n=a(t,p))[c.type].apply(n,c.payload)}})),f=l[0],h=l[1],g=l[2];return u=f,i&&i(f,s,{type:c.type,params:c.payload,patches:h},p,(function(t){var e=o(f,t);u=e[0],h=W(h,e[1]),g=W(e[2],g)})),[z.UNDO,z.REDO].includes(c.type)&&e&&(u=t(u,e)),W(n,[z.UNDO,z.REDO,z.IGNORE]).includes(c.type)||(c.type===z.THROTTLE?d.throttleAdd(h,g,c.config&&c.config.rate):c.type===z.MERGE?d.merge(h,g):d.add(h,g)),u},a]}),[d,a,r]),m=y[1],v=u(y[0],n),b=v[0],w=v[1],E=c();E.current=b;var O=s((function(){return r?J(r,(function(){return E.current}),d):[]}),[d,r]),R=s((function(){var t=Object.keys(m(null,null)),e=f.current;return Y(Y({},t.reduce((function(t,e){return t[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return w({type:e,payload:t})},t}),{})),{history:{undo:function(){return w({type:z.UNDO})},redo:function(){return w({type:z.REDO})},throttle:function(n){return Y({},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 w({type:z.THROTTLE,payload:W([e],t),config:{rate:n}})},t}),{}))},ignore:function(){return Y({},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 w({type:z.IGNORE,payload:W([e],t)})},t}),{}))},merge:function(){return Y({},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 w({type:z.MERGE,payload:W([e],t)})},t}),{}))}}})}),[m]),T=p((function(){return E.current}),[]),C=s((function(){return new K(T)}),[T]);return l((function(){E.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:d}}),[R,O,C,T,d])}function J(t,e,n){var r=Object.keys(t()).reduce((function(n,r){var o;return Y(Y({},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 Y(Y({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}n(),r();var K=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e,n){var r=this,o=new Q((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}(),Q=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}(),V=function(t){return{left:parseInt(window.getComputedStyle(t).paddingLeft),right:parseInt(window.getComputedStyle(t).paddingRight),bottom:parseInt(window.getComputedStyle(t).paddingTop),top:parseInt(window.getComputedStyle(t).paddingBottom)}},X=function(t){return{left:parseInt(window.getComputedStyle(t).marginLeft),right:parseInt(window.getComputedStyle(t).marginRight),bottom:parseInt(window.getComputedStyle(t).marginTop),top:parseInt(window.getComputedStyle(t).marginBottom)}},Z=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,p=X(t),l=V(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+p.left+p.right),outerHeight:Math.round(u+p.top+p.bottom),margin:p,padding:l,inFlow:t&&t.parentElement&&!!tt(t,t.parentElement)}},$=function(t){return window.getComputedStyle(t)},tt=function(t,e){var n=$(t),r=$(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 et(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 f=p((function(t){return Y(Y({},t),{actions:o,query:i})}),[o,i]);a.current&&e&&(s.current=e(r(),i),a.current=!1);var h=d(f(s.current)),g=h[0],y=h[1];return l((function(){var t;return u.current&&(t=n((function(t){return u.current(t,i)}),(function(t){y(f(t))}))),function(){t&&t()}}),[f,i,n]),g}var nt,rt=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=y();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(g(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"}(nt||(nt={}));var ot=function(){function t(t){this.registry=new rt,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(nt.HandlerDisabled)}))},t.prototype.enable=function(){this.registry.enable(),this.subscribers.forEach((function(t){t(nt.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 Y(Y({},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,W([t],o));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 nt.HandlerEnabled:return r.enable();case nt.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}G(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}(ot);function at(t,e){e&&("function"==typeof t?t(e):t.current=e)}function st(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"),f(t,n?{ref:function(t){at(n,t),at(e,t)}}:{ref:e})}function ct(t){if("string"!=typeof t.type)throw new Error}function ut(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,W([o],n)),o}var i=e;return ct(i),st(i,t)}}function pt(t){return Object.keys(t).reduce((function(e,n){return e[n]=ut((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:Y({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},dt=function(t){l(t,[])},ft=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{w as DEPRECATED_ROOT_NODE,it as DerivedEventHandlers,_ as ERROR_CANNOT_DRAG,A as ERROR_DELETE_TOP_LEVEL_NODE,U as ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER,O as ERROR_DUPLICATE_NODEID,j as ERROR_INFINITE_CANVAS,R as ERROR_INVALID_NODEID,q as ERROR_INVALID_NODE_ID,C as ERROR_MISSING_PLACEHOLDER_PLACEMENT,I as ERROR_MOVE_CANNOT_DROP,H as ERROR_MOVE_INCOMING_PARENT,M as ERROR_MOVE_NONCANVAS_CHILD,D as ERROR_MOVE_OUTGOING_PARENT,x as ERROR_MOVE_ROOT_NODE,S as ERROR_MOVE_TOP_LEVEL_NODE,k as ERROR_MOVE_TO_DESCENDANT,P as ERROR_MOVE_TO_NONCANVAS_PARENT,E as ERROR_NOPARENT,N as ERROR_NOT_IN_RESOLVER,L as ERROR_RESOLVER_NOT_AN_OBJECT,T as ERROR_TOP_LEVEL_ELEMENT_NO_ID,nt as EventHandlerUpdates,ot as EventHandlers,z as HISTORY_ACTIONS,B as History,b as ROOT_NODE,lt as RenderIndicator,st as cloneWithRef,J as createQuery,ft as deprecationWarning,$ as getComputedStyle,Z as getDOMInfo,X as getDOMMargin,V as getDOMPadding,tt as styleInFlow,et as useCollector,dt as useEffectOnce,F as useMethods,pt as wrapConnectorHooks,ut as wrapHookToRecognizeElement}; |
@@ -1,9 +0,9 @@ | ||
import { CallbacksFor, MethodsOrOptions, StateFor, QueryCallbacksFor, QueryMethods, SubscriberAndCallbacksFor } from './useMethods'; | ||
declare type Actions<M extends MethodsOrOptions, Q extends QueryMethods> = { | ||
actions: CallbacksFor<M>; | ||
query: QueryCallbacksFor<Q>; | ||
import { SubscriberAndCallbacksFor } from './useMethods'; | ||
import { ConditionallyMergeRecordTypes } from './utilityTypes'; | ||
declare type CollectorMethods<S extends SubscriberAndCallbacksFor<any, any>> = { | ||
actions: S['actions']; | ||
query: S['query']; | ||
}; | ||
export declare type useCollector<M extends MethodsOrOptions, Q extends QueryMethods | null, C = null> = C extends null ? Actions<M, Q> : C & Actions<M, Q>; | ||
export declare function useCollector<M extends MethodsOrOptions, Q extends QueryMethods | null>(store: SubscriberAndCallbacksFor<M, Q>): useCollector<M, Q>; | ||
export declare function useCollector<M extends MethodsOrOptions, Q extends QueryMethods | null, C>(store: SubscriberAndCallbacksFor<M, Q>, collector: (state: StateFor<M>, query: Q) => C): useCollector<M, Q, C>; | ||
export declare type useCollectorReturnType<S extends SubscriberAndCallbacksFor<any, any>, C = null> = ConditionallyMergeRecordTypes<C, CollectorMethods<S>>; | ||
export declare function useCollector<S extends SubscriberAndCallbacksFor<any, any>, C>(store: S, collector?: (state: ReturnType<S['getState']>['current'], query: S['query']) => C): useCollectorReturnType<S, C>; | ||
export {}; |
@@ -31,3 +31,3 @@ import { Patch } from 'immer'; | ||
}; | ||
} : never; | ||
} : {}; | ||
export declare type Methods<S = any, R extends MethodRecordBase<S> = any, Q = any> = (state: S, query: Q) => R; | ||
@@ -63,3 +63,3 @@ export declare type Options<S = any, R extends MethodRecordBase<S> = any, Q = any> = { | ||
}; | ||
} : never; | ||
} : {}; | ||
export declare type PatchListenerAction<S, M extends MethodsOrOptions> = { | ||
@@ -66,0 +66,0 @@ type: keyof CallbacksFor<M>; |
export declare type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U; | ||
export declare type Delete<T, U> = Pick<T, Exclude<keyof T, U>>; | ||
export declare type OverwriteFnReturnType<F extends (...args: any) => void, R> = (...args: Parameters<F>) => Delete<ReturnType<F>, R>; | ||
export declare type ConditionallyMergeRecordTypes<C, S extends Record<string, any>> = C extends null ? S : C & S; |
{ | ||
"name": "@craftjs/utils", | ||
"description": "Utilities used internally across the craft.js monorepo", | ||
"private": false, | ||
"version": "0.2.0-alpha.23", | ||
"version": "0.2.0-alpha.24", | ||
"author": "Prev Wong <prevwong@gmail.com>", | ||
@@ -18,5 +17,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"@types/react": "^16.9.11", | ||
"@types/react": "^17.0.5", | ||
"immer": "^8.0.1", | ||
"lodash": "^4.17.20", | ||
"shallowequal": "^1.1.0", | ||
"tiny-invariant": "^1.0.6" | ||
@@ -29,5 +29,5 @@ }, | ||
"peerDependencies": { | ||
"react": "^16.11.0" | ||
"react": "^16.8.0" | ||
}, | ||
"gitHead": "b61998c8ab6ef0e534c9523bdc0aac56f58d37a1" | ||
"gitHead": "8d637112e9b40ddf9d43f134e0ea458724135d77" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
320235
445
6
+ Addedshallowequal@^1.1.0
+ Added@types/react@17.0.83(transitive)
+ Addedshallowequal@1.1.0(transitive)
- Removed@types/react@16.14.62(transitive)
Updated@types/react@^17.0.5