@linzjs/step-ag-grid 2.5.0 → 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 +0 -1
  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 +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 +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
package/dist/index.js CHANGED
@@ -903,7 +903,7 @@ var positionMenu = function (props) {
903
903
 
904
904
  var MenuListContext = react.createContext({});
905
905
 
906
- // FIXME hacking a default context in here is probably bad
906
+ // FIXME hacking a default context in here is probably bad, but the context is mess
907
907
  var SettingsContext = react.createContext({});
908
908
 
909
909
  var MenuList = function (_a) {
@@ -921,6 +921,7 @@ var MenuList = function (_a) {
921
921
  var focusRef = react.useRef(null);
922
922
  var arrowRef = react.useRef(null);
923
923
  var prevOpen = react.useRef(false);
924
+ var latestWindowSize = react.useRef({ width: 0, height: 0 });
924
925
  var latestMenuSize = react.useRef({ width: 0, height: 0 });
925
926
  var latestHandlePosition = react.useRef(function () { });
926
927
  var _t = useItems(menuRef, focusRef), hoverItem = _t.hoverItem, dispatch = _t.dispatch, updateItems = _t.updateItems;
@@ -1146,6 +1147,32 @@ var MenuList = function (_a) {
1146
1147
  resizeObserver.observe(observeTarget, { box: "border-box" });
1147
1148
  return function () { return resizeObserver.unobserve(observeTarget); };
1148
1149
  }, [reposition]);
1150
+ // Matt added window resize observer
1151
+ react.useEffect(function () {
1152
+ if (typeof ResizeObserver !== "function" || reposition === "initial")
1153
+ return;
1154
+ var callback = lodashEs.debounce(function () {
1155
+ var _a = menuRef.current.ownerDocument.body.getBoundingClientRect(), width = _a.width, height = _a.height;
1156
+ if (width === 0 || height === 0)
1157
+ return;
1158
+ if (floatEqual(width, latestWindowSize.current.width, 1) &&
1159
+ floatEqual(height, latestWindowSize.current.height, 1)) {
1160
+ return;
1161
+ }
1162
+ latestWindowSize.current = { width: width, height: height };
1163
+ reactDom.flushSync(function () {
1164
+ latestHandlePosition.current();
1165
+ forceReposSubmenu();
1166
+ });
1167
+ }, 250);
1168
+ var resizeObserver = new ResizeObserver(callback);
1169
+ var observeTarget = menuRef.current.ownerDocument.body;
1170
+ resizeObserver.observe(observeTarget, { box: "border-box" });
1171
+ return function () {
1172
+ callback.cancel();
1173
+ resizeObserver.unobserve(observeTarget);
1174
+ };
1175
+ }, [reposition]);
1149
1176
  react.useEffect(function () {
1150
1177
  if (!isOpen) {
1151
1178
  dispatch(HoverActionTypes.RESET, undefined, 0);
@@ -2627,52 +2654,49 @@ var GridPopoverContext = react.createContext({
2627
2654
  anchorRef: { current: null },
2628
2655
  saving: false,
2629
2656
  setSaving: function () { },
2630
- setProps: function () { },
2631
- propsRef: { current: null }
2657
+ field: "",
2658
+ value: null,
2659
+ data: null,
2660
+ selectedRows: [],
2661
+ updateValue: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
2662
+ return [2 /*return*/, false];
2663
+ }); }); }
2632
2664
  });
2633
2665
 
2634
- var GridPopoverContextProvider = function (props) {
2635
- var _a = react.useContext(GridContext), getSelectedRows = _a.getSelectedRows, updatingCells = _a.updatingCells;
2636
- var anchorRef = react.useRef();
2637
- var propsRef = react.useRef({});
2638
- var _b = react.useState(false), saving = _b[0], setSaving = _b[1];
2639
- var setProps = react.useCallback(function (props, multiEdit) {
2640
- var _a, _b;
2641
- // Then item that is clicked on will always be first in the list
2642
- var selectedRows = multiEdit
2643
- ? lodashEs.sortBy(getSelectedRows(), function (row) { return row.id !== props.data.id; })
2644
- : [props.data];
2645
- var field = (_b = (_a = props.colDef) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : "";
2646
- anchorRef.current = props.eGridCell;
2647
- propsRef.current = {
2648
- value: props.value,
2649
- data: props.data,
2650
- field: field,
2651
- selectedRows: selectedRows,
2652
- updateValue: function (saveFn) { return __awaiter(void 0, void 0, void 0, function () {
2653
- var _a;
2654
- return __generator(this, function (_b) {
2655
- switch (_b.label) {
2656
- case 0:
2657
- _a = !saving;
2658
- if (!_a) return [3 /*break*/, 2];
2659
- return [4 /*yield*/, updatingCells({ selectedRows: selectedRows, field: field }, saveFn, setSaving)];
2660
- case 1:
2661
- _a = (_b.sent());
2662
- _b.label = 2;
2663
- case 2: return [2 /*return*/, _a];
2664
- }
2665
- });
2666
- }); }
2667
- };
2668
- }, [getSelectedRows, saving, updatingCells]);
2666
+ var GridPopoverContextProvider = function (_a) {
2667
+ var _b, _c, _d;
2668
+ var props = _a.props, children = _a.children;
2669
+ var _e = react.useContext(GridContext), getSelectedRows = _e.getSelectedRows, updatingCells = _e.updatingCells;
2670
+ var anchorRef = react.useRef(props.eGridCell);
2671
+ var _f = react.useState(false), saving = _f[0], setSaving = _f[1];
2672
+ var colDef = props.colDef;
2673
+ var cellEditorParams = colDef.cellEditorParams;
2674
+ var multiEdit = (_b = cellEditorParams === null || cellEditorParams === void 0 ? void 0 : cellEditorParams.multiEdit) !== null && _b !== void 0 ? _b : false;
2675
+ // Then item that is clicked on will always be first in the list
2676
+ var selectedRows = react.useMemo(function () { return (multiEdit ? lodashEs.sortBy(getSelectedRows(), function (row) { return row.id !== props.data.id; }) : [props.data]); }, [getSelectedRows, multiEdit, props.data]);
2677
+ var field = (_d = (_c = props.colDef) === null || _c === void 0 ? void 0 : _c.field) !== null && _d !== void 0 ? _d : "";
2678
+ var updateValue = react.useCallback(function (saveFn) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
2679
+ switch (_b.label) {
2680
+ case 0:
2681
+ _a = !saving;
2682
+ if (!_a) return [3 /*break*/, 2];
2683
+ return [4 /*yield*/, updatingCells({ selectedRows: selectedRows, field: field }, saveFn, setSaving)];
2684
+ case 1:
2685
+ _a = (_b.sent());
2686
+ _b.label = 2;
2687
+ case 2: return [2 /*return*/, _a];
2688
+ }
2689
+ }); }); }, [field, saving, selectedRows, updatingCells]);
2669
2690
  return (jsxRuntime.jsx(GridPopoverContext.Provider, __assign({ value: {
2670
2691
  anchorRef: anchorRef,
2671
2692
  saving: saving,
2672
2693
  setSaving: setSaving,
2673
- propsRef: propsRef,
2674
- setProps: setProps
2675
- } }, { children: props.children })));
2694
+ selectedRows: selectedRows,
2695
+ field: field,
2696
+ data: props.data,
2697
+ value: props.value,
2698
+ updateValue: updateValue
2699
+ } }, { children: children })));
2676
2700
  };
