@lemonadejs/contextmenu 5.8.1 → 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.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
- // Aria indication
149
- current.modal.top = rect.y + s.el.offsetTop + 2;
150
- current.modal.left = rect.x + 248;
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;
@@ -408,6 +468,7 @@ if (! Modal && typeof (require) === 'function') {
408
468
  menu.item.expanded = false;
409
469
  menu.item = null;
410
470
  }
471
+ menu.openedLeft = false;
411
472
  menu.modal.close();
412
473
  }
413
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
@@ -19,5 +19,5 @@
19
19
  },
20
20
  "main": "dist/index.js",
21
21
  "types": "dist/index.d.ts",
22
- "version": "5.8.1"
22
+ "version": "5.8.3"
23
23
  }