@linzjs/step-ag-grid 2.5.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/index.js +361 -282
  2. package/dist/index.js.map +1 -1
  3. package/dist/src/components/GridCell.d.ts +4 -7
  4. package/dist/src/components/gridForm/GridFormDropDown.d.ts +1 -1
  5. package/dist/src/components/gridForm/GridFormEditBearing.d.ts +1 -1
  6. package/dist/src/components/gridForm/GridFormMessage.d.ts +3 -3
  7. package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +2 -2
  8. package/dist/src/components/gridForm/GridFormPopoverMenu.d.ts +8 -3
  9. package/dist/src/components/gridForm/GridFormSubComponentTextInput.d.ts +1 -1
  10. package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -1
  11. package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -1
  12. package/dist/src/contexts/GridPopoverContext.d.ts +10 -6
  13. package/dist/src/contexts/GridPopoverContextProvider.d.ts +3 -1
  14. package/dist/src/lui/TextInputFormatted.d.ts +0 -1
  15. package/dist/step-ag-grid.esm.js +362 -283
  16. package/dist/step-ag-grid.esm.js.map +1 -1
  17. package/package.json +1 -1
  18. package/src/components/GridCell.tsx +9 -33
  19. package/src/components/GridPopoverHook.tsx +4 -8
  20. package/src/components/GridSubComponentTextArea.tsx +0 -6
  21. package/src/components/gridForm/GridFormDropDown.tsx +35 -37
  22. package/src/components/gridForm/GridFormEditBearing.tsx +12 -8
  23. package/src/components/gridForm/GridFormMessage.tsx +8 -6
  24. package/src/components/gridForm/GridFormMultiSelect.tsx +56 -48
  25. package/src/components/gridForm/GridFormPopoverMenu.tsx +112 -29
  26. package/src/components/gridForm/GridFormSubComponentTextInput.tsx +2 -1
  27. package/src/components/gridForm/GridFormTextArea.tsx +11 -9
  28. package/src/components/gridForm/GridFormTextInput.tsx +13 -16
  29. package/src/contexts/GridPopoverContext.tsx +18 -9
  30. package/src/contexts/GridPopoverContextProvider.tsx +24 -27
  31. package/src/lui/TextAreaInput.tsx +13 -1
  32. package/src/lui/TextInputFormatted.tsx +3 -2
  33. package/src/react-menu3/components/MenuList.tsx +42 -10
  34. package/src/react-menu3/contexts/SettingsContext.ts +1 -1
  35. package/src/stories/grid/FormTest.tsx +17 -15
  36. package/src/stories/grid/GridPopoutEditDropDown.stories.tsx +3 -1
  37. package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +0 -1
  38. package/src/stories/grid/GridPopoutEditMultiSelect.stories.tsx +3 -3
  39. package/src/stories/grid/GridReadOnly.stories.tsx +15 -5
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,52 @@ var GridPopoverContext = react.createContext({
2627
2654
  anchorRef: { current: null },
2628
2655
  saving: false,
2629
2656
  setSaving: function () { },
2630
- setProps: function () { },
2631
- propsRef: { current: null }
2632
- });
2657
+ field: "",
2658
+ value: null,
2659
+ data: {},
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
+ }); }); }
2664
+ });
2665
+ var useGridPopoverContext = function () {
2666
+ return react.useContext(GridPopoverContext);
2667
+ };
2633
2668
 
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]);
2669
+ var GridPopoverContextProvider = function (_a) {
2670
+ var _b, _c, _d;
2671
+ var props = _a.props, children = _a.children;
2672
+ var _e = react.useContext(GridContext), getSelectedRows = _e.getSelectedRows, updatingCells = _e.updatingCells;
2673
+ var anchorRef = react.useRef(props.eGridCell);
2674
+ var _f = react.useState(false), saving = _f[0], setSaving = _f[1];
2675
+ var colDef = props.colDef;
2676
+ var cellEditorParams = colDef.cellEditorParams;
2677
+ var multiEdit = (_b = cellEditorParams === null || cellEditorParams === void 0 ? void 0 : cellEditorParams.multiEdit) !== null && _b !== void 0 ? _b : false;
2678
+ // Then item that is clicked on will always be first in the list
2679
+ var selectedRows = react.useMemo(function () { return (multiEdit ? lodashEs.sortBy(getSelectedRows(), function (row) { return row.id !== props.data.id; }) : [props.data]); }, [getSelectedRows, multiEdit, props.data]);
2680
+ var field = (_d = (_c = props.colDef) === null || _c === void 0 ? void 0 : _c.field) !== null && _d !== void 0 ? _d : "";
2681
+ var updateValue = react.useCallback(function (saveFn) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
2682
+ switch (_b.label) {
2683
+ case 0:
2684
+ _a = !saving;
2685
+ if (!_a) return [3 /*break*/, 2];
2686
+ return [4 /*yield*/, updatingCells({ selectedRows: selectedRows, field: field }, saveFn, setSaving)];
2687
+ case 1:
2688
+ _a = (_b.sent());
2689
+ _b.label = 2;
2690
+ case 2: return [2 /*return*/, _a];
2691
+ }
2692
+ }); }); }, [field, saving, selectedRows, updatingCells]);
2669
2693
  return (jsxRuntime.jsx(GridPopoverContext.Provider, __assign({ value: {
2670
2694
  anchorRef: anchorRef,
2671
2695
  saving: saving,
2672
2696
  setSaving: setSaving,
2673
- propsRef: propsRef,
2674
- setProps: setProps
2675
- } }, { children: props.children })));
2697
+ selectedRows: selectedRows,
2698
+ field: field,
2699
+ data: props.data,
2700
+ value: props.value,
2701
+ updateValue: updateValue
2702
+ } }, { children: children })));
2676
2703
  };
