1 line
26 KiB
Plaintext
1 line
26 KiB
Plaintext
|
|
{"version":3,"file":"sub-menu.mjs","sources":["../../../../../../packages/components/menu/src/sub-menu.ts"],"sourcesContent":["import {\n Fragment,\n computed,\n defineComponent,\n getCurrentInstance,\n h,\n inject,\n nextTick,\n onBeforeUnmount,\n onMounted,\n provide,\n reactive,\n ref,\n vShow,\n watch,\n withDirectives,\n} from 'vue'\nimport { useTimeoutFn } from '@vueuse/core'\nimport ElCollapseTransition from '@element-plus/components/collapse-transition'\nimport ElTooltip from '@element-plus/components/tooltip'\nimport {\n buildProps,\n focusElement,\n iconPropType,\n isString,\n isUndefined,\n throwError,\n} from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { ArrowDown, ArrowRight } from '@element-plus/icons-vue'\nimport { ElIcon } from '@element-plus/components/icon'\nimport useMenu from './use-menu'\nimport { useMenuCssVar } from './use-menu-css-var'\nimport { MENU_INJECTION_KEY, SUB_MENU_INJECTION_KEY } from './tokens'\n\nimport type { Placement } from '@element-plus/components/popper'\nimport type { TooltipInstance } from '@element-plus/components/tooltip'\nimport type {\n ExtractPropTypes,\n VNodeArrayChildren,\n __ExtractPublicPropTypes,\n} from 'vue'\nimport type { MenuProvider, SubMenuProvider } from './types'\n\nexport const subMenuProps = buildProps({\n /**\n * @description unique identification\n */\n index: {\n type: String,\n required: true,\n },\n /**\n * @description timeout before showing a sub-menu(inherit `show-timeout` of the menu by default.)\n */\n showTimeout: Number,\n /**\n * @description timeout before hiding a sub-menu(inherit `hide-timeout` of the menu by default.)\n */\n hideTimeout: Number,\n /**\n * @description custom class name for the popup menu\n */\n popperClass: String,\n /**\n * @description whether the sub-menu is disabled\n */\n disabled: Boolean,\n /**\n * @description whether popup menu is teleported to the body\n */\n teleported: {\n type: Boolean,\n default: undefined,\n },\n /**\n * @description offset of the popper (overrides the `popper` of menu)\n */\n popperOffset: Number,\n /**\n * @description Icon when menu are expanded and submenu are closed, `expand-close-icon` and `expand-open-icon` need to be passed together to take effect\n */\n expandCloseIcon: {\n type: iconPropType,\n },\n /**\n * @description Icon when menu are expanded and submenu are opened, `expand-open-icon` and `expand-close-icon` need to be passed together to take effect\n */\n expandOpenIcon: {\n type: iconPropType,\n },\n /**\n * @description Icon when menu are collapsed and submenu are closed, `collapse-close-icon` and `collapse-open-icon` need to be passed together to take effect\n */\n collapseCloseIcon: {\n type: iconPropType,\n },\n /**\n * @description Icon when menu are collapsed and submenu are opened, `collapse-open-icon` and `collapse-close-icon` need to be passed together to take effect\n */\n collapseOpenIcon: {\n type: iconPropType,\n },\n} as const)\nexport type SubMenuProps = ExtractPropTypes<typeof subMenuProps>\nexport type SubMenuPropsPublic = __ExtractPublicPropTypes<typeof subMenuProps>\n\nconst COMPONENT_NAME = 'ElSubMenu'\nexport default defineComponent({\n name: COMPONENT_NAME,\n props: subMenuProps,\n\n setup(props, { slots, expose }) {\n const instance = getCurrentInstance()!\n const { indexPath, parentMenu } = useMenu(\n instance,\n computed(() => props.index)\n )\n const nsMenu = useNamespace('menu')\n const nsSubMenu = useNamespace('sub-menu')\n\n // inject\n const rootMenu = inject<MenuProvider>(MENU_INJECTION_KEY)\n if (!rootMenu) throwError(COMPONENT_NAME, 'can not inject root menu')\n\n const subMenu = inject<SubMenuProvider>(\n `${SUB_MENU_INJECTION_KEY}${parentMenu.value!.uid}`\n )\n if (!subMenu) throwError(COMPONENT_NAME, 'can not inject sub menu')\n\n const items = ref<MenuProvider['items']>({})\n const subMenus = ref<MenuProvider['subMenus']>({})\n
|