Socket
Socket
Sign inDemoInstall

@craftjs/utils

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@craftjs/utils - npm Package Compare versions

Comparing version 0.1.0-beta.10 to 0.1.0-beta.11

lib/History.d.ts

2

dist/cjs/index.js

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

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var produce=_interopDefault(require("immer")),React=require("react"),React__default=_interopDefault(React),isEqualWith=_interopDefault(require("lodash.isequalwith")),invariant=_interopDefault(require("tiny-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",_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}function useMethods(e,t,n){var r=React.useMemo((function(){var t,r;return"function"==typeof e?t=e:(t=e.methods,r=e.patchListener),[function(e,o){var i=n&&createQuery(n,(function(){return e}));return produce(e,(function(e){var n;return(n=t(e,i))[o.type].apply(n,o.payload)}),r)},t]}),[e,n]),o=r[1],i=React.useReducer(r[0],t),a=i[0],s=i[1],c=React.useRef();c.current=a;var u=React.useMemo((function(){return n?createQuery(n,(function(){return c.current})):[]}),[n]),R=React.useMemo((function(){return Object.keys(o(null,null)).reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return s({type:t,payload:e})},e}),{})}),[o]),E=React.useCallback((function(){return c.current}),[]),O=React.useMemo((function(){return new Watcher(E)}),[E]);return React.useEffect((function(){c.current=a,O.notify()}),[a,O]),React.useMemo((function(){return{getState:E,subscribe:function(e,t,n){return O.subscribe(e,t,n)},actions:R,query:u}}),[R,u,O,E])}function createQuery(e,t){return 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))}),{})}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(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,R=getDOMMargin(e),E=getDOMPadding(e);return{x:Math.round(n),y:Math.round(r),top:Math.round(o),left:Math.round(i),bottom:Math.round(a),right:Math.round(s),width:Math.round(c),height:Math.round(u),outerWidth:Math.round(c+R.left+R.right),outerHeight:Math.round(u+R.top+R.bottom),margin:R,padding:E,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 u=React.useCallback((function(e){return _assign(_assign({},e),{actions:o,query:i})}),[o,i]);a.current&&t&&(s.current=t(r(),i),a.current=!1);var R=React.useState(u(s.current)),E=R[0],O=R[1];return React.useEffect((function(){var e;return c.current&&(e=n((function(e){return c.current(e,i)}),(function(e){O(u(e))}))),function(){e&&e()}}),[u,i,n]),E}function setRef(e,t){t&&("function"==typeof e?e(t):e.current=t)}function cloneWithRef(e,t){var n=e.ref;return invariant("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.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,[])},defineEventListener=function(e,t,n){return[e,t,n]},isEventBlockedByDescendant=function(e,t,n){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},WatchHandler=function(){function e(e,t,n,r){var o=this;this.el=t,this.opts=n,this.handler=r,this.unsubscribe=e.subscribe((function(e){return{enabled:e.options.enabled}}),(function(e){var n=e.enabled;if(!document.body.contains(t))return o.remove(),o.unsubscribe();n?o.add():o.remove()}),!0)}return e.prototype.add=function(){var e=this,t=this.handler,n=t.init,r=t.events;this.cleanDOM=n&&n(this.el,this.opts),this.listenersToRemove=r&&r.map((function(t){var n=t[0],r=t[1],o=t[2],i=function(t){t.craft||(t.craft={blockedEvents:{},stopPropagation:function(){}}),isEventBlockedByDescendant(t,n,e.el)||(t.craft.stopPropagation=function(){t.craft.blockedEvents[n]||(t.craft.blockedEvents[n]=[]),t.craft.blockedEvents[n].push(e.el)},r(t,e.opts))};return e.el.addEventListener(n,i,o),function(){return e.el.removeEventListener(n,i,o)}}))},e.prototype.remove=function(){this.cleanDOM&&(this.cleanDOM(),this.cleanDOM=null),this.listenersToRemove&&(this.listenersToRemove.forEach((function(e){return e()})),this.listenersToRemove=null)},e}(),Handlers=function(){function e(e){this.wm=new WeakMap,this.store=e}return e.prototype.connectors=function(){var e=this,t=this.handlers()||{};return Object.keys(t).reduce((function(n,r){var o=t[r],i=o.init,a=o.events;return i||a?(n[r]=wrapHookToRecognizeElement((function(t,n){var o;if(t&&document.body.contains(t)){var s=e.wm.get(t);s&&s[r]||e.wm.set(t,_assign(_assign({},s),((o={})[r]=new WatchHandler(e.store,t,n,{init:i,events:a}),o)))}else e.wm.delete(t)})),n):(n[r]=function(){},n)}),{})},e.getConnectors=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new(this.bind.apply(this,__spreadArrays([void 0],e)));return n.connectors()},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_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_TOP_LEVEL_ELEMENT_NO_ID=ERROR_TOP_LEVEL_ELEMENT_NO_ID,exports.Handlers=Handlers,exports.ROOT_NODE=ROOT_NODE,exports.RenderIndicator=RenderIndicator,exports.cloneWithRef=cloneWithRef,exports.createQuery=createQuery,exports.defineEventListener=defineEventListener,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"),React=require("react"),isEqualWith=require("lodash.isequalwith"),invariant=require("tiny-invariant");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var produce__default=_interopDefaultLegacy(produce),React__default=_interopDefaultLegacy(React),isEqualWith__default=_interopDefaultLegacy(isEqualWith),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",_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"},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.timestamp;if((new Date).getTime()-i<n&&o.length===e.length&&o.every((function(t,n){var r=e[n];return r.op===t.op&&isEqualWith__default.default(r.path,t.path)})))return void(this.throttledInversePatch||(this.throttledInversePatch=t))}this.add(e,this.throttledInversePatch||t),this.throttledInversePatch=null}},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()){this.throttledInversePatch=null;var t=this.timeline[this.pointer].inversePatches;return this.pointer=this.pointer-1,produce.applyPatches(e,t)}},e.prototype.redo=function(e){if(this.canRedo())return this.pointer=this.pointer+1,produce.applyPatches(e,this.timeline[this.pointer].patches)},e}();function useMethods(e,t,n,r){var o,i=React.useMemo((function(){return new History}),[]),a=React.useRef([]),s=React.useRef();"function"==typeof e?o=e:(o=e.methods,a.current=e.ignoreHistoryForActions,s.current=e.normalizeHistory);var c=React.useRef(r);c.current=r;var u=React.useMemo((function(){var e=s.current,t=a.current,r=c.current;return[function(a,s){var c,u=n&&createQuery(n,(function(){return a}),i),R=produce.produceWithPatches(a,(function(e){var t,n;switch(s.type){case HISTORY_ACTIONS.UNDO:return i.undo(e);case HISTORY_ACTIONS.REDO:return i.redo(e);case HISTORY_ACTIONS.IGNORE: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)}})),d=R[0],l=R[1],O=R[2];return c=d,r&&r(d,a,{type:s.type,params:s.payload,patches:l},u,(function(e){var t=produce.produceWithPatches(d,e);c=t[0],l=__spreadArrays(l,t[1]),O=__spreadArrays(t[2],O)})),[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,O,s.config&&s.config.rate):i.add(l,O)),c},o]}),[i,o,n]),R=u[1],d=React.useReducer(u[0],t),l=d[0],O=d[1],p=React.useRef();p.current=l;var E=React.useMemo((function(){return n?createQuery(n,(function(){return p.current}),i):[]}),[i,n]),_=React.useMemo((function(){var e=Object.keys(R(null,null)),t=a.current;return _assign(_assign({},e.reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return O({type:t,payload:e})},e}),{})),{history:{undo:function(){return O({type:HISTORY_ACTIONS.UNDO})},redo:function(){return O({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 O({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 O({type:HISTORY_ACTIONS.IGNORE,payload:__spreadArrays([t],e)})},e}),{}))}}})}),[R]),f=React.useCallback((function(){return p.current}),[]),h=React.useMemo((function(){return new Watcher(f)}),[f]);return React.useEffect((function(){p.current=l,h.notify()}),[l,h]),React.useMemo((function(){return{getState:f,subscribe:function(e,t,n){return h.subscribe(e,t,n)},actions:_,query:E,history:i}}),[_,E,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,u=t.height,R=getDOMMargin(e),d=getDOMPadding(e);return{x:Math.round(n),y:Math.round(r),top:Math.round(o),left:Math.round(i),bottom:Math.round(a),right:Math.round(s),width:Math.round(c),height:Math.round(u),outerWidth:Math.round(c+R.left+R.right),outerHeight:Math.round(u+R.top+R.bottom),margin:R,padding:d,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 u=React.useCallback((function(e){return _assign(_assign({},e),{actions:o,query:i})}),[o,i]);a.current&&t&&(s.current=t(r(),i),a.current=!1);var R=React.useState(u(s.current)),d=R[0],l=R[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]),d}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,[])},defineEventListener=function(e,t,n){return[e,t,n]},isEventBlockedByDescendant=function(e,t,n){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},WatchHandler=function(){function e(e,t,n,r){var o=this;this.el=t,this.opts=n,this.handler=r,this.unsubscribe=e.subscribe((function(e){return{enabled:e.options.enabled}}),(function(e){var n=e.enabled;if(!document.body.contains(t))return o.remove(),o.unsubscribe();n?o.add():o.remove()}),!0)}return e.prototype.add=function(){var e=this,t=this.handler,n=t.init,r=t.events;this.cleanDOM=n&&n(this.el,this.opts),this.listenersToRemove=r&&r.map((function(t){var n=t[0],r=t[1],o=t[2],i=function(t){t.craft||(t.craft={blockedEvents:{},stopPropagation:function(){}}),isEventBlockedByDescendant(t,n,e.el)||(t.craft.stopPropagation=function(){t.craft.blockedEvents[n]||(t.craft.blockedEvents[n]=[]),t.craft.blockedEvents[n].push(e.el)},r(t,e.opts))};return e.el.addEventListener(n,i,o),function(){return e.el.removeEventListener(n,i,o)}}))},e.prototype.remove=function(){this.cleanDOM&&(this.cleanDOM(),this.cleanDOM=null),this.listenersToRemove&&(this.listenersToRemove.forEach((function(e){return e()})),this.listenersToRemove=null)},e}(),Handlers=function(){function e(e){this.wm=new WeakMap,this.store=e}return e.prototype.connectors=function(){var e=this,t=this.handlers()||{};return Object.keys(t).reduce((function(n,r){var o=t[r],i=o.init,a=o.events;return i||a?(n[r]=wrapHookToRecognizeElement((function(t,n){var o;if(t&&document.body.contains(t)){var s=e.wm.get(t);s&&s[r]||e.wm.set(t,_assign(_assign({},s),((o={})[r]=new WatchHandler(e.store,t,n,{init:i,events:a}),o)))}else e.wm.delete(t)})),n):(n[r]=function(){},n)}),{})},e.getConnectors=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new(this.bind.apply(this,__spreadArrays([void 0],e)));return n.connectors()},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_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_TOP_LEVEL_ELEMENT_NO_ID=ERROR_TOP_LEVEL_ELEMENT_NO_ID,exports.HISTORY_ACTIONS=HISTORY_ACTIONS,exports.Handlers=Handlers,exports.History=History,exports.ROOT_NODE=ROOT_NODE,exports.RenderIndicator=RenderIndicator,exports.cloneWithRef=cloneWithRef,exports.createQuery=createQuery,exports.defineEventListener=defineEventListener,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 from"immer";import e,{useMemo as n,useReducer as r,useRef as o,useCallback as i,useEffect as a,useState as c,cloneElement as s,isValidElement as u}from"react";import d from"lodash.isequalwith";import l from"tiny-invariant";var f="ROOT",p="canvas-ROOT",h="Parent id cannot be ommited",v="Attempting to add a node with duplicated id",m="Node does not exist, it may have been removed",g='A <Element /> that is used inside a User Component must specify an `id` prop, eg: <Element id="text_element">...</Element> ',b="Placeholder required placement info (parent, index, or where) is missing",y="Node cannot be dropped into target parent",w="Target parent rejects incoming node",C="Current parent rejects outgoing node",O="Cannot move node that is not a direct child of a Canvas node",E="Cannot move node into a non-Canvas parent",T="A top-level Node cannot be moved",k="Root Node cannot be moved",x="Cannot move node into a descendant",M="The component type specified for this node does not exist in the resolver",S="The component specified in the <Canvas> `is` prop has additional Canvas specified in it's render template.",R="The node has specified a canDrag() rule that prevents it from being dragged",I="Invalid parameter Node Id specified",D="Attempting to delete a top-level Node",j=function(){return(j=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 N(){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}function P(e,c,s){var u=n((function(){var n,r;return"function"==typeof e?n=e:(n=e.methods,r=e.patchListener),[function(e,o){var i=s&&A(s,(function(){return e}));return t(e,(function(t){var e;return(e=n(t,i))[o.type].apply(e,o.payload)}),r)},n]}),[e,s]),d=u[1],l=r(u[0],c),f=l[0],p=l[1],h=o();h.current=f;var v=n((function(){return s?A(s,(function(){return h.current})):[]}),[s]),m=n((function(){return Object.keys(d(null,null)).reduce((function(t,e){return t[e]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return p({type:e,payload:t})},t}),{})}),[d]),g=i((function(){return h.current}),[]),b=n((function(){return new q(g)}),[g]);return a((function(){h.current=f,b.notify()}),[f,b]),n((function(){return{getState:g,subscribe:function(t,e,n){return b.subscribe(t,e,n)},actions:m,query:v}}),[m,v,b,g])}function A(t,e){return Object.keys(t()).reduce((function(n,r){var o;return j(j({},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))}),{})}var q=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e,n){var r=this,o=new L((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}(),L=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();d(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)}},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)}},F=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,d=W(t),l=B(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+d.left+d.right),outerHeight:Math.round(u+d.top+d.bottom),margin:d,padding:l,inFlow:t&&t.parentElement&&!!z(t,t.parentElement)}},H=function(t){return window.getComputedStyle(t)},z=function(t,e){var n=H(t),r=H(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 U(t,e){var n=t.subscribe,r=t.getState,s=t.actions,u=t.query,d=o(!0),l=o(null),f=o(e);f.current=e;var p=i((function(t){return j(j({},t),{actions:s,query:u})}),[s,u]);d.current&&e&&(l.current=e(r(),u),d.current=!1);var h=c(p(l.current)),v=h[0],m=h[1];return a((function(){var t;return f.current&&(t=n((function(t){return f.current(t,u)}),(function(t){m(p(t))}))),function(){t&&t()}}),[p,u,n]),v}function Y(t,e){e&&("function"==typeof t?t(e):t.current=e)}function _(t,e){var n=t.ref;return l("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"),s(t,n?{ref:function(t){Y(n,t),Y(e,t)}}:{ref:e})}function G(t){return function(e,n){if(void 0===e&&(e=null),!u(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),_(o,t)}}var J=function(t){return e.createElement("div",{style:j({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},t.style)})},K=function(t){a(t,[])},Q=function(t,e,n){return[t,e,n]},V=function(){function t(t,e,n,r){var o=this;this.el=e,this.opts=n,this.handler=r,this.unsubscribe=t.subscribe((function(t){return{enabled:t.options.enabled}}),(function(t){var n=t.enabled;if(!document.body.contains(e))return o.remove(),o.unsubscribe();n?o.add():o.remove()}),!0)}return t.prototype.add=function(){var t=this,e=this.handler,n=e.init,r=e.events;this.cleanDOM=n&&n(this.el,this.opts),this.listenersToRemove=r&&r.map((function(e){var n=e[0],r=e[1],o=e[2],i=function(e){e.craft||(e.craft={blockedEvents:{},stopPropagation:function(){}}),function(t,e,n){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}(e,n,t.el)||(e.craft.stopPropagation=function(){e.craft.blockedEvents[n]||(e.craft.blockedEvents[n]=[]),e.craft.blockedEvents[n].push(t.el)},r(e,t.opts))};return t.el.addEventListener(n,i,o),function(){return t.el.removeEventListener(n,i,o)}}))},t.prototype.remove=function(){this.cleanDOM&&(this.cleanDOM(),this.cleanDOM=null),this.listenersToRemove&&(this.listenersToRemove.forEach((function(t){return t()})),this.listenersToRemove=null)},t}(),X=function(){function t(t){this.wm=new WeakMap,this.store=t}return t.prototype.connectors=function(){var t=this,e=this.handlers()||{};return Object.keys(e).reduce((function(n,r){var o=e[r],i=o.init,a=o.events;return i||a?(n[r]=G((function(e,n){var o;if(e&&document.body.contains(e)){var c=t.wm.get(e);c&&c[r]||t.wm.set(e,j(j({},c),((o={})[r]=new V(t.store,e,n,{init:i,events:a}),o)))}else t.wm.delete(e)})),n):(n[r]=function(){},n)}),{})},t.getConnectors=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=new(this.bind.apply(this,N([void 0],t)));return n.connectors()},t}(),Z=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{p as DEPRECATED_ROOT_NODE,R as ERROR_CANNOT_DRAG,D as ERROR_DELETE_TOP_LEVEL_NODE,v as ERROR_DUPLICATE_NODEID,S as ERROR_INFINITE_CANVAS,m as ERROR_INVALID_NODEID,I as ERROR_INVALID_NODE_ID,b as ERROR_MISSING_PLACEHOLDER_PLACEMENT,y as ERROR_MOVE_CANNOT_DROP,w as ERROR_MOVE_INCOMING_PARENT,O as ERROR_MOVE_NONCANVAS_CHILD,C as ERROR_MOVE_OUTGOING_PARENT,k as ERROR_MOVE_ROOT_NODE,T as ERROR_MOVE_TOP_LEVEL_NODE,x as ERROR_MOVE_TO_DESCENDANT,E as ERROR_MOVE_TO_NONCANVAS_PARENT,h as ERROR_NOPARENT,M as ERROR_NOT_IN_RESOLVER,g as ERROR_TOP_LEVEL_ELEMENT_NO_ID,X as Handlers,f as ROOT_NODE,J as RenderIndicator,_ as cloneWithRef,A as createQuery,Q as defineEventListener,Z as deprecationWarning,H as getComputedStyle,F as getDOMInfo,W as getDOMMargin,B as getDOMPadding,z as styleInFlow,U as useCollector,K as useEffectOnce,P as useMethods,G as wrapHookToRecognizeElement};
import t,{applyPatches as e,produceWithPatches as n}from"immer";import r,{useMemo as o,useRef as i,useReducer as a,useCallback as c,useEffect as s,useState as u,cloneElement as d,isValidElement as l}from"react";import h from"lodash.isequalwith";import f from"tiny-invariant";var p="ROOT",v="canvas-ROOT",m="Parent id cannot be ommited",g="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",T="Target parent rejects incoming node",R="Current parent rejects outgoing node",E="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",D="Root Node cannot be moved",N="Cannot move node into a descendant",S="The component type specified for this node does not exist in the resolver",k="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",M="Invalid parameter Node Id specified",P="Attempting to delete a top-level Node",H=function(){return(H=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 U(){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 A={UNDO:"HISTORY_UNDO",REDO:"HISTORY_REDO",THROTTLE:"HISTORY_THROTTLE",IGNORE:"HISTORY_IGNORE"},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],o=r.patches,i=r.timestamp;if((new Date).getTime()-i<n&&o.length===t.length&&o.every((function(e,n){var r=t[n];return r.op===e.op&&h(r.path,e.path)})))return void(this.throttledInversePatch||(this.throttledInversePatch=e))}this.add(t,this.throttledInversePatch||e),this.throttledInversePatch=null}},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()){this.throttledInversePatch=null;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 j(e,r,u,d){var l,h=o((function(){return new L}),[]),f=i([]),p=i();"function"==typeof e?l=e:(l=e.methods,f.current=e.ignoreHistoryForActions,p.current=e.normalizeHistory);var v=i(d);v.current=d;var m=o((function(){var e=p.current,r=f.current,o=v.current;return[function(i,a){var c,s=u&&q(u,(function(){return i}),h),d=n(i,(function(t){var e,n;switch(a.type){case A.UNDO:return h.undo(t);case A.REDO:return h.redo(t);case A.IGNORE:case A.THROTTLE:var r=a.payload,o=r[0],i=r.slice(1);(e=l(t,s))[o].apply(e,i);break;default:(n=l(t,s))[a.type].apply(n,a.payload)}})),f=d[0],p=d[1],v=d[2];return c=f,o&&o(f,i,{type:a.type,params:a.payload,patches:p},s,(function(t){var e=n(f,t);c=e[0],p=U(p,e[1]),v=U(e[2],v)})),[A.UNDO,A.REDO].includes(a.type)&&e&&(c=t(c,e)),U(r,[A.UNDO,A.REDO,A.IGNORE]).includes(a.type)||(a.type===A.THROTTLE?h.throttleAdd(p,v,a.config&&a.config.rate):h.add(p,v)),c},l]}),[h,l,u]),g=m[1],y=a(m[0],r),b=y[0],w=y[1],O=i();O.current=b;var T=o((function(){return u?q(u,(function(){return O.current}),h):[]}),[h,u]),R=o((function(){var t=Object.keys(g(null,null)),e=f.current;return H(H({},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:A.UNDO})},redo:function(){return w({type:A.REDO})},throttle:function(n){return H({},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:A.THROTTLE,payload:U([e],t),config:{rate:n}})},t}),{}))},ignore:function(){return H({},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:A.IGNORE,payload:U([e],t)})},t}),{}))}}})}),[g]),E=c((function(){return O.current}),[]),C=o((function(){return new G(E)}),[E]);return s((function(){O.current=b,C.notify()}),[b,C]),o((function(){return{getState:E,subscribe:function(t,e,n){return C.subscribe(t,e,n)},actions:R,query:T,history:h}}),[R,T,C,E,h])}function q(t,e,n){var r=Object.keys(t()).reduce((function(n,r){var o;return H(H({},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 H(H({},r),{history:{canUndo:function(){return n.canUndo()},canRedo:function(){return n.canRedo()}}})}var G=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e,n){var r=this,o=new Y((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}(),Y=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();h(t,this.collected)||(this.collected=t,this.onChange&&this.onChange(this.collected))}catch(t){console.warn(t)}},t}(),_=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)}},B=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)}},F=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,d=B(t),l=_(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+d.left+d.right),outerHeight:Math.round(u+d.top+d.bottom),margin:d,padding:l,inFlow:t&&t.parentElement&&!!z(t,t.parentElement)}},W=function(t){return window.getComputedStyle(t)},z=function(t,e){var n=W(t),r=W(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 J(t,e){var n=t.subscribe,r=t.getState,o=t.actions,a=t.query,d=i(!0),l=i(null),h=i(e);h.current=e;var f=c((function(t){return H(H({},t),{actions:o,query:a})}),[o,a]);d.current&&e&&(l.current=e(r(),a),d.current=!1);var p=u(f(l.current)),v=p[0],m=p[1];return s((function(){var t;return h.current&&(t=n((function(t){return h.current(t,a)}),(function(t){m(f(t))}))),function(){t&&t()}}),[f,a,n]),v}function K(t,e){e&&("function"==typeof t?t(e):t.current=e)}function Q(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){K(n,t),K(e,t)}}:{ref:e})}function V(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),Q(o,t)}}var X=function(t){return r.createElement("div",{style:H({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},t.style)})},Z=function(t){s(t,[])},$=function(t,e,n){return[t,e,n]},tt=function(){function t(t,e,n,r){var o=this;this.el=e,this.opts=n,this.handler=r,this.unsubscribe=t.subscribe((function(t){return{enabled:t.options.enabled}}),(function(t){var n=t.enabled;if(!document.body.contains(e))return o.remove(),o.unsubscribe();n?o.add():o.remove()}),!0)}return t.prototype.add=function(){var t=this,e=this.handler,n=e.init,r=e.events;this.cleanDOM=n&&n(this.el,this.opts),this.listenersToRemove=r&&r.map((function(e){var n=e[0],r=e[1],o=e[2],i=function(e){e.craft||(e.craft={blockedEvents:{},stopPropagation:function(){}}),function(t,e,n){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}(e,n,t.el)||(e.craft.stopPropagation=function(){e.craft.blockedEvents[n]||(e.craft.blockedEvents[n]=[]),e.craft.blockedEvents[n].push(t.el)},r(e,t.opts))};return t.el.addEventListener(n,i,o),function(){return t.el.removeEventListener(n,i,o)}}))},t.prototype.remove=function(){this.cleanDOM&&(this.cleanDOM(),this.cleanDOM=null),this.listenersToRemove&&(this.listenersToRemove.forEach((function(t){return t()})),this.listenersToRemove=null)},t}(),et=function(){function t(t){this.wm=new WeakMap,this.store=t}return t.prototype.connectors=function(){var t=this,e=this.handlers()||{};return Object.keys(e).reduce((function(n,r){var o=e[r],i=o.init,a=o.events;return i||a?(n[r]=V((function(e,n){var o;if(e&&document.body.contains(e)){var c=t.wm.get(e);c&&c[r]||t.wm.set(e,H(H({},c),((o={})[r]=new tt(t.store,e,n,{init:i,events:a}),o)))}else t.wm.delete(e)})),n):(n[r]=function(){},n)}),{})},t.getConnectors=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=new(this.bind.apply(this,U([void 0],t)));return n.connectors()},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{v as DEPRECATED_ROOT_NODE,x as ERROR_CANNOT_DRAG,P as ERROR_DELETE_TOP_LEVEL_NODE,g as ERROR_DUPLICATE_NODEID,k as ERROR_INFINITE_CANVAS,y as ERROR_INVALID_NODEID,M as ERROR_INVALID_NODE_ID,w as ERROR_MISSING_PLACEHOLDER_PLACEMENT,O as ERROR_MOVE_CANNOT_DROP,T as ERROR_MOVE_INCOMING_PARENT,E as ERROR_MOVE_NONCANVAS_CHILD,R as ERROR_MOVE_OUTGOING_PARENT,D as ERROR_MOVE_ROOT_NODE,I as ERROR_MOVE_TOP_LEVEL_NODE,N as ERROR_MOVE_TO_DESCENDANT,C as ERROR_MOVE_TO_NONCANVAS_PARENT,m as ERROR_NOPARENT,S as ERROR_NOT_IN_RESOLVER,b as ERROR_TOP_LEVEL_ELEMENT_NO_ID,A as HISTORY_ACTIONS,et as Handlers,L as History,p as ROOT_NODE,X as RenderIndicator,Q as cloneWithRef,q as createQuery,$ as defineEventListener,nt as deprecationWarning,W as getComputedStyle,F as getDOMInfo,B as getDOMMargin,_ as getDOMPadding,z as styleInFlow,J as useCollector,Z as useEffectOnce,j as useMethods,V as wrapHookToRecognizeElement};

