@vtj/core 0.1.0
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/CHANGELOG.md +0 -0
- package/README.md +2 -0
- package/index.cjs.js +60 -0
- package/package.json +26 -0
- package/types.d.ts +275 -0
package/CHANGELOG.md
ADDED
|
File without changes
|
package/README.md
ADDED
package/index.cjs.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";var Ne=Object.defineProperty,Ce=Object.defineProperties;var Ie=Object.getOwnPropertyDescriptors;var re=Object.getOwnPropertySymbols;var Me=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var J=(t,e,n)=>e in t?Ne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,p=(t,e)=>{for(var n in e||(e={}))Me.call(e,n)&&J(t,n,e[n]);if(re)for(var n of re(e))Te.call(e,n)&&J(t,n,e[n]);return t},b=(t,e)=>Ce(t,Ie(e));var l=(t,e,n)=>(J(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var oe=require("lodash-es"),Re=require("prettier"),Be=require("prettier/parser-html"),Ve=require("prettier/parser-babel"),De=require("prettier/parser-postcss"),Le=require("vue/compiler-sfc");function D(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}function k(t){if(t&&t.__esModule)return t;var e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return t&&Object.keys(t).forEach(function(n){if(n!=="default"){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}var G=D(Re),Fe=D(Be),Je=D(Ve),qe=D(De),A=k(Le);function W(t,e){if(t&&t.toSchema){if(e(t,t.parent)===!1)return;Object.values(t.config).forEach(s=>{Array.isArray(s)?s.forEach(r=>{W(r,e)}):W(s,e)})}}function O(t,e,n=null){if(t&&t.__model_id__){if(e(t,n)===!1)return;Object.values(t).forEach(r=>{Array.isArray(r)?r.forEach(o=>{O(o,e,t)}):O(r,e,t)})}}const V=class{constructor(e,n){l(this,"id");l(this,"config");l(this,"disposed",!1);l(this,"parent",null);l(this,"modelName","Base");this.config=p(p({},oe.cloneDeep(n)),e),this.id=(e==null?void 0:e.__model_id__)||he(),this.defineExtendMethods(),V.instances[this.id]=this}defineExtendMethods(){const e={enumerable:!1,writable:!1,configurable:!1};Object.keys(this.config).forEach(n=>{if(n.startsWith("__"))return;let s=oe.upperFirst(n);Object.defineProperty(this,`get${s}`,b(p({},e),{value:()=>this.get(s)})),Object.defineProperty(this,`set${s}`,b(p({},e),{value:o=>{this.set(s,o)}}));const r=this.config[n];Array.isArray(r)&&(s==="Classes"?s="Class":s=s.endsWith("s")?s.substring(0,s.length-1):s,Object.defineProperty(this,`add${s}`,b(p({},e),{value:(o,i)=>this.add(s,o,i)})),Object.defineProperty(this,`remove${s}`,b(p({},e),{value:(o,i)=>this.remove(s,o,i)})))})}get(e){return this.config[e]}set(e,n){if(!this.disposed)return this.config[e]=n}add(e,n,s){const r=this.get(e);!Array.isArray(r)||(!s||s&&!r.find(s))&&(n.parent=this,r.push(n))}remove(e,n,s){const r=this.get(e);if(!Array.isArray(r))return;const o=r.findIndex(s||(i=>i===n));o>-1&&(r[o].parent=null,r.splice(o,1))}clear(e){const n=this.config[e];!Array.isArray(n)||this.set(e,[])}dispose(){this.disposed=!0,this.parent=null,this.config=Object.create(null),delete V.instances[this.id]}toSchema(){const{config:e,id:n}=this,s=this.modelName,r={};return Object.keys(e).forEach(o=>{const i=e[o];Array.isArray(i)?r[o]=i.map(a=>a&&a.toSchema?a.toSchema():a):r[o]=i&&i.toSchema?i.toSchema():i}),p({__model_id__:n,__model_name__:s},r)}};let f=V;l(f,"instances",{});var E=(t=>(t.META="meta",t.ElementUI="element-ui",t.ElementPlus="element-plus",t.UI="ui",t.BLOCK="block",t.PAGE="page",t.CUSTOM="custom",t))(E||{});const K=class extends f{constructor(e,n){super(e,p(p({},K.defaults),n));l(this,"modelName","Tag");const{name:s}=this.config;this.config.name=s||`model_${this.id}`}dispose(){const e=this.get("props");for(let o of e)o.dispose();const n=this.get("slots");for(let o of n)o.dispose();const s=this.get("events");for(let o of s)o.dispose();const r=this.get("directives");for(let o of r)o.dispose();super.dispose()}append(e,n="default"){const{slots:s}=this.config,r=s.find(o=>o===n||o.config.name===n);r?r.add("children",e):console.error(`slot: ${n} not exist`)}unappend(e,n="default"){const{slots:s}=this.config,r=s.find(o=>o===n||o.config.name===n);r?r.remove("children",e):console.error(`slot: ${n} not exist`)}};let v=K;l(v,"defaults",{type:"div",props:[],events:[],directives:[],slots:[],style:{},classes:[],text:"",origin:"meta",file:"",visible:!0});var P=(t=>(t.DEFAULT="default",t.MODEL="model",t.SYNC="sync",t))(P||{}),x=(t=>(t.DEFAULT="default",t.SLOT="slot",t.DATA_SOURCE="data",t))(x||{}),Q=(t=>(t.STRING="string",t.NUMBER="number",t.BOOLEAN="boolean",t.OBJECT="object",t.ARRAY="array",t.FUNCTION="function",t.UNDEFINED="undefined",t))(Q||{});const Y=class extends f{constructor(e){const{type:n,value:s}=e;n||(e.type=Array.isArray(s)?"array":typeof s);super(e,Y.defaults);l(this,"modelName","Property")}};let w=Y;l(w,"defaults",{binding:{type:"default",source:"default",name:"",code:null}});const X=class extends f{constructor(e){super(e,X.defaults);l(this,"modelName","Slot")}dispose(){const{children:e}=this.config;for(let n of e)n.dispose();super.dispose()}};let N=X;l(N,"defaults",{name:"default",params:[],children:[]});var z=(t=>(t.STOP="stop",t.PREVENT="prevent",t.CAPTURE="capture",t.SELF="self",t.ONCE="once",t.PASSIVE="passive",t))(z||{});const Z=class extends f{constructor(e){super(e,Z.defaults);l(this,"modelName","Event")}};let C=Z;l(C,"defaults",{type:"",handler:"",params:[],modifiers:"",code:null});const ee=class extends f{constructor(e){super(e,ee.defaults);l(this,"modelName","Directive")}};let I=ee;l(I,"defaults",{name:"",value:"",arg:"",modifiers:""});const te=class extends v{constructor(e){super(e,te.defaults);l(this,"modelName","Page")}};let M=te;l(M,"defaults",b(p({},v.defaults),{imports:"",css:"",scoped:!0,dataSources:[],mixin:"",origin:E.PAGE}));var y=(t=>(t.JSON="json",t.CODE="code",t.API="api",t))(y||{});const ne=class extends f{constructor(e){super(e,ne.defaults);l(this,"modelName","DataSource")}};let T=ne;l(T,"defaults",{type:"code",name:"",code:null,api:null});var We=Object.freeze(Object.defineProperty({__proto__:null,Base:f,TagOrigin:E,Tag:v,BindingType:P,BindingSource:x,PropertyDataType:Q,Property:w,Slot:N,EventModifier:z,Event:C,Directive:I,Page:M,DataSourceType:y,DataSource:T},Symbol.toStringTag,{value:"Module"}));function ce(t,e){const n=t.__model_name__,s=We[n];if(s){const r=new s(t);return r.parent=e,r}else console.error(`__model_name__:${n} is not exist`)}function R(t,e=null){if(t.__model_name__){const n=ce(t,e);return Object.entries(n.config).forEach(([s,r])=>{if(Array.isArray(r)){const o=r.filter(i=>i&&i.__model_name__).map(i=>R(i,n));o.length&&n.set(s,o)}else if(r&&r.__model_name__){const o=R(r,n);o&&n.set(s,o)}}),n}}function ae(t){return R(t,null)}function He(t){const e=f.instances;return Object.values(e).filter(t)}function B(t){const{type:e,origin:n,__model_id__:s,slots:r,visible:o}=t,i={type:e,origin:n,__model_id__:s,visible:o,children:[]};if(r.length===0)return i;const a=r.length===1&&r[0].name==="default";return i.children=a?r[0].children.map(u=>B(u)):r.map(u=>({slot:!0,name:u.name,__model_id__:u.__model_id__,children:u.children.map(c=>B(c))})),i}function le(t){return B(t)}function H(t){return G.default.format(t,{parser:"html",bracketSameLine:!1,plugins:[Fe.default]})}function ue(t){return G.default.format(t,{parser:"babel",singleQuote:!0,semi:!0,trailingComma:"none",bracketSpacing:!0,bracketSameLine:!1,plugins:[Je.default]})}function U(t){return G.default.format(t,{parser:"scss",bracketSameLine:!1,plugins:[qe.default]})}function Ue(t,e){for(;t.length<e;)t="0"+t;return t}function h(t,e){var n,s,r;if(e.length===0)return t;for(n=0,r=e.length;n<r;n++)s=e.charCodeAt(n),t=(t<<5)-t+s,t|=0;return t<0?t*-2:t}function ke(t,e,n){return Object.keys(e).sort().reduce(s,t);function s(r,o){return de(r,e[o],o,n)}}function de(t,e,n,s){var r=h(h(h(t,n),Ge(e)),typeof e);if(e===null)return h(r,"null");if(e===void 0)return h(r,"undefined");if(typeof e=="object"||typeof e=="function"){if(s.indexOf(e)!==-1)return h(r,"[Circular]"+n);s.push(e);var o=ke(r,e,s);if(!("valueOf"in e)||typeof e.valueOf!="function")return o;try{return h(o,String(e.valueOf()))}catch(i){return h(o,"[valueOf exception]"+(i.stack||i.message))}}return h(r,e.toString())}function Ge(t){return Object.prototype.toString.call(t)}function Qe(t){return Ue(de(0,t,"",[]).toString(16),8)}var pe=Qe;function fe(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)}).toLowerCase()}function me(t){return!t||typeof t=="string"?t:JSON.stringify(t).replace(/\"/g,"'")}function he(){return pe(fe())}function ge(t){const e=Object.create(null);return new URLSearchParams(t).forEach((s,r)=>{e[r]=s}),e}function _e(t=""){const e=t.indexOf("?"),n=e<=0?"":t.substring(e+1);return ge(n)}async function ye(t){return fetch(t).then(e=>e.json())}async function ve(t){return fetch(t).then(e=>e.text())}const ze=["Page","Tag"];function Ke(t){return t.length===1&&t[0].name==="default"&&t[0].params.length===0}function Ye(t){return t||""}function Xe(t){if(!t)return"";const{name:e,params:n,children:s}=t,r=n.length?`="{${n.join(",")}}"`:"";return`<template v-slot:${e}${r}>
|
|
2
|
+
${be(s)}
|
|
3
|
+
</template>`}function Ze(t){return Ke(t)?be(t[0].children):t.map(e=>Xe(e))}function et(t){const{name:e,modifiers:n}=t,s=t.arg?`:${t.arg}`:"",r=t.value?`="${t.value}"`:"";return`v-${e}${s}${n}${r}`}function tt(t){return t.map(e=>et(e)).join(" ")}function nt(t){return t?`data-model-id="${t}"`:""}function st(t,e,n,s){const o=s&&Object.keys(s).length>0?n||`model_${e}`:"",i=o?[o,...t]:t;return i.length?`class="${i.join(" ")}"`:""}function rt(t){const n=t.filter(c=>c.type!=="function"&&c.binding.type===P.DEFAULT&&c.binding.source===x.DEFAULT).map(c=>`${c.type==="string"?"":":"}${c.name}="${me(c.value)}"`),r=t.filter(c=>c.type==="function"&&c.binding.type===P.DEFAULT).map(c=>`:${c.name}="${c.binding.name||c.value}"`),i=t.filter(c=>c.binding.source===x.SLOT&&!!c.binding.name).map(c=>`:${c.name}="${c.binding.name}"`),u=t.filter(c=>c.binding.source===x.DATA_SOURCE&&!!c.binding.name).map(c=>`:${c.name}="${c.binding.name}"`);return[...n,...i,...r,...u].join(" ")}function ot(t){return t.filter(e=>e.type&&e.handler).map(e=>{const n=e.params.length?`(${e.params.join(",")})`:"";return`@${e.type}${e.modifiers}="${e.handler}${n}"`}).join(" ")}function Se(t){if(ze.includes(t.__model_name__)&&t.visible){const{type:e,text:n,slots:s,directives:r,name:o,classes:i,style:a,props:u,events:c}=t;return`<${e}
|
|
4
|
+
${nt(t.__model_id__)}
|
|
5
|
+
${tt(r)}
|
|
6
|
+
${st(i,t.__model_id__,o,a)}
|
|
7
|
+
${rt(u)}
|
|
8
|
+
${ot(c)}
|
|
9
|
+
>
|
|
10
|
+
${Ye(n)}
|
|
11
|
+
${Ze(s)}
|
|
12
|
+
</${e}>`}return""}function be(t=[]){return t.map(e=>Se(e)).join(`
|
|
13
|
+
`)}function it(t){return Se(t)}function ct(t){if(!t.length)return"{}";const e=t.filter(s=>s.type===y.JSON).map(s=>`${s.name}: ${s.code}`).join(","),n=t.filter(s=>s.type!==y.JSON).map(s=>y.CODE===s.type?`${s.name}: ${s.code}`:y.API===s.type?`${s.name}: createApi({
|
|
14
|
+
url:'${s.api.url}',
|
|
15
|
+
method:'${s.api.method}'
|
|
16
|
+
})`:"").join(",");return`{
|
|
17
|
+
data() {
|
|
18
|
+
return {
|
|
19
|
+
${e}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
methods: {
|
|
23
|
+
${n}
|
|
24
|
+
}
|
|
25
|
+
}`}function at(t){const e=[];return O(t,n=>{n.__model_name__==="Event"&&e.push(n)}),e.filter(n=>n.code&&n.handler).map(n=>`${n.handler}${n.code}`).join(",")}function lt(t){const e={};O(t,(r,o)=>{if([E.ElementPlus,E.ElementUI].includes(r.origin)&&r.visible){const i=e[r.origin];i?i.add(r.type):e[r.origin]=new Set([r.type])}});let n="",s=[];return Object.keys(e).forEach(r=>{const o=Array.from(e[r]);n+=`import {${o.join(",")}} from '${r}';`,s=s.concat(o)}),{imports:n,components:s}}function ut(t){const{imports:e,components:n}=lt(t);return`
|
|
26
|
+
${e}
|
|
27
|
+
${t.imports||""}
|
|
28
|
+
const __mixin = ${t.mixin||"{}"}
|
|
29
|
+
const __dataSources = ${ct(t.dataSources)}
|
|
30
|
+
export default {
|
|
31
|
+
components: {${n.join(",")}},
|
|
32
|
+
mixins:[__dataSources, __mixin],
|
|
33
|
+
data() {
|
|
34
|
+
return {}
|
|
35
|
+
},
|
|
36
|
+
methods: {
|
|
37
|
+
${at(t)}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`}function dt(t){const e={};O(t,(s,r)=>{if(s.style&&Object.keys(s.style).length>0){const o=s.name||`model_${s.id}`;e[`.${o}`]=s.style}});let n="";return Object.keys(e).forEach(s=>{const r=e[s]||{};n+=`
|
|
41
|
+
${s} {`,Object.entries(r).forEach(([o,i])=>{n+=`${o}: ${i};`}),n+=`}
|
|
42
|
+
`}),n}function pt(t){return t?"scoped":""}var $=(t=>(t.VUE2="VUE2",t.VUE3="VUE3",t.VUE3_TS="VUE3_TS",t.UNI_APP="UNI_APP",t))($||{});function $e(t="VUE3",e){const n=it(e),s=ut(e),r=dt(e);return H(`
|
|
43
|
+
<template>
|
|
44
|
+
${H(n)}
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script>
|
|
48
|
+
${ue(s)}
|
|
49
|
+
<\/script>
|
|
50
|
+
|
|
51
|
+
<style lang="css" ${pt(e.scoped)}>
|
|
52
|
+
${U(e==null?void 0:e.css)}
|
|
53
|
+
${U(r)}
|
|
54
|
+
</style>
|
|
55
|
+
`)}async function xe(){return await Promise.resolve().then(function(){return k(require("systemjs"))}).then(async t=>window.System)}async function Oe(){return await Promise.resolve().then(function(){return k(require("systemjs-babel"))})}const ft=/\\/g;function ie(t,e){if(t.indexOf("\\")!==-1&&(t=t.replace(ft,"/")),t[0]==="/"&&t[1]==="/")return e.slice(0,e.indexOf(":")+1)+t;if(t[0]==="."&&(t[1]==="/"||t[1]==="."&&(t[2]==="/"||t.length===2&&(t+="/"))||t.length===1&&(t+="/"))||t[0]==="/"){const n=e.slice(0,e.indexOf(":")+1);let s;if(e[n.length+1]==="/"?n!=="file:"?(s=e.slice(n.length+2),s=s.slice(s.indexOf("/")+1)):s=e.slice(8):s=e.slice(n.length+(e[n.length]==="/")),t[0]==="/")return e.slice(0,e.length-s.length-1)+t;const r=s.slice(0,s.lastIndexOf("/")+1)+t,o=[];let i=-1;for(let a=0;a<r.length;a++)i!==-1?r[a]==="/"&&(o.push(r.slice(i,a+1)),i=-1):r[a]==="."?r[a+1]==="."&&(r[a+2]==="/"||a+2===r.length)?(o.pop(),a+=2):r[a+1]==="/"||a+1===r.length?a+=1:i=a:i=a;return i!==-1&&o.push(r.slice(i)),e.slice(0,e.length-s.length)+o.join("")}}function mt(t,e){return ie(t,e)||(t.indexOf(":")!==-1?t:ie("./"+t,e))}function Ee(t,e){var se;const n=pe(t+e),s="data-v-"+n,o=A.parse(e,{sourceMap:!1}).descriptor,i=o.styles.some(S=>S.scoped),a=A.compileTemplate({id:n,filename:t,source:((se=o.template)==null?void 0:se.content)||"",scoped:i,compilerOptions:{scopeId:i?s:void 0}}),u=A.compileScript(o,{id:n,templateOptions:{scoped:i,compilerOptions:{scopeId:i?s:void 0}}}),c=o.styles,d=[];if(c.length)for(let S=0;S<c.length;S++){const j=c[S];d.push(A.compileStyle({source:j.content,id:s,filename:t,scoped:j.scoped}).code)}let m=d.join(`
|
|
56
|
+
`);const _=t+".css";m=m.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g,function(S,j,Pe,we){return"url("+j+mt(Pe||we,_)+j+")"});const L="_sfc_render",g="_sfc_main",je=a.code.replace(/\nexport (function|const) (render|ssrRender)/,`
|
|
57
|
+
$1 _sfc_$2`),F=[A.rewriteDefault(u.content,g),je,g+".render="+L,"export default "+g];i&&F.push(g+".__scopeId = "+JSON.stringify(s)),F.push(g+".__file = "+JSON.stringify(t));const Ae=F.join(`
|
|
58
|
+
`);return{style:m,script:Ae}}class ht{constructor(e,n){l(this,"model");this.schema=e,this.contentWindow=n,this.model=ae(e)}getSchema(){return this.model.toSchema()}getModel(e){return f.instances[e]}getOutline(){const e=this.getSchema();return[le(e)]}getHoverModel(e=[]){var m,_;const n=e.find(L=>{var g;return(g=L.dataset)==null?void 0:g.modelId});if(!n)return null;const s=(m=n.dataset)==null?void 0:m.modelId,r=this.getModel(s),o=((_=r.parent)==null?void 0:_.get("children"))||[],{width:i,height:a,left:u,top:c}=n.getBoundingClientRect(),d=r.modelName!=="Page";return{el:n,id:s,model:r,props:{id:s,width:i,height:a,left:u,top:c,opacity:1,type:r.get("type"),removeable:d,first:!d||d&&o[0]===r,last:!d||d&&o[o.length-1]===r,label:!0}}}getSelectedById(e){const{contentWindow:n}=this;if(!n)return;const s=n.document.querySelector(`[data-model-id="${e}"]`);if(!!s)return this.getHoverModel([s])}getSelectedModel(e=[]){return this.getHoverModel(e)}getDropModel(e=[]){return this.getHoverModel(e)}async appendModel(e={},n,s="default"){const{path:r,origin:o}=e,i=await ye(r),a=(i.props||[]).map(d=>new w({name:d.name,type:d.type,value:d.value})),u=(i.slots||[]).map(d=>new N(p({},d))),c=new v({type:i.tag,props:a,slots:u,origin:o,text:i.text||"",style:i.style||{},file:r});n.append(c,s)}removeModel(e){const n=e.parent;n&&(n.remove("children",e),e.dispose())}moveNext(e){const n=e.parent;if(!n)return;const s=n.get("children"),r=s.findIndex(i=>i===e),o=s[r+1];!o||(s[r]=o,s[r+1]=e)}movePrev(e){const n=e.parent;if(!n)return;const s=n.get("children"),r=s.findIndex(i=>i===e),o=s[r-1];!o||(s[r]=o,s[r-1]=e)}updateProps(e,n={}){this.getModel(e).get("props").forEach(o=>{const i=o.get("name"),a=n[i];o.set("value",a)})}setVisible(e,n){this.getModel(e).set("visible",n)}}const q={};class gt{constructor(e){l(this,"config");l(this,"system");l(this,"libs",{});l(this,"scriptEl",null);l(this,"app",null);l(this,"helper",null);this.config=p({imports:{},loader:"/engine.js",vue:"/libs/vue3/vue.runtime.esm-browser.prod.js",dslType:$.VUE3},e),this.init()}async init(){this.setImportMap(),await this.initSystem(),await this.prepareEnv();const{onReady:e}=this.config;e&&e(this)}async initSystem(){let e=window==null?void 0:window.System;if(e)return this.system=e,e;e=await xe();const n=e.constructor.prototype;n.shouldFetch=function(o){return!0};const s=n.fetch,{loader:r}=this.config;return n.fetch=(o,i)=>o.includes(r||"")?this.intercepter(o,i):s(o,i),this.system=e,await Oe()}async intercepter(e,n){const{type:s,file:r,id:o}=_e(e)||{};if(s==="lib")if(r.endsWith(".css")){const i=await ve(decodeURIComponent(r));return this.adoptedStyleSheets(r,i),new Response(null)}else{const i=`
|
|
59
|
+
export * from '${decodeURIComponent(r)}';
|
|
60
|
+
`;return Promise.resolve(new Response(new Blob([i],{type:"application/javascript"})))}if(s==="schema"){const i=q[o],a=$e($.VUE3,i);delete q[o];const{script:u,style:c}=Ee(i.name,a);return this.adoptedStyleSheets(o,c),Promise.resolve(new Response(new Blob([u],{type:"application/javascript"})))}return fetch(e,n)}async prepareEnv(){const{system:e,config:n,libs:s}=this,{imports:r,loader:o,vue:i}=n,a=`${o}?type=lib&name=vue&file=${encodeURIComponent(i)}`;await e.import(a).then(c=>{s.Vue=c,e.set("app:vue",c)}),e.prepareImport(!0);const u=Object.entries(r||{});for(let[c,d]of u){const m=`${o}?type=lib&name=${c}&file=${encodeURIComponent(d)}`;await e.import(m).then(_=>{s[c]=_,e.set(`app:${c}`,_)})}e.prepareImport(!0)}setImportMap(){const{scriptEl:e,config:n}=this,{imports:s,vue:r}=n;let o=e;o||(this.scriptEl=o=document.createElement("script"),o.type="systemjs-importmap");const i={vue:"app:vue"};Object.keys(s||{}).forEach(a=>{i[a]=`app:${a}`}),o.innerHTML=JSON.stringify({imports:i}),document.body.appendChild(o)}adoptedStyleSheets(e,n){const{contentWindow:s}=this.config;if(!s)return;const r=new s.CSSStyleSheet;r.id=e,r.replaceSync(n);const o=s.document,i=Array.from(o.adoptedStyleSheets).filter(a=>a.id!==e);o.adoptedStyleSheets=[...i,r]}async load(e){const{config:n,system:s}=this,{loader:r,dslType:o,contentWindow:i,onLoad:a}=n,u=e.__model_id__;q[u]=e,this.helper=new ht(e,i);const c=`${r}?type=schema&dsl=${o}&id=${u}&t=${Date.now()}`;return await s.import(c).then(d=>{const m=this.createApp(d.default);return a&&a(m),m}).catch(d=>{console.warn(d)})}async reload(){var n;const e=(n=this.helper)==null?void 0:n.getSchema();return await this.load(e)}createApp(e){var r;const{dslType:n,contentWindow:s}=this.config;if(n===$.VUE3){(r=this.app)==null||r.unmount();const o=this.libs.Vue.createApp(e);o.mount(s.document.body),this.app=o}return this.app}dispose(){const{scriptEl:e,app:n,config:s}=this,{contentWindow:r,dslType:o}=s;if(e&&e.parentNode&&e.parentNode.removeChild(e),r){const i=r.document;i.adoptedStyleSheets=[]}n&&o===$.VUE3&&(n.unmount(),this.app=null)}}exports.Base=f;exports.BindingSource=x;exports.BindingType=P;exports.DSLType=$;exports.DataSource=T;exports.DataSourceType=y;exports.Directive=I;exports.Engine=gt;exports.Event=C;exports.EventModifier=z;exports.Page=M;exports.Property=w;exports.PropertyDataType=Q;exports.Slot=N;exports.Tag=v;exports.TagOrigin=E;exports.cleanJSON=me;exports.compiler=Ee;exports.craeteOutline=B;exports.createModel=ce;exports.createModelTree=R;exports.cssFormat=U;exports.fetchCSS=ve;exports.fetchJSON=ye;exports.findModel=He;exports.getQuery=_e;exports.hashId=he;exports.htmlFormat=H;exports.loadSystemJs=xe;exports.loadSystemJsBabel=Oe;exports.modelTraverse=W;exports.schemaTraverse=O;exports.scriptFormat=ue;exports.toDSL=$e;exports.toModel=ae;exports.toOutline=le;exports.urlParser=ge;exports.uuid=fe;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vtj/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "天匠(Tj)可视化低代码平台核心库",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "chenhuachun",
|
|
7
|
+
"email": "samchen08@163.com"
|
|
8
|
+
},
|
|
9
|
+
"main": "index.cjs.js",
|
|
10
|
+
"module": "index.es.js",
|
|
11
|
+
"types": "types.d.ts",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"hash-sum": "^2.0.0",
|
|
14
|
+
"lodash-es": "^4.17.21",
|
|
15
|
+
"prettier": "^2.6.1",
|
|
16
|
+
"systemjs": "^6.12.1",
|
|
17
|
+
"systemjs-babel": "^0.3.1"
|
|
18
|
+
},
|
|
19
|
+
"files": ["index.js", "types.d.ts"],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://gitee.com/vtj/core.git"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "http://newgateway.gitee.io/my/",
|
|
25
|
+
"license": "MIT"
|
|
26
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
declare module '@vtj/core' {
|
|
2
|
+
// Base >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
3
|
+
export interface BaseConfig {
|
|
4
|
+
__model_id__?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class Base {
|
|
8
|
+
id: string;
|
|
9
|
+
config: any;
|
|
10
|
+
disposed: boolean;
|
|
11
|
+
parent: Base | null;
|
|
12
|
+
modelName: string;
|
|
13
|
+
static instances: Record<string, Base>;
|
|
14
|
+
constructor(config?: BaseConfig, defaults?: BaseConfig);
|
|
15
|
+
get<T>(key: string): T;
|
|
16
|
+
set(key: string, value: any): void;
|
|
17
|
+
add<T>(key: string, item: any, finder?: (p: any) => boolean): void;
|
|
18
|
+
remove<T>(key: string, item: any, finder?: (p: any) => boolean): void;
|
|
19
|
+
clear(key: string): void;
|
|
20
|
+
dispose(): void;
|
|
21
|
+
toSchema(): object;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Property >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
25
|
+
export enum BindingType {
|
|
26
|
+
// 静态模板
|
|
27
|
+
DEFAULT = 'default',
|
|
28
|
+
// 双向绑定
|
|
29
|
+
MODEL = 'model',
|
|
30
|
+
// 同步
|
|
31
|
+
SYNC = 'sync'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export enum BindingSource {
|
|
35
|
+
DEFAULT = 'default', // 默认
|
|
36
|
+
SLOT = 'slot', // 插槽提供
|
|
37
|
+
DATA_SOURCE = 'data'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export enum PropertyDataType {
|
|
41
|
+
STRING = 'string',
|
|
42
|
+
NUMBER = 'number',
|
|
43
|
+
BOOLEAN = 'boolean',
|
|
44
|
+
OBJECT = 'object',
|
|
45
|
+
ARRAY = 'array',
|
|
46
|
+
FUNCTION = 'function',
|
|
47
|
+
UNDEFINED = 'undefined'
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface Binding {
|
|
51
|
+
type?: string;
|
|
52
|
+
source?: string;
|
|
53
|
+
name?: string; // source 为 slot或data时,需要设置名称
|
|
54
|
+
code?: string | null; // 手动调用数据源代码
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface PropertyConfig extends BaseConfig {
|
|
58
|
+
name?: string;
|
|
59
|
+
value?: any;
|
|
60
|
+
type?: PropertyDataType; // 数据类型
|
|
61
|
+
binding?: Binding;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class Property extends Base {
|
|
65
|
+
static defaults: PropertyConfig;
|
|
66
|
+
modelName: string;
|
|
67
|
+
|
|
68
|
+
constructor(config: PropertyConfig);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Slot >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
72
|
+
export interface SlotConfig extends BaseConfig {
|
|
73
|
+
name?: string;
|
|
74
|
+
params?: string[];
|
|
75
|
+
children?: any;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export class Slot extends Base {
|
|
79
|
+
static defaults: SlotConfig;
|
|
80
|
+
modelName: string;
|
|
81
|
+
|
|
82
|
+
constructor(config?: SlotConfig);
|
|
83
|
+
|
|
84
|
+
dispose(): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Event >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
|
|
88
|
+
export enum EventModifier {
|
|
89
|
+
STOP = 'stop',
|
|
90
|
+
PREVENT = 'prevent',
|
|
91
|
+
CAPTURE = 'capture',
|
|
92
|
+
SELF = 'self',
|
|
93
|
+
ONCE = 'once',
|
|
94
|
+
PASSIVE = 'passive'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface EventConfig extends BaseConfig {
|
|
98
|
+
// 事件类型
|
|
99
|
+
type: string | null;
|
|
100
|
+
// 处理句柄
|
|
101
|
+
handler: string | null;
|
|
102
|
+
// 参数
|
|
103
|
+
params?: EventModifier[];
|
|
104
|
+
// 修饰符
|
|
105
|
+
modifiers?: string;
|
|
106
|
+
// 自定义处理句柄代码
|
|
107
|
+
code?: string | null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class Event extends Base {
|
|
111
|
+
static defaults: EventConfig;
|
|
112
|
+
modelName: string;
|
|
113
|
+
|
|
114
|
+
constructor(config: EventConfig);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Tag >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
|
|
118
|
+
export interface TagConfig extends BaseConfig {
|
|
119
|
+
type: string; // 组件名称
|
|
120
|
+
name?: string; // 组件实例名称
|
|
121
|
+
props?: Property[]; // 组件属性
|
|
122
|
+
events?: Event[]; // 事件
|
|
123
|
+
directives?: object[]; // 指令
|
|
124
|
+
slots?: Slot[]; // 插槽
|
|
125
|
+
style?: Record<string, string | number>;
|
|
126
|
+
classes?: string[];
|
|
127
|
+
text?: string; //内嵌文本
|
|
128
|
+
origin?: TagOrigin; // 组件来源
|
|
129
|
+
file?: string;
|
|
130
|
+
visible?: boolean;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export enum TagOrigin {
|
|
134
|
+
META = 'meta',
|
|
135
|
+
ElementUI = 'element-ui',
|
|
136
|
+
ElementPlus = 'element-plus',
|
|
137
|
+
UI = 'ui',
|
|
138
|
+
BLOCK = 'block',
|
|
139
|
+
PAGE = 'page',
|
|
140
|
+
CUSTOM = 'custom'
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export class Tag extends Base {
|
|
144
|
+
static defaults: TagConfig;
|
|
145
|
+
modelName: string;
|
|
146
|
+
constructor(config: TagConfig, defaults?: TagConfig);
|
|
147
|
+
dispose(): void;
|
|
148
|
+
append(model: Tag, place: string | Slot): void;
|
|
149
|
+
unappend(model: Tag, place: string | Slot): void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Directive >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
153
|
+
export interface DirectiveConfig extends BaseConfig {
|
|
154
|
+
// 指令类型
|
|
155
|
+
name: string;
|
|
156
|
+
// 处理句柄
|
|
157
|
+
value?: string | null;
|
|
158
|
+
// 参数
|
|
159
|
+
arg?: string;
|
|
160
|
+
// 修饰符
|
|
161
|
+
modifiers?: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export class Directive extends Base {
|
|
165
|
+
static defaults: DirectiveConfig;
|
|
166
|
+
modelName: string;
|
|
167
|
+
constructor(config: DirectiveConfig);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// DataSource >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
171
|
+
export enum DataSourceType {
|
|
172
|
+
JSON = 'json',
|
|
173
|
+
CODE = 'code',
|
|
174
|
+
API = 'api'
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface DataSourceApi {
|
|
178
|
+
url: string;
|
|
179
|
+
method: string;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface DataSourceConfig extends BaseConfig {
|
|
183
|
+
// 数据源类型
|
|
184
|
+
type: DataSourceType;
|
|
185
|
+
// 数据源名称
|
|
186
|
+
name: string;
|
|
187
|
+
code?: string | null;
|
|
188
|
+
api?: DataSourceApi | null;
|
|
189
|
+
}
|
|
190
|
+
export class DataSource extends Base {
|
|
191
|
+
static defaults: DataSourceConfig;
|
|
192
|
+
modelName: string;
|
|
193
|
+
constructor(config: DataSourceConfig);
|
|
194
|
+
}
|
|
195
|
+
// Page >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
196
|
+
export interface PageConfig extends TagConfig {
|
|
197
|
+
imports?: string;
|
|
198
|
+
css?: string;
|
|
199
|
+
scoped?: boolean;
|
|
200
|
+
dataSources?: object[];
|
|
201
|
+
mixin?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export class Page extends Tag {
|
|
205
|
+
static defaults: PageConfig;
|
|
206
|
+
modelName: string;
|
|
207
|
+
constructor(config: PageConfig);
|
|
208
|
+
setText(text: string): void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// engine >>>>>>>>>>>>>>>>>>>>>>>>
|
|
212
|
+
|
|
213
|
+
export function compiler(
|
|
214
|
+
filename: string,
|
|
215
|
+
source: string
|
|
216
|
+
): { style: string; script: string };
|
|
217
|
+
|
|
218
|
+
export function loadSystemJs(): Promise<any>;
|
|
219
|
+
export function loadSystemJsBabel(): Promise<any>;
|
|
220
|
+
export function getQuery(url: string): Record<string, string>;
|
|
221
|
+
export function toDSL(dsl: DSLType, schema: any): string;
|
|
222
|
+
|
|
223
|
+
export enum DSLType {
|
|
224
|
+
VUE2 = 'VUE2',
|
|
225
|
+
VUE3 = 'VUE3',
|
|
226
|
+
VUE3_TS = 'VUE3_TS',
|
|
227
|
+
UNI_APP = 'UNI_APP'
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export interface EngineConfig {
|
|
231
|
+
imports?: Record<string, string>;
|
|
232
|
+
loader?: string;
|
|
233
|
+
onReady?: (engine: Engine) => void;
|
|
234
|
+
onLoad?: (app: any) => void;
|
|
235
|
+
vue?: string;
|
|
236
|
+
dslType?: DSLType;
|
|
237
|
+
contentWindow?: any;
|
|
238
|
+
}
|
|
239
|
+
export class Engine {
|
|
240
|
+
config: EngineConfig;
|
|
241
|
+
system: any;
|
|
242
|
+
libs: Record<string, any>;
|
|
243
|
+
scriptEl: HTMLScriptElement | null;
|
|
244
|
+
app: any;
|
|
245
|
+
helper: Helper | null;
|
|
246
|
+
constructor(config: EngineConfig);
|
|
247
|
+
load(schema: any): Promise<any>;
|
|
248
|
+
reload(): Promise<any>;
|
|
249
|
+
dispose(): void;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export class Helper {
|
|
253
|
+
model: any;
|
|
254
|
+
constructor(schema: any, contentWindow: any);
|
|
255
|
+
getModel(id: string): Base;
|
|
256
|
+
getSchema(): any;
|
|
257
|
+
getOutline(): any;
|
|
258
|
+
getHoverModel(path: any[]): any;
|
|
259
|
+
getSelectedModel(path: any[]): any;
|
|
260
|
+
getDropModel(path: any[]): any;
|
|
261
|
+
appendModel(
|
|
262
|
+
defineConfig: any,
|
|
263
|
+
target: Base,
|
|
264
|
+
slotName?: string
|
|
265
|
+
): Promise<any>;
|
|
266
|
+
removeModel(model: any): void;
|
|
267
|
+
moveNext(model: any): void;
|
|
268
|
+
movePrev(model: any): void;
|
|
269
|
+
updateProps(id: string, model: any): void;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// utils >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
273
|
+
export function fetchJSON(url: string): Promise<any>;
|
|
274
|
+
export function fetchCSS(url: string): Promise<any>;
|
|
275
|
+
}
|