@vtj/coder 0.13.20 → 0.13.21
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 +6 -6
- package/dist/index.mjs +12 -12
- package/package.json +4 -4
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
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.21
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const re="0.13.
|
|
7
|
+
*/const re="0.13.21";/**!
|
|
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.21
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
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 N(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}',
|
|
@@ -28,10 +28,10 @@
|
|
|
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 ye=["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:y,name:$,invisible:b,from:g}=h;if(b)continue;const C=$e($,e,g);C&&a.push(C),
|
|
32
|
-
`),Object.assign(o,S?.methods||{}),a=a.concat(S?.components||[]),u=u.concat(S?.importBlocks||[]));const _=["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes(g||e.get($)?.package)?f.kebabCase($):
|
|
31
|
+
}`}})}const ye=["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:y,name:$,invisible:b,from:g}=h;if(b)continue;const C=$e($,e,g);C&&a.push(C),Z(g)&&u.push({id:g.id,name:$});const{props:P,events:O,handlers:E}=we(h,y,h.props,h.events,n,s),W=Ce(h.directives,s,m).join(" "),S=h.children?Oe(h.children,s,e,n,h):"";Object.assign(o,E);let x="";typeof S=="string"?x=S:(x=(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(g||e.get($)?.package)?f.kebabCase($):X(g)||Y(g)?"component":$;v.push(ye.includes(_)?`<${_} ${W} ${P} ${O} />`:`<${_} ${W} ${P} ${O}>${x?`
|
|
33
33
|
`+x.trim():""}</${_}>`)}const p=Ee(c.slot,v.join(`
|
|
34
|
-
`),i?.id);r.push(p)}),{nodes:r,methods:o,directives:ge(m),components:f.dedupArray(a),importBlocks:f.dedupArray(u,"id")}}function ge(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
|
|
34
|
+
`),i?.id);r.push(p)}),{nodes:r,methods:o,directives:ge(m),components:f.dedupArray(a),importBlocks:f.dedupArray(u,"id")}}function ge(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
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}=Pe(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),y=p.arg?k(p.arg)?`:[${d(p.arg,!0,!0,e)}]`:`:${p.arg}`:"";n.push(`v-model${y}${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="",y="";k(p.name)?(y=d(p.name,!0,!0,e),s.push(y)):y=p.name;const $=y?.startsWith("v")?f.kebabCase(y):f.kebabCase("v-"+y);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(g=>"."+g))}p.value?n.push(`${h}="${d(p.value,!0,!0,e)}"`):n.push(h)}),n}function Pe(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 Oe(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 Ee(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}
|
package/dist/index.mjs
CHANGED
|
@@ -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.21
|
|
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.21";
|
|
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.21
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const oe = [
|
|
@@ -123,7 +123,7 @@ function G(t) {
|
|
|
123
123
|
function ae(t = {}) {
|
|
124
124
|
return Object.entries(t).map(([e, s]) => `"${e}": ${h(s)}`);
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function Z(t = {}, e = !1) {
|
|
127
127
|
const s = Object.keys(t);
|
|
128
128
|
return e ? s.map((n) => "." + n) : s;
|
|
129
129
|
}
|
|
@@ -348,7 +348,7 @@ function z(t, e, s = [], n = {}, i) {
|
|
|
348
348
|
if (v)
|
|
349
349
|
continue;
|
|
350
350
|
const E = je($, e, g);
|
|
351
|
-
E && c.push(E),
|
|
351
|
+
E && c.push(E), X(g) && u.push({ id: g.id, name: $ });
|
|
352
352
|
const { props: O, events: P, handlers: x } = Ee(
|
|
353
353
|
m,
|
|
354
354
|
d,
|
|
@@ -373,7 +373,7 @@ function z(t, e, s = [], n = {}, i) {
|
|
|
373
373
|
`), Object.assign(o, S?.methods || {}), c = c.concat(S?.components || []), u = u.concat(S?.importBlocks || []));
|
|
374
374
|
const I = ["@dcloudio/uni-h5", "@dcloudio/uni-ui"].includes(
|
|
375
375
|
g || e.get($)?.package
|
|
376
|
-
) ? F($) :
|
|
376
|
+
) ? F($) : Y(g) || K(g) ? "component" : $;
|
|
377
377
|
y.push(
|
|
378
378
|
$e.includes(I) ? `<${I} ${W} ${O} ${P} />` : `<${I} ${W} ${O} ${P}>${_ ? `
|
|
379
379
|
` + _.trim() : ""}</${I}>`
|
|
@@ -408,12 +408,12 @@ function je(t, e, s) {
|
|
|
408
408
|
const i = n.parent ? `${n.parent}.${n.alias}` : n.alias;
|
|
409
409
|
return `${t}: ${i}`;
|
|
410
410
|
}
|
|
411
|
-
return
|
|
411
|
+
return X(s) || n ? t : null;
|
|
412
412
|
}
|
|
413
|
-
function
|
|
413
|
+
function X(t) {
|
|
414
414
|
return !!t && typeof t == "object" && t.type === "Schema";
|
|
415
415
|
}
|
|
416
|
-
function
|
|
416
|
+
function Y(t) {
|
|
417
417
|
return typeof t == "object" && t.type === "UrlSchema";
|
|
418
418
|
}
|
|
419
419
|
function K(t) {
|
|
@@ -439,13 +439,13 @@ function ke(t, e = {}, s = []) {
|
|
|
439
439
|
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;
|
|
440
440
|
}
|
|
441
441
|
const i = t.from;
|
|
442
|
-
return (
|
|
442
|
+
return (Y(i) || K(i)) && (e.is = {
|
|
443
443
|
type: "JSExpression",
|
|
444
444
|
value: t.name
|
|
445
445
|
}), Object.entries(e).map(([r, o]) => Se(r, o, s));
|
|
446
446
|
}
|
|
447
447
|
function we(t, e, s, n, i) {
|
|
448
|
-
const r =
|
|
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
451
|
function Ce(t, e = {}, s = {}) {
|
|
@@ -491,7 +491,7 @@ function Oe(t = [], e = [], s = []) {
|
|
|
491
491
|
), l && n.push(
|
|
492
492
|
`v-bind="${h(l.value, !0, !0, e)}"`
|
|
493
493
|
), f.forEach((p) => {
|
|
494
|
-
const m =
|
|
494
|
+
const m = Z(p.modifiers, !0), d = p.arg ? k(p.arg) ? `:[${h(p.arg, !0, !0, e)}]` : `:${p.arg}` : "";
|
|
495
495
|
n.push(
|
|
496
496
|
`v-model${d}${m}="${h(p.value, !0, !0, e)}"`
|
|
497
497
|
);
|
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.21",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"低代码引擎",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"prettier": "~3.6.0",
|
|
25
|
-
"@vtj/
|
|
26
|
-
"@vtj/
|
|
25
|
+
"@vtj/base": "~0.12.3",
|
|
26
|
+
"@vtj/core": "~0.13.21"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@vtj/cli": "~0.12.
|
|
29
|
+
"@vtj/cli": "~0.12.12"
|
|
30
30
|
},
|
|
31
31
|
"exports": {
|
|
32
32
|
".": {
|
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.20
|
|
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.20";
|