@linzjs/step-ag-grid 2.5.0 → 3.0.1

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 (39) hide show
  1. package/dist/index.js +361 -282
  2. package/dist/index.js.map +1 -1
  3. package/dist/src/components/GridCell.d.ts +4 -7
  4. package/dist/src/components/gridForm/GridFormDropDown.d.ts +1 -1
  5. package/dist/src/components/gridForm/GridFormEditBearing.d.ts +1 -1
  6. package/dist/src/components/gridForm/GridFormMessage.d.ts +3 -3
  7. package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +2 -2
  8. package/dist/src/components/gridForm/GridFormPopoverMenu.d.ts +8 -3
  9. package/dist/src/components/gridForm/GridFormSubComponentTextInput.d.ts +1 -1
  10. package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -1
  11. package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -1
  12. package/dist/src/contexts/GridPopoverContext.d.ts +10 -6
  13. package/dist/src/contexts/GridPopoverContextProvider.d.ts +3 -1
  14. package/dist/src/lui/TextInputFormatted.d.ts +0 -1
  15. package/dist/step-ag-grid.esm.js +362 -283
  16. package/dist/step-ag-grid.esm.js.map +1 -1
  17. package/package.json +1 -1
  18. package/src/components/GridCell.tsx +9 -33
  19. package/src/components/GridPopoverHook.tsx +4 -8
  20. package/src/components/GridSubComponentTextArea.tsx +0 -6
  21. package/src/components/gridForm/GridFormDropDown.tsx +35 -37
  22. package/src/components/gridForm/GridFormEditBearing.tsx +12 -8
  23. package/src/components/gridForm/GridFormMessage.tsx +8 -6
  24. package/src/components/gridForm/GridFormMultiSelect.tsx +56 -48
  25. package/src/components/gridForm/GridFormPopoverMenu.tsx +112 -29
  26. package/src/components/gridForm/GridFormSubComponentTextInput.tsx +2 -1
  27. package/src/components/gridForm/GridFormTextArea.tsx +11 -9
  28. package/src/components/gridForm/GridFormTextInput.tsx +13 -16
  29. package/src/contexts/GridPopoverContext.tsx +18 -9
  30. package/src/contexts/GridPopoverContextProvider.tsx +24 -27
  31. package/src/lui/TextAreaInput.tsx +13 -1
  32. package/src/lui/TextInputFormatted.tsx +3 -2
  33. package/src/react-menu3/components/MenuList.tsx +42 -10
  34. package/src/react-menu3/contexts/SettingsContext.ts +1 -1
  35. package/src/stories/grid/FormTest.tsx +17 -15
  36. package/src/stories/grid/GridPopoutEditDropDown.stories.tsx +3 -1
  37. package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +0 -1
  38. package/src/stories/grid/GridPopoutEditMultiSelect.stories.tsx +3 -3
  39. package/src/stories/grid/GridReadOnly.stories.tsx +15 -5
@@ -1,6 +1,6 @@
1
1
  import { useMemo, useLayoutEffect, useEffect, createContext, memo, forwardRef, useRef, useContext, useState, useCallback, useReducer, cloneElement, useImperativeHandle, Fragment } from 'react';
2
2
  import { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
3
- import { findIndex, isEmpty, castArray, remove, flatten, delay, sortBy, last, difference, xorBy, pickBy, pick } from 'lodash-es';
3
+ import { findIndex, debounce, isEmpty, castArray, remove, flatten, delay, sortBy, last, difference, xorBy, fromPairs, omit, pick, toPairs, isEqual } from 'lodash-es';
4
4
  import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
5
5
  import { AgGridReact } from 'ag-grid-react';
6
6
  import { LuiMiniSpinner, LuiIcon, LuiCheckboxInput, LuiButton } from '@linzjs/lui';
@@ -901,7 +901,7 @@ var positionMenu = function (props) {
901
901
 
902
902
  var MenuListContext = createContext({});
903
903
 
904
- // FIXME hacking a default context in here is probably bad
904
+ // FIXME hacking a default context in here is probably bad, but the context is mess
905
905
  var SettingsContext = createContext({});
906
906
 
907
907
  var MenuList = function (_a) {
@@ -919,6 +919,7 @@ var MenuList = function (_a) {
919
919
  var focusRef = useRef(null);
920
920
  var arrowRef = useRef(null);
921
921
  var prevOpen = useRef(false);
922
+ var latestWindowSize = useRef({ width: 0, height: 0 });
922
923
  var latestMenuSize = useRef({ width: 0, height: 0 });
923
924
  var latestHandlePosition = useRef(function () { });
924
925
  var _t = useItems(menuRef, focusRef), hoverItem = _t.hoverItem, dispatch = _t.dispatch, updateItems = _t.updateItems;
@@ -1144,6 +1145,32 @@ var MenuList = function (_a) {
1144
1145
  resizeObserver.observe(observeTarget, { box: "border-box" });
1145
1146
  return function () { return resizeObserver.unobserve(observeTarget); };
1146
1147
  }, [reposition]);
1148
+ // Matt added window resize observer
1149
+ useEffect(function () {
1150
+ if (typeof ResizeObserver !== "function" || reposition === "initial")
1151
+ return;
1152
+ var callback = debounce(function () {
1153
+ var _a = menuRef.current.ownerDocument.body.getBoundingClientRect(), width = _a.width, height = _a.height;
1154
+ if (width === 0 || height === 0)
1155
+ return;
1156
+ if (floatEqual(width, latestWindowSize.current.width, 1) &&
1157
+ floatEqual(height, latestWindowSize.current.height, 1)) {
1158
+ return;
1159
+ }
1160
+ latestWindowSize.current = { width: width, height: height };
1161
+ flushSync(function () {
1162
+ latestHandlePosition.current();
1163
+ forceReposSubmenu();
1164
+ });
1165
+ }, 250);
1166
+ var resizeObserver = new ResizeObserver(callback);
1167
+ var observeTarget = menuRef.current.ownerDocument.body;
1168
+ resizeObserver.observe(observeTarget, { box: "border-box" });
1169
+ return function () {
1170
+ callback.cancel();
1171
+ resizeObserver.unobserve(observeTarget);
1172
+ };
1173
+ }, [reposition]);
1147
1174
  useEffect(function () {
1148
1175
  if (!isOpen) {
1149
1176
  dispatch(HoverActionTypes.RESET, undefined, 0);
@@ -2625,52 +2652,52 @@ var GridPopoverContext = createContext({
2625
2652
  anchorRef: { current: null },
2626
2653
  saving: false,
2627
2654
  setSaving: function () { },
2628
- setProps: function () { },
2629
- propsRef: { current: null }
2630
- });
2655
+ field: "",
2656
+ value: null,
2657
+ data: {},
2658
+ selectedRows: [],
2659
+ updateValue: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
2660
+ return [2 /*return*/, false];
2661
+ }); }); }
2662
+ });
2663
+ var useGridPopoverContext = function () {
2664
+ return useContext(GridPopoverContext);
2665
+ };
2631
2666
 
