@vtj/core 0.13.14 → 0.13.16

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.14
5
+ * @version 0.13.16
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
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;
7
+ */const U="0.13.16",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"],M=[{label:"简体中文",value:"zh-CN"},{label:"English",value:"en"}];class ${}class K{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 C{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 C(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:l,id:f}=t;return{id:f,name:i,arg:s,modifiers:a,value:o,iterator:l}})}}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:l={},events:f={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(a,!0),this.setSlot(o,!0),this.props=v.parse(l),this.events=C.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 C(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:l,props:f,directives:p,events:P}=this,T=Array.isArray(l)?l.map(H=>H.toDsl()):l;return{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:T,props:v.toDsl(f),directives:E.toDsl(p),events:C.toDsl(P)}}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,l)=>(o[l]=this[l],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 c="EVENT_PROJECT_CHANGE",x="EVENT_PROJECT_ACTIVED",V="EVENT_PROJECT_DEPS_CHANGE",g="EVENT_PROJECT_PAGES_CHANGE",N="EVENT_PROJECT_BLOCKS_CHANGE",A="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",k="EVENT_PROJECT_PUBLISH",b="EVENT_PROJECT_FILE_PUBLISH",L="EVENT_PROJECT_GEN_SOURCE";class I{id="";locked="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};globals={};i18n={locale:"zh-CN",fallbackLocale:"zh-CN",messages:[]};__BASE_PATH__="/";__UID__=r.uuid(!0);static attrs=["locked","platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","globals","i18n","__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 I.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=I.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(x,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(x,{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}_副本`,l=new u({id:s,name:a}).toDsl(),f=r.merge({},e,{id:s,name:a,title:o,dsl:l}),p=t?this.getPage(t)?.children||[]:this.pages,P=p.findIndex(T=>T.id===e.id);if(p.splice(P+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(),l=r.merge({},e,{id:i,name:s,title:a,dsl:o,type:"block",fromType:"Schema"});if(this.blocks.push(l),!t){const f={model:this,type:"create",data:l};n.emit(N,f),n.emit(c,f)}}removePage(e,t=!1){const i=this.getPage(e),s=(a,o)=>{const l=o.findIndex(f=>f.id===a);if(l>=0){o.splice(l,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(N,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(N,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(),l=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,l),!t){const p={model:this,type:"clone",data:{source:e,target:l}};n.emit(N,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(N,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(A,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(A,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(A,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)}}setI18n(e,t=!1){if(this.i18n=Object.assign(this.i18n,e),!t){const i={model:this,type:"update",data:this.i18n};n.emit(c,i)}}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(L,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(l=>({id:l.id,path:`${o}/${s}/${l.id}`,name:l.name,title:l.title,meta:l.meta}))}}const y="EVENT_HISTORY_CHANGE",O="EVENT_HISTORY_LOAD";class Y{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(y,{model:this,type:"delete",data:a.map(o=>o.id)})}this.index=-1,t||n.emit(y,{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(y,{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(O,{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(O,{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(O,{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(y,{model:this,type:"clear",data:t})}}const n=r.mitt();function z(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 Q(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=K;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=d;exports.EVENT_HISTORY_CHANGE=y;exports.EVENT_HISTORY_LOAD=O;exports.EVENT_NODE_CHANGE=h;exports.EVENT_PROJECT_ACTIVED=x;exports.EVENT_PROJECT_APIS_CHANGE=A;exports.EVENT_PROJECT_BLOCKS_CHANGE=N;exports.EVENT_PROJECT_CHANGE=c;exports.EVENT_PROJECT_DEPS_CHANGE=V;exports.EVENT_PROJECT_FILE_PUBLISH=b;exports.EVENT_PROJECT_GEN_SOURCE=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=g;exports.EVENT_PROJECT_PUBLISH=k;exports.EventModel=C;exports.HistoryModel=Y;exports.I18N_LOCALES=M;exports.NodeModel=_;exports.ProjectModel=I;exports.PropModel=v;exports.Service=$;exports.VTJ_CORE_VERSION=U;exports.cloneDsl=D;exports.createNodeFrom=Q;exports.emitter=n;exports.isBlock=z;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 R, cloneDeep as C, upperFirstCamelCase as D, delay as O, merge as I, mitt as F } from "@vtj/base";
1
+ import { uid as m, timestamp as G, isString as T, uuid as b, cloneDeep as C, upperFirstCamelCase as R, delay as P, merge as I, mitt as j } 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.14
6
+ * @version 0.13.16
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const Y = "0.13.14", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial", q = [H, J], z = {
9
+ const Y = "0.13.16", z = "BuiltIn", H = "VueMaterial", L = "VueRouterMaterial", W = [H, L], q = {
10
10
  vue: "Vue",
11
11
  "vue-router": "VueRouter"
12
12
  }, Q = {
@@ -17,7 +17,7 @@ const Y = "0.13.14", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial",
17
17
  "Teleport",
18
18
  "Suspense"
19
19
  ],
20
- [J]: ["RouterView", "RouterLink"]
20
+ [L]: ["RouterView", "RouterLink"]
21
21
  }, X = [
22
22
  "slot",
23
23
  "template",
@@ -30,10 +30,19 @@ const Y = "0.13.14", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial",
30
30
  "h3",
31
31
  "span",
32
32
  "a"
33
+ ], Z = [
34
+ {
35
+ label: "简体中文",
36
+ value: "zh-CN"
37
+ },
38
+ {
39
+ label: "English",
40
+ value: "en"
41
+ }
33
42
  ];
