@linzjs/step-ag-grid 2.4.11 → 3.0.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.
Files changed (38) hide show
  1. package/dist/index.js +301 -249
  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 +7 -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 +5 -3
  13. package/dist/src/contexts/GridPopoverContextProvider.d.ts +3 -1
  14. package/dist/src/lui/TextInputFormatted.d.ts +3 -2
  15. package/dist/step-ag-grid.esm.js +302 -250
  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 +3 -7
  20. package/src/components/GridSubComponentTextArea.tsx +0 -6
  21. package/src/components/gridForm/GridFormDropDown.tsx +23 -30
  22. package/src/components/gridForm/GridFormEditBearing.tsx +10 -8
  23. package/src/components/gridForm/GridFormMessage.tsx +9 -7
  24. package/src/components/gridForm/GridFormMultiSelect.tsx +56 -48
  25. package/src/components/gridForm/GridFormPopoverMenu.tsx +94 -29
  26. package/src/components/gridForm/GridFormSubComponentTextInput.tsx +2 -1
  27. package/src/components/gridForm/GridFormTextArea.tsx +8 -8
  28. package/src/components/gridForm/GridFormTextInput.tsx +12 -16
  29. package/src/contexts/GridPopoverContext.tsx +10 -5
  30. package/src/contexts/GridPopoverContextProvider.tsx +24 -27
  31. package/src/lui/TextAreaInput.tsx +13 -1
  32. package/src/lui/TextInputFormatted.tsx +14 -3
  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 +18 -16
  36. package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +0 -1
  37. package/src/stories/grid/GridPopoutEditMultiSelect.stories.tsx +3 -3
  38. 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,49 @@ var GridPopoverContext = createContext({
2625
2652
  anchorRef: { current: null },
2626
2653
  saving: false,
2627
2654
  setSaving: function () { },
2628
- setProps: function () { },
2629
- propsRef: { current: null }
2655
+ field: "",
2656
+ value: null,
2657
+ data: null,
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
+ }); }); }
2630
2662
  });
2631
2663
 
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]);
2664
+ var GridPopoverContextProvider = function (_a) {
2665
+ var _b, _c, _d;
2666
+ var props = _a.props, children = _a.children;
2667
+ var _e = useContext(GridContext), getSelectedRows = _e.getSelectedRows, updatingCells = _e.updatingCells;
2668
+ var anchorRef = useRef(props.eGridCell);
2669
+ var _f = useState(false), saving = _f[0], setSaving = _f[1];
2670
+ var colDef = props.colDef;
2671
+ var cellEditorParams = colDef.cellEditorParams;
2672
+ var multiEdit = (_b = cellEditorParams === null || cellEditorParams === void 0 ? void 0 : cellEditorParams.multiEdit) !== null && _b !== void 0 ? _b : false;
2673
+ // Then item that is clicked on will always be first in the list
2674
+ var selectedRows = useMemo(function () { return (multiEdit ? sortBy(getSelectedRows(), function (row) { return row.id !== props.data.id; }) : [props.data]); }, [getSelectedRows, multiEdit, props.data]);
2675
+ var field = (_d = (_c = props.colDef) === null || _c === void 0 ? void 0 : _c.field) !== null && _d !== void 0 ? _d : "";
2676
+ var updateValue = useCallback(function (saveFn) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
2677
+ switch (_b.label) {
2678
+ case 0:
2679
+ _a = !saving;
2680
+ if (!_a) return [3 /*break*/, 2];
2681
+ return [4 /*yield*/, updatingCells({ selectedRows: selectedRows, field: field }, saveFn, setSaving)];
2682
+ case 1:
2683
+ _a = (_b.sent());
2684
+ _b.label = 2;
2685
+ case 2: return [2 /*return*/, _a];
2686
+ }
2687
+ }); }); }, [field, saving, selectedRows, updatingCells]);
2667
2688
  return (jsx(GridPopoverContext.Provider, __assign({ value: {
2668
2689
  anchorRef: anchorRef,
2669
2690
  saving: saving,
2670
2691
  setSaving: setSaving,
2671
- propsRef: propsRef,
2672
- setProps: setProps
2673
- } }, { children: props.children })));
2692
+ selectedRows: selectedRows,
2693
+ field: field,
2694
+ data: props.data,
2695
+ value: props.value,
2696
+ updateValue: updateValue
2697
+ } }, { children: children })));
2674
2698
  };
2675
2699
 
