@vtj/core 0.20.4 → 0.20.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +6 -2
- package/package.json +1 -1
- package/types/protocols/schemas/backend/index.d.ts +48 -0
- package/types/protocols/schemas/backend/model.d.ts +119 -0
- package/types/protocols/schemas/index.d.ts +1 -0
- package/types/protocols/service.d.ts +5 -1
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@vtj/base");/**!
|
|
2
2
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.20.
|
|
5
|
+
* @version 0.20.5
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const W="0.20.4",Z="BuiltIn",$="VueMaterial",F="VueRouterMaterial",Q=[$,F],X={vue:"Vue","vue-router":"VueRouter"},ee={[$]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[F]:["RouterView","RouterLink"]},te=["slot","template","component","img","div","p","h1","h2","h3","span","a"],ie=[{label:"简体中文",value:"zh-CN"},{label:"English",value:"en"}];class se{}class ne{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 x{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 x(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:n,modifiers:r}=s;return t[i]={name:i,handler:n,modifiers:r},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new A(s),t),{})}}class v{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:n,iterator:r}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=n,this.iterator=r}static parse(e=[]){return e.map(t=>new v(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:n,value:r,iterator:l,id:c}=t;return{id:c,name:i,arg:s,modifiers:n,value:r,iterator:l}})}}const m="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=d.uid(),name:s,from:n=""}=e;this.id=i,this.name=s,this.from=n,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:n=[],slot:r,props:l={},events:c={},directives:P=[]}=e;this.invisible=i,this.locked=s,this.setChildren(n,!0),this.setSlot(r,!0),this.props=x.parse(l),this.events=A.parse(c),this.directives=v.parse(P),t||a.emit(m,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new _(i,this)):this.children=e,t||a.emit(m,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||a.emit(m,this)}setProp(e,t,i,s=!1){const n=this.props[e];n?n.setValue(t):this.props[e]=new x(e,t,i),s||a.emit(m,this)}removeProp(e,t=!1){delete this.props[e],t||a.emit(m,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||a.emit(m,this)}removeEvent(e,t=!1){delete this.events[e],t||a.emit(m,this)}setDirective(e,t=!1){const i=e instanceof v?e:new v(e),s=this.directives.findIndex(n=>n.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||a.emit(m,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||a.emit(m,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const n=i.findIndex(r=>r===e);e.parent=null,i.splice(n,1),t||a.emit(m,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||a.emit(m,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||a.emit(m,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||a.emit(m,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||a.emit(m,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||a.emit(m,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:n,slot:r,children:l,props:c,directives:P,events:p}=this,O=Array.isArray(l)?l.map(L=>L.toDsl()):l;return{id:e,name:t,from:i,invisible:s,locked:n,slot:r,children:O,props:x.toDsl(c),directives:v.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||a.emit(m,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||a.emit(m,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||a.emit(m,this)}setVisible(e,t=!1){if(this.invisible=!e,Array.isArray(this.children))for(const i of this.children)i.setVisible(e,!0);t||a.emit(m,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}findChildIndex(e){return Array.isArray(this.children)?this.children.findIndex(t=>t===e||t.id===e.id):-1}}const h="EVENT_BLOCK_CHANGE";class E{__VTJ_BLOCK__=!0;id;name="";apiMode="options";inject=[];state={};refs={};reactives={};lifeCycles={};methods={};computed={};watch=[];composables=[];setup=void 0;provide={};css="";props=[];emits=[];expose=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","apiMode","inject","state","refs","reactives","lifeCycles","methods","computed","watch","composables","setup","provide","css","props","emits","expose","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 E.normalAttrs){const n=e[s];(n!==void 0||s==="setup")&&(this[s]=n)}const{nodes:i=[]}=e;i.length?this.nodes=i.map(s=>new _(s)):this.nodes=[],t||a.emit(h,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...E.normalAttrs.reduce((r,l)=>(r[l]=this[l],r),{}),__VTJ_BLOCK__:t,__VERSION__:e||d.timestamp().toString(),id:i,nodes:s.map(r=>r.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}isExistName(e){return e in this.refs||e in this.reactives||e in this.computed||e in this.methods}setFunction(e,t,i,s=!1){this[e][t]=i,s||a.emit(h,this)}removeFunction(e,t,i=!1){delete this[e][t],i||a.emit(h,this)}setComputed(e,t,i=!1){t?this.computed[e]=t:delete this.computed[e],i||a.emit(h,this)}setState(e,t,i=!1){this.state[e]=t,i||a.emit(h,this)}removeState(e,t=!1){delete this.state[e],t||a.emit(h,this)}setCss(e,t=!1){this.css=e,t||a.emit(h,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||a.emit(h,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||a.emit(h,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||a.emit(h,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||a.emit(h,this))}setEmit(e,t=!1){const i=d.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(n=>n===i.name||n.name===i.name);s>-1?this.emits.splice(s,1,i):this.emits.push(i),t||a.emit(h,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||a.emit(h,this))}setExpose(e,t=!1){this.expose=e,t||a.emit(h,this)}setSlot(e,t=!1){const i=d.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(n=>n===i.name||n.name===i.name);s>-1?this.slots.splice(s,1,i):this.slots.push(i),t||a.emit(h,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||a.emit(h,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||a.emit(h,this)}removeInject(e,t=!1){const i=this.inject.findIndex(s=>s.name===e.name);i>-1&&(this.inject.splice(i,1),t||a.emit(h,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||a.emit(h,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||a.emit(h,this)}setApiMode(e,t=!1){this.apiMode=e,t||a.emit(h,this)}setRef(e,t,i=!1){this.refs[e]=t,i||a.emit(h,this)}removeRef(e,t=!1){delete this.refs[e],t||a.emit(h,this)}setReactive(e,t,i=!1){this.reactives[e]=t,i||a.emit(h,this)}removeReactive(e,t=!1){delete this.reactives[e],t||a.emit(h,this)}setComposable(e,t=!1){const i=this.composables.findIndex(s=>s.name===e.name);i>-1?this.composables.splice(i,1,e):this.composables.push(e),t||a.emit(h,this)}removeComposable(e,t=!1){const i=this.composables.findIndex(s=>s.name===e);i>-1&&(this.composables.splice(i,1),t||a.emit(h,this))}setProvide(e,t,i=!1){this.provide[e]=t,i||a.emit(h,this)}removeProvide(e,t=!1){delete this.provide[e],t||a.emit(h,this)}setSetup(e,t=!1){this.setup=e,t||a.emit(h,this)}insertAfter(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s+1,0,e),i||a.emit(h,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||a.emit(h,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||a.emit(h,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||a.emit(h,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||a.emit(h,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||a.emit(h,this))}}cloneNode(e,t=!1){const i=G(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||a.emit(h,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||a.emit(h,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",D="EVENT_PROJECT_ACTIVED",k="EVENT_PROJECT_DEPS_CHANGE",T="EVENT_PROJECT_PAGES_CHANGE",C="EVENT_PROJECT_BLOCKS_CHANGE",S="EVENT_PROJECT_APIS_CHANGE",b="EVENT_PROJECT_META_CHANGE",M="EVENT_PROJECT_PUBLISH",j="EVENT_PROJECT_FILE_PUBLISH",K="EVENT_PROJECT_GEN_SOURCE";class w{id="";locked="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};globals={};i18n={locale:"zh-CN",fallbackLocale:"zh-CN",messages:[]};env=[];__BASE_PATH__="/";__UID__=d.uuid(!0);static attrs=["locked","platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","globals","i18n","env","__BASE_PATH__","__UID__"];constructor(e){const{id:t,__UID__:i}=e;this.id=t||d.uid(),this.__UID__=i||d.uuid(!0),this.update(e,!0)}update(e,t=!1){for(const i of w.attrs){const s=e[i];s&&(this[i]=s)}t||a.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=w.attrs.reduce((s,n)=>(s[n]=this[n],s),{});return i.pages&&(i.pages=i.pages.map(s=>d.cloneDeep({...s,dsl:void 0})),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>d.cloneDeep({...s,dsl:void 0}))),{__VTJ_PROJECT__:!0,id:t,...i}}active(e,t=!1){this.currentFile=e,t||a.emit(D,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||a.emit(D,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(r=>r.package===e.package);let n;if(s>-1?(n="update",i.splice(s,1,{...i[s],...e})):(n="create",i.push(e)),!t){const r={model:this,type:n,data:e};a.emit(k,r),a.emit(f,r)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(n=>n.package===e.package);if(s>-1&&i.splice(s,1),!t){const n={model:this,type:"delete",data:e};a.emit(k,n),a.emit(f,n)}}getPage(e){const t=(i,s=[])=>{for(const n of s){if(n.id===i)return n;if(n.children&&n.children.length){const r=t(i,n.children);if(r)return r}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir||s.layout?(s.layout&&i.push(s),s.children&&s.children.length&&(i=i.concat(e(s.children)))):i.push(s);return i};return e(this.pages)}getHomepage(){return this.homepage?this.getPage(this.homepage):this.getPages()[0]}async createPage(e,t,i=!1){if(e.id=e.id||d.uid(),e.type="page",e.name=d.upperFirstCamelCase(e.name),this.existPageName(e.name))throw new Error(`页面名称【${e.name}】已经存在`);if(e.dir)delete e.filePath,delete e.routePath;else{const s=N(e.name);e.filePath=s,e.routePath=this.platform==="uniapp"?void 0:`/page/${s}`}if(this.validatePagePath(e),e.dir?e.children=[]:e.dsl=e.dsl||new E({id:e.id,name:d.upperFirstCamelCase(e.name),apiMode:"composition"}).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};a.emit(T,s),a.emit(f,s)}return!this.currentFile&&!e.dir&&(this.active(e,!0),await d.delay(1e3),this.active(e,i)),e}updatePage(e,t=!1){const i=this.getPage(e.id);let s;if(delete e.dsl,i){if(s={...i},e.name=d.upperFirstCamelCase(e.name),this.existPageName(e.name,[e.id]))throw new Error(`页面名称【${e.name}】已经存在`);if(e.name!==i.name&&!i.raw){const n=N(i.name);i.filePath===n&&(e.filePath=N(e.name)),this.platform!=="uniapp"&&i.routePath===`/page/${n}`&&(e.routePath=`/page/${N(e.name)}`)}this.validatePagePath(e,[e.id]),Object.assign(i,e)}else console.warn(`not found PageFile for id: ${e.id} `);if(!t){const n={model:this,type:"update",data:e,previous:s};a.emit(T,n),a.emit(f,n)}return i}findParent(e){const t=(i,s=[],n)=>{for(const r of s){if(r.id===i)return n;if(r.children&&r.children.length){const l=t(i,r.children,r);if(l)return l}}};return t(e,this.pages)}movePageTo(e,t,i=!1){const s=t?this.getPage(t):null,n=this.getPage(e);if(!n)return!1;const r=this.findParent(e);if(r?r.children=r.children?.filter(l=>l.id!==e):this.pages=this.pages.filter(l=>l.id!==e),s?(s.dir||s.layout)&&(s.children?s.children.push(n):s.children=[n]):this.pages.push(n),!i){const l={model:this,type:"update",data:n};a.emit(T,l),a.emit(f,l)}return!0}getPageTree(){const e=d.cloneDeep(this.pages);return this.cleanPagesDsl(e),e}clonePage(e,t,i=!1){const s=d.uid(),n=this.createUniquePath(`${e.name}Copy`,g=>this.existPageName(g)),r=`${e.title}_副本`,l=new E({id:s,name:n,apiMode:"composition"}).toDsl(),c=N(n),P=this.platform==="uniapp"?void 0:`/page/${c}`,p=d.merge({},e,{id:s,name:n,title:r,filePath:c,routePath:P,dsl:l}),O=t?this.getPage(t)?.children||[]:this.pages,L=O.findIndex(g=>g.id===e.id);if(O.splice(L+1,0,p),!i){const g={model:this,type:"clone",data:{source:e,target:p}};a.emit(T,g),a.emit(f,g)}}async saveToBlock(e,t=!1){this.active(e,t),await d.delay(1e3);const i=d.uid(),s=this.createUniquePath(e.name,c=>this.existBlockName(c)),n=e.title,r=new E({...e.dsl,id:i,name:s}).toDsl(),l={id:i,name:s,title:n,filePath:s,dsl:r,type:"block",fromType:"Schema"};if(this.blocks.push(l),!t){const c={model:this,type:"create",data:l};a.emit(C,c),a.emit(f,c)}}removePage(e,t=!1){const i=this.getPage(e),s=(n,r)=>{const l=r.findIndex(c=>c.id===n);if(l>=0){r.splice(l,1);return}for(const c of r)c.children&&c.children.length&&s(n,c.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const n={model:this,type:"delete",data:i};a.emit(T,n),a.emit(f,n)}}getBlock(e){return this.blocks.find(t=>t.id===e)}getFile(e){return this.getPage(e)||this.getBlock(e)}async createBlock(e,t=!1){const i=e.id||d.uid(),s=d.upperFirstCamelCase(e.name);if(e.id=i,e.name=s,e.type="block",e.fromType=e.fromType||"Schema",this.existBlockName(s))throw new Error(`区块名称【${s}】已经存在`);e.fromType==="Schema"?e.filePath=s:delete e.filePath,this.validateBlockPath(e),e.dsl=new E({id:i,name:s,apiMode:"composition"}).toDsl(),this.blocks.push(e);const n=e.fromType||"Schema";if(!t){const r={model:this,type:"create",data:e};a.emit(C,r),a.emit(f,r)}return!this.currentFile&&n==="Schema"&&(this.active(e,!0),await d.delay(1e3),this.active(e,t)),e}updateBlock(e,t=!1){const i=this.getBlock(e.id);let s;if(i){if(s={...i},e.name=d.upperFirstCamelCase(e.name),this.existBlockName(e.name,[e.id]))throw new Error(`区块名称【${e.name}】已经存在`);e.name!==i.name&&(i.fromType||"Schema")==="Schema"&&i.filePath===i.name&&(e.filePath=e.name),this.validateBlockPath(e,[e.id]),Object.assign(i,e),i.dsl&&(i.dsl.name=e.name)}else console.warn(`not found PageFile for id: ${e.id} `);if(!t){const n={model:this,type:"update",data:e,previous:s};a.emit(C,n),a.emit(f,n)}return i}cloneBlock(e,t=!1){const i=d.uid(),s=this.createUniquePath(`${e.name}Copy`,p=>this.existBlockName(p)),n=`${e.title}_副本`,r=new E({id:i,name:s,apiMode:"composition"}).toDsl(),l=s,c=d.merge({},e,{id:i,name:s,title:n,filePath:l,dsl:r}),P=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(P+1,0,c),!t){const p={model:this,type:"clone",data:{source:e,target:c}};a.emit(C,p),a.emit(f,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,n=s.findIndex(r=>r.id===e);if(n>-1?(s.splice(n,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};a.emit(C,r),a.emit(f,r)}}existBlockName(e,t=[]){const i=e.toLowerCase();return this.blocks.some(s=>s.name.toLowerCase()===i&&!t.includes(s.id))}existBlockFilePath(e,t=[]){const i=B(e).toLowerCase();return this.blocks.some(s=>u(s).toLowerCase()===i&&!t.includes(s.id))}existPageName(e,t=[]){const i=e.toLowerCase(),s=n=>n.some(r=>r.name.toLowerCase()===i&&!t.includes(r.id)?!0:r.children?.length?s(r.children):!1);return s(this.pages)}existPageFilePath(e,t=[]){const i=B(e).toLowerCase();return this.getPages().some(s=>u(s).toLowerCase()===i&&!t.includes(s.id))}existRoutePath(e,t=[]){const i=I(e).replace(/:[^/]+/g,":");return this.getPages().some(s=>V(s).replace(/:[^/]+/g,":")===i&&!t.includes(s.id))}validatePagePath(e,t=[]){const i=u(e);if(!e.dir&&!U(i))throw new Error(`页面文件路径【${i}】格式不正确`);if(!q(e.routePath))throw new Error(`页面路由【${e.routePath}】格式不正确`);if(!e.dir&&this.existPageFilePath(u(e),t))throw new Error(`页面文件路径【${u(e)}】已经存在`);const s=V(e);if(!e.dir&&this.existRoutePath(s,t))throw new Error(`页面路由【${s}】已经存在`)}validateBlockPath(e,t=[]){const i=u(e);if(!U(i))throw new Error(`区块文件路径【${i}】格式不正确`);if((e.fromType||this.getBlock(e.id)?.fromType||"Schema")==="Schema"&&this.existBlockFilePath(u(e),t))throw new Error(`区块文件路径【${u(e)}】已经存在`)}createUniquePath(e,t){const i=e;let s=i,n=2;for(;t(s);)s=`${i}${n++}`;return s}setApi(e,t=!1){const i=this.apis.find(n=>n.name===e.name||n.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 n={model:this,type:s,data:e};a.emit(S,n),a.emit(f,n)}return i||e}setApis(e,t=!1){for(const i of e)this.setApi(i,!0);if(!t){const i={model:this,type:"create",data:e};a.emit(S,i),a.emit(f,i)}}removeApi(e,t=!1){const i=this.apis.findIndex(s=>s.name===e||s.id===e);if(i>-1?this.apis.splice(i,1):console.warn(`not found Api for name: ${e} `),!t){const s={model:this,type:"delete",data:e};a.emit(S,s),a.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(n=>n.code===e.code||n.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 n={model:this,type:s,data:e};a.emit(b,n),a.emit(f,n)}}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};a.emit(b,s),a.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};a.emit(f,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};a.emit(f,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};a.emit(f,s)}}setGloblas(e,t,i=!1){if(this.globals=Object.assign(this.globals,{[e]:t}),!i){const s={model:this,type:"update",data:this.globals};a.emit(f,s)}}setI18n(e,t=!1){if(this.i18n=Object.assign(this.i18n,e),!t){const i={model:this,type:"update",data:this.i18n};a.emit(f,i)}}setEnv(e,t=!1){if(this.env=[...e],!t){const i={model:this,type:"update",data:this.env};a.emit(f,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?a.emit(j,t):a.emit(M,t)}genSource(){const e={model:this,type:"gen",data:null};a.emit(K,e)}lock(e){this.locked=e;const t={model:this,type:"update",data:e};a.emit(f,t)}unlock(e){if(e!==this.locked)return;this.locked="";const t={model:this,type:"update",data:null};a.emit(f,t)}getPageRoutes(e,t){const i=this.platform==="uniapp",s=e||(i?"pages":"page"),n=this.getPages(),r=t||"";return n.map(l=>{const c=i?`/${Y(l)}`:V(l,`${r}/`,s);return{id:l.id,path:c,name:l.name,title:l.title,meta:l.meta}})}}const y="EVENT_HISTORY_CHANGE",R="EVENT_HISTORY_LOAD";class ae{options={max:50};index=-1;id;type;items;constructor(e,t={}){Object.assign(this.options,t);const{id:i,type:s="file",items:n=[]}=e;this.id=i,this.type=s,this.items=n}toDsl(){const{id:e,type:t,items:i}=this;return{id:e,type:t,items:i.map(s=>({id:s.id,label:s.label,remark:s.remark||""}))}}get(e){return this.items.find(t=>t.id===e)}add(e,t="",i=!1){const{max:s}=this.options,n={id:d.uid(),label:new Date().toLocaleString(),remark:t,dsl:d.cloneDeep(e)};this.items.unshift(n);const r=this.items.filter(l=>!l.remark);if(r.length>s){const l=r.splice(s).map(c=>c.id);this.items=this.items.filter(c=>!l.includes(c.id)),i||a.emit(y,{model:this,type:"delete",data:l})}this.index=-1,i||a.emit(y,{model:this,type:"create",data:n})}update(e,t=!1){const i=this.items.find(s=>s.id===e.id);i&&Object.assign(i,e),t||a.emit(y,{model:this,type:"update",data:i})}remove(e,t=!1){const i=d.toArray(e);for(const s of i){const n=this.items.findIndex(r=>r.id===s);n>-1?(this.items.splice(n,1),n===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||a.emit(y,{model:this,type:"delete",data:i})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&a.emit(R,{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&&a.emit(R,{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||a.emit(R,{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||a.emit(y,{model:this,type:"clear",data:t})}}const a=d.mitt();function re(o){return o instanceof E}function oe(o){return o instanceof _}function le(o){return!!o.__VTJ_BLOCK__}function G(o){const e=d.cloneDeep(o);return delete e.id,Array.isArray(e.children)&&(e.children=e.children.map(t=>G(t))),e}function he(o){const e=o.fromType||"Schema";return e==="Schema"?{type:"Schema",id:o.id}:e==="UrlSchema"?{type:"UrlSchema",url:(o.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(o.urls||"").split(","),library:o.library}:""}function B(o){return(o||"").trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,"").replace(/\.vue$/i,"")}function I(o){const e=(o||"").trim().replace(/\\/g,"/");if(!e)return"";const t=`/${e}`.replace(/\/{2,}/g,"/");return t.length>1?t.replace(/\/$/,""):t}function u(o){return B(o.filePath)||o.id}function N(o){return d.kebabCase(o)}function H(o,e="web"){const t=u(o);return o.type==="block"?`src/components/${t}.vue`:e==="uniapp"?`src/pages/${t}.vue`:`src/views/${t}.vue`}function z(o){return`@/components/${u(o)}.vue`}function V(o,e="",t="page"){const i=I(o.routePath);if(i)return i;if(o.filePath){const s=u(o).split("/").map(n=>d.kebabCase(n)).join("/");return I(`${e}${t}/${s}`)}return I(`${e}${t}/${o.id}`)}function Y(o){return`pages/${u(o)}`}function J(o=[]){const e=[];for(const t of o)t.dir||e.push(t),t.children?.length&&e.push(...J(t.children));return e}function de(o){const e=new Map,t=new Map,i=new Map,s=new Map;for(const n of o.blocks||[]){const r=H(n,o.platform).toLowerCase();e.set(n.id,n),i.set(r,n.id),t.set(z(n).toLowerCase(),n.id)}for(const n of J(o.pages))e.set(n.id,n),s.set(H(n,o.platform).toLowerCase(),n.id);return{byId:e,blockIdByImportPath:t,blockIdBySourcePath:i,pageIdBySourcePath:s}}function U(o){if(!o)return!0;const e=o.trim();return!!e&&!e.startsWith("/")&&!e.endsWith(".vue")&&!/[\\?#]/.test(e)&&e.split("/").every(t=>/^(?!\.{1,2}$)[A-Za-z0-9_-]+$/.test(t))}function q(o){return o?o.startsWith("/")&&!/[?#]/.test(o):!0}exports.BUILT_IN_COMPONENTS=ee;exports.BUILT_IN_LIBRARAY_MAP=X;exports.BUILT_IN_MATERIALS=Q;exports.BUILT_IN_NAME=Z;exports.BUILT_IN_TAGS=te;exports.BUILT_IN_VUE=$;exports.BUILT_IN_VUE_ROUTER=F;exports.Base=ne;exports.BlockModel=E;exports.DirectiveModel=v;exports.EVENT_BLOCK_CHANGE=h;exports.EVENT_HISTORY_CHANGE=y;exports.EVENT_HISTORY_LOAD=R;exports.EVENT_NODE_CHANGE=m;exports.EVENT_PROJECT_ACTIVED=D;exports.EVENT_PROJECT_APIS_CHANGE=S;exports.EVENT_PROJECT_BLOCKS_CHANGE=C;exports.EVENT_PROJECT_CHANGE=f;exports.EVENT_PROJECT_DEPS_CHANGE=k;exports.EVENT_PROJECT_FILE_PUBLISH=j;exports.EVENT_PROJECT_GEN_SOURCE=K;exports.EVENT_PROJECT_META_CHANGE=b;exports.EVENT_PROJECT_PAGES_CHANGE=T;exports.EVENT_PROJECT_PUBLISH=M;exports.EventModel=A;exports.HistoryModel=ae;exports.I18N_LOCALES=ie;exports.NodeModel=_;exports.ProjectModel=w;exports.PropModel=x;exports.Service=se;exports.VTJ_CORE_VERSION=W;exports.cloneDsl=G;exports.createNodeFrom=he;exports.createProjectFileIndex=de;exports.emitter=a;exports.flattenPages=J;exports.getBlockImportPath=z;exports.getFilePath=u;exports.getPageNamePath=N;exports.getPageRoutePath=V;exports.getSourceFilePath=H;exports.getUniPagePath=Y;exports.isBlock=re;exports.isBlockSchema=le;exports.isNode=oe;exports.isValidFilePath=U;exports.isValidRoutePath=q;exports.normalizeFilePath=B;exports.normalizeRoutePath=I;
|
|
7
|
+
*/const W="0.20.5",Z="BuiltIn",$="VueMaterial",F="VueRouterMaterial",Q=[$,F],X={vue:"Vue","vue-router":"VueRouter"},ee={[$]:["Transition","TransitionGroup","KeepAlive","Teleport","Suspense"],[F]:["RouterView","RouterLink"]},te=["slot","template","component","img","div","p","h1","h2","h3","span","a"],ie=[{label:"简体中文",value:"zh-CN"},{label:"English",value:"en"}];class se{getBackendCapabilities;getBackendDraft}class ne{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 x{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 x(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:n,modifiers:r}=s;return t[i]={name:i,handler:n,modifiers:r},t},{})}static parse(e={}){return Object.entries(e).reduce((t,[i,s])=>(t[i]=new A(s),t),{})}}class v{constructor(e){this.schema=e,this.id=e.id||h.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:n,iterator:r}=this.schema;this.name=t,this.arg=i,this.modifiers=s,this.value=n,this.iterator=r}static parse(e=[]){return e.map(t=>new v(t))}static toDsl(e=[]){return e.map(t=>{const{name:i,arg:s,modifiers:n,value:r,iterator:l,id:c}=t;return{id:c,name:i,arg:s,modifiers:n,value:r,iterator:l}})}}const m="EVENT_NODE_CHANGE";class _{constructor(e,t=null){this.parent=t;const{id:i=h.uid(),name:s,from:n=""}=e;this.id=i,this.name=s,this.from=n,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:n=[],slot:r,props:l={},events:c={},directives:P=[]}=e;this.invisible=i,this.locked=s,this.setChildren(n,!0),this.setSlot(r,!0),this.props=x.parse(l),this.events=A.parse(c),this.directives=v.parse(P),t||a.emit(m,this)}setChildren(e="",t=!1){Array.isArray(e)?this.children=e.map(i=>new _(i,this)):this.children=e,t||a.emit(m,this)}setSlot(e,t=!1){this.slot=typeof e=="string"?{name:e,params:[]}:e,t||a.emit(m,this)}setProp(e,t,i,s=!1){const n=this.props[e];n?n.setValue(t):this.props[e]=new x(e,t,i),s||a.emit(m,this)}removeProp(e,t=!1){delete this.props[e],t||a.emit(m,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||a.emit(m,this)}removeEvent(e,t=!1){delete this.events[e],t||a.emit(m,this)}setDirective(e,t=!1){const i=e instanceof v?e:new v(e),s=this.directives.findIndex(n=>n.id===e.id);s>=0?this.directives.splice(s,1,i):this.directives.push(i),t||a.emit(m,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||a.emit(m,this)}removeChild(e,t=!1){const{children:i,disposed:s}=this;if(s||!Array.isArray(i))return;const n=i.findIndex(r=>r===e);e.parent=null,i.splice(n,1),t||a.emit(m,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||a.emit(m,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||a.emit(m,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||a.emit(m,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||a.emit(m,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||a.emit(m,t))}}toDsl(){const{id:e,name:t,from:i,invisible:s,locked:n,slot:r,children:l,props:c,directives:P,events:p}=this,O=Array.isArray(l)?l.map(L=>L.toDsl()):l;return{id:e,name:t,from:i,invisible:s,locked:n,slot:r,children:O,props:x.toDsl(c),directives:v.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||a.emit(m,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||a.emit(m,this)}unlock(e=!1){if(this.locked=!1,Array.isArray(this.children))for(const t of this.children)t.unlock(!0);e||a.emit(m,this)}setVisible(e,t=!1){if(this.invisible=!e,Array.isArray(this.children))for(const i of this.children)i.setVisible(e,!0);t||a.emit(m,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}findChildIndex(e){return Array.isArray(this.children)?this.children.findIndex(t=>t===e||t.id===e.id):-1}}const d="EVENT_BLOCK_CHANGE";class E{__VTJ_BLOCK__=!0;id;name="";apiMode="options";inject=[];state={};refs={};reactives={};lifeCycles={};methods={};computed={};watch=[];composables=[];setup=void 0;provide={};css="";props=[];emits=[];expose=[];slots=[];dataSources={};nodes=[];locked=!1;disposed=!1;static normalAttrs=["name","locked","apiMode","inject","state","refs","reactives","lifeCycles","methods","computed","watch","composables","setup","provide","css","props","emits","expose","slots","dataSources","__TEMPLATE_ID__"];constructor(e){const{id:t}=e;this.id=t||h.uid(),this.update(e,!0)}update(e,t=!1){for(const s of E.normalAttrs){const n=e[s];(n!==void 0||s==="setup")&&(this[s]=n)}const{nodes:i=[]}=e;i.length?this.nodes=i.map(s=>new _(s)):this.nodes=[],t||a.emit(d,this)}toDsl(e){const{__VTJ_BLOCK__:t,id:i,nodes:s}=this;return{...E.normalAttrs.reduce((r,l)=>(r[l]=this[l],r),{}),__VTJ_BLOCK__:t,__VERSION__:e||h.timestamp().toString(),id:i,nodes:s.map(r=>r.toDsl())}}dispose(){this.nodes.map(e=>e.dispose(!0)),this.nodes=[],this.disposed=!0}isExistName(e){return e in this.refs||e in this.reactives||e in this.computed||e in this.methods}setFunction(e,t,i,s=!1){this[e][t]=i,s||a.emit(d,this)}removeFunction(e,t,i=!1){delete this[e][t],i||a.emit(d,this)}setComputed(e,t,i=!1){t?this.computed[e]=t:delete this.computed[e],i||a.emit(d,this)}setState(e,t,i=!1){this.state[e]=t,i||a.emit(d,this)}removeState(e,t=!1){delete this.state[e],t||a.emit(d,this)}setCss(e,t=!1){this.css=e,t||a.emit(d,this)}setWatch(e,t=!1){e.id=e.id||h.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||a.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||a.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||a.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||a.emit(d,this))}setEmit(e,t=!1){const i=h.isString(e)?{name:e,params:[]}:e,s=this.emits.findIndex(n=>n===i.name||n.name===i.name);s>-1?this.emits.splice(s,1,i):this.emits.push(i),t||a.emit(d,this)}removeEmit(e,t=!1){const i=this.emits.findIndex(s=>h.isString(s)?s===e:s.name===e);i>-1&&(this.emits.splice(i,1),t||a.emit(d,this))}setExpose(e,t=!1){this.expose=e,t||a.emit(d,this)}setSlot(e,t=!1){const i=h.isString(e)?{name:e,params:[]}:e,s=this.slots.findIndex(n=>n===i.name||n.name===i.name);s>-1?this.slots.splice(s,1,i):this.slots.push(i),t||a.emit(d,this)}removeSlot(e,t=!1){const i=this.slots.findIndex(s=>h.isString(s)?s===e:s.name===e);i>-1&&(this.slots.splice(i,1),t||a.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||a.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||a.emit(d,this))}setDataSource(e,t=!1){this.dataSources[e.name]=e,t||a.emit(d,this)}removeDataSource(e,t=!1){delete this.dataSources[e],t||a.emit(d,this)}setApiMode(e,t=!1){this.apiMode=e,t||a.emit(d,this)}setRef(e,t,i=!1){this.refs[e]=t,i||a.emit(d,this)}removeRef(e,t=!1){delete this.refs[e],t||a.emit(d,this)}setReactive(e,t,i=!1){this.reactives[e]=t,i||a.emit(d,this)}removeReactive(e,t=!1){delete this.reactives[e],t||a.emit(d,this)}setComposable(e,t=!1){const i=this.composables.findIndex(s=>s.name===e.name);i>-1?this.composables.splice(i,1,e):this.composables.push(e),t||a.emit(d,this)}removeComposable(e,t=!1){const i=this.composables.findIndex(s=>s.name===e);i>-1&&(this.composables.splice(i,1),t||a.emit(d,this))}setProvide(e,t,i=!1){this.provide[e]=t,i||a.emit(d,this)}removeProvide(e,t=!1){delete this.provide[e],t||a.emit(d,this)}setSetup(e,t=!1){this.setup=e,t||a.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||a.emit(d,this)}insertBefore(e,t,i=!1){e.parent=null;const s=this.nodes.indexOf(t);this.nodes.splice(s,0,e),i||a.emit(d,this)}appendNode(e,t=!1){e.parent=null,this.nodes.push(e),t||a.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||a.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||a.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||a.emit(d,this))}}cloneNode(e,t=!1){const i=G(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||a.emit(d,this)}unlock(e=!1){this.locked=!1;for(const t of this.nodes)t.unlock(!0);e||a.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",D="EVENT_PROJECT_ACTIVED",k="EVENT_PROJECT_DEPS_CHANGE",T="EVENT_PROJECT_PAGES_CHANGE",C="EVENT_PROJECT_BLOCKS_CHANGE",S="EVENT_PROJECT_APIS_CHANGE",b="EVENT_PROJECT_META_CHANGE",M="EVENT_PROJECT_PUBLISH",j="EVENT_PROJECT_FILE_PUBLISH",K="EVENT_PROJECT_GEN_SOURCE";class w{id="";locked="";platform="web";name="";description="";homepage="";dependencies=[];pages=[];blocks=[];apis=[];meta=[];currentFile=null;config={};uniConfig={};globals={};i18n={locale:"zh-CN",fallbackLocale:"zh-CN",messages:[]};env=[];__BASE_PATH__="/";__UID__=h.uuid(!0);static attrs=["locked","platform","name","homepage","description","dependencies","pages","blocks","apis","meta","config","uniConfig","globals","i18n","env","__BASE_PATH__","__UID__"];constructor(e){const{id:t,__UID__:i}=e;this.id=t||h.uid(),this.__UID__=i||h.uuid(!0),this.update(e,!0)}update(e,t=!1){for(const i of w.attrs){const s=e[i];s&&(this[i]=s)}t||a.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=w.attrs.reduce((s,n)=>(s[n]=this[n],s),{});return i.pages&&(i.pages=i.pages.map(s=>h.cloneDeep({...s,dsl:void 0})),this.cleanPagesDsl(i.pages)),i.blocks&&(i.blocks=i.blocks.map(s=>h.cloneDeep({...s,dsl:void 0}))),{__VTJ_PROJECT__:!0,id:t,...i}}active(e,t=!1){this.currentFile=e,t||a.emit(D,{model:this,type:"update",data:e})}deactivate(e=!1){this.currentFile=null,e||a.emit(D,{model:this,type:"update",data:null})}setDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(r=>r.package===e.package);let n;if(s>-1?(n="update",i.splice(s,1,{...i[s],...e})):(n="create",i.push(e)),!t){const r={model:this,type:n,data:e};a.emit(k,r),a.emit(f,r)}}removeDeps(e,t=!1){const i=this.dependencies,s=i.findIndex(n=>n.package===e.package);if(s>-1&&i.splice(s,1),!t){const n={model:this,type:"delete",data:e};a.emit(k,n),a.emit(f,n)}}getPage(e){const t=(i,s=[])=>{for(const n of s){if(n.id===i)return n;if(n.children&&n.children.length){const r=t(i,n.children);if(r)return r}}};return t(e,this.pages)}getPages(){const e=(t=[])=>{let i=[];for(const s of t)s.dir||s.layout?(s.layout&&i.push(s),s.children&&s.children.length&&(i=i.concat(e(s.children)))):i.push(s);return i};return e(this.pages)}getHomepage(){return this.homepage?this.getPage(this.homepage):this.getPages()[0]}async createPage(e,t,i=!1){if(e.id=e.id||h.uid(),e.type="page",e.name=h.upperFirstCamelCase(e.name),this.existPageName(e.name))throw new Error(`页面名称【${e.name}】已经存在`);if(e.dir)delete e.filePath,delete e.routePath;else{const s=N(e.name);e.filePath=s,e.routePath=this.platform==="uniapp"?void 0:`/page/${s}`}if(this.validatePagePath(e),e.dir?e.children=[]:e.dsl=e.dsl||new E({id:e.id,name:h.upperFirstCamelCase(e.name),apiMode:"composition"}).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};a.emit(T,s),a.emit(f,s)}return!this.currentFile&&!e.dir&&(this.active(e,!0),await h.delay(1e3),this.active(e,i)),e}updatePage(e,t=!1){const i=this.getPage(e.id);let s;if(delete e.dsl,i){if(s={...i},e.name=h.upperFirstCamelCase(e.name),this.existPageName(e.name,[e.id]))throw new Error(`页面名称【${e.name}】已经存在`);if(e.name!==i.name&&!i.raw){const n=N(i.name);i.filePath===n&&(e.filePath=N(e.name)),this.platform!=="uniapp"&&i.routePath===`/page/${n}`&&(e.routePath=`/page/${N(e.name)}`)}this.validatePagePath(e,[e.id]),Object.assign(i,e)}else console.warn(`not found PageFile for id: ${e.id} `);if(!t){const n={model:this,type:"update",data:e,previous:s};a.emit(T,n),a.emit(f,n)}return i}findParent(e){const t=(i,s=[],n)=>{for(const r of s){if(r.id===i)return n;if(r.children&&r.children.length){const l=t(i,r.children,r);if(l)return l}}};return t(e,this.pages)}movePageTo(e,t,i=!1){const s=t?this.getPage(t):null,n=this.getPage(e);if(!n)return!1;const r=this.findParent(e);if(r?r.children=r.children?.filter(l=>l.id!==e):this.pages=this.pages.filter(l=>l.id!==e),s?(s.dir||s.layout)&&(s.children?s.children.push(n):s.children=[n]):this.pages.push(n),!i){const l={model:this,type:"update",data:n};a.emit(T,l),a.emit(f,l)}return!0}getPageTree(){const e=h.cloneDeep(this.pages);return this.cleanPagesDsl(e),e}clonePage(e,t,i=!1){const s=h.uid(),n=this.createUniquePath(`${e.name}Copy`,g=>this.existPageName(g)),r=`${e.title}_副本`,l=new E({id:s,name:n,apiMode:"composition"}).toDsl(),c=N(n),P=this.platform==="uniapp"?void 0:`/page/${c}`,p=h.merge({},e,{id:s,name:n,title:r,filePath:c,routePath:P,dsl:l}),O=t?this.getPage(t)?.children||[]:this.pages,L=O.findIndex(g=>g.id===e.id);if(O.splice(L+1,0,p),!i){const g={model:this,type:"clone",data:{source:e,target:p}};a.emit(T,g),a.emit(f,g)}}async saveToBlock(e,t=!1){this.active(e,t),await h.delay(1e3);const i=h.uid(),s=this.createUniquePath(e.name,c=>this.existBlockName(c)),n=e.title,r=new E({...e.dsl,id:i,name:s}).toDsl(),l={id:i,name:s,title:n,filePath:s,dsl:r,type:"block",fromType:"Schema"};if(this.blocks.push(l),!t){const c={model:this,type:"create",data:l};a.emit(C,c),a.emit(f,c)}}removePage(e,t=!1){const i=this.getPage(e),s=(n,r)=>{const l=r.findIndex(c=>c.id===n);if(l>=0){r.splice(l,1);return}for(const c of r)c.children&&c.children.length&&s(n,c.children)};if(s(e,this.pages),e===this.homepage&&(this.homepage=""),this.currentFile?.id===e&&this.deactivate(t),!t){const n={model:this,type:"delete",data:i};a.emit(T,n),a.emit(f,n)}}getBlock(e){return this.blocks.find(t=>t.id===e)}getFile(e){return this.getPage(e)||this.getBlock(e)}async createBlock(e,t=!1){const i=e.id||h.uid(),s=h.upperFirstCamelCase(e.name);if(e.id=i,e.name=s,e.type="block",e.fromType=e.fromType||"Schema",this.existBlockName(s))throw new Error(`区块名称【${s}】已经存在`);e.fromType==="Schema"?e.filePath=s:delete e.filePath,this.validateBlockPath(e),e.dsl=new E({id:i,name:s,apiMode:"composition"}).toDsl(),this.blocks.push(e);const n=e.fromType||"Schema";if(!t){const r={model:this,type:"create",data:e};a.emit(C,r),a.emit(f,r)}return!this.currentFile&&n==="Schema"&&(this.active(e,!0),await h.delay(1e3),this.active(e,t)),e}updateBlock(e,t=!1){const i=this.getBlock(e.id);let s;if(i){if(s={...i},e.name=h.upperFirstCamelCase(e.name),this.existBlockName(e.name,[e.id]))throw new Error(`区块名称【${e.name}】已经存在`);e.name!==i.name&&(i.fromType||"Schema")==="Schema"&&i.filePath===i.name&&(e.filePath=e.name),this.validateBlockPath(e,[e.id]),Object.assign(i,e),i.dsl&&(i.dsl.name=e.name)}else console.warn(`not found PageFile for id: ${e.id} `);if(!t){const n={model:this,type:"update",data:e,previous:s};a.emit(C,n),a.emit(f,n)}return i}cloneBlock(e,t=!1){const i=h.uid(),s=this.createUniquePath(`${e.name}Copy`,p=>this.existBlockName(p)),n=`${e.title}_副本`,r=new E({id:i,name:s,apiMode:"composition"}).toDsl(),l=s,c=h.merge({},e,{id:i,name:s,title:n,filePath:l,dsl:r}),P=this.blocks.findIndex(p=>p.id===e.id);if(this.blocks.splice(P+1,0,c),!t){const p={model:this,type:"clone",data:{source:e,target:c}};a.emit(C,p),a.emit(f,p)}}removeBlock(e,t=!1){const i=this.getBlock(e),s=this.blocks,n=s.findIndex(r=>r.id===e);if(n>-1?(s.splice(n,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};a.emit(C,r),a.emit(f,r)}}existBlockName(e,t=[]){const i=e.toLowerCase();return this.blocks.some(s=>s.name.toLowerCase()===i&&!t.includes(s.id))}existBlockFilePath(e,t=[]){const i=B(e).toLowerCase();return this.blocks.some(s=>u(s).toLowerCase()===i&&!t.includes(s.id))}existPageName(e,t=[]){const i=e.toLowerCase(),s=n=>n.some(r=>r.name.toLowerCase()===i&&!t.includes(r.id)?!0:r.children?.length?s(r.children):!1);return s(this.pages)}existPageFilePath(e,t=[]){const i=B(e).toLowerCase();return this.getPages().some(s=>u(s).toLowerCase()===i&&!t.includes(s.id))}existRoutePath(e,t=[]){const i=I(e).replace(/:[^/]+/g,":");return this.getPages().some(s=>V(s).replace(/:[^/]+/g,":")===i&&!t.includes(s.id))}validatePagePath(e,t=[]){const i=u(e);if(!e.dir&&!U(i))throw new Error(`页面文件路径【${i}】格式不正确`);if(!q(e.routePath))throw new Error(`页面路由【${e.routePath}】格式不正确`);if(!e.dir&&this.existPageFilePath(u(e),t))throw new Error(`页面文件路径【${u(e)}】已经存在`);const s=V(e);if(!e.dir&&this.existRoutePath(s,t))throw new Error(`页面路由【${s}】已经存在`)}validateBlockPath(e,t=[]){const i=u(e);if(!U(i))throw new Error(`区块文件路径【${i}】格式不正确`);if((e.fromType||this.getBlock(e.id)?.fromType||"Schema")==="Schema"&&this.existBlockFilePath(u(e),t))throw new Error(`区块文件路径【${u(e)}】已经存在`)}createUniquePath(e,t){const i=e;let s=i,n=2;for(;t(s);)s=`${i}${n++}`;return s}setApi(e,t=!1){const i=this.apis.find(n=>n.name===e.name||n.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=h.uid(),this.apis.push(e)),!t){const n={model:this,type:s,data:e};a.emit(S,n),a.emit(f,n)}return i||e}setApis(e,t=!1){for(const i of e)this.setApi(i,!0);if(!t){const i={model:this,type:"create",data:e};a.emit(S,i),a.emit(f,i)}}removeApi(e,t=!1){const i=this.apis.findIndex(s=>s.name===e||s.id===e);if(i>-1?this.apis.splice(i,1):console.warn(`not found Api for name: ${e} `),!t){const s={model:this,type:"delete",data:e};a.emit(S,s),a.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(n=>n.code===e.code||n.id===e.id);let s;if(i?(s="update",Object.assign(i,e)):(s="create",e.id=h.uid(),this.meta.push(e)),!t){const n={model:this,type:s,data:e};a.emit(b,n),a.emit(f,n)}}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};a.emit(b,s),a.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};a.emit(f,i)}}setConfig(e,t=!1){if(this.config=Object.assign(this.config,e),!t){const i={model:this,type:"update",data:e};a.emit(f,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};a.emit(f,s)}}setGloblas(e,t,i=!1){if(this.globals=Object.assign(this.globals,{[e]:t}),!i){const s={model:this,type:"update",data:this.globals};a.emit(f,s)}}setI18n(e,t=!1){if(this.i18n=Object.assign(this.i18n,e),!t){const i={model:this,type:"update",data:this.i18n};a.emit(f,i)}}setEnv(e,t=!1){if(this.env=[...e],!t){const i={model:this,type:"update",data:this.env};a.emit(f,i)}}publish(e){const t={model:this,type:"publish",data:e||this};e?a.emit(j,t):a.emit(M,t)}genSource(){const e={model:this,type:"gen",data:null};a.emit(K,e)}lock(e){this.locked=e;const t={model:this,type:"update",data:e};a.emit(f,t)}unlock(e){if(e!==this.locked)return;this.locked="";const t={model:this,type:"update",data:null};a.emit(f,t)}getPageRoutes(e,t){const i=this.platform==="uniapp",s=e||(i?"pages":"page"),n=this.getPages(),r=t||"";return n.map(l=>{const c=i?`/${Y(l)}`:V(l,`${r}/`,s);return{id:l.id,path:c,name:l.name,title:l.title,meta:l.meta}})}}const y="EVENT_HISTORY_CHANGE",R="EVENT_HISTORY_LOAD";class ae{options={max:50};index=-1;id;type;items;constructor(e,t={}){Object.assign(this.options,t);const{id:i,type:s="file",items:n=[]}=e;this.id=i,this.type=s,this.items=n}toDsl(){const{id:e,type:t,items:i}=this;return{id:e,type:t,items:i.map(s=>({id:s.id,label:s.label,remark:s.remark||""}))}}get(e){return this.items.find(t=>t.id===e)}add(e,t="",i=!1){const{max:s}=this.options,n={id:h.uid(),label:new Date().toLocaleString(),remark:t,dsl:h.cloneDeep(e)};this.items.unshift(n);const r=this.items.filter(l=>!l.remark);if(r.length>s){const l=r.splice(s).map(c=>c.id);this.items=this.items.filter(c=>!l.includes(c.id)),i||a.emit(y,{model:this,type:"delete",data:l})}this.index=-1,i||a.emit(y,{model:this,type:"create",data:n})}update(e,t=!1){const i=this.items.find(s=>s.id===e.id);i&&Object.assign(i,e),t||a.emit(y,{model:this,type:"update",data:i})}remove(e,t=!1){const i=h.toArray(e);for(const s of i){const n=this.items.findIndex(r=>r.id===s);n>-1?(this.items.splice(n,1),n===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||a.emit(y,{model:this,type:"delete",data:i})}forward(e=!1){const{index:t,items:i}=this;if(t<0)return;--this.index;const s=i[this.index];s&&!e&&a.emit(R,{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&&a.emit(R,{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||a.emit(R,{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||a.emit(y,{model:this,type:"clear",data:t})}}const a=h.mitt();function re(o){return o instanceof E}function oe(o){return o instanceof _}function le(o){return!!o.__VTJ_BLOCK__}function G(o){const e=h.cloneDeep(o);return delete e.id,Array.isArray(e.children)&&(e.children=e.children.map(t=>G(t))),e}function de(o){const e=o.fromType||"Schema";return e==="Schema"?{type:"Schema",id:o.id}:e==="UrlSchema"?{type:"UrlSchema",url:(o.urls||"").split(",")[0]||""}:e==="Plugin"?{type:"Plugin",urls:(o.urls||"").split(","),library:o.library}:""}function B(o){return(o||"").trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,"").replace(/\.vue$/i,"")}function I(o){const e=(o||"").trim().replace(/\\/g,"/");if(!e)return"";const t=`/${e}`.replace(/\/{2,}/g,"/");return t.length>1?t.replace(/\/$/,""):t}function u(o){return B(o.filePath)||o.id}function N(o){return h.kebabCase(o)}function H(o,e="web"){const t=u(o);return o.type==="block"?`src/components/${t}.vue`:e==="uniapp"?`src/pages/${t}.vue`:`src/views/${t}.vue`}function z(o){return`@/components/${u(o)}.vue`}function V(o,e="",t="page"){const i=I(o.routePath);if(i)return i;if(o.filePath){const s=u(o).split("/").map(n=>h.kebabCase(n)).join("/");return I(`${e}${t}/${s}`)}return I(`${e}${t}/${o.id}`)}function Y(o){return`pages/${u(o)}`}function J(o=[]){const e=[];for(const t of o)t.dir||e.push(t),t.children?.length&&e.push(...J(t.children));return e}function he(o){const e=new Map,t=new Map,i=new Map,s=new Map;for(const n of o.blocks||[]){const r=H(n,o.platform).toLowerCase();e.set(n.id,n),i.set(r,n.id),t.set(z(n).toLowerCase(),n.id)}for(const n of J(o.pages))e.set(n.id,n),s.set(H(n,o.platform).toLowerCase(),n.id);return{byId:e,blockIdByImportPath:t,blockIdBySourcePath:i,pageIdBySourcePath:s}}function U(o){if(!o)return!0;const e=o.trim();return!!e&&!e.startsWith("/")&&!e.endsWith(".vue")&&!/[\\?#]/.test(e)&&e.split("/").every(t=>/^(?!\.{1,2}$)[A-Za-z0-9_-]+$/.test(t))}function q(o){return o?o.startsWith("/")&&!/[?#]/.test(o):!0}exports.BUILT_IN_COMPONENTS=ee;exports.BUILT_IN_LIBRARAY_MAP=X;exports.BUILT_IN_MATERIALS=Q;exports.BUILT_IN_NAME=Z;exports.BUILT_IN_TAGS=te;exports.BUILT_IN_VUE=$;exports.BUILT_IN_VUE_ROUTER=F;exports.Base=ne;exports.BlockModel=E;exports.DirectiveModel=v;exports.EVENT_BLOCK_CHANGE=d;exports.EVENT_HISTORY_CHANGE=y;exports.EVENT_HISTORY_LOAD=R;exports.EVENT_NODE_CHANGE=m;exports.EVENT_PROJECT_ACTIVED=D;exports.EVENT_PROJECT_APIS_CHANGE=S;exports.EVENT_PROJECT_BLOCKS_CHANGE=C;exports.EVENT_PROJECT_CHANGE=f;exports.EVENT_PROJECT_DEPS_CHANGE=k;exports.EVENT_PROJECT_FILE_PUBLISH=j;exports.EVENT_PROJECT_GEN_SOURCE=K;exports.EVENT_PROJECT_META_CHANGE=b;exports.EVENT_PROJECT_PAGES_CHANGE=T;exports.EVENT_PROJECT_PUBLISH=M;exports.EventModel=A;exports.HistoryModel=ae;exports.I18N_LOCALES=ie;exports.NodeModel=_;exports.ProjectModel=w;exports.PropModel=x;exports.Service=se;exports.VTJ_CORE_VERSION=W;exports.cloneDsl=G;exports.createNodeFrom=de;exports.createProjectFileIndex=he;exports.emitter=a;exports.flattenPages=J;exports.getBlockImportPath=z;exports.getFilePath=u;exports.getPageNamePath=N;exports.getPageRoutePath=V;exports.getSourceFilePath=H;exports.getUniPagePath=Y;exports.isBlock=re;exports.isBlockSchema=le;exports.isNode=oe;exports.isValidFilePath=U;exports.isValidRoutePath=q;exports.normalizeFilePath=B;exports.normalizeRoutePath=I;
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import { uid as m, timestamp as Z, isString as S, uuid as H, cloneDeep as A, upp
|
|
|
3
3
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
4
4
|
* @name @vtj/core
|
|
5
5
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
6
|
-
* @version 0.20.
|
|
6
|
+
* @version 0.20.5
|
|
7
7
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
8
8
|
*/
|
|
9
|
-
const oe = "0.20.
|
|
9
|
+
const oe = "0.20.5", le = "BuiltIn", z = "VueMaterial", W = "VueRouterMaterial", he = [z, W], de = {
|
|
10
10
|
vue: "Vue",
|
|
11
11
|
"vue-router": "VueRouter"
|
|
12
12
|
}, ce = {
|
|
@@ -41,6 +41,10 @@ const oe = "0.20.4", le = "BuiltIn", z = "VueMaterial", W = "VueRouterMaterial",
|
|
|
41
41
|
}
|
|
42
42
|
];
|
|
43
43
|
class pe {
|
|
44
|
+
/** 可选后端能力;未实现时设计器不显示后端入口。 */
|
|
45
|
+
getBackendCapabilities;
|
|
46
|
+
/** 只读获取草稿,不将后端协议嵌入前端项目 DSL。 */
|
|
47
|
+
getBackendDraft;
|
|
44
48
|
}
|
|
45
49
|
class ue {
|
|
46
50
|
listeners = [];
|
package/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BackendModelSchema } from './model';
|
|
2
|
+
export * from './model';
|
|
3
|
+
/**
|
|
4
|
+
* 后端模型协议 v1,与 ProjectSchema 并列。
|
|
5
|
+
* 应用、环境、草稿 revision 与发布状态由平台管理,不嵌入协议。
|
|
6
|
+
* 首期仅声明模型 CRUD,不支持自定义代码 API、SQL 或执行钩子。
|
|
7
|
+
* 类型不代替运行时校验,未知版本和属性须由服务端拒绝。
|
|
8
|
+
*/
|
|
9
|
+
export interface BackendSchema {
|
|
10
|
+
dslVersion: '1.0';
|
|
11
|
+
models: BackendModelSchema[];
|
|
12
|
+
}
|
|
13
|
+
/** 当前项目可用的后端读取能力,不代表服务端授权。 */
|
|
14
|
+
export interface BackendCapabilities {
|
|
15
|
+
protocolVersions: string[];
|
|
16
|
+
operations: 'read'[];
|
|
17
|
+
}
|
|
18
|
+
/** 独立于 ProjectSchema 的后端草稿视图。 */
|
|
19
|
+
export interface BackendDraftView {
|
|
20
|
+
schema: BackendSchema;
|
|
21
|
+
revision: number;
|
|
22
|
+
appliedReleaseId: string | null;
|
|
23
|
+
appliedRevision: number | null;
|
|
24
|
+
}
|
|
25
|
+
/** 模型编辑器和 AI 共用的校验诊断,不包含内部 SQL 或凭据。 */
|
|
26
|
+
export interface BackendDiagnostic {
|
|
27
|
+
code: string;
|
|
28
|
+
/** JSON Pointer,例如 /models/0/fields/1/default。 */
|
|
29
|
+
path: string;
|
|
30
|
+
message: string;
|
|
31
|
+
severity: 'error' | 'warning';
|
|
32
|
+
modelId?: string;
|
|
33
|
+
fieldId?: string;
|
|
34
|
+
}
|
|
35
|
+
/** 成功时返回规范化协议;失败时不能消费 normalized 或 schemaHash。 */
|
|
36
|
+
export type BackendValidationResult = {
|
|
37
|
+
valid: true;
|
|
38
|
+
diagnostics: BackendDiagnostic[];
|
|
39
|
+
truncated: boolean;
|
|
40
|
+
normalized: BackendSchema;
|
|
41
|
+
schemaHash: string;
|
|
42
|
+
} | {
|
|
43
|
+
valid: false;
|
|
44
|
+
diagnostics: BackendDiagnostic[];
|
|
45
|
+
truncated: boolean;
|
|
46
|
+
normalized?: never;
|
|
47
|
+
schemaHash?: never;
|
|
48
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 可持久化的 JSON 值。与现有 JSONValue 不同,不包含 undefined。
|
|
3
|
+
* 有限数字、对象深度等约束仍须由服务端验证。
|
|
4
|
+
*/
|
|
5
|
+
export type BackendJSONValue = string | number | boolean | null | BackendJSONValue[] | {
|
|
6
|
+
[key: string]: BackendJSONValue;
|
|
7
|
+
};
|
|
8
|
+
/** 模型对外开放的 CRUD 操作。未声明的操作不可调用。 */
|
|
9
|
+
export type BackendOperation = 'list' | 'get' | 'create' | 'update' | 'delete';
|
|
10
|
+
/** 字段公共信息,不包含数据库物理映射。 */
|
|
11
|
+
interface BackendFieldBase {
|
|
12
|
+
/** 模型内唯一、不可变的逻辑标识。 */
|
|
13
|
+
id: string;
|
|
14
|
+
/** 模型内唯一的逻辑名称;应用到数据库后不可修改。 */
|
|
15
|
+
name: string;
|
|
16
|
+
/** 展示标题。省略时由消费者使用 name。 */
|
|
17
|
+
label?: string;
|
|
18
|
+
/** 创建时是否必须提供值;缺失时先应用 default。默认 false。 */
|
|
19
|
+
required?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* nullable 默认 false;显式 null 默认值必须声明 nullable: true。
|
|
23
|
+
* required/default/nullable 的组合及默认值范围由服务端验证。
|
|
24
|
+
* PATCH 中字段缺失表示不修改,不触发默认值。
|
|
25
|
+
*/
|
|
26
|
+
type BackendFieldDefault<T> = {
|
|
27
|
+
nullable?: false;
|
|
28
|
+
default?: T;
|
|
29
|
+
} | {
|
|
30
|
+
nullable: true;
|
|
31
|
+
default?: T | null;
|
|
32
|
+
};
|
|
33
|
+
export type BackendStringFieldSchema = BackendFieldBase & BackendFieldDefault<string> & {
|
|
34
|
+
type: 'string';
|
|
35
|
+
maxLength: number;
|
|
36
|
+
minLength?: number;
|
|
37
|
+
};
|
|
38
|
+
export type BackendTextFieldSchema = BackendFieldBase & BackendFieldDefault<string> & {
|
|
39
|
+
type: 'text';
|
|
40
|
+
maxLength?: number;
|
|
41
|
+
};
|
|
42
|
+
export type BackendIntegerFieldSchema = BackendFieldBase & BackendFieldDefault<number> & {
|
|
43
|
+
type: 'integer';
|
|
44
|
+
/** 首期为有符号 INT,运行时拒绝浮点数和隐式转换。 */
|
|
45
|
+
minimum?: number;
|
|
46
|
+
maximum?: number;
|
|
47
|
+
};
|
|
48
|
+
export type BackendDecimalFieldSchema = BackendFieldBase & BackendFieldDefault<string> & {
|
|
49
|
+
type: 'decimal';
|
|
50
|
+
precision: number;
|
|
51
|
+
scale: number;
|
|
52
|
+
/** 十进制字符串,禁止指数形式与隐式舍入。 */
|
|
53
|
+
minimum?: string;
|
|
54
|
+
maximum?: string;
|
|
55
|
+
};
|
|
56
|
+
export type BackendBooleanFieldSchema = BackendFieldBase & BackendFieldDefault<boolean> & {
|
|
57
|
+
type: 'boolean';
|
|
58
|
+
};
|
|
59
|
+
export type BackendDateFieldSchema = BackendFieldBase & BackendFieldDefault<string> & {
|
|
60
|
+
/** YYYY-MM-DD,真实日期合法性由服务端验证。 */
|
|
61
|
+
type: 'date';
|
|
62
|
+
};
|
|
63
|
+
export type BackendDatetimeFieldSchema = BackendFieldBase & BackendFieldDefault<string> & {
|
|
64
|
+
/** 带时区的 ISO 输入,统一使用 UTC。 */
|
|
65
|
+
type: 'datetime';
|
|
66
|
+
};
|
|
67
|
+
export type BackendEnumFieldSchema = BackendFieldBase & BackendFieldDefault<string> & {
|
|
68
|
+
type: 'enum';
|
|
69
|
+
/** 非空、无重复字符串集合,default 必须属于该集合。 */
|
|
70
|
+
values: string[];
|
|
71
|
+
};
|
|
72
|
+
export type BackendJsonFieldSchema = BackendFieldBase & BackendFieldDefault<Exclude<BackendJSONValue, null>> & {
|
|
73
|
+
type: 'json';
|
|
74
|
+
};
|
|
75
|
+
export type BackendReferenceFieldSchema = BackendFieldBase & {
|
|
76
|
+
type: 'reference';
|
|
77
|
+
nullable?: boolean;
|
|
78
|
+
/** 同应用目标模型的 id,引用其系统主键。不支持级联写入。 */
|
|
79
|
+
targetModelId: string;
|
|
80
|
+
/** 首期不允许引用字段声明默认值。 */
|
|
81
|
+
default?: never;
|
|
82
|
+
};
|
|
83
|
+
/** 以 type 区分字段属性;不支持代码、SQL 或表达式类型。 */
|
|
84
|
+
export type BackendFieldSchema = BackendStringFieldSchema | BackendTextFieldSchema | BackendIntegerFieldSchema | BackendDecimalFieldSchema | BackendBooleanFieldSchema | BackendDateFieldSchema | BackendDatetimeFieldSchema | BackendEnumFieldSchema | BackendJsonFieldSchema | BackendReferenceFieldSchema;
|
|
85
|
+
export interface BackendIndexSchema {
|
|
86
|
+
/** 模型内唯一标识。 */
|
|
87
|
+
id: string;
|
|
88
|
+
/** 有序的字段 id 列表,不是字段名或 SQL 列名。 */
|
|
89
|
+
fields: string[];
|
|
90
|
+
/** 默认 false。nullable 字段的唯一约束允许多个 NULL。 */
|
|
91
|
+
unique?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 正向授权策略。无匹配策略时拒绝;不能突破模型 operations。
|
|
95
|
+
* 首期同一操作的策略字段集合须一致,由服务端校验。
|
|
96
|
+
*/
|
|
97
|
+
export interface BackendPolicySchema {
|
|
98
|
+
role: string;
|
|
99
|
+
actions: BackendOperation[];
|
|
100
|
+
/** owner 由服务端注入的 createdBy 判定。 */
|
|
101
|
+
scope: 'all' | 'owner';
|
|
102
|
+
/** 可读取的自定义字段 id。系统字段投影由运行时控制。 */
|
|
103
|
+
readFields: string[];
|
|
104
|
+
/** 可写入的自定义字段 id,不包含系统字段。 */
|
|
105
|
+
writeFields: string[];
|
|
106
|
+
}
|
|
107
|
+
export interface BackendModelSchema {
|
|
108
|
+
/** 应用内唯一、不可变的模型逻辑标识。 */
|
|
109
|
+
id: string;
|
|
110
|
+
/** 应用内唯一逻辑名称,应用到数据库后不可修改。 */
|
|
111
|
+
name: string;
|
|
112
|
+
label: string;
|
|
113
|
+
/** 系统字段由运行时维护,不在此声明。 */
|
|
114
|
+
fields: BackendFieldSchema[];
|
|
115
|
+
indexes?: BackendIndexSchema[];
|
|
116
|
+
operations: BackendOperation[];
|
|
117
|
+
policies: BackendPolicySchema[];
|
|
118
|
+
}
|
|
119
|
+
export {};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { ProjectSchema, BlockSchema, HistorySchema, HistoryItem, PageFile, BlockFile, NodeFromPlugin } from './schemas';
|
|
1
|
+
import { BackendCapabilities, BackendDraftView, ProjectSchema, BlockSchema, HistorySchema, HistoryItem, PageFile, BlockFile, NodeFromPlugin } from './schemas';
|
|
2
2
|
import { MaterialDescription } from './assets';
|
|
3
3
|
import { StaticFileInfo, VTJConfig, ParseVueOptions } from './shared';
|
|
4
4
|
export declare abstract class Service {
|
|
5
|
+
/** 可选后端能力;未实现时设计器不显示后端入口。 */
|
|
6
|
+
getBackendCapabilities?: (projectId: string) => Promise<BackendCapabilities>;
|
|
7
|
+
/** 只读获取草稿,不将后端协议嵌入前端项目 DSL。 */
|
|
8
|
+
getBackendDraft?: (projectId: string) => Promise<BackendDraftView>;
|
|
5
9
|
/**
|
|
6
10
|
* 获取低代码设计器配置
|
|
7
11
|
*/
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/core
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.20.
|
|
5
|
+
* @version 0.20.4
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.20.
|
|
8
|
+
export declare const version = "0.20.4";
|