@acusti/dropdown 0.57.0 → 1.0.0-alpha.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/Dropdown.js CHANGED
@@ -1,57 +1,172 @@
1
1
  import { c } from "react/compiler-runtime";
2
2
  import useKeyboardEvents, { isEventTargetUsingKeyEvent } from "@acusti/use-keyboard-events";
3
3
  import clsx from "clsx";
4
- import { Children, Fragment, cloneElement, isValidElement, useEffect, useId, useRef, useState } from "react";
4
+ import { Children, Fragment, cloneElement, createContext, isValidElement, useContext, useEffect, useId, useRef, useState } from "react";
5
5
  import { getBestMatch } from "@acusti/matchmaking";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
+ //#region src/context.ts
8
+ var DropdownContext = createContext(null);
9
+ var MenubarContext = createContext(null);
10
+ //#endregion
7
11
  //#region src/Dropdown.css?inline
8
- var Dropdown_default = ":root{--uktdd-font-family:system-ui, Segoe UI, Roboto, Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, Helvetica, Arial, sans-serif;--uktdd-body-bg-color:#fff;--uktdd-body-bg-color-hover:#69a2f9;--uktdd-body-color-hover:#fff;--uktdd-body-buffer:10px;--uktdd-body-max-height:calc(100dvh - var(--uktdd-body-buffer));--uktdd-body-max-width:calc(100dvw - var(--uktdd-body-buffer));--uktdd-body-min-height:30px;--uktdd-body-pad-bottom:9px;--uktdd-body-pad-left:12px;--uktdd-body-pad-right:12px;--uktdd-body-pad-top:9px;--uktdd-body-min-width:min(50px, 100%);--uktdd-body-position-area:bottom span-right;--uktdd-body-position-try-fallbacks:--uktdd-top-left, --uktdd-bottom-right, --uktdd-top-right;--uktdd-body-translate:0 0;--uktdd-label-pad-right:10px}.uktdropdown,.uktdropdown-trigger{font-family:var(--uktdd-font-family)}.uktdropdown{anchor-scope:--uktdd-anchor;width:max-content}.uktdropdown.disabled{pointer-events:none}.uktdropdown>*{cursor:default}.uktdropdown>:first-child{anchor-name:--uktdd-anchor}.uktdropdown-label{align-items:center;display:flex}.uktdropdown-label-text{padding-right:var(--uktdd-label-pad-right)}.uktdropdown-body{box-sizing:border-box;position-anchor:--uktdd-anchor;position-area:var(--uktdd-body-position-area);position-try-order:most-height;position-try-fallbacks:var(--uktdd-body-position-try-fallbacks);min-block-size:min(var(--uktdd-body-min-height), var(--uktdd-body-max-height));max-block-size:min(var(--uktdd-body-max-height), 100%);min-inline-size:min(var(--uktdd-body-min-width), var(--uktdd-body-max-width));max-inline-size:var(--uktdd-body-max-width);inline-size:max-content;translate:var(--uktdd-body-translate);z-index:2;background-color:var(--uktdd-body-bg-color);flex-direction:column;display:flex;position:fixed;overflow:hidden;box-shadow:0 8px 18px #00000040}.uktdropdown-body.has-items{-webkit-user-select:none;user-select:none}.uktdropdown-body [data-ukt-active]{background-color:var(--uktdd-body-bg-color-hover);color:var(--uktdd-body-color-hover)}.uktdropdown-content{box-sizing:border-box;overscroll-behavior:contain;min-block-size:0;padding:var(--uktdd-body-pad-top) var(--uktdd-body-pad-right) var(--uktdd-body-pad-bottom) var(--uktdd-body-pad-left);overflow:auto}@position-try --uktdd-top-left{position-area: top span-right;}@position-try --uktdd-bottom-left{position-area: bottom span-right;}@position-try --uktdd-bottom-right{position-area: bottom span-left;}@position-try --uktdd-top-right{position-area: top span-left;}";
12
+ var Dropdown_default = ":root{--uktdd-font-family:system-ui, Segoe UI, Roboto, Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, Helvetica, Arial, sans-serif;--uktdd-body-bg-color:#fff;--uktdd-body-bg-color-hover:#69a2f9;--uktdd-body-color-hover:#fff;--uktdd-body-buffer:10px;--uktdd-body-max-height:calc(100dvh - var(--uktdd-body-buffer));--uktdd-body-max-width:calc(100dvw - var(--uktdd-body-buffer));--uktdd-body-min-height:30px;--uktdd-body-pad-bottom:.5em;--uktdd-body-pad-left:.6875em;--uktdd-body-pad-right:.6875em;--uktdd-body-pad-top:.5em;--uktdd-body-min-width:min(50px, 100%);--uktdd-body-position-area:bottom span-right;--uktdd-body-position-try-fallbacks:--uktdd-top-left, --uktdd-bottom-right, --uktdd-top-right;--uktdd-body-gap:0px;--uktdd-body-color:canvastext;--uktdd-body-bg-color-path:#dcdcdc;--uktdd-body-color-path:currentColor;--uktdd-label-pad-right:.625em;--uktdd-submenu-position-area:inline-end span-block-end;--uktdd-submenu-position-try-fallbacks:--uktdd-submenu-inline-start;--uktdd-submenu-gap:0px;--uktdd-menubar-trigger-bg-color-active:#0000001f}.uktdropdown,.uktdropdown-trigger{font-family:var(--uktdd-font-family)}.uktdropdown{anchor-scope:--uktdd-anchor;width:max-content}.uktdropdown.disabled{pointer-events:none}.uktdropdown>*{cursor:default}.uktdropdown>:first-child{anchor-name:--uktdd-anchor}.uktdropdown-label{align-items:center;display:flex}.uktdropdown-label-text{padding-right:var(--uktdd-label-pad-right)}.uktdropdown-body{box-sizing:border-box;position-anchor:--uktdd-anchor;position-area:var(--uktdd-body-position-area);position-try-order:most-height;position-try-fallbacks:var(--uktdd-body-position-try-fallbacks);min-block-size:min(var(--uktdd-body-min-height), var(--uktdd-body-max-height));max-block-size:min(var(--uktdd-body-max-height), 100%);min-inline-size:min(var(--uktdd-body-min-width), var(--uktdd-body-max-width));max-inline-size:var(--uktdd-body-max-width);inline-size:max-content;color:inherit;background-color:var(--uktdd-body-bg-color);flex-direction:column;display:flex;position:fixed;overflow:hidden;box-shadow:0 8px 18px #00000040}.uktdropdown-body.has-items{-webkit-user-select:none;user-select:none}.uktdropdown-body [data-ukt-active]{background-color:var(--uktdd-body-bg-color-hover);color:var(--uktdd-body-color-hover)}:is(.uktdropdown-body [data-ukt-active]:has([data-ukt-submenu] [data-ukt-active]),.uktdropdown-body [data-ukt-active]:has([data-ukt-submenu]:hover)){background-color:var(--uktdd-body-bg-color-path);color:var(--uktdd-body-color-path)}.uktdropdown-body [data-ukt-item][aria-disabled=true]{opacity:.5;pointer-events:none}.uktdropdown-body [data-ukt-item]{anchor-scope:--uktdd-submenu-anchor}.uktdropdown-body :is([data-ukt-item],[data-ukt-value])[aria-haspopup=menu]{padding-inline-end:2em;position:relative}.uktdropdown-body :is([data-ukt-item],[data-ukt-value])[aria-haspopup=menu]:after{content:\"\";border-block-start:.14em solid;border-inline-end:.14em solid;block-size:.3em;inline-size:.3em;position:absolute;inset-block-start:50%;inset-inline-end:.9em;translate:0 -50%;rotate:45deg}.uktdropdown-body :is([data-ukt-item],[data-ukt-value])[aria-haspopup=menu]:is(:lang(ae),:lang(ar),:lang(arc),:lang(bcc),:lang(bqi),:lang(ckb),:lang(dv),:lang(fa),:lang(glk),:lang(he),:lang(ku),:lang(mzn),:lang(nqo),:lang(pnb),:lang(ps),:lang(sd),:lang(ug),:lang(ur),:lang(yi)):after{rotate:-45deg}.uktdropdown-body [data-ukt-item][aria-expanded=true]{anchor-name:--uktdd-submenu-anchor}.uktdropdown-body [data-ukt-item][aria-expanded=true]>[data-ukt-submenu]{display:block}.uktdropdown-body [data-ukt-submenu]{box-sizing:border-box;color:var(--uktdd-body-color);position-anchor:--uktdd-submenu-anchor;position-area:var(--uktdd-submenu-position-area);position-try-fallbacks:var(--uktdd-submenu-position-try-fallbacks);z-index:2;margin-block:0;margin-inline:var(--uktdd-submenu-gap);padding:var(--uktdd-body-pad-top) var(--uktdd-body-pad-right) var(--uktdd-body-pad-bottom) var(--uktdd-body-pad-left);inline-size:max-content;max-inline-size:var(--uktdd-body-max-width);max-block-size:var(--uktdd-body-max-height);overscroll-behavior:contain;background-color:var(--uktdd-body-bg-color);list-style:none;display:none;position:fixed;overflow:auto;box-shadow:0 8px 18px #00000040}div.uktdropdown-body{block-size:auto;margin-block:var(--uktdd-body-gap);border:0;margin-inline:0;padding:0;inset:auto}.uktmenubar{width:max-content;font-family:var(--uktdd-font-family);align-items:stretch;display:flex}.uktmenubar .uktdropdown.is-open .uktdropdown-trigger{box-shadow:inset 0 0 0 100vmax var(--uktdd-menubar-trigger-bg-color-active)}.uktdropdown-content{box-sizing:border-box;overscroll-behavior:contain;min-block-size:0;padding:var(--uktdd-body-pad-top) var(--uktdd-body-pad-right) var(--uktdd-body-pad-bottom) var(--uktdd-body-pad-left);overflow:auto}@position-try --uktdd-top-left{position-area: top span-right;}@position-try --uktdd-bottom-left{position-area: bottom span-right;}@position-try --uktdd-bottom-right{position-area: bottom span-left;}@position-try --uktdd-top-right{position-area: top span-left;}@position-try --uktdd-submenu-inline-start{position-area: inline-start span-block-end;}";
9
13
  //#endregion
10
14
  //#region src/helpers.ts
