@linzjs/step-ag-grid 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import { KeyboardEventHandler } from "react";
2
2
  import { GridBaseRow } from "./Grid";
3
3
  export interface GridPopoverHookProps<RowType> {
4
4
  className: string | undefined;
5
+ invalid?: () => Promise<boolean | string | null> | boolean | string | null;
5
6
  save?: (selectedRows: RowType[]) => Promise<boolean>;
6
7
  }
7
8
  export declare const useGridPopoverHook: <RowType extends GridBaseRow>(props: GridPopoverHookProps<RowType>) => {
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { CellEditorCommon } from "../GridCell";
3
3
  import { TextInputValidatorProps } from "../../utils/textValidator";
4
- export interface GridSubComponentTextAreaProps extends TextInputValidatorProps, CellEditorCommon {
4
+ import { GridBaseRow } from "../Grid";
5
+ export interface GridSubComponentTextAreaProps<RowType extends GridBaseRow> extends TextInputValidatorProps<RowType>, CellEditorCommon {
5
6
  placeholder?: string;
6
7
  width?: string | number;
7
8
  defaultValue: string;
8
9
  className?: string;
9
10
  helpText?: string;
10
11
  }
11
- export declare const GridFormSubComponentTextArea: (props: GridSubComponentTextAreaProps) => JSX.Element;
12
+ export declare const GridFormSubComponentTextArea: <RowType extends GridBaseRow>(props: GridSubComponentTextAreaProps<RowType>) => JSX.Element;
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { TextInputValidatorProps } from "../../utils/textValidator";
3
3
  import { CellEditorCommon } from "../GridCell";
4
- export interface GridFormSubComponentTextInputProps extends TextInputValidatorProps, CellEditorCommon {
4
+ import { GridBaseRow } from "../Grid";
5
+ export interface GridFormSubComponentTextInputProps<RowType extends GridBaseRow> extends TextInputValidatorProps<RowType>, CellEditorCommon {
5
6
  placeholder?: string;
6
7
  width?: string | number;
7
8
  defaultValue: string;
8
9
  helpText?: string;
9
10
  }
10
- export declare const GridFormSubComponentTextInput: (props: GridFormSubComponentTextInputProps) => JSX.Element;
11
+ export declare const GridFormSubComponentTextInput: <RowType extends GridBaseRow>(props: GridFormSubComponentTextInputProps<RowType>) => JSX.Element;
@@ -2,7 +2,7 @@
2
2
  import { GridBaseRow } from "../Grid";
3
3
  import { CellEditorCommon } from "../GridCell";
4
4
  import { TextInputValidatorProps } from "../../utils/textValidator";
5
- export interface GridFormTextAreaProps<RowType extends GridBaseRow> extends TextInputValidatorProps, CellEditorCommon {
5
+ export interface GridFormTextAreaProps<RowType extends GridBaseRow> extends TextInputValidatorProps<RowType>, CellEditorCommon {
6
6
  placeholder?: string;
7
7
  width?: string | number;
8
8
  onSave?: (selectedRows: RowType[], value: string) => Promise<boolean>;
@@ -2,7 +2,7 @@
2
2
  import { GridBaseRow } from "../Grid";
3
3
  import { CellEditorCommon } from "../GridCell";
4
4
  import { TextInputValidatorProps } from "../../utils/textValidator";
5
- export interface GridFormTextInputProps<RowType extends GridBaseRow> extends TextInputValidatorProps, CellEditorCommon {
5
+ export interface GridFormTextInputProps<RowType extends GridBaseRow> extends TextInputValidatorProps<RowType>, CellEditorCommon {
6
6
  placeholder?: string;
7
7
  units?: string;
8
8
  width?: string | number;
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  export interface GridSubComponentContextType {
3
3
  value: any;
4
+ data: any;
4
5
  setValue: (value: string) => void;
5
6
  setValid: (valid: boolean) => void;
6
7
  triggerSave: () => Promise<void>;
@@ -1,6 +1,7 @@
1
- export interface TextInputValidatorProps {
1
+ import { GridBaseRow } from "../components/Grid";
2
+ export interface TextInputValidatorProps<RowType extends GridBaseRow> {
2
3
  required?: boolean;
3
4
  maxLength?: number;
4
- validate?: (value: string) => string | null;
5
+ validate?: (value: string, data: RowType) => string | null;
5
6
  }
6
- export declare const TextInputValidator: (props: TextInputValidatorProps, value: string | null) => string | null;
7
+ export declare const TextInputValidator: <RowType extends GridBaseRow>(props: TextInputValidatorProps<RowType>, value: string | null, data: RowType) => string | null;
@@ -2244,6 +2244,7 @@ var GridPopoverContextProvider = function (_a) {
2244
2244
 
2245
2245
  var GridSubComponentContext = createContext({
2246
2246
  value: "GridSubComponentContext value no context",
2247
+ data: {},
2247
2248
  setValue: function () {
2248
2249
  console.error("GridSubComponentContext setValue no context");
2249
2250
  },
@@ -2793,30 +2794,35 @@ var useGridPopoverHook = function (props) {
2793
2794
  setOpen(true);
2794
2795
  }, []);
2795
2796
  var triggerSave = useCallback(function (reason) { return __awaiter(void 0, void 0, void 0, function () {
2796
- var _a, _b;
2797
- return __generator(this, function (_c) {
2798
- switch (_c.label) {
2797
+ return __generator(this, function (_a) {
2798
+ switch (_a.label) {
2799
2799
  case 0:
2800
- _a = reason == "cancel" || !props.save;
2801
- if (_a) return [3 /*break*/, 3];
2802
- _b = updateValue;
2803
- if (!_b) return [3 /*break*/, 2];
2804
- return [4 /*yield*/, updateValue(props.save)];
2800
+ if (reason == "cancel") {
2801
+ stopEditing();
2802
+ return [2 /*return*/];
2803
+ }
2804
+ if (props.invalid && props.invalid()) {
2805
+ return [2 /*return*/];
2806
+ }
2807
+ if (!!props.save) return [3 /*break*/, 1];
2808
+ stopEditing();
2809
+ return [3 /*break*/, 3];
2805
2810
  case 1:
2806
- _b = (_c.sent());
2807
- _c.label = 2;
2808
- case 2:
2809
- _a = (_b);
2810
- _c.label = 3;
2811
- case 3:
2812
- if (_a) {
2813
- setOpen(false);
2811
+ if (!props.save) return [3 /*break*/, 3];
2812
+ // forms that don't provide an invalid fn must wait until they have saved to close
2813
+ if (props.invalid)
2814
2814
  stopEditing();
2815
+ return [4 /*yield*/, updateValue(props.save)];
2816
+ case 2:
2817
+ if (_a.sent()) {
2818
+ if (!props.invalid)
2819
+ stopEditing();
2815
2820
  }
2816
- return [2 /*return*/];
2821
+ _a.label = 3;
2822
+ case 3: return [2 /*return*/];
2817
2823
  }
2818
2824
  });
2819
- }); }, [props.save, stopEditing, updateValue]);
2825
+ }); }, [props, stopEditing, updateValue]);
2820
2826
  var onlyInputKeyboardEventHandlers = {
2821
2827
  onKeyUp: function (e) {
2822
2828
  var isTextArea = e.currentTarget.type === "textarea";
@@ -2898,7 +2904,9 @@ var useGridPopoverHook = function (props) {
2898
2904
  right: 0,
2899
2905
  backgroundColor: "rgba(64,64,64,0.1)",
2900
2906
  zIndex: 1000
2901
- } })), children, jsx("button", { ref: saveButtonRef, onClick: function () { return triggerSave().then(); }, style: { display: "none" } })] }))) }));
2907
+ } })), children, jsx("button", { ref: saveButtonRef, onClick: function () {
2908
+ triggerSave().then();
2909
+ }, style: { display: "none" } })] }))) }));
2902
2910
  }, [anchorRef, isOpen, props.className, saving, triggerSave]);