2676
2700
  var GridCellRenderer = function (props) {
@@ -2692,7 +2716,7 @@ var GridCell = function (props, custom) {
2692
2716
  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
2717
  cellClass: (custom === null || custom === void 0 ? void 0 : custom.multiEdit) ? GenericMultiEditCellClass : undefined,
2694
2718
  editable: (_a = props.editable) !== null && _a !== void 0 ? _a : true,
2695
- cellEditor: GenericCellEditorComponent(custom.editor)
2719
+ cellEditor: GenericCellEditorComponentWrapper(custom)
2696
2720
  })), ((custom === null || custom === void 0 ? void 0 : custom.editorParams) && {
2697
2721
  cellEditorParams: __assign(__assign({}, custom.editorParams), { multiEdit: custom.multiEdit })
2698
2722
  })), {
@@ -2707,21 +2731,10 @@ var GridCell = function (props, custom) {
2707
2731
  return JSON.stringify(params.value);
2708
2732
  } }), props), { cellRenderer: GridCellRenderer, cellRendererParams: __assign({ originalCellRenderer: props.cellRenderer }, props.cellRendererParams) });
2709
2733
  };
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 }))) }));
2734
+ var GenericCellEditorComponentWrapper = function (custom) {
2735
+ return forwardRef(function GenericCellEditorComponentFr(cellEditorParams, _) {
2736
+ 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
2737
  });
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
2738
  };
2726
2739
 
2727
2740
  /**
@@ -2742,7 +2755,7 @@ var ComponentLoadingWrapper = function (props) {
2742
2755
 
2743
2756
  var useGridPopoverHook = function (props) {
2744
2757
  var stopEditing = useContext(GridContext).stopEditing;
2745
- var _a = useContext(GridPopoverContext), anchorRef = _a.anchorRef, saving = _a.saving, propsRef = _a.propsRef;
2758
+ var _a = useContext(GridPopoverContext), anchorRef = _a.anchorRef, saving = _a.saving, updateValue = _a.updateValue;
2746
2759
  var saveButtonRef = useRef(null);
2747
2760
  var _b = useState(false), isOpen = _b[0], setOpen = _b[1];
2748
2761
  useEffect(function () {
@@ -2750,22 +2763,20 @@ var useGridPopoverHook = function (props) {
2750
2763
  }, []);
2751
2764
  var triggerSave = useCallback(function (reason) { return __awaiter(void 0, void 0, void 0, function () {
2752
2765
  var _a, _b;
2753
- var _c, _d;
2754
- return __generator(this, function (_e) {
2755
- switch (_e.label) {
2766
+ return __generator(this, function (_c) {
2767
+ switch (_c.label) {
2756
2768
  case 0:
2757
- _a = reason == "cancel" ||
2758
- !props.save;
2769
+ _a = reason == "cancel" || !props.save;
2759
2770
  if (_a) return [3 /*break*/, 3];
2760
- _b = ((_c = propsRef.current) === null || _c === void 0 ? void 0 : _c.updateValue);
2771
+ _b = updateValue;
2761
2772
  if (!_b) return [3 /*break*/, 2];
2762
- return [4 /*yield*/, ((_d = propsRef.current) === null || _d === void 0 ? void 0 : _d.updateValue(props.save))];
2773
+ return [4 /*yield*/, updateValue(props.save)];
2763
2774
  case 1:
2764
- _b = (_e.sent());
2765
- _e.label = 2;
2775
+ _b = (_c.sent());
2776
+ _c.label = 2;
2766
2777
  case 2:
2767
2778
  _a = (_b);
2768
- _e.label = 3;
2779
+ _c.label = 3;
2769
2780
  case 3:
2770
2781
  if (_a) {
2771
2782
  setOpen(false);
@@ -2774,7 +2785,7 @@ var useGridPopoverHook = function (props) {
2774
2785
  return [2 /*return*/];
2775
2786
  }
2776
2787
  });
