@linzjs/step-ag-grid 2.2.2 → 2.3.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 +76 -31
- package/dist/index.js.map +1 -1
- package/dist/src/components/GridSubComponentTextArea.d.ts +7 -2
- package/dist/src/components/gridForm/GridFormDropDown.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +6 -7
- package/dist/src/components/gridForm/GridSubComponentProps.d.ts +6 -0
- package/dist/src/lui/TextInputFormatted.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +77 -32
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridSubComponentTextArea.tsx +42 -12
- package/src/components/gridForm/GridFormDropDown.tsx +1 -0
- package/src/components/gridForm/GridFormMultiSelect.tsx +50 -24
- package/src/components/gridForm/GridFormTextInput.tsx +6 -0
- package/src/components/gridForm/GridSubComponentProps.ts +6 -0
- package/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.ts +7 -14
- package/src/components/gridPopoverEdit/GridPopoverEditBearing.ts +6 -9
- package/src/components/gridPopoverEdit/GridPopoverEditDropDown.ts +8 -15
- package/src/components/gridPopoverEdit/GridPopoverMessage.ts +2 -4
- package/src/components/gridPopoverEdit/GridPopoverTextArea.ts +1 -8
- package/src/components/gridPopoverEdit/GridPopoverTextInput.ts +5 -12
- package/src/lui/TextInputFormatted.tsx +4 -1
- package/src/stories/grid/GridPopoutEditMultiSelect.stories.tsx +16 -7
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { GridSubComponentProps } from "./gridForm/GridSubComponentProps";
|
|
3
|
+
export interface GridSubComponentTextAreaProps extends GridSubComponentProps {
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
maxlength?: number;
|
|
7
|
+
width?: string | number;
|
|
8
|
+
validate: (value: string) => string | null;
|
|
4
9
|
}
|
|
5
10
|
export declare const GridSubComponentTextArea: (props: GridSubComponentTextAreaProps) => JSX.Element;
|
|
@@ -22,7 +22,7 @@ export declare const MenuHeaderItem: (title: string) => {
|
|
|
22
22
|
};
|
|
23
23
|
export declare type SelectOption<ValueType> = ValueType | FinalSelectOption<ValueType>;
|
|
24
24
|
export interface GridFormPopoutDropDownProps<RowType extends GridBaseRow, ValueType> extends CellEditorCommon {
|
|
25
|
-
className?: "GridPopoverEditDropDown-containerSmall" | "GridPopoverEditDropDown-containerMedium" | "GridPopoverEditDropDown-containerLarge" | string | undefined;
|
|
25
|
+
className?: "GridPopoverEditDropDown-containerSmall" | "GridPopoverEditDropDown-containerMedium" | "GridPopoverEditDropDown-containerLarge" | "GridPopoverEditDropDown-containerUnlimited" | string | undefined;
|
|
26
26
|
filtered?: "local" | "reload";
|
|
27
27
|
filterPlaceholder?: string;
|
|
28
28
|
onSelectedItem?: (props: GridPopoutEditDropDownSelectedItem<RowType, ValueType>) => Promise<void>;
|
|
@@ -5,20 +5,19 @@ import { CellEditorCommon } from "../GridCell";
|
|
|
5
5
|
interface MultiFinalSelectOption<ValueType> {
|
|
6
6
|
value: ValueType;
|
|
7
7
|
label?: JSX.Element | string;
|
|
8
|
-
subComponent?: (props: any
|
|
8
|
+
subComponent?: (props: any) => JSX.Element;
|
|
9
9
|
}
|
|
10
10
|
export declare type MultiSelectOption<ValueType> = ValueType | MultiFinalSelectOption<ValueType>;
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
values: Record<string, any>;
|
|
11
|
+
export interface SelectedOptionResult<ValueType> extends MultiFinalSelectOption<ValueType> {
|
|
12
|
+
subValue: any;
|
|
14
13
|
}
|
|
15
14
|
export interface GridFormMultiSelectProps<RowType extends GridBaseRow, ValueType> extends CellEditorCommon {
|
|
16
|
-
className?: "GridMultiSelect-containerSmall" | "GridMultiSelect-containerMedium" | "GridMultiSelect-containerLarge" | string | undefined;
|
|
15
|
+
className?: "GridMultiSelect-containerSmall" | "GridMultiSelect-containerMedium" | "GridMultiSelect-containerLarge" | "GridMultiSelect-containerUnlimited" | string | undefined;
|
|
17
16
|
filtered?: boolean;
|
|
18
17
|
filterPlaceholder?: string;
|
|
19
|
-
onSave?: (
|
|
18
|
+
onSave?: (selectedRows: RowType[], selectedOptions: SelectedOptionResult<ValueType>[]) => Promise<boolean>;
|
|
20
19
|
options: MultiSelectOption<ValueType>[] | ((selectedRows: RowType[]) => Promise<MultiSelectOption<ValueType>[]> | MultiSelectOption<ValueType>[]);
|
|
21
|
-
initialSelectedValues?: (selectedRows: RowType[]) => any[]
|
|
20
|
+
initialSelectedValues?: (selectedRows: RowType[]) => any[] | Record<string, any>;
|
|
22
21
|
}
|
|
23
22
|
export declare const GridFormMultiSelect: <RowType extends GridBaseRow, ValueType>(props: GridFormMultiSelectProps<RowType, ValueType>) => JSX.Element;
|
|
24
23
|
export {};
|
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo, useLayoutEffect, useEffect, createContext, memo, forwardRef, useRef, useContext, useState, useCallback, useReducer, cloneElement, useImperativeHandle, Fragment } from 'react';
|
|
2
2
|
import { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
|
|
3
|
-
import { findIndex, isEmpty, castArray, remove, flatten, delay, sortBy, last, difference, xorBy,
|
|
3
|
+
import { findIndex, isEmpty, castArray, remove, flatten, delay, sortBy, last, difference, xorBy, pickBy, pick } from 'lodash-es';
|
|
4
4
|
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
5
5
|
import { AgGridReact } from 'ag-grid-react';
|
|
6
6
|
import { LuiMiniSpinner, LuiIcon, LuiCheckboxInput, LuiButton } from '@linzjs/lui';
|
|
@@ -3000,27 +3000,39 @@ var GridFormDropDown = function (_props) {
|
|
|
3000
3000
|
|
|
3001
3001
|
var GridFormMultiSelect = function (props) {
|
|
3002
3002
|
var selectedRows = props.selectedRows;
|
|
3003
|
-
var
|
|
3004
|
-
var
|
|
3003
|
+
var initialiseValues = useMemo(function () { return props.initialSelectedValues && props.initialSelectedValues(selectedRows); }, [props, selectedRows]);
|
|
3004
|
+
var subComponentIsValid = useRef({});
|
|
3005
|
+
var _a = useState(initialiseValues && !Array.isArray(initialiseValues)
|
|
3006
|
+
? pickBy(initialiseValues, function (value) { return typeof value !== "boolean"; })
|
|
3007
|
+
: {}), subSelectedValues = _a[0], setSubSelectedValues = _a[1];
|
|
3008
|
+
var _b = useState(function () {
|
|
3009
|
+
return initialiseValues ? (Array.isArray(initialiseValues) ? initialiseValues : Object.keys(initialiseValues)) : [];
|
|
3010
|
+
}), selectedValues = _b[0], setSelectedValues = _b[1];
|
|
3011
|
+
var _c = useState(""), filter = _c[0], setFilter = _c[1];
|
|
3012
|
+
var _d = useState([]), filteredValues = _d[0], setFilteredValues = _d[1];
|
|
3005
3013
|
var optionsInitialising = useRef(false);
|
|
3006
|
-
var
|
|
3007
|
-
var subSelectedValues = useRef({});
|
|
3008
|
-
var _d = useState(function () {
|
|
3009
|
-
return props.initialSelectedValues ? props.initialSelectedValues(selectedRows) : [];
|
|
3010
|
-
}), selectedValues = _d[0], setSelectedValues = _d[1];
|
|
3014
|
+
var _e = useState(), options = _e[0], setOptions = _e[1];
|
|
3011
3015
|
var save = useCallback(function (selectedRows) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3012
|
-
var
|
|
3013
|
-
|
|
3014
|
-
|
|
3016
|
+
var validations, notValid, selectedOptions, selectedResults;
|
|
3017
|
+
var _a;
|
|
3018
|
+
return __generator(this, function (_b) {
|
|
3019
|
+
switch (_b.label) {
|
|
3015
3020
|
case 0:
|
|
3016
|
-
values = fromPairs(selectedValues.map(function (value) { var _a; return [value, (_a = subSelectedValues.current[value]) !== null && _a !== void 0 ? _a : true]; }));
|
|
3017
3021
|
if (!props.onSave) return [3 /*break*/, 2];
|
|
3018
|
-
|
|
3019
|
-
|
|
3022
|
+
validations = pick(subComponentIsValid.current, selectedValues);
|
|
3023
|
+
notValid = Object.values(validations).some(function (v) { return !v; });
|
|
3024
|
+
if (notValid)
|
|
3025
|
+
return [2 /*return*/, false];
|
|
3026
|
+
selectedOptions = (_a = selectedValues.map(function (row) { return (options !== null && options !== void 0 ? options : []).find(function (opt) { return opt.value == row; }); })) !== null && _a !== void 0 ? _a : [];
|
|
3027
|
+
selectedResults = selectedOptions.map(function (selectedOption) {
|
|
3028
|
+
return (__assign(__assign({}, selectedOption), { subValue: subSelectedValues["".concat(selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value)] }));
|
|
3029
|
+
});
|
|
3030
|
+
return [4 /*yield*/, props.onSave(selectedRows, selectedResults)];
|
|
3031
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
3020
3032
|
case 2: return [2 /*return*/, true];
|
|
3021
3033
|
}
|
|
3022
3034
|
});
|
|
3023
|
-
}); }, [props, selectedValues]);
|
|
3035
|
+
}); }, [options, props, selectedValues, subSelectedValues]);
|
|
3024
3036
|
// Load up options list if it's async function
|
|
3025
3037
|
useEffect(function () {
|
|
3026
3038
|
var _a;
|
|
@@ -3073,7 +3085,7 @@ var GridFormMultiSelect = function (props) {
|
|
|
3073
3085
|
})
|
|
3074
3086
|
.filter(function (r) { return r !== undefined; }));
|
|
3075
3087
|
}, [props.filtered, filter, options]);
|
|
3076
|
-
var
|
|
3088
|
+
var _f = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _f.popoverWrapper, triggerSave = _f.triggerSave;
|
|
3077
3089
|
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) {
|
|
3078
3090
|
var _b;
|
|
3079
3091
|
var ref = _a.ref;
|
|
@@ -3115,16 +3127,23 @@ var GridFormMultiSelect = function (props) {
|
|
|
3115
3127
|
} }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
|
|
3116
3128
|
return item.subComponent &&
|
|
3117
3129
|
item.subComponent({
|
|
3130
|
+
ref: ref,
|
|
3131
|
+
value: subSelectedValues["".concat(item.value)],
|
|
3118
3132
|
setValue: function (value) {
|
|
3119
|
-
subSelectedValues.
|
|
3120
|
-
|
|
3121
|
-
|
|
3133
|
+
subSelectedValues["".concat(item.value)] = value;
|
|
3134
|
+
setSubSelectedValues(__assign({}, subSelectedValues));
|
|
3135
|
+
},
|
|
3136
|
+
setValid: function (valid) {
|
|
3137
|
+
subComponentIsValid.current["".concat(item.value)] = valid;
|
|
3138
|
+
},
|
|
3139
|
+
triggerSave: triggerSave
|
|
3140
|
+
});
|
|
3122
3141
|
} }), "".concat(item.value, "_subcomponent")))] }, "".concat(index)));
|
|
3123
3142
|
}) }))] }) })));
|
|
3124
3143
|
};
|
|
3125
3144
|
|
|
3126
3145
|
var GridPopoutEditMultiSelect = function (colDef, props) {
|
|
3127
|
-
return GridCell(
|
|
3146
|
+
return GridCell(colDef, __assign(__assign({ editor: GridFormMultiSelect }, props), { editorParams: __assign({ className: "GridMultiSelect-containerMedium" }, props.editorParams) }));
|
|
3128
3147
|
};
|
|
3129
3148
|
|
|
3130
3149
|
var css_248z$3 = ".GridPopoutMenu-burger{cursor:pointer}.GridPopoutMenu-burger svg{fill:#007198}.GridPopoutMenu-burgerDisabled svg{fill:#989189}";
|
|
@@ -3298,7 +3317,7 @@ var css_248z$1 = ".LuiTextInput{margin-bottom:0}.LuiTextInput-formatted{color:#b
|
|
|
3298
3317
|
styleInject(css_248z$1);
|
|
3299
3318
|
|
|
3300
3319
|
var TextInputFormatted = function (props) {
|
|
3301
|
-
return (jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsx("input", __assign({ type: "text", className: "LuiTextInput-input", min: "0",
|
|
3320
|
+
return (jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsx("input", __assign({ type: "text", className: "LuiTextInput-input", min: "0", spellCheck: true, defaultValue: props.value, onChange: props.onChange }, props.inputProps)), jsx("span", __assign({ className: "LuiTextInput-formatted" }, { children: props.formatted }))] })), props.error && (jsxs("span", __assign({ className: "LuiTextInput-error" }, { children: [jsx(LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }), props.error] }))), props.warning && (jsxs("span", __assign({ className: "LuiTextInput-warning" }, { children: [jsx(LuiIcon, { alt: "warning", name: "ic_warning", className: "LuiTextInput-warning-icon", size: "sm", status: "warning" }), props.warning] })))] })));
|
|
3302
3321
|
};
|
|
3303
3322
|
|
|
3304
3323
|
var GridFormEditBearing = function (_props) {
|
|
@@ -3380,7 +3399,7 @@ var GridPopoverEditBearingCorrection = function (colDef, props) {
|
|
|
3380
3399
|
};
|
|
3381
3400
|
|
|
3382
3401
|
var GridPopoverEditDropDown = function (colDef, props) {
|
|
3383
|
-
return GridCell(
|
|
3402
|
+
return GridCell(colDef, __assign(__assign({ editor: GridFormDropDown }, props), { editorParams: __assign({
|
|
3384
3403
|
// Defaults to medium size container
|
|
3385
3404
|
className: "GridPopoverEditDropDown-containerMedium" }, props.editorParams) }));
|
|
3386
3405
|
};
|
|
@@ -3408,7 +3427,7 @@ var GridFormMessage = function (_props) {
|
|
|
3408
3427
|
};
|
|
3409
3428
|
|
|
3410
3429
|
var GridPopoverMessage = function (colDef, props) {
|
|
3411
|
-
return GridCell(__assign(__assign({
|
|
3430
|
+
return GridCell(__assign(__assign({}, colDef), { cellRendererParams: __assign({ singleClickEdit: true }, colDef.cellRendererParams) }), __assign({ editor: GridFormMessage }, props));
|
|
3412
3431
|
};
|
|
3413
3432
|
|
|
3414
3433
|
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
@@ -3529,9 +3548,7 @@ var GridFormTextArea = function (_props) {
|
|
|
3529
3548
|
return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_b = props.width) !== null && _b !== void 0 ? _b : 240 } }, { children: jsx(TextAreaInput, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), inputProps: { placeholder: props.placeholder } }) })));
|
|
3530
3549
|
};
|
|
3531
3550
|
|
|
3532
|
-
var GridPopoverTextArea = function (colDef, params) {
|
|
3533
|
-
return GridCell(__assign({ maxWidth: 260 }, colDef), __assign({ editor: GridFormTextArea }, params));
|
|
3534
|
-
};
|
|
3551
|
+
var GridPopoverTextArea = function (colDef, params) { return GridCell(colDef, __assign({ editor: GridFormTextArea }, params)); };
|
|
3535
3552
|
|
|
3536
3553
|
var GridFormTextInput = function (_props) {
|
|
3537
3554
|
var _a;
|
|
@@ -3576,7 +3593,12 @@ var GridFormTextInput = function (_props) {
|
|
|
3576
3593
|
});
|
|
3577
3594
|
}); }, [invalid, value, initValue, props]);
|
|
3578
3595
|
var _c = useGridPopoverHook({ className: props.className, save: save }), popoverWrapper = _c.popoverWrapper, triggerSave = _c.triggerSave;
|
|
3579
|
-
return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 }, className: "FormTest" }, { children: jsx(TextInputFormatted, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units,
|
|
3596
|
+
return popoverWrapper(jsx("div", __assign({ style: { display: "flex", flexDirection: "row", width: (_a = props.width) !== null && _a !== void 0 ? _a : 240 }, className: "FormTest" }, { children: jsx(TextInputFormatted, { value: value, onChange: function (e) { return setValue(e.target.value); }, error: invalid(), formatted: props.units, onMouseEnter: function (e) {
|
|
3597
|
+
if (document.activeElement != e.currentTarget) {
|
|
3598
|
+
e.currentTarget.focus();
|
|
3599
|
+
e.currentTarget.selectionStart = e.currentTarget.value.length;
|
|
3600
|
+
}
|
|
3601
|
+
}, inputProps: {
|
|
3580
3602
|
style: { width: "100%" },
|
|
3581
3603
|
placeholder: props.placeholder,
|
|
3582
3604
|
onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
@@ -3586,15 +3608,38 @@ var GridFormTextInput = function (_props) {
|
|
|
3586
3608
|
};
|
|
3587
3609
|
|
|
3588
3610
|
var GridPopoverTextInput = function (colDef, params) {
|
|
3589
|
-
return GridCell(
|
|
3611
|
+
return GridCell(colDef, __assign({ editor: GridFormTextInput }, params));
|
|
3590
3612
|
};
|
|
3591
3613
|
|
|
3592
3614
|
var GridSubComponentTextArea = function (props) {
|
|
3593
|
-
var
|
|
3615
|
+
var value = props.value, setValue = props.setValue, setValid = props.setValid, triggerSave = props.triggerSave;
|
|
3616
|
+
var validate = useCallback(function (value) {
|
|
3617
|
+
if (props.required && value.length === 0) {
|
|
3618
|
+
return "Some text is required";
|
|
3619
|
+
}
|
|
3620
|
+
if (props.maxlength && value.length > props.maxlength) {
|
|
3621
|
+
return "Text must be no longer than ".concat(props.maxlength, " characters");
|
|
3622
|
+
}
|
|
3623
|
+
if (props.validate) {
|
|
3624
|
+
return props.validate(value);
|
|
3625
|
+
}
|
|
3626
|
+
return null;
|
|
3627
|
+
}, [props]);
|
|
3594
3628
|
useEffect(function () {
|
|
3595
|
-
|
|
3596
|
-
}, [
|
|
3597
|
-
return (jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsx(
|
|
3629
|
+
setValid(validate(value) == null);
|
|
3630
|
+
}, [setValid, validate, value]);
|
|
3631
|
+
return (jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsx(TextInputFormatted, { className: "free-text-input", value: value, onMouseEnter: function (e) {
|
|
3632
|
+
if (document.activeElement != e.currentTarget) {
|
|
3633
|
+
e.currentTarget.focus();
|
|
3634
|
+
e.currentTarget.selectionStart = e.currentTarget.value.length;
|
|
3635
|
+
}
|
|
3636
|
+
}, onChange: function (e) { return setValue(e.target.value); }, error: validate(value), inputProps: {
|
|
3637
|
+
autoFocus: true,
|
|
3638
|
+
placeholder: props.placeholder,
|
|
3639
|
+
onKeyDown: function (e) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
3640
|
+
return [2 /*return*/, e.key === "Enter" && triggerSave().then()];
|
|
3641
|
+
}); }); }
|
|
3642
|
+
} }) })));
|
|
3598
3643
|
};
|
|
3599
3644
|
|
|
3600
3645
|
var css_248z = ".ActionButton{align-items:center;display:flex}.ActionButton .LuiIcon{margin:0 4px!important}.ActionButton-minimalArea{position:relative}.ActionButton-minimalAreaDisplay{position:absolute}.ActionButton-minimalAreaExpand{visibility:hidden}.ActionButton-inProgress{background-color:#e2f3f7!important;color:#007198!important;cursor:progress}.ActionButton-inProgress svg *{fill:#0000!important}";
|