@vtj/renderer 0.7.29 → 0.7.30

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.29
5
+ * @version 0.7.30
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const C="0.7.29";var j=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(j||{});const N=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],fe=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],W=["vIf","vShow","vModel","vFor","vBind"],X={String,Number,Boolean,Array,Object,Function,Date};function I(r,e){return r.map(t=>c.isUrl(t)?t:`${e}${t}`)}function A(r){return/\.css$/.test(r)}function V(r){return/\.js$/.test(r)}function me(r){return r.map(e=>`<script src="${c.url.append(e,{v:C})}"><\/script>`).join("")}function he(r=[]){return r.map(e=>`<link rel="stylesheet" href="${c.url.append(e,{v:C})}" />`).join("")}function G(r,e){const t=r.filter(h=>!!h.enabled),s=[],n=[],o=[],i=[],a={},u=[],l={};return t.forEach(({urls:h,assetsUrl:m,library:p,assetsLibrary:g})=>{h?.forEach(S=>{V(S)&&s.push(S),A(S)&&n.push(S)}),p&&(i.push(p),a[p]=I(h||[],e)),m&&o.push(m),g&&u.push(g),p&&g&&(l[g]=p)}),{scripts:I(s,e),css:I(n,e),materials:I(o,e),libraryExports:i,materialExports:c.dedupArray(u),materialMapLibrary:l,libraryMap:a}}function Q(r,e){const{name:t,parent:s,alias:n}=r;return s?e[s]?.[n||t]:e[n||t]}function B(r){return c.isString(r)?r:JSON.stringify(r)}function k(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(u=>u.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 Z(r,e){const t=await window.fetch(e).then(s=>s.text()).catch(()=>"");t&&k(window,r,t)}function ee(r){return c.isFunction(r)||c.isFunction(r?.install)}function R(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,u)=>`__self${u}`),o=n.join(`
7
+ */const C="0.7.30";var j=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(j||{});const N=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],fe=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],W=["vIf","vShow","vModel","vFor","vBind"],X={String,Number,Boolean,Array,Object,Function,Date};function I(r,e){return r.map(t=>c.isUrl(t)?t:`${e}${t}`)}function A(r){return/\.css$/.test(r)}function V(r){return/\.js$/.test(r)}function me(r){return r.map(e=>`<script src="${c.url.append(e,{v:C})}"><\/script>`).join("")}function he(r=[]){return r.map(e=>`<link rel="stylesheet" href="${c.url.append(e,{v:C})}" />`).join("")}function G(r,e){const t=r.filter(h=>!!h.enabled),s=[],n=[],o=[],i=[],a={},u=[],l={};return t.forEach(({urls:h,assetsUrl:m,library:p,assetsLibrary:g})=>{h?.forEach(S=>{V(S)&&s.push(S),A(S)&&n.push(S)}),p&&(i.push(p),a[p]=I(h||[],e)),m&&o.push(m),g&&u.push(g),p&&g&&(l[g]=p)}),{scripts:I(s,e),css:I(n,e),materials:I(o,e),libraryExports:i,materialExports:c.dedupArray(u),materialMapLibrary:l,libraryMap:a}}function Q(r,e){const{name:t,parent:s,alias:n}=r;return s?e[s]?.[n||t]:e[n||t]}function B(r){return c.isString(r)?r:JSON.stringify(r)}function k(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(u=>u.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 Z(r,e){const t=await window.fetch(e).then(s=>s.text()).catch(()=>"");t&&k(window,r,t)}function ee(r){return c.isFunction(r)||c.isFunction(r?.install)}function R(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,u)=>`__self${u}`),o=n.join(`
8
8
  `)+o;const i=`with(${t?"{}":"$scope || {}"}) { ${o} }`;return new Function("$scope",i)(e)}catch(n){if(c.logger.error("parseExpression.error",n,r,e?.__self??e),s)throw n}}function D(r,e,t=!1,s=!1){const n=R(r,e,t,s);if(typeof n!="function"&&(c.logger.error("parseFunction.error","not a function",r,e?.__self??e),s))throw new Error(`"${r.value}" not a function`);return n}function y(r){return r&&r.type==="JSExpression"}function H(r){return typeof r=="object"&&r&&r.type==="JSFunction"}function te(r){return y(r)||H(r)}function ve(r){return te(r)?r.value:JSON.stringify(r)}let b=null;const _e=c.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:()=>{b&&b.close(),b=F.ElLoading.service({lock:!0,text:"Loading",background:"rgba(0, 0, 0, 0.05)"})},hideLoading:()=>{b&&(b.close(),b=null)}}});function re(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?R(r.headers,{},!0):void 0,o={url:r.url,method:r.method,settings:{...r.settings,headers:n}};return(i,a)=>s.send(c.merge(o,a||{},{data:i}))}}function se(r=[],e){return r.reduce((t,s)=>(t[s.id]=re(s,e),t),{})}class ne{__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=M){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&&N.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){N.forEach(e=>{this[e]=null})}__parseFunction(e){if(e)if(this.__mode===j.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return D({type:s,value:n},this)}else return D(e,this)}__parseExpression(e){if(e)if(this.__mode===j.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return R({type:s,value:n},this)}else return R(e,this)}__ref(e=null,t){if(this.__mode!==j.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),j.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 L(r){const{Vue:e=M,mode:t=j.Runtime,components:s={},libs:n={},apis:o={},loader:i}=r,a=e.computed(()=>r.dsl),u={$components:s,$libs:n,$apis:o},l=new ne({mode:t,dsl:a.value,attrs:u}),h=e.defineComponent({name:a.value.name,props:{...ge(a.value.props??[],l)},setup(m){l.$props=m,a.value.id&&k(r.window||window,a.value.id,a.value.css||""),l.state=ye(e,a.value.state??{},l);const p=Se(e,a.value.computed??{},l),g=we(a.value.methods??{},l),S=je(e,a.value.inject,l),d=oe(a.value.dataSources||{},l),w={...S,...p,...g,...d};return l.setup(w,e),$e(e,a.value.watch??[],l),{vtj:l}},emits:[...a.value.emits??[]],expose:["vtj"],render(){if(!a.value.nodes)return null;const m=a.value.nodes||[];return m.length===1?x(m[0],l,e,i):m.map(p=>x(p,l,e,i))},...Ee(a.value.lifeCycles??{},l)});return{renderer:e.markRaw(h),context:l}}function ge(r=[],e){const t=s=>s?(Array.isArray(s)?s:[s]).map(o=>X[o]):void 0;return r.map(s=>c.isString(s)?{name:s}:{name:s.name,type:s.type,required:s.required,default:y(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 ye(r,e,t){return r.reactive(Object.keys(e||{}).reduce((s,n)=>{let o=e[n];return y(o)?o=t.__parseExpression(o):H(o)&&(o=t.__parseFunction(o)),s[n]=o,s},{}))}function Se(r,e,t){return Object.entries(e??{}).reduce((s,[n,o])=>(s[n]=r.computed(t.__parseFunction(o)),s),{})}function we(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}function je(r,e=[],t){return e.reduce((s,n)=>{const{name:o,from:i}=n||{};n.default;const a=y(i)?t.__parseExpression(i)||o:i??o,u=y(n.default)?t.__parseExpression(n.default):n.default??null;return s[o]=r.inject(a,u),s},{})}function oe(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 u=await o.apply(e,a);return i?i(u):u},t},{})}function $e(r,e=[],t){e.forEach(s=>{r.watch(t.__parseExpression(s.source),t.__parseFunction(s.handler),{deep:s.deep,immediate:s.immediate})})}function Ee(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}const ie=r=>r;function q(r){const{getDsl:e,options:t}=r;return(s,n,o=M)=>!n||typeof n=="string"?s:n.type==="Schema"?o.defineAsyncComponent(async()=>{const i=await e(n.id);return i?L({...t,Vue:o,dsl:i,mode:j.Runtime,loader:q(r)}).renderer:null}):s}function x(r,e,t=M,s=ie){if(!r||!r.name||r.invisible)return null;const{id:n=null,directives:o=[]}=r,{vIf:i,vFor:a,vShow:u,vModels:l,vBind:h}=Pe(o);if(i&&!be(i,e))return null;const m=p=>{const g=p.$components,S=(()=>{if(r.name==="component")return Ce(p,r.props?.is);if(r.name==="slot")return r.name;const v=s(r.name,r.from,t);return c.isString(v)?g[v]??v:v})(),d=Ie(n,r.props??{},p),w=Fe(t,r.events??{},p);if(r.name==="slot")return Re(t,r,d,p);h&&Object.assign(d,p.__parseExpression(h.value)),u&&(d.style=Object.assign(d.style??{},He(u,p))),l.forEach(v=>{Object.assign(d,Te(t,v,p))});const E=Me(t,r.children??[],p,r);return t.createVNode(S,{...d,...w},E)};return a?De(a,m,e):m(e)}function Pe(r=[]){const e=r.find(a=>c.camelCase(a.name)==="vIf"),t=r.find(a=>c.camelCase(a.name)==="vFor"),s=r.find(a=>c.camelCase(a.name)==="vShow"),n=r.find(a=>c.camelCase(a.name)==="vBind"),o=r.filter(a=>c.camelCase(a.name)==="vModel"),i=r.filter(a=>!W.includes(c.camelCase(a.name)));return{vIf:e,vFor:t,vShow:s,vModels:o,vBind:n,others:i}}function be(r,e){return!!e.__parseExpression(r.value)}function Ce(r,e){return e?y(e)?r.__parseExpression(e):e:"div"}function Ie(r,e,t){const s=Object.keys(e||{}).reduce((n,o)=>{let i=e[o];return y(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 Fe(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],u=J(a.modifiers),l=u.find(p=>s.includes(p)),h="on"+c.upperFirst(i)+(l&&n[l]||""),m=t.__parseFunction(a.handler);return m&&(o[h]=r.withModifiers(m,u)),o},{})}function J(r={},e=!1){const t=Object.keys(r);return e?t.map(s=>"."+s):t}function Re(r,e,t,s){const{children:n}=e,o=xe(e,s),i=s.$slots?.[o.name];return i?i(t):n?c.isString(n)?r.createTextVNode(n):y(n)?r.createTextVNode(B(s.__parseExpression(n))):Array.isArray(n)?n.map(a=>x(a,s,r)):null:null}function xe(r,e){const{props:t}=r,s=t?.name||"default";return{name:y(s)?e.__parseExpression(s):s,params:[]}}function He(r,e){return e.__parseExpression(r.value)?{}:{display:"none"}}function Te(r,e,t){const s={type:"JSFunction",value:e.value?.value?`(v) => {
9
9
  ${e.value.value} = v;
10
- }`:"(v) => {}"},n=t.__parseFunction(s),o=J(e.modifiers),i=y(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 Me(r,e,t,s){if(!e)return null;if(c.isString(e))return{default:()=>e};if(y(e))return{default:()=>B(t.__parseExpression(e))};if(Array.isArray(e)&&e.length>0){const n=Oe(e),o=i=>!i||!s?{}:s?.id&&Object.keys(i).length?{[`scope_${s.id}`]:i}:{};return Object.entries(n).reduce((i,[a,{nodes:u,params:l}])=>(i[a]=h=>{const m=l.length?c.pick(h??{},l):o(h);return u.map(p=>x(p,t.__clone(m),r))},i),{})}return null}function Oe(r){const e={default:{params:[],nodes:[]}};for(const t of r){const s=Ne(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 Ne(r="default"){return c.isString(r)?{name:r,params:[]}:{params:[],...r}}function De(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((u,l)=>l+1)),Array.isArray(a)?a.map((u,l)=>e(t.__clone({[o]:u,[i]:l}))):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const z=f.defineComponent({name:"VtjPageContainer",async setup(){const r=Y(),e=K.useRoute(),t=e.params.id,s=t?r.getPage(t):r.getHomepage(),n=s?await r.getRenderComponent(s.id):null;return s&&ue.useTitle(s.title||"VTJ"),{provider:r,component:n,file:s,query:e.query}},render(){return this.component?f.h(this.component,this.query):f.h("div","页面不存在")}}),Ae={name:{type:String,default:"VTJ.PRO"},tagline:{type:String,default:"基于 Vue3 + TypeScript 快速打造高生产力的低代码研发平台"},actionText:{type:String,default:"开始设计"},actionLink:{type:String,default:"/@vtj/pro/"}},Ve={class:"x-startup"},Be={class:"x-startup__wrapper"},ke={class:"x-startup__name"},Le={class:"clip"},qe={class:"x-startup__tagline"},Je={class:"x-startup__actions"},Ue=f.defineComponent({__name:"Startup",props:Ae,setup(r){const e=r,t=()=>{if(typeof window<"u"){let s=(window.__VTJ_LINK__||{}).href||window.location.pathname+"@vtj/pro/#/";window.location.href=s}};return(s,n)=>(f.openBlock(),f.createElementBlock("div",Ve,[f.createElementVNode("div",Be,[f.createElementVNode("div",ke,[f.createElementVNode("span",Le,f.toDisplayString(e.name),1)]),f.createElementVNode("div",qe,f.toDisplayString(e.tagline),1),f.createElementVNode("div",Je,[f.createVNode(f.unref(F.ElButton),{type:"primary",size:"large",round:"",icon:f.unref(pe.EditPen),onClick:t},{default:f.withCtx(()=>[f.createTextVNode(f.toDisplayString(e.actionText),1)]),_:1},8,["icon"])])])]))}}),Ye=f.defineComponent({name:"VtjStartupContainer",render(){return f.h(Ue)}}),U=Symbol("Provider");class ae extends $.Base{mode;globals={};modules={};adapter={request:_e,jsonp:c.jsonp};apis={};dependencies={};materials={};library={};service;project=null;components={};router=null;materialPath="./";constructor(e){super();const{service:t,mode:s=j.Raw,dependencies:n,materials:o,project:i={},adapter:a={},globals:u={},modules:l={},router:h=null,materialPath:m="./"}=e;this.mode=s,this.modules=l,this.service=t,this.router=h,this.materialPath=m,n&&(this.dependencies=n),o&&(this.materials=o),Object.assign(this.globals,u),Object.assign(this.adapter,a),s!==j.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:u}=this,{libraryExports:l,libraryMap:h,materials:m,materialExports:p,materialMapLibrary:g}=G(s,u);for(const d of l){const w=o[d],E=window[d];if(E)i[d]=E;else if(w)window[d]=i[d]=await w();else{const v=h[d]||[];for(const P of v)A(P)&&await Z(d,c.url.append(P,{v:C})),V(P)&&await c.loadScript(c.url.append(P,{v:C})),i[d]=window[d]}}for(const d of m)await c.loadScript(c.url.append(d,{v:C}));const S=this.materials||{};for(const d of p){const w=window[g[d]],E=$.BUILT_IN_COMPONENTS[d];if(E)w&&E.forEach(v=>{a[v]=w[v]});else{const v=S[d]?(await S[d]()).default:window[d];v&&w&&(v.components||[]).forEach(P=>{a[P.name]=Q(P,w)})}}n&&(this.apis=se(n,this.adapter)),this.initRouter(),this.triggerReady()}initRouter(){const{router:e,project:t}=this;e&&(e.addRoute({path:"/page/:id",name:"VtjPage",component:z}),e.addRoute({path:"/",name:"VtjHomepage",component:t?.homepage?z:Ye}))}install(e){const t=e.config.globalProperties.installed||{};for(const[s,n]of Object.entries(this.library))!t[s]&&ee(n)&&(e.use(n),t[s]=!0);e.provide(U,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 c.logger.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 c.logger.warn(`Can not find dsl: ${e}`),null;const{library:i,components:a,mode:u,apis:l}=this,h={mode:u,Vue:i.Vue,components:a,libs:i,apis:l,window},m=q({getDsl:async g=>await this.getDsl(g)||null,options:h}),{renderer:p}=L({...h,dsl:o,loader:m});return p}}function ze(r){const e=new ae(r);return{provider:e,onReady:s=>e.ready(s)}}function Y(r={}){const e=f.inject(U);if(!e)throw new Error("Can not find provider");if(e.mode===j.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 Ke=new c.Request({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:r=>r.data?.code===0,showError:r=>{F.ElNotification.error({message:r||"未知错误"})}}}),We=(r="/vtj/local/repository/${type}.json")=>(e,t)=>Ke.send({url:r,method:"post",query:{type:e},data:{type:e,data:t}});class O{api;constructor(){this.api=We()}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 _=new c.Storage({type:"local",expired:0,prefix:"__VTJ_"});class Xe extends O{init(e){const t=new $.ProjectModel(e),s=_.get(`project_${t.id}`),n=Object.assign(t.toDsl(),s||{});return _.save(`project_${t.id}`,n),Promise.resolve(n)}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}`,c.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 n=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,n),_.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=_.get(`history_${e}`),s=new $.HistoryModel(t||{id:e});return Promise.resolve(s.toDsl())}getHistoryItem(e,t){const s=_.get(`history_${e}_${t}`);return Promise.resolve(s)}saveHistoryItem(e,t){return _.save(`history_${e}_${t.id}`,t),Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{_.remove(`history_${e}_${s}`)}),Promise.resolve(!0)}}class ce extends O{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new $.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 $.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=c.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 $.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 Ge(){return T||(T=new ce,T)}class Qe extends O{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:c.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 le(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?le(o):void 0}})}function Ze(){const r=Y(),e=K.useRoute(),t=f.ref(!1),s=r.project;f.watchEffect(()=>{const{name:o,params:i,meta:a}=e;if(o==="VtjPage"){const u=r.getPage(i.id);t.value=!u?.mask}else if(o==="VtjHomepage"){const u=r.getHomepage();t.value=!u?.mask}else t.value=!a.mask});const n=le(s?.pages);return{disabled:t,title:s?.description||s?.name||"VTJ App",menus:n}}exports.BUILT_IN_DIRECTIVES=W;exports.BaseService=O;exports.CONTEXT_HOST=N;exports.Context=ne;exports.ContextMode=j;exports.DATA_TYPES=X;exports.JSCodeToString=ve;exports.LIFE_CYCLES_LIST=fe;exports.LocalService=Qe;exports.MemoryService=ce;exports.Provider=ae;exports.StorageService=Xe;exports.VTJ_RENDERER_VERSION=C;exports.adoptedStyleSheets=k;exports.createAssetScripts=me;exports.createAssetsCss=he;exports.createDataSources=oe;exports.createLoader=q;exports.createMemoryService=Ge;exports.createProvider=ze;exports.createRenderer=L;exports.createSchemaApi=re;exports.createSchemaApis=se;exports.defaultLoader=ie;exports.fillBasePath=I;exports.getModifiers=J;exports.getRawComponent=Q;exports.isCSSUrl=A;exports.isJSCode=te;exports.isJSExpression=y;exports.isJSFunction=H;exports.isJSUrl=V;exports.isVuePlugin=ee;exports.loadCss=Z;exports.nodeRender=x;exports.parseDeps=G;exports.parseExpression=R;exports.parseFunction=D;exports.providerKey=U;exports.toString=B;exports.useMask=Ze;exports.useProvider=Y;
10
+ }`:"(v) => {}"},n=t.__parseFunction(s),o=J(e.modifiers),i=y(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 Me(r,e,t,s){if(!e)return null;if(c.isString(e))return{default:()=>e};if(y(e))return{default:()=>B(t.__parseExpression(e))};if(Array.isArray(e)&&e.length>0){const n=Oe(e),o=i=>!i||!s?{}:s?.id&&Object.keys(i).length?{[`scope_${s.id}`]:i}:{};return Object.entries(n).reduce((i,[a,{nodes:u,params:l}])=>(i[a]=h=>{const m=l.length?c.pick(h??{},l):o(h);return u.map(p=>x(p,t.__clone(m),r))},i),{})}return null}function Oe(r){const e={default:{params:[],nodes:[]}};for(const t of r){const s=Ne(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 Ne(r="default"){return c.isString(r)?{name:r,params:[]}:{params:[],...r}}function De(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((u,l)=>l+1)),Array.isArray(a)?a.map((u,l)=>e(t.__clone({[o]:u,[i]:l}))):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const z=f.defineComponent({name:"VtjPageContainer",async setup(){const r=Y(),e=K.useRoute(),t=e.params.id,s=t?r.getPage(t):r.getHomepage(),n=s?await r.getRenderComponent(s.id):null;return s&&ue.useTitle(s.title||"VTJ"),{provider:r,component:n,file:s,query:e.query}},render(){return this.component?f.h(this.component,this.query):f.h("div","页面不存在")}}),Ae={name:{type:String,default:"VTJ.PRO"},tagline:{type:String,default:"基于 Vue3 + TypeScript 快速打造高生产力的低代码研发平台"},actionText:{type:String,default:"开始设计"},actionLink:{type:String,default:"/@vtj/pro/"}},Ve={class:"x-startup"},Be={class:"x-startup__wrapper"},ke={class:"x-startup__name"},Le={class:"clip"},qe={class:"x-startup__tagline"},Je={class:"x-startup__actions"},Ue=f.defineComponent({__name:"Startup",props:Ae,setup(r){const e=r,t=()=>{if(typeof window<"u"){let s=(window.__VTJ_LINK__||{}).href||window.location.pathname+"@vtj/pro/#/";window.location.href=s}};return(s,n)=>(f.openBlock(),f.createElementBlock("div",Ve,[f.createElementVNode("div",Be,[f.createElementVNode("div",ke,[f.createElementVNode("span",Le,f.toDisplayString(e.name),1)]),f.createElementVNode("div",qe,f.toDisplayString(e.tagline),1),f.createElementVNode("div",Je,[f.createVNode(f.unref(F.ElButton),{type:"primary",size:"large",round:"",icon:f.unref(pe.EditPen),onClick:t},{default:f.withCtx(()=>[f.createTextVNode(f.toDisplayString(e.actionText),1)]),_:1},8,["icon"])])])]))}}),Ye=f.defineComponent({name:"VtjStartupContainer",render(){return f.h(Ue)}}),U=Symbol("Provider");class ae extends $.Base{mode;globals={};modules={};adapter={request:_e,jsonp:c.jsonp};apis={};dependencies={};materials={};library={};service;project=null;components={};nodeEnv="development";router=null;materialPath="./";constructor(e){super();const{service:t,mode:s=j.Raw,dependencies:n,materials:o,project:i={},adapter:a={},globals:u={},modules:l={},router:h=null,materialPath:m="./",nodeEnv:p="development"}=e;this.mode=s,this.modules=l,this.service=t,this.router=h,this.materialPath=m,this.nodeEnv=p,n&&(this.dependencies=n),o&&(this.materials=o),Object.assign(this.globals,u),Object.assign(this.adapter,a),s!==j.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:u}=this,{libraryExports:l,libraryMap:h,materials:m,materialExports:p,materialMapLibrary:g}=G(s,u);for(const d of l){const w=o[d],E=window[d];if(E)i[d]=E;else if(w)window[d]=i[d]=await w();else{const v=h[d]||[];for(const P of v)A(P)&&await Z(d,c.url.append(P,{v:C})),V(P)&&await c.loadScript(c.url.append(P,{v:C})),i[d]=window[d]}}for(const d of m)await c.loadScript(c.url.append(d,{v:C}));const S=this.materials||{};for(const d of p){const w=window[g[d]],E=$.BUILT_IN_COMPONENTS[d];if(E)w&&E.forEach(v=>{a[v]=w[v]});else{const v=S[d]?(await S[d]()).default:window[d];v&&w&&(v.components||[]).forEach(P=>{a[P.name]=Q(P,w)})}}n&&(this.apis=se(n,this.adapter)),this.initRouter(),this.triggerReady()}initRouter(){const{router:e,project:t}=this;e&&(e.addRoute({path:"/page/:id",name:"VtjPage",component:z}),e.addRoute({path:"/",name:"VtjHomepage",component:t?.homepage?z:Ye}))}install(e){const t=e.config.globalProperties.installed||{};for(const[s,n]of Object.entries(this.library))!t[s]&&ee(n)&&(e.use(n),t[s]=!0);e.provide(U,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 c.logger.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 c.logger.warn(`Can not find dsl: ${e}`),null;const{library:i,components:a,mode:u,apis:l}=this,h={mode:u,Vue:i.Vue,components:a,libs:i,apis:l,window},m=q({getDsl:async g=>await this.getDsl(g)||null,options:h}),{renderer:p}=L({...h,dsl:o,loader:m});return p}}function ze(r){const e=new ae(r);return{provider:e,onReady:s=>e.ready(s)}}function Y(r={}){const e=f.inject(U);if(!e)throw new Error("Can not find provider");if(e.mode===j.Raw&&e.nodeEnv==="development"){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 Ke=new c.Request({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:r=>r.data?.code===0,showError:r=>{F.ElNotification.error({message:r||"未知错误"})}}}),We=(r="/vtj/local/repository/${type}.json")=>(e,t)=>Ke.send({url:r,method:"post",query:{type:e},data:{type:e,data:t}});class O{api;constructor(){this.api=We()}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 _=new c.Storage({type:"local",expired:0,prefix:"__VTJ_"});class Xe extends O{init(e){const t=new $.ProjectModel(e),s=_.get(`project_${t.id}`),n=Object.assign(t.toDsl(),s||{});return _.save(`project_${t.id}`,n),Promise.resolve(n)}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}`,c.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 n=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,n),_.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=_.get(`history_${e}`),s=new $.HistoryModel(t||{id:e});return Promise.resolve(s.toDsl())}getHistoryItem(e,t){const s=_.get(`history_${e}_${t}`);return Promise.resolve(s)}saveHistoryItem(e,t){return _.save(`history_${e}_${t.id}`,t),Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{_.remove(`history_${e}_${s}`)}),Promise.resolve(!0)}}class ce extends O{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new $.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 $.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=c.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 $.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 Ge(){return T||(T=new ce,T)}class Qe extends O{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:c.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 le(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?le(o):void 0}})}function Ze(){const r=Y(),e=K.useRoute(),t=f.ref(!1),s=r.project;f.watchEffect(()=>{const{name:o,params:i,meta:a}=e;if(o==="VtjPage"){const u=r.getPage(i.id);t.value=!u?.mask}else if(o==="VtjHomepage"){const u=r.getHomepage();t.value=!u?.mask}else t.value=!a.mask});const n=le(s?.pages);return{disabled:t,title:s?.description||s?.name||"VTJ App",menus:n}}exports.BUILT_IN_DIRECTIVES=W;exports.BaseService=O;exports.CONTEXT_HOST=N;exports.Context=ne;exports.ContextMode=j;exports.DATA_TYPES=X;exports.JSCodeToString=ve;exports.LIFE_CYCLES_LIST=fe;exports.LocalService=Qe;exports.MemoryService=ce;exports.Provider=ae;exports.StorageService=Xe;exports.VTJ_RENDERER_VERSION=C;exports.adoptedStyleSheets=k;exports.createAssetScripts=me;exports.createAssetsCss=he;exports.createDataSources=oe;exports.createLoader=q;exports.createMemoryService=Ge;exports.createProvider=ze;exports.createRenderer=L;exports.createSchemaApi=re;exports.createSchemaApis=se;exports.defaultLoader=ie;exports.fillBasePath=I;exports.getModifiers=J;exports.getRawComponent=Q;exports.isCSSUrl=A;exports.isJSCode=te;exports.isJSExpression=y;exports.isJSFunction=H;exports.isJSUrl=V;exports.isVuePlugin=ee;exports.loadCss=Z;exports.nodeRender=x;exports.parseDeps=G;exports.parseExpression=R;exports.parseFunction=D;exports.providerKey=U;exports.toString=B;exports.useMask=Ze;exports.useProvider=Y;
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Base as ae, BUILT_IN_COMPONENTS as ce, ProjectModel as R, HistoryModel as Y } from "@vtj/core";
2
- import { isUrl as le, url as F, dedupArray as ue, isString as P, isFunction as L, logger as C, createRequest as pe, merge as fe, camelCase as j, upperFirst as me, pick as de, jsonp as he, loadScript as q, Request as ve, Storage as _e, mapToObject as A } from "@vtj/utils";
2
+ import { isUrl as le, url as F, dedupArray as ue, isString as P, isFunction as L, logger as C, createRequest as pe, merge as fe, camelCase as j, upperFirst as de, pick as me, jsonp as he, loadScript as q, Request as ve, Storage as _e, mapToObject as A } from "@vtj/utils";
3
3
  import * as M from "vue";
