@vtj/core 0.7.30 → 0.7.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.7.
|
|
5
|
+
* @version 0.7.32
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const H="0.7.30",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:f}=t;return{id:f,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:f={},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(f),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:f,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(f),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 m="EVENT_PROJECT_CHANGE",P="EVENT_PROJECT_ACTIVED",V="EVENT_PROJECT_DEPS_CHANGE",A="EVENT_PROJECT_PAGES_CHANGE",C="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;static attrs=["name","homepage","description","dependencies","pages","blocks","apis"];constructor(e){const{id:t}=e;this.id=t||l.uid(),this.update(e,!0)}update(e,t=!1){for(const i of O.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(m,{model:this,type:"update",data:e})}isPageFile(e){return e.type==="page"}toDsl(e){const{id:t}=this,i=O.attrs.reduce((s,r)=>(s[r]=this[r],s),{});return i.pages&&(i.pages=i.pages.map(s=>(delete s.dsl,s))),i.blocks&&(i.blocks=i.blocks.map(s=>(delete s.dsl,s))),{__VTJ_PROJECT__:!0,__VERSION__:e||l.timestamp().toString(),id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(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(m,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(m,r)}}getPage(e){const t=(i,s=[])=>{for(const r of s){if(r.id===i)return r;if(r.children&&r.children.length){const 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(m,s)}}updatePage(e,t=!1){const i=this.getPage(e.id);if(i?Object.assign(i,e):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(A,s),n.emit(m,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(),f=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,f),!i){const N={model:this,type:"clone",data:{page:e,newPage:f}};n.emit(A,N),n.emit(m,N)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,o)=>{const h=o.findIndex(f=>f.id===r);if(h>=0){o.splice(h,1);return}for(const f of o)if(f.children&&f.children.length)return s(r,f.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const r={model:this,type:"delete",data:i};n.emit(A,r),n.emit(m,r)}}getBlock(e){return this.blocks.find(t=>t.id===e)}createBlock(e,t=!1){const i=e.id||l.uid(),s=l.upperFirstCamelCase(e.name);if(e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e),this.currentFile||this.active(e,t),!t){const r={model:this,type:"create",data:e};n.emit(C,r),n.emit(m,r)}}updateBlock(e,t=!1){const i=this.getBlock(e.id);if(i?(Object.assign(i,e),i.dsl&&(i.dsl.name=e.name)):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(C,s),n.emit(m,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(m,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(m,r)}}removeApi(e,t=!1){const i=this.apis.findIndex(s=>s.name===e||s.id===e);if(i>-1?this.apis.splice(i,1):console.warn(`not found Api for name: ${e} `),!t){const s={model:this,type:"delete",data:e};n.emit(g,s),n.emit(m,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setHomepage(e,t=!1){if(this.homepage=e,!t){const i={model:this,type:"update",data:e};n.emit(m,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(L,t):n.emit(k,t)}}const x="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(x,{model:this,type:"delete",data:r.map(o=>o.id)})}this.index=-1,t||n.emit(x,{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(x,{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(x,{model:this,type:"clear",data:t})}}const n=l.mitt();function K(c){return c instanceof u}function Y(c){return c instanceof p}function $(c){return!!c.__VTJ_BLOCK__}function B(c){return delete c.id,Array.isArray(c.children)&&(c.children=c.children.map(e=>B(e))),c}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=x;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=C;exports.EVENT_PROJECT_CHANGE=m;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.7.32",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;
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import { uid as m, timestamp as S, upperFirstCamelCase as I, merge as H, cloneDe
|
|
|
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.
|
|
6
|
+
* @version 0.7.32
|
|
7
7
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
9
|
+
const j = "0.7.32", U = "BuiltIn", k = "VueMaterial", D = "VueRouterMaterial", K = [k, D], $ = {
|
|
10
10
|
vue: "Vue",
|
|
11
11
|
"vue-router": "VueRouter"
|
|
12
12
|
}, Y = {
|
|
@@ -70,7 +70,7 @@ class x {
|
|
|
70
70
|
return Object.entries(e).reduce((t, [i, s]) => (t[i] = new x(i, s), t), {});
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
class
|
|
73
|
+
class y {
|
|
74
74
|
constructor(e) {
|
|
75
75
|
this.schema = e;
|
|
76
76
|
const { name: t, handler: i } = this.schema;
|
|
@@ -92,7 +92,7 @@ class A {
|
|
|
92
92
|
}
|
|
93
93
|
static parse(e = {}) {
|
|
94
94
|
return Object.entries(e).reduce(
|
|
95
|
-
(t, [i, s]) => (t[i] = new
|
|
95
|
+
(t, [i, s]) => (t[i] = new y(s), t),
|
|
96
96
|
{}
|
|
97
97
|
);
|
|
98
98
|
}
|
|
@@ -221,7 +221,7 @@ class p {
|
|
|
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 =
|
|
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);
|
|
225
225
|
}
|
|
226
226
|
/**
|
|
227
227
|
* 设置子节点
|
|
@@ -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
|
|
278
|
+
i ? i.update(e) : this.events[e.name] = new y(e), t || n.emit(d, this);
|
|
279
279
|
}
|
|
280
280
|
/**
|
|
281
281
|
* 删除事件
|
|
@@ -407,7 +407,7 @@ class p {
|
|
|
407
407
|
children: _,
|
|
408
408
|
props: x.toDsl(c),
|
|
409
409
|
directives: v.toDsl(E),
|
|
410
|
-
events:
|
|
410
|
+
events: y.toDsl(T)
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
413
|
/**
|
|
@@ -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",
|
|
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";
|
|
786
786
|
class O {
|
|
787
787
|
id = "";
|
|
788
788
|
name = "";
|
|
@@ -793,6 +793,7 @@ class O {
|
|
|
793
793
|
blocks = [];
|
|
794
794
|
apis = [];
|
|
795
795
|
currentFile = null;
|
|
796
|
+
config = {};
|
|
796
797
|
static attrs = [
|
|
797
798
|
"name",
|
|
798
799
|
"homepage",
|
|
@@ -800,7 +801,8 @@ class O {
|
|
|
800
801
|
"dependencies",
|
|
801
802
|
"pages",
|
|
802
803
|
"blocks",
|
|
803
|
-
"apis"
|
|
804
|
+
"apis",
|
|
805
|
+
"config"
|
|
804
806
|
];
|
|
805
807
|
constructor(e) {
|
|
806
808
|
const { id: t } = e;
|
|
@@ -944,7 +946,7 @@ class O {
|
|
|
944
946
|
type: "create",
|
|
945
947
|
data: e
|
|
946
948
|
};
|
|
947
|
-
n.emit(
|
|
949
|
+
n.emit(A, s), n.emit(f, s);
|
|
948
950
|
}
|
|
949
951
|
}
|
|
950
952
|
/**
|
|
@@ -960,7 +962,7 @@ class O {
|
|
|
960
962
|
type: "update",
|
|
961
963
|
data: e
|
|
962
964
|
};
|
|
963
|
-
n.emit(
|
|
965
|
+
n.emit(A, s), n.emit(f, s);
|
|
964
966
|
}
|
|
965
967
|
}
|
|
966
968
|
/**
|
|
@@ -983,7 +985,7 @@ class O {
|
|
|
983
985
|
newPage: c
|
|
984
986
|
}
|
|
985
987
|
};
|
|
986
|
-
n.emit(
|
|
988
|
+
n.emit(A, _), n.emit(f, _);
|
|
987
989
|
}
|
|
988
990
|
}
|
|
989
991
|
/**
|
|
@@ -1008,7 +1010,7 @@ class O {
|
|
|
1008
1010
|
type: "delete",
|
|
1009
1011
|
data: i
|
|
1010
1012
|
};
|
|
1011
|
-
n.emit(
|
|
1013
|
+
n.emit(A, r), n.emit(f, r);
|
|
1012
1014
|
}
|
|
1013
1015
|
}
|
|
1014
1016
|
/**
|
|
@@ -1032,7 +1034,7 @@ class O {
|
|
|
1032
1034
|
type: "create",
|
|
1033
1035
|
data: e
|
|
1034
1036
|
};
|
|
1035
|
-
n.emit(
|
|
1037
|
+
n.emit(g, r), n.emit(f, r);
|
|
1036
1038
|
}
|
|
1037
1039
|
}
|
|
1038
1040
|
/**
|
|
@@ -1048,7 +1050,7 @@ class O {
|
|
|
1048
1050
|
type: "update",
|
|
1049
1051
|
data: e
|
|
1050
1052
|
};
|
|
1051
|
-
n.emit(
|
|
1053
|
+
n.emit(g, s), n.emit(f, s);
|
|
1052
1054
|
}
|
|
1053
1055
|
}
|
|
1054
1056
|
/**
|
|
@@ -1064,7 +1066,7 @@ class O {
|
|
|
1064
1066
|
type: "delete",
|
|
1065
1067
|
data: i
|
|
1066
1068
|
};
|
|
1067
|
-
n.emit(
|
|
1069
|
+
n.emit(g, a), n.emit(f, a);
|
|
1068
1070
|
}
|
|
1069
1071
|
}
|
|
1070
1072
|
/**
|
|
@@ -1133,6 +1135,16 @@ class O {
|
|
|
1133
1135
|
n.emit(f, i);
|
|
1134
1136
|
}
|
|
1135
1137
|
}
|
|
1138
|
+
setConfig(e, t = !1) {
|
|
1139
|
+
if (this.config = Object.assign(this.config, e), !t) {
|
|
1140
|
+
const i = {
|
|
1141
|
+
model: this,
|
|
1142
|
+
type: "update",
|
|
1143
|
+
data: e
|
|
1144
|
+
};
|
|
1145
|
+
n.emit(f, i);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1136
1148
|
publish(e) {
|
|
1137
1149
|
const t = {
|
|
1138
1150
|
model: this,
|
|
@@ -1142,7 +1154,7 @@ class O {
|
|
|
1142
1154
|
e ? n.emit(G, t) : n.emit(J, t);
|
|
1143
1155
|
}
|
|
1144
1156
|
}
|
|
1145
|
-
const N = "EVENT_HISTORY_CHANGE",
|
|
1157
|
+
const N = "EVENT_HISTORY_CHANGE", C = "EVENT_HISTORY_LOAD";
|
|
1146
1158
|
class z {
|
|
1147
1159
|
options = { max: 50 };
|
|
1148
1160
|
index = -1;
|
|
@@ -1212,7 +1224,7 @@ class z {
|
|
|
1212
1224
|
return;
|
|
1213
1225
|
--this.index;
|
|
1214
1226
|
const s = i[this.index];
|
|
1215
|
-
s && !e && n.emit(
|
|
1227
|
+
s && !e && n.emit(C, {
|
|
1216
1228
|
model: this,
|
|
1217
1229
|
type: "load",
|
|
1218
1230
|
data: s
|
|
@@ -1224,7 +1236,7 @@ class z {
|
|
|
1224
1236
|
return;
|
|
1225
1237
|
t < 0 && (this.index = 0), ++this.index;
|
|
1226
1238
|
const s = i[this.index];
|
|
1227
|
-
s && !e && n.emit(
|
|
1239
|
+
s && !e && n.emit(C, {
|
|
1228
1240
|
model: this,
|
|
1229
1241
|
type: "load",
|
|
1230
1242
|
data: s
|
|
@@ -1232,7 +1244,7 @@ class z {
|
|
|
1232
1244
|
}
|
|
1233
1245
|
load(e, t = !1) {
|
|
1234
1246
|
const i = this.items.findIndex((s) => s.id === e);
|
|
1235
|
-
i >= 0 && (this.index = i, t || n.emit(
|
|
1247
|
+
i >= 0 && (this.index = i, t || n.emit(C, {
|
|
1236
1248
|
model: this,
|
|
1237
1249
|
type: "load",
|
|
1238
1250
|
data: this.items[i]
|
|
@@ -1265,7 +1277,7 @@ export {
|
|
|
1265
1277
|
Y as BUILT_IN_COMPONENTS,
|
|
1266
1278
|
$ as BUILT_IN_LIBRARAY_MAP,
|
|
1267
1279
|
K as BUILT_IN_MATERIALS,
|
|
1268
|
-
|
|
1280
|
+
U as BUILT_IN_NAME,
|
|
1269
1281
|
M as BUILT_IN_TAGS,
|
|
1270
1282
|
k as BUILT_IN_VUE,
|
|
1271
1283
|
D as BUILT_IN_VUE_ROUTER,
|
|
@@ -1274,23 +1286,23 @@ export {
|
|
|
1274
1286
|
v as DirectiveModel,
|
|
1275
1287
|
o as EVENT_BLOCK_CHANGE,
|
|
1276
1288
|
N as EVENT_HISTORY_CHANGE,
|
|
1277
|
-
|
|
1289
|
+
C as EVENT_HISTORY_LOAD,
|
|
1278
1290
|
d as EVENT_NODE_CHANGE,
|
|
1279
1291
|
P as EVENT_PROJECT_ACTIVED,
|
|
1280
1292
|
R as EVENT_PROJECT_APIS_CHANGE,
|
|
1281
|
-
|
|
1293
|
+
g as EVENT_PROJECT_BLOCKS_CHANGE,
|
|
1282
1294
|
f as EVENT_PROJECT_CHANGE,
|
|
1283
1295
|
V as EVENT_PROJECT_DEPS_CHANGE,
|
|
1284
1296
|
G as EVENT_PROJECT_FILE_PUBLISH,
|
|
1285
|
-
|
|
1297
|
+
A as EVENT_PROJECT_PAGES_CHANGE,
|
|
1286
1298
|
J as EVENT_PROJECT_PUBLISH,
|
|
1287
|
-
|
|
1299
|
+
y as EventModel,
|
|
1288
1300
|
z as HistoryModel,
|
|
1289
1301
|
p as NodeModel,
|
|
1290
1302
|
O as ProjectModel,
|
|
1291
1303
|
x as PropModel,
|
|
1292
1304
|
W as Service,
|
|
1293
|
-
|
|
1305
|
+
j as VTJ_CORE_VERSION,
|
|
1294
1306
|
B as cloneDsl,
|
|
1295
1307
|
n as emitter,
|
|
1296
1308
|
Q as isBlock,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.32",
|
|
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.
|
|
13
|
+
"@vtj/base": "^0.7.8"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@vtj/cli": "^0.7.
|
|
16
|
+
"@vtj/cli": "^0.7.21"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist",
|
|
30
30
|
"types"
|
|
31
31
|
],
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "2b52c6e2664561d691067d48170d3837f78d5ee5",
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ModelEventType } from '../tools';
|
|
2
|
-
import { ProjectSchema, Dependencie, PageFile, BlockFile, ApiSchema } from '../protocols';
|
|
2
|
+
import { ProjectSchema, Dependencie, PageFile, BlockFile, ApiSchema, ProjectConfig } from '../protocols';
|
|
3
3
|
|
|
4
4
|
export interface ProjectModelEvent {
|
|
5
5
|
model: ProjectModel;
|
|
@@ -48,6 +48,7 @@ export declare class ProjectModel {
|
|
|
48
48
|
blocks: BlockFile[];
|
|
49
49
|
apis: ApiSchema[];
|
|
50
50
|
currentFile: PageFile | BlockFile | null;
|
|
51
|
+
config: ProjectConfig;
|
|
51
52
|
static attrs: string[];
|
|
52
53
|
constructor(schema: ProjectSchema);
|
|
53
54
|
update(schema: Partial<ProjectSchema>, silent?: boolean): void;
|
|
@@ -165,5 +166,6 @@ export declare class ProjectModel {
|
|
|
165
166
|
removeApi(name: string, silent?: boolean): void;
|
|
166
167
|
existApiName(name: string, excludes?: string[]): boolean;
|
|
167
168
|
setHomepage(id: string, silent?: boolean): void;
|
|
169
|
+
setConfig(config: ProjectConfig, silent?: boolean): void;
|
|
168
170
|
publish(file?: PageFile | BlockFile): void;
|
|
169
171
|
}
|
|
@@ -38,6 +38,10 @@ export interface ProjectSchema {
|
|
|
38
38
|
* api
|
|
39
39
|
*/
|
|
40
40
|
apis?: ApiSchema[];
|
|
41
|
+
/**
|
|
42
|
+
* 项目配置
|
|
43
|
+
*/
|
|
44
|
+
config?: ProjectConfig;
|
|
41
45
|
/**
|
|
42
46
|
* 标记
|
|
43
47
|
*/
|
|
@@ -47,3 +51,24 @@ export interface ProjectSchema {
|
|
|
47
51
|
*/
|
|
48
52
|
__VERSION__?: string;
|
|
49
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* 项目配置信息
|
|
56
|
+
*/
|
|
57
|
+
export interface ProjectConfig {
|
|
58
|
+
/**
|
|
59
|
+
* 开启模拟数据
|
|
60
|
+
*/
|
|
61
|
+
mock?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 开启主题切换
|
|
64
|
+
*/
|
|
65
|
+
themeSwitchable?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 站点标题
|
|
68
|
+
*/
|
|
69
|
+
title?: string;
|
|
70
|
+
/**
|
|
71
|
+
* logo
|
|
72
|
+
*/
|
|
73
|
+
logo?: string;
|
|
74
|
+
}
|
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.7.
|
|
5
|
+
* @version 0.7.31
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.7.
|
|
8
|
+
export declare const version = "0.7.31";
|