@@ -10,1 +10,3 @@ export * from './constants';

export * from './deprecate';
export * from './utilityTypes';
export * from './History';

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

import { CallbacksFor, Methods, StateFor, QueryCallbacksFor, QueryMethods, SubscriberAndCallbacksFor } from './useMethods';
declare type Actions<M extends Methods, Q extends QueryMethods> = {
import { CallbacksFor, MethodsOrOptions, StateFor, QueryCallbacksFor, QueryMethods, SubscriberAndCallbacksFor } from './useMethods';
declare type Actions<M extends MethodsOrOptions, Q extends QueryMethods> = {
actions: CallbacksFor<M>;
query: QueryCallbacksFor<Q>;
};
export declare type useCollector<M extends Methods, Q extends QueryMethods | null, C = null> = C extends null ? Actions<M, Q> : C & Actions<M, Q>;
export declare function useCollector<M extends Methods, Q extends QueryMethods | null>(store: SubscriberAndCallbacksFor<M, Q>): useCollector<M, Q>;
export declare function useCollector<M extends Methods, Q extends QueryMethods | null, C>(store: SubscriberAndCallbacksFor<M, Q>, collector: (state: StateFor<M>, query: Q) => C): useCollector<M, Q, C>;
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 {};

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

import { PatchListener } from 'immer';
import { Patch } from 'immer';
import { History } from './History';
import { Delete } from './utilityTypes';
export declare type SubscriberAndCallbacksFor<M extends MethodsOrOptions, Q extends QueryMethods = any> = {

@@ -10,2 +12,3 @@ subscribe: Watcher<StateFor<M>>['subscribe'];

query: QueryCallbacksFor<Q>;
history: History;
};

@@ -15,2 +18,13 @@ export declare type StateFor<M extends MethodsOrOptions> = M extends MethodsOrOptions<infer S, any> ? S : never;

[T in ActionUnion<R>['type']]: (...payload: ActionByType<ActionUnion<R>, T>['payload']) => void;
} & {
history: {
undo: () => void;
redo: () => void;
throttle: (rate?: number) => Delete<{
[T in ActionUnion<R>['type']]: (...payload: ActionByType<ActionUnion<R>, T>['payload']) => void;
}, M extends Options ? M['ignoreHistoryForActions'][number] : never>;
ignore: () => Delete<{
[T in ActionUnion<R>['type']]: (...payload: ActionByType<ActionUnion<R>, T>['payload']) => void;
}, M extends Options ? M['ignoreHistoryForActions'][number] : never>;
};
} : never;