2632
- var GridPopoverContextProvider = function (props) {
2633
- var _a = useContext(GridContext), getSelectedRows = _a.getSelectedRows, updatingCells = _a.updatingCells;
2634
- var anchorRef = useRef();
2635
- var propsRef = useRef({});
2636
- var _b = useState(false), saving = _b[0], setSaving = _b[1];
2637
- var setProps = useCallback(function (props, multiEdit) {
2638
- var _a, _b;
2639
- // Then item that is clicked on will always be first in the list
2640
- var selectedRows = multiEdit
2641
- ? sortBy(getSelectedRows(), function (row) { return row.id !== props.data.id; })
2642
- : [props.data];
2643
- var field = (_b = (_a = props.colDef) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : "";
2644
- anchorRef.current = props.eGridCell;
2645
- propsRef.current = {
2646
- value: props.value,
2647
- data: props.data,
2648
- field: field,
2649
- selectedRows: selectedRows,
2650
- updateValue: function (saveFn) { return __awaiter(void 0, void 0, void 0, function () {
2651
- var _a;
2652
- return __generator(this, function (_b) {
2653
- switch (_b.label) {
2654
- case 0:
2655
- _a = !saving;
2656
- if (!_a) return [3 /*break*/, 2];
2657
- return [4 /*yield*/, updatingCells({ selectedRows: selectedRows, field: field }, saveFn, setSaving)];
2658
- case 1:
2659
- _a = (_b.sent());
2660
- _b.label = 2;
2661
- case 2: return [2 /*return*/, _a];
2662
- }
2663
- });
2664
- }); }
2665
- };
2666
- }, [getSelectedRows, saving, updatingCells]);
2667
+ var GridPopoverContextProvider = function (_a) {
2668
+ var _b, _c, _d;
2669
+ var props = _a.props, children = _a.children;
2670
+ var _e = useContext(GridContext), getSelectedRows = _e.getSelectedRows, updatingCells = _e.updatingCells;
2671
+ var anchorRef = useRef(props.eGridCell);
2672
+ var _f = useState(false), saving = _f[0], setSaving = _f[1];
2673
+ var colDef = props.colDef;
2674
+ var cellEditorParams = colDef.cellEditorParams;
2675
+ var multiEdit = (_b = cellEditorParams === null || cellEditorParams === void 0 ? void 0 : cellEditorParams.multiEdit) !== null && _b !== void 0 ? _b : false;
2676
+ // Then item that is clicked on will always be first in the list
2677
+ var selectedRows = useMemo(function () { return (multiEdit ? sortBy(getSelectedRows(), function (row) { return row.id !== props.data.id; }) : [props.data]); }, [getSelectedRows, multiEdit, props.data]);
2678
+ var field = (_d = (_c = props.colDef) === null || _c === void 0 ? void 0 : _c.field) !== null && _d !== void 0 ? _d : "";
2679
+ var updateValue = useCallback(function (saveFn) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
2680
+ switch (_b.label) {
2681
+ case 0:
2682
+ _a = !saving;
2683
+ if (!_a) return [3 /*break*/, 2];
2684
+ return [4 /*yield*/, updatingCells({ selectedRows: selectedRows, field: field }, saveFn, setSaving)];
2685
+ case 1:
2686
+ _a = (_b.sent());
2687
+ _b.label = 2;
2688
+ case 2: return [2 /*return*/, _a];
2689
+ }
2690
+ }); }); }, [field, saving, selectedRows, updatingCells]);
2667
2691
  return (jsx(GridPopoverContext.Provider, __assign({ value: {
2668
2692
  anchorRef: anchorRef,
2669
2693
  saving: saving,
2670
2694
  setSaving: setSaving,
2671
- propsRef: propsRef,
2672
- setProps: setProps
2673
- } }, { children: props.children })));
2695
+ selectedRows: selectedRows,
2696
+ field: field,
2697
+ data: props.data,
2698
+ value: props.value,
2699
+ updateValue: updateValue
2700
+ } }, { children: children })));
2674
2701
  };
2675
2702
 