2777
- }); }, [props, stopEditing, propsRef]);
2788
+ }); }, [props.save, stopEditing, updateValue]);
2778
2789
  var popoverWrapper = useCallback(function (children) {
2779
2790
  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
2791
  triggerSave(event.reason).then();
@@ -2897,66 +2908,57 @@ var MenuHeaderString = "_____MENU_HEADER_____";
2897
2908
  var MenuHeaderItem = function (title) {
2898
2909
  return { label: title, value: MenuHeaderString };
2899
2910
  };
2900
- var GridFormDropDown = function (_props) {
2901
- var props = _props;
2902
- var _a = useContext(GridContext), updatingCells = _a.updatingCells, stopEditing = _a.stopEditing;
2911
+ var GridFormDropDown = function (props) {
2912
+ var _a = useContext(GridPopoverContext), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue;
2913
+ var stopEditing = useContext(GridContext).stopEditing;
2903
2914
  var _b = useState(""), filter = _b[0], setFilter = _b[1];
2904
2915
  var _c = useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
2905
2916
  var optionsInitialising = useRef(false);
2906
2917
  var _d = useState(null), options = _d[0], setOptions = _d[1];
2907
2918
  var _e = useState([]), subComponentValues = _e[0], setSubComponentValues = _e[1];
2908
2919
  var selectItemHandler = useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
2909
- var field;
2910
2920
  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
- }
2921
+ return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2922
+ var hasChanged;
2923
+ return __generator(this, function (_a) {
2924
+ switch (_a.label) {
2925
+ case 0:
2926
+ hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
2927
+ if (!hasChanged) return [3 /*break*/, 3];
2928
+ if (!props.onSelectedItem) return [3 /*break*/, 2];
2929
+ return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
2930
+ case 1:
2931
+ _a.sent();
2932
+ return [3 /*break*/, 3];
2933
+ case 2:
2934
+ selectedRows.forEach(function (row) { return (row[field] = value); });
2935
+ _a.label = 3;
2936
+ case 3: return [2 /*return*/, true];
2937
+ }
2938
+ });
2939
+ }); })];
2935
2940
  });
2936
- }); }, [props, updatingCells]);
2941
+ }); }, [field, props, updateValue]);
2937
2942
  var selectFilterHandler = useCallback(function (value) { return __awaiter(void 0, void 0, void 0, function () {
2938
- var field;
2939
2943
  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
- }
2944
+ return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2945
+ var _a;
2946
+ return __generator(this, function (_b) {
2947
+ switch (_b.label) {
2948
+ case 0:
2949
+ _a = props.onSelectFilter;
2950
+ if (!_a) return [3 /*break*/, 2];
2951
+ return [4 /*yield*/, props.onSelectFilter({ selectedRows: selectedRows, value: value })];
2952
+ case 1:
2953
+ _a = (_b.sent());
2954
+ _b.label = 2;
2955
+ case 2:
2956
+ return [2 /*return*/, true];
2957
+ }
2958
+ });
2959
+ }); })];
2958
2960
  });
2959
- }); }, [props, updatingCells]);
2961
+ }); }, [props, updateValue]);
2960
2962
  // Load up options list if it's async function
2961
2963
  useEffect(function () {
2962
2964
  var _a;
@@ -2970,7 +2972,7 @@ var GridFormDropDown = function (_props) {
2970
2972
  switch (_a.label) {
2971
2973
  case 0:
2972
2974
  if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
2973
- return [4 /*yield*/, optionsConf(props.selectedRows, filter)];
2975
+ return [4 /*yield*/, optionsConf(selectedRows, filter)];
2974
2976
  case 1:
2975
2977
  optionsConf = _a.sent();
2976
2978
  _a.label = 2;
@@ -2998,7 +3000,7 @@ var GridFormDropDown = function (_props) {
2998
3000
  }
2999
3001
  });
3000
3002
  }); })();
3001
- }, [filter, options, props]);
3003
+ }, [filter, options, props, selectedRows]);
3002
3004
  // Local filtering.
3003
3005
  useEffect(function () {
3004
3006
  if (props.filtered == "local") {
@@ -3063,11 +3065,11 @@ var GridFormDropDown = function (_props) {
3063
3065
  var _b;
3064
3066
  var ref = _a.ref;
3065
3067
  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) {
3068
+ } })), 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(field, "-empty")), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3067
3069
  var _a;
3068
3070
  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
+ selectItemHandler(item.value).then();
3072
+ } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(field, "-").concat(index))) : (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3071
3073
  return item.subComponent &&
3072
3074
  item.subComponent({
3073
3075
  setValue: function (value) {
@@ -3102,9 +3104,9 @@ var GridFormDropDown = function (_props) {
3102
3104
  }
3103
3105
  return false;
3104
3106
  },
3105
- key: "".concat(props.field, "-").concat(index, "_subcomponent_inner")
3107
+ key: "".concat(field, "-").concat(index, "_subcomponent_inner")
3106
3108
  }, ref);
3107
- } }), "".concat(props.field, "-").concat(index, "_subcomponent"))) }, "menu-wrapper-".concat(index)));
3109
+ } }), "".concat(field, "-").concat(index, "_subcomponent"))) }, "menu-wrapper-".concat(index)));
3108
3110
  })] }) }))] }));
3109
3111
  };
