@linzjs/step-ag-grid 5.0.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1347,8 +1347,10 @@ var ControlledMenuFr = function (_a, externalRef) {
1347
1347
  // the cell doesn't refresh during update if save is invoked from a native event
1348
1348
  // This doesn't happen in React18
1349
1349
  // To work around it, I invoke the save by clicking on a passed in invisible button ref
1350
- if (saveButtonRef === null || saveButtonRef === void 0 ? void 0 : saveButtonRef.current)
1350
+ if (saveButtonRef === null || saveButtonRef === void 0 ? void 0 : saveButtonRef.current) {
1351
+ saveButtonRef.current.setAttribute("data-reason", CloseReason.BLUR);
1351
1352
  saveButtonRef.current.click();
1353
+ }
1352
1354
  else
1353
1355
  safeCall(onClose, { reason: CloseReason.BLUR });
1354
1356
  // If a user clicks on the menu button when a menu is open, we need to close the menu.
@@ -1481,8 +1483,8 @@ var ControlledMenuFr = function (_a, externalRef) {
1481
1483
  thisDocument_1.addEventListener("click", handleScreenEventForCancel, true);
1482
1484
  thisDocument_1.addEventListener("dblclick", handleScreenEventForCancel, true);
1483
1485
  return function () {
1484
- thisDocument_1.addEventListener("keydown", handleKeydownTabAndEnter, true);
1485
- thisDocument_1.addEventListener("keyup", handleKeyupTabAndEnter, true);
1486
+ thisDocument_1.removeEventListener("keydown", handleKeydownTabAndEnter, true);
1487
+ thisDocument_1.removeEventListener("keyup", handleKeyupTabAndEnter, true);
1486
1488
  thisDocument_1.removeEventListener("mousedown", handleScreenEventForSave, true);
1487
1489
  thisDocument_1.removeEventListener("mouseup", handleScreenEventForCancel, true);
1488
1490
  thisDocument_1.removeEventListener("click", handleScreenEventForCancel, true);
@@ -1517,7 +1519,12 @@ var ControlledMenuFr = function (_a, externalRef) {
1517
1519
  safeCall(onClose, {
1518
1520
  value: event.value,
1519
1521
  key: event.key,
1520
- reason: CloseReason.CLICK
1522
+ shiftKey: event.shiftKey,
1523
+ reason: event.key === "Tab"
1524
+ ? event.shiftKey
1525
+ ? CloseReason.TAB_BACKWARD
1526
+ : CloseReason.TAB_FORWARD
1527
+ : CloseReason.CLICK
1521
1528
  });
1522
1529
  }
1523
1530
  },
@@ -1986,9 +1993,6 @@ var GridContext = react.createContext({
1986
1993
  }); },
1987
1994
  redrawRows: function () {
1988
1995
  console.error("no context provider for redrawRows");
1989
- },
1990
- selectNextCell: function () {
1991
- console.error("no context provider for selectNextCell");
1992
1996
  }
1993
1997
  });
1994
1998
 
@@ -2208,17 +2212,18 @@ var GridContextProvider = function (props) {
2208
2212
  });
2209
2213
  };
2210
2214
  var stopEditing = function () { return gridApiOp(function (gridApi) { return gridApi.stopEditing(); }); };