2677
2701
 
2678
2702
  var GridCellRenderer = function (props) {
@@ -2694,7 +2718,7 @@ var GridCell = function (props, custom) {
2694
2718
  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) && {
2695
2719
  cellClass: (custom === null || custom === void 0 ? void 0 : custom.multiEdit) ? GenericMultiEditCellClass : undefined,
2696
2720
  editable: (_a = props.editable) !== null && _a !== void 0 ? _a : true,
2697
- cellEditor: GenericCellEditorComponent(custom.editor)
2721
+ cellEditor: GenericCellEditorComponentWrapper(custom)
2698
2722
  })), ((custom === null || custom === void 0 ? void 0 : custom.editorParams) && {
2699
2723
  cellEditorParams: __assign(__assign({}, custom.editorParams), { multiEdit: custom.multiEdit })
2700
2724
  })), {
@@ -2709,21 +2733,10 @@ var GridCell = function (props, custom) {
2709
2733
  return JSON.stringify(params.value);
2710
2734
  } }), props), { cellRenderer: GridCellRenderer, cellRendererParams: __assign({ originalCellRenderer: props.cellRenderer }, props.cellRendererParams) });
2711
2735
  };
2712
- // TODO memo?
2713
- var GenericCellEditorComponent = function (editor) {
2714
- return react.forwardRef(function GenericCellEditorComponent2(props, _) {
2715
- return (jsxRuntime.jsx(GridPopoverContextProvider, { children: jsxRuntime.jsx(GenericCellEditorComponent3, __assign({}, __assign(__assign({}, props), { editor: editor }))) }));
2736
+ var GenericCellEditorComponentWrapper = function (custom) {
2737
+ return react.forwardRef(function GenericCellEditorComponentFr(cellEditorParams, _) {
2738
+ return (jsxRuntime.jsxs(GridPopoverContextProvider, __assign({ props: cellEditorParams }, { children: [jsxRuntime.jsx(cellEditorParams.colDef.cellRenderer, __assign({}, cellEditorParams, cellEditorParams.colDef.cellRendererParams)), (custom === null || custom === void 0 ? void 0 : custom.editor) && jsxRuntime.jsx(custom.editor, __assign({}, cellEditorParams))] })));
2716
2739
  });
2717
- };
2718
- var GenericCellEditorComponent3 = function (props) {
2719
- var _a;
2720
- var _b = react.useContext(GridPopoverContext), setProps = _b.setProps, propsRef = _b.propsRef;
2721
- var colDef = props.colDef;
2722
- var cellEditorParams = colDef.cellEditorParams;
2723
- var multiEdit = (_a = cellEditorParams === null || cellEditorParams === void 0 ? void 0 : cellEditorParams.multiEdit) !== null && _a !== void 0 ? _a : false;
2724
- // TODO don't need all these props in context
2725
- setProps(props, multiEdit);
2726
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(colDef.cellRenderer, __assign({}, props)), (props === null || props === void 0 ? void 0 : props.editor) && jsxRuntime.jsx(props.editor, __assign({}, cellEditorParams, propsRef.current))] }));
2727
2740
  };
2728
2741
 
2729
2742
  /**
@@ -2744,7 +2757,7 @@ var ComponentLoadingWrapper = function (props) {
2744
2757
 
2745
2758
  var useGridPopoverHook = function (props) {
2746
2759
  var stopEditing = react.useContext(GridContext).stopEditing;
2747
- var _a = react.useContext(GridPopoverContext), anchorRef = _a.anchorRef, saving = _a.saving, propsRef = _a.propsRef;
2760
+ var _a = react.useContext(GridPopoverContext), anchorRef = _a.anchorRef, saving = _a.saving, updateValue = _a.updateValue;
2748
2761
  var saveButtonRef = react.useRef(null);
2749
2762
  var _b = react.useState(false), isOpen = _b[0], setOpen = _b[1];
2750
2763
  react.useEffect(function () {
@@ -2752,22 +2765,20 @@ var useGridPopoverHook = function (props) {
2752
2765
  }, []);
2753
2766
  var triggerSave = react.useCallback(function (reason) { return __awaiter(void 0, void 0, void 0, function () {
2754
2767
  var _a, _b;
2755
- var _c, _d;
2756
- return __generator(this, function (_e) {
2757
- switch (_e.label) {
2768
+ return __generator(this, function (_c) {
2769
+ switch (_c.label) {
2758
2770
  case 0:
2759
- _a = reason == "cancel" ||
2760
- !props.save;
2771
+ _a = reason == "cancel" || !props.save;
2761
2772
  if (_a) return [3 /*break*/, 3];
2762
- _b = ((_c = propsRef.current) === null || _c === void 0 ? void 0 : _c.updateValue);
2773
+ _b = updateValue;
2763
2774
  if (!_b) return [3 /*break*/, 2];
2764
- return [4 /*yield*/, ((_d = propsRef.current) === null || _d === void 0 ? void 0 : _d.updateValue(props.save))];
2775
+ return [4 /*yield*/, updateValue(props.save)];
2765
2776
  case 1:
2766
- _b = (_e.sent());
2767
- _e.label = 2;
2777
+ _b = (_c.sent());
2778
+ _c.label = 2;
2768
2779
  case 2:
2769
2780
  _a = (_b);
2770
- _e.label = 3;
2781
+ _c.label = 3;
2771
2782
  case 3:
2772
2783
  if (_a) {
2773
2784
  setOpen(false);
@@ -2776,7 +2787,7 @@ var useGridPopoverHook = function (props) {
2776
2787
  return [2 /*return*/];
2777
2788
  }
2778
2789
  });
