@vtj/core 0.9.0-alpha.2 → 0.9.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@vtj/base");/**!
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@vtj/base");/**!
2
2
  * Copyright (c) 2024, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/core
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.9.0-alpha.2
5
+ * @version 0.9.0-alpha.4
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const b="0.9.0-alpha.2",J="BuiltIn",R="VueMaterial",B="VueRouterMaterial",G=[R,B],w={vue:"Vue","vue-router":"VueRouter"},U={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[B]:["RouterView","RouterLink"]},F=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class M{}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 N{constructor(e,t,i){this.name=e,this.value=t,this.defaultValue=i,this.setValue(t)}isUnset=!1;setValue(e){this.value=e,this.isUnset=this.value===this.defaultValue}getValue(){return this.value??this.defaultValue}static toDsl(e={}){return Object.entries(e).reduce((t,[i,s])=>(s.isUnset||(t[i]=s.getValue()),t),{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new N(i,s),t),{})}}class v{constructor(e){this.schema=e;const{name:t,handler:i}=this.schema;this.name=t,this.handler=i,this.update(e)}name;handler;modifiers={};update(e){Object.assign(this.schema,e);const{handler:t,modifiers:i={}}=this.schema;this.handler=t,this.modifiers=i}static toDsl(e){return Object.entries(e).reduce((t,[i,s])=>{const{handler:r,modifiers:a}=s;return t[i]={name:i,handler:r,modifiers:a},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new v(s),t),{})}}class _{constructor(e){this.schema=e,this.id=e.id||d.uid(),this.update(e)}id;name="";arg;modifiers;value;iterator;update(e){Object.assign(this.schema,e);const{name:t,arg:i,modifiers:s,value:r,iterator:a}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=r,this.iterator=a}static parse(e=[]){return e.map(t=>new _(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:r,value:a,iterator:c,id:m}=t;return{id:m,name:i,arg:s,modifiers:r,value:a,iterator:c}})}}const l="EVENT_NODE_CHANGE";class E{constructor(e,t=null){this.parent=t;const{id:i=d.uid(),name:s,from:r=""}=e;this.id=i,this.name=s,this.from=r,this.update(e,!0),E.nodes[this.id]=this}__VTJ_NODE__=!0;locked=!1;static nodes={};id;name;from;invisible=!1;children="";slot;props={};events={};directives=[];disposed=!1;update(e,t=!1){const{invisible:i=!1,locked:s=!1,children:r=[],slot:a,props:c={},events:m={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(a,!0),this.props=N.parse(c),this.events=v.parse(m),this.directives=_.parse(p),t||n.emit(l,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new E(i,this)):this.children=e,t||n.emit(l,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(l,this)}setProp(e,t,i,s=!1){const r=this.props[e];r?r.setValue(t):this.props[e]=new N(e,t,i),s||n.emit(l,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(l,this)}getPropValue(e){const t=this.props[e];if(t)return t.getValue()}setEvent(e,t=!1){const i=this.events[e.name];i?i.update(e):this.events[e.name]=new v(e),t||n.emit(l,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(l,this)}setDirective(e,t=!1){const i=this.directives.findIndex(s=>s.id===e.id);i>=0?this.directives.splice(i,1,new _(e)):this.directives.push(new _(e)),t||n.emit(l,this)}removeDirective(e,t=!1){const i=this.directives.findIndex(s=>s===e||s.id===e.id);i>=0&&this.directives.splice(i,1),t||n.emit(l,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const r=i.findIndex(a=>a===e);e.parent=null,i.splice(r,1),t||n.emit(l,this)}appendChild(e,t=!1){const{children:i,disposed:s}=this;s||(e.parent=this,Array.isArray(i)?i.push(e):this.children=[e],t||n.emit(l,this))}insertAfter(e,t=!1){if(!this.parent)return;const i=this.parent.children;if(Array.isArray(i)){e.parent=this.parent;const s=i.indexOf(this);i.splice(s+1,0,e),t||n.emit(l,this.parent)}}insertBefore(e,t=!1){if(!this.parent)return;const i=this.parent.children;if(Array.isArray(i)){e.parent=this.parent;const s=i.indexOf(this);i.splice(s,0,e),t||n.emit(l,this.parent)}}movePrev(e=!1){const t=this.parent;if(!t)return;const i=t.children;if(Array.isArray(i)){const s=i.indexOf(this);s>0&&(i.splice(s,1),i.splice(s-1,0,this),e||n.emit(l,t))}}moveNext(e=!1){const t=this.parent;if(!t)return;const i=t.children;if(Array.isArray(i)){const s=i.indexOf(this);s>-1&&s<i.length-1&&(i.splice(s,1),i.splice(s+1,0,this),e||n.emit(l,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:c,props:m,directives:p,events:I}=this,T=Array.isArray(c)?c.map(k=>k.toDsl()):c;return{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:T,props:N.toDsl(m),directives:_.toDsl(p),events:v.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(l,this),this.parent=null,this.disposed=!0,delete E.nodes[this.id])}lock(e=!1){if(this.locked=!0,Array.isArray(this.children))for(const t of this.children)t.lock(!0);e||n.emit(l,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(l,this)}setVisible(e,t=!1){if(this.invisible=!e,Array.isArray(this.children))for(const i of this.children)i.setVisible(e,!0);t||n.emit(l,this)}isChild(e){let t=!1;if(Array.isArray(this.children)){for(const i of this.children)if(e===i||e.id===i.id){t=!0;break}else if(t=i.isChild(e),t)break}return t}}const o="EVENT_BLOCK_CHANGE";class u{__VTJ_BLOCK__=!0;id;name="";inject=[];state={};lifeCycles={};methods={};computed={};watch=[];css="";props=[];emits=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","inject","state","lifeCycles","methods","computed","watch","css","props","emits","slots","dataSources","__TEMPLATE_ID__"];constructor(e){const{id:t}=e;this.id=t||d.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 E(s))),t||n.emit(o,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((a,c)=>(a[c]=this[c],a),{}),__VTJ_BLOCK__:t,__VERSION__:e||d.timestamp().toString(),id:i,nodes:s.map(a=>a.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}setFunction(e,t,i,s=!1){this[e][t]=i,s||n.emit(o,this)}removeFunction(e,t,i=!1){delete this[e][t],i||n.emit(o,this)}setState(e,t,i=!1){this.state[e]=t,i||n.emit(o,this)}removeState(e,t=!1){delete this.state[e],t||n.emit(o,this)}setCss(e,t=!1){this.css=e,t||n.emit(o,this)}setWatch(e,t=!1){e.id=e.id||d.uid();const i=this.watch.findIndex(s=>s.id&&s.id===e.id||s===e);i>-1?this.watch.splice(i,1,e):this.watch.push(e),t||n.emit(o,this)}removeWatch(e,t=!1){const i=this.watch.findIndex(s=>s.id&&s.id===e.id||s===e);i>-1&&(this.watch.splice(i,1),t||n.emit(o,this))}setProp(e,t=!1){const i=this.props.findIndex(s=>typeof s=="string"?s===e.name:s.name===e.name);i>-1?this.props.splice(i,1,e):this.props.push(e),t||n.emit(o,this)}removeProp(e,t=!1){const i=this.props.findIndex(s=>typeof s=="string"?s===e.name:s.name===e.name);i>-1&&(this.props.splice(i,1),t||n.emit(o,this))}setEmit(e,t=!1){const i=d.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(r=>r===i.name||r===i);s>-1?this.emits.splice(s,1,i):this.emits.push(i),t||n.emit(o,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>d.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||n.emit(o,this))}setSlot(e,t=!1){const i=d.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(r=>r===i.name||r===i);s>-1?this.slots.splice(s,1,i):this.slots.push(i),t||n.emit(o,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>d.isString(s)?s===e:s.name===e);i>-1&&(this.slots.splice(i,1),t||n.emit(o,this))}setInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1?this.inject.splice(i,1,e):this.inject.push(e),t||n.emit(o,this)}removeInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1&&(this.inject.splice(i,1),t||n.emit(o,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||n.emit(o,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||n.emit(o,this)}insertAfter(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s+1,0,e),i||n.emit(o,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||n.emit(o,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||n.emit(o,this)}addNode(e,t,i="inner",s=!1){t?["left","top"].includes(i)?t.parent?t.insertAfter(e,s):this.insertBefore(e,t,s):["right","bottom"].includes(i)?t.parent?t.insertAfter(e,s):this.insertAfter(e,t,s):t.appendChild(e,s):this.appendNode(e,s)}__removeNode(e,t=!1){const i=this.nodes.findIndex(s=>s.id===e.id);i>-1&&(this.nodes.splice(i,1),t||n.emit(o,this))}removeNode(e,t=!1){e.parent?e.dispose(t):(e.dispose(!0),this.__removeNode(e,t))}move(e,t,i="inner",s=!1){e.parent?e.parent.removeChild(e,!0):this.__removeNode(e,!0),this.addNode(e,t,i,s)}movePrev(e,t=!1){if(e.parent)e.movePrev(t);else{const i=this.nodes,s=i.indexOf(e);s>0&&(i.splice(s,1),i.splice(s-1,0,e),t||n.emit(o,this))}}moveNext(e,t=!1){if(e.parent)e.moveNext(t);else{const i=this.nodes,s=i.indexOf(e);s>-1&&s<i.length-1&&(i.splice(s,1),i.splice(s+1,0,e),t||n.emit(o,this))}}cloneNode(e,t=!1){const i=D(e.toDsl()),s=new E(i);return this.addNode(s,e,"bottom",t),s}lock(e=!1){this.locked=!0;for(const t of this.nodes)t.lock(!0);e||n.emit(o,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||n.emit(o,this)}isChild(e){let t=!1;for(const i of this.nodes)if(e===i||e.id===i.id){t=!0;break}else if(t=i.isChild(e),t)break;return t}}const h="EVENT_PROJECT_CHANGE",g="EVENT_PROJECT_ACTIVED",O="EVENT_PROJECT_DEPS_CHANGE",A="EVENT_PROJECT_PAGES_CHANGE",y="EVENT_PROJECT_BLOCKS_CHANGE",V="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",H="EVENT_PROJECT_PUBLISH",L="EVENT_PROJECT_FILE_PUBLISH";class P{id="";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};__BASE_PATH__="/";static attrs=["name","homepage","description","dependencies","pages","blocks","apis","meta","config","__BASE_PATH__"];constructor(e){const{id:t}=e;this.id=t||d.uid(),this.update(e,!0)}update(e,t=!1){for(const i of P.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(h,{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=P.attrs.reduce((s,r)=>(s[r]=this[r],s),{});return i.pages&&(i.pages=i.pages.map(s=>(delete s.dsl,s)),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>(delete s.dsl,s))),{__VTJ_PROJECT__:!0,id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(g,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(g,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(a=>a.package===e.package);let r;if(s>-1?(r="update",i.splice(s,1,{...i[s],...e})):(r="create",i.push(e)),!t){const a={model:this,type:r,data:e};n.emit(O,a),n.emit(h,a)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(r=>r.package===e.package);if(s>-1&&i.splice(s,1),!t){const r={model:this,type:"delete",data:e};n.emit(O,r),n.emit(h,r)}}getPage(e){const t=(i,s=[])=>{for(const r of s){if(r.id===i)return r;if(r.children&&r.children.length){const a=t(i,r.children);if(a)return a}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir?s.children&&s.children.length&&(i=i.concat(e(s.children))):i.push(s);return i};return e(this.pages)}async createPage(e,t,i=!1){if(e.id=e.raw?e.name:e.id||d.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:d.upperFirstCamelCase(e.name)}).toDsl(),t){const s=this.getPage(t);s?s.children?s.children.push(e):s.children=[e]:console.warn(`not found PageFile for id: ${t} `)}else this.pages.push(e);if(!i){const s={model:this,type:"create",data:e};n.emit(A,s),n.emit(h,s)}!this.currentFile&&!e.dir&&(await d.delay(1e3),this.active(e,i))}updatePage(e,t=!1){const i=this.getPage(e.id);if(i?Object.assign(i,e):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(A,s),n.emit(h,s)}}clonePage(e,t,i=!1){const s=d.uid(),r=`${e.name}Copy`,a=`${e.title}_副本`,c=new u({id:s,name:r}).toDsl(),m=d.merge({},e,{id:s,name:r,title:a,dsl:c}),p=t?this.getPage(t)?.children||[]:this.pages,I=p.findIndex(T=>T.id===e.id);if(p.splice(I+1,0,m),!i){const T={model:this,type:"clone",data:{source:e,target:m}};n.emit(A,T),n.emit(h,T)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,a)=>{const c=a.findIndex(m=>m.id===r);if(c>=0){a.splice(c,1);return}for(const m of a)m.children&&m.children.length&&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(h,r)}}getBlock(e){return this.blocks.find(t=>t.id===e)}async createBlock(e,t=!1){const i=e.id||d.uid(),s=d.upperFirstCamelCase(e.name);e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e);const r=e.fromType||"Schema";if(!t){const a={model:this,type:"create",data:e};n.emit(y,a),n.emit(h,a)}!this.currentFile&&r==="Schema"&&(await d.delay(1e3),this.active(e,t))}updateBlock(e,t=!1){const i=this.getBlock(e.id);if(i?(Object.assign(i,e),i.dsl&&(i.dsl.name=e.name)):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(y,s),n.emit(h,s)}}cloneBlock(e,t=!1){const i=d.uid(),s=`${e.name}Copy`,r=`${e.title}_副本`,a=new u({id:i,name:s}).toDsl(),c=d.merge({},e,{id:i,name:s,title:r,dsl:a}),m=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(m+1,0,c),!t){const p={model:this,type:"clone",data:{source:e,target:c}};n.emit(y,p),n.emit(h,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,r=s.findIndex(a=>a.id===e);if(r>-1?(s.splice(r,1),this.currentFile?.id===e&&this.deactivate(t)):console.warn(`not found PageFile for id: ${e} `),!t){const a={model:this,type:"delete",data:i};n.emit(y,a),n.emit(h,a)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(r=>r.name===e.name||r.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=d.uid(),this.apis.push(e)),!t){const r={model:this,type:s,data:e};n.emit(V,r),n.emit(h,r)}}removeApi(e,t=!1){const i=this.apis.findIndex(s=>s.name===e||s.id===e);if(i>-1?this.apis.splice(i,1):console.warn(`not found Api for name: ${e} `),!t){const s={model:this,type:"delete",data:e};n.emit(V,s),n.emit(h,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(r=>r.code===e.code||r.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=d.uid(),this.meta.push(e)),!t){const r={model:this,type:s,data:e};n.emit(S,r),n.emit(h,r)}}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(h,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(h,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(h,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(L,t):n.emit(H,t)}}const C="EVENT_HISTORY_CHANGE",x="EVENT_HISTORY_LOAD";class ${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:d.uid(),label:new Date().toLocaleString(),dsl:d.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(a=>a.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(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(C,{model:this,type:"clear",data:t})}}const n=d.mitt();function K(f){return f instanceof u}function Y(f){return f instanceof E}function W(f){return!!f.__VTJ_BLOCK__}function D(f){const e=d.cloneDeep(f);return delete e.id,Array.isArray(e.children)&&(e.children=e.children.map(t=>D(t))),e}function q(f){const e=f.fromType||"Schema";return e==="Schema"?{type:"Schema",id:f.id}:e==="UrlSchema"?{type:"UrlSchema",url:(f.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(f.urls||"").split(","),library:f.library}:""}exports.BUILT_IN_COMPONENTS=U;exports.BUILT_IN_LIBRARAY_MAP=w;exports.BUILT_IN_MATERIALS=G;exports.BUILT_IN_NAME=J;exports.BUILT_IN_TAGS=F;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=B;exports.Base=j;exports.BlockModel=u;exports.DirectiveModel=_;exports.EVENT_BLOCK_CHANGE=o;exports.EVENT_HISTORY_CHANGE=C;exports.EVENT_HISTORY_LOAD=x;exports.EVENT_NODE_CHANGE=l;exports.EVENT_PROJECT_ACTIVED=g;exports.EVENT_PROJECT_APIS_CHANGE=V;exports.EVENT_PROJECT_BLOCKS_CHANGE=y;exports.EVENT_PROJECT_CHANGE=h;exports.EVENT_PROJECT_DEPS_CHANGE=O;exports.EVENT_PROJECT_FILE_PUBLISH=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=A;exports.EVENT_PROJECT_PUBLISH=H;exports.EventModel=v;exports.HistoryModel=$;exports.NodeModel=E;exports.ProjectModel=P;exports.PropModel=N;exports.Service=M;exports.VTJ_CORE_VERSION=b;exports.cloneDsl=D;exports.createNodeFrom=q;exports.emitter=n;exports.isBlock=K;exports.isBlockSchema=W;exports.isNode=Y;
7
+ */const b="0.9.0-alpha.4",J="BuiltIn",R="VueMaterial",B="VueRouterMaterial",w=[R,B],G={vue:"Vue","vue-router":"VueRouter"},U={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[B]:["RouterView","RouterLink"]},F=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class M{}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 v{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 v(i,s),t),{})}}class A{constructor(e){this.schema=e;const{name:t,handler:i}=this.schema;this.name=t,this.handler=i,this.update(e)}name;handler;modifiers={};update(e){Object.assign(this.schema,e);const{handler:t,modifiers:i={}}=this.schema;this.handler=t,this.modifiers=i}static toDsl(e){return Object.entries(e).reduce((t,[i,s])=>{const{handler:r,modifiers:a}=s;return t[i]={name:i,handler:r,modifiers:a},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new A(s),t),{})}}class _{constructor(e){this.schema=e,this.id=e.id||o.uid(),this.update(e)}id;name="";arg;modifiers;value;iterator;update(e){Object.assign(this.schema,e);const{name:t,arg:i,modifiers:s,value:r,iterator:a}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=r,this.iterator=a}static parse(e=[]){return e.map(t=>new _(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:r,value:a,iterator:l,id:h}=t;return{id:h,name:i,arg:s,modifiers:r,value:a,iterator:l}})}}const c="EVENT_NODE_CHANGE";class E{constructor(e,t=null){this.parent=t;const{id:i=o.uid(),name:s,from:r=""}=e;this.id=i,this.name=s,this.from=r,this.update(e,!0),E.nodes[this.id]=this}__VTJ_NODE__=!0;locked=!1;static nodes={};id;name;from;invisible=!1;children="";slot;props={};events={};directives=[];disposed=!1;update(e,t=!1){const{invisible:i=!1,locked:s=!1,children:r=[],slot:a,props:l={},events:h={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(r,!0),this.setSlot(a,!0),this.props=v.parse(l),this.events=A.parse(h),this.directives=_.parse(p),t||n.emit(c,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new E(i,this)):this.children=e,t||n.emit(c,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||n.emit(c,this)}setProp(e,t,i,s=!1){const r=this.props[e];r?r.setValue(t):this.props[e]=new v(e,t,i),s||n.emit(c,this)}removeProp(e,t=!1){delete this.props[e],t||n.emit(c,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 A(e),t||n.emit(c,this)}removeEvent(e,t=!1){delete this.events[e],t||n.emit(c,this)}setDirective(e,t=!1){const i=this.directives.findIndex(s=>s.id===e.id);i>=0?this.directives.splice(i,1,new _(e)):this.directives.push(new _(e)),t||n.emit(c,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(c,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const r=i.findIndex(a=>a===e);e.parent=null,i.splice(r,1),t||n.emit(c,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(c,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(c,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(c,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(c,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(c,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:l,props:h,directives:p,events:I}=this,T=Array.isArray(l)?l.map(L=>L.toDsl()):l;return{id:e,name:t,from:i,invisible:s,locked:r,slot:a,children:T,props:v.toDsl(h),directives:_.toDsl(p),events:A.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(c,this),this.parent=null,this.disposed=!0,delete E.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(c,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||n.emit(c,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(c,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=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","inject","state","lifeCycles","methods","computed","watch","css","props","emits","slots","dataSources","__TEMPLATE_ID__"];constructor(e){const{id:t}=e;this.id=t||o.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 E(s))),t||n.emit(d,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((a,l)=>(a[l]=this[l],a),{}),__VTJ_BLOCK__:t,__VERSION__:e||o.timestamp().toString(),id:i,nodes:s.map(a=>a.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}setFunction(e,t,i,s=!1){this[e][t]=i,s||n.emit(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||o.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=o.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(r=>r===i.name||r===i);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=>o.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||n.emit(d,this))}setSlot(e,t=!1){const i=o.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(r=>r===i.name||r===i);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=>o.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 E(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 f="EVENT_PROJECT_CHANGE",O="EVENT_PROJECT_ACTIVED",g="EVENT_PROJECT_DEPS_CHANGE",y="EVENT_PROJECT_PAGES_CHANGE",N="EVENT_PROJECT_BLOCKS_CHANGE",V="EVENT_PROJECT_APIS_CHANGE",S="EVENT_PROJECT_META_CHANGE",H="EVENT_PROJECT_PUBLISH",k="EVENT_PROJECT_FILE_PUBLISH";class P{id="";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};__BASE_PATH__="/";static attrs=["name","homepage","description","dependencies","pages","blocks","apis","meta","config","__BASE_PATH__"];constructor(e){const{id:t}=e;this.id=t||o.uid(),this.update(e,!0)}update(e,t=!1){for(const i of P.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(f,{model:this,type:"update",data:e})}isPageFile(e){return e.type==="page"}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=P.attrs.reduce((s,r)=>(s[r]=this[r],s),{});return i.pages&&(i.pages=i.pages.map(s=>(delete s.dsl,s)),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>(delete s.dsl,s))),{__VTJ_PROJECT__:!0,id:t,...i}}active(e,t=!1){this.currentFile=e,t||n.emit(O,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(O,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(a=>a.package===e.package);let r;if(s>-1?(r="update",i.splice(s,1,{...i[s],...e})):(r="create",i.push(e)),!t){const a={model:this,type:r,data:e};n.emit(g,a),n.emit(f,a)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(r=>r.package===e.package);if(s>-1&&i.splice(s,1),!t){const r={model:this,type:"delete",data:e};n.emit(g,r),n.emit(f,r)}}getPage(e){const t=(i,s=[])=>{for(const r of s){if(r.id===i)return r;if(r.children&&r.children.length){const a=t(i,r.children);if(a)return a}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir?s.children&&s.children.length&&(i=i.concat(e(s.children))):i.push(s);return i};return e(this.pages)}async createPage(e,t,i=!1){if(e.id=e.raw?e.name:e.id||o.uid(),e.type="page",e.dir?e.children=[]:e.dsl=e.dsl||new u({id:e.id,name:o.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(y,s),n.emit(f,s)}!this.currentFile&&!e.dir&&(await o.delay(1e3),this.active(e,i))}updatePage(e,t=!1){const i=this.getPage(e.id);if(i?Object.assign(i,e):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(y,s),n.emit(f,s)}}clonePage(e,t,i=!1){const s=o.uid(),r=`${e.name}Copy`,a=`${e.title}_副本`,l=new u({id:s,name:r}).toDsl(),h=o.merge({},e,{id:s,name:r,title:a,dsl:l}),p=t?this.getPage(t)?.children||[]:this.pages,I=p.findIndex(T=>T.id===e.id);if(p.splice(I+1,0,h),!i){const T={model:this,type:"clone",data:{source:e,target:h}};n.emit(y,T),n.emit(f,T)}}async saveToBlock(e,t=!1){this.active(e,t),await o.delay(1e3);const i=o.uid(),s=e.name,r=e.title,a=new u({id:i,name:s}).toDsl(),l=o.merge({},e,{id:i,name:s,title:r,dsl:a,type:"block",fromType:"Schema"});if(this.blocks.push(l),!t){const h={model:this,type:"create",data:l};n.emit(N,h),n.emit(f,h)}}removePage(e,t=!1){const i=this.getPage(e),s=(r,a)=>{const l=a.findIndex(h=>h.id===r);if(l>=0){a.splice(l,1);return}for(const h of a)h.children&&h.children.length&&s(r,h.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(y,r),n.emit(f,r)}}getBlock(e){return this.blocks.find(t=>t.id===e)}async createBlock(e,t=!1){const i=e.id||o.uid(),s=o.upperFirstCamelCase(e.name);e.id=i,e.type="block",e.dsl=new u({id:i,name:s}).toDsl(),this.blocks.push(e);const r=e.fromType||"Schema";if(!t){const a={model:this,type:"create",data:e};n.emit(N,a),n.emit(f,a)}!this.currentFile&&r==="Schema"&&(await o.delay(1e3),this.active(e,t))}updateBlock(e,t=!1){const i=this.getBlock(e.id);if(i?(Object.assign(i,e),i.dsl&&(i.dsl.name=e.name)):console.warn(`not found PageFile for id: ${e.id} `),!t){const s={model:this,type:"update",data:e};n.emit(N,s),n.emit(f,s)}}cloneBlock(e,t=!1){const i=o.uid(),s=`${e.name}Copy`,r=`${e.title}_副本`,a=new u({id:i,name:s}).toDsl(),l=o.merge({},e,{id:i,name:s,title:r,dsl:a}),h=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(h+1,0,l),!t){const p={model:this,type:"clone",data:{source:e,target:l}};n.emit(N,p),n.emit(f,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,r=s.findIndex(a=>a.id===e);if(r>-1?(s.splice(r,1),this.currentFile?.id===e&&this.deactivate(t)):console.warn(`not found PageFile for id: ${e} `),!t){const a={model:this,type:"delete",data:i};n.emit(N,a),n.emit(f,a)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(r=>r.name===e.name||r.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=o.uid(),this.apis.push(e)),!t){const r={model:this,type:s,data:e};n.emit(V,r),n.emit(f,r)}}removeApi(e,t=!1){const i=this.apis.findIndex(s=>s.name===e||s.id===e);if(i>-1?this.apis.splice(i,1):console.warn(`not found Api for name: ${e} `),!t){const s={model:this,type:"delete",data:e};n.emit(V,s),n.emit(f,s)}}existApiName(e,t=[]){return this.apis.some(i=>i.name===e&&!t.includes(i.id))}setMeta(e,t=!1){const i=this.meta.find(r=>r.code===e.code||r.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=o.uid(),this.meta.push(e)),!t){const r={model:this,type:s,data:e};n.emit(S,r),n.emit(f,r)}}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(f,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(f,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};n.emit(f,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?n.emit(k,t):n.emit(H,t)}}const C="EVENT_HISTORY_CHANGE",x="EVENT_HISTORY_LOAD";class ${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:o.uid(),label:new Date().toLocaleString(),dsl:o.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(a=>a.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(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(C,{model:this,type:"clear",data:t})}}const n=o.mitt();function K(m){return m instanceof u}function Y(m){return m instanceof E}function W(m){return!!m.__VTJ_BLOCK__}function D(m){const e=o.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=U;exports.BUILT_IN_LIBRARAY_MAP=G;exports.BUILT_IN_MATERIALS=w;exports.BUILT_IN_NAME=J;exports.BUILT_IN_TAGS=F;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=B;exports.Base=j;exports.BlockModel=u;exports.DirectiveModel=_;exports.EVENT_BLOCK_CHANGE=d;exports.EVENT_HISTORY_CHANGE=C;exports.EVENT_HISTORY_LOAD=x;exports.EVENT_NODE_CHANGE=c;exports.EVENT_PROJECT_ACTIVED=O;exports.EVENT_PROJECT_APIS_CHANGE=V;exports.EVENT_PROJECT_BLOCKS_CHANGE=N;exports.EVENT_PROJECT_CHANGE=f;exports.EVENT_PROJECT_DEPS_CHANGE=g;exports.EVENT_PROJECT_FILE_PUBLISH=k;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=y;exports.EVENT_PROJECT_PUBLISH=H;exports.EventModel=A;exports.HistoryModel=$;exports.NodeModel=E;exports.ProjectModel=P;exports.PropModel=v;exports.Service=M;exports.VTJ_CORE_VERSION=b;exports.cloneDsl=D;exports.createNodeFrom=q;exports.emitter=n;exports.isBlock=K;exports.isBlockSchema=W;exports.isNode=Y;
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
- import { uid as m, timestamp as G, isString as A, upperFirstCamelCase as I, delay as V, merge as S, cloneDeep as b, mitt as F } from "@vtj/base";
1
+ import { uid as m, timestamp as G, isString as A, upperFirstCamelCase as S, delay as P, merge as O, cloneDeep as b, mitt as F } from "@vtj/base";
2
2
  /**!
3
3
  * Copyright (c) 2024, VTJ.PRO All rights reserved.
4
4
  * @name @vtj/core
5
5
  * @author CHC chenhuachun1549@dingtalk.com
6
- * @version 0.9.0-alpha.2
6
+ * @version 0.9.0-alpha.4
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const M = "0.9.0-alpha.2", K = "BuiltIn", w = "VueMaterial", H = "VueRouterMaterial", Y = [w, H], W = {
9
+ const M = "0.9.0-alpha.4", K = "BuiltIn", w = "VueMaterial", H = "VueRouterMaterial", Y = [w, H], W = {
10
10
  vue: "Vue",
11
11
  "vue-router": "VueRouter"
12
12
  }, q = {
@@ -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 y {
73
+ class T {
74
74
  constructor(e) {
75
75
  this.schema = e;
76
76
  const { name: t, handler: i } = this.schema;
@@ -86,13 +86,13 @@ class y {
86
86
  }
87
87
  static toDsl(e) {
88
88
  return Object.entries(e).reduce((t, [i, s]) => {
89
- const { handler: r, modifiers: a } = s;
90
- return t[i] = { name: i, handler: r, modifiers: a }, t;
89
+ const { handler: a, modifiers: r } = s;
90
+ return t[i] = { name: i, handler: a, modifiers: r }, t;
91
91
  }, {});
92
92
  }
93
93
  static parse(e = {}) {
94
94
  return Object.entries(e).reduce(
95
- (t, [i, s]) => (t[i] = new y(s), t),
95
+ (t, [i, s]) => (t[i] = new T(s), t),
96
96
  {}
97
97
  );
98
98
  }
@@ -127,32 +127,32 @@ class v {
127
127
  iterator;
128
128
  update(e) {
129
129
  Object.assign(this.schema, e);
130
- const { name: t, arg: i, modifiers: s, value: r, iterator: a } = this.schema;
131
- this.name = t, this.arg = i, this.modifiers = s, this.value = r, this.iterator = a;
130
+ const { name: t, arg: i, modifiers: s, value: a, iterator: r } = this.schema;
131
+ this.name = t, this.arg = i, this.modifiers = s, this.value = a, this.iterator = r;
132
132
  }
133
133
  static parse(e = []) {
134
134
  return e.map((t) => new v(t));
135
135
  }
136
136
  static toDsl(e = []) {
137
137
  return e.map((t) => {
138
- const { name: i, arg: s, modifiers: r, value: a, iterator: l, id: f } = t;
138
+ const { name: i, arg: s, modifiers: a, value: r, iterator: d, id: l } = t;
139
139
  return {
140
- id: f,
140
+ id: l,
141
141
  name: i,
142
142
  arg: s,
143
- modifiers: r,
144
- value: a,
145
- iterator: l
143
+ modifiers: a,
144
+ value: r,
145
+ iterator: d
146
146
  };
147
147
  });
148
148
  }
149
149
  }
150
- const d = "EVENT_NODE_CHANGE";
150
+ const c = "EVENT_NODE_CHANGE";
151
151
  class _ {
152
152
  constructor(e, t = null) {
153
153
  this.parent = t;
154
- const { id: i = m(), name: s, from: r = "" } = e;
155
- this.id = i, this.name = s, this.from = r, this.update(e, !0), _.nodes[this.id] = this;
154
+ const { id: i = m(), name: s, from: a = "" } = e;
155
+ this.id = i, this.name = s, this.from = a, this.update(e, !0), _.nodes[this.id] = this;
156
156
  }
157
157
  /**
158
158
  * 标记
@@ -215,13 +215,13 @@ class _ {
215
215
  const {
216
216
  invisible: i = !1,
217
217
  locked: s = !1,
218
- children: r = [],
219
- slot: a,
220
- props: l = {},
221
- events: f = {},
218
+ children: a = [],
219
+ slot: r,
220
+ props: d = {},
221
+ events: l = {},
222
222
  directives: p = []
223
223
  } = e;
224
- this.invisible = i, this.locked = s, this.setChildren(r, !0), this.setSlot(a, !0), this.props = x.parse(l), this.events = y.parse(f), this.directives = v.parse(p), t || n.emit(d, this);
224
+ this.invisible = i, this.locked = s, this.setChildren(a, !0), this.setSlot(r, !0), this.props = x.parse(d), this.events = T.parse(l), this.directives = v.parse(p), t || n.emit(c, this);
225
225
  }
226
226
  /**
227
227
  * 设置子节点
@@ -229,7 +229,7 @@ class _ {
229
229
  * @param silent
230
230
  */
231
231
  setChildren(e = "", t = !1) {
232
- Array.isArray(e) ? this.children = e.map((i) => new _(i, this)) : this.children = e, t || n.emit(d, this);
232
+ Array.isArray(e) ? this.children = e.map((i) => new _(i, this)) : this.children = e, t || n.emit(c, this);
233
233
  }
234
234
  /**
235
235
  * 设置节点放置的插槽
@@ -237,7 +237,7 @@ class _ {
237
237
  * @param silent
238
238
  */
239
239
  setSlot(e, t = !1) {
240
- this.slot = typeof e == "string" ? { name: e, params: [] } : e, t || n.emit(d, this);
240
+ this.slot = typeof e == "string" ? { name: e, params: [] } : e, t || n.emit(c, this);
241
241
  }
242
242
  /**
243
243
  * 新增或更新属性
@@ -247,8 +247,8 @@ class _ {
247
247
  * @param silent
248
248
  */
249
249
  setProp(e, t, i, s = !1) {
250
- const r = this.props[e];
251
- r ? r.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(d, this);
250
+ const a = this.props[e];
251
+ a ? a.setValue(t) : this.props[e] = new x(e, t, i), s || n.emit(c, this);
252
252
  }
253
253
  /**
254
254
  * 删除属性
@@ -256,7 +256,7 @@ class _ {
256
256
  * @param silent
257
257
  */
258
258
  removeProp(e, t = !1) {
259
- delete this.props[e], t || n.emit(d, this);
259
+ delete this.props[e], t || n.emit(c, this);
260
260
  }
261
261
  /**
262
262
  * 获取属性值
@@ -275,7 +275,7 @@ class _ {
275
275
  */
276
276
  setEvent(e, t = !1) {
277
277
  const i = this.events[e.name];
278
- i ? i.update(e) : this.events[e.name] = new y(e), t || n.emit(d, this);
278
+ i ? i.update(e) : this.events[e.name] = new T(e), t || n.emit(c, this);
279
279
  }
280
280
  /**
281
281
  * 删除事件
@@ -283,7 +283,7 @@ class _ {
283
283
  * @param silent
284
284
  */
285
285
  removeEvent(e, t = !1) {
286
- delete this.events[e], t || n.emit(d, this);
286
+ delete this.events[e], t || n.emit(c, this);
287
287
  }
288
288
  /**
289
289
  * 新增或更新指令
@@ -292,7 +292,7 @@ class _ {
292
292
  */
293
293
  setDirective(e, t = !1) {
294
294
  const i = this.directives.findIndex((s) => s.id === e.id);
295
- i >= 0 ? this.directives.splice(i, 1, new v(e)) : this.directives.push(new v(e)), t || n.emit(d, this);
295
+ i >= 0 ? this.directives.splice(i, 1, new v(e)) : this.directives.push(new v(e)), t || n.emit(c, this);
296
296
  }
297
297
  /**
298
298
  * 删除指令
@@ -303,7 +303,7 @@ class _ {
303
303
  const i = this.directives.findIndex(
304
304
  (s) => s === e || s.id === e.id
305
305
  );
306
- i >= 0 && this.directives.splice(i, 1), t || n.emit(d, this);
306
+ i >= 0 && this.directives.splice(i, 1), t || n.emit(c, this);
307
307
  }
308
308
  /**
309
309
  * 删除子节点
@@ -314,8 +314,8 @@ class _ {
314
314
  removeChild(e, t = !1) {
315
315
  const { children: i, disposed: s } = this;
316
316
  if (s || !Array.isArray(i)) return;
317
- const r = i.findIndex((a) => a === e);
318
- e.parent = null, i.splice(r, 1), t || n.emit(d, this);
317
+ const a = i.findIndex((r) => r === e);
318
+ e.parent = null, i.splice(a, 1), t || n.emit(c, this);
319
319
  }
320
320
  /**
321
321
  * 追加子节点
@@ -325,7 +325,7 @@ class _ {
325
325
  */
326
326
  appendChild(e, t = !1) {
327
327
  const { children: i, disposed: s } = this;
328
- s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(d, this));
328
+ s || (e.parent = this, Array.isArray(i) ? i.push(e) : this.children = [e], t || n.emit(c, this));
329
329
  }
330
330
  /**
331
331
  * 在当前节点的后面插入节点
@@ -339,7 +339,7 @@ class _ {
339
339
  if (Array.isArray(i)) {
340
340
  e.parent = this.parent;
341
341
  const s = i.indexOf(this);
342
- i.splice(s + 1, 0, e), t || n.emit(d, this.parent);
342
+ i.splice(s + 1, 0, e), t || n.emit(c, this.parent);
343
343
  }
344
344
  }
345
345
  /**
@@ -354,7 +354,7 @@ class _ {
354
354
  if (Array.isArray(i)) {
355
355
  e.parent = this.parent;
356
356
  const s = i.indexOf(this);
357
- i.splice(s, 0, e), t || n.emit(d, this.parent);
357
+ i.splice(s, 0, e), t || n.emit(c, this.parent);
358
358
  }
359
359
  }
360
360
  movePrev(e = !1) {
@@ -363,7 +363,7 @@ class _ {
363
363
  const i = t.children;
364
364
  if (Array.isArray(i)) {
365
365
  const s = i.indexOf(this);
366
- s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(d, t));
366
+ s > 0 && (i.splice(s, 1), i.splice(s - 1, 0, this), e || n.emit(c, t));
367
367
  }
368
368
  }
369
369
  moveNext(e = !1) {
@@ -372,7 +372,7 @@ class _ {
372
372
  const i = t.children;
373
373
  if (Array.isArray(i)) {
374
374
  const s = i.indexOf(this);
375
- s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(d, t));
375
+ s > -1 && s < i.length - 1 && (i.splice(s, 1), i.splice(s + 1, 0, this), e || n.emit(c, t));
376
376
  }
377
377
  }
378
378
  /**
@@ -385,24 +385,24 @@ class _ {
385
385
  name: t,
386
386
  from: i,
387
387
  invisible: s,
388
- locked: r,
389
- slot: a,
390
- children: l,
391
- props: f,
388
+ locked: a,
389
+ slot: r,
390
+ children: d,
391
+ props: l,
392
392
  directives: p,
393
393
  events: C
394
- } = this, E = Array.isArray(l) ? l.map((J) => J.toDsl()) : l;
394
+ } = this, E = Array.isArray(d) ? d.map((J) => J.toDsl()) : d;
395
395
  return {
396
396
  id: e,
397
397
  name: t,
398
398
  from: i,
399
399
  invisible: s,
400
- locked: r,
401
- slot: a,
400
+ locked: a,
401
+ slot: r,
402
402
  children: E,
403
- props: x.toDsl(f),
403
+ props: x.toDsl(l),
404
404
  directives: v.toDsl(p),
405
- events: y.toDsl(C)
405
+ events: T.toDsl(C)
406
406
  };
407
407
  }
408
408
  /**
@@ -412,25 +412,25 @@ class _ {
412
412
  */
413
413
  dispose(e = !1) {
414
414
  const { children: t, disposed: i } = this;
415
- 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 _.nodes[this.id]);
415
+ i || (Array.isArray(t) && t.forEach((s) => s.dispose(!0)), this.parent ? this.parent.removeChild(this, e) : e || n.emit(c, this), this.parent = null, this.disposed = !0, delete _.nodes[this.id]);
416
416
  }
417
417
  lock(e = !1) {
418
418
  if (this.locked = !0, Array.isArray(this.children))
419
419
  for (const t of this.children)
420
420
  t.lock(!0);
421
- e || n.emit(d, this);
421
+ e || n.emit(c, this);
422
422
  }
423
423
  unlock(e = !1) {
424
424
  if (this.locked = !1, Array.isArray(this.children))
425
425
  for (const t of this.children)
426
426
  t.unlock(!0);
427
- e || n.emit(d, this);
427
+ e || n.emit(c, this);
428
428
  }
429
429
  setVisible(e, t = !1) {
430
430
  if (this.invisible = !e, Array.isArray(this.children))
431
431
  for (const i of this.children)
432
432
  i.setVisible(e, !0);
433
- t || n.emit(d, this);
433
+ t || n.emit(c, this);
434
434
  }
435
435
  isChild(e) {
436
436
  let t = !1;
@@ -486,8 +486,8 @@ class u {
486
486
  }
487
487
  update(e, t = !1) {
488
488
  for (const s of u.normalAttrs) {
489
- const r = e[s];
490
- r && (this[s] = r);
489
+ const a = e[s];
490
+ a && (this[s] = a);
491
491
  }
492
492
  const { nodes: i = [] } = e;
493
493
  i.length && (this.nodes = i.map((s) => new _(s))), t || n.emit(o, this);
@@ -500,13 +500,13 @@ class u {
500
500
  const { __VTJ_BLOCK__: t, id: i, nodes: s } = this;
501
501
  return {
502
502
  ...u.normalAttrs.reduce(
503
- (a, l) => (a[l] = this[l], a),
503
+ (r, d) => (r[d] = this[d], r),
504
504
  {}
505
505
  ),
506
506
  __VTJ_BLOCK__: t,
507
507
  __VERSION__: e || G().toString(),
508
508
  id: i,
509
- nodes: s.map((a) => a.toDsl())
509
+ nodes: s.map((r) => r.toDsl())
510
510
  };
511
511
  }
512
512
  /**
@@ -610,7 +610,7 @@ class u {
610
610
  * @param silent
611
611
  */
612
612
  setEmit(e, t = !1) {
613
- const i = A(e) ? { name: e, params: [] } : e, s = this.emits.findIndex((r) => r === i.name || r === i);
613
+ const i = A(e) ? { name: e, params: [] } : e, s = this.emits.findIndex((a) => a === i.name || a === i);
614
614
  s > -1 ? this.emits.splice(s, 1, i) : this.emits.push(i), t || n.emit(o, this);
615
615
  }
616
616
  /**
@@ -630,7 +630,7 @@ class u {
630
630
  * @param silent
631
631
  */
632
632
  setSlot(e, t = !1) {
633
- const i = A(e) ? { name: e, params: [] } : e, s = this.slots.findIndex((r) => r === i.name || r === i);
633
+ const i = A(e) ? { name: e, params: [] } : e, s = this.slots.findIndex((a) => a === i.name || a === i);
634
634
  s > -1 ? this.slots.splice(s, 1, i) : this.slots.push(i), t || n.emit(o, this);
635
635
  }
636
636
  /**
@@ -782,8 +782,8 @@ class u {
782
782
  return t;
783
783
  }
784
784
  }
785
- const c = "EVENT_PROJECT_CHANGE", R = "EVENT_PROJECT_ACTIVED", D = "EVENT_PROJECT_DEPS_CHANGE", T = "EVENT_PROJECT_PAGES_CHANGE", g = "EVENT_PROJECT_BLOCKS_CHANGE", k = "EVENT_PROJECT_APIS_CHANGE", B = "EVENT_PROJECT_META_CHANGE", U = "EVENT_PROJECT_PUBLISH", j = "EVENT_PROJECT_FILE_PUBLISH";
786
- class O {
785
+ const h = "EVENT_PROJECT_CHANGE", k = "EVENT_PROJECT_ACTIVED", R = "EVENT_PROJECT_DEPS_CHANGE", N = "EVENT_PROJECT_PAGES_CHANGE", y = "EVENT_PROJECT_BLOCKS_CHANGE", D = "EVENT_PROJECT_APIS_CHANGE", B = "EVENT_PROJECT_META_CHANGE", U = "EVENT_PROJECT_PUBLISH", j = "EVENT_PROJECT_FILE_PUBLISH";
786
+ class V {
787
787
  id = "";
788
788
  name = "";
789
789
  description = "";
@@ -813,11 +813,11 @@ class O {
813
813
  this.id = t || m(), this.update(e, !0);
814
814
  }
815
815
  update(e, t = !1) {
816
- for (const i of O.attrs) {
816
+ for (const i of V.attrs) {
817
817
  const s = e[i];
818
818
  s && (this[i] = s);
819
819
  }
820
- t || n.emit(c, {
820
+ t || n.emit(h, {
821
821
  model: this,
822
822
  type: "update",
823
823
  data: e
@@ -831,8 +831,8 @@ class O {
831
831
  delete t.dsl, t.children && t.children.length && this.cleanPagesDsl(t.children);
832
832
  }
833
833
  toDsl(e) {
834
- const { id: t } = this, i = O.attrs.reduce(
835
- (s, r) => (s[r] = this[r], s),
834
+ const { id: t } = this, i = V.attrs.reduce(
835
+ (s, a) => (s[a] = this[a], s),
836
836
  {}
837
837
  );
838
838
  return i.pages && (i.pages = i.pages.map((s) => (delete s.dsl, s)), this.cleanPagesDsl(i.pages)), i.blocks && (i.blocks = i.blocks.map((s) => (delete s.dsl, s))), {
@@ -848,7 +848,7 @@ class O {
848
848
  * @param silent
849
849
  */
850
850
  active(e, t = !1) {
851
- this.currentFile = e, t || n.emit(R, {
851
+ this.currentFile = e, t || n.emit(k, {
852
852
  model: this,
853
853
  type: "update",
854
854
  data: e
@@ -859,7 +859,7 @@ class O {
859
859
  * @param silent
860
860
  */
861
861
  deactivate(e = !1) {
862
- this.currentFile = null, e || n.emit(R, {
862
+ this.currentFile = null, e || n.emit(k, {
863
863
  model: this,
864
864
  type: "update",
865
865
  data: null
@@ -871,18 +871,18 @@ class O {
871
871
  * @param silent
872
872
  */
873
873
  setDeps(e, t = !1) {
874
- const i = this.dependencies, s = i.findIndex((a) => a.package === e.package);
875
- let r;
876
- if (s > -1 ? (r = "update", i.splice(s, 1, {
874
+ const i = this.dependencies, s = i.findIndex((r) => r.package === e.package);
875
+ let a;
876
+ if (s > -1 ? (a = "update", i.splice(s, 1, {
877
877
  ...i[s],
878
878
  ...e
879
- })) : (r = "create", i.push(e)), !t) {
880
- const a = {
879
+ })) : (a = "create", i.push(e)), !t) {
880
+ const r = {
881
881
  model: this,
882
- type: r,
882
+ type: a,
883
883
  data: e
884
884
  };
885
- n.emit(D, a), n.emit(c, a);
885
+ n.emit(R, r), n.emit(h, r);
886
886
  }
887
887
  }
888
888
  /**
@@ -891,14 +891,14 @@ class O {
891
891
  * @param silent
892
892
  */
893
893
  removeDeps(e, t = !1) {
894
- const i = this.dependencies, s = i.findIndex((r) => r.package === e.package);
894
+ const i = this.dependencies, s = i.findIndex((a) => a.package === e.package);
895
895
  if (s > -1 && i.splice(s, 1), !t) {
896
- const r = {
896
+ const a = {
897
897
  model: this,
898
898
  type: "delete",
899
899
  data: e
900
900
  };
901
- n.emit(D, r), n.emit(c, r);
901
+ n.emit(R, a), n.emit(h, a);
902
902
  }
903
903
  }
904
904
  /**
@@ -908,13 +908,13 @@ class O {
908
908
  */
909
909
  getPage(e) {
910
910
  const t = (i, s = []) => {
911
- for (const r of s) {
912
- if (r.id === i)
913
- return r;
914
- if (r.children && r.children.length) {
915
- const a = t(i, r.children);
916
- if (a)
917
- return a;
911
+ for (const a of s) {
912
+ if (a.id === i)
913
+ return a;
914
+ if (a.children && a.children.length) {
915
+ const r = t(i, a.children);
916
+ if (r)
917
+ return r;
918
918
  }
919
919
  }
920
920
  };
@@ -942,7 +942,7 @@ class O {
942
942
  async createPage(e, t, i = !1) {
943
943
  if (e.id = e.raw ? e.name : e.id || m(), e.type = "page", e.dir ? e.children = [] : e.dsl = e.dsl || new u({
944
944
  id: e.id,
945
- name: I(e.name)
945
+ name: S(e.name)
946
946
  }).toDsl(), t) {
947
947
  const s = this.getPage(t);
948
948
  s ? s.children ? s.children.push(e) : s.children = [e] : console.warn(`not found PageFile for id: ${t} `);
@@ -954,9 +954,9 @@ class O {
954
954
  type: "create",
955
955
  data: e
956
956
  };
957
- n.emit(T, s), n.emit(c, s);
957
+ n.emit(N, s), n.emit(h, s);
958
958
  }
959
- !this.currentFile && !e.dir && (await V(1e3), this.active(e, i));
959
+ !this.currentFile && !e.dir && (await P(1e3), this.active(e, i));
960
960
  }
961
961
  /**
962
962
  * 更新页面
@@ -971,7 +971,7 @@ class O {
971
971
  type: "update",
972
972
  data: e
973
973
  };
974
- n.emit(T, s), n.emit(c, s);
974
+ n.emit(N, s), n.emit(h, s);
975
975
  }
976
976
  }
977
977
  /**
@@ -981,20 +981,42 @@ class O {
981
981
  * @param silent
982
982
  */
983
983
  clonePage(e, t, i = !1) {
984
- const s = m(), r = `${e.name}Copy`, a = `${e.title}_副本`, l = new u({
984
+ const s = m(), a = `${e.name}Copy`, r = `${e.title}_副本`, d = new u({
985
985
  id: s,
986
- name: r
987
- }).toDsl(), f = S({}, e, { id: s, name: r, title: a, dsl: l }), p = t ? this.getPage(t)?.children || [] : this.pages, C = p.findIndex((E) => E.id === e.id);
988
- if (p.splice(C + 1, 0, f), !i) {
986
+ name: a
987
+ }).toDsl(), l = O({}, e, { id: s, name: a, title: r, dsl: d }), p = t ? this.getPage(t)?.children || [] : this.pages, C = p.findIndex((E) => E.id === e.id);
988
+ if (p.splice(C + 1, 0, l), !i) {
989
989
  const E = {
990
990
  model: this,
991
991
  type: "clone",
992
992
  data: {
993
993
  source: e,
994
- target: f
994
+ target: l
995
995
  }
996
996
  };
997
- n.emit(T, E), n.emit(c, E);
997
+ n.emit(N, E), n.emit(h, E);
998
+ }
999
+ }
1000
+ async saveToBlock(e, t = !1) {
1001
+ this.active(e, t), await P(1e3);
1002
+ const i = m(), s = e.name, a = e.title, r = new u({
1003
+ id: i,
1004
+ name: s
1005
+ }).toDsl(), d = O({}, e, {
1006
+ id: i,
1007
+ name: s,
1008
+ title: a,
1009
+ dsl: r,
1010
+ type: "block",
1011
+ fromType: "Schema"
1012
+ });
1013
+ if (this.blocks.push(d), !t) {
1014
+ const l = {
1015
+ model: this,
1016
+ type: "create",
1017
+ data: d
1018
+ };
1019
+ n.emit(y, l), n.emit(h, l);
998
1020
  }
999
1021
  }
1000
1022
  /**
@@ -1003,22 +1025,22 @@ class O {
1003
1025
  * @param silent
1004
1026
  */
1005
1027
  removePage(e, t = !1) {
1006
- const i = this.getPage(e), s = (r, a) => {
1007
- const l = a.findIndex((f) => f.id === r);
1008
- if (l >= 0) {
1009
- a.splice(l, 1);
1028
+ const i = this.getPage(e), s = (a, r) => {
1029
+ const d = r.findIndex((l) => l.id === a);
1030
+ if (d >= 0) {
1031
+ r.splice(d, 1);
1010
1032
  return;
1011
1033
  }
1012
- for (const f of a)
1013
- f.children && f.children.length && s(r, f.children);
1034
+ for (const l of r)
1035
+ l.children && l.children.length && s(a, l.children);
1014
1036
  };
1015
1037
  if (s(e, this.pages), e === this.homepage && (this.homepage = ""), this.currentFile?.id === e && this.deactivate(t), !t) {
1016
- const r = {
1038
+ const a = {
1017
1039
  model: this,
1018
1040
  type: "delete",
1019
1041
  data: i
1020
1042
  };
1021
- n.emit(T, r), n.emit(c, r);
1043
+ n.emit(N, a), n.emit(h, a);
1022
1044
  }
1023
1045
  }
1024
1046
  /**
@@ -1035,18 +1057,18 @@ class O {
1035
1057
  * @param silent
1036
1058
  */
1037
1059
  async createBlock(e, t = !1) {
1038
- const i = e.id || m(), s = I(e.name);
1060
+ const i = e.id || m(), s = S(e.name);
1039
1061
  e.id = i, e.type = "block", e.dsl = new u({ id: i, name: s }).toDsl(), this.blocks.push(e);
1040
- const r = e.fromType || "Schema";
1062
+ const a = e.fromType || "Schema";
1041
1063
  if (!t) {
1042
- const a = {
1064
+ const r = {
1043
1065
  model: this,
1044
1066
  type: "create",
1045
1067
  data: e
1046
1068
  };
1047
- n.emit(g, a), n.emit(c, a);
1069
+ n.emit(y, r), n.emit(h, r);
1048
1070
  }
1049
- !this.currentFile && r === "Schema" && (await V(1e3), this.active(e, t));
1071
+ !this.currentFile && a === "Schema" && (await P(1e3), this.active(e, t));
1050
1072
  }
1051
1073
  /**
1052
1074
  *
@@ -1061,24 +1083,24 @@ class O {
1061
1083
  type: "update",
1062
1084
  data: e
1063
1085
  };
1064
- n.emit(g, s), n.emit(c, s);
1086
+ n.emit(y, s), n.emit(h, s);
1065
1087
  }
1066
1088
  }
1067
1089
  cloneBlock(e, t = !1) {
1068
- const i = m(), s = `${e.name}Copy`, r = `${e.title}_副本`, a = new u({
1090
+ const i = m(), s = `${e.name}Copy`, a = `${e.title}_副本`, r = new u({
1069
1091
  id: i,
1070
1092
  name: s
1071
- }).toDsl(), l = S({}, e, { id: i, name: s, title: r, dsl: a }), f = this.blocks.findIndex((p) => p.id === e.id);
1072
- if (this.blocks.splice(f + 1, 0, l), !t) {
1093
+ }).toDsl(), d = O({}, e, { id: i, name: s, title: a, dsl: r }), l = this.blocks.findIndex((p) => p.id === e.id);
1094
+ if (this.blocks.splice(l + 1, 0, d), !t) {
1073
1095
  const p = {
1074
1096
  model: this,
1075
1097
  type: "clone",
1076
1098
  data: {
1077
1099
  source: e,
1078
- target: l
1100
+ target: d
1079
1101
  }
1080
1102
  };
1081
- n.emit(g, p), n.emit(c, p);
1103
+ n.emit(y, p), n.emit(h, p);
1082
1104
  }
1083
1105
  }
1084
1106
  /**
@@ -1087,14 +1109,14 @@ class O {
1087
1109
  * @param silent
1088
1110
  */
1089
1111
  removeBlock(e, t = !1) {
1090
- const i = this.getBlock(e), s = this.blocks, r = s.findIndex((a) => a.id === e);
1091
- if (r > -1 ? (s.splice(r, 1), this.currentFile?.id === e && this.deactivate(t)) : console.warn(`not found PageFile for id: ${e} `), !t) {
1092
- const a = {
1112
+ const i = this.getBlock(e), s = this.blocks, a = s.findIndex((r) => r.id === e);
1113
+ if (a > -1 ? (s.splice(a, 1), this.currentFile?.id === e && this.deactivate(t)) : console.warn(`not found PageFile for id: ${e} `), !t) {
1114
+ const r = {
1093
1115
  model: this,
1094
1116
  type: "delete",
1095
1117
  data: i
1096
1118
  };
1097
- n.emit(g, a), n.emit(c, a);
1119
+ n.emit(y, r), n.emit(h, r);
1098
1120
  }
1099
1121
  }
1100
1122
  /**
@@ -1122,16 +1144,16 @@ class O {
1122
1144
  */
1123
1145
  setApi(e, t = !1) {
1124
1146
  const i = this.apis.find(
1125
- (r) => r.name === e.name || r.id === e.id
1147
+ (a) => a.name === e.name || a.id === e.id
1126
1148
  );
1127
1149
  let s;
1128
1150
  if (i ? (s = "update", Object.assign(i, e)) : (s = "create", e.id = m(), this.apis.push(e)), !t) {
1129
- const r = {
1151
+ const a = {
1130
1152
  model: this,
1131
1153
  type: s,
1132
1154
  data: e
1133
1155
  };
1134
- n.emit(k, r), n.emit(c, r);
1156
+ n.emit(D, a), n.emit(h, a);
1135
1157
  }
1136
1158
  }
1137
1159
  /**
@@ -1147,7 +1169,7 @@ class O {
1147
1169
  type: "delete",
1148
1170
  data: e
1149
1171
  };
1150
- n.emit(k, s), n.emit(c, s);
1172
+ n.emit(D, s), n.emit(h, s);
1151
1173
  }
1152
1174
  }
1153
1175
  existApiName(e, t = []) {
@@ -1155,16 +1177,16 @@ class O {
1155
1177
  }
1156
1178
  setMeta(e, t = !1) {
1157
1179
  const i = this.meta.find(
1158
- (r) => r.code === e.code || r.id === e.id
1180
+ (a) => a.code === e.code || a.id === e.id
1159
1181
  );
1160
1182
  let s;
1161
1183
  if (i ? (s = "update", Object.assign(i, e)) : (s = "create", e.id = m(), this.meta.push(e)), !t) {
1162
- const r = {
1184
+ const a = {
1163
1185
  model: this,
1164
1186
  type: s,
1165
1187
  data: e
1166
1188
  };
1167
- n.emit(B, r), n.emit(c, r);
1189
+ n.emit(B, a), n.emit(h, a);
1168
1190
  }
1169
1191
  }
1170
1192
  removeMeta(e, t = !1) {
@@ -1175,7 +1197,7 @@ class O {
1175
1197
  type: "delete",
1176
1198
  data: e
1177
1199
  };
1178
- n.emit(B, s), n.emit(c, s);
1200
+ n.emit(B, s), n.emit(h, s);
1179
1201
  }
1180
1202
  }
1181
1203
  existMetaCode(e, t = []) {
@@ -1188,7 +1210,7 @@ class O {
1188
1210
  type: "update",
1189
1211
  data: e
1190
1212
  };
1191
- n.emit(c, i);
1213
+ n.emit(h, i);
1192
1214
  }
1193
1215
  }
1194
1216
  setConfig(e, t = !1) {
@@ -1198,7 +1220,7 @@ class O {
1198
1220
  type: "update",
1199
1221
  data: e
1200
1222
  };
1201
- n.emit(c, i);
1223
+ n.emit(h, i);
1202
1224
  }
1203
1225
  }
1204
1226
  publish(e) {
@@ -1210,7 +1232,7 @@ class O {
1210
1232
  e ? n.emit(j, t) : n.emit(U, t);
1211
1233
  }
1212
1234
  }
1213
- const N = "EVENT_HISTORY_CHANGE", P = "EVENT_HISTORY_LOAD";
1235
+ const g = "EVENT_HISTORY_CHANGE", I = "EVENT_HISTORY_LOAD";
1214
1236
  class Z {
1215
1237
  options = { max: 50 };
1216
1238
  index = -1;
@@ -1248,14 +1270,14 @@ class Z {
1248
1270
  dsl: b(e)
1249
1271
  };
1250
1272
  if (this.items.unshift(s), this.items.length > i) {
1251
- const r = this.items.splice(i);
1252
- t || n.emit(N, {
1273
+ const a = this.items.splice(i);
1274
+ t || n.emit(g, {
1253
1275
  model: this,
1254
1276
  type: "delete",
1255
- data: r.map((a) => a.id)
1277
+ data: a.map((r) => r.id)
1256
1278
  });
1257
1279
  }
1258
- this.index = -1, t || n.emit(N, {
1280
+ this.index = -1, t || n.emit(g, {
1259
1281
  model: this,
1260
1282
  type: "create",
1261
1283
  data: s
@@ -1268,7 +1290,7 @@ class Z {
1268
1290
  */
1269
1291
  remove(e, t = !1) {
1270
1292
  const i = this.items.findIndex((s) => s.id === e);
1271
- i > -1 ? (this.items.splice(i, 1), i === this.index ? this.index = -1 : this.index >= this.items.length && (this.index = this.items.length - 1)) : console.warn(`not found HistoryItem for id: ${e} `), t || n.emit(N, {
1293
+ i > -1 ? (this.items.splice(i, 1), i === this.index ? this.index = -1 : this.index >= this.items.length && (this.index = this.items.length - 1)) : console.warn(`not found HistoryItem for id: ${e} `), t || n.emit(g, {
1272
1294
  model: this,
1273
1295
  type: "delete",
1274
1296
  data: [e]
@@ -1279,7 +1301,7 @@ class Z {
1279
1301
  if (t < 0) return;
1280
1302
  --this.index;
1281
1303
  const s = i[this.index];
1282
- s && !e && n.emit(P, {
1304
+ s && !e && n.emit(I, {
1283
1305
  model: this,
1284
1306
  type: "load",
1285
1307
  data: s
@@ -1290,7 +1312,7 @@ class Z {
1290
1312
  if (t >= i.length - 1) return;
1291
1313
  t < 0 && (this.index = 0), ++this.index;
1292
1314
  const s = i[this.index];
1293
- s && !e && n.emit(P, {
1315
+ s && !e && n.emit(I, {
1294
1316
  model: this,
1295
1317
  type: "load",
1296
1318
  data: s
@@ -1298,7 +1320,7 @@ class Z {
1298
1320
  }
1299
1321
  load(e, t = !1) {
1300
1322
  const i = this.items.findIndex((s) => s.id === e);
1301
- i >= 0 && (this.index = i, t || n.emit(P, {
1323
+ i >= 0 && (this.index = i, t || n.emit(I, {
1302
1324
  model: this,
1303
1325
  type: "load",
1304
1326
  data: this.items[i]
@@ -1307,7 +1329,7 @@ class Z {
1307
1329
  clear(e = !1) {
1308
1330
  this.index = -1;
1309
1331
  const t = this.items.map((i) => i.id);
1310
- this.items = [], e || n.emit(N, {
1332
+ this.items = [], e || n.emit(g, {
1311
1333
  model: this,
1312
1334
  type: "clear",
1313
1335
  data: t
@@ -1315,31 +1337,31 @@ class Z {
1315
1337
  }
1316
1338
  }
1317
1339
  const n = F();
1318
- function ee(h) {
1319
- return h instanceof u;
1340
+ function ee(f) {
1341
+ return f instanceof u;
1320
1342
  }
1321
- function te(h) {
1322
- return h instanceof _;
1343
+ function te(f) {
1344
+ return f instanceof _;
1323
1345
  }
1324
- function ie(h) {
1325
- return !!h.__VTJ_BLOCK__;
1346
+ function ie(f) {
1347
+ return !!f.__VTJ_BLOCK__;
1326
1348
  }
1327
- function L(h) {
1328
- const e = b(h);
1349
+ function L(f) {
1350
+ const e = b(f);
1329
1351
  return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) => L(t))), e;
1330
1352
  }
1331
- function se(h) {
1332
- const e = h.fromType || "Schema";
1353
+ function se(f) {
1354
+ const e = f.fromType || "Schema";
1333
1355
  return e === "Schema" ? {
1334
1356
  type: "Schema",
1335
- id: h.id
1357
+ id: f.id
1336
1358
  } : e === "UrlSchema" ? {
1337
1359
  type: "UrlSchema",
1338
- url: (h.urls || "").split(",")[0] || ""
1360
+ url: (f.urls || "").split(",")[0] || ""
1339
1361
  } : e === "Plugin" ? {
1340
1362
  type: "Plugin",
1341
- urls: (h.urls || "").split(","),
1342
- library: h.library
1363
+ urls: (f.urls || "").split(","),
1364
+ library: f.library
1343
1365
  } : "";
1344
1366
  }
1345
1367
  export {
@@ -1354,22 +1376,22 @@ export {
1354
1376
  u as BlockModel,
1355
1377
  v as DirectiveModel,
1356
1378
  o as EVENT_BLOCK_CHANGE,
1357
- N as EVENT_HISTORY_CHANGE,
1358
- P as EVENT_HISTORY_LOAD,
1359
- d as EVENT_NODE_CHANGE,
1360
- R as EVENT_PROJECT_ACTIVED,
1361
- k as EVENT_PROJECT_APIS_CHANGE,
1362
- g as EVENT_PROJECT_BLOCKS_CHANGE,
1363
- c as EVENT_PROJECT_CHANGE,
1364
- D as EVENT_PROJECT_DEPS_CHANGE,
1379
+ g as EVENT_HISTORY_CHANGE,
1380
+ I as EVENT_HISTORY_LOAD,
1381
+ c as EVENT_NODE_CHANGE,
1382
+ k as EVENT_PROJECT_ACTIVED,
1383
+ D as EVENT_PROJECT_APIS_CHANGE,
1384
+ y as EVENT_PROJECT_BLOCKS_CHANGE,
1385
+ h as EVENT_PROJECT_CHANGE,
1386
+ R as EVENT_PROJECT_DEPS_CHANGE,
1365
1387
  j as EVENT_PROJECT_FILE_PUBLISH,
1366
1388
  B as EVENT_PROJECT_META_CHANGE,
1367
- T as EVENT_PROJECT_PAGES_CHANGE,
1389
+ N as EVENT_PROJECT_PAGES_CHANGE,
1368
1390
  U as EVENT_PROJECT_PUBLISH,
1369
- y as EventModel,
1391
+ T as EventModel,
1370
1392
  Z as HistoryModel,
1371
1393
  _ as NodeModel,
1372
- O as ProjectModel,
1394
+ V as ProjectModel,
1373
1395
  x as PropModel,
1374
1396
  Q as Service,
1375
1397
  M as VTJ_CORE_VERSION,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@vtj/core",
3
3
  "private": false,
4
- "version": "0.9.0-alpha.2",
4
+ "version": "0.9.0-alpha.4",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@vtj/base": "~0.9.0-alpha.0"
7
+ "@vtj/base": "~0.9.0-alpha.1"
8
8
  },
9
9
  "devDependencies": {
10
- "@vtj/cli": "~0.9.0-alpha.0"
10
+ "@vtj/cli": "~0.9.0-alpha.1"
11
11
  },
12
12
  "exports": {
13
13
  ".": {
@@ -114,6 +114,7 @@ export declare class ProjectModel {
114
114
  * @param silent
115
115
  */
116
116
  clonePage(page: PageFile, parentId?: string, silent?: boolean): void;
117
+ saveToBlock(page: PageFile, silent?: boolean): Promise<void>;
117
118
  /**
118
119
  * 删除页面或目录
119
120
  * @param id
@@ -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.9.0-alpha.1
5
+ * @version 0.9.0-alpha.3
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.9.0-alpha.1";
8
+ export declare const version = "0.9.0-alpha.3";