@elliemae/ds-menu-button 3.80.0-next.8 → 3.80.0-next.80

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.
Files changed (96) hide show
  1. package/dist/cjs/config/useLatestValueReferenciallyStable.js +43 -0
  2. package/dist/cjs/config/useLatestValueReferenciallyStable.js.map +7 -0
  3. package/dist/cjs/config/useSideEffectSyntheticEvent.js +44 -0
  4. package/dist/cjs/config/useSideEffectSyntheticEvent.js.map +7 -0
  5. package/dist/cjs/config/useSplitInherithedProps.js +19 -2
  6. package/dist/cjs/config/useSplitInherithedProps.js.map +2 -2
  7. package/dist/cjs/parts/DSFlyoutMenu/DSFlyoutMenu.js +22 -1
  8. package/dist/cjs/parts/DSFlyoutMenu/DSFlyoutMenu.js.map +2 -2
  9. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js +4 -3
  10. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js.map +2 -2
  11. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js +10 -1
  12. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js.map +2 -2
  13. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useGlobalEvents.js +4 -3
  14. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useGlobalEvents.js.map +2 -2
  15. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js +59 -24
  16. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js.map +2 -2
  17. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.js +14 -8
  18. package/dist/cjs/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.js.map +2 -2
  19. package/dist/cjs/parts/DSMenuItemRendererFactory/ActivableMenuItem.js +6 -3
  20. package/dist/cjs/parts/DSMenuItemRendererFactory/ActivableMenuItem.js.map +2 -2
  21. package/dist/cjs/parts/DSMenuItemRendererFactory/ActivableWithSubmenuMenuItem.js +6 -3
  22. package/dist/cjs/parts/DSMenuItemRendererFactory/ActivableWithSubmenuMenuItem.js.map +2 -2
  23. package/dist/cjs/parts/DSMenuItemRendererFactory/MultipleSelectMenuItem.js +8 -5
  24. package/dist/cjs/parts/DSMenuItemRendererFactory/MultipleSelectMenuItem.js.map +2 -2
  25. package/dist/cjs/parts/DSMenuItemRendererFactory/MultipleSelectWithSubmenuMenuItem.js +8 -5
  26. package/dist/cjs/parts/DSMenuItemRendererFactory/MultipleSelectWithSubmenuMenuItem.js.map +2 -2
  27. package/dist/cjs/parts/DSMenuItemRendererFactory/SingleSelectMenuItem.js +6 -3
  28. package/dist/cjs/parts/DSMenuItemRendererFactory/SingleSelectMenuItem.js.map +2 -2
  29. package/dist/cjs/parts/DSMenuItemRendererFactory/SingleSelectWithSubmenuMenuItem.js +6 -3
  30. package/dist/cjs/parts/DSMenuItemRendererFactory/SingleSelectWithSubmenuMenuItem.js.map +2 -2
  31. package/dist/cjs/parts/DSMenuItemRendererFactory/SkeletonMenuItem.js +9 -1
  32. package/dist/cjs/parts/DSMenuItemRendererFactory/SkeletonMenuItem.js.map +2 -2
  33. package/dist/cjs/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.js +6 -3
  34. package/dist/cjs/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.js.map +2 -2
  35. package/dist/cjs/parts/DSOpinionatedButton/DSOpinionatedButton.js +9 -2
  36. package/dist/cjs/parts/DSOpinionatedButton/DSOpinionatedButton.js.map +2 -2
  37. package/dist/cjs/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js +58 -21
  38. package/dist/cjs/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js.map +2 -2
  39. package/dist/cjs/react-desc-prop-types.js +18 -2
  40. package/dist/cjs/react-desc-prop-types.js.map +2 -2
  41. package/dist/cjs/utils/nodesTypeguardsAndGetters.js +9 -0
  42. package/dist/cjs/utils/nodesTypeguardsAndGetters.js.map +2 -2
  43. package/dist/esm/config/useLatestValueReferenciallyStable.js +13 -0
  44. package/dist/esm/config/useLatestValueReferenciallyStable.js.map +7 -0
  45. package/dist/esm/config/useSideEffectSyntheticEvent.js +14 -0
  46. package/dist/esm/config/useSideEffectSyntheticEvent.js.map +7 -0
  47. package/dist/esm/config/useSplitInherithedProps.js +19 -2
  48. package/dist/esm/config/useSplitInherithedProps.js.map +2 -2
  49. package/dist/esm/parts/DSFlyoutMenu/DSFlyoutMenu.js +22 -1
  50. package/dist/esm/parts/DSFlyoutMenu/DSFlyoutMenu.js.map +2 -2
  51. package/dist/esm/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js +4 -3
  52. package/dist/esm/parts/DSMenuBehaviouralContextProvider/DSMenuBehaviouralContextProvider.js.map +2 -2
  53. package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js +10 -1
  54. package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.js.map +2 -2
  55. package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useGlobalEvents.js +4 -3
  56. package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useGlobalEvents.js.map +2 -2
  57. package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js +61 -24
  58. package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.js.map +2 -2
  59. package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.js +14 -8
  60. package/dist/esm/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.js.map +2 -2
  61. package/dist/esm/parts/DSMenuItemRendererFactory/ActivableMenuItem.js +6 -3
  62. package/dist/esm/parts/DSMenuItemRendererFactory/ActivableMenuItem.js.map +2 -2
  63. package/dist/esm/parts/DSMenuItemRendererFactory/ActivableWithSubmenuMenuItem.js +6 -3
  64. package/dist/esm/parts/DSMenuItemRendererFactory/ActivableWithSubmenuMenuItem.js.map +2 -2
  65. package/dist/esm/parts/DSMenuItemRendererFactory/MultipleSelectMenuItem.js +8 -5
  66. package/dist/esm/parts/DSMenuItemRendererFactory/MultipleSelectMenuItem.js.map +2 -2
  67. package/dist/esm/parts/DSMenuItemRendererFactory/MultipleSelectWithSubmenuMenuItem.js +8 -5
  68. package/dist/esm/parts/DSMenuItemRendererFactory/MultipleSelectWithSubmenuMenuItem.js.map +2 -2
  69. package/dist/esm/parts/DSMenuItemRendererFactory/SingleSelectMenuItem.js +6 -3
  70. package/dist/esm/parts/DSMenuItemRendererFactory/SingleSelectMenuItem.js.map +2 -2
  71. package/dist/esm/parts/DSMenuItemRendererFactory/SingleSelectWithSubmenuMenuItem.js +6 -3
  72. package/dist/esm/parts/DSMenuItemRendererFactory/SingleSelectWithSubmenuMenuItem.js.map +2 -2
  73. package/dist/esm/parts/DSMenuItemRendererFactory/SkeletonMenuItem.js +9 -1
  74. package/dist/esm/parts/DSMenuItemRendererFactory/SkeletonMenuItem.js.map +2 -2
  75. package/dist/esm/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.js +6 -3
  76. package/dist/esm/parts/DSMenuItemRendererFactory/WithSubmenuMenuItem.js.map +2 -2
  77. package/dist/esm/parts/DSOpinionatedButton/DSOpinionatedButton.js +9 -2
  78. package/dist/esm/parts/DSOpinionatedButton/DSOpinionatedButton.js.map +2 -2
  79. package/dist/esm/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js +58 -21
  80. package/dist/esm/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.js.map +2 -2
  81. package/dist/esm/react-desc-prop-types.js +18 -2
  82. package/dist/esm/react-desc-prop-types.js.map +2 -2
  83. package/dist/esm/utils/nodesTypeguardsAndGetters.js +9 -0
  84. package/dist/esm/utils/nodesTypeguardsAndGetters.js.map +2 -2
  85. package/dist/types/config/useLatestValueReferenciallyStable.d.ts +4 -0
  86. package/dist/types/config/useSideEffectSyntheticEvent.d.ts +9 -0
  87. package/dist/types/config/useSplitInherithedProps.d.ts +7 -3
  88. package/dist/types/parts/DSMenuBehaviouralContextProvider/config/useFocusTracker.d.ts +4 -1
  89. package/dist/types/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.d.ts +1 -0
  90. package/dist/types/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.d.ts +12 -4
  91. package/dist/types/parts/DSMenuItemRendererFactory/focusNodeRacingConditionSolved.d.ts +1 -1
  92. package/dist/types/parts/DSOpinionatedButton/config/useOpinionatedButton.d.ts +2 -1
  93. package/dist/types/parts/DSOpinionatedButton/config/useTriggerEventsHandlers.d.ts +1 -0
  94. package/dist/types/react-desc-prop-types.d.ts +64 -2
  95. package/dist/types/utils/nodesTypeguardsAndGetters.d.ts +21 -0
  96. package/package.json +14 -13