2779
- }); }, [props, stopEditing, propsRef]);
2790
+ }); }, [props.save, stopEditing, updateValue]);
2780
2791
  var popoverWrapper = react.useCallback(function (children) {
2781
2792
  return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: anchorRef.current && (jsxRuntime.jsxs(ControlledMenu, __assign({ state: isOpen ? "open" : "closed", portal: true, unmountOnClose: true, anchorRef: anchorRef, saveButtonRef: saveButtonRef, menuClassName: "step-ag-grid-react-menu", onClose: function (event) {
2782
2793
  triggerSave(event.reason).then();
@@ -2899,66 +2910,57 @@ var MenuHeaderString = "_____MENU_HEADER_____";
2899
2910
  var MenuHeaderItem = function (title) {
2900
2911
  return { label: title, value: MenuHeaderString };
2901
2912
  };
2902
- var GridFormDropDown = function (_props) {
2903
- var props = _props;
2904
- var _a = react.useContext(GridContext), updatingCells = _a.updatingCells, stopEditing = _a.stopEditing;
2913
+ var GridFormDropDown = function (props) {
2914
+ var _a = react.useContext(GridPopoverContext), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue;
2915
+ var stopEditing = react.useContext(GridContext).stopEditing;
2905
2916
  var _b = react.useState(""), filter = _b[0], setFilter = _b[1];
2906
2917
  var _c = react.useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
2907
2918
  var optionsInitialising = react.useRef(false);
2908
2919
  var _d = react.useState(null), options = _d[0], setOptions = _d[1];
2909
2920
  var _e = react.useState([]), subComponentValues = _e[0], setSubComponentValues = _e[1];
2910
2921
  var selectItemHandler = react.useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
2911
- var field;
2912
2922
  return __generator(this, function (_a) {
2913
- switch (_a.label) {
2914
- case 0:
2915
- field = props.field;
2916
- return [4 /*yield*/, updatingCells({ selectedRows: props.selectedRows, field: field }, function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2917
- var hasChanged;
2918
- return __generator(this, function (_a) {
2919
- switch (_a.label) {
2920
- case 0:
2921
- hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
2922
- if (!hasChanged) return [3 /*break*/, 3];
2923
- if (!props.onSelectedItem) return [3 /*break*/, 2];
2924
- return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
2925
- case 1:
2926
- _a.sent();
2927
- return [3 /*break*/, 3];
2928
- case 2:
2929
- selectedRows.forEach(function (row) { return (row[field] = value); });
2930
- _a.label = 3;
2931
- case 3: return [2 /*return*/, true];
2932
- }
2933
- });
2934
- }); })];
2935
- case 1: return [2 /*return*/, _a.sent()];
2936
- }
2923
+ return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2924
+ var hasChanged;
2925
+ return __generator(this, function (_a) {
2926
+ switch (_a.label) {
2927
+ case 0:
2928
+ hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
2929
+ if (!hasChanged) return [3 /*break*/, 3];
2930
+ if (!props.onSelectedItem) return [3 /*break*/, 2];
2931
+ return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
2932
+ case 1:
2933
+ _a.sent();
2934
+ return [3 /*break*/, 3];
2935
+ case 2:
2936
+ selectedRows.forEach(function (row) { return (row[field] = value); });
2937
+ _a.label = 3;
2938
+ case 3: return [2 /*return*/, true];
2939
+ }
2940
+ });
2941
+ }); })];
2937
2942
  });
2938
- }); }, [props, updatingCells]);
2943
+ }); }, [field, props, updateValue]);
2939
2944
  var selectFilterHandler = react.useCallback(function (value) { return __awaiter(void 0, void 0, void 0, function () {
2940
- var field;
2941
2945
  return __generator(this, function (_a) {
2942
- switch (_a.label) {
2943
- case 0:
2944
- field = props.field;
2945
- return [4 /*yield*/, updatingCells({ selectedRows: props.selectedRows, field: field }, function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2946
- return __generator(this, function (_a) {
2947
- switch (_a.label) {
2948
- case 0:
2949
- if (!props.onSelectFilter) return [3 /*break*/, 2];
2950
- return [4 /*yield*/, props.onSelectFilter({ selectedRows: selectedRows, value: value })];
2951
- case 1:
2952
- _a.sent();
2953
- _a.label = 2;
2954
- case 2: return [2 /*return*/, true];
2955
- }
2956
- });
2957
- }); })];
2958
- case 1: return [2 /*return*/, _a.sent()];
2959
- }
2946
+ return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2947
+ var _a;
2948
+ return __generator(this, function (_b) {
2949
+ switch (_b.label) {
2950
+ case 0:
2951
+ _a = props.onSelectFilter;
2952
+ if (!_a) return [3 /*break*/, 2];
2953
+ return [4 /*yield*/, props.onSelectFilter({ selectedRows: selectedRows, value: value })];
2954
+ case 1:
2955
+ _a = (_b.sent());
2956
+ _b.label = 2;
2957
+ case 2:
2958
+ return [2 /*return*/, true];
2959
+ }
2960
+ });
2961
+ }); })];
2960
2962
  });
2961
- }); }, [props, updatingCells]);
2963
+ }); }, [props, updateValue]);
2962
2964
  // Load up options list if it's async function
2963
2965
  react.useEffect(function () {
2964
2966
  var _a;
@@ -2972,7 +2974,7 @@ var GridFormDropDown = function (_props) {
2972
2974
  switch (_a.label) {
2973
2975
  case 0:
2974
2976
  if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
2975
- return [4 /*yield*/, optionsConf(props.selectedRows, filter)];
2977
+ return [4 /*yield*/, optionsConf(selectedRows, filter)];
2976
2978
  case 1:
2977
2979
  optionsConf = _a.sent();
2978
2980
  _a.label = 2;
@@ -3000,7 +3002,7 @@ var GridFormDropDown = function (_props) {
3000
3002
  }
3001
3003
  });
3002
3004
  }); })();
3003
- }, [filter, options, props]);
3005
+ }, [filter, options, props, selectedRows]);
3004
3006
  // Local filtering.
3005
3007
  react.useEffect(function () {
3006
3008
  if (props.filtered == "local") {
@@ -3065,11 +3067,11 @@ var GridFormDropDown = function (_props) {
3065
3067
  var _b;
3066
3068
  var ref = _a.ref;
3067
3069
  return (jsxRuntime.jsx("div", __assign({ style: { display: "flex", width: "100%" } }, { children: jsxRuntime.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); } }) })));