2676
2703
  var GridCellRenderer = function (props) {
@@ -2692,7 +2719,7 @@ var GridCell = function (props, custom) {
2692
2719
  return __assign(__assign(__assign(__assign(__assign({ colId: props.field, sortable: !!((props === null || props === void 0 ? void 0 : props.field) || (props === null || props === void 0 ? void 0 : props.valueGetter)), resizable: true }, ((custom === null || custom === void 0 ? void 0 : custom.editor) && {
2693
2720
  cellClass: (custom === null || custom === void 0 ? void 0 : custom.multiEdit) ? GenericMultiEditCellClass : undefined,
2694
2721
  editable: (_a = props.editable) !== null && _a !== void 0 ? _a : true,
2695
- cellEditor: GenericCellEditorComponent(custom.editor)
2722
+ cellEditor: GenericCellEditorComponentWrapper(custom)
2696
2723
  })), ((custom === null || custom === void 0 ? void 0 : custom.editorParams) && {
2697
2724
  cellEditorParams: __assign(__assign({}, custom.editorParams), { multiEdit: custom.multiEdit })
2698
2725
  })), {
@@ -2707,21 +2734,10 @@ var GridCell = function (props, custom) {
2707
2734
  return JSON.stringify(params.value);
2708
2735
  } }), props), { cellRenderer: GridCellRenderer, cellRendererParams: __assign({ originalCellRenderer: props.cellRenderer }, props.cellRendererParams) });
2709
2736
  };
2710
- // TODO memo?
2711
- var GenericCellEditorComponent = function (editor) {
2712
- return forwardRef(function GenericCellEditorComponent2(props, _) {
2713
- return (jsx(GridPopoverContextProvider, { children: jsx(GenericCellEditorComponent3, __assign({}, __assign(__assign({}, props), { editor: editor }))) }));
2737
+ var GenericCellEditorComponentWrapper = function (custom) {
2738
+ return forwardRef(function GenericCellEditorComponentFr(cellEditorParams, _) {
2739
+ return (jsxs(GridPopoverContextProvider, __assign({ props: cellEditorParams }, { children: [jsx(cellEditorParams.colDef.cellRenderer, __assign({}, cellEditorParams, cellEditorParams.colDef.cellRendererParams)), (custom === null || custom === void 0 ? void 0 : custom.editor) && jsx(custom.editor, __assign({}, cellEditorParams))] })));
2714
2740
  });
2715
- };
2716
- var GenericCellEditorComponent3 = function (props) {
2717
- var _a;
2718
- var _b = useContext(GridPopoverContext), setProps = _b.setProps, propsRef = _b.propsRef;
2719
- var colDef = props.colDef;
2720
- var cellEditorParams = colDef.cellEditorParams;
2721
- var multiEdit = (_a = cellEditorParams === null || cellEditorParams === void 0 ? void 0 : cellEditorParams.multiEdit) !== null && _a !== void 0 ? _a : false;
2722
- // TODO don't need all these props in context
2723
- setProps(props, multiEdit);
2724
- return (jsxs(Fragment$1, { children: [jsx(colDef.cellRenderer, __assign({}, props)), (props === null || props === void 0 ? void 0 : props.editor) && jsx(props.editor, __assign({}, cellEditorParams, propsRef.current))] }));
2725
2741
  };
2726
2742
 
2727
2743
  /**
@@ -2742,7 +2758,7 @@ var ComponentLoadingWrapper = function (props) {
2742
2758
 
2743
2759
  var useGridPopoverHook = function (props) {
2744
2760
  var stopEditing = useContext(GridContext).stopEditing;
2745
- var _a = useContext(GridPopoverContext), anchorRef = _a.anchorRef, saving = _a.saving, propsRef = _a.propsRef;
2761
+ var _a = useGridPopoverContext(), anchorRef = _a.anchorRef, saving = _a.saving, updateValue = _a.updateValue;
2746
2762
  var saveButtonRef = useRef(null);
2747
2763
  var _b = useState(false), isOpen = _b[0], setOpen = _b[1];
2748
2764
  useEffect(function () {
@@ -2750,22 +2766,20 @@ var useGridPopoverHook = function (props) {
2750
2766
  }, []);
2751
2767
  var triggerSave = useCallback(function (reason) { return __awaiter(void 0, void 0, void 0, function () {
2752
2768
  var _a, _b;
2753
- var _c, _d;
2754
- return __generator(this, function (_e) {
2755
- switch (_e.label) {
2769
+ return __generator(this, function (_c) {
2770
+ switch (_c.label) {
2756
2771
  case 0:
2757
- _a = reason == "cancel" ||
2758
- !props.save;
2772
+ _a = reason == "cancel" || !props.save;
2759
2773
  if (_a) return [3 /*break*/, 3];
2760
- _b = ((_c = propsRef.current) === null || _c === void 0 ? void 0 : _c.updateValue);
2774
+ _b = updateValue;
2761
2775
  if (!_b) return [3 /*break*/, 2];
2762
- return [4 /*yield*/, ((_d = propsRef.current) === null || _d === void 0 ? void 0 : _d.updateValue(props.save))];
2776
+ return [4 /*yield*/, updateValue(props.save)];
2763
2777
  case 1:
2764
- _b = (_e.sent());
2765
- _e.label = 2;
2778
+ _b = (_c.sent());
2779
+ _c.label = 2;
2766
2780
  case 2:
2767
2781
  _a = (_b);
2768
- _e.label = 3;
2782
+ _c.label = 3;
2769
2783
  case 3:
2770
2784
  if (_a) {
2771
2785
  setOpen(false);
@@ -2774,7 +2788,7 @@ var useGridPopoverHook = function (props) {
2774
2788
  return [2 /*return*/];
2775
2789
  }
2776
2790
  });
2777
- }); }, [props, stopEditing, propsRef]);
2791
+ }); }, [props.save, stopEditing, updateValue]);
2778
2792
  var popoverWrapper = useCallback(function (children) {
2779
2793
  return (jsx(Fragment$1, { children: anchorRef.current && (jsxs(ControlledMenu, __assign({ state: isOpen ? "open" : "closed", portal: true, unmountOnClose: true, anchorRef: anchorRef, saveButtonRef: saveButtonRef, menuClassName: "step-ag-grid-react-menu", onClose: function (event) {
2780
2794
  triggerSave(event.reason).then();
@@ -2897,66 +2911,60 @@ var MenuHeaderString = "_____MENU_HEADER_____";
2897
2911
  var MenuHeaderItem = function (title) {
2898
2912
  return { label: title, value: MenuHeaderString };
2899
2913
  };
2900
- var GridFormDropDown = function (_props) {
2901
- var props = _props;
2902
- var _a = useContext(GridContext), updatingCells = _a.updatingCells, stopEditing = _a.stopEditing;
2914
+ var fieldToString = function (field) {
2915
+ return typeof field == "symbol" ? field.toString() : "".concat(field);
2916
+ };
2917
+ var GridFormDropDown = function (props) {
2918
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue;
2919
+ var stopEditing = useContext(GridContext).stopEditing;
2903
2920
  var _b = useState(""), filter = _b[0], setFilter = _b[1];
2904
2921
  var _c = useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
2905
2922
  var optionsInitialising = useRef(false);
2906
2923
  var _d = useState(null), options = _d[0], setOptions = _d[1];
2907
2924
  var _e = useState([]), subComponentValues = _e[0], setSubComponentValues = _e[1];
2908
2925
  var selectItemHandler = useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
2909
- var field;
2910
2926
  return __generator(this, function (_a) {
2911
- switch (_a.label) {
2912
- case 0:
2913
- field = props.field;
2914
- return [4 /*yield*/, updatingCells({ selectedRows: props.selectedRows, field: field }, function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2915
- var hasChanged;
2916
- return __generator(this, function (_a) {
2917
- switch (_a.label) {
2918
- case 0:
2919
- hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
2920
- if (!hasChanged) return [3 /*break*/, 3];
2921
- if (!props.onSelectedItem) return [3 /*break*/, 2];
2922
- return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
2923
- case 1:
2924
- _a.sent();
2925
- return [3 /*break*/, 3];
2926
- case 2:
2927
- selectedRows.forEach(function (row) { return (row[field] = value); });
2928
- _a.label = 3;
2929
- case 3: return [2 /*return*/, true];
2930
- }
2931
- });
2932
- }); })];
2933
- case 1: return [2 /*return*/, _a.sent()];
2934
- }
2927
+ return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2928
+ var hasChanged;
2929
+ return __generator(this, function (_a) {
2930
+ switch (_a.label) {
2931
+ case 0:
2932
+ hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
2933
+ if (!hasChanged) return [3 /*break*/, 3];
2934
+ if (!props.onSelectedItem) return [3 /*break*/, 2];
2935
+ return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
2936
+ case 1:
2937
+ _a.sent();
2938
+ return [3 /*break*/, 3];
2939
+ case 2:
2940
+ selectedRows.forEach(function (row) { return (row[field] = value); });
2941
+ _a.label = 3;
2942
+ case 3: return [2 /*return*/, true];
2943
+ }
2944
+ });
2945
+ }); })];
2935
2946
  });
2936
- }); }, [props, updatingCells]);
2947
+ }); }, [field, props, updateValue]);
2937
2948
  var selectFilterHandler = useCallback(function (value) { return __awaiter(void 0, void 0, void 0, function () {
2938
- var field;
2939
2949
  return __generator(this, function (_a) {
2940
- switch (_a.label) {
2941
- case 0:
2942
- field = props.field;
2943
- return [4 /*yield*/, updatingCells({ selectedRows: props.selectedRows, field: field }, function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2944
- return __generator(this, function (_a) {
2945
- switch (_a.label) {
2946
- case 0:
2947
- if (!props.onSelectFilter) return [3 /*break*/, 2];
2948
- return [4 /*yield*/, props.onSelectFilter({ selectedRows: selectedRows, value: value })];
2949
- case 1:
2950
- _a.sent();
2951
- _a.label = 2;
2952
- case 2: return [2 /*return*/, true];
2953
- }
2954
- });
2955
- }); })];
2956
- case 1: return [2 /*return*/, _a.sent()];
2957
- }
2950
+ return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2951
+ var _a;
2952
+ return __generator(this, function (_b) {
2953
+ switch (_b.label) {
2954
+ case 0:
2955
+ _a = props.onSelectFilter;
2956
+ if (!_a) return [3 /*break*/, 2];
2957
+ return [4 /*yield*/, props.onSelectFilter({ selectedRows: selectedRows, value: value })];
2958
+ case 1:
2959
+ _a = (_b.sent());
2960
+ _b.label = 2;
2961
+ case 2:
2962
+ return [2 /*return*/, true];
2963
+ }
2964
+ });
2965
+ }); })];
2958
2966
  });
2959
- }); }, [props, updatingCells]);
2967
+ }); }, [props, updateValue]);
2960
2968
  // Load up options list if it's async function
2961
2969
  useEffect(function () {
2962
2970
  var _a;
@@ -2970,7 +2978,7 @@ var GridFormDropDown = function (_props) {
2970
2978
  switch (_a.label) {
2971
2979
  case 0:
2972
2980
  if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
2973
- return [4 /*yield*/, optionsConf(props.selectedRows, filter)];
2981
+ return [4 /*yield*/, optionsConf(selectedRows, filter)];
2974
2982
  case 1:
2975
2983
  optionsConf = _a.sent();
2976
2984
  _a.label = 2;
@@ -2998,7 +3006,7 @@ var GridFormDropDown = function (_props) {
2998
3006
  }
2999
3007
  });
3000
3008
  }); })();
3001
- }, [filter, options, props]);
3009
+ }, [filter, options, props, selectedRows]);
3002
3010
  // Local filtering.
3003
3011
  useEffect(function () {
3004
3012
  if (props.filtered == "local") {
@@ -3063,48 +3071,43 @@ var GridFormDropDown = function (_props) {
3063
3071
  var _b;
3064
3072
  var ref = _a.ref;
3065
3073
  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 = props.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); } }) })));
