Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@clutch-creator/bridge

Package Overview
Dependencies
Maintainers
6
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clutch-creator/bridge - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

2

index.js

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

module.exports=function(n){var o={};function i(e){if(o[e])return o[e].exports;var t=o[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,i),t.l=!0,t.exports}return i.m=n,i.c=o,i.d=function(e,t,n){if(!i.o(e,t))Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){if("undefined"!=typeof Symbol&&Symbol.toStringTag)Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(t,e){if(1&e)t=i(t);if(8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)i.d(n,o,function(e){return t[e]}.bind(null,o));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=11)}([function(e,t){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,t){e.exports=require("lodash/get")},function(e,t){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,t){e.exports=require("@babel/runtime/helpers/classCallCheck")},function(e,t){e.exports=require("@babel/runtime/helpers/createClass")},function(e,t){e.exports=require("lodash/find")},function(e,t){e.exports=require("@babel/runtime/helpers/typeof")},function(e,t){e.exports=require("classnames")},function(e,t){e.exports=require("@babel/runtime/helpers/objectWithoutProperties")},function(e,t){e.exports=require("lodash/findIndex")},function(e,t){function n(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}n.keys=function(){return[]},n.resolve=n,(e.exports=n).id=10},function(e,t,s){"use strict";s.r(t);var n=s(8),r=s.n(n),o=s(3),u=s.n(o),i=s(4),a=s.n(i),c=s(0),f=s.n(c),l=s(6),p=s.n(l),d=s(2),h=s.n(d),g=s(9),v=s.n(g),y=s(5),m=s.n(y),b=s(7),C=s.n(b),O=s(1),k=s.n(O),P=Object.prototype.hasOwnProperty;function w(e,t,n){if(e===t)return!0;if(e&&!t||t&&!e)return!1;var o=0,i=0;for(var r in e){if(P.call(e,r)&&(n?!n(e[r],t[r]):e[r]!==t[r]))return!1;o+=1}for(var s in t)if(P.call(t,s))i+=1;return o===i}function S(e){var t=e||{},n=t.keys,o=t.rootInstances,i="".concat(t.id);if(n&&n.length)i+=".".concat(n.map(function(e){return e.key}).join("."));if(o&&o.length)i+=".".concat(o.join("."));return i}function j(e,t,n){if(!e||!t)return!1;else return e.id===t.id&&function(e,t){if(e===t||!e&&!t)return!0;var n=e||[],o=t||[];if(n.length!==o.length)return!1;else return w(n,o)}(e.rootInstances,t.rootInstances)&&(n||function(e,t){if(e===t||!e&&!t)return!0;var n=e||[],o=t||[];if(n.length!==o.length)return!1;else return n.map(function(e){return e.key}).join()===o.map(function(e){return e.key}).join()}(e.keys,t.keys))}function M(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);if(e)o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable});n.push.apply(n,o)}return n}var E=function(){function c(e,t,n,o,i,r){var s=this;u()(this,c),f()(this,"onMouseOver",function(e){if(s.clutchBridge.editing)e.stopPropagation(),s.clutchBridge.overComponent(s.selection)}),f()(this,"onMouseOut",function(){if(s.clutchBridge.editing)s.clutchBridge.outComponent(s.selection)}),f()(this,"onContextMenu",function(e){if(s.clutchBridge.editing)e.stopPropagation(),e.preventDefault(),s.clutchBridge.openComponentContextMenu(s.selection,e)}),f()(this,"onClick",function(e){if(s.clutchBridge.editing)e.stopPropagation(),e.preventDefault(),s.clutchBridge.selectComponent(s.selection)}),f()(this,"onDoubleClick",function(){if(s.clutchBridge.editing)s.clutchBridge.unlockComponent(s.selection)}),this.selection=t,this.clutchBridge=e,this.updateComponent=i,this.setState=r,this.reference=void 0,this.childReferences=[],this.masterProps=o,this.outboundProps=null,this.inboundProps={},this.state=void 0,this.parentSelection=n}return a()(c,[{key:"setReference",value:function(e){if(this.reference=e,this.parentSelection)this.clutchBridge.registerComponentChildReference(this.parentSelection,this.selection,this.reference);e.addEventListener("mouseover",this.onMouseOver),e.addEventListener("mouseout",this.onMouseOut),e.addEventListener("click",this.onClick),e.addEventListener("doubleclick",this.onDoubleClick),e.addEventListener("contextmenu",this.onContextMenu)}},{key:"setChildReference",value:function(e,t){if(!this.reference){var n=S(e),o=m()(this.childReferences,function(e){return e.id===n});if(o)o.reference=t;else this.childReferences.push({id:n,reference:t});if(this.parentSelection)this.clutchBridge.registerComponentChildReference(this.parentSelection,e,t)}}},{key:"getElementRect",value:function(e){var t={};try{var n=e.getBoundingClientRect();t={top:n.top,right:n.right,bottom:n.bottom,left:n.left,width:n.width,height:n.height}}catch(e){}return t}},{key:"getElementBoxLayout",value:function(e){var t={};try{t={paddingLeft:e.getStyle("padding-left"),paddingRight:e.getStyle("padding-right"),paddingTop:e.getStyle("padding-top"),paddingBottom:e.getStyle("padding-bottom"),marginLeft:e.getStyle("margin-left"),marginRight:e.getStyle("margin-right"),marginTop:e.getStyle("margin-top"),marginBottom:e.getStyle("margin-bottom")}}catch(e){}return t}},{key:"updateRect",value:function(){var o=this,i={};if(this.reference)i=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};if(e%2)M(Object(n),!0).forEach(function(e){f()(t,e,n[e])});else if(Object.getOwnPropertyDescriptors)Object.defineProperties(t,Object.getOwnPropertyDescriptors(n));else M(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({},this.getElementRect(this.reference),{},this.getElementBoxLayout(this.reference));else{this.childReferences.forEach(function(e,t){var n=o.getElementRect(e.reference);if(0===t)i=n;else i.top=Math.min(n.top,i.top),i.bottom=Math.max(n.bottom,i.bottom),i.left=Math.min(n.left,i.left),i.right=Math.max(n.right,i.right),i.width=i.right-i.left,i.height=i.bottom-i.top})}if(!w(this.calculatedRect,i))this.calculatedRect=i,this.clutchBridge.updateComponentRect(this.selection,i)}},{key:"updateOutboundProps",value:function(e,t){this.outboundProps=this.outboundProps||{},this.outboundProps[e]=t}},{key:"updateInboundProps",value:function(e){this.inboundProps=e}},{key:"updateMasterProps",value:function(e){this.masterProps=e}},{key:"updateState",value:function(e){this.state=e}},{key:"setComponentState",value:function(e){this.setState(e)}},{key:"matchesSelection",value:function(e,t){var n=1<arguments.length&&void 0!==t?t:!1;return j(e,this.selection,n)}}]),c}();function B(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);if(e)o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable});n.push.apply(n,o)}return n}s.d(t,"classnames",function(){return R}),s.d(t,"getUniqueClassName",function(){return x}),s.d(t,"mergeProperty",function(){return L}),s.d(t,"mergeVariants",function(){return _}),s.d(t,"mergeProperties",function(){return I}),s.d(t,"mergeOverrides",function(){return A}),s.d(t,"getOverrides",function(){return D}),s.d(t,"getClutchProps",function(){return q}),s.d(t,"hasVariant",function(){return U}),s.d(t,"propertyBind",function(){return N});var R=C.a;function x(e,t){var n;if("undefined"!=typeof window&&window.CLUTCH_CLASSES_MAP){var o=S(e);if(void 0===window.CLUTCH_CLASSES_MAP["".concat(o).concat(t)])n="-clutch-identifier".concat(Object.keys(window.CLUTCH_CLASSES_MAP).length),window.CLUTCH_CLASSES_MAP["".concat(o).concat(t)]=n;else n=window.CLUTCH_CLASSES_MAP["".concat(o).concat(t)]}return n}function L(e){for(var t=e,n=arguments.length,o=new Array(1<n?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return o.forEach(function(e){if(void 0!==e)if(e&&e.className&&e.style)t={className:C()(t&&t.className,e&&e.className),style:Object.assign({},t&&t.style,e&&e.style)};else t=e}),t}function _(e){for(var n=Object.assign({},e),t=arguments.length,o=new Array(1<t?t-1:0),i=1;i<t;i++)o[i-1]=arguments[i];if(o&&o.length)o.forEach(function(e){n=Object.assign({},n,e)});return Object.keys(n).reduce(function(e,t){if(n[t])return[].concat(h()(e),[t]);else return e},[])}function I(e){for(var r=Object.assign({},e),t=arguments.length,n=new Array(1<t?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];if(n&&n.length)n.forEach(function(i){if(i&&"object"===p()(i))Object.keys(i).forEach(function(e){var t=r[e],n=i[e];if("variants"===e){if(n&&n.length)r.variants=h()(t||[]),n.forEach(function(e){if(e&&"string"==typeof e&&!r.variants.includes(e))r.variants.push(e)})}else if("clutchProps"===e)if(t&&n&&n.overrides){var o=t.overrides||{};Object.keys(n.overrides).forEach(function(e){o[e]=I(o[e],n.overrides[e])}),r[e]=Object.assign({},t,n,{overrides:o})}else r[e]=Object.assign({},t,n);else r[e]=L(t,n)})});return r}function A(e){for(var n=Object.assign({},e),t=arguments.length,o=new Array(1<t?t-1:0),i=1;i<t;i++)o[i-1]=arguments[i];return Object.keys(o).forEach(function(t){if(t)Object.keys(t).forEach(function(e){n[e]=I(n[e],t[e])})}),n}function D(e){var t,n=k()(e,["clutchProps","selection"]),o=k()(e,["clutchProps","overrides"]);if(n&&o){var i=n.rootInstances||[];t=o["".concat(i.join("."),".").concat(n.id)]}return t}function q(e,t,n,o,i,r){var s=k()(t,["clutchProps","selection"],{}),c=i.keys||[];if(void 0!==o)c=[].concat(h()(c),[{componentId:i.id,key:o}]);var u=s.rootInstances||[];if(!s.rootInstances)u=[];else u=[].concat(h()(u),[s.id]);var a=k()(t,["clutchProps","overrides"]);if(r){a=Object.assign({},a);var f=s.rootInstances&&s.rootInstances.length;Object.keys(r).forEach(function(e){var t=e;if(f)t="".concat(s.rootInstances.join("."),".").concat(e);if(a[t])a[t]=I(r[e],a[t]);else a[t]=r[e]})}return{selection:{id:e,rootInstances:u,keys:c},parentSelection:i,masterProps:t,flowProps:n,overrides:a}}function U(e,t){return e&&Array.isArray(e)&&e.includes(t)?!0:void 0}function N(e,t){var n;try{if(void 0!==(n=k()(this,e))&&t)n+=t}catch(e){}return n}var T=function(){function e(){var i=this;if(u()(this,e),f()(this,"shallowEqual",w),f()(this,"getSelectionUID",S),f()(this,"onReceivedMessage",function(e){if("string"==typeof e.data){var t=JSON.parse(e.data),n=t.type,o=r()(t,["type"]);switch(n){case"setComponentState":i.setComponentState(o.selection,o.state);break;case"setEditing":i.setEditing(o.editing);break;case"request-binds-resolve":i.resolveBinds(o.selection,o.binds)}}}),f()(this,"setEditing",function(e){i.editing=e}),f()(this,"checkComponentsRects",function(){if("undefined"!=typeof window)i.registeredComponents.forEach(function(e){return e.updateRect()}),window.requestAnimationFrame(i.checkComponentsRects)}),this.registeredComponents=[],this.editing=!1,"undefined"!=typeof window)window.addEventListener("message",this.onReceivedMessage,!1),window.requestAnimationFrame(this.checkComponentsRects),this.sendMessage({type:"getEditing"})}return a()(e,[{key:"sendMessage",value:function(e){if("development"===process.env.NODE_ENV&&"undefined"!=typeof window){var t=JSON.stringify(e,(n=new WeakSet,function(e,t){if("object"===p()(t)&&null!==t){if(n.has(t))return;n.add(t)}if("function"==typeof t)return t.toString();if("object"===p()(t)&&t.constructor&&t.constructor.name.includes("HTML"))return"<".concat(t.constructor.name,">");else return t}));if(window.opener)window.opener.postMessage(t,"*");else window.parent.postMessage(t,"*")}var n}},{key:"removeWindowListener",value:function(){if("undefined"!=typeof window)window.removeEventListener("resize",this.checkComponentsRects)}},{key:"unlistenStructure",value:function(){if(this.observerBody)this.observerBody.disconnect(),delete this.observerBody}},{key:"destroy",value:function(){this.unlistenStructure()}},{key:"propertyBind",value:function(e,t){var n;try{if(void 0!==(n=k()(this,e))&&t)n+=t}catch(e){}return n}},{key:"resolveBinds",value:function(e,t){var n=this,o=this.findComponentBySelection(e);if(o){var i=t.map(function(e){return function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};if(e%2)B(Object(n),!0).forEach(function(e){f()(t,e,n[e])});else if(Object.getOwnPropertyDescriptors)Object.defineProperties(t,Object.getOwnPropertyDescriptors(n));else B(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({},e,{bind:n.processBind(e.bind,o.flowProps,o.masterProps)})}),r={type:"return-binds-resolve",id:this.getSelectionUID(e),binds:i};this.sendMessage(r)}}},{key:"processBind",value:function(e,t,n){var o=e;try{if("PROP"===e.type){if(void 0!==(o=k()({flowProps:t,masterProps:n},e.value))&&e.suffix)o+=e.suffix}else if("EXPRESSION"===e.type){var i="(function () {\n return ".concat(e.value,";\n })");o=window.eval(i).call({flowProps:t,masterProps:n})}else if("MODULE"===e.type){var r=s(10)(e.path).default;o=window.eval(r).call({flowProps:t,masterProps:n})}}catch(e){o={type:"__CLUTCH_ERROR__",message:e.message}}return o}},{key:"registerComponent",value:function(e,t,n,o,i){var r=this.findComponentIndexBySelection(e),s=new E(this,e,t,n,o,i);if(-1!==r)this.registeredComponents.splice(r,1),s.prevUnregistered=!0;this.registeredComponents.unshift(s),this.sendMessage({type:"registerComponent",selection:e})}},{key:"unregisterComponent",value:function(e){var t=this.findComponentIndexBySelection(e);if(-1!==t){var n=this.registeredComponents[t];if(!n.prevUnregistered)this.registeredComponents.splice(t,1);else delete n.prevUnregistered}this.sendMessage({type:"unregisterComponent",selection:e})}},{key:"findComponentIndexBySelection",value:function(t){return v()(this.registeredComponents,function(e){return e.matchesSelection(t)})}},{key:"findComponentBySelection",value:function(t){return m()(this.registeredComponents,function(e){return e.matchesSelection(t)})}},{key:"findComponentsBySelection",value:function(t,e){var n=1<arguments.length&&void 0!==e?e:!1;return this.registeredComponents.filter(function(e){return e.matchesSelection(t,n)})}},{key:"changeComponentProp",value:function(e,t,n){this.sendMessage({type:"changeComponentProp",selection:e,propName:t,value:n})}},{key:"overComponent",value:function(e){this.sendMessage({type:"overComponent",selection:e})}},{key:"outComponent",value:function(e){this.sendMessage({type:"outComponent",selection:e})}},{key:"selectComponent",value:function(e){this.sendMessage({type:"selectComponent",selection:e})}},{key:"unlockComponent",value:function(e){this.sendMessage({type:"unlockComponent",selection:e})}},{key:"registerComponentReference",value:function(e,t){var n=this.findComponentBySelection(e);if(n&&null!==t)n.setReference(t)}},{key:"registerComponentChildReference",value:function(e,t,n){var o=this.findComponentBySelection(e);if(o)o.setChildReference(t,n)}},{key:"openComponentContextMenu",value:function(e,t){this.sendMessage({type:"openComponentContextMenu",selection:e,eventX:t.clientX,eventY:t.clientY})}},{key:"setHistory",value:function(e){var t=e.history;if(this.history=Object.assign(this.history,t),this.canvasId)this.unlistenHistory=t.listen(this.persistHistory)}},{key:"updateComponentOutboundProps",value:function(e,t,n){this.sendMessage({type:"updateComponentOutboundProps",selection:e,area:t,outboundProps:n})}},{key:"updateComponentInboundProps",value:function(e,t){this.sendMessage({type:"updateComponentInboundProps",selection:e,inboundProps:t})}},{key:"updateComponentMasterProps",value:function(e,t){var n=this.findComponentBySelection(e);if(n)n.updateMasterProps(t)}},{key:"updateComponentState",value:function(e,t){this.sendMessage({type:"updateComponentState",selection:e,state:t})}},{key:"updateComponentRect",value:function(e,t){this.sendMessage({type:"updateComponentRect",selection:e,rect:t})}},{key:"setComponentState",value:function(e,t){var n=this.findComponentBySelection(e);if(n)n.setComponentState(t)}},{key:"setCanvasError",value:function(e){if(this.sendMessage({type:"setCanvasError",err:e}),e)console.error(e)}}]),e}();t.default=new T}]);
module.exports=function(n){var o={};function i(e){if(o[e])return o[e].exports;var t=o[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,i),t.l=!0,t.exports}return i.m=n,i.c=o,i.d=function(e,t,n){if(!i.o(e,t))Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){if("undefined"!=typeof Symbol&&Symbol.toStringTag)Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(t,e){if(1&e)t=i(t);if(8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)i.d(n,o,function(e){return t[e]}.bind(null,o));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=11)}([function(e,t){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,t){e.exports=require("lodash/get")},function(e,t){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,t){e.exports=require("@babel/runtime/helpers/classCallCheck")},function(e,t){e.exports=require("@babel/runtime/helpers/createClass")},function(e,t){e.exports=require("lodash/find")},function(e,t){e.exports=require("@babel/runtime/helpers/typeof")},function(e,t){e.exports=require("classnames")},function(e,t){e.exports=require("@babel/runtime/helpers/objectWithoutProperties")},function(e,t){e.exports=require("lodash/findIndex")},function(e,t){function n(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}n.keys=function(){return[]},n.resolve=n,(e.exports=n).id=10},function(e,t,s){"use strict";s.r(t);var n=s(8),r=s.n(n),o=s(3),u=s.n(o),i=s(4),a=s.n(i),c=s(0),f=s.n(c),l=s(6),p=s.n(l),d=s(2),h=s.n(d),g=s(9),v=s.n(g),y=s(5),m=s.n(y),b=s(7),C=s.n(b),O=s(1),k=s.n(O),P=Object.prototype.hasOwnProperty;function w(e,t,n){if(e===t)return!0;if(e&&!t||t&&!e)return!1;var o=0,i=0;for(var r in e){if(P.call(e,r)&&(n?!n(e[r],t[r]):e[r]!==t[r]))return!1;o+=1}for(var s in t)if(P.call(t,s))i+=1;return o===i}function S(e){var t=e||{},n=t.keys,o=t.rootInstances,i="".concat(t.id);if(n&&n.length)i+=".".concat(n.map(function(e){return e.key}).join("."));if(o&&o.length)i+=".".concat(o.join("."));return i}function j(e,t,n){if(!e||!t)return!1;else return e.id===t.id&&function(e,t){if(e===t||!e&&!t)return!0;var n=e||[],o=t||[];if(n.length!==o.length)return!1;else return w(n,o)}(e.rootInstances,t.rootInstances)&&(n||function(e,t){if(e===t||!e&&!t)return!0;var n=e||[],o=t||[];if(n.length!==o.length)return!1;else return n.map(function(e){return e.key}).join()===o.map(function(e){return e.key}).join()}(e.keys,t.keys))}function M(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);if(e)o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable});n.push.apply(n,o)}return n}var E=function(){function c(e,t,n,o,i,r){var s=this;u()(this,c),f()(this,"onMouseOver",function(e){if(s.clutchBridge.editing)e.stopPropagation(),s.clutchBridge.overComponent(s.selection)}),f()(this,"onMouseOut",function(){if(s.clutchBridge.editing)s.clutchBridge.outComponent(s.selection)}),f()(this,"onContextMenu",function(e){if(s.clutchBridge.editing)e.stopPropagation(),e.preventDefault(),s.clutchBridge.openComponentContextMenu(s.selection,e)}),f()(this,"onClick",function(e){if(s.clutchBridge.editing)e.stopPropagation(),e.preventDefault(),s.clutchBridge.selectComponent(s.selection)}),f()(this,"onDoubleClick",function(){if(s.clutchBridge.editing)s.clutchBridge.unlockComponent(s.selection)}),this.selection=t,this.clutchBridge=e,this.updateComponent=i,this.setState=r,this.reference=void 0,this.childReferences=[],this.masterProps=o,this.outboundProps=null,this.inboundProps={},this.state=void 0,this.parentSelection=n}return a()(c,[{key:"setReference",value:function(e){if(this.reference=e,this.parentSelection)this.clutchBridge.registerComponentChildReference(this.parentSelection,this.selection,this.reference);e.addEventListener("mouseover",this.onMouseOver),e.addEventListener("mouseout",this.onMouseOut),e.addEventListener("click",this.onClick),e.addEventListener("doubleclick",this.onDoubleClick),e.addEventListener("contextmenu",this.onContextMenu)}},{key:"setChildReference",value:function(e,t){if(!this.reference){var n=S(e),o=m()(this.childReferences,function(e){return e.id===n});if(o)o.reference=t;else this.childReferences.push({id:n,reference:t});if(this.parentSelection)this.clutchBridge.registerComponentChildReference(this.parentSelection,e,t)}}},{key:"getElementRect",value:function(e){var t={};try{var n=e.getBoundingClientRect();t={top:n.top,right:n.right,bottom:n.bottom,left:n.left,width:n.width,height:n.height}}catch(e){}return t}},{key:"getElementBoxLayout",value:function(e){var t={};try{t={paddingLeft:e.getStyle("padding-left"),paddingRight:e.getStyle("padding-right"),paddingTop:e.getStyle("padding-top"),paddingBottom:e.getStyle("padding-bottom"),marginLeft:e.getStyle("margin-left"),marginRight:e.getStyle("margin-right"),marginTop:e.getStyle("margin-top"),marginBottom:e.getStyle("margin-bottom")}}catch(e){}return t}},{key:"updateRect",value:function(){var o=this,i={};if(this.reference)i=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};if(e%2)M(Object(n),!0).forEach(function(e){f()(t,e,n[e])});else if(Object.getOwnPropertyDescriptors)Object.defineProperties(t,Object.getOwnPropertyDescriptors(n));else M(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({},this.getElementRect(this.reference),{},this.getElementBoxLayout(this.reference));else{this.childReferences.forEach(function(e,t){var n=o.getElementRect(e.reference);if(0===t)i=n;else i.top=Math.min(n.top,i.top),i.bottom=Math.max(n.bottom,i.bottom),i.left=Math.min(n.left,i.left),i.right=Math.max(n.right,i.right),i.width=i.right-i.left,i.height=i.bottom-i.top})}if(!w(this.calculatedRect,i))this.calculatedRect=i,this.clutchBridge.updateComponentRect(this.selection,i)}},{key:"updateOutboundProps",value:function(e,t){this.outboundProps=this.outboundProps||{},this.outboundProps[e]=t}},{key:"updateInboundProps",value:function(e){this.inboundProps=e}},{key:"updateMasterProps",value:function(e){this.masterProps=e}},{key:"updateState",value:function(e){this.state=e}},{key:"setComponentState",value:function(e){this.setState(e)}},{key:"matchesSelection",value:function(e,t){var n=1<arguments.length&&void 0!==t?t:!1;return j(e,this.selection,n)}}]),c}();function B(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);if(e)o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable});n.push.apply(n,o)}return n}s.d(t,"classnames",function(){return R}),s.d(t,"getUniqueClassName",function(){return x}),s.d(t,"mergeProperty",function(){return L}),s.d(t,"mergeVariants",function(){return _}),s.d(t,"mergeProperties",function(){return I}),s.d(t,"mergeOverrides",function(){return A}),s.d(t,"getOverrides",function(){return D}),s.d(t,"getClutchProps",function(){return q}),s.d(t,"hasVariant",function(){return U}),s.d(t,"propertyBind",function(){return N});var R=C.a;function x(e,t){var n;if("undefined"!=typeof window&&window.CLUTCH_CLASSES_MAP){var o=S(e);if(void 0===window.CLUTCH_CLASSES_MAP["".concat(o).concat(t)])n="-clutch-identifier".concat(Object.keys(window.CLUTCH_CLASSES_MAP).length),window.CLUTCH_CLASSES_MAP["".concat(o).concat(t)]=n;else n=window.CLUTCH_CLASSES_MAP["".concat(o).concat(t)]}return n}function L(e){for(var t=e,n=arguments.length,o=new Array(1<n?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return o.forEach(function(e){if(void 0!==e)if(e&&e.className&&e.style)t={className:C()(t&&t.className,e&&e.className),style:Object.assign({},t&&t.style,e&&e.style)};else t=e}),t}function _(e){for(var n=Object.assign({},e),t=arguments.length,o=new Array(1<t?t-1:0),i=1;i<t;i++)o[i-1]=arguments[i];if(o&&o.length)o.forEach(function(e){n=Object.assign({},n,e)});return Object.keys(n).reduce(function(e,t){if(n[t])return[].concat(h()(e),[t]);else return e},[])}function I(e){for(var r=Object.assign({},e),t=arguments.length,n=new Array(1<t?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];if(n&&n.length)n.forEach(function(i){if(i&&"object"===p()(i))Object.keys(i).forEach(function(e){var t=r[e],n=i[e];if("variants"===e){if(n&&n.length)r.variants=h()(t||[]),n.forEach(function(e){if(e&&"string"==typeof e&&!r.variants.includes(e))r.variants.push(e)})}else if("clutchProps"===e)if(t&&n&&n.overrides){var o=t.overrides||{};Object.keys(n.overrides).forEach(function(e){o[e]=I(o[e],n.overrides[e])}),r[e]=Object.assign({},t,n,{overrides:o})}else r[e]=Object.assign({},t,n);else r[e]=L(t,n)})});return r}function A(e){for(var n=Object.assign({},e),t=arguments.length,o=new Array(1<t?t-1:0),i=1;i<t;i++)o[i-1]=arguments[i];return Object.keys(o).forEach(function(t){if(t)Object.keys(t).forEach(function(e){n[e]=I(n[e],t[e])})}),n}function D(e){var t,n=k()(e,["clutchProps","selection"]),o=k()(e,["clutchProps","overrides"]);if(n&&o){var i=n.rootInstances||[];t=o["".concat(i.join("."),".").concat(n.id)]}return t}function q(e,t,n,o,i,r){var s=k()(t,["clutchProps","selection"],{}),c=i.keys||[];if(void 0!==o)c=[].concat(h()(c),[{componentId:i.id,key:o}]);var u=s.rootInstances||[];if(!s.rootInstances)u=[];else u=[].concat(h()(u),[s.id]);var a=k()(t,["clutchProps","overrides"]);if(r){a=Object.assign({},a);var f=s.rootInstances&&s.rootInstances.length;Object.keys(r).forEach(function(e){var t=e;if(f)t="".concat(s.rootInstances.join("."),".").concat(e);if(a[t])a[t]=I(r[e],a[t]);else a[t]=r[e]})}return{selection:{id:e,rootInstances:u,keys:c},parentSelection:i,masterProps:t,flowProps:n,overrides:a}}function U(e,t){return e&&Array.isArray(e)&&e.includes(t)?!0:void 0}function N(e,t){var n;try{if(void 0!==(n=k()(this,e))&&t)n+=t}catch(e){}return n}var T=function(){function e(){var i=this;if(u()(this,e),f()(this,"shallowEqual",w),f()(this,"getSelectionUID",S),f()(this,"onReceivedMessage",function(e){if("string"==typeof e.data){var t=JSON.parse(e.data),n=t.type,o=r()(t,["type"]);switch(n){case"setComponentState":i.setComponentState(o.selection,o.state);break;case"setEditing":i.setEditing(o.editing);break;case"request-binds-resolve":i.resolveBinds(o.selection,o.binds)}}}),f()(this,"setEditing",function(e){i.editing=e}),f()(this,"checkComponentsRects",function(){if("undefined"!=typeof window)i.registeredComponents.forEach(function(e){return e.updateRect()}),window.requestAnimationFrame(i.checkComponentsRects)}),this.registeredComponents=[],this.editing=!1,"undefined"!=typeof window)window.addEventListener("message",this.onReceivedMessage,!1),window.requestAnimationFrame(this.checkComponentsRects),this.sendMessage({type:"getEditing"})}return a()(e,[{key:"sendMessage",value:function(e){if("development"===process.env.NODE_ENV&&"undefined"!=typeof window){var t=JSON.stringify(e,(n=new WeakSet,function(e,t){if("object"===p()(t)&&null!==t){if(n.has(t))return;n.add(t)}if("function"==typeof t)return t.toString();if("object"===p()(t)&&null!=t&&t.constructor&&t.constructor.name.includes("HTML"))return"<".concat(t.constructor.name,">");else return t}));if(window.opener)window.opener.postMessage(t,"*");else window.parent.postMessage(t,"*")}var n}},{key:"removeWindowListener",value:function(){if("undefined"!=typeof window)window.removeEventListener("resize",this.checkComponentsRects)}},{key:"unlistenStructure",value:function(){if(this.observerBody)this.observerBody.disconnect(),delete this.observerBody}},{key:"destroy",value:function(){this.unlistenStructure()}},{key:"propertyBind",value:function(e,t){var n;try{if(void 0!==(n=k()(this,e))&&t)n+=t}catch(e){}return n}},{key:"resolveBinds",value:function(e,t){var n=this,o=this.findComponentBySelection(e);if(o){var i=t.map(function(e){return function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};if(e%2)B(Object(n),!0).forEach(function(e){f()(t,e,n[e])});else if(Object.getOwnPropertyDescriptors)Object.defineProperties(t,Object.getOwnPropertyDescriptors(n));else B(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({},e,{bind:n.processBind(e.bind,o.flowProps,o.masterProps)})}),r={type:"return-binds-resolve",id:this.getSelectionUID(e),binds:i};this.sendMessage(r)}}},{key:"processBind",value:function(e,t,n){var o=e;try{if("PROP"===e.type){if(void 0!==(o=k()({flowProps:t,masterProps:n},e.value))&&e.suffix)o+=e.suffix}else if("EXPRESSION"===e.type){var i="(function () {\n return ".concat(e.value,";\n })");o=window.eval(i).call({flowProps:t,masterProps:n})}else if("MODULE"===e.type){var r=s(10)(e.path).default;o=window.eval(r).call({flowProps:t,masterProps:n})}}catch(e){o={type:"__CLUTCH_ERROR__",message:e.message}}return o}},{key:"registerComponent",value:function(e,t,n,o,i){var r=this.findComponentIndexBySelection(e),s=new E(this,e,t,n,o,i);if(-1!==r)this.registeredComponents.splice(r,1),s.prevUnregistered=!0;this.registeredComponents.unshift(s),this.sendMessage({type:"registerComponent",selection:e})}},{key:"unregisterComponent",value:function(e){var t=this.findComponentIndexBySelection(e);if(-1!==t){var n=this.registeredComponents[t];if(!n.prevUnregistered)this.registeredComponents.splice(t,1);else delete n.prevUnregistered}this.sendMessage({type:"unregisterComponent",selection:e})}},{key:"findComponentIndexBySelection",value:function(t){return v()(this.registeredComponents,function(e){return e.matchesSelection(t)})}},{key:"findComponentBySelection",value:function(t){return m()(this.registeredComponents,function(e){return e.matchesSelection(t)})}},{key:"findComponentsBySelection",value:function(t,e){var n=1<arguments.length&&void 0!==e?e:!1;return this.registeredComponents.filter(function(e){return e.matchesSelection(t,n)})}},{key:"changeComponentProp",value:function(e,t,n){this.sendMessage({type:"changeComponentProp",selection:e,propName:t,value:n})}},{key:"overComponent",value:function(e){this.sendMessage({type:"overComponent",selection:e})}},{key:"outComponent",value:function(e){this.sendMessage({type:"outComponent",selection:e})}},{key:"selectComponent",value:function(e){this.sendMessage({type:"selectComponent",selection:e})}},{key:"unlockComponent",value:function(e){this.sendMessage({type:"unlockComponent",selection:e})}},{key:"registerComponentReference",value:function(e,t){var n=this.findComponentBySelection(e);if(n&&null!==t)n.setReference(t)}},{key:"registerComponentChildReference",value:function(e,t,n){var o=this.findComponentBySelection(e);if(o)o.setChildReference(t,n)}},{key:"openComponentContextMenu",value:function(e,t){this.sendMessage({type:"openComponentContextMenu",selection:e,eventX:t.clientX,eventY:t.clientY})}},{key:"setHistory",value:function(e){var t=e.history;if(this.history=Object.assign(this.history,t),this.canvasId)this.unlistenHistory=t.listen(this.persistHistory)}},{key:"updateComponentOutboundProps",value:function(e,t,n){this.sendMessage({type:"updateComponentOutboundProps",selection:e,area:t,outboundProps:n})}},{key:"updateComponentInboundProps",value:function(e,t){this.sendMessage({type:"updateComponentInboundProps",selection:e,inboundProps:t})}},{key:"updateComponentMasterProps",value:function(e,t){var n=this.findComponentBySelection(e);if(n)n.updateMasterProps(t)}},{key:"updateComponentState",value:function(e,t){this.sendMessage({type:"updateComponentState",selection:e,state:t})}},{key:"updateComponentRect",value:function(e,t){this.sendMessage({type:"updateComponentRect",selection:e,rect:t})}},{key:"setComponentState",value:function(e,t){var n=this.findComponentBySelection(e);if(n)n.setComponentState(t)}},{key:"setCanvasError",value:function(e){if(this.sendMessage({type:"setCanvasError",err:e}),e)console.error(e)}}]),e}();t.default=new T}]);
{
"name": "@clutch-creator/bridge",
"version": "0.0.2",
"version": "0.0.3",
"description": "Clutch Bridge",

@@ -5,0 +5,0 @@ "main": "index.js",

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