@bluemarble/bm-components 0.0.93 → 0.0.94
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.d.mts +81 -24
- package/dist/index.d.ts +81 -24
- package/dist/index.js +294 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +307 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React, { ReactNode, FC } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import * as _mui_material from '@mui/material';
|
|
3
|
+
import { TableCellProps, TextFieldProps, TableRowProps, StandardTextFieldProps, SelectProps as SelectProps$1, FormControlProps, InputLabelProps, AutocompleteRenderInputParams, AutocompleteProps as AutocompleteProps$1, CheckboxProps as CheckboxProps$1, FormControlLabelProps, SwitchProps as SwitchProps$1, RadioGroupProps, ButtonProps, CircularProgressProps, SxProps, PaperProps, TableProps, TableHeadProps, TableBodyProps, ModalProps as ModalProps$1, DialogProps, AlertColor } from '@mui/material';
|
|
3
4
|
import IMask$1 from 'imask';
|
|
5
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
6
|
+
import { ZodTypeDef, ZodSchema } from 'zod';
|
|
7
|
+
import { AxiosInstance } from 'axios';
|
|
4
8
|
|
|
5
9
|
interface ColumnTitleProps {
|
|
6
10
|
name: string;
|
|
@@ -230,6 +234,75 @@ interface GridProps {
|
|
|
230
234
|
}
|
|
231
235
|
declare function BaseGrid({ columns, children, paperProps, tableBodyProps, tableHeadProps, tableProps, sortedDirection, sortedBy, onSortBy, dense, striped, bordered, currentPage, totalNumberOfPages, onPageChange, rowsPerPage, setRowsPerPage, rowsPerPageOptions, hideFooter, prependColumn, appendColumn, isLoading }: GridProps): JSX.Element;
|
|
232
236
|
|
|
237
|
+
declare type ModalProps = {
|
|
238
|
+
open: boolean;
|
|
239
|
+
onClose: () => void;
|
|
240
|
+
} & ModalProps$1;
|
|
241
|
+
declare const Modal: ({ open, onClose, ...rest }: ModalProps) => JSX.Element;
|
|
242
|
+
|
|
243
|
+
declare function GetInputLabel<T extends Array<Record<string, any>>, K extends T[number]['name']>(columns: T): (columnName: K) => {
|
|
244
|
+
label: any;
|
|
245
|
+
name: any;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
interface DialogOptionsProps {
|
|
249
|
+
label: string;
|
|
250
|
+
focus?: boolean;
|
|
251
|
+
cb(label: string): void;
|
|
252
|
+
}
|
|
253
|
+
interface DialogCustomProps extends DialogProps {
|
|
254
|
+
open: boolean;
|
|
255
|
+
title: string;
|
|
256
|
+
body: string;
|
|
257
|
+
options: DialogOptionsProps[];
|
|
258
|
+
loading: boolean;
|
|
259
|
+
}
|
|
260
|
+
declare const Dialog: ({ open, title, loading, body, options, ...rest }: DialogCustomProps) => JSX.Element;
|
|
261
|
+
|
|
262
|
+
declare class HttpError extends Error {
|
|
263
|
+
status: number;
|
|
264
|
+
constructor(status: number, message: any);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
declare type PossibleMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
268
|
+
declare type HandlerProps = (req: NextApiRequest & {
|
|
269
|
+
user?: number;
|
|
270
|
+
}, res: NextApiResponse) => Promise<any>;
|
|
271
|
+
declare type MethodProps = Partial<Record<PossibleMethods, HandlerProps>>;
|
|
272
|
+
declare type MiddlewaresProps = ((handler: HandlerProps) => HandlerProps)[];
|
|
273
|
+
declare type ConstructorProps = {
|
|
274
|
+
middlewares?: MiddlewaresProps;
|
|
275
|
+
onFinally: () => void;
|
|
276
|
+
};
|
|
277
|
+
declare class ApiHelper {
|
|
278
|
+
middlewares: MiddlewaresProps;
|
|
279
|
+
private onFinally;
|
|
280
|
+
constructor(props?: ConstructorProps);
|
|
281
|
+
setMiddlewares(middlewares: any[]): this;
|
|
282
|
+
createMethods(methods: MethodProps): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
283
|
+
static parserErrorWrapper<Output, Def extends ZodTypeDef, Input>(body: Record<string, any>, parser: ZodSchema<Output, Def, Input>): Output;
|
|
284
|
+
static parseQueyFilters<T extends Record<string, any>>(filters: T): T;
|
|
285
|
+
static create({ onFinally }: {
|
|
286
|
+
onFinally: any;
|
|
287
|
+
}): ApiHelper;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
declare type Methods = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
|
|
291
|
+
declare type HandleProps = {
|
|
292
|
+
name: `${Methods}:${string}`;
|
|
293
|
+
};
|
|
294
|
+
declare type UseFormHelperProps = {
|
|
295
|
+
formatErrorMessage: (message: any) => string;
|
|
296
|
+
api: AxiosInstance;
|
|
297
|
+
};
|
|
298
|
+
declare function useFormHelper({ formatErrorMessage, api }: UseFormHelperProps): {
|
|
299
|
+
onSubmitWrapper: <T extends Record<string, any>>(fn: (fields: T, methods: any) => Promise<void>, { name }: HandleProps) => (fields: T, methods: any) => Promise<void>;
|
|
300
|
+
onRequestWrapper: <F extends (...args: Parameters<F>) => R, R>(fn: F, { name }: HandleProps) => (...params: Parameters<F>) => Promise<R>;
|
|
301
|
+
isLoading: (prop: string) => boolean;
|
|
302
|
+
setLoading: (prop: string, remove?: boolean) => void;
|
|
303
|
+
createAlert(message: string, type: _mui_material.AlertColor): void;
|
|
304
|
+
};
|
|
305
|
+
|
|
233
306
|
declare type FilterCompareType = 'gte' | 'lte' | 'lt' | 'gt' | 'equal' | 'in' | 'notEqual' | 'notIn';
|
|
234
307
|
declare type FilterProps = {
|
|
235
308
|
id?: string;
|
|
@@ -283,29 +356,13 @@ declare function useLoading<T = string>(): {
|
|
|
283
356
|
setLoading: (prop: T, remove?: boolean) => void;
|
|
284
357
|
};
|
|
285
358
|
|
|
286
|
-
declare
|
|
287
|
-
|
|
288
|
-
onClose: () => void;
|
|
289
|
-
} & ModalProps$1;
|
|
290
|
-
declare const Modal: ({ open, onClose, ...rest }: ModalProps) => JSX.Element;
|
|
291
|
-
|
|
292
|
-
declare function GetInputLabel<T extends Array<Record<string, any>>, K extends T[number]['name']>(columns: T): (columnName: K) => {
|
|
293
|
-
label: any;
|
|
294
|
-
name: any;
|
|
359
|
+
declare const useAlert: () => {
|
|
360
|
+
createAlert(message: string, type: _mui_material.AlertColor): void;
|
|
295
361
|
};
|
|
296
362
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
interface DialogCustomProps extends DialogProps {
|
|
303
|
-
open: boolean;
|
|
304
|
-
title: string;
|
|
305
|
-
body: string;
|
|
306
|
-
options: DialogOptionsProps[];
|
|
307
|
-
loading: boolean;
|
|
308
|
-
}
|
|
309
|
-
declare const Dialog: ({ open, title, loading, body, options, ...rest }: DialogCustomProps) => JSX.Element;
|
|
363
|
+
declare type AlertContextProps = {
|
|
364
|
+
createAlert(message: string, type: AlertColor): void;
|
|
365
|
+
};
|
|
366
|
+
declare const AlertContext: React.Context<AlertContextProps>;
|
|
310
367
|
|
|
311
|
-
export { Autocomplete, BaseGrid, Checkbox, type ColumnTitleProps, type ColumnsProps, Dialog, EditableTableCell, type FilterCompareType, type FilterProps, GetInputLabel, Grid, type IFilter, Input, InputMask, LargeButton, Modal, Radio, Select, Switch, TabPanel, type TabPanelProps, Td, Tr, createFilter, filterData, getTabProps, useEvent, useFilter, useGrid, useLoading };
|
|
368
|
+
export { AlertContext, ApiHelper, Autocomplete, BaseGrid, Checkbox, type ColumnTitleProps, type ColumnsProps, Dialog, EditableTableCell, type FilterCompareType, type FilterProps, GetInputLabel, Grid, HttpError, type IFilter, Input, InputMask, LargeButton, Modal, Radio, Select, Switch, TabPanel, type TabPanelProps, Td, Tr, createFilter, filterData, getTabProps, useAlert, useEvent, useFilter, useFormHelper, useGrid, useLoading };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React, { ReactNode, FC } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import * as _mui_material from '@mui/material';
|
|
3
|
+
import { TableCellProps, TextFieldProps, TableRowProps, StandardTextFieldProps, SelectProps as SelectProps$1, FormControlProps, InputLabelProps, AutocompleteRenderInputParams, AutocompleteProps as AutocompleteProps$1, CheckboxProps as CheckboxProps$1, FormControlLabelProps, SwitchProps as SwitchProps$1, RadioGroupProps, ButtonProps, CircularProgressProps, SxProps, PaperProps, TableProps, TableHeadProps, TableBodyProps, ModalProps as ModalProps$1, DialogProps, AlertColor } from '@mui/material';
|
|
3
4
|
import IMask$1 from 'imask';
|
|
5
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
6
|
+
import { ZodTypeDef, ZodSchema } from 'zod';
|
|
7
|
+
import { AxiosInstance } from 'axios';
|
|
4
8
|
|
|
5
9
|
interface ColumnTitleProps {
|
|
6
10
|
name: string;
|
|
@@ -230,6 +234,75 @@ interface GridProps {
|
|
|
230
234
|
}
|
|
231
235
|
declare function BaseGrid({ columns, children, paperProps, tableBodyProps, tableHeadProps, tableProps, sortedDirection, sortedBy, onSortBy, dense, striped, bordered, currentPage, totalNumberOfPages, onPageChange, rowsPerPage, setRowsPerPage, rowsPerPageOptions, hideFooter, prependColumn, appendColumn, isLoading }: GridProps): JSX.Element;
|
|
232
236
|
|
|
237
|
+
declare type ModalProps = {
|
|
238
|
+
open: boolean;
|
|
239
|
+
onClose: () => void;
|
|
240
|
+
} & ModalProps$1;
|
|
241
|
+
declare const Modal: ({ open, onClose, ...rest }: ModalProps) => JSX.Element;
|
|
242
|
+
|
|
243
|
+
declare function GetInputLabel<T extends Array<Record<string, any>>, K extends T[number]['name']>(columns: T): (columnName: K) => {
|
|
244
|
+
label: any;
|
|
245
|
+
name: any;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
interface DialogOptionsProps {
|
|
249
|
+
label: string;
|
|
250
|
+
focus?: boolean;
|
|
251
|
+
cb(label: string): void;
|
|
252
|
+
}
|
|
253
|
+
interface DialogCustomProps extends DialogProps {
|
|
254
|
+
open: boolean;
|
|
255
|
+
title: string;
|
|
256
|
+
body: string;
|
|
257
|
+
options: DialogOptionsProps[];
|
|
258
|
+
loading: boolean;
|
|
259
|
+
}
|
|
260
|
+
declare const Dialog: ({ open, title, loading, body, options, ...rest }: DialogCustomProps) => JSX.Element;
|
|
261
|
+
|
|
262
|
+
declare class HttpError extends Error {
|
|
263
|
+
status: number;
|
|
264
|
+
constructor(status: number, message: any);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
declare type PossibleMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
268
|
+
declare type HandlerProps = (req: NextApiRequest & {
|
|
269
|
+
user?: number;
|
|
270
|
+
}, res: NextApiResponse) => Promise<any>;
|
|
271
|
+
declare type MethodProps = Partial<Record<PossibleMethods, HandlerProps>>;
|
|
272
|
+
declare type MiddlewaresProps = ((handler: HandlerProps) => HandlerProps)[];
|
|
273
|
+
declare type ConstructorProps = {
|
|
274
|
+
middlewares?: MiddlewaresProps;
|
|
275
|
+
onFinally: () => void;
|
|
276
|
+
};
|
|
277
|
+
declare class ApiHelper {
|
|
278
|
+
middlewares: MiddlewaresProps;
|
|
279
|
+
private onFinally;
|
|
280
|
+
constructor(props?: ConstructorProps);
|
|
281
|
+
setMiddlewares(middlewares: any[]): this;
|
|
282
|
+
createMethods(methods: MethodProps): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
283
|
+
static parserErrorWrapper<Output, Def extends ZodTypeDef, Input>(body: Record<string, any>, parser: ZodSchema<Output, Def, Input>): Output;
|
|
284
|
+
static parseQueyFilters<T extends Record<string, any>>(filters: T): T;
|
|
285
|
+
static create({ onFinally }: {
|
|
286
|
+
onFinally: any;
|
|
287
|
+
}): ApiHelper;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
declare type Methods = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
|
|
291
|
+
declare type HandleProps = {
|
|
292
|
+
name: `${Methods}:${string}`;
|
|
293
|
+
};
|
|
294
|
+
declare type UseFormHelperProps = {
|
|
295
|
+
formatErrorMessage: (message: any) => string;
|
|
296
|
+
api: AxiosInstance;
|
|
297
|
+
};
|
|
298
|
+
declare function useFormHelper({ formatErrorMessage, api }: UseFormHelperProps): {
|
|
299
|
+
onSubmitWrapper: <T extends Record<string, any>>(fn: (fields: T, methods: any) => Promise<void>, { name }: HandleProps) => (fields: T, methods: any) => Promise<void>;
|
|
300
|
+
onRequestWrapper: <F extends (...args: Parameters<F>) => R, R>(fn: F, { name }: HandleProps) => (...params: Parameters<F>) => Promise<R>;
|
|
301
|
+
isLoading: (prop: string) => boolean;
|
|
302
|
+
setLoading: (prop: string, remove?: boolean) => void;
|
|
303
|
+
createAlert(message: string, type: _mui_material.AlertColor): void;
|
|
304
|
+
};
|
|
305
|
+
|
|
233
306
|
declare type FilterCompareType = 'gte' | 'lte' | 'lt' | 'gt' | 'equal' | 'in' | 'notEqual' | 'notIn';
|
|
234
307
|
declare type FilterProps = {
|
|
235
308
|
id?: string;
|
|
@@ -283,29 +356,13 @@ declare function useLoading<T = string>(): {
|
|
|
283
356
|
setLoading: (prop: T, remove?: boolean) => void;
|
|
284
357
|
};
|
|
285
358
|
|
|
286
|
-
declare
|
|
287
|
-
|
|
288
|
-
onClose: () => void;
|
|
289
|
-
} & ModalProps$1;
|
|
290
|
-
declare const Modal: ({ open, onClose, ...rest }: ModalProps) => JSX.Element;
|
|
291
|
-
|
|
292
|
-
declare function GetInputLabel<T extends Array<Record<string, any>>, K extends T[number]['name']>(columns: T): (columnName: K) => {
|
|
293
|
-
label: any;
|
|
294
|
-
name: any;
|
|
359
|
+
declare const useAlert: () => {
|
|
360
|
+
createAlert(message: string, type: _mui_material.AlertColor): void;
|
|
295
361
|
};
|
|
296
362
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
interface DialogCustomProps extends DialogProps {
|
|
303
|
-
open: boolean;
|
|
304
|
-
title: string;
|
|
305
|
-
body: string;
|
|
306
|
-
options: DialogOptionsProps[];
|
|
307
|
-
loading: boolean;
|
|
308
|
-
}
|
|
309
|
-
declare const Dialog: ({ open, title, loading, body, options, ...rest }: DialogCustomProps) => JSX.Element;
|
|
363
|
+
declare type AlertContextProps = {
|
|
364
|
+
createAlert(message: string, type: AlertColor): void;
|
|
365
|
+
};
|
|
366
|
+
declare const AlertContext: React.Context<AlertContextProps>;
|
|
310
367
|
|
|
311
|
-
export { Autocomplete, BaseGrid, Checkbox, type ColumnTitleProps, type ColumnsProps, Dialog, EditableTableCell, type FilterCompareType, type FilterProps, GetInputLabel, Grid, type IFilter, Input, InputMask, LargeButton, Modal, Radio, Select, Switch, TabPanel, type TabPanelProps, Td, Tr, createFilter, filterData, getTabProps, useEvent, useFilter, useGrid, useLoading };
|
|
368
|
+
export { AlertContext, ApiHelper, Autocomplete, BaseGrid, Checkbox, type ColumnTitleProps, type ColumnsProps, Dialog, EditableTableCell, type FilterCompareType, type FilterProps, GetInputLabel, Grid, HttpError, type IFilter, Input, InputMask, LargeButton, Modal, Radio, Select, Switch, TabPanel, type TabPanelProps, Td, Tr, createFilter, filterData, getTabProps, useAlert, useEvent, useFilter, useFormHelper, useGrid, useLoading };
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
52
52
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
53
53
|
mod
|
|
54
54
|
));
|
|
55
|
+
var __async = (__this, __arguments, generator) => {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
var fulfilled = (value) => {
|
|
58
|
+
try {
|
|
59
|
+
step(generator.next(value));
|
|
60
|
+
} catch (e) {
|
|
61
|
+
reject(e);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var rejected = (value) => {
|
|
65
|
+
try {
|
|
66
|
+
step(generator.throw(value));
|
|
67
|
+
} catch (e) {
|
|
68
|
+
reject(e);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
72
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
73
|
+
});
|
|
74
|
+
};
|
|
55
75
|
|
|
56
76
|
// node_modules/prop-types/node_modules/react-is/cjs/react-is.production.min.js
|
|
57
77
|
var require_react_is_production_min = __commonJS({
|
|
@@ -3815,7 +3835,276 @@ function BaseGrid({
|
|
|
3815
3835
|
);
|
|
3816
3836
|
}
|
|
3817
3837
|
|
|
3818
|
-
// src/components/
|
|
3838
|
+
// src/components/Modal/index.tsx
|
|
3839
|
+
|
|
3840
|
+
|
|
3841
|
+
|
|
3842
|
+
|
|
3843
|
+
|
|
3844
|
+
var Modal = (_a) => {
|
|
3845
|
+
var _b = _a, { open, onClose } = _b, rest = __objRest(_b, ["open", "onClose"]);
|
|
3846
|
+
return /* @__PURE__ */ React4.default.createElement(_material.Modal, __spreadValues({ open, onClose, disableEnforceFocus: true }, rest), /* @__PURE__ */ React4.default.createElement(
|
|
3847
|
+
_material.Box,
|
|
3848
|
+
{
|
|
3849
|
+
sx: {
|
|
3850
|
+
outline: "none",
|
|
3851
|
+
backgroundColor: "white",
|
|
3852
|
+
position: "absolute",
|
|
3853
|
+
top: "50%",
|
|
3854
|
+
left: "50%",
|
|
3855
|
+
transform: "translate(-50%, -50%)",
|
|
3856
|
+
borderRadius: 1
|
|
3857
|
+
}
|
|
3858
|
+
},
|
|
3859
|
+
/* @__PURE__ */ React4.default.createElement(React4.default.Fragment, null, rest.children)
|
|
3860
|
+
));
|
|
3861
|
+
};
|
|
3862
|
+
|
|
3863
|
+
// src/components/utils/GetInputLabel.ts
|
|
3864
|
+
function GetInputLabel(columns) {
|
|
3865
|
+
return (columnName) => {
|
|
3866
|
+
const column = columns.find((column2) => column2.name === columnName);
|
|
3867
|
+
return { label: column.label, name: column.name };
|
|
3868
|
+
};
|
|
3869
|
+
}
|
|
3870
|
+
|
|
3871
|
+
// src/components/Dialog/index.tsx
|
|
3872
|
+
|
|
3873
|
+
|
|
3874
|
+
|
|
3875
|
+
|
|
3876
|
+
|
|
3877
|
+
|
|
3878
|
+
|
|
3879
|
+
|
|
3880
|
+
|
|
3881
|
+
|
|
3882
|
+
var Dialog = (_a) => {
|
|
3883
|
+
var _b = _a, {
|
|
3884
|
+
open,
|
|
3885
|
+
title,
|
|
3886
|
+
loading,
|
|
3887
|
+
body,
|
|
3888
|
+
options
|
|
3889
|
+
} = _b, rest = __objRest(_b, [
|
|
3890
|
+
"open",
|
|
3891
|
+
"title",
|
|
3892
|
+
"loading",
|
|
3893
|
+
"body",
|
|
3894
|
+
"options"
|
|
3895
|
+
]);
|
|
3896
|
+
return /* @__PURE__ */ React4.default.createElement(_material.Dialog, __spreadValues({ open }, rest), /* @__PURE__ */ React4.default.createElement(_material.Box, { sx: { p: 2 } }, /* @__PURE__ */ React4.default.createElement(_material.DialogTitle, { sx: { fontWeight: "bold" } }, title), /* @__PURE__ */ React4.default.createElement(_material.DialogContentText, { sx: { px: "10px", textAlign: "center", mb: 2 } }, body), /* @__PURE__ */ React4.default.createElement(_material.DialogActions, null, options.map((option, index) => {
|
|
3897
|
+
return /* @__PURE__ */ React4.default.createElement(
|
|
3898
|
+
_material.Button,
|
|
3899
|
+
{
|
|
3900
|
+
key: index,
|
|
3901
|
+
onClick: () => option.cb(option.label),
|
|
3902
|
+
variant: option.focus ? "contained" : "text",
|
|
3903
|
+
sx: {
|
|
3904
|
+
fontWeight: option.focus ? "bold" : "normal",
|
|
3905
|
+
color: option.focus ? "#fff" : "primary.main"
|
|
3906
|
+
},
|
|
3907
|
+
disableElevation: true,
|
|
3908
|
+
disabled: loading
|
|
3909
|
+
},
|
|
3910
|
+
loading && option.focus ? /* @__PURE__ */ React4.default.createElement(_material.CircularProgress, { size: 25, color: "inherit" }) : /* @__PURE__ */ React4.default.createElement(React4.default.Fragment, null, option.label)
|
|
3911
|
+
);
|
|
3912
|
+
}))));
|
|
3913
|
+
};
|
|
3914
|
+
|
|
3915
|
+
// src/errors/HttpError.ts
|
|
3916
|
+
var HttpError = class extends Error {
|
|
3917
|
+
constructor(status, message) {
|
|
3918
|
+
super(message);
|
|
3919
|
+
this.message = message;
|
|
3920
|
+
this.stack = `HttpError: ${message}`;
|
|
3921
|
+
this.status = status;
|
|
3922
|
+
}
|
|
3923
|
+
};
|
|
3924
|
+
|
|
3925
|
+
// src/helpers/apiHelper/index.ts
|
|
3926
|
+
var ApiHelper = class _ApiHelper {
|
|
3927
|
+
onFinally() {
|
|
3928
|
+
}
|
|
3929
|
+
constructor(props) {
|
|
3930
|
+
this.middlewares = (props == null ? void 0 : props.middlewares.reverse()) || [];
|
|
3931
|
+
this.onFinally = props.onFinally;
|
|
3932
|
+
}
|
|
3933
|
+
setMiddlewares(middlewares) {
|
|
3934
|
+
this.middlewares = middlewares.reverse();
|
|
3935
|
+
return this;
|
|
3936
|
+
}
|
|
3937
|
+
createMethods(methods) {
|
|
3938
|
+
return (req, res) => __async(this, null, function* () {
|
|
3939
|
+
const currentMethod = methods[req.method];
|
|
3940
|
+
try {
|
|
3941
|
+
if (!currentMethod)
|
|
3942
|
+
throw new HttpError(405, "M\xE9todo inv\xE1lido");
|
|
3943
|
+
const methodWithMiddlewares = this.middlewares.reduce(
|
|
3944
|
+
(acc, fn) => fn(acc),
|
|
3945
|
+
currentMethod
|
|
3946
|
+
);
|
|
3947
|
+
yield methodWithMiddlewares(req, res);
|
|
3948
|
+
} catch (error) {
|
|
3949
|
+
if (error instanceof HttpError)
|
|
3950
|
+
return res.status(error.status).json(error.message);
|
|
3951
|
+
if (process.env.NODE_ENV === "production")
|
|
3952
|
+
return res.status(500).json({
|
|
3953
|
+
code: "internal.error",
|
|
3954
|
+
error: "Erro interno do servidor",
|
|
3955
|
+
details: error
|
|
3956
|
+
});
|
|
3957
|
+
throw new Error(error);
|
|
3958
|
+
} finally {
|
|
3959
|
+
this.onFinally();
|
|
3960
|
+
}
|
|
3961
|
+
});
|
|
3962
|
+
}
|
|
3963
|
+
static parserErrorWrapper(body, parser) {
|
|
3964
|
+
try {
|
|
3965
|
+
const object = parser.parse(body);
|
|
3966
|
+
return object;
|
|
3967
|
+
} catch (error) {
|
|
3968
|
+
throw new HttpError(400, {
|
|
3969
|
+
code: "invalid.body",
|
|
3970
|
+
error: "Dados inv\xE1lidos",
|
|
3971
|
+
details: error
|
|
3972
|
+
});
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
static parseQueyFilters(filters) {
|
|
3976
|
+
return Object.entries(filters).reduce((acc, [key, value]) => {
|
|
3977
|
+
if (value)
|
|
3978
|
+
acc[key] = value;
|
|
3979
|
+
return acc;
|
|
3980
|
+
}, {});
|
|
3981
|
+
}
|
|
3982
|
+
static create({ onFinally }) {
|
|
3983
|
+
return new _ApiHelper({
|
|
3984
|
+
onFinally
|
|
3985
|
+
});
|
|
3986
|
+
}
|
|
3987
|
+
};
|
|
3988
|
+
|
|
3989
|
+
// src/hooks/useFormHelper.ts
|
|
3990
|
+
var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
|
|
3991
|
+
|
|
3992
|
+
|
|
3993
|
+
// src/hooks/useAlert.ts
|
|
3994
|
+
|
|
3995
|
+
|
|
3996
|
+
// src/contexts/AlertContext.tsx
|
|
3997
|
+
|
|
3998
|
+
|
|
3999
|
+
|
|
4000
|
+
// src/components/Toast/index.tsx
|
|
4001
|
+
|
|
4002
|
+
|
|
4003
|
+
|
|
4004
|
+
|
|
4005
|
+
// src/contexts/AlertContext.tsx
|
|
4006
|
+
var AlertContext = _react.createContext.call(void 0, {});
|
|
4007
|
+
|
|
4008
|
+
// src/hooks/useAlert.ts
|
|
4009
|
+
var useAlert = () => {
|
|
4010
|
+
return _react.useContext.call(void 0, AlertContext);
|
|
4011
|
+
};
|
|
4012
|
+
|
|
4013
|
+
// src/hooks/useLoading.ts
|
|
4014
|
+
|
|
4015
|
+
function useLoading() {
|
|
4016
|
+
const [state, setState] = _react.useState.call(void 0, []);
|
|
4017
|
+
const isLoading = (prop) => state.includes(prop);
|
|
4018
|
+
const setLoading = (prop, remove) => {
|
|
4019
|
+
if (remove)
|
|
4020
|
+
setState((prevState) => prevState.filter((state2) => state2 !== prop));
|
|
4021
|
+
else
|
|
4022
|
+
setState((prevState) => [...prevState, prop]);
|
|
4023
|
+
};
|
|
4024
|
+
return { isLoading, setLoading };
|
|
4025
|
+
}
|
|
4026
|
+
|
|
4027
|
+
// src/hooks/useFormHelper.ts
|
|
4028
|
+
function useFormHelper({ formatErrorMessage, api }) {
|
|
4029
|
+
const alertProps = useAlert();
|
|
4030
|
+
const loadingProps = useLoading();
|
|
4031
|
+
const { createAlert } = alertProps;
|
|
4032
|
+
const { setLoading } = loadingProps;
|
|
4033
|
+
const sourceRef = _react.useRef.call(void 0, );
|
|
4034
|
+
function onSubmitWrapper(fn, { name }) {
|
|
4035
|
+
return (fields, methods) => __async(this, null, function* () {
|
|
4036
|
+
const LOADING_NAME = name;
|
|
4037
|
+
setLoading(LOADING_NAME);
|
|
4038
|
+
try {
|
|
4039
|
+
yield fn(fields, methods);
|
|
4040
|
+
} catch (error) {
|
|
4041
|
+
errorHandler(error, methods.setErrors);
|
|
4042
|
+
} finally {
|
|
4043
|
+
setLoading(LOADING_NAME, true);
|
|
4044
|
+
}
|
|
4045
|
+
});
|
|
4046
|
+
}
|
|
4047
|
+
function onRequestWrapper(fn, { name }) {
|
|
4048
|
+
return (...params) => __async(this, null, function* () {
|
|
4049
|
+
if (name.includes("get:"))
|
|
4050
|
+
sourceRef.current = _axios2.default.CancelToken.source();
|
|
4051
|
+
const LOADING_NAME = name;
|
|
4052
|
+
setLoading(LOADING_NAME);
|
|
4053
|
+
api.interceptors.request.use(
|
|
4054
|
+
(config) => {
|
|
4055
|
+
var _a;
|
|
4056
|
+
if (!config.cancelToken && sourceRef.current && config.method === "get") {
|
|
4057
|
+
config.cancelToken = (_a = sourceRef.current) == null ? void 0 : _a.token;
|
|
4058
|
+
}
|
|
4059
|
+
return config;
|
|
4060
|
+
},
|
|
4061
|
+
(error) => {
|
|
4062
|
+
console.log("[middleware]");
|
|
4063
|
+
return Promise.reject(error);
|
|
4064
|
+
}
|
|
4065
|
+
);
|
|
4066
|
+
try {
|
|
4067
|
+
const response = yield fn(...params);
|
|
4068
|
+
return response;
|
|
4069
|
+
} catch (error) {
|
|
4070
|
+
errorHandler(error);
|
|
4071
|
+
} finally {
|
|
4072
|
+
setLoading(LOADING_NAME, true);
|
|
4073
|
+
}
|
|
4074
|
+
});
|
|
4075
|
+
}
|
|
4076
|
+
function errorHandler(error, callback) {
|
|
4077
|
+
if ((error == null ? void 0 : error.message) === "cancel.navigation")
|
|
4078
|
+
return;
|
|
4079
|
+
if (callback) {
|
|
4080
|
+
if (error.response.data.code === "invalid.body") {
|
|
4081
|
+
const errors = error.response.data.details.issues;
|
|
4082
|
+
const currentErrors = errors.reduce((acc, item) => {
|
|
4083
|
+
acc[item.path.join(".")] = item.message;
|
|
4084
|
+
return acc;
|
|
4085
|
+
}, {});
|
|
4086
|
+
callback(currentErrors);
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
createAlert(formatErrorMessage(error), "error");
|
|
4090
|
+
}
|
|
4091
|
+
_react.useEffect.call(void 0, () => {
|
|
4092
|
+
return () => {
|
|
4093
|
+
var _a;
|
|
4094
|
+
(_a = sourceRef.current) == null ? void 0 : _a.cancel("cancel.navigation");
|
|
4095
|
+
};
|
|
4096
|
+
}, []);
|
|
4097
|
+
return __spreadProps(__spreadValues(__spreadValues({}, alertProps), loadingProps), {
|
|
4098
|
+
onSubmitWrapper,
|
|
4099
|
+
onRequestWrapper
|
|
4100
|
+
});
|
|
4101
|
+
}
|
|
4102
|
+
|
|
4103
|
+
// src/hooks/useGrid.ts
|
|
4104
|
+
|
|
4105
|
+
|
|
4106
|
+
// src/hooks/useFilter.ts
|
|
4107
|
+
|
|
3819
4108
|
|
|
3820
4109
|
|
|
3821
4110
|
// src/components/utils/getObjectValue.ts
|
|
@@ -3823,9 +4112,7 @@ function getObjectValue(obj) {
|
|
|
3823
4112
|
return (prop) => prop.split(".").reduce((o, k) => o[k], obj);
|
|
3824
4113
|
}
|
|
3825
4114
|
|
|
3826
|
-
// src/
|
|
3827
|
-
|
|
3828
|
-
|
|
4115
|
+
// src/hooks/useFilter.ts
|
|
3829
4116
|
function useFilter() {
|
|
3830
4117
|
const [selectedFilters, setSelectedFilters] = _react.useState.call(void 0, []);
|
|
3831
4118
|
const filterBy = (newFilter) => {
|
|
@@ -3897,7 +4184,7 @@ function createFilter(filters) {
|
|
|
3897
4184
|
};
|
|
3898
4185
|
}
|
|
3899
4186
|
|
|
3900
|
-
// src/
|
|
4187
|
+
// src/hooks/useGrid.ts
|
|
3901
4188
|
function useGrid({
|
|
3902
4189
|
columns,
|
|
3903
4190
|
filters = [],
|
|
@@ -4030,7 +4317,7 @@ function createSearch(options) {
|
|
|
4030
4317
|
};
|
|
4031
4318
|
}
|
|
4032
4319
|
|
|
4033
|
-
// src/
|
|
4320
|
+
// src/hooks/useEvent.ts
|
|
4034
4321
|
|
|
4035
4322
|
function useEvent(event, handler, passive = false) {
|
|
4036
4323
|
_react.useEffect.call(void 0, () => {
|
|
@@ -4041,98 +4328,12 @@ function useEvent(event, handler, passive = false) {
|
|
|
4041
4328
|
});
|
|
4042
4329
|
}
|
|
4043
4330
|
|
|
4044
|
-
// src/components/hooks/useLoading.ts
|
|
4045
4331
|
|
|
4046
|
-
function useLoading() {
|
|
4047
|
-
const [state, setState] = _react.useState.call(void 0, []);
|
|
4048
|
-
const isLoading = (prop) => state.includes(prop);
|
|
4049
|
-
const setLoading = (prop, remove) => {
|
|
4050
|
-
if (remove)
|
|
4051
|
-
setState((prevState) => prevState.filter((state2) => state2 !== prop));
|
|
4052
|
-
else
|
|
4053
|
-
setState((prevState) => [...prevState, prop]);
|
|
4054
|
-
};
|
|
4055
|
-
return { isLoading, setLoading };
|
|
4056
|
-
}
|
|
4057
|
-
|
|
4058
|
-
// src/components/Modal/index.tsx
|
|
4059
4332
|
|
|
4060
4333
|
|
|
4061
4334
|
|
|
4062
4335
|
|
|
4063
4336
|
|
|
4064
|
-
var Modal = (_a) => {
|
|
4065
|
-
var _b = _a, { open, onClose } = _b, rest = __objRest(_b, ["open", "onClose"]);
|
|
4066
|
-
return /* @__PURE__ */ React4.default.createElement(_material.Modal, __spreadValues({ open, onClose, disableEnforceFocus: true }, rest), /* @__PURE__ */ React4.default.createElement(
|
|
4067
|
-
_material.Box,
|
|
4068
|
-
{
|
|
4069
|
-
sx: {
|
|
4070
|
-
outline: "none",
|
|
4071
|
-
backgroundColor: "white",
|
|
4072
|
-
position: "absolute",
|
|
4073
|
-
top: "50%",
|
|
4074
|
-
left: "50%",
|
|
4075
|
-
transform: "translate(-50%, -50%)",
|
|
4076
|
-
borderRadius: 1
|
|
4077
|
-
}
|
|
4078
|
-
},
|
|
4079
|
-
/* @__PURE__ */ React4.default.createElement(React4.default.Fragment, null, rest.children)
|
|
4080
|
-
));
|
|
4081
|
-
};
|
|
4082
|
-
|
|
4083
|
-
// src/components/utils/GetInputLabel.ts
|
|
4084
|
-
function GetInputLabel(columns) {
|
|
4085
|
-
return (columnName) => {
|
|
4086
|
-
const column = columns.find((column2) => column2.name === columnName);
|
|
4087
|
-
return { label: column.label, name: column.name };
|
|
4088
|
-
};
|
|
4089
|
-
}
|
|
4090
|
-
|
|
4091
|
-
// src/components/Dialog/index.tsx
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
var Dialog = (_a) => {
|
|
4103
|
-
var _b = _a, {
|
|
4104
|
-
open,
|
|
4105
|
-
title,
|
|
4106
|
-
loading,
|
|
4107
|
-
body,
|
|
4108
|
-
options
|
|
4109
|
-
} = _b, rest = __objRest(_b, [
|
|
4110
|
-
"open",
|
|
4111
|
-
"title",
|
|
4112
|
-
"loading",
|
|
4113
|
-
"body",
|
|
4114
|
-
"options"
|
|
4115
|
-
]);
|
|
4116
|
-
return /* @__PURE__ */ React4.default.createElement(_material.Dialog, __spreadValues({ open }, rest), /* @__PURE__ */ React4.default.createElement(_material.Box, { sx: { p: 2 } }, /* @__PURE__ */ React4.default.createElement(_material.DialogTitle, { sx: { fontWeight: "bold" } }, title), /* @__PURE__ */ React4.default.createElement(_material.DialogContentText, { sx: { px: "10px", textAlign: "center", mb: 2 } }, body), /* @__PURE__ */ React4.default.createElement(_material.DialogActions, null, options.map((option, index) => {
|
|
4117
|
-
return /* @__PURE__ */ React4.default.createElement(
|
|
4118
|
-
_material.Button,
|
|
4119
|
-
{
|
|
4120
|
-
key: index,
|
|
4121
|
-
onClick: () => option.cb(option.label),
|
|
4122
|
-
variant: option.focus ? "contained" : "text",
|
|
4123
|
-
sx: {
|
|
4124
|
-
fontWeight: option.focus ? "bold" : "normal",
|
|
4125
|
-
color: option.focus ? "#fff" : "primary.main"
|
|
4126
|
-
},
|
|
4127
|
-
disableElevation: true,
|
|
4128
|
-
disabled: loading
|
|
4129
|
-
},
|
|
4130
|
-
loading && option.focus ? /* @__PURE__ */ React4.default.createElement(_material.CircularProgress, { size: 25, color: "inherit" }) : /* @__PURE__ */ React4.default.createElement(React4.default.Fragment, null, option.label)
|
|
4131
|
-
);
|
|
4132
|
-
}))));
|
|
4133
|
-
};
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
4337
|
|
|
4137
4338
|
|
|
4138
4339
|
|
|
@@ -4156,7 +4357,7 @@ var Dialog = (_a) => {
|
|
|
4156
4357
|
|
|
4157
4358
|
|
|
4158
4359
|
|
|
4159
|
-
exports.Autocomplete = Autocomplete2; exports.BaseGrid = BaseGrid; exports.Checkbox = Checkbox; exports.Dialog = Dialog; exports.EditableTableCell = EditableTableCell; exports.GetInputLabel = GetInputLabel; exports.Grid = Grid_default; exports.Input = Input; exports.InputMask = InputMask2; exports.LargeButton = LargeButton; exports.Modal = Modal; exports.Radio = Radio; exports.Select = Select; exports.Switch = Switch; exports.TabPanel = TabPanel; exports.Td = Td; exports.Tr = Tr; exports.createFilter = createFilter; exports.filterData = filterData; exports.getTabProps = getTabProps; exports.useEvent = useEvent; exports.useFilter = useFilter; exports.useGrid = useGrid; exports.useLoading = useLoading;
|
|
4360
|
+
exports.AlertContext = AlertContext; exports.ApiHelper = ApiHelper; exports.Autocomplete = Autocomplete2; exports.BaseGrid = BaseGrid; exports.Checkbox = Checkbox; exports.Dialog = Dialog; exports.EditableTableCell = EditableTableCell; exports.GetInputLabel = GetInputLabel; exports.Grid = Grid_default; exports.HttpError = HttpError; exports.Input = Input; exports.InputMask = InputMask2; exports.LargeButton = LargeButton; exports.Modal = Modal; exports.Radio = Radio; exports.Select = Select; exports.Switch = Switch; exports.TabPanel = TabPanel; exports.Td = Td; exports.Tr = Tr; exports.createFilter = createFilter; exports.filterData = filterData; exports.getTabProps = getTabProps; exports.useAlert = useAlert; exports.useEvent = useEvent; exports.useFilter = useFilter; exports.useFormHelper = useFormHelper; exports.useGrid = useGrid; exports.useLoading = useLoading;
|
|
4160
4361
|
/*! Bundled license information:
|
|
4161
4362
|
|
|
4162
4363
|
react-is/cjs/react-is.production.min.js:
|