3066
- } })), jsx(MenuDivider, {}, "$$divider_filter")] }))), jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxs(Fragment$1, { children: [options && options.length == (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length) && (jsx(MenuItem, { children: "[Empty]" }, "".concat(props.field, "-empty"))), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3074
+ } })), jsx(MenuDivider, {}, "$$divider_filter")] }))), jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxs(Fragment$1, { children: [options && options.length == (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length) && (jsx(MenuItem, { children: "[Empty]" }, "".concat(fieldToString(field), "-empty"))), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3067
3075
  var _a;
3068
3076
  return item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : item.value === MenuHeaderString ? (jsx(MenuHeader, { children: item.label }, "$$header_".concat(index))) : filteredValues.includes(item.value) ? null : (jsx("div", { children: !item.subComponent ? (jsx(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onClick: function () {
3069
- selectItemHandler(item.value);
3070
- } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(props.field, "-").concat(index))) : (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3071
- return item.subComponent &&
3072
- item.subComponent({
3073
- setValue: function (value) {
3074
- var localSubComponentValues = __spreadArray([], subComponentValues, true);
3075
- var subComponentValueIndex = localSubComponentValues.findIndex(function (_a) {
3076
- var optionValue = _a.optionValue;
3077
- return optionValue === item.value;
3077
+ selectItemHandler(item.value).then();
3078
+ } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(fieldToString(field), "-").concat(index))) : (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3079
+ return item.subComponent && (jsx(item.subComponent, { setValue: function (value) {
3080
+ var localSubComponentValues = __spreadArray([], subComponentValues, true);
3081
+ var subComponentValueIndex = localSubComponentValues.findIndex(function (_a) {
3082
+ var optionValue = _a.optionValue;
3083
+ return optionValue === item.value;
3084
+ });
3085
+ if (subComponentValueIndex !== -1) {
3086
+ localSubComponentValues[subComponentValueIndex].subComponentValue = value;
3087
+ }
3088
+ else {
3089
+ localSubComponentValues.push({
3090
+ subComponentValue: value,
3091
+ optionValue: item.value
3078
3092
  });
3079
- if (subComponentValueIndex !== -1) {
3080
- localSubComponentValues[subComponentValueIndex].subComponentValue = value;
3081
- }
3082
- else {
3083
- localSubComponentValues.push({
3084
- subComponentValue: value,
3085
- optionValue: item.value
3086
- });
3087
- }
3088
- setSubComponentValues(localSubComponentValues);
3089
- },
3090
- keyDown: function (key, event) {
3091
- var subComponentItem = subComponentValues.find(function (_a) {
3092
- var optionValue = _a.optionValue;
3093
- return optionValue === item.value;
3093
+ }
3094
+ setSubComponentValues(localSubComponentValues);
3095
+ }, keyDown: function (key, event) {
3096
+ var subComponentItem = subComponentValues.find(function (_a) {
3097
+ var optionValue = _a.optionValue;
3098
+ return optionValue === item.value;
3099
+ });
3100
+ if ((key === "Enter" || key === "Tab") && subComponentItem) {
3101
+ event.preventDefault();
3102
+ event.stopPropagation();
3103
+ return selectItemHandler(item.value, subComponentItem.subComponentValue).then(function () {
3104
+ ref.closeMenu();
3105
+ return true;
3094
3106
  });
3095
- if ((key === "Enter" || key === "Tab") && subComponentItem) {
3096
- event.preventDefault();
3097
- event.stopPropagation();
3098
- return selectItemHandler(item.value, subComponentItem.subComponentValue).then(function () {
3099
- ref.closeMenu();
3100
- return true;
3101
- });
3102
- }
3103
- return false;
3104
- },
3105
- key: "".concat(props.field, "-").concat(index, "_subcomponent_inner")
3106
- }, ref);
3107
- } }), "".concat(props.field, "-").concat(index, "_subcomponent"))) }, "menu-wrapper-".concat(index)));
3107
+ }
3108
+ return false;
3109
+ } }, "".concat(fieldToString(field), "-").concat(index, "_subcomponent_inner")));
3110
+ } }), "".concat(fieldToString(field), "-").concat(index, "_subcomponent"))) }, "menu-wrapper-".concat(index)));
3108
3111
  })] }) }))] }));
3109
3112
  };
3110
3113
 
@@ -3125,40 +3128,48 @@ var GridSubComponentContext = createContext({
3125
3128
  });
3126
3129
 
3127
3130
  var GridFormMultiSelect = function (props) {
3128
- var selectedRows = props.selectedRows;
3129
- var initialiseValues = useMemo(function () { return props.initialSelectedValues && props.initialSelectedValues(selectedRows); }, [props, selectedRows]);
3131
+ var selectedRows = useGridPopoverContext().selectedRows;
3132
+ var initialiseValues = useMemo(function () {
3133
+ var r = props.initialSelectedValues && props.initialSelectedValues(selectedRows);
3134
+ // convert array of strings to object<value,null>
3135
+ return Array.isArray(r) ? fromPairs(r.map(function (v) { return [v, null]; })) : r;
3136
+ }, [props, selectedRows]);
3130
3137
  var subComponentIsValid = useRef({});
3131
- var _a = useState(initialiseValues && !Array.isArray(initialiseValues)
3132
- ? pickBy(initialiseValues, function (value) { return typeof value !== "boolean"; })
3133
- : {}), subSelectedValues = _a[0], setSubSelectedValues = _a[1];
3134
- var _b = useState(function () {
3135
- return initialiseValues ? (Array.isArray(initialiseValues) ? initialiseValues : Object.keys(initialiseValues)) : [];
3136
- }), selectedValues = _b[0], setSelectedValues = _b[1];
3137
- var _c = useState(""), filter = _c[0], setFilter = _c[1];
3138
- var _d = useState([]), filteredValues = _d[0], setFilteredValues = _d[1];
3138
+ var _a = useState(function () { return initialiseValues !== null && initialiseValues !== void 0 ? initialiseValues : {}; }), selectedValues = _a[0], setSelectedValues = _a[1];
3139
+ var _b = useState(""), filter = _b[0], setFilter = _b[1];
3140
+ var _c = useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
3139
3141
  var optionsInitialising = useRef(false);
3140
- var _e = useState(), options = _e[0], setOptions = _e[1];
3142
+ var _d = useState(), options = _d[0], setOptions = _d[1];
3141
3143
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3142
- var validations, notValid, selectedOptions, selectedResults;
3143
- var _a;
3144
- return __generator(this, function (_b) {
3145
- switch (_b.label) {
3144
+ var validations, notValid, menuOptionSubValueResult;
3145
+ return __generator(this, function (_a) {
3146
+ switch (_a.label) {
3146
3147
  case 0:
3147
3148
  if (!props.onSave) return [3 /*break*/, 2];
3148
- validations = pick(subComponentIsValid.current, selectedValues);
3149
+ if (!options) {
3150
+ console.error("options not initialised");
3151
+ return [2 /*return*/, false];
3152
+ }
3153
+ validations = pick(subComponentIsValid.current, Object.keys(selectedValues));
3149
3154
  notValid = Object.values(validations).some(function (v) { return !v; });
3150
3155
  if (notValid)
3151
3156
  return [2 /*return*/, false];
3152
- selectedOptions = (_a = selectedValues.map(function (row) { return (options !== null && options !== void 0 ? options : []).find(function (opt) { return opt.value == row; }); })) !== null && _a !== void 0 ? _a : [];
3153
- selectedResults = selectedOptions.map(function (selectedOption) {
3154
- return (__assign(__assign({}, selectedOption), { subValue: subSelectedValues["".concat(selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value)] }));
3157
+ menuOptionSubValueResult = toPairs(selectedValues).map(function (_a) {
3158
+ var value = _a[0], subValue = _a[1];
3159
+ var o = __assign({}, options.find(function (o) { return o.value == value; }));
3160
+ o.subValue = subValue;
3161
+ return o;
3155
3162
  });
3156
- return [4 /*yield*/, props.onSave(selectedRows, selectedResults)];
3157
- case 1: return [2 /*return*/, _b.sent()];
3163
+ if (isEqual(initialiseValues, selectedValues)) {
3164
+ // No changes to save
3165
+ return [2 /*return*/, true];
3166
+ }
3167
+ return [4 /*yield*/, props.onSave(selectedRows, menuOptionSubValueResult)];
3168
+ case 1: return [2 /*return*/, _a.sent()];
3158
3169
  case 2: return [2 /*return*/, true];
3159
3170
  }
3160
3171
  });
3161
- }); }, [options, props, selectedValues, subSelectedValues]);
3172
+ }); }, [initialiseValues, options, props, selectedValues]);
3162
3173
  // Load up options list if it's async function
