@chamn/render 0.3.3 → 0.3.4
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +7 -7
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
originData: ${JSON.stringify(e)}`):console.warn(`${JSON.stringify(e)}
|
|
26
26
|
data struct format is invalidate`),o},Ar=t=>{const{data:e,message:r,throwError:n,dataStruct:o}=t;return yh(({data:a})=>{try{return ra(a,o),{isValidate:!0}}catch(s){let i=s;return s instanceof ea&&(i=s.failures().map(c=>`【${c.path.join(".")}】: ${c.message}
|
|
27
27
|
`)),{isValidate:!1,message:i,error:s}}})({data:e,message:r,throwError:n})};var Lt=(t=>(t.ROOT_CONTAINER="RootContainer",t))(Lt||{});const bh=x({type:F(V.FUNCTION),value:_()}),_h=$r(na(Et,["componentName"]),x({componentName:F("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 ne=Sh(),Ch=(t,e)=>{const r={...t,value:[]},n=t.value;let o=new ht([]);return e&&(o=e.materialsMode||new ht([])),n&&(L(n)?r.value=n.map(a=>new P(a,{parent:e,materials:o})):U(n)&&r.value.push(new P(n,{parent:e,materials:o}))),r};class Nt{constructor(e,r){E(this,"nodeType","SLOT"),E(this,"rawData"),E(this,"parent"),E(this,"emitter",ne),E(this,"data"),E(this,"id"),E(this,"materialsMode"),this.parent=(r==null?void 0:r.parent)||null,this.rawData=e;const n=(r==null?void 0:r.materials)||new ht([]);this.materialsMode=n,this.id=Z(),this.data=Ch(e,this)}get value(){return this.data}export(e){const r=this.data,n=o=>{if(o instanceof P)return o.export(e);if(U(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 ia=t=>{let e=[];return t.forEach(r=>{const n=r;n.type?n.type===Ye.SINGLE?e.push(n.content):n.type===Ye.GROUP&&(e=[...e,...ia(n.content)]):e.push(r)}),e},Ke=(t,e,r)=>{if(t.type)return t.type===V.SLOT?new Nt(t,{parent:e,materials:r}):t;if(U(t)){const n={};return Object.keys(t).forEach(o=>{n[o]=Xe(t[o],e,r)}),n}else return Array.isArray(t)?t.map(n=>Ke(n,e,r)):t},Xe=(t,e,r)=>U(t)?Ke(t,e,r):L(t)?t.map(n=>Ke(n,e,r)):t;class st{constructor(e,r,n){E(this,"nodeType","PROP"),E(this,"rawData"),E(this,"parent"),E(this,"emitter",ne),E(this,"data"),E(this,"name"),E(this,"materialsMode");const o=(n==null?void 0:n.materials)||new ht([]);this.materialsMode=o,this.parent=n==null?void 0:n.parent,this.rawData=r,this.name=e,this.data=Xe(r,this,o)}isIncludeSlot(){return!1}isIncludeExpression(){return!1}get value(){return this.data}updateValue(e){const r=this.data;this.data=Xe(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 P){const r=e.material;return ia((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 st||o instanceof Nt||o instanceof P)return o.export(e);if(L(o))return o.map(a=>n(a));if(U(o)){const a={};return Object.keys(o||{}).forEach(s=>{a[s]=n(o[s])}),a}return o};return n(r)}}const Oh=t=>{if(typeof t=="string")return!0;Ar({data:t,dataStruct:Et,throwError:!1})},Tn=(t,e,r=new ht([]))=>{if(typeof t=="string")return t;const n={...t,id:t.id??Z(),children:[],props:{},methods:t.methods||[],configure:Zo(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 st){n.props[a]=i;return}n.props[a]=new st(a,i||"",{parent:e,materials:r})}),t.children&&(Array.isArray(t.children)?n.children=t.children.map(a=>{if(a instanceof P)return a;if(U(a)){const s=a;return new P(s,{parent:e,materials:r})}else return a}):(t.children instanceof P&&(n.children=[t.children]),n.children=[new P(t.children,{parent:e,materials:r})])),n};class P{constructor(e,r){E(this,"nodeType","NODE"),E(this,"rawData"),E(this,"data"),E(this,"emitter",ne),E(this,"parent"),E(this,"materialsModel"),E(this,"listenerHandle"),E(this,"onChangeCbQueue"),this.rawData=JSON.parse(JSON.stringify(e)),Oh(e);const n=(r==null?void 0:r.materials)||new ht([]);this.parent=(r==null?void 0:r.parent)||null,this.materialsModel=n,this.data=Tn(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||Z()};return new P(r,{materials:this.materialsModel})}updateWithPlainObj(e){const r={...this.data,...e};return this.data=Tn(r,this),r}updateValue(e){const r=this.data,n=this.updateWithPlainObj(e);this.emitter.emit("onNodeChange",{value:n,preValue:r,node:this})}contains(e){return Ir(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(d=>{o[d]=n.props[d].export(e)});const a=(r=n.children)==null?void 0:r.map(d=>d instanceof P?d.export(e):d),s=n.configure||{},i=s.propsSetter||{},c={};Object.keys(i).forEach(d=>{const l=Mo(i,d,!1);l&&(c[d]=l)}),s.propsSetter=c;const f=this.materialsModel.usedMaterials.find(d=>{var l;return d.componentName===((l=this.material)==null?void 0:l.componentName)});this.material&&!f&&this.materialsModel.usedMaterials.push(this.material);let u={...n,configure:s,props:o,children:a,condition:n.condition};return e==="design"&&delete u.id,u=Mr(u),u}}const An=(t,e,r)=>{const n={...t,id:Z(),props:{},componentName:Lt.ROOT_CONTAINER,children:[],methods:t.methods||[],configure:Zo(t.configure||{},{propsSetter:{},advanceSetter:{}})};let o=[];L(t.children)?o=t.children.map(s=>s instanceof P?s:U(s)?new P(s,{parent:e,materials:r}):s):t.children instanceof P?o.push(t.children):t.children&&U(t.children)&&o.push(new P(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 st?n.props[s]=c:n.props[s]=new st(s,c||"",{parent:e,materials:r})}),n.children=o,n};class Kt{constructor(e,{parent:r,materials:n}){E(this,"rawData"),E(this,"data"),E(this,"nodeType",Lt.ROOT_CONTAINER),E(this,"emitter",ne),E(this,"materialsModel"),E(this,"listenerHandle"),E(this,"onChangeCbQueue"),E(this,"parent"),this.materialsModel=n,this.rawData=JSON.parse(JSON.stringify(e)),this.data=An(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=An(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 Ir(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=Rr.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 f;return(f=c==null?void 0:c.export)==null?void 0:f.call(c,e)}))||[],s={...n,props:o,children:a.filter(c=>c),condition:n.condition};let i=ta(s,["id"]);return i=Mr(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||Z()};return new Kt(r,{materials:this.materialsModel,parent:null})}}const ct=t=>(t==null?void 0:t.type)===V.EXPRESSION,ca=t=>(t==null?void 0:t.type)===V.FUNCTION,jh=t=>(t==null?void 0:t.type)===V.ACTION,Z=()=>Math.random().toString(32).slice(3,9),wh=t=>(t==null?void 0:t.nodeType)==="NODE",Ze=t=>(t==null?void 0:t.nodeType)==="PROP",Eh=t=>(t==null?void 0:t.nodeType)==="SLOT",Mr=t=>Qp(t,e=>U(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 P){r.push(i);return}if(i instanceof Nt&&a(i.value.value),i instanceof st){a(i.value);return}if(U(i)){const c=i;Object.keys(c).forEach(f=>{a(c[f])});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 P))||[];r.push(...s)}}function Ir(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}-${Z()}`,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){E(this,"rawData"),E(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 Re=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=>{Ar({data:e,dataStruct:vh,throwError:!1})})};class ht{constructor(e){E(this,"rawData"),E(this,"data"),E(this,"usedMaterials",[]),this.rawData=e,Rh(e),this.data=Re(e)}addMaterials(e){const r=Re(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=Re(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(d=>{const l=d.category||"default";s.includes(l)||(s.push(l),i[l]=[]),i[l].push(d)});const f=[];s.forEach(d=>{i[d].length&&f.push({name:d,list:i[d]})});const u={name:a,list:f};o.push(u)}}),o=o.sort((a,s)=>(a.name||"")>(s.name||"")?1:-1),o}get value(){return this.data}get rawValue(){return this.rawData}}const Th=x({version:_(),name:_(),css:b(_()),renderType:b(k([F("COMPONENT"),F("PAGE")])),loadType:b(R()),lifecycle:b(R()),props:b(R()),methods:b(I(bh)),componentsMeta:I($r(x({componentName:_()}),xr)),thirdLibs:b(uh),componentsTree:_h,assets:b(I(R()))}),ua=t=>(Ar({data:t,dataStruct:Th,throwError:!1}),t),Te=(t,e,r)=>({...t,componentsTree:new Kt(t.componentsTree,{parent:e,materials:r})});class de{constructor(e,r){E(this,"nodeType","PAGE"),E(this,"rawData"),E(this,"emitter",ne),E(this,"data"),E(this,"parent"),E(this,"materialsModel"),E(this,"assetPackagesList"),ua(e),this.rawData=JSON.parse(JSON.stringify(e)),this.materialsModel=new ht((r==null?void 0:r.materials)||[]),this.data=Te(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=Te(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=Te(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 Ir(r,e)}addNode(e,r,n="AFTER"){var o;if(n==="AFTER"||n==="BEFORE"){const a=r.parent;if(a===null&&r instanceof Kt)return console.warn("Not found parent node"),!1;if(a instanceof st)return console.warn("CProp can not add node"),!1;if(a instanceof Nt){const i=a.value.value,c=i.findIndex(f=>f===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 de)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(U(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 P(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=Z();const n=new P(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 P?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 P&&a instanceof P?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 P||n instanceof Kt){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=Rr.SAVE){var r;const n=this.data.componentsTree.export(e),o=this.assetPackagesList,a=[],s=this.materialsModel.usedMaterials.map(c=>{const f=o.find(u=>{var d;return u.package===((d=c.value.npm)==null?void 0:d.package)});return f&&a.push(f),{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:Mr(n),componentsMeta:s,thirdLibs:this.data.thirdLibs,assets:[]};return(r=this.data.thirdLibs)==null||r.forEach(c=>{const f=o.find(u=>c.package===u.package);f&&a.push(f)}),i.assets=th(a,c=>c.package),i=ta(i,["id"]),JSON.parse(JSON.stringify(i))}getRootNode(){return this.data.componentsTree}}Lt.ROOT_CONTAINER;const oe="DYNAMIC",la=["$$context","$$nodeModel"],Pr="ON_DID_RENDER",Dr="ON_WILL_DESTROY",fa=[Pr,Dr],tr=(t,e)=>{let r=t;return e&&(r={...t},r.__proto__=e||null),r},Xt=(t,e={},...r)=>typeof t=="string"||typeof t=="number"?String(t):(la.forEach(o=>{o in e&&t.__CP_TYPE__!==oe&&delete e[o]}),N.createElement(t,e,...r)),Mn=(t={},e)=>{const r=[],n=(o,a)=>{let s=a;Ze(a)&&(s=a.value),e(s)?r.push({keyPath:o,val:s}):Ot(s)?s.forEach((i,c)=>{n([...o,String(c)],i)}):Tt(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 u=f;if(u.type==="RUN_CODE"){const d=te({funcName:"",funcBody:`function() {
|
|
28
|
-
${u.value} }`,nodeContext:n,storeManager:o,$$response:e.$$response,actionVariableSpace:e.actionVariableSpace});let l;e.$$response!==void 0?l=d(e.$$response,...a):l=d(...a),l!=null&&l.then?s[u.id]=await l:s[u.id]=l}if(u.type==="JUMP_LINK"){const l=Ah(u,e)(...a);l!=null&&l.then?s[u.id]=await l:s[u.id]=l}if(u.type==="REQUEST_API"){const{run:d,afterFailedResponse:l,afterSuccessResponse:h}=Mh(u,e);try{const y=d(...a);y!=null&&y.then?s[u.id]=await y:s[u.id]=y,u.responseVarName&&(e.actionVariableSpace[u.responseVarName]=s[u.id]);const p=h(s[u.id],...a);return p!=null&&p.then?await p:p}catch(y){const p=await l(y);return p!=null&&p.then?await p:p}}if(u.type==="CALL_NODE_METHOD"){const l=Ih(u,e)(...a);l!=null&&l.then?s[u.id]=await l:s[u.id]=l,u.returnVarName&&(e.actionVariableSpace[u.returnVarName]=s[u.id])}if(u.type==="ASSIGN_VALUE"){const d=Ph(u,e);let l=[...a];e.$$response!==void 0&&(l=[e.$$response,l]);const h=d(...l);s[u.id]=await h}};let c=r[0];for(;c;)await i(c),c=r.find(u=>(c==null?void 0:c.next)&&u.id===(c==null?void 0:c.next))}};function Ah(t,e){return lt(t.link,e)}const lt=(t,e)=>function(...r){return ct(t)?ut(t.value,e.context):ca(t)?te({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 l,h;let s="";t.apiPath&&(s=lt(t.apiPath,e)(...a));const i=t.body||{};Object.keys(i).forEach(y=>{i[y]=lt(i[y],e)(...a)});const c=t.query||{};Object.keys(c).forEach(y=>{c[y]=lt(c[y],e)(...a)});const f=t.header||{};Object.keys(f).forEach(y=>{f[y]=lt(f[y],e)(...a)});const u=t.method||"GET";return(h=(l=e.context).requestAPI)==null?void 0:h.call(l,{url:s,method:u,header:f,body:i,query:c})},afterSuccessResponse:async(a,...s)=>{if(!t.afterSuccessResponse)return a;const i=[...t.afterSuccessResponse||[],...t.afterFailedResponse||[]];return St({type:"ACTION",handler:i},{...e,$$response:a})(...s)},afterFailedResponse:async(a,...s)=>{if(!t.afterFailedResponse)return a;const i=[...t.afterFailedResponse||[],...t.afterSuccessResponse||[]];return St({type:"ACTION",handler:i},{...e,$$response:a})(...s)}}),Ih=(t,e)=>(...r)=>{const n=te({funcName:"",funcBody:`
|
|
28
|
+
${u.value} }`,nodeContext:n,storeManager:o,$$response:e.$$response,actionVariableSpace:e.actionVariableSpace});let l;e.$$response!==void 0?l=d(e.$$response,...a):l=d(...a),l!=null&&l.then?s[u.id]=await l:s[u.id]=l}if(u.type==="JUMP_LINK"){const l=Ah(u,e)(...a);l!=null&&l.then?s[u.id]=await l:s[u.id]=l}if(u.type==="REQUEST_API"){const{run:d,afterFailedResponse:l,afterSuccessResponse:h}=Mh(u,e);try{const y=d(...a);y!=null&&y.then?s[u.id]=await y:s[u.id]=y,u.responseVarName&&(e.actionVariableSpace[u.responseVarName]=s[u.id]);const p=h(s[u.id],...a);return p!=null&&p.then?await p:p}catch(y){const p=await l(y);return p!=null&&p.then?await p:p}}if(u.type==="CALL_NODE_METHOD"){const l=Ih(u,e)(...a);l!=null&&l.then?s[u.id]=await l:s[u.id]=l,u.returnVarName&&(e.actionVariableSpace[u.returnVarName]=s[u.id])}if(u.type==="ASSIGN_VALUE"){const d=Ph(u,e);let l=[...a];e.$$response!==void 0&&(l=[e.$$response,l]);const h=d(...l);s[u.id]=await h}};let c=r[0];for(;c;)await i(c),c=r.find(u=>(c==null?void 0:c.next)&&u.id===(c==null?void 0:c.next))}};function Ah(t,e){return lt(t.link,e)}const lt=(t,e)=>function(...r){return ct(t)?ut(t.value,{...e.context,nodeContext:e.context,storeManager:e.storeManager,$$response:e.$$response,actionVariableSpace:e.actionVariableSpace}):ca(t)?te({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 l,h;let s="";t.apiPath&&(s=lt(t.apiPath,e)(...a));const i=t.body||{};Object.keys(i).forEach(y=>{i[y]=lt(i[y],e)(...a)});const c=t.query||{};Object.keys(c).forEach(y=>{c[y]=lt(c[y],e)(...a)});const f=t.header||{};Object.keys(f).forEach(y=>{f[y]=lt(f[y],e)(...a)});const u=t.method||"GET";return(h=(l=e.context).requestAPI)==null?void 0:h.call(l,{url:s,method:u,header:f,body:i,query:c})},afterSuccessResponse:async(a,...s)=>{if(!t.afterSuccessResponse)return a;const i=[...t.afterSuccessResponse||[],...t.afterFailedResponse||[]];return St({type:"ACTION",handler:i},{...e,$$response:a})(...s)},afterFailedResponse:async(a,...s)=>{if(!t.afterFailedResponse)return a;const i=[...t.afterFailedResponse||[],...t.afterSuccessResponse||[]];return St({type:"ACTION",handler:i},{...e,$$response:a})(...s)}}),Ih=(t,e)=>(...r)=>{const n=te({funcName:"",funcBody:`
|
|
29
29
|
function () {
|
|
30
30
|
var args = arguments;
|
|
31
31
|
var nodeRef = $$context.nodeRefs.get(${JSON.stringify(t.nodeId)});
|