2677
2704
 
2678
2705
  var GridCellRenderer = function (props) {
@@ -2694,7 +2721,7 @@ var GridCell = function (props, custom) {
2694
2721
  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
2722
  cellClass: (custom === null || custom === void 0 ? void 0 : custom.multiEdit) ? GenericMultiEditCellClass : undefined,
2696
2723
  editable: (_a = props.editable) !== null && _a !== void 0 ? _a : true,
2697
- cellEditor: GenericCellEditorComponent(custom.editor)
2724
+ cellEditor: GenericCellEditorComponentWrapper(custom)
2698
2725
  })), ((custom === null || custom === void 0 ? void 0 : custom.editorParams) && {
2699
2726
  cellEditorParams: __assign(__assign({}, custom.editorParams), { multiEdit: custom.multiEdit })
2700
2727
  })), {
@@ -2709,21 +2736,10 @@ var GridCell = function (props, custom) {
2709
2736
  return JSON.stringify(params.value);
2710
2737
  } }), props), { cellRenderer: GridCellRenderer, cellRendererParams: __assign({ originalCellRenderer: props.cellRenderer }, props.cellRendererParams) });
2711
2738
  };
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 }))) }));
2739
+ var GenericCellEditorComponentWrapper = function (custom) {
2740
+ return react.forwardRef(function GenericCellEditorComponentFr(cellEditorParams, _) {
2741
+ 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
2742
  });
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
2743
  };
2728
2744
 
2729
2745
  /**
@@ -2744,7 +2760,7 @@ var ComponentLoadingWrapper = function (props) {
2744
2760
 
2745
2761
  var useGridPopoverHook = function (props) {
2746
2762
  var stopEditing = react.useContext(GridContext).stopEditing;
2747
- var _a = react.useContext(GridPopoverContext), anchorRef = _a.anchorRef, saving = _a.saving, propsRef = _a.propsRef;
2763
+ var _a = useGridPopoverContext(), anchorRef = _a.anchorRef, saving = _a.saving, updateValue = _a.updateValue;
2748
2764
  var saveButtonRef = react.useRef(null);
2749
2765
  var _b = react.useState(false), isOpen = _b[0], setOpen = _b[1];
2750
2766
  react.useEffect(function () {
@@ -2752,22 +2768,20 @@ var useGridPopoverHook = function (props) {
2752
2768
  }, []);
2753
2769
  var triggerSave = react.useCallback(function (reason) { return __awaiter(void 0, void 0, void 0, function () {
2754
2770
  var _a, _b;
2755
- var _c, _d;
2756
- return __generator(this, function (_e) {
2757
- switch (_e.label) {
2771
+ return __generator(this, function (_c) {
2772
+ switch (_c.label) {
2758
2773
  case 0:
2759
- _a = reason == "cancel" ||
2760
- !props.save;
2774
+ _a = reason == "cancel" || !props.save;
2761
2775
  if (_a) return [3 /*break*/, 3];
2762
- _b = ((_c = propsRef.current) === null || _c === void 0 ? void 0 : _c.updateValue);
2776
+ _b = updateValue;
2763
2777
  if (!_b) return [3 /*break*/, 2];
2764
- return [4 /*yield*/, ((_d = propsRef.current) === null || _d === void 0 ? void 0 : _d.updateValue(props.save))];
2778
+ return [4 /*yield*/, updateValue(props.save)];
2765
2779
  case 1:
2766
- _b = (_e.sent());
2767
- _e.label = 2;
2780
+ _b = (_c.sent());
2781
+ _c.label = 2;
2768
2782
  case 2:
2769
2783
  _a = (_b);
2770
- _e.label = 3;
2784
+ _c.label = 3;
2771
2785
  case 3:
2772
2786
  if (_a) {
2773
2787
  setOpen(false);
@@ -2776,7 +2790,7 @@ var useGridPopoverHook = function (props) {
2776
2790
  return [2 /*return*/];
2777
2791
  }
2778
2792
  });
