| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { inject, ref, computed, unref, watch, onMounted } from 'vue';
- import { isUndefined } from 'lodash-unified';
- import { POPPER_INJECTION_KEY } from '../constants.mjs';
- import { buildPopperOptions, unwrapMeasurableEl } from '../utils.mjs';
- import { usePopper } from '../../../../hooks/use-popper/index.mjs';
- const DEFAULT_ARROW_OFFSET = 0;
- const usePopperContent = (props) => {
- const { popperInstanceRef, contentRef, triggerRef, role } = inject(POPPER_INJECTION_KEY, void 0);
- const arrowRef = ref();
- const arrowOffset = computed(() => props.arrowOffset);
- const eventListenerModifier = computed(() => {
- return {
- name: "eventListeners",
- enabled: !!props.visible
- };
- });
- const arrowModifier = computed(() => {
- var _a;
- const arrowEl = unref(arrowRef);
- const offset = (_a = unref(arrowOffset)) != null ? _a : DEFAULT_ARROW_OFFSET;
- return {
- name: "arrow",
- enabled: !isUndefined(arrowEl),
- options: {
- element: arrowEl,
- padding: offset
- }
- };
- });
- const options = computed(() => {
- return {
- onFirstUpdate: () => {
- update();
- },
- ...buildPopperOptions(props, [
- unref(arrowModifier),
- unref(eventListenerModifier)
- ])
- };
- });
- const computedReference = computed(() => unwrapMeasurableEl(props.referenceEl) || unref(triggerRef));
- const { attributes, state, styles, update, forceUpdate, instanceRef } = usePopper(computedReference, contentRef, options);
- watch(instanceRef, (instance) => popperInstanceRef.value = instance, {
- flush: "sync"
- });
- onMounted(() => {
- watch(() => {
- var _a, _b;
- return (_b = (_a = unref(computedReference)) == null ? void 0 : _a.getBoundingClientRect) == null ? void 0 : _b.call(_a);
- }, () => {
- update();
- });
- });
- return {
- attributes,
- arrowRef,
- contentRef,
- instanceRef,
- state,
- styles,
- role,
- forceUpdate,
- update
- };
- };
- export { usePopperContent };
- //# sourceMappingURL=use-content.mjs.map
|