@vtj/coder 0.13.27 → 0.13.29
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 +20 -19
- package/dist/index.mjs +32 -30
- package/package.json +2 -2
- package/types/parser/index.d.ts +1 -0
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@vtj/base"),D=require("prettier/standalone"),K=require("prettier/plugins/html"),ee=require("prettier/plugins/babel"),te=require("prettier/plugins/postcss"),se=require("prettier/plugins/estree");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@vtj/base"),D=require("prettier/standalone"),K=require("prettier/plugins/html"),ee=require("prettier/plugins/babel"),te=require("prettier/plugins/postcss"),se=require("prettier/plugins/estree");function N(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 ne=N(K),q=N(ee),M=N(te),U=N(se);/**!
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.13.
|
|
5
|
+
* @version 0.13.29
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const re="0.13.
|
|
7
|
+
*/const re="0.13.29";/**!
|
|
8
8
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/core
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.13.
|
|
11
|
+
* @version 0.13.29
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
-
*/const ie=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const T={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 B(t,e){return e?t:await D.format(t,{parser:"vue",...T,plugins:[ne,q,U,M]})}async function V(t,e){if(e)return t;try{return(await D.format(t,{parser:"babel-ts",...T,plugins:[q,U]})).replace(/;\n$/gi,"")}catch(s){return console.warn(s),t}}async function
|
|
13
|
+
*/const ie=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const T={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 B(t,e){return e?t:await D.format(t,{parser:"vue",...T,plugins:[ne,q,U,M]})}async function V(t,e){if(e)return t;try{return(await D.format(t,{parser:"babel-ts",...T,plugins:[q,U]})).replace(/;\n$/gi,"")}catch(s){return console.warn(s),t}}async function F(t,e){return e?t:D.format(t,{parser:"scss",...T,plugins:[M]})}function k(t){return t&&t.type==="JSExpression"}function I(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function j(t){return k(t)||I(t)}function H(t){return t.replace(new RegExp("this.","g"),"")}function L(t){return t.replace(/this\.context\??\./g,"")}function d(t,e=!0,s=!0,n=[]){let i=j(t)?t.value.trim().replace(/;$/,""):e?JSON.stringify(t):t;return i=w(i,n),s?H(L(i)):L(i)}function w(t="",e=[]){let s=t;for(const n of e)s=s.replace(new RegExp(`this.${n}.value`,"g"),`this.${n}`);return s}function Q(t){let e=t.trim().replace(/;$/,"");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 oe(t={}){return Object.entries(t).map(([e,s])=>`"${e}": ${d(s)}`)}function z(t={},e=!1){const s=Object.keys(t);return e?s.map(n=>"."+n):s}function ae(t){let e="";for(var s in t)if(t.hasOwnProperty(s)){var n=t[s];e+=s+": "+n+";"}return e}function ce(t=[],e=[]){return t.filter(s=>!e.includes(s))}function R(t){return f.base64(JSON.stringify(t))}class le{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 m=a.path.replace(/\$/g,"\\$");n=n.replace(new RegExp(m,"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)j(r)?r.value=this.replaceLibraryPath(r):s(r)};s(e)}getLibraryMember(e=[]){let s=[...e];const n={...this.imports};delete n["uni-h5"],delete n["@dcloudio/uni-h5"],delete n["uni-ui"],delete n["@dcloudio/uni-ui"];for(const i of Object.values(n))s=s.concat(Array.from(i));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:m="index"}=i.iterator||{};r=new Set([a,m,...Array.from(r)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],m=a.length?a:[`scope_${s?.id}`];r=new Set([...m,...Array.from(r)])}this.context[e.id]=r}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&!j(e.props.style)&&(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 ue(t={}){return Object.entries(t).map(([e,s])=>{const n=d(s,!1);return`${e}:${n}`})}function pe(t=[]){return t.map(e=>`${e.name}: {
|
|
14
14
|
from: '${e.from||e.name}',
|
|
15
15
|
default: ${d(e.default,!0,!1)}
|
|
16
16
|
}`)}function fe(t=[]){const e=s=>s?`[${f.toArray(s).map(r=>r.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:(j(s.default)&&!s.default.value&&(s.default.value="undefined"),`${s.name}: {
|
|
@@ -28,24 +28,24 @@
|
|
|
28
28
|
}`}else{const s=I(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args) {
|
|
29
29
|
// DataSource: ${R(e)}
|
|
30
30
|
return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
|
|
31
|
-
}`}})}const
|
|
32
|
-
`),Object.assign(o,S?.methods||{}),a=a.concat(S?.components||[]),u=u.concat(S?.importBlocks||[]));const _=["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes(
|
|
33
|
-
`+
|
|
34
|
-
`),i?.id);r.push(p)}),{nodes:r,methods:o,directives:
|
|
31
|
+
}`}})}const ge=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],J=["vIf","vElseIf","vElse","vShow","vModel","vFor","vBind","vHtml"];function G(t,e,s=[],n={},i){const r=[];let o={},a=[];const m=[];let u=[];return ve(t).forEach(c=>{const v=[];for(const h of c.children){let{id:g,name:$,invisible:b,from:y}=h;if(b)continue;const C=$e($,e,y);C&&a.push(C),Z(y)&&u.push({id:y.id,name:$});const{props:O,events:P,handlers:x}=we(h,g,h.props,h.events,n,s),W=Ce(h.directives,s,m).join(" "),S=h.children?Pe(h.children,s,e,n,h):"";Object.assign(o,x);let E="";typeof S=="string"?E=S:(E=(S?.nodes||[]).join(`
|
|
32
|
+
`),Object.assign(o,S?.methods||{}),a=a.concat(S?.components||[]),u=u.concat(S?.importBlocks||[]));const _=["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes(y||e.get($)?.package)?f.kebabCase($):X(y)||Y(y)?"component":$;v.push(ge.includes(_)?`<${_} ${W} ${O} ${P} />`:`<${_} ${W} ${O} ${P}>${E?`
|
|
33
|
+
`+E.trim():""}</${_}>`)}const p=xe(c.slot,v.join(`
|
|
34
|
+
`),i?.id);r.push(p)}),{nodes:r,methods:o,directives:ye(m),components:f.dedupArray(a),importBlocks:f.dedupArray(u,"id")}}function ye(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ve(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 $e(t,e,s){if(ie.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 Z(s)||n?t:null}function Z(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function X(t){return typeof t=="object"&&t.type==="UrlSchema"}function Y(t){return typeof t=="object"&&t.type==="Plugin"}function be(t,e,s=[]){return t==="style"?j(e)?`:style="${d({...e,value:w(e.value,s)})}"`:"":t==="__class"&&j(e)?`:class="${d({...e,value:w(e.value,s)})}"`:typeof e=="string"?`${t}="${e}"`:j(e)?`:${t}="${d({...e,value:w(e.value,s)})}"`:f.isPlainObject(e)?`:${t}='{${oe(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function je(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,j(e.style)||delete e.style}const i=t.from;return(X(i)||Y(i))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([r,o])=>be(r,o,s))}function Se(t,e,s,n,i){const r=z(e.modifiers,!0);return i?`@${t}${r.join("")}="${s}"`:n&&n.length>0?`@${t}${r.join("")}="(...args:any[]) => ${s}"`:`@${t}${r.join("")}="${s}"`}function ke(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,m])=>{const u=m.handler.value.startsWith("this."),l=u?H(m.handler.value):`${f.camelCase(a)}_${t}${r}`;return u||(n[l]=i.length?{type:"JSFunction",value:`{
|
|
35
35
|
return (${m.handler.value}).apply(this, args);
|
|
36
|
-
}`}:m.handler),Se(a,m,l,i,u)}),handlers:n}}function we(t,e,s={},n={},i={},r){const{binders:o,handlers:a}=ke(e,n,i);return{props:je(t,s,r).join(" "),handlers:a,binders:o,events:o.join(" ")}}function Ce(t=[],e=[],s=[]){const n=[],{vIf:i,vElse:r,vElseIf:o,vShow:a,vModels:m,vFor:u,vBind:l,vHtml:c,customDirectives:v}=
|
|
36
|
+
}`}:m.handler),Se(a,m,l,i,u)}),handlers:n}}function we(t,e,s={},n={},i={},r){const{binders:o,handlers:a}=ke(e,n,i);return{props:je(t,s,r).join(" "),handlers:a,binders:o,events:o.join(" ")}}function Ce(t=[],e=[],s=[]){const n=[],{vIf:i,vElse:r,vElseIf:o,vShow:a,vModels:m,vFor:u,vBind:l,vHtml:c,customDirectives:v}=Oe(t);if(i&&n.push(`v-if="${d(i.value,!0,!0,e)}"`),o&&n.push(`v-else-if="${d(o.value,!0,!0,e)}"`),r&&n.push("v-else"),a&&n.push(`v-show="${d(a.value,!0,!0,e)}"`),l&&n.push(`v-bind="${d(l.value,!0,!0,e)}"`),m.forEach(p=>{const h=z(p.modifiers,!0),g=p.arg?k(p.arg)?`:[${d(p.arg,!0,!0,e)}]`:`:${p.arg}`:"";n.push(`v-model${g}${h}="${d(p.value,!0,!0,e)}"`)}),u){const{item:p,index:h}={item:"item",index:"index",...u.iterator};n.push(`v-for="(${p}, ${h}) in ${d(u.value,!0,!0,e)}"`)}return c&&n.push(`v-html="${d(c.value,!0,!0,e)}"`),v&&v.length&&v.forEach(p=>{if(!p.name)return;let h="",g="";k(p.name)?(g=d(p.name,!0,!0,e),s.push(g)):g=p.name;const $=g?.startsWith("v")?f.kebabCase(g):f.kebabCase("v-"+g);if(h+=$,p.arg&&(k(p.arg)?h+=`:[${d(p.name,!0,!0,e)}]`:h+=`:${p.arg}`),p.modifiers){const b=Object.keys(p.modifiers);b.length&&(h+=b.map(y=>"."+y))}p.value?n.push(`${h}="${d(p.value,!0,!0,e)}"`):n.push(h)}),n}function Oe(t=[]){const e=t.filter(c=>J.includes(c.name)),s=t.filter(c=>!J.includes(c.name)),n=e.find(c=>f.camelCase(c.name)==="vIf"),i=e.find(c=>f.camelCase(c.name)==="vElseIf"),r=e.find(c=>f.camelCase(c.name)==="vElse"),o=e.find(c=>f.camelCase(c.name)==="vFor"),a=e.find(c=>f.camelCase(c.name)==="vShow"),m=e.find(c=>f.camelCase(c.name)==="vBind"),u=e.find(c=>f.camelCase(c.name)==="vHtml"),l=e.filter(c=>f.camelCase(c.name)==="vModel");return{vIf:n,vElseIf:i,vElse:r,vFor:o,vShow:a,vModels:l,vBind:m,vHtml:u,customDirectives:s}}function Pe(t,e,s,n,i){return typeof t=="string"?t:k(t)?`{{ ${d(t,!1,!0,e)} }}`:Array.isArray(t)?G(t,s,e,n,i):""}function xe(t,e,s){if(!t)return e;const n=typeof t=="string"?{name:t,params:[],scope:""}:{params:[],scope:"",...t};return`<template ${`#${n.name}="${n.scope?n.scope:n.params?.length>0?`{${n.params?.join(",")}}`:`scope_${s}`}"`}>
|
|
37
37
|
${e}
|
|
38
|
-
</template>`}function
|
|
38
|
+
</template>`}function Ee(t,e=[],s=[],n={},i="web"){const r=["@dcloudio/uni-h5","uni-h5","@dcloudio/uni-ui","uni-ui"],o={vue:["defineComponent","reactive"]},a=[];for(const u of e){const l=t.get(u.split(":")[0]);if(l&&l.package){const c=o[l.package]??(o[l.package]=[]),v=l.parent||(l.alias||"").split(".")[0]||l.name;c.push(v),i==="uniapp"&&r.includes(l.package)&&a.push(v)}}for(const[u,l]of Object.entries(n))(o[u]??(o[u]=[])).push(...Array.from(l)),i==="uniapp"&&r.includes(u)&&a.push(...Array.from(l));return{imports:Object.entries(o).filter(([u,l])=>i==="uniapp"?!r.includes(u)&&!!l.length:!!l.length).map(([u,l])=>`import { ${f.dedupArray(l).join(",")}} from '${u}';`).concat(s),uniComponents:a}}function _e(t={}){const e=[];for(const[s,n]of Object.entries(t))e.push(`
|
|
39
39
|
${s} {
|
|
40
40
|
${ae(n)}
|
|
41
41
|
}
|
|
42
42
|
`);return e.join(`
|
|
43
|
-
`)}function Ae(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`)}),e}function Ie(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`)}),e}function
|
|
43
|
+
`)}function Ae(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`)}),e}function Ie(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`)}),e}function Ne(t,e,s="web"){const{dsl:n}=t,i=Object.keys(n.computed||{}),r=A(n.lifeCycles,i),o=A(n.computed,i),a=he(n.watch,i),m=de(n.dataSources),{methods:u,nodes:l,components:c,importBlocks:v,directives:p}=G(n.nodes||[],e,i,t.context),h=[...o,...a.computed],g=A({...u,...n.methods||{}},i),$=v.map(x=>`import ${x.name} from './${x.id}.vue';`);let{imports:b,uniComponents:y}=Ee(e,c,$,t.imports,s);const C=Object.keys({...t.urlSchemas,...t.blockPlugins}),O=Ae(t.urlSchemas),P=Ie(t.blockPlugins);return{id:n.id,version:n.__VERSION__,name:n.name,state:ue(n.state).join(","),inject:pe(n.inject).join(","),props:fe(n.props).join(","),emits:me(n.emits).join(","),expose:n.expose&&n.expose.length?JSON.stringify(n.expose||[]):"",watch:a.watches.join(","),lifeCycles:r.join(","),computed:h.join(","),methods:[...m,...g].join(","),imports:`
|
|
44
44
|
`+b.join(`
|
|
45
|
-
`),components:ce(c,
|
|
46
|
-
`),css:n.css||"",style:_e(t.style),urlSchemas:
|
|
47
|
-
`),blockPlugins:
|
|
48
|
-
`),asyncComponents:C.join(","),uniComponents:
|
|
45
|
+
`),components:ce(c,y).join(","),directives:p.join(","),returns:t.members.join(","),template:l.join(`
|
|
46
|
+
`),css:n.css||"",style:_e(t.style),urlSchemas:O.join(`
|
|
47
|
+
`),blockPlugins:P.join(`
|
|
48
|
+
`),asyncComponents:C.join(","),uniComponents:y,renderer:s==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Fe=`
|
|
49
49
|
// @ts-nocheck
|
|
50
50
|
|
|
51
51
|
<%= imports %>
|
|
@@ -56,7 +56,8 @@ export default defineComponent({
|
|
|
56
56
|
<% if(components) { %> components: { <%= components %> }, <% } %>
|
|
57
57
|
<% if(directives) { %> directives: { <%= directives %> }, <% } %>
|
|
58
58
|
<% if(props) { %> props: { <%= props %> }, <% } %>
|
|
59
|
-
<% if(emits) {%> emits: [<%= emits %>], <% } %>
|
|
59
|
+
<% if(emits) {%> emits: [<%= emits %>], <% } %>
|
|
60
|
+
<% if(expose) {%> expose: <%= expose %>, <% } %>
|
|
60
61
|
setup(props) {
|
|
61
62
|
const provider = useProvider({
|
|
62
63
|
id: '<%= id %>',
|
|
@@ -88,7 +89,7 @@ export default defineComponent({
|
|
|
88
89
|
<%= css %>
|
|
89
90
|
<%= style %>
|
|
90
91
|
</style>
|
|
91
|
-
`,Te=f.template(
|
|
92
|
+
`,Te=f.template(Fe),Be=f.template(De);async function We(t,e=new Map,s=[],n="web",i){const r=t,o=typeof r.dsl=="object"&&arguments.length===1?r:{dsl:t,componentMap:e,dependencies:s,platform:n,formatterDisabled:i},{dsl:a,componentMap:m=new Map,dependencies:u=[],platform:l="web",formatterDisabled:c=!1,ts:v=!0,scss:p=!1}=o,h=new le(f.cloneDeep(a),u),g=Ne(h,m,l),$=Te(g),b=Be({template:g.template,css:await F(g.css,c),script:await V($,c),style:await F(g.style,c),scriptLang:v?"ts":"js",styleLang:p?"scss":"css"});return await B(b,c).catch(y=>(y.content=b,Promise.reject(y)))}async function Le(t){const e=`
|
|
92
93
|
<template>
|
|
93
94
|
<div>
|
|
94
95
|
<h3>源码模式页面</h3>
|
|
@@ -99,4 +100,4 @@ export default defineComponent({
|
|
|
99
100
|
<\/script>
|
|
100
101
|
<style scoped lang="scss">
|
|
101
102
|
</style>
|
|
102
|
-
`;return await B(e)}exports.VTJ_CODER_VERSION=re;exports.createEmptyPage=Le;exports.cssFormatter=
|
|
103
|
+
`;return await B(e)}exports.VTJ_CODER_VERSION=re;exports.createEmptyPage=Le;exports.cssFormatter=F;exports.generator=We;exports.tsFormatter=V;exports.vueFormatter=B;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mitt as ee, base64 as te, dedupArray as
|
|
1
|
+
import { mitt as ee, base64 as te, dedupArray as x, toArray as se, kebabCase as F, camelCase as b, isPlainObject as ne, template as U, cloneDeep as re } from "@vtj/base";
|
|
2
2
|
import { format as B } from "prettier/standalone";
|
|
3
3
|
import * as ie from "prettier/plugins/html";
|
|
4
4
|
import * as M from "prettier/plugins/babel";
|
|
@@ -8,15 +8,15 @@ import * as H from "prettier/plugins/estree";
|
|
|
8
8
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/coder
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.13.
|
|
11
|
+
* @version 0.13.29
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const Ue = "0.13.
|
|
14
|
+
const Ue = "0.13.29";
|
|
15
15
|
/**!
|
|
16
16
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
17
17
|
* @name @vtj/core
|
|
18
18
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
19
|
-
* @version 0.13.
|
|
19
|
+
* @version 0.13.29
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const oe = [
|
|
@@ -218,7 +218,7 @@ class pe {
|
|
|
218
218
|
delete n["uni-h5"], delete n["@dcloudio/uni-h5"], delete n["uni-ui"], delete n["@dcloudio/uni-ui"];
|
|
219
219
|
for (const i of Object.values(n))
|
|
220
220
|
s = s.concat(Array.from(i));
|
|
221
|
-
return
|
|
221
|
+
return x(s);
|
|
222
222
|
}
|
|
223
223
|
collectContext(e, s) {
|
|
224
224
|
const n = new Set(s?.id ? this.context[s.id] : []), i = (e.directives || []).find((c) => c.name === "vFor");
|
|
@@ -347,27 +347,27 @@ function z(t, e, s = [], n = {}, i) {
|
|
|
347
347
|
let { id: d, name: $, invisible: v, from: g } = m;
|
|
348
348
|
if (v)
|
|
349
349
|
continue;
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
const { props:
|
|
350
|
+
const O = je($, e, g);
|
|
351
|
+
O && c.push(O), X(g) && u.push({ id: g.id, name: $ });
|
|
352
|
+
const { props: C, events: E, handlers: P } = Oe(
|
|
353
353
|
m,
|
|
354
354
|
d,
|
|
355
355
|
m.props,
|
|
356
356
|
m.events,
|
|
357
357
|
n,
|
|
358
358
|
s
|
|
359
|
-
), W =
|
|
359
|
+
), W = Ce(
|
|
360
360
|
m.directives,
|
|
361
361
|
s,
|
|
362
362
|
f
|
|
363
|
-
).join(" "), S = m.children ?
|
|
363
|
+
).join(" "), S = m.children ? Pe(
|
|
364
364
|
m.children,
|
|
365
365
|
s,
|
|
366
366
|
e,
|
|
367
367
|
n,
|
|
368
368
|
m
|
|
369
369
|
) : "";
|
|
370
|
-
Object.assign(o,
|
|
370
|
+
Object.assign(o, P);
|
|
371
371
|
let _ = "";
|
|
372
372
|
typeof S == "string" ? _ = S : (_ = (S?.nodes || []).join(`
|
|
373
373
|
`), Object.assign(o, S?.methods || {}), c = c.concat(S?.components || []), u = u.concat(S?.importBlocks || []));
|
|
@@ -375,7 +375,7 @@ function z(t, e, s = [], n = {}, i) {
|
|
|
375
375
|
g || e.get($)?.package
|
|
376
376
|
) ? F($) : Y(g) || K(g) ? "component" : $;
|
|
377
377
|
y.push(
|
|
378
|
-
$e.includes(I) ? `<${I} ${W} ${
|
|
378
|
+
$e.includes(I) ? `<${I} ${W} ${C} ${E} />` : `<${I} ${W} ${C} ${E}>${_ ? `
|
|
379
379
|
` + _.trim() : ""}</${I}>`
|
|
380
380
|
);
|
|
381
381
|
}
|
|
@@ -386,12 +386,12 @@ function z(t, e, s = [], n = {}, i) {
|
|
|
386
386
|
nodes: r,
|
|
387
387
|
methods: o,
|
|
388
388
|
directives: ve(f),
|
|
389
|
-
components:
|
|
390
|
-
importBlocks:
|
|
389
|
+
components: x(c),
|
|
390
|
+
importBlocks: x(u, "id")
|
|
391
391
|
};
|
|
392
392
|
}
|
|
393
393
|
function ve(t) {
|
|
394
|
-
return
|
|
394
|
+
return x(t).map((e) => `${e.startsWith("v") ? e.substring(1) : e}:${e}`);
|
|
395
395
|
}
|
|
396
396
|
function be(t = []) {
|
|
397
397
|
const e = /* @__PURE__ */ new Map();
|
|
@@ -448,7 +448,7 @@ function we(t, e, s, n, i) {
|
|
|
448
448
|
const r = Z(e.modifiers, !0);
|
|
449
449
|
return i ? `@${t}${r.join("")}="${s}"` : n && n.length > 0 ? `@${t}${r.join("")}="(...args:any[]) => ${s}"` : `@${t}${r.join("")}="${s}"`;
|
|
450
450
|
}
|
|
451
|
-
function
|
|
451
|
+
function xe(t, e = {}, s = {}) {
|
|
452
452
|
const n = {}, i = Array.from(s[t] || /* @__PURE__ */ new Set([])), r = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
453
453
|
return {
|
|
454
454
|
binders: Object.entries(e).map(([c, f]) => {
|
|
@@ -463,8 +463,8 @@ function Ce(t, e = {}, s = {}) {
|
|
|
463
463
|
handlers: n
|
|
464
464
|
};
|
|
465
465
|
}
|
|
466
|
-
function
|
|
467
|
-
const { binders: o, handlers: c } =
|
|
466
|
+
function Oe(t, e, s = {}, n = {}, i = {}, r) {
|
|
467
|
+
const { binders: o, handlers: c } = xe(e, n, i);
|
|
468
468
|
return {
|
|
469
469
|
props: ke(t, s, r).join(" "),
|
|
470
470
|
handlers: c,
|
|
@@ -472,7 +472,7 @@ function Ee(t, e, s = {}, n = {}, i = {}, r) {
|
|
|
472
472
|
events: o.join(" ")
|
|
473
473
|
};
|
|
474
474
|
}
|
|
475
|
-
function
|
|
475
|
+
function Ce(t = [], e = [], s = []) {
|
|
476
476
|
const n = [], {
|
|
477
477
|
vIf: i,
|
|
478
478
|
vElse: r,
|
|
@@ -483,7 +483,7 @@ function Oe(t = [], e = [], s = []) {
|
|
|
483
483
|
vBind: l,
|
|
484
484
|
vHtml: a,
|
|
485
485
|
customDirectives: y
|
|
486
|
-
} =
|
|
486
|
+
} = Ee(t);
|
|
487
487
|
if (i && n.push(`v-if="${h(i.value, !0, !0, e)}"`), o && n.push(
|
|
488
488
|
`v-else-if="${h(o.value, !0, !0, e)}"`
|
|
489
489
|
), r && n.push("v-else"), c && n.push(
|
|
@@ -517,7 +517,7 @@ function Oe(t = [], e = [], s = []) {
|
|
|
517
517
|
) : n.push(m);
|
|
518
518
|
}), n;
|
|
519
519
|
}
|
|
520
|
-
function
|
|
520
|
+
function Ee(t = []) {
|
|
521
521
|
const e = t.filter(
|
|
522
522
|
(a) => J.includes(a.name)
|
|
523
523
|
), s = t.filter(
|
|
@@ -551,7 +551,7 @@ function Pe(t = []) {
|
|
|
551
551
|
customDirectives: s
|
|
552
552
|
};
|
|
553
553
|
}
|
|
554
|
-
function
|
|
554
|
+
function Pe(t, e, s, n, i) {
|
|
555
555
|
return typeof t == "string" ? t : k(t) ? `{{ ${h(t, !1, !0, e)} }}` : Array.isArray(t) ? z(t, s, e, n, i) : "";
|
|
556
556
|
}
|
|
557
557
|
function _e(t, e, s) {
|
|
@@ -580,7 +580,7 @@ function Ie(t, e = [], s = [], n = {}, i = "web") {
|
|
|
580
580
|
for (const [u, l] of Object.entries(n))
|
|
581
581
|
(o[u] ?? (o[u] = [])).push(...Array.from(l)), i === "uniapp" && r.includes(u) && c.push(...Array.from(l));
|
|
582
582
|
return {
|
|
583
|
-
imports: Object.entries(o).filter(([u, l]) => i === "uniapp" ? !r.includes(u) && !!l.length : !!l.length).map(([u, l]) => `import { ${
|
|
583
|
+
imports: Object.entries(o).filter(([u, l]) => i === "uniapp" ? !r.includes(u) && !!l.length : !!l.length).map(([u, l]) => `import { ${x(l).join(
|
|
584
584
|
","
|
|
585
585
|
)}} from '${u}';`).concat(s),
|
|
586
586
|
uniComponents: c
|
|
@@ -625,7 +625,7 @@ function Be(t, e, s = "web") {
|
|
|
625
625
|
...n.methods || {}
|
|
626
626
|
},
|
|
627
627
|
i
|
|
628
|
-
), $ = y.map((
|
|
628
|
+
), $ = y.map((P) => `import ${P.name} from './${P.id}.vue';`);
|
|
629
629
|
let { imports: v, uniComponents: g } = Ie(
|
|
630
630
|
e,
|
|
631
631
|
a,
|
|
@@ -633,10 +633,10 @@ function Be(t, e, s = "web") {
|
|
|
633
633
|
t.imports,
|
|
634
634
|
s
|
|
635
635
|
);
|
|
636
|
-
const
|
|
636
|
+
const O = Object.keys({
|
|
637
637
|
...t.urlSchemas,
|
|
638
638
|
...t.blockPlugins
|
|
639
|
-
}),
|
|
639
|
+
}), C = Ne(t.urlSchemas), E = Fe(t.blockPlugins);
|
|
640
640
|
return {
|
|
641
641
|
id: n.id,
|
|
642
642
|
version: n.__VERSION__,
|
|
@@ -645,6 +645,7 @@ function Be(t, e, s = "web") {
|
|
|
645
645
|
inject: me(n.inject).join(","),
|
|
646
646
|
props: he(n.props).join(","),
|
|
647
647
|
emits: de(n.emits).join(","),
|
|
648
|
+
expose: n.expose && n.expose.length ? JSON.stringify(n.expose || []) : "",
|
|
648
649
|
watch: c.watches.join(","),
|
|
649
650
|
lifeCycles: r.join(","),
|
|
650
651
|
computed: m.join(","),
|
|
@@ -659,11 +660,11 @@ function Be(t, e, s = "web") {
|
|
|
659
660
|
`),
|
|
660
661
|
css: n.css || "",
|
|
661
662
|
style: Ae(t.style),
|
|
662
|
-
urlSchemas:
|
|
663
|
+
urlSchemas: C.join(`
|
|
663
664
|
`),
|
|
664
|
-
blockPlugins:
|
|
665
|
+
blockPlugins: E.join(`
|
|
665
666
|
`),
|
|
666
|
-
asyncComponents:
|
|
667
|
+
asyncComponents: O.join(","),
|
|
667
668
|
uniComponents: g,
|
|
668
669
|
renderer: s === "uniapp" ? "@vtj/uni-app" : "@vtj/renderer"
|
|
669
670
|
};
|
|
@@ -679,7 +680,8 @@ export default defineComponent({
|
|
|
679
680
|
<% if(components) { %> components: { <%= components %> }, <% } %>
|
|
680
681
|
<% if(directives) { %> directives: { <%= directives %> }, <% } %>
|
|
681
682
|
<% if(props) { %> props: { <%= props %> }, <% } %>
|
|
682
|
-
<% if(emits) {%> emits: [<%= emits %>], <% } %>
|
|
683
|
+
<% if(emits) {%> emits: [<%= emits %>], <% } %>
|
|
684
|
+
<% if(expose) {%> expose: <%= expose %>, <% } %>
|
|
683
685
|
setup(props) {
|
|
684
686
|
const provider = useProvider({
|
|
685
687
|
id: '<%= id %>',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.29",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"低代码引擎",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"prettier": "~3.6.0",
|
|
25
25
|
"@vtj/base": "~0.12.3",
|
|
26
|
-
"@vtj/core": "~0.13.
|
|
26
|
+
"@vtj/core": "~0.13.29"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@vtj/cli": "~0.12.13"
|
package/types/parser/index.d.ts
CHANGED
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.13.
|
|
5
|
+
* @version 0.13.28
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.13.
|
|
8
|
+
export declare const version = "0.13.28";
|