3068
- } })), jsxRuntime.jsx(MenuDivider, {}, "$$divider_filter")] }))), jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [options && options.length == (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length) && (jsxRuntime.jsx(MenuItem, { children: "[Empty]" }, "".concat(props.field, "-empty"))), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3070
+ } })), jsxRuntime.jsx(MenuDivider, {}, "$$divider_filter")] }))), jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [options && options.length == (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length) && jsxRuntime.jsx(MenuItem, { children: "[Empty]" }, "".concat(field, "-empty")), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3069
3071
  var _a;
3070
3072
  return item.value === MenuSeparatorString ? (jsxRuntime.jsx(MenuDivider, {}, "$$divider_".concat(index))) : item.value === MenuHeaderString ? (jsxRuntime.jsx(MenuHeader, { children: item.label }, "$$header_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxRuntime.jsx("div", { children: !item.subComponent ? (jsxRuntime.jsx(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onClick: function () {
3071
- selectItemHandler(item.value);
3072
- } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(props.field, "-").concat(index))) : (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3073
+ selectItemHandler(item.value).then();
3074
+ } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(field, "-").concat(index))) : (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3073
3075
  return item.subComponent &&
3074
3076
  item.subComponent({
3075
3077
  setValue: function (value) {
@@ -3104,9 +3106,9 @@ var GridFormDropDown = function (_props) {
3104
3106
  }
3105
3107
  return false;
3106
3108
  },
3107
- key: "".concat(props.field, "-").concat(index, "_subcomponent_inner")
3109
+ key: "".concat(field, "-").concat(index, "_subcomponent_inner")
3108
3110
  }, ref);
3109
- } }), "".concat(props.field, "-").concat(index, "_subcomponent"))) }, "menu-wrapper-".concat(index)));
3111
+ } }), "".concat(field, "-").concat(index, "_subcomponent"))) }, "menu-wrapper-".concat(index)));
3110
3112
  })] }) }))] }));
3111
3113
  };
3112
3114
 
@@ -3127,40 +3129,48 @@ var GridSubComponentContext = react.createContext({
3127
3129
  });
3128
3130
 
3129
3131
  var GridFormMultiSelect = function (props) {
3130
- var selectedRows = props.selectedRows;
3131
- var initialiseValues = react.useMemo(function () { return props.initialSelectedValues && props.initialSelectedValues(selectedRows); }, [props, selectedRows]);
3132
+ var selectedRows = react.useContext(GridPopoverContext).selectedRows;
3133
+ var initialiseValues = react.useMemo(function () {
3134
+ var r = props.initialSelectedValues && props.initialSelectedValues(selectedRows);
3135
+ // convert array of strings to object<value,null>
3136
+ return Array.isArray(r) ? lodashEs.fromPairs(r.map(function (v) { return [v, null]; })) : r;
3137
+ }, [props, selectedRows]);
3132
3138
  var subComponentIsValid = react.useRef({});
3133
- var _a = react.useState(initialiseValues && !Array.isArray(initialiseValues)
3134
- ? lodashEs.pickBy(initialiseValues, function (value) { return typeof value !== "boolean"; })
3135
- : {}), subSelectedValues = _a[0], setSubSelectedValues = _a[1];
3136
- var _b = react.useState(function () {
3137
- return initialiseValues ? (Array.isArray(initialiseValues) ? initialiseValues : Object.keys(initialiseValues)) : [];
3138
- }), selectedValues = _b[0], setSelectedValues = _b[1];
3139
- var _c = react.useState(""), filter = _c[0], setFilter = _c[1];
3140
- var _d = react.useState([]), filteredValues = _d[0], setFilteredValues = _d[1];
3139
+ var _a = react.useState(function () { return initialiseValues !== null && initialiseValues !== void 0 ? initialiseValues : {}; }), selectedValues = _a[0], setSelectedValues = _a[1];
3140
+ var _b = react.useState(""), filter = _b[0], setFilter = _b[1];
3141
+ var _c = react.useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
3141
3142
  var optionsInitialising = react.useRef(false);
3142
- var _e = react.useState(), options = _e[0], setOptions = _e[1];
3143
+ var _d = react.useState(), options = _d[0], setOptions = _d[1];
3143
3144
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3144
- var validations, notValid, selectedOptions, selectedResults;
3145
- var _a;
3146
- return __generator(this, function (_b) {
3147
- switch (_b.label) {
3145
+ var validations, notValid, menuOptionSubValueResult;
3146
+ return __generator(this, function (_a) {
3147
+ switch (_a.label) {
3148
3148
  case 0:
3149
3149
  if (!props.onSave) return [3 /*break*/, 2];
3150
- validations = lodashEs.pick(subComponentIsValid.current, selectedValues);
3150
+ if (!options) {
3151
+ console.error("options not initialised");
3152
+ return [2 /*return*/, false];
3153
+ }
3154
+ validations = lodashEs.pick(subComponentIsValid.current, Object.keys(selectedValues));
3151
3155
  notValid = Object.values(validations).some(function (v) { return !v; });
3152
3156
  if (notValid)
3153
3157
  return [2 /*return*/, false];
3154
- 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 : [];
3155
- selectedResults = selectedOptions.map(function (selectedOption) {
3156
- return (__assign(__assign({}, selectedOption), { subValue: subSelectedValues["".concat(selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value)] }));
3158
+ menuOptionSubValueResult = lodashEs.toPairs(selectedValues).map(function (_a) {
3159
+ var value = _a[0], subValue = _a[1];
3160
+ var o = __assign({}, options.find(function (o) { return o.value == value; }));
3161
+ o.subValue = subValue;
3162
+ return o;
3157
3163
  });
3158
- return [4 /*yield*/, props.onSave(selectedRows, selectedResults)];
3159
- case 1: return [2 /*return*/, _b.sent()];
3164
+ if (lodashEs.isEqual(initialiseValues, selectedValues)) {
3165
+ // No changes to save
3166
+ return [2 /*return*/, true];
3167
+ }
3168
+ return [4 /*yield*/, props.onSave(selectedRows, menuOptionSubValueResult)];
3169
+ case 1: return [2 /*return*/, _a.sent()];
3160
3170
  case 2: return [2 /*return*/, true];
3161
3171
  }
3162
3172
  });
3163
- }); }, [options, props, selectedValues, subSelectedValues]);
3173
+ }); }, [initialiseValues, options, props, selectedValues]);
3164
3174
  // Load up options list if it's async function
