@chief-editor/editor
Version:
FlowEditor Editor
1 lines • 2.03 kB
JavaScript
;var __assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var r,t=1,i=arguments.length;t<i;t++)for(var n in r=arguments[t])Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n]);return e}).apply(this,arguments)},__rest=this&&this.__rest||function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)r.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(t[i[n]]=e[i[n]])}return t},__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)Object.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r.default=e,r};Object.defineProperty(exports,"__esModule",{value:!0});var react_1=__importStar(require("react")),runtime_1=require("@chief-editor/runtime"),use_1=require("@rc-hooks/use"),useEditorCls_1=require("../hooks/useEditorCls"),useTemplate_1=require("../hooks/useTemplate"),BrickContainer_1=require("./BrickContainer");exports.BrickRender=react_1.memo((function(e){var r=e.brickId,t=e.brickType,i=e.node,n=runtime_1.useRuntime(),o=n.Bricks,a=n.BrickContainers,s=void 0===a?{}:a,c=n.BrickContainerRender,u=useTemplate_1.useTemplate(),l=u.getBrickByNode(i),_=runtime_1.useBrickInstance(l),f=_.layout,d=__rest(_,["layout"]),p=function(){return l.isActiveBrick()},h=use_1.useShallowState(p),k=h[0],y=h[1];react_1.useEffect((function(){var e=function(){y(p)};return u.addListener("active-brick-change",e),function(){u.removeListener("active-brick-change",e)}}),[]);var m=useEditorCls_1.useEditorCls("brick-container",{active:k}),v=o[t];if(!v)return console.warn("Brick: "+t+" is not found"),null;var b=s[t]||c||BrickContainer_1.BrickContainer;return react_1.default.createElement(b,{brickId:r,className:m,style:f,node:i,key:"container-"+l.id},react_1.default.createElement(v,__assign({key:l.id},d,{layout:{width:f.width,height:f.height}})))}));