element-plus
Version:
A Component Library for Vue 3
47 lines (44 loc) • 1.68 kB
JavaScript
import { defineComponent, inject } from 'vue';
import { isArray, isString, isFunction } from '@vue/shared';
import { isEqual } from 'lodash-unified';
import '../../../utils/index.mjs';
import { selectKey } from './token.mjs';
var ElOptions = defineComponent({
name: "ElOptions",
setup(_, { slots }) {
const select = inject(selectKey);
let cachedValueList = [];
return () => {
var _a, _b;
const children = (_a = slots.default) == null ? void 0 : _a.call(slots);
const valueList = [];
function filterOptions(children2) {
if (!isArray(children2))
return;
children2.forEach((item) => {
var _a2, _b2, _c, _d;
const name = (_a2 = (item == null ? void 0 : item.type) || {}) == null ? void 0 : _a2.name;
if (name === "ElOptionGroup") {
filterOptions(!isString(item.children) && !isArray(item.children) && isFunction((_b2 = item.children) == null ? void 0 : _b2.default) ? (_c = item.children) == null ? void 0 : _c.default() : item.children);
} else if (name === "ElOption") {
valueList.push((_d = item.props) == null ? void 0 : _d.value);
} else if (isArray(item.children)) {
filterOptions(item.children);
}
});
}
if (children.length) {
filterOptions((_b = children[0]) == null ? void 0 : _b.children);
}
if (!isEqual(valueList, cachedValueList)) {
cachedValueList = valueList;
if (select) {
select.states.optionValues = valueList;
}
}
return children;
};
}
});
export { ElOptions as default };
//# sourceMappingURL=options.mjs.map