3110
3112
 
@@ -3125,40 +3127,48 @@ var GridSubComponentContext = createContext({
3125
3127
  });
3126
3128
 
3127
3129
  var GridFormMultiSelect = function (props) {
3128
- var selectedRows = props.selectedRows;
3129
- var initialiseValues = useMemo(function () { return props.initialSelectedValues && props.initialSelectedValues(selectedRows); }, [props, selectedRows]);
3130
+ var selectedRows = useContext(GridPopoverContext).selectedRows;
3131
+ var initialiseValues = useMemo(function () {
3132
+ var r = props.initialSelectedValues && props.initialSelectedValues(selectedRows);
3133
+ // convert array of strings to object<value,null>
3134
+ return Array.isArray(r) ? fromPairs(r.map(function (v) { return [v, null]; })) : r;
3135
+ }, [props, selectedRows]);
3130
3136
  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];
3137
+ var _a = useState(function () { return initialiseValues !== null && initialiseValues !== void 0 ? initialiseValues : {}; }), selectedValues = _a[0], setSelectedValues = _a[1];
3138
+ var _b = useState(""), filter = _b[0], setFilter = _b[1];
3139
+ var _c = useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
3139
3140
  var optionsInitialising = useRef(false);
3140
- var _e = useState(), options = _e[0], setOptions = _e[1];
3141
+ var _d = useState(), options = _d[0], setOptions = _d[1];
3141
3142
  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) {
3143
+ var validations, notValid, menuOptionSubValueResult;
3144
+ return __generator(this, function (_a) {
3145
+ switch (_a.label) {
3146
3146
  case 0:
3147
3147
  if (!props.onSave) return [3 /*break*/, 2];
3148
- validations = pick(subComponentIsValid.current, selectedValues);
3148
+ if (!options) {
3149
+ console.error("options not initialised");
3150
+ return [2 /*return*/, false];
3151
+ }
3152
+ validations = pick(subComponentIsValid.current, Object.keys(selectedValues));
3149
3153
  notValid = Object.values(validations).some(function (v) { return !v; });
3150
3154
  if (notValid)
3151
3155
  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)] }));
3156
+ menuOptionSubValueResult = toPairs(selectedValues).map(function (_a) {
3157
+ var value = _a[0], subValue = _a[1];
3158
+ var o = __assign({}, options.find(function (o) { return o.value == value; }));
3159
+ o.subValue = subValue;
3160
+ return o;
3155
3161
  });
3156
- return [4 /*yield*/, props.onSave(selectedRows, selectedResults)];
3157
- case 1: return [2 /*return*/, _b.sent()];
3162
+ if (isEqual(initialiseValues, selectedValues)) {
3163
+ // No changes to save
3164
+ return [2 /*return*/, true];
3165
+ }
3166
+ return [4 /*yield*/, props.onSave(selectedRows, menuOptionSubValueResult)];
3167
+ case 1: return [2 /*return*/, _a.sent()];
3158
3168
  case 2: return [2 /*return*/, true];
3159
3169
  }
3160
3170
  });
3161
- }); }, [options, props, selectedValues, subSelectedValues]);
3171
+ }); }, [initialiseValues, options, props, selectedValues]);
3162
3172
  // Load up options list if it's async function
3163
3173
  useEffect(function () {
3164
3174
  var _a;
@@ -3178,7 +3188,7 @@ var GridFormMultiSelect = function (props) {
3178
3188
  _a.label = 2;
3179
3189
  case 2:
3180
3190
  optionsList = optionsConf === null || optionsConf === void 0 ? void 0 : optionsConf.map(function (item) {
3181
- if (item == null || typeof item == "string" || typeof item == "number") {
3191
+ if (item == null || typeof item === "string" || typeof item === "number") {
3182
3192
  item = { value: item, label: item };
3183
3193
  }
3184
3194
  return item;
@@ -3211,7 +3221,16 @@ var GridFormMultiSelect = function (props) {
3211
3221
  })
3212
3222
  .filter(function (r) { return r !== undefined; }));
3213
3223
  }, [props.filtered, filter, options]);
3214
- var _f = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _f.popoverWrapper, triggerSave = _f.triggerSave;
3224
+ var toggleValue = useCallback(function (item) {
3225
+ var _a;
3226
+ if ("".concat(item.value) in selectedValues) {
3227
+ setSelectedValues(omit(selectedValues, ["".concat(item.value)]));
3228
+ }
3229
+ else {
3230
+ setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = null, _a)));
3231
+ }
3232
+ }, [selectedValues]);
3233
+ var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3215
3234
  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
