drf-react-by-schema 0.20.0 → 0.20.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/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +39 -3
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts +28 -0
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/FileInputCell.js +114 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { JSX } from 'react';
|
|
2
|
-
import { GridRowId, GridRenderCellParams } from '@mui/x-data-grid';
|
|
3
2
|
import * as Yup from 'yup';
|
|
3
|
+
import { GridRowId, GridRenderCellParams } from '@mui/x-data-grid';
|
|
4
4
|
import { SxProps } from '@mui/material';
|
|
5
5
|
import { Item, SchemaType, Id, GridEnrichedBySchemaColDef, PaginationModel, ActionType, OnSelectActions, OptionsAC, FormFieldLayout, CustomAction, LinkComponentType } from '../../@types';
|
|
6
6
|
import { OnEditModelType } from '../../context/APIWrapperContext';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataGridDesktop.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/DataGridDesktop.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA+B,GAAG,EAAgB,MAAM,OAAO,CAAC;AAE9E,OAAO,EAML,SAAS,EAET,oBAAoB,EAErB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"DataGridDesktop.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/DataGridDesktop.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA+B,GAAG,EAAgB,MAAM,OAAO,CAAC;AAE9E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E,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,eAAe,CAAC,EAAE,IAAI,CAAC;IAEvB,SAAS,EAAE,IAAI,CAAC;IAChB,iBAAiB,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,MAAM,IAAI,CAAC;IAC1C,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,mBAAmB,EAAE,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;CAC3C;AAED,iBAAS,eAAe,CAAC,EACvB,MAAM,EACN,QAAQ,EACR,WAAW,EACX,QAAY,EACZ,OAAO,EACP,KAAK,EACL,IAAqD,EACrD,UAAmB,EACnB,gBAAgB,EAChB,kBAAwB,EACxB,kBAAuB,EACvB,sBAAsB,EACtB,WAAgB,EAChB,QAAa,EACb,OAAO,EACP,WAAW,EACX,aAAa,EACb,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,UAAkB,EAClB,aAAqB,EACrB,eAAe,EACf,YAAoB,EACpB,oBAA4B,EAC5B,cAAc,EACd,eAA2B,EAC3B,kBAA8B,EAC9B,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,OAAkC,EAClC,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EAAE,iBAAiB,EAE5B,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,mBAAmB,GACpB,EAAE,oBAAoB,eA2+BtB;;AAED,wBAA6D"}
|
|
@@ -48,7 +48,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
48
48
|
const react_1 = __importStar(require("react"));
|
|
49
49
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
50
50
|
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
51
|
+
const string_mask_1 = __importDefault(require("string-mask"));
|
|
51
52
|
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
53
|
+
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
52
54
|
const CircularProgress_1 = __importDefault(require("@mui/material/CircularProgress"));
|
|
53
55
|
const Edit_1 = __importDefault(require("@mui/icons-material/Edit"));
|
|
54
56
|
const Bolt_1 = __importDefault(require("@mui/icons-material/Bolt"));
|
|
@@ -56,20 +58,20 @@ const Visibility_1 = __importDefault(require("@mui/icons-material/Visibility"));
|
|
|
56
58
|
const Clear_1 = __importDefault(require("@mui/icons-material/Clear"));
|
|
57
59
|
const Check_1 = __importDefault(require("@mui/icons-material/Check"));
|
|
58
60
|
const Undo_1 = __importDefault(require("@mui/icons-material/Undo"));
|
|
59
|
-
const string_mask_1 = __importDefault(require("string-mask"));
|
|
60
61
|
const styles_1 = require("../../styles");
|
|
61
62
|
const api_1 = require("../../api");
|
|
62
63
|
const utils_1 = require("../../utils");
|
|
63
|
-
const DRFReactBySchemaContext_1 = require("../../context/DRFReactBySchemaContext");
|
|
64
64
|
const utils_2 = require("./utils");
|
|
65
|
+
const DRFReactBySchemaContext_1 = require("../../context/DRFReactBySchemaContext");
|
|
66
|
+
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
65
67
|
const CustomToolbar_1 = require("./CustomToolbar");
|
|
66
68
|
const SelectEditInputCell_1 = require("./SelectEditInputCell");
|
|
67
69
|
const GridDateInput_1 = require("./GridDateInput");
|
|
68
70
|
const GridDecimalInput_1 = require("./GridDecimalInput");
|
|
69
71
|
const GridPatternInput_1 = require("./GridPatternInput");
|
|
70
72
|
const BooleanInputCell_1 = require("./BooleanInputCell");
|
|
73
|
+
const FileInputCell_1 = require("./FileInputCell");
|
|
71
74
|
const FooterToolbar_1 = require("./FooterToolbar");
|
|
72
|
-
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
73
75
|
function DataGridDesktop({ schema, dataGrid, setDataGrid, rowCount = 0, columns, model, name = Math.floor(Math.random() * 1000000).toString(), indexField = 'nome', addExistingModel, indexFieldMinWidth = 350, indexFieldBasePath = '', indexFieldViewBasePath, stateToLink = {}, minWidth = 80, loading, modelParent, modelParentId, customColumnOperations, customFieldFormLayouts, customLinkDestination, LinkComponent, onProcessRow, onDataChange, onEditModel, isEditable = false, hasBulkSelect = false, onSelectActions, isAutoHeight = false, hideFooterPagination = false, setVisibleRows, paginationModel = undefined, setPaginationModel = undefined, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions = ['editInline', 'remove'], customActions, hideColumnsButton, hideFilterButton, hideDensityButton, hideExportButton, hideQuickFilterBar, optionsAC: optionsACExternal, emptyItem, handleDeleteClick, setSnackBar, yupValidationSchema, }) {
|
|
74
76
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
75
77
|
const apiContext = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
@@ -364,6 +366,40 @@ function DataGridDesktop({ schema, dataGrid, setDataGrid, rowCount = 0, columns,
|
|
|
364
366
|
type: 'number',
|
|
365
367
|
});
|
|
366
368
|
break;
|
|
369
|
+
case 'image upload':
|
|
370
|
+
case 'file upload':
|
|
371
|
+
column.filterable = false;
|
|
372
|
+
column.orderable = false;
|
|
373
|
+
const colSchema = schema[col.field];
|
|
374
|
+
const accept = colSchema.allowed_mime_types
|
|
375
|
+
? colSchema.allowed_mime_types.join(', ')
|
|
376
|
+
: colSchema.type === 'image upload'
|
|
377
|
+
? '/image*'
|
|
378
|
+
: '*';
|
|
379
|
+
column.minWidth = 200;
|
|
380
|
+
column.valueFormatter = (params) => {
|
|
381
|
+
var _a;
|
|
382
|
+
return !((_a = params.value) === null || _a === void 0 ? void 0 : _a.name)
|
|
383
|
+
? ''
|
|
384
|
+
: `${params.value.name.split('/').pop()} (${(0, utils_1.formatFileSize)(params.value.size)})`;
|
|
385
|
+
};
|
|
386
|
+
column.renderCell = (params) => {
|
|
387
|
+
var _a, _b;
|
|
388
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, !((_a = params.value) === null || _a === void 0 ? void 0 : _a.name) ? null : ((_b = params.value) === null || _b === void 0 ? void 0 : _b.url) &&
|
|
389
|
+
colSchema.type === 'image upload' ? (react_1.default.createElement("img", { src: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${params.value.url}`, alt: params.value.name, title: params.value.name, style: {
|
|
390
|
+
width: '100%',
|
|
391
|
+
maxHeight: '100px',
|
|
392
|
+
objectFit: 'cover',
|
|
393
|
+
} })) : (react_1.default.createElement(Typography_1.default, { variant: "body2", sx: { mb: 1 } },
|
|
394
|
+
params.value.name.split('/').pop(),
|
|
395
|
+
" (",
|
|
396
|
+
(0, utils_1.formatFileSize)(params.value.size),
|
|
397
|
+
")"))));
|
|
398
|
+
};
|
|
399
|
+
if (isEditable && !col.disabled) {
|
|
400
|
+
column.renderEditCell = (params) => (react_1.default.createElement(FileInputCell_1.FileInputCell, Object.assign({ accept: accept, fileType: colSchema.type, column: column, required: colSchema.required }, params)));
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
367
403
|
}
|
|
368
404
|
if (indexFieldMinWidth && !column.minWidth) {
|
|
369
405
|
column.minWidth = col.field === indexField ? indexFieldMinWidth : minWidth;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { JSX } from 'react';
|
|
2
|
+
import { SxProps } from '@mui/material';
|
|
3
|
+
import { GenericValue, GridEnrichedBySchemaColDef } from '../../@types';
|
|
4
|
+
interface FileInputCellProps {
|
|
5
|
+
field: string;
|
|
6
|
+
id: number | string;
|
|
7
|
+
value?: GenericValue;
|
|
8
|
+
column: GridEnrichedBySchemaColDef;
|
|
9
|
+
accept: string;
|
|
10
|
+
fileType?: string;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
sx?: SxProps;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @param {FileInputCellProps} {
|
|
18
|
+
* field,
|
|
19
|
+
* id,
|
|
20
|
+
* value,
|
|
21
|
+
* column,
|
|
22
|
+
* sx = {}
|
|
23
|
+
* }
|
|
24
|
+
* @returns {*} {JSX.Element}
|
|
25
|
+
*/
|
|
26
|
+
export declare function FileInputCell({ field, id, value, column, accept, fileType, required, sx, }: FileInputCellProps): JSX.Element;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=FileInputCell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileInputCell.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/FileInputCell.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAInC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAUxC,OAAO,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAgBxE,UAAU,kBAAkB;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,0BAA0B,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,OAAO,CAAC;CACd;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,EAAE,EACF,KAAK,EACL,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,EAAO,GACR,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAqGlC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.FileInputCell = FileInputCell;
|
|
16
|
+
const react_1 = __importDefault(require("react"));
|
|
17
|
+
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
18
|
+
const styles_1 = require("@mui/material/styles");
|
|
19
|
+
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
20
|
+
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
21
|
+
const FormControl_1 = __importDefault(require("@mui/material/FormControl"));
|
|
22
|
+
const FormControlLabel_1 = __importDefault(require("@mui/material/FormControlLabel"));
|
|
23
|
+
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
24
|
+
const CloudUpload_1 = __importDefault(require("@mui/icons-material/CloudUpload"));
|
|
25
|
+
const DRFReactBySchemaContext_1 = require("../../context/DRFReactBySchemaContext");
|
|
26
|
+
const utils_1 = require("../../utils");
|
|
27
|
+
const VisuallyHiddenInput = (0, styles_1.styled)('input')({
|
|
28
|
+
clip: 'rect(0 0 0 0)',
|
|
29
|
+
clipPath: 'inset(50%)',
|
|
30
|
+
height: 1,
|
|
31
|
+
overflow: 'hidden',
|
|
32
|
+
position: 'absolute',
|
|
33
|
+
bottom: 0,
|
|
34
|
+
left: 0,
|
|
35
|
+
whiteSpace: 'nowrap',
|
|
36
|
+
width: 1,
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
* @param {FileInputCellProps} {
|
|
42
|
+
* field,
|
|
43
|
+
* id,
|
|
44
|
+
* value,
|
|
45
|
+
* column,
|
|
46
|
+
* sx = {}
|
|
47
|
+
* }
|
|
48
|
+
* @returns {*} {JSX.Element}
|
|
49
|
+
*/
|
|
50
|
+
function FileInputCell({ field, id, value, column, accept, fileType, required, sx = {}, }) {
|
|
51
|
+
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
52
|
+
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
53
|
+
const handleChange = (newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
yield apiRef.current.setEditCellValue({ id, field, value: newValue });
|
|
55
|
+
apiRef.current.stopCellEditMode({ id, field });
|
|
56
|
+
});
|
|
57
|
+
const fileTypeStr = fileType === 'image upload' ? 'imagem' : 'documento';
|
|
58
|
+
return (react_1.default.createElement(FormControl_1.default, { component: "fieldset", sx: { width: '100%' } },
|
|
59
|
+
react_1.default.createElement(FormControlLabel_1.default, { control: react_1.default.createElement(Box_1.default, { sx: Object.assign({ display: 'flex', flexDirection: 'column', alignItems: 'center', width: '100%' }, sx) },
|
|
60
|
+
!(value === null || value === void 0 ? void 0 : value.name) ? null : ((value === null || value === void 0 ? void 0 : value.url) || (value === null || value === void 0 ? void 0 : value.src)) && fileType === 'image upload' ? (react_1.default.createElement("img", { src: value.url ? `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${value.url}` : value.src, alt: value.name, title: value.name, style: {
|
|
61
|
+
width: '100%',
|
|
62
|
+
maxHeight: '100px',
|
|
63
|
+
objectFit: 'cover',
|
|
64
|
+
} })) : (react_1.default.createElement(Typography_1.default, { variant: "body2", sx: { mb: 1 } },
|
|
65
|
+
value.name.split('/').pop(),
|
|
66
|
+
" (",
|
|
67
|
+
(0, utils_1.formatFileSize)(value.size),
|
|
68
|
+
")")),
|
|
69
|
+
react_1.default.createElement(Button_1.default, { component: "label", variant: "outlined", startIcon: react_1.default.createElement(CloudUpload_1.default, null), disabled: column.disabled === true, fullWidth: true, sx: { mt: 1 },
|
|
70
|
+
// color={error ? 'error' : 'primary'}
|
|
71
|
+
color: "primary" },
|
|
72
|
+
value ? `Trocar ${fileTypeStr}` : `Enviar ${fileTypeStr}`,
|
|
73
|
+
react_1.default.createElement(VisuallyHiddenInput, { type: "file", onChange: (e) => {
|
|
74
|
+
var _a;
|
|
75
|
+
const file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
76
|
+
if (file) {
|
|
77
|
+
if (file.type.startsWith('image/')) {
|
|
78
|
+
const reader = new FileReader();
|
|
79
|
+
reader.onload = (event) => {
|
|
80
|
+
const src = event.target ? event.target.result : undefined;
|
|
81
|
+
const newValue = {
|
|
82
|
+
name: file.name,
|
|
83
|
+
size: file.size,
|
|
84
|
+
type: file.type,
|
|
85
|
+
src,
|
|
86
|
+
file,
|
|
87
|
+
};
|
|
88
|
+
handleChange(newValue);
|
|
89
|
+
// if (onValueChange) {
|
|
90
|
+
// onValueChange(newValue);
|
|
91
|
+
// }
|
|
92
|
+
};
|
|
93
|
+
reader.readAsDataURL(file);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const newValue = {
|
|
97
|
+
name: file.name,
|
|
98
|
+
size: file.size,
|
|
99
|
+
type: file.type,
|
|
100
|
+
file,
|
|
101
|
+
};
|
|
102
|
+
handleChange(newValue);
|
|
103
|
+
// if (onValueChange) {
|
|
104
|
+
// onValueChange(newValue);
|
|
105
|
+
// }
|
|
106
|
+
}
|
|
107
|
+
}, accept: accept }))), label: '',
|
|
108
|
+
// labelPlacement="top"
|
|
109
|
+
required: required, sx: {
|
|
110
|
+
width: '100%',
|
|
111
|
+
alignItems: 'flex-start',
|
|
112
|
+
marginLeft: 0,
|
|
113
|
+
} })));
|
|
114
|
+
}
|
package/package.json
CHANGED