@acusti/dropdown 0.56.0 → 1.0.0-alpha.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/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,21 +207,192 @@ 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;
107
393
  const childrenCount = Children.count(children);
108
394
  if (childrenCount !== 1 && childrenCount !== 2) {
109
- if (childrenCount === 0) throw new Error(CHILDREN_ERROR + " Received no children.");
395
+ if (childrenCount === 0) throw new Error("@acusti/dropdown requires either 1 child (the dropdown body) or 2 children: the dropdown trigger and the dropdown body. Received no children.");
110
396
  console.error(`${CHILDREN_ERROR} Received ${childrenCount} children.`);
111
397
  }
112
398
  let trigger;
@@ -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,38 +490,308 @@ 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
- if (!element && !allowCreateRef.current) {
223
- if (!allowEmptyRef.current) return;
224
- if (inputElementRef.current?.value) return;
790
+ if (!element) {
791
+ if (!inputElementRef.current) return;
792
+ if (inputElementRef.current.value) {
793
+ if (!allowCreateRef.current) return;
794
+ } else if (!allowEmptyRef.current) return;
225
795
  }
226
796
  let itemLabel = element?.innerText ?? "";
227
797
  if (inputElementRef.current) {
@@ -232,7 +802,7 @@ function Dropdown(t0) {
232
802
  const nextValue = element?.dataset.uktValue ?? itemLabel;
233
803
  if (valueRef.current && valueRef.current === nextValue) return;
234
804
  if (element) {
235
- const eventTarget = event.target;
805
+ const eventTarget = event_1.target;
236
806
  if (element.matches(CLICKABLE_SELECTOR)) {
237
807
  if (element !== eventTarget && !element.contains(eventTarget)) element.click();
238
808
  } else {
@@ -243,142 +813,177 @@ function Dropdown(t0) {
243
813
  }
244
814
  }
245
815
  }
246
- onSubmitItemRef.current?.({
816
+ const payload_1 = {
247
817
  element,
248
- event,
818
+ event: event_1,
249
819
  label: itemLabel,
820
+ path: getItemPath(element),
250
821
  value: nextValue
251
- });
822
+ };
823
+ onSubmitItemRef.current?.(payload_1);
824
+ dispatchToSubmenus("onSubmitItem", payload_1);
252
825
  };
253
- $[16] = dropdownElement;
254
- $[17] = t9;
255
- } else t9 = $[17];
256
- const handleSubmitItem = t9;
257
- let t10;
258
- if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
259
- t10 = (t11) => {
260
- 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;
261
835
  currentInputMethodRef.current = "mouse";
836
+ trackSafeArea(event_2);
262
837
  const initialPosition = mouseDownPositionRef.current;
263
838
  if (!initialPosition) return;
264
839
  if (Math.abs(initialPosition.clientX - clientX) < 12 && Math.abs(initialPosition.clientY - clientY) < 12) return;
265
840
  setIsOpening(false);
266
841
  };
267
- $[18] = t10;
268
- } else t10 = $[18];
269
- const handleMouseMove = t10;
270
- let t11;
271
- if ($[19] !== dropdownElement || $[20] !== onActiveItem) {
272
- 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) => {
273
849
  if (!hasItemsRef.current) return;
274
850
  if (currentInputMethodRef.current !== "mouse") return;
275
851
  if (!dropdownElement) return;
276
- const itemElements = getItemElements(dropdownElement);
277
- if (!itemElements) return;
278
- const eventTarget_0 = event_0.target;
279
- const element_0 = eventTarget_0.closest(ITEM_SELECTOR) ?? eventTarget_0;
280
- for (const itemElement of itemElements) if (itemElement === element_0) {
281
- setActiveItem({
282
- dropdownElement,
283
- element: element_0,
284
- event: event_0,
285
- onActiveItem
286
- });
287
- return;
288
- }
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();
289
866
  };
290
- $[19] = dropdownElement;
291
- $[20] = onActiveItem;
292
- $[21] = t11;
293
- } else t11 = $[21];
294
- const handleMouseOver = t11;
295
- let t12;
296
- if ($[22] !== dropdownElement) {
297
- 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) => {
298
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;
299
884
  const activeItem = getActiveItemElement(dropdownElement);
300
885
  if (!activeItem) return;
301
- const eventRelatedTarget = event_1.relatedTarget;
302
- 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;
303
888
  delete activeItem.dataset.uktActive;
889
+ syncSubmenuDisclosure();
304
890
  };