2779
- }); }, [props, stopEditing, propsRef]);
2793
+ }); }, [props.save, stopEditing, updateValue]);
2780
2794
  var popoverWrapper = react.useCallback(function (children) {
2781
2795
  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
2796
  triggerSave(event.reason).then();
@@ -2899,66 +2913,60 @@ var MenuHeaderString = "_____MENU_HEADER_____";
2899
2913
  var MenuHeaderItem = function (title) {
2900
2914
  return { label: title, value: MenuHeaderString };
2901
2915
  };
2902
- var GridFormDropDown = function (_props) {
2903
- var props = _props;
2904
- var _a = react.useContext(GridContext), updatingCells = _a.updatingCells, stopEditing = _a.stopEditing;
2916
+ var fieldToString = function (field) {
2917
+ return typeof field == "symbol" ? field.toString() : "".concat(field);
2918
+ };
2919
+ var GridFormDropDown = function (props) {
2920
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue;
2921
+ var stopEditing = react.useContext(GridContext).stopEditing;
2905
2922
  var _b = react.useState(""), filter = _b[0], setFilter = _b[1];
2906
2923
  var _c = react.useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
2907
2924
  var optionsInitialising = react.useRef(false);
2908
2925
  var _d = react.useState(null), options = _d[0], setOptions = _d[1];
2909
2926
  var _e = react.useState([]), subComponentValues = _e[0], setSubComponentValues = _e[1];
2910
2927
  var selectItemHandler = react.useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
2911
- var field;
2912
2928
  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
- }
2929
+ return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2930
+ var hasChanged;
2931
+ return __generator(this, function (_a) {
2932
+ switch (_a.label) {
2933
+ case 0:
2934
+ hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
2935
+ if (!hasChanged) return [3 /*break*/, 3];
2936
+ if (!props.onSelectedItem) return [3 /*break*/, 2];
2937
+ return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
2938
+ case 1:
2939
+ _a.sent();
2940
+ return [3 /*break*/, 3];
2941
+ case 2:
2942
+ selectedRows.forEach(function (row) { return (row[field] = value); });
2943
+ _a.label = 3;
2944
+ case 3: return [2 /*return*/, true];
2945
+ }
2946
+ });
2947
+ }); })];
2937
2948
  });
2938
- }); }, [props, updatingCells]);
2949
+ }); }, [field, props, updateValue]);
2939
2950
  var selectFilterHandler = react.useCallback(function (value) { return __awaiter(void 0, void 0, void 0, function () {
2940
- var field;
2941
2951
  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
- }
2952
+ return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
2953
+ var _a;
2954
+ return __generator(this, function (_b) {
2955
+ switch (_b.label) {
2956
+ case 0:
2957
+ _a = props.onSelectFilter;
2958
+ if (!_a) return [3 /*break*/, 2];
2959
+ return [4 /*yield*/, props.onSelectFilter({ selectedRows: selectedRows, value: value })];
2960
+ case 1:
2961
+ _a = (_b.sent());
2962
+ _b.label = 2;
2963
+ case 2:
2964
+ return [2 /*return*/, true];
2965
+ }
2966
+ });
2967
+ }); })];
2960
2968
  });
2961
- }); }, [props, updatingCells]);
2969
+ }); }, [props, updateValue]);
2962
2970
  // Load up options list if it's async function
2963
2971
  react.useEffect(function () {
2964
2972
  var _a;
@@ -2972,7 +2980,7 @@ var GridFormDropDown = function (_props) {
2972
2980
  switch (_a.label) {
2973
2981
  case 0:
2974
2982
  if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
2975
- return [4 /*yield*/, optionsConf(props.selectedRows, filter)];
2983
+ return [4 /*yield*/, optionsConf(selectedRows, filter)];
2976
2984
  case 1:
2977
2985
  optionsConf = _a.sent();
2978
2986
  _a.label = 2;
@@ -3000,7 +3008,7 @@ var GridFormDropDown = function (_props) {
3000
3008
  }
3001
3009
  });
3002
3010
  }); })();
3003
- }, [filter, options, props]);
3011
+ }, [filter, options, props, selectedRows]);
3004
3012
  // Local filtering.
3005
3013
  react.useEffect(function () {
3006
3014
  if (props.filtered == "local") {
@@ -3065,48 +3073,43 @@ var GridFormDropDown = function (_props) {
3065
3073
  var _b;
3066
3074
  var ref = _a.ref;
3067
3075
  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) {
3076
+ } })), 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(fieldToString(field), "-empty"))), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3069
3077
  var _a;
3070
3078
  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
