remove redundant menuOffsetX

This commit is contained in:
Moritz Bischof 2021-05-03 17:28:25 +02:00
commit 047865368a
2 changed files with 1 additions and 11 deletions

View file

@ -26,7 +26,6 @@
const position = writable([x, y]); const position = writable([x, y]);
const currentIndex = writable(-1); const currentIndex = writable(-1);
const hasPopup = writable(false); const hasPopup = writable(false);
const menuOffsetX = writable(0);
const ctx = getContext("ContextMenu"); const ctx = getContext("ContextMenu");
let options = []; let options = [];
@ -45,7 +44,6 @@
} }
setContext("ContextMenu", { setContext("ContextMenu", {
menuOffsetX,
currentIndex, currentIndex,
position, position,
close, close,
@ -91,8 +89,6 @@
} }
if (open || y === 0) { if (open || y === 0) {
menuOffsetX.set(e.x);
if (window.innerHeight - height < e.y) { if (window.innerHeight - height < e.y) {
y = e.y - height; y = e.y - height;
} else { } else {

View file

@ -70,16 +70,11 @@
let role = "menuitem"; let role = "menuitem";
let submenuOpen = false; let submenuOpen = false;
let submenuPosition = [0, 0]; let submenuPosition = [0, 0];
let menuOffsetX = 0;
const unsubPosition = ctx.position.subscribe((position) => { const unsubPosition = ctx.position.subscribe((position) => {
rootMenuPosition = position; rootMenuPosition = position;
}); });
const unsubMenuOffsetX = ctx.menuOffsetX.subscribe((_menuOffsetX) => {
menuOffsetX = _menuOffsetX;
});
function handleClick(opts = {}) { function handleClick(opts = {}) {
if (disabled) return ctx.close(); if (disabled) return ctx.close();
if (subOptions) return; if (subOptions) return;
@ -117,7 +112,6 @@
return () => { return () => {
unsubPosition(); unsubPosition();
unsubMenuOffsetX();
if (unsubCurrentIds) unsubCurrentIds(); if (unsubCurrentIds) unsubCurrentIds();
if (unsubCurrentId) unsubCurrentId(); if (unsubCurrentId) unsubCurrentId();
if (typeof timeoutHover === "number") clearTimeout(timeoutHover); if (typeof timeoutHover === "number") clearTimeout(timeoutHover);
@ -132,7 +126,7 @@
const { width, y } = ref.getBoundingClientRect(); const { width, y } = ref.getBoundingClientRect();
let x = rootMenuPosition[0] + width; let x = rootMenuPosition[0] + width;
if (window.innerWidth - menuOffsetX < width) { if (window.innerWidth - rootMenuPosition[0] < width) {
x = rootMenuPosition[0] - width; x = rootMenuPosition[0] - width;
} }