@vtj/coder 0.8.17 → 0.8.19
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 +24 -24
- package/dist/index.mjs +210 -202
- package/package.json +3 -3
- package/types/utils.d.ts +1 -1
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@vtj/base"),x=require("prettier/standalone"),H=require("prettier/plugins/html"),X=require("prettier/plugins/babel"),Y=require("prettier/plugins/postcss"),Z=require("prettier/plugins/estree");function k(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@vtj/base"),x=require("prettier/standalone"),H=require("prettier/plugins/html"),X=require("prettier/plugins/babel"),Y=require("prettier/plugins/postcss"),Z=require("prettier/plugins/estree");function k(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const K=k(H),J=k(X),T=k(Y),q=k(Z);/**!
|
|
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.8.
|
|
5
|
+
* @version 0.8.19
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const ee="0.8.
|
|
7
|
+
*/const ee="0.8.19";/**!
|
|
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.8.
|
|
11
|
+
* @version 0.8.19
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
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 L(t,e){return e?t:await x.format(t,{parser:"vue",..._,plugins:[K,J,q,T]})}async function ne(t,e){return e?t:await x.format(t,{parser:"babel-ts",..._,plugins:[J,q]})}async function W(t,e){return e?t:x.format(t,{parser:"scss",..._,plugins:[T]})}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 F(t){return t.replace(new RegExp("this.","g"),"")}function I(t){return t.replace(/this\.context\??\./g,"")}function u(t,e=!0,n=!0){
|
|
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 L(t,e){return e?t:await x.format(t,{parser:"vue",..._,plugins:[K,J,q,T]})}async function ne(t,e){return e?t:await x.format(t,{parser:"babel-ts",..._,plugins:[J,q]})}async function W(t,e){return e?t:x.format(t,{parser:"scss",..._,plugins:[T]})}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 F(t){return t.replace(new RegExp("this.","g"),"")}function I(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=b(i,r),n?F(I(i)):I(i)}function b(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}',
|
|
15
15
|
default: ${u(e.default,!0,!1)}
|
|
16
|
-
}`)}function
|
|
16
|
+
}`)}function ce(t=[]){const e=n=>n?`[${l.toArray(n).map(s=>s.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(n=>typeof n=="string"?`${n}: {}`:($(n.default)&&!n.default.value&&(n.default.value="undefined"),`${n.name}: {
|
|
17
17
|
type:${e(n.type)},
|
|
18
18
|
required: ${u(!!n.required,!0,!1)},
|
|
19
19
|
default: ${u(n.default,!0,!1)}
|
|
20
|
-
}`))}function le(t=[]){return t.map(e=>`'${e}'`)}function
|
|
21
|
-
deep: ${
|
|
22
|
-
immediate:${
|
|
23
|
-
handler${U(
|
|
24
|
-
}`);return{computed:
|
|
20
|
+
}`))}function le(t=[]){return t.map(e=>`'${e}'`)}function w(t={},e=[]){return Object.entries(t).map(([n,r])=>{let i=U(u(r,!1,!1));return i=b(i,e),i.startsWith("async")?`async ${n}${i.replace(/^async/,"")}`:`${n}${i}`})}function ue(t=[],e=[]){const n=t.reduce((s,o)=>(o.id&&A(o.source)&&(s[`watcher_${o.id}`]=o.source),s),{}),r=w(n,e),i=t.map(s=>`watcher_${s.id}: {
|
|
21
|
+
deep: ${s.deep},
|
|
22
|
+
immediate:${s.immediate},
|
|
23
|
+
handler${U(s.handler.value)}
|
|
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
|
-
}`})}function M(t,e,n=[],
|
|
27
|
-
`),Object.assign(o,
|
|
28
|
-
`+
|
|
29
|
-
`),i?.id);
|
|
30
|
-
return (${
|
|
31
|
-
}`}:
|
|
26
|
+
}`})}function M(t,e,n=[],r={},i){const s=[];let o={},a=[],c=[];return fe(t).forEach(f=>{const j=[];for(const p of f.children){let{id:O,name:h,invisible:C,from:d}=p;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:N,handlers:G}=$e(p,O,p.props,p.events,r,n),B=be(p.directives,n).join(" "),y=p.children?ve(p.children,n,e,r,p):"";Object.assign(o,G);let S="";typeof y=="string"?S=y:(S=(y?.nodes||[]).join(`
|
|
27
|
+
`),Object.assign(o,y?.methods||{}),a=a.concat(y?.components||[]),c=c.concat(y?.importBlocks||[]));const R=Q(d)||z(d)?"component":h;j.push(h==="img"?`<${h} ${B} ${g} ${N} />`:`<${R} ${B} ${g} ${N}>${S?`
|
|
28
|
+
`+S.trim():""}</${R}>`)}const P=Se(f.slot,j.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 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:b(e.value,n)})}"`:typeof e=="string"?`${t}="${e}"`:$(e)?`:${t}="${u({...e,value:b(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){const i=V(e.modifiers,!0);return r&&r.length>0?`@${t}${i.join("")}="(...args:any[]) => ${n}"`:`@${t}${i.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 m=c.handler.value.startsWith("this."),f=m?F(c.handler.value):`${l.camelCase(a)}_${t}${s}`;return m||(r[f]=i.length?{type:"JSFunction",value:`{
|
|
30
|
+
return (${c.handler.value}).apply(this, args);
|
|
31
|
+
}`}:c.handler),ye(a,c,f,i)}),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}=je(t);if(r&&n.push(`v-if="${u(r.value,!0,!0,e)}"`),i&&n.push(`v-show="${u(i.value,!0,!0,e)}"`),s.forEach(a=>{const c=V(a.modifiers,!0),m=a.arg?E(a.arg)?`:[${u(a.arg,!0,!0,e)}]`:`:${a.arg}`:"";n.push(`v-model${m}${c}="${u(a.value,!0,!0,e)}"`)}),o){const{item:a,index:c}={item:"item",index:"index",...o.iterator};n.push(`v-for="(${a}, ${c}) in ${u(o.value,!0,!0,e)}"`)}return n}function je(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 ve(t,e,n,r,i){if(typeof t=="string")return t;if(E(t)){let s=u(t,!1);return s=b(s,e),s=F(s),`{{ ${s} }}`}return 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}
|
|
33
|
-
</template>`}function we(t,e=[],n=[],
|
|
33
|
+
</template>`}function we(t,e=[],n=[],r={}){const i={vue:["defineComponent","reactive"]};for(const s of e){const o=t.get(s.split(":")[0]);o&&o.package&&(i[o.package]??(i[o.package]=[])).push(o.parent||(o.alias||"").split(".")[0]||o.name)}for(const[s,o]of Object.entries(r))(i[s]??(i[s]=[])).push(...Array.from(o));return Object.entries(i).filter(([s,o])=>!!o.length).map(([s,o])=>`import { ${l.dedupArray(o).join(",")}} from '${s}';`).concat(n)}function ke(t={}){const e=[];for(const[n,r]of Object.entries(t))e.push(`
|
|
34
34
|
${n} {
|
|
35
|
-
${
|
|
35
|
+
${se(r)}
|
|
36
36
|
}
|
|
37
37
|
`);return e.join(`
|
|
38
|
-
`)}function Pe(t={}){const e=[];return Object.entries(t).forEach(([n,
|
|
39
|
-
`),components:f.join(","),returns:t.members.join(","),template:
|
|
40
|
-
`),css:n.css||"",style:ke(t.style),urlSchemas:
|
|
41
|
-
`),blockPlugins:
|
|
38
|
+
`)}function Pe(t={}){const e=[];return Object.entries(t).forEach(([n,r])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${r.url}');`)}),e}function Oe(t={}){const e=[];return Object.entries(t).forEach(([n,r])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(r)});`)}),e}function Ce(t,e){const{dsl:n}=t,r=Object.keys(n.computed||{}),i=w(n.lifeCycles,r),s=w(n.computed,r),o=ue(n.watch,r),a=pe(n.dataSources),{methods:c,nodes:m,components:f,importBlocks:j}=M(n.nodes||[],e,r,t.context),P=[...s,...o.computed],p=w({...c,...n.methods||{}},r),O=j.map(g=>`import ${g.name} from './${g.id}.vue';`),h=we(e,f,O,t.imports),C=Object.keys({...t.urlSchemas,...t.blockPlugins}),d=Pe(t.urlSchemas),v=Oe(t.blockPlugins);return{id:n.id,version:n.__VERSION__,name:n.name,state:oe(n.state).join(","),inject:ae(n.inject).join(","),props:ce(n.props).join(","),emits:le(n.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:P.join(","),methods:[...a,...p].join(","),imports:h.join(`
|
|
39
|
+
`),components:f.join(","),returns:t.members.join(","),template:m.join(`
|
|
40
|
+
`),css:n.css||"",style:ke(t.style),urlSchemas:d.join(`
|
|
41
|
+
`),blockPlugins:v.join(`
|
|
42
42
|
`),asyncComponents:C.join(",")}}const xe=`
|
|
43
43
|
<%= imports %>
|
|
44
44
|
import { useProvider } from '@vtj/renderer';
|
|
@@ -79,7 +79,7 @@ export default defineComponent({
|
|
|
79
79
|
<%= css %>
|
|
80
80
|
<%= style %>
|
|
81
81
|
</style>
|
|
82
|
-
`,Ee=l.template(xe),Ae=l.template(_e);async function Fe(t,e=new Map,n=[],
|
|
82
|
+
`,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 W(s.css,r),script:await ne(o,r),style:await W(s.style,r)});return await L(a,r).catch(c=>(c.content=a,c))}async function Ne(t){const e=`
|
|
83
83
|
<template>
|
|
84
84
|
<div>
|
|
85
85
|
<h3>源码模式页面</h3>
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mitt as X, dedupArray as
|
|
1
|
+
import { mitt as X, dedupArray as k, toArray as Y, camelCase as y, isPlainObject as Z, template as J, cloneDeep as K } from "@vtj/base";
|
|
2
2
|
import { format as C } from "prettier/standalone";
|
|
3
3
|
import * as tt from "prettier/plugins/html";
|
|
4
4
|
import * as L from "prettier/plugins/babel";
|
|
@@ -8,15 +8,15 @@ import * as U 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.8.
|
|
11
|
+
* @version 0.8.19
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const Bt = "0.8.
|
|
14
|
+
const Bt = "0.8.19";
|
|
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.8.
|
|
19
|
+
* @version 0.8.19
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const et = [
|
|
@@ -60,7 +60,7 @@ async function V(e, t) {
|
|
|
60
60
|
plugins: [tt, L, U, T]
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
async function
|
|
63
|
+
async function nt(e, t) {
|
|
64
64
|
return t ? e : await C(e, {
|
|
65
65
|
parser: "babel-ts",
|
|
66
66
|
...E,
|
|
@@ -89,18 +89,18 @@ function F(e) {
|
|
|
89
89
|
function I(e) {
|
|
90
90
|
return e.replace(/this\.context\??\./g, "");
|
|
91
91
|
}
|
|
92
|
-
function l(e, t = !0,
|
|
93
|
-
|
|
94
|
-
return s ? F(I(
|
|
92
|
+
function l(e, t = !0, n = !0, s = []) {
|
|
93
|
+
let i = $(e) ? e.value : t ? JSON.stringify(e) : e;
|
|
94
|
+
return i = b(i, s), n ? F(I(i)) : I(i);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
let
|
|
98
|
-
for (const
|
|
99
|
-
|
|
100
|
-
new RegExp(`this.${
|
|
101
|
-
`this.${
|
|
96
|
+
function b(e, t = []) {
|
|
97
|
+
let n = e;
|
|
98
|
+
for (const s of t)
|
|
99
|
+
n = n.replace(
|
|
100
|
+
new RegExp(`this.${s}.value`, "g"),
|
|
101
|
+
`this.${s}`
|
|
102
102
|
);
|
|
103
|
-
return
|
|
103
|
+
return n;
|
|
104
104
|
}
|
|
105
105
|
function q(e) {
|
|
106
106
|
let t = e.trim();
|
|
@@ -111,30 +111,30 @@ function q(e) {
|
|
|
111
111
|
else if (t.startsWith("function"))
|
|
112
112
|
t = t.replace(/^function/, "");
|
|
113
113
|
else {
|
|
114
|
-
const
|
|
114
|
+
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/, r = t.match(i);
|
|
115
115
|
r && r[2] && (r[2].startsWith("{") || (t = t.replace(r[2], `{ return ${r[2]} }`))), t = t.replace("=>", "");
|
|
116
116
|
}
|
|
117
117
|
return t;
|
|
118
118
|
}
|
|
119
|
-
function
|
|
120
|
-
return Object.entries(e).map(([t,
|
|
119
|
+
function st(e = {}) {
|
|
120
|
+
return Object.entries(e).map(([t, n]) => `"${t}": ${l(n)}`);
|
|
121
121
|
}
|
|
122
122
|
function M(e = {}, t = !1) {
|
|
123
|
-
const
|
|
124
|
-
return t ?
|
|
123
|
+
const n = Object.keys(e);
|
|
124
|
+
return t ? n.map((s) => "." + s) : n;
|
|
125
125
|
}
|
|
126
126
|
function rt(e) {
|
|
127
127
|
let t = "";
|
|
128
|
-
for (var
|
|
129
|
-
if (e.hasOwnProperty(
|
|
130
|
-
var
|
|
131
|
-
t +=
|
|
128
|
+
for (var n in e)
|
|
129
|
+
if (e.hasOwnProperty(n)) {
|
|
130
|
+
var s = e[n];
|
|
131
|
+
t += n + ": " + s + ";";
|
|
132
132
|
}
|
|
133
133
|
return t;
|
|
134
134
|
}
|
|
135
135
|
class it {
|
|
136
|
-
constructor(t,
|
|
137
|
-
this.dsl = t, this.dependencies =
|
|
136
|
+
constructor(t, n) {
|
|
137
|
+
this.dsl = t, this.dependencies = n, this.libraryRegex = this.collectLibrary(), this.walk(t), this.walkNodes(t), this.members = this.getLibraryMember();
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* { 'element-plus': ['ElButton', 'ElInput' ...] }
|
|
@@ -155,18 +155,18 @@ class it {
|
|
|
155
155
|
* @returns ex: { name: 'ElButton', path: 'this.$libs.ElementPlus.', library: 'ElementPlus' }
|
|
156
156
|
*/
|
|
157
157
|
collectImport(t) {
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
-
const
|
|
161
|
-
if (
|
|
162
|
-
const
|
|
158
|
+
const n = t.split(".");
|
|
159
|
+
if (n.length === 4) {
|
|
160
|
+
const s = n.pop(), i = n.join(".") + ".", r = n.pop();
|
|
161
|
+
if (s && r) {
|
|
162
|
+
const o = this.dependencies.find(
|
|
163
163
|
(c) => c.library === r
|
|
164
164
|
)?.package;
|
|
165
|
-
|
|
165
|
+
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(s);
|
|
166
166
|
}
|
|
167
167
|
return {
|
|
168
|
-
name:
|
|
169
|
-
path:
|
|
168
|
+
name: s,
|
|
169
|
+
path: i,
|
|
170
170
|
library: r
|
|
171
171
|
};
|
|
172
172
|
}
|
|
@@ -174,51 +174,51 @@ class it {
|
|
|
174
174
|
}
|
|
175
175
|
// 代码中包含依赖库的引用,需要从代码中移除
|
|
176
176
|
replaceLibraryPath(t) {
|
|
177
|
-
const { libraryRegex:
|
|
178
|
-
let
|
|
179
|
-
for (const
|
|
180
|
-
const r = t.value.match(
|
|
181
|
-
for (const
|
|
182
|
-
const c = this.collectImport(
|
|
177
|
+
const { libraryRegex: n } = this;
|
|
178
|
+
let s = t.value;
|
|
179
|
+
for (const i of n) {
|
|
180
|
+
const r = t.value.match(i) || [];
|
|
181
|
+
for (const o of r) {
|
|
182
|
+
const c = this.collectImport(o);
|
|
183
183
|
if (c) {
|
|
184
184
|
const a = c.path.replace(/\$/g, "\\$");
|
|
185
|
-
|
|
185
|
+
s = s.replace(new RegExp(a, "g"), "");
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
return
|
|
189
|
+
return s;
|
|
190
190
|
}
|
|
191
191
|
walk(t) {
|
|
192
|
-
const
|
|
193
|
-
if (!
|
|
192
|
+
const n = (s) => {
|
|
193
|
+
if (!s || typeof s != "object")
|
|
194
194
|
return;
|
|
195
|
-
if (Array.isArray(
|
|
196
|
-
for (let r of
|
|
197
|
-
|
|
195
|
+
if (Array.isArray(s)) {
|
|
196
|
+
for (let r of s)
|
|
197
|
+
n(r);
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
|
-
const
|
|
201
|
-
for (const r of
|
|
202
|
-
$(r) ? r.value = this.replaceLibraryPath(r) :
|
|
200
|
+
const i = Object.values(s);
|
|
201
|
+
for (const r of i)
|
|
202
|
+
$(r) ? r.value = this.replaceLibraryPath(r) : n(r);
|
|
203
203
|
};
|
|
204
|
-
|
|
204
|
+
n(t);
|
|
205
205
|
}
|
|
206
206
|
getLibraryMember(t = []) {
|
|
207
|
-
let
|
|
208
|
-
for (const
|
|
209
|
-
|
|
210
|
-
return
|
|
207
|
+
let n = [...t];
|
|
208
|
+
for (const s of Object.values(this.imports))
|
|
209
|
+
n = n.concat(Array.from(s));
|
|
210
|
+
return k(n);
|
|
211
211
|
}
|
|
212
|
-
collectContext(t,
|
|
213
|
-
const
|
|
214
|
-
let r = new Set(Array.from(
|
|
215
|
-
if (
|
|
216
|
-
const { item: c = "item", index: a = "index" } =
|
|
212
|
+
collectContext(t, n) {
|
|
213
|
+
const s = new Set(n?.id ? this.context[n.id] : []), i = (t.directives || []).find((c) => c.name === "vFor");
|
|
214
|
+
let r = new Set(Array.from(s));
|
|
215
|
+
if (i) {
|
|
216
|
+
const { item: c = "item", index: a = "index" } = i.iterator || {};
|
|
217
217
|
r = /* @__PURE__ */ new Set([c, a, ...Array.from(r)]);
|
|
218
218
|
}
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
221
|
-
const c = typeof
|
|
219
|
+
const o = t.slot;
|
|
220
|
+
if (o) {
|
|
221
|
+
const c = typeof o == "string" ? [] : o.params || [], a = c.length ? c : [`scope_${n?.id}`];
|
|
222
222
|
r = /* @__PURE__ */ new Set([...a, ...Array.from(r)]);
|
|
223
223
|
}
|
|
224
224
|
this.context[t.id] = r;
|
|
@@ -233,16 +233,16 @@ class it {
|
|
|
233
233
|
typeof t.from == "object" && t.from.type === "Plugin" && (this.blockPlugins[t.name] = t.from);
|
|
234
234
|
}
|
|
235
235
|
walkNodes(t) {
|
|
236
|
-
const
|
|
237
|
-
this.collectContext(
|
|
236
|
+
const n = (s, i) => {
|
|
237
|
+
this.collectContext(s, i), this.collectStyle(s), this.collectUrlSchema(s), this.collectBlockPlugin(s), Array.isArray(s.children) && s.children.forEach((r) => n(r, s));
|
|
238
238
|
};
|
|
239
|
-
Array.isArray(t.nodes) && t.nodes.forEach((
|
|
239
|
+
Array.isArray(t.nodes) && t.nodes.forEach((s) => n(s));
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
function ot(e = {}) {
|
|
243
|
-
return Object.entries(e).map(([t,
|
|
244
|
-
const
|
|
245
|
-
return `${t}:${
|
|
243
|
+
return Object.entries(e).map(([t, n]) => {
|
|
244
|
+
const s = l(n, !1);
|
|
245
|
+
return `${t}:${s}`;
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
248
|
function ct(e = []) {
|
|
@@ -252,106 +252,108 @@ function ct(e = []) {
|
|
|
252
252
|
}`);
|
|
253
253
|
}
|
|
254
254
|
function at(e = []) {
|
|
255
|
-
const t = (
|
|
256
|
-
return e.map((
|
|
257
|
-
type:${t(
|
|
258
|
-
required: ${l(!!
|
|
259
|
-
default: ${l(
|
|
255
|
+
const t = (n) => n ? `[${Y(n).map((r) => r.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
256
|
+
return e.map((n) => typeof n == "string" ? `${n}: {}` : ($(n.default) && !n.default.value && (n.default.value = "undefined"), `${n.name}: {
|
|
257
|
+
type:${t(n.type)},
|
|
258
|
+
required: ${l(!!n.required, !0, !1)},
|
|
259
|
+
default: ${l(n.default, !0, !1)}
|
|
260
260
|
}`));
|
|
261
261
|
}
|
|
262
262
|
function lt(e = []) {
|
|
263
263
|
return e.map((t) => `'${t}'`);
|
|
264
264
|
}
|
|
265
|
-
function
|
|
266
|
-
return Object.entries(e).map(([
|
|
267
|
-
let
|
|
268
|
-
return
|
|
265
|
+
function w(e = {}, t = []) {
|
|
266
|
+
return Object.entries(e).map(([n, s]) => {
|
|
267
|
+
let i = q(l(s, !1, !1));
|
|
268
|
+
return i = b(i, t), i.startsWith("async") ? `async ${n}${i.replace(/^async/, "")}` : `${n}${i}`;
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
function ut(e = [], t = []) {
|
|
272
|
-
const
|
|
273
|
-
(r,
|
|
272
|
+
const n = e.reduce(
|
|
273
|
+
(r, o) => (o.id && A(o.source) && (r[`watcher_${o.id}`] = o.source), r),
|
|
274
274
|
{}
|
|
275
|
-
),
|
|
275
|
+
), s = w(n, t), i = e.map((r) => `watcher_${r.id}: {
|
|
276
276
|
deep: ${r.deep},
|
|
277
277
|
immediate:${r.immediate},
|
|
278
278
|
handler${q(r.handler.value)}
|
|
279
279
|
}`);
|
|
280
280
|
return {
|
|
281
|
-
computed:
|
|
282
|
-
watches:
|
|
281
|
+
computed: s,
|
|
282
|
+
watches: i
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
285
|
function pt(e = {}) {
|
|
286
286
|
return Object.values(e).map((t) => {
|
|
287
|
-
const
|
|
287
|
+
const n = A(t.transform) && t.transform.value || "(res) => res";
|
|
288
288
|
return `async ${t.name}(...args:any[]) {
|
|
289
|
-
return await this.provider.apis['${t.ref}'].apply(this, args).then(${
|
|
289
|
+
return await this.provider.apis['${t.ref}'].apply(this, args).then(${n});
|
|
290
290
|
}`;
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
|
-
function D(e, t,
|
|
293
|
+
function D(e, t, n = [], s = {}, i) {
|
|
294
294
|
const r = [];
|
|
295
|
-
let
|
|
295
|
+
let o = {}, c = [], a = [];
|
|
296
296
|
return ft(e).forEach((p) => {
|
|
297
|
-
const
|
|
297
|
+
const v = [];
|
|
298
298
|
for (const u of p.children) {
|
|
299
|
-
let { id: x, name:
|
|
299
|
+
let { id: x, name: m, invisible: O, from: h } = u;
|
|
300
300
|
if (O)
|
|
301
301
|
continue;
|
|
302
|
-
const
|
|
303
|
-
|
|
302
|
+
const j = mt(m, t, h);
|
|
303
|
+
j && c.push(j), Q(h) && a.push({ id: h.id, name: m });
|
|
304
304
|
const { props: g, events: N, handlers: H } = $t(
|
|
305
305
|
u,
|
|
306
306
|
x,
|
|
307
307
|
u.props,
|
|
308
308
|
u.events,
|
|
309
|
-
n,
|
|
310
|
-
s
|
|
311
|
-
), B = bt(u.directives).join(" "), h = u.children ? jt(
|
|
312
|
-
u.children,
|
|
313
309
|
s,
|
|
314
|
-
|
|
310
|
+
n
|
|
311
|
+
), B = bt(u.directives, n).join(
|
|
312
|
+
" "
|
|
313
|
+
), d = u.children ? jt(
|
|
314
|
+
u.children,
|
|
315
315
|
n,
|
|
316
|
+
t,
|
|
317
|
+
s,
|
|
316
318
|
u
|
|
317
319
|
) : "";
|
|
318
|
-
Object.assign(
|
|
319
|
-
let
|
|
320
|
-
typeof
|
|
321
|
-
`), Object.assign(
|
|
322
|
-
const R = z(
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
` +
|
|
320
|
+
Object.assign(o, H);
|
|
321
|
+
let S = "";
|
|
322
|
+
typeof d == "string" ? S = d : (S = (d?.nodes || []).join(`
|
|
323
|
+
`), Object.assign(o, d?.methods || {}), c = c.concat(d?.components || []), a = a.concat(d?.importBlocks || []));
|
|
324
|
+
const R = z(h) || G(h) ? "component" : m;
|
|
325
|
+
v.push(
|
|
326
|
+
m === "img" ? `<${m} ${B} ${g} ${N} />` : `<${R} ${B} ${g} ${N}>${S ? `
|
|
327
|
+
` + S.trim() : ""}</${R}>`
|
|
326
328
|
);
|
|
327
329
|
}
|
|
328
|
-
const P = St(p.slot,
|
|
329
|
-
`),
|
|
330
|
+
const P = St(p.slot, v.join(`
|
|
331
|
+
`), i?.id);
|
|
330
332
|
r.push(P);
|
|
331
333
|
}), {
|
|
332
334
|
nodes: r,
|
|
333
|
-
methods:
|
|
334
|
-
components:
|
|
335
|
-
importBlocks:
|
|
335
|
+
methods: o,
|
|
336
|
+
components: k(c),
|
|
337
|
+
importBlocks: k(a, "id")
|
|
336
338
|
};
|
|
337
339
|
}
|
|
338
340
|
function ft(e = []) {
|
|
339
341
|
const t = /* @__PURE__ */ new Map();
|
|
340
|
-
for (const
|
|
341
|
-
const
|
|
342
|
-
|
|
342
|
+
for (const n of e) {
|
|
343
|
+
const s = typeof n.slot == "string" ? n.slot : n.slot?.name, i = t.get(s);
|
|
344
|
+
i ? i.children.push(n) : t.set(s, { slot: n.slot, children: [n] });
|
|
343
345
|
}
|
|
344
346
|
return t;
|
|
345
347
|
}
|
|
346
|
-
function mt(e, t,
|
|
348
|
+
function mt(e, t, n) {
|
|
347
349
|
if (et.includes(e))
|
|
348
350
|
return null;
|
|
349
|
-
const
|
|
350
|
-
if (
|
|
351
|
-
const
|
|
352
|
-
return `${e}: ${
|
|
351
|
+
const s = t.get(e);
|
|
352
|
+
if (s && s.alias) {
|
|
353
|
+
const i = s.parent ? `${s.parent}.${s.alias}` : s.alias;
|
|
354
|
+
return `${e}: ${i}`;
|
|
353
355
|
}
|
|
354
|
-
return Q(
|
|
356
|
+
return Q(n) || s ? e : null;
|
|
355
357
|
}
|
|
356
358
|
function Q(e) {
|
|
357
359
|
return !!e && typeof e == "object" && e.type === "Schema";
|
|
@@ -362,114 +364,120 @@ function z(e) {
|
|
|
362
364
|
function G(e) {
|
|
363
365
|
return typeof e == "object" && e.type === "Plugin";
|
|
364
366
|
}
|
|
365
|
-
function ht(e, t,
|
|
367
|
+
function ht(e, t, n = []) {
|
|
366
368
|
return e === "style" ? "" : e === "__class" && $(t) ? `:class="${l({
|
|
367
369
|
...t,
|
|
368
|
-
value:
|
|
370
|
+
value: b(t.value, n)
|
|
369
371
|
})}"` : typeof t == "string" ? `${e}="${t}"` : $(t) ? `:${e}="${l({
|
|
370
372
|
...t,
|
|
371
|
-
value:
|
|
372
|
-
})}"` : Z(t) ? `:${e}='{${
|
|
373
|
+
value: b(t.value, n)
|
|
374
|
+
})}"` : Z(t) ? `:${e}='{${st(
|
|
373
375
|
t
|
|
374
376
|
).join(", ")}}'` : `:${e}='${JSON.stringify(t)}'`;
|
|
375
377
|
}
|
|
376
|
-
function dt(e, t = {},
|
|
378
|
+
function dt(e, t = {}, n = []) {
|
|
377
379
|
if (!!Object.keys(t.style || {}).length) {
|
|
378
380
|
const r = `${e.name}_${e.id}`;
|
|
379
381
|
t.class ? typeof t.class == "string" ? t.class = [t.class, r].join(" ") : (t.__class = t.class, t.class = r) : (t.class = r, delete t.style);
|
|
380
382
|
}
|
|
381
|
-
const
|
|
382
|
-
return (z(
|
|
383
|
+
const i = e.from;
|
|
384
|
+
return (z(i) || G(i)) && (t.is = {
|
|
383
385
|
type: "JSExpression",
|
|
384
386
|
value: e.name
|
|
385
|
-
}), Object.entries(t).map(([r,
|
|
387
|
+
}), Object.entries(t).map(([r, o]) => ht(r, o, n));
|
|
386
388
|
}
|
|
387
|
-
function yt(e, t,
|
|
388
|
-
const
|
|
389
|
-
return
|
|
389
|
+
function yt(e, t, n, s) {
|
|
390
|
+
const i = M(t.modifiers, !0);
|
|
391
|
+
return s && s.length > 0 ? `@${e}${i.join("")}="(...args:any[]) => ${n}"` : `@${e}${i.join("")}="${n}"`;
|
|
390
392
|
}
|
|
391
|
-
function gt(e, t = {},
|
|
392
|
-
const
|
|
393
|
+
function gt(e, t = {}, n = {}) {
|
|
394
|
+
const s = {}, i = Array.from(n[e] || /* @__PURE__ */ new Set([])), r = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
393
395
|
return {
|
|
394
396
|
binders: Object.entries(t).map(([c, a]) => {
|
|
395
|
-
const
|
|
396
|
-
return
|
|
397
|
+
const f = a.handler.value.startsWith("this."), p = f ? F(a.handler.value) : `${y(c)}_${e}${r}`;
|
|
398
|
+
return f || (s[p] = i.length ? {
|
|
397
399
|
type: "JSFunction",
|
|
398
400
|
value: `{
|
|
399
401
|
return (${a.handler.value}).apply(this, args);
|
|
400
402
|
}`
|
|
401
|
-
} : a.handler), yt(c, a, p,
|
|
403
|
+
} : a.handler), yt(c, a, p, i);
|
|
402
404
|
}),
|
|
403
|
-
handlers:
|
|
405
|
+
handlers: s
|
|
404
406
|
};
|
|
405
407
|
}
|
|
406
|
-
function $t(e, t,
|
|
407
|
-
const { binders:
|
|
408
|
+
function $t(e, t, n = {}, s = {}, i = {}, r) {
|
|
409
|
+
const { binders: o, handlers: c } = gt(t, s, i);
|
|
408
410
|
return {
|
|
409
|
-
props: dt(e,
|
|
411
|
+
props: dt(e, n, r).join(" "),
|
|
410
412
|
handlers: c,
|
|
411
|
-
binders:
|
|
412
|
-
events:
|
|
413
|
+
binders: o,
|
|
414
|
+
events: o.join(" ")
|
|
413
415
|
};
|
|
414
416
|
}
|
|
415
|
-
function bt(e = []) {
|
|
416
|
-
const
|
|
417
|
-
if (s &&
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
417
|
+
function bt(e = [], t = []) {
|
|
418
|
+
const n = [], { vIf: s, vShow: i, vModels: r, vFor: o } = vt(e);
|
|
419
|
+
if (s && n.push(`v-if="${l(s.value, !0, !0, t)}"`), i && n.push(
|
|
420
|
+
`v-show="${l(i.value, !0, !0, t)}"`
|
|
421
|
+
), r.forEach((c) => {
|
|
422
|
+
const a = M(c.modifiers, !0), f = c.arg ? _(c.arg) ? `:[${l(c.arg, !0, !0, t)}]` : `:${c.arg}` : "";
|
|
423
|
+
n.push(
|
|
424
|
+
`v-model${f}${a}="${l(c.value, !0, !0, t)}"`
|
|
425
|
+
);
|
|
426
|
+
}), o) {
|
|
427
|
+
const { item: c, index: a } = { item: "item", index: "index", ...o.iterator };
|
|
428
|
+
n.push(
|
|
429
|
+
`v-for="(${c}, ${a}) in ${l(o.value, !0, !0, t)}"`
|
|
430
|
+
);
|
|
423
431
|
}
|
|
424
|
-
return
|
|
432
|
+
return n;
|
|
425
433
|
}
|
|
426
434
|
function vt(e = []) {
|
|
427
|
-
const t = e.find((
|
|
435
|
+
const t = e.find((o) => y(o.name) === "vIf"), n = e.find((o) => y(o.name) === "vFor"), s = e.find((o) => y(o.name) === "vShow"), i = e.find((o) => y(o.name) === "vBind"), r = e.filter((o) => y(o.name) === "vModel");
|
|
428
436
|
return {
|
|
429
437
|
vIf: t,
|
|
430
|
-
vFor:
|
|
431
|
-
vShow:
|
|
438
|
+
vFor: n,
|
|
439
|
+
vShow: s,
|
|
432
440
|
vModels: r,
|
|
433
|
-
vBind:
|
|
441
|
+
vBind: i
|
|
434
442
|
};
|
|
435
443
|
}
|
|
436
|
-
function jt(e, t,
|
|
444
|
+
function jt(e, t, n, s, i) {
|
|
437
445
|
if (typeof e == "string")
|
|
438
446
|
return e;
|
|
439
447
|
if (_(e)) {
|
|
440
448
|
let r = l(e, !1);
|
|
441
|
-
return r =
|
|
449
|
+
return r = b(r, t), r = F(r), `{{ ${r} }}`;
|
|
442
450
|
}
|
|
443
|
-
return Array.isArray(e) ? D(e,
|
|
451
|
+
return Array.isArray(e) ? D(e, n, t, s, i) : "";
|
|
444
452
|
}
|
|
445
|
-
function St(e, t,
|
|
453
|
+
function St(e, t, n) {
|
|
446
454
|
if (!e)
|
|
447
455
|
return t;
|
|
448
|
-
const
|
|
449
|
-
return `<template ${`#${
|
|
456
|
+
const s = typeof e == "string" ? { name: e, params: [] } : { params: [], ...e };
|
|
457
|
+
return `<template ${`#${s.name}="${s.params?.length > 0 ? `{${s.params?.join(",")}}` : `scope_${n}`}"`}>
|
|
450
458
|
${t}
|
|
451
459
|
</template>`;
|
|
452
460
|
}
|
|
453
|
-
function wt(e, t = [],
|
|
454
|
-
const
|
|
461
|
+
function wt(e, t = [], n = [], s = {}) {
|
|
462
|
+
const i = {
|
|
455
463
|
vue: ["defineComponent", "reactive"]
|
|
456
464
|
};
|
|
457
465
|
for (const r of t) {
|
|
458
|
-
const
|
|
459
|
-
|
|
466
|
+
const o = e.get(r.split(":")[0]);
|
|
467
|
+
o && o.package && (i[o.package] ?? (i[o.package] = [])).push(o.parent || (o.alias || "").split(".")[0] || o.name);
|
|
460
468
|
}
|
|
461
|
-
for (const [r,
|
|
462
|
-
(
|
|
463
|
-
return Object.entries(
|
|
469
|
+
for (const [r, o] of Object.entries(s))
|
|
470
|
+
(i[r] ?? (i[r] = [])).push(...Array.from(o));
|
|
471
|
+
return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${k(o).join(
|
|
464
472
|
","
|
|
465
|
-
)}} from '${r}';`).concat(
|
|
473
|
+
)}} from '${r}';`).concat(n);
|
|
466
474
|
}
|
|
467
475
|
function kt(e = {}) {
|
|
468
476
|
const t = [];
|
|
469
|
-
for (const [
|
|
477
|
+
for (const [n, s] of Object.entries(e))
|
|
470
478
|
t.push(`
|
|
471
|
-
${
|
|
472
|
-
${rt(
|
|
479
|
+
${n} {
|
|
480
|
+
${rt(s)}
|
|
473
481
|
}
|
|
474
482
|
`);
|
|
475
483
|
return t.join(`
|
|
@@ -477,33 +485,33 @@ function kt(e = {}) {
|
|
|
477
485
|
}
|
|
478
486
|
function Pt(e = {}) {
|
|
479
487
|
const t = [];
|
|
480
|
-
return Object.entries(e).forEach(([
|
|
488
|
+
return Object.entries(e).forEach(([n, s]) => {
|
|
481
489
|
t.push(
|
|
482
|
-
`const ${
|
|
490
|
+
`const ${n} = provider.defineUrlSchemaComponent('${s.url}');`
|
|
483
491
|
);
|
|
484
492
|
}), t;
|
|
485
493
|
}
|
|
486
494
|
function xt(e = {}) {
|
|
487
495
|
const t = [];
|
|
488
|
-
return Object.entries(e).forEach(([
|
|
496
|
+
return Object.entries(e).forEach(([n, s]) => {
|
|
489
497
|
t.push(
|
|
490
|
-
`const ${
|
|
498
|
+
`const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`
|
|
491
499
|
);
|
|
492
500
|
}), t;
|
|
493
501
|
}
|
|
494
502
|
function Ot(e, t) {
|
|
495
|
-
const { dsl:
|
|
496
|
-
|
|
503
|
+
const { dsl: n } = e, s = Object.keys(n.computed || {}), i = w(n.lifeCycles, s), r = w(n.computed, s), o = ut(n.watch, s), c = pt(n.dataSources), { methods: a, nodes: f, components: p, importBlocks: v } = D(
|
|
504
|
+
n.nodes || [],
|
|
497
505
|
t,
|
|
498
|
-
|
|
506
|
+
s,
|
|
499
507
|
e.context
|
|
500
|
-
), P = [...r, ...
|
|
508
|
+
), P = [...r, ...o.computed], u = w(
|
|
501
509
|
{
|
|
502
510
|
...a,
|
|
503
|
-
...
|
|
511
|
+
...n.methods || {}
|
|
504
512
|
},
|
|
505
|
-
|
|
506
|
-
), x =
|
|
513
|
+
s
|
|
514
|
+
), x = v.map((g) => `import ${g.name} from './${g.id}.vue';`), m = wt(
|
|
507
515
|
t,
|
|
508
516
|
p,
|
|
509
517
|
x,
|
|
@@ -511,30 +519,30 @@ function Ot(e, t) {
|
|
|
511
519
|
), O = Object.keys({
|
|
512
520
|
...e.urlSchemas,
|
|
513
521
|
...e.blockPlugins
|
|
514
|
-
}),
|
|
522
|
+
}), h = Pt(e.urlSchemas), j = xt(e.blockPlugins);
|
|
515
523
|
return {
|
|
516
|
-
id:
|
|
517
|
-
version:
|
|
518
|
-
name:
|
|
519
|
-
state: ot(
|
|
520
|
-
inject: ct(
|
|
521
|
-
props: at(
|
|
522
|
-
emits: lt(
|
|
523
|
-
watch:
|
|
524
|
-
lifeCycles:
|
|
524
|
+
id: n.id,
|
|
525
|
+
version: n.__VERSION__,
|
|
526
|
+
name: n.name,
|
|
527
|
+
state: ot(n.state).join(","),
|
|
528
|
+
inject: ct(n.inject).join(","),
|
|
529
|
+
props: at(n.props).join(","),
|
|
530
|
+
emits: lt(n.emits).join(","),
|
|
531
|
+
watch: o.watches.join(","),
|
|
532
|
+
lifeCycles: i.join(","),
|
|
525
533
|
computed: P.join(","),
|
|
526
534
|
methods: [...c, ...u].join(","),
|
|
527
|
-
imports:
|
|
535
|
+
imports: m.join(`
|
|
528
536
|
`),
|
|
529
537
|
components: p.join(","),
|
|
530
538
|
returns: e.members.join(","),
|
|
531
|
-
template:
|
|
539
|
+
template: f.join(`
|
|
532
540
|
`),
|
|
533
|
-
css:
|
|
541
|
+
css: n.css || "",
|
|
534
542
|
style: kt(e.style),
|
|
535
|
-
urlSchemas:
|
|
543
|
+
urlSchemas: h.join(`
|
|
536
544
|
`),
|
|
537
|
-
blockPlugins:
|
|
545
|
+
blockPlugins: j.join(`
|
|
538
546
|
`),
|
|
539
547
|
asyncComponents: O.join(",")
|
|
540
548
|
};
|
|
@@ -580,14 +588,14 @@ export default defineComponent({
|
|
|
580
588
|
<%= style %>
|
|
581
589
|
</style>
|
|
582
590
|
`, _t = J(Ct), At = J(Et);
|
|
583
|
-
async function Rt(e, t = /* @__PURE__ */ new Map(),
|
|
584
|
-
const
|
|
591
|
+
async function Rt(e, t = /* @__PURE__ */ new Map(), n = [], s) {
|
|
592
|
+
const i = new it(K(e), n), r = Ot(i, t), o = _t(r), c = At({
|
|
585
593
|
template: r.template,
|
|
586
|
-
css: await W(r.css,
|
|
587
|
-
script: await
|
|
588
|
-
style: await W(r.style,
|
|
594
|
+
css: await W(r.css, s),
|
|
595
|
+
script: await nt(o, s),
|
|
596
|
+
style: await W(r.style, s)
|
|
589
597
|
});
|
|
590
|
-
return await V(c,
|
|
598
|
+
return await V(c, s).catch((a) => (a.content = c, a));
|
|
591
599
|
}
|
|
592
600
|
async function Wt(e) {
|
|
593
601
|
const t = `
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.19",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"prettier": "~3.2.1",
|
|
8
8
|
"@vtj/base": "~0.8.2",
|
|
9
|
-
"@vtj/core": "~0.8.
|
|
9
|
+
"@vtj/core": "~0.8.19"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@vtj/cli": "~0.8.
|
|
12
|
+
"@vtj/cli": "~0.8.6"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
package/types/utils.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare function isJSCode(data: unknown): data is JSExpression | JSFuncti
|
|
|
6
6
|
export declare function JSCodeToString(data: unknown): string;
|
|
7
7
|
export declare function replaceThis(content: string): string;
|
|
8
8
|
export declare function replaceContext(content: string): string;
|
|
9
|
-
export declare function parseValue(val: unknown, stringify?: boolean, noThis?: boolean): string;
|
|
9
|
+
export declare function parseValue(val: unknown, stringify?: boolean, noThis?: boolean, computedKeys?: string[]): string;
|
|
10
10
|
export declare function replaceComputedValue(content: string, keys?: string[]): string;
|
|
11
11
|
export declare function replaceFunctionTag(content: string): string;
|
|
12
12
|
export declare function parsePlainObjectValue(obj?: Record<string, any>): 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.8.
|
|
5
|
+
* @version 0.8.18
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.8.
|
|
8
|
+
export declare const version = "0.8.18";
|