@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,4 +1,3 @@
1
- // @ts-nocheck
2
1
  import { useState, useReducer, useEffect, useRef, useMemo, useCallback, useContext } from "react";
3
2
  import { flushSync } from "react-dom";
4
3
  import { useBEM, useCombinedRef, useLayoutEffect, useItems } from "../hooks";
@@ -23,6 +22,7 @@ import {
23
22
  MenuListItemContext,
24
23
  HoverItemContext,
25
24
  } from "../utils";
25
+ import { ControlledMenuProps, MenuDirection } from "../types";
26
26
 
27
27
  export const MenuList = ({
28
28
  ariaLabel,
@@ -52,10 +52,10 @@ export const MenuList = ({
52
52
  children,
53
53
  onClose,
54
54
  ...restProps
55
- }) => {
55
+ }: ControlledMenuProps) => {
56
56
  const [menuPosition, setMenuPosition] = useState({ x: 0, y: 0 });
57
- const [arrowPosition, setArrowPosition] = useState({});
58
- const [overflowData, setOverflowData] = useState();
57
+ const [arrowPosition, setArrowPosition] = useState({ x: 0, y: 0 });
58
+ const [overflowData, setOverflowData] = useState<{ height: number; overflowAmt: number | undefined }>();
59
59
  const [expandedDirection, setExpandedDirection] = useState(direction);
60
60
  const [openSubmenuCount, setOpenSubmenuCount] = useState(0);
61
61
  const [reposSubmenu, forceReposSubmenu] = useReducer((c) => c + 1, 1);
@@ -70,9 +70,9 @@ export const MenuList = ({
70
70
  viewScroll,
71
71
  } = useContext(SettingsContext);
72
72
  const reposFlag = useContext(MenuListContext).reposSubmenu || repositionFlag;
73
- const menuRef = useRef(null);
74
- const focusRef = useRef();
75
- const arrowRef = useRef();
73
+ const menuRef = useRef<HTMLUListElement>({} as HTMLUListElement);
74
+ const focusRef = useRef<HTMLDivElement>(null);
75
+ const arrowRef = useRef<HTMLDivElement>(null);
76
76
  const prevOpen = useRef(false);
77
77
  const latestMenuSize = useRef({ width: 0, height: 0 });
78
78
  const latestHandlePosition = useRef(() => {});
@@ -83,34 +83,37 @@ export const MenuList = ({
83
83
  const closeTransition = getTransition(transition, "close");
84
84
  const scrollNodes = scrollNodesRef.current;
85
85
 
86
- const onKeyDown = (e) => {
86
+ const onKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {
87
+ const elementTarget = e.target instanceof HTMLElement ? (e.target as HTMLElement) : null;
87
88
  const isTextInputTarget =
88
- e.target.nodeName === "TEXTAREA" || (e.target.nodeName === "INPUT" && e.target.getAttribute("type") === "text");
89
+ elementTarget &&
90
+ (elementTarget.nodeName === "TEXTAREA" ||
91
+ (elementTarget.nodeName === "INPUT" && elementTarget.getAttribute("type") === "text"));
89
92
  switch (e.key) {
90
93
  case Keys.HOME:
91
94
  // Don't eat home/end events on inputs
92
95
  if (isTextInputTarget) return;
93
- dispatch(HoverActionTypes.FIRST);
96
+ dispatch(HoverActionTypes.FIRST, null, 0);
94
97
  break;
95
98
 
96
99
  case Keys.END:
97
100
  // Don't eat home/end events on inputs
98
101
  if (isTextInputTarget) return;
99
- dispatch(HoverActionTypes.LAST);
102
+ dispatch(HoverActionTypes.LAST, null, 0);
100
103
  break;
101
104
 
102
105
  case Keys.UP:
103
- dispatch(HoverActionTypes.DECREASE, hoverItem);
106
+ dispatch(HoverActionTypes.DECREASE, hoverItem, 0);
104
107
  break;
105
108
 
106
109
  case Keys.DOWN:
107
- dispatch(HoverActionTypes.INCREASE, hoverItem);
110
+ dispatch(HoverActionTypes.INCREASE, hoverItem, 0);
108
111
  break;
109
112
 
110
113
  // prevent browser from scrolling the page when SPACE is pressed
111
114
  case Keys.SPACE:
112
115
  // Don't preventDefault on children of FocusableItem
113
- if (e.target && e.target.className.indexOf(menuClass) !== -1) {
116
+ if (elementTarget && elementTarget.className.includes(menuClass)) {
114
117
  e.preventDefault();
115
118
  }
116
119
  return;
@@ -125,15 +128,15 @@ export const MenuList = ({
125
128
 
126
129
  const onAnimationEnd = () => {
127
130
  if (state === "closing") {
128
- setOverflowData(); // reset overflowData after closing
131
+ setOverflowData(undefined); // reset overflowData after closing
129
132
  }
130
133
 
131
- safeCall(endTransition);
134
+ endTransition && safeCall(endTransition);
132
135
  };
133
136
 
134
137
  const handlePosition = useCallback(
135
- (noOverflowCheck) => {
136
- if (!containerRef.current) {
138
+ (noOverflowCheck?: boolean) => {
139
+ if (!containerRef?.current) {
137
140
  if (process.env.NODE_ENV !== "production") {
138
141
  console.error(
139
142
  '[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',
@@ -146,12 +149,16 @@ export const MenuList = ({
146
149
  scrollNodes.menu =
147
150
  (boundingBoxRef
148
151
  ? boundingBoxRef.current // user explicitly sets boundingBoxRef
149
- : getScrollAncestor(rootMenuRef.current)) || window; // try to discover bounding box automatically
152
+ : getScrollAncestor(rootMenuRef?.current)) || window; // try to discover bounding box automatically
150
153
  }
151
154
 
152
155
  const positionHelpers = getPositionHelpers(containerRef, menuRef, scrollNodes.menu, boundingBoxPadding);
153
156
  const { menuRect } = positionHelpers;
154
- let results = { computedDirection: "bottom" };
157
+ let results: { computedDirection: MenuDirection; arrowX?: number; arrowY?: number; x: number; y: number } = {
158
+ computedDirection: "bottom",
159
+ x: 0,
160
+ y: 0,
161
+ };
155
162
  if (anchorPoint) {
156
163
  results = positionContextMenu({ positionHelpers, anchorPoint });
157
164
  } else if (anchorRef) {
@@ -167,13 +174,14 @@ export const MenuList = ({
167
174
  positionHelpers,
168
175
  });
169
176
  }
170
- let { arrowX, arrowY, x, y, computedDirection } = results;
177
+ let { y } = results;
178
+ const { x, arrowX, arrowY, computedDirection } = results;
171
179
  let menuHeight = menuRect.height;
172
180
 
173
181
  if (!noOverflowCheck && overflow !== "visible") {
174
182
  const { getTopOverflow, getBottomOverflow } = positionHelpers;
175
183
 
176
- let height, overflowAmt;
184
+ let height: number | undefined, overflowAmt: number | undefined;
177
185
  const prevHeight = latestMenuSize.current.height;
178
186
  const bottomOverflow = getBottomOverflow(y);
179
187
  // When bottomOverflow is 0, menu is on the bottom edge of viewport
@@ -192,16 +200,16 @@ export const MenuList = ({
192
200
  }
193
201
  }
194
202
 
195
- if (height >= 0) {
203
+ if (height != null && height >= 0) {
196
204
  // To avoid triggering reposition in the next ResizeObserver callback
197
205
  menuHeight = height;
198
206
  setOverflowData({ height, overflowAmt });
199
207
  } else {
200
- setOverflowData();
208
+ setOverflowData(undefined);
201
209
  }
202
210
  }
203
211
 
204
- if (arrow) setArrowPosition({ x: arrowX, y: arrowY });
212
+ if (arrow) setArrowPosition({ x: arrowX ?? 0, y: arrowY ?? 0 });
205
213
  setMenuPosition({ x, y });
206
214
  setExpandedDirection(computedDirection);
207
215
  latestMenuSize.current = { width: menuRect.width, height: menuHeight };
@@ -267,11 +275,11 @@ export const MenuList = ({
267
275
  };
268
276
 
269
277
  const scrollObservers = scrollNodes.anchors.concat(viewScroll !== "initial" ? menuScroll : []);
270
- scrollObservers.forEach((o) => o.addEventListener("scroll", handleScroll));
278
+ scrollObservers.forEach((o: any) => o.addEventListener("scroll", handleScroll));
271
279
  return () => scrollObservers.forEach((o) => o.removeEventListener("scroll", handleScroll));
272
280
  }, [rootAnchorRef, scrollNodes, isOpen, onClose, viewScroll, handlePosition]);
273
281
 
274
- const hasOverflow = !!overflowData && overflowData.overflowAmt > 0;
282
+ const hasOverflow = !!overflowData && overflowData.overflowAmt != null && overflowData.overflowAmt > 0;
275
283
  useEffect(() => {
276
284
  if (hasOverflow || !isOpen || !parentScrollingRef) return;
277
285
 
@@ -313,18 +321,18 @@ export const MenuList = ({
313
321
 
314
322
  useEffect(() => {
315
323
  if (!isOpen) {
316
- dispatch(HoverActionTypes.RESET);
317
- if (!closeTransition) setOverflowData();
318
- return;
324
+ dispatch(HoverActionTypes.RESET, undefined, 0);
325
+ if (!closeTransition) setOverflowData(undefined);
326
+ return () => {};
319
327
  }
320
328
 
321
329
  const { position, alwaysUpdate } = menuItemFocus || {};
322
330
  const setItemFocus = () => {
323
331
  if (position === FocusPositions.FIRST) {
324
- dispatch(HoverActionTypes.FIRST);
332
+ dispatch(HoverActionTypes.FIRST, undefined, 0);
325
333
  } else if (position === FocusPositions.LAST) {
326
- dispatch(HoverActionTypes.LAST);
327
- } else if (position >= -1) {
334
+ dispatch(HoverActionTypes.LAST, undefined, 0);
335
+ } else if (typeof position === "number" && position >= -1) {
328
336
  dispatch(HoverActionTypes.SET_INDEX, undefined, position);
329
337
  }
330
338
  };
@@ -337,7 +345,22 @@ export const MenuList = ({
337
345
  () => {
338
346
  // If focus has already been set to a children element, don't set focus on menu or item
339
347
  if (!menuRef.current.contains(document.activeElement)) {
340
- focusRef.current.focus();
348
+ // Handle popover portal focus
349
+ const popupElement = focusRef.current?.nextSibling;
350
+ if (popupElement instanceof Element) {
351
+ const input = popupElement.querySelectorAll("input,textarea")[0] as HTMLElement;
352
+ if (input) {
353
+ input.focus();
354
+ // Text areas should start at end
355
+ if (input instanceof HTMLTextAreaElement) {
356
+ input.selectionStart = input.value.length;
357
+ }
358
+ } else {
359
+ focusRef.current?.focus();
360
+ }
361
+ } else {
362
+ focusRef.current?.focus();
363
+ }
341
364
  setItemFocus();
342
365
  }
343
366
  },
@@ -346,6 +369,7 @@ export const MenuList = ({
346
369
 
347
370
  return () => clearTimeout(id);
348
371
  }
372
+ return () => {};
349
373
  }, [isOpen, openTransition, closeTransition, captureFocus, menuItemFocus, dispatch]);
350
374
 
351
375
  const isSubmenuOpen = openSubmenuCount > 0;
@@ -360,7 +384,8 @@ export const MenuList = ({
360
384
  [isOpen, isSubmenuOpen, dispatch, updateItems],
361
385
  );
362
386
 
363
- let maxHeight, overflowAmt;
387
+ let maxHeight: number | undefined;
388
+ let overflowAmt: number | undefined;
364
389
  if (overflowData) {
365
390
  setDownOverflow ? (overflowAmt = overflowData.overflowAmt) : (maxHeight = overflowData.height);
366
391
  }
@@ -375,7 +400,7 @@ export const MenuList = ({
375
400
  }),
376
401
  [reposSubmenu, overflow, overflowAmt, expandedDirection],
377
402
  );
378
- const overflowStyle = maxHeight >= 0 ? { maxHeight, overflow } : undefined;
403
+ const overflowStyle = maxHeight != null && maxHeight >= 0 ? { maxHeight, overflow } : undefined;
379
404
 
380
405
  const modifiers = useMemo(
381
406
  () => ({
@@ -1,13 +1,57 @@
1
- // @ts-nocheck
2
- import { forwardRef, useMemo } from "react";
3
- import { any, string, func } from "prop-types";
1
+ import { ForwardedRef, forwardRef, ReactNode, useMemo } from "react";
4
2
  import { useBEM } from "../hooks";
5
- import { stylePropTypes, menuClass, radioGroupClass, RadioGroupContext } from "../utils";
3
+ import { menuClass, radioGroupClass, RadioGroupContext } from "../utils";
4
+ import { BaseProps, Event, EventHandler } from "../types";
6
5
 
7
- export const MenuRadioGroup = forwardRef(function MenuRadioGroup(
8
- { "aria-label": ariaLabel, className, name, value, onRadioChange, ...restProps },
9
- externalRef,
10
- ) {
6
+ export interface RadioChangeEvent extends Event {
7
+ /**
8
+ * The `name` prop passed to the `MenuRadioGroup` when the menu item is in a radio group.
9
+ */
10
+ name?: string;
11
+ /**
12
+ * Set this property on event object to control whether to keep menu open after menu item is activated.
13
+ * Leaving it `undefined` will behave in accordance with WAI-ARIA Authoring Practices.
14
+ */
15
+ keepOpen?: boolean;
16
+ /**
17
+ * Setting this property on event object to `true` will skip `onItemClick` event on root menu component.
18
+ */
19
+ stopPropagation?: boolean;
20
+ /**
21
+ * DOM event object (React synthetic event)
22
+ */
23
+ syntheticEvent: MouseEvent | KeyboardEvent;
24
+ }
25
+
26
+ //
27
+ // MenuRadioGroup
28
+ // ----------------------------------------------------------------------
29
+ export interface MenuRadioGroupProps extends BaseProps {
30
+ /**
31
+ * Optionally set the radio group name.
32
+ *
33
+ * The name will be passed to the `onRadioChange` event.
34
+ * It's useful for identifying radio groups if you attach the same event handler to multiple groups.
35
+ */
36
+ name?: string;
37
+ /**
38
+ * Set value of the radio group.
39
+ *
40
+ * The child menu item which has the same value (strict equality ===) as the
41
+ * radio group is marked as checked.
42
+ */
43
+ value?: any;
44
+ children?: ReactNode;
45
+ /**
46
+ * Event fired when a child menu item is clicked (selected).
47
+ */
48
+ onRadioChange?: EventHandler<RadioChangeEvent>;
49
+ }
50
+
51
+ export const MenuRadioGroupFr = (
52
+ { "aria-label": ariaLabel, className, name, value, onRadioChange, ...restProps }: MenuRadioGroupProps,
53
+ externalRef: ForwardedRef<HTMLUListElement>,
54
+ ) => {
11
55
  const contextValue = useMemo(() => ({ name, value, onRadioChange }), [name, value, onRadioChange]);
12
56
 
13
57
  return (
@@ -23,11 +67,6 @@ export const MenuRadioGroup = forwardRef(function MenuRadioGroup(
23
67
  </li>
24
68
  </RadioGroupContext.Provider>
25
69
  );
26
- });
27
-
28
- MenuRadioGroup.propTypes = {
29
- ...stylePropTypes(),
30
- name: string,
31
- value: any,
32
- onRadioChange: func,
33
70
  };
71
+
72
+ export const MenuRadioGroup = forwardRef(MenuRadioGroupFr);