@vtj/renderer 0.7.0
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/LICENSE +21 -0
- package/dist/index.cjs +10 -0
- package/dist/index.mjs +1130 -0
- package/package.json +42 -0
- package/types/constants.d.ts +32 -0
- package/types/hooks/index.d.ts +1 -0
- package/types/hooks/mask.d.ts +7 -0
- package/types/index.d.ts +7 -0
- package/types/provider/apis.d.ts +5 -0
- package/types/provider/defaults.d.ts +2 -0
- package/types/provider/index.d.ts +2 -0
- package/types/provider/page.d.ts +10 -0
- package/types/provider/provider.d.ts +53 -0
- package/types/render/block.d.ts +20 -0
- package/types/render/context.d.ts +46 -0
- package/types/render/index.d.ts +4 -0
- package/types/render/loader.d.ts +10 -0
- package/types/render/node.d.ts +6 -0
- package/types/services/base.d.ts +20 -0
- package/types/services/index.d.ts +4 -0
- package/types/services/local.d.ts +16 -0
- package/types/services/memory.d.ts +22 -0
- package/types/services/storage.d.ts +16 -0
- package/types/utils/deps.d.ts +15 -0
- package/types/utils/index.d.ts +4 -0
- package/types/utils/logger.d.ts +7 -0
- package/types/utils/parser.d.ts +7 -0
- package/types/utils/util.d.ts +5 -0
- package/types/version.d.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 陈华春
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("@vtj/core"),f=require("@vtj/utils"),$=require("vue"),W=require("vue-router"),O=require("element-plus"),pe=require("@vueuse/core");require("@vtj/ui");function de(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const M=de($);/**!
|
|
2
|
+
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
|
+
* @name @vtj/renderer
|
|
4
|
+
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
+
* @version 0.7.0
|
|
6
|
+
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
+
*/const me="0.7.0";var S=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(S||{});const T=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],ve=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],K=["vIf","vShow","vModel","vFor","vBind"],X={String,Number,Boolean,Array,Object,Function,Date};function A(r){return/\.css$/.test(r)}function L(r){return/\.js$/.test(r)}function he(r){return r.map(e=>`<script src="${e}"><\/script>`).join("")}function ge(r=[]){return r.map(e=>`<link rel="stylesheet" href="${e}" />`).join("")}function G(r){const e=r.filter(c=>!!c.enabled),t=[],s=[],n=[],o=[],i={},a=[],u={};return e.forEach(({urls:c,assetsUrl:m,library:p,assetsLibrary:l})=>{c?.forEach(g=>{L(g)&&t.push(g),A(g)&&s.push(g)}),p&&(o.push(p),i[p]=c||[]),m&&n.push(m),l&&a.push(l),p&&l&&(u[l]=p)}),{scripts:t,css:s,materials:n,libraryExports:o,materialExports:a,materialMapLibrary:u,libraryMap:i}}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 f.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 f.isFunction(r)||f.isFunction(r?.install)}var R=function(){return R=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},R.apply(this,arguments)},N={debug:-1,log:0,info:0,warn:1,error:2},_e=function(r,e,t,s){return function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];if(e&&N[e]<=N[r]&&console[r].apply&&(s==="*"||t.startsWith(s)))return console[r].apply(console,ye(n,t))}};function ye(r,e){return e!=="*"&&(typeof r[0]=="string"?r[0]="["+e+"] "+r[0]:r=["["+e+"]"].concat(r)),r}function Se(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 we={level:"warn",bizName:"*"},te=function(){function r(e){e=R(R({},we),e);var t=location||{},s=(/__(?:logConf|logLevel)__=([^#/&]*)/.exec(t.href)||[])[1],n=Se(s,e),o=n.targetLevel,i=n.targetBizName;for(var a in N)this[a]=_e(a,o,e.bizName,i)}return r}();function re(r){return new te(r)}const P=re({level:"log",bizName:"VTJ"});function F(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
|
+
`)+o;const i=`with(${t?"{}":"$scope || {}"}) { ${o} }`;return new Function("$scope",i)(e)}catch(n){if(P.error("parseExpression.error",n,r,e?.__self??e),s)throw n}}function D(r,e,t=!1,s=!1){const n=F(r,e,t,s);if(typeof n!="function"&&(P.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 I(r){return typeof r=="object"&&r&&r.type==="JSFunction"}function se(r){return _(r)||I(r)}function je(r){return se(r)?r.value:JSON.stringify(r)}let E=null;const $e=f.createRequest({settings:{type:"form",validSuccess:!0,originResponse:!1,loading:!0,validate:r=>r.data?.code===0||!!r.data?.success,failMessage:!0,showError:r=>{O.ElNotification.error({message:r||"未知错误"})},showLoading:()=>{E&&E.close(),E=O.ElLoading.service({lock:!0,text:"Loading",background:"rgba(0, 0, 0, 0.05)"})},hideLoading:()=>{E&&(E.close(),E=null)}}});function ne(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?F(r.headers,{},!0):void 0,o={url:r.url,method:r.method,settings:{...r.settings,headers:n}};return(i,a)=>s.send(f.merge(o,a||{},{data:i}))}}function oe(r=[],e){return r.reduce((t,s)=>(t[s.id]=ne(s,e),t),{})}class ie{__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&&T.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){T.forEach(e=>{this[e]=null})}__parseFunction(e){if(e)if(this.__mode===S.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===S.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return F({type:s,value:n},this)}else return F(e,this)}__ref(e=null,t){if(this.__mode!==S.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),S.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 q(r){const{Vue:e=M,mode:t=S.Runtime,components:s={},libs:n={},apis:o={},loader:i}=r,a=e.computed(()=>r.dsl),u={$components:s,$libs:n,$apis:o},c=new ie({mode:t,dsl:a.value,attrs:u}),m=e.defineComponent({name:a.value.name,props:{...be(a.value.props??[],c)},setup(p){c.$props=p,a.value.id&&k(r.window||window,a.value.id,a.value.css||""),c.state=Ee(e,a.value.state??{},c);const l=Pe(e,a.value.computed??{},c),g=Fe(a.value.methods??{},c),d=Ce(e,a.value.inject,c),v=ae(a.value.dataSources||{},c),w={...d,...l,...g,...v};return c.setup(w,e),Ie(e,a.value.watch??[],c),{vtj:c}},emits:[...a.value.emits??[]],expose:["vtj"],render(){if(!a.value.nodes)return null;const p=a.value.nodes||[];return p.length===1?C(p[0],c,e,i):p.map(l=>C(l,c,e,i))},...He(a.value.lifeCycles??{},c)});return{renderer:e.markRaw(m),context:c}}function be(r=[],e){const t=s=>s?(Array.isArray(s)?s:[s]).map(o=>X[o]):void 0;return r.map(s=>f.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 Ee(r,e,t){return r.reactive(Object.keys(e||{}).reduce((s,n)=>{let o=e[n];return _(o)?o=t.__parseExpression(o):I(o)&&(o=t.__parseFunction(o)),s[n]=o,s},{}))}function Pe(r,e,t){return Object.entries(e??{}).reduce((s,[n,o])=>(s[n]=r.computed(t.__parseFunction(o)),s),{})}function Fe(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}function Ce(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,u=_(n.default)?t.__parseExpression(n.default):n.default??null;return s[o]=r.inject(a,u),s},{})}function ae(r,e){return Object.keys(r).reduce((t,s)=>{const n=r[s],o=e.$apis[n.ref],i=I(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 Ie(r,e=[],t){e.forEach(s=>{r.watch(t.__parseExpression(s.source),t.__parseFunction(s.handler),{deep:s.deep,immediate:s.immediate})})}function He(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}const ce=r=>r;function V(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?q({...t,Vue:o,dsl:i,mode:S.Runtime,loader:V(r)}).renderer:null}):s}function C(r,e,t=M,s=ce){if(!r||!r.name||r.invisible)return null;const{id:n=null,directives:o=[]}=r,{vIf:i,vFor:a,vShow:u,vModels:c,vBind:m}=Oe(o);if(i&&!Re(i,e))return null;const p=l=>{const g=l.$components,d=(()=>{if(r.name==="component")return Me(l,r.props?.is);if(r.name==="slot")return r.name;const y=s(r.name,r.from,t);return f.isString(y)?g[y]??y:y})(),v=xe(n,r.props??{},l),w=Te(t,r.events??{},l);if(r.name==="slot")return Ne(t,r,v,l);m&&Object.assign(v,l.__parseExpression(m.value)),u&&(v.style=Object.assign(v.style??{},Ae(u,l))),c.forEach(y=>{Object.assign(v,Le(t,y,l))});const b=Be(t,r.children??[],l,r);return t.createVNode(d,{...v,...w},b)};return a?Ve(a,p,e):p(e)}function Oe(r=[]){const e=r.find(a=>f.camelCase(a.name)==="vIf"),t=r.find(a=>f.camelCase(a.name)==="vFor"),s=r.find(a=>f.camelCase(a.name)==="vShow"),n=r.find(a=>f.camelCase(a.name)==="vBind"),o=r.filter(a=>f.camelCase(a.name)==="vModel"),i=r.filter(a=>!K.includes(f.camelCase(a.name)));return{vIf:e,vFor:t,vShow:s,vModels:o,vBind:n,others:i}}function Re(r,e){return!!e.__parseExpression(r.value)}function Me(r,e){return e?_(e)?r.__parseExpression(e):e:"div"}function xe(r,e,t){const s=Object.keys(e||{}).reduce((n,o)=>{let i=e[o];return _(i)?i=t.__parseExpression(i):I(i)&&(i=t.__parseFunction(i)),n[o]=i,n},{});return s.ref=t.__ref(r,s.ref),s}function Te(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),c=u.find(l=>s.includes(l)),m="on"+f.upperFirst(i)+(c&&n[c]||""),p=t.__parseFunction(a.handler);return p&&(o[m]=r.withModifiers(p,u)),o},{})}function J(r={},e=!1){const t=Object.keys(r);return e?t.map(s=>"."+s):t}function Ne(r,e,t,s){const{children:n}=e,o=De(e,s),i=s.$slots?.[o.name];return i?i(t):n?f.isString(n)?r.createTextVNode(n):_(n)?r.createTextVNode(B(s.__parseExpression(n))):Array.isArray(n)?n.map(a=>C(a,s,r)):null:null}function De(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 Le(r,e,t){const s={type:"JSFunction",value:e.value?.value?`(v) => {
|
|
9
|
+
${e.value.value} = v;
|
|
10
|
+
}`:"(v) => {}"},n=t.__parseFunction(s),o=J(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 Be(r,e,t,s){if(!e)return null;if(f.isString(e))return{default:()=>e};if(_(e))return{default:()=>B(t.__parseExpression(e))};if(Array.isArray(e)){const n=ke(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:c}])=>(i[a]=m=>{const p=c.length?f.pick(m??{},c):o(m);return u.map(l=>C(l,t.__clone(p),r))},i),{})}}function ke(r){const e={default:{params:[],nodes:[]}};for(const t of r){const s=qe(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 qe(r="default"){return f.isString(r)?{name:r,params:[]}:{params:[],...r}}function Ve(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,c)=>c+1)),Array.isArray(a)?a.map((u,c)=>e(t.__clone({[o]:u,[i]:c}))):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const Y=$.defineComponent({name:"VtjPageContainer",async setup(){const r=z(),e=W.useRoute(),t=e.params.id,s=t?r.getPage(t):r.getHomepage(),n=s?await r.getRenderComponent(s.id):null;return s&&pe.useTitle(s.title||"VTJ"),{provider:r,component:n,file:s,query:e.query}},render(){return this.component?$.h(this.component,this.query):$.h("div","页面不存在")}});var Je={ENV_TYPE:"local",NODE_ENV:"production"};const U=Symbol("Provider");class ue extends j.Base{mode;globals={};modules={};adapter={request:$e,jsonp:f.jsonp};apis={};dependencies={};materials={};library={};service;project=null;components={};router=null;constructor(e){super();const{service:t,mode:s=S.Raw,dependencies:n,materials:o,project:i={},adapter:a={},globals:u={},modules:c={},router:m=null}=e;this.mode=s,this.modules=c,this.service=t,this.router=m,n&&(this.dependencies=n),o&&(this.materials=o),Object.assign(this.globals,u),Object.assign(this.adapter,a),s!==S.Design&&this.load(i)}async load(e){const t=this.modules[".vtj/project.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}=this,{libraryExports:u,libraryMap:c,materials:m,materialExports:p,materialMapLibrary:l}=G(s);for(const d of u){const v=o[d],w=window[d];if(w)i[d]=w;else if(v)window[d]=i[d]=await v();else{const b=c[d]||[];for(const y of b)A(y)&&await Z(d,y),L(y)&&await f.loadScript(y),i[d]=window[d]}}for(const d of m)await f.loadScript(d);const g=this.materials||{};for(const d of p){const v=g[d]?(await g[d]()).default:window[d],w=window[l[d]];v&&w&&v.components.forEach(b=>{a[b.name]=Q(b,w)})}n&&(this.apis=oe(n,this.adapter)),this.initRouter(),this.triggerReady()}initRouter(){const{router:e,project:t}=this;e&&(e.addRoute({path:"/page/:id",name:"VtjPage",component:Y}),t?.homepage&&e.addRoute({path:"/",name:"VtjHomepage",component:Y}))}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 P.warn(`Can not find file: ${e}`),null;const s=`.vtj/raw/${e}.vue`,n=this.modules[s];if(n)return(await n())?.default;const o=await this.getDsl(t.id);if(!o)return P.warn(`Can not find dsl: ${e}`),null;const{library:i,components:a,mode:u,apis:c}=this,m={mode:u,Vue:i.Vue,components:a,libs:i,apis:c,window},p=V({getDsl:async g=>await this.getDsl(g)||null,options:m}),{renderer:l}=q({...m,dsl:o,loader:p});return l}}function Ue(r){const e=new ue(r);return{provider:e,onReady:s=>e.ready(s)}}function z(r={}){const e=$.inject(U);if(!e)throw new Error("Can not find provider");if(e.mode===S.Runtime&&Je.NODE_ENV==="development"){const{id:t,version:s}=r;t&&s&&(async()=>{const n=await e.getDsl(t);n?.__VERSION__!==s&&O.ElNotification.warning({title:n?.name,message:"当前组件源码版本与运行时版本不一致,请重新发布组件"})})()}return e}const ze=new f.Request({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:r=>r.data?.code===0,showError:r=>{O.ElNotification.error({message:r||"未知错误"})}}}),Ye=(r="/vtj/local/api/${type}.json")=>(e,t)=>ze.send({url:r,method:"post",query:{type:e},data:{type:e,data:t}});class x{api;constructor(){this.api=Ye()}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 getRaw(e,t){return await this.api("getRaw",{project:e,dsl:t}).catch(()=>"")}}const h=new f.Storage({type:"local",expired:0,prefix:"__VTJ_"});class We extends x{init(e){const t=new j.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 j.ProjectModel(e);return h.save(`project_${t.id}`,t.toDsl()),Promise.resolve(!0)}saveMaterials(e,t){return h.save(`materials_${e.id}`,f.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 j.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 le extends x{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new j.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 j.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=f.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 j.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 H=null;function Ke(){return H||(H=new le,H)}class Xe extends x{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:f.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 fe(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?fe(o):void 0}})}function Ge(){const r=z(),e=W.useRoute(),t=$.ref(!1),s=r.project;$.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=fe(s?.pages);return{disabled:t,title:s?.description||s?.name||"VTJ App",menus:n}}exports.BUILDIN_DIRECTIVES=K;exports.BaseService=x;exports.CONTEXT_HOST=T;exports.Context=ie;exports.ContextMode=S;exports.DATA_TYPES=X;exports.JSCodeToString=je;exports.LIFE_CYCLES_LIST=ve;exports.LocalService=Xe;exports.Logger=te;exports.MemoryService=le;exports.Provider=ue;exports.StorageService=We;exports.VTJ_RENDERER_VERSION=me;exports.adoptedStyleSheets=k;exports.createAssetScripts=he;exports.createAssetsCss=ge;exports.createDataSources=ae;exports.createLoader=V;exports.createMemoryService=Ke;exports.createProvider=Ue;exports.createRenderer=q;exports.createSchemaApi=ne;exports.createSchemaApis=oe;exports.defaultLoader=ce;exports.getLogger=re;exports.getModifiers=J;exports.getRawComponent=Q;exports.isCSSUrl=A;exports.isJSCode=se;exports.isJSExpression=_;exports.isJSFunction=I;exports.isJSUrl=L;exports.isVuePlugin=ee;exports.loadCss=Z;exports.logger=P;exports.nodeRender=C;exports.parseDeps=G;exports.parseExpression=F;exports.parseFunction=D;exports.providerKey=U;exports.toString=B;exports.useMask=Ge;exports.useProvider=z;
|