mirror of
https://github.com/frappe/books.git
synced 2025-01-23 15:18:24 +00:00
fix: window-drag on Windows
- remove listener on unmounting outside click
This commit is contained in:
parent
5f8663438c
commit
af8ffcbf71
@ -1,15 +1,10 @@
|
||||
<template>
|
||||
<div
|
||||
class="
|
||||
px-4
|
||||
flex
|
||||
justify-between
|
||||
window-drag
|
||||
items-center
|
||||
h-row-largest
|
||||
flex-shrink-0
|
||||
"
|
||||
:class="border ? 'border-b' : ''"
|
||||
class="px-4 flex justify-between items-center h-row-largest flex-shrink-0"
|
||||
:class="[
|
||||
border ? 'border-b' : '',
|
||||
platform !== 'Windows' ? 'window-drag' : '',
|
||||
]"
|
||||
>
|
||||
<h1 class="text-xl font-semibold select-none" v-if="title">
|
||||
{{ title }}
|
||||
|
@ -1,5 +1,8 @@
|
||||
<template>
|
||||
<div class="flex-1 bg-gray-25 flex justify-center items-center window-drag">
|
||||
<div
|
||||
class="flex-1 bg-gray-25 flex justify-center items-center window-drag"
|
||||
:class="{ 'window-drag': platform !== 'Windows' }"
|
||||
>
|
||||
<!-- Setup Wizard Slide -->
|
||||
<Slide
|
||||
:primary-disabled="!valuesFilled || loading"
|
||||
|
@ -1,35 +1,39 @@
|
||||
import { Directive } from 'vue';
|
||||
|
||||
const instances: OutsideClickCallback[] = [];
|
||||
type OutsideClickCallback = (e: Event) => void;
|
||||
const instanceMap: Map<HTMLElement, OutsideClickCallback> = new Map();
|
||||
|
||||
export const outsideClickDirective: Directive<
|
||||
HTMLElement,
|
||||
OutsideClickCallback
|
||||
> = {
|
||||
beforeMount(el, binding) {
|
||||
el.dataset.outsideClickIndex = String(instances.length);
|
||||
|
||||
const fn = binding.value;
|
||||
const click = function (e: Event) {
|
||||
onDocumentClick(e, el, fn);
|
||||
const clickHandler = function (e: Event) {
|
||||
onDocumentClick(e, el, binding.value);
|
||||
};
|
||||
|
||||
document.addEventListener('click', click);
|
||||
instances.push(click);
|
||||
removeHandlerIfPresent(el);
|
||||
instanceMap.set(el, clickHandler);
|
||||
document.addEventListener('click', clickHandler);
|
||||
},
|
||||
unmounted(el) {
|
||||
const index = parseInt(el.dataset.outsideClickIndex ?? '0');
|
||||
const handler = instances[index];
|
||||
document.addEventListener('click', handler);
|
||||
instances.splice(index, 1);
|
||||
removeHandlerIfPresent(el);
|
||||
},
|
||||
};
|
||||
|
||||
function onDocumentClick(e: Event, el: HTMLElement, fn: OutsideClickCallback) {
|
||||
const target = e.target;
|
||||
|
||||
if (el !== target && !el.contains(target as Node)) {
|
||||
fn(e);
|
||||
const target = e.target as Node;
|
||||
if (el !== target && !el.contains(target)) {
|
||||
fn?.(e);
|
||||
}
|
||||
}
|
||||
|
||||
function removeHandlerIfPresent(el: HTMLElement) {
|
||||
const clickHandler = instanceMap.get(el);
|
||||
if (!clickHandler) {
|
||||
return;
|
||||
}
|
||||
|
||||
instanceMap.delete(el);
|
||||
document.removeEventListener('click', clickHandler);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user