UNPKG

tdesign-vue

Version:
192 lines (188 loc) 7.83 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { ref, computed, watch, onBeforeUpdate } from '@vue/composition-api'; import { omit, get } from 'lodash-es'; import { getVNodeComponentName, getVueComponentName } from '../../utils/helper.js'; import _Option from '../option.js'; import _OptionGroup from '../optionGroup.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import '../../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import '@babel/runtime/helpers/typeof'; import 'vue'; import '../../utils/ripple.js'; import '../../_common/js/utils/setStyle.js'; import '../../config.js'; import '../../config-provider/config-receiver.js'; import '../../config-provider/context.js'; import '../../_common/js/global-config/default-config.js'; import '../../_common/js/global-config/locale/zh_CN.js'; import '../../_chunks/dep-c44a474d.js'; import '../../_chunks/dep-d639fbd7.js'; import 'dayjs'; import '../../_chunks/dep-3c66615e.js'; import '../../config-provider/type.js'; import '../../_common/js/global-config/t.js'; import '../option-props.js'; import '../../checkbox/index.js'; import '../../checkbox/group.js'; import '../../_chunks/dep-323b993c.js'; import '@babel/runtime/helpers/toConsumableArray'; import '../../checkbox/checkbox.js'; import '../../checkbox/props.js'; import '../../hooks/index.js'; import '../../hooks/slots.js'; import '../../hooks/useCommonClassName.js'; import '../../config-provider/useConfig.js'; import '../../hooks/useConfig.js'; import '../../hooks/useDefaultValue.js'; import '../../hooks/useDestroyOnClose.js'; import '../../hooks/useElementLazyRender.js'; import '../../_common/js/utils/observe.js'; import '../../hooks/useFormDisabled.js'; import '../../hooks/useGlobalIcon.js'; import '../../hooks/useLazyLoad.js'; import '../../hooks/useResizeObserver.js'; import '../../hooks/useVirtualScrollNew.js'; import '../../hooks/useVModel.js'; import '../../hooks/useImagePreviewUrl.js'; import '../../_common/js/upload/utils.js'; import '../../_common/js/log/log.js'; import '../../checkbox/constants.js'; import '../../checkbox/store.js'; import '@babel/runtime/helpers/classCallCheck'; import '@babel/runtime/helpers/createClass'; import '../../checkbox/hooks/useKeyboardEvent.js'; import '../../_common/js/common.js'; import '../../checkbox/checkbox-group-props.js'; import '../../utils/withInstall.js'; import './style/css.js'; import '../../checkbox/type.js'; import '../util.js'; import '../option-group-props.js'; import '../../hooks/tnode.js'; import '../../hooks/render-tnode.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function useSelectOptions(props, instance, keys) { var options = ref([]); var optionsCache = ref([]); var innerSlotRecord = null; var getOptions = function getOptions() { var _props$options; var dynamicIndex = 0; var innerOptions = ((_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.map(function (option) { var getFormatOption = function getFormatOption(option2) { var _keys$value = keys.value, value = _keys$value.value, label = _keys$value.label, disabled = _keys$value.disabled; var restOption = omit(option2, [value, label, disabled]); var res = _objectSpread(_objectSpread({}, restOption), {}, { index: dynamicIndex, label: get(option2, label), value: get(option2, value), disabled: get(option2, disabled) }); dynamicIndex += 1; return res; }; if (option.children) { return _objectSpread(_objectSpread({}, option), {}, { children: option.children.map(function (child) { return getFormatOption(child); }) }); } return getFormatOption(option); })) || []; if (props.options === void 0) { innerSlotRecord = instance.proxy.$slots["default"]; var currentSlots = instance.proxy.$slots["default"] || []; currentSlots.forEach(function (child) { if (!child.componentOptions) { return; } var componentName = getVNodeComponentName(child); if (componentName && componentName === getVueComponentName(_Option)) { innerOptions.push(_objectSpread(_objectSpread({ "class": child.data.staticClass, style: child.data.staticStyle }, child.componentOptions.propsData), {}, { slots: function slots() { return child.componentOptions.children; }, index: dynamicIndex })); dynamicIndex += 1; } else if (componentName && componentName === getVueComponentName(_OptionGroup)) { var _child$componentOptio, _child$componentOptio2, _child$componentOptio3; var groupOption = _objectSpread(_objectSpread({ group: (_child$componentOptio = child.componentOptions.propsData) === null || _child$componentOptio === void 0 ? void 0 : _child$componentOptio.label }, child.componentOptions.propsData), {}, { children: [] }); (_child$componentOptio2 = child.componentOptions.children) === null || _child$componentOptio2 === void 0 || (_child$componentOptio3 = _child$componentOptio2.forEach) === null || _child$componentOptio3 === void 0 || _child$componentOptio3.call(_child$componentOptio2, function (groupChild) { groupOption.children.push(_objectSpread(_objectSpread({ "class": groupChild.data.staticClass, style: groupChild.data.staticStyle }, groupChild.componentOptions.propsData), {}, { slots: function slots() { return groupChild.componentOptions.children; }, index: dynamicIndex })); dynamicIndex += 1; }); innerOptions.push(groupOption); } }); } options.value = innerOptions; }; var optionsMap = computed(function () { var res = /* @__PURE__ */new Map(); optionsCache.value.concat(optionsList.value).forEach(function (option) { res.set(option.value, option); }); return res; }); var optionsList = computed(function () { var res = []; var _getOptionsList = function getOptionsList(options2) { options2.forEach(function (option) { if (option.children) { _getOptionsList(option.children); } else { res.push(option); } }); }; _getOptionsList(options.value); return res; }); getOptions(); watch(function () { return props.options; }, function () { getOptions(); }); onBeforeUpdate(function () { if (props.options === void 0 && innerSlotRecord !== instance.proxy.$slots["default"]) { getOptions(); } }); return { options: options, optionsMap: optionsMap, optionsList: optionsList, optionsCache: optionsCache }; } export { useSelectOptions as default }; //# sourceMappingURL=useSelectOptions.js.map