@vtj/core 0.9.0-alpha.3 → 0.9.0-alpha.30

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.3
5
+ * @version 0.9.0-alpha.30
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const b="0.9.0-alpha.3",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 J="0.9.0-alpha.30",G="BuiltIn",R="VueMaterial",B="VueRouterMaterial",U=[R,B],w={vue:"Vue","vue-router":"VueRouter"},F={[R]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[B]:["RouterView","RouterLink"]},M=["slot","template","component","img","div","p","h1","h2","h3","span","a"];class j{}class ${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:P}=this,T=Array.isArray(l)?l.map(b=>b.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(P)}}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",I="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",L="EVENT_PROJECT_GEN_SOURCE";class O{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 O.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=O.attrs.reduce((s,r)=>(s[r]=this[r],s),{});return i.pages&&(i.pages=i.pages.map(s=>o.cloneDeep({...s,dsl:void 0})),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>o.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(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,P=p.findIndex(T=>T.id===e.id);if(p.splice(P+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)}genSource(){const e={model:this,type:"gen",data:null};n.emit(L,e)}}const C="EVENT_HISTORY_CHANGE",x="EVENT_HISTORY_LOAD";class K{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 Y(m){return m instanceof u}function W(m){return m instanceof E}function q(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 z(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=F;exports.BUILT_IN_LIBRARAY_MAP=w;exports.BUILT_IN_MATERIALS=U;exports.BUILT_IN_NAME=G;exports.BUILT_IN_TAGS=M;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=B;exports.Base=$;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=I;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_GEN_SOURCE=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=y;exports.EVENT_PROJECT_PUBLISH=H;exports.EventModel=A;exports.HistoryModel=K;exports.NodeModel=E;exports.ProjectModel=O;exports.PropModel=v;exports.Service=j;exports.VTJ_CORE_VERSION=J;exports.cloneDsl=D;exports.createNodeFrom=z;exports.emitter=n;exports.isBlock=Y;exports.isBlockSchema=q;exports.isNode=W;
package/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
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, cloneDeep as C, upperFirstCamelCase as R, delay as O, merge as I, mitt as U } 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.3
6
+ * @version 0.9.0-alpha.30
7
7
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
8
8
  */
