@vtj/coder 0.9.0-alpha.5 → 0.9.0-alpha.50
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 +10 -10
- package/package.json +5 -5
- package/types/generator.d.ts +1 -1
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.9.0-alpha.
|
|
5
|
+
* @version 0.9.0-alpha.50
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const ee="0.9.0-alpha.
|
|
7
|
+
*/const ee="0.9.0-alpha.50";/**!
|
|
8
8
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/core
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.9.0-alpha.
|
|
11
|
+
* @version 0.9.0-alpha.50
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/const te=["slot","template","component","img","div","p","h1","h2","h3","span","a"];l.mitt();const _={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 q(t,e){return e?t:await x.format(t,{parser:"vue",..._,plugins:[K,I,T,J]})}async function ne(t,e){return e?t:await x.format(t,{parser:"babel-ts",..._,plugins:[I,T]})}async function R(t,e){return e?t:x.format(t,{parser:"scss",..._,plugins:[J]})}function E(t){return t&&t.type==="JSExpression"}function A(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function $(t){return E(t)||A(t)}function L(t){return t.replace(new RegExp("this.","g"),"")}function W(t){return t.replace(/this\.context\??\./g,"")}function u(t,e=!0,n=!0,r=[]){let i=$(t)?t.value:e?JSON.stringify(t):t;return i=w(i,r),n?L(W(i)):W(i)}function w(t,e=[]){let n=t;for(const r of e)n=n.replace(new RegExp(`this.${r}.value`,"g"),`this.${r}`);return n}function U(t){let e=t.trim();if(e=/^\((\(|async|function)/.test(e)?e.substring(1,e.length-1):e,e.startsWith("{"))return e;if(e.startsWith("async function"))e=e.replace(/^async function/,"async");else if(e.startsWith("function"))e=e.replace(/^function/,"");else{const i=/^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,s=e.match(i);s&&s[2]&&(s[2].startsWith("{")||(e=e.replace(s[2],`{ return ${s[2]} }`))),e=e.replace("=>","")}return e}function re(t={}){return Object.entries(t).map(([e,n])=>`"${e}": ${u(n)}`)}function V(t={},e=!1){const n=Object.keys(t);return e?n.map(r=>"."+r):n}function se(t){let e="";for(var n in t)if(t.hasOwnProperty(n)){var r=t[n];e+=n+": "+r+";"}return e}class ie{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 r=n.pop(),i=n.join(".")+".",s=n.pop();if(r&&s){const o=this.dependencies.find(a=>a.library===s)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(r)}return{name:r,path:i,library:s}}return null}replaceLibraryPath(e){const{libraryRegex:n}=this;let r=e.value;for(const i of n){const s=e.value.match(i)||[];for(const o of s){const a=this.collectImport(o);if(a){const c=a.path.replace(/\$/g,"\\$");r=r.replace(new RegExp(c,"g"),"")}}}return r}walk(e){const n=r=>{if(!r||typeof r!="object")return;if(Array.isArray(r)){for(let s of r)n(s);return}const i=Object.values(r);for(const s of i)$(s)?s.value=this.replaceLibraryPath(s):n(s)};n(e)}getLibraryMember(e=[]){let n=[...e];for(const r of Object.values(this.imports))n=n.concat(Array.from(r));return l.dedupArray(n)}collectContext(e,n){const r=new Set(n?.id?this.context[n.id]:[]),i=(e.directives||[]).find(a=>a.name==="vFor");let s=new Set(Array.from(r));if(i){const{item:a="item",index:c="index"}=i.iterator||{};s=new Set([a,c,...Array.from(s)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],c=a.length?a:[`scope_${n?.id}`];s=new Set([...c,...Array.from(s)])}this.context[e.id]=s}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&(this.style[`.${e.name}_${e.id}`]=e.props.style)}collectUrlSchema(e){typeof e.from=="object"&&e.from.type==="UrlSchema"&&(this.urlSchemas[e.name]=e.from)}collectBlockPlugin(e){typeof e.from=="object"&&e.from.type==="Plugin"&&(this.blockPlugins[e.name]=e.from)}walkNodes(e){const n=(r,i)=>{this.collectContext(r,i),this.collectStyle(r),this.collectUrlSchema(r),this.collectBlockPlugin(r),Array.isArray(r.children)&&r.children.forEach(s=>n(s,r))};Array.isArray(e.nodes)&&e.nodes.forEach(r=>n(r))}}function oe(t={}){return Object.entries(t).map(([e,n])=>{const r=u(n,!1);return`${e}:${r}`})}function ae(t=[]){return t.map(e=>`${e.name}: {
|
|
14
14
|
from: '${e.from||e.name}',
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
}`);return{computed:r,watches:i}}function pe(t={}){return Object.values(t).map(e=>{const n=A(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
25
25
|
return await this.provider.apis['${e.ref}'].apply(this, args).then(${n});
|
|
26
26
|
}`})}function M(t,e,n=[],r={},i){const s=[];let o={},a=[],c=[];return fe(t).forEach(f=>{const b=[];for(const m of f.children){let{id:O,name:h,invisible:C,from:d}=m;if(C)continue;const v=me(h,e,d);v&&a.push(v),D(d)&&c.push({id:d.id,name:h});const{props:g,events:F,handlers:G}=$e(m,O,m.props,m.events,r,n),N=be(m.directives,n).join(" "),y=m.children?je(m.children,n,e,r,m):"";Object.assign(o,G);let j="";typeof y=="string"?j=y:(j=(y?.nodes||[]).join(`
|
|
27
|
-
`),Object.assign(o,y?.methods||{}),a=a.concat(y?.components||[]),c=c.concat(y?.importBlocks||[]));const B=
|
|
27
|
+
`),Object.assign(o,y?.methods||{}),a=a.concat(y?.components||[]),c=c.concat(y?.importBlocks||[]));const B=Q(d)||z(d)?"component":h;b.push(h==="img"?`<${h} ${N} ${g} ${F} />`:`<${B} ${N} ${g} ${F}>${j?`
|
|
28
28
|
`+j.trim():""}</${B}>`)}const P=Se(f.slot,b.join(`
|
|
29
|
-
`),i?.id);s.push(P)}),{nodes:s,methods:o,components:l.dedupArray(a),importBlocks:l.dedupArray(c,"id")}}function fe(t=[]){const e=new Map;for(const n of t){const r=typeof n.slot=="string"?n.slot:n.slot?.name,i=e.get(r);i?i.children.push(n):e.set(r,{slot:n.slot,children:[n]})}return e}function me(t,e,n){if(te.includes(t))return null;const r=e.get(t);if(r&&r.alias){const i=r.parent?`${r.parent}.${r.alias}`:r.alias;return`${t}: ${i}`}return D(n)||r?t:null}function D(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function
|
|
29
|
+
`),i?.id);s.push(P)}),{nodes:s,methods:o,components:l.dedupArray(a),importBlocks:l.dedupArray(c,"id")}}function fe(t=[]){const e=new Map;for(const n of t){const r=typeof n.slot=="string"?n.slot:n.slot?.name,i=e.get(r);i?i.children.push(n):e.set(r,{slot:n.slot,children:[n]})}return e}function me(t,e,n){if(te.includes(t))return null;const r=e.get(t);if(r&&r.alias){const i=r.parent?`${r.parent}.${r.alias}`:r.alias;return`${t}: ${i}`}return D(n)||r?t:null}function D(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function Q(t){return typeof t=="object"&&t.type==="UrlSchema"}function z(t){return typeof t=="object"&&t.type==="Plugin"}function he(t,e,n=[]){return t==="style"?"":t==="__class"&&$(e)?`:class="${u({...e,value:w(e.value,n)})}"`:typeof e=="string"?`${t}="${e}"`:$(e)?`:${t}="${u({...e,value:w(e.value,n)})}"`:l.isPlainObject(e)?`:${t}='{${re(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function de(t,e={},n=[]){if(!!Object.keys(e.style||{}).length){const s=`${t.name}_${t.id}`;e.class?typeof e.class=="string"?e.class=[e.class,s].join(" "):(e.__class=e.class,e.class=s):(e.class=s,delete e.style)}const i=t.from;return(Q(i)||z(i))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([s,o])=>he(s,o,n))}function ye(t,e,n,r,i){const s=V(e.modifiers,!0);return i?`@${t}${s.join("")}="${n}"`:r&&r.length>0?`@${t}${s.join("")}="(...args:any[]) => ${n}"`:`@${t}${s.join("")}="${n}"`}function ge(t,e={},n={}){const r={},i=Array.from(n[t]||new Set([])),s=i.length?`({${i.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,c])=>{const p=c.handler.value.startsWith("this."),f=p?L(c.handler.value):`${l.camelCase(a)}_${t}${s}`;return p||(r[f]=i.length?{type:"JSFunction",value:`{
|
|
30
30
|
return (${c.handler.value}).apply(this, args);
|
|
31
31
|
}`}:c.handler),ye(a,c,f,i,p)}),handlers:r}}function $e(t,e,n={},r={},i={},s){const{binders:o,handlers:a}=ge(e,r,i);return{props:de(t,n,s).join(" "),handlers:a,binders:o,events:o.join(" ")}}function be(t=[],e=[]){const n=[],{vIf:r,vShow:i,vModels:s,vFor:o,vBind:a}=ve(t);if(r&&n.push(`v-if="${u(r.value,!0,!0,e)}"`),i&&n.push(`v-show="${u(i.value,!0,!0,e)}"`),a&&n.push(`v-bind="${u(a.value,!0,!0,e)}"`),s.forEach(c=>{const p=V(c.modifiers,!0),f=c.arg?E(c.arg)?`:[${u(c.arg,!0,!0,e)}]`:`:${c.arg}`:"";n.push(`v-model${f}${p}="${u(c.value,!0,!0,e)}"`)}),o){const{item:c,index:p}={item:"item",index:"index",...o.iterator};n.push(`v-for="(${c}, ${p}) in ${u(o.value,!0,!0,e)}"`)}return n}function ve(t=[]){const e=t.find(o=>l.camelCase(o.name)==="vIf"),n=t.find(o=>l.camelCase(o.name)==="vFor"),r=t.find(o=>l.camelCase(o.name)==="vShow"),i=t.find(o=>l.camelCase(o.name)==="vBind"),s=t.filter(o=>l.camelCase(o.name)==="vModel");return{vIf:e,vFor:n,vShow:r,vModels:s,vBind:i}}function je(t,e,n,r,i){return typeof t=="string"?t:E(t)?`{{ ${u(t,!1,!0,e)} }}`:Array.isArray(t)?M(t,n,e,r,i):""}function Se(t,e,n){if(!t)return e;const r=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${r.name}="${r.params?.length>0?`{${r.params?.join(",")}}`:`scope_${n}`}"`}>
|
|
32
32
|
${e}
|
|
@@ -82,7 +82,7 @@ export default defineComponent({
|
|
|
82
82
|
<%= css %>
|
|
83
83
|
<%= style %>
|
|
84
84
|
</style>
|
|
85
|
-
`,Ee=l.template(xe),Ae=l.template(_e);async function Fe(t,e=new Map,n=[],r){const i=new ie(l.cloneDeep(t),n),s=Ce(i,e),o=Ee(s),a=Ae({template:s.template,css:await R(s.css,r),script:await ne(o,r),style:await R(s.style,r)});return await q(a,r).catch(c=>(c.content=a,c))}async function Ne(t){const e=`
|
|
85
|
+
`,Ee=l.template(xe),Ae=l.template(_e);async function Fe(t,e=new Map,n=[],r){const i=new ie(l.cloneDeep(t),n),s=Ce(i,e),o=Ee(s),a=Ae({template:s.template,css:await R(s.css,r),script:await ne(o,r),style:await R(s.style,r)});return await q(a,r).catch(c=>(c.content=a,Promise.reject(c)))}async function Ne(t){const e=`
|
|
86
86
|
<template>
|
|
87
87
|
<div>
|
|
88
88
|
<h3>源码模式页面</h3>
|
package/dist/index.mjs
CHANGED
|
@@ -8,15 +8,15 @@ import * as T from "prettier/plugins/estree";
|
|
|
8
8
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/coder
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.9.0-alpha.
|
|
11
|
+
* @version 0.9.0-alpha.50
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const Bt = "0.9.0-alpha.
|
|
14
|
+
const Bt = "0.9.0-alpha.50";
|
|
15
15
|
/**!
|
|
16
16
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
17
17
|
* @name @vtj/core
|
|
18
18
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
19
|
-
* @version 0.9.0-alpha.
|
|
19
|
+
* @version 0.9.0-alpha.50
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const et = [
|
|
@@ -288,7 +288,7 @@ function pt(e = {}) {
|
|
|
288
288
|
}`;
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
-
function
|
|
291
|
+
function Q(e, t, n = [], s = {}, i) {
|
|
292
292
|
const r = [];
|
|
293
293
|
let o = {}, c = [], a = [];
|
|
294
294
|
return ft(e).forEach((p) => {
|
|
@@ -298,7 +298,7 @@ function D(e, t, n = [], s = {}, i) {
|
|
|
298
298
|
if (O)
|
|
299
299
|
continue;
|
|
300
300
|
const b = mt(m, t, h);
|
|
301
|
-
b && c.push(b),
|
|
301
|
+
b && c.push(b), D(h) && a.push({ id: h.id, name: m });
|
|
302
302
|
const { props: g, events: F, handlers: H } = $t(
|
|
303
303
|
f,
|
|
304
304
|
x,
|
|
@@ -350,9 +350,9 @@ function mt(e, t, n) {
|
|
|
350
350
|
const i = s.parent ? `${s.parent}.${s.alias}` : s.alias;
|
|
351
351
|
return `${e}: ${i}`;
|
|
352
352
|
}
|
|
353
|
-
return
|
|
353
|
+
return D(n) || s ? e : null;
|
|
354
354
|
}
|
|
355
|
-
function
|
|
355
|
+
function D(e) {
|
|
356
356
|
return !!e && typeof e == "object" && e.type === "Schema";
|
|
357
357
|
}
|
|
358
358
|
function z(e) {
|
|
@@ -441,7 +441,7 @@ function bt(e = []) {
|
|
|
441
441
|
};
|
|
442
442
|
}
|
|
443
443
|
function jt(e, t, n, s, i) {
|
|
444
|
-
return typeof e == "string" ? e : _(e) ? `{{ ${l(e, !1, !0, t)} }}` : Array.isArray(e) ?
|
|
444
|
+
return typeof e == "string" ? e : _(e) ? `{{ ${l(e, !1, !0, t)} }}` : Array.isArray(e) ? Q(e, n, t, s, i) : "";
|
|
445
445
|
}
|
|
446
446
|
function St(e, t, n) {
|
|
447
447
|
if (!e) return t;
|
|
@@ -492,7 +492,7 @@ function xt(e = {}) {
|
|
|
492
492
|
}), t;
|
|
493
493
|
}
|
|
494
494
|
function Ot(e, t) {
|
|
495
|
-
const { dsl: n } = e, s = Object.keys(n.computed || {}), i = S(n.lifeCycles, s), r = S(n.computed, s), o = ut(n.watch, s), c = pt(n.dataSources), { methods: a, nodes: u, components: p, importBlocks: v } =
|
|
495
|
+
const { dsl: n } = e, s = Object.keys(n.computed || {}), i = S(n.lifeCycles, s), r = S(n.computed, s), o = ut(n.watch, s), c = pt(n.dataSources), { methods: a, nodes: u, components: p, importBlocks: v } = Q(
|
|
496
496
|
n.nodes || [],
|
|
497
497
|
t,
|
|
498
498
|
s,
|
|
@@ -590,7 +590,7 @@ async function Rt(e, t = /* @__PURE__ */ new Map(), n = [], s) {
|
|
|
590
590
|
script: await nt(o, s),
|
|
591
591
|
style: await R(r.style, s)
|
|
592
592
|
});
|
|
593
|
-
return await U(c, s).catch((a) => (a.content = c, a));
|
|
593
|
+
return await U(c, s).catch((a) => (a.content = c, Promise.reject(a)));
|
|
594
594
|
}
|
|
595
595
|
async function Wt(e) {
|
|
596
596
|
const t = `
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.9.0-alpha.
|
|
4
|
+
"version": "0.9.0-alpha.50",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"prettier": "~3.
|
|
8
|
-
"@vtj/base": "~0.9.0-alpha.
|
|
9
|
-
"@vtj/core": "~0.9.0-alpha.
|
|
7
|
+
"prettier": "~3.4.0",
|
|
8
|
+
"@vtj/base": "~0.9.0-alpha.2",
|
|
9
|
+
"@vtj/core": "~0.9.0-alpha.50"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@vtj/cli": "~0.9.0-alpha.
|
|
12
|
+
"@vtj/cli": "~0.9.0-alpha.3"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
package/types/generator.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ import { BlockSchema, MaterialDescription, Dependencie, PageFile } from '@vtj/co
|
|
|
6
6
|
* 3. Parser 解析 dsl,提取 token
|
|
7
7
|
* 4. Compiled token 注入模板生成代码文件字符串
|
|
8
8
|
*/
|
|
9
|
-
export declare function generator(dsl: BlockSchema, componentMap?: Map<string, MaterialDescription>, dependencies?: Dependencie[], formatterDisabled?: boolean): Promise<
|
|
9
|
+
export declare function generator(dsl: BlockSchema, componentMap?: Map<string, MaterialDescription>, dependencies?: Dependencie[], formatterDisabled?: boolean): Promise<string>;
|
|
10
10
|
export declare function createEmptyPage(file: PageFile): Promise<string>;
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.9.0-alpha.
|
|
5
|
+
* @version 0.9.0-alpha.49
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.9.0-alpha.
|
|
8
|
+
export declare const version = "0.9.0-alpha.49";
|