@bluemarble/bm-components 0.0.25 → 0.0.28
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/esm/index.js +14 -420
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/Input/index.d.ts +1 -0
- package/dist/esm/types/components/LargeButton/index.d.ts +1 -1
- package/dist/esm/types/components/TabPanel/index.d.ts +11 -0
- package/dist/esm/types/components/index.d.ts +1 -3
- package/dist/index.d.ts +12 -86
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import React__default, { memo, useState, useRef, useMemo, useEffect, useCallback } from 'react';
|
|
3
|
-
import { TableHead, TableRow, TableCell, TableSortLabel, Chip, Tooltip, IconButton, Paper, LinearProgress, TableContainer, Table, TableBody, TablePagination, Popover, Box as Box$2, Typography, Autocomplete as Autocomplete$1, TextField, Button, FormControl, Select as Select$1, InputLabel, FormControlLabel, Checkbox as Checkbox$1, Switch as Switch$1, FormLabel, RadioGroup, Radio as Radio$1, CircularProgress
|
|
3
|
+
import { TableHead, TableRow, TableCell, TableSortLabel, Chip, Tooltip, IconButton, Paper, LinearProgress, TableContainer, Table, TableBody, TablePagination, Popover, Box as Box$2, Typography, Autocomplete as Autocomplete$1, TextField, Button, FormControl, Select as Select$1, InputLabel, FormControlLabel, Checkbox as Checkbox$1, Switch as Switch$1, FormLabel, RadioGroup, Radio as Radio$1, CircularProgress } from '@mui/material';
|
|
4
4
|
import emStyled from '@emotion/styled';
|
|
5
5
|
import '@emotion/react';
|
|
6
6
|
import { Field, useField } from 'formik';
|
|
7
|
-
import { red } from '@mui/material/colors';
|
|
8
7
|
|
|
9
8
|
const GridHeader = ({ setOrder, setOrderBy, order, orderBy, titles = [], }) => {
|
|
10
9
|
function onRequestSort(title) {
|
|
@@ -3834,16 +3833,6 @@ function __rest(s, e) {
|
|
|
3834
3833
|
t[p[i]] = s[p[i]];
|
|
3835
3834
|
}
|
|
3836
3835
|
return t;
|
|
3837
|
-
}
|
|
3838
|
-
|
|
3839
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
3840
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3841
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3842
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3843
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3844
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3845
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3846
|
-
});
|
|
3847
3836
|
}
|
|
3848
3837
|
|
|
3849
3838
|
const CustomTableCell = (_a) => {
|
|
@@ -14781,10 +14770,10 @@ const BaseInput$1 = (props) => {
|
|
|
14781
14770
|
return React__default.createElement(TextField, Object.assign({ fullWidth: true }, props));
|
|
14782
14771
|
};
|
|
14783
14772
|
const FormikInput = (_a) => {
|
|
14784
|
-
var { name } = _a, rest = __rest(_a, ["name"]);
|
|
14773
|
+
var { name, shrink } = _a, rest = __rest(_a, ["name", "shrink"]);
|
|
14785
14774
|
return (React__default.createElement(Field, { name: name }, (_a) => {
|
|
14786
14775
|
var _b = _a.field, { value } = _b, field = __rest(_b, ["value"]);
|
|
14787
|
-
return (React__default.createElement(BaseInput$1, Object.assign({}, field, rest, {
|
|
14776
|
+
return (React__default.createElement(BaseInput$1, Object.assign({ defaultValue: value }, field, rest, { InputLabelProps: Object.assign({ shrink }, rest.InputLabelProps) })));
|
|
14788
14777
|
}));
|
|
14789
14778
|
};
|
|
14790
14779
|
|
|
@@ -14978,415 +14967,20 @@ const FormikRadio = (_a) => {
|
|
|
14978
14967
|
};
|
|
14979
14968
|
|
|
14980
14969
|
const LargeButton = (_a) => {
|
|
14981
|
-
var { loading, children, CircularProgressProps } = _a, rest = __rest(_a, ["loading", "children", "CircularProgressProps"]);
|
|
14982
|
-
return (React__default.createElement(Button, Object.assign({ variant: "contained", fullWidth: true, sx: Object.assign({ color: "#fff", fontWeight: "bold" },
|
|
14983
|
-
};
|
|
14984
|
-
|
|
14985
|
-
/* eslint no-undef: "off" */
|
|
14986
|
-
function useEvent(event, handler, passive = false) {
|
|
14987
|
-
useEffect(() => {
|
|
14988
|
-
window.addEventListener(event, handler, passive);
|
|
14989
|
-
return function cleanup() {
|
|
14990
|
-
window.removeEventListener(event, handler);
|
|
14991
|
-
};
|
|
14992
|
-
});
|
|
14993
|
-
}
|
|
14994
|
-
|
|
14995
|
-
const InputAutocompleteCell = ({ options, label, value, onInputChange, currentValue, defaultValue: ExternalDefaultValue, }) => {
|
|
14996
|
-
const defaultValue = options.find((option) => String(option[value]) ===
|
|
14997
|
-
(String(currentValue) || String(ExternalDefaultValue)));
|
|
14998
|
-
const onChange = (_, newValue, reason) => {
|
|
14999
|
-
if (reason === "clear")
|
|
15000
|
-
return;
|
|
15001
|
-
onInputChange(newValue[value]);
|
|
15002
|
-
};
|
|
15003
|
-
return (React__default.createElement(Autocomplete$1, { defaultValue: defaultValue, options: options, onChange: onChange, getOptionLabel: (option) => option[label], renderInput: (params) => React__default.createElement(RenderInput, Object.assign({}, params)), isOptionEqualToValue: (a, b) => (a === null || a === void 0 ? void 0 : a[value]) === (b === null || b === void 0 ? void 0 : b[value]) }));
|
|
15004
|
-
};
|
|
15005
|
-
const RenderInput = (params) => {
|
|
15006
|
-
return (React__default.createElement(TextField, Object.assign({}, params, { autoFocus: true, focused: true, sx: {
|
|
15007
|
-
width: "100%",
|
|
15008
|
-
height: "100%",
|
|
15009
|
-
position: "absolute",
|
|
15010
|
-
left: 0,
|
|
15011
|
-
top: 0,
|
|
15012
|
-
borderRadius: 0,
|
|
15013
|
-
color: "primary.main",
|
|
15014
|
-
p: 0,
|
|
15015
|
-
}, inputProps: Object.assign(Object.assign({}, params.inputProps), { sx: Object.assign(Object.assign({}, params.inputProps.sx), { width: "100%", height: "100%", p: "0!important", pl: 2 }) }), InputProps: Object.assign(Object.assign({}, params.InputProps), { sx: Object.assign(Object.assign({}, params.inputProps.sx), { height: "100%", borderRadius: 0 }) }) })));
|
|
15016
|
-
};
|
|
15017
|
-
|
|
15018
|
-
const InputTextCell = ({ defaultValue, currentValue, inputProps = {}, onInputChange, }) => {
|
|
15019
|
-
const { onDefaultValue } = inputProps, rest = __rest(inputProps, ["onDefaultValue"]);
|
|
15020
|
-
const formattedDefaultValue = onDefaultValue
|
|
15021
|
-
? onDefaultValue(currentValue || defaultValue)
|
|
15022
|
-
: currentValue || defaultValue;
|
|
15023
|
-
return (React__default.createElement(TextField, Object.assign({ focused: true, autoFocus: true, onChange: ({ target }) => onInputChange(target.value), sx: {
|
|
15024
|
-
width: "100%",
|
|
15025
|
-
height: "100%",
|
|
15026
|
-
position: "absolute",
|
|
15027
|
-
left: 0,
|
|
15028
|
-
top: 0,
|
|
15029
|
-
borderRadius: 0,
|
|
15030
|
-
color: "primary.main",
|
|
15031
|
-
}, InputProps: { sx: { width: "100%", height: "100%", borderRadius: 0 } }, inputProps: {
|
|
15032
|
-
sx: { width: "100%", height: "100%", pl: 1, borderRadius: 0 },
|
|
15033
|
-
}, defaultValue: formattedDefaultValue }, rest)));
|
|
15034
|
-
};
|
|
15035
|
-
|
|
15036
|
-
const InputSelectCell = ({ options, label, value, setCanSave, onInputChange, currentValue, }) => {
|
|
15037
|
-
var _a;
|
|
15038
|
-
const defaultValue = (_a = options.find((option) => option[value] === currentValue)) === null || _a === void 0 ? void 0 : _a[value];
|
|
15039
|
-
const onChange = (_, { props }) => {
|
|
15040
|
-
onInputChange(props.value);
|
|
15041
|
-
};
|
|
15042
|
-
return (React__default.createElement(TextField, { defaultValue: defaultValue, autoFocus: true, focused: true, onChange: onChange, sx: {
|
|
15043
|
-
width: "100%",
|
|
15044
|
-
height: "100%",
|
|
15045
|
-
position: "absolute",
|
|
15046
|
-
left: 0,
|
|
15047
|
-
top: 0,
|
|
15048
|
-
borderRadius: 0,
|
|
15049
|
-
color: "primary.main",
|
|
15050
|
-
}, inputProps: {
|
|
15051
|
-
sx: { width: "100%", height: "100%", p: 0, pl: 2 },
|
|
15052
|
-
}, InputProps: {
|
|
15053
|
-
sx: { height: "100%", borderRadius: 0 },
|
|
15054
|
-
}, SelectProps: {
|
|
15055
|
-
// onOpen: () => setCanSave(false),
|
|
15056
|
-
// onClose: () => setCanSave(true)
|
|
15057
|
-
}, select: true }, options.map((option) => (React__default.createElement(MenuItem, { key: option[value], value: option[value] }, option[label])))));
|
|
15058
|
-
};
|
|
15059
|
-
|
|
15060
|
-
const InputCell = (props) => {
|
|
15061
|
-
if (props.type === "select" && props.select)
|
|
15062
|
-
return (React__default.createElement(InputSelectCell, Object.assign({}, props.select, { setCanSave: props.setCanSave, onInputChange: props.onInputChange, currentValue: props.currentValue })));
|
|
15063
|
-
else if (props.type === "autocomplete")
|
|
15064
|
-
return (React__default.createElement(InputAutocompleteCell, Object.assign({}, props.select, { setCanSave: props.setCanSave, onInputChange: props.onInputChange, defaultValue: props.defaultValue, currentValue: props.currentValue })));
|
|
15065
|
-
else {
|
|
15066
|
-
return React__default.createElement(InputTextCell, Object.assign({}, props));
|
|
15067
|
-
}
|
|
15068
|
-
};
|
|
15069
|
-
|
|
15070
|
-
const GridCell = ({ value, focusedIndex, canEditTable, columnIndex, rowIndex, isEditing, onInputChange, bordered, onClick, onDoubleClick, setCanSave, tableCellProps, validationErrors, column, }) => {
|
|
15071
|
-
var _a;
|
|
15072
|
-
const formattedValue = (column === null || column === void 0 ? void 0 : column.formatLabelValue)
|
|
15073
|
-
? column === null || column === void 0 ? void 0 : column.formatLabelValue(value)
|
|
15074
|
-
: value;
|
|
15075
|
-
const isFocused = focusedIndex.y === rowIndex && focusedIndex.x === columnIndex;
|
|
15076
|
-
const canEdit = isEditing && isFocused;
|
|
15077
|
-
const withOthersStyles = () => {
|
|
15078
|
-
let result = {};
|
|
15079
|
-
if (bordered) {
|
|
15080
|
-
result = {
|
|
15081
|
-
border: "1px solid",
|
|
15082
|
-
borderColor: "divider",
|
|
15083
|
-
};
|
|
15084
|
-
}
|
|
15085
|
-
if (isFocused && !canEdit && canEditTable) {
|
|
15086
|
-
result = Object.assign(Object.assign({}, result), { outline: "2px solid", color: "primary.main", outlineColor: "inherit" });
|
|
15087
|
-
}
|
|
15088
|
-
if (canEdit) {
|
|
15089
|
-
result = Object.assign(Object.assign({}, result), { p: 0 });
|
|
15090
|
-
}
|
|
15091
|
-
if (validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.includes(column === null || column === void 0 ? void 0 : column.name)) {
|
|
15092
|
-
result = {
|
|
15093
|
-
bgcolor: red[100],
|
|
15094
|
-
};
|
|
15095
|
-
}
|
|
15096
|
-
return result;
|
|
15097
|
-
};
|
|
15098
|
-
return (React__default.createElement(TableCell, Object.assign({ onClick: onClick, onDoubleClick: onDoubleClick }, tableCellProps, { sx: Object.assign(Object.assign({ position: "relative" }, tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx), withOthersStyles()) }), canEdit ? (React__default.createElement(InputCell, { select: column === null || column === void 0 ? void 0 : column.select, type: column === null || column === void 0 ? void 0 : column.type, inputProps: column === null || column === void 0 ? void 0 : column.inputProps, defaultValue: (_a = column === null || column === void 0 ? void 0 : column.newRow) === null || _a === void 0 ? void 0 : _a.defaultValue, currentValue: value, onInputChange: onInputChange, setCanSave: setCanSave })) : (React__default.createElement(Typography, { variant: "body2", color: "initial" }, formattedValue))));
|
|
15099
|
-
};
|
|
15100
|
-
|
|
15101
|
-
const NewRow = ({ columns, hasCheckbox, maxPositions, onSaveNewRow, }) => {
|
|
15102
|
-
const [focusedIndex, setFocusedIndex] = useState({ x: 0, y: 0 });
|
|
15103
|
-
const newRowValues = useRef({});
|
|
15104
|
-
const [validationError, setValidationError] = useState([]);
|
|
15105
|
-
const onInputChange = (prop, value) => {
|
|
15106
|
-
newRowValues.current = Object.assign(Object.assign({}, newRowValues.current), { [prop]: value });
|
|
15107
|
-
};
|
|
15108
|
-
const getDefaultRowValues = () => {
|
|
15109
|
-
const defaultNewRow = {};
|
|
15110
|
-
columns.forEach((column) => {
|
|
15111
|
-
var _a;
|
|
15112
|
-
defaultNewRow[column.name] =
|
|
15113
|
-
((_a = column === null || column === void 0 ? void 0 : column.newRow) === null || _a === void 0 ? void 0 : _a.defaultValue) || undefined;
|
|
15114
|
-
});
|
|
15115
|
-
return defaultNewRow;
|
|
15116
|
-
};
|
|
15117
|
-
const saveRow = () => {
|
|
15118
|
-
const requiredColumns = columns.filter((column) => column.required);
|
|
15119
|
-
let isRequiredsFilled = true;
|
|
15120
|
-
requiredColumns.forEach((column) => {
|
|
15121
|
-
var _a, _b, _c;
|
|
15122
|
-
if (!((_a = newRowValues.current) === null || _a === void 0 ? void 0 : _a[column.name]) ||
|
|
15123
|
-
((_c = (_b = newRowValues.current) === null || _b === void 0 ? void 0 : _b[column.name]) === null || _c === void 0 ? void 0 : _c.trim()) === "")
|
|
15124
|
-
isRequiredsFilled = false;
|
|
15125
|
-
});
|
|
15126
|
-
if (!isRequiredsFilled) {
|
|
15127
|
-
setValidationError(requiredColumns.map((column) => column === null || column === void 0 ? void 0 : column.name));
|
|
15128
|
-
return;
|
|
15129
|
-
}
|
|
15130
|
-
if (onSaveNewRow)
|
|
15131
|
-
onSaveNewRow(newRowValues.current);
|
|
15132
|
-
newRowValues.current = getDefaultRowValues();
|
|
15133
|
-
setFocusedIndex({ x: 0, y: 0 });
|
|
15134
|
-
setValidationError([]);
|
|
15135
|
-
};
|
|
15136
|
-
const onKeyDown = (event) => {
|
|
15137
|
-
const canMoveRight = focusedIndex.x + 1 <= maxPositions.x;
|
|
15138
|
-
const canMoveLeft = focusedIndex.x - 1 >= 0;
|
|
15139
|
-
const { key, shiftKey } = event;
|
|
15140
|
-
if (key === "Enter") {
|
|
15141
|
-
event.preventDefault();
|
|
15142
|
-
saveRow();
|
|
15143
|
-
}
|
|
15144
|
-
else if (shiftKey && key === "Tab") {
|
|
15145
|
-
event.preventDefault();
|
|
15146
|
-
setFocusedIndex({
|
|
15147
|
-
y: 0,
|
|
15148
|
-
x: canMoveLeft ? focusedIndex.x - 1 : focusedIndex.x,
|
|
15149
|
-
});
|
|
15150
|
-
}
|
|
15151
|
-
else if (key === "Tab") {
|
|
15152
|
-
event.preventDefault();
|
|
15153
|
-
setFocusedIndex({
|
|
15154
|
-
y: 0,
|
|
15155
|
-
x: canMoveRight ? focusedIndex.x + 1 : focusedIndex.x,
|
|
15156
|
-
});
|
|
15157
|
-
}
|
|
15158
|
-
};
|
|
15159
|
-
useEffect(() => {
|
|
15160
|
-
newRowValues.current = getDefaultRowValues();
|
|
15161
|
-
}, []);
|
|
15162
|
-
return (React__default.createElement(TableRow, { onKeyDown: onKeyDown },
|
|
15163
|
-
hasCheckbox && React__default.createElement(TableCell, { padding: "checkbox" }),
|
|
15164
|
-
columns
|
|
15165
|
-
.filter((columns) => columns.visible !== false)
|
|
15166
|
-
.map((column, columnIndex) => {
|
|
15167
|
-
var _a, _b;
|
|
15168
|
-
const key = String(column.name || column.label || columnIndex);
|
|
15169
|
-
return (React__default.createElement(GridCell, { canEditTable: true, bordered: true, key: key, isEditing: true, focusedIndex: focusedIndex, rowIndex: 0, columnIndex: columnIndex, value: ((_a = newRowValues.current) === null || _a === void 0 ? void 0 : _a[column.name]) ||
|
|
15170
|
-
((_b = column === null || column === void 0 ? void 0 : column.newRow) === null || _b === void 0 ? void 0 : _b.defaultValue), onInputChange: (value) => onInputChange(column.name, value), column: column, onClick: () => setFocusedIndex({ x: columnIndex, y: 0 }), onDoubleClick: () => { }, setCanSave: () => { }, tableCellProps: { sx: { height: 31 } }, validationErrors: validationError }));
|
|
15171
|
-
})));
|
|
14970
|
+
var { loading, children, CircularProgressProps, sx } = _a, rest = __rest(_a, ["loading", "children", "CircularProgressProps", "sx"]);
|
|
14971
|
+
return (React__default.createElement(Button, Object.assign({ variant: "contained", fullWidth: true, sx: Object.assign({ color: "#fff", fontWeight: "bold" }, sx), disabled: rest.disabled || loading }, rest), loading ? (React__default.createElement(CircularProgress, Object.assign({ size: 25, color: "inherit" }, CircularProgressProps))) : (children)));
|
|
15172
14972
|
};
|
|
15173
14973
|
|
|
15174
|
-
function
|
|
15175
|
-
var _a;
|
|
15176
|
-
const [canSave, setCanSave] = useState(true);
|
|
15177
|
-
const checkboxOffset = checkbox ? 1 : 0;
|
|
15178
|
-
const inputValue = useRef("");
|
|
15179
|
-
const maxPositions = {
|
|
15180
|
-
x: columns.length - 1 - checkboxOffset,
|
|
15181
|
-
y: data.length - 1,
|
|
15182
|
-
};
|
|
15183
|
-
const focusedRow = data === null || data === void 0 ? void 0 : data[focusedIndex === null || focusedIndex === void 0 ? void 0 : focusedIndex.y];
|
|
15184
|
-
const focusedProp = (_a = columns === null || columns === void 0 ? void 0 : columns[(focusedIndex === null || focusedIndex === void 0 ? void 0 : focusedIndex.x) + checkboxOffset]) === null || _a === void 0 ? void 0 : _a.name;
|
|
15185
|
-
const gridRef = useRef(null);
|
|
15186
|
-
const [isShiftPressed, setIsShiftPressed] = useState(false);
|
|
15187
|
-
const onInputChange = (value) => {
|
|
15188
|
-
inputValue.current = value;
|
|
15189
|
-
};
|
|
15190
|
-
const moveIndexPosition = (x = 0, y = 0, ignoreEditing) => {
|
|
15191
|
-
let xPosition = focusedIndex.x + x;
|
|
15192
|
-
let yPosition = focusedIndex.y + y;
|
|
15193
|
-
if (isEditing && !ignoreEditing)
|
|
15194
|
-
return;
|
|
15195
|
-
if (xPosition > maxPositions.x && yPosition < maxPositions.y) {
|
|
15196
|
-
xPosition = 0;
|
|
15197
|
-
yPosition += 1;
|
|
15198
|
-
}
|
|
15199
|
-
else if (xPosition < 0 && yPosition > 0) {
|
|
15200
|
-
xPosition = maxPositions.x;
|
|
15201
|
-
yPosition -= 1;
|
|
15202
|
-
}
|
|
15203
|
-
else if (xPosition < 0) {
|
|
15204
|
-
xPosition = 0;
|
|
15205
|
-
}
|
|
15206
|
-
else if (yPosition < 0) {
|
|
15207
|
-
yPosition = 0;
|
|
15208
|
-
}
|
|
15209
|
-
else if (xPosition > maxPositions.x) {
|
|
15210
|
-
xPosition = maxPositions.x;
|
|
15211
|
-
}
|
|
15212
|
-
else if (yPosition > maxPositions.y) {
|
|
15213
|
-
yPosition = maxPositions.y;
|
|
15214
|
-
}
|
|
15215
|
-
setFocusedIndex({
|
|
15216
|
-
x: xPosition,
|
|
15217
|
-
y: yPosition,
|
|
15218
|
-
});
|
|
15219
|
-
};
|
|
15220
|
-
const handleSaveChanges = () => __awaiter(this, void 0, void 0, function* () {
|
|
15221
|
-
const previousValue = focusedRow[focusedProp];
|
|
15222
|
-
if (previousValue !== inputValue.current)
|
|
15223
|
-
onSave(updateRowData(), {
|
|
15224
|
-
prop: focusedProp,
|
|
15225
|
-
newValue: inputValue.current,
|
|
15226
|
-
index: focusedIndex.y,
|
|
15227
|
-
});
|
|
15228
|
-
});
|
|
15229
|
-
const updateRowData = () => {
|
|
15230
|
-
const updatedRow = Object.assign(Object.assign({}, focusedRow), { [focusedProp]: inputValue.current });
|
|
15231
|
-
return updatedRow;
|
|
15232
|
-
};
|
|
15233
|
-
const startEditOrSave = () => {
|
|
15234
|
-
if (!canSave)
|
|
15235
|
-
return;
|
|
15236
|
-
if (!isEditing) {
|
|
15237
|
-
setIsEditing(true);
|
|
15238
|
-
}
|
|
15239
|
-
else {
|
|
15240
|
-
handleSaveChanges();
|
|
15241
|
-
setIsEditing(false);
|
|
15242
|
-
}
|
|
15243
|
-
};
|
|
15244
|
-
const saveAndMove = (event) => {
|
|
15245
|
-
event.preventDefault();
|
|
15246
|
-
if (isEditing)
|
|
15247
|
-
handleSaveChanges();
|
|
15248
|
-
moveIndexPosition(1, 0, true);
|
|
15249
|
-
};
|
|
15250
|
-
const keyMaps = {
|
|
15251
|
-
ArrowRight: (event) => moveIndexPosition(1, 0),
|
|
15252
|
-
ArrowLeft: (event) => moveIndexPosition(-1, 0),
|
|
15253
|
-
ArrowDown: (event) => moveIndexPosition(0, 1),
|
|
15254
|
-
ArrowUp: (event) => moveIndexPosition(0, -1),
|
|
15255
|
-
Enter: (event) => startEditOrSave(),
|
|
15256
|
-
Tab: (event) => saveAndMove(event),
|
|
15257
|
-
Escape: (event) => {
|
|
15258
|
-
event.preventDefault();
|
|
15259
|
-
setIsEditing(false);
|
|
15260
|
-
if (!isEditing)
|
|
15261
|
-
setCanEditTable(false);
|
|
15262
|
-
},
|
|
15263
|
-
};
|
|
15264
|
-
const handleKeyDown = (event) => {
|
|
15265
|
-
if (event.key === "Shift")
|
|
15266
|
-
setIsShiftPressed(true);
|
|
15267
|
-
if (!canEditTable)
|
|
15268
|
-
return;
|
|
15269
|
-
const movement = keyMaps[event.key];
|
|
15270
|
-
if (event.shiftKey && event.key === "Tab") {
|
|
15271
|
-
event.preventDefault();
|
|
15272
|
-
if (isEditing)
|
|
15273
|
-
handleSaveChanges();
|
|
15274
|
-
moveIndexPosition(-1, 0, true);
|
|
15275
|
-
}
|
|
15276
|
-
else if (movement) {
|
|
15277
|
-
movement(event);
|
|
15278
|
-
}
|
|
15279
|
-
};
|
|
15280
|
-
const handleKeyUp = (event) => {
|
|
15281
|
-
if (event.key === "Shift")
|
|
15282
|
-
setIsShiftPressed(false);
|
|
15283
|
-
};
|
|
15284
|
-
const onClick = (x, y) => {
|
|
15285
|
-
if (!canEditTable)
|
|
15286
|
-
setCanEditTable(true);
|
|
15287
|
-
if (focusedIndex.x === x && focusedIndex.y === y && canEditTable)
|
|
15288
|
-
setIsEditing(true);
|
|
15289
|
-
else {
|
|
15290
|
-
if (isEditing)
|
|
15291
|
-
handleSaveChanges();
|
|
15292
|
-
setFocusedIndex({ x, y });
|
|
15293
|
-
}
|
|
15294
|
-
};
|
|
15295
|
-
const onDoubleClickCell = (x, y) => {
|
|
15296
|
-
if (!canEditTable)
|
|
15297
|
-
return;
|
|
15298
|
-
setIsEditing(true);
|
|
15299
|
-
setFocusedIndex({ x, y });
|
|
15300
|
-
};
|
|
15301
|
-
const onClickAwayTable = () => {
|
|
15302
|
-
if (!canSave)
|
|
15303
|
-
return;
|
|
15304
|
-
if (isEditing)
|
|
15305
|
-
handleSaveChanges();
|
|
15306
|
-
setCanEditTable(false);
|
|
15307
|
-
setIsEditing(false);
|
|
15308
|
-
};
|
|
15309
|
-
const isSelectedRow = (row) => selectedRows.includes(row);
|
|
15310
|
-
const onChangeSelectRow = (row) => {
|
|
15311
|
-
if (isSelectedRow(row))
|
|
15312
|
-
setSelectedRows(selectedRows.filter((selectedRow) => selectedRow !== row));
|
|
15313
|
-
else if (selectedRows.length > 0 && checkMultiple && isShiftPressed) {
|
|
15314
|
-
const lastRowIndex = data.findIndex((each) => each[primaryKey] === selectedRows[selectedRows.length - 1]);
|
|
15315
|
-
const currentRowIndex = data.findIndex((each) => each[primaryKey] === row);
|
|
15316
|
-
const sortedIndexes = [lastRowIndex, currentRowIndex].sort((a, b) => a - b);
|
|
15317
|
-
const filteredRows = data.filter((_, index) => index >= sortedIndexes[0] && index <= sortedIndexes[1]);
|
|
15318
|
-
const filteredRowsId = filteredRows.map((data) => data[primaryKey]);
|
|
15319
|
-
setSelectedRows([...selectedRows, ...filteredRowsId]);
|
|
15320
|
-
}
|
|
15321
|
-
else {
|
|
15322
|
-
if (!checkMultiple)
|
|
15323
|
-
setSelectedRows([row]);
|
|
15324
|
-
else
|
|
15325
|
-
setSelectedRows([...selectedRows, row]);
|
|
15326
|
-
}
|
|
15327
|
-
};
|
|
15328
|
-
useEvent("keydown", handleKeyDown);
|
|
15329
|
-
useEvent("keyup", handleKeyUp);
|
|
15330
|
-
useEffect(() => {
|
|
15331
|
-
if (isEditing) {
|
|
15332
|
-
inputValue.current = focusedRow[focusedProp];
|
|
15333
|
-
}
|
|
15334
|
-
}, [isEditing, focusedIndex]);
|
|
15335
|
-
return (React__default.createElement(ClickAwayListener, { onClickAway: onClickAwayTable },
|
|
15336
|
-
React__default.createElement(Paper, null,
|
|
15337
|
-
React__default.createElement(Table, { ref: gridRef, size: "small" },
|
|
15338
|
-
React__default.createElement(TableHead, null,
|
|
15339
|
-
React__default.createElement(TableRow, null, columns.map((column, index) => {
|
|
15340
|
-
var _a;
|
|
15341
|
-
const key = column.name === ""
|
|
15342
|
-
? column.id || column.label || index
|
|
15343
|
-
: String(column.name);
|
|
15344
|
-
return (React__default.createElement(TableCell, Object.assign({ key: key }, column === null || column === void 0 ? void 0 : column.TableCellProps, { sx: Object.assign({ border: "1px solid", borderColor: "divider" }, (_a = column === null || column === void 0 ? void 0 : column.TableCellProps) === null || _a === void 0 ? void 0 : _a.sx) }),
|
|
15345
|
-
React__default.createElement(Typography, { variant: "body2", fontWeight: "bold", fontSize: "inherit" }, column.label)));
|
|
15346
|
-
}))),
|
|
15347
|
-
React__default.createElement(TableBody, null,
|
|
15348
|
-
canInsertNewRow && (React__default.createElement(NewRow, { columns: columns, hasCheckbox: checkbox, maxPositions: maxPositions, onSaveNewRow: onSaveNewRow })),
|
|
15349
|
-
data.map((row, rowIndex) => {
|
|
15350
|
-
return (React__default.createElement(TableRow, { key: row[primaryKey] },
|
|
15351
|
-
checkbox && (React__default.createElement(TableCell, { padding: "checkbox" },
|
|
15352
|
-
React__default.createElement(Checkbox$1, { checked: isSelectedRow(row[primaryKey]), onChange: () => onChangeSelectRow(row[primaryKey]), size: "small", sx: { m: 0 } }))),
|
|
15353
|
-
columns
|
|
15354
|
-
.filter((columns) => columns.visible !== false)
|
|
15355
|
-
.map((column, columnIndex) => {
|
|
15356
|
-
const key = String(column.name || column.label || columnIndex);
|
|
15357
|
-
return (React__default.createElement(GridCell, { canEditTable: canEditTable, bordered: bordered, key: key, isEditing: isEditing, focusedIndex: focusedIndex, rowIndex: rowIndex, columnIndex: columnIndex, value: row[column.name], onInputChange: onInputChange, column: column, onClick: () => onClick(columnIndex, rowIndex), onDoubleClick: () => onDoubleClickCell(columnIndex, rowIndex), setCanSave: setCanSave }));
|
|
15358
|
-
})));
|
|
15359
|
-
}))))));
|
|
15360
|
-
}
|
|
15361
|
-
|
|
15362
|
-
function useEditableGrid() {
|
|
15363
|
-
const [focusedIndex, setFocusedIndex] = useState({ x: 0, y: 0 });
|
|
15364
|
-
const [isEditing, setIsEditing] = useState(false);
|
|
15365
|
-
const [data, setData] = useState([]);
|
|
15366
|
-
const [canEditTable, setCanEditTable] = useState(false);
|
|
15367
|
-
const [selectedRows, setSelectedRows] = useState([]);
|
|
15368
|
-
const [canInsertNewRow, setCanInsertNewRow] = useState(false);
|
|
15369
|
-
const onSave = (newItem) => {
|
|
15370
|
-
const updatedData = data.filter((_, index) => index !== focusedIndex.y);
|
|
15371
|
-
updatedData.splice(focusedIndex.y, 0, newItem);
|
|
15372
|
-
setData(updatedData);
|
|
15373
|
-
};
|
|
14974
|
+
function getTabProps(index) {
|
|
15374
14975
|
return {
|
|
15375
|
-
|
|
15376
|
-
|
|
15377
|
-
isEditing,
|
|
15378
|
-
setData,
|
|
15379
|
-
setIsEditing,
|
|
15380
|
-
setFocusedIndex,
|
|
15381
|
-
onSave,
|
|
15382
|
-
canEditTable,
|
|
15383
|
-
setCanEditTable,
|
|
15384
|
-
selectedRows,
|
|
15385
|
-
setSelectedRows,
|
|
15386
|
-
canInsertNewRow,
|
|
15387
|
-
setCanInsertNewRow,
|
|
14976
|
+
id: `tab-${index}`,
|
|
14977
|
+
"aria-controls": `tabpanel-${index}`,
|
|
15388
14978
|
};
|
|
15389
|
-
}
|
|
14979
|
+
}
|
|
14980
|
+
const TabPanel = (props) => {
|
|
14981
|
+
const { children, value, index } = props, other = __rest(props, ["children", "value", "index"]);
|
|
14982
|
+
return (React__default.createElement("div", Object.assign({ role: "tabpanel", hidden: value !== index, id: `tabpanel-${index}`, "aria-labelledby": `tab-${index}` }, other), value === index && React__default.createElement(React__default.Fragment, null, children)));
|
|
14983
|
+
};
|
|
15390
14984
|
|
|
15391
|
-
export { Autocomplete, Checkbox,
|
|
14985
|
+
export { Autocomplete, Checkbox, EditableTableCell, Grid, Input, InputMask, LargeButton, Radio, Select, Switch, TabPanel, Td, Tr, filterData, getTabProps };
|
|
15392
14986
|
//# sourceMappingURL=index.js.map
|