- return item.subComponent &&
3074
- item.subComponent({
3075
- setValue: function (value) {
3076
- var localSubComponentValues = __spreadArray([], subComponentValues, true);
3077
- var subComponentValueIndex = localSubComponentValues.findIndex(function (_a) {
3078
- var optionValue = _a.optionValue;
3079
- return optionValue === item.value;
3079
+ selectItemHandler(item.value).then();
3080
+ } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(fieldToString(field), "-").concat(index))) : (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3081
+ return item.subComponent && (jsxRuntime.jsx(item.subComponent, { setValue: function (value) {
3082
+ var localSubComponentValues = __spreadArray([], subComponentValues, true);
3083
+ var subComponentValueIndex = localSubComponentValues.findIndex(function (_a) {
3084
+ var optionValue = _a.optionValue;
3085
+ return optionValue === item.value;
3086
+ });
3087
+ if (subComponentValueIndex !== -1) {
3088
+ localSubComponentValues[subComponentValueIndex].subComponentValue = value;
3089
+ }
3090
+ else {
3091
+ localSubComponentValues.push({
3092
+ subComponentValue: value,
3093
+ optionValue: item.value
3080
3094
  });
3081
- if (subComponentValueIndex !== -1) {
3082
- localSubComponentValues[subComponentValueIndex].subComponentValue = value;
3083
- }
3084
- else {
3085
- localSubComponentValues.push({
3086
- subComponentValue: value,
3087
- optionValue: item.value
3088
- });
3089
- }
3090
- setSubComponentValues(localSubComponentValues);
3091
- },
3092
- keyDown: function (key, event) {
3093
- var subComponentItem = subComponentValues.find(function (_a) {
3094
- var optionValue = _a.optionValue;
3095
- return optionValue === item.value;
3095
+ }
3096
+ setSubComponentValues(localSubComponentValues);
3097
+ }, keyDown: function (key, event) {
3098
+ var subComponentItem = subComponentValues.find(function (_a) {
3099
+ var optionValue = _a.optionValue;
3100
+ return optionValue === item.value;
3101
+ });
3102
+ if ((key === "Enter" || key === "Tab") && subComponentItem) {
3103
+ event.preventDefault();
3104
+ event.stopPropagation();
3105
+ return selectItemHandler(item.value, subComponentItem.subComponentValue).then(function () {
3106
+ ref.closeMenu();
3107
+ return true;
3096
3108
  });
3097
- if ((key === "Enter" || key === "Tab") && subComponentItem) {
3098
- event.preventDefault();
3099
- event.stopPropagation();
3100
- return selectItemHandler(item.value, subComponentItem.subComponentValue).then(function () {
3101
- ref.closeMenu();
3102
- return true;
3103
- });
3104
- }
3105
- return false;
3106
- },
3107
- key: "".concat(props.field, "-").concat(index, "_subcomponent_inner")
3108
- }, ref);
3109
- } }), "".concat(props.field, "-").concat(index, "_subcomponent"))) }, "menu-wrapper-".concat(index)));
3109
+ }
3110
+ return false;
3111
+ } }, "".concat(fieldToString(field), "-").concat(index, "_subcomponent_inner")));
3112
+ } }), "".concat(fieldToString(field), "-").concat(index, "_subcomponent"))) }, "menu-wrapper-".concat(index)));
3110
3113
  })] }) }))] }));
3111
3114
  };
3112
3115
 
@@ -3127,40 +3130,48 @@ var GridSubComponentContext = react.createContext({
3127
3130
  });
3128
3131
 
3129
3132
  var GridFormMultiSelect = function (props) {
3130
- var selectedRows = props.selectedRows;
3131
- var initialiseValues = react.useMemo(function () { return props.initialSelectedValues && props.initialSelectedValues(selectedRows); }, [props, selectedRows]);
3133
+ var selectedRows = useGridPopoverContext().selectedRows;
3134
+ var initialiseValues = react.useMemo(function () {
3135
+ var r = props.initialSelectedValues && props.initialSelectedValues(selectedRows);
3136
+ // convert array of strings to object<value,null>
3137
+ return Array.isArray(r) ? lodashEs.fromPairs(r.map(function (v) { return [v, null]; })) : r;
3138
+ }, [props, selectedRows]);
3132
3139
  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];
3140
+ var _a = react.useState(function () { return initialiseValues !== null && initialiseValues !== void 0 ? initialiseValues : {}; }), selectedValues = _a[0], setSelectedValues = _a[1];
3141
+ var _b = react.useState(""), filter = _b[0], setFilter = _b[1];
3142
+ var _c = react.useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
3141
3143
  var optionsInitialising = react.useRef(false);
3142
- var _e = react.useState(), options = _e[0], setOptions = _e[1];
3144
+ var _d = react.useState(), options = _d[0], setOptions = _d[1];
3143
3145
  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) {
3146
+ var validations, notValid, menuOptionSubValueResult;
3147
+ return __generator(this, function (_a) {
3148
+ switch (_a.label) {
3148
3149
  case 0:
3149
3150
  if (!props.onSave) return [3 /*break*/, 2];
3150
- validations = lodashEs.pick(subComponentIsValid.current, selectedValues);
3151
+ if (!options) {
3152
+ console.error("options not initialised");
3153
+ return [2 /*return*/, false];
3154
+ }
3155
+ validations = lodashEs.pick(subComponentIsValid.current, Object.keys(selectedValues));
3151
3156
  notValid = Object.values(validations).some(function (v) { return !v; });
3152
3157
  if (notValid)
3153
3158
  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)] }));
3159
+ menuOptionSubValueResult = lodashEs.toPairs(selectedValues).map(function (_a) {
3160
+ var value = _a[0], subValue = _a[1];
3161
+ var o = __assign({}, options.find(function (o) { return o.value == value; }));
3162
+ o.subValue = subValue;
3163
+ return o;
3157
3164
  });
3158
- return [4 /*yield*/, props.onSave(selectedRows, selectedResults)];
3159
- case 1: return [2 /*return*/, _b.sent()];
3165
+ if (lodashEs.isEqual(initialiseValues, selectedValues)) {
3166
+ // No changes to save
3167
+ return [2 /*return*/, true];
3168
+ }
3169
+ return [4 /*yield*/, props.onSave(selectedRows, menuOptionSubValueResult)];
3170
+ case 1: return [2 /*return*/, _a.sent()];
3160
3171
  case 2: return [2 /*return*/, true];
3161
3172
  }
3162
3173
  });
3163
- }); }, [options, props, selectedValues, subSelectedValues]);
3174
+ }); }, [initialiseValues, options, props, selectedValues]);
3164
3175
  // Load up options list if it's async function
