842fc1559fbd44a1a579a22fd1d2a295e897d01fdb881034162ecbc60c01c0454ab1b91451f78230aaafd6b7a103d85893400928ad1ec08bba7d142e0e515a 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { defineComponent, ref, getCurrentInstance, provide, reactive, toRefs, computed, onMounted, withDirectives, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, renderSlot, vShow, isVNode } from 'vue';
  2. import { useMutationObserver } from '@vueuse/core';
  3. import { selectGroupKey } from './token.mjs';
  4. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  5. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  6. import { castArray } from 'lodash-unified';
  7. import { isArray } from '@vue/shared';
  8. const _sfc_main = defineComponent({
  9. name: "ElOptionGroup",
  10. componentName: "ElOptionGroup",
  11. props: {
  12. label: String,
  13. disabled: Boolean
  14. },
  15. setup(props) {
  16. const ns = useNamespace("select");
  17. const groupRef = ref();
  18. const instance = getCurrentInstance();
  19. const children = ref([]);
  20. provide(selectGroupKey, reactive({
  21. ...toRefs(props)
  22. }));
  23. const visible = computed(() => children.value.some((option) => option.visible === true));
  24. const isOption = (node) => {
  25. var _a;
  26. return node.type.name === "ElOption" && !!((_a = node.component) == null ? void 0 : _a.proxy);
  27. };
  28. const flattedChildren = (node) => {
  29. const nodes = castArray(node);
  30. const children2 = [];
  31. nodes.forEach((child) => {
  32. var _a;
  33. if (!isVNode(child))
  34. return;
  35. if (isOption(child)) {
  36. children2.push(child.component.proxy);
  37. } else if (isArray(child.children) && child.children.length) {
  38. children2.push(...flattedChildren(child.children));
  39. } else if ((_a = child.component) == null ? void 0 : _a.subTree) {
  40. children2.push(...flattedChildren(child.component.subTree));
  41. }
  42. });
  43. return children2;
  44. };
  45. const updateChildren = () => {
  46. children.value = flattedChildren(instance.subTree);
  47. };
  48. onMounted(() => {
  49. updateChildren();
  50. });
  51. useMutationObserver(groupRef, updateChildren, {
  52. attributes: true,
  53. subtree: true,
  54. childList: true
  55. });
  56. return {
  57. groupRef,
  58. visible,
  59. ns
  60. };
  61. }
  62. });
  63. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  64. return withDirectives((openBlock(), createElementBlock("ul", {
  65. ref: "groupRef",
  66. class: normalizeClass(_ctx.ns.be("group", "wrap"))
  67. }, [
  68. createElementVNode("li", {
  69. class: normalizeClass(_ctx.ns.be("group", "title"))
  70. }, toDisplayString(_ctx.label), 3),
  71. createElementVNode("li", null, [
  72. createElementVNode("ul", {
  73. class: normalizeClass(_ctx.ns.b("group"))
  74. }, [
  75. renderSlot(_ctx.$slots, "default")
  76. ], 2)
  77. ])
  78. ], 2)), [
  79. [vShow, _ctx.visible]
  80. ]);
  81. }
  82. var OptionGroup = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "option-group.vue"]]);
  83. export { OptionGroup as default };
  84. //# sourceMappingURL=option-group.mjs.map