@vtj/renderer 0.10.11 → 0.10.12
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 +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +5 -5
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
3
3
|
* @name @vtj/renderer
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
5
|
-
* @version 0.10.
|
5
|
+
* @version 0.10.12
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
7
|
-
*/const V="0.10.
|
7
|
+
*/const V="0.10.12";var _=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(_||{});const J=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],xe=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],ne=["vIf","vShow","vModel","vFor","vBind","vHtml"],oe={String,Number,Boolean,Array,Object,Function,Date},C="VtjPage",T="VtjHomepage",ie="html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot".split(","),ae="component,slot".split(",");function k(r,e){return r.map(t=>l.isUrl(t)||t.startsWith("/")?t:`${e}${t}`)}function N(r){return/\.css$/.test(r)}function U(r){return/\.js$/.test(r)}function ce(r){return/\.json$/.test(r)}function Ne(r){return r.map(e=>`<script src="${l.url.append(e,{v:V})}"><\/script>`).join("")}function Ue(r=[]){return r.map(e=>`<link rel="stylesheet" href="${l.url.append(e,{v:V})}" />`).join("")}function le(r,e=!1){return e&&r.endsWith(".prod.js")?r.replace(".prod.js",".js"):r}function ue(r,e,t=!1){const s=r.filter(g=>!!g.enabled),n=[],o=[],a=[],i=[],c={},u={},h=[],p={};return s.forEach(({urls:g,assetsUrl:m,library:f,assetsLibrary:d,localeLibrary:j})=>{g?.forEach(v=>{U(v)&&n.push(le(v,t)),N(v)&&o.push(v)}),f&&(i.push(f),c[f]=k(g||[],e),j&&(u[f]=j)),m&&a.push(m),d&&h.push(d),f&&d&&(p[d]=f)}),{scripts:k(n,e),css:k(o,e),materials:k(a,e),libraryExports:i,materialExports:l.dedupArray(h),materialMapLibrary:p,libraryMap:c,libraryLocaleMap:u}}function de(r,e){const{name:t,parent:s,alias:n}=r;return s?e[s]?.[n||t]:e[n||t]}function z(r){return l.isString(r)?r:JSON.stringify(r)}function G(r,e,t){const s=r.CSSStyleSheet;if(s.prototype.replaceSync){const n=new s;n.id=e,n.replaceSync(t);const o=r.document,a=o.adoptedStyleSheets,i=Array.from(a).filter(c=>c.id!==e);o.adoptedStyleSheets=[...i,n]}else{const n=r.document;let o=n.getElementById(e);o?o.innerHTML=t:(o=n.createElement("style"),o.id=e,o.innerHTML=t,n.head.appendChild(o))}}async function pe(r,e){const t=await window.fetch(e).then(s=>s.text()).catch(()=>"");t&&G(window,r,t)}function fe(r,e=window){const t=e.document,s=e.document.head;for(const n of r)if(!t.getElementById(n)){const a=t.createElement("link");a.rel="stylesheet",a.id=n,a.href=n,s.appendChild(a)}}async function he(r,e,t=window){const s=t.document,n=t.document.head;let o=t[e];return o?o.default||o:new Promise((a,i)=>{for(const c of r){const u=s.createElement("script");u.src=c,u.onload=()=>{o=t[e],o?a(o.default||o):i(null)},u.onerror=h=>{i(h)},n.appendChild(u)}})}function me(r){return l.isFunction(r)||l.isFunction(r?.install)}function ge(r){return ae.includes(r)}function ve(r){return ie.includes(r)}function R(r=window){const e=window?.Mock;if(e)return e;const t=r?.Mock;if(t&&window)return window.Mock=t,t}function A(r,e,t=!1,s=!1){try{const n=['"use strict";',"var __self = arguments[0];"];n.push("return ");let o=(r.value||"").trim();o=o.replace(/this(\W|$)/g,(i,c)=>`__self${c}`),o=n.join(`
|
8
8
|
`)+o;const a=`with(${t?"{}":"$scope || {}"}) { ${o} }`;return new Function("$scope",a)(e)}catch(n){if(l.logger.error("parseExpression.error",n,r,e?.__self??e),s)throw n}}function O(r,e,t=!1,s=!1){const n=A(r,e,t,s);if(typeof n!="function"&&(l.logger.error("parseFunction.error","not a function",r,e?.__self??e),s))throw new Error(`"${r.value}" not a function`);return n}function w(r){return r&&r.type==="JSExpression"}function M(r){return typeof r=="object"&&r&&r.type==="JSFunction"}function ye(r){return w(r)||M(r)}function Be(r){return ye(r)?r.value:JSON.stringify(r)}const Le={session:!1,authKey:"Authorization",storageKey:"ACCESS_STORAGE",storagePrefix:"__VTJ_",unauthorized:void 0,auth:"/#/login",redirectParam:"r",unauthorizedCode:401,unauthorizedMessage:"登录已经失效,请重新登录!",noPermissionMessage:"无权限访问该页面",appName:""},W=Symbol("access");class qe{options;data=null;mode=_.Raw;constructor(e){this.options=Object.assign({},Le,e),this.loadData()}connect(e){const{mode:t,router:s,request:n}=e;this.mode=t,s&&this.mode===_.Raw&&this.setGuard(s),n&&this.setRequest(n)}login(e){const{storageKey:t,storagePrefix:s,session:n,authKey:o}=this.options;this.setData(e),this.data&&(l.storage.save(t,e,{type:"local",prefix:s}),n&&l.cookie.set(o,this.data.token))}clear(){const{storageKey:e,storagePrefix:t,session:s,authKey:n}=this.options;this.data=null,l.storage.remove(e,{type:"local",prefix:t}),s&&l.cookie.remove(n)}logout(){this.clear(),this.toLogin()}getData(){return this.data?this.data:(this.loadData(),this.data)}getToken(){return this.data||this.loadData(),this.data?.token}can(e){const{appName:t}=this.options,{permissions:s={}}=this.data||{};return typeof e=="function"?e(s):l.toArray(e).every(o=>s[o]||s[t+"."+o])}some(e){const{appName:t}=this.options,{permissions:s={}}=this.data||{};return l.toArray(e).some(o=>s[o]||s[t+"."+o])}install(e){e.config.globalProperties.$access||(e.config.globalProperties.$access=this,e.provide(W,this))}isAuthPath(e){const{auth:t,isAuth:s}=this.options;if(s)return s(e);if(e.path&&typeof t=="string"){const n=t.split("#")[1]||t;return e.path===n}return!1}toLogin(){const{auth:e,redirectParam:t}=this.options;if(!e)return;const s=t?`?${t}=${encodeURIComponent(location.href)}`:"";typeof e=="function"?e(s):location.href=t?`${e}${s}`:e}setData(e){const{privateKey:t}=this.options;if(Array.isArray(e)&&t){const s=e.map(n=>l.unRSA(n,t));this.data=JSON.parse(s.join(""));return}if(typeof e=="string")try{const s=t?l.unRSA(e,t):e;s?this.data=JSON.parse(s):console.warn("RSA解密失败或登录信息缺失")}catch(s){console.warn(s)}else this.data=e}loadData(){const{storageKey:e,storagePrefix:t}=this.options,s=l.storage.get(e,{type:"local",prefix:t});this.setData(s||null)}isLogined(){const{session:e,authKey:t}=this.options;return e&&t?!!l.cookie.get(t):!!this.getToken()}hasRoutePermission(e){if(e.name===C){const t=e.params.id;return t&&this.can(t)}return!0}setGuard(e){e.beforeEach((t,s,n)=>this.guard(t,n))}async guard(e,t){if(this.isWhiteList(e)||this.isAuthPath(e))return t();if(this.isLogined()){if(this.hasRoutePermission(e))return t();{const{noPermissionMessage:s="无权限访问",unauthorized:n=!1}=this.options;return await this.showTip(s),l.isFunction(n)?(n(),t(!1)):l.isString(n)?t(n):t(!1)}}t(!1),this.toLogin()}isWhiteList(e){const{whiteList:t}=this.options;return t?Array.isArray(t)?t.some(s=>e.fullPath.startsWith(s)):t(e):!1}isUnauthorized(e){const{unauthorizedCode:t=401}=this.options;return e.status===t||e.data?.code===t}async showUnauthorizedAlert(e){const{unauthorizedMessage:t="登录已失效"}=this.options;this.isUnauthorized(e)&&(await this.showTip(t),this.toLogin())}async showTip(e){const{alert:t}=this.options;return t?(await l.delay(150),await t(e,{title:"提示",type:"warning"}).catch(()=>!1)):!1}setRequest(e){e.useRequest(t=>(this.data?.token&&(t.headers[this.options.authKey]=this.data?.token),t)),e.useResponse(async t=>(await this.showUnauthorizedAlert(t),t),async t=>{const s=t.response||t||{};return await this.showUnauthorizedAlert(s),Promise.reject(t)})}}function _e(){return y.inject(W,null)}function Je(r={}){const{notify:e,loading:t,settings:s={},Startup:n}=r;let o=null;return{request:l.createRequest({settings:{type:"form",validSuccess:!0,originResponse:!1,loading:!0,validate:i=>i.data?.code===0||!!i.data?.success,failMessage:!0,showError:i=>{e&&e(i||"未知错误")},showLoading:()=>{o&&o.close(),t&&(o=t())},hideLoading:()=>{o&&(o.close(),o=null)},...s}}),jsonp:l.jsonp,notify:e,loading:t,startupComponent:n}}function Se(r,e){const{jsonp:t,request:s}=e;if(r.method==="jsonp")return(n={})=>t(r.url,{...r.jsonpOptions,query:n});{const n=r.headers?A(r.headers,{},!0):void 0,o={url:r.url,method:r.method,settings:{...r.settings,headers:n}};return(a,i)=>(delete o.data,s.send(l.merge(o,i||{},{data:a})))}}function we(r,e){const{metaQuery:t}=e;if(!t)return;const{code:s,queryCode:n}=r;return(o,a)=>{if(!t){console.warn("adapter.metaQuery is not defined!");return}return t(s,n,o,a)}}function je(r=[],e=[],t){const s={};for(const n of r)s[n.id]=Se(n,t);for(const n of e)s[n.id]=we(n,t);return s}async function Ee(r=[],e=window){const t=R(e);t&&(Y(e),r.forEach(s=>Pe(t,s)))}function $e(r,e=window){const t=M(r.mockTemplate)&&r.mockTemplate.value?O(r.mockTemplate,{},!0):void 0,s=R(e);return async(...n)=>{let o={};if(t)try{o=await t.apply(t,n)}catch(a){l.logger.warn("模拟数据模版异常",a)}return s?.mock(o)}}function Pe(r,e){if(!e.mock)return;const{url:t,mockTemplate:s}=e;if(t&&s){const n=l.pathToRegexp(`${t}(.*)`),o=l.pathToRegexpMatch(t,{decode:decodeURIComponent}),a=A(s,{},!0);r.mock(n,i=>{const c=l.url.parse(i.url)||{},u=i.body instanceof FormData?l.formDataToJson(i.body):i.body,h=o(i.url)?.params;return Object.assign(i,{data:u,params:c,query:h}),r.mock(a(i))})}}function Y(r=window){const e=R(r);e&&(e._mocked={})}class be{__id=null;__mode;__instance=null;__contextRefs={};__refs={};context={};state={};props={};$props={};$refs={};$el=null;$emit=null;$nextTick=null;$parent=null;$root=null;$attrs=null;$slots=null;$watch=null;$options=null;$forceUpdate=null;$components={};$libs={};$apis={};__transform={};constructor(e){const{mode:t,dsl:s,attrs:n}=e;this.__mode=t,s&&(this.__id=s.id||null,this.__transform=s.transform||{}),n&&Object.assign(this,n)}setup(e,t=x){const s=t.getCurrentInstance();if(!s)return;this.__refs={},this.$refs={},this.context={},this.__contextRefs={},this.__instance=s.proxy;const n=s.appContext.config.globalProperties;Object.assign(this,n),Object.assign(this,e||{}),this.__proxy(),t.onMounted(()=>{this.__proxy()}),t.onUnmounted(()=>{this.__cleanup()}),t.onBeforeUpdate(()=>{this.__reset()})}__proxy(){this.__instance&&J.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){J.forEach(e=>{this[e]=null}),this.__reset()}__reset(){this.__refs={},this.$refs={},this.__contextRefs={},this.context={}}__parseFunction(e){if(e)if(this.__mode===_.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return O({type:s,value:n},this)}else return O(e,this)}__parseExpression(e){if(e)if(this.__mode===_.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return A({type:s,value:n},this)}else return A(e,this)}__ref(e=null,t){if(this.__mode!==_.VNode)return e&&e!==this.__id&&(this.__contextRefs[e]=this),async s=>{await l.delay(0);let n=s?.$vtjEl||s?.$el||s?._?.vnode?.el||s;if(!n){typeof t=="string"&&(delete this.$refs[t],e&&delete this.__refs[e]);return}return n.nodeType===3&&n.nextSibling&&(n=n.nextSibling),n.__vtj__=e,_.Design===this.__mode&&(n.__context__=this,n.draggable=!0),e&&(this.__refs[e]=this.__getRefEl(this.__refs,e,s)),typeof t=="function"?t(s):t&&(this.$refs[t]=this.__getRefEl(this.$refs,t,s)),s}}__getRefEl(e,t,s){const n=e[t];if(n&&s!==n){const o=new Set([].concat(n,s));return Array.from(o)}else return s}__clone(e={}){const t={...this.context,...e},s={...t,context:t};return s.context.__proto__=this.context,s.__proto__=this,s}}function D(r){const{Vue:e=x,mode:t=_.Runtime,components:s={},libs:n={},apis:o={},loader:a}=r,i=e.computed(()=>r.dsl),c={$components:s,$libs:n,$apis:o},u=new be({mode:t,dsl:i.value,attrs:c}),h=e.defineComponent({name:i.value.name,props:{...Ve(i.value.props??[],u)},setup(p){u.$props=p,u.props=p,i.value.id&&G(r.window||window,i.value.id,i.value.css||""),u.state=ze(e,i.value.state??{},u);const g=Ge(e,i.value.computed??{},u),m=We(i.value.methods??{},u),f=Ye(e,i.value.inject,u),d=Ce(i.value.dataSources||{},u),j={...f,...g,...m,...d};return u.setup(j,e),Qe(e,i.value.watch??[],u),{vtj:u}},emits:Ke(i.value.emits),expose:["vtj"],render(){if(!i.value.nodes)return null;const p=i.value.nodes||[];return p.length===1?F(p[0],u,e,a):p.map(g=>F(g,u,e,a))},...Xe(i.value.lifeCycles??{},u)});return{renderer:e.markRaw(h),context:u}}function Ke(r=[]){return r.map(e=>l.isString(e)?e:e.name)}function Ve(r=[],e){const t=s=>s?(Array.isArray(s)?s:[s]).map(o=>oe[o]):void 0;return r.map(s=>l.isString(s)?{name:s}:{name:s.name,type:s.type,required:s.required,default:w(s.default)?e.__parseExpression(s.default):s.default}).reduce((s,n)=>(s[n.name]={type:t(n.type),required:n.required,default:n.default},s),{})}function ze(r,e,t){return r.reactive(Object.keys(e||{}).reduce((s,n)=>{let o=e[n];return w(o)?o=t.__parseExpression(o):M(o)&&(o=t.__parseFunction(o)),s[n]=o,s},{}))}function Ge(r,e,t){return Object.entries(e??{}).reduce((s,[n,o])=>(s[n]=r.computed(t.__parseFunction(o)),s),{})}function We(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}function Ye(r,e=[],t){return e.reduce((s,n)=>{const{name:o,from:a}=n||{};n.default;const i=w(a)?t.__parseExpression(a)||o:a??o,c=w(n.default)?t.__parseExpression(n.default):n.default??null;return s[o]=r.inject(i,c),s},{})}function Ce(r,e){return Object.keys(r).reduce((t,s)=>{const n=r[s];if(n.type==="mock")t[s]=$e(n);else if(n.ref){const o=e.$apis[n.ref],a=M(n.transform)?n.transform.value?e.__parseFunction(n.transform):void 0:n.transform;t[s]=async(...i)=>{const c=await o.apply(e,i);return a?a(c):c}}return t},{})}function Qe(r,e=[],t){e.forEach(s=>{r.watch(t.__parseExpression(s.source),t.__parseFunction(s.handler),{deep:s.deep,immediate:s.immediate})})}function Xe(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}let q=[],b={};const Re=r=>r;async function Q(r,e=window){const{urls:t=[],library:s}=r,n=t.filter(i=>U(i));if(n.length===0||!s)return null;const o=t.filter(i=>N(i));return o.length&&fe(o,e),await he(n,s,e).catch(i=>(console.warn("loadScriptUrl error",n,s,i),null))}function H(r){const{getDsl:e,getDslByUrl:t,options:s}=r;return s.window&&(q.forEach(n=>{delete s.window[n]}),q=[]),(n,o,a=x)=>{if(!o||typeof o=="string")return n;if(o.type==="Schema"&&o.id){let i=b[o.id];return i||(i=b[o.id]=a.defineAsyncComponent(async()=>{const c=await e(o.id);return c&&(c.name=n),c?D({...s,Vue:a,dsl:c,mode:_.Runtime,loader:H(r)}).renderer:null}),i)}if(o.type==="UrlSchema"&&o.url){let i=b[o.url];return i||(i=b[o.url]=a.defineAsyncComponent(async()=>{const c=await t(o.url);return c&&(c.name=n),c?D({...s,Vue:a,dsl:c,mode:_.Runtime,loader:H(r)}).renderer:null}),i)}if(o.type==="Plugin"){let i=o.library?b[o.library]:null;return i||(o.library&&q.push(o.library),i=b[o.library||Symbol()]=a.defineAsyncComponent(async()=>{const c=await Q(o,s.window);return c||(console.warn("getPlugin result is null",o),null)}),i)}return n}}function Ze(){b={}}function F(r,e,t=x,s=Re){if(!r||!r.name||r.invisible)return null;const n=t.getCurrentInstance()?.appContext,{id:o=null,directives:a=[]}=r,{vIf:i,vFor:c,vShow:u,vModels:h,vBind:p,vHtml:g,others:m}=tt(a);if(i&&!st(i,e))return null;const f=d=>{const j=d.$components,v=(()=>{if(r.name==="component")return rt(d,r.props?.is);if(r.name==="slot")return r.name;const $=s(r.name,r.from,t);return l.isString($)?ge($)||ve($)?$:j[$]??n?.app?.component($)??$:$})(),E=nt(o,r.props??{},d),Oe=ot(t,r.events??{},d);if(r.name==="slot")return it(t,r,E,d,s);p&&Object.assign(E,d.__parseExpression(p.value)),u&&(E.style=Object.assign(E.style??{},ct(u,d))),g&&Object.assign(E,lt(g,d)),h.forEach($=>{Object.assign(E,ut(t,$,d))});const De=dt(t,r.children??[],d,s,r);let L=t.createVNode(v,{...E,...Oe},De);const te=n?et(n,m,d):[];return te.length&&(L=t.withDirectives(L,te)),L};return c?ht(c,f,e):f(e)}function et(r,e,t){const s=r.app;return e.map(n=>{const o=typeof n.name=="string"?s.directive(n.name):t.__parseExpression(n.name);if(!o)return null;const a=[o];return n.value&&a.push(t.__parseExpression(n.value)),n.arg&&a.push(n.arg),n.modifiers&&a.push(n.modifiers),a}).filter(n=>!!n)}function tt(r=[]){const e=r.find(c=>l.camelCase(c.name)==="vIf"),t=r.find(c=>l.camelCase(c.name)==="vFor"),s=r.find(c=>l.camelCase(c.name)==="vShow"),n=r.find(c=>l.camelCase(c.name)==="vBind"),o=r.find(c=>l.camelCase(c.name)==="vHtml"),a=r.filter(c=>l.camelCase(c.name)==="vModel"),i=r.filter(c=>!ne.includes(l.camelCase(c.name)));return{vIf:e,vFor:t,vShow:s,vModels:a,vBind:n,others:i,vHtml:o}}function st(r,e){return!!e.__parseExpression(r.value)}function rt(r,e){return e?w(e)?r.__parseExpression(e):e:"div"}function nt(r,e,t){const s=K(e,t);return s.ref=t.__ref(r,s.ref),s}function K(r,e){return w(r)?e.__parseExpression(r):M(r)?e.__parseFunction(r):Array.isArray(r)?r.map(t=>K(t,e)):typeof r=="object"?Object.keys(r||{}).reduce((t,s)=>{let n=r[s];return t[s]=K(n,e),t},{}):r}function ot(r,e,t){const s=["passive","capture","once"],n={capture:"Capture",once:"Once",passive:"OnceCapture"};return Object.keys(e||{}).reduce((o,a)=>{const i=e[a],c=X(i.modifiers),u=c.find(g=>s.includes(g)),h="on"+l.upperFirst(a)+(u&&n[u]||""),p=t.__parseFunction(i.handler);return p&&(o[h]=r.withModifiers(p,c)),o},{})}function X(r={},e=!1){const t=Object.keys(r);return e?t.map(s=>"."+s):t}function it(r,e,t,s,n){const{children:o}=e,a=at(e,s),i=s.$slots?.[a.name];return i?i(t):o?l.isString(o)?r.createTextVNode(o):w(o)?r.createTextVNode(z(s.__parseExpression(o))):Array.isArray(o)?o.map(c=>F(c,s,r,n)):null:null}function at(r,e){const{props:t}=r,s=t?.name||"default";return{name:w(s)?e.__parseExpression(s):s,params:[]}}function ct(r,e){return e.__parseExpression(r.value)?{}:{display:"none"}}function lt(r,e){return{innerHTML:e.__parseExpression(r.value)||""}}function ut(r,e,t){const s={type:"JSFunction",value:e.value?.value?`(v) => {
|
9
9
|
${e.value.value} = v;
|
10
10
|
}`:"(v) => {}"},n=t.__parseFunction(s),o=X(w(e.modifiers)?t.__parseExpression(e.modifiers):e.modifiers),a=w(e.arg)?t.__parseExpression(e.arg):e.arg||"modelValue";return{[a]:t.__parseExpression(e.value),[`onUpdate:${a}`]:o.length&&n?r.withModifiers(n,o):n}}function dt(r,e,t,s,n){if(!e)return null;if(l.isString(e))return{default:()=>e};if(w(e))return{default:()=>z(t.__parseExpression(e))};if(Array.isArray(e)&&e.length>0){const o=pt(e),a=i=>!i||!n?{}:n?.id&&Object.keys(i).length?{[`scope_${n.id}`]:i}:{};return Object.entries(o).reduce((i,[c,{nodes:u,params:h}])=>(i[c]=p=>{const g=h.length?l.pick(p??{},h):a(p);return u.map(m=>F(m,t.__clone(g),r,s))},i),{})}return null}function pt(r){const e={default:{params:[],nodes:[]}};for(const t of r){const s=ft(t.slot),n=s.name;e[n]?(e[n].nodes.push(t),e[n].params=e[n].params.concat(s.params)):e[n]={nodes:[t],params:s.params}}return e}function ft(r="default"){return l.isString(r)?{name:r,params:[]}:{params:[],...r}}function ht(r,e,t){const{value:s,iterator:n}=r,{item:o="item",index:a="index"}=n||{};let i=t.__parseExpression(s)||[];return Number.isInteger(i)&&(i=new Array(i).fill(!0).map((c,u)=>u+1)),Array.isArray(i)?i.map((c,u)=>e(t.__clone({[o]:c,[a]:u}))):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const se=y.defineComponent({name:"VtjPageContainer",async setup(){const r=ee(),e=re.useRoute(),t=e.params.id,s=t?r.getPage(t):r.getHomepage(),n=s?await r.getRenderComponent(s.id):null,o=y.ref(Symbol());if(s){Object.assign(e.meta,s.meta||{},{cache:s.cache});const{useTitle:a}=r?.adapter;a&&a(s.title||"VTJ")}return{provider:r,component:n,file:s,query:e.query,meta:e.meta,sid:o,route:e}},render(){const{component:r,query:e,sid:t}=this;return r?y.h(r,{...e,key:t}):y.h("div","页面不存在")},activated(){this.meta.cache===!1&&(this.sid=Symbol())}}),mt=y.defineComponent({name:"VtjStartupContainer",render(){return y.h("div","page not found!")}}),Z=Symbol("Provider");var Ae=(r=>(r.Production="production",r.Development="development",r))(Ae||{});class Me extends P.Base{constructor(e){super(),this.options=e;const{service:t,mode:s=_.Raw,dependencies:n,materials:o,project:a={},adapter:i={},globals:c={},modules:u={},router:h=null,materialPath:p="./",nodeEnv:g="development"}=e;this.mode=s,this.modules=u,this.service=t,this.router=h,this.materialPath=p,this.nodeEnv=g,n&&(this.dependencies=n),o&&(this.materials=o),Object.assign(this.globals,c),Object.assign(this.adapter,i);const{access:m,request:f}=this.adapter;m&&m.connect({mode:s,router:h,request:f}),a&&s!==_.Design?this.load(a):this.project=a}mode;globals={};modules={};adapter={request:l.request,jsonp:l.jsonp};apis={};dependencies={};materials={};library={};service;project=null;components={};nodeEnv="development";router=null;materialPath="./";urlDslCaches={};createMock(e){return async(...t)=>{let s={};if(e)try{s=await e.apply(e,t)}catch(o){l.logger.warn("模拟数据模版异常",o)}return R()?.mock(s)}}async load(e){const t=this.modules[`.vtj/projects/${e.id}.json`]||this.modules[`/src/.vtj/projects/${e.id}.json`];if(this.project=t?await t():await this.service.init(e),!this.project)throw new Error("project is null");const{apis:s=[],meta:n=[]}=this.project,o=window;o&&(o.CKEDITOR_VERSION=void 0),this.mode===_.Raw?await this.loadDependencies(o):await this.loadAssets(o),this.initMock(o),this.apis=je(s,n,this.adapter),Y(o),Ee(s,o),e.platform!=="uniapp"&&this.initRouter(),this.triggerReady()}initMock(e){const t=R(e);t&&t.setup({timeout:"50-500"})}async loadDependencies(e){const t=Object.entries(this.dependencies);for(const[s,n]of t)e[s]||(e[s]=this.library[s]=await n())}async loadAssets(e){const{dependencies:t=[]}=this.project,{dependencies:s,library:n,components:o,materialPath:a,nodeEnv:i}=this,{libraryExports:c,libraryMap:u,materials:h,materialExports:p,materialMapLibrary:g}=ue(t,a,i==="development");for(const m of c){const f=s[m],d=e[m];if(d)n[m]=d;else if(f)e[m]=n[m]=await f();else{const j=u[m]||[];for(const v of j)N(v)&&await pe(m,l.url.append(v,{v:y.version})),U(v)&&await l.loadScript(l.url.append(v,{v:y.version}));n[m]=e[m]}}if(i==="development"){for(const f of h)await l.loadScript(l.url.append(f,{v:y.version}));const m=this.materials||{};for(const f of p){const d=e[g[f]],j=P.BUILT_IN_COMPONENTS[f];if(j)d&&j.forEach(v=>{o[v]=d[v]});else{const v=m[f]?(await m[f]()).default:e[f];v&&d&&(v.components||[]).forEach(E=>{o[E.name]=de(E,d)})}}}}initRouter(){const{router:e,project:t,options:s,adapter:n}=this;if(!e)return;const o=t?.platform==="uniapp"?"pages":"page",{routeAppendTo:a,pageRouteName:i=o,routeMeta:c}=s,u=a?"":"/",h={path:`${u}${i}/:id`,name:C,component:se},p={path:u,name:T,component:t?.homepage?se:n.startupComponent||mt,meta:c};e.hasRoute(C)&&e.removeRoute(C),e.hasRoute(T)&&e.removeRoute(T),a?(e.addRoute(a,h),e.addRoute(a,p)):(e.addRoute(h),e.addRoute(p))}install(e){const t=e.config.globalProperties.installed||{};for(const[s,n]of Object.entries(this.library))!t[s]&&me(n)&&(e.use(n),t[s]=!0);this.options.install&&e.use(this.options.install),this.adapter.access&&e.use(this.adapter.access),e.provide(Z,this),e.config.globalProperties.$provider=this,e.config.globalProperties.installed=t,this.mode===_.Design&&(e.config.errorHandler=(s,n,o)=>{const a=n?.$options.name,i=typeof s=="string"?s:s?.message||s?.msg||"未知错误",c=`[ ${a} ] ${i} ${o}`;console.error("[VTJ Error]:",{err:s,instance:n,info:o},s?.stack),this.adapter.notify&&this.adapter.notify(c,"组件渲染错误","error")})}getFile(e){const{blocks:t=[]}=this.project||{};return this.getPage(e)||t.find(s=>s.id===e)||null}getPage(e){const{pages:t=[]}=this.project||{},s=(n,o=[])=>{for(const a of o){if(a.id===n)return a;if(a.children&&a.children.length){const i=s(n,a.children);if(i)return i}}};return s(e,t)||null}getHomepage(){const{homepage:e}=this.project||{};return e?this.getPage(e):null}async getDsl(e){const t=this.modules[`.vtj/files/${e}.json`]||this.modules[`/src/.vtj/files/${e}.json`];return t?await t():this.service.getFile(e,this.project||void 0).catch(()=>null)}async getDslByUrl(e){const t=this.urlDslCaches[e];return t||(this.adapter.request?this.urlDslCaches[e]=this.adapter.request.send({url:e,method:"get",settings:{validSuccess:!1,originResponse:!0}}).then(s=>s.data).catch(()=>null):null)}createDslRenderer(e,t={}){const{library:s,components:n,mode:o,apis:a}=this,i={mode:o,Vue:s.Vue,components:n,libs:s,apis:a,window,...t},c=H({getDsl:async u=>await this.getDsl(u)||null,getDslByUrl:async u=>await this.getDslByUrl(u)||null,options:i});return D({...i,dsl:e,loader:c})}async getRenderComponent(e,t){const s=this.getFile(e);if(!s)return l.logger.warn(`Can not find file: ${e}`),null;t&&t(s);const n=`.vtj/vue/${e}.vue`,o=this.modules[n]||this.modules[`/src/pages/${e}.vue`];if(o)return(await o())?.default;const a=await this.getDsl(s.id);return a?this.createDslRenderer(a).renderer:(l.logger.warn(`Can not find dsl: ${e}`),null)}defineUrlSchemaComponent(e,t){return y.defineAsyncComponent(async()=>{const s=await this.getDslByUrl(e);return s?(s.name=t||s.name,this.createDslRenderer(s).renderer):null})}definePluginComponent(e){return y.defineAsyncComponent(async()=>await Q(e,window))}}function gt(r){const e=new Me(r);return{provider:e,onReady:s=>e.ready(s)}}function ee(r={}){const e=y.inject(Z,null);if(!e)throw new Error("Can not find provider");if(e.nodeEnv==="development"){const{id:t,version:s}=r;t&&s&&(async()=>{const n=await e.getDsl(t);n?.__VERSION__!==s&&e.adapter.notify&&e.adapter.notify(`[ ${n?.name} ] 组件源码版本与运行时版本不一致,请重新发布组件`,"版本不一致","warning")})()}return e}const ke={type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:r=>r.data?.code===0},vt=(r,e="/__vtj__/api/:type.json")=>(t,s,n)=>r.send({url:e,method:"post",params:{type:t},query:n,data:{type:t,data:s},settings:ke}),yt=(r,e="/__vtj__/api/uploader.json")=>async(t,s)=>await r.send({url:e,method:"post",data:{files:t,projectId:s},settings:{...ke,type:"data"}}).then(n=>n&&n[0]?n[0]:null).catch(()=>null);function _t(r){return l.createRequest({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:e=>e.data?.code===0,showError:e=>{r&&r(e||"未知错误")}}})}class B{api;pluginCaches={};uploader;constructor(e=l.request){this.api=vt(e),this.uploader=yt(e)}async getExtension(){console.log("BaseService.getExtension")}async init(e){return console.log("BaseService.init",e),{}}async saveProject(e,t){return!!await this.api("saveProject",e,{type:t}).catch(()=>!1)}async saveMaterials(e,t){return console.log("BaseService.saveMaterials",e,t),!1}async saveFile(e){return console.log("BaseService.saveFile",e),!1}async getFile(e){return console.log("BaseService.getFile",e),{}}async removeFile(e){return console.log("BaseService.removeFile",e),!1}async saveHistory(e){return console.log("BaseService.saveHistory",e),!1}async removeHistory(e){return console.log("BaseService.removeHistory",e),!1}async getHistory(e){return console.log("BaseService.getHistory",e),{}}async getHistoryItem(e,t){return console.log("BaseService.getHistoryItem",e,t),{}}async saveHistoryItem(e,t){return console.log("BaseService.saveHistoryItem",e,t),!1}async removeHistoryItem(e,t){return console.log("BaseService.removeHistoryItem",e,t),!1}async publish(e){return!!await this.api("publish",e).catch(()=>!1)}async publishFile(e,t){return!!await this.api("publishFile",{project:e,file:t}).catch(()=>!1)}async genVueContent(e,t){return await this.api("genVueContent",{project:e,dsl:t}).catch(()=>"")}async createRawPage(e){return await this.api("createRawPage",e).catch(()=>"")}async removeRawPage(e){return await this.api("removeRawPage",e).catch(()=>"")}async uploadStaticFile(e,t){return await this.uploader(e,t).catch(()=>null)}async getStaticFiles(e){return await this.api("getStaticFiles",e).catch(()=>[])}async removeStaticFile(e,t){return await this.api("removeStaticFile",{name:e,projectId:t}).catch(()=>"")}async clearStaticFiles(e){return await this.api("clearStaticFiles",e).catch(()=>"")}async getPluginMaterial(e){const{urls:t=[]}=e,s=t.filter(o=>ce(o))[0];if(!s)return null;const n=this.pluginCaches[s];return n||(this.pluginCaches[s]=l.request.send({url:s,method:"get",settings:{validSuccess:!1,originResponse:!0}}).then(o=>o.data).catch(()=>null))}async genSource(e){return console.log("BaseService.genSource",e),""}}const S=new l.Storage({type:"local",expired:0,prefix:"__VTJ_"});class St extends B{init(e){const t=new P.ProjectModel(e),s=S.get(`project_${t.id}`),n=Object.assign(t.toDsl(),s||{});return S.save(`project_${t.id}`,n),Promise.resolve(n)}saveProject(e){const t=new P.ProjectModel(e);return S.save(`project_${t.id}`,t.toDsl()),Promise.resolve(!0)}saveMaterials(e,t){return S.save(`materials_${e.id}`,l.mapToObject(t)),Promise.resolve(!0)}saveFile(e){return S.save(`file_${e.id}`,e),Promise.resolve(!0)}getFile(e){const t=S.get(`file_${e}`);return t?Promise.resolve(t):Promise.reject(null)}removeFile(e){return S.remove(`file_${e}`),Promise.resolve(!0)}saveHistory(e){return S.save(`history_${e.id}`,e),Promise.resolve(!0)}removeHistory(e){const t=S.get(`history_${e}`);if(t){const n=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,n),S.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=S.get(`history_${e}`),s=new P.HistoryModel(t||{id:e});return Promise.resolve(s.toDsl())}getHistoryItem(e,t){const s=S.get(`history_${e}_${t}`);return Promise.resolve(s)}saveHistoryItem(e,t){return S.save(`history_${e}_${t.id}`,t),Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{S.remove(`history_${e}_${s}`)}),Promise.resolve(!0)}}class Te extends B{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new P.ProjectModel(e),s=this.projects[t.id]||{},n=Object.assign(t.toDsl(),s);return this.projects[n.id]=n,Promise.resolve(n)}saveProject(e){const t=new P.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=l.mapToObject(t)),Promise.resolve(!0)}saveFile(e){return this.files[e.id]=e,Promise.resolve(!0)}getFile(e){const t=this.files[e];return t?Promise.resolve(t):Promise.reject(null)}removeFile(e){return delete this.files[e],Promise.resolve(!0)}saveHistory(e){return this.histories[e.id]=e,Promise.resolve(!0)}removeHistory(e){const t=this.histories[e];if(t){const n=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,n),delete this.historyItems[e]}return Promise.resolve(!0)}getHistory(e){const t=this.histories[e],s=new P.HistoryModel(t||{id:e});return Promise.resolve(s)}getHistoryItem(e,t){const s=`${e}_${t}`,n=this.historyItems[s]||{};return Promise.resolve(n)}saveHistoryItem(e,t){const s=`${e}_${t.id}`;return this.historyItems[s]=t,Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{const n=`${e}_${s}`;delete this.historyItems[n]}),Promise.resolve(!0)}}let I=null;function wt(){return I||(I=new Te,I)}class jt extends B{getFileCaches={};async getExtension(){return await this.api("getExtension",{}).catch(()=>{})}async init(e){return await this.api("init",e).catch(()=>null)||{}}async saveProject(e,t){return!!await this.api("saveProject",e,{type:t}).catch(()=>!1)}async saveMaterials(e,t){return!!await this.api("saveMaterials",{project:e,materials:l.mapToObject(t)}).catch(()=>!1)}async saveFile(e){return!!await this.api("saveFile",e).catch(()=>!1)}async getFile(e){const t=this.getFileCaches[e];return t||(this.getFileCaches[e]=this.api("getFile",e).catch(()=>null)).finally(()=>{delete this.getFileCaches[e]})}async removeFile(e){return!!await this.api("removeFile",e).catch(()=>!1)}async saveHistory(e){return!!await this.api("saveHistory",e).catch(()=>!1)}async removeHistory(e){return!!await this.api("removeHistory",e).catch(()=>!1)}async getHistory(e){return await this.api("getHistory",e).catch(()=>null)||{}}async getHistoryItem(e,t){return await this.api("getHistoryItem",{fId:e,id:t}).catch(()=>null)||{}}async saveHistoryItem(e,t){return!!await this.api("saveHistoryItem",{fId:e,item:t}).catch(()=>!1)}async removeHistoryItem(e,t){return!!await this.api("removeHistoryItem",{fId:e,ids:t}).catch(()=>!1)}}function Fe(r,e,t=[]){return t.map(s=>{const{id:n,title:o,icon:a,children:i,hidden:c}=s;return{id:n,title:o,icon:a,hidden:c,url:`${r}/${e}/${n}`,children:i&&i.length?Fe(r,e,i):void 0}})}function Ie(r,e){if(!e)return r;let t=[];for(const s of r)if(s.children&&s.children.length){const n=Ie(s.children,e);n.length&&(s.children=n,t.push(s))}else e.can(s.id.toString())&&t.push(s);return t}function Et(r){const{menuPathPrefix:e="",pageRouteName:t="page",disableMenusFilter:s=!1}=r||{},n=ee(),o=re.useRoute(),a=_e(),i=y.ref(!1),c=y.ref(!1),u=n.project;y.watchEffect(()=>{const{name:g,params:m,meta:f}=o;if(g===C){const d=n.getPage(m.id);i.value=!d?.mask,c.value=!!d?.pure}else if(g===T){const d=n.getHomepage();i.value=!d?.mask,c.value=!!d?.pure}else i.value=!f.mask,c.value=!!f.pure});const h=Fe(e,t,u?.pages),p=u?.config;return{disabled:i,logo:p?.logo,themeSwitchable:p?.themeSwitchable,title:p?.title||u?.description||u?.name||"VTJ App",menus:s?h:Ie(h,a),pure:c}}exports.ACCESS_KEY=W;exports.Access=qe;exports.BUILD_IN_TAGS=ae;exports.BUILT_IN_DIRECTIVES=ne;exports.BaseService=B;exports.CONTEXT_HOST=J;exports.Context=be;exports.ContextMode=_;exports.DATA_TYPES=oe;exports.HOMEPAGE_ROUTE_NAME=T;exports.HTML_TAGS=ie;exports.JSCodeToString=Be;exports.LIFE_CYCLES_LIST=xe;exports.LocalService=jt;exports.MemoryService=Te;exports.NodeEnv=Ae;exports.PAGE_ROUTE_NAME=C;exports.Provider=Me;exports.StorageService=St;exports.VTJ_RENDERER_VERSION=V;exports.adoptedStyleSheets=G;exports.clearLoaderCache=Ze;exports.createAdapter=Je;exports.createAssetScripts=Ne;exports.createAssetsCss=Ue;exports.createDataSources=Ce;exports.createLoader=H;exports.createMemoryService=wt;exports.createMetaApi=we;exports.createMock=$e;exports.createProvider=gt;exports.createRenderer=D;exports.createSchemaApi=Se;exports.createSchemaApis=je;exports.createServiceRequest=_t;exports.defaultLoader=Re;exports.fillBasePath=k;exports.getMock=R;exports.getModifiers=X;exports.getPlugin=Q;exports.getRawComponent=de;exports.isBuiltInTag=ge;exports.isCSSUrl=N;exports.isJSCode=ye;exports.isJSExpression=w;exports.isJSFunction=M;exports.isJSON=ce;exports.isJSUrl=U;exports.isNativeTag=ve;exports.isVuePlugin=me;exports.loadCss=pe;exports.loadCssUrl=fe;exports.loadScriptUrl=he;exports.mockApi=Pe;exports.mockApis=Ee;exports.mockCleanup=Y;exports.nodeRender=F;exports.parseDeps=ue;exports.parseExpression=A;exports.parseFunction=O;exports.providerKey=Z;exports.removeProdFlag=le;exports.toString=z;exports.useAccess=_e;exports.useMask=Et;exports.useProvider=ee;
|
package/dist/index.mjs
CHANGED
@@ -7,10 +7,10 @@ import { useRoute as he } from "vue-router";
|
|
7
7
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
8
8
|
* @name @vtj/renderer
|
9
9
|
* @author CHC chenhuachun1549@dingtalk.com
|
10
|
-
* @version 0.10.
|
10
|
+
* @version 0.10.12
|
11
11
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
12
12
|
*/
|
13
|
-
const me = "0.10.
|
13
|
+
const me = "0.10.12";
|
14
14
|
var y = /* @__PURE__ */ ((r) => (r.Runtime = "Runtime", r.Design = "Design", r.Raw = "Raw", r.VNode = "VNode", r))(y || {});
|
15
15
|
const oe = [
|
16
16
|
"$el",
|
package/package.json
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vtj/renderer",
|
3
3
|
"private": false,
|
4
|
-
"version": "0.10.
|
4
|
+
"version": "0.10.12",
|
5
5
|
"type": "module",
|
6
6
|
"dependencies": {
|
7
|
-
"@vtj/core": "~0.10.
|
8
|
-
"@vtj/utils": "~0.10.
|
7
|
+
"@vtj/core": "~0.10.12",
|
8
|
+
"@vtj/utils": "~0.10.12"
|
9
9
|
},
|
10
10
|
"devDependencies": {
|
11
11
|
"vue": "~3.5.5",
|
12
12
|
"vue-router": "~4.5.0",
|
13
13
|
"@vtj/cli": "~0.10.2",
|
14
|
-
"@vtj/ui": "~0.10.
|
15
|
-
"@vtj/icons": "~0.10.
|
14
|
+
"@vtj/ui": "~0.10.12",
|
15
|
+
"@vtj/icons": "~0.10.12"
|
16
16
|
},
|
17
17
|
"exports": {
|
18
18
|
".": {
|
package/types/version.d.ts
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
3
3
|
* @name @vtj/renderer
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
5
|
-
* @version 0.10.
|
5
|
+
* @version 0.10.11
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
7
7
|
*/
|
8
|
-
export declare const version = "0.10.
|
8
|
+
export declare const version = "0.10.11";
|