@linzjs/step-ag-grid 3.0.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.
package/dist/index.js CHANGED
@@ -2656,12 +2656,15 @@ var GridPopoverContext = react.createContext({
2656
2656
  setSaving: function () { },
2657
2657
  field: "",
2658
2658
  value: null,
2659
- data: null,
2659
+ data: {},
2660
2660
  selectedRows: [],
2661
2661
  updateValue: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
2662
2662
  return [2 /*return*/, false];
2663
2663
  }); }); }
2664
- });
2664
+ });
2665
+ var useGridPopoverContext = function () {
2666
+ return react.useContext(GridPopoverContext);
2667
+ };
2665
2668
 
2666
2669
  var GridPopoverContextProvider = function (_a) {
2667
2670
  var _b, _c, _d;
@@ -2757,7 +2760,7 @@ var ComponentLoadingWrapper = function (props) {
2757
2760
 
2758
2761
  var useGridPopoverHook = function (props) {
2759
2762
  var stopEditing = react.useContext(GridContext).stopEditing;
2760
- var _a = react.useContext(GridPopoverContext), anchorRef = _a.anchorRef, saving = _a.saving, updateValue = _a.updateValue;
2763
+ var _a = useGridPopoverContext(), anchorRef = _a.anchorRef, saving = _a.saving, updateValue = _a.updateValue;
2761
2764
  var saveButtonRef = react.useRef(null);
2762
2765
  var _b = react.useState(false), isOpen = _b[0], setOpen = _b[1];
2763
2766
  react.useEffect(function () {
@@ -2910,8 +2913,11 @@ var MenuHeaderString = "_____MENU_HEADER_____";
2910
2913
  var MenuHeaderItem = function (title) {
2911
2914
  return { label: title, value: MenuHeaderString };
2912
2915
  };
2916
+ var fieldToString = function (field) {
2917
+ return typeof field == "symbol" ? field.toString() : "".concat(field);
2918
+ };
2913
2919
  var GridFormDropDown = function (props) {
2914
- var _a = react.useContext(GridPopoverContext), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue;
2920
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue;
2915
2921
  var stopEditing = react.useContext(GridContext).stopEditing;
2916
2922
  var _b = react.useState(""), filter = _b[0], setFilter = _b[1];
2917
2923
  var _c = react.useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
@@ -3067,48 +3073,43 @@ var GridFormDropDown = function (props) {
3067
3073
  var _b;
3068
3074
  var ref = _a.ref;
3069
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); } }) })));
3070
- } })), jsxRuntime.jsx(MenuDivider, {}, "$$divider_filter")] }))), jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [options && options.length == (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length) && jsxRuntime.jsx(MenuItem, { children: "[Empty]" }, "".concat(field, "-empty")), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
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) {
3071
3077
  var _a;
3072
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 () {
3073
3079
  selectItemHandler(item.value).then();
3074
- } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(field, "-").concat(index))) : (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3075
- return item.subComponent &&
3076
- item.subComponent({
3077
- setValue: function (value) {
3078
- var localSubComponentValues = __spreadArray([], subComponentValues, true);
3079
- var subComponentValueIndex = localSubComponentValues.findIndex(function (_a) {
3080
- var optionValue = _a.optionValue;
3081
- return optionValue === item.value;
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
3082
3094
  });
3083
- if (subComponentValueIndex !== -1) {
3084
- localSubComponentValues[subComponentValueIndex].subComponentValue = value;
3085
- }
3086
- else {
3087
- localSubComponentValues.push({
3088
- subComponentValue: value,
3089
- optionValue: item.value
3090
- });
3091
- }
3092
- setSubComponentValues(localSubComponentValues);
3093
- },
3094
- keyDown: function (key, event) {
3095
- var subComponentItem = subComponentValues.find(function (_a) {
3096
- var optionValue = _a.optionValue;
3097
- 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;
3098
3108
  });
3099
- if ((key === "Enter" || key === "Tab") && subComponentItem) {
3100
- event.preventDefault();
3101
- event.stopPropagation();
3102
- return selectItemHandler(item.value, subComponentItem.subComponentValue).then(function () {
3103
- ref.closeMenu();
3104
- return true;
3105
- });
3106
- }
3107
- return false;
3108
- },
3109
- key: "".concat(field, "-").concat(index, "_subcomponent_inner")
3110
- }, ref);
3111
- } }), "".concat(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)));
3112
3113
  })] }) }))] }));
3113
3114
  };