3165
3176
  react.useEffect(function () {
3166
3177
  var _a;
@@ -3180,7 +3191,7 @@ var GridFormMultiSelect = function (props) {
3180
3191
  _a.label = 2;
3181
3192
  case 2:
3182
3193
  optionsList = optionsConf === null || optionsConf === void 0 ? void 0 : optionsConf.map(function (item) {
3183
- if (item == null || typeof item == "string" || typeof item == "number") {
3194
+ if (item == null || typeof item === "string" || typeof item === "number") {
3184
3195
  item = { value: item, label: item };
3185
3196
  }
3186
3197
  return item;
@@ -3213,7 +3224,16 @@ var GridFormMultiSelect = function (props) {
3213
3224
  })
3214
3225
  .filter(function (r) { return r !== undefined; }));
3215
3226
  }, [props.filtered, filter, options]);
3216
- var _f = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _f.popoverWrapper, triggerSave = _f.triggerSave;
3227
+ var toggleValue = react.useCallback(function (item) {
3228
+ var _a;
3229
+ if ("".concat(item.value) in selectedValues) {
3230
+ setSelectedValues(lodashEs.omit(selectedValues, ["".concat(item.value)]));
3231
+ }
3232
+ else {
3233
+ setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = null, _a)));
3234
+ }
3235
+ }, [selectedValues]);
3236
+ var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3217
3237
  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
3238
  var _b;
3219
3239
  var ref = _a.ref;
@@ -3222,29 +3242,19 @@ var GridFormMultiSelect = function (props) {
3222
3242
  var _a;
3223
3243
  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
3244
  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
- }
3245
+ toggleValue(item);
3231
3246
  }, onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () {
3232
3247
  return __generator(this, function (_a) {
3233
3248
  if (e.key === "Enter")
3234
3249
  triggerSave().then();
3235
3250
  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
- }
3251
+ toggleValue(item);
3242
3252
  e.preventDefault();
3243
3253
  e.stopPropagation();
3244
3254
  }
3245
3255
  return [2 /*return*/];
3246
3256
  });
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: {
3257
+ }); } }, { 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
3258
  onClick: function (e) {
3249
3259
  e.preventDefault();
3250
3260
  e.stopPropagation();
@@ -3252,12 +3262,12 @@ var GridFormMultiSelect = function (props) {
3252
3262
  }
3253
3263
  }, onChange: function () {
3254
3264
  /*Do nothing, change handled by menuItem*/
3255
- } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3265
+ } }) })), "".concat(item.value) in selectedValues && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3256
3266
  return item.subComponent && (jsxRuntime.jsx(GridSubComponentContext.Provider, __assign({ value: {
3257
- value: subSelectedValues["".concat(item.value)],
3267
+ value: selectedValues["".concat(item.value)],
3258
3268
  setValue: function (value) {
3259
- subSelectedValues["".concat(item.value)] = value;
3260
- setSubSelectedValues(__assign({}, subSelectedValues));
3269
+ var _a;
3270
+ setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = value, _a)));
3261
3271
  },
3262
3272
  setValid: function (valid) {
3263
3273
  subComponentIsValid.current["".concat(item.value)] = valid;
@@ -3281,11 +3291,31 @@ var PopoutMenuSeparator = Object.freeze({ __isMenuSeparator__: true });
3281
3291
  * NOTE: If the popout menu doesn't appear on single click when also selecting row it's because
3282
3292
  * you need a useMemo around your columnDefs
3283
3293
  */
3284
- var GridFormPopoverMenu = function (_props) {
3285
- var props = _props;
3286
- var updatingCells = react.useContext(GridContext).updatingCells;
3294
+ var GridFormPopoverMenu = function (props) {
3295
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, updateValue = _a.updateValue;
3287
3296
  var optionsInitialising = react.useRef(false);
3288
- var _a = react.useState(), options = _a[0], setOptions = _a[1];
3297
+ var _b = react.useState(), options = _b[0], setOptions = _b[1];
3298
+ // Save triggers during async action processing which triggers another action(), this ref blocks that
3299
+ var actionProcessing = react.useRef(false);
3300
+ var _c = react.useState(null), subComponentSelected = _c[0], setSubComponentSelected = _c[1];
3301
+ var subComponentIsValid = react.useRef(false);
3302
+ var _d = react.useState(), subSelectedValue = _d[0], setSubSelectedValue = _d[1];
3303
+ var defaultAction = react.useCallback(function (selectedRows, menuOption) { return __awaiter(void 0, void 0, void 0, function () {
3304
+ return __generator(this, function (_a) {
3305
+ switch (_a.label) {
3306
+ case 0:
3307
+ if (!props.defaultAction) return [3 /*break*/, 2];
3308
+ return [4 /*yield*/, props.defaultAction(selectedRows, menuOption)];
3309
+ case 1:
3310
+ _a.sent();
3311
+ return [3 /*break*/, 3];
3312
+ case 2:
3313
+ console.error("No action specified for ".concat(menuOption.label, " menu options"));
3314
+ _a.label = 3;
3315
+ case 3: return [2 /*return*/];
3316
+ }
3317
+ });
3318
+ }); }, [props]);
3289
3319
  // Load up options list if it's async function
3290
3320
  react.useEffect(function () {
3291
3321
  var _a;
@@ -3294,56 +3324,107 @@ var GridFormPopoverMenu = function (_props) {
3294
3324
  optionsInitialising.current = true;
3295
3325
  var optionsConf = (_a = props.options) !== null && _a !== void 0 ? _a : [];
3296
3326
  (function () { return __awaiter(void 0, void 0, void 0, function () {
3297
- var _a;
3327
+ var newOptions, _a, anyOptionsAreMissingAction;
3298
3328
  return __generator(this, function (_b) {
3299
3329
  switch (_b.label) {
3300
3330
  case 0:
3301
3331
  if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
3302
- _a = setOptions;
3303
- return [4 /*yield*/, optionsConf(props.selectedRows)];
3332
+ return [4 /*yield*/, optionsConf(selectedRows)];
3304
3333
  case 1:
3305
- _a.apply(void 0, [_b.sent()]);
3334
+ _a = _b.sent();
3306
3335
  return [3 /*break*/, 3];
3307
3336
  case 2:
3308
- setOptions(optionsConf);
3337
+ _a = optionsConf;
3309
3338
  _b.label = 3;
3310
3339
  case 3:
3340
+ newOptions = _a;
3341
+ setOptions(newOptions);
3342
+ if (!props.defaultAction) {
3343
+ anyOptionsAreMissingAction = newOptions.some(function (option) { return !option.action; });
3344
+ if (anyOptionsAreMissingAction) {
3345
+ console.error("There's no default action handler and some Menu options are missing an action handler", {
3346
+ invalidMenuOptions: newOptions.filter(function (option) { return !option.action; })
3347
+ });
3348
+ }
3349
+ }
3311
3350
  optionsInitialising.current = false;
3312
3351
  return [2 /*return*/];
3313
3352
  }
3314
3353
  });
3315
3354
  }); })();
3316
- }, [options, props.options, props.selectedRows]);
3355
+ }, [options, props.defaultAction, props.options, selectedRows]);
3317
3356
  var actionClick = react.useCallback(function (menuOption) { return __awaiter(void 0, void 0, void 0, function () {
3318
3357
  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
- }
3358
+ actionProcessing.current = true;
3359
+ return [2 /*return*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () {
3360
+ var result;
3361
+ var _a;
3362
+ return __generator(this, function (_b) {
3363
+ switch (_b.label) {
3364
+ case 0:
3365
+ result = __assign(__assign({}, menuOption), { subValue: subSelectedValue });
3366
+ return [4 /*yield*/, ((_a = menuOption.action) !== null && _a !== void 0 ? _a : defaultAction)(selectedRows, result)];
3367
+ case 1:
3368
+ _b.sent();
3369
+ actionProcessing.current = false;
3370
+ return [2 /*return*/, true];
3371
+ }
3372
+ });
3373
+ }); })];
3338
3374
  });
