@vtj/coder 0.7.11 → 0.7.13
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 +18 -18
- package/dist/index.mjs +67 -57
- package/package.json +5 -5
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@vtj/base"),k=require("prettier/standalone"),L=require("prettier/plugins/html"),V=require("prettier/plugins/babel"),D=require("prettier/plugins/postcss"),M=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(V),G=b(D),H=b(M);/**!
|
|
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
|
-
*/const U="0.7.
|
|
7
|
+
*/const U="0.7.13";u.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 N(t,e){return e?t:await k.format(t,{parser:"html",...x,plugins:[Q]})}async function X(t,e){return e?t:await k.format(t,{parser:"babel-ts",...x,plugins:[z,H]})}async function Y(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 F(t){return t.replace(/this\.context\??\./g,"")}function p(t,e=!0,r=!0){const n=P(t)?t.value:e?JSON.stringify(t):t;return r?_(F(n)):F(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 R(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 Z(t={}){return Object.entries(t).map(([e,r])=>`"${e}": ${p(r)}`)}function W(t={},e=!1){const r=Object.keys(t);return e?r.map(n=>"."+n):r}class K{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 u.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 ee(t={}){return Object.entries(t).map(([e,r])=>{const n=p(r,!1);return`${e}:${n}`})}function te(t=[]){return t.map(e=>`${e.name}: {
|
|
8
8
|
from: '${e.from||e.name}',
|
|
9
|
-
default: ${
|
|
10
|
-
}`)}function re(t=[]){const e=r=>r?`[${
|
|
9
|
+
default: ${p(e.default,!0,!1)}
|
|
10
|
+
}`)}function re(t=[]){const e=r=>r?`[${u.toArray(r).map(s=>s.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(r=>typeof r=="string"?`${r}: {}`:`${r.name}: {
|
|
11
11
|
type:${e(r.type)},
|
|
12
12
|
required: ${r.required},
|
|
13
|
-
default: ${
|
|
14
|
-
}`)}function ne(t=[]){return t.map(e=>`'${e}'`)}function $(t={},e=[]){return Object.entries(t).map(([r,n])=>{let i=
|
|
13
|
+
default: ${p(r.default,!0,!1)}
|
|
14
|
+
}`)}function ne(t=[]){return t.map(e=>`'${e}'`)}function $(t={},e=[]){return Object.entries(t).map(([r,n])=>{let i=R(p(n,!1,!1));return i=A(i,e),i.startsWith("async")?`async ${r}${i.replace(/^async/,"")}`:`${r}${i}`})}function se(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
15
|
deep: ${s.deep},
|
|
16
16
|
immediate:${s.immediate},
|
|
17
|
-
handler${
|
|
18
|
-
}`);return{computed:n,watches:i}}function oe(t={}){return Object.values(t).map(e=>{const r=
|
|
17
|
+
handler${R(s.handler.value)}
|
|
18
|
+
}`);return{computed:n,watches:i}}function oe(t={}){return Object.values(t).map(e=>{const r=O(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
19
19
|
return await this.provider.apis.${e.ref}.apply(this, args).then(${r});
|
|
20
|
-
}`})}function
|
|
21
|
-
`),Object.assign(o,
|
|
22
|
-
`),i?.id);s.push(
|
|
20
|
+
}`})}function I(t,e,r=[],n={},i){const s=[];let o={},a=[],c=[];return ie(t).forEach(f=>{const y=[];for(const l of f.children){let{id:j,name:m,invisible:g,from:w}=l;if(g)continue;const E=ae(m,e,w);E&&a.push(E),ce(w)&&c.push({id:w.id,name:m});const{props:q,events:B,handlers:T}=me(j,l.props,l.events,n,r),J=de(l.directives).join(" "),d=l.children?ye(l.children,r,e,n,l):"";Object.assign(o,T);let S="";typeof d=="string"?S=d:(S=(d?.nodes||[]).join(`
|
|
21
|
+
`),Object.assign(o,d?.methods||{}),a=a.concat(d?.components||[]),c=c.concat(d?.importBlocks||[])),y.push(`<${m} ${J} ${q} ${B}>${S.trim()}</${m}>`)}const v=ge(f.slot,y.join(`
|
|
22
|
+
`),i?.id);s.push(v)}),{nodes:s,methods:o,components:u.dedupArray(a),importBlocks:u.dedupArray(c,"id")}}function ie(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 ae(t,e,r){if(["slot","component","template"].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 ce(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function ue(t,e,r=[]){return typeof e=="string"?`${t}="${e}"`:P(e)?`:${t}="${p({...e,value:A(e.value,r)})}"`:u.isPlainObject(e)?`:${t}='{${Z(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function pe(t={},e=[]){return Object.entries(t).map(([r,n])=>ue(r,n,e))}function le(t,e,r,n){const i=W(e.modifiers,!0);return n&&n.length>0?`@${t}${i.join("")}="(...args:any[]) => ${r}"`:`@${t}${i.join("")}="${r}"`}function fe(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):`${u.camelCase(a)}_handler_${t}${s}`;return h||(n[f]=i.length?{type:"JSFunction",value:`{
|
|
23
23
|
return (${c.handler.value}).apply(this, args);
|
|
24
|
-
}`}:c.handler,le(a,c,
|
|
24
|
+
}`}:c.handler),le(a,c,f,i)}),handlers:n}}function me(t,e={},r={},n={},i){const{binders:s,handlers:o}=fe(t,r,n);return{props:pe(e,i).join(" "),handlers:o,binders:s,events:s.join(" ")}}function de(t=[]){const e=[],{vIf:r,vShow:n,vModels:i,vFor:s}=he(t);if(r&&e.push(`v-if="${p(r.value)}"`),n&&e.push(`v-show="${p(n.value)}"`),i.forEach(o=>{const a=W(o.modifiers,!0),c=o.arg?C(o.arg)?`:[${p(o.arg)}]`:`:${o.arg}`:"";e.push(`v-model${c}${a}="${p(o.value)}"`)}),s){const{item:o,index:a}={item:"item",index:"index",...s.iterator};e.push(`v-for="(${o}, ${a}) in ${p(s.value)}"`)}return e}function he(t=[]){const e=t.find(o=>u.camelCase(o.name)==="vIf"),r=t.find(o=>u.camelCase(o.name)==="vFor"),n=t.find(o=>u.camelCase(o.name)==="vShow"),i=t.find(o=>u.camelCase(o.name)==="vBind"),s=t.filter(o=>u.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=p(t,!1);return s=A(s,e),s=_(s),`{{ ${s} }}`}return Array.isArray(t)?I(t,r,e,n,i):""}function ge(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
25
|
${e}
|
|
26
|
-
</template>`}function $e(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 { ${
|
|
27
|
-
`),components:
|
|
28
|
-
`),css:r.css||""}}const
|
|
26
|
+
</template>`}function $e(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 { ${u.dedupArray(o).join(",")}} from '${s}';`).concat(r)}function be(t,e){const{dsl:r}=t,n=Object.keys(r.computed||{}),i=$(r.lifeCycles,n),s=$(r.computed,n),o=se(r.watch,n),a=oe(r.dataSources),{methods:c,nodes:h,components:f,importBlocks:y}=I(r.nodes||[],e,n,t.context),v=[...s,...o.computed],l=$({...c,...r.methods||{}},n),j=y.map(g=>`import ${g.name} from './${g.id}.vue';`),m=$e(e,f,j,t.imports);return{id:r.id,version:r.__VERSION__,name:r.name,state:ee(r.state).join(","),inject:te(r.inject).join(","),props:re(r.props).join(","),emits:ne(r.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:v.join(","),methods:[...a,...l].join(","),imports:m.join(`
|
|
27
|
+
`),components:f.join(","),returns:t.members.join(","),template:h.join(`
|
|
28
|
+
`),css:r.css||""}}const ve=`
|
|
29
29
|
<%= imports %>
|
|
30
30
|
import { useProvider } from '@vtj/renderer';
|
|
31
31
|
export default defineComponent({
|
|
@@ -61,7 +61,7 @@ export default defineComponent({
|
|
|
61
61
|
<style lang="scss" scoped>
|
|
62
62
|
<%= css %>
|
|
63
63
|
</style>
|
|
64
|
-
`,we=
|
|
64
|
+
`,we=u.template(ve),Se=u.template(je);async function ke(t,e=new Map,r=[],n){const i=new K(u.cloneDeep(t),r),s=be(i,e),o=we(s),a=Se({template:s.template,css:await Y(s.css,n),script:await X(o,n)});return await N(a,n)}async function xe(t){const e=`
|
|
65
65
|
<template>
|
|
66
66
|
<div>
|
|
67
67
|
<h3>源码模式页面</h3>
|
|
@@ -72,4 +72,4 @@ export default defineComponent({
|
|
|
72
72
|
<\/script>
|
|
73
73
|
<style scoped lang="scss">
|
|
74
74
|
</style>
|
|
75
|
-
`;return await
|
|
75
|
+
`;return await N(e)}exports.VTJ_CODER_VERSION=U;exports.createEmptyPage=xe;exports.generator=ke;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mitt as q, dedupArray as v, toArray as D, camelCase as
|
|
1
|
+
import { mitt as q, dedupArray as v, toArray as D, camelCase as d, isPlainObject as M, template as N, 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,10 @@ 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.13
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const Ce = "0.7.
|
|
14
|
+
const Ce = "0.7.13";
|
|
15
15
|
q();
|
|
16
16
|
const k = {
|
|
17
17
|
arrowParens: "always",
|
|
@@ -33,7 +33,7 @@ const k = {
|
|
|
33
33
|
useTabs: !1,
|
|
34
34
|
vueIndentScriptAndStyle: !0
|
|
35
35
|
};
|
|
36
|
-
async function
|
|
36
|
+
async function R(t, e) {
|
|
37
37
|
return e ? t : await x(t, {
|
|
38
38
|
parser: "html",
|
|
39
39
|
...k,
|
|
@@ -63,17 +63,17 @@ function O(t) {
|
|
|
63
63
|
function E(t) {
|
|
64
64
|
return C(t) || O(t);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function P(t) {
|
|
67
67
|
return t.replace(new RegExp("this.", "g"), "");
|
|
68
68
|
}
|
|
69
|
-
function
|
|
70
|
-
return t.replace(
|
|
69
|
+
function F(t) {
|
|
70
|
+
return t.replace(/this\.context\??\./g, "");
|
|
71
71
|
}
|
|
72
72
|
function p(t, e = !0, r = !0) {
|
|
73
73
|
const n = E(t) ? t.value : e ? JSON.stringify(t) : t;
|
|
74
|
-
return r ?
|
|
74
|
+
return r ? P(F(n)) : F(n);
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function A(t, e = []) {
|
|
77
77
|
let r = t;
|
|
78
78
|
for (const n of e)
|
|
79
79
|
r = r.replace(
|
|
@@ -82,14 +82,24 @@ function P(t, e = []) {
|
|
|
82
82
|
);
|
|
83
83
|
return r;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
85
|
+
function W(t) {
|
|
86
86
|
let e = t.trim();
|
|
87
|
-
|
|
87
|
+
if (e = /^\((\(|async|function)/.test(e) ? e.substring(1, e.length - 1) : e, e.startsWith("{"))
|
|
88
|
+
return e;
|
|
89
|
+
if (e.startsWith("async function"))
|
|
90
|
+
e = e.replace(/^async function/, "async");
|
|
91
|
+
else if (e.startsWith("function"))
|
|
92
|
+
e = e.replace(/^function/, "");
|
|
93
|
+
else {
|
|
94
|
+
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/, s = e.match(i);
|
|
95
|
+
s && s[2] && (s[2].startsWith("{") || (e = e.replace(s[2], `{ return ${s[2]} }`))), e = e.replace("=>", "");
|
|
96
|
+
}
|
|
97
|
+
return e;
|
|
88
98
|
}
|
|
89
99
|
function Z(t = {}) {
|
|
90
100
|
return Object.entries(t).map(([e, r]) => `"${e}": ${p(r)}`);
|
|
91
101
|
}
|
|
92
|
-
function
|
|
102
|
+
function I(t = {}, e = !1) {
|
|
93
103
|
const r = Object.keys(t);
|
|
94
104
|
return e ? r.map((n) => "." + n) : r;
|
|
95
105
|
}
|
|
@@ -211,20 +221,20 @@ function re(t = []) {
|
|
|
211
221
|
function ne(t = []) {
|
|
212
222
|
return t.map((e) => `'${e}'`);
|
|
213
223
|
}
|
|
214
|
-
function
|
|
224
|
+
function $(t = {}, e = []) {
|
|
215
225
|
return Object.entries(t).map(([r, n]) => {
|
|
216
|
-
let i =
|
|
217
|
-
return i =
|
|
226
|
+
let i = W(p(n, !1, !1));
|
|
227
|
+
return i = A(i, e), i.startsWith("async") ? `async ${r}${i.replace(/^async/, "")}` : `${r}${i}`;
|
|
218
228
|
});
|
|
219
229
|
}
|
|
220
230
|
function se(t = [], e = []) {
|
|
221
231
|
const r = t.reduce(
|
|
222
232
|
(s, o) => (o.id && O(o.source) && (s[`watcher_${o.id}`] = o.source), s),
|
|
223
233
|
{}
|
|
224
|
-
), n =
|
|
234
|
+
), n = $(r, e), i = t.map((s) => `watcher_${s.id}: {
|
|
225
235
|
deep: ${s.deep},
|
|
226
236
|
immediate:${s.immediate},
|
|
227
|
-
handler${
|
|
237
|
+
handler${W(s.handler.value)}
|
|
228
238
|
}`);
|
|
229
239
|
return {
|
|
230
240
|
computed: n,
|
|
@@ -239,24 +249,24 @@ function oe(t = {}) {
|
|
|
239
249
|
}`;
|
|
240
250
|
});
|
|
241
251
|
}
|
|
242
|
-
function
|
|
252
|
+
function B(t, e, r = [], n = {}, i) {
|
|
243
253
|
const s = [];
|
|
244
254
|
let o = {}, a = [], c = [];
|
|
245
|
-
return ie(t).forEach((
|
|
255
|
+
return ie(t).forEach((l) => {
|
|
246
256
|
const y = [];
|
|
247
|
-
for (const u of
|
|
248
|
-
let { id:
|
|
249
|
-
if (
|
|
257
|
+
for (const u of l.children) {
|
|
258
|
+
let { id: j, name: f, invisible: g, from: w } = u;
|
|
259
|
+
if (g)
|
|
250
260
|
continue;
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
const { props:
|
|
254
|
-
|
|
261
|
+
const _ = ae(f, e, w);
|
|
262
|
+
_ && a.push(_), ce(w) && c.push({ id: w.id, name: f });
|
|
263
|
+
const { props: J, events: L, handlers: T } = me(
|
|
264
|
+
j,
|
|
255
265
|
u.props,
|
|
256
266
|
u.events,
|
|
257
267
|
n,
|
|
258
268
|
r
|
|
259
|
-
), V = de(u.directives).join(" "),
|
|
269
|
+
), V = de(u.directives).join(" "), m = u.children ? ye(
|
|
260
270
|
u.children,
|
|
261
271
|
r,
|
|
262
272
|
e,
|
|
@@ -265,14 +275,14 @@ function L(t, e, r = [], n = {}, i) {
|
|
|
265
275
|
) : "";
|
|
266
276
|
Object.assign(o, T);
|
|
267
277
|
let S = "";
|
|
268
|
-
typeof
|
|
269
|
-
`), Object.assign(o,
|
|
270
|
-
`<${
|
|
278
|
+
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 || [])), y.push(
|
|
280
|
+
`<${f} ${V} ${J} ${L}>${S.trim()}</${f}>`
|
|
271
281
|
);
|
|
272
282
|
}
|
|
273
|
-
const
|
|
283
|
+
const b = ge(l.slot, y.join(`
|
|
274
284
|
`), i?.id);
|
|
275
|
-
s.push(
|
|
285
|
+
s.push(b);
|
|
276
286
|
}), {
|
|
277
287
|
nodes: s,
|
|
278
288
|
methods: o,
|
|
@@ -304,7 +314,7 @@ function ce(t) {
|
|
|
304
314
|
function pe(t, e, r = []) {
|
|
305
315
|
return typeof e == "string" ? `${t}="${e}"` : E(e) ? `:${t}="${p({
|
|
306
316
|
...e,
|
|
307
|
-
value:
|
|
317
|
+
value: A(e.value, r)
|
|
308
318
|
})}"` : M(e) ? `:${t}='{${Z(
|
|
309
319
|
e
|
|
310
320
|
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
@@ -313,20 +323,20 @@ function ue(t = {}, e = []) {
|
|
|
313
323
|
return Object.entries(t).map(([r, n]) => pe(r, n, e));
|
|
314
324
|
}
|
|
315
325
|
function le(t, e, r, n) {
|
|
316
|
-
const i =
|
|
326
|
+
const i = I(e.modifiers, !0);
|
|
317
327
|
return n && n.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${r}"` : `@${t}${i.join("")}="${r}"`;
|
|
318
328
|
}
|
|
319
329
|
function fe(t, e = {}, r = {}) {
|
|
320
330
|
const n = {}, i = Array.from(r[t] || /* @__PURE__ */ new Set([])), s = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
321
331
|
return {
|
|
322
332
|
binders: Object.entries(e).map(([a, c]) => {
|
|
323
|
-
const
|
|
324
|
-
return n[
|
|
333
|
+
const h = c.handler.value.startsWith("this."), l = h ? P(c.handler.value) : `${d(a)}_handler_${t}${s}`;
|
|
334
|
+
return h || (n[l] = i.length ? {
|
|
325
335
|
type: "JSFunction",
|
|
326
336
|
value: `{
|
|
327
337
|
return (${c.handler.value}).apply(this, args);
|
|
328
338
|
}`
|
|
329
|
-
} : c.handler, le(a, c,
|
|
339
|
+
} : c.handler), le(a, c, l, i);
|
|
330
340
|
}),
|
|
331
341
|
handlers: n
|
|
332
342
|
};
|
|
@@ -343,7 +353,7 @@ function me(t, e = {}, r = {}, n = {}, i) {
|
|
|
343
353
|
function de(t = []) {
|
|
344
354
|
const e = [], { vIf: r, vShow: n, vModels: i, vFor: s } = he(t);
|
|
345
355
|
if (r && e.push(`v-if="${p(r.value)}"`), n && e.push(`v-show="${p(n.value)}"`), i.forEach((o) => {
|
|
346
|
-
const a =
|
|
356
|
+
const a = I(o.modifiers, !0), c = o.arg ? C(o.arg) ? `:[${p(o.arg)}]` : `:${o.arg}` : "";
|
|
347
357
|
e.push(`v-model${c}${a}="${p(o.value)}"`);
|
|
348
358
|
}), s) {
|
|
349
359
|
const { item: o, index: a } = { item: "item", index: "index", ...s.iterator };
|
|
@@ -352,7 +362,7 @@ function de(t = []) {
|
|
|
352
362
|
return e;
|
|
353
363
|
}
|
|
354
364
|
function he(t = []) {
|
|
355
|
-
const e = t.find((o) =>
|
|
365
|
+
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
366
|
return {
|
|
357
367
|
vIf: e,
|
|
358
368
|
vFor: r,
|
|
@@ -366,11 +376,11 @@ function ye(t, e, r, n, i) {
|
|
|
366
376
|
return t;
|
|
367
377
|
if (C(t)) {
|
|
368
378
|
let s = p(t, !1);
|
|
369
|
-
return s =
|
|
379
|
+
return s = A(s, e), s = P(s), `{{ ${s} }}`;
|
|
370
380
|
}
|
|
371
|
-
return Array.isArray(t) ?
|
|
381
|
+
return Array.isArray(t) ? B(t, r, e, n, i) : "";
|
|
372
382
|
}
|
|
373
|
-
function
|
|
383
|
+
function ge(t, e, r) {
|
|
374
384
|
if (!t)
|
|
375
385
|
return e;
|
|
376
386
|
const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
|
|
@@ -378,7 +388,7 @@ function $e(t, e, r) {
|
|
|
378
388
|
${e}
|
|
379
389
|
</template>`;
|
|
380
390
|
}
|
|
381
|
-
function
|
|
391
|
+
function $e(t, e = [], r = [], n = {}) {
|
|
382
392
|
const i = {
|
|
383
393
|
vue: ["defineComponent", "reactive"]
|
|
384
394
|
};
|
|
@@ -393,21 +403,21 @@ function ge(t, e = [], r = [], n = {}) {
|
|
|
393
403
|
)}} from '${s}';`).concat(r);
|
|
394
404
|
}
|
|
395
405
|
function ve(t, e) {
|
|
396
|
-
const { dsl: r } = t, n = Object.keys(r.computed || {}), i =
|
|
406
|
+
const { dsl: r } = t, n = Object.keys(r.computed || {}), i = $(r.lifeCycles, n), s = $(r.computed, n), o = se(r.watch, n), a = oe(r.dataSources), { methods: c, nodes: h, components: l, importBlocks: y } = B(
|
|
397
407
|
r.nodes || [],
|
|
398
408
|
e,
|
|
399
409
|
n,
|
|
400
410
|
t.context
|
|
401
|
-
),
|
|
411
|
+
), b = [...s, ...o.computed], u = $(
|
|
402
412
|
{
|
|
403
413
|
...c,
|
|
404
414
|
...r.methods || {}
|
|
405
415
|
},
|
|
406
416
|
n
|
|
407
|
-
),
|
|
417
|
+
), j = y.map((g) => `import ${g.name} from './${g.id}.vue';`), f = $e(
|
|
408
418
|
e,
|
|
409
|
-
|
|
410
|
-
|
|
419
|
+
l,
|
|
420
|
+
j,
|
|
411
421
|
t.imports
|
|
412
422
|
);
|
|
413
423
|
return {
|
|
@@ -420,18 +430,18 @@ function ve(t, e) {
|
|
|
420
430
|
emits: ne(r.emits).join(","),
|
|
421
431
|
watch: o.watches.join(","),
|
|
422
432
|
lifeCycles: i.join(","),
|
|
423
|
-
computed:
|
|
433
|
+
computed: b.join(","),
|
|
424
434
|
methods: [...a, ...u].join(","),
|
|
425
|
-
imports:
|
|
435
|
+
imports: f.join(`
|
|
426
436
|
`),
|
|
427
|
-
components:
|
|
437
|
+
components: l.join(","),
|
|
428
438
|
returns: t.members.join(","),
|
|
429
|
-
template:
|
|
439
|
+
template: h.join(`
|
|
430
440
|
`),
|
|
431
441
|
css: r.css || ""
|
|
432
442
|
};
|
|
433
443
|
}
|
|
434
|
-
const
|
|
444
|
+
const be = `
|
|
435
445
|
<%= imports %>
|
|
436
446
|
import { useProvider } from '@vtj/renderer';
|
|
437
447
|
export default defineComponent({
|
|
@@ -457,7 +467,7 @@ export default defineComponent({
|
|
|
457
467
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
458
468
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
459
469
|
});
|
|
460
|
-
`.replace(/(\n|\r|\t)/g, ""),
|
|
470
|
+
`.replace(/(\n|\r|\t)/g, ""), je = `
|
|
461
471
|
<template>
|
|
462
472
|
<%= template %>
|
|
463
473
|
</template>
|
|
@@ -467,14 +477,14 @@ export default defineComponent({
|
|
|
467
477
|
<style lang="scss" scoped>
|
|
468
478
|
<%= css %>
|
|
469
479
|
</style>
|
|
470
|
-
`, we =
|
|
480
|
+
`, we = N(be), Se = N(je);
|
|
471
481
|
async function Oe(t, e = /* @__PURE__ */ new Map(), r = [], n) {
|
|
472
482
|
const i = new K(Q(t), r), s = ve(i, e), o = we(s), a = Se({
|
|
473
483
|
template: s.template,
|
|
474
484
|
css: await Y(s.css, n),
|
|
475
485
|
script: await X(o, n)
|
|
476
486
|
});
|
|
477
|
-
return await
|
|
487
|
+
return await R(a, n);
|
|
478
488
|
}
|
|
479
489
|
async function Ee(t) {
|
|
480
490
|
const e = `
|
|
@@ -489,7 +499,7 @@ async function Ee(t) {
|
|
|
489
499
|
<style scoped lang="scss">
|
|
490
500
|
</style>
|
|
491
501
|
`;
|
|
492
|
-
return await
|
|
502
|
+
return await R(e);
|
|
493
503
|
}
|
|
494
504
|
export {
|
|
495
505
|
Ce as VTJ_CODER_VERSION,
|
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.13",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "vue-tsc && vite build",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"coverage": "vitest run --coverage"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@vtj/base": "^0.7.
|
|
14
|
-
"@vtj/core": "^0.7.
|
|
13
|
+
"@vtj/base": "^0.7.5",
|
|
14
|
+
"@vtj/core": "^0.7.13",
|
|
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": "010201b133340a84d345745a0ea351c98098fa14",
|
|
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";
|