3114
3115
 
@@ -3129,7 +3130,7 @@ var GridSubComponentContext = react.createContext({
3129
3130
  });
3130
3131
 
3131
3132
  var GridFormMultiSelect = function (props) {
3132
- var selectedRows = react.useContext(GridPopoverContext).selectedRows;
3133
+ var selectedRows = useGridPopoverContext().selectedRows;
3133
3134
  var initialiseValues = react.useMemo(function () {
3134
3135
  var r = props.initialSelectedValues && props.initialSelectedValues(selectedRows);
3135
3136
  // convert array of strings to object<value,null>
@@ -3291,7 +3292,7 @@ var PopoutMenuSeparator = Object.freeze({ __isMenuSeparator__: true });
3291
3292
  * you need a useMemo around your columnDefs
3292
3293
  */
3293
3294
  var GridFormPopoverMenu = function (props) {
3294
- var _a = react.useContext(GridPopoverContext), selectedRows = _a.selectedRows, updateValue = _a.updateValue;
3295
+ var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, updateValue = _a.updateValue;
3295
3296
  var optionsInitialising = react.useRef(false);
3296
3297
  var _b = react.useState(), options = _b[0], setOptions = _b[1];
3297
3298
  // Save triggers during async action processing which triggers another action(), this ref blocks that
@@ -3299,6 +3300,22 @@ var GridFormPopoverMenu = function (props) {
3299
3300
  var _c = react.useState(null), subComponentSelected = _c[0], setSubComponentSelected = _c[1];
3300
3301
  var subComponentIsValid = react.useRef(false);
3301
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]);
3302
3319
  // Load up options list if it's async function
3303
3320
  react.useEffect(function () {
3304
3321
  var _a;
@@ -3307,50 +3324,55 @@ var GridFormPopoverMenu = function (props) {
3307
3324
  optionsInitialising.current = true;
3308
3325
  var optionsConf = (_a = props.options) !== null && _a !== void 0 ? _a : [];
3309
3326
  (function () { return __awaiter(void 0, void 0, void 0, function () {
3310
- var _a, _b;
3311
- return __generator(this, function (_c) {
3312
- switch (_c.label) {
3327
+ var newOptions, _a, anyOptionsAreMissingAction;
3328
+ return __generator(this, function (_b) {
3329
+ switch (_b.label) {
3313
3330
  case 0:
3314
- _a = setOptions;
3315
3331
  if (!(typeof optionsConf == "function")) return [3 /*break*/, 2];
3316
3332
  return [4 /*yield*/, optionsConf(selectedRows)];
3317
3333
  case 1:
3318
- _b = _c.sent();
3334
+ _a = _b.sent();
3319
3335
  return [3 /*break*/, 3];
3320
3336
  case 2:
3321
- _b = optionsConf;
3322
- _c.label = 3;
3337
+ _a = optionsConf;
3338
+ _b.label = 3;
3323
3339
  case 3:
3324
- _a.apply(void 0, [_b]);
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
+ }
3325
3350
  optionsInitialising.current = false;
3326
3351
  return [2 /*return*/];
3327
3352
  }
3328
3353
  });
3329
3354
  }); })();
3330
- }, [options, props.options, selectedRows]);
3355
+ }, [options, props.defaultAction, props.options, selectedRows]);
3331
3356
  var actionClick = react.useCallback(function (menuOption) { return __awaiter(void 0, void 0, void 0, function () {
3332
3357
  return __generator(this, function (_a) {
3333
3358
  actionProcessing.current = true;
3334
3359
  return [2 /*return*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () {
3335
- var result, _a;
3360
+ var result;
3361
+ var _a;
3336
3362
  return __generator(this, function (_b) {
3337
3363
  switch (_b.label) {
3338
3364
  case 0:
3339
3365
  result = __assign(__assign({}, menuOption), { subValue: subSelectedValue });
3340
- _a = menuOption.action;
3341
- if (!_a) return [3 /*break*/, 2];
3342
- return [4 /*yield*/, menuOption.action(selectedRows, result)];
3366
+ return [4 /*yield*/, ((_a = menuOption.action) !== null && _a !== void 0 ? _a : defaultAction)(selectedRows, result)];
3343
3367
  case 1:
3344
- _a = (_b.sent());
3345
- _b.label = 2;
3346
- case 2:
3368
+ _b.sent();
3347
3369
  actionProcessing.current = false;
3348
3370
  return [2 /*return*/, true];
3349
3371
  }
3350
3372
  });
3351
3373
  }); })];
3352
3374
  });