3235
  var _b;
3217
3236
  var ref = _a.ref;
@@ -3220,29 +3239,19 @@ var GridFormMultiSelect = function (props) {
3220
3239
  var _a;
3221
3240
  return item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxs("div", { children: [jsx(MenuItem, __assign({ onClick: function (e) {
3222
3241
  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
- }
3242
+ toggleValue(item);
3229
3243
  }, onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () {
3230
3244
  return __generator(this, function (_a) {
3231
3245
  if (e.key === "Enter")
3232
3246
  triggerSave().then();
3233
3247
  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
- }
3248
+ toggleValue(item);
3240
3249
  e.preventDefault();
3241
3250
  e.stopPropagation();
3242
3251
  }
3243
3252
  return [2 /*return*/];
3244
3253
  });
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: {
3254
+ }); } }, { 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
3255
  onClick: function (e) {
3247
3256
  e.preventDefault();
3248
3257
  e.stopPropagation();
@@ -3250,12 +3259,12 @@ var GridFormMultiSelect = function (props) {
3250
3259
  }
3251
3260
  }, onChange: function () {
3252
3261
  /*Do nothing, change handled by menuItem*/
3253
- } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3262
+ } }) })), "".concat(item.value) in selectedValues && item.subComponent && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3254
3263
  return item.subComponent && (jsx(GridSubComponentContext.Provider, __assign({ value: {
3255
- value: subSelectedValues["".concat(item.value)],
3264
+ value: selectedValues["".concat(item.value)],
3256
3265
  setValue: function (value) {
3257
- subSelectedValues["".concat(item.value)] = value;
3258
- setSubSelectedValues(__assign({}, subSelectedValues));
3266
+ var _a;
3267
+ setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = value, _a)));
3259
3268
  },
3260
3269
  setValid: function (valid) {
3261
3270
  subComponentIsValid.current["".concat(item.value)] = valid;
@@ -3279,11 +3288,15 @@ var PopoutMenuSeparator = Object.freeze({ __isMenuSeparator__: true });
3279
3288
  * NOTE: If the popout menu doesn't appear on single click when also selecting row it's because
3280
3289
  * you need a useMemo around your columnDefs
3281
3290
  */
3282
- var GridFormPopoverMenu = function (_props) {
3283
- var props = _props;
3284
- var updatingCells = useContext(GridContext).updatingCells;
3291
+ var GridFormPopoverMenu = function (props) {
3292
+ var _a = useContext(GridPopoverContext), selectedRows = _a.selectedRows, updateValue = _a.updateValue;
3285
3293
  var optionsInitialising = useRef(false);
3286
- var _a = useState(), options = _a[0], setOptions = _a[1];
3294
+ var _b = useState(), options = _b[0], setOptions = _b[1];
3295
+ // Save triggers during async action processing which triggers another action(), this ref blocks that
3296
+ var actionProcessing = useRef(false);
3297
+ var _c = useState(null), subComponentSelected = _c[0], setSubComponentSelected = _c[1];
3298
+ var subComponentIsValid = useRef(false);
3299
+ var _d = useState(), subSelectedValue = _d[0], setSubSelectedValue = _d[1];
3287
3300
  // Load up options list if it's async function
3288
3301
  useEffect(function () {
3289
3302
  var _a;
@@ -3292,56 +3305,102 @@ var GridFormPopoverMenu = function (_props) {
3292
3305
  optionsInitialising.current = true;
3293
3306
  var optionsConf = (_a = props.options) !== null && _a !== void 0 ? _a : [];
3294
3307
  (function () { return __awaiter(void 0, void 0, void 0, function () {
3295
- var _a;
3296
- return __generator(this, function (_b) {
3297
- switch (_b.label) {
3308
+ var _a, _b;
3309
+ return __generator(this, function (_c) {
3310
+ switch (_c.label) {
3298
3311
  case 0:
3299
- if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
3300
3312
  _a = setOptions;
3301
- return [4 /*yield*/, optionsConf(props.selectedRows)];
3313
+ if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
3314
+ return [4 /*yield*/, optionsConf(selectedRows)];
3302
3315
  case 1:
3303
- _a.apply(void 0, [_b.sent()]);
3316
+ _b = _c.sent();
3304
3317
  return [3 /*break*/, 3];
3305
3318
  case 2:
3306
- setOptions(optionsConf);
3307
- _b.label = 3;
3319
+ _b = optionsConf;
3320
+ _c.label = 3;
3308
3321
  case 3:
3322
+ _a.apply(void 0, [_b]);
3309
3323
  optionsInitialising.current = false;
3310
3324
  return [2 /*return*/];
3311
3325
  }
3312
3326
  });
3313
3327
  }); })();
3314
- }, [options, props.options, props.selectedRows]);
3328
+ }, [options, props.options, selectedRows]);
3315
3329
  var actionClick = useCallback(function (menuOption) { return __awaiter(void 0, void 0, void 0, function () {
3316
3330
  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
- }
3331
+ actionProcessing.current = true;
3332
+ return [2 /*return*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () {
3333
+ var result, _a;
3334
+ return __generator(this, function (_b) {
3335
+ switch (_b.label) {
3336
+ case 0:
3337
+ result = __assign(__assign({}, menuOption), { subValue: subSelectedValue });
3338
+ _a = menuOption.action;
3339
+ if (!_a) return [3 /*break*/, 2];
3340
+ return [4 /*yield*/, menuOption.action(selectedRows, result)];
3341
+ case 1:
3342
+ _a = (_b.sent());
3343
+ _b.label = 2;
3344
+ case 2:
3345
+ actionProcessing.current = false;
3346
+ return [2 /*return*/, true];
3347
+ }
3348
+ });
3349
+ }); })];
3336
3350
  });
