@setoelkahfi / svara / commits / 5ae4e8d

chore: code cleanup

mellbacon committed Aug 28, 2023 at 17:42 UTC 5ae4e8d32afd8e8852b41379acdd8071749ef9a0
1 file changed +5 -10
src/lib/utility/ContextMenu.svelte
+5 -10
@@ -5,8 +5,7 @@
5 export let items = [];
6 export let target: HTMLElement = null;
7
8 - let ref = null;
9 - let menuOpen = false;
8 + export let menuOpen = false;
9
10 let cursorPos = { x: 0, y: 0 }
11 let menuPos = { h: 0, w: 0 }
@@ -26,8 +25,8 @@
25 let windowHeight = appWindowSize.height;
26
27 menuOpen = true;
29 - windowSize = {w: windowWidth, h: windowHeight}
30 - cursorPos = {x: e.clientX, y: e.clientY}
28 + windowSize = {w: windowWidth, h: windowHeight};
29 + cursorPos = {x: e.clientX, y: e.clientY};
30
31 // Adjust context menu position based on where it is on the window
32 // If it overlaps with the window border then move it to the right/left/top/bottom accordingly
@@ -55,16 +54,12 @@
54 }
55 </script>
56
58 -<svelte:window on:contextmenu|preventDefault={(e) => {
59 - menuOpen = false;
60 - if (target !== null) return;
61 - openContextMenu(e);
62 -}} on:click={(e) => {
57 +<svelte:window on:contextmenu|preventDefault on:mousedown={(e) => {
58 menuOpen = false;
59 }}></svelte:window>
60
61 {#if menuOpen}
67 - <div use:getContextMenuDimension class="context-menu" bind:this={ref} style="top:{cursorPos.y}px; left:{cursorPos.x}px">
62 + <div use:getContextMenuDimension class="context-menu" style="top:{cursorPos.y}px; left:{cursorPos.x}px">
63 {#each items as item}
64 <!-- svelte-ignore a11y-click-events-have-key-events -->
65 <div class="context-menu-option" title="" class:disabled={item.disabled} on:click={() => {