@shift-studio/bridge
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,1 +0,1 @@ | ||
module.exports=function(n){var i={};function o(e){if(i[e])return i[e].exports;var t=i[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}return o.m=n,o.c=i,o.d=function(e,t,n){if(!o.o(e,t))Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){if("undefined"!=typeof Symbol&&Symbol.toStringTag)Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e)t=o(t);if(8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)o.d(n,i,function(e){return t[e]}.bind(null,i));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.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),i=s(3),u=s.n(i),o=s(4),a=s.n(o),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),S=s.n(O),k=Object.prototype.hasOwnProperty;function w(e,t,n){if(e===t)return!0;if(e&&!t||t&&!e)return!1;var i=0,o=0;for(var r in e){if(k.call(e,r)&&(n?!n(e[r],t[r]):e[r]!==t[r]))return!1;i+=1}for(var s in t)if(k.call(t,s))o+=1;return i===o}function P(e){var t=e||{},n=t.id,i=t.keys,o=t.rootInstances,r="".concat(n);if(i&&i.length)r+=".".concat(i.map(function(e){return e.key}).join("."));if(o&&o.length)r+=".".concat(o.join("."));return r}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||[],i=t||[];if(n.length!==i.length)return!1;else return w(n,i)}(e.rootInstances,t.rootInstances)&&(n||function(e,t){if(e===t||!e&&!t)return!0;var n=e||[],i=t||[];if(n.length!==i.length)return!1;else return n.map(function(e){return e.key}).join()===i.map(function(e){return e.key}).join()}(e.keys,t.keys))}function E(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);if(e)i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable});n.push.apply(n,i)}return n}var M=function(){function c(e,t,n,i,o,r){var s=this;u()(this,c),f()(this,"onMouseOver",function(e){if(s.shiftBridge.editing)e.stopPropagation(),s.shiftBridge.overComponent(s.selection)}),f()(this,"onMouseOut",function(){if(s.shiftBridge.editing)s.shiftBridge.outComponent(s.selection)}),f()(this,"onContextMenu",function(e){if(s.shiftBridge.editing)e.stopPropagation(),e.preventDefault(),s.shiftBridge.openComponentContextMenu(s.selection,e)}),f()(this,"onClick",function(e){if(s.shiftBridge.editing)e.stopPropagation(),e.preventDefault(),s.shiftBridge.selectComponent(s.selection)}),f()(this,"onDoubleClick",function(){if(s.shiftBridge.editing)s.shiftBridge.unlockComponent(s.selection)}),this.selection=t,this.shiftBridge=e,this.updateComponent=o,this.setState=r,this.reference=void 0,this.childReferences=[],this.masterProps=i,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.shiftBridge.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=P(e),i=m()(this.childReferences,function(e){return e.id===n});if(i)i.reference=t;else this.childReferences.push({id:n,reference:t});if(this.parentSelection)this.shiftBridge.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 i=this,o={};if(this.reference)o=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};if(e%2)E(n,!0).forEach(function(e){f()(t,e,n[e])});else if(Object.getOwnPropertyDescriptors)Object.defineProperties(t,Object.getOwnPropertyDescriptors(n));else E(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=i.getElementRect(e.reference);if(0===t)o=n;else o.top=Math.min(n.top,o.top),o.bottom=Math.max(n.bottom,o.bottom),o.left=Math.min(n.left,o.left),o.right=Math.max(n.right,o.right),o.width=o.right-o.left,o.height=o.bottom-o.top})}if(!w(this.calculatedRect,o))this.calculatedRect=o,this.shiftBridge.updateComponentRect(this.selection,o)}},{key:"updateOutboundProps",value:function(e,t){this.outboundProps=this.outboundProps||{},this.outboundProps[e]=t}},{key:"updateInboundProps",value:function(e){this.inboundProps=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 i=Object.getOwnPropertySymbols(t);if(e)i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable});n.push.apply(n,i)}return n}s.d(t,"classnames",function(){return R}),s.d(t,"getUniqueClassName",function(){return x}),s.d(t,"mergeProperty",function(){return I}),s.d(t,"mergeVariants",function(){return _}),s.d(t,"mergeProperties",function(){return D}),s.d(t,"mergeOverrides",function(){return L}),s.d(t,"getOverrides",function(){return A}),s.d(t,"getShiftProps",function(){return q}),s.d(t,"hasVariant",function(){return N}),s.d(t,"propertyBind",function(){return T});var R=C.a;function x(e,t){var n;if("undefined"!=typeof window&&window.SHIFT_CLASSES_MAP){var i=P(e);if(void 0===window.SHIFT_CLASSES_MAP["".concat(i).concat(t)])n="-shift-identifier".concat(Object.keys(window.SHIFT_CLASSES_MAP).length),window.SHIFT_CLASSES_MAP["".concat(i).concat(t)]=n}return n}function I(e){for(var t=e,n=arguments.length,i=new Array(1<n?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];return i.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,i=new Array(1<t?t-1:0),o=1;o<t;o++)i[o-1]=arguments[o];if(i&&i.length)i.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 D(e){for(var r=Object.assign({},e),t=arguments.length,n=new Array(1<t?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];if(n&&n.length)n.forEach(function(o){if(o&&"object"===p()(o))Object.keys(o).forEach(function(e){var t=r[e],n=o[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("shiftProps"===e)if(t&&n&&n.overrides){var i=t.overrides||{};Object.keys(n.overrides).forEach(function(e){i[e]=D(i[e],n.overrides[e])}),r[e]=Object.assign({},t,n,{overrides:i})}else r[e]=Object.assign({},t,n);else r[e]=I(t,n)})});return r}function L(e){for(var n=Object.assign({},e),t=arguments.length,i=new Array(1<t?t-1:0),o=1;o<t;o++)i[o-1]=arguments[o];return Object.keys(i).forEach(function(t){if(t)Object.keys(t).forEach(function(e){n[e]=D(n[e],t[e])})}),n}function A(e){var t,n=S()(e,["shiftProps","selection"]),i=S()(e,["shiftProps","overrides"]);if(n&&i){var o=n.rootInstances||[];t=i["".concat(o.join("."),".").concat(n.id)]}return t}function q(e,t,n,i,o,r){var s=S()(t,["shiftProps","selection"],{}),c=o.keys||[];if(void 0!==i)c=[].concat(h()(c),[{componentId:o.id,key:i}]);var u=s.rootInstances||[];if(!s.rootInstances)u=[];else u=[].concat(h()(u),[s.id]);var a=S()(t,["shiftProps","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]=D(r[e],a[t]);else a[t]=r[e]})}return{selection:{id:e,rootInstances:u,keys:c},parentSelection:o,masterProps:t,flowProps:n,overrides:a}}function N(e,t){return e&&Array.isArray(e)&&e.includes(t)?!0:void 0}function T(e,t){var n;try{if(void 0!==(n=S()(this,e))&&t)n+=t}catch(e){}return n}var U=function(){function e(){var o=this;if(u()(this,e),f()(this,"shallowEqual",w),f()(this,"getSelectionUID",P),f()(this,"onReceivedMessage",function(e){if("string"==typeof e.data){var t=JSON.parse(e.data),n=t.type,i=r()(t,["type"]);switch(n){case"setComponentState":o.setComponentState(i.selection,i.state);break;case"setEditing":o.setEditing(i.editing);break;case"request-binds-resolve":o.resolveBinds(i.selection,i.binds)}}}),f()(this,"setEditing",function(e){o.editing=e}),f()(this,"checkComponentsRects",function(){if("undefined"!=typeof window)o.registeredComponents.forEach(function(e){return e.updateRect()}),window.requestAnimationFrame(o.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,function(){var n=new WeakSet;return function(e,t){if("object"===p()(t)&&null!==t){if(n.has(t))return;n.add(t)}else if("function"==typeof t)return t.toString();return t}}());if(window.opener)window.opener.postMessage(t,"*");else window.parent.postMessage(t,"*")}}},{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=S()(this,e))&&t)n+=t}catch(e){}return n}},{key:"resolveBinds",value:function(e,t){var n=this,i=this.findComponentBySelection(e);if(i){var o=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(n,!0).forEach(function(e){f()(t,e,n[e])});else if(Object.getOwnPropertyDescriptors)Object.defineProperties(t,Object.getOwnPropertyDescriptors(n));else B(n).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({},e,{bind:n.processBind(e.bind,i.flowProps,i.masterProps)})}),r={type:"return-binds-resolve",id:this.getSelectionUID(e),binds:o};this.sendMessage(r)}}},{key:"processBind",value:function(e,t,n){var i=e;try{if("PROP"===e.type){if(void 0!==(i=S()({flowProps:t,masterProps:n},e.value))&&e.suffix)i+=e.suffix}else if("EXPRESSION"===e.type){var o="(function () {\n return ".concat(e.value,";\n })");i=window.eval(o).call({flowProps:t,masterProps:n})}else if("MODULE"===e.type){var r=s(10)(e.path).default;i=window.eval(r).call({flowProps:t,masterProps:n})}}catch(e){i={type:"__SHIFT_ERROR__",message:e.message}}return i}},{key:"registerComponent",value:function(e,t,n,i,o){var r=this.findComponentIndexBySelection(e),s=new M(this,e,t,n,i,o);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 i=this.findComponentBySelection(e);if(i)i.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:"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 U}]); | ||
module.exports=function(n){var i={};function o(e){if(i[e])return i[e].exports;var t=i[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}return o.m=n,o.c=i,o.d=function(e,t,n){if(!o.o(e,t))Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){if("undefined"!=typeof Symbol&&Symbol.toStringTag)Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e)t=o(t);if(8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)o.d(n,i,function(e){return t[e]}.bind(null,i));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.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),i=s(3),u=s.n(i),o=s(4),a=s.n(o),c=s(0),f=s.n(c),l=s(6),d=s.n(l),p=s(2),h=s.n(p),g=s(9),v=s.n(g),y=s(5),m=s.n(y),b=s(7),C=s.n(b),S=s(1),O=s.n(S),k=Object.prototype.hasOwnProperty;function w(e,t,n){if(e===t)return!0;if(e&&!t||t&&!e)return!1;var i=0,o=0;for(var r in e){if(k.call(e,r)&&(n?!n(e[r],t[r]):e[r]!==t[r]))return!1;i+=1}for(var s in t)if(k.call(t,s))o+=1;return i===o}function P(e){var t=e||{},n=t.id,i=t.keys,o=t.rootInstances,r="".concat(n);if(i&&i.length)r+=".".concat(i.map(function(e){return e.key}).join("."));if(o&&o.length)r+=".".concat(o.join("."));return r}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||[],i=t||[];if(n.length!==i.length)return!1;else return w(n,i)}(e.rootInstances,t.rootInstances)&&(n||function(e,t){if(e===t||!e&&!t)return!0;var n=e||[],i=t||[];if(n.length!==i.length)return!1;else return n.map(function(e){return e.key}).join()===i.map(function(e){return e.key}).join()}(e.keys,t.keys))}function E(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);if(e)i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable});n.push.apply(n,i)}return n}var M=function(){function c(e,t,n,i,o,r){var s=this;u()(this,c),f()(this,"onMouseOver",function(e){if(s.shiftBridge.editing)e.stopPropagation(),s.shiftBridge.overComponent(s.selection)}),f()(this,"onMouseOut",function(){if(s.shiftBridge.editing)s.shiftBridge.outComponent(s.selection)}),f()(this,"onContextMenu",function(e){if(s.shiftBridge.editing)e.stopPropagation(),e.preventDefault(),s.shiftBridge.openComponentContextMenu(s.selection,e)}),f()(this,"onClick",function(e){if(s.shiftBridge.editing)e.stopPropagation(),e.preventDefault(),s.shiftBridge.selectComponent(s.selection)}),f()(this,"onDoubleClick",function(){if(s.shiftBridge.editing)s.shiftBridge.unlockComponent(s.selection)}),this.selection=t,this.shiftBridge=e,this.updateComponent=o,this.setState=r,this.reference=void 0,this.childReferences=[],this.masterProps=i,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.shiftBridge.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=P(e),i=m()(this.childReferences,function(e){return e.id===n});if(i)i.reference=t;else this.childReferences.push({id:n,reference:t});if(this.parentSelection)this.shiftBridge.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 i=this,o={};if(this.reference)o=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};if(e%2)E(n,!0).forEach(function(e){f()(t,e,n[e])});else if(Object.getOwnPropertyDescriptors)Object.defineProperties(t,Object.getOwnPropertyDescriptors(n));else E(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=i.getElementRect(e.reference);if(0===t)o=n;else o.top=Math.min(n.top,o.top),o.bottom=Math.max(n.bottom,o.bottom),o.left=Math.min(n.left,o.left),o.right=Math.max(n.right,o.right),o.width=o.right-o.left,o.height=o.bottom-o.top})}if(!w(this.calculatedRect,o))this.calculatedRect=o,this.shiftBridge.updateComponentRect(this.selection,o)}},{key:"updateOutboundProps",value:function(e,t){this.outboundProps=this.outboundProps||{},this.outboundProps[e]=t}},{key:"updateInboundProps",value:function(e){this.inboundProps=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 i=Object.getOwnPropertySymbols(t);if(e)i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable});n.push.apply(n,i)}return n}s.d(t,"classnames",function(){return R}),s.d(t,"getUniqueClassName",function(){return x}),s.d(t,"mergeProperty",function(){return I}),s.d(t,"mergeVariants",function(){return _}),s.d(t,"mergeProperties",function(){return A}),s.d(t,"mergeOverrides",function(){return L}),s.d(t,"getOverrides",function(){return D}),s.d(t,"getShiftProps",function(){return q}),s.d(t,"hasVariant",function(){return N}),s.d(t,"propertyBind",function(){return T});var R=C.a;function x(e,t){var n;if("undefined"!=typeof window&&window.SHIFT_CLASSES_MAP){var i=P(e);if(void 0===window.SHIFT_CLASSES_MAP["".concat(i).concat(t)])n="-shift-identifier".concat(Object.keys(window.SHIFT_CLASSES_MAP).length),window.SHIFT_CLASSES_MAP["".concat(i).concat(t)]=n;else n=window.SHIFT_CLASSES_MAP["".concat(i).concat(t)]}return n}function I(e){for(var t=e,n=arguments.length,i=new Array(1<n?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];return i.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,i=new Array(1<t?t-1:0),o=1;o<t;o++)i[o-1]=arguments[o];if(i&&i.length)i.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 A(e){for(var r=Object.assign({},e),t=arguments.length,n=new Array(1<t?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];if(n&&n.length)n.forEach(function(o){if(o&&"object"===d()(o))Object.keys(o).forEach(function(e){var t=r[e],n=o[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("shiftProps"===e)if(t&&n&&n.overrides){var i=t.overrides||{};Object.keys(n.overrides).forEach(function(e){i[e]=A(i[e],n.overrides[e])}),r[e]=Object.assign({},t,n,{overrides:i})}else r[e]=Object.assign({},t,n);else r[e]=I(t,n)})});return r}function L(e){for(var n=Object.assign({},e),t=arguments.length,i=new Array(1<t?t-1:0),o=1;o<t;o++)i[o-1]=arguments[o];return Object.keys(i).forEach(function(t){if(t)Object.keys(t).forEach(function(e){n[e]=A(n[e],t[e])})}),n}function D(e){var t,n=O()(e,["shiftProps","selection"]),i=O()(e,["shiftProps","overrides"]);if(n&&i){var o=n.rootInstances||[];t=i["".concat(o.join("."),".").concat(n.id)]}return t}function q(e,t,n,i,o,r){var s=O()(t,["shiftProps","selection"],{}),c=o.keys||[];if(void 0!==i)c=[].concat(h()(c),[{componentId:o.id,key:i}]);var u=s.rootInstances||[];if(!s.rootInstances)u=[];else u=[].concat(h()(u),[s.id]);var a=O()(t,["shiftProps","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]=A(r[e],a[t]);else a[t]=r[e]})}return{selection:{id:e,rootInstances:u,keys:c},parentSelection:o,masterProps:t,flowProps:n,overrides:a}}function N(e,t){return e&&Array.isArray(e)&&e.includes(t)?!0:void 0}function T(e,t){var n;try{if(void 0!==(n=O()(this,e))&&t)n+=t}catch(e){}return n}var F=function(){function e(){var o=this;if(u()(this,e),f()(this,"shallowEqual",w),f()(this,"getSelectionUID",P),f()(this,"onReceivedMessage",function(e){if("string"==typeof e.data){var t=JSON.parse(e.data),n=t.type,i=r()(t,["type"]);switch(n){case"setComponentState":o.setComponentState(i.selection,i.state);break;case"setEditing":o.setEditing(i.editing);break;case"request-binds-resolve":o.resolveBinds(i.selection,i.binds)}}}),f()(this,"setEditing",function(e){o.editing=e}),f()(this,"checkComponentsRects",function(){if("undefined"!=typeof window)o.registeredComponents.forEach(function(e){return e.updateRect()}),window.requestAnimationFrame(o.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,function(){var n=new WeakSet;return function(e,t){if("object"===d()(t)&&null!==t){if(n.has(t))return;n.add(t)}else if("function"==typeof t)return t.toString();return t}}());if(window.opener)window.opener.postMessage(t,"*");else window.parent.postMessage(t,"*")}}},{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=O()(this,e))&&t)n+=t}catch(e){}return n}},{key:"resolveBinds",value:function(e,t){var n=this,i=this.findComponentBySelection(e);if(i){var o=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(n,!0).forEach(function(e){f()(t,e,n[e])});else if(Object.getOwnPropertyDescriptors)Object.defineProperties(t,Object.getOwnPropertyDescriptors(n));else B(n).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({},e,{bind:n.processBind(e.bind,i.flowProps,i.masterProps)})}),r={type:"return-binds-resolve",id:this.getSelectionUID(e),binds:o};this.sendMessage(r)}}},{key:"processBind",value:function(e,t,n){var i=e;try{if("PROP"===e.type){if(void 0!==(i=O()({flowProps:t,masterProps:n},e.value))&&e.suffix)i+=e.suffix}else if("EXPRESSION"===e.type){var o="(function () {\n return ".concat(e.value,";\n })");i=window.eval(o).call({flowProps:t,masterProps:n})}else if("MODULE"===e.type){var r=s(10)(e.path).default;i=window.eval(r).call({flowProps:t,masterProps:n})}}catch(e){i={type:"__SHIFT_ERROR__",message:e.message}}return i}},{key:"registerComponent",value:function(e,t,n,i,o){var r=this.findComponentIndexBySelection(e),s=new M(this,e,t,n,i,o);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 i=this.findComponentBySelection(e);if(i)i.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:"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 F}]); |
{ | ||
"name": "@shift-studio/bridge", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Shift Bridge", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17531
2