@linzjs/step-ag-grid 17.0.7 → 17.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
2
  import { LuiMiniSpinner, LuiIcon, LuiButton, LuiCheckboxInput, LuiButtonGroup } from '@linzjs/lui';
3
3
  import { AgGridReact } from 'ag-grid-react';
4
4
  import { negate, isEmpty, findIndex, defer as defer$1, debounce as debounce$1, xorBy, last, difference, omit, sortBy, delay, partition, pick, groupBy, fromPairs, toPairs, isEqual, compact, filter, sumBy, pull, remove, castArray, flatten } from 'lodash-es';
5
- import { createContext, useContext, useRef, useEffect, useCallback, useState, useMemo, useLayoutEffect, memo, forwardRef, useReducer, cloneElement, useImperativeHandle, Fragment } from 'react';
5
+ import React, { createContext, useContext, useRef, useEffect, useCallback, useState, useMemo, useLayoutEffect, memo, forwardRef, useReducer, cloneElement, useImperativeHandle, Fragment } from 'react';
6
6
  import { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
7
7
  import * as testUtils from 'react-dom/test-utils';
8
8
  import 'react-dom/client';
@@ -1688,7 +1688,7 @@ const MenuList = ({ ariaLabel, menuClassName, menuStyle, arrowClassName, arrowSt
1688
1688
  }, ref: arrowRef })), jsx(MenuListContext.Provider, { value: listContext, children: jsx(MenuListItemContext.Provider, { value: itemContext, children: jsx(HoverItemContext.Provider, { value: hoverItem, children: children }) }) })] }));
1689
1689
  };
1690
1690
 
