@linzjs/step-ag-grid 1.4.5 → 1.4.7

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 (85) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +284 -232
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/components/GridCell.d.ts +4 -3
  5. package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +8 -5
  6. package/dist/src/react-menu3/components/ControlledMenu.d.ts +8 -2
  7. package/dist/src/react-menu3/components/FocusableItem.d.ts +8 -0
  8. package/dist/src/react-menu3/components/Menu.d.ts +16 -2
  9. package/dist/src/react-menu3/components/MenuButton.d.ts +8 -1
  10. package/dist/src/react-menu3/components/MenuDivider.d.ts +2 -1
  11. package/dist/src/react-menu3/components/MenuGroup.d.ts +12 -2
  12. package/dist/src/react-menu3/components/MenuHeader.d.ts +4 -2
  13. package/dist/src/react-menu3/components/MenuItem.d.ts +56 -0
  14. package/dist/src/react-menu3/components/MenuList.d.ts +2 -29
  15. package/dist/src/react-menu3/components/MenuRadioGroup.d.ts +44 -2
  16. package/dist/src/react-menu3/components/SubMenu.d.ts +109 -0
  17. package/dist/src/react-menu3/hooks/useBEM.d.ts +4 -3
  18. package/dist/src/react-menu3/hooks/useCombinedRef.d.ts +2 -2
  19. package/dist/src/react-menu3/hooks/useItemEffect.d.ts +1 -1
  20. package/dist/src/react-menu3/hooks/useItemState.d.ts +4 -3
  21. package/dist/src/react-menu3/hooks/useItems.d.ts +6 -4
  22. package/dist/src/react-menu3/hooks/useMenuChange.d.ts +2 -1
  23. package/dist/src/react-menu3/hooks/useMenuState.d.ts +13 -10
  24. package/dist/src/react-menu3/hooks/useMenuStateAndFocus.d.ts +2 -10
  25. package/dist/src/react-menu3/index.d.ts +1 -0
  26. package/dist/src/react-menu3/positionUtils/getPositionHelpers.d.ts +10 -9
  27. package/dist/src/react-menu3/positionUtils/placeArrowHorizontal.d.ts +7 -6
  28. package/dist/src/react-menu3/positionUtils/placeArrowVertical.d.ts +7 -6
  29. package/dist/src/react-menu3/positionUtils/placeLeftorRight.d.ts +17 -19
  30. package/dist/src/react-menu3/positionUtils/placeToporBottom.d.ts +18 -20
  31. package/dist/src/react-menu3/positionUtils/positionContextMenu.d.ts +11 -6
  32. package/dist/src/react-menu3/positionUtils/positionMenu.d.ts +23 -18
  33. package/dist/src/react-menu3/types.d.ts +389 -0
  34. package/dist/src/react-menu3/utils/constants.d.ts +58 -9
  35. package/dist/src/react-menu3/utils/index.d.ts +0 -1
  36. package/dist/src/react-menu3/utils/{propTypes.d.ts → propTypes2.d.ts} +1 -0
  37. package/dist/src/react-menu3/utils/utils.d.ts +20 -11
  38. package/dist/src/react-menu3/utils/withHovering.d.ts +7 -1
  39. package/dist/src/stories/components/ReactMenu.stories.d.ts +8 -0
  40. package/dist/step-ag-grid.esm.js +276 -235
  41. package/dist/step-ag-grid.esm.js.map +1 -1
  42. package/package.json +11 -11
  43. package/src/components/GridCell.tsx +6 -3
  44. package/src/components/GridPopoverHook.tsx +1 -1
  45. package/src/components/gridForm/GridFormDropDown.tsx +1 -1
  46. package/src/components/gridForm/GridFormMultiSelect.tsx +36 -17
  47. package/src/components/gridRender/GridRenderGenericCell.tsx +11 -7
  48. package/src/components/gridRender/GridRenderPopoutMenuCell.tsx +14 -2
  49. package/src/contexts/GridContextProvider.tsx +3 -2
  50. package/src/react-menu3/components/ControlledMenu.tsx +40 -45
  51. package/src/react-menu3/components/FocusableItem.tsx +58 -53
  52. package/src/react-menu3/components/Menu.tsx +40 -28
  53. package/src/react-menu3/components/MenuButton.tsx +30 -29
  54. package/src/react-menu3/components/MenuDivider.tsx +14 -18
  55. package/src/react-menu3/components/MenuGroup.tsx +25 -16
  56. package/src/react-menu3/components/MenuHeader.tsx +14 -18
  57. package/src/react-menu3/components/MenuItem.tsx +158 -106
  58. package/src/react-menu3/components/MenuList.tsx +61 -36
  59. package/src/react-menu3/components/MenuRadioGroup.tsx +54 -15
  60. package/src/react-menu3/components/SubMenu.tsx +317 -202
  61. package/src/react-menu3/hooks/useBEM.ts +4 -3
  62. package/src/react-menu3/hooks/useCombinedRef.ts +6 -12
  63. package/src/react-menu3/hooks/useItemEffect.ts +6 -5
  64. package/src/react-menu3/hooks/useItemState.ts +16 -12
  65. package/src/react-menu3/hooks/useItems.ts +11 -10
  66. package/src/react-menu3/hooks/useMenuChange.ts +3 -3
  67. package/src/react-menu3/hooks/useMenuState.ts +25 -7
  68. package/src/react-menu3/hooks/useMenuStateAndFocus.ts +6 -4
  69. package/src/react-menu3/index.ts +1 -0
  70. package/src/react-menu3/positionUtils/getPositionHelpers.ts +19 -12
  71. package/src/react-menu3/positionUtils/placeArrowHorizontal.ts +12 -5
  72. package/src/react-menu3/positionUtils/placeArrowVertical.ts +12 -5
  73. package/src/react-menu3/positionUtils/placeLeftorRight.ts +33 -17
  74. package/src/react-menu3/positionUtils/placeToporBottom.ts +34 -18
  75. package/src/react-menu3/positionUtils/positionContextMenu.ts +15 -3
  76. package/src/react-menu3/positionUtils/positionMenu.ts +21 -14
  77. package/src/react-menu3/style-utils/index.ts +10 -7
  78. package/src/react-menu3/{index.d.ts → types.ts} +106 -358
  79. package/src/react-menu3/utils/constants.ts +82 -10
  80. package/src/react-menu3/utils/index.ts +1 -1
  81. package/src/react-menu3/utils/{propTypes.ts → propTypes2.ts} +3 -1
  82. package/src/react-menu3/utils/utils.ts +41 -24
  83. package/src/react-menu3/utils/withHovering.tsx +11 -6
  84. package/src/stories/components/GridReadOnly.stories.tsx +3 -4
  85. package/src/stories/components/ReactMenu.stories.tsx +37 -0
@@ -1,10 +1,9 @@
1
- import { createContext, useRef, useContext, useCallback, useState, useEffect, useMemo, useLayoutEffect, memo, forwardRef, useReducer, cloneElement, useImperativeHandle, Fragment as Fragment$1 } from 'react';
1
+ import { createContext, useRef, useContext, useCallback, useState, useEffect, useMemo, forwardRef, useLayoutEffect, memo, useReducer, cloneElement, useImperativeHandle, Fragment as Fragment$1 } from 'react';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
- import { castArray, remove, flatten, isEmpty, delay, sortBy, last, difference, xorBy } from 'lodash-es';
3
+ import { castArray, remove, flatten, isEmpty, delay, sortBy, last, difference, xorBy, findIndex } from 'lodash-es';
4
4
  import { AgGridReact } from 'ag-grid-react';
5
5
  import { LuiMiniSpinner, LuiIcon, LuiCheckboxInput } from '@linzjs/lui';
6
6
  import { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
7
- import { object, bool, number, oneOf, string, oneOfType, exact, func, element, node, shape, any } from 'prop-types';
8
7
  import { useTransition } from 'react-transition-state';
9
8
  import debounce from 'debounce-promise';
10
9
  import { v4 } from 'uuid';
@@ -468,9 +467,11 @@ var GridContextProvider = function (props) {
468
467
  }
469
468
  // This is needed to trigger postSortRowsHook
470
469
  gridApi.refreshClientSideRowModel();
471
- stopEditing();
472
470
  }
473
- setSaving && setSaving(false);
471
+ else {
472
+ // Don't set saving if ok as the form has already closed
473
+ setSaving && setSaving(false);
474
+ }
474
475
  return [2 /*return*/, ok];
475
476
  }
476
477
  });
@@ -901,7 +902,7 @@ var GridCell = function (props) {
901
902
  cellEditor: GenericCellEditorComponent
902
903
  })), props), { cellRendererParams: __assign({ originalCellRender: props.cellRenderer }, props.cellRendererParams) });
903
904
  };
