@vtj/coder 0.7.12 → 0.7.14
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 +23 -17
- package/dist/index.mjs +129 -99
- package/package.json +4 -4
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@vtj/base"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@vtj/base"),k=require("prettier/standalone"),L=require("prettier/plugins/html"),M=require("prettier/plugins/babel"),V=require("prettier/plugins/postcss"),D=require("prettier/plugins/estree");function b(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const Q=b(L),z=b(M),G=b(V),H=b(D);/**!
|
|
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.7.
|
|
5
|
+
* @version 0.7.14
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const U="0.7.
|
|
7
|
+
*/const U="0.7.14";/**!
|
|
8
|
+
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
9
|
+
* @name @vtj/core
|
|
10
|
+
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
+
* @version 0.7.14
|
|
12
|
+
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
+
*/const X=["slot","template","component","img","div","p","h1","h2","h3","span","a"];p.mitt();const x={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 I(t,e){return e?t:await k.format(t,{parser:"html",...x,plugins:[Q]})}async function Y(t,e){return e?t:await k.format(t,{parser:"babel-ts",...x,plugins:[z,H]})}async function Z(t,e){return e?t:k.format(t,{parser:"scss",...x,plugins:[G]})}function C(t){return t&&t.type==="JSExpression"}function O(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function P(t){return C(t)||O(t)}function _(t){return t.replace(new RegExp("this.","g"),"")}function W(t){return t.replace(/this\.context\??\./g,"")}function u(t,e=!0,r=!0){const n=P(t)?t.value:e?JSON.stringify(t):t;return r?_(W(n)):W(n)}function A(t,e=[]){let r=t;for(const n of e)r=r.replace(new RegExp(`this.${n}.value`,"g"),`this.${n}`);return r}function q(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]+)/,s=e.match(i);s&&s[2]&&(s[2].startsWith("{")||(e=e.replace(s[2],`{ return ${s[2]} }`))),e=e.replace("=>","")}return e}function K(t={}){return Object.entries(t).map(([e,r])=>`"${e}": ${u(r)}`)}function B(t={},e=!1){const r=Object.keys(t);return e?r.map(n=>"."+n):r}class ee{constructor(e,r){this.dsl=e,this.dependencies=r,this.libraryRegex=this.collectLibrary(),this.walk(e),this.walkNodes(e),this.members=this.getLibraryMember()}imports={};context={};members=[];libraryRegex=[];collectLibrary(){return this.dependencies.filter(e=>!!e.library).map(e=>new RegExp(`(this.\\$libs.${e.library}.([\\w]+))`,"g"))}collectImport(e){const r=e.split(".");if(r.length===4){const n=r.pop(),i=r.join(".")+".",s=r.pop();if(n&&s){const o=this.dependencies.find(a=>a.library===s)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(n)}return{name:n,path:i,library:s}}return null}replaceLibraryPath(e){const{libraryRegex:r}=this;let n=e.value;for(const i of r){const s=e.value.match(i)||[];for(const o of s){const a=this.collectImport(o);if(a){const c=a.path.replace(/\$/g,"\\$");n=n.replace(new RegExp(c,"g"),"")}}}return n}walk(e){const r=n=>{if(!n||typeof n!="object")return;if(Array.isArray(n)){for(let s of n)r(s);return}const i=Object.values(n);for(const s of i)P(s)?s.value=this.replaceLibraryPath(s):r(s)};r(e)}getLibraryMember(e=[]){let r=[...e];for(const n of Object.values(this.imports))r=r.concat(Array.from(n));return p.dedupArray(r)}collectContext(e,r){const n=new Set(r?.id?this.context[r.id]:[]),i=(e.directives||[]).find(a=>a.name==="vFor");let s=new Set(Array.from(n));if(i){const{item:a="item",index:c="index"}=i.iterator||{};s=new Set([a,c,...Array.from(s)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],c=a.length?a:[`scope_${r?.id}`];s=new Set([...c,...Array.from(s)])}this.context[e.id]=s}walkNodes(e){const r=(n,i)=>{this.collectContext(n,i),Array.isArray(n.children)&&n.children.forEach(s=>r(s,n))};Array.isArray(e.nodes)&&e.nodes.forEach(n=>r(n))}}function te(t={}){return Object.entries(t).map(([e,r])=>{const n=u(r,!1);return`${e}:${n}`})}function re(t=[]){return t.map(e=>`${e.name}: {
|
|
8
14
|
from: '${e.from||e.name}',
|
|
9
15
|
default: ${u(e.default,!0,!1)}
|
|
10
|
-
}`)}function
|
|
16
|
+
}`)}function ne(t=[]){const e=r=>r?`[${p.toArray(r).map(s=>s.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(r=>typeof r=="string"?`${r}: {}`:`${r.name}: {
|
|
11
17
|
type:${e(r.type)},
|
|
12
18
|
required: ${r.required},
|
|
13
19
|
default: ${u(r.default,!0,!1)}
|
|
14
|
-
}`)}function
|
|
20
|
+
}`)}function se(t=[]){return t.map(e=>`'${e}'`)}function $(t={},e=[]){return Object.entries(t).map(([r,n])=>{let i=q(u(n,!1,!1));return i=A(i,e),i.startsWith("async")?`async ${r}${i.replace(/^async/,"")}`:`${r}${i}`})}function oe(t=[],e=[]){const r=t.reduce((s,o)=>(o.id&&O(o.source)&&(s[`watcher_${o.id}`]=o.source),s),{}),n=$(r,e),i=t.map(s=>`watcher_${s.id}: {
|
|
15
21
|
deep: ${s.deep},
|
|
16
22
|
immediate:${s.immediate},
|
|
17
|
-
handler${
|
|
18
|
-
}`);return{computed:n,watches:i}}function
|
|
23
|
+
handler${q(s.handler.value)}
|
|
24
|
+
}`);return{computed:n,watches:i}}function ie(t={}){return Object.values(t).map(e=>{const r=O(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
19
25
|
return await this.provider.apis.${e.ref}.apply(this, args).then(${r});
|
|
20
|
-
}`})}function
|
|
21
|
-
`),Object.assign(o,
|
|
22
|
-
`),i?.id);s.push(
|
|
26
|
+
}`})}function T(t,e,r=[],n={},i){const s=[];let o={},a=[],c=[];return ae(t).forEach(f=>{const g=[];for(const l of f.children){let{id:j,name:m,invisible:y,from:w}=l;if(y)continue;const E=ce(m,e,w);E&&a.push(E),pe(w)&&c.push({id:w.id,name:m});const{props:F,events:N,handlers:J}=de(j,l.props,l.events,n,r),R=he(l.directives).join(" "),d=l.children?ye(l.children,r,e,n,l):"";Object.assign(o,J);let S="";typeof d=="string"?S=d:(S=(d?.nodes||[]).join(`
|
|
27
|
+
`),Object.assign(o,d?.methods||{}),a=a.concat(d?.components||[]),c=c.concat(d?.importBlocks||[])),g.push(m==="img"?`<${m} ${R} ${F} ${N} />`:`<${m} ${R} ${F} ${N}>${S.trim()}</${m}>`)}const v=$e(f.slot,g.join(`
|
|
28
|
+
`),i?.id);s.push(v)}),{nodes:s,methods:o,components:p.dedupArray(a),importBlocks:p.dedupArray(c,"id")}}function ae(t=[]){const e=new Map;for(const r of t){const n=typeof r.slot=="string"?r.slot:r.slot?.name,i=e.get(n);i?i.children.push(r):e.set(n,{slot:r.slot,children:[r]})}return e}function ce(t,e,r){if(X.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 r||n?t:null}function pe(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function ue(t,e,r=[]){return typeof e=="string"?`${t}="${e}"`:P(e)?`:${t}="${u({...e,value:A(e.value,r)})}"`:p.isPlainObject(e)?`:${t}='{${K(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function le(t={},e=[]){return Object.entries(t).map(([r,n])=>ue(r,n,e))}function fe(t,e,r,n){const i=B(e.modifiers,!0);return n&&n.length>0?`@${t}${i.join("")}="(...args:any[]) => ${r}"`:`@${t}${i.join("")}="${r}"`}function me(t,e={},r={}){const n={},i=Array.from(r[t]||new Set([])),s=i.length?`({${i.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,c])=>{const h=c.handler.value.startsWith("this."),f=h?_(c.handler.value):`${p.camelCase(a)}_handler_${t}${s}`;return h||(n[f]=i.length?{type:"JSFunction",value:`{
|
|
23
29
|
return (${c.handler.value}).apply(this, args);
|
|
24
|
-
}`}:c.handler,
|
|
30
|
+
}`}:c.handler),fe(a,c,f,i)}),handlers:n}}function de(t,e={},r={},n={},i){const{binders:s,handlers:o}=me(t,r,n);return{props:le(e,i).join(" "),handlers:o,binders:s,events:s.join(" ")}}function he(t=[]){const e=[],{vIf:r,vShow:n,vModels:i,vFor:s}=ge(t);if(r&&e.push(`v-if="${u(r.value)}"`),n&&e.push(`v-show="${u(n.value)}"`),i.forEach(o=>{const a=B(o.modifiers,!0),c=o.arg?C(o.arg)?`:[${u(o.arg)}]`:`:${o.arg}`:"";e.push(`v-model${c}${a}="${u(o.value)}"`)}),s){const{item:o,index:a}={item:"item",index:"index",...s.iterator};e.push(`v-for="(${o}, ${a}) in ${u(s.value)}"`)}return e}function ge(t=[]){const e=t.find(o=>p.camelCase(o.name)==="vIf"),r=t.find(o=>p.camelCase(o.name)==="vFor"),n=t.find(o=>p.camelCase(o.name)==="vShow"),i=t.find(o=>p.camelCase(o.name)==="vBind"),s=t.filter(o=>p.camelCase(o.name)==="vModel");return{vIf:e,vFor:r,vShow:n,vModels:s,vBind:i}}function ye(t,e,r,n,i){if(typeof t=="string")return t;if(C(t)){let s=u(t,!1);return s=A(s,e),s=_(s),`{{ ${s} }}`}return Array.isArray(t)?T(t,r,e,n,i):""}function $e(t,e,r){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_${r}`}"`}>
|
|
25
31
|
${e}
|
|
26
|
-
</template>`}function
|
|
27
|
-
`),components:
|
|
28
|
-
`),css:r.css||""}}const
|
|
32
|
+
</template>`}function be(t,e=[],r=[],n={}){const i={vue:["defineComponent","reactive"]};for(const s of e){const o=t.get(s.split(":")[0]);o&&o.package&&(i[o.package]??(i[o.package]=[])).push(o.parent||(o.alias||"").split(".")[0]||o.name)}for(const[s,o]of Object.entries(n))(i[s]??(i[s]=[])).push(...Array.from(o));return Object.entries(i).filter(([s,o])=>!!o.length).map(([s,o])=>`import { ${p.dedupArray(o).join(",")}} from '${s}';`).concat(r)}function ve(t,e){const{dsl:r}=t,n=Object.keys(r.computed||{}),i=$(r.lifeCycles,n),s=$(r.computed,n),o=oe(r.watch,n),a=ie(r.dataSources),{methods:c,nodes:h,components:f,importBlocks:g}=T(r.nodes||[],e,n,t.context),v=[...s,...o.computed],l=$({...c,...r.methods||{}},n),j=g.map(y=>`import ${y.name} from './${y.id}.vue';`),m=be(e,f,j,t.imports);return{id:r.id,version:r.__VERSION__,name:r.name,state:te(r.state).join(","),inject:re(r.inject).join(","),props:ne(r.props).join(","),emits:se(r.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:v.join(","),methods:[...a,...l].join(","),imports:m.join(`
|
|
33
|
+
`),components:f.join(","),returns:t.members.join(","),template:h.join(`
|
|
34
|
+
`),css:r.css||""}}const je=`
|
|
29
35
|
<%= imports %>
|
|
30
36
|
import { useProvider } from '@vtj/renderer';
|
|
31
37
|
export default defineComponent({
|
|
@@ -51,7 +57,7 @@ export default defineComponent({
|
|
|
51
57
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
52
58
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
53
59
|
});
|
|
54
|
-
`.replace(/(\n|\r|\t)/g,""),
|
|
60
|
+
`.replace(/(\n|\r|\t)/g,""),we=`
|
|
55
61
|
<template>
|
|
56
62
|
<%= template %>
|
|
57
63
|
</template>
|
|
@@ -61,7 +67,7 @@ export default defineComponent({
|
|
|
61
67
|
<style lang="scss" scoped>
|
|
62
68
|
<%= css %>
|
|
63
69
|
</style>
|
|
64
|
-
`,
|
|
70
|
+
`,Se=p.template(je),ke=p.template(we);async function xe(t,e=new Map,r=[],n){const i=new ee(p.cloneDeep(t),r),s=ve(i,e),o=Se(s),a=ke({template:s.template,css:await Z(s.css,n),script:await Y(o,n)});return await I(a,n)}async function Ce(t){const e=`
|
|
65
71
|
<template>
|
|
66
72
|
<div>
|
|
67
73
|
<h3>源码模式页面</h3>
|
|
@@ -72,4 +78,4 @@ export default defineComponent({
|
|
|
72
78
|
<\/script>
|
|
73
79
|
<style scoped lang="scss">
|
|
74
80
|
</style>
|
|
75
|
-
`;return await
|
|
81
|
+
`;return await I(e)}exports.VTJ_CODER_VERSION=U;exports.createEmptyPage=Ce;exports.generator=xe;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mitt as q, dedupArray as v, toArray as
|
|
1
|
+
import { mitt as q, dedupArray as v, toArray as M, camelCase as d, isPlainObject as D, template as I, cloneDeep as Q } from "@vtj/base";
|
|
2
2
|
import { format as x } from "prettier/standalone";
|
|
3
3
|
import * as z from "prettier/plugins/html";
|
|
4
4
|
import * as G from "prettier/plugins/babel";
|
|
@@ -8,10 +8,30 @@ import * as U from "prettier/plugins/estree";
|
|
|
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.7.
|
|
11
|
+
* @version 0.7.14
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const Oe = "0.7.14";
|
|
15
|
+
/**!
|
|
16
|
+
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
17
|
+
* @name @vtj/core
|
|
18
|
+
* @author CHC chenhuachun1549@dingtalk.com
|
|
19
|
+
* @version 0.7.14
|
|
20
|
+
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
|
+
*/
|
|
22
|
+
const X = [
|
|
23
|
+
"slot",
|
|
24
|
+
"template",
|
|
25
|
+
"component",
|
|
26
|
+
"img",
|
|
27
|
+
"div",
|
|
28
|
+
"p",
|
|
29
|
+
"h1",
|
|
30
|
+
"h2",
|
|
31
|
+
"h3",
|
|
32
|
+
"span",
|
|
33
|
+
"a"
|
|
34
|
+
];
|
|
15
35
|
q();
|
|
16
36
|
const k = {
|
|
17
37
|
arrowParens: "always",
|
|
@@ -33,21 +53,21 @@ const k = {
|
|
|
33
53
|
useTabs: !1,
|
|
34
54
|
vueIndentScriptAndStyle: !0
|
|
35
55
|
};
|
|
36
|
-
async function
|
|
56
|
+
async function B(t, e) {
|
|
37
57
|
return e ? t : await x(t, {
|
|
38
58
|
parser: "html",
|
|
39
59
|
...k,
|
|
40
60
|
plugins: [z]
|
|
41
61
|
});
|
|
42
62
|
}
|
|
43
|
-
async function
|
|
63
|
+
async function Y(t, e) {
|
|
44
64
|
return e ? t : await x(t, {
|
|
45
65
|
parser: "babel-ts",
|
|
46
66
|
...k,
|
|
47
67
|
plugins: [G, U]
|
|
48
68
|
});
|
|
49
69
|
}
|
|
50
|
-
async function
|
|
70
|
+
async function Z(t, e) {
|
|
51
71
|
return e ? t : x(t, {
|
|
52
72
|
parser: "scss",
|
|
53
73
|
...k,
|
|
@@ -63,17 +83,17 @@ function O(t) {
|
|
|
63
83
|
function E(t) {
|
|
64
84
|
return C(t) || O(t);
|
|
65
85
|
}
|
|
66
|
-
function
|
|
86
|
+
function P(t) {
|
|
67
87
|
return t.replace(new RegExp("this.", "g"), "");
|
|
68
88
|
}
|
|
69
|
-
function
|
|
70
|
-
return t.replace(
|
|
89
|
+
function W(t) {
|
|
90
|
+
return t.replace(/this\.context\??\./g, "");
|
|
71
91
|
}
|
|
72
92
|
function p(t, e = !0, r = !0) {
|
|
73
93
|
const n = E(t) ? t.value : e ? JSON.stringify(t) : t;
|
|
74
|
-
return r ?
|
|
94
|
+
return r ? P(W(n)) : W(n);
|
|
75
95
|
}
|
|
76
|
-
function
|
|
96
|
+
function A(t, e = []) {
|
|
77
97
|
let r = t;
|
|
78
98
|
for (const n of e)
|
|
79
99
|
r = r.replace(
|
|
@@ -82,18 +102,28 @@ function P(t, e = []) {
|
|
|
82
102
|
);
|
|
83
103
|
return r;
|
|
84
104
|
}
|
|
85
|
-
function
|
|
105
|
+
function J(t) {
|
|
86
106
|
let e = t.trim();
|
|
87
|
-
|
|
107
|
+
if (e = /^\((\(|async|function)/.test(e) ? e.substring(1, e.length - 1) : e, e.startsWith("{"))
|
|
108
|
+
return e;
|
|
109
|
+
if (e.startsWith("async function"))
|
|
110
|
+
e = e.replace(/^async function/, "async");
|
|
111
|
+
else if (e.startsWith("function"))
|
|
112
|
+
e = e.replace(/^function/, "");
|
|
113
|
+
else {
|
|
114
|
+
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/, s = e.match(i);
|
|
115
|
+
s && s[2] && (s[2].startsWith("{") || (e = e.replace(s[2], `{ return ${s[2]} }`))), e = e.replace("=>", "");
|
|
116
|
+
}
|
|
117
|
+
return e;
|
|
88
118
|
}
|
|
89
|
-
function
|
|
119
|
+
function K(t = {}) {
|
|
90
120
|
return Object.entries(t).map(([e, r]) => `"${e}": ${p(r)}`);
|
|
91
121
|
}
|
|
92
|
-
function
|
|
122
|
+
function L(t = {}, e = !1) {
|
|
93
123
|
const r = Object.keys(t);
|
|
94
124
|
return e ? r.map((n) => "." + n) : r;
|
|
95
125
|
}
|
|
96
|
-
class
|
|
126
|
+
class ee {
|
|
97
127
|
constructor(e, r) {
|
|
98
128
|
this.dsl = e, this.dependencies = r, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
|
|
99
129
|
}
|
|
@@ -188,50 +218,50 @@ class K {
|
|
|
188
218
|
Array.isArray(e.nodes) && e.nodes.forEach((n) => r(n));
|
|
189
219
|
}
|
|
190
220
|
}
|
|
191
|
-
function
|
|
221
|
+
function te(t = {}) {
|
|
192
222
|
return Object.entries(t).map(([e, r]) => {
|
|
193
223
|
const n = p(r, !1);
|
|
194
224
|
return `${e}:${n}`;
|
|
195
225
|
});
|
|
196
226
|
}
|
|
197
|
-
function
|
|
227
|
+
function re(t = []) {
|
|
198
228
|
return t.map((e) => `${e.name}: {
|
|
199
229
|
from: '${e.from || e.name}',
|
|
200
230
|
default: ${p(e.default, !0, !1)}
|
|
201
231
|
}`);
|
|
202
232
|
}
|
|
203
|
-
function
|
|
204
|
-
const e = (r) => r ? `[${
|
|
233
|
+
function ne(t = []) {
|
|
234
|
+
const e = (r) => r ? `[${M(r).map((s) => s.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
205
235
|
return t.map((r) => typeof r == "string" ? `${r}: {}` : `${r.name}: {
|
|
206
236
|
type:${e(r.type)},
|
|
207
237
|
required: ${r.required},
|
|
208
238
|
default: ${p(r.default, !0, !1)}
|
|
209
239
|
}`);
|
|
210
240
|
}
|
|
211
|
-
function
|
|
241
|
+
function se(t = []) {
|
|
212
242
|
return t.map((e) => `'${e}'`);
|
|
213
243
|
}
|
|
214
|
-
function
|
|
244
|
+
function y(t = {}, e = []) {
|
|
215
245
|
return Object.entries(t).map(([r, n]) => {
|
|
216
|
-
let i =
|
|
217
|
-
return i =
|
|
246
|
+
let i = J(p(n, !1, !1));
|
|
247
|
+
return i = A(i, e), i.startsWith("async") ? `async ${r}${i.replace(/^async/, "")}` : `${r}${i}`;
|
|
218
248
|
});
|
|
219
249
|
}
|
|
220
|
-
function
|
|
250
|
+
function oe(t = [], e = []) {
|
|
221
251
|
const r = t.reduce(
|
|
222
252
|
(s, o) => (o.id && O(o.source) && (s[`watcher_${o.id}`] = o.source), s),
|
|
223
253
|
{}
|
|
224
|
-
), n =
|
|
254
|
+
), n = y(r, e), i = t.map((s) => `watcher_${s.id}: {
|
|
225
255
|
deep: ${s.deep},
|
|
226
256
|
immediate:${s.immediate},
|
|
227
|
-
handler${
|
|
257
|
+
handler${J(s.handler.value)}
|
|
228
258
|
}`);
|
|
229
259
|
return {
|
|
230
260
|
computed: n,
|
|
231
261
|
watches: i
|
|
232
262
|
};
|
|
233
263
|
}
|
|
234
|
-
function
|
|
264
|
+
function ie(t = {}) {
|
|
235
265
|
return Object.values(t).map((e) => {
|
|
236
266
|
const r = O(e.transform) && e.transform.value || "(res) => res";
|
|
237
267
|
return `async ${e.name}(...args:any[]) {
|
|
@@ -239,40 +269,40 @@ function oe(t = {}) {
|
|
|
239
269
|
}`;
|
|
240
270
|
});
|
|
241
271
|
}
|
|
242
|
-
function
|
|
272
|
+
function T(t, e, r = [], n = {}, i) {
|
|
243
273
|
const s = [];
|
|
244
274
|
let o = {}, a = [], c = [];
|
|
245
|
-
return
|
|
246
|
-
const
|
|
247
|
-
for (const u of
|
|
248
|
-
let { id:
|
|
249
|
-
if (
|
|
275
|
+
return ae(t).forEach((l) => {
|
|
276
|
+
const $ = [];
|
|
277
|
+
for (const u of l.children) {
|
|
278
|
+
let { id: j, name: f, invisible: g, from: w } = u;
|
|
279
|
+
if (g)
|
|
250
280
|
continue;
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
const { props:
|
|
254
|
-
|
|
281
|
+
const _ = ce(f, e, w);
|
|
282
|
+
_ && a.push(_), pe(w) && c.push({ id: w.id, name: f });
|
|
283
|
+
const { props: F, events: N, handlers: V } = de(
|
|
284
|
+
j,
|
|
255
285
|
u.props,
|
|
256
286
|
u.events,
|
|
257
287
|
n,
|
|
258
288
|
r
|
|
259
|
-
),
|
|
289
|
+
), R = he(u.directives).join(" "), m = u.children ? ge(
|
|
260
290
|
u.children,
|
|
261
291
|
r,
|
|
262
292
|
e,
|
|
263
293
|
n,
|
|
264
294
|
u
|
|
265
295
|
) : "";
|
|
266
|
-
Object.assign(o,
|
|
296
|
+
Object.assign(o, V);
|
|
267
297
|
let S = "";
|
|
268
|
-
typeof
|
|
269
|
-
`), Object.assign(o,
|
|
270
|
-
`<${
|
|
298
|
+
typeof m == "string" ? S = m : (S = (m?.nodes || []).join(`
|
|
299
|
+
`), Object.assign(o, m?.methods || {}), a = a.concat(m?.components || []), c = c.concat(m?.importBlocks || [])), $.push(
|
|
300
|
+
f === "img" ? `<${f} ${R} ${F} ${N} />` : `<${f} ${R} ${F} ${N}>${S.trim()}</${f}>`
|
|
271
301
|
);
|
|
272
302
|
}
|
|
273
|
-
const
|
|
303
|
+
const b = ye(l.slot, $.join(`
|
|
274
304
|
`), i?.id);
|
|
275
|
-
s.push(
|
|
305
|
+
s.push(b);
|
|
276
306
|
}), {
|
|
277
307
|
nodes: s,
|
|
278
308
|
methods: o,
|
|
@@ -280,7 +310,7 @@ function L(t, e, r = [], n = {}, i) {
|
|
|
280
310
|
importBlocks: v(c, "id")
|
|
281
311
|
};
|
|
282
312
|
}
|
|
283
|
-
function
|
|
313
|
+
function ae(t = []) {
|
|
284
314
|
const e = /* @__PURE__ */ new Map();
|
|
285
315
|
for (const r of t) {
|
|
286
316
|
const n = typeof r.slot == "string" ? r.slot : r.slot?.name, i = e.get(n);
|
|
@@ -288,8 +318,8 @@ function ie(t = []) {
|
|
|
288
318
|
}
|
|
289
319
|
return e;
|
|
290
320
|
}
|
|
291
|
-
function
|
|
292
|
-
if (
|
|
321
|
+
function ce(t, e, r) {
|
|
322
|
+
if (X.includes(t))
|
|
293
323
|
return null;
|
|
294
324
|
const n = e.get(t);
|
|
295
325
|
if (n && n.alias) {
|
|
@@ -298,52 +328,52 @@ function ae(t, e, r) {
|
|
|
298
328
|
}
|
|
299
329
|
return r || n ? t : null;
|
|
300
330
|
}
|
|
301
|
-
function
|
|
331
|
+
function pe(t) {
|
|
302
332
|
return !!t && typeof t == "object" && t.type === "Schema";
|
|
303
333
|
}
|
|
304
|
-
function
|
|
334
|
+
function ue(t, e, r = []) {
|
|
305
335
|
return typeof e == "string" ? `${t}="${e}"` : E(e) ? `:${t}="${p({
|
|
306
336
|
...e,
|
|
307
|
-
value:
|
|
308
|
-
})}"` :
|
|
337
|
+
value: A(e.value, r)
|
|
338
|
+
})}"` : D(e) ? `:${t}='{${K(
|
|
309
339
|
e
|
|
310
340
|
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
311
341
|
}
|
|
312
|
-
function
|
|
313
|
-
return Object.entries(t).map(([r, n]) =>
|
|
342
|
+
function le(t = {}, e = []) {
|
|
343
|
+
return Object.entries(t).map(([r, n]) => ue(r, n, e));
|
|
314
344
|
}
|
|
315
|
-
function
|
|
316
|
-
const i =
|
|
345
|
+
function fe(t, e, r, n) {
|
|
346
|
+
const i = L(e.modifiers, !0);
|
|
317
347
|
return n && n.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${r}"` : `@${t}${i.join("")}="${r}"`;
|
|
318
348
|
}
|
|
319
|
-
function
|
|
349
|
+
function me(t, e = {}, r = {}) {
|
|
320
350
|
const n = {}, i = Array.from(r[t] || /* @__PURE__ */ new Set([])), s = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
321
351
|
return {
|
|
322
352
|
binders: Object.entries(e).map(([a, c]) => {
|
|
323
|
-
const
|
|
324
|
-
return n[
|
|
353
|
+
const h = c.handler.value.startsWith("this."), l = h ? P(c.handler.value) : `${d(a)}_handler_${t}${s}`;
|
|
354
|
+
return h || (n[l] = i.length ? {
|
|
325
355
|
type: "JSFunction",
|
|
326
356
|
value: `{
|
|
327
357
|
return (${c.handler.value}).apply(this, args);
|
|
328
358
|
}`
|
|
329
|
-
} : c.handler,
|
|
359
|
+
} : c.handler), fe(a, c, l, i);
|
|
330
360
|
}),
|
|
331
361
|
handlers: n
|
|
332
362
|
};
|
|
333
363
|
}
|
|
334
|
-
function
|
|
335
|
-
const { binders: s, handlers: o } =
|
|
364
|
+
function de(t, e = {}, r = {}, n = {}, i) {
|
|
365
|
+
const { binders: s, handlers: o } = me(t, r, n);
|
|
336
366
|
return {
|
|
337
|
-
props:
|
|
367
|
+
props: le(e, i).join(" "),
|
|
338
368
|
handlers: o,
|
|
339
369
|
binders: s,
|
|
340
370
|
events: s.join(" ")
|
|
341
371
|
};
|
|
342
372
|
}
|
|
343
|
-
function
|
|
344
|
-
const e = [], { vIf: r, vShow: n, vModels: i, vFor: s } =
|
|
373
|
+
function he(t = []) {
|
|
374
|
+
const e = [], { vIf: r, vShow: n, vModels: i, vFor: s } = $e(t);
|
|
345
375
|
if (r && e.push(`v-if="${p(r.value)}"`), n && e.push(`v-show="${p(n.value)}"`), i.forEach((o) => {
|
|
346
|
-
const a =
|
|
376
|
+
const a = L(o.modifiers, !0), c = o.arg ? C(o.arg) ? `:[${p(o.arg)}]` : `:${o.arg}` : "";
|
|
347
377
|
e.push(`v-model${c}${a}="${p(o.value)}"`);
|
|
348
378
|
}), s) {
|
|
349
379
|
const { item: o, index: a } = { item: "item", index: "index", ...s.iterator };
|
|
@@ -351,8 +381,8 @@ function de(t = []) {
|
|
|
351
381
|
}
|
|
352
382
|
return e;
|
|
353
383
|
}
|
|
354
|
-
function
|
|
355
|
-
const e = t.find((o) =>
|
|
384
|
+
function $e(t = []) {
|
|
385
|
+
const e = t.find((o) => d(o.name) === "vIf"), r = t.find((o) => d(o.name) === "vFor"), n = t.find((o) => d(o.name) === "vShow"), i = t.find((o) => d(o.name) === "vBind"), s = t.filter((o) => d(o.name) === "vModel");
|
|
356
386
|
return {
|
|
357
387
|
vIf: e,
|
|
358
388
|
vFor: r,
|
|
@@ -361,16 +391,16 @@ function he(t = []) {
|
|
|
361
391
|
vBind: i
|
|
362
392
|
};
|
|
363
393
|
}
|
|
364
|
-
function
|
|
394
|
+
function ge(t, e, r, n, i) {
|
|
365
395
|
if (typeof t == "string")
|
|
366
396
|
return t;
|
|
367
397
|
if (C(t)) {
|
|
368
398
|
let s = p(t, !1);
|
|
369
|
-
return s =
|
|
399
|
+
return s = A(s, e), s = P(s), `{{ ${s} }}`;
|
|
370
400
|
}
|
|
371
|
-
return Array.isArray(t) ?
|
|
401
|
+
return Array.isArray(t) ? T(t, r, e, n, i) : "";
|
|
372
402
|
}
|
|
373
|
-
function
|
|
403
|
+
function ye(t, e, r) {
|
|
374
404
|
if (!t)
|
|
375
405
|
return e;
|
|
376
406
|
const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
|
|
@@ -378,7 +408,7 @@ function $e(t, e, r) {
|
|
|
378
408
|
${e}
|
|
379
409
|
</template>`;
|
|
380
410
|
}
|
|
381
|
-
function
|
|
411
|
+
function ve(t, e = [], r = [], n = {}) {
|
|
382
412
|
const i = {
|
|
383
413
|
vue: ["defineComponent", "reactive"]
|
|
384
414
|
};
|
|
@@ -392,41 +422,41 @@ function ge(t, e = [], r = [], n = {}) {
|
|
|
392
422
|
","
|
|
393
423
|
)}} from '${s}';`).concat(r);
|
|
394
424
|
}
|
|
395
|
-
function
|
|
396
|
-
const { dsl: r } = t, n = Object.keys(r.computed || {}), i =
|
|
425
|
+
function be(t, e) {
|
|
426
|
+
const { dsl: r } = t, n = Object.keys(r.computed || {}), i = y(r.lifeCycles, n), s = y(r.computed, n), o = oe(r.watch, n), a = ie(r.dataSources), { methods: c, nodes: h, components: l, importBlocks: $ } = T(
|
|
397
427
|
r.nodes || [],
|
|
398
428
|
e,
|
|
399
429
|
n,
|
|
400
430
|
t.context
|
|
401
|
-
),
|
|
431
|
+
), b = [...s, ...o.computed], u = y(
|
|
402
432
|
{
|
|
403
433
|
...c,
|
|
404
434
|
...r.methods || {}
|
|
405
435
|
},
|
|
406
436
|
n
|
|
407
|
-
),
|
|
437
|
+
), j = $.map((g) => `import ${g.name} from './${g.id}.vue';`), f = ve(
|
|
408
438
|
e,
|
|
409
|
-
|
|
410
|
-
|
|
439
|
+
l,
|
|
440
|
+
j,
|
|
411
441
|
t.imports
|
|
412
442
|
);
|
|
413
443
|
return {
|
|
414
444
|
id: r.id,
|
|
415
445
|
version: r.__VERSION__,
|
|
416
446
|
name: r.name,
|
|
417
|
-
state:
|
|
418
|
-
inject:
|
|
419
|
-
props:
|
|
420
|
-
emits:
|
|
447
|
+
state: te(r.state).join(","),
|
|
448
|
+
inject: re(r.inject).join(","),
|
|
449
|
+
props: ne(r.props).join(","),
|
|
450
|
+
emits: se(r.emits).join(","),
|
|
421
451
|
watch: o.watches.join(","),
|
|
422
452
|
lifeCycles: i.join(","),
|
|
423
|
-
computed:
|
|
453
|
+
computed: b.join(","),
|
|
424
454
|
methods: [...a, ...u].join(","),
|
|
425
|
-
imports:
|
|
455
|
+
imports: f.join(`
|
|
426
456
|
`),
|
|
427
|
-
components:
|
|
457
|
+
components: l.join(","),
|
|
428
458
|
returns: t.members.join(","),
|
|
429
|
-
template:
|
|
459
|
+
template: h.join(`
|
|
430
460
|
`),
|
|
431
461
|
css: r.css || ""
|
|
432
462
|
};
|
|
@@ -457,7 +487,7 @@ export default defineComponent({
|
|
|
457
487
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
458
488
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
459
489
|
});
|
|
460
|
-
`.replace(/(\n|\r|\t)/g, ""),
|
|
490
|
+
`.replace(/(\n|\r|\t)/g, ""), we = `
|
|
461
491
|
<template>
|
|
462
492
|
<%= template %>
|
|
463
493
|
</template>
|
|
@@ -467,16 +497,16 @@ export default defineComponent({
|
|
|
467
497
|
<style lang="scss" scoped>
|
|
468
498
|
<%= css %>
|
|
469
499
|
</style>
|
|
470
|
-
`,
|
|
471
|
-
async function
|
|
472
|
-
const i = new
|
|
500
|
+
`, Se = I(je), xe = I(we);
|
|
501
|
+
async function Ee(t, e = /* @__PURE__ */ new Map(), r = [], n) {
|
|
502
|
+
const i = new ee(Q(t), r), s = be(i, e), o = Se(s), a = xe({
|
|
473
503
|
template: s.template,
|
|
474
|
-
css: await
|
|
475
|
-
script: await
|
|
504
|
+
css: await Z(s.css, n),
|
|
505
|
+
script: await Y(o, n)
|
|
476
506
|
});
|
|
477
|
-
return await
|
|
507
|
+
return await B(a, n);
|
|
478
508
|
}
|
|
479
|
-
async function
|
|
509
|
+
async function Pe(t) {
|
|
480
510
|
const e = `
|
|
481
511
|
<template>
|
|
482
512
|
<div>
|
|
@@ -489,10 +519,10 @@ async function Ee(t) {
|
|
|
489
519
|
<style scoped lang="scss">
|
|
490
520
|
</style>
|
|
491
521
|
`;
|
|
492
|
-
return await
|
|
522
|
+
return await B(e);
|
|
493
523
|
}
|
|
494
524
|
export {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
525
|
+
Oe as VTJ_CODER_VERSION,
|
|
526
|
+
Pe as createEmptyPage,
|
|
527
|
+
Ee as generator
|
|
498
528
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.14",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "vue-tsc && vite build",
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@vtj/base": "^0.7.5",
|
|
14
|
-
"@vtj/core": "^0.7.
|
|
14
|
+
"@vtj/core": "^0.7.14",
|
|
15
15
|
"prettier": "~3.2.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@vtj/cli": "^0.7.
|
|
18
|
+
"@vtj/cli": "^0.7.10"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"types"
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "8e69e3eea31f488f318f28013b7ef3df02ee8174",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
}
|
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.7.
|
|
5
|
+
* @version 0.7.13
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.7.
|
|
8
|
+
export declare const version = "0.7.13";
|