@vtj/core 0.12.70 → 0.13.0

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.12.70
5
+ * @version 0.13.0
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const U="0.12.70",J="BuiltIn",R="VueMaterial",B="VueRouterMaterial",G=[R,B],w={vue:"Vue","vue-router":"VueRouter"},F={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[B]:["RouterView","RouterLink"]},M=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class j{}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 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:o,modifiers:a}=s;return t[i]={name:i,handler:o,modifiers:a},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:o,iterator:a}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=o,this.iterator=a}static parse(e=[]){return e.map(t=>new E(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:o,value:a,iterator:c,id:f}=t;return{id:f,name:i,arg:s,modifiers:o,value:a,iterator:c}})}}const h="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=r.uid(),name:s,from:o=""}=e;this.id=i,this.name=s,this.from=o,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:o=[],slot:a,props:c={},events:f={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(o,!0),this.setSlot(a,!0),this.props=v.parse(c),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 o=this.props[e];o?o.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(o=>o.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 o=i.findIndex(a=>a===e);e.parent=null,i.splice(o,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:o,slot:a,children:c,props:f,directives:p,events:g}=this,T=Array.isArray(c)?c.map(b=>b.toDsl()):c;return{id:e,name:t,from:i,invisible:s,locked:o,slot:a,children:T,props:v.toDsl(f),directives:E.toDsl(p),events:C.toDsl(g)}}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 o=e[s];o!==void 0&&(this[s]=o)}const{nodes:i=[]}=e;i.length&&(this.nodes=i.map(s=>new _(s))),t||n.emit(d,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((a,c)=>(a[c]=this[c],a),{}),__VTJ_BLOCK__:t,__VERSION__:e||r.timestamp().toString(),id:i,nodes:s.map(a=>a.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(o=>o===i.name||o.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(o=>o===i.name||o.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",I="EVENT_PROJECT_ACTIVED",P="EVENT_PROJECT_DEPS_CHANGE",y="EVENT_PROJECT_PAGES_CHANGE",N="EVENT_PROJECT_BLOCKS_CHANGE",V="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",k="EVENT_PROJECT_PUBLISH",H="EVENT_PROJECT_FILE_PUBLISH",L="EVENT_PROJECT_GEN_SOURCE";class O{id="";locked="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};__BASE_PATH__="/";__UID__=r.uuid(!0);static attrs=["locked","platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","__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 O.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=O.attrs.reduce((s,o)=>(s[o]=this[o],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(a=>a.package===e.package);let o;if(s>-1?(o="update",i.splice(s,1,{...i[s],...e})):(o="create",i.push(e)),!t){const a={model:this,type:o,data:e};n.emit(P,a),n.emit(l,a)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(o=>o.package===e.package);if(s>-1&&i.splice(s,1),!t){const o={model:this,type:"delete",data:e};n.emit(P,o),n.emit(l,o)}}getPage(e){const t=(i,s=[])=>{for(const o of s){if(o.id===i)return o;if(o.children&&o.children.length){const a=t(i,o.children);if(a)return a}}};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(y,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(y,s),n.emit(l,s)}}clonePage(e,t,i=!1){const s=r.uid(),o=`${e.name}Copy`,a=`${e.title}_副本`,c=new u({id:s,name:o}).toDsl(),f=r.merge({},e,{id:s,name:o,title:a,dsl:c}),p=t?this.getPage(t)?.children||[]:this.pages,g=p.findIndex(T=>T.id===e.id);if(p.splice(g+1,0,f),!i){const T={model:this,type:"clone",data:{source:e,target:f}};n.emit(y,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,o=e.title,a=new u({...e.dsl,id:i,name:s}).toDsl(),c=r.merge({},e,{id:i,name:s,title:o,dsl:a,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=(o,a)=>{const c=a.findIndex(f=>f.id===o);if(c>=0){a.splice(c,1);return}for(const f of a)f.children&&f.children.length&&s(o,f.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const o={model:this,type:"delete",data:i};n.emit(y,o),n.emit(l,o)}}getBlock(e){return this.blocks.find(t=>t.id===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 o=e.fromType||"Schema";if(!t){const a={model:this,type:"create",data:e};n.emit(N,a),n.emit(l,a)}!this.currentFile&&o==="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`,o=`${e.title}_副本`,a=new u({id:i,name:s}).toDsl(),c=r.merge({},e,{id:i,name:s,title:o,dsl:a}),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,o=s.findIndex(a=>a.id===e);if(o>-1?(s.splice(o,1),this.currentFile?.id===e&&this.deactivate(t)):console.warn(`not found PageFile for id: ${e} `),!t){const a={model:this,type:"delete",data:i};n.emit(N,a),n.emit(l,a)}}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(o=>o.name===e.name||o.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 o={model:this,type:s,data:e};n.emit(V,o),n.emit(l,o)}}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(o=>o.code===e.code||o.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 o={model:this,type:s,data:e};n.emit(S,o),n.emit(l,o)}}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)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(H,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(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",x="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 o=this.items.splice(i);t||n.emit(A,{model:this,type:"delete",data:o.map(a=>a.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(x,{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(x,{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(x,{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=G;exports.BUILT_IN_NAME=J;exports.BUILT_IN_TAGS=M;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=x;exports.EVENT_NODE_CHANGE=h;exports.EVENT_PROJECT_ACTIVED=I;exports.EVENT_PROJECT_APIS_CHANGE=V;exports.EVENT_PROJECT_BLOCKS_CHANGE=N;exports.EVENT_PROJECT_CHANGE=l;exports.EVENT_PROJECT_DEPS_CHANGE=P;exports.EVENT_PROJECT_FILE_PUBLISH=H;exports.EVENT_PROJECT_GEN_SOURCE=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=y;exports.EVENT_PROJECT_PUBLISH=k;exports.EventModel=C;exports.HistoryModel=K;exports.NodeModel=_;exports.ProjectModel=O;exports.PropModel=v;exports.Service=j;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.0",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))),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;
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { uid as m, timestamp as G, isString as A, 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 k, cloneDeep as C, upperFirstCamelCase as R, delay as P, 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.12.70
6
+ * @version 0.13.0
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const Y = "0.12.70", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial", q = [H, J], z = {
9
+ const Y = "0.13.0", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial", q = [H, J], z = {
10
10
  vue: "Vue",
11
11
  "vue-router": "VueRouter"
12
12
  }, Q = {
@@ -49,7 +49,7 @@ class ee {
49
49
  this.isReady = !1;
50
50
  }
51
51
  }
52
- class x {
52
+ class g {
53
53
  constructor(e, t, i) {
54
54
  this.name = e, this.value = t, this.defaultValue = i, this.setValue(t);
55
55
  }
@@ -67,10 +67,10 @@ class x {
67
67
  return Object.entries(e).reduce((t, [i, s]) => (s.isUnset || (t[i] = s.getValue()), t), {});
68
68
  }
69
69
  static parse(e = {}) {
70
- return Object.entries(e).reduce((t, [i, s]) => (t[i] = new x(i, s), t), {});
70
+ return Object.entries(e).reduce((t, [i, s]) => (t[i] = new g(i, s), t), {});
71
71
  }
72
72
  }
73
- class T {
73
+ class x {
74
74
  constructor(e) {
75
75
  this.schema = e;
76
76
  const { name: t, handler: i } = this.schema;
@@ -92,7 +92,7 @@ class T {
92
92
  }
93
93
  static parse(e = {}) {
94
94
  return Object.entries(e).reduce(
95
- (t, [i, s]) => (t[i] = new T(s), t),
95
+ (t, [i, s]) => (t[i] = new x(s), t),
96
96
  {}
97
97
  );
98
98
  }
@@ -221,7 +221,7 @@ class _ {
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 = x.parse(d), this.events = T.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(d), this.events = x.parse(c), this.directives = v.parse(p), t || n.emit(h, this);
225
225
  }
226
226
  /**
227
227
  * 设置子节点
@@ -248,7 +248,7 @@ class _ {
248
248
  */
249
249
  setProp(e, t, i, s = !1) {
250
250
  const a = this.props[e];
251
- a ? a.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(h, this);
251
+ a ? a.setValue(t) : this.props[e] = new g(e, t, i), s || n.emit(h, this);
252
252
  }
253
253
  /**
254
254
  * 删除属性
@@ -275,7 +275,7 @@ class _ {
275
275
  */
276
276
  setEvent(e, t = !1) {
277
277
  const i = this.events[e.name];
278
- i ? i.update(e) : this.events[e.name] = new T(e), t || n.emit(h, this);
278
+ i ? i.update(e) : this.events[e.name] = new x(e), t || n.emit(h, this);
279
279
  }
280
280
  /**
281
281
  * 删除事件
@@ -400,9 +400,9 @@ class _ {
400
400
  locked: a,
401
401
  slot: o,
402
402
  children: E,
403
- props: x.toDsl(c),
403
+ props: g.toDsl(c),
404
404
  directives: v.toDsl(p),
405
- events: T.toDsl(O)
405
+ events: x.toDsl(O)
406
406
  };
407
407
  }
408
408
  /**
@@ -610,7 +610,7 @@ class u {
610
610
  * @param silent
611
611
  */
612
612
  setEmit(e, t = !1) {
613
- const i = A(e) ? { name: e, params: [] } : e, s = this.emits.findIndex(
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
616
  s > -1 ? this.emits.splice(s, 1, i) : this.emits.push(i), t || n.emit(r, this);
@@ -622,7 +622,7 @@ class u {
622
622
  */
623
623
  removeEmit(e, t = !1) {
624
624
  const i = this.emits.findIndex(
625
- (s) => A(s) ? s === e : s.name === e
625
+ (s) => T(s) ? s === e : s.name === e
626
626
  );
627
627
  i > -1 && (this.emits.splice(i, 1), t || n.emit(r, this));
628
628
  }
@@ -632,7 +632,7 @@ class u {
632
632
  * @param silent
633
633
  */
634
634
  setSlot(e, t = !1) {
635
- const i = A(e) ? { name: e, params: [] } : e, s = this.slots.findIndex(
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
638
  s > -1 ? this.slots.splice(s, 1, i) : this.slots.push(i), t || n.emit(r, this);
@@ -644,7 +644,7 @@ class u {
644
644
  */
645
645
  removeSlot(e, t = !1) {
646
646
  const i = this.slots.findIndex(
647
- (s) => A(s) ? s === e : s.name === e
647
+ (s) => T(s) ? s === e : s.name === e
648
648
  );
649
649
  i > -1 && (this.slots.splice(i, 1), t || n.emit(r, this));
650
650
  }
@@ -786,7 +786,7 @@ 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", g = "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";
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
790
  class S {
791
791
  id = "";
792
792
  locked = "";
@@ -802,6 +802,7 @@ class S {
802
802
  currentFile = null;
803
803
  config = {};
804
804
  uniConfig = {};
805
+ globals = {};
805
806
  __BASE_PATH__ = "/";
806
807
  __UID__ = k(!0);
807
808
  static attrs = [
@@ -817,6 +818,7 @@ class S {
817
818
  "meta",
818
819
  "config",
819
820
  "uniConfig",
821
+ "globals",
820
822
  "__BASE_PATH__",
821
823
  "__UID__"
822
824
  ];
@@ -899,7 +901,7 @@ class S {
899
901
  type: a,
900
902
  data: e
901
903
  };
902
- n.emit(B, o), n.emit(l, o);
904
+ n.emit(b, o), n.emit(l, o);
903
905
  }
904
906
  }
905
907
  /**
@@ -915,7 +917,7 @@ class S {
915
917
  type: "delete",
916
918
  data: e
917
919
  };
918
- n.emit(B, a), n.emit(l, a);
920
+ n.emit(b, a), n.emit(l, a);
919
921
  }
920
922
  }
921
923
  /**
@@ -971,7 +973,7 @@ class S {
971
973
  type: "create",
972
974
  data: e
973
975
  };
974
- n.emit(g, s), n.emit(l, s);
976
+ n.emit(A, s), n.emit(l, s);
975
977
  }
976
978
  !this.currentFile && !e.dir && (await P(1e3), this.active(e, i));
977
979
  }
@@ -988,7 +990,7 @@ class S {
988
990
  type: "update",
989
991
  data: e
990
992
  };
991
- n.emit(g, s), n.emit(l, s);
993
+ n.emit(A, s), n.emit(l, s);
992
994
  }
993
995
  }
994
996
  /**
@@ -1011,7 +1013,7 @@ class S {
1011
1013
  target: c
1012
1014
  }
1013
1015
  };
1014
- n.emit(g, E), n.emit(l, E);
1016
+ n.emit(A, E), n.emit(l, E);
1015
1017
  }
1016
1018
  }
1017
1019
  async saveToBlock(e, t = !1) {
@@ -1058,7 +1060,7 @@ class S {
1058
1060
  type: "delete",
1059
1061
  data: i
1060
1062
  };
1061
- n.emit(g, a), n.emit(l, a);
1063
+ n.emit(A, a), n.emit(l, a);
1062
1064
  }
1063
1065
  }
1064
1066
  /**
@@ -1069,6 +1071,9 @@ class S {
1069
1071
  getBlock(e) {
1070
1072
  return this.blocks.find((t) => t.id === e);
1071
1073
  }
1074
+ getFile(e) {
1075
+ return this.getPage(e) || this.getBlock(e);
1076
+ }
1072
1077
  /**
1073
1078
  * 创建区块
1074
1079
  * @param block
@@ -1171,7 +1176,7 @@ class S {
1171
1176
  type: s,
1172
1177
  data: e
1173
1178
  };
1174
- n.emit(b, a), n.emit(l, a);
1179
+ n.emit(B, a), n.emit(l, a);
1175
1180
  }
1176
1181
  }
1177
1182
  /**
@@ -1187,7 +1192,7 @@ class S {
1187
1192
  type: "delete",
1188
1193
  data: e
1189
1194
  };
1190
- n.emit(b, s), n.emit(l, s);
1195
+ n.emit(B, s), n.emit(l, s);
1191
1196
  }
1192
1197
  }
1193
1198
  existApiName(e, t = []) {
@@ -1251,6 +1256,16 @@ class S {
1251
1256
  n.emit(l, s);
1252
1257
  }
1253
1258
  }
1259
+ setGloblas(e, t, i = !1) {
1260
+ if (this.globals = Object.assign(this.globals, { [e]: t }), !i) {
1261
+ const s = {
1262
+ model: this,
1263
+ type: "update",
1264
+ data: this.globals
1265
+ };
1266
+ n.emit(l, s);
1267
+ }
1268
+ }
1254
1269
  publish(e) {
1255
1270
  const t = {
1256
1271
  model: this,
@@ -1436,20 +1451,20 @@ export {
1436
1451
  V as EVENT_HISTORY_LOAD,
1437
1452
  h as EVENT_NODE_CHANGE,
1438
1453
  D as EVENT_PROJECT_ACTIVED,
1439
- b as EVENT_PROJECT_APIS_CHANGE,
1454
+ B as EVENT_PROJECT_APIS_CHANGE,
1440
1455
  y as EVENT_PROJECT_BLOCKS_CHANGE,
1441
1456
  l as EVENT_PROJECT_CHANGE,
1442
- B as EVENT_PROJECT_DEPS_CHANGE,
1457
+ b as EVENT_PROJECT_DEPS_CHANGE,
1443
1458
  $ as EVENT_PROJECT_FILE_PUBLISH,
1444
1459
  M as EVENT_PROJECT_GEN_SOURCE,
1445
1460
  w as EVENT_PROJECT_META_CHANGE,
1446
- g as EVENT_PROJECT_PAGES_CHANGE,
1461
+ A as EVENT_PROJECT_PAGES_CHANGE,
1447
1462
  j as EVENT_PROJECT_PUBLISH,
1448
- T as EventModel,
1463
+ x as EventModel,
1449
1464
  te as HistoryModel,
1450
1465
  _ as NodeModel,
1451
1466
  S as ProjectModel,
1452
- x as PropModel,
1467
+ g as PropModel,
1453
1468
  Z as Service,
1454
1469
  Y as VTJ_CORE_VERSION,
1455
1470
  L as cloneDsl,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/core",
3
3
  "private": false,
4
- "version": "0.12.70",
4
+ "version": "0.13.0",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -1,4 +1,4 @@
1
- import { ProjectSchema, Dependencie, PageFile, BlockFile, ApiSchema, MetaSchema, ProjectConfig, UniConfig, PlatformType } from '../protocols';
1
+ import { ProjectSchema, Dependencie, PageFile, BlockFile, ApiSchema, MetaSchema, ProjectConfig, UniConfig, PlatformType, GlobalConfig, JSFunction } from '../protocols';
2
2
  import { ModelEventType } from '../tools';
3
3
  export interface ProjectModelEvent {
4
4
  model: ProjectModel;
@@ -60,6 +60,7 @@ export declare class ProjectModel {
60
60
  currentFile: PageFile | BlockFile | null;
61
61
  config: ProjectConfig;
62
62
  uniConfig: UniConfig;
63
+ globals: GlobalConfig;
63
64
  __BASE_PATH__: string;
64
65
  __UID__: string;
65
66
  static attrs: string[];
@@ -135,6 +136,7 @@ export declare class ProjectModel {
135
136
  * @returns
136
137
  */
137
138
  getBlock(id: string): BlockFile | undefined;
139
+ getFile(id: string): BlockFile | PageFile | undefined;
138
140
  /**
139
141
  * 创建区块
140
142
  * @param block
@@ -187,6 +189,7 @@ export declare class ProjectModel {
187
189
  setHomepage(id: string, silent?: boolean): void;
188
190
  setConfig(config: ProjectConfig, silent?: boolean): void;
189
191
  setUniConfig(key: keyof UniConfig, value: Record<string, any>, silent?: boolean): void;
192
+ setGloblas(key: keyof GlobalConfig, value: string | JSFunction, silent?: boolean): void;
190
193
  publish(file?: PageFile | BlockFile): void;
191
194
  genSource(): void;
192
195
  lock(id: string): void;
@@ -58,6 +58,10 @@ export interface ProjectSchema {
58
58
  * UniApp项目配置
59
59
  */
60
60
  uniConfig?: UniConfig;
61
+ /**
62
+ * (Web、H5)应用全局配置
63
+ */
64
+ globals?: GlobalConfig;
61
65
  /**
62
66
  * 标记
63
67
  */
@@ -76,7 +80,7 @@ export interface ProjectSchema {
76
80
  __UID__?: string;
77
81
  }
78
82
  /**
79
- * 项目配置信息
83
+ * 项目母版配置信息
80
84
  */
81
85
  export interface ProjectConfig {
82
86
  /**
@@ -149,3 +153,44 @@ export interface UniConfig {
149
153
  */
150
154
  onExit?: JSFunction;
151
155
  }
156
+ /**
157
+ * 应用全局配置项
158
+ */
159
+ export interface GlobalConfig {
160
+ /**
161
+ * 应用全局样式
162
+ */
163
+ css?: string;
164
+ /**
165
+ * 应用全局状态
166
+ */
167
+ store?: JSFunction;
168
+ /**
169
+ * 权限控制插件配置项
170
+ */
171
+ access?: JSFunction;
172
+ /**
173
+ * 应用增强函数
174
+ */
175
+ enhance?: JSFunction;
176
+ /**
177
+ * 请求工具配置项
178
+ */
179
+ axios?: JSFunction;
180
+ /**
181
+ * 请求拦截器
182
+ */
183
+ request?: JSFunction;
184
+ /**
185
+ * 响应拦截器
186
+ */
187
+ response?: JSFunction;
188
+ /**
189
+ * 前置路由守卫
190
+ */
191
+ beforeEach?: JSFunction;
192
+ /**
193
+ * 后置路由守卫
194
+ */
195
+ afterEach?: JSFunction;
196
+ }
@@ -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.12.69
5
+ * @version 0.12.70
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.12.69";
8
+ export declare const version = "0.12.70";