@vtj/core 0.8.146 → 0.8.147

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) 2024, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/core
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.8.146
5
+ * @version 0.8.147
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const b="0.8.146",J="BuiltIn",R="VueMaterial",B="VueRouterMaterial",G=[R,B],U={vue:"Vue","vue-router":"VueRouter"},w={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[B]:["RouterView","RouterLink"]},F=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class M{}class j{listeners=[];isReady=!1;triggerReady(){this.isReady=!0;for(const e of this.listeners)e();this.listeners=[]}ready(e){this.isReady?e():this.listeners.push(e)}resetReady(){this.isReady=!1}}class N{constructor(e,t,i){this.name=e,this.value=t,this.defaultValue=i,this.setValue(t)}isUnset=!1;setValue(e){this.value=e,this.isUnset=this.value===this.defaultValue}getValue(){return this.value??this.defaultValue}static toDsl(e={}){return Object.entries(e).reduce((t,[i,s])=>(s.isUnset||(t[i]=s.getValue()),t),{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new N(i,s),t),{})}}class v{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 v(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||d.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:f,id:m}=t;return{id:m,name:i,arg:s,modifiers:r,value:a,iterator:f}})}}const c="EVENT_NODE_CHANGE";class p{constructor(e,t=null){this.parent=t;const{id:i=d.uid(),name:s,from:r=""}=e;this.id=i,this.name=s,this.from=r,this.update(e,!0),p.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:f={},events:m={},directives:_=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(a,!0),this.props=N.parse(f),this.events=v.parse(m),this.directives=E.parse(_),t||n.emit(c,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new p(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 N(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 v(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=this.directives.findIndex(s=>s.id===e.id);i>=0?this.directives.splice(i,1,new E(e)):this.directives.push(new E(e)),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:f,props:m,directives:_,events:O}=this,T=Array.isArray(f)?f.map(D=>D.toDsl()):f;return{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:T,props:N.toDsl(m),directives:E.toDsl(_),events:v.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 p.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 o="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"];constructor(e){const{id:t}=e;this.id=t||d.uid(),this.update(e,!0)}update(e,t=!1){for(const s of u.normalAttrs){const r=e[s];r&&(this[s]=r)}const{nodes:i=[]}=e;i.length&&(this.nodes=i.map(s=>new p(s))),t||n.emit(o,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((a,f)=>(a[f]=this[f],a),{}),__VTJ_BLOCK__:t,__VERSION__:e||d.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(o,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(o,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(o,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(o,this)}setCss(e,t=!1){this.css=e,t||n.emit(o,this)}setWatch(e,t=!1){e.id=e.id||d.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(o,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(o,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(o,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(o,this))}setEmit(e,t=!1){const i=d.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(o,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>d.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||n.emit(o,this))}setSlot(e,t=!1){const i=d.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(o,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>d.isString(s)?s===e:s.name===e);i>-1&&(this.slots.splice(i,1),t||n.emit(o,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(o,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(o,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(o,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(o,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(o,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(o,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(o,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(o,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(o,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(o,this))}}cloneNode(e,t=!1){const i=H(e.toDsl()),s=new p(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(o,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(o,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",P="EVENT_PROJECT_ACTIVED",g="EVENT_PROJECT_DEPS_CHANGE",A="EVENT_PROJECT_PAGES_CHANGE",y="EVENT_PROJECT_BLOCKS_CHANGE",V="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",L="EVENT_PROJECT_PUBLISH",k="EVENT_PROJECT_FILE_PUBLISH";class I{id="";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};__BASE_PATH__="/";static attrs=["name","homepage","description","dependencies","pages","blocks","apis","meta","config","__BASE_PATH__"];constructor(e){const{id:t}=e;this.id=t||d.uid(),this.update(e,!0)}update(e,t=!1){for(const i of I.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(h,{model:this,type:"update",data:e})}isPageFile(e){return e.type==="page"}toDsl(e){const{id:t}=this,i=I.attrs.reduce((s,r)=>(s[r]=this[r],s),{});return i.pages&&(i.pages=i.pages.map(s=>(delete s.dsl,s))),i.blocks&&(i.blocks=i.blocks.map(s=>(delete s.dsl,s))),{__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(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(g,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(g,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||d.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:d.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 d.delay(1e3),this.active(e,i))}updatePage(e,t=!1){const i=this.getPage(e.id);if(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=d.uid(),r=`${e.name}Copy`,a=`${e.title}_副本`,f=new u({id:s,name:r}).toDsl(),m=d.merge({},e,{id:s,name:r,title:a,dsl:f}),_=t?this.getPage(t)?.children||[]:this.pages,O=_.findIndex(T=>T.id===e.id);if(_.splice(O+1,0,m),!i){const T={model:this,type:"clone",data:{page:e,newPage:m}};n.emit(A,T),n.emit(h,T)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,a)=>{const f=a.findIndex(m=>m.id===r);if(f>=0){a.splice(f,1);return}for(const m of a)m.children&&m.children.length&&s(r,m.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||d.uid(),s=d.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(y,a),n.emit(h,a)}!this.currentFile&&r==="Schema"&&(await d.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(y,s),n.emit(h,s)}}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(y,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=d.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=d.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)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(k,t):n.emit(L,t)}}const C="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:d.uid(),label:new Date().toLocaleString(),dsl:d.cloneDeep(e)};if(this.items.unshift(s),this.items.length>i){const r=this.items.splice(i);t||n.emit(C,{model:this,type:"delete",data:r.map(a=>a.id)})}this.index=-1,t||n.emit(C,{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(C,{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(C,{model:this,type:"clear",data:t})}}const n=d.mitt();function $(l){return l instanceof u}function Y(l){return l instanceof p}function W(l){return!!l.__VTJ_BLOCK__}function H(l){return delete l.id,Array.isArray(l.children)&&(l.children=l.children.map(e=>H(e))),l}function q(l){const e=l.fromType||"Schema";return e==="Schema"?{type:"Schema",id:l.id}:e==="UrlSchema"?{type:"UrlSchema",url:(l.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(l.urls||"").split(","),library:l.library}:""}exports.BUILT_IN_COMPONENTS=w;exports.BUILT_IN_LIBRARAY_MAP=U;exports.BUILT_IN_MATERIALS=G;exports.BUILT_IN_NAME=J;exports.BUILT_IN_TAGS=F;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=B;exports.Base=j;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=o;exports.EVENT_HISTORY_CHANGE=C;exports.EVENT_HISTORY_LOAD=x;exports.EVENT_NODE_CHANGE=c;exports.EVENT_PROJECT_ACTIVED=P;exports.EVENT_PROJECT_APIS_CHANGE=V;exports.EVENT_PROJECT_BLOCKS_CHANGE=y;exports.EVENT_PROJECT_CHANGE=h;exports.EVENT_PROJECT_DEPS_CHANGE=g;exports.EVENT_PROJECT_FILE_PUBLISH=k;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=A;exports.EVENT_PROJECT_PUBLISH=L;exports.EventModel=v;exports.HistoryModel=K;exports.NodeModel=p;exports.ProjectModel=I;exports.PropModel=N;exports.Service=M;exports.VTJ_CORE_VERSION=b;exports.cloneDsl=H;exports.createNodeFrom=q;exports.emitter=n;exports.isBlock=$;exports.isBlockSchema=W;exports.isNode=Y;
7
+ */const b="0.8.147",J="BuiltIn",R="VueMaterial",B="VueRouterMaterial",G=[R,B],U={vue:"Vue","vue-router":"VueRouter"},w={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[B]:["RouterView","RouterLink"]},F=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class M{}class j{listeners=[];isReady=!1;triggerReady(){this.isReady=!0;for(const e of this.listeners)e();this.listeners=[]}ready(e){this.isReady?e():this.listeners.push(e)}resetReady(){this.isReady=!1}}class N{constructor(e,t,i){this.name=e,this.value=t,this.defaultValue=i,this.setValue(t)}isUnset=!1;setValue(e){this.value=e,this.isUnset=this.value===this.defaultValue}getValue(){return this.value??this.defaultValue}static toDsl(e={}){return Object.entries(e).reduce((t,[i,s])=>(s.isUnset||(t[i]=s.getValue()),t),{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new N(i,s),t),{})}}class v{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 v(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||d.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:f,id:m}=t;return{id:m,name:i,arg:s,modifiers:r,value:a,iterator:f}})}}const l="EVENT_NODE_CHANGE";class p{constructor(e,t=null){this.parent=t;const{id:i=d.uid(),name:s,from:r=""}=e;this.id=i,this.name=s,this.from=r,this.update(e,!0),p.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:f={},events:m={},directives:_=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(a,!0),this.props=N.parse(f),this.events=v.parse(m),this.directives=E.parse(_),t||n.emit(l,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new p(i,this)):this.children=e,t||n.emit(l,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(l,this)}setProp(e,t,i,s=!1){const r=this.props[e];r?r.setValue(t):this.props[e]=new N(e,t,i),s||n.emit(l,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(l,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 v(e),t||n.emit(l,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(l,this)}setDirective(e,t=!1){const i=this.directives.findIndex(s=>s.id===e.id);i>=0?this.directives.splice(i,1,new E(e)):this.directives.push(new E(e)),t||n.emit(l,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(l,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(l,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(l,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(l,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(l,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(l,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(l,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:f,props:m,directives:_,events:O}=this,T=Array.isArray(f)?f.map(k=>k.toDsl()):f;return{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:T,props:N.toDsl(m),directives:E.toDsl(_),events:v.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(l,this),this.parent=null,this.disposed=!0,delete p.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(l,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(l,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(l,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 o="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"];constructor(e){const{id:t}=e;this.id=t||d.uid(),this.update(e,!0)}update(e,t=!1){for(const s of u.normalAttrs){const r=e[s];r&&(this[s]=r)}const{nodes:i=[]}=e;i.length&&(this.nodes=i.map(s=>new p(s))),t||n.emit(o,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((a,f)=>(a[f]=this[f],a),{}),__VTJ_BLOCK__:t,__VERSION__:e||d.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(o,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(o,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(o,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(o,this)}setCss(e,t=!1){this.css=e,t||n.emit(o,this)}setWatch(e,t=!1){e.id=e.id||d.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(o,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(o,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(o,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(o,this))}setEmit(e,t=!1){const i=d.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(o,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>d.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||n.emit(o,this))}setSlot(e,t=!1){const i=d.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(o,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>d.isString(s)?s===e:s.name===e);i>-1&&(this.slots.splice(i,1),t||n.emit(o,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(o,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(o,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(o,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(o,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(o,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(o,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(o,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(o,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(o,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(o,this))}}cloneNode(e,t=!1){const i=H(e.toDsl()),s=new p(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(o,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(o,this)}isChild(e){let t=!1;for(const i of this.nodes)if(e===i||e.id===i.id){t=!0;break}else if(t=i.isChild(e),t)break;return t}}const c="EVENT_PROJECT_CHANGE",P="EVENT_PROJECT_ACTIVED",g="EVENT_PROJECT_DEPS_CHANGE",A="EVENT_PROJECT_PAGES_CHANGE",y="EVENT_PROJECT_BLOCKS_CHANGE",V="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",D="EVENT_PROJECT_PUBLISH",L="EVENT_PROJECT_FILE_PUBLISH";class I{id="";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};__BASE_PATH__="/";static attrs=["name","homepage","description","dependencies","pages","blocks","apis","meta","config","__BASE_PATH__"];constructor(e){const{id:t}=e;this.id=t||d.uid(),this.update(e,!0)}update(e,t=!1){for(const i of I.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(c,{model:this,type:"update",data:e})}isPageFile(e){return e.type==="page"}toDsl(e){const{id:t}=this,i=I.attrs.reduce((s,r)=>(s[r]=this[r],s),{});return i.pages&&(i.pages=i.pages.map(s=>(delete s.dsl,s))),i.blocks&&(i.blocks=i.blocks.map(s=>(delete s.dsl,s))),{__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(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(g,a),n.emit(c,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(g,r),n.emit(c,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||d.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:d.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(c,s)}!this.currentFile&&!e.dir&&(await d.delay(1e3),this.active(e,i))}updatePage(e,t=!1){const i=this.getPage(e.id);if(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(c,s)}}clonePage(e,t,i=!1){const s=d.uid(),r=`${e.name}Copy`,a=`${e.title}_副本`,f=new u({id:s,name:r}).toDsl(),m=d.merge({},e,{id:s,name:r,title:a,dsl:f}),_=t?this.getPage(t)?.children||[]:this.pages,O=_.findIndex(T=>T.id===e.id);if(_.splice(O+1,0,m),!i){const T={model:this,type:"clone",data:{page:e,newPage:m}};n.emit(A,T),n.emit(c,T)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,a)=>{const f=a.findIndex(m=>m.id===r);if(f>=0){a.splice(f,1);return}for(const m of a)m.children&&m.children.length&&s(r,m.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(c,r)}}getBlock(e){return this.blocks.find(t=>t.id===e)}async createBlock(e,t=!1){const i=e.id||d.uid(),s=d.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(y,a),n.emit(c,a)}!this.currentFile&&r==="Schema"&&(await d.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(y,s),n.emit(c,s)}}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(y,a),n.emit(c,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=d.uid(),this.apis.push(e)),!t){const r={model:this,type:s,data:e};n.emit(V,r),n.emit(c,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(c,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setMeta(e,t=!1){const i=this.meta.find(r=>r.code===e.code||r.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=d.uid(),this.meta.push(e)),!t){const r={model:this,type:s,data:e};n.emit(S,r),n.emit(c,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(c,s)}}existMetaCode(e,t=[]){return this.meta.some(i=>i.code===e&&!t.includes(i.id))}setHomepage(e,t=!1){if(this.homepage=e,!t){const i={model:this,type:"update",data:e};n.emit(c,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(c,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(L,t):n.emit(D,t)}}const C="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:d.uid(),label:new Date().toLocaleString(),dsl:d.cloneDeep(e)};if(this.items.unshift(s),this.items.length>i){const r=this.items.splice(i);t||n.emit(C,{model:this,type:"delete",data:r.map(a=>a.id)})}this.index=-1,t||n.emit(C,{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(C,{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(C,{model:this,type:"clear",data:t})}}const n=d.mitt();function $(h){return h instanceof u}function Y(h){return h instanceof p}function W(h){return!!h.__VTJ_BLOCK__}function H(h){const e=d.cloneDeep(h);return delete e.id,Array.isArray(e.children)&&(e.children=e.children.map(t=>H(t))),e}function q(h){const e=h.fromType||"Schema";return e==="Schema"?{type:"Schema",id:h.id}:e==="UrlSchema"?{type:"UrlSchema",url:(h.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(h.urls||"").split(","),library:h.library}:""}exports.BUILT_IN_COMPONENTS=w;exports.BUILT_IN_LIBRARAY_MAP=U;exports.BUILT_IN_MATERIALS=G;exports.BUILT_IN_NAME=J;exports.BUILT_IN_TAGS=F;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=B;exports.Base=j;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=o;exports.EVENT_HISTORY_CHANGE=C;exports.EVENT_HISTORY_LOAD=x;exports.EVENT_NODE_CHANGE=l;exports.EVENT_PROJECT_ACTIVED=P;exports.EVENT_PROJECT_APIS_CHANGE=V;exports.EVENT_PROJECT_BLOCKS_CHANGE=y;exports.EVENT_PROJECT_CHANGE=c;exports.EVENT_PROJECT_DEPS_CHANGE=g;exports.EVENT_PROJECT_FILE_PUBLISH=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=A;exports.EVENT_PROJECT_PUBLISH=D;exports.EventModel=v;exports.HistoryModel=K;exports.NodeModel=p;exports.ProjectModel=I;exports.PropModel=N;exports.Service=M;exports.VTJ_CORE_VERSION=b;exports.cloneDsl=H;exports.createNodeFrom=q;exports.emitter=n;exports.isBlock=$;exports.isBlockSchema=W;exports.isNode=Y;
package/dist/index.mjs CHANGED
@@ -1,23 +1,23 @@
1
- import { uid as m, timestamp as L, isString as A, upperFirstCamelCase as I, delay as V, merge as J, cloneDeep as G, mitt as F } from "@vtj/base";
1
+ import { uid as m, timestamp as J, isString as A, upperFirstCamelCase as I, delay as V, merge as G, cloneDeep as D, mitt as F } from "@vtj/base";
2
2
  /**!
3
3
  * Copyright (c) 2024, VTJ.PRO All rights reserved.
4
4
  * @name @vtj/core
5
5
  * @author CHC chenhuachun1549@dingtalk.com
6
- * @version 0.8.146
6
+ * @version 0.8.147
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const K = "0.8.146", M = "BuiltIn", D = "VueMaterial", b = "VueRouterMaterial", Y = [D, b], W = {
9
+ const K = "0.8.147", M = "BuiltIn", b = "VueMaterial", H = "VueRouterMaterial", Y = [b, H], W = {
10
10
  vue: "Vue",
11
11
  "vue-router": "VueRouter"
12
12
  }, q = {
13
- [D]: [
13
+ [b]: [
14
14
  "Transition",
15
15
  "TransitionGroup",
16
16
  "KeepAlive",
17
17
  "Teleport",
18
18
  "Suspense"
19
19
  ],
20
- [b]: ["RouterView", "RouterLink"]
20
+ [H]: ["RouterView", "RouterLink"]
21
21
  }, z = [
22
22
  "slot",
23
23
  "template",
@@ -147,7 +147,7 @@ class v {
147
147
  });
148
148
  }
149
149
  }
150
- const l = "EVENT_NODE_CHANGE";
150
+ const d = "EVENT_NODE_CHANGE";
151
151
  class p {
152
152
  constructor(e, t = null) {
153
153
  this.parent = t;
@@ -221,7 +221,7 @@ class p {
221
221
  events: f = {},
222
222
  directives: _ = []
223
223
  } = e;
224
- this.invisible = i, this.locked = s, this.setChildren(r, !0), this.setSlot(a, !0), this.props = x.parse(c), this.events = y.parse(f), this.directives = v.parse(_), t || n.emit(l, this);
224
+ this.invisible = i, this.locked = s, this.setChildren(r, !0), this.setSlot(a, !0), this.props = x.parse(c), this.events = y.parse(f), this.directives = v.parse(_), t || n.emit(d, this);
225
225
  }
226
226
  /**
227
227
  * 设置子节点
@@ -229,7 +229,7 @@ class p {
229
229
  * @param silent
230
230
  */
231
231
  setChildren(e = "", t = !1) {
232
- Array.isArray(e) ? this.children = e.map((i) => new p(i, this)) : this.children = e, t || n.emit(l, this);
232
+ Array.isArray(e) ? this.children = e.map((i) => new p(i, this)) : this.children = e, t || n.emit(d, this);
233
233
  }
234
234
  /**
235
235
  * 设置节点放置的插槽
@@ -237,7 +237,7 @@ class p {
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(l, this);
240
+ this.slot = typeof e == "string" ? { name: e, params: [] } : e, t || n.emit(d, this);
241
241
  }
242
242
  /**
243
243
  * 新增或更新属性
@@ -248,7 +248,7 @@ class p {
248
248
  */
249
249
  setProp(e, t, i, s = !1) {
250
250
  const r = this.props[e];
251
- r ? r.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(l, this);
251
+ r ? r.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(d, this);
252
252
  }
253
253
  /**
254
254
  * 删除属性
@@ -256,7 +256,7 @@ class p {
256
256
  * @param silent
257
257
  */
258
258
  removeProp(e, t = !1) {
259
- delete this.props[e], t || n.emit(l, this);
259
+ delete this.props[e], t || n.emit(d, this);
260
260
  }
261
261
  /**
262
262
  * 获取属性值
@@ -275,7 +275,7 @@ class p {
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 y(e), t || n.emit(l, this);
278
+ i ? i.update(e) : this.events[e.name] = new y(e), t || n.emit(d, this);
279
279
  }
280
280
  /**
281
281
  * 删除事件
@@ -283,7 +283,7 @@ class p {
283
283
  * @param silent
284
284
  */
285
285
  removeEvent(e, t = !1) {
286
- delete this.events[e], t || n.emit(l, this);
286
+ delete this.events[e], t || n.emit(d, this);
287
287
  }
288
288
  /**
289
289
  * 新增或更新指令
@@ -292,7 +292,7 @@ class p {
292
292
  */
293
293
  setDirective(e, t = !1) {
294
294
  const i = this.directives.findIndex((s) => s.id === e.id);
295
- i >= 0 ? this.directives.splice(i, 1, new v(e)) : this.directives.push(new v(e)), t || n.emit(l, this);
295
+ i >= 0 ? this.directives.splice(i, 1, new v(e)) : this.directives.push(new v(e)), t || n.emit(d, this);
296
296
  }
297
297
  /**
298
298
  * 删除指令
@@ -303,7 +303,7 @@ class p {
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(l, this);
306
+ i >= 0 && this.directives.splice(i, 1), t || n.emit(d, this);
307
307
  }
308
308
  /**
309
309
  * 删除子节点
@@ -315,7 +315,7 @@ class p {
315
315
  const { children: i, disposed: s } = this;
316
316
  if (s || !Array.isArray(i)) return;
317
317
  const r = i.findIndex((a) => a === e);
318
- e.parent = null, i.splice(r, 1), t || n.emit(l, this);
318
+ e.parent = null, i.splice(r, 1), t || n.emit(d, this);
319
319
  }
320
320
  /**
321
321
  * 追加子节点
@@ -325,7 +325,7 @@ class p {
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(l, this));
328
+ s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(d, this));
329
329
  }
330
330
  /**
331
331
  * 在当前节点的后面插入节点
@@ -339,7 +339,7 @@ class p {
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(l, this.parent);
342
+ i.splice(s + 1, 0, e), t || n.emit(d, this.parent);
343
343
  }
344
344
  }
345
345
  /**
@@ -354,7 +354,7 @@ class p {
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(l, this.parent);
357
+ i.splice(s, 0, e), t || n.emit(d, this.parent);
358
358
  }
359
359
  }
360
360
  movePrev(e = !1) {
@@ -363,7 +363,7 @@ class p {
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(l, t));
366
+ s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(d, t));
367
367
  }
368
368
  }
369
369
  moveNext(e = !1) {
@@ -372,7 +372,7 @@ class p {
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(l, t));
375
+ s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(d, t));
376
376
  }
377
377
  }
378
378
  /**
@@ -391,7 +391,7 @@ class p {
391
391
  props: f,
392
392
  directives: _,
393
393
  events: g
394
- } = this, E = Array.isArray(c) ? c.map((w) => w.toDsl()) : c;
394
+ } = this, E = Array.isArray(c) ? c.map((L) => L.toDsl()) : c;
395
395
  return {
396
396
  id: e,
397
397
  name: t,
@@ -412,25 +412,25 @@ class p {
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(l, this), this.parent = null, this.disposed = !0, delete p.nodes[this.id]);
415
+ i || (Array.isArray(t) && t.forEach((s) => s.dispose(!0)), this.parent ? this.parent.removeChild(this, e) : e || n.emit(d, this), this.parent = null, this.disposed = !0, delete p.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(l, this);
421
+ e || n.emit(d, 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(l, this);
427
+ e || n.emit(d, 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(l, this);
433
+ t || n.emit(d, this);
434
434
  }
435
435
  isChild(e) {
436
436
  let t = !1;
@@ -503,7 +503,7 @@ class u {
503
503
  {}
504
504
  ),
505
505
  __VTJ_BLOCK__: t,
506
- __VERSION__: e || L().toString(),
506
+ __VERSION__: e || J().toString(),
507
507
  id: i,
508
508
  nodes: s.map((a) => a.toDsl())
509
509
  };
@@ -755,7 +755,7 @@ class u {
755
755
  * @returns
756
756
  */
757
757
  cloneNode(e, t = !1) {
758
- const i = H(e.toDsl()), s = new p(i);
758
+ const i = w(e.toDsl()), s = new p(i);
759
759
  return this.addNode(s, e, "bottom", t), s;
760
760
  }
761
761
  lock(e = !1) {
@@ -979,7 +979,7 @@ class P {
979
979
  const s = m(), r = `${e.name}Copy`, a = `${e.title}_副本`, c = new u({
980
980
  id: s,
981
981
  name: r
982
- }).toDsl(), f = J({}, e, { id: s, name: r, title: a, dsl: c }), _ = t ? this.getPage(t)?.children || [] : this.pages, g = _.findIndex((E) => E.id === e.id);
982
+ }).toDsl(), f = G({}, e, { id: s, name: r, title: a, dsl: c }), _ = t ? this.getPage(t)?.children || [] : this.pages, g = _.findIndex((E) => E.id === e.id);
983
983
  if (_.splice(g + 1, 0, f), !i) {
984
984
  const E = {
985
985
  model: this,
@@ -1223,7 +1223,7 @@ class Z {
1223
1223
  const { max: i } = this.options, s = {
1224
1224
  id: m(),
1225
1225
  label: (/* @__PURE__ */ new Date()).toLocaleString(),
1226
- dsl: G(e)
1226
+ dsl: D(e)
1227
1227
  };
1228
1228
  if (this.items.unshift(s), this.items.length > i) {
1229
1229
  const r = this.items.splice(i);
@@ -1293,30 +1293,31 @@ class Z {
1293
1293
  }
1294
1294
  }
1295
1295
  const n = F();
1296
- function ee(d) {
1297
- return d instanceof u;
1296
+ function ee(l) {
1297
+ return l instanceof u;
1298
1298
  }
1299
- function te(d) {
1300
- return d instanceof p;
1299
+ function te(l) {
1300
+ return l instanceof p;
1301
1301
  }
1302
- function ie(d) {
1303
- return !!d.__VTJ_BLOCK__;
1302
+ function ie(l) {
1303
+ return !!l.__VTJ_BLOCK__;
1304
1304
  }
1305
- function H(d) {
1306
- return delete d.id, Array.isArray(d.children) && (d.children = d.children.map((e) => H(e))), d;
1305
+ function w(l) {
1306
+ const e = D(l);
1307
+ return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) => w(t))), e;
1307
1308
  }
1308
- function se(d) {
1309
- const e = d.fromType || "Schema";
1309
+ function se(l) {
1310
+ const e = l.fromType || "Schema";
1310
1311
  return e === "Schema" ? {
1311
1312
  type: "Schema",
1312
- id: d.id
1313
+ id: l.id
1313
1314
  } : e === "UrlSchema" ? {
1314
1315
  type: "UrlSchema",
1315
- url: (d.urls || "").split(",")[0] || ""
1316
+ url: (l.urls || "").split(",")[0] || ""
1316
1317
  } : e === "Plugin" ? {
1317
1318
  type: "Plugin",
1318
- urls: (d.urls || "").split(","),
1319
- library: d.library
1319
+ urls: (l.urls || "").split(","),
1320
+ library: l.library
1320
1321
  } : "";
1321
1322
  }
1322
1323
  export {
@@ -1325,15 +1326,15 @@ export {
1325
1326
  Y as BUILT_IN_MATERIALS,
1326
1327
  M as BUILT_IN_NAME,
1327
1328
  z as BUILT_IN_TAGS,
1328
- D as BUILT_IN_VUE,
1329
- b as BUILT_IN_VUE_ROUTER,
1329
+ b as BUILT_IN_VUE,
1330
+ H as BUILT_IN_VUE_ROUTER,
1330
1331
  X as Base,
1331
1332
  u as BlockModel,
1332
1333
  v as DirectiveModel,
1333
1334
  o as EVENT_BLOCK_CHANGE,
1334
1335
  N as EVENT_HISTORY_CHANGE,
1335
1336
  O as EVENT_HISTORY_LOAD,
1336
- l as EVENT_NODE_CHANGE,
1337
+ d as EVENT_NODE_CHANGE,
1337
1338
  S as EVENT_PROJECT_ACTIVED,
1338
1339
  k as EVENT_PROJECT_APIS_CHANGE,
1339
1340
  C as EVENT_PROJECT_BLOCKS_CHANGE,
@@ -1350,7 +1351,7 @@ export {
1350
1351
  x as PropModel,
1351
1352
  Q as Service,
1352
1353
  K as VTJ_CORE_VERSION,
1353
- H as cloneDsl,
1354
+ w as cloneDsl,
1354
1355
  se as createNodeFrom,
1355
1356
  n as emitter,
1356
1357
  ee as isBlock,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@vtj/core",
3
3
  "private": false,
4
- "version": "0.8.146",
4
+ "version": "0.8.147",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "@vtj/base": "~0.8.11"
8
8
  },
9
9
  "devDependencies": {
10
- "@vtj/cli": "~0.8.36"
10
+ "@vtj/cli": "~0.8.37"
11
11
  },
12
12
  "exports": {
13
13
  ".": {
@@ -3,5 +3,5 @@ import { BlockSchema, NodeSchema, BlockFile, NodeFrom } from '../protocols';
3
3
  export declare function isBlock(value: unknown): value is BlockModel;
4
4
  export declare function isNode(value: unknown): value is BlockModel;
5
5
  export declare function isBlockSchema(value: unknown): value is BlockSchema;
6
- export declare function cloneDsl(dsl: NodeSchema): NodeSchema;
6
+ export declare function cloneDsl(oDsl: NodeSchema): NodeSchema;
7
7
  export declare function createNodeFrom(file: BlockFile): NodeFrom;
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2024, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/core
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.8.145
5
+ * @version 0.8.146
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.8.145";
8
+ export declare const version = "0.8.146";