3339
- }); }, [props.field, props.selectedRows, updatingCells]);
3340
- var selectedRowCount = props.selectedRows.length;
3375
+ }); }, [defaultAction, selectedRows, subSelectedValue, updateValue]);
3376
+ var onMenuItemClick = react.useCallback(function (e, item) {
3377
+ if (item.subComponent) {
3378
+ subComponentIsValid.current = false;
3379
+ setSubSelectedValue(null);
3380
+ setSubComponentSelected(subComponentSelected === item ? null : item);
3381
+ e.keepOpen = true;
3382
+ }
3383
+ else {
3384
+ setSubComponentSelected(null);
3385
+ actionClick(item).then();
3386
+ }
3387
+ }, [actionClick, subComponentSelected]);
3388
+ var selectedRowCount = selectedRows.length;
3341
3389
  var filteredOptions = options === null || options === void 0 ? void 0 : options.filter(function (menuOption) {
3342
3390
  return menuOption.label === PopoutMenuSeparator || selectedRowCount === 1 || menuOption.supportsMultiEdit;
3343
3391
  });
3344
- var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3392
+ var save = react.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
3393
+ return __generator(this, function (_a) {
3394
+ switch (_a.label) {
3395
+ case 0:
3396
+ if (!(!actionProcessing.current && subComponentSelected)) return [3 /*break*/, 2];
3397
+ if (!subComponentIsValid.current)
3398
+ return [2 /*return*/, false];
3399
+ return [4 /*yield*/, actionClick(subComponentSelected)];
3400
+ case 1:
3401
+ _a.sent();
3402
+ _a.label = 2;
3403
+ case 2: return [2 /*return*/, true];
3404
+ }
3405
+ });
3406
+ }); }, [actionClick, subComponentSelected]);
3407
+ var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, triggerSave = _e.triggerSave;
3408
+ var localTriggerSave = function (reason) { return __awaiter(void 0, void 0, void 0, function () {
3409
+ return __generator(this, function (_a) {
3410
+ if (!subComponentIsValid.current)
3411
+ return [2 /*return*/];
3412
+ return [2 /*return*/, triggerSave(reason)];
3413
+ });
3414
+ }); };
3345
3415
  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))));