3163
3174
  useEffect(function () {
3164
3175
  var _a;
@@ -3178,7 +3189,7 @@ var GridFormMultiSelect = function (props) {
3178
3189
  _a.label = 2;
3179
3190
  case 2:
3180
3191
  optionsList = optionsConf === null || optionsConf === void 0 ? void 0 : optionsConf.map(function (item) {
3181
- if (item == null || typeof item == "string" || typeof item == "number") {
3192
+ if (item == null || typeof item === "string" || typeof item === "number") {
3182
3193
  item = { value: item, label: item };
3183
3194
  }
3184
3195
  return item;
@@ -3211,7 +3222,16 @@ var GridFormMultiSelect = function (props) {
3211
3222
  })
3212
3223
  .filter(function (r) { return r !== undefined; }));
3213
3224
  }, [props.filtered, filter, options]);
3214
- var _f = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _f.popoverWrapper, triggerSave = _f.triggerSave;
3225
+ var toggleValue = useCallback(function (item) {
3226
+ var _a;
3227
+ if ("".concat(item.value) in selectedValues) {
3228
+ setSelectedValues(omit(selectedValues, ["".concat(item.value)]));
3229
+ }
3230
+ else {
3231
+ setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = null, _a)));
3232
+ }
3233
+ }, [selectedValues]);
3234
+ var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3215
3235
  return popoverWrapper(jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormMultiSelect-container" }, { children: jsxs(Fragment$1, { children: [options && props.filtered && (jsxs(Fragment$1, { children: [jsx(FocusableItem, __assign({ className: "filter-item" }, { children: function (_a) {
3216
3236
  var _b;
3217
3237
  var ref = _a.ref;
@@ -3220,29 +3240,19 @@ var GridFormMultiSelect = function (props) {
3220
3240
  var _a;
3221
3241
  return item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxs("div", { children: [jsx(MenuItem, __assign({ onClick: function (e) {
3222
3242
  e.keepOpen = true;
3223
- if (selectedValues.includes(item.value)) {
3224
- setSelectedValues(selectedValues.filter(function (value) { return value != item.value; }));
3225
- }
3226
- else {
3227
- setSelectedValues(__spreadArray(__spreadArray([], selectedValues, true), [item.value], false));
3228
- }
3243
+ toggleValue(item);
3229
3244
  }, onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () {
3230
3245
  return __generator(this, function (_a) {
3231
3246
  if (e.key === "Enter")
3232
3247
  triggerSave().then();
3233
3248
  else if (e.key === " ") {
3234
- if (selectedValues.includes(item.value)) {
3235
- setSelectedValues(selectedValues.filter(function (value) { return value != item.value; }));
3236
- }
3237
- else {
3238
- setSelectedValues(__spreadArray(__spreadArray([], selectedValues, true), [item.value], false));
3239
- }
3249
+ toggleValue(item);
3240
3250
  e.preventDefault();
3241
3251
  e.stopPropagation();
3242
3252
  }
3243
3253
  return [2 /*return*/];
3244
3254
  });
3245
- }); } }, { 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: {
3255
+ }); } }, { children: jsx(LuiCheckboxInput, { isChecked: "".concat(item.value) in selectedValues, value: "".concat(item.value), label: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)), inputProps: {
3246
3256
  onClick: function (e) {
3247
3257
  e.preventDefault();
3248
3258
  e.stopPropagation();
@@ -3250,12 +3260,12 @@ var GridFormMultiSelect = function (props) {
3250
3260
  }
3251
3261
  }, onChange: function () {
3252
3262
  /*Do nothing, change handled by menuItem*/
3253
- } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3263
+ } }) })), "".concat(item.value) in selectedValues && item.subComponent && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3254
3264
  return item.subComponent && (jsx(GridSubComponentContext.Provider, __assign({ value: {
3255
- value: subSelectedValues["".concat(item.value)],
3265
+ value: selectedValues["".concat(item.value)],
3256
3266
  setValue: function (value) {
3257
- subSelectedValues["".concat(item.value)] = value;
3258
- setSubSelectedValues(__assign({}, subSelectedValues));
3267
+ var _a;
3268
+ setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = value, _a)));
3259
3269
  },
3260
3270
  setValid: function (valid) {
3261
3271
  subComponentIsValid.current["".concat(item.value)] = valid;
@@ -3279,11 +3289,31 @@ var PopoutMenuSeparator = Object.freeze({ __isMenuSeparator__: true });
3279
3289
  * NOTE: If the popout menu doesn't appear on single click when also selecting row it's because
3280
3290
  * you need a useMemo around your columnDefs
3281
3291
  */
3282
- var GridFormPopoverMenu = function (_props) {
3283
- var props = _props;
3284
- var updatingCells = useContext(GridContext).updatingCells;
3292
+ var GridFormPopoverMenu = function (props) {
3293
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, updateValue = _a.updateValue;
3285
3294
  var optionsInitialising = useRef(false);
3286
- var _a = useState(), options = _a[0], setOptions = _a[1];
3295
+ var _b = useState(), options = _b[0], setOptions = _b[1];
3296
+ // Save triggers during async action processing which triggers another action(), this ref blocks that
3297
+ var actionProcessing = useRef(false);
3298
+ var _c = useState(null), subComponentSelected = _c[0], setSubComponentSelected = _c[1];
3299
+ var subComponentIsValid = useRef(false);
3300
+ var _d = useState(), subSelectedValue = _d[0], setSubSelectedValue = _d[1];
3301
+ var defaultAction = useCallback(function (selectedRows, menuOption) { return __awaiter(void 0, void 0, void 0, function () {
3302
+ return __generator(this, function (_a) {
3303
+ switch (_a.label) {
3304
+ case 0:
3305
+ if (!props.defaultAction) return [3 /*break*/, 2];
3306
+ return [4 /*yield*/, props.defaultAction(selectedRows, menuOption)];
3307
+ case 1:
3308
+ _a.sent();
3309
+ return [3 /*break*/, 3];
3310
+ case 2:
3311
+ console.error("No action specified for ".concat(menuOption.label, " menu options"));
3312
+ _a.label = 3;
3313
+ case 3: return [2 /*return*/];
3314
+ }
3315
+ });
3316
+ }); }, [props]);
3287
3317
  // Load up options list if it's async function
3288
3318
  useEffect(function () {
3289
3319
  var _a;
@@ -3292,56 +3322,107 @@ var GridFormPopoverMenu = function (_props) {
3292
3322
  optionsInitialising.current = true;
3293
3323
  var optionsConf = (_a = props.options) !== null && _a !== void 0 ? _a : [];
3294
3324
  (function () { return __awaiter(void 0, void 0, void 0, function () {
3295
- var _a;
3325
+ var newOptions, _a, anyOptionsAreMissingAction;
3296
3326
  return __generator(this, function (_b) {
3297
3327
  switch (_b.label) {
3298
3328
  case 0:
3299
3329
  if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
3300
- _a = setOptions;
3301
- return [4 /*yield*/, optionsConf(props.selectedRows)];
3330
+ return [4 /*yield*/, optionsConf(selectedRows)];
3302
3331
  case 1:
3303
- _a.apply(void 0, [_b.sent()]);
3332
+ _a = _b.sent();
3304
3333
  return [3 /*break*/, 3];
3305
3334
  case 2:
3306
- setOptions(optionsConf);
3335
+ _a = optionsConf;
3307
3336
  _b.label = 3;
3308
3337
  case 3:
3338
+ newOptions = _a;
3339
+ setOptions(newOptions);
3340
+ if (!props.defaultAction) {
3341
+ anyOptionsAreMissingAction = newOptions.some(function (option) { return !option.action; });
3342
+ if (anyOptionsAreMissingAction) {
3343
+ console.error("There's no default action handler and some Menu options are missing an action handler", {
3344
+ invalidMenuOptions: newOptions.filter(function (option) { return !option.action; })
3345
+ });
3346
+ }
3347
+ }
3309
3348
  optionsInitialising.current = false;
3310
3349
  return [2 /*return*/];
3311
3350
  }
3312
3351
  });
3313
3352
  }); })();
3314
- }, [options, props.options, props.selectedRows]);
3353
+ }, [options, props.defaultAction, props.options, selectedRows]);
3315
3354
  var actionClick = useCallback(function (menuOption) { return __awaiter(void 0, void 0, void 0, function () {
3316
3355
  return __generator(this, function (_a) {
3317
- switch (_a.label) {
3318
- case 0: return [4 /*yield*/, updatingCells({ selectedRows: props.selectedRows, field: props.field }, function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3319
- var _a;
3320
- return __generator(this, function (_b) {
3321
- switch (_b.label) {
3322
- case 0:
3323
- _a = menuOption.action;
3324
- if (!_a) return [3 /*break*/, 2];
3325
- return [4 /*yield*/, menuOption.action(selectedRows)];
3326
- case 1:
3327
- _a = (_b.sent());
3328
- _b.label = 2;
3329
- case 2:
3330
- return [2 /*return*/, true];
3331
- }
3332
- });
3333
- }); })];
3334
- case 1: return [2 /*return*/, _a.sent()];
3335
- }
3356
+ actionProcessing.current = true;
3357
+ return [2 /*return*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () {
3358
+ var result;
3359
+ var _a;
3360
+ return __generator(this, function (_b) {
3361
+ switch (_b.label) {
3362
+ case 0:
3363
+ result = __assign(__assign({}, menuOption), { subValue: subSelectedValue });
3364
+ return [4 /*yield*/, ((_a = menuOption.action) !== null && _a !== void 0 ? _a : defaultAction)(selectedRows, result)];
3365
+ case 1:
3366
+ _b.sent();
3367
+ actionProcessing.current = false;
3368
+ return [2 /*return*/, true];
3369
+ }
3370
+ });
3371
+ }); })];
3336
3372
  });