3337
- }); }, [props.field, props.selectedRows, updatingCells]);
3338
- var selectedRowCount = props.selectedRows.length;
3351
+ }); }, [selectedRows, subSelectedValue, updateValue]);
3352
+ var onMenuItemClick = useCallback(function (e, item) {
3353
+ if (item.subComponent) {
3354
+ subComponentIsValid.current = false;
3355
+ setSubSelectedValue(null);
3356
+ setSubComponentSelected(subComponentSelected === item ? null : item);
3357
+ e.keepOpen = true;
3358
+ }
3359
+ else {
3360
+ setSubComponentSelected(null);
3361
+ actionClick(item).then();
3362
+ }
3363
+ }, [actionClick, subComponentSelected]);
3364
+ var selectedRowCount = selectedRows.length;
3339
3365
  var filteredOptions = options === null || options === void 0 ? void 0 : options.filter(function (menuOption) {
3340
3366
  return menuOption.label === PopoutMenuSeparator || selectedRowCount === 1 || menuOption.supportsMultiEdit;
3341
3367
  });
3342
- var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3368
+ var save = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
3369
+ return __generator(this, function (_a) {
3370
+ switch (_a.label) {
3371
+ case 0:
3372
+ if (!(!actionProcessing.current && subComponentSelected)) return [3 /*break*/, 2];
3373
+ if (!subComponentIsValid.current)
3374
+ return [2 /*return*/, false];
3375
+ return [4 /*yield*/, actionClick(subComponentSelected)];
3376
+ case 1:
3377
+ _a.sent();
3378
+ _a.label = 2;
3379
+ case 2: return [2 /*return*/, true];
3380
+ }
3381
+ });
3382
+ }); }, [actionClick, subComponentSelected]);
3383
+ var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3384
+ var localTriggerSave = function (reason) { return __awaiter(void 0, void 0, void 0, function () {
3385
+ return __generator(this, function (_a) {
3386
+ if (!subComponentIsValid.current)
3387
+ return [2 /*return*/];
3388
+ return [2 /*return*/, triggerSave(reason)];
3389
+ });
3390
+ }); };
3343
3391
  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))));
3392
+ 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 (_) {
3393
+ return item.subComponent && (jsx(GridSubComponentContext.Provider, __assign({ value: {
3394
+ value: subSelectedValue,
3395
+ setValue: function (value) {
3396
+ setSubSelectedValue(value);
3397
+ },
3398
+ setValid: function (valid) {
3399
+ subComponentIsValid.current = valid;
3400
+ },
3401
+ triggerSave: localTriggerSave
3402
+ } }, { children: jsx(item.subComponent, {}) })));
3403
+ } }), "".concat(item.label, "_subcomponent")))] })));
3345
3404
  }) }) })));
3346
3405
  };
3347
3406
 
@@ -3440,15 +3499,16 @@ var css_248z$2 = ".LuiTextInput{margin-bottom:0}.LuiTextInput-formatted{color:#b
3440
3499
  styleInject(css_248z$2);
3441
3500
 
3442
3501
  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 }, 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] })))] })));
3502
+ 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) {
3503
+ e.currentTarget.focus();
3504
+ } }, 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
3505
  };
