UNPKG

@element-plus-next/vue-hooks

Version:
1,107 lines (1,076 loc) 33.6 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { FORWARD_REF_INJECTION_KEY: () => FORWARD_REF_INJECTION_KEY, ID_INJECTION_KEY: () => ID_INJECTION_KEY, POPPER_CONTAINER_ID: () => POPPER_CONTAINER_ID, POPPER_CONTAINER_SELECTOR: () => POPPER_CONTAINER_SELECTOR, arrowMiddleware: () => arrowMiddleware, buildLocaleContext: () => buildLocaleContext, buildTranslator: () => buildTranslator, createModelToggleComposable: () => createModelToggleComposable, defaultNamespace: () => defaultNamespace, getPositionDataWithUnit: () => getPositionDataWithUnit, translate: () => translate, useAttrs: () => useAttrs, useCursor: () => useCursor, useDelayedRender: () => useDelayedRender, useDelayedToggle: () => useDelayedToggle, useDelayedToggleProps: () => useDelayedToggleProps, useDeprecated: () => useDeprecated, useDisabled: () => useDisabled, useDraggable: () => useDraggable, useEscapeKeydown: () => useEscapeKeydown, useFloating: () => useFloating, useFloatingProps: () => useFloatingProps, useFocus: () => useFocus, useForwardRef: () => useForwardRef, useForwardRefDirective: () => useForwardRefDirective, useId: () => useId, useLocale: () => useLocale, useLockscreen: () => useLockscreen, useModal: () => useModal, useModelToggle: () => useModelToggle, useModelToggleEmits: () => useModelToggleEmits, useModelToggleProps: () => useModelToggleProps, useNamespace: () => useNamespace, usePopperContainer: () => usePopperContainer, usePreventGlobal: () => usePreventGlobal, useProp: () => useProp, useRestoreActive: () => useRestoreActive, useSameTarget: () => useSameTarget, useSize: () => useSize, useSizeProp: () => useSizeProp, useTeleport: () => useTeleport, useThrottleRender: () => useThrottleRender, useTimeout: () => useTimeout, useTransitionFallthrough: () => useTransitionFallthrough, useTransitionFallthroughEmits: () => useTransitionFallthroughEmits, useZIndex: () => useZIndex }); module.exports = __toCommonJS(src_exports); // src/use-attrs/index.ts var import_vue = require("vue"); var import_lodash_unified = require("lodash-unified"); var import_utils = require("@element-plus-next/utils"); var DEFAULT_EXCLUDE_KEYS = ["class", "style"]; var LISTENER_PREFIX = /^on[A-Z]/; var useAttrs = (params = {}) => { const { excludeListeners = false, excludeKeys } = params; const allExcludeKeys = (0, import_vue.computed)(() => { return ((excludeKeys == null ? void 0 : excludeKeys.value) || []).concat(DEFAULT_EXCLUDE_KEYS); }); const instance = (0, import_vue.getCurrentInstance)(); if (!instance) { (0, import_utils.debugWarn)( "use-attrs", "getCurrentInstance() returned null. useAttrs() must be called at the top of a setup function" ); return (0, import_vue.computed)(() => ({})); } return (0, import_vue.computed)( () => { var _a; return (0, import_lodash_unified.fromPairs)( Object.entries((_a = instance.proxy) == null ? void 0 : _a.$attrs).filter( ([key]) => !allExcludeKeys.value.includes(key) && !(excludeListeners && LISTENER_PREFIX.test(key)) ) ); } ); }; // src/use-common-props/index.ts var import_vue3 = require("vue"); var import_vue_utils = require("@element-plus-next/vue-utils"); var import_constants = require("@element-plus-next/constants"); var import_vue_context = require("@element-plus-next/vue-context"); // src/use-prop/index.ts var import_vue2 = require("vue"); var useProp = (name) => { const vm = (0, import_vue2.getCurrentInstance)(); return (0, import_vue2.computed)(() => { var _a, _b; return (_b = ((_a = vm.proxy) == null ? void 0 : _a.$props)[name]) != null ? _b : void 0; }); }; // src/use-common-props/index.ts var useSizeProp = (0, import_vue_utils.buildProp)({ type: String, values: import_constants.componentSizes, required: false }); var useSize = (fallback, ignore = {}) => { const emptyRef = (0, import_vue3.ref)(void 0); const size = ignore.prop ? emptyRef : useProp("size"); const globalConfig = ignore.global ? emptyRef : (0, import_vue_context.useGlobalConfig)("size"); return (0, import_vue3.computed)( () => size.value || (0, import_vue3.unref)(fallback) || globalConfig.value || "" ); }; var useDisabled = (fallback) => { const disabled = useProp("disabled"); return (0, import_vue3.computed)( () => disabled.value || (0, import_vue3.unref)(fallback) || false ); }; // src/use-deprecated/index.ts var import_vue4 = require("vue"); var import_utils2 = require("@element-plus-next/utils"); var useDeprecated = ({ from, replacement, scope, version, ref: ref8, type = "API" }, condition) => { (0, import_vue4.watch)( () => (0, import_vue4.unref)(condition), (val) => { if (val) { (0, import_utils2.debugWarn)( scope, `[${type}] ${from} is about to be deprecated in version ${version}, please use ${replacement} instead. For more detail, please visit: ${ref8} ` ); } }, { immediate: true } ); }; // src/use-draggable/index.ts var import_vue5 = require("vue"); var import_utils3 = require("@element-plus-next/utils"); var useDraggable = (targetRef, dragRef, draggable) => { let transform = { offsetX: 0, offsetY: 0 }; const onMousedown = (e) => { const downX = e.clientX; const downY = e.clientY; const { offsetX, offsetY } = transform; const targetRect = targetRef.value.getBoundingClientRect(); const targetLeft = targetRect.left; const targetTop = targetRect.top; const targetWidth = targetRect.width; const targetHeight = targetRect.height; const clientWidth = document.documentElement.clientWidth; const clientHeight = document.documentElement.clientHeight; const minLeft = -targetLeft + offsetX; const minTop = -targetTop + offsetY; const maxLeft = clientWidth - targetLeft - targetWidth + offsetX; const maxTop = clientHeight - targetTop - targetHeight + offsetY; const onMousemove = (e2) => { const moveX = Math.min( Math.max(offsetX + e2.clientX - downX, minLeft), maxLeft ); const moveY = Math.min( Math.max(offsetY + e2.clientY - downY, minTop), maxTop ); transform = { offsetX: moveX, offsetY: moveY }; targetRef.value.style.transform = `translate(${(0, import_utils3.addUnit)( moveX )}, ${(0, import_utils3.addUnit)(moveY)})`; }; const onMouseup = () => { document.removeEventListener("mousemove", onMousemove); document.removeEventListener("mouseup", onMouseup); }; document.addEventListener("mousemove", onMousemove); document.addEventListener("mouseup", onMouseup); }; const onDraggable = () => { if (dragRef.value && targetRef.value) { dragRef.value.addEventListener("mousedown", onMousedown); } }; const offDraggable = () => { if (dragRef.value && targetRef.value) { dragRef.value.removeEventListener("mousedown", onMousedown); } }; (0, import_vue5.onMounted)(() => { (0, import_vue5.watchEffect)(() => { if (draggable.value) { onDraggable(); } else { offDraggable(); } }); }); (0, import_vue5.onBeforeUnmount)(() => { offDraggable(); }); }; // src/use-focus/index.ts var useFocus = (el) => { return { focus: () => { var _a, _b; (_b = (_a = el.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a); } }; }; // src/use-locale/index.ts var import_vue6 = require("vue"); var import_lodash_unified2 = require("lodash-unified"); var import_en = __toESM(require("@element-plus-next/locale/lang/en")); var import_vue_context2 = require("@element-plus-next/vue-context"); var buildTranslator = (locale) => (path, option) => translate(path, option, (0, import_vue6.unref)(locale)); var translate = (path, option, locale) => (0, import_lodash_unified2.get)(locale, path, path).replace( /\{(\w+)\}/g, (_, key) => { var _a; return `${(_a = option == null ? void 0 : option[key]) != null ? _a : `{${key}}`}`; } ); var buildLocaleContext = (locale) => { const lang = (0, import_vue6.computed)(() => (0, import_vue6.unref)(locale).name); const localeRef = (0, import_vue6.isRef)(locale) ? locale : (0, import_vue6.ref)(locale); return { lang, locale: localeRef, t: buildTranslator(locale) }; }; var useLocale = () => { const locale = (0, import_vue_context2.useGlobalConfig)("locale"); return buildLocaleContext((0, import_vue6.computed)(() => locale.value || import_en.default)); }; // src/use-lockscreen/index.ts var import_vue8 = require("vue"); var import_utils4 = require("@element-plus-next/utils"); // src/use-namespace/index.ts var import_vue7 = require("vue"); var import_vue_context3 = require("@element-plus-next/vue-context"); var defaultNamespace = "el"; var statePrefix = "is-"; var _bem = (namespace, block, blockSuffix, element, modifier) => { let cls = `${namespace}-${block}`; if (blockSuffix) { cls += `-${blockSuffix}`; } if (element) { cls += `__${element}`; } if (modifier) { cls += `--${modifier}`; } return cls; }; var useNamespace = (block) => { const globalConfig = (0, import_vue_context3.useGlobalConfig)("namespace"); const namespace = (0, import_vue7.computed)(() => globalConfig.value || defaultNamespace); const b = (blockSuffix = "") => _bem((0, import_vue7.unref)(namespace), block, blockSuffix, "", ""); const e = (element) => element ? _bem((0, import_vue7.unref)(namespace), block, "", element, "") : ""; const m = (modifier) => modifier ? _bem((0, import_vue7.unref)(namespace), block, "", "", modifier) : ""; const be = (blockSuffix, element) => blockSuffix && element ? _bem((0, import_vue7.unref)(namespace), block, blockSuffix, element, "") : ""; const em = (element, modifier) => element && modifier ? _bem((0, import_vue7.unref)(namespace), block, "", element, modifier) : ""; const bm = (blockSuffix, modifier) => blockSuffix && modifier ? _bem((0, import_vue7.unref)(namespace), block, blockSuffix, "", modifier) : ""; const bem = (blockSuffix, element, modifier) => blockSuffix && element && modifier ? _bem((0, import_vue7.unref)(namespace), block, blockSuffix, element, modifier) : ""; const is = (name, ...args) => { const state = args.length >= 1 ? args[0] : true; return name && state ? `${statePrefix}${name}` : ""; }; const cssVar = (object) => { const styles = {}; for (const key in object) { if (object[key]) { styles[`--${namespace.value}-${key}`] = object[key]; } } return styles; }; const cssVarBlock = (object) => { const styles = {}; for (const key in object) { if (object[key]) { styles[`--${namespace.value}-${block}-${key}`] = object[key]; } } return styles; }; const cssVarName = (name) => `--${namespace.value}-${name}`; const cssVarBlockName = (name) => `--${namespace.value}-${block}-${name}`; return { namespace, b, e, m, be, em, bm, bem, is, cssVar, cssVarName, cssVarBlock, cssVarBlockName }; }; // src/use-lockscreen/index.ts var useLockscreen = (trigger) => { if (!(0, import_vue8.isRef)(trigger)) { (0, import_utils4.throwError)( "[useLockscreen]", "You need to pass a ref param to this function" ); } const ns = useNamespace("popup"); const hiddenCls = (0, import_vue8.computed)(() => ns.bm("parent", "hidden")); if (!import_utils4.isClient || (0, import_utils4.hasClass)(document.body, hiddenCls.value)) { return; } let scrollBarWidth = 0; let withoutHiddenClass = false; let bodyWidth = "0"; const cleanup = () => { (0, import_utils4.removeClass)(document.body, hiddenCls.value); if (withoutHiddenClass) { document.body.style.width = bodyWidth; } }; (0, import_vue8.watch)(trigger, (val) => { if (!val) { cleanup(); return; } withoutHiddenClass = !(0, import_utils4.hasClass)(document.body, hiddenCls.value); if (withoutHiddenClass) { bodyWidth = document.body.style.width; } scrollBarWidth = (0, import_utils4.getScrollBarWidth)(ns.namespace.value); const bodyHasOverflow = document.documentElement.clientHeight < document.body.scrollHeight; const bodyOverflowY = (0, import_utils4.getStyle)(document.body, "overflowY"); if (scrollBarWidth > 0 && (bodyHasOverflow || bodyOverflowY === "scroll") && withoutHiddenClass) { document.body.style.width = `calc(100% - ${scrollBarWidth}px)`; } (0, import_utils4.addClass)(document.body, hiddenCls.value); }); (0, import_vue8.onScopeDispose)(() => cleanup()); }; // src/use-modal/index.ts var import_vue9 = require("vue"); var import_core = require("@vueuse/core"); var import_constants2 = require("@element-plus-next/constants"); var import_utils5 = require("@element-plus-next/utils"); var modalStack = []; var closeModal = (e) => { if (modalStack.length === 0) return; if (e.code === import_constants2.EVENT_CODE.esc) { e.stopPropagation(); const topModal = modalStack[modalStack.length - 1]; topModal.handleClose(); } }; var useModal = (instance, visibleRef) => { (0, import_vue9.watch)(visibleRef, (val) => { if (val) { modalStack.push(instance); } else { modalStack.splice(modalStack.indexOf(instance), 1); } }); }; if (import_utils5.isClient) (0, import_core.useEventListener)(document, "keydown", closeModal); // src/use-model-toggle/index.ts var import_vue10 = require("vue"); var import_utils6 = require("@element-plus-next/utils"); var import_vue_utils2 = require("@element-plus-next/vue-utils"); var _prop = (0, import_vue_utils2.buildProp)({ type: (0, import_vue_utils2.definePropType)(Boolean), default: null }); var _event = (0, import_vue_utils2.buildProp)({ type: (0, import_vue_utils2.definePropType)(Function) }); var createModelToggleComposable = (name) => { const updateEventKey = `update:${name}`; const updateEventKeyRaw = `onUpdate:${name}`; const useModelToggleEmits2 = [updateEventKey]; const useModelToggleProps2 = { [name]: _prop, [updateEventKeyRaw]: _event }; const useModelToggle2 = ({ indicator, toggleReason, shouldHideWhenRouteChanges, shouldProceed, onShow, onHide }) => { const instance = (0, import_vue10.getCurrentInstance)(); const { emit } = instance; const props = instance.props; const hasUpdateHandler = (0, import_vue10.computed)( () => (0, import_utils6.isFunction)(props[updateEventKeyRaw]) ); const isModelBindingAbsent = (0, import_vue10.computed)(() => props[name] === null); const doShow = (event) => { if (indicator.value === true) { return; } indicator.value = true; if (toggleReason) { toggleReason.value = event; } if ((0, import_utils6.isFunction)(onShow)) { onShow(event); } }; const doHide = (event) => { if (indicator.value === false) { return; } indicator.value = false; if (toggleReason) { toggleReason.value = event; } if ((0, import_utils6.isFunction)(onHide)) { onHide(event); } }; const show = (event) => { if (props.disabled === true || (0, import_utils6.isFunction)(shouldProceed) && !shouldProceed()) return; const shouldEmit = hasUpdateHandler.value && import_utils6.isClient; if (shouldEmit) { emit(updateEventKey, true); } if (isModelBindingAbsent.value || !shouldEmit) { doShow(event); } }; const hide = (event) => { if (props.disabled === true || !import_utils6.isClient) return; const shouldEmit = hasUpdateHandler.value && import_utils6.isClient; if (shouldEmit) { emit(updateEventKey, false); } if (isModelBindingAbsent.value || !shouldEmit) { doHide(event); } }; const onChange = (val) => { if (!(0, import_utils6.isBoolean)(val)) return; if (props.disabled && val) { if (hasUpdateHandler.value) { emit(updateEventKey, false); } } else if (indicator.value !== val) { if (val) { doShow(); } else { doHide(); } } }; const toggle = () => { if (indicator.value) { hide(); } else { show(); } }; (0, import_vue10.watch)(() => props[name], onChange); if (shouldHideWhenRouteChanges && instance.appContext.config.globalProperties.$route !== void 0) { (0, import_vue10.watch)( () => ({ ...instance.proxy.$route }), () => { if (shouldHideWhenRouteChanges.value && indicator.value) { hide(); } } ); } (0, import_vue10.onMounted)(() => { onChange(props[name]); }); return { hide, show, toggle, hasUpdateHandler }; }; return { useModelToggle: useModelToggle2, useModelToggleProps: useModelToggleProps2, useModelToggleEmits: useModelToggleEmits2 }; }; var { useModelToggle, useModelToggleProps, useModelToggleEmits } = createModelToggleComposable("modelValue"); // src/use-prevent-global/index.ts var import_vue11 = require("vue"); var import_core2 = require("@vueuse/core"); var usePreventGlobal = (indicator, evt, cb) => { const prevent = (e) => { if (cb(e)) e.stopImmediatePropagation(); }; let stop = void 0; (0, import_vue11.watch)( () => indicator.value, (val) => { if (val) { stop = (0, import_core2.useEventListener)(document, evt, prevent, true); } else { stop == null ? void 0 : stop(); } }, { immediate: true } ); }; // src/use-restore-active/index.ts var import_vue12 = require("vue"); var useRestoreActive = (toggle, initialFocus) => { let previousActive; (0, import_vue12.watch)( () => toggle.value, (val) => { var _a, _b; if (val) { previousActive = document.activeElement; if ((0, import_vue12.isRef)(initialFocus)) { (_b = (_a = initialFocus.value).focus) == null ? void 0 : _b.call(_a); } } else { if (false) { previousActive.focus.call(previousActive); } else { previousActive.focus(); } } } ); }; // src/use-same-target/index.ts var import_utils7 = require("@element-plus-next/utils"); var useSameTarget = (handleClick) => { if (!handleClick) { return { onClick: import_utils7.NOOP, onMousedown: import_utils7.NOOP, onMouseup: import_utils7.NOOP }; } let mousedownTarget = false; let mouseupTarget = false; const onClick = (e) => { if (mousedownTarget && mouseupTarget) { handleClick(e); } mousedownTarget = mouseupTarget = false; }; const onMousedown = (e) => { mousedownTarget = e.target === e.currentTarget; }; const onMouseup = (e) => { mouseupTarget = e.target === e.currentTarget; }; return { onClick, onMousedown, onMouseup }; }; // src/use-teleport/index.ts var import_vue13 = require("vue"); var import_utils8 = require("@element-plus-next/utils"); var import_vue_utils3 = require("@element-plus-next/vue-utils"); var useTeleport = (contentRenderer, appendToBody) => { const isTeleportVisible = (0, import_vue13.ref)(false); if (!import_utils8.isClient) { return { isTeleportVisible, showTeleport: import_utils8.NOOP, hideTeleport: import_utils8.NOOP, renderTeleport: import_utils8.NOOP }; } let $el = null; const showTeleport = () => { isTeleportVisible.value = true; if ($el !== null) return; $el = (0, import_vue_utils3.createGlobalNode)(); }; const hideTeleport = () => { isTeleportVisible.value = false; if ($el !== null) { (0, import_vue_utils3.removeGlobalNode)($el); $el = null; } }; const renderTeleport = () => { return appendToBody.value !== true ? contentRenderer() : isTeleportVisible.value ? [(0, import_vue13.h)(import_vue13.Teleport, { to: $el }, contentRenderer())] : void 0; }; (0, import_vue13.onUnmounted)(hideTeleport); return { isTeleportVisible, showTeleport, hideTeleport, renderTeleport }; }; // src/use-throttle-render/index.ts var import_vue14 = require("vue"); var useThrottleRender = (loading, throttle = 0) => { if (throttle === 0) return loading; const throttled = (0, import_vue14.ref)(false); let timeoutHandle = 0; const dispatchThrottling = () => { if (timeoutHandle) { clearTimeout(timeoutHandle); } timeoutHandle = window.setTimeout(() => { throttled.value = loading.value; }, throttle); }; (0, import_vue14.onMounted)(dispatchThrottling); (0, import_vue14.watch)( () => loading.value, (val) => { if (val) { dispatchThrottling(); } else { throttled.value = val; } } ); return throttled; }; // src/use-timeout/index.ts var import_core3 = require("@vueuse/core"); function useTimeout() { let timeoutHandle; const registerTimeout = (fn, delay) => { cancelTimeout(); timeoutHandle = window.setTimeout(fn, delay); }; const cancelTimeout = () => window.clearTimeout(timeoutHandle); (0, import_core3.tryOnScopeDispose)(() => cancelTimeout()); return { registerTimeout, cancelTimeout }; } // src/use-transition-fallthrough/index.ts var import_vue15 = require("vue"); var AFTER_APPEAR = "after-appear"; var AFTER_ENTER = "after-enter"; var AFTER_LEAVE = "after-leave"; var APPEAR = "appear"; var APPEAR_CANCELLED = "appear-cancelled"; var BEFORE_ENTER = "before-enter"; var BEFORE_LEAVE = "before-leave"; var ENTER = "enter"; var ENTER_CANCELLED = "enter-cancelled"; var LEAVE = "leave"; var LEAVE_CANCELLED = "leave-cancelled"; var useTransitionFallthroughEmits = [ AFTER_APPEAR, AFTER_ENTER, AFTER_LEAVE, APPEAR, APPEAR_CANCELLED, BEFORE_ENTER, BEFORE_LEAVE, ENTER, ENTER_CANCELLED, LEAVE, LEAVE_CANCELLED ]; var useTransitionFallthrough = () => { const { emit } = (0, import_vue15.getCurrentInstance)(); return { onAfterAppear: () => { emit(AFTER_APPEAR); }, onAfterEnter: () => { emit(AFTER_ENTER); }, onAfterLeave: () => { emit(AFTER_LEAVE); }, onAppearCancelled: () => { emit(APPEAR_CANCELLED); }, onBeforeEnter: () => { emit(BEFORE_ENTER); }, onBeforeLeave: () => { emit(BEFORE_LEAVE); }, onEnter: () => { emit(ENTER); }, onEnterCancelled: () => { emit(ENTER_CANCELLED); }, onLeave: () => { emit(LEAVE); }, onLeaveCancelled: () => { emit(LEAVE_CANCELLED); } }; }; // src/use-id/index.ts var import_vue16 = require("vue"); var import_utils9 = require("@element-plus-next/utils"); var import_vue_context4 = require("@element-plus-next/vue-context"); var defaultIdInjection = { prefix: Math.floor(Math.random() * 1e4), current: 0 }; var ID_INJECTION_KEY = Symbol("elIdInjection"); var useId = (deterministicId) => { const idInjection = (0, import_vue16.inject)(ID_INJECTION_KEY, defaultIdInjection); if (!import_utils9.isClient && idInjection === defaultIdInjection) { (0, import_utils9.debugWarn)( "IdInjection", `Looks like you are using server rendering, you must provide a id provider to ensure the hydration process to be succeed usage: app.provide(ID_INJECTION_KEY, { prefix: number, current: number, })` ); } const namespace = (0, import_vue_context4.useGlobalConfig)("namespace", defaultNamespace); const idRef = (0, import_vue16.computed)( () => (0, import_vue16.unref)(deterministicId) || `${namespace.value}-id-${idInjection.prefix}-${idInjection.current++}` ); return idRef; }; // src/use-escape-keydown/index.ts var import_vue17 = require("vue"); var import_utils10 = require("@element-plus-next/utils"); var import_constants3 = require("@element-plus-next/constants"); var registeredEscapeHandlers = []; var cachedHandler = (e) => { const event = e; if (event.key === import_constants3.EVENT_CODE.esc) { registeredEscapeHandlers.forEach( (registeredHandler) => registeredHandler(event) ); } }; var useEscapeKeydown = (handler) => { (0, import_vue17.onMounted)(() => { if (registeredEscapeHandlers.length === 0) { document.addEventListener("keydown", cachedHandler); } if (import_utils10.isClient) registeredEscapeHandlers.push(handler); }); (0, import_vue17.onBeforeUnmount)(() => { registeredEscapeHandlers = registeredEscapeHandlers.filter( (registeredHandler) => registeredHandler !== handler ); if (registeredEscapeHandlers.length === 0) { if (import_utils10.isClient) document.removeEventListener("keydown", cachedHandler); } }); }; // src/use-popper-container/index.ts var import_vue18 = require("vue"); var import_utils11 = require("@element-plus-next/utils"); var cachedContainer; var POPPER_CONTAINER_ID = `el-popper-container-${(0, import_utils11.generateId)()}`; var POPPER_CONTAINER_SELECTOR = `#${POPPER_CONTAINER_ID}`; var createContainer = () => { const container = document.createElement("div"); container.id = POPPER_CONTAINER_ID; document.body.appendChild(container); return container; }; var usePopperContainer = () => { (0, import_vue18.onBeforeMount)(() => { if (!import_utils11.isClient) return; if (!cachedContainer || !document.body.querySelector(POPPER_CONTAINER_SELECTOR)) { cachedContainer = createContainer(); } }); }; // src/use-intermediate-render/index.ts var import_vue19 = require("vue"); var useDelayedRender = ({ indicator, intermediateIndicator, shouldSetIntermediate = () => true, beforeShow, afterShow, afterHide, beforeHide }) => { (0, import_vue19.watch)( () => (0, import_vue19.unref)(indicator), (val) => { if (val) { beforeShow == null ? void 0 : beforeShow(); (0, import_vue19.nextTick)(() => { if (!(0, import_vue19.unref)(indicator)) return; if (shouldSetIntermediate("show")) { intermediateIndicator.value = true; } }); } else { beforeHide == null ? void 0 : beforeHide(); (0, import_vue19.nextTick)(() => { if ((0, import_vue19.unref)(indicator)) return; if (shouldSetIntermediate("hide")) { intermediateIndicator.value = false; } }); } } ); (0, import_vue19.watch)( () => intermediateIndicator.value, (val) => { if (val) { afterShow == null ? void 0 : afterShow(); } else { afterHide == null ? void 0 : afterHide(); } } ); }; // src/use-delayed-toggle/index.ts var import_vue20 = require("vue"); var import_vue_utils4 = require("@element-plus-next/vue-utils"); var useDelayedToggleProps = (0, import_vue_utils4.buildProps)({ showAfter: { type: Number, default: 0 }, hideAfter: { type: Number, default: 200 } }); var useDelayedToggle = ({ showAfter, hideAfter, open, close }) => { const { registerTimeout } = useTimeout(); const onOpen = (event) => { registerTimeout(() => { open(event); }, (0, import_vue20.unref)(showAfter)); }; const onClose = (event) => { registerTimeout(() => { close(event); }, (0, import_vue20.unref)(hideAfter)); }; return { onOpen, onClose }; }; // src/use-forward-ref/index.ts var import_vue21 = require("vue"); var FORWARD_REF_INJECTION_KEY = Symbol("elForwardRef"); var useForwardRef = (forwardRef) => { const setForwardRef = (el) => { forwardRef.value = el; }; (0, import_vue21.provide)(FORWARD_REF_INJECTION_KEY, { setForwardRef }); }; var useForwardRefDirective = (setForwardRef) => { return { mounted(el) { setForwardRef(el); }, updated(el) { setForwardRef(el); }, unmounted() { setForwardRef(null); } }; }; // src/use-z-index/index.ts var import_vue22 = require("vue"); var import_vue_context5 = require("@element-plus-next/vue-context"); var zIndex = (0, import_vue22.ref)(0); var useZIndex = () => { const initialZIndex = (0, import_vue_context5.useGlobalConfig)("zIndex", 2e3); const currentZIndex = (0, import_vue22.computed)(() => initialZIndex.value + zIndex.value); const nextZIndex = () => { zIndex.value++; return currentZIndex.value; }; return { initialZIndex, currentZIndex, nextZIndex }; }; // src/use-floating/index.ts var import_vue23 = require("vue"); var import_core4 = require("@vueuse/core"); var import_lodash_unified3 = require("lodash-unified"); var import_dom = require("@floating-ui/dom"); var import_vue_utils5 = require("@element-plus-next/vue-utils"); var import_utils12 = require("@element-plus-next/utils"); var useFloatingProps = (0, import_vue_utils5.buildProps)({}); var unrefReference = (elRef) => { if (!import_utils12.isClient) return; if (!elRef) return elRef; const unrefEl = (0, import_core4.unrefElement)(elRef); if (unrefEl) return unrefEl; return (0, import_vue23.isRef)(elRef) ? unrefEl : elRef; }; var getPositionDataWithUnit = (record, key) => { const value = record == null ? void 0 : record[key]; return (0, import_lodash_unified3.isNil)(value) ? "" : `${value}px`; }; var useFloating = ({ middleware, placement, strategy }) => { const referenceRef = (0, import_vue23.ref)(); const contentRef = (0, import_vue23.ref)(); const x = (0, import_vue23.ref)(); const y = (0, import_vue23.ref)(); const middlewareData = (0, import_vue23.ref)({}); const states = { x, y, placement, strategy, middlewareData }; const update = async () => { if (!import_utils12.isClient) return; const referenceEl = unrefReference(referenceRef); const contentEl = (0, import_core4.unrefElement)(contentRef); if (!referenceEl || !contentEl) return; const data = await (0, import_dom.computePosition)(referenceEl, contentEl, { placement: (0, import_vue23.unref)(placement), strategy: (0, import_vue23.unref)(strategy), middleware: (0, import_vue23.unref)(middleware) }); (0, import_utils12.keysOf)(states).forEach((key) => { states[key].value = data[key]; }); }; (0, import_vue23.onMounted)(() => { (0, import_vue23.watchEffect)(() => { update(); }); }); return { ...states, update, referenceRef, contentRef }; }; var arrowMiddleware = ({ arrowRef, padding }) => { return { name: "arrow", options: { element: arrowRef, padding }, fn(args) { const arrowEl = (0, import_vue23.unref)(arrowRef); if (!arrowEl) return {}; return (0, import_dom.arrow)({ element: arrowEl, padding }).fn(args); } }; }; // src/use-cursor/index.ts var import_vue24 = require("vue"); function useCursor(input) { const selectionRef = (0, import_vue24.ref)(); function recordCursor() { if (input.value == void 0) return; const { selectionStart, selectionEnd, value } = input.value; if (selectionStart == null || selectionEnd == null) return; const beforeTxt = value.slice(0, Math.max(0, selectionStart)); const afterTxt = value.slice(Math.max(0, selectionEnd)); selectionRef.value = { selectionStart, selectionEnd, value, beforeTxt, afterTxt }; } function setCursor() { if (input.value == void 0 || selectionRef.value == void 0) return; const { value } = input.value; const { beforeTxt, afterTxt, selectionStart } = selectionRef.value; if (beforeTxt == void 0 || afterTxt == void 0 || selectionStart == void 0) return; let startPos = value.length; if (value.endsWith(afterTxt)) { startPos = value.length - afterTxt.length; } else if (value.startsWith(beforeTxt)) { startPos = beforeTxt.length; } else { const beforeLastChar = beforeTxt[selectionStart - 1]; const newIndex = value.indexOf(beforeLastChar, selectionStart - 1); if (newIndex !== -1) { startPos = newIndex + 1; } } input.value.setSelectionRange(startPos, startPos); } return [recordCursor, setCursor]; }