@vtj/core 0.11.16 → 0.12.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.
|
|
5
|
+
* @version 0.12.0-alpha.1
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const J="0.11.16",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 C{constructor(e){this.schema=e;const{name:t,handler:i}=this.schema;this.name=t,this.handler=i,this.update(e)}name;handler;modifiers={};update(e){Object.assign(this.schema,e);const{handler:t,modifiers:i={}}=this.schema;this.handler=t,this.modifiers=i}static toDsl(e){return Object.entries(e).reduce((t,[i,s])=>{const{handler:a,modifiers:r}=s;return t[i]={name:i,handler:a,modifiers:r},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new C(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:a,iterator:r}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=a,this.iterator=r}static parse(e=[]){return e.map(t=>new _(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:a,value:r,iterator:l,id:f}=t;return{id:f,name:i,arg:s,modifiers:a,value:r,iterator:l}})}}const c="EVENT_NODE_CHANGE";class E{constructor(e,t=null){this.parent=t;const{id:i=o.uid(),name:s,from:a=""}=e;this.id=i,this.name=s,this.from=a,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:a=[],slot:r,props:l={},events:f={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(a,!0),this.setSlot(r,!0),this.props=v.parse(l),this.events=C.parse(f),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 a=this.props[e];a?a.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 C(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=e instanceof _?e:new _(e),s=this.directives.findIndex(a=>a.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||n.emit(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 a=i.findIndex(r=>r===e);e.parent=null,i.splice(a,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:a,slot:r,children:l,props:f,directives:p,events:O}=this,T=Array.isArray(l)?l.map(b=>b.toDsl()):l;return{id:e,name:t,from:i,invisible:s,locked:a,slot:r,children:T,props:v.toDsl(f),directives:_.toDsl(p),events:C.toDsl(O)}}dispose(e=!1){const{children:t,disposed:i}=this;i||(Array.isArray(t)&&t.forEach(s=>s.dispose(!0)),this.parent?this.parent.removeChild(this,e):e||n.emit(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 a=e[s];a&&(this[s]=a)}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((r,l)=>(r[l]=this[l],r),{}),__VTJ_BLOCK__:t,__VERSION__:e||o.timestamp().toString(),id:i,nodes:s.map(r=>r.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(a=>a===i.name||a===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(a=>a===i.name||a===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 h="EVENT_PROJECT_CHANGE",P="EVENT_PROJECT_ACTIVED",I="EVENT_PROJECT_DEPS_CHANGE",A="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 x{id="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};__BASE_PATH__="/";static attrs=["platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","__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 x.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=x.attrs.reduce((s,a)=>(s[a]=this[a],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(P,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||n.emit(P,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(r=>r.package===e.package);let a;if(s>-1?(a="update",i.splice(s,1,{...i[s],...e})):(a="create",i.push(e)),!t){const r={model:this,type:a,data:e};n.emit(I,r),n.emit(h,r)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(a=>a.package===e.package);if(s>-1&&i.splice(s,1),!t){const a={model:this,type:"delete",data:e};n.emit(I,a),n.emit(h,a)}}getPage(e){const t=(i,s=[])=>{for(const a of s){if(a.id===i)return a;if(a.children&&a.children.length){const r=t(i,a.children);if(r)return r}}};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(A,s),n.emit(h,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(A,s),n.emit(h,s)}}clonePage(e,t,i=!1){const s=o.uid(),a=`${e.name}Copy`,r=`${e.title}_副本`,l=new u({id:s,name:a}).toDsl(),f=o.merge({},e,{id:s,name:a,title:r,dsl:l}),p=t?this.getPage(t)?.children||[]:this.pages,O=p.findIndex(T=>T.id===e.id);if(p.splice(O+1,0,f),!i){const T={model:this,type:"clone",data:{source:e,target:f}};n.emit(A,T),n.emit(h,T)}}async saveToBlock(e,t=!1){this.active(e,t),await o.delay(1e3);const i=o.uid(),s=e.name,a=e.title,r=new u({id:i,name:s}).toDsl(),l=o.merge({},e,{id:i,name:s,title:a,dsl:r,type:"block",fromType:"Schema"});if(this.blocks.push(l),!t){const f={model:this,type:"create",data:l};n.emit(N,f),n.emit(h,f)}}removePage(e,t=!1){const i=this.getPage(e),s=(a,r)=>{const l=r.findIndex(f=>f.id===a);if(l>=0){r.splice(l,1);return}for(const f of r)f.children&&f.children.length&&s(a,f.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const a={model:this,type:"delete",data:i};n.emit(A,a),n.emit(h,a)}}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 a=e.fromType||"Schema";if(!t){const r={model:this,type:"create",data:e};n.emit(N,r),n.emit(h,r)}!this.currentFile&&a==="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(h,s)}}cloneBlock(e,t=!1){const i=o.uid(),s=`${e.name}Copy`,a=`${e.title}_副本`,r=new u({id:i,name:s}).toDsl(),l=o.merge({},e,{id:i,name:s,title:a,dsl:r}),f=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(f+1,0,l),!t){const p={model:this,type:"clone",data:{source:e,target:l}};n.emit(N,p),n.emit(h,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,a=s.findIndex(r=>r.id===e);if(a>-1?(s.splice(a,1),this.currentFile?.id===e&&this.deactivate(t)):console.warn(`not found PageFile for id: ${e} `),!t){const r={model:this,type:"delete",data:i};n.emit(N,r),n.emit(h,r)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(a=>a.name===e.name||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=o.uid(),this.apis.push(e)),!t){const a={model:this,type:s,data:e};n.emit(V,a),n.emit(h,a)}}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(a=>a.code===e.code||a.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 a={model:this,type:s,data:e};n.emit(S,a),n.emit(h,a)}}removeMeta(e,t=!1){const i=this.meta.findIndex(s=>s.code===e||s.id===e);if(i>-1?this.meta.splice(i,1):console.warn(`not found meta for name: ${name} `),!t){const s={model:this,type:"delete",data:e};n.emit(S,s),n.emit(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)}}setUniConfig(e,t,i=!1){if(this.uniConfig=Object.assign(this.uniConfig,{[e]:t}),!i){const s={model:this,type:"update",data:this.uniConfig};n.emit(h,s)}}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 y="EVENT_HISTORY_CHANGE",g="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 a=this.items.splice(i);t||n.emit(y,{model:this,type:"delete",data:a.map(r=>r.id)})}this.index=-1,t||n.emit(y,{model:this,type:"create",data:s})}remove(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>-1?(this.items.splice(i,1),i===this.index?this.index=-1:this.index>=this.items.length&&(this.index=this.items.length-1)):console.warn(`not found HistoryItem for id: ${e} `),t||n.emit(y,{model:this,type:"delete",data:[e]})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&n.emit(g,{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(g,{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(g,{model:this,type:"load",data:this.items[i]}))}clear(e=!1){this.index=-1;const t=this.items.map(i=>i.id);this.items=[],e||n.emit(y,{model:this,type:"clear",data:t})}}const n=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=y;exports.EVENT_HISTORY_LOAD=g;exports.EVENT_NODE_CHANGE=c;exports.EVENT_PROJECT_ACTIVED=P;exports.EVENT_PROJECT_APIS_CHANGE=V;exports.EVENT_PROJECT_BLOCKS_CHANGE=N;exports.EVENT_PROJECT_CHANGE=h;exports.EVENT_PROJECT_DEPS_CHANGE=I;exports.EVENT_PROJECT_FILE_PUBLISH=k;exports.EVENT_PROJECT_GEN_SOURCE=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=A;exports.EVENT_PROJECT_PUBLISH=H;exports.EventModel=C;exports.HistoryModel=K;exports.NodeModel=E;exports.ProjectModel=x;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;
|
|
7
|
+
*/const U="0.12.0-alpha.1",J="BuiltIn",R="VueMaterial",B="VueRouterMaterial",G=[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 C{constructor(e){this.schema=e;const{name:t,handler:i}=this.schema;this.name=t,this.handler=i,this.update(e)}name;handler;modifiers={};update(e){Object.assign(this.schema,e);const{handler:t,modifiers:i={}}=this.schema;this.handler=t,this.modifiers=i}static toDsl(e){return Object.entries(e).reduce((t,[i,s])=>{const{handler:a,modifiers:r}=s;return t[i]={name:i,handler:a,modifiers:r},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new C(s),t),{})}}class E{constructor(e){this.schema=e,this.id=e.id||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:a,iterator:r}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=a,this.iterator=r}static parse(e=[]){return e.map(t=>new E(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:a,value:r,iterator:l,id:f}=t;return{id:f,name:i,arg:s,modifiers:a,value:r,iterator:l}})}}const c="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=o.uid(),name:s,from:a=""}=e;this.id=i,this.name=s,this.from=a,this.update(e,!0),_.nodes[this.id]=this}__VTJ_NODE__=!0;locked=!1;static nodes={};id;name;from;invisible=!1;children="";slot;props={};events={};directives=[];disposed=!1;update(e,t=!1){const{invisible:i=!1,locked:s=!1,children:a=[],slot:r,props:l={},events:f={},directives:p=[]}=e;this.invisible=i,this.locked=s,this.setChildren(a,!0),this.setSlot(r,!0),this.props=v.parse(l),this.events=C.parse(f),this.directives=E.parse(p),t||n.emit(c,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new _(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 a=this.props[e];a?a.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 C(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=e instanceof E?e:new E(e),s=this.directives.findIndex(a=>a.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||n.emit(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 a=i.findIndex(r=>r===e);e.parent=null,i.splice(a,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:a,slot:r,children:l,props:f,directives:p,events:O}=this,T=Array.isArray(l)?l.map(b=>b.toDsl()):l;return{id:e,name:t,from:i,invisible:s,locked:a,slot:r,children:T,props:v.toDsl(f),directives:E.toDsl(p),events:C.toDsl(O)}}dispose(e=!1){const{children:t,disposed:i}=this;i||(Array.isArray(t)&&t.forEach(s=>s.dispose(!0)),this.parent?this.parent.removeChild(this,e):e||n.emit(c,this),this.parent=null,this.disposed=!0,delete _.nodes[this.id])}lock(e=!1){if(this.locked=!0,Array.isArray(this.children))for(const t of this.children)t.lock(!0);e||n.emit(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 a=e[s];a&&(this[s]=a)}const{nodes:i=[]}=e;i.length&&(this.nodes=i.map(s=>new _(s))),t||n.emit(d,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...u.normalAttrs.reduce((r,l)=>(r[l]=this[l],r),{}),__VTJ_BLOCK__:t,__VERSION__:e||o.timestamp().toString(),id:i,nodes:s.map(r=>r.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(a=>a===i.name||a===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(a=>a===i.name||a===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 _(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 h="EVENT_PROJECT_CHANGE",I="EVENT_PROJECT_ACTIVED",P="EVENT_PROJECT_DEPS_CHANGE",A="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 x{id="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};__BASE_PATH__="/";__UID__=o.uuid(!0);static attrs=["platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","__BASE_PATH__","__UID__"];constructor(e){const{id:t,__UID__:i}=e;this.id=t||o.uid(),this.__UID__=i||o.uuid(!0),this.update(e,!0)}update(e,t=!1){for(const i of x.attrs){const s=e[i];s&&(this[i]=s)}t||n.emit(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=x.attrs.reduce((s,a)=>(s[a]=this[a],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(r=>r.package===e.package);let a;if(s>-1?(a="update",i.splice(s,1,{...i[s],...e})):(a="create",i.push(e)),!t){const r={model:this,type:a,data:e};n.emit(P,r),n.emit(h,r)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(a=>a.package===e.package);if(s>-1&&i.splice(s,1),!t){const a={model:this,type:"delete",data:e};n.emit(P,a),n.emit(h,a)}}getPage(e){const t=(i,s=[])=>{for(const a of s){if(a.id===i)return a;if(a.children&&a.children.length){const r=t(i,a.children);if(r)return r}}};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(A,s),n.emit(h,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(A,s),n.emit(h,s)}}clonePage(e,t,i=!1){const s=o.uid(),a=`${e.name}Copy`,r=`${e.title}_副本`,l=new u({id:s,name:a}).toDsl(),f=o.merge({},e,{id:s,name:a,title:r,dsl:l}),p=t?this.getPage(t)?.children||[]:this.pages,O=p.findIndex(T=>T.id===e.id);if(p.splice(O+1,0,f),!i){const T={model:this,type:"clone",data:{source:e,target:f}};n.emit(A,T),n.emit(h,T)}}async saveToBlock(e,t=!1){this.active(e,t),await o.delay(1e3);const i=o.uid(),s=e.name,a=e.title,r=new u({id:i,name:s}).toDsl(),l=o.merge({},e,{id:i,name:s,title:a,dsl:r,type:"block",fromType:"Schema"});if(this.blocks.push(l),!t){const f={model:this,type:"create",data:l};n.emit(N,f),n.emit(h,f)}}removePage(e,t=!1){const i=this.getPage(e),s=(a,r)=>{const l=r.findIndex(f=>f.id===a);if(l>=0){r.splice(l,1);return}for(const f of r)f.children&&f.children.length&&s(a,f.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const a={model:this,type:"delete",data:i};n.emit(A,a),n.emit(h,a)}}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 a=e.fromType||"Schema";if(!t){const r={model:this,type:"create",data:e};n.emit(N,r),n.emit(h,r)}!this.currentFile&&a==="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(h,s)}}cloneBlock(e,t=!1){const i=o.uid(),s=`${e.name}Copy`,a=`${e.title}_副本`,r=new u({id:i,name:s}).toDsl(),l=o.merge({},e,{id:i,name:s,title:a,dsl:r}),f=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(f+1,0,l),!t){const p={model:this,type:"clone",data:{source:e,target:l}};n.emit(N,p),n.emit(h,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,a=s.findIndex(r=>r.id===e);if(a>-1?(s.splice(a,1),this.currentFile?.id===e&&this.deactivate(t)):console.warn(`not found PageFile for id: ${e} `),!t){const r={model:this,type:"delete",data:i};n.emit(N,r),n.emit(h,r)}}existBlockName(e,t=[]){return this.blocks.some(i=>i.name===e&&!t.includes(i.id))}existPageName(e,t=[]){return this.getPages().some(s=>s.name===e&&!t.includes(s.id))}setApi(e,t=!1){const i=this.apis.find(a=>a.name===e.name||a.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=o.uid(),this.apis.push(e)),!t){const a={model:this,type:s,data:e};n.emit(V,a),n.emit(h,a)}}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(a=>a.code===e.code||a.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 a={model:this,type:s,data:e};n.emit(S,a),n.emit(h,a)}}removeMeta(e,t=!1){const i=this.meta.findIndex(s=>s.code===e||s.id===e);if(i>-1?this.meta.splice(i,1):console.warn(`not found meta for name: ${name} `),!t){const s={model:this,type:"delete",data:e};n.emit(S,s),n.emit(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)}}setUniConfig(e,t,i=!1){if(this.uniConfig=Object.assign(this.uniConfig,{[e]:t}),!i){const s={model:this,type:"update",data:this.uniConfig};n.emit(h,s)}}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 y="EVENT_HISTORY_CHANGE",g="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 a=this.items.splice(i);t||n.emit(y,{model:this,type:"delete",data:a.map(r=>r.id)})}this.index=-1,t||n.emit(y,{model:this,type:"create",data:s})}remove(e,t=!1){const i=this.items.findIndex(s=>s.id===e);i>-1?(this.items.splice(i,1),i===this.index?this.index=-1:this.index>=this.items.length&&(this.index=this.items.length-1)):console.warn(`not found HistoryItem for id: ${e} `),t||n.emit(y,{model:this,type:"delete",data:[e]})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&n.emit(g,{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(g,{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(g,{model:this,type:"load",data:this.items[i]}))}clear(e=!1){this.index=-1;const t=this.items.map(i=>i.id);this.items=[],e||n.emit(y,{model:this,type:"clear",data:t})}}const n=o.mitt();function Y(m){return m instanceof u}function W(m){return m instanceof _}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=G;exports.BUILT_IN_NAME=J;exports.BUILT_IN_TAGS=M;exports.BUILT_IN_VUE=R;exports.BUILT_IN_VUE_ROUTER=B;exports.Base=$;exports.BlockModel=u;exports.DirectiveModel=E;exports.EVENT_BLOCK_CHANGE=d;exports.EVENT_HISTORY_CHANGE=y;exports.EVENT_HISTORY_LOAD=g;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=h;exports.EVENT_PROJECT_DEPS_CHANGE=P;exports.EVENT_PROJECT_FILE_PUBLISH=k;exports.EVENT_PROJECT_GEN_SOURCE=L;exports.EVENT_PROJECT_META_CHANGE=S;exports.EVENT_PROJECT_PAGES_CHANGE=A;exports.EVENT_PROJECT_PUBLISH=H;exports.EventModel=C;exports.HistoryModel=K;exports.NodeModel=_;exports.ProjectModel=x;exports.PropModel=v;exports.Service=j;exports.VTJ_CORE_VERSION=U;exports.cloneDsl=D;exports.createNodeFrom=z;exports.emitter=n;exports.isBlock=Y;exports.isBlockSchema=q;exports.isNode=W;
|
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { uid as m, timestamp as G, isString as g, cloneDeep as C, upperFirstCamelCase as
|
|
1
|
+
import { uid as m, timestamp as G, isString as g, uuid as R, cloneDeep as C, upperFirstCamelCase as D, delay as P, merge as I, mitt as F } from "@vtj/base";
|
|
2
2
|
/**!
|
|
3
3
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
4
4
|
* @name @vtj/core
|
|
5
5
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
6
|
-
* @version 0.
|
|
6
|
+
* @version 0.12.0-alpha.1
|
|
7
7
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
9
|
+
const Y = "0.12.0-alpha.1", W = "BuiltIn", H = "VueMaterial", J = "VueRouterMaterial", q = [H, J], z = {
|
|
10
10
|
vue: "Vue",
|
|
11
11
|
"vue-router": "VueRouter"
|
|
12
|
-
},
|
|
13
|
-
[
|
|
12
|
+
}, Q = {
|
|
13
|
+
[H]: [
|
|
14
14
|
"Transition",
|
|
15
15
|
"TransitionGroup",
|
|
16
16
|
"KeepAlive",
|
|
17
17
|
"Teleport",
|
|
18
18
|
"Suspense"
|
|
19
19
|
],
|
|
20
|
-
[
|
|
21
|
-
},
|
|
20
|
+
[J]: ["RouterView", "RouterLink"]
|
|
21
|
+
}, X = [
|
|
22
22
|
"slot",
|
|
23
23
|
"template",
|
|
24
24
|
"component",
|
|
@@ -31,9 +31,9 @@ const K = "0.11.16", Y = "BuiltIn", w = "VueMaterial", H = "VueRouterMaterial",
|
|
|
31
31
|
"span",
|
|
32
32
|
"a"
|
|
33
33
|
];
|
|
34
|
-
class X {
|
|
35
|
-
}
|
|
36
34
|
class Z {
|
|
35
|
+
}
|
|
36
|
+
class ee {
|
|
37
37
|
listeners = [];
|
|
38
38
|
isReady = !1;
|
|
39
39
|
triggerReady() {
|
|
@@ -391,7 +391,7 @@ class _ {
|
|
|
391
391
|
props: l,
|
|
392
392
|
directives: p,
|
|
393
393
|
events: O
|
|
394
|
-
} = this, E = Array.isArray(d) ? d.map((
|
|
394
|
+
} = this, E = Array.isArray(d) ? d.map((U) => U.toDsl()) : d;
|
|
395
395
|
return {
|
|
396
396
|
id: e,
|
|
397
397
|
name: t,
|
|
@@ -756,7 +756,7 @@ class u {
|
|
|
756
756
|
* @returns
|
|
757
757
|
*/
|
|
758
758
|
cloneNode(e, t = !1) {
|
|
759
|
-
const i =
|
|
759
|
+
const i = L(e.toDsl()), s = new _(i);
|
|
760
760
|
return this.addNode(s, e, "bottom", t), s;
|
|
761
761
|
}
|
|
762
762
|
lock(e = !1) {
|
|
@@ -782,7 +782,7 @@ class u {
|
|
|
782
782
|
return t;
|
|
783
783
|
}
|
|
784
784
|
}
|
|
785
|
-
const h = "EVENT_PROJECT_CHANGE", k = "EVENT_PROJECT_ACTIVED",
|
|
785
|
+
const h = "EVENT_PROJECT_CHANGE", k = "EVENT_PROJECT_ACTIVED", B = "EVENT_PROJECT_DEPS_CHANGE", A = "EVENT_PROJECT_PAGES_CHANGE", y = "EVENT_PROJECT_BLOCKS_CHANGE", b = "EVENT_PROJECT_APIS_CHANGE", w = "EVENT_PROJECT_META_CHANGE", j = "EVENT_PROJECT_PUBLISH", $ = "EVENT_PROJECT_FILE_PUBLISH", M = "EVENT_PROJECT_GEN_SOURCE";
|
|
786
786
|
class S {
|
|
787
787
|
id = "";
|
|
788
788
|
platform = "web";
|
|
@@ -798,6 +798,7 @@ class S {
|
|
|
798
798
|
config = {};
|
|
799
799
|
uniConfig = {};
|
|
800
800
|
__BASE_PATH__ = "/";
|
|
801
|
+
__UID__ = R(!0);
|
|
801
802
|
static attrs = [
|
|
802
803
|
"platform",
|
|
803
804
|
"name",
|
|
@@ -810,11 +811,12 @@ class S {
|
|
|
810
811
|
"meta",
|
|
811
812
|
"config",
|
|
812
813
|
"uniConfig",
|
|
813
|
-
"__BASE_PATH__"
|
|
814
|
+
"__BASE_PATH__",
|
|
815
|
+
"__UID__"
|
|
814
816
|
];
|
|
815
817
|
constructor(e) {
|
|
816
|
-
const { id: t } = e;
|
|
817
|
-
this.id = t || m(), this.update(e, !0);
|
|
818
|
+
const { id: t, __UID__: i } = e;
|
|
819
|
+
this.id = t || m(), this.__UID__ = i || R(!0), this.update(e, !0);
|
|
818
820
|
}
|
|
819
821
|
update(e, t = !1) {
|
|
820
822
|
for (const i of S.attrs) {
|
|
@@ -891,7 +893,7 @@ class S {
|
|
|
891
893
|
type: a,
|
|
892
894
|
data: e
|
|
893
895
|
};
|
|
894
|
-
n.emit(
|
|
896
|
+
n.emit(B, r), n.emit(h, r);
|
|
895
897
|
}
|
|
896
898
|
}
|
|
897
899
|
/**
|
|
@@ -907,7 +909,7 @@ class S {
|
|
|
907
909
|
type: "delete",
|
|
908
910
|
data: e
|
|
909
911
|
};
|
|
910
|
-
n.emit(
|
|
912
|
+
n.emit(B, a), n.emit(h, a);
|
|
911
913
|
}
|
|
912
914
|
}
|
|
913
915
|
/**
|
|
@@ -951,7 +953,7 @@ class S {
|
|
|
951
953
|
async createPage(e, t, i = !1) {
|
|
952
954
|
if (e.id = e.raw ? e.name : e.id || m(), e.type = "page", e.dir ? e.children = [] : e.dsl = e.dsl || new u({
|
|
953
955
|
id: e.id,
|
|
954
|
-
name:
|
|
956
|
+
name: D(e.name)
|
|
955
957
|
}).toDsl(), t) {
|
|
956
958
|
const s = this.getPage(t);
|
|
957
959
|
s ? s.children ? s.children.push(e) : s.children = [e] : console.warn(`not found PageFile for id: ${t} `);
|
|
@@ -1066,7 +1068,7 @@ class S {
|
|
|
1066
1068
|
* @param silent
|
|
1067
1069
|
*/
|
|
1068
1070
|
async createBlock(e, t = !1) {
|
|
1069
|
-
const i = e.id || m(), s =
|
|
1071
|
+
const i = e.id || m(), s = D(e.name);
|
|
1070
1072
|
e.id = i, e.type = "block", e.dsl = new u({ id: i, name: s }).toDsl(), this.blocks.push(e);
|
|
1071
1073
|
const a = e.fromType || "Schema";
|
|
1072
1074
|
if (!t) {
|
|
@@ -1162,7 +1164,7 @@ class S {
|
|
|
1162
1164
|
type: s,
|
|
1163
1165
|
data: e
|
|
1164
1166
|
};
|
|
1165
|
-
n.emit(
|
|
1167
|
+
n.emit(b, a), n.emit(h, a);
|
|
1166
1168
|
}
|
|
1167
1169
|
}
|
|
1168
1170
|
/**
|
|
@@ -1178,7 +1180,7 @@ class S {
|
|
|
1178
1180
|
type: "delete",
|
|
1179
1181
|
data: e
|
|
1180
1182
|
};
|
|
1181
|
-
n.emit(
|
|
1183
|
+
n.emit(b, s), n.emit(h, s);
|
|
1182
1184
|
}
|
|
1183
1185
|
}
|
|
1184
1186
|
existApiName(e, t = []) {
|
|
@@ -1195,7 +1197,7 @@ class S {
|
|
|
1195
1197
|
type: s,
|
|
1196
1198
|
data: e
|
|
1197
1199
|
};
|
|
1198
|
-
n.emit(
|
|
1200
|
+
n.emit(w, a), n.emit(h, a);
|
|
1199
1201
|
}
|
|
1200
1202
|
}
|
|
1201
1203
|
removeMeta(e, t = !1) {
|
|
@@ -1206,7 +1208,7 @@ class S {
|
|
|
1206
1208
|
type: "delete",
|
|
1207
1209
|
data: e
|
|
1208
1210
|
};
|
|
1209
|
-
n.emit(
|
|
1211
|
+
n.emit(w, s), n.emit(h, s);
|
|
1210
1212
|
}
|
|
1211
1213
|
}
|
|
1212
1214
|
existMetaCode(e, t = []) {
|
|
@@ -1248,7 +1250,7 @@ class S {
|
|
|
1248
1250
|
type: "publish",
|
|
1249
1251
|
data: e || this
|
|
1250
1252
|
};
|
|
1251
|
-
e ? n.emit(
|
|
1253
|
+
e ? n.emit($, t) : n.emit(j, t);
|
|
1252
1254
|
}
|
|
1253
1255
|
genSource() {
|
|
1254
1256
|
const e = {
|
|
@@ -1256,11 +1258,11 @@ class S {
|
|
|
1256
1258
|
type: "gen",
|
|
1257
1259
|
data: null
|
|
1258
1260
|
};
|
|
1259
|
-
n.emit(
|
|
1261
|
+
n.emit(M, e);
|
|
1260
1262
|
}
|
|
1261
1263
|
}
|
|
1262
1264
|
const N = "EVENT_HISTORY_CHANGE", V = "EVENT_HISTORY_LOAD";
|
|
1263
|
-
class
|
|
1265
|
+
class te {
|
|
1264
1266
|
options = { max: 50 };
|
|
1265
1267
|
index = -1;
|
|
1266
1268
|
id;
|
|
@@ -1363,21 +1365,21 @@ class ee {
|
|
|
1363
1365
|
});
|
|
1364
1366
|
}
|
|
1365
1367
|
}
|
|
1366
|
-
const n =
|
|
1367
|
-
function
|
|
1368
|
+
const n = F();
|
|
1369
|
+
function ie(f) {
|
|
1368
1370
|
return f instanceof u;
|
|
1369
1371
|
}
|
|
1370
|
-
function
|
|
1372
|
+
function se(f) {
|
|
1371
1373
|
return f instanceof _;
|
|
1372
1374
|
}
|
|
1373
|
-
function
|
|
1375
|
+
function ne(f) {
|
|
1374
1376
|
return !!f.__VTJ_BLOCK__;
|
|
1375
1377
|
}
|
|
1376
|
-
function
|
|
1378
|
+
function L(f) {
|
|
1377
1379
|
const e = C(f);
|
|
1378
|
-
return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) =>
|
|
1380
|
+
return delete e.id, Array.isArray(e.children) && (e.children = e.children.map((t) => L(t))), e;
|
|
1379
1381
|
}
|
|
1380
|
-
function
|
|
1382
|
+
function ae(f) {
|
|
1381
1383
|
const e = f.fromType || "Schema";
|
|
1382
1384
|
return e === "Schema" ? {
|
|
1383
1385
|
type: "Schema",
|
|
@@ -1392,14 +1394,14 @@ function ne(f) {
|
|
|
1392
1394
|
} : "";
|
|
1393
1395
|
}
|
|
1394
1396
|
export {
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1397
|
+
Q as BUILT_IN_COMPONENTS,
|
|
1398
|
+
z as BUILT_IN_LIBRARAY_MAP,
|
|
1399
|
+
q as BUILT_IN_MATERIALS,
|
|
1400
|
+
W as BUILT_IN_NAME,
|
|
1401
|
+
X as BUILT_IN_TAGS,
|
|
1402
|
+
H as BUILT_IN_VUE,
|
|
1403
|
+
J as BUILT_IN_VUE_ROUTER,
|
|
1404
|
+
ee as Base,
|
|
1403
1405
|
u as BlockModel,
|
|
1404
1406
|
v as DirectiveModel,
|
|
1405
1407
|
o as EVENT_BLOCK_CHANGE,
|
|
@@ -1407,26 +1409,26 @@ export {
|
|
|
1407
1409
|
V as EVENT_HISTORY_LOAD,
|
|
1408
1410
|
c as EVENT_NODE_CHANGE,
|
|
1409
1411
|
k as EVENT_PROJECT_ACTIVED,
|
|
1410
|
-
|
|
1412
|
+
b as EVENT_PROJECT_APIS_CHANGE,
|
|
1411
1413
|
y as EVENT_PROJECT_BLOCKS_CHANGE,
|
|
1412
1414
|
h as EVENT_PROJECT_CHANGE,
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1415
|
+
B as EVENT_PROJECT_DEPS_CHANGE,
|
|
1416
|
+
$ as EVENT_PROJECT_FILE_PUBLISH,
|
|
1417
|
+
M as EVENT_PROJECT_GEN_SOURCE,
|
|
1418
|
+
w as EVENT_PROJECT_META_CHANGE,
|
|
1417
1419
|
A as EVENT_PROJECT_PAGES_CHANGE,
|
|
1418
|
-
|
|
1420
|
+
j as EVENT_PROJECT_PUBLISH,
|
|
1419
1421
|
T as EventModel,
|
|
1420
|
-
|
|
1422
|
+
te as HistoryModel,
|
|
1421
1423
|
_ as NodeModel,
|
|
1422
1424
|
S as ProjectModel,
|
|
1423
1425
|
x as PropModel,
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1426
|
+
Z as Service,
|
|
1427
|
+
Y as VTJ_CORE_VERSION,
|
|
1428
|
+
L as cloneDsl,
|
|
1429
|
+
ae as createNodeFrom,
|
|
1428
1430
|
n as emitter,
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1431
|
+
ie as isBlock,
|
|
1432
|
+
ne as isBlockSchema,
|
|
1433
|
+
se as isNode
|
|
1432
1434
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0-alpha.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"低代码引擎",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"author": "chenhuachun",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@vtj/base": "~0.
|
|
24
|
+
"@vtj/base": "~0.12.0-alpha.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@vtj/cli": "~0.
|
|
27
|
+
"@vtj/cli": "~0.12.0-alpha.1"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
@@ -60,6 +60,7 @@ export declare class ProjectModel {
|
|
|
60
60
|
config: ProjectConfig;
|
|
61
61
|
uniConfig: UniConfig;
|
|
62
62
|
__BASE_PATH__: string;
|
|
63
|
+
__UID__: string;
|
|
63
64
|
static attrs: string[];
|
|
64
65
|
constructor(schema: ProjectSchema);
|
|
65
66
|
update(schema: Partial<ProjectSchema>, silent?: boolean): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProjectSchema, BlockSchema, HistorySchema, HistoryItem, PageFile, BlockFile, NodeFromPlugin } from './schemas';
|
|
2
2
|
import { MaterialDescription } from './assets';
|
|
3
|
-
import { StaticFileInfo, VTJConfig } from './shared';
|
|
3
|
+
import { StaticFileInfo, VTJConfig, ParseVueOptions } from './shared';
|
|
4
4
|
export declare abstract class Service {
|
|
5
5
|
abstract getExtension(): Promise<VTJConfig | undefined>;
|
|
6
6
|
abstract init(project: Partial<ProjectSchema>): Promise<ProjectSchema>;
|
|
@@ -18,6 +18,7 @@ export declare abstract class Service {
|
|
|
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 parseVue(project: ProjectSchema, options: ParseVueOptions): Promise<BlockSchema>;
|
|
21
22
|
abstract createRawPage(file: PageFile, project?: ProjectSchema): Promise<boolean>;
|
|
22
23
|
abstract removeRawPage(id: string, project?: ProjectSchema): Promise<boolean>;
|
|
23
24
|
abstract uploadStaticFile(file: File, projectId: string): Promise<StaticFileInfo | null>;
|
|
@@ -81,6 +81,14 @@ export interface VTJConfig {
|
|
|
81
81
|
* 远程服务host
|
|
82
82
|
*/
|
|
83
83
|
remote?: string;
|
|
84
|
+
/**
|
|
85
|
+
* 授权登录
|
|
86
|
+
*/
|
|
87
|
+
auth?: string | (() => Promise<any>);
|
|
88
|
+
/**
|
|
89
|
+
* 检查版本更新
|
|
90
|
+
*/
|
|
91
|
+
checkVersion?: boolean;
|
|
84
92
|
/**
|
|
85
93
|
* 平台
|
|
86
94
|
*/
|
|
@@ -98,3 +106,8 @@ export interface VTJConfig {
|
|
|
98
106
|
* 平台类型
|
|
99
107
|
*/
|
|
100
108
|
export type PlatformType = 'web' | 'h5' | 'uniapp';
|
|
109
|
+
export interface ParseVueOptions {
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
source: string;
|
|
113
|
+
}
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.
|
|
5
|
+
* @version 0.12.0-alpha.0
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.
|
|
8
|
+
export declare const version = "0.12.0-alpha.0";
|