@chamn/render 0.0.40 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonComponent/index.d.ts +1 -12
- package/dist/core/adapterReact.d.ts +2 -2
- package/dist/core/designReactRender.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -16
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/util/assetsLoader.d.ts +4 -1
- package/dist/util/index.d.ts +3 -3
- package/package.json +6 -6
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const InnerComponent: {
|
|
3
|
-
CContainer: ({ children, $$attributes, afterMount, beforeDestroy, ...props }: any) => JSX.Element;
|
|
4
|
-
CVideo: ({ children, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
5
|
-
CAudio: ({ children, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
6
|
-
CBlock: ({ children, width, height, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
7
|
-
CImage: ({ children, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
8
|
-
CText: ({ $$attributes, content, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
9
|
-
CCanvas: ({ afterMount, beforeDestroy, $$attributes, ...props }: any) => React.DetailedReactHTMLElement<any, HTMLElement>;
|
|
10
|
-
CNativeTag: ({ children, $$attributes, htmlTag, ...props }: any) => React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
|
11
|
-
RootContainer: ({ children }: any) => any;
|
|
12
|
-
};
|
|
1
|
+
export declare const InnerComponent: any;
|
|
@@ -34,8 +34,8 @@ export declare class DefineReactAdapter {
|
|
|
34
34
|
}): {
|
|
35
35
|
_CONDITION: boolean;
|
|
36
36
|
_DESIGN_BOX: boolean;
|
|
37
|
-
_NODE_MODEL:
|
|
38
|
-
_NODE_ID:
|
|
37
|
+
_NODE_MODEL: any;
|
|
38
|
+
_NODE_ID: any;
|
|
39
39
|
UNIQUE_ID: string;
|
|
40
40
|
targetComponentRef: React.MutableRefObject<any>;
|
|
41
41
|
listenerHandle: (() => void)[];
|
|
@@ -30,7 +30,7 @@ export declare class DesignRender extends React.Component<DesignRenderProp> {
|
|
|
30
30
|
constructor(props: DesignRenderProp);
|
|
31
31
|
updateComponents(newComponents?: Record<string, string>): void;
|
|
32
32
|
componentDidMount(): void;
|
|
33
|
-
getPageModel():
|
|
33
|
+
getPageModel(): any;
|
|
34
34
|
onGetComponent: (comp: any, node: CNode | CRootNode) => React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<unknown>>;
|
|
35
35
|
rerender(newPage?: CPageDataType | CPage): void | undefined;
|
|
36
36
|
getInstancesById(id: string, uniqueId?: string): RenderInstance[];
|
package/dist/index.js
CHANGED
|
@@ -25,5 +25,5 @@ return $$_run_$$();
|
|
|
25
25
|
*
|
|
26
26
|
* This source code is licensed under the MIT license found in the
|
|
27
27
|
* LICENSE file in the root directory of this source tree.
|
|
28
|
-
*/var Rm=S,Dm=Symbol.for("react.element"),Im=Symbol.for("react.fragment"),Lm=Object.prototype.hasOwnProperty,Bm=Rm.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Fm={key:!0,ref:!0,__self:!0,__source:!0};function ia(t,e,r){var n,o={},a=null,i=null;r!==void 0&&(a=""+r),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(i=e.ref);for(n in e)Lm.call(e,n)&&!Fm.hasOwnProperty(n)&&(o[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)o[n]===void 0&&(o[n]=e[n]);return{$$typeof:Dm,type:t,key:a,ref:i,props:o,_owner:Bm.current}}Ee.Fragment=Im;Ee.jsx=ia;Ee.jsxs=ia;sa.exports=Ee;var Um=sa.exports;const km=Um.jsx,nt=t=>{const e={};return t.forEach(r=>{e[r.key]=r.value}),e},Vm=[...Mm,...Ef],zm=Vm.reduce((t,e)=>(t[e]=({children:r,$$attributes:n=[],...o})=>{let a=r;return Array.isArray(r)||(a=[r]),S.createElement(e,{...o,...nt(n)},...a)},t),{}),Gm=({children:t,width:e,height:r,$$attributes:n=[],...o})=>{let a=t;Array.isArray(t)||(a=[t]),a=a.filter(u=>u!==void 0);const{style:i={},...s}=nt(n),c={height:r,width:e,...i,...o.style||{}};return S.createElement("div",{...o,...s,style:c},...a)},Hm=({afterMount:t,beforeDestroy:e,$$attributes:r=[],...n})=>(S.useEffect(()=>(t==null||t(n),()=>{e==null||e(n)}),[]),S.createElement("canvas",{...n,...nt(r)})),Wm=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("img",{...r,...nt(e)},...n)},Jm=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("video",{...r,...nt(e)},...n)},Qm=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("audio",{...r,...nt(e)},...n)},qm=({$$attributes:t=[],content:e,...r})=>S.createElement("span",{...r,...nt(t)},e),Ym=({children:t,$$attributes:e=[],afterMount:r,beforeDestroy:n,...o})=>{let a=t;return Array.isArray(t)||(a=[t]),S.useEffect(()=>(r==null||r(o),()=>{n==null||n(o)}),[]),km("div",{...o,...nt(e),children:a})},Km=({children:t,$$attributes:e=[],htmlTag:r="div",...n})=>{let o=t;Array.isArray(t)||(o=[t]);const{style:a={},...i}=nt(e),s={...a,...n.style||{}};return S.createElement(r,{...n,...i,style:s},...o)},Xm={RootContainer:({children:t})=>t,...zm,CContainer:Ym,CVideo:Jm,CAudio:Qm,CBlock:Gm,CImage:Wm,CText:qm,CCanvas:Hm,CNativeTag:Km};class Zm{constructor(){y(this,"refMap",new Map)}get(e){return this.refMap.get(e)}add(e,r){this.refMap.set(e,r)}remove(e){this.refMap.delete(e)}destroy(){this.refMap.clear()}}class ca extends S.Component{constructor(r){super(r);y(this,"refManager");y(this,"dynamicComponentInstanceMap",new Map);y(this,"onGetRef",(r,n,o)=>{var a,i;(i=(a=this.props).onGetRef)==null||i.call(a,r,n,o),this.dynamicComponentInstanceMap.set(n.id,o),this.refManager.add(n.value.refId||n.id,r)});y(this,"rerender",r=>{if(this.props.adapter.clear(),(r==null?void 0:r.nodeType)==="PAGE"&&r)this.setState({pageModel:r});else if($t(r)&&wo(r)){const n=r;this.setState({pageModel:new he(n,{materials:this.state.pageModel.materialsModel.rawValue})})}});this.state={pageModel:r.pageModel||new he(r.page)},this.refManager=new Zm}getPageModel(){return this.state.pageModel}componentDidMount(){const{render:r}=this.props;r&&(r.ref.current=this)}componentWillUnmount(){this.refManager.destroy()}render(){const{props:r}=this,{adapter:n,onGetComponent:o,onComponentDestroy:a,onComponentMount:i}=r,{pageModel:s}=this.state;if(!s)return console.warn("pageModel is null"),null;const c={...Xm,...r.components},u=this.props.$$context??{};return u.refs=this.refManager,n.pageRender(s,{libs:{},components:c,onGetRef:this.onGetRef,onGetComponent:o,onComponentMount:i,onComponentDestroy:a,$$context:u,renderMode:r.renderMode,processNodeConfigHook:r.processNodeConfigHook})}}const tv=()=>{const t=S.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)}}};class ev extends S.Component{constructor(r){super(r);y(this,"onDoubleClick",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:""}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){var o,a;(a=(o=this.props).onError)==null||a.call(o,n)}render(){if(this.state.hasError){const{onDoubleClick:r}=this,n=this.props.node.value;console.error(this.props.node,this.props.children);const o=S.createElement("div",{style:{backgroundColor:"rgb(255 206 215 / 13%)",padding:"5px",color:"#ff0000b0",textAlign:"center",fontSize:"12px"}},"Render error, node id: ",n.id,", node name:",n.title," component name:",n.title||n.componentName,S.createElement("p",null,"msg: ",String(this.state.error)),S.createElement("button",{onDoubleClick:r,style:{border:"1px solid rgba(100,100,100,0.1)",backgroundColor:"#fff",padding:"5px 10px",borderRadius:"2px",color:"gray",cursor:"pointer",marginTop:"5px"}},"double click to refresh"),S.createElement("div",{style:{display:"none"}}));return S.createElement(this.props.targetComponent,{onlyRenderChild:!0},o)}return this.props.children}}class ua{constructor(){y(this,"instanceMap",new Map)}get(e){return this.instanceMap.get(e)}add(e,r){const n=this.instanceMap.get(e);n?n.push(r):this.instanceMap.set(e,[r])}remove(e,r){const n=this.instanceMap.get(e);if(r!==void 0&&Array.isArray(n)){const o=n.filter(a=>a!==r);this.instanceMap.set(e,o)}else this.instanceMap.delete(e)}destroy(){this.instanceMap.clear()}}const la=t=>{const{node:e}=t,r=S.useMemo(()=>{const s=e.isContainer();return $t(s)?s:{placeholder:"Drag the component to place it",width:"100%",height:"100%",style:{}}},[t.node]),{placeholder:n,height:o,width:a,style:i}=r;return S.createElement("div",{style:{margin:0,padding:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(200,200,200,0.1)",border:"1px solid rgba(0,0,0,0.1)",borderRadius:"2px",fontSize:"14px",color:"gray",cursor:"default",width:a,height:o,...i}},n)};class rv extends S.Component{constructor(r){super(r);y(this,"instanceManager",new ua);y(this,"renderRef");y(this,"dropPlaceholder",la);y(this,"_components",{});y(this,"onGetComponent",(r,n)=>{var c,u;const o=this;let a=r;const i=(u=(c=n.material)==null?void 0:c.value.advanceCustom)==null?void 0:u.wrapComponent;i&&(a=i(r,{node:n,ctx:window.__C_ENGINE_DESIGNER_PLUGIN_CTX__}));class s extends S.Component{constructor(){super(...arguments);y(this,"_DESIGN_BOX",!0);y(this,"_NODE_MODEL",n);y(this,"_NODE_ID",n.id);y(this,"_UNIQUE_ID",`${n.id}_${Z()}`);y(this,"_STATUS")}componentDidMount(){o.instanceManager.add(n.id,this)}componentWillUnmount(){this._STATUS="DESTROY",o.instanceManager.remove(n.id,this)}render(){var j,O;const{children:f=[],onlyRenderChild:d,...h}=this.props;let g=f;if(Et(f)||(g=[f]),!!!g.filter(Boolean).length&&(n.isContainer()||n.value.componentName===At.ROOT_CONTAINER)){const T=(O=(j=n.material)==null?void 0:j.value.advanceCustom)==null?void 0:O.dropPlaceholder;g.push(S.createElement(T||o.dropPlaceholder,{node:n}))}return d?g:S.createElement(a,h,...g)}}return S.forwardRef(function(p,f){return S.createElement(ev,{node:n,targetComponent:s},S.createElement(s,{ref:f,...p}))})});this.updateComponents(this.props.components),this.renderRef=S.createRef(),r.dropPlaceholder&&(this.dropPlaceholder=r.dropPlaceholder)}updateComponents(r={}){this._components=Object.assign(this._components,r),this.forceUpdate()}componentDidMount(){var r,n;this.updateComponents(this.props.components),(n=(r=this.props).onMount)==null||n.call(r,this)}getPageModel(){var r;return(r=this.renderRef.current)==null?void 0:r.state.pageModel}rerender(r){var n;return(n=this.renderRef.current)==null?void 0:n.rerender(r)}getInstancesById(r,n){let o=[...this.instanceManager.get(r)||[]];return n!==void 0&&(o=o.filter(a=>n===(a==null?void 0:a._UNIQUE_ID))),o}getInstanceByDom(r){const n=fa(r);if(!n)return null;const o=pa(n);return(o==null?void 0:o.stateNode)||null}getDomsById(r,n){const o=this.getInstancesById(r),a=[];return o==null||o.forEach(i=>{var c;if((i==null?void 0:i._STATUS)==="DESTROY")return;const s=Sa.findDOMNode(i);if(s&&!(s instanceof Text))if(n){const u=Array.from(((c=s.querySelectorAll)==null?void 0:c.call(s,n))||[]);a.push(...u)}else a.push(s)}),a}getDomRectById(r,n){return this.getDomsById(r,n).map(i=>i==null?void 0:i.getBoundingClientRect()).filter(Boolean)}render(){const{props:r,onGetComponent:n}=this,{render:o,...a}=r;return o&&(o.ref.current=this),S.createElement(ca,{onGetComponent:n,...a,components:this._components,processNodeConfigHook:(i,s)=>{var h,g;if(s.nodeType!=="NODE")return i;const{props:c,condition:u}=i;let l={...c};const p=((h=s.value.configure)==null?void 0:h.devState)||{},f=(g=s.material)==null?void 0:g.value.fixedProps;if(f!==void 0){if($t(f))l={...l,...f};else if(typeof f=="function"){const b=f(l);l={...l,...b}}}let d=u;return p.condition===!1&&(d=p.condition),{props:bm(l,p.props||{}),condition:d}},ref:this.renderRef})}}const fa=t=>{if(!t)return null;const e=Object.keys(t).find(r=>r.startsWith("__reactInternalInstance$")||r.startsWith("__reactFiber$"))||"";return e?t[e]:fa(t.parentElement)},pa=t=>{var e;return t?(e=t==null?void 0:t.stateNode)!=null&&e._DESIGN_BOX?t:pa(t.return):null},nv=()=>{const t=S.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)},getInstancesById(e,r){var n;return((n=t.current)==null?void 0:n.getInstancesById(e,r))||[]},getInstanceByDom(e){var r;return((r=t.current)==null?void 0:r.getInstanceByDom(e))||null},getDomsById(e,r){var n;return((n=t.current)==null?void 0:n.getDomsById(e,r))||[]},getDomRectById(e,r){var n;return((n=t.current)==null?void 0:n.getDomRectById(e,r))||[]}}};var da={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(Am,function(){var r=function(){},n={},o={},a={};function i(f,d){f=f.push?f:[f];var h=[],g=f.length,b=g,j,O,T,A;for(j=function(I,k){k.length&&h.push(I),b--,b||d(h)};g--;){if(O=f[g],T=o[O],T){j(O,T);continue}A=a[O]=a[O]||[],A.push(j)}}function s(f,d){if(f){var h=a[f];if(o[f]=d,!!h)for(;h.length;)h[0](f,d),h.splice(0,1)}}function c(f,d){f.call&&(f={success:f}),d.length?(f.error||r)(d):(f.success||r)(f)}function u(f,d,h,g){var b=document,j=h.async,O=(h.numRetries||0)+1,T=h.before||r,A=f.replace(/[\?|#].*$/,""),I=f.replace(/^(css|img|module|nomodule)!/,""),k,Lt,w;if(g=g||0,/(^css!|\.css$)/.test(A))w=b.createElement("link"),w.rel="stylesheet",w.href=I,k="hideFocus"in w,k&&w.relList&&(k=0,w.rel="preload",w.as="style");else if(/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(A))w=b.createElement("img"),w.src=I;else if(w=b.createElement("script"),w.src=I,w.async=j===void 0?!0:j,Lt="noModule"in w,/^module!/.test(A)){if(!Lt)return d(f,"l");w.type="module"}else if(/^nomodule!/.test(A)&&Lt)return d(f,"l");w.onload=w.onerror=w.onbeforeload=function(ot){var it=ot.type[0];if(k)try{w.sheet.cssText.length||(it="e")}catch(ae){ae.code!=18&&(it="e")}if(it=="e"){if(g+=1,g<O)return u(f,d,h,g)}else if(w.rel=="preload"&&w.as=="style")return w.rel="stylesheet";d(f,it,ot.defaultPrevented)},T(f,w)!==!1&&b.head.appendChild(w)}function l(f,d,h){f=f.push?f:[f];var g=f.length,b=g,j=[],O,T;for(O=function(A,I,k){if(I=="e"&&j.push(A),I=="b")if(k)j.push(A);else return;g--,g||d(j)},T=0;T<b;T++)u(f[T],O,h)}function p(f,d,h){var g,b;if(d&&d.trim&&(g=d),b=(g?h:d)||{},g){if(g in n)throw"LoadJS";n[g]=!0}function j(O,T){l(f,function(A){c(b,A),O&&c({success:O,error:T},A),s(g,A)},b)}if(b.returnPromise)return new Promise(j);j()}return p.ready=function(d,h){return i(d,function(g){c(h,g)}),p},p.done=function(d){s(d,[])},p.reset=function(){n={},o={},a={}},p.isDefined=function(d){return d in n},p})})(da);var ov=da.exports;const In=Pm(ov);class av{constructor(e,r){y(this,"assets");y(this,"loadStatus");y(this,"win",window);y(this,"_onSuccessList",[]);y(this,"_onErrorList",[]);this.assets=JSON.parse(JSON.stringify(e||[])),this.loadStatus="INIT",r!=null&&r.window&&(this.win=r.window)}load(){const e=this.assets||[],r=[];for(let n=0;n<e.length;n++){const o=e[n];o.id||(o.id=Z()),r.push(o.id);const a=o.resources.map(i=>i.src);a.length&&In(a,o.id,{async:!1,before:(i,s)=>(this.win.document.body.appendChild(s),!1)})}return new Promise((n,o)=>{if(e.length===0){this._onSuccessList.forEach(a=>a()),n("");return}In.ready(r,{success:()=>{this._onSuccessList.forEach(a=>a()),n("")},error:a=>{this._onErrorList.forEach(i=>i(a)),o(a)}})})}onSuccess(e){return this._onSuccessList.push(e),this}onError(e){return this._onErrorList.push(e),this}}exports.AssetLoader=av;exports.ComponentInstanceManager=ua;exports.DefaultDropPlaceholder=la;exports.DefineReactAdapter=aa;exports.DesignRender=rv;exports.ReactAdapter=xm;exports.Render=ca;exports.canAcceptsRef=Zo;exports.collectVariable=jm;exports.compWrapper=ta;exports.convertCodeStringToFunction=ea;exports.findComponentByChainRefer=oa;exports.flatObject=Om;exports.formatSourceStylePropertyName=nr;exports.getAdapter=Ln;exports.getCSSTextValue=Sm;exports.getComponentsLibs=Cm;exports.getMatchVal=ra;exports.getNodeCssClassName=le;exports.getObjFromArrayMap=rr;exports.getThirdLibs=wm;exports.isClass=_m;exports.runExpression=lt;exports.shouldConstruct=Xo;exports.useDesignRender=nv;exports.useRender=tv;
|
|
28
|
+
*/var Rm=S,Dm=Symbol.for("react.element"),Im=Symbol.for("react.fragment"),Lm=Object.prototype.hasOwnProperty,Bm=Rm.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Fm={key:!0,ref:!0,__self:!0,__source:!0};function ia(t,e,r){var n,o={},a=null,i=null;r!==void 0&&(a=""+r),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(i=e.ref);for(n in e)Lm.call(e,n)&&!Fm.hasOwnProperty(n)&&(o[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)o[n]===void 0&&(o[n]=e[n]);return{$$typeof:Dm,type:t,key:a,ref:i,props:o,_owner:Bm.current}}Ee.Fragment=Im;Ee.jsx=ia;Ee.jsxs=ia;sa.exports=Ee;var Um=sa.exports;const km=Um.jsx,nt=t=>{const e={};return t.forEach(r=>{e[r.key]=r.value}),e},Vm=[...Mm,...Ef],zm=Vm.reduce((t,e)=>(t[e]=({children:r,$$attributes:n=[],...o})=>{let a=r;return Array.isArray(r)||(a=[r]),S.createElement(e,{...o,...nt(n)},...a)},t),{}),Gm=({children:t,width:e,height:r,$$attributes:n=[],...o})=>{let a=t;Array.isArray(t)||(a=[t]),a=a.filter(u=>u!==void 0);const{style:i={},...s}=nt(n),c={height:r,width:e,...i,...o.style||{}};return S.createElement("div",{...o,...s,style:c},...a)},Hm=({afterMount:t,beforeDestroy:e,$$attributes:r=[],...n})=>(S.useEffect(()=>(t==null||t(n),()=>{e==null||e(n)}),[]),S.createElement("canvas",{...n,...nt(r)})),Wm=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("img",{...r,...nt(e)},...n)},Jm=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("video",{...r,...nt(e)},...n)},Qm=({children:t,$$attributes:e=[],...r})=>{let n=t;return Array.isArray(t)||(n=[t]),S.createElement("audio",{...r,...nt(e)},...n)},qm=({$$attributes:t=[],content:e,...r})=>S.createElement("span",{...r,...nt(t)},e),Ym=({children:t,$$attributes:e=[],afterMount:r,beforeDestroy:n,...o})=>{let a=t;return Array.isArray(t)||(a=[t]),S.useEffect(()=>(r==null||r(o),()=>{n==null||n(o)}),[]),km("div",{...o,...nt(e),children:a})},Km=({children:t,$$attributes:e=[],htmlTag:r="div",...n})=>{let o=t;Array.isArray(t)||(o=[t]);const{style:a={},...i}=nt(e),s={...a,...n.style||{}};return S.createElement(r,{...n,...i,style:s},...o)},Xm={RootContainer:({children:t})=>t,...zm,CContainer:Ym,CVideo:Jm,CAudio:Qm,CBlock:Gm,CImage:Wm,CText:qm,CCanvas:Hm,CNativeTag:Km};class Zm{constructor(){y(this,"refMap",new Map)}get(e){return this.refMap.get(e)}add(e,r){this.refMap.set(e,r)}remove(e){this.refMap.delete(e)}destroy(){this.refMap.clear()}}class ca extends S.Component{constructor(r){super(r);y(this,"refManager");y(this,"dynamicComponentInstanceMap",new Map);y(this,"onGetRef",(r,n,o)=>{var a,i;(i=(a=this.props).onGetRef)==null||i.call(a,r,n,o),this.dynamicComponentInstanceMap.set(n.id,o),this.refManager.add(n.value.refId||n.id,r)});y(this,"rerender",r=>{if(this.props.adapter.clear(),(r==null?void 0:r.nodeType)==="PAGE"&&r)this.setState({pageModel:r});else if($t(r)&&wo(r)){const n=r;this.setState({pageModel:new he(n,{materials:this.state.pageModel.materialsModel.rawValue})})}});this.state={pageModel:r.pageModel||new he(r.page)},this.refManager=new Zm}getPageModel(){return this.state.pageModel}componentDidMount(){const{render:r}=this.props;r&&(r.ref.current=this)}componentWillUnmount(){this.refManager.destroy()}render(){const{props:r}=this,{adapter:n,onGetComponent:o,onComponentDestroy:a,onComponentMount:i}=r,{pageModel:s}=this.state;if(!s)return console.warn("pageModel is null"),null;const c={...Xm,...r.components},u=this.props.$$context??{};return u.refs=this.refManager,n.pageRender(s,{libs:{},components:c,onGetRef:this.onGetRef,onGetComponent:o,onComponentMount:i,onComponentDestroy:a,$$context:u,renderMode:r.renderMode,processNodeConfigHook:r.processNodeConfigHook})}}const tv=()=>{const t=S.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)}}};class ev extends S.Component{constructor(r){super(r);y(this,"onDoubleClick",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:""}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){var o,a;(a=(o=this.props).onError)==null||a.call(o,n)}render(){if(this.state.hasError){const{onDoubleClick:r}=this,n=this.props.node.value;console.error(this.props.node,this.props.children);const o=S.createElement("div",{style:{backgroundColor:"rgb(255 206 215 / 13%)",padding:"5px",color:"#ff0000b0",textAlign:"center",fontSize:"12px"}},"Render error, node id: ",n.id,", node name:",n.title," component name:",n.title||n.componentName,S.createElement("p",null,"msg: ",String(this.state.error)),S.createElement("button",{onDoubleClick:r,style:{border:"1px solid rgba(100,100,100,0.1)",backgroundColor:"#fff",padding:"5px 10px",borderRadius:"2px",color:"gray",cursor:"pointer",marginTop:"5px"}},"double click to refresh"),S.createElement("div",{style:{display:"none"}}));return S.createElement(this.props.targetComponent,{onlyRenderChild:!0},o)}return this.props.children}}class ua{constructor(){y(this,"instanceMap",new Map)}get(e){return this.instanceMap.get(e)}add(e,r){const n=this.instanceMap.get(e);n?n.push(r):this.instanceMap.set(e,[r])}remove(e,r){const n=this.instanceMap.get(e);if(r!==void 0&&Array.isArray(n)){const o=n.filter(a=>a!==r);this.instanceMap.set(e,o)}else this.instanceMap.delete(e)}destroy(){this.instanceMap.clear()}}const la=t=>{const{node:e}=t,r=S.useMemo(()=>{const s=e.isContainer();return $t(s)?s:{placeholder:"Drag the component to place it",width:"100%",height:"100%",style:{}}},[t.node]),{placeholder:n,height:o,width:a,style:i}=r;return S.createElement("div",{style:{margin:0,padding:0,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(200,200,200,0.1)",border:"1px solid rgba(0,0,0,0.1)",borderRadius:"2px",fontSize:"14px",color:"gray",cursor:"default",width:a,height:o,...i}},n)};class rv extends S.Component{constructor(r){super(r);y(this,"instanceManager",new ua);y(this,"renderRef");y(this,"dropPlaceholder",la);y(this,"_components",{});y(this,"onGetComponent",(r,n)=>{var c,u;const o=this;let a=r;const i=(u=(c=n.material)==null?void 0:c.value.advanceCustom)==null?void 0:u.wrapComponent;i&&(a=i(r,{node:n,ctx:window.__C_ENGINE_DESIGNER_PLUGIN_CTX__}));class s extends S.Component{constructor(){super(...arguments);y(this,"_DESIGN_BOX",!0);y(this,"_NODE_MODEL",n);y(this,"_NODE_ID",n.id);y(this,"_UNIQUE_ID",`${n.id}_${Z()}`);y(this,"_STATUS")}componentDidMount(){o.instanceManager.add(n.id,this)}componentWillUnmount(){this._STATUS="DESTROY",o.instanceManager.remove(n.id,this)}render(){var j,O;const{children:f=[],onlyRenderChild:d,...h}=this.props;let g=f;if(Et(f)||(g=[f]),!!!g.filter(Boolean).length&&(n.isContainer()||n.value.componentName===At.ROOT_CONTAINER)){const T=(O=(j=n.material)==null?void 0:j.value.advanceCustom)==null?void 0:O.dropPlaceholder;g.push(S.createElement(T||o.dropPlaceholder,{node:n}))}return d?g:S.createElement(a,h,...g)}}return S.forwardRef(function(p,f){return S.createElement(ev,{node:n,targetComponent:s},S.createElement(s,{ref:f,...p}))})});this.updateComponents(this.props.components),this.renderRef=S.createRef(),r.dropPlaceholder&&(this.dropPlaceholder=r.dropPlaceholder)}updateComponents(r={}){this._components=Object.assign(this._components,r),this.forceUpdate()}componentDidMount(){var r,n;this.updateComponents(this.props.components),(n=(r=this.props).onMount)==null||n.call(r,this)}getPageModel(){var r;return(r=this.renderRef.current)==null?void 0:r.state.pageModel}rerender(r){var n;return(n=this.renderRef.current)==null?void 0:n.rerender(r)}getInstancesById(r,n){let o=[...this.instanceManager.get(r)||[]];return n!==void 0&&(o=o.filter(a=>n===(a==null?void 0:a._UNIQUE_ID))),o}getInstanceByDom(r){const n=fa(r);if(!n)return null;const o=pa(n);return(o==null?void 0:o.stateNode)||null}getDomsById(r,n){const o=this.getInstancesById(r),a=[];return o==null||o.forEach(i=>{var c;if((i==null?void 0:i._STATUS)==="DESTROY")return;const s=Sa.findDOMNode(i);if(s&&!(s instanceof Text))if(n){const u=Array.from(((c=s.querySelectorAll)==null?void 0:c.call(s,n))||[]);a.push(...u)}else a.push(s)}),a}getDomRectById(r,n){return this.getDomsById(r,n).map(i=>i==null?void 0:i.getBoundingClientRect()).filter(Boolean)}render(){const{props:r,onGetComponent:n}=this,{render:o,...a}=r;return o&&(o.ref.current=this),S.createElement(ca,{onGetComponent:n,...a,components:this._components,processNodeConfigHook:(i,s)=>{var h,g;if(s.nodeType!=="NODE")return i;const{props:c,condition:u}=i;let l={...c};const p=((h=s.value.configure)==null?void 0:h.devState)||{},f=(g=s.material)==null?void 0:g.value.fixedProps;if(f!==void 0){if($t(f))l={...l,...f};else if(typeof f=="function"){const b=f(l);l={...l,...b}}}let d=u;return p.condition===!1&&(d=p.condition),{props:bm(l,p.props||{}),condition:d}},ref:this.renderRef})}}const fa=t=>{if(!t)return null;const e=Object.keys(t).find(r=>r.startsWith("__reactInternalInstance$")||r.startsWith("__reactFiber$"))||"";return e?t[e]:fa(t.parentElement)},pa=t=>{var e;return t?(e=t==null?void 0:t.stateNode)!=null&&e._DESIGN_BOX?t:pa(t.return):null},nv=()=>{const t=S.useRef(null);return{ref:t,rerender:function(...e){t.current&&t.current.rerender(...e)},getInstancesById(e,r){var n;return((n=t.current)==null?void 0:n.getInstancesById(e,r))||[]},getInstanceByDom(e){var r;return((r=t.current)==null?void 0:r.getInstanceByDom(e))||null},getDomsById(e,r){var n;return((n=t.current)==null?void 0:n.getDomsById(e,r))||[]},getDomRectById(e,r){var n;return((n=t.current)==null?void 0:n.getDomRectById(e,r))||[]}}};var da={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(Am,function(){var r=function(){},n={},o={},a={};function i(f,d){f=f.push?f:[f];var h=[],g=f.length,b=g,j,O,T,A;for(j=function(I,k){k.length&&h.push(I),b--,b||d(h)};g--;){if(O=f[g],T=o[O],T){j(O,T);continue}A=a[O]=a[O]||[],A.push(j)}}function s(f,d){if(f){var h=a[f];if(o[f]=d,!!h)for(;h.length;)h[0](f,d),h.splice(0,1)}}function c(f,d){f.call&&(f={success:f}),d.length?(f.error||r)(d):(f.success||r)(f)}function u(f,d,h,g){var b=document,j=h.async,O=(h.numRetries||0)+1,T=h.before||r,A=f.replace(/[\?|#].*$/,""),I=f.replace(/^(css|img|module|nomodule)!/,""),k,Lt,w;if(g=g||0,/(^css!|\.css$)/.test(A))w=b.createElement("link"),w.rel="stylesheet",w.href=I,k="hideFocus"in w,k&&w.relList&&(k=0,w.rel="preload",w.as="style");else if(/(^img!|\.(png|gif|jpg|svg|webp)$)/.test(A))w=b.createElement("img"),w.src=I;else if(w=b.createElement("script"),w.src=I,w.async=j===void 0?!0:j,Lt="noModule"in w,/^module!/.test(A)){if(!Lt)return d(f,"l");w.type="module"}else if(/^nomodule!/.test(A)&&Lt)return d(f,"l");w.onload=w.onerror=w.onbeforeload=function(ot){var it=ot.type[0];if(k)try{w.sheet.cssText.length||(it="e")}catch(ae){ae.code!=18&&(it="e")}if(it=="e"){if(g+=1,g<O)return u(f,d,h,g)}else if(w.rel=="preload"&&w.as=="style")return w.rel="stylesheet";d(f,it,ot.defaultPrevented)},T(f,w)!==!1&&b.head.appendChild(w)}function l(f,d,h){f=f.push?f:[f];var g=f.length,b=g,j=[],O,T;for(O=function(A,I,k){if(I=="e"&&j.push(A),I=="b")if(k)j.push(A);else return;g--,g||d(j)},T=0;T<b;T++)u(f[T],O,h)}function p(f,d,h){var g,b;if(d&&d.trim&&(g=d),b=(g?h:d)||{},g){if(g in n)throw"LoadJS";n[g]=!0}function j(O,T){l(f,function(A){c(b,A),O&&c({success:O,error:T},A),s(g,A)},b)}if(b.returnPromise)return new Promise(j);j()}return p.ready=function(d,h){return i(d,function(g){c(h,g)}),p},p.done=function(d){s(d,[])},p.reset=function(){n={},o={},a={}},p.isDefined=function(d){return d in n},p})})(da);var ov=da.exports;const In=Pm(ov);class av{constructor(e,r){y(this,"assets");y(this,"loadStatus");y(this,"win",window);y(this,"_onSuccessList",[]);y(this,"_onErrorList",[]);this.assets=JSON.parse(JSON.stringify(e||[])),this.loadStatus="INIT",r!=null&&r.window&&(this.win=r.window)}load(e){const r=this.assets||[],n=[];for(let o=0;o<r.length;o++){const a=r[o];a.id||(a.id=Z()),n.push(a.id);const i=a.resources.map(s=>s.src);i.length&&In(i,a.id,{async:(e==null?void 0:e.async)??!1,before:(s,c)=>(this.win.document.body.appendChild(c),!1)})}return new Promise((o,a)=>{if(r.length===0){this._onSuccessList.forEach(i=>i()),o("");return}In.ready(n,{success:()=>{this._onSuccessList.forEach(i=>i()),o("")},error:i=>{this._onErrorList.forEach(s=>s(i)),a(i)}})})}onSuccess(e){return this._onSuccessList.push(e),this}onError(e){return this._onErrorList.push(e),this}}exports.AssetLoader=av;exports.ComponentInstanceManager=ua;exports.DefaultDropPlaceholder=la;exports.DefineReactAdapter=aa;exports.DesignRender=rv;exports.ReactAdapter=xm;exports.Render=ca;exports.canAcceptsRef=Zo;exports.collectVariable=jm;exports.compWrapper=ta;exports.convertCodeStringToFunction=ea;exports.findComponentByChainRefer=oa;exports.flatObject=Om;exports.formatSourceStylePropertyName=nr;exports.getAdapter=Ln;exports.getCSSTextValue=Sm;exports.getComponentsLibs=Cm;exports.getMatchVal=ra;exports.getNodeCssClassName=le;exports.getObjFromArrayMap=rr;exports.getThirdLibs=wm;exports.isClass=_m;exports.runExpression=lt;exports.shouldConstruct=Xo;exports.useDesignRender=nv;exports.useRender=tv;
|
|
29
29
|
//# sourceMappingURL=index.js.map
|