904
- var GenericCellEditorComponent = function (props) {
905
+ var GenericCellEditorComponentFr = function (props, _) {
905
906
  var _a, _b, _c;
906
907
  var _d = useContext(GridContext), updatingCells = _d.updatingCells, getSelectedRows = _d.getSelectedRows;
907
908
  var colDef = props.colDef, data = props.data;
@@ -930,7 +931,8 @@ var GenericCellEditorComponent = function (props) {
930
931
  if (cellEditorParams == null)
931
932
  return jsx(Fragment, {});
932
933
  return (jsxs(Fragment, { children: [jsx("div", { children: colDef.cellRenderer ? jsx(colDef.cellRenderer, __assign({}, props, { saving: saving })) : props.value }), (cellEditorParams === null || cellEditorParams === void 0 ? void 0 : cellEditorParams.form) && (jsx(cellEditorParams.form, { cellEditorParams: props, updateValue: updateValue, saving: saving, formProps: formProps, value: value, field: field, selectedRows: selectedRows }))] }));
933
- };
934
+ };
935
+ var GenericCellEditorComponent = forwardRef(GenericCellEditorComponentFr);
934
936
 
935
937
  /**
936
938
  * If loading is true this returns a loading spinner, otherwise it returns its children.
@@ -983,10 +985,6 @@ var setRef = function (ref, instance) {
983
985
  };
984
986
  var useCombinedRef = function (refA, refB) {
985
987
  return useMemo(function () {
986
- if (!refA)
987
- return refB;
988
- if (!refB)
989
- return refA;
990
988
  return function (instance) {
991
989
  setRef(refA, instance);
992
990
  setRef(refB, instance);
@@ -1004,7 +1002,6 @@ var useIsomorphicLayoutEffect = typeof window !== "undefined" &&
1004
1002
  ? useLayoutEffect
1005
1003
  : useEffect;
1006
1004
 
1007
- // @ts-nocheck
1008
1005
  var menuContainerClass = "szh-menu-container";
1009
1006
  var menuClass = "szh-menu";
1010
1007
  var menuButtonClass = "szh-menu-button";
@@ -1015,13 +1012,23 @@ var menuHeaderClass = "header";
1015
1012
  var menuGroupClass = "group";
1016
1013
  var subMenuClass = "submenu";
1017
1014
  var radioGroupClass = "radio-group";
1018
- var HoverItemContext = createContext();
1019
- var MenuListItemContext = createContext({});
1015
+ var HoverItemContext = createContext(undefined);
1016
+ var MenuListItemContext = createContext({
1017
+ dispatch: function () { },
1018
+ updateItems: function () { },
1019
+ setOpenSubmenuCount: function () { return 0; }
1020
+ });
1020
1021
  var MenuListContext = createContext({});
1021
- var EventHandlersContext = createContext({});
1022
+ var EventHandlersContext = createContext({
1023
+ handleClick: function () { }
1024
+ });
1022
1025
  var RadioGroupContext = createContext({});
1026
+ // FIXME hacking a default context in here is probably bad
1023
1027
  var SettingsContext = createContext({});
1024
- var ItemSettingsContext = createContext({});
1028
+ var ItemSettingsContext = createContext({
1029
+ submenuOpenDelay: 0,
1030
+ submenuCloseDelay: 0
1031
+ });
1025
1032
  var Keys = Object.freeze({
1026
1033
  ENTER: "Enter",
1027
1034
  ESC: "Escape",
@@ -1060,10 +1067,8 @@ var MenuStateMap = Object.freeze({
1060
1067
  exited: "closed"
1061
1068
  });
1062
1069
 
1063
- // @ts-nocheck
1064
1070
  var isMenuOpen = function (state) { return !!state && state[0] === "o"; };
1065
1071
  var batchedUpdates = unstable_batchedUpdates || (function (callback) { return callback(); });
1066
- var values = Object.values || (function (obj) { return Object.keys(obj).map(function (key) { return obj[key]; }); });
1067
1072
  var floatEqual = function (a, b, diff) {
1068
1073
  if (diff === void 0) { diff = 0.0001; }
1069
1074
  return Math.abs(a - b) < diff;
@@ -1071,10 +1076,11 @@ var floatEqual = function (a, b, diff) {
1071
1076
  var getTransition = function (transition, name) {
1072
1077
  return transition === true || !!(transition && transition[name]);
1073
1078
  };
1074
- var safeCall = function (fn, arg) { return (typeof fn === "function" ? fn(arg) : fn); };
1079
+ function safeCall(fn, arg) {
1080
+ return typeof fn === "function" ? fn(arg) : fn;
1081
+ }
1075
1082
  var internalKey = "_szhsinMenu";
1076
1083
  var getName = function (component) { return component[internalKey]; };
1077
- var defineName = function (name, component) { return Object.defineProperty(component, internalKey, { value: name }); };
1078
1084
  var mergeProps = function (target, source) {
1079
1085
  source &&
1080
1086
  Object.keys(source).forEach(function (key) {
@@ -1097,7 +1103,7 @@ var mergeProps = function (target, source) {
1097
1103
  return target;
1098
1104
  };
1099
1105
  var parsePadding = function (paddingStr) {
1100
- if (typeof paddingStr !== "string")
1106
+ if (paddingStr == null)
1101
1107
  return { top: 0, right: 0, bottom: 0, left: 0 };
1102
1108
  var padding = paddingStr.trim().split(/\s+/, 4).map(parseFloat);
1103
1109
  var top = !isNaN(padding[0]) ? padding[0] : 0;
@@ -1111,15 +1117,19 @@ var parsePadding = function (paddingStr) {
1111
1117
  };
1112
1118
  // Adapted from https://github.com/popperjs/popper-core/tree/v2.9.1/src/dom-utils
1113
1119
  var getScrollAncestor = function (node) {
1114
- var thisWindow = node.ownerDocument.defaultView;
1120
+ var _a, _b, _c;
1121
+ var thisWindow = (_b = ((_a = node === null || node === void 0 ? void 0 : node.ownerDocument) !== null && _a !== void 0 ? _a : document).defaultView) !== null && _b !== void 0 ? _b : window;
1115
1122
  while (node) {
1116
1123
  node = node.parentNode;
1117
- if (!node || node === thisWindow.document.body)
1118
- return;
1119
- var _a = thisWindow.getComputedStyle(node), overflow = _a.overflow, overflowX = _a.overflowX, overflowY = _a.overflowY;
1120
- if (/auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX))
1121
- return node;
1124
+ if (!node || node === ((_c = thisWindow === null || thisWindow === void 0 ? void 0 : thisWindow.document) === null || _c === void 0 ? void 0 : _c.body))
1125
+ return null;
1126
+ if (node instanceof Element) {
1127
+ var _d = thisWindow.getComputedStyle(node), overflow = _d.overflow, overflowX = _d.overflowX, overflowY = _d.overflowY;
1128
+ if (/auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX))
1129
+ return node;
1130
+ }
1122
1131
  }
1132
+ return null;
1123
1133
  };
1124
1134
  function commonProps(isDisabled, isHovering) {
1125
1135
  return {
@@ -1127,54 +1137,18 @@ function commonProps(isDisabled, isHovering) {
1127
1137
  tabIndex: isHovering ? 0 : -1
1128
1138
  };
1129
1139
  }
1130
- function indexOfNode(nodeList, node) {
1131
- for (var i = 0; i < nodeList.length; i++) {
1132
- if (nodeList[i] === node)
1133
- return i;
1134
- }
1135
- return -1;
1136
- }
1137
-
1138
- var stylePropTypes = function (name) {
1139
- var _a;
1140
- return (_a = {},
1141
- _a[name ? "".concat(name, "ClassName") : "className"] = oneOfType([string, func]),
1142
- _a);
1143
- };
1144
- // Menu, SubMenu and ControlledMenu
1145
- var menuPropTypes = __assign(__assign(__assign({ className: string }, stylePropTypes("menu")), stylePropTypes("arrow")), { menuStyle: object, arrowStyle: object, arrow: bool, setDownOverflow: bool, offsetX: number, offsetY: number, align: oneOf(["start", "center", "end"]), direction: oneOf(["left", "right", "top", "bottom"]), position: oneOf(["auto", "anchor", "initial"]), overflow: oneOf(["auto", "visible", "hidden"]) });
1146
- // Menu and ControlledMenu
1147
- var rootMenuPropTypes = __assign(__assign({}, menuPropTypes), { containerProps: object, initialMounted: bool, unmountOnClose: bool, transition: oneOfType([
1148
- bool,
1149
- exact({
1150
- open: bool,
1151
- close: bool,
1152
- item: bool
1153
- }),
1154
- ]), transitionTimeout: number, boundingBoxRef: object, boundingBoxPadding: string, reposition: oneOf(["auto", "initial"]), repositionFlag: oneOfType([string, number]), viewScroll: oneOf(["auto", "close", "initial"]), submenuOpenDelay: number, submenuCloseDelay: number, portal: oneOfType([
1155
- bool,
1156
- exact({
1157
- target: object,
1158
- stablePosition: bool
1159
- }),
1160
- ]), theming: string, onItemClick: func });
1161
- // Menu and SubMenu
1162
- var uncontrolledMenuPropTypes = {
1163
- instanceRef: oneOfType([object, func]),
1164
- onMenuChange: func
1165
- };
1140
+ var indexOfNode = function (nodeList, node) { return findIndex(nodeList, node); };
1166
1141
 
1167
1142
  var withHovering = function (name, WrappedComponent) {
1168
1143
  var Component = memo(WrappedComponent);
1169
1144
  var WithHovering = forwardRef(function (props, ref) {
1170
- var itemRef = useRef(null);
1171
- return (jsx(Component, __assign({}, props, { itemRef: itemRef, externalRef: ref, isHovering: useContext(HoverItemContext) === itemRef.current })));
1145
+ var menuItemRef = useRef(null);
1146
+ return (jsx(Component, __assign({}, props, { menuItemRef: menuItemRef, externalRef: ref, isHovering: useContext(HoverItemContext) === menuItemRef.current })));
1172
1147
  });
1173
1148
  WithHovering.displayName = "WithHovering(".concat(name, ")");
1174
1149
  return WithHovering;
1175
1150
  };
1176
1151
 
1177
- // @ts-nocheck
1178
1152
  var useItems = function (menuRef, focusRef) {
1179
1153
  var _a = useState(), hoverItem = _a[0], setHoverItem = _a[1];
1180
1154
  var stateRef = useRef({
@@ -1184,6 +1158,7 @@ var useItems = function (menuRef, focusRef) {
1184
1158
  });
1185
1159
  var mutableState = stateRef.current;
1186
1160
  var updateItems = useCallback(function (item, isMounted) {
1161
+ var _a;
1187
1162
  var items = mutableState.items;
1188
1163
  if (!item) {
1189
1164
  mutableState.items = [];
@@ -1196,8 +1171,8 @@ var useItems = function (menuRef, focusRef) {
1196
1171
  if (index > -1) {
1197
1172
  items.splice(index, 1);
1198
1173
  if (item.contains(document.activeElement)) {
1199
- focusRef.current.focus();
1200
- setHoverItem();
1174
+ (_a = focusRef === null || focusRef === void 0 ? void 0 : focusRef.current) === null || _a === void 0 ? void 0 : _a.focus();
1175
+ setHoverItem(undefined);
1201
1176
  }
1202
1177
  }
1203
1178
  }
@@ -1234,6 +1209,8 @@ var useItems = function (menuRef, focusRef) {
1234
1209
  newItem = items[index];
1235
1210
  break;
1236
1211
  case HoverActionTypes.SET_INDEX:
1212
+ if (typeof nextIndex !== "number")
1213
+ break;
1237
1214
  sortItems();
1238
1215
  index = nextIndex;
1239
1216
  newItem = items[index];
@@ -1270,32 +1247,33 @@ var useItems = function (menuRef, focusRef) {
1270
1247
  return { hoverItem: hoverItem, dispatch: dispatch, updateItems: updateItems };
1271
1248
  };
1272
1249
 
1273
- var useItemEffect = function (isDisabled, itemRef, updateItems) {
1250
+ var useItemEffect = function (isDisabled, menuItemRef, updateItems) {
1274
1251
  useIsomorphicLayoutEffect(function () {
1252
+ if (!menuItemRef)
1253
+ return;
1275
1254
  if (process.env.NODE_ENV !== "production" && !updateItems) {
1276
- throw new Error("[React-Menu] This menu item or submenu should be rendered under a menu: ".concat(itemRef.current.outerHTML));
1255
+ throw new Error("[React-Menu] This menu item or submenu should be rendered under a menu: ".concat(menuItemRef.current.outerHTML));
1277
1256
  }
1278
1257
  if (isDisabled)
1279
1258
  return;
1280
- var item = itemRef.current;
1259
+ var item = menuItemRef.current;
1281
1260
  updateItems(item, true);
1282
1261
  return function () {
1283
1262
  updateItems(item);
1284
1263
  };
1285
- }, [isDisabled, itemRef, updateItems]);
1264
+ }, [isDisabled, menuItemRef, updateItems]);
1286
1265
  };
1287
1266
 
1288
- // @ts-nocheck
1289
1267
  // This hook includes some common stateful logic in MenuItem and FocusableItem
1290
- var useItemState = function (itemRef, focusRef, isHovering, isDisabled) {
1268
+ var useItemState = function (menuItemRef, focusRef, isHovering, isDisabled) {
1291
1269
  var submenuCloseDelay = useContext(ItemSettingsContext).submenuCloseDelay;
1292
1270
  var _a = useContext(MenuListItemContext), isParentOpen = _a.isParentOpen, isSubmenuOpen = _a.isSubmenuOpen, dispatch = _a.dispatch, updateItems = _a.updateItems;
1293
- var timeoutId = useRef(0);
1271
+ var timeoutId = useRef();
1294
1272
  var setHover = function () {
1295
- !isHovering && !isDisabled && dispatch(HoverActionTypes.SET, itemRef.current);
1273
+ !isHovering && !isDisabled && dispatch(HoverActionTypes.SET, menuItemRef === null || menuItemRef === void 0 ? void 0 : menuItemRef.current, 0);
1296
1274
  };
1297
1275
  var unsetHover = function () {
1298
- !isDisabled && dispatch(HoverActionTypes.UNSET, itemRef.current);
1276
+ !isDisabled && dispatch(HoverActionTypes.UNSET, menuItemRef === null || menuItemRef === void 0 ? void 0 : menuItemRef.current, 0);
1299
1277
  };
1300
1278
  var onBlur = function (e) {
1301
1279
  // Focus has moved out of the entire item
@@ -1307,7 +1285,7 @@ var useItemState = function (itemRef, focusRef, isHovering, isDisabled) {
1307
1285
  if (isSubmenuOpen) {
1308
1286
  if (!timeoutId.current)
1309
1287
  timeoutId.current = setTimeout(function () {
1310
- timeoutId.current = 0;
1288
+ timeoutId.current = undefined;
1311
1289
  setHover();
1312
1290
  }, submenuCloseDelay);
1313
1291
  }
@@ -1318,17 +1296,17 @@ var useItemState = function (itemRef, focusRef, isHovering, isDisabled) {
1318
1296
  var onPointerLeave = function (_, keepHover) {
1319
1297
  if (timeoutId.current) {
1320
1298
  clearTimeout(timeoutId.current);
1321
- timeoutId.current = 0;
1299
+ timeoutId.current = undefined;
1322
1300
  }
1323
1301
  !keepHover && unsetHover();
1324
1302
  };
1325
- useItemEffect(isDisabled, itemRef, updateItems);
1303
+ useItemEffect(isDisabled, menuItemRef, updateItems);
1326
1304
  useEffect(function () { return function () { return clearTimeout(timeoutId.current); }; }, []);
1327
1305
  useEffect(function () {
1328
1306
  // Don't set focus when parent menu is closed, otherwise focus will be lost
1329
1307
  // and onBlur event will be fired with relatedTarget setting as null.
1330
1308
  if (isHovering && isParentOpen) {
1331
- focusRef.current && focusRef.current.focus();
1309
+ (focusRef === null || focusRef === void 0 ? void 0 : focusRef.current) && focusRef.current.focus();
1332
1310
  }
1333
1311
  }, [focusRef, isHovering, isParentOpen]);
1334
1312
  return {
@@ -1339,16 +1317,18 @@ var useItemState = function (itemRef, focusRef, isHovering, isDisabled) {
1339
1317
  };
1340
1318
  };
1341
1319
 
1342
- // @ts-nocheck
1343
1320
  var useMenuChange = function (onMenuChange, isOpen) {
1344
1321
  var prevOpen = useRef(isOpen);
1345
1322
  useEffect(function () {
1346
- if (prevOpen.current !== isOpen)
1347
- safeCall(onMenuChange, { open: isOpen });
1323
+ if (onMenuChange && prevOpen.current !== isOpen)
1324
+ safeCall(onMenuChange, { open: !!isOpen });
1348
1325
  prevOpen.current = isOpen;
1349
1326
  }, [onMenuChange, isOpen]);
1350
1327
  };
1351
1328
 
1329
+ /**
1330
+ * A custom Hook which helps manage the states of `ControlledMenu`.
1331
+ */
1352
1332
  var useMenuState = function (props) {
1353
1333
  var _a = props !== null && props !== void 0 ? props : {
1354
1334
  transition: false
@@ -1373,18 +1353,17 @@ var useMenuStateAndFocus = function (options) {
1373
1353
  return [__assign({ menuItemFocus: menuItemFocus }, menuProps), toggleMenu, openMenu];
1374
1354
  };
1375
1355
 
1376
- var MenuButton = defineName("MenuButton", forwardRef(function MenuButton(_a, ref) {
1356
+ var MenuButton = forwardRef(function MenuButton(_a, ref) {
1377
1357
  var className = _a.className, isOpen = _a.isOpen, disabled = _a.disabled, children = _a.children, restProps = __rest(_a, ["className", "isOpen", "disabled", "children"]);
1378
1358
  var modifiers = useMemo(function () { return ({ open: isOpen }); }, [isOpen]);
1379
1359
  return (jsx("button", __assign({ "aria-haspopup": true, "aria-expanded": isOpen, "aria-disabled": disabled || undefined, type: "button", disabled: disabled }, restProps, { ref: ref, className: useBEM({ block: menuButtonClass, modifiers: modifiers, className: className }) }, { children: children })));
1380
- }));
1381
- MenuButton.propTypes = __assign(__assign({}, stylePropTypes()), { isOpen: bool, disabled: bool });
1360
+ });
1382
1361
 
1383
- // @ts-nocheck
1384
1362
  var getPositionHelpers = function (containerRef, menuRef, menuScroll, boundingBoxPadding) {
1363
+ var _a, _b, _c;
1385
1364
  var menuRect = menuRef.current.getBoundingClientRect();
1386
- var containerRect = containerRef.current.getBoundingClientRect();
1387
- var thisWindow = containerRef.current.ownerDocument.defaultView;
1365
+ var thisWindow = (_b = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.defaultView) !== null && _b !== void 0 ? _b : window;
1366
+ var containerRect = ((_c = containerRef.current) !== null && _c !== void 0 ? _c : thisWindow.document.body).getBoundingClientRect();
1388
1367
  var boundingRect = menuScroll === window || menuScroll === thisWindow
1389
1368
  ? {
1390
1369
  left: 0,
@@ -1399,7 +1378,9 @@ var getPositionHelpers = function (containerRef, menuRef, menuScroll, boundingBo
1399
1378
  var getLeftOverflow = function (x) { return x + containerRect.left - boundingRect.left - padding.left; };
1400
1379
  var getRightOverflow = function (x) { return x + containerRect.left + menuRect.width - boundingRect.right + padding.right; };
1401
1380
  var getTopOverflow = function (y) { return y + containerRect.top - boundingRect.top - padding.top; };
1402
- var getBottomOverflow = function (y) { return y + containerRect.top + menuRect.height - boundingRect.bottom + padding.bottom; };
1381
+ var getBottomOverflow = function (y) {
1382
+ return y + containerRect.top + menuRect.height - boundingRect.bottom + padding.bottom;
1383
+ };
1403
1384
  var confineHorizontally = function (x) {
1404
1385
  // If menu overflows to the left side, adjust x to have the menu contained within the viewport
1405
1386
  // and there is no need to check the right side;
@@ -1413,7 +1394,7 @@ var getPositionHelpers = function (containerRef, menuRef, menuScroll, boundingBo
1413
1394
  if (rightOverflow > 0) {
1414
1395
  x -= rightOverflow;
1415
1396
  // Check again to make sure menu doesn't overflow to the left
1416
- // because it may go off screen and cannot be scroll into view.
1397
+ // because it may go off-screen and cannot be scrolled into view.
1417
1398
  leftOverflow = getLeftOverflow(x);
1418
1399
  if (leftOverflow < 0)
1419
1400
  x -= leftOverflow;
@@ -1452,7 +1433,6 @@ var getPositionHelpers = function (containerRef, menuRef, menuScroll, boundingBo
1452
1433
  };
1453
1434
  };
1454
1435
 
1455
- // @ts-nocheck
1456
1436
  var positionContextMenu = function (_a) {
1457
1437
  var positionHelpers = _a.positionHelpers, anchorPoint = _a.anchorPoint;
1458
1438
  var menuRect = positionHelpers.menuRect, containerRect = positionHelpers.containerRect, getLeftOverflow = positionHelpers.getLeftOverflow, getRightOverflow = positionHelpers.getRightOverflow, getTopOverflow = positionHelpers.getTopOverflow, getBottomOverflow = positionHelpers.getBottomOverflow, confineHorizontally = positionHelpers.confineHorizontally, confineVertically = positionHelpers.confineVertically;
@@ -1489,19 +1469,16 @@ var positionContextMenu = function (_a) {
1489
1469
  return { x: x, y: y, computedDirection: computedDirection };
1490
1470
  };
1491
1471
 
1492
- // @ts-nocheck
1493
- var placeArrowVertical = function (_a) {
1494
- var arrowRef = _a.arrowRef, menuY = _a.menuY, anchorRect = _a.anchorRect, containerRect = _a.containerRect, menuRect = _a.menuRect;
1495
- var y = anchorRect.top - containerRect.top - menuY + anchorRect.height / 2;
1496
- var offset = arrowRef.current.offsetHeight * 1.25;
1472
+ var placeArrowVertical = function (p) {
1473
+ var y = p.anchorRect.top - p.containerRect.top - p.menuY + p.anchorRect.height / 2;
1474
+ var offset = p.arrowRef.current ? p.arrowRef.current.offsetHeight * 1.25 : 0;
1497
1475
  y = Math.max(offset, y);
1498
- y = Math.min(y, menuRect.height - offset);
1476
+ y = Math.min(y, p.menuRect.height - offset);
1499
1477
  return y;
1500
1478
  };
1501
1479
 
1502
- // @ts-nocheck
1503
- var placeLeftorRight = function (_a) {
1504
- var anchorRect = _a.anchorRect, containerRect = _a.containerRect, menuRect = _a.menuRect, placeLeftorRightY = _a.placeLeftorRightY, placeLeftX = _a.placeLeftX, placeRightX = _a.placeRightX, getLeftOverflow = _a.getLeftOverflow, getRightOverflow = _a.getRightOverflow, confineHorizontally = _a.confineHorizontally, confineVertically = _a.confineVertically, arrowRef = _a.arrowRef, arrow = _a.arrow, direction = _a.direction, position = _a.position;
1480
+ var placeLeftorRight = function (props) {
1481
+ var anchorRect = props.anchorRect, containerRect = props.containerRect, menuRect = props.menuRect, placeLeftorRightY = props.placeLeftorRightY, placeLeftX = props.placeLeftX, placeRightX = props.placeRightX, getLeftOverflow = props.getLeftOverflow, getRightOverflow = props.getRightOverflow, confineHorizontally = props.confineHorizontally, confineVertically = props.confineVertically, arrowRef = props.arrowRef, arrow = props.arrow, direction = props.direction, position = props.position;
1505
1482
  var computedDirection = direction;
1506
1483
  var y = placeLeftorRightY;
1507
1484
  if (position !== "initial") {
@@ -1558,19 +1535,16 @@ var placeLeftorRight = function (_a) {
1558
1535
  return { arrowY: arrowY, x: x, y: y, computedDirection: computedDirection };
1559
1536
  };
1560
1537
 
1561
- // @ts-nocheck
1562
- var placeArrowHorizontal = function (_a) {
1563
- var arrowRef = _a.arrowRef, menuX = _a.menuX, anchorRect = _a.anchorRect, containerRect = _a.containerRect, menuRect = _a.menuRect;
1564
- var x = anchorRect.left - containerRect.left - menuX + anchorRect.width / 2;
1565
- var offset = arrowRef.current.offsetWidth * 1.25;
1538
+ var placeArrowHorizontal = function (p) {
1539
+ var x = p.anchorRect.left - p.containerRect.left - p.menuX + p.anchorRect.width / 2;
1540
+ var offset = p.arrowRef.current ? p.arrowRef.current.offsetWidth * 1.25 : 0;
1566
1541
  x = Math.max(offset, x);
1567
- x = Math.min(x, menuRect.width - offset);
1542
+ x = Math.min(x, p.menuRect.width - offset);
1568
1543
  return x;
1569
1544
  };
1570
1545
 
1571
- // @ts-nocheck
1572
- var placeToporBottom = function (_a) {
1573
- var anchorRect = _a.anchorRect, containerRect = _a.containerRect, menuRect = _a.menuRect, placeToporBottomX = _a.placeToporBottomX, placeTopY = _a.placeTopY, placeBottomY = _a.placeBottomY, getTopOverflow = _a.getTopOverflow, getBottomOverflow = _a.getBottomOverflow, confineHorizontally = _a.confineHorizontally, confineVertically = _a.confineVertically, arrowRef = _a.arrowRef, arrow = _a.arrow, direction = _a.direction, position = _a.position;
1546
+ var placeToporBottom = function (props) {
1547
+ var anchorRect = props.anchorRect, containerRect = props.containerRect, menuRect = props.menuRect, placeToporBottomX = props.placeToporBottomX, placeTopY = props.placeTopY, placeBottomY = props.placeBottomY, getTopOverflow = props.getTopOverflow, getBottomOverflow = props.getBottomOverflow, confineHorizontally = props.confineHorizontally, confineVertically = props.confineVertically, arrowRef = props.arrowRef, arrow = props.arrow, direction = props.direction, position = props.position;
1574
1548
  // make sure invalid direction is treated as 'bottom'
1575
1549
  var computedDirection = direction === "top" ? "top" : "bottom";
1576
1550
  var x = placeToporBottomX;
@@ -1628,12 +1602,12 @@ var placeToporBottom = function (_a) {
1628
1602
  return { arrowX: arrowX, x: x, y: y, computedDirection: computedDirection };
1629
1603
  };
1630
1604
 
1631
- var positionMenu = function (_a) {
1632
- var arrow = _a.arrow, align = _a.align, direction = _a.direction, offsetX = _a.offsetX, offsetY = _a.offsetY, position = _a.position, anchorRef = _a.anchorRef, arrowRef = _a.arrowRef, positionHelpers = _a.positionHelpers;
1605
+ var positionMenu = function (props) {
1606
+ var arrow = props.arrow, align = props.align, direction = props.direction, offsetX = props.offsetX, offsetY = props.offsetY, position = props.position, anchorRef = props.anchorRef, arrowRef = props.arrowRef, positionHelpers = props.positionHelpers;
1633
1607
  var menuRect = positionHelpers.menuRect, containerRect = positionHelpers.containerRect;
1634
1608
  var horizontalOffset = offsetX;
1635
1609
  var verticalOffset = offsetY;
1636
- if (arrow) {
1610
+ if (arrow && arrowRef.current) {
1637
1611
  if (direction === "left" || direction === "right") {
1638
1612
  horizontalOffset += arrowRef.current.offsetWidth;
1639
1613
  }
@@ -1641,7 +1615,9 @@ var positionMenu = function (_a) {
1641
1615
  verticalOffset += arrowRef.current.offsetHeight;
1642
1616
  }
1643
1617
  }
1644
- var anchorRect = anchorRef.current.getBoundingClientRect();
1618
+ var anchorRect = anchorRef.current
1619
+ ? anchorRef.current.getBoundingClientRect()
1620
+ : { left: 0, right: 0, top: 200, bottom: 200, width: 200, height: 200 };
1645
1621
  var placeLeftX = anchorRect.left - containerRect.left - menuRect.width - horizontalOffset;
1646
1622
  var placeRightX = anchorRect.right - containerRect.left + horizontalOffset;
1647
1623
  var placeTopY = anchorRect.top - containerRect.top - menuRect.height - verticalOffset;
@@ -1676,16 +1652,16 @@ var positionMenu = function (_a) {
1676
1652
  var MenuList = function (_a) {
1677
1653
  var ariaLabel = _a.ariaLabel, menuClassName = _a.menuClassName, menuStyle = _a.menuStyle, arrowClassName = _a.arrowClassName, arrowStyle = _a.arrowStyle, anchorPoint = _a.anchorPoint, anchorRef = _a.anchorRef, containerRef = _a.containerRef, externalRef = _a.externalRef, parentScrollingRef = _a.parentScrollingRef, arrow = _a.arrow, _b = _a.align, align = _b === void 0 ? "start" : _b, _c = _a.direction, direction = _c === void 0 ? "bottom" : _c, _d = _a.position, position = _d === void 0 ? "auto" : _d, _e = _a.overflow, overflow = _e === void 0 ? "visible" : _e, setDownOverflow = _a.setDownOverflow, repositionFlag = _a.repositionFlag, _f = _a.captureFocus, captureFocus = _f === void 0 ? true : _f, state = _a.state, endTransition = _a.endTransition, isDisabled = _a.isDisabled, menuItemFocus = _a.menuItemFocus, _g = _a.offsetX, offsetX = _g === void 0 ? 0 : _g, _h = _a.offsetY, offsetY = _h === void 0 ? 0 : _h, children = _a.children, onClose = _a.onClose, restProps = __rest(_a, ["ariaLabel", "menuClassName", "menuStyle", "arrowClassName", "arrowStyle", "anchorPoint", "anchorRef", "containerRef", "externalRef", "parentScrollingRef", "arrow", "align", "direction", "position", "overflow", "setDownOverflow", "repositionFlag", "captureFocus", "state", "endTransition", "isDisabled", "menuItemFocus", "offsetX", "offsetY", "children", "onClose"]);
1678
1654
  var _j = useState({ x: 0, y: 0 }), menuPosition = _j[0], setMenuPosition = _j[1];
1679
- var _k = useState({}), arrowPosition = _k[0], setArrowPosition = _k[1];
1655
+ var _k = useState({ x: 0, y: 0 }), arrowPosition = _k[0], setArrowPosition = _k[1];
1680
1656
  var _l = useState(), overflowData = _l[0], setOverflowData = _l[1];
1681
1657
  var _m = useState(direction), expandedDirection = _m[0], setExpandedDirection = _m[1];
1682
1658
  var _o = useState(0), openSubmenuCount = _o[0], setOpenSubmenuCount = _o[1];
1683
1659
  var _p = useReducer(function (c) { return c + 1; }, 1), reposSubmenu = _p[0], forceReposSubmenu = _p[1];
1684
1660
  var _q = useContext(SettingsContext), transition = _q.transition, boundingBoxRef = _q.boundingBoxRef, boundingBoxPadding = _q.boundingBoxPadding, rootMenuRef = _q.rootMenuRef, rootAnchorRef = _q.rootAnchorRef, scrollNodesRef = _q.scrollNodesRef, reposition = _q.reposition, viewScroll = _q.viewScroll;
1685
1661
  var reposFlag = useContext(MenuListContext).reposSubmenu || repositionFlag;
1686
- var menuRef = useRef(null);
1687
- var focusRef = useRef();
1688
- var arrowRef = useRef();
1662
+ var menuRef = useRef({});
1663
+ var focusRef = useRef(null);
1664
+ var arrowRef = useRef(null);
1689
1665
  var prevOpen = useRef(false);
1690
1666
  var latestMenuSize = useRef({ width: 0, height: 0 });
1691
1667
  var latestHandlePosition = useRef(function () { });
@@ -1695,30 +1671,33 @@ var MenuList = function (_a) {
1695
1671
  var closeTransition = getTransition(transition, "close");
1696
1672
  var scrollNodes = scrollNodesRef.current;
1697
1673
  var onKeyDown = function (e) {
1698
- var isTextInputTarget = e.target.nodeName === "TEXTAREA" || (e.target.nodeName === "INPUT" && e.target.getAttribute("type") === "text");
1674
+ var elementTarget = e.target instanceof HTMLElement ? e.target : null;
1675
+ var isTextInputTarget = elementTarget &&
1676
+ (elementTarget.nodeName === "TEXTAREA" ||
1677
+ (elementTarget.nodeName === "INPUT" && elementTarget.getAttribute("type") === "text"));
1699
1678
  switch (e.key) {
1700
1679
  case Keys.HOME:
1701
1680
  // Don't eat home/end events on inputs
1702
1681
  if (isTextInputTarget)
1703
1682
  return;
1704
- dispatch(HoverActionTypes.FIRST);
1683
+ dispatch(HoverActionTypes.FIRST, null, 0);
1705
1684
  break;
1706
1685
  case Keys.END:
1707
1686
  // Don't eat home/end events on inputs
1708
1687
  if (isTextInputTarget)
1709
1688
  return;
1710
- dispatch(HoverActionTypes.LAST);
1689
+ dispatch(HoverActionTypes.LAST, null, 0);
1711
1690
  break;
1712
1691
  case Keys.UP:
1713
- dispatch(HoverActionTypes.DECREASE, hoverItem);
1692
+ dispatch(HoverActionTypes.DECREASE, hoverItem, 0);
1714
1693
  break;
1715
1694
  case Keys.DOWN:
1716
- dispatch(HoverActionTypes.INCREASE, hoverItem);
1695
+ dispatch(HoverActionTypes.INCREASE, hoverItem, 0);
1717
1696
  break;
1718
1697
  // prevent browser from scrolling the page when SPACE is pressed
1719
1698
  case Keys.SPACE:
1720
1699
  // Don't preventDefault on children of FocusableItem
1721
- if (e.target && e.target.className.indexOf(menuClass) !== -1) {
1700
+ if (elementTarget && elementTarget.className.includes(menuClass)) {
1722
1701
  e.preventDefault();
1723
1702
  }
1724
1703
  return;
@@ -1730,12 +1709,12 @@ var MenuList = function (_a) {
1730
1709
  };
1731
1710
  var onAnimationEnd = function () {
1732
1711
  if (state === "closing") {
1733
- setOverflowData(); // reset overflowData after closing
1712
+ setOverflowData(undefined); // reset overflowData after closing
1734
1713
  }
1735
- safeCall(endTransition);
1714
+ endTransition && safeCall(endTransition);
1736
1715
  };
1737
1716
  var handlePosition = useCallback(function (noOverflowCheck) {
1738
- if (!containerRef.current) {
1717
+ if (!(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current)) {
1739
1718
  if (process.env.NODE_ENV !== "production") {
1740
1719
  console.error('[React-Menu] Menu cannot be positioned properly as container ref is null. If you need to initialise `state` prop to "open" for ControlledMenu, please see this solution: https://codesandbox.io/s/initial-open-sp10wn');
1741
1720
  }
@@ -1745,11 +1724,15 @@ var MenuList = function (_a) {
1745
1724
  scrollNodes.menu =
1746
1725
  (boundingBoxRef
1747
1726
  ? boundingBoxRef.current // user explicitly sets boundingBoxRef
1748
- : getScrollAncestor(rootMenuRef.current)) || window; // try to discover bounding box automatically
1727
+ : getScrollAncestor(rootMenuRef === null || rootMenuRef === void 0 ? void 0 : rootMenuRef.current)) || window; // try to discover bounding box automatically
1749
1728
  }
1750
1729
  var positionHelpers = getPositionHelpers(containerRef, menuRef, scrollNodes.menu, boundingBoxPadding);
1751
1730
  var menuRect = positionHelpers.menuRect;
1752
- var results = { computedDirection: "bottom" };
1731
+ var results = {
1732
+ computedDirection: "bottom",
1733
+ x: 0,
1734
+ y: 0
1735
+ };
1753
1736
  if (anchorPoint) {
1754
1737
  results = positionContextMenu({ positionHelpers: positionHelpers, anchorPoint: anchorPoint });
1755
1738
  }
@@ -1766,7 +1749,8 @@ var MenuList = function (_a) {
1766
1749
  positionHelpers: positionHelpers
1767
1750
  });
1768
1751
  }
1769
- var arrowX = results.arrowX, arrowY = results.arrowY, x = results.x, y = results.y, computedDirection = results.computedDirection;
1752
+ var y = results.y;
1753
+ var x = results.x, arrowX = results.arrowX, arrowY = results.arrowY, computedDirection = results.computedDirection;
1770
1754
  var menuHeight = menuRect.height;
1771
1755
  if (!noOverflowCheck && overflow !== "visible") {
1772
1756
  var getTopOverflow = positionHelpers.getTopOverflow, getBottomOverflow = positionHelpers.getBottomOverflow;
@@ -1790,17 +1774,17 @@ var MenuList = function (_a) {
1790
1774
  y -= topOverflow;
1791
1775
  }
1792
1776
  }
1793
- if (height >= 0) {
1777
+ if (height != null && height >= 0) {
1794
1778
  // To avoid triggering reposition in the next ResizeObserver callback
1795
1779
  menuHeight = height;
1796
1780
  setOverflowData({ height: height, overflowAmt: overflowAmt_1 });
1797
1781
  }
1798
1782
  else {
1799
- setOverflowData();
1783
+ setOverflowData(undefined);
1800
1784
  }
1801
1785
  }
1802
1786
  if (arrow)
1803
- setArrowPosition({ x: arrowX, y: arrowY });
1787
+ setArrowPosition({ x: arrowX !== null && arrowX !== void 0 ? arrowX : 0, y: arrowY !== null && arrowY !== void 0 ? arrowY : 0 });
1804
1788
  setMenuPosition({ x: x, y: y });
1805
1789
  setExpandedDirection(computedDirection);
1806
1790
  latestMenuSize.current = { width: menuRect.width, height: menuHeight };
@@ -1865,7 +1849,7 @@ var MenuList = function (_a) {
1865
1849
  scrollObservers.forEach(function (o) { return o.addEventListener("scroll", handleScroll); });
1866
1850
  return function () { return scrollObservers.forEach(function (o) { return o.removeEventListener("scroll", handleScroll); }); };
1867
1851
  }, [rootAnchorRef, scrollNodes, isOpen, onClose, viewScroll, handlePosition]);
1868
- var hasOverflow = !!overflowData && overflowData.overflowAmt > 0;
1852
+ var hasOverflow = !!overflowData && overflowData.overflowAmt != null && overflowData.overflowAmt > 0;
1869
1853
  useEffect(function () {
1870
1854
  if (hasOverflow || !isOpen || !parentScrollingRef)
1871
1855
  return;
@@ -1906,20 +1890,20 @@ var MenuList = function (_a) {
1906
1890
  }, [reposition]);
1907
1891
  useEffect(function () {
1908
1892
  if (!isOpen) {
1909
- dispatch(HoverActionTypes.RESET);
1893
+ dispatch(HoverActionTypes.RESET, undefined, 0);
1910
1894
  if (!closeTransition)
1911
- setOverflowData();
1912
- return;
1895
+ setOverflowData(undefined);
1896
+ return function () { };
1913
1897
  }
1914
1898
  var _a = menuItemFocus || {}, position = _a.position, alwaysUpdate = _a.alwaysUpdate;
1915
1899
  var setItemFocus = function () {
1916
1900
  if (position === FocusPositions.FIRST) {
1917
- dispatch(HoverActionTypes.FIRST);
1901
+ dispatch(HoverActionTypes.FIRST, undefined, 0);
1918
1902
  }
1919
1903
  else if (position === FocusPositions.LAST) {
1920
- dispatch(HoverActionTypes.LAST);
1904
+ dispatch(HoverActionTypes.LAST, undefined, 0);
1921
1905
  }
1922
- else if (position >= -1) {
1906
+ else if (typeof position === "number" && position >= -1) {
1923
1907
  dispatch(HoverActionTypes.SET_INDEX, undefined, position);
1924
1908
  }
1925
1909
  };
@@ -1929,14 +1913,33 @@ var MenuList = function (_a) {
1929
1913
  else if (captureFocus) {
1930
1914
  // Use a timeout here because if set focus immediately, page might scroll unexpectedly.
1931
1915
  var id_1 = setTimeout(function () {
1916
+ var _a, _b, _c;
1932
1917
  // If focus has already been set to a children element, don't set focus on menu or item
1933
1918
  if (!menuRef.current.contains(document.activeElement)) {
1934
- focusRef.current.focus();
1919
+ // Handle popover portal focus
1920
+ var popupElement = (_a = focusRef.current) === null || _a === void 0 ? void 0 : _a.nextSibling;
1921
+ if (popupElement instanceof Element) {
1922
+ var input = popupElement.querySelectorAll("input,textarea")[0];
1923
+ if (input) {
1924
+ input.focus();
1925
+ // Text areas should start at end
1926
+ if (input instanceof HTMLTextAreaElement) {
1927
+ input.selectionStart = input.value.length;
1928
+ }
1929
+ }
1930
+ else {
1931
+ (_b = focusRef.current) === null || _b === void 0 ? void 0 : _b.focus();
1932
+ }
1933
+ }
1934
+ else {
1935
+ (_c = focusRef.current) === null || _c === void 0 ? void 0 : _c.focus();
1936
+ }
1935
1937
  setItemFocus();
1936
1938
  }
1937
1939
  }, openTransition ? 170 : 100);
1938
1940
  return function () { return clearTimeout(id_1); };
1939
1941
  }
1942
+ return function () { };
1940
1943
  }, [isOpen, openTransition, closeTransition, captureFocus, menuItemFocus, dispatch]);
1941
1944
  var isSubmenuOpen = openSubmenuCount > 0;
1942
1945
  var itemContext = useMemo(function () { return ({
@@ -1946,7 +1949,8 @@ var MenuList = function (_a) {
1946
1949
  dispatch: dispatch,
1947
1950
  updateItems: updateItems
1948
1951
  }); }, [isOpen, isSubmenuOpen, dispatch, updateItems]);
1949
- var maxHeight, overflowAmt;
1952
+ var maxHeight;
1953
+ var overflowAmt;
1950
1954
  if (overflowData) {
1951
1955
  setDownOverflow ? (overflowAmt = overflowData.overflowAmt) : (maxHeight = overflowData.height);
1952
1956
  }
@@ -1957,7 +1961,7 @@ var MenuList = function (_a) {
1957
1961
  parentMenuRef: menuRef,
1958
1962
  parentDir: expandedDirection
1959
1963
  }); }, [reposSubmenu, overflow, overflowAmt, expandedDirection]);
1960
- var overflowStyle = maxHeight >= 0 ? { maxHeight: maxHeight, overflow: overflow } : undefined;
1964
+ var overflowStyle = maxHeight != null && maxHeight >= 0 ? { maxHeight: maxHeight, overflow: overflow } : undefined;
1961
1965
  var modifiers = useMemo(function () { return ({
1962
1966
  state: state,
1963
1967
  dir: expandedDirection
@@ -1972,9 +1976,9 @@ var MenuList = function (_a) {
1972
1976
  return (jsxs("ul", __assign({ role: "menu", "aria-label": ariaLabel }, mergeProps({ onKeyDown: onKeyDown, onAnimationEnd: onAnimationEnd }, restProps), commonProps(isDisabled), { ref: useCombinedRef(externalRef, menuRef), className: useBEM({ block: menuClass, modifiers: modifiers, className: menuClassName }), style: __assign(__assign(__assign({}, menuStyle), overflowStyle), { margin: 0, display: state === "closed" ? "none" : undefined, position: "absolute", left: menuPosition.x, top: menuPosition.y }) }, { children: [jsx("div", { ref: focusRef, tabIndex: -1, style: { position: "absolute", left: 0, top: 0 } }), arrow && (jsx("div", { className: _arrowClass, style: __assign(__assign({}, arrowStyle), { position: "absolute", left: arrowPosition.x, top: arrowPosition.y }), ref: arrowRef })), jsx(MenuListContext.Provider, __assign({ value: listContext }, { children: jsx(MenuListItemContext.Provider, __assign({ value: itemContext }, { children: jsx(HoverItemContext.Provider, __assign({ value: hoverItem }, { children: children })) })) }))] })));
1973
1977
  };
1974
1978
 
1975
- var ControlledMenu = forwardRef(function ControlledMenu(_a, externalRef) {
1979
+ var ControlledMenuFr = function (_a, externalRef) {
1976
1980
  var ariaLabel = _a["aria-label"], className = _a.className, containerProps = _a.containerProps, initialMounted = _a.initialMounted, unmountOnClose = _a.unmountOnClose, transition = _a.transition, transitionTimeout = _a.transitionTimeout, boundingBoxRef = _a.boundingBoxRef, boundingBoxPadding = _a.boundingBoxPadding, _b = _a.reposition, reposition = _b === void 0 ? "auto" : _b, _c = _a.submenuOpenDelay, submenuOpenDelay = _c === void 0 ? 300 : _c, _d = _a.submenuCloseDelay, submenuCloseDelay = _d === void 0 ? 150 : _d, skipOpen = _a.skipOpen, _e = _a.viewScroll, viewScroll = _e === void 0 ? "initial" : _e, portal = _a.portal, theming = _a.theming, onItemClick = _a.onItemClick, onClose = _a.onClose, saveButtonRef = _a.saveButtonRef, restProps = __rest(_a, ["aria-label", "className", "containerProps", "initialMounted", "unmountOnClose", "transition", "transitionTimeout", "boundingBoxRef", "boundingBoxPadding", "reposition", "submenuOpenDelay", "submenuCloseDelay", "skipOpen", "viewScroll", "portal", "theming", "onItemClick", "onClose", "saveButtonRef"]);
1977
- var containerRef = useRef(null);
1981
+ var containerRef = useRef();
1978
1982
  var scrollNodesRef = useRef({});
1979
1983
  var anchorRef = restProps.anchorRef, state = restProps.state;
1980
1984
  var settings = useMemo(function () { return ({
@@ -2012,7 +2016,7 @@ var ControlledMenu = forwardRef(function ControlledMenu(_a, externalRef) {
2012
2016
  // the cell doesn't refresh during update if save is invoked from a native event
2013
2017
  // This doesn't happen in React18
2014
2018
  // To work around it, I invoke the save by clicking on a passed in invisible button ref
2015
- if (saveButtonRef.current)
2019
+ if (saveButtonRef === null || saveButtonRef === void 0 ? void 0 : saveButtonRef.current)
2016
2020
  saveButtonRef.current.click();
2017
2021
  else
2018
2022
  safeCall(onClose, { reason: CloseReason.BLUR });
@@ -2027,7 +2031,7 @@ var ControlledMenu = forwardRef(function ControlledMenu(_a, externalRef) {
2027
2031
  setTimeout(function () { return (skipOpen.current = false); }, 300);
2028
2032
  }
2029
2033
  }
2030
- }, [clickIsWithinMenu, onClose]);
2034
+ }, [clickIsWithinMenu, onClose, saveButtonRef, skipOpen]);
2031
2035
  var handleScreenEventForCancel = useCallback(function (ev) {
2032
2036
  if (!clickIsWithinMenu(ev)) {
2033
2037
  ev.preventDefault();
@@ -2036,7 +2040,7 @@ var ControlledMenu = forwardRef(function ControlledMenu(_a, externalRef) {
2036
2040
  }, [clickIsWithinMenu]);
2037
2041
  useEffect(function () {
2038
2042
  if (isMenuOpen(state)) {
2039
- var thisDocument_1 = anchorRef.current ? anchorRef.current.ownerDocument : document;
2043
+ var thisDocument_1 = (anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) ? anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current.ownerDocument : document;
2040
2044
  thisDocument_1.addEventListener("mousedown", handleScreenEventForCancel, true);
2041
2045
  thisDocument_1.addEventListener("mouseup", handleScreenEventForSave, true);
2042
2046
  thisDocument_1.addEventListener("click", handleScreenEventForCancel, true);
@@ -2049,13 +2053,13 @@ var ControlledMenu = forwardRef(function ControlledMenu(_a, externalRef) {
2049
2053
  };
2050
2054
  }
2051
2055
  return function () { };
2052
- }, [handleScreenEventForSave, handleScreenEventForCancel, state]);
2056
+ }, [handleScreenEventForSave, handleScreenEventForCancel, state, anchorRef]);
2053
2057
  var itemSettings = useMemo(function () { return ({
2054
2058
  submenuOpenDelay: submenuOpenDelay,
2055
2059
  submenuCloseDelay: submenuCloseDelay
2056
2060
  }); }, [submenuOpenDelay, submenuCloseDelay]);
2057
2061
  var eventHandlers = useMemo(function () { return ({
2058
- handleClick: function (event, isCheckorRadio) {
2062
+ handleClick: function (event, isCheckOrRadio) {
2059
2063
  if (!event.stopPropagation)
2060
2064
  safeCall(onItemClick, event);
2061
2065
  var keepOpen = event.keepOpen;
@@ -2063,7 +2067,7 @@ var ControlledMenu = forwardRef(function ControlledMenu(_a, externalRef) {
2063
2067
  // if event.keepOpen is undefined, the following default behaviour is used
2064
2068
  // According to WAI-ARIA Authoring Practices 1.1
2065
2069
  // Keep menu open when check or radio is invoked by SPACE key
2066
- keepOpen = isCheckorRadio && event.key === Keys.SPACE;
2070
+ keepOpen = isCheckOrRadio && event.key === Keys.SPACE;
2067
2071
  }
2068
2072
  if (!keepOpen) {
2069
2073
  safeCall(onClose, {
@@ -2091,7 +2095,7 @@ var ControlledMenu = forwardRef(function ControlledMenu(_a, externalRef) {
2091
2095
  // If a user clicks on the menu button when a menu is open, we need to close the menu.
2092
2096
  // However, a blur event will be fired prior to the click event on menu button,
2093
2097
  // which makes the menu first close and then open again.
2094
- // If this happen, e.relatedTarget is incorrectly set to null instead of the button in Safari and Firefox,
2098
+ // If this happens, e.relatedTarget is incorrectly set to null instead of the button in Safari and Firefox,
2095
2099
  // and makes it difficult to determine whether onBlur is fired because of clicking on menu button.
2096
2100
  // This is a workaround approach which sets a flag to skip a following click event.
2097
2101
  if (skipOpen) {
@@ -2107,27 +2111,25 @@ var ControlledMenu = forwardRef(function ControlledMenu(_a, externalRef) {
2107
2111
  modifiers: modifiers,
2108
2112
  className: className
2109
2113
  }), style: __assign(__assign({}, containerProps === null || containerProps === void 0 ? void 0 : containerProps.style), { position: "relative" }), ref: containerRef }, { children: state && (jsx(SettingsContext.Provider, __assign({ value: settings }, { children: jsx(ItemSettingsContext.Provider, __assign({ value: itemSettings }, { children: jsx(EventHandlersContext.Provider, __assign({ value: eventHandlers }, { children: jsx(MenuList, __assign({}, restProps, { ariaLabel: ariaLabel || "Menu", externalRef: externalRef, containerRef: containerRef, onClose: onClose })) })) })) }))) })));
2110
- if (portal === true && anchorRef.current !== undefined) {
2114
+ if (portal === true && (anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== undefined) {
2111
2115
  portal = { target: anchorRef.current.ownerDocument.body };
2112
2116
  }
2113
- if (portal === true && typeof document !== "undefined") {
2114
- return createPortal(menuList, document.body);
2115
- }
2116
- else if (portal) {
2117
- return portal.target ? createPortal(menuList, portal.target) : portal.stablePosition ? null : menuList;
2117
+ if (portal) {
2118
+ if (typeof portal === "boolean") {
2119
+ if (portal && typeof document !== "undefined") {
2120
+ return createPortal(menuList, document.body);
2121
+ }
2122
+ }
2123
+ else {
2124
+ return portal.target ? createPortal(menuList, portal.target) : portal.stablePosition ? null : menuList;
2125
+ }
2118
2126
  }
2119
2127
  return menuList;
2120
- });
2121
- ControlledMenu.propTypes /* remove-proptypes */ = __assign(__assign({}, rootMenuPropTypes), { state: oneOf(values(MenuStateMap)), anchorPoint: exact({
2122
- x: number,
2123
- y: number
2124
- }), anchorRef: object, skipOpen: object, captureFocus: bool, menuItemFocus: exact({
2125
- position: oneOfType([string, number]),
2126
- alwaysUpdate: bool
2127
- }), onClose: func });
2128
-
2129
- var Menu = forwardRef(function Menu(_a, externalRef) {
2130
- var ariaLabel = _a["aria-label"]; _a.captureFocus; var menuButton = _a.menuButton, instanceRef = _a.instanceRef, onMenuChange = _a.onMenuChange, restProps = __rest(_a, ["aria-label", "captureFocus", "menuButton", "instanceRef", "onMenuChange"]);
2128
+ };
2129
+ var ControlledMenu = forwardRef(ControlledMenuFr);
2130
+
2131
+ function MenuFr(_a, externalRef) {
2132
+ var ariaLabel = _a["aria-label"], menuButton = _a.menuButton, instanceRef = _a.instanceRef, onMenuChange = _a.onMenuChange, restProps = __rest(_a, ["aria-label", "menuButton", "instanceRef", "onMenuChange"]);
2131
2133
  var _b = useMenuStateAndFocus(restProps), stateProps = _b[0], toggleMenu = _b[1], openMenu = _b[2];
2132
2134
  var isOpen = isMenuOpen(stateProps.state);
2133
2135
  var skipOpen = useRef(false);
@@ -2135,7 +2137,7 @@ var Menu = forwardRef(function Menu(_a, externalRef) {
2135
2137
  var handleClose = useCallback(function (e) {
2136
2138
  toggleMenu(false);
2137
2139
  if (e.key)
2138
- buttonRef.current.focus();
2140
+ buttonRef.current && buttonRef.current.focus();
2139
2141
  }, [toggleMenu]);
2140
2142
  var onClick = function (e) {
2141
2143
  if (skipOpen.current)
@@ -2156,10 +2158,11 @@ var Menu = forwardRef(function Menu(_a, externalRef) {
2156
2158
  }
2157
2159
  e.preventDefault();
2158
2160
  };
2161
+ // FIXME erk! button seems to be many types
2159
2162
  var button = safeCall(menuButton, { open: isOpen });
2160
2163
  if (!button || !button.type)
2161
2164
  throw new Error("Menu requires a menuButton prop.");
2162
- var buttonProps = __assign({ ref: useCombinedRef(button.ref, buttonRef) }, mergeProps({ onClick: onClick, onKeyDown: onKeyDown }, button.props));
2165
+ var buttonProps = __assign(__assign({ ref: useCombinedRef(button.ref, buttonRef) }, mergeProps({ onClick: onClick, onKeyDown: onKeyDown }, button.props)), { isOpen: false });
2163
2166
  if (getName(button.type) === "MenuButton") {
2164
2167
  buttonProps.isOpen = isOpen;
2165
2168
  }
@@ -2170,27 +2173,28 @@ var Menu = forwardRef(function Menu(_a, externalRef) {
2170
2173
  closeMenu: function () { return toggleMenu(false); }
2171
2174
  }); });
2172
2175
  return (jsxs(Fragment$1, { children: [renderButton, jsx(ControlledMenu, __assign({}, restProps, stateProps, { "aria-label": ariaLabel || (typeof button.props.children === "string" ? button.props.children : "Menu"), anchorRef: buttonRef, ref: externalRef, onClose: handleClose, skipOpen: skipOpen }))] }));
2173
- });
2174
- Menu.propTypes = __assign(__assign(__assign({}, rootMenuPropTypes), uncontrolledMenuPropTypes), { menuButton: oneOfType([element, func]).isRequired });
2176
+ }
2177
+ var Menu = forwardRef(MenuFr);
2175
2178
 
2176
- var SubMenu = withHovering("SubMenu", function SubMenu(_a) {
2177
- var ariaLabel = _a["aria-label"], className = _a.className, disabled = _a.disabled, direction = _a.direction, label = _a.label, openTrigger = _a.openTrigger, onMenuChange = _a.onMenuChange, isHovering = _a.isHovering, instanceRef = _a.instanceRef, itemRef = _a.itemRef; _a.captureFocus; _a.repositionFlag; var _b = _a.itemProps, itemProps = _b === void 0 ? {} : _b, restProps = __rest(_a, ["aria-label", "className", "disabled", "direction", "label", "openTrigger", "onMenuChange", "isHovering", "instanceRef", "itemRef", "captureFocus", "repositionFlag", "itemProps"]);
2179
+ var SubMenuFr = function (_a) {
2180
+ var ariaLabel = _a["aria-label"], className = _a.className, disabled = _a.disabled, direction = _a.direction, label = _a.label, openTrigger = _a.openTrigger, onMenuChange = _a.onMenuChange, isHovering = _a.isHovering, instanceRef = _a.instanceRef, menuItemRef = _a.menuItemRef, _b = _a.itemProps, itemProps = _b === void 0 ? {} : _b, restProps = __rest(_a, ["aria-label", "className", "disabled", "direction", "label", "openTrigger", "onMenuChange", "isHovering", "instanceRef", "menuItemRef", "itemProps"]);
2178
2181
  var settings = useContext(SettingsContext);
2179
2182
  var rootMenuRef = settings.rootMenuRef;
2180
2183
  var _c = useContext(ItemSettingsContext), submenuOpenDelay = _c.submenuOpenDelay, submenuCloseDelay = _c.submenuCloseDelay;
2181
2184
  var _d = useContext(MenuListContext), parentMenuRef = _d.parentMenuRef, parentDir = _d.parentDir, parentOverflow = _d.overflow;
2182
2185
  var _e = useContext(MenuListItemContext), isParentOpen = _e.isParentOpen, isSubmenuOpen = _e.isSubmenuOpen, setOpenSubmenuCount = _e.setOpenSubmenuCount, dispatch = _e.dispatch, updateItems = _e.updateItems;
2183
2186
  var isPortal = parentOverflow !== "visible";
2187
+ // FIXME Matt no idea what's going on here
2184
2188
  var _f = useMenuStateAndFocus(settings), stateProps = _f[0], toggleMenu = _f[1], _openMenu = _f[2];
2185
2189
  var state = stateProps.state;
2186
2190
  var isDisabled = !!disabled;
2187
2191
  var isOpen = isMenuOpen(state);
2188
2192
  var containerRef = useRef(null);
2189
- var timeoutId = useRef(0);
2193
+ var timeoutId = useRef();
2190
2194
  var stopTimer = function () {
2191
2195
  if (timeoutId.current) {
2192
2196
  clearTimeout(timeoutId.current);
2193
- timeoutId.current = 0;
2197
+ timeoutId.current = undefined;
2194
2198
  }
2195
2199
  };
2196
2200
  var openMenu = function () {
@@ -2202,7 +2206,7 @@ var SubMenu = withHovering("SubMenu", function SubMenu(_a) {
2202
2206
  setHover();
2203
2207
  !isDisabled && _openMenu.apply(void 0, args);
2204
2208
  };
2205
- var setHover = function () { return !isHovering && !isDisabled && dispatch(HoverActionTypes.SET, itemRef.current); };
2209
+ var setHover = function () { return !isHovering && !isDisabled && dispatch(HoverActionTypes.SET, menuItemRef === null || menuItemRef === void 0 ? void 0 : menuItemRef.current, 0); };
2206
2210
  var delayOpen = function (delay) {
2207
2211
  setHover();
2208
2212
  if (!openTrigger)
@@ -2221,7 +2225,7 @@ var SubMenu = withHovering("SubMenu", function SubMenu(_a) {
2221
2225
  var handlePointerLeave = function () {
2222
2226
  stopTimer();
2223
2227
  if (!isOpen)
2224
- dispatch(HoverActionTypes.UNSET, itemRef.current);
2228
+ dispatch(HoverActionTypes.UNSET, menuItemRef === null || menuItemRef === void 0 ? void 0 : menuItemRef.current, 0);
2225
2229
  };
2226
2230
  var handleKeyDown = function (e) {
2227
2231
  var handled = false;
@@ -2229,7 +2233,7 @@ var SubMenu = withHovering("SubMenu", function SubMenu(_a) {
2229
2233
  // LEFT key is bubbled up from submenu items
2230
2234
  case Keys.LEFT:
2231
2235
  if (isOpen) {
2232
- itemRef.current.focus();
2236
+ (menuItemRef === null || menuItemRef === void 0 ? void 0 : menuItemRef.current) && menuItemRef.current.focus();
2233
2237
  toggleMenu(false);
2234
2238
  handled = true;
2235
2239
  }
@@ -2256,19 +2260,19 @@ var SubMenu = withHovering("SubMenu", function SubMenu(_a) {
2256
2260
  break;
2257
2261
  }
2258
2262
  };
2259
- useItemEffect(isDisabled, itemRef, updateItems);
2263
+ useItemEffect(isDisabled, menuItemRef, updateItems);
2260
2264
  useMenuChange(onMenuChange, isOpen);
2261
2265
  useEffect(function () { return function () { return clearTimeout(timeoutId.current); }; }, []);
2262
2266
  useEffect(function () {
2263
2267
  // Don't set focus when parent menu is closed, otherwise focus will be lost
2264
2268
  // and onBlur event will be fired with relatedTarget setting as null.
2265
2269
  if (isHovering && isParentOpen) {
2266
- itemRef.current.focus();
2270
+ (menuItemRef === null || menuItemRef === void 0 ? void 0 : menuItemRef.current) && menuItemRef.current.focus();
2267
2271
  }
2268
2272
  else {
2269
2273
  toggleMenu(false);
2270
2274
  }
2271
- }, [isHovering, isParentOpen, toggleMenu, itemRef]);
2275
+ }, [isHovering, isParentOpen, toggleMenu, menuItemRef]);
2272
2276
  useEffect(function () {
2273
2277
  setOpenSubmenuCount(function (count) { return (isOpen ? count + 1 : Math.max(count - 1, 0)); });
2274
2278
  }, [setOpenSubmenuCount, isOpen]);
@@ -2282,7 +2286,7 @@ var SubMenu = withHovering("SubMenu", function SubMenu(_a) {
2282
2286
  },
2283
2287
  closeMenu: function () {
2284
2288
  if (isOpen) {
2285
- itemRef.current.focus();
2289
+ (menuItemRef === null || menuItemRef === void 0 ? void 0 : menuItemRef.current) && menuItemRef.current.focus();
2286
2290
  toggleMenu(false);
2287
2291
  }
2288
2292
  }
@@ -2301,36 +2305,40 @@ var SubMenu = withHovering("SubMenu", function SubMenu(_a) {
2301
2305
  onClick: function () { return openTrigger !== "none" && openMenu(); }
2302
2306
  }, restItemProps);
2303
2307
  var getMenuList = function () {
2304
- var menuList = (jsx(MenuList, __assign({}, restProps, stateProps, { ariaLabel: ariaLabel || (typeof label === "string" ? label : "Submenu"), anchorRef: itemRef, containerRef: isPortal ? rootMenuRef : containerRef, direction: direction || (parentDir === "right" || parentDir === "left" ? parentDir : "right"), parentScrollingRef: isPortal && parentMenuRef, isDisabled: isDisabled })));
2305
- var container = rootMenuRef.current;
2308
+ var menuList = (jsx(MenuList, __assign({}, restProps, stateProps, { ariaLabel: ariaLabel || (typeof label === "string" ? label : "Submenu"), anchorRef: menuItemRef, containerRef: isPortal ? rootMenuRef : containerRef, direction: direction || (parentDir === "right" || parentDir === "left" ? parentDir : "right"), parentScrollingRef: isPortal && parentMenuRef, isDisabled: isDisabled })));
2309
+ var container = rootMenuRef === null || rootMenuRef === void 0 ? void 0 : rootMenuRef.current;
2306
2310
  return isPortal && container ? createPortal(menuList, container) : menuList;
2307
2311
  };
2308
- return (jsxs("li", __assign({ className: useBEM({ block: menuClass, element: subMenuClass, className: className }), style: { position: "relative" }, role: "presentation", ref: containerRef, onKeyDown: handleKeyDown }, { children: [jsx("div", __assign({ role: "menuitem", "aria-haspopup": true, "aria-expanded": isOpen }, mergedItemProps, commonProps(isDisabled, isHovering), { ref: useCombinedRef(externalItemRef, itemRef), className: useBEM({
2312
+ return (jsxs("li", __assign({ className: useBEM({ block: menuClass, element: subMenuClass, className: className }), style: { position: "relative" }, role: "presentation", ref: containerRef, onKeyDown: handleKeyDown }, { children: [jsx("div", __assign({ role: "menuitem", "aria-haspopup": true, "aria-expanded": isOpen }, mergedItemProps, commonProps(isDisabled, isHovering), { ref: useCombinedRef(externalItemRef, menuItemRef), className: useBEM({
2309
2313
  block: menuClass,
2310
2314
  element: menuItemClass,
2311
2315
  modifiers: modifiers,
2312
2316
  className: itemClassName
2313
2317
  }) }, { children: useMemo(function () { return safeCall(label, modifiers); }, [label, modifiers]) })), state && getMenuList()] })));
2314
- });
2315
- SubMenu.propTypes = __assign(__assign(__assign({}, menuPropTypes), uncontrolledMenuPropTypes), { disabled: bool, openTrigger: oneOf(["none", "clickOnly"]), label: oneOfType([node, func]), itemProps: shape(__assign({}, stylePropTypes())) });
2318
+ };
2319
+ var SubMenu = withHovering("SubMenu", SubMenuFr);
2316
2320
 
2317
- var MenuItem = withHovering("MenuItem", function MenuItem(_a) {
2318
- var className = _a.className, value = _a.value, href = _a.href, type = _a.type, checked = _a.checked, disabled = _a.disabled, children = _a.children, onClick = _a.onClick, isHovering = _a.isHovering, itemRef = _a.itemRef, externalRef = _a.externalRef, restProps = __rest(_a, ["className", "value", "href", "type", "checked", "disabled", "children", "onClick", "isHovering", "itemRef", "externalRef"]);
2321
+ var MenuItemFr = function (_a) {
2322
+ var className = _a.className, value = _a.value, href = _a.href, type = _a.type, checked = _a.checked, disabled = _a.disabled, children = _a.children, onClick = _a.onClick, isHovering = _a.isHovering, menuItemRef = _a.menuItemRef, externalRef = _a.externalRef, restProps = __rest(_a, ["className", "value", "href", "type", "checked", "disabled", "children", "onClick", "isHovering", "menuItemRef", "externalRef"]);
2319
2323
  var isDisabled = !!disabled;
2320
- var _b = useItemState(itemRef, itemRef, isHovering, isDisabled), setHover = _b.setHover, restStateProps = __rest(_b, ["setHover"]);
2324
+ var _b = useItemState(menuItemRef, menuItemRef, isHovering, isDisabled), setHover = _b.setHover, restStateProps = __rest(_b, ["setHover"]);
2321
2325
  var eventHandlers = useContext(EventHandlersContext);
2322
2326
  var radioGroup = useContext(RadioGroupContext);
2323
2327
  var isRadio = type === "radio";
2324
2328
  var isCheckBox = type === "checkbox";
2325
2329
  var isAnchor = !!href && !isDisabled && !isRadio && !isCheckBox;
2326
2330
  var isChecked = isRadio ? radioGroup.value === value : isCheckBox ? !!checked : false;
2331
+ // FIXME handle click seems to be a combination of multiple event types
2327
2332
  var handleClick = function (e) {
2328
2333
  if (isDisabled) {
2329
2334
  e.stopPropagation();
2330
2335
  e.preventDefault();
2331
2336
  return;
2332
2337
  }
2333
- var event = { value: value, syntheticEvent: e };
2338
+ var event = {
2339
+ value: value,
2340
+ syntheticEvent: e
2341
+ };
2334
2342
  if (e.key !== undefined)
2335
2343
  event.key = e.key;
2336
2344
  if (isCheckBox)
@@ -2349,7 +2357,7 @@ var MenuItem = withHovering("MenuItem", function MenuItem(_a) {
2349
2357
  case Keys.ENTER:
2350
2358
  case Keys.SPACE:
2351
2359
  if (isAnchor) {
2352
- itemRef.current.click();
2360
+ (menuItemRef === null || menuItemRef === void 0 ? void 0 : menuItemRef.current) && menuItemRef.current.click();
2353
2361
  }
2354
2362
  else {
2355
2363
  handleClick(e);
@@ -2369,21 +2377,21 @@ var MenuItem = withHovering("MenuItem", function MenuItem(_a) {
2369
2377
  // 1. Preset props adhering to WAI-ARIA Authoring Practices.
2370
2378
  // 2. Merged outer and local props
2371
2379
  // 3. ref, className
2372
- var menuItemProps = __assign(__assign(__assign({ role: isRadio ? "menuitemradio" : isCheckBox ? "menuitemcheckbox" : "menuitem", "aria-checked": isRadio || isCheckBox ? isChecked : undefined }, mergedProps), commonProps(isDisabled, isHovering)), { ref: useCombinedRef(externalRef, itemRef), className: useBEM({ block: menuClass, element: menuItemClass, modifiers: modifiers, className: className }), children: useMemo(function () { return safeCall(children, modifiers); }, [children, modifiers]) });
2380
+ var menuItemProps = __assign(__assign(__assign({ role: isRadio ? "menuitemradio" : isCheckBox ? "menuitemcheckbox" : "menuitem", "aria-checked": isRadio || isCheckBox ? isChecked : undefined }, mergedProps), commonProps(isDisabled, isHovering)), { ref: useCombinedRef(externalRef, menuItemRef), className: useBEM({ block: menuClass, element: menuItemClass, modifiers: modifiers, className: className }), children: useMemo(function () { return safeCall(children, modifiers); }, [children, modifiers]) });
2373
2381
  if (isAnchor) {
2374
2382
  return (jsx("li", __assign({ role: "presentation" }, { children: jsx("a", __assign({ href: href }, menuItemProps)) })));
2375
2383
  }
2376
2384
  else {
2377
2385
  return jsx("li", __assign({}, menuItemProps));
2378
2386
  }
2379
- });
2380
- MenuItem.propTypes = __assign(__assign({}, stylePropTypes()), { value: any, href: string, type: oneOf(["checkbox", "radio"]), checked: bool, disabled: bool, children: oneOfType([node, func]), onClick: func });
2387
+ };
2388
+ var MenuItem = withHovering("MenuItem", MenuItemFr);
2381
2389
 
2382
- var FocusableItem = withHovering("FocusableItem", function FocusableItem(_a) {
2383
- var className = _a.className, disabled = _a.disabled, children = _a.children, isHovering = _a.isHovering, itemRef = _a.itemRef, externalRef = _a.externalRef, restProps = __rest(_a, ["className", "disabled", "children", "isHovering", "itemRef", "externalRef"]);
2390
+ var FocusableItemFr = function (_a) {
2391
+ var className = _a.className, disabled = _a.disabled, children = _a.children, isHovering = _a.isHovering, menuItemRef = _a.menuItemRef, externalRef = _a.externalRef, restProps = __rest(_a, ["className", "disabled", "children", "isHovering", "menuItemRef", "externalRef"]);
2384
2392
  var isDisabled = !!disabled;
2385
2393
  var ref = useRef(null);
2386
- var _b = useItemState(itemRef, ref, isHovering, isDisabled), setHover = _b.setHover, onPointerLeave = _b.onPointerLeave, restStateProps = __rest(_b, ["setHover", "onPointerLeave"]);
2394
+ var _b = useItemState(menuItemRef, ref, isHovering, isDisabled), setHover = _b.setHover, onPointerLeave = _b.onPointerLeave, restStateProps = __rest(_b, ["setHover", "onPointerLeave"]);
2387
2395
  var handleClose = useContext(EventHandlersContext).handleClose;
2388
2396
  var modifiers = useMemo(function () { return ({
2389
2397
  disabled: isDisabled,
@@ -2394,50 +2402,51 @@ var FocusableItem = withHovering("FocusableItem", function FocusableItem(_a) {
2394
2402
  return safeCall(children, __assign(__assign({}, modifiers), { ref: ref, closeMenu: handleClose }));
2395
2403
  }, [children, modifiers, handleClose]);
2396
2404
  var mergedProps = mergeProps(__assign(__assign({}, restStateProps), { onPointerLeave: function (e) { return onPointerLeave(e, true); }, onFocus: setHover }), restProps);
2397
- return (jsx("li", __assign({ role: "menuitem" }, mergedProps, commonProps(isDisabled), { ref: useCombinedRef(externalRef, itemRef), className: useBEM({ block: menuClass, element: menuItemClass, modifiers: modifiers, className: className }) }, { children: renderChildren })));
2398
- });
2399
- FocusableItem.propTypes = __assign(__assign({}, stylePropTypes()), { disabled: bool, children: func });
2405
+ return (jsx("li", __assign({ role: "menuitem" }, mergedProps, commonProps(isDisabled), { ref: useCombinedRef(externalRef, menuItemRef), className: useBEM({ block: menuClass, element: menuItemClass, modifiers: modifiers, className: className }) }, { children: renderChildren })));
2406
+ };
2407
+ var FocusableItem = withHovering("FocusableItem", FocusableItemFr);
2400
2408
 
2401
- var MenuDivider = memo(forwardRef(function MenuDivider(_a, externalRef) {
2409
+ var MenuDividerFr = function (_a, externalRef) {
2402
2410
  var className = _a.className, restProps = __rest(_a, ["className"]);
2403
2411
  return (jsx("li", __assign({ role: "separator" }, restProps, { ref: externalRef, className: useBEM({ block: menuClass, element: menuDividerClass, className: className }) })));
2404
- }));
2405
- MenuDivider.propTypes = __assign({}, stylePropTypes());
2412
+ };
2413
+ var MenuDivider = memo(forwardRef(MenuDividerFr));
2406
2414
 
2407
- var MenuHeader = memo(forwardRef(function MenuHeader(_a, externalRef) {
2415
+ var MenuHeaderFr = function (_a, externalRef) {
2408
2416
  var className = _a.className, restProps = __rest(_a, ["className"]);
2409
2417
  return (jsx("li", __assign({ role: "presentation" }, restProps, { ref: externalRef, className: useBEM({ block: menuClass, element: menuHeaderClass, className: className }) })));
2410
- }));
2411
- MenuHeader.propTypes = __assign({}, stylePropTypes());
2418
+ };
2419
+ var MenuHeader = memo(forwardRef(MenuHeaderFr));
2412
2420
 
2413
- var MenuGroup = forwardRef(function MenuGroup(_a, externalRef) {
2421
+ var MenuGroupFr = function (_a, externalRef) {
2414
2422
  var className = _a.className, style = _a.style, takeOverflow = _a.takeOverflow, restProps = __rest(_a, ["className", "style", "takeOverflow"]);
2415
2423
  var ref = useRef(null);
2416
2424
  var _b = useState(), overflowStyle = _b[0], setOverflowStyle = _b[1];
2417
2425
  var _c = useContext(MenuListContext), overflow = _c.overflow, overflowAmt = _c.overflowAmt;
2418
2426
  useIsomorphicLayoutEffect(function () {
2419
2427
  var maxHeight;
2420
- if (takeOverflow && overflowAmt >= 0) {
2428
+ if (takeOverflow && overflowAmt != null && overflowAmt >= 0 && ref.current) {
2429
+ // FIXME Matt added && ref.current
2421
2430
  maxHeight = ref.current.getBoundingClientRect().height - overflowAmt;
2422
2431
  if (maxHeight < 0)
2423
2432
  maxHeight = 0;
2424
2433
  }
2425
- setOverflowStyle(maxHeight >= 0 ? { maxHeight: maxHeight, overflow: overflow } : undefined);
2434
+ setOverflowStyle(maxHeight != null && maxHeight >= 0 ? { maxHeight: maxHeight, overflow: overflow } : undefined);
2426
2435
  }, [takeOverflow, overflow, overflowAmt]);
2427
2436
  useIsomorphicLayoutEffect(function () {
2428
- if (overflowStyle)
2437
+ if (overflowStyle && ref.current)
2429
2438
  ref.current.scrollTop = 0;
2430
2439
  }, [overflowStyle]);
2431
2440
  return (jsx("div", __assign({}, restProps, { ref: useCombinedRef(externalRef, ref), className: useBEM({ block: menuClass, element: menuGroupClass, className: className }), style: __assign(__assign({}, style), overflowStyle) })));
2432
- });
2433
- MenuGroup.propTypes = __assign(__assign({}, stylePropTypes()), { takeOverflow: bool });
2441
+ };
2442
+ var MenuGroup = forwardRef(MenuGroupFr);
2434
2443
 
2435
- var MenuRadioGroup = forwardRef(function MenuRadioGroup(_a, externalRef) {
2444
+ var MenuRadioGroupFr = function (_a, externalRef) {
2436
2445
  var ariaLabel = _a["aria-label"], className = _a.className, name = _a.name, value = _a.value, onRadioChange = _a.onRadioChange, restProps = __rest(_a, ["aria-label", "className", "name", "value", "onRadioChange"]);
2437
2446
  var contextValue = useMemo(function () { return ({ name: name, value: value, onRadioChange: onRadioChange }); }, [name, value, onRadioChange]);
2438
2447
  return (jsx(RadioGroupContext.Provider, __assign({ value: contextValue }, { children: jsx("li", __assign({ role: "presentation" }, { children: jsx("ul", __assign({ role: "group", "aria-label": ariaLabel || name || "Radio group" }, restProps, { ref: externalRef, className: useBEM({ block: menuClass, element: radioGroupClass, className: className }) })) })) })));
2439
- });
2440
- MenuRadioGroup.propTypes = __assign(__assign({}, stylePropTypes()), { name: string, value: any, onRadioChange: func });
2448
+ };
2449
+ var MenuRadioGroup = forwardRef(MenuRadioGroupFr);
2441
2450
 
2442
2451
  var useGridPopoverHook = function (props, save) {
2443
2452
  var cellEditorParams = props.cellEditorParams, saving = props.saving, updateValue = props.updateValue;
@@ -2491,7 +2500,18 @@ var GridRenderPopoutMenuCell = function (props) {
2491
2500
  var _a, _b, _c;
2492
2501
  var checkUpdating = useContext(UpdatingContext).checkUpdating;
2493
2502
  var isLoading = checkUpdating((_b = (_a = props.colDef) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : "", props.data.id);
2494
- var disabled = !((_c = props.colDef) === null || _c === void 0 ? void 0 : _c.editable);
2503
+ var editable = (_c = props.colDef) === null || _c === void 0 ? void 0 : _c.editable;
2504
+ var disabled = !(typeof editable === "function"
2505
+ ? editable({
2506
+ node: props.node,
2507
+ data: props.data,
2508
+ column: props.column,
2509
+ colDef: props.colDef,
2510
+ api: props.api,
2511
+ columnApi: props.columnApi,
2512
+ context: props.context
2513
+ })
2514
+ : editable);
2495
2515
  return (jsx(GridLoadableCell, __assign({ isLoading: isLoading, className: disabled ? "GridPopoutMenu-burgerDisabled" : "GridPopoutMenu-burger" }, { children: jsx(LuiIcon, { name: "ic_more_vert", alt: "More actions", size: "md" }) })));
2496
2516
  };
2497
2517
 
@@ -2525,7 +2545,7 @@ var GridFormMultiSelect = function (props) {
2525
2545
  }
2526
2546
  });
2527
2547
  }); }, [formProps, selectedValues]);
2528
- var popoverWrapper = useGridPopoverHook(props, save).popoverWrapper;
2548
+ var _e = useGridPopoverHook(props, save), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
2529
2549
  // Load up options list if it's async function
2530
2550
  useEffect(function () {
2531
2551
  var _a;
@@ -2574,7 +2594,7 @@ var GridFormMultiSelect = function (props) {
2574
2594
  return undefined;
2575
2595
  }
2576
2596
  var str = option.label || "";
2577
- return str.toLowerCase().indexOf(filter) === -1 ? option.value : undefined;
2597
+ return str.toLowerCase().indexOf(filter.trim()) === -1 ? option.value : undefined;
2578
2598
  })
2579
2599
  .filter(function (r) { return r !== undefined; }));
2580
2600
  }, [formProps.filtered, filter, options]);
@@ -2582,27 +2602,48 @@ var GridFormMultiSelect = function (props) {
2582
2602
  var _b;
2583
2603
  var ref = _a.ref;
2584
2604
  return (jsx("div", __assign({ style: { display: "flex", width: "100%" } }, { children: jsx("input", { autoFocus: true, className: "free-text-input", style: { border: "0px" }, ref: ref, type: "text", placeholder: (_b = formProps.filterPlaceholder) !== null && _b !== void 0 ? _b : "Placeholder", "data-testid": "filteredMenu-free-text-input", defaultValue: "", onChange: function (e) { return setFilter(e.target.value.toLowerCase()); } }) })));
2585
- } })), jsx(MenuDivider, {}, "$$divider_filter")] })), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
2605
+ } }), "filter"), jsx(MenuDivider, {}, "$$divider_filter")] })), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
2586
2606
  var _a;
2587
- return item.value === MenuSeparatorString$1 ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxs(Fragment, { children: [jsx(MenuItem, __assign({ onClick: function (e) {
2607
+ return item.value === MenuSeparatorString$1 ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxs(Fragment$1, { children: [jsx(MenuItem, __assign({ onClick: function (e) {
2588
2608
  e.keepOpen = true;
2589
- // onSelectMenuOption(itemIndex, e.value);
2590
- return false;
2591
- } }, { children: jsx(LuiCheckboxInput, { isChecked: selectedValues.includes(item.value), value: "".concat(item.value), label: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)), onChange: function (e) {
2592
- if (e.target.checked) {
2593
- setSelectedValues(__spreadArray(__spreadArray([], selectedValues, true), [item.value], false));
2609
+ if (selectedValues.includes(item.value)) {
2610
+ setSelectedValues(selectedValues.filter(function (value) { return value != item.value; }));
2611
+ }
2612
+ else {
2613
+ setSelectedValues(__spreadArray(__spreadArray([], selectedValues, true), [item.value], false));
2614
+ }
2615
+ }, onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () {
2616
+ return __generator(this, function (_a) {
2617
+ if (e.key === "Enter")
2618
+ triggerSave().then();
2619
+ else if (e.key === " ") {
2620
+ if (selectedValues.includes(item.value)) {
2621
+ setSelectedValues(selectedValues.filter(function (value) { return value != item.value; }));
2622
+ }
2623
+ else {
2624
+ setSelectedValues(__spreadArray(__spreadArray([], selectedValues, true), [item.value], false));
2625
+ }
2626
+ e.preventDefault();
2627
+ e.stopPropagation();
2594
2628
  }
2595
- else {
2596
- setSelectedValues(selectedValues.filter(function (value) { return value != item.value; }));
2629
+ return [2 /*return*/];
2630
+ });
2631
+ }); } }, { children: jsx(LuiCheckboxInput, { isChecked: selectedValues.includes(item.value), value: "".concat(item.value), label: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)), inputProps: {
2632
+ onClick: function (e) {
2633
+ e.preventDefault();
2634
+ e.stopPropagation();
2635
+ return false;
2597
2636
  }
2598
- } }) }), "".concat(item.value)), selectedValues.includes(item.value) && item.subComponent && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
2637
+ }, onChange: function () {
2638
+ /*Do nothing, change handled by menuItem*/
2639
+ } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
2599
2640
  return item.subComponent &&
2600
2641
  item.subComponent({
2601
2642
  setValue: function (value) {
2602
2643
  subSelectedValues.current[item.value] = value;
2603
2644
  }
2604
2645
  }, ref);
2605
- } }), "".concat(item.value, "_subcomponent")))] }));
2646
+ } }), "".concat(item.value, "_subcomponent")))] }, "".concat(index)));
2606
2647
  })] })) })));
2607
2648
  };
2608
2649
 
@@ -2989,7 +3030,7 @@ var GridFormDropDown = function (props) {
2989
3030
  }
2990
3031
  });
2991
3032
  }); }, [filteredValues, options, selectItemHandler, stopEditing]);
2992
- return popoverWrapper(jsxs(Fragment, { children: [formProps.filtered && (jsxs(Fragment, { children: [jsx(FocusableItem, __assign({ className: "filter-item", index: -1 }, { children: function (_a) {
3033
+ return popoverWrapper(jsxs(Fragment, { children: [formProps.filtered && (jsxs(Fragment, { children: [jsx(FocusableItem, __assign({ className: "filter-item" }, { children: function (_a) {
2993
3034
  var _b;
2994
3035
  var ref = _a.ref;
2995
3036
  return (jsx("div", __assign({ style: { display: "flex", width: "100%" } }, { children: jsx("input", { autoFocus: true, className: "free-text-input", style: { border: "0px" }, ref: ref, type: "text", placeholder: (_b = formProps.filterPlaceholder) !== null && _b !== void 0 ? _b : "Placeholder", "data-testid": "filteredMenu-free-text-input", defaultValue: filter, onChange: function (e) { return setFilter(e.target.value.toLowerCase()); }, onKeyDown: function (e) { return onFilterKeyDown(e); } }) })));
@@ -3151,5 +3192,5 @@ var GridPopoverTextInput = function (colDef) {
3151
3192
  })));
3152
3193
  };
3153
3194
 
3154
- export { ComponentLoadingWrapper, GenericMultiEditCellClass, Grid, GridCell, GridContext, GridContextProvider, GridFormDropDown, GridFormEditBearing, GridFormMessage, GridFormMultiSelect, GridFormPopoutMenu, GridFormTextArea, GridFormTextInput, GridHeaderSelect, GridIcon, GridLoadableCell, GridPopoutEditMultiSelect, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridRendererGenericCell, TextAreaInput, TextInputFormatted, UpdatingContext, UpdatingContextProvider, bearingCorrectionValueFormatter, bearingNumberParser, bearingStringValidator, bearingValueFormatter, convertDDToDMS, hasParentClass, isFloat, isNotEmpty, useGridPopoverHook, usePostSortRowsHook, wait };
3195
+ export { ComponentLoadingWrapper, ControlledMenu, FocusableItem, GenericMultiEditCellClass, Grid, GridCell, GridContext, GridContextProvider, GridFormDropDown, GridFormEditBearing, GridFormMessage, GridFormMultiSelect, GridFormPopoutMenu, GridFormTextArea, GridFormTextInput, GridHeaderSelect, GridIcon, GridLoadableCell, GridPopoutEditMultiSelect, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridRendererGenericCell, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuItem, MenuRadioGroup, SubMenu, TextAreaInput, TextInputFormatted, UpdatingContext, UpdatingContextProvider, bearingCorrectionValueFormatter, bearingNumberParser, bearingStringValidator, bearingValueFormatter, convertDDToDMS, hasParentClass, isFloat, isNotEmpty, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait };
3155
3196
  //# sourceMappingURL=step-ag-grid.esm.js.map