@vtj/renderer 0.8.129 → 0.8.130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2,9 +2,9 @@
2
2
  * Copyright (c) 2024, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/renderer
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.8.129
5
+ * @version 0.8.130
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const P="0.8.129";var w=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(w||{});const U=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],Ee=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],ee=["vIf","vShow","vModel","vFor","vBind"],te={String,Number,Boolean,Array,Object,Function,Date};function R(r,e){return r.map(t=>u.isUrl(t)||t.startsWith("/")?t:`${e}${t}`)}function A(r){return/\.css$/.test(r)}function k(r){return/\.js$/.test(r)}function ne(r){return/\.json$/.test(r)}function Ce(r){return r.map(e=>`<script src="${u.url.append(e,{v:P})}"><\/script>`).join("")}function Pe(r=[]){return r.map(e=>`<link rel="stylesheet" href="${u.url.append(e,{v:P})}" />`).join("")}function re(r,e){const t=r.filter(d=>!!d.enabled),n=[],s=[],o=[],a=[],i={},l={},c=[],h={};return t.forEach(({urls:d,assetsUrl:f,library:p,assetsLibrary:g,localeLibrary:v})=>{d?.forEach(y=>{k(y)&&n.push(y),A(y)&&s.push(y)}),p&&(a.push(p),i[p]=R(d||[],e),v&&(l[p]=v)),f&&o.push(f),g&&c.push(g),p&&g&&(h[g]=p)}),{scripts:R(n,e),css:R(s,e),materials:R(o,e),libraryExports:a,materialExports:u.dedupArray(c),materialMapLibrary:h,libraryMap:i,libraryLocaleMap:l}}function se(r,e){const{name:t,parent:n,alias:s}=r;return n?e[n]?.[s||t]:e[s||t]}function J(r){return u.isString(r)?r:JSON.stringify(r)}function L(r,e,t){const n=r.CSSStyleSheet;if(n.prototype.replaceSync){const s=new n;s.id=e,s.replaceSync(t);const o=r.document,a=o.adoptedStyleSheets,i=Array.from(a).filter(l=>l.id!==e);o.adoptedStyleSheets=[...i,s]}else{const s=r.document;let o=s.getElementById(e);o?o.innerHTML=t:(o=s.createElement("style"),o.id=e,o.innerHTML=t,s.head.appendChild(o))}}async function oe(r,e){const t=await window.fetch(e).then(n=>n.text()).catch(()=>"");t&&L(window,r,t)}function ie(r,e=window){const t=e.document,n=e.document.head;for(const s of r)if(!t.getElementById(s)){const a=t.createElement("link");a.rel="stylesheet",a.id=s,a.href=s,n.appendChild(a)}}async function ae(r,e,t=window){const n=t.document,s=t.document.head;let o=t[e];return o?o.default||o:new Promise((a,i)=>{for(const l of r){const c=n.createElement("script");c.src=l,c.onload=()=>{o=t[e],o?a(o.default||o):i(null)},c.onerror=h=>{i(h)},s.appendChild(c)}})}function ce(r){return u.isFunction(r)||u.isFunction(r?.install)}function b(r,e,t=!1,n=!1){try{const s=['"use strict";',"var __self = arguments[0];"];s.push("return ");let o=(r.value||"").trim();o=o.replace(/this(\W|$)/g,(i,l)=>`__self${l}`),o=s.join(`
7
+ */const P="0.8.130";var w=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(w||{});const U=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],Ee=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],ee=["vIf","vShow","vModel","vFor","vBind"],te={String,Number,Boolean,Array,Object,Function,Date};function R(r,e){return r.map(t=>u.isUrl(t)||t.startsWith("/")?t:`${e}${t}`)}function A(r){return/\.css$/.test(r)}function k(r){return/\.js$/.test(r)}function ne(r){return/\.json$/.test(r)}function Ce(r){return r.map(e=>`<script src="${u.url.append(e,{v:P})}"><\/script>`).join("")}function Pe(r=[]){return r.map(e=>`<link rel="stylesheet" href="${u.url.append(e,{v:P})}" />`).join("")}function re(r,e){const t=r.filter(d=>!!d.enabled),n=[],s=[],o=[],a=[],i={},l={},c=[],h={};return t.forEach(({urls:d,assetsUrl:f,library:p,assetsLibrary:g,localeLibrary:v})=>{d?.forEach(y=>{k(y)&&n.push(y),A(y)&&s.push(y)}),p&&(a.push(p),i[p]=R(d||[],e),v&&(l[p]=v)),f&&o.push(f),g&&c.push(g),p&&g&&(h[g]=p)}),{scripts:R(n,e),css:R(s,e),materials:R(o,e),libraryExports:a,materialExports:u.dedupArray(c),materialMapLibrary:h,libraryMap:i,libraryLocaleMap:l}}function se(r,e){const{name:t,parent:n,alias:s}=r;return n?e[n]?.[s||t]:e[s||t]}function J(r){return u.isString(r)?r:JSON.stringify(r)}function L(r,e,t){const n=r.CSSStyleSheet;if(n.prototype.replaceSync){const s=new n;s.id=e,s.replaceSync(t);const o=r.document,a=o.adoptedStyleSheets,i=Array.from(a).filter(l=>l.id!==e);o.adoptedStyleSheets=[...i,s]}else{const s=r.document;let o=s.getElementById(e);o?o.innerHTML=t:(o=s.createElement("style"),o.id=e,o.innerHTML=t,s.head.appendChild(o))}}async function oe(r,e){const t=await window.fetch(e).then(n=>n.text()).catch(()=>"");t&&L(window,r,t)}function ie(r,e=window){const t=e.document,n=e.document.head;for(const s of r)if(!t.getElementById(s)){const a=t.createElement("link");a.rel="stylesheet",a.id=s,a.href=s,n.appendChild(a)}}async function ae(r,e,t=window){const n=t.document,s=t.document.head;let o=t[e];return o?o.default||o:new Promise((a,i)=>{for(const l of r){const c=n.createElement("script");c.src=l,c.onload=()=>{o=t[e],o?a(o.default||o):i(null)},c.onerror=h=>{i(h)},s.appendChild(c)}})}function ce(r){return u.isFunction(r)||u.isFunction(r?.install)}function b(r,e,t=!1,n=!1){try{const s=['"use strict";',"var __self = arguments[0];"];s.push("return ");let o=(r.value||"").trim();o=o.replace(/this(\W|$)/g,(i,l)=>`__self${l}`),o=s.join(`
8
8
  `)+o;const a=`with(${t?"{}":"$scope || {}"}) { ${o} }`;return new Function("$scope",a)(e)}catch(s){if(u.logger.error("parseExpression.error",s,r,e?.__self??e),n)throw s}}function q(r,e,t=!1,n=!1){const s=b(r,e,t,n);if(typeof s!="function"&&(u.logger.error("parseFunction.error","not a function",r,e?.__self??e),n))throw new Error(`"${r.value}" not a function`);return s}function S(r){return r&&r.type==="JSExpression"}function M(r){return typeof r=="object"&&r&&r.type==="JSFunction"}function le(r){return S(r)||M(r)}function be(r){return le(r)?r.value:JSON.stringify(r)}let C=null;const Re=u.createRequest({settings:{type:"form",validSuccess:!0,originResponse:!1,loading:!0,validate:r=>r.data?.code===0||!!r.data?.success,failMessage:!0,showError:r=>{F.ElNotification.error({message:r||"未知错误"})},showLoading:()=>{C&&C.close(),C=F.ElLoading.service({lock:!0,text:"Loading",background:"rgba(0, 0, 0, 0.05)"})},hideLoading:()=>{C&&(C.close(),C=null)}}});function ue(r,e){const{jsonp:t,request:n}=e;if(r.method==="jsonp")return(s={})=>t(r.url,{...r.jsonpOptions,query:s});{const s=r.headers?b(r.headers,{},!0):void 0,o={url:r.url,method:r.method,settings:{...r.settings,headers:s}};return(a,i)=>n.send(u.merge(o,i||{},{data:a}))}}function de(r,e){const{metaQuery:t}=e;if(!t)return;const{code:n,queryCode:s}=r;return(o,a)=>{if(!t){console.warn("adapter.metaQuery is not defined!");return}return t(n,s,o,a)}}function fe(r=[],e=[],t){const n={};for(const s of r)n[s.id]=ue(s,t);for(const s of e)n[s.id]=de(s,t);return n}function pe(r=[]){T.setup({timeout:"50-500"}),V(),r.forEach(e=>me(e))}function me(r){if(!r.mock)return;const{url:e,mockTemplate:t}=r;if(e&&t){const n=u.pathToRegexp(`${e}(.*)`),s=u.pathToRegexpMatch(e,{decode:decodeURIComponent}),o=b(t,{},!0);T.mock(n,a=>{const i=u.url.parse(a.url)||{},l=a.body instanceof FormData?u.formDataToJson(a.body):a.body,c=s(a.url)?.params;return Object.assign(a,{data:l,params:i,query:c}),T.mock(o(a))})}}function V(){T._mocked={}}class he{__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:n,attrs:s}=e;this.__mode=t,n&&(this.__id=n.id||null,this.__transform=n.transform||{}),s&&Object.assign(this,s)}setup(e,t=D){const n=t.getCurrentInstance();if(!n)return;this.__refs={},this.$refs={},this.context={},this.__contextRefs={},this.__instance=n.proxy;const s=n.appContext.config.globalProperties;Object.assign(this,s),Object.assign(this,e||{}),this.__proxy(),t.onMounted(()=>{this.__proxy()}),t.onUnmounted(()=>{this.__cleanup()}),t.onBeforeUpdate(()=>{this.__refs={},this.$refs={},this.__contextRefs={},this.context={}})}__proxy(){this.__instance&&U.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){U.forEach(e=>{this[e]=null})}__parseFunction(e){if(e)if(this.__mode===w.Runtime){const{id:t,type:n}=e,s=t?this.__transform[t]??e.value:e.value;return q({type:n,value:s},this)}else return q(e,this)}__parseExpression(e){if(e)if(this.__mode===w.Runtime){const{id:t,type:n}=e,s=t?this.__transform[t]??e.value:e.value;return b({type:n,value:s},this)}else return b(e,this)}__ref(e=null,t){if(this.__mode!==w.VNode)return e&&e!==this.__id&&(this.__contextRefs[e]=this),async n=>{await u.delay(0);let s=n?.$vtjEl||n?.$el||n?._?.vnode?.el||n;if(!s){typeof t=="string"&&(delete this.$refs[t],e&&delete this.__refs[e]);return}if(s.nodeType===3&&s.nextSibling&&(s=s.nextSibling),s.__vtj__=e,w.Design===this.__mode&&(s.__context__=this),e&&(this.__refs[e]=n),typeof t=="function")t(n);else if(t){const o=this.$refs[t];if(o){const a=new Set([].concat(o,n));this.$refs[t]=Array.from(a)}else this.$refs[t]=n}return n}}__clone(e={}){const t={...this.context,...e},n={...t,context:t};return n.context.__proto__=this.context,n.__proto__=this,n}}function x(r){const{Vue:e=D,mode:t=w.Runtime,components:n={},libs:s={},apis:o={},loader:a}=r,i=e.computed(()=>r.dsl),l={$components:n,$libs:s,$apis:o},c=new he({mode:t,dsl:i.value,attrs:l}),h=e.defineComponent({name:i.value.name,props:{...Ie(i.value.props??[],c)},setup(d){c.$props=d,c.props=d,i.value.id&&L(r.window||window,i.value.id,i.value.css||""),c.state=Me(e,i.value.state??{},c);const f=Oe(e,i.value.computed??{},c),p=Te(i.value.methods??{},c),g=xe(e,i.value.inject,c),v=ve(i.value.dataSources||{},c),y={...g,...f,...p,...v};return c.setup(y,e),He(e,i.value.watch??[],c),{vtj:c}},emits:Fe(i.value.emits),expose:["vtj"],render(){if(!i.value.nodes)return null;const d=i.value.nodes||[];return d.length===1?I(d[0],c,e,a):d.map(f=>I(f,c,e,a))},...De(i.value.lifeCycles??{},c)});return{renderer:e.markRaw(h),context:c}}function Fe(r=[]){return r.map(e=>u.isString(e)?e:e.name)}function Ie(r=[],e){const t=n=>n?(Array.isArray(n)?n:[n]).map(o=>te[o]):void 0;return r.map(n=>u.isString(n)?{name:n}:{name:n.name,type:n.type,required:n.required,default:S(n.default)?e.__parseExpression(n.default):n.default}).reduce((n,s)=>(n[s.name]={type:t(s.type),required:s.required,default:s.default},n),{})}function Me(r,e,t){return r.reactive(Object.keys(e||{}).reduce((n,s)=>{let o=e[s];return S(o)?o=t.__parseExpression(o):M(o)&&(o=t.__parseFunction(o)),n[s]=o,n},{}))}function Oe(r,e,t){return Object.entries(e??{}).reduce((n,[s,o])=>(n[s]=r.computed(t.__parseFunction(o)),n),{})}function Te(r,e){return Object.entries(r??{}).reduce((t,[n,s])=>(t[n]=e.__parseFunction(s),t),{})}function xe(r,e=[],t){return e.reduce((n,s)=>{const{name:o,from:a}=s||{};s.default;const i=S(a)?t.__parseExpression(a)||o:a??o,l=S(s.default)?t.__parseExpression(s.default):s.default??null;return n[o]=r.inject(i,l),n},{})}function ve(r,e){return Object.keys(r).reduce((t,n)=>{const s=r[n],o=e.$apis[s.ref],a=M(s.transform)?s.transform.value?e.__parseFunction(s.transform):void 0:s.transform;return t[n]=async(...i)=>{const l=await o.apply(e,i);return a?a(l):l},t},{})}function He(r,e=[],t){e.forEach(n=>{r.watch(t.__parseExpression(n.source),t.__parseFunction(n.handler),{deep:n.deep,immediate:n.immediate})})}function De(r,e){return Object.entries(r??{}).reduce((t,[n,s])=>(t[n]=e.__parseFunction(s),t),{})}let N=[];const ge=r=>r;async function W(r,e=window){const{urls:t=[],library:n}=r,s=t.filter(i=>k(i));if(s.length===0||!n)return null;const o=t.filter(i=>A(i));return o.length&&ie(o,e),await ae(s,n,e).catch(i=>(console.warn("loadScriptUrl error",s,n,i),null))}function H(r){const{getDsl:e,getDslByUrl:t,options:n}=r;return n.window&&(N.forEach(s=>{delete n.window[s]}),N=[]),(s,o,a=D)=>!o||typeof o=="string"?s:o.type==="Schema"&&o.id?a.defineAsyncComponent(async()=>{const i=await e(o.id);return i&&(i.name=s),i?x({...n,Vue:a,dsl:i,mode:w.Runtime,loader:H(r)}).renderer:null}):o.type==="UrlSchema"&&o.url?a.defineAsyncComponent(async()=>{const i=await t(o.url);return i&&(i.name=s),i?x({...n,Vue:a,dsl:i,mode:w.Runtime,loader:H(r)}).renderer:null}):o.type==="Plugin"?(o.library&&N.push(o.library),a.defineAsyncComponent(async()=>{const i=await W(o,n.window);return i||(console.warn("getPlugin result is null",o),null)})):s}function I(r,e,t=D,n=ge){if(!r||!r.name||r.invisible)return null;const{id:s=null,directives:o=[]}=r,{vIf:a,vFor:i,vShow:l,vModels:c,vBind:h}=Ae(o);if(a&&!ke(a,e))return null;const d=f=>{const p=f.$components,g=(()=>{if(r.name==="component")return Be(f,r.props?.is);if(r.name==="slot")return r.name;const E=n(r.name,r.from,t);return u.isString(E)?p[E]??E:E})(),v=Ne(s,r.props??{},f),y=Ue(t,r.events??{},f);if(r.name==="slot")return qe(t,r,v,f,n);h&&Object.assign(v,f.__parseExpression(h.value)),l&&(v.style=Object.assign(v.style??{},Le(l,f))),c.forEach(E=>{Object.assign(v,Ve(t,E,f))});const j=We(t,r.children??[],f,n,r);return t.createVNode(g,{...v,...y},j)};return i?Xe(i,d,e):d(e)}function Ae(r=[]){const e=r.find(i=>u.camelCase(i.name)==="vIf"),t=r.find(i=>u.camelCase(i.name)==="vFor"),n=r.find(i=>u.camelCase(i.name)==="vShow"),s=r.find(i=>u.camelCase(i.name)==="vBind"),o=r.filter(i=>u.camelCase(i.name)==="vModel"),a=r.filter(i=>!ee.includes(u.camelCase(i.name)));return{vIf:e,vFor:t,vShow:n,vModels:o,vBind:s,others:a}}function ke(r,e){return!!e.__parseExpression(r.value)}function Be(r,e){return e?S(e)?r.__parseExpression(e):e:"div"}function Ne(r,e,t){const n=Object.keys(e||{}).reduce((s,o)=>{let a=e[o];return S(a)?a=t.__parseExpression(a):M(a)&&(a=t.__parseFunction(a)),s[o]=a,s},{});return n.ref=t.__ref(r,n.ref),n}function Ue(r,e,t){const n=["passive","capture","once"],s={capture:"Capture",once:"Once",passive:"OnceCapture"};return Object.keys(e||{}).reduce((o,a)=>{const i=e[a],l=Y(i.modifiers),c=l.find(f=>n.includes(f)),h="on"+u.upperFirst(a)+(c&&s[c]||""),d=t.__parseFunction(i.handler);return d&&(o[h]=r.withModifiers(d,l)),o},{})}function Y(r={},e=!1){const t=Object.keys(r);return e?t.map(n=>"."+n):t}function qe(r,e,t,n,s){const{children:o}=e,a=Je(e,n),i=n.$slots?.[a.name];return i?i(t):o?u.isString(o)?r.createTextVNode(o):S(o)?r.createTextVNode(J(n.__parseExpression(o))):Array.isArray(o)?o.map(l=>I(l,n,r,s)):null:null}function Je(r,e){const{props:t}=r,n=t?.name||"default";return{name:S(n)?e.__parseExpression(n):n,params:[]}}function Le(r,e){return e.__parseExpression(r.value)?{}:{display:"none"}}function Ve(r,e,t){const n={type:"JSFunction",value:e.value?.value?`(v) => {
9
9
  ${e.value.value} = v;
10
10
  }`:"(v) => {}"},s=t.__parseFunction(n),o=Y(e.modifiers),a=S(e.arg)?t.__parseExpression(e.arg):e.arg||"modelValue";return{[a]:t.__parseExpression(e.value),[`onUpdate:${a}`]:o.length&&s?r.withModifiers(s,o):s}}function We(r,e,t,n,s){if(!e)return null;if(u.isString(e))return{default:()=>e};if(S(e))return{default:()=>J(t.__parseExpression(e))};if(Array.isArray(e)&&e.length>0){const o=Ye(e),a=i=>!i||!s?{}:s?.id&&Object.keys(i).length?{[`scope_${s.id}`]:i}:{};return Object.entries(o).reduce((i,[l,{nodes:c,params:h}])=>(i[l]=d=>{const f=h.length?u.pick(d??{},h):a(d);return c.map(p=>I(p,t.__clone(f),r,n))},i),{})}return null}function Ye(r){const e={default:{params:[],nodes:[]}};for(const t of r){const n=Ke(t.slot),s=n.name;e[s]?(e[s].nodes.push(t),e[s].params=e[s].params.concat(n.params)):e[s]={nodes:[t],params:n.params}}return e}function Ke(r="default"){return u.isString(r)?{name:r,params:[]}:{params:[],...r}}function Xe(r,e,t){const{value:n,iterator:s}=r,{item:o="item",index:a="index"}=s||{};let i=t.__parseExpression(n)||[];return Number.isInteger(i)&&(i=new Array(i).fill(!0).map((l,c)=>c+1)),Array.isArray(i)?i.map((l,c)=>e(t.__clone({[o]:l,[a]:c}))):(console.warn("[vForRender]:",`${n?.value} is not a Arrary`),[])}function ze(r){return m.getCurrentScope()?(m.onScopeDispose(r),!0):!1}function K(r){return typeof r=="function"?r():m.unref(r)}const ye=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Ge=r=>r!=null,Qe=()=>{};function Ze(r){return m.getCurrentInstance()}function et(...r){if(r.length!==1)return m.toRef(...r);const e=r[0];return typeof e=="function"?m.readonly(m.customRef(()=>({get:e,set:Qe}))):m.ref(e)}function tt(r,e){Ze()&&m.onBeforeUnmount(r,e)}function nt(r){var e;const t=K(r);return(e=t?.$el)!=null?e:t}const rt=ye?window:void 0,st=ye?window.document:void 0;function ot(){const r=m.ref(!1),e=m.getCurrentInstance();return e&&m.onMounted(()=>{r.value=!0},e),r}function it(r){const e=ot();return m.computed(()=>(e.value,!!r()))}function at(r,e,t={}){const{window:n=rt,...s}=t;let o;const a=it(()=>n&&"MutationObserver"in n),i=()=>{o&&(o.disconnect(),o=void 0)},l=m.computed(()=>{const f=K(r),p=(Array.isArray(f)?f:[f]).map(nt).filter(Ge);return new Set(p)}),c=m.watch(()=>l.value,f=>{i(),a.value&&f.size&&(o=new MutationObserver(e),f.forEach(p=>o.observe(p,s)))},{immediate:!0,flush:"post"}),h=()=>o?.takeRecords(),d=()=>{c(),i()};return ze(d),{isSupported:a,stop:d,takeRecords:h}}function ct(r=null,e={}){var t,n,s;const{document:o=st,restoreOnUnmount:a=d=>d}=e,i=(t=o?.title)!=null?t:"",l=et((n=r??o?.title)!=null?n:null),c=r&&typeof r=="function";function h(d){if(!("titleTemplate"in e))return d;const f=e.titleTemplate||"%s";return typeof f=="function"?f(d):K(f).replace(/%s/g,d)}return m.watch(l,(d,f)=>{d!==f&&o&&(o.title=h(typeof d=="string"?d:""))},{immediate:!0}),e.observe&&!e.titleTemplate&&o&&!c&&at((s=o.head)==null?void 0:s.querySelector("title"),()=>{o&&o.title!==l.value&&(l.value=h(o.title))},{childList:!0}),tt(()=>{if(a){const d=a(i,l.value||"");d!=null&&o&&(o.title=d)}}),l}const Q=m.defineComponent({name:"VtjPageContainer",async setup(){const r=z(),e=Z.useRoute(),t=e.params.id,n=t?r.getPage(t):r.getHomepage(),s=n?await r.getRenderComponent(n.id):null;return n&&ct(n.title||"VTJ"),{provider:r,component:s,file:n,query:e.query}},render(){return this.component?m.h(this.component,this.query):m.h("div","页面不存在")}}),lt=m.defineComponent({name:"VtjStartupContainer",render(){return m.h(je.XStartup)}}),X=Symbol("Provider");class _e extends $.Base{constructor(e){super(),this.options=e;const{service:t,mode:n=w.Raw,dependencies:s,materials:o,project:a={},adapter:i={},globals:l={},modules:c={},router:h=null,materialPath:d="./",nodeEnv:f="development"}=e;this.mode=n,this.modules=c,this.service=t,this.router=h,this.materialPath=d,this.nodeEnv=f,s&&(this.dependencies=s),o&&(this.materials=o),Object.assign(this.globals,l),Object.assign(this.adapter,i),n!==w.Design&&this.load(a)}mode;globals={};modules={};adapter={request:Re,jsonp:u.jsonp};apis={};dependencies={};materials={};library={};service;project=null;components={};nodeEnv="development";router=null;materialPath="./";urlDslCaches={};async load(e){const t=this.modules[`.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:n=[],meta:s=[]}=this.project,o=window;o.CKEDITOR_VERSION=void 0,this.nodeEnv!=="production"?await this.loadAssets(o):await this.loadDependencies(o),this.apis=fe(n,s,this.adapter),V(),this.project.config?.mock&&pe(n),this.initRouter(),this.triggerReady()}async loadDependencies(e){const t=Object.entries(this.dependencies);for(const[n,s]of t)e[n]||(e[n]=await s())}async loadAssets(e){const{dependencies:t=[]}=this.project,{dependencies:n,library:s,components:o,materialPath:a}=this,{libraryExports:i,libraryMap:l,materials:c,materialExports:h,materialMapLibrary:d}=re(t,a);for(const p of i){const g=n[p],v=e[p];if(v)s[p]=v;else if(g)e[p]=s[p]=await g();else{const y=l[p]||[];for(const j of y)A(j)&&await oe(p,u.url.append(j,{v:P})),k(j)&&await u.loadScript(u.url.append(j,{v:P}));s[p]=e[p]}}for(const p of c)await u.loadScript(u.url.append(p,{v:P}));const f=this.materials||{};for(const p of h){const g=e[d[p]],v=$.BUILT_IN_COMPONENTS[p];if(v)g&&v.forEach(y=>{o[y]=g[y]});else{const y=f[p]?(await f[p]()).default:e[p];y&&g&&(y.components||[]).forEach(j=>{o[j.name]=se(j,g)})}}}initRouter(){const{router:e,project:t}=this;e&&(e.addRoute({path:"/page/:id",name:"VtjPage",component:Q}),e.addRoute({path:"/",name:"VtjHomepage",component:t?.homepage?Q:lt}))}install(e){const t=e.config.globalProperties.installed||{};for(const[n,s]of Object.entries(this.library))!t[n]&&ce(s)&&(e.use(s),t[n]=!0);this.options.install&&e.use(this.options.install),e.provide(X,this),e.config.globalProperties.installed=t,this.nodeEnv==="development"&&(e.config.errorHandler=(n,s,o)=>{const a=s?.$options.name,i=n?.message||n?.msg||"未知错误",l=`[ ${a} ] ${i}`;console.error("[VTJ Error]:",{err:n,instance:s,info:o},n?.stack),F.ElNotification.error({title:"运行时错误:请在控制台查看详情",message:l})})}getFile(e){const{blocks:t=[]}=this.project||{};return this.getPage(e)||t.find(n=>n.id===e)||null}getPage(e){const{pages:t=[]}=this.project||{},n=(s,o=[])=>{for(const a of o){if(a.id===s)return a;if(a.children&&a.children.length){const i=n(s,a.children);if(i)return i}}};return n(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`];return t?await t():this.service.getFile(e).catch(()=>null)}async getDslByUrl(e){const t=this.urlDslCaches[e];return t||(this.urlDslCaches[e]=this.adapter.request.send({url:e,method:"get",settings:{validSuccess:!1,originResponse:!0}}).then(n=>n.data).catch(()=>null))}createDslRenderer(e,t={}){const{library:n,components:s,mode:o,apis:a}=this,i={mode:o,Vue:n.Vue,components:s,libs:n,apis:a,window,...t},l=H({getDsl:async c=>await this.getDsl(c)||null,getDslByUrl:async c=>await this.getDslByUrl(c)||null,options:i});return x({...i,dsl:e,loader:l})}async getRenderComponent(e){const t=this.getFile(e);if(!t)return u.logger.warn(`Can not find file: ${e}`),null;const n=`.vtj/vue/${e}.vue`,s=this.modules[n];if(s)return(await s())?.default;const o=await this.getDsl(t.id);return o?this.createDslRenderer(o).renderer:(u.logger.warn(`Can not find dsl: ${e}`),null)}defineUrlSchemaComponent(e,t){return m.defineAsyncComponent(async()=>{const n=await this.getDslByUrl(e);return n?(n.name=t||n.name,this.createDslRenderer(n).renderer):null})}definePluginComponent(e){return m.defineAsyncComponent(async()=>await W(e,window))}}function ut(r){const e=new _e(r);return{provider:e,onReady:n=>e.ready(n)}}function z(r={}){const e=m.inject(X);if(!e)throw new Error("Can not find provider");if(e.nodeEnv==="development"){const{id:t,version:n}=r;t&&n&&(async()=>{const s=await e.getDsl(t);s?.__VERSION__!==n&&F.ElNotification.warning({title:s?.name,message:"当前组件源码版本与运行时版本不一致,请重新发布组件"})})()}return e}const G=new u.Request({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:r=>r.data?.code===0,showError:r=>{F.ElNotification.error({message:r||"未知错误"})}}}),dt=(r="/vtj/local/repository/:type.json")=>(e,t)=>G.send({url:r,method:"post",params:{type:e},data:{type:e,data:t}}),ft=(r="/vtj/local/repository/uploader.json")=>async(e,t)=>await G.send({url:r,method:"post",data:{files:e,projectId:t},settings:{type:"data"}}).then(n=>n&&n[0]?n[0]:null).catch(()=>null);class B{api;pluginCaches={};uploader;constructor(){this.api=dt(),this.uploader=ft()}async getExtension(){console.log("BaseService.getExtension")}async init(e){return console.log("BaseService.init",e),{}}async saveProject(e){return!!await this.api("saveProject",e).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,n=t.filter(o=>ne(o))[0];if(!n)return null;const s=this.pluginCaches[n];return s||(this.pluginCaches[n]=G.send({url:n,method:"get",settings:{validSuccess:!1,originResponse:!0}}).then(o=>o.data).catch(()=>null))}}const _=new u.Storage({type:"local",expired:0,prefix:"__VTJ_"});class pt extends B{init(e){const t=new $.ProjectModel(e),n=_.get(`project_${t.id}`),s=Object.assign(t.toDsl(),n||{});return _.save(`project_${t.id}`,s),Promise.resolve(s)}saveProject(e){const t=new $.ProjectModel(e);return _.save(`project_${t.id}`,t.toDsl()),Promise.resolve(!0)}saveMaterials(e,t){return _.save(`materials_${e.id}`,u.mapToObject(t)),Promise.resolve(!0)}saveFile(e){return _.save(`file_${e.id}`,e),Promise.resolve(!0)}getFile(e){const t=_.get(`file_${e}`);return t?Promise.resolve(t):Promise.reject(null)}removeFile(e){return _.remove(`file_${e}`),Promise.resolve(!0)}saveHistory(e){return _.save(`history_${e.id}`,e),Promise.resolve(!0)}removeHistory(e){const t=_.get(`history_${e}`);if(t){const s=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,s),_.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=_.get(`history_${e}`),n=new $.HistoryModel(t||{id:e});return Promise.resolve(n.toDsl())}getHistoryItem(e,t){const n=_.get(`history_${e}_${t}`);return Promise.resolve(n)}saveHistoryItem(e,t){return _.save(`history_${e}_${t.id}`,t),Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(n=>{_.remove(`history_${e}_${n}`)}),Promise.resolve(!0)}}class Se extends B{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new $.ProjectModel(e),n=this.projects[t.id]||{},s=Object.assign(t.toDsl(),n);return this.projects[s.id]=s,Promise.resolve(s)}saveProject(e){const t=new $.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=u.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 s=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,s),delete this.historyItems[e]}return Promise.resolve(!0)}getHistory(e){const t=this.histories[e],n=new $.HistoryModel(t||{id:e});return Promise.resolve(n)}getHistoryItem(e,t){const n=`${e}_${t}`,s=this.historyItems[n]||{};return Promise.resolve(s)}saveHistoryItem(e,t){const n=`${e}_${t.id}`;return this.historyItems[n]=t,Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(n=>{const s=`${e}_${n}`;delete this.historyItems[s]}),Promise.resolve(!0)}}let O=null;function mt(){return O||(O=new Se,O)}class ht 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){return!!await this.api("saveProject",e).catch(()=>!1)}async saveMaterials(e,t){return!!await this.api("saveMaterials",{project:e,materials:u.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 we(r=[]){return r.map(e=>{const{id:t,title:n,icon:s,children:o,hidden:a}=e;return{id:t,title:n,icon:s,hidden:a,url:`/page/${t}`,children:o&&o.length?we(o):void 0}})}function vt(){const r=z(),e=Z.useRoute(),t=m.ref(!1),n=r.project;m.watchEffect(()=>{const{name:a,params:i,meta:l}=e;if(a==="VtjPage"){const c=r.getPage(i.id);t.value=!c?.mask}else if(a==="VtjHomepage"){const c=r.getHomepage();t.value=!c?.mask}else t.value=!l.mask});const s=we(n?.pages),o=n?.config;return{disabled:t,logo:o?.logo,themeSwitchable:o?.themeSwitchable,title:o?.title||n?.description||n?.name||"VTJ App",menus:s}}exports.BUILT_IN_DIRECTIVES=ee;exports.BaseService=B;exports.CONTEXT_HOST=U;exports.Context=he;exports.ContextMode=w;exports.DATA_TYPES=te;exports.JSCodeToString=be;exports.LIFE_CYCLES_LIST=Ee;exports.LocalService=ht;exports.MemoryService=Se;exports.Provider=_e;exports.StorageService=pt;exports.VTJ_RENDERER_VERSION=P;exports.adoptedStyleSheets=L;exports.createAssetScripts=Ce;exports.createAssetsCss=Pe;exports.createDataSources=ve;exports.createLoader=H;exports.createMemoryService=mt;exports.createMetaApi=de;exports.createProvider=ut;exports.createRenderer=x;exports.createSchemaApi=ue;exports.createSchemaApis=fe;exports.defaultLoader=ge;exports.fillBasePath=R;exports.getModifiers=Y;exports.getPlugin=W;exports.getRawComponent=se;exports.isCSSUrl=A;exports.isJSCode=le;exports.isJSExpression=S;exports.isJSFunction=M;exports.isJSON=ne;exports.isJSUrl=k;exports.isVuePlugin=ce;exports.loadCss=oe;exports.loadCssUrl=ie;exports.loadScriptUrl=ae;exports.mockApi=me;exports.mockApis=pe;exports.mockCleanup=V;exports.nodeRender=I;exports.parseDeps=re;exports.parseExpression=b;exports.parseFunction=q;exports.providerKey=X;exports.toString=J;exports.useMask=vt;exports.useProvider=z;
package/dist/index.mjs CHANGED
@@ -10,10 +10,10 @@ import { XStartup as Ne } from "@vtj/ui";
10
10
  * Copyright (c) 2024, VTJ.PRO All rights reserved.
11
11
  * @name @vtj/renderer
12
12
  * @author CHC chenhuachun1549@dingtalk.com
13
- * @version 0.8.129
13
+ * @version 0.8.130
14
14
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
15
15
  */
16
- const P = "0.8.129";
16
+ const P = "0.8.130";
17
17
  var _ = /* @__PURE__ */ ((r) => (r.Runtime = "Runtime", r.Design = "Design", r.Raw = "Raw", r.VNode = "VNode", r))(_ || {});
18
18
  const Y = [
19
19
  "$el",
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@vtj/renderer",
3
3
  "private": false,
4
- "version": "0.8.129",
4
+ "version": "0.8.130",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "mockjs": "~1.1.0",
8
- "@vtj/core": "~0.8.129",
9
- "@vtj/icons": "~0.8.129",
10
- "@vtj/ui": "~0.8.129",
11
- "@vtj/utils": "~0.8.129"
8
+ "@vtj/utils": "~0.8.130",
9
+ "@vtj/core": "~0.8.130",
10
+ "@vtj/ui": "~0.8.130",
11
+ "@vtj/icons": "~0.8.130"
12
12
  },
13
13
  "devDependencies": {
14
14
  "vue": "~3.4.15",
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2024, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/renderer
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.8.128
5
+ * @version 0.8.129
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.8.128";
8
+ export declare const version = "0.8.129";