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
6.7 KiB

1 month ago
  1. {"ast":null,"code":"import { inject, ref, computed, unref, watch, onMounted } from 'vue';\nimport { isUndefined } from 'lodash-unified';\nimport { POPPER_INJECTION_KEY } from '../constants.mjs';\nimport { buildPopperOptions, unwrapMeasurableEl } from '../utils.mjs';\nimport { usePopper } from '../../../../hooks/use-popper/index.mjs';\nconst DEFAULT_ARROW_OFFSET = 0;\nconst usePopperContent = props => {\n const {\n popperInstanceRef,\n contentRef,\n triggerRef,\n role\n } = inject(POPPER_INJECTION_KEY, void 0);\n const arrowRef = ref();\n const arrowOffset = ref();\n const eventListenerModifier = computed(() => {\n return {\n name: \"eventListeners\",\n enabled: !!props.visible\n };\n });\n const arrowModifier = computed(() => {\n var _a;\n const arrowEl = unref(arrowRef);\n const offset = (_a = unref(arrowOffset)) != null ? _a : DEFAULT_ARROW_OFFSET;\n return {\n name: \"arrow\",\n enabled: !isUndefined(arrowEl),\n options: {\n element: arrowEl,\n padding: offset\n }\n };\n });\n const options = computed(() => {\n return {\n onFirstUpdate: () => {\n update();\n },\n ...buildPopperOptions(props, [unref(arrowModifier), unref(eventListenerModifier)])\n };\n });\n const computedReference = computed(() => unwrapMeasurableEl(props.referenceEl) || unref(triggerRef));\n const {\n attributes,\n state,\n styles,\n update,\n forceUpdate,\n instanceRef\n } = usePopper(computedReference, contentRef, options);\n watch(instanceRef, instance => popperInstanceRef.value = instance);\n onMounted(() => {\n watch(() => {\n var _a;\n return (_a = unref(computedReference)) == null ? void 0 : _a.getBoundingClientRect();\n }, () => {\n update();\n });\n });\n return {\n attributes,\n arrowRef,\n contentRef,\n instanceRef,\n state,\n styles,\n role,\n forceUpdate,\n update\n };\n};\nexport { usePopperContent };","map":{"version":3,"names":["DEFAULT_ARROW_OFFSET","usePopperContent","props","popperInstanceRef","contentRef","triggerRef","role","inject","POPPER_INJECTION_KEY","arrowRef","ref","arrowOffset","eventListenerModifier","computed","name","enabled","visible","arrowModifier","_a","arrowEl","unref","offset","isUndefined","options","element","padding","onFirstUpdate","update","buildPopperOptions","computedReference","unwrapMeasurableEl","referenceEl","attributes","state","styles","forceUpdate","instanceRef","usePopper","watch","instance","value","onMounted","getBoundingClientRect"],"sources":["../../../../../../../packages/components/popper/src/composables/use-content.ts"],"sourcesContent":["import { computed, inject, onMounted, ref, unref, watch } from 'vue'\nimport { isUndefined } from 'lodash-unified'\nimport { usePopper } from '@element-plus/hooks'\nimport { POPPER_INJECTION_KEY } from '../constants'\nimport { buildPopperOptions, unwrapMeasurableEl } from '../utils'\n\nimport type { Modifier } from '@popperjs/core'\nimport type { PartialOptions } from '@element-plus/hooks'\nimport type { PopperContentProps } from '../content'\n\nconst DEFAULT_ARROW_OFFSET = 0\n\nexport const usePopperContent = (props: PopperContentProps) => {\n const { popperInstanceRef, contentRef, triggerRef, role } = inject(\n POPPER_INJECTION_KEY,\n undefined\n )!\n\n const arrowRef = ref<HTMLElement>()\n const arrowOffset = ref<number>()\n\n const eventListenerModifier = computed(() => {\n return {\n name: 'eventListeners',\n enabled: !!props.visible,\n } as Modifier<'eventListeners', any>\n })\n\n const arrowModifier = computed(() => {\n const arrowEl = unref(arrowRef)\n const offset = unref(arrowOffset) ?? DEFAULT_ARROW_OFFSET\n // Seems like the `phase` and `fn` is required by Modifier type\n // But on its documentation they didn't specify that.\n // Refer to https://popper.js.org/docs/v2/modifiers/arrow/\n return {\n name: 'arrow',\n enabled: !isUndefined(arrowEl),\n options: {\n element: arrowEl,\n p