@lemonadejs/contextmenu 5.2.4 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -76,7 +76,7 @@ if (! Modal && typeof (require) === 'function') {
76
76
  return `<div></div>`;
77
77
  } else {
78
78
  return `<div class="lm-menu-item" role="menuitem" data-disabled="{{self.disabled}}" data-cursor="{{self.cursor}}" data-icon="{{self.icon}}" title="{{self.tooltip}}" data-submenu="${!!self.submenu}" aria-haspopup="${!!self.submenu}" aria-expanded="{{self.expanded}}" aria-label="{{self.title}}" tabindex="-1" onmouseup="self.parent.mouseUp" onmouseenter="self.parent.mouseEnter" onmouseleave="self.parent.mouseLeave">
79
- <a>{{self.title}}</a> <div>{{self.shortcut}}</div>
79
+ <span>{{self.title}}</span> <div>{{self.shortcut}}</div>
80
80
  </div>`;
81
81
  }
82
82
  }
@@ -321,11 +321,14 @@ if (! Modal && typeof (require) === 'function') {
321
321
  return self.modals[0].modal.closed === true;
322
322
  }
323
323
 
324
- self.open = function(options, x, y, e) {
324
+ self.open = function(options, x, y, adjust) {
325
325
  // Get the main modal
326
326
  let menu = self.modals[0];
327
327
  // Reset cursor
328
328
  resetCursor.call(menu);
329
+ // Define new position
330
+ menu.modal.top = y;
331
+ menu.modal.left = x;
329
332
  // Open
330
333
  menu.modal.open();
331
334
  // If the modal is open and the content is different from what is shown. Close modals with higher level
@@ -335,12 +338,48 @@ if (! Modal && typeof (require) === 'function') {
335
338
  // Refresh content
336
339
  menu.options = options;
337
340
  }
338
- // Define new position
339
- menu.modal.top = y;
340
- menu.modal.left = x;
341
-
342
341
  onopen(self, options);
343
342
 
343
+ // Adjust position to respect mouse cursor after auto-adjust
344
+ // Use queueMicrotask to ensure it runs after the modal's auto-adjust
345
+ if (adjust === true) {
346
+ queueMicrotask(() => {
347
+ let modalEl = menu.modal.el;
348
+ let rect = modalEl.getBoundingClientRect();
349
+ let marginLeft = parseFloat(modalEl.style.marginLeft) || 0;
350
+ let marginTop = parseFloat(modalEl.style.marginTop) || 0;
351
+
352
+ // Check if horizontal adjustment was applied (margin is non-zero)
353
+ if (marginLeft !== 0) {
354
+ // Position modal so its right edge is at x - 1 (cursor 1px to the right of modal)
355
+ // Formula: left + margin + width = x - 1, where left = x
356
+ // Therefore: margin = -width - 1
357
+ let newMarginLeft = -rect.width - 1;
358
+ // Check if this would push modal off the left edge
359
+ let newLeft = x + newMarginLeft;
360
+ if (newLeft < 10) {
361
+ // Keep a 10px margin from the left edge
362
+ newMarginLeft = 10 - x;
363
+ }
364
+ modalEl.style.marginLeft = newMarginLeft + 'px';
365
+ }
366
+
367
+ // Check if vertical adjustment was applied (margin is non-zero)
368
+ if (marginTop !== 0) {
369
+ // Position modal so its bottom edge is at y - 1 (cursor 1px below modal)
370
+ // Formula: top + margin + height = y - 1, where top = y
371
+ // Therefore: margin = -height - 1
372
+ let newMarginTop = -rect.height - 1;
373
+ // Check if this would push modal off the top edge
374
+ let newTop = y + newMarginTop;
375
+ if (newTop < 10) {
376
+ // Keep a 10px margin from the top edge
377
+ newMarginTop = 10 - y;
378
+ }
379
+ modalEl.style.marginTop = newMarginTop + 'px';
380
+ }
381
+ });
382
+ }
344
383
  // Focus
345
384
  self.el.classList.add('lm-menu-focus');
346
385
  // Focus on the contextmenu
@@ -450,14 +489,18 @@ if (! Modal && typeof (require) === 'function') {
450
489
  });
451
490
 
452
491
  if (! self.root) {
453
- self.root = self.el.parentNode;
492
+ if (self.tagName) {
493
+ self.root = self.el.parentNode.parentNode;
494
+ } else {
495
+ self.root = self.el.parentNode;
496
+ }
454
497
  }
455
498
 
456
499
  // Parent
457
500
  self.root.addEventListener("contextmenu", function(e) {
458
501
  if (Array.isArray(self.options) && self.options.length) {
459
502
  let [x, y] = getCoords(e);
460
- self.open(self.options, x, y, e);
503
+ self.open(self.options, x, y, true);
461
504
  e.preventDefault();
462
505
  e.stopImmediatePropagation();
463
506
  }
package/dist/style.css CHANGED
@@ -40,7 +40,7 @@
40
40
  position: relative;
41
41
  }
42
42
 
43
- .lm-menu-submenu > div.lm-menu-item a {
43
+ .lm-menu-submenu > div.lm-menu-item span {
44
44
  text-decoration: none;
45
45
  flex: 1;
46
46
  cursor: pointer;
@@ -66,7 +66,7 @@
66
66
 
67
67
  .lm-menu-submenu > div.lm-menu-item:hover,
68
68
  .lm-menu-submenu > div.lm-menu-item[data-cursor="true"] {
69
- background-color: var(--lm-background-color-hover, #ebebeb);
69
+ background-color: var(--lm-background-color-highlight, #ebebeb);
70
70
  }
71
71
 
72
72
  .lm-menu-submenu hr {
@@ -96,5 +96,5 @@
96
96
 
97
97
  .lm-dark-mode .lm-menu-submenu > div.lm-menu-item:hover,
98
98
  .lm-dark-mode .lm-menu-submenu > div.lm-menu-item[data-cursor="true"] {
99
- background-color: var(--lm-background-color-hover, #2d2d2d);
99
+ background-color: var(--lm-background-color-highlight, #2d2d2d);
100
100
  }
package/package.json CHANGED
@@ -14,10 +14,10 @@
14
14
  "build": "webpack --config webpack.config.js"
15
15
  },
16
16
  "dependencies": {
17
- "lemonadejs": "^5.2.0",
18
- "@lemonadejs/modal": "^5.2.1"
17
+ "lemonadejs": "^5.3.2",
18
+ "@lemonadejs/modal": "^5.8.0"
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "5.2.4"
22
+ "version": "5.8.0"
23
23
  }