@vtj/core 0.7.34 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@vtj/base");/**!
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=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.34
5
+ * @version 0.8.0
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const H="0.7.34",b="BuiltIn",R="VueMaterial",S="VueRouterMaterial",J=[R,S],G={vue:"Vue","vue-router":"VueRouter"},U={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[S]:["RouterView","RouterLink"]},w=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class F{}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 T{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 T(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:o}=s;return t[i]={name:i,handler:r,modifiers:o},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||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:o}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=r,this.iterator=o}static parse(e=[]){return e.map(t=>new E(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:r,value:o,iterator:h,id:m}=t;return{id:m,name:i,arg:s,modifiers:r,value:o,iterator:h}})}}const d="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:o,props:h={},events:m={},directives:_=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(o,!0),this.props=T.parse(h),this.events=v.parse(m),this.directives=E.parse(_),t||n.emit(d,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new p(i,this)):this.children=e,t||n.emit(d,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(d,this)}setProp(e,t,i,s=!1){const r=this.props[e];r?r.setValue(t):this.props[e]=new T(e,t,i),s||n.emit(d,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(d,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(d,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(d,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(d,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(d,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const r=i.findIndex(o=>o===e);e.parent=null,i.splice(r,1),t||n.emit(d,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(d,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(d,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(d,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(d,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(d,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:r,slot:o,children:h,props:m,directives:_,events:y}=this,N=Array.isArray(h)?h.map(D=>D.toDsl()):h;return{id:e,name:t,from:i,invisible:s,locked:r,slot:o,children:N,props:T.toDsl(m),directives:E.toDsl(_),events:v.toDsl(y)}}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(d,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(d,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(d,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(d,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((o,h)=>(o[h]=this[h],o),{}),__VTJ_BLOCK__:t,__VERSION__:e||l.timestamp().toString(),id:i,nodes:s.map(o=>o.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}setFunction(e,t,i,s=!1){this[e][t]=i,s||n.emit(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=B(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 c="EVENT_PROJECT_CHANGE",P="EVENT_PROJECT_ACTIVED",V="EVENT_PROJECT_DEPS_CHANGE",A="EVENT_PROJECT_PAGES_CHANGE",x="EVENT_PROJECT_BLOCKS_CHANGE",g="EVENT_PROJECT_APIS_CHANGE",k="EVENT_PROJECT_PUBLISH",L="EVENT_PROJECT_FILE_PUBLISH";class O{id="";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];currentFile=null;config={};static attrs=["name","homepage","description","dependencies","pages","blocks","apis","config"];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(c,{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(P,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(P,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(o=>o.package===e.package);let r;if(s>-1?(r="update",i.splice(s,1,{...i[s],...e})):(r="create",i.push(e)),!t){const o={model:this,type:r,data:e};n.emit(V,o),n.emit(c,o)}}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(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 o=t(i,r.children);if(o)return o}}};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(A,s),n.emit(c,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(A,s),n.emit(c,s)}}clonePage(e,t,i=!1){const s=l.uid(),r=`${e.name}Copy`,o=`${e.title}_副本`,h=new u({id:s,name:r}).toDsl(),m=l.merge({},e,{id:s,name:r,title:o,dsl:h}),_=t?this.getPage(t)?.children||[]:this.pages,y=_.findIndex(N=>N.id===e.id);if(_.splice(y+1,0,m),!i){const N={model:this,type:"clone",data:{page:e,newPage:m}};n.emit(A,N),n.emit(c,N)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,o)=>{const h=o.findIndex(m=>m.id===r);if(h>=0){o.splice(h,1);return}for(const m of o)if(m.children&&m.children.length)return 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)}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(x,r),n.emit(c,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(x,s),n.emit(c,s)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,r=s.findIndex(o=>o.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 o={model:this,type:"delete",data:i};n.emit(x,o),n.emit(c,o)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(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(g,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(g,s),n.emit(c,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(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(k,t)}}const C="EVENT_HISTORY_CHANGE",I="EVENT_HISTORY_LOAD";class M{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(C,{model:this,type:"delete",data:r.map(o=>o.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(I,{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(I,{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(I,{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=l.mitt();function K(f){return f instanceof u}function Y(f){return f instanceof p}function $(f){return!!f.__VTJ_BLOCK__}function B(f){return delete f.id,Array.isArray(f.children)&&(f.children=f.children.map(e=>B(e))),f}exports.BUILT_IN_COMPONENTS=U;exports.BUILT_IN_LIBRARAY_MAP=G;exports.BUILT_IN_MATERIALS=J;exports.BUILT_IN_NAME=b;exports.BUILT_IN_TAGS=w;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=S;exports.Base=j;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=a;exports.EVENT_HISTORY_CHANGE=C;exports.EVENT_HISTORY_LOAD=I;exports.EVENT_NODE_CHANGE=d;exports.EVENT_PROJECT_ACTIVED=P;exports.EVENT_PROJECT_APIS_CHANGE=g;exports.EVENT_PROJECT_BLOCKS_CHANGE=x;exports.EVENT_PROJECT_CHANGE=c;exports.EVENT_PROJECT_DEPS_CHANGE=V;exports.EVENT_PROJECT_FILE_PUBLISH=L;exports.EVENT_PROJECT_PAGES_CHANGE=A;exports.EVENT_PROJECT_PUBLISH=k;exports.EventModel=v;exports.HistoryModel=M;exports.NodeModel=p;exports.ProjectModel=O;exports.PropModel=T;exports.Service=F;exports.VTJ_CORE_VERSION=H;exports.cloneDsl=B;exports.emitter=n;exports.isBlock=K;exports.isBlockSchema=$;exports.isNode=Y;
7
+ */const H="0.8.0",b="BuiltIn",S="VueMaterial",R="VueRouterMaterial",J=[S,R],U={vue:"Vue","vue-router":"VueRouter"},G={[S]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[R]:["RouterView","RouterLink"]},w=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class F{}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 T{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 T(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:o}=s;return t[i]={name:i,handler:r,modifiers:o},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||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:o}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=r,this.iterator=o}static parse(e=[]){return e.map(t=>new E(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:r,value:o,iterator:c,id:m}=t;return{id:m,name:i,arg:s,modifiers:r,value:o,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:o,props:c={},events:m={},directives:_=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(o,!0),this.props=T.parse(c),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 T(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(o=>o===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:o,children:c,props:m,directives:_,events:O}=this,N=Array.isArray(c)?c.map(D=>D.toDsl()):c;return{id:e,name:t,from:i,invisible:s,locked:r,slot:o,children:N,props:T.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 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((o,c)=>(o[c]=this[c],o),{}),__VTJ_BLOCK__:t,__VERSION__:e||h.timestamp().toString(),id:i,nodes:s.map(o=>o.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}setFunction(e,t,i,s=!1){this[e][t]=i,s||n.emit(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=B(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 f="EVENT_PROJECT_CHANGE",P="EVENT_PROJECT_ACTIVED",g="EVENT_PROJECT_DEPS_CHANGE",A="EVENT_PROJECT_PAGES_CHANGE",C="EVENT_PROJECT_BLOCKS_CHANGE",V="EVENT_PROJECT_APIS_CHANGE",L="EVENT_PROJECT_PUBLISH",k="EVENT_PROJECT_FILE_PUBLISH";class I{id="";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];currentFile=null;config={};static attrs=["name","homepage","description","dependencies","pages","blocks","apis","config"];constructor(e){const{id:t}=e;this.id=t||h.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(f,{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,__VERSION__:e||h.timestamp().toString(),id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(P,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(P,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(o=>o.package===e.package);let r;if(s>-1?(r="update",i.splice(s,1,{...i[s],...e})):(r="create",i.push(e)),!t){const o={model:this,type:r,data:e};n.emit(g,o),n.emit(f,o)}}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(f,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 o=t(i,r.children);if(o)return o}}};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(A,s),n.emit(f,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(A,s),n.emit(f,s)}}clonePage(e,t,i=!1){const s=h.uid(),r=`${e.name}Copy`,o=`${e.title}_副本`,c=new u({id:s,name:r}).toDsl(),m=h.merge({},e,{id:s,name:r,title:o,dsl:c}),_=t?this.getPage(t)?.children||[]:this.pages,O=_.findIndex(N=>N.id===e.id);if(_.splice(O+1,0,m),!i){const N={model:this,type:"clone",data:{page:e,newPage:m}};n.emit(A,N),n.emit(f,N)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,o)=>{const c=o.findIndex(m=>m.id===r);if(c>=0){o.splice(c,1);return}for(const m of o)if(m.children&&m.children.length)return 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(f,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);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(!this.currentFile&&r==="Schema"&&this.active(e,t),!t){const o={model:this,type:"create",data:e};n.emit(C,o),n.emit(f,o)}}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(C,s),n.emit(f,s)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,r=s.findIndex(o=>o.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 o={model:this,type:"delete",data:i};n.emit(C,o),n.emit(f,o)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(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(V,r),n.emit(f,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(f,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(f,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(f,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(k,t):n.emit(L,t)}}const y="EVENT_HISTORY_CHANGE",x="EVENT_HISTORY_LOAD";class M{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(y,{model:this,type:"delete",data:r.map(o=>o.id)})}this.index=-1,t||n.emit(y,{model:this,type:"create",data:s})}remove(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>-1?(this.items.splice(i,1),i===this.index?this.index=-1:this.index>=this.items.length&&(this.index=this.items.length-1)):console.warn(`not found HistoryItem for id: ${e} `),t||n.emit(y,{model:this,type:"delete",data:[e]})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&n.emit(x,{model:this,type:"load",data:s})}backward(e=!1){const{index:t,items:i}=this;if(t>=i.length-1)return;t<0&&(this.index=0),++this.index;const s=i[this.index];s&&!e&&n.emit(x,{model:this,type:"load",data:s})}load(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>=0&&(this.index=i,t||n.emit(x,{model:this,type:"load",data:this.items[i]}))}clear(e=!1){this.index=-1;const t=this.items.map(i=>i.id);this.items=[],e||n.emit(y,{model:this,type:"clear",data:t})}}const n=h.mitt();function K(d){return d instanceof u}function Y(d){return d instanceof p}function $(d){return!!d.__VTJ_BLOCK__}function B(d){return delete d.id,Array.isArray(d.children)&&(d.children=d.children.map(e=>B(e))),d}function W(d){const e=d.fromType||"Schema";return e==="Schema"?{type:"Schema",id:d.id}:e==="UrlSchema"?{type:"UrlSchema",url:(d.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(d.urls||"").split(","),library:d.library}:""}exports.BUILT_IN_COMPONENTS=G;exports.BUILT_IN_LIBRARAY_MAP=U;exports.BUILT_IN_MATERIALS=J;exports.BUILT_IN_NAME=b;exports.BUILT_IN_TAGS=w;exports.BUILT_IN_VUE=S;exports.BUILT_IN_VUE_ROUTER=R;exports.Base=j;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=a;exports.EVENT_HISTORY_CHANGE=y;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=C;exports.EVENT_PROJECT_CHANGE=f;exports.EVENT_PROJECT_DEPS_CHANGE=g;exports.EVENT_PROJECT_FILE_PUBLISH=k;exports.EVENT_PROJECT_PAGES_CHANGE=A;exports.EVENT_PROJECT_PUBLISH=L;exports.EventModel=v;exports.HistoryModel=M;exports.NodeModel=p;exports.ProjectModel=I;exports.PropModel=T;exports.Service=F;exports.VTJ_CORE_VERSION=H;exports.cloneDsl=B;exports.createNodeFrom=W;exports.emitter=n;exports.isBlock=K;exports.isBlockSchema=$;exports.isNode=Y;
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { uid as m, timestamp as S, upperFirstCamelCase as I, merge as H, cloneDeep as w, mitt as L } from "@vtj/base";
1
+ import { uid as m, timestamp as R, upperFirstCamelCase as I, merge as H, cloneDeep as w, mitt as L } 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.34
6
+ * @version 0.8.0
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const j = "0.7.34", U = "BuiltIn", k = "VueMaterial", D = "VueRouterMaterial", K = [k, D], $ = {
9
+ const U = "0.8.0", j = "BuiltIn", k = "VueMaterial", D = "VueRouterMaterial", K = [k, D], $ = {
10
10
  vue: "Vue",
11
11
  "vue-router": "VueRouter"
12
12
  }, Y = {
@@ -135,19 +135,19 @@ class v {
135
135
  }
136
136
  static toDsl(e = []) {
137
137
  return e.map((t) => {
138
- const { name: i, arg: s, modifiers: r, value: a, iterator: l, id: c } = t;
138
+ const { name: i, arg: s, modifiers: r, value: a, iterator: h, id: c } = t;
139
139
  return {
140
140
  id: c,
141
141
  name: i,
142
142
  arg: s,
143
143
  modifiers: r,
144
144
  value: a,
145
- iterator: l
145
+ iterator: h
146
146
  };
147
147
  });
148
148
  }
149
149
  }
150
- const d = "EVENT_NODE_CHANGE";
150
+ const l = "EVENT_NODE_CHANGE";
151
151
  class p {
152
152
  constructor(e, t = null) {
153
153
  this.parent = t;
@@ -217,11 +217,11 @@ class p {
217
217
  locked: s = !1,
218
218
  children: r = [],
219
219
  slot: a,
220
- props: l = {},
220
+ props: h = {},
221
221
  events: c = {},
222
222
  directives: E = []
223
223
  } = e;
224
- 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 = v.parse(E), t || n.emit(d, this);
224
+ 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 = v.parse(E), t || n.emit(l, 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(d, this);
232
+ Array.isArray(e) ? this.children = e.map((i) => new p(i, this)) : this.children = e, t || n.emit(l, 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(d, this);
240
+ this.slot = typeof e == "string" ? { name: e, params: [] } : e, t || n.emit(l, 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(d, this);
251
+ r ? r.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(l, 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(d, this);
259
+ delete this.props[e], t || n.emit(l, 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(d, this);
278
+ i ? i.update(e) : this.events[e.name] = new y(e), t || n.emit(l, 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(d, this);
286
+ delete this.events[e], t || n.emit(l, 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(d, this);
295
+ i >= 0 ? this.directives.splice(i, 1, new v(e)) : this.directives.push(new v(e)), t || n.emit(l, 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(d, this);
306
+ i >= 0 && this.directives.splice(i, 1), t || n.emit(l, this);
307
307
  }
308
308
  /**
309
309
  * 删除子节点
@@ -316,7 +316,7 @@ class p {
316
316
  if (s || !Array.isArray(i))
317
317
  return;
318
318
  const r = i.findIndex((a) => a === e);
319
- e.parent = null, i.splice(r, 1), t || n.emit(d, this);
319
+ e.parent = null, i.splice(r, 1), t || n.emit(l, this);
320
320
  }
321
321
  /**
322
322
  * 追加子节点
@@ -326,7 +326,7 @@ class p {
326
326
  */
327
327
  appendChild(e, t = !1) {
328
328
  const { children: i, disposed: s } = this;
329
- s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(d, this));
329
+ s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(l, this));
330
330
  }
331
331
  /**
332
332
  * 在当前节点的后面插入节点
@@ -341,7 +341,7 @@ class p {
341
341
  if (Array.isArray(i)) {
342
342
  e.parent = this.parent;
343
343
  const s = i.indexOf(this);
344
- i.splice(s + 1, 0, e), t || n.emit(d, this.parent);
344
+ i.splice(s + 1, 0, e), t || n.emit(l, this.parent);
345
345
  }
346
346
  }
347
347
  /**
@@ -357,7 +357,7 @@ class p {
357
357
  if (Array.isArray(i)) {
358
358
  e.parent = this.parent;
359
359
  const s = i.indexOf(this);
360
- i.splice(s, 0, e), t || n.emit(d, this.parent);
360
+ i.splice(s, 0, e), t || n.emit(l, this.parent);
361
361
  }
362
362
  }
363
363
  movePrev(e = !1) {
@@ -367,7 +367,7 @@ class p {
367
367
  const i = t.children;
368
368
  if (Array.isArray(i)) {
369
369
  const s = i.indexOf(this);
370
- s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(d, t));
370
+ s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(l, t));
371
371
  }
372
372
  }
373
373
  moveNext(e = !1) {
@@ -377,7 +377,7 @@ class p {
377
377
  const i = t.children;
378
378
  if (Array.isArray(i)) {
379
379
  const s = i.indexOf(this);
380
- s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(d, t));
380
+ s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(l, t));
381
381
  }
382
382
  }
383
383
  /**
@@ -392,11 +392,11 @@ class p {
392
392
  invisible: s,
393
393
  locked: r,
394
394
  slot: a,
395
- children: l,
395
+ children: h,
396
396
  props: c,
397
397
  directives: E,
398
398
  events: T
399
- } = this, _ = Array.isArray(l) ? l.map((b) => b.toDsl()) : l;
399
+ } = this, _ = Array.isArray(h) ? h.map((B) => B.toDsl()) : h;
400
400
  return {
401
401
  id: e,
402
402
  name: t,
@@ -417,25 +417,25 @@ class p {
417
417
  */
418
418
  dispose(e = !1) {
419
419
  const { children: t, disposed: i } = this;
420
- 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]);
420
+ 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]);
421
421
  }
422
422
  lock(e = !1) {
423
423
  if (this.locked = !0, Array.isArray(this.children))
424
424
  for (const t of this.children)
425
425
  t.lock(!0);
426
- e || n.emit(d, this);
426
+ e || n.emit(l, this);
427
427
  }
428
428
  unlock(e = !1) {
429
429
  if (this.locked = !1, Array.isArray(this.children))
430
430
  for (const t of this.children)
431
431
  t.unlock(!0);
432
- e || n.emit(d, this);
432
+ e || n.emit(l, this);
433
433
  }
434
434
  setVisible(e, t = !1) {
435
435
  if (this.invisible = !e, Array.isArray(this.children))
436
436
  for (const i of this.children)
437
437
  i.setVisible(e, !0);
438
- t || n.emit(d, this);
438
+ t || n.emit(l, this);
439
439
  }
440
440
  isChild(e) {
441
441
  let t = !1;
@@ -504,11 +504,11 @@ class u {
504
504
  const { __VTJ_BLOCK__: t, id: i, nodes: s } = this;
505
505
  return {
506
506
  ...u.normalAttrs.reduce(
507
- (a, l) => (a[l] = this[l], a),
507
+ (a, h) => (a[h] = this[h], a),
508
508
  {}
509
509
  ),
510
510
  __VTJ_BLOCK__: t,
511
- __VERSION__: e || S().toString(),
511
+ __VERSION__: e || R().toString(),
512
512
  id: i,
513
513
  nodes: s.map((a) => a.toDsl())
514
514
  };
@@ -756,7 +756,7 @@ class u {
756
756
  * @returns
757
757
  */
758
758
  cloneNode(e, t = !1) {
759
- const i = B(e.toDsl()), s = new p(i);
759
+ const i = b(e.toDsl()), s = new p(i);
760
760
  return this.addNode(s, e, "bottom", t), s;
761
761
  }
762
762
  lock(e = !1) {
@@ -782,7 +782,7 @@ class u {
782
782
  return t;
783
783
  }
784
784
  }
785
- const f = "EVENT_PROJECT_CHANGE", P = "EVENT_PROJECT_ACTIVED", V = "EVENT_PROJECT_DEPS_CHANGE", A = "EVENT_PROJECT_PAGES_CHANGE", g = "EVENT_PROJECT_BLOCKS_CHANGE", R = "EVENT_PROJECT_APIS_CHANGE", J = "EVENT_PROJECT_PUBLISH", G = "EVENT_PROJECT_FILE_PUBLISH";
785
+ const f = "EVENT_PROJECT_CHANGE", P = "EVENT_PROJECT_ACTIVED", V = "EVENT_PROJECT_DEPS_CHANGE", A = "EVENT_PROJECT_PAGES_CHANGE", g = "EVENT_PROJECT_BLOCKS_CHANGE", S = "EVENT_PROJECT_APIS_CHANGE", J = "EVENT_PROJECT_PUBLISH", F = "EVENT_PROJECT_FILE_PUBLISH";
786
786
  class O {
787
787
  id = "";
788
788
  name = "";
@@ -829,7 +829,7 @@ class O {
829
829
  );
830
830
  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))), {
831
831
  __VTJ_PROJECT__: !0,
832
- __VERSION__: e || S().toString(),
832
+ __VERSION__: e || R().toString(),
833
833
  id: t,
834
834
  ...i
835
835
  };
@@ -972,10 +972,10 @@ class O {
972
972
  * @param silent
973
973
  */
974
974
  clonePage(e, t, i = !1) {
975
- const s = m(), r = `${e.name}Copy`, a = `${e.title}_副本`, l = new u({
975
+ const s = m(), r = `${e.name}Copy`, a = `${e.title}_副本`, h = new u({
976
976
  id: s,
977
977
  name: r
978
- }).toDsl(), c = H({}, e, { id: s, name: r, title: a, dsl: l }), E = t ? this.getPage(t)?.children || [] : this.pages, T = E.findIndex((_) => _.id === e.id);
978
+ }).toDsl(), c = H({}, e, { id: s, name: r, title: a, dsl: h }), E = t ? this.getPage(t)?.children || [] : this.pages, T = E.findIndex((_) => _.id === e.id);
979
979
  if (E.splice(T + 1, 0, c), !i) {
980
980
  const _ = {
981
981
  model: this,
@@ -995,9 +995,9 @@ class O {
995
995
  */
996
996
  removePage(e, t = !1) {
997
997
  const i = this.getPage(e), s = (r, a) => {
998
- const l = a.findIndex((c) => c.id === r);
999
- if (l >= 0) {
1000
- a.splice(l, 1);
998
+ const h = a.findIndex((c) => c.id === r);
999
+ if (h >= 0) {
1000
+ a.splice(h, 1);
1001
1001
  return;
1002
1002
  }
1003
1003
  for (const c of a)
@@ -1028,13 +1028,15 @@ class O {
1028
1028
  */
1029
1029
  createBlock(e, t = !1) {
1030
1030
  const i = e.id || m(), s = I(e.name);
1031
- 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) {
1032
- const r = {
1031
+ e.id = i, e.type = "block", e.dsl = new u({ id: i, name: s }).toDsl(), this.blocks.push(e);
1032
+ const r = e.fromType || "Schema";
1033
+ if (!this.currentFile && r === "Schema" && this.active(e, t), !t) {
1034
+ const a = {
1033
1035
  model: this,
1034
1036
  type: "create",
1035
1037
  data: e
1036
1038
  };
1037
- n.emit(g, r), n.emit(f, r);
1039
+ n.emit(g, a), n.emit(f, a);
1038
1040
  }
1039
1041
  }
1040
1042
  /**
@@ -1103,7 +1105,7 @@ class O {
1103
1105
  type: s,
1104
1106
  data: e
1105
1107
  };
1106
- n.emit(R, r), n.emit(f, r);
1108
+ n.emit(S, r), n.emit(f, r);
1107
1109
  }
1108
1110
  }
1109
1111
  /**
@@ -1119,7 +1121,7 @@ class O {
1119
1121
  type: "delete",
1120
1122
  data: e
1121
1123
  };
1122
- n.emit(R, s), n.emit(f, s);
1124
+ n.emit(S, s), n.emit(f, s);
1123
1125
  }
1124
1126
  }
1125
1127
  existApiName(e, t = []) {
@@ -1151,7 +1153,7 @@ class O {
1151
1153
  type: "publish",
1152
1154
  data: e || this
1153
1155
  };
1154
- e ? n.emit(G, t) : n.emit(J, t);
1156
+ e ? n.emit(F, t) : n.emit(J, t);
1155
1157
  }
1156
1158
  }
1157
1159
  const N = "EVENT_HISTORY_CHANGE", C = "EVENT_HISTORY_LOAD";
@@ -1261,23 +1263,37 @@ class z {
1261
1263
  }
1262
1264
  }
1263
1265
  const n = L();
1264
- function Q(h) {
1265
- return h instanceof u;
1266
+ function Q(d) {
1267
+ return d instanceof u;
1268
+ }
1269
+ function X(d) {
1270
+ return d instanceof p;
1266
1271
  }
1267
- function X(h) {
1268
- return h instanceof p;
1272
+ function Z(d) {
1273
+ return !!d.__VTJ_BLOCK__;
1269
1274
  }
1270
- function Z(h) {
1271
- return !!h.__VTJ_BLOCK__;
1275
+ function b(d) {
1276
+ return delete d.id, Array.isArray(d.children) && (d.children = d.children.map((e) => b(e))), d;
1272
1277
  }
1273
- function B(h) {
1274
- return delete h.id, Array.isArray(h.children) && (h.children = h.children.map((e) => B(e))), h;
1278
+ function ee(d) {
1279
+ const e = d.fromType || "Schema";
1280
+ return e === "Schema" ? {
1281
+ type: "Schema",
1282
+ id: d.id
1283
+ } : e === "UrlSchema" ? {
1284
+ type: "UrlSchema",
1285
+ url: (d.urls || "").split(",")[0] || ""
1286
+ } : e === "Plugin" ? {
1287
+ type: "Plugin",
1288
+ urls: (d.urls || "").split(","),
1289
+ library: d.library
1290
+ } : "";
1275
1291
  }
1276
1292
  export {
1277
1293
  Y as BUILT_IN_COMPONENTS,
1278
1294
  $ as BUILT_IN_LIBRARAY_MAP,
1279
1295
  K as BUILT_IN_MATERIALS,
1280
- U as BUILT_IN_NAME,
1296
+ j as BUILT_IN_NAME,
1281
1297
  M as BUILT_IN_TAGS,
1282
1298
  k as BUILT_IN_VUE,
1283
1299
  D as BUILT_IN_VUE_ROUTER,
@@ -1287,13 +1303,13 @@ export {
1287
1303
  o as EVENT_BLOCK_CHANGE,
1288
1304
  N as EVENT_HISTORY_CHANGE,
1289
1305
  C as EVENT_HISTORY_LOAD,
1290
- d as EVENT_NODE_CHANGE,
1306
+ l as EVENT_NODE_CHANGE,
1291
1307
  P as EVENT_PROJECT_ACTIVED,
1292
- R as EVENT_PROJECT_APIS_CHANGE,
1308
+ S as EVENT_PROJECT_APIS_CHANGE,
1293
1309
  g as EVENT_PROJECT_BLOCKS_CHANGE,
1294
1310
  f as EVENT_PROJECT_CHANGE,
1295
1311
  V as EVENT_PROJECT_DEPS_CHANGE,
1296
- G as EVENT_PROJECT_FILE_PUBLISH,
1312
+ F as EVENT_PROJECT_FILE_PUBLISH,
1297
1313
  A as EVENT_PROJECT_PAGES_CHANGE,
1298
1314
  J as EVENT_PROJECT_PUBLISH,
1299
1315
  y as EventModel,
@@ -1302,8 +1318,9 @@ export {
1302
1318
  O as ProjectModel,
1303
1319
  x as PropModel,
1304
1320
  W as Service,
1305
- j as VTJ_CORE_VERSION,
1306
- B as cloneDsl,
1321
+ U as VTJ_CORE_VERSION,
1322
+ b as cloneDsl,
1323
+ ee as createNodeFrom,
1307
1324
  n as emitter,
1308
1325
  Q as isBlock,
1309
1326
  Z as isBlockSchema,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/core",
3
3
  "private": false,
4
- "version": "0.7.34",
4
+ "version": "0.8.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "vue-tsc && vite build",
@@ -10,10 +10,10 @@
10
10
  "coverage": "vitest run --coverage"
11
11
  },
12
12
  "dependencies": {
13
- "@vtj/base": "^0.7.8"
13
+ "@vtj/base": "^0.8.0"
14
14
  },
15
15
  "devDependencies": {
16
- "@vtj/cli": "^0.7.21"
16
+ "@vtj/cli": "^0.8.0"
17
17
  },
18
18
  "exports": {
19
19
  ".": {
@@ -29,7 +29,7 @@
29
29
  "dist",
30
30
  "types"
31
31
  ],
32
- "gitHead": "307cf220b3b712bdc2264e44ae800f95017e0f0a",
32
+ "gitHead": "911c3a0e2bb60548affe5dcf5a496577809d63b8",
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  }
@@ -26,6 +26,10 @@ export interface Dependencie {
26
26
  * 库导出名称
27
27
  */
28
28
  library: string;
29
+ /**
30
+ * 语言包库导出名称
31
+ */
32
+ localeLibrary?: string;
29
33
  /**
30
34
  * 加载资源url
31
35
  */
@@ -2,3 +2,4 @@ export * from './shared';
2
2
  export * from './assets';
3
3
  export * from './schemas';
4
4
  export * from './service';
5
+ export * from './plugins';
@@ -0,0 +1,10 @@
1
+ import { DefineComponent } from 'vue';
2
+
3
+ export interface BlockPluginExports {
4
+ plugin: DefineComponent<any, any, any, any> | Record<string, any>;
5
+ [index: string]: any;
6
+ }
7
+ export interface BlockPlugin {
8
+ component: DefineComponent<any, any, any, any> | Record<string, any>;
9
+ css: string[];
10
+ }
@@ -4,6 +4,20 @@ import { BlockSchema } from './block';
4
4
  * 文件类型
5
5
  */
6
6
  export type FileType = 'block' | 'page';
7
+ export interface MarketInstallInfo {
8
+ /**
9
+ * 物料标识
10
+ */
11
+ id: string;
12
+ /**
13
+ * 安装版本号
14
+ */
15
+ version: string;
16
+ /**
17
+ * 物料主页 url
18
+ */
19
+ url: string;
20
+ }
7
21
  export interface BlockFile {
8
22
  /**
9
23
  * 文件类型
@@ -21,6 +35,25 @@ export interface BlockFile {
21
35
  * 页面标题
22
36
  */
23
37
  title: string;
38
+ /**
39
+ * 从物料市场安装
40
+ */
41
+ market?: MarketInstallInfo;
42
+ /**
43
+ * 区块来源,默认为Schema,一旦确定,不允许更改
44
+ */
45
+ fromType?: 'Schema' | 'UrlSchema' | 'Plugin';
46
+ /**
47
+ * 资源url,
48
+ * Schema: 无url
49
+ * UrlSchema: 只允许一个json文件
50
+ * Plugin:支持多个文件(.css或.js),多个文件用逗号分隔
51
+ */
52
+ urls?: string;
53
+ /**
54
+ * Plugin 时的插件名称
55
+ */
56
+ library?: string;
24
57
  /**
25
58
  * 文件内容
26
59
  */
@@ -48,7 +48,7 @@ export interface NodeSchema {
48
48
  /**
49
49
  * 组件来源, 字符串是依赖包名
50
50
  */
51
- export type NodeFrom = string | NodeFromSchema | NodeFromUrlSchema | NodeFromRemote;
51
+ export type NodeFrom = string | NodeFromSchema | NodeFromUrlSchema | NodeFromPlugin;
52
52
  /**
53
53
  * 来源于其他Schema对象
54
54
  */
@@ -69,9 +69,9 @@ export interface NodeFromUrlSchema {
69
69
  /**
70
70
  * 来源远程组件
71
71
  */
72
- export interface NodeFromRemote {
73
- type: 'Remote';
74
- urls: string;
72
+ export interface NodeFromPlugin {
73
+ type: 'Plugin';
74
+ urls: string[];
75
75
  library?: string;
76
76
  }
77
77
  /**
@@ -1,5 +1,6 @@
1
+ import { StaticFileInfo } from './shared';
1
2
  import { MaterialDescription } from './assets';
2
- import { ProjectSchema, BlockSchema, HistorySchema, HistoryItem, PageFile, BlockFile } from './schemas';
3
+ import { ProjectSchema, BlockSchema, HistorySchema, HistoryItem, PageFile, BlockFile, NodeFromPlugin } from './schemas';
3
4
 
4
5
  export declare abstract class Service {
5
6
  abstract init(project: ProjectSchema): Promise<ProjectSchema>;
@@ -19,4 +20,9 @@ export declare abstract class Service {
19
20
  abstract genVueContent(project: ProjectSchema, dsl: BlockSchema): Promise<string>;
20
21
  abstract createRawPage(file: PageFile): Promise<boolean>;
21
22
  abstract removeRawPage(id: string): Promise<boolean>;
23
+ abstract uploadStaticFile(file: File, projectId: string): Promise<StaticFileInfo | null>;
24
+ abstract getStaticFiles(projectId: string): Promise<StaticFileInfo[]>;
25
+ abstract removeStaticFile(name: string, projectId: string): Promise<boolean>;
26
+ abstract clearStaticFiles(projectId: string): Promise<boolean>;
27
+ abstract getPluginMaterial(from: NodeFromPlugin): Promise<MaterialDescription | null>;
22
28
  }
@@ -32,3 +32,10 @@ export interface JSFunction {
32
32
  * 数据类型
33
33
  */
34
34
  export type DataType = 'String' | 'Boolean' | 'Number' | 'Date' | 'Object' | 'Array' | 'Function';
35
+ /**
36
+ * 静态文件
37
+ */
38
+ export interface StaticFileInfo {
39
+ filename?: string;
40
+ filepath: string;
41
+ }
@@ -1,7 +1,8 @@
1
- import { BlockSchema, NodeSchema } from '../protocols';
1
+ import { BlockSchema, NodeSchema, BlockFile, NodeFrom } from '../protocols';
2
2
  import { BlockModel } from '../models';
3
3
 
4
4
  export declare function isBlock(value: unknown): value is BlockModel;
5
5
  export declare function isNode(value: unknown): value is BlockModel;
6
6
  export declare function isBlockSchema(value: unknown): value is BlockSchema;
7
7
  export declare function cloneDsl(dsl: NodeSchema): NodeSchema;
8
+ 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.7.33
5
+ * @version 0.7.34
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.7.33";
8
+ export declare const version = "0.7.34";