2903
2911
  return {
2904
2912
  popoverWrapper: popoverWrapper,
@@ -3015,19 +3023,22 @@ var fieldToString = function (field) {
3015
3023
  return typeof field == "symbol" ? field.toString() : "".concat(field);
3016
3024
  };
3017
3025
  var GridFormDropDown = function (props) {
3018
- var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue;
3026
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue, data = _a.data;
3019
3027
  var stopEditing = useContext(GridContext).stopEditing;
3028
+ // Save triggers during async action processing which triggers another selectItem(), this ref blocks that
3029
+ var hasSubmitted = useRef(false);
3020
3030
  var _b = useState(""), filter = _b[0], setFilter = _b[1];
3021
3031
  var _c = useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
3022
3032
  var optionsInitialising = useRef(false);
3023
3033
  var _d = useState(null), options = _d[0], setOptions = _d[1];
3024
3034
  var subComponentIsValid = useRef(false);
3025
3035
  var _e = useState(), subSelectedValue = _e[0], setSubSelectedValue = _e[1];
3026
- var _f = useState(), selectedSubComponent = _f[0], setSelectedSubComponent = _f[1];
3036
+ var _f = useState(null), selectedSubComponent = _f[0], setSelectedSubComponent = _f[1];
3027
3037
  var selectItemHandler = useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
3028
3038
  return __generator(this, function (_a) {
3029
- if (subComponentValue !== undefined && !subComponentIsValid.current)
3039
+ if (hasSubmitted.current || (subComponentValue !== undefined && !subComponentIsValid.current))
3030
3040
  return [2 /*return*/, false];
3041
+ hasSubmitted.current = true;
3031
3042
  return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3032
3043
  var hasChanged;
3033
3044
  return __generator(this, function (_a) {
@@ -3177,7 +3188,7 @@ var GridFormDropDown = function (props) {
3177
3188
  // Handler for sub-selected value
3178
3189
  if (!selectedSubComponent)
3179
3190
  return [2 /*return*/, true];
3180
- if (!subComponentIsValid.current)
3191
+ if (selectedSubComponent.subComponent && !subComponentIsValid.current)
3181
3192
  return [2 /*return*/, false];
3182
3193
  return [4 /*yield*/, selectItemHandler(selectedSubComponent.value, subSelectedValue)];
3183
3194
  case 1:
@@ -3186,20 +3197,26 @@ var GridFormDropDown = function (props) {
3186
3197
  }
3187
3198
  });
3188
3199
  }); }, [selectItemHandler, selectedSubComponent, subSelectedValue]);
3189
- var popoverWrapper = useGridPopoverHook({ className: props.className, save: save }).popoverWrapper;
3200
+ var popoverWrapper = useGridPopoverHook({
3201
+ className: props.className,
3202
+ invalid: function () { return !!(selectedSubComponent && !subComponentIsValid.current); },
3203
+ save: save
3204
+ }).popoverWrapper;
3190
3205
  return popoverWrapper(jsxs(Fragment$1, { children: [props.filtered && (jsxs("div", __assign({ className: "GridFormDropDown-filter" }, { children: [jsx(FocusableItem, __assign({ className: "filter-item" }, { children: function (_a) {
3191
3206
  var _b;
3192
3207
  var ref = _a.ref;
3193
3208
  return (jsx("div", __assign({ style: { display: "flex", width: "100%" } }, { children: jsx("input", { autoFocus: true, className: "free-text-input", style: { border: "0px" }, ref: ref, type: "text", placeholder: (_b = props.filterPlaceholder) !== null && _b !== void 0 ? _b : "Placeholder", "data-testid": "filteredMenu-free-text-input", defaultValue: filter, onChange: function (e) { return setFilter(e.target.value.toLowerCase()); }, onKeyDown: function (e) { return onFilterKeyDown(e); } }) })));
3194
3209
  } })), jsx(MenuDivider, {}, "$$divider_filter")] }))), jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxs(Fragment$1, { children: [options && options.length == (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length) && (jsx(MenuItem, { children: "[Empty]" }, "".concat(fieldToString(field), "-empty"))), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3195
3210
  var _a;
3196
- return item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : item.value === MenuHeaderString ? (jsx(MenuHeader, { children: item.label }, "$$header_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxs("div", { children: [jsx(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onClick: function (e) {
3211
+ return item.value === MenuSeparatorString ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : item.value === MenuHeaderString ? (jsx(MenuHeader, { children: item.label }, "$$header_".concat(index))) : filteredValues.includes(item.value) ? null : (jsxs("div", { children: [jsxs(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onClick: function (e) {
3197
3212
  if (item.subComponent) {
3198
3213
  if (selectedSubComponent === item) {
3214
+ // toggle selection off
3199
3215
  setSelectedSubComponent(null);
3200
3216
  subComponentIsValid.current = true;
3201
3217
  }
3202
3218
  else {
3219
+ // toggle selection on
3203
3220
  setSelectedSubComponent(item);
3204
3221
  }
3205
3222
  e.keepOpen = true;
@@ -3207,7 +3224,8 @@ var GridFormDropDown = function (props) {
3207
3224
  else {
3208
3225
  selectItemHandler(item.value).then();
3209
3226
  }
3210
- } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(fieldToString(field), "-").concat(index)), item.subComponent && selectedSubComponent === item && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) { return (jsx(GridSubComponentContext.Provider, __assign({ value: {
3227
+ } }, { children: [(_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)), item.subComponent ? "..." : ""] }), "".concat(fieldToString(field), "-").concat(index)), item.subComponent && selectedSubComponent === item && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) { return (jsx(GridSubComponentContext.Provider, __assign({ value: {
3228
+ data: data,
3211
3229
  value: subSelectedValue,
3212
3230
  setValue: function (value) {
3213
3231
  setSubSelectedValue(value);
@@ -3226,18 +3244,18 @@ var GridFormDropDown = function (props) {
3226
3244
  };
3227
3245
 
3228
3246
  var GridFormMultiSelect = function (props) {
3229
- var selectedRows = useGridPopoverContext().selectedRows;
3247
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, data = _a.data;
3230
3248
  var initialiseValues = useMemo(function () {
3231
3249
  var r = props.initialSelectedValues && props.initialSelectedValues(selectedRows);
3232
3250
  // convert array of strings to object<value,null>
3233
3251
  return Array.isArray(r) ? fromPairs(r.map(function (v) { return [v, null]; })) : r;
3234
3252
  }, [props, selectedRows]);
3235
3253
  var subComponentIsValid = useRef({});
3236
- var _a = useState(function () { return initialiseValues !== null && initialiseValues !== void 0 ? initialiseValues : {}; }), selectedValues = _a[0], setSelectedValues = _a[1];
3237
- var _b = useState(""), filter = _b[0], setFilter = _b[1];
3238
- var _c = useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
3254
+ var _b = useState(function () { return initialiseValues !== null && initialiseValues !== void 0 ? initialiseValues : {}; }), selectedValues = _b[0], setSelectedValues = _b[1];
3255
+ var _c = useState(""), filter = _c[0], setFilter = _c[1];
3256
+ var _d = useState([]), filteredValues = _d[0], setFilteredValues = _d[1];
3239
3257
  var optionsInitialising = useRef(false);
3240
- var _d = useState(), options = _d[0], setOptions = _d[1];
3258
+ var _e = useState(), options = _e[0], setOptions = _e[1];
3241
3259
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3242
3260
  var validations, notValid, menuOptionSubValueResult;
3243
3261
  return __generator(this, function (_a) {
@@ -3329,10 +3347,10 @@ var GridFormMultiSelect = function (props) {
3329
3347
  setSelectedValues(__assign(__assign({}, selectedValues), (_a = {}, _a["".concat(item.value)] = null, _a)));
3330
3348
  }
3331
3349
  }, [selectedValues]);
3332
- var _e = useGridPopoverHook({
3350
+ var _f = useGridPopoverHook({
3333
3351
  className: props.className,
3334
3352
  save: save
3335
- }), popoverWrapper = _e.popoverWrapper, lastInputKeyboardEventHandlers = _e.lastInputKeyboardEventHandlers, triggerSave = _e.triggerSave;
3353
+ }), popoverWrapper = _f.popoverWrapper, lastInputKeyboardEventHandlers = _f.lastInputKeyboardEventHandlers, triggerSave = _f.triggerSave;
3336
3354
  return popoverWrapper(jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormMultiSelect-container" }, { children: jsxs(Fragment$1, { children: [options && props.filtered && (jsxs(Fragment$1, { children: [jsx(FocusableItem, __assign({ className: "filter-item" }, { children: function (_a) {
3337
3355
  var _b;
3338
3356
  var ref = _a.ref;
@@ -3352,6 +3370,7 @@ var GridFormMultiSelect = function (props) {
3352
3370
  /*Do nothing, change handled by menuItem*/
3353
3371
  } }) })), "".concat(item.value) in selectedValues && item.subComponent && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3354
3372
  return item.subComponent && (jsx(GridSubComponentContext.Provider, __assign({ value: {
3373
+ data: data,
3355
3374
  value: selectedValues["".concat(item.value)],
3356
3375
  setValue: function (value) {
3357
3376
  var _a;
@@ -3380,7 +3399,7 @@ var PopoutMenuSeparator = Object.freeze({ __isMenuSeparator__: true });
3380
3399
  * you need a useMemo around your columnDefs
3381
3400
  */
3382
3401
  var GridFormPopoverMenu = function (props) {
3383
- var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, updateValue = _a.updateValue;
3402
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, updateValue = _a.updateValue, data = _a.data;
3384
3403
  var optionsInitialising = useRef(false);
3385
3404
  var _b = useState(), options = _b[0], setOptions = _b[1];
3386
3405
  // Save triggers during async action processing which triggers another action(), this ref blocks that
@@ -3498,6 +3517,7 @@ var GridFormPopoverMenu = function (props) {
3498
3517
  return popoverWrapper(jsx(ComponentLoadingWrapper, __assign({ loading: !filteredOptions, className: "GridFormPopupMenu" }, { children: jsx(Fragment$1, { children: options === null || options === void 0 ? void 0 : options.map(function (item, index) {
3499
3518
  return item.label === PopoutMenuSeparator ? (jsx(MenuDivider, {}, "$$divider_".concat(index))) : (!item.hidden && (jsxs(Fragment, { children: [jsx(MenuItem, __assign({ onClick: function (e) { return onMenuItemClick(e, item); }, disabled: !!item.disabled || !(filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.includes(item)), title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "" }, { children: item.label }), "".concat(item.label)), item.subComponent && subComponentSelected === item && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3500
3519
  return item.subComponent && (jsx(GridSubComponentContext.Provider, __assign({ value: {
3520
+ data: data,
3501
3521
  value: subSelectedValue,
3502
3522
  setValue: function (value) {
3503
3523
  setSubSelectedValue(value);
@@ -3522,7 +3542,7 @@ var GridPopoverMenu = function (colDef, custom) {
3522
3542
  };
3523
3543
 
3524
3544
  var bearingValueFormatter = function (params) {
3525
- var value = params.value;
3545
+ var value = typeof params.value == "string" ? parseFloat(params.value) : params.value;
3526
3546
  if (value == null) {
3527
3547
  return "-";
3528
3548
  }
@@ -3616,17 +3636,18 @@ var TextInputFormatted = function (props) {
3616
3636
 
3617
3637
  var GridFormEditBearing = function (props) {
3618
3638
  var _a = useGridPopoverContext(), field = _a.field, initialValue = _a.value;
3619
- var _b = useState("".concat(initialValue !== null && initialValue !== void 0 ? initialValue : "")), value = _b[0], setValue = _b[1];
3639
+ // This clears out any scientific precision
3640
+ var defaultValue = useMemo(function () { return (initialValue == null ? "" : parseFloat(parseFloat(initialValue).toFixed(10)).toString()); }, [initialValue]);
3641
+ var _b = useState(defaultValue), value = _b[0], setValue = _b[1];
3642
+ var invalid = useCallback(function () { return bearingStringValidator(value, props.range); }, [props.range, value]);
3620
3643
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3621
3644
  var parsedValue;
3622
3645
  return __generator(this, function (_a) {
3623
3646
  switch (_a.label) {
3624
3647
  case 0:
3625
- if (bearingStringValidator(value))
3626
- return [2 /*return*/, false];
3627
3648
  parsedValue = bearingNumberParser(value);
3628
3649
  // Value didn't change so don't save just cancel
3629
- if (parsedValue === initialValue) {
3650
+ if (parsedValue === bearingNumberParser(defaultValue)) {
3630
3651
  return [2 /*return*/, true];
3631
3652
  }
3632
3653
  if (!props.onSave) return [3 /*break*/, 2];
@@ -3645,14 +3666,15 @@ var GridFormEditBearing = function (props) {
3645
3666
  case 3: return [2 /*return*/, true];
3646
3667
  }
3647
3668
  });
3648
- }); }, [field, initialValue, props, value]);
3669
+ }); }, [defaultValue, field, props, value]);
3649
3670
  var _c = useGridPopoverHook({
3650
3671
  className: props.className,
3672
+ invalid: invalid,
3651
3673
  save: save
3652
3674
  }), popoverWrapper = _c.popoverWrapper, onlyInputKeyboardEventHandlers = _c.onlyInputKeyboardEventHandlers;
3653
- return popoverWrapper(jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsx(TextInputFormatted, __assign({ value: value !== null && value !== void 0 ? value : "", onChange: function (e) {
3675
+ return popoverWrapper(jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsx(TextInputFormatted, __assign({ value: defaultValue, onChange: function (e) {
3654
3676
  setValue(e.target.value.trim());
3655
- }, autoFocus: true, placeholder: props.placeHolder }, onlyInputKeyboardEventHandlers, { formatted: bearingStringValidator(value, props.range) ? "?" : convertDDToDMS(bearingNumberParser(value)), error: bearingStringValidator(value, props.range) })) })));
3677
+ }, autoFocus: true, placeholder: props.placeHolder }, onlyInputKeyboardEventHandlers, { formatted: bearingStringValidator(value, props.range) ? "?" : convertDDToDMS(bearingNumberParser(value)), error: bearingStringValidator(value, props.range), helpText: "Press enter or tab to save" })) })));
3656
3678
  };
3657
3679
 
3658
3680
  var GridPopoverEditBearingLike = function (colDef, props) {
@@ -3802,7 +3824,7 @@ var TextAreaInput = function (props) {
3802
3824
  } }, { children: props.helpText })))] })));
3803
3825
  };
3804
3826
 
3805
- var TextInputValidator = function (props, value) {
3827
+ var TextInputValidator = function (props, value, data) {
3806
3828
  if (value == null)
3807
3829
  return null;
3808
3830
  // This can happen because subcomponent is invoked without type safety
@@ -3816,23 +3838,21 @@ var TextInputValidator = function (props, value) {
3816
3838
  return "Text must be no longer than ".concat(props.maxLength, " characters");
3817
3839
  }
3818
3840
  if (props.validate) {
3819
- return props.validate(value);
3841
+ return props.validate(value, data);
3820
3842
  }
3821
3843
  return null;
3822
3844
  };
3823
3845
 
3824
3846
  var GridFormTextArea = function (props) {
3825
3847
  var _a, _b;
3826
- var _c = useGridPopoverContext(), field = _c.field, initialVale = _c.value;
3848
+ var _c = useGridPopoverContext(), field = _c.field, initialVale = _c.value, data = _c.data;
3827
3849
  var _d = useState(initialVale != null ? "".concat(initialVale) : ""), value = _d[0], setValue = _d[1];
3828
3850
  var helpText = (_a = props.helpText) !== null && _a !== void 0 ? _a : "Press tab to save";
3829
- var invalid = useCallback(function () { return TextInputValidator(props, value); }, [props, value]);
3851
+ var invalid = useCallback(function () { return TextInputValidator(props, value, data); }, [props, value, data]);
3830
3852
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3831
3853
  return __generator(this, function (_a) {
3832
3854
  switch (_a.label) {
3833
3855
  case 0:
3834
- if (invalid())
3835
- return [2 /*return*/, false];
3836
3856
  if (initialVale === (value !== null && value !== void 0 ? value : ""))
3837
3857
  return [2 /*return*/, true];
3838
3858
  if (!props.onSave) return [3 /*break*/, 2];
@@ -3849,8 +3869,12 @@ var GridFormTextArea = function (props) {
3849
3869
  return [2 /*return*/, true];
3850
3870
  }
3851
3871
  });
3852
- }); }, [invalid, initialVale, value, props, field]);
3853
- var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, onlyInputKeyboardEventHandlers = _e.onlyInputKeyboardEventHandlers;
3872
+ }); }, [initialVale, value, props, field]);
3873
+ var _e = useGridPopoverHook({
3874
+ className: props.className,
3875
+ invalid: invalid,
3876
+ save: save
3877
+ }), popoverWrapper = _e.popoverWrapper, onlyInputKeyboardEventHandlers = _e.onlyInputKeyboardEventHandlers;
3854
3878
  return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_b = props.width) !== null && _b !== void 0 ? _b : 240 } }, { children: jsx(TextAreaInput, __assign({ value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), placeholder: props.placeholder, helpText: helpText }, onlyInputKeyboardEventHandlers)) })));
3855
3879
  };
3856
3880
 
@@ -3858,11 +3882,12 @@ var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __
3858
3882
 
3859
3883
  var GridFormTextInput = function (props) {
3860
3884
  var _a, _b;
3861
- var _c = useGridPopoverContext(), field = _c.field, initialVale = _c.value;
3885
+ var stopEditing = useContext(GridContext).stopEditing;
3886
+ var _c = useGridPopoverContext(), field = _c.field, initialVale = _c.value, data = _c.data;
3862
3887
  var helpText = (_a = props.helpText) !== null && _a !== void 0 ? _a : "Press enter or tab to save";
3863
- var initValue = initialVale == null ? "" : "".concat(initialVale);
3888
+ var initValue = useMemo(function () { return (initialVale == null ? "" : "".concat(initialVale)); }, [initialVale]);
3864
3889
  var _d = useState(initValue), value = _d[0], setValue = _d[1];
3865
- var invalid = useCallback(function () { return TextInputValidator(props, value); }, [props, value]);
3890
+ var invalid = useCallback(function () { return TextInputValidator(props, value, data); }, [data, props, value]);
3866
3891
  var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3867
3892
  var trimmedValue;
3868
3893
  return __generator(this, function (_a) {
@@ -3870,6 +3895,7 @@ var GridFormTextInput = function (props) {
3870
3895
  case 0:
3871
3896
  if (invalid())
3872
3897
  return [2 /*return*/, false];
3898
+ stopEditing();
3873
3899
  trimmedValue = value.trim();
3874
3900
  if (initValue === trimmedValue)
3875
3901
  return [2 /*return*/, true];
@@ -3887,8 +3913,12 @@ var GridFormTextInput = function (props) {
3887
3913
  return [2 /*return*/, true];
3888
3914
  }
3889
3915
  });
3890
- }); }, [invalid, value, initValue, props, field]);
3891
- var _e = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _e.popoverWrapper, onlyInputKeyboardEventHandlers = _e.onlyInputKeyboardEventHandlers;
3916
+ }); }, [invalid, stopEditing, value, initValue, props, field]);
3917
+ var _e = useGridPopoverHook({
3918
+ className: props.className,
3919
+ invalid: invalid,
3920
+ save: save
3921
+ }), popoverWrapper = _e.popoverWrapper, onlyInputKeyboardEventHandlers = _e.onlyInputKeyboardEventHandlers;
3892
3922
  return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_b = props.width) !== null && _b !== void 0 ? _b : 240 }, className: "FormTest" }, { children: jsx(TextInputFormatted, __assign({ value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units, style: { width: "100%" }, placeholder: props.placeholder }, onlyInputKeyboardEventHandlers, { helpText: helpText })) })));
3893
3923
  };
3894
3924
 
@@ -3898,14 +3928,14 @@ var GridPopoverTextInput = function (colDef, params) {
3898
3928
 
3899
3929
  var GridFormSubComponentTextInput = function (props) {
3900
3930
  var _a;
3901
- var _b = useContext(GridSubComponentContext), value = _b.value, setValue = _b.setValue, setValid = _b.setValid, triggerSave = _b.triggerSave;
3931
+ var _b = useContext(GridSubComponentContext), value = _b.value, setValue = _b.setValue, setValid = _b.setValid, triggerSave = _b.triggerSave, data = _b.data;
3902
3932
  var helpText = (_a = props.helpText) !== null && _a !== void 0 ? _a : "Press enter or tab to save";
3903
3933
  // If is not initialised yet as it's just been created then set the default value
3904
3934
  useEffect(function () {
3905
3935
  if (value == null)
3906
3936
  setValue(props.defaultValue);
3907
3937
  }, [props.defaultValue, setValue, value]);
3908
- var invalid = useCallback(function () { return TextInputValidator(props, value); }, [props, value]);
3938
+ var invalid = useCallback(function () { return TextInputValidator(props, value, data); }, [data, props, value]);
3909
3939
  useEffect(function () {
3910
3940
  setValid(value != null && invalid() == null);
3911
3941
  }, [setValid, invalid, value]);
@@ -3932,14 +3962,14 @@ var GridFormSubComponentTextInput = function (props) {
3932
3962
 
3933
3963
  var GridFormSubComponentTextArea = function (props) {
3934
3964
  var _a;
3935
- var _b = useContext(GridSubComponentContext), value = _b.value, setValue = _b.setValue, setValid = _b.setValid, triggerSave = _b.triggerSave;
3965
+ var _b = useContext(GridSubComponentContext), value = _b.value, data = _b.data, setValue = _b.setValue, setValid = _b.setValid, triggerSave = _b.triggerSave;
3936
3966
  var helpText = (_a = props.helpText) !== null && _a !== void 0 ? _a : "Press tab to save";
3937
3967
  // If is not initialised yet as it's just been created then set the default value
3938
3968
  useEffect(function () {
3939
3969
  if (value == null)
3940
3970
  setValue(props.defaultValue);
3941
3971
  }, [props.defaultValue, setValue, value]);
3942
- var invalid = useCallback(function () { return TextInputValidator(props, value); }, [props, value]);
3972
+ var invalid = useCallback(function () { return TextInputValidator(props, value, data); }, [data, props, value]);
3943
3973
  useEffect(function () {
3944
3974
  setValid(value != null && invalid() == null);
3945
3975
  }, [setValid, invalid, value]);