3416
+ 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 (_) {
3417
+ return item.subComponent && (jsxRuntime.jsx(GridSubComponentContext.Provider, __assign({ value: {
3418
+ value: subSelectedValue,
3419
+ setValue: function (value) {
3420
+ setSubSelectedValue(value);
3421
+ },
3422
+ setValid: function (valid) {
3423
+ subComponentIsValid.current = valid;
3424
+ },
3425
+ triggerSave: localTriggerSave
3426
+ } }, { children: jsxRuntime.jsx(item.subComponent, {}) })));
3427
+ } }), "".concat(item.label, "_subcomponent")))] })));
3347
3428
  }) }) })));
3348
3429
  };
3349
3430
 
@@ -3442,15 +3523,16 @@ var css_248z$2 = ".LuiTextInput{margin-bottom:0}.LuiTextInput-formatted{color:#b
3442
3523
  styleInject(css_248z$2);
3443
3524
 
3444
3525
  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] })))] })));
3526
+ 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) {
3527
+ e.currentTarget.focus();
3528
+ } }, 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
3529
  };
3447
3530
 
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];
3531
+ var GridFormEditBearing = function (props) {
3532
+ var _a = useGridPopoverContext(), field = _a.field, initialValue = _a.value;
3533
+ var _b = react.useState("".concat(initialValue !== null && initialValue !== void 0 ? initialValue : "")), value = _b[0], setValue = _b[1];
3452
3534
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3453
- var parsedValue, field_1;
3535
+ var parsedValue;
3454
3536
  return __generator(this, function (_a) {
3455
3537
  switch (_a.label) {
3456
3538
  case 0:
@@ -3458,25 +3540,26 @@ var GridFormEditBearing = function (_props) {
3458
3540
  return [2 /*return*/, false];
3459
3541
  parsedValue = bearingNumberParser(value);
3460
3542
  // Value didn't change so don't save just cancel
3461
- if (parsedValue === props.value) {
3543
+ if (parsedValue === initialValue) {
3462
3544
  return [2 /*return*/, true];
3463
3545
  }
3464
3546
  if (!props.onSave) return [3 /*break*/, 2];
3465
3547
  return [4 /*yield*/, props.onSave(selectedRows, parsedValue)];
3466
3548
  case 1: return [2 /*return*/, _a.sent()];
3467
3549
  case 2:
3468
- field_1 = props.field;
3469
- if (field_1 == null) {
3550
+ if (field == null) {
3470
3551
  console.error("field is not defined in ColDef");
3471
3552
  }
3472
3553
  else {
3473
- selectedRows.forEach(function (row) { return (row[field_1] = parsedValue); });
3554
+ selectedRows.forEach(function (row) {
3555
+ row[field] = parsedValue;
3556
+ });
3474
3557
  }
3475
3558
  _a.label = 3;
3476
3559
  case 3: return [2 /*return*/, true];
3477
3560
  }
3478
3561
  });
3479
- }); }, [props, value]);
3562
+ }); }, [field, initialValue, props, value]);
3480
3563
  var _c = useGridPopoverHook({ className: props.className, save: save }), triggerSave = _c.triggerSave, popoverWrapper = _c.popoverWrapper;
3481
3564
  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
3565
  setValue(e.target.value.trim());
@@ -3529,8 +3612,8 @@ var GridPopoverEditDropDown = function (colDef, props) {
3529
3612
  className: "GridPopoverEditDropDown-containerMedium" }, props.editorParams) }));
3530
3613
  };
3531
3614
 
3532
- var GridFormMessage = function (_props) {
3533
- var props = _props;
3615
+ var GridFormMessage = function (props) {
3616
+ var selectedRows = useGridPopoverContext().selectedRows;
3534
3617
  var _a = react.useState(null), message = _a[0], setMessage = _a[1];
3535
3618
  var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3536
3619
  react.useEffect(function () {
@@ -3540,14 +3623,14 @@ var GridFormMessage = function (_props) {
3540
3623
  switch (_b.label) {
3541
3624
  case 0:
3542
3625
  _a = setMessage;
3543
- return [4 /*yield*/, props.message(props)];
3626
+ return [4 /*yield*/, props.message(selectedRows)];
3544
3627
  case 1:
3545
3628
  _a.apply(void 0, [_b.sent()]);
3546
3629
  return [2 /*return*/];
3547
3630
  }
3548
3631
  });
3549
3632
  }); })().then();
3550
- }, [props]);
3633
+ }, [props, selectedRows]);
3551
3634
  return popoverWrapper(jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: message === null, className: clsx("GridFormMessage-container", props.className) }, { children: jsxRuntime.jsx(jsxRuntime.Fragment, { children: message }) })));
3552
3635
  };
3553
3636
 
@@ -3627,13 +3710,18 @@ var useGenerateOrDefaultId = function (idFromProps) {
3627
3710
  var TextAreaInput = function (props) {
3628
3711
  var _a, _b;
3629
3712
  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] })))] })));
3713
+ 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) {
3714
+ if (document.activeElement != e.currentTarget) {
3715
+ e.currentTarget.focus();
3716
+ e.currentTarget.selectionStart = e.currentTarget.value.length;
3717
+ }
3718
+ } }))] }))] })), 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
3719
  };
