@vtj/coder 0.7.7 → 0.7.10
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 +12 -14
- package/dist/index.mjs +11 -8
- package/package.json +4 -4
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
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.10
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const U="0.7.
|
|
7
|
+
*/const U="0.7.10",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);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 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=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
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
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
|
-
|
|
23
|
-
</${f}>`)}const b=ge(h.slot,y.join(`
|
|
24
|
-
`),i?.id);s.push(b)}),{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:_(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=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=`${u.camelCase(a)}_handler_${t}${s}`;return n[d]=i.length?{type:"JSFunction",value:`{
|
|
21
|
+
`),Object.assign(o,m?.methods||{}),a=a.concat(m?.components||[]),c=c.concat(m?.importBlocks||[])),y.push(`<${f} ${W} ${T} ${J}>${S.trim()}</${f}>`)}const b=ge(h.slot,y.join(`
|
|
22
|
+
`),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
23
|
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:
|
|
24
|
+
}`}: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
25
|
${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 { ${
|
|
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 { ${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 './${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
27
|
`),components:h.join(","),returns:t.members.join(","),template:d.join(`
|
|
30
28
|
`),css:r.css||""}}const be=`
|
|
31
29
|
<%= imports %>
|
|
@@ -63,7 +61,7 @@ export default defineComponent({
|
|
|
63
61
|
<style lang="scss" scoped>
|
|
64
62
|
<%= css %>
|
|
65
63
|
</style>
|
|
66
|
-
`,we=
|
|
64
|
+
`,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
65
|
<template>
|
|
68
66
|
<div>
|
|
69
67
|
<h3>源码模式页面</h3>
|
package/dist/index.mjs
CHANGED
|
@@ -8,10 +8,10 @@ import * as H 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.10
|
|
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.10", k = {
|
|
15
15
|
arrowParens: "always",
|
|
16
16
|
bracketSpacing: !0,
|
|
17
17
|
bracketSameLine: !0,
|
|
@@ -115,7 +115,9 @@ class Z {
|
|
|
115
115
|
if (r.length === 4) {
|
|
116
116
|
const n = r.pop(), i = r.join(".") + ".", s = r.pop();
|
|
117
117
|
if (n && s) {
|
|
118
|
-
const o = this.dependencies.find(
|
|
118
|
+
const o = this.dependencies.find(
|
|
119
|
+
(a) => a.library === s
|
|
120
|
+
)?.package;
|
|
119
121
|
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(n);
|
|
120
122
|
}
|
|
121
123
|
return {
|
|
@@ -134,7 +136,10 @@ class Z {
|
|
|
134
136
|
const s = e.value.match(i) || [];
|
|
135
137
|
for (const o of s) {
|
|
136
138
|
const a = this.collectImport(o);
|
|
137
|
-
|
|
139
|
+
if (a) {
|
|
140
|
+
const c = a.path.replace(/\$/g, "\\$");
|
|
141
|
+
n = n.replace(new RegExp(c, "g"), "");
|
|
142
|
+
}
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
145
|
return n;
|
|
@@ -260,9 +265,7 @@ function L(t, e, r = [], n = {}, i) {
|
|
|
260
265
|
let S = "";
|
|
261
266
|
typeof f == "string" ? S = f : (S = (f?.nodes || []).join(`
|
|
262
267
|
`), Object.assign(o, f?.methods || {}), a = a.concat(f?.components || []), c = c.concat(f?.importBlocks || [])), y.push(
|
|
263
|
-
`<${l} ${V} ${W} ${B}
|
|
264
|
-
${S}
|
|
265
|
-
</${l}>`
|
|
268
|
+
`<${l} ${V} ${W} ${B}>${S.trim()}</${l}>`
|
|
266
269
|
);
|
|
267
270
|
}
|
|
268
271
|
const j = ye(h.slot, y.join(`
|
|
@@ -399,7 +402,7 @@ function ge(t, e) {
|
|
|
399
402
|
...r.methods || {}
|
|
400
403
|
},
|
|
401
404
|
n
|
|
402
|
-
), b = y.map(($) => `import ${$.name} from '
|
|
405
|
+
), b = y.map(($) => `import ${$.name} from './${$.id}.vue';`), l = $e(
|
|
403
406
|
e,
|
|
404
407
|
h,
|
|
405
408
|
b,
|
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.10",
|
|
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.3",
|
|
14
|
-
"@vtj/core": "^0.7.
|
|
14
|
+
"@vtj/core": "^0.7.10",
|
|
15
15
|
"prettier": "~3.2.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@vtj/cli": "^0.7.
|
|
18
|
+
"@vtj/cli": "^0.7.7"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"types"
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "6c54f72d57ad363d1ed75a36f25aed10d6b6a262",
|
|
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.10
|
|
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.10";
|