You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
7.8 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, ref, getCurrentInstance, provide, reactive, toRefs, computed, onMounted, withDirectives, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, renderSlot, vShow } from 'vue';\nimport { useMutationObserver } from '@vueuse/core';\nimport { selectGroupKey } from './token.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { castArray } from 'lodash-unified';\nconst _sfc_main = defineComponent({\n name: \"ElOptionGroup\",\n componentName: \"ElOptionGroup\",\n props: {\n label: String,\n disabled: Boolean\n },\n setup(props) {\n const ns = useNamespace(\"select\");\n const groupRef = ref(null);\n const instance = getCurrentInstance();\n const children = ref([]);\n provide(selectGroupKey, reactive({\n ...toRefs(props)\n }));\n const visible = computed(() => children.value.some(option => option.visible === true));\n const isOption = node => {\n var _a, _b;\n return ((_a = node.type) == null ? void 0 : _a.name) === \"ElOption\" && !!((_b = node.component) == null ? void 0 : _b.proxy);\n };\n const flattedChildren = node => {\n const Nodes = castArray(node);\n const children2 = [];\n Nodes.forEach(child => {\n var _a, _b;\n if (isOption(child)) {\n children2.push(child.component.proxy);\n } else if ((_a = child.children) == null ? void 0 : _a.length) {\n children2.push(...flattedChildren(child.children));\n } else if ((_b = child.component) == null ? void 0 : _b.subTree) {\n children2.push(...flattedChildren(child.component.subTree));\n }\n });\n return children2;\n };\n const updateChildren = () => {\n children.value = flattedChildren(instance.subTree);\n };\n onMounted(() => {\n updateChildren();\n });\n useMutationObserver(groupRef, updateChildren, {\n attributes: true,\n subtree: true,\n childList: true\n });\n return {\n groupRef,\n visible,\n ns\n };\n }\n});\nfunction _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {\n return withDirectives((openBlock(), createElementBlock(\"ul\", {\n ref: \"groupRef\",\n class: normalizeClass(_ctx.ns.be(\"group\", \"wrap\"))\n }, [createElementVNode(\"li\", {\n class: normalizeClass(_ctx.ns.be(\"group\", \"title\"))\n }, toDisplayString(_ctx.label), 3), createElementVNode(\"li\", null, [createElementVNode(\"ul\", {\n class: normalizeClass(_ctx.ns.b(\"group\"))\n }, [renderSlot(_ctx.$slots, \"default\")], 2)])], 2)), [[vShow, _ctx.visible]]);\n}\nvar OptionGroup = /* @__PURE__ */_export_sfc(_sfc_main, [[\"render\", _sfc_render], [\"__file\", \"option-group.vue\"]]);\nexport { OptionGroup as default };","map":{"version":3,"names":["_sfc_main","defineComponent","name","componentName","props","label","String","disabled","Boolean","setup","ns","useNamespace","groupRef","ref","instance","getCurrentInstance","children","provide","selectGroupKey","reactive","toRefs","visible","computed","value","some","option","isOption","node","_a","_b","type","component","proxy","flattedChildren","Nodes","castArray","children2","forEach","child","push","length","subTree","updateChildren","onMounted","useMutationObserver","attributes","subtree","childList","_sfc_render","_ctx","_cache","$props","$setup","$data","$options","withDirectives","openBlock","createElementBlock","class","normalizeClass","be","createElementVNode","b","renderSlot","$slots","vShow","_export_sfc"],"sources":["../../../../../../packages/components/select/src/option-group.vue"],"sourcesContent":["<template>\n <ul v-show=\"visible\" ref=\"groupRef\" :class=\"ns.be('group', 'wrap')\">\n <li :class=\"ns.be('group', 'title')\">{{ label }}</li>\n <li>\n <ul :class=\"ns.b('group')\">\n <slot />\n </ul>\n </li>\n </ul>\n</template>\n\n<script lang=\"ts\">\n// @ts-nocheck\nimport {\n computed,\n defineCom