import{A as g,a as m,_ as v}from"./plugin-vue_export-helper.8f6f5b47.js";const h="modulepreload",f={},w="/runtime/",E=function(s,c){return!c||c.length===0?s():Promise.all(c.map(r=>{if(r=`${w}${r}`,r in f)return;f[r]=!0;const t=r.endsWith(".css"),i=t?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${r}"]${i}`))return;const e=document.createElement("link");if(e.rel=t?"stylesheet":h,t||(e.as="script",e.crossOrigin=""),e.href=r,document.head.appendChild(e),t)return new Promise((n,u)=>{e.addEventListener("load",n),e.addEventListener("error",()=>u(new Error(`Unable to preload CSS for ${r}`)))})})).then(()=>s())};const _=Vue.defineComponent({setup(){const o=Vue.ref(),s=Vue.ref(),c=Vue.ref(),r=Vue.computed(()=>{var i,e,n,u;return((e=(i=o.value)==null?void 0:i.items)==null?void 0:e.find(a=>a.id===s.value))||((u=(n=o.value)==null?void 0:n.items)==null?void 0:u[0])}),t=new g({config:o.value,platform:"editor"});return Vue.provide("app",t),Vue.watch(r,async()=>{await Vue.nextTick();const i=document.querySelector(".magic-ui-page");i&&window.magic.onPageElUpdate(i)}),Vue.onMounted(()=>{var i;(i=window.magic)==null||i.onRuntimeReady({getApp(){return t},updateRootConfig(e){console.log("update config",e),o.value=e,t==null||t.setConfig(e,s.value)},updatePageId(e){console.log("update page id",e),s.value=e,t==null||t.setPage(e)},getSnapElements(){return Array.from(document.querySelectorAll("[class*=magic-ui][id]"))},select(e){console.log("select config",e),c.value=e;const n=document.getElementById(`${e}`);return n||Vue.nextTick().then(()=>document.getElementById(`${e}`))},add({config:e}){var l;if(console.log("add config",e),!o.value)throw new Error("error");if(!c.value)throw new Error("error");const n=m(c.value,[o.value]),u=n.pop(),a=u!=null&&u.items?u:n.pop();if(!a)throw new Error("\u672A\u627E\u5230\u7236\u8282\u70B9");(l=a.items)==null||l.push(e)},update({config:e}){var p;if(console.log("update config",e),!o.value)throw new Error("error");const n=m(e.id,[o.value]),u=n.pop(),a=n.pop();if(!u)throw new Error("\u672A\u627E\u5230\u76EE\u6807\u8282\u70B9");if(!a)throw new Error("\u672A\u627E\u5230\u7236\u8282\u70B9");const l=(p=a.items)==null?void 0:p.findIndex(d=>d.id===u.id);a.items.splice(l,1,Vue.reactive(e))},remove({id:e}){var p;if(!o.value)throw new Error("error");const n=m(e,[o.value]),u=n.pop();if(!u)throw new Error("\u672A\u627E\u5230\u76EE\u6807\u5143\u7D20");const a=n.pop();if(!a)throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");const l=(p=a.items)==null?void 0:p.findIndex(d=>d.id===u.id);a.items.splice(l,1)}})}),{pageConfig:r}}});function V(o,s,c,r,t,i){const e=Vue.resolveComponent("magic-ui-page");return o.pageConfig?(Vue.openBlock(),Vue.createBlock(e,{key:0,config:o.pageConfig},null,8,["config"])):Vue.createCommentVNode("v-if",!0)}var A=v(_,[["render",V],["__file","/data/magic/tmagic-editor/runtime/vue3/src/playground/App.vue"]]);E(()=>import("./comp-entry.d785a88e.js"),["assets/comp-entry.d785a88e.js","assets/plugin-vue_export-helper.8f6f5b47.js"]).then(o=>{const{components:s,plugins:c}=o.default,r=Vue.createApp(A);Object.values(s).forEach(t=>{r.component(t.name,t)}),Object.values(c).forEach(t=>{r.use(t)}),r.mount("#app")});
//# sourceMappingURL=playground.js.map
