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

1 month ago
  1. {"ast":null,"code":"import { isClient } from '@vueuse/core';\nimport { isArray } from '@vue/shared';\nimport { isElement } from '../../utils/types.mjs';\nconst nodeList = /* @__PURE__ */new Map();\nif (isClient) {\n let startClick;\n document.addEventListener(\"mousedown\", e => startClick = e);\n document.addEventListener(\"mouseup\", e => {\n if (startClick) {\n for (const handlers of nodeList.values()) {\n for (const {\n documentHandler\n } of handlers) {\n documentHandler(e, startClick);\n }\n }\n startClick = void 0;\n }\n });\n}\nfunction createDocumentHandler(el, binding) {\n let excludes = [];\n if (isArray(binding.arg)) {\n excludes = binding.arg;\n } else if (isElement(binding.arg)) {\n excludes.push(binding.arg);\n }\n return function (mouseup, mousedown) {\n const popperRef = binding.instance.popperRef;\n const mouseUpTarget = mouseup.target;\n const mouseDownTarget = mousedown == null ? void 0 : mousedown.target;\n const isBound = !binding || !binding.instance;\n const isTargetExists = !mouseUpTarget || !mouseDownTarget;\n const isContainedByEl = el.contains(mouseUpTarget) || el.contains(mouseDownTarget);\n const isSelf = el === mouseUpTarget;\n const isTargetExcluded = excludes.length && excludes.some(item => item == null ? void 0 : item.contains(mouseUpTarget)) || excludes.length && excludes.includes(mouseDownTarget);\n const isContainedByPopper = popperRef && (popperRef.contains(mouseUpTarget) || popperRef.contains(mouseDownTarget));\n if (isBound || isTargetExists || isContainedByEl || isSelf || isTargetExcluded || isContainedByPopper) {\n return;\n }\n binding.value(mouseup, mousedown);\n };\n}\nconst ClickOutside = {\n beforeMount(el, binding) {\n if (!nodeList.has(el)) {\n nodeList.set(el, []);\n }\n nodeList.get(el).push({\n documentHandler: createDocumentHandler(el, binding),\n bindingFn: binding.value\n });\n },\n updated(el, binding) {\n if (!nodeList.has(el)) {\n nodeList.set(el, []);\n }\n const handlers = nodeList.get(el);\n const oldHandlerIndex = handlers.findIndex(item => item.bindingFn === binding.oldValue);\n const newHandler = {\n documentHandler: createDocumentHandler(el, binding),\n bindingFn: binding.value\n };\n if (oldHandlerIndex >= 0) {\n handlers.splice(oldHandlerIndex, 1, newHandler);\n } else {\n handlers.push(newHandler);\n }\n },\n unmounted(el) {\n nodeList.delete(el);\n }\n};\nexport { ClickOutside as default };","map":{"version":3,"names":["nodeList","Map","isClient","startClick","document","addEventListener","e","handlers","values","documentHandler","createDocumentHandler","el","binding","excludes","isArray","arg","isElement","push","mouseup","mousedown","popperRef","instance","mouseUpTarget","target","mouseDownTarget","isBound","isTargetExists","isContainedByEl","contains","isSelf","isTargetExcluded","length","some","item","includes","isContainedByPopper","value","ClickOutside","beforeMount","has","set","get","bindingFn","updated","oldHandlerIndex","findIndex","oldValue","newHandler","splice","unmounted","delete"],"sources":["../../../../../packages/directives/click-outside/index.ts"],"sourcesContent":["import { isArray, isClient, isElement } from '@element-plus/utils'\n\nimport type {\n ComponentPublicInstance,\n DirectiveBinding,\n ObjectDirective,\n} from 'vue'\n\ntype DocumentHandler = <T extends MouseEvent>(mouseup: T, mousedown: T) => void\ntype FlushList = Map<\n HTMLElement,\n {\n documentHandler: DocumentHandler\n bindingFn: (...args: unknown[]) => unknown\n }[]\n>\n\nconst nodeList: FlushList = new Map()\n\nif (isClient) {\n let startClick: MouseEvent | undefined\n document.addEventListener('mousedown', (e: MouseEvent) => (startClick = e))\n document.addEventListener('mouseup', (e: MouseEvent) => {\n if (startClick) {\n for (const handlers of nodeList.values()) {\n for (const { documentHandler } of handlers) {\n documentH