1bed0df68f64a8cf09381699a97e8d7d017eb952c774bb45c17830a17ba863d4ef39e145a281f74a49ba71b22285f6eacf80671111e38665510ff3f0ae6813 2.9 KB

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