3337
- }); }, [props.field, props.selectedRows, updatingCells]);
3338
- var selectedRowCount = props.selectedRows.length;
3373
+ }); }, [defaultAction, selectedRows, subSelectedValue, updateValue]);
3374
+ var onMenuItemClick = useCallback(function (e, item) {
3375
+ if (item.subComponent) {
3376
+ subComponentIsValid.current = false;
3377
+ setSubSelectedValue(null);
3378
+ setSubComponentSelected(subComponentSelected === item ? null : item);
3379
+ e.keepOpen = true;
3380
+ }
3381
+ else {
3382
+ setSubComponentSelected(null);
3383
+ actionClick(item).then();
3384
+ }
3385
+ }, [actionClick, subComponentSelected]);
3386
+ var selectedRowCount = selectedRows.length;
3339
3387
  var filteredOptions = options === null || options === void 0 ? void 0 : options.filter(function (menuOption) {
3340
3388
  return menuOption.label === PopoutMenuSeparator || selectedRowCount === 1 || menuOption.supportsMultiEdit;
3341
3389
  });
3342
- var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3390
+ var save = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
3391
+ return __generator(this, function (_a) {
3392
+ switch (_a.label) {
3393
+ case 0:
3394
+ if (!(!actionProcessing.current && subComponentSelected)) return [3 /*break*/, 2];
3395
+ if (!subComponentIsValid.current)
3396
+ return [2 /*return*/, false];
3397
+ return [4 /*yield*/, actionClick(subComponentSelected)];
3398
+ case 1:
3399
+ _a.sent();
3400
+ _a.label = 2;
3401
+ case 2: return [2 /*return*/, true];
3402
+ }
3403
+ });
3404
+ }); }, [actionClick, subComponentSelected]);
3405
+ var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3406
+ var localTriggerSave = function (reason) { return __awaiter(void 0, void 0, void 0, function () {
3407
+ return __generator(this, function (_a) {
3408
+ if (!subComponentIsValid.current)
3409
+ return [2 /*return*/];
3410
+ return [2 /*return*/, triggerSave(reason)];
3411
+ });
3412
+ }); };
3343
3413
  return popoverWrapper(jsx(ComponentLoadingWrapper, __assign({ loading: !filteredOptions, className: "GridFormPopupMenu" }, { children: jsx(Fragment$1, { children: options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3344
- return item.label === PopoutMenuSeparator ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : (!item.hidden && (jsx(MenuItem, __assign({ onClick: function () { return actionClick(item); }, disabled: !!item.disabled || !(filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.includes(item)), title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "" }, { children: item.label }), "".concat(item.label))));
3414
+ return item.label === PopoutMenuSeparator ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : (!item.hidden && (jsxs(Fragment$1, { children: [jsx(MenuItem, __assign({ onClick: function (e) { return onMenuItemClick(e, item); }, disabled: !!item.disabled || !(filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.includes(item)), title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "" }, { children: item.label }), "".concat(item.label)), item.subComponent && subComponentSelected === item && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3415
+ return item.subComponent && (jsx(GridSubComponentContext.Provider, __assign({ value: {
3416
+ value: subSelectedValue,
3417
+ setValue: function (value) {
3418
+ setSubSelectedValue(value);
3419
+ },
3420
+ setValid: function (valid) {
3421
+ subComponentIsValid.current = valid;
3422
+ },
3423
+ triggerSave: localTriggerSave
3424
+ } }, { children: jsx(item.subComponent, {}) })));
3425
+ } }), "".concat(item.label, "_subcomponent")))] })));
3345
3426
  }) }) })));
3346
3427
  };
3347
3428
 
@@ -3440,15 +3521,16 @@ var css_248z$2 = ".LuiTextInput{margin-bottom:0}.LuiTextInput-formatted{color:#b
3440
3521
  styleInject(css_248z$2);
3441
3522
 
3442
3523
  var TextInputFormatted = function (props) {
3443
- return (jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsx("input", __assign({ type: "text", className: "LuiTextInput-input", min: "0", spellCheck: true, defaultValue: props.value, onChange: props.onChange, onFocus: props.onFocus, onClick: props.onClick }, props.inputProps)), jsx("span", __assign({ className: "LuiTextInput-formatted" }, { children: props.formatted }))] })), props.error && (jsxs("span", __assign({ className: "LuiTextInput-error" }, { children: [jsx(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }), props.error] }))), props.warning && (jsxs("span", __assign({ className: "LuiTextInput-warning" }, { children: [jsx(LuiIcon, { alt: "warning", name: "ic_warning", className: "LuiTextInput-warning-icon", size: "sm", status: "warning" }), props.warning] })))] })));
3524
+ return (jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsx("input", __assign({ type: "text", className: "LuiTextInput-input", min: "0", spellCheck: true, defaultValue: props.value, onChange: props.onChange, onFocus: props.onFocus, onClick: props.onClick, onMouseEnter: function (e) {
3525
+ e.currentTarget.focus();
3526
+ } }, props.inputProps)), jsx("span", __assign({ className: "LuiTextInput-formatted" }, { children: props.formatted }))] })), props.error && (jsxs("span", __assign({ className: "LuiTextInput-error" }, { children: [jsx(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }), props.error] }))), props.warning && (jsxs("span", __assign({ className: "LuiTextInput-warning" }, { children: [jsx(LuiIcon, { alt: "warning", name: "ic_warning", className: "LuiTextInput-warning-icon", size: "sm", status: "warning" }), props.warning] })))] })));
3444
3527
  };