305
- $[22] = dropdownElement;
306
- $[23] = t12;
307
- } else t12 = $[23];
308
- const handleMouseOut = t12;
309
- let t13;
310
- if ($[24] !== onMouseDown) {
311
- t13 = (event_2) => {
312
- 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);
313
900
  if (isOpenRef.current) return;
314
901
  setIsOpen(true);
315
902
  setIsOpening(true);
316
903
  mouseDownPositionRef.current = {
317
- clientX: event_2.clientX,
318
- clientY: event_2.clientY
904
+ clientX: event_5.clientX,
905
+ clientY: event_5.clientY
319
906
  };
320
907
  isOpeningTimerRef.current = setTimeout(() => {
321
908
  setIsOpening(false);
322
909
  isOpeningTimerRef.current = null;
323
910
  }, 1e3);
324
911
  };
325
- $[24] = onMouseDown;
326
- $[25] = t13;
327
- } else t13 = $[25];
328
- const handleMouseDown = t13;
329
- let t14;
330
- if ($[26] !== handleSubmitItem || $[27] !== onMouseUp) {
331
- t14 = (event_3) => {
332
- 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);
333
920
  if (isOpeningRef.current || !isOpenRef.current || closingTimerRef.current != null) return;
334
- const eventTarget_1 = event_3.target;
335
- 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)) {
336
926
  if (!isOpeningRef.current && inputElementRef.current !== eventTarget_1.ownerDocument.activeElement) closeDropdown();
337
927
  return;
338
928
  }
339
929
  if (!hasItemsRef.current) return;
340
- 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);
341
941
  };
