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.2 to 0.1.0-beta.4

lib/Handlers.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="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_ROOT_CANVAS_NO_ID='A <Canvas /> that is a child of a non Canvas node must specify an `id` prop, eg: <Canvas id="MyCanvas">...</Canvas> ',ERROR_MISSING_PLACEHOLDER_PLACEMENT="Placeholder required placement info (parent, index, or where) is missing",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_CANVAS="A <Canvas /> that is a child of a non-Canvas node cannot be moved",ERROR_MOVE_ROOT_NODE="Root Node cannot be moved",ERROR_MOVE_TO_DESCENDANT="Cannot move node into a descendant",ERRROR_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_FRAME_IMMEDIATE_NON_CANVAS="The immediate child of <Frame /> has to be a Canvas",_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 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],u=i[1],s=React.useRef();s.current=a;var R=React.useMemo((function(){return n?createQuery(n,(function(){return s.current})):[]}),[n]),c=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 u({type:t,payload:e})},e}),{})}),[o]),O=React.useMemo((function(){return new Watcher}),[]);return React.useEffect((function(){s.current=a,O.notify()}),[a,O]),React.useMemo((function(){return{getState:function(){return s.current},subscribe:function(e){return O.subscribe(e)},actions:c,query:R}}),[c,R,O])}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(){this.subscribers=[]}return e.prototype.subscribe=function(e){return this.subscribers.push(e),this.unsubscribe.bind(this)},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(){for(var e=0;e<this.subscribers.length;e++)this.subscribers[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,u=t.right,s=t.width,R=t.height,c=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(u),width:Math.round(s),height:Math.round(R),outerWidth:Math.round(s+c.left+c.right),outerHeight:Math.round(R+c.top+c.bottom),margin:c,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),u=React.useRef(null),s=React.useCallback((function(e){return _assign(_assign({},e),{actions:o,query:i})}),[o,i]);a.current&&t&&(u.current=t(r(),i),a.current=!1);var R=React.useState(s(u.current)),c=R[0],O=R[1];return React.useEffect((function(){var e,o=!1;return t&&(e=n((function(){try{if(o)return;var e=r(),n=t(e,i);isEqualWith(n,u.current)||(u.current=n,window.state=e,O(s(u.current)))}catch(e){console.warn(e)}}))),function(){o=!0,e&&e()}}),[t,r,s,i,n]),c}function useHandlerGuard(e,t){var n=React.useRef(t);n.current=t;var r=Object.keys(e).reduce((function(t,r){return t[r]=function(){for(var t,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return n.current?(t=e[r])[1].apply(t,o):{}},t}),{}),o=React.useRef({});return React.useMemo((function(){return Object.keys(r).reduce((function(t,n){var i=o.current[n]||{};return t[n]=function(t,a){if(t){i.node===t&&i.opts===a||i.unsubscribe&&i.unsubscribe();var u=e[n][0],s=function(e){return r[n](e,a)},R=!!e[n][2];t.addEventListener(u,s,R),o.current={node:t,opts:a,unsubscribe:function(){return t.removeEventListener(u,s,R)}}}},t}),{})}),[e,r])}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)}}function useConnectorHooks(e,t){void 0===t&&(t=!0);var n=React.useRef(e);return React.useMemo((function(){var e=n.current;return Object.keys(e).reduce((function(n,r){var o,i;return e[r]instanceof Array?(o=e[r][0],i=e[r][1]):o=e[r],n[r]=t||!t&&!i?o&&wrapHookToRecognizeElement(o):i&&wrapHookToRecognizeElement(i),n}),{})}),[t])}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,[])};exports.ERROR_CANNOT_DRAG=ERROR_CANNOT_DRAG,exports.ERROR_DUPLICATE_NODEID=ERROR_DUPLICATE_NODEID,exports.ERROR_FRAME_IMMEDIATE_NON_CANVAS=ERROR_FRAME_IMMEDIATE_NON_CANVAS,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_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_CANVAS=ERROR_MOVE_TOP_LEVEL_CANVAS,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_ROOT_CANVAS_NO_ID=ERROR_ROOT_CANVAS_NO_ID,exports.ERRROR_NOT_IN_RESOLVER=ERRROR_NOT_IN_RESOLVER,exports.ROOT_NODE=ROOT_NODE,exports.RenderIndicator=RenderIndicator,exports.cloneWithRef=cloneWithRef,exports.createQuery=createQuery,exports.getComputedStyle=getComputedStyle,exports.getDOMInfo=getDOMInfo,exports.getDOMMargin=getDOMMargin,exports.getDOMPadding=getDOMPadding,exports.styleInFlow=styleInFlow,exports.useCollector=useCollector,exports.useConnectorHooks=useConnectorHooks,exports.useEffectOnce=useEffectOnce,exports.useHandlerGuard=useHandlerGuard,exports.useMethods=useMethods;
"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="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_ROOT_CANVAS_NO_ID='A <Canvas /> that is a child of a non Canvas node must specify an `id` prop, eg: <Canvas id="MyCanvas">...</Canvas> ',ERROR_MISSING_PLACEHOLDER_PLACEMENT="Placeholder required placement info (parent, index, or where) is missing",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_CANVAS="A <Canvas /> that is a child of a non-Canvas node cannot be moved",ERROR_MOVE_ROOT_NODE="Root Node cannot be moved",ERROR_MOVE_TO_DESCENDANT="Cannot move node into a descendant",ERRROR_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_FRAME_IMMEDIATE_NON_CANVAS="The immediate child of <Frame /> has to be a Canvas",_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]),l=React.useCallback((function(){return c.current}),[]),d=React.useMemo((function(){return new Watcher(l)}),[l]);return React.useEffect((function(){c.current=a,d.notify()}),[a,d]),React.useMemo((function(){return{getState:l,subscribe:function(e,t){return d.subscribe(e,t)},actions:R,query:u}}),[R,u,d,l])}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){var n=this,r=new Subscriber((function(){return e(n.getState())}),t);return this.subscribers.push(r),this.unsubscribe.bind(this,r)},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(){var e=this;setTimeout((function(){for(var t=0;t<e.subscribers.length;t++)e.subscribers[t].collect()}))},e}(),Subscriber=function(){function e(e,t){this.collector=e,this.onChange=t}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),l=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:l,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)),l=R[0],d=R[1];return React.useEffect((function(){var e;return c.current&&(e=n((function(e){return c.current(e,i)}),(function(e){d(u(e))}))),function(){e&&e()}}),[u,i,n]),l}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,[])},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()}))}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){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.store=e}return e.prototype.connectors=function(){var t=this,n=this.handlers()||{};return Object.keys(n).reduce((function(r,o){var i=n[o],a=i.init,s=i.events;return a||s?(r[o]=wrapHookToRecognizeElement((function(n,r){var i;document.body.contains(n)||e.wm.delete(n);var c=e.wm.get(n);if(c&&c[o]){if(c[o].opts===r)return;c[o].remove()}e.wm.set(n,_assign(_assign({},c),((i={})[o]=new WatchHandler(t.store,n,r,{init:a,events:s}),i)))})),r):(r[o]=function(){},r)}),{})},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.wm=new WeakMap,e}();exports.ERROR_CANNOT_DRAG=ERROR_CANNOT_DRAG,exports.ERROR_DUPLICATE_NODEID=ERROR_DUPLICATE_NODEID,exports.ERROR_FRAME_IMMEDIATE_NON_CANVAS=ERROR_FRAME_IMMEDIATE_NON_CANVAS,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_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_CANVAS=ERROR_MOVE_TOP_LEVEL_CANVAS,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_ROOT_CANVAS_NO_ID=ERROR_ROOT_CANVAS_NO_ID,exports.ERRROR_NOT_IN_RESOLVER=ERRROR_NOT_IN_RESOLVER,exports.Handlers=Handlers,exports.ROOT_NODE=ROOT_NODE,exports.RenderIndicator=RenderIndicator,exports.cloneWithRef=cloneWithRef,exports.createQuery=createQuery,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 n,{useMemo as e,useReducer as r,useRef as o,useEffect as i,useCallback as a,useState as u,cloneElement as c,isValidElement as s}from"react";import d from"lodash.isequalwith";import f from"tiny-invariant";var p="canvas-ROOT",l="Parent id cannot be ommited",h="Attempting to add a node with duplicated id",v="Node does not exist, it may have been removed",b='A <Canvas /> that is a child of a non Canvas node must specify an `id` prop, eg: <Canvas id="MyCanvas">...</Canvas> ',m="Placeholder required placement info (parent, index, or where) is missing",g="Target parent rejects incoming node",y="Current parent rejects outgoing node",w="Cannot move node that is not a direct child of a Canvas node",C="Cannot move node into a non-Canvas parent",x="A <Canvas /> that is a child of a non-Canvas node cannot be moved",O="Root Node cannot be moved",T="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.",I="The node has specified a canDrag() rule that prevents it from being dragged",M="Invalid parameter Node Id specified",j="The immediate child of <Frame /> has to be a Canvas",E=function(){return(E=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t}).apply(this,arguments)};function R(n,a,u){var c=e((function(){var e,r;return"function"==typeof n?e=n:(e=n.methods,r=n.patchListener),[function(n,o){var i=u&&q(u,(function(){return n}));return t(n,(function(t){var n;return(n=e(t,i))[o.type].apply(n,o.payload)}),r)},e]}),[n,u]),s=c[1],d=r(c[0],a),f=d[0],p=d[1],l=o();l.current=f;var h=e((function(){return u?q(u,(function(){return l.current})):[]}),[u]),v=e((function(){return Object.keys(s(null,null)).reduce((function(t,n){return t[n]=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return p({type:n,payload:t})},t}),{})}),[s]),b=e((function(){return new A}),[]);return i((function(){l.current=f,b.notify()}),[f,b]),e((function(){return{getState:function(){return l.current},subscribe:function(t){return b.subscribe(t)},actions:v,query:h}}),[v,h,b])}function q(t,n){return Object.keys(t()).reduce((function(e,r){var o;return E(E({},e),((o={})[r]=function(){for(var e,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return(e=t(n()))[r].apply(e,o)},o))}),{})}var A=function(){function t(){this.subscribers=[]}return t.prototype.subscribe=function(t){return this.subscribers.push(t),this.unsubscribe.bind(this)},t.prototype.unsubscribe=function(t){if(this.subscribers.length){var n=this.subscribers.indexOf(t);if(n>-1)return this.subscribers.splice(n,1)}},t.prototype.notify=function(){for(var t=0;t<this.subscribers.length;t++)this.subscribers[t]()},t}(),L=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)}},N=function(t){var n=t.getBoundingClientRect(),e=n.x,r=n.y,o=n.top,i=n.left,a=n.bottom,u=n.right,c=n.width,s=n.height,d=B(t),f=L(t);return{x:Math.round(e),y:Math.round(r),top:Math.round(o),left:Math.round(i),bottom:Math.round(a),right:Math.round(u),width:Math.round(c),height:Math.round(s),outerWidth:Math.round(c+d.left+d.right),outerHeight:Math.round(s+d.top+d.bottom),margin:d,padding:f,inFlow:t&&t.parentElement&&!!D(t,t.parentElement)}},P=function(t){return window.getComputedStyle(t)},D=function(t,n){var e=P(t),r=P(n);if(!(e.overflow&&"visible"!==e.overflow||"none"!==r.float||n&&"flex"===r.display&&"column"!==r["flex-direction"])){switch(e.position){case"static":case"relative":break;default:return}switch(t.tagName){case"TR":case"TBODY":case"THEAD":case"TFOOT":return!0}switch(e.display){case"block":case"list-item":case"table":case"flex":return!0}}};function F(t,n){var e=t.subscribe,r=t.getState,c=t.actions,s=t.query,f=o(!0),p=o(null),l=a((function(t){return E(E({},t),{actions:c,query:s})}),[c,s]);f.current&&n&&(p.current=n(r(),s),f.current=!1);var h=u(l(p.current)),v=h[0],b=h[1];return i((function(){var t,o=!1;return n&&(t=e((function(){try{if(o)return;var t=r(),e=n(t,s);d(e,p.current)||(p.current=e,window.state=t,b(l(p.current)))}catch(t){console.warn(t)}}))),function(){o=!0,t&&t()}}),[n,r,l,s,e]),v}function H(t,n){var r=o(n);r.current=n;var i=Object.keys(t).reduce((function(n,e){return n[e]=function(){for(var n,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return r.current?(n=t[e])[1].apply(n,o):{}},n}),{}),a=o({});return e((function(){return Object.keys(i).reduce((function(n,e){var r=a.current[e]||{};return n[e]=function(n,o){if(n){r.node===n&&r.opts===o||r.unsubscribe&&r.unsubscribe();var u=t[e][0],c=function(t){return i[e](t,o)},s=!!t[e][2];n.addEventListener(u,c,s),a.current={node:n,opts:o,unsubscribe:function(){return n.removeEventListener(u,c,s)}}}},n}),{})}),[t,i])}function W(t,n){n&&("function"==typeof t?t(n):t.current=n)}function z(t,n){var e=t.ref;return f("string"!=typeof e,"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"),c(t,e?{ref:function(t){W(e,t),W(n,t)}}:{ref:n})}function Y(t){return function(n,e){if(void 0===n&&(n=null),!s(n)){var r=n;return r&&t(r,e),r}var o=n;return function(t){if("string"!=typeof t.type)throw new Error}(o),z(o,t)}}function G(t,n){void 0===n&&(n=!0);var r=o(t);return e((function(){var t=r.current;return Object.keys(t).reduce((function(e,r){var o,i;return t[r]instanceof Array?(o=t[r][0],i=t[r][1]):o=t[r],e[r]=n||!n&&!i?o&&Y(o):i&&Y(i),e}),{})}),[n])}var J=function(t){return n.createElement("div",{style:E({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},t.style)})},K=function(t){i(t,[])};export{I as ERROR_CANNOT_DRAG,h as ERROR_DUPLICATE_NODEID,j as ERROR_FRAME_IMMEDIATE_NON_CANVAS,k as ERROR_INFINITE_CANVAS,v as ERROR_INVALID_NODEID,M as ERROR_INVALID_NODE_ID,m as ERROR_MISSING_PLACEHOLDER_PLACEMENT,g as ERROR_MOVE_INCOMING_PARENT,w as ERROR_MOVE_NONCANVAS_CHILD,y as ERROR_MOVE_OUTGOING_PARENT,O as ERROR_MOVE_ROOT_NODE,x as ERROR_MOVE_TOP_LEVEL_CANVAS,T as ERROR_MOVE_TO_DESCENDANT,C as ERROR_MOVE_TO_NONCANVAS_PARENT,l as ERROR_NOPARENT,b as ERROR_ROOT_CANVAS_NO_ID,S as ERRROR_NOT_IN_RESOLVER,p as ROOT_NODE,J as RenderIndicator,z as cloneWithRef,q as createQuery,P as getComputedStyle,N as getDOMInfo,B as getDOMMargin,L as getDOMPadding,D as styleInFlow,F as useCollector,G as useConnectorHooks,K as useEffectOnce,H as useHandlerGuard,R as useMethods};
import t from"immer";import e,{useMemo as n,useReducer as r,useRef as o,useCallback as i,useEffect as a,useState as s,cloneElement as u,isValidElement as c}from"react";import d from"lodash.isequalwith";import f from"tiny-invariant";var l="canvas-ROOT",h="Parent id cannot be ommited",p="Attempting to add a node with duplicated id",v="Node does not exist, it may have been removed",m='A <Canvas /> that is a child of a non Canvas node must specify an `id` prop, eg: <Canvas id="MyCanvas">...</Canvas> ',b="Placeholder required placement info (parent, index, or where) is missing",g="Target parent rejects incoming node",y="Current parent rejects outgoing node",w="Cannot move node that is not a direct child of a Canvas node",C="Cannot move node into a non-Canvas parent",T="A <Canvas /> that is a child of a non-Canvas node cannot be moved",M="Root Node cannot be moved",O="Cannot move node into a descendant",x="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.",I="The node has specified a canDrag() rule that prevents it from being dragged",R="Invalid parameter Node Id specified",k="The immediate child of <Frame /> has to be a Canvas",E=function(){return(E=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 j(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),o=0;for(e=0;e<n;e++)for(var i=arguments[e],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}function D(e,s,u){var c=n((function(){var n,r;return"function"==typeof e?n=e:(n=e.methods,r=e.patchListener),[function(e,o){var i=u&&q(u,(function(){return e}));return t(e,(function(t){var e;return(e=n(t,i))[o.type].apply(e,o.payload)}),r)},n]}),[e,u]),d=c[1],f=r(c[0],s),l=f[0],h=f[1],p=o();p.current=l;var v=n((function(){return u?q(u,(function(){return p.current})):[]}),[u]),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 h({type:e,payload:t})},t}),{})}),[d]),b=i((function(){return p.current}),[]),g=n((function(){return new A(b)}),[b]);return a((function(){p.current=l,g.notify()}),[l,g]),n((function(){return{getState:b,subscribe:function(t,e){return g.subscribe(t,e)},actions:m,query:v}}),[m,v,g,b])}function q(t,e){return Object.keys(t()).reduce((function(n,r){var o;return E(E({},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 A=function(){function t(t){this.subscribers=[],this.getState=t}return t.prototype.subscribe=function(t,e){var n=this,r=new L((function(){return t(n.getState())}),e);return this.subscribers.push(r),this.unsubscribe.bind(this,r)},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(){var t=this;setTimeout((function(){for(var e=0;e<t.subscribers.length;e++)t.subscribers[e].collect()}))},t}(),L=function(){function t(t,e){this.collector=t,this.onChange=e}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)}},N=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)}},P=function(t){var e=t.getBoundingClientRect(),n=e.x,r=e.y,o=e.top,i=e.left,a=e.bottom,s=e.right,u=e.width,c=e.height,d=N(t),f=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(s),width:Math.round(u),height:Math.round(c),outerWidth:Math.round(u+d.left+d.right),outerHeight:Math.round(c+d.top+d.bottom),margin:d,padding:f,inFlow:t&&t.parentElement&&!!W(t,t.parentElement)}},F=function(t){return window.getComputedStyle(t)},W=function(t,e){var n=F(t),r=F(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 H(t,e){var n=t.subscribe,r=t.getState,u=t.actions,c=t.query,d=o(!0),f=o(null),l=o(e);l.current=e;var h=i((function(t){return E(E({},t),{actions:u,query:c})}),[u,c]);d.current&&e&&(f.current=e(r(),c),d.current=!1);var p=s(h(f.current)),v=p[0],m=p[1];return a((function(){var t;return l.current&&(t=n((function(t){return l.current(t,c)}),(function(t){m(h(t))}))),function(){t&&t()}}),[h,c,n]),v}function z(t,e){e&&("function"==typeof t?t(e):t.current=e)}function Y(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"),u(t,n?{ref:function(t){z(n,t),z(e,t)}}:{ref:e})}function G(t){return function(e,n){if(void 0===e&&(e=null),!c(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),Y(o,t)}}var J=function(t){return e.createElement("div",{style:E({position:"fixed",display:"block",opacity:1,borderStyle:"solid",borderWidth:"1px",borderColor:"transparent",zIndex:99999},t.style)})},K=function(t){a(t,[])},Q=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()}))}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){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}(),U=function(){function t(t){this.store=t}return t.prototype.connectors=function(){var e=this,n=this.handlers()||{};return Object.keys(n).reduce((function(r,o){var i=n[o],a=i.init,s=i.events;return a||s?(r[o]=G((function(n,r){var i;document.body.contains(n)||t.wm.delete(n);var u=t.wm.get(n);if(u&&u[o]){if(u[o].opts===r)return;u[o].remove()}t.wm.set(n,E(E({},u),((i={})[o]=new Q(e.store,n,r,{init:a,events:s}),i)))})),r):(r[o]=function(){},r)}),{})},t.getConnectors=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=new(this.bind.apply(this,j([void 0],t)));return n.connectors()},t.wm=new WeakMap,t}();export{I as ERROR_CANNOT_DRAG,p as ERROR_DUPLICATE_NODEID,k as ERROR_FRAME_IMMEDIATE_NON_CANVAS,S as ERROR_INFINITE_CANVAS,v as ERROR_INVALID_NODEID,R as ERROR_INVALID_NODE_ID,b as ERROR_MISSING_PLACEHOLDER_PLACEMENT,g as ERROR_MOVE_INCOMING_PARENT,w as ERROR_MOVE_NONCANVAS_CHILD,y as ERROR_MOVE_OUTGOING_PARENT,M as ERROR_MOVE_ROOT_NODE,T as ERROR_MOVE_TOP_LEVEL_CANVAS,O as ERROR_MOVE_TO_DESCENDANT,C as ERROR_MOVE_TO_NONCANVAS_PARENT,h as ERROR_NOPARENT,m as ERROR_ROOT_CANVAS_NO_ID,x as ERRROR_NOT_IN_RESOLVER,U as Handlers,l as ROOT_NODE,J as RenderIndicator,Y as cloneWithRef,q as createQuery,F as getComputedStyle,P as getDOMInfo,N as getDOMMargin,B as getDOMPadding,W as styleInFlow,H as useCollector,K as useEffectOnce,D as useMethods,G as wrapHookToRecognizeElement};

@@ -5,5 +5,5 @@ export * from "./constants";

export * from "./useCollector";
export * from "./useHandlerGuard";
export * from "./useConnectorHooks";
export * from "./wrapConnectorHooks";
export * from "./RenderIndicator";
export * from "./useEffectOnce";
export * from "./Handlers";
import { PatchListener } from "immer";
export declare type SubscriberAndCallbacksFor<M extends MethodsOrOptions, Q extends QueryMethods = any> = {
subscribe: (listener: () => void) => void;
subscribe: any;
getState: () => {

@@ -5,0 +5,0 @@ prev: StateFor<M>;

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

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

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

},
"gitHead": "4b4b4836232003ad6022f9a73e7eb96088d17460"
"gitHead": "236b010cb2681630561dfc6e653cf6e88c2cd032"
}

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