@@ -20,11 +34,14 @@ export declare type Methods<S = any, R extends MethodRecordBase<S> = any, Q = any> = (state: S, query: Q) => R;

methods: Methods<S, R, Q>;
patchListener?: PatchListener;
ignoreHistoryForActions: ReadonlyArray<keyof MethodRecordBase>;
normalizeHistory?: (state: S) => void;
};
export declare type MethodsOrOptions<S = any, R extends MethodRecordBase<S> = any, Q = any> = Methods<S, R, Q> | Options<S, R, Q>;
export declare type MethodRecordBase<S = any> = Record<string, (...args: any[]) => S extends object ? S | void : S>;
export declare type Action<T = any, P = any> = {
type: T;
payload?: P;
config?: Record<string, any>;
};
export declare type ActionUnion<R extends MethodRecordBase> = {
[T in keyof R]: {
type: T;
payload: Parameters<R[T]>;
};
[T in keyof R]: Action<T, Parameters<R[T]>>;
}[keyof R];

@@ -37,7 +54,25 @@ export declare type ActionByType<A, T> = A extends {

[T in ActionUnion<R>['type']]: (...payload: ActionByType<ActionUnion<R>, T>['payload']) => ReturnType<R[T]>;
} & {
history: {
canUndo: () => boolean;
canRedo: () => boolean;
};
} : never;
export declare type PatchListenerAction<S, M extends MethodsOrOptions> = {
type: keyof CallbacksFor<M>;
params: any;
patches: Patch[];
};
export declare type PatchListener<S, M extends MethodsOrOptions, Q extends QueryMethods> = (newState: S, previousState: S, actionPerformedWithPatches: PatchListenerAction<S, M>, query: QueryCallbacksFor<Q>, normalizer: (cb: (draft: S) => void) => void) => void;
export declare function useMethods<S, R extends MethodRecordBase<S>>(methodsOrOptions: Methods<S, R>, initialState: any): SubscriberAndCallbacksFor<MethodsOrOptions<S, R>>;
export declare function useMethods<S, R extends MethodRecordBase<S>, Q extends QueryMethods>(methodsOrOptions: Methods<S, R, QueryCallbacksFor<Q>>, // methods to manipulate the state
export declare function useMethods<S, R extends MethodRecordBase<S>, Q extends QueryMethods>(methodsOrOptions: MethodsOrOptions<S, R, QueryCallbacksFor<Q>>, // methods to manipulate the state
initialState: any, queryMethods: Q): SubscriberAndCallbacksFor<MethodsOrOptions<S, R>, Q>;
export declare function createQuery<Q extends QueryMethods>(queryMethods: Q, getState: any): QueryCallbacksFor<Q>;
export declare function useMethods<S, R extends MethodRecordBase<S>, Q extends QueryMethods>(methodsOrOptions: MethodsOrOptions<S, R, QueryCallbacksFor<Q>>, // methods to manipulate the state
initialState: any, queryMethods: Q, patchListener: PatchListener<S, MethodsOrOptions<S, R, QueryCallbacksFor<Q>>, Q>): SubscriberAndCallbacksFor<MethodsOrOptions<S, R>, Q>;
export declare function createQuery<Q extends QueryMethods>(queryMethods: Q, getState: any, history: History): QueryCallbacksFor<Q> & {
history: {
canUndo: () => boolean;
canRedo: () => boolean;
};
};
declare class Watcher<S> {

@@ -44,0 +79,0 @@ getState: any;

@@ -5,3 +5,3 @@ {

"private": false,
"version": "0.1.0-beta.10",
"version": "0.1.0-beta.11",
"author": "Prev Wong <prevwong@gmail.com>",

@@ -26,3 +26,3 @@ "license": "MIT",

},
"gitHead": "7b24f3a79149e99895906e04e7d72da62752bdd7"
"gitHead": "b45c210e5b519fd23e0bb95761580c034e4c963c"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc