@lemonadejs/contextmenu 5.8.0 → 5.8.3
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 +79 -4
- package/dist/style.css +4 -2
- 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
|
@@ -70,7 +70,7 @@ if (! Modal && typeof (require) === 'function') {
|
|
|
70
70
|
// Initialize expanded state
|
|
71
71
|
self.expanded = false;
|
|
72
72
|
|
|
73
|
-
if (self.type === 'line') {
|
|
73
|
+
if (self.type === 'line' || self.type === 'divisor') {
|
|
74
74
|
return `<hr role="separator" />`;
|
|
75
75
|
} else if (self.type === 'inline') {
|
|
76
76
|
return `<div></div>`;
|
|
@@ -145,9 +145,69 @@ if (! Modal && typeof (require) === 'function') {
|
|
|
145
145
|
let rect = parent.modal.el.getBoundingClientRect();
|
|
146
146
|
// Update modal
|
|
147
147
|
current.modal.open();
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
|
|
149
|
+
// Calculate initial position using item's actual screen position (accounts for scroll)
|
|
150
|
+
let itemRect = s.el.getBoundingClientRect();
|
|
151
|
+
let submenuWidth = 250;
|
|
152
|
+
let submenuTop = itemRect.y;
|
|
153
|
+
let submenuLeft = rect.x + rect.width - 2; // Position to the right of parent
|
|
154
|
+
|
|
155
|
+
// Check if parent was positioned to the left (has negative margin or is on left side)
|
|
156
|
+
let parentOpenedLeft = parent.openedLeft || false;
|
|
157
|
+
|
|
158
|
+
// Check horizontal space
|
|
159
|
+
let spaceOnRight = window.innerWidth - (rect.x + rect.width);
|
|
160
|
+
let spaceOnLeft = rect.x;
|
|
161
|
+
|
|
162
|
+
// Determine which side to open the submenu
|
|
163
|
+
let openLeft = parentOpenedLeft; // Follow parent's direction by default
|
|
164
|
+
|
|
165
|
+
// If parent opened to right, check if we still have space
|
|
166
|
+
if (!parentOpenedLeft && spaceOnRight < submenuWidth + 10) {
|
|
167
|
+
// Not enough space on right, switch to left
|
|
168
|
+
openLeft = true;
|
|
169
|
+
}
|
|
170
|
+
// If parent opened to left, check if we still have space on left
|
|
171
|
+
if (parentOpenedLeft && spaceOnLeft < submenuWidth + 10) {
|
|
172
|
+
// Not enough space on left, switch to right if possible
|
|
173
|
+
if (spaceOnRight >= submenuWidth + 10) {
|
|
174
|
+
openLeft = false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (openLeft) {
|
|
179
|
+
// Position to the left of parent menu
|
|
180
|
+
submenuLeft = rect.x - submenuWidth + 2;
|
|
181
|
+
// Ensure it doesn't go off the left edge
|
|
182
|
+
if (submenuLeft < 10) {
|
|
183
|
+
submenuLeft = 10;
|
|
184
|
+
}
|
|
185
|
+
current.openedLeft = true;
|
|
186
|
+
} else {
|
|
187
|
+
current.openedLeft = false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Set position
|
|
191
|
+
current.modal.top = submenuTop;
|
|
192
|
+
current.modal.left = submenuLeft;
|
|
193
|
+
|
|
194
|
+
// Adjust vertical position after render
|
|
195
|
+
queueMicrotask(() => {
|
|
196
|
+
let submenuEl = current.modal.el;
|
|
197
|
+
let submenuRect = submenuEl.getBoundingClientRect();
|
|
198
|
+
|
|
199
|
+
// Check if submenu goes off the bottom
|
|
200
|
+
if (submenuRect.bottom > window.innerHeight - 10) {
|
|
201
|
+
let overflow = submenuRect.bottom - (window.innerHeight - 10);
|
|
202
|
+
let newTop = submenuTop - overflow;
|
|
203
|
+
// Don't go above the top of the screen
|
|
204
|
+
if (newTop < 10) {
|
|
205
|
+
newTop = 10;
|
|
206
|
+
}
|
|
207
|
+
current.modal.top = newTop;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
151
211
|
// Keep current item for each modal
|
|
152
212
|
current.item = s;
|
|
153
213
|
s.expanded = true;
|
|
@@ -321,6 +381,20 @@ if (! Modal && typeof (require) === 'function') {
|
|
|
321
381
|
return self.modals[0].modal.closed === true;
|
|
322
382
|
}
|
|
323
383
|
|
|
384
|
+
self.openAt = function(a, b) {
|
|
385
|
+
let x, y;
|
|
386
|
+
if (a instanceof Event || (a && a.clientX !== undefined)) {
|
|
387
|
+
// openAt(event)
|
|
388
|
+
x = a.clientX;
|
|
389
|
+
y = a.clientY;
|
|
390
|
+
} else {
|
|
391
|
+
// openAt(x, y)
|
|
392
|
+
x = a;
|
|
393
|
+
y = b;
|
|
394
|
+
}
|
|
395
|
+
self.open(self.options, x, y, true);
|
|
396
|
+
};
|
|
397
|
+
|
|
324
398
|
self.open = function(options, x, y, adjust) {
|
|
325
399
|
// Get the main modal
|
|
326
400
|
let menu = self.modals[0];
|
|
@@ -394,6 +468,7 @@ if (! Modal && typeof (require) === 'function') {
|
|
|
394
468
|
menu.item.expanded = false;
|
|
395
469
|
menu.item = null;
|
|
396
470
|
}
|
|
471
|
+
menu.openedLeft = false;
|
|
397
472
|
menu.modal.close();
|
|
398
473
|
}
|
|
399
474
|
});
|
package/dist/style.css
CHANGED
|
@@ -65,7 +65,8 @@
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
.lm-menu-submenu > div.lm-menu-item:hover,
|
|
68
|
-
.lm-menu-submenu > div.lm-menu-item[data-cursor="true"]
|
|
68
|
+
.lm-menu-submenu > div.lm-menu-item[data-cursor="true"],
|
|
69
|
+
.lm-menu-submenu > div.lm-menu-item[aria-expanded="true"] {
|
|
69
70
|
background-color: var(--lm-background-color-highlight, #ebebeb);
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -95,6 +96,7 @@
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
.lm-dark-mode .lm-menu-submenu > div.lm-menu-item:hover,
|
|
98
|
-
.lm-dark-mode .lm-menu-submenu > div.lm-menu-item[data-cursor="true"]
|
|
99
|
+
.lm-dark-mode .lm-menu-submenu > div.lm-menu-item[data-cursor="true"],
|
|
100
|
+
.lm-dark-mode .lm-menu-submenu > div.lm-menu-item[aria-expanded="true"] {
|
|
99
101
|
background-color: var(--lm-background-color-highlight, #2d2d2d);
|
|
100
102
|
}
|
package/package.json
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"build": "webpack --config webpack.config.js"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"lemonadejs": "^5.3.
|
|
18
|
-
"@lemonadejs/modal": "^5.8.
|
|
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.8.
|
|
22
|
+
"version": "5.8.3"
|
|
23
23
|
}
|