@vtj/coder 0.9.1 → 0.9.3
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 +38 -34
- package/dist/index.mjs +407 -349
- package/package.json +3 -3
- package/types/parser/index.d.ts +1 -0
- package/types/parser/template.d.ts +5 -0
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@vtj/base"),A=require("prettier/standalone"),Y=require("prettier/plugins/html"),Z=require("prettier/plugins/babel"),K=require("prettier/plugins/postcss"),ee=require("prettier/plugins/estree");function _(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 te=_(Y),J=_(Z),q=_(K),L=_(ee);/**!
|
|
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.9.
|
|
5
|
+
* @version 0.9.3
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const
|
|
7
|
+
*/const se="0.9.3";/**!
|
|
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.9.
|
|
11
|
+
* @version 0.9.3
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
-
*/const
|
|
13
|
+
*/const ne=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const F={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 D(t,e){return e?t:await A.format(t,{parser:"vue",...F,plugins:[te,J,L,q]})}async function re(t,e){return e?t:await A.format(t,{parser:"babel-ts",...F,plugins:[J,L]})}async function T(t,e){return e?t:A.format(t,{parser:"scss",...F,plugins:[q]})}function S(t){return t&&t.type==="JSExpression"}function O(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function k(t){return S(t)||O(t)}function U(t){return t.replace(new RegExp("this.","g"),"")}function R(t){return t.replace(/this\.context\??\./g,"")}function p(t,e=!0,s=!0,n=[]){let i=k(t)?t.value:e?JSON.stringify(t):t;return i=x(i,n),s?U(R(i)):R(i)}function x(t,e=[]){let s=t;for(const n of e)s=s.replace(new RegExp(`this.${n}.value`,"g"),`this.${n}`);return s}function M(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 ie(t={}){return Object.entries(t).map(([e,s])=>`"${e}": ${p(s)}`)}function V(t={},e=!1){const s=Object.keys(t);return e?s.map(n=>"."+n):s}function oe(t){let e="";for(var s in t)if(t.hasOwnProperty(s)){var n=t[s];e+=s+": "+n+";"}return e}class ae{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(a=>a.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 a=this.collectImport(o);if(a){const u=a.path.replace(/\$/g,"\\$");n=n.replace(new RegExp(u,"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)k(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 f.dedupArray(s)}collectContext(e,s){const n=new Set(s?.id?this.context[s.id]:[]),i=(e.directives||[]).find(a=>a.name==="vFor");let r=new Set(Array.from(n));if(i){const{item:a="item",index:u="index"}=i.iterator||{};r=new Set([a,u,...Array.from(r)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],u=a.length?a:[`scope_${s?.id}`];r=new Set([...u,...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 ce(t={}){return Object.entries(t).map(([e,s])=>{const n=p(s,!1);return`${e}:${n}`})}function le(t=[]){return t.map(e=>`${e.name}: {
|
|
14
14
|
from: '${e.from||e.name}',
|
|
15
|
-
default: ${
|
|
16
|
-
}`)}function
|
|
17
|
-
type:${e(
|
|
18
|
-
required: ${
|
|
19
|
-
default: ${
|
|
20
|
-
}`))}function
|
|
21
|
-
deep: ${
|
|
22
|
-
immediate:${
|
|
23
|
-
handler${
|
|
24
|
-
}`);return{computed:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
`)
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
default: ${p(e.default,!0,!1)}
|
|
16
|
+
}`)}function ue(t=[]){const e=s=>s?`[${f.toArray(s).map(r=>r.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:(k(s.default)&&!s.default.value&&(s.default.value="undefined"),`${s.name}: {
|
|
17
|
+
type:${e(s.type)},
|
|
18
|
+
required: ${p(!!s.required,!0,!1)},
|
|
19
|
+
default: ${p(s.default,!0,!1)}
|
|
20
|
+
}`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function C(t={},e=[]){return Object.entries(t).map(([s,n])=>{let i=M(p(n,!1,!1));return i=x(i,e),i.startsWith("async")?`async ${s}${i.replace(/^async/,"")}`:`${s}${i}`})}function pe(t=[],e=[]){const s=t.reduce((r,o)=>(o.id&&O(o.source)&&(r[`watcher_${o.id}`]=o.source),r),{}),n=C(s,e),i=t.map(r=>`watcher_${r.id}: {
|
|
21
|
+
deep: ${r.deep},
|
|
22
|
+
immediate:${r.immediate},
|
|
23
|
+
handler${M(r.handler.value)}
|
|
24
|
+
}`);return{computed:n,watches:i}}function me(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const s=O(e.mockTemplate)&&e.mockTemplate.value||"(params) => ({})";return`async ${e.name}(...args:any[]) {
|
|
25
|
+
const mock = this.provider.createMock(${s})
|
|
26
|
+
return await mock.apply(this, args);
|
|
27
|
+
}`}else{const s=O(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
28
|
+
return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
|
|
29
|
+
}`}})}const W=["vIf","vShow","vModel","vFor","vBind","vHtml"];function H(t,e,s=[],n={},i){const r=[];let o={},a=[];const u=[];let c=[];return de(t).forEach(l=>{const m=[];for(const d of l.children){let{id:v,name:g,invisible:E,from:$}=d;if(E)continue;const w=ye(g,e,$);w&&a.push(w),Q($)&&c.push({id:$.id,name:g});const{props:j,events:I,handlers:X}=je(d,v,d.props,d.events,n,s),N=Se(d.directives,s,u).join(" "),b=d.children?we(d.children,s,e,n,d):"";Object.assign(o,X);let P="";typeof b=="string"?P=b:(P=(b?.nodes||[]).join(`
|
|
30
|
+
`),Object.assign(o,b?.methods||{}),a=a.concat(b?.components||[]),c=c.concat(b?.importBlocks||[]));const B=z($)||G($)?"component":g;m.push(g==="img"?`<${g} ${N} ${j} ${I} />`:`<${B} ${N} ${j} ${I}>${P?`
|
|
31
|
+
`+P.trim():""}</${B}>`)}const h=Pe(l.slot,m.join(`
|
|
32
|
+
`),i?.id);r.push(h)}),{nodes:r,methods:o,directives:he(u),components:f.dedupArray(a),importBlocks:f.dedupArray(c,"id")}}function he(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function de(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 ye(t,e,s){if(ne.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 Q(s)||n?t:null}function Q(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function z(t){return typeof t=="object"&&t.type==="UrlSchema"}function G(t){return typeof t=="object"&&t.type==="Plugin"}function ge(t,e,s=[]){return t==="style"?"":t==="__class"&&k(e)?`:class="${p({...e,value:x(e.value,s)})}"`:typeof e=="string"?`${t}="${e}"`:k(e)?`:${t}="${p({...e,value:x(e.value,s)})}"`:f.isPlainObject(e)?`:${t}='{${ie(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function $e(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(z(i)||G(i))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([r,o])=>ge(r,o,s))}function ve(t,e,s,n,i){const r=V(e.modifiers,!0);return i?`@${t}${r.join("")}="${s}"`:n&&n.length>0?`@${t}${r.join("")}="(...args:any[]) => ${s}"`:`@${t}${r.join("")}="${s}"`}function be(t,e={},s={}){const n={},i=Array.from(s[t]||new Set([])),r=i.length?`({${i.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,u])=>{const c=u.handler.value.startsWith("this."),y=c?U(u.handler.value):`${f.camelCase(a)}_${t}${r}`;return c||(n[y]=i.length?{type:"JSFunction",value:`{
|
|
33
|
+
return (${u.handler.value}).apply(this, args);
|
|
34
|
+
}`}:u.handler),ve(a,u,y,i,c)}),handlers:n}}function je(t,e,s={},n={},i={},r){const{binders:o,handlers:a}=be(e,n,i);return{props:$e(t,s,r).join(" "),handlers:a,binders:o,events:o.join(" ")}}function Se(t=[],e=[],s=[]){const n=[],{vIf:i,vShow:r,vModels:o,vFor:a,vBind:u,vHtml:c,customDirectives:y}=ke(t);if(i&&n.push(`v-if="${p(i.value,!0,!0,e)}"`),r&&n.push(`v-show="${p(r.value,!0,!0,e)}"`),u&&n.push(`v-bind="${p(u.value,!0,!0,e)}"`),o.forEach(l=>{const m=V(l.modifiers,!0),h=l.arg?S(l.arg)?`:[${p(l.arg,!0,!0,e)}]`:`:${l.arg}`:"";n.push(`v-model${h}${m}="${p(l.value,!0,!0,e)}"`)}),a){const{item:l,index:m}={item:"item",index:"index",...a.iterator};n.push(`v-for="(${l}, ${m}) in ${p(a.value,!0,!0,e)}"`)}return c&&n.push(`v-html="${p(c.value,!0,!0,e)}"`),y&&y.length&&y.forEach(l=>{if(!l.name)return;let m="",h="";S(l.name)?(h=p(l.name,!0,!0,e),s.push(h)):h=l.name;const d=h?.startsWith("v")?f.kebabCase(h):f.kebabCase("v-"+h);if(m+=d,l.arg&&(S(l.arg)?m+=`:[${p(l.name,!0,!0,e)}]`:m+=`:${l.arg}`),l.modifiers){const v=Object.keys(l.modifiers);v.length&&(m+=v.map(g=>"."+g))}l.value?n.push(`${m}="${p(l.value,!0,!0,e)}"`):n.push(m)}),n}function ke(t=[]){const e=t.filter(c=>W.includes(c.name)),s=t.filter(c=>!W.includes(c.name)),n=e.find(c=>f.camelCase(c.name)==="vIf"),i=e.find(c=>f.camelCase(c.name)==="vFor"),r=e.find(c=>f.camelCase(c.name)==="vShow"),o=e.find(c=>f.camelCase(c.name)==="vBind"),a=e.find(c=>f.camelCase(c.name)==="vHtml"),u=e.filter(c=>f.camelCase(c.name)==="vModel");return{vIf:n,vFor:i,vShow:r,vModels:u,vBind:o,vHtml:a,customDirectives:s}}function we(t,e,s,n,i){return typeof t=="string"?t:S(t)?`{{ ${p(t,!1,!0,e)} }}`:Array.isArray(t)?H(t,s,e,n,i):""}function Pe(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}`}"`}>
|
|
32
35
|
${e}
|
|
33
|
-
</template>`}function
|
|
34
|
-
${
|
|
35
|
-
${
|
|
36
|
+
</template>`}function Ce(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 { ${f.dedupArray(o).join(",")}} from '${r}';`).concat(s)}function Oe(t={}){const e=[];for(const[s,n]of Object.entries(t))e.push(`
|
|
37
|
+
${s} {
|
|
38
|
+
${oe(n)}
|
|
36
39
|
}
|
|
37
40
|
`);return e.join(`
|
|
38
|
-
`)}function
|
|
39
|
-
`+
|
|
40
|
-
`),components:
|
|
41
|
-
`),css:
|
|
42
|
-
`),blockPlugins:
|
|
43
|
-
`),asyncComponents:
|
|
41
|
+
`)}function xe(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`)}),e}function _e(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`)}),e}function Ee(t,e){const{dsl:s}=t,n=Object.keys(s.computed||{}),i=C(s.lifeCycles,n),r=C(s.computed,n),o=pe(s.watch,n),a=me(s.dataSources),{methods:u,nodes:c,components:y,importBlocks:l,directives:m}=H(s.nodes||[],e,n,t.context),h=[...r,...o.computed],d=C({...u,...s.methods||{}},n),v=l.map(j=>`import ${j.name} from './${j.id}.vue';`),g=Ce(e,y,v,t.imports),E=Object.keys({...t.urlSchemas,...t.blockPlugins}),$=xe(t.urlSchemas),w=_e(t.blockPlugins);return{id:s.id,version:s.__VERSION__,name:s.name,state:ce(s.state).join(","),inject:le(s.inject).join(","),props:ue(s.props).join(","),emits:fe(s.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:h.join(","),methods:[...a,...d].join(","),imports:`
|
|
42
|
+
`+g.join(`
|
|
43
|
+
`),components:y.join(","),directives:m.join(","),returns:t.members.join(","),template:c.join(`
|
|
44
|
+
`),css:s.css||"",style:Oe(t.style),urlSchemas:$.join(`
|
|
45
|
+
`),blockPlugins:w.join(`
|
|
46
|
+
`),asyncComponents:E.join(",")}}const Ae=`
|
|
44
47
|
// @ts-nocheck
|
|
45
48
|
|
|
46
49
|
<%= imports %>
|
|
@@ -49,6 +52,7 @@ export default defineComponent({
|
|
|
49
52
|
name: '<%= name %>',
|
|
50
53
|
<% if(inject) { %> inject: { <%= inject %>}, <% } %>
|
|
51
54
|
<% if(components) { %> components: { <%= components %> }, <% } %>
|
|
55
|
+
<% if(directives) { %> directives: { <%= directives %> }, <% } %>
|
|
52
56
|
<% if(props) { %> props: { <%= props %> }, <% } %>
|
|
53
57
|
<% if(emits) {%> emits: [<%= emits %>], <% } %>
|
|
54
58
|
setup(props) {
|
|
@@ -71,7 +75,7 @@ export default defineComponent({
|
|
|
71
75
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
72
76
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
73
77
|
});
|
|
74
|
-
`.replace(/(\n|\r|\t)/g,""),
|
|
78
|
+
`.replace(/(\n|\r|\t)/g,""),Fe=`
|
|
75
79
|
<template>
|
|
76
80
|
<%= template %>
|
|
77
81
|
</template>
|
|
@@ -82,7 +86,7 @@ export default defineComponent({
|
|
|
82
86
|
<%= css %>
|
|
83
87
|
<%= style %>
|
|
84
88
|
</style>
|
|
85
|
-
`,
|
|
89
|
+
`,Ie=f.template(Ae),Ne=f.template(Fe);async function Be(t,e=new Map,s=[],n){const i=new ae(f.cloneDeep(t),s),r=Ee(i,e),o=Ie(r),a=Ne({template:r.template,css:await T(r.css,n),script:await re(o,n),style:await T(r.style,n)});return await D(a,n).catch(u=>(u.content=a,Promise.reject(u)))}async function Te(t){const e=`
|
|
86
90
|
<template>
|
|
87
91
|
<div>
|
|
88
92
|
<h3>源码模式页面</h3>
|
|
@@ -93,4 +97,4 @@ export default defineComponent({
|
|
|
93
97
|
<\/script>
|
|
94
98
|
<style scoped lang="scss">
|
|
95
99
|
</style>
|
|
96
|
-
`;return await
|
|
100
|
+
`;return await D(e)}exports.VTJ_CODER_VERSION=se;exports.createEmptyPage=Te;exports.generator=Be;
|
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 K, dedupArray as k, toArray as ee, kebabCase as R, camelCase as $, isPlainObject as te, template as L, cloneDeep as se } from "@vtj/base";
|
|
2
|
+
import { format as A } from "prettier/standalone";
|
|
3
|
+
import * as ne from "prettier/plugins/html";
|
|
4
|
+
import * as U from "prettier/plugins/babel";
|
|
5
|
+
import * as D from "prettier/plugins/postcss";
|
|
6
|
+
import * as V 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.9.
|
|
11
|
+
* @version 0.9.3
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const We = "0.9.3";
|
|
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.9.
|
|
19
|
+
* @version 0.9.3
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
22
|
+
const re = [
|
|
23
23
|
"slot",
|
|
24
24
|
"template",
|
|
25
25
|
"component",
|
|
@@ -32,8 +32,8 @@ const et = [
|
|
|
32
32
|
"span",
|
|
33
33
|
"a"
|
|
34
34
|
];
|
|
35
|
-
|
|
36
|
-
const
|
|
35
|
+
K();
|
|
36
|
+
const F = {
|
|
37
37
|
arrowParens: "always",
|
|
38
38
|
bracketSpacing: !0,
|
|
39
39
|
bracketSameLine: !0,
|
|
@@ -53,87 +53,87 @@ const E = {
|
|
|
53
53
|
useTabs: !1,
|
|
54
54
|
vueIndentScriptAndStyle: !0
|
|
55
55
|
};
|
|
56
|
-
async function
|
|
57
|
-
return
|
|
56
|
+
async function M(t, e) {
|
|
57
|
+
return e ? t : await A(t, {
|
|
58
58
|
parser: "vue",
|
|
59
|
-
...
|
|
60
|
-
plugins: [
|
|
59
|
+
...F,
|
|
60
|
+
plugins: [ne, U, V, D]
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
async function
|
|
64
|
-
return
|
|
63
|
+
async function ie(t, e) {
|
|
64
|
+
return e ? t : await A(t, {
|
|
65
65
|
parser: "babel-ts",
|
|
66
|
-
...
|
|
67
|
-
plugins: [
|
|
66
|
+
...F,
|
|
67
|
+
plugins: [U, V]
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
async function
|
|
71
|
-
return
|
|
70
|
+
async function T(t, e) {
|
|
71
|
+
return e ? t : A(t, {
|
|
72
72
|
parser: "scss",
|
|
73
|
-
...
|
|
74
|
-
plugins: [
|
|
73
|
+
...F,
|
|
74
|
+
plugins: [D]
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
77
|
+
function S(t) {
|
|
78
|
+
return t && t.type === "JSExpression";
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
return typeof
|
|
80
|
+
function O(t) {
|
|
81
|
+
return typeof t == "object" && t && t.type === "JSFunction";
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
83
|
+
function w(t) {
|
|
84
|
+
return S(t) || O(t);
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
return
|
|
86
|
+
function q(t) {
|
|
87
|
+
return t.replace(new RegExp("this.", "g"), "");
|
|
88
88
|
}
|
|
89
|
-
function W(
|
|
90
|
-
return
|
|
89
|
+
function W(t) {
|
|
90
|
+
return t.replace(/this\.context\??\./g, "");
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
let i =
|
|
94
|
-
return i =
|
|
92
|
+
function f(t, e = !0, s = !0, n = []) {
|
|
93
|
+
let i = w(t) ? t.value : e ? JSON.stringify(t) : t;
|
|
94
|
+
return i = E(i, n), s ? q(W(i)) : W(i);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
let
|
|
98
|
-
for (const
|
|
99
|
-
|
|
100
|
-
new RegExp(`this.${
|
|
101
|
-
`this.${
|
|
96
|
+
function E(t, e = []) {
|
|
97
|
+
let s = t;
|
|
98
|
+
for (const n of e)
|
|
99
|
+
s = s.replace(
|
|
100
|
+
new RegExp(`this.${n}.value`, "g"),
|
|
101
|
+
`this.${n}`
|
|
102
102
|
);
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
function
|
|
106
|
-
let
|
|
107
|
-
if (
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
else if (
|
|
111
|
-
|
|
103
|
+
return s;
|
|
104
|
+
}
|
|
105
|
+
function H(t) {
|
|
106
|
+
let e = t.trim();
|
|
107
|
+
if (e = /^\((\(|async|function)/.test(e) ? e.substring(1, e.length - 1) : e, e.startsWith("{")) return e;
|
|
108
|
+
if (e.startsWith("async function"))
|
|
109
|
+
e = e.replace(/^async function/, "async");
|
|
110
|
+
else if (e.startsWith("function"))
|
|
111
|
+
e = e.replace(/^function/, "");
|
|
112
112
|
else {
|
|
113
|
-
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/, r =
|
|
114
|
-
r && r[2] && (r[2].startsWith("{") || (
|
|
113
|
+
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/, r = e.match(i);
|
|
114
|
+
r && r[2] && (r[2].startsWith("{") || (e = e.replace(r[2], `{ return ${r[2]} }`))), e = e.replace("=>", "");
|
|
115
115
|
}
|
|
116
|
-
return
|
|
116
|
+
return e;
|
|
117
117
|
}
|
|
118
|
-
function
|
|
119
|
-
return Object.entries(
|
|
118
|
+
function oe(t = {}) {
|
|
119
|
+
return Object.entries(t).map(([e, s]) => `"${e}": ${f(s)}`);
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
const
|
|
123
|
-
return
|
|
121
|
+
function Q(t = {}, e = !1) {
|
|
122
|
+
const s = Object.keys(t);
|
|
123
|
+
return e ? s.map((n) => "." + n) : s;
|
|
124
124
|
}
|
|
125
|
-
function
|
|
126
|
-
let
|
|
127
|
-
for (var
|
|
128
|
-
if (
|
|
129
|
-
var
|
|
130
|
-
|
|
125
|
+
function ce(t) {
|
|
126
|
+
let e = "";
|
|
127
|
+
for (var s in t)
|
|
128
|
+
if (t.hasOwnProperty(s)) {
|
|
129
|
+
var n = t[s];
|
|
130
|
+
e += s + ": " + n + ";";
|
|
131
131
|
}
|
|
132
|
-
return
|
|
132
|
+
return e;
|
|
133
133
|
}
|
|
134
|
-
class
|
|
135
|
-
constructor(
|
|
136
|
-
this.dsl =
|
|
134
|
+
class ae {
|
|
135
|
+
constructor(e, s) {
|
|
136
|
+
this.dsl = e, this.dependencies = s, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* { 'element-plus': ['ElButton', 'ElInput' ...] }
|
|
@@ -146,25 +146,25 @@ class it {
|
|
|
146
146
|
blockPlugins = {};
|
|
147
147
|
libraryRegex = [];
|
|
148
148
|
collectLibrary() {
|
|
149
|
-
return this.dependencies.filter((
|
|
149
|
+
return this.dependencies.filter((e) => !!e.library).map((e) => new RegExp(`(this.\\$libs.${e.library}.([\\w]+))`, "g"));
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* 收集 import 信息
|
|
153
153
|
* @param regexMatchItem ex: this.$libs.ElementPlus.ElButton
|
|
154
154
|
* @returns ex: { name: 'ElButton', path: 'this.$libs.ElementPlus.', library: 'ElementPlus' }
|
|
155
155
|
*/
|
|
156
|
-
collectImport(
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
156
|
+
collectImport(e) {
|
|
157
|
+
const s = e.split(".");
|
|
158
|
+
if (s.length === 4) {
|
|
159
|
+
const n = s.pop(), i = s.join(".") + ".", r = s.pop();
|
|
160
|
+
if (n && r) {
|
|
161
161
|
const o = this.dependencies.find(
|
|
162
162
|
(c) => c.library === r
|
|
163
163
|
)?.package;
|
|
164
|
-
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(
|
|
164
|
+
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(n);
|
|
165
165
|
}
|
|
166
166
|
return {
|
|
167
|
-
name:
|
|
167
|
+
name: n,
|
|
168
168
|
path: i,
|
|
169
169
|
library: r
|
|
170
170
|
};
|
|
@@ -172,375 +172,432 @@ class it {
|
|
|
172
172
|
return null;
|
|
173
173
|
}
|
|
174
174
|
// 代码中包含依赖库的引用,需要从代码中移除
|
|
175
|
-
replaceLibraryPath(
|
|
176
|
-
const { libraryRegex:
|
|
177
|
-
let
|
|
178
|
-
for (const i of
|
|
179
|
-
const r =
|
|
175
|
+
replaceLibraryPath(e) {
|
|
176
|
+
const { libraryRegex: s } = this;
|
|
177
|
+
let n = e.value;
|
|
178
|
+
for (const i of s) {
|
|
179
|
+
const r = e.value?.match(i) || [];
|
|
180
180
|
for (const o of r) {
|
|
181
181
|
const c = this.collectImport(o);
|
|
182
182
|
if (c) {
|
|
183
|
-
const
|
|
184
|
-
|
|
183
|
+
const u = c.path.replace(/\$/g, "\\$");
|
|
184
|
+
n = n.replace(new RegExp(u, "g"), "");
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
-
return
|
|
188
|
+
return n;
|
|
189
189
|
}
|
|
190
|
-
walk(
|
|
191
|
-
const
|
|
192
|
-
if (!
|
|
193
|
-
if (Array.isArray(
|
|
194
|
-
for (let r of
|
|
195
|
-
|
|
190
|
+
walk(e) {
|
|
191
|
+
const s = (n) => {
|
|
192
|
+
if (!n || typeof n != "object") return;
|
|
193
|
+
if (Array.isArray(n)) {
|
|
194
|
+
for (let r of n)
|
|
195
|
+
s(r);
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
198
|
-
const i = Object.values(
|
|
198
|
+
const i = Object.values(n);
|
|
199
199
|
for (const r of i)
|
|
200
|
-
|
|
200
|
+
w(r) ? r.value = this.replaceLibraryPath(r) : s(r);
|
|
201
201
|
};
|
|
202
|
-
|
|
202
|
+
s(e);
|
|
203
203
|
}
|
|
204
|
-
getLibraryMember(
|
|
205
|
-
let
|
|
206
|
-
for (const
|
|
207
|
-
|
|
208
|
-
return
|
|
204
|
+
getLibraryMember(e = []) {
|
|
205
|
+
let s = [...e];
|
|
206
|
+
for (const n of Object.values(this.imports))
|
|
207
|
+
s = s.concat(Array.from(n));
|
|
208
|
+
return k(s);
|
|
209
209
|
}
|
|
210
|
-
collectContext(
|
|
211
|
-
const
|
|
212
|
-
let r = new Set(Array.from(
|
|
210
|
+
collectContext(e, s) {
|
|
211
|
+
const n = new Set(s?.id ? this.context[s.id] : []), i = (e.directives || []).find((c) => c.name === "vFor");
|
|
212
|
+
let r = new Set(Array.from(n));
|
|
213
213
|
if (i) {
|
|
214
|
-
const { item: c = "item", index:
|
|
215
|
-
r = /* @__PURE__ */ new Set([c,
|
|
214
|
+
const { item: c = "item", index: u = "index" } = i.iterator || {};
|
|
215
|
+
r = /* @__PURE__ */ new Set([c, u, ...Array.from(r)]);
|
|
216
216
|
}
|
|
217
|
-
const o =
|
|
217
|
+
const o = e.slot;
|
|
218
218
|
if (o) {
|
|
219
|
-
const c = typeof o == "string" ? [] : o.params || [],
|
|
220
|
-
r = /* @__PURE__ */ new Set([...
|
|
219
|
+
const c = typeof o == "string" ? [] : o.params || [], u = c.length ? c : [`scope_${s?.id}`];
|
|
220
|
+
r = /* @__PURE__ */ new Set([...u, ...Array.from(r)]);
|
|
221
221
|
}
|
|
222
|
-
this.context[
|
|
222
|
+
this.context[e.id] = r;
|
|
223
223
|
}
|
|
224
|
-
collectStyle(
|
|
225
|
-
|
|
224
|
+
collectStyle(e) {
|
|
225
|
+
e.id && e.props?.style && Object.keys(e.props.style).length && (this.style[`.${e.name}_${e.id}`] = e.props.style);
|
|
226
226
|
}
|
|
227
|
-
collectUrlSchema(
|
|
228
|
-
typeof
|
|
227
|
+
collectUrlSchema(e) {
|
|
228
|
+
typeof e.from == "object" && e.from.type === "UrlSchema" && (this.urlSchemas[e.name] = e.from);
|
|
229
229
|
}
|
|
230
|
-
collectBlockPlugin(
|
|
231
|
-
typeof
|
|
230
|
+
collectBlockPlugin(e) {
|
|
231
|
+
typeof e.from == "object" && e.from.type === "Plugin" && (this.blockPlugins[e.name] = e.from);
|
|
232
232
|
}
|
|
233
|
-
walkNodes(
|
|
234
|
-
const
|
|
235
|
-
this.collectContext(
|
|
233
|
+
walkNodes(e) {
|
|
234
|
+
const s = (n, i) => {
|
|
235
|
+
this.collectContext(n, i), this.collectStyle(n), this.collectUrlSchema(n), this.collectBlockPlugin(n), Array.isArray(n.children) && n.children.forEach((r) => s(r, n));
|
|
236
236
|
};
|
|
237
|
-
Array.isArray(
|
|
237
|
+
Array.isArray(e.nodes) && e.nodes.forEach((n) => s(n));
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
function
|
|
241
|
-
return Object.entries(
|
|
242
|
-
const
|
|
243
|
-
return `${
|
|
240
|
+
function le(t = {}) {
|
|
241
|
+
return Object.entries(t).map(([e, s]) => {
|
|
242
|
+
const n = f(s, !1);
|
|
243
|
+
return `${e}:${n}`;
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
|
-
function
|
|
247
|
-
return
|
|
248
|
-
from: '${
|
|
249
|
-
default: ${
|
|
246
|
+
function ue(t = []) {
|
|
247
|
+
return t.map((e) => `${e.name}: {
|
|
248
|
+
from: '${e.from || e.name}',
|
|
249
|
+
default: ${f(e.default, !0, !1)}
|
|
250
250
|
}`);
|
|
251
251
|
}
|
|
252
|
-
function
|
|
253
|
-
const
|
|
254
|
-
return
|
|
255
|
-
type:${
|
|
256
|
-
required: ${
|
|
257
|
-
default: ${
|
|
252
|
+
function fe(t = []) {
|
|
253
|
+
const e = (s) => s ? `[${ee(s).map((r) => r.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
254
|
+
return t.map((s) => typeof s == "string" ? `${s}: {}` : (w(s.default) && !s.default.value && (s.default.value = "undefined"), `${s.name}: {
|
|
255
|
+
type:${e(s.type)},
|
|
256
|
+
required: ${f(!!s.required, !0, !1)},
|
|
257
|
+
default: ${f(s.default, !0, !1)}
|
|
258
258
|
}`));
|
|
259
259
|
}
|
|
260
|
-
function
|
|
261
|
-
return
|
|
260
|
+
function pe(t = []) {
|
|
261
|
+
return t.map((e) => `'${typeof e == "string" ? e : e.name}'`);
|
|
262
262
|
}
|
|
263
|
-
function
|
|
264
|
-
return Object.entries(
|
|
265
|
-
let i =
|
|
266
|
-
return i =
|
|
263
|
+
function C(t = {}, e = []) {
|
|
264
|
+
return Object.entries(t).map(([s, n]) => {
|
|
265
|
+
let i = H(f(n, !1, !1));
|
|
266
|
+
return i = E(i, e), i.startsWith("async") ? `async ${s}${i.replace(/^async/, "")}` : `${s}${i}`;
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
const
|
|
271
|
-
(r, o) => (o.id &&
|
|
269
|
+
function me(t = [], e = []) {
|
|
270
|
+
const s = t.reduce(
|
|
271
|
+
(r, o) => (o.id && O(o.source) && (r[`watcher_${o.id}`] = o.source), r),
|
|
272
272
|
{}
|
|
273
|
-
),
|
|
273
|
+
), n = C(s, e), i = t.map((r) => `watcher_${r.id}: {
|
|
274
274
|
deep: ${r.deep},
|
|
275
275
|
immediate:${r.immediate},
|
|
276
|
-
handler${
|
|
276
|
+
handler${H(r.handler.value)}
|
|
277
277
|
}`);
|
|
278
278
|
return {
|
|
279
|
-
computed:
|
|
279
|
+
computed: n,
|
|
280
280
|
watches: i
|
|
281
281
|
};
|
|
282
282
|
}
|
|
283
|
-
function
|
|
284
|
-
return Object.values(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
283
|
+
function he(t = {}) {
|
|
284
|
+
return Object.values(t).map((e) => {
|
|
285
|
+
if (e.type === "mock") {
|
|
286
|
+
const s = O(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
|
|
287
|
+
return `async ${e.name}(...args:any[]) {
|
|
288
|
+
const mock = this.provider.createMock(${s})
|
|
289
|
+
return await mock.apply(this, args);
|
|
290
|
+
}`;
|
|
291
|
+
} else {
|
|
292
|
+
const s = O(e.transform) && e.transform.value || "(res) => res";
|
|
293
|
+
return `async ${e.name}(...args:any[]) {
|
|
294
|
+
return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
|
|
288
295
|
}`;
|
|
296
|
+
}
|
|
289
297
|
});
|
|
290
298
|
}
|
|
291
|
-
|
|
299
|
+
const J = [
|
|
300
|
+
"vIf",
|
|
301
|
+
"vShow",
|
|
302
|
+
"vModel",
|
|
303
|
+
"vFor",
|
|
304
|
+
"vBind",
|
|
305
|
+
"vHtml"
|
|
306
|
+
];
|
|
307
|
+
function z(t, e, s = [], n = {}, i) {
|
|
292
308
|
const r = [];
|
|
293
|
-
let o = {}, c = []
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
309
|
+
let o = {}, c = [];
|
|
310
|
+
const u = [];
|
|
311
|
+
let a = [];
|
|
312
|
+
return ye(t).forEach((l) => {
|
|
313
|
+
const p = [];
|
|
314
|
+
for (const h of l.children) {
|
|
315
|
+
let { id: v, name: y, invisible: _, from: g } = h;
|
|
316
|
+
if (_)
|
|
299
317
|
continue;
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
const { props:
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
s,
|
|
308
|
-
n
|
|
309
|
-
), N = vt(f.directives, n).join(
|
|
310
|
-
" "
|
|
311
|
-
), d = f.children ? jt(
|
|
312
|
-
f.children,
|
|
318
|
+
const P = ge(y, e, g);
|
|
319
|
+
P && c.push(P), G(g) && a.push({ id: g.id, name: y });
|
|
320
|
+
const { props: j, events: I, handlers: Z } = Se(
|
|
321
|
+
h,
|
|
322
|
+
v,
|
|
323
|
+
h.props,
|
|
324
|
+
h.events,
|
|
313
325
|
n,
|
|
314
|
-
|
|
326
|
+
s
|
|
327
|
+
), B = ke(
|
|
328
|
+
h.directives,
|
|
329
|
+
s,
|
|
330
|
+
u
|
|
331
|
+
).join(" "), b = h.children ? Pe(
|
|
332
|
+
h.children,
|
|
315
333
|
s,
|
|
316
|
-
|
|
334
|
+
e,
|
|
335
|
+
n,
|
|
336
|
+
h
|
|
317
337
|
) : "";
|
|
318
|
-
Object.assign(o,
|
|
319
|
-
let
|
|
320
|
-
typeof
|
|
321
|
-
`), Object.assign(o,
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
` +
|
|
338
|
+
Object.assign(o, Z);
|
|
339
|
+
let x = "";
|
|
340
|
+
typeof b == "string" ? x = b : (x = (b?.nodes || []).join(`
|
|
341
|
+
`), Object.assign(o, b?.methods || {}), c = c.concat(b?.components || []), a = a.concat(b?.importBlocks || []));
|
|
342
|
+
const N = X(g) || Y(g) ? "component" : y;
|
|
343
|
+
p.push(
|
|
344
|
+
y === "img" ? `<${y} ${B} ${j} ${I} />` : `<${N} ${B} ${j} ${I}>${x ? `
|
|
345
|
+
` + x.trim() : ""}</${N}>`
|
|
326
346
|
);
|
|
327
347
|
}
|
|
328
|
-
const
|
|
348
|
+
const m = xe(l.slot, p.join(`
|
|
329
349
|
`), i?.id);
|
|
330
|
-
r.push(
|
|
350
|
+
r.push(m);
|
|
331
351
|
}), {
|
|
332
352
|
nodes: r,
|
|
333
353
|
methods: o,
|
|
334
|
-
|
|
335
|
-
|
|
354
|
+
directives: de(u),
|
|
355
|
+
components: k(c),
|
|
356
|
+
importBlocks: k(a, "id")
|
|
336
357
|
};
|
|
337
358
|
}
|
|
338
|
-
function
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
359
|
+
function de(t) {
|
|
360
|
+
return k(t).map((e) => `${e.startsWith("v") ? e.substring(1) : e}:${e}`);
|
|
361
|
+
}
|
|
362
|
+
function ye(t = []) {
|
|
363
|
+
const e = /* @__PURE__ */ new Map();
|
|
364
|
+
for (const s of t) {
|
|
365
|
+
const n = typeof s.slot == "string" ? s.slot : s.slot?.name, i = e.get(n);
|
|
366
|
+
i ? i.children.push(s) : e.set(n, { slot: s.slot, children: [s] });
|
|
343
367
|
}
|
|
344
|
-
return
|
|
345
|
-
}
|
|
346
|
-
function
|
|
347
|
-
if (
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
const i =
|
|
351
|
-
return `${
|
|
368
|
+
return e;
|
|
369
|
+
}
|
|
370
|
+
function ge(t, e, s) {
|
|
371
|
+
if (re.includes(t)) return null;
|
|
372
|
+
const n = e.get(t);
|
|
373
|
+
if (n && n.alias) {
|
|
374
|
+
const i = n.parent ? `${n.parent}.${n.alias}` : n.alias;
|
|
375
|
+
return `${t}: ${i}`;
|
|
352
376
|
}
|
|
353
|
-
return
|
|
354
|
-
}
|
|
355
|
-
function
|
|
356
|
-
return !!
|
|
357
|
-
}
|
|
358
|
-
function
|
|
359
|
-
return typeof
|
|
360
|
-
}
|
|
361
|
-
function
|
|
362
|
-
return typeof
|
|
363
|
-
}
|
|
364
|
-
function
|
|
365
|
-
return
|
|
366
|
-
...
|
|
367
|
-
value:
|
|
368
|
-
})}"` : typeof
|
|
369
|
-
...
|
|
370
|
-
value:
|
|
371
|
-
})}"` :
|
|
372
|
-
|
|
373
|
-
).join(", ")}}'` : `:${
|
|
374
|
-
}
|
|
375
|
-
function
|
|
376
|
-
if (!!Object.keys(
|
|
377
|
-
const r = `${
|
|
378
|
-
|
|
377
|
+
return G(s) || n ? t : null;
|
|
378
|
+
}
|
|
379
|
+
function G(t) {
|
|
380
|
+
return !!t && typeof t == "object" && t.type === "Schema";
|
|
381
|
+
}
|
|
382
|
+
function X(t) {
|
|
383
|
+
return typeof t == "object" && t.type === "UrlSchema";
|
|
384
|
+
}
|
|
385
|
+
function Y(t) {
|
|
386
|
+
return typeof t == "object" && t.type === "Plugin";
|
|
387
|
+
}
|
|
388
|
+
function $e(t, e, s = []) {
|
|
389
|
+
return t === "style" ? "" : t === "__class" && w(e) ? `:class="${f({
|
|
390
|
+
...e,
|
|
391
|
+
value: E(e.value, s)
|
|
392
|
+
})}"` : typeof e == "string" ? `${t}="${e}"` : w(e) ? `:${t}="${f({
|
|
393
|
+
...e,
|
|
394
|
+
value: E(e.value, s)
|
|
395
|
+
})}"` : te(e) ? `:${t}='{${oe(
|
|
396
|
+
e
|
|
397
|
+
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
398
|
+
}
|
|
399
|
+
function ve(t, e = {}, s = []) {
|
|
400
|
+
if (!!Object.keys(e.style || {}).length) {
|
|
401
|
+
const r = `${t.name}_${t.id}`;
|
|
402
|
+
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);
|
|
379
403
|
}
|
|
380
|
-
const i =
|
|
381
|
-
return (
|
|
404
|
+
const i = t.from;
|
|
405
|
+
return (X(i) || Y(i)) && (e.is = {
|
|
382
406
|
type: "JSExpression",
|
|
383
|
-
value:
|
|
384
|
-
}), Object.entries(
|
|
407
|
+
value: t.name
|
|
408
|
+
}), Object.entries(e).map(([r, o]) => $e(r, o, s));
|
|
385
409
|
}
|
|
386
|
-
function
|
|
387
|
-
const r =
|
|
388
|
-
return i ? `@${
|
|
410
|
+
function be(t, e, s, n, i) {
|
|
411
|
+
const r = Q(e.modifiers, !0);
|
|
412
|
+
return i ? `@${t}${r.join("")}="${s}"` : n && n.length > 0 ? `@${t}${r.join("")}="(...args:any[]) => ${s}"` : `@${t}${r.join("")}="${s}"`;
|
|
389
413
|
}
|
|
390
|
-
function
|
|
391
|
-
const
|
|
414
|
+
function je(t, e = {}, s = {}) {
|
|
415
|
+
const n = {}, i = Array.from(s[t] || /* @__PURE__ */ new Set([])), r = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
392
416
|
return {
|
|
393
|
-
binders: Object.entries(
|
|
394
|
-
const
|
|
395
|
-
return
|
|
417
|
+
binders: Object.entries(e).map(([c, u]) => {
|
|
418
|
+
const a = u.handler.value.startsWith("this."), d = a ? q(u.handler.value) : `${$(c)}_${t}${r}`;
|
|
419
|
+
return a || (n[d] = i.length ? {
|
|
396
420
|
type: "JSFunction",
|
|
397
421
|
value: `{
|
|
398
|
-
return (${
|
|
422
|
+
return (${u.handler.value}).apply(this, args);
|
|
399
423
|
}`
|
|
400
|
-
} :
|
|
424
|
+
} : u.handler), be(c, u, d, i, a);
|
|
401
425
|
}),
|
|
402
|
-
handlers:
|
|
426
|
+
handlers: n
|
|
403
427
|
};
|
|
404
428
|
}
|
|
405
|
-
function
|
|
406
|
-
const { binders: o, handlers: c } =
|
|
429
|
+
function Se(t, e, s = {}, n = {}, i = {}, r) {
|
|
430
|
+
const { binders: o, handlers: c } = je(e, n, i);
|
|
407
431
|
return {
|
|
408
|
-
props:
|
|
432
|
+
props: ve(t, s, r).join(" "),
|
|
409
433
|
handlers: c,
|
|
410
434
|
binders: o,
|
|
411
435
|
events: o.join(" ")
|
|
412
436
|
};
|
|
413
437
|
}
|
|
414
|
-
function
|
|
415
|
-
const n = [], { vIf:
|
|
416
|
-
if (
|
|
417
|
-
`v-show="${
|
|
418
|
-
),
|
|
419
|
-
`v-bind="${
|
|
420
|
-
),
|
|
421
|
-
const
|
|
438
|
+
function ke(t = [], e = [], s = []) {
|
|
439
|
+
const n = [], { vIf: i, vShow: r, vModels: o, vFor: c, vBind: u, vHtml: a, customDirectives: d } = we(t);
|
|
440
|
+
if (i && n.push(`v-if="${f(i.value, !0, !0, e)}"`), r && n.push(
|
|
441
|
+
`v-show="${f(r.value, !0, !0, e)}"`
|
|
442
|
+
), u && n.push(
|
|
443
|
+
`v-bind="${f(u.value, !0, !0, e)}"`
|
|
444
|
+
), o.forEach((l) => {
|
|
445
|
+
const p = Q(l.modifiers, !0), m = l.arg ? S(l.arg) ? `:[${f(l.arg, !0, !0, e)}]` : `:${l.arg}` : "";
|
|
422
446
|
n.push(
|
|
423
|
-
`v-model${
|
|
447
|
+
`v-model${m}${p}="${f(l.value, !0, !0, e)}"`
|
|
424
448
|
);
|
|
425
|
-
}),
|
|
426
|
-
const { item:
|
|
449
|
+
}), c) {
|
|
450
|
+
const { item: l, index: p } = { item: "item", index: "index", ...c.iterator };
|
|
427
451
|
n.push(
|
|
428
|
-
`v-for="(${
|
|
452
|
+
`v-for="(${l}, ${p}) in ${f(c.value, !0, !0, e)}"`
|
|
429
453
|
);
|
|
430
454
|
}
|
|
431
|
-
return n
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
455
|
+
return a && n.push(
|
|
456
|
+
`v-html="${f(a.value, !0, !0, e)}"`
|
|
457
|
+
), d && d.length && d.forEach((l) => {
|
|
458
|
+
if (!l.name) return;
|
|
459
|
+
let p = "", m = "";
|
|
460
|
+
S(l.name) ? (m = f(l.name, !0, !0, e), s.push(m)) : m = l.name;
|
|
461
|
+
const h = m?.startsWith("v") ? R(m) : R("v-" + m);
|
|
462
|
+
if (p += h, l.arg && (S(l.arg) ? p += `:[${f(l.name, !0, !0, e)}]` : p += `:${l.arg}`), l.modifiers) {
|
|
463
|
+
const v = Object.keys(l.modifiers);
|
|
464
|
+
v.length && (p += v.map((y) => "." + y));
|
|
465
|
+
}
|
|
466
|
+
l.value ? n.push(
|
|
467
|
+
`${p}="${f(l.value, !0, !0, e)}"`
|
|
468
|
+
) : n.push(p);
|
|
469
|
+
}), n;
|
|
470
|
+
}
|
|
471
|
+
function we(t = []) {
|
|
472
|
+
const e = t.filter(
|
|
473
|
+
(a) => J.includes(a.name)
|
|
474
|
+
), s = t.filter(
|
|
475
|
+
(a) => !J.includes(a.name)
|
|
476
|
+
), n = e.find(
|
|
477
|
+
(a) => $(a.name) === "vIf"
|
|
478
|
+
), i = e.find(
|
|
479
|
+
(a) => $(a.name) === "vFor"
|
|
480
|
+
), r = e.find(
|
|
481
|
+
(a) => $(a.name) === "vShow"
|
|
482
|
+
), o = e.find(
|
|
483
|
+
(a) => $(a.name) === "vBind"
|
|
484
|
+
), c = e.find(
|
|
485
|
+
(a) => $(a.name) === "vHtml"
|
|
486
|
+
), u = e.filter(
|
|
487
|
+
(a) => $(a.name) === "vModel"
|
|
488
|
+
);
|
|
435
489
|
return {
|
|
436
|
-
vIf:
|
|
437
|
-
vFor:
|
|
438
|
-
vShow:
|
|
439
|
-
vModels:
|
|
440
|
-
vBind:
|
|
490
|
+
vIf: n,
|
|
491
|
+
vFor: i,
|
|
492
|
+
vShow: r,
|
|
493
|
+
vModels: u,
|
|
494
|
+
vBind: o,
|
|
495
|
+
vHtml: c,
|
|
496
|
+
customDirectives: s
|
|
441
497
|
};
|
|
442
498
|
}
|
|
443
|
-
function
|
|
444
|
-
return typeof
|
|
499
|
+
function Pe(t, e, s, n, i) {
|
|
500
|
+
return typeof t == "string" ? t : S(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? z(t, s, e, n, i) : "";
|
|
445
501
|
}
|
|
446
|
-
function
|
|
447
|
-
if (!
|
|
448
|
-
const
|
|
449
|
-
return `<template ${`#${
|
|
450
|
-
${
|
|
502
|
+
function xe(t, e, s) {
|
|
503
|
+
if (!t) return e;
|
|
504
|
+
const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
|
|
505
|
+
return `<template ${`#${n.name}="${n.params?.length > 0 ? `{${n.params?.join(",")}}` : `scope_${s}`}"`}>
|
|
506
|
+
${e}
|
|
451
507
|
</template>`;
|
|
452
508
|
}
|
|
453
|
-
function
|
|
509
|
+
function Ce(t, e = [], s = [], n = {}) {
|
|
454
510
|
const i = {
|
|
455
511
|
vue: ["defineComponent", "reactive"]
|
|
456
512
|
};
|
|
457
|
-
for (const r of
|
|
458
|
-
const o =
|
|
513
|
+
for (const r of e) {
|
|
514
|
+
const o = t.get(r.split(":")[0]);
|
|
459
515
|
o && o.package && (i[o.package] ?? (i[o.package] = [])).push(o.parent || (o.alias || "").split(".")[0] || o.name);
|
|
460
516
|
}
|
|
461
|
-
for (const [r, o] of Object.entries(
|
|
517
|
+
for (const [r, o] of Object.entries(n))
|
|
462
518
|
(i[r] ?? (i[r] = [])).push(...Array.from(o));
|
|
463
|
-
return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${
|
|
519
|
+
return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${k(o).join(
|
|
464
520
|
","
|
|
465
|
-
)}} from '${r}';`).concat(
|
|
466
|
-
}
|
|
467
|
-
function
|
|
468
|
-
const
|
|
469
|
-
for (const [
|
|
470
|
-
|
|
471
|
-
${
|
|
472
|
-
${
|
|
521
|
+
)}} from '${r}';`).concat(s);
|
|
522
|
+
}
|
|
523
|
+
function Oe(t = {}) {
|
|
524
|
+
const e = [];
|
|
525
|
+
for (const [s, n] of Object.entries(t))
|
|
526
|
+
e.push(`
|
|
527
|
+
${s} {
|
|
528
|
+
${ce(n)}
|
|
473
529
|
}
|
|
474
530
|
`);
|
|
475
|
-
return
|
|
531
|
+
return e.join(`
|
|
476
532
|
`);
|
|
477
533
|
}
|
|
478
|
-
function
|
|
479
|
-
const
|
|
480
|
-
return Object.entries(
|
|
481
|
-
|
|
482
|
-
`const ${
|
|
534
|
+
function Ee(t = {}) {
|
|
535
|
+
const e = [];
|
|
536
|
+
return Object.entries(t).forEach(([s, n]) => {
|
|
537
|
+
e.push(
|
|
538
|
+
`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`
|
|
483
539
|
);
|
|
484
|
-
}),
|
|
540
|
+
}), e;
|
|
485
541
|
}
|
|
486
|
-
function
|
|
487
|
-
const
|
|
488
|
-
return Object.entries(
|
|
489
|
-
|
|
490
|
-
`const ${
|
|
542
|
+
function _e(t = {}) {
|
|
543
|
+
const e = [];
|
|
544
|
+
return Object.entries(t).forEach(([s, n]) => {
|
|
545
|
+
e.push(
|
|
546
|
+
`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`
|
|
491
547
|
);
|
|
492
|
-
}),
|
|
493
|
-
}
|
|
494
|
-
function
|
|
495
|
-
const { dsl:
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
),
|
|
548
|
+
}), e;
|
|
549
|
+
}
|
|
550
|
+
function Ae(t, e) {
|
|
551
|
+
const { dsl: s } = t, n = Object.keys(s.computed || {}), i = C(s.lifeCycles, n), r = C(s.computed, n), o = me(s.watch, n), c = he(s.dataSources), { methods: u, nodes: a, components: d, importBlocks: l, directives: p } = z(
|
|
552
|
+
s.nodes || [],
|
|
553
|
+
e,
|
|
554
|
+
n,
|
|
555
|
+
t.context
|
|
556
|
+
), m = [...r, ...o.computed], h = C(
|
|
501
557
|
{
|
|
502
|
-
...
|
|
503
|
-
...
|
|
558
|
+
...u,
|
|
559
|
+
...s.methods || {}
|
|
504
560
|
},
|
|
505
|
-
|
|
506
|
-
),
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
),
|
|
512
|
-
...
|
|
513
|
-
...
|
|
514
|
-
}),
|
|
561
|
+
n
|
|
562
|
+
), v = l.map((j) => `import ${j.name} from './${j.id}.vue';`), y = Ce(
|
|
563
|
+
e,
|
|
564
|
+
d,
|
|
565
|
+
v,
|
|
566
|
+
t.imports
|
|
567
|
+
), _ = Object.keys({
|
|
568
|
+
...t.urlSchemas,
|
|
569
|
+
...t.blockPlugins
|
|
570
|
+
}), g = Ee(t.urlSchemas), P = _e(t.blockPlugins);
|
|
515
571
|
return {
|
|
516
|
-
id:
|
|
517
|
-
version:
|
|
518
|
-
name:
|
|
519
|
-
state:
|
|
520
|
-
inject:
|
|
521
|
-
props:
|
|
522
|
-
emits:
|
|
572
|
+
id: s.id,
|
|
573
|
+
version: s.__VERSION__,
|
|
574
|
+
name: s.name,
|
|
575
|
+
state: le(s.state).join(","),
|
|
576
|
+
inject: ue(s.inject).join(","),
|
|
577
|
+
props: fe(s.props).join(","),
|
|
578
|
+
emits: pe(s.emits).join(","),
|
|
523
579
|
watch: o.watches.join(","),
|
|
524
580
|
lifeCycles: i.join(","),
|
|
525
|
-
computed:
|
|
526
|
-
methods: [...c, ...
|
|
581
|
+
computed: m.join(","),
|
|
582
|
+
methods: [...c, ...h].join(","),
|
|
527
583
|
imports: `
|
|
528
|
-
` +
|
|
584
|
+
` + y.join(`
|
|
529
585
|
`),
|
|
530
|
-
components:
|
|
531
|
-
|
|
532
|
-
|
|
586
|
+
components: d.join(","),
|
|
587
|
+
directives: p.join(","),
|
|
588
|
+
returns: t.members.join(","),
|
|
589
|
+
template: a.join(`
|
|
533
590
|
`),
|
|
534
|
-
css:
|
|
535
|
-
style:
|
|
536
|
-
urlSchemas:
|
|
591
|
+
css: s.css || "",
|
|
592
|
+
style: Oe(t.style),
|
|
593
|
+
urlSchemas: g.join(`
|
|
537
594
|
`),
|
|
538
|
-
blockPlugins:
|
|
595
|
+
blockPlugins: P.join(`
|
|
539
596
|
`),
|
|
540
|
-
asyncComponents:
|
|
597
|
+
asyncComponents: _.join(",")
|
|
541
598
|
};
|
|
542
599
|
}
|
|
543
|
-
const
|
|
600
|
+
const Fe = `
|
|
544
601
|
// @ts-nocheck
|
|
545
602
|
|
|
546
603
|
<%= imports %>
|
|
@@ -549,6 +606,7 @@ export default defineComponent({
|
|
|
549
606
|
name: '<%= name %>',
|
|
550
607
|
<% if(inject) { %> inject: { <%= inject %>}, <% } %>
|
|
551
608
|
<% if(components) { %> components: { <%= components %> }, <% } %>
|
|
609
|
+
<% if(directives) { %> directives: { <%= directives %> }, <% } %>
|
|
552
610
|
<% if(props) { %> props: { <%= props %> }, <% } %>
|
|
553
611
|
<% if(emits) {%> emits: [<%= emits %>], <% } %>
|
|
554
612
|
setup(props) {
|
|
@@ -571,7 +629,7 @@ export default defineComponent({
|
|
|
571
629
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
572
630
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
573
631
|
});
|
|
574
|
-
`.replace(/(\n|\r|\t)/g, ""),
|
|
632
|
+
`.replace(/(\n|\r|\t)/g, ""), Ie = `
|
|
575
633
|
<template>
|
|
576
634
|
<%= template %>
|
|
577
635
|
</template>
|
|
@@ -582,22 +640,22 @@ export default defineComponent({
|
|
|
582
640
|
<%= css %>
|
|
583
641
|
<%= style %>
|
|
584
642
|
</style>
|
|
585
|
-
`,
|
|
586
|
-
async function
|
|
587
|
-
const i = new
|
|
643
|
+
`, Be = L(Fe), Ne = L(Ie);
|
|
644
|
+
async function Je(t, e = /* @__PURE__ */ new Map(), s = [], n) {
|
|
645
|
+
const i = new ae(se(t), s), r = Ae(i, e), o = Be(r), c = Ne({
|
|
588
646
|
template: r.template,
|
|
589
|
-
css: await
|
|
590
|
-
script: await
|
|
591
|
-
style: await
|
|
647
|
+
css: await T(r.css, n),
|
|
648
|
+
script: await ie(o, n),
|
|
649
|
+
style: await T(r.style, n)
|
|
592
650
|
});
|
|
593
|
-
return await
|
|
651
|
+
return await M(c, n).catch((u) => (u.content = c, Promise.reject(u)));
|
|
594
652
|
}
|
|
595
|
-
async function
|
|
596
|
-
const
|
|
653
|
+
async function Le(t) {
|
|
654
|
+
const e = `
|
|
597
655
|
<template>
|
|
598
656
|
<div>
|
|
599
657
|
<h3>源码模式页面</h3>
|
|
600
|
-
<div>文件路径:/.vtj/vue/${
|
|
658
|
+
<div>文件路径:/.vtj/vue/${t.id}.vue</div>
|
|
601
659
|
</div>
|
|
602
660
|
</template>
|
|
603
661
|
<script lang="ts" setup>
|
|
@@ -605,10 +663,10 @@ async function Wt(e) {
|
|
|
605
663
|
<style scoped lang="scss">
|
|
606
664
|
</style>
|
|
607
665
|
`;
|
|
608
|
-
return await
|
|
666
|
+
return await M(e);
|
|
609
667
|
}
|
|
610
668
|
export {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
669
|
+
We as VTJ_CODER_VERSION,
|
|
670
|
+
Le as createEmptyPage,
|
|
671
|
+
Je as generator
|
|
614
672
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"prettier": "~3.4.0",
|
|
8
|
-
"@vtj/
|
|
9
|
-
"@vtj/
|
|
8
|
+
"@vtj/base": "~0.9.1",
|
|
9
|
+
"@vtj/core": "~0.9.3"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@vtj/cli": "~0.9.1"
|
package/types/parser/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { NodeSchema, MaterialDescription, JSFunction } from '@vtj/core';
|
|
2
|
+
/**
|
|
3
|
+
* 内置指令
|
|
4
|
+
*/
|
|
5
|
+
export declare const BUILT_IN_DIRECTIVES: string[];
|
|
2
6
|
export declare function parseTemplate(children: NodeSchema[], componentMap: Map<string, MaterialDescription>, computedKeys?: string[], context?: Record<string, Set<string>>, parent?: NodeSchema): {
|
|
3
7
|
nodes: string[];
|
|
4
8
|
methods: Record<string, JSFunction>;
|
|
9
|
+
directives: string[];
|
|
5
10
|
components: string[];
|
|
6
11
|
importBlocks: {
|
|
7
12
|
id: string;
|
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.9.
|
|
5
|
+
* @version 0.9.2
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.9.
|
|
8
|
+
export declare const version = "0.9.2";
|