|
|
@ -10,17 +10,12 @@ import { isServer } from '/@/utils/is'; |
|
|
|
import type { ComponentPublicInstance, DirectiveBinding, ObjectDirective } from 'vue'; |
|
|
|
import type { ComponentPublicInstance, DirectiveBinding, ObjectDirective } from 'vue'; |
|
|
|
|
|
|
|
|
|
|
|
type DocumentHandler = <T extends MouseEvent>(mouseup: T, mousedown: T) => void; |
|
|
|
type DocumentHandler = <T extends MouseEvent>(mouseup: T, mousedown: T) => void; |
|
|
|
|
|
|
|
type FlushList = Map<HTMLElement, { |
|
|
|
type FlushList = Map< |
|
|
|
documentHandler: DocumentHandler; |
|
|
|
HTMLElement, |
|
|
|
bindingFn: (...args: unknown[]) => unknown; |
|
|
|
{ |
|
|
|
}>; |
|
|
|
documentHandler: DocumentHandler; |
|
|
|
|
|
|
|
bindingFn: (...args: unknown[]) => unknown; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const nodeList: FlushList = new Map(); |
|
|
|
const nodeList: FlushList = new Map(); |
|
|
|
|
|
|
|
|
|
|
|
let startClick: MouseEvent; |
|
|
|
let startClick: MouseEvent; |
|
|
|
|
|
|
|
|
|
|
|
if (!isServer) { |
|
|
|
if (!isServer) { |
|
|
@ -36,38 +31,24 @@ function createDocumentHandler(el: HTMLElement, binding: DirectiveBinding): Docu |
|
|
|
let excludes: HTMLElement[] = []; |
|
|
|
let excludes: HTMLElement[] = []; |
|
|
|
if (Array.isArray(binding.arg)) { |
|
|
|
if (Array.isArray(binding.arg)) { |
|
|
|
excludes = binding.arg; |
|
|
|
excludes = binding.arg; |
|
|
|
} else { |
|
|
|
// 由于当前对绑定类型的实现是错误的,这里需要进行类型转换
|
|
|
|
// 由于当前对绑定类型的实现是错误的,这里需要进行类型转换
|
|
|
|
} else excludes.push(binding.arg as unknown as HTMLElement); |
|
|
|
excludes.push(binding.arg as unknown as HTMLElement); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return function (mouseup, mousedown) { |
|
|
|
return function (mouseup, mousedown) { |
|
|
|
const popperRef = ( |
|
|
|
const popperRef = (binding.instance as ComponentPublicInstance<{ |
|
|
|
binding.instance as ComponentPublicInstance<{ |
|
|
|
popperRef: Nullable<HTMLElement>; |
|
|
|
popperRef: Nullable<HTMLElement>; |
|
|
|
}>).popperRef; |
|
|
|
}> |
|
|
|
|
|
|
|
).popperRef; |
|
|
|
|
|
|
|
const mouseUpTarget = mouseup.target as Node; |
|
|
|
const mouseUpTarget = mouseup.target as Node; |
|
|
|
const mouseDownTarget = mousedown.target as Node; |
|
|
|
const mouseDownTarget = mousedown.target as Node; |
|
|
|
const isBound = !binding || !binding.instance; |
|
|
|
const isBound = !binding || !binding.instance; |
|
|
|
const isTargetExists = !mouseUpTarget || !mouseDownTarget; |
|
|
|
const isTargetExists = !mouseUpTarget || !mouseDownTarget; |
|
|
|
const isContainedByEl = el.contains(mouseUpTarget) || el.contains(mouseDownTarget); |
|
|
|
const isContainedByEl = el.contains(mouseUpTarget) || el.contains(mouseDownTarget); |
|
|
|
const isSelf = el === mouseUpTarget; |
|
|
|
const isSelf = el === mouseUpTarget; |
|
|
|
|
|
|
|
|
|
|
|
const isTargetExcluded = |
|
|
|
const isTargetExcluded = |
|
|
|
(excludes.length && excludes.some((item) => item?.contains(mouseUpTarget))) || |
|
|
|
(excludes.length && excludes.some((item) => item?.contains(mouseUpTarget))) || |
|
|
|
(excludes.length && excludes.includes(mouseDownTarget as HTMLElement)); |
|
|
|
(excludes.length && excludes.includes(mouseDownTarget as HTMLElement)); |
|
|
|
const isContainedByPopper = |
|
|
|
const isContainedByPopper = |
|
|
|
popperRef && (popperRef.contains(mouseUpTarget) || popperRef.contains(mouseDownTarget)); |
|
|
|
popperRef && (popperRef.contains(mouseUpTarget) || popperRef.contains(mouseDownTarget)); |
|
|
|
if ( |
|
|
|
if (isBound || isTargetExists || isContainedByEl || isSelf || isTargetExcluded || isContainedByPopper) return; |
|
|
|
isBound || |
|
|
|
|
|
|
|
isTargetExists || |
|
|
|
|
|
|
|
isContainedByEl || |
|
|
|
|
|
|
|
isSelf || |
|
|
|
|
|
|
|
isTargetExcluded || |
|
|
|
|
|
|
|
isContainedByPopper |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
binding.value(); |
|
|
|
binding.value(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|