3165
3175
  react.useEffect(function () {
3166
3176
  var _a;
@@ -3180,7 +3190,7 @@ var GridFormMultiSelect = function (props) {
3180
3190
  _a.label = 2;
3181
3191
  case 2:
3182
3192
  optionsList = optionsConf === null || optionsConf === void 0 ? void 0 : optionsConf.map(function (item) {
3183
- if (item == null || typeof item == "string" || typeof item == "number") {
3193
+ if (item == null || typeof item === "string" || typeof item === "number") {
3184
3194
  item = { value: item, label: item };
3185
3195
  }
3186
3196
  return item;
@@ -3213,7 +3223,16 @@ var GridFormMultiSelect = function (props) {
3213
3223
  })
3214
3224
  .filter(function (r) { return r !== undefined; }));
3215
3225
  }, [props.filtered, filter, options]);
3216
- var _f = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _f.popoverWrapper, triggerSave = _f.triggerSave;
3226
+ var toggleValue = react.useCallback(function (item) {
3227
+ var _a;
3228
+ if ("".concat(item.value) in selectedValues) {
3229
+ setSelectedValues(lodashEs.omit(selectedValues, ["".concat(item.value)]));
3230
+ }
3231
+ else {
3232
+ setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = null, _a)));
3233
+ }
3234
+ }, [selectedValues]);
3235
+ var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3217
3236
  return popoverWrapper(jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormMultiSelect-container" }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [options && props.filtered && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(FocusableItem, __assign({ className: "filter-item" }, { children: function (_a) {
3218
3237
  var _b;
3219
3238
  var ref = _a.ref;
@@ -3222,29 +3241,19 @@ var GridFormMultiSelect = function (props) {
3222
3241
  var _a;
3223
3242
  return item.value === MenuSeparatorString ? (jsxRuntime.jsx(MenuDivider, {}, "$$divider_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx(MenuItem, __assign({ onClick: function (e) {
3224
3243
  e.keepOpen = true;
3225
- if (selectedValues.includes(item.value)) {
3226
- setSelectedValues(selectedValues.filter(function (value) { return value != item.value; }));
3227
- }
3228
- else {
3229
- setSelectedValues(__spreadArray(__spreadArray([], selectedValues, true), [item.value], false));
3230
- }
3244
+ toggleValue(item);
3231
3245
  }, onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () {
3232
3246
  return __generator(this, function (_a) {
3233
3247
  if (e.key === "Enter")
3234
3248
  triggerSave().then();
3235
3249
  else if (e.key === " ") {
3236
- if (selectedValues.includes(item.value)) {
3237
- setSelectedValues(selectedValues.filter(function (value) { return value != item.value; }));
3238
- }
3239
- else {
3240
- setSelectedValues(__spreadArray(__spreadArray([], selectedValues, true), [item.value], false));
3241
- }
3250
+ toggleValue(item);
3242
3251
  e.preventDefault();
3243
3252
  e.stopPropagation();
3244
3253
  }
3245
3254
  return [2 /*return*/];
3246
3255
  });
3247
- }); } }, { children: jsxRuntime.jsx(lui.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: {
3256
+ }); } }, { children: jsxRuntime.jsx(lui.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: {
3248
3257
  onClick: function (e) {
3249
3258
  e.preventDefault();
3250
3259
  e.stopPropagation();
@@ -3252,12 +3261,12 @@ var GridFormMultiSelect = function (props) {
3252
3261
  }
3253
3262
  }, onChange: function () {
3254
3263
  /*Do nothing, change handled by menuItem*/
3255
- } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3264
+ } }) })), "".concat(item.value) in selectedValues && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3256
3265
  return item.subComponent && (jsxRuntime.jsx(GridSubComponentContext.Provider, __assign({ value: {
3257
- value: subSelectedValues["".concat(item.value)],
3266
+ value: selectedValues["".concat(item.value)],
3258
3267
  setValue: function (value) {
3259
- subSelectedValues["".concat(item.value)] = value;
3260
- setSubSelectedValues(__assign({}, subSelectedValues));
3268
+ var _a;
3269
+ setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = value, _a)));
3261
3270
  },
3262
3271
  setValid: function (valid) {
3263
3272
  subComponentIsValid.current["".concat(item.value)] = valid;
@@ -3281,11 +3290,15 @@ var PopoutMenuSeparator = Object.freeze({ __isMenuSeparator__: true });
3281
3290
  * NOTE: If the popout menu doesn't appear on single click when also selecting row it's because
3282
3291
  * you need a useMemo around your columnDefs
3283
3292
  */
3284
- var GridFormPopoverMenu = function (_props) {
3285
- var props = _props;
3286
- var updatingCells = react.useContext(GridContext).updatingCells;
3293
+ var GridFormPopoverMenu = function (props) {
3294
+ var _a = react.useContext(GridPopoverContext), selectedRows = _a.selectedRows, updateValue = _a.updateValue;
3287
3295
  var optionsInitialising = react.useRef(false);
3288
- var _a = react.useState(), options = _a[0], setOptions = _a[1];
3296
+ var _b = react.useState(), options = _b[0], setOptions = _b[1];
3297
+ // Save triggers during async action processing which triggers another action(), this ref blocks that
3298
+ var actionProcessing = react.useRef(false);
3299
+ var _c = react.useState(null), subComponentSelected = _c[0], setSubComponentSelected = _c[1];
3300
+ var subComponentIsValid = react.useRef(false);
3301
+ var _d = react.useState(), subSelectedValue = _d[0], setSubSelectedValue = _d[1];
3289
3302
  // Load up options list if it's async function
3290
3303
  react.useEffect(function () {
3291
3304
  var _a;
@@ -3294,56 +3307,102 @@ var GridFormPopoverMenu = function (_props) {
3294
3307
  optionsInitialising.current = true;
3295
3308
  var optionsConf = (_a = props.options) !== null && _a !== void 0 ? _a : [];
3296
3309
  (function () { return __awaiter(void 0, void 0, void 0, function () {
3297
- var _a;
3298
- return __generator(this, function (_b) {
3299
- switch (_b.label) {
3310
+ var _a, _b;
3311
+ return __generator(this, function (_c) {
3312
+ switch (_c.label) {
3300
3313
  case 0:
3301
- if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
3302
3314
  _a = setOptions;
3303
- return [4 /*yield*/, optionsConf(props.selectedRows)];
3315
+ if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
3316
+ return [4 /*yield*/, optionsConf(selectedRows)];
3304
3317
  case 1:
3305
- _a.apply(void 0, [_b.sent()]);
3318
+ _b = _c.sent();
3306
3319
  return [3 /*break*/, 3];
3307
3320
  case 2:
3308
- setOptions(optionsConf);
3309
- _b.label = 3;
3321
+ _b = optionsConf;
3322
+ _c.label = 3;
3310
3323
  case 3:
3324
+ _a.apply(void 0, [_b]);
3311
3325
  optionsInitialising.current = false;
3312
3326
  return [2 /*return*/];
3313
3327
  }
3314
3328
  });
3315
3329
  }); })();
3316
- }, [options, props.options, props.selectedRows]);
3330
+ }, [options, props.options, selectedRows]);
3317
3331
  var actionClick = react.useCallback(function (menuOption) { return __awaiter(void 0, void 0, void 0, function () {
3318
3332
  return __generator(this, function (_a) {
3319
- switch (_a.label) {
3320
- case 0: return [4 /*yield*/, updatingCells({ selectedRows: props.selectedRows, field: props.field }, function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3321
- var _a;
3322
- return __generator(this, function (_b) {
3323
- switch (_b.label) {
3324
- case 0:
3325
- _a = menuOption.action;
3326
- if (!_a) return [3 /*break*/, 2];
3327
- return [4 /*yield*/, menuOption.action(selectedRows)];
3328
- case 1:
3329
- _a = (_b.sent());
3330
- _b.label = 2;
3331
- case 2:
3332
- return [2 /*return*/, true];
3333
- }
3334
- });
3335
- }); })];
3336
- case 1: return [2 /*return*/, _a.sent()];
3337
- }
3333
+ actionProcessing.current = true;
3334
+ return [2 /*return*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () {
3335
+ var result, _a;
3336
+ return __generator(this, function (_b) {
3337
+ switch (_b.label) {
3338
+ case 0:
3339
+ result = __assign(__assign({}, menuOption), { subValue: subSelectedValue });
3340
+ _a = menuOption.action;
3341
+ if (!_a) return [3 /*break*/, 2];
3342
+ return [4 /*yield*/, menuOption.action(selectedRows, result)];
3343
+ case 1:
3344
+ _a = (_b.sent());
3345
+ _b.label = 2;
3346
+ case 2:
3347
+ actionProcessing.current = false;
3348
+ return [2 /*return*/, true];
3349
+ }
3350
+ });
3351
+ }); })];
3338
3352
  });