34
- class Z {
35
- }
36
43
  class ee {
44
+ }
45
+ class te {
37
46
  listeners = [];
38
47
  isReady = !1;
39
48
  triggerReady() {
@@ -390,7 +399,7 @@ class _ {
390
399
  children: r,
391
400
  props: c,
392
401
  directives: p,
393
- events: P
402
+ events: O
394
403
  } = this, E = Array.isArray(r) ? r.map((U) => U.toDsl()) : r;
395
404
  return {
396
405
  id: e,
@@ -402,7 +411,7 @@ class _ {
402
411
  children: E,
403
412
  props: g.toDsl(c),
404
413
  directives: v.toDsl(p),
405
- events: x.toDsl(P)
414
+ events: x.toDsl(O)
406
415
  };
407
416
  }
408
417
  /**
@@ -760,7 +769,7 @@ class u {
760
769
  * @returns
761
770
  */
762
771
  cloneNode(e, t = !1) {
763
- const i = L(e.toDsl()), s = new _(i);
772
+ const i = J(e.toDsl()), s = new _(i);
764
773
  return this.addNode(s, e, "bottom", t), s;
765
774
  }
766
775
  lock(e = !1) {
@@ -786,7 +795,7 @@ class u {
786
795
  return t;
787
796
  }
788
797
  }
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";
798
+ const d = "EVENT_PROJECT_CHANGE", D = "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", F = "EVENT_PROJECT_PUBLISH", $ = "EVENT_PROJECT_FILE_PUBLISH", M = "EVENT_PROJECT_GEN_SOURCE";
790
799
  class k {
791
800
  id = "";
792
801
  locked = "";
@@ -803,8 +812,13 @@ class k {
803
812
  config = {};
804
813
  uniConfig = {};
805
814
  globals = {};
815
+ i18n = {
816
+ locale: "zh-CN",
817
+ fallbackLocale: "zh-CN",
818
+ messages: []
819
+ };
806
820
  __BASE_PATH__ = "/";
807
- __UID__ = R(!0);
821
+ __UID__ = b(!0);
808
822
  static attrs = [
809
823
  "locked",
810
824
  "platform",
@@ -819,12 +833,13 @@ class k {
819
833
  "config",
820
834
  "uniConfig",
821
835
  "globals",
836
+ "i18n",
822
837
  "__BASE_PATH__",
823
838
  "__UID__"
824
839
  ];
825
840
  constructor(e) {
826
841
  const { id: t, __UID__: i } = e;
827
- this.id = t || m(), this.__UID__ = i || R(!0), this.update(e, !0);
842
+ this.id = t || m(), this.__UID__ = i || b(!0), this.update(e, !0);
828
843
  }
829
844
  update(e, t = !1) {
830
845
  for (const i of k.attrs) {
@@ -867,7 +882,7 @@ class k {
867
882
  * @param silent
868
883
  */
869
884
  active(e, t = !1) {
870
- this.currentFile = e, t || n.emit(b, {
885
+ this.currentFile = e, t || n.emit(D, {
871
886
  model: this,
872
887
  type: "update",
873
888
  data: e
@@ -878,7 +893,7 @@ class k {
878
893
  * @param silent
879
894
  */
880
895
  deactivate(e = !1) {
881
- this.currentFile = null, e || n.emit(b, {
896
+ this.currentFile = null, e || n.emit(D, {
882
897
  model: this,
883
898
  type: "update",
884
899
  data: null
@@ -961,7 +976,7 @@ class k {
961
976
  async createPage(e, t, i = !1) {
962
977
  if (e.id = e.raw ? e.name : e.id || m(), e.type = "page", e.dir ? e.children = [] : e.dsl = e.dsl || new u({
963
978
  id: e.id,
964
- name: D(e.name)
979
+ name: R(e.name)
965
980
  }).toDsl(), t) {
966
981
  const s = this.getPage(t);
967
982
  s ? s.children ? s.children.push(e) : s.children = [e] : console.warn(`not found PageFile for id: ${t} `);
@@ -975,7 +990,7 @@ class k {
975
990
  };
976
991
  n.emit(A, s), n.emit(d, s);
977
992
  }
978
- !this.currentFile && !e.dir && (await O(1e3), this.active(e, i));
993
+ !this.currentFile && !e.dir && (await P(1e3), this.active(e, i));
979
994
  }
980
995
  /**
981
996
  * 更新页面
@@ -1003,8 +1018,8 @@ class k {
1003
1018
  const s = m(), a = `${e.name}Copy`, o = `${e.title}_副本`, r = new u({
1004
1019
  id: s,
1005
1020
  name: a
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) {
1021
+ }).toDsl(), c = I({}, e, { id: s, name: a, title: o, dsl: r }), p = t ? this.getPage(t)?.children || [] : this.pages, O = p.findIndex((E) => E.id === e.id);
1022
+ if (p.splice(O + 1, 0, c), !i) {
1008
1023
  const E = {
1009
1024
  model: this,
1010
1025
  type: "clone",
@@ -1017,7 +1032,7 @@ class k {
1017
1032
  }
1018
1033
  }
1019
1034
  async saveToBlock(e, t = !1) {
1020
- this.active(e, t), await O(1e3);
1035
+ this.active(e, t), await P(1e3);
1021
1036
  const i = m(), s = e.name, a = e.title, o = new u({
1022
1037
  ...e.dsl,
1023
1038
  id: i,
@@ -1080,7 +1095,7 @@ class k {
1080
1095
  * @param silent
1081
1096
  */
1082
1097
  async createBlock(e, t = !1) {
1083
- const i = e.id || m(), s = D(e.name);
1098
+ const i = e.id || m(), s = R(e.name);
1084
1099
  e.id = i, e.type = "block", e.dsl = new u({ id: i, name: s }).toDsl(), this.blocks.push(e);
1085
1100
  const a = e.fromType || "Schema";
1086
1101
  if (!t) {
@@ -1091,7 +1106,7 @@ class k {
1091
1106
  };
1092
1107
  n.emit(y, o), n.emit(d, o);
1093
1108
  }
1094
- !this.currentFile && a === "Schema" && (await O(1e3), this.active(e, t));
1109
+ !this.currentFile && a === "Schema" && (await P(1e3), this.active(e, t));
1095
1110
  }
1096
1111
  /**
1097
1112
  *
@@ -1278,13 +1293,23 @@ class k {
1278
1293
  n.emit(d, s);
1279
1294
  }
1280
1295
  }
1296
+ setI18n(e, t = !1) {
1297
+ if (this.i18n = Object.assign(this.i18n, e), !t) {
1298
+ const i = {
1299
+ model: this,
1300
+ type: "update",
1301
+ data: this.i18n
1302
+ };
1303
+ n.emit(d, i);
1304
+ }
1305
+ }
1281
1306
  publish(e) {
1282
1307
  const t = {
1283
1308
  model: this,
1284
1309
  type: "publish",
1285
1310
  data: e || this
1286
1311
  };
1287
- e ? n.emit($, t) : n.emit(j, t);
1312
+ e ? n.emit($, t) : n.emit(F, t);
1288
1313
  }
1289
1314
  genSource() {
1290
1315
  const e = {
@@ -1326,7 +1351,7 @@ class k {
1326
1351
  }
1327
1352
  }
1328
1353
  const N = "EVENT_HISTORY_CHANGE", S = "EVENT_HISTORY_LOAD";
1329
- class te {
1354
+ class ie {
1330
1355
  options = { max: 50 };
1331
1356
  index = -1;
1332
1357
  id;
@@ -1429,21 +1454,21 @@ class te {
1429
1454
  });
1430
1455
  }
1431
1456
  }
1432
- const n = F();
1433
- function ie(f) {
1457
+ const n = j();
1458
+ function se(f) {
1434
1459
  return f instanceof u;
1435
1460
  }
1436
- function se(f) {
1461
+ function ne(f) {
1437
1462
  return f instanceof _;
1438
1463
  }
1439
- function ne(f) {
1464
+ function ae(f) {
1440
1465
  return !!f.__VTJ_BLOCK__;
1441
1466
  }
1442
- function L(f) {
1467
+ function J(f) {
1443
1468
  const e = C(f);
1444
- return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) => L(t))), e;
1469
+ return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) => J(t))), e;
1445
1470
  }
1446
- function ae(f) {
1471
+ function oe(f) {
1447
1472
  const e = f.fromType || "Schema";
1448
1473
  return e === "Schema" ? {
1449
1474
  type: "Schema",
@@ -1459,20 +1484,20 @@ function ae(f) {
1459
1484
  }
1460
1485
  export {
1461
1486
  Q as BUILT_IN_COMPONENTS,
1462
- z as BUILT_IN_LIBRARAY_MAP,
1463
- q as BUILT_IN_MATERIALS,
1464
- W as BUILT_IN_NAME,
1487
+ q as BUILT_IN_LIBRARAY_MAP,
1488
+ W as BUILT_IN_MATERIALS,
1489
+ z as BUILT_IN_NAME,
1465
1490
  X as BUILT_IN_TAGS,
1466
1491
  H as BUILT_IN_VUE,
1467
- J as BUILT_IN_VUE_ROUTER,
1468
- ee as Base,
1492
+ L as BUILT_IN_VUE_ROUTER,
1493
+ te as Base,
1469
1494
  u as BlockModel,
1470
1495
  v as DirectiveModel,
1471
1496
  l as EVENT_BLOCK_CHANGE,
1472
1497
  N as EVENT_HISTORY_CHANGE,
1473
1498
  S as EVENT_HISTORY_LOAD,
1474
1499
  h as EVENT_NODE_CHANGE,
1475
- b as EVENT_PROJECT_ACTIVED,
1500
+ D as EVENT_PROJECT_ACTIVED,
1476
1501
  V as EVENT_PROJECT_APIS_CHANGE,
1477
1502
  y as EVENT_PROJECT_BLOCKS_CHANGE,
1478
1503
  d as EVENT_PROJECT_CHANGE,
@@ -1481,18 +1506,19 @@ export {
1481
1506
  M as EVENT_PROJECT_GEN_SOURCE,
1482
1507
  w as EVENT_PROJECT_META_CHANGE,
1483
1508
  A as EVENT_PROJECT_PAGES_CHANGE,
1484
- j as EVENT_PROJECT_PUBLISH,
1509
+ F as EVENT_PROJECT_PUBLISH,
1485
1510
  x as EventModel,
1486
- te as HistoryModel,
1511
+ ie as HistoryModel,
1512
+ Z as I18N_LOCALES,
1487
1513
  _ as NodeModel,
1488
1514
  k as ProjectModel,
1489
1515
  g as PropModel,
1490
- Z as Service,
1516
+ ee as Service,
1491
1517
  Y as VTJ_CORE_VERSION,
1492
- L as cloneDsl,
1493
- ae as createNodeFrom,
1518
+ J as cloneDsl,
1519
+ oe as createNodeFrom,
1494
1520
  n as emitter,
1495
- ie as isBlock,
1496
- ne as isBlockSchema,
1497
- se as isNode
1521
+ se as isBlock,
1522
+ ae as isBlockSchema,
1523
+ ne as isNode
1498
1524
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/core",
3
3
  "private": false,
4
- "version": "0.13.14",
4
+ "version": "0.13.16",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -23,3 +23,7 @@ export declare const BUILT_IN_LIBRARAY_MAP: Record<string, string>;
23
23
  */
24
24
  export declare const BUILT_IN_COMPONENTS: Record<string, string[]>;
25
25
  export declare const BUILT_IN_TAGS: string[];
26
+ export declare const I18N_LOCALES: {
27
+ label: string;
28
+ value: string;
29
+ }[];
@@ -1,4 +1,4 @@
1
- import { ProjectSchema, Dependencie, PageFile, BlockFile, ApiSchema, MetaSchema, ProjectConfig, UniConfig, PlatformType, GlobalConfig, JSFunction } from '../protocols';
1
+ import { ProjectSchema, Dependencie, PageFile, BlockFile, ApiSchema, MetaSchema, ProjectConfig, UniConfig, PlatformType, GlobalConfig, JSFunction, I18nConfig } from '../protocols';
2
2
  import { ModelEventType } from '../tools';
3
3
  export interface ProjectModelEvent {
4
4
  model: ProjectModel;
@@ -61,6 +61,7 @@ export declare class ProjectModel {
61
61
  config: ProjectConfig;
62
62
  uniConfig: UniConfig;
63
63
  globals: GlobalConfig;
64
+ i18n: I18nConfig;
64
65
  __BASE_PATH__: string;
65
66
  __UID__: string;
66
67
  static attrs: string[];
@@ -191,6 +192,7 @@ export declare class ProjectModel {
191
192
  setConfig(config: ProjectConfig, silent?: boolean): void;
192
193
  setUniConfig(key: keyof UniConfig, value: Record<string, any>, silent?: boolean): void;
193
194
  setGloblas(key: keyof GlobalConfig, value: string | JSFunction, silent?: boolean): void;
195
+ setI18n(i18n: I18nConfig, silent?: boolean): void;
194
196
  publish(file?: PageFile | BlockFile): void;
195
197
  genSource(): void;
196
198
  lock(id: string): void;
@@ -62,6 +62,10 @@ export interface ProjectSchema {
62
62
  * (Web、H5)应用全局配置
63
63
  */
64
64
  globals?: GlobalConfig;
65
+ /**
66
+ * 国际化
67
+ */
68
+ i18n?: I18nConfig;
65
69
  /**
66
70
  * 标记
67
71
  */
@@ -194,3 +198,33 @@ export interface GlobalConfig {
194
198
  */
195
199
  afterEach?: JSFunction;
196
200
  }
201
+ /**
202
+ * 国际化配置
203
+ */
204
+ export interface I18nConfig {
205
+ /**
206
+ * 默认本地化语言
207
+ */
208
+ locale?: I18nLocale;
209
+ /**
210
+ * 兜底语言
211
+ */
212
+ fallbackLocale?: I18nLocale;
213
+ /**
214
+ * 语言包
215
+ */
216
+ messages?: I18nMessage[];
217
+ }
218
+ /**
219
+ * 本地语言名
220
+ */
221
+ export type I18nLocale = 'zh-CN' | 'en';
222
+ /**
223
+ * 语言信息项
224
+ */
225
+ export interface I18nMessage {
226
+ key: string;
227
+ ['zh-CN']: string;
228
+ en: string;
229
+ [index: string]: string;
230
+ }
@@ -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.13
5
+ * @version 0.13.15
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.13.13";
8
+ export declare const version = "0.13.15";