9
- const M = "0.9.0-alpha.3", K = "BuiltIn", w = "VueMaterial", H = "VueRouterMaterial", Y = [w, H], W = {
9
+ const K = "0.9.0-alpha.30", Y = "BuiltIn", w = "VueMaterial", H = "VueRouterMaterial", W = [w, H], q = {
10
10
  vue: "Vue",
11
11
  "vue-router": "VueRouter"
12
- }, q = {
12
+ }, z = {
13
13
  [w]: [
14
14
  "Transition",
15
15
  "TransitionGroup",
@@ -18,7 +18,7 @@ const M = "0.9.0-alpha.3", K = "BuiltIn", w = "VueMaterial", H = "VueRouterMater
18
18
  "Suspense"
19
19
  ],
20
20
  [H]: ["RouterView", "RouterLink"]
21
- }, z = [
21
+ }, Q = [
22
22
  "slot",
23
23
  "template",
24
24
  "component",
@@ -31,9 +31,9 @@ const M = "0.9.0-alpha.3", K = "BuiltIn", w = "VueMaterial", H = "VueRouterMater
31
31
  "span",
32
32
  "a"
33
33
  ];
34
- class Q {
35
- }
36
34
  class X {
35
+ }
36
+ class Z {
37
37
  listeners = [];
38
38
  isReady = !1;
39
39
  triggerReady() {
@@ -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
- events: C
394
- } = this, E = Array.isArray(l) ? l.map((J) => J.toDsl()) : l;
393
+ events: P
394
+ } = this, E = Array.isArray(d) ? d.map((L) => L.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(P)
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
  /**
@@ -756,7 +756,7 @@ class u {
756
756
  * @returns
757
757
  */
758
758
  cloneNode(e, t = !1) {
759
- const i = L(e.toDsl()), s = new _(i);
759
+ const i = J(e.toDsl()), s = new _(i);
760
760
  return this.addNode(s, e, "bottom", t), s;
761
761
  }
762
762
  lock(e = !1) {
@@ -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", D = "EVENT_PROJECT_DEPS_CHANGE", N = "EVENT_PROJECT_PAGES_CHANGE", y = "EVENT_PROJECT_BLOCKS_CHANGE", B = "EVENT_PROJECT_APIS_CHANGE", b = "EVENT_PROJECT_META_CHANGE", F = "EVENT_PROJECT_PUBLISH", j = "EVENT_PROJECT_FILE_PUBLISH", $ = "EVENT_PROJECT_GEN_SOURCE";
786
+ class S {
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 S.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,11 +831,17 @@ 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 = S.attrs.reduce(
835
+ (s, a) => (s[a] = this[a], s),
836
836
  {}
837
837
  );
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))), {
838
+ return i.pages && (i.pages = i.pages.map((s) => C({
839
+ ...s,
840
+ dsl: void 0
841
+ })), this.cleanPagesDsl(i.pages)), i.blocks && (i.blocks = i.blocks.map((s) => C({
842
+ ...s,
843
+ dsl: void 0
844
+ }))), {
839
845
  __VTJ_PROJECT__: !0,
840
846
  // __VERSION__: version || timestamp().toString(),
841
847
  id: t,
@@ -848,7 +854,7 @@ class O {
848
854
  * @param silent
849
855
  */
850
856
  active(e, t = !1) {
851
- this.currentFile = e, t || n.emit(R, {
857
+ this.currentFile = e, t || n.emit(k, {
852
858
  model: this,
853
859
  type: "update",
854
860
  data: e
@@ -859,7 +865,7 @@ class O {
859
865
  * @param silent
860
866
  */
861
867
  deactivate(e = !1) {
862
- this.currentFile = null, e || n.emit(R, {
868
+ this.currentFile = null, e || n.emit(k, {
863
869
  model: this,
864
870
  type: "update",
865
871
  data: null
@@ -871,18 +877,18 @@ class O {
871
877
  * @param silent
872
878
  */
873
879
  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, {
880
+ const i = this.dependencies, s = i.findIndex((r) => r.package === e.package);
881
+ let a;
882
+ if (s > -1 ? (a = "update", i.splice(s, 1, {
877
883
  ...i[s],
878
884
  ...e
879
- })) : (r = "create", i.push(e)), !t) {
880
- const a = {
885
+ })) : (a = "create", i.push(e)), !t) {
886
+ const r = {
881
887
  model: this,
882
- type: r,
888
+ type: a,
883
889
  data: e
884
890
  };
885
- n.emit(D, a), n.emit(c, a);
891
+ n.emit(D, r), n.emit(h, r);
886
892
  }
887
893
  }
888
894
  /**
@@ -891,14 +897,14 @@ class O {
891
897
  * @param silent
892
898
  */
893
899
  removeDeps(e, t = !1) {
894
- const i = this.dependencies, s = i.findIndex((r) => r.package === e.package);
900
+ const i = this.dependencies, s = i.findIndex((a) => a.package === e.package);
895
901
  if (s > -1 && i.splice(s, 1), !t) {
896
- const r = {
902
+ const a = {
897
903
  model: this,
898
904
  type: "delete",
899
905
  data: e
900
906
  };
901
- n.emit(D, r), n.emit(c, r);
907
+ n.emit(D, a), n.emit(h, a);
902
908
  }
903
909
  }
904
910
  /**
@@ -908,13 +914,13 @@ class O {
908
914
  */
909
915
  getPage(e) {
910
916
  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;
917
+ for (const a of s) {
918
+ if (a.id === i)
919
+ return a;
920
+ if (a.children && a.children.length) {
921
+ const r = t(i, a.children);
922
+ if (r)
923
+ return r;
918
924
  }
919
925
  }
920
926
  };
@@ -942,7 +948,7 @@ class O {
942
948
  async createPage(e, t, i = !1) {
943
949
  if (e.id = e.raw ? e.name : e.id || m(), e.type = "page", e.dir ? e.children = [] : e.dsl = e.dsl || new u({
944
950
  id: e.id,
945
- name: I(e.name)
951
+ name: R(e.name)
946
952
  }).toDsl(), t) {
947
953
  const s = this.getPage(t);
948
954
  s ? s.children ? s.children.push(e) : s.children = [e] : console.warn(`not found PageFile for id: ${t} `);
@@ -954,9 +960,9 @@ class O {
954
960
  type: "create",
955
961
  data: e
956
962
  };
957
- n.emit(T, s), n.emit(c, s);
963
+ n.emit(N, s), n.emit(h, s);
958
964
  }
959
- !this.currentFile && !e.dir && (await V(1e3), this.active(e, i));
965
+ !this.currentFile && !e.dir && (await O(1e3), this.active(e, i));
960
966
  }
961
967
  /**
962
968
  * 更新页面
@@ -971,7 +977,7 @@ class O {
971
977
  type: "update",
972
978
  data: e
973
979
  };
974
- n.emit(T, s), n.emit(c, s);
980
+ n.emit(N, s), n.emit(h, s);
975
981
  }
976
982
  }
977
983
  /**
@@ -981,20 +987,42 @@ class O {
981
987
  * @param silent
982
988
  */
983
989
  clonePage(e, t, i = !1) {
984
- const s = m(), r = `${e.name}Copy`, a = `${e.title}_副本`, l = new u({
990
+ const s = m(), a = `${e.name}Copy`, r = `${e.title}_副本`, d = new u({
985
991
  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) {
992
+ name: a
993
+ }).toDsl(), l = I({}, e, { id: s, name: a, title: r, dsl: d }), p = t ? this.getPage(t)?.children || [] : this.pages, P = p.findIndex((E) => E.id === e.id);
994
+ if (p.splice(P + 1, 0, l), !i) {
989
995
  const E = {
990
996
  model: this,
991
997
  type: "clone",
992
998
  data: {
993
999
  source: e,
994
- target: f
1000
+ target: l
995
1001
  }
996
1002
  };
997
- n.emit(T, E), n.emit(c, E);
1003
+ n.emit(N, E), n.emit(h, E);
1004
+ }
1005
+ }
1006
+ async saveToBlock(e, t = !1) {
1007
+ this.active(e, t), await O(1e3);
1008
+ const i = m(), s = e.name, a = e.title, r = new u({
1009
+ id: i,
1010
+ name: s
1011
+ }).toDsl(), d = I({}, e, {
1012
+ id: i,
1013
+ name: s,
1014
+ title: a,
1015
+ dsl: r,
1016
+ type: "block",
1017
+ fromType: "Schema"
1018
+ });
1019
+ if (this.blocks.push(d), !t) {
1020
+ const l = {
1021
+ model: this,
1022
+ type: "create",
1023
+ data: d
1024
+ };
1025
+ n.emit(y, l), n.emit(h, l);
998
1026
  }
999
1027
  }
1000
1028
  /**
@@ -1003,22 +1031,22 @@ class O {
1003
1031
  * @param silent
1004
1032
  */
1005
1033
  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);
1034
+ const i = this.getPage(e), s = (a, r) => {
1035
+ const d = r.findIndex((l) => l.id === a);
1036
+ if (d >= 0) {
1037
+ r.splice(d, 1);
1010
1038
  return;
1011
1039
  }
1012
- for (const f of a)
1013
- f.children && f.children.length && s(r, f.children);
1040
+ for (const l of r)
1041
+ l.children && l.children.length && s(a, l.children);
1014
1042
  };
1015
1043
  if (s(e, this.pages), e === this.homepage && (this.homepage = ""), this.currentFile?.id === e && this.deactivate(t), !t) {
1016
- const r = {
1044
+ const a = {
1017
1045
  model: this,
1018
1046
  type: "delete",
1019
1047
  data: i
1020
1048
  };
1021
- n.emit(T, r), n.emit(c, r);
1049
+ n.emit(N, a), n.emit(h, a);
1022
1050
  }
1023
1051
  }
1024
1052
  /**
@@ -1035,18 +1063,18 @@ class O {
1035
1063
  * @param silent
1036
1064
  */
1037
1065
  async createBlock(e, t = !1) {
1038
- const i = e.id || m(), s = I(e.name);
1066
+ const i = e.id || m(), s = R(e.name);
1039
1067
  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";
1068
+ const a = e.fromType || "Schema";
1041
1069
  if (!t) {
1042
- const a = {
1070
+ const r = {
1043
1071
  model: this,
1044
1072
  type: "create",
1045
1073
  data: e
1046
1074
  };
1047
- n.emit(g, a), n.emit(c, a);
1075
+ n.emit(y, r), n.emit(h, r);
1048
1076
  }
1049
- !this.currentFile && r === "Schema" && (await V(1e3), this.active(e, t));
1077
+ !this.currentFile && a === "Schema" && (await O(1e3), this.active(e, t));
1050
1078
  }
1051
1079
  /**
1052
1080
  *
@@ -1061,24 +1089,24 @@ class O {
1061
1089
  type: "update",
1062
1090
  data: e
1063
1091
  };
1064
- n.emit(g, s), n.emit(c, s);
1092
+ n.emit(y, s), n.emit(h, s);
1065
1093
  }
1066
1094
  }
1067
1095
  cloneBlock(e, t = !1) {
1068
- const i = m(), s = `${e.name}Copy`, r = `${e.title}_副本`, a = new u({
1096
+ const i = m(), s = `${e.name}Copy`, a = `${e.title}_副本`, r = new u({
1069
1097
  id: i,
1070
1098
  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) {
1099
+ }).toDsl(), d = I({}, e, { id: i, name: s, title: a, dsl: r }), l = this.blocks.findIndex((p) => p.id === e.id);
1100
+ if (this.blocks.splice(l + 1, 0, d), !t) {
1073
1101
  const p = {
1074
1102
  model: this,
1075
1103
  type: "clone",
1076
1104
  data: {
1077
1105
  source: e,
1078
- target: l
1106
+ target: d
1079
1107
  }
1080
1108
  };
1081
- n.emit(g, p), n.emit(c, p);
1109
+ n.emit(y, p), n.emit(h, p);
1082
1110
  }
1083
1111
  }
1084
1112
  /**
@@ -1087,14 +1115,14 @@ class O {
1087
1115
  * @param silent
1088
1116
  */
1089
1117
  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 = {
1118
+ const i = this.getBlock(e), s = this.blocks, a = s.findIndex((r) => r.id === e);
1119
+ if (a > -1 ? (s.splice(a, 1), this.currentFile?.id === e && this.deactivate(t)) : console.warn(`not found PageFile for id: ${e} `), !t) {
1120
+ const r = {
1093
1121
  model: this,
1094
1122
  type: "delete",
1095
1123
  data: i
1096
1124
  };
1097
- n.emit(g, a), n.emit(c, a);
1125
+ n.emit(y, r), n.emit(h, r);
1098
1126
  }
1099
1127
  }
1100
1128
  /**
@@ -1122,16 +1150,16 @@ class O {
1122
1150
  */
1123
1151
  setApi(e, t = !1) {
1124
1152
  const i = this.apis.find(
1125
- (r) => r.name === e.name || r.id === e.id
1153
+ (a) => a.name === e.name || a.id === e.id
1126
1154
  );
1127
1155
  let s;
1128
1156
  if (i ? (s = "update", Object.assign(i, e)) : (s = "create", e.id = m(), this.apis.push(e)), !t) {
1129
- const r = {
1157
+ const a = {
1130
1158
  model: this,
1131
1159
  type: s,
1132
1160
  data: e
1133
1161
  };
1134
- n.emit(k, r), n.emit(c, r);
1162
+ n.emit(B, a), n.emit(h, a);
1135
1163
  }
1136
1164
  }
1137
1165
  /**
@@ -1147,7 +1175,7 @@ class O {
1147
1175
  type: "delete",
1148
1176
  data: e
1149
1177
  };
1150
- n.emit(k, s), n.emit(c, s);
1178
+ n.emit(B, s), n.emit(h, s);
1151
1179
  }
1152
1180
  }
1153
1181
  existApiName(e, t = []) {
@@ -1155,16 +1183,16 @@ class O {
1155
1183
  }
1156
1184
  setMeta(e, t = !1) {
1157
1185
  const i = this.meta.find(
1158
- (r) => r.code === e.code || r.id === e.id
1186
+ (a) => a.code === e.code || a.id === e.id
1159
1187
  );
1160
1188
  let s;
1161
1189
  if (i ? (s = "update", Object.assign(i, e)) : (s = "create", e.id = m(), this.meta.push(e)), !t) {
1162
- const r = {
1190
+ const a = {
1163
1191
  model: this,
1164
1192
  type: s,
1165
1193
  data: e
1166
1194
  };
1167
- n.emit(B, r), n.emit(c, r);
1195
+ n.emit(b, a), n.emit(h, a);
1168
1196
  }
1169
1197
  }
1170
1198
  removeMeta(e, t = !1) {
@@ -1175,7 +1203,7 @@ class O {
1175
1203
  type: "delete",
1176
1204
  data: e
1177
1205
  };
1178
- n.emit(B, s), n.emit(c, s);
1206
+ n.emit(b, s), n.emit(h, s);
1179
1207
  }
1180
1208
  }
1181
1209
  existMetaCode(e, t = []) {
@@ -1188,7 +1216,7 @@ class O {
1188
1216
  type: "update",
1189
1217
  data: e
1190
1218
  };
1191
- n.emit(c, i);
1219
+ n.emit(h, i);
1192
1220
  }
1193
1221
  }
1194
1222
  setConfig(e, t = !1) {
@@ -1198,7 +1226,7 @@ class O {
1198
1226
  type: "update",
1199
1227
  data: e
1200
1228
  };
1201
- n.emit(c, i);
1229
+ n.emit(h, i);
1202
1230
  }
1203
1231
  }
1204
1232
  publish(e) {
@@ -1207,11 +1235,19 @@ class O {
1207
1235
  type: "publish",
1208
1236
  data: e || this
1209
1237
  };
1210
- e ? n.emit(j, t) : n.emit(U, t);
1238
+ e ? n.emit(j, t) : n.emit(F, t);
1239
+ }
1240
+ genSource() {
1241
+ const e = {
1242
+ model: this,
1243
+ type: "gen",
1244
+ data: null
1245
+ };
1246
+ n.emit($, e);
1211
1247
  }
1212
1248
  }
1213
- const N = "EVENT_HISTORY_CHANGE", P = "EVENT_HISTORY_LOAD";
1214
- class Z {
1249
+ const g = "EVENT_HISTORY_CHANGE", V = "EVENT_HISTORY_LOAD";
1250
+ class ee {
1215
1251
  options = { max: 50 };
1216
1252
  index = -1;
1217
1253
  id;
@@ -1245,17 +1281,17 @@ class Z {
1245
1281
  const { max: i } = this.options, s = {
1246
1282
  id: m(),
1247
1283
  label: (/* @__PURE__ */ new Date()).toLocaleString(),
1248
- dsl: b(e)
1284
+ dsl: C(e)
1249
1285
  };
1250
1286
  if (this.items.unshift(s), this.items.length > i) {
1251
- const r = this.items.splice(i);
1252
- t || n.emit(N, {
1287
+ const a = this.items.splice(i);
1288
+ t || n.emit(g, {
1253
1289
  model: this,
1254
1290
  type: "delete",
1255
- data: r.map((a) => a.id)
1291
+ data: a.map((r) => r.id)
1256
1292
  });
1257
1293
  }
1258
- this.index = -1, t || n.emit(N, {
1294
+ this.index = -1, t || n.emit(g, {
1259
1295
  model: this,
1260
1296
  type: "create",
1261
1297
  data: s
@@ -1268,7 +1304,7 @@ class Z {
1268
1304
  */
1269
1305
  remove(e, t = !1) {
1270
1306
  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, {
1307
+ 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
1308
  model: this,
1273
1309
  type: "delete",
1274
1310
  data: [e]
@@ -1279,7 +1315,7 @@ class Z {
1279
1315
  if (t < 0) return;
1280
1316
  --this.index;
1281
1317
  const s = i[this.index];
1282
- s && !e && n.emit(P, {
1318
+ s && !e && n.emit(V, {
1283
1319
  model: this,
1284
1320
  type: "load",
1285
1321
  data: s
@@ -1290,7 +1326,7 @@ class Z {
1290
1326
  if (t >= i.length - 1) return;
1291
1327
  t < 0 && (this.index = 0), ++this.index;
1292
1328
  const s = i[this.index];
1293
- s && !e && n.emit(P, {
1329
+ s && !e && n.emit(V, {
1294
1330
  model: this,
1295
1331
  type: "load",
1296
1332
  data: s
@@ -1298,7 +1334,7 @@ class Z {
1298
1334
  }
1299
1335
  load(e, t = !1) {
1300
1336
  const i = this.items.findIndex((s) => s.id === e);
1301
- i >= 0 && (this.index = i, t || n.emit(P, {
1337
+ i >= 0 && (this.index = i, t || n.emit(V, {
1302
1338
  model: this,
1303
1339
  type: "load",
1304
1340
  data: this.items[i]
@@ -1307,76 +1343,77 @@ class Z {
1307
1343
  clear(e = !1) {
1308
1344
  this.index = -1;
1309
1345
  const t = this.items.map((i) => i.id);
1310
- this.items = [], e || n.emit(N, {
1346
+ this.items = [], e || n.emit(g, {
1311
1347
  model: this,
1312
1348
  type: "clear",
1313
1349
  data: t
1314
1350
  });
1315
1351
  }
1316
1352
  }
1317
- const n = F();
1318
- function ee(h) {
1319
- return h instanceof u;
1353
+ const n = U();
1354
+ function te(f) {
1355
+ return f instanceof u;
1320
1356
  }
1321
- function te(h) {
1322
- return h instanceof _;
1357
+ function ie(f) {
1358
+ return f instanceof _;
1323
1359
  }
1324
- function ie(h) {
1325
- return !!h.__VTJ_BLOCK__;
1360
+ function se(f) {
1361
+ return !!f.__VTJ_BLOCK__;
1326
1362
  }
1327
- function L(h) {
1328
- const e = b(h);
1329
- return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) => L(t))), e;
1363
+ function J(f) {
1364
+ const e = C(f);
1365
+ return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) => J(t))), e;
1330
1366
  }
1331
- function se(h) {
1332
- const e = h.fromType || "Schema";
1367
+ function ne(f) {
1368
+ const e = f.fromType || "Schema";
1333
1369
  return e === "Schema" ? {
1334
1370
  type: "Schema",
1335
- id: h.id
1371
+ id: f.id
1336
1372
  } : e === "UrlSchema" ? {
1337
1373
  type: "UrlSchema",
1338
- url: (h.urls || "").split(",")[0] || ""
1374
+ url: (f.urls || "").split(",")[0] || ""
1339
1375
  } : e === "Plugin" ? {
1340
1376
  type: "Plugin",
1341
- urls: (h.urls || "").split(","),
1342
- library: h.library
1377
+ urls: (f.urls || "").split(","),
1378
+ library: f.library
1343
1379
  } : "";
1344
1380
  }
1345
1381
  export {
1346
- q as BUILT_IN_COMPONENTS,
1347
- W as BUILT_IN_LIBRARAY_MAP,
1348
- Y as BUILT_IN_MATERIALS,
1349
- K as BUILT_IN_NAME,
1350
- z as BUILT_IN_TAGS,
1382
+ z as BUILT_IN_COMPONENTS,
1383
+ q as BUILT_IN_LIBRARAY_MAP,
1384
+ W as BUILT_IN_MATERIALS,
1385
+ Y as BUILT_IN_NAME,
1386
+ Q as BUILT_IN_TAGS,
1351
1387
  w as BUILT_IN_VUE,
1352
1388
  H as BUILT_IN_VUE_ROUTER,
1353
- X as Base,
1389
+ Z as Base,
1354
1390
  u as BlockModel,
1355
1391
  v as DirectiveModel,
1356
1392
  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,
1393
+ g as EVENT_HISTORY_CHANGE,
1394
+ V as EVENT_HISTORY_LOAD,
1395
+ c as EVENT_NODE_CHANGE,
1396
+ k as EVENT_PROJECT_ACTIVED,
1397
+ B as EVENT_PROJECT_APIS_CHANGE,
1398
+ y as EVENT_PROJECT_BLOCKS_CHANGE,
1399
+ h as EVENT_PROJECT_CHANGE,
1364
1400
  D as EVENT_PROJECT_DEPS_CHANGE,
1365
1401
  j as EVENT_PROJECT_FILE_PUBLISH,
1366
- B as EVENT_PROJECT_META_CHANGE,
1367
- T as EVENT_PROJECT_PAGES_CHANGE,
1368
- U as EVENT_PROJECT_PUBLISH,
1369
- y as EventModel,
1370
- Z as HistoryModel,
1402
+ $ as EVENT_PROJECT_GEN_SOURCE,
1403
+ b as EVENT_PROJECT_META_CHANGE,
1404
+ N as EVENT_PROJECT_PAGES_CHANGE,
1405
+ F as EVENT_PROJECT_PUBLISH,
1406
+ T as EventModel,
1407
+ ee as HistoryModel,
1371
1408
  _ as NodeModel,
1372
- O as ProjectModel,
1409
+ S as ProjectModel,
1373
1410
  x as PropModel,
1374
- Q as Service,
1375
- M as VTJ_CORE_VERSION,
1376
- L as cloneDsl,
1377
- se as createNodeFrom,
1411
+ X as Service,
1412
+ K as VTJ_CORE_VERSION,
1413
+ J as cloneDsl,
1414
+ ne as createNodeFrom,
1378
1415
  n as emitter,
1379
- ee as isBlock,
1380
- ie as isBlockSchema,
1381
- te as isNode
1416
+ te as isBlock,
1417
+ se as isBlockSchema,
1418
+ ie as isNode
1382
1419
  };
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.3",
4
+ "version": "0.9.0-alpha.30",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@vtj/base": "~0.9.0-alpha.0"
7
+ "@vtj/base": "~0.9.0-alpha.2"
8
8
  },
9
9
  "devDependencies": {
10
- "@vtj/cli": "~0.9.0-alpha.0"
10
+ "@vtj/cli": "~0.9.0-alpha.2"
11
11
  },
12
12
  "exports": {
13
13
  ".": {
@@ -1,6 +1,6 @@
1
1
  export declare class Base {
2
2
  protected listeners: Array<() => void>;
3
- protected isReady: boolean;
3
+ isReady: boolean;
4
4
  protected triggerReady(): void;
5
5
  ready(callback: () => void): void;
6
6
  resetReady(): void;
@@ -41,6 +41,10 @@ export declare const EVENT_PROJECT_PUBLISH = "EVENT_PROJECT_PUBLISH";
41
41
  * 项目文件发布
42
42
  */
43
43
  export declare const EVENT_PROJECT_FILE_PUBLISH = "EVENT_PROJECT_FILE_PUBLISH";
44
+ /**
45
+ * 出码
46
+ */
47
+ export declare const EVENT_PROJECT_GEN_SOURCE = "EVENT_PROJECT_GEN_SOURCE";
44
48
  export declare class ProjectModel {
45
49
  id: string;
46
50
  name: string;
@@ -114,6 +118,7 @@ export declare class ProjectModel {
114
118
  * @param silent
115
119
  */
116
120
  clonePage(page: PageFile, parentId?: string, silent?: boolean): void;
121
+ saveToBlock(page: PageFile, silent?: boolean): Promise<void>;
117
122
  /**
118
123
  * 删除页面或目录
119
124
  * @param id
@@ -178,4 +183,5 @@ export declare class ProjectModel {
178
183
  setHomepage(id: string, silent?: boolean): void;
179
184
  setConfig(config: ProjectConfig, silent?: boolean): void;
180
185
  publish(file?: PageFile | BlockFile): void;
186
+ genSource(): void;
181
187
  }
@@ -94,6 +94,10 @@ export interface PageFile extends BlockFile {
94
94
  * 纯净的页面
95
95
  */
96
96
  pure?: boolean;
97
+ /**
98
+ * 开启页面缓存
99
+ */
100
+ cache?: boolean;
97
101
  /**
98
102
  * 路由元信息
99
103
  */
@@ -3,26 +3,27 @@ import { MaterialDescription } from './assets';
3
3
  import { StaticFileInfo, ExtensionConfig } from './shared';
4
4
  export declare abstract class Service {
5
5
  abstract getExtension(): Promise<ExtensionConfig | undefined>;
6
- abstract init(project: ProjectSchema): Promise<ProjectSchema>;
6
+ abstract init(project: Partial<ProjectSchema>): Promise<ProjectSchema>;
7
7
  abstract saveProject(project: ProjectSchema): Promise<boolean>;
8
8
  abstract saveMaterials(project: ProjectSchema, materials: Map<string, MaterialDescription>): Promise<boolean>;
9
- abstract saveFile(file: BlockSchema): Promise<boolean>;
10
- abstract getFile(id: string): Promise<BlockSchema>;
11
- abstract removeFile(id: string): Promise<boolean>;
12
- abstract saveHistory(history: HistorySchema): Promise<boolean>;
13
- abstract removeHistory(id: string): Promise<boolean>;
14
- abstract getHistory(id: string): Promise<HistorySchema>;
15
- abstract getHistoryItem(fId: string, id: string): Promise<HistoryItem>;
16
- abstract saveHistoryItem(fId: string, item: HistoryItem): Promise<boolean>;
17
- abstract removeHistoryItem(fId: string, ids: string[]): Promise<boolean>;
9
+ abstract saveFile(file: BlockSchema, project?: ProjectSchema): Promise<boolean>;
10
+ abstract getFile(id: string, project?: ProjectSchema): Promise<BlockSchema>;
11
+ abstract removeFile(id: string, project?: ProjectSchema): Promise<boolean>;
12
+ abstract saveHistory(history: HistorySchema, project?: ProjectSchema): Promise<boolean>;
13
+ abstract removeHistory(id: string, project?: ProjectSchema): Promise<boolean>;
14
+ abstract getHistory(id: string, project?: ProjectSchema): Promise<HistorySchema>;
15
+ abstract getHistoryItem(fId: string, id: string, project?: ProjectSchema): Promise<HistoryItem>;
16
+ abstract saveHistoryItem(fId: string, item: HistoryItem, project?: ProjectSchema): Promise<boolean>;
17
+ abstract removeHistoryItem(fId: string, ids: string[], project?: ProjectSchema): Promise<boolean>;
18
18
  abstract publish(project: ProjectSchema): Promise<boolean>;
19
19
  abstract publishFile(project: ProjectSchema, file: PageFile | BlockFile): Promise<boolean>;
20
20
  abstract genVueContent(project: ProjectSchema, dsl: BlockSchema): Promise<string>;
21
- abstract createRawPage(file: PageFile): Promise<boolean>;
22
- abstract removeRawPage(id: string): Promise<boolean>;
21
+ abstract createRawPage(file: PageFile, project?: ProjectSchema): Promise<boolean>;
22
+ abstract removeRawPage(id: string, project?: ProjectSchema): Promise<boolean>;
23
23
  abstract uploadStaticFile(file: File, projectId: string): Promise<StaticFileInfo | null>;
24
24
  abstract getStaticFiles(projectId: string): Promise<StaticFileInfo[]>;
25
25
  abstract removeStaticFile(name: string, projectId: string): Promise<boolean>;
26
26
  abstract clearStaticFiles(projectId: string): Promise<boolean>;
27
27
  abstract getPluginMaterial(from: NodeFromPlugin): Promise<MaterialDescription | null>;
28
+ abstract genSource(project: ProjectSchema): Promise<string>;
28
29
  }
@@ -55,6 +55,10 @@ export interface ExtensionConfig {
55
55
  * 附加参数/数据,用作个性需求
56
56
  */
57
57
  params?: Array<Record<string, any>>;
58
+ /**
59
+ * 路由History模式
60
+ */
61
+ history?: 'hash' | 'web';
58
62
  /**
59
63
  * 项目部署目录
60
64
  */
@@ -1,4 +1,4 @@
1
- import { ProjectModelEvent, BlockModel, NodeModel, HistoryModelEvent, EVENT_PROJECT_CHANGE, EVENT_PROJECT_ACTIVED, EVENT_PROJECT_DEPS_CHANGE, EVENT_PROJECT_PAGES_CHANGE, EVENT_PROJECT_BLOCKS_CHANGE, EVENT_PROJECT_APIS_CHANGE, EVENT_PROJECT_META_CHANGE, EVENT_PROJECT_PUBLISH, EVENT_PROJECT_FILE_PUBLISH, EVENT_BLOCK_CHANGE, EVENT_NODE_CHANGE, EVENT_HISTORY_CHANGE, EVENT_HISTORY_LOAD } from '../models';
1
+ import { ProjectModelEvent, BlockModel, NodeModel, HistoryModelEvent, EVENT_PROJECT_CHANGE, EVENT_PROJECT_ACTIVED, EVENT_PROJECT_DEPS_CHANGE, EVENT_PROJECT_PAGES_CHANGE, EVENT_PROJECT_BLOCKS_CHANGE, EVENT_PROJECT_APIS_CHANGE, EVENT_PROJECT_META_CHANGE, EVENT_PROJECT_PUBLISH, EVENT_PROJECT_FILE_PUBLISH, EVENT_BLOCK_CHANGE, EVENT_NODE_CHANGE, EVENT_HISTORY_CHANGE, EVENT_HISTORY_LOAD, EVENT_PROJECT_GEN_SOURCE } from '../models';
2
2
  import { Emitter } from 'mitt';
3
3
  type Events = {
4
4
  [EVENT_PROJECT_CHANGE]: ProjectModelEvent;
@@ -14,6 +14,7 @@ type Events = {
14
14
  [EVENT_NODE_CHANGE]: NodeModel;
15
15
  [EVENT_HISTORY_CHANGE]: HistoryModelEvent;
16
16
  [EVENT_HISTORY_LOAD]: HistoryModelEvent;
17
+ [EVENT_PROJECT_GEN_SOURCE]: ProjectModelEvent;
17
18
  };
18
19
  export declare const emitter: Emitter<Events>;
19
20
  export type Emitter = {
@@ -24,5 +25,5 @@ export type Emitter = {
24
25
  clear(): void;
25
26
  };
26
27
  };
27
- export type ModelEventType = 'create' | 'update' | 'delete' | 'clone' | 'clear' | 'load' | 'publish';
28
+ export type ModelEventType = 'create' | 'update' | 'delete' | 'clone' | 'clear' | 'load' | 'publish' | 'gen';
28
29
  export {};
@@ -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.3
5
+ * @version 0.9.0-alpha.29
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.9.0-alpha.3";
8
+ export declare const version = "0.9.0-alpha.29";