@@ -32,19 +32,24 @@ __export(useMenuItemEventsHandlers_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(useMenuItemEventsHandlers_exports);
34
34
  var React = __toESM(require("react"));
35
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
35
36
  var import_react = __toESM(require("react"));
36
37
  var import_nodesTypeguardsAndGetters = require("../../../utils/nodesTypeguardsAndGetters.js");
37
38
  var import_Errors = require("../constants/Errors.js");
38
39
  var import_multipleSelectionHelpers = require("../utils/multipleSelectionHelpers.js");
39
40
  var import_nodeGettersByCriterias = require("../utils/nodeGettersByCriterias.js");
40
41
  var import_singleSelectionHelpers = require("../utils/singleSelectionHelpers.js");
42
+ const invokeItemOnClickOnKeyboardActivation = (pseudoFocusedItemNode, event) => {
43
+ if (event?.type === "keydown" && pseudoFocusedItemNode.plainItem.onClick)
44
+ pseudoFocusedItemNode.plainItem.onClick(event);
45
+ };
41
46
  const useMenuItemEventsHandlers = ({
42
47
  propsWithDefault,
43
48
  focusTrackers,
44
49
  menuOpenStatus,
45
50
  handleChangeOpenedSubItems
46
51
  }) => {
47
- const { onItemSelected, onActivateItem, selectedNodes } = propsWithDefault;
52
+ const { onItemSelected, onActivateItem, onItemKeyDown, selectedNodes, buttonDOMNodeRef } = propsWithDefault;
48
53
  const { onOpinionatedClose } = menuOpenStatus;
49
54
  const {
50
55
  trackFocusFirstChildItem,
@@ -54,7 +59,8 @@ const useMenuItemEventsHandlers = ({
54
59
  trackFocusParentItem,
55
60
  trackFocusNode,
56
61
  focusedElementItemNode,
57
- trackFocusTrigger
62
+ trackFocusTrigger,
63
+ trackFocusRegionReset
58
64
  } = focusTrackers;
59
65
  const openSubmenu = import_react.default.useCallback(
60
66
  ({
@@ -116,10 +122,11 @@ const useMenuItemEventsHandlers = ({
116
122
  } else {
117
123
  onActivateItem(pseudoFocusedItemNode, { itemNode: pseudoFocusedItemNode, event });
118
124
  }
125
+ invokeItemOnClickOnKeyboardActivation(pseudoFocusedItemNode, event);
119
126
  const metainfo = { itemNode: pseudoFocusedItemNode, event };
120
127
  const newOpenedItems = [];
121
128
  handleChangeOpenedSubItems(newOpenedItems, metainfo);
122
- onOpinionatedClose();
129
+ onOpinionatedClose({ reason: "item-activation", event });
123
130
  }
124
131
  },
125
132
  [
@@ -142,18 +149,21 @@ const useMenuItemEventsHandlers = ({
142
149
  if ((0, import_nodesTypeguardsAndGetters.isMultipleSelectNode)(pseudoFocusedItemNode)) {
143
150
  const newSelection = (0, import_multipleSelectionHelpers.getNewSelectionMultipleSelect)(selectedNodes, pseudoFocusedItemNode);
144
151
  onItemSelected(newSelection, { itemNode: pseudoFocusedItemNode, event });
152
+ invokeItemOnClickOnKeyboardActivation(pseudoFocusedItemNode, event);
145
153
  return;
146
154
  }
147
155
  if ((0, import_nodesTypeguardsAndGetters.isSingleSelectNode)(pseudoFocusedItemNode)) {
148
156
  const newSelection = (0, import_singleSelectionHelpers.getNewSelectionSingleSelect)(selectedNodes, pseudoFocusedItemNode);
149
157
  onItemSelected(newSelection, { itemNode: pseudoFocusedItemNode, event });
158
+ invokeItemOnClickOnKeyboardActivation(pseudoFocusedItemNode, event);
150
159
  return;
151
160
  }
152
161
  onActivateItem?.(pseudoFocusedItemNode, { itemNode: pseudoFocusedItemNode, event });
162
+ invokeItemOnClickOnKeyboardActivation(pseudoFocusedItemNode, event);
153
163
  const metainfo = { itemNode: pseudoFocusedItemNode, event };
154
164
  const newOpenedItems = [];
155
165
  handleChangeOpenedSubItems(newOpenedItems, metainfo);
156
- onOpinionatedClose();
166
+ onOpinionatedClose({ reason: "item-activation", event });
157
167
  },
158
168
  [
159
169
  onActivateItem,
@@ -170,9 +180,7 @@ const useMenuItemEventsHandlers = ({
170
180
  if ((0, import_nodesTypeguardsAndGetters.isWithSubmenuNode)(pseudoFocusedItemNode)) {
171
181
  openSubmenu({ itemNode: pseudoFocusedItemNode, event });
172
182
  trackFocusFirstChildItem(pseudoFocusedItemNode);
173
- return;
174
183
  }
175
- return;
176
184
  },
177
185
  [openSubmenu, trackFocusFirstChildItem]
178
186
  );
@@ -185,36 +193,62 @@ const useMenuItemEventsHandlers = ({
185
193
  },
186
194
  [closeCurrentSubmenu, trackFocusParentItem]
187
195
  );
196
+ const handleMenuTabKeyDownCapture = import_react.default.useCallback(
197
+ (event) => {
198
+ if (event.key !== "Tab") return;
199
+ buttonDOMNodeRef.current?.focus();
200
+ trackFocusRegionReset();
201
+ onOpinionatedClose({ skipFocus: true, reason: "tab", event });
202
+ },
203
+ [buttonDOMNodeRef, onOpinionatedClose, trackFocusRegionReset]
204
+ );
188
205
  const handleFocusableMenuItemKeyDown = import_react.default.useCallback(
189
206
  (event) => {
207
+ if (event.key === "Tab") return;
208
+ const consumeKey = () => {
209
+ event.preventDefault();
210
+ event.stopPropagation();
211
+ };
190
212
  const pseudoFocusedItemNode = focusedElementItemNode.current;
191
213
  if (pseudoFocusedItemNode === null) throw import_Errors.UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_NODE_NOT_SET;
192
- if (pseudoFocusedItemNode.plainItem.onKeyDown) pseudoFocusedItemNode.plainItem.onKeyDown(event);
193
- if (event.key === "Tab") {
194
- trackFocusTrigger({ shouldFocusImmediately: true });
195
- onOpinionatedClose();
196
- return;
214
+ const isLockedActivation = (0, import_nodesTypeguardsAndGetters.isItemLocked)(pseudoFocusedItemNode.plainItem) && (0, import_ds_props_helpers.isActivationKey)(event);
215
+ if (pseudoFocusedItemNode.plainItem.onKeyDown && !isLockedActivation)
216
+ pseudoFocusedItemNode.plainItem.onKeyDown(event);
217
+ if (onItemKeyDown) {
218
+ onItemKeyDown({
219
+ itemNode: pseudoFocusedItemNode,
220
+ event,
221
+ nestLevel: (0, import_nodeGettersByCriterias.getSubMenusPath)(pseudoFocusedItemNode).length,
222
+ hasSubmenu: (0, import_nodesTypeguardsAndGetters.isWithSubmenuNode)(pseudoFocusedItemNode)
223
+ });
197
224
  }
198
225
  if (event.key === "ArrowDown") {
199
- event?.preventDefault();
226
+ consumeKey();
200
227
  trackFocusNextItem(pseudoFocusedItemNode);
201
228
  return;
202
229
  }
203
230
  if (event.key === "ArrowUp") {
204
- event?.preventDefault();
231
+ consumeKey();
205
232
  trackFocusPreviousItem(pseudoFocusedItemNode);
206
233
  return;
207
234
  }
208
235
  if (event.key === "ArrowLeft") {
209
- event?.preventDefault();
236
+ consumeKey();
210
237
  handleMenuItemLeftArrowKeyDown({ pseudoFocusedItemNode, event });
211
238
  return;
212
239
  }
240
+ if (event.key === "ArrowRight") {
241
+ consumeKey();
242
+ if (!(0, import_nodesTypeguardsAndGetters.isItemDisabled)(pseudoFocusedItemNode.plainItem))
243
+ handleMenuItemRightArrowKeyDown({ pseudoFocusedItemNode, event });
244
+ return;
245
+ }
213
246
  if (event.key === "Home") {
214
247
  if (!pseudoFocusedItemNode.parent) {
215
248
  console.log("handleFocusableMenuItemKeyDown -> Home > focused item node", pseudoFocusedItemNode);
216
249
  throw import_Errors.UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_HAS_NO_PARENT;
217
250
  }
251
+ consumeKey();
218
252
  trackFocusFirstChildItem(pseudoFocusedItemNode.parent);
219
253
  return;
220
254
  }
@@ -223,10 +257,12 @@ const useMenuItemEventsHandlers = ({
223
257
  console.log("handleFocusableMenuItemKeyDown -> Home > focused item node", pseudoFocusedItemNode);
224
258
  throw import_Errors.UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_HAS_NO_PARENT;
225
259
  }
260
+ consumeKey();
226
261
  trackFocusLastChildItem(pseudoFocusedItemNode.parent);
227
262
  return;
228
263
  }
229
264
  if (event.key === "Escape") {
265
+ event.stopPropagation();
230
266
  if (event.altKey && (0, import_nodesTypeguardsAndGetters.isWithSubmenuNode)(pseudoFocusedItemNode)) {
231
267
  closeSubmenusAfterNode({ itemNode: pseudoFocusedItemNode, event });
232
268
  return;
@@ -234,30 +270,27 @@ const useMenuItemEventsHandlers = ({
234
270
  const { currentSubmenuWasMainMenu } = closeCurrentSubmenu({ itemNode: pseudoFocusedItemNode, event });
235
271
  if (currentSubmenuWasMainMenu) {
236
272
  trackFocusTrigger({ shouldFocusImmediately: true });
237
- onOpinionatedClose({ skipFocus: true });
273
+ onOpinionatedClose({ skipFocus: true, reason: "escape", event });
238
274
  } else {
239
275
  trackFocusParentItem(pseudoFocusedItemNode);
240
276
  }
241
277
  return;
242
278
  }
243
- if (pseudoFocusedItemNode.plainItem.disabled) return;
279
+ if ((0, import_nodesTypeguardsAndGetters.isItemLocked)(pseudoFocusedItemNode.plainItem)) return;
244
280
  if (event.key === "Enter") {
281
+ event.stopPropagation();
245
282
  handleMenuItemEnterKeyDown({ pseudoFocusedItemNode, event });
246
283
  return;
247
284
  }
248
285
  if (event.key === " ") {
249
- event?.preventDefault();
286
+ consumeKey();
250
287
  handleMenuItemSpaceKeyDown({ pseudoFocusedItemNode, event });
251
288
  return;
252
289
  }
253
- if (event.key === "ArrowRight") {
254
- event?.preventDefault();
255
- handleMenuItemRightArrowKeyDown({ pseudoFocusedItemNode, event });
256
- return;
257
- }
258
290
  },
259
291
  [
260
292
  focusedElementItemNode,
293
+ onItemKeyDown,
261
294
  trackFocusTrigger,
262
295
  trackFocusNextItem,
263
296
  trackFocusPreviousItem,
@@ -277,7 +310,7 @@ const useMenuItemEventsHandlers = ({
277
310
  (event) => {
278
311
  const pseudoFocusedItemNode = focusedElementItemNode.current;
279
312
  if (pseudoFocusedItemNode === null) throw import_Errors.UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_NODE_NOT_SET;
280
- if (pseudoFocusedItemNode.plainItem.disabled) return;
313
+ if ((0, import_nodesTypeguardsAndGetters.isItemLocked)(pseudoFocusedItemNode.plainItem)) return;
281
314
  const parentMenuNode = pseudoFocusedItemNode.parent;
282
315
  if ((0, import_nodesTypeguardsAndGetters.isRootNode)(parentMenuNode)) {
283
316
  const metainfo = { itemNode: pseudoFocusedItemNode, event };
@@ -315,7 +348,7 @@ const useMenuItemEventsHandlers = ({
315
348
  handleChangeOpenedSubItems(newOpenedItems, metainfo);
316
349
  return;
317
350
  }
318
- if (itemNode.plainItem.disabled) return;
351
+ if ((0, import_nodesTypeguardsAndGetters.isItemDisabled)(itemNode.plainItem)) return;
319
352
  openSubmenu({ itemNode, event });
320
353
  },
321
354
  [handleChangeOpenedSubItems, openSubmenu, trackFocusNode]
@@ -338,12 +371,14 @@ const useMenuItemEventsHandlers = ({
338
371
  );
339
372
  return import_react.default.useMemo(
340
373
  () => ({
374
+ handleMenuTabKeyDownCapture,
341
375
  handleFocusableMenuItemKeyDown,
342
376
  handleFocusableMenuItemClick,
343
377
  handleFocusableMenuItemOnMouseEnter,
344
378
  handleFocusableMenuItemNativeFocusEvent
345
379
  }),
346
380
  [
381
+ handleMenuTabKeyDownCapture,
347
382
  handleFocusableMenuItemClick,
348
383
  handleFocusableMenuItemKeyDown,
349
384
  handleFocusableMenuItemNativeFocusEvent,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/parts/DSMenuBehaviouralContextProvider/config/useMenuItemEventsHandlers.ts", "../../../../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable no-console */\n/* eslint-disable max-lines */\n// in this files the returns are not useless, they are used to clearly demark the intended behavior shortcircuit for the next developer that reads the code\n/* eslint-disable no-useless-return */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\nimport React from 'react';\nimport { type DSMenuButtonT } from '../../../react-desc-prop-types.js';\nimport {\n isFocusableNode,\n isMultipleSelectNode,\n isRootNode,\n isSingleSelectNode,\n isWithSubmenuNode,\n isWithSubmenuOnlyNode,\n} from '../../../utils/nodesTypeguardsAndGetters.js';\nimport { FORBIDDEN_BEHAVIOURS, UNEXPECTED_INTERNAL_ERRORS } from '../constants/Errors.js';\nimport { type DSMenuBehaviouralContextProviderT } from '../react-desc-prop-types.js';\nimport { getNewSelectionMultipleSelect } from '../utils/multipleSelectionHelpers.js';\nimport { getSubMenusPath } from '../utils/nodeGettersByCriterias.js';\nimport { getNewSelectionSingleSelect } from '../utils/singleSelectionHelpers.js';\nimport type { useFocusTracker } from './useFocusTracker.js';\nimport type { useMenuOpenStatus } from './useMenuOpenStatus.js';\n\ntype ItemKeydownHelpersArgs = {\n pseudoFocusedItemNode: DSMenuButtonT.PseudoFocusableMenuNodes;\n event?: React.KeyboardEvent | React.MouseEvent;\n};\ntype SubmenuChangeMetainfo = {\n itemNode: DSMenuButtonT.PseudoFocusableMenuNodes;\n event?: React.SyntheticEvent;\n};\n\ntype UseMenuItemEventsHandlersConfig = {\n propsWithDefault: DSMenuBehaviouralContextProviderT.InternalProps;\n focusTrackers: ReturnType<typeof useFocusTracker>;\n menuOpenStatus: ReturnType<typeof useMenuOpenStatus>;\n handleChangeOpenedSubItems: Required<DSMenuButtonT.MenuBehaviouralLayerOptionalProps>['onDisplayedSubmenuChange'];\n};\n\nexport const useMenuItemEventsHandlers = ({\n propsWithDefault,\n focusTrackers,\n menuOpenStatus,\n handleChangeOpenedSubItems,\n}: UseMenuItemEventsHandlersConfig) => {\n const { onItemSelected, onActivateItem, selectedNodes } = propsWithDefault;\n const { onOpinionatedClose } = menuOpenStatus;\n const {\n trackFocusFirstChildItem,\n trackFocusLastChildItem,\n trackFocusNextItem,\n trackFocusPreviousItem,\n trackFocusParentItem,\n trackFocusNode,\n focusedElementItemNode,\n trackFocusTrigger,\n } = focusTrackers;\n\n const openSubmenu = React.useCallback(\n ({\n itemNode,\n event,\n }: {\n itemNode: DSMenuButtonT.WithSubmenuMenuNodes;\n event?: React.KeyboardEvent | React.MouseEvent | React.FocusEvent;\n }) => {\n if (!isWithSubmenuNode(itemNode)) {\n console.log('openSubmenu -> itemNode:', itemNode);\n throw FORBIDDEN_BEHAVIOURS.TRYING_TO_OPEN_SUBMENU_OF_NODE_WITHOUT_SUBMENU;\n }\n const subMenuNodesPath = getSubMenusPath(itemNode);\n const metainfo: SubmenuChangeMetainfo = { itemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [...subMenuNodesPath, itemNode];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n },\n [handleChangeOpenedSubItems],\n );\n const closeSubmenusAfterNode = React.useCallback(\n ({\n itemNode,\n event,\n }: {\n itemNode: DSMenuButtonT.PseudoFocusableMenuNodes;\n event?: React.KeyboardEvent | React.MouseEvent | React.FocusEvent;\n }) => {\n const subMenuNodesPath = getSubMenusPath(itemNode);\n const metainfo: SubmenuChangeMetainfo = { itemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [...subMenuNodesPath];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n },\n [handleChangeOpenedSubItems],\n );\n const closeCurrentSubmenu = React.useCallback(\n ({\n itemNode,\n event,\n }: {\n itemNode: DSMenuButtonT.PseudoFocusableMenuNodes;\n event?: React.KeyboardEvent | React.MouseEvent;\n }) => {\n const metainfo: SubmenuChangeMetainfo = { itemNode, event };\n const subMenuNodesPath = getSubMenusPath(itemNode);\n // if length is 0, it means the parent is the root node, so we close all the submenus\n if (subMenuNodesPath.length === 0) {\n handleChangeOpenedSubItems([], metainfo);\n return { currentSubmenuWasMainMenu: true };\n }\n\n // we want to close current submenu, so we pop the last element\n // getSubMenusPath guarantees the order by walkParents + reverse at the end\n subMenuNodesPath.pop();\n handleChangeOpenedSubItems(subMenuNodesPath, metainfo);\n return { currentSubmenuWasMainMenu: false };\n },\n [handleChangeOpenedSubItems],\n );\n\n /*\n * 13th August 2024:\n * https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/\n * Additional roles, states, and properties needed for the menu element are described in the Menu and Menubar Pattern.\n * https://www.w3.org/WAI/ARIA/apg/patterns/menubar/\n * Because menubar and menu elements are composite widgets as described in the practice for Keyboard Navigation Inside Components,\n * Tab and Shift + Tab do not move focus among the items in the menu.\n * Instead, the keyboard commands described in this section enable users to move focus among the elements in a menubar or menu.\n * Tab and Shift + Tab:\n * - Move focus into a menubar <- Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n * - When focus is on a menuitem in a menu or menubar, move focus out of the menu or menubar, and close all menus and submenus.\n * ************************************************************************************************************************************\n * this will be implemented by not setting document.activeElement to the menuitem but keeping it on the trigger button\n * why? because there is no javascript API to trigger a \"tab\"/\"shift+tab\" navigation and any algorithm trying to do so is fragile\n * also, this is enforced by w3.org too as per:\n * ************************************************************************************************************************************\n * Note that Tab and Shift + Tab do not move focus into a menu.\n * Unlike a menubar, a menu is not visually persistent,\n * and authors are responsible for ensuring focus moves to an item inside of a menu when the menu opens.\n *\n */\n const handleMenuItemEnterKeyDown = React.useCallback(\n ({ pseudoFocusedItemNode, event }: ItemKeydownHelpersArgs) => {\n // Enter:\n // - When focus is on a menuitem that has a submenu, opens the submenu and places focus on its first item.\n // ...\n if (isWithSubmenuOnlyNode(pseudoFocusedItemNode)) {\n openSubmenu({ itemNode: pseudoFocusedItemNode, event });\n trackFocusFirstChildItem(pseudoFocusedItemNode);\n } else {\n // - Otherwise, activates the item...\n\n // ----------------------------------\n // 4. Although it is recommended that authors avoid doing so,\n // some implementations of navigation menubars may have menuitem elements that both perform a function and open a submenu.\n // In such implementations, Enter and Space perform a navigation function,\n // e.g., load new content, while Down Arrow, in a horizontal menubar, opens the submenu associated with that same menuitem.\n // ---------------------------------\n // Based on an investigation, the above statement is not specific to \"navigation\" nor to ONLY \"menubars\", it really is about \"menuitems\" in general\n // as long as the role=\"menuitem\" & aria-haspopup=\"${id-of-the-submenu}\" & aria-expanded=\"${true/false}\" (& aria-orientation=\"vertical/horizontal\" if non-default)\n // are set, the Screen Readers will provide the same announcement for the menuitem regardless of the parent role\n\n // \"activation\" is a concept,\n // WCAG here implies that for menuitemscheckbox and menuitemsradio this triggers the selection\n // for menuitems (that doesn't fit selection nor submenus) it triggers the action\n // this also triggers enter -> single-select-item-with-submenu as expected\n if (isMultipleSelectNode(pseudoFocusedItemNode)) {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n const newSelection = getNewSelectionMultipleSelect(selectedNodes!, pseudoFocusedItemNode);\n onItemSelected!(newSelection, { itemNode: pseudoFocusedItemNode, event });\n } else if (isSingleSelectNode(pseudoFocusedItemNode)) {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n const newSelection = getNewSelectionSingleSelect(selectedNodes!, pseudoFocusedItemNode);\n onItemSelected!(newSelection, { itemNode: pseudoFocusedItemNode, event });\n } else {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n onActivateItem!(pseudoFocusedItemNode, { itemNode: pseudoFocusedItemNode, event });\n }\n // ... and closes the menu.\n const metainfo: SubmenuChangeMetainfo = { itemNode: pseudoFocusedItemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n onOpinionatedClose();\n }\n },\n [\n trackFocusFirstChildItem,\n openSubmenu,\n handleChangeOpenedSubItems,\n onOpinionatedClose,\n selectedNodes,\n onItemSelected,\n onActivateItem,\n ],\n );\n const handleMenuItemSpaceKeyDown = React.useCallback(\n ({ pseudoFocusedItemNode, event }: ItemKeydownHelpersArgs) => {\n // Space:\n // [X] (Optional): When focus is on a menuitem that has a submenu, opens the submenu and places focus on its first item.\n // ----------------------------------\n // 4. Although it is recommended that authors avoid doing so,\n // some implementations of navigation menubars may have menuitem elements that both perform a function and open a submenu.\n // In such implementations, Enter and Space perform a navigation function,\n // e.g., load new content, while Down Arrow, in a horizontal menubar, opens the submenu associated with that same menuitem.\n // ---------------------------------\n // Based on an investigation, the above statement is not specific to \"navigation\" nor to ONLY \"menubars\", it really is about \"menuitems\" in general\n // as long as the role=\"menuitem\" & aria-haspopup=\"${id-of-the-submenu}\" & aria-expanded=\"${true/false}\" (& aria-orientation=\"vertical/horizontal\" if non-default)\n // are set, the Screen Readers will provide the same announcement for the menuitem regardless of the parent role\n if (isWithSubmenuOnlyNode(pseudoFocusedItemNode)) {\n openSubmenu({ itemNode: pseudoFocusedItemNode, event });\n trackFocusFirstChildItem(pseudoFocusedItemNode);\n return;\n }\n // [X] (Optional): When focus is on a menuitemcheckbox, changes the state without closing the menu.\n if (isMultipleSelectNode(pseudoFocusedItemNode)) {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n const newSelection = getNewSelectionMultipleSelect(selectedNodes!, pseudoFocusedItemNode);\n onItemSelected!(newSelection, { itemNode: pseudoFocusedItemNode, event });\n return;\n }\n // [X] (Optional): When focus is on a menuitemradio that is not checked, without closing the menu,\n // checks the focused menuitemradio and unchecks any other checked menuitemradio element in the same group.\n if (isSingleSelectNode(pseudoFocusedItemNode)) {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n const newSelection = getNewSelectionSingleSelect(selectedNodes!, pseudoFocusedItemNode);\n onItemSelected!(newSelection, { itemNode: pseudoFocusedItemNode, event });\n return;\n }\n // [X] (Optional): When focus is on a menuitem that does not have a submenu, activates the menuitem and closes the menu.\n onActivateItem?.(pseudoFocusedItemNode, { itemNode: pseudoFocusedItemNode, event });\n\n const metainfo: SubmenuChangeMetainfo = { itemNode: pseudoFocusedItemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n onOpinionatedClose();\n },\n [\n onActivateItem,\n handleChangeOpenedSubItems,\n onOpinionatedClose,\n trackFocusFirstChildItem,\n openSubmenu,\n selectedNodes,\n onItemSelected,\n ],\n );\n const handleMenuItemRightArrowKeyDown = React.useCallback(\n ({ pseudoFocusedItemNode, event }: ItemKeydownHelpersArgs) => {\n // Right Arrow:\n // [N/A] When focus is in a menubar, moves focus to the next item, optionally wrapping from the last to the first.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n\n // [X] When focus is in a menu and on a menuitem that has a submenu, opens the submenu and places focus on its first item.\n // [N/A] When focus is in a menu and on an item that does not have a submenu, performs the following 3 actions:\n // [N/A] Closes the submenu and any parent menus.\n // [N/A] Moves focus to the next item in the menubar.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n\n // [X] If focus is now on a menuitem with a submenu, either:\n // [X] (Recommended) opens the submenu of that menuitem without moving focus into the submenu,\n // /\\ we choose the recommended option\n // OR\n // [N/A] opens the submenu of that menuitem and places focus on the first item in the submenu.\n // ***********************************************************\n // Dimsum implements IoC, if APP side for whatever reason wants to open the new sub sub menu,\n // it's up to them to listen to the pseudo focus event and open the sub sub menu\n // ***********************************************************\n if (isWithSubmenuNode(pseudoFocusedItemNode)) {\n openSubmenu({ itemNode: pseudoFocusedItemNode, event });\n trackFocusFirstChildItem(pseudoFocusedItemNode);\n return;\n }\n // Note that if the menubar were not present, e.g., the menus were opened from a menubutton,\n // Right Arrow would not do anything when focus is on an item that does not have a submenu.\n return;\n },\n [openSubmenu, trackFocusFirstChildItem],\n );\n\n const handleMenuItemLeftArrowKeyDown = React.useCallback(\n ({ pseudoFocusedItemNode, event }: ItemKeydownHelpersArgs) => {\n // Left Arrow:\n // [N/A] When focus is in a menubar, moves focus to the previous item, optionally wrapping from the first to the last.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n\n // [X] When focus is in a submenu of an item in a menu, closes the submenu and returns focus to the parent menuitem.\n const { currentSubmenuWasMainMenu } = closeCurrentSubmenu({ itemNode: pseudoFocusedItemNode, event });\n if (!currentSubmenuWasMainMenu) {\n trackFocusParentItem(pseudoFocusedItemNode);\n }\n\n // [N/A] When focus is in a submenu of an item in a menubar, performs the following 3 actions:\n // [N/A] Closes the submenu.\n // [N/A] Moves focus to the previous item in the menubar.\n // [N/A] If focus is now on a menuitem with a submenu, either:\n // (Recommended) opens the submenu of that menuitem without moving focus into the submenu,\n // or\n // opens the submenu of that menuitem and places focus on the first item in the submenu.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n },\n [closeCurrentSubmenu, trackFocusParentItem],\n );\n\n const handleFocusableMenuItemKeyDown = React.useCallback<React.KeyboardEventHandler<HTMLDivElement>>(\n (event) => {\n const pseudoFocusedItemNode = focusedElementItemNode.current;\n // if there is no focused item, we can't handle the logics\n if (pseudoFocusedItemNode === null) throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_NODE_NOT_SET;\n // if the item contains an `onKeyDown` prop, we trigger it\n if (pseudoFocusedItemNode.plainItem.onKeyDown) pseudoFocusedItemNode.plainItem.onKeyDown(event);\n // TAB:\n // When focus is on a menuitem in a menu or menubar, move focus to the trigger so tab flows occurs from there.\n // Then close all menus and submenus.\n if (event.key === 'Tab') {\n trackFocusTrigger({ shouldFocusImmediately: true });\n onOpinionatedClose();\n return;\n }\n // Down Arrow:\n // [N/A] When focus is on a menuitem in a menubar, and that menuitem has a submenu, opens the submenu and places focus on the first item in the submenu.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n // [X] When focus is in a menu, moves focus to the next item,\n // [X] optionally wrapping from the last to the first.\n if (event.key === 'ArrowDown') {\n event?.preventDefault(); // if scrollbar are present, this keydown event should not interact with the scrollbar\n trackFocusNextItem(pseudoFocusedItemNode);\n return;\n }\n // Up Arrow:\n // [X] When focus is in a menu, moves focus to the previous item,\n // [X] optionally wrapping from the first to the last.\n // [N/A] (Optional): When focus is on a menuitem in a menubar, and that menuitem has a submenu, opens the submenu and places focus on the last item in the submenu.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n if (event.key === 'ArrowUp') {\n event?.preventDefault(); // if scrollbar are present, this keydown event should not interact with the scrollbar\n trackFocusPreviousItem(pseudoFocusedItemNode);\n return;\n }\n // Left Arrow:\n if (event.key === 'ArrowLeft') {\n event?.preventDefault(); // if scrollbar are present, this keydown event should not interact with the scrollbar\n handleMenuItemLeftArrowKeyDown({ pseudoFocusedItemNode, event });\n return;\n }\n // Home: If arrow key wrapping is not supported, moves focus to the first item in the current menu or menubar.\n if (event.key === 'Home') {\n if (!pseudoFocusedItemNode.parent) {\n console.log('handleFocusableMenuItemKeyDown -> Home > focused item node', pseudoFocusedItemNode);\n // should be impossible, at most the .parent is the root node, which is not able to trigger this event\n throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_HAS_NO_PARENT;\n }\n trackFocusFirstChildItem(pseudoFocusedItemNode.parent);\n return;\n }\n // End: If arrow key wrapping is not supported, moves focus to the last item in the current menu or menubar.\n if (event.key === 'End') {\n if (!pseudoFocusedItemNode.parent) {\n console.log('handleFocusableMenuItemKeyDown -> Home > focused item node', pseudoFocusedItemNode);\n // should be impossible, at most the .parent is the root node, which is not able to trigger this event\n throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_HAS_NO_PARENT;\n }\n trackFocusLastChildItem(pseudoFocusedItemNode.parent);\n return;\n }\n if (event.key === 'Escape') {\n // if the item has no submenu, the alt key is transparent, we behave as if it's not even pressed\n if (event.altKey && isWithSubmenuNode(pseudoFocusedItemNode)) {\n // PUI-14639 - Implement submenu dismissal mechanism\n // Description: we need to add a mechanism to close submenus that automatically expand when a menu item is focused with the keyboard.\n // we have decided to implement a special shortcut (Alt/Option + Esc) as the dismissal mechanism.\n // This change is necessary to comply with WCAG success criterion 1.4.13.\n // https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus.html\n // if the item has a submenu, we close it\n closeSubmenusAfterNode({ itemNode: pseudoFocusedItemNode, event });\n return;\n }\n // Escape: Close the menu that contains focus and return focus to the element or context, e.g., menu button or parent menuitem, from which the menu was opened\n const { currentSubmenuWasMainMenu } = closeCurrentSubmenu({ itemNode: pseudoFocusedItemNode, event });\n if (currentSubmenuWasMainMenu) {\n // if the menu we are trying to close is the main menu, we additionally close the main menu itself\n // we focus the trigger immediately (shouldFocusImmediately: true) so the focus return is synchronous\n // and not deferred to requestAnimationFrame \u2014 Escape on the trigger is safe since it only calls\n // onOpinionatedClose() which is already a no-op when the menu is closed\n trackFocusTrigger({ shouldFocusImmediately: true });\n onOpinionatedClose({ skipFocus: true });\n } else {\n trackFocusParentItem(pseudoFocusedItemNode);\n }\n return;\n }\n\n /* ************************************************************************************\n * ******* ACTIVATION & SUBMENU keys doesn't apply if the item is \"disabled\" **********\n * ************************************************************************************ */\n if (pseudoFocusedItemNode.plainItem.disabled) return;\n // Enter:\n if (event.key === 'Enter') {\n handleMenuItemEnterKeyDown({ pseudoFocusedItemNode, event });\n return;\n }\n // Space:\n if (event.key === ' ') {\n event?.preventDefault(); // if scrollbar are present, this keydown event should not interact with the scrollbar\n handleMenuItemSpaceKeyDown({ pseudoFocusedItemNode, event });\n return;\n }\n // Right Arrow:\n if (event.key === 'ArrowRight') {\n event?.preventDefault(); // if scrollbar are present, this keydown event should not interact with the scrollbar\n handleMenuItemRightArrowKeyDown({ pseudoFocusedItemNode, event });\n return;\n }\n },\n [\n focusedElementItemNode,\n trackFocusTrigger,\n trackFocusNextItem,\n trackFocusPreviousItem,\n handleMenuItemLeftArrowKeyDown,\n trackFocusFirstChildItem,\n trackFocusLastChildItem,\n closeCurrentSubmenu,\n trackFocusParentItem,\n closeSubmenusAfterNode,\n onOpinionatedClose,\n handleMenuItemEnterKeyDown,\n handleMenuItemSpaceKeyDown,\n handleMenuItemRightArrowKeyDown,\n ],\n );\n const handleFocusableMenuItemClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement>) => {\n const pseudoFocusedItemNode = focusedElementItemNode.current;\n if (pseudoFocusedItemNode === null) throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_NODE_NOT_SET;\n // if the item is disabled, we don't do anything\n if (pseudoFocusedItemNode.plainItem.disabled) return;\n // we need to handle which submenu needs to close automagically based on the click\n // starting from the itemNode, we check:\n // - the parent of the itemNode is root?\n // - yes -> we close all the submenus\n const parentMenuNode = pseudoFocusedItemNode.parent;\n if (isRootNode(parentMenuNode)) {\n const metainfo: SubmenuChangeMetainfo = { itemNode: pseudoFocusedItemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n } else {\n // - no -> we close all the submenus that are not in the path to the root of the itemNode\n // this is necessary on click because the user can still interact with other (visual) depths of the menu\n // during keyboard navigation, the user is limited to the current (visual) depth\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [...getSubMenusPath(pseudoFocusedItemNode)];\n // - if the clicked node has a submenu, keep it open\n if (isWithSubmenuNode(pseudoFocusedItemNode)) {\n newOpenedItems.push(pseudoFocusedItemNode);\n }\n const metainfo: SubmenuChangeMetainfo = { itemNode: pseudoFocusedItemNode, event };\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n }\n\n // to all effects and purposes, the click event is the same as the space key\n // the main difference between enter and space is that\n // - enter ALWAYS closes the menu excepts for submenus\n // - space closes the menu if \"activable\", selections doesn't, submenus doesn't\n handleMenuItemSpaceKeyDown({ pseudoFocusedItemNode, event });\n // if the item contains an `onClick` prop, we trigger it\n if (pseudoFocusedItemNode.plainItem.onClick) pseudoFocusedItemNode.plainItem.onClick(event);\n },\n [focusedElementItemNode, handleMenuItemSpaceKeyDown, handleChangeOpenedSubItems],\n );\n\n // the \"menu-button\" widget is an opinionated widget with a specific behaviour to follow when a focusable item is \"focused\"\n // this function achieve the opinionated \"focus an item\" opinionated behaviour (regardless of why the item is focused)\n const opinionatedFocusBehaviour = React.useCallback(\n // we currently know only one \"event\" that can trigger this opinionated behaviour\n // - focus => React.FocusEvent <-- triggered by ATs \"focus mode\" or \"virtual cursor\" navigation\n // NOTE:\n // mouseEnter => React.MouseEvent\n // still ends up calling this function, but as a side effect of mouse-enter focusing the item, not as the main event\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes, event: React.FocusEvent) => {\n if (!isFocusableNode(itemNode)) {\n console.log('handleFocusableMenuItemOnMouseEnter > itemNode:', itemNode);\n throw FORBIDDEN_BEHAVIOURS.TRYING_TO_FOCUS_NON_FOCUSABLE_NODE;\n }\n // on hover -> we track the hovered item as the focused one on top of which events should work on\n trackFocusNode(itemNode);\n if (!isWithSubmenuNode(itemNode)) {\n // if the item has nosubmenu we close all the siblings submenus\n const subMenuNodesPath = getSubMenusPath(itemNode);\n const metainfo: SubmenuChangeMetainfo = { itemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [...subMenuNodesPath];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n return;\n }\n // if the item is disabled, we don't open the submenu, and there is nothing else to do\n if (itemNode.plainItem.disabled) return;\n // if not disabled and it has a submenu, we open it, and there is nothing else to do\n openSubmenu({ itemNode, event });\n },\n [handleChangeOpenedSubItems, openSubmenu, trackFocusNode],\n );\n\n // when an item is hovered, we focus it\n // this effectively achieves:\n // - the item is focused (it trigger the handleFocusableMenuItemNativeFocusEvent function because render runs node.focus())\n // - if the user presses a keyboard key, the interaction will work starting from the (hovered hence focused) item\n const handleFocusableMenuItemOnMouseEnter = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n if (!isFocusableNode(itemNode)) {\n console.log('handleFocusableMenuItemOnMouseEnter > itemNode:', itemNode);\n throw FORBIDDEN_BEHAVIOURS.TRYING_TO_FOCUS_NON_FOCUSABLE_NODE;\n }\n // on hover -> we track the hovered item as the focused one on top of which events should work on\n trackFocusNode(itemNode);\n },\n [trackFocusNode],\n );\n\n const handleFocusableMenuItemNativeFocusEvent = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes, event: React.FocusEvent) => {\n opinionatedFocusBehaviour(itemNode, event);\n },\n [opinionatedFocusBehaviour],\n );\n\n return React.useMemo(\n () => ({\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemClick,\n handleFocusableMenuItemOnMouseEnter,\n handleFocusableMenuItemNativeFocusEvent,\n }),\n [\n handleFocusableMenuItemClick,\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemNativeFocusEvent,\n handleFocusableMenuItemOnMouseEnter,\n ],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADMvB,mBAAkB;AAElB,uCAOO;AACP,oBAAiE;AAEjE,sCAA8C;AAC9C,oCAAgC;AAChC,oCAA4C;AAoBrC,MAAM,4BAA4B,CAAC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAuC;AACrC,QAAM,EAAE,gBAAgB,gBAAgB,cAAc,IAAI;AAC1D,QAAM,EAAE,mBAAmB,IAAI;AAC/B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,cAAc,aAAAA,QAAM;AAAA,IACxB,CA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cAAM,iBAAuD,CAAC,GAAG,gBAAgB;AACjF,mCAA2B,gBAAgB,QAAQ;AACnD;AAAA,MACF;AAEA,UAAI,SAAS,UAAU,SAAU;AAEjC,kBAAY,EAAE,UAAU,MAAM,CAAC;AAAA,IACjC;AAAA,IACA,CAAC,4BAA4B,aAAa,cAAc;AAAA,EAC1D;AAMA,QAAM,sCAAsC,aAAAA,QAAM;AAAA,IAChD,CAAC,aAAqD;AACpD,UAAI,KAAC,kDAAgB,QAAQ,GAAG;AAC9B,gBAAQ,IAAI,mDAAmD,QAAQ;AACvE,cAAM,mCAAqB;AAAA,MAC7B;AAEA,qBAAe,QAAQ;AAAA,IACzB;AAAA,IACA,CAAC,cAAc;AAAA,EACjB;AAEA,QAAM,0CAA0C,aAAAA,QAAM;AAAA,IACpD,CAAC,UAAkD,UAA4B;AAC7E,gCAA0B,UAAU,KAAK;AAAA,IAC3C;AAAA,IACA,CAAC,yBAAyB;AAAA,EAC5B;AAEA,SAAO,aAAAA,QAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["/* eslint-disable no-console */\n/* eslint-disable max-lines */\n// in this files the returns are not useless, they are used to clearly demark the intended behavior shortcircuit for the next developer that reads the code\n/* eslint-disable no-useless-return */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\nimport { isActivationKey } from '@elliemae/ds-props-helpers';\nimport React from 'react';\nimport { type DSMenuButtonT } from '../../../react-desc-prop-types.js';\nimport {\n isFocusableNode,\n isItemDisabled,\n isItemLocked,\n isMultipleSelectNode,\n isRootNode,\n isSingleSelectNode,\n isWithSubmenuNode,\n isWithSubmenuOnlyNode,\n} from '../../../utils/nodesTypeguardsAndGetters.js';\nimport { FORBIDDEN_BEHAVIOURS, UNEXPECTED_INTERNAL_ERRORS } from '../constants/Errors.js';\nimport { type DSMenuBehaviouralContextProviderT } from '../react-desc-prop-types.js';\nimport { getNewSelectionMultipleSelect } from '../utils/multipleSelectionHelpers.js';\nimport { getSubMenusPath } from '../utils/nodeGettersByCriterias.js';\nimport { getNewSelectionSingleSelect } from '../utils/singleSelectionHelpers.js';\nimport type { useFocusTracker } from './useFocusTracker.js';\nimport type { useMenuOpenStatus } from './useMenuOpenStatus.js';\n\ntype ItemKeydownHelpersArgs = {\n pseudoFocusedItemNode: DSMenuButtonT.PseudoFocusableMenuNodes;\n event?: React.KeyboardEvent | React.MouseEvent;\n};\ntype SubmenuChangeMetainfo = {\n itemNode: DSMenuButtonT.PseudoFocusableMenuNodes;\n event?: React.SyntheticEvent;\n};\n\ntype UseMenuItemEventsHandlersConfig = {\n propsWithDefault: DSMenuBehaviouralContextProviderT.InternalProps;\n focusTrackers: ReturnType<typeof useFocusTracker>;\n menuOpenStatus: ReturnType<typeof useMenuOpenStatus>;\n handleChangeOpenedSubItems: Required<DSMenuButtonT.MenuBehaviouralLayerOptionalProps>['onDisplayedSubmenuChange'];\n};\n\n// the item's own `onClick` is part of the item contract for ANY activation (its type accepts keyboard events):\n// the click path already invokes it, so the keyboard activation (Enter/Space) must invoke it too.\n// The click path routes through the Space handler and then calls `onClick` itself, hence the `keydown` check to never fire it twice.\nconst invokeItemOnClickOnKeyboardActivation = (\n pseudoFocusedItemNode: DSMenuButtonT.PseudoFocusableMenuNodes,\n event?: React.KeyboardEvent | React.MouseEvent,\n) => {\n if (event?.type === 'keydown' && pseudoFocusedItemNode.plainItem.onClick)\n pseudoFocusedItemNode.plainItem.onClick(event as React.KeyboardEvent);\n};\n\nexport const useMenuItemEventsHandlers = ({\n propsWithDefault,\n focusTrackers,\n menuOpenStatus,\n handleChangeOpenedSubItems,\n}: UseMenuItemEventsHandlersConfig) => {\n const { onItemSelected, onActivateItem, onItemKeyDown, selectedNodes, buttonDOMNodeRef } = propsWithDefault;\n const { onOpinionatedClose } = menuOpenStatus;\n const {\n trackFocusFirstChildItem,\n trackFocusLastChildItem,\n trackFocusNextItem,\n trackFocusPreviousItem,\n trackFocusParentItem,\n trackFocusNode,\n focusedElementItemNode,\n trackFocusTrigger,\n trackFocusRegionReset,\n } = focusTrackers;\n\n const openSubmenu = React.useCallback(\n ({\n itemNode,\n event,\n }: {\n itemNode: DSMenuButtonT.WithSubmenuMenuNodes;\n event?: React.KeyboardEvent | React.MouseEvent | React.FocusEvent;\n }) => {\n if (!isWithSubmenuNode(itemNode)) {\n console.log('openSubmenu -> itemNode:', itemNode);\n throw FORBIDDEN_BEHAVIOURS.TRYING_TO_OPEN_SUBMENU_OF_NODE_WITHOUT_SUBMENU;\n }\n const subMenuNodesPath = getSubMenusPath(itemNode);\n const metainfo: SubmenuChangeMetainfo = { itemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [...subMenuNodesPath, itemNode];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n },\n [handleChangeOpenedSubItems],\n );\n const closeSubmenusAfterNode = React.useCallback(\n ({\n itemNode,\n event,\n }: {\n itemNode: DSMenuButtonT.PseudoFocusableMenuNodes;\n event?: React.KeyboardEvent | React.MouseEvent | React.FocusEvent;\n }) => {\n const subMenuNodesPath = getSubMenusPath(itemNode);\n const metainfo: SubmenuChangeMetainfo = { itemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [...subMenuNodesPath];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n },\n [handleChangeOpenedSubItems],\n );\n const closeCurrentSubmenu = React.useCallback(\n ({\n itemNode,\n event,\n }: {\n itemNode: DSMenuButtonT.PseudoFocusableMenuNodes;\n event?: React.KeyboardEvent | React.MouseEvent;\n }) => {\n const metainfo: SubmenuChangeMetainfo = { itemNode, event };\n const subMenuNodesPath = getSubMenusPath(itemNode);\n // if length is 0, it means the parent is the root node, so we close all the submenus\n if (subMenuNodesPath.length === 0) {\n handleChangeOpenedSubItems([], metainfo);\n return { currentSubmenuWasMainMenu: true };\n }\n\n // we want to close current submenu, so we pop the last element\n // getSubMenusPath guarantees the order by walkParents + reverse at the end\n subMenuNodesPath.pop();\n handleChangeOpenedSubItems(subMenuNodesPath, metainfo);\n return { currentSubmenuWasMainMenu: false };\n },\n [handleChangeOpenedSubItems],\n );\n\n /*\n * 13th August 2024:\n * https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/\n * Additional roles, states, and properties needed for the menu element are described in the Menu and Menubar Pattern.\n * https://www.w3.org/WAI/ARIA/apg/patterns/menubar/\n * Because menubar and menu elements are composite widgets as described in the practice for Keyboard Navigation Inside Components,\n * Tab and Shift + Tab do not move focus among the items in the menu.\n * Instead, the keyboard commands described in this section enable users to move focus among the elements in a menubar or menu.\n * Tab and Shift + Tab:\n * - Move focus into a menubar <- Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n * - When focus is on a menuitem in a menu or menubar, move focus out of the menu or menubar, and close all menus and submenus.\n * ************************************************************************************************************************************\n * this will be implemented by not setting document.activeElement to the menuitem but keeping it on the trigger button\n * why? because there is no javascript API to trigger a \"tab\"/\"shift+tab\" navigation and any algorithm trying to do so is fragile\n * also, this is enforced by w3.org too as per:\n * ************************************************************************************************************************************\n * Note that Tab and Shift + Tab do not move focus into a menu.\n * Unlike a menubar, a menu is not visually persistent,\n * and authors are responsible for ensuring focus moves to an item inside of a menu when the menu opens.\n *\n */\n const handleMenuItemEnterKeyDown = React.useCallback(\n ({ pseudoFocusedItemNode, event }: ItemKeydownHelpersArgs) => {\n // Enter:\n // - When focus is on a menuitem that has a submenu, opens the submenu and places focus on its first item.\n // ...\n if (isWithSubmenuOnlyNode(pseudoFocusedItemNode)) {\n openSubmenu({ itemNode: pseudoFocusedItemNode, event });\n trackFocusFirstChildItem(pseudoFocusedItemNode);\n } else {\n // - Otherwise, activates the item...\n\n // ----------------------------------\n // 4. Although it is recommended that authors avoid doing so,\n // some implementations of navigation menubars may have menuitem elements that both perform a function and open a submenu.\n // In such implementations, Enter and Space perform a navigation function,\n // e.g., load new content, while Down Arrow, in a horizontal menubar, opens the submenu associated with that same menuitem.\n // ---------------------------------\n // Based on an investigation, the above statement is not specific to \"navigation\" nor to ONLY \"menubars\", it really is about \"menuitems\" in general\n // as long as the role=\"menuitem\" & aria-haspopup=\"${id-of-the-submenu}\" & aria-expanded=\"${true/false}\" (& aria-orientation=\"vertical/horizontal\" if non-default)\n // are set, the Screen Readers will provide the same announcement for the menuitem regardless of the parent role\n\n // \"activation\" is a concept,\n // WCAG here implies that for menuitemscheckbox and menuitemsradio this triggers the selection\n // for menuitems (that doesn't fit selection nor submenus) it triggers the action\n // this also triggers enter -> single-select-item-with-submenu as expected\n if (isMultipleSelectNode(pseudoFocusedItemNode)) {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n const newSelection = getNewSelectionMultipleSelect(selectedNodes!, pseudoFocusedItemNode);\n onItemSelected!(newSelection, { itemNode: pseudoFocusedItemNode, event });\n } else if (isSingleSelectNode(pseudoFocusedItemNode)) {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n const newSelection = getNewSelectionSingleSelect(selectedNodes!, pseudoFocusedItemNode);\n onItemSelected!(newSelection, { itemNode: pseudoFocusedItemNode, event });\n } else {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n onActivateItem!(pseudoFocusedItemNode, { itemNode: pseudoFocusedItemNode, event });\n }\n invokeItemOnClickOnKeyboardActivation(pseudoFocusedItemNode, event);\n // ... and closes the menu.\n const metainfo: SubmenuChangeMetainfo = { itemNode: pseudoFocusedItemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n onOpinionatedClose({ reason: 'item-activation', event });\n }\n },\n [\n trackFocusFirstChildItem,\n openSubmenu,\n handleChangeOpenedSubItems,\n onOpinionatedClose,\n selectedNodes,\n onItemSelected,\n onActivateItem,\n ],\n );\n const handleMenuItemSpaceKeyDown = React.useCallback(\n ({ pseudoFocusedItemNode, event }: ItemKeydownHelpersArgs) => {\n // Space:\n // [X] (Optional): When focus is on a menuitem that has a submenu, opens the submenu and places focus on its first item.\n // ----------------------------------\n // 4. Although it is recommended that authors avoid doing so,\n // some implementations of navigation menubars may have menuitem elements that both perform a function and open a submenu.\n // In such implementations, Enter and Space perform a navigation function,\n // e.g., load new content, while Down Arrow, in a horizontal menubar, opens the submenu associated with that same menuitem.\n // ---------------------------------\n // Based on an investigation, the above statement is not specific to \"navigation\" nor to ONLY \"menubars\", it really is about \"menuitems\" in general\n // as long as the role=\"menuitem\" & aria-haspopup=\"${id-of-the-submenu}\" & aria-expanded=\"${true/false}\" (& aria-orientation=\"vertical/horizontal\" if non-default)\n // are set, the Screen Readers will provide the same announcement for the menuitem regardless of the parent role\n if (isWithSubmenuOnlyNode(pseudoFocusedItemNode)) {\n openSubmenu({ itemNode: pseudoFocusedItemNode, event });\n trackFocusFirstChildItem(pseudoFocusedItemNode);\n return;\n }\n // [X] (Optional): When focus is on a menuitemcheckbox, changes the state without closing the menu.\n if (isMultipleSelectNode(pseudoFocusedItemNode)) {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n const newSelection = getNewSelectionMultipleSelect(selectedNodes!, pseudoFocusedItemNode);\n onItemSelected!(newSelection, { itemNode: pseudoFocusedItemNode, event });\n invokeItemOnClickOnKeyboardActivation(pseudoFocusedItemNode, event);\n return;\n }\n // [X] (Optional): When focus is on a menuitemradio that is not checked, without closing the menu,\n // checks the focused menuitemradio and unchecks any other checked menuitemradio element in the same group.\n if (isSingleSelectNode(pseudoFocusedItemNode)) {\n // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator\n // useAdvancedValidation guarantees the non-null in this \"if\" branch\n const newSelection = getNewSelectionSingleSelect(selectedNodes!, pseudoFocusedItemNode);\n onItemSelected!(newSelection, { itemNode: pseudoFocusedItemNode, event });\n invokeItemOnClickOnKeyboardActivation(pseudoFocusedItemNode, event);\n return;\n }\n // [X] (Optional): When focus is on a menuitem that does not have a submenu, activates the menuitem and closes the menu.\n onActivateItem?.(pseudoFocusedItemNode, { itemNode: pseudoFocusedItemNode, event });\n invokeItemOnClickOnKeyboardActivation(pseudoFocusedItemNode, event);\n\n const metainfo: SubmenuChangeMetainfo = { itemNode: pseudoFocusedItemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n onOpinionatedClose({ reason: 'item-activation', event });\n },\n [\n onActivateItem,\n handleChangeOpenedSubItems,\n onOpinionatedClose,\n trackFocusFirstChildItem,\n openSubmenu,\n selectedNodes,\n onItemSelected,\n ],\n );\n const handleMenuItemRightArrowKeyDown = React.useCallback(\n ({ pseudoFocusedItemNode, event }: ItemKeydownHelpersArgs) => {\n // Right Arrow:\n // [N/A] When focus is in a menubar, moves focus to the next item, optionally wrapping from the last to the first.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n\n // [X] When focus is in a menu and on a menuitem that has a submenu, opens the submenu and places focus on its first item.\n // [N/A] When focus is in a menu and on an item that does not have a submenu, performs the following 3 actions:\n // [N/A] Closes the submenu and any parent menus.\n // [N/A] Moves focus to the next item in the menubar.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n\n // [X] If focus is now on a menuitem with a submenu, either:\n // [X] (Recommended) opens the submenu of that menuitem without moving focus into the submenu,\n // /\\ we choose the recommended option\n // OR\n // [N/A] opens the submenu of that menuitem and places focus on the first item in the submenu.\n // ***********************************************************\n // Dimsum implements IoC, if APP side for whatever reason wants to open the new sub sub menu,\n // it's up to them to listen to the pseudo focus event and open the sub sub menu\n // ***********************************************************\n if (isWithSubmenuNode(pseudoFocusedItemNode)) {\n openSubmenu({ itemNode: pseudoFocusedItemNode, event });\n trackFocusFirstChildItem(pseudoFocusedItemNode);\n }\n // Note that if the menubar were not present, e.g., the menus were opened from a menubutton,\n // Right Arrow would not do anything when focus is on an item that does not have a submenu.\n // \"Does nothing\" is still a demand on whoever is around the menu: the key is consumed on every item,\n // see handleFocusableMenuItemKeyDown.\n },\n [openSubmenu, trackFocusFirstChildItem],\n );\n\n const handleMenuItemLeftArrowKeyDown = React.useCallback(\n ({ pseudoFocusedItemNode, event }: ItemKeydownHelpersArgs) => {\n // Left Arrow:\n // [N/A] When focus is in a menubar, moves focus to the previous item, optionally wrapping from the first to the last.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n\n // [X] When focus is in a submenu of an item in a menu, closes the submenu and returns focus to the parent menuitem.\n // on the main menu there is no submenu to leave and nothing else happens; the key is still consumed, see\n // handleFocusableMenuItemKeyDown\n const { currentSubmenuWasMainMenu } = closeCurrentSubmenu({ itemNode: pseudoFocusedItemNode, event });\n if (!currentSubmenuWasMainMenu) {\n trackFocusParentItem(pseudoFocusedItemNode);\n }\n\n // [N/A] When focus is in a submenu of an item in a menubar, performs the following 3 actions:\n // [N/A] Closes the submenu.\n // [N/A] Moves focus to the previous item in the menubar.\n // [N/A] If focus is now on a menuitem with a submenu, either:\n // (Recommended) opens the submenu of that menuitem without moving focus into the submenu,\n // or\n // opens the submenu of that menuitem and places focus on the first item in the submenu.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n },\n [closeCurrentSubmenu, trackFocusParentItem],\n );\n\n /*\n * TAB (APG): \"When focus is on a menuitem in a menu or menubar, move focus out of the menu or menubar, and close\n * all menus and submenus.\"\n *\n * Tab is an event of the TRIGGER, not of the items. The menu is the trigger's contextual child (it only lives in a\n * portal to solve z-index/visual issues): real browser focus sits on the items \u2014 instead of a simulated\n * pseudo-focus \u2014 so assistive technologies announce them, but to the browser the Tab must behave as if focus never\n * left the trigger. So the items do not take part in it at all (their own `onKeyDown` is not invoked for Tab) and\n * it cannot be altered from them: it is handled in the CAPTURE phase of the root menu, before anything else can\n * stop or alter the event.\n *\n * The ONE place in this widget where focus is moved from a handler instead of the focus tracker's ref callbacks \u2014\n * on purpose (see KNOWN_INTENTIONAL_DEVIATIONS.md, \"Tab moves focus from the keydown handler\"). Tab/Shift+Tab have\n * a browser DEFAULT ACTION that runs right after the keydown handlers: it moves focus on from wherever focus is at\n * that moment. Anything that moves focus later (tracker write -> render -> ref callback, throttled or deferred) is\n * too late: the default has already moved on from the (about to unmount) item and focus ends on the body (Tab) or\n * after the menu (Shift+Tab). So: focus the trigger ONCE, synchronously, and let the browser take over from there\n * (next tabbable for Tab, previous for Shift+Tab).\n */\n const handleMenuTabKeyDownCapture = React.useCallback<React.KeyboardEventHandler<HTMLElement>>(\n (event) => {\n if (event.key !== 'Tab') return;\n buttonDOMNodeRef.current?.focus();\n // focus is about to leave the whole button navigation for another element of the page: neutralize the focus\n // tracker (\"nothing to focus\") so nothing in it can ever steal the focus back\n trackFocusRegionReset();\n onOpinionatedClose({ skipFocus: true, reason: 'tab', event });\n },\n [buttonDOMNodeRef, onOpinionatedClose, trackFocusRegionReset],\n );\n\n const handleFocusableMenuItemKeyDown = React.useCallback<React.KeyboardEventHandler<HTMLDivElement>>(\n (event) => {\n // TAB is handled in the CAPTURE phase of the root menu (`handleMenuTabKeyDownCapture`, above): by the time this\n // handler runs, the trigger already holds focus and the tracker/menu state already moved on\n if (event.key === 'Tab') return;\n // A key the menu USES is consumed: preventDefault + stopPropagation. React bubbles synthetic events through the\n // portal, so without this an ancestor that owns the same key (a toolbar moving focus with Home/End/Left/Right, a\n // dialog closing on Escape...) would act on it too and pull focus out of the open menu. The old\n // DSDropdownMenuV2 listbox stopped every key it handled for the same reason.\n // A key that does nothing for the focused item is NOT consumed (activation keys on a locked item, any key the\n // menu has no use for): it keeps reaching the container.\n // EXCEPTION: Left and Right Arrow are consumed on EVERY item, also where the menu has nothing to do with them\n // (Right on an item without a submenu, Left on the main menu, locked items). APG, toolbar example, keyboard\n // support table (https://www.w3.org/WAI/ARIA/apg/patterns/toolbar/examples/toolbar/): for both Right Arrow and\n // Left Arrow it says \"If an item in the popup menu has focus, does nothing.\" A menu button in a toolbar is\n // exactly that case, and the pattern itself demands the toolbar does not act on the key: for that to be true\n // the key must not bubble out of the popup (React bubbles synthetic events through the portal) nor trigger\n // its default.\n const consumeKey = () => {\n event.preventDefault(); // if scrollbar are present, a consumed key should not interact with the scrollbar\n event.stopPropagation();\n };\n const pseudoFocusedItemNode = focusedElementItemNode.current;\n // if there is no focused item, we can't handle the logics\n if (pseudoFocusedItemNode === null) throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_NODE_NOT_SET;\n // if the item contains an `onKeyDown` prop, we trigger it, but a locked item (disabled or applyAriaDisabled)\n // does not get Enter/Space\n const isLockedActivation = isItemLocked(pseudoFocusedItemNode.plainItem) && isActivationKey(event);\n if (pseudoFocusedItemNode.plainItem.onKeyDown && !isLockedActivation)\n pseudoFocusedItemNode.plainItem.onKeyDown(event);\n // then the menu-level counterpart (`onItemKeyDown`), still before the menu handles or consumes the key: it is how a\n // host that wants menubar behaviour reads the Left/Right that this menu consumes (they never bubble out of it).\n // `nestLevel` counts the submenus above the item (groups do not open a menu), 0 is the main menu\n if (onItemKeyDown) {\n onItemKeyDown({\n itemNode: pseudoFocusedItemNode,\n event,\n nestLevel: getSubMenusPath(pseudoFocusedItemNode).length,\n hasSubmenu: isWithSubmenuNode(pseudoFocusedItemNode),\n });\n }\n // Down Arrow:\n // [N/A] When focus is on a menuitem in a menubar, and that menuitem has a submenu, opens the submenu and places focus on the first item in the submenu.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n // [X] When focus is in a menu, moves focus to the next item,\n // [X] optionally wrapping from the last to the first.\n if (event.key === 'ArrowDown') {\n consumeKey();\n trackFocusNextItem(pseudoFocusedItemNode);\n return;\n }\n // Up Arrow:\n // [X] When focus is in a menu, moves focus to the previous item,\n // [X] optionally wrapping from the first to the last.\n // [N/A] (Optional): When focus is on a menuitem in a menubar, and that menuitem has a submenu, opens the submenu and places focus on the last item in the submenu.\n // /\\ Not relevant for this component, this is ONLY FOR MENU, not for MENUBARS\n if (event.key === 'ArrowUp') {\n consumeKey();\n trackFocusPreviousItem(pseudoFocusedItemNode);\n return;\n }\n // Left Arrow: consumed on every item (see the APG note above), also on a locked one\n if (event.key === 'ArrowLeft') {\n consumeKey();\n handleMenuItemLeftArrowKeyDown({ pseudoFocusedItemNode, event });\n return;\n }\n // Right Arrow: consumed on every item (see the APG note above); a disabled item does not open its submenu\n // (PUI-16695), a soft-locked one (applyAriaDisabled) still does\n if (event.key === 'ArrowRight') {\n consumeKey();\n if (!isItemDisabled(pseudoFocusedItemNode.plainItem))\n handleMenuItemRightArrowKeyDown({ pseudoFocusedItemNode, event });\n return;\n }\n // Home: If arrow key wrapping is not supported, moves focus to the first item in the current menu or menubar.\n if (event.key === 'Home') {\n if (!pseudoFocusedItemNode.parent) {\n console.log('handleFocusableMenuItemKeyDown -> Home > focused item node', pseudoFocusedItemNode);\n // should be impossible, at most the .parent is the root node, which is not able to trigger this event\n throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_HAS_NO_PARENT;\n }\n consumeKey();\n trackFocusFirstChildItem(pseudoFocusedItemNode.parent);\n return;\n }\n // End: If arrow key wrapping is not supported, moves focus to the last item in the current menu or menubar.\n if (event.key === 'End') {\n if (!pseudoFocusedItemNode.parent) {\n console.log('handleFocusableMenuItemKeyDown -> Home > focused item node', pseudoFocusedItemNode);\n // should be impossible, at most the .parent is the root node, which is not able to trigger this event\n throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_HAS_NO_PARENT;\n }\n consumeKey();\n trackFocusLastChildItem(pseudoFocusedItemNode.parent);\n return;\n }\n if (event.key === 'Escape') {\n // an item only receives keys while the menu is open: the menu consumes this Escape, so it must not also reach\n // an ancestor that closes on Escape (DSDialog, DSModalSlide... React bubbles through portals) \u2014 the old\n // DSDropdownMenuV2 listbox stopped every key here for the same reason\n event.stopPropagation();\n // if the item has no submenu, the alt key is transparent, we behave as if it's not even pressed\n if (event.altKey && isWithSubmenuNode(pseudoFocusedItemNode)) {\n // PUI-14639 - Implement submenu dismissal mechanism\n // Description: we need to add a mechanism to close submenus that automatically expand when a menu item is focused with the keyboard.\n // we have decided to implement a special shortcut (Alt/Option + Esc) as the dismissal mechanism.\n // This change is necessary to comply with WCAG success criterion 1.4.13.\n // https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus.html\n // if the item has a submenu, we close it\n closeSubmenusAfterNode({ itemNode: pseudoFocusedItemNode, event });\n return;\n }\n // Escape: Close the menu that contains focus and return focus to the element or context, e.g., menu button or parent menuitem, from which the menu was opened\n const { currentSubmenuWasMainMenu } = closeCurrentSubmenu({ itemNode: pseudoFocusedItemNode, event });\n if (currentSubmenuWasMainMenu) {\n // if the menu we are trying to close is the main menu, we additionally close the main menu itself\n // we focus the trigger immediately (shouldFocusImmediately: true) so the focus return is synchronous\n // and not deferred to requestAnimationFrame \u2014 Escape on the trigger is safe since it only calls\n // onOpinionatedClose() which is already a no-op when the menu is closed\n trackFocusTrigger({ shouldFocusImmediately: true });\n onOpinionatedClose({ skipFocus: true, reason: 'escape', event });\n } else {\n trackFocusParentItem(pseudoFocusedItemNode);\n }\n return;\n }\n\n /* ************************************************************************************\n * ******* ACTIVATION & SUBMENU keys doesn't apply if the item is \"locked\" **********\n * ************************************************************************************ */\n if (isItemLocked(pseudoFocusedItemNode.plainItem)) return;\n // Enter:\n if (event.key === 'Enter') {\n event.stopPropagation(); // activation is ours; the browser default of Enter is left alone (custom item renderers may rely on it)\n handleMenuItemEnterKeyDown({ pseudoFocusedItemNode, event });\n return;\n }\n // Space:\n if (event.key === ' ') {\n consumeKey();\n handleMenuItemSpaceKeyDown({ pseudoFocusedItemNode, event });\n return;\n }\n },\n [\n focusedElementItemNode,\n onItemKeyDown,\n trackFocusTrigger,\n trackFocusNextItem,\n trackFocusPreviousItem,\n handleMenuItemLeftArrowKeyDown,\n trackFocusFirstChildItem,\n trackFocusLastChildItem,\n closeCurrentSubmenu,\n trackFocusParentItem,\n closeSubmenusAfterNode,\n onOpinionatedClose,\n handleMenuItemEnterKeyDown,\n handleMenuItemSpaceKeyDown,\n handleMenuItemRightArrowKeyDown,\n ],\n );\n const handleFocusableMenuItemClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement>) => {\n const pseudoFocusedItemNode = focusedElementItemNode.current;\n if (pseudoFocusedItemNode === null) throw UNEXPECTED_INTERNAL_ERRORS.FOCUSED_ITEM_NODE_NOT_SET;\n // if the item is locked (disabled or applyAriaDisabled), we don't do anything\n if (isItemLocked(pseudoFocusedItemNode.plainItem)) return;\n // we need to handle which submenu needs to close automagically based on the click\n // starting from the itemNode, we check:\n // - the parent of the itemNode is root?\n // - yes -> we close all the submenus\n const parentMenuNode = pseudoFocusedItemNode.parent;\n if (isRootNode(parentMenuNode)) {\n const metainfo: SubmenuChangeMetainfo = { itemNode: pseudoFocusedItemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n } else {\n // - no -> we close all the submenus that are not in the path to the root of the itemNode\n // this is necessary on click because the user can still interact with other (visual) depths of the menu\n // during keyboard navigation, the user is limited to the current (visual) depth\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [...getSubMenusPath(pseudoFocusedItemNode)];\n // - if the clicked node has a submenu, keep it open\n if (isWithSubmenuNode(pseudoFocusedItemNode)) {\n newOpenedItems.push(pseudoFocusedItemNode);\n }\n const metainfo: SubmenuChangeMetainfo = { itemNode: pseudoFocusedItemNode, event };\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n }\n\n // to all effects and purposes, the click event is the same as the space key\n // the main difference between enter and space is that\n // - enter ALWAYS closes the menu excepts for submenus\n // - space closes the menu if \"activable\", selections doesn't, submenus doesn't\n handleMenuItemSpaceKeyDown({ pseudoFocusedItemNode, event });\n // if the item contains an `onClick` prop, we trigger it\n if (pseudoFocusedItemNode.plainItem.onClick) pseudoFocusedItemNode.plainItem.onClick(event);\n },\n [focusedElementItemNode, handleMenuItemSpaceKeyDown, handleChangeOpenedSubItems],\n );\n\n // the \"menu-button\" widget is an opinionated widget with a specific behaviour to follow when a focusable item is \"focused\"\n // this function achieve the opinionated \"focus an item\" opinionated behaviour (regardless of why the item is focused)\n const opinionatedFocusBehaviour = React.useCallback(\n // we currently know only one \"event\" that can trigger this opinionated behaviour\n // - focus => React.FocusEvent <-- triggered by ATs \"focus mode\" or \"virtual cursor\" navigation\n // NOTE:\n // mouseEnter => React.MouseEvent\n // still ends up calling this function, but as a side effect of mouse-enter focusing the item, not as the main event\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes, event: React.FocusEvent) => {\n if (!isFocusableNode(itemNode)) {\n console.log('handleFocusableMenuItemOnMouseEnter > itemNode:', itemNode);\n throw FORBIDDEN_BEHAVIOURS.TRYING_TO_FOCUS_NON_FOCUSABLE_NODE;\n }\n // on hover -> we track the hovered item as the focused one on top of which events should work on\n trackFocusNode(itemNode);\n if (!isWithSubmenuNode(itemNode)) {\n // if the item has nosubmenu we close all the siblings submenus\n const subMenuNodesPath = getSubMenusPath(itemNode);\n const metainfo: SubmenuChangeMetainfo = { itemNode, event };\n const newOpenedItems: DSMenuButtonT.WithSubmenuMenuNodes[] = [...subMenuNodesPath];\n handleChangeOpenedSubItems(newOpenedItems, metainfo);\n return;\n }\n // if the item is disabled (hard lock, PUI-16695), we don't open the submenu, and there is nothing else to do.\n // a soft-locked item (applyAriaDisabled) still opens it: the submenu is a view-only popup\n if (isItemDisabled(itemNode.plainItem)) return;\n // if not disabled and it has a submenu, we open it, and there is nothing else to do\n openSubmenu({ itemNode, event });\n },\n [handleChangeOpenedSubItems, openSubmenu, trackFocusNode],\n );\n\n // when an item is hovered, we focus it\n // this effectively achieves:\n // - the item is focused (it trigger the handleFocusableMenuItemNativeFocusEvent function because render runs node.focus())\n // - if the user presses a keyboard key, the interaction will work starting from the (hovered hence focused) item\n const handleFocusableMenuItemOnMouseEnter = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes) => {\n if (!isFocusableNode(itemNode)) {\n console.log('handleFocusableMenuItemOnMouseEnter > itemNode:', itemNode);\n throw FORBIDDEN_BEHAVIOURS.TRYING_TO_FOCUS_NON_FOCUSABLE_NODE;\n }\n // on hover -> we track the hovered item as the focused one on top of which events should work on\n trackFocusNode(itemNode);\n },\n [trackFocusNode],\n );\n\n const handleFocusableMenuItemNativeFocusEvent = React.useCallback(\n (itemNode: DSMenuButtonT.PseudoFocusableMenuNodes, event: React.FocusEvent) => {\n opinionatedFocusBehaviour(itemNode, event);\n },\n [opinionatedFocusBehaviour],\n );\n\n return React.useMemo(\n () => ({\n handleMenuTabKeyDownCapture,\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemClick,\n handleFocusableMenuItemOnMouseEnter,\n handleFocusableMenuItemNativeFocusEvent,\n }),\n [\n handleMenuTabKeyDownCapture,\n handleFocusableMenuItemClick,\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemNativeFocusEvent,\n handleFocusableMenuItemOnMouseEnter,\n ],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADMvB,8BAAgC;AAChC,mBAAkB;AAElB,uCASO;AACP,oBAAiE;AAEjE,sCAA8C;AAC9C,oCAAgC;AAChC,oCAA4C;AAuB5C,MAAM,wCAAwC,CAC5C,uBACA,UACG;AACH,MAAI,OAAO,SAAS,aAAa,sBAAsB,UAAU;AAC/D,0BAAsB,UAAU,QAAQ,KAA4B;AACxE;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A,cAAI,iDAAe,SAAS,SAAS,EAAG;AAExC,kBAAY,EAAE,UAAU,MAAM,CAAC;AAAA,IACjC;AAAA,IACA,CAAC,4BAA4B,aAAa,cAAc;AAAA,EAC1D;AAMA,QAAM,sCAAsC,aAAAA,QAAM;AAAA,IAChD,CAAC,aAAqD;AACpD,UAAI,KAAC,kDAAgB,QAAQ,GAAG;AAC9B,gBAAQ,IAAI,mDAAmD,QAAQ;AACvE,cAAM,mCAAqB;AAAA,MAC7B;AAEA,qBAAe,QAAQ;AAAA,IACzB;AAAA,IACA,CAAC,cAAc;AAAA,EACjB;AAEA,QAAM,0CAA0C,aAAAA,QAAM;AAAA,IACpD,CAAC,UAAkD,UAA4B;AAC7E,gCAA0B,UAAU,KAAK;AAAA,IAC3C;AAAA,IACA,CAAC,yBAAyB;AAAA,EAC5B;AAEA,SAAO,aAAAA,QAAM;AAAA,IACX,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": ["React"]
7
7
  }
@@ -35,22 +35,28 @@ var React = __toESM(require("react"));
35
35
  var import_react = __toESM(require("react"));
36
36
  const useMenuOpenStatus = ({ propsWithDefault, focusTrackers }) => {
37
37
  const { trackFocusTrigger, trackFocusFirstChildItem, trackFocusLastChildItem, preventBlurReset } = focusTrackers;
38
- const { onClose, onOpen, optionsTree } = propsWithDefault;
39
- const [isMenuOpen, setIsMenuOpen] = import_react.default.useState(false);
38
+ const { onClose, onOpen, optionsTree, a11yDangerouslyConsumerOwnedMenuOpenState } = propsWithDefault;
39
+ const [internalIsMenuOpen, setIsMenuOpen] = import_react.default.useState(false);
40
+ const isMenuOpen = a11yDangerouslyConsumerOwnedMenuOpenState ?? internalIsMenuOpen;
41
+ const isMenuOpenRef = import_react.default.useRef(isMenuOpen);
42
+ isMenuOpenRef.current = isMenuOpen;
43
+ const openIntentPendingRef = import_react.default.useRef(false);
40
44
  const onOpinionatedClose = import_react.default.useCallback(
41
- ({ skipFocus } = { skipFocus: false }) => {
45
+ ({ skipFocus = false, reason, event }) => {
46
+ if (!isMenuOpenRef.current) return;
47
+ openIntentPendingRef.current = false;
42
48
  setIsMenuOpen(false);
43
- if (onClose) onClose();
49
+ if (onClose) onClose({ reason, event });
44
50
  if (!skipFocus) trackFocusTrigger();
45
51
  preventBlurReset.current = false;
46
52
  },
47
53
  [onClose, preventBlurReset, trackFocusTrigger]
48
54
  );
49
55
  const onOpinionatedOpen = import_react.default.useCallback(
50
- (config) => {
51
- const { focusLastChild = false } = config || {};
56
+ ({ focusLastChild = false, reason, event }) => {
57
+ if (onOpen && !isMenuOpenRef.current) onOpen({ reason, event });
52
58
  setIsMenuOpen(true);
53
- if (onOpen) onOpen();
59
+ openIntentPendingRef.current = true;
54
60
  const typeCastedOptionsTree = optionsTree;
55
61
  if (focusLastChild) trackFocusLastChildItem(typeCastedOptionsTree);
56
62
  else trackFocusFirstChildItem(typeCastedOptionsTree);
@@ -59,7 +65,7 @@ const useMenuOpenStatus = ({ propsWithDefault, focusTrackers }) => {
59
65
  [onOpen, optionsTree, preventBlurReset, trackFocusFirstChildItem, trackFocusLastChildItem]
60
66
  );
61
67
  return import_react.default.useMemo(
62
- () => ({ isMenuOpen, onOpinionatedClose, onOpinionatedOpen }),
68
+ () => ({ isMenuOpen, onOpinionatedClose, onOpinionatedOpen, openIntentPendingRef }),
63
69
  [isMenuOpen, onOpinionatedClose, onOpinionatedOpen]
64
70
  );
65
71
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/parts/DSMenuBehaviouralContextProvider/config/useMenuOpenStatus.ts", "../../../../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["import React from 'react';\nimport { type DSMenuButtonT } from '../../../react-desc-prop-types.js';\nimport { type DSMenuBehaviouralContextProviderT } from '../react-desc-prop-types.js';\nimport type { useFocusTracker } from './useFocusTracker.js';\n\ntype UseMenuOpenStatusConfig = {\n propsWithDefault: DSMenuBehaviouralContextProviderT.InternalProps;\n focusTrackers: ReturnType<typeof useFocusTracker>;\n};\n\ntype OnOpinionatedOpenConfig = {\n focusLastChild?: boolean;\n};\n\nexport const useMenuOpenStatus = ({ propsWithDefault, focusTrackers }: UseMenuOpenStatusConfig) => {\n // when the menu closes the focus must be returned to the trigger\n const { trackFocusTrigger, trackFocusFirstChildItem, trackFocusLastChildItem, preventBlurReset } = focusTrackers;\n const { onClose, onOpen, optionsTree } = propsWithDefault;\n const [isMenuOpen, setIsMenuOpen] = React.useState(false);\n\n const onOpinionatedClose = React.useCallback(\n ({ skipFocus } = { skipFocus: false }) => {\n setIsMenuOpen(false);\n if (onClose) onClose();\n if (!skipFocus) trackFocusTrigger();\n preventBlurReset.current = false;\n },\n [onClose, preventBlurReset, trackFocusTrigger],\n );\n\n const onOpinionatedOpen = React.useCallback(\n (config?: OnOpinionatedOpenConfig) => {\n const { focusLastChild = false } = config || {};\n setIsMenuOpen(true);\n if (onOpen) onOpen();\n // Focus on the first item\n // this conversion is a unsafe but that's because we are handling the treeroot node\n // and DSTree doesn't have direct support for typescript tree-root interfaces being different from the rest of the tree\n // the function trackFocusLastChildItem takes any MenuNode and generates the list from subitems autonomously\n // except for the \"trigger\" scenario, we always expect to invoke this function with a PseudoFocusableMenuNodes\n // so we typecast here instead of losing the type safety in the rest of the code\n const typeCastedOptionsTree = optionsTree as DSMenuButtonT.PseudoFocusableMenuNodes;\n if (focusLastChild) trackFocusLastChildItem(typeCastedOptionsTree);\n else trackFocusFirstChildItem(typeCastedOptionsTree);\n preventBlurReset.current = true;\n },\n [onOpen, optionsTree, preventBlurReset, trackFocusFirstChildItem, trackFocusLastChildItem],\n );\n\n return React.useMemo(\n () => ({ isMenuOpen, onOpinionatedClose, onOpinionatedOpen }),\n [isMenuOpen, onOpinionatedClose, onOpinionatedOpen],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAkB;AAcX,MAAM,oBAAoB,CAAC,EAAE,kBAAkB,cAAc,MAA+B;AAEjG,QAAM,EAAE,mBAAmB,0BAA0B,yBAAyB,iBAAiB,IAAI;AACnG,QAAM,EAAE,SAAS,QAAQ,YAAY,IAAI;AACzC,QAAM,CAAC,YAAY,aAAa,IAAI,aAAAA,QAAM,SAAS,KAAK;AAExD,QAAM,qBAAqB,aAAAA,QAAM;AAAA,IAC/B,CAAC,EAAE,UAAU,IAAI,EAAE,WAAW,MAAM,MAAM;AACxC,oBAAc,KAAK;AACnB,UAAI,QAAS,SAAQ;AACrB,UAAI,CAAC,UAAW,mBAAkB;AAClC,uBAAiB,UAAU;AAAA,IAC7B;AAAA,IACA,CAAC,SAAS,kBAAkB,iBAAiB;AAAA,EAC/C;AAEA,QAAM,oBAAoB,aAAAA,QAAM;AAAA,IAC9B,CAAC,WAAqC;AACpC,YAAM,EAAE,iBAAiB,MAAM,IAAI,UAAU,CAAC;AAC9C,oBAAc,IAAI;AAClB,UAAI,OAAQ,QAAO;AAOnB,YAAM,wBAAwB;AAC9B,UAAI,eAAgB,yBAAwB,qBAAqB;AAAA,UAC5D,0BAAyB,qBAAqB;AACnD,uBAAiB,UAAU;AAAA,IAC7B;AAAA,IACA,CAAC,QAAQ,aAAa,kBAAkB,0BAA0B,uBAAuB;AAAA,EAC3F;AAEA,SAAO,aAAAA,QAAM;AAAA,IACX,OAAO,EAAE,YAAY,oBAAoB,kBAAkB;AAAA,IAC3D,CAAC,YAAY,oBAAoB,iBAAiB;AAAA,EACpD;AACF;",
4
+ "sourcesContent": ["import React from 'react';\nimport { type DSMenuButtonT } from '../../../react-desc-prop-types.js';\nimport { type DSMenuBehaviouralContextProviderT } from '../react-desc-prop-types.js';\nimport type { useFocusTracker } from './useFocusTracker.js';\n\ntype UseMenuOpenStatusConfig = {\n propsWithDefault: DSMenuBehaviouralContextProviderT.InternalProps;\n focusTrackers: ReturnType<typeof useFocusTracker>;\n};\n\ntype OnOpinionatedOpenConfig = {\n focusLastChild?: boolean;\n reason: DSMenuButtonT.MenuOpenReason;\n event?: DSMenuButtonT.MenuOpenMetainfo['event'];\n};\n\ntype OnOpinionatedCloseConfig = {\n skipFocus?: boolean;\n reason: DSMenuButtonT.MenuCloseReason;\n event?: DSMenuButtonT.MenuCloseMetainfo['event'];\n};\n\nexport const useMenuOpenStatus = ({ propsWithDefault, focusTrackers }: UseMenuOpenStatusConfig) => {\n // when the menu closes the focus must be returned to the trigger\n const { trackFocusTrigger, trackFocusFirstChildItem, trackFocusLastChildItem, preventBlurReset } = focusTrackers;\n const { onClose, onOpen, optionsTree, a11yDangerouslyConsumerOwnedMenuOpenState } = propsWithDefault;\n const [internalIsMenuOpen, setIsMenuOpen] = React.useState(false);\n /*\n * Escape hatch (a11yDangerouslyConsumerOwnedMenuOpenState): when the consumer provides a boolean\n * they own the effective open state \u2014 this resolved value is the single source of truth read by\n * the flyout visibility, the floating context's `externallyControlledIsOpen` and the trigger's\n * open/close toggle check, so consumer-ownership propagates through the already-controlled paths.\n * The intents below still fire `onOpen`/`onClose` (+ focus tracking) so the consumer can sync;\n * if they don't, the documented trade-off applies: focus may leave a panel that stays open.\n */\n const isMenuOpen = a11yDangerouslyConsumerOwnedMenuOpenState ?? internalIsMenuOpen;\n // read through a ref to keep `onOpinionatedClose` referentially stable (it is a dependency of many handlers/effects)\n const isMenuOpenRef = React.useRef(isMenuOpen);\n isMenuOpenRef.current = isMenuOpen;\n /*\n * An open INTENT that already armed the focus tracker (trigger click / ArrowDown / ArrowUp) and whose menu has not\n * mounted yet. The tracker throttles its calls (50ms, last one wins), so the armed region may not be visible yet\n * when the menu mounts: this synchronous flag tells the root flyout \"the focus target is already decided, do not\n * decide a second one\" (otherwise ArrowUp -> last item would be overridden by the default \"first item\").\n */\n const openIntentPendingRef = React.useRef(false);\n\n const onOpinionatedClose = React.useCallback(\n ({ skipFocus = false, reason, event }: OnOpinionatedCloseConfig) => {\n // closing a menu that is not open is a no-op: no `onClose`, no focus change.\n // without this guard every closed instance reports a \"close intent\" on window blur / Escape on the trigger\n if (!isMenuOpenRef.current) return;\n openIntentPendingRef.current = false;\n setIsMenuOpen(false);\n if (onClose) onClose({ reason, event });\n if (!skipFocus) trackFocusTrigger();\n preventBlurReset.current = false;\n },\n [onClose, preventBlurReset, trackFocusTrigger],\n );\n\n const onOpinionatedOpen = React.useCallback(\n ({ focusLastChild = false, reason, event }: OnOpinionatedOpenConfig) => {\n // `onOpen` reports a closed -> open intent only; re-arming the focus while already open (ArrowDown/Up) is still allowed\n if (onOpen && !isMenuOpenRef.current) onOpen({ reason, event });\n setIsMenuOpen(true);\n openIntentPendingRef.current = true;\n // Focus on the first item\n // this conversion is a unsafe but that's because we are handling the treeroot node\n // and DSTree doesn't have direct support for typescript tree-root interfaces being different from the rest of the tree\n // the function trackFocusLastChildItem takes any MenuNode and generates the list from subitems autonomously\n // except for the \"trigger\" scenario, we always expect to invoke this function with a PseudoFocusableMenuNodes\n // so we typecast here instead of losing the type safety in the rest of the code\n const typeCastedOptionsTree = optionsTree as DSMenuButtonT.PseudoFocusableMenuNodes;\n if (focusLastChild) trackFocusLastChildItem(typeCastedOptionsTree);\n else trackFocusFirstChildItem(typeCastedOptionsTree);\n preventBlurReset.current = true;\n },\n [onOpen, optionsTree, preventBlurReset, trackFocusFirstChildItem, trackFocusLastChildItem],\n );\n\n return React.useMemo(\n () => ({ isMenuOpen, onOpinionatedClose, onOpinionatedOpen, openIntentPendingRef }),\n [isMenuOpen, onOpinionatedClose, onOpinionatedOpen],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAkB;AAsBX,MAA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6
  "names": ["React"]
7
7
  }
@@ -39,9 +39,11 @@ var import_MenuBehaviouralContextProviderCTX = require("../DSMenuBehaviouralCont
39
39
  var import_constants = require("../DSMenuBehaviouralContextProvider/constants/index.js");
40
40
  var import_focusNodeRacingConditionSolved = require("./focusNodeRacingConditionSolved.js");
41
41
  var import_MenuButtonContextProviderCTX = require("../../MenuButtonContextProviderCTX.js");
42
+ var import_nodesTypeguardsAndGetters = require("../../utils/nodesTypeguardsAndGetters.js");
42
43
  const ActivableMenuItem = ({ itemNode, ariaPosInSet, ariaSetSize }) => {
43
44
  const { dsId, plainItem } = itemNode;
44
45
  const { label, secondaryLabel, leftDecoration: LeftDecComponent, minWidth, disabled } = plainItem;
46
+ const locked = (0, import_nodesTypeguardsAndGetters.isItemLocked)(plainItem);
45
47
  const {
46
48
  ownerProps: { getOwnerProps }
47
49
  } = import_react.default.useContext(import_MenuButtonContextProviderCTX.MenuButtonContextProvider);
@@ -97,10 +99,11 @@ const ActivableMenuItem = ({ itemNode, ariaPosInSet, ariaSetSize }) => {
97
99
  id: `${spacelessDsIdForDom}`,
98
100
  role: "menuitem",
99
101
  tabIndex: isFocused ? 0 : -1,
100
- "aria-disabled": disabled,
102
+ "aria-disabled": locked ? true : void 0,
101
103
  "aria-posinset": ariaPosInSet,
102
104
  "aria-setsize": ariaSetSize,
103
- applyAriaDisabled: disabled,
105
+ applyAriaDisabled: locked,
106
+ $disabled: disabled,
104
107
  getOwnerProps,
105
108
  getOwnerPropsArguments,
106
109
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
@@ -130,7 +133,7 @@ const ActivableMenuItem = ({ itemNode, ariaPosInSet, ariaSetSize }) => {
130
133
  {
131
134
  getOwnerProps,
132
135
  getOwnerPropsArguments,
133
- disabled,
136
+ $disabled: locked,
134
137
  children: secondaryLabel
135
138
  }
136
139
  )
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/parts/DSMenuItemRendererFactory/ActivableMenuItem.tsx", "../../../../../../../scripts/build/transpile/react-shim.js"],
4
- "sourcesContent": ["/* eslint-disable max-lines */\nimport {\n StyleMenuItemLabel,\n StyleMenuItemSecondaryLabel,\n StyledContentWrapper,\n StyledGlobalMenuItemWrapper,\n} from '@elliemae/ds-menu-items-commons';\nimport React, { useCallback } from 'react';\nimport type { DSMenuButtonT } from '../../react-desc-prop-types.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { MENU_FOCUS_REGIONS } from '../DSMenuBehaviouralContextProvider/constants/index.js';\nimport { focusNodeRacingConditionSolved } from './focusNodeRacingConditionSolved.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nexport const ActivableMenuItem: React.ComponentType<{\n itemNode: DSMenuButtonT.MenuNodeActivableItem;\n ariaPosInSet?: number;\n ariaSetSize?: number;\n}> = ({ itemNode, ariaPosInSet, ariaSetSize }) => {\n const { dsId, plainItem } = itemNode;\n const { label, secondaryLabel, leftDecoration: LeftDecComponent, minWidth, disabled } = plainItem;\n\n const {\n ownerProps: { getOwnerProps },\n } = React.useContext(MenuButtonContextProvider);\n\n const getOwnerPropsArguments = useCallback(() => plainItem, [plainItem]);\n const {\n focusRegion,\n menuItemEventsHandlers: {\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemClick,\n handleFocusableMenuItemOnMouseEnter,\n handleFocusableMenuItemNativeFocusEvent,\n },\n } = React.useContext(MenuBehaviouralContextProviderContext);\n\n const gridLayout = React.useMemo(() => {\n const cols = LeftDecComponent ? ['min-content', 'auto'] : ['auto'];\n if (secondaryLabel) cols.push('auto');\n return cols;\n }, [LeftDecComponent, secondaryLabel]);\n\n const focusedRegionPerformanceHelper = React.useRef(focusRegion);\n focusedRegionPerformanceHelper.current = focusRegion;\n\n const isFocused = focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId);\n\n const handleFocusOnRender = React.useCallback(\n (node: HTMLDivElement) => {\n if (node && focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId)) {\n focusNodeRacingConditionSolved(node);\n }\n },\n // we need to change the callback reference every time the focusRegion changes or else the focus will not be set\n [dsId, focusRegion],\n // we are using the \"as='div'\", typescript is not able to infer the correct type\n // the logic here actually receives a ref to a HTMLDivElement,\n // but the component must think this is a HTMLLIElement ref callback\n ) as unknown as React.RefCallback<HTMLLIElement>;\n const handleOnMouseEnter = React.useCallback<React.MouseEventHandler<HTMLDivElement>>(() => {\n handleFocusableMenuItemOnMouseEnter(itemNode);\n }, [handleFocusableMenuItemOnMouseEnter, itemNode]);\n const handleOnFocus = React.useCallback<React.FocusEventHandler<HTMLDivElement>>(\n (e) => {\n handleFocusableMenuItemNativeFocusEvent(itemNode, e);\n },\n [handleFocusableMenuItemNativeFocusEvent, itemNode],\n );\n\n const spacelessDsIdForDom = `ds-menu-item-${`${dsId}`.replace(/\\s/g, '')}`;\n\n return (\n <StyledGlobalMenuItemWrapper\n innerRef={handleFocusOnRender}\n onKeyDown={handleFocusableMenuItemKeyDown}\n onClick={handleFocusableMenuItemClick}\n onMouseEnter={handleOnMouseEnter}\n onFocus={handleOnFocus}\n as=\"div\"\n id={`${spacelessDsIdForDom}`}\n role=\"menuitem\"\n tabIndex={isFocused ? 0 : -1}\n aria-disabled={disabled}\n aria-posinset={ariaPosInSet}\n aria-setsize={ariaSetSize}\n applyAriaDisabled={disabled}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <StyledContentWrapper\n cols={gridLayout}\n minHeight=\"16px\"\n gutter=\"xxs\"\n alignItems=\"center\"\n minWidth={minWidth ?? undefined}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n {LeftDecComponent ? <LeftDecComponent /> : null}\n <StyleMenuItemLabel\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n variant=\"b2\"\n component=\"span\"\n >\n {label}\n </StyleMenuItemLabel>\n {secondaryLabel !== undefined && (\n <StyleMenuItemSecondaryLabel\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n disabled={disabled}\n >\n {secondaryLabel}\n </StyleMenuItemSecondaryLabel>\n )}\n </StyledContentWrapper>\n </StyledGlobalMenuItemWrapper>\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADyFjB;AAxFN,mCAKO;AACP,mBAAmC;AAEnC,+CAAsD;AACtD,uBAAmC;AACnC,4CAA+C;AAC/C,0CAA0C;AACnC,MAAM,oBAIR,CAAC,EAAE,UAAU,cAAc,YAAY,MAAM;AAChD,QAAM,EAAE,MAAM,UAAU,IAAI;AAC5B,QAAM,EAAE,OAAO,gBAAgB,gBAAgB,kBAAkB,UAAU,SAAS,IAAI;AAExF,QAAM;AAAA,IACJ,YAAY,EAAE,cAAc;AAAA,EAC9B,IAAI,aAAAA,QAAM,WAAW,6DAAyB;AAE9C,QAAM,6BAAyB,0BAAY,MAAM,WAAW,CAAC,SAAS,CAAC;AACvE,QAAM;AAAA,IACJ;AAAA,IACA,wBAAwB;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,IAAI,aAAAA,QAAM,WAAW,8EAAqC;AAE1D,QAAM,aAAa,aAAAA,QAAM,QAAQ,MAAM;AACrC,UAAM,OAAO,mBAAmB,CAAC,eAAe,MAAM,IAAI,CAAC,MAAM;AACjE,QAAI,eAAgB,MAAK,KAAK,MAAM;AACpC,WAAO;AAAA,EACT,GAAG,CAAC,kBAAkB,cAAc,CAAC;AAErC,QAAM,iCAAiC,aAAAA,QAAM,OAAO,WAAW;AAC/D,iCAA+B,UAAU;AAEzC,QAAM,YAAY,gBAAgB,oCAAmB,aAAa,IAAI;AAEtE,QAAM,sBAAsB,aAA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A,gBAEC;AAAA;AAAA,YACH;AAAA;AAAA;AAAA,MAEJ;AAAA;AAAA,EACF;AAEJ;",
4
+ "sourcesContent": ["/* eslint-disable max-lines */\nimport {\n StyleMenuItemLabel,\n StyleMenuItemSecondaryLabel,\n StyledContentWrapper,\n StyledGlobalMenuItemWrapper,\n} from '@elliemae/ds-menu-items-commons';\nimport React, { useCallback } from 'react';\nimport type { DSMenuButtonT } from '../../react-desc-prop-types.js';\nimport { MenuBehaviouralContextProviderContext } from '../DSMenuBehaviouralContextProvider/MenuBehaviouralContextProviderCTX.js';\nimport { MENU_FOCUS_REGIONS } from '../DSMenuBehaviouralContextProvider/constants/index.js';\nimport { focusNodeRacingConditionSolved } from './focusNodeRacingConditionSolved.js';\nimport { MenuButtonContextProvider } from '../../MenuButtonContextProviderCTX.js';\nimport { isItemLocked } from '../../utils/nodesTypeguardsAndGetters.js';\nexport const ActivableMenuItem: React.ComponentType<{\n itemNode: DSMenuButtonT.MenuNodeActivableItem;\n ariaPosInSet?: number;\n ariaSetSize?: number;\n}> = ({ itemNode, ariaPosInSet, ariaSetSize }) => {\n const { dsId, plainItem } = itemNode;\n const { label, secondaryLabel, leftDecoration: LeftDecComponent, minWidth, disabled } = plainItem;\n // locked = disabled || applyAriaDisabled. aria-disabled is printed as \"true\" or not at all (never \"false\")\n const locked = isItemLocked(plainItem);\n\n const {\n ownerProps: { getOwnerProps },\n } = React.useContext(MenuButtonContextProvider);\n\n const getOwnerPropsArguments = useCallback(() => plainItem, [plainItem]);\n const {\n focusRegion,\n menuItemEventsHandlers: {\n handleFocusableMenuItemKeyDown,\n handleFocusableMenuItemClick,\n handleFocusableMenuItemOnMouseEnter,\n handleFocusableMenuItemNativeFocusEvent,\n },\n } = React.useContext(MenuBehaviouralContextProviderContext);\n\n const gridLayout = React.useMemo(() => {\n const cols = LeftDecComponent ? ['min-content', 'auto'] : ['auto'];\n if (secondaryLabel) cols.push('auto');\n return cols;\n }, [LeftDecComponent, secondaryLabel]);\n\n const focusedRegionPerformanceHelper = React.useRef(focusRegion);\n focusedRegionPerformanceHelper.current = focusRegion;\n\n const isFocused = focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId);\n\n const handleFocusOnRender = React.useCallback(\n (node: HTMLDivElement) => {\n if (node && focusRegion === MENU_FOCUS_REGIONS.ITEM_BY_DSID(dsId)) {\n focusNodeRacingConditionSolved(node);\n }\n },\n // we need to change the callback reference every time the focusRegion changes or else the focus will not be set\n [dsId, focusRegion],\n // we are using the \"as='div'\", typescript is not able to infer the correct type\n // the logic here actually receives a ref to a HTMLDivElement,\n // but the component must think this is a HTMLLIElement ref callback\n ) as unknown as React.RefCallback<HTMLLIElement>;\n const handleOnMouseEnter = React.useCallback<React.MouseEventHandler<HTMLDivElement>>(() => {\n handleFocusableMenuItemOnMouseEnter(itemNode);\n }, [handleFocusableMenuItemOnMouseEnter, itemNode]);\n const handleOnFocus = React.useCallback<React.FocusEventHandler<HTMLDivElement>>(\n (e) => {\n handleFocusableMenuItemNativeFocusEvent(itemNode, e);\n },\n [handleFocusableMenuItemNativeFocusEvent, itemNode],\n );\n\n const spacelessDsIdForDom = `ds-menu-item-${`${dsId}`.replace(/\\s/g, '')}`;\n\n return (\n <StyledGlobalMenuItemWrapper\n innerRef={handleFocusOnRender}\n onKeyDown={handleFocusableMenuItemKeyDown}\n onClick={handleFocusableMenuItemClick}\n onMouseEnter={handleOnMouseEnter}\n onFocus={handleOnFocus}\n as=\"div\"\n id={`${spacelessDsIdForDom}`}\n role=\"menuitem\"\n tabIndex={isFocused ? 0 : -1}\n aria-disabled={locked ? true : undefined}\n aria-posinset={ariaPosInSet}\n aria-setsize={ariaSetSize}\n applyAriaDisabled={locked}\n $disabled={disabled}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n <StyledContentWrapper\n cols={gridLayout}\n minHeight=\"16px\"\n gutter=\"xxs\"\n alignItems=\"center\"\n minWidth={minWidth ?? undefined}\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n >\n {LeftDecComponent ? <LeftDecComponent /> : null}\n <StyleMenuItemLabel\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n variant=\"b2\"\n component=\"span\"\n >\n {label}\n </StyleMenuItemLabel>\n {secondaryLabel !== undefined && (\n <StyleMenuItemSecondaryLabel\n getOwnerProps={getOwnerProps}\n getOwnerPropsArguments={getOwnerPropsArguments}\n $disabled={locked}\n >\n {secondaryLabel}\n </StyleMenuItemSecondaryLabel>\n )}\n </StyledContentWrapper>\n </StyledGlobalMenuItemWrapper>\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;AD6FjB;AA5FN,mCAKO;AACP,mBAAmC;AAEnC,+CAAsD;AACtD,uBAAmC;AACnC,4CAA+C;AAC/C,0CAA0C;AAC1C,uCAA6B;AACtB,MAAM,oBAIR,CAAC,EAAE,UAAU,cAAc,YAAY,MAAM;AAChD,QAAM,EAAE,MAAM,UAAU,IAAI;AAC5B,QAAM,EAAE,OAAO,gBAAgB,gBAAgB,kBAAkB,UAAU,SAAS,IAAI;AAExF,QAAM,aAAS,+CAAa,SAAS;AAErC,QAAM;AAAA,IACJ,YAAY,EAAE,cAAc;AAAA,EAC9B,IAAI,aAAAA,QAAM,WAAW,6DAAyB;AAE9C,QAAM,6BAAyB,0BAAY,MAAM,WAAW,CAAC,SAAS,CAAC;AACvE,QAAM;AAAA,IACJ;AAAA,IACA,wBAAwB;AAAA,MACtB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,IAAI,aAAAA,QAAM,WAAW,8EAAqC;AAE1D,QAAM,aAAa,aAAAA,QAAM,QAAQ,MAAM;AACrC,UAAM,OAAO,mBAAmB,CAAC,eAAe,MAAM,IAAI,CAAC,MAAM;AACjE,QAAI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