3339
- }); }, [props.field, props.selectedRows, updatingCells]);
3340
- var selectedRowCount = props.selectedRows.length;
3353
+ }); }, [selectedRows, subSelectedValue, updateValue]);
3354
+ var onMenuItemClick = react.useCallback(function (e, item) {
3355
+ if (item.subComponent) {
3356
+ subComponentIsValid.current = false;
3357
+ setSubSelectedValue(null);
3358
+ setSubComponentSelected(subComponentSelected === item ? null : item);
3359
+ e.keepOpen = true;
3360
+ }
3361
+ else {
3362
+ setSubComponentSelected(null);
3363
+ actionClick(item).then();
3364
+ }
3365
+ }, [actionClick, subComponentSelected]);
3366
+ var selectedRowCount = selectedRows.length;
3341
3367
  var filteredOptions = options === null || options === void 0 ? void 0 : options.filter(function (menuOption) {
3342
3368
  return menuOption.label === PopoutMenuSeparator || selectedRowCount === 1 || menuOption.supportsMultiEdit;
3343
3369
  });
3344
- var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3370
+ var save = react.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
3371
+ return __generator(this, function (_a) {
3372
+ switch (_a.label) {
3373
+ case 0:
3374
+ if (!(!actionProcessing.current && subComponentSelected)) return [3 /*break*/, 2];
3375
+ if (!subComponentIsValid.current)
3376
+ return [2 /*return*/, false];
3377
+ return [4 /*yield*/, actionClick(subComponentSelected)];
3378
+ case 1:
3379
+ _a.sent();
3380
+ _a.label = 2;
3381
+ case 2: return [2 /*return*/, true];
3382
+ }
3383
+ });
3384
+ }); }, [actionClick, subComponentSelected]);
3385
+ var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3386
+ var localTriggerSave = function (reason) { return __awaiter(void 0, void 0, void 0, function () {
3387
+ return __generator(this, function (_a) {
3388
+ if (!subComponentIsValid.current)
3389
+ return [2 /*return*/];
3390
+ return [2 /*return*/, triggerSave(reason)];
3391
+ });
3392
+ }); };
3345
3393
  return popoverWrapper(jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: !filteredOptions, className: "GridFormPopupMenu" }, { children: jsxRuntime.jsx(jsxRuntime.Fragment, { children: options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3346
- return item.label === PopoutMenuSeparator ? (jsxRuntime.jsx(MenuDivider, {}, "$$divider_".concat(index))) : (!item.hidden && (jsxRuntime.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))));
3394
+ return item.label === PopoutMenuSeparator ? (jsxRuntime.jsx(MenuDivider, {}, "$$divider_".concat(index))) : (!item.hidden && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.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 && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3395
+ return item.subComponent && (jsxRuntime.jsx(GridSubComponentContext.Provider, __assign({ value: {
3396
+ value: subSelectedValue,
3397
+ setValue: function (value) {
3398
+ setSubSelectedValue(value);
3399
+ },
3400
+ setValid: function (valid) {
3401
+ subComponentIsValid.current = valid;
3402
+ },
3403
+ triggerSave: localTriggerSave
3404
+ } }, { children: jsxRuntime.jsx(item.subComponent, {}) })));
3405
+ } }), "".concat(item.label, "_subcomponent")))] })));
3347
3406
  }) }) })));
3348
3407
  };
3349
3408
 
@@ -3442,15 +3501,16 @@ var css_248z$2 = ".LuiTextInput{margin-bottom:0}.LuiTextInput-formatted{color:#b
3442
3501
  styleInject(css_248z$2);
3443
3502
 
3444
3503
  var TextInputFormatted = function (props) {
3445
- return (jsxRuntime.jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsxRuntime.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)), jsxRuntime.jsx("span", __assign({ className: "LuiTextInput-formatted" }, { children: props.formatted }))] })), props.error && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-error" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }), props.error] }))), props.warning && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-warning" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "warning", name: "ic_warning", className: "LuiTextInput-warning-icon", size: "sm", status: "warning" }), props.warning] })))] })));
3504
+ return (jsxRuntime.jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsxRuntime.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) {
3505
+ e.currentTarget.focus();
3506
+ } }, props.inputProps)), jsxRuntime.jsx("span", __assign({ className: "LuiTextInput-formatted" }, { children: props.formatted }))] })), props.error && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-error" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }), props.error] }))), props.warning && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-warning" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "warning", name: "ic_warning", className: "LuiTextInput-warning-icon", size: "sm", status: "warning" }), props.warning] })))] })));
3446
3507
  };
3447
3508
 
