first commit
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
import { ObjectDirective } from "vue";
|
||||
|
||||
//#region ../../packages/directives/click-outside/index.d.ts
|
||||
declare const ClickOutside: ObjectDirective<HTMLElement, any>;
|
||||
//#endregion
|
||||
export { ClickOutside as default };
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
||||
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
||||
const require_types = require('../../utils/types.js');
|
||||
let _vueuse_core = require("@vueuse/core");
|
||||
let _vue_shared = require("@vue/shared");
|
||||
|
||||
//#region ../../packages/directives/click-outside/index.ts
|
||||
const nodeList = /* @__PURE__ */ new Map();
|
||||
if (_vueuse_core.isClient) {
|
||||
let startClick;
|
||||
document.addEventListener("mousedown", (e) => startClick = e);
|
||||
document.addEventListener("mouseup", (e) => {
|
||||
if (startClick) {
|
||||
for (const handlers of nodeList.values()) for (const { documentHandler } of handlers) documentHandler(e, startClick);
|
||||
startClick = void 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
function createDocumentHandler(el, binding) {
|
||||
let excludes = [];
|
||||
if ((0, _vue_shared.isArray)(binding.arg)) excludes = binding.arg;
|
||||
else if (require_types.isElement(binding.arg)) excludes.push(binding.arg);
|
||||
return function(mouseup, mousedown) {
|
||||
const popperRef = binding.instance.popperRef;
|
||||
const mouseUpTarget = mouseup.target;
|
||||
const mouseDownTarget = mousedown?.target;
|
||||
const isBound = !binding || !binding.instance;
|
||||
const isTargetExists = !mouseUpTarget || !mouseDownTarget;
|
||||
const isContainedByEl = el.contains(mouseUpTarget) || el.contains(mouseDownTarget);
|
||||
const isSelf = el === mouseUpTarget;
|
||||
const isTargetExcluded = excludes.length && excludes.some((item) => item?.contains(mouseUpTarget)) || excludes.length && excludes.includes(mouseDownTarget);
|
||||
const isContainedByPopper = popperRef && (popperRef.contains(mouseUpTarget) || popperRef.contains(mouseDownTarget));
|
||||
if (isBound || isTargetExists || isContainedByEl || isSelf || isTargetExcluded || isContainedByPopper) return;
|
||||
binding.value(mouseup, mousedown);
|
||||
};
|
||||
}
|
||||
const ClickOutside = {
|
||||
beforeMount(el, binding) {
|
||||
if (!nodeList.has(el)) nodeList.set(el, []);
|
||||
nodeList.get(el).push({
|
||||
documentHandler: createDocumentHandler(el, binding),
|
||||
bindingFn: binding.value
|
||||
});
|
||||
},
|
||||
updated(el, binding) {
|
||||
if (!nodeList.has(el)) nodeList.set(el, []);
|
||||
const handlers = nodeList.get(el);
|
||||
const oldHandlerIndex = handlers.findIndex((item) => item.bindingFn === binding.oldValue);
|
||||
const newHandler = {
|
||||
documentHandler: createDocumentHandler(el, binding),
|
||||
bindingFn: binding.value
|
||||
};
|
||||
if (oldHandlerIndex >= 0) handlers.splice(oldHandlerIndex, 1, newHandler);
|
||||
else handlers.push(newHandler);
|
||||
},
|
||||
unmounted(el) {
|
||||
nodeList.delete(el);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
exports.default = ClickOutside;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user