From b1f2dd376b5ff1f834b602c88bb8c3cc8039cda0 Mon Sep 17 00:00:00 2001 From: Rizky Date: Wed, 17 Jul 2024 21:05:08 +0700 Subject: [PATCH] fix --- app/srv/core/main.js | 2 +- app/web/src/nova/vi/render/script/passprop.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/srv/core/main.js b/app/srv/core/main.js index e588b013..2f57531c 100644 --- a/app/srv/core/main.js +++ b/app/srv/core/main.js @@ -93,7 +93,7 @@ Error generating stack: `+o.message+` ${Ig(e,t.mode)} ${pg(e,t.mode)} ${Ng(e,t.mode)} - `,(t?.hover||t?.active)&&Og({item:e,hover:t?.hover,active:t?.active}),dg(e,t.mode)])}catch(n){console.log(n)}return cx([])};var Lg=P(G()),bo=(e,t,n,r,i)=>{let o=t.item,s;o.component?.style&&(s={style:o.component.style,className:Rf(o.component.style,{mode:e.mode})});let l={className:Rf(o,{mode:e.mode}),inherit:s},c={},u=t.item.childs,a;return t.item.type==="text"?(a=null,l.dangerouslySetInnerHTML={__html:t.item.html||""}):a=Array.isArray(u)&&u?.map(p=>{if(!p)return null;let{id:f}=p,d=n?e.layout?.meta[f]:e.meta[f];return d?(0,Lg.jsx)(en,{meta:d,is_layout:n,passprop:{...r},depth:i+1},f):(p.type==="item"&&p.component?.id&&console.error(`Warning component ${p.name} - ${p.component.id} failed to load.`),null)}),l.children=a,t.item.adv?.html?(delete l.children,l.dangerouslySetInnerHTML={__html:t.item.adv?.html}):t.item.adv?.js&&!t.item.adv.js.includes("children")&&(delete l.children,delete l.dangerouslySetInnerHTML),{props:l,text_props:c}};var Fy=P(_e());var My=P(Vl());var ni={NORMAL:0,WILDCARD:1,PLACEHOLDER:2};function Wl(e={}){let t={options:e,rootNode:Ty(),staticRoutesMap:{}},n=r=>e.strictTrailingSlash?r:r.replace(/\/$/,"")||"/";if(e.routes)for(let r in e.routes)Iy(t,n(r),e.routes[r]);return{ctx:t,lookup:r=>tE(t,n(r)),insert:(r,i)=>Iy(t,n(r),i),remove:r=>nE(t,n(r))}}function tE(e,t){let n=e.staticRoutesMap[t];if(n)return n.data;let r=t.split("/"),i={},o=!1,s=null,l=e.rootNode,c=null;for(let u=0;u1){let f=r.length-u;l=l.placeholderChildren.find(d=>d.maxDepth===f)||null}else l=l.placeholderChildren[0]||null;if(!l)break;l.paramName&&(i[l.paramName]=a),o=!0}else l=p}return(l===null||l.data===null)&&s!==null&&(l=s,i[l.paramName||"_"]=c,o=!0),l?o?{...l.data,params:o?i:void 0}:l.data:null}function Iy(e,t,n){let r=!0,i=t.split("/"),o=e.rootNode,s=0,l=[o];for(let c of i){let u;if(u=o.children.get(c))o=u;else{let a=rE(c);u=Ty({type:a,parent:o}),o.children.set(c,u),a===ni.PLACEHOLDER?(u.paramName=c==="*"?`_${s++}`:c.slice(1),o.placeholderChildren.push(u),r=!1):a===ni.WILDCARD&&(o.wildcardChildNode=u,u.paramName=c.slice(3)||"_",r=!1),l.push(u),o=u}}for(let[c,u]of l.entries())u.maxDepth=Math.max(l.length-c,u.maxDepth||0);return o.data=n,r===!0&&(e.staticRoutesMap[t]=o),o}function nE(e,t){let n=!1,r=t.split("/"),i=e.rootNode;for(let o of r)if(i=i.children.get(o),!i)return n;if(i.data){let o=r.at(-1)||"";i.data=null,Object.keys(i.children).length===0&&i.parent&&(i.parent.children.delete(o),i.parent.wildcardChildNode=null,i.parent.placeholderChildren=[]),n=!0}return n}function Ty(e={}){return{type:e.type||ni.NORMAL,maxDepth:0,parent:e.parent||null,children:new Map,data:e.data||null,paramName:e.paramName||null,wildcardChildNode:null,placeholderChildren:[]}}function rE(e){return e.startsWith("**")?ni.WILDCARD:e[0]===":"||e==="*"?ni.PLACEHOLDER:ni.NORMAL}var iE={id:"",name:"",domain:"",config:{api_url:""},js:"",js_compiled:"",responsive:"",layout:{id:"--",meta:void 0,entry:[]}},oE={id:"",name:"",url:"",snapshot:null,comps:{}};var Ne={active_id:!1,comp_id:!1,instance_comp_id:!1,instance_item_id:!1},ri={should_render_main:!0,hover:{id:""},scope:{},script_nav:{list:[],idx:-1},text:{id:"",content:"",timeout:null,el:null},get item_id(){return Ne.active_id===!1&&(Ne.active_id=localStorage.getItem("prasi-active-id")||""),Ne.active_id||""},set item_id(e){localStorage.setItem("prasi-active-id",e||""),Ne.active_id=e||""},get comp_id(){return Ne.comp_id===!1&&(Ne.comp_id=localStorage.getItem("prasi-comp-id")||""),Ne.comp_id||""},set comp_id(e){localStorage.setItem("prasi-comp-id",e||""),Ne.comp_id=e||""},instance:{get comp_id(){return Ne.instance_comp_id===!1&&(Ne.instance_comp_id=localStorage.getItem("prasi-instance-comp-id")||""),Ne.instance_comp_id||""},set comp_id(e){localStorage.setItem("prasi-instance-comp-id",e||""),Ne.instance_comp_id=e||""},get item_id(){return Ne.instance_item_id===!1&&(Ne.instance_item_id=localStorage.getItem("prasi-instance-item-id")||""),Ne.instance_item_id||""},set item_id(e){localStorage.setItem("prasi-instance-item-id",e||""),Ne.instance_item_id=e||""}}},HI={mode:"",user:{id:"",username:"",client_id:""},clients:{},status:"init",preview:{url_cache:new Set,route_cache:Wl(),page_cache:{},meta_cache:{}},sync:null,sync_assigned:!1,site:Jr(iE),site_tstamp:Date.now(),site_exports:{},site_dts:"",site_dts_entry:{},prisma_ext:"",script:{site_types:{},loaded:!1,do_edit:async(e,t)=>{},db:null,api:null,init_local_effect:{}},page:{history:{id:"",show:!1},root_id:"root",cur:oE,doc:null,list:{},building:!1,meta:{},entry:[],tree:[],render:()=>{}},comp:{doc:null,item:null,loaded:{},list:{},group:{}},code:{},global_prop:[],ui:{monaco:null,comp_editable:localStorage.getItem("prasi-comp-editable")==="yes",zoom:localStorage.zoom||"100%",side:{prop:!0},layout:{left:parseInt(localStorage.getItem("prasi-layout-left")||"250"),right:parseInt(localStorage.getItem("prasi-layout-right")||"250")},prevent_indent_hook:!1,syncing:!1,tree:{item_loading:[],search:"",search_ref:null,search_mode:{Name:!0,JS:!1,HTML:!1,CSS:!1},rename_id:"",open_all:!1,open:{}},popup:{file:{enabled:!1,open:!1,picker:{value:"",on_pick:!1,multi:!1},path:"/",expanded:JSON.parse(localStorage.getItem("panel-file-expanded")||"{}"),entry:{},selected:new Set,action:null,file_renaming:"",file_ctx_menu_event:null,tree:[],tree_renaming:"",tree_ctx_path:"",tree_ctx_menu_event:null,preview:!0,upload:{started:!1,progress:{}}},code:{init:!1,open:!1,name:"site",log:"",loading:!1,rebuilding:!1,startup_status:"init",error:!1,show_log:!1,list:{}},page:{open:null,form:null},script:{open:!1,mode:"js",lastMode:"js",type:"item",prop_kind:"",prop_name:"",on_close:()=>{},typings:{status:"ok",err_msg:""},wb_render:()=>{}},site:null,site_form:null,comp:{preview_id:"",open:null,import:!1},comp_group:null,api:{open:!1}}}};var Gl=e=>({isMobile:e.mode==="mobile",isDesktop:e.mode==="desktop",isEditor:location.pathname.startsWith("/ed/")});var cr=P(_e());var Mn=window;var sE=hf("prasi-cache","prasi-cache-store"),Oy={timeout:null,store:sE},Zl=(e,t)=>{let n=[...Ny(t,"navigate(",")"),...Ny(t,"href = ",";")],r=e.page.cur.id;e.page.navs[r]||(e.page.navs[r]=new Set);for(let i of n)e.page.navs[r].add(i);clearTimeout(Oy.timeout),Oy.timeout=setTimeout(()=>{e.on_nav_loaded&&e.on_nav_loaded({urls:Array.from(e.page.navs[r])})},100)},Ny=(e,t,n)=>{let r=0,i=0,o=[];for(;;){let s=e.indexOf(t,r);if(i=r,s>=0){let l=e[s+t.length];if(l==='"'||l==="'"||l==="`"){let c=e.indexOf(`${l}${n}`,s+t.length+1),u=e.substring(s+t.length+1,c);r=c+2+n.length,o.push(u)}}if(i===r)break}return o};var ur=P(_e());var Py=P(bf()),ar=P(_e());var Mf=P(G()),Ay=(e,t,n,r,i)=>o=>{let[s,l]=(0,ar.useState)({}),c=o.internal_key;n.item.script||(n.item.script={});let u=n.item.script;typeof c<"u"&&(n.item.script_keyed||(n.item.script_keyed={}),n.item.script_keyed[c]||(n.item.script_keyed[c]={}),u=n.item.script_keyed[c]),u.passprop||(u.passprop={});let a={},p=!1;for(let[g,w]of Object.entries(o))["children","key"].includes(g)||(p=!0,a[g]=w);let f={...r,...a};if(typeof c<"u"&&((typeof u.passprop.internal_key>"u"||c===u.passprop.internal_key)&&(u.passprop=f),f=u.passprop),n.editor_props=f,!Array.isArray(o.children)&&(0,ar.isValidElement)(o.children)&&typeof o.children=="object"){let g=(0,Py.default)(o.children,"props.meta.item.component.props.child.content.childs");if(Array.isArray(g)){let w=!0;for(let v of g)!(0,ar.isValidElement)(v)&&typeof v=="object"||(w=!1);if(w)return g.map(v=>{let m=e.meta[v.id];if(m||(e.meta[v.id]={item:v},m=e.meta[v.id]),m){if(Object.keys(m.item).length<=3&&m.mitem){let h={...m.item},y=m.mitem.toJSON();m.item={...y,...h}}return(0,Mf.jsx)(en,{is_layout:t,meta:m,passprop:f,parent_key:o.internal_key,depth:i},v.id)}return null})}}if(!Array.isArray(o.children)&&!(0,ar.isValidElement)(o.children)&&typeof o.children=="object"){let g=o.children.id;if(g){let w=e.meta[g];if(!w){e.meta[g]={item:o.children},w=e.meta[g];let v=w.item.component?.id;v&&e.comp.load(v).then(m=>{if(m){for(let[y,_]of Object.entries(m)){let S=w.item;S[y]||(S[y]=_)}let h=w.item.component?.props;for(let[y,_]of Object.entries(m.component?.props||{}))h[y]||(h[y]=_);l({})}})}return(0,Mf.jsx)(en,{is_layout:t,meta:w,passprop:f,parent_key:o.internal_key,depth:i})}}return zf(o,f,c?{parent_key:c}:void 0)},zf=(e,t,n)=>{let r={};if(Array.isArray(e)?r.children=e:r=e,Array.isArray(r.children)){if(r.children.length===1)return Df(r.children[0],r,t,n);let i=[];for(let o of r.children)i.push(Df(o,r,t,n));return i}return Df(r.children,r,t,n)},Df=(e,t,n,r)=>{if((0,ar.isValidElement)(e)){let i={...t};return delete i.children,{...e,props:{...e.props,...r,passprop:{...n,...i}}}}return e};var ii={},Ly=(e,t,n)=>r=>{let i=(["prasi.avolut.com"].includes(location.hostname)||location.host==="localhost:4550")&&location.pathname.startsWith("/ed/"),o=n.item.id,{children:s,parent_key:l}=r,c=e.script?.init_local_effect,u=t?e.layout?.meta:e.meta,a=(0,ur.useRef)(ii[o]?ii[o]:r.value),[p,f]=(0,ur.useState)({}),d=a.current;return d.render=()=>{window.prasiContext.render?window.prasiContext.render():f({})},Kl(e,n,n.script?.scope,l),r.hook&&r.hook(d),(0,ur.useEffect)(()=>{if(n.parent?.instance_id&&u){let w=u[n.parent?.instance_id];if(w&&w.instances){for(let[v,m]of Object.entries(w.instances[n.parent.instance_id]))if(m===n.item.id){o=v;break}}}return!c[o]&&(typeof c=="object"&&(c[o]=!0),(async()=>r.effect&&(await r.effect(d),i&&(ii[o]=d)))()),()=>{}},[...r.deps||[],location.pathname]),(0,ur.useEffect)(()=>{i&&ii[o]===null&&(async()=>r.effect&&(await r.effect(d),i&&(ii[o]=d)))()},[ii[o]]),zf(s,{...n.script?.scope,[r.name]:d})};var jf=P(Vl()),No=window,oi=(e,t,n)=>{No.prasiEditDevItem||(No.prasiEditDevItem={});let r=No.prasiEditDevItem[n];r||(No.prasiEditDevItem[n]={},r=No.prasiEditDevItem[n]);let i=()=>{let s=t.get("id")||"",l=r[s];return l||(r[s]=[],l=r[s]),l},o=t.toJSON();return{...o,edit:{get props(){if(o.component?.props){let s={};for(let[l,c]of Object.entries(o.component.props))if(c.content){let u=t.get("component")?.get("props")?.get(l)?.get("content");u?s[l]={mode:"jsx",value:oi(e,u,n)}:s[l]={mode:"jsx",value:null}}else{let u=typeof c.valueBuilt=="string"?c.valueBuilt.trim():"";if(u.endsWith(`; + `,(t?.hover||t?.active)&&Og({item:e,hover:t?.hover,active:t?.active}),dg(e,t.mode)])}catch(n){console.log(n)}return cx([])};var Lg=P(G()),bo=(e,t,n,r,i)=>{let o=t.item,s;o.component?.style&&(s={style:o.component.style,className:Rf(o.component.style,{mode:e.mode})});let l={className:Rf(o,{mode:e.mode}),inherit:s},c={},u=t.item.childs,a;return t.item.type==="text"?(a=null,l.dangerouslySetInnerHTML={__html:t.item.html||""}):a=Array.isArray(u)&&u?.map(p=>{if(!p)return null;let{id:f}=p,d=n?e.layout?.meta[f]:e.meta[f];return d?(0,Lg.jsx)(en,{meta:d,is_layout:n,passprop:{...r},depth:i+1},f):(p.type==="item"&&p.component?.id&&console.error(`Warning component ${p.name} - ${p.component.id} failed to load.`),null)}),l.children=a,t.item.adv?.html?(delete l.children,l.dangerouslySetInnerHTML={__html:t.item.adv?.html}):t.item.adv?.js&&!t.item.adv.js.includes("children")&&(delete l.children,delete l.dangerouslySetInnerHTML),{props:l,text_props:c}};var Fy=P(_e());var My=P(Vl());var ni={NORMAL:0,WILDCARD:1,PLACEHOLDER:2};function Wl(e={}){let t={options:e,rootNode:Ty(),staticRoutesMap:{}},n=r=>e.strictTrailingSlash?r:r.replace(/\/$/,"")||"/";if(e.routes)for(let r in e.routes)Iy(t,n(r),e.routes[r]);return{ctx:t,lookup:r=>tE(t,n(r)),insert:(r,i)=>Iy(t,n(r),i),remove:r=>nE(t,n(r))}}function tE(e,t){let n=e.staticRoutesMap[t];if(n)return n.data;let r=t.split("/"),i={},o=!1,s=null,l=e.rootNode,c=null;for(let u=0;u1){let f=r.length-u;l=l.placeholderChildren.find(d=>d.maxDepth===f)||null}else l=l.placeholderChildren[0]||null;if(!l)break;l.paramName&&(i[l.paramName]=a),o=!0}else l=p}return(l===null||l.data===null)&&s!==null&&(l=s,i[l.paramName||"_"]=c,o=!0),l?o?{...l.data,params:o?i:void 0}:l.data:null}function Iy(e,t,n){let r=!0,i=t.split("/"),o=e.rootNode,s=0,l=[o];for(let c of i){let u;if(u=o.children.get(c))o=u;else{let a=rE(c);u=Ty({type:a,parent:o}),o.children.set(c,u),a===ni.PLACEHOLDER?(u.paramName=c==="*"?`_${s++}`:c.slice(1),o.placeholderChildren.push(u),r=!1):a===ni.WILDCARD&&(o.wildcardChildNode=u,u.paramName=c.slice(3)||"_",r=!1),l.push(u),o=u}}for(let[c,u]of l.entries())u.maxDepth=Math.max(l.length-c,u.maxDepth||0);return o.data=n,r===!0&&(e.staticRoutesMap[t]=o),o}function nE(e,t){let n=!1,r=t.split("/"),i=e.rootNode;for(let o of r)if(i=i.children.get(o),!i)return n;if(i.data){let o=r.at(-1)||"";i.data=null,Object.keys(i.children).length===0&&i.parent&&(i.parent.children.delete(o),i.parent.wildcardChildNode=null,i.parent.placeholderChildren=[]),n=!0}return n}function Ty(e={}){return{type:e.type||ni.NORMAL,maxDepth:0,parent:e.parent||null,children:new Map,data:e.data||null,paramName:e.paramName||null,wildcardChildNode:null,placeholderChildren:[]}}function rE(e){return e.startsWith("**")?ni.WILDCARD:e[0]===":"||e==="*"?ni.PLACEHOLDER:ni.NORMAL}var iE={id:"",name:"",domain:"",config:{api_url:""},js:"",js_compiled:"",responsive:"",layout:{id:"--",meta:void 0,entry:[]}},oE={id:"",name:"",url:"",snapshot:null,comps:{}};var Ne={active_id:!1,comp_id:!1,instance_comp_id:!1,instance_item_id:!1},ri={should_render_main:!0,hover:{id:""},scope:{},script_nav:{list:[],idx:-1},text:{id:"",content:"",timeout:null,el:null},get item_id(){return Ne.active_id===!1&&(Ne.active_id=localStorage.getItem("prasi-active-id")||""),Ne.active_id||""},set item_id(e){localStorage.setItem("prasi-active-id",e||""),Ne.active_id=e||""},get comp_id(){return Ne.comp_id===!1&&(Ne.comp_id=localStorage.getItem("prasi-comp-id")||""),Ne.comp_id||""},set comp_id(e){localStorage.setItem("prasi-comp-id",e||""),Ne.comp_id=e||""},instance:{get comp_id(){return Ne.instance_comp_id===!1&&(Ne.instance_comp_id=localStorage.getItem("prasi-instance-comp-id")||""),Ne.instance_comp_id||""},set comp_id(e){localStorage.setItem("prasi-instance-comp-id",e||""),Ne.instance_comp_id=e||""},get item_id(){return Ne.instance_item_id===!1&&(Ne.instance_item_id=localStorage.getItem("prasi-instance-item-id")||""),Ne.instance_item_id||""},set item_id(e){localStorage.setItem("prasi-instance-item-id",e||""),Ne.instance_item_id=e||""}}},HI={mode:"",user:{id:"",username:"",client_id:""},clients:{},status:"init",preview:{url_cache:new Set,route_cache:Wl(),page_cache:{},meta_cache:{}},sync:null,sync_assigned:!1,site:Jr(iE),site_tstamp:Date.now(),site_exports:{},site_dts:"",site_dts_entry:{},prisma_ext:"",script:{site_types:{},loaded:!1,do_edit:async(e,t)=>{},db:null,api:null,init_local_effect:{}},page:{history:{id:"",show:!1},root_id:"root",cur:oE,doc:null,list:{},building:!1,meta:{},entry:[],tree:[],render:()=>{}},comp:{doc:null,item:null,loaded:{},list:{},group:{}},code:{},global_prop:[],ui:{monaco:null,comp_editable:localStorage.getItem("prasi-comp-editable")==="yes",zoom:localStorage.zoom||"100%",side:{prop:!0},layout:{left:parseInt(localStorage.getItem("prasi-layout-left")||"250"),right:parseInt(localStorage.getItem("prasi-layout-right")||"250")},prevent_indent_hook:!1,syncing:!1,tree:{item_loading:[],search:"",search_ref:null,search_mode:{Name:!0,JS:!1,HTML:!1,CSS:!1},rename_id:"",open_all:!1,open:{}},popup:{file:{enabled:!1,open:!1,picker:{value:"",on_pick:!1,multi:!1},path:"/",expanded:JSON.parse(localStorage.getItem("panel-file-expanded")||"{}"),entry:{},selected:new Set,action:null,file_renaming:"",file_ctx_menu_event:null,tree:[],tree_renaming:"",tree_ctx_path:"",tree_ctx_menu_event:null,preview:!0,upload:{started:!1,progress:{}}},code:{init:!1,open:!1,name:"site",log:"",loading:!1,rebuilding:!1,startup_status:"init",error:!1,show_log:!1,list:{}},page:{open:null,form:null},script:{open:!1,mode:"js",lastMode:"js",type:"item",prop_kind:"",prop_name:"",on_close:()=>{},typings:{status:"ok",err_msg:""},wb_render:()=>{}},site:null,site_form:null,comp:{preview_id:"",open:null,import:!1},comp_group:null,api:{open:!1}}}};var Gl=e=>({isMobile:e.mode==="mobile",isDesktop:e.mode==="desktop",isEditor:location.pathname.startsWith("/ed/")});var cr=P(_e());var Mn=window;var sE=hf("prasi-cache","prasi-cache-store"),Oy={timeout:null,store:sE},Zl=(e,t)=>{let n=[...Ny(t,"navigate(",")"),...Ny(t,"href = ",";")],r=e.page.cur.id;e.page.navs[r]||(e.page.navs[r]=new Set);for(let i of n)e.page.navs[r].add(i);clearTimeout(Oy.timeout),Oy.timeout=setTimeout(()=>{e.on_nav_loaded&&e.on_nav_loaded({urls:Array.from(e.page.navs[r])})},100)},Ny=(e,t,n)=>{let r=0,i=0,o=[];for(;;){let s=e.indexOf(t,r);if(i=r,s>=0){let l=e[s+t.length];if(l==='"'||l==="'"||l==="`"){let c=e.indexOf(`${l}${n}`,s+t.length+1),u=e.substring(s+t.length+1,c);r=c+2+n.length,o.push(u)}}if(i===r)break}return o};var ur=P(_e());var Py=P(bf()),ar=P(_e());var Mf=P(G()),Ay=(e,t,n,r,i)=>o=>{let[s,l]=(0,ar.useState)({}),c=o.idx||o.internal_key;n.item.script||(n.item.script={});let u=n.item.script;typeof c<"u"&&(n.item.script_keyed||(n.item.script_keyed={}),n.item.script_keyed[c]||(n.item.script_keyed[c]={}),u=n.item.script_keyed[c]),u.passprop||(u.passprop={});let a={},p=!1;for(let[g,w]of Object.entries(o))["children","key"].includes(g)||(p=!0,a[g]=w);let f={...r,...a};if(typeof c<"u"&&((typeof u.passprop.internal_key>"u"||c===u.passprop.internal_key)&&(u.passprop=f),f=u.passprop),n.editor_props=f,!Array.isArray(o.children)&&(0,ar.isValidElement)(o.children)&&typeof o.children=="object"){let g=(0,Py.default)(o.children,"props.meta.item.component.props.child.content.childs");if(Array.isArray(g)){let w=!0;for(let v of g)!(0,ar.isValidElement)(v)&&typeof v=="object"||(w=!1);if(w)return g.map(v=>{let m=e.meta[v.id];if(m||(e.meta[v.id]={item:v},m=e.meta[v.id]),m){if(Object.keys(m.item).length<=3&&m.mitem){let h={...m.item},y=m.mitem.toJSON();m.item={...y,...h}}return(0,Mf.jsx)(en,{is_layout:t,meta:m,passprop:f,parent_key:o.internal_key,depth:i},v.id)}return null})}}if(!Array.isArray(o.children)&&!(0,ar.isValidElement)(o.children)&&typeof o.children=="object"){let g=o.children.id;if(g){let w=e.meta[g];if(!w){e.meta[g]={item:o.children},w=e.meta[g];let v=w.item.component?.id;v&&e.comp.load(v).then(m=>{if(m){for(let[y,_]of Object.entries(m)){let S=w.item;S[y]||(S[y]=_)}let h=w.item.component?.props;for(let[y,_]of Object.entries(m.component?.props||{}))h[y]||(h[y]=_);l({})}})}return(0,Mf.jsx)(en,{is_layout:t,meta:w,passprop:f,parent_key:o.internal_key,depth:i})}}return zf(o,f,c?{parent_key:c}:void 0)},zf=(e,t,n)=>{let r={};if(Array.isArray(e)?r.children=e:r=e,Array.isArray(r.children)){if(r.children.length===1)return Df(r.children[0],r,t,n);let i=[];for(let o of r.children)i.push(Df(o,r,t,n));return i}return Df(r.children,r,t,n)},Df=(e,t,n,r)=>{if((0,ar.isValidElement)(e)){let i={...t};return delete i.children,{...e,props:{...e.props,...r,passprop:{...n,...i}}}}return e};var ii={},Ly=(e,t,n)=>r=>{let i=(["prasi.avolut.com"].includes(location.hostname)||location.host==="localhost:4550")&&location.pathname.startsWith("/ed/"),o=n.item.id,{children:s,parent_key:l}=r,c=e.script?.init_local_effect,u=t?e.layout?.meta:e.meta,a=(0,ur.useRef)(ii[o]?ii[o]:r.value),[p,f]=(0,ur.useState)({}),d=a.current;return d.render=()=>{window.prasiContext.render?window.prasiContext.render():f({})},Kl(e,n,n.script?.scope,l),r.hook&&r.hook(d),(0,ur.useEffect)(()=>{if(n.parent?.instance_id&&u){let w=u[n.parent?.instance_id];if(w&&w.instances){for(let[v,m]of Object.entries(w.instances[n.parent.instance_id]))if(m===n.item.id){o=v;break}}}return!c[o]&&(typeof c=="object"&&(c[o]=!0),(async()=>r.effect&&(await r.effect(d),i&&(ii[o]=d)))()),()=>{}},[...r.deps||[],location.pathname]),(0,ur.useEffect)(()=>{i&&ii[o]===null&&(async()=>r.effect&&(await r.effect(d),i&&(ii[o]=d)))()},[ii[o]]),zf(s,{...n.script?.scope,[r.name]:d})};var jf=P(Vl()),No=window,oi=(e,t,n)=>{No.prasiEditDevItem||(No.prasiEditDevItem={});let r=No.prasiEditDevItem[n];r||(No.prasiEditDevItem[n]={},r=No.prasiEditDevItem[n]);let i=()=>{let s=t.get("id")||"",l=r[s];return l||(r[s]=[],l=r[s]),l},o=t.toJSON();return{...o,edit:{get props(){if(o.component?.props){let s={};for(let[l,c]of Object.entries(o.component.props))if(c.content){let u=t.get("component")?.get("props")?.get(l)?.get("content");u?s[l]={mode:"jsx",value:oi(e,u,n)}:s[l]={mode:"jsx",value:null}}else{let u=typeof c.valueBuilt=="string"?c.valueBuilt.trim():"";if(u.endsWith(`; `)&&(u=u.substring(0,u.length-2)),u&&u===c.value.trim()){let a=new Function(`return ${c.value}`);s[l]={mode:"string",value:a()}}else s[l]={mode:"raw",value:c.value,valueBuilt:c.valueBuilt}}return s}},get pending(){return[]},async commit(){let s={},l={};if(t){for(let[c,u]of Object.entries(r)){let a=e[c];if(!a||!a.mitem)continue;let f=a.mitem.toJSON();if(f&&f.component){let d=f?.component?.props;if(!d){console.log(f,d);return}let g={};for(let v of u)if(v.type==="prop"&&d)d[v.name]&&(v.mode==="string"?(d[v.name].value=JSON.stringify(v.value),d[v.name].valueBuilt=JSON.stringify(v.value)):v.mode==="raw"?(d[v.name].value=v.value,v.valueBuilt?d[v.name].valueBuilt=v.valueBuilt:g[v.name]=v.value):v.mode==="jsx"&&(d[v.name]||(d[v.name]={meta:{type:"content-element"}}),v.value&&(d[v.name].content=si([v.value],l)[0])));else if(v.type==="set"&&typeof v.value=="object")for(let[m,h]of Object.entries(v.value))f[m]=h;else if(v.type==="child"&&Array.isArray(v.childs))if(f.component?.id)f.component.props||(f.component.props={}),f.component.props.child={meta:{type:"content-element"},content:{type:"item",id:(0,jf.createId)(),name:"child",childs:si(v.childs.filter(m=>m),l)}};else{let m=si(v.childs.filter(h=>h),l);f.childs=m}for(let[v,m]of Object.entries(l))g[v]=m.value;let w=await _api.code_build(g);if(d)for(let[v,m]of Object.entries(w))d[v]?d[v].valueBuilt=m:l[v]&&(l[v].valueBuilt=m);s[c]=f}}t.doc?.transact(()=>{for(let[c,u]of Object.entries(s)){let a=e[c];a.mitem&&syncronize(a.mitem,u)}})}},setValue(s,l){let c=i(),u=l;if(s==="childs")throw new Error("Please modify childs via .child");c.push({type:"set",name:s,value:u})},setProp(s,l){let c=i();typeof l=="string"?c.push({type:"prop",mode:"string",name:s,value:l}):l.mode==="string"?c.push({type:"prop",mode:"string",name:s,value:l.value}):l.mode==="raw"?c.push({type:"prop",mode:"raw",name:s,value:l.value,valueBuilt:l.valueBuilt}):l.mode==="jsx"&&c.push({type:"prop",mode:"jsx",name:s,value:l.value})},setChilds(s){i().push({type:"child",childs:s})},get childs(){let s=t?.toJSON();if(s.component?.id){if((s.component?.props.child).content){let c=t.get("component")?.get("props")?.get("child")?.get("content");if(c)return[oi(e,c,n)]}return[]}return s.childs?s.childs.map(l=>{if(l){let c=e[l.id];if(c&&c.mitem)return oi(e,c.mitem,n)}}).filter(l=>l):[]},get parent(){if(t){let s=t.parent.toJSON();if(Array.isArray(s)){let l=(t.parent?.parent).get("id"),c=e[l].mitem;if(c)return{item:oi(e,c,n),child_type:"child",child_idx:s.findIndex(u=>u.id===o.id)}}}return null}}}},lE=(e,t)=>{let n={};for(let[r,i]of Object.entries(e))i.mode?i.mode==="string"?n[r]={value:JSON.stringify(i.value),valueBuilt:JSON.stringify(i.value),meta:{type:"text"}}:i.mode==="jsx"&&i.value?n[r]={value:"",valueBuilt:"",content:si([i.value],t)[0],meta:{type:"content-element"}}:i.mode==="raw"&&(n[r]={value:i.value,valueBuilt:i.valueBuilt,meta:{type:"text"}}):n[r]=i;return n},si=(e,t)=>{let n=t||{};return e.map(i=>{let o={...i};if(delete o.edit,o.id||(o.id=(0,jf.createId)()),o.component&&(o.component.instances||(o.component.instances={}),o.component.ref_ids||(o.component.ref_ids={}),o.component?.props)){o.component.props=lE(o.component.props,n);for(let[s,l]of Object.entries(o.component.props))!l.valueBuilt&&l.value&&(n[o.id+"|||"+s]=l),l.content&&(l.content=si([l.content],n)[0])}return o.childs?o.childs=si(o.childs,n):o.childs=[],o})};var li=(e,t,n)=>({...t,edit:{setChilds(r){},get childs(){if(t.component?.id){let r=t.component?.props.child;return r.content?[li(e,r.content,n)]:[]}return t.childs?t.childs.map(r=>{if(r){let i=e[r.id];if(i&&i.item)return li(e,i.item,n)}}).filter(r=>r):[]},get props(){if(t.component?.props){let r={};for(let[i,o]of Object.entries(t.component.props))if(o.content){let s=t.component?.props?.[i]?.content;s?r[i]={mode:"jsx",value:li(e,s,n)}:r[i]={mode:"jsx",value:null}}else{let s=typeof o.valueBuilt=="string"?o.valueBuilt.trim():"";if(s.endsWith(`; `)&&(s=s.substring(0,s.length-2)),s&&s===o.value.trim()){let l=new Function(`return ${o.value}`);r[i]={mode:"string",value:l()}}else r[i]={mode:"raw",value:o.value,valueBuilt:o.valueBuilt}}return r}},async commit(){},get parent(){let r=e[t.id];if(r&&r.parent?.id){let i=e[r.parent.id];return li(e,i.item,n)}return null},pending:[],setProp(r,i){},setValue(r,i){}}});var Ff=P(G()),Dy=(e,t,n,r,i,o)=>{let s=bo(e,t,n,r,i);e.visit&&e.visit(t,s),t.script?t.script.scope=r:t.script={scope:r,result:null,Local:Ly(e,n,t),PassProp:Ay(e,n,t,r,i)};let l=t.script,c=window.exports,u={useEffect:cr.useEffect,children:s.props.children,props:s.props,Local:l?.Local,db:e.site.db,api:e.site.api,PassProp:l?.PassProp,ErrorBox:Nt,newElement:()=>{},__props:r,_item:t.mitem?oi(e.meta,t.mitem,e.page.cur.id):li(e.meta,t.item,e.page.cur.id),_meta:e.meta,render:d=>{let g=d;if((0,cr.isValidElement)(d)&&d.props.children){let w=m=>{let h=!1,y=[];if((0,cr.isValidElement)(m)){if(m.type===t.script?.PassProp)return{should_replace:!0,el:{...m,props:{...m.props,internal_key:m.key}}};if(Array.isArray(m.props?.children))for(let _ of m.props?.children)if(Array.isArray(_)){let S=[],R=!1;for(let k of _){let E=w(k);E.should_replace?(S.push(E.el),R=!0):S.push(k)}R?(h=!0,y.push(S)):y.push(_)}else typeof _=="object"&&_?_.type===t.script?.PassProp&&(h=!0,y.push({..._,props:{..._.props,internal_key:_.props.key}})):y.push(_)}return{should_replace:h,el:{...m,props:{...m.props,children:y}}}},v=w(d);v.should_replace&&(g=v.el)}l&&(l.result=(0,Ff.jsx)(cr.Suspense,{children:g}))},params,...Gl(e),...c,...r};if(typeof r=="object"){for(let[d,g]of Object.entries(r))if(typeof g=="object"&&g&&g._jsx){let w=g;u[d]=(0,Ff.jsx)(aE,{fn:w.fn,passprop:{...r},meta:t})}}!Mn.isEditor&&t.item.adv?.js&&Zl(e,t.item.adv.js);let a=t.item.adv?.jsBuilt||"",p=Bf(a,Uf)||"",f=`// ${t.item.name}: ${t.item.id} try { diff --git a/app/web/src/nova/vi/render/script/passprop.tsx b/app/web/src/nova/vi/render/script/passprop.tsx index fb6672c8..791a0e71 100644 --- a/app/web/src/nova/vi/render/script/passprop.tsx +++ b/app/web/src/nova/vi/render/script/passprop.tsx @@ -15,7 +15,7 @@ export const createViPassProp = ( arg: Record & { children: ReactNode; internal_key: any } ) => { const [_, render] = useState({}); - const internal_key = arg.internal_key; + const internal_key = arg.idx || arg.internal_key; if (!meta.item.script) { meta.item.script = {};