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
11 KiB
1 lines
11 KiB
{"ast":null,"code":"import { defineComponent, inject, computed, openBlock, createElementBlock, normalizeClass, normalizeStyle, withModifiers, renderSlot, unref } from 'vue';\nimport { DROPDOWN_INJECTION_KEY } from './tokens.mjs';\nimport { dropdownMenuProps, DROPDOWN_COLLECTION_INJECTION_KEY as COLLECTION_INJECTION_KEY, FIRST_LAST_KEYS, LAST_KEYS } from './dropdown.mjs';\nimport { useDropdown } from './useDropdown.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { ROVING_FOCUS_GROUP_INJECTION_KEY } from '../../roving-focus-group/src/tokens.mjs';\nimport { ROVING_FOCUS_COLLECTION_INJECTION_KEY as COLLECTION_INJECTION_KEY$1 } from '../../roving-focus-group/src/roving-focus-group.mjs';\nimport { focusFirst } from '../../roving-focus-group/src/utils.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { FOCUS_TRAP_INJECTION_KEY } from '../../focus-trap/src/tokens.mjs';\nimport { composeRefs } from '../../../utils/vue/refs.mjs';\nimport { composeEventHandlers } from '../../../utils/dom/event.mjs';\nimport { EVENT_CODE } from '../../../constants/aria.mjs';\nconst _sfc_main = defineComponent({\n name: \"ElDropdownMenu\",\n props: dropdownMenuProps,\n setup(props) {\n const ns = useNamespace(\"dropdown\");\n const {\n _elDropdownSize\n } = useDropdown();\n const size = _elDropdownSize.value;\n const {\n focusTrapRef,\n onKeydown\n } = inject(FOCUS_TRAP_INJECTION_KEY, void 0);\n const {\n contentRef,\n role,\n triggerId\n } = inject(DROPDOWN_INJECTION_KEY, void 0);\n const {\n collectionRef: dropdownCollectionRef,\n getItems\n } = inject(COLLECTION_INJECTION_KEY, void 0);\n const {\n rovingFocusGroupRef,\n rovingFocusGroupRootStyle,\n tabIndex,\n onBlur,\n onFocus,\n onMousedown\n } = inject(ROVING_FOCUS_GROUP_INJECTION_KEY, void 0);\n const {\n collectionRef: rovingFocusGroupCollectionRef\n } = inject(COLLECTION_INJECTION_KEY$1, void 0);\n const dropdownKls = computed(() => {\n return [ns.b(\"menu\"), ns.bm(\"menu\", size == null ? void 0 : size.value)];\n });\n const dropdownListWrapperRef = composeRefs(contentRef, dropdownCollectionRef, focusTrapRef, rovingFocusGroupRef, rovingFocusGroupCollectionRef);\n const composedKeydown = composeEventHandlers(e => {\n var _a;\n (_a = props.onKeydown) == null ? void 0 : _a.call(props, e);\n }, e => {\n const {\n currentTarget,\n code,\n target\n } = e;\n currentTarget.contains(target);\n if (EVENT_CODE.tab === code) {\n e.stopImmediatePropagation();\n }\n e.preventDefault();\n if (target !== unref(contentRef) || !FIRST_LAST_KEYS.includes(code)) return;\n const items = getItems().filter(item => !item.disabled);\n const targets = items.map(item => item.ref);\n if (LAST_KEYS.includes(code)) {\n targets.reverse();\n }\n focusFirst(targets);\n });\n const handleKeydown = e => {\n composedKeydown(e);\n onKeydown(e);\n };\n return {\n size,\n rovingFocusGroupRootStyle,\n tabIndex,\n dropdownKls,\n role,\n triggerId,\n dropdownListWrapperRef,\n handleKeydown,\n onBlur,\n onFocus,\n onMousedown\n };\n }\n});\nfunction _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {\n return openBlock(), createElementBlock(\"ul\", {\n ref: _ctx.dropdownListWrapperRef,\n class: normalizeClass(_ctx.dropdownKls),\n style: normalizeStyle(_ctx.rovingFocusGroupRootStyle),\n tabindex: -1,\n role: _ctx.role,\n \"aria-labelledby\": _ctx.triggerId,\n onBlur: _ctx.onBlur,\n onFocus: _ctx.onFocus,\n onKeydown: withModifiers(_ctx.handleKeydown, [\"self\"]),\n onMousedown: withModifiers(_ctx.onMousedown, [\"self\"])\n }, [renderSlot(_ctx.$slots, \"default\")], 46, [\"role\", \"aria-labelledby\", \"onBlur\", \"onFocus\", \"onKeydown\", \"onMousedown\"]);\n}\nvar DropdownMenu = /* @__PURE__ */_export_sfc(_sfc_main, [[\"render\", _sfc_render], [\"__file\", \"dropdown-menu.vue\"]]);\nexport { DropdownMenu as default };","map":{"version":3,"names":["_sfc_main","defineComponent","name","props","dropdownMenuProps","setup","ns","useNamespace","_elDropdownSize","useDropdown","size","value","focusTrapRef","onKeydown","inject","FOCUS_TRAP_INJECTION_KEY","contentRef","role","triggerId","DROPDOWN_INJECTION_KEY","collectionRef","dropdownCollectionRef","getItems","COLLECTION_INJECTION_KEY","rovingFocusGroupRef","rovingFocusGroupRootStyle","tabIndex","onBlur","onFocus","onMousedown","ROVING_FOCUS_GROUP_INJECTION_KEY","rovingFocusGroupCollectionRef","COLLECTION_INJECTION_KEY$1","dropdownKls","computed","b","bm","dropdownListWrapperRef","composeRefs","composedKeydown","composeEventHandlers","e","_a","call","currentTarget","code","target","contains","EVENT_CODE","tab","stopImmediatePropagation","preventDefault","unref","FIRST_LAST_KEYS","includes","items","filter","item","disabled","targets","map","ref","LAST_KEYS","reverse","focusFirst","handleKeydown","_sfc_render","_ctx","_cache","$props","$setup","$data","$options","openBlock","createElementBlock","class","normalizeClass","style","normalizeStyle","tabindex","withModifiers","renderSlot","$slots","DropdownMenu","_export_sfc"],"sources":["../../../../../../packages/components/dropdown/src/dropdown-menu.vue"],"sourcesContent":["<template>\n <ul\n :ref=\"dropdownListWrapperRef\"\n :class=\"dropdownKls\"\n :style=\"rovingFocusGroupRootStyle\"\n :tabindex=\"-1\"\n :role=\"role\"\n :aria-labelledby=\"triggerId\"\n @blur=\"onBlur\"\n @focus=\"onFocus\"\n @keydown.self=\"handleKeydown\"\n @mousedown.self=\"onMousedown\"\n >\n <slot />\n </ul>\n</template>\n<script lang=\"ts\">\n// @ts-nocheck\nimport { computed, defineComponent, inject, unref } from 'vue'\nimport { composeEventHandlers, composeRefs } from '@element-plus/utils'\nimport { EVENT_CODE } from '@element-plus/constants'\nimport { FOCUS_TRAP_INJECTION_KEY } from '@element-plus/components/focus-trap'\nimport {\n ROVING_FOCUS_COLLECTION_INJECTION_KEY,\n ROVING_FOCUS_GROUP_INJECTION_KEY,\n focusFirst,\n} from '@element-plus/components/roving-focus-group'\nimport { useNamespace } from '@element-plus/hooks'\nimport { DROPDOWN_INJECTION_KEY } from './tokens'\nimport {\n DROPDOWN_COLLECTION_INJECTION_KEY,\n FIRST_LAST_KEYS,\n LAST_KEYS,\n dropdownMenuProps,\n} from './dropdown'\nimport { useDropdown } from './useDropdown'\n\nexport default defineComponent({\n name: 'ElDropdownMenu',\n props: dropdownMenuProps,\n setup(props) {\n const ns = useNamespace('dropdown')\n const { _elDropdownSize } = useDropdown()\n const size = _elDropdownSize.value\n\n const { focusTrapRef, onKeydown } = inject(\n FOCUS_TRAP_INJECTION_KEY,\n undefined\n )!\n\n const { contentRef, role, triggerId } = inject(\n DROPDOWN_INJECTION_KEY,\n undefined\n )!\n\n const { collectionRef: dropdownCollectionRef, getItems } = inject(\n DROPDOWN_COLLECTION_INJECTION_KEY,\n undefined\n )!\n\n const {\n rovingFocusGroupRef,\n rovingFocusGroupRootStyle,\n tabIndex,\n onBlur,\n onFocus,\n onMousedown,\n } = inject(ROVING_FOCUS_GROUP_INJECTION_KEY, undefined)!\n\n const { collectionRef: rovingFocusGroupCollectionRef } = inject(\n ROVING_FOCUS_COLLECTION_INJECTION_KEY,\n undefined\n )!\n\n const dropdownKls = computed(() => {\n return [ns.b('menu'), ns.bm('menu', size?.value)]\n })\n\n const dropdownListWrapperRef = composeRefs(\n contentRef,\n dropdownCollectionRef,\n focusTrapRef,\n rovingFocusGroupRef,\n rovingFocusGroupCollectionRef\n )\n\n const composedKeydown = composeEventHandlers(\n (e: KeyboardEvent) => {\n props.onKeydown?.(e)\n },\n (e) => {\n const { currentTarget, code, target } = e\n const isKeydownContained = (currentTarget as Node).contains(\n target as Node\n )\n\n if (isKeydownContained) {\n // TODO: implement typeahead search\n }\n\n if (EVENT_CODE.tab === code) {\n e.stopImmediatePropagation()\n }\n\n e.preventDefault()\n\n if (target !== unref(contentRef) || !FIRST_LAST_KEYS.includes(code))\n return\n const items = getItems<{ disabled: boolean }>().filter(\n (item) => !item.disabled\n )\n const targets = items.map((item) => item.ref!)\n if (LAST_KEYS.includes(code)) {\n targets.reverse()\n }\n focusFirst(targets)\n }\n )\n\n const handleKeydown = (e: KeyboardEvent) => {\n composedKeydown(e)\n onKeydown(e)\n }\n\n return {\n size,\n rovingFocusGroupRootStyle,\n tabIndex,\n dropdownKls,\n role,\n triggerId,\n dropdownListWrapperRef,\n handleKeydown,\n onBlur,\n onFocus,\n onMousedown,\n }\n },\n})\n</script>\n"],"mappings":";;;;;;;;;;;;;AAqCA,MAAKA,SAAA,GAAaC,eAAa;EAC7BC,IAAM;EACNC,KAAO,EAAAC,iBAAA;EACPC,MAAMF,KAAO;IACL,MAAAG,EAAA,GAAKC,YAAA,CAAa,UAAU;IAC5B;MAAEC;IAAgB,IAAIC,WAAY;IACxC,MAAMC,IAAA,GAAOF,eAAgB,CAAAG,KAAA;IAEvB;MAAEC,YAAc;MAAAC;IAAA,CAAc,GAAAC,MAAA,CAAAC,wBAAA;IAClC;MAAAC,UAAA;MAAAC,IAAA;MAAAC;IAAA,IAAAJ,MAAA,CAAAK,sBAAA;IACA;MAAAC,aAAA,EAAAC,qBAAA;MAAAC;IAAA,IAAAR,MAAA,CAAAS,wBAAA;IACF;MAEAC,mBAA0B;MACxBC,yBAAA;MACAC,QAAA;MACFC,MAAA;MAEAC,OAAQ;MACNC;IAAA,CACA,GAAAf,MAAA,CAAAgB,gCAAA;IACF;MAAAV,aAAA,EAAAW;IAAA,IAAAjB,MAAA,CAAAkB,0BAAA;IAEM,MAAAC,WAAA,GAAAC,QAAA;MACJ,QAAA5B,EAAA,CAAA6B,CAAA,UAAA7B,EAAA,CAAA8B,EAAA,SAAA1B,IAAA,oBAAAA,IAAA,CAAAC,KAAA;IAAA,CACA;IACA,MAAA0B,sBAAA,GAAAC,WAAA,CAAAtB,UAAA,EAAAK,qBAAA,EAAAT,YAAA,EAAAY,mBAAA,EAAAO,6BAAA;IACA,MAAAQ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