1691
- const ControlledMenuFr = ({ "aria-label": ariaLabel, className, containerProps, initialMounted, unmountOnClose, transition, transitionTimeout, boundingBoxRef, boundingBoxPadding, reposition = "auto", submenuOpenDelay = 300, submenuCloseDelay = 150, skipOpen, viewScroll = "initial", portal, theming, onItemClick, onClose, saveButtonRef, closeMenuExclusionClassName, ...restProps }, externalRef) => {
1691
+ const ControlledMenuFr = ({ "aria-label": ariaLabel, className, containerProps, initialMounted, unmountOnClose, transition, transitionTimeout, boundingBoxRef, boundingBoxPadding, reposition = "auto", submenuOpenDelay = 300, submenuCloseDelay = 150, skipOpen, viewScroll = "initial", portal, theming, onItemClick, onClose, saveButtonRef, ...restProps }, externalRef) => {
1692
1692
  const containerRef = useRef();
1693
1693
  const scrollNodesRef = useRef({});
1694
1694
  const { anchorRef, state } = restProps;
@@ -1715,8 +1715,7 @@ const ControlledMenuFr = ({ "aria-label": ariaLabel, className, containerProps,
1715
1715
  reposition,
1716
1716
  viewScroll,
1717
1717
  ]);
1718
- const isWithinMenu = useCallback((target) => hasParentClass("szh-menu--state-open", target) ||
1719
- (closeMenuExclusionClassName && hasParentClass(closeMenuExclusionClassName, target)), [closeMenuExclusionClassName]);
1718
+ const isWithinMenu = useCallback((target) => hasParentClass("szh-menu--state-open", target), []);
1720
1719
  const handleScreenEventForSave = useCallback((ev) => {
1721
1720
  if (!isWithinMenu(ev.target)) {
1722
1721
  ev.preventDefault();
@@ -3408,7 +3407,7 @@ const useGridPopoverHook = (props) => {
3408
3407
  if (event.reason === CloseReason.BLUR)
3409
3408
  return;
3410
3409
  triggerSave(event.reason).then();
3411
- }, viewScroll: "auto", dontShrinkIfDirectionIsTop: true, className: props.className, closeMenuExclusionClassName: "ReactModal__Content", children: [saving && ( // This is the overlay that prevents editing when the editor is saving
3410
+ }, viewScroll: "auto", dontShrinkIfDirectionIsTop: true, className: props.className, children: [saving && ( // This is the overlay that prevents editing when the editor is saving
3412
3411
  jsx("div", { className: "ComponentLoadingWrapper-saveOverlay" })), children, jsx("button", { ref: saveButtonRef, "data-reason": "", onClick: (e) => {
3413
3412
  let reason = e.currentTarget.getAttribute("data-reason") ?? undefined;
3414
3413
  if (props.dontSaveOnExternalClick && reason === CloseReason.BLUR) {
@@ -3759,6 +3758,7 @@ const GridFormMultiSelect = (props) => {
3759
3758
  const { selectedRows, data } = useGridPopoverContext();
3760
3759
  const subComponentIsValidRef = useRef({});
3761
3760
  const optionsInitialising = useRef(false);
3761
+ const firstInputSubComponent = useRef(null);
3762
3762
  const [filter, setFilter] = useState("");
3763
3763
  const [initialValues, setInitialValues] = useState("");
3764
3764
  const [options, setOptions] = useState();
@@ -3834,7 +3834,12 @@ const GridFormMultiSelect = (props) => {
3834
3834
  return popoverWrapper(jsx(ComponentLoadingWrapper, { loading: !options, className: "GridFormMultiSelect-container", children: options && (jsxs(Fragment$1, { children: [props.filtered && (jsx(FilterInput, { ...{ headerGroups, options, setOptions, filter, setFilter, triggerSave }, filterHelpText: props.filterHelpText, onSelectFilter: props.onSelectFilter, filterPlaceholder: props.filterPlaceholder })), headerGroups &&
3835
3835
  (isEmpty(headerGroups) || !toPairs(headerGroups).some(([_, options]) => !isEmpty(options))) && (jsx(MenuItem, { className: "GridMultiSelect-noOptions", disabled: true, children: props.noOptionsMessage ?? "No Options" }, "noOptions")), headerGroups && !isEmpty(headerGroups) && (jsx("div", { className: "GridFormMultiSelect-options", children: headers.map((header, index) => {
3836
3836
  const subOptions = headerGroups[`${header.filter}`];
3837
- return (!isEmpty(subOptions) && (jsxs(Fragment, { children: [header.header && jsx(MenuHeader, { children: header.header }), subOptions.map((item, index) => item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, `div_${index}`)) : (jsxs(Fragment, { children: [jsx(MenuRadioItem, { item: item, options: options, setOptions: setOptions }), item.checked && item.subComponent && (jsx(MenuSubComponent, { ...{ item, options, setOptions, data, triggerSave }, subComponentIsValid: subComponentIsValidRef.current }))] }, `val_${item.value}`)))] }, `group_${index}`)));
3837
+ return (!isEmpty(subOptions) && (jsxs(Fragment, { children: [header.header && jsx(MenuHeader, { children: header.header }), subOptions.map((item, index) => item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, `div_${index}`)) : (jsxs(Fragment, { children: [jsx(MenuRadioItem, { item: item, options: options, setOptions: setOptions, onChecked: () => {
3838
+ // Default to focus on first input in subComponent
3839
+ defer$1(() => {
3840
+ firstInputSubComponent.current?.focus();
3841
+ });
3842
+ } }), item.checked && item.subComponent && (jsx(MenuSubComponent, { ...{ item, options, setOptions, data, triggerSave }, ref: firstInputSubComponent, subComponentIsValid: subComponentIsValidRef.current }))] }, `val_${item.value}`)))] }, `group_${index}`)));
3838
3843
  }) }))] })) }));
3839
3844
  };
3840
3845
  const FilterInput = (props) => {
@@ -3923,6 +3928,7 @@ const MenuRadioItem = (props) => {
3923
3928
  e.keepOpen = true;
3924
3929
  toggleValue(item);
3925
3930
  }
3931
+ item.checked && props.onChecked && props.onChecked();
3926
3932
  }, children: jsx(LuiCheckboxInput, { isChecked: item.checked ?? false, value: `${item.value}`, label: jsxs(Fragment$1, { children: [item.warning && jsx(GridIcon, { icon: "ic_warning_outline", title: item.warning }), item.label ?? (item.value == null ? `<${item.value}>` : `${item.value}`)] }), inputProps: {
3927
3933
  onClick: (e) => {
3928
3934
  // Click is handled by MenuItem onClick
@@ -3933,9 +3939,22 @@ const MenuRadioItem = (props) => {
3933
3939
  /*Do nothing, change handled by menuItem*/
3934
3940
  } }) }));
3935
3941
  };
3936
- const MenuSubComponent = (props) => {
3942
+ const MenuSubComponent = React.forwardRef(MenuSubComponentFr);
3943
+ function MenuSubComponentFr(props, ref) {
3937
3944
  const { data, item, options, setOptions, subComponentIsValid, triggerSave } = props;
3938
- return (jsx(FocusableItem, { className: "LuiDeprecatedForms", children: () => (jsx(GridSubComponentContext.Provider, { value: {
3945
+ const focusableRef = React.useRef(null);
3946
+ useEffect(() => {
3947
+ if (focusableRef.current) {
3948
+ const firstInputElement = focusableRef.current.querySelectorAll("input")[0] ?? null;
3949
+ if (typeof ref === "function") {
3950
+ ref(firstInputElement);
3951
+ }
3952
+ else if (ref) {
3953
+ ref.current = firstInputElement;
3954
+ }
3955
+ }
3956
+ }, [ref]);
3957
+ return (jsx(FocusableItem, { className: "LuiDeprecatedForms", ref: focusableRef, children: () => (jsx(GridSubComponentContext.Provider, { value: {
3939
3958
  context: { options },
3940
3959
  data,
3941
3960
  value: item.subValue,
@@ -3948,7 +3967,7 @@ const MenuSubComponent = (props) => {
3948
3967
  },
3949
3968
  triggerSave,
3950
3969
  }, children: jsx("div", { className: "subComponent", children: item.subComponent && jsx(item.subComponent, {}) }) })) }, `${item.value}_subcomponent`));
3951
- };
3970
+ }
3952
3971
 
3953
3972
  const GridFormMultiSelectGrid = (props) => {
3954
3973
  const { selectedRows } = useGridPopoverContext();