@vtj/core 0.8.12 → 0.8.13
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 +2 -2
- package/dist/index.mjs +57 -55
- package/package.json +1 -1
- package/types/models/project.d.ts +2 -2
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.8.
|
|
5
|
+
* @version 0.8.13
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const H="0.8.12",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;
|
|
7
|
+
*/const H="0.8.13",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:a}=s;return t[i]={name:i,handler:r,modifiers:a},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new v(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||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:a}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=r,this.iterator=a}static parse(e=[]){return e.map(t=>new E(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:r,value:a,iterator:c,id:m}=t;return{id:m,name:i,arg:s,modifiers:r,value:a,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:a,props:c={},events:m={},directives:_=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(a,!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(a=>a===e);e.parent=null,i.splice(r,1),t||n.emit(l,this)}appendChild(e,t=!1){const{children:i,disposed:s}=this;s||(e.parent=this,Array.isArray(i)?i.push(e):this.children=[e],t||n.emit(l,this))}insertAfter(e,t=!1){if(!this.parent)return;const i=this.parent.children;if(Array.isArray(i)){e.parent=this.parent;const s=i.indexOf(this);i.splice(s+1,0,e),t||n.emit(l,this.parent)}}insertBefore(e,t=!1){if(!this.parent)return;const i=this.parent.children;if(Array.isArray(i)){e.parent=this.parent;const s=i.indexOf(this);i.splice(s,0,e),t||n.emit(l,this.parent)}}movePrev(e=!1){const t=this.parent;if(!t)return;const i=t.children;if(Array.isArray(i)){const s=i.indexOf(this);s>0&&(i.splice(s,1),i.splice(s-1,0,this),e||n.emit(l,t))}}moveNext(e=!1){const t=this.parent;if(!t)return;const i=t.children;if(Array.isArray(i)){const s=i.indexOf(this);s>-1&&s<i.length-1&&(i.splice(s,1),i.splice(s+1,0,this),e||n.emit(l,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children: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:a,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 o="EVENT_BLOCK_CHANGE";class u{__VTJ_BLOCK__=!0;id;name="";inject=[];state={};lifeCycles={};methods={};computed={};watch=[];css="";props=[];emits=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","inject","state","lifeCycles","methods","computed","watch","css","props","emits","slots","dataSources"];constructor(e){const{id:t}=e;this.id=t||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(o,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((a,c)=>(a[c]=this[c],a),{}),__VTJ_BLOCK__:t,__VERSION__:e||h.timestamp().toString(),id:i,nodes:s.map(a=>a.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}setFunction(e,t,i,s=!1){this[e][t]=i,s||n.emit(o,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(o,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(o,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(o,this)}setCss(e,t=!1){this.css=e,t||n.emit(o,this)}setWatch(e,t=!1){e.id=e.id||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(o,this)}removeWatch(e,t=!1){const i=this.watch.findIndex(s=>s.id&&s.id===e.id||s===e);i>-1&&(this.watch.splice(i,1),t||n.emit(o,this))}setProp(e,t=!1){const i=this.props.findIndex(s=>typeof s=="string"?s===e.name:s.name===e.name);i>-1?this.props.splice(i,1,e):this.props.push(e),t||n.emit(o,this)}removeProp(e,t=!1){const i=this.props.findIndex(s=>typeof s=="string"?s===e.name:s.name===e.name);i>-1&&(this.props.splice(i,1),t||n.emit(o,this))}setEmit(e,t=!1){const i=this.emits.findIndex(s=>s===e);i>-1?this.emits.splice(i,1,e):this.emits.push(e),t||n.emit(o,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>s===e);i>-1&&(this.emits.splice(i,1),t||n.emit(o,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(o,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>s===e);i>-1&&(this.slots.splice(i,1),t||n.emit(o,this))}setInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1?this.inject.splice(i,1,e):this.inject.push(e),t||n.emit(o,this)}removeInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1&&(this.inject.splice(i,1),t||n.emit(o,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(o,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(o,this)}insertAfter(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s+1,0,e),i||n.emit(o,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(o,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(o,this)}addNode(e,t,i="inner",s=!1){t?["left","top"].includes(i)?t.parent?t.insertAfter(e,s):this.insertBefore(e,t,s):["right","bottom"].includes(i)?t.parent?t.insertAfter(e,s):this.insertAfter(e,t,s):t.appendChild(e,s):this.appendNode(e,s)}__removeNode(e,t=!1){const i=this.nodes.findIndex(s=>s.id===e.id);i>-1&&(this.nodes.splice(i,1),t||n.emit(o,this))}removeNode(e,t=!1){e.parent?e.dispose(t):(e.dispose(!0),this.__removeNode(e,t))}move(e,t,i="inner",s=!1){e.parent?e.parent.removeChild(e,!0):this.__removeNode(e,!0),this.addNode(e,t,i,s)}movePrev(e,t=!1){if(e.parent)e.movePrev(t);else{const i=this.nodes,s=i.indexOf(e);s>0&&(i.splice(s,1),i.splice(s-1,0,e),t||n.emit(o,this))}}moveNext(e,t=!1){if(e.parent)e.moveNext(t);else{const i=this.nodes,s=i.indexOf(e);s>-1&&s<i.length-1&&(i.splice(s,1),i.splice(s+1,0,e),t||n.emit(o,this))}}cloneNode(e,t=!1){const i=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(o,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(o,this)}isChild(e){let t=!1;for(const i of this.nodes)if(e===i||e.id===i.id){t=!0;break}else if(t=i.isChild(e),t)break;return t}}const 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(a=>a.package===e.package);let r;if(s>-1?(r="update",i.splice(s,1,{...i[s],...e})):(r="create",i.push(e)),!t){const a={model:this,type:r,data:e};n.emit(g,a),n.emit(f,a)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(r=>r.package===e.package);if(s>-1&&i.splice(s,1),!t){const r={model:this,type:"delete",data:e};n.emit(g,r),n.emit(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 a=t(i,r.children);if(a)return a}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir?s.children&&s.children.length&&(i=i.concat(e(s.children))):i.push(s);return i};return e(this.pages)}async createPage(e,t,i=!1){if(e.id=e.raw?e.name:e.id||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(!i){const s={model:this,type:"create",data:e};n.emit(A,s),n.emit(f,s)}!this.currentFile&&!e.dir&&(await h.delay(500),this.active(e,i))}updatePage(e,t=!1){const i=this.getPage(e.id);if(i?Object.assign(i,e):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(A,s),n.emit(f,s)}}clonePage(e,t,i=!1){const s=h.uid(),r=`${e.name}Copy`,a=`${e.title}_副本`,c=new u({id:s,name:r}).toDsl(),m=h.merge({},e,{id:s,name:r,title:a,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,a)=>{const c=a.findIndex(m=>m.id===r);if(c>=0){a.splice(c,1);return}for(const m of a)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)}async 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(!t){const a={model:this,type:"create",data:e};n.emit(C,a),n.emit(f,a)}!this.currentFile&&r==="Schema"&&(await h.delay(500),this.active(e,t))}updateBlock(e,t=!1){const i=this.getBlock(e.id);if(i?(Object.assign(i,e),i.dsl&&(i.dsl.name=e.name)):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(C,s),n.emit(f,s)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,r=s.findIndex(a=>a.id===e);if(r>-1?(s.splice(r,1),this.currentFile?.id===e&&this.deactivate(t)):console.warn(`not found PageFile for id: ${e} `),!t){const a={model:this,type:"delete",data:i};n.emit(C,a),n.emit(f,a)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(r=>r.name===e.name||r.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=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(a=>a.id)})}this.index=-1,t||n.emit(y,{model:this,type:"create",data:s})}remove(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>-1?(this.items.splice(i,1),i===this.index?this.index=-1:this.index>=this.items.length&&(this.index=this.items.length-1)):console.warn(`not found HistoryItem for id: ${e} `),t||n.emit(y,{model:this,type:"delete",data:[e]})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&n.emit(x,{model:this,type:"load",data:s})}backward(e=!1){const{index:t,items:i}=this;if(t>=i.length-1)return;t<0&&(this.index=0),++this.index;const s=i[this.index];s&&!e&&n.emit(x,{model:this,type:"load",data:s})}load(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>=0&&(this.index=i,t||n.emit(x,{model:this,type:"load",data:this.items[i]}))}clear(e=!1){this.index=-1;const t=this.items.map(i=>i.id);this.items=[],e||n.emit(y,{model:this,type:"clear",data:t})}}const n=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=o;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,24 +1,24 @@
|
|
|
1
|
-
import { uid as m, timestamp as
|
|
1
|
+
import { uid as m, timestamp as k, upperFirstCamelCase as I, delay as P, merge as H, cloneDeep as L, mitt as J } from "@vtj/base";
|
|
2
2
|
/**!
|
|
3
3
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
4
4
|
* @name @vtj/core
|
|
5
5
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
6
|
-
* @version 0.8.
|
|
6
|
+
* @version 0.8.13
|
|
7
7
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
9
|
+
const j = "0.8.13", K = "BuiltIn", D = "VueMaterial", b = "VueRouterMaterial", $ = [D, b], Y = {
|
|
10
10
|
vue: "Vue",
|
|
11
11
|
"vue-router": "VueRouter"
|
|
12
|
-
},
|
|
13
|
-
[
|
|
12
|
+
}, M = {
|
|
13
|
+
[D]: [
|
|
14
14
|
"Transition",
|
|
15
15
|
"TransitionGroup",
|
|
16
16
|
"KeepAlive",
|
|
17
17
|
"Teleport",
|
|
18
18
|
"Suspense"
|
|
19
19
|
],
|
|
20
|
-
[
|
|
21
|
-
},
|
|
20
|
+
[b]: ["RouterView", "RouterLink"]
|
|
21
|
+
}, W = [
|
|
22
22
|
"slot",
|
|
23
23
|
"template",
|
|
24
24
|
"component",
|
|
@@ -31,9 +31,9 @@ const U = "0.8.12", j = "BuiltIn", k = "VueMaterial", D = "VueRouterMaterial", K
|
|
|
31
31
|
"span",
|
|
32
32
|
"a"
|
|
33
33
|
];
|
|
34
|
-
class W {
|
|
35
|
-
}
|
|
36
34
|
class q {
|
|
35
|
+
}
|
|
36
|
+
class z {
|
|
37
37
|
listeners = [];
|
|
38
38
|
isReady = !1;
|
|
39
39
|
triggerReady() {
|
|
@@ -396,7 +396,7 @@ class p {
|
|
|
396
396
|
props: c,
|
|
397
397
|
directives: E,
|
|
398
398
|
events: T
|
|
399
|
-
} = this, _ = Array.isArray(h) ? h.map((
|
|
399
|
+
} = this, _ = Array.isArray(h) ? h.map((w) => w.toDsl()) : h;
|
|
400
400
|
return {
|
|
401
401
|
id: e,
|
|
402
402
|
name: t,
|
|
@@ -508,7 +508,7 @@ class u {
|
|
|
508
508
|
{}
|
|
509
509
|
),
|
|
510
510
|
__VTJ_BLOCK__: t,
|
|
511
|
-
__VERSION__: e ||
|
|
511
|
+
__VERSION__: e || k().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 =
|
|
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",
|
|
785
|
+
const f = "EVENT_PROJECT_CHANGE", V = "EVENT_PROJECT_ACTIVED", S = "EVENT_PROJECT_DEPS_CHANGE", A = "EVENT_PROJECT_PAGES_CHANGE", g = "EVENT_PROJECT_BLOCKS_CHANGE", R = "EVENT_PROJECT_APIS_CHANGE", F = "EVENT_PROJECT_PUBLISH", G = "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 ||
|
|
832
|
+
__VERSION__: e || k().toString(),
|
|
833
833
|
id: t,
|
|
834
834
|
...i
|
|
835
835
|
};
|
|
@@ -840,7 +840,7 @@ class O {
|
|
|
840
840
|
* @param silent
|
|
841
841
|
*/
|
|
842
842
|
active(e, t = !1) {
|
|
843
|
-
this.currentFile = e, t || n.emit(
|
|
843
|
+
this.currentFile = e, t || n.emit(V, {
|
|
844
844
|
model: this,
|
|
845
845
|
type: "update",
|
|
846
846
|
data: e
|
|
@@ -851,7 +851,7 @@ class O {
|
|
|
851
851
|
* @param silent
|
|
852
852
|
*/
|
|
853
853
|
deactivate(e = !1) {
|
|
854
|
-
this.currentFile = null, e || n.emit(
|
|
854
|
+
this.currentFile = null, e || n.emit(V, {
|
|
855
855
|
model: this,
|
|
856
856
|
type: "update",
|
|
857
857
|
data: null
|
|
@@ -874,7 +874,7 @@ class O {
|
|
|
874
874
|
type: r,
|
|
875
875
|
data: e
|
|
876
876
|
};
|
|
877
|
-
n.emit(
|
|
877
|
+
n.emit(S, a), n.emit(f, a);
|
|
878
878
|
}
|
|
879
879
|
}
|
|
880
880
|
/**
|
|
@@ -890,7 +890,7 @@ class O {
|
|
|
890
890
|
type: "delete",
|
|
891
891
|
data: e
|
|
892
892
|
};
|
|
893
|
-
n.emit(
|
|
893
|
+
n.emit(S, r), n.emit(f, r);
|
|
894
894
|
}
|
|
895
895
|
}
|
|
896
896
|
/**
|
|
@@ -931,7 +931,7 @@ class O {
|
|
|
931
931
|
* @param parentId
|
|
932
932
|
* @param silent
|
|
933
933
|
*/
|
|
934
|
-
createPage(e, t, i = !1) {
|
|
934
|
+
async createPage(e, t, i = !1) {
|
|
935
935
|
if (e.id = e.raw ? e.name : e.id || m(), e.type = "page", e.dir ? e.children = [] : e.dsl = e.dsl || new u({
|
|
936
936
|
id: e.id,
|
|
937
937
|
name: I(e.name)
|
|
@@ -940,7 +940,7 @@ class O {
|
|
|
940
940
|
s ? s.children ? s.children.push(e) : s.children = [e] : console.warn(`not found PageFile for id: ${t} `);
|
|
941
941
|
} else
|
|
942
942
|
this.pages.push(e);
|
|
943
|
-
if (!
|
|
943
|
+
if (!i) {
|
|
944
944
|
const s = {
|
|
945
945
|
model: this,
|
|
946
946
|
type: "create",
|
|
@@ -948,6 +948,7 @@ class O {
|
|
|
948
948
|
};
|
|
949
949
|
n.emit(A, s), n.emit(f, s);
|
|
950
950
|
}
|
|
951
|
+
!this.currentFile && !e.dir && (await P(500), this.active(e, i));
|
|
951
952
|
}
|
|
952
953
|
/**
|
|
953
954
|
* 更新页面
|
|
@@ -1026,11 +1027,11 @@ class O {
|
|
|
1026
1027
|
* @param block
|
|
1027
1028
|
* @param silent
|
|
1028
1029
|
*/
|
|
1029
|
-
createBlock(e, t = !1) {
|
|
1030
|
+
async createBlock(e, t = !1) {
|
|
1030
1031
|
const i = e.id || m(), s = I(e.name);
|
|
1031
1032
|
e.id = i, e.type = "block", e.dsl = new u({ id: i, name: s }).toDsl(), this.blocks.push(e);
|
|
1032
1033
|
const r = e.fromType || "Schema";
|
|
1033
|
-
if (!
|
|
1034
|
+
if (!t) {
|
|
1034
1035
|
const a = {
|
|
1035
1036
|
model: this,
|
|
1036
1037
|
type: "create",
|
|
@@ -1038,6 +1039,7 @@ class O {
|
|
|
1038
1039
|
};
|
|
1039
1040
|
n.emit(g, a), n.emit(f, a);
|
|
1040
1041
|
}
|
|
1042
|
+
!this.currentFile && r === "Schema" && (await P(500), this.active(e, t));
|
|
1041
1043
|
}
|
|
1042
1044
|
/**
|
|
1043
1045
|
*
|
|
@@ -1105,7 +1107,7 @@ class O {
|
|
|
1105
1107
|
type: s,
|
|
1106
1108
|
data: e
|
|
1107
1109
|
};
|
|
1108
|
-
n.emit(
|
|
1110
|
+
n.emit(R, r), n.emit(f, r);
|
|
1109
1111
|
}
|
|
1110
1112
|
}
|
|
1111
1113
|
/**
|
|
@@ -1121,7 +1123,7 @@ class O {
|
|
|
1121
1123
|
type: "delete",
|
|
1122
1124
|
data: e
|
|
1123
1125
|
};
|
|
1124
|
-
n.emit(
|
|
1126
|
+
n.emit(R, s), n.emit(f, s);
|
|
1125
1127
|
}
|
|
1126
1128
|
}
|
|
1127
1129
|
existApiName(e, t = []) {
|
|
@@ -1153,11 +1155,11 @@ class O {
|
|
|
1153
1155
|
type: "publish",
|
|
1154
1156
|
data: e || this
|
|
1155
1157
|
};
|
|
1156
|
-
e ? n.emit(
|
|
1158
|
+
e ? n.emit(G, t) : n.emit(F, t);
|
|
1157
1159
|
}
|
|
1158
1160
|
}
|
|
1159
1161
|
const N = "EVENT_HISTORY_CHANGE", C = "EVENT_HISTORY_LOAD";
|
|
1160
|
-
class
|
|
1162
|
+
class Q {
|
|
1161
1163
|
options = { max: 50 };
|
|
1162
1164
|
index = -1;
|
|
1163
1165
|
id;
|
|
@@ -1191,7 +1193,7 @@ class z {
|
|
|
1191
1193
|
const { max: i } = this.options, s = {
|
|
1192
1194
|
id: m(),
|
|
1193
1195
|
label: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
1194
|
-
dsl:
|
|
1196
|
+
dsl: L(e)
|
|
1195
1197
|
};
|
|
1196
1198
|
if (this.items.unshift(s), this.items.length > i) {
|
|
1197
1199
|
const r = this.items.splice(i);
|
|
@@ -1262,20 +1264,20 @@ class z {
|
|
|
1262
1264
|
});
|
|
1263
1265
|
}
|
|
1264
1266
|
}
|
|
1265
|
-
const n =
|
|
1266
|
-
function
|
|
1267
|
+
const n = J();
|
|
1268
|
+
function X(d) {
|
|
1267
1269
|
return d instanceof u;
|
|
1268
1270
|
}
|
|
1269
|
-
function
|
|
1271
|
+
function Z(d) {
|
|
1270
1272
|
return d instanceof p;
|
|
1271
1273
|
}
|
|
1272
|
-
function
|
|
1274
|
+
function ee(d) {
|
|
1273
1275
|
return !!d.__VTJ_BLOCK__;
|
|
1274
1276
|
}
|
|
1275
|
-
function
|
|
1276
|
-
return delete d.id, Array.isArray(d.children) && (d.children = d.children.map((e) =>
|
|
1277
|
+
function B(d) {
|
|
1278
|
+
return delete d.id, Array.isArray(d.children) && (d.children = d.children.map((e) => B(e))), d;
|
|
1277
1279
|
}
|
|
1278
|
-
function
|
|
1280
|
+
function te(d) {
|
|
1279
1281
|
const e = d.fromType || "Schema";
|
|
1280
1282
|
return e === "Schema" ? {
|
|
1281
1283
|
type: "Schema",
|
|
@@ -1290,39 +1292,39 @@ function ee(d) {
|
|
|
1290
1292
|
} : "";
|
|
1291
1293
|
}
|
|
1292
1294
|
export {
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1295
|
+
M as BUILT_IN_COMPONENTS,
|
|
1296
|
+
Y as BUILT_IN_LIBRARAY_MAP,
|
|
1297
|
+
$ as BUILT_IN_MATERIALS,
|
|
1298
|
+
K as BUILT_IN_NAME,
|
|
1299
|
+
W as BUILT_IN_TAGS,
|
|
1300
|
+
D as BUILT_IN_VUE,
|
|
1301
|
+
b as BUILT_IN_VUE_ROUTER,
|
|
1302
|
+
z as Base,
|
|
1301
1303
|
u as BlockModel,
|
|
1302
1304
|
v as DirectiveModel,
|
|
1303
1305
|
o as EVENT_BLOCK_CHANGE,
|
|
1304
1306
|
N as EVENT_HISTORY_CHANGE,
|
|
1305
1307
|
C as EVENT_HISTORY_LOAD,
|
|
1306
1308
|
l as EVENT_NODE_CHANGE,
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
+
V as EVENT_PROJECT_ACTIVED,
|
|
1310
|
+
R as EVENT_PROJECT_APIS_CHANGE,
|
|
1309
1311
|
g as EVENT_PROJECT_BLOCKS_CHANGE,
|
|
1310
1312
|
f as EVENT_PROJECT_CHANGE,
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
+
S as EVENT_PROJECT_DEPS_CHANGE,
|
|
1314
|
+
G as EVENT_PROJECT_FILE_PUBLISH,
|
|
1313
1315
|
A as EVENT_PROJECT_PAGES_CHANGE,
|
|
1314
|
-
|
|
1316
|
+
F as EVENT_PROJECT_PUBLISH,
|
|
1315
1317
|
y as EventModel,
|
|
1316
|
-
|
|
1318
|
+
Q as HistoryModel,
|
|
1317
1319
|
p as NodeModel,
|
|
1318
1320
|
O as ProjectModel,
|
|
1319
1321
|
x as PropModel,
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1322
|
+
q as Service,
|
|
1323
|
+
j as VTJ_CORE_VERSION,
|
|
1324
|
+
B as cloneDsl,
|
|
1325
|
+
te as createNodeFrom,
|
|
1324
1326
|
n as emitter,
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1327
|
+
X as isBlock,
|
|
1328
|
+
ee as isBlockSchema,
|
|
1329
|
+
Z as isNode
|
|
1328
1330
|
};
|
package/package.json
CHANGED
|
@@ -94,7 +94,7 @@ export declare class ProjectModel {
|
|
|
94
94
|
* @param parentId
|
|
95
95
|
* @param silent
|
|
96
96
|
*/
|
|
97
|
-
createPage(page: PageFile, parentId?: string, silent?: boolean): void
|
|
97
|
+
createPage(page: PageFile, parentId?: string, silent?: boolean): Promise<void>;
|
|
98
98
|
/**
|
|
99
99
|
* 更新页面
|
|
100
100
|
* @param page
|
|
@@ -125,7 +125,7 @@ export declare class ProjectModel {
|
|
|
125
125
|
* @param block
|
|
126
126
|
* @param silent
|
|
127
127
|
*/
|
|
128
|
-
createBlock(block: BlockFile, silent?: boolean): void
|
|
128
|
+
createBlock(block: BlockFile, silent?: boolean): Promise<void>;
|
|
129
129
|
/**
|
|
130
130
|
*
|
|
131
131
|
* @param block 更新区块
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.8.
|
|
5
|
+
* @version 0.8.12
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.8.
|
|
8
|
+
export declare const version = "0.8.12";
|