@vtj/core 0.13.13 → 0.13.14

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
@@ -2,6 +2,6 @@
2
2
  * Copyright (c) 2025, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/core
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.13.13
5
+ * @version 0.13.14
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const U="0.13.13",G="BuiltIn",R="VueMaterial",B="VueRouterMaterial",J=[R,B],w={vue:"Vue","vue-router":"VueRouter"},F={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[B]:["RouterView","RouterLink"]},j=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class M{}class ${listeners=[];isReady=!1;triggerReady(){this.isReady=!0;for(const e of this.listeners)e();this.listeners=[]}ready(e){this.isReady?e():this.listeners.push(e)}resetReady(){this.isReady=!1}}class v{constructor(e,t,i){this.name=e,this.value=t,this.defaultValue=i,this.setValue(t)}isUnset=!1;setValue(e){this.value=e,this.isUnset=this.value===this.defaultValue}getValue(){return this.value??this.defaultValue}static toDsl(e={}){return Object.entries(e).reduce((t,[i,s])=>(s.isUnset||(t[i]=s.getValue()),t),{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new v(i,s),t),{})}}class y{constructor(e){this.schema=e;const{name:t,handler:i}=this.schema;this.name=t,this.handler=i,this.update(e)}name;handler;modifiers={};update(e){Object.assign(this.schema,e);const{handler:t,modifiers:i={}}=this.schema;this.handler=t,this.modifiers=i}static toDsl(e){return Object.entries(e).reduce((t,[i,s])=>{const{handler:a,modifiers:o}=s;return t[i]={name:i,handler:a,modifiers:o},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new y(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||r.uid(),this.update(e)}id;name="";arg;modifiers;value;iterator;update(e){Object.assign(this.schema,e);const{name:t,arg:i,modifiers:s,value:a,iterator:o}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=a,this.iterator=o}static parse(e=[]){return e.map(t=>new E(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:a,value:o,iterator:c,id:f}=t;return{id:f,name:i,arg:s,modifiers:a,value:o,iterator:c}})}}const h="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=r.uid(),name:s,from:a=""}=e;this.id=i,this.name=s,this.from=a,this.update(e,!0),_.nodes[this.id]=this}__VTJ_NODE__=!0;locked=!1;static nodes={};id;name;from;invisible=!1;children="";slot;props={};events={};directives=[];disposed=!1;update(e,t=!1){const{invisible:i=!1,locked:s=!1,children:a=[],slot:o,props:c={},events:f={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(a,!0),this.setSlot(o,!0),this.props=v.parse(c),this.events=y.parse(f),this.directives=E.parse(p),t||n.emit(h,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new _(i,this)):this.children=e,t||n.emit(h,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(h,this)}setProp(e,t,i,s=!1){const a=this.props[e];a?a.setValue(t):this.props[e]=new v(e,t,i),s||n.emit(h,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(h,this)}getPropValue(e){const t=this.props[e];if(t)return t.getValue()}setEvent(e,t=!1){const i=this.events[e.name];i?i.update(e):this.events[e.name]=new y(e),t||n.emit(h,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(h,this)}setDirective(e,t=!1){const i=e instanceof E?e:new E(e),s=this.directives.findIndex(a=>a.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||n.emit(h,this)}removeDirective(e,t=!1){const i=this.directives.findIndex(s=>s===e||s.id===e.id);i>=0&&this.directives.splice(i,1),t||n.emit(h,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const a=i.findIndex(o=>o===e);e.parent=null,i.splice(a,1),t||n.emit(h,this)}appendChild(e,t=!1){const{children:i,disposed:s}=this;s||(e.parent=this,Array.isArray(i)?i.push(e):this.children=[e],t||n.emit(h,this))}insertAfter(e,t=!1){if(!this.parent)return;const i=this.parent.children;if(Array.isArray(i)){e.parent=this.parent;const s=i.indexOf(this);i.splice(s+1,0,e),t||n.emit(h,this.parent)}}insertBefore(e,t=!1){if(!this.parent)return;const i=this.parent.children;if(Array.isArray(i)){e.parent=this.parent;const s=i.indexOf(this);i.splice(s,0,e),t||n.emit(h,this.parent)}}movePrev(e=!1){const t=this.parent;if(!t)return;const i=t.children;if(Array.isArray(i)){const s=i.indexOf(this);s>0&&(i.splice(s,1),i.splice(s-1,0,this),e||n.emit(h,t))}}moveNext(e=!1){const t=this.parent;if(!t)return;const i=t.children;if(Array.isArray(i)){const s=i.indexOf(this);s>-1&&s<i.length-1&&(i.splice(s,1),i.splice(s+1,0,this),e||n.emit(h,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:c,props:f,directives:p,events:O}=this,T=Array.isArray(c)?c.map(L=>L.toDsl()):c;return{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:T,props:v.toDsl(f),directives:E.toDsl(p),events:y.toDsl(O)}}dispose(e=!1){const{children:t,disposed:i}=this;i||(Array.isArray(t)&&t.forEach(s=>s.dispose(!0)),this.parent?this.parent.removeChild(this,e):e||n.emit(h,this),this.parent=null,this.disposed=!0,delete _.nodes[this.id])}lock(e=!1){if(this.locked=!0,Array.isArray(this.children))for(const t of this.children)t.lock(!0);e||n.emit(h,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(h,this)}setVisible(e,t=!1){if(this.invisible=!e,Array.isArray(this.children))for(const i of this.children)i.setVisible(e,!0);t||n.emit(h,this)}isChild(e){let t=!1;if(Array.isArray(this.children)){for(const i of this.children)if(e===i||e.id===i.id){t=!0;break}else if(t=i.isChild(e),t)break}return t}}const d="EVENT_BLOCK_CHANGE";class u{__VTJ_BLOCK__=!0;id;name="";inject=[];state={};lifeCycles={};methods={};computed={};watch=[];css="";props=[];emits=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","inject","state","lifeCycles","methods","computed","watch","css","props","emits","slots","dataSources","__TEMPLATE_ID__"];constructor(e){const{id:t}=e;this.id=t||r.uid(),this.update(e,!0)}update(e,t=!1){for(const s of u.normalAttrs){const a=e[s];a!==void 0&&(this[s]=a)}const{nodes:i=[]}=e;i.length?this.nodes=i.map(s=>new _(s)):this.nodes=[],t||n.emit(d,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((o,c)=>(o[c]=this[c],o),{}),__VTJ_BLOCK__:t,__VERSION__:e||r.timestamp().toString(),id:i,nodes:s.map(o=>o.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}setFunction(e,t,i,s=!1){this[e][t]=i,s||n.emit(d,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(d,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(d,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(d,this)}setCss(e,t=!1){this.css=e,t||n.emit(d,this)}setWatch(e,t=!1){e.id=e.id||r.uid();const i=this.watch.findIndex(s=>s.id&&s.id===e.id||s===e);i>-1?this.watch.splice(i,1,e):this.watch.push(e),t||n.emit(d,this)}removeWatch(e,t=!1){const i=this.watch.findIndex(s=>s.id&&s.id===e.id||s===e);i>-1&&(this.watch.splice(i,1),t||n.emit(d,this))}setProp(e,t=!1){const i=this.props.findIndex(s=>typeof s=="string"?s===e.name:s.name===e.name);i>-1?this.props.splice(i,1,e):this.props.push(e),t||n.emit(d,this)}removeProp(e,t=!1){const i=this.props.findIndex(s=>typeof s=="string"?s===e.name:s.name===e.name);i>-1&&(this.props.splice(i,1),t||n.emit(d,this))}setEmit(e,t=!1){const i=r.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(a=>a===i.name||a.name===i.name);s>-1?this.emits.splice(s,1,i):this.emits.push(i),t||n.emit(d,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>r.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||n.emit(d,this))}setSlot(e,t=!1){const i=r.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(a=>a===i.name||a.name===i.name);s>-1?this.slots.splice(s,1,i):this.slots.push(i),t||n.emit(d,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>r.isString(s)?s===e:s.name===e);i>-1&&(this.slots.splice(i,1),t||n.emit(d,this))}setInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1?this.inject.splice(i,1,e):this.inject.push(e),t||n.emit(d,this)}removeInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1&&(this.inject.splice(i,1),t||n.emit(d,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(d,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(d,this)}insertAfter(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s+1,0,e),i||n.emit(d,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(d,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(d,this)}addNode(e,t,i="inner",s=!1){t?["left","top"].includes(i)?t.parent?t.insertAfter(e,s):this.insertBefore(e,t,s):["right","bottom"].includes(i)?t.parent?t.insertAfter(e,s):this.insertAfter(e,t,s):t.appendChild(e,s):this.appendNode(e,s)}__removeNode(e,t=!1){const i=this.nodes.findIndex(s=>s.id===e.id);i>-1&&(this.nodes.splice(i,1),t||n.emit(d,this))}removeNode(e,t=!1){e.parent?e.dispose(t):(e.dispose(!0),this.__removeNode(e,t))}move(e,t,i="inner",s=!1){e.parent?e.parent.removeChild(e,!0):this.__removeNode(e,!0),this.addNode(e,t,i,s)}movePrev(e,t=!1){if(e.parent)e.movePrev(t);else{const i=this.nodes,s=i.indexOf(e);s>0&&(i.splice(s,1),i.splice(s-1,0,e),t||n.emit(d,this))}}moveNext(e,t=!1){if(e.parent)e.moveNext(t);else{const i=this.nodes,s=i.indexOf(e);s>-1&&s<i.length-1&&(i.splice(s,1),i.splice(s+1,0,e),t||n.emit(d,this))}}cloneNode(e,t=!1){const i=D(e.toDsl()),s=new _(i);return this.addNode(s,e,"bottom",t),s}lock(e=!1){this.locked=!0;for(const t of this.nodes)t.lock(!0);e||n.emit(d,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(d,this)}isChild(e){let t=!1;for(const i of this.nodes)if(e===i||e.id===i.id){t=!0;break}else if(t=i.isChild(e),t)break;return t}}const l="EVENT_PROJECT_CHANGE",P="EVENT_PROJECT_ACTIVED",I="EVENT_PROJECT_DEPS_CHANGE",C="EVENT_PROJECT_PAGES_CHANGE",N="EVENT_PROJECT_BLOCKS_CHANGE",V="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",k="EVENT_PROJECT_PUBLISH",b="EVENT_PROJECT_FILE_PUBLISH",H="EVENT_PROJECT_GEN_SOURCE";class x{id="";locked="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};globals={};__BASE_PATH__="/";__UID__=r.uuid(!0);static attrs=["locked","platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","globals","__BASE_PATH__","__UID__"];constructor(e){const{id:t,__UID__:i}=e;this.id=t||r.uid(),this.__UID__=i||r.uuid(!0),this.update(e,!0)}update(e,t=!1){for(const i of x.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(l,{model:this,type:"update",data:e})}isPageFile(e){return e.type==="page"}cleanPagesDsl(e){for(const t of e)delete t.dsl,t.children&&t.children.length&&this.cleanPagesDsl(t.children)}toDsl(e){const{id:t}=this,i=x.attrs.reduce((s,a)=>(s[a]=this[a],s),{});return i.pages&&(i.pages=i.pages.map(s=>r.cloneDeep({...s,dsl:void 0})),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>r.cloneDeep({...s,dsl:void 0}))),{__VTJ_PROJECT__:!0,id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(P,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(P,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(o=>o.package===e.package);let a;if(s>-1?(a="update",i.splice(s,1,{...i[s],...e})):(a="create",i.push(e)),!t){const o={model:this,type:a,data:e};n.emit(I,o),n.emit(l,o)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(a=>a.package===e.package);if(s>-1&&i.splice(s,1),!t){const a={model:this,type:"delete",data:e};n.emit(I,a),n.emit(l,a)}}getPage(e){const t=(i,s=[])=>{for(const a of s){if(a.id===i)return a;if(a.children&&a.children.length){const o=t(i,a.children);if(o)return o}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir||s.layout?(s.layout&&i.push(s),s.children&&s.children.length&&(i=i.concat(e(s.children)))):i.push(s);return i};return e(this.pages)}async createPage(e,t,i=!1){if(e.id=e.raw?e.name:e.id||r.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:r.upperFirstCamelCase(e.name)}).toDsl(),t){const s=this.getPage(t);s?s.children?s.children.push(e):s.children=[e]:console.warn(`not found PageFile for id: ${t} `)}else this.pages.push(e);if(!i){const s={model:this,type:"create",data:e};n.emit(C,s),n.emit(l,s)}!this.currentFile&&!e.dir&&(await r.delay(1e3),this.active(e,i))}updatePage(e,t=!1){const i=this.getPage(e.id);if(delete e.dsl,i?Object.assign(i,e):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(C,s),n.emit(l,s)}}clonePage(e,t,i=!1){const s=r.uid(),a=`${e.name}Copy`,o=`${e.title}_副本`,c=new u({id:s,name:a}).toDsl(),f=r.merge({},e,{id:s,name:a,title:o,dsl:c}),p=t?this.getPage(t)?.children||[]:this.pages,O=p.findIndex(T=>T.id===e.id);if(p.splice(O+1,0,f),!i){const T={model:this,type:"clone",data:{source:e,target:f}};n.emit(C,T),n.emit(l,T)}}async saveToBlock(e,t=!1){this.active(e,t),await r.delay(1e3);const i=r.uid(),s=e.name,a=e.title,o=new u({...e.dsl,id:i,name:s}).toDsl(),c=r.merge({},e,{id:i,name:s,title:a,dsl:o,type:"block",fromType:"Schema"});if(this.blocks.push(c),!t){const f={model:this,type:"create",data:c};n.emit(N,f),n.emit(l,f)}}removePage(e,t=!1){const i=this.getPage(e),s=(a,o)=>{const c=o.findIndex(f=>f.id===a);if(c>=0){o.splice(c,1);return}for(const f of o)f.children&&f.children.length&&s(a,f.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const a={model:this,type:"delete",data:i};n.emit(C,a),n.emit(l,a)}}getBlock(e){return this.blocks.find(t=>t.id===e)}getFile(e){return this.getPage(e)||this.getBlock(e)}async createBlock(e,t=!1){const i=e.id||r.uid(),s=r.upperFirstCamelCase(e.name);e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e);const a=e.fromType||"Schema";if(!t){const o={model:this,type:"create",data:e};n.emit(N,o),n.emit(l,o)}!this.currentFile&&a==="Schema"&&(await r.delay(1e3),this.active(e,t))}updateBlock(e,t=!1){const i=this.getBlock(e.id);if(i?(Object.assign(i,e),i.dsl&&(i.dsl.name=e.name)):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(N,s),n.emit(l,s)}}cloneBlock(e,t=!1){const i=r.uid(),s=`${e.name}Copy`,a=`${e.title}_副本`,o=new u({id:i,name:s}).toDsl(),c=r.merge({},e,{id:i,name:s,title:a,dsl:o}),f=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(f+1,0,c),!t){const p={model:this,type:"clone",data:{source:e,target:c}};n.emit(N,p),n.emit(l,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,a=s.findIndex(o=>o.id===e);if(a>-1?(s.splice(a,1),this.currentFile?.id===e&&this.deactivate(t)):console.warn(`not found PageFile for id: ${e} `),!t){const o={model:this,type:"delete",data:i};n.emit(N,o),n.emit(l,o)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(a=>a.name===e.name||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=r.uid(),this.apis.push(e)),!t){const a={model:this,type:s,data:e};n.emit(V,a),n.emit(l,a)}}removeApi(e,t=!1){const i=this.apis.findIndex(s=>s.name===e||s.id===e);if(i>-1?this.apis.splice(i,1):console.warn(`not found Api for name: ${e} `),!t){const s={model:this,type:"delete",data:e};n.emit(V,s),n.emit(l,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setMeta(e,t=!1){const i=this.meta.find(a=>a.code===e.code||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=r.uid(),this.meta.push(e)),!t){const a={model:this,type:s,data:e};n.emit(S,a),n.emit(l,a)}}removeMeta(e,t=!1){const i=this.meta.findIndex(s=>s.code===e||s.id===e);if(i>-1?this.meta.splice(i,1):console.warn(`not found meta for name: ${name} `),!t){const s={model:this,type:"delete",data:e};n.emit(S,s),n.emit(l,s)}}existMetaCode(e,t=[]){return this.meta.some(i=>i.code===e&&!t.includes(i.id))}setHomepage(e,t=!1){if(this.homepage=e,!t){const i={model:this,type:"update",data:e};n.emit(l,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(l,i)}}setUniConfig(e,t,i=!1){if(this.uniConfig=Object.assign(this.uniConfig,{[e]:t}),!i){const s={model:this,type:"update",data:this.uniConfig};n.emit(l,s)}}setGloblas(e,t,i=!1){if(this.globals=Object.assign(this.globals,{[e]:t}),!i){const s={model:this,type:"update",data:this.globals};n.emit(l,s)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(b,t):n.emit(k,t)}genSource(){const e={model:this,type:"gen",data:null};n.emit(H,e)}lock(e){this.locked=e;const t={model:this,type:"update",data:e};n.emit(l,t)}unlock(e){if(e!==this.locked)return;this.locked="";const t={model:this,type:"update",data:null};n.emit(l,t)}}const A="EVENT_HISTORY_CHANGE",g="EVENT_HISTORY_LOAD";class K{options={max:50};index=-1;id;items;constructor(e,t={}){Object.assign(this.options,t);const{id:i,items:s=[]}=e;this.id=i,this.items=s}toDsl(){const{id:e,items:t}=this;return{id:e,items:t.map(i=>({id:i.id,label:i.label}))}}get(e){return this.items.find(t=>t.id===e)}add(e,t=!1){const{max:i}=this.options,s={id:r.uid(),label:new Date().toLocaleString(),dsl:r.cloneDeep(e)};if(this.items.unshift(s),this.items.length>i){const a=this.items.splice(i);t||n.emit(A,{model:this,type:"delete",data:a.map(o=>o.id)})}this.index=-1,t||n.emit(A,{model:this,type:"create",data:s})}remove(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>-1?(this.items.splice(i,1),i===this.index?this.index=-1:this.index>=this.items.length&&(this.index=this.items.length-1)):console.warn(`not found HistoryItem for id: ${e} `),t||n.emit(A,{model:this,type:"delete",data:[e]})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&n.emit(g,{model:this,type:"load",data:s})}backward(e=!1){const{index:t,items:i}=this;if(t>=i.length-1)return;t<0&&(this.index=0),++this.index;const s=i[this.index];s&&!e&&n.emit(g,{model:this,type:"load",data:s})}load(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>=0&&(this.index=i,t||n.emit(g,{model:this,type:"load",data:this.items[i]}))}clear(e=!1){this.index=-1;const t=this.items.map(i=>i.id);this.items=[],e||n.emit(A,{model:this,type:"clear",data:t})}}const n=r.mitt();function Y(m){return m instanceof u}function W(m){return m instanceof _}function q(m){return!!m.__VTJ_BLOCK__}function D(m){const e=r.cloneDeep(m);return delete e.id,Array.isArray(e.children)&&(e.children=e.children.map(t=>D(t))),e}function z(m){const e=m.fromType||"Schema";return e==="Schema"?{type:"Schema",id:m.id}:e==="UrlSchema"?{type:"UrlSchema",url:(m.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(m.urls||"").split(","),library:m.library}:""}exports.BUILT_IN_COMPONENTS=F;exports.BUILT_IN_LIBRARAY_MAP=w;exports.BUILT_IN_MATERIALS=J;exports.BUILT_IN_NAME=G;exports.BUILT_IN_TAGS=j;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=B;exports.Base=$;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=d;exports.EVENT_HISTORY_CHANGE=A;exports.EVENT_HISTORY_LOAD=g;exports.EVENT_NODE_CHANGE=h;exports.EVENT_PROJECT_ACTIVED=P;exports.EVENT_PROJECT_APIS_CHANGE=V;exports.EVENT_PROJECT_BLOCKS_CHANGE=N;exports.EVENT_PROJECT_CHANGE=l;exports.EVENT_PROJECT_DEPS_CHANGE=I;exports.EVENT_PROJECT_FILE_PUBLISH=b;exports.EVENT_PROJECT_GEN_SOURCE=H;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=C;exports.EVENT_PROJECT_PUBLISH=k;exports.EventModel=y;exports.HistoryModel=K;exports.NodeModel=_;exports.ProjectModel=x;exports.PropModel=v;exports.Service=M;exports.VTJ_CORE_VERSION=U;exports.cloneDsl=D;exports.createNodeFrom=z;exports.emitter=n;exports.isBlock=Y;exports.isBlockSchema=q;exports.isNode=W;
7
+ */const U="0.13.14",G="BuiltIn",R="VueMaterial",B="VueRouterMaterial",J=[R,B],w={vue:"Vue","vue-router":"VueRouter"},F={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[B]:["RouterView","RouterLink"]},j=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class M{}class ${listeners=[];isReady=!1;triggerReady(){this.isReady=!0;for(const e of this.listeners)e();this.listeners=[]}ready(e){this.isReady?e():this.listeners.push(e)}resetReady(){this.isReady=!1}}class N{constructor(e,t,i){this.name=e,this.value=t,this.defaultValue=i,this.setValue(t)}isUnset=!1;setValue(e){this.value=e,this.isUnset=this.value===this.defaultValue}getValue(){return this.value??this.defaultValue}static toDsl(e={}){return Object.entries(e).reduce((t,[i,s])=>(s.isUnset||(t[i]=s.getValue()),t),{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new N(i,s),t),{})}}class y{constructor(e){this.schema=e;const{name:t,handler:i}=this.schema;this.name=t,this.handler=i,this.update(e)}name;handler;modifiers={};update(e){Object.assign(this.schema,e);const{handler:t,modifiers:i={}}=this.schema;this.handler=t,this.modifiers=i}static toDsl(e){return Object.entries(e).reduce((t,[i,s])=>{const{handler:a,modifiers:o}=s;return t[i]={name:i,handler:a,modifiers:o},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new y(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||r.uid(),this.update(e)}id;name="";arg;modifiers;value;iterator;update(e){Object.assign(this.schema,e);const{name:t,arg:i,modifiers:s,value:a,iterator:o}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=a,this.iterator=o}static parse(e=[]){return e.map(t=>new E(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:a,value:o,iterator:d,id:f}=t;return{id:f,name:i,arg:s,modifiers:a,value:o,iterator:d}})}}const h="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=r.uid(),name:s,from:a=""}=e;this.id=i,this.name=s,this.from=a,this.update(e,!0),_.nodes[this.id]=this}__VTJ_NODE__=!0;locked=!1;static nodes={};id;name;from;invisible=!1;children="";slot;props={};events={};directives=[];disposed=!1;update(e,t=!1){const{invisible:i=!1,locked:s=!1,children:a=[],slot:o,props:d={},events:f={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(a,!0),this.setSlot(o,!0),this.props=N.parse(d),this.events=y.parse(f),this.directives=E.parse(p),t||n.emit(h,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new _(i,this)):this.children=e,t||n.emit(h,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(h,this)}setProp(e,t,i,s=!1){const a=this.props[e];a?a.setValue(t):this.props[e]=new N(e,t,i),s||n.emit(h,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(h,this)}getPropValue(e){const t=this.props[e];if(t)return t.getValue()}setEvent(e,t=!1){const i=this.events[e.name];i?i.update(e):this.events[e.name]=new y(e),t||n.emit(h,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(h,this)}setDirective(e,t=!1){const i=e instanceof E?e:new E(e),s=this.directives.findIndex(a=>a.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||n.emit(h,this)}removeDirective(e,t=!1){const i=this.directives.findIndex(s=>s===e||s.id===e.id);i>=0&&this.directives.splice(i,1),t||n.emit(h,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const a=i.findIndex(o=>o===e);e.parent=null,i.splice(a,1),t||n.emit(h,this)}appendChild(e,t=!1){const{children:i,disposed:s}=this;s||(e.parent=this,Array.isArray(i)?i.push(e):this.children=[e],t||n.emit(h,this))}insertAfter(e,t=!1){if(!this.parent)return;const i=this.parent.children;if(Array.isArray(i)){e.parent=this.parent;const s=i.indexOf(this);i.splice(s+1,0,e),t||n.emit(h,this.parent)}}insertBefore(e,t=!1){if(!this.parent)return;const i=this.parent.children;if(Array.isArray(i)){e.parent=this.parent;const s=i.indexOf(this);i.splice(s,0,e),t||n.emit(h,this.parent)}}movePrev(e=!1){const t=this.parent;if(!t)return;const i=t.children;if(Array.isArray(i)){const s=i.indexOf(this);s>0&&(i.splice(s,1),i.splice(s-1,0,this),e||n.emit(h,t))}}moveNext(e=!1){const t=this.parent;if(!t)return;const i=t.children;if(Array.isArray(i)){const s=i.indexOf(this);s>-1&&s<i.length-1&&(i.splice(s,1),i.splice(s+1,0,this),e||n.emit(h,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:d,props:f,directives:p,events:O}=this,T=Array.isArray(d)?d.map(L=>L.toDsl()):d;return{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:T,props:N.toDsl(f),directives:E.toDsl(p),events:y.toDsl(O)}}dispose(e=!1){const{children:t,disposed:i}=this;i||(Array.isArray(t)&&t.forEach(s=>s.dispose(!0)),this.parent?this.parent.removeChild(this,e):e||n.emit(h,this),this.parent=null,this.disposed=!0,delete _.nodes[this.id])}lock(e=!1){if(this.locked=!0,Array.isArray(this.children))for(const t of this.children)t.lock(!0);e||n.emit(h,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(h,this)}setVisible(e,t=!1){if(this.invisible=!e,Array.isArray(this.children))for(const i of this.children)i.setVisible(e,!0);t||n.emit(h,this)}isChild(e){let t=!1;if(Array.isArray(this.children)){for(const i of this.children)if(e===i||e.id===i.id){t=!0;break}else if(t=i.isChild(e),t)break}return t}}const l="EVENT_BLOCK_CHANGE";class u{__VTJ_BLOCK__=!0;id;name="";inject=[];state={};lifeCycles={};methods={};computed={};watch=[];css="";props=[];emits=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","inject","state","lifeCycles","methods","computed","watch","css","props","emits","slots","dataSources","__TEMPLATE_ID__"];constructor(e){const{id:t}=e;this.id=t||r.uid(),this.update(e,!0)}update(e,t=!1){for(const s of u.normalAttrs){const a=e[s];a!==void 0&&(this[s]=a)}const{nodes:i=[]}=e;i.length?this.nodes=i.map(s=>new _(s)):this.nodes=[],t||n.emit(l,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((o,d)=>(o[d]=this[d],o),{}),__VTJ_BLOCK__:t,__VERSION__:e||r.timestamp().toString(),id:i,nodes:s.map(o=>o.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}setFunction(e,t,i,s=!1){this[e][t]=i,s||n.emit(l,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(l,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(l,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(l,this)}setCss(e,t=!1){this.css=e,t||n.emit(l,this)}setWatch(e,t=!1){e.id=e.id||r.uid();const i=this.watch.findIndex(s=>s.id&&s.id===e.id||s===e);i>-1?this.watch.splice(i,1,e):this.watch.push(e),t||n.emit(l,this)}removeWatch(e,t=!1){const i=this.watch.findIndex(s=>s.id&&s.id===e.id||s===e);i>-1&&(this.watch.splice(i,1),t||n.emit(l,this))}setProp(e,t=!1){const i=this.props.findIndex(s=>typeof s=="string"?s===e.name:s.name===e.name);i>-1?this.props.splice(i,1,e):this.props.push(e),t||n.emit(l,this)}removeProp(e,t=!1){const i=this.props.findIndex(s=>typeof s=="string"?s===e.name:s.name===e.name);i>-1&&(this.props.splice(i,1),t||n.emit(l,this))}setEmit(e,t=!1){const i=r.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(a=>a===i.name||a.name===i.name);s>-1?this.emits.splice(s,1,i):this.emits.push(i),t||n.emit(l,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>r.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||n.emit(l,this))}setSlot(e,t=!1){const i=r.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(a=>a===i.name||a.name===i.name);s>-1?this.slots.splice(s,1,i):this.slots.push(i),t||n.emit(l,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>r.isString(s)?s===e:s.name===e);i>-1&&(this.slots.splice(i,1),t||n.emit(l,this))}setInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1?this.inject.splice(i,1,e):this.inject.push(e),t||n.emit(l,this)}removeInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1&&(this.inject.splice(i,1),t||n.emit(l,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(l,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(l,this)}insertAfter(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s+1,0,e),i||n.emit(l,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(l,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(l,this)}addNode(e,t,i="inner",s=!1){t?["left","top"].includes(i)?t.parent?t.insertAfter(e,s):this.insertBefore(e,t,s):["right","bottom"].includes(i)?t.parent?t.insertAfter(e,s):this.insertAfter(e,t,s):t.appendChild(e,s):this.appendNode(e,s)}__removeNode(e,t=!1){const i=this.nodes.findIndex(s=>s.id===e.id);i>-1&&(this.nodes.splice(i,1),t||n.emit(l,this))}removeNode(e,t=!1){e.parent?e.dispose(t):(e.dispose(!0),this.__removeNode(e,t))}move(e,t,i="inner",s=!1){e.parent?e.parent.removeChild(e,!0):this.__removeNode(e,!0),this.addNode(e,t,i,s)}movePrev(e,t=!1){if(e.parent)e.movePrev(t);else{const i=this.nodes,s=i.indexOf(e);s>0&&(i.splice(s,1),i.splice(s-1,0,e),t||n.emit(l,this))}}moveNext(e,t=!1){if(e.parent)e.moveNext(t);else{const i=this.nodes,s=i.indexOf(e);s>-1&&s<i.length-1&&(i.splice(s,1),i.splice(s+1,0,e),t||n.emit(l,this))}}cloneNode(e,t=!1){const i=D(e.toDsl()),s=new _(i);return this.addNode(s,e,"bottom",t),s}lock(e=!1){this.locked=!0;for(const t of this.nodes)t.lock(!0);e||n.emit(l,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(l,this)}isChild(e){let t=!1;for(const i of this.nodes)if(e===i||e.id===i.id){t=!0;break}else if(t=i.isChild(e),t)break;return t}}const c="EVENT_PROJECT_CHANGE",I="EVENT_PROJECT_ACTIVED",V="EVENT_PROJECT_DEPS_CHANGE",g="EVENT_PROJECT_PAGES_CHANGE",v="EVENT_PROJECT_BLOCKS_CHANGE",C="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",k="EVENT_PROJECT_PUBLISH",b="EVENT_PROJECT_FILE_PUBLISH",H="EVENT_PROJECT_GEN_SOURCE";class x{id="";locked="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};globals={};__BASE_PATH__="/";__UID__=r.uuid(!0);static attrs=["locked","platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","globals","__BASE_PATH__","__UID__"];constructor(e){const{id:t,__UID__:i}=e;this.id=t||r.uid(),this.__UID__=i||r.uuid(!0),this.update(e,!0)}update(e,t=!1){for(const i of x.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(c,{model:this,type:"update",data:e})}isPageFile(e){return e.type==="page"}cleanPagesDsl(e){for(const t of e)delete t.dsl,t.children&&t.children.length&&this.cleanPagesDsl(t.children)}toDsl(e){const{id:t}=this,i=x.attrs.reduce((s,a)=>(s[a]=this[a],s),{});return i.pages&&(i.pages=i.pages.map(s=>r.cloneDeep({...s,dsl:void 0})),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>r.cloneDeep({...s,dsl:void 0}))),{__VTJ_PROJECT__:!0,id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(I,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(I,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(o=>o.package===e.package);let a;if(s>-1?(a="update",i.splice(s,1,{...i[s],...e})):(a="create",i.push(e)),!t){const o={model:this,type:a,data:e};n.emit(V,o),n.emit(c,o)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(a=>a.package===e.package);if(s>-1&&i.splice(s,1),!t){const a={model:this,type:"delete",data:e};n.emit(V,a),n.emit(c,a)}}getPage(e){const t=(i,s=[])=>{for(const a of s){if(a.id===i)return a;if(a.children&&a.children.length){const o=t(i,a.children);if(o)return o}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir||s.layout?(s.layout&&i.push(s),s.children&&s.children.length&&(i=i.concat(e(s.children)))):i.push(s);return i};return e(this.pages)}async createPage(e,t,i=!1){if(e.id=e.raw?e.name:e.id||r.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:r.upperFirstCamelCase(e.name)}).toDsl(),t){const s=this.getPage(t);s?s.children?s.children.push(e):s.children=[e]:console.warn(`not found PageFile for id: ${t} `)}else this.pages.push(e);if(!i){const s={model:this,type:"create",data:e};n.emit(g,s),n.emit(c,s)}!this.currentFile&&!e.dir&&(await r.delay(1e3),this.active(e,i))}updatePage(e,t=!1){const i=this.getPage(e.id);if(delete e.dsl,i?Object.assign(i,e):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(g,s),n.emit(c,s)}}clonePage(e,t,i=!1){const s=r.uid(),a=`${e.name}Copy`,o=`${e.title}_副本`,d=new u({id:s,name:a}).toDsl(),f=r.merge({},e,{id:s,name:a,title:o,dsl:d}),p=t?this.getPage(t)?.children||[]:this.pages,O=p.findIndex(T=>T.id===e.id);if(p.splice(O+1,0,f),!i){const T={model:this,type:"clone",data:{source:e,target:f}};n.emit(g,T),n.emit(c,T)}}async saveToBlock(e,t=!1){this.active(e,t),await r.delay(1e3);const i=r.uid(),s=e.name,a=e.title,o=new u({...e.dsl,id:i,name:s}).toDsl(),d=r.merge({},e,{id:i,name:s,title:a,dsl:o,type:"block",fromType:"Schema"});if(this.blocks.push(d),!t){const f={model:this,type:"create",data:d};n.emit(v,f),n.emit(c,f)}}removePage(e,t=!1){const i=this.getPage(e),s=(a,o)=>{const d=o.findIndex(f=>f.id===a);if(d>=0){o.splice(d,1);return}for(const f of o)f.children&&f.children.length&&s(a,f.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const a={model:this,type:"delete",data:i};n.emit(g,a),n.emit(c,a)}}getBlock(e){return this.blocks.find(t=>t.id===e)}getFile(e){return this.getPage(e)||this.getBlock(e)}async createBlock(e,t=!1){const i=e.id||r.uid(),s=r.upperFirstCamelCase(e.name);e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e);const a=e.fromType||"Schema";if(!t){const o={model:this,type:"create",data:e};n.emit(v,o),n.emit(c,o)}!this.currentFile&&a==="Schema"&&(await r.delay(1e3),this.active(e,t))}updateBlock(e,t=!1){const i=this.getBlock(e.id);if(i?(Object.assign(i,e),i.dsl&&(i.dsl.name=e.name)):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(v,s),n.emit(c,s)}}cloneBlock(e,t=!1){const i=r.uid(),s=`${e.name}Copy`,a=`${e.title}_副本`,o=new u({id:i,name:s}).toDsl(),d=r.merge({},e,{id:i,name:s,title:a,dsl:o}),f=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(f+1,0,d),!t){const p={model:this,type:"clone",data:{source:e,target:d}};n.emit(v,p),n.emit(c,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,a=s.findIndex(o=>o.id===e);if(a>-1?(s.splice(a,1),this.currentFile?.id===e&&this.deactivate(t)):console.warn(`not found PageFile for id: ${e} `),!t){const o={model:this,type:"delete",data:i};n.emit(v,o),n.emit(c,o)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(a=>a.name===e.name||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=r.uid(),this.apis.push(e)),!t){const a={model:this,type:s,data:e};n.emit(C,a),n.emit(c,a)}}setApis(e,t=!1){for(const i of e)this.setApi(i,!0);if(!t){const i={model:this,type:"create",data:e};n.emit(C,i),n.emit(c,i)}}removeApi(e,t=!1){const i=this.apis.findIndex(s=>s.name===e||s.id===e);if(i>-1?this.apis.splice(i,1):console.warn(`not found Api for name: ${e} `),!t){const s={model:this,type:"delete",data:e};n.emit(C,s),n.emit(c,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setMeta(e,t=!1){const i=this.meta.find(a=>a.code===e.code||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=r.uid(),this.meta.push(e)),!t){const a={model:this,type:s,data:e};n.emit(S,a),n.emit(c,a)}}removeMeta(e,t=!1){const i=this.meta.findIndex(s=>s.code===e||s.id===e);if(i>-1?this.meta.splice(i,1):console.warn(`not found meta for name: ${name} `),!t){const s={model:this,type:"delete",data:e};n.emit(S,s),n.emit(c,s)}}existMetaCode(e,t=[]){return this.meta.some(i=>i.code===e&&!t.includes(i.id))}setHomepage(e,t=!1){if(this.homepage=e,!t){const i={model:this,type:"update",data:e};n.emit(c,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(c,i)}}setUniConfig(e,t,i=!1){if(this.uniConfig=Object.assign(this.uniConfig,{[e]:t}),!i){const s={model:this,type:"update",data:this.uniConfig};n.emit(c,s)}}setGloblas(e,t,i=!1){if(this.globals=Object.assign(this.globals,{[e]:t}),!i){const s={model:this,type:"update",data:this.globals};n.emit(c,s)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(b,t):n.emit(k,t)}genSource(){const e={model:this,type:"gen",data:null};n.emit(H,e)}lock(e){this.locked=e;const t={model:this,type:"update",data:e};n.emit(c,t)}unlock(e){if(e!==this.locked)return;this.locked="";const t={model:this,type:"update",data:null};n.emit(c,t)}getPageRoutes(e,t){const i=this.platform==="uniapp",s=e||(i?"pages":"page"),a=this.getPages(),o=t||"";return a.map(d=>({id:d.id,path:`${o}/${s}/${d.id}`,name:d.name,title:d.title,meta:d.meta}))}}const A="EVENT_HISTORY_CHANGE",P="EVENT_HISTORY_LOAD";class K{options={max:50};index=-1;id;items;constructor(e,t={}){Object.assign(this.options,t);const{id:i,items:s=[]}=e;this.id=i,this.items=s}toDsl(){const{id:e,items:t}=this;return{id:e,items:t.map(i=>({id:i.id,label:i.label}))}}get(e){return this.items.find(t=>t.id===e)}add(e,t=!1){const{max:i}=this.options,s={id:r.uid(),label:new Date().toLocaleString(),dsl:r.cloneDeep(e)};if(this.items.unshift(s),this.items.length>i){const a=this.items.splice(i);t||n.emit(A,{model:this,type:"delete",data:a.map(o=>o.id)})}this.index=-1,t||n.emit(A,{model:this,type:"create",data:s})}remove(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>-1?(this.items.splice(i,1),i===this.index?this.index=-1:this.index>=this.items.length&&(this.index=this.items.length-1)):console.warn(`not found HistoryItem for id: ${e} `),t||n.emit(A,{model:this,type:"delete",data:[e]})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&n.emit(P,{model:this,type:"load",data:s})}backward(e=!1){const{index:t,items:i}=this;if(t>=i.length-1)return;t<0&&(this.index=0),++this.index;const s=i[this.index];s&&!e&&n.emit(P,{model:this,type:"load",data:s})}load(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>=0&&(this.index=i,t||n.emit(P,{model:this,type:"load",data:this.items[i]}))}clear(e=!1){this.index=-1;const t=this.items.map(i=>i.id);this.items=[],e||n.emit(A,{model:this,type:"clear",data:t})}}const n=r.mitt();function Y(m){return m instanceof u}function W(m){return m instanceof _}function q(m){return!!m.__VTJ_BLOCK__}function D(m){const e=r.cloneDeep(m);return delete e.id,Array.isArray(e.children)&&(e.children=e.children.map(t=>D(t))),e}function z(m){const e=m.fromType||"Schema";return e==="Schema"?{type:"Schema",id:m.id}:e==="UrlSchema"?{type:"UrlSchema",url:(m.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(m.urls||"").split(","),library:m.library}:""}exports.BUILT_IN_COMPONENTS=F;exports.BUILT_IN_LIBRARAY_MAP=w;exports.BUILT_IN_MATERIALS=J;exports.BUILT_IN_NAME=G;exports.BUILT_IN_TAGS=j;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=B;exports.Base=$;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=l;exports.EVENT_HISTORY_CHANGE=A;exports.EVENT_HISTORY_LOAD=P;exports.EVENT_NODE_CHANGE=h;exports.EVENT_PROJECT_ACTIVED=I;exports.EVENT_PROJECT_APIS_CHANGE=C;exports.EVENT_PROJECT_BLOCKS_CHANGE=v;exports.EVENT_PROJECT_CHANGE=c;exports.EVENT_PROJECT_DEPS_CHANGE=V;exports.EVENT_PROJECT_FILE_PUBLISH=b;exports.EVENT_PROJECT_GEN_SOURCE=H;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=g;exports.EVENT_PROJECT_PUBLISH=k;exports.EventModel=y;exports.HistoryModel=K;exports.NodeModel=_;exports.ProjectModel=x;exports.PropModel=N;exports.Service=M;exports.VTJ_CORE_VERSION=U;exports.cloneDsl=D;exports.createNodeFrom=z;exports.emitter=n;exports.isBlock=Y;exports.isBlockSchema=q;exports.isNode=W;
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { uid as m, timestamp as G, isString as T, uuid as k, cloneDeep as C, upperFirstCamelCase as R, delay as P, merge as I, mitt as F } from "@vtj/base";
1
+ import { uid as m, timestamp as G, isString as T, uuid as R, cloneDeep as C, upperFirstCamelCase as D, delay as O, merge as I, mitt as F } from "@vtj/base";
2
2
  /**!
3
3
  * Copyright (c) 2025, VTJ.PRO All rights reserved.
4
4
  * @name @vtj/core
5
5
  * @author CHC chenhuachun1549@dingtalk.com
6
- * @version 0.13.13
6
+ * @version 0.13.14
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const Y = "0.13.13", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial", q = [H, J], z = {
9
+ const Y = "0.13.14", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial", q = [H, J], z = {
10
10
  vue: "Vue",
11
11
  "vue-router": "VueRouter"
12
12
  }, Q = {
@@ -135,14 +135,14 @@ class v {
135
135
  }
136
136
  static toDsl(e = []) {
137
137
  return e.map((t) => {
138
- const { name: i, arg: s, modifiers: a, value: o, iterator: d, id: c } = t;
138
+ const { name: i, arg: s, modifiers: a, value: o, iterator: r, id: c } = t;
139
139
  return {
140
140
  id: c,
141
141
  name: i,
142
142
  arg: s,
143
143
  modifiers: a,
144
144
  value: o,
145
- iterator: d
145
+ iterator: r
146
146
  };
147
147
  });
148
148
  }
@@ -217,11 +217,11 @@ class _ {
217
217
  locked: s = !1,
218
218
  children: a = [],
219
219
  slot: o,
220
- props: d = {},
220
+ props: r = {},
221
221
  events: c = {},
222
222
  directives: p = []
223
223
  } = e;
224
- this.invisible = i, this.locked = s, this.setChildren(a, !0), this.setSlot(o, !0), this.props = g.parse(d), this.events = x.parse(c), this.directives = v.parse(p), t || n.emit(h, this);
224
+ this.invisible = i, this.locked = s, this.setChildren(a, !0), this.setSlot(o, !0), this.props = g.parse(r), this.events = x.parse(c), this.directives = v.parse(p), t || n.emit(h, this);
225
225
  }
226
226
  /**
227
227
  * 设置子节点
@@ -387,11 +387,11 @@ class _ {
387
387
  invisible: s,
388
388
  locked: a,
389
389
  slot: o,
390
- children: d,
390
+ children: r,
391
391
  props: c,
392
392
  directives: p,
393
- events: O
394
- } = this, E = Array.isArray(d) ? d.map((U) => U.toDsl()) : d;
393
+ events: P
394
+ } = this, E = Array.isArray(r) ? r.map((U) => U.toDsl()) : r;
395
395
  return {
396
396
  id: e,
397
397
  name: t,
@@ -402,7 +402,7 @@ class _ {
402
402
  children: E,
403
403
  props: g.toDsl(c),
404
404
  directives: v.toDsl(p),
405
- events: x.toDsl(O)
405
+ events: x.toDsl(P)
406
406
  };
407
407
  }
408
408
  /**
@@ -445,7 +445,7 @@ class _ {
445
445
  return t;
446
446
  }
447
447
  }
448
- const r = "EVENT_BLOCK_CHANGE";
448
+ const l = "EVENT_BLOCK_CHANGE";
449
449
  class u {
450
450
  __VTJ_BLOCK__ = !0;
451
451
  id;
@@ -490,7 +490,7 @@ class u {
490
490
  a !== void 0 && (this[s] = a);
491
491
  }
492
492
  const { nodes: i = [] } = e;
493
- i.length ? this.nodes = i.map((s) => new _(s)) : this.nodes = [], t || n.emit(r, this);
493
+ i.length ? this.nodes = i.map((s) => new _(s)) : this.nodes = [], t || n.emit(l, this);
494
494
  }
495
495
  /**
496
496
  * 获取DSL
@@ -500,7 +500,7 @@ class u {
500
500
  const { __VTJ_BLOCK__: t, id: i, nodes: s } = this;
501
501
  return {
502
502
  ...u.normalAttrs.reduce(
503
- (o, d) => (o[d] = this[d], o),
503
+ (o, r) => (o[r] = this[r], o),
504
504
  {}
505
505
  ),
506
506
  __VTJ_BLOCK__: t,
@@ -523,7 +523,7 @@ class u {
523
523
  * @param silent
524
524
  */
525
525
  setFunction(e, t, i, s = !1) {
526
- this[e][t] = i, s || n.emit(r, this);
526
+ this[e][t] = i, s || n.emit(l, this);
527
527
  }
528
528
  /**
529
529
  * 删除通用函数属性
@@ -532,7 +532,7 @@ class u {
532
532
  * @param silent
533
533
  */
534
534
  removeFunction(e, t, i = !1) {
535
- delete this[e][t], i || n.emit(r, this);
535
+ delete this[e][t], i || n.emit(l, this);
536
536
  }
537
537
  /**
538
538
  * 设置状态
@@ -541,7 +541,7 @@ class u {
541
541
  * @param silent
542
542
  */
543
543
  setState(e, t, i = !1) {
544
- this.state[e] = t, i || n.emit(r, this);
544
+ this.state[e] = t, i || n.emit(l, this);
545
545
  }
546
546
  /**
547
547
  * 删除状态
@@ -549,7 +549,7 @@ class u {
549
549
  * @param silent
550
550
  */
551
551
  removeState(e, t = !1) {
552
- delete this.state[e], t || n.emit(r, this);
552
+ delete this.state[e], t || n.emit(l, this);
553
553
  }
554
554
  /**
555
555
  * 更新CSS
@@ -557,7 +557,7 @@ class u {
557
557
  * @param silent
558
558
  */
559
559
  setCss(e, t = !1) {
560
- this.css = e, t || n.emit(r, this);
560
+ this.css = e, t || n.emit(l, this);
561
561
  }
562
562
  /**
563
563
  * 新增或更新 watch
@@ -569,7 +569,7 @@ class u {
569
569
  const i = this.watch.findIndex(
570
570
  (s) => s.id && s.id === e.id || s === e
571
571
  );
572
- i > -1 ? this.watch.splice(i, 1, e) : this.watch.push(e), t || n.emit(r, this);
572
+ i > -1 ? this.watch.splice(i, 1, e) : this.watch.push(e), t || n.emit(l, this);
573
573
  }
574
574
  /**
575
575
  * 删除 watch
@@ -580,7 +580,7 @@ class u {
580
580
  const i = this.watch.findIndex(
581
581
  (s) => s.id && s.id === e.id || s === e
582
582
  );
583
- i > -1 && (this.watch.splice(i, 1), t || n.emit(r, this));
583
+ i > -1 && (this.watch.splice(i, 1), t || n.emit(l, this));
584
584
  }
585
585
  /**
586
586
  * 定义属性参数
@@ -591,7 +591,7 @@ class u {
591
591
  const i = this.props.findIndex(
592
592
  (s) => typeof s == "string" ? s === e.name : s.name === e.name
593
593
  );
594
- i > -1 ? this.props.splice(i, 1, e) : this.props.push(e), t || n.emit(r, this);
594
+ i > -1 ? this.props.splice(i, 1, e) : this.props.push(e), t || n.emit(l, this);
595
595
  }
596
596
  /**
597
597
  * 删除属性
@@ -602,7 +602,7 @@ class u {
602
602
  const i = this.props.findIndex(
603
603
  (s) => typeof s == "string" ? s === e.name : s.name === e.name
604
604
  );
605
- i > -1 && (this.props.splice(i, 1), t || n.emit(r, this));
605
+ i > -1 && (this.props.splice(i, 1), t || n.emit(l, this));
606
606
  }
607
607
  /**
608
608
  * 设置事件
@@ -613,7 +613,7 @@ class u {
613
613
  const i = T(e) ? { name: e, params: [] } : e, s = this.emits.findIndex(
614
614
  (a) => a === i.name || a.name === i.name
615
615
  );
616
- s > -1 ? this.emits.splice(s, 1, i) : this.emits.push(i), t || n.emit(r, this);
616
+ s > -1 ? this.emits.splice(s, 1, i) : this.emits.push(i), t || n.emit(l, this);
617
617
  }
618
618
  /**
619
619
  * 删除事件
@@ -624,7 +624,7 @@ class u {
624
624
  const i = this.emits.findIndex(
625
625
  (s) => T(s) ? s === e : s.name === e
626
626
  );
627
- i > -1 && (this.emits.splice(i, 1), t || n.emit(r, this));
627
+ i > -1 && (this.emits.splice(i, 1), t || n.emit(l, this));
628
628
  }
629
629
  /**
630
630
  * 设置插槽
@@ -635,7 +635,7 @@ class u {
635
635
  const i = T(e) ? { name: e, params: [] } : e, s = this.slots.findIndex(
636
636
  (a) => a === i.name || a.name === i.name
637
637
  );
638
- s > -1 ? this.slots.splice(s, 1, i) : this.slots.push(i), t || n.emit(r, this);
638
+ s > -1 ? this.slots.splice(s, 1, i) : this.slots.push(i), t || n.emit(l, this);
639
639
  }
640
640
  /**
641
641
  * 删除插槽
@@ -646,7 +646,7 @@ class u {
646
646
  const i = this.slots.findIndex(
647
647
  (s) => T(s) ? s === e : s.name === e
648
648
  );
649
- i > -1 && (this.slots.splice(i, 1), t || n.emit(r, this));
649
+ i > -1 && (this.slots.splice(i, 1), t || n.emit(l, this));
650
650
  }
651
651
  /**
652
652
  * 设置注入
@@ -655,7 +655,7 @@ class u {
655
655
  */
656
656
  setInject(e, t = !1) {
657
657
  const i = this.inject.findIndex((s) => s.name === e.name);
658
- i > -1 ? this.inject.splice(i, 1, e) : this.inject.push(e), t || n.emit(r, this);
658
+ i > -1 ? this.inject.splice(i, 1, e) : this.inject.push(e), t || n.emit(l, this);
659
659
  }
660
660
  /**
661
661
  * 删除注入
@@ -664,7 +664,7 @@ class u {
664
664
  */
665
665
  removeInject(e, t = !1) {
666
666
  const i = this.inject.findIndex((s) => s.name === e.name);
667
- i > -1 && (this.inject.splice(i, 1), t || n.emit(r, this));
667
+ i > -1 && (this.inject.splice(i, 1), t || n.emit(l, this));
668
668
  }
669
669
  /**
670
670
  * 设置数据源
@@ -672,7 +672,7 @@ class u {
672
672
  * @param silent
673
673
  */
674
674
  setDataSource(e, t = !1) {
675
- this.dataSources[e.name] = e, t || n.emit(r, this);
675
+ this.dataSources[e.name] = e, t || n.emit(l, this);
676
676
  }
677
677
  /**
678
678
  * 删除数据源
@@ -680,20 +680,20 @@ class u {
680
680
  * @param silent
681
681
  */
682
682
  removeDataSource(e, t = !1) {
683
- delete this.dataSources[e], t || n.emit(r, this);
683
+ delete this.dataSources[e], t || n.emit(l, this);
684
684
  }
685
685
  insertAfter(e, t, i = !1) {
686
686
  e.parent = null;
687
687
  const s = this.nodes.indexOf(t);
688
- this.nodes.splice(s + 1, 0, e), i || n.emit(r, this);
688
+ this.nodes.splice(s + 1, 0, e), i || n.emit(l, this);
689
689
  }
690
690
  insertBefore(e, t, i = !1) {
691
691
  e.parent = null;
692
692
  const s = this.nodes.indexOf(t);
693
- this.nodes.splice(s, 0, e), i || n.emit(r, this);
693
+ this.nodes.splice(s, 0, e), i || n.emit(l, this);
694
694
  }
695
695
  appendNode(e, t = !1) {
696
- e.parent = null, this.nodes.push(e), t || n.emit(r, this);
696
+ e.parent = null, this.nodes.push(e), t || n.emit(l, this);
697
697
  }
698
698
  /**
699
699
  * 添加节点
@@ -707,7 +707,7 @@ class u {
707
707
  }
708
708
  __removeNode(e, t = !1) {
709
709
  const i = this.nodes.findIndex((s) => s.id === e.id);
710
- i > -1 && (this.nodes.splice(i, 1), t || n.emit(r, this));
710
+ i > -1 && (this.nodes.splice(i, 1), t || n.emit(l, this));
711
711
  }
712
712
  /**
713
713
  * 删除节点
@@ -737,7 +737,7 @@ class u {
737
737
  e.movePrev(t);
738
738
  else {
739
739
  const i = this.nodes, s = i.indexOf(e);
740
- s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, e), t || n.emit(r, this));
740
+ s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, e), t || n.emit(l, this));
741
741
  }
742
742
  }
743
743
  /**
@@ -750,7 +750,7 @@ class u {
750
750
  e.moveNext(t);
751
751
  else {
752
752
  const i = this.nodes, s = i.indexOf(e);
753
- s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, e), t || n.emit(r, this));
753
+ s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, e), t || n.emit(l, this));
754
754
  }
755
755
  }
756
756
  /**
@@ -767,13 +767,13 @@ class u {
767
767
  this.locked = !0;
768
768
  for (const t of this.nodes)
769
769
  t.lock(!0);
770
- e || n.emit(r, this);
770
+ e || n.emit(l, this);
771
771
  }
772
772
  unlock(e = !1) {
773
773
  this.locked = !1;
774
774
  for (const t of this.nodes)
775
775
  t.unlock(!0);
776
- e || n.emit(r, this);
776
+ e || n.emit(l, this);
777
777
  }
778
778
  isChild(e) {
779
779
  let t = !1;
@@ -786,8 +786,8 @@ class u {
786
786
  return t;
787
787
  }
788
788
  }
789
- const l = "EVENT_PROJECT_CHANGE", D = "EVENT_PROJECT_ACTIVED", b = "EVENT_PROJECT_DEPS_CHANGE", A = "EVENT_PROJECT_PAGES_CHANGE", y = "EVENT_PROJECT_BLOCKS_CHANGE", B = "EVENT_PROJECT_APIS_CHANGE", w = "EVENT_PROJECT_META_CHANGE", j = "EVENT_PROJECT_PUBLISH", $ = "EVENT_PROJECT_FILE_PUBLISH", M = "EVENT_PROJECT_GEN_SOURCE";
790
- class S {
789
+ const d = "EVENT_PROJECT_CHANGE", b = "EVENT_PROJECT_ACTIVED", B = "EVENT_PROJECT_DEPS_CHANGE", A = "EVENT_PROJECT_PAGES_CHANGE", y = "EVENT_PROJECT_BLOCKS_CHANGE", V = "EVENT_PROJECT_APIS_CHANGE", w = "EVENT_PROJECT_META_CHANGE", j = "EVENT_PROJECT_PUBLISH", $ = "EVENT_PROJECT_FILE_PUBLISH", M = "EVENT_PROJECT_GEN_SOURCE";
790
+ class k {
791
791
  id = "";
792
792
  locked = "";
793
793
  platform = "web";
@@ -804,7 +804,7 @@ class S {
804
804
  uniConfig = {};
805
805
  globals = {};
806
806
  __BASE_PATH__ = "/";
807
- __UID__ = k(!0);
807
+ __UID__ = R(!0);
808
808
  static attrs = [
809
809
  "locked",
810
810
  "platform",
@@ -824,14 +824,14 @@ class S {
824
824
  ];
825
825
  constructor(e) {
826
826
  const { id: t, __UID__: i } = e;
827
- this.id = t || m(), this.__UID__ = i || k(!0), this.update(e, !0);
827
+ this.id = t || m(), this.__UID__ = i || R(!0), this.update(e, !0);
828
828
  }
829
829
  update(e, t = !1) {
830
- for (const i of S.attrs) {
830
+ for (const i of k.attrs) {
831
831
  const s = e[i];
832
832
  s && (this[i] = s);
833
833
  }
834
- t || n.emit(l, {
834
+ t || n.emit(d, {
835
835
  model: this,
836
836
  type: "update",
837
837
  data: e
@@ -845,7 +845,7 @@ class S {
845
845
  delete t.dsl, t.children && t.children.length && this.cleanPagesDsl(t.children);
846
846
  }
847
847
  toDsl(e) {
848
- const { id: t } = this, i = S.attrs.reduce(
848
+ const { id: t } = this, i = k.attrs.reduce(
849
849
  (s, a) => (s[a] = this[a], s),
850
850
  {}
851
851
  );
@@ -867,7 +867,7 @@ class S {
867
867
  * @param silent
868
868
  */
869
869
  active(e, t = !1) {
870
- this.currentFile = e, t || n.emit(D, {
870
+ this.currentFile = e, t || n.emit(b, {
871
871
  model: this,
872
872
  type: "update",
873
873
  data: e
@@ -878,7 +878,7 @@ class S {
878
878
  * @param silent
879
879
  */
880
880
  deactivate(e = !1) {
881
- this.currentFile = null, e || n.emit(D, {
881
+ this.currentFile = null, e || n.emit(b, {
882
882
  model: this,
883
883
  type: "update",
884
884
  data: null
@@ -901,7 +901,7 @@ class S {
901
901
  type: a,
902
902
  data: e
903
903
  };
904
- n.emit(b, o), n.emit(l, o);
904
+ n.emit(B, o), n.emit(d, o);
905
905
  }
906
906
  }
907
907
  /**
@@ -917,7 +917,7 @@ class S {
917
917
  type: "delete",
918
918
  data: e
919
919
  };
920
- n.emit(b, a), n.emit(l, a);
920
+ n.emit(B, a), n.emit(d, a);
921
921
  }
922
922
  }
923
923
  /**
@@ -961,7 +961,7 @@ class S {
961
961
  async createPage(e, t, i = !1) {
962
962
  if (e.id = e.raw ? e.name : e.id || m(), e.type = "page", e.dir ? e.children = [] : e.dsl = e.dsl || new u({
963
963
  id: e.id,
964
- name: R(e.name)
964
+ name: D(e.name)
965
965
  }).toDsl(), t) {
966
966
  const s = this.getPage(t);
967
967
  s ? s.children ? s.children.push(e) : s.children = [e] : console.warn(`not found PageFile for id: ${t} `);
@@ -973,9 +973,9 @@ class S {
973
973
  type: "create",
974
974
  data: e
975
975
  };
976
- n.emit(A, s), n.emit(l, s);
976
+ n.emit(A, s), n.emit(d, s);
977
977
  }
978
- !this.currentFile && !e.dir && (await P(1e3), this.active(e, i));
978
+ !this.currentFile && !e.dir && (await O(1e3), this.active(e, i));
979
979
  }
980
980
  /**
981
981
  * 更新页面
@@ -990,7 +990,7 @@ class S {
990
990
  type: "update",
991
991
  data: e
992
992
  };
993
- n.emit(A, s), n.emit(l, s);
993
+ n.emit(A, s), n.emit(d, s);
994
994
  }
995
995
  }
996
996
  /**
@@ -1000,11 +1000,11 @@ class S {
1000
1000
  * @param silent
1001
1001
  */
1002
1002
  clonePage(e, t, i = !1) {
1003
- const s = m(), a = `${e.name}Copy`, o = `${e.title}_副本`, d = new u({
1003
+ const s = m(), a = `${e.name}Copy`, o = `${e.title}_副本`, r = new u({
1004
1004
  id: s,
1005
1005
  name: a
1006
- }).toDsl(), c = I({}, e, { id: s, name: a, title: o, dsl: d }), p = t ? this.getPage(t)?.children || [] : this.pages, O = p.findIndex((E) => E.id === e.id);
1007
- if (p.splice(O + 1, 0, c), !i) {
1006
+ }).toDsl(), c = I({}, e, { id: s, name: a, title: o, dsl: r }), p = t ? this.getPage(t)?.children || [] : this.pages, P = p.findIndex((E) => E.id === e.id);
1007
+ if (p.splice(P + 1, 0, c), !i) {
1008
1008
  const E = {
1009
1009
  model: this,
1010
1010
  type: "clone",
@@ -1013,16 +1013,16 @@ class S {
1013
1013
  target: c
1014
1014
  }
1015
1015
  };
1016
- n.emit(A, E), n.emit(l, E);
1016
+ n.emit(A, E), n.emit(d, E);
1017
1017
  }
1018
1018
  }
1019
1019
  async saveToBlock(e, t = !1) {
1020
- this.active(e, t), await P(1e3);
1020
+ this.active(e, t), await O(1e3);
1021
1021
  const i = m(), s = e.name, a = e.title, o = new u({
1022
1022
  ...e.dsl,
1023
1023
  id: i,
1024
1024
  name: s
1025
- }).toDsl(), d = I({}, e, {
1025
+ }).toDsl(), r = I({}, e, {
1026
1026
  id: i,
1027
1027
  name: s,
1028
1028
  title: a,
@@ -1030,13 +1030,13 @@ class S {
1030
1030
  type: "block",
1031
1031
  fromType: "Schema"
1032
1032
  });
1033
- if (this.blocks.push(d), !t) {
1033
+ if (this.blocks.push(r), !t) {
1034
1034
  const c = {
1035
1035
  model: this,
1036
1036
  type: "create",
1037
- data: d
1037
+ data: r
1038
1038
  };
1039
- n.emit(y, c), n.emit(l, c);
1039
+ n.emit(y, c), n.emit(d, c);
1040
1040
  }
1041
1041
  }
1042
1042
  /**
@@ -1046,9 +1046,9 @@ class S {
1046
1046
  */
1047
1047
  removePage(e, t = !1) {
1048
1048
  const i = this.getPage(e), s = (a, o) => {
1049
- const d = o.findIndex((c) => c.id === a);
1050
- if (d >= 0) {
1051
- o.splice(d, 1);
1049
+ const r = o.findIndex((c) => c.id === a);
1050
+ if (r >= 0) {
1051
+ o.splice(r, 1);
1052
1052
  return;
1053
1053
  }
1054
1054
  for (const c of o)
@@ -1060,7 +1060,7 @@ class S {
1060
1060
  type: "delete",
1061
1061
  data: i
1062
1062
  };
1063
- n.emit(A, a), n.emit(l, a);
1063
+ n.emit(A, a), n.emit(d, a);
1064
1064
  }
1065
1065
  }
1066
1066
  /**
@@ -1080,7 +1080,7 @@ class S {
1080
1080
  * @param silent
1081
1081
  */
1082
1082
  async createBlock(e, t = !1) {
1083
- const i = e.id || m(), s = R(e.name);
1083
+ const i = e.id || m(), s = D(e.name);
1084
1084
  e.id = i, e.type = "block", e.dsl = new u({ id: i, name: s }).toDsl(), this.blocks.push(e);
1085
1085
  const a = e.fromType || "Schema";
1086
1086
  if (!t) {
@@ -1089,9 +1089,9 @@ class S {
1089
1089
  type: "create",
1090
1090
  data: e
1091
1091
  };
1092
- n.emit(y, o), n.emit(l, o);
1092
+ n.emit(y, o), n.emit(d, o);
1093
1093
  }
1094
- !this.currentFile && a === "Schema" && (await P(1e3), this.active(e, t));
1094
+ !this.currentFile && a === "Schema" && (await O(1e3), this.active(e, t));
1095
1095
  }
1096
1096
  /**
1097
1097
  *
@@ -1106,24 +1106,24 @@ class S {
1106
1106
  type: "update",
1107
1107
  data: e
1108
1108
  };
1109
- n.emit(y, s), n.emit(l, s);
1109
+ n.emit(y, s), n.emit(d, s);
1110
1110
  }
1111
1111
  }
1112
1112
  cloneBlock(e, t = !1) {
1113
1113
  const i = m(), s = `${e.name}Copy`, a = `${e.title}_副本`, o = new u({
1114
1114
  id: i,
1115
1115
  name: s
1116
- }).toDsl(), d = I({}, e, { id: i, name: s, title: a, dsl: o }), c = this.blocks.findIndex((p) => p.id === e.id);
1117
- if (this.blocks.splice(c + 1, 0, d), !t) {
1116
+ }).toDsl(), r = I({}, e, { id: i, name: s, title: a, dsl: o }), c = this.blocks.findIndex((p) => p.id === e.id);
1117
+ if (this.blocks.splice(c + 1, 0, r), !t) {
1118
1118
  const p = {
1119
1119
  model: this,
1120
1120
  type: "clone",
1121
1121
  data: {
1122
1122
  source: e,
1123
- target: d
1123
+ target: r
1124
1124
  }
1125
1125
  };
1126
- n.emit(y, p), n.emit(l, p);
1126
+ n.emit(y, p), n.emit(d, p);
1127
1127
  }
1128
1128
  }
1129
1129
  /**
@@ -1139,7 +1139,7 @@ class S {
1139
1139
  type: "delete",
1140
1140
  data: i
1141
1141
  };
1142
- n.emit(y, o), n.emit(l, o);
1142
+ n.emit(y, o), n.emit(d, o);
1143
1143
  }
1144
1144
  }
1145
1145
  /**
@@ -1176,7 +1176,19 @@ class S {
1176
1176
  type: s,
1177
1177
  data: e
1178
1178
  };
1179
- n.emit(B, a), n.emit(l, a);
1179
+ n.emit(V, a), n.emit(d, a);
1180
+ }
1181
+ }
1182
+ setApis(e, t = !1) {
1183
+ for (const i of e)
1184
+ this.setApi(i, !0);
1185
+ if (!t) {
1186
+ const i = {
1187
+ model: this,
1188
+ type: "create",
1189
+ data: e
1190
+ };
1191
+ n.emit(V, i), n.emit(d, i);
1180
1192
  }
1181
1193
  }
1182
1194
  /**
@@ -1192,7 +1204,7 @@ class S {
1192
1204
  type: "delete",
1193
1205
  data: e
1194
1206
  };
1195
- n.emit(B, s), n.emit(l, s);
1207
+ n.emit(V, s), n.emit(d, s);
1196
1208
  }
1197
1209
  }
1198
1210
  existApiName(e, t = []) {
@@ -1209,7 +1221,7 @@ class S {
1209
1221
  type: s,
1210
1222
  data: e
1211
1223
  };
1212
- n.emit(w, a), n.emit(l, a);
1224
+ n.emit(w, a), n.emit(d, a);
1213
1225
  }
1214
1226
  }
1215
1227
  removeMeta(e, t = !1) {
@@ -1220,7 +1232,7 @@ class S {
1220
1232
  type: "delete",
1221
1233
  data: e
1222
1234
  };
1223
- n.emit(w, s), n.emit(l, s);
1235
+ n.emit(w, s), n.emit(d, s);
1224
1236
  }
1225
1237
  }
1226
1238
  existMetaCode(e, t = []) {
@@ -1233,7 +1245,7 @@ class S {
1233
1245
  type: "update",
1234
1246
  data: e
1235
1247
  };
1236
- n.emit(l, i);
1248
+ n.emit(d, i);
1237
1249
  }
1238
1250
  }
1239
1251
  setConfig(e, t = !1) {
@@ -1243,7 +1255,7 @@ class S {
1243
1255
  type: "update",
1244
1256
  data: e
1245
1257
  };
1246
- n.emit(l, i);
1258
+ n.emit(d, i);
1247
1259
  }
1248
1260
  }
1249
1261
  setUniConfig(e, t, i = !1) {
@@ -1253,7 +1265,7 @@ class S {
1253
1265
  type: "update",
1254
1266
  data: this.uniConfig
1255
1267
  };
1256
- n.emit(l, s);
1268
+ n.emit(d, s);
1257
1269
  }
1258
1270
  }
1259
1271
  setGloblas(e, t, i = !1) {
@@ -1263,7 +1275,7 @@ class S {
1263
1275
  type: "update",
1264
1276
  data: this.globals
1265
1277
  };
1266
- n.emit(l, s);
1278
+ n.emit(d, s);
1267
1279
  }
1268
1280
  }
1269
1281
  publish(e) {
@@ -1289,7 +1301,7 @@ class S {
1289
1301
  type: "update",
1290
1302
  data: e
1291
1303
  };
1292
- n.emit(l, t);
1304
+ n.emit(d, t);
1293
1305
  }
1294
1306
  unlock(e) {
1295
1307
  if (e !== this.locked)
@@ -1300,10 +1312,20 @@ class S {
1300
1312
  type: "update",
1301
1313
  data: null
1302
1314
  };
1303
- n.emit(l, t);
1315
+ n.emit(d, t);
1316
+ }
1317
+ getPageRoutes(e, t) {
1318
+ const i = this.platform === "uniapp", s = e || (i ? "pages" : "page"), a = this.getPages(), o = t || "";
1319
+ return a.map((r) => ({
1320
+ id: r.id,
1321
+ path: `${o}/${s}/${r.id}`,
1322
+ name: r.name,
1323
+ title: r.title,
1324
+ meta: r.meta
1325
+ }));
1304
1326
  }
1305
1327
  }
1306
- const N = "EVENT_HISTORY_CHANGE", V = "EVENT_HISTORY_LOAD";
1328
+ const N = "EVENT_HISTORY_CHANGE", S = "EVENT_HISTORY_LOAD";
1307
1329
  class te {
1308
1330
  options = { max: 50 };
1309
1331
  index = -1;
@@ -1372,7 +1394,7 @@ class te {
1372
1394
  if (t < 0) return;
1373
1395
  --this.index;
1374
1396
  const s = i[this.index];
1375
- s && !e && n.emit(V, {
1397
+ s && !e && n.emit(S, {
1376
1398
  model: this,
1377
1399
  type: "load",
1378
1400
  data: s
@@ -1383,7 +1405,7 @@ class te {
1383
1405
  if (t >= i.length - 1) return;
1384
1406
  t < 0 && (this.index = 0), ++this.index;
1385
1407
  const s = i[this.index];
1386
- s && !e && n.emit(V, {
1408
+ s && !e && n.emit(S, {
1387
1409
  model: this,
1388
1410
  type: "load",
1389
1411
  data: s
@@ -1391,7 +1413,7 @@ class te {
1391
1413
  }
1392
1414
  load(e, t = !1) {
1393
1415
  const i = this.items.findIndex((s) => s.id === e);
1394
- i >= 0 && (this.index = i, t || n.emit(V, {
1416
+ i >= 0 && (this.index = i, t || n.emit(S, {
1395
1417
  model: this,
1396
1418
  type: "load",
1397
1419
  data: this.items[i]
@@ -1446,15 +1468,15 @@ export {
1446
1468
  ee as Base,
1447
1469
  u as BlockModel,
1448
1470
  v as DirectiveModel,
1449
- r as EVENT_BLOCK_CHANGE,
1471
+ l as EVENT_BLOCK_CHANGE,
1450
1472
  N as EVENT_HISTORY_CHANGE,
1451
- V as EVENT_HISTORY_LOAD,
1473
+ S as EVENT_HISTORY_LOAD,
1452
1474
  h as EVENT_NODE_CHANGE,
1453
- D as EVENT_PROJECT_ACTIVED,
1454
- B as EVENT_PROJECT_APIS_CHANGE,
1475
+ b as EVENT_PROJECT_ACTIVED,
1476
+ V as EVENT_PROJECT_APIS_CHANGE,
1455
1477
  y as EVENT_PROJECT_BLOCKS_CHANGE,
1456
- l as EVENT_PROJECT_CHANGE,
1457
- b as EVENT_PROJECT_DEPS_CHANGE,
1478
+ d as EVENT_PROJECT_CHANGE,
1479
+ B as EVENT_PROJECT_DEPS_CHANGE,
1458
1480
  $ as EVENT_PROJECT_FILE_PUBLISH,
1459
1481
  M as EVENT_PROJECT_GEN_SOURCE,
1460
1482
  w as EVENT_PROJECT_META_CHANGE,
@@ -1463,7 +1485,7 @@ export {
1463
1485
  x as EventModel,
1464
1486
  te as HistoryModel,
1465
1487
  _ as NodeModel,
1466
- S as ProjectModel,
1488
+ k as ProjectModel,
1467
1489
  g as PropModel,
1468
1490
  Z as Service,
1469
1491
  Y as VTJ_CORE_VERSION,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/core",
3
3
  "private": false,
4
- "version": "0.13.13",
4
+ "version": "0.13.14",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -176,6 +176,7 @@ export declare class ProjectModel {
176
176
  * @param silent
177
177
  */
178
178
  setApi(item: ApiSchema, silent?: boolean): void;
179
+ setApis(items: ApiSchema[], silent?: boolean): void;
179
180
  /**
180
181
  * 删除api
181
182
  * @param name
@@ -194,4 +195,11 @@ export declare class ProjectModel {
194
195
  genSource(): void;
195
196
  lock(id: string): void;
196
197
  unlock(id: string): void;
198
+ getPageRoutes(pageRouteName?: string, pageBasePath?: string): {
199
+ id: string;
200
+ path: string;
201
+ name: string;
202
+ title: string;
203
+ meta: Record<string, any> | undefined;
204
+ }[];
197
205
  }
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2025, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/core
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.13.12
5
+ * @version 0.13.13
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.13.12";
8
+ export declare const version = "0.13.13";