@vtj/renderer 0.7.9 → 0.7.10

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.7.9
5
+ * @version 0.7.10
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const b="0.7.9";var w=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(w||{});const B=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],_e=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],Q=["vIf","vShow","vModel","vFor","vBind"],Z={String,Number,Boolean,Array,Object,Function,Date};function C(r,e){return r.map(t=>u.isUrl(t)?t:`${e}${t}`)}function A(r){return/\.css$/.test(r)}function k(r){return/\.js$/.test(r)}function ye(r){return r.map(e=>`<script src="${u.url.append(e,{v:b})}"><\/script>`).join("")}function Se(r=[]){return r.map(e=>`<link rel="stylesheet" href="${u.url.append(e,{v:b})}" />`).join("")}function ee(r,e){const t=r.filter(v=>!!v.enabled),s=[],n=[],o=[],i=[],a={},l=[],c={};return t.forEach(({urls:v,assetsUrl:m,library:p,assetsLibrary:g})=>{v?.forEach(y=>{k(y)&&s.push(y),A(y)&&n.push(y)}),p&&(i.push(p),a[p]=C(v||[],e)),m&&o.push(m),g&&l.push(g),p&&g&&(c[g]=p)}),{scripts:C(s,e),css:C(n,e),materials:C(o,e),libraryExports:i,materialExports:l,materialMapLibrary:c,libraryMap:a}}function te(r,e){const{name:t,parent:s,alias:n}=r;return s?e[s]?.[n||t]:e[n||t]}function J(r){return u.isString(r)?r:JSON.stringify(r)}function q(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,i=o.adoptedStyleSheets,a=Array.from(i).filter(l=>l.id!==e);o.adoptedStyleSheets=[...a,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 re(r,e){const t=await window.fetch(e).then(s=>s.text()).catch(()=>"");t&&q(window,r,t)}function se(r){return u.isFunction(r)||u.isFunction(r?.install)}var M=function(){return M=Object.assign||function(r){for(var e,t=1,s=arguments.length;t<s;t++){e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r},M.apply(this,arguments)},L={debug:-1,log:0,info:0,warn:1,error:2},we=function(r,e,t,s){return function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];if(e&&L[e]<=L[r]&&console[r].apply&&(s==="*"||t.startsWith(s)))return console[r].apply(console,je(n,t))}};function je(r,e){return e!=="*"&&(typeof r[0]=="string"?r[0]="["+e+"] "+r[0]:r=["["+e+"]"].concat(r)),r}function $e(r,e){if(!r)return{targetLevel:e.level,targetBizName:e.bizName};if(~r.indexOf(":")){var t=r.split(":");return{targetLevel:t[0],targetBizName:t[1]}}return{targetLevel:r,targetBizName:"*"}}var Pe={level:"warn",bizName:"*"},ne=function(){function r(e){e=M(M({},Pe),e);var t=location||{},s=(/__(?:logConf|logLevel)__=([^#/&]*)/.exec(t.href)||[])[1],n=$e(s,e),o=n.targetLevel,i=n.targetBizName;for(var a in L)this[a]=we(a,o,e.bizName,i)}return r}();function oe(r){return new ne(r)}const R=oe({level:"log",bizName:"VTJ"});function x(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,(a,l)=>`__self${l}`),o=n.join(`
7
+ */const b="0.7.10";var w=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(w||{});const B=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],_e=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],Q=["vIf","vShow","vModel","vFor","vBind"],Z={String,Number,Boolean,Array,Object,Function,Date};function C(r,e){return r.map(t=>u.isUrl(t)?t:`${e}${t}`)}function A(r){return/\.css$/.test(r)}function k(r){return/\.js$/.test(r)}function ye(r){return r.map(e=>`<script src="${u.url.append(e,{v:b})}"><\/script>`).join("")}function Se(r=[]){return r.map(e=>`<link rel="stylesheet" href="${u.url.append(e,{v:b})}" />`).join("")}function ee(r,e){const t=r.filter(v=>!!v.enabled),s=[],n=[],o=[],i=[],a={},l=[],c={};return t.forEach(({urls:v,assetsUrl:m,library:p,assetsLibrary:g})=>{v?.forEach(y=>{k(y)&&s.push(y),A(y)&&n.push(y)}),p&&(i.push(p),a[p]=C(v||[],e)),m&&o.push(m),g&&l.push(g),p&&g&&(c[g]=p)}),{scripts:C(s,e),css:C(n,e),materials:C(o,e),libraryExports:i,materialExports:l,materialMapLibrary:c,libraryMap:a}}function te(r,e){const{name:t,parent:s,alias:n}=r;return s?e[s]?.[n||t]:e[n||t]}function J(r){return u.isString(r)?r:JSON.stringify(r)}function q(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,i=o.adoptedStyleSheets,a=Array.from(i).filter(l=>l.id!==e);o.adoptedStyleSheets=[...a,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 re(r,e){const t=await window.fetch(e).then(s=>s.text()).catch(()=>"");t&&q(window,r,t)}function se(r){return u.isFunction(r)||u.isFunction(r?.install)}var M=function(){return M=Object.assign||function(r){for(var e,t=1,s=arguments.length;t<s;t++){e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r},M.apply(this,arguments)},L={debug:-1,log:0,info:0,warn:1,error:2},we=function(r,e,t,s){return function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];if(e&&L[e]<=L[r]&&console[r].apply&&(s==="*"||t.startsWith(s)))return console[r].apply(console,je(n,t))}};function je(r,e){return e!=="*"&&(typeof r[0]=="string"?r[0]="["+e+"] "+r[0]:r=["["+e+"]"].concat(r)),r}function $e(r,e){if(!r)return{targetLevel:e.level,targetBizName:e.bizName};if(~r.indexOf(":")){var t=r.split(":");return{targetLevel:t[0],targetBizName:t[1]}}return{targetLevel:r,targetBizName:"*"}}var Pe={level:"warn",bizName:"*"},ne=function(){function r(e){e=M(M({},Pe),e);var t=location||{},s=(/__(?:logConf|logLevel)__=([^#/&]*)/.exec(t.href)||[])[1],n=$e(s,e),o=n.targetLevel,i=n.targetBizName;for(var a in L)this[a]=we(a,o,e.bizName,i)}return r}();function oe(r){return new ne(r)}const R=oe({level:"log",bizName:"VTJ"});function x(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,(a,l)=>`__self${l}`),o=n.join(`
8
8
  `)+o;const i=`with(${t?"{}":"$scope || {}"}) { ${o} }`;return new Function("$scope",i)(e)}catch(n){if(R.error("parseExpression.error",n,r,e?.__self??e),s)throw n}}function V(r,e,t=!1,s=!1){const n=x(r,e,t,s);if(typeof n!="function"&&(R.error("parseFunction.error","not a function",r,e?.__self??e),s))throw new Error(`"${r.value}" not a function`);return n}function _(r){return r&&r.type==="JSExpression"}function H(r){return typeof r=="object"&&r&&r.type==="JSFunction"}function ie(r){return _(r)||H(r)}function Ee(r){return ie(r)?r.value:JSON.stringify(r)}let E=null;const be=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:()=>{E&&E.close(),E=F.ElLoading.service({lock:!0,text:"Loading",background:"rgba(0, 0, 0, 0.05)"})},hideLoading:()=>{E&&(E.close(),E=null)}}});function ae(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?x(r.headers,{},!0):void 0,o={url:r.url,method:r.method,settings:{...r.settings,headers:n}};return(i,a)=>s.send(u.merge(o,a||{},{data:i}))}}function ce(r=[],e){return r.reduce((t,s)=>(t[s.id]=ae(s,e),t),{})}class le{__id=null;__mode;__instance=null;__contextRefs={};__refs={};context={};state={};$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=N){const s=t.getCurrentInstance();if(!s)return;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()})}__proxy(){this.__instance&&B.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){B.forEach(e=>{this[e]=null})}__parseFunction(e){if(e)if(this.__mode===w.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return V({type:s,value:n},this)}else return V(e,this)}__parseExpression(e){if(e)if(this.__mode===w.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return x({type:s,value:n},this)}else return x(e,this)}__ref(e=null,t){if(this.__mode!==w.VNode)return e&&e!==this.__id&&(this.__contextRefs[e]=this),s=>{let n=s?.$vtjEl||s?.$el||s;if(!n){typeof t=="string"&&(delete this.$refs[t],e&&delete this.__refs[e]);return}if(n.__vtj__=e,n.nodeType===3&&n.nextSibling&&(n=n.nextSibling),w.Design===this.__mode&&(n.__context__=this),e&&(this.__refs[e]=s),typeof t=="function")t(s);else if(t){const o=this.$refs[t];if(o){const i=new Set([].concat(o,s));this.$refs[t]=Array.from(i)}else this.$refs[t]=s}return s}}__clone(e={}){const t={...this.context,...e},s={...t,context:t};return s.context.__proto__=this.context,s.__proto__=this,s}}function U(r){const{Vue:e=N,mode:t=w.Runtime,components:s={},libs:n={},apis:o={},loader:i}=r,a=e.computed(()=>r.dsl),l={$components:s,$libs:n,$apis:o},c=new le({mode:t,dsl:a.value,attrs:l}),v=e.defineComponent({name:a.value.name,props:{...Ce(a.value.props??[],c)},setup(m){c.$props=m,a.value.id&&q(r.window||window,a.value.id,a.value.css||""),c.state=Fe(e,a.value.state??{},c);const p=Re(e,a.value.computed??{},c),g=xe(a.value.methods??{},c),y=Ie(e,a.value.inject,c),f=ue(a.value.dataSources||{},c),j={...y,...p,...g,...f};return c.setup(j,e),He(e,a.value.watch??[],c),{vtj:c}},emits:[...a.value.emits??[]],expose:["vtj"],render(){if(!a.value.nodes)return null;const m=a.value.nodes||[];return m.length===1?I(m[0],c,e,i):m.map(p=>I(p,c,e,i))},...Oe(a.value.lifeCycles??{},c)});return{renderer:e.markRaw(v),context:c}}function Ce(r=[],e){const t=s=>s?(Array.isArray(s)?s:[s]).map(o=>Z[o]):void 0;return r.map(s=>u.isString(s)?{name:s}:{name:s.name,type:s.type,required:s.required,default:_(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 Fe(r,e,t){return r.reactive(Object.keys(e||{}).reduce((s,n)=>{let o=e[n];return _(o)?o=t.__parseExpression(o):H(o)&&(o=t.__parseFunction(o)),s[n]=o,s},{}))}function Re(r,e,t){return Object.entries(e??{}).reduce((s,[n,o])=>(s[n]=r.computed(t.__parseFunction(o)),s),{})}function xe(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}function Ie(r,e=[],t){return e.reduce((s,n)=>{const{name:o,from:i}=n||{};n.default;const a=_(i)?t.__parseExpression(i)||o:i??o,l=_(n.default)?t.__parseExpression(n.default):n.default??null;return s[o]=r.inject(a,l),s},{})}function ue(r,e){return Object.keys(r).reduce((t,s)=>{const n=r[s],o=e.$apis[n.ref],i=H(n.transform)?n.transform.value?e.__parseFunction(n.transform):void 0:n.transform;return t[s]=async(...a)=>{const l=await o.apply(e,a);return i?i(l):l},t},{})}function He(r,e=[],t){e.forEach(s=>{r.watch(t.__parseExpression(s.source),t.__parseFunction(s.handler),{deep:s.deep,immediate:s.immediate})})}function Oe(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}const pe=r=>r;function z(r){const{getDsl:e,options:t}=r;return(s,n,o=N)=>!n||typeof n=="string"?s:n.type==="Schema"?o.defineAsyncComponent(async()=>{const i=await e(n.id);return i?U({...t,Vue:o,dsl:i,mode:w.Runtime,loader:z(r)}).renderer:null}):s}function I(r,e,t=N,s=pe){if(!r||!r.name||r.invisible)return null;const{id:n=null,directives:o=[]}=r,{vIf:i,vFor:a,vShow:l,vModels:c,vBind:v}=Te(o);if(i&&!Me(i,e))return null;const m=p=>{const g=p.$components,y=(()=>{if(r.name==="component")return Ne(p,r.props?.is);if(r.name==="slot")return r.name;const S=s(r.name,r.from,t);return u.isString(S)?g[S]??S:S})(),f=De(n,r.props??{},p),j=Be(t,r.events??{},p);if(r.name==="slot")return Le(t,r,f,p);v&&Object.assign(f,p.__parseExpression(v.value)),l&&(f.style=Object.assign(f.style??{},Ae(l,p))),c.forEach(S=>{Object.assign(f,ke(t,S,p))});const $=Je(t,r.children??[],p,r);return t.createVNode(y,{...f,...j},$)};return a?ze(a,m,e):m(e)}function Te(r=[]){const e=r.find(a=>u.camelCase(a.name)==="vIf"),t=r.find(a=>u.camelCase(a.name)==="vFor"),s=r.find(a=>u.camelCase(a.name)==="vShow"),n=r.find(a=>u.camelCase(a.name)==="vBind"),o=r.filter(a=>u.camelCase(a.name)==="vModel"),i=r.filter(a=>!Q.includes(u.camelCase(a.name)));return{vIf:e,vFor:t,vShow:s,vModels:o,vBind:n,others:i}}function Me(r,e){return!!e.__parseExpression(r.value)}function Ne(r,e){return e?_(e)?r.__parseExpression(e):e:"div"}function De(r,e,t){const s=Object.keys(e||{}).reduce((n,o)=>{let i=e[o];return _(i)?i=t.__parseExpression(i):H(i)&&(i=t.__parseFunction(i)),n[o]=i,n},{});return s.ref=t.__ref(r,s.ref),s}function Be(r,e,t){const s=["passive","capture","once"],n={capture:"Capture",once:"Once",passive:"OnceCapture"};return Object.keys(e||{}).reduce((o,i)=>{const a=e[i],l=K(a.modifiers),c=l.find(p=>s.includes(p)),v="on"+u.upperFirst(i)+(c&&n[c]||""),m=t.__parseFunction(a.handler);return m&&(o[v]=r.withModifiers(m,l)),o},{})}function K(r={},e=!1){const t=Object.keys(r);return e?t.map(s=>"."+s):t}function Le(r,e,t,s){const{children:n}=e,o=Ve(e,s),i=s.$slots?.[o.name];return i?i(t):n?u.isString(n)?r.createTextVNode(n):_(n)?r.createTextVNode(J(s.__parseExpression(n))):Array.isArray(n)?n.map(a=>I(a,s,r)):null:null}function Ve(r,e){const{props:t}=r,s=t?.name||"default";return{name:_(s)?e.__parseExpression(s):s,params:[]}}function Ae(r,e){return e.__parseExpression(r.value)?{}:{display:"none"}}function ke(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=K(e.modifiers),i=_(e.arg)?t.__parseExpression(e.arg):e.arg||"modelValue";return{[i]:t.__parseExpression(e.value),[`onUpdate:${i}`]:o.length&&n?r.withModifiers(n,o):n}}function Je(r,e,t,s){if(!e)return null;if(u.isString(e))return{default:()=>e};if(_(e))return{default:()=>J(t.__parseExpression(e))};if(Array.isArray(e)){const n=qe(e),o=i=>!i||!s?{}:s?.id&&Object.keys(i).length?{[`scope_${s.id}`]:i}:{};return Object.entries(n).reduce((i,[a,{nodes:l,params:c}])=>(i[a]=v=>{const m=c.length?u.pick(v??{},c):o(v);return l.map(p=>I(p,t.__clone(m),r))},i),{})}}function qe(r){const e={default:{params:[],nodes:[]}};for(const t of r){const s=Ue(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 Ue(r="default"){return u.isString(r)?{name:r,params:[]}:{params:[],...r}}function ze(r,e,t){const{value:s,iterator:n}=r,{item:o="item",index:i="index"}=n||{};let a=t.__parseExpression(s)||[];return Number.isInteger(a)&&(a=new Array(a).fill(!0).map((l,c)=>c+1)),Array.isArray(a)?a.map((l,c)=>e(t.__clone({[o]:l,[i]:c}))):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const X=d.defineComponent({name:"VtjPageContainer",async setup(){const r=W(),e=G.useRoute(),t=e.params.id,s=t?r.getPage(t):r.getHomepage(),n=s?await r.getRenderComponent(s.id):null;return s&&ve.useTitle(s.title||"VTJ"),{provider:r,component:n,file:s,query:e.query}},render(){return this.component?d.h(this.component,this.query):d.h("div","页面不存在")}}),Ke={name:{type:String,default:"VTJ.PRO"},tagline:{type:String,default:"基于 Vue3 + TypeScript 快速打造高生产力的低代码研发平台"},actionText:{type:String,default:"开始设计"},actionLink:{type:String,default:"/@vtj/pro/"}},Ye={class:"x-startup"},We={class:"x-startup__wrapper"},Xe={class:"x-startup__name"},Ge={class:"clip"},Qe={class:"x-startup__tagline"},Ze={class:"x-startup__actions"},et=d.defineComponent({__name:"Startup",props:Ke,setup(r){const e=r,t=()=>{let s=(window.__VTJ_LINK__||{}).href||window.location.pathname+"@vtj/pro/#/";location.href=s};return(s,n)=>(d.openBlock(),d.createElementBlock("div",Ye,[d.createElementVNode("div",We,[d.createElementVNode("div",Xe,[d.createElementVNode("span",Ge,d.toDisplayString(e.name),1)]),d.createElementVNode("div",Qe,d.toDisplayString(e.tagline),1),d.createElementVNode("div",Ze,[d.createVNode(d.unref(F.ElButton),{type:"primary",size:"large",round:"",icon:d.unref(he.EditPen),onClick:t},{default:d.withCtx(()=>[d.createTextVNode(d.toDisplayString(e.actionText),1)]),_:1},8,["icon"])])])]))}}),tt=d.defineComponent({name:"VtjStartupContainer",render(){return d.h(et)}}),Y=Symbol("Provider");class fe extends P.Base{mode;globals={};modules={};adapter={request:be,jsonp:u.jsonp};apis={};dependencies={};materials={};library={};service;project=null;components={};router=null;materialPath="./";constructor(e){super();const{service:t,mode:s=w.Raw,dependencies:n,materials:o,project:i={},adapter:a={},globals:l={},modules:c={},router:v=null,materialPath:m="./"}=e;this.mode=s,this.modules=c,this.service=t,this.router=v,this.materialPath=m,n&&(this.dependencies=n),o&&(this.materials=o),Object.assign(this.globals,l),Object.assign(this.adapter,a),s!==w.Design&&this.load(i)}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:s=[],apis:n}=this.project,{dependencies:o,library:i,components:a,materialPath:l}=this,{libraryExports:c,libraryMap:v,materials:m,materialExports:p,materialMapLibrary:g}=ee(s,l);for(const f of c){const j=o[f],$=window[f];if($)i[f]=$;else if(j)window[f]=i[f]=await j();else{const S=v[f]||[];for(const O of S)A(O)&&await re(f,u.url.append(O,{v:b})),k(O)&&await u.loadScript(u.url.append(O,{v:b})),i[f]=window[f]}}for(const f of m)await u.loadScript(u.url.append(f,{v:b}));const y=this.materials||{};for(const f of p){const j=y[f]?(await y[f]()).default:window[f],$=window[g[f]];j&&$&&j.components.forEach(S=>{a[S.name]=te(S,$)})}n&&(this.apis=ce(n,this.adapter)),this.initRouter(),this.triggerReady()}initRouter(){const{router:e,project:t}=this;e&&(e.addRoute({path:"/page/:id",name:"VtjPage",component:X}),e.addRoute({path:"/",name:"VtjHomepage",component:t?.homepage?X:tt}))}install(e){const t=e.config.globalProperties.installed||{};for(const[s,n]of Object.entries(this.library))!t[s]&&se(n)&&(e.use(n),t[s]=!0);e.provide(Y,this),e.config.globalProperties.installed=t}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 i of o){if(i.id===n)return i;if(i.children&&i.children.length){const a=s(n,i.children);if(a)return a}}};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`];return t?await t():this.service.getFile(e).catch(()=>null)}async getRenderComponent(e){const t=this.getFile(e);if(!t)return R.warn(`Can not find file: ${e}`),null;const s=`.vtj/vue/${e}.vue`,n=this.modules[s];if(n)return(await n())?.default;const o=await this.getDsl(t.id);if(!o)return R.warn(`Can not find dsl: ${e}`),null;const{library:i,components:a,mode:l,apis:c}=this,v={mode:l,Vue:i.Vue,components:a,libs:i,apis:c,window},m=z({getDsl:async g=>await this.getDsl(g)||null,options:v}),{renderer:p}=U({...v,dsl:o,loader:m});return p}}function rt(r){const e=new fe(r);return{provider:e,onReady:s=>e.ready(s)}}function W(r={}){const e=d.inject(Y);if(!e)throw new Error("Can not find provider");if(e.mode===w.Raw){const{id:t,version:s}=r;t&&s&&(async()=>{const n=await e.getDsl(t);n?.__VERSION__!==s&&F.ElNotification.warning({title:n?.name,message:"当前组件源码版本与运行时版本不一致,请重新发布组件"})})()}return e}const st=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||"未知错误"})}}}),nt=(r="/vtj/local/repository/${type}.json")=>(e,t)=>st.send({url:r,method:"post",query:{type:e},data:{type:e,data:t}});class D{api;constructor(){this.api=nt()}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(()=>"")}}const h=new u.Storage({type:"local",expired:0,prefix:"__VTJ_"});class ot extends D{init(e){const t=new P.ProjectModel(e),s=h.get(`project_${t.id}`),n=Object.assign(t.toDsl(),s||{});return h.save(`project_${t.id}`,n),Promise.resolve(n)}saveProject(e){const t=new P.ProjectModel(e);return h.save(`project_${t.id}`,t.toDsl()),Promise.resolve(!0)}saveMaterials(e,t){return h.save(`materials_${e.id}`,u.mapToObject(t)),Promise.resolve(!0)}saveFile(e){return h.save(`file_${e.id}`,e),Promise.resolve(!0)}getFile(e){const t=h.get(`file_${e}`);return t?Promise.resolve(t):Promise.reject(null)}removeFile(e){return h.remove(`file_${e}`),Promise.resolve(!0)}saveHistory(e){return h.save(`history_${e.id}`,e),Promise.resolve(!0)}removeHistory(e){const t=h.get(`history_${e}`);if(t){const n=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,n),h.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=h.get(`history_${e}`),s=new P.HistoryModel(t||{id:e});return Promise.resolve(s.toDsl())}getHistoryItem(e,t){const s=h.get(`history_${e}_${t}`);return Promise.resolve(s)}saveHistoryItem(e,t){return h.save(`history_${e}_${t.id}`,t),Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{h.remove(`history_${e}_${s}`)}),Promise.resolve(!0)}}class de extends D{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]=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 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 T=null;function it(){return T||(T=new de,T)}class at extends D{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){return await this.api("getFile",e).catch(()=>null)||{}}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 me(r=[]){return r.map(e=>{const{id:t,title:s,icon:n,children:o,hidden:i}=e;return{id:t,title:s,icon:n,hidden:i,url:`/page/${t}`,children:o&&o.length?me(o):void 0}})}function ct(){const r=W(),e=G.useRoute(),t=d.ref(!1),s=r.project;d.watchEffect(()=>{const{name:o,params:i,meta:a}=e;if(o==="VtjPage"){const l=r.getPage(i.id);t.value=!l?.mask}else if(o==="VtjHomepage"){const l=r.getHomepage();t.value=!l?.mask}else t.value=!a.mask});const n=me(s?.pages);return{disabled:t,title:s?.description||s?.name||"VTJ App",menus:n}}exports.BUILDIN_DIRECTIVES=Q;exports.BaseService=D;exports.CONTEXT_HOST=B;exports.Context=le;exports.ContextMode=w;exports.DATA_TYPES=Z;exports.JSCodeToString=Ee;exports.LIFE_CYCLES_LIST=_e;exports.LocalService=at;exports.Logger=ne;exports.MemoryService=de;exports.Provider=fe;exports.StorageService=ot;exports.VTJ_RENDERER_VERSION=b;exports.adoptedStyleSheets=q;exports.createAssetScripts=ye;exports.createAssetsCss=Se;exports.createDataSources=ue;exports.createLoader=z;exports.createMemoryService=it;exports.createProvider=rt;exports.createRenderer=U;exports.createSchemaApi=ae;exports.createSchemaApis=ce;exports.defaultLoader=pe;exports.fillBasePath=C;exports.getLogger=oe;exports.getModifiers=K;exports.getRawComponent=te;exports.isCSSUrl=A;exports.isJSCode=ie;exports.isJSExpression=_;exports.isJSFunction=H;exports.isJSUrl=k;exports.isVuePlugin=se;exports.loadCss=re;exports.logger=R;exports.nodeRender=I;exports.parseDeps=ee;exports.parseExpression=x;exports.parseFunction=V;exports.providerKey=Y;exports.toString=J;exports.useMask=ct;exports.useProvider=W;