3445
3528
 
3446
- var GridFormEditBearing = function (_props) {
3447
- var _a;
3448
- var props = _props;
3449
- var _b = useState("".concat((_a = props.value) !== null && _a !== void 0 ? _a : "")), value = _b[0], setValue = _b[1];
3529
+ var GridFormEditBearing = function (props) {
3530
+ var _a = useGridPopoverContext(), field = _a.field, initialValue = _a.value;
3531
+ var _b = useState("".concat(initialValue !== null && initialValue !== void 0 ? initialValue : "")), value = _b[0], setValue = _b[1];
3450
3532
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3451
- var parsedValue, field_1;
3533
+ var parsedValue;
3452
3534
  return __generator(this, function (_a) {
3453
3535
  switch (_a.label) {
3454
3536
  case 0:
@@ -3456,25 +3538,26 @@ var GridFormEditBearing = function (_props) {
3456
3538
  return [2 /*return*/, false];
3457
3539
  parsedValue = bearingNumberParser(value);
3458
3540
  // Value didn't change so don't save just cancel
3459
- if (parsedValue === props.value) {
3541
+ if (parsedValue === initialValue) {
3460
3542
  return [2 /*return*/, true];
3461
3543
  }
3462
3544
  if (!props.onSave) return [3 /*break*/, 2];
3463
3545
  return [4 /*yield*/, props.onSave(selectedRows, parsedValue)];
3464
3546
  case 1: return [2 /*return*/, _a.sent()];
3465
3547
  case 2:
3466
- field_1 = props.field;
3467
- if (field_1 == null) {
3548
+ if (field == null) {
3468
3549
  console.error("field is not defined in ColDef");
3469
3550
  }
3470
3551
  else {
3471
- selectedRows.forEach(function (row) { return (row[field_1] = parsedValue); });
3552
+ selectedRows.forEach(function (row) {
3553
+ row[field] = parsedValue;
3554
+ });
3472
3555
  }
3473
3556
  _a.label = 3;
3474
3557
  case 3: return [2 /*return*/, true];
3475
3558
  }
3476
3559
  });
3477
- }); }, [props, value]);
3560
+ }); }, [field, initialValue, props, value]);
3478
3561
  var _c = useGridPopoverHook({ className: props.className, save: save }), triggerSave = _c.triggerSave, popoverWrapper = _c.popoverWrapper;
3479
3562
  return popoverWrapper(jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsx(TextInputFormatted, { value: value !== null && value !== void 0 ? value : "", onChange: function (e) {
3480
3563
  setValue(e.target.value.trim());
@@ -3527,8 +3610,8 @@ var GridPopoverEditDropDown = function (colDef, props) {
3527
3610
  className: "GridPopoverEditDropDown-containerMedium" }, props.editorParams) }));
3528
3611
  };
3529
3612
 
3530
- var GridFormMessage = function (_props) {
3531
- var props = _props;
3613
+ var GridFormMessage = function (props) {
3614
+ var selectedRows = useGridPopoverContext().selectedRows;
3532
3615
  var _a = useState(null), message = _a[0], setMessage = _a[1];
3533
3616
  var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3534
3617
  useEffect(function () {
@@ -3538,14 +3621,14 @@ var GridFormMessage = function (_props) {
3538
3621
  switch (_b.label) {
3539
3622
  case 0:
3540
3623
  _a = setMessage;
3541
- return [4 /*yield*/, props.message(props)];
3624
+ return [4 /*yield*/, props.message(selectedRows)];
3542
3625
  case 1:
3543
3626
  _a.apply(void 0, [_b.sent()]);
3544
3627
  return [2 /*return*/];
3545
3628
  }
3546
3629
  });
3547
3630
  }); })().then();
3548
- }, [props]);
3631
+ }, [props, selectedRows]);
3549
3632
  return popoverWrapper(jsx(ComponentLoadingWrapper, __assign({ loading: message === null, className: clsx("GridFormMessage-container", props.className) }, { children: jsx(Fragment$1, { children: message }) })));
3550
3633
  };
3551
3634
 
