@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
|
@@ -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>) => {
|
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -2794,30 +2794,35 @@ var useGridPopoverHook = function (props) {
|
|
|
2794
2794
|
setOpen(true);
|
|
2795
2795
|
}, []);
|
|
2796
2796
|
var triggerSave = useCallback(function (reason) { return __awaiter(void 0, void 0, void 0, function () {
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
switch (_c.label) {
|
|
2797
|
+
return __generator(this, function (_a) {
|
|
2798
|
+
switch (_a.label) {
|
|
2800
2799
|
case 0:
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
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];
|
|
2806
2810
|
case 1:
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
_a = (_b);
|
|
2811
|
-
_c.label = 3;
|
|
2812
|
-
case 3:
|
|
2813
|
-
if (_a) {
|
|
2814
|
-
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)
|
|
2815
2814
|
stopEditing();
|
|
2815
|
+
return [4 /*yield*/, updateValue(props.save)];
|
|
2816
|
+
case 2:
|
|
2817
|
+
if (_a.sent()) {
|
|
2818
|
+
if (!props.invalid)
|
|
2819
|
+
stopEditing();
|
|
2816
2820
|
}
|
|
2817
|
-
|
|
2821
|
+
_a.label = 3;
|
|
2822
|
+
case 3: return [2 /*return*/];
|
|
2818
2823
|
}
|
|
2819
2824
|
});
|
|
2820
|
-
}); }, [props
|
|
2825
|
+
}); }, [props, stopEditing, updateValue]);
|
|
2821
2826
|
var onlyInputKeyboardEventHandlers = {
|
|
2822
2827
|
onKeyUp: function (e) {
|
|
2823
2828
|
var isTextArea = e.currentTarget.type === "textarea";
|
|
@@ -2899,7 +2904,9 @@ var useGridPopoverHook = function (props) {
|
|
|
2899
2904
|
right: 0,
|
|
2900
2905
|
backgroundColor: "rgba(64,64,64,0.1)",
|
|
2901
2906
|
zIndex: 1000
|
|
2902
|
-
} })), children, jsx("button", { ref: saveButtonRef, onClick: function () {
|
|
2907
|
+
} })), children, jsx("button", { ref: saveButtonRef, onClick: function () {
|
|
2908
|
+
triggerSave().then();
|
|
2909
|
+
}, style: { display: "none" } })] }))) }));
|
|
2903
2910
|
}, [anchorRef, isOpen, props.className, saving, triggerSave]);
|
|
2904
2911
|
return {
|
|
2905
2912
|
popoverWrapper: popoverWrapper,
|
|
@@ -3018,17 +3025,20 @@ var fieldToString = function (field) {
|
|
|
3018
3025
|
var GridFormDropDown = function (props) {
|
|
3019
3026
|
var _a = useGridPopoverContext(), selectedRows = _a.selectedRows, field = _a.field, updateValue = _a.updateValue, data = _a.data;
|
|
3020
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);
|
|
3021
3030
|
var _b = useState(""), filter = _b[0], setFilter = _b[1];
|
|
3022
3031
|
var _c = useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
|
|
3023
3032
|
var optionsInitialising = useRef(false);
|
|
3024
3033
|
var _d = useState(null), options = _d[0], setOptions = _d[1];
|
|
3025
3034
|
var subComponentIsValid = useRef(false);
|
|
3026
3035
|
var _e = useState(), subSelectedValue = _e[0], setSubSelectedValue = _e[1];
|
|
3027
|
-
var _f = useState(), selectedSubComponent = _f[0], setSelectedSubComponent = _f[1];
|
|
3036
|
+
var _f = useState(null), selectedSubComponent = _f[0], setSelectedSubComponent = _f[1];
|
|
3028
3037
|
var selectItemHandler = useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3029
3038
|
return __generator(this, function (_a) {
|
|
3030
|
-
if (subComponentValue !== undefined && !subComponentIsValid.current)
|
|
3039
|
+
if (hasSubmitted.current || (subComponentValue !== undefined && !subComponentIsValid.current))
|
|
3031
3040
|
return [2 /*return*/, false];
|
|
3041
|
+
hasSubmitted.current = true;
|
|
3032
3042
|
return [2 /*return*/, updateValue(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3033
3043
|
var hasChanged;
|
|
3034
3044
|
return __generator(this, function (_a) {
|
|
@@ -3178,7 +3188,7 @@ var GridFormDropDown = function (props) {
|
|
|
3178
3188
|
// Handler for sub-selected value
|
|
3179
3189
|
if (!selectedSubComponent)
|
|
3180
3190
|
return [2 /*return*/, true];
|
|
3181
|
-
if (!subComponentIsValid.current)
|
|
3191
|
+
if (selectedSubComponent.subComponent && !subComponentIsValid.current)
|
|
3182
3192
|
return [2 /*return*/, false];
|
|
3183
3193
|
return [4 /*yield*/, selectItemHandler(selectedSubComponent.value, subSelectedValue)];
|
|
3184
3194
|
case 1:
|
|
@@ -3187,20 +3197,26 @@ var GridFormDropDown = function (props) {
|
|
|
3187
3197
|
}
|
|
3188
3198
|
});
|
|
3189
3199
|
}); }, [selectItemHandler, selectedSubComponent, subSelectedValue]);
|
|
3190
|
-
var popoverWrapper = useGridPopoverHook({
|
|
3200
|
+
var popoverWrapper = useGridPopoverHook({
|
|
3201
|
+
className: props.className,
|
|
3202
|
+
invalid: function () { return !!(selectedSubComponent && !subComponentIsValid.current); },
|
|
3203
|
+
save: save
|
|
3204
|
+
}).popoverWrapper;
|
|
3191
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) {
|
|
3192
3206
|
var _b;
|
|
3193
3207
|
var ref = _a.ref;
|
|
3194
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); } }) })));
|
|
3195
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) {
|
|
3196
3210
|
var _a;
|
|
3197
|
-
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: [
|
|
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) {
|
|
3198
3212
|
if (item.subComponent) {
|
|
3199
3213
|
if (selectedSubComponent === item) {
|
|
3214
|
+
// toggle selection off
|
|
3200
3215
|
setSelectedSubComponent(null);
|
|
3201
3216
|
subComponentIsValid.current = true;
|
|
3202
3217
|
}
|
|
3203
3218
|
else {
|
|
3219
|
+
// toggle selection on
|
|
3204
3220
|
setSelectedSubComponent(item);
|
|
3205
3221
|
}
|
|
3206
3222
|
e.keepOpen = true;
|
|
@@ -3208,7 +3224,7 @@ var GridFormDropDown = function (props) {
|
|
|
3208
3224
|
else {
|
|
3209
3225
|
selectItemHandler(item.value).then();
|
|
3210
3226
|
}
|
|
3211
|
-
} }, { 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: {
|
|
3212
3228
|
data: data,
|
|
3213
3229
|
value: subSelectedValue,
|
|
3214
3230
|
setValue: function (value) {
|
|
@@ -3526,7 +3542,7 @@ var GridPopoverMenu = function (colDef, custom) {
|
|
|
3526
3542
|
};
|
|
3527
3543
|
|
|
3528
3544
|
var bearingValueFormatter = function (params) {
|
|
3529
|
-
var value = params.value;
|
|
3545
|
+
var value = typeof params.value == "string" ? parseFloat(params.value) : params.value;
|
|
3530
3546
|
if (value == null) {
|
|
3531
3547
|
return "-";
|
|
3532
3548
|
}
|
|
@@ -3620,17 +3636,18 @@ var TextInputFormatted = function (props) {
|
|
|
3620
3636
|
|
|
3621
3637
|
var GridFormEditBearing = function (props) {
|
|
3622
3638
|
var _a = useGridPopoverContext(), field = _a.field, initialValue = _a.value;
|
|
3623
|
-
|
|
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]);
|
|
3624
3643
|
var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3625
3644
|
var parsedValue;
|
|
3626
3645
|
return __generator(this, function (_a) {
|
|
3627
3646
|
switch (_a.label) {
|
|
3628
3647
|
case 0:
|
|
3629
|
-
if (bearingStringValidator(value))
|
|
3630
|
-
return [2 /*return*/, false];
|
|
3631
3648
|
parsedValue = bearingNumberParser(value);
|
|
3632
3649
|
// Value didn't change so don't save just cancel
|
|
3633
|
-
if (parsedValue ===
|
|
3650
|
+
if (parsedValue === bearingNumberParser(defaultValue)) {
|
|
3634
3651
|
return [2 /*return*/, true];
|
|
3635
3652
|
}
|
|
3636
3653
|
if (!props.onSave) return [3 /*break*/, 2];
|
|
@@ -3649,14 +3666,15 @@ var GridFormEditBearing = function (props) {
|
|
|
3649
3666
|
case 3: return [2 /*return*/, true];
|
|
3650
3667
|
}
|
|
3651
3668
|
});
|
|
3652
|
-
}); }, [
|
|
3669
|
+
}); }, [defaultValue, field, props, value]);
|
|
3653
3670
|
var _c = useGridPopoverHook({
|
|
3654
3671
|
className: props.className,
|
|
3672
|
+
invalid: invalid,
|
|
3655
3673
|
save: save
|
|
3656
3674
|
}), popoverWrapper = _c.popoverWrapper, onlyInputKeyboardEventHandlers = _c.onlyInputKeyboardEventHandlers;
|
|
3657
|
-
return popoverWrapper(jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsx(TextInputFormatted, __assign({ value:
|
|
3675
|
+
return popoverWrapper(jsx("div", __assign({ className: "GridFormEditBearing-input Grid-popoverContainer" }, { children: jsx(TextInputFormatted, __assign({ value: defaultValue, onChange: function (e) {
|
|
3658
3676
|
setValue(e.target.value.trim());
|
|
3659
|
-
}, 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" })) })));
|
|
3660
3678
|
};
|
|
3661
3679
|
|
|
3662
3680
|
var GridPopoverEditBearingLike = function (colDef, props) {
|
|
@@ -3835,8 +3853,6 @@ var GridFormTextArea = function (props) {
|
|
|
3835
3853
|
return __generator(this, function (_a) {
|
|
3836
3854
|
switch (_a.label) {
|
|
3837
3855
|
case 0:
|
|
3838
|
-
if (invalid())
|
|
3839
|
-
return [2 /*return*/, false];
|
|
3840
3856
|
if (initialVale === (value !== null && value !== void 0 ? value : ""))
|
|
3841
3857
|
return [2 /*return*/, true];
|
|
3842
3858
|
if (!props.onSave) return [3 /*break*/, 2];
|
|
@@ -3853,8 +3869,12 @@ var GridFormTextArea = function (props) {
|
|
|
3853
3869
|
return [2 /*return*/, true];
|
|
3854
3870
|
}
|
|
3855
3871
|
});
|
|
3856
|
-
}); }, [
|
|
3857
|
-
var _e = useGridPopoverHook({
|
|
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;
|
|
3858
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)) })));
|
|
3859
3879
|
};
|
|
3860
3880
|
|
|
@@ -3862,9 +3882,10 @@ var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __
|
|
|
3862
3882
|
|
|
3863
3883
|
var GridFormTextInput = function (props) {
|
|
3864
3884
|
var _a, _b;
|
|
3885
|
+
var stopEditing = useContext(GridContext).stopEditing;
|
|
3865
3886
|
var _c = useGridPopoverContext(), field = _c.field, initialVale = _c.value, data = _c.data;
|
|
3866
3887
|
var helpText = (_a = props.helpText) !== null && _a !== void 0 ? _a : "Press enter or tab to save";
|
|
3867
|
-
var initValue = initialVale == null ? "" : "".concat(initialVale);
|
|
3888
|
+
var initValue = useMemo(function () { return (initialVale == null ? "" : "".concat(initialVale)); }, [initialVale]);
|
|
3868
3889
|
var _d = useState(initValue), value = _d[0], setValue = _d[1];
|
|
3869
3890
|
var invalid = useCallback(function () { return TextInputValidator(props, value, data); }, [data, props, value]);
|
|
3870
3891
|
var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -3874,6 +3895,7 @@ var GridFormTextInput = function (props) {
|
|
|
3874
3895
|
case 0:
|
|
3875
3896
|
if (invalid())
|
|
3876
3897
|
return [2 /*return*/, false];
|
|
3898
|
+
stopEditing();
|
|
3877
3899
|
trimmedValue = value.trim();
|
|
3878
3900
|
if (initValue === trimmedValue)
|
|
3879
3901
|
return [2 /*return*/, true];
|
|
@@ -3891,8 +3913,12 @@ var GridFormTextInput = function (props) {
|
|
|
3891
3913
|
return [2 /*return*/, true];
|
|
3892
3914
|
}
|
|
3893
3915
|
});
|
|
3894
|
-
}); }, [invalid, value, initValue, props, field]);
|
|
3895
|
-
var _e = useGridPopoverHook({
|
|
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;
|
|
3896
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 })) })));
|
|
3897
3923
|
};
|
|
3898
3924
|
|