3632
3720
 
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];
3721
+ var GridFormTextArea = function (props) {
3722
+ var _a;
3723
+ var _b = useGridPopoverContext(), field = _b.field, initialVale = _b.value;
3724
+ var _c = react.useState(initialVale != null ? "".concat(initialVale) : ""), value = _c[0], setValue = _c[1];
3637
3725
  var invalid = react.useCallback(function () {
3638
3726
  if (props.required && value.length == 0) {
3639
3727
  return "Some text is required";
@@ -3647,39 +3735,39 @@ var GridFormTextArea = function (_props) {
3647
3735
  return null;
3648
3736
  }, [props, value]);
3649
3737
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3650
- var field;
3651
3738
  return __generator(this, function (_a) {
3652
3739
  switch (_a.label) {
3653
3740
  case 0:
3654
3741
  if (invalid())
3655
3742
  return [2 /*return*/, false];
3656
- if (props.value === (value !== null && value !== void 0 ? value : ""))
3743
+ if (initialVale === (value !== null && value !== void 0 ? value : ""))
3657
3744
  return [2 /*return*/, true];
3658
3745
  if (!props.onSave) return [3 /*break*/, 2];
3659
3746
  return [4 /*yield*/, props.onSave(selectedRows, value)];
3660
3747
  case 1: return [2 /*return*/, _a.sent()];
3661
3748
  case 2:
3662
- field = props.field;
3663
3749
  if (field == null) {
3664
3750
  console.error("ColDef has no field set");
3665
3751
  return [2 /*return*/, false];
3666
3752
  }
3667
- selectedRows.forEach(function (row) { return (row[field] = value); });
3753
+ selectedRows.forEach(function (row) {
3754
+ row[field] = value;
3755
+ });
3668
3756
  return [2 /*return*/, true];
3669
3757
  }
3670
3758
  });
3671
- }); }, [props, invalid, value]);
3759
+ }); }, [invalid, initialVale, value, props, field]);
3672
3760
  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 } }) })));
3761
+ 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
3762
  };
3675
3763
 
3676
3764
  var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __assign({ editor: GridFormTextArea }, params)); };
3677
3765
 
3678
- var GridFormTextInput = function (_props) {
3766
+ var GridFormTextInput = function (props) {
3679
3767
  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];
3768
+ var _b = useGridPopoverContext(), field = _b.field, data = _b.data, initialVale = _b.value;
3769
+ var initValue = initialVale == null ? "" : "".concat(initialVale);
3770
+ var _c = react.useState(initValue), value = _c[0], setValue = _c[1];
3683
3771
  var invalid = react.useCallback(function () {
3684
3772
  var trimmedValue = value.trim();
3685
3773
  if (props.required && trimmedValue.length == 0) {
@@ -3689,12 +3777,12 @@ var GridFormTextInput = function (_props) {
3689
3777
  return "Text must be no longer than ".concat(props.maxLength, " characters");
3690
3778
  }
3691
3779
  if (props.validate) {
3692
- return props.validate(trimmedValue, props.data);
3780
+ return props.validate(trimmedValue, data);
3693
3781
  }
3694
3782
  return null;
3695
- }, [props, value]);
3783
+ }, [data, props, value]);
3696
3784
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3697
- var trimmedValue, field;
3785
+ var trimmedValue;
3698
3786
  return __generator(this, function (_a) {
3699
3787
  switch (_a.label) {
3700
3788
  case 0:
@@ -3707,23 +3795,19 @@ var GridFormTextInput = function (_props) {
3707
3795
  return [4 /*yield*/, props.onSave(selectedRows, trimmedValue)];
3708
3796
  case 1: return [2 /*return*/, _a.sent()];
3709
3797
  case 2:
3710
- field = props.field;
3711
3798
  if (field == null) {
3712
3799
  console.error("ColDef has no field set");
3713
3800
  return [2 /*return*/, false];
3714
3801
  }
3715
- selectedRows.forEach(function (row) { return (row[field] = trimmedValue); });
3802
+ selectedRows.forEach(function (row) {
3803
+ row[field] = trimmedValue;
3804
+ });
3716
3805
  return [2 /*return*/, true];
3717
3806
  }
3718
3807
  });
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: {
3808
+ }); }, [invalid, value, initValue, props, field]);
3809
+ var _d = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _d.popoverWrapper, triggerSave = _d.triggerSave;
3810
+ 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
3811
  style: { width: "100%" },
3728
3812
  placeholder: props.placeholder,
3729
3813
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3800,12 +3884,7 @@ var GridSubComponentTextArea = function (props) {
3800
3884
  react.useEffect(function () {
3801
3885
  setValid(value != null && validate(value) == null);
3802
3886
  }, [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: {
3887
+ 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
3888
  autoFocus: true,
3810
3889
  placeholder: props.placeholder,
3811
3890
  onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
@@ -3930,7 +4009,7 @@ exports.ActionButton = ActionButton;
3930
4009
  exports.ComponentLoadingWrapper = ComponentLoadingWrapper;
3931
4010
  exports.ControlledMenu = ControlledMenu;
3932
4011
  exports.FocusableItem = FocusableItem;
3933
- exports.GenericCellEditorComponent = GenericCellEditorComponent;
4012
+ exports.GenericCellEditorComponentWrapper = GenericCellEditorComponentWrapper;
3934
4013
  exports.GenericMultiEditCellClass = GenericMultiEditCellClass;
3935
4014
  exports.Grid = Grid;
3936
4015
  exports.GridCell = GridCell;