@@ -3625,13 +3708,18 @@ var useGenerateOrDefaultId = function (idFromProps) {
3625
3708
  var TextAreaInput = function (props) {
3626
3709
  var _a, _b;
3627
3710
  var id = useGenerateOrDefaultId((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.id);
3628
- return (jsxs("div", __assign({ className: clsx("LuiTextAreaInput Grid-popoverContainer", ((_b = props.inputProps) === null || _b === void 0 ? void 0 : _b.disabled) ? "isDisabled" : "", (props === null || props === void 0 ? void 0 : props.error) ? "hasError" : "") }, { children: [jsxs("label", __assign({ htmlFor: id }, { children: [props.mandatory && jsx("span", __assign({ className: "LuiTextAreaInput-mandatory" }, { children: "*" })), props.label && jsx("span", __assign({ className: "LuiTextAreaInput-label" }, { children: props.label })), jsxs("div", __assign({ className: "LuiTextAreaInput-wrapper" }, { children: [" ", jsx("textarea", __assign({ id: id, value: props.value, onChange: props.onChange, rows: 5 }, props.inputProps))] }))] })), props.error && (jsxs("span", __assign({ className: "LuiTextAreaInput-error" }, { children: [jsx(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextAreaInput-error-icon", size: "sm", status: "error" }), props.error] })))] })));
3711
+ return (jsxs("div", __assign({ className: clsx("LuiTextAreaInput Grid-popoverContainer", ((_b = props.inputProps) === null || _b === void 0 ? void 0 : _b.disabled) ? "isDisabled" : "", (props === null || props === void 0 ? void 0 : props.error) ? "hasError" : "") }, { children: [jsxs("label", __assign({ htmlFor: id }, { children: [props.mandatory && jsx("span", __assign({ className: "LuiTextAreaInput-mandatory" }, { children: "*" })), props.label && jsx("span", __assign({ className: "LuiTextAreaInput-label" }, { children: props.label })), jsxs("div", __assign({ className: "LuiTextAreaInput-wrapper" }, { children: [" ", jsx("textarea", __assign({ id: id, value: props.value, onChange: props.onChange, rows: 5 }, props.inputProps, { onMouseEnter: function (e) {
3712
+ if (document.activeElement != e.currentTarget) {
3713
+ e.currentTarget.focus();
3714
+ e.currentTarget.selectionStart = e.currentTarget.value.length;
3715
+ }
3716
+ } }))] }))] })), props.error && (jsxs("span", __assign({ className: "LuiTextAreaInput-error" }, { children: [jsx(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextAreaInput-error-icon", size: "sm", status: "error" }), props.error] })))] })));
3629
3717
  };
3630
3718
 
3631
- var GridFormTextArea = function (_props) {
3632
- var _a, _b;
3633
- var props = _props;
3634
- var _c = useState((_a = props.value) !== null && _a !== void 0 ? _a : ""), value = _c[0], setValue = _c[1];
3719
+ var GridFormTextArea = function (props) {
3720
+ var _a;
3721
+ var _b = useGridPopoverContext(), field = _b.field, initialVale = _b.value;
3722
+ var _c = useState(initialVale != null ? "".concat(initialVale) : ""), value = _c[0], setValue = _c[1];
3635
3723
  var invalid = useCallback(function () {
3636
3724
  if (props.required && value.length == 0) {
3637
3725
  return "Some text is required";
@@ -3645,39 +3733,39 @@ var GridFormTextArea = function (_props) {
3645
3733
  return null;
3646
3734
  }, [props, value]);
3647
3735
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3648
- var field;
3649
3736
  return __generator(this, function (_a) {
3650
3737
  switch (_a.label) {
3651
3738
  case 0:
3652
3739
  if (invalid())
3653
3740
  return [2 /*return*/, false];
3654
- if (props.value === (value !== null && value !== void 0 ? value : ""))
3741
+ if (initialVale === (value !== null && value !== void 0 ? value : ""))
3655
3742
  return [2 /*return*/, true];
3656
3743
  if (!props.onSave) return [3 /*break*/, 2];
3657
3744
  return [4 /*yield*/, props.onSave(selectedRows, value)];
3658
3745
  case 1: return [2 /*return*/, _a.sent()];
3659
3746
  case 2:
3660
- field = props.field;
3661
3747
  if (field == null) {
3662
3748
  console.error("ColDef has no field set");
3663
3749
  return [2 /*return*/, false];
3664
3750
  }
3665
- selectedRows.forEach(function (row) { return (row[field] = value); });
3751
+ selectedRows.forEach(function (row) {
3752
+ row[field] = value;
3753
+ });
3666
3754
  return [2 /*return*/, true];
3667
3755
  }
3668
3756
  });
3669
- }); }, [props, invalid, value]);
3757
+ }); }, [invalid, initialVale, value, props, field]);
3670
3758
  var popoverWrapper = useGridPopoverHook({ className: props.className, save: save }).popoverWrapper;
3671
- return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_b = props.width) !== null && _b !== void 0 ? _b : 240 } }, { children: jsx(TextAreaInput, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), inputProps: { placeholder: props.placeholder } }) })));
3759
+ return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 } }, { children: jsx(TextAreaInput, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), inputProps: { placeholder: props.placeholder } }) })));
3672
3760
  };
3673
3761
 
3674
3762
  var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __assign({ editor: GridFormTextArea }, params)); };
3675
3763
 
3676
- var GridFormTextInput = function (_props) {
3764
+ var GridFormTextInput = function (props) {
3677
3765
  var _a;
3678
- var props = _props;
3679
- var initValue = props.value == null ? "" : "".concat(props.value);
3680
- var _b = useState(initValue), value = _b[0], setValue = _b[1];
3766
+ var _b = useGridPopoverContext(), field = _b.field, data = _b.data, initialVale = _b.value;
3767
+ var initValue = initialVale == null ? "" : "".concat(initialVale);
3768
+ var _c = useState(initValue), value = _c[0], setValue = _c[1];
3681
3769
  var invalid = useCallback(function () {
3682
3770
  var trimmedValue = value.trim();
3683
3771
  if (props.required && trimmedValue.length == 0) {
@@ -3687,12 +3775,12 @@ var GridFormTextInput = function (_props) {
3687
3775
  return "Text must be no longer than ".concat(props.maxLength, " characters");
3688
3776
  }
3689
3777
  if (props.validate) {
3690
- return props.validate(trimmedValue, props.data);
3778
+ return props.validate(trimmedValue, data);
3691
3779
  }
3692
3780
  return null;
3693
- }, [props, value]);
3781
+ }, [data, props, value]);
3694
3782
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3695
- var trimmedValue, field;
3783
+ var trimmedValue;
3696
3784
  return __generator(this, function (_a) {
3697
3785
  switch (_a.label) {
3698
3786
  case 0:
@@ -3705,23 +3793,19 @@ var GridFormTextInput = function (_props) {
3705
3793
  return [4 /*yield*/, props.onSave(selectedRows, trimmedValue)];
3706
3794
  case 1: return [2 /*return*/, _a.sent()];
3707
3795
  case 2:
3708
- field = props.field;
3709
3796
  if (field == null) {
3710
3797
  console.error("ColDef has no field set");
3711
3798
  return [2 /*return*/, false];
3712
3799
  }
3713
- selectedRows.forEach(function (row) { return (row[field] = trimmedValue); });
3800
+ selectedRows.forEach(function (row) {
3801
+ row[field] = trimmedValue;
3802
+ });
3714
3803
  return [2 /*return*/, true];
3715
3804
  }
3716
3805
  });
3717
- }); }, [invalid, value, initValue, props]);
3718
- var _c = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _c.popoverWrapper, triggerSave = _c.triggerSave;
3719
- return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 }, className: "FormTest" }, { children: jsx(TextInputFormatted, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units, onMouseEnter: function (e) {
3720
- if (document.activeElement != e.currentTarget) {
3721
- e.currentTarget.focus();
3722
- e.currentTarget.selectionStart = e.currentTarget.value.length;
3723
- }
3724
- }, inputProps: {
3806
+ }); }, [invalid, value, initValue, props, field]);
3807
+ var _d = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _d.popoverWrapper, triggerSave = _d.triggerSave;
3808
+ return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 }, className: "FormTest" }, { children: jsx(TextInputFormatted, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units, inputProps: {
3725
3809
  style: { width: "100%" },
3726
3810
  placeholder: props.placeholder,
3727
3811
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3798,12 +3882,7 @@ var GridSubComponentTextArea = function (props) {
3798
3882
  useEffect(function () {
3799
3883
  setValid(value != null && validate(value) == null);
3800
3884
  }, [setValid, validate, value]);
3801
- return (jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsx(TextInputFormatted, { className: "free-text-input", value: value, onMouseEnter: function (e) {
3802
- if (document.activeElement != e.currentTarget) {
3803
- e.currentTarget.focus();
3804
- e.currentTarget.selectionStart = e.currentTarget.value.length;
3805
- }
3806
- }, onChange: function (e) { return setValue(e.target.value); }, error: validate(value), inputProps: {
3885
+ return (jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsx(TextInputFormatted, { className: "free-text-input", value: value, onChange: function (e) { return setValue(e.target.value); }, error: validate(value), inputProps: {
3807
3886
  autoFocus: true,
3808
3887
  placeholder: props.placeholder,
3809
3888
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3924,5 +4003,5 @@ var ActionButton = function (_a) {
3924
4003
  } })) : (jsx(LuiIcon, { name: icon, alt: (_c = ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : name) !== null && _c !== void 0 ? _c : "", size: size })), jsxs("span", __assign({ className: "ActionButton-minimalArea" }, { children: [jsx("span", __assign({ className: "ActionButton-minimalAreaDisplay" }, { children: (_d = (localInProgress ? inProgressName : name)) !== null && _d !== void 0 ? _d : name })), jsx("span", __assign({ className: "ActionButton-minimalAreaExpand" }, { children: name }))] }))] })));
3925
4004
  };
3926
4005
 
3927
- export { ActionButton, ComponentLoadingWrapper, ControlledMenu, FocusableItem, GenericCellEditorComponent, GenericMultiEditCellClass, Grid, GridCell, GridCellRenderer, GridContext, GridContextProvider, GridFormDropDown, GridFormMultiSelect, GridFormPopoverMenu, GridFormSubComponentTextInput, GridHeaderSelect, GridIcon, GridLoadableCell, GridPopoutEditMultiSelect, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridRendererGenericCell, GridSubComponentTextArea, GridUpdatingContext, GridUpdatingContextProvider, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, bearingCorrectionValueFormatter, bearingNumberParser, bearingStringValidator, bearingValueFormatter, convertDDToDMS, hasParentClass, isFloat, isNotEmpty, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait };
4006
+ export { ActionButton, ComponentLoadingWrapper, ControlledMenu, FocusableItem, GenericCellEditorComponentWrapper, GenericMultiEditCellClass, Grid, GridCell, GridCellRenderer, GridContext, GridContextProvider, GridFormDropDown, GridFormMultiSelect, GridFormPopoverMenu, GridFormSubComponentTextInput, GridHeaderSelect, GridIcon, GridLoadableCell, GridPopoutEditMultiSelect, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridRendererGenericCell, GridSubComponentTextArea, GridUpdatingContext, GridUpdatingContextProvider, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, bearingCorrectionValueFormatter, bearingNumberParser, bearingStringValidator, bearingValueFormatter, convertDDToDMS, hasParentClass, isFloat, isNotEmpty, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait };
3928
4007
  //# sourceMappingURL=step-ag-grid.esm.js.map