3445
3506
 
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];
3507
+ var GridFormEditBearing = function (props) {
3508
+ var _a = useContext(GridPopoverContext), field = _a.field, initialValue = _a.value;
3509
+ var _b = useState("".concat(initialValue !== null && initialValue !== void 0 ? initialValue : "")), value = _b[0], setValue = _b[1];
3450
3510
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3451
- var parsedValue, field_1;
3511
+ var parsedValue;
3452
3512
  return __generator(this, function (_a) {
3453
3513
  switch (_a.label) {
3454
3514
  case 0:
@@ -3456,25 +3516,24 @@ var GridFormEditBearing = function (_props) {
3456
3516
  return [2 /*return*/, false];
3457
3517
  parsedValue = bearingNumberParser(value);
3458
3518
  // Value didn't change so don't save just cancel
3459
- if (parsedValue === props.value) {
3519
+ if (parsedValue === initialValue) {
3460
3520
  return [2 /*return*/, true];
3461
3521
  }
3462
3522
  if (!props.onSave) return [3 /*break*/, 2];
3463
3523
  return [4 /*yield*/, props.onSave(selectedRows, parsedValue)];
3464
3524
  case 1: return [2 /*return*/, _a.sent()];
3465
3525
  case 2:
3466
- field_1 = props.field;
3467
- if (field_1 == null) {
3526
+ if (field == null) {
3468
3527
  console.error("field is not defined in ColDef");
3469
3528
  }
3470
3529
  else {
3471
- selectedRows.forEach(function (row) { return (row[field_1] = parsedValue); });
3530
+ selectedRows.forEach(function (row) { return (row[field] = parsedValue); });
3472
3531
  }
3473
3532
  _a.label = 3;
3474
3533
  case 3: return [2 /*return*/, true];
3475
3534
  }
3476
3535
  });
3477
- }); }, [props, value]);
3536
+ }); }, [field, initialValue, props, value]);
3478
3537
  var _c = useGridPopoverHook({ className: props.className, save: save }), triggerSave = _c.triggerSave, popoverWrapper = _c.popoverWrapper;
3479
3538
  return popoverWrapper(jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsx(TextInputFormatted, { value: value !== null && value !== void 0 ? value : "", onChange: function (e) {
3480
3539
  setValue(e.target.value.trim());
@@ -3527,8 +3586,8 @@ var GridPopoverEditDropDown = function (colDef, props) {
3527
3586
  className: "GridPopoverEditDropDown-containerMedium" }, props.editorParams) }));
3528
3587
  };
3529
3588
 
3530
- var GridFormMessage = function (_props) {
3531
- var props = _props;
3589
+ var GridFormMessage = function (props) {
3590
+ var selectedRows = useContext(GridPopoverContext).selectedRows;
3532
3591
  var _a = useState(null), message = _a[0], setMessage = _a[1];
3533
3592
  var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3534
3593
  useEffect(function () {
@@ -3538,14 +3597,14 @@ var GridFormMessage = function (_props) {
3538
3597
  switch (_b.label) {
3539
3598
  case 0:
3540
3599
  _a = setMessage;
3541
- return [4 /*yield*/, props.message(props)];
3600
+ return [4 /*yield*/, props.message(selectedRows)];
3542
3601
  case 1:
3543
3602
  _a.apply(void 0, [_b.sent()]);
3544
3603
  return [2 /*return*/];
3545
3604
  }
3546
3605
  });
3547
3606
  }); })().then();
3548
- }, [props]);
3607
+ }, [props, selectedRows]);
3549
3608
  return popoverWrapper(jsx(ComponentLoadingWrapper, __assign({ loading: message === null, className: clsx("GridFormMessage-container", props.className) }, { children: jsx(Fragment$1, { children: message }) })));
3550
3609
  };
3551
3610
 
@@ -3625,13 +3684,18 @@ var useGenerateOrDefaultId = function (idFromProps) {
3625
3684
  var TextAreaInput = function (props) {
3626
3685
  var _a, _b;
3627
3686
  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] })))] })));
3687
+ 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) {
3688
+ if (document.activeElement != e.currentTarget) {
3689
+ e.currentTarget.focus();
3690
+ e.currentTarget.selectionStart = e.currentTarget.value.length;
3691
+ }
3692
+ } }))] }))] })), 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
3693
  };
