@vtj/core 0.16.0 → 0.16.2
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 +3 -3
- package/dist/index.mjs +133 -99
- package/package.json +1 -1
- package/types/models/project.d.ts +3 -0
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@vtj/base");/**!
|
|
2
2
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.16.
|
|
5
|
+
* @version 0.16.2
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const U="0.16.0",G="BuiltIn",R="VueMaterial",k="VueRouterMaterial",J=[R,k],w={vue:"Vue","vue-router":"VueRouter"},j={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[k]:["RouterView","RouterLink"]},F=["slot","template","component","img","div","p","h1","h2","h3","span","a"],M=[{label:"简体中文",value:"zh-CN"},{label:"English",value:"en"}];class ${}class K{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 y{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 y(i,s),t),{})}}class C{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:a,modifiers:o}=s;return t[i]={name:i,handler:a,modifiers:o},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new C(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||r.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:a,iterator:o}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=a,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:a,value:o,iterator:d,id:h}=t;return{id:h,name:i,arg:s,modifiers:a,value:o,iterator:d}})}}const f="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=r.uid(),name:s,from:a=""}=e;this.id=i,this.name=s,this.from=a,this.update(e,!0),_.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:a=[],slot:o,props:d={},events:h={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(a,!0),this.setSlot(o,!0),this.props=y.parse(d),this.events=C.parse(h),this.directives=E.parse(p),t||n.emit(f,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new _(i,this)):this.children=e,t||n.emit(f,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(f,this)}setProp(e,t,i,s=!1){const a=this.props[e];a?a.setValue(t):this.props[e]=new y(e,t,i),s||n.emit(f,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(f,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 C(e),t||n.emit(f,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(f,this)}setDirective(e,t=!1){const i=e instanceof E?e:new E(e),s=this.directives.findIndex(a=>a.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||n.emit(f,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(f,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const a=i.findIndex(o=>o===e);e.parent=null,i.splice(a,1),t||n.emit(f,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(f,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(f,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(f,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(f,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(f,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:d,props:h,directives:p,events:I}=this,v=Array.isArray(d)?d.map(H=>H.toDsl()):d;return{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:v,props:y.toDsl(h),directives:E.toDsl(p),events:C.toDsl(I)}}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(f,this),this.parent=null,this.disposed=!0,delete _.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(f,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(f,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(f,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 l="EVENT_BLOCK_CHANGE";class u{__VTJ_BLOCK__=!0;id;name="";inject=[];state={};lifeCycles={};methods={};computed={};watch=[];css="";props=[];emits=[];expose=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","inject","state","lifeCycles","methods","computed","watch","css","props","emits","expose","slots","dataSources","__TEMPLATE_ID__"];constructor(e){const{id:t}=e;this.id=t||r.uid(),this.update(e,!0)}update(e,t=!1){for(const s of u.normalAttrs){const a=e[s];a!==void 0&&(this[s]=a)}const{nodes:i=[]}=e;i.length?this.nodes=i.map(s=>new _(s)):this.nodes=[],t||n.emit(l,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((o,d)=>(o[d]=this[d],o),{}),__VTJ_BLOCK__:t,__VERSION__:e||r.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(l,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(l,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(l,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(l,this)}setCss(e,t=!1){this.css=e,t||n.emit(l,this)}setWatch(e,t=!1){e.id=e.id||r.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(l,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(l,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(l,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(l,this))}setEmit(e,t=!1){const i=r.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(a=>a===i.name||a.name===i.name);s>-1?this.emits.splice(s,1,i):this.emits.push(i),t||n.emit(l,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>r.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||n.emit(l,this))}setExpose(e,t=!1){this.expose=e,t||n.emit(l,this)}setSlot(e,t=!1){const i=r.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(a=>a===i.name||a.name===i.name);s>-1?this.slots.splice(s,1,i):this.slots.push(i),t||n.emit(l,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>r.isString(s)?s===e:s.name===e);i>-1&&(this.slots.splice(i,1),t||n.emit(l,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(l,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(l,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(l,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(l,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(l,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(l,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(l,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(l,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(l,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(l,this))}}cloneNode(e,t=!1){const i=B(e.toDsl()),s=new _(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(l,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(l,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",g="EVENT_PROJECT_PAGES_CHANGE",T="EVENT_PROJECT_BLOCKS_CHANGE",A="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",D="EVENT_PROJECT_PUBLISH",b="EVENT_PROJECT_FILE_PUBLISH",L="EVENT_PROJECT_GEN_SOURCE";class O{id="";locked="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};globals={};i18n={locale:"zh-CN",fallbackLocale:"zh-CN",messages:[]};env=[];__BASE_PATH__="/";__UID__=r.uuid(!0);static attrs=["locked","platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","globals","i18n","env","__BASE_PATH__","__UID__"];constructor(e){const{id:t,__UID__:i}=e;this.id=t||r.uid(),this.__UID__=i||r.uuid(!0),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"}cleanPagesDsl(e){for(const t of e)delete t.dsl,t.children&&t.children.length&&this.cleanPagesDsl(t.children)}toDsl(e){const{id:t}=this,i=O.attrs.reduce((s,a)=>(s[a]=this[a],s),{});return i.pages&&(i.pages=i.pages.map(s=>r.cloneDeep({...s,dsl:void 0})),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>r.cloneDeep({...s,dsl:void 0}))),{__VTJ_PROJECT__:!0,id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(P,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(P,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(o=>o.package===e.package);let a;if(s>-1?(a="update",i.splice(s,1,{...i[s],...e})):(a="create",i.push(e)),!t){const o={model:this,type:a,data:e};n.emit(V,o),n.emit(c,o)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(a=>a.package===e.package);if(s>-1&&i.splice(s,1),!t){const a={model:this,type:"delete",data:e};n.emit(V,a),n.emit(c,a)}}getPage(e){const t=(i,s=[])=>{for(const a of s){if(a.id===i)return a;if(a.children&&a.children.length){const o=t(i,a.children);if(o)return o}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir||s.layout?(s.layout&&i.push(s),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||r.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:r.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(g,s),n.emit(c,s)}return!this.currentFile&&!e.dir&&(await r.delay(1e3),this.active(e,i)),e}updatePage(e,t=!1){const i=this.getPage(e.id);if(delete e.dsl,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(g,s),n.emit(c,s)}return i}clonePage(e,t,i=!1){const s=r.uid(),a=`${e.name}Copy`,o=`${e.title}_副本`,d=new u({id:s,name:a}).toDsl(),h=r.merge({},e,{id:s,name:a,title:o,dsl:d}),p=t?this.getPage(t)?.children||[]:this.pages,I=p.findIndex(v=>v.id===e.id);if(p.splice(I+1,0,h),!i){const v={model:this,type:"clone",data:{source:e,target:h}};n.emit(g,v),n.emit(c,v)}}async saveToBlock(e,t=!1){this.active(e,t),await r.delay(1e3);const i=r.uid(),s=e.name,a=e.title,o=new u({...e.dsl,id:i,name:s}).toDsl(),d=r.merge({},e,{id:i,name:s,title:a,dsl:o,type:"block",fromType:"Schema"});if(this.blocks.push(d),!t){const h={model:this,type:"create",data:d};n.emit(T,h),n.emit(c,h)}}removePage(e,t=!1){const i=this.getPage(e),s=(a,o)=>{const d=o.findIndex(h=>h.id===a);if(d>=0){o.splice(d,1);return}for(const h of o)h.children&&h.children.length&&s(a,h.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const a={model:this,type:"delete",data:i};n.emit(g,a),n.emit(c,a)}}getBlock(e){return this.blocks.find(t=>t.id===e)}getFile(e){return this.getPage(e)||this.getBlock(e)}async createBlock(e,t=!1){const i=e.id||r.uid(),s=r.upperFirstCamelCase(e.name);e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e);const a=e.fromType||"Schema";if(!t){const o={model:this,type:"create",data:e};n.emit(T,o),n.emit(c,o)}return!this.currentFile&&a==="Schema"&&(await r.delay(1e3),this.active(e,t)),e}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(T,s),n.emit(c,s)}return i}cloneBlock(e,t=!1){const i=r.uid(),s=`${e.name}Copy`,a=`${e.title}_副本`,o=new u({id:i,name:s}).toDsl(),d=r.merge({},e,{id:i,name:s,title:a,dsl:o}),h=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(h+1,0,d),!t){const p={model:this,type:"clone",data:{source:e,target:d}};n.emit(T,p),n.emit(c,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,a=s.findIndex(o=>o.id===e);if(a>-1?(s.splice(a,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(T,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(a=>a.name===e.name||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=r.uid(),this.apis.push(e)),!t){const a={model:this,type:s,data:e};n.emit(A,a),n.emit(c,a)}return i||e}setApis(e,t=!1){for(const i of e)this.setApi(i,!0);if(!t){const i={model:this,type:"create",data:e};n.emit(A,i),n.emit(c,i)}}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(A,s),n.emit(c,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setMeta(e,t=!1){const i=this.meta.find(a=>a.code===e.code||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=r.uid(),this.meta.push(e)),!t){const a={model:this,type:s,data:e};n.emit(S,a),n.emit(c,a)}}removeMeta(e,t=!1){const i=this.meta.findIndex(s=>s.code===e||s.id===e);if(i>-1?this.meta.splice(i,1):console.warn(`not found meta for name: ${name} `),!t){const s={model:this,type:"delete",data:e};n.emit(S,s),n.emit(c,s)}}existMetaCode(e,t=[]){return this.meta.some(i=>i.code===e&&!t.includes(i.id))}setHomepage(e,t=!1){if(this.homepage=e,!t){const i={model:this,type:"update",data:e};n.emit(c,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(c,i)}}setUniConfig(e,t,i=!1){if(this.uniConfig=Object.assign(this.uniConfig,{[e]:t}),!i){const s={model:this,type:"update",data:this.uniConfig};n.emit(c,s)}}setGloblas(e,t,i=!1){if(this.globals=Object.assign(this.globals,{[e]:t}),!i){const s={model:this,type:"update",data:this.globals};n.emit(c,s)}}setI18n(e,t=!1){if(this.i18n=Object.assign(this.i18n,e),!t){const i={model:this,type:"update",data:this.i18n};n.emit(c,i)}}setEnv(e,t=!1){if(this.env=[...e],!t){const i={model:this,type:"update",data:this.env};n.emit(c,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(b,t):n.emit(D,t)}genSource(){const e={model:this,type:"gen",data:null};n.emit(L,e)}lock(e){this.locked=e;const t={model:this,type:"update",data:e};n.emit(c,t)}unlock(e){if(e!==this.locked)return;this.locked="";const t={model:this,type:"update",data:null};n.emit(c,t)}getPageRoutes(e,t){const i=this.platform==="uniapp",s=e||(i?"pages":"page"),a=this.getPages(),o=t||"";return a.map(d=>({id:d.id,path:`${o}/${s}/${d.id}`,name:d.name,title:d.title,meta:d.meta}))}}const N="EVENT_HISTORY_CHANGE",x="EVENT_HISTORY_LOAD";class Y{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,remark:i.remark||""}))}}get(e){return this.items.find(t=>t.id===e)}add(e,t="",i=!1){const{max:s}=this.options,a={id:r.uid(),label:new Date().toLocaleString(),remark:t,dsl:r.cloneDeep(e)};this.items.unshift(a);const o=this.items.filter(d=>!d.remark);if(o.length>s){const d=o.splice(s).map(h=>h.id);this.items=this.items.filter(h=>!d.includes(h.id)),i||n.emit(N,{model:this,type:"delete",data:d})}this.index=-1,i||n.emit(N,{model:this,type:"create",data:a})}update(e,t=!1){const i=this.items.find(s=>s.id===e.id);i&&Object.assign(i,e),t||n.emit(N,{model:this,type:"update",data:i})}remove(e,t=!1){const i=r.toArray(e);for(const s of i){const a=this.items.findIndex(o=>o.id===s);a>-1?(this.items.splice(a,1),a===this.index?this.index=-1:this.index>=this.items.length&&(this.index=this.items.length-1)):console.warn(`not found HistoryItem for id: ${e} `)}t||n.emit(N,{model:this,type:"delete",data:i})}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(N,{model:this,type:"clear",data:t})}}const n=r.mitt();function z(m){return m instanceof u}function W(m){return m instanceof _}function q(m){return!!m.__VTJ_BLOCK__}function B(m){const e=r.cloneDeep(m);return delete e.id,Array.isArray(e.children)&&(e.children=e.children.map(t=>B(t))),e}function Q(m){const e=m.fromType||"Schema";return e==="Schema"?{type:"Schema",id:m.id}:e==="UrlSchema"?{type:"UrlSchema",url:(m.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(m.urls||"").split(","),library:m.library}:""}exports.BUILT_IN_COMPONENTS=j;exports.BUILT_IN_LIBRARAY_MAP=w;exports.BUILT_IN_MATERIALS=J;exports.BUILT_IN_NAME=G;exports.BUILT_IN_TAGS=F;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=k;exports.Base=K;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=l;exports.EVENT_HISTORY_CHANGE=N;exports.EVENT_HISTORY_LOAD=x;exports.EVENT_NODE_CHANGE=f;exports.EVENT_PROJECT_ACTIVED=P;exports.EVENT_PROJECT_APIS_CHANGE=A;exports.EVENT_PROJECT_BLOCKS_CHANGE=T;exports.EVENT_PROJECT_CHANGE=c;exports.EVENT_PROJECT_DEPS_CHANGE=V;exports.EVENT_PROJECT_FILE_PUBLISH=b;exports.EVENT_PROJECT_GEN_SOURCE=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=g;exports.EVENT_PROJECT_PUBLISH=D;exports.EventModel=C;exports.HistoryModel=Y;exports.I18N_LOCALES=M;exports.NodeModel=_;exports.ProjectModel=O;exports.PropModel=y;exports.Service=$;exports.VTJ_CORE_VERSION=U;exports.cloneDsl=B;exports.createNodeFrom=Q;exports.emitter=n;exports.isBlock=z;exports.isBlockSchema=q;exports.isNode=W;
|
|
7
|
+
*/const U="0.16.2",G="BuiltIn",R="VueMaterial",k="VueRouterMaterial",J=[R,k],w={vue:"Vue","vue-router":"VueRouter"},j={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[k]:["RouterView","RouterLink"]},F=["slot","template","component","img","div","p","h1","h2","h3","span","a"],M=[{label:"简体中文",value:"zh-CN"},{label:"English",value:"en"}];class ${}class K{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 y{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 y(i,s),t),{})}}class C{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:a,modifiers:o}=s;return t[i]={name:i,handler:a,modifiers:o},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new C(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:a,iterator:o}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=a,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:a,value:o,iterator:r,id:h}=t;return{id:h,name:i,arg:s,modifiers:a,value:o,iterator:r}})}}const f="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=l.uid(),name:s,from:a=""}=e;this.id=i,this.name=s,this.from=a,this.update(e,!0),_.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:a=[],slot:o,props:r={},events:h={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(a,!0),this.setSlot(o,!0),this.props=y.parse(r),this.events=C.parse(h),this.directives=E.parse(p),t||n.emit(f,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new _(i,this)):this.children=e,t||n.emit(f,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(f,this)}setProp(e,t,i,s=!1){const a=this.props[e];a?a.setValue(t):this.props[e]=new y(e,t,i),s||n.emit(f,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(f,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 C(e),t||n.emit(f,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(f,this)}setDirective(e,t=!1){const i=e instanceof E?e:new E(e),s=this.directives.findIndex(a=>a.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||n.emit(f,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(f,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const a=i.findIndex(o=>o===e);e.parent=null,i.splice(a,1),t||n.emit(f,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(f,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(f,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(f,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(f,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(f,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:r,props:h,directives:p,events:O}=this,v=Array.isArray(r)?r.map(H=>H.toDsl()):r;return{id:e,name:t,from:i,invisible:s,locked:a,slot:o,children:v,props:y.toDsl(h),directives:E.toDsl(p),events:C.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(f,this),this.parent=null,this.disposed=!0,delete _.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(f,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(f,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(f,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 d="EVENT_BLOCK_CHANGE";class u{__VTJ_BLOCK__=!0;id;name="";inject=[];state={};lifeCycles={};methods={};computed={};watch=[];css="";props=[];emits=[];expose=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","inject","state","lifeCycles","methods","computed","watch","css","props","emits","expose","slots","dataSources","__TEMPLATE_ID__"];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 a=e[s];a!==void 0&&(this[s]=a)}const{nodes:i=[]}=e;i.length?this.nodes=i.map(s=>new _(s)):this.nodes=[],t||n.emit(d,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((o,r)=>(o[r]=this[r],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(d,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(d,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(d,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(d,this)}setCss(e,t=!1){this.css=e,t||n.emit(d,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(d,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(d,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(d,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(d,this))}setEmit(e,t=!1){const i=l.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(a=>a===i.name||a.name===i.name);s>-1?this.emits.splice(s,1,i):this.emits.push(i),t||n.emit(d,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>l.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||n.emit(d,this))}setExpose(e,t=!1){this.expose=e,t||n.emit(d,this)}setSlot(e,t=!1){const i=l.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(a=>a===i.name||a.name===i.name);s>-1?this.slots.splice(s,1,i):this.slots.push(i),t||n.emit(d,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>l.isString(s)?s===e:s.name===e);i>-1&&(this.slots.splice(i,1),t||n.emit(d,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(d,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(d,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(d,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(d,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(d,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(d,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(d,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(d,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(d,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(d,this))}}cloneNode(e,t=!1){const i=D(e.toDsl()),s=new _(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(d,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(d,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",I="EVENT_PROJECT_ACTIVED",V="EVENT_PROJECT_DEPS_CHANGE",T="EVENT_PROJECT_PAGES_CHANGE",N="EVENT_PROJECT_BLOCKS_CHANGE",A="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",B="EVENT_PROJECT_PUBLISH",b="EVENT_PROJECT_FILE_PUBLISH",L="EVENT_PROJECT_GEN_SOURCE";class x{id="";locked="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};globals={};i18n={locale:"zh-CN",fallbackLocale:"zh-CN",messages:[]};env=[];__BASE_PATH__="/";__UID__=l.uuid(!0);static attrs=["locked","platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","globals","i18n","env","__BASE_PATH__","__UID__"];constructor(e){const{id:t,__UID__:i}=e;this.id=t||l.uid(),this.__UID__=i||l.uuid(!0),this.update(e,!0)}update(e,t=!1){for(const i of x.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"}cleanPagesDsl(e){for(const t of e)delete t.dsl,t.children&&t.children.length&&this.cleanPagesDsl(t.children)}toDsl(e){const{id:t}=this,i=x.attrs.reduce((s,a)=>(s[a]=this[a],s),{});return i.pages&&(i.pages=i.pages.map(s=>l.cloneDeep({...s,dsl:void 0})),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>l.cloneDeep({...s,dsl:void 0}))),{__VTJ_PROJECT__:!0,id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(I,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(I,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(o=>o.package===e.package);let a;if(s>-1?(a="update",i.splice(s,1,{...i[s],...e})):(a="create",i.push(e)),!t){const o={model:this,type:a,data:e};n.emit(V,o),n.emit(c,o)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(a=>a.package===e.package);if(s>-1&&i.splice(s,1),!t){const a={model:this,type:"delete",data:e};n.emit(V,a),n.emit(c,a)}}getPage(e){const t=(i,s=[])=>{for(const a of s){if(a.id===i)return a;if(a.children&&a.children.length){const o=t(i,a.children);if(o)return o}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir||s.layout?(s.layout&&i.push(s),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||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(!i){const s={model:this,type:"create",data:e};n.emit(T,s),n.emit(c,s)}return!this.currentFile&&!e.dir&&(await l.delay(1e3),this.active(e,i)),e}updatePage(e,t=!1){const i=this.getPage(e.id);if(delete e.dsl,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(T,s),n.emit(c,s)}return i}findParent(e){const t=(i,s=[],a)=>{for(const o of s){if(o.id===i)return a;if(o.children&&o.children.length){const r=t(i,o.children,o);if(r)return r}}};return t(e,this.pages)}movePageTo(e,t,i=!1){const s=t?this.getPage(t):null,a=this.getPage(e);if(!a)return!1;const o=this.findParent(e);if(o?o.children=o.children?.filter(r=>r.id!==e):this.pages=this.pages.filter(r=>r.id!==e),s?(s.dir||s.layout)&&(s.children?s.children.push(a):s.children=[a]):this.pages.push(a),!i){const r={model:this,type:"update",data:a};n.emit(T,r),n.emit(c,r)}return!0}getPageTree(){const e=l.cloneDeep(this.pages);return this.cleanPagesDsl(e),e}clonePage(e,t,i=!1){const s=l.uid(),a=`${e.name}Copy`,o=`${e.title}_副本`,r=new u({id:s,name:a}).toDsl(),h=l.merge({},e,{id:s,name:a,title:o,dsl:r}),p=t?this.getPage(t)?.children||[]:this.pages,O=p.findIndex(v=>v.id===e.id);if(p.splice(O+1,0,h),!i){const v={model:this,type:"clone",data:{source:e,target:h}};n.emit(T,v),n.emit(c,v)}}async saveToBlock(e,t=!1){this.active(e,t),await l.delay(1e3);const i=l.uid(),s=e.name,a=e.title,o=new u({...e.dsl,id:i,name:s}).toDsl(),r=l.merge({},e,{id:i,name:s,title:a,dsl:o,type:"block",fromType:"Schema"});if(this.blocks.push(r),!t){const h={model:this,type:"create",data:r};n.emit(N,h),n.emit(c,h)}}removePage(e,t=!1){const i=this.getPage(e),s=(a,o)=>{const r=o.findIndex(h=>h.id===a);if(r>=0){o.splice(r,1);return}for(const h of o)h.children&&h.children.length&&s(a,h.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const a={model:this,type:"delete",data:i};n.emit(T,a),n.emit(c,a)}}getBlock(e){return this.blocks.find(t=>t.id===e)}getFile(e){return this.getPage(e)||this.getBlock(e)}async createBlock(e,t=!1){const i=e.id||l.uid(),s=l.upperFirstCamelCase(e.name);e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e);const a=e.fromType||"Schema";if(!t){const o={model:this,type:"create",data:e};n.emit(N,o),n.emit(c,o)}return!this.currentFile&&a==="Schema"&&(await l.delay(1e3),this.active(e,t)),e}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(N,s),n.emit(c,s)}return i}cloneBlock(e,t=!1){const i=l.uid(),s=`${e.name}Copy`,a=`${e.title}_副本`,o=new u({id:i,name:s}).toDsl(),r=l.merge({},e,{id:i,name:s,title:a,dsl:o}),h=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(h+1,0,r),!t){const p={model:this,type:"clone",data:{source:e,target:r}};n.emit(N,p),n.emit(c,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,a=s.findIndex(o=>o.id===e);if(a>-1?(s.splice(a,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(N,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(a=>a.name===e.name||a.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 a={model:this,type:s,data:e};n.emit(A,a),n.emit(c,a)}return i||e}setApis(e,t=!1){for(const i of e)this.setApi(i,!0);if(!t){const i={model:this,type:"create",data:e};n.emit(A,i),n.emit(c,i)}}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(A,s),n.emit(c,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setMeta(e,t=!1){const i=this.meta.find(a=>a.code===e.code||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=l.uid(),this.meta.push(e)),!t){const a={model:this,type:s,data:e};n.emit(S,a),n.emit(c,a)}}removeMeta(e,t=!1){const i=this.meta.findIndex(s=>s.code===e||s.id===e);if(i>-1?this.meta.splice(i,1):console.warn(`not found meta for name: ${name} `),!t){const s={model:this,type:"delete",data:e};n.emit(S,s),n.emit(c,s)}}existMetaCode(e,t=[]){return this.meta.some(i=>i.code===e&&!t.includes(i.id))}setHomepage(e,t=!1){if(this.homepage=e,!t){const i={model:this,type:"update",data:e};n.emit(c,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(c,i)}}setUniConfig(e,t,i=!1){if(this.uniConfig=Object.assign(this.uniConfig,{[e]:t}),!i){const s={model:this,type:"update",data:this.uniConfig};n.emit(c,s)}}setGloblas(e,t,i=!1){if(this.globals=Object.assign(this.globals,{[e]:t}),!i){const s={model:this,type:"update",data:this.globals};n.emit(c,s)}}setI18n(e,t=!1){if(this.i18n=Object.assign(this.i18n,e),!t){const i={model:this,type:"update",data:this.i18n};n.emit(c,i)}}setEnv(e,t=!1){if(this.env=[...e],!t){const i={model:this,type:"update",data:this.env};n.emit(c,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(b,t):n.emit(B,t)}genSource(){const e={model:this,type:"gen",data:null};n.emit(L,e)}lock(e){this.locked=e;const t={model:this,type:"update",data:e};n.emit(c,t)}unlock(e){if(e!==this.locked)return;this.locked="";const t={model:this,type:"update",data:null};n.emit(c,t)}getPageRoutes(e,t){const i=this.platform==="uniapp",s=e||(i?"pages":"page"),a=this.getPages(),o=t||"";return a.map(r=>({id:r.id,path:`${o}/${s}/${r.id}`,name:r.name,title:r.title,meta:r.meta}))}}const g="EVENT_HISTORY_CHANGE",P="EVENT_HISTORY_LOAD";class Y{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,remark:i.remark||""}))}}get(e){return this.items.find(t=>t.id===e)}add(e,t="",i=!1){const{max:s}=this.options,a={id:l.uid(),label:new Date().toLocaleString(),remark:t,dsl:l.cloneDeep(e)};this.items.unshift(a);const o=this.items.filter(r=>!r.remark);if(o.length>s){const r=o.splice(s).map(h=>h.id);this.items=this.items.filter(h=>!r.includes(h.id)),i||n.emit(g,{model:this,type:"delete",data:r})}this.index=-1,i||n.emit(g,{model:this,type:"create",data:a})}update(e,t=!1){const i=this.items.find(s=>s.id===e.id);i&&Object.assign(i,e),t||n.emit(g,{model:this,type:"update",data:i})}remove(e,t=!1){const i=l.toArray(e);for(const s of i){const a=this.items.findIndex(o=>o.id===s);a>-1?(this.items.splice(a,1),a===this.index?this.index=-1:this.index>=this.items.length&&(this.index=this.items.length-1)):console.warn(`not found HistoryItem for id: ${e} `)}t||n.emit(g,{model:this,type:"delete",data:i})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&n.emit(P,{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(P,{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(P,{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(g,{model:this,type:"clear",data:t})}}const n=l.mitt();function z(m){return m instanceof u}function W(m){return m instanceof _}function q(m){return!!m.__VTJ_BLOCK__}function D(m){const e=l.cloneDeep(m);return delete e.id,Array.isArray(e.children)&&(e.children=e.children.map(t=>D(t))),e}function Q(m){const e=m.fromType||"Schema";return e==="Schema"?{type:"Schema",id:m.id}:e==="UrlSchema"?{type:"UrlSchema",url:(m.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(m.urls||"").split(","),library:m.library}:""}exports.BUILT_IN_COMPONENTS=j;exports.BUILT_IN_LIBRARAY_MAP=w;exports.BUILT_IN_MATERIALS=J;exports.BUILT_IN_NAME=G;exports.BUILT_IN_TAGS=F;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=k;exports.Base=K;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=d;exports.EVENT_HISTORY_CHANGE=g;exports.EVENT_HISTORY_LOAD=P;exports.EVENT_NODE_CHANGE=f;exports.EVENT_PROJECT_ACTIVED=I;exports.EVENT_PROJECT_APIS_CHANGE=A;exports.EVENT_PROJECT_BLOCKS_CHANGE=N;exports.EVENT_PROJECT_CHANGE=c;exports.EVENT_PROJECT_DEPS_CHANGE=V;exports.EVENT_PROJECT_FILE_PUBLISH=b;exports.EVENT_PROJECT_GEN_SOURCE=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=T;exports.EVENT_PROJECT_PUBLISH=B;exports.EventModel=C;exports.HistoryModel=Y;exports.I18N_LOCALES=M;exports.NodeModel=_;exports.ProjectModel=x;exports.PropModel=y;exports.Service=$;exports.VTJ_CORE_VERSION=U;exports.cloneDsl=D;exports.createNodeFrom=Q;exports.emitter=n;exports.isBlock=z;exports.isBlockSchema=q;exports.isNode=W;
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { uid as m, timestamp as G, isString as
|
|
1
|
+
import { uid as m, timestamp as G, isString as C, uuid as b, cloneDeep as T, upperFirstCamelCase as R, delay as O, merge as I, toArray as j, mitt as F } from "@vtj/base";
|
|
2
2
|
/**!
|
|
3
3
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
4
4
|
* @name @vtj/core
|
|
5
5
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
6
|
-
* @version 0.16.
|
|
6
|
+
* @version 0.16.2
|
|
7
7
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
8
8
|
*/
|
|
9
|
-
const z = "0.16.
|
|
9
|
+
const z = "0.16.2", W = "BuiltIn", H = "VueMaterial", L = "VueRouterMaterial", q = [H, L], Q = {
|
|
10
10
|
vue: "Vue",
|
|
11
11
|
"vue-router": "VueRouter"
|
|
12
12
|
}, X = {
|
|
@@ -58,7 +58,7 @@ class ie {
|
|
|
58
58
|
this.isReady = !1;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
class
|
|
61
|
+
class A {
|
|
62
62
|
constructor(e, t, i) {
|
|
63
63
|
this.name = e, this.value = t, this.defaultValue = i, this.setValue(t);
|
|
64
64
|
}
|
|
@@ -76,10 +76,10 @@ class x {
|
|
|
76
76
|
return Object.entries(e).reduce((t, [i, s]) => (s.isUnset || (t[i] = s.getValue()), t), {});
|
|
77
77
|
}
|
|
78
78
|
static parse(e = {}) {
|
|
79
|
-
return Object.entries(e).reduce((t, [i, s]) => (t[i] = new
|
|
79
|
+
return Object.entries(e).reduce((t, [i, s]) => (t[i] = new A(i, s), t), {});
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
class
|
|
82
|
+
class N {
|
|
83
83
|
constructor(e) {
|
|
84
84
|
this.schema = e;
|
|
85
85
|
const { name: t, handler: i } = this.schema;
|
|
@@ -95,13 +95,13 @@ class T {
|
|
|
95
95
|
}
|
|
96
96
|
static toDsl(e) {
|
|
97
97
|
return Object.entries(e).reduce((t, [i, s]) => {
|
|
98
|
-
const { handler: a, modifiers:
|
|
99
|
-
return t[i] = { name: i, handler: a, modifiers:
|
|
98
|
+
const { handler: a, modifiers: r } = s;
|
|
99
|
+
return t[i] = { name: i, handler: a, modifiers: r }, t;
|
|
100
100
|
}, {});
|
|
101
101
|
}
|
|
102
102
|
static parse(e = {}) {
|
|
103
103
|
return Object.entries(e).reduce(
|
|
104
|
-
(t, [i, s]) => (t[i] = new
|
|
104
|
+
(t, [i, s]) => (t[i] = new N(s), t),
|
|
105
105
|
{}
|
|
106
106
|
);
|
|
107
107
|
}
|
|
@@ -136,22 +136,22 @@ class v {
|
|
|
136
136
|
iterator;
|
|
137
137
|
update(e) {
|
|
138
138
|
Object.assign(this.schema, e);
|
|
139
|
-
const { name: t, arg: i, modifiers: s, value: a, iterator:
|
|
140
|
-
this.name = t, this.arg = i, this.modifiers = s, this.value = a, this.iterator =
|
|
139
|
+
const { name: t, arg: i, modifiers: s, value: a, iterator: r } = this.schema;
|
|
140
|
+
this.name = t, this.arg = i, this.modifiers = s, this.value = a, this.iterator = r;
|
|
141
141
|
}
|
|
142
142
|
static parse(e = []) {
|
|
143
143
|
return e.map((t) => new v(t));
|
|
144
144
|
}
|
|
145
145
|
static toDsl(e = []) {
|
|
146
146
|
return e.map((t) => {
|
|
147
|
-
const { name: i, arg: s, modifiers: a, value:
|
|
147
|
+
const { name: i, arg: s, modifiers: a, value: r, iterator: o, id: c } = t;
|
|
148
148
|
return {
|
|
149
149
|
id: c,
|
|
150
150
|
name: i,
|
|
151
151
|
arg: s,
|
|
152
152
|
modifiers: a,
|
|
153
|
-
value:
|
|
154
|
-
iterator:
|
|
153
|
+
value: r,
|
|
154
|
+
iterator: o
|
|
155
155
|
};
|
|
156
156
|
});
|
|
157
157
|
}
|
|
@@ -225,12 +225,12 @@ class _ {
|
|
|
225
225
|
invisible: i = !1,
|
|
226
226
|
locked: s = !1,
|
|
227
227
|
children: a = [],
|
|
228
|
-
slot:
|
|
229
|
-
props:
|
|
228
|
+
slot: r,
|
|
229
|
+
props: o = {},
|
|
230
230
|
events: c = {},
|
|
231
231
|
directives: p = []
|
|
232
232
|
} = e;
|
|
233
|
-
this.invisible = i, this.locked = s, this.setChildren(a, !0), this.setSlot(
|
|
233
|
+
this.invisible = i, this.locked = s, this.setChildren(a, !0), this.setSlot(r, !0), this.props = A.parse(o), this.events = N.parse(c), this.directives = v.parse(p), t || n.emit(h, this);
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
236
|
* 设置子节点
|
|
@@ -257,7 +257,7 @@ class _ {
|
|
|
257
257
|
*/
|
|
258
258
|
setProp(e, t, i, s = !1) {
|
|
259
259
|
const a = this.props[e];
|
|
260
|
-
a ? a.setValue(t) : this.props[e] = new
|
|
260
|
+
a ? a.setValue(t) : this.props[e] = new A(e, t, i), s || n.emit(h, this);
|
|
261
261
|
}
|
|
262
262
|
/**
|
|
263
263
|
* 删除属性
|
|
@@ -284,7 +284,7 @@ class _ {
|
|
|
284
284
|
*/
|
|
285
285
|
setEvent(e, t = !1) {
|
|
286
286
|
const i = this.events[e.name];
|
|
287
|
-
i ? i.update(e) : this.events[e.name] = new
|
|
287
|
+
i ? i.update(e) : this.events[e.name] = new N(e), t || n.emit(h, this);
|
|
288
288
|
}
|
|
289
289
|
/**
|
|
290
290
|
* 删除事件
|
|
@@ -323,7 +323,7 @@ class _ {
|
|
|
323
323
|
removeChild(e, t = !1) {
|
|
324
324
|
const { children: i, disposed: s } = this;
|
|
325
325
|
if (s || !Array.isArray(i)) return;
|
|
326
|
-
const a = i.findIndex((
|
|
326
|
+
const a = i.findIndex((r) => r === e);
|
|
327
327
|
e.parent = null, i.splice(a, 1), t || n.emit(h, this);
|
|
328
328
|
}
|
|
329
329
|
/**
|
|
@@ -395,23 +395,23 @@ class _ {
|
|
|
395
395
|
from: i,
|
|
396
396
|
invisible: s,
|
|
397
397
|
locked: a,
|
|
398
|
-
slot:
|
|
399
|
-
children:
|
|
398
|
+
slot: r,
|
|
399
|
+
children: o,
|
|
400
400
|
props: c,
|
|
401
401
|
directives: p,
|
|
402
|
-
events:
|
|
403
|
-
} = this, E = Array.isArray(
|
|
402
|
+
events: P
|
|
403
|
+
} = this, E = Array.isArray(o) ? o.map((U) => U.toDsl()) : o;
|
|
404
404
|
return {
|
|
405
405
|
id: e,
|
|
406
406
|
name: t,
|
|
407
407
|
from: i,
|
|
408
408
|
invisible: s,
|
|
409
409
|
locked: a,
|
|
410
|
-
slot:
|
|
410
|
+
slot: r,
|
|
411
411
|
children: E,
|
|
412
|
-
props:
|
|
412
|
+
props: A.toDsl(c),
|
|
413
413
|
directives: v.toDsl(p),
|
|
414
|
-
events:
|
|
414
|
+
events: N.toDsl(P)
|
|
415
415
|
};
|
|
416
416
|
}
|
|
417
417
|
/**
|
|
@@ -511,13 +511,13 @@ class u {
|
|
|
511
511
|
const { __VTJ_BLOCK__: t, id: i, nodes: s } = this;
|
|
512
512
|
return {
|
|
513
513
|
...u.normalAttrs.reduce(
|
|
514
|
-
(
|
|
514
|
+
(r, o) => (r[o] = this[o], r),
|
|
515
515
|
{}
|
|
516
516
|
),
|
|
517
517
|
__VTJ_BLOCK__: t,
|
|
518
518
|
__VERSION__: e || G().toString(),
|
|
519
519
|
id: i,
|
|
520
|
-
nodes: s.map((
|
|
520
|
+
nodes: s.map((r) => r.toDsl())
|
|
521
521
|
};
|
|
522
522
|
}
|
|
523
523
|
/**
|
|
@@ -621,7 +621,7 @@ class u {
|
|
|
621
621
|
* @param silent
|
|
622
622
|
*/
|
|
623
623
|
setEmit(e, t = !1) {
|
|
624
|
-
const i =
|
|
624
|
+
const i = C(e) ? { name: e, params: [] } : e, s = this.emits.findIndex(
|
|
625
625
|
(a) => a === i.name || a.name === i.name
|
|
626
626
|
);
|
|
627
627
|
s > -1 ? this.emits.splice(s, 1, i) : this.emits.push(i), t || n.emit(l, this);
|
|
@@ -633,7 +633,7 @@ class u {
|
|
|
633
633
|
*/
|
|
634
634
|
removeEmit(e, t = !1) {
|
|
635
635
|
const i = this.emits.findIndex(
|
|
636
|
-
(s) =>
|
|
636
|
+
(s) => C(s) ? s === e : s.name === e
|
|
637
637
|
);
|
|
638
638
|
i > -1 && (this.emits.splice(i, 1), t || n.emit(l, this));
|
|
639
639
|
}
|
|
@@ -646,7 +646,7 @@ class u {
|
|
|
646
646
|
* @param silent
|
|
647
647
|
*/
|
|
648
648
|
setSlot(e, t = !1) {
|
|
649
|
-
const i =
|
|
649
|
+
const i = C(e) ? { name: e, params: [] } : e, s = this.slots.findIndex(
|
|
650
650
|
(a) => a === i.name || a.name === i.name
|
|
651
651
|
);
|
|
652
652
|
s > -1 ? this.slots.splice(s, 1, i) : this.slots.push(i), t || n.emit(l, this);
|
|
@@ -658,7 +658,7 @@ class u {
|
|
|
658
658
|
*/
|
|
659
659
|
removeSlot(e, t = !1) {
|
|
660
660
|
const i = this.slots.findIndex(
|
|
661
|
-
(s) =>
|
|
661
|
+
(s) => C(s) ? s === e : s.name === e
|
|
662
662
|
);
|
|
663
663
|
i > -1 && (this.slots.splice(i, 1), t || n.emit(l, this));
|
|
664
664
|
}
|
|
@@ -800,7 +800,7 @@ class u {
|
|
|
800
800
|
return t;
|
|
801
801
|
}
|
|
802
802
|
}
|
|
803
|
-
const d = "EVENT_PROJECT_CHANGE", D = "EVENT_PROJECT_ACTIVED", B = "EVENT_PROJECT_DEPS_CHANGE",
|
|
803
|
+
const d = "EVENT_PROJECT_CHANGE", D = "EVENT_PROJECT_ACTIVED", B = "EVENT_PROJECT_DEPS_CHANGE", g = "EVENT_PROJECT_PAGES_CHANGE", y = "EVENT_PROJECT_BLOCKS_CHANGE", V = "EVENT_PROJECT_APIS_CHANGE", w = "EVENT_PROJECT_META_CHANGE", $ = "EVENT_PROJECT_PUBLISH", M = "EVENT_PROJECT_FILE_PUBLISH", K = "EVENT_PROJECT_GEN_SOURCE";
|
|
804
804
|
class S {
|
|
805
805
|
id = "";
|
|
806
806
|
locked = "";
|
|
@@ -871,10 +871,10 @@ class S {
|
|
|
871
871
|
(s, a) => (s[a] = this[a], s),
|
|
872
872
|
{}
|
|
873
873
|
);
|
|
874
|
-
return i.pages && (i.pages = i.pages.map((s) =>
|
|
874
|
+
return i.pages && (i.pages = i.pages.map((s) => T({
|
|
875
875
|
...s,
|
|
876
876
|
dsl: void 0
|
|
877
|
-
})), this.cleanPagesDsl(i.pages)), i.blocks && (i.blocks = i.blocks.map((s) =>
|
|
877
|
+
})), this.cleanPagesDsl(i.pages)), i.blocks && (i.blocks = i.blocks.map((s) => T({
|
|
878
878
|
...s,
|
|
879
879
|
dsl: void 0
|
|
880
880
|
}))), {
|
|
@@ -912,18 +912,18 @@ class S {
|
|
|
912
912
|
* @param silent
|
|
913
913
|
*/
|
|
914
914
|
setDeps(e, t = !1) {
|
|
915
|
-
const i = this.dependencies, s = i.findIndex((
|
|
915
|
+
const i = this.dependencies, s = i.findIndex((r) => r.package === e.package);
|
|
916
916
|
let a;
|
|
917
917
|
if (s > -1 ? (a = "update", i.splice(s, 1, {
|
|
918
918
|
...i[s],
|
|
919
919
|
...e
|
|
920
920
|
})) : (a = "create", i.push(e)), !t) {
|
|
921
|
-
const
|
|
921
|
+
const r = {
|
|
922
922
|
model: this,
|
|
923
923
|
type: a,
|
|
924
924
|
data: e
|
|
925
925
|
};
|
|
926
|
-
n.emit(B,
|
|
926
|
+
n.emit(B, r), n.emit(d, r);
|
|
927
927
|
}
|
|
928
928
|
}
|
|
929
929
|
/**
|
|
@@ -953,9 +953,9 @@ class S {
|
|
|
953
953
|
if (a.id === i)
|
|
954
954
|
return a;
|
|
955
955
|
if (a.children && a.children.length) {
|
|
956
|
-
const
|
|
957
|
-
if (
|
|
958
|
-
return
|
|
956
|
+
const r = t(i, a.children);
|
|
957
|
+
if (r)
|
|
958
|
+
return r;
|
|
959
959
|
}
|
|
960
960
|
}
|
|
961
961
|
};
|
|
@@ -995,9 +995,9 @@ class S {
|
|
|
995
995
|
type: "create",
|
|
996
996
|
data: e
|
|
997
997
|
};
|
|
998
|
-
n.emit(
|
|
998
|
+
n.emit(g, s), n.emit(d, s);
|
|
999
999
|
}
|
|
1000
|
-
return !this.currentFile && !e.dir && (await
|
|
1000
|
+
return !this.currentFile && !e.dir && (await O(1e3), this.active(e, i)), e;
|
|
1001
1001
|
}
|
|
1002
1002
|
/**
|
|
1003
1003
|
* 更新页面
|
|
@@ -1012,10 +1012,44 @@ class S {
|
|
|
1012
1012
|
type: "update",
|
|
1013
1013
|
data: e
|
|
1014
1014
|
};
|
|
1015
|
-
n.emit(
|
|
1015
|
+
n.emit(g, s), n.emit(d, s);
|
|
1016
1016
|
}
|
|
1017
1017
|
return i;
|
|
1018
1018
|
}
|
|
1019
|
+
findParent(e) {
|
|
1020
|
+
const t = (i, s = [], a) => {
|
|
1021
|
+
for (const r of s) {
|
|
1022
|
+
if (r.id === i)
|
|
1023
|
+
return a;
|
|
1024
|
+
if (r.children && r.children.length) {
|
|
1025
|
+
const o = t(i, r.children, r);
|
|
1026
|
+
if (o)
|
|
1027
|
+
return o;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
return t(e, this.pages);
|
|
1032
|
+
}
|
|
1033
|
+
movePageTo(e, t, i = !1) {
|
|
1034
|
+
const s = t ? this.getPage(t) : null, a = this.getPage(e);
|
|
1035
|
+
if (!a) return !1;
|
|
1036
|
+
const r = this.findParent(e);
|
|
1037
|
+
if (r ? r.children = r.children?.filter(
|
|
1038
|
+
(o) => o.id !== e
|
|
1039
|
+
) : this.pages = this.pages.filter((o) => o.id !== e), s ? (s.dir || s.layout) && (s.children ? s.children.push(a) : s.children = [a]) : this.pages.push(a), !i) {
|
|
1040
|
+
const o = {
|
|
1041
|
+
model: this,
|
|
1042
|
+
type: "update",
|
|
1043
|
+
data: a
|
|
1044
|
+
};
|
|
1045
|
+
n.emit(g, o), n.emit(d, o);
|
|
1046
|
+
}
|
|
1047
|
+
return !0;
|
|
1048
|
+
}
|
|
1049
|
+
getPageTree() {
|
|
1050
|
+
const e = T(this.pages);
|
|
1051
|
+
return this.cleanPagesDsl(e), e;
|
|
1052
|
+
}
|
|
1019
1053
|
/**
|
|
1020
1054
|
* 复制页面
|
|
1021
1055
|
* @param page
|
|
@@ -1023,11 +1057,11 @@ class S {
|
|
|
1023
1057
|
* @param silent
|
|
1024
1058
|
*/
|
|
1025
1059
|
clonePage(e, t, i = !1) {
|
|
1026
|
-
const s = m(), a = `${e.name}Copy`,
|
|
1060
|
+
const s = m(), a = `${e.name}Copy`, r = `${e.title}_副本`, o = new u({
|
|
1027
1061
|
id: s,
|
|
1028
1062
|
name: a
|
|
1029
|
-
}).toDsl(), c = I({}, e, { id: s, name: a, title:
|
|
1030
|
-
if (p.splice(
|
|
1063
|
+
}).toDsl(), c = I({}, e, { id: s, name: a, title: r, dsl: o }), p = t ? this.getPage(t)?.children || [] : this.pages, P = p.findIndex((E) => E.id === e.id);
|
|
1064
|
+
if (p.splice(P + 1, 0, c), !i) {
|
|
1031
1065
|
const E = {
|
|
1032
1066
|
model: this,
|
|
1033
1067
|
type: "clone",
|
|
@@ -1036,28 +1070,28 @@ class S {
|
|
|
1036
1070
|
target: c
|
|
1037
1071
|
}
|
|
1038
1072
|
};
|
|
1039
|
-
n.emit(
|
|
1073
|
+
n.emit(g, E), n.emit(d, E);
|
|
1040
1074
|
}
|
|
1041
1075
|
}
|
|
1042
1076
|
async saveToBlock(e, t = !1) {
|
|
1043
|
-
this.active(e, t), await
|
|
1044
|
-
const i = m(), s = e.name, a = e.title,
|
|
1077
|
+
this.active(e, t), await O(1e3);
|
|
1078
|
+
const i = m(), s = e.name, a = e.title, r = new u({
|
|
1045
1079
|
...e.dsl,
|
|
1046
1080
|
id: i,
|
|
1047
1081
|
name: s
|
|
1048
|
-
}).toDsl(),
|
|
1082
|
+
}).toDsl(), o = I({}, e, {
|
|
1049
1083
|
id: i,
|
|
1050
1084
|
name: s,
|
|
1051
1085
|
title: a,
|
|
1052
|
-
dsl:
|
|
1086
|
+
dsl: r,
|
|
1053
1087
|
type: "block",
|
|
1054
1088
|
fromType: "Schema"
|
|
1055
1089
|
});
|
|
1056
|
-
if (this.blocks.push(
|
|
1090
|
+
if (this.blocks.push(o), !t) {
|
|
1057
1091
|
const c = {
|
|
1058
1092
|
model: this,
|
|
1059
1093
|
type: "create",
|
|
1060
|
-
data:
|
|
1094
|
+
data: o
|
|
1061
1095
|
};
|
|
1062
1096
|
n.emit(y, c), n.emit(d, c);
|
|
1063
1097
|
}
|
|
@@ -1068,13 +1102,13 @@ class S {
|
|
|
1068
1102
|
* @param silent
|
|
1069
1103
|
*/
|
|
1070
1104
|
removePage(e, t = !1) {
|
|
1071
|
-
const i = this.getPage(e), s = (a,
|
|
1072
|
-
const
|
|
1073
|
-
if (
|
|
1074
|
-
|
|
1105
|
+
const i = this.getPage(e), s = (a, r) => {
|
|
1106
|
+
const o = r.findIndex((c) => c.id === a);
|
|
1107
|
+
if (o >= 0) {
|
|
1108
|
+
r.splice(o, 1);
|
|
1075
1109
|
return;
|
|
1076
1110
|
}
|
|
1077
|
-
for (const c of
|
|
1111
|
+
for (const c of r)
|
|
1078
1112
|
c.children && c.children.length && s(a, c.children);
|
|
1079
1113
|
};
|
|
1080
1114
|
if (s(e, this.pages), e === this.homepage && (this.homepage = ""), this.currentFile?.id === e && this.deactivate(t), !t) {
|
|
@@ -1083,7 +1117,7 @@ class S {
|
|
|
1083
1117
|
type: "delete",
|
|
1084
1118
|
data: i
|
|
1085
1119
|
};
|
|
1086
|
-
n.emit(
|
|
1120
|
+
n.emit(g, a), n.emit(d, a);
|
|
1087
1121
|
}
|
|
1088
1122
|
}
|
|
1089
1123
|
/**
|
|
@@ -1107,14 +1141,14 @@ class S {
|
|
|
1107
1141
|
e.id = i, e.type = "block", e.dsl = new u({ id: i, name: s }).toDsl(), this.blocks.push(e);
|
|
1108
1142
|
const a = e.fromType || "Schema";
|
|
1109
1143
|
if (!t) {
|
|
1110
|
-
const
|
|
1144
|
+
const r = {
|
|
1111
1145
|
model: this,
|
|
1112
1146
|
type: "create",
|
|
1113
1147
|
data: e
|
|
1114
1148
|
};
|
|
1115
|
-
n.emit(y,
|
|
1149
|
+
n.emit(y, r), n.emit(d, r);
|
|
1116
1150
|
}
|
|
1117
|
-
return !this.currentFile && a === "Schema" && (await
|
|
1151
|
+
return !this.currentFile && a === "Schema" && (await O(1e3), this.active(e, t)), e;
|
|
1118
1152
|
}
|
|
1119
1153
|
/**
|
|
1120
1154
|
*
|
|
@@ -1134,17 +1168,17 @@ class S {
|
|
|
1134
1168
|
return i;
|
|
1135
1169
|
}
|
|
1136
1170
|
cloneBlock(e, t = !1) {
|
|
1137
|
-
const i = m(), s = `${e.name}Copy`, a = `${e.title}_副本`,
|
|
1171
|
+
const i = m(), s = `${e.name}Copy`, a = `${e.title}_副本`, r = new u({
|
|
1138
1172
|
id: i,
|
|
1139
1173
|
name: s
|
|
1140
|
-
}).toDsl(),
|
|
1141
|
-
if (this.blocks.splice(c + 1, 0,
|
|
1174
|
+
}).toDsl(), o = I({}, e, { id: i, name: s, title: a, dsl: r }), c = this.blocks.findIndex((p) => p.id === e.id);
|
|
1175
|
+
if (this.blocks.splice(c + 1, 0, o), !t) {
|
|
1142
1176
|
const p = {
|
|
1143
1177
|
model: this,
|
|
1144
1178
|
type: "clone",
|
|
1145
1179
|
data: {
|
|
1146
1180
|
source: e,
|
|
1147
|
-
target:
|
|
1181
|
+
target: o
|
|
1148
1182
|
}
|
|
1149
1183
|
};
|
|
1150
1184
|
n.emit(y, p), n.emit(d, p);
|
|
@@ -1156,14 +1190,14 @@ class S {
|
|
|
1156
1190
|
* @param silent
|
|
1157
1191
|
*/
|
|
1158
1192
|
removeBlock(e, t = !1) {
|
|
1159
|
-
const i = this.getBlock(e), s = this.blocks, a = s.findIndex((
|
|
1193
|
+
const i = this.getBlock(e), s = this.blocks, a = s.findIndex((r) => r.id === e);
|
|
1160
1194
|
if (a > -1 ? (s.splice(a, 1), this.currentFile?.id === e && this.deactivate(t)) : console.warn(`not found PageFile for id: ${e} `), !t) {
|
|
1161
|
-
const
|
|
1195
|
+
const r = {
|
|
1162
1196
|
model: this,
|
|
1163
1197
|
type: "delete",
|
|
1164
1198
|
data: i
|
|
1165
1199
|
};
|
|
1166
|
-
n.emit(y,
|
|
1200
|
+
n.emit(y, r), n.emit(d, r);
|
|
1167
1201
|
}
|
|
1168
1202
|
}
|
|
1169
1203
|
/**
|
|
@@ -1360,17 +1394,17 @@ class S {
|
|
|
1360
1394
|
n.emit(d, t);
|
|
1361
1395
|
}
|
|
1362
1396
|
getPageRoutes(e, t) {
|
|
1363
|
-
const i = this.platform === "uniapp", s = e || (i ? "pages" : "page"), a = this.getPages(),
|
|
1364
|
-
return a.map((
|
|
1365
|
-
id:
|
|
1366
|
-
path: `${
|
|
1367
|
-
name:
|
|
1368
|
-
title:
|
|
1369
|
-
meta:
|
|
1397
|
+
const i = this.platform === "uniapp", s = e || (i ? "pages" : "page"), a = this.getPages(), r = t || "";
|
|
1398
|
+
return a.map((o) => ({
|
|
1399
|
+
id: o.id,
|
|
1400
|
+
path: `${r}/${s}/${o.id}`,
|
|
1401
|
+
name: o.name,
|
|
1402
|
+
title: o.title,
|
|
1403
|
+
meta: o.meta
|
|
1370
1404
|
}));
|
|
1371
1405
|
}
|
|
1372
1406
|
}
|
|
1373
|
-
const
|
|
1407
|
+
const x = "EVENT_HISTORY_CHANGE", k = "EVENT_HISTORY_LOAD";
|
|
1374
1408
|
class se {
|
|
1375
1409
|
options = { max: 50 };
|
|
1376
1410
|
index = -1;
|
|
@@ -1410,19 +1444,19 @@ class se {
|
|
|
1410
1444
|
id: m(),
|
|
1411
1445
|
label: (/* @__PURE__ */ new Date()).toLocaleString(),
|
|
1412
1446
|
remark: t,
|
|
1413
|
-
dsl:
|
|
1447
|
+
dsl: T(e)
|
|
1414
1448
|
};
|
|
1415
1449
|
this.items.unshift(a);
|
|
1416
|
-
const
|
|
1417
|
-
if (
|
|
1418
|
-
const
|
|
1419
|
-
this.items = this.items.filter((c) => !
|
|
1450
|
+
const r = this.items.filter((o) => !o.remark);
|
|
1451
|
+
if (r.length > s) {
|
|
1452
|
+
const o = r.splice(s).map((c) => c.id);
|
|
1453
|
+
this.items = this.items.filter((c) => !o.includes(c.id)), i || n.emit(x, {
|
|
1420
1454
|
model: this,
|
|
1421
1455
|
type: "delete",
|
|
1422
|
-
data:
|
|
1456
|
+
data: o
|
|
1423
1457
|
});
|
|
1424
1458
|
}
|
|
1425
|
-
this.index = -1, i || n.emit(
|
|
1459
|
+
this.index = -1, i || n.emit(x, {
|
|
1426
1460
|
model: this,
|
|
1427
1461
|
type: "create",
|
|
1428
1462
|
data: a
|
|
@@ -1436,7 +1470,7 @@ class se {
|
|
|
1436
1470
|
*/
|
|
1437
1471
|
update(e, t = !1) {
|
|
1438
1472
|
const i = this.items.find((s) => s.id === e.id);
|
|
1439
|
-
i && Object.assign(i, e), t || n.emit(
|
|
1473
|
+
i && Object.assign(i, e), t || n.emit(x, {
|
|
1440
1474
|
model: this,
|
|
1441
1475
|
type: "update",
|
|
1442
1476
|
data: i
|
|
@@ -1450,10 +1484,10 @@ class se {
|
|
|
1450
1484
|
remove(e, t = !1) {
|
|
1451
1485
|
const i = j(e);
|
|
1452
1486
|
for (const s of i) {
|
|
1453
|
-
const a = this.items.findIndex((
|
|
1487
|
+
const a = this.items.findIndex((r) => r.id === s);
|
|
1454
1488
|
a > -1 ? (this.items.splice(a, 1), a === this.index ? this.index = -1 : this.index >= this.items.length && (this.index = this.items.length - 1)) : console.warn(`not found HistoryItem for id: ${e} `);
|
|
1455
1489
|
}
|
|
1456
|
-
t || n.emit(
|
|
1490
|
+
t || n.emit(x, {
|
|
1457
1491
|
model: this,
|
|
1458
1492
|
type: "delete",
|
|
1459
1493
|
data: i
|
|
@@ -1492,7 +1526,7 @@ class se {
|
|
|
1492
1526
|
clear(e = !1) {
|
|
1493
1527
|
this.index = -1;
|
|
1494
1528
|
const t = this.items.map((i) => i.id);
|
|
1495
|
-
this.items = [], e || n.emit(
|
|
1529
|
+
this.items = [], e || n.emit(x, {
|
|
1496
1530
|
model: this,
|
|
1497
1531
|
type: "clear",
|
|
1498
1532
|
data: t
|
|
@@ -1506,14 +1540,14 @@ function ne(f) {
|
|
|
1506
1540
|
function ae(f) {
|
|
1507
1541
|
return f instanceof _;
|
|
1508
1542
|
}
|
|
1509
|
-
function
|
|
1543
|
+
function re(f) {
|
|
1510
1544
|
return !!f.__VTJ_BLOCK__;
|
|
1511
1545
|
}
|
|
1512
1546
|
function J(f) {
|
|
1513
|
-
const e =
|
|
1547
|
+
const e = T(f);
|
|
1514
1548
|
return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) => J(t))), e;
|
|
1515
1549
|
}
|
|
1516
|
-
function
|
|
1550
|
+
function oe(f) {
|
|
1517
1551
|
const e = f.fromType || "Schema";
|
|
1518
1552
|
return e === "Schema" ? {
|
|
1519
1553
|
type: "Schema",
|
|
@@ -1539,7 +1573,7 @@ export {
|
|
|
1539
1573
|
u as BlockModel,
|
|
1540
1574
|
v as DirectiveModel,
|
|
1541
1575
|
l as EVENT_BLOCK_CHANGE,
|
|
1542
|
-
|
|
1576
|
+
x as EVENT_HISTORY_CHANGE,
|
|
1543
1577
|
k as EVENT_HISTORY_LOAD,
|
|
1544
1578
|
h as EVENT_NODE_CHANGE,
|
|
1545
1579
|
D as EVENT_PROJECT_ACTIVED,
|
|
@@ -1550,20 +1584,20 @@ export {
|
|
|
1550
1584
|
M as EVENT_PROJECT_FILE_PUBLISH,
|
|
1551
1585
|
K as EVENT_PROJECT_GEN_SOURCE,
|
|
1552
1586
|
w as EVENT_PROJECT_META_CHANGE,
|
|
1553
|
-
|
|
1587
|
+
g as EVENT_PROJECT_PAGES_CHANGE,
|
|
1554
1588
|
$ as EVENT_PROJECT_PUBLISH,
|
|
1555
|
-
|
|
1589
|
+
N as EventModel,
|
|
1556
1590
|
se as HistoryModel,
|
|
1557
1591
|
ee as I18N_LOCALES,
|
|
1558
1592
|
_ as NodeModel,
|
|
1559
1593
|
S as ProjectModel,
|
|
1560
|
-
|
|
1594
|
+
A as PropModel,
|
|
1561
1595
|
te as Service,
|
|
1562
1596
|
z as VTJ_CORE_VERSION,
|
|
1563
1597
|
J as cloneDsl,
|
|
1564
|
-
|
|
1598
|
+
oe as createNodeFrom,
|
|
1565
1599
|
n as emitter,
|
|
1566
1600
|
ne as isBlock,
|
|
1567
|
-
|
|
1601
|
+
re as isBlockSchema,
|
|
1568
1602
|
ae as isNode
|
|
1569
1603
|
};
|
package/package.json
CHANGED
|
@@ -118,6 +118,9 @@ export declare class ProjectModel {
|
|
|
118
118
|
* @param silent
|
|
119
119
|
*/
|
|
120
120
|
updatePage(page: PageFile, silent?: boolean): PageFile | undefined;
|
|
121
|
+
findParent(id: string): PageFile | undefined;
|
|
122
|
+
movePageTo(pageId: string, parentId?: string, silent?: boolean): boolean;
|
|
123
|
+
getPageTree(): PageFile[];
|
|
121
124
|
/**
|
|
122
125
|
* 复制页面
|
|
123
126
|
* @param page
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.
|
|
5
|
+
* @version 0.16.1
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.
|
|
8
|
+
export declare const version = "0.16.1";
|