@vtj/coder 0.7.34 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +31 -28
- package/dist/index.mjs +259 -214
- package/package.json +5 -5
- package/types/collecter.d.ts +5 -1
- package/types/parser/defines.d.ts +4 -0
- package/types/parser/index.d.ts +3 -0
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@vtj/base"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@vtj/base"),x=require("prettier/standalone"),H=require("prettier/plugins/html"),X=require("prettier/plugins/babel"),Y=require("prettier/plugins/postcss"),Z=require("prettier/plugins/estree");function k(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const K=k(H),J=k(X),T=k(Y),q=k(Z);/**!
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.
|
|
5
|
+
* @version 0.8.1
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const
|
|
7
|
+
*/const ee="0.8.1";/**!
|
|
8
8
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/core
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.
|
|
11
|
+
* @version 0.8.1
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
-
*/const
|
|
13
|
+
*/const te=["slot","template","component","img","div","p","h1","h2","h3","span","a"];l.mitt();const _={arrowParens:"always",bracketSpacing:!0,bracketSameLine:!0,endOfLine:"lf",htmlWhitespaceSensitivity:"css",insertPragma:!1,jsxBracketSameLine:!0,jsxSingleQuote:!0,printWidth:80,proseWrap:"preserve",quoteProps:"as-needed",requirePragma:!1,semi:!0,singleQuote:!0,tabWidth:2,trailingComma:"none",useTabs:!1,vueIndentScriptAndStyle:!0};async function L(t,e){return e?t:await x.format(t,{parser:"vue",..._,plugins:[K,J,q,T]})}async function se(t,e){return e?t:await x.format(t,{parser:"babel-ts",..._,plugins:[J,q]})}async function W(t,e){return e?t:x.format(t,{parser:"scss",..._,plugins:[T]})}function E(t){return t&&t.type==="JSExpression"}function A(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function S(t){return E(t)||A(t)}function F(t){return t.replace(new RegExp("this.","g"),"")}function I(t){return t.replace(/this\.context\??\./g,"")}function u(t,e=!0,s=!0){const n=S(t)?t.value:e?JSON.stringify(t):t;return s?F(I(n)):I(n)}function w(t,e=[]){let s=t;for(const n of e)s=s.replace(new RegExp(`this.${n}.value`,"g"),`this.${n}`);return s}function U(t){let e=t.trim();if(e=/^\((\(|async|function)/.test(e)?e.substring(1,e.length-1):e,e.startsWith("{"))return e;if(e.startsWith("async function"))e=e.replace(/^async function/,"async");else if(e.startsWith("function"))e=e.replace(/^function/,"");else{const i=/^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,r=e.match(i);r&&r[2]&&(r[2].startsWith("{")||(e=e.replace(r[2],`{ return ${r[2]} }`))),e=e.replace("=>","")}return e}function ne(t={}){return Object.entries(t).map(([e,s])=>`"${e}": ${u(s)}`)}function M(t={},e=!1){const s=Object.keys(t);return e?s.map(n=>"."+n):s}function re(t){let e="";for(var s in t)if(t.hasOwnProperty(s)){var n=t[s];e+=s+": "+n+";"}return e}class oe{constructor(e,s){this.dsl=e,this.dependencies=s,this.libraryRegex=this.collectLibrary(),this.walk(e),this.walkNodes(e),this.members=this.getLibraryMember()}imports={};context={};style={};members=[];urlSchemas={};blockPlugins={};libraryRegex=[];collectLibrary(){return this.dependencies.filter(e=>!!e.library).map(e=>new RegExp(`(this.\\$libs.${e.library}.([\\w]+))`,"g"))}collectImport(e){const s=e.split(".");if(s.length===4){const n=s.pop(),i=s.join(".")+".",r=s.pop();if(n&&r){const o=this.dependencies.find(c=>c.library===r)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(n)}return{name:n,path:i,library:r}}return null}replaceLibraryPath(e){const{libraryRegex:s}=this;let n=e.value;for(const i of s){const r=e.value.match(i)||[];for(const o of r){const c=this.collectImport(o);if(c){const a=c.path.replace(/\$/g,"\\$");n=n.replace(new RegExp(a,"g"),"")}}}return n}walk(e){const s=n=>{if(!n||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)s(r);return}const i=Object.values(n);for(const r of i)S(r)?r.value=this.replaceLibraryPath(r):s(r)};s(e)}getLibraryMember(e=[]){let s=[...e];for(const n of Object.values(this.imports))s=s.concat(Array.from(n));return l.dedupArray(s)}collectContext(e,s){const n=new Set(s?.id?this.context[s.id]:[]),i=(e.directives||[]).find(c=>c.name==="vFor");let r=new Set(Array.from(n));if(i){const{item:c="item",index:a="index"}=i.iterator||{};r=new Set([c,a,...Array.from(r)])}const o=e.slot;if(o){const c=typeof o=="string"?[]:o.params||[],a=c.length?c:[`scope_${s?.id}`];r=new Set([...a,...Array.from(r)])}this.context[e.id]=r}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&(this.style[`.${e.name}_${e.id}`]=e.props.style)}collectUrlSchema(e){typeof e.from=="object"&&e.from.type==="UrlSchema"&&(this.urlSchemas[e.name]=e.from)}collectBlockPlugin(e){typeof e.from=="object"&&e.from.type==="Plugin"&&(this.blockPlugins[e.name]=e.from)}walkNodes(e){const s=(n,i)=>{this.collectContext(n,i),this.collectStyle(n),this.collectUrlSchema(n),this.collectBlockPlugin(n),Array.isArray(n.children)&&n.children.forEach(r=>s(r,n))};Array.isArray(e.nodes)&&e.nodes.forEach(n=>s(n))}}function ie(t={}){return Object.entries(t).map(([e,s])=>{const n=u(s,!1);return`${e}:${n}`})}function ce(t=[]){return t.map(e=>`${e.name}: {
|
|
14
14
|
from: '${e.from||e.name}',
|
|
15
15
|
default: ${u(e.default,!0,!1)}
|
|
16
|
-
}`)}function
|
|
16
|
+
}`)}function ae(t=[]){const e=s=>s?`[${l.toArray(s).map(r=>r.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:`${s.name}: {
|
|
17
17
|
type:${e(s.type)},
|
|
18
18
|
required: ${s.required},
|
|
19
19
|
default: ${u(s.default,!0,!1)}
|
|
20
|
-
}`)}function
|
|
21
|
-
deep: ${
|
|
22
|
-
immediate:${
|
|
23
|
-
handler${
|
|
24
|
-
}`);return{computed:
|
|
20
|
+
}`)}function le(t=[]){return t.map(e=>`'${e}'`)}function v(t={},e=[]){return Object.entries(t).map(([s,n])=>{let i=U(u(n,!1,!1));return i=w(i,e),i.startsWith("async")?`async ${s}${i.replace(/^async/,"")}`:`${s}${i}`})}function ue(t=[],e=[]){const s=t.reduce((r,o)=>(o.id&&A(o.source)&&(r[`watcher_${o.id}`]=o.source),r),{}),n=v(s,e),i=t.map(r=>`watcher_${r.id}: {
|
|
21
|
+
deep: ${r.deep},
|
|
22
|
+
immediate:${r.immediate},
|
|
23
|
+
handler${U(r.handler.value)}
|
|
24
|
+
}`);return{computed:n,watches:i}}function pe(t={}){return Object.values(t).map(e=>{const s=A(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
25
25
|
return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
|
|
26
|
-
}`})}function V(t,e,s=[],
|
|
27
|
-
`),Object.assign(o,d?.methods||{}),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
`),i
|
|
32
|
-
return (${c.handler.value}).apply(this, args);
|
|
33
|
-
}`}:c.handler),me(a,c,f,i)}),handlers:r}}function he(t,e,s={},r={},i={},n){const{binders:o,handlers:a}=de(e,r,i);return{props:fe(t,s,n).join(" "),handlers:a,binders:o,events:o.join(" ")}}function ye(t=[]){const e=[],{vIf:s,vShow:r,vModels:i,vFor:n}=ge(t);if(s&&e.push(`v-if="${u(s.value)}"`),r&&e.push(`v-show="${u(r.value)}"`),i.forEach(o=>{const a=M(o.modifiers,!0),c=o.arg?C(o.arg)?`:[${u(o.arg)}]`:`:${o.arg}`:"";e.push(`v-model${c}${a}="${u(o.value)}"`)}),n){const{item:o,index:a}={item:"item",index:"index",...n.iterator};e.push(`v-for="(${o}, ${a}) in ${u(n.value)}"`)}return e}function ge(t=[]){const e=t.find(o=>l.camelCase(o.name)==="vIf"),s=t.find(o=>l.camelCase(o.name)==="vFor"),r=t.find(o=>l.camelCase(o.name)==="vShow"),i=t.find(o=>l.camelCase(o.name)==="vBind"),n=t.filter(o=>l.camelCase(o.name)==="vModel");return{vIf:e,vFor:s,vShow:r,vModels:n,vBind:i}}function $e(t,e,s,r,i){if(typeof t=="string")return t;if(C(t)){let n=u(t,!1);return n=j(n,e),n=A(n),`{{ ${n} }}`}return Array.isArray(t)?V(t,s,e,r,i):""}function be(t,e,s){if(!t)return e;const r=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${r.name}="${r.params?.length>0?`{${r.params?.join(",")}}`:`scope_${s}`}"`}>
|
|
26
|
+
}`})}function V(t,e,s=[],n={},i){const r=[];let o={},c=[],a=[];return fe(t).forEach(f=>{const $=[];for(const p of f.children){let{id:O,name:m,invisible:C,from:h}=p;if(C)continue;const b=me(m,e,h);b&&c.push(b),D(h)&&a.push({id:h.id,name:m});const{props:g,events:N,handlers:G}=$e(p,O,p.props,p.events,n,s),B=be(p.directives).join(" "),d=p.children?ve(p.children,s,e,n,p):"";Object.assign(o,G);let j="";typeof d=="string"?j=d:(j=(d?.nodes||[]).join(`
|
|
27
|
+
`),Object.assign(o,d?.methods||{}),c=c.concat(d?.components||[]),a=a.concat(d?.importBlocks||[]));const R=Q(h)||z(h)?"component":m;$.push(m==="img"?`<${m} ${B} ${g} ${N} />`:`<${R} ${B} ${g} ${N}>${j?`
|
|
28
|
+
`+j.trim():""}</${R}>`)}const P=Se(f.slot,$.join(`
|
|
29
|
+
`),i?.id);r.push(P)}),{nodes:r,methods:o,components:l.dedupArray(c),importBlocks:l.dedupArray(a,"id")}}function fe(t=[]){const e=new Map;for(const s of t){const n=typeof s.slot=="string"?s.slot:s.slot?.name,i=e.get(n);i?i.children.push(s):e.set(n,{slot:s.slot,children:[s]})}return e}function me(t,e,s){if(te.includes(t))return null;const n=e.get(t);if(n&&n.alias){const i=n.parent?`${n.parent}.${n.alias}`:n.alias;return`${t}: ${i}`}return D(s)||n?t:null}function D(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function Q(t){return typeof t=="object"&&t.type==="UrlSchema"}function z(t){return typeof t=="object"&&t.type==="Plugin"}function he(t,e,s=[]){return t==="style"?"":t==="__class"&&S(e)?`:class="${u({...e,value:w(e.value,s)})}"`:typeof e=="string"?`${t}="${e}"`:S(e)?`:${t}="${u({...e,value:w(e.value,s)})}"`:l.isPlainObject(e)?`:${t}='{${ne(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function de(t,e={},s=[]){if(!!Object.keys(e.style||{}).length){const r=`${t.name}_${t.id}`;e.class?typeof e.class=="string"?e.class=[e.class,r].join(" "):(e.__class=e.class,e.class=r):(e.class=r,delete e.style)}const i=t.from;return(Q(i)||z(i))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([r,o])=>he(r,o,s))}function ye(t,e,s,n){const i=M(e.modifiers,!0);return n&&n.length>0?`@${t}${i.join("")}="(...args:any[]) => ${s}"`:`@${t}${i.join("")}="${s}"`}function ge(t,e={},s={}){const n={},i=Array.from(s[t]||new Set([])),r=i.length?`({${i.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([c,a])=>{const y=a.handler.value.startsWith("this."),f=y?F(a.handler.value):`${l.camelCase(c)}_${t}${r}`;return y||(n[f]=i.length?{type:"JSFunction",value:`{
|
|
30
|
+
return (${a.handler.value}).apply(this, args);
|
|
31
|
+
}`}:a.handler),ye(c,a,f,i)}),handlers:n}}function $e(t,e,s={},n={},i={},r){const{binders:o,handlers:c}=ge(e,n,i);return{props:de(t,s,r).join(" "),handlers:c,binders:o,events:o.join(" ")}}function be(t=[]){const e=[],{vIf:s,vShow:n,vModels:i,vFor:r}=je(t);if(s&&e.push(`v-if="${u(s.value)}"`),n&&e.push(`v-show="${u(n.value)}"`),i.forEach(o=>{const c=M(o.modifiers,!0),a=o.arg?E(o.arg)?`:[${u(o.arg)}]`:`:${o.arg}`:"";e.push(`v-model${a}${c}="${u(o.value)}"`)}),r){const{item:o,index:c}={item:"item",index:"index",...r.iterator};e.push(`v-for="(${o}, ${c}) in ${u(r.value)}"`)}return e}function je(t=[]){const e=t.find(o=>l.camelCase(o.name)==="vIf"),s=t.find(o=>l.camelCase(o.name)==="vFor"),n=t.find(o=>l.camelCase(o.name)==="vShow"),i=t.find(o=>l.camelCase(o.name)==="vBind"),r=t.filter(o=>l.camelCase(o.name)==="vModel");return{vIf:e,vFor:s,vShow:n,vModels:r,vBind:i}}function ve(t,e,s,n,i){if(typeof t=="string")return t;if(E(t)){let r=u(t,!1);return r=w(r,e),r=F(r),`{{ ${r} }}`}return Array.isArray(t)?V(t,s,e,n,i):""}function Se(t,e,s){if(!t)return e;const n=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${n.name}="${n.params?.length>0?`{${n.params?.join(",")}}`:`scope_${s}`}"`}>
|
|
34
32
|
${e}
|
|
35
|
-
</template>`}function
|
|
33
|
+
</template>`}function we(t,e=[],s=[],n={}){const i={vue:["defineComponent","reactive"]};for(const r of e){const o=t.get(r.split(":")[0]);o&&o.package&&(i[o.package]??(i[o.package]=[])).push(o.parent||(o.alias||"").split(".")[0]||o.name)}for(const[r,o]of Object.entries(n))(i[r]??(i[r]=[])).push(...Array.from(o));return Object.entries(i).filter(([r,o])=>!!o.length).map(([r,o])=>`import { ${l.dedupArray(o).join(",")}} from '${r}';`).concat(s)}function ke(t={}){const e=[];for(const[s,n]of Object.entries(t))e.push(`
|
|
36
34
|
${s} {
|
|
37
|
-
${
|
|
35
|
+
${re(n)}
|
|
38
36
|
}
|
|
39
37
|
`);return e.join(`
|
|
40
|
-
`)}function
|
|
41
|
-
`),components:f.join(","),returns:t.members.join(","),template:
|
|
42
|
-
`),css:s.css||"",style:
|
|
38
|
+
`)}function Pe(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`)}),e}function Oe(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`)}),e}function Ce(t,e){const{dsl:s}=t,n=Object.keys(s.computed||{}),i=v(s.lifeCycles,n),r=v(s.computed,n),o=ue(s.watch,n),c=pe(s.dataSources),{methods:a,nodes:y,components:f,importBlocks:$}=V(s.nodes||[],e,n,t.context),P=[...r,...o.computed],p=v({...a,...s.methods||{}},n),O=$.map(g=>`import ${g.name} from './${g.id}.vue';`),m=we(e,f,O,t.imports),C=Object.keys({...t.urlSchemas,...t.blockPlugins}),h=Pe(t.urlSchemas),b=Oe(t.blockPlugins);return{id:s.id,version:s.__VERSION__,name:s.name,state:ie(s.state).join(","),inject:ce(s.inject).join(","),props:ae(s.props).join(","),emits:le(s.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:P.join(","),methods:[...c,...p].join(","),imports:m.join(`
|
|
39
|
+
`),components:f.join(","),returns:t.members.join(","),template:y.join(`
|
|
40
|
+
`),css:s.css||"",style:ke(t.style),urlSchemas:h.join(`
|
|
41
|
+
`),blockPlugins:b.join(`
|
|
42
|
+
`),asyncComponents:C.join(",")}}const xe=`
|
|
43
43
|
<%= imports %>
|
|
44
44
|
import { useProvider } from '@vtj/renderer';
|
|
45
45
|
export default defineComponent({
|
|
@@ -53,11 +53,14 @@ export default defineComponent({
|
|
|
53
53
|
id: '<%= id %>',
|
|
54
54
|
version: '<%= version %>'
|
|
55
55
|
});
|
|
56
|
-
const state = reactive({ <%= state %> });
|
|
56
|
+
const state = reactive<Record<string, any>>({ <%= state %> });
|
|
57
|
+
<%= urlSchemas %>
|
|
58
|
+
<%= blockPlugins %>
|
|
57
59
|
return {
|
|
58
60
|
state,
|
|
59
61
|
props,
|
|
60
62
|
provider
|
|
63
|
+
<% if(asyncComponents) { %>, <%= asyncComponents %> <% }%>
|
|
61
64
|
<% if(returns) { %>, <%= returns %> <% } %>
|
|
62
65
|
};
|
|
63
66
|
},
|
|
@@ -65,7 +68,7 @@ export default defineComponent({
|
|
|
65
68
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
66
69
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
67
70
|
});
|
|
68
|
-
`.replace(/(\n|\r|\t)/g,""),
|
|
71
|
+
`.replace(/(\n|\r|\t)/g,""),_e=`
|
|
69
72
|
<template>
|
|
70
73
|
<%= template %>
|
|
71
74
|
</template>
|
|
@@ -76,7 +79,7 @@ export default defineComponent({
|
|
|
76
79
|
<%= css %>
|
|
77
80
|
<%= style %>
|
|
78
81
|
</style>
|
|
79
|
-
`,
|
|
82
|
+
`,Ee=l.template(xe),Ae=l.template(_e);async function Fe(t,e=new Map,s=[],n){const i=new oe(l.cloneDeep(t),s),r=Ce(i,e),o=Ee(r),c=Ae({template:r.template,css:await W(r.css,n),script:await se(o,n),style:await W(r.style,n)});return await L(c,n)}async function Ne(t){const e=`
|
|
80
83
|
<template>
|
|
81
84
|
<div>
|
|
82
85
|
<h3>源码模式页面</h3>
|
|
@@ -87,4 +90,4 @@ export default defineComponent({
|
|
|
87
90
|
<\/script>
|
|
88
91
|
<style scoped lang="scss">
|
|
89
92
|
</style>
|
|
90
|
-
`;return await
|
|
93
|
+
`;return await L(e)}exports.VTJ_CODER_VERSION=ee;exports.createEmptyPage=Ne;exports.generator=Fe;
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { mitt as
|
|
2
|
-
import { format as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
1
|
+
import { mitt as X, dedupArray as S, toArray as Y, camelCase as y, isPlainObject as Z, template as J, cloneDeep as K } from "@vtj/base";
|
|
2
|
+
import { format as C } from "prettier/standalone";
|
|
3
|
+
import * as tt from "prettier/plugins/html";
|
|
4
|
+
import * as L from "prettier/plugins/babel";
|
|
5
|
+
import * as T from "prettier/plugins/postcss";
|
|
6
|
+
import * as U from "prettier/plugins/estree";
|
|
7
7
|
/**!
|
|
8
8
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/coder
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.
|
|
11
|
+
* @version 0.8.1
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const Bt = "0.8.1";
|
|
15
15
|
/**!
|
|
16
16
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
17
17
|
* @name @vtj/core
|
|
18
18
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
19
|
-
* @version 0.
|
|
19
|
+
* @version 0.8.1
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
22
|
+
const et = [
|
|
23
23
|
"slot",
|
|
24
24
|
"template",
|
|
25
25
|
"component",
|
|
@@ -32,8 +32,8 @@ const Y = [
|
|
|
32
32
|
"span",
|
|
33
33
|
"a"
|
|
34
34
|
];
|
|
35
|
-
|
|
36
|
-
const
|
|
35
|
+
X();
|
|
36
|
+
const E = {
|
|
37
37
|
arrowParens: "always",
|
|
38
38
|
bracketSpacing: !0,
|
|
39
39
|
bracketSameLine: !0,
|
|
@@ -54,51 +54,51 @@ const C = {
|
|
|
54
54
|
vueIndentScriptAndStyle: !0
|
|
55
55
|
};
|
|
56
56
|
async function V(e, t) {
|
|
57
|
-
return t ? e : await
|
|
57
|
+
return t ? e : await C(e, {
|
|
58
58
|
parser: "vue",
|
|
59
|
-
...
|
|
60
|
-
plugins: [
|
|
59
|
+
...E,
|
|
60
|
+
plugins: [tt, L, U, T]
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
async function
|
|
64
|
-
return t ? e : await
|
|
63
|
+
async function st(e, t) {
|
|
64
|
+
return t ? e : await C(e, {
|
|
65
65
|
parser: "babel-ts",
|
|
66
|
-
...
|
|
67
|
-
plugins: [
|
|
66
|
+
...E,
|
|
67
|
+
plugins: [L, U]
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
async function W(e, t) {
|
|
71
|
-
return t ? e :
|
|
71
|
+
return t ? e : C(e, {
|
|
72
72
|
parser: "scss",
|
|
73
|
-
...
|
|
74
|
-
plugins: [
|
|
73
|
+
...E,
|
|
74
|
+
plugins: [T]
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
function _(e) {
|
|
78
78
|
return e && e.type === "JSExpression";
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function A(e) {
|
|
81
81
|
return typeof e == "object" && e && e.type === "JSFunction";
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return _(e) ||
|
|
83
|
+
function w(e) {
|
|
84
|
+
return _(e) || A(e);
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function F(e) {
|
|
87
87
|
return e.replace(new RegExp("this.", "g"), "");
|
|
88
88
|
}
|
|
89
89
|
function I(e) {
|
|
90
90
|
return e.replace(/this\.context\??\./g, "");
|
|
91
91
|
}
|
|
92
92
|
function l(e, t = !0, s = !0) {
|
|
93
|
-
const
|
|
94
|
-
return s ?
|
|
93
|
+
const n = w(e) ? e.value : t ? JSON.stringify(e) : e;
|
|
94
|
+
return s ? F(I(n)) : I(n);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function k(e, t = []) {
|
|
97
97
|
let s = e;
|
|
98
|
-
for (const
|
|
98
|
+
for (const n of t)
|
|
99
99
|
s = s.replace(
|
|
100
|
-
new RegExp(`this.${
|
|
101
|
-
`this.${
|
|
100
|
+
new RegExp(`this.${n}.value`, "g"),
|
|
101
|
+
`this.${n}`
|
|
102
102
|
);
|
|
103
103
|
return s;
|
|
104
104
|
}
|
|
@@ -111,28 +111,28 @@ function q(e) {
|
|
|
111
111
|
else if (t.startsWith("function"))
|
|
112
112
|
t = t.replace(/^function/, "");
|
|
113
113
|
else {
|
|
114
|
-
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,
|
|
115
|
-
|
|
114
|
+
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/, r = t.match(i);
|
|
115
|
+
r && r[2] && (r[2].startsWith("{") || (t = t.replace(r[2], `{ return ${r[2]} }`))), t = t.replace("=>", "");
|
|
116
116
|
}
|
|
117
117
|
return t;
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function nt(e = {}) {
|
|
120
120
|
return Object.entries(e).map(([t, s]) => `"${t}": ${l(s)}`);
|
|
121
121
|
}
|
|
122
122
|
function M(e = {}, t = !1) {
|
|
123
123
|
const s = Object.keys(e);
|
|
124
|
-
return t ? s.map((
|
|
124
|
+
return t ? s.map((n) => "." + n) : s;
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function rt(e) {
|
|
127
127
|
let t = "";
|
|
128
128
|
for (var s in e)
|
|
129
129
|
if (e.hasOwnProperty(s)) {
|
|
130
|
-
var
|
|
131
|
-
t += s + ": " +
|
|
130
|
+
var n = e[s];
|
|
131
|
+
t += s + ": " + n + ";";
|
|
132
132
|
}
|
|
133
133
|
return t;
|
|
134
134
|
}
|
|
135
|
-
class
|
|
135
|
+
class ot {
|
|
136
136
|
constructor(t, s) {
|
|
137
137
|
this.dsl = t, this.dependencies = s, this.libraryRegex = this.collectLibrary(), this.walk(t), this.walkNodes(t), this.members = this.getLibraryMember();
|
|
138
138
|
}
|
|
@@ -143,6 +143,8 @@ class et {
|
|
|
143
143
|
context = {};
|
|
144
144
|
style = {};
|
|
145
145
|
members = [];
|
|
146
|
+
urlSchemas = {};
|
|
147
|
+
blockPlugins = {};
|
|
146
148
|
libraryRegex = [];
|
|
147
149
|
collectLibrary() {
|
|
148
150
|
return this.dependencies.filter((t) => !!t.library).map((t) => new RegExp(`(this.\\$libs.${t.library}.([\\w]+))`, "g"));
|
|
@@ -155,17 +157,17 @@ class et {
|
|
|
155
157
|
collectImport(t) {
|
|
156
158
|
const s = t.split(".");
|
|
157
159
|
if (s.length === 4) {
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
+
const n = s.pop(), i = s.join(".") + ".", r = s.pop();
|
|
161
|
+
if (n && r) {
|
|
160
162
|
const o = this.dependencies.find(
|
|
161
|
-
(
|
|
163
|
+
(c) => c.library === r
|
|
162
164
|
)?.package;
|
|
163
|
-
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(
|
|
165
|
+
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(n);
|
|
164
166
|
}
|
|
165
167
|
return {
|
|
166
|
-
name:
|
|
168
|
+
name: n,
|
|
167
169
|
path: i,
|
|
168
|
-
library:
|
|
170
|
+
library: r
|
|
169
171
|
};
|
|
170
172
|
}
|
|
171
173
|
return null;
|
|
@@ -173,320 +175,355 @@ class et {
|
|
|
173
175
|
// 代码中包含依赖库的引用,需要从代码中移除
|
|
174
176
|
replaceLibraryPath(t) {
|
|
175
177
|
const { libraryRegex: s } = this;
|
|
176
|
-
let
|
|
178
|
+
let n = t.value;
|
|
177
179
|
for (const i of s) {
|
|
178
|
-
const
|
|
179
|
-
for (const o of
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
182
|
-
const
|
|
183
|
-
|
|
180
|
+
const r = t.value.match(i) || [];
|
|
181
|
+
for (const o of r) {
|
|
182
|
+
const c = this.collectImport(o);
|
|
183
|
+
if (c) {
|
|
184
|
+
const a = c.path.replace(/\$/g, "\\$");
|
|
185
|
+
n = n.replace(new RegExp(a, "g"), "");
|
|
184
186
|
}
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
|
-
return
|
|
189
|
+
return n;
|
|
188
190
|
}
|
|
189
191
|
walk(t) {
|
|
190
|
-
const s = (
|
|
191
|
-
if (!
|
|
192
|
+
const s = (n) => {
|
|
193
|
+
if (!n || typeof n != "object")
|
|
192
194
|
return;
|
|
193
|
-
if (Array.isArray(
|
|
194
|
-
for (let
|
|
195
|
-
s(
|
|
195
|
+
if (Array.isArray(n)) {
|
|
196
|
+
for (let r of n)
|
|
197
|
+
s(r);
|
|
196
198
|
return;
|
|
197
199
|
}
|
|
198
|
-
const i = Object.values(
|
|
199
|
-
for (const
|
|
200
|
-
|
|
200
|
+
const i = Object.values(n);
|
|
201
|
+
for (const r of i)
|
|
202
|
+
w(r) ? r.value = this.replaceLibraryPath(r) : s(r);
|
|
201
203
|
};
|
|
202
204
|
s(t);
|
|
203
205
|
}
|
|
204
206
|
getLibraryMember(t = []) {
|
|
205
207
|
let s = [...t];
|
|
206
|
-
for (const
|
|
207
|
-
s = s.concat(Array.from(
|
|
208
|
-
return
|
|
208
|
+
for (const n of Object.values(this.imports))
|
|
209
|
+
s = s.concat(Array.from(n));
|
|
210
|
+
return S(s);
|
|
209
211
|
}
|
|
210
212
|
collectContext(t, s) {
|
|
211
|
-
const
|
|
212
|
-
let
|
|
213
|
+
const n = new Set(s?.id ? this.context[s.id] : []), i = (t.directives || []).find((c) => c.name === "vFor");
|
|
214
|
+
let r = new Set(Array.from(n));
|
|
213
215
|
if (i) {
|
|
214
|
-
const { item:
|
|
215
|
-
|
|
216
|
+
const { item: c = "item", index: a = "index" } = i.iterator || {};
|
|
217
|
+
r = /* @__PURE__ */ new Set([c, a, ...Array.from(r)]);
|
|
216
218
|
}
|
|
217
219
|
const o = t.slot;
|
|
218
220
|
if (o) {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
+
const c = typeof o == "string" ? [] : o.params || [], a = c.length ? c : [`scope_${s?.id}`];
|
|
222
|
+
r = /* @__PURE__ */ new Set([...a, ...Array.from(r)]);
|
|
221
223
|
}
|
|
222
|
-
this.context[t.id] =
|
|
224
|
+
this.context[t.id] = r;
|
|
223
225
|
}
|
|
224
226
|
collectStyle(t) {
|
|
225
227
|
t.id && t.props?.style && Object.keys(t.props.style).length && (this.style[`.${t.name}_${t.id}`] = t.props.style);
|
|
226
228
|
}
|
|
229
|
+
collectUrlSchema(t) {
|
|
230
|
+
typeof t.from == "object" && t.from.type === "UrlSchema" && (this.urlSchemas[t.name] = t.from);
|
|
231
|
+
}
|
|
232
|
+
collectBlockPlugin(t) {
|
|
233
|
+
typeof t.from == "object" && t.from.type === "Plugin" && (this.blockPlugins[t.name] = t.from);
|
|
234
|
+
}
|
|
227
235
|
walkNodes(t) {
|
|
228
|
-
const s = (
|
|
229
|
-
this.collectContext(
|
|
236
|
+
const s = (n, i) => {
|
|
237
|
+
this.collectContext(n, i), this.collectStyle(n), this.collectUrlSchema(n), this.collectBlockPlugin(n), Array.isArray(n.children) && n.children.forEach((r) => s(r, n));
|
|
230
238
|
};
|
|
231
|
-
Array.isArray(t.nodes) && t.nodes.forEach((
|
|
239
|
+
Array.isArray(t.nodes) && t.nodes.forEach((n) => s(n));
|
|
232
240
|
}
|
|
233
241
|
}
|
|
234
|
-
function
|
|
242
|
+
function it(e = {}) {
|
|
235
243
|
return Object.entries(e).map(([t, s]) => {
|
|
236
|
-
const
|
|
237
|
-
return `${t}:${
|
|
244
|
+
const n = l(s, !1);
|
|
245
|
+
return `${t}:${n}`;
|
|
238
246
|
});
|
|
239
247
|
}
|
|
240
|
-
function
|
|
248
|
+
function ct(e = []) {
|
|
241
249
|
return e.map((t) => `${t.name}: {
|
|
242
250
|
from: '${t.from || t.name}',
|
|
243
251
|
default: ${l(t.default, !0, !1)}
|
|
244
252
|
}`);
|
|
245
253
|
}
|
|
246
|
-
function
|
|
247
|
-
const t = (s) => s ? `[${
|
|
254
|
+
function at(e = []) {
|
|
255
|
+
const t = (s) => s ? `[${Y(s).map((r) => r.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
248
256
|
return e.map((s) => typeof s == "string" ? `${s}: {}` : `${s.name}: {
|
|
249
257
|
type:${t(s.type)},
|
|
250
258
|
required: ${s.required},
|
|
251
259
|
default: ${l(s.default, !0, !1)}
|
|
252
260
|
}`);
|
|
253
261
|
}
|
|
254
|
-
function
|
|
262
|
+
function lt(e = []) {
|
|
255
263
|
return e.map((t) => `'${t}'`);
|
|
256
264
|
}
|
|
257
|
-
function
|
|
258
|
-
return Object.entries(e).map(([s,
|
|
259
|
-
let i = q(l(
|
|
260
|
-
return i =
|
|
265
|
+
function j(e = {}, t = []) {
|
|
266
|
+
return Object.entries(e).map(([s, n]) => {
|
|
267
|
+
let i = q(l(n, !1, !1));
|
|
268
|
+
return i = k(i, t), i.startsWith("async") ? `async ${s}${i.replace(/^async/, "")}` : `${s}${i}`;
|
|
261
269
|
});
|
|
262
270
|
}
|
|
263
|
-
function
|
|
271
|
+
function ut(e = [], t = []) {
|
|
264
272
|
const s = e.reduce(
|
|
265
|
-
(
|
|
273
|
+
(r, o) => (o.id && A(o.source) && (r[`watcher_${o.id}`] = o.source), r),
|
|
266
274
|
{}
|
|
267
|
-
),
|
|
268
|
-
deep: ${
|
|
269
|
-
immediate:${
|
|
270
|
-
handler${q(
|
|
275
|
+
), n = j(s, t), i = e.map((r) => `watcher_${r.id}: {
|
|
276
|
+
deep: ${r.deep},
|
|
277
|
+
immediate:${r.immediate},
|
|
278
|
+
handler${q(r.handler.value)}
|
|
271
279
|
}`);
|
|
272
280
|
return {
|
|
273
|
-
computed:
|
|
281
|
+
computed: n,
|
|
274
282
|
watches: i
|
|
275
283
|
};
|
|
276
284
|
}
|
|
277
|
-
function
|
|
285
|
+
function pt(e = {}) {
|
|
278
286
|
return Object.values(e).map((t) => {
|
|
279
|
-
const s =
|
|
287
|
+
const s = A(t.transform) && t.transform.value || "(res) => res";
|
|
280
288
|
return `async ${t.name}(...args:any[]) {
|
|
281
289
|
return await this.provider.apis['${t.ref}'].apply(this, args).then(${s});
|
|
282
290
|
}`;
|
|
283
291
|
});
|
|
284
292
|
}
|
|
285
|
-
function D(e, t, s = [],
|
|
286
|
-
const
|
|
287
|
-
let o = {},
|
|
288
|
-
return
|
|
289
|
-
const
|
|
293
|
+
function D(e, t, s = [], n = {}, i) {
|
|
294
|
+
const r = [];
|
|
295
|
+
let o = {}, c = [], a = [];
|
|
296
|
+
return ft(e).forEach((p) => {
|
|
297
|
+
const $ = [];
|
|
290
298
|
for (const u of p.children) {
|
|
291
|
-
let { id: x, name: f, invisible:
|
|
292
|
-
if (
|
|
299
|
+
let { id: x, name: f, invisible: O, from: m } = u;
|
|
300
|
+
if (O)
|
|
293
301
|
continue;
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
const { props:
|
|
302
|
+
const b = mt(f, t, m);
|
|
303
|
+
b && c.push(b), Q(m) && a.push({ id: m.id, name: f });
|
|
304
|
+
const { props: g, events: N, handlers: H } = $t(
|
|
297
305
|
u,
|
|
298
306
|
x,
|
|
299
307
|
u.props,
|
|
300
308
|
u.events,
|
|
301
|
-
|
|
309
|
+
n,
|
|
302
310
|
s
|
|
303
|
-
),
|
|
311
|
+
), B = bt(u.directives).join(" "), h = u.children ? jt(
|
|
304
312
|
u.children,
|
|
305
313
|
s,
|
|
306
314
|
t,
|
|
307
|
-
|
|
315
|
+
n,
|
|
308
316
|
u
|
|
309
317
|
) : "";
|
|
310
|
-
Object.assign(o,
|
|
311
|
-
let
|
|
312
|
-
typeof
|
|
313
|
-
`), Object.assign(o,
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
`
|
|
318
|
+
Object.assign(o, H);
|
|
319
|
+
let v = "";
|
|
320
|
+
typeof h == "string" ? v = h : (v = (h?.nodes || []).join(`
|
|
321
|
+
`), Object.assign(o, h?.methods || {}), c = c.concat(h?.components || []), a = a.concat(h?.importBlocks || []));
|
|
322
|
+
const R = z(m) || G(m) ? "component" : f;
|
|
323
|
+
$.push(
|
|
324
|
+
f === "img" ? `<${f} ${B} ${g} ${N} />` : `<${R} ${B} ${g} ${N}>${v ? `
|
|
325
|
+
` + v.trim() : ""}</${R}>`
|
|
318
326
|
);
|
|
319
327
|
}
|
|
320
|
-
const
|
|
328
|
+
const P = St(p.slot, $.join(`
|
|
321
329
|
`), i?.id);
|
|
322
|
-
|
|
330
|
+
r.push(P);
|
|
323
331
|
}), {
|
|
324
|
-
nodes:
|
|
332
|
+
nodes: r,
|
|
325
333
|
methods: o,
|
|
326
|
-
components:
|
|
327
|
-
importBlocks:
|
|
334
|
+
components: S(c),
|
|
335
|
+
importBlocks: S(a, "id")
|
|
328
336
|
};
|
|
329
337
|
}
|
|
330
|
-
function
|
|
338
|
+
function ft(e = []) {
|
|
331
339
|
const t = /* @__PURE__ */ new Map();
|
|
332
340
|
for (const s of e) {
|
|
333
|
-
const
|
|
334
|
-
i ? i.children.push(s) : t.set(
|
|
341
|
+
const n = typeof s.slot == "string" ? s.slot : s.slot?.name, i = t.get(n);
|
|
342
|
+
i ? i.children.push(s) : t.set(n, { slot: s.slot, children: [s] });
|
|
335
343
|
}
|
|
336
344
|
return t;
|
|
337
345
|
}
|
|
338
|
-
function
|
|
339
|
-
if (
|
|
346
|
+
function mt(e, t, s) {
|
|
347
|
+
if (et.includes(e))
|
|
340
348
|
return null;
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
343
|
-
const i =
|
|
349
|
+
const n = t.get(e);
|
|
350
|
+
if (n && n.alias) {
|
|
351
|
+
const i = n.parent ? `${n.parent}.${n.alias}` : n.alias;
|
|
344
352
|
return `${e}: ${i}`;
|
|
345
353
|
}
|
|
346
|
-
return s ||
|
|
354
|
+
return Q(s) || n ? e : null;
|
|
347
355
|
}
|
|
348
|
-
function
|
|
356
|
+
function Q(e) {
|
|
349
357
|
return !!e && typeof e == "object" && e.type === "Schema";
|
|
350
358
|
}
|
|
351
|
-
function
|
|
352
|
-
return e
|
|
359
|
+
function z(e) {
|
|
360
|
+
return typeof e == "object" && e.type === "UrlSchema";
|
|
361
|
+
}
|
|
362
|
+
function G(e) {
|
|
363
|
+
return typeof e == "object" && e.type === "Plugin";
|
|
364
|
+
}
|
|
365
|
+
function ht(e, t, s = []) {
|
|
366
|
+
return e === "style" ? "" : e === "__class" && w(t) ? `:class="${l({
|
|
353
367
|
...t,
|
|
354
|
-
value:
|
|
355
|
-
})}"` : typeof t == "string" ? `${e}="${t}"` :
|
|
368
|
+
value: k(t.value, s)
|
|
369
|
+
})}"` : typeof t == "string" ? `${e}="${t}"` : w(t) ? `:${e}="${l({
|
|
356
370
|
...t,
|
|
357
|
-
value:
|
|
358
|
-
})}"` :
|
|
371
|
+
value: k(t.value, s)
|
|
372
|
+
})}"` : Z(t) ? `:${e}='{${nt(
|
|
359
373
|
t
|
|
360
374
|
).join(", ")}}'` : `:${e}='${JSON.stringify(t)}'`;
|
|
361
375
|
}
|
|
362
|
-
function
|
|
376
|
+
function yt(e, t = {}, s = []) {
|
|
363
377
|
if (!!Object.keys(t.style || {}).length) {
|
|
364
|
-
const
|
|
365
|
-
t.class ? typeof t.class == "string" ? t.class = [t.class,
|
|
378
|
+
const r = `${e.name}_${e.id}`;
|
|
379
|
+
t.class ? typeof t.class == "string" ? t.class = [t.class, r].join(" ") : (t.__class = t.class, t.class = r) : (t.class = r, delete t.style);
|
|
366
380
|
}
|
|
367
|
-
|
|
381
|
+
const i = e.from;
|
|
382
|
+
return (z(i) || G(i)) && (t.is = {
|
|
383
|
+
type: "JSExpression",
|
|
384
|
+
value: e.name
|
|
385
|
+
}), Object.entries(t).map(([r, o]) => ht(r, o, s));
|
|
368
386
|
}
|
|
369
|
-
function
|
|
387
|
+
function dt(e, t, s, n) {
|
|
370
388
|
const i = M(t.modifiers, !0);
|
|
371
|
-
return
|
|
389
|
+
return n && n.length > 0 ? `@${e}${i.join("")}="(...args:any[]) => ${s}"` : `@${e}${i.join("")}="${s}"`;
|
|
372
390
|
}
|
|
373
|
-
function
|
|
374
|
-
const
|
|
391
|
+
function gt(e, t = {}, s = {}) {
|
|
392
|
+
const n = {}, i = Array.from(s[e] || /* @__PURE__ */ new Set([])), r = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
375
393
|
return {
|
|
376
|
-
binders: Object.entries(t).map(([
|
|
377
|
-
const d =
|
|
378
|
-
return d || (
|
|
394
|
+
binders: Object.entries(t).map(([c, a]) => {
|
|
395
|
+
const d = a.handler.value.startsWith("this."), p = d ? F(a.handler.value) : `${y(c)}_${e}${r}`;
|
|
396
|
+
return d || (n[p] = i.length ? {
|
|
379
397
|
type: "JSFunction",
|
|
380
398
|
value: `{
|
|
381
|
-
return (${
|
|
399
|
+
return (${a.handler.value}).apply(this, args);
|
|
382
400
|
}`
|
|
383
|
-
} :
|
|
401
|
+
} : a.handler), dt(c, a, p, i);
|
|
384
402
|
}),
|
|
385
|
-
handlers:
|
|
403
|
+
handlers: n
|
|
386
404
|
};
|
|
387
405
|
}
|
|
388
|
-
function
|
|
389
|
-
const { binders: o, handlers:
|
|
406
|
+
function $t(e, t, s = {}, n = {}, i = {}, r) {
|
|
407
|
+
const { binders: o, handlers: c } = gt(t, n, i);
|
|
390
408
|
return {
|
|
391
|
-
props:
|
|
392
|
-
handlers:
|
|
409
|
+
props: yt(e, s, r).join(" "),
|
|
410
|
+
handlers: c,
|
|
393
411
|
binders: o,
|
|
394
412
|
events: o.join(" ")
|
|
395
413
|
};
|
|
396
414
|
}
|
|
397
|
-
function
|
|
398
|
-
const t = [], { vIf: s, vShow:
|
|
399
|
-
if (s && t.push(`v-if="${l(s.value)}"`),
|
|
400
|
-
const
|
|
401
|
-
t.push(`v-model${
|
|
402
|
-
}),
|
|
403
|
-
const { item: o, index:
|
|
404
|
-
t.push(`v-for="(${o}, ${
|
|
415
|
+
function bt(e = []) {
|
|
416
|
+
const t = [], { vIf: s, vShow: n, vModels: i, vFor: r } = vt(e);
|
|
417
|
+
if (s && t.push(`v-if="${l(s.value)}"`), n && t.push(`v-show="${l(n.value)}"`), i.forEach((o) => {
|
|
418
|
+
const c = M(o.modifiers, !0), a = o.arg ? _(o.arg) ? `:[${l(o.arg)}]` : `:${o.arg}` : "";
|
|
419
|
+
t.push(`v-model${a}${c}="${l(o.value)}"`);
|
|
420
|
+
}), r) {
|
|
421
|
+
const { item: o, index: c } = { item: "item", index: "index", ...r.iterator };
|
|
422
|
+
t.push(`v-for="(${o}, ${c}) in ${l(r.value)}"`);
|
|
405
423
|
}
|
|
406
424
|
return t;
|
|
407
425
|
}
|
|
408
|
-
function
|
|
409
|
-
const t = e.find((o) =>
|
|
426
|
+
function vt(e = []) {
|
|
427
|
+
const t = e.find((o) => y(o.name) === "vIf"), s = e.find((o) => y(o.name) === "vFor"), n = e.find((o) => y(o.name) === "vShow"), i = e.find((o) => y(o.name) === "vBind"), r = e.filter((o) => y(o.name) === "vModel");
|
|
410
428
|
return {
|
|
411
429
|
vIf: t,
|
|
412
430
|
vFor: s,
|
|
413
|
-
vShow:
|
|
414
|
-
vModels:
|
|
431
|
+
vShow: n,
|
|
432
|
+
vModels: r,
|
|
415
433
|
vBind: i
|
|
416
434
|
};
|
|
417
435
|
}
|
|
418
|
-
function
|
|
436
|
+
function jt(e, t, s, n, i) {
|
|
419
437
|
if (typeof e == "string")
|
|
420
438
|
return e;
|
|
421
439
|
if (_(e)) {
|
|
422
|
-
let
|
|
423
|
-
return
|
|
440
|
+
let r = l(e, !1);
|
|
441
|
+
return r = k(r, t), r = F(r), `{{ ${r} }}`;
|
|
424
442
|
}
|
|
425
|
-
return Array.isArray(e) ? D(e, s, t,
|
|
443
|
+
return Array.isArray(e) ? D(e, s, t, n, i) : "";
|
|
426
444
|
}
|
|
427
|
-
function
|
|
445
|
+
function St(e, t, s) {
|
|
428
446
|
if (!e)
|
|
429
447
|
return t;
|
|
430
|
-
const
|
|
431
|
-
return `<template ${`#${
|
|
448
|
+
const n = typeof e == "string" ? { name: e, params: [] } : { params: [], ...e };
|
|
449
|
+
return `<template ${`#${n.name}="${n.params?.length > 0 ? `{${n.params?.join(",")}}` : `scope_${s}`}"`}>
|
|
432
450
|
${t}
|
|
433
451
|
</template>`;
|
|
434
452
|
}
|
|
435
|
-
function
|
|
453
|
+
function wt(e, t = [], s = [], n = {}) {
|
|
436
454
|
const i = {
|
|
437
455
|
vue: ["defineComponent", "reactive"]
|
|
438
456
|
};
|
|
439
|
-
for (const
|
|
440
|
-
const o = e.get(
|
|
457
|
+
for (const r of t) {
|
|
458
|
+
const o = e.get(r.split(":")[0]);
|
|
441
459
|
o && o.package && (i[o.package] ?? (i[o.package] = [])).push(o.parent || (o.alias || "").split(".")[0] || o.name);
|
|
442
460
|
}
|
|
443
|
-
for (const [
|
|
444
|
-
(i[
|
|
445
|
-
return Object.entries(i).filter(([
|
|
461
|
+
for (const [r, o] of Object.entries(n))
|
|
462
|
+
(i[r] ?? (i[r] = [])).push(...Array.from(o));
|
|
463
|
+
return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${S(o).join(
|
|
446
464
|
","
|
|
447
|
-
)}} from '${
|
|
465
|
+
)}} from '${r}';`).concat(s);
|
|
448
466
|
}
|
|
449
|
-
function
|
|
467
|
+
function kt(e = {}) {
|
|
450
468
|
const t = [];
|
|
451
|
-
for (const [s,
|
|
469
|
+
for (const [s, n] of Object.entries(e))
|
|
452
470
|
t.push(`
|
|
453
471
|
${s} {
|
|
454
|
-
${
|
|
472
|
+
${rt(n)}
|
|
455
473
|
}
|
|
456
474
|
`);
|
|
457
475
|
return t.join(`
|
|
458
476
|
`);
|
|
459
477
|
}
|
|
460
|
-
function
|
|
461
|
-
const
|
|
478
|
+
function Pt(e = {}) {
|
|
479
|
+
const t = [];
|
|
480
|
+
return Object.entries(e).forEach(([s, n]) => {
|
|
481
|
+
t.push(
|
|
482
|
+
`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`
|
|
483
|
+
);
|
|
484
|
+
}), t;
|
|
485
|
+
}
|
|
486
|
+
function xt(e = {}) {
|
|
487
|
+
const t = [];
|
|
488
|
+
return Object.entries(e).forEach(([s, n]) => {
|
|
489
|
+
t.push(
|
|
490
|
+
`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`
|
|
491
|
+
);
|
|
492
|
+
}), t;
|
|
493
|
+
}
|
|
494
|
+
function Ot(e, t) {
|
|
495
|
+
const { dsl: s } = e, n = Object.keys(s.computed || {}), i = j(s.lifeCycles, n), r = j(s.computed, n), o = ut(s.watch, n), c = pt(s.dataSources), { methods: a, nodes: d, components: p, importBlocks: $ } = D(
|
|
462
496
|
s.nodes || [],
|
|
463
497
|
t,
|
|
464
|
-
|
|
498
|
+
n,
|
|
465
499
|
e.context
|
|
466
|
-
),
|
|
500
|
+
), P = [...r, ...o.computed], u = j(
|
|
467
501
|
{
|
|
468
|
-
...
|
|
502
|
+
...a,
|
|
469
503
|
...s.methods || {}
|
|
470
504
|
},
|
|
471
|
-
|
|
472
|
-
), x =
|
|
505
|
+
n
|
|
506
|
+
), x = $.map((g) => `import ${g.name} from './${g.id}.vue';`), f = wt(
|
|
473
507
|
t,
|
|
474
508
|
p,
|
|
475
509
|
x,
|
|
476
510
|
e.imports
|
|
477
|
-
)
|
|
511
|
+
), O = Object.keys({
|
|
512
|
+
...e.urlSchemas,
|
|
513
|
+
...e.blockPlugins
|
|
514
|
+
}), m = Pt(e.urlSchemas), b = xt(e.blockPlugins);
|
|
478
515
|
return {
|
|
479
516
|
id: s.id,
|
|
480
517
|
version: s.__VERSION__,
|
|
481
518
|
name: s.name,
|
|
482
|
-
state:
|
|
483
|
-
inject:
|
|
484
|
-
props:
|
|
485
|
-
emits:
|
|
519
|
+
state: it(s.state).join(","),
|
|
520
|
+
inject: ct(s.inject).join(","),
|
|
521
|
+
props: at(s.props).join(","),
|
|
522
|
+
emits: lt(s.emits).join(","),
|
|
486
523
|
watch: o.watches.join(","),
|
|
487
524
|
lifeCycles: i.join(","),
|
|
488
|
-
computed:
|
|
489
|
-
methods: [...
|
|
525
|
+
computed: P.join(","),
|
|
526
|
+
methods: [...c, ...u].join(","),
|
|
490
527
|
imports: f.join(`
|
|
491
528
|
`),
|
|
492
529
|
components: p.join(","),
|
|
@@ -494,10 +531,15 @@ function wt(e, t) {
|
|
|
494
531
|
template: d.join(`
|
|
495
532
|
`),
|
|
496
533
|
css: s.css || "",
|
|
497
|
-
style:
|
|
534
|
+
style: kt(e.style),
|
|
535
|
+
urlSchemas: m.join(`
|
|
536
|
+
`),
|
|
537
|
+
blockPlugins: b.join(`
|
|
538
|
+
`),
|
|
539
|
+
asyncComponents: O.join(",")
|
|
498
540
|
};
|
|
499
541
|
}
|
|
500
|
-
const
|
|
542
|
+
const Ct = `
|
|
501
543
|
<%= imports %>
|
|
502
544
|
import { useProvider } from '@vtj/renderer';
|
|
503
545
|
export default defineComponent({
|
|
@@ -511,11 +553,14 @@ export default defineComponent({
|
|
|
511
553
|
id: '<%= id %>',
|
|
512
554
|
version: '<%= version %>'
|
|
513
555
|
});
|
|
514
|
-
const state = reactive({ <%= state %> });
|
|
556
|
+
const state = reactive<Record<string, any>>({ <%= state %> });
|
|
557
|
+
<%= urlSchemas %>
|
|
558
|
+
<%= blockPlugins %>
|
|
515
559
|
return {
|
|
516
560
|
state,
|
|
517
561
|
props,
|
|
518
562
|
provider
|
|
563
|
+
<% if(asyncComponents) { %>, <%= asyncComponents %> <% }%>
|
|
519
564
|
<% if(returns) { %>, <%= returns %> <% } %>
|
|
520
565
|
};
|
|
521
566
|
},
|
|
@@ -523,7 +568,7 @@ export default defineComponent({
|
|
|
523
568
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
524
569
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
525
570
|
});
|
|
526
|
-
`.replace(/(\n|\r|\t)/g, ""),
|
|
571
|
+
`.replace(/(\n|\r|\t)/g, ""), Et = `
|
|
527
572
|
<template>
|
|
528
573
|
<%= template %>
|
|
529
574
|
</template>
|
|
@@ -534,17 +579,17 @@ export default defineComponent({
|
|
|
534
579
|
<%= css %>
|
|
535
580
|
<%= style %>
|
|
536
581
|
</style>
|
|
537
|
-
`,
|
|
538
|
-
async function
|
|
539
|
-
const i = new
|
|
540
|
-
template:
|
|
541
|
-
css: await W(
|
|
542
|
-
script: await
|
|
543
|
-
style: await W(
|
|
582
|
+
`, _t = J(Ct), At = J(Et);
|
|
583
|
+
async function Rt(e, t = /* @__PURE__ */ new Map(), s = [], n) {
|
|
584
|
+
const i = new ot(K(e), s), r = Ot(i, t), o = _t(r), c = At({
|
|
585
|
+
template: r.template,
|
|
586
|
+
css: await W(r.css, n),
|
|
587
|
+
script: await st(o, n),
|
|
588
|
+
style: await W(r.style, n)
|
|
544
589
|
});
|
|
545
|
-
return await V(
|
|
590
|
+
return await V(c, n);
|
|
546
591
|
}
|
|
547
|
-
async function
|
|
592
|
+
async function Wt(e) {
|
|
548
593
|
const t = `
|
|
549
594
|
<template>
|
|
550
595
|
<div>
|
|
@@ -560,7 +605,7 @@ async function At(e) {
|
|
|
560
605
|
return await V(t);
|
|
561
606
|
}
|
|
562
607
|
export {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
608
|
+
Bt as VTJ_CODER_VERSION,
|
|
609
|
+
Wt as createEmptyPage,
|
|
610
|
+
Rt as generator
|
|
566
611
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "vue-tsc && vite build",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"coverage": "vitest run --coverage"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@vtj/base": "^0.
|
|
14
|
-
"@vtj/core": "^0.
|
|
13
|
+
"@vtj/base": "^0.8.1",
|
|
14
|
+
"@vtj/core": "^0.8.1",
|
|
15
15
|
"prettier": "~3.2.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@vtj/cli": "^0.
|
|
18
|
+
"@vtj/cli": "^0.8.1"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"types"
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "56000d79e6dc07c9d86fda6ee8b746dca7bdcd93",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
}
|
package/types/collecter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockSchema, Dependencie } from '@vtj/core';
|
|
1
|
+
import { BlockSchema, Dependencie, NodeFromUrlSchema, NodeFromPlugin } from '@vtj/core';
|
|
2
2
|
|
|
3
3
|
export declare class Collecter {
|
|
4
4
|
dsl: BlockSchema;
|
|
@@ -10,6 +10,8 @@ export declare class Collecter {
|
|
|
10
10
|
context: Record<string, Set<string>>;
|
|
11
11
|
style: Record<string, Record<string, any>>;
|
|
12
12
|
members: string[];
|
|
13
|
+
urlSchemas: Record<string, NodeFromUrlSchema>;
|
|
14
|
+
blockPlugins: Record<string, NodeFromPlugin>;
|
|
13
15
|
private libraryRegex;
|
|
14
16
|
constructor(dsl: BlockSchema, dependencies: Dependencie[]);
|
|
15
17
|
private collectLibrary;
|
|
@@ -24,5 +26,7 @@ export declare class Collecter {
|
|
|
24
26
|
private getLibraryMember;
|
|
25
27
|
private collectContext;
|
|
26
28
|
private collectStyle;
|
|
29
|
+
private collectUrlSchema;
|
|
30
|
+
private collectBlockPlugin;
|
|
27
31
|
private walkNodes;
|
|
28
32
|
}
|
package/types/parser/index.d.ts
CHANGED
|
@@ -19,5 +19,8 @@ export interface Token {
|
|
|
19
19
|
template: string;
|
|
20
20
|
css: string;
|
|
21
21
|
style: string;
|
|
22
|
+
urlSchemas: string;
|
|
23
|
+
blockPlugins: string;
|
|
24
|
+
asyncComponents: string;
|
|
22
25
|
}
|
|
23
26
|
export declare function parser(collecter: Collecter, componentMap: Map<string, MaterialDescription>): Token;
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.
|
|
5
|
+
* @version 0.8.0
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.
|
|
8
|
+
export declare const version = "0.8.0";
|