@vtj/coder 0.11.16 → 0.12.0-alpha.0

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 CHANGED
@@ -2,15 +2,15 @@
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.16
5
+ * @version 0.12.0-alpha.0
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const se="0.11.16";/**!
7
+ */const se="0.12.0-alpha.0";/**!
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.16
11
+ * @version 0.12.0-alpha.0
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 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}: {
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){if(e)return t;try{return(await T.format(t,{parser:"babel-ts",...B,plugins:[D,U]})).replace(/;\n$/gi,"")}catch(n){return console.warn(n),t}}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.replace(/\"/g,"'"):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
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}: {
@@ -60,7 +60,7 @@ export default defineComponent({
60
60
  id: '<%= id %>',
61
61
  version: '<%= version %>'
62
62
  });
63
- const state = reactive<Record<string, any>>({ <%= state %> });
63
+ const state = reactive({ <%= state %> });
64
64
  <%= urlSchemas %>
65
65
  <%= blockPlugins %>
66
66
  return {
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.11.16
11
+ * @version 0.12.0-alpha.0
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Le = "0.11.16";
14
+ const Le = "0.12.0-alpha.0";
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.16
19
+ * @version 0.12.0-alpha.0
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 R = {
36
+ const T = {
37
37
  arrowParens: "always",
38
38
  bracketSpacing: !0,
39
39
  bracketSameLine: !0,
@@ -56,21 +56,26 @@ const R = {
56
56
  async function M(t, e) {
57
57
  return e ? t : await B(t, {
58
58
  parser: "vue",
59
- ...R,
59
+ ...T,
60
60
  plugins: [se, D, H, V]
61
61
  });
62
62
  }
63
63
  async function ie(t, e) {
64
- return e ? t : await B(t, {
65
- parser: "babel-ts",
66
- ...R,
67
- plugins: [D, H]
68
- });
64
+ if (e) return t;
65
+ try {
66
+ return (await B(t, {
67
+ parser: "babel-ts",
68
+ ...T,
69
+ plugins: [D, H]
70
+ })).replace(/;\n$/gi, "");
71
+ } catch (n) {
72
+ return console.warn(n), t;
73
+ }
69
74
  }
70
75
  async function W(t, e) {
71
76
  return e ? t : B(t, {
72
77
  parser: "scss",
73
- ...R,
78
+ ...T,
74
79
  plugins: [V]
75
80
  });
76
81
  }
@@ -90,7 +95,7 @@ function J(t) {
90
95
  return t.replace(/this\.context\??\./g, "");
91
96
  }
92
97
  function f(t, e = !0, n = !0, s = []) {
93
- let r = $(t) ? t.value : e ? JSON.stringify(t) : t;
98
+ let r = $(t) ? t.value.replace(/\"/g, "'") : e ? JSON.stringify(t) : t;
94
99
  return r = k(r, s), n ? q(J(r)) : J(r);
95
100
  }
96
101
  function k(t, e = []) {
@@ -324,7 +329,7 @@ const ye = [
324
329
  "vBind",
325
330
  "vHtml"
326
331
  ];
327
- function z(t, e, n = [], s = {}, r) {
332
+ function X(t, e, n = [], s = {}, r) {
328
333
  const i = [];
329
334
  let c = {}, a = [];
330
335
  const p = [];
@@ -336,7 +341,7 @@ function z(t, e, n = [], s = {}, r) {
336
341
  if (F)
337
342
  continue;
338
343
  const C = ve(g, e, y);
339
- C && a.push(C), X(y) && o.push({ id: y.id, name: g });
344
+ C && a.push(C), z(y) && o.push({ id: y.id, name: g });
340
345
  const { props: P, events: O, handlers: x } = we(
341
346
  d,
342
347
  b,
@@ -344,7 +349,7 @@ function z(t, e, n = [], s = {}, r) {
344
349
  d.events,
345
350
  s,
346
351
  n
347
- ), T = Ce(
352
+ ), R = Ce(
348
353
  d.directives,
349
354
  n,
350
355
  p
@@ -363,7 +368,7 @@ function z(t, e, n = [], s = {}, r) {
363
368
  y
364
369
  ) ? I(g) : Y(y) || Z(y) ? "component" : g;
365
370
  m.push(
366
- ye.includes(_) ? `<${_} ${T} ${P} ${O} />` : `<${_} ${T} ${P} ${O}>${E ? `
371
+ ye.includes(_) ? `<${_} ${R} ${P} ${O} />` : `<${_} ${R} ${P} ${O}>${E ? `
367
372
  ` + E.trim() : ""}</${_}>`
368
373
  );
369
374
  }
@@ -396,9 +401,9 @@ function ve(t, e, n) {
396
401
  const r = s.parent ? `${s.parent}.${s.alias}` : s.alias;
397
402
  return `${t}: ${r}`;
398
403
  }
399
- return X(n) || s ? t : null;
404
+ return z(n) || s ? t : null;
400
405
  }
401
- function X(t) {
406
+ function z(t) {
402
407
  return !!t && typeof t == "object" && t.type === "Schema";
403
408
  }
404
409
  function Y(t) {
@@ -522,7 +527,7 @@ function Pe(t = []) {
522
527
  };
523
528
  }
524
529
  function Oe(t, e, n, s, r) {
525
- return typeof t == "string" ? t : S(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? z(t, n, e, s, r) : "";
530
+ return typeof t == "string" ? t : S(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? X(t, n, e, s, r) : "";
526
531
  }
527
532
  function xe(t, e, n) {
528
533
  if (!t) return e;
@@ -584,7 +589,7 @@ function Ne(t = {}) {
584
589
  }), e;
585
590
  }
586
591
  function Fe(t, e, n = "web") {
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(
592
+ 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 } = X(
588
593
  s.nodes || [],
589
594
  e,
590
595
  r,
@@ -655,7 +660,7 @@ export default defineComponent({
655
660
  id: '<%= id %>',
656
661
  version: '<%= version %>'
657
662
  });
658
- const state = reactive<Record<string, any>>({ <%= state %> });
663
+ const state = reactive({ <%= state %> });
659
664
  <%= urlSchemas %>
660
665
  <%= blockPlugins %>
661
666
  return {
@@ -681,9 +686,9 @@ export default defineComponent({
681
686
  <%= css %>
682
687
  <%= style %>
683
688
  </style>
684
- `, Re = U(Ie), Te = U(Be);
689
+ `, Te = U(Ie), Re = U(Be);
685
690
  async function Ue(t, e = /* @__PURE__ */ new Map(), n = [], s = "web", r) {
686
- const i = new ue(ne(t), n), c = Fe(i, e, s), a = Re(c), p = Te({
691
+ const i = new ue(ne(t), n), c = Fe(i, e, s), a = Te(c), p = Re({
687
692
  template: c.template,
688
693
  css: await W(c.css, r),
689
694
  script: await ie(a, r),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.11.16",
4
+ "version": "0.12.0-alpha.0",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -22,11 +22,11 @@
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
24
  "prettier": "~3.5.0",
25
- "@vtj/core": "~0.11.16",
26
- "@vtj/base": "~0.11.2"
25
+ "@vtj/base": "~0.12.0-alpha.0",
26
+ "@vtj/core": "~0.12.0-alpha.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@vtj/cli": "~0.11.2"
29
+ "@vtj/cli": "~0.12.0-alpha.0"
30
30
  },
31
31
  "exports": {
32
32
  ".": {
@@ -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.15
5
+ * @version 0.11.16
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.11.15";
8
+ export declare const version = "0.11.16";