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