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

1 month ago
  1. {"ast":null,"code":"import { unref, ref, onMounted, watchEffect, isRef } from 'vue';\nimport { isClient, unrefElement } from '@vueuse/core';\nimport { isNil } from 'lodash-unified';\nimport { arrow, computePosition } from '@floating-ui/dom';\nimport { keysOf } from '../../utils/objects.mjs';\nimport { buildProps } from '../../utils/vue/props/runtime.mjs';\nconst useFloatingProps = buildProps({});\nconst unrefReference = elRef => {\n if (!isClient) return;\n if (!elRef) return elRef;\n const unrefEl = unrefElement(elRef);\n if (unrefEl) return unrefEl;\n return isRef(elRef) ? unrefEl : elRef;\n};\nconst getPositionDataWithUnit = (record, key) => {\n const value = record == null ? void 0 : record[key];\n return isNil(value) ? \"\" : `${value}px`;\n};\nconst useFloating = ({\n middleware,\n placement,\n strategy\n}) => {\n const referenceRef = ref();\n const contentRef = ref();\n const x = ref();\n const y = ref();\n const middlewareData = ref({});\n const states = {\n x,\n y,\n placement,\n strategy,\n middlewareData\n };\n const update = async () => {\n if (!isClient) return;\n const referenceEl = unrefReference(referenceRef);\n const contentEl = unrefElement(contentRef);\n if (!referenceEl || !contentEl) return;\n const data = await computePosition(referenceEl, contentEl, {\n placement: unref(placement),\n strategy: unref(strategy),\n middleware: unref(middleware)\n });\n keysOf(states).forEach(key => {\n states[key].value = data[key];\n });\n };\n onMounted(() => {\n watchEffect(() => {\n update();\n });\n });\n return {\n ...states,\n update,\n referenceRef,\n contentRef\n };\n};\nconst arrowMiddleware = ({\n arrowRef,\n padding\n}) => {\n return {\n name: \"arrow\",\n options: {\n element: arrowRef,\n padding\n },\n fn(args) {\n const arrowEl = unref(arrowRef);\n if (!arrowEl) return {};\n return arrow({\n element: arrowEl,\n padding\n }).fn(args);\n }\n };\n};\nexport { arrowMiddleware, getPositionDataWithUnit, useFloating, useFloatingProps };","map":{"version":3,"names":["useFloatingProps","buildProps","unrefReference","elRef","isClient","unrefEl","unrefElement","isRef","getPositionDataWithUnit","record","key","value","isNil","useFloating","middleware","placement","strategy","referenceRef","ref","contentRef","x","y","middlewareData","states","update","referenceEl","contentEl","data","computePosition","unref","keysOf","forEach","onMounted","watchEffect","arrowMiddleware","arrowRef","padding","name","options","element","fn","args","arrowEl","arrow"],"sources":["../../../../../packages/hooks/use-floating/index.ts"],"sourcesContent":["import { isRef, onMounted, ref, unref, watchEffect } from 'vue'\nimport { unrefElement } from '@vueuse/core'\nimport { isNil } from 'lodash-unified'\nimport { arrow as arrowCore, computePosition } from '@floating-ui/dom'\nimport { buildProps, isClient, keysOf } from '@element-plus/utils'\n\nimport type { Ref, ToRefs } from 'vue'\nimport type {\n ComputePositionReturn,\n Middleware,\n Placement,\n SideObject,\n Strategy,\n VirtualElement,\n} from '@floating-ui/dom'\n\nexport const useFloatingProps = buildProps({} as const)\n\nexport type UseFloatingProps = ToRefs<{\n middleware: Array<Middleware>\n placement: Placement\n strategy: Strategy\n}>\n\ntype ElementRef = Parameters<typeof unrefElement>['0']\n\nconst unrefReference = (\n elRef: ElementRef | Ref<VirtualElement | undefined>\n) => {\n if (!isClient) return\n if (!elRef) return elRef\n const unrefEl = unrefElement(elRef as ElementRef)\n if (unrefEl) return unrefEl\n return isRef(elRef) ? unrefEl : (elRef as VirtualElement)\n}\n\nexport const getPositionDataWithUnit = <T extends Record<string, number>>(\n record: T | undefined,\n key: keyof T\n) => {\n const value = record?.[key]\n return isNil(value) ? '' : `${value}px`\n}\n\nexport const useFloating = ({\n middleware,\n placement,\n strategy,\n}: UseFloatingProps) => {\n const referenceRef = ref<