3448
- var GridFormEditBearing = function (_props) {
3449
- var _a;
3450
- var props = _props;
3451
- var _b = react.useState("".concat((_a = props.value) !== null && _a !== void 0 ? _a : "")), value = _b[0], setValue = _b[1];
3509
+ var GridFormEditBearing = function (props) {
3510
+ var _a = react.useContext(GridPopoverContext), field = _a.field, initialValue = _a.value;
3511
+ var _b = react.useState("".concat(initialValue !== null && initialValue !== void 0 ? initialValue : "")), value = _b[0], setValue = _b[1];
3452
3512
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3453
- var parsedValue, field_1;
3513
+ var parsedValue;
3454
3514
  return __generator(this, function (_a) {
3455
3515
  switch (_a.label) {
3456
3516
  case 0:
@@ -3458,25 +3518,24 @@ var GridFormEditBearing = function (_props) {
3458
3518
  return [2 /*return*/, false];
3459
3519
  parsedValue = bearingNumberParser(value);
3460
3520
  // Value didn't change so don't save just cancel
3461
- if (parsedValue === props.value) {
3521
+ if (parsedValue === initialValue) {
3462
3522
  return [2 /*return*/, true];
3463
3523
  }
3464
3524
  if (!props.onSave) return [3 /*break*/, 2];
3465
3525
  return [4 /*yield*/, props.onSave(selectedRows, parsedValue)];
3466
3526
  case 1: return [2 /*return*/, _a.sent()];
3467
3527
  case 2:
3468
- field_1 = props.field;
3469
- if (field_1 == null) {
3528
+ if (field == null) {
3470
3529
  console.error("field is not defined in ColDef");
3471
3530
  }
3472
3531
  else {
3473
- selectedRows.forEach(function (row) { return (row[field_1] = parsedValue); });
3532
+ selectedRows.forEach(function (row) { return (row[field] = parsedValue); });
3474
3533
  }
3475
3534
  _a.label = 3;
3476
3535
  case 3: return [2 /*return*/, true];
3477
3536
  }
3478
3537
  });
3479
- }); }, [props, value]);
3538
+ }); }, [field, initialValue, props, value]);
3480
3539
  var _c = useGridPopoverHook({ className: props.className, save: save }), triggerSave = _c.triggerSave, popoverWrapper = _c.popoverWrapper;
3481
3540
  return popoverWrapper(jsxRuntime.jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsxRuntime.jsx(TextInputFormatted, { value: value !== null && value !== void 0 ? value : "", onChange: function (e) {
3482
3541
  setValue(e.target.value.trim());
@@ -3529,8 +3588,8 @@ var GridPopoverEditDropDown = function (colDef, props) {
3529
3588
  className: "GridPopoverEditDropDown-containerMedium" }, props.editorParams) }));
3530
3589
  };
3531
3590
 
3532
- var GridFormMessage = function (_props) {
3533
- var props = _props;
3591
+ var GridFormMessage = function (props) {
3592
+ var selectedRows = react.useContext(GridPopoverContext).selectedRows;
3534
3593
  var _a = react.useState(null), message = _a[0], setMessage = _a[1];
3535
3594
  var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3536
3595
  react.useEffect(function () {
@@ -3540,14 +3599,14 @@ var GridFormMessage = function (_props) {
3540
3599
  switch (_b.label) {
3541
3600
  case 0:
3542
3601
  _a = setMessage;
3543
- return [4 /*yield*/, props.message(props)];
3602
+ return [4 /*yield*/, props.message(selectedRows)];
3544
3603
  case 1:
3545
3604
  _a.apply(void 0, [_b.sent()]);
3546
3605
  return [2 /*return*/];
3547
3606
  }
3548
3607
  });
3549
3608
  }); })().then();
3550
- }, [props]);
3609
+ }, [props, selectedRows]);
3551
3610
  return popoverWrapper(jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: message === null, className: clsx("GridFormMessage-container", props.className) }, { children: jsxRuntime.jsx(jsxRuntime.Fragment, { children: message }) })));
3552
3611
  };
3553
3612
 
@@ -3627,13 +3686,18 @@ var useGenerateOrDefaultId = function (idFromProps) {
3627
3686
  var TextAreaInput = function (props) {
3628
3687
  var _a, _b;
3629
3688
  var id = useGenerateOrDefaultId((_a = props.inputProps) === null || _a === void 0 ? void 0 : _a.id);
3630
- return (jsxRuntime.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: [jsxRuntime.jsxs("label", __assign({ htmlFor: id }, { children: [props.mandatory && jsxRuntime.jsx("span", __assign({ className: "LuiTextAreaInput-mandatory" }, { children: "*" })), props.label && jsxRuntime.jsx("span", __assign({ className: "LuiTextAreaInput-label" }, { children: props.label })), jsxRuntime.jsxs("div", __assign({ className: "LuiTextAreaInput-wrapper" }, { children: [" ", jsxRuntime.jsx("textarea", __assign({ id: id, value: props.value, onChange: props.onChange, rows: 5 }, props.inputProps))] }))] })), props.error && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextAreaInput-error" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextAreaInput-error-icon", size: "sm", status: "error" }), props.error] })))] })));
3689
+ return (jsxRuntime.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: [jsxRuntime.jsxs("label", __assign({ htmlFor: id }, { children: [props.mandatory && jsxRuntime.jsx("span", __assign({ className: "LuiTextAreaInput-mandatory" }, { children: "*" })), props.label && jsxRuntime.jsx("span", __assign({ className: "LuiTextAreaInput-label" }, { children: props.label })), jsxRuntime.jsxs("div", __assign({ className: "LuiTextAreaInput-wrapper" }, { children: [" ", jsxRuntime.jsx("textarea", __assign({ id: id, value: props.value, onChange: props.onChange, rows: 5 }, props.inputProps, { onMouseEnter: function (e) {
3690
+ if (document.activeElement != e.currentTarget) {
3691
+ e.currentTarget.focus();
3692
+ e.currentTarget.selectionStart = e.currentTarget.value.length;
3693
+ }
3694
+ } }))] }))] })), props.error && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextAreaInput-error" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextAreaInput-error-icon", size: "sm", status: "error" }), props.error] })))] })));
3631
3695
  };
3632
3696
 
