@chamn/render 0.5.1 → 0.5.2

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/index.cjs CHANGED
@@ -24,7 +24,7 @@
24
24
  data struct format is invalidate`);return o.message||r?console.warn(`${o.message||r}
25
25
  originData: ${JSON.stringify(e)}`):console.warn(`${JSON.stringify(e)}
26
26
  data struct format is invalidate`),o},Mr=t=>{const{data:e,message:r,throwError:n,dataStruct:o}=t;return yh(({data:a})=>{try{return na(a,o),{isValidate:!0}}catch(s){let i=s;return s instanceof ra&&(i=s.failures().map(c=>`【${c.path.join(".")}】: ${c.message}
27
- `)),{isValidate:!1,message:i,error:s}}})({data:e,message:r,throwError:n})};var Ft=(t=>(t.ROOT_CONTAINER="RootContainer",t))(Ft||{});const bh=R({type:k(F.FUNCTION),value:O()}),_h=xr(oa(Et,["componentName"]),R({componentName:k("RootContainer")}));function Sh(t){return{all:t=t||new Map,on:function(e,r){var n=t.get(e);n?n.push(r):t.set(e,[r])},off:function(e,r){var n=t.get(e);n&&(r?n.splice(n.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var n=t.get(e);n&&n.slice().map(function(o){o(r)}),(n=t.get("*"))&&n.slice().map(function(o){o(e,r)})}}}const oe=Sh(),Oh=(t,e)=>{const r={...t,value:[]},n=t.value;let o=new $t([]);return e&&(o=e.materialsMode||new $t([])),n&&(L(n)?r.value=n.map(a=>new D(a,{parent:e,materials:o})):V(n)&&r.value.push(new D(n,{parent:e,materials:o}))),r};class Nt{constructor(e,r){w(this,"nodeType","SLOT"),w(this,"rawData"),w(this,"parent"),w(this,"emitter",oe),w(this,"data"),w(this,"id"),w(this,"materialsMode"),this.parent=(r==null?void 0:r.parent)||null,this.rawData=e;const n=(r==null?void 0:r.materials)||new $t([]);this.materialsMode=n,this.id=tt(),this.data=Oh(e,this)}get value(){return this.data}export(e){const r=this.data,n=o=>{if(o instanceof D)return o.export(e);if(V(o)){const a={};return Object.keys(o||{}).forEach(s=>{a[s]=n(o[s])}),a}return L(o)?o.map(a=>n(a)):(e==="design"&&delete o.id,o)};return n(r)}}const ua=t=>{let e=[];return t.forEach(r=>{const n=r;n.type?n.type===Ke.SINGLE?e.push(n.content):n.type===Ke.GROUP&&(e=[...e,...ua(n.content)]):e.push(r)}),e},Xe=(t,e,r)=>{if(t.type)return t.type===F.SLOT?new Nt(t,{parent:e,materials:r}):t;if(V(t)){const n={};return Object.keys(t).forEach(o=>{n[o]=Ze(t[o],e,r)}),n}else return Array.isArray(t)?t.map(n=>Xe(n,e,r)):t},Ze=(t,e,r)=>V(t)?Xe(t,e,r):L(t)?t.map(n=>Xe(n,e,r)):t;class at{constructor(e,r,n){w(this,"nodeType","PROP"),w(this,"rawData"),w(this,"parent"),w(this,"emitter",oe),w(this,"data"),w(this,"name"),w(this,"materialsMode");const o=(n==null?void 0:n.materials)||new $t([]);this.materialsMode=o,this.parent=n==null?void 0:n.parent,this.rawData=r,this.name=e,this.data=Ze(r,this,o)}isIncludeSlot(){return!1}isIncludeExpression(){return!1}get value(){return this.data}updateValue(e){const r=this.data;this.data=Ze(e??r,this,this.materialsMode),this.emitter.emit("onPropChange",{value:this.data,preValue:r,node:this}),this.parent&&!(this.parent instanceof Nt)&&this.emitter.emit("onNodeChange",{value:this.parent.value,preValue:this.parent.value,node:this.parent})}get material(){const e=this.parent;if(e instanceof D){const r=e.material;return ua((r==null?void 0:r.value.props)||[]).find(n=>n.name===this.name)}else return null}export(e){const r=this.data,n=o=>{if(o instanceof at||o instanceof Nt||o instanceof D)return o.export(e);if(L(o))return o.map(a=>n(a));if(V(o)){const a={};return Object.keys(o||{}).forEach(s=>{a[s]=n(o[s])}),a}return o};return n(r)}}const jh=t=>{if(typeof t=="string")return!0;Mr({data:t,dataStruct:Et,throwError:!1})},An=(t,e,r)=>{if(typeof t=="string")return t;const n={...t,id:t.id??tt(),children:[],props:{},methods:t.methods||[],configure:ta(t.configure||{},{propsSetter:{},advanceSetter:{}})},o=Object.keys(t.props||{});return o.length&&o.forEach(a=>{var s;const i=(s=t.props)==null?void 0:s[a];if(i instanceof at){n.props[a]=i;return}n.props[a]=new at(a,i||"",{parent:e,materials:r})}),t.children&&(Array.isArray(t.children)?n.children=t.children.map(a=>{if(a instanceof D)return a;if(V(a)){const s=a;return new D(s,{parent:e,materials:r})}else return a}):(t.children instanceof D&&(n.children=[t.children]),n.children=[new D(t.children,{parent:e,materials:r})])),n};class D{constructor(e,r){w(this,"nodeType","NODE"),w(this,"rawData"),w(this,"data"),w(this,"emitter",oe),w(this,"parent"),w(this,"materialsModel"),w(this,"listenerHandle"),w(this,"onChangeCbQueue"),this.rawData=JSON.parse(JSON.stringify(e)),jh(e);const n=(r==null?void 0:r.materials)||new $t([]);this.parent=(r==null?void 0:r.parent)||null,this.materialsModel=n,this.data=An(e,this,n),this.listenerHandle=[],this.onChangeCbQueue=[],this.registerListener()}registerListener(){const e=r=>{const{node:n}=r;n===this&&n.id===this.id&&this.onChangeCbQueue.forEach(o=>o(r))};this.emitter.on("onNodeChange",e),this.listenerHandle.push(()=>{this.emitter.off("onNodeChange",e)})}onChange(e){return this.onChangeCbQueue.push(e),()=>{this.onChangeCbQueue=this.onChangeCbQueue.filter(r=>r!==e)}}destroy(){this.listenerHandle.forEach(e=>e())}get id(){return this.data.id}get value(){return this.data}clone(e){const r={...this.export("design"),id:e||tt()};return new D(r,{materials:this.materialsModel})}updateWithPlainObj(e){const r={...this.data,...e};return this.data=An(r,this,this.materialsModel),r}updateValue(e){const r=this.data,n=this.updateWithPlainObj(e);this.emitter.emit("onNodeChange",{value:n,preValue:r,node:this})}contains(e){return Pr(this,e)}get props(){return this.data.props}get material(){const e=this.materialsModel;return e==null?void 0:e.findByComponentName(this.data.componentName)}getPlainProps(){const e=this.data,r={};return Object.keys(e.props||{}).forEach(n=>{r[n]=e.props[n].export("design")}),r}getMaterialConfig(e){var r;return this.data.configure[e]!==void 0?this.data.configure.isContainer:(r=this.material)==null?void 0:r.value.isContainer}isContainer(){return this.getMaterialConfig("isContainer")}export(e){var r;const n=this.data;if(typeof n=="string")return n;const o={};Object.keys(n.props||{}).forEach(l=>{o[l]=n.props[l].export(e)});const a=(r=n.children)==null?void 0:r.map(l=>l instanceof D?l.export(e):l),s=n.configure||{},i=s.propsSetter||{},c={};Object.keys(i).forEach(l=>{const d=Io(i,l,!1);d&&(c[l]=d)}),s.propsSetter=c;const u=this.materialsModel.usedMaterials.find(l=>{var d;return l.componentName===((d=this.material)==null?void 0:d.componentName)});this.material&&!u&&this.materialsModel.usedMaterials.push(this.material);let f={...n,configure:s,props:o,children:a,condition:n.condition};return e==="design"&&delete f.id,f=Ir(f),f}}const Mn=(t,e,r)=>{const n={...t,id:tt(),props:{},componentName:Ft.ROOT_CONTAINER,children:[],methods:t.methods||[],configure:ta(t.configure||{},{propsSetter:{},advanceSetter:{}}),injectEnvList:t.injectEnvList};let o=[];L(t.children)?o=t.children.map(s=>s instanceof D?s:V(s)?new D(s,{parent:e,materials:r}):s):t.children instanceof D?o.push(t.children):t.children&&V(t.children)&&o.push(new D(t.children,{parent:e,materials:r}));const a=Object.keys(t.props||{});return a.length&&a.forEach(s=>{var i;const c=(i=t.props)==null?void 0:i[s];c instanceof at?n.props[s]=c:n.props[s]=new at(s,c||"",{parent:e,materials:r})}),n.children=o,n};class Xt{constructor(e,{parent:r,materials:n}){w(this,"rawData"),w(this,"data"),w(this,"nodeType",Ft.ROOT_CONTAINER),w(this,"emitter",oe),w(this,"materialsModel"),w(this,"listenerHandle"),w(this,"onChangeCbQueue"),w(this,"parent"),this.materialsModel=n,this.rawData=JSON.parse(JSON.stringify(e)),this.data=Mn(e,this,n),this.listenerHandle=[],this.onChangeCbQueue=[],this.registerListener(),this.parent=r}registerListener(){const e=r=>{const{node:n}=r;n===this&&n.id===this.id&&this.onChangeCbQueue.forEach(o=>o(r))};this.emitter.on("onNodeChange",e),this.listenerHandle.push(()=>{this.emitter.off("onNodeChange",e)})}onChange(e){return this.onChangeCbQueue.push(e),()=>{this.onChangeCbQueue=this.onChangeCbQueue.filter(r=>r!==e)}}get id(){return this.data.id}get value(){return this.data}get props(){return this.data.props}get material(){const e=this.materialsModel;return e==null?void 0:e.findByComponentName(this.data.componentName)}updateWithPlainObj(e){const r={...this.data,...e};return this.data=Mn(r,this,this.materialsModel),r}updateValue(e){const r=this.data;this.updateWithPlainObj(e),this.emitter.emit("onNodeChange",{value:this.data,preValue:r,node:this})}contains(e){return Pr(this,e)}getMaterialConfig(e){var r;return this.data.configure[e]!==void 0?this.data.configure.isContainer:(r=this.material)==null?void 0:r.value.isContainer}isContainer(){return this.getMaterialConfig("isContainer")}export(e=Tr.SAVE){var r;const n=this.data,o={};Object.keys(n.props||{}).forEach(c=>{o[c]=n.props[c].export(e)});const a=((r=n.children)==null?void 0:r.map(c=>{var u;return(u=c==null?void 0:c.export)==null?void 0:u.call(c,e)}))||[],s={...n,props:o,children:a.filter(c=>c),condition:n.condition};let i=ea(s,["id"]);return i=Ir(i),i}getPlainProps(){const e=this.data,r={};return Object.keys(e.props||{}).forEach(n=>{r[n]=e.props[n].export("design")}),r}destroy(){this.listenerHandle.forEach(e=>e())}clone(e){const r={...this.export("design"),id:e||tt()};return new Xt(r,{materials:this.materialsModel,parent:null})}}const ut=t=>(t==null?void 0:t.type)===F.EXPRESSION,la=t=>(t==null?void 0:t.type)===F.FUNCTION,Ch=t=>(t==null?void 0:t.type)===F.ACTION,tt=()=>Math.random().toString(32).slice(3,9),wh=t=>(t==null?void 0:t.nodeType)==="NODE",tr=t=>(t==null?void 0:t.nodeType)==="PROP",Eh=t=>(t==null?void 0:t.nodeType)==="SLOT",Ir=t=>Qp(t,e=>V(e)?!Object.keys(e).length:L(e)?!e.length:!e);function Nh(t,e){const r=[t];for(;r.length;){const n=r.shift();if(n&&e(n))return n;const o=(n==null?void 0:n.props)||{},a=i=>{if(i instanceof D){r.push(i);return}if(i instanceof Nt&&a(i.value.value),i instanceof at){a(i.value);return}if(V(i)){const c=i;Object.keys(c).forEach(u=>{a(c[u])});return}if(L(i)){i.forEach(c=>{a(c)});return}};a(o);const s=(n==null?void 0:n.value.children.filter(i=>i instanceof D))||[];r.push(...s)}}function Pr(t,e){return Nh(t,r=>r.id===e)}const $h=t=>{const e=Jo(t),r=e.snippets;return delete e.snippets,e.snippets=r.map(n=>({...e,...n,id:n.id||`${t.componentName}-${tt()}`,title:n.title||t.title,category:n.category||t.category,tags:[...n.tags||[],...t.tags||[]],groupName:n.groupName||t.groupName,snapshot:n.snapshot||t.icon,snapshotText:n.snapshotText,schema:{...n.schema,componentName:n.schema.componentName||t.componentName}})),e};class xh{constructor(e){w(this,"rawData"),w(this,"data"),this.rawData=e,this.data=$h(e)}get value(){return this.data}get rawValue(){return this.rawData}get componentName(){return this.data.componentName}get snippets(){return this.data.snippets}getSnippetById(e){return this.data.snippets.find(r=>r.id===e)}}const Te=t=>{if(!L(t))throw new Error("Materials must be a array");return t.map(e=>new xh(e))},Rh=t=>{t==null||t.forEach(e=>{Mr({data:e,dataStruct:vh,throwError:!1})})};class $t{constructor(e){w(this,"rawData"),w(this,"data"),w(this,"usedMaterials",[]),this.rawData=e,Rh(e),this.data=Te(e)}addMaterials(e){const r=Te(e),n=[],o=this.data.map(s=>{const i=r.findIndex(c=>c.componentName===s.componentName);return i>=0?(n.push(i),r[i]):s}),a=r.filter((s,i)=>!n.includes(i));this.data=[...o,...a]}replaceMaterials(e){const r=Te(e);this.data=[...r]}removeMaterial(e){const r=this.data.filter(n=>!e.includes(n.componentName));this.data=r}findByComponentName(e){return this.data.find(r=>r.componentName===e)}findSnippetById(e){const r=[...this.data];let n=null;for(;!n&&r.length;){const o=r.pop();n=o==null?void 0:o.getSnippetById(e)}return n}getAllSnippets(){const e=this.data.reduce((a,s)=>(a.push(...s.snippets),a),[]),r=[],n={default:[]};e.forEach(a=>{const s=a.groupName||"default";r.includes(s)||(r.push(s),n[s]=[]),n[s].push(a)});let o=[];return r.forEach(a=>{const s=["default"],i={default:[]},c=n[a];if(c.length!==0){c.forEach(l=>{const d=l.category||"default";s.includes(d)||(s.push(d),i[d]=[]),i[d].push(l)});const u=[];s.forEach(l=>{i[l].length&&u.push({name:l,list:i[l]})});const f={name:a,list:u};o.push(f)}}),o=o.sort((a,s)=>(a.name||"")>(s.name||"")?1:-1),o}get value(){return this.data}get rawValue(){return this.rawData}}const Th=R({version:b(O()),name:b(O()),css:b(O()),lifecycle:b(T()),props:b(T()),methods:b(P(bh)),componentsMeta:P(xr(R({componentName:O()}),Rr)),thirdLibs:b(uh),componentsTree:_h,assets:b(P(T())),extra:b(T())}),fa=t=>(Mr({data:t,dataStruct:Th,throwError:!1}),t),Ae=(t,e,r)=>({...t,componentsTree:new Xt(t.componentsTree,{parent:e,materials:r})});class pe{constructor(e,r){w(this,"nodeType","PAGE"),w(this,"rawData"),w(this,"emitter",oe),w(this,"data"),w(this,"parent"),w(this,"materialsModel"),w(this,"assetPackagesList"),fa(e),this.rawData=JSON.parse(JSON.stringify(e)),this.materialsModel=new $t((r==null?void 0:r.materials)||[]),this.data=Ae(e,this,this.materialsModel),this.assetPackagesList=[...(r==null?void 0:r.assetPackagesList)||[],...this.data.assets||[]]}updatePage(e){const r=this.data;this.rawData=JSON.parse(JSON.stringify(e)),this.data=Ae(e,this,this.materialsModel),this.emitter.emit("onPageChange",{value:this.data,preValue:r,node:this})}reloadPage(e){const r=this.data;e&&(this.rawData=JSON.parse(JSON.stringify(e)),this.data=Ae(e,this,this.materialsModel)),this.emitter.emit("onReloadPage",{value:this.data,preValue:r,node:this})}get value(){return this.data}getNode(e){if(!e)return;const r=this.data.componentsTree;return Pr(r,e)}addNode(e,r,n="AFTER"){var o;if(n==="AFTER"||n==="BEFORE"){const a=r.parent;if(a===null&&r instanceof Xt)return console.warn("Not found parent node"),!1;if(a instanceof at)return console.warn("CProp can not add node"),!1;if(a instanceof Nt){const i=a.value.value,c=i.findIndex(u=>u===r)??-1;return c>=0?(n==="BEFORE"?i.splice(c,0,e):i.splice(c+1,0,e),e.parent=a,(o=a.parent)==null||o.updateValue(),!0):!1}if(a instanceof pe)return!1;const s=(a==null?void 0:a.value.children.findIndex(i=>i===r))??-1;return s>=0?(n==="BEFORE"?a==null||a.value.children.splice(s,0,e):a==null||a.value.children.splice(s+1,0,e),e.parent=a,a==null||a.updateValue(),!0):(console.warn("Not found target node"),!1)}if(n==="CHILD_START")return r.value.children.unshift(e),e.parent=r,r.updateValue(),!0;if(n==="CHILD_END")return r.value.children.push(e),e.parent=r,r.updateValue(),!0;if(V(n)){const a=n;if(a.type==="CHILD"){const s=a.pos,i=a.index||0;return s==="BEFORE"?r==null||r.value.children.splice(i,0,e):r==null||r.value.children.splice(i+1,0,e),e.parent=r,r.updateValue(),!0}else console.warn("Can not parse pos obj")}return!1}createNode(e){return delete e.id,new D(e,{parent:null,materials:this.materialsModel})}addNodeById(e,r,n="AFTER"){const o=this.getNode(r);return o?this.addNode(e,o,n):(console.warn(`Not find a node by ${r}, pls check it`),!1)}copyNode(e){const r=e.export("design");r.id=tt();const n=new D(r,{parent:e.parent,materials:this.materialsModel});return this.addNode(n,e,"AFTER"),n}copyNodeById(e){const r=this.getNode(e);return r&&r instanceof D?this.copyNode(r):!1}moveNode(e,r,n){this.deleteNode(e);let o=r;return["AFTER","BEFORE"].includes(n)&&(o=r.parent),e.parent=o,this.addNode(e,r,n)}moveNodeById(e,r,n){const o=this.getNode(e),a=this.getNode(r);return o&&a&&o instanceof D&&a instanceof D?this.moveNode(o,a,n):!1}deleteNode(e){var r;const n=e.parent;if(!n)throw new Error("parent node is null or undefined, pls check it");if(n instanceof Nt){const o=n.value.value,a=o.findIndex(i=>i===e),s=o[a];return o.splice(a,1),(r=n.parent)==null||r.updateValue(),s}if(n instanceof D||n instanceof Xt){const o=n.value.children,a=o.findIndex(i=>i===e),s=o[a];return o.splice(a,1),n.updateValue(),s}}deleteNodeById(e){const r=this.getNode(e);if(r)return this.deleteNode(r)}export(e=Tr.SAVE){var r;const n=this.data.componentsTree.export(e),o=this.assetPackagesList,a=[],s=this.materialsModel.usedMaterials.map(c=>{const u=o.find(f=>{var l;return f.package===((l=c.value.npm)==null?void 0:l.package)});return u&&a.push(u),{componentName:c.componentName,...Jo(c.value.npm||{})}}).filter(c=>c.componentName&&c.package&&c.version?!0:(console.warn(`${JSON.stringify(c,null,2)} not a valid material info`),!1));this.materialsModel.usedMaterials=[];let i={...this.data,componentsTree:Ir(n),componentsMeta:s,thirdLibs:this.data.thirdLibs,assets:[]};return(r=this.data.thirdLibs)==null||r.forEach(c=>{const u=o.find(f=>c.package===f.package);u&&a.push(u)}),i.assets=th(a,c=>c.package),i=ea(i,["id"]),JSON.parse(JSON.stringify(i))}getRootNode(){return this.data.componentsTree}}Ft.ROOT_CONTAINER;const ae="DYNAMIC",da=["$$context","$$nodeModel"],Dr="ON_DID_RENDER",Lr="ON_WILL_DESTROY",pa=[Dr,Lr],er=(t,e)=>{let r=t;return e&&(r={...t},r.__proto__=e||null),r},Zt=(t,e={},...r)=>typeof t=="string"||typeof t=="number"?String(t):(da.forEach(o=>{o in e&&t.__CP_TYPE__!==ae&&delete e[o]}),N.createElement(t,e,...r)),In=(t={},e)=>{const r=[],n=(o,a)=>{let s=a;tr(a)&&(s=a.value),e(s)?r.push({keyPath:o,val:s}):jt(s)?s.forEach((i,c)=>{n([...o,String(c)],i)}):At(s)&&Object.keys(s).forEach(i=>{n([...o,i],s[i])})};return n(["$root"],t),r},St=(t,e)=>{const r=t.handler,{context:n,storeManager:o}=e;return e.actionVariableSpace||(e.actionVariableSpace={}),async function(...a){const s={},i=async f=>{const l=f;if(l.type==="RUN_CODE"){const d=ee({funcName:"",funcBody:`function() {
27
+ `)),{isValidate:!1,message:i,error:s}}})({data:e,message:r,throwError:n})};var Ft=(t=>(t.ROOT_CONTAINER="RootContainer",t))(Ft||{});const bh=R({type:k(F.FUNCTION),value:O()}),_h=xr(oa(Et,["componentName"]),R({componentName:k("RootContainer")}));function Sh(t){return{all:t=t||new Map,on:function(e,r){var n=t.get(e);n?n.push(r):t.set(e,[r])},off:function(e,r){var n=t.get(e);n&&(r?n.splice(n.indexOf(r)>>>0,1):t.set(e,[]))},emit:function(e,r){var n=t.get(e);n&&n.slice().map(function(o){o(r)}),(n=t.get("*"))&&n.slice().map(function(o){o(e,r)})}}}const oe=Sh(),Oh=(t,e)=>{const r={...t,value:[]},n=t.value;let o=new $t([]);return e&&(o=e.materialsMode||new $t([])),n&&(L(n)?r.value=n.map(a=>new D(a,{parent:e,materials:o})):V(n)&&r.value.push(new D(n,{parent:e,materials:o}))),r};class Nt{constructor(e,r){w(this,"nodeType","SLOT"),w(this,"rawData"),w(this,"parent"),w(this,"emitter",oe),w(this,"data"),w(this,"id"),w(this,"materialsMode"),this.parent=(r==null?void 0:r.parent)||null,this.rawData=e;const n=(r==null?void 0:r.materials)||new $t([]);this.materialsMode=n,this.id=tt(),this.data=Oh(e,this)}get value(){return this.data}export(e){const r=this.data,n=o=>{if(o instanceof D)return o.export(e);if(V(o)){const a={};return Object.keys(o||{}).forEach(s=>{a[s]=n(o[s])}),a}return L(o)?o.map(a=>n(a)):(e==="design"&&delete o.id,o)};return n(r)}}const ua=t=>{let e=[];return t.forEach(r=>{const n=r;n.type?n.type===Ke.SINGLE?e.push(n.content):n.type===Ke.GROUP&&(e=[...e,...ua(n.content)]):e.push(r)}),e},Xe=(t,e,r)=>{if(t.type)return t.type===F.SLOT?new Nt(t,{parent:e,materials:r}):t;if(V(t)){const n={};return Object.keys(t).forEach(o=>{n[o]=Ze(t[o],e,r)}),n}else return Array.isArray(t)?t.map(n=>Xe(n,e,r)):t},Ze=(t,e,r)=>V(t)?Xe(t,e,r):L(t)?t.map(n=>Xe(n,e,r)):t;class at{constructor(e,r,n){w(this,"nodeType","PROP"),w(this,"rawData"),w(this,"parent"),w(this,"emitter",oe),w(this,"data"),w(this,"name"),w(this,"materialsMode");const o=(n==null?void 0:n.materials)||new $t([]);this.materialsMode=o,this.parent=n==null?void 0:n.parent,this.rawData=r,this.name=e,this.data=Ze(r,this,o)}isIncludeSlot(){return!1}isIncludeExpression(){return!1}get value(){return this.data}updateValue(e){const r=this.data;this.data=Ze(e??r,this,this.materialsMode),this.emitter.emit("onPropChange",{value:this.data,preValue:r,node:this}),this.parent&&!(this.parent instanceof Nt)&&this.emitter.emit("onNodeChange",{value:this.parent.value,preValue:this.parent.value,node:this.parent})}get material(){const e=this.parent;if(e instanceof D){const r=e.material;return ua((r==null?void 0:r.value.props)||[]).find(n=>n.name===this.name)}else return null}export(e){const r=this.data,n=o=>{if(o instanceof at||o instanceof Nt||o instanceof D)return o.export(e);if(L(o))return o.map(a=>n(a));if(V(o)){const a={};return Object.keys(o||{}).forEach(s=>{a[s]=n(o[s])}),a}return o};return n(r)}}const jh=t=>{if(typeof t=="string")return!0;Mr({data:t,dataStruct:Et,throwError:!1})},An=(t,e,r)=>{if(typeof t=="string")return t;const n={...t,id:t.id??tt(),children:[],props:{},methods:t.methods||[],configure:ta(t.configure||{},{propsSetter:{},advanceSetter:{}})},o=Object.keys(t.props||{});return o.length&&o.forEach(a=>{var s;const i=(s=t.props)==null?void 0:s[a];if(i instanceof at){n.props[a]=i;return}n.props[a]=new at(a,i||"",{parent:e,materials:r})}),t.children&&(Array.isArray(t.children)?n.children=t.children.map(a=>{if(a instanceof D)return a;if(V(a)){const s=a;return new D(s,{parent:e,materials:r})}else return a}):(t.children instanceof D&&(n.children=[t.children]),n.children=[new D(t.children,{parent:e,materials:r})])),n};class D{constructor(e,r){w(this,"nodeType","NODE"),w(this,"rawData"),w(this,"data"),w(this,"emitter",oe),w(this,"parent"),w(this,"materialsModel"),w(this,"listenerHandle"),w(this,"onChangeCbQueue"),this.rawData=JSON.parse(JSON.stringify(e)),jh(e);const n=(r==null?void 0:r.materials)||new $t([]);this.parent=(r==null?void 0:r.parent)||null,this.materialsModel=n,this.data=An(e,this,n),this.listenerHandle=[],this.onChangeCbQueue=[],this.registerListener()}registerListener(){const e=r=>{const{node:n}=r;n===this&&n.id===this.id&&this.onChangeCbQueue.forEach(o=>o(r))};this.emitter.on("onNodeChange",e),this.listenerHandle.push(()=>{this.emitter.off("onNodeChange",e)})}onChange(e){return this.onChangeCbQueue.push(e),()=>{this.onChangeCbQueue=this.onChangeCbQueue.filter(r=>r!==e)}}destroy(){this.listenerHandle.forEach(e=>e())}get id(){return this.data.id}get value(){return this.data}clone(e){const r={...this.export("design"),id:e||tt()};return new D(r,{materials:this.materialsModel})}updateWithPlainObj(e){const r={...this.data,...e};return this.data=An(r,this,this.materialsModel),r}updateValue(e){const r=this.data,n=this.updateWithPlainObj(e);this.emitter.emit("onNodeChange",{value:n,preValue:r,node:this})}contains(e){return Pr(this,e)}get props(){return this.data.props}get material(){const e=this.materialsModel;return e==null?void 0:e.findByComponentName(this.data.componentName)}getPlainProps(){const e=this.data,r={};return Object.keys(e.props||{}).forEach(n=>{r[n]=e.props[n].export("design")}),r}getMaterialConfig(e){var r;return this.data.configure[e]!==void 0?this.data.configure.isContainer:(r=this.material)==null?void 0:r.value.isContainer}isContainer(){return this.getMaterialConfig("isContainer")}export(e){var r;const n=this.data;if(typeof n=="string")return n;const o={};Object.keys(n.props||{}).forEach(l=>{o[l]=n.props[l].export(e)});const a=(r=n.children)==null?void 0:r.map(l=>l instanceof D?l.export(e):l),s=n.configure||{},i=s.propsSetter||{},c={};Object.keys(i).forEach(l=>{const d=Io(i,l,!1);d&&(c[l]=d)}),s.propsSetter=c;const u=this.materialsModel.usedMaterials.find(l=>{var d;return l.componentName===((d=this.material)==null?void 0:d.componentName)});this.material&&!u&&this.materialsModel.usedMaterials.push(this.material);let f={...n,configure:s,props:o,children:a,condition:n.condition,extra:this.data.extra};return e==="design"&&delete f.id,f=Ir(f),f}}const Mn=(t,e,r)=>{const n={...t,id:tt(),props:{},componentName:Ft.ROOT_CONTAINER,children:[],methods:t.methods||[],configure:ta(t.configure||{},{propsSetter:{},advanceSetter:{}}),injectEnvList:t.injectEnvList};let o=[];L(t.children)?o=t.children.map(s=>s instanceof D?s:V(s)?new D(s,{parent:e,materials:r}):s):t.children instanceof D?o.push(t.children):t.children&&V(t.children)&&o.push(new D(t.children,{parent:e,materials:r}));const a=Object.keys(t.props||{});return a.length&&a.forEach(s=>{var i;const c=(i=t.props)==null?void 0:i[s];c instanceof at?n.props[s]=c:n.props[s]=new at(s,c||"",{parent:e,materials:r})}),n.children=o,n};class Xt{constructor(e,{parent:r,materials:n}){w(this,"rawData"),w(this,"data"),w(this,"nodeType",Ft.ROOT_CONTAINER),w(this,"emitter",oe),w(this,"materialsModel"),w(this,"listenerHandle"),w(this,"onChangeCbQueue"),w(this,"parent"),this.materialsModel=n,this.rawData=JSON.parse(JSON.stringify(e)),this.data=Mn(e,this,n),this.listenerHandle=[],this.onChangeCbQueue=[],this.registerListener(),this.parent=r}registerListener(){const e=r=>{const{node:n}=r;n===this&&n.id===this.id&&this.onChangeCbQueue.forEach(o=>o(r))};this.emitter.on("onNodeChange",e),this.listenerHandle.push(()=>{this.emitter.off("onNodeChange",e)})}onChange(e){return this.onChangeCbQueue.push(e),()=>{this.onChangeCbQueue=this.onChangeCbQueue.filter(r=>r!==e)}}get id(){return this.data.id}get value(){return this.data}get props(){return this.data.props}get material(){const e=this.materialsModel;return e==null?void 0:e.findByComponentName(this.data.componentName)}updateWithPlainObj(e){const r={...this.data,...e};return this.data=Mn(r,this,this.materialsModel),r}updateValue(e){const r=this.data;this.updateWithPlainObj(e),this.emitter.emit("onNodeChange",{value:this.data,preValue:r,node:this})}contains(e){return Pr(this,e)}getMaterialConfig(e){var r;return this.data.configure[e]!==void 0?this.data.configure.isContainer:(r=this.material)==null?void 0:r.value.isContainer}isContainer(){return this.getMaterialConfig("isContainer")}export(e=Tr.SAVE){var r;const n=this.data,o={};Object.keys(n.props||{}).forEach(c=>{o[c]=n.props[c].export(e)});const a=((r=n.children)==null?void 0:r.map(c=>{var u;return(u=c==null?void 0:c.export)==null?void 0:u.call(c,e)}))||[],s={...n,props:o,children:a.filter(c=>c),condition:n.condition,extra:this.data.extra};let i=ea(s,["id"]);return i=Ir(i),i}getPlainProps(){const e=this.data,r={};return Object.keys(e.props||{}).forEach(n=>{r[n]=e.props[n].export("design")}),r}destroy(){this.listenerHandle.forEach(e=>e())}clone(e){const r={...this.export("design"),id:e||tt()};return new Xt(r,{materials:this.materialsModel,parent:null})}}const ut=t=>(t==null?void 0:t.type)===F.EXPRESSION,la=t=>(t==null?void 0:t.type)===F.FUNCTION,Ch=t=>(t==null?void 0:t.type)===F.ACTION,tt=()=>Math.random().toString(32).slice(3,9),wh=t=>(t==null?void 0:t.nodeType)==="NODE",tr=t=>(t==null?void 0:t.nodeType)==="PROP",Eh=t=>(t==null?void 0:t.nodeType)==="SLOT",Ir=t=>Qp(t,e=>V(e)?!Object.keys(e).length:L(e)?!e.length:!e);function Nh(t,e){const r=[t];for(;r.length;){const n=r.shift();if(n&&e(n))return n;const o=(n==null?void 0:n.props)||{},a=i=>{if(i instanceof D){r.push(i);return}if(i instanceof Nt&&a(i.value.value),i instanceof at){a(i.value);return}if(V(i)){const c=i;Object.keys(c).forEach(u=>{a(c[u])});return}if(L(i)){i.forEach(c=>{a(c)});return}};a(o);const s=(n==null?void 0:n.value.children.filter(i=>i instanceof D))||[];r.push(...s)}}function Pr(t,e){return Nh(t,r=>r.id===e)}const $h=t=>{const e=Jo(t),r=e.snippets;return delete e.snippets,e.snippets=r.map(n=>({...e,...n,id:n.id||`${t.componentName}-${tt()}`,title:n.title||t.title,category:n.category||t.category,tags:[...n.tags||[],...t.tags||[]],groupName:n.groupName||t.groupName,snapshot:n.snapshot||t.icon,snapshotText:n.snapshotText,schema:{...n.schema,componentName:n.schema.componentName||t.componentName}})),e};class xh{constructor(e){w(this,"rawData"),w(this,"data"),this.rawData=e,this.data=$h(e)}get value(){return this.data}get rawValue(){return this.rawData}get componentName(){return this.data.componentName}get snippets(){return this.data.snippets}getSnippetById(e){return this.data.snippets.find(r=>r.id===e)}}const Te=t=>{if(!L(t))throw new Error("Materials must be a array");return t.map(e=>new xh(e))},Rh=t=>{t==null||t.forEach(e=>{Mr({data:e,dataStruct:vh,throwError:!1})})};class $t{constructor(e){w(this,"rawData"),w(this,"data"),w(this,"usedMaterials",[]),this.rawData=e,Rh(e),this.data=Te(e)}addMaterials(e){const r=Te(e),n=[],o=this.data.map(s=>{const i=r.findIndex(c=>c.componentName===s.componentName);return i>=0?(n.push(i),r[i]):s}),a=r.filter((s,i)=>!n.includes(i));this.data=[...o,...a]}replaceMaterials(e){const r=Te(e);this.data=[...r]}removeMaterial(e){const r=this.data.filter(n=>!e.includes(n.componentName));this.data=r}findByComponentName(e){return this.data.find(r=>r.componentName===e)}findSnippetById(e){const r=[...this.data];let n=null;for(;!n&&r.length;){const o=r.pop();n=o==null?void 0:o.getSnippetById(e)}return n}getAllSnippets(){const e=this.data.reduce((a,s)=>(a.push(...s.snippets),a),[]),r=[],n={default:[]};e.forEach(a=>{const s=a.groupName||"default";r.includes(s)||(r.push(s),n[s]=[]),n[s].push(a)});let o=[];return r.forEach(a=>{const s=["default"],i={default:[]},c=n[a];if(c.length!==0){c.forEach(l=>{const d=l.category||"default";s.includes(d)||(s.push(d),i[d]=[]),i[d].push(l)});const u=[];s.forEach(l=>{i[l].length&&u.push({name:l,list:i[l]})});const f={name:a,list:u};o.push(f)}}),o=o.sort((a,s)=>(a.name||"")>(s.name||"")?1:-1),o}get value(){return this.data}get rawValue(){return this.rawData}}const Th=R({version:b(O()),name:b(O()),css:b(O()),lifecycle:b(T()),props:b(T()),methods:b(P(bh)),componentsMeta:P(xr(R({componentName:O()}),Rr)),thirdLibs:b(uh),componentsTree:_h,assets:b(P(T())),extra:b(T())}),fa=t=>(Mr({data:t,dataStruct:Th,throwError:!1}),t),Ae=(t,e,r)=>({...t,componentsTree:new Xt(t.componentsTree,{parent:e,materials:r})});class pe{constructor(e,r){w(this,"nodeType","PAGE"),w(this,"rawData"),w(this,"emitter",oe),w(this,"data"),w(this,"parent"),w(this,"materialsModel"),w(this,"assetPackagesList"),fa(e),this.rawData=JSON.parse(JSON.stringify(e)),this.materialsModel=new $t((r==null?void 0:r.materials)||[]),this.data=Ae(e,this,this.materialsModel),this.assetPackagesList=[...(r==null?void 0:r.assetPackagesList)||[],...this.data.assets||[]]}updatePage(e){const r=this.data;this.rawData=JSON.parse(JSON.stringify(e)),this.data=Ae(e,this,this.materialsModel),this.emitter.emit("onPageChange",{value:this.data,preValue:r,node:this})}reloadPage(e){const r=this.data;e&&(this.rawData=JSON.parse(JSON.stringify(e)),this.data=Ae(e,this,this.materialsModel)),this.emitter.emit("onReloadPage",{value:this.data,preValue:r,node:this})}get value(){return this.data}getNode(e){if(!e)return;const r=this.data.componentsTree;return Pr(r,e)}addNode(e,r,n="AFTER"){var o;if(n==="AFTER"||n==="BEFORE"){const a=r.parent;if(a===null&&r instanceof Xt)return console.warn("Not found parent node"),!1;if(a instanceof at)return console.warn("CProp can not add node"),!1;if(a instanceof Nt){const i=a.value.value,c=i.findIndex(u=>u===r)??-1;return c>=0?(n==="BEFORE"?i.splice(c,0,e):i.splice(c+1,0,e),e.parent=a,(o=a.parent)==null||o.updateValue(),!0):!1}if(a instanceof pe)return!1;const s=(a==null?void 0:a.value.children.findIndex(i=>i===r))??-1;return s>=0?(n==="BEFORE"?a==null||a.value.children.splice(s,0,e):a==null||a.value.children.splice(s+1,0,e),e.parent=a,a==null||a.updateValue(),!0):(console.warn("Not found target node"),!1)}if(n==="CHILD_START")return r.value.children.unshift(e),e.parent=r,r.updateValue(),!0;if(n==="CHILD_END")return r.value.children.push(e),e.parent=r,r.updateValue(),!0;if(V(n)){const a=n;if(a.type==="CHILD"){const s=a.pos,i=a.index||0;return s==="BEFORE"?r==null||r.value.children.splice(i,0,e):r==null||r.value.children.splice(i+1,0,e),e.parent=r,r.updateValue(),!0}else console.warn("Can not parse pos obj")}return!1}createNode(e){return delete e.id,new D(e,{parent:null,materials:this.materialsModel})}addNodeById(e,r,n="AFTER"){const o=this.getNode(r);return o?this.addNode(e,o,n):(console.warn(`Not find a node by ${r}, pls check it`),!1)}copyNode(e){const r=e.export("design");r.id=tt();const n=new D(r,{parent:e.parent,materials:this.materialsModel});return this.addNode(n,e,"AFTER"),n}copyNodeById(e){const r=this.getNode(e);return r&&r instanceof D?this.copyNode(r):!1}moveNode(e,r,n){this.deleteNode(e);let o=r;return["AFTER","BEFORE"].includes(n)&&(o=r.parent),e.parent=o,this.addNode(e,r,n)}moveNodeById(e,r,n){const o=this.getNode(e),a=this.getNode(r);return o&&a&&o instanceof D&&a instanceof D?this.moveNode(o,a,n):!1}deleteNode(e){var r;const n=e.parent;if(!n)throw new Error("parent node is null or undefined, pls check it");if(n instanceof Nt){const o=n.value.value,a=o.findIndex(i=>i===e),s=o[a];return o.splice(a,1),(r=n.parent)==null||r.updateValue(),s}if(n instanceof D||n instanceof Xt){const o=n.value.children,a=o.findIndex(i=>i===e),s=o[a];return o.splice(a,1),n.updateValue(),s}}deleteNodeById(e){const r=this.getNode(e);if(r)return this.deleteNode(r)}export(e=Tr.SAVE){var r;const n=this.data.componentsTree.export(e),o=this.assetPackagesList,a=[],s=this.materialsModel.usedMaterials.map(c=>{const u=o.find(f=>{var l;return f.package===((l=c.value.npm)==null?void 0:l.package)});return u&&a.push(u),{componentName:c.componentName,...Jo(c.value.npm||{})}}).filter(c=>c.componentName&&c.package&&c.version?!0:(console.warn(`${JSON.stringify(c,null,2)} not a valid material info`),!1));this.materialsModel.usedMaterials=[];let i={...this.data,componentsTree:Ir(n),componentsMeta:s,thirdLibs:this.data.thirdLibs,assets:[],extra:this.data.extra};return(r=this.data.thirdLibs)==null||r.forEach(c=>{const u=o.find(f=>c.package===f.package);u&&a.push(u)}),i.assets=th(a,c=>c.package),i=ea(i,["id"]),JSON.parse(JSON.stringify(i))}getRootNode(){return this.data.componentsTree}}Ft.ROOT_CONTAINER;const ae="DYNAMIC",da=["$$context","$$nodeModel"],Dr="ON_DID_RENDER",Lr="ON_WILL_DESTROY",pa=[Dr,Lr],er=(t,e)=>{let r=t;return e&&(r={...t},r.__proto__=e||null),r},Zt=(t,e={},...r)=>typeof t=="string"||typeof t=="number"?String(t):(da.forEach(o=>{o in e&&t.__CP_TYPE__!==ae&&delete e[o]}),N.createElement(t,e,...r)),In=(t={},e)=>{const r=[],n=(o,a)=>{let s=a;tr(a)&&(s=a.value),e(s)?r.push({keyPath:o,val:s}):jt(s)?s.forEach((i,c)=>{n([...o,String(c)],i)}):At(s)&&Object.keys(s).forEach(i=>{n([...o,i],s[i])})};return n(["$root"],t),r},St=(t,e)=>{const r=t.handler,{context:n,storeManager:o}=e;return e.actionVariableSpace||(e.actionVariableSpace={}),async function(...a){const s={},i=async f=>{const l=f;if(l.type==="RUN_CODE"){const d=ee({funcName:"",funcBody:`function() {
28
28
  ${l.value} }`,nodeContext:n,storeManager:o,$$response:e.$$response,actionVariableSpace:e.actionVariableSpace});let p;e.$$response!==void 0?p=d(e.$$response,...a):p=d(...a),p!=null&&p.then?s[l.id]=await p:s[l.id]=p}if(l.type==="JUMP_LINK"){const p=Ah(l,e)(...a);p!=null&&p.then?s[l.id]=await p:s[l.id]=p}if(l.type==="REQUEST_API"){const{run:d,afterFailedResponse:p,afterSuccessResponse:y}=Mh(l,e);try{const S=d(...a);S!=null&&S.then?s[l.id]=await S:s[l.id]=S,l.responseVarName&&(e.actionVariableSpace[l.responseVarName]=s[l.id]);const h=y(s[l.id],...a);return h!=null&&h.then?await h:h}catch(S){const h=await p(S);return h!=null&&h.then?await h:h}}if(l.type==="CALL_NODE_METHOD"){const p=Ih(l,e)(...a);p!=null&&p.then?s[l.id]=await p:s[l.id]=p,l.returnVarName&&(e.actionVariableSpace[l.returnVarName]=s[l.id])}if(l.type==="ASSIGN_VALUE"){const d=Ph(l,e);let p=[...a];e.$$response!==void 0&&(p=[e.$$response,p]);const y=d(...p);s[l.id]=await y}};let c=r[0];const u=new Set;for(;c;){if(u.has(c.id))return;await i(c),u.add(c.id),c=r.find(l=>(c==null?void 0:c.next)&&l.id===(c==null?void 0:c.next))}}};function Ah(t,e){return ft(t.link,e)}const ft=(t,e)=>function(...r){return ut(t)?lt(t.value,{...e.context,nodeContext:e.context,storeManager:e.storeManager,$$response:e.$$response,actionVariableSpace:e.actionVariableSpace}):la(t)?ee({funcName:t.name||"",funcBody:t.value,nodeContext:e.context,storeManager:e.storeManager,$$response:e.$$response,actionVariableSpace:e.actionVariableSpace})(...r):t},Mh=(t,e)=>({run:function(...a){var d,p;let s="";t.apiPath&&(s=ft(t.apiPath,e)(...a));const i=t.body||{};Object.keys(i).forEach(y=>{i[y]=ft(i[y],e)(...a)});const c=t.query||{};Object.keys(c).forEach(y=>{c[y]=ft(c[y],e)(...a)});const u=t.header||{};Object.keys(u).forEach(y=>{u[y]=ft(u[y],e)(...a)});const f=t.method||"GET";return(p=(d=e.context).requestAPI)==null?void 0:p.call(d,{url:s,method:f,header:u,body:i,query:c})},afterSuccessResponse:async(a,...s)=>{if(!t.afterSuccessResponse)return a;const i=[...t.afterSuccessResponse||[],...t.afterFailedResponse||[]];return St({handler:i},{...e,$$response:a})(...s)},afterFailedResponse:async(a,...s)=>{if(!t.afterFailedResponse)return a;const i=[...t.afterFailedResponse||[],...t.afterSuccessResponse||[]];return St({handler:i},{...e,$$response:a})(...s)}}),Ih=(t,e)=>(...r)=>{const n=ee({funcName:"",funcBody:`
29
29
  function () {
30
30
  var args = arguments;