@vtj/core 0.7.9 → 0.7.11

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 h=require("@vtj/base");/**!
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@vtj/base");/**!
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.7.9
5
+ * @version 0.7.11
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const H="0.7.9";class b{}function B(o){return{all:o=o||new Map,on:function(e,t){var i=o.get(e);i?i.push(t):o.set(e,[t])},off:function(e,t){var i=o.get(e);i&&(t?i.splice(i.indexOf(t)>>>0,1):o.set(e,[]))},emit:function(e,t){var i=o.get(e);i&&i.slice().map(function(s){s(t)}),(i=o.get("*"))&&i.slice().map(function(s){s(e,t)})}}}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 x{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 x(i,s),t),{})}}class N{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:d}=s;return t[i]={name:i,handler:r,modifiers:d},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new N(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||h.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:d}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=r,this.iterator=d}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:d,iterator:c,id:f}=t;return{id:f,name:i,arg:s,modifiers:r,value:d,iterator:c}})}}const l="EVENT_NODE_CHANGE";class p{constructor(e,t=null){this.parent=t;const{id:i=h.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:d,props:c={},events:f={},directives:_=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(d,!0),this.props=x.parse(c),this.events=N.parse(f),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 x(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 N(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(d=>d===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:d,children:c,props:f,directives:_,events:P}=this,v=Array.isArray(c)?c.map(D=>D.toDsl()):c;return{id:e,name:t,from:i,invisible:s,locked:r,slot:d,children:v,props:x.toDsl(f),directives:E.toDsl(_),events:N.toDsl(P)}}dispose(e=!1){const{children:t,disposed:i}=this;i||(Array.isArray(t)&&t.forEach(s=>s.dispose(!0)),this.parent?this.parent.removeChild(this,e):e||n.emit(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 a="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||h.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(a,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((d,c)=>(d[c]=this[c],d),{}),__VTJ_BLOCK__:t,__VERSION__:e||h.timestamp().toString(),id:i,nodes:s.map(d=>d.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(a,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(a,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(a,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(a,this)}setCss(e,t=!1){this.css=e,t||n.emit(a,this)}setWatch(e,t=!1){e.id=e.id||h.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(a,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(a,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(a,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(a,this))}setEmit(e,t=!1){const i=this.emits.findIndex(s=>s===e);i>-1?this.emits.splice(i,1,e):this.emits.push(e),t||n.emit(a,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>s===e);i>-1&&(this.emits.splice(i,1),t||n.emit(a,this))}setSlot(e,t=!1){const i=this.slots.findIndex(s=>s===e);i>-1?this.slots.splice(i,1,e):this.slots.push(e),t||n.emit(a,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>s===e);i>-1&&(this.slots.splice(i,1),t||n.emit(a,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(a,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(a,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(a,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(a,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(a,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(a,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(a,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(a,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(a,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(a,this))}}cloneNode(e,t=!1){const i=I(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(a,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(a,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 m="EVENT_PROJECT_CHANGE",g="EVENT_PROJECT_ACTIVED",V="EVENT_PROJECT_DEPS_CHANGE",C="EVENT_PROJECT_PAGES_CHANGE",A="EVENT_PROJECT_BLOCKS_CHANGE",S="EVENT_PROJECT_APIS_CHANGE",R="EVENT_PROJECT_PUBLISH",k="EVENT_PROJECT_FILE_PUBLISH";class O{id="";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];currentFile=null;static attrs=["name","homepage","description","dependencies","pages","blocks","apis"];constructor(e){const{id:t}=e;this.id=t||h.uid(),this.update(e,!0)}update(e,t=!1){for(const i of O.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(m,{model:this,type:"update",data:e})}isPageFile(e){return e.type==="page"}toDsl(e){const{id:t}=this,i=O.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,__VERSION__:e||h.timestamp().toString(),id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(g,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(g,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(d=>d.package===e.package);let r;if(s>-1?(r="update",i.splice(s,1,{...i[s],...e})):(r="create",i.push(e)),!t){const d={model:this,type:r,data:e};n.emit(V,d),n.emit(m,d)}}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(V,r),n.emit(m,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 d=t(i,r.children);if(d)return d}}};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)}createPage(e,t,i=!1){if(e.id=e.raw?e.name:e.id||h.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:h.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(!this.currentFile&&!e.dir&&this.active(e,i),!i){const s={model:this,type:"create",data:e};n.emit(C,s),n.emit(m,s)}}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(C,s),n.emit(m,s)}}clonePage(e,t,i=!1){const s=h.uid(),r=`${e.name}Copy`,d=`${e.title}_副本`,c=new u({id:s,name:r}).toDsl(),f=h.merge({},e,{id:s,name:r,title:d,dsl:c}),_=t?this.getPage(t)?.children||[]:this.pages,P=_.findIndex(v=>v.id===e.id);if(_.splice(P+1,0,f),!i){const v={model:this,type:"clone",data:{page:e,newPage:f}};n.emit(C,v),n.emit(m,v)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,d)=>{const c=d.findIndex(f=>f.id===r);if(c>=0){d.splice(c,1);return}for(const f of d)if(f.children&&f.children.length)return 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(C,r),n.emit(m,r)}}getBlock(e){return this.blocks.find(t=>t.id===e)}createBlock(e,t=!1){const i=e.id||h.uid(),s=h.upperFirstCamelCase(e.name);if(e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e),this.currentFile||this.active(e,t),!t){const r={model:this,type:"create",data:e};n.emit(A,r),n.emit(m,r)}}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(A,s),n.emit(m,s)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,r=s.findIndex(d=>d.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 d={model:this,type:"delete",data:i};n.emit(A,d),n.emit(m,d)}}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=h.uid(),this.apis.push(e)),!t){const r={model:this,type:s,data:e};n.emit(S,r),n.emit(m,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(S,s),n.emit(m,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setHomepage(e,t=!1){if(this.homepage=e,!t){const i={model:this,type:"update",data:e};n.emit(m,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(k,t):n.emit(R,t)}}const T="EVENT_HISTORY_CHANGE",y="EVENT_HISTORY_LOAD";class G{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:h.uid(),label:new Date().toLocaleString(),dsl:h.cloneDeep(e)};if(this.items.unshift(s),this.items.length>i){const r=this.items.splice(i);t||n.emit(T,{model:this,type:"delete",data:r.map(d=>d.id)})}this.index=-1,t||n.emit(T,{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(T,{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(y,{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(y,{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(y,{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(T,{model:this,type:"clear",data:t})}}const n=B();function w(o){return o instanceof u}function L(o){return o instanceof p}function F(o){return!!o.__VTJ_BLOCK__}function I(o){return delete o.id,Array.isArray(o.children)&&(o.children=o.children.map(e=>I(e))),o}exports.Base=J;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=a;exports.EVENT_HISTORY_CHANGE=T;exports.EVENT_HISTORY_LOAD=y;exports.EVENT_NODE_CHANGE=l;exports.EVENT_PROJECT_ACTIVED=g;exports.EVENT_PROJECT_APIS_CHANGE=S;exports.EVENT_PROJECT_BLOCKS_CHANGE=A;exports.EVENT_PROJECT_CHANGE=m;exports.EVENT_PROJECT_DEPS_CHANGE=V;exports.EVENT_PROJECT_FILE_PUBLISH=k;exports.EVENT_PROJECT_PAGES_CHANGE=C;exports.EVENT_PROJECT_PUBLISH=R;exports.EventModel=N;exports.HistoryModel=G;exports.NodeModel=p;exports.ProjectModel=O;exports.PropModel=x;exports.Service=b;exports.VTJ_CORE_VERSION=H;exports.cloneDsl=I;exports.emitter=n;exports.isBlock=w;exports.isBlockSchema=F;exports.isNode=L;
7
+ */const H="0.7.11";class b{}class B{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 x{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:d}=s;return t[i]={name:i,handler:r,modifiers:d},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new x(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||l.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:d}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=r,this.iterator=d}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:d,iterator:h,id:f}=t;return{id:f,name:i,arg:s,modifiers:r,value:d,iterator:h}})}}const o="EVENT_NODE_CHANGE";class p{constructor(e,t=null){this.parent=t;const{id:i=l.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:d,props:h={},events:f={},directives:_=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(d,!0),this.props=N.parse(h),this.events=x.parse(f),this.directives=E.parse(_),t||n.emit(o,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new p(i,this)):this.children=e,t||n.emit(o,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(o,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(o,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(o,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 x(e),t||n.emit(o,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(o,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(o,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(o,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const r=i.findIndex(d=>d===e);e.parent=null,i.splice(r,1),t||n.emit(o,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(o,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(o,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(o,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(o,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(o,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:r,slot:d,children:h,props:f,directives:_,events:P}=this,v=Array.isArray(h)?h.map(D=>D.toDsl()):h;return{id:e,name:t,from:i,invisible:s,locked:r,slot:d,children:v,props:N.toDsl(f),directives:E.toDsl(_),events:x.toDsl(P)}}dispose(e=!1){const{children:t,disposed:i}=this;i||(Array.isArray(t)&&t.forEach(s=>s.dispose(!0)),this.parent?this.parent.removeChild(this,e):e||n.emit(o,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(o,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(o,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(o,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 a="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||l.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(a,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((d,h)=>(d[h]=this[h],d),{}),__VTJ_BLOCK__:t,__VERSION__:e||l.timestamp().toString(),id:i,nodes:s.map(d=>d.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(a,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(a,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(a,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(a,this)}setCss(e,t=!1){this.css=e,t||n.emit(a,this)}setWatch(e,t=!1){e.id=e.id||l.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(a,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(a,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(a,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(a,this))}setEmit(e,t=!1){const i=this.emits.findIndex(s=>s===e);i>-1?this.emits.splice(i,1,e):this.emits.push(e),t||n.emit(a,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>s===e);i>-1&&(this.emits.splice(i,1),t||n.emit(a,this))}setSlot(e,t=!1){const i=this.slots.findIndex(s=>s===e);i>-1?this.slots.splice(i,1,e):this.slots.push(e),t||n.emit(a,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>s===e);i>-1&&(this.slots.splice(i,1),t||n.emit(a,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(a,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(a,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(a,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(a,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(a,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(a,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(a,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(a,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(a,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(a,this))}}cloneNode(e,t=!1){const i=I(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(a,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(a,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 m="EVENT_PROJECT_CHANGE",g="EVENT_PROJECT_ACTIVED",V="EVENT_PROJECT_DEPS_CHANGE",C="EVENT_PROJECT_PAGES_CHANGE",A="EVENT_PROJECT_BLOCKS_CHANGE",S="EVENT_PROJECT_APIS_CHANGE",R="EVENT_PROJECT_PUBLISH",k="EVENT_PROJECT_FILE_PUBLISH";class O{id="";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];currentFile=null;static attrs=["name","homepage","description","dependencies","pages","blocks","apis"];constructor(e){const{id:t}=e;this.id=t||l.uid(),this.update(e,!0)}update(e,t=!1){for(const i of O.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(m,{model:this,type:"update",data:e})}isPageFile(e){return e.type==="page"}toDsl(e){const{id:t}=this,i=O.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,__VERSION__:e||l.timestamp().toString(),id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(g,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(g,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(d=>d.package===e.package);let r;if(s>-1?(r="update",i.splice(s,1,{...i[s],...e})):(r="create",i.push(e)),!t){const d={model:this,type:r,data:e};n.emit(V,d),n.emit(m,d)}}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(V,r),n.emit(m,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 d=t(i,r.children);if(d)return d}}};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)}createPage(e,t,i=!1){if(e.id=e.raw?e.name:e.id||l.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:l.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(!this.currentFile&&!e.dir&&this.active(e,i),!i){const s={model:this,type:"create",data:e};n.emit(C,s),n.emit(m,s)}}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(C,s),n.emit(m,s)}}clonePage(e,t,i=!1){const s=l.uid(),r=`${e.name}Copy`,d=`${e.title}_副本`,h=new u({id:s,name:r}).toDsl(),f=l.merge({},e,{id:s,name:r,title:d,dsl:h}),_=t?this.getPage(t)?.children||[]:this.pages,P=_.findIndex(v=>v.id===e.id);if(_.splice(P+1,0,f),!i){const v={model:this,type:"clone",data:{page:e,newPage:f}};n.emit(C,v),n.emit(m,v)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,d)=>{const h=d.findIndex(f=>f.id===r);if(h>=0){d.splice(h,1);return}for(const f of d)if(f.children&&f.children.length)return 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(C,r),n.emit(m,r)}}getBlock(e){return this.blocks.find(t=>t.id===e)}createBlock(e,t=!1){const i=e.id||l.uid(),s=l.upperFirstCamelCase(e.name);if(e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e),this.currentFile||this.active(e,t),!t){const r={model:this,type:"create",data:e};n.emit(A,r),n.emit(m,r)}}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(A,s),n.emit(m,s)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,r=s.findIndex(d=>d.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 d={model:this,type:"delete",data:i};n.emit(A,d),n.emit(m,d)}}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=l.uid(),this.apis.push(e)),!t){const r={model:this,type:s,data:e};n.emit(S,r),n.emit(m,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(S,s),n.emit(m,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setHomepage(e,t=!1){if(this.homepage=e,!t){const i={model:this,type:"update",data:e};n.emit(m,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(k,t):n.emit(R,t)}}const T="EVENT_HISTORY_CHANGE",y="EVENT_HISTORY_LOAD";class J{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:l.uid(),label:new Date().toLocaleString(),dsl:l.cloneDeep(e)};if(this.items.unshift(s),this.items.length>i){const r=this.items.splice(i);t||n.emit(T,{model:this,type:"delete",data:r.map(d=>d.id)})}this.index=-1,t||n.emit(T,{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(T,{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(y,{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(y,{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(y,{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(T,{model:this,type:"clear",data:t})}}const n=l.mitt();function G(c){return c instanceof u}function w(c){return c instanceof p}function L(c){return!!c.__VTJ_BLOCK__}function I(c){return delete c.id,Array.isArray(c.children)&&(c.children=c.children.map(e=>I(e))),c}exports.Base=B;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=a;exports.EVENT_HISTORY_CHANGE=T;exports.EVENT_HISTORY_LOAD=y;exports.EVENT_NODE_CHANGE=o;exports.EVENT_PROJECT_ACTIVED=g;exports.EVENT_PROJECT_APIS_CHANGE=S;exports.EVENT_PROJECT_BLOCKS_CHANGE=A;exports.EVENT_PROJECT_CHANGE=m;exports.EVENT_PROJECT_DEPS_CHANGE=V;exports.EVENT_PROJECT_FILE_PUBLISH=k;exports.EVENT_PROJECT_PAGES_CHANGE=C;exports.EVENT_PROJECT_PUBLISH=R;exports.EventModel=x;exports.HistoryModel=J;exports.NodeModel=p;exports.ProjectModel=O;exports.PropModel=N;exports.Service=b;exports.VTJ_CORE_VERSION=H;exports.cloneDsl=I;exports.emitter=n;exports.isBlock=G;exports.isBlockSchema=L;exports.isNode=w;
package/dist/index.mjs CHANGED
@@ -1,30 +1,14 @@
1
- import { uid as m, timestamp as S, upperFirstCamelCase as P, merge as b, cloneDeep as H } from "@vtj/base";
1
+ import { uid as m, timestamp as S, upperFirstCamelCase as P, merge as b, cloneDeep as H, mitt as w } 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.7.9
6
+ * @version 0.7.11
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const G = "0.7.9";
9
+ const G = "0.7.11";
10
10
  class j {
11
11
  }
12
- function w(o) {
13
- return { all: o = o || /* @__PURE__ */ new Map(), on: function(e, t) {
14
- var i = o.get(e);
15
- i ? i.push(t) : o.set(e, [t]);
16
- }, off: function(e, t) {
17
- var i = o.get(e);
18
- i && (t ? i.splice(i.indexOf(t) >>> 0, 1) : o.set(e, []));
19
- }, emit: function(e, t) {
20
- var i = o.get(e);
21
- i && i.slice().map(function(s) {
22
- s(t);
23
- }), (i = o.get("*")) && i.slice().map(function(s) {
24
- s(e, t);
25
- });
26
- } };
27
- }
28
12
  class L {
29
13
  listeners = [];
30
14
  isReady = !1;
@@ -127,19 +111,19 @@ class _ {
127
111
  }
128
112
  static toDsl(e = []) {
129
113
  return e.map((t) => {
130
- const { name: i, arg: s, modifiers: r, value: a, iterator: h, id: c } = t;
114
+ const { name: i, arg: s, modifiers: r, value: a, iterator: l, id: c } = t;
131
115
  return {
132
116
  id: c,
133
117
  name: i,
134
118
  arg: s,
135
119
  modifiers: r,
136
120
  value: a,
137
- iterator: h
121
+ iterator: l
138
122
  };
139
123
  });
140
124
  }
141
125
  }
142
- const l = "EVENT_NODE_CHANGE";
126
+ const o = "EVENT_NODE_CHANGE";
143
127
  class p {
144
128
  constructor(e, t = null) {
145
129
  this.parent = t;
@@ -209,11 +193,11 @@ class p {
209
193
  locked: s = !1,
210
194
  children: r = [],
211
195
  slot: a,
212
- props: h = {},
196
+ props: l = {},
213
197
  events: c = {},
214
198
  directives: E = []
215
199
  } = e;
216
- this.invisible = i, this.locked = s, this.setChildren(r, !0), this.setSlot(a, !0), this.props = x.parse(h), this.events = y.parse(c), this.directives = _.parse(E), t || n.emit(l, this);
200
+ this.invisible = i, this.locked = s, this.setChildren(r, !0), this.setSlot(a, !0), this.props = x.parse(l), this.events = y.parse(c), this.directives = _.parse(E), t || n.emit(o, this);
217
201
  }
218
202
  /**
219
203
  * 设置子节点
@@ -221,7 +205,7 @@ class p {
221
205
  * @param silent
222
206
  */
223
207
  setChildren(e = "", t = !1) {
224
- Array.isArray(e) ? this.children = e.map((i) => new p(i, this)) : this.children = e, t || n.emit(l, this);
208
+ Array.isArray(e) ? this.children = e.map((i) => new p(i, this)) : this.children = e, t || n.emit(o, this);
225
209
  }
226
210
  /**
227
211
  * 设置节点放置的插槽
@@ -229,7 +213,7 @@ class p {
229
213
  * @param silent
230
214
  */
231
215
  setSlot(e, t = !1) {
232
- this.slot = typeof e == "string" ? { name: e, params: [] } : e, t || n.emit(l, this);
216
+ this.slot = typeof e == "string" ? { name: e, params: [] } : e, t || n.emit(o, this);
233
217
  }
234
218
  /**
235
219
  * 新增或更新属性
@@ -240,7 +224,7 @@ class p {
240
224
  */
241
225
  setProp(e, t, i, s = !1) {
242
226
  const r = this.props[e];
243
- r ? r.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(l, this);
227
+ r ? r.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(o, this);
244
228
  }
245
229
  /**
246
230
  * 删除属性
@@ -248,7 +232,7 @@ class p {
248
232
  * @param silent
249
233
  */
250
234
  removeProp(e, t = !1) {
251
- delete this.props[e], t || n.emit(l, this);
235
+ delete this.props[e], t || n.emit(o, this);
252
236
  }
253
237
  /**
254
238
  * 获取属性值
@@ -267,7 +251,7 @@ class p {
267
251
  */
268
252
  setEvent(e, t = !1) {
269
253
  const i = this.events[e.name];
270
- i ? i.update(e) : this.events[e.name] = new y(e), t || n.emit(l, this);
254
+ i ? i.update(e) : this.events[e.name] = new y(e), t || n.emit(o, this);
271
255
  }
272
256
  /**
273
257
  * 删除事件
@@ -275,7 +259,7 @@ class p {
275
259
  * @param silent
276
260
  */
277
261
  removeEvent(e, t = !1) {
278
- delete this.events[e], t || n.emit(l, this);
262
+ delete this.events[e], t || n.emit(o, this);
279
263
  }
280
264
  /**
281
265
  * 新增或更新指令
@@ -284,7 +268,7 @@ class p {
284
268
  */
285
269
  setDirective(e, t = !1) {
286
270
  const i = this.directives.findIndex((s) => s.id === e.id);
287
- i >= 0 ? this.directives.splice(i, 1, new _(e)) : this.directives.push(new _(e)), t || n.emit(l, this);
271
+ i >= 0 ? this.directives.splice(i, 1, new _(e)) : this.directives.push(new _(e)), t || n.emit(o, this);
288
272
  }
289
273
  /**
290
274
  * 删除指令
@@ -295,7 +279,7 @@ class p {
295
279
  const i = this.directives.findIndex(
296
280
  (s) => s === e || s.id === e.id
297
281
  );
298
- i >= 0 && this.directives.splice(i, 1), t || n.emit(l, this);
282
+ i >= 0 && this.directives.splice(i, 1), t || n.emit(o, this);
299
283
  }
300
284
  /**
301
285
  * 删除子节点
@@ -308,7 +292,7 @@ class p {
308
292
  if (s || !Array.isArray(i))
309
293
  return;
310
294
  const r = i.findIndex((a) => a === e);
311
- e.parent = null, i.splice(r, 1), t || n.emit(l, this);
295
+ e.parent = null, i.splice(r, 1), t || n.emit(o, this);
312
296
  }
313
297
  /**
314
298
  * 追加子节点
@@ -318,7 +302,7 @@ class p {
318
302
  */
319
303
  appendChild(e, t = !1) {
320
304
  const { children: i, disposed: s } = this;
321
- s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(l, this));
305
+ s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(o, this));
322
306
  }
323
307
  /**
324
308
  * 在当前节点的后面插入节点
@@ -333,7 +317,7 @@ class p {
333
317
  if (Array.isArray(i)) {
334
318
  e.parent = this.parent;
335
319
  const s = i.indexOf(this);
336
- i.splice(s + 1, 0, e), t || n.emit(l, this.parent);
320
+ i.splice(s + 1, 0, e), t || n.emit(o, this.parent);
337
321
  }
338
322
  }
339
323
  /**
@@ -349,7 +333,7 @@ class p {
349
333
  if (Array.isArray(i)) {
350
334
  e.parent = this.parent;
351
335
  const s = i.indexOf(this);
352
- i.splice(s, 0, e), t || n.emit(l, this.parent);
336
+ i.splice(s, 0, e), t || n.emit(o, this.parent);
353
337
  }
354
338
  }
355
339
  movePrev(e = !1) {
@@ -359,7 +343,7 @@ class p {
359
343
  const i = t.children;
360
344
  if (Array.isArray(i)) {
361
345
  const s = i.indexOf(this);
362
- s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(l, t));
346
+ s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(o, t));
363
347
  }
364
348
  }
365
349
  moveNext(e = !1) {
@@ -369,7 +353,7 @@ class p {
369
353
  const i = t.children;
370
354
  if (Array.isArray(i)) {
371
355
  const s = i.indexOf(this);
372
- s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(l, t));
356
+ s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(o, t));
373
357
  }
374
358
  }
375
359
  /**
@@ -384,11 +368,11 @@ class p {
384
368
  invisible: s,
385
369
  locked: r,
386
370
  slot: a,
387
- children: h,
371
+ children: l,
388
372
  props: c,
389
373
  directives: E,
390
- events: N
391
- } = this, v = Array.isArray(h) ? h.map((R) => R.toDsl()) : h;
374
+ events: C
375
+ } = this, v = Array.isArray(l) ? l.map((R) => R.toDsl()) : l;
392
376
  return {
393
377
  id: e,
394
378
  name: t,
@@ -399,7 +383,7 @@ class p {
399
383
  children: v,
400
384
  props: x.toDsl(c),
401
385
  directives: _.toDsl(E),
402
- events: y.toDsl(N)
386
+ events: y.toDsl(C)
403
387
  };
404
388
  }
405
389
  /**
@@ -409,25 +393,25 @@ class p {
409
393
  */
410
394
  dispose(e = !1) {
411
395
  const { children: t, disposed: i } = this;
412
- 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]);
396
+ i || (Array.isArray(t) && t.forEach((s) => s.dispose(!0)), this.parent ? this.parent.removeChild(this, e) : e || n.emit(o, this), this.parent = null, this.disposed = !0, delete p.nodes[this.id]);
413
397
  }
414
398
  lock(e = !1) {
415
399
  if (this.locked = !0, Array.isArray(this.children))
416
400
  for (const t of this.children)
417
401
  t.lock(!0);
418
- e || n.emit(l, this);
402
+ e || n.emit(o, this);
419
403
  }
420
404
  unlock(e = !1) {
421
405
  if (this.locked = !1, Array.isArray(this.children))
422
406
  for (const t of this.children)
423
407
  t.unlock(!0);
424
- e || n.emit(l, this);
408
+ e || n.emit(o, this);
425
409
  }
426
410
  setVisible(e, t = !1) {
427
411
  if (this.invisible = !e, Array.isArray(this.children))
428
412
  for (const i of this.children)
429
413
  i.setVisible(e, !0);
430
- t || n.emit(l, this);
414
+ t || n.emit(o, this);
431
415
  }
432
416
  isChild(e) {
433
417
  let t = !1;
@@ -496,7 +480,7 @@ class u {
496
480
  const { __VTJ_BLOCK__: t, id: i, nodes: s } = this;
497
481
  return {
498
482
  ...u.normalAttrs.reduce(
499
- (a, h) => (a[h] = this[h], a),
483
+ (a, l) => (a[l] = this[l], a),
500
484
  {}
501
485
  ),
502
486
  __VTJ_BLOCK__: t,
@@ -774,7 +758,7 @@ class u {
774
758
  return t;
775
759
  }
776
760
  }
777
- const f = "EVENT_PROJECT_CHANGE", V = "EVENT_PROJECT_ACTIVED", I = "EVENT_PROJECT_DEPS_CHANGE", A = "EVENT_PROJECT_PAGES_CHANGE", C = "EVENT_PROJECT_BLOCKS_CHANGE", k = "EVENT_PROJECT_APIS_CHANGE", B = "EVENT_PROJECT_PUBLISH", J = "EVENT_PROJECT_FILE_PUBLISH";
761
+ const f = "EVENT_PROJECT_CHANGE", V = "EVENT_PROJECT_ACTIVED", I = "EVENT_PROJECT_DEPS_CHANGE", A = "EVENT_PROJECT_PAGES_CHANGE", g = "EVENT_PROJECT_BLOCKS_CHANGE", k = "EVENT_PROJECT_APIS_CHANGE", B = "EVENT_PROJECT_PUBLISH", J = "EVENT_PROJECT_FILE_PUBLISH";
778
762
  class T {
779
763
  id = "";
780
764
  name = "";
@@ -962,11 +946,11 @@ class T {
962
946
  * @param silent
963
947
  */
964
948
  clonePage(e, t, i = !1) {
965
- const s = m(), r = `${e.name}Copy`, a = `${e.title}_副本`, h = new u({
949
+ const s = m(), r = `${e.name}Copy`, a = `${e.title}_副本`, l = new u({
966
950
  id: s,
967
951
  name: r
968
- }).toDsl(), c = b({}, e, { id: s, name: r, title: a, dsl: h }), E = t ? this.getPage(t)?.children || [] : this.pages, N = E.findIndex((v) => v.id === e.id);
969
- if (E.splice(N + 1, 0, c), !i) {
952
+ }).toDsl(), c = b({}, e, { id: s, name: r, title: a, dsl: l }), E = t ? this.getPage(t)?.children || [] : this.pages, C = E.findIndex((v) => v.id === e.id);
953
+ if (E.splice(C + 1, 0, c), !i) {
970
954
  const v = {
971
955
  model: this,
972
956
  type: "clone",
@@ -985,9 +969,9 @@ class T {
985
969
  */
986
970
  removePage(e, t = !1) {
987
971
  const i = this.getPage(e), s = (r, a) => {
988
- const h = a.findIndex((c) => c.id === r);
989
- if (h >= 0) {
990
- a.splice(h, 1);
972
+ const l = a.findIndex((c) => c.id === r);
973
+ if (l >= 0) {
974
+ a.splice(l, 1);
991
975
  return;
992
976
  }
993
977
  for (const c of a)
@@ -1024,7 +1008,7 @@ class T {
1024
1008
  type: "create",
1025
1009
  data: e
1026
1010
  };
1027
- n.emit(C, r), n.emit(f, r);
1011
+ n.emit(g, r), n.emit(f, r);
1028
1012
  }
1029
1013
  }
1030
1014
  /**
@@ -1040,7 +1024,7 @@ class T {
1040
1024
  type: "update",
1041
1025
  data: e
1042
1026
  };
1043
- n.emit(C, s), n.emit(f, s);
1027
+ n.emit(g, s), n.emit(f, s);
1044
1028
  }
1045
1029
  }
1046
1030
  /**
@@ -1056,7 +1040,7 @@ class T {
1056
1040
  type: "delete",
1057
1041
  data: i
1058
1042
  };
1059
- n.emit(C, a), n.emit(f, a);
1043
+ n.emit(g, a), n.emit(f, a);
1060
1044
  }
1061
1045
  }
1062
1046
  /**
@@ -1134,7 +1118,7 @@ class T {
1134
1118
  e ? n.emit(J, t) : n.emit(B, t);
1135
1119
  }
1136
1120
  }
1137
- const g = "EVENT_HISTORY_CHANGE", O = "EVENT_HISTORY_LOAD";
1121
+ const N = "EVENT_HISTORY_CHANGE", O = "EVENT_HISTORY_LOAD";
1138
1122
  class $ {
1139
1123
  options = { max: 50 };
1140
1124
  index = -1;
@@ -1173,13 +1157,13 @@ class $ {
1173
1157
  };
1174
1158
  if (this.items.unshift(s), this.items.length > i) {
1175
1159
  const r = this.items.splice(i);
1176
- t || n.emit(g, {
1160
+ t || n.emit(N, {
1177
1161
  model: this,
1178
1162
  type: "delete",
1179
1163
  data: r.map((a) => a.id)
1180
1164
  });
1181
1165
  }
1182
- this.index = -1, t || n.emit(g, {
1166
+ this.index = -1, t || n.emit(N, {
1183
1167
  model: this,
1184
1168
  type: "create",
1185
1169
  data: s
@@ -1192,7 +1176,7 @@ class $ {
1192
1176
  */
1193
1177
  remove(e, t = !1) {
1194
1178
  const i = this.items.findIndex((s) => s.id === e);
1195
- 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(g, {
1179
+ 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(N, {
1196
1180
  model: this,
1197
1181
  type: "delete",
1198
1182
  data: [e]
@@ -1233,7 +1217,7 @@ class $ {
1233
1217
  clear(e = !1) {
1234
1218
  this.index = -1;
1235
1219
  const t = this.items.map((i) => i.id);
1236
- this.items = [], e || n.emit(g, {
1220
+ this.items = [], e || n.emit(N, {
1237
1221
  model: this,
1238
1222
  type: "clear",
1239
1223
  data: t
@@ -1241,29 +1225,29 @@ class $ {
1241
1225
  }
1242
1226
  }
1243
1227
  const n = w();
1244
- function K(o) {
1245
- return o instanceof u;
1228
+ function K(h) {
1229
+ return h instanceof u;
1246
1230
  }
1247
- function U(o) {
1248
- return o instanceof p;
1231
+ function U(h) {
1232
+ return h instanceof p;
1249
1233
  }
1250
- function Y(o) {
1251
- return !!o.__VTJ_BLOCK__;
1234
+ function Y(h) {
1235
+ return !!h.__VTJ_BLOCK__;
1252
1236
  }
1253
- function D(o) {
1254
- return delete o.id, Array.isArray(o.children) && (o.children = o.children.map((e) => D(e))), o;
1237
+ function D(h) {
1238
+ return delete h.id, Array.isArray(h.children) && (h.children = h.children.map((e) => D(e))), h;
1255
1239
  }
1256
1240
  export {
1257
1241
  L as Base,
1258
1242
  u as BlockModel,
1259
1243
  _ as DirectiveModel,
1260
1244
  d as EVENT_BLOCK_CHANGE,
1261
- g as EVENT_HISTORY_CHANGE,
1245
+ N as EVENT_HISTORY_CHANGE,
1262
1246
  O as EVENT_HISTORY_LOAD,
1263
- l as EVENT_NODE_CHANGE,
1247
+ o as EVENT_NODE_CHANGE,
1264
1248
  V as EVENT_PROJECT_ACTIVED,
1265
1249
  k as EVENT_PROJECT_APIS_CHANGE,
1266
- C as EVENT_PROJECT_BLOCKS_CHANGE,
1250
+ g as EVENT_PROJECT_BLOCKS_CHANGE,
1267
1251
  f as EVENT_PROJECT_CHANGE,
1268
1252
  I as EVENT_PROJECT_DEPS_CHANGE,
1269
1253
  J as EVENT_PROJECT_FILE_PUBLISH,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/core",
3
3
  "private": false,
4
- "version": "0.7.9",
4
+ "version": "0.7.11",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "vue-tsc && vite build",
@@ -10,11 +10,10 @@
10
10
  "coverage": "vitest run --coverage"
11
11
  },
12
12
  "dependencies": {
13
- "@vtj/base": "^0.7.3",
14
- "mitt": "~3.0.1"
13
+ "@vtj/base": "^0.7.4"
15
14
  },
16
15
  "devDependencies": {
17
- "@vtj/cli": "^0.7.7"
16
+ "@vtj/cli": "^0.7.8"
18
17
  },
19
18
  "exports": {
20
19
  ".": {
@@ -30,7 +29,7 @@
30
29
  "dist",
31
30
  "types"
32
31
  ],
33
- "gitHead": "923aab791b5aacf1f0e75255ad7aa2b1b71e26bf",
32
+ "gitHead": "c06eab62d9b15ba39fd489316dc9389030b2d040",
34
33
  "publishConfig": {
35
34
  "access": "public"
36
35
  }
@@ -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.7.8
5
+ * @version 0.7.10
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.7.8";
8
+ export declare const version = "0.7.10";