@vtj/coder 0.8.99 → 0.8.100
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 +15 -15
- package/dist/index.mjs +49 -55
- package/package.json +2 -2
- 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 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),
|
|
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),I=k(X),J=k(Y),T=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.100
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const ee="0.8.
|
|
7
|
+
*/const ee="0.8.100";/**!
|
|
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.100
|
|
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
|
|
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}',
|
|
15
15
|
default: ${u(e.default,!0,!1)}
|
|
16
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=>`'${typeof e=="string"?e:e.name}'`)}function
|
|
20
|
+
}`))}function le(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function S(t={},e=[]){return Object.entries(t).map(([n,r])=>{let i=U(u(r,!1,!1));return i=w(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=S(n,e),i=t.map(s=>`watcher_${s.id}: {
|
|
21
21
|
deep: ${s.deep},
|
|
22
22
|
immediate:${s.immediate},
|
|
23
23
|
handler${U(s.handler.value)}
|
|
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
|
-
}`})}function M(t,e,n=[],r={},i){const s=[];let o={},a=[],c=[];return fe(t).forEach(m=>{const
|
|
27
|
-
`),Object.assign(o,y?.methods||{}),a=a.concat(y?.components||[]),c=c.concat(y?.importBlocks||[]));const
|
|
28
|
-
`+
|
|
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 z(t){return typeof t=="object"&&t.type==="UrlSchema"}function Q(t){return typeof t=="object"&&t.type==="Plugin"}function he(t,e,n=[]){return t==="style"?"":t==="__class"&&$(e)?`:class="${u({...e,value:
|
|
26
|
+
}`})}function M(t,e,n=[],r={},i){const s=[];let o={},a=[],c=[];return fe(t).forEach(m=>{const b=[];for(const p of m.children){let{id:O,name:h,invisible:C,from:d}=p;if(C)continue;const j=me(h,e,d);j&&a.push(j),D(d)&&c.push({id:d.id,name:h});const{props:g,events:F,handlers:G}=$e(p,O,p.props,p.events,r,n),N=be(p.directives,n).join(" "),y=p.children?ve(p.children,n,e,r,p):"";Object.assign(o,G);let v="";typeof y=="string"?v=y:(v=(y?.nodes||[]).join(`
|
|
27
|
+
`),Object.assign(o,y?.methods||{}),a=a.concat(y?.components||[]),c=c.concat(y?.importBlocks||[]));const B=z(d)||Q(d)?"component":h;b.push(h==="img"?`<${h} ${N} ${g} ${F} />`:`<${B} ${N} ${g} ${F}>${v?`
|
|
28
|
+
`+v.trim():""}</${B}>`)}const P=Se(m.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 z(t){return typeof t=="object"&&t.type==="UrlSchema"}function Q(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(z(i)||Q(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 f=c.handler.value.startsWith("this."),m=f?L(c.handler.value):`${l.camelCase(a)}_${t}${s}`;return f||(r[m]=i.length?{type:"JSFunction",value:`{
|
|
30
30
|
return (${c.handler.value}).apply(this, args);
|
|
31
|
-
}`}:c.handler),ye(a,c,m,i,f)}),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),f=a.arg?E(a.arg)?`:[${u(a.arg,!0,!0,e)}]`:`:${a.arg}`:"";n.push(`v-model${f}${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){
|
|
31
|
+
}`}:c.handler),ye(a,c,m,i,f)}),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),f=a.arg?E(a.arg)?`:[${u(a.arg,!0,!0,e)}]`:`:${a.arg}`:"";n.push(`v-model${f}${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){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}
|
|
33
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,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=
|
|
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=S(n.lifeCycles,r),s=S(n.computed,r),o=ue(n.watch,r),a=pe(n.dataSources),{methods:c,nodes:f,components:m,importBlocks:b}=M(n.nodes||[],e,r,t.context),P=[...s,...o.computed],p=S({...c,...n.methods||{}},r),O=b.map(g=>`import ${g.name} from './${g.id}.vue';`),h=we(e,m,O,t.imports),C=Object.keys({...t.urlSchemas,...t.blockPlugins}),d=Pe(t.urlSchemas),j=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
39
|
`),components:m.join(","),returns:t.members.join(","),template:f.join(`
|
|
40
40
|
`),css:n.css||"",style:ke(t.style),urlSchemas:d.join(`
|
|
41
|
-
`),blockPlugins:
|
|
41
|
+
`),blockPlugins:j.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=[],r){const i=new ie(l.cloneDeep(t),n),s=Ce(i,e),o=Ee(s),a=Ae({template:s.template,css:await
|
|
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 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=`
|
|
83
83
|
<template>
|
|
84
84
|
<div>
|
|
85
85
|
<h3>源码模式页面</h3>
|
|
@@ -90,4 +90,4 @@ export default defineComponent({
|
|
|
90
90
|
<\/script>
|
|
91
91
|
<style scoped lang="scss">
|
|
92
92
|
</style>
|
|
93
|
-
`;return await
|
|
93
|
+
`;return await q(e)}exports.VTJ_CODER_VERSION=ee;exports.createEmptyPage=Ne;exports.generator=Fe;
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { mitt as X, dedupArray as
|
|
1
|
+
import { mitt as X, dedupArray as w, toArray as Y, camelCase as y, isPlainObject as Z, template as I, 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
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
4
|
+
import * as J from "prettier/plugins/babel";
|
|
5
|
+
import * as L from "prettier/plugins/postcss";
|
|
6
|
+
import * as T from "prettier/plugins/estree";
|
|
7
7
|
/**!
|
|
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.100
|
|
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.100";
|
|
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.100
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const et = [
|
|
@@ -53,25 +53,25 @@ const E = {
|
|
|
53
53
|
useTabs: !1,
|
|
54
54
|
vueIndentScriptAndStyle: !0
|
|
55
55
|
};
|
|
56
|
-
async function
|
|
56
|
+
async function U(e, t) {
|
|
57
57
|
return t ? e : await C(e, {
|
|
58
58
|
parser: "vue",
|
|
59
59
|
...E,
|
|
60
|
-
plugins: [tt,
|
|
60
|
+
plugins: [tt, J, T, L]
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
async function nt(e, t) {
|
|
64
64
|
return t ? e : await C(e, {
|
|
65
65
|
parser: "babel-ts",
|
|
66
66
|
...E,
|
|
67
|
-
plugins: [
|
|
67
|
+
plugins: [J, T]
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
async function
|
|
70
|
+
async function R(e, t) {
|
|
71
71
|
return t ? e : C(e, {
|
|
72
72
|
parser: "scss",
|
|
73
73
|
...E,
|
|
74
|
-
plugins: [
|
|
74
|
+
plugins: [L]
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
function _(e) {
|
|
@@ -83,17 +83,17 @@ function A(e) {
|
|
|
83
83
|
function $(e) {
|
|
84
84
|
return _(e) || A(e);
|
|
85
85
|
}
|
|
86
|
-
function
|
|
86
|
+
function V(e) {
|
|
87
87
|
return e.replace(new RegExp("this.", "g"), "");
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function W(e) {
|
|
90
90
|
return e.replace(/this\.context\??\./g, "");
|
|
91
91
|
}
|
|
92
92
|
function l(e, t = !0, n = !0, s = []) {
|
|
93
93
|
let i = $(e) ? e.value : t ? JSON.stringify(e) : e;
|
|
94
|
-
return i =
|
|
94
|
+
return i = k(i, s), n ? V(W(i)) : W(i);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function k(e, t = []) {
|
|
97
97
|
let n = e;
|
|
98
98
|
for (const s of t)
|
|
99
99
|
n = n.replace(
|
|
@@ -205,7 +205,7 @@ class it {
|
|
|
205
205
|
let n = [...t];
|
|
206
206
|
for (const s of Object.values(this.imports))
|
|
207
207
|
n = n.concat(Array.from(s));
|
|
208
|
-
return
|
|
208
|
+
return w(n);
|
|
209
209
|
}
|
|
210
210
|
collectContext(t, n) {
|
|
211
211
|
const s = new Set(n?.id ? this.context[n.id] : []), i = (t.directives || []).find((c) => c.name === "vFor");
|
|
@@ -260,17 +260,17 @@ function at(e = []) {
|
|
|
260
260
|
function lt(e = []) {
|
|
261
261
|
return e.map((t) => `'${typeof t == "string" ? t : t.name}'`);
|
|
262
262
|
}
|
|
263
|
-
function
|
|
263
|
+
function S(e = {}, t = []) {
|
|
264
264
|
return Object.entries(e).map(([n, s]) => {
|
|
265
265
|
let i = q(l(s, !1, !1));
|
|
266
|
-
return i =
|
|
266
|
+
return i = k(i, t), i.startsWith("async") ? `async ${n}${i.replace(/^async/, "")}` : `${n}${i}`;
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
function ut(e = [], t = []) {
|
|
270
270
|
const n = e.reduce(
|
|
271
271
|
(r, o) => (o.id && A(o.source) && (r[`watcher_${o.id}`] = o.source), r),
|
|
272
272
|
{}
|
|
273
|
-
), s =
|
|
273
|
+
), s = S(n, t), i = e.map((r) => `watcher_${r.id}: {
|
|
274
274
|
deep: ${r.deep},
|
|
275
275
|
immediate:${r.immediate},
|
|
276
276
|
handler${q(r.handler.value)}
|
|
@@ -292,21 +292,21 @@ function D(e, t, n = [], s = {}, i) {
|
|
|
292
292
|
const r = [];
|
|
293
293
|
let o = {}, c = [], a = [];
|
|
294
294
|
return ft(e).forEach((f) => {
|
|
295
|
-
const
|
|
295
|
+
const v = [];
|
|
296
296
|
for (const u of f.children) {
|
|
297
297
|
let { id: x, name: m, invisible: O, from: h } = u;
|
|
298
298
|
if (O)
|
|
299
299
|
continue;
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
const { props: g, events:
|
|
300
|
+
const b = mt(m, t, h);
|
|
301
|
+
b && c.push(b), Q(h) && a.push({ id: h.id, name: m });
|
|
302
|
+
const { props: g, events: F, handlers: H } = $t(
|
|
303
303
|
u,
|
|
304
304
|
x,
|
|
305
305
|
u.props,
|
|
306
306
|
u.events,
|
|
307
307
|
s,
|
|
308
308
|
n
|
|
309
|
-
),
|
|
309
|
+
), N = vt(u.directives, n).join(
|
|
310
310
|
" "
|
|
311
311
|
), d = u.children ? jt(
|
|
312
312
|
u.children,
|
|
@@ -316,23 +316,23 @@ function D(e, t, n = [], s = {}, i) {
|
|
|
316
316
|
u
|
|
317
317
|
) : "";
|
|
318
318
|
Object.assign(o, H);
|
|
319
|
-
let
|
|
320
|
-
typeof d == "string" ?
|
|
319
|
+
let j = "";
|
|
320
|
+
typeof d == "string" ? j = d : (j = (d?.nodes || []).join(`
|
|
321
321
|
`), Object.assign(o, d?.methods || {}), c = c.concat(d?.components || []), a = a.concat(d?.importBlocks || []));
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
m === "img" ? `<${m} ${
|
|
325
|
-
` +
|
|
322
|
+
const B = z(h) || G(h) ? "component" : m;
|
|
323
|
+
v.push(
|
|
324
|
+
m === "img" ? `<${m} ${N} ${g} ${F} />` : `<${B} ${N} ${g} ${F}>${j ? `
|
|
325
|
+
` + j.trim() : ""}</${B}>`
|
|
326
326
|
);
|
|
327
327
|
}
|
|
328
|
-
const P = St(f.slot,
|
|
328
|
+
const P = St(f.slot, v.join(`
|
|
329
329
|
`), i?.id);
|
|
330
330
|
r.push(P);
|
|
331
331
|
}), {
|
|
332
332
|
nodes: r,
|
|
333
333
|
methods: o,
|
|
334
|
-
components:
|
|
335
|
-
importBlocks:
|
|
334
|
+
components: w(c),
|
|
335
|
+
importBlocks: w(a, "id")
|
|
336
336
|
};
|
|
337
337
|
}
|
|
338
338
|
function ft(e = []) {
|
|
@@ -364,10 +364,10 @@ function G(e) {
|
|
|
364
364
|
function ht(e, t, n = []) {
|
|
365
365
|
return e === "style" ? "" : e === "__class" && $(t) ? `:class="${l({
|
|
366
366
|
...t,
|
|
367
|
-
value:
|
|
367
|
+
value: k(t.value, n)
|
|
368
368
|
})}"` : typeof t == "string" ? `${e}="${t}"` : $(t) ? `:${e}="${l({
|
|
369
369
|
...t,
|
|
370
|
-
value:
|
|
370
|
+
value: k(t.value, n)
|
|
371
371
|
})}"` : Z(t) ? `:${e}='{${st(
|
|
372
372
|
t
|
|
373
373
|
).join(", ")}}'` : `:${e}='${JSON.stringify(t)}'`;
|
|
@@ -391,7 +391,7 @@ function gt(e, t = {}, n = {}) {
|
|
|
391
391
|
const s = {}, i = Array.from(n[e] || /* @__PURE__ */ new Set([])), r = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
392
392
|
return {
|
|
393
393
|
binders: Object.entries(t).map(([c, a]) => {
|
|
394
|
-
const p = a.handler.value.startsWith("this."), f = p ?
|
|
394
|
+
const p = a.handler.value.startsWith("this."), f = p ? V(a.handler.value) : `${y(c)}_${e}${r}`;
|
|
395
395
|
return p || (s[f] = i.length ? {
|
|
396
396
|
type: "JSFunction",
|
|
397
397
|
value: `{
|
|
@@ -439,13 +439,7 @@ function bt(e = []) {
|
|
|
439
439
|
};
|
|
440
440
|
}
|
|
441
441
|
function jt(e, t, n, s, i) {
|
|
442
|
-
|
|
443
|
-
return e;
|
|
444
|
-
if (_(e)) {
|
|
445
|
-
let r = l(e, !1);
|
|
446
|
-
return r = v(r, t), r = F(r), `{{ ${r} }}`;
|
|
447
|
-
}
|
|
448
|
-
return Array.isArray(e) ? D(e, n, t, s, i) : "";
|
|
442
|
+
return typeof e == "string" ? e : _(e) ? `{{ ${l(e, !1, !0, t)} }}` : Array.isArray(e) ? D(e, n, t, s, i) : "";
|
|
449
443
|
}
|
|
450
444
|
function St(e, t, n) {
|
|
451
445
|
if (!e) return t;
|
|
@@ -464,7 +458,7 @@ function wt(e, t = [], n = [], s = {}) {
|
|
|
464
458
|
}
|
|
465
459
|
for (const [r, o] of Object.entries(s))
|
|
466
460
|
(i[r] ?? (i[r] = [])).push(...Array.from(o));
|
|
467
|
-
return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${
|
|
461
|
+
return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${w(o).join(
|
|
468
462
|
","
|
|
469
463
|
)}} from '${r}';`).concat(n);
|
|
470
464
|
}
|
|
@@ -496,18 +490,18 @@ function xt(e = {}) {
|
|
|
496
490
|
}), t;
|
|
497
491
|
}
|
|
498
492
|
function Ot(e, t) {
|
|
499
|
-
const { dsl: n } = e, s = Object.keys(n.computed || {}), i =
|
|
493
|
+
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: p, components: f, importBlocks: v } = D(
|
|
500
494
|
n.nodes || [],
|
|
501
495
|
t,
|
|
502
496
|
s,
|
|
503
497
|
e.context
|
|
504
|
-
), P = [...r, ...o.computed], u =
|
|
498
|
+
), P = [...r, ...o.computed], u = S(
|
|
505
499
|
{
|
|
506
500
|
...a,
|
|
507
501
|
...n.methods || {}
|
|
508
502
|
},
|
|
509
503
|
s
|
|
510
|
-
), x =
|
|
504
|
+
), x = v.map((g) => `import ${g.name} from './${g.id}.vue';`), m = wt(
|
|
511
505
|
t,
|
|
512
506
|
f,
|
|
513
507
|
x,
|
|
@@ -515,7 +509,7 @@ function Ot(e, t) {
|
|
|
515
509
|
), O = Object.keys({
|
|
516
510
|
...e.urlSchemas,
|
|
517
511
|
...e.blockPlugins
|
|
518
|
-
}), h = Pt(e.urlSchemas),
|
|
512
|
+
}), h = Pt(e.urlSchemas), b = xt(e.blockPlugins);
|
|
519
513
|
return {
|
|
520
514
|
id: n.id,
|
|
521
515
|
version: n.__VERSION__,
|
|
@@ -538,7 +532,7 @@ function Ot(e, t) {
|
|
|
538
532
|
style: kt(e.style),
|
|
539
533
|
urlSchemas: h.join(`
|
|
540
534
|
`),
|
|
541
|
-
blockPlugins:
|
|
535
|
+
blockPlugins: b.join(`
|
|
542
536
|
`),
|
|
543
537
|
asyncComponents: O.join(",")
|
|
544
538
|
};
|
|
@@ -583,15 +577,15 @@ export default defineComponent({
|
|
|
583
577
|
<%= css %>
|
|
584
578
|
<%= style %>
|
|
585
579
|
</style>
|
|
586
|
-
`, _t =
|
|
580
|
+
`, _t = I(Ct), At = I(Et);
|
|
587
581
|
async function Rt(e, t = /* @__PURE__ */ new Map(), n = [], s) {
|
|
588
582
|
const i = new it(K(e), n), r = Ot(i, t), o = _t(r), c = At({
|
|
589
583
|
template: r.template,
|
|
590
|
-
css: await
|
|
584
|
+
css: await R(r.css, s),
|
|
591
585
|
script: await nt(o, s),
|
|
592
|
-
style: await
|
|
586
|
+
style: await R(r.style, s)
|
|
593
587
|
});
|
|
594
|
-
return await
|
|
588
|
+
return await U(c, s).catch((a) => (a.content = c, a));
|
|
595
589
|
}
|
|
596
590
|
async function Wt(e) {
|
|
597
591
|
const t = `
|
|
@@ -606,7 +600,7 @@ async function Wt(e) {
|
|
|
606
600
|
<style scoped lang="scss">
|
|
607
601
|
</style>
|
|
608
602
|
`;
|
|
609
|
-
return await
|
|
603
|
+
return await U(t);
|
|
610
604
|
}
|
|
611
605
|
export {
|
|
612
606
|
Bt as VTJ_CODER_VERSION,
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.100",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"prettier": "~3.3.0",
|
|
8
8
|
"@vtj/base": "~0.8.10",
|
|
9
|
-
"@vtj/core": "~0.8.
|
|
9
|
+
"@vtj/core": "~0.8.100"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@vtj/cli": "~0.8.24"
|
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.99
|
|
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.99";
|