@linzjs/step-ag-grid 4.0.2 → 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.
- package/dist/index.js +66 -40
- package/dist/index.js.map +1 -1
- package/dist/src/components/GridPopoverHook.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +66 -40
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridPopoverHook.tsx +24 -4
- package/src/components/gridForm/GridFormDropDown.tsx +14 -4
- package/src/components/gridForm/GridFormEditBearing.tsx +15 -6
- package/src/components/gridForm/GridFormTextArea.tsx +6 -4
- package/src/components/gridForm/GridFormTextInput.tsx +11 -4
- package/src/stories/grid/FormTest.tsx +8 -5
- package/src/stories/grid/GridPopoutBearing.stories.tsx +3 -2
- package/src/utils/bearing.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -2796,30 +2796,35 @@ var useGridPopoverHook = function (props) {
|
|
|
2796
2796
|
setOpen(true);
|
|
2797
2797
|
}, []);
|
|
2798
2798
|
var triggerSave = react.useCallback(function (reason) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
switch (_c.label) {
|
|
2799
|
+
return __generator(this, function (_a) {
|
|
2800
|
+
switch (_a.label) {
|
|
2802
2801
|
case 0:
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2802
|
+
if (reason == "cancel") {
|
|
2803
|
+
stopEditing();
|
|
2804
|
+
return [2 /*return*/];
|
|
2805
|
+
}
|
|
2806
|
+
if (props.invalid && props.invalid()) {
|
|
2807
|
+
return [2 /*return*/];
|
|
2808
|
+
}
|
|
2809
|
+
if (!!props.save) return [3 /*break*/, 1];
|
|
2810
|
+
stopEditing();
|
|
2811
|
+
return [3 /*break*/, 3];
|
|
2808
2812
|
case 1:
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
_a = (_b);
|
|
2813
|
-
_c.label = 3;
|
|
2814
|
-
case 3:
|
|
2815
|
-
if (_a) {
|
|
2816
|
-
setOpen(false);
|
|
2813
|
+
if (!props.save) return [3 /*break*/, 3];
|
|
2814
|
+
// forms that don't provide an invalid fn must wait until they have saved to close
|
|
2815
|
+
if (props.invalid)
|
|
2817
2816
|
stopEditing();
|
|
2817
|
+
return [4 /*yield*/, updateValue(props.save)];
|
|
2818
|
+
case 2:
|
|
2819
|
+
if (_a.sent()) {
|
|
2820
|
+
if (!props.invalid)
|
|
2821
|
+
stopEditing();
|
|
2818
2822
|
}
|
|
2819
|
-
|
|
2823
|
+
_a.label = 3;
|
|
2824
|
+
case 3: return [2 /*return*/];
|
|
2820
2825
|
}
|
|
2821
2826
|
});
|
|
2822
|
-
}); }, [props
|
|
2827
|
+
}); }, [props, stopEditing, updateValue]);
|
|
2823
2828
|
var onlyInputKeyboardEventHandlers = {
|
|
2824
2829
|
onKeyUp: function (e) {
|
|
2825
2830
|
var isTextArea = e.currentTarget.type === "textarea";
|
|
@@ -2901,7 +2906,9 @@ var useGridPopoverHook = function (props) {
|
|
|
2901
2906
|
right: 0,
|
|
2902
2907
|
backgroundColor: "rgba(64,64,64,0.1)",
|
|
2903
2908
|
zIndex: 1000
|
|
2904
|
-
} })), children, jsxRuntime.jsx("button", { ref: saveButtonRef, onClick: function () {
|
|
2909
|
+
} })), children, jsxRuntime.jsx("button", { ref: saveButtonRef, onClick: function () {
|
|
2910
|
+
triggerSave().then();
|
|
2911
|
+
}, style: { display: "none" } })] }))) }));
|
|
2905
2912
|
}, [anchorRef, isOpen, props.className, saving, triggerSave]);
|
|
2906
2913
|
return {
|
|
2907
2914
|
popoverWrapper: popoverWrapper,
|
|
@@ -3020,17 +3027,20 @@ var fieldToString = function (field) {
|
|
|
3020
3027
|
var GridFormDropDown = function (props) {
|
|
3021
3028
|
var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue, data = _a.data;
|
|
3022
3029
|
var stopEditing = react.useContext(GridContext).stopEditing;
|
|
3030
|
+
// Save triggers during async action processing which triggers another selectItem(), this ref blocks that
|
|
3031
|
+
var hasSubmitted = react.useRef(false);
|
|
3023
3032
|
var _b = react.useState(""), filter = _b[0], setFilter = _b[1];
|
|
3024
3033
|
var _c = react.useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
|
|
3025
3034
|
var optionsInitialising = react.useRef(false);
|
|
3026
3035
|
var _d = react.useState(null), options = _d[0], setOptions = _d[1];
|
|
3027
3036
|
var subComponentIsValid = react.useRef(false);
|
|
3028
3037
|
var _e = react.useState(), subSelectedValue = _e[0], setSubSelectedValue = _e[1];
|
|
3029
|
-
var _f = react.useState(), selectedSubComponent = _f[0], setSelectedSubComponent = _f[1];
|
|
3038
|
+
var _f = react.useState(null), selectedSubComponent = _f[0], setSelectedSubComponent = _f[1];
|
|
3030
3039
|
var selectItemHandler = react.useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3031
3040
|
return __generator(this, function (_a) {
|
|
3032
|
-
if (subComponentValue !== undefined && !subComponentIsValid.current)
|
|
3041
|
+
if (hasSubmitted.current || (subComponentValue !== undefined && !subComponentIsValid.current))
|
|
3033
3042
|
return [2 /*return*/, false];
|
|
3043
|
+
hasSubmitted.current = true;
|
|
3034
3044
|
return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3035
3045
|
var hasChanged;
|
|
3036
3046
|
return __generator(this, function (_a) {
|
|
@@ -3180,7 +3190,7 @@ var GridFormDropDown = function (props) {
|
|
|
3180
3190
|
// Handler for sub-selected value
|
|
3181
3191
|
if (!selectedSubComponent)
|
|
3182
3192
|
return [2 /*return*/, true];
|
|
3183
|
-
if (!subComponentIsValid.current)
|
|
3193
|
+
if (selectedSubComponent.subComponent && !subComponentIsValid.current)
|
|
3184
3194
|
return [2 /*return*/, false];
|
|
3185
3195
|
return [4 /*yield*/, selectItemHandler(selectedSubComponent.value, subSelectedValue)];
|
|
3186
3196
|
case 1:
|
|
@@ -3189,20 +3199,26 @@ var GridFormDropDown = function (props) {
|
|
|
3189
3199
|
}
|
|
3190
3200
|
});
|
|
3191
3201
|
}); }, [selectItemHandler, selectedSubComponent, subSelectedValue]);
|
|
3192
|
-
var popoverWrapper = useGridPopoverHook({
|
|
3202
|
+
var popoverWrapper = useGridPopoverHook({
|
|
3203
|
+
className: props.className,
|
|
3204
|
+
invalid: function () { return !!(selectedSubComponent && !subComponentIsValid.current); },
|
|
3205
|
+
save: save
|
|
3206
|
+
}).popoverWrapper;
|
|
3193
3207
|
return popoverWrapper(jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [props.filtered && (jsxRuntime.jsxs("div", __assign({ className: "GridFormDropDown-filter" }, { children: [jsxRuntime.jsx(FocusableItem, __assign({ className: "filter-item" }, { children: function (_a) {
|
|
3194
3208
|
var _b;
|
|
3195
3209
|
var ref = _a.ref;
|
|
3196
3210
|
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); } }) })));
|
|
3197
3211
|
} })), 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) {
|
|
3198
3212
|
var _a;
|
|
3199
|
-
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.jsxs("div", { children: [jsxRuntime.
|
|
3213
|
+
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.jsxs("div", { children: [jsxRuntime.jsxs(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onClick: function (e) {
|
|
3200
3214
|
if (item.subComponent) {
|
|
3201
3215
|
if (selectedSubComponent === item) {
|
|
3216
|
+
// toggle selection off
|
|
3202
3217
|
setSelectedSubComponent(null);
|
|
3203
3218
|
subComponentIsValid.current = true;
|
|
3204
3219
|
}
|
|
3205
3220
|
else {
|
|
3221
|
+
// toggle selection on
|
|
3206
3222
|
setSelectedSubComponent(item);
|
|
3207
3223
|
}
|
|
3208
3224
|
e.keepOpen = true;
|
|
@@ -3210,7 +3226,7 @@ var GridFormDropDown = function (props) {
|
|
|
3210
3226
|
else {
|
|
3211
3227
|
selectItemHandler(item.value).then();
|
|
3212
3228
|
}
|
|
3213
|
-
} }, { 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 && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) { return (jsxRuntime.jsx(GridSubComponentContext.Provider, __assign({ value: {
|
|
3229
|
+
} }, { 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 && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) { return (jsxRuntime.jsx(GridSubComponentContext.Provider, __assign({ value: {
|
|
3214
3230
|
data: data,
|
|
3215
3231
|
value: subSelectedValue,
|
|
3216
3232
|
setValue: function (value) {
|
|
@@ -3528,7 +3544,7 @@ var GridPopoverMenu = function (colDef, custom) {
|
|
|
3528
3544
|
};
|
|
3529
3545
|
|
|
3530
3546
|
var bearingValueFormatter = function (params) {
|
|
3531
|
-
var value = params.value;
|
|
3547
|
+
var value = typeof params.value == "string" ? parseFloat(params.value) : params.value;
|
|
3532
3548
|
if (value == null) {
|
|
3533
3549
|
return "-";
|
|
3534
3550
|
}
|
|
@@ -3622,17 +3638,18 @@ var TextInputFormatted = function (props) {
|
|
|
3622
3638
|
|
|
3623
3639
|
var GridFormEditBearing = function (props) {
|
|
3624
3640
|
var _a = useGridPopoverContext(), field = _a.field, initialValue = _a.value;
|
|
3625
|
-
|
|
3641
|
+
// This clears out any scientific precision
|
|
3642
|
+
var defaultValue = react.useMemo(function () { return (initialValue == null ? "" : parseFloat(parseFloat(initialValue).toFixed(10)).toString()); }, [initialValue]);
|
|
3643
|
+
var _b = react.useState(defaultValue), value = _b[0], setValue = _b[1];
|
|
3644
|
+
var invalid = react.useCallback(function () { return bearingStringValidator(value, props.range); }, [props.range, value]);
|
|
3626
3645
|
var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3627
3646
|
var parsedValue;
|
|
3628
3647
|
return __generator(this, function (_a) {
|
|
3629
3648
|
switch (_a.label) {
|
|
3630
3649
|
case 0:
|
|
3631
|
-
if (bearingStringValidator(value))
|
|
3632
|
-
return [2 /*return*/, false];
|
|
3633
3650
|
parsedValue = bearingNumberParser(value);
|
|
3634
3651
|
// Value didn't change so don't save just cancel
|
|
3635
|
-
if (parsedValue ===
|
|
3652
|
+
if (parsedValue === bearingNumberParser(defaultValue)) {
|
|
3636
3653
|
return [2 /*return*/, true];
|
|
3637
3654
|
}
|
|
3638
3655
|
if (!props.onSave) return [3 /*break*/, 2];
|
|
@@ -3651,14 +3668,15 @@ var GridFormEditBearing = function (props) {
|
|
|
3651
3668
|
case 3: return [2 /*return*/, true];
|
|
3652
3669
|
}
|
|
3653
3670
|
});
|
|
3654
|
-
}); }, [
|
|
3671
|
+
}); }, [defaultValue, field, props, value]);
|
|
3655
3672
|
var _c = useGridPopoverHook({
|
|
3656
3673
|
className: props.className,
|
|
3674
|
+
invalid: invalid,
|
|
3657
3675
|
save: save
|
|
3658
3676
|
}), popoverWrapper = _c.popoverWrapper, onlyInputKeyboardEventHandlers = _c.onlyInputKeyboardEventHandlers;
|
|
3659
|
-
return popoverWrapper(jsxRuntime.jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsxRuntime.jsx(TextInputFormatted, __assign({ value:
|
|
3677
|
+
return popoverWrapper(jsxRuntime.jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsxRuntime.jsx(TextInputFormatted, __assign({ value: defaultValue, onChange: function (e) {
|
|
3660
3678
|
setValue(e.target.value.trim());
|
|
3661
|
-
}, autoFocus: true, placeholder: props.placeHolder }, onlyInputKeyboardEventHandlers, { formatted: bearingStringValidator(value, props.range) ? "?" : convertDDToDMS(bearingNumberParser(value)), error: bearingStringValidator(value, props.range) })) })));
|
|
3679
|
+
}, 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" })) })));
|
|
3662
3680
|
};
|
|
3663
3681
|
|
|
3664
3682
|
var GridPopoverEditBearingLike = function (colDef, props) {
|
|
@@ -3837,8 +3855,6 @@ var GridFormTextArea = function (props) {
|
|
|
3837
3855
|
return __generator(this, function (_a) {
|
|
3838
3856
|
switch (_a.label) {
|
|
3839
3857
|
case 0:
|
|
3840
|
-
if (invalid())
|
|
3841
|
-
return [2 /*return*/, false];
|
|
3842
3858
|
if (initialVale === (value !== null && value !== void 0 ? value : ""))
|
|
3843
3859
|
return [2 /*return*/, true];
|
|
3844
3860
|
if (!props.onSave) return [3 /*break*/, 2];
|
|
@@ -3855,8 +3871,12 @@ var GridFormTextArea = function (props) {
|
|
|
3855
3871
|
return [2 /*return*/, true];
|
|
3856
3872
|
}
|
|
3857
3873
|
});
|
|
3858
|
-
}); }, [
|
|
3859
|
-
var _e = useGridPopoverHook({
|
|
3874
|
+
}); }, [initialVale, value, props, field]);
|
|
3875
|
+
var _e = useGridPopoverHook({
|
|
3876
|
+
className: props.className,
|
|
3877
|
+
invalid: invalid,
|
|
3878
|
+
save: save
|
|
3879
|
+
}), popoverWrapper = _e.popoverWrapper, onlyInputKeyboardEventHandlers = _e.onlyInputKeyboardEventHandlers;
|
|
3860
3880
|
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, __assign({ value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), placeholder: props.placeholder, helpText: helpText }, onlyInputKeyboardEventHandlers)) })));
|
|
3861
3881
|
};
|
|
3862
3882
|
|
|
@@ -3864,9 +3884,10 @@ var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __
|
|
|
3864
3884
|
|
|
3865
3885
|
var GridFormTextInput = function (props) {
|
|
3866
3886
|
var _a, _b;
|
|
3887
|
+
var stopEditing = react.useContext(GridContext).stopEditing;
|
|
3867
3888
|
var _c = useGridPopoverContext(), field = _c.field, initialVale = _c.value, data = _c.data;
|
|
3868
3889
|
var helpText = (_a = props.helpText) !== null && _a !== void 0 ? _a : "Press enter or tab to save";
|
|
3869
|
-
var initValue = initialVale == null ? "" : "".concat(initialVale);
|
|
3890
|
+
var initValue = react.useMemo(function () { return (initialVale == null ? "" : "".concat(initialVale)); }, [initialVale]);
|
|
3870
3891
|
var _d = react.useState(initValue), value = _d[0], setValue = _d[1];
|
|
3871
3892
|
var invalid = react.useCallback(function () { return TextInputValidator(props, value, data); }, [data, props, value]);
|
|
3872
3893
|
var save = react.useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -3876,6 +3897,7 @@ var GridFormTextInput = function (props) {
|
|
|
3876
3897
|
case 0:
|
|
3877
3898
|
if (invalid())
|
|
3878
3899
|
return [2 /*return*/, false];
|
|
3900
|
+
stopEditing();
|
|
3879
3901
|
trimmedValue = value.trim();
|
|
3880
3902
|
if (initValue === trimmedValue)
|
|
3881
3903
|
return [2 /*return*/, true];
|
|
@@ -3893,8 +3915,12 @@ var GridFormTextInput = function (props) {
|
|
|
3893
3915
|
return [2 /*return*/, true];
|
|
3894
3916
|
}
|
|
3895
3917
|
});
|
|
3896
|
-
}); }, [invalid, value, initValue, props, field]);
|
|
3897
|
-
var _e = useGridPopoverHook({
|
|
3918
|
+
}); }, [invalid, stopEditing, value, initValue, props, field]);
|
|
3919
|
+
var _e = useGridPopoverHook({
|
|
3920
|
+
className: props.className,
|
|
3921
|
+
invalid: invalid,
|
|
3922
|
+
save: save
|
|
3923
|
+
}), popoverWrapper = _e.popoverWrapper, onlyInputKeyboardEventHandlers = _e.onlyInputKeyboardEventHandlers;
|
|
3898
3924
|
return popoverWrapper(jsxRuntime.jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_b = props.width) !== null && _b !== void 0 ? _b : 240 }, className: "FormTest" }, { children: jsxRuntime.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 })) })));
|
|
3899
3925
|
};
|
|
3900
3926
|
|