@vtj/coder 0.7.13 → 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 +24 -18
- package/dist/index.mjs +98 -78
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
-
default: ${
|
|
10
|
-
}`)}function
|
|
15
|
+
default: ${u(e.default,!0,!1)}
|
|
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
|
-
default: ${
|
|
14
|
-
}`)}function
|
|
19
|
+
default: ${u(r.default,!0,!1)}
|
|
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,d?.methods||{}),a=a.concat(d?.components||[]),c=c.concat(d?.importBlocks||[])),
|
|
22
|
-
`),i?.id);s.push(v)}),{nodes:s,methods:o,components:
|
|
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
|
|
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(`
|
|
27
33
|
`),components:f.join(","),returns:t.members.join(","),template:h.join(`
|
|
28
|
-
`),css:r.css||""}}const
|
|
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,
|
|
@@ -66,12 +86,12 @@ function E(t) {
|
|
|
66
86
|
function P(t) {
|
|
67
87
|
return t.replace(new RegExp("this.", "g"), "");
|
|
68
88
|
}
|
|
69
|
-
function
|
|
89
|
+
function W(t) {
|
|
70
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 ? P(
|
|
94
|
+
return r ? P(W(n)) : W(n);
|
|
75
95
|
}
|
|
76
96
|
function A(t, e = []) {
|
|
77
97
|
let r = t;
|
|
@@ -82,7 +102,7 @@ function A(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("{"))
|
|
88
108
|
return e;
|
|
@@ -96,14 +116,14 @@ function W(t) {
|
|
|
96
116
|
}
|
|
97
117
|
return e;
|
|
98
118
|
}
|
|
99
|
-
function
|
|
119
|
+
function K(t = {}) {
|
|
100
120
|
return Object.entries(t).map(([e, r]) => `"${e}": ${p(r)}`);
|
|
101
121
|
}
|
|
102
|
-
function
|
|
122
|
+
function L(t = {}, e = !1) {
|
|
103
123
|
const r = Object.keys(t);
|
|
104
124
|
return e ? r.map((n) => "." + n) : r;
|
|
105
125
|
}
|
|
106
|
-
class
|
|
126
|
+
class ee {
|
|
107
127
|
constructor(e, r) {
|
|
108
128
|
this.dsl = e, this.dependencies = r, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
|
|
109
129
|
}
|
|
@@ -198,50 +218,50 @@ class K {
|
|
|
198
218
|
Array.isArray(e.nodes) && e.nodes.forEach((n) => r(n));
|
|
199
219
|
}
|
|
200
220
|
}
|
|
201
|
-
function
|
|
221
|
+
function te(t = {}) {
|
|
202
222
|
return Object.entries(t).map(([e, r]) => {
|
|
203
223
|
const n = p(r, !1);
|
|
204
224
|
return `${e}:${n}`;
|
|
205
225
|
});
|
|
206
226
|
}
|
|
207
|
-
function
|
|
227
|
+
function re(t = []) {
|
|
208
228
|
return t.map((e) => `${e.name}: {
|
|
209
229
|
from: '${e.from || e.name}',
|
|
210
230
|
default: ${p(e.default, !0, !1)}
|
|
211
231
|
}`);
|
|
212
232
|
}
|
|
213
|
-
function
|
|
214
|
-
const e = (r) => r ? `[${
|
|
233
|
+
function ne(t = []) {
|
|
234
|
+
const e = (r) => r ? `[${M(r).map((s) => s.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
215
235
|
return t.map((r) => typeof r == "string" ? `${r}: {}` : `${r.name}: {
|
|
216
236
|
type:${e(r.type)},
|
|
217
237
|
required: ${r.required},
|
|
218
238
|
default: ${p(r.default, !0, !1)}
|
|
219
239
|
}`);
|
|
220
240
|
}
|
|
221
|
-
function
|
|
241
|
+
function se(t = []) {
|
|
222
242
|
return t.map((e) => `'${e}'`);
|
|
223
243
|
}
|
|
224
|
-
function
|
|
244
|
+
function y(t = {}, e = []) {
|
|
225
245
|
return Object.entries(t).map(([r, n]) => {
|
|
226
|
-
let i =
|
|
246
|
+
let i = J(p(n, !1, !1));
|
|
227
247
|
return i = A(i, e), i.startsWith("async") ? `async ${r}${i.replace(/^async/, "")}` : `${r}${i}`;
|
|
228
248
|
});
|
|
229
249
|
}
|
|
230
|
-
function
|
|
250
|
+
function oe(t = [], e = []) {
|
|
231
251
|
const r = t.reduce(
|
|
232
252
|
(s, o) => (o.id && O(o.source) && (s[`watcher_${o.id}`] = o.source), s),
|
|
233
253
|
{}
|
|
234
|
-
), n =
|
|
254
|
+
), n = y(r, e), i = t.map((s) => `watcher_${s.id}: {
|
|
235
255
|
deep: ${s.deep},
|
|
236
256
|
immediate:${s.immediate},
|
|
237
|
-
handler${
|
|
257
|
+
handler${J(s.handler.value)}
|
|
238
258
|
}`);
|
|
239
259
|
return {
|
|
240
260
|
computed: n,
|
|
241
261
|
watches: i
|
|
242
262
|
};
|
|
243
263
|
}
|
|
244
|
-
function
|
|
264
|
+
function ie(t = {}) {
|
|
245
265
|
return Object.values(t).map((e) => {
|
|
246
266
|
const r = O(e.transform) && e.transform.value || "(res) => res";
|
|
247
267
|
return `async ${e.name}(...args:any[]) {
|
|
@@ -249,38 +269,38 @@ function oe(t = {}) {
|
|
|
249
269
|
}`;
|
|
250
270
|
});
|
|
251
271
|
}
|
|
252
|
-
function
|
|
272
|
+
function T(t, e, r = [], n = {}, i) {
|
|
253
273
|
const s = [];
|
|
254
274
|
let o = {}, a = [], c = [];
|
|
255
|
-
return
|
|
256
|
-
const
|
|
275
|
+
return ae(t).forEach((l) => {
|
|
276
|
+
const $ = [];
|
|
257
277
|
for (const u of l.children) {
|
|
258
278
|
let { id: j, name: f, invisible: g, from: w } = u;
|
|
259
279
|
if (g)
|
|
260
280
|
continue;
|
|
261
|
-
const _ =
|
|
262
|
-
_ && a.push(_),
|
|
263
|
-
const { props:
|
|
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(
|
|
264
284
|
j,
|
|
265
285
|
u.props,
|
|
266
286
|
u.events,
|
|
267
287
|
n,
|
|
268
288
|
r
|
|
269
|
-
),
|
|
289
|
+
), R = he(u.directives).join(" "), m = u.children ? ge(
|
|
270
290
|
u.children,
|
|
271
291
|
r,
|
|
272
292
|
e,
|
|
273
293
|
n,
|
|
274
294
|
u
|
|
275
295
|
) : "";
|
|
276
|
-
Object.assign(o,
|
|
296
|
+
Object.assign(o, V);
|
|
277
297
|
let S = "";
|
|
278
298
|
typeof m == "string" ? S = m : (S = (m?.nodes || []).join(`
|
|
279
|
-
`), Object.assign(o, m?.methods || {}), a = a.concat(m?.components || []), c = c.concat(m?.importBlocks || [])),
|
|
280
|
-
`<${f} ${
|
|
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}>`
|
|
281
301
|
);
|
|
282
302
|
}
|
|
283
|
-
const b =
|
|
303
|
+
const b = ye(l.slot, $.join(`
|
|
284
304
|
`), i?.id);
|
|
285
305
|
s.push(b);
|
|
286
306
|
}), {
|
|
@@ -290,7 +310,7 @@ function B(t, e, r = [], n = {}, i) {
|
|
|
290
310
|
importBlocks: v(c, "id")
|
|
291
311
|
};
|
|
292
312
|
}
|
|
293
|
-
function
|
|
313
|
+
function ae(t = []) {
|
|
294
314
|
const e = /* @__PURE__ */ new Map();
|
|
295
315
|
for (const r of t) {
|
|
296
316
|
const n = typeof r.slot == "string" ? r.slot : r.slot?.name, i = e.get(n);
|
|
@@ -298,8 +318,8 @@ function ie(t = []) {
|
|
|
298
318
|
}
|
|
299
319
|
return e;
|
|
300
320
|
}
|
|
301
|
-
function
|
|
302
|
-
if (
|
|
321
|
+
function ce(t, e, r) {
|
|
322
|
+
if (X.includes(t))
|
|
303
323
|
return null;
|
|
304
324
|
const n = e.get(t);
|
|
305
325
|
if (n && n.alias) {
|
|
@@ -308,25 +328,25 @@ function ae(t, e, r) {
|
|
|
308
328
|
}
|
|
309
329
|
return r || n ? t : null;
|
|
310
330
|
}
|
|
311
|
-
function
|
|
331
|
+
function pe(t) {
|
|
312
332
|
return !!t && typeof t == "object" && t.type === "Schema";
|
|
313
333
|
}
|
|
314
|
-
function
|
|
334
|
+
function ue(t, e, r = []) {
|
|
315
335
|
return typeof e == "string" ? `${t}="${e}"` : E(e) ? `:${t}="${p({
|
|
316
336
|
...e,
|
|
317
337
|
value: A(e.value, r)
|
|
318
|
-
})}"` :
|
|
338
|
+
})}"` : D(e) ? `:${t}='{${K(
|
|
319
339
|
e
|
|
320
340
|
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
321
341
|
}
|
|
322
|
-
function
|
|
323
|
-
return Object.entries(t).map(([r, n]) =>
|
|
342
|
+
function le(t = {}, e = []) {
|
|
343
|
+
return Object.entries(t).map(([r, n]) => ue(r, n, e));
|
|
324
344
|
}
|
|
325
|
-
function
|
|
326
|
-
const i =
|
|
345
|
+
function fe(t, e, r, n) {
|
|
346
|
+
const i = L(e.modifiers, !0);
|
|
327
347
|
return n && n.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${r}"` : `@${t}${i.join("")}="${r}"`;
|
|
328
348
|
}
|
|
329
|
-
function
|
|
349
|
+
function me(t, e = {}, r = {}) {
|
|
330
350
|
const n = {}, i = Array.from(r[t] || /* @__PURE__ */ new Set([])), s = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
331
351
|
return {
|
|
332
352
|
binders: Object.entries(e).map(([a, c]) => {
|
|
@@ -336,24 +356,24 @@ function fe(t, e = {}, r = {}) {
|
|
|
336
356
|
value: `{
|
|
337
357
|
return (${c.handler.value}).apply(this, args);
|
|
338
358
|
}`
|
|
339
|
-
} : c.handler),
|
|
359
|
+
} : c.handler), fe(a, c, l, i);
|
|
340
360
|
}),
|
|
341
361
|
handlers: n
|
|
342
362
|
};
|
|
343
363
|
}
|
|
344
|
-
function
|
|
345
|
-
const { binders: s, handlers: o } =
|
|
364
|
+
function de(t, e = {}, r = {}, n = {}, i) {
|
|
365
|
+
const { binders: s, handlers: o } = me(t, r, n);
|
|
346
366
|
return {
|
|
347
|
-
props:
|
|
367
|
+
props: le(e, i).join(" "),
|
|
348
368
|
handlers: o,
|
|
349
369
|
binders: s,
|
|
350
370
|
events: s.join(" ")
|
|
351
371
|
};
|
|
352
372
|
}
|
|
353
|
-
function
|
|
354
|
-
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);
|
|
355
375
|
if (r && e.push(`v-if="${p(r.value)}"`), n && e.push(`v-show="${p(n.value)}"`), i.forEach((o) => {
|
|
356
|
-
const a =
|
|
376
|
+
const a = L(o.modifiers, !0), c = o.arg ? C(o.arg) ? `:[${p(o.arg)}]` : `:${o.arg}` : "";
|
|
357
377
|
e.push(`v-model${c}${a}="${p(o.value)}"`);
|
|
358
378
|
}), s) {
|
|
359
379
|
const { item: o, index: a } = { item: "item", index: "index", ...s.iterator };
|
|
@@ -361,7 +381,7 @@ function de(t = []) {
|
|
|
361
381
|
}
|
|
362
382
|
return e;
|
|
363
383
|
}
|
|
364
|
-
function
|
|
384
|
+
function $e(t = []) {
|
|
365
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");
|
|
366
386
|
return {
|
|
367
387
|
vIf: e,
|
|
@@ -371,16 +391,16 @@ function he(t = []) {
|
|
|
371
391
|
vBind: i
|
|
372
392
|
};
|
|
373
393
|
}
|
|
374
|
-
function
|
|
394
|
+
function ge(t, e, r, n, i) {
|
|
375
395
|
if (typeof t == "string")
|
|
376
396
|
return t;
|
|
377
397
|
if (C(t)) {
|
|
378
398
|
let s = p(t, !1);
|
|
379
399
|
return s = A(s, e), s = P(s), `{{ ${s} }}`;
|
|
380
400
|
}
|
|
381
|
-
return Array.isArray(t) ?
|
|
401
|
+
return Array.isArray(t) ? T(t, r, e, n, i) : "";
|
|
382
402
|
}
|
|
383
|
-
function
|
|
403
|
+
function ye(t, e, r) {
|
|
384
404
|
if (!t)
|
|
385
405
|
return e;
|
|
386
406
|
const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
|
|
@@ -388,7 +408,7 @@ function ge(t, e, r) {
|
|
|
388
408
|
${e}
|
|
389
409
|
</template>`;
|
|
390
410
|
}
|
|
391
|
-
function
|
|
411
|
+
function ve(t, e = [], r = [], n = {}) {
|
|
392
412
|
const i = {
|
|
393
413
|
vue: ["defineComponent", "reactive"]
|
|
394
414
|
};
|
|
@@ -402,19 +422,19 @@ function $e(t, e = [], r = [], n = {}) {
|
|
|
402
422
|
","
|
|
403
423
|
)}} from '${s}';`).concat(r);
|
|
404
424
|
}
|
|
405
|
-
function
|
|
406
|
-
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(
|
|
407
427
|
r.nodes || [],
|
|
408
428
|
e,
|
|
409
429
|
n,
|
|
410
430
|
t.context
|
|
411
|
-
), b = [...s, ...o.computed], u =
|
|
431
|
+
), b = [...s, ...o.computed], u = y(
|
|
412
432
|
{
|
|
413
433
|
...c,
|
|
414
434
|
...r.methods || {}
|
|
415
435
|
},
|
|
416
436
|
n
|
|
417
|
-
), j =
|
|
437
|
+
), j = $.map((g) => `import ${g.name} from './${g.id}.vue';`), f = ve(
|
|
418
438
|
e,
|
|
419
439
|
l,
|
|
420
440
|
j,
|
|
@@ -424,10 +444,10 @@ function ve(t, e) {
|
|
|
424
444
|
id: r.id,
|
|
425
445
|
version: r.__VERSION__,
|
|
426
446
|
name: r.name,
|
|
427
|
-
state:
|
|
428
|
-
inject:
|
|
429
|
-
props:
|
|
430
|
-
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(","),
|
|
431
451
|
watch: o.watches.join(","),
|
|
432
452
|
lifeCycles: i.join(","),
|
|
433
453
|
computed: b.join(","),
|
|
@@ -441,7 +461,7 @@ function ve(t, e) {
|
|
|
441
461
|
css: r.css || ""
|
|
442
462
|
};
|
|
443
463
|
}
|
|
444
|
-
const
|
|
464
|
+
const je = `
|
|
445
465
|
<%= imports %>
|
|
446
466
|
import { useProvider } from '@vtj/renderer';
|
|
447
467
|
export default defineComponent({
|
|
@@ -467,7 +487,7 @@ export default defineComponent({
|
|
|
467
487
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
468
488
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
469
489
|
});
|
|
470
|
-
`.replace(/(\n|\r|\t)/g, ""),
|
|
490
|
+
`.replace(/(\n|\r|\t)/g, ""), we = `
|
|
471
491
|
<template>
|
|
472
492
|
<%= template %>
|
|
473
493
|
</template>
|
|
@@ -477,16 +497,16 @@ export default defineComponent({
|
|
|
477
497
|
<style lang="scss" scoped>
|
|
478
498
|
<%= css %>
|
|
479
499
|
</style>
|
|
480
|
-
`,
|
|
481
|
-
async function
|
|
482
|
-
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({
|
|
483
503
|
template: s.template,
|
|
484
|
-
css: await
|
|
485
|
-
script: await
|
|
504
|
+
css: await Z(s.css, n),
|
|
505
|
+
script: await Y(o, n)
|
|
486
506
|
});
|
|
487
|
-
return await
|
|
507
|
+
return await B(a, n);
|
|
488
508
|
}
|
|
489
|
-
async function
|
|
509
|
+
async function Pe(t) {
|
|
490
510
|
const e = `
|
|
491
511
|
<template>
|
|
492
512
|
<div>
|
|
@@ -499,10 +519,10 @@ async function Ee(t) {
|
|
|
499
519
|
<style scoped lang="scss">
|
|
500
520
|
</style>
|
|
501
521
|
`;
|
|
502
|
-
return await
|
|
522
|
+
return await B(e);
|
|
503
523
|
}
|
|
504
524
|
export {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
525
|
+
Oe as VTJ_CODER_VERSION,
|
|
526
|
+
Pe as createEmptyPage,
|
|
527
|
+
Ee as generator
|
|
508
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,7 +11,7 @@
|
|
|
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": {
|
|
@@ -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
|
}
|