@craftjs/utils
Advanced tools
Comparing version 0.2.0-alpha.12 to 0.2.0-alpha.13
@@ -6,2 +6,13 @@ # Change Log | ||
# 0.2.0-alpha.13 (2021-02-03) | ||
### Bug Fixes | ||
* yarn.lock ([6782edf](https://github.com/prevwong/craft.js/commit/6782edf1715a41c0f21daaeab92c5e7edb8c2f17)) | ||
# 0.2.0-alpha.12 (2021-01-28) | ||
@@ -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"),invariant=require("tiny-invariant");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),invariant__default=_interopDefaultLegacy(invariant),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",_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 R=React.useMemo((function(){var e=s.current,t=a.current,r=c.current;return[function(a,s){var c,R=n&&createQuery(n,(function(){return a}),i),u=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,R))[a].apply(t,c);break;default:(n=o(e,R))[s.type].apply(n,s.payload)}})),O=u[0],_=u[1],E=u[2];return c=O,r&&r(O,a,{type:s.type,params:s.payload,patches:_},R,(function(e){var t=produce.produceWithPatches(O,e);c=t[0],_=__spreadArrays(_,t[1]),E=__spreadArrays(t[2],E)})),[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(_,E,s.config&&s.config.rate):s.type===HISTORY_ACTIONS.MERGE?i.merge(_,E):i.add(_,E)),c},o]}),[i,o,n]),u=R[1],O=React.useReducer(R[0],t),_=O[0],E=O[1],p=React.useRef();p.current=_;var d=React.useMemo((function(){return n?createQuery(n,(function(){return p.current}),i):[]}),[i,n]),l=React.useMemo((function(){var e=Object.keys(u(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 E({type:t,payload:e})},e}),{})),{history:{undo:function(){return E({type:HISTORY_ACTIONS.UNDO})},redo:function(){return E({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 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}),{}))}}})}),[u]),f=React.useCallback((function(){return p.current}),[]),h=React.useMemo((function(){return new Watcher(f)}),[f]);return React.useEffect((function(){p.current=_,h.notify()}),[_,h]),React.useMemo((function(){return{getState:f,subscribe:function(e,t,n){return h.subscribe(e,t,n)},actions:l,query:d,history:i}}),[l,d,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()}}})}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,R=t.height,u=getDOMMargin(e),O=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(R),outerWidth:Math.round(c+u.left+u.right),outerHeight:Math.round(R+u.top+u.bottom),margin:u,padding:O,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&&"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":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 R=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 u=React.useState(R(s.current)),O=u[0],_=u[1];return React.useEffect((function(){var e;return c.current&&(e=n((function(e){return c.current(e,i)}),(function(e){_(R(e))}))),function(){e&&e()}}),[R,i,n]),O}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,n){if(void 0===t&&(t=null),!React.isValidElement(t)){var r=t;return r&&e(r,n),r}var o=t;return throwIfCompositeComponentElement(o),cloneWithRef(o,e)}}var RenderIndicator=function(e){return React__default.default.createElement("div",{style:_assign({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},e.style)})},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.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.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.wrapHookToRecognizeElement=wrapHookToRecognizeElement; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var produce=require("immer"),isEqualWith=require("lodash/isEqualWith"),React=require("react"),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),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",_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 R=React.useMemo((function(){var e=s.current,t=a.current,r=c.current;return[function(a,s){var c,R=n&&createQuery(n,(function(){return a}),i),u=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,R))[a].apply(t,c);break;default:(n=o(e,R))[s.type].apply(n,s.payload)}})),O=u[0],_=u[1],E=u[2];return c=O,r&&r(O,a,{type:s.type,params:s.payload,patches:_},R,(function(e){var t=produce.produceWithPatches(O,e);c=t[0],_=__spreadArrays(_,t[1]),E=__spreadArrays(t[2],E)})),[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(_,E,s.config&&s.config.rate):s.type===HISTORY_ACTIONS.MERGE?i.merge(_,E):i.add(_,E)),c},o]}),[i,o,n]),u=R[1],O=React.useReducer(R[0],t),_=O[0],E=O[1],p=React.useRef();p.current=_;var d=React.useMemo((function(){return n?createQuery(n,(function(){return p.current}),i):[]}),[i,n]),l=React.useMemo((function(){var e=Object.keys(u(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 E({type:t,payload:e})},e}),{})),{history:{undo:function(){return E({type:HISTORY_ACTIONS.UNDO})},redo:function(){return E({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 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}),{}))}}})}),[u]),f=React.useCallback((function(){return p.current}),[]),h=React.useMemo((function(){return new Watcher(f)}),[f]);return React.useEffect((function(){p.current=_,h.notify()}),[_,h]),React.useMemo((function(){return{getState:f,subscribe:function(e,t,n){return h.subscribe(e,t,n)},actions:l,query:d,history:i}}),[l,d,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()}}})}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,R=t.height,u=getDOMMargin(e),O=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(R),outerWidth:Math.round(c+u.left+u.right),outerHeight:Math.round(R+u.top+u.bottom),margin:u,padding:O,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&&"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 R=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 u=React.useState(R(s.current)),O=u[0],_=u[1];return React.useEffect((function(){var e;return c.current&&(e=n((function(e){return c.current(e,i)}),(function(e){_(R(e))}))),function(){e&&e()}}),[R,i,n]),O}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,n){if(void 0===t&&(t=null),!React.isValidElement(t)){var r=t;return r&&e(r,n),r}var o=t;return throwIfCompositeComponentElement(o),cloneWithRef(o,e)}}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.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.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.wrapHookToRecognizeElement=wrapHookToRecognizeElement; |
@@ -1,1 +0,1 @@ | ||
import t,{applyPatches as e,produceWithPatches as n}from"immer";import r from"lodash.isequalwith";import i,{useMemo as o,useRef as a,useReducer as s,useCallback as c,useEffect as u,useState as p,cloneElement as d,isValidElement as l}from"react";import f from"tiny-invariant";var h="ROOT",m="canvas-ROOT",g="Parent id cannot be ommited",v="Attempting to add a node with duplicated id",y="Node does not exist, it may have been removed",b='A <Element /> that is used inside a User Component must specify an `id` prop, eg: <Element id="text_element">...</Element> ',w="Placeholder required placement info (parent, index, or where) is missing",O="Node cannot be dropped into target parent",R="Target parent rejects incoming node",E="Current parent rejects outgoing node",T="Cannot move node that is not a direct child of a Canvas node",C="Cannot move node into a non-Canvas parent",I="A top-level Node cannot be moved",N="Root Node cannot be moved",S="Cannot move node into a descendant",D="The component type specified for this node does not exist in the resolver",M="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",x="The node has specified a canDrag() rule that prevents it from being dragged",H="Invalid parameter Node Id specified",P="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",A="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",j=function(){return(j=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 k(){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 G={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE",MERGE:"HISTORY_MERGE"},L=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:k(i,t),inversePatches:k(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:k(n.patches,t),inversePatches:k(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 Y(e,r,i,p){var d,l=o((function(){return new L}),[]),f=a([]),h=a();"function"==typeof e?d=e:(d=e.methods,f.current=e.ignoreHistoryForActions,h.current=e.normalizeHistory);var m=a(p);m.current=p;var g=o((function(){var e=h.current,r=f.current,o=m.current;return[function(a,s){var c,u=i&&_(i,(function(){return a}),l),p=n(a,(function(t){var e,n;switch(s.type){case G.UNDO:return l.undo(t);case G.REDO:return l.redo(t);case G.IGNORE:case G.MERGE:case G.THROTTLE:var r=s.payload,i=r[0],o=r.slice(1);(e=d(t,u))[i].apply(e,o);break;default:(n=d(t,u))[s.type].apply(n,s.payload)}})),f=p[0],h=p[1],m=p[2];return c=f,o&&o(f,a,{type:s.type,params:s.payload,patches:h},u,(function(t){var e=n(f,t);c=e[0],h=k(h,e[1]),m=k(e[2],m)})),[G.UNDO,G.REDO].includes(s.type)&&e&&(c=t(c,e)),k(r,[G.UNDO,G.REDO,G.IGNORE]).includes(s.type)||(s.type===G.THROTTLE?l.throttleAdd(h,m,s.config&&s.config.rate):s.type===G.MERGE?l.merge(h,m):l.add(h,m)),c},d]}),[l,d,i]),v=g[1],y=s(g[0],r),b=y[0],w=y[1],O=a();O.current=b;var R=o((function(){return i?_(i,(function(){return O.current}),l):[]}),[l,i]),E=o((function(){var t=Object.keys(v(null,null)),e=f.current;return j(j({},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:G.UNDO})},redo:function(){return w({type:G.REDO})},throttle:function(n){return j({},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:G.THROTTLE,payload:k([e],t),config:{rate:n}})},t}),{}))},ignore:function(){return j({},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:G.IGNORE,payload:k([e],t)})},t}),{}))},merge:function(){return j({},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:G.MERGE,payload:k([e],t)})},t}),{}))}}})}),[v]),T=c((function(){return O.current}),[]),C=o((function(){return new q(T)}),[T]);return u((function(){O.current=b,C.notify()}),[b,C]),o((function(){return{getState:T,subscribe:function(t,e,n){return C.subscribe(t,e,n)},actions:E,query:R,history:l}}),[E,R,C,T,l])}function _(t,e,n){var r=Object.keys(t()).reduce((function(n,r){var i;return j(j({},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 j(j({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}var q=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e,n){var r=this,i=new z((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}(),z=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();r(t,this.collected)||(this.collected=t,this.onChange&&this.onChange(this.collected))}catch(t){console.warn(t)}},t}(),B=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)}},F=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)}},W=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=F(t),d=B(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&&!!K(t,t.parentElement)}},J=function(t){return window.getComputedStyle(t)},K=function(t,e){var n=J(t),r=J(e);if(!(n.overflow&&"visible"!==n.overflow||"none"!==r.float||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":return!0}}};function Q(t,e){var n=t.subscribe,r=t.getState,i=t.actions,o=t.query,s=a(!0),d=a(null),l=a(e);l.current=e;var f=c((function(t){return j(j({},t),{actions:i,query:o})}),[i,o]);s.current&&e&&(d.current=e(r(),o),s.current=!1);var h=p(f(d.current)),m=h[0],g=h[1];return u((function(){var t;return l.current&&(t=n((function(t){return l.current(t,o)}),(function(t){g(f(t))}))),function(){t&&t()}}),[f,o,n]),m}function V(t,e){e&&("function"==typeof t?t(e):t.current=e)}function X(t,e){var n=t.ref;return f("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){V(n,t),V(e,t)}}:{ref:e})}function Z(t){return function(e,n){if(void 0===e&&(e=null),!l(e)){var r=e;return r&&t(r,n),r}var i=e;return function(t){if("string"!=typeof t.type)throw new Error}(i),X(i,t)}}var $=function(t){return i.createElement("div",{style:j({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},t.style)})},tt=function(t){u(t,[])},et=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{m as DEPRECATED_ROOT_NODE,x as ERROR_CANNOT_DRAG,P as ERROR_DELETE_TOP_LEVEL_NODE,A as ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER,v as ERROR_DUPLICATE_NODEID,M as ERROR_INFINITE_CANVAS,y as ERROR_INVALID_NODEID,H as ERROR_INVALID_NODE_ID,w as ERROR_MISSING_PLACEHOLDER_PLACEMENT,O as ERROR_MOVE_CANNOT_DROP,R as ERROR_MOVE_INCOMING_PARENT,T as ERROR_MOVE_NONCANVAS_CHILD,E as ERROR_MOVE_OUTGOING_PARENT,N as ERROR_MOVE_ROOT_NODE,I as ERROR_MOVE_TOP_LEVEL_NODE,S as ERROR_MOVE_TO_DESCENDANT,C as ERROR_MOVE_TO_NONCANVAS_PARENT,g as ERROR_NOPARENT,D as ERROR_NOT_IN_RESOLVER,U as ERROR_RESOLVER_NOT_AN_OBJECT,b as ERROR_TOP_LEVEL_ELEMENT_NO_ID,G as HISTORY_ACTIONS,L as History,h as ROOT_NODE,$ as RenderIndicator,X as cloneWithRef,_ as createQuery,et as deprecationWarning,J as getComputedStyle,W as getDOMInfo,F as getDOMMargin,B as getDOMPadding,K as styleInFlow,Q as useCollector,tt as useEffectOnce,Y as useMethods,Z as wrapHookToRecognizeElement}; | ||
import t,{applyPatches as e,produceWithPatches as n}from"immer";import r from"lodash/isEqualWith";import o,{useMemo as i,useRef as a,useReducer as c,useCallback as s,useEffect as u,useState as p,cloneElement as d,isValidElement as l}from"react";import f from"tiny-invariant";import h from"react-dom";var m="ROOT",g="canvas-ROOT",v="Parent id cannot be ommited",y="Attempting to add a node with duplicated id",b="Node does not exist, it may have been removed",w='A <Element /> that is used inside a User Component must specify an `id` prop, eg: <Element id="text_element">...</Element> ',O="Placeholder required placement info (parent, index, or where) is missing",E="Node cannot be dropped into target parent",R="Target parent rejects incoming node",T="Current parent rejects outgoing node",C="Cannot move node that is not a direct child of a Canvas node",D="Cannot move node into a non-Canvas parent",I="A top-level Node cannot be moved",N="Root Node cannot be moved",S="Cannot move node into a descendant",M="The component type specified for this node does not exist in the resolver",x="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",H="The node has specified a canDrag() rule that prevents it from being dragged",P="Invalid parameter Node Id specified",U="Attempting to delete a top-level Node",A="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",j="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",k=function(){return(k=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 G(){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,c=i.length;a<c;a++,o++)r[o]=i[a];return r}var L={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE",MERGE:"HISTORY_MERGE"},Y=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:G(o,t),inversePatches:G(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:G(n.patches,t),inversePatches:G(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 _(e,r,o,p){var d,l=i((function(){return new Y}),[]),f=a([]),h=a();"function"==typeof e?d=e:(d=e.methods,f.current=e.ignoreHistoryForActions,h.current=e.normalizeHistory);var m=a(p);m.current=p;var g=i((function(){var e=h.current,r=f.current,i=m.current;return[function(a,c){var s,u=o&&q(o,(function(){return a}),l),p=n(a,(function(t){var e,n;switch(c.type){case L.UNDO:return l.undo(t);case L.REDO:return l.redo(t);case L.IGNORE:case L.MERGE:case L.THROTTLE:var r=c.payload,o=r[0],i=r.slice(1);(e=d(t,u))[o].apply(e,i);break;default:(n=d(t,u))[c.type].apply(n,c.payload)}})),f=p[0],h=p[1],m=p[2];return s=f,i&&i(f,a,{type:c.type,params:c.payload,patches:h},u,(function(t){var e=n(f,t);s=e[0],h=G(h,e[1]),m=G(e[2],m)})),[L.UNDO,L.REDO].includes(c.type)&&e&&(s=t(s,e)),G(r,[L.UNDO,L.REDO,L.IGNORE]).includes(c.type)||(c.type===L.THROTTLE?l.throttleAdd(h,m,c.config&&c.config.rate):c.type===L.MERGE?l.merge(h,m):l.add(h,m)),s},d]}),[l,d,o]),v=g[1],y=c(g[0],r),b=y[0],w=y[1],O=a();O.current=b;var E=i((function(){return o?q(o,(function(){return O.current}),l):[]}),[l,o]),R=i((function(){var t=Object.keys(v(null,null)),e=f.current;return k(k({},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:L.UNDO})},redo:function(){return w({type:L.REDO})},throttle:function(n){return k({},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:L.THROTTLE,payload:G([e],t),config:{rate:n}})},t}),{}))},ignore:function(){return k({},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:L.IGNORE,payload:G([e],t)})},t}),{}))},merge:function(){return k({},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:L.MERGE,payload:G([e],t)})},t}),{}))}}})}),[v]),T=s((function(){return O.current}),[]),C=i((function(){return new z(T)}),[T]);return u((function(){O.current=b,C.notify()}),[b,C]),i((function(){return{getState:T,subscribe:function(t,e,n){return C.subscribe(t,e,n)},actions:R,query:E,history:l}}),[R,E,C,T,l])}function q(t,e,n){var r=Object.keys(t()).reduce((function(n,r){var o;return k(k({},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 k(k({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}var z=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e,n){var r=this,o=new B((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}(),B=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();r(t,this.collected)||(this.collected=t,this.onChange&&this.onChange(this.collected))}catch(t){console.warn(t)}},t}(),F=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)}},W=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)}},J=function(t){var e=t.getBoundingClientRect(),n=e.x,r=e.y,o=e.top,i=e.left,a=e.bottom,c=e.right,s=e.width,u=e.height,p=W(t),d=F(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(c),width:Math.round(s),height:Math.round(u),outerWidth:Math.round(s+p.left+p.right),outerHeight:Math.round(u+p.top+p.bottom),margin:p,padding:d,inFlow:t&&t.parentElement&&!!Q(t,t.parentElement)}},K=function(t){return window.getComputedStyle(t)},Q=function(t,e){var n=K(t),r=K(e);if(!(n.overflow&&"visible"!==n.overflow||"none"!==r.float||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 V(t,e){var n=t.subscribe,r=t.getState,o=t.actions,i=t.query,c=a(!0),d=a(null),l=a(e);l.current=e;var f=s((function(t){return k(k({},t),{actions:o,query:i})}),[o,i]);c.current&&e&&(d.current=e(r(),i),c.current=!1);var h=p(f(d.current)),m=h[0],g=h[1];return u((function(){var t;return l.current&&(t=n((function(t){return l.current(t,i)}),(function(t){g(f(t))}))),function(){t&&t()}}),[f,i,n]),m}function X(t,e){e&&("function"==typeof t?t(e):t.current=e)}function Z(t,e){var n=t.ref;return f("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){X(n,t),X(e,t)}}:{ref:e})}function $(t){return function(e,n){if(void 0===e&&(e=null),!l(e)){var r=e;return r&&t(r,n),r}var o=e;return function(t){if("string"!=typeof t.type)throw new Error}(o),Z(o,t)}}var tt=function(t){var e=t.parentDom,n=o.createElement("div",{style:k({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},t.style)});return e&&e.ownerDocument!==document?h.createPortal(n,e.ownerDocument.body):n},et=function(t){u(t,[])},nt=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{g as DEPRECATED_ROOT_NODE,H as ERROR_CANNOT_DRAG,U as ERROR_DELETE_TOP_LEVEL_NODE,j as ERROR_DESERIALIZE_COMPONENT_NOT_IN_RESOLVER,y as ERROR_DUPLICATE_NODEID,x as ERROR_INFINITE_CANVAS,b as ERROR_INVALID_NODEID,P as ERROR_INVALID_NODE_ID,O as ERROR_MISSING_PLACEHOLDER_PLACEMENT,E as ERROR_MOVE_CANNOT_DROP,R as ERROR_MOVE_INCOMING_PARENT,C as ERROR_MOVE_NONCANVAS_CHILD,T as ERROR_MOVE_OUTGOING_PARENT,N as ERROR_MOVE_ROOT_NODE,I as ERROR_MOVE_TOP_LEVEL_NODE,S as ERROR_MOVE_TO_DESCENDANT,D as ERROR_MOVE_TO_NONCANVAS_PARENT,v as ERROR_NOPARENT,M as ERROR_NOT_IN_RESOLVER,A as ERROR_RESOLVER_NOT_AN_OBJECT,w as ERROR_TOP_LEVEL_ELEMENT_NO_ID,L as HISTORY_ACTIONS,Y as History,m as ROOT_NODE,tt as RenderIndicator,Z as cloneWithRef,q as createQuery,nt as deprecationWarning,K as getComputedStyle,J as getDOMInfo,W as getDOMMargin,F as getDOMPadding,Q as styleInFlow,V as useCollector,et as useEffectOnce,_ as useMethods,$ as wrapHookToRecognizeElement}; |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "0.2.0-alpha.12", | ||
"version": "0.2.0-alpha.13", | ||
"author": "Prev Wong <prevwong@gmail.com>", | ||
@@ -21,3 +21,3 @@ "license": "MIT", | ||
"immer": "^3.1.3", | ||
"lodash.isequalwith": "^4.4.0", | ||
"lodash": "^4.17.20", | ||
"tiny-invariant": "^1.0.6" | ||
@@ -28,3 +28,3 @@ }, | ||
}, | ||
"gitHead": "9c27936ec48dc8e9ea319deff5ef581139c2bf94" | ||
"gitHead": "adbfa18926c757b0d2a2028f377312f528ed2e21" | ||
} |
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
290724
322
+ Addedlodash@^4.17.20
+ Addedlodash@4.17.21(transitive)
- Removedlodash.isequalwith@^4.4.0
- Removedlodash.isequalwith@4.4.0(transitive)