devextreme-vue
Version:
DevExtreme UI and Visualization Components for Vue
100 lines (98 loc) • 3.2 kB
JavaScript
/*!
* devextreme-vue
* Version: 25.2.7
* Build date: Tue May 05 2026
*
* Copyright (c) 2012 - 2026 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
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.discover = exports.mountTemplate = void 0;
const vue_1 = require("vue");
const vue_helper_1 = require("./vue-helper");
const TEMPLATE_PROP = 'template';
function asConfigurable(component) {
const componentOptions = component;
if (!componentOptions) {
return;
}
if (!componentOptions.$_config?.name) {
return undefined;
}
return componentOptions;
}
function hasTemplate(component) {
return TEMPLATE_PROP in component.type.props && (0, vue_helper_1.configurationTemplate)(component);
}
function discover(component) {
const templates = {};
const namedTeplates = (0, vue_helper_1.declaredTemplates)(component);
for (const slotName in namedTeplates) {
if (slotName === 'default' && component.$slots.default) {
continue;
}
const slot = namedTeplates[slotName];
if (!slot) {
continue;
}
templates[slotName] = slot;
}
const componentChildren = (0, vue_helper_1.getChildren)(component);
for (const childComponent of componentChildren) {
const configurable = asConfigurable(childComponent);
if (!configurable) {
continue;
}
const defaultSlot = (0, vue_helper_1.configurationDefaultTemplate)(childComponent);
if (!defaultSlot || !hasTemplate(childComponent)) {
continue;
}
const templateName = `${configurable.$_config.fullPath}.${TEMPLATE_PROP}`;
templates[templateName] = defaultSlot;
}
return templates;
}
exports.discover = discover;
function clearConfiguration(content) {
const newContent = [];
content.forEach((item) => {
const configurable = (0, vue_helper_1.getConfigurationOptions)(item);
if (!configurable?.$_optionName) {
newContent.push(item);
}
});
return newContent;
}
function mountTemplate(getSlot, parent, data, name, placeholder) {
return (0, vue_helper_1.mount)({
name,
inject: ['eventBus'],
created() {
this.eventBus.add(this.$_updatedHandler);
},
mounted() {
data.onRendered();
},
unmounted() {
this.eventBus.remove(this.$_updatedHandler);
},
methods: {
$_updatedHandler() {
this.$forceUpdate();
},
},
render: () => {
const content = clearConfiguration(getSlot()(data));
if (!content) {
return (0, vue_1.h)('div');
}
return content.length > 1 ? content : content[0];
},
}, parent, placeholder);
}
exports.mountTemplate = mountTemplate;