2211
- var updatingCells = function (props, fnUpdate, setSaving) { return __awaiter(void 0, void 0, void 0, function () {
2215
+ var updatingCells = function (props, fnUpdate, setSaving, tabDirection) { return __awaiter(void 0, void 0, void 0, function () {
2212
2216
  return __generator(this, function (_a) {
2213
2217
  switch (_a.label) {
2214
2218
  case 0:
2215
2219
  setSaving && setSaving(true);
2216
2220
  return [4 /*yield*/, gridApiOp(function (gridApi) { return __awaiter(void 0, void 0, void 0, function () {
2217
- var selectedRows, ok, cell;
2221
+ var preOpCell, selectedRows, ok, cell, postOpCell;
2218
2222
  var _a;
2219
2223
  return __generator(this, function (_b) {
2220
2224
  switch (_b.label) {
2221
2225
  case 0:
2226
+ preOpCell = gridApi.getFocusedCell();
2222
2227
  selectedRows = props.selectedRows;
2223
2228
  ok = false;
2224
2229
  return [4 /*yield*/, modifyUpdating((_a = props.field) !== null && _a !== void 0 ? _a : "", selectedRows.map(function (data) { return data.id; }), function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -2250,6 +2255,14 @@ var GridContextProvider = function (props) {
2250
2255
  // Don't set saving if ok as the form has already closed
2251
2256
  setSaving && setSaving(false);
2252
2257
  }
2258
+ postOpCell = gridApi.getFocusedCell();
2259
+ if (tabDirection &&
2260
+ preOpCell &&
2261
+ postOpCell &&
2262
+ preOpCell.rowIndex == postOpCell.rowIndex &&
2263
+ preOpCell.column.getColId() == postOpCell.column.getColId()) {
2264
+ selectNextCell(tabDirection);
2265
+ }
2253
2266
  return [2 /*return*/, ok];
2254
2267
  }
2255
2268
  });
@@ -2290,8 +2303,7 @@ var GridContextProvider = function (props) {
2290
2303
  sizeColumnsToFit: sizeColumnsToFit,
2291
2304
  stopEditing: stopEditing,
2292
2305
  updatingCells: updatingCells,
2293
- redrawRows: redrawRows,
2294
- selectNextCell: selectNextCell
2306
+ redrawRows: redrawRows
2295
2307
  } }, { children: props.children })));
2296
2308
  };
2297
2309
 
@@ -2356,8 +2368,9 @@ var useGridPopoverContext = function () {
2356
2368
  var GridPopoverContextProvider = function (_a) {
2357
2369
  var _b, _c, _d;
2358
2370
  var props = _a.props, children = _a.children;
2359
- var _e = react.useContext(GridContext), getSelectedRows = _e.getSelectedRows, updatingCells = _e.updatingCells, stopEditing = _e.stopEditing, selectNextCell = _e.selectNextCell;
2371
+ var _e = react.useContext(GridContext), getSelectedRows = _e.getSelectedRows, updatingCells = _e.updatingCells;
2360
2372
  var anchorRef = react.useRef(props.eGridCell);
2373
+ var hasSaved = react.useRef(false);
2361
2374
  var _f = react.useState(false), saving = _f[0], setSaving = _f[1];
2362
2375
  var colDef = props.colDef;
2363
2376
  var cellEditorParams = colDef.cellEditorParams;
@@ -2366,24 +2379,27 @@ var GridPopoverContextProvider = function (_a) {
2366
2379
  var selectedRows = react.useMemo(function () { return (multiEdit ? lodashEs.sortBy(getSelectedRows(), function (row) { return row.id !== props.data.id; }) : [props.data]); }, [getSelectedRows, multiEdit, props.data]);
2367
2380
  var field = (_d = (_c = props.colDef) === null || _c === void 0 ? void 0 : _c.field) !== null && _d !== void 0 ? _d : "";
2368
2381
  var updateValue = react.useCallback(function (saveFn, tabDirection) { return __awaiter(void 0, void 0, void 0, function () {
2369
- var result;
2370
- return __generator(this, function (_a) {
2371
- switch (_a.label) {
2382
+ var r, _a;
2383
+ return __generator(this, function (_b) {
2384
+ switch (_b.label) {
2372
2385
  case 0:
2373
- result = false;
2374
- if (!!saving) return [3 /*break*/, 2];
2375
- return [4 /*yield*/, updatingCells({ selectedRows: selectedRows, field: field }, saveFn, setSaving)];
2376
- case 1:
2377
- result = _a.sent();
2378
- if (result) {
2379
- stopEditing();
2380
- tabDirection && selectNextCell(tabDirection);
2381
- }
2382
- _a.label = 2;
2383
- case 2: return [2 /*return*/, result];
2386
+ if (hasSaved.current)
2387
+ return [2 /*return*/, true];
2388
+ hasSaved.current = true;
2389
+ if (!saving) return [3 /*break*/, 1];
2390
+ _a = false;
2391
+ return [3 /*break*/, 3];
2392
+ case 1: return [4 /*yield*/, updatingCells({ selectedRows: selectedRows, field: field }, saveFn, setSaving, tabDirection)];
2393
+ case 2:
2394
+ _a = _b.sent();
2395
+ _b.label = 3;
2396
+ case 3:
2397
+ r = _a;
2398
+ //if (r) stopEditing();
2399
+ return [2 /*return*/, r];
2384
2400
  }
2385
2401
  });
2386
- }); }, [field, saving, selectNextCell, selectedRows, stopEditing, updatingCells]);
2402
+ }); }, [field, saving, selectedRows, updatingCells]);
2387
2403
  return (jsxRuntime.jsx(GridPopoverContext.Provider, __assign({ value: {
2388
2404
  anchorRef: anchorRef,
2389
2405
  saving: saving,
@@ -2915,7 +2931,7 @@ var useGridPopoverHook = function (props) {
2915
2931
  return __generator(this, function (_a) {
2916
2932
  switch (_a.label) {
2917
2933
  case 0:
2918
- if (reason == "cancel") {
2934
+ if (reason == CloseReason.CANCEL) {
2919
2935
  stopEditing();
2920
2936
  return [2 /*return*/];
2921
2937
  }
@@ -2944,7 +2960,7 @@ var useGridPopoverHook = function (props) {
2944
2960
  var popoverWrapper = react.useCallback(function (children) {
2945
2961
  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) {
2946
2962
  // Prevent menu from closing when modals are invoked
2947
- if (event.reason === "blur")
2963
+ if (event.reason === CloseReason.BLUR)
2948
2964
  return;
2949
2965
  triggerSave(event.reason).then();
2950
2966
  }, viewScroll: "auto", dontShrinkIfDirectionIsTop: true, className: props.className, closeMenuExclusionClassName: "ReactModal__Content" }, { children: [saving && ( // This is the overlay that prevents editing when the editor is saving
@@ -3075,7 +3091,6 @@ var fieldToString = function (field) {
3075
3091
  var GridFormDropDown = function (props) {
3076
3092
  var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue, data = _a.data;
3077
3093
  // Save triggers during async action processing which triggers another selectItem(), this ref blocks that
3078
- var hasSubmitted = react.useRef(false);
3079
3094
  var _b = react.useState(""), filter = _b[0], setFilter = _b[1];
3080
3095
  var _c = react.useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
3081
3096
  var optionsInitialising = react.useRef(false);
@@ -3083,32 +3098,39 @@ var GridFormDropDown = function (props) {
3083
3098
  var subComponentIsValid = react.useRef(false);
3084
3099
  var _e = react.useState(), subSelectedValue = _e[0], setSubSelectedValue = _e[1];
3085
3100
  var _f = react.useState(null), selectedSubComponent = _f[0], setSelectedSubComponent = _f[1];
3086
- var selectItemHandler = react.useCallback(function (value, subComponentValue, reason) { return __awaiter(void 0, void 0, void 0, function () {
3101
+ var selectItemHandler = react.useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
3102
+ var hasChanged;
3087
3103
  return __generator(this, function (_a) {
3088
- if (hasSubmitted.current || (subComponentValue !== undefined && !subComponentIsValid.current))
3104
+ switch (_a.label) {
3105
+ case 0:
3106
+ hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
3107
+ if (!hasChanged) return [3 /*break*/, 3];
3108
+ if (!props.onSelectedItem) return [3 /*break*/, 2];
3109
+ return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
3110
+ case 1:
3111
+ _a.sent();
3112
+ return [3 /*break*/, 3];
3113
+ case 2:
3114
+ selectedRows.forEach(function (row) { return (row[field] = value); });
3115
+ _a.label = 3;
3116
+ case 3: return [2 /*return*/, true];
3117
+ }
3118
+ });
3119
+ }); }, [field, props, selectedRows]);
3120
+ var clickItemHandler = react.useCallback(function (value, subComponentValue, reason) { return __awaiter(void 0, void 0, void 0, function () {
3121
+ return __generator(this, function (_a) {
3122
+ if (subComponentValue !== undefined && !subComponentIsValid.current)
3089
3123
  return [2 /*return*/, false];
3090
- hasSubmitted.current = true;
3091
- return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3092
- var hasChanged;
3124
+ return [2 /*return*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () {
3093
3125
  return __generator(this, function (_a) {
3094
3126
  switch (_a.label) {
3095
- case 0:
3096
- hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
3097
- if (!hasChanged) return [3 /*break*/, 3];
3098
- if (!props.onSelectedItem) return [3 /*break*/, 2];
3099
- return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
3100
- case 1:
3101
- _a.sent();
3102
- return [3 /*break*/, 3];
3103
- case 2:
3104
- selectedRows.forEach(function (row) { return (row[field] = value); });
3105
- _a.label = 3;
3106
- case 3: return [2 /*return*/, true];
3127
+ case 0: return [4 /*yield*/, selectItemHandler(value, subComponentValue)];
3128
+ case 1: return [2 /*return*/, _a.sent()];
3107
3129
  }
3108
3130
  });
3109
3131
  }); }, reason === CloseReason.TAB_FORWARD ? 1 : reason === CloseReason.TAB_BACKWARD ? -1 : 0)];
3110
3132
  });
3111
- }); }, [field, props, updateValue]);
3133
+ }); }, [selectItemHandler, updateValue]);
3112
3134
  var selectFilterHandler = react.useCallback(function (value) { return __awaiter(void 0, void 0, void 0, function () {
3113
3135
  return __generator(this, function (_a) {
3114
3136
  return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
@@ -3148,14 +3170,13 @@ var GridFormDropDown = function (props) {
3148
3170
  _a.label = 2;
3149
3171
  case 2:
3150
3172
  optionsList = optionsConf === null || optionsConf === void 0 ? void 0 : optionsConf.map(function (item) {
3151
- if (item == null || typeof item == "string" || typeof item == "number") {
3152
- item = {
3173
+ return item == null || typeof item == "string"
3174
+ ? {
3153
3175
  value: item,
3154
3176
  label: item,
3155
3177
  disabled: false
3156
- };
3157
- }
3158
- return item;
3178
+ }
3179
+ : item;
3159
3180
  });
3160
3181
  if (props.filtered) {
3161
3182
  // This is needed otherwise when filter input is rendered and sets autofocus
@@ -3200,6 +3221,9 @@ var GridFormDropDown = function (props) {
3200
3221
  researchOnFilterChange().then();
3201
3222
  }
3202
3223
  }, [filter, props, researchOnFilterChange]);
3224
+ /**
3225
+ * Saves are wrapped in updateValue and triggered by blur events
3226
+ */
3203
3227
  var save = react.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
3204
3228
  var activeOptions;
3205
3229
  return __generator(this, function (_a) {
@@ -3267,7 +3291,7 @@ var GridFormDropDown = function (props) {
3267
3291
  e.keepOpen = true;
3268
3292
  }
3269
3293
  else {
3270
- selectItemHandler(item.value, undefined, e.key === "Tab"
3294
+ clickItemHandler(item.value, undefined, e.key === "Tab"
3271
3295
  ? e.shiftKey
3272
3296
  ? CloseReason.TAB_BACKWARD
3273
3297
  : CloseReason.TAB_FORWARD
@@ -3459,8 +3483,6 @@ var GridFormPopoverMenu = function (props) {
3459
3483
  var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, updateValue = _a.updateValue, data = _a.data;
3460
3484
  var optionsInitialising = react.useRef(false);
3461
3485
  var _b = react.useState(), options = _b[0], setOptions = _b[1];
3462
- // Save triggers during async action processing which triggers another action(), this ref blocks that
3463
- var actionProcessing = react.useRef(false);
3464
3486
  var _c = react.useState(null), subComponentSelected = _c[0], setSubComponentSelected = _c[1];
3465
3487
  var subComponentIsValid = react.useRef(false);
3466
3488
  var _d = react.useState(), subSelectedValue = _d[0], setSubSelectedValue = _d[1];
@@ -3517,26 +3539,20 @@ var GridFormPopoverMenu = function (props) {
3517
3539
  });
3518
3540
  }); })();
3519
3541
  }, [options, props.defaultAction, props.options, selectedRows]);
3520
- var actionClick = react.useCallback(function (menuOption, reason) { return __awaiter(void 0, void 0, void 0, function () {
3521
- return __generator(this, function (_a) {
3522
- actionProcessing.current = true;
3523
- return [2 /*return*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () {
3524
- var result;
3525
- var _a;
3526
- return __generator(this, function (_b) {
3527
- switch (_b.label) {
3528
- case 0:
3529
- result = __assign(__assign({}, menuOption), { subValue: subSelectedValue });
3530
- return [4 /*yield*/, ((_a = menuOption.action) !== null && _a !== void 0 ? _a : defaultAction)(selectedRows, result)];
3531
- case 1:
3532
- _b.sent();
3533
- actionProcessing.current = false;
3534
- return [2 /*return*/, true];
3535
- }
3536
- });
3537
- }); }, reason === CloseReason.TAB_FORWARD ? 1 : reason === CloseReason.TAB_BACKWARD ? -1 : 0)];
3542
+ var actionClick = react.useCallback(function (menuOption) { return __awaiter(void 0, void 0, void 0, function () {
3543
+ var result;
3544
+ var _a;
3545
+ return __generator(this, function (_b) {
3546
+ switch (_b.label) {
3547
+ case 0:
3548
+ result = __assign(__assign({}, menuOption), { subValue: subSelectedValue });
3549
+ return [4 /*yield*/, ((_a = menuOption.action) !== null && _a !== void 0 ? _a : defaultAction)(selectedRows, result)];
3550
+ case 1:
3551
+ _b.sent();
3552
+ return [2 /*return*/, true];
3553
+ }
3538
3554
  });
3539
- }); }, [defaultAction, selectedRows, subSelectedValue, updateValue]);
3555
+ }); }, [defaultAction, selectedRows, subSelectedValue]);
3540
3556
  var onMenuItemClick = react.useCallback(function (e, item) { return __awaiter(void 0, void 0, void 0, function () {
3541
3557
  return __generator(this, function (_a) {
3542
3558
  switch (_a.label) {
@@ -3547,27 +3563,29 @@ var GridFormPopoverMenu = function (props) {
3547
3563
  setSubComponentSelected(subComponentSelected === item ? null : item);
3548
3564
  e.keepOpen = true;
3549
3565
  return [3 /*break*/, 3];
3550
- case 1: return [4 /*yield*/, actionClick(item, e.key === "Tab" ? (e.shiftKey ? CloseReason.TAB_BACKWARD : CloseReason.TAB_FORWARD) : CloseReason.CLICK).then()];
3566
+ case 1: return [4 /*yield*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
3567
+ return [2 /*return*/, actionClick(item)];
3568
+ }); }); }, e.key === "Tab" ? (e.shiftKey ? -1 : 1) : 0)];
3551
3569
  case 2:
3552
3570
  _a.sent();
3553
3571
  _a.label = 3;
3554
3572
  case 3: return [2 /*return*/];
3555
3573
  }
3556
3574
  });
3557
- }); }, [actionClick, subComponentSelected]);
3575
+ }); }, [actionClick, subComponentSelected, updateValue]);
3558
3576
  var save = react.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
3559
3577
  return __generator(this, function (_a) {
3560
3578
  switch (_a.label) {
3561
3579
  case 0:
3562
- if (!(!actionProcessing.current && subComponentSelected)) return [3 /*break*/, 2];
3580
+ if (!subComponentSelected) return [3 /*break*/, 2];
3563
3581
  if (!subComponentIsValid.current)
3564
3582
  return [2 /*return*/, false];
3565
- return [4 /*yield*/, actionClick(subComponentSelected, "click")];
3583
+ return [4 /*yield*/, actionClick(subComponentSelected)];
3566
3584
  case 1:
3567
3585
  _a.sent();
3568
- return [2 /*return*/, true];
3586
+ _a.label = 2;
3569
3587
  case 2:
3570
- // Otherwise assume it's a cancel, either way we close the menu
3588
+ // Close the menu
3571
3589
  return [2 /*return*/, true];
3572
3590
  }
3573
3591
  });
@@ -3627,7 +3645,7 @@ var bearingNumberParser = function (value) {
3627
3645
  return parseFloat(value);
3628
3646
  };
3629
3647
  var validMaskForDmsBearing = /^((-)?\d+)?(\.([0-5](\d([0-5](\d(\d+)?)?)?)?)?)?$/;
3630
- var bearingStringValidator = function (value, customValidate) {
3648
+ var bearingStringValidator = function (value, customInvalid) {
3631
3649
  value = value.trim();
3632
3650
  if (value === "")
3633
3651
  return null;
@@ -3639,7 +3657,7 @@ var bearingStringValidator = function (value, customValidate) {
3639
3657
  return "Bearing has a maximum of 5 decimal places";
3640
3658
  }
3641
3659
  var bearing = parseFloat(value);
3642
- return customValidate ? customValidate(bearing) : null;
3660
+ return customInvalid ? customInvalid(bearing) : null;
3643
3661
  };
3644
3662
  // Decimal-ish degrees to Degrees Minutes Seconds converter
3645
3663
  var convertDDToDMS = function (dd, showPositiveSymbol, addTrailingZeros) {
@@ -3902,8 +3920,11 @@ var TextInputValidator = function (props, value, data) {
3902
3920
  if (props.maxLength && value.length > props.maxLength) {
3903
3921
  return "Text must be no longer than ".concat(props.maxLength, " characters");
3904
3922
  }
3905
- if (props.validate) {
3906
- return props.validate(value, data);
3923
+ if (props.maxBytes && new TextEncoder().encode(value).length > props.maxBytes) {
3924
+ return "Text must be no longer than ".concat(props.maxLength, " bytes");
3925
+ }
3926
+ if (props.invalid) {
3927
+ return props.invalid(value, data);
3907
3928
  }
3908
3929
  return null;
3909
3930
  };