@vtj/coder 0.7.2 → 0.7.4
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 +28 -17
- package/dist/index.mjs +64 -48
- package/package.json +4 -4
- package/types/generator.d.ts +2 -1
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
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"),C=require("prettier/standalone"),B=require("prettier/plugins/html"),V=require("prettier/plugins/babel"),D=require("prettier/plugins/postcss"),M=require("prettier/plugins/estree");function v(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=v(B),z=v(V),G=v(D),H=v(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.4
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const
|
|
7
|
+
*/const U="0.7.4",O={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 F(t,e){return e?t:await C.format(t,{parser:"html",...O,plugins:[Q]})}async function X(t,e){return e?t:await C.format(t,{parser:"babel-ts",...O,plugins:[z,H]})}async function Y(t,e){return e?t:C.format(t,{parser:"scss",...O,plugins:[G]})}function k(t){return t&&t.type==="JSExpression"}function x(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function P(t){return k(t)||x(t)}function N(t){return t.replace(new RegExp("this.","g"),"")}function E(t){return t.replace(new RegExp("this.context.","g"),"")}function u(t,e=!0,r=!0){const n=P(t)?t.value:e?JSON.stringify(t):t;return r?N(E(n)):E(n)}function _(t,e=[]){let r=t;for(const n of e)r=r.replace(new RegExp(`this.${n}.value`,"g"),`this.${n}`);return r}function I(t){let e=t.trim();return e.startsWith("{")||(e.startsWith("async function")?e=e.replace(/^async function/,"async"):e.startsWith("function")?e=e.replace(/^function/,""):e=e.replace("=>","")),e}function Z(t={}){return Object.entries(t).map(([e,r])=>`"${e}": ${u(r)}`)}function R(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);a&&(n=n.replace(new RegExp(a.path,"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 ee(t={}){return Object.entries(t).map(([e,r])=>{const n=u(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: ${u(e.default,!0,!1)}
|
|
10
|
+
}`)}function re(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
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: ${u(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=I(u(n,!1,!1));return i=_(i,e),i.startsWith("async")?`async ${r}${i.replace(/^async/,"")}`:`${r}${i}`})}function se(t=[],e=[]){const r=t.reduce((s,o)=>(o.id&&x(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${
|
|
17
|
+
handler${I(s.handler.value)}
|
|
18
18
|
}`);return{computed:n,watches:i}}function oe(t={}){return Object.values(t).map(e=>{const r=x(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,m?.methods||{}),a=a.concat(m?.components||[]),c=c.concat(m?.importBlocks||[])),y.push(`<${f} ${
|
|
20
|
+
}`})}function q(t,e,r=[],n={},i){const s=[];let o={},a=[],c=[];return ie(t).forEach(h=>{const y=[];for(const l of h.children){let{id:j,name:f,invisible:g,from:w}=l;if(g)continue;const A=ae(f,e,w);A&&a.push(A),ce(w)&&c.push({id:w.id,name:f});const{props:T,events:J,handlers:L}=me(j,l.props,l.events,n,r),W=de(l.directives).join(" "),m=l.children?ye(l.children,r,e,n,l):"";Object.assign(o,L);let S="";typeof m=="string"?S=m:(S=(m?.nodes||[]).join(`
|
|
21
|
+
`),Object.assign(o,m?.methods||{}),a=a.concat(m?.components||[]),c=c.concat(m?.importBlocks||[])),y.push(`<${f} ${W} ${T} ${J}>
|
|
22
22
|
${S}
|
|
23
|
-
</${f}>`)}const
|
|
24
|
-
`),i?.id);s.push(
|
|
23
|
+
</${f}>`)}const b=ge(h.slot,y.join(`
|
|
24
|
+
`),i?.id);s.push(b)}),{nodes:s,methods:o,components:p.dedupArray(a),importBlocks:p.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 pe(t,e,r=[]){return typeof e=="string"?`${t}="${e}"`:P(e)?`:${t}="${u({...e,value:_(e.value,r)})}"`:p.isPlainObject(e)?`:${t}='{${Z(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function ue(t={},e=[]){return Object.entries(t).map(([r,n])=>pe(r,n,e))}function le(t,e,r,n){const i=R(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 d=`${p.camelCase(a)}_handler_${t}${s}`;return n[d]=i.length?{type:"JSFunction",value:`{
|
|
25
25
|
return (${c.handler.value}).apply(this, args);
|
|
26
|
-
}`}:c.handler,le(a,c,d,i)}),handlers:n}}function me(t,e={},r={},n={},i){const{binders:s,handlers:o}=fe(t,r,n);return{props:
|
|
26
|
+
}`}:c.handler,le(a,c,d,i)}),handlers:n}}function me(t,e={},r={},n={},i){const{binders:s,handlers:o}=fe(t,r,n);return{props:ue(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="${u(r.value)}"`),n&&e.push(`v-show="${u(n.value)}"`),i.forEach(o=>{const a=R(o.modifiers,!0),c=o.arg?k(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 he(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(k(t)){let s=u(t,!1);return s=_(s,e),s=N(s),`{{ ${s} }}`}return Array.isArray(t)?q(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}`}"`}>
|
|
27
27
|
${e}
|
|
28
|
-
</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 { ${
|
|
28
|
+
</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 { ${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=se(r.watch,n),a=oe(r.dataSources),{methods:c,nodes:d,components:h,importBlocks:y}=q(r.nodes||[],e,n,t.context),b=[...s,...o.computed],l=$({...c,...r.methods||{}},n),j=y.map(g=>`import ${g.name} from '$vtj/raw/${g.id}.vue';`),f=$e(e,h,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:b.join(","),methods:[...a,...l].join(","),imports:f.join(`
|
|
29
29
|
`),components:h.join(","),returns:t.members.join(","),template:d.join(`
|
|
30
|
-
`),css:r.css||""}}const
|
|
30
|
+
`),css:r.css||""}}const be=`
|
|
31
31
|
<%= imports %>
|
|
32
32
|
import { useProvider } from '@vtj/renderer';
|
|
33
33
|
export default defineComponent({
|
|
@@ -53,7 +53,7 @@ export default defineComponent({
|
|
|
53
53
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
54
54
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
55
55
|
});
|
|
56
|
-
`.replace(/(\n|\r|\t)/g,""),
|
|
56
|
+
`.replace(/(\n|\r|\t)/g,""),je=`
|
|
57
57
|
<template>
|
|
58
58
|
<%= template %>
|
|
59
59
|
</template>
|
|
@@ -63,4 +63,15 @@ export default defineComponent({
|
|
|
63
63
|
<style lang="scss" scoped>
|
|
64
64
|
<%= css %>
|
|
65
65
|
</style>
|
|
66
|
-
`,we=
|
|
66
|
+
`,we=p.template(be),Se=p.template(je);async function Ce(t,e=new Map,r=[],n){const i=new K(p.cloneDeep(t),r),s=ve(i,e),o=we(s),a=Se({template:s.template,css:await Y(s.css,n),script:await X(o,n)});return await F(a,n)}async function Oe(t){const e=`
|
|
67
|
+
<template>
|
|
68
|
+
<div>
|
|
69
|
+
<h3>源码模式页面</h3>
|
|
70
|
+
<div>文件路径:/src/views/${t.id}.vue</div>
|
|
71
|
+
</div>
|
|
72
|
+
</template>
|
|
73
|
+
<script lang="ts" setup>
|
|
74
|
+
<\/script>
|
|
75
|
+
<style scoped lang="scss">
|
|
76
|
+
</style>
|
|
77
|
+
`;return await F(e)}exports.VTJ_CODER_VERSION=U;exports.createEmptyPage=Oe;exports.generator=Ce;
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { dedupArray as v, toArray as
|
|
1
|
+
import { dedupArray as v, toArray as q, camelCase as m, isPlainObject as D, template as F, cloneDeep as M } from "@vtj/base";
|
|
2
2
|
import { format as x } from "prettier/standalone";
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
3
|
+
import * as Q from "prettier/plugins/html";
|
|
4
|
+
import * as z from "prettier/plugins/babel";
|
|
5
|
+
import * as G from "prettier/plugins/postcss";
|
|
6
|
+
import * as H 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.7.
|
|
11
|
+
* @version 0.7.4
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const ke = "0.7.
|
|
14
|
+
const ke = "0.7.4", k = {
|
|
15
15
|
arrowParens: "always",
|
|
16
16
|
bracketSpacing: !0,
|
|
17
17
|
bracketSameLine: !0,
|
|
@@ -31,25 +31,25 @@ const ke = "0.7.1", k = {
|
|
|
31
31
|
useTabs: !1,
|
|
32
32
|
vueIndentScriptAndStyle: !0
|
|
33
33
|
};
|
|
34
|
-
async function
|
|
34
|
+
async function N(t, e) {
|
|
35
35
|
return e ? t : await x(t, {
|
|
36
36
|
parser: "html",
|
|
37
37
|
...k,
|
|
38
|
-
plugins: [
|
|
38
|
+
plugins: [Q]
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
async function U(t, e) {
|
|
42
42
|
return e ? t : await x(t, {
|
|
43
43
|
parser: "babel-ts",
|
|
44
44
|
...k,
|
|
45
|
-
plugins: [
|
|
45
|
+
plugins: [z, H]
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
async function X(t, e) {
|
|
49
49
|
return e ? t : x(t, {
|
|
50
50
|
parser: "scss",
|
|
51
51
|
...k,
|
|
52
|
-
plugins: [
|
|
52
|
+
plugins: [G]
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
function C(t) {
|
|
@@ -58,20 +58,20 @@ function C(t) {
|
|
|
58
58
|
function O(t) {
|
|
59
59
|
return typeof t == "object" && t && t.type === "JSFunction";
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function E(t) {
|
|
62
62
|
return C(t) || O(t);
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function I(t) {
|
|
65
65
|
return t.replace(new RegExp("this.", "g"), "");
|
|
66
66
|
}
|
|
67
67
|
function _(t) {
|
|
68
68
|
return t.replace(new RegExp("this.context.", "g"), "");
|
|
69
69
|
}
|
|
70
70
|
function p(t, e = !0, r = !0) {
|
|
71
|
-
const n =
|
|
72
|
-
return r ?
|
|
71
|
+
const n = E(t) ? t.value : e ? JSON.stringify(t) : t;
|
|
72
|
+
return r ? I(_(n)) : _(n);
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function P(t, e = []) {
|
|
75
75
|
let r = t;
|
|
76
76
|
for (const n of e)
|
|
77
77
|
r = r.replace(
|
|
@@ -80,14 +80,14 @@ function E(t, e = []) {
|
|
|
80
80
|
);
|
|
81
81
|
return r;
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function R(t) {
|
|
84
84
|
let e = t.trim();
|
|
85
85
|
return e.startsWith("{") || (e.startsWith("async function") ? e = e.replace(/^async function/, "async") : e.startsWith("function") ? e = e.replace(/^function/, "") : e = e.replace("=>", "")), e;
|
|
86
86
|
}
|
|
87
87
|
function Y(t = {}) {
|
|
88
88
|
return Object.entries(t).map(([e, r]) => `"${e}": ${p(r)}`);
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function J(t = {}, e = !1) {
|
|
91
91
|
const r = Object.keys(t);
|
|
92
92
|
return e ? r.map((n) => "." + n) : r;
|
|
93
93
|
}
|
|
@@ -150,7 +150,7 @@ class Z {
|
|
|
150
150
|
}
|
|
151
151
|
const i = Object.values(n);
|
|
152
152
|
for (const s of i)
|
|
153
|
-
|
|
153
|
+
E(s) ? s.value = this.replaceLibraryPath(s) : r(s);
|
|
154
154
|
};
|
|
155
155
|
r(e);
|
|
156
156
|
}
|
|
@@ -194,7 +194,7 @@ function ee(t = []) {
|
|
|
194
194
|
}`);
|
|
195
195
|
}
|
|
196
196
|
function te(t = []) {
|
|
197
|
-
const e = (r) => r ? `[${
|
|
197
|
+
const e = (r) => r ? `[${q(r).map((s) => s.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
198
198
|
return t.map((r) => typeof r == "string" ? `${r}: {}` : `${r.name}: {
|
|
199
199
|
type:${e(r.type)},
|
|
200
200
|
required: ${r.required},
|
|
@@ -206,8 +206,8 @@ function re(t = []) {
|
|
|
206
206
|
}
|
|
207
207
|
function g(t = {}, e = []) {
|
|
208
208
|
return Object.entries(t).map(([r, n]) => {
|
|
209
|
-
let i =
|
|
210
|
-
return i =
|
|
209
|
+
let i = R(p(n, !1, !1));
|
|
210
|
+
return i = P(i, e), i.startsWith("async") ? `async ${r}${i.replace(/^async/, "")}` : `${r}${i}`;
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
function ne(t = [], e = []) {
|
|
@@ -217,7 +217,7 @@ function ne(t = [], e = []) {
|
|
|
217
217
|
), n = g(r, e), i = t.map((s) => `watcher_${s.id}: {
|
|
218
218
|
deep: ${s.deep},
|
|
219
219
|
immediate:${s.immediate},
|
|
220
|
-
handler${
|
|
220
|
+
handler${R(s.handler.value)}
|
|
221
221
|
}`);
|
|
222
222
|
return {
|
|
223
223
|
computed: n,
|
|
@@ -232,40 +232,40 @@ function se(t = {}) {
|
|
|
232
232
|
}`;
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function L(t, e, r = [], n = {}, i) {
|
|
236
236
|
const s = [];
|
|
237
237
|
let o = {}, a = [], c = [];
|
|
238
238
|
return oe(t).forEach((h) => {
|
|
239
|
-
const
|
|
239
|
+
const y = [];
|
|
240
240
|
for (const u of h.children) {
|
|
241
|
-
let { id: b, name: l, invisible:
|
|
242
|
-
if (
|
|
241
|
+
let { id: b, name: l, invisible: $, from: w } = u;
|
|
242
|
+
if ($)
|
|
243
243
|
continue;
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
const { props:
|
|
244
|
+
const A = ie(l, e, w);
|
|
245
|
+
A && a.push(A), ae(w) && c.push({ id: w.id, name: l });
|
|
246
|
+
const { props: W, events: B, handlers: T } = fe(
|
|
247
247
|
b,
|
|
248
248
|
u.props,
|
|
249
249
|
u.events,
|
|
250
250
|
n,
|
|
251
251
|
r
|
|
252
|
-
),
|
|
252
|
+
), V = me(u.directives).join(" "), f = u.children ? he(
|
|
253
253
|
u.children,
|
|
254
254
|
r,
|
|
255
255
|
e,
|
|
256
256
|
n,
|
|
257
257
|
u
|
|
258
258
|
) : "";
|
|
259
|
-
Object.assign(o,
|
|
259
|
+
Object.assign(o, T);
|
|
260
260
|
let S = "";
|
|
261
261
|
typeof f == "string" ? S = f : (S = (f?.nodes || []).join(`
|
|
262
|
-
`), Object.assign(o, f?.methods || {}), a = a.concat(f?.components || []), c = c.concat(f?.importBlocks || [])),
|
|
263
|
-
`<${l} ${
|
|
262
|
+
`), Object.assign(o, f?.methods || {}), a = a.concat(f?.components || []), c = c.concat(f?.importBlocks || [])), y.push(
|
|
263
|
+
`<${l} ${V} ${W} ${B}>
|
|
264
264
|
${S}
|
|
265
265
|
</${l}>`
|
|
266
266
|
);
|
|
267
267
|
}
|
|
268
|
-
const j =
|
|
268
|
+
const j = ye(h.slot, y.join(`
|
|
269
269
|
`), i?.id);
|
|
270
270
|
s.push(j);
|
|
271
271
|
}), {
|
|
@@ -297,10 +297,10 @@ function ae(t) {
|
|
|
297
297
|
return !!t && typeof t == "object" && t.type === "Schema";
|
|
298
298
|
}
|
|
299
299
|
function ce(t, e, r = []) {
|
|
300
|
-
return typeof e == "string" ? `${t}="${e}"` :
|
|
300
|
+
return typeof e == "string" ? `${t}="${e}"` : E(e) ? `:${t}="${p({
|
|
301
301
|
...e,
|
|
302
|
-
value:
|
|
303
|
-
})}"` :
|
|
302
|
+
value: P(e.value, r)
|
|
303
|
+
})}"` : D(e) ? `:${t}='{${Y(
|
|
304
304
|
e
|
|
305
305
|
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
306
306
|
}
|
|
@@ -308,7 +308,7 @@ function pe(t = {}, e = []) {
|
|
|
308
308
|
return Object.entries(t).map(([r, n]) => ce(r, n, e));
|
|
309
309
|
}
|
|
310
310
|
function ue(t, e, r, n) {
|
|
311
|
-
const i =
|
|
311
|
+
const i = J(e.modifiers, !0);
|
|
312
312
|
return n && n.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${r}"` : `@${t}${i.join("")}="${r}"`;
|
|
313
313
|
}
|
|
314
314
|
function le(t, e = {}, r = {}) {
|
|
@@ -338,7 +338,7 @@ function fe(t, e = {}, r = {}, n = {}, i) {
|
|
|
338
338
|
function me(t = []) {
|
|
339
339
|
const e = [], { vIf: r, vShow: n, vModels: i, vFor: s } = de(t);
|
|
340
340
|
if (r && e.push(`v-if="${p(r.value)}"`), n && e.push(`v-show="${p(n.value)}"`), i.forEach((o) => {
|
|
341
|
-
const a =
|
|
341
|
+
const a = J(o.modifiers, !0), c = o.arg ? C(o.arg) ? `:[${p(o.arg)}]` : `:${o.arg}` : "";
|
|
342
342
|
e.push(`v-model${c}${a}="${p(o.value)}"`);
|
|
343
343
|
}), s) {
|
|
344
344
|
const { item: o, index: a } = { item: "item", index: "index", ...s.iterator };
|
|
@@ -361,11 +361,11 @@ function he(t, e, r, n, i) {
|
|
|
361
361
|
return t;
|
|
362
362
|
if (C(t)) {
|
|
363
363
|
let s = p(t, !1);
|
|
364
|
-
return s =
|
|
364
|
+
return s = P(s, e), s = I(s), `{{ ${s} }}`;
|
|
365
365
|
}
|
|
366
|
-
return Array.isArray(t) ?
|
|
366
|
+
return Array.isArray(t) ? L(t, r, e, n, i) : "";
|
|
367
367
|
}
|
|
368
|
-
function
|
|
368
|
+
function ye(t, e, r) {
|
|
369
369
|
if (!t)
|
|
370
370
|
return e;
|
|
371
371
|
const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
|
|
@@ -373,7 +373,7 @@ function $e(t, e, r) {
|
|
|
373
373
|
${e}
|
|
374
374
|
</template>`;
|
|
375
375
|
}
|
|
376
|
-
function
|
|
376
|
+
function $e(t, e = [], r = [], n = {}) {
|
|
377
377
|
const i = {
|
|
378
378
|
vue: ["defineComponent", "reactive"]
|
|
379
379
|
};
|
|
@@ -388,7 +388,7 @@ function ye(t, e = [], r = [], n = {}) {
|
|
|
388
388
|
)}} from '${s}';`).concat(r);
|
|
389
389
|
}
|
|
390
390
|
function ge(t, e) {
|
|
391
|
-
const { dsl: r } = t, n = Object.keys(r.computed || {}), i = g(r.lifeCycles, n), s = g(r.computed, n), o = ne(r.watch, n), a = se(r.dataSources), { methods: c, nodes: d, components: h, importBlocks:
|
|
391
|
+
const { dsl: r } = t, n = Object.keys(r.computed || {}), i = g(r.lifeCycles, n), s = g(r.computed, n), o = ne(r.watch, n), a = se(r.dataSources), { methods: c, nodes: d, components: h, importBlocks: y } = L(
|
|
392
392
|
r.nodes || [],
|
|
393
393
|
e,
|
|
394
394
|
n,
|
|
@@ -399,7 +399,7 @@ function ge(t, e) {
|
|
|
399
399
|
...r.methods || {}
|
|
400
400
|
},
|
|
401
401
|
n
|
|
402
|
-
), b =
|
|
402
|
+
), b = y.map(($) => `import ${$.name} from '$vtj/raw/${$.id}.vue';`), l = $e(
|
|
403
403
|
e,
|
|
404
404
|
h,
|
|
405
405
|
b,
|
|
@@ -464,14 +464,30 @@ export default defineComponent({
|
|
|
464
464
|
</style>
|
|
465
465
|
`, be = F(ve), we = F(je);
|
|
466
466
|
async function Ce(t, e = /* @__PURE__ */ new Map(), r = [], n) {
|
|
467
|
-
const i = new Z(
|
|
467
|
+
const i = new Z(M(t), r), s = ge(i, e), o = be(s), a = we({
|
|
468
468
|
template: s.template,
|
|
469
469
|
css: await X(s.css, n),
|
|
470
470
|
script: await U(o, n)
|
|
471
471
|
});
|
|
472
|
-
return await
|
|
472
|
+
return await N(a, n);
|
|
473
|
+
}
|
|
474
|
+
async function Oe(t) {
|
|
475
|
+
const e = `
|
|
476
|
+
<template>
|
|
477
|
+
<div>
|
|
478
|
+
<h3>源码模式页面</h3>
|
|
479
|
+
<div>文件路径:/src/views/${t.id}.vue</div>
|
|
480
|
+
</div>
|
|
481
|
+
</template>
|
|
482
|
+
<script lang="ts" setup>
|
|
483
|
+
<\/script>
|
|
484
|
+
<style scoped lang="scss">
|
|
485
|
+
</style>
|
|
486
|
+
`;
|
|
487
|
+
return await N(e);
|
|
473
488
|
}
|
|
474
489
|
export {
|
|
475
490
|
ke as VTJ_CODER_VERSION,
|
|
491
|
+
Oe as createEmptyPage,
|
|
476
492
|
Ce as generator
|
|
477
493
|
};
|
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.4",
|
|
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.2",
|
|
14
|
-
"@vtj/core": "^0.7.
|
|
14
|
+
"@vtj/core": "^0.7.4",
|
|
15
15
|
"prettier": "~3.2.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@vtj/cli": "^0.7.
|
|
18
|
+
"@vtj/cli": "^0.7.3"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"types"
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "7c7bb7bd2696a691987bd58f20e118987e1cf404",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
}
|
package/types/generator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BlockSchema, type MaterialDescription, type Dependencie } from '@vtj/core';
|
|
1
|
+
import { type BlockSchema, type MaterialDescription, type Dependencie, type PageFile } from '@vtj/core';
|
|
2
2
|
/**
|
|
3
3
|
* 代码生成器 处理过程:
|
|
4
4
|
* 1. Generator 读取 dsl、componentMap、dependencies
|
|
@@ -7,3 +7,4 @@ import { type BlockSchema, type MaterialDescription, type Dependencie } from '@v
|
|
|
7
7
|
* 4. Compiled token 注入模板生成代码文件字符串
|
|
8
8
|
*/
|
|
9
9
|
export declare function generator(dsl: BlockSchema, componentMap?: Map<string, MaterialDescription>, dependencies?: Dependencie[], formatterDisabled?: boolean): Promise<string>;
|
|
10
|
+
export declare function createEmptyPage(file: PageFile): Promise<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.7.
|
|
5
|
+
* @version 0.7.4
|
|
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.4";
|