@lemonadejs/contextmenu 5.2.4 → 5.8.1
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.d.ts +5 -1
- package/dist/index.js +65 -8
- package/dist/style.css +3 -3
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare namespace Contextmenu {
|
|
|
13
13
|
disabled?: boolean;
|
|
14
14
|
tooltip?: string;
|
|
15
15
|
shortcut?: string;
|
|
16
|
-
type
|
|
16
|
+
type?: 'line' | 'default';
|
|
17
17
|
onclick?: (e: MouseEvent, element: HTMLElement) => void;
|
|
18
18
|
icon?: string;
|
|
19
19
|
render?: (e: MouseEvent, element: HTMLElement) => void;
|
|
@@ -31,6 +31,10 @@ declare namespace Contextmenu {
|
|
|
31
31
|
interface Instance {
|
|
32
32
|
options: boolean;
|
|
33
33
|
open: (options: Options, x: number, y: number, e: MouseEvent) => void;
|
|
34
|
+
openAt: {
|
|
35
|
+
(event: MouseEvent | { clientX: number; clientY: number }): void;
|
|
36
|
+
(x: number, y: number): void;
|
|
37
|
+
};
|
|
34
38
|
close: () => void;
|
|
35
39
|
}
|
|
36
40
|
}
|
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
|
-
<
|
|
79
|
+
<span>{{self.title}}</span> <div>{{self.shortcut}}</div>
|
|
80
80
|
</div>`;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -321,11 +321,28 @@ if (! Modal && typeof (require) === 'function') {
|
|
|
321
321
|
return self.modals[0].modal.closed === true;
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
self.
|
|
324
|
+
self.openAt = function(a, b) {
|
|
325
|
+
let x, y;
|
|
326
|
+
if (a instanceof Event || (a && a.clientX !== undefined)) {
|
|
327
|
+
// openAt(event)
|
|
328
|
+
x = a.clientX;
|
|
329
|
+
y = a.clientY;
|
|
330
|
+
} else {
|
|
331
|
+
// openAt(x, y)
|
|
332
|
+
x = a;
|
|
333
|
+
y = b;
|
|
334
|
+
}
|
|
335
|
+
self.open(self.options, x, y, true);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
self.open = function(options, x, y, adjust) {
|
|
325
339
|
// Get the main modal
|
|
326
340
|
let menu = self.modals[0];
|
|
327
341
|
// Reset cursor
|
|
328
342
|
resetCursor.call(menu);
|
|
343
|
+
// Define new position
|
|
344
|
+
menu.modal.top = y;
|
|
345
|
+
menu.modal.left = x;
|
|
329
346
|
// Open
|
|
330
347
|
menu.modal.open();
|
|
331
348
|
// If the modal is open and the content is different from what is shown. Close modals with higher level
|
|
@@ -335,12 +352,48 @@ if (! Modal && typeof (require) === 'function') {
|
|
|
335
352
|
// Refresh content
|
|
336
353
|
menu.options = options;
|
|
337
354
|
}
|
|
338
|
-
// Define new position
|
|
339
|
-
menu.modal.top = y;
|
|
340
|
-
menu.modal.left = x;
|
|
341
|
-
|
|
342
355
|
onopen(self, options);
|
|
343
356
|
|
|
357
|
+
// Adjust position to respect mouse cursor after auto-adjust
|
|
358
|
+
// Use queueMicrotask to ensure it runs after the modal's auto-adjust
|
|
359
|
+
if (adjust === true) {
|
|
360
|
+
queueMicrotask(() => {
|
|
361
|
+
let modalEl = menu.modal.el;
|
|
362
|
+
let rect = modalEl.getBoundingClientRect();
|
|
363
|
+
let marginLeft = parseFloat(modalEl.style.marginLeft) || 0;
|
|
364
|
+
let marginTop = parseFloat(modalEl.style.marginTop) || 0;
|
|
365
|
+
|
|
366
|
+
// Check if horizontal adjustment was applied (margin is non-zero)
|
|
367
|
+
if (marginLeft !== 0) {
|
|
368
|
+
// Position modal so its right edge is at x - 1 (cursor 1px to the right of modal)
|
|
369
|
+
// Formula: left + margin + width = x - 1, where left = x
|
|
370
|
+
// Therefore: margin = -width - 1
|
|
371
|
+
let newMarginLeft = -rect.width - 1;
|
|
372
|
+
// Check if this would push modal off the left edge
|
|
373
|
+
let newLeft = x + newMarginLeft;
|
|
374
|
+
if (newLeft < 10) {
|
|
375
|
+
// Keep a 10px margin from the left edge
|
|
376
|
+
newMarginLeft = 10 - x;
|
|
377
|
+
}
|
|
378
|
+
modalEl.style.marginLeft = newMarginLeft + 'px';
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Check if vertical adjustment was applied (margin is non-zero)
|
|
382
|
+
if (marginTop !== 0) {
|
|
383
|
+
// Position modal so its bottom edge is at y - 1 (cursor 1px below modal)
|
|
384
|
+
// Formula: top + margin + height = y - 1, where top = y
|
|
385
|
+
// Therefore: margin = -height - 1
|
|
386
|
+
let newMarginTop = -rect.height - 1;
|
|
387
|
+
// Check if this would push modal off the top edge
|
|
388
|
+
let newTop = y + newMarginTop;
|
|
389
|
+
if (newTop < 10) {
|
|
390
|
+
// Keep a 10px margin from the top edge
|
|
391
|
+
newMarginTop = 10 - y;
|
|
392
|
+
}
|
|
393
|
+
modalEl.style.marginTop = newMarginTop + 'px';
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
344
397
|
// Focus
|
|
345
398
|
self.el.classList.add('lm-menu-focus');
|
|
346
399
|
// Focus on the contextmenu
|
|
@@ -450,14 +503,18 @@ if (! Modal && typeof (require) === 'function') {
|
|
|
450
503
|
});
|
|
451
504
|
|
|
452
505
|
if (! self.root) {
|
|
453
|
-
self.
|
|
506
|
+
if (self.tagName) {
|
|
507
|
+
self.root = self.el.parentNode.parentNode;
|
|
508
|
+
} else {
|
|
509
|
+
self.root = self.el.parentNode;
|
|
510
|
+
}
|
|
454
511
|
}
|
|
455
512
|
|
|
456
513
|
// Parent
|
|
457
514
|
self.root.addEventListener("contextmenu", function(e) {
|
|
458
515
|
if (Array.isArray(self.options) && self.options.length) {
|
|
459
516
|
let [x, y] = getCoords(e);
|
|
460
|
-
self.open(self.options, x, y,
|
|
517
|
+
self.open(self.options, x, y, true);
|
|
461
518
|
e.preventDefault();
|
|
462
519
|
e.stopImmediatePropagation();
|
|
463
520
|
}
|
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
|
|
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-
|
|
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-
|
|
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.
|
|
18
|
-
"@lemonadejs/modal": "^5.2
|
|
17
|
+
"lemonadejs": "^5.3.6",
|
|
18
|
+
"@lemonadejs/modal": "^5.8.2"
|
|
19
19
|
},
|
|
20
20
|
"main": "dist/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
|
-
"version": "5.
|
|
22
|
+
"version": "5.8.1"
|
|
23
23
|
}
|