43dfb235f08d6f30c5b434689d4014a806fff3ddab2397ee8fc03e63911a3ce539c74d8750967220616eca024352a391960e4e335476018a80fd458b29c88a 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { defineComponent, inject } from 'vue';
  2. import { isEqual } from 'lodash-unified';
  3. import { selectKey } from './token.mjs';
  4. import { isArray, isString, isFunction } from '@vue/shared';
  5. var ElOptions = defineComponent({
  6. name: "ElOptions",
  7. setup(_, { slots }) {
  8. const select = inject(selectKey);
  9. let cachedValueList = [];
  10. return () => {
  11. var _a, _b;
  12. const children = (_a = slots.default) == null ? void 0 : _a.call(slots);
  13. const valueList = [];
  14. function filterOptions(children2) {
  15. if (!isArray(children2))
  16. return;
  17. children2.forEach((item) => {
  18. var _a2, _b2, _c, _d;
  19. const name = (_a2 = (item == null ? void 0 : item.type) || {}) == null ? void 0 : _a2.name;
  20. if (name === "ElOptionGroup") {
  21. 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);
  22. } else if (name === "ElOption") {
  23. valueList.push((_d = item.props) == null ? void 0 : _d.value);
  24. } else if (isArray(item.children)) {
  25. filterOptions(item.children);
  26. }
  27. });
  28. }
  29. if (children.length) {
  30. filterOptions((_b = children[0]) == null ? void 0 : _b.children);
  31. }
  32. if (!isEqual(valueList, cachedValueList)) {
  33. cachedValueList = valueList;
  34. if (select) {
  35. select.states.optionValues = valueList;
  36. }
  37. }
  38. return children;
  39. };
  40. }
  41. });
  42. export { ElOptions as default };
  43. //# sourceMappingURL=options.mjs.map