4
4
  import { defineComponent as D, h as k, openBlock as ye, createElementBlock as ge, createElementVNode as b, toDisplayString as B, createVNode as we, unref as U, withCtx as Se, createTextVNode as $e, inject as je, ref as Ee, watchEffect as Pe } from "vue";
5
5
  import { useRoute as G } from "vue-router";
@@ -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.29
13
+ * @version 0.7.30
14
14
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
15
15
  */
16
- const I = "0.7.29";
16
+ const I = "0.7.30";
17
17
  var w = /* @__PURE__ */ ((s) => (s.Runtime = "Runtime", s.Design = "Design", s.Raw = "Raw", s.VNode = "VNode", s))(w || {});
18
18
  const z = [
19
19
  "$el",
@@ -70,11 +70,11 @@ function Rt(s = []) {
70
70
  ).join("");
71
71
  }
72
72
  function Ce(s, e) {
73
- const t = s.filter((m) => !!m.enabled), r = [], n = [], o = [], i = [], a = {}, l = [], c = {};
74
- return t.forEach(({ urls: m, assetsUrl: f, library: u, assetsLibrary: v }) => {
75
- m?.forEach((_) => {
73
+ const t = s.filter((d) => !!d.enabled), r = [], n = [], o = [], i = [], a = {}, l = [], c = {};
74
+ return t.forEach(({ urls: d, assetsUrl: f, library: u, assetsLibrary: v }) => {
75
+ d?.forEach((_) => {
76
76
  Q(_) && r.push(_), X(_) && n.push(_);
77
- }), u && (i.push(u), a[u] = H(m || [], e)), f && o.push(f), v && l.push(v), u && v && (c[v] = u);
77
+ }), u && (i.push(u), a[u] = H(d || [], e)), f && o.push(f), v && l.push(v), u && v && (c[v] = u);
78
78
  }), {
79
79
  scripts: H(r, e),
80
80
  css: H(n, e),
@@ -310,7 +310,7 @@ function te(s) {
310
310
  mode: t,
311
311
  dsl: a.value,
312
312
  attrs: l
313
- }), m = e.defineComponent({
313
+ }), d = e.defineComponent({
314
314
  name: a.value.name,
315
315
  props: {
316
316
  ...Ve(a.value.props ?? [], c)
@@ -345,7 +345,7 @@ function te(s) {
345
345
  ...We(a.value.lifeCycles ?? {}, c)
346
346
  });
347
347
  return {
348
- renderer: e.markRaw(m),
348
+ renderer: e.markRaw(d),
349
349
  context: c
350
350
  };
351
351
  }
@@ -448,7 +448,7 @@ function re(s) {
448
448
  function T(s, e, t = M, r = Ye) {
449
449
  if (!s || !s.name || s.invisible)
450
450
  return null;
451
- const { id: n = null, directives: o = [] } = s, { vIf: i, vFor: a, vShow: l, vModels: c, vBind: m } = Ge(o);
451
+ const { id: n = null, directives: o = [] } = s, { vIf: i, vFor: a, vShow: l, vModels: c, vBind: d } = Ge(o);
452
452
  if (i && !Xe(i, e))
453
453
  return null;
454
454
  const f = (u) => {
@@ -457,16 +457,16 @@ function T(s, e, t = M, r = Ye) {
457
457
  return Qe(u, s.props?.is);
458
458
  if (s.name === "slot")
459
459
  return s.name;
460
- const d = r(s.name, s.from, t);
461
- return P(d) ? v[d] ?? d : d;
460
+ const m = r(s.name, s.from, t);
461
+ return P(m) ? v[m] ?? m : m;
462
462
  })(), p = Ze(n, s.props ?? {}, u), y = et(t, s.events ?? {}, u);
463
463
  if (s.name === "slot")
464
464
  return tt(t, s, p, u);
465
- m && Object.assign(p, u.__parseExpression(m.value)), l && (p.style = Object.assign(
465
+ d && Object.assign(p, u.__parseExpression(d.value)), l && (p.style = Object.assign(
466
466
  p.style ?? {},
467
467
  st(l, u)
468
- )), c.forEach((d) => {
469
- Object.assign(p, nt(t, d, u));
468
+ )), c.forEach((m) => {
469
+ Object.assign(p, nt(t, m, u));
470
470
  });
471
471
  const S = ot(t, s.children ?? [], u, s);
472
472
  return t.createVNode(_, { ...p, ...y }, S);
@@ -510,8 +510,8 @@ function et(s, e, t) {
510
510
  };
511
511
  return Object.keys(e || {}).reduce(
512
512
  (o, i) => {
513
- const a = e[i], l = se(a.modifiers), c = l.find((u) => r.includes(u)), m = "on" + me(i) + (c && n[c] || ""), f = t.__parseFunction(a.handler);
514
- return f && (o[m] = s.withModifiers(f, l)), o;
513
+ const a = e[i], l = se(a.modifiers), c = l.find((u) => r.includes(u)), d = "on" + de(i) + (c && n[c] || ""), f = t.__parseFunction(a.handler);
514
+ return f && (o[d] = s.withModifiers(f, l)), o;
515
515
  },
516
516
  {}
517
517
  );
@@ -563,8 +563,8 @@ function ot(s, e, t, r) {
563
563
  const n = it(e), o = (i) => !i || !r ? {} : r?.id && Object.keys(i).length ? {
564
564
  [`scope_${r.id}`]: i
565
565
  } : {};
566
- return Object.entries(n).reduce((i, [a, { nodes: l, params: c }]) => (i[a] = (m) => {
567
- const f = c.length ? de(m ?? {}, c) : o(m);
566
+ return Object.entries(n).reduce((i, [a, { nodes: l, params: c }]) => (i[a] = (d) => {
567
+ const f = c.length ? me(d ?? {}, c) : o(d);
568
568
  return l.map(
569
569
  (u) => T(u, t.__clone(f), s)
570
570
  );
@@ -627,7 +627,7 @@ const W = D({
627
627
  type: String,
628
628
  default: "/@vtj/pro/"
629
629
  }
630
- }, ut = { class: "x-startup" }, pt = { class: "x-startup__wrapper" }, ft = { class: "x-startup__name" }, mt = { class: "clip" }, dt = { class: "x-startup__tagline" }, ht = { class: "x-startup__actions" }, vt = /* @__PURE__ */ D({
630
+ }, ut = { class: "x-startup" }, pt = { class: "x-startup__wrapper" }, ft = { class: "x-startup__name" }, dt = { class: "clip" }, mt = { class: "x-startup__tagline" }, ht = { class: "x-startup__actions" }, vt = /* @__PURE__ */ D({
631
631
  __name: "Startup",
632
632
  props: lt,
633
633
  setup(s) {
@@ -640,9 +640,9 @@ const W = D({
640
640
  return (r, n) => (ye(), ge("div", ut, [
641
641
  b("div", pt, [
642
642
  b("div", ft, [
643
- b("span", mt, B(e.name), 1)
643
+ b("span", dt, B(e.name), 1)
644
644
  ]),
645
- b("div", dt, B(e.tagline), 1),
645
+ b("div", mt, B(e.tagline), 1),
646
646
  b("div", ht, [
647
647
  we(U(Fe), {
648
648
  type: "primary",
@@ -678,6 +678,7 @@ class yt extends ae {
678
678
  service;
679
679
  project = null;
680
680
  components = {};
681
+ nodeEnv = "development";
681
682
  router = null;
682
683
  materialPath = "./";
683
684
  constructor(e) {
@@ -691,10 +692,11 @@ class yt extends ae {
691
692
  adapter: a = {},
692
693
  globals: l = {},
693
694
  modules: c = {},
694
- router: m = null,
695
- materialPath: f = "./"
695
+ router: d = null,
696
+ materialPath: f = "./",
697
+ nodeEnv: u = "development"
696
698
  } = e;
697
- this.mode = r, this.modules = c, this.service = t, this.router = m, this.materialPath = f, n && (this.dependencies = n), o && (this.materials = o), Object.assign(this.globals, l), Object.assign(this.adapter, a), r !== w.Design && this.load(i);
699
+ this.mode = r, this.modules = c, this.service = t, this.router = d, this.materialPath = f, this.nodeEnv = u, n && (this.dependencies = n), o && (this.materials = o), Object.assign(this.globals, l), Object.assign(this.adapter, a), r !== w.Design && this.load(i);
698
700
  }
699
701
  async load(e) {
700
702
  const t = this.modules[`.vtj/projects/${e.id}.json`];
@@ -702,7 +704,7 @@ class yt extends ae {
702
704
  throw new Error("project is null");
703
705
  const { dependencies: r = [], apis: n } = this.project, { dependencies: o, library: i, components: a, materialPath: l } = this, {
704
706
  libraryExports: c,
705
- libraryMap: m,
707
+ libraryMap: d,
706
708
  materials: f,
707
709
  materialExports: u,
708
710
  materialMapLibrary: v
@@ -714,8 +716,8 @@ class yt extends ae {
714
716
  else if (y)
715
717
  window[p] = i[p] = await y();
716
718
  else {
717
- const d = m[p] || [];
718
- for (const $ of d)
719
+ const m = d[p] || [];
720
+ for (const $ of m)
719
721
  X($) && await Te(p, F.append($, { v: I })), Q($) && await q(F.append($, { v: I })), i[p] = window[p];
720
722
  }
721
723
  }
@@ -725,12 +727,12 @@ class yt extends ae {
725
727
  for (const p of u) {
726
728
  const y = window[v[p]], S = ce[p];
727
729
  if (S)
728
- y && S.forEach((d) => {
729
- a[d] = y[d];
730
+ y && S.forEach((m) => {
731
+ a[m] = y[m];
730
732
  });
731
733
  else {
732
- const d = _[p] ? (await _[p]()).default : window[p];
733
- d && y && (d.components || []).forEach(($) => {
734
+ const m = _[p] ? (await _[p]()).default : window[p];
735
+ m && y && (m.components || []).forEach(($) => {
734
736
  a[$.name] = Oe($, y);
735
737
  });
736
738
  }
@@ -791,7 +793,7 @@ class yt extends ae {
791
793
  const o = await this.getDsl(t.id);
792
794
  if (!o)
793
795
  return C.warn(`Can not find dsl: ${e}`), null;
794
- const { library: i, components: a, mode: l, apis: c } = this, m = {
796
+ const { library: i, components: a, mode: l, apis: c } = this, d = {
795
797
  mode: l,
796
798
  Vue: i.Vue,
797
799
  components: a,
@@ -800,9 +802,9 @@ class yt extends ae {
800
802
  window
801
803
  }, f = re({
802
804
  getDsl: async (v) => await this.getDsl(v) || null,
803
- options: m
805
+ options: d
804
806
  }), { renderer: u } = te({
805
- ...m,
807
+ ...d,
806
808
  dsl: o,
807
809
  loader: f
808
810
  });
@@ -820,7 +822,7 @@ function oe(s = {}) {
820
822
  const e = je(ne);
821
823
  if (!e)
822
824
  throw new Error("Can not find provider");
823
- if (e.mode === w.Raw) {
825
+ if (e.mode === w.Raw && e.nodeEnv === "development") {
824
826
  const { id: t, version: r } = s;
825
827
  t && r && (async () => {
826
828
  const n = await e.getDsl(t);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/renderer",
3
3
  "private": false,
4
- "version": "0.7.29",
4
+ "version": "0.7.30",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "vue-tsc && vite build",
@@ -10,13 +10,13 @@
10
10
  "coverage": "vitest run --coverage"
11
11
  },
12
12
  "dependencies": {
13
- "@vtj/core": "^0.7.29",
14
- "@vtj/icons": "^0.7.29",
15
- "@vtj/ui": "^0.7.29",
16
- "@vtj/utils": "^0.7.29"
13
+ "@vtj/core": "^0.7.30",
14
+ "@vtj/icons": "^0.7.30",
15
+ "@vtj/ui": "^0.7.30",
16
+ "@vtj/utils": "^0.7.30"
17
17
  },
18
18
  "devDependencies": {
19
- "@vtj/cli": "^0.7.19",
19
+ "@vtj/cli": "^0.7.20",
20
20
  "vue": "~3.4.15",
21
21
  "vue-router": "~4.3.0"
22
22
  },
@@ -34,7 +34,7 @@
34
34
  "dist",
35
35
  "types"
36
36
  ],
37
- "gitHead": "051c91898082b0e954af310f9cfcd794a2cb84c2",
37
+ "gitHead": "229d9d4fd7c80a7400146c253a01d0c6546aa737",
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  }
@@ -1,4 +1,5 @@
1
- import { type BlockPropDataType } from '@vtj/core';
1
+ import { BlockPropDataType } from '@vtj/core';
2
+
2
3
  export declare enum ContextMode {
3
4
  /**
4
5
  * 运行时
@@ -1,5 +1,6 @@
1
1
  import { Ref } from 'vue';
2
- import { type MenuDataItem } from '@vtj/ui';
2
+ import { MenuDataItem } from '@vtj/ui';
3
+
3
4
  export declare function useMask(): {
4
5
  disabled: Ref<boolean>;
5
6
  title: string;
@@ -1,5 +1,6 @@
1
- import { type ApiSchema } from '@vtj/core';
2
- import { type IRequestConfig } from '@vtj/utils';
3
- import { type ProvideAdapter } from './provider';
1
+ import { ProvideAdapter } from './provider';
2
+ import { IRequestConfig } from '@vtj/utils';
3
+ import { ApiSchema } from '@vtj/core';
4
+
4
5
  export declare function createSchemaApi(schema: ApiSchema, adapter: ProvideAdapter): ((query?: Record<string, any>) => Promise<any>) | ((data: any, opts?: IRequestConfig) => Promise<any>);
5
6
  export declare function createSchemaApis(schema: ApiSchema[] | undefined, adapter: ProvideAdapter): Record<string, any>;
@@ -7,4 +7,4 @@ export declare const PageContainer: DefineComponent<{}, {
7
7
  component: any;
8
8
  file: PageFile | null;
9
9
  query: LocationQuery;
10
- }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<{}>>, {}, {}>;
10
+ }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{}>>, {}, {}>;
@@ -1,8 +1,9 @@
1
- import { type App, type InjectionKey } from 'vue';
2
- import { type Router } from 'vue-router';
3
- import { type ProjectSchema, type PageFile, type BlockFile, type Service, type BlockSchema, Base } from '@vtj/core';
4
- import { type IStaticRequest, type Jsonp } from '@vtj/utils';
5
1
  import { ContextMode } from '../constants';
2
+ import { IStaticRequest, Jsonp } from '@vtj/utils';
3
+ import { ProjectSchema, PageFile, BlockFile, Service, BlockSchema, Base } from '@vtj/core';
4
+ import { Router } from 'vue-router';
5
+ import { App, InjectionKey } from 'vue';
6
+
6
7
  export declare const providerKey: InjectionKey<Provider>;
7
8
  export interface ProviderOptions {
8
9
  service: Service;
@@ -15,6 +16,7 @@ export interface ProviderOptions {
15
16
  materials?: Record<string, () => Promise<any>>;
16
17
  globals?: Record<string, any>;
17
18
  materialPath?: string;
19
+ nodeEnv?: 'development' | 'production';
18
20
  }
19
21
  export interface ProvideAdapter {
20
22
  request: IStaticRequest;
@@ -32,6 +34,7 @@ export declare class Provider extends Base {
32
34
  service: Service;
33
35
  project: ProjectSchema | null;
34
36
  components: Record<string, any>;
37
+ nodeEnv: 'development' | 'production';
35
38
  private router;
36
39
  private materialPath;
37
40
  constructor(options: ProviderOptions);
@@ -1,2 +1,2 @@
1
1
  import { DefineComponent, ComponentOptionsMixin, PublicProps, ExtractPropTypes } from 'vue';
2
- export declare const StartupContainer: DefineComponent<{}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<ExtractPropTypes<{}>>, {}, {}>;
2
+ export declare const StartupContainer: DefineComponent<{}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{}>>, {}, {}>;
@@ -1,7 +1,8 @@
1
- import { type BlockSchema, type DataSourceSchema } from '@vtj/core';
2
- import { ContextMode } from '../constants';
1
+ import { BlockLoader } from './loader';
3
2
  import { Context } from './context';
4
- import { type BlockLoader } from './loader';
3
+ import { ContextMode } from '../constants';
4
+ import { BlockSchema, DataSourceSchema } from '@vtj/core';
5
+
5
6
  export type DataSourceHandler = (...args: any[]) => Promise<any>;
6
7
  export interface CreateRendererOptions {
7
8
  Vue?: any;
@@ -1,5 +1,6 @@
1
+ import { BlockSchema, JSFunction, JSExpression } from '@vtj/core';
1
2
  import { ContextMode } from '../constants';
2
- import { type BlockSchema, type JSFunction, type JSExpression } from '@vtj/core';
3
+
3
4
  export interface ContextOptions {
4
5
  mode: ContextMode;
5
6
  dsl?: BlockSchema;
@@ -1,6 +1,7 @@
1
- import type { DefineComponent } from 'vue';
2
- import type { NodeFrom, BlockSchema } from '@vtj/core';
3
- import { type CreateRendererOptions } from './block';
1
+ import { CreateRendererOptions } from './block';
2
+ import { NodeFrom, BlockSchema } from '@vtj/core';
3
+ import { DefineComponent } from 'vue';
4
+
4
5
  export type BlockLoader = (name: string, from?: NodeFrom, Vue?: any) => string | DefineComponent;
5
6
  export declare const defaultLoader: BlockLoader;
6
7
  export interface CreateLoaderOptions {
@@ -1,6 +1,7 @@
1
- import type { VNode } from 'vue';
2
- import { type NodeSchema, type NodeModifiers } from '@vtj/core';
3
- import { type Context } from './context';
4
- import { type BlockLoader } from './loader';
1
+ import { BlockLoader } from './loader';
2
+ import { Context } from './context';
3
+ import { NodeSchema, NodeModifiers } from '@vtj/core';
4
+ import { VNode } from 'vue';
5
+
5
6
  export declare function nodeRender(dsl: NodeSchema, context: Context, Vue?: any, loader?: BlockLoader): VNode | VNode[] | null;
6
7
  export declare function getModifiers(modifiers?: NodeModifiers, isToString?: boolean): string[];
@@ -1,4 +1,5 @@
1
- import { type ProjectSchema, type PageFile, type BlockFile, type BlockSchema, type MaterialDescription, type HistorySchema, type HistoryItem, type Service } from '@vtj/core';
1
+ import { ProjectSchema, PageFile, BlockFile, BlockSchema, MaterialDescription, HistorySchema, HistoryItem, Service } from '@vtj/core';
2
+
2
3
  export declare class BaseService implements Service {
3
4
  protected api: (type: string, data: any) => Promise<any>;
4
5
  constructor();
@@ -1,5 +1,6 @@
1
- import { type ProjectSchema, type BlockSchema, type HistorySchema, type HistoryItem, type MaterialDescription } from '@vtj/core';
2
1
  import { BaseService } from './base';
2
+ import { ProjectSchema, BlockSchema, HistorySchema, HistoryItem, MaterialDescription } from '@vtj/core';
3
+
3
4
  export declare class LocalService extends BaseService {
4
5
  init(project: ProjectSchema): Promise<ProjectSchema>;
5
6
  saveProject(project: ProjectSchema): Promise<boolean>;
@@ -1,5 +1,6 @@
1
- import { type ProjectSchema, type BlockSchema, type HistorySchema, type HistoryItem, type MaterialDescription } from '@vtj/core';
2
1
  import { BaseService } from './base';
2
+ import { ProjectSchema, BlockSchema, HistorySchema, HistoryItem, MaterialDescription } from '@vtj/core';
3
+
3
4
  export declare class MemoryService extends BaseService {
4
5
  private projects;
5
6
  private materials;
@@ -1,5 +1,6 @@
1
- import { type ProjectSchema, type BlockSchema, type HistorySchema, type HistoryItem, type MaterialDescription } from '@vtj/core';
2
1
  import { BaseService } from './base';
2
+ import { ProjectSchema, BlockSchema, HistorySchema, HistoryItem, MaterialDescription } from '@vtj/core';
3
+
3
4
  export declare class StorageService extends BaseService {
4
5
  init(project: ProjectSchema): Promise<ProjectSchema>;
5
6
  saveProject(project: ProjectSchema): Promise<boolean>;
@@ -1,4 +1,5 @@
1
- import type { Dependencie, MaterialDescription } from '@vtj/core';
1
+ import { Dependencie, MaterialDescription } from '@vtj/core';
2
+
2
3
  export declare function fillBasePath(urls: string[], basePath: string): string[];
3
4
  export declare function isCSSUrl(url: string): boolean;
4
5
  export declare function isJSUrl(url: string): boolean;
@@ -1,4 +1,5 @@
1
- import type { JSExpression, JSFunction } from '@vtj/core';
1
+ import { JSExpression, JSFunction } from '@vtj/core';
2
+
2
3
  export declare function parseExpression(str: JSExpression | JSFunction, self: any, thisRequired?: boolean, throwError?: boolean): any;
3
4
  export declare function parseFunction(str: JSFunction, self: any, thisRequired?: boolean, throwError?: boolean): Function;
4
5
  export declare function isJSExpression(data: any): data is JSExpression;
@@ -1,4 +1,5 @@
1
- import type { Plugin } from 'vue';
1
+ import { Plugin } from 'vue';
2
+
2
3
  export declare function toString(value: any): string;
3
4
  export declare function adoptedStyleSheets(global: Window, id: string, css: string): void;
4
5
  export declare function loadCss(id: string, url: string): Promise<void>;
@@ -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.28
5
+ * @version 0.7.29
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.7.28";
8
+ export declare const version = "0.7.29";