@vtj/core 0.12.18 → 0.12.20

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
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@vtj/base");/**!
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@vtj/base");/**!
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.18
5
+ * @version 0.12.20
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const U="0.12.18",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:r,modifiers:a}=s;return t[i]={name:i,handler:r,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||o.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:r,iterator:a}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=r,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:r,value:a,iterator:l,id:f}=t;return{id:f,name:i,arg:s,modifiers:r,value:a,iterator:l}})}}const c="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=o.uid(),name:s,from:r=""}=e;this.id=i,this.name=s,this.from=r,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:r=[],slot:a,props:l={},events:f={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(a,!0),this.props=v.parse(l),this.events=C.parse(f),this.directives=E.parse(p),t||n.emit(c,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new _(i,this)):this.children=e,t||n.emit(c,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(c,this)}setProp(e,t,i,s=!1){const r=this.props[e];r?r.setValue(t):this.props[e]=new v(e,t,i),s||n.emit(c,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(c,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(c,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(c,this)}setDirective(e,t=!1){const i=e instanceof E?e:new E(e),s=this.directives.findIndex(r=>r.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||n.emit(c,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(c,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const r=i.findIndex(a=>a===e);e.parent=null,i.splice(r,1),t||n.emit(c,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(c,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(c,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(c,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(c,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(c,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:l,props:f,directives:p,events:O}=this,T=Array.isArray(l)?l.map(b=>b.toDsl()):l;return{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:T,props:v.toDsl(f),directives:E.toDsl(p),events:C.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(c,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(c,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(c,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(c,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||o.uid(),this.update(e,!0)}update(e,t=!1){for(const s of u.normalAttrs){const r=e[s];r!==void 0&&(this[s]=r)}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,l)=>(a[l]=this[l],a),{}),__VTJ_BLOCK__:t,__VERSION__:e||o.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||o.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=o.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(r=>r===i.name||r===i);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=>o.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=o.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(r=>r===i.name||r===i);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=>o.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 h="EVENT_PROJECT_CHANGE",I="EVENT_PROJECT_ACTIVED",P="EVENT_PROJECT_DEPS_CHANGE",A="EVENT_PROJECT_PAGES_CHANGE",N="EVENT_PROJECT_BLOCKS_CHANGE",V="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",H="EVENT_PROJECT_PUBLISH",k="EVENT_PROJECT_FILE_PUBLISH",L="EVENT_PROJECT_GEN_SOURCE";class g{id="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};__BASE_PATH__="/";__UID__=o.uuid(!0);static attrs=["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||o.uid(),this.__UID__=i||o.uuid(!0),this.update(e,!0)}update(e,t=!1){for(const i of g.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(h,{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=g.attrs.reduce((s,r)=>(s[r]=this[r],s),{});return i.pages&&(i.pages=i.pages.map(s=>o.cloneDeep({...s,dsl:void 0})),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>o.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 r;if(s>-1?(r="update",i.splice(s,1,{...i[s],...e})):(r="create",i.push(e)),!t){const a={model:this,type:r,data:e};n.emit(P,a),n.emit(h,a)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(r=>r.package===e.package);if(s>-1&&i.splice(s,1),!t){const r={model:this,type:"delete",data:e};n.emit(P,r),n.emit(h,r)}}getPage(e){const t=(i,s=[])=>{for(const r of s){if(r.id===i)return r;if(r.children&&r.children.length){const a=t(i,r.children);if(a)return a}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir?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||o.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:o.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(A,s),n.emit(h,s)}!this.currentFile&&!e.dir&&(await o.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(A,s),n.emit(h,s)}}clonePage(e,t,i=!1){const s=o.uid(),r=`${e.name}Copy`,a=`${e.title}_副本`,l=new u({id:s,name:r}).toDsl(),f=o.merge({},e,{id:s,name:r,title:a,dsl:l}),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(A,T),n.emit(h,T)}}async saveToBlock(e,t=!1){this.active(e,t),await o.delay(1e3);const i=o.uid(),s=e.name,r=e.title,a=new u({id:i,name:s}).toDsl(),l=o.merge({},e,{id:i,name:s,title:r,dsl:a,type:"block",fromType:"Schema"});if(this.blocks.push(l),!t){const f={model:this,type:"create",data:l};n.emit(N,f),n.emit(h,f)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,a)=>{const l=a.findIndex(f=>f.id===r);if(l>=0){a.splice(l,1);return}for(const f of a)f.children&&f.children.length&&s(r,f.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const r={model:this,type:"delete",data:i};n.emit(A,r),n.emit(h,r)}}getBlock(e){return this.blocks.find(t=>t.id===e)}async createBlock(e,t=!1){const i=e.id||o.uid(),s=o.upperFirstCamelCase(e.name);e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e);const r=e.fromType||"Schema";if(!t){const a={model:this,type:"create",data:e};n.emit(N,a),n.emit(h,a)}!this.currentFile&&r==="Schema"&&(await o.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(h,s)}}cloneBlock(e,t=!1){const i=o.uid(),s=`${e.name}Copy`,r=`${e.title}_副本`,a=new u({id:i,name:s}).toDsl(),l=o.merge({},e,{id:i,name:s,title:r,dsl:a}),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(h,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,r=s.findIndex(a=>a.id===e);if(r>-1?(s.splice(r,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(h,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(r=>r.name===e.name||r.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=o.uid(),this.apis.push(e)),!t){const r={model:this,type:s,data:e};n.emit(V,r),n.emit(h,r)}}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(h,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(r=>r.code===e.code||r.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=o.uid(),this.meta.push(e)),!t){const r={model:this,type:s,data:e};n.emit(S,r),n.emit(h,r)}}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(h,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(h,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(h,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(h,s)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(k,t):n.emit(H,t)}genSource(){const e={model:this,type:"gen",data:null};n.emit(L,e)}}const y="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:o.uid(),label:new Date().toLocaleString(),dsl:o.cloneDeep(e)};if(this.items.unshift(s),this.items.length>i){const r=this.items.splice(i);t||n.emit(y,{model:this,type:"delete",data:r.map(a=>a.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(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(y,{model:this,type:"clear",data:t})}}const n=o.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=o.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=y;exports.EVENT_HISTORY_LOAD=x;exports.EVENT_NODE_CHANGE=c;exports.EVENT_PROJECT_ACTIVED=I;exports.EVENT_PROJECT_APIS_CHANGE=V;exports.EVENT_PROJECT_BLOCKS_CHANGE=N;exports.EVENT_PROJECT_CHANGE=h;exports.EVENT_PROJECT_DEPS_CHANGE=P;exports.EVENT_PROJECT_FILE_PUBLISH=k;exports.EVENT_PROJECT_GEN_SOURCE=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=A;exports.EVENT_PROJECT_PUBLISH=H;exports.EventModel=C;exports.HistoryModel=K;exports.NodeModel=_;exports.ProjectModel=g;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.12.20",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:O}=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(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 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===i);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===i);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",A="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 g{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 g.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=g.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.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(A,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(A,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,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(A,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({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(A,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 y="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(y,{model:this,type:"delete",data:o.map(a=>a.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(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(y,{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=y;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=A;exports.EVENT_PROJECT_PUBLISH=k;exports.EventModel=C;exports.HistoryModel=K;exports.NodeModel=_;exports.ProjectModel=g;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;
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { uid as m, timestamp as G, isString as A, uuid as R, cloneDeep as C, upperFirstCamelCase as D, delay as P, merge as I, mitt as F } from "@vtj/base";
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";
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.18
6
+ * @version 0.12.20
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const Y = "0.12.18", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial", q = [H, J], z = {
9
+ const Y = "0.12.20", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial", q = [H, J], z = {
10
10
  vue: "Vue",
11
11
  "vue-router": "VueRouter"
12
12
  }, Q = {
@@ -86,8 +86,8 @@ class T {
86
86
  }
87
87
  static toDsl(e) {
88
88
  return Object.entries(e).reduce((t, [i, s]) => {
89
- const { handler: a, modifiers: r } = s;
90
- return t[i] = { name: i, handler: a, modifiers: r }, t;
89
+ const { handler: a, modifiers: o } = s;
90
+ return t[i] = { name: i, handler: a, modifiers: o }, t;
91
91
  }, {});
92
92
  }
93
93
  static parse(e = {}) {
@@ -127,27 +127,27 @@ class v {
127
127
  iterator;
128
128
  update(e) {
129
129
  Object.assign(this.schema, e);
130
- const { name: t, arg: i, modifiers: s, value: a, iterator: r } = this.schema;
131
- this.name = t, this.arg = i, this.modifiers = s, this.value = a, this.iterator = r;
130
+ const { name: t, arg: i, modifiers: s, value: a, iterator: o } = this.schema;
131
+ this.name = t, this.arg = i, this.modifiers = s, this.value = a, this.iterator = o;
132
132
  }
133
133
  static parse(e = []) {
134
134
  return e.map((t) => new v(t));
135
135
  }
136
136
  static toDsl(e = []) {
137
137
  return e.map((t) => {
138
- const { name: i, arg: s, modifiers: a, value: r, iterator: d, id: l } = t;
138
+ const { name: i, arg: s, modifiers: a, value: o, iterator: d, id: c } = t;
139
139
  return {
140
- id: l,
140
+ id: c,
141
141
  name: i,
142
142
  arg: s,
143
143
  modifiers: a,
144
- value: r,
144
+ value: o,
145
145
  iterator: d
146
146
  };
147
147
  });
148
148
  }
149
149
  }
150
- const c = "EVENT_NODE_CHANGE";
150
+ const h = "EVENT_NODE_CHANGE";
151
151
  class _ {
152
152
  constructor(e, t = null) {
153
153
  this.parent = t;
@@ -216,12 +216,12 @@ class _ {
216
216
  invisible: i = !1,
217
217
  locked: s = !1,
218
218
  children: a = [],
219
- slot: r,
219
+ slot: o,
220
220
  props: d = {},
221
- events: l = {},
221
+ events: c = {},
222
222
  directives: p = []
223
223
  } = e;
224
- this.invisible = i, this.locked = s, this.setChildren(a, !0), this.setSlot(r, !0), this.props = x.parse(d), this.events = T.parse(l), this.directives = v.parse(p), t || n.emit(c, this);
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);
225
225
  }
226
226
  /**
227
227
  * 设置子节点
@@ -229,7 +229,7 @@ class _ {
229
229
  * @param silent
230
230
  */
231
231
  setChildren(e = "", t = !1) {
232
- Array.isArray(e) ? this.children = e.map((i) => new _(i, this)) : this.children = e, t || n.emit(c, this);
232
+ Array.isArray(e) ? this.children = e.map((i) => new _(i, this)) : this.children = e, t || n.emit(h, this);
233
233
  }
234
234
  /**
235
235
  * 设置节点放置的插槽
@@ -237,7 +237,7 @@ class _ {
237
237
  * @param silent
238
238
  */
239
239
  setSlot(e, t = !1) {
240
- this.slot = typeof e == "string" ? { name: e, params: [] } : e, t || n.emit(c, this);
240
+ this.slot = typeof e == "string" ? { name: e, params: [] } : e, t || n.emit(h, this);
241
241
  }
242
242
  /**
243
243
  * 新增或更新属性
@@ -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(c, this);
251
+ a ? a.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(h, this);
252
252
  }
253
253
  /**
254
254
  * 删除属性
@@ -256,7 +256,7 @@ class _ {
256
256
  * @param silent
257
257
  */
258
258
  removeProp(e, t = !1) {
259
- delete this.props[e], t || n.emit(c, this);
259
+ delete this.props[e], t || n.emit(h, this);
260
260
  }
261
261
  /**
262
262
  * 获取属性值
@@ -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(c, this);
278
+ i ? i.update(e) : this.events[e.name] = new T(e), t || n.emit(h, this);
279
279
  }
280
280
  /**
281
281
  * 删除事件
@@ -283,7 +283,7 @@ class _ {
283
283
  * @param silent
284
284
  */
285
285
  removeEvent(e, t = !1) {
286
- delete this.events[e], t || n.emit(c, this);
286
+ delete this.events[e], t || n.emit(h, this);
287
287
  }
288
288
  /**
289
289
  * 新增或更新指令
@@ -292,7 +292,7 @@ class _ {
292
292
  */
293
293
  setDirective(e, t = !1) {
294
294
  const i = e instanceof v ? e : new v(e), s = this.directives.findIndex((a) => a.id === e.id);
295
- s >= 0 ? this.directives.splice(s, 1, i) : this.directives.push(i), t || n.emit(c, this);
295
+ s >= 0 ? this.directives.splice(s, 1, i) : this.directives.push(i), t || n.emit(h, this);
296
296
  }
297
297
  /**
298
298
  * 删除指令
@@ -303,7 +303,7 @@ class _ {
303
303
  const i = this.directives.findIndex(
304
304
  (s) => s === e || s.id === e.id
305
305
  );
306
- i >= 0 && this.directives.splice(i, 1), t || n.emit(c, this);
306
+ i >= 0 && this.directives.splice(i, 1), t || n.emit(h, this);
307
307
  }
308
308
  /**
309
309
  * 删除子节点
@@ -314,8 +314,8 @@ class _ {
314
314
  removeChild(e, t = !1) {
315
315
  const { children: i, disposed: s } = this;
316
316
  if (s || !Array.isArray(i)) return;
317
- const a = i.findIndex((r) => r === e);
318
- e.parent = null, i.splice(a, 1), t || n.emit(c, this);
317
+ const a = i.findIndex((o) => o === e);
318
+ e.parent = null, i.splice(a, 1), t || n.emit(h, this);
319
319
  }
320
320
  /**
321
321
  * 追加子节点
@@ -325,7 +325,7 @@ class _ {
325
325
  */
326
326
  appendChild(e, t = !1) {
327
327
  const { children: i, disposed: s } = this;
328
- s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(c, this));
328
+ s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(h, this));
329
329
  }
330
330
  /**
331
331
  * 在当前节点的后面插入节点
@@ -339,7 +339,7 @@ class _ {
339
339
  if (Array.isArray(i)) {
340
340
  e.parent = this.parent;
341
341
  const s = i.indexOf(this);
342
- i.splice(s + 1, 0, e), t || n.emit(c, this.parent);
342
+ i.splice(s + 1, 0, e), t || n.emit(h, this.parent);
343
343
  }
344
344
  }
345
345
  /**
@@ -354,7 +354,7 @@ class _ {
354
354
  if (Array.isArray(i)) {
355
355
  e.parent = this.parent;
356
356
  const s = i.indexOf(this);
357
- i.splice(s, 0, e), t || n.emit(c, this.parent);
357
+ i.splice(s, 0, e), t || n.emit(h, this.parent);
358
358
  }
359
359
  }
360
360
  movePrev(e = !1) {
@@ -363,7 +363,7 @@ class _ {
363
363
  const i = t.children;
364
364
  if (Array.isArray(i)) {
365
365
  const s = i.indexOf(this);
366
- s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(c, t));
366
+ s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(h, t));
367
367
  }
368
368
  }
369
369
  moveNext(e = !1) {
@@ -372,7 +372,7 @@ class _ {
372
372
  const i = t.children;
373
373
  if (Array.isArray(i)) {
374
374
  const s = i.indexOf(this);
375
- s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(c, t));
375
+ s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(h, t));
376
376
  }
377
377
  }
378
378
  /**
@@ -386,9 +386,9 @@ class _ {
386
386
  from: i,
387
387
  invisible: s,
388
388
  locked: a,
389
- slot: r,
389
+ slot: o,
390
390
  children: d,
391
- props: l,
391
+ props: c,
392
392
  directives: p,
393
393
  events: O
394
394
  } = this, E = Array.isArray(d) ? d.map((U) => U.toDsl()) : d;
@@ -398,9 +398,9 @@ class _ {
398
398
  from: i,
399
399
  invisible: s,
400
400
  locked: a,
401
- slot: r,
401
+ slot: o,
402
402
  children: E,
403
- props: x.toDsl(l),
403
+ props: x.toDsl(c),
404
404
  directives: v.toDsl(p),
405
405
  events: T.toDsl(O)
406
406
  };
@@ -412,25 +412,25 @@ class _ {
412
412
  */
413
413
  dispose(e = !1) {
414
414
  const { children: t, disposed: i } = this;
415
- i || (Array.isArray(t) && t.forEach((s) => s.dispose(!0)), this.parent ? this.parent.removeChild(this, e) : e || n.emit(c, this), this.parent = null, this.disposed = !0, delete _.nodes[this.id]);
415
+ 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]);
416
416
  }
417
417
  lock(e = !1) {
418
418
  if (this.locked = !0, Array.isArray(this.children))
419
419
  for (const t of this.children)
420
420
  t.lock(!0);
421
- e || n.emit(c, this);
421
+ e || n.emit(h, this);
422
422
  }
423
423
  unlock(e = !1) {
424
424
  if (this.locked = !1, Array.isArray(this.children))
425
425
  for (const t of this.children)
426
426
  t.unlock(!0);
427
- e || n.emit(c, this);
427
+ e || n.emit(h, this);
428
428
  }
429
429
  setVisible(e, t = !1) {
430
430
  if (this.invisible = !e, Array.isArray(this.children))
431
431
  for (const i of this.children)
432
432
  i.setVisible(e, !0);
433
- t || n.emit(c, this);
433
+ t || n.emit(h, this);
434
434
  }
435
435
  isChild(e) {
436
436
  let t = !1;
@@ -445,7 +445,7 @@ class _ {
445
445
  return t;
446
446
  }
447
447
  }
448
- const o = "EVENT_BLOCK_CHANGE";
448
+ const r = "EVENT_BLOCK_CHANGE";
449
449
  class u {
450
450
  __VTJ_BLOCK__ = !0;
451
451
  id;
@@ -490,7 +490,7 @@ class u {
490
490
  a !== void 0 && (this[s] = a);
491
491
  }
492
492
  const { nodes: i = [] } = e;
493
- i.length && (this.nodes = i.map((s) => new _(s))), t || n.emit(o, this);
493
+ i.length && (this.nodes = i.map((s) => new _(s))), t || n.emit(r, this);
494
494
  }
495
495
  /**
496
496
  * 获取DSL
@@ -500,13 +500,13 @@ class u {
500
500
  const { __VTJ_BLOCK__: t, id: i, nodes: s } = this;
501
501
  return {
502
502
  ...u.normalAttrs.reduce(
503
- (r, d) => (r[d] = this[d], r),
503
+ (o, d) => (o[d] = this[d], o),
504
504
  {}
505
505
  ),
506
506
  __VTJ_BLOCK__: t,
507
507
  __VERSION__: e || G().toString(),
508
508
  id: i,
509
- nodes: s.map((r) => r.toDsl())
509
+ nodes: s.map((o) => o.toDsl())
510
510
  };
511
511
  }
512
512
  /**
@@ -523,7 +523,7 @@ class u {
523
523
  * @param silent
524
524
  */
525
525
  setFunction(e, t, i, s = !1) {
526
- this[e][t] = i, s || n.emit(o, this);
526
+ this[e][t] = i, s || n.emit(r, this);
527
527
  }
528
528
  /**
529
529
  * 删除通用函数属性
@@ -532,7 +532,7 @@ class u {
532
532
  * @param silent
533
533
  */
534
534
  removeFunction(e, t, i = !1) {
535
- delete this[e][t], i || n.emit(o, this);
535
+ delete this[e][t], i || n.emit(r, this);
536
536
  }
537
537
  /**
538
538
  * 设置状态
@@ -541,7 +541,7 @@ class u {
541
541
  * @param silent
542
542
  */
543
543
  setState(e, t, i = !1) {
544
- this.state[e] = t, i || n.emit(o, this);
544
+ this.state[e] = t, i || n.emit(r, this);
545
545
  }
546
546
  /**
547
547
  * 删除状态
@@ -549,7 +549,7 @@ class u {
549
549
  * @param silent
550
550
  */
551
551
  removeState(e, t = !1) {
552
- delete this.state[e], t || n.emit(o, this);
552
+ delete this.state[e], t || n.emit(r, this);
553
553
  }
554
554
  /**
555
555
  * 更新CSS
@@ -557,7 +557,7 @@ class u {
557
557
  * @param silent
558
558
  */
559
559
  setCss(e, t = !1) {
560
- this.css = e, t || n.emit(o, this);
560
+ this.css = e, t || n.emit(r, this);
561
561
  }
562
562
  /**
563
563
  * 新增或更新 watch
@@ -569,7 +569,7 @@ class u {
569
569
  const i = this.watch.findIndex(
570
570
  (s) => s.id && s.id === e.id || s === e
571
571
  );
572
- i > -1 ? this.watch.splice(i, 1, e) : this.watch.push(e), t || n.emit(o, this);
572
+ i > -1 ? this.watch.splice(i, 1, e) : this.watch.push(e), t || n.emit(r, this);
573
573
  }
574
574
  /**
575
575
  * 删除 watch
@@ -580,7 +580,7 @@ class u {
580
580
  const i = this.watch.findIndex(
581
581
  (s) => s.id && s.id === e.id || s === e
582
582
  );
583
- i > -1 && (this.watch.splice(i, 1), t || n.emit(o, this));
583
+ i > -1 && (this.watch.splice(i, 1), t || n.emit(r, this));
584
584
  }
585
585
  /**
586
586
  * 定义属性参数
@@ -591,7 +591,7 @@ class u {
591
591
  const i = this.props.findIndex(
592
592
  (s) => typeof s == "string" ? s === e.name : s.name === e.name
593
593
  );
594
- i > -1 ? this.props.splice(i, 1, e) : this.props.push(e), t || n.emit(o, this);
594
+ i > -1 ? this.props.splice(i, 1, e) : this.props.push(e), t || n.emit(r, this);
595
595
  }
596
596
  /**
597
597
  * 删除属性
@@ -602,7 +602,7 @@ class u {
602
602
  const i = this.props.findIndex(
603
603
  (s) => typeof s == "string" ? s === e.name : s.name === e.name
604
604
  );
605
- i > -1 && (this.props.splice(i, 1), t || n.emit(o, this));
605
+ i > -1 && (this.props.splice(i, 1), t || n.emit(r, this));
606
606
  }
607
607
  /**
608
608
  * 设置事件
@@ -611,7 +611,7 @@ class u {
611
611
  */
612
612
  setEmit(e, t = !1) {
613
613
  const i = A(e) ? { name: e, params: [] } : e, s = this.emits.findIndex((a) => a === i.name || a === i);
614
- s > -1 ? this.emits.splice(s, 1, i) : this.emits.push(i), t || n.emit(o, this);
614
+ s > -1 ? this.emits.splice(s, 1, i) : this.emits.push(i), t || n.emit(r, this);
615
615
  }
616
616
  /**
617
617
  * 删除事件
@@ -622,7 +622,7 @@ class u {
622
622
  const i = this.emits.findIndex(
623
623
  (s) => A(s) ? s === e : s.name === e
624
624
  );
625
- i > -1 && (this.emits.splice(i, 1), t || n.emit(o, this));
625
+ i > -1 && (this.emits.splice(i, 1), t || n.emit(r, this));
626
626
  }
627
627
  /**
628
628
  * 设置插槽
@@ -631,7 +631,7 @@ class u {
631
631
  */
632
632
  setSlot(e, t = !1) {
633
633
  const i = A(e) ? { name: e, params: [] } : e, s = this.slots.findIndex((a) => a === i.name || a === i);
634
- s > -1 ? this.slots.splice(s, 1, i) : this.slots.push(i), t || n.emit(o, this);
634
+ s > -1 ? this.slots.splice(s, 1, i) : this.slots.push(i), t || n.emit(r, this);
635
635
  }
636
636
  /**
637
637
  * 删除插槽
@@ -642,7 +642,7 @@ class u {
642
642
  const i = this.slots.findIndex(
643
643
  (s) => A(s) ? s === e : s.name === e
644
644
  );
645
- i > -1 && (this.slots.splice(i, 1), t || n.emit(o, this));
645
+ i > -1 && (this.slots.splice(i, 1), t || n.emit(r, this));
646
646
  }
647
647
  /**
648
648
  * 设置注入
@@ -651,7 +651,7 @@ class u {
651
651
  */
652
652
  setInject(e, t = !1) {
653
653
  const i = this.inject.findIndex((s) => s.name === e.name);
654
- i > -1 ? this.inject.splice(i, 1, e) : this.inject.push(e), t || n.emit(o, this);
654
+ i > -1 ? this.inject.splice(i, 1, e) : this.inject.push(e), t || n.emit(r, this);
655
655
  }
656
656
  /**
657
657
  * 删除注入
@@ -660,7 +660,7 @@ class u {
660
660
  */
661
661
  removeInject(e, t = !1) {
662
662
  const i = this.inject.findIndex((s) => s.name === e.name);
663
- i > -1 && (this.inject.splice(i, 1), t || n.emit(o, this));
663
+ i > -1 && (this.inject.splice(i, 1), t || n.emit(r, this));
664
664
  }
665
665
  /**
666
666
  * 设置数据源
@@ -668,7 +668,7 @@ class u {
668
668
  * @param silent
669
669
  */
670
670
  setDataSource(e, t = !1) {
671
- this.dataSources[e.name] = e, t || n.emit(o, this);
671
+ this.dataSources[e.name] = e, t || n.emit(r, this);
672
672
  }
673
673
  /**
674
674
  * 删除数据源
@@ -676,20 +676,20 @@ class u {
676
676
  * @param silent
677
677
  */
678
678
  removeDataSource(e, t = !1) {
679
- delete this.dataSources[e], t || n.emit(o, this);
679
+ delete this.dataSources[e], t || n.emit(r, this);
680
680
  }
681
681
  insertAfter(e, t, i = !1) {
682
682
  e.parent = null;
683
683
  const s = this.nodes.indexOf(t);
684
- this.nodes.splice(s + 1, 0, e), i || n.emit(o, this);
684
+ this.nodes.splice(s + 1, 0, e), i || n.emit(r, this);
685
685
  }
686
686
  insertBefore(e, t, i = !1) {
687
687
  e.parent = null;
688
688
  const s = this.nodes.indexOf(t);
689
- this.nodes.splice(s, 0, e), i || n.emit(o, this);
689
+ this.nodes.splice(s, 0, e), i || n.emit(r, this);
690
690
  }
691
691
  appendNode(e, t = !1) {
692
- e.parent = null, this.nodes.push(e), t || n.emit(o, this);
692
+ e.parent = null, this.nodes.push(e), t || n.emit(r, this);
693
693
  }
694
694
  /**
695
695
  * 添加节点
@@ -703,7 +703,7 @@ class u {
703
703
  }
704
704
  __removeNode(e, t = !1) {
705
705
  const i = this.nodes.findIndex((s) => s.id === e.id);
706
- i > -1 && (this.nodes.splice(i, 1), t || n.emit(o, this));
706
+ i > -1 && (this.nodes.splice(i, 1), t || n.emit(r, this));
707
707
  }
708
708
  /**
709
709
  * 删除节点
@@ -733,7 +733,7 @@ class u {
733
733
  e.movePrev(t);
734
734
  else {
735
735
  const i = this.nodes, s = i.indexOf(e);
736
- s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, e), t || n.emit(o, this));
736
+ s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, e), t || n.emit(r, this));
737
737
  }
738
738
  }
739
739
  /**
@@ -746,7 +746,7 @@ class u {
746
746
  e.moveNext(t);
747
747
  else {
748
748
  const i = this.nodes, s = i.indexOf(e);
749
- s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, e), t || n.emit(o, this));
749
+ s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, e), t || n.emit(r, this));
750
750
  }
751
751
  }
752
752
  /**
@@ -763,13 +763,13 @@ class u {
763
763
  this.locked = !0;
764
764
  for (const t of this.nodes)
765
765
  t.lock(!0);
766
- e || n.emit(o, this);
766
+ e || n.emit(r, this);
767
767
  }
768
768
  unlock(e = !1) {
769
769
  this.locked = !1;
770
770
  for (const t of this.nodes)
771
771
  t.unlock(!0);
772
- e || n.emit(o, this);
772
+ e || n.emit(r, this);
773
773
  }
774
774
  isChild(e) {
775
775
  let t = !1;
@@ -782,9 +782,10 @@ class u {
782
782
  return t;
783
783
  }
784
784
  }
785
- const h = "EVENT_PROJECT_CHANGE", k = "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";
785
+ 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";
786
786
  class S {
787
787
  id = "";
788
+ locked = "";
788
789
  platform = "web";
789
790
  name = "";
790
791
  description = "";
@@ -798,8 +799,9 @@ class S {
798
799
  config = {};
799
800
  uniConfig = {};
800
801
  __BASE_PATH__ = "/";
801
- __UID__ = R(!0);
802
+ __UID__ = k(!0);
802
803
  static attrs = [
804
+ "locked",
803
805
  "platform",
804
806
  "name",
805
807
  "homepage",
@@ -816,14 +818,14 @@ class S {
816
818
  ];
817
819
  constructor(e) {
818
820
  const { id: t, __UID__: i } = e;
819
- this.id = t || m(), this.__UID__ = i || R(!0), this.update(e, !0);
821
+ this.id = t || m(), this.__UID__ = i || k(!0), this.update(e, !0);
820
822
  }
821
823
  update(e, t = !1) {
822
824
  for (const i of S.attrs) {
823
825
  const s = e[i];
824
826
  s && (this[i] = s);
825
827
  }
826
- t || n.emit(h, {
828
+ t || n.emit(l, {
827
829
  model: this,
828
830
  type: "update",
829
831
  data: e
@@ -859,7 +861,7 @@ class S {
859
861
  * @param silent
860
862
  */
861
863
  active(e, t = !1) {
862
- this.currentFile = e, t || n.emit(k, {
864
+ this.currentFile = e, t || n.emit(D, {
863
865
  model: this,
864
866
  type: "update",
865
867
  data: e
@@ -870,7 +872,7 @@ class S {
870
872
  * @param silent
871
873
  */
872
874
  deactivate(e = !1) {
873
- this.currentFile = null, e || n.emit(k, {
875
+ this.currentFile = null, e || n.emit(D, {
874
876
  model: this,
875
877
  type: "update",
876
878
  data: null
@@ -882,18 +884,18 @@ class S {
882
884
  * @param silent
883
885
  */
884
886
  setDeps(e, t = !1) {
885
- const i = this.dependencies, s = i.findIndex((r) => r.package === e.package);
887
+ const i = this.dependencies, s = i.findIndex((o) => o.package === e.package);
886
888
  let a;
887
889
  if (s > -1 ? (a = "update", i.splice(s, 1, {
888
890
  ...i[s],
889
891
  ...e
890
892
  })) : (a = "create", i.push(e)), !t) {
891
- const r = {
893
+ const o = {
892
894
  model: this,
893
895
  type: a,
894
896
  data: e
895
897
  };
896
- n.emit(B, r), n.emit(h, r);
898
+ n.emit(B, o), n.emit(l, o);
897
899
  }
898
900
  }
899
901
  /**
@@ -909,7 +911,7 @@ class S {
909
911
  type: "delete",
910
912
  data: e
911
913
  };
912
- n.emit(B, a), n.emit(h, a);
914
+ n.emit(B, a), n.emit(l, a);
913
915
  }
914
916
  }
915
917
  /**
@@ -923,9 +925,9 @@ class S {
923
925
  if (a.id === i)
924
926
  return a;
925
927
  if (a.children && a.children.length) {
926
- const r = t(i, a.children);
927
- if (r)
928
- return r;
928
+ const o = t(i, a.children);
929
+ if (o)
930
+ return o;
929
931
  }
930
932
  }
931
933
  };
@@ -953,7 +955,7 @@ class S {
953
955
  async createPage(e, t, i = !1) {
954
956
  if (e.id = e.raw ? e.name : e.id || m(), e.type = "page", e.dir ? e.children = [] : e.dsl = e.dsl || new u({
955
957
  id: e.id,
956
- name: D(e.name)
958
+ name: R(e.name)
957
959
  }).toDsl(), t) {
958
960
  const s = this.getPage(t);
959
961
  s ? s.children ? s.children.push(e) : s.children = [e] : console.warn(`not found PageFile for id: ${t} `);
@@ -965,7 +967,7 @@ class S {
965
967
  type: "create",
966
968
  data: e
967
969
  };
968
- n.emit(g, s), n.emit(h, s);
970
+ n.emit(g, s), n.emit(l, s);
969
971
  }
970
972
  !this.currentFile && !e.dir && (await P(1e3), this.active(e, i));
971
973
  }
@@ -982,7 +984,7 @@ class S {
982
984
  type: "update",
983
985
  data: e
984
986
  };
985
- n.emit(g, s), n.emit(h, s);
987
+ n.emit(g, s), n.emit(l, s);
986
988
  }
987
989
  }
988
990
  /**
@@ -992,42 +994,42 @@ class S {
992
994
  * @param silent
993
995
  */
994
996
  clonePage(e, t, i = !1) {
995
- const s = m(), a = `${e.name}Copy`, r = `${e.title}_副本`, d = new u({
997
+ const s = m(), a = `${e.name}Copy`, o = `${e.title}_副本`, d = new u({
996
998
  id: s,
997
999
  name: a
998
- }).toDsl(), l = I({}, e, { id: s, name: a, title: r, dsl: d }), p = t ? this.getPage(t)?.children || [] : this.pages, O = p.findIndex((E) => E.id === e.id);
999
- if (p.splice(O + 1, 0, l), !i) {
1000
+ }).toDsl(), c = I({}, e, { id: s, name: a, title: o, dsl: d }), p = t ? this.getPage(t)?.children || [] : this.pages, O = p.findIndex((E) => E.id === e.id);
1001
+ if (p.splice(O + 1, 0, c), !i) {
1000
1002
  const E = {
1001
1003
  model: this,
1002
1004
  type: "clone",
1003
1005
  data: {
1004
1006
  source: e,
1005
- target: l
1007
+ target: c
1006
1008
  }
1007
1009
  };
1008
- n.emit(g, E), n.emit(h, E);
1010
+ n.emit(g, E), n.emit(l, E);
1009
1011
  }
1010
1012
  }
1011
1013
  async saveToBlock(e, t = !1) {
1012
1014
  this.active(e, t), await P(1e3);
1013
- const i = m(), s = e.name, a = e.title, r = new u({
1015
+ const i = m(), s = e.name, a = e.title, o = new u({
1014
1016
  id: i,
1015
1017
  name: s
1016
1018
  }).toDsl(), d = I({}, e, {
1017
1019
  id: i,
1018
1020
  name: s,
1019
1021
  title: a,
1020
- dsl: r,
1022
+ dsl: o,
1021
1023
  type: "block",
1022
1024
  fromType: "Schema"
1023
1025
  });
1024
1026
  if (this.blocks.push(d), !t) {
1025
- const l = {
1027
+ const c = {
1026
1028
  model: this,
1027
1029
  type: "create",
1028
1030
  data: d
1029
1031
  };
1030
- n.emit(y, l), n.emit(h, l);
1032
+ n.emit(y, c), n.emit(l, c);
1031
1033
  }
1032
1034
  }
1033
1035
  /**
@@ -1036,14 +1038,14 @@ class S {
1036
1038
  * @param silent
1037
1039
  */
1038
1040
  removePage(e, t = !1) {
1039
- const i = this.getPage(e), s = (a, r) => {
1040
- const d = r.findIndex((l) => l.id === a);
1041
+ const i = this.getPage(e), s = (a, o) => {
1042
+ const d = o.findIndex((c) => c.id === a);
1041
1043
  if (d >= 0) {
1042
- r.splice(d, 1);
1044
+ o.splice(d, 1);
1043
1045
  return;
1044
1046
  }
1045
- for (const l of r)
1046
- l.children && l.children.length && s(a, l.children);
1047
+ for (const c of o)
1048
+ c.children && c.children.length && s(a, c.children);
1047
1049
  };
1048
1050
  if (s(e, this.pages), e === this.homepage && (this.homepage = ""), this.currentFile?.id === e && this.deactivate(t), !t) {
1049
1051
  const a = {
@@ -1051,7 +1053,7 @@ class S {
1051
1053
  type: "delete",
1052
1054
  data: i
1053
1055
  };
1054
- n.emit(g, a), n.emit(h, a);
1056
+ n.emit(g, a), n.emit(l, a);
1055
1057
  }
1056
1058
  }
1057
1059
  /**
@@ -1068,16 +1070,16 @@ class S {
1068
1070
  * @param silent
1069
1071
  */
1070
1072
  async createBlock(e, t = !1) {
1071
- const i = e.id || m(), s = D(e.name);
1073
+ const i = e.id || m(), s = R(e.name);
1072
1074
  e.id = i, e.type = "block", e.dsl = new u({ id: i, name: s }).toDsl(), this.blocks.push(e);
1073
1075
  const a = e.fromType || "Schema";
1074
1076
  if (!t) {
1075
- const r = {
1077
+ const o = {
1076
1078
  model: this,
1077
1079
  type: "create",
1078
1080
  data: e
1079
1081
  };
1080
- n.emit(y, r), n.emit(h, r);
1082
+ n.emit(y, o), n.emit(l, o);
1081
1083
  }
1082
1084
  !this.currentFile && a === "Schema" && (await P(1e3), this.active(e, t));
1083
1085
  }
@@ -1094,15 +1096,15 @@ class S {
1094
1096
  type: "update",
1095
1097
  data: e
1096
1098
  };
1097
- n.emit(y, s), n.emit(h, s);
1099
+ n.emit(y, s), n.emit(l, s);
1098
1100
  }
1099
1101
  }
1100
1102
  cloneBlock(e, t = !1) {
1101
- const i = m(), s = `${e.name}Copy`, a = `${e.title}_副本`, r = new u({
1103
+ const i = m(), s = `${e.name}Copy`, a = `${e.title}_副本`, o = new u({
1102
1104
  id: i,
1103
1105
  name: s
1104
- }).toDsl(), d = I({}, e, { id: i, name: s, title: a, dsl: r }), l = this.blocks.findIndex((p) => p.id === e.id);
1105
- if (this.blocks.splice(l + 1, 0, d), !t) {
1106
+ }).toDsl(), d = I({}, e, { id: i, name: s, title: a, dsl: o }), c = this.blocks.findIndex((p) => p.id === e.id);
1107
+ if (this.blocks.splice(c + 1, 0, d), !t) {
1106
1108
  const p = {
1107
1109
  model: this,
1108
1110
  type: "clone",
@@ -1111,7 +1113,7 @@ class S {
1111
1113
  target: d
1112
1114
  }
1113
1115
  };
1114
- n.emit(y, p), n.emit(h, p);
1116
+ n.emit(y, p), n.emit(l, p);
1115
1117
  }
1116
1118
  }
1117
1119
  /**
@@ -1120,14 +1122,14 @@ class S {
1120
1122
  * @param silent
1121
1123
  */
1122
1124
  removeBlock(e, t = !1) {
1123
- const i = this.getBlock(e), s = this.blocks, a = s.findIndex((r) => r.id === e);
1125
+ const i = this.getBlock(e), s = this.blocks, a = s.findIndex((o) => o.id === e);
1124
1126
  if (a > -1 ? (s.splice(a, 1), this.currentFile?.id === e && this.deactivate(t)) : console.warn(`not found PageFile for id: ${e} `), !t) {
1125
- const r = {
1127
+ const o = {
1126
1128
  model: this,
1127
1129
  type: "delete",
1128
1130
  data: i
1129
1131
  };
1130
- n.emit(y, r), n.emit(h, r);
1132
+ n.emit(y, o), n.emit(l, o);
1131
1133
  }
1132
1134
  }
1133
1135
  /**
@@ -1164,7 +1166,7 @@ class S {
1164
1166
  type: s,
1165
1167
  data: e
1166
1168
  };
1167
- n.emit(b, a), n.emit(h, a);
1169
+ n.emit(b, a), n.emit(l, a);
1168
1170
  }
1169
1171
  }
1170
1172
  /**
@@ -1180,7 +1182,7 @@ class S {
1180
1182
  type: "delete",
1181
1183
  data: e
1182
1184
  };
1183
- n.emit(b, s), n.emit(h, s);
1185
+ n.emit(b, s), n.emit(l, s);
1184
1186
  }
1185
1187
  }
1186
1188
  existApiName(e, t = []) {
@@ -1197,7 +1199,7 @@ class S {
1197
1199
  type: s,
1198
1200
  data: e
1199
1201
  };
1200
- n.emit(w, a), n.emit(h, a);
1202
+ n.emit(w, a), n.emit(l, a);
1201
1203
  }
1202
1204
  }
1203
1205
  removeMeta(e, t = !1) {
@@ -1208,7 +1210,7 @@ class S {
1208
1210
  type: "delete",
1209
1211
  data: e
1210
1212
  };
1211
- n.emit(w, s), n.emit(h, s);
1213
+ n.emit(w, s), n.emit(l, s);
1212
1214
  }
1213
1215
  }
1214
1216
  existMetaCode(e, t = []) {
@@ -1221,7 +1223,7 @@ class S {
1221
1223
  type: "update",
1222
1224
  data: e
1223
1225
  };
1224
- n.emit(h, i);
1226
+ n.emit(l, i);
1225
1227
  }
1226
1228
  }
1227
1229
  setConfig(e, t = !1) {
@@ -1231,7 +1233,7 @@ class S {
1231
1233
  type: "update",
1232
1234
  data: e
1233
1235
  };
1234
- n.emit(h, i);
1236
+ n.emit(l, i);
1235
1237
  }
1236
1238
  }
1237
1239
  setUniConfig(e, t, i = !1) {
@@ -1241,7 +1243,7 @@ class S {
1241
1243
  type: "update",
1242
1244
  data: this.uniConfig
1243
1245
  };
1244
- n.emit(h, s);
1246
+ n.emit(l, s);
1245
1247
  }
1246
1248
  }
1247
1249
  publish(e) {
@@ -1260,6 +1262,26 @@ class S {
1260
1262
  };
1261
1263
  n.emit(M, e);
1262
1264
  }
1265
+ lock(e) {
1266
+ this.locked = e;
1267
+ const t = {
1268
+ model: this,
1269
+ type: "update",
1270
+ data: e
1271
+ };
1272
+ n.emit(l, t);
1273
+ }
1274
+ unlock(e) {
1275
+ if (e !== this.locked)
1276
+ return;
1277
+ this.locked = "";
1278
+ const t = {
1279
+ model: this,
1280
+ type: "update",
1281
+ data: null
1282
+ };
1283
+ n.emit(l, t);
1284
+ }
1263
1285
  }
1264
1286
  const N = "EVENT_HISTORY_CHANGE", V = "EVENT_HISTORY_LOAD";
1265
1287
  class te {
@@ -1303,7 +1325,7 @@ class te {
1303
1325
  t || n.emit(N, {
1304
1326
  model: this,
1305
1327
  type: "delete",
1306
- data: a.map((r) => r.id)
1328
+ data: a.map((o) => o.id)
1307
1329
  });
1308
1330
  }
1309
1331
  this.index = -1, t || n.emit(N, {
@@ -1404,14 +1426,14 @@ export {
1404
1426
  ee as Base,
1405
1427
  u as BlockModel,
1406
1428
  v as DirectiveModel,
1407
- o as EVENT_BLOCK_CHANGE,
1429
+ r as EVENT_BLOCK_CHANGE,
1408
1430
  N as EVENT_HISTORY_CHANGE,
1409
1431
  V as EVENT_HISTORY_LOAD,
1410
- c as EVENT_NODE_CHANGE,
1411
- k as EVENT_PROJECT_ACTIVED,
1432
+ h as EVENT_NODE_CHANGE,
1433
+ D as EVENT_PROJECT_ACTIVED,
1412
1434
  b as EVENT_PROJECT_APIS_CHANGE,
1413
1435
  y as EVENT_PROJECT_BLOCKS_CHANGE,
1414
- h as EVENT_PROJECT_CHANGE,
1436
+ l as EVENT_PROJECT_CHANGE,
1415
1437
  B as EVENT_PROJECT_DEPS_CHANGE,
1416
1438
  $ as EVENT_PROJECT_FILE_PUBLISH,
1417
1439
  M as EVENT_PROJECT_GEN_SOURCE,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/core",
3
3
  "private": false,
4
- "version": "0.12.18",
4
+ "version": "0.12.20",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -47,6 +47,7 @@ export declare const EVENT_PROJECT_FILE_PUBLISH = "EVENT_PROJECT_FILE_PUBLISH";
47
47
  export declare const EVENT_PROJECT_GEN_SOURCE = "EVENT_PROJECT_GEN_SOURCE";
48
48
  export declare class ProjectModel {
49
49
  id: string;
50
+ locked: string;
50
51
  platform: PlatformType;
51
52
  name: string;
52
53
  description: string;
@@ -188,4 +189,6 @@ export declare class ProjectModel {
188
189
  setUniConfig(key: keyof UniConfig, value: Record<string, any>, silent?: boolean): void;
189
190
  publish(file?: PageFile | BlockFile): void;
190
191
  genSource(): void;
192
+ lock(id: string): void;
193
+ unlock(id: string): void;
191
194
  }
@@ -6,6 +6,10 @@ import { PlatformType, JSFunction } from '../shared';
6
6
  * 项目描述信息
7
7
  */
8
8
  export interface ProjectSchema {
9
+ /**
10
+ * 被锁定
11
+ */
12
+ locked?: string;
9
13
  /**
10
14
  * 平台,默认 web
11
15
  */
@@ -53,14 +53,22 @@ export interface ExtensionConfig {
53
53
  */
54
54
  params?: Array<Record<string, any>>;
55
55
  }
56
+ export interface EnhanceConfig {
57
+ name: string;
58
+ urls: string[];
59
+ }
56
60
  /**
57
61
  * 扩展配置
58
62
  */
59
63
  export interface VTJConfig {
64
+ /**
65
+ * 应用增强配置
66
+ */
67
+ enhance?: boolean | EnhanceConfig;
60
68
  /**
61
69
  * 扩展配置
62
70
  */
63
- extension: ExtensionConfig;
71
+ extension?: ExtensionConfig;
64
72
  /**
65
73
  * 路由History模式
66
74
  */
@@ -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.17
5
+ * @version 0.12.19
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.12.17";
8
+ export declare const version = "0.12.19";