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

{"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 padding: offset,\n },\n } as any\n })\n\n const options = computed<PartialOptions>(() => {\n return {\n onFirstUpdate: () => {\n update()\n },\n ...buildPopperOptions(props, [\n unref(arrowModifier),\n unref(eventListenerModifier),\n ]),\n }\n })\n\n const computedReference = computed(\n () => unwrapMeasurableEl(props.referenceEl) || unref(triggerRef)\n )\n\n const { attributes, state, styles, update, forceUpdate, instanceRef } =\n usePopper(computedReference, contentRef, options)\n\n watch(instanceRef, (instance) => (popperInstanceRef.value = instance))\n\n onMounted(() => {\n watch(\n () => unref(computedReference)?.getBoundingClientRect(),\n () => {\n update()\n }\n )\n })\n\n return {\n attributes,\n arrowRef,\n contentRef,\n instanceRef,\n state,\n styles,\n role,\n\n forceUpdate,\n update,\n }\n}\n\nexport type UsePopperContentReturn = ReturnType<typeof usePopperContent>\n"],"mappings":";;;;;AAKA,MAAMA,oBAAoB,GAAG,CAAC;AAClB,MAACC,gBAAgB,GAAIC,KAAK,IAAK;EACzC,MAAM;IAAEC,iBAAiB;IAAEC,UAAU;IAAEC,UAAU;IAAEC;EAAI,CAAE,GAAGC,MAAM,CAACC,oBAAoB,EAAE,KAAK,CAAC,CAAC;EAChG,MAAMC,QAAQ,GAAGC,GAAG,EAAE;EACtB,MAAMC,WAAW,GAAGD,GAAG,EAAE;EACzB,MAAME,qBAAqB,GAAGC,QAAQ,CAAC,MAAM;IAC3C,OAAO;MACLC,IAAI,EAAE,gBAAgB;MACtBC,OAAO,EAAE,CAAC,CAACb,KAAK,CAACc;IACvB,CAAK;EACL,CAAG,CAAC;EACF,MAAMC,aAAa,GAAGJ,QAAQ,CAAC,MAAM;IACnC,IAAIK,EAAE;IACN,MAAMC,OAAO,GAAGC,KAAK,CAACX,QAAQ,CAAC;IAC/B,MAAMY,MAAM,GAAG,CAACH,EAAE,GAAGE,KAAK,CAACT,WAAW,CAAC,KAAK,IAAI,GAAGO,EAAE,GAAGlB,oBAAoB;IAC5E,OAAO;MACLc,IAAI,EAAE,OAAO;MACbC,OAAO,EAAE,CAACO,WAAW,CAACH,OAAO,CAAC;MAC9BI,OAAO,EAAE;QACPC,OAAO,EAAEL,OAAO;QAChBM,OAAO,EAAEJ;MACjB;IACA,CAAK;EACL,CAAG,CAAC;EACF,MAAME,OAAO,GAAGV,QAAQ,CAAC,MAAM;IAC7B,OAAO;MACLa,aAAa,EAAEA,CAAA,KAAM;QACnBC,MAAM,EAAE;MAChB,CAAO;MACD,GAAGC,kBAAkB,CAAC1B,KAAK,EAAE,CA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