options.mjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { isArray, isFunction, isString } from "../../../utils/types.mjs";
  2. import { selectKey } from "./token.mjs";
  3. import { isEqual } from "lodash-unified";
  4. import { defineComponent, inject } from "vue";
  5. //#region ../../packages/components/select/src/options.ts
  6. var options_default = defineComponent({
  7. name: "ElOptions",
  8. setup(_, { slots }) {
  9. const select = inject(selectKey);
  10. let cachedValueList = [];
  11. return () => {
  12. const children = slots.default?.();
  13. const valueList = [];
  14. function filterOptions(children) {
  15. if (!isArray(children)) return;
  16. children.forEach((item) => {
  17. const name = (item?.type || {})?.name;
  18. if (name === "ElOptionGroup") filterOptions(!isString(item.children) && !isArray(item.children) && isFunction(item.children?.default) ? item.children?.default() : item.children);
  19. else if (name === "ElOption") valueList.push(item.props?.value);
  20. else if (isArray(item.children)) filterOptions(item.children);
  21. });
  22. }
  23. if (children.length) filterOptions(children[0]?.children);
  24. if (!isEqual(valueList, cachedValueList)) {
  25. cachedValueList = valueList;
  26. if (select) select.states.optionValues = valueList;
  27. }
  28. return children;
  29. };
  30. }
  31. });
  32. //#endregion
  33. export { options_default as default };
  34. //# sourceMappingURL=options.mjs.map