devextreme-vue
Version:
DevExtreme Vue UI and Visualization Components
86 lines (84 loc) • 2.67 kB
JavaScript
/*!
* devextreme-vue
* Version: 19.2.6
* Build date: Thu Jan 30 2020
*
* Copyright (c) 2012 - 2020 Developer Express Inc. ALL RIGHTS RESERVED
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file in the root of the project for details.
*
* https://github.com/DevExpress/devextreme-vue
*/
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var VueType = require("vue");
var errors_1 = require("./errors");
var TEMPLATE_PROP = "template";
var Vue = VueType.default || VueType;
function asConfigurable(component) {
if (!component.$vnode) {
return undefined;
}
var configurable = component.$vnode.componentOptions;
if (!configurable.$_config || !configurable.$_config.name) {
return undefined;
}
return configurable;
}
function hasTemplate(component) {
return TEMPLATE_PROP in component.$props && (component.$vnode.data && component.$vnode.data.scopedSlots);
}
function discover(component) {
var templates = {};
for (var slotName in component.$scopedSlots) {
if (slotName === "default" && component.$slots.default) {
continue;
}
var slot = component.$scopedSlots[slotName];
if (!slot) {
continue;
}
templates[slotName] = slot;
}
for (var _i = 0, _a = component.$children; _i < _a.length; _i++) {
var childComponent = _a[_i];
var configurable = asConfigurable(childComponent);
if (!configurable) {
continue;
}
var defaultSlot = childComponent.$scopedSlots.default;
if (!defaultSlot || !hasTemplate(childComponent)) {
continue;
}
var templateName = configurable.$_config.fullPath + "." + TEMPLATE_PROP;
templates[templateName] = defaultSlot;
}
return templates;
}
exports.discover = discover;
function mountTemplate(getSlot, parent, data, name, placeholder) {
return new Vue({
el: placeholder,
name: name,
inject: ["eventBus"],
parent: parent,
created: function () {
var _this = this;
this.eventBus.$on("updated", function () {
_this.$forceUpdate();
});
},
render: function (createElement) {
var content = getSlot()(data);
if (!content) {
return createElement("div");
}
if (content.length > 1) {
throw new Error(errors_1.TEMPLATE_MULTIPLE_ROOTS_ERROR);
}
return content[0];
}
});
}
exports.mountTemplate = mountTemplate;