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.

1 lines
7.8 KiB

{"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 defineComponent,\n getCurrentInstance,\n onMounted,\n provide,\n reactive,\n ref,\n toRefs,\n} from 'vue'\nimport { useMutationObserver } from '@vueuse/core'\nimport { ensureArray } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { selectGroupKey } from './token'\n\nexport default defineComponent({\n name: 'ElOptionGroup',\n componentName: 'ElOptionGroup',\n\n props: {\n /**\n * @description name of the group\n */\n label: String,\n /**\n * @description whether to disable all options in this group\n */\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\n provide(\n selectGroupKey,\n reactive({\n ...toRefs(props),\n })\n )\n\n const visible = computed(() =>\n children.value.some((option) => option.visible === true)\n )\n\n const isOption = (node) =>\n node.type?.name === 'ElOption' && !!node.component?.proxy\n\n // get all instances of options\n const flattedChildren = (node) => {\n const Nodes = ensureArray(node)\n const children = []\n\n Nodes.forEach((child) => {\n if (isOption(child)) {\n children.push(child.component.proxy)\n } else if (child.children?.length) {\n children.push(...flattedChildren(child.children))\n } else if (child.component?.subTree) {\n children.push(...flattedChildren(child.component.subTree))\n }\n })\n\n return children\n }\n\n const updateChildren = () => {\n children.value = flattedChildren(instance.subTree)\n }\n\n onMounted(() => {\n updateChildren()\n })\n\n useMutationObserver(groupRef, updateChildren, {\n attributes: true,\n subtree: true,\n childList: true,\n })\n\n return {\n groupRef,\n visible,\n ns,\n }\n },\n})\n</script>\n"],"mappings":";;;;;;AA4BA,MAAKA,SAAA,GAAaC,eAAa;EAC7BC,IAAM;EACNC,aAAe;EAEfC,KAAO;IAAAC,KAAA,EAAAC,MAAA;IAAAC,QAAA,EAAAC;EAAA;EAAAC,KAIEA,CAAAL,KAAA;IAAA,MAAAM,EAAA,GAAAC,YAAA;IAAA,MAAAC,QAAA,GAAAC,GAAA;IAAA,MAAAC,QAAA,GAAAC,kBAAA;IAIP,MAAUC,QAAA,GAAAH,GAAA;IACZI,OAAA,CAAAC,cAAA,EAAAC,QAAA;MAAA,GACaC,MAAA,CAAAhB,KAAA;IACX,CAAM;IACA,MAAAiB,OAAA,GAAAC,QAAmB,OAAAN,QAAA,CAAAO,KAAA,CAAAC,IAAA,CAAAC,MAAA,IAAAA,MAAA,CAAAJ,OAAA;IACzB,MAAMK,QAAA,GAA8BC,IAAA;MAC9B,IAAAC,EAAA,EAAAC,EAAA;MAEN,SAAAD,EAAA,GAAAD,IAAA,CAAAG,IAAA,qBAAAF,EAAA,CAAA1B,IAAA,wBAAA2B,EAAA,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