devextreme-vue
Version:
DevExtreme Vue UI and Visualization Components
167 lines (165 loc) • 6.22 kB
JavaScript
/*!
* devextreme-vue
* Version: 25.1.6
* Build date: Mon Oct 13 2025
*
* Copyright (c) 2012 - 2025 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
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfigurationOptions = exports.setVModel = exports.getVModelValue = exports.getNodeTypeOfComponent = exports.getNodeOptions = exports.getComponentProps = exports.mount = exports.defaultSlots = exports.declaredTemplates = exports.configurationTemplate = exports.configurationDefaultTemplate = exports.configurationChildren = exports.getNormalizedProps = exports.getComponentInfo = exports.getChildren = exports.VMODEL_NAME = void 0;
const vue_1 = require("vue");
const helpers_1 = require("./helpers");
const children_processing_1 = require("./children-processing");
exports.VMODEL_NAME = 'modelValue';
function getChildren(component) {
if (!hasChildren(component) || !component.$_config) {
return [];
}
const children = component.$.subTree && component.$.subTree.children;
if (!Array.isArray(children)) {
return [];
}
// @ts-expect-error TS7030
return children.filter((child) => {
if (!(0, children_processing_1.isFragment)(child)) {
return child;
}
});
}
exports.getChildren = getChildren;
function getComponentInfo(component) {
return getConfigurationOptions(component);
}
exports.getComponentInfo = getComponentInfo;
function getNormalizedProps(props) {
const result = {};
for (const propName in props) {
if (props.hasOwnProperty(propName)) {
result[(0, helpers_1.camelize)(propName)] = props[propName];
}
}
return result;
}
exports.getNormalizedProps = getNormalizedProps;
function configurationChildren(component) {
if (!component.children?.default) {
return [];
}
return findConfigurationComponents(component.children.default());
}
exports.configurationChildren = configurationChildren;
function configurationDefaultTemplate(node) {
if (!node.children || node.children === 'object' || !node.children.default) {
return;
}
return hasInlineTemplate(node.children.default()) ? node.children.default : undefined;
}
exports.configurationDefaultTemplate = configurationDefaultTemplate;
function configurationTemplate(node) {
return configurationDefaultTemplate(node);
}
exports.configurationTemplate = configurationTemplate;
function declaredTemplates(component) {
return component.$slots;
}
exports.declaredTemplates = declaredTemplates;
function defaultSlots(component) {
const templates = declaredTemplates(component);
if (!templates.default) {
return [];
}
return templates.default();
}
exports.defaultSlots = defaultSlots;
function mount(options, parent, el) {
const template = (0, vue_1.createApp)(options);
template.provide('eventBus', parent.eventBus);
setAppContext(template, parent);
return template.mount(el);
}
exports.mount = mount;
function getComponentProps(component) {
const props = component.$.vnode.props || {};
return getNormalizedProps(props);
}
exports.getComponentProps = getComponentProps;
function getNodeOptions(component) {
if (component.$) {
return component.$.vnode;
}
return component;
}
exports.getNodeOptions = getNodeOptions;
function getNodeTypeOfComponent(component) {
return component.$.vnode.type;
}
exports.getNodeTypeOfComponent = getNodeTypeOfComponent;
function getVModelValue(options) {
return options[exports.VMODEL_NAME];
}
exports.getVModelValue = getVModelValue;
function setVModel(config) {
const eventName = `update:${exports.VMODEL_NAME}`;
config.model.prop = exports.VMODEL_NAME;
config.model.event = eventName;
config.props.modelValue = {};
config.emits = { ...config.emits, [`${eventName}`]: null };
}
exports.setVModel = setVModel;
function setCustomPluginsData(appContext, parentAppContext) {
for (const prop in parentAppContext) {
if (!appContext.hasOwnProperty(prop) && parentAppContext.hasOwnProperty(prop)) {
appContext[prop] = parentAppContext[prop];
}
}
}
function setAppContext(template, parent) {
template._context.components = Object.assign(parent.$.appContext.components, template._context.components);
Object.setPrototypeOf(template._context.provides, Object.getPrototypeOf(parent.$.provides));
Object.assign(template._context.provides, parent.$.appContext.provides);
template._context.config = parent.$.appContext.config;
template._context.directives = parent.$.appContext.directives;
template._context.mixins = parent.$.appContext.mixins;
setCustomPluginsData(template._context.app, parent.$.appContext.app);
}
function findConfigurationComponents(children) {
return children.filter((child) => {
if ((0, children_processing_1.isFragment)(child)) {
return findConfigurationComponents(child.children || []);
}
const childType = child.type;
if (childType && typeof childType === 'object' && childType.$_optionName) {
delete child.$_config;
delete child.$_innerChanges;
return child;
}
});
}
function hasInlineTemplate(children) {
let hasTemplate = false;
children.forEach((child) => {
if (!isConfiguration(child) && !(0, children_processing_1.isFragment)(child) && !isComment(child)) {
hasTemplate = true;
}
});
return hasTemplate;
}
function isComment(node) {
return node.type === vue_1.Comment || (node.type.toString() === 'Symbol()' && !node.children);
}
function isConfiguration(child) {
return child.type && typeof child.type === 'object' && child.type.$_optionName;
}
function getConfigurationOptions(node) {
return node.type;
}
exports.getConfigurationOptions = getConfigurationOptions;
function hasChildren(component) {
return component.$.vnode && component.$.vnode.children && component.$.vnode.children.default;
}