3353
- }); }, [selectedRows, subSelectedValue, updateValue]);
3375
+ }); }, [defaultAction, selectedRows, subSelectedValue, updateValue]);
3354
3376
  var onMenuItemClick = react.useCallback(function (e, item) {
3355
3377
  if (item.subComponent) {
3356
3378
  subComponentIsValid.current = false;
@@ -3507,7 +3529,7 @@ var TextInputFormatted = function (props) {
3507
3529
  };
3508
3530
 
3509
3531
  var GridFormEditBearing = function (props) {
3510
- var _a = react.useContext(GridPopoverContext), field = _a.field, initialValue = _a.value;
3532
+ var _a = useGridPopoverContext(), field = _a.field, initialValue = _a.value;
3511
3533
  var _b = react.useState("".concat(initialValue !== null && initialValue !== void 0 ? initialValue : "")), value = _b[0], setValue = _b[1];
3512
3534
  var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
3513
3535
  var parsedValue;
@@ -3529,7 +3551,9 @@ var GridFormEditBearing = function (props) {
3529
3551
  console.error("field is not defined in ColDef");
3530
3552
  }
3531
3553
  else {
3532
- selectedRows.forEach(function (row) { return (row[field] = parsedValue); });
3554
+ selectedRows.forEach(function (row) {
3555
+ row[field] = parsedValue;
3556
+ });
3533
3557
  }
3534
3558
  _a.label = 3;
3535
3559
  case 3: return [2 /*return*/, true];
@@ -3589,7 +3613,7 @@ var GridPopoverEditDropDown = function (colDef, props) {
3589
3613
  };
3590
3614
 
3591
3615
  var GridFormMessage = function (props) {
3592
- var selectedRows = react.useContext(GridPopoverContext).selectedRows;
3616
+ var selectedRows = useGridPopoverContext().selectedRows;
3593
3617
  var _a = react.useState(null), message = _a[0], setMessage = _a[1];
3594
3618
  var popoverWrapper = useGridPopoverHook({ className: props.className }).popoverWrapper;
3595
3619
  react.useEffect(function () {
@@ -3696,8 +3720,8 @@ var TextAreaInput = function (props) {
3696
3720
 
3697
3721
  var GridFormTextArea = function (props) {
3698
3722
  var _a;
3699
- var _b = react.useContext(GridPopoverContext), field = _b.field, initialVale = _b.value;
3700
- var _c = react.useState(initialVale !== null && initialVale !== void 0 ? initialVale : ""), value = _c[0], setValue = _c[1];
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];
3701
3725
  var invalid = react.useCallback(function () {
3702
3726
  if (props.required && value.length == 0) {
3703
3727
  return "Some text is required";
@@ -3726,7 +3750,9 @@ var GridFormTextArea = function (props) {
3726
3750
  console.error("ColDef has no field set");
3727
3751
  return [2 /*return*/, false];
3728
3752
  }
3729
- selectedRows.forEach(function (row) { return (row[field] = value); });
3753
+ selectedRows.forEach(function (row) {
3754
+ row[field] = value;
3755
+ });
3730
3756
  return [2 /*return*/, true];
3731
3757
  }
3732
3758
  });
@@ -3739,7 +3765,7 @@ var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __
3739
3765
 
3740
3766
  var GridFormTextInput = function (props) {
3741
3767
  var _a;
3742
- var _b = react.useContext(GridPopoverContext), field = _b.field, data = _b.data, initialVale = _b.value;
3768
+ var _b = useGridPopoverContext(), field = _b.field, data = _b.data, initialVale = _b.value;
3743
3769
  var initValue = initialVale == null ? "" : "".concat(initialVale);
3744
3770
  var _c = react.useState(initValue), value = _c[0], setValue = _c[1];
3745
3771
  var invalid = react.useCallback(function () {
@@ -3773,8 +3799,9 @@ var GridFormTextInput = function (props) {
3773
3799
  console.error("ColDef has no field set");
3774
3800
  return [2 /*return*/, false];
3775
3801
  }
3776
- // @ts-ignore row[field] row is of type any
3777
- selectedRows.forEach(function (row) { return (row[field] = trimmedValue); });
3802
+ selectedRows.forEach(function (row) {
3803
+ row[field] = trimmedValue;
3804
+ });
3778
3805
  return [2 /*return*/, true];
3779
3806
  }
3780
3807
  });