342
- $[26] = handleSubmitItem;
343
- $[27] = onMouseUp;
344
- $[28] = t14;
345
- } else t14 = $[28];
346
- const handleMouseUp = t14;
347
- let t15;
348
- if ($[29] !== dropdownElement || $[30] !== handleSubmitItem || $[31] !== onActiveItem) {
349
- t15 = (event_4) => {
350
- const { altKey, ctrlKey, key, metaKey } = event_4;
351
- 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;
352
954
  if (!dropdownElement) return;
353
955
  const onEventHandled = () => {
354
- event_4.stopPropagation();
355
- event_4.preventDefault();
956
+ event_7.stopPropagation();
957
+ event_7.preventDefault();
356
958
  currentInputMethodRef.current = "keyboard";
357
959
  };
358
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;
359
963
  if (!isOpenRef.current) {
360
964
  if (!isEventTargetingDropdown) return;
361
- 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")) {
362
966
  onEventHandled();
363
967
  setIsOpen(true);
364
968
  }
365
969
  return;
366
970
  }
367
- const isTargetUsingKeyEvents = isEventTargetUsingKeyEvent(event_4);
971
+ const isTargetUsingKeyEvents = isEventTargetUsingKeyEvent(event_7);
368
972
  if (hasItemsRef.current && !isTargetUsingKeyEvents) {
369
- let isEditingCharacters = !ctrlKey && !metaKey && /^[A-Za-z0-9]$/.test(key);
370
- 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";
371
975
  if (isEditingCharacters) {
372
976
  onEventHandled();
373
- if (key === "Backspace") enteredCharactersRef.current = enteredCharactersRef.current.slice(0, -1);
374
- 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;
375
979
  setActiveItem({
376
980
  dropdownElement,
377
- event: event_4,
981
+ event: event_7,
378
982
  isExactMatch: allowCreateRef.current,
379
- onActiveItem,
983
+ onActiveItem: handleActiveItem,
380
984
  text: enteredCharactersRef.current
381
985
  });
986
+ syncSubmenuDisclosure();
382
987
  if (clearEnteredCharactersTimerRef.current != null) clearTimeout(clearEnteredCharactersTimerRef.current);
383
988
  clearEnteredCharactersTimerRef.current = setTimeout(() => {
384
989
  enteredCharactersRef.current = "";
@@ -387,69 +992,117 @@ function Dropdown(t0) {
387
992
  return;
388
993
  }
389
994
  }
390
- if (key === "Enter" || key === " " && !inputElementRef.current) {
995
+ if (key_0 === "Enter" || key_0 === " " && !inputElementRef.current) {
391
996
  onEventHandled();
392
- handleSubmitItem(event_4);
997
+ handleSubmitItem(event_7);
393
998
  return;
394
999
  }
395
- if (key === "Escape" || isEventTargetingDropdown && key === " " && !hasItemsRef.current) {
396
- 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
+ }
397
1005
  return;
398
1006
  }
399
1007
  if (hasItemsRef.current) {
400
- if (key === "ArrowUp") {
1008
+ if (key_0 === "ArrowUp") {
401
1009
  onEventHandled();
402
1010
  if (altKey || metaKey) setActiveItem({
403
1011
  dropdownElement,
404
- event: event_4,
1012
+ event: event_7,
405
1013
  index: 0,
406
- onActiveItem
1014
+ onActiveItem: handleActiveItem
407
1015
  });
408
1016
  else setActiveItem({
409
1017
  dropdownElement,
410
- event: event_4,
1018
+ event: event_7,
411
1019
  indexAddend: -1,
412
- onActiveItem
1020
+ onActiveItem: handleActiveItem
413
1021
  });
1022
+ syncSubmenuDisclosure();
414
1023
  return;
415
1024
  }
416
- if (key === "ArrowDown") {
1025
+ if (key_0 === "ArrowDown") {
417
1026
  onEventHandled();
418
1027
  if (altKey || metaKey) setActiveItem({
419
1028
  dropdownElement,
420
- event: event_4,
1029
+ event: event_7,
421
1030
  index: -1,
422
- onActiveItem
1031
+ onActiveItem: handleActiveItem
423
1032
  });
424
1033
  else setActiveItem({
425
1034
  dropdownElement,
426
- event: event_4,
1035
+ event: event_7,
427
1036
  indexAddend: 1,
428
- onActiveItem
1037
+ onActiveItem: handleActiveItem
429
1038
  });
1039
+ syncSubmenuDisclosure();
430
1040
  return;
431
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
+ }
432
1082
  }
433
1083
  };
434
- $[29] = dropdownElement;
435
- $[30] = handleSubmitItem;
436
- $[31] = onActiveItem;
437
- $[32] = t15;
438
- } else t15 = $[32];
439
- const handleKeyDown = t15;
440
- let t16;
441
- if ($[33] !== handleKeyDown) {
442
- 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 = {
443
1096
  ignoreUsedKeyboardEvents: false,
444
1097
  onKeyDown: handleKeyDown
445
1098
  };
446
- $[33] = handleKeyDown;
447
- $[34] = t16;
448
- } else t16 = $[34];
449
- useKeyboardEvents(t16);
450
- let t17;
451
- if ($[35] !== isOpenOnMount || $[36] !== onActiveItem) {
452
- 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) => {
453
1106
  setDropdownElement(ref);
454
1107
  if (!ref) return;
455
1108
  const { ownerDocument } = ref;
@@ -459,13 +1112,13 @@ function Dropdown(t0) {
459
1112
  else inputElement = ref.firstElementChild.querySelector(TEXT_INPUT_SELECTOR);
460
1113
  inputElementRef.current = inputElement;
461
1114
  }
462
- const handleGlobalMouseDown = (t18) => {
463
- const { target } = t18;
464
- const eventTarget_3 = target;
1115
+ const handleGlobalMouseDown = (t37) => {
1116
+ const { target: target_1 } = t37;
1117
+ const eventTarget_3 = target_1;
465
1118
  if (!ref.contains(eventTarget_3)) closeDropdown();
466
1119
  };
467
- const handleGlobalMouseUp = (t19) => {
468
- const { target: target_0 } = t19;
1120
+ const handleGlobalMouseUp = (t38) => {
1121
+ const { target: target_2 } = t38;
469
1122
  if (!isOpenRef.current || closingTimerRef.current != null) return;
470
1123
  if (isOpeningRef.current) {
471
1124
  setIsOpening(false);
@@ -475,13 +1128,13 @@ function Dropdown(t0) {
475
1128
  }
476
1129
  return;
477
1130
  }
478
- const eventTarget_4 = target_0;
1131
+ const eventTarget_4 = target_2;
479
1132
  if (!ref.contains(eventTarget_4)) closeDropdown();
480
1133
  };
481
- const handleGlobalFocusIn = (t20) => {
482
- const { target: target_1 } = t20;
1134
+ const handleGlobalFocusIn = (t39) => {
1135
+ const { target: target_3 } = t39;
483
1136
  if (!isOpenRef.current) return;
484
- const eventTarget_5 = target_1;
1137
+ const eventTarget_5 = target_3;
485
1138
  if (ref.contains(eventTarget_5) || eventTarget_5.contains(ref)) return;
486
1139
  closeDropdown();
487
1140
  };
@@ -494,17 +1147,17 @@ function Dropdown(t0) {
494
1147
  ownerDocument.addEventListener("mouseup", handleGlobalMouseUp);
495
1148
  }
496
1149
  if (isOpenOnMount) ref.focus();
497
- const handleInput = (event_5) => {
1150
+ const handleInput = (event_8) => {
498
1151
  if (!isOpenRef.current) setIsOpen(true);
499
- const input = event_5.target;
1152
+ const input = event_8.target;
500
1153
  const isDeleting = enteredCharactersRef.current.length > input.value.length;
501
1154
  enteredCharactersRef.current = input.value;
502
1155
  if (isDeleting && input.value.length && getActiveItemElement(ref)) return;
503
1156
  setActiveItem({
504
1157
  dropdownElement: ref,
505
- event: event_5,
1158
+ event: event_8,
506
1159
  isExactMatch: allowCreateRef.current,
507
- onActiveItem,
1160
+ onActiveItem: handleActiveItem,
508
1161
  text: enteredCharactersRef.current
509
1162
  });
510
1163
  };
@@ -521,50 +1174,51 @@ function Dropdown(t0) {
521
1174
  if (inputElement) inputElement.removeEventListener("input", handleInput);
522
1175
  };
523
1176
  };
524
- $[35] = isOpenOnMount;
525
- $[36] = onActiveItem;
526
- $[37] = t17;
527
- } else t17 = $[37];
528
- const handleRef = t17;
1177
+ $[77] = handleActiveItem;
1178
+ $[78] = isOpenOnMount;
1179
+ $[79] = t36;
1180
+ } else t36 = $[79];
1181
+ const handleRef = t36;
1182
+ const handleBodyRef = _temp;
529
1183
  if (!isValidElement(trigger)) if (isSearchable) {
530
- const t18 = value ?? "";
531
- let t19;
532
- if ($[38] === Symbol.for("react.memo_cache_sentinel")) {
533
- t19 = () => setIsOpen(true);
534
- $[38] = t19;
535
- } else t19 = $[38];
536
- let t20;
537
- if ($[39] !== bodyId || $[40] !== disabled || $[41] !== isOpen || $[42] !== name || $[43] !== placeholder || $[44] !== popupRole || $[45] !== t18 || $[46] !== tabIndex) {
538
- 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", {
539
1193
  "aria-controls": bodyId,
540
1194
  "aria-expanded": isOpen,
541
1195
  "aria-haspopup": popupRole,
542
1196
  autoComplete: "off",
543
1197
  className: "uktdropdown-trigger",
544
- defaultValue: t18,
1198
+ defaultValue: t37,
545
1199
  disabled,
546
1200
  name,
547
- onFocus: t19,
1201
+ onFocus: t38,
548
1202
  placeholder,
549
1203
  ref: inputElementRef,
550
1204
  tabIndex,
551
1205
  type: "text"
552
1206
  });
553
- $[39] = bodyId;
554
- $[40] = disabled;
555
- $[41] = isOpen;
556
- $[42] = name;
557
- $[43] = placeholder;
558
- $[44] = popupRole;
559
- $[45] = t18;
560
- $[46] = tabIndex;
561
- $[47] = t20;
562
- } else t20 = $[47];
563
- 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;
564
1218
  } else {
565
- let t18;
566
- if ($[48] !== bodyId || $[49] !== isOpen || $[50] !== popupRole || $[51] !== trigger) {
567
- t18 = /* @__PURE__ */ jsx("button", {
1219
+ let t37;
1220
+ if ($[90] !== bodyId || $[91] !== isOpen || $[92] !== popupRole || $[93] !== trigger) {
1221
+ t37 = /* @__PURE__ */ jsx("button", {
568
1222
  "aria-controls": bodyId,
569
1223
  "aria-expanded": isOpen,
570
1224
  "aria-haspopup": popupRole,
@@ -573,127 +1227,107 @@ function Dropdown(t0) {
573
1227
  type: "button",
574
1228
  children: trigger
575
1229
  });
576
- $[48] = bodyId;
577
- $[49] = isOpen;
578
- $[50] = popupRole;
579
- $[51] = trigger;
580
- $[52] = t18;
581
- } else t18 = $[52];
582
- trigger = t18;
1230
+ $[90] = bodyId;
1231
+ $[91] = isOpen;
1232
+ $[92] = popupRole;
1233
+ $[93] = trigger;
1234
+ $[94] = t37;
1235
+ } else t37 = $[94];
1236
+ trigger = t37;
583
1237
  }
584
1238
  else {
585
1239
  const triggerProps = trigger.props;
586
- const t18 = trigger;
587
- const t19 = triggerProps["aria-controls"] ?? bodyId;
588
- const t20 = triggerProps["aria-expanded"] ?? isOpen;
589
- const t21 = triggerProps["aria-haspopup"] ?? popupRole;
590
- let t22;
591
- if ($[53] !== t18 || $[54] !== t19 || $[55] !== t20 || $[56] !== t21) {
592
- t22 = cloneElement(t18, {
593
- "aria-controls": t19,
594
- "aria-expanded": t20,
595
- "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
596
1250
  });
597
- $[53] = t18;
598
- $[54] = t19;
599
- $[55] = t20;
600
- $[56] = t21;
601
- $[57] = t22;
602
- } else t22 = $[57];
603
- trigger = t22;
1251
+ $[95] = t37;
1252
+ $[96] = t38;
1253
+ $[97] = t39;
1254
+ $[98] = t40;
1255
+ $[99] = t41;
1256
+ } else t41 = $[99];
1257
+ trigger = t41;
604
1258
  }
605
1259
  if (label != null) {
606
- let t18;
607
- if ($[58] !== label) {
608
- t18 = /* @__PURE__ */ jsx("div", {
1260
+ let t37;
1261
+ if ($[100] !== label) {
1262
+ t37 = /* @__PURE__ */ jsx("div", {
609
1263
  className: "uktdropdown-label-text",
610
1264
  children: label
611
1265
  });
612
- $[58] = label;
613
- $[59] = t18;
614
- } else t18 = $[59];
615
- let t19;
616
- if ($[60] !== t18 || $[61] !== trigger) {
617
- 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", {
618
1272
  className: "uktdropdown-label",
619
- children: [t18, trigger]
1273
+ children: [t37, trigger]
620
1274
  });
621
- $[60] = t18;
622
- $[61] = trigger;
623
- $[62] = t19;
624
- } else t19 = $[62];
625
- trigger = t19;
1275
+ $[102] = t37;
1276
+ $[103] = trigger;
1277
+ $[104] = t38;
1278
+ } else t38 = $[104];
1279
+ trigger = t38;
626
1280
  }
627
- let t18;
628
- if ($[63] !== minHeightBody) {
629
- t18 = minHeightBody != null && minHeightBody > 0 ? { "--uktdd-body-min-height": `${minHeightBody}px` } : null;
630
- $[63] = minHeightBody;
631
- $[64] = t18;
632
- } else t18 = $[64];
633
- let t19;
634
- if ($[65] !== minWidthBody) {
635
- t19 = minWidthBody != null && minWidthBody > 0 ? { "--uktdd-body-min-width": `${minWidthBody}px` } : null;
636
- $[65] = minWidthBody;
637
- $[66] = t19;
638
- } else t19 = $[66];
639
- let t20;
640
- if ($[67] !== styleFromProps || $[68] !== t18 || $[69] !== t19) {
641
- t20 = {
642
- ...styleFromProps,
643
- ...t18,
644
- ...t19
645
- };
646
- $[67] = styleFromProps;
647
- $[68] = t18;
648
- $[69] = t19;
649
- $[70] = t20;
650
- } else t20 = $[70];
651
- const style = t20;
652
- let t21;
653
- if ($[71] === Symbol.for("react.memo_cache_sentinel")) {
654
- t21 = /* @__PURE__ */ jsx("style", {
1281
+ let t37;
1282
+ if ($[105] === Symbol.for("react.memo_cache_sentinel")) {
1283
+ t37 = /* @__PURE__ */ jsx("style", {
655
1284
  href: "@acusti/dropdown/Dropdown",
656
1285
  precedence: "medium",
657
1286
  children: Dropdown_default
658
1287
  });
659
- $[71] = t21;
660
- } else t21 = $[71];
661
- let t22;
662
- if ($[72] !== className || $[73] !== disabled || $[74] !== isOpen || $[75] !== isSearchable) {
663
- 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, {
664
1293
  disabled,
665
1294
  "is-open": isOpen,
666
1295
  "is-searchable": isSearchable
667
1296
  });
668
- $[72] = className;
669
- $[73] = disabled;
670
- $[74] = isOpen;
671
- $[75] = isSearchable;
672
- $[76] = t22;
673
- } else t22 = $[76];
674
- let t23;
675
- if ($[77] !== bodyId || $[78] !== children || $[79] !== childrenCount || $[80] !== hasItems || $[81] !== isOpen || $[82] !== popupRole) {
676
- 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", {
677
1306
  className: clsx("uktdropdown-body", { "has-items": hasItems }),
678
1307
  id: bodyId,
1308
+ popover: "manual",
1309
+ ref: handleBodyRef,
679
1310
  role: popupRole,
680
1311
  children: /* @__PURE__ */ jsx("div", {
681
1312
  className: "uktdropdown-content",
682
- children: childrenCount > 1 ? children[1] : children
1313
+ children: /* @__PURE__ */ jsx(DropdownContext.Provider, {
1314
+ value: dropdownContextValue,
1315
+ children: childrenCount > 1 ? children[1] : children
1316
+ })
683
1317
  })
684
1318
  }) : null;
685
- $[77] = bodyId;
686
- $[78] = children;
687
- $[79] = childrenCount;
688
- $[80] = hasItems;
689
- $[81] = isOpen;
690
- $[82] = popupRole;
691
- $[83] = t23;
692
- } else t23 = $[83];
693
- let t24;
694
- if ($[84] !== handleMouseDown || $[85] !== handleMouseOut || $[86] !== handleMouseOver || $[87] !== handleMouseUp || $[88] !== handleRef || $[89] !== onClick || $[90] !== style || $[91] !== t22 || $[92] !== t23 || $[93] !== trigger) {
695
- t24 = /* @__PURE__ */ jsxs(Fragment, { children: [t21, /* @__PURE__ */ jsxs("div", {
696
- 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,
697
1331
  onClick,
698
1332
  onMouseDown: handleMouseDown,
699
1333
  onMouseMove: handleMouseMove,
@@ -701,24 +1335,129 @@ function Dropdown(t0) {
701
1335
  onMouseOver: handleMouseOver,
702
1336
  onMouseUp: handleMouseUp,
703
1337
  ref: handleRef,
704
- style,
705
- children: [trigger, t23]
1338
+ style: styleFromProps,
1339
+ children: [trigger, t39]
706
1340
  })] });
707
- $[84] = handleMouseDown;
708
- $[85] = handleMouseOut;
709
- $[86] = handleMouseOver;
710
- $[87] = handleMouseUp;
711
- $[88] = handleRef;
712
- $[89] = onClick;
713
- $[90] = style;
714
- $[91] = t22;
715
- $[92] = t23;
716
- $[93] = trigger;
717
- $[94] = t24;
718
- } else t24 = $[94];
719
- 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;
720
1459
  }
721
1460
  //#endregion
722
- export { Dropdown as default };
1461
+ export { Menubar, Dropdown as default };
723
1462
 
724
1463
  //# sourceMappingURL=Dropdown.js.map