@vtj/coder 0.9.2 → 0.9.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 +24 -21
- package/dist/index.mjs +70 -62
- package/package.json +3 -3
- package/types/version.d.ts +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@vtj/base"),
|
|
2
|
-
* Copyright (c)
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@vtj/base"),A=require("prettier/standalone"),Y=require("prettier/plugins/html"),Z=require("prettier/plugins/babel"),K=require("prettier/plugins/postcss"),ee=require("prettier/plugins/estree");function _(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const te=_(Y),J=_(Z),q=_(K),L=_(ee);/**!
|
|
2
|
+
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.9.
|
|
5
|
+
* @version 0.9.4
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const se="0.9.
|
|
8
|
-
* Copyright (c)
|
|
7
|
+
*/const se="0.9.4";/**!
|
|
8
|
+
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/core
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.9.
|
|
11
|
+
* @version 0.9.4
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
-
*/const ne=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const
|
|
13
|
+
*/const ne=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const F={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 D(t,e){return e?t:await A.format(t,{parser:"vue",...F,plugins:[te,J,L,q]})}async function re(t,e){return e?t:await A.format(t,{parser:"babel-ts",...F,plugins:[J,L]})}async function T(t,e){return e?t:A.format(t,{parser:"scss",...F,plugins:[q]})}function S(t){return t&&t.type==="JSExpression"}function O(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function k(t){return S(t)||O(t)}function U(t){return t.replace(new RegExp("this.","g"),"")}function R(t){return t.replace(/this\.context\??\./g,"")}function p(t,e=!0,s=!0,n=[]){let i=k(t)?t.value:e?JSON.stringify(t):t;return i=x(i,n),s?U(R(i)):R(i)}function x(t,e=[]){let s=t;for(const n of e)s=s.replace(new RegExp(`this.${n}.value`,"g"),`this.${n}`);return s}function M(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]+)/,r=e.match(i);r&&r[2]&&(r[2].startsWith("{")||(e=e.replace(r[2],`{ return ${r[2]} }`))),e=e.replace("=>","")}return e}function ie(t={}){return Object.entries(t).map(([e,s])=>`"${e}": ${p(s)}`)}function V(t={},e=!1){const s=Object.keys(t);return e?s.map(n=>"."+n):s}function oe(t){let e="";for(var s in t)if(t.hasOwnProperty(s)){var n=t[s];e+=s+": "+n+";"}return e}class ae{constructor(e,s){this.dsl=e,this.dependencies=s,this.libraryRegex=this.collectLibrary(),this.walk(e),this.walkNodes(e),this.members=this.getLibraryMember()}imports={};context={};style={};members=[];urlSchemas={};blockPlugins={};libraryRegex=[];collectLibrary(){return this.dependencies.filter(e=>!!e.library).map(e=>new RegExp(`(this.\\$libs.${e.library}.([\\w]+))`,"g"))}collectImport(e){const s=e.split(".");if(s.length===4){const n=s.pop(),i=s.join(".")+".",r=s.pop();if(n&&r){const o=this.dependencies.find(a=>a.library===r)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(n)}return{name:n,path:i,library:r}}return null}replaceLibraryPath(e){const{libraryRegex:s}=this;let n=e.value;for(const i of s){const r=e.value?.match(i)||[];for(const o of r){const a=this.collectImport(o);if(a){const u=a.path.replace(/\$/g,"\\$");n=n.replace(new RegExp(u,"g"),"")}}}return n}walk(e){const s=n=>{if(!n||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)s(r);return}const i=Object.values(n);for(const r of i)k(r)?r.value=this.replaceLibraryPath(r):s(r)};s(e)}getLibraryMember(e=[]){let s=[...e];for(const n of Object.values(this.imports))s=s.concat(Array.from(n));return f.dedupArray(s)}collectContext(e,s){const n=new Set(s?.id?this.context[s.id]:[]),i=(e.directives||[]).find(a=>a.name==="vFor");let r=new Set(Array.from(n));if(i){const{item:a="item",index:u="index"}=i.iterator||{};r=new Set([a,u,...Array.from(r)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],u=a.length?a:[`scope_${s?.id}`];r=new Set([...u,...Array.from(r)])}this.context[e.id]=r}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&(this.style[`.${e.name}_${e.id}`]=e.props.style)}collectUrlSchema(e){typeof e.from=="object"&&e.from.type==="UrlSchema"&&(this.urlSchemas[e.name]=e.from)}collectBlockPlugin(e){typeof e.from=="object"&&e.from.type==="Plugin"&&(this.blockPlugins[e.name]=e.from)}walkNodes(e){const s=(n,i)=>{this.collectContext(n,i),this.collectStyle(n),this.collectUrlSchema(n),this.collectBlockPlugin(n),Array.isArray(n.children)&&n.children.forEach(r=>s(r,n))};Array.isArray(e.nodes)&&e.nodes.forEach(n=>s(n))}}function ce(t={}){return Object.entries(t).map(([e,s])=>{const n=p(s,!1);return`${e}:${n}`})}function le(t=[]){return t.map(e=>`${e.name}: {
|
|
14
14
|
from: '${e.from||e.name}',
|
|
15
15
|
default: ${p(e.default,!0,!1)}
|
|
16
|
-
}`)}function ue(t=[]){const e=s=>s?`[${f.toArray(s).map(r=>r.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:(
|
|
16
|
+
}`)}function ue(t=[]){const e=s=>s?`[${f.toArray(s).map(r=>r.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:(k(s.default)&&!s.default.value&&(s.default.value="undefined"),`${s.name}: {
|
|
17
17
|
type:${e(s.type)},
|
|
18
18
|
required: ${p(!!s.required,!0,!1)},
|
|
19
19
|
default: ${p(s.default,!0,!1)}
|
|
20
|
-
}`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function C(t={},e=[]){return Object.entries(t).map(([s,n])=>{let i=
|
|
20
|
+
}`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function C(t={},e=[]){return Object.entries(t).map(([s,n])=>{let i=M(p(n,!1,!1));return i=x(i,e),i.startsWith("async")?`async ${s}${i.replace(/^async/,"")}`:`${s}${i}`})}function pe(t=[],e=[]){const s=t.reduce((r,o)=>(o.id&&O(o.source)&&(r[`watcher_${o.id}`]=o.source),r),{}),n=C(s,e),i=t.map(r=>`watcher_${r.id}: {
|
|
21
21
|
deep: ${r.deep},
|
|
22
22
|
immediate:${r.immediate},
|
|
23
|
-
handler${
|
|
24
|
-
}`);return{computed:n,watches:i}}function me(t={}){return Object.values(t).map(e=>{const s=
|
|
23
|
+
handler${M(r.handler.value)}
|
|
24
|
+
}`);return{computed:n,watches:i}}function me(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const s=O(e.mockTemplate)&&e.mockTemplate.value||"(params) => ({})";return`async ${e.name}(...args:any[]) {
|
|
25
|
+
const mock = this.provider.createMock(${s})
|
|
26
|
+
return await mock.apply(this, args);
|
|
27
|
+
}`}else{const s=O(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
25
28
|
return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
|
|
26
|
-
}`})}const
|
|
27
|
-
`),Object.assign(o,b?.methods||{}),
|
|
29
|
+
}`}})}const W=["vIf","vShow","vModel","vFor","vBind","vHtml"];function H(t,e,s=[],n={},i){const r=[];let o={},a=[];const u=[];let c=[];return de(t).forEach(l=>{const m=[];for(const d of l.children){let{id:v,name:g,invisible:E,from:$}=d;if(E)continue;const w=ye(g,e,$);w&&a.push(w),Q($)&&c.push({id:$.id,name:g});const{props:j,events:I,handlers:X}=je(d,v,d.props,d.events,n,s),N=Se(d.directives,s,u).join(" "),b=d.children?we(d.children,s,e,n,d):"";Object.assign(o,X);let P="";typeof b=="string"?P=b:(P=(b?.nodes||[]).join(`
|
|
30
|
+
`),Object.assign(o,b?.methods||{}),a=a.concat(b?.components||[]),c=c.concat(b?.importBlocks||[]));const B=z($)||G($)?"component":g;m.push(g==="img"?`<${g} ${N} ${j} ${I} />`:`<${B} ${N} ${j} ${I}>${P?`
|
|
28
31
|
`+P.trim():""}</${B}>`)}const h=Pe(l.slot,m.join(`
|
|
29
|
-
`),i?.id);r.push(h)}),{nodes:r,methods:o,directives:he(u),components:f.dedupArray(
|
|
32
|
+
`),i?.id);r.push(h)}),{nodes:r,methods:o,directives:he(u),components:f.dedupArray(a),importBlocks:f.dedupArray(c,"id")}}function he(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function de(t=[]){const e=new Map;for(const s of t){const n=typeof s.slot=="string"?s.slot:s.slot?.name,i=e.get(n);i?i.children.push(s):e.set(n,{slot:s.slot,children:[s]})}return e}function ye(t,e,s){if(ne.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 Q(s)||n?t:null}function Q(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function z(t){return typeof t=="object"&&t.type==="UrlSchema"}function G(t){return typeof t=="object"&&t.type==="Plugin"}function ge(t,e,s=[]){return t==="style"?"":t==="__class"&&k(e)?`:class="${p({...e,value:x(e.value,s)})}"`:typeof e=="string"?`${t}="${e}"`:k(e)?`:${t}="${p({...e,value:x(e.value,s)})}"`:f.isPlainObject(e)?`:${t}='{${ie(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function $e(t,e={},s=[]){if(!!Object.keys(e.style||{}).length){const r=`${t.name}_${t.id}`;e.class?typeof e.class=="string"?e.class=[e.class,r].join(" "):(e.__class=e.class,e.class=r):(e.class=r,delete e.style)}const i=t.from;return(z(i)||G(i))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([r,o])=>ge(r,o,s))}function ve(t,e,s,n,i){const r=V(e.modifiers,!0);return i?`@${t}${r.join("")}="${s}"`:n&&n.length>0?`@${t}${r.join("")}="(...args:any[]) => ${s}"`:`@${t}${r.join("")}="${s}"`}function be(t,e={},s={}){const n={},i=Array.from(s[t]||new Set([])),r=i.length?`({${i.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,u])=>{const c=u.handler.value.startsWith("this."),y=c?U(u.handler.value):`${f.camelCase(a)}_${t}${r}`;return c||(n[y]=i.length?{type:"JSFunction",value:`{
|
|
30
33
|
return (${u.handler.value}).apply(this, args);
|
|
31
|
-
}`}:u.handler),ve(
|
|
34
|
+
}`}:u.handler),ve(a,u,y,i,c)}),handlers:n}}function je(t,e,s={},n={},i={},r){const{binders:o,handlers:a}=be(e,n,i);return{props:$e(t,s,r).join(" "),handlers:a,binders:o,events:o.join(" ")}}function Se(t=[],e=[],s=[]){const n=[],{vIf:i,vShow:r,vModels:o,vFor:a,vBind:u,vHtml:c,customDirectives:y}=ke(t);if(i&&n.push(`v-if="${p(i.value,!0,!0,e)}"`),r&&n.push(`v-show="${p(r.value,!0,!0,e)}"`),u&&n.push(`v-bind="${p(u.value,!0,!0,e)}"`),o.forEach(l=>{const m=V(l.modifiers,!0),h=l.arg?S(l.arg)?`:[${p(l.arg,!0,!0,e)}]`:`:${l.arg}`:"";n.push(`v-model${h}${m}="${p(l.value,!0,!0,e)}"`)}),a){const{item:l,index:m}={item:"item",index:"index",...a.iterator};n.push(`v-for="(${l}, ${m}) in ${p(a.value,!0,!0,e)}"`)}return c&&n.push(`v-html="${p(c.value,!0,!0,e)}"`),y&&y.length&&y.forEach(l=>{if(!l.name)return;let m="",h="";S(l.name)?(h=p(l.name,!0,!0,e),s.push(h)):h=l.name;const d=h?.startsWith("v")?f.kebabCase(h):f.kebabCase("v-"+h);if(m+=d,l.arg&&(S(l.arg)?m+=`:[${p(l.name,!0,!0,e)}]`:m+=`:${l.arg}`),l.modifiers){const v=Object.keys(l.modifiers);v.length&&(m+=v.map(g=>"."+g))}l.value?n.push(`${m}="${p(l.value,!0,!0,e)}"`):n.push(m)}),n}function ke(t=[]){const e=t.filter(c=>W.includes(c.name)),s=t.filter(c=>!W.includes(c.name)),n=e.find(c=>f.camelCase(c.name)==="vIf"),i=e.find(c=>f.camelCase(c.name)==="vFor"),r=e.find(c=>f.camelCase(c.name)==="vShow"),o=e.find(c=>f.camelCase(c.name)==="vBind"),a=e.find(c=>f.camelCase(c.name)==="vHtml"),u=e.filter(c=>f.camelCase(c.name)==="vModel");return{vIf:n,vFor:i,vShow:r,vModels:u,vBind:o,vHtml:a,customDirectives:s}}function we(t,e,s,n,i){return typeof t=="string"?t:S(t)?`{{ ${p(t,!1,!0,e)} }}`:Array.isArray(t)?H(t,s,e,n,i):""}function Pe(t,e,s){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_${s}`}"`}>
|
|
32
35
|
${e}
|
|
33
36
|
</template>`}function Ce(t,e=[],s=[],n={}){const i={vue:["defineComponent","reactive"]};for(const r of e){const o=t.get(r.split(":")[0]);o&&o.package&&(i[o.package]??(i[o.package]=[])).push(o.parent||(o.alias||"").split(".")[0]||o.name)}for(const[r,o]of Object.entries(n))(i[r]??(i[r]=[])).push(...Array.from(o));return Object.entries(i).filter(([r,o])=>!!o.length).map(([r,o])=>`import { ${f.dedupArray(o).join(",")}} from '${r}';`).concat(s)}function Oe(t={}){const e=[];for(const[s,n]of Object.entries(t))e.push(`
|
|
34
37
|
${s} {
|
|
35
38
|
${oe(n)}
|
|
36
39
|
}
|
|
37
40
|
`);return e.join(`
|
|
38
|
-
`)}function xe(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`)}),e}function _e(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`)}),e}function Ee(t,e){const{dsl:s}=t,n=Object.keys(s.computed||{}),i=C(s.lifeCycles,n),r=C(s.computed,n),o=pe(s.watch,n),
|
|
41
|
+
`)}function xe(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`)}),e}function _e(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`)}),e}function Ee(t,e){const{dsl:s}=t,n=Object.keys(s.computed||{}),i=C(s.lifeCycles,n),r=C(s.computed,n),o=pe(s.watch,n),a=me(s.dataSources),{methods:u,nodes:c,components:y,importBlocks:l,directives:m}=H(s.nodes||[],e,n,t.context),h=[...r,...o.computed],d=C({...u,...s.methods||{}},n),v=l.map(j=>`import ${j.name} from './${j.id}.vue';`),g=Ce(e,y,v,t.imports),E=Object.keys({...t.urlSchemas,...t.blockPlugins}),$=xe(t.urlSchemas),w=_e(t.blockPlugins);return{id:s.id,version:s.__VERSION__,name:s.name,state:ce(s.state).join(","),inject:le(s.inject).join(","),props:ue(s.props).join(","),emits:fe(s.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:h.join(","),methods:[...a,...d].join(","),imports:`
|
|
39
42
|
`+g.join(`
|
|
40
|
-
`),components:y.join(","),directives:m.join(","),returns:t.members.join(","),template:
|
|
43
|
+
`),components:y.join(","),directives:m.join(","),returns:t.members.join(","),template:c.join(`
|
|
41
44
|
`),css:s.css||"",style:Oe(t.style),urlSchemas:$.join(`
|
|
42
|
-
`),blockPlugins:
|
|
43
|
-
`),asyncComponents:
|
|
45
|
+
`),blockPlugins:w.join(`
|
|
46
|
+
`),asyncComponents:E.join(",")}}const Ae=`
|
|
44
47
|
// @ts-nocheck
|
|
45
48
|
|
|
46
49
|
<%= imports %>
|
|
@@ -83,7 +86,7 @@ export default defineComponent({
|
|
|
83
86
|
<%= css %>
|
|
84
87
|
<%= style %>
|
|
85
88
|
</style>
|
|
86
|
-
`,Ie=f.template(Ae),Ne=f.template(Fe);async function Be(t,e=new Map,s=[],n){const i=new
|
|
89
|
+
`,Ie=f.template(Ae),Ne=f.template(Fe);async function Be(t,e=new Map,s=[],n){const i=new ae(f.cloneDeep(t),s),r=Ee(i,e),o=Ie(r),a=Ne({template:r.template,css:await T(r.css,n),script:await re(o,n),style:await T(r.style,n)});return await D(a,n).catch(u=>(u.content=a,Promise.reject(u)))}async function Te(t){const e=`
|
|
87
90
|
<template>
|
|
88
91
|
<div>
|
|
89
92
|
<h3>源码模式页面</h3>
|
|
@@ -94,4 +97,4 @@ export default defineComponent({
|
|
|
94
97
|
<\/script>
|
|
95
98
|
<style scoped lang="scss">
|
|
96
99
|
</style>
|
|
97
|
-
`;return await D(e)}exports.VTJ_CODER_VERSION=se;exports.createEmptyPage=
|
|
100
|
+
`;return await D(e)}exports.VTJ_CODER_VERSION=se;exports.createEmptyPage=Te;exports.generator=Be;
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { mitt as K, dedupArray as
|
|
2
|
-
import { format as
|
|
1
|
+
import { mitt as K, dedupArray as k, toArray as ee, kebabCase as R, camelCase as $, isPlainObject as te, template as L, cloneDeep as se } from "@vtj/base";
|
|
2
|
+
import { format as A } from "prettier/standalone";
|
|
3
3
|
import * as ne from "prettier/plugins/html";
|
|
4
4
|
import * as U from "prettier/plugins/babel";
|
|
5
5
|
import * as D from "prettier/plugins/postcss";
|
|
6
6
|
import * as V from "prettier/plugins/estree";
|
|
7
7
|
/**!
|
|
8
|
-
* Copyright (c)
|
|
8
|
+
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/coder
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.9.
|
|
11
|
+
* @version 0.9.4
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const We = "0.9.4";
|
|
15
15
|
/**!
|
|
16
|
-
* Copyright (c)
|
|
16
|
+
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
17
17
|
* @name @vtj/core
|
|
18
18
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
19
|
-
* @version 0.9.
|
|
19
|
+
* @version 0.9.4
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const re = [
|
|
@@ -33,7 +33,7 @@ const re = [
|
|
|
33
33
|
"a"
|
|
34
34
|
];
|
|
35
35
|
K();
|
|
36
|
-
const
|
|
36
|
+
const F = {
|
|
37
37
|
arrowParens: "always",
|
|
38
38
|
bracketSpacing: !0,
|
|
39
39
|
bracketSameLine: !0,
|
|
@@ -53,47 +53,47 @@ const A = {
|
|
|
53
53
|
useTabs: !1,
|
|
54
54
|
vueIndentScriptAndStyle: !0
|
|
55
55
|
};
|
|
56
|
-
async function
|
|
57
|
-
return e ? t : await
|
|
56
|
+
async function M(t, e) {
|
|
57
|
+
return e ? t : await A(t, {
|
|
58
58
|
parser: "vue",
|
|
59
|
-
...
|
|
59
|
+
...F,
|
|
60
60
|
plugins: [ne, U, V, D]
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
async function ie(t, e) {
|
|
64
|
-
return e ? t : await
|
|
64
|
+
return e ? t : await A(t, {
|
|
65
65
|
parser: "babel-ts",
|
|
66
|
-
...
|
|
66
|
+
...F,
|
|
67
67
|
plugins: [U, V]
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
async function
|
|
71
|
-
return e ? t :
|
|
70
|
+
async function T(t, e) {
|
|
71
|
+
return e ? t : A(t, {
|
|
72
72
|
parser: "scss",
|
|
73
|
-
...
|
|
73
|
+
...F,
|
|
74
74
|
plugins: [D]
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
function S(t) {
|
|
78
78
|
return t && t.type === "JSExpression";
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function O(t) {
|
|
81
81
|
return typeof t == "object" && t && t.type === "JSFunction";
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return S(t) ||
|
|
83
|
+
function w(t) {
|
|
84
|
+
return S(t) || O(t);
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function q(t) {
|
|
87
87
|
return t.replace(new RegExp("this.", "g"), "");
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function W(t) {
|
|
90
90
|
return t.replace(/this\.context\??\./g, "");
|
|
91
91
|
}
|
|
92
92
|
function f(t, e = !0, s = !0, n = []) {
|
|
93
|
-
let i =
|
|
94
|
-
return i =
|
|
93
|
+
let i = w(t) ? t.value : e ? JSON.stringify(t) : t;
|
|
94
|
+
return i = E(i, n), s ? q(W(i)) : W(i);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function E(t, e = []) {
|
|
97
97
|
let s = t;
|
|
98
98
|
for (const n of e)
|
|
99
99
|
s = s.replace(
|
|
@@ -102,7 +102,7 @@ function O(t, e = []) {
|
|
|
102
102
|
);
|
|
103
103
|
return s;
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function H(t) {
|
|
106
106
|
let e = t.trim();
|
|
107
107
|
if (e = /^\((\(|async|function)/.test(e) ? e.substring(1, e.length - 1) : e, e.startsWith("{")) return e;
|
|
108
108
|
if (e.startsWith("async function"))
|
|
@@ -176,7 +176,7 @@ class ae {
|
|
|
176
176
|
const { libraryRegex: s } = this;
|
|
177
177
|
let n = e.value;
|
|
178
178
|
for (const i of s) {
|
|
179
|
-
const r = e.value
|
|
179
|
+
const r = e.value?.match(i) || [];
|
|
180
180
|
for (const o of r) {
|
|
181
181
|
const c = this.collectImport(o);
|
|
182
182
|
if (c) {
|
|
@@ -197,7 +197,7 @@ class ae {
|
|
|
197
197
|
}
|
|
198
198
|
const i = Object.values(n);
|
|
199
199
|
for (const r of i)
|
|
200
|
-
|
|
200
|
+
w(r) ? r.value = this.replaceLibraryPath(r) : s(r);
|
|
201
201
|
};
|
|
202
202
|
s(e);
|
|
203
203
|
}
|
|
@@ -205,7 +205,7 @@ class ae {
|
|
|
205
205
|
let s = [...e];
|
|
206
206
|
for (const n of Object.values(this.imports))
|
|
207
207
|
s = s.concat(Array.from(n));
|
|
208
|
-
return
|
|
208
|
+
return k(s);
|
|
209
209
|
}
|
|
210
210
|
collectContext(e, s) {
|
|
211
211
|
const n = new Set(s?.id ? this.context[s.id] : []), i = (e.directives || []).find((c) => c.name === "vFor");
|
|
@@ -251,7 +251,7 @@ function ue(t = []) {
|
|
|
251
251
|
}
|
|
252
252
|
function fe(t = []) {
|
|
253
253
|
const e = (s) => s ? `[${ee(s).map((r) => r.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
254
|
-
return t.map((s) => typeof s == "string" ? `${s}: {}` : (
|
|
254
|
+
return t.map((s) => typeof s == "string" ? `${s}: {}` : (w(s.default) && !s.default.value && (s.default.value = "undefined"), `${s.name}: {
|
|
255
255
|
type:${e(s.type)},
|
|
256
256
|
required: ${f(!!s.required, !0, !1)},
|
|
257
257
|
default: ${f(s.default, !0, !1)}
|
|
@@ -262,18 +262,18 @@ function pe(t = []) {
|
|
|
262
262
|
}
|
|
263
263
|
function C(t = {}, e = []) {
|
|
264
264
|
return Object.entries(t).map(([s, n]) => {
|
|
265
|
-
let i =
|
|
266
|
-
return i =
|
|
265
|
+
let i = H(f(n, !1, !1));
|
|
266
|
+
return i = E(i, e), i.startsWith("async") ? `async ${s}${i.replace(/^async/, "")}` : `${s}${i}`;
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
function me(t = [], e = []) {
|
|
270
270
|
const s = t.reduce(
|
|
271
|
-
(r, o) => (o.id &&
|
|
271
|
+
(r, o) => (o.id && O(o.source) && (r[`watcher_${o.id}`] = o.source), r),
|
|
272
272
|
{}
|
|
273
273
|
), n = C(s, e), i = t.map((r) => `watcher_${r.id}: {
|
|
274
274
|
deep: ${r.deep},
|
|
275
275
|
immediate:${r.immediate},
|
|
276
|
-
handler${
|
|
276
|
+
handler${H(r.handler.value)}
|
|
277
277
|
}`);
|
|
278
278
|
return {
|
|
279
279
|
computed: n,
|
|
@@ -282,13 +282,21 @@ function me(t = [], e = []) {
|
|
|
282
282
|
}
|
|
283
283
|
function he(t = {}) {
|
|
284
284
|
return Object.values(t).map((e) => {
|
|
285
|
-
|
|
286
|
-
|
|
285
|
+
if (e.type === "mock") {
|
|
286
|
+
const s = O(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
|
|
287
|
+
return `async ${e.name}(...args:any[]) {
|
|
288
|
+
const mock = this.provider.createMock(${s})
|
|
289
|
+
return await mock.apply(this, args);
|
|
290
|
+
}`;
|
|
291
|
+
} else {
|
|
292
|
+
const s = O(e.transform) && e.transform.value || "(res) => res";
|
|
293
|
+
return `async ${e.name}(...args:any[]) {
|
|
287
294
|
return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
|
|
288
295
|
}`;
|
|
296
|
+
}
|
|
289
297
|
});
|
|
290
298
|
}
|
|
291
|
-
const
|
|
299
|
+
const J = [
|
|
292
300
|
"vIf",
|
|
293
301
|
"vShow",
|
|
294
302
|
"vModel",
|
|
@@ -304,8 +312,8 @@ function z(t, e, s = [], n = {}, i) {
|
|
|
304
312
|
return ye(t).forEach((l) => {
|
|
305
313
|
const p = [];
|
|
306
314
|
for (const h of l.children) {
|
|
307
|
-
let { id: v, name: y, invisible:
|
|
308
|
-
if (
|
|
315
|
+
let { id: v, name: y, invisible: _, from: g } = h;
|
|
316
|
+
if (_)
|
|
309
317
|
continue;
|
|
310
318
|
const P = ge(y, e, g);
|
|
311
319
|
P && c.push(P), G(g) && a.push({ id: g.id, name: y });
|
|
@@ -316,7 +324,7 @@ function z(t, e, s = [], n = {}, i) {
|
|
|
316
324
|
h.events,
|
|
317
325
|
n,
|
|
318
326
|
s
|
|
319
|
-
), B =
|
|
327
|
+
), B = ke(
|
|
320
328
|
h.directives,
|
|
321
329
|
s,
|
|
322
330
|
u
|
|
@@ -344,12 +352,12 @@ function z(t, e, s = [], n = {}, i) {
|
|
|
344
352
|
nodes: r,
|
|
345
353
|
methods: o,
|
|
346
354
|
directives: de(u),
|
|
347
|
-
components:
|
|
348
|
-
importBlocks:
|
|
355
|
+
components: k(c),
|
|
356
|
+
importBlocks: k(a, "id")
|
|
349
357
|
};
|
|
350
358
|
}
|
|
351
359
|
function de(t) {
|
|
352
|
-
return
|
|
360
|
+
return k(t).map((e) => `${e.startsWith("v") ? e.substring(1) : e}:${e}`);
|
|
353
361
|
}
|
|
354
362
|
function ye(t = []) {
|
|
355
363
|
const e = /* @__PURE__ */ new Map();
|
|
@@ -378,12 +386,12 @@ function Y(t) {
|
|
|
378
386
|
return typeof t == "object" && t.type === "Plugin";
|
|
379
387
|
}
|
|
380
388
|
function $e(t, e, s = []) {
|
|
381
|
-
return t === "style" ? "" : t === "__class" &&
|
|
389
|
+
return t === "style" ? "" : t === "__class" && w(e) ? `:class="${f({
|
|
382
390
|
...e,
|
|
383
|
-
value:
|
|
384
|
-
})}"` : typeof e == "string" ? `${t}="${e}"` :
|
|
391
|
+
value: E(e.value, s)
|
|
392
|
+
})}"` : typeof e == "string" ? `${t}="${e}"` : w(e) ? `:${t}="${f({
|
|
385
393
|
...e,
|
|
386
|
-
value:
|
|
394
|
+
value: E(e.value, s)
|
|
387
395
|
})}"` : te(e) ? `:${t}='{${oe(
|
|
388
396
|
e
|
|
389
397
|
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
@@ -407,7 +415,7 @@ function je(t, e = {}, s = {}) {
|
|
|
407
415
|
const n = {}, i = Array.from(s[t] || /* @__PURE__ */ new Set([])), r = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
408
416
|
return {
|
|
409
417
|
binders: Object.entries(e).map(([c, u]) => {
|
|
410
|
-
const a = u.handler.value.startsWith("this."), d = a ?
|
|
418
|
+
const a = u.handler.value.startsWith("this."), d = a ? q(u.handler.value) : `${$(c)}_${t}${r}`;
|
|
411
419
|
return a || (n[d] = i.length ? {
|
|
412
420
|
type: "JSFunction",
|
|
413
421
|
value: `{
|
|
@@ -427,8 +435,8 @@ function Se(t, e, s = {}, n = {}, i = {}, r) {
|
|
|
427
435
|
events: o.join(" ")
|
|
428
436
|
};
|
|
429
437
|
}
|
|
430
|
-
function
|
|
431
|
-
const n = [], { vIf: i, vShow: r, vModels: o, vFor: c, vBind: u, vHtml: a, customDirectives: d } =
|
|
438
|
+
function ke(t = [], e = [], s = []) {
|
|
439
|
+
const n = [], { vIf: i, vShow: r, vModels: o, vFor: c, vBind: u, vHtml: a, customDirectives: d } = we(t);
|
|
432
440
|
if (i && n.push(`v-if="${f(i.value, !0, !0, e)}"`), r && n.push(
|
|
433
441
|
`v-show="${f(r.value, !0, !0, e)}"`
|
|
434
442
|
), u && n.push(
|
|
@@ -460,11 +468,11 @@ function we(t = [], e = [], s = []) {
|
|
|
460
468
|
) : n.push(p);
|
|
461
469
|
}), n;
|
|
462
470
|
}
|
|
463
|
-
function
|
|
471
|
+
function we(t = []) {
|
|
464
472
|
const e = t.filter(
|
|
465
|
-
(a) =>
|
|
473
|
+
(a) => J.includes(a.name)
|
|
466
474
|
), s = t.filter(
|
|
467
|
-
(a) => !
|
|
475
|
+
(a) => !J.includes(a.name)
|
|
468
476
|
), n = e.find(
|
|
469
477
|
(a) => $(a.name) === "vIf"
|
|
470
478
|
), i = e.find(
|
|
@@ -508,7 +516,7 @@ function Ce(t, e = [], s = [], n = {}) {
|
|
|
508
516
|
}
|
|
509
517
|
for (const [r, o] of Object.entries(n))
|
|
510
518
|
(i[r] ?? (i[r] = [])).push(...Array.from(o));
|
|
511
|
-
return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${
|
|
519
|
+
return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${k(o).join(
|
|
512
520
|
","
|
|
513
521
|
)}} from '${r}';`).concat(s);
|
|
514
522
|
}
|
|
@@ -556,7 +564,7 @@ function Ae(t, e) {
|
|
|
556
564
|
d,
|
|
557
565
|
v,
|
|
558
566
|
t.imports
|
|
559
|
-
),
|
|
567
|
+
), _ = Object.keys({
|
|
560
568
|
...t.urlSchemas,
|
|
561
569
|
...t.blockPlugins
|
|
562
570
|
}), g = Ee(t.urlSchemas), P = _e(t.blockPlugins);
|
|
@@ -586,7 +594,7 @@ function Ae(t, e) {
|
|
|
586
594
|
`),
|
|
587
595
|
blockPlugins: P.join(`
|
|
588
596
|
`),
|
|
589
|
-
asyncComponents:
|
|
597
|
+
asyncComponents: _.join(",")
|
|
590
598
|
};
|
|
591
599
|
}
|
|
592
600
|
const Fe = `
|
|
@@ -633,14 +641,14 @@ export default defineComponent({
|
|
|
633
641
|
<%= style %>
|
|
634
642
|
</style>
|
|
635
643
|
`, Be = L(Fe), Ne = L(Ie);
|
|
636
|
-
async function
|
|
644
|
+
async function Je(t, e = /* @__PURE__ */ new Map(), s = [], n) {
|
|
637
645
|
const i = new ae(se(t), s), r = Ae(i, e), o = Be(r), c = Ne({
|
|
638
646
|
template: r.template,
|
|
639
|
-
css: await
|
|
647
|
+
css: await T(r.css, n),
|
|
640
648
|
script: await ie(o, n),
|
|
641
|
-
style: await
|
|
649
|
+
style: await T(r.style, n)
|
|
642
650
|
});
|
|
643
|
-
return await
|
|
651
|
+
return await M(c, n).catch((u) => (u.content = c, Promise.reject(u)));
|
|
644
652
|
}
|
|
645
653
|
async function Le(t) {
|
|
646
654
|
const e = `
|
|
@@ -655,10 +663,10 @@ async function Le(t) {
|
|
|
655
663
|
<style scoped lang="scss">
|
|
656
664
|
</style>
|
|
657
665
|
`;
|
|
658
|
-
return await
|
|
666
|
+
return await M(e);
|
|
659
667
|
}
|
|
660
668
|
export {
|
|
661
|
-
|
|
669
|
+
We as VTJ_CODER_VERSION,
|
|
662
670
|
Le as createEmptyPage,
|
|
663
|
-
|
|
671
|
+
Je as generator
|
|
664
672
|
};
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"prettier": "~3.4.0",
|
|
8
8
|
"@vtj/base": "~0.9.1",
|
|
9
|
-
"@vtj/core": "~0.9.
|
|
9
|
+
"@vtj/core": "~0.9.4"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@vtj/cli": "~0.9.
|
|
12
|
+
"@vtj/cli": "~0.9.2"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
package/types/version.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**!
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.9.
|
|
5
|
+
* @version 0.9.3
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.9.
|
|
8
|
+
export declare const version = "0.9.3";
|