@vtj/coder 0.11.7 → 0.11.9
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 +17 -17
- package/dist/index.mjs +68 -65
- package/package.json +3 -3
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2,48 +2,48 @@
|
|
|
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.11.
|
|
5
|
+
* @version 0.11.9
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const se="0.11.
|
|
7
|
+
*/const se="0.11.9";/**!
|
|
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.11.
|
|
11
|
+
* @version 0.11.9
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
-
*/const re=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const B={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 R(t,e){return e?t:await T.format(t,{parser:"vue",...B,plugins:[ne,D,U,L]})}async function M(t,e){return e?t:await T.format(t,{parser:"babel-ts",...B,plugins:[D,U]})}async function I(t,e){return e?t:T.format(t,{parser:"scss",...B,plugins:[L]})}function
|
|
13
|
+
*/const re=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const B={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 R(t,e){return e?t:await T.format(t,{parser:"vue",...B,plugins:[ne,D,U,L]})}async function M(t,e){return e?t:await T.format(t,{parser:"babel-ts",...B,plugins:[D,U]})}async function I(t,e){return e?t:T.format(t,{parser:"scss",...B,plugins:[L]})}function S(t){return t&&t.type==="JSExpression"}function A(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function v(t){return S(t)||A(t)}function V(t){return t.replace(new RegExp("this.","g"),"")}function J(t){return t.replace(/this\.context\??\./g,"")}function m(t,e=!0,n=!0,s=[]){let r=v(t)?t.value:e?JSON.stringify(t):t;return r=k(r,s),n?V(J(r)):J(r)}function k(t,e=[]){let n=t;for(const s of e)n=n.replace(new RegExp(`this.${s}.value`,"g"),`this.${s}`);return n}function H(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 r=/^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,i=e.match(r);i&&i[2]&&(i[2].startsWith("{")||(e=e.replace(i[2],`{ return ${i[2]} }`))),e=e.replace("=>","")}return e}function ie(t={}){return Object.entries(t).map(([e,n])=>`"${e}": ${m(n)}`)}function Q(t={},e=!1){const n=Object.keys(t);return e?n.map(s=>"."+s):n}function oe(t){let e="";for(var n in t)if(t.hasOwnProperty(n)){var s=t[n];e+=n+": "+s+";"}return e}function ce(t=[],e=[]){return t.filter(n=>!e.includes(n))}class ae{constructor(e,n){this.dsl=e,this.dependencies=n,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 n=e.split(".");if(n.length===4){const s=n.pop(),r=n.join(".")+".",i=n.pop();if(s&&i){const c=this.dependencies.find(a=>a.library===i)?.package;c&&(this.imports[c]||(this.imports[c]=new Set)).add(s)}return{name:s,path:r,library:i}}return null}replaceLibraryPath(e){const{libraryRegex:n}=this;let s=e.value;for(const r of n){const i=e.value?.match(r)||[];for(const c of i){const a=this.collectImport(c);if(a){const p=a.path.replace(/\$/g,"\\$");s=s.replace(new RegExp(p,"g"),"")}}}return s}walk(e){const n=s=>{if(!s||typeof s!="object")return;if(Array.isArray(s)){for(let i of s)n(i);return}const r=Object.values(s);for(const i of r)v(i)?i.value=this.replaceLibraryPath(i):n(i)};n(e)}getLibraryMember(e=[]){let n=[...e];const s={...this.imports};delete s["uni-h5"],delete s["@dcloudio/uni-h5"],delete s["uni-ui"],delete s["@dcloudio/uni-ui"];for(const r of Object.values(s))n=n.concat(Array.from(r));return f.dedupArray(n)}collectContext(e,n){const s=new Set(n?.id?this.context[n.id]:[]),r=(e.directives||[]).find(a=>a.name==="vFor");let i=new Set(Array.from(s));if(r){const{item:a="item",index:p="index"}=r.iterator||{};i=new Set([a,p,...Array.from(i)])}const c=e.slot;if(c){const a=typeof c=="string"?[]:c.params||[],p=a.length?a:[`scope_${n?.id}`];i=new Set([...p,...Array.from(i)])}this.context[e.id]=i}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&!v(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 n=(s,r)=>{this.collectContext(s,r),this.collectStyle(s),this.collectUrlSchema(s),this.collectBlockPlugin(s),Array.isArray(s.children)&&s.children.forEach(i=>n(i,s))};Array.isArray(e.nodes)&&e.nodes.forEach(s=>n(s))}}function ue(t={}){return Object.entries(t).map(([e,n])=>{const s=m(n,!1);return`${e}:${s}`})}function le(t=[]){return t.map(e=>`${e.name}: {
|
|
14
14
|
from: '${e.from||e.name}',
|
|
15
15
|
default: ${m(e.default,!0,!1)}
|
|
16
|
-
}`)}function pe(t=[]){const e=n=>n?`[${f.toArray(n).map(i=>i.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(n=>typeof n=="string"?`${n}: {}`:(
|
|
16
|
+
}`)}function pe(t=[]){const e=n=>n?`[${f.toArray(n).map(i=>i.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(n=>typeof n=="string"?`${n}: {}`:(v(n.default)&&!n.default.value&&(n.default.value="undefined"),`${n.name}: {
|
|
17
17
|
type:${e(n.type)},
|
|
18
18
|
required: ${m(!!n.required,!0,!1)},
|
|
19
19
|
default: ${m(n.default,!0,!1)}
|
|
20
|
-
}`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function
|
|
20
|
+
}`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function E(t={},e=[]){return Object.entries(t).map(([n,s])=>{let r=H(m(s,!1,!1));return r=k(r,e),r.startsWith("async")?`async ${n}${r.replace(/^async/,"")}`:`${n}${r}`})}function me(t=[],e=[]){const n=t.reduce((i,c)=>(c.id&&A(c.source)&&(i[`watcher_${c.id}`]=c.source),i),{}),s=E(n,e),r=t.map(i=>`watcher_${i.id}: {
|
|
21
21
|
deep: ${i.deep},
|
|
22
22
|
immediate:${i.immediate},
|
|
23
23
|
handler${H(i.handler.value)}
|
|
24
|
-
}`);return{computed:s,watches:r}}function he(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const n=
|
|
24
|
+
}`);return{computed:s,watches:r}}function he(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const n=A(e.mockTemplate)&&e.mockTemplate.value||"(params) => ({})";return`async ${e.name}(...args:any[]) {
|
|
25
25
|
const mock = this.provider.createMock(${n})
|
|
26
26
|
return await mock.apply(this, args);
|
|
27
|
-
}`}else{const n=
|
|
27
|
+
}`}else{const n=A(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
28
28
|
return await this.provider.apis['${e.ref}'].apply(this, args).then(${n});
|
|
29
|
-
}`}})}const de=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],q=["vIf","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,n=[],s={},r){const i=[];let c={},a=[];const p=[];let o=[];return ge(t).forEach(u=>{const h=[];for(const y of u.children){let{id:
|
|
30
|
-
`),Object.assign(c,
|
|
31
|
-
`+
|
|
32
|
-
`),r?.id);i.push(d)}),{nodes:i,methods:c,directives:ye(p),components:f.dedupArray(a),importBlocks:f.dedupArray(o,"id")}}function ye(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ge(t=[]){const e=new Map;for(const n of t){const s=typeof n.slot=="string"?n.slot:n.slot?.name,r=e.get(s);r?r.children.push(n):e.set(s,{slot:n.slot,children:[n]})}return e}function $e(t,e,n){if(re.includes(t))return null;const s=e.get(t);if(s&&s.alias){const r=s.parent?`${s.parent}.${s.alias}`:s.alias;return`${t}: ${r}`}return G(n)||s?t:null}function G(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 ve(t,e,n=[]){return t==="style"?"":t==="__class"&&
|
|
29
|
+
}`}})}const de=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],q=["vIf","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,n=[],s={},r){const i=[];let c={},a=[];const p=[];let o=[];return ge(t).forEach(u=>{const h=[];for(const y of u.children){let{id:b,name:$,invisible:N,from:g}=y;if(N)continue;const w=$e($,e,g);w&&a.push(w),G(g)&&o.push({id:g.id,name:$});const{props:C,events:P,handlers:O}=ke(y,b,y.props,y.events,s,n),W=we(y.directives,n,p).join(" "),j=y.children?Pe(y.children,n,e,s,y):"";Object.assign(c,O);let _="";typeof j=="string"?_=j:(_=(j?.nodes||[]).join(`
|
|
30
|
+
`),Object.assign(c,j?.methods||{}),a=a.concat(j?.components||[]),o=o.concat(j?.importBlocks||[]));const x=["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes(g)?f.kebabCase($):X(g)||Y(g)?"component":$;h.push(de.includes(x)?`<${x} ${W} ${C} ${P} />`:`<${x} ${W} ${C} ${P}>${_?`
|
|
31
|
+
`+_.trim():""}</${x}>`)}const d=Oe(u.slot,h.join(`
|
|
32
|
+
`),r?.id);i.push(d)}),{nodes:i,methods:c,directives:ye(p),components:f.dedupArray(a),importBlocks:f.dedupArray(o,"id")}}function ye(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ge(t=[]){const e=new Map;for(const n of t){const s=typeof n.slot=="string"?n.slot:n.slot?.name,r=e.get(s);r?r.children.push(n):e.set(s,{slot:n.slot,children:[n]})}return e}function $e(t,e,n){if(re.includes(t))return null;const s=e.get(t);if(s&&s.alias){const r=s.parent?`${s.parent}.${s.alias}`:s.alias;return`${t}: ${r}`}return G(n)||s?t:null}function G(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 ve(t,e,n=[]){return t==="style"?v(e)?`:style="${m({...e,value:k(e.value,n)})}"`:"":t==="__class"&&v(e)?`:class="${m({...e,value:k(e.value,n)})}"`:typeof e=="string"?`${t}="${e}"`:v(e)?`:${t}="${m({...e,value:k(e.value,n)})}"`:f.isPlainObject(e)?`:${t}='{${ie(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function be(t,e={},n=[]){if(!!Object.keys(e.style||{}).length){const i=`${t.name}_${t.id}`;e.class?typeof e.class=="string"?e.class=[e.class,i].join(" "):(e.__class=e.class,e.class=i):e.class=i,v(e.style)||delete e.style}const r=t.from;return(X(r)||Y(r))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([i,c])=>ve(i,c,n))}function je(t,e,n,s,r){const i=Q(e.modifiers,!0);return r?`@${t}${i.join("")}="${n}"`:s&&s.length>0?`@${t}${i.join("")}="(...args:any[]) => ${n}"`:`@${t}${i.join("")}="${n}"`}function Se(t,e={},n={}){const s={},r=Array.from(n[t]||new Set([])),i=r.length?`({${r.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,p])=>{const o=p.handler.value.startsWith("this."),l=o?V(p.handler.value):`${f.camelCase(a)}_${t}${i}`;return o||(s[l]=r.length?{type:"JSFunction",value:`{
|
|
33
33
|
return (${p.handler.value}).apply(this, args);
|
|
34
|
-
}`}:p.handler),je(a,p,l,r,o)}),handlers:s}}function ke(t,e,n={},s={},r={},i){const{binders:c,handlers:a}=Se(e,s,r);return{props:be(t,n,i).join(" "),handlers:a,binders:c,events:c.join(" ")}}function we(t=[],e=[],n=[]){const s=[],{vIf:r,vShow:i,vModels:c,vFor:a,vBind:p,vHtml:o,customDirectives:l}=Ce(t);if(r&&s.push(`v-if="${m(r.value,!0,!0,e)}"`),i&&s.push(`v-show="${m(i.value,!0,!0,e)}"`),p&&s.push(`v-bind="${m(p.value,!0,!0,e)}"`),c.forEach(u=>{const h=Q(u.modifiers,!0),d=u.arg?
|
|
34
|
+
}`}:p.handler),je(a,p,l,r,o)}),handlers:s}}function ke(t,e,n={},s={},r={},i){const{binders:c,handlers:a}=Se(e,s,r);return{props:be(t,n,i).join(" "),handlers:a,binders:c,events:c.join(" ")}}function we(t=[],e=[],n=[]){const s=[],{vIf:r,vShow:i,vModels:c,vFor:a,vBind:p,vHtml:o,customDirectives:l}=Ce(t);if(r&&s.push(`v-if="${m(r.value,!0,!0,e)}"`),i&&s.push(`v-show="${m(i.value,!0,!0,e)}"`),p&&s.push(`v-bind="${m(p.value,!0,!0,e)}"`),c.forEach(u=>{const h=Q(u.modifiers,!0),d=u.arg?S(u.arg)?`:[${m(u.arg,!0,!0,e)}]`:`:${u.arg}`:"";s.push(`v-model${d}${h}="${m(u.value,!0,!0,e)}"`)}),a){const{item:u,index:h}={item:"item",index:"index",...a.iterator};s.push(`v-for="(${u}, ${h}) in ${m(a.value,!0,!0,e)}"`)}return o&&s.push(`v-html="${m(o.value,!0,!0,e)}"`),l&&l.length&&l.forEach(u=>{if(!u.name)return;let h="",d="";S(u.name)?(d=m(u.name,!0,!0,e),n.push(d)):d=u.name;const y=d?.startsWith("v")?f.kebabCase(d):f.kebabCase("v-"+d);if(h+=y,u.arg&&(S(u.arg)?h+=`:[${m(u.name,!0,!0,e)}]`:h+=`:${u.arg}`),u.modifiers){const b=Object.keys(u.modifiers);b.length&&(h+=b.map($=>"."+$))}u.value?s.push(`${h}="${m(u.value,!0,!0,e)}"`):s.push(h)}),s}function Ce(t=[]){const e=t.filter(o=>q.includes(o.name)),n=t.filter(o=>!q.includes(o.name)),s=e.find(o=>f.camelCase(o.name)==="vIf"),r=e.find(o=>f.camelCase(o.name)==="vFor"),i=e.find(o=>f.camelCase(o.name)==="vShow"),c=e.find(o=>f.camelCase(o.name)==="vBind"),a=e.find(o=>f.camelCase(o.name)==="vHtml"),p=e.filter(o=>f.camelCase(o.name)==="vModel");return{vIf:s,vFor:r,vShow:i,vModels:p,vBind:c,vHtml:a,customDirectives:n}}function Pe(t,e,n,s,r){return typeof t=="string"?t:S(t)?`{{ ${m(t,!1,!0,e)} }}`:Array.isArray(t)?z(t,n,e,s,r):""}function Oe(t,e,n){if(!t)return e;const s=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${s.name}="${s.params?.length>0?`{${s.params?.join(",")}}`:`scope_${n}`}"`}>
|
|
35
35
|
${e}
|
|
36
36
|
</template>`}function _e(t,e=[],n=[],s={},r="web"){const i=["@dcloudio/uni-h5","uni-h5","@dcloudio/uni-ui","uni-ui"],c={vue:["defineComponent","reactive"]},a=[];for(const o of e){const l=t.get(o.split(":")[0]);if(l&&l.package){const u=c[l.package]??(c[l.package]=[]),h=l.parent||(l.alias||"").split(".")[0]||l.name;u.push(h),r==="uniapp"&&i.includes(l.package)&&a.push(h)}}for(const[o,l]of Object.entries(s))(c[o]??(c[o]=[])).push(...Array.from(l)),r==="uniapp"&&i.includes(o)&&a.push(...Array.from(l));return{imports:Object.entries(c).filter(([o,l])=>r==="uniapp"?!i.includes(o)&&!!l.length:!!l.length).map(([o,l])=>`import { ${f.dedupArray(l).join(",")}} from '${o}';`).concat(n),uniComponents:a}}function xe(t={}){const e=[];for(const[n,s]of Object.entries(t))e.push(`
|
|
37
37
|
${n} {
|
|
38
38
|
${oe(s)}
|
|
39
39
|
}
|
|
40
40
|
`);return e.join(`
|
|
41
|
-
`)}function Ee(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${s.url}');`)}),e}function Ae(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`)}),e}function Fe(t,e,n="web"){const{dsl:s}=t,r=Object.keys(s.computed||{}),i=
|
|
41
|
+
`)}function Ee(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${s.url}');`)}),e}function Ae(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`)}),e}function Fe(t,e,n="web"){const{dsl:s}=t,r=Object.keys(s.computed||{}),i=E(s.lifeCycles,r),c=E(s.computed,r),a=me(s.watch,r),p=he(s.dataSources),{methods:o,nodes:l,components:u,importBlocks:h,directives:d}=z(s.nodes||[],e,r,t.context),y=[...c,...a.computed],b=E({...o,...s.methods||{}},r),$=h.map(O=>`import ${O.name} from './${O.id}.vue';`);let{imports:N,uniComponents:g}=_e(e,u,$,t.imports,n);const w=Object.keys({...t.urlSchemas,...t.blockPlugins}),C=Ee(t.urlSchemas),P=Ae(t.blockPlugins);return{id:s.id,version:s.__VERSION__,name:s.name,state:ue(s.state).join(","),inject:le(s.inject).join(","),props:pe(s.props).join(","),emits:fe(s.emits).join(","),watch:a.watches.join(","),lifeCycles:i.join(","),computed:y.join(","),methods:[...p,...b].join(","),imports:`
|
|
42
42
|
`+N.join(`
|
|
43
43
|
`),components:ce(u,g).join(","),directives:d.join(","),returns:t.members.join(","),template:l.join(`
|
|
44
|
-
`),css:s.css||"",style:xe(t.style),urlSchemas:
|
|
45
|
-
`),blockPlugins:
|
|
46
|
-
`),asyncComponents:
|
|
44
|
+
`),css:s.css||"",style:xe(t.style),urlSchemas:C.join(`
|
|
45
|
+
`),blockPlugins:P.join(`
|
|
46
|
+
`),asyncComponents:w.join(","),uniComponents:g,renderer:n==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Ne=`
|
|
47
47
|
// @ts-nocheck
|
|
48
48
|
|
|
49
49
|
<%= imports %>
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mitt as K, dedupArray as
|
|
1
|
+
import { mitt as K, dedupArray as w, toArray as ee, kebabCase as I, camelCase as v, isPlainObject as te, template as U, cloneDeep as ne } from "@vtj/base";
|
|
2
2
|
import { format as B } from "prettier/standalone";
|
|
3
3
|
import * as se from "prettier/plugins/html";
|
|
4
4
|
import * as D 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.11.
|
|
11
|
+
* @version 0.11.9
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const Le = "0.11.
|
|
14
|
+
const Le = "0.11.9";
|
|
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.11.
|
|
19
|
+
* @version 0.11.9
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const re = [
|
|
@@ -74,14 +74,14 @@ async function W(t, e) {
|
|
|
74
74
|
plugins: [V]
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function S(t) {
|
|
78
78
|
return t && t.type === "JSExpression";
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function N(t) {
|
|
81
81
|
return typeof t == "object" && t && t.type === "JSFunction";
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
83
|
+
function $(t) {
|
|
84
|
+
return S(t) || N(t);
|
|
85
85
|
}
|
|
86
86
|
function q(t) {
|
|
87
87
|
return t.replace(new RegExp("this.", "g"), "");
|
|
@@ -90,10 +90,10 @@ function J(t) {
|
|
|
90
90
|
return t.replace(/this\.context\??\./g, "");
|
|
91
91
|
}
|
|
92
92
|
function f(t, e = !0, n = !0, s = []) {
|
|
93
|
-
let r =
|
|
94
|
-
return r =
|
|
93
|
+
let r = $(t) ? t.value : e ? JSON.stringify(t) : t;
|
|
94
|
+
return r = k(r, s), n ? q(J(r)) : J(r);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function k(t, e = []) {
|
|
97
97
|
let n = t;
|
|
98
98
|
for (const s of e)
|
|
99
99
|
n = n.replace(
|
|
@@ -200,7 +200,7 @@ class ue {
|
|
|
200
200
|
}
|
|
201
201
|
const r = Object.values(s);
|
|
202
202
|
for (const i of r)
|
|
203
|
-
|
|
203
|
+
$(i) ? i.value = this.replaceLibraryPath(i) : n(i);
|
|
204
204
|
};
|
|
205
205
|
n(e);
|
|
206
206
|
}
|
|
@@ -210,7 +210,7 @@ class ue {
|
|
|
210
210
|
delete s["uni-h5"], delete s["@dcloudio/uni-h5"], delete s["uni-ui"], delete s["@dcloudio/uni-ui"];
|
|
211
211
|
for (const r of Object.values(s))
|
|
212
212
|
n = n.concat(Array.from(r));
|
|
213
|
-
return
|
|
213
|
+
return w(n);
|
|
214
214
|
}
|
|
215
215
|
collectContext(e, n) {
|
|
216
216
|
const s = new Set(n?.id ? this.context[n.id] : []), r = (e.directives || []).find((a) => a.name === "vFor");
|
|
@@ -227,7 +227,7 @@ class ue {
|
|
|
227
227
|
this.context[e.id] = i;
|
|
228
228
|
}
|
|
229
229
|
collectStyle(e) {
|
|
230
|
-
e.id && e.props?.style && Object.keys(e.props.style).length && (this.style[`.${e.name}_${e.id}`] = e.props.style);
|
|
230
|
+
e.id && e.props?.style && Object.keys(e.props.style).length && !$(e.props.style) && (this.style[`.${e.name}_${e.id}`] = e.props.style);
|
|
231
231
|
}
|
|
232
232
|
collectUrlSchema(e) {
|
|
233
233
|
typeof e.from == "object" && e.from.type === "UrlSchema" && (this.urlSchemas[e.name] = e.from);
|
|
@@ -256,7 +256,7 @@ function pe(t = []) {
|
|
|
256
256
|
}
|
|
257
257
|
function fe(t = []) {
|
|
258
258
|
const e = (n) => n ? `[${ee(n).map((i) => i.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
259
|
-
return t.map((n) => typeof n == "string" ? `${n}: {}` : (
|
|
259
|
+
return t.map((n) => typeof n == "string" ? `${n}: {}` : ($(n.default) && !n.default.value && (n.default.value = "undefined"), `${n.name}: {
|
|
260
260
|
type:${e(n.type)},
|
|
261
261
|
required: ${f(!!n.required, !0, !1)},
|
|
262
262
|
default: ${f(n.default, !0, !1)}
|
|
@@ -265,17 +265,17 @@ function fe(t = []) {
|
|
|
265
265
|
function me(t = []) {
|
|
266
266
|
return t.map((e) => `'${typeof e == "string" ? e : e.name}'`);
|
|
267
267
|
}
|
|
268
|
-
function
|
|
268
|
+
function A(t = {}, e = []) {
|
|
269
269
|
return Object.entries(t).map(([n, s]) => {
|
|
270
270
|
let r = Q(f(s, !1, !1));
|
|
271
|
-
return r =
|
|
271
|
+
return r = k(r, e), r.startsWith("async") ? `async ${n}${r.replace(/^async/, "")}` : `${n}${r}`;
|
|
272
272
|
});
|
|
273
273
|
}
|
|
274
274
|
function he(t = [], e = []) {
|
|
275
275
|
const n = t.reduce(
|
|
276
|
-
(i, c) => (c.id &&
|
|
276
|
+
(i, c) => (c.id && N(c.source) && (i[`watcher_${c.id}`] = c.source), i),
|
|
277
277
|
{}
|
|
278
|
-
), s =
|
|
278
|
+
), s = A(n, e), r = t.map((i) => `watcher_${i.id}: {
|
|
279
279
|
deep: ${i.deep},
|
|
280
280
|
immediate:${i.immediate},
|
|
281
281
|
handler${Q(i.handler.value)}
|
|
@@ -288,13 +288,13 @@ function he(t = [], e = []) {
|
|
|
288
288
|
function de(t = {}) {
|
|
289
289
|
return Object.values(t).map((e) => {
|
|
290
290
|
if (e.type === "mock") {
|
|
291
|
-
const n =
|
|
291
|
+
const n = N(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
|
|
292
292
|
return `async ${e.name}(...args:any[]) {
|
|
293
293
|
const mock = this.provider.createMock(${n})
|
|
294
294
|
return await mock.apply(this, args);
|
|
295
295
|
}`;
|
|
296
296
|
} else {
|
|
297
|
-
const n =
|
|
297
|
+
const n = N(e.transform) && e.transform.value || "(res) => res";
|
|
298
298
|
return `async ${e.name}(...args:any[]) {
|
|
299
299
|
return await this.provider.apis['${e.ref}'].apply(this, args).then(${n});
|
|
300
300
|
}`;
|
|
@@ -332,14 +332,14 @@ function z(t, e, n = [], s = {}, r) {
|
|
|
332
332
|
return $e(t).forEach((u) => {
|
|
333
333
|
const m = [];
|
|
334
334
|
for (const d of u.children) {
|
|
335
|
-
let { id:
|
|
335
|
+
let { id: b, name: g, invisible: F, from: y } = d;
|
|
336
336
|
if (F)
|
|
337
337
|
continue;
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
const { props:
|
|
338
|
+
const C = ve(g, e, y);
|
|
339
|
+
C && a.push(C), X(y) && o.push({ id: y.id, name: g });
|
|
340
|
+
const { props: P, events: O, handlers: x } = we(
|
|
341
341
|
d,
|
|
342
|
-
|
|
342
|
+
b,
|
|
343
343
|
d.props,
|
|
344
344
|
d.events,
|
|
345
345
|
s,
|
|
@@ -348,23 +348,23 @@ function z(t, e, n = [], s = {}, r) {
|
|
|
348
348
|
d.directives,
|
|
349
349
|
n,
|
|
350
350
|
p
|
|
351
|
-
).join(" "),
|
|
351
|
+
).join(" "), j = d.children ? Oe(
|
|
352
352
|
d.children,
|
|
353
353
|
n,
|
|
354
354
|
e,
|
|
355
355
|
s,
|
|
356
356
|
d
|
|
357
357
|
) : "";
|
|
358
|
-
Object.assign(c,
|
|
359
|
-
let
|
|
360
|
-
typeof
|
|
361
|
-
`), Object.assign(c,
|
|
362
|
-
const
|
|
358
|
+
Object.assign(c, x);
|
|
359
|
+
let E = "";
|
|
360
|
+
typeof j == "string" ? E = j : (E = (j?.nodes || []).join(`
|
|
361
|
+
`), Object.assign(c, j?.methods || {}), a = a.concat(j?.components || []), o = o.concat(j?.importBlocks || []));
|
|
362
|
+
const _ = ["@dcloudio/uni-h5", "@dcloudio/uni-ui"].includes(
|
|
363
363
|
y
|
|
364
364
|
) ? I(g) : Y(y) || Z(y) ? "component" : g;
|
|
365
365
|
m.push(
|
|
366
|
-
ye.includes(
|
|
367
|
-
` +
|
|
366
|
+
ye.includes(_) ? `<${_} ${T} ${P} ${O} />` : `<${_} ${T} ${P} ${O}>${E ? `
|
|
367
|
+
` + E.trim() : ""}</${_}>`
|
|
368
368
|
);
|
|
369
369
|
}
|
|
370
370
|
const h = xe(u.slot, m.join(`
|
|
@@ -374,12 +374,12 @@ function z(t, e, n = [], s = {}, r) {
|
|
|
374
374
|
nodes: i,
|
|
375
375
|
methods: c,
|
|
376
376
|
directives: ge(p),
|
|
377
|
-
components:
|
|
378
|
-
importBlocks:
|
|
377
|
+
components: w(a),
|
|
378
|
+
importBlocks: w(o, "id")
|
|
379
379
|
};
|
|
380
380
|
}
|
|
381
381
|
function ge(t) {
|
|
382
|
-
return
|
|
382
|
+
return w(t).map((e) => `${e.startsWith("v") ? e.substring(1) : e}:${e}`);
|
|
383
383
|
}
|
|
384
384
|
function $e(t = []) {
|
|
385
385
|
const e = /* @__PURE__ */ new Map();
|
|
@@ -408,12 +408,15 @@ function Z(t) {
|
|
|
408
408
|
return typeof t == "object" && t.type === "Plugin";
|
|
409
409
|
}
|
|
410
410
|
function be(t, e, n = []) {
|
|
411
|
-
return t === "style" ?
|
|
411
|
+
return t === "style" ? $(e) ? `:style="${f({
|
|
412
412
|
...e,
|
|
413
|
-
value:
|
|
414
|
-
})}"` :
|
|
413
|
+
value: k(e.value, n)
|
|
414
|
+
})}"` : "" : t === "__class" && $(e) ? `:class="${f({
|
|
415
415
|
...e,
|
|
416
|
-
value:
|
|
416
|
+
value: k(e.value, n)
|
|
417
|
+
})}"` : typeof e == "string" ? `${t}="${e}"` : $(e) ? `:${t}="${f({
|
|
418
|
+
...e,
|
|
419
|
+
value: k(e.value, n)
|
|
417
420
|
})}"` : te(e) ? `:${t}='{${oe(
|
|
418
421
|
e
|
|
419
422
|
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
@@ -421,7 +424,7 @@ function be(t, e, n = []) {
|
|
|
421
424
|
function je(t, e = {}, n = []) {
|
|
422
425
|
if (!!Object.keys(e.style || {}).length) {
|
|
423
426
|
const i = `${t.name}_${t.id}`;
|
|
424
|
-
e.class ? typeof e.class == "string" ? e.class = [e.class, i].join(" ") : (e.__class = e.class, e.class = i) :
|
|
427
|
+
e.class ? typeof e.class == "string" ? e.class = [e.class, i].join(" ") : (e.__class = e.class, e.class = i) : e.class = i, $(e.style) || delete e.style;
|
|
425
428
|
}
|
|
426
429
|
const r = t.from;
|
|
427
430
|
return (Y(r) || Z(r)) && (e.is = {
|
|
@@ -437,7 +440,7 @@ function ke(t, e = {}, n = {}) {
|
|
|
437
440
|
const s = {}, r = Array.from(n[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
|
|
438
441
|
return {
|
|
439
442
|
binders: Object.entries(e).map(([a, p]) => {
|
|
440
|
-
const o = p.handler.value.startsWith("this."), l = o ? q(p.handler.value) : `${
|
|
443
|
+
const o = p.handler.value.startsWith("this."), l = o ? q(p.handler.value) : `${v(a)}_${t}${i}`;
|
|
441
444
|
return o || (s[l] = r.length ? {
|
|
442
445
|
type: "JSFunction",
|
|
443
446
|
value: `{
|
|
@@ -464,7 +467,7 @@ function Ce(t = [], e = [], n = []) {
|
|
|
464
467
|
), p && s.push(
|
|
465
468
|
`v-bind="${f(p.value, !0, !0, e)}"`
|
|
466
469
|
), c.forEach((u) => {
|
|
467
|
-
const m = G(u.modifiers, !0), h = u.arg ?
|
|
470
|
+
const m = G(u.modifiers, !0), h = u.arg ? S(u.arg) ? `:[${f(u.arg, !0, !0, e)}]` : `:${u.arg}` : "";
|
|
468
471
|
s.push(
|
|
469
472
|
`v-model${h}${m}="${f(u.value, !0, !0, e)}"`
|
|
470
473
|
);
|
|
@@ -479,11 +482,11 @@ function Ce(t = [], e = [], n = []) {
|
|
|
479
482
|
), l && l.length && l.forEach((u) => {
|
|
480
483
|
if (!u.name) return;
|
|
481
484
|
let m = "", h = "";
|
|
482
|
-
|
|
485
|
+
S(u.name) ? (h = f(u.name, !0, !0, e), n.push(h)) : h = u.name;
|
|
483
486
|
const d = h?.startsWith("v") ? I(h) : I("v-" + h);
|
|
484
|
-
if (m += d, u.arg && (
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
+
if (m += d, u.arg && (S(u.arg) ? m += `:[${f(u.name, !0, !0, e)}]` : m += `:${u.arg}`), u.modifiers) {
|
|
488
|
+
const b = Object.keys(u.modifiers);
|
|
489
|
+
b.length && (m += b.map((g) => "." + g));
|
|
487
490
|
}
|
|
488
491
|
u.value ? s.push(
|
|
489
492
|
`${m}="${f(u.value, !0, !0, e)}"`
|
|
@@ -496,17 +499,17 @@ function Pe(t = []) {
|
|
|
496
499
|
), n = t.filter(
|
|
497
500
|
(o) => !L.includes(o.name)
|
|
498
501
|
), s = e.find(
|
|
499
|
-
(o) =>
|
|
502
|
+
(o) => v(o.name) === "vIf"
|
|
500
503
|
), r = e.find(
|
|
501
|
-
(o) =>
|
|
504
|
+
(o) => v(o.name) === "vFor"
|
|
502
505
|
), i = e.find(
|
|
503
|
-
(o) =>
|
|
506
|
+
(o) => v(o.name) === "vShow"
|
|
504
507
|
), c = e.find(
|
|
505
|
-
(o) =>
|
|
508
|
+
(o) => v(o.name) === "vBind"
|
|
506
509
|
), a = e.find(
|
|
507
|
-
(o) =>
|
|
510
|
+
(o) => v(o.name) === "vHtml"
|
|
508
511
|
), p = e.filter(
|
|
509
|
-
(o) =>
|
|
512
|
+
(o) => v(o.name) === "vModel"
|
|
510
513
|
);
|
|
511
514
|
return {
|
|
512
515
|
vIf: s,
|
|
@@ -519,7 +522,7 @@ function Pe(t = []) {
|
|
|
519
522
|
};
|
|
520
523
|
}
|
|
521
524
|
function Oe(t, e, n, s, r) {
|
|
522
|
-
return typeof t == "string" ? t :
|
|
525
|
+
return typeof t == "string" ? t : S(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? z(t, n, e, s, r) : "";
|
|
523
526
|
}
|
|
524
527
|
function xe(t, e, n) {
|
|
525
528
|
if (!t) return e;
|
|
@@ -547,7 +550,7 @@ function Ee(t, e = [], n = [], s = {}, r = "web") {
|
|
|
547
550
|
for (const [o, l] of Object.entries(s))
|
|
548
551
|
(c[o] ?? (c[o] = [])).push(...Array.from(l)), r === "uniapp" && i.includes(o) && a.push(...Array.from(l));
|
|
549
552
|
return {
|
|
550
|
-
imports: Object.entries(c).filter(([o, l]) => r === "uniapp" ? !i.includes(o) && !!l.length : !!l.length).map(([o, l]) => `import { ${
|
|
553
|
+
imports: Object.entries(c).filter(([o, l]) => r === "uniapp" ? !i.includes(o) && !!l.length : !!l.length).map(([o, l]) => `import { ${w(l).join(
|
|
551
554
|
","
|
|
552
555
|
)}} from '${o}';`).concat(n),
|
|
553
556
|
uniComponents: a
|
|
@@ -581,18 +584,18 @@ function Ne(t = {}) {
|
|
|
581
584
|
}), e;
|
|
582
585
|
}
|
|
583
586
|
function Fe(t, e, n = "web") {
|
|
584
|
-
const { dsl: s } = t, r = Object.keys(s.computed || {}), i =
|
|
587
|
+
const { dsl: s } = t, r = Object.keys(s.computed || {}), i = A(s.lifeCycles, r), c = A(s.computed, r), a = he(s.watch, r), p = de(s.dataSources), { methods: o, nodes: l, components: u, importBlocks: m, directives: h } = z(
|
|
585
588
|
s.nodes || [],
|
|
586
589
|
e,
|
|
587
590
|
r,
|
|
588
591
|
t.context
|
|
589
|
-
), d = [...c, ...a.computed],
|
|
592
|
+
), d = [...c, ...a.computed], b = A(
|
|
590
593
|
{
|
|
591
594
|
...o,
|
|
592
595
|
...s.methods || {}
|
|
593
596
|
},
|
|
594
597
|
r
|
|
595
|
-
), g = m.map((
|
|
598
|
+
), g = m.map((x) => `import ${x.name} from './${x.id}.vue';`);
|
|
596
599
|
let { imports: F, uniComponents: y } = Ee(
|
|
597
600
|
e,
|
|
598
601
|
u,
|
|
@@ -600,10 +603,10 @@ function Fe(t, e, n = "web") {
|
|
|
600
603
|
t.imports,
|
|
601
604
|
n
|
|
602
605
|
);
|
|
603
|
-
const
|
|
606
|
+
const C = Object.keys({
|
|
604
607
|
...t.urlSchemas,
|
|
605
608
|
...t.blockPlugins
|
|
606
|
-
}),
|
|
609
|
+
}), P = Ae(t.urlSchemas), O = Ne(t.blockPlugins);
|
|
607
610
|
return {
|
|
608
611
|
id: s.id,
|
|
609
612
|
version: s.__VERSION__,
|
|
@@ -615,7 +618,7 @@ function Fe(t, e, n = "web") {
|
|
|
615
618
|
watch: a.watches.join(","),
|
|
616
619
|
lifeCycles: i.join(","),
|
|
617
620
|
computed: d.join(","),
|
|
618
|
-
methods: [...p, ...
|
|
621
|
+
methods: [...p, ...b].join(","),
|
|
619
622
|
imports: `
|
|
620
623
|
` + F.join(`
|
|
621
624
|
`),
|
|
@@ -626,11 +629,11 @@ function Fe(t, e, n = "web") {
|
|
|
626
629
|
`),
|
|
627
630
|
css: s.css || "",
|
|
628
631
|
style: _e(t.style),
|
|
629
|
-
urlSchemas:
|
|
632
|
+
urlSchemas: P.join(`
|
|
630
633
|
`),
|
|
631
|
-
blockPlugins:
|
|
634
|
+
blockPlugins: O.join(`
|
|
632
635
|
`),
|
|
633
|
-
asyncComponents:
|
|
636
|
+
asyncComponents: C.join(","),
|
|
634
637
|
uniComponents: y,
|
|
635
638
|
renderer: n === "uniapp" ? "@vtj/uni-app" : "@vtj/renderer"
|
|
636
639
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"低代码引擎",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"prettier": "~3.5.0",
|
|
25
|
-
"@vtj/
|
|
26
|
-
"@vtj/
|
|
25
|
+
"@vtj/base": "~0.11.2",
|
|
26
|
+
"@vtj/core": "~0.11.9"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@vtj/cli": "~0.11.2"
|
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.11.
|
|
5
|
+
* @version 0.11.8
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.11.
|
|
8
|
+
export declare const version = "0.11.8";
|