11
- var ITEM_SELECTOR = `[data-ukt-item], [data-ukt-value]`;
12
- var getItemElements = (dropdownElement) => {
13
- if (!dropdownElement) return null;
14
- const bodyElement = dropdownElement.querySelector(".uktdropdown-body");
15
+ var ITEM_SELECTOR = "[data-ukt-item], [data-ukt-value]";
16
+ var SUBMENU_SELECTOR = "[data-ukt-submenu]";
17
+ var DISABLED_ITEM_SELECTOR = "[aria-disabled=\"true\"]";
18
+ var getBodyElement = (dropdownElement) => dropdownElement?.querySelector(".uktdropdown-body") ?? null;
19
+ var getLevelRoot = (element) => element.closest(SUBMENU_SELECTOR);
20
+ var getSubmenuOfItem = (item) => {
21
+ const submenu = item.querySelector(SUBMENU_SELECTOR);
22
+ if (!submenu) return null;
23
+ return submenu.parentElement?.closest("[data-ukt-item], [data-ukt-value]") === item ? submenu : null;
24
+ };
25
+ var getParentItem = (levelRoot) => levelRoot.parentElement?.closest("[data-ukt-item], [data-ukt-value]") ?? null;
26
+ var getItemLabel = (item) => {
27
+ if (!getSubmenuOfItem(item)) return item.innerText ?? "";
28
+ const clone = item.cloneNode(true);
29
+ for (const submenu of Array.from(clone.querySelectorAll(SUBMENU_SELECTOR))) submenu.remove();
30
+ return (clone.textContent ?? "").trim();
31
+ };
32
+ var getItemPath = (element) => {
33
+ const path = [];
34
+ if (!element) return path;
35
+ let levelRoot = getLevelRoot(element);
36
+ while (levelRoot) {
37
+ const parentItem = getParentItem(levelRoot);
38
+ if (!parentItem) break;
39
+ const label = getItemLabel(parentItem);
40
+ path.unshift({
41
+ label,
42
+ value: parentItem.dataset.uktValue ?? label
43
+ });
44
+ levelRoot = getLevelRoot(parentItem);
45
+ }
46
+ return path;
47
+ };
48
+ var getItemElements = (dropdownElement, levelRoot) => {
49
+ const bodyElement = getBodyElement(dropdownElement);
15
50
  if (!bodyElement) return null;
16
- let items = bodyElement.querySelectorAll(ITEM_SELECTOR);
17
- if (items.length) return items;
18
- items = bodyElement.children;
51
+ const root = levelRoot ?? bodyElement;
52
+ const candidates = Array.from(root.querySelectorAll(ITEM_SELECTOR));
53
+ if (candidates.length) return candidates.filter((item) => {
54
+ if (item.matches(DISABLED_ITEM_SELECTOR)) return false;
55
+ return getLevelRoot(item) === (levelRoot ?? null);
56
+ });
57
+ let items = root.children;
19
58
  while (items.length === 1) {
20
59
  if (items[0].children == null) break;
21
60
  items = items[0].children;
22
61
  }
23
- if (items.length === 1) items = bodyElement.children;
24
- return items;
62
+ if (items.length === 1) items = root.children;
63
+ return Array.from(items).filter((item) => !item.matches(DISABLED_ITEM_SELECTOR));
64
+ };
65
+ var getItemForTarget = (dropdownElement, target) => {
66
+ let item = target.closest(ITEM_SELECTOR);
67
+ const targetLevelRoot = getLevelRoot(target);
68
+ if (!item || targetLevelRoot && item.contains(targetLevelRoot)) item = getItemElements(dropdownElement, targetLevelRoot)?.find((itemElement) => itemElement === target) ?? item;
69
+ if (!item || !dropdownElement.contains(item)) return null;
70
+ if (item.matches(DISABLED_ITEM_SELECTOR)) return null;
71
+ return item;
72
+ };
73
+ var getActiveItemElements = (dropdownElement) => {
74
+ if (!dropdownElement) return null;
75
+ const actives = dropdownElement.querySelectorAll("[data-ukt-active]");
76
+ return actives.length ? Array.from(actives) : null;
25
77
  };
26
78
  var getActiveItemElement = (dropdownElement) => {
79
+ const actives = getActiveItemElements(dropdownElement);
80
+ return actives ? actives[actives.length - 1] : null;
81
+ };
82
+ var getDeepestExpandedItem = (dropdownElement) => {
27
83
  if (!dropdownElement) return null;
28
- return dropdownElement.querySelector("[data-ukt-active]");
84
+ const expanded = Array.from(dropdownElement.querySelectorAll("[aria-expanded=\"true\"]")).filter((element) => element.matches(ITEM_SELECTOR));
85
+ return expanded.length ? expanded[expanded.length - 1] : null;
86
+ };
87
+ var isItemExpanded = (item) => item.getAttribute("aria-expanded") === "true";
88
+ var submenuIdCounter = 0;
89
+ var ensureSubmenuAria = (item, submenu) => {
90
+ if (!submenu.hasAttribute("role")) submenu.setAttribute("role", "menu");
91
+ if (!submenu.id) submenu.id = `uktdd-submenu-${++submenuIdCounter}`;
92
+ if (!item.hasAttribute("aria-haspopup")) item.setAttribute("aria-haspopup", "menu");
93
+ if (!item.hasAttribute("aria-expanded")) item.setAttribute("aria-expanded", "false");
94
+ if (!item.hasAttribute("aria-controls")) item.setAttribute("aria-controls", submenu.id);
95
+ };
96
+ var annotateParentItems = (bodyElement) => {
97
+ if (!bodyElement) return;
98
+ for (const submenu of Array.from(bodyElement.querySelectorAll(SUBMENU_SELECTOR))) {
99
+ const item = getParentItem(submenu);
100
+ if (item) ensureSubmenuAria(item, submenu);
101
+ }
102
+ };
103
+ var expandItem = (item, onToggleSubmenu) => {
104
+ const submenu = getSubmenuOfItem(item);
105
+ if (!submenu) return;
106
+ ensureSubmenuAria(item, submenu);
107
+ if (isItemExpanded(item)) return;
108
+ item.setAttribute("aria-expanded", "true");
109
+ onToggleSubmenu?.(item, true);
110
+ };
111
+ var collapseItem = (item, onToggleSubmenu) => {
112
+ if (!isItemExpanded(item)) return;
113
+ const submenu = getSubmenuOfItem(item);
114
+ if (submenu) {
115
+ const expandedDescendants = Array.from(submenu.querySelectorAll("[aria-expanded=\"true\"]")).filter((descendant) => descendant.matches(ITEM_SELECTOR));
116
+ for (const descendant of expandedDescendants) collapseItem(descendant, onToggleSubmenu);
117
+ for (const active of Array.from(submenu.querySelectorAll("[data-ukt-active]"))) delete active.dataset.uktActive;
118
+ }
119
+ item.setAttribute("aria-expanded", "false");
120
+ onToggleSubmenu?.(item, false);
121
+ };
122
+ var collapseItemsOutsidePath = (dropdownElement, element, onToggleSubmenu) => {
123
+ const bodyElement = getBodyElement(dropdownElement);
124
+ if (!bodyElement) return;
125
+ const expandedItems = Array.from(bodyElement.querySelectorAll("[aria-expanded=\"true\"]")).filter((item) => item.matches(ITEM_SELECTOR));
126
+ for (const item of expandedItems.reverse()) {
127
+ if (element && item.contains(element)) continue;
128
+ collapseItem(item, onToggleSubmenu);
129
+ }
29
130
  };
30
131
  var clearItemElementsState = (itemElements) => {
31
132
  itemElements.forEach((itemElement) => {
32
133
  if (itemElement.hasAttribute("data-ukt-active")) delete itemElement.dataset.uktActive;
134
+ for (const active of Array.from(itemElement.querySelectorAll("[data-ukt-active]"))) delete active.dataset.uktActive;
33
135
  });
34
136
  };
137
+ var setActiveChain = (dropdownElement, element) => {
138
+ const chain = /* @__PURE__ */ new Set([element]);
139
+ let levelRoot = getLevelRoot(element);
140
+ while (levelRoot) {
141
+ const parentItem = getParentItem(levelRoot);
142
+ if (!parentItem) break;
143
+ chain.add(parentItem);
144
+ levelRoot = getLevelRoot(parentItem);
145
+ }
146
+ for (const active of getActiveItemElements(dropdownElement) ?? []) if (!chain.has(active)) delete active.dataset.uktActive;
147
+ for (const item of chain) item.setAttribute("data-ukt-active", "");
148
+ };
35
149
  var setActiveItem = ({ dropdownElement, element, event, index, indexAddend, isExactMatch, onActiveItem, text }) => {
36
- const items = getItemElements(dropdownElement);
37
- if (!items) return;
38
- const itemElements = Array.from(items);
39
- if (!itemElements.length) return;
150
+ const currentDeepest = getActiveItemElement(dropdownElement);
151
+ const itemElements = getItemElements(dropdownElement, element ? getLevelRoot(element) : currentDeepest ? getLevelRoot(currentDeepest) : null);
152
+ if (!itemElements || itemElements.length === 0) return currentDeepest;
40
153
  const lastIndex = itemElements.length - 1;
41
- const currentActiveIndex = itemElements.findIndex((itemElement) => itemElement.hasAttribute("data-ukt-active"));
154
+ const currentActiveIndex = itemElements.findIndex((itemElement) => itemElement === currentDeepest);
42
155
  let nextActiveIndex = currentActiveIndex;
43
156
  if (typeof index === "number") nextActiveIndex = index < 0 ? itemElements.length + index : index;
44
- if (element) nextActiveIndex = itemElements.findIndex((itemElement) => itemElement === element);
45
- else if (typeof indexAddend === "number") {
157
+ if (element) {
158
+ nextActiveIndex = itemElements.findIndex((itemElement) => itemElement === element);
159
+ if (nextActiveIndex === -1) return currentDeepest;
160
+ } else if (typeof indexAddend === "number") {
46
161
  if (currentActiveIndex === -1 && indexAddend === -1) nextActiveIndex = lastIndex;
47
162
  else nextActiveIndex += indexAddend;
48
163
  nextActiveIndex = Math.max(0, Math.min(nextActiveIndex, lastIndex));
49
164
  } else if (typeof text === "string") {
50
165
  if (!text) {
51
166
  clearItemElementsState(itemElements);
52
- return;
167
+ return null;
53
168
  }
54
- const itemTexts = itemElements.map((itemElement) => itemElement.innerText);
169
+ const itemTexts = itemElements.map(getItemLabel);
55
170
  if (isExactMatch) {
56
171
  const textToCompare = text.toLowerCase();
57
172
  nextActiveIndex = itemTexts.findIndex((itemText) => itemText.toLowerCase().startsWith(textToCompare));
@@ -64,16 +179,16 @@ var setActiveItem = ({ dropdownElement, element, event, index, indexAddend, isEx
64
179
  nextActiveIndex = itemTexts.findIndex((itemText) => itemText === bestMatch);
65
180
  }
66
181
  }
67
- const nextActiveItem = items[nextActiveIndex];
68
- if (nextActiveItem == null || nextActiveIndex === currentActiveIndex) return;
69
- clearItemElementsState(itemElements);
70
- nextActiveItem.setAttribute("data-ukt-active", "");
71
- const label = nextActiveItem.innerText;
182
+ const nextActiveItem = itemElements[nextActiveIndex];
183
+ if (nextActiveItem == null || nextActiveItem === currentDeepest) return currentDeepest;
184
+ setActiveChain(dropdownElement, nextActiveItem);
185
+ const label = getItemLabel(nextActiveItem);
72
186
  const value = nextActiveItem.dataset.uktValue ?? label;
73
187
  onActiveItem?.({
74
188
  element: nextActiveItem,
75
189
  event,
76
190
  label,
191
+ path: getItemPath(nextActiveItem),
77
192
  value
78
193
  });
79
194
  let { parentElement } = nextActiveItem;
@@ -92,15 +207,186 @@ var setActiveItem = ({ dropdownElement, element, event, index, indexAddend, isEx
92
207
  scrollableParent.scrollTop = scrollTop;
93
208
  }
94
209
  }
210
+ return nextActiveItem;
211
+ };
212
+ var isPointInTriangle = (p, a, b, c) => {
213
+ const cross = (u, v, w) => (u.x - w.x) * (v.y - w.y) - (v.x - w.x) * (u.y - w.y);
214
+ const d1 = cross(p, a, b);
215
+ const d2 = cross(p, b, c);
216
+ const d3 = cross(p, c, a);
217
+ return !((d1 < 0 || d2 < 0 || d3 < 0) && (d1 > 0 || d2 > 0 || d3 > 0));
95
218
  };
96
219
  //#endregion
220
+ //#region src/Menubar.tsx
221
+ var compareDocumentOrder = (a, b) => {
222
+ if (a.element === b.element) return 0;
223
+ const position = a.element.compareDocumentPosition(b.element);
224
+ if ((position & Node.DOCUMENT_POSITION_FOLLOWING) !== 0) return -1;
225
+ if ((position & Node.DOCUMENT_POSITION_PRECEDING) !== 0) return 1;
226
+ return 0;
227
+ };
228
+ function Menubar(t0) {
229
+ const $ = c(15);
230
+ const { children, className, style } = t0;
231
+ let t1;
232
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
233
+ t1 = /* @__PURE__ */ new Set();
234
+ $[0] = t1;
235
+ } else t1 = $[0];
236
+ const membersRef = useRef(t1);
237
+ let t2;
238
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
239
+ t2 = () => Array.from(membersRef.current).sort(compareDocumentOrder);
240
+ $[1] = t2;
241
+ } else t2 = $[1];
242
+ const getOrderedMembersRef = useRef(t2);
243
+ const getOrderedMembers = getOrderedMembersRef.current;
244
+ let t3;
245
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
246
+ t3 = {
247
+ moveOpen(fromElement, direction) {
248
+ const members = getOrderedMembersRef.current();
249
+ if (members.length < 2) return;
250
+ const index = members.findIndex((member) => member.element === fromElement);
251
+ if (index === -1) return;
252
+ const nextIndex = (index + direction + members.length) % members.length;
253
+ members[index].close();
254
+ members[nextIndex].open();
255
+ members[nextIndex].focusTrigger();
256
+ },
257
+ notifyOpened(element) {
258
+ for (const member_0 of membersRef.current) if (member_0.element !== element && member_0.isOpen()) member_0.close();
259
+ },
260
+ registerMember(member_1) {
261
+ membersRef.current.add(member_1);
262
+ return () => {
263
+ membersRef.current.delete(member_1);
264
+ };
265
+ }
266
+ };
267
+ $[2] = t3;
268
+ } else t3 = $[2];
269
+ const contextValue = t3;
270
+ let t4;
271
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
272
+ t4 = (event) => {
273
+ const { key } = event;
274
+ if (key !== "ArrowLeft" && key !== "ArrowRight") return;
275
+ const members_0 = getOrderedMembers();
276
+ if (members_0.length < 2) return;
277
+ if (members_0.some(_temp$1)) return;
278
+ const eventTarget = event.target;
279
+ const index_0 = members_0.findIndex((member_3) => member_3.element.contains(eventTarget));
280
+ if (index_0 === -1) return;
281
+ event.preventDefault();
282
+ event.stopPropagation();
283
+ members_0[(index_0 + (key === "ArrowRight" ? 1 : -1) + members_0.length) % members_0.length].focusTrigger();
284
+ };
285
+ $[3] = t4;
286
+ } else t4 = $[3];
287
+ const handleKeyDown = t4;
288
+ let t5;
289
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
290
+ t5 = (eventTarget_0) => {
291
+ const members_1 = getOrderedMembers();
292
+ if (!members_1.some(_temp2)) return;
293
+ const member_5 = members_1.find((m) => m.element.contains(eventTarget_0));
294
+ if (!member_5 || member_5.isOpen()) return;
295
+ member_5.open();
296
+ };
297
+ $[4] = t5;
298
+ } else t5 = $[4];
299
+ const switchToMemberAt = t5;
300
+ let t6;
301
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
302
+ t6 = (event_0) => {
303
+ switchToMemberAt(event_0.target);
304
+ };
305
+ $[5] = t6;
306
+ } else t6 = $[5];
307
+ const handleFocus = t6;
308
+ let t7;
309
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
310
+ t7 = (event_1) => {
311
+ switchToMemberAt(event_1.target);
312
+ };
313
+ $[6] = t7;
314
+ } else t7 = $[6];
315
+ const handleMouseOver = t7;
316
+ let t8;
317
+ if ($[7] !== className) {
318
+ t8 = clsx("uktmenubar", className);
319
+ $[7] = className;
320
+ $[8] = t8;
321
+ } else t8 = $[8];
322
+ let t9;
323
+ if ($[9] !== children) {
324
+ t9 = /* @__PURE__ */ jsx(MenubarContext.Provider, {
325
+ value: contextValue,
326
+ children
327
+ });
328
+ $[9] = children;
329
+ $[10] = t9;
330
+ } else t9 = $[10];
331
+ let t10;
332
+ if ($[11] !== style || $[12] !== t8 || $[13] !== t9) {
333
+ t10 = /* @__PURE__ */ jsx("div", {
334
+ className: t8,
335
+ onFocus: handleFocus,
336
+ onKeyDown: handleKeyDown,
337
+ onMouseOver: handleMouseOver,
338
+ role: "menubar",
339
+ style,
340
+ children: t9
341
+ });
342
+ $[11] = style;
343
+ $[12] = t8;
344
+ $[13] = t9;
345
+ $[14] = t10;
346
+ } else t10 = $[14];
347
+ return t10;
348
+ }
349
+ function _temp2(member_4) {
350
+ return member_4.isOpen();
351
+ }
352
+ function _temp$1(member_2) {
353
+ return member_2.isOpen();
354
+ }
355
+ //#endregion
97
356
  //#region src/Dropdown.tsx