3633
- var GridFormTextArea = function (_props) {
3634
- var _a, _b;
3635
- var props = _props;
3636
- var _c = react.useState((_a = props.value) !== null && _a !== void 0 ? _a : ""), value = _c[0], setValue = _c[1];
3697
+ var GridFormTextArea = function (props) {
3698
+ var _a;
3699
+ var _b = react.useContext(GridPopoverContext), field = _b.field, initialVale = _b.value;
3700
+ var _c = react.useState(initialVale !== null && initialVale !== void 0 ? initialVale : ""), value = _c[0], setValue = _c[1];
3637
3701
  var invalid = react.useCallback(function () {
3638
3702
  if (props.required && value.length == 0) {
3639
3703
  return "Some text is required";
@@ -3647,19 +3711,17 @@ var GridFormTextArea = function (_props) {
3647
3711
  return null;
3648
3712
  }, [props, value]);
3649
3713
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3650
- var field;
3651
3714
  return __generator(this, function (_a) {
3652
3715
  switch (_a.label) {
3653
3716
  case 0:
3654
3717
  if (invalid())
3655
3718
  return [2 /*return*/, false];
3656
- if (props.value === (value !== null && value !== void 0 ? value : ""))
3719
+ if (initialVale === (value !== null && value !== void 0 ? value : ""))
3657
3720
  return [2 /*return*/, true];
3658
3721
  if (!props.onSave) return [3 /*break*/, 2];
3659
3722
  return [4 /*yield*/, props.onSave(selectedRows, value)];
3660
3723
  case 1: return [2 /*return*/, _a.sent()];
3661
3724
  case 2:
3662
- field = props.field;
3663
3725
  if (field == null) {
3664
3726
  console.error("ColDef has no field set");
3665
3727
  return [2 /*return*/, false];
@@ -3668,18 +3730,18 @@ var GridFormTextArea = function (_props) {
3668
3730
  return [2 /*return*/, true];
3669
3731
  }
3670
3732
  });
3671
- }); }, [props, invalid, value]);
3733
+ }); }, [invalid, initialVale, value, props, field]);
3672
3734
  var popoverWrapper = useGridPopoverHook({ className: props.className, save: save }).popoverWrapper;
3673
- return popoverWrapper(jsxRuntime.jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_b = props.width) !== null && _b !== void 0 ? _b : 240 } }, { children: jsxRuntime.jsx(TextAreaInput, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), inputProps: { placeholder: props.placeholder } }) })));
3735
+ return popoverWrapper(jsxRuntime.jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 } }, { children: jsxRuntime.jsx(TextAreaInput, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), inputProps: { placeholder: props.placeholder } }) })));
3674
3736
  };
3675
3737
 
3676
3738
  var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __assign({ editor: GridFormTextArea }, params)); };
3677
3739
 
3678
- var GridFormTextInput = function (_props) {
3740
+ var GridFormTextInput = function (props) {
3679
3741
  var _a;
3680
- var props = _props;
3681
- var initValue = props.value == null ? "" : "".concat(props.value);
3682
- var _b = react.useState(initValue), value = _b[0], setValue = _b[1];
3742
+ var _b = react.useContext(GridPopoverContext), field = _b.field, data = _b.data, initialVale = _b.value;
3743
+ var initValue = initialVale == null ? "" : "".concat(initialVale);
3744
+ var _c = react.useState(initValue), value = _c[0], setValue = _c[1];
3683
3745
  var invalid = react.useCallback(function () {
3684
3746
  var trimmedValue = value.trim();
3685
3747
  if (props.required && trimmedValue.length == 0) {
@@ -3689,12 +3751,12 @@ var GridFormTextInput = function (_props) {
3689
3751
  return "Text must be no longer than ".concat(props.maxLength, " characters");
3690
3752
  }
3691
3753
  if (props.validate) {
3692
- return props.validate(trimmedValue, props.data);
3754
+ return props.validate(trimmedValue, data);
3693
3755
  }
3694
3756
  return null;
3695
- }, [props, value]);
3757
+ }, [data, props, value]);
3696
3758
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3697
- var trimmedValue, field;
3759
+ var trimmedValue;
3698
3760
  return __generator(this, function (_a) {
3699
3761
  switch (_a.label) {
3700
3762
  case 0:
@@ -3707,23 +3769,18 @@ var GridFormTextInput = function (_props) {
3707
3769
  return [4 /*yield*/, props.onSave(selectedRows, trimmedValue)];
3708
3770
  case 1: return [2 /*return*/, _a.sent()];
3709
3771
  case 2:
3710
- field = props.field;
3711
3772
  if (field == null) {
3712
3773
  console.error("ColDef has no field set");
3713
3774
  return [2 /*return*/, false];
3714
3775
  }
3776
+ // @ts-ignore row[field] row is of type any
3715
3777
  selectedRows.forEach(function (row) { return (row[field] = trimmedValue); });
3716
3778
  return [2 /*return*/, true];
3717
3779
  }
3718
3780
  });
3719
- }); }, [invalid, value, initValue, props]);
3720
- var _c = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _c.popoverWrapper, triggerSave = _c.triggerSave;
3721
- return popoverWrapper(jsxRuntime.jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 }, className: "FormTest" }, { children: jsxRuntime.jsx(TextInputFormatted, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units, onMouseEnter: function (e) {
3722
- if (document.activeElement != e.currentTarget) {
3723
- e.currentTarget.focus();
3724
- e.currentTarget.selectionStart = e.currentTarget.value.length;
3725
- }
3726
- }, inputProps: {
3781
+ }); }, [invalid, value, initValue, props, field]);
3782
+ var _d = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _d.popoverWrapper, triggerSave = _d.triggerSave;
3783
+ return popoverWrapper(jsxRuntime.jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 }, className: "FormTest" }, { children: jsxRuntime.jsx(TextInputFormatted, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units, inputProps: {
3727
3784
  style: { width: "100%" },
3728
3785
  placeholder: props.placeholder,
3729
3786
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3800,12 +3857,7 @@ var GridSubComponentTextArea = function (props) {
3800
3857
  react.useEffect(function () {
3801
3858
  setValid(value != null && validate(value) == null);
3802
3859
  }, [setValid, validate, value]);
3803
- return (jsxRuntime.jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsxRuntime.jsx(TextInputFormatted, { className: "free-text-input", value: value, onMouseEnter: function (e) {
3804
- if (document.activeElement != e.currentTarget) {
3805
- e.currentTarget.focus();
3806
- e.currentTarget.selectionStart = e.currentTarget.value.length;
3807
- }
3808
- }, onChange: function (e) { return setValue(e.target.value); }, error: validate(value), inputProps: {
3860
+ return (jsxRuntime.jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsxRuntime.jsx(TextInputFormatted, { className: "free-text-input", value: value, onChange: function (e) { return setValue(e.target.value); }, error: validate(value), inputProps: {
3809
3861
  autoFocus: true,
3810
3862
  placeholder: props.placeholder,
3811
3863
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3930,7 +3982,7 @@ exports.ActionButton = ActionButton;
3930
3982
  exports.ComponentLoadingWrapper = ComponentLoadingWrapper;
3931
3983
  exports.ControlledMenu = ControlledMenu;
3932
3984
  exports.FocusableItem = FocusableItem;
3933
- exports.GenericCellEditorComponent = GenericCellEditorComponent;
3985
+ exports.GenericCellEditorComponentWrapper = GenericCellEditorComponentWrapper;
3934
3986
  exports.GenericMultiEditCellClass = GenericMultiEditCellClass;
3935
3987
  exports.Grid = Grid;
3936
3988
  exports.GridCell = GridCell;