UNPKG

@syncfusion/ej2-vue-popups

Version:

A package of Essential JS 2 popup components such as Dialog and Tooltip that is used to display information or messages in separate pop-ups. for Vue

175 lines (174 loc) 8.19 kB
import { ComponentBase, gh, getProps, isExecute, vueDefineComponent } from '@syncfusion/ej2-vue-base'; import { isNullOrUndefined } from '@syncfusion/ej2-base'; import { isUndefined } from '@syncfusion/ej2-base'; import { Dialog } from '@syncfusion/ej2-popups'; import { ButtonsDirective, DialogButtonDirective, ButtonsPlugin, DialogButtonPlugin } from './buttons.directive'; export var properties = ['isLazyUpdate', 'plugins', 'allowDragging', 'animationSettings', 'buttons', 'closeOnEscape', 'content', 'cssClass', 'enableHtmlSanitizer', 'enablePersistence', 'enableResize', 'enableRtl', 'footerTemplate', 'header', 'height', 'isModal', 'locale', 'minHeight', 'position', 'resizeHandles', 'showCloseIcon', 'target', 'visible', 'width', 'zIndex', 'beforeClose', 'beforeOpen', 'beforeSanitizeHtml', 'close', 'created', 'destroyed', 'drag', 'dragStart', 'dragStop', 'open', 'overlayClick', 'resizeStart', 'resizeStop', 'resizing']; export var modelProps = ['visible']; export var testProp = getProps({ props: properties }); export var props = testProp[0], watch = testProp[1], emitProbs = Object.keys(watch); emitProbs.push('modelchanged', 'update:modelValue'); for (var _i = 0, modelProps_1 = modelProps; _i < modelProps_1.length; _i++) { var props_1 = modelProps_1[_i]; emitProbs.push('update:' + props_1); } /** * Represents the VueJS Dialog component * ```html * <ejs-dialog></ejs-dialog> * ``` */ export var DialogComponent = vueDefineComponent({ name: 'DialogComponent', mixins: [ComponentBase], props: props, watch: watch, emits: emitProbs, model: { event: 'modelchanged' }, provide: function () { return { custom: this.custom }; }, data: function () { return { ej2Instances: new Dialog({}), propKeys: properties, models: modelProps, hasChildDirective: true, hasInjectedModules: false, tagMapper: { "e-buttons": "e-dialogbutton" }, tagNameMapper: {}, isVue3: !isExecute, templateCollection: {}, }; }, created: function () { this.ej2Instances._trigger = this.ej2Instances.trigger; this.ej2Instances.trigger = this.trigger; this.bindProperties(); this.ej2Instances._setProperties = this.ej2Instances.setProperties; this.ej2Instances.setProperties = this.setProperties; this.ej2Instances.clearTemplate = this.clearTemplate; this.updated = this.updated; }, render: function (createElement) { var h = !isExecute ? gh : createElement; var slots = null; if (!isNullOrUndefined(this.$slots.default)) { slots = !isExecute ? this.$slots.default() : this.$slots.default; } return h('div', slots); }, methods: { clearTemplate: function (templateNames) { if (!templateNames) { templateNames = Object.keys(this.templateCollection || {}); } if (templateNames.length && this.templateCollection) { for (var _i = 0, templateNames_1 = templateNames; _i < templateNames_1.length; _i++) { var tempName = templateNames_1[_i]; var elementCollection = this.templateCollection[tempName]; if (elementCollection && elementCollection.length) { for (var _a = 0, elementCollection_1 = elementCollection; _a < elementCollection_1.length; _a++) { var ele = elementCollection_1[_a]; this.destroyPortals(ele); } delete this.templateCollection[tempName]; } } } }, setProperties: function (prop, muteOnChange) { var _this = this; if (this.isVue3) { this.models = !this.models ? this.ej2Instances.referModels : this.models; } if (this.ej2Instances && this.ej2Instances._setProperties) { this.ej2Instances._setProperties(prop, muteOnChange); } if (prop && this.models && this.models.length) { Object.keys(prop).map(function (key) { _this.models.map(function (model) { if ((key === model) && !(/datasource/i.test(key))) { if (_this.isVue3) { _this.ej2Instances.vueInstance.$emit('update:' + key, prop[key]); } else { _this.$emit('update:' + key, prop[key]); _this.$emit('modelchanged', prop[key]); } } }); }); } }, trigger: function (eventName, eventProp, successHandler) { if (!isExecute) { this.models = !this.models ? this.ej2Instances.referModels : this.models; } if ((eventName === 'change' || eventName === 'input') && this.models && (this.models.length !== 0)) { var key = this.models.toString().match(/checked|value/) || []; var propKey = key[0]; if (eventProp && key && !isUndefined(eventProp[propKey])) { if (!isExecute) { this.ej2Instances.vueInstance.$emit('update:' + propKey, eventProp[propKey]); this.ej2Instances.vueInstance.$emit('modelchanged', eventProp[propKey]); this.ej2Instances.vueInstance.$emit('update:modelValue', eventProp[propKey]); } else { if (eventName === 'change' || (this.$props && !this.$props.isLazyUpdate)) { this.$emit('update:' + propKey, eventProp[propKey]); this.$emit('modelchanged', eventProp[propKey]); } } } } else if ((eventName === 'actionBegin' && eventProp.requestType === 'dateNavigate') && this.models && (this.models.length !== 0)) { var key = this.models.toString().match(/currentView|selectedDate/) || []; var propKey = key[0]; if (eventProp && key && !isUndefined(eventProp[propKey])) { if (!isExecute) { this.ej2Instances.vueInstance.$emit('update:' + propKey, eventProp[propKey]); this.ej2Instances.vueInstance.$emit('modelchanged', eventProp[propKey]); } else { this.$emit('update:' + propKey, eventProp[propKey]); this.$emit('modelchanged', eventProp[propKey]); } } } if ((this.ej2Instances && this.ej2Instances._trigger)) { this.ej2Instances._trigger(eventName, eventProp, successHandler); } }, custom: function () { this.updated(); }, destroy: function () { return this.ej2Instances.destroy(); }, getButtons: function (index) { return this.ej2Instances.getButtons(index); }, getDimension: function () { return this.ej2Instances.getDimension(); }, hide: function (event) { return this.ej2Instances.hide(event); }, refreshPosition: function () { return this.ej2Instances.refreshPosition(); }, sanitizeHelper: function (value) { return this.ej2Instances.sanitizeHelper(value); }, show: function (isFullScreen) { return this.ej2Instances.show(isFullScreen); }, } }); export var DialogPlugin = { name: 'ejs-dialog', install: function (Vue) { Vue.component(DialogPlugin.name, DialogComponent); Vue.component(DialogButtonPlugin.name, DialogButtonDirective); Vue.component(ButtonsPlugin.name, ButtonsDirective); } };