98
357
  var CHILDREN_ERROR = "@acusti/dropdown requires either 1 child (the dropdown body) or 2 children: the dropdown trigger and the dropdown body.";
99
358
  var CLICKABLE_SELECTOR = "button, a[href], input[type=\"button\"], input[type=\"submit\"]";
359
+ var FOCUSABLE_SELECTOR = "a[href], button, input, select, textarea, [tabindex]";
100
360
  var TEXT_INPUT_SELECTOR = "input:not([type=radio]):not([type=checkbox]):not([type=range]),textarea";
101
- function Dropdown(t0) {
102
- const $ = c(95);
103
- const { allowCreate, allowEmpty: t1, children, className, disabled, hasItems: t2, isOpenOnMount, isSearchable, keepOpenOnSubmit: t3, label, minHeightBody, minWidthBody, name, onActiveItem, onClick, onClose, onMouseDown, onMouseUp, onOpen, onSubmitItem, placeholder, style: styleFromProps, tabIndex, value } = t0;
361
+ var SUBMENU_DISCLOSURE_DELAY = 200;
362
+ var SAFE_AREA_TIMEOUT = 300;
363
+ function Dropdown(props) {
364
+ const $ = c(5);
365
+ const parentDropdown = useContext(DropdownContext);
366
+ if (parentDropdown && props.hasItems !== false) {
367
+ let t0;
368
+ if ($[0] !== parentDropdown || $[1] !== props) {
369
+ t0 = /* @__PURE__ */ jsx(SubmenuDropdown, {
370
+ ...props,
371
+ parentDropdown
372
+ });
373
+ $[0] = parentDropdown;
374
+ $[1] = props;
375
+ $[2] = t0;
376
+ } else t0 = $[2];
377
+ return t0;
378
+ }
379
+ let t0;
380
+ if ($[3] !== props) {
381
+ t0 = /* @__PURE__ */ jsx(RootDropdown, { ...props });
382
+ $[3] = props;
383
+ $[4] = t0;
384
+ } else t0 = $[4];
385
+ return t0;
386
+ }
387
+ function RootDropdown(t0) {
388
+ const $ = c(130);
389
+ const { allowCreate, allowEmpty: t1, children, className, disabled, hasItems: t2, isOpenOnMount, isSearchable, keepOpenOnSubmit: t3, label, name, onActiveItem, onClick, onClose, onMouseDown, onMouseUp, onOpen, onSubmitItem, placeholder, style: styleFromProps, tabIndex, value } = t0;
104
390
  const allowEmpty = t1 === void 0 ? true : t1;
105
391
  const hasItems = t2 === void 0 ? true : t2;
106
392
  const keepOpenOnSubmit = t3 === void 0 ? !hasItems : t3;
@@ -116,6 +402,7 @@ function Dropdown(t0) {
116
402
  const [dropdownElement, setDropdownElement] = useState(null);
117
403
  const bodyId = useId();
118
404
  const popupRole = isSearchable ? "listbox" : hasItems ? "menu" : "dialog";
405
+ const menubar = useContext(MenubarContext);
119
406
  const inputElementRef = useRef(null);
120
407
  const closingTimerRef = useRef(null);
121
408
  const isOpeningTimerRef = useRef(null);
@@ -123,6 +410,19 @@ function Dropdown(t0) {
123
410
  const clearEnteredCharactersTimerRef = useRef(null);
124
411
  const enteredCharactersRef = useRef("");
125
412
  const mouseDownPositionRef = useRef(null);
413
+ const disclosureTimerRef = useRef(null);
414
+ const pendingDisclosureItemRef = useRef(null);
415
+ let t4;
416
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
417
+ t4 = /* @__PURE__ */ new Set();
418
+ $[0] = t4;
419
+ } else t4 = $[0];
420
+ const submenuRegistrationsRef = useRef(t4);
421
+ const pointerRef = useRef(null);
422
+ const lastMouseEventRef = useRef(null);
423
+ const safeAreaRef = useRef(null);
424
+ const safeAreaTimerRef = useRef(null);
425
+ const wasInSafeAreaRef = useRef(false);
126
426
  const allowCreateRef = useRef(allowCreate);
127
427
  const allowEmptyRef = useRef(allowEmpty);
128
428
  const hasItemsRef = useRef(hasItems);
@@ -133,10 +433,10 @@ function Dropdown(t0) {
133
433
  const onOpenRef = useRef(onOpen);
134
434
  const onSubmitItemRef = useRef(onSubmitItem);
135
435
  const valueRef = useRef(value);
136
- let t4;
137
436
  let t5;
138
- if ($[0] !== allowCreate || $[1] !== allowEmpty || $[2] !== hasItems || $[3] !== isOpen || $[4] !== isOpening || $[5] !== keepOpenOnSubmit || $[6] !== onClose || $[7] !== onOpen || $[8] !== onSubmitItem || $[9] !== value) {
139
- t4 = () => {
437
+ let t6;
438
+ if ($[1] !== allowCreate || $[2] !== allowEmpty || $[3] !== hasItems || $[4] !== isOpen || $[5] !== isOpening || $[6] !== keepOpenOnSubmit || $[7] !== onClose || $[8] !== onOpen || $[9] !== onSubmitItem || $[10] !== value) {
439
+ t5 = () => {
140
440
  allowCreateRef.current = allowCreate;
141
441
  allowEmptyRef.current = allowEmpty;
142
442
  hasItemsRef.current = hasItems;
@@ -148,7 +448,7 @@ function Dropdown(t0) {
148
448
  onSubmitItemRef.current = onSubmitItem;
149
449
  valueRef.current = value;
150
450
  };
151
- t5 = [
451
+ t6 = [
152
452
  allowCreate,
153
453
  allowEmpty,
154
454
  hasItems,
@@ -160,28 +460,28 @@ function Dropdown(t0) {
160
460
  onSubmitItem,
161
461
  value
162
462
  ];
163
- $[0] = allowCreate;
164
- $[1] = allowEmpty;
165
- $[2] = hasItems;
166
- $[3] = isOpen;
167
- $[4] = isOpening;
168
- $[5] = keepOpenOnSubmit;
169
- $[6] = onClose;
170
- $[7] = onOpen;
171
- $[8] = onSubmitItem;
172
- $[9] = value;
173
- $[10] = t4;
463
+ $[1] = allowCreate;
464
+ $[2] = allowEmpty;
465
+ $[3] = hasItems;
466
+ $[4] = isOpen;
467
+ $[5] = isOpening;
468
+ $[6] = keepOpenOnSubmit;
469
+ $[7] = onClose;
470
+ $[8] = onOpen;
471
+ $[9] = onSubmitItem;
472
+ $[10] = value;
174
473
  $[11] = t5;
474
+ $[12] = t6;
175
475
  } else {
176
- t4 = $[10];
177
476
  t5 = $[11];
477
+ t6 = $[12];
178
478
  }
179
- useEffect(t4, t5);
479
+ useEffect(t5, t6);
180
480
  const isMountedRef = useRef(false);
181
- let t6;
182
481
  let t7;
183
- if ($[12] !== isOpen) {
184
- t6 = () => {
482
+ let t8;
483
+ if ($[13] !== isOpen) {
484
+ t7 = () => {
185
485
  if (!isMountedRef.current) {
186
486
  isMountedRef.current = true;
187
487
  if (isOpenRef.current && onOpenRef.current) onOpenRef.current();
@@ -190,35 +490,303 @@ function Dropdown(t0) {
190
490
  if (isOpen && onOpenRef.current) onOpenRef.current();
191
491
  else if (!isOpen && onCloseRef.current) onCloseRef.current();
192
492
  };
193
- t7 = [isOpen];
194
- $[12] = isOpen;
195
- $[13] = t6;
493
+ t8 = [isOpen];
494
+ $[13] = isOpen;
196
495
  $[14] = t7;
496
+ $[15] = t8;
197
497
  } else {
198
- t6 = $[13];
199
498
  t7 = $[14];
499
+ t8 = $[15];
200
500
  }
201
- useEffect(t6, t7);
202
- let t8;
203
- if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
204
- t8 = () => {
501
+ useEffect(t7, t8);
502
+ let t9;
503
+ if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
504
+ t9 = { registerSubmenu(registration) {
505
+ submenuRegistrationsRef.current.add(registration);
506
+ return () => {
507
+ submenuRegistrationsRef.current.delete(registration);
508
+ };
509
+ } };
510
+ $[16] = t9;
511
+ } else t9 = $[16];
512
+ const dropdownContextValue = t9;
513
+ let t10;
514
+ if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
515
+ t10 = (key, payload) => {
516
+ if (!payload.element) return;
517
+ for (const registration_0 of submenuRegistrationsRef.current) if (registration_0.element.contains(payload.element)) registration_0[key]?.(payload);
518
+ };
519
+ $[17] = t10;
520
+ } else t10 = $[17];
521
+ const dispatchToSubmenus = t10;
522
+ let t11;
523
+ if ($[18] !== onActiveItem) {
524
+ t11 = (payload_0) => {
525
+ onActiveItem?.(payload_0);
526
+ dispatchToSubmenus("onActiveItem", payload_0);
527
+ };
528
+ $[18] = onActiveItem;
529
+ $[19] = t11;
530
+ } else t11 = $[19];
531
+ const handleActiveItem = t11;
532
+ let t12;
533
+ if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
534
+ t12 = (item, isExpanded) => {
535
+ for (const registration_1 of submenuRegistrationsRef.current) if (registration_1.element === item) (isExpanded ? registration_1.onOpen : registration_1.onClose)?.();
536
+ };
537
+ $[20] = t12;
538
+ } else t12 = $[20];
539
+ const handleToggleSubmenu = t12;
540
+ let t13;
541
+ if ($[21] === Symbol.for("react.memo_cache_sentinel")) {
542
+ t13 = () => {
543
+ if (disclosureTimerRef.current != null) {
544
+ clearTimeout(disclosureTimerRef.current);
545
+ disclosureTimerRef.current = null;
546
+ }
547
+ pendingDisclosureItemRef.current = null;
548
+ };
549
+ $[21] = t13;
550
+ } else t13 = $[21];
551
+ const clearDisclosureTimer = t13;
552
+ let t14;
553
+ let t15;
554
+ if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
555
+ t14 = () => clearDisclosureTimer;
556
+ t15 = [];
557
+ $[22] = t14;
558
+ $[23] = t15;
559
+ } else {
560
+ t14 = $[22];
561
+ t15 = $[23];
562
+ }
563
+ useEffect(t14, t15);
564
+ let t16;
565
+ if ($[24] !== dropdownElement) {
566
+ t16 = () => {
567
+ if (!dropdownElement) return;
568
+ const activeElement = getActiveItemElement(dropdownElement);
569
+ collapseItemsOutsidePath(dropdownElement, activeElement, handleToggleSubmenu);
570
+ const submenu = activeElement ? getSubmenuOfItem(activeElement) : null;
571
+ if (activeElement && submenu && !isItemExpanded(activeElement)) {
572
+ if (pendingDisclosureItemRef.current === activeElement) return;
573
+ clearDisclosureTimer();
574
+ pendingDisclosureItemRef.current = activeElement;
575
+ disclosureTimerRef.current = setTimeout(() => {
576
+ disclosureTimerRef.current = null;
577
+ pendingDisclosureItemRef.current = null;
578
+ if (!activeElement.hasAttribute("data-ukt-active")) return;
579
+ expandItem(activeElement, handleToggleSubmenu);
580
+ }, SUBMENU_DISCLOSURE_DELAY);
581
+ return;
582
+ }
583
+ clearDisclosureTimer();
584
+ };
585
+ $[24] = dropdownElement;
586
+ $[25] = t16;
587
+ } else t16 = $[25];
588
+ const syncSubmenuDisclosure = t16;
589
+ let t17;
590
+ if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
591
+ t17 = () => {
592
+ if (safeAreaTimerRef.current != null) {
593
+ clearTimeout(safeAreaTimerRef.current);
594
+ safeAreaTimerRef.current = null;
595
+ }
596
+ };
597
+ $[26] = t17;
598
+ } else t17 = $[26];
599
+ const clearSafeAreaTimer = t17;
600
+ let t18;
601
+ let t19;
602
+ if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
603
+ t18 = () => clearSafeAreaTimer;
604
+ t19 = [];
605
+ $[27] = t18;
606
+ $[28] = t19;
607
+ } else {
608
+ t18 = $[27];
609
+ t19 = $[28];
610
+ }
611
+ useEffect(t18, t19);
612
+ let t20;
613
+ if ($[29] === Symbol.for("react.memo_cache_sentinel")) {
614
+ t20 = (x, y) => {
615
+ const safeArea = safeAreaRef.current;
616
+ if (!safeArea || !isItemExpanded(safeArea.parent)) return false;
617
+ const submenu_0 = getSubmenuOfItem(safeArea.parent);
618
+ if (!submenu_0) return false;
619
+ const submenuRect = submenu_0.getBoundingClientRect();
620
+ const parentRect = safeArea.parent.getBoundingClientRect();
621
+ const nearX = submenuRect.left >= parentRect.right - 1 ? submenuRect.left : submenuRect.right;
622
+ return isPointInTriangle({
623
+ x,
624
+ y
625
+ }, safeArea.apex, {
626
+ x: nearX,
627
+ y: submenuRect.top
628
+ }, {
629
+ x: nearX,
630
+ y: submenuRect.bottom
631
+ });
632
+ };
633
+ $[29] = t20;
634
+ } else t20 = $[29];
635
+ const isPointerInSafeArea = t20;
636
+ let t21;
637
+ if ($[30] !== dropdownElement || $[31] !== handleActiveItem || $[32] !== syncSubmenuDisclosure) {
638
+ t21 = (targetElement) => {
639
+ clearSafeAreaTimer();
640
+ safeAreaRef.current = null;
641
+ wasInSafeAreaRef.current = false;
642
+ const pointer = pointerRef.current;
643
+ const target = targetElement ?? (pointer ? dropdownElement?.ownerDocument.elementFromPoint(pointer.x, pointer.y) : null);
644
+ if (!dropdownElement || !target || !dropdownElement.contains(target)) return;
645
+ const item_0 = getItemForTarget(dropdownElement, target);
646
+ const event = lastMouseEventRef.current;
647
+ if (item_0 && event) setActiveItem({
648
+ dropdownElement,
649
+ element: item_0,
650
+ event,
651
+ onActiveItem: handleActiveItem
652
+ });
653
+ syncSubmenuDisclosure();
654
+ };
655
+ $[30] = dropdownElement;
656
+ $[31] = handleActiveItem;
657
+ $[32] = syncSubmenuDisclosure;
658
+ $[33] = t21;
659
+ } else t21 = $[33];
660
+ const commitPointerTarget = t21;
661
+ let t22;
662
+ if ($[34] !== commitPointerTarget || $[35] !== dropdownElement) {
663
+ t22 = (event_0) => {
664
+ if (!dropdownElement || !isOpenRef.current || !hasItemsRef.current) return;
665
+ const pointer_0 = {
666
+ x: event_0.clientX,
667
+ y: event_0.clientY
668
+ };
669
+ pointerRef.current = pointer_0;
670
+ lastMouseEventRef.current = event_0.nativeEvent;
671
+ const parent = getDeepestExpandedItem(dropdownElement);
672
+ if (!parent) {
673
+ safeAreaRef.current = null;
674
+ wasInSafeAreaRef.current = false;
675
+ clearSafeAreaTimer();
676
+ return;
677
+ }
678
+ const target_0 = event_0.target;
679
+ const submenu_1 = getSubmenuOfItem(parent);
680
+ if (parent.contains(target_0) && !(submenu_1?.contains(target_0) ?? false)) {
681
+ safeAreaRef.current = {
682
+ apex: pointer_0,
683
+ parent
684
+ };
685
+ wasInSafeAreaRef.current = false;
686
+ clearSafeAreaTimer();
687
+ return;
688
+ }
689
+ if (safeAreaRef.current?.parent !== parent) safeAreaRef.current = null;
690
+ clearSafeAreaTimer();
691
+ if (isPointerInSafeArea(pointer_0.x, pointer_0.y)) {
692
+ wasInSafeAreaRef.current = true;
693
+ safeAreaTimerRef.current = setTimeout(commitPointerTarget, SAFE_AREA_TIMEOUT);
694
+ } else if (wasInSafeAreaRef.current) commitPointerTarget(target_0);
695
+ };
696
+ $[34] = commitPointerTarget;
697
+ $[35] = dropdownElement;
698
+ $[36] = t22;
699
+ } else t22 = $[36];
700
+ const trackSafeArea = t22;
701
+ let t23;
702
+ if ($[37] === Symbol.for("react.memo_cache_sentinel")) {
703
+ t23 = () => {
205
704
  setIsOpen(false);
206
705
  setIsOpening(false);
207
706
  mouseDownPositionRef.current = null;
707
+ clearDisclosureTimer();
708
+ clearSafeAreaTimer();
709
+ safeAreaRef.current = null;
710
+ wasInSafeAreaRef.current = false;
208
711
  if (closingTimerRef.current != null) {
209
712
  clearTimeout(closingTimerRef.current);
210
713
  closingTimerRef.current = null;
211
714
  }
212
715
  };
213
- $[15] = t8;
214
- } else t8 = $[15];
215
- const closeDropdown = t8;
216
- let t9;
217
- if ($[16] !== dropdownElement) {
218
- t9 = (event) => {
716
+ $[37] = t23;
717
+ } else t23 = $[37];
718
+ const closeDropdown = t23;
719
+ let t24;
720
+ if ($[38] !== dropdownElement?.firstElementChild) {
721
+ t24 = () => {
722
+ const firstChild = dropdownElement?.firstElementChild;
723
+ if (!firstChild) return;
724
+ (firstChild.matches(FOCUSABLE_SELECTOR) ? firstChild : firstChild.querySelector(FOCUSABLE_SELECTOR))?.focus();
725
+ };
726
+ $[38] = dropdownElement?.firstElementChild;
727
+ $[39] = t24;
728
+ } else t24 = $[39];
729
+ const focusTrigger = t24;
730
+ let t25;
731
+ if ($[40] !== dropdownElement || $[41] !== focusTrigger || $[42] !== menubar) {
732
+ t25 = () => {
733
+ if (!menubar || !dropdownElement) return;
734
+ return menubar.registerMember({
735
+ close: closeDropdown,
736
+ element: dropdownElement,
737
+ focusTrigger,
738
+ isOpen: () => isOpenRef.current,
739
+ open: () => setIsOpen(true)
740
+ });
741
+ };
742
+ $[40] = dropdownElement;
743
+ $[41] = focusTrigger;
744
+ $[42] = menubar;
745
+ $[43] = t25;
746
+ } else t25 = $[43];
747
+ useEffect(t25);
748
+ let t26;
749
+ let t27;
750
+ if ($[44] !== dropdownElement || $[45] !== isOpen || $[46] !== menubar) {
751
+ t26 = () => {
752
+ if (isOpen && menubar && dropdownElement) menubar.notifyOpened(dropdownElement);
753
+ };
754
+ t27 = [
755
+ dropdownElement,
756
+ isOpen,
757
+ menubar
758
+ ];
759
+ $[44] = dropdownElement;
760
+ $[45] = isOpen;
761
+ $[46] = menubar;
762
+ $[47] = t26;
763
+ $[48] = t27;
764
+ } else {
765
+ t26 = $[47];
766
+ t27 = $[48];
767
+ }
768
+ useEffect(t26, t27);
769
+ let t28;
770
+ if ($[49] !== dropdownElement || $[50] !== handleActiveItem) {
771
+ t28 = (event_1) => {
772
+ const element = hasItemsRef.current ? getActiveItemElement(dropdownElement) : null;
773
+ const submenuOfActive = element ? getSubmenuOfItem(element) : null;
774
+ if (element && submenuOfActive) {
775
+ clearDisclosureTimer();
776
+ expandItem(element, handleToggleSubmenu);
777
+ if (currentInputMethodRef.current === "keyboard" && dropdownElement) {
778
+ const firstItem = getItemElements(dropdownElement, submenuOfActive)?.[0];
779
+ if (firstItem) setActiveItem({
780
+ dropdownElement,
781
+ element: firstItem,
782
+ event: event_1,
783
+ onActiveItem: handleActiveItem
784
+ });
785
+ }
786
+ return;
787
+ }
219
788
  if (isOpenRef.current && !keepOpenOnSubmitRef.current) closingTimerRef.current = setTimeout(closeDropdown, 90);
220
789
  if (!hasItemsRef.current) return;
221
- const element = getActiveItemElement(dropdownElement);
222
790
  if (!element) {
223
791
  if (!inputElementRef.current) return;
224
792
  if (inputElementRef.current.value) {
@@ -234,7 +802,7 @@ function Dropdown(t0) {
234
802
  const nextValue = element?.dataset.uktValue ?? itemLabel;
235
803
  if (valueRef.current && valueRef.current === nextValue) return;
236
804
  if (element) {
237
- const eventTarget = event.target;
805
+ const eventTarget = event_1.target;
238
806
  if (element.matches(CLICKABLE_SELECTOR)) {
239
807
  if (element !== eventTarget && !element.contains(eventTarget)) element.click();
240
808
  } else {
@@ -245,142 +813,177 @@ function Dropdown(t0) {
245
813
  }
246
814
  }
247
815
  }
248
- onSubmitItemRef.current?.({
816
+ const payload_1 = {
249
817
  element,
250
- event,
818
+ event: event_1,
251
819
  label: itemLabel,
820
+ path: getItemPath(element),
252
821
  value: nextValue
253
- });
822
+ };
823
+ onSubmitItemRef.current?.(payload_1);
824
+ dispatchToSubmenus("onSubmitItem", payload_1);
254
825
  };
255
- $[16] = dropdownElement;
256
- $[17] = t9;
257
- } else t9 = $[17];
258
- const handleSubmitItem = t9;
259
- let t10;
260
- if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
261
- t10 = (t11) => {
262
- const { clientX, clientY } = t11;
826
+ $[49] = dropdownElement;
827
+ $[50] = handleActiveItem;
828
+ $[51] = t28;
829
+ } else t28 = $[51];
830
+ const handleSubmitItem = t28;
831
+ let t29;
832
+ if ($[52] !== trackSafeArea) {
833
+ t29 = (event_2) => {
834
+ const { clientX, clientY } = event_2;
263
835
  currentInputMethodRef.current = "mouse";
836
+ trackSafeArea(event_2);
264
837
  const initialPosition = mouseDownPositionRef.current;
265
838
  if (!initialPosition) return;
266
839
  if (Math.abs(initialPosition.clientX - clientX) < 12 && Math.abs(initialPosition.clientY - clientY) < 12) return;
267
840
  setIsOpening(false);
268
841
  };
269
- $[18] = t10;
270
- } else t10 = $[18];
271
- const handleMouseMove = t10;
272
- let t11;
273
- if ($[19] !== dropdownElement || $[20] !== onActiveItem) {
274
- t11 = (event_0) => {
842
+ $[52] = trackSafeArea;
843
+ $[53] = t29;
844
+ } else t29 = $[53];
845
+ const handleMouseMove = t29;
846
+ let t30;
847
+ if ($[54] !== dropdownElement || $[55] !== handleActiveItem || $[56] !== syncSubmenuDisclosure) {
848
+ t30 = (event_3) => {
275
849
  if (!hasItemsRef.current) return;
276
850
  if (currentInputMethodRef.current !== "mouse") return;
277
851
  if (!dropdownElement) return;
278
- const itemElements = getItemElements(dropdownElement);
279
- if (!itemElements) return;
280
- const eventTarget_0 = event_0.target;
281
- const element_0 = eventTarget_0.closest(ITEM_SELECTOR) ?? eventTarget_0;
282
- for (const itemElement of itemElements) if (itemElement === element_0) {
283
- setActiveItem({
284
- dropdownElement,
285
- element: element_0,
286
- event: event_0,
287
- onActiveItem
288
- });
289
- return;
290
- }
852
+ const eventTarget_0 = event_3.target;
853
+ if (!eventTarget_0.closest(".uktdropdown-body")) return;
854
+ const hoveredRoot = eventTarget_0.closest(".uktdropdown");
855
+ if (hoveredRoot !== dropdownElement && hoveredRoot?.classList.contains("is-open")) return;
856
+ if (isPointerInSafeArea(event_3.clientX, event_3.clientY)) return;
857
+ const item_1 = getItemForTarget(dropdownElement, eventTarget_0);
858
+ if (!item_1) return;
859
+ setActiveItem({
860
+ dropdownElement,
861
+ element: item_1,
862
+ event: event_3,
863
+ onActiveItem: handleActiveItem
864
+ });
865
+ syncSubmenuDisclosure();
291
866
  };
292
- $[19] = dropdownElement;
293
- $[20] = onActiveItem;
294
- $[21] = t11;
295
- } else t11 = $[21];
296
- const handleMouseOver = t11;
297
- let t12;
298
- if ($[22] !== dropdownElement) {
299
- t12 = (event_1) => {
867
+ $[54] = dropdownElement;
868
+ $[55] = handleActiveItem;
869
+ $[56] = syncSubmenuDisclosure;
870
+ $[57] = t30;
871
+ } else t30 = $[57];
872
+ const handleMouseOver = t30;
873
+ let t31;
874
+ if ($[58] !== dropdownElement || $[59] !== syncSubmenuDisclosure) {
875
+ t31 = (event_4) => {
300
876
  if (!hasItemsRef.current) return;
877
+ const relatedTarget = event_4.relatedTarget;
878
+ if (!dropdownElement?.contains(relatedTarget)) {
879
+ clearSafeAreaTimer();
880
+ safeAreaRef.current = null;
881
+ wasInSafeAreaRef.current = false;
882
+ }
883
+ if (isPointerInSafeArea(event_4.clientX, event_4.clientY)) return;
301
884
  const activeItem = getActiveItemElement(dropdownElement);
302
885
  if (!activeItem) return;
303
- const eventRelatedTarget = event_1.relatedTarget;
304
- if (activeItem !== event_1.target || activeItem.contains(eventRelatedTarget)) return;
886
+ const eventRelatedTarget = event_4.relatedTarget;
887
+ if (activeItem !== event_4.target || activeItem.contains(eventRelatedTarget)) return;
305
888
  delete activeItem.dataset.uktActive;
889
+ syncSubmenuDisclosure();
306
890
  };
307
- $[22] = dropdownElement;
308
- $[23] = t12;
309
- } else t12 = $[23];
310
- const handleMouseOut = t12;
311
- let t13;
312
- if ($[24] !== onMouseDown) {
313
- t13 = (event_2) => {
314
- if (onMouseDown) onMouseDown(event_2);
891
+ $[58] = dropdownElement;
892
+ $[59] = syncSubmenuDisclosure;
893
+ $[60] = t31;
894
+ } else t31 = $[60];
895
+ const handleMouseOut = t31;
896
+ let t32;
897
+ if ($[61] !== onMouseDown) {
898
+ t32 = (event_5) => {
899
+ if (onMouseDown) onMouseDown(event_5);
315
900
  if (isOpenRef.current) return;
316
901
  setIsOpen(true);
317
902
  setIsOpening(true);
318
903
  mouseDownPositionRef.current = {
319
- clientX: event_2.clientX,
320
- clientY: event_2.clientY
904
+ clientX: event_5.clientX,
905
+ clientY: event_5.clientY
321
906
  };
322
907
  isOpeningTimerRef.current = setTimeout(() => {
323
908
  setIsOpening(false);
324
909
  isOpeningTimerRef.current = null;
325
910
  }, 1e3);
326
911
  };
327
- $[24] = onMouseDown;
328
- $[25] = t13;
329
- } else t13 = $[25];
330
- const handleMouseDown = t13;
331
- let t14;
332
- if ($[26] !== handleSubmitItem || $[27] !== onMouseUp) {
333
- t14 = (event_3) => {
334
- if (onMouseUp) onMouseUp(event_3);
912
+ $[61] = onMouseDown;
913
+ $[62] = t32;
914
+ } else t32 = $[62];
915
+ const handleMouseDown = t32;
916
+ let t33;
917
+ if ($[63] !== dropdownElement || $[64] !== handleActiveItem || $[65] !== handleSubmitItem || $[66] !== onMouseUp) {
918
+ t33 = (event_6) => {
919
+ if (onMouseUp) onMouseUp(event_6);
335
920
  if (isOpeningRef.current || !isOpenRef.current || closingTimerRef.current != null) return;
336
- const eventTarget_1 = event_3.target;
337
- if (!eventTarget_1.closest(".uktdropdown-body")) {
921
+ const eventTarget_1 = event_6.target;
922
+ const clickedRoot = eventTarget_1.closest(".uktdropdown");
923
+ if (clickedRoot !== dropdownElement && clickedRoot?.classList.contains("is-open") && dropdownElement?.contains(clickedRoot)) return;
924
+ const targetBody = eventTarget_1.closest(".uktdropdown-body");
925
+ if (!Boolean(targetBody && targetBody.closest(".uktdropdown") === dropdownElement)) {
338
926
  if (!isOpeningRef.current && inputElementRef.current !== eventTarget_1.ownerDocument.activeElement) closeDropdown();
339
927
  return;
340
928
  }
341
929
  if (!hasItemsRef.current) return;
342
- handleSubmitItem(event_3);
930
+ if (dropdownElement) {
931
+ const clickedItem = getItemForTarget(dropdownElement, eventTarget_1);
932
+ if (clickedItem) setActiveItem({
933
+ dropdownElement,
934
+ element: clickedItem,
935
+ event: event_6,
936
+ onActiveItem: handleActiveItem
937
+ });
938
+ else if (getActiveItemElement(dropdownElement)) return;
939
+ }
940
+ handleSubmitItem(event_6);
343
941
  };
344
- $[26] = handleSubmitItem;
345
- $[27] = onMouseUp;
346
- $[28] = t14;
347
- } else t14 = $[28];
348
- const handleMouseUp = t14;
349
- let t15;
350
- if ($[29] !== dropdownElement || $[30] !== handleSubmitItem || $[31] !== onActiveItem) {
351
- t15 = (event_4) => {
352
- const { altKey, ctrlKey, key, metaKey } = event_4;
353
- const eventTarget_2 = event_4.target;
942
+ $[63] = dropdownElement;
943
+ $[64] = handleActiveItem;
944
+ $[65] = handleSubmitItem;
945
+ $[66] = onMouseUp;
946
+ $[67] = t33;
947
+ } else t33 = $[67];
948
+ const handleMouseUp = t33;
949
+ let t34;
950
+ if ($[68] !== dropdownElement || $[69] !== focusTrigger || $[70] !== handleActiveItem || $[71] !== handleSubmitItem || $[72] !== menubar || $[73] !== syncSubmenuDisclosure) {
951
+ t34 = (event_7) => {
952
+ const { altKey, ctrlKey, key: key_0, metaKey } = event_7;
953
+ const eventTarget_2 = event_7.target;
354
954
  if (!dropdownElement) return;
355
955
  const onEventHandled = () => {
356
- event_4.stopPropagation();
357
- event_4.preventDefault();
956
+ event_7.stopPropagation();
957
+ event_7.preventDefault();
358
958
  currentInputMethodRef.current = "keyboard";
359
959
  };
360
960
  const isEventTargetingDropdown = dropdownElement.contains(eventTarget_2);
961
+ const nestedRoot = eventTarget_2.closest?.(".uktdropdown");
962
+ if (nestedRoot && nestedRoot !== dropdownElement && dropdownElement.contains(nestedRoot) && nestedRoot.classList.contains("is-open")) return;
361
963
  if (!isOpenRef.current) {
362
964
  if (!isEventTargetingDropdown) return;
363
- if (key === " " || key === "Enter" || hasItemsRef.current && (key === "ArrowUp" || key === "ArrowDown")) {
965
+ if (key_0 === " " || key_0 === "Enter" || hasItemsRef.current && (key_0 === "ArrowUp" || key_0 === "ArrowDown")) {
364
966
  onEventHandled();
365
967
  setIsOpen(true);
366
968
  }
367
969
  return;
368
970
  }
369
- const isTargetUsingKeyEvents = isEventTargetUsingKeyEvent(event_4);
971
+ const isTargetUsingKeyEvents = isEventTargetUsingKeyEvent(event_7);
370
972
  if (hasItemsRef.current && !isTargetUsingKeyEvents) {
371
- let isEditingCharacters = !ctrlKey && !metaKey && /^[A-Za-z0-9]$/.test(key);
372
- if (!isEditingCharacters && enteredCharactersRef.current) isEditingCharacters = key === " " || key === "Backspace";
973
+ let isEditingCharacters = !ctrlKey && !metaKey && /^[A-Za-z0-9]$/.test(key_0);
974
+ if (!isEditingCharacters && enteredCharactersRef.current) isEditingCharacters = key_0 === " " || key_0 === "Backspace";
373
975
  if (isEditingCharacters) {
374
976
  onEventHandled();
375
- if (key === "Backspace") enteredCharactersRef.current = enteredCharactersRef.current.slice(0, -1);
376
- else enteredCharactersRef.current = enteredCharactersRef.current + key;
977
+ if (key_0 === "Backspace") enteredCharactersRef.current = enteredCharactersRef.current.slice(0, -1);
978
+ else enteredCharactersRef.current = enteredCharactersRef.current + key_0;
377
979
  setActiveItem({
378
980
  dropdownElement,
379
- event: event_4,
981
+ event: event_7,
380
982
  isExactMatch: allowCreateRef.current,
381
- onActiveItem,
983
+ onActiveItem: handleActiveItem,
382
984
  text: enteredCharactersRef.current
383
985
  });
986
+ syncSubmenuDisclosure();
384
987
  if (clearEnteredCharactersTimerRef.current != null) clearTimeout(clearEnteredCharactersTimerRef.current);
385
988
  clearEnteredCharactersTimerRef.current = setTimeout(() => {
386
989
  enteredCharactersRef.current = "";
@@ -389,69 +992,117 @@ function Dropdown(t0) {
389
992
  return;
390
993
  }
391
994
  }
392
- if (key === "Enter" || key === " " && !inputElementRef.current) {
995
+ if (key_0 === "Enter" || key_0 === " " && !inputElementRef.current) {
393
996
  onEventHandled();
394
- handleSubmitItem(event_4);
997
+ handleSubmitItem(event_7);
395
998
  return;
396
999
  }
397
- if (key === "Escape" || isEventTargetingDropdown && key === " " && !hasItemsRef.current) {
398
- if (hasItemsRef.current || !isTargetUsingKeyEvents) closeDropdown();
1000
+ if (key_0 === "Escape" || isEventTargetingDropdown && key_0 === " " && !hasItemsRef.current) {
1001
+ if (hasItemsRef.current || !isTargetUsingKeyEvents) {
1002
+ focusTrigger();
1003
+ closeDropdown();
1004
+ }
399
1005
  return;
400
1006
  }
401
1007
  if (hasItemsRef.current) {
402
- if (key === "ArrowUp") {
1008
+ if (key_0 === "ArrowUp") {
403
1009
  onEventHandled();
404
1010
  if (altKey || metaKey) setActiveItem({
405
1011
  dropdownElement,
406
- event: event_4,
1012
+ event: event_7,
407
1013
  index: 0,
408
- onActiveItem
1014
+ onActiveItem: handleActiveItem
409
1015
  });
410
1016
  else setActiveItem({
411
1017
  dropdownElement,
412
- event: event_4,
1018
+ event: event_7,
413
1019
  indexAddend: -1,
414
- onActiveItem
1020
+ onActiveItem: handleActiveItem
415
1021
  });
1022
+ syncSubmenuDisclosure();
416
1023
  return;
417
1024
  }
418
- if (key === "ArrowDown") {
1025
+ if (key_0 === "ArrowDown") {
419
1026
  onEventHandled();
420
1027
  if (altKey || metaKey) setActiveItem({
421
1028
  dropdownElement,
422
- event: event_4,
1029
+ event: event_7,
423
1030
  index: -1,
424
- onActiveItem
1031
+ onActiveItem: handleActiveItem
425
1032
  });
426
1033
  else setActiveItem({
427
1034
  dropdownElement,
428
- event: event_4,
1035
+ event: event_7,
429
1036
  indexAddend: 1,
430
- onActiveItem
1037
+ onActiveItem: handleActiveItem
431
1038
  });
1039
+ syncSubmenuDisclosure();
432
1040
  return;
433
1041
  }
1042
+ if (!isTargetUsingKeyEvents) {
1043
+ if (key_0 === "ArrowRight") {
1044
+ const activeElement_0 = getActiveItemElement(dropdownElement);
1045
+ const submenu_2 = activeElement_0 ? getSubmenuOfItem(activeElement_0) : null;
1046
+ if (activeElement_0 && submenu_2) {
1047
+ onEventHandled();
1048
+ clearDisclosureTimer();
1049
+ expandItem(activeElement_0, handleToggleSubmenu);
1050
+ const firstItem_0 = getItemElements(dropdownElement, submenu_2)?.[0];
1051
+ if (firstItem_0) setActiveItem({
1052
+ dropdownElement,
1053
+ element: firstItem_0,
1054
+ event: event_7,
1055
+ onActiveItem: handleActiveItem
1056
+ });
1057
+ return;
1058
+ }
1059
+ if (menubar) {
1060
+ onEventHandled();
1061
+ menubar.moveOpen(dropdownElement, 1);
1062
+ }
1063
+ return;
1064
+ }
1065
+ if (key_0 === "ArrowLeft") {
1066
+ const activeElement_1 = getActiveItemElement(dropdownElement);
1067
+ const levelRoot = activeElement_1 ? getLevelRoot(activeElement_1) : null;
1068
+ if (levelRoot) {
1069
+ onEventHandled();
1070
+ clearDisclosureTimer();
1071
+ const parentItem = getParentItem(levelRoot);
1072
+ if (parentItem) collapseItem(parentItem, handleToggleSubmenu);
1073
+ return;
1074
+ }
1075
+ if (menubar) {
1076
+ onEventHandled();
1077
+ menubar.moveOpen(dropdownElement, -1);
1078
+ }
1079
+ return;
1080
+ }
1081
+ }
434
1082
  }
435
1083
  };
436
- $[29] = dropdownElement;
437
- $[30] = handleSubmitItem;
438
- $[31] = onActiveItem;
439
- $[32] = t15;
440
- } else t15 = $[32];
441
- const handleKeyDown = t15;
442
- let t16;
443
- if ($[33] !== handleKeyDown) {
444
- t16 = {
1084
+ $[68] = dropdownElement;
1085
+ $[69] = focusTrigger;
1086
+ $[70] = handleActiveItem;
1087
+ $[71] = handleSubmitItem;
1088
+ $[72] = menubar;
1089
+ $[73] = syncSubmenuDisclosure;
1090
+ $[74] = t34;
1091
+ } else t34 = $[74];
1092
+ const handleKeyDown = t34;
1093
+ let t35;
1094
+ if ($[75] !== handleKeyDown) {
1095
+ t35 = {
445
1096
  ignoreUsedKeyboardEvents: false,
446
1097
  onKeyDown: handleKeyDown
447
1098
  };
448
- $[33] = handleKeyDown;
449
- $[34] = t16;
450
- } else t16 = $[34];
451
- useKeyboardEvents(t16);
452
- let t17;
453
- if ($[35] !== isOpenOnMount || $[36] !== onActiveItem) {
454
- t17 = (ref) => {
1099
+ $[75] = handleKeyDown;
1100
+ $[76] = t35;
1101
+ } else t35 = $[76];
1102
+ useKeyboardEvents(t35);
1103
+ let t36;
1104
+ if ($[77] !== handleActiveItem || $[78] !== isOpenOnMount) {
1105
+ t36 = (ref) => {
455
1106
  setDropdownElement(ref);
456
1107
  if (!ref) return;
457
1108
  const { ownerDocument } = ref;
@@ -461,13 +1112,13 @@ function Dropdown(t0) {
461
1112
  else inputElement = ref.firstElementChild.querySelector(TEXT_INPUT_SELECTOR);
462
1113
  inputElementRef.current = inputElement;
463
1114
  }
464
- const handleGlobalMouseDown = (t18) => {
465
- const { target } = t18;
466
- const eventTarget_3 = target;
1115
+ const handleGlobalMouseDown = (t37) => {
1116
+ const { target: target_1 } = t37;
1117
+ const eventTarget_3 = target_1;
467
1118
  if (!ref.contains(eventTarget_3)) closeDropdown();
468
1119
  };
469
- const handleGlobalMouseUp = (t19) => {
470
- const { target: target_0 } = t19;
1120
+ const handleGlobalMouseUp = (t38) => {
1121
+ const { target: target_2 } = t38;
471
1122
  if (!isOpenRef.current || closingTimerRef.current != null) return;
472
1123
  if (isOpeningRef.current) {
473
1124
  setIsOpening(false);
@@ -477,13 +1128,13 @@ function Dropdown(t0) {
477
1128
  }
478
1129
  return;
479
1130
  }
480
- const eventTarget_4 = target_0;
1131
+ const eventTarget_4 = target_2;
481
1132
  if (!ref.contains(eventTarget_4)) closeDropdown();
482
1133
  };
483
- const handleGlobalFocusIn = (t20) => {
484
- const { target: target_1 } = t20;
1134
+ const handleGlobalFocusIn = (t39) => {
1135
+ const { target: target_3 } = t39;
485
1136
  if (!isOpenRef.current) return;
486
- const eventTarget_5 = target_1;
1137
+ const eventTarget_5 = target_3;
487
1138
  if (ref.contains(eventTarget_5) || eventTarget_5.contains(ref)) return;
488
1139
  closeDropdown();
489
1140
  };
@@ -496,17 +1147,17 @@ function Dropdown(t0) {
496
1147
  ownerDocument.addEventListener("mouseup", handleGlobalMouseUp);
497
1148
  }
498
1149
  if (isOpenOnMount) ref.focus();
499
- const handleInput = (event_5) => {
1150
+ const handleInput = (event_8) => {
500
1151
  if (!isOpenRef.current) setIsOpen(true);
501
- const input = event_5.target;
1152
+ const input = event_8.target;
502
1153
  const isDeleting = enteredCharactersRef.current.length > input.value.length;
503
1154
  enteredCharactersRef.current = input.value;
504
1155
  if (isDeleting && input.value.length && getActiveItemElement(ref)) return;
505
1156
  setActiveItem({
506
1157
  dropdownElement: ref,
507
- event: event_5,
1158
+ event: event_8,
508
1159
  isExactMatch: allowCreateRef.current,
509
- onActiveItem,
1160
+ onActiveItem: handleActiveItem,
510
1161
  text: enteredCharactersRef.current
511
1162
  });
512
1163
  };
@@ -523,50 +1174,51 @@ function Dropdown(t0) {
523
1174
  if (inputElement) inputElement.removeEventListener("input", handleInput);
524
1175
  };
525
1176
  };
526
- $[35] = isOpenOnMount;
527
- $[36] = onActiveItem;
528
- $[37] = t17;
529
- } else t17 = $[37];
530
- const handleRef = t17;
1177
+ $[77] = handleActiveItem;
1178
+ $[78] = isOpenOnMount;
1179
+ $[79] = t36;
1180
+ } else t36 = $[79];
1181
+ const handleRef = t36;
1182
+ const handleBodyRef = _temp;
531
1183
  if (!isValidElement(trigger)) if (isSearchable) {
532
- const t18 = value ?? "";
533
- let t19;
534
- if ($[38] === Symbol.for("react.memo_cache_sentinel")) {
535
- t19 = () => setIsOpen(true);
536
- $[38] = t19;
537
- } else t19 = $[38];
538
- let t20;
539
- if ($[39] !== bodyId || $[40] !== disabled || $[41] !== isOpen || $[42] !== name || $[43] !== placeholder || $[44] !== popupRole || $[45] !== t18 || $[46] !== tabIndex) {
540
- t20 = /* @__PURE__ */ jsx("input", {
1184
+ const t37 = value ?? "";
1185
+ let t38;
1186
+ if ($[80] === Symbol.for("react.memo_cache_sentinel")) {
1187
+ t38 = () => setIsOpen(true);
1188
+ $[80] = t38;
1189
+ } else t38 = $[80];
1190
+ let t39;
1191
+ if ($[81] !== bodyId || $[82] !== disabled || $[83] !== isOpen || $[84] !== name || $[85] !== placeholder || $[86] !== popupRole || $[87] !== t37 || $[88] !== tabIndex) {
1192
+ t39 = /* @__PURE__ */ jsx("input", {
541
1193
  "aria-controls": bodyId,
542
1194
  "aria-expanded": isOpen,
543
1195
  "aria-haspopup": popupRole,
544
1196
  autoComplete: "off",
545
1197
  className: "uktdropdown-trigger",
546
- defaultValue: t18,
1198
+ defaultValue: t37,
547
1199
  disabled,
548
1200
  name,
549
- onFocus: t19,
1201
+ onFocus: t38,
550
1202
  placeholder,
551
1203
  ref: inputElementRef,
552
1204
  tabIndex,
553
1205
  type: "text"
554
1206
  });
555
- $[39] = bodyId;
556
- $[40] = disabled;
557
- $[41] = isOpen;
558
- $[42] = name;
559
- $[43] = placeholder;
560
- $[44] = popupRole;
561
- $[45] = t18;
562
- $[46] = tabIndex;
563
- $[47] = t20;
564
- } else t20 = $[47];
565
- trigger = t20;
1207
+ $[81] = bodyId;
1208
+ $[82] = disabled;
1209
+ $[83] = isOpen;
1210
+ $[84] = name;
1211
+ $[85] = placeholder;
1212
+ $[86] = popupRole;
1213
+ $[87] = t37;
1214
+ $[88] = tabIndex;
1215
+ $[89] = t39;
1216
+ } else t39 = $[89];
1217
+ trigger = t39;
566
1218
  } else {
567
- let t18;
568
- if ($[48] !== bodyId || $[49] !== isOpen || $[50] !== popupRole || $[51] !== trigger) {
569
- t18 = /* @__PURE__ */ jsx("button", {
1219
+ let t37;
1220
+ if ($[90] !== bodyId || $[91] !== isOpen || $[92] !== popupRole || $[93] !== trigger) {
1221
+ t37 = /* @__PURE__ */ jsx("button", {
570
1222
  "aria-controls": bodyId,
571
1223
  "aria-expanded": isOpen,
572
1224
  "aria-haspopup": popupRole,
@@ -575,127 +1227,107 @@ function Dropdown(t0) {
575
1227
  type: "button",
576
1228
  children: trigger
577
1229
  });
578
- $[48] = bodyId;
579
- $[49] = isOpen;
580
- $[50] = popupRole;
581
- $[51] = trigger;
582
- $[52] = t18;
583
- } else t18 = $[52];
584
- trigger = t18;
1230
+ $[90] = bodyId;
1231
+ $[91] = isOpen;
1232
+ $[92] = popupRole;
1233
+ $[93] = trigger;
1234
+ $[94] = t37;
1235
+ } else t37 = $[94];
1236
+ trigger = t37;
585
1237
  }
586
1238
  else {
587
1239
  const triggerProps = trigger.props;
588
- const t18 = trigger;
589
- const t19 = triggerProps["aria-controls"] ?? bodyId;
590
- const t20 = triggerProps["aria-expanded"] ?? isOpen;
591
- const t21 = triggerProps["aria-haspopup"] ?? popupRole;
592
- let t22;
593
- if ($[53] !== t18 || $[54] !== t19 || $[55] !== t20 || $[56] !== t21) {
594
- t22 = cloneElement(t18, {
595
- "aria-controls": t19,
596
- "aria-expanded": t20,
597
- "aria-haspopup": t21
1240
+ const t37 = trigger;
1241
+ const t38 = triggerProps["aria-controls"] ?? bodyId;
1242
+ const t39 = triggerProps["aria-expanded"] ?? isOpen;
1243
+ const t40 = triggerProps["aria-haspopup"] ?? popupRole;
1244
+ let t41;
1245
+ if ($[95] !== t37 || $[96] !== t38 || $[97] !== t39 || $[98] !== t40) {
1246
+ t41 = cloneElement(t37, {
1247
+ "aria-controls": t38,
1248
+ "aria-expanded": t39,
1249
+ "aria-haspopup": t40
598
1250
  });
599
- $[53] = t18;
600
- $[54] = t19;
601
- $[55] = t20;
602
- $[56] = t21;
603
- $[57] = t22;
604
- } else t22 = $[57];
605
- trigger = t22;
1251
+ $[95] = t37;
1252
+ $[96] = t38;
1253
+ $[97] = t39;
1254
+ $[98] = t40;
1255
+ $[99] = t41;
1256
+ } else t41 = $[99];
1257
+ trigger = t41;
606
1258
  }
607
1259
  if (label != null) {
608
- let t18;
609
- if ($[58] !== label) {
610
- t18 = /* @__PURE__ */ jsx("div", {
1260
+ let t37;
1261
+ if ($[100] !== label) {
1262
+ t37 = /* @__PURE__ */ jsx("div", {
611
1263
  className: "uktdropdown-label-text",
612
1264
  children: label
613
1265
  });
614
- $[58] = label;
615
- $[59] = t18;
616
- } else t18 = $[59];
617
- let t19;
618
- if ($[60] !== t18 || $[61] !== trigger) {
619
- t19 = /* @__PURE__ */ jsxs("label", {
1266
+ $[100] = label;
1267
+ $[101] = t37;
1268
+ } else t37 = $[101];
1269
+ let t38;
1270
+ if ($[102] !== t37 || $[103] !== trigger) {
1271
+ t38 = /* @__PURE__ */ jsxs("label", {
620
1272
  className: "uktdropdown-label",
621
- children: [t18, trigger]
1273
+ children: [t37, trigger]
622
1274
  });
623
- $[60] = t18;
624
- $[61] = trigger;
625
- $[62] = t19;
626
- } else t19 = $[62];
627
- trigger = t19;
1275
+ $[102] = t37;
1276
+ $[103] = trigger;
1277
+ $[104] = t38;
1278
+ } else t38 = $[104];
1279
+ trigger = t38;
628
1280
  }
629
- let t18;
630
- if ($[63] !== minHeightBody) {
631
- t18 = minHeightBody != null && minHeightBody > 0 ? { "--uktdd-body-min-height": `${minHeightBody}px` } : null;
632
- $[63] = minHeightBody;
633
- $[64] = t18;
634
- } else t18 = $[64];
635
- let t19;
636
- if ($[65] !== minWidthBody) {
637
- t19 = minWidthBody != null && minWidthBody > 0 ? { "--uktdd-body-min-width": `${minWidthBody}px` } : null;
638
- $[65] = minWidthBody;
639
- $[66] = t19;
640
- } else t19 = $[66];
641
- let t20;
642
- if ($[67] !== styleFromProps || $[68] !== t18 || $[69] !== t19) {
643
- t20 = {
644
- ...styleFromProps,
645
- ...t18,
646
- ...t19
647
- };
648
- $[67] = styleFromProps;
649
- $[68] = t18;
650
- $[69] = t19;
651
- $[70] = t20;
652
- } else t20 = $[70];
653
- const style = t20;
654
- let t21;
655
- if ($[71] === Symbol.for("react.memo_cache_sentinel")) {
656
- t21 = /* @__PURE__ */ jsx("style", {
1281
+ let t37;
1282
+ if ($[105] === Symbol.for("react.memo_cache_sentinel")) {
1283
+ t37 = /* @__PURE__ */ jsx("style", {
657
1284
  href: "@acusti/dropdown/Dropdown",
658
1285
  precedence: "medium",
659
1286
  children: Dropdown_default
660
1287
  });
661
- $[71] = t21;
662
- } else t21 = $[71];
663
- let t22;
664
- if ($[72] !== className || $[73] !== disabled || $[74] !== isOpen || $[75] !== isSearchable) {
665
- t22 = clsx("uktdropdown", className, {
1288
+ $[105] = t37;
1289
+ } else t37 = $[105];
1290
+ let t38;
1291
+ if ($[106] !== className || $[107] !== disabled || $[108] !== isOpen || $[109] !== isSearchable) {
1292
+ t38 = clsx("uktdropdown", className, {
666
1293
  disabled,
667
1294
  "is-open": isOpen,
668
1295
  "is-searchable": isSearchable
669
1296
  });
670
- $[72] = className;
671
- $[73] = disabled;
672
- $[74] = isOpen;
673
- $[75] = isSearchable;
674
- $[76] = t22;
675
- } else t22 = $[76];
676
- let t23;
677
- if ($[77] !== bodyId || $[78] !== children || $[79] !== childrenCount || $[80] !== hasItems || $[81] !== isOpen || $[82] !== popupRole) {
678
- t23 = isOpen ? /* @__PURE__ */ jsx("div", {
1297
+ $[106] = className;
1298
+ $[107] = disabled;
1299
+ $[108] = isOpen;
1300
+ $[109] = isSearchable;
1301
+ $[110] = t38;
1302
+ } else t38 = $[110];
1303
+ let t39;
1304
+ if ($[111] !== bodyId || $[112] !== children || $[113] !== childrenCount || $[114] !== hasItems || $[115] !== isOpen || $[116] !== popupRole) {
1305
+ t39 = isOpen ? /* @__PURE__ */ jsx("div", {
679
1306
  className: clsx("uktdropdown-body", { "has-items": hasItems }),
680
1307
  id: bodyId,
1308
+ popover: "manual",
1309
+ ref: handleBodyRef,
681
1310
  role: popupRole,
682
1311
  children: /* @__PURE__ */ jsx("div", {
683
1312
  className: "uktdropdown-content",
684
- children: childrenCount > 1 ? children[1] : children
1313
+ children: /* @__PURE__ */ jsx(DropdownContext.Provider, {
1314
+ value: hasItems ? dropdownContextValue : null,
1315
+ children: childrenCount > 1 ? children[1] : children
1316
+ })
685
1317
  })
686
1318
  }) : null;
687
- $[77] = bodyId;
688
- $[78] = children;
689
- $[79] = childrenCount;
690
- $[80] = hasItems;
691
- $[81] = isOpen;
692
- $[82] = popupRole;
693
- $[83] = t23;
694
- } else t23 = $[83];
695
- let t24;
696
- if ($[84] !== handleMouseDown || $[85] !== handleMouseOut || $[86] !== handleMouseOver || $[87] !== handleMouseUp || $[88] !== handleRef || $[89] !== onClick || $[90] !== style || $[91] !== t22 || $[92] !== t23 || $[93] !== trigger) {
697
- t24 = /* @__PURE__ */ jsxs(Fragment, { children: [t21, /* @__PURE__ */ jsxs("div", {
698
- className: t22,
1319
+ $[111] = bodyId;
1320
+ $[112] = children;
1321
+ $[113] = childrenCount;
1322
+ $[114] = hasItems;
1323
+ $[115] = isOpen;
1324
+ $[116] = popupRole;
1325
+ $[117] = t39;
1326
+ } else t39 = $[117];
1327
+ let t40;
1328
+ if ($[118] !== handleMouseDown || $[119] !== handleMouseMove || $[120] !== handleMouseOut || $[121] !== handleMouseOver || $[122] !== handleMouseUp || $[123] !== handleRef || $[124] !== onClick || $[125] !== styleFromProps || $[126] !== t38 || $[127] !== t39 || $[128] !== trigger) {
1329
+ t40 = /* @__PURE__ */ jsxs(Fragment, { children: [t37, /* @__PURE__ */ jsxs("div", {
1330
+ className: t38,
699
1331
  onClick,
700
1332
  onMouseDown: handleMouseDown,
701
1333
  onMouseMove: handleMouseMove,
@@ -703,24 +1335,129 @@ function Dropdown(t0) {
703
1335
  onMouseOver: handleMouseOver,
704
1336
  onMouseUp: handleMouseUp,
705
1337
  ref: handleRef,
706
- style,
707
- children: [trigger, t23]
1338
+ style: styleFromProps,
1339
+ children: [trigger, t39]
708
1340
  })] });
709
- $[84] = handleMouseDown;
710
- $[85] = handleMouseOut;
711
- $[86] = handleMouseOver;
712
- $[87] = handleMouseUp;
713
- $[88] = handleRef;
714
- $[89] = onClick;
715
- $[90] = style;
716
- $[91] = t22;
717
- $[92] = t23;
718
- $[93] = trigger;
719
- $[94] = t24;
720
- } else t24 = $[94];
721
- return t24;
1341
+ $[118] = handleMouseDown;
1342
+ $[119] = handleMouseMove;
1343
+ $[120] = handleMouseOut;
1344
+ $[121] = handleMouseOver;
1345
+ $[122] = handleMouseUp;
1346
+ $[123] = handleRef;
1347
+ $[124] = onClick;
1348
+ $[125] = styleFromProps;
1349
+ $[126] = t38;
1350
+ $[127] = t39;
1351
+ $[128] = trigger;
1352
+ $[129] = t40;
1353
+ } else t40 = $[129];
1354
+ return t40;
1355
+ }
1356
+ function _temp(ref_0) {
1357
+ if (!ref_0) return;
1358
+ annotateParentItems(ref_0);
1359
+ ref_0.showPopover();
1360
+ }
1361
+ var INERT_SUBMENU_PROPS = [
1362
+ "allowCreate",
1363
+ "allowEmpty",
1364
+ "isOpenOnMount",
1365
+ "isSearchable",
1366
+ "keepOpenOnSubmit",
1367
+ "name",
1368
+ "placeholder",
1369
+ "tabIndex",
1370
+ "value"
1371
+ ];
1372
+ function SubmenuDropdown(props) {
1373
+ const $ = c(17);
1374
+ const { children, className, disabled, label, onActiveItem, onClose, onOpen, onSubmitItem, parentDropdown, style } = props;
1375
+ const itemRef = useRef(null);
1376
+ let t0;
1377
+ let t1;
1378
+ if ($[0] !== onActiveItem || $[1] !== onClose || $[2] !== onOpen || $[3] !== onSubmitItem || $[4] !== parentDropdown) {
1379
+ t0 = () => {
1380
+ const element = itemRef.current;
1381
+ if (!element) return;
1382
+ return parentDropdown.registerSubmenu({
1383
+ element,
1384
+ onActiveItem,
1385
+ onClose,
1386
+ onOpen,
1387
+ onSubmitItem
1388
+ });
1389
+ };
1390
+ t1 = [
1391
+ onActiveItem,
1392
+ onClose,
1393
+ onOpen,
1394
+ onSubmitItem,
1395
+ parentDropdown
1396
+ ];
1397
+ $[0] = onActiveItem;
1398
+ $[1] = onClose;
1399
+ $[2] = onOpen;
1400
+ $[3] = onSubmitItem;
1401
+ $[4] = parentDropdown;
1402
+ $[5] = t0;
1403
+ $[6] = t1;
1404
+ } else {
1405
+ t0 = $[5];
1406
+ t1 = $[6];
1407
+ }
1408
+ useEffect(t0, t1);
1409
+ const warnedRef = useRef(false);
1410
+ let t2;
1411
+ if ($[7] !== props) {
1412
+ t2 = () => {
1413
+ if (warnedRef.current) return;
1414
+ const inertProps = INERT_SUBMENU_PROPS.filter((propName) => props[propName] !== void 0);
1415
+ if (!inertProps.length) return;
1416
+ warnedRef.current = true;
1417
+ console.error(`@acusti/dropdown: ${inertProps.join(", ")} only apply to a top-level Dropdown and are ignored on a nested (submenu) Dropdown.`);
1418
+ };
1419
+ $[7] = props;
1420
+ $[8] = t2;
1421
+ } else t2 = $[8];
1422
+ useEffect(t2);
1423
+ const childrenCount = Children.count(children);
1424
+ let labelContent = label;
1425
+ let body = children;
1426
+ if (childrenCount > 1) {
1427
+ labelContent = children[0];
1428
+ body = children[1];
1429
+ }
1430
+ let t3;
1431
+ if ($[9] !== body) {
1432
+ t3 = isValidElement(body) ? cloneElement(body, { "data-ukt-submenu": "" }) : /* @__PURE__ */ jsx("div", {
1433
+ "data-ukt-submenu": "",
1434
+ children: body
1435
+ });
1436
+ $[9] = body;
1437
+ $[10] = t3;
1438
+ } else t3 = $[10];
1439
+ const submenu = t3;
1440
+ const t4 = disabled || void 0;
1441
+ let t5;
1442
+ if ($[11] !== className || $[12] !== labelContent || $[13] !== style || $[14] !== submenu || $[15] !== t4) {
1443
+ t5 = /* @__PURE__ */ jsxs("li", {
1444
+ "aria-disabled": t4,
1445
+ className,
1446
+ "data-ukt-item": "",
1447
+ ref: itemRef,
1448
+ style,
1449
+ children: [labelContent, submenu]
1450
+ });
1451
+ $[11] = className;
1452
+ $[12] = labelContent;
1453
+ $[13] = style;
1454
+ $[14] = submenu;
1455
+ $[15] = t4;
1456
+ $[16] = t5;
1457
+ } else t5 = $[16];
1458
+ return t5;
722
1459
  }
723
1460
  //#endregion
724
- export { Dropdown as default };
1461
+ export { Menubar, Dropdown as default };
725
1462
 
726
1463
  //# sourceMappingURL=Dropdown.js.map