UNPKG

@syncfusion/ej2-vue-base

Version:

A common package of Essential JS 2 base Vue libraries, methods and class definitions

12 lines (11 loc) 16.3 kB
/*! * filename: ej2-vue-base.min.js * version : 31.2.5 * Copyright Syncfusion Inc. 2001 - 2025. All rights reserved. * Use of this code is subject to the terms of our license. * A copy of the current license can be obtained at any time by e-mailing * licensing@syncfusion.com. Any infringement will be prosecuted under * applicable laws. */ this.ej=this.ej||{},this.ej.vuebase=function(e,t,n){"use strict";function s(e){if(void 0===e&&(e={}),e.props)for(var t=0,n=e.props;t<n.length;t++)!function(t){(e.newprops||(e.newprops={}))[""+t]={},(e.watch||(e.watch={}))[""+t]=function(n){this.ej2Instances[""+t]=n,this.dataBind&&"DateRangePickerComponent"!==e.name&&this.dataBind()}}(n[t]);return[e.newprops,e.watch]}function r(e,t){var s=this;return function(r,o,p,c,h){var g;if(o){var f=o.vueInstance&&o.vueInstance.plugins?{plugins:o.vueInstance.plugins}:{},v=o.vueInstance?o.vueInstance:h&&h.vueInstance?h.vueInstance:null,j=n.getUniqueID("templateParentDiv"),O=n.getUniqueID("templateDiv"),y=n.createElement("div",{id:j,innerHTML:'<div id="'+O+'"></div>'});if(document.body.appendChild(y),!d&&("string"==typeof e||e.prototype&&e.prototype.CSPTemplate&&"function"==typeof e)){var C=l(o.vueInstance,e,h);if(!C)return n.detach(y),I(e,t)(r);E=u.createVNode({render:function(){return C[""+e]({data:r})}},f);y.innerHTML="",i(E,o.vueInstance,h),u.render(E,y),g=y.childNodes,v&&((S=v.templateCollection)||(v.templateCollection={},S=v.templateCollection),p&&(S[""+p]||(S[""+p]=[]),S[""+p].push(g[0]))),n.detach(y)}else if(d)if("string"==typeof e||e.prototype&&e.prototype.CSPTemplate&&"function"==typeof e){var $=a(o.vueInstance,e,h);if(!$)return n.detach(y),I(e,t)(r);var b={},V=function(e){e.$parent&&V(e.$parent),e._provided&&Object.keys(e._provided).length>0&&(b=m({},b,e._provided))},x=o.vueInstance?o.vueInstance:h&&h.vueInstance?h.vueInstance:null;x&&V(x),new u({provide:m({},b),render:function(){return $[""+e]({data:r})}}).$mount("#"+O),g=y.childNodes,x&&((S=x.templateCollection)||(x.templateCollection={},S=x.templateCollection),p&&(S[""+p]||(S[""+p]=[]),S[""+p].push(g[0]))),n.detach(y)}else{var M=e.call(s,{}),N=M.template,D=n.getValue("template.propsData",M),k={data:{data:n.extend(M.data||{},r)},parent:o.vueInstance};if(D&&(N=M.template.extends,k.propsData=D),"function"!=typeof N&&(N=u.extend(N)),N.options.setup&&(k.propsData=Object.assign(k.propsData||{},r)),new N(k).$mount("#"+O),g=y.childNodes,k.parent=null,v){var S=v.templateCollection;S||(v.templateCollection={},S=v.templateCollection),p&&(S[""+p]||(S[""+p]=[]),S[""+p].push(g[0]))}n.detach(y)}else{var T=M=e.call(s,{}),D=n.getValue("template.propsData",M),_={data:{data:n.extend(M.data||{},r)},parent:o.vueInstance};T.template||(T.template=T[Object.keys(T)[0]]);var P=void 0;if(T.template.extends)P=T.template.extends._context.components.template;else if(!(P=T.template._context.components[e.name])){var w=Object.keys(T.template._context.components)[0];P=T.template._context.components[""+w]}var U;if(D)U=P.setup?Object.assign({},D):Object.assign(P.data(),D);else if(U=P.setup?Object.assign({},_.data):Object.assign(P.data(),_.data),P.components)for(var L=0,A=Object.keys(P.components)||[];L<A.length;L++)!function(e){var t=P.components[""+e];t&&t.data&&(t.__data||(t.__data=t.data),t.data=function(e){return Object.assign(t.__data.call(e),_.data)})}(A[L]);P.setup&&(f=Object.assign(f,r)),P.data=function(){return U};var E=u.createVNode(P,f);y.innerHTML="",i(E,o.vueInstance,h),u.render(E,y),g=y.childNodes,_.parent=null,v&&((S=v.templateCollection)||(v.templateCollection={},S=v.templateCollection),p&&(S[""+p]||(S[""+p]=[]),S[""+p].push(g[0]))),n.detach(y)}}return g||[]}}function i(e,t,n){var s=t||(n&&n.vueInstance?n.vueInstance:null);if(s){e.appContext=s.$.appContext;var r={},i=function(e){e.$&&e.$.parent&&i(e.$.parent),e.provides&&Object.keys(e.provides).length>0&&(r=m({},r,e.provides))};i(s),e.appContext.provides&&(e.appContext.provides=m({},e.appContext.provides,r))}}function a(e,t,n){if(e||n&&n.vueInstance)return o(n&&n.vueInstance?n.vueInstance:e,t)}function o(e,t){if(e){var n=e.$slots,s=e.$scopedSlots,r=e.scopedSlots,i=e.children;if(s&&s[""+t])return s;if(n&&n.default){for(var a=n.default,l=0;l<a.length;l++)if(c=o(p(a[parseInt(l.toString(),10)]),t))return c}else{if(r&&r[""+t])return r;if(i)for(l=0;l<i.length;l++){var c=o(p(i[parseInt(l.toString(),10)]),t);if(c)return c}}}}function p(e){var t=e.componentOptions&&e.componentOptions.children?e.componentOptions:e.data||"e-markersettings"!==e.tag&&"e-markersetting"!==e.tag?e.data:e;return e.componentInstance?e.componentInstance:t}function l(e,t,n){if(e||n&&n.vueInstance)return c(n&&n.vueInstance?n.vueInstance.$slots:e.$slots,t)}function c(e,t){if(e&&e[""+t])return e;if(e&&e.default){var n=e.default();n=n.flatMap(function(e){return Array.isArray(e.children)?e.children:e});for(var s=0;s<n.length;s++){var r=c(n[parseInt(s.toString(),10)].children,t);if(r)return r}}}var h=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[""+n]=e[""+n]);return t.default=e,t}(t),d=!(parseInt(h.version,10)>2),u=d?h.default.default?h.default.default:h.default:h,g=h.h,f=function(e){return d?u.extend(e):u.defineComponent(e)},v=f({name:"ComponentBase",data:function(){return{tagMapper:{},tagNameMapper:{},hasInjectedModules:!1,hasChildDirective:!1,childDirObjects:"",propKeys:{},isDecorator:!1}},created:function(){var e=this;if(this.ej2Instance&&(this.ej2Instances=this.isVue3?u.toRaw(this.ej2Instance):this.ej2Instance),this.propKeys){for(var t=this,s=0,r=this.propKeys;s<r.length;s++)!function(n){t.ej2Instances.addEventListener(n,function(t){e.$emit(n,t)})}(r[s]);var i=n.getValue("$root.$options.provide",this),a=n.getValue("$parent.$options.provide",this);if(a=n.isNullOrUndefined(a)?n.getValue("$.parent.provides",this):a,this.hasInjectedModules&&!d){var o=[];i&&i.managed?(this.isDecorator=!0,o=this.getInjectedServices()||[]):i?o=i[this.ej2Instances.getModuleName()]||[]:a&&(o=this.getInjectedServices()||[]);for(var p=0,l=this.ej2Instances.getInjectedModules()||[];p<l.length;p++){var c=l[p];-1===o.indexOf(c)&&o.push(c)}this.ej2Instances.injectedModules=o}}},mounted:function(){var e=this.$el?this.$el.querySelectorAll("div.e-directive"):null;if(!d&&e)for(var t=0;t<e.length;t++){var n=e[parseInt(t.toString(),10)];n.parentElement&&n.parentElement.removeChild(n)}this.ej2Instances.isVue=!0,this.ej2Instances.isVue3=this.isVue3,this.ej2Instances.vueInstance=this,this.isVue3&&(this.ej2Instances.ej2Instances=this.ej2Instances,this.ej2Instances.referModels=this.models,this.setModelValue()),this.ej2Instances.appendTo(this.$el)},updated:function(){this.updated()},beforeDestroy:function(){this.destroyComponent()},beforeUnmount:function(){this.destroyComponent()},methods:{setModelValue:function(){if(!n.isNullOrUndefined(this.modelValue)||!n.isNullOrUndefined(this.$attrs.modelValue)){var e=(this.models.toString().match(/checked|value/)||[])[0];n.isNullOrUndefined(e)||(this.ej2Instances[""+e]=n.isNullOrUndefined(this.modelValue)?this.$attrs.modelValue:this.modelValue)}},updated:function(){if(this.isVue3&&this.setModelValue(),this.hasChildDirective){var e={};this.fetchChildPropValues(e);var t=JSON.stringify(e);this.childDirObjects!==t&&(this.childDirObjects=t,this.assignValueToWrapper(e,!1))}},getInjectedServices:function(){var e,t=[];if(this.$root&&this.isDecorator?e=n.getValue("$root.$options.provide",this):this.$vnode?e=n.getValue("$vnode.context.$options.provide",this):this.$parent&&(e=n.getValue("$parent.$options.provide",this)),n.isNullOrUndefined(e)&&!n.isNullOrUndefined(this.$)&&(e=n.getValue("$.parent.provides",this)),e){var s=e;if("function"==typeof e)if(e.managed){var r=e.managed,i=Object.keys(r),a=void 0;this.$root&&this.isDecorator?a=Object.keys(this.$root):this.$vnode?a=Object.keys(this.$vnode.context):this.$parent&&(a=Object.keys(this.$parent));for(var o=0;o<i.length;o++)for(var p=0;p<a.length;p++)-1!==a[parseInt(p.toString(),10)].indexOf(i[parseInt(o.toString(),10)])&&(this.$root&&this.isDecorator?r[i[parseInt(p.toString(),10)]]=this.$root[a[parseInt(o.toString(),10)]]:this.$vnode?r[i[parseInt(o.toString(),10)]]=this.$vnode.context[a[parseInt(p.toString(),10)]]:this.$parent&&(r[i[parseInt(o.toString(),10)]]=this.$parent[a[parseInt(p.toString(),10)]]),s=r)}else this.$vnode?s=this.$vnode.context.$options.provide():this.$parent&&(s=this.$parent.$options.provide());t=s[this.ej2Instances.getModuleName()]||[]}return this.isDecorator=!1,t},destroyComponent:function(){this.ej2Instances.destroy(),this.$el.style.visibility="hidden",this.clearTemplate()},destroyPortals:function(e){if(e){if(n.getValue("__vue__.$destroy",e))e.__vue__.$destroy();else if(!d&&e._vnode)try{u.render(null,e)}catch(e){}e.innerHTML&&(e.innerHTML="")}},bindProperties:function(){for(var e={},t=0,s=this.propKeys;t<s.length;t++){var r=s[t];n.isNullOrUndefined(this[""+r])?!this[0]||n.isNullOrUndefined(this[0][0])||n.isNullOrUndefined(this[0][0][""+r])||(e[""+r]=this[0][0][""+r]):e[""+r]=this[""+r]}if(this.hasChildDirective&&this.fetchChildPropValues(e),this.hasInjectedModules){for(var i=this.getInjectedServices()||[],a=0,o=this.ej2Instances.getInjectedModules()||[];a<o.length;a++){var p=o[a];-1===i.indexOf(p)&&i.push(p)}this.ej2Instances.injectedModules=i}this.assignValueToWrapper(e)},assignValueToWrapper:function(e,t){this.ej2Instances.setProperties(n.extend({},{},e,!0),!!n.isNullOrUndefined(t)||t)},fetchChildPropValues:function(e){var t={};if(this.isVue3){var n=void 0;if(this[0]&&this[0][1].slots.default?n=this[0][1].slots.default():this&&this.$&&this.$.slots&&this.$.slots.default&&(n=this.$.slots.default()),!n)return;for(var s=0;s<n.length;s++)if(n[parseInt(s.toString(),10)].type.methods||"e-seriescollection"===n[parseInt(s.toString(),10)].type){var r="e-seriescollection"===n[parseInt(s.toString(),10)].type?"series-collection":n[parseInt(s.toString(),10)].type.methods.getTag().replace("e-",""),i=this.resolveArrayDirectives(n[parseInt(s.toString(),10)].children,r),a=r.split("-"),o=this.ej2Instances.getModuleName().toLowerCase(),p=a.length>1&&o.indexOf(a[0])>-1?a[1]:a[0];p=p.replace(o,""),p=this.tagNameMapper["e-"+r]?this.tagNameMapper["e-"+r].replace("e-",""):p,"splitter"===o&&"panes"===p?p="paneSettings":"bulletchart"===o&&"range"===p?p="ranges":"schedule"===o&&"header"===p&&(p="headerRows"),t[""+p]=i[""+r]}}else t=this.getDirectiveValues(this.$slots.default,this.tagMapper||{},this.tagNameMapper||{});this.childDirObjects||(this.childDirObjects=JSON.stringify(t));for(var l=0,c=Object.keys(t);l<c.length;l++){var h=c[l];e[""+h]=t[""+h]}},resolveArrayDirectives:function(e,t){var n,s=[];s=(s=e.default?e.default():e).flatMap(function(e){return Array.isArray(e.children)?e.children:e});var r={};r[""+t]=[];for(var i=this,a=0,o=s;a<o.length;a++)!function(e){var s={},a=e.type.methods?e.type.methods.getTag():t;if(e.children){var o=void 0;if((n=i.resolveComplexDirs(e.children,i.tagMapper["e-"+t],a)).length)s=n;else for(var p=0;p<Object.keys(n).length;p++)o=Object.keys(n)[parseInt(p.toString(),10)],s[""+o]=n[""+o]}e.props&&Object.keys(e.props).forEach(function(t){var n=t.replace(/-[a-z]/g,function(e){return e[1].toUpperCase()});n&&(s[""+n]=e.props[""+t])}),/[s]\b/.test(a)&&n&&(!/[s]\b/.test(t)||n.length)?Array.isArray(s)?s.forEach(function(e){r[""+t].push(e)}):r[""+t].push(s):s&&0!==Object.keys(s).length&&r[""+t].push(s)}(o[a]);return r},resolveComplexDirs:function(e,t,n){for(var s,r=[],i={},a=this,o=0,p=r=e.default?e.default():e;o<p.length;o++)!function(e){var o=void 0;t[""+n]&&(o=(o=Object.keys(t[""+n]).find(function(s){return t[""+n][""+s]===e.type.methods.getTag().replace(/[s]\b/,"")}))||e.type.methods.getTag(),o=(a.tagNameMapper[""+o]?a.tagNameMapper[""+o]:o).replace("e-",""),"diagram"===a.ej2Instances.getModuleName().toLowerCase()&&-1!==o.indexOf("annotations")&&(o="annotations")),e.children&&(s=a.resolveComplexInnerDirs(e.children,t[""+n],e.type.methods.getTag()),i[""+o]||(i[""+o]=[]),s.length>1?i[""+o]=s:i[""+o].push(s)),e.props&&(e.props=a.getCamelCaseProps(e.props)),r.length>1?(i=0!==Object.keys(i).length||i.length?i:[],e.props&&i.push(e.props)):i=e.props?Object.assign(i,e.props):i}(p[o]);return i},resolveComplexInnerDirs:function(e,t,n){for(var s=[],r=(s=e.default?e.default():e).length>1?[]:{},i=0,a=s;i<a.length;i++){var o=a[i],p=null,l=o.type.methods.getTag();l=(this.tagNameMapper[""+l]?this.tagNameMapper[""+l]:l).replace("e-",""),o.children&&(p=this.resolveMultilevelComplexInnerDirs(o.children,t[""+n],o.type.methods.getTag()),/[s]\b/.test(l)||s.length>1?/[s]\b/.test(l)?(r[""+l]=r[""+l]?r[""+l]:[],p.length?r[""+l]=p:r[""+l].push(p)):p&&!o.props&&r.push(p):r=p||r),o.props&&(o.props=this.getCamelCaseProps(o.props)),s.length>1&&o.props?p?(p=o.props?Object.assign(p,o.props):p,r.push(p)):r.length>=0?r.push(o.props):r=o.props?Object.assign(r,o.props):r:r=o.props?Object.assign(r,o.props):r}return r},resolveMultilevelComplexInnerDirs:function(e,t,n){for(var s=[],r=(s=e.default?e.default():e).length>1?[]:{},i=0,a=s;i<a.length;i++){var o=a[i],p=null,l=o.type.methods.getTag();l=(this.tagNameMapper[""+l]?this.tagNameMapper[""+l]:l).replace("e-",""),o.children&&(p=this.resolveComplexInnerDirs(o.children,t[""+n],o.type.methods.getTag())),o.props&&(o.props=this.getCamelCaseProps(o.props)),/[s]\b/.test(l)?(r[""+l]=r[""+l]?r[""+l]:[],p.length?r[""+l]=p:r[""+l].push(p),o.props&&r[""+l].push(o.props)):(r=p,r=o.props?Object.assign(r,o.props):r)}return r},getDirectiveValues:function(e,t,n){var s=Object.keys(t),r={};if(e)for(var i=0,a=e;i<a.length;i++){var o=a[i],p=o.componentOptions;if(p&&p.children&&this.getTagName(p)||"e-seriescollection"===o.tag&&o.children){var l=p?this.getTagName(p):o.tag;if(l="e-seriescollection"===l?"e-seriesCollection":l,-1!==s.indexOf(l)){var c=n[""+l]?n[""+l]:l;r[c.replace("e-","")]=[];for(var h=0,d=p?p.children:o.children;h<d.length;h++){var u=d[h],g=this.getVNodeValue(u,t[""+l],n);0!==Object.keys(g).length&&r[c.replace("e-","")].push(g)}}}}return r},getMultiLevelDirValue:function(e,t,n){for(var s={},r=0,i=e;r<i.length;r++){var a=i[r],o=void 0,p=void 0;if(a.componentOptions?(o=this.getTagName(a.componentOptions),a.componentOptions.children&&(p=a.componentOptions.children)):"e-markersettings"!==a.tag&&"e-markersetting"!==a.tag||!a.children||(o="e-markersettings"===a.tag?"e-markerSettings":"e-markerSetting",p=a.children),o){var l=n[""+o]?n[""+o]:o;if(s[l.replace("e-","")]=[],p)for(var c=0,h=p;c<h.length;c++){var d=h[c],u=this.getVNodeValue(d,t[""+o],n);0!==Object.keys(u).length&&s[l.replace("e-","")].push(u)}}}return s},getVNodeValue:function(e,t,s){var r={};if(e.componentOptions||("e-markersettings"===e.tag||"e-markersetting"===e.tag)&&e.context){var i=void 0;i=e.componentOptions?this.getTagName(e.componentOptions):"e-markersettings"===e.tag?"e-markerSettings":"e-markerSetting";var a=e.data;"string"==typeof t&&i===t&&a?r=a.attrs?this.getCamelCaseProps(a.attrs):this.getCamelCaseProps(a):"object"==typeof t&&(e.componentOptions.children&&-1!==Object.keys(t).indexOf(i)?r=this.getMultiLevelDirValue(e.componentOptions.children,t[""+i],s):!e.children||-1===Object.keys(t).indexOf(i)||"e-markersettings"!==i&&"e-markersetting"!==i||(r=this.getMultiLevelDirValue(e.children,t[""+i],s)),a&&a.attrs&&(r=n.extend(r,this.getCamelCaseProps(a.attrs))))}return r},getCamelCaseProps:function(e){for(var t={},n=0,s=Object.keys(e);n<s.length;n++){var r=s[n];t[r.replace(/-[a-z]/g,function(e){return e[1].toUpperCase()})]=e[""+r]}return t},dataBind:function(){this.ej2Instances.dataBind()},setProperties:function(e,t){return this.ej2Instances.setProperties(e,t)},getTagName:function(e){var t=e.tag,n=e.Ctor;return!t&&n&&n.extendOptions&&n.extendOptions.methods&&n.extendOptions.methods.getTag&&(t=e.Ctor.extendOptions.methods.getTag()),t}}});d||n.setProxyToRaw(u.toRaw);var m=function(){return(m=Object.assign||function(e){for(var t,n=1,s=arguments.length;n<s;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)},I=n.getTemplateEngine();return n.setTemplateEngine({compile:r}),e.ComponentBase=v,e.aVue=u,e.compile=r,e.getProps=s,e.gh=g,e.isExecute=d,e.vueDefineComponent=f,e}({},Vue,ej.base),this.ejs=ej; //# sourceMappingURL=ej2-vue-base.min.js.map