package/dist/index.mjs CHANGED
@@ -10,10 +10,10 @@ import { EditPen as He } from "@vtj/icons";
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.7.9
13
+ * @version 0.7.10
14
14
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
15
15
  */
16
- const F = "0.7.9";
16
+ const F = "0.7.10";
17
17
  var y = /* @__PURE__ */ ((r) => (r.Runtime = "Runtime", r.Design = "Design", r.Raw = "Raw", r.VNode = "VNode", r))(y || {});
18
18
  const W = [
19
19
  "$el",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/renderer",
3
3
  "private": false,
4
- "version": "0.7.9",
4
+ "version": "0.7.10",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "vue-tsc && vite build",
@@ -10,10 +10,10 @@
10
10
  "coverage": "vitest run --coverage"
11
11
  },
12
12
  "dependencies": {
13
- "@vtj/core": "^0.7.9",
14
- "@vtj/icons": "^0.7.9",
15
- "@vtj/ui": "^0.7.9",
16
- "@vtj/utils": "^0.7.9",
13
+ "@vtj/core": "^0.7.10",
14
+ "@vtj/icons": "^0.7.10",
15
+ "@vtj/ui": "^0.7.10",
16
+ "@vtj/utils": "^0.7.10",
17
17
  "zen-logger": "~1.1.4"
18
18
  },
19
19
  "devDependencies": {
@@ -35,7 +35,7 @@
35
35
  "dist",
36
36
  "types"
37
37
  ],
38
- "gitHead": "923aab791b5aacf1f0e75255ad7aa2b1b71e26bf",
38
+ "gitHead": "6c54f72d57ad363d1ed75a36f25aed10d6b6a262",
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  }
@@ -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.7.8
5
+ * @version 0.7.9
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.7.8";
8
+ export declare const version = "0.7.9";