@vtj/core 0.1.1 → 0.1.2
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/index.cjs.js +10 -10
- package/package.json +21 -2
package/index.cjs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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"),
|
|
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"),Ve=require("prettier/parser-html"),Be=require("prettier/parser-babel"),Le=require("prettier/parser-postcss"),Fe=require("vue/compiler-sfc");function L(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=L(Re),De=L(Ve),Je=L(Be),qe=L(Le),P=k(Fe);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 j(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=>{j(o,e,t)}):j(r,e,t)})}}const B=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(),B.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 B.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=B;l(f,"instances",{});var A=(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))(A||{});const K=class extends f{constructor(n,s){super(n,p(p({},K.defaults),s));l(this,"modelName","Tag");const{name:r}=this.config;this.config.name=r||`model_${this.id}`}dispose(){const n=this.get("props");for(let i of n)i.dispose();const s=this.get("slots");for(let i of s)i.dispose();const r=this.get("events");for(let i of r)i.dispose();const o=this.get("directives");for(let i of o)i.dispose();super.dispose()}append(n,s="default"){const{slots:r}=this.config,o=r.find(i=>i===s||i.config.name===s);o?o.add("children",n):console.error(`slot: ${s} not exist`)}unappend(n,s="default"){const{slots:r}=this.config,o=r.find(i=>i===s||i.config.name===s);o?o.remove("children",n):console.error(`slot: ${s} not exist`)}};let _=K;l(_,"defaults",{type:"div",props:[],events:[],directives:[],slots:[],style:{},classes:[],text:"",origin:"meta",file:"",visible:!0});var T=(t=>(t.DEFAULT="default",t.MODEL="model",t.SYNC="sync",t))(T||{}),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(n){const{type:s,value:r}=n;s||(n.type=Array.isArray(r)?"array":typeof r);super(n,Y.defaults);l(this,"modelName","Property")}};let O=Y;l(O,"defaults",{binding:{type:"default",source:"default",name:"",code:null}});const X=class extends f{constructor(n){super(n,X.defaults);l(this,"modelName","Slot")}dispose(){const{children:n}=this.config;for(let s of n)s.dispose();super.dispose()}};let E=X;l(E,"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(n){super(n,Z.defaults);l(this,"modelName","Event")}};let N=Z;l(N,"defaults",{type:"",handler:"",params:[],modifiers:"",code:null});const ee=class extends f{constructor(n){super(n,ee.defaults);l(this,"modelName","Directive")}};let C=ee;l(C,"defaults",{name:"",value:"",arg:"",modifiers:""});const te=class extends _{constructor(n){super(n,te.defaults);l(this,"modelName","Page")}};let I=te;l(I,"defaults",b(p({},_.defaults),{imports:"",css:"",scoped:!0,dataSources:[],mixin:"",origin:A.PAGE}));var v=(t=>(t.JSON="json",t.CODE="code",t.API="api",t))(v||{});const ne=class extends f{constructor(n){super(n,ne.defaults);l(this,"modelName","DataSource")}};let M=ne;l(M,"defaults",{type:"code",name:"",code:null,api:null});var We=Object.freeze(Object.defineProperty({__proto__:null,Base:f,TagOrigin:A,Tag:_,BindingType:T,BindingSource:x,PropertyDataType:Q,Property:O,Slot:E,EventModifier:z,Event:N,Directive:C,Page:I,DataSourceType:v,DataSource:M},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 V(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=>V(u)):r.map(u=>({slot:!0,name:u.name,__model_id__:u.__model_id__,children:u.children.map(c=>V(c))})),i}function le(t){return V(t)}function H(t){return G.default.format(t,{parser:"html",bracketSameLine:!1,plugins:[De.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
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===
|
|
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===T.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===T.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
4
|
${nt(t.__model_id__)}
|
|
5
5
|
${tt(r)}
|
|
6
6
|
${st(i,t.__model_id__,o,a)}
|
|
@@ -10,7 +10,7 @@ ${ot(c)}
|
|
|
10
10
|
${Ye(n)}
|
|
11
11
|
${Ze(s)}
|
|
12
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===
|
|
13
|
+
`)}function it(t){return Se(t)}function ct(t){if(!t.length)return"{}";const e=t.filter(s=>s.type===v.JSON).map(s=>`${s.name}: ${s.code}`).join(","),n=t.filter(s=>s.type!==v.JSON).map(s=>v.CODE===s.type?`${s.name}: ${s.code}`:v.API===s.type?`${s.name}: createApi({
|
|
14
14
|
url:'${s.api.url}',
|
|
15
15
|
method:'${s.api.method}'
|
|
16
16
|
})`:"").join(",");return`{
|
|
@@ -22,7 +22,7 @@ ${Ze(s)}
|
|
|
22
22
|
methods: {
|
|
23
23
|
${n}
|
|
24
24
|
}
|
|
25
|
-
}`}function at(t){const e=[];return
|
|
25
|
+
}`}function at(t){const e=[];return j(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={};j(t,(r,o)=>{if([A.ElementPlus,A.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
26
|
${e}
|
|
27
27
|
${t.imports||""}
|
|
28
28
|
const __mixin = ${t.mixin||"{}"}
|
|
@@ -37,7 +37,7 @@ methods: {
|
|
|
37
37
|
${at(t)}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
`}function dt(t){const e={};
|
|
40
|
+
`}function dt(t){const e={};j(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
41
|
${s} {`,Object.entries(r).forEach(([o,i])=>{n+=`${o}: ${i};`}),n+=`}
|
|
42
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
43
|
<template>
|
|
@@ -52,9 +52,9 @@ ${ue(s)}
|
|
|
52
52
|
${U(e==null?void 0:e.css)}
|
|
53
53
|
${U(r)}
|
|
54
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=
|
|
56
|
-
`);const
|
|
57
|
-
$1 _sfc_$2`),
|
|
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,
|
|
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=P.parse(e,{sourceMap:!1}).descriptor,i=o.styles.some(S=>S.scoped),a=P.compileTemplate({id:n,filename:t,source:((se=o.template)==null?void 0:se.content)||"",scoped:i,compilerOptions:{scopeId:i?s:void 0}}),u=P.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 w=c[S];d.push(P.compileStyle({source:w.content,id:s,filename:t,scoped:w.scoped}).code)}let m=d.join(`
|
|
56
|
+
`);const y=t+".css";m=m.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g,function(S,w,we,Pe){return"url("+w+mt(we||Pe,y)+w+")"});const F="_sfc_render",g="_sfc_main",je=a.code.replace(/\nexport (function|const) (render|ssrRender)/,`
|
|
57
|
+
$1 _sfc_$2`),D=[P.rewriteDefault(u.content,g),je,g+".render="+F,"export default "+g];i&&D.push(g+".__scopeId = "+JSON.stringify(s)),D.push(g+".__file = "+JSON.stringify(t));const Ae=D.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,y;const n=e.find(F=>{var g;return(g=F.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=((y=r.parent)==null?void 0:y.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 O({name:d.name,type:d.type,value:d.value})),u=(i.slots||[]).map(d=>new E(p({},d))),c=new _({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
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(
|
|
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(y=>{s[c]=y,e.set(`app:${c}`,y)})}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=T;exports.DSLType=$;exports.DataSource=M;exports.DataSourceType=v;exports.Directive=C;exports.Engine=gt;exports.Event=N;exports.EventModifier=z;exports.Page=I;exports.Property=O;exports.PropertyDataType=Q;exports.Slot=E;exports.Tag=_;exports.TagOrigin=A;exports.cleanJSON=me;exports.compiler=Ee;exports.craeteOutline=V;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=j;exports.scriptFormat=ue;exports.toDSL=$e;exports.toModel=ae;exports.toOutline=le;exports.urlParser=ge;exports.uuid=fe;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "天匠(Tj)可视化低代码平台核心库",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "chenhuachun",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
"main": "index.cjs.js",
|
|
10
10
|
"module": "index.es.js",
|
|
11
11
|
"types": "types.d.ts",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "vue-tsc --noEmit && vite build && node build.mjs"
|
|
14
|
+
},
|
|
12
15
|
"dependencies": {
|
|
13
16
|
"hash-sum": "^2.0.0",
|
|
14
17
|
"lodash-es": "^4.17.21",
|
|
@@ -16,7 +19,23 @@
|
|
|
16
19
|
"systemjs": "^6.12.1",
|
|
17
20
|
"systemjs-babel": "^0.3.1"
|
|
18
21
|
},
|
|
19
|
-
"
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/types": "^7.17.0",
|
|
24
|
+
"@types/lodash-es": "^4.17.6",
|
|
25
|
+
"@types/node": "^17.0.25",
|
|
26
|
+
"@types/prettier": "^2.6.0",
|
|
27
|
+
"@vitejs/plugin-vue": "^2.3.1",
|
|
28
|
+
"type-fest": "^2.12.2",
|
|
29
|
+
"typescript": "^4.6.3",
|
|
30
|
+
"vite": "^2.9.5",
|
|
31
|
+
"vue-tsc": "^0.34.10",
|
|
32
|
+
"vue": "3.2.33"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"index.cjs.js",
|
|
36
|
+
"index.es.js",
|
|
37
|
+
"types.d.ts"
|
|
38
|
+
],
|
|
20
39
|
"repository": {
|
|
21
40
|
"type": "git",
|
|
22
41
|
"url": "https://gitee.com/vtj/core.git"
|