3630
3694
 
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];
3695
+ var GridFormTextArea = function (props) {
3696
+ var _a;
3697
+ var _b = useContext(GridPopoverContext), field = _b.field, initialVale = _b.value;
3698
+ var _c = useState(initialVale !== null && initialVale !== void 0 ? initialVale : ""), value = _c[0], setValue = _c[1];
3635
3699
  var invalid = useCallback(function () {
3636
3700
  if (props.required && value.length == 0) {
3637
3701
  return "Some text is required";
@@ -3645,19 +3709,17 @@ var GridFormTextArea = function (_props) {
3645
3709
  return null;
3646
3710
  }, [props, value]);
3647
3711
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3648
- var field;
3649
3712
  return __generator(this, function (_a) {
3650
3713
  switch (_a.label) {
3651
3714
  case 0:
3652
3715
  if (invalid())
3653
3716
  return [2 /*return*/, false];
3654
- if (props.value === (value !== null && value !== void 0 ? value : ""))
3717
+ if (initialVale === (value !== null && value !== void 0 ? value : ""))
3655
3718
  return [2 /*return*/, true];
3656
3719
  if (!props.onSave) return [3 /*break*/, 2];
3657
3720
  return [4 /*yield*/, props.onSave(selectedRows, value)];
3658
3721
  case 1: return [2 /*return*/, _a.sent()];
3659
3722
  case 2:
3660
- field = props.field;
3661
3723
  if (field == null) {
3662
3724
  console.error("ColDef has no field set");
3663
3725
  return [2 /*return*/, false];
@@ -3666,18 +3728,18 @@ var GridFormTextArea = function (_props) {
3666
3728
  return [2 /*return*/, true];
3667
3729
  }
3668
3730
  });
3669
- }); }, [props, invalid, value]);
3731
+ }); }, [invalid, initialVale, value, props, field]);
3670
3732
  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 } }) })));
3733
+ 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
3734
  };
3673
3735
 
3674
3736
  var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __assign({ editor: GridFormTextArea }, params)); };
3675
3737
 
3676
- var GridFormTextInput = function (_props) {
3738
+ var GridFormTextInput = function (props) {
3677
3739
  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];
3740
+ var _b = useContext(GridPopoverContext), field = _b.field, data = _b.data, initialVale = _b.value;
3741
+ var initValue = initialVale == null ? "" : "".concat(initialVale);
3742
+ var _c = useState(initValue), value = _c[0], setValue = _c[1];
3681
3743
  var invalid = useCallback(function () {
3682
3744
  var trimmedValue = value.trim();
3683
3745
  if (props.required && trimmedValue.length == 0) {
@@ -3687,12 +3749,12 @@ var GridFormTextInput = function (_props) {
3687
3749
  return "Text must be no longer than ".concat(props.maxLength, " characters");
3688
3750
  }
3689
3751
  if (props.validate) {
3690
- return props.validate(trimmedValue, props.data);
3752
+ return props.validate(trimmedValue, data);
3691
3753
  }
3692
3754
  return null;
3693
- }, [props, value]);
3755
+ }, [data, props, value]);
3694
3756
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3695
- var trimmedValue, field;
3757
+ var trimmedValue;
3696
3758
  return __generator(this, function (_a) {
3697
3759
  switch (_a.label) {
3698
3760
  case 0:
@@ -3705,23 +3767,18 @@ var GridFormTextInput = function (_props) {
3705
3767
  return [4 /*yield*/, props.onSave(selectedRows, trimmedValue)];
3706
3768
  case 1: return [2 /*return*/, _a.sent()];
3707
3769
  case 2:
3708
- field = props.field;
3709
3770
  if (field == null) {
3710
3771
  console.error("ColDef has no field set");
3711
3772
  return [2 /*return*/, false];
3712
3773
  }
3774
+ // @ts-ignore row[field] row is of type any
3713
3775
  selectedRows.forEach(function (row) { return (row[field] = trimmedValue); });
3714
3776
  return [2 /*return*/, true];
3715
3777
  }
3716
3778
  });
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: {
3779
+ }); }, [invalid, value, initValue, props, field]);
3780
+ var _d = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _d.popoverWrapper, triggerSave = _d.triggerSave;
3781
+ 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
3782
  style: { width: "100%" },
3726
3783
  placeholder: props.placeholder,
3727
3784
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3798,12 +3855,7 @@ var GridSubComponentTextArea = function (props) {
3798
3855
  useEffect(function () {
3799
3856
  setValid(value != null && validate(value) == null);
3800
3857
  }, [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: {
3858
+ 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
3859
  autoFocus: true,
3808
3860
  placeholder: props.placeholder,
3809
3861
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3924,5 +3976,5 @@ var ActionButton = function (_a) {
3924
3976
  } })) : (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
3977
  };
3926
3978
 
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 };
3979
+ 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
3980
  //# sourceMappingURL=step-ag-grid.esm.js.map