@bluemarble/bm-components 2.4.1 → 3.0.0-beta.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 CHANGED
@@ -206,7 +206,7 @@ var require_react_is_development = __commonJS({
206
206
  var ContextProvider = REACT_PROVIDER_TYPE;
207
207
  var Element = REACT_ELEMENT_TYPE;
208
208
  var ForwardRef = REACT_FORWARD_REF_TYPE;
209
- var Fragment3 = REACT_FRAGMENT_TYPE;
209
+ var Fragment10 = REACT_FRAGMENT_TYPE;
210
210
  var Lazy = REACT_LAZY_TYPE;
211
211
  var Memo = REACT_MEMO_TYPE;
212
212
  var Portal2 = REACT_PORTAL_TYPE;
@@ -265,7 +265,7 @@ var require_react_is_development = __commonJS({
265
265
  exports.ContextProvider = ContextProvider;
266
266
  exports.Element = Element;
267
267
  exports.ForwardRef = ForwardRef;
268
- exports.Fragment = Fragment3;
268
+ exports.Fragment = Fragment10;
269
269
  exports.Lazy = Lazy;
270
270
  exports.Memo = Memo;
271
271
  exports.Portal = Portal2;
@@ -1179,8 +1179,278 @@ var require_react_is2 = __commonJS({
1179
1179
  }
1180
1180
  });
1181
1181
 
1182
+ // packages/http-client/types.ts
1183
+ var HttpClientError = class _HttpClientError extends Error {
1184
+ constructor(status, statusText, data) {
1185
+ super(`Request failed with status ${status}: ${statusText}`);
1186
+ this.name = "HttpClientError";
1187
+ this.status = status;
1188
+ this.statusText = statusText;
1189
+ this.data = data;
1190
+ }
1191
+ static isHttpClientError(e) {
1192
+ return e instanceof _HttpClientError;
1193
+ }
1194
+ };
1195
+
1196
+ // packages/http-client/util.ts
1197
+ function buildURL(base, path, params) {
1198
+ const url = base ? `${base.replace(/\/$/, "")}/${path.replace(/^\//, "")}` : path;
1199
+ if (!params || Object.keys(params).length === 0) return url;
1200
+ const query = new URLSearchParams(
1201
+ Object.entries(params).map(([k, v]) => [k, String(v)])
1202
+ ).toString();
1203
+ return `${url}?${query}`;
1204
+ }
1205
+ function buildHeaders(defaults, overrides, token) {
1206
+ const headers = {
1207
+ "Content-Type": "application/json",
1208
+ ...defaults,
1209
+ ...overrides
1210
+ };
1211
+ if (token) {
1212
+ headers["Authorization"] = `Bearer ${token}`;
1213
+ }
1214
+ return headers;
1215
+ }
1216
+ function toRecord(headers) {
1217
+ const record = {};
1218
+ headers.forEach((value, key) => {
1219
+ record[key] = value;
1220
+ });
1221
+ return record;
1222
+ }
1223
+ function withTimeout(ms, external) {
1224
+ if (!ms && !external) {
1225
+ const controller2 = new AbortController();
1226
+ return { signal: controller2.signal, clear: () => {
1227
+ } };
1228
+ }
1229
+ if (!ms && external) {
1230
+ return { signal: external, clear: () => {
1231
+ } };
1232
+ }
1233
+ const controller = new AbortController();
1234
+ const timer = setTimeout(() => controller.abort(new DOMException("Request timed out", "TimeoutError")), ms);
1235
+ if (external) {
1236
+ external.addEventListener("abort", () => controller.abort(external.reason), { once: true });
1237
+ }
1238
+ return {
1239
+ signal: controller.signal,
1240
+ clear: () => clearTimeout(timer)
1241
+ };
1242
+ }
1243
+
1244
+ // packages/http-client/index.ts
1245
+ async function executeRequest(reqConfig, clientConfig, defaultHeaders, token, instanceSignal) {
1246
+ const url = buildURL(clientConfig.baseURL, reqConfig.url, reqConfig.params);
1247
+ const headers = buildHeaders(defaultHeaders, reqConfig.headers, token);
1248
+ const timeout = reqConfig.timeout ?? clientConfig.timeout;
1249
+ const externalSignal = reqConfig.signal ? AbortSignal.any([reqConfig.signal, instanceSignal]) : instanceSignal;
1250
+ const { signal, clear } = withTimeout(timeout, externalSignal);
1251
+ try {
1252
+ const response = await fetch(url, {
1253
+ method: reqConfig.method ?? "GET",
1254
+ headers,
1255
+ body: reqConfig.data != null ? JSON.stringify(reqConfig.data) : void 0,
1256
+ signal
1257
+ });
1258
+ if (!response.ok) {
1259
+ const contentType = response.headers.get("content-type") ?? "";
1260
+ const errData = contentType.includes("application/json") ? await response.json() : await response.text();
1261
+ throw new HttpClientError(response.status, response.statusText, errData);
1262
+ }
1263
+ let data;
1264
+ const responseType = reqConfig.responseType;
1265
+ if (responseType === "arraybuffer") {
1266
+ data = await response.arrayBuffer();
1267
+ } else if (responseType === "blob") {
1268
+ data = await response.blob();
1269
+ } else if (responseType === "text") {
1270
+ data = await response.text();
1271
+ } else if (responseType === "json") {
1272
+ data = await response.json();
1273
+ } else {
1274
+ const contentType = response.headers.get("content-type") ?? "";
1275
+ data = contentType.includes("application/json") ? await response.json() : await response.text();
1276
+ }
1277
+ return {
1278
+ data,
1279
+ status: response.status,
1280
+ statusText: response.statusText,
1281
+ headers: toRecord(response.headers)
1282
+ };
1283
+ } finally {
1284
+ clear();
1285
+ }
1286
+ }
1287
+ function createHttpClient(clientConfig = {}) {
1288
+ const { auth } = clientConfig;
1289
+ const maxRetries = auth?.maxRetries ?? 1;
1290
+ const defaultHeaders = { ...clientConfig.headers };
1291
+ let abortController = new AbortController();
1292
+ async function request(reqConfig) {
1293
+ const token = auth ? await auth.getToken() : null;
1294
+ let attemptsLeft = maxRetries;
1295
+ try {
1296
+ return await executeRequest(reqConfig, clientConfig, defaultHeaders, token, abortController.signal);
1297
+ } catch (err) {
1298
+ if (!HttpClientError.isHttpClientError(err) || err.status !== 401) throw err;
1299
+ if (!auth?.refreshToken) throw err;
1300
+ while (attemptsLeft > 0) {
1301
+ attemptsLeft--;
1302
+ const newToken = await auth.refreshToken();
1303
+ try {
1304
+ return await executeRequest(reqConfig, clientConfig, defaultHeaders, newToken, abortController.signal);
1305
+ } catch (retryErr) {
1306
+ if (!HttpClientError.isHttpClientError(retryErr) || retryErr.status !== 401) throw retryErr;
1307
+ if (attemptsLeft === 0) throw retryErr;
1308
+ }
1309
+ }
1310
+ throw err;
1311
+ }
1312
+ }
1313
+ return {
1314
+ request,
1315
+ get(url, config) {
1316
+ return request({ ...config, url, method: "GET" });
1317
+ },
1318
+ post(url, data, config) {
1319
+ return request({ ...config, url, method: "POST", data });
1320
+ },
1321
+ put(url, data, config) {
1322
+ return request({ ...config, url, method: "PUT", data });
1323
+ },
1324
+ patch(url, data, config) {
1325
+ return request({ ...config, url, method: "PATCH", data });
1326
+ },
1327
+ delete(url, config) {
1328
+ return request({ ...config, url, method: "DELETE" });
1329
+ },
1330
+ setHeader(key, value) {
1331
+ if (value === null) {
1332
+ delete defaultHeaders[key];
1333
+ } else {
1334
+ defaultHeaders[key] = value;
1335
+ }
1336
+ },
1337
+ abort() {
1338
+ abortController.abort();
1339
+ abortController = new AbortController();
1340
+ }
1341
+ };
1342
+ }
1343
+
1344
+ // packages/nookies/index.ts
1345
+ import * as cookie from "cookie";
1346
+ import * as setCookieParser from "set-cookie-parser";
1347
+
1348
+ // packages/nookies/util.ts
1349
+ function isBrowser() {
1350
+ return typeof window !== "undefined";
1351
+ }
1352
+ function createCookie(name, value, options) {
1353
+ let sameSite = options.sameSite;
1354
+ if (sameSite === true) {
1355
+ sameSite = "strict";
1356
+ }
1357
+ if (sameSite === void 0 || sameSite === false) {
1358
+ sameSite = "lax";
1359
+ }
1360
+ const cookieToSet = { ...options, sameSite };
1361
+ delete cookieToSet.encode;
1362
+ return {
1363
+ name,
1364
+ value,
1365
+ ...cookieToSet
1366
+ };
1367
+ }
1368
+ function hasSameProperties(a, b) {
1369
+ const aProps = Object.getOwnPropertyNames(a);
1370
+ const bProps = Object.getOwnPropertyNames(b);
1371
+ if (aProps.length !== bProps.length) {
1372
+ return false;
1373
+ }
1374
+ for (let i = 0; i < aProps.length; i++) {
1375
+ const propName = aProps[i];
1376
+ if (a[propName] !== b[propName]) {
1377
+ return false;
1378
+ }
1379
+ }
1380
+ return true;
1381
+ }
1382
+ function areCookiesEqual(a, b) {
1383
+ let sameSiteSame = a.sameSite === b.sameSite;
1384
+ if (typeof a.sameSite === "string" && typeof b.sameSite === "string") {
1385
+ sameSiteSame = a.sameSite.toLowerCase() === b.sameSite.toLowerCase();
1386
+ }
1387
+ return hasSameProperties(
1388
+ { ...a, sameSite: void 0 },
1389
+ { ...b, sameSite: void 0 }
1390
+ ) && sameSiteSame;
1391
+ }
1392
+
1393
+ // packages/nookies/index.ts
1394
+ function parseCookies(ctx, options) {
1395
+ if (ctx?.req?.headers?.cookie) {
1396
+ return cookie.parse(ctx.req.headers.cookie, options);
1397
+ }
1398
+ if (isBrowser()) {
1399
+ return cookie.parse(document.cookie, options);
1400
+ }
1401
+ return {};
1402
+ }
1403
+ function setCookie(ctx, name, value, options = {}) {
1404
+ if (ctx?.res?.getHeader && ctx.res.setHeader) {
1405
+ if (ctx?.res?.finished) {
1406
+ console.warn(`Not setting "${name}" cookie. Response has finished.`);
1407
+ console.warn(`You should set cookie before res.send()`);
1408
+ return {};
1409
+ }
1410
+ let cookies = ctx.res.getHeader("Set-Cookie") || [];
1411
+ if (typeof cookies === "string") cookies = [cookies];
1412
+ if (typeof cookies === "number") cookies = [];
1413
+ const parsedCookies = setCookieParser.parse(cookies, {
1414
+ decodeValues: false
1415
+ });
1416
+ const newCookie = createCookie(name, value, options);
1417
+ let cookiesToSet = [];
1418
+ parsedCookies.forEach((parsedCookie) => {
1419
+ if (!areCookiesEqual(parsedCookie, newCookie)) {
1420
+ const serializedCookie = cookie.serialize(
1421
+ parsedCookie.name,
1422
+ parsedCookie.value,
1423
+ {
1424
+ // we prevent reencoding by default, but you might override it
1425
+ encode: (val) => val,
1426
+ ...parsedCookie
1427
+ }
1428
+ );
1429
+ cookiesToSet.push(serializedCookie);
1430
+ }
1431
+ });
1432
+ cookiesToSet.push(cookie.serialize(name, value, options));
1433
+ ctx.res.setHeader("Set-Cookie", cookiesToSet);
1434
+ }
1435
+ if (isBrowser()) {
1436
+ if (options && options.httpOnly) {
1437
+ throw new Error("Can not set a httpOnly cookie in the browser.");
1438
+ }
1439
+ document.cookie = cookie.serialize(name, value, options);
1440
+ }
1441
+ return {};
1442
+ }
1443
+ function destroyCookie(ctx, name, options) {
1444
+ return setCookie(ctx, name, "", { ...options || {}, maxAge: -1 });
1445
+ }
1446
+ var nookies = {
1447
+ set: setCookie,
1448
+ get: parseCookies,
1449
+ destroy: destroyCookie
1450
+ };
1451
+
1182
1452
  // src/components/Grid/Grid.tsx
1183
- import React7, {
1453
+ import {
1184
1454
  useEffect,
1185
1455
  useMemo,
1186
1456
  useRef,
@@ -1203,8 +1473,8 @@ import {
1203
1473
  } from "@mui/material";
1204
1474
 
1205
1475
  // src/components/Grid/Header.tsx
1206
- import React from "react";
1207
1476
  import { TableCell, TableHead, TableRow, TableSortLabel } from "@mui/material";
1477
+ import { jsx } from "react/jsx-runtime";
1208
1478
  var GridHeader = ({
1209
1479
  setOrder,
1210
1480
  setOrderBy,
@@ -1232,34 +1502,31 @@ var GridHeader = ({
1232
1502
  break;
1233
1503
  }
1234
1504
  }
1235
- return /* @__PURE__ */ React.createElement(TableHead, null, /* @__PURE__ */ React.createElement(TableRow, { sx: { backgroundColor: "background.default" } }, titles.map((title) => {
1236
- return /* @__PURE__ */ React.createElement(
1505
+ return /* @__PURE__ */ jsx(TableHead, { children: /* @__PURE__ */ jsx(TableRow, { sx: { backgroundColor: "background.default" }, children: titles.map((title) => {
1506
+ return /* @__PURE__ */ jsx(
1237
1507
  TableCell,
1238
1508
  {
1239
- key: title.name,
1240
1509
  sortDirection: orderBy === title.name ? order : false,
1241
- sx: { fontWeight: "bold", ...title.sx }
1242
- },
1243
- /* @__PURE__ */ React.createElement(
1244
- TableSortLabel,
1245
- {
1246
- onClick: () => onRequestSort(title.name),
1247
- active: orderBy === title.name,
1248
- direction: orderBy === title.name ? order : "asc",
1249
- sx: {
1250
- position: "relative",
1251
- svg: { position: "absolute", right: "27px" }
1510
+ sx: { fontWeight: "bold", ...title.sx },
1511
+ children: /* @__PURE__ */ jsx(
1512
+ TableSortLabel,
1513
+ {
1514
+ onClick: () => onRequestSort(title.name),
1515
+ active: orderBy === title.name,
1516
+ direction: orderBy === title.name ? order : "asc",
1517
+ sx: {
1518
+ position: "relative",
1519
+ svg: { position: "absolute", right: "27px" }
1520
+ },
1521
+ children: title.label
1252
1522
  }
1253
- },
1254
- title.label
1255
- )
1523
+ )
1524
+ },
1525
+ title.name
1256
1526
  );
1257
- })));
1527
+ }) }) });
1258
1528
  };
1259
1529
 
1260
- // src/components/Grid/Filters.tsx
1261
- import React5 from "react";
1262
-
1263
1530
  // node_modules/@mui/utils/esm/formatMuiErrorMessage/formatMuiErrorMessage.js
1264
1531
  function formatMuiErrorMessage(code, ...args) {
1265
1532
  const url = new URL(`https://mui.com/production-error/?code=${code}`);
@@ -1288,7 +1555,7 @@ function styled(tag, options) {
1288
1555
 
1289
1556
  // node_modules/@mui/utils/esm/deepmerge/deepmerge.js
1290
1557
  var import_react_is = __toESM(require_react_is2(), 1);
1291
- import * as React2 from "react";
1558
+ import * as React from "react";
1292
1559
  function isPlainObject(item) {
1293
1560
  if (typeof item !== "object" || item === null) {
1294
1561
  return false;
@@ -1297,7 +1564,7 @@ function isPlainObject(item) {
1297
1564
  return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in item) && !(Symbol.iterator in item);
1298
1565
  }
1299
1566
  function deepClone(source) {
1300
- if (/* @__PURE__ */ React2.isValidElement(source) || (0, import_react_is.isValidElementType)(source) || !isPlainObject(source)) {
1567
+ if (/* @__PURE__ */ React.isValidElement(source) || (0, import_react_is.isValidElementType)(source) || !isPlainObject(source)) {
1301
1568
  return source;
1302
1569
  }
1303
1570
  const output = {};
@@ -1314,7 +1581,7 @@ function deepmerge(target, source, options = {
1314
1581
  } : target;
1315
1582
  if (isPlainObject(target) && isPlainObject(source)) {
1316
1583
  Object.keys(source).forEach((key) => {
1317
- if (/* @__PURE__ */ React2.isValidElement(source[key]) || (0, import_react_is.isValidElementType)(source[key])) {
1584
+ if (/* @__PURE__ */ React.isValidElement(source[key]) || (0, import_react_is.isValidElementType)(source[key])) {
1318
1585
  output[key] = source[key];
1319
1586
  } else if (isPlainObject(source[key]) && // Avoid prototype pollution
1320
1587
  Object.prototype.hasOwnProperty.call(target, key) && isPlainObject(target[key])) {
@@ -2531,12 +2798,12 @@ function createTheme(options = {}, ...args) {
2531
2798
  var createTheme_default = createTheme;
2532
2799
 
2533
2800
  // node_modules/@mui/system/esm/useThemeWithoutDefault/useThemeWithoutDefault.js
2534
- import * as React3 from "react";
2801
+ import * as React2 from "react";
2535
2802
  function isObjectEmpty(obj) {
2536
2803
  return Object.keys(obj).length === 0;
2537
2804
  }
2538
2805
  function useTheme(defaultTheme = null) {
2539
- const contextTheme = React3.useContext(ThemeContext);
2806
+ const contextTheme = React2.useContext(ThemeContext);
2540
2807
  return !contextTheme || isObjectEmpty(contextTheme) ? defaultTheme : contextTheme;
2541
2808
  }
2542
2809
  var useThemeWithoutDefault_default = useTheme;
@@ -2622,7 +2889,7 @@ var ClassNameGenerator = createClassNameGenerator();
2622
2889
  var ClassNameGenerator_default = ClassNameGenerator;
2623
2890
 
2624
2891
  // node_modules/@mui/system/esm/createBox/createBox.js
2625
- import * as React4 from "react";
2892
+ import * as React3 from "react";
2626
2893
 
2627
2894
  // node_modules/clsx/dist/clsx.mjs
2628
2895
  function r(e) {
@@ -2652,7 +2919,7 @@ function createBox(options = {}) {
2652
2919
  const BoxRoot = styled("div", {
2653
2920
  shouldForwardProp: (prop) => prop !== "theme" && prop !== "sx" && prop !== "as"
2654
2921
  })(styleFunctionSx_default);
2655
- const Box9 = /* @__PURE__ */ React4.forwardRef(function Box10(inProps, ref) {
2922
+ const Box9 = /* @__PURE__ */ React3.forwardRef(function Box10(inProps, ref) {
2656
2923
  const theme = useTheme_default(defaultTheme);
2657
2924
  const {
2658
2925
  className,
@@ -2732,6 +2999,7 @@ var Box_default = Box;
2732
2999
  // src/components/Grid/Filters.tsx
2733
3000
  import { MdFilterList, MdSearch } from "react-icons/md";
2734
3001
  import { Chip, IconButton, Tooltip } from "@mui/material";
3002
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
2735
3003
  var FiltersBar = ({
2736
3004
  customButtons,
2737
3005
  selectedFilters,
@@ -2742,7 +3010,7 @@ var FiltersBar = ({
2742
3010
  setAnchorEl,
2743
3011
  noFilters
2744
3012
  }) => {
2745
- return /* @__PURE__ */ React5.createElement(
3013
+ return /* @__PURE__ */ jsxs(
2746
3014
  Box_default,
2747
3015
  {
2748
3016
  sx: {
@@ -2750,26 +3018,34 @@ var FiltersBar = ({
2750
3018
  justifyContent: "space-between",
2751
3019
  alignItems: "center",
2752
3020
  width: "100%"
2753
- }
2754
- },
2755
- !noFilters && /* @__PURE__ */ React5.createElement(Box_default, { sx: { pl: 1 } }, selectedFilters.map((item, index) => {
2756
- return /* @__PURE__ */ React5.createElement(
2757
- Chip,
2758
- {
2759
- key: index,
2760
- label: item.value,
2761
- onDelete: () => handleCloseFilter(item)
2762
- }
2763
- );
2764
- })),
2765
- /* @__PURE__ */ React5.createElement(Box_default, { ref: searchAnchorEl, sx: { minHeight: 30, width: "100%" } }, customButtons, !noFilterButtons && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(Tooltip, { title: "Buscar" }, /* @__PURE__ */ React5.createElement(IconButton, { onClick: () => setOpenSearch(true) }, /* @__PURE__ */ React5.createElement(MdSearch, { size: 8 * 3 }))), /* @__PURE__ */ React5.createElement(Tooltip, { title: "Filtrar" }, /* @__PURE__ */ React5.createElement(
2766
- IconButton,
2767
- {
2768
- sx: { position: "relative" },
2769
- onClick: ({ currentTarget }) => setAnchorEl(currentTarget)
2770
3021
  },
2771
- /* @__PURE__ */ React5.createElement(MdFilterList, { size: 8 * 3 })
2772
- ))))
3022
+ children: [
3023
+ !noFilters && /* @__PURE__ */ jsx2(Box_default, { sx: { pl: 1 }, children: selectedFilters.map((item, index) => {
3024
+ return /* @__PURE__ */ jsx2(
3025
+ Chip,
3026
+ {
3027
+ label: item.value,
3028
+ onDelete: () => handleCloseFilter(item)
3029
+ },
3030
+ index
3031
+ );
3032
+ }) }),
3033
+ /* @__PURE__ */ jsxs(Box_default, { ref: searchAnchorEl, sx: { minHeight: 30, width: "100%" }, children: [
3034
+ customButtons,
3035
+ !noFilterButtons && /* @__PURE__ */ jsxs(Fragment, { children: [
3036
+ /* @__PURE__ */ jsx2(Tooltip, { title: "Buscar", children: /* @__PURE__ */ jsx2(IconButton, { onClick: () => setOpenSearch(true), children: /* @__PURE__ */ jsx2(MdSearch, { size: 8 * 3 }) }) }),
3037
+ /* @__PURE__ */ jsx2(Tooltip, { title: "Filtrar", children: /* @__PURE__ */ jsx2(
3038
+ IconButton,
3039
+ {
3040
+ sx: { position: "relative" },
3041
+ onClick: ({ currentTarget }) => setAnchorEl(currentTarget),
3042
+ children: /* @__PURE__ */ jsx2(MdFilterList, { size: 8 * 3 })
3043
+ }
3044
+ ) })
3045
+ ] })
3046
+ ] })
3047
+ ]
3048
+ }
2773
3049
  );
2774
3050
  };
2775
3051
 
@@ -2795,9 +3071,6 @@ function getPropertyValue(obj, property) {
2795
3071
  return String(property.split(".").reduce((o, k) => o && o[k], obj));
2796
3072
  }
2797
3073
 
2798
- // src/components/Grid/AutoCreatedRows.tsx
2799
- import React6 from "react";
2800
-
2801
3074
  // src/components/Grid/Td.tsx
2802
3075
  import { TableCell as TableCell2 } from "@mui/material";
2803
3076
  var Td = TableCell2;
@@ -2807,18 +3080,20 @@ import { TableRow as TableRow2 } from "@mui/material";
2807
3080
  var Tr = TableRow2;
2808
3081
 
2809
3082
  // src/components/Grid/AutoCreatedRows.tsx
3083
+ import { Fragment as Fragment2, jsx as jsx3 } from "react/jsx-runtime";
2810
3084
  var AutoCreatedRows = ({
2811
3085
  tableData,
2812
3086
  columns,
2813
3087
  primaryKey
2814
3088
  }) => {
2815
- return /* @__PURE__ */ React6.createElement(React6.Fragment, null, tableData.map((row) => /* @__PURE__ */ React6.createElement(Tr, { key: row[primaryKey] }, columns.map((column) => {
3089
+ return /* @__PURE__ */ jsx3(Fragment2, { children: tableData.map((row) => /* @__PURE__ */ jsx3(Tr, { children: columns.map((column) => {
2816
3090
  const cellValue = column.transformer ? column.transformer(row[column.name]) : row[column.name];
2817
- return /* @__PURE__ */ React6.createElement(Td, { key: column.name }, cellValue);
2818
- }))));
3091
+ return /* @__PURE__ */ jsx3(Td, { children: cellValue }, column.name);
3092
+ }) }, row[primaryKey])) });
2819
3093
  };
2820
3094
 
2821
3095
  // src/components/Grid/Grid.tsx
3096
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
2822
3097
  var Grid = (props) => {
2823
3098
  const {
2824
3099
  columnTitles,
@@ -2992,170 +3267,191 @@ var Grid = (props) => {
2992
3267
  useEffect(() => {
2993
3268
  updateFilters(selectedFilters);
2994
3269
  }, [selectedFilters]);
2995
- return /* @__PURE__ */ React7.createElement(Paper, null, isLoading && /* @__PURE__ */ React7.createElement(LinearProgress, null), /* @__PURE__ */ React7.createElement(
2996
- FiltersBar,
2997
- {
2998
- setAnchorEl,
2999
- setOpenSearch,
3000
- searchAnchorEl,
3001
- noFilters,
3002
- noFilterButtons,
3003
- selectedFilters,
3004
- customButtons,
3005
- handleCloseFilter
3006
- }
3007
- ), /* @__PURE__ */ React7.createElement(TableContainer, null, /* @__PURE__ */ React7.createElement(Table, { size: "small" }, /* @__PURE__ */ React7.createElement(
3008
- GridHeader,
3009
- {
3010
- titles: columnTitles,
3011
- order,
3012
- orderBy,
3013
- setOrder,
3014
- setOrderBy
3015
- }
3016
- ), /* @__PURE__ */ React7.createElement(TableBody, null, props.children ? props.children : primaryKey ? /* @__PURE__ */ React7.createElement(
3017
- AutoCreatedRows,
3018
- {
3019
- tableData,
3020
- columns: columnTitles,
3021
- primaryKey
3022
- }
3023
- ) : null, footer))), !noPagination && /* @__PURE__ */ React7.createElement(
3024
- TablePagination,
3025
- {
3026
- page,
3027
- component: "div",
3028
- rowsPerPage,
3029
- labelRowsPerPage: "Linhas por p\xE1gina",
3030
- rowsPerPageOptions: rowOptions,
3031
- count: countRows,
3032
- labelDisplayedRows: ({ page: page2 }) => `${page2 + 1} de ${Math.floor(countRows / rowsPerPage) + 1}`,
3033
- onPageChange: (_, newPage) => {
3034
- setPage(newPage);
3035
- },
3036
- onRowsPerPageChange: handleChangeRowsPerPage
3037
- }
3038
- ), /* @__PURE__ */ React7.createElement(
3039
- Popover,
3040
- {
3041
- anchorEl,
3042
- open: !!anchorEl,
3043
- onClose: () => setAnchorEl(null),
3044
- anchorOrigin: {
3045
- vertical: "top",
3046
- horizontal: "right"
3047
- },
3048
- transformOrigin: {
3049
- vertical: "top",
3050
- horizontal: "right"
3051
- }
3052
- },
3053
- /* @__PURE__ */ React7.createElement(Box2, { sx: { minWidth: 300, padding: 2 } }, /* @__PURE__ */ React7.createElement(Typography, { fontWeight: "bold", variant: "body2" }, "Filtrar por:"), /* @__PURE__ */ React7.createElement(
3054
- Autocomplete,
3270
+ return /* @__PURE__ */ jsxs2(Paper, { children: [
3271
+ isLoading && /* @__PURE__ */ jsx4(LinearProgress, {}),
3272
+ /* @__PURE__ */ jsx4(
3273
+ FiltersBar,
3055
3274
  {
3056
- value: selectedTitle || "",
3057
- onChange: ({ target }) => {
3058
- !target.innerHTML.includes("path") ? setSelectedTitle(target.innerHTML) : setSelectedTitle(void 0);
3059
- },
3060
- options: columnTitles.map((title) => title.label),
3061
- renderInput: (params) => /* @__PURE__ */ React7.createElement(
3062
- TextField,
3275
+ setAnchorEl,
3276
+ setOpenSearch,
3277
+ searchAnchorEl,
3278
+ noFilters,
3279
+ noFilterButtons,
3280
+ selectedFilters,
3281
+ customButtons,
3282
+ handleCloseFilter
3283
+ }
3284
+ ),
3285
+ /* @__PURE__ */ jsx4(TableContainer, { children: /* @__PURE__ */ jsxs2(Table, { size: "small", children: [
3286
+ /* @__PURE__ */ jsx4(
3287
+ GridHeader,
3288
+ {
3289
+ titles: columnTitles,
3290
+ order,
3291
+ orderBy,
3292
+ setOrder,
3293
+ setOrderBy
3294
+ }
3295
+ ),
3296
+ /* @__PURE__ */ jsxs2(TableBody, { children: [
3297
+ props.children ? props.children : primaryKey ? /* @__PURE__ */ jsx4(
3298
+ AutoCreatedRows,
3063
3299
  {
3064
- variant: "standard",
3065
- margin: "dense",
3066
- ...params,
3067
- label: "Coluna"
3300
+ tableData,
3301
+ columns: columnTitles,
3302
+ primaryKey
3068
3303
  }
3069
- )
3070
- }
3071
- ), /* @__PURE__ */ React7.createElement(
3072
- Autocomplete,
3304
+ ) : null,
3305
+ footer
3306
+ ] })
3307
+ ] }) }),
3308
+ !noPagination && /* @__PURE__ */ jsx4(
3309
+ TablePagination,
3073
3310
  {
3074
- value: selectedFilterValue || "",
3075
- onChange: ({ target }) => {
3076
- !target.innerHTML.includes("path") ? setSelectedFilterValue(target.innerHTML) : setSelectedFilterValue(void 0);
3311
+ page,
3312
+ component: "div",
3313
+ rowsPerPage,
3314
+ labelRowsPerPage: "Linhas por p\xE1gina",
3315
+ rowsPerPageOptions: rowOptions,
3316
+ count: countRows,
3317
+ labelDisplayedRows: ({ page: page2 }) => `${page2 + 1} de ${Math.floor(countRows / rowsPerPage) + 1}`,
3318
+ onPageChange: (_, newPage) => {
3319
+ setPage(newPage);
3077
3320
  },
3078
- disabled: valuesToFilter.length < 1,
3079
- options: valuesToFilter.map((title) => title),
3080
- renderInput: (params) => /* @__PURE__ */ React7.createElement(
3081
- TextField,
3082
- {
3083
- variant: "standard",
3084
- margin: "dense",
3085
- ...params,
3086
- label: "Valor"
3087
- }
3088
- )
3321
+ onRowsPerPageChange: handleChangeRowsPerPage
3089
3322
  }
3090
- ), /* @__PURE__ */ React7.createElement(Box2, { sx: { py: 1 } }), /* @__PURE__ */ React7.createElement(
3091
- Button,
3323
+ ),
3324
+ /* @__PURE__ */ jsx4(
3325
+ Popover,
3092
3326
  {
3093
- disabled: !selectedFilterValue,
3094
- onClick: handleAddFilter,
3095
- fullWidth: true
3096
- },
3097
- "Adicionar filtro"
3098
- ))
3099
- ), /* @__PURE__ */ React7.createElement(
3100
- Popover,
3101
- {
3102
- anchorEl: searchAnchorEl.current,
3103
- open: openSearch,
3104
- onClose: () => setOpenSearch(false),
3105
- anchorOrigin: {
3106
- vertical: "top",
3107
- horizontal: "left"
3108
- },
3109
- transformOrigin: {
3110
- vertical: "top",
3111
- horizontal: "left"
3327
+ anchorEl,
3328
+ open: !!anchorEl,
3329
+ onClose: () => setAnchorEl(null),
3330
+ anchorOrigin: {
3331
+ vertical: "top",
3332
+ horizontal: "right"
3333
+ },
3334
+ transformOrigin: {
3335
+ vertical: "top",
3336
+ horizontal: "right"
3337
+ },
3338
+ children: /* @__PURE__ */ jsxs2(Box2, { sx: { minWidth: 300, padding: 2 }, children: [
3339
+ /* @__PURE__ */ jsx4(Typography, { fontWeight: "bold", variant: "body2", children: "Filtrar por:" }),
3340
+ /* @__PURE__ */ jsx4(
3341
+ Autocomplete,
3342
+ {
3343
+ value: selectedTitle || "",
3344
+ onChange: ({ target }) => {
3345
+ !target.innerHTML.includes("path") ? setSelectedTitle(target.innerHTML) : setSelectedTitle(void 0);
3346
+ },
3347
+ options: columnTitles.map((title) => title.label),
3348
+ renderInput: (params) => /* @__PURE__ */ jsx4(
3349
+ TextField,
3350
+ {
3351
+ variant: "standard",
3352
+ margin: "dense",
3353
+ ...params,
3354
+ label: "Coluna"
3355
+ }
3356
+ )
3357
+ }
3358
+ ),
3359
+ /* @__PURE__ */ jsx4(
3360
+ Autocomplete,
3361
+ {
3362
+ value: selectedFilterValue || "",
3363
+ onChange: ({ target }) => {
3364
+ !target.innerHTML.includes("path") ? setSelectedFilterValue(target.innerHTML) : setSelectedFilterValue(void 0);
3365
+ },
3366
+ disabled: valuesToFilter.length < 1,
3367
+ options: valuesToFilter.map((title) => title),
3368
+ renderInput: (params) => /* @__PURE__ */ jsx4(
3369
+ TextField,
3370
+ {
3371
+ variant: "standard",
3372
+ margin: "dense",
3373
+ ...params,
3374
+ label: "Valor"
3375
+ }
3376
+ )
3377
+ }
3378
+ ),
3379
+ /* @__PURE__ */ jsx4(Box2, { sx: { py: 1 } }),
3380
+ /* @__PURE__ */ jsx4(
3381
+ Button,
3382
+ {
3383
+ disabled: !selectedFilterValue,
3384
+ onClick: handleAddFilter,
3385
+ fullWidth: true,
3386
+ children: "Adicionar filtro"
3387
+ }
3388
+ )
3389
+ ] })
3112
3390
  }
3113
- },
3114
- /* @__PURE__ */ React7.createElement(
3115
- Box2,
3391
+ ),
3392
+ /* @__PURE__ */ jsx4(
3393
+ Popover,
3116
3394
  {
3117
- sx: {
3118
- minWidth: 300,
3119
- px: 2,
3120
- pb: 1,
3121
- display: "grid",
3122
- gridTemplateColumns: "1fr 30px",
3123
- alignItems: "flex-end"
3124
- }
3125
- },
3126
- /* @__PURE__ */ React7.createElement(
3127
- TextField,
3128
- {
3129
- variant: "standard",
3130
- margin: "dense",
3131
- label: "Buscar",
3132
- value: searchText,
3133
- onChange: ({ currentTarget }) => setSearchText(currentTarget.value)
3134
- }
3135
- ),
3136
- /* @__PURE__ */ React7.createElement(Box2, null, /* @__PURE__ */ React7.createElement(
3137
- IconButton2,
3138
- {
3139
- onClick: () => {
3140
- setSearchText("");
3141
- setOpenSearch(false);
3142
- }
3395
+ anchorEl: searchAnchorEl.current,
3396
+ open: openSearch,
3397
+ onClose: () => setOpenSearch(false),
3398
+ anchorOrigin: {
3399
+ vertical: "top",
3400
+ horizontal: "left"
3143
3401
  },
3144
- /* @__PURE__ */ React7.createElement(MdClose, { size: 8 * 3 })
3145
- ))
3402
+ transformOrigin: {
3403
+ vertical: "top",
3404
+ horizontal: "left"
3405
+ },
3406
+ children: /* @__PURE__ */ jsxs2(
3407
+ Box2,
3408
+ {
3409
+ sx: {
3410
+ minWidth: 300,
3411
+ px: 2,
3412
+ pb: 1,
3413
+ display: "grid",
3414
+ gridTemplateColumns: "1fr 30px",
3415
+ alignItems: "flex-end"
3416
+ },
3417
+ children: [
3418
+ /* @__PURE__ */ jsx4(
3419
+ TextField,
3420
+ {
3421
+ variant: "standard",
3422
+ margin: "dense",
3423
+ label: "Buscar",
3424
+ value: searchText,
3425
+ onChange: ({ currentTarget }) => setSearchText(currentTarget.value)
3426
+ }
3427
+ ),
3428
+ /* @__PURE__ */ jsx4(Box2, { children: /* @__PURE__ */ jsx4(
3429
+ IconButton2,
3430
+ {
3431
+ onClick: () => {
3432
+ setSearchText("");
3433
+ setOpenSearch(false);
3434
+ },
3435
+ children: /* @__PURE__ */ jsx4(MdClose, { size: 8 * 3 })
3436
+ }
3437
+ ) })
3438
+ ]
3439
+ }
3440
+ )
3441
+ }
3146
3442
  )
3147
- ));
3443
+ ] });
3148
3444
  };
3149
3445
  var Grid_default = Grid;
3150
3446
 
3151
3447
  // src/components/Grid/EditableTableCell/index.tsx
3152
3448
  import { TableCell as TableCell3 } from "@mui/material";
3153
- import React10, { useState as useState2 } from "react";
3449
+ import { useState as useState2 } from "react";
3154
3450
 
3155
3451
  // src/components/Grid/EditableTableCell/DefaultInput.tsx
3156
- import React8 from "react";
3157
3452
  import { TextField as TextField2 } from "@mui/material";
3158
- import moment from "moment";
3453
+ import dayjs from "dayjs";
3454
+ import { jsx as jsx5 } from "react/jsx-runtime";
3159
3455
  var DefaultInput = (allProps) => {
3160
3456
  const {
3161
3457
  TextFieldProps: TextFieldProps3,
@@ -3174,9 +3470,9 @@ var DefaultInput = (allProps) => {
3174
3470
  if (formatInputDefautvalue) return formatInputDefautvalue(value);
3175
3471
  switch (type) {
3176
3472
  case "date":
3177
- return moment(value).format("YYYY-MM-DD");
3473
+ return dayjs(value).format("YYYY-MM-DD");
3178
3474
  case "datetime-local":
3179
- return moment(value).format("YYYY-MM-DDTHH:mm:ss");
3475
+ return dayjs(value).format("YYYY-MM-DDTHH:mm:ss");
3180
3476
  default:
3181
3477
  return String(value);
3182
3478
  }
@@ -3196,7 +3492,7 @@ var DefaultInput = (allProps) => {
3196
3492
  if (ev.code === "Enter") handleSave(ev);
3197
3493
  if (ev.code === "Escape") handleCancelEditing();
3198
3494
  };
3199
- return /* @__PURE__ */ React8.createElement(
3495
+ return /* @__PURE__ */ jsx5(
3200
3496
  TextField2,
3201
3497
  {
3202
3498
  name,
@@ -3232,8 +3528,9 @@ var DefaultInput = (allProps) => {
3232
3528
 
3233
3529
  // src/components/Grid/EditableTableCell/InputMask.tsx
3234
3530
  import { useIMask } from "react-imask";
3235
- import React9, { useEffect as useEffect2 } from "react";
3531
+ import { useEffect as useEffect2 } from "react";
3236
3532
  import { TextField as TextField3 } from "@mui/material";
3533
+ import { jsx as jsx6 } from "react/jsx-runtime";
3237
3534
  var InputMask = (allProps) => {
3238
3535
  const {
3239
3536
  TextFieldProps: TextFieldProps3,
@@ -3246,9 +3543,7 @@ var InputMask = (allProps) => {
3246
3543
  handleCancelEditing,
3247
3544
  setIsEditing
3248
3545
  } = allProps;
3249
- const { ref, unmaskedValue, setValue } = useIMask(
3250
- mask
3251
- );
3546
+ const { ref, unmaskedValue, setValue } = useIMask(mask);
3252
3547
  const handleSave = (event) => {
3253
3548
  setIsEditing(false);
3254
3549
  setValue(String(event.target?.value));
@@ -3268,7 +3563,7 @@ var InputMask = (allProps) => {
3268
3563
  useEffect2(() => {
3269
3564
  if (rowData?.[name]) setValue(String(rowData?.[name]));
3270
3565
  }, [rowData?.[name]]);
3271
- return /* @__PURE__ */ React9.createElement(
3566
+ return /* @__PURE__ */ jsx6(
3272
3567
  TextField3,
3273
3568
  {
3274
3569
  inputRef: ref,
@@ -3302,6 +3597,7 @@ var InputMask = (allProps) => {
3302
3597
  };
3303
3598
 
3304
3599
  // src/components/Grid/EditableTableCell/index.tsx
3600
+ import { Fragment as Fragment3, jsx as jsx7 } from "react/jsx-runtime";
3305
3601
  var EditableTableCell = (allProps) => {
3306
3602
  const {
3307
3603
  TextFieldProps: TextFieldProps3,
@@ -3325,7 +3621,7 @@ var EditableTableCell = (allProps) => {
3325
3621
  setIsEditing(false);
3326
3622
  if (onCancel) onCancel();
3327
3623
  };
3328
- return /* @__PURE__ */ React10.createElement(
3624
+ return /* @__PURE__ */ jsx7(
3329
3625
  TableCell3,
3330
3626
  {
3331
3627
  ...props,
@@ -3335,55 +3631,55 @@ var EditableTableCell = (allProps) => {
3335
3631
  border: bordered ? "1px solid" : "initial",
3336
3632
  borderColor: "divider"
3337
3633
  },
3338
- onDoubleClick: () => setIsEditing(true)
3339
- },
3340
- isEditing ? /* @__PURE__ */ React10.createElement(React10.Fragment, null, mask ? /* @__PURE__ */ React10.createElement(
3341
- InputMask,
3342
- {
3343
- mask,
3344
- isEditing,
3345
- setIsEditing,
3346
- name,
3347
- rowData,
3348
- onSave: ({ value: value2, ...rest }) => {
3349
- setValue(value2);
3350
- onSave({ value: value2, ...rest });
3351
- },
3352
- handleCancelEditing,
3353
- formatInputDefautvalue
3354
- }
3355
- ) : /* @__PURE__ */ React10.createElement(
3356
- DefaultInput,
3357
- {
3358
- onUpdateValue: (newValue) => {
3359
- setValue(newValue);
3360
- },
3361
- isEditing,
3362
- name,
3363
- rowData,
3364
- onSave,
3365
- handleCancelEditing,
3366
- setIsEditing,
3367
- formatInputDefautvalue,
3368
- type
3369
- }
3370
- )) : /* @__PURE__ */ React10.createElement(React10.Fragment, null, formatCellValue(value))
3371
- );
3372
- };
3634
+ onDoubleClick: () => setIsEditing(true),
3635
+ children: isEditing ? /* @__PURE__ */ jsx7(Fragment3, { children: mask ? /* @__PURE__ */ jsx7(
3636
+ InputMask,
3637
+ {
3638
+ mask,
3639
+ isEditing,
3640
+ setIsEditing,
3641
+ name,
3642
+ rowData,
3643
+ onSave: ({ value: value2, ...rest }) => {
3644
+ setValue(value2);
3645
+ onSave({ value: value2, ...rest });
3646
+ },
3647
+ handleCancelEditing,
3648
+ formatInputDefautvalue
3649
+ }
3650
+ ) : /* @__PURE__ */ jsx7(
3651
+ DefaultInput,
3652
+ {
3653
+ onUpdateValue: (newValue) => {
3654
+ setValue(newValue);
3655
+ },
3656
+ isEditing,
3657
+ name,
3658
+ rowData,
3659
+ onSave,
3660
+ handleCancelEditing,
3661
+ setIsEditing,
3662
+ formatInputDefautvalue,
3663
+ type
3664
+ }
3665
+ ) }) : /* @__PURE__ */ jsx7(Fragment3, { children: formatCellValue(value) })
3666
+ }
3667
+ );
3668
+ };
3373
3669
 
3374
3670
  // src/components/Input/index.tsx
3375
- import React11 from "react";
3376
3671
  import { TextField as TextField4 } from "@mui/material";
3377
3672
  import { Field } from "formik";
3673
+ import { jsx as jsx8 } from "react/jsx-runtime";
3378
3674
  var Input = ({ withFormik = true, ...rest }) => {
3379
- if (withFormik) return /* @__PURE__ */ React11.createElement(FormikInput, { ...rest });
3380
- else return /* @__PURE__ */ React11.createElement(BaseInput, { ...rest });
3675
+ if (withFormik) return /* @__PURE__ */ jsx8(FormikInput, { ...rest });
3676
+ else return /* @__PURE__ */ jsx8(BaseInput, { ...rest });
3381
3677
  };
3382
3678
  var BaseInput = (props) => {
3383
- return /* @__PURE__ */ React11.createElement(TextField4, { fullWidth: true, ...props });
3679
+ return /* @__PURE__ */ jsx8(TextField4, { fullWidth: true, ...props });
3384
3680
  };
3385
3681
  var FormikInput = ({ name, shrink, ...rest }) => {
3386
- return /* @__PURE__ */ React11.createElement(Field, { name }, ({ field: { value, ...field }, meta: { error } }) => /* @__PURE__ */ React11.createElement(
3682
+ return /* @__PURE__ */ jsx8(Field, { name, children: ({ field: { value, ...field }, meta: { error } }) => /* @__PURE__ */ jsx8(
3387
3683
  BaseInput,
3388
3684
  {
3389
3685
  defaultValue: value,
@@ -3393,16 +3689,17 @@ var FormikInput = ({ name, shrink, ...rest }) => {
3393
3689
  ...rest,
3394
3690
  InputLabelProps: { shrink, ...rest.InputLabelProps }
3395
3691
  }
3396
- ));
3692
+ ) });
3397
3693
  };
3398
3694
 
3399
3695
  // src/components/InputMask/index.tsx
3400
- import React12, { useEffect as useEffect3, useRef as useRef2 } from "react";
3696
+ import { useEffect as useEffect3, useRef as useRef2 } from "react";
3401
3697
  import { useIMask as useIMask2 } from "react-imask";
3402
3698
  import { Field as Field2 } from "formik";
3699
+ import { jsx as jsx9 } from "react/jsx-runtime";
3403
3700
  function InputMask2({ withFormik = true, ...rest }) {
3404
- if (withFormik) return /* @__PURE__ */ React12.createElement(FormikInputMask, { ...rest });
3405
- else return /* @__PURE__ */ React12.createElement(BaseInputMask, { ...rest });
3701
+ if (withFormik) return /* @__PURE__ */ jsx9(FormikInputMask, { ...rest });
3702
+ else return /* @__PURE__ */ jsx9(BaseInputMask, { ...rest });
3406
3703
  }
3407
3704
  var BaseInputMask = ({
3408
3705
  mask,
@@ -3427,7 +3724,7 @@ var BaseInputMask = ({
3427
3724
  setValue(controlledValue);
3428
3725
  maskRef.current.value = controlledValue;
3429
3726
  }, [controlledValue]);
3430
- return /* @__PURE__ */ React12.createElement(BaseInput, { inputRef: ref, ...rest });
3727
+ return /* @__PURE__ */ jsx9(BaseInput, { inputRef: ref, ...rest });
3431
3728
  };
3432
3729
  function FormikInputMask({
3433
3730
  mask,
@@ -3454,14 +3751,14 @@ function FormikInputMask({
3454
3751
  if (formikSaveFunction.current)
3455
3752
  formikSaveFunction.current(name, unmaskedValue);
3456
3753
  }, [value]);
3457
- return /* @__PURE__ */ React12.createElement(Field2, { name }, ({
3754
+ return /* @__PURE__ */ jsx9(Field2, { name, children: ({
3458
3755
  field: { value: value2, ...field },
3459
3756
  meta: { error },
3460
3757
  form: { setFieldValue }
3461
3758
  }) => {
3462
3759
  initialValue.current = value2;
3463
3760
  formikSaveFunction.current = setFieldValue;
3464
- return /* @__PURE__ */ React12.createElement(
3761
+ return /* @__PURE__ */ jsx9(
3465
3762
  BaseInput,
3466
3763
  {
3467
3764
  ...rest,
@@ -3471,11 +3768,10 @@ function FormikInputMask({
3471
3768
  helperText: error
3472
3769
  }
3473
3770
  );
3474
- });
3771
+ } });
3475
3772
  }
3476
3773
 
3477
3774
  // src/components/Select/index.tsx
3478
- import React13 from "react";
3479
3775
  import {
3480
3776
  FormControl,
3481
3777
  FormHelperText,
@@ -3483,10 +3779,11 @@ import {
3483
3779
  Select as MuiSelect
3484
3780
  } from "@mui/material";
3485
3781
  import { useField } from "formik";
3782
+ import { jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
3486
3783
  var CustomInputLabel = InputLabel;
3487
- function Select({ withFormik = true, ...rest }) {
3488
- if (withFormik) return /* @__PURE__ */ React13.createElement(FormikSelect, { ...rest });
3489
- else return /* @__PURE__ */ React13.createElement(BaseSelect, { ...rest });
3784
+ function Select({ withFormik = true, helperText, ...rest }) {
3785
+ if (withFormik) return /* @__PURE__ */ jsx10(FormikSelect, { helperText, ...rest });
3786
+ else return /* @__PURE__ */ jsx10(BaseSelect, { ...rest });
3490
3787
  }
3491
3788
  function BaseSelect({
3492
3789
  name,
@@ -3496,18 +3793,21 @@ function BaseSelect({
3496
3793
  InputLabelProps: InputLabelProps2,
3497
3794
  ...rest
3498
3795
  }) {
3499
- return /* @__PURE__ */ React13.createElement(FormControl, { fullWidth: true, ...FormControlProps2 }, /* @__PURE__ */ React13.createElement(CustomInputLabel, { ...InputLabelProps2 }, label), /* @__PURE__ */ React13.createElement(
3500
- MuiSelect,
3501
- {
3502
- name,
3503
- inputProps: {
3504
- name
3505
- },
3506
- label,
3507
- ...rest
3508
- },
3509
- children
3510
- ));
3796
+ return /* @__PURE__ */ jsxs3(FormControl, { fullWidth: true, ...FormControlProps2, children: [
3797
+ /* @__PURE__ */ jsx10(CustomInputLabel, { ...InputLabelProps2, children: label }),
3798
+ /* @__PURE__ */ jsx10(
3799
+ MuiSelect,
3800
+ {
3801
+ name,
3802
+ inputProps: {
3803
+ name
3804
+ },
3805
+ label,
3806
+ ...rest,
3807
+ children
3808
+ }
3809
+ )
3810
+ ] });
3511
3811
  }
3512
3812
  function FormikSelect({
3513
3813
  name,
@@ -3522,25 +3822,29 @@ function FormikSelect({
3522
3822
  const onChange = (_, { props: { value: value2 } }) => {
3523
3823
  setValue(value2);
3524
3824
  };
3525
- return /* @__PURE__ */ React13.createElement(FormControl, { fullWidth: true, ...FormControlProps2, error: Boolean(meta?.error) }, /* @__PURE__ */ React13.createElement(CustomInputLabel, { ...InputLabelProps2 }, label), /* @__PURE__ */ React13.createElement(
3526
- MuiSelect,
3527
- {
3528
- inputProps: {
3529
- name
3530
- },
3531
- label,
3532
- ...rest,
3533
- ...field,
3534
- defaultValue: value,
3535
- onChange
3536
- },
3537
- children
3538
- ), /* @__PURE__ */ React13.createElement(FormHelperText, null, helperText || meta?.error));
3825
+ return /* @__PURE__ */ jsxs3(FormControl, { fullWidth: true, ...FormControlProps2, error: Boolean(meta?.error), children: [
3826
+ /* @__PURE__ */ jsx10(CustomInputLabel, { ...InputLabelProps2, children: label }),
3827
+ /* @__PURE__ */ jsx10(
3828
+ MuiSelect,
3829
+ {
3830
+ inputProps: {
3831
+ name
3832
+ },
3833
+ label,
3834
+ ...rest,
3835
+ ...field,
3836
+ defaultValue: value,
3837
+ onChange,
3838
+ children
3839
+ }
3840
+ ),
3841
+ /* @__PURE__ */ jsx10(FormHelperText, { children: helperText || meta?.error })
3842
+ ] });
3539
3843
  }
3540
3844
 
3541
3845
  // src/components/Autocomplete/index.tsx
3542
- import React14, {
3543
- Fragment,
3846
+ import {
3847
+ Fragment as Fragment4,
3544
3848
  useMemo as useMemo2,
3545
3849
  useState as useState3
3546
3850
  } from "react";
@@ -3551,6 +3855,7 @@ import {
3551
3855
  CircularProgress
3552
3856
  } from "@mui/material";
3553
3857
  import { useTheme as useTheme3 } from "@mui/material/styles";
3858
+ import { jsx as jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
3554
3859
  function Autocomplete2({
3555
3860
  withFormik = true,
3556
3861
  name,
@@ -3564,7 +3869,7 @@ function Autocomplete2({
3564
3869
  }, [theme]);
3565
3870
  const isLegacyBehaviorDisabled = typeof rest?.["data-legacy-behavior"] !== "undefined" ? rest["data-legacy-behavior"] === "disabled" : isLegacyBehaviorDisabledTheme;
3566
3871
  if (isLegacyBehaviorDisabled)
3567
- return /* @__PURE__ */ React14.createElement(
3872
+ return /* @__PURE__ */ jsx11(
3568
3873
  FormikAutocomplete,
3569
3874
  {
3570
3875
  name,
@@ -3572,7 +3877,7 @@ function Autocomplete2({
3572
3877
  ...rest
3573
3878
  }
3574
3879
  );
3575
- return /* @__PURE__ */ React14.createElement(
3880
+ return /* @__PURE__ */ jsx11(
3576
3881
  FormikAutocompleteLegacy,
3577
3882
  {
3578
3883
  name,
@@ -3581,14 +3886,14 @@ function Autocomplete2({
3581
3886
  }
3582
3887
  );
3583
3888
  }
3584
- return /* @__PURE__ */ React14.createElement(BaseInput2, { ...rest });
3889
+ return /* @__PURE__ */ jsx11(BaseInput2, { ...rest });
3585
3890
  }
3586
3891
  function BaseInput2(props) {
3587
- return /* @__PURE__ */ React14.createElement(
3892
+ return /* @__PURE__ */ jsx11(
3588
3893
  MuiAutocomplete,
3589
3894
  {
3590
3895
  fullWidth: true,
3591
- renderInput: (params) => /* @__PURE__ */ React14.createElement(TextField5, { label: props.label, ...params }),
3896
+ renderInput: (params) => /* @__PURE__ */ jsx11(TextField5, { label: props.label, ...params }),
3592
3897
  ...props
3593
3898
  }
3594
3899
  );
@@ -3627,11 +3932,11 @@ function FormikAutocompleteLegacy({
3627
3932
  if (key) return a[key] === b[key];
3628
3933
  return Object.values(a)[0] === Object.values(b)[0];
3629
3934
  };
3630
- return /* @__PURE__ */ React14.createElement(
3935
+ return /* @__PURE__ */ jsx11(
3631
3936
  MuiAutocomplete,
3632
3937
  {
3633
3938
  getOptionLabel,
3634
- renderInput: (params) => /* @__PURE__ */ React14.createElement(
3939
+ renderInput: (params) => /* @__PURE__ */ jsx11(
3635
3940
  TextField5,
3636
3941
  {
3637
3942
  error: Boolean(meta?.error),
@@ -3640,7 +3945,10 @@ function FormikAutocompleteLegacy({
3640
3945
  ...field,
3641
3946
  InputProps: {
3642
3947
  ...params.InputProps,
3643
- endAdornment: /* @__PURE__ */ React14.createElement(Fragment, null, props.loading ? /* @__PURE__ */ React14.createElement(CircularProgress, { color: "inherit", size: 20 }) : null, params.InputProps.endAdornment)
3948
+ endAdornment: /* @__PURE__ */ jsxs4(Fragment4, { children: [
3949
+ props.loading ? /* @__PURE__ */ jsx11(CircularProgress, { color: "inherit", size: 20 }) : null,
3950
+ params.InputProps.endAdornment
3951
+ ] })
3644
3952
  },
3645
3953
  label: props.label,
3646
3954
  required: props.required,
@@ -3672,10 +3980,10 @@ function FormikAutocomplete({
3672
3980
  setValue(newValue[value2]);
3673
3981
  } else setValue(newValue);
3674
3982
  };
3675
- return /* @__PURE__ */ React14.createElement(
3983
+ return /* @__PURE__ */ jsx11(
3676
3984
  MuiAutocomplete,
3677
3985
  {
3678
- renderInput: (params) => /* @__PURE__ */ React14.createElement(
3986
+ renderInput: (params) => /* @__PURE__ */ jsx11(
3679
3987
  TextField5,
3680
3988
  {
3681
3989
  error: Boolean(meta?.error),
@@ -3684,7 +3992,10 @@ function FormikAutocomplete({
3684
3992
  ...field,
3685
3993
  InputProps: {
3686
3994
  ...params.InputProps,
3687
- endAdornment: /* @__PURE__ */ React14.createElement(Fragment, null, props.loading ? /* @__PURE__ */ React14.createElement(CircularProgress, { color: "inherit", size: 20 }) : null, params.InputProps.endAdornment)
3995
+ endAdornment: /* @__PURE__ */ jsxs4(Fragment4, { children: [
3996
+ props.loading ? /* @__PURE__ */ jsx11(CircularProgress, { color: "inherit", size: 20 }) : null,
3997
+ params.InputProps.endAdornment
3998
+ ] })
3688
3999
  },
3689
4000
  label: props.label,
3690
4001
  required: props.required,
@@ -3700,174 +4011,199 @@ function FormikAutocomplete({
3700
4011
  }
3701
4012
 
3702
4013
  // src/components/Checkbox/index.tsx
3703
- import React15 from "react";
3704
4014
  import {
3705
4015
  Checkbox as MuiCheckbox,
3706
- FormControlLabel
4016
+ FormControl as FormControl2,
4017
+ FormControlLabel,
4018
+ FormHelperText as FormHelperText2
3707
4019
  } from "@mui/material";
3708
4020
  import { useField as useField3 } from "formik";
4021
+ import { jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
3709
4022
  var Checkbox = ({
3710
4023
  withFormik = true,
3711
4024
  name,
3712
4025
  ...props
3713
4026
  }) => {
3714
- if (withFormik && name) return /* @__PURE__ */ React15.createElement(FormikCheckbox, { name, ...props });
3715
- else return /* @__PURE__ */ React15.createElement(BaseCheckbox, { ...props });
4027
+ if (withFormik && name) return /* @__PURE__ */ jsx12(FormikCheckbox, { name, ...props });
4028
+ else return /* @__PURE__ */ jsx12(BaseCheckbox, { ...props });
3716
4029
  };
3717
4030
  var BaseCheckbox = ({
3718
4031
  label,
4032
+ helperText,
3719
4033
  FormControlLabelProps: FormControlLabelProps3,
3720
4034
  ...props
3721
4035
  }) => {
3722
- return /* @__PURE__ */ React15.createElement(
3723
- FormControlLabel,
3724
- {
3725
- label,
3726
- control: /* @__PURE__ */ React15.createElement(MuiCheckbox, { ...props }),
3727
- ...FormControlLabelProps3
3728
- }
3729
- );
4036
+ return /* @__PURE__ */ jsxs5(FormControl2, { children: [
4037
+ /* @__PURE__ */ jsx12(
4038
+ FormControlLabel,
4039
+ {
4040
+ label,
4041
+ control: /* @__PURE__ */ jsx12(MuiCheckbox, { ...props }),
4042
+ ...FormControlLabelProps3
4043
+ }
4044
+ ),
4045
+ helperText && /* @__PURE__ */ jsx12(FormHelperText2, { children: helperText })
4046
+ ] });
3730
4047
  };
3731
4048
  var FormikCheckbox = ({
3732
4049
  label,
3733
4050
  name,
4051
+ helperText,
3734
4052
  FormControlLabelProps: FormControlLabelProps3,
3735
4053
  ...props
3736
4054
  }) => {
3737
- const [{ value, ...field }, , { setValue }] = useField3({
3738
- name
3739
- });
4055
+ const [{ value, ...field }, { error }, { setValue }] = useField3({ name });
3740
4056
  const onChange = (_, value2) => {
3741
4057
  setValue(value2);
3742
4058
  };
3743
- return /* @__PURE__ */ React15.createElement(
3744
- FormControlLabel,
3745
- {
3746
- label,
3747
- control: /* @__PURE__ */ React15.createElement(MuiCheckbox, { ...props, defaultChecked: Boolean(value) }),
3748
- ...field,
3749
- onChange,
3750
- ...FormControlLabelProps3
3751
- }
3752
- );
4059
+ return /* @__PURE__ */ jsxs5(FormControl2, { error: Boolean(error), children: [
4060
+ /* @__PURE__ */ jsx12(
4061
+ FormControlLabel,
4062
+ {
4063
+ label,
4064
+ control: /* @__PURE__ */ jsx12(MuiCheckbox, { ...props, checked: Boolean(value) }),
4065
+ ...field,
4066
+ onChange,
4067
+ ...FormControlLabelProps3
4068
+ }
4069
+ ),
4070
+ (error || helperText) && /* @__PURE__ */ jsx12(FormHelperText2, { children: error ?? helperText })
4071
+ ] });
3753
4072
  };
3754
4073
 
3755
4074
  // src/components/Switch/index.tsx
3756
- import React16 from "react";
3757
4075
  import {
3758
4076
  Switch as MuiSwitch,
3759
- FormControlLabel as FormControlLabel2
4077
+ FormControl as FormControl3,
4078
+ FormControlLabel as FormControlLabel2,
4079
+ FormHelperText as FormHelperText3
3760
4080
  } from "@mui/material";
3761
4081
  import { useField as useField4 } from "formik";
4082
+ import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
3762
4083
  var Switch = ({ withFormik = true, name, ...props }) => {
3763
- if (withFormik && name) return /* @__PURE__ */ React16.createElement(FormikSwitch, { name, ...props });
3764
- else return /* @__PURE__ */ React16.createElement(BaseSwitch, { ...props });
4084
+ if (withFormik && name) return /* @__PURE__ */ jsx13(FormikSwitch, { name, ...props });
4085
+ else return /* @__PURE__ */ jsx13(BaseSwitch, { ...props });
3765
4086
  };
3766
4087
  var BaseSwitch = ({
3767
4088
  label,
4089
+ helperText,
3768
4090
  FormControlLabelProps: FormControlLabelProps3,
3769
4091
  ...props
3770
4092
  }) => {
3771
- return /* @__PURE__ */ React16.createElement(
3772
- FormControlLabel2,
3773
- {
3774
- label,
3775
- control: /* @__PURE__ */ React16.createElement(MuiSwitch, { ...props }),
3776
- ...FormControlLabelProps3
3777
- }
3778
- );
4093
+ return /* @__PURE__ */ jsxs6(FormControl3, { children: [
4094
+ /* @__PURE__ */ jsx13(
4095
+ FormControlLabel2,
4096
+ {
4097
+ label,
4098
+ control: /* @__PURE__ */ jsx13(MuiSwitch, { ...props }),
4099
+ ...FormControlLabelProps3
4100
+ }
4101
+ ),
4102
+ helperText && /* @__PURE__ */ jsx13(FormHelperText3, { children: helperText })
4103
+ ] });
3779
4104
  };
3780
4105
  var FormikSwitch = ({
3781
4106
  label,
3782
4107
  name,
4108
+ helperText,
3783
4109
  FormControlLabelProps: FormControlLabelProps3,
3784
4110
  ...props
3785
4111
  }) => {
3786
- const [{ value, onChange: unused, ...field }, , { setValue }] = useField4({
3787
- name
3788
- });
4112
+ const [{ value, onChange: unused, ...field }, { error }, { setValue }] = useField4({ name });
3789
4113
  const onChange = (_, value2) => {
3790
4114
  setValue(value2);
3791
4115
  };
3792
- return /* @__PURE__ */ React16.createElement(
3793
- FormControlLabel2,
3794
- {
3795
- label,
3796
- onChange,
3797
- control: /* @__PURE__ */ React16.createElement(MuiSwitch, { defaultChecked: value, ...props }),
3798
- ...field,
3799
- ...FormControlLabelProps3
3800
- }
3801
- );
4116
+ return /* @__PURE__ */ jsxs6(FormControl3, { error: Boolean(error), children: [
4117
+ /* @__PURE__ */ jsx13(
4118
+ FormControlLabel2,
4119
+ {
4120
+ label,
4121
+ onChange,
4122
+ control: /* @__PURE__ */ jsx13(MuiSwitch, { checked: value, ...props }),
4123
+ ...field,
4124
+ ...FormControlLabelProps3
4125
+ }
4126
+ ),
4127
+ (error || helperText) && /* @__PURE__ */ jsx13(FormHelperText3, { children: error ?? helperText })
4128
+ ] });
3802
4129
  };
3803
4130
 
3804
4131
  // src/components/Radio/index.tsx
3805
- import React17 from "react";
3806
4132
  import {
3807
- FormControl as FormControl2,
4133
+ FormControl as FormControl4,
3808
4134
  FormControlLabel as FormControlLabel3,
4135
+ FormHelperText as FormHelperText4,
3809
4136
  FormLabel,
3810
4137
  Radio as MuiRadio,
3811
4138
  RadioGroup
3812
4139
  } from "@mui/material";
3813
- import { Field as Field3 } from "formik";
4140
+ import { useField as useField5 } from "formik";
4141
+ import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
3814
4142
  var Radio = ({
3815
4143
  name,
3816
4144
  withFormik = true,
3817
4145
  ...rest
3818
4146
  }) => {
3819
- if (withFormik && name) return /* @__PURE__ */ React17.createElement(FormikRadio, { name, ...rest });
3820
- else return /* @__PURE__ */ React17.createElement(BaseRadio, { ...rest });
4147
+ if (withFormik && name) return /* @__PURE__ */ jsx14(FormikRadio, { name, ...rest });
4148
+ else return /* @__PURE__ */ jsx14(BaseRadio, { ...rest });
3821
4149
  };
3822
4150
  var BaseRadio = ({
3823
4151
  label,
3824
4152
  options,
4153
+ helperText,
3825
4154
  ...rest
3826
4155
  }) => {
3827
- return /* @__PURE__ */ React17.createElement(FormControl2, null, label && /* @__PURE__ */ React17.createElement(FormLabel, null, label), /* @__PURE__ */ React17.createElement(RadioGroup, { ...rest }, options.map((option) => /* @__PURE__ */ React17.createElement(
3828
- FormControlLabel3,
3829
- {
3830
- key: String(option.value),
3831
- value: option.value,
3832
- label: option.label,
3833
- control: /* @__PURE__ */ React17.createElement(MuiRadio, null)
3834
- }
3835
- ))));
4156
+ return /* @__PURE__ */ jsxs7(FormControl4, { children: [
4157
+ label && /* @__PURE__ */ jsx14(FormLabel, { children: label }),
4158
+ /* @__PURE__ */ jsx14(RadioGroup, { ...rest, children: options.map((option) => /* @__PURE__ */ jsx14(
4159
+ FormControlLabel3,
4160
+ {
4161
+ value: option.value,
4162
+ label: option.label,
4163
+ control: /* @__PURE__ */ jsx14(MuiRadio, {})
4164
+ },
4165
+ String(option.value)
4166
+ )) }),
4167
+ helperText && /* @__PURE__ */ jsx14(FormHelperText4, { children: helperText })
4168
+ ] });
3836
4169
  };
3837
4170
  var FormikRadio = ({
3838
4171
  label,
3839
4172
  name,
3840
4173
  options,
4174
+ helperText,
3841
4175
  ...rest
3842
4176
  }) => {
3843
- const onChange = (setFieldValue, value) => {
3844
- setFieldValue(name, value);
3845
- };
3846
- return /* @__PURE__ */ React17.createElement(Field3, null, ({ field: { value }, form: { setFieldValue } }) => /* @__PURE__ */ React17.createElement(FormControl2, null, label && /* @__PURE__ */ React17.createElement(FormLabel, null, label), /* @__PURE__ */ React17.createElement(
3847
- RadioGroup,
3848
- {
3849
- defaultValue: value,
3850
- onChange: (_, value2) => onChange(setFieldValue, value2),
3851
- ...rest
3852
- },
3853
- options.map((option) => /* @__PURE__ */ React17.createElement(
3854
- FormControlLabel3,
4177
+ const [{ value }, meta, { setValue }] = useField5(name);
4178
+ return /* @__PURE__ */ jsxs7(FormControl4, { error: Boolean(meta.error), children: [
4179
+ label && /* @__PURE__ */ jsx14(FormLabel, { children: label }),
4180
+ /* @__PURE__ */ jsx14(
4181
+ RadioGroup,
3855
4182
  {
3856
- key: String(option.value),
3857
- value: option.value,
3858
- label: option.label,
3859
- control: /* @__PURE__ */ React17.createElement(MuiRadio, null)
4183
+ value: value ?? "",
4184
+ onChange: (_, val) => setValue(val),
4185
+ ...rest,
4186
+ children: options.map((option) => /* @__PURE__ */ jsx14(
4187
+ FormControlLabel3,
4188
+ {
4189
+ value: option.value,
4190
+ label: option.label,
4191
+ control: /* @__PURE__ */ jsx14(MuiRadio, {})
4192
+ },
4193
+ String(option.value)
4194
+ ))
3860
4195
  }
3861
- ))
3862
- )));
4196
+ ),
4197
+ /* @__PURE__ */ jsx14(FormHelperText4, { children: helperText || meta.error })
4198
+ ] });
3863
4199
  };
3864
4200
 
3865
4201
  // src/components/LargeButton/index.tsx
3866
- import React18 from "react";
3867
4202
  import {
3868
4203
  Button as Button2,
3869
4204
  CircularProgress as CircularProgress2
3870
4205
  } from "@mui/material";
4206
+ import { jsx as jsx15 } from "react/jsx-runtime";
3871
4207
  var LargeButton = ({
3872
4208
  loading,
3873
4209
  children,
@@ -3875,28 +4211,28 @@ var LargeButton = ({
3875
4211
  sx,
3876
4212
  ...rest
3877
4213
  }) => {
3878
- return /* @__PURE__ */ React18.createElement(
4214
+ return /* @__PURE__ */ jsx15(
3879
4215
  Button2,
3880
4216
  {
3881
4217
  variant: "contained",
3882
4218
  fullWidth: true,
3883
4219
  sx: { fontWeight: "bold", ...sx },
3884
4220
  disabled: rest.disabled || loading,
3885
- ...rest
3886
- },
3887
- loading ? /* @__PURE__ */ React18.createElement(
3888
- CircularProgress2,
3889
- {
3890
- size: 25,
3891
- color: "inherit",
3892
- ...CircularProgressProps2
3893
- }
3894
- ) : children
4221
+ ...rest,
4222
+ children: loading ? /* @__PURE__ */ jsx15(
4223
+ CircularProgress2,
4224
+ {
4225
+ size: 25,
4226
+ color: "inherit",
4227
+ ...CircularProgressProps2
4228
+ }
4229
+ ) : children
4230
+ }
3895
4231
  );
3896
4232
  };
3897
4233
 
3898
4234
  // src/components/TabPanel/index.tsx
3899
- import React19 from "react";
4235
+ import { Fragment as Fragment5, jsx as jsx16 } from "react/jsx-runtime";
3900
4236
  function getTabProps(index) {
3901
4237
  return {
3902
4238
  id: `tab-${index}`,
@@ -3905,21 +4241,20 @@ function getTabProps(index) {
3905
4241
  }
3906
4242
  var TabPanel = (props) => {
3907
4243
  const { children, value, index, ...other } = props;
3908
- return /* @__PURE__ */ React19.createElement(
4244
+ return /* @__PURE__ */ jsx16(
3909
4245
  "div",
3910
4246
  {
3911
4247
  role: "tabpanel",
3912
4248
  hidden: value !== index,
3913
4249
  id: `tabpanel-${index}`,
3914
4250
  "aria-labelledby": `tab-${index}`,
3915
- ...other
3916
- },
3917
- value === index && /* @__PURE__ */ React19.createElement(React19.Fragment, null, children)
4251
+ ...other,
4252
+ children: value === index && /* @__PURE__ */ jsx16(Fragment5, { children })
4253
+ }
3918
4254
  );
3919
4255
  };
3920
4256
 
3921
4257
  // src/components/BaseGrid/index.tsx
3922
- import React21 from "react";
3923
4258
  import {
3924
4259
  Box as Box4,
3925
4260
  LinearProgress as LinearProgress2,
@@ -3933,7 +4268,6 @@ import {
3933
4268
  } from "@mui/material";
3934
4269
 
3935
4270
  // src/components/BaseGrid/Pagination/index.tsx
3936
- import React20 from "react";
3937
4271
  import {
3938
4272
  Box as Box3,
3939
4273
  IconButton as IconButton3,
@@ -3943,6 +4277,7 @@ import {
3943
4277
  Typography as Typography2
3944
4278
  } from "@mui/material";
3945
4279
  import { MdArrowForwardIos, MdArrowBackIosNew } from "react-icons/md";
4280
+ import { jsx as jsx17, jsxs as jsxs8 } from "react/jsx-runtime";
3946
4281
  var GridPagination = ({
3947
4282
  currentPage,
3948
4283
  totalNumberOfPages,
@@ -3952,44 +4287,55 @@ var GridPagination = ({
3952
4287
  rowsPerPage,
3953
4288
  dense
3954
4289
  }) => {
3955
- return /* @__PURE__ */ React20.createElement(
4290
+ return /* @__PURE__ */ jsxs8(
3956
4291
  Stack,
3957
4292
  {
3958
4293
  direction: "row",
3959
4294
  justifyContent: "space-between",
3960
4295
  alignItems: "center",
3961
4296
  width: "100%",
3962
- py: dense ? 0.5 : 1
3963
- },
3964
- /* @__PURE__ */ React20.createElement(Box3, null),
3965
- /* @__PURE__ */ React20.createElement(Stack, { direction: "row", alignItems: "center" }, /* @__PURE__ */ React20.createElement(
3966
- Select2,
3967
- {
3968
- variant: "standard",
3969
- size: "small",
3970
- margin: "dense",
3971
- sx: { width: 60, mr: 2, textAlign: "center", fontSize: 13 },
3972
- value: rowsPerPage,
3973
- onChange: ({ target }) => setRowsPerPage(parseInt(target.value))
3974
- },
3975
- rowsPerPageOptions.map((option) => /* @__PURE__ */ React20.createElement(MenuItem, { key: option, value: option }, option))
3976
- ), /* @__PURE__ */ React20.createElement(Typography2, { variant: "body2" }, currentPage + 1, " de ", totalNumberOfPages + 1), /* @__PURE__ */ React20.createElement(
3977
- IconButton3,
3978
- {
3979
- size: "small",
3980
- disabled: currentPage === 0,
3981
- onClick: () => onPageChange(currentPage - 1)
3982
- },
3983
- /* @__PURE__ */ React20.createElement(MdArrowBackIosNew, { size: 8 * 2 })
3984
- ), /* @__PURE__ */ React20.createElement(
3985
- IconButton3,
3986
- {
3987
- size: "small",
3988
- disabled: currentPage === totalNumberOfPages,
3989
- onClick: () => onPageChange(currentPage + 1)
3990
- },
3991
- /* @__PURE__ */ React20.createElement(MdArrowForwardIos, { size: 8 * 2 })
3992
- ))
4297
+ py: dense ? 0.5 : 1,
4298
+ children: [
4299
+ /* @__PURE__ */ jsx17(Box3, {}),
4300
+ /* @__PURE__ */ jsxs8(Stack, { direction: "row", alignItems: "center", children: [
4301
+ /* @__PURE__ */ jsx17(
4302
+ Select2,
4303
+ {
4304
+ variant: "standard",
4305
+ size: "small",
4306
+ margin: "dense",
4307
+ sx: { width: 60, mr: 2, textAlign: "center", fontSize: 13 },
4308
+ value: rowsPerPage,
4309
+ onChange: ({ target }) => setRowsPerPage(parseInt(target.value)),
4310
+ children: rowsPerPageOptions.map((option) => /* @__PURE__ */ jsx17(MenuItem, { value: option, children: option }, option))
4311
+ }
4312
+ ),
4313
+ /* @__PURE__ */ jsxs8(Typography2, { variant: "body2", children: [
4314
+ currentPage + 1,
4315
+ " de ",
4316
+ totalNumberOfPages + 1
4317
+ ] }),
4318
+ /* @__PURE__ */ jsx17(
4319
+ IconButton3,
4320
+ {
4321
+ size: "small",
4322
+ disabled: currentPage === 0,
4323
+ onClick: () => onPageChange(currentPage - 1),
4324
+ children: /* @__PURE__ */ jsx17(MdArrowBackIosNew, { size: 8 * 2 })
4325
+ }
4326
+ ),
4327
+ /* @__PURE__ */ jsx17(
4328
+ IconButton3,
4329
+ {
4330
+ size: "small",
4331
+ disabled: currentPage === totalNumberOfPages,
4332
+ onClick: () => onPageChange(currentPage + 1),
4333
+ children: /* @__PURE__ */ jsx17(MdArrowForwardIos, { size: 8 * 2 })
4334
+ }
4335
+ )
4336
+ ] })
4337
+ ]
4338
+ }
3993
4339
  );
3994
4340
  };
3995
4341
 
@@ -4031,6 +4377,7 @@ var styles = {
4031
4377
  };
4032
4378
 
4033
4379
  // src/components/BaseGrid/index.tsx
4380
+ import { jsx as jsx18, jsxs as jsxs9 } from "react/jsx-runtime";
4034
4381
  function BaseGrid({
4035
4382
  columns,
4036
4383
  children,
@@ -4057,7 +4404,7 @@ function BaseGrid({
4057
4404
  loadingColSpan,
4058
4405
  isLoading
4059
4406
  }) {
4060
- return /* @__PURE__ */ React21.createElement(
4407
+ return /* @__PURE__ */ jsxs9(
4061
4408
  Paper2,
4062
4409
  {
4063
4410
  ...paperProps,
@@ -4067,93 +4414,109 @@ function BaseGrid({
4067
4414
  ...styles.striped(striped),
4068
4415
  ...styles.lastRowBorder(hideFooter),
4069
4416
  ...paperProps?.sx
4070
- }
4071
- },
4072
- /* @__PURE__ */ React21.createElement(
4073
- Box4,
4074
- {
4075
- ...boxContainerProps,
4076
- sx: { overflowX: "auto", ...boxContainerProps?.sx }
4077
4417
  },
4078
- /* @__PURE__ */ React21.createElement(
4079
- Table2,
4080
- {
4081
- size: "small",
4082
- stickyHeader: true,
4083
- ...tableProps,
4084
- sx: {
4085
- ...tableProps?.sx
4086
- }
4087
- },
4088
- /* @__PURE__ */ React21.createElement(TableHead2, { ...tableHeadProps }, /* @__PURE__ */ React21.createElement(TableRow3, null, prependColumn, columns.map((column) => /* @__PURE__ */ React21.createElement(
4089
- TableCell4,
4418
+ children: [
4419
+ /* @__PURE__ */ jsx18(
4420
+ Box4,
4090
4421
  {
4091
- key: column.name,
4092
- padding: dense ? "none" : "normal",
4093
- ...column.props,
4094
- sx: {
4095
- pl: 2,
4096
- ...column?.sx
4097
- }
4098
- },
4099
- column.children ? column.children : /* @__PURE__ */ React21.createElement(
4100
- TableSortLabel2,
4101
- {
4102
- active: sortedBy.some((p) => p.prop === column.name),
4103
- direction: sortedBy.find((p) => p.prop === column.name)?.direction || "desc",
4104
- onClick: () => onSortBy(column.name),
4105
- disabled: column.canSort === false,
4106
- ...tableSortLabelProps,
4107
- sx: { ...tableSortLabelProps?.sx }
4108
- },
4109
- column.label
4110
- )
4111
- )), appendColumn), isLoading && /* @__PURE__ */ React21.createElement(TableRow3, null, /* @__PURE__ */ React21.createElement(
4112
- TableCell4,
4422
+ ...boxContainerProps,
4423
+ sx: { overflowX: "auto", ...boxContainerProps?.sx },
4424
+ children: /* @__PURE__ */ jsxs9(
4425
+ Table2,
4426
+ {
4427
+ size: "small",
4428
+ stickyHeader: true,
4429
+ ...tableProps,
4430
+ sx: {
4431
+ ...tableProps?.sx
4432
+ },
4433
+ children: [
4434
+ /* @__PURE__ */ jsxs9(TableHead2, { ...tableHeadProps, children: [
4435
+ /* @__PURE__ */ jsxs9(TableRow3, { children: [
4436
+ prependColumn,
4437
+ columns.map((column) => /* @__PURE__ */ jsx18(
4438
+ TableCell4,
4439
+ {
4440
+ padding: dense ? "none" : "normal",
4441
+ ...column.props,
4442
+ sx: {
4443
+ pl: 2,
4444
+ ...column?.sx
4445
+ },
4446
+ children: column.children ? column.children : /* @__PURE__ */ jsx18(
4447
+ TableSortLabel2,
4448
+ {
4449
+ active: sortedBy.some((p) => p.prop === column.name),
4450
+ direction: sortedBy.find((p) => p.prop === column.name)?.direction || "desc",
4451
+ onClick: () => onSortBy(column.name),
4452
+ disabled: column.canSort === false,
4453
+ ...tableSortLabelProps,
4454
+ sx: { ...tableSortLabelProps?.sx },
4455
+ children: column.label
4456
+ }
4457
+ )
4458
+ },
4459
+ column.name
4460
+ )),
4461
+ appendColumn
4462
+ ] }),
4463
+ isLoading && /* @__PURE__ */ jsx18(TableRow3, { children: /* @__PURE__ */ jsx18(
4464
+ TableCell4,
4465
+ {
4466
+ colSpan: loadingColSpan || columns.length,
4467
+ sx: { p: 0, border: "none" },
4468
+ children: /* @__PURE__ */ jsx18(LinearProgress2, {})
4469
+ }
4470
+ ) })
4471
+ ] }),
4472
+ /* @__PURE__ */ jsx18(TableBody2, { ...tableBodyProps, children })
4473
+ ]
4474
+ }
4475
+ )
4476
+ }
4477
+ ),
4478
+ !hideFooter && /* @__PURE__ */ jsx18(
4479
+ GridPagination,
4113
4480
  {
4114
- colSpan: loadingColSpan || columns.length,
4115
- sx: { p: 0, border: "none" }
4116
- },
4117
- /* @__PURE__ */ React21.createElement(LinearProgress2, null)
4118
- ))),
4119
- /* @__PURE__ */ React21.createElement(TableBody2, { ...tableBodyProps }, children)
4120
- )
4121
- ),
4122
- !hideFooter && /* @__PURE__ */ React21.createElement(
4123
- GridPagination,
4124
- {
4125
- rowsPerPageOptions,
4126
- currentPage,
4127
- totalNumberOfPages,
4128
- onPageChange,
4129
- setRowsPerPage,
4130
- rowsPerPage,
4131
- dense
4132
- }
4133
- )
4481
+ rowsPerPageOptions,
4482
+ currentPage,
4483
+ totalNumberOfPages,
4484
+ onPageChange,
4485
+ setRowsPerPage,
4486
+ rowsPerPage,
4487
+ dense
4488
+ }
4489
+ )
4490
+ ]
4491
+ }
4134
4492
  );
4135
4493
  }
4136
4494
 
4137
4495
  // src/components/BaseGrid/BaseGridAutoRows.tsx
4138
- import React22 from "react";
4139
- import { Fragment as Fragment2 } from "react";
4496
+ import { Fragment as Fragment6 } from "react";
4140
4497
  import { TableCell as TableCell5, TableRow as TableRow4 } from "@mui/material";
4498
+ import { jsx as jsx19 } from "react/jsx-runtime";
4141
4499
  function BaseGridAutoRows({
4142
4500
  data,
4143
4501
  columns,
4144
4502
  rowKey
4145
4503
  }) {
4146
- return /* @__PURE__ */ React22.createElement(Fragment2, null, data.map((row) => /* @__PURE__ */ React22.createElement(TableRow4, { key: row[rowKey] }, columns.map((column) => /* @__PURE__ */ React22.createElement(TableCell5, { key: column.name }, row[column.name])))));
4504
+ return /* @__PURE__ */ jsx19(Fragment6, { children: data.map((row) => /* @__PURE__ */ jsx19(TableRow4, { children: columns.map((column) => /* @__PURE__ */ jsx19(TableCell5, { children: row[column.name] }, column.name)) }, row[rowKey])) });
4147
4505
  }
4148
4506
 
4149
4507
  // src/components/Modal/index.tsx
4150
- import React23 from "react";
4151
4508
  import {
4152
4509
  Box as Box5,
4153
4510
  Modal as MuiModal
4154
4511
  } from "@mui/material";
4512
+ import { jsx as jsx20 } from "react/jsx-runtime";
4155
4513
  var Modal = ({ open, onClose, BoxProps: BoxProps3, ...rest }) => {
4156
- return /* @__PURE__ */ React23.createElement(MuiModal, { open, onClose, ...rest }, /* @__PURE__ */ React23.createElement(
4514
+ if (process.env.NODE_ENV !== "production") {
4515
+ console.warn(
4516
+ "[Modal] is deprecated. Use `BaseDialog` instead. `Modal` will be removed in a future release."
4517
+ );
4518
+ }
4519
+ return /* @__PURE__ */ jsx20(MuiModal, { open, onClose, ...rest, children: /* @__PURE__ */ jsx20(
4157
4520
  Box5,
4158
4521
  {
4159
4522
  ...BoxProps3,
@@ -4166,10 +4529,10 @@ var Modal = ({ open, onClose, BoxProps: BoxProps3, ...rest }) => {
4166
4529
  transform: "translate(-50%, -50%)",
4167
4530
  borderRadius: 1,
4168
4531
  ...BoxProps3?.sx
4169
- }
4170
- },
4171
- rest.children
4172
- ));
4532
+ },
4533
+ children: rest.children
4534
+ }
4535
+ ) });
4173
4536
  };
4174
4537
 
4175
4538
  // src/components/utils/GetInputLabel.ts
@@ -4181,7 +4544,6 @@ function GetInputLabel(columns) {
4181
4544
  }
4182
4545
 
4183
4546
  // src/components/Dialog/index.tsx
4184
- import React24 from "react";
4185
4547
  import {
4186
4548
  Box as Box6,
4187
4549
  Dialog as DefaultDialog,
@@ -4191,6 +4553,7 @@ import {
4191
4553
  Button as Button3,
4192
4554
  CircularProgress as CircularProgress3
4193
4555
  } from "@mui/material";
4556
+ import { Fragment as Fragment7, jsx as jsx21, jsxs as jsxs10 } from "react/jsx-runtime";
4194
4557
  var Dialog = ({
4195
4558
  open,
4196
4559
  title,
@@ -4199,27 +4562,30 @@ var Dialog = ({
4199
4562
  options,
4200
4563
  ...rest
4201
4564
  }) => {
4202
- return /* @__PURE__ */ React24.createElement(DefaultDialog, { open, ...rest }, /* @__PURE__ */ React24.createElement(Box6, { sx: { p: 2 } }, /* @__PURE__ */ React24.createElement(DialogTitle, { sx: { fontWeight: "bold" } }, title), /* @__PURE__ */ React24.createElement(DialogContentText, { sx: { px: "10px", textAlign: "center", mb: 2 } }, body), /* @__PURE__ */ React24.createElement(DialogActions, null, options.map((option, index) => {
4203
- return /* @__PURE__ */ React24.createElement(
4204
- Button3,
4205
- {
4206
- key: index,
4207
- onClick: () => option.cb(option.label),
4208
- variant: option.focus ? "contained" : "text",
4209
- sx: {
4210
- fontWeight: option.focus ? "bold" : "normal",
4211
- color: option.focus ? "#fff" : "primary.main"
4565
+ return /* @__PURE__ */ jsx21(DefaultDialog, { open, ...rest, children: /* @__PURE__ */ jsxs10(Box6, { sx: { p: 2 }, children: [
4566
+ /* @__PURE__ */ jsx21(DialogTitle, { sx: { fontWeight: "bold" }, children: title }),
4567
+ /* @__PURE__ */ jsx21(DialogContentText, { sx: { px: "10px", textAlign: "center", mb: 2 }, children: body }),
4568
+ /* @__PURE__ */ jsx21(DialogActions, { children: options.map((option, index) => {
4569
+ return /* @__PURE__ */ jsx21(
4570
+ Button3,
4571
+ {
4572
+ onClick: () => option.cb(option.label),
4573
+ variant: option.focus ? "contained" : "text",
4574
+ sx: {
4575
+ fontWeight: option.focus ? "bold" : "normal",
4576
+ color: option.focus ? "#fff" : "primary.main"
4577
+ },
4578
+ disableElevation: true,
4579
+ disabled: loading,
4580
+ children: loading && option.focus ? /* @__PURE__ */ jsx21(CircularProgress3, { size: 25, color: "inherit" }) : /* @__PURE__ */ jsx21(Fragment7, { children: option.label })
4212
4581
  },
4213
- disableElevation: true,
4214
- disabled: loading
4215
- },
4216
- loading && option.focus ? /* @__PURE__ */ React24.createElement(CircularProgress3, { size: 25, color: "inherit" }) : /* @__PURE__ */ React24.createElement(React24.Fragment, null, option.label)
4217
- );
4218
- }))));
4582
+ index
4583
+ );
4584
+ }) })
4585
+ ] }) });
4219
4586
  };
4220
4587
 
4221
4588
  // src/components/DialogConfirm/DialogConfirm.view.tsx
4222
- import React25 from "react";
4223
4589
  import { Box as Box7, Portal, Stack as Stack2, Typography as Typography3 } from "@mui/material";
4224
4590
  import { grey, orange } from "@mui/material/colors";
4225
4591
  import { MdOutlineWarningAmber } from "react-icons/md";
@@ -4271,56 +4637,65 @@ function UseDialogConfirm() {
4271
4637
  }
4272
4638
 
4273
4639
  // src/components/DialogConfirm/DialogConfirm.view.tsx
4640
+ import { Fragment as Fragment8, jsx as jsx22, jsxs as jsxs11 } from "react/jsx-runtime";
4274
4641
  var DEFAULT_ICON = MdOutlineWarningAmber;
4275
4642
  var DialogConfirm = (props) => {
4276
4643
  const model = UseDialogConfirm();
4277
4644
  const Icon = props.icon || DEFAULT_ICON;
4278
- return /* @__PURE__ */ React25.createElement(React25.Fragment, null, props.children({
4279
- onConfirm: model.onConfirm,
4280
- onCancel: model.onCancel
4281
- }), /* @__PURE__ */ React25.createElement(Portal, null, /* @__PURE__ */ React25.createElement(Modal, { open: model.opened, onClose: model.onCloseModal }, /* @__PURE__ */ React25.createElement(Box7, { sx: { p: 2, maxWidth: 400, textAlign: "center" } }, /* @__PURE__ */ React25.createElement(
4282
- Stack2,
4283
- {
4284
- mx: "auto",
4285
- color: orange[800],
4286
- bgcolor: orange[50],
4287
- borderRadius: "50%",
4288
- height: 8 * 5,
4289
- width: 8 * 5,
4290
- direction: "row",
4291
- justifyContent: "center",
4292
- alignItems: "center"
4293
- },
4294
- /* @__PURE__ */ React25.createElement(Icon, { size: 8 * 3 })
4295
- ), /* @__PURE__ */ React25.createElement(Typography3, { fontWeight: "bold", variant: "h6", mt: 1 }, props.title || "Aten\xE7\xE3o"), /* @__PURE__ */ React25.createElement(Typography3, { my: 1 }, props.body || "Tem certeza que deseja realizar essa a\xE7\xE3o?"), /* @__PURE__ */ React25.createElement(Stack2, { gap: 1, mt: 3, color: grey[600] }, /* @__PURE__ */ React25.createElement(
4296
- LargeButton,
4297
- {
4298
- color: "warning",
4299
- loading: model.isLoading,
4300
- onClick: model.onProceed
4301
- },
4302
- props.confirmButtonText || "Confirmar"
4303
- ), /* @__PURE__ */ React25.createElement(
4304
- LargeButton,
4305
- {
4306
- variant: "outlined",
4307
- disabled: model.isLoading,
4308
- onClick: model.onCancel,
4309
- color: "inherit"
4310
- },
4311
- props.cancelButtonText || "Cancelar"
4312
- ))))));
4645
+ return /* @__PURE__ */ jsxs11(Fragment8, { children: [
4646
+ props.children({
4647
+ onConfirm: model.onConfirm,
4648
+ onCancel: model.onCancel
4649
+ }),
4650
+ /* @__PURE__ */ jsx22(Portal, { children: /* @__PURE__ */ jsx22(Modal, { open: model.opened, onClose: model.onCloseModal, children: /* @__PURE__ */ jsxs11(Box7, { sx: { p: 2, maxWidth: 400, textAlign: "center" }, children: [
4651
+ /* @__PURE__ */ jsx22(
4652
+ Stack2,
4653
+ {
4654
+ mx: "auto",
4655
+ color: orange[800],
4656
+ bgcolor: orange[50],
4657
+ borderRadius: "50%",
4658
+ height: 8 * 5,
4659
+ width: 8 * 5,
4660
+ direction: "row",
4661
+ justifyContent: "center",
4662
+ alignItems: "center",
4663
+ children: /* @__PURE__ */ jsx22(Icon, { size: 8 * 3 })
4664
+ }
4665
+ ),
4666
+ /* @__PURE__ */ jsx22(Typography3, { fontWeight: "bold", variant: "h6", mt: 1, children: props.title || "Aten\xE7\xE3o" }),
4667
+ /* @__PURE__ */ jsx22(Typography3, { my: 1, children: props.body || "Tem certeza que deseja realizar essa a\xE7\xE3o?" }),
4668
+ /* @__PURE__ */ jsxs11(Stack2, { gap: 1, mt: 3, color: grey[600], children: [
4669
+ /* @__PURE__ */ jsx22(
4670
+ LargeButton,
4671
+ {
4672
+ color: "warning",
4673
+ loading: model.isLoading,
4674
+ onClick: model.onProceed,
4675
+ children: props.confirmButtonText || "Confirmar"
4676
+ }
4677
+ ),
4678
+ /* @__PURE__ */ jsx22(
4679
+ LargeButton,
4680
+ {
4681
+ variant: "outlined",
4682
+ disabled: model.isLoading,
4683
+ onClick: model.onCancel,
4684
+ color: "inherit",
4685
+ children: props.cancelButtonText || "Cancelar"
4686
+ }
4687
+ )
4688
+ ] })
4689
+ ] }) }) })
4690
+ ] });
4313
4691
  };
4314
4692
 
4315
- // src/components/BaseDialog/BaseDialog.tsx
4316
- import React29 from "react";
4317
-
4318
4693
  // src/components/BaseDialog/BaseDialogHook.ts
4319
4694
  import { useContext as useContext2 } from "react";
4320
4695
 
4321
4696
  // src/components/BaseDialog/BaseDialogContext.tsx
4322
- import React26 from "react";
4323
4697
  import { createContext, useCallback, useState as useState5 } from "react";
4698
+ import { jsx as jsx23 } from "react/jsx-runtime";
4324
4699
  var BaseDialogContext = createContext({});
4325
4700
  var BaseDialogProvider = (props) => {
4326
4701
  const [openedDialogs, setOpenedDialogs] = useState5([]);
@@ -4348,7 +4723,7 @@ var BaseDialogProvider = (props) => {
4348
4723
  const closeAllDialogs = useCallback(() => {
4349
4724
  return setOpenedDialogs([]);
4350
4725
  }, [openedDialogs]);
4351
- return /* @__PURE__ */ React26.createElement(
4726
+ return /* @__PURE__ */ jsx23(
4352
4727
  BaseDialogContext.Provider,
4353
4728
  {
4354
4729
  value: {
@@ -4358,21 +4733,21 @@ var BaseDialogProvider = (props) => {
4358
4733
  open: openDialog,
4359
4734
  closeAll: closeAllDialogs,
4360
4735
  close: closeDialog
4361
- }
4362
- },
4363
- props.children
4736
+ },
4737
+ children: props.children
4738
+ }
4364
4739
  );
4365
4740
  };
4366
4741
 
4367
4742
  // src/components/BaseDialog/BaseDialogInstanceContext.tsx
4368
- import React27 from "react";
4369
4743
  import { createContext as createContext2 } from "react";
4744
+ import { jsx as jsx24 } from "react/jsx-runtime";
4370
4745
  var BaseDialogInstanceContext = createContext2(
4371
4746
  {}
4372
4747
  );
4373
4748
  var BaseDialogInstanceProvider = (props) => {
4374
4749
  const actions = useBaseDialog();
4375
- return /* @__PURE__ */ React27.createElement(BaseDialogInstanceContext.Provider, { value: { name: props.name, actions } }, props.children);
4750
+ return /* @__PURE__ */ jsx24(BaseDialogInstanceContext.Provider, { value: { name: props.name, actions }, children: props.children });
4376
4751
  };
4377
4752
 
4378
4753
  // src/components/BaseDialog/BaseDialogHook.ts
@@ -4387,13 +4762,13 @@ function useBaseDialogInstance() {
4387
4762
  import { Box as Box8, Button as Button4 } from "@mui/material";
4388
4763
 
4389
4764
  // src/components/BaseDialog/BaseDialogHeader.tsx
4390
- import React28 from "react";
4391
4765
  import {
4392
4766
  IconButton as IconButton4,
4393
4767
  Stack as Stack3,
4394
4768
  Typography as Typography4
4395
4769
  } from "@mui/material";
4396
4770
  import { MdClose as MdClose2 } from "react-icons/md";
4771
+ import { jsx as jsx25, jsxs as jsxs12 } from "react/jsx-runtime";
4397
4772
  var BaseDialogHeader = ({
4398
4773
  title,
4399
4774
  onClose,
@@ -4407,7 +4782,7 @@ var BaseDialogHeader = ({
4407
4782
  if (onClose) return onClose();
4408
4783
  closeDialog(name);
4409
4784
  }
4410
- return /* @__PURE__ */ React28.createElement(
4785
+ return /* @__PURE__ */ jsxs12(
4411
4786
  Stack3,
4412
4787
  {
4413
4788
  direction: "row",
@@ -4415,24 +4790,27 @@ var BaseDialogHeader = ({
4415
4790
  justifyContent: "space-between",
4416
4791
  px: 2,
4417
4792
  my: 1,
4418
- ...props
4419
- },
4420
- /* @__PURE__ */ React28.createElement(Typography4, { variant: "h6", fontWeight: "bold", ...TypographyProps2 }, title),
4421
- /* @__PURE__ */ React28.createElement(IconButton4, { ...IconButtonProps, onClick: handleClose }, /* @__PURE__ */ React28.createElement(MdClose2, null))
4793
+ ...props,
4794
+ children: [
4795
+ /* @__PURE__ */ jsx25(Typography4, { variant: "h6", fontWeight: "bold", ...TypographyProps2, children: title }),
4796
+ /* @__PURE__ */ jsx25(IconButton4, { ...IconButtonProps, onClick: handleClose, children: /* @__PURE__ */ jsx25(MdClose2, {}) })
4797
+ ]
4798
+ }
4422
4799
  );
4423
4800
  };
4424
4801
 
4425
4802
  // src/components/BaseDialog/BaseDialog.tsx
4803
+ import { jsx as jsx26 } from "react/jsx-runtime";
4426
4804
  var BaseDialogContainer = ({
4427
4805
  children,
4428
4806
  ...rest
4429
4807
  }) => {
4430
4808
  const { name } = useBaseDialogInstance();
4431
4809
  const { isOpened, close: closeDialog } = useBaseDialog();
4432
- return /* @__PURE__ */ React29.createElement(Modal, { open: isOpened(name), onClose: () => closeDialog(name), ...rest }, children instanceof Function ? children({ close: () => closeDialog(name) }) : children);
4810
+ return /* @__PURE__ */ jsx26(Modal, { open: isOpened(name), onClose: () => closeDialog(name), ...rest, children: children instanceof Function ? children({ close: () => closeDialog(name) }) : children });
4433
4811
  };
4434
4812
  var BaseDialogBody = (props) => {
4435
- return /* @__PURE__ */ React29.createElement(Box8, { px: 2, pb: 2, width: "100vw", maxWidth: 650, ...props }, props.children);
4813
+ return /* @__PURE__ */ jsx26(Box8, { px: 2, pb: 2, width: "100vw", maxWidth: 650, ...props, children: props.children });
4436
4814
  };
4437
4815
  var BaseDialogTrigger = ({
4438
4816
  name,
@@ -4440,23 +4818,23 @@ var BaseDialogTrigger = ({
4440
4818
  ...props
4441
4819
  }) => {
4442
4820
  const { open } = useBaseDialog();
4443
- return /* @__PURE__ */ React29.createElement(
4821
+ return /* @__PURE__ */ jsx26(
4444
4822
  Button4,
4445
4823
  {
4446
4824
  ...props,
4447
4825
  onClick: (...params) => {
4448
4826
  if (onClick) onClick(...params);
4449
4827
  open(name);
4450
- }
4451
- },
4452
- props.children
4828
+ },
4829
+ children: props.children
4830
+ }
4453
4831
  );
4454
4832
  };
4455
4833
  var BaseDialogCreate = (name = /* @__PURE__ */ Symbol()) => {
4456
4834
  return {
4457
4835
  name,
4458
- Trigger: (props) => /* @__PURE__ */ React29.createElement(BaseDialogTrigger, { name, ...props }),
4459
- Root: (props) => /* @__PURE__ */ React29.createElement(BaseDialogInstanceProvider, { name, ...props }),
4836
+ Trigger: (props) => /* @__PURE__ */ jsx26(BaseDialogTrigger, { name, ...props }),
4837
+ Root: (props) => /* @__PURE__ */ jsx26(BaseDialogInstanceProvider, { name, ...props }),
4460
4838
  Container: BaseDialogContainer,
4461
4839
  Header: BaseDialogHeader,
4462
4840
  Body: BaseDialogBody
@@ -4472,163 +4850,56 @@ var BaseDialog = {
4472
4850
  Body: BaseDialogBody
4473
4851
  };
4474
4852
 
4475
- // src/errors/HttpError.ts
4476
- var HttpError = class extends Error {
4477
- constructor(status, message) {
4478
- super(message);
4479
- this.message = message;
4480
- this.stack = `HttpError: ${message}`;
4481
- this.status = status;
4482
- }
4853
+ // src/contexts/FormHelperProvider.tsx
4854
+ import { createContext as createContext3 } from "react";
4855
+ import { jsx as jsx27 } from "react/jsx-runtime";
4856
+ var FormHelperContext = createContext3({});
4857
+ var FormHelperProvider = ({ formatErrorMessage, api, children }) => {
4858
+ return /* @__PURE__ */ jsx27(FormHelperContext.Provider, { value: { formatErrorMessage, api }, children });
4483
4859
  };
4484
4860
 
4485
- // src/errors/DomainError.ts
4486
- var DomainError = class extends Error {
4487
- constructor(message) {
4488
- super(message);
4489
- this.message = message;
4490
- this.stack = `DomainError: ${message}`;
4491
- }
4492
- };
4493
-
4494
- // src/helpers/apiHelper/index.ts
4495
- var VALID_METHODS = [
4496
- "GET",
4497
- "HEAD",
4498
- "POST",
4499
- "PUT",
4500
- "DELETE",
4501
- "CONNECT",
4502
- "OPTIONS",
4503
- "TRACE",
4504
- "PATCH"
4505
- ];
4506
- var _ApiHelper = class _ApiHelper {
4507
- async onFinally(_req, _res) {
4508
- }
4509
- async onError(_req, _res, _error) {
4510
- }
4511
- constructor(props) {
4512
- this.public = props?.public ?? false;
4513
- this.middlewares = (props?.middlewares || []).reverse();
4514
- this.onFinally = props?.onFinally || (async () => {
4515
- });
4516
- this.onError = props?.onError || (async () => {
4517
- });
4518
- }
4519
- createMethods(methods) {
4520
- return async (req, res) => {
4521
- const currentMethod = methods[req.method] || methods.ALL;
4522
- const options = { public: this.public };
4523
- if (req.method === "OPTIONS") return res.status(200).end();
4524
- try {
4525
- if (!VALID_METHODS.includes(req.method))
4526
- throw new HttpError(405, "M\xE9todo inv\xE1lido");
4527
- if (!currentMethod) throw new HttpError(500, "M\xE9todo n\xE3o encontrado");
4528
- const methodWithMiddlewares = this.middlewares.reduce(
4529
- (acc, fn) => fn(acc, options),
4530
- currentMethod
4531
- );
4532
- return await methodWithMiddlewares(req, res, options);
4533
- } catch (error) {
4534
- if (error instanceof DomainError) return res.status(400).json(error.message);
4535
- if (error instanceof HttpError) return res.status(error.status).json(error.message);
4536
- this.onError(req, res, error);
4537
- throw error;
4538
- } finally {
4539
- await this.onFinally(req, res);
4540
- }
4541
- };
4542
- }
4543
- buildFactory(factory) {
4544
- const options = {
4545
- public: this.public
4546
- };
4547
- return async (req, res) => {
4548
- const methods = factory(req, res);
4549
- const handler = methods[req.method];
4550
- const methodWithMiddlewares = this.middlewares.reduce((acc, fn) => {
4551
- return fn(acc, options);
4552
- }, handler);
4553
- return await methodWithMiddlewares(req, res, options);
4554
- };
4555
- }
4556
- static build(factory, options) {
4557
- const helper = new _ApiHelper({
4558
- ...options
4559
- }).buildFactory(factory);
4560
- return helper;
4561
- }
4562
- static parse(body, parser) {
4563
- try {
4564
- const object = parser.parse(body);
4565
- return object;
4566
- } catch (error) {
4567
- throw new HttpError(400, {
4568
- code: "invalid.body",
4569
- error: "Dados inv\xE1lidos",
4570
- details: error
4571
- });
4572
- }
4573
- }
4574
- /** @deprecated Use {@Link ApiHelper.build} instead. */
4575
- static create({ onFinally }) {
4576
- return new _ApiHelper({
4577
- onFinally
4578
- });
4579
- }
4580
- };
4581
- /** @deprecated Use {@link ApiHelper.parser} instead. */
4582
- _ApiHelper.parserErrorWrapper = _ApiHelper.parse;
4583
- var ApiHelper = _ApiHelper;
4584
-
4585
- // src/hooks/useFormHelper.ts
4586
- import { useCallback as useCallback4, useContext as useContext4, useEffect as useEffect4, useRef as useRef4 } from "react";
4587
-
4588
- // src/hooks/useAlert.ts
4589
- import { useContext as useContext3 } from "react";
4590
-
4591
- // src/contexts/AlertContext.tsx
4592
- import React31, { useCallback as useCallback2 } from "react";
4593
- import { createContext as createContext3, useState as useState6 } from "react";
4594
-
4595
- // src/components/Toast/index.tsx
4596
- import React30 from "react";
4597
- import { Alert, IconButton as IconButton5, Snackbar } from "@mui/material";
4598
- import { MdClose as MdClose3 } from "react-icons/md";
4599
- var Toast = ({ open, onClose, severity, message }) => {
4600
- return /* @__PURE__ */ React30.createElement(React30.Fragment, null, /* @__PURE__ */ React30.createElement(
4601
- Snackbar,
4602
- {
4603
- open,
4604
- autoHideDuration: 6e3,
4605
- onClose,
4606
- anchorOrigin: { vertical: "top", horizontal: "right" },
4607
- sx: { zIndex: 99999999 }
4608
- },
4609
- /* @__PURE__ */ React30.createElement(
4610
- Alert,
4611
- {
4612
- severity,
4613
- elevation: 2,
4614
- action: /* @__PURE__ */ React30.createElement(
4615
- IconButton5,
4616
- {
4617
- "aria-label": "close",
4618
- color: "inherit",
4619
- size: "small",
4620
- onClick: onClose
4621
- },
4622
- /* @__PURE__ */ React30.createElement(MdClose3, { fontSize: "inherit" })
4623
- )
4624
- },
4625
- message
4626
- )
4627
- ));
4861
+ // src/contexts/AlertContext.tsx
4862
+ import { useCallback as useCallback2 } from "react";
4863
+ import { createContext as createContext4, useState as useState6 } from "react";
4864
+
4865
+ // src/components/Toast/index.tsx
4866
+ import { Alert, IconButton as IconButton5, Snackbar } from "@mui/material";
4867
+ import { MdClose as MdClose3 } from "react-icons/md";
4868
+ import { Fragment as Fragment9, jsx as jsx28 } from "react/jsx-runtime";
4869
+ var Toast = ({ open, onClose, severity, message }) => {
4870
+ return /* @__PURE__ */ jsx28(Fragment9, { children: /* @__PURE__ */ jsx28(
4871
+ Snackbar,
4872
+ {
4873
+ open,
4874
+ autoHideDuration: 6e3,
4875
+ onClose,
4876
+ anchorOrigin: { vertical: "top", horizontal: "right" },
4877
+ sx: { zIndex: 99999999 },
4878
+ children: /* @__PURE__ */ jsx28(
4879
+ Alert,
4880
+ {
4881
+ severity,
4882
+ elevation: 2,
4883
+ action: /* @__PURE__ */ jsx28(
4884
+ IconButton5,
4885
+ {
4886
+ "aria-label": "close",
4887
+ color: "inherit",
4888
+ size: "small",
4889
+ onClick: onClose,
4890
+ children: /* @__PURE__ */ jsx28(MdClose3, { fontSize: "inherit" })
4891
+ }
4892
+ ),
4893
+ children: message
4894
+ }
4895
+ )
4896
+ }
4897
+ ) });
4628
4898
  };
4629
4899
 
4630
4900
  // src/contexts/AlertContext.tsx
4631
- var AlertContext = createContext3({});
4901
+ import { jsx as jsx29, jsxs as jsxs13 } from "react/jsx-runtime";
4902
+ var AlertContext = createContext4({});
4632
4903
  var AlertProvider = ({ children }) => {
4633
4904
  const [severity, setSeverity] = useState6("info");
4634
4905
  const [message, setMessage] = useState6("");
@@ -4644,1050 +4915,1012 @@ var AlertProvider = ({ children }) => {
4644
4915
  const onCloseToast = useCallback2(() => {
4645
4916
  setIsVisible(false);
4646
4917
  }, []);
4647
- return /* @__PURE__ */ React31.createElement(AlertContext.Provider, { value: { createAlert } }, children, /* @__PURE__ */ React31.createElement(
4648
- Toast,
4649
- {
4650
- open: isVisible,
4651
- onClose: onCloseToast,
4652
- severity,
4653
- message
4654
- }
4655
- ));
4918
+ return /* @__PURE__ */ jsxs13(AlertContext.Provider, { value: { createAlert }, children: [
4919
+ children,
4920
+ /* @__PURE__ */ jsx29(
4921
+ Toast,
4922
+ {
4923
+ open: isVisible,
4924
+ onClose: onCloseToast,
4925
+ severity,
4926
+ message
4927
+ }
4928
+ )
4929
+ ] });
4656
4930
  };
4657
4931
 
4658
- // src/hooks/useAlert.ts
4659
- var useAlert = () => {
4660
- return useContext3(AlertContext);
4661
- };
4932
+ // src/contexts/AuthContext.tsx
4933
+ import {
4934
+ createContext as createContext5,
4935
+ useCallback as useCallback8,
4936
+ useEffect as useEffect8,
4937
+ useState as useState11
4938
+ } from "react";
4662
4939
 
4663
- // src/hooks/useLoading.ts
4940
+ // src/hooks/useGrid.ts
4941
+ import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo3, useState as useState8 } from "react";
4942
+
4943
+ // src/hooks/useFilter.ts
4664
4944
  import { useCallback as useCallback3, useState as useState7 } from "react";
4665
- function useLoading() {
4666
- const [state, setState] = useState7([]);
4667
- const isLoading = useCallback3((prop) => state.includes(prop), [state]);
4668
- const setLoading = useCallback3((prop, remove) => {
4669
- if (remove)
4670
- setState((prevState) => prevState.filter((state2) => state2 !== prop));
4671
- else setState((prevState) => [...prevState, prop]);
4672
- }, []);
4673
- return { isLoading, setLoading };
4674
- }
4675
4945
 
4676
- // src/contexts/FormHelperProvider.tsx
4677
- import React32 from "react";
4678
- import { createContext as createContext4 } from "react";
4679
- var FormHelperContext = createContext4({});
4680
- var FormHelperProvider = ({ formatErrorMessage, api, children }) => {
4681
- return /* @__PURE__ */ React32.createElement(FormHelperContext.Provider, { value: { formatErrorMessage, api } }, children);
4682
- };
4946
+ // src/components/utils/getObjectValue.ts
4947
+ function getObjectValue(obj) {
4948
+ return (prop) => {
4949
+ try {
4950
+ return prop.split(".").reduce((o, k) => o[k], obj);
4951
+ } catch (_) {
4952
+ return void 0;
4953
+ }
4954
+ };
4955
+ }
4683
4956
 
4684
- // src/hooks/useFormHelper.ts
4685
- function useFormHelper() {
4686
- const alertProps = useAlert();
4687
- const loadingProps = useLoading();
4688
- const { api, formatErrorMessage } = useContext4(FormHelperContext);
4689
- const { createAlert } = alertProps;
4690
- const { setLoading } = loadingProps;
4691
- const sourceRef = useRef4(new AbortController());
4692
- const onSubmitWrapper = useCallback4(
4693
- (fn, { name }) => {
4694
- return async (fields, methods) => {
4695
- const LOADING_NAME = name;
4696
- setLoading(LOADING_NAME);
4697
- try {
4698
- await fn(fields, methods);
4699
- } catch (error) {
4700
- errorHandler(error, methods.setErrors);
4701
- } finally {
4702
- setLoading(LOADING_NAME, true);
4703
- }
4704
- };
4705
- },
4706
- [setLoading]
4707
- );
4708
- const onRequestWrapper = useCallback4(
4709
- (fn, { name }) => {
4710
- return async (...params) => {
4711
- const LOADING_NAME = name;
4712
- setLoading(LOADING_NAME);
4713
- api.interceptors.request.use(
4714
- (config) => {
4715
- if (!config.signal && sourceRef.current && config.method === "get") {
4716
- config.signal = sourceRef.current.signal;
4717
- }
4718
- return config;
4719
- },
4720
- (error) => {
4721
- return Promise.reject(error);
4722
- }
4723
- );
4724
- try {
4725
- const response = await fn(...params);
4726
- return response;
4727
- } catch (error) {
4728
- errorHandler(error);
4729
- } finally {
4730
- setLoading(LOADING_NAME, true);
4731
- }
4732
- };
4733
- },
4734
- [setLoading, api]
4735
- );
4736
- const errorHandler = useCallback4(
4737
- (error, callback) => {
4738
- if (error?.message === "cancel.navigation") return;
4739
- if (callback) {
4740
- if (error.response.data.code === "invalid.body") {
4741
- const errors = error.response.data.details.issues;
4742
- const currentErrors = errors.reduce((acc, item) => {
4743
- acc[item.path.join(".")] = item.message;
4744
- return acc;
4745
- }, {});
4746
- callback(currentErrors);
4747
- }
4748
- }
4749
- createAlert(formatErrorMessage(error), "error");
4957
+ // src/hooks/useFilter.ts
4958
+ function useFilter(props = { defaultFilters: [] }) {
4959
+ const [selectedFilters, setSelectedFilters] = useState7(() => {
4960
+ const { defaultFilters } = props;
4961
+ return defaultFilters || [];
4962
+ });
4963
+ const filterBy = useCallback3((newFilter) => {
4964
+ const propToCompare = newFilter?.id ? "id" : "prop";
4965
+ function removeRepeatedFilters(filter) {
4966
+ return filter[propToCompare] !== newFilter[propToCompare];
4967
+ }
4968
+ setSelectedFilters((filters) => [
4969
+ ...filters.filter(removeRepeatedFilters),
4970
+ newFilter
4971
+ ]);
4972
+ }, []);
4973
+ const removeFilter = useCallback3(
4974
+ (prop, isId) => {
4975
+ const propToCompare = isId ? "id" : "prop";
4976
+ setSelectedFilters(
4977
+ selectedFilters.filter((filter) => filter[propToCompare] !== prop)
4978
+ );
4750
4979
  },
4751
- [formatErrorMessage, createAlert]
4980
+ [selectedFilters]
4752
4981
  );
4753
- useEffect4(() => {
4754
- return () => {
4755
- sourceRef.current.abort();
4756
- sourceRef.current = new AbortController();
4757
- };
4758
- }, []);
4982
+ function clearAllFilters() {
4983
+ setSelectedFilters([]);
4984
+ }
4759
4985
  return {
4760
- ...alertProps,
4761
- ...loadingProps,
4762
- onSubmitWrapper,
4763
- onRequestWrapper
4986
+ filters: selectedFilters,
4987
+ filterBy,
4988
+ removeFilter,
4989
+ createFilter,
4990
+ clearAllFilters
4764
4991
  };
4765
4992
  }
4766
-
4767
- // src/helpers/authHelper.ts
4768
- import { serialize as serialize2 } from "cookie";
4769
- import { v4 as uuid } from "uuid";
4770
- import jwt from "jsonwebtoken";
4771
-
4772
- // packages/nookies/index.ts
4773
- import * as cookie from "cookie";
4774
- import * as setCookieParser from "set-cookie-parser";
4775
-
4776
- // packages/nookies/util.ts
4777
- function isBrowser() {
4778
- return typeof window !== "undefined";
4993
+ function isDate(date) {
4994
+ if (date instanceof Date) return true;
4995
+ else if (String(date).endsWith("Z")) return true;
4996
+ return false;
4779
4997
  }
4780
- function createCookie(name, value, options) {
4781
- let sameSite = options.sameSite;
4782
- if (sameSite === true) {
4783
- sameSite = "strict";
4784
- }
4785
- if (sameSite === void 0 || sameSite === false) {
4786
- sameSite = "lax";
4998
+ function compareFilter(item, filter) {
4999
+ const itemValue = getObjectValue(item)(filter.prop);
5000
+ switch (filter.compareType) {
5001
+ case "equal":
5002
+ return itemValue === filter.value;
5003
+ case "notEqual":
5004
+ return itemValue !== filter.value;
5005
+ case "in":
5006
+ return filter.value.includes(itemValue);
5007
+ case "notIn":
5008
+ return !filter.value.includes(itemValue);
5009
+ case "valueIn":
5010
+ return itemValue.includes(filter.value);
5011
+ case "valueNotIn":
5012
+ return !itemValue.includes(filter.value);
5013
+ case "gte":
5014
+ return isDate(itemValue) ? new Date(String(itemValue)) >= filter.value : itemValue >= filter.value;
5015
+ case "gt":
5016
+ return isDate(itemValue) ? new Date(String(itemValue)) > filter.value : itemValue > filter.value;
5017
+ case "lte":
5018
+ return isDate(itemValue) ? new Date(String(itemValue)) <= filter.value : itemValue <= filter.value;
5019
+ case "lt":
5020
+ return isDate(itemValue) ? new Date(String(itemValue)) < filter.value : itemValue < filter.value;
4787
5021
  }
4788
- const cookieToSet = { ...options, sameSite };
4789
- delete cookieToSet.encode;
4790
- return {
4791
- name,
4792
- value,
4793
- ...cookieToSet
4794
- };
4795
5022
  }
4796
- function hasSameProperties(a, b) {
4797
- const aProps = Object.getOwnPropertyNames(a);
4798
- const bProps = Object.getOwnPropertyNames(b);
4799
- if (aProps.length !== bProps.length) {
4800
- return false;
4801
- }
4802
- for (let i = 0; i < aProps.length; i++) {
4803
- const propName = aProps[i];
4804
- if (a[propName] !== b[propName]) {
4805
- return false;
4806
- }
4807
- }
4808
- return true;
4809
- }
4810
- function areCookiesEqual(a, b) {
4811
- let sameSiteSame = a.sameSite === b.sameSite;
4812
- if (typeof a.sameSite === "string" && typeof b.sameSite === "string") {
4813
- sameSiteSame = a.sameSite.toLowerCase() === b.sameSite.toLowerCase();
5023
+ function createFilter(filters) {
5024
+ function apply(item) {
5025
+ const satisfiedFilters = filters.reduce((acc, filter) => {
5026
+ if (compareFilter(item, filter)) acc += 1;
5027
+ return acc;
5028
+ }, 0);
5029
+ return satisfiedFilters === filters.length;
4814
5030
  }
4815
- return hasSameProperties(
4816
- { ...a, sameSite: void 0 },
4817
- { ...b, sameSite: void 0 }
4818
- ) && sameSiteSame;
5031
+ return {
5032
+ apply
5033
+ };
4819
5034
  }
4820
5035
 
4821
- // packages/nookies/index.ts
4822
- function parseCookies(ctx, options) {
4823
- if (ctx?.req?.headers?.cookie) {
4824
- return cookie.parse(ctx.req.headers.cookie, options);
4825
- }
4826
- if (isBrowser()) {
4827
- return cookie.parse(document.cookie, options);
4828
- }
4829
- return {};
4830
- }
4831
- function setCookie(ctx, name, value, options = {}) {
4832
- if (ctx?.res?.getHeader && ctx.res.setHeader) {
4833
- if (ctx?.res?.finished) {
4834
- console.warn(`Not setting "${name}" cookie. Response has finished.`);
4835
- console.warn(`You should set cookie before res.send()`);
4836
- return {};
4837
- }
4838
- let cookies = ctx.res.getHeader("Set-Cookie") || [];
4839
- if (typeof cookies === "string") cookies = [cookies];
4840
- if (typeof cookies === "number") cookies = [];
4841
- const parsedCookies = setCookieParser.parse(cookies, {
4842
- decodeValues: false
4843
- });
4844
- const newCookie = createCookie(name, value, options);
4845
- let cookiesToSet = [];
4846
- parsedCookies.forEach((parsedCookie) => {
4847
- if (!areCookiesEqual(parsedCookie, newCookie)) {
4848
- const serializedCookie = cookie.serialize(
4849
- parsedCookie.name,
4850
- parsedCookie.value,
4851
- {
4852
- // we prevent reencoding by default, but you might override it
4853
- encode: (val) => val,
4854
- ...parsedCookie
4855
- }
4856
- );
4857
- cookiesToSet.push(serializedCookie);
5036
+ // src/helpers/sortHelper.ts
5037
+ function SortHelper(...fields) {
5038
+ return (a, b) => {
5039
+ for (const field of fields) {
5040
+ let direction = 1;
5041
+ let key = field;
5042
+ if (field.startsWith("-")) {
5043
+ direction = -1;
5044
+ key = field.slice(1);
4858
5045
  }
4859
- });
4860
- cookiesToSet.push(cookie.serialize(name, value, options));
4861
- ctx.res.setHeader("Set-Cookie", cookiesToSet);
4862
- }
4863
- if (isBrowser()) {
4864
- if (options && options.httpOnly) {
4865
- throw new Error("Can not set a httpOnly cookie in the browser.");
5046
+ const aVal = a[key];
5047
+ const bVal = b[key];
5048
+ if (aVal > bVal) return direction;
5049
+ if (aVal < bVal) return -direction;
4866
5050
  }
4867
- document.cookie = cookie.serialize(name, value, options);
4868
- }
4869
- return {};
4870
- }
4871
- function destroyCookie(ctx, name, options) {
4872
- return setCookie(ctx, name, "", { ...options || {}, maxAge: -1 });
5051
+ return 0;
5052
+ };
4873
5053
  }
4874
- var nookies = {
4875
- set: setCookie,
4876
- get: parseCookies,
4877
- destroy: destroyCookie
4878
- };
4879
5054
 
4880
- // src/helpers/authHelper.ts
4881
- function decodeSessionToken({
4882
- req,
4883
- res,
4884
- sessionTokenName,
4885
- validate
5055
+ // src/hooks/useGrid.ts
5056
+ function useGrid({
5057
+ columns,
5058
+ filters,
5059
+ search,
5060
+ rowsPerPageOptions = [30, 60, 100],
5061
+ defaultData: externalDefaultData,
5062
+ defaultCurrentPage,
5063
+ defaultSortedBy
4886
5064
  }) {
4887
- const token = req.headers.authorization?.split(" ")[1] || req.cookies[sessionTokenName];
4888
- if (!token) {
4889
- res.status(401).json({ error: "Token inv\xE1lido", code: "token.invalid" });
4890
- return true;
4891
- }
4892
- const jwtDecode = (token2) => {
4893
- if (validate) {
4894
- return jwt.verify(token2, process.env.JWT_SECRET);
5065
+ const [defaultData, setDefaultData] = useState8(externalDefaultData || []);
5066
+ const [sortedBy, setSortedBy] = useState8(
5067
+ defaultSortedBy || []
5068
+ );
5069
+ const [currentPage, setCurrentPage] = useState8(defaultCurrentPage || 0);
5070
+ const [rowsPerPage, setRowsPerPage] = useState8(rowsPerPageOptions[0]);
5071
+ const toggleSortedDirection = useCallback4(
5072
+ (direction) => {
5073
+ if (direction === "asc") return "desc";
5074
+ return "asc";
5075
+ },
5076
+ []
5077
+ );
5078
+ const clearSort = useCallback4(() => {
5079
+ setSortedBy([]);
5080
+ }, []);
5081
+ const appendSort = useCallback4((prop, direction) => {
5082
+ setSortedBy((prev) => [...prev, { prop, direction }]);
5083
+ }, []);
5084
+ const setSort = useCallback4((prop, direction) => {
5085
+ setSortedBy([{ prop, direction }]);
5086
+ }, []);
5087
+ const onSortBy = useCallback4(
5088
+ (prop) => {
5089
+ if (!prop) return;
5090
+ const currentSorted = sortedBy.find((p) => p.prop === prop);
5091
+ if (currentSorted) {
5092
+ if (currentSorted.direction === "asc") {
5093
+ setSortedBy((prev) => prev.filter((p) => p.prop !== prop));
5094
+ } else {
5095
+ setSortedBy((prev) => {
5096
+ const newArr = prev.map((p) => {
5097
+ if (p.prop !== prop) return p;
5098
+ return {
5099
+ prop: p.prop,
5100
+ direction: toggleSortedDirection(p.direction)
5101
+ };
5102
+ });
5103
+ return [...newArr].slice(0);
5104
+ });
5105
+ }
5106
+ } else {
5107
+ setSortedBy((prev) => [...prev, { prop, direction: "desc" }]);
5108
+ }
5109
+ },
5110
+ [toggleSortedDirection, sortedBy]
5111
+ );
5112
+ const set = useCallback4((data) => {
5113
+ setDefaultData(data);
5114
+ }, []);
5115
+ const sortData = useCallback4(
5116
+ (data) => {
5117
+ if (sortedBy.length > 0) {
5118
+ const symbolDir = {
5119
+ asc: "",
5120
+ desc: "-"
5121
+ };
5122
+ const formattedKeys = sortedBy.map(
5123
+ ({ prop, direction }) => `${symbolDir[direction]}${prop}`
5124
+ );
5125
+ return data.sort(SortHelper(...formattedKeys));
5126
+ } else return data;
5127
+ },
5128
+ [sortedBy]
5129
+ );
5130
+ const onPageChange = (pageNumber) => {
5131
+ if (pageNumber < 0) return;
5132
+ if (pageNumber > totalNumberOfPages) return;
5133
+ setCurrentPage(pageNumber);
5134
+ };
5135
+ const onChangeRowsPerPage = useCallback4(
5136
+ (rows) => {
5137
+ let totalNumberOfPages2 = Math.round(filteredData.length / rows) - 1;
5138
+ totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
5139
+ if (currentPage > totalNumberOfPages2) setCurrentPage(totalNumberOfPages2);
5140
+ setRowsPerPage(rows);
5141
+ },
5142
+ [currentPage]
5143
+ );
5144
+ const orderedData = useMemo3(() => {
5145
+ if (sortedBy.length === 0) return defaultData;
5146
+ const newData = defaultData.slice(0);
5147
+ const sortedData = sortData(newData);
5148
+ return sortedData;
5149
+ }, [defaultData, sortData, sortedBy]);
5150
+ const filteredData = useMemo3(() => {
5151
+ let newData = orderedData.slice(0);
5152
+ if (search && search.value !== "") {
5153
+ const searchBy = createSearch(search);
5154
+ newData = newData.filter(searchBy);
4895
5155
  }
4896
- return jwt.decode(token2);
5156
+ if (!filters) return newData;
5157
+ const newFilter = createFilter(filters);
5158
+ return newData.filter(newFilter.apply);
5159
+ }, [orderedData, search, filters]);
5160
+ const paginatedData = useMemo3(() => {
5161
+ const startPage = currentPage * rowsPerPage;
5162
+ const endPage = startPage + rowsPerPage;
5163
+ return filteredData.slice(startPage, endPage);
5164
+ }, [currentPage, rowsPerPage, filteredData]);
5165
+ const totalNumberOfPages = Math.ceil(filteredData.length / rowsPerPage) - 1;
5166
+ useEffect4(() => {
5167
+ if (externalDefaultData) setDefaultData(externalDefaultData);
5168
+ }, [externalDefaultData]);
5169
+ return {
5170
+ data: paginatedData,
5171
+ orderedData,
5172
+ filteredData,
5173
+ defaultData,
5174
+ sortedBy,
5175
+ columns,
5176
+ currentPage,
5177
+ totalNumberOfPages: totalNumberOfPages < 0 ? 0 : totalNumberOfPages,
5178
+ rowsPerPageOptions,
5179
+ rowsPerPage,
5180
+ set,
5181
+ onSortBy,
5182
+ onPageChange,
5183
+ setRowsPerPage: onChangeRowsPerPage,
5184
+ appendSort,
5185
+ setSort,
5186
+ clearSort
4897
5187
  };
4898
- try {
4899
- const decoded = jwtDecode(token);
4900
- req.user = decoded.sub;
4901
- } catch (_) {
4902
- res.status(401).json({ error: "Token inv\xE1lido", code: "token.expired" });
4903
- return true;
4904
- }
4905
5188
  }
4906
- var AuthHelper = class {
4907
- constructor({
4908
- cookies,
4909
- oauth,
4910
- tokenExpTimeInSeconds,
4911
- onLogin,
4912
- onValidateRefreshToken,
4913
- onInvalidateRefreshToken,
4914
- onCreateRefreshToken,
4915
- onGetUserData
4916
- }) {
4917
- this.generateJwtAndRefreshToken = async (userId, payload = {}) => {
4918
- const token = jwt.sign(payload, process.env.JWT_SECRET, {
4919
- subject: String(userId),
4920
- expiresIn: this.tokenExpTimeInSeconds || 60 * 15
4921
- // 15 minutos
4922
- });
4923
- const uniqueToken = uuid();
4924
- await this.onCreateRefreshToken(userId, uniqueToken);
4925
- return {
4926
- token,
4927
- refreshToken: uniqueToken
4928
- };
4929
- };
4930
- this.invalidateCookies = (res) => {
4931
- return res.setHeader("Set-Cookie", [
4932
- serialize2(this.cookies.sessionToken, "", {
4933
- maxAge: -1,
4934
- path: "/"
4935
- }),
4936
- serialize2(this.cookies.refreshToken, "", {
4937
- maxAge: -1,
4938
- path: "/"
4939
- })
4940
- ]);
4941
- };
4942
- this.cookies = cookies;
4943
- this.oauth = oauth;
4944
- this.tokenExpTimeInSeconds = tokenExpTimeInSeconds;
4945
- this.onLogin = onLogin;
4946
- this.onValidateRefreshToken = onValidateRefreshToken;
4947
- this.onInvalidateRefreshToken = onInvalidateRefreshToken;
4948
- this.onCreateRefreshToken = onCreateRefreshToken;
4949
- this.onGetUserData = onGetUserData;
4950
- }
4951
- async handler(req, res) {
4952
- if (!req.url) return res.status(400).json({ error: "url not sent" });
4953
- if (req.url.endsWith("/login")) {
4954
- const loginResult = await this.onLogin(req.body);
4955
- if (loginResult.status === "sucess") {
4956
- const { refreshToken, token } = await this.generateJwtAndRefreshToken(
4957
- loginResult.userId,
4958
- {}
4959
- );
4960
- setCookie({ res }, this.cookies.sessionToken, token, {
4961
- secure: true,
4962
- maxAge: 60 * 60 * 24 * 30,
4963
- // 30 days
4964
- path: "/",
4965
- sameSite: true
4966
- });
4967
- setCookie({ res }, this.cookies.refreshToken, refreshToken, {
4968
- secure: true,
4969
- maxAge: 60 * 60 * 24 * 30,
4970
- // 30 days
4971
- path: "/",
4972
- sameSite: true,
4973
- httpOnly: true
4974
- });
4975
- return res.json({ token, refreshToken });
4976
- }
4977
- throw new HttpError(400, loginResult.response);
4978
- }
4979
- if (req.url.endsWith("/logout")) {
4980
- this.invalidateCookies(res).end();
4981
- }
4982
- if (req.url.endsWith("/refresh")) {
4983
- const error = decodeSessionToken({
4984
- req,
4985
- res,
4986
- sessionTokenName: this.cookies.sessionToken,
4987
- validate: false
4988
- });
4989
- if (error) return;
4990
- const userId = String(req.user);
4991
- const refreshToken = parseCookies({ req })[this.cookies.refreshToken];
4992
- if (!refreshToken) {
4993
- this.invalidateCookies(res);
4994
- return res.status(400).json({
4995
- error: "Refresh Token inv\xE1lido"
4996
- });
4997
- }
4998
- const isValidRefreshToken = await this.onValidateRefreshToken(
4999
- userId,
5000
- refreshToken
5001
- );
5002
- if (!isValidRefreshToken) {
5003
- this.invalidateCookies(res);
5004
- return res.status(400).json({
5005
- error: "Refresh Token inv\xE1lido"
5006
- });
5007
- }
5008
- await this.onInvalidateRefreshToken(userId, refreshToken);
5009
- const { token, refreshToken: newRefreshToken } = await this.generateJwtAndRefreshToken(userId, {});
5010
- setCookie({ res }, this.cookies.sessionToken, token, {
5011
- secure: true,
5012
- maxAge: 60 * 60 * 24 * 30,
5013
- // 30 days
5014
- path: "/",
5015
- sameSite: true
5016
- });
5017
- setCookie({ res }, this.cookies.refreshToken, newRefreshToken, {
5018
- secure: true,
5019
- maxAge: 60 * 60 * 24 * 30,
5020
- // 30 days
5021
- path: "/",
5022
- sameSite: true,
5023
- httpOnly: true
5024
- });
5025
- return res.json({
5026
- token,
5027
- refreshToken: newRefreshToken
5028
- });
5029
- }
5030
- if (req.url.endsWith("/me")) {
5031
- const error = decodeSessionToken({
5032
- req,
5033
- res,
5034
- sessionTokenName: this.cookies.sessionToken,
5035
- validate: true
5036
- });
5037
- if (error) return;
5038
- if (!req.user)
5039
- return res.status(400).json({ error: "Usu\xE1rio n\xE3o encontrado" });
5040
- const userData = await this.onGetUserData(req.user);
5041
- if (!userData)
5042
- return res.status(400).json({ error: "Usu\xE1rio n\xE3o encontrado" });
5043
- return res.json(userData);
5044
- }
5045
- if (req.url.endsWith("/oauth-url") && this.oauth) {
5046
- const params = {
5047
- client_id: this.oauth.client_id,
5048
- redirect_uri: this.oauth.redirect_uri,
5049
- scope: this.oauth.scope,
5050
- response_type: "code",
5051
- response_mode: "query"
5052
- };
5053
- const url = `https://login.microsoftonline.com/${this.oauth.tenant_id}/oauth2/v2.0/authorize?${new URLSearchParams(params)}`;
5054
- return res.json({
5055
- url
5056
- });
5057
- }
5058
- return res.status(404).json({ error: "Route not found" });
5059
- }
5060
- async oauthSignInCallback(code) {
5061
- if (!this.oauth) throw new Error("OAUTH variables is not defined");
5062
- const body = {
5063
- client_id: this.oauth.client_id,
5064
- scope: this.oauth.scope,
5065
- code,
5066
- session_state: this.oauth.client_id,
5067
- redirect_uri: this.oauth.redirect_uri,
5068
- grant_type: "authorization_code",
5069
- client_secret: this.oauth.client_secret
5070
- };
5071
- const response = await fetch(
5072
- `https://login.microsoftonline.com/${this.oauth.tenant_id}/oauth2/v2.0/token`,
5073
- {
5074
- method: "POST",
5075
- body: new URLSearchParams(body),
5076
- headers: { "Content-Type": "application/x-www-form-urlencoded" }
5077
- }
5078
- );
5079
- const data = await response.json();
5080
- const decodedToken = jwt.decode(data.access_token);
5081
- const email = decodedToken.upn;
5082
- const fullName = `${decodedToken?.given_name} ${decodedToken?.family_name}`;
5083
- return { decodedToken, email, fullName };
5084
- }
5085
- createOauthCallbackGetServerSideProps({
5086
- onSuccessDestination,
5087
- onFailedDestination
5088
- }) {
5089
- return async (ctx) => {
5090
- if (!this.oauth) throw new Error("Oauth env variables are not defined");
5091
- const code = ctx.query.code;
5092
- if (!code)
5093
- return {
5094
- redirect: {
5095
- permanent: false,
5096
- destination: onFailedDestination || "/"
5097
- }
5098
- };
5099
- try {
5100
- const { fullName, email } = await this.oauthSignInCallback(code);
5101
- const userExists = await this.onGetUserData(email);
5102
- if (!userExists && !this.oauth.onCreateUser)
5103
- throw new Error("User does not exists");
5104
- if (!userExists && this.oauth.onCreateUser) {
5105
- await this.oauth.onCreateUser({ fullname: fullName, email });
5106
- }
5107
- const { token, refreshToken } = await this.generateJwtAndRefreshToken(
5108
- email,
5109
- {}
5110
- );
5111
- setCookie(ctx, this.cookies.sessionToken, token, {
5112
- secure: true,
5113
- maxAge: 60 * 60 * 24 * 30,
5114
- // 30 days
5115
- path: "/"
5116
- });
5117
- setCookie(ctx, this.cookies.refreshToken, refreshToken, {
5118
- secure: true,
5119
- maxAge: 60 * 60 * 24 * 30,
5120
- // 30 days
5121
- path: "/",
5122
- httpOnly: true
5123
- });
5124
- return {
5125
- redirect: {
5126
- destination: onSuccessDestination,
5127
- permanent: false
5128
- }
5129
- };
5130
- } catch (error) {
5131
- return {
5132
- props: {
5133
- error: JSON.stringify(error)
5134
- }
5135
- };
5136
- }
5137
- };
5138
- }
5189
+ var isNumberOrString = (value) => ["number", "string"].includes(typeof value);
5190
+ var concatenateKey = (key, prev) => {
5191
+ if (!prev) return key;
5192
+ return `${prev}.${key}`;
5139
5193
  };
5140
-
5141
- // src/hooks/useGrid.ts
5142
- import { useCallback as useCallback6, useEffect as useEffect5, useMemo as useMemo3, useState as useState9 } from "react";
5143
-
5144
- // src/hooks/useFilter.ts
5145
- import moment2 from "moment";
5146
- import { useCallback as useCallback5, useState as useState8 } from "react";
5147
-
5148
- // src/components/utils/getObjectValue.ts
5149
- function getObjectValue(obj) {
5150
- return (prop) => {
5151
- try {
5152
- return prop.split(".").reduce((o, k) => o[k], obj);
5153
- } catch (_) {
5154
- return void 0;
5194
+ function searchKeysForValue(row, accKey, compare) {
5195
+ if (typeof row === "undefined") return false;
5196
+ const rowKeys = Object.keys(row);
5197
+ let match = false;
5198
+ for (const key of rowKeys) {
5199
+ if (match) break;
5200
+ const objValue = row[key];
5201
+ if (!objValue) continue;
5202
+ const concatenatedKey = concatenateKey(key, accKey);
5203
+ if (Array.isArray(objValue)) {
5204
+ match = objValue.some(
5205
+ (obj) => isNumberOrString(obj) ? compare(concatenatedKey, obj) : searchKeysForValue(obj, concatenatedKey, compare)
5206
+ );
5207
+ continue;
5155
5208
  }
5156
- };
5157
- }
5158
-
5159
- // src/hooks/useFilter.ts
5160
- function useFilter(props = { defaultFilters: [] }) {
5161
- const [selectedFilters, setSelectedFilters] = useState8(() => {
5162
- const { defaultFilters } = props;
5163
- return defaultFilters || [];
5164
- });
5165
- const filterBy = useCallback5((newFilter) => {
5166
- const propToCompare = newFilter?.id ? "id" : "prop";
5167
- function removeRepeatedFilters(filter) {
5168
- return filter[propToCompare] !== newFilter[propToCompare];
5209
+ if (typeof objValue === "object") {
5210
+ match = searchKeysForValue(objValue, concatenatedKey, compare);
5211
+ continue;
5169
5212
  }
5170
- setSelectedFilters((filters) => [
5171
- ...filters.filter(removeRepeatedFilters),
5172
- newFilter
5173
- ]);
5174
- }, []);
5175
- const removeFilter = useCallback5(
5176
- (prop, isId) => {
5177
- const propToCompare = isId ? "id" : "prop";
5178
- setSelectedFilters(
5179
- selectedFilters.filter((filter) => filter[propToCompare] !== prop)
5180
- );
5181
- },
5182
- [selectedFilters]
5183
- );
5184
- function clearAllFilters() {
5185
- setSelectedFilters([]);
5186
- }
5187
- return {
5188
- filters: selectedFilters,
5189
- filterBy,
5190
- removeFilter,
5191
- createFilter,
5192
- clearAllFilters
5193
- };
5194
- }
5195
- function isDate(date) {
5196
- if (date instanceof Date) return true;
5197
- else if (String(date).endsWith("Z")) return true;
5198
- return false;
5199
- }
5200
- function compareFilter(item, filter) {
5201
- const itemValue = getObjectValue(item)(filter.prop);
5202
- switch (filter.compareType) {
5203
- case "equal":
5204
- return itemValue === filter.value;
5205
- case "notEqual":
5206
- return itemValue !== filter.value;
5207
- case "in":
5208
- return filter.value.includes(itemValue);
5209
- case "notIn":
5210
- return !filter.value.includes(itemValue);
5211
- case "valueIn":
5212
- return itemValue.includes(filter.value);
5213
- case "valueNotIn":
5214
- return !itemValue.includes(filter.value);
5215
- case "gte":
5216
- return isDate(itemValue) ? moment2(String(itemValue)).isSameOrAfter(filter.value) : itemValue >= filter.value;
5217
- case "gt":
5218
- return isDate(itemValue) ? moment2(String(itemValue)).isAfter(filter.value) : itemValue > filter.value;
5219
- case "lte":
5220
- return isDate(itemValue) ? moment2(String(itemValue)).isSameOrBefore(filter.value) : itemValue <= filter.value;
5221
- case "lt":
5222
- return isDate(itemValue) ? moment2(String(itemValue)).isBefore(filter.value) : itemValue < filter.value;
5213
+ match = compare(concatenatedKey, row[key]);
5223
5214
  }
5215
+ return match;
5224
5216
  }
5225
- function createFilter(filters) {
5226
- function apply(item) {
5227
- const satisfiedFilters = filters.reduce((acc, filter) => {
5228
- if (compareFilter(item, filter)) acc += 1;
5229
- return acc;
5230
- }, 0);
5231
- return satisfiedFilters === filters.length;
5217
+ var normalize = (str) => str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
5218
+ function createSearch(options) {
5219
+ const searchValue = options.caseSensitive ? options.value : String(options.value).toLowerCase();
5220
+ function getValue2(value) {
5221
+ if (options.caseSensitive) return String(value);
5222
+ return String(value).toLowerCase();
5232
5223
  }
5233
- return {
5234
- apply
5235
- };
5236
- }
5237
-
5238
- // src/helpers/sortHelper.ts
5239
- function SortHelper(...fields) {
5240
- return (a, b) => {
5241
- for (const field of fields) {
5242
- let direction = 1;
5243
- let key = field;
5244
- if (field.startsWith("-")) {
5245
- direction = -1;
5246
- key = field.slice(1);
5247
- }
5248
- const aVal = a[key];
5249
- const bVal = b[key];
5250
- if (aVal > bVal) return direction;
5251
- if (aVal < bVal) return -direction;
5224
+ function compare(key, objValue) {
5225
+ if (options.ignoredKeys) {
5226
+ const isIgnoredKey = options.ignoredKeys.includes(key);
5227
+ if (isIgnoredKey) return false;
5252
5228
  }
5253
- return 0;
5229
+ const value = getValue2(objValue);
5230
+ if (options.exact) return value === searchValue;
5231
+ if (options.ignoreAccentMark) return normalize(value).includes(normalize(searchValue));
5232
+ return value.includes(searchValue);
5233
+ }
5234
+ return (row) => {
5235
+ const match = searchKeysForValue(row, "", compare);
5236
+ return match;
5254
5237
  };
5255
5238
  }
5256
5239
 
5257
- // src/hooks/useGrid.ts
5258
- function useGrid({
5240
+ // src/hooks/useAsyncGrid.ts
5241
+ import { useCallback as useCallback5, useEffect as useEffect5, useState as useState9 } from "react";
5242
+ function useAsyncGrid({
5259
5243
  columns,
5260
- filters,
5244
+ filters = [],
5261
5245
  search,
5262
5246
  rowsPerPageOptions = [30, 60, 100],
5247
+ onRequest,
5248
+ httpClient,
5249
+ url,
5263
5250
  defaultData: externalDefaultData,
5264
5251
  defaultCurrentPage,
5265
5252
  defaultSortedBy
5266
5253
  }) {
5267
5254
  const [defaultData, setDefaultData] = useState9(externalDefaultData || []);
5268
- const [sortedBy, setSortedBy] = useState9(
5269
- defaultSortedBy || []
5270
- );
5255
+ const [sortedBy, setSortedBy] = useState9(defaultSortedBy || []);
5256
+ const [totalNumberOfItems, setTotalNumberOfItems] = useState9(0);
5257
+ const [isLoading, setIsLoading] = useState9(false);
5271
5258
  const [currentPage, setCurrentPage] = useState9(defaultCurrentPage || 0);
5272
5259
  const [rowsPerPage, setRowsPerPage] = useState9(rowsPerPageOptions[0]);
5273
- const toggleSortedDirection = useCallback6(
5274
- (direction) => {
5275
- if (direction === "asc") return "desc";
5276
- return "asc";
5277
- },
5278
- []
5279
- );
5280
- const clearSort = useCallback6(() => {
5281
- setSortedBy([]);
5260
+ const totalNumberOfPages = Math.ceil(totalNumberOfItems / rowsPerPage) - 1;
5261
+ const toggleSortedDirection = useCallback5((direction) => {
5262
+ if (direction === "asc") return "desc";
5263
+ return "asc";
5282
5264
  }, []);
5283
- const appendSort = useCallback6((prop, direction) => {
5265
+ const setSort = useCallback5((prop, direction) => {
5284
5266
  setSortedBy((prev) => [...prev, { prop, direction }]);
5285
5267
  }, []);
5286
- const setSort = useCallback6((prop, direction) => {
5287
- setSortedBy([{ prop, direction }]);
5288
- }, []);
5289
- const onSortBy = useCallback6(
5290
- (prop) => {
5268
+ const onSortBy = useCallback5(
5269
+ async (prop) => {
5291
5270
  if (!prop) return;
5271
+ let finalArr = [];
5292
5272
  const currentSorted = sortedBy.find((p) => p.prop === prop);
5293
5273
  if (currentSorted) {
5294
5274
  if (currentSorted.direction === "asc") {
5295
- setSortedBy((prev) => prev.filter((p) => p.prop !== prop));
5275
+ finalArr = sortedBy.filter((p) => p.prop !== prop);
5296
5276
  } else {
5297
- setSortedBy((prev) => {
5298
- const newArr = prev.map((p) => {
5299
- if (p.prop !== prop) return p;
5300
- return {
5301
- prop: p.prop,
5302
- direction: toggleSortedDirection(p.direction)
5303
- };
5304
- });
5305
- return [...newArr].slice(0);
5277
+ finalArr = sortedBy.map((p) => {
5278
+ if (p.prop !== prop) return p;
5279
+ return {
5280
+ prop: p.prop,
5281
+ direction: toggleSortedDirection(p.direction)
5282
+ };
5306
5283
  });
5307
5284
  }
5308
5285
  } else {
5309
- setSortedBy((prev) => [...prev, { prop, direction: "desc" }]);
5286
+ finalArr = [...sortedBy, { prop, direction: "desc" }];
5310
5287
  }
5288
+ await updateGridContent({
5289
+ page: currentPage,
5290
+ sortedBy: finalArr,
5291
+ rowsPerPage
5292
+ });
5311
5293
  },
5312
- [toggleSortedDirection, sortedBy]
5294
+ [sortedBy, toggleSortedDirection, rowsPerPage, currentPage]
5313
5295
  );
5314
- const set = useCallback6((data) => {
5296
+ const set = useCallback5((data) => {
5315
5297
  setDefaultData(data);
5316
5298
  }, []);
5317
- const sortData = useCallback6(
5318
- (data) => {
5319
- if (sortedBy.length > 0) {
5320
- const symbolDir = {
5321
- asc: "",
5322
- desc: "-"
5323
- };
5324
- const formattedKeys = sortedBy.map(
5325
- ({ prop, direction }) => `${symbolDir[direction]}${prop}`
5299
+ const baseRequest = useCallback5(
5300
+ async ({ page, search: search2, filters: filters2, sortedBy: sortedBy2, rowsPerPage: rowsPerPage2 }) => {
5301
+ if (!httpClient) throw new Error("HttpClient instance not provided");
5302
+ try {
5303
+ const params = new URLSearchParams({
5304
+ page: String(page),
5305
+ rowsPerPage: String(rowsPerPage2),
5306
+ searchText: search2?.value || "",
5307
+ sort: sortedBy2.map(({ prop, direction }) => `${prop}:${direction}`).join(","),
5308
+ filters: filters2.map((filter) => `${filter.prop}:${filter.compareType}:${filter.value}`).join(",")
5309
+ });
5310
+ const pathWithParams = `${url}?${params.toString()}`;
5311
+ const { data } = await httpClient.get(
5312
+ pathWithParams
5326
5313
  );
5327
- return data.sort(SortHelper(...formattedKeys));
5328
- } else return data;
5314
+ setTotalNumberOfItems(data.totalNumberOfItems);
5315
+ return data.rows;
5316
+ } catch (_) {
5317
+ return [];
5318
+ }
5329
5319
  },
5330
- [sortedBy]
5320
+ [httpClient, url]
5331
5321
  );
5332
- const onPageChange = (pageNumber) => {
5333
- if (pageNumber < 0) return;
5334
- if (pageNumber > totalNumberOfPages) return;
5335
- setCurrentPage(pageNumber);
5336
- };
5337
- const onChangeRowsPerPage = useCallback6(
5338
- (rows) => {
5339
- let totalNumberOfPages2 = Math.round(filteredData.length / rows) - 1;
5340
- totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
5341
- if (currentPage > totalNumberOfPages2) setCurrentPage(totalNumberOfPages2);
5342
- setRowsPerPage(rows);
5322
+ const updateGridContent = useCallback5(
5323
+ async ({
5324
+ page,
5325
+ sortedBy: sortedBy2,
5326
+ rowsPerPage: rowsPerPage2
5327
+ }) => {
5328
+ setIsLoading(true);
5329
+ try {
5330
+ const props = {
5331
+ page,
5332
+ rowsPerPage: rowsPerPage2,
5333
+ sortedBy: sortedBy2,
5334
+ search,
5335
+ filters
5336
+ };
5337
+ const result = !onRequest ? await baseRequest(props) : await onRequest(props);
5338
+ setSortedBy(sortedBy2);
5339
+ setRowsPerPage(rowsPerPage2);
5340
+ set(result);
5341
+ setCurrentPage(page);
5342
+ } finally {
5343
+ setIsLoading(false);
5344
+ }
5343
5345
  },
5344
- [currentPage]
5346
+ [set, search, filters, onRequest, baseRequest]
5345
5347
  );
5346
- const orderedData = useMemo3(() => {
5347
- if (sortedBy.length === 0) return defaultData;
5348
- const newData = defaultData.slice(0);
5349
- const sortedData = sortData(newData);
5350
- return sortedData;
5351
- }, [defaultData, sortData, sortedBy]);
5352
- const filteredData = useMemo3(() => {
5353
- let newData = orderedData.slice(0);
5354
- if (search && search.value !== "") {
5355
- const searchBy = createSearch(search);
5356
- newData = newData.filter(searchBy);
5357
- }
5358
- if (!filters) return newData;
5359
- const newFilter = createFilter(filters);
5360
- return newData.filter(newFilter.apply);
5361
- }, [orderedData, search, filters]);
5362
- const paginatedData = useMemo3(() => {
5363
- const startPage = currentPage * rowsPerPage;
5364
- const endPage = startPage + rowsPerPage;
5365
- return filteredData.slice(startPage, endPage);
5366
- }, [currentPage, rowsPerPage, filteredData]);
5367
- const totalNumberOfPages = Math.ceil(filteredData.length / rowsPerPage) - 1;
5348
+ const onPageChange = useCallback5(
5349
+ (pageNumber) => {
5350
+ if (pageNumber < 0) return;
5351
+ if (pageNumber > totalNumberOfPages) return;
5352
+ updateGridContent({ page: pageNumber, sortedBy, rowsPerPage });
5353
+ },
5354
+ [updateGridContent, totalNumberOfPages, sortedBy, rowsPerPage]
5355
+ );
5356
+ const onChangeRowsPerPage = useCallback5(
5357
+ (rows) => {
5358
+ let totalNumberOfPages2 = Math.round(totalNumberOfItems / rows) - 1;
5359
+ totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
5360
+ if (currentPage > totalNumberOfPages2)
5361
+ updateGridContent({
5362
+ page: totalNumberOfPages2,
5363
+ sortedBy,
5364
+ rowsPerPage: rows
5365
+ });
5366
+ updateGridContent({
5367
+ page: currentPage,
5368
+ sortedBy,
5369
+ rowsPerPage: rows
5370
+ });
5371
+ },
5372
+ [updateGridContent, totalNumberOfItems, sortedBy, currentPage]
5373
+ );
5374
+ const displayData = defaultData;
5368
5375
  useEffect5(() => {
5369
- if (externalDefaultData) setDefaultData(externalDefaultData);
5370
- }, [externalDefaultData]);
5376
+ updateGridContent({ page: 0, sortedBy: [], rowsPerPage });
5377
+ }, [updateGridContent, rowsPerPage]);
5371
5378
  return {
5372
- data: paginatedData,
5373
- orderedData,
5374
- filteredData,
5375
- defaultData,
5379
+ data: displayData,
5380
+ set,
5381
+ onSortBy,
5376
5382
  sortedBy,
5383
+ defaultData,
5377
5384
  columns,
5378
5385
  currentPage,
5379
5386
  totalNumberOfPages: totalNumberOfPages < 0 ? 0 : totalNumberOfPages,
5380
- rowsPerPageOptions,
5381
- rowsPerPage,
5382
- set,
5383
- onSortBy,
5384
5387
  onPageChange,
5385
5388
  setRowsPerPage: onChangeRowsPerPage,
5386
- appendSort,
5389
+ rowsPerPageOptions,
5390
+ rowsPerPage,
5387
5391
  setSort,
5388
- clearSort
5392
+ isLoading,
5393
+ setIsLoading
5389
5394
  };
5390
5395
  }
5391
- var isNumberOrString = (value) => ["number", "string"].includes(typeof value);
5392
- var concatenateKey = (key, prev) => {
5393
- if (!prev) return key;
5394
- return `${prev}.${key}`;
5396
+
5397
+ // src/hooks/useEvent.ts
5398
+ import { useEffect as useEffect6 } from "react";
5399
+ function useEvent(event, handler, passive = false) {
5400
+ useEffect6(() => {
5401
+ window.addEventListener(event, handler, passive);
5402
+ return function cleanup() {
5403
+ window.removeEventListener(event, handler);
5404
+ };
5405
+ });
5406
+ }
5407
+
5408
+ // src/hooks/useLoading.ts
5409
+ import { useCallback as useCallback6, useState as useState10 } from "react";
5410
+ function useLoading() {
5411
+ const [state, setState] = useState10([]);
5412
+ const isLoading = useCallback6((prop) => state.includes(prop), [state]);
5413
+ const setLoading = useCallback6((prop, remove) => {
5414
+ if (remove)
5415
+ setState((prevState) => prevState.filter((state2) => state2 !== prop));
5416
+ else setState((prevState) => [...prevState, prop]);
5417
+ }, []);
5418
+ return { isLoading, setLoading };
5419
+ }
5420
+
5421
+ // src/hooks/useAlert.ts
5422
+ import { useContext as useContext3 } from "react";
5423
+ var useAlert = () => {
5424
+ return useContext3(AlertContext);
5395
5425
  };
5396
- function searchKeysForValue(row, accKey, compare) {
5397
- if (typeof row === "undefined") return false;
5398
- const rowKeys = Object.keys(row);
5399
- let match = false;
5400
- for (const key of rowKeys) {
5401
- if (match) break;
5402
- const objValue = row[key];
5403
- if (!objValue) continue;
5404
- const concatenatedKey = concatenateKey(key, accKey);
5405
- if (Array.isArray(objValue)) {
5406
- match = objValue.some(
5407
- (obj) => isNumberOrString(obj) ? compare(concatenatedKey, obj) : searchKeysForValue(obj, concatenatedKey, compare)
5408
- );
5409
- continue;
5426
+
5427
+ // src/hooks/useFormHelper.ts
5428
+ import { useCallback as useCallback7, useContext as useContext4, useEffect as useEffect7 } from "react";
5429
+ function useFormHelper() {
5430
+ const alertProps = useAlert();
5431
+ const loadingProps = useLoading();
5432
+ const { api, formatErrorMessage } = useContext4(FormHelperContext);
5433
+ const { createAlert } = alertProps;
5434
+ const { setLoading } = loadingProps;
5435
+ const onSubmitWrapper = useCallback7(
5436
+ (fn, { name }) => {
5437
+ return async (fields, methods) => {
5438
+ const LOADING_NAME = name;
5439
+ setLoading(LOADING_NAME);
5440
+ try {
5441
+ await fn(fields, methods);
5442
+ } catch (error) {
5443
+ errorHandler(error, methods.setErrors);
5444
+ } finally {
5445
+ setLoading(LOADING_NAME, true);
5446
+ }
5447
+ };
5448
+ },
5449
+ [setLoading]
5450
+ );
5451
+ const onRequestWrapper = useCallback7(
5452
+ (fn, { name }) => {
5453
+ return async (...params) => {
5454
+ const LOADING_NAME = name;
5455
+ setLoading(LOADING_NAME);
5456
+ try {
5457
+ const response = await fn(...params);
5458
+ return response;
5459
+ } catch (error) {
5460
+ errorHandler(error);
5461
+ } finally {
5462
+ setLoading(LOADING_NAME, true);
5463
+ }
5464
+ };
5465
+ },
5466
+ [setLoading]
5467
+ );
5468
+ const errorHandler = useCallback7(
5469
+ (error, callback) => {
5470
+ if (error?.message === "cancel.navigation") return;
5471
+ if (callback) {
5472
+ if (error.response.data.code === "invalid.body") {
5473
+ const errors = error.response.data.details.issues;
5474
+ const currentErrors = errors.reduce((acc, item) => {
5475
+ acc[item.path.join(".")] = item.message;
5476
+ return acc;
5477
+ }, {});
5478
+ callback(currentErrors);
5479
+ }
5480
+ }
5481
+ createAlert(formatErrorMessage(error), "error");
5482
+ },
5483
+ [formatErrorMessage, createAlert]
5484
+ );
5485
+ useEffect7(() => {
5486
+ return () => {
5487
+ api.abort();
5488
+ };
5489
+ }, [api]);
5490
+ return {
5491
+ ...alertProps,
5492
+ ...loadingProps,
5493
+ onSubmitWrapper,
5494
+ onRequestWrapper
5495
+ };
5496
+ }
5497
+
5498
+ // src/contexts/AuthContext.tsx
5499
+ import { jsx as jsx30 } from "react/jsx-runtime";
5500
+ function createAuthContext() {
5501
+ return createContext5({});
5502
+ }
5503
+ function CreateAuthProvider({
5504
+ api,
5505
+ children,
5506
+ sessionTokenName,
5507
+ Provider
5508
+ }) {
5509
+ const [user, setUser] = useState11();
5510
+ const [status, setStatus] = useState11("unauthenticated");
5511
+ const { createAlert } = useAlert();
5512
+ const signIn = useCallback8(
5513
+ async ({ email, password }) => {
5514
+ setStatus("loading");
5515
+ try {
5516
+ const response = await api.post("/auth/login", {
5517
+ email,
5518
+ password
5519
+ });
5520
+ const { token } = response.data;
5521
+ api.setHeader("Authorization", `Bearer ${token}`);
5522
+ const { data } = await api.get("/auth/me");
5523
+ setUser(data);
5524
+ setStatus("autenticated");
5525
+ return true;
5526
+ } catch (error) {
5527
+ createAlert(error?.response?.data?.error, "error");
5528
+ setStatus("unauthenticated");
5529
+ throw error;
5530
+ }
5531
+ },
5532
+ [createAlert, api]
5533
+ );
5534
+ const ClientSignOut = useCallback8(async () => {
5535
+ await api.get("/auth/logout");
5536
+ setUser(void 0);
5537
+ }, [api]);
5538
+ useEffect8(() => {
5539
+ const token = parseCookies()[sessionTokenName];
5540
+ if (token) {
5541
+ setStatus("loading");
5542
+ api.get("/auth/me").then((response) => {
5543
+ setStatus("autenticated");
5544
+ setUser(response.data);
5545
+ }).catch(() => {
5546
+ setStatus("unauthenticated");
5547
+ });
5410
5548
  }
5411
- if (typeof objValue === "object") {
5412
- match = searchKeysForValue(objValue, concatenatedKey, compare);
5413
- continue;
5549
+ }, [api, sessionTokenName]);
5550
+ return /* @__PURE__ */ jsx30(
5551
+ Provider,
5552
+ {
5553
+ value: {
5554
+ user,
5555
+ signOut: ClientSignOut,
5556
+ signIn,
5557
+ status
5558
+ },
5559
+ children
5414
5560
  }
5415
- match = compare(concatenatedKey, row[key]);
5561
+ );
5562
+ }
5563
+
5564
+ // src/errors/HttpError.ts
5565
+ var HttpError = class extends Error {
5566
+ constructor(status, message) {
5567
+ super(message);
5568
+ this.message = message;
5569
+ this.stack = `HttpError: ${message}`;
5570
+ this.status = status;
5571
+ }
5572
+ };
5573
+
5574
+ // src/errors/DomainError.ts
5575
+ var DomainError = class extends Error {
5576
+ constructor(message) {
5577
+ super(message);
5578
+ this.message = message;
5579
+ this.stack = `DomainError: ${message}`;
5580
+ }
5581
+ };
5582
+
5583
+ // src/helpers/apiHelper/index.ts
5584
+ var VALID_METHODS = [
5585
+ "GET",
5586
+ "HEAD",
5587
+ "POST",
5588
+ "PUT",
5589
+ "DELETE",
5590
+ "CONNECT",
5591
+ "OPTIONS",
5592
+ "TRACE",
5593
+ "PATCH"
5594
+ ];
5595
+ var _ApiHelper = class _ApiHelper {
5596
+ async onFinally(_req, _res) {
5597
+ }
5598
+ async onError(_req, _res, _error) {
5599
+ }
5600
+ constructor(props) {
5601
+ this.public = props?.public ?? false;
5602
+ this.middlewares = (props?.middlewares || []).reverse();
5603
+ this.onFinally = props?.onFinally || (async () => {
5604
+ });
5605
+ this.onError = props?.onError || (async () => {
5606
+ });
5607
+ }
5608
+ createMethods(methods) {
5609
+ return async (req, res) => {
5610
+ const currentMethod = methods[req.method] || methods.ALL;
5611
+ const options = { public: this.public };
5612
+ if (req.method === "OPTIONS") return res.status(200).end();
5613
+ try {
5614
+ if (!VALID_METHODS.includes(req.method))
5615
+ throw new HttpError(405, "M\xE9todo inv\xE1lido");
5616
+ if (!currentMethod) throw new HttpError(500, "M\xE9todo n\xE3o encontrado");
5617
+ const methodWithMiddlewares = this.middlewares.reduce(
5618
+ (acc, fn) => fn(acc, options),
5619
+ currentMethod
5620
+ );
5621
+ return await methodWithMiddlewares(req, res, options);
5622
+ } catch (error) {
5623
+ if (error instanceof DomainError) return res.status(400).json(error.message);
5624
+ if (error instanceof HttpError) return res.status(error.status).json(error.message);
5625
+ this.onError(req, res, error);
5626
+ throw error;
5627
+ } finally {
5628
+ await this.onFinally(req, res);
5629
+ }
5630
+ };
5416
5631
  }
5417
- return match;
5418
- }
5419
- var normalize = (str) => str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
5420
- function createSearch(options) {
5421
- const searchValue = options.caseSensitive ? options.value : String(options.value).toLowerCase();
5422
- function getValue2(value) {
5423
- if (options.caseSensitive) return String(value);
5424
- return String(value).toLowerCase();
5632
+ buildFactory(factory) {
5633
+ const options = { public: this.public };
5634
+ return async (req, res) => {
5635
+ const methods = factory(req, res);
5636
+ const handler = methods[req.method];
5637
+ const methodWithMiddlewares = this.middlewares.reduce((acc, fn) => fn(acc, options), handler);
5638
+ return await methodWithMiddlewares(req, res, options);
5639
+ };
5425
5640
  }
5426
- function compare(key, objValue) {
5427
- if (options.ignoredKeys) {
5428
- const isIgnoredKey = options.ignoredKeys.includes(key);
5429
- if (isIgnoredKey) return false;
5641
+ static build(factory, options) {
5642
+ return new _ApiHelper({ ...options }).buildFactory(factory);
5643
+ }
5644
+ static parse(body, parser) {
5645
+ try {
5646
+ const object = parser.parse(body);
5647
+ return object;
5648
+ } catch (error) {
5649
+ throw new HttpError(400, {
5650
+ code: "invalid.body",
5651
+ error: "Dados inv\xE1lidos",
5652
+ details: error
5653
+ });
5430
5654
  }
5431
- const value = getValue2(objValue);
5432
- if (options.exact) return value === searchValue;
5433
- if (options.ignoreAccentMark) return normalize(value).includes(normalize(searchValue));
5434
- return value.includes(searchValue);
5435
5655
  }
5436
- return (row) => {
5437
- const match = searchKeysForValue(row, "", compare);
5438
- return match;
5439
- };
5440
- }
5656
+ /** @deprecated Use {@Link ApiHelper.build} instead. */
5657
+ static create({ onFinally }) {
5658
+ return new _ApiHelper({
5659
+ onFinally
5660
+ });
5661
+ }
5662
+ };
5663
+ /** @deprecated Use {@link ApiHelper.parser} instead. */
5664
+ _ApiHelper.parserErrorWrapper = _ApiHelper.parse;
5665
+ var ApiHelper = _ApiHelper;
5441
5666
 
5442
- // src/hooks/useAsyncGrid.ts
5443
- import { useCallback as useCallback7, useEffect as useEffect6, useState as useState10 } from "react";
5444
- function useAsyncGrid({
5445
- columns,
5446
- filters = [],
5447
- search,
5448
- rowsPerPageOptions = [30, 60, 100],
5449
- onRequest,
5450
- axiosInstance,
5451
- url,
5452
- defaultData: externalDefaultData,
5453
- defaultCurrentPage,
5454
- defaultSortedBy
5667
+ // src/helpers/authHelper.ts
5668
+ import { randomUUID } from "crypto";
5669
+ import { serialize as serialize2 } from "cookie";
5670
+ import jwt from "jsonwebtoken";
5671
+ function decodeSessionToken({
5672
+ req,
5673
+ res,
5674
+ sessionTokenName,
5675
+ validate
5455
5676
  }) {
5456
- const [defaultData, setDefaultData] = useState10(externalDefaultData || []);
5457
- const [sortedBy, setSortedBy] = useState10(
5458
- defaultSortedBy || []
5459
- );
5460
- const [totalNumberOfItems, setTotalNumberOfItems] = useState10(0);
5461
- const [isLoading, setIsLoading] = useState10(false);
5462
- const [currentPage, setCurrentPage] = useState10(defaultCurrentPage || 0);
5463
- const [rowsPerPage, setRowsPerPage] = useState10(rowsPerPageOptions[0]);
5464
- const totalNumberOfPages = Math.ceil(totalNumberOfItems / rowsPerPage) - 1;
5465
- const toggleSortedDirection = useCallback7(
5466
- (direction) => {
5467
- if (direction === "asc") return "desc";
5468
- return "asc";
5469
- },
5470
- []
5471
- );
5472
- const setSort = useCallback7((prop, direction) => {
5473
- setSortedBy((prev) => [...prev, { prop, direction }]);
5474
- }, []);
5475
- const onSortBy = useCallback7(
5476
- async (prop) => {
5477
- if (!prop) return;
5478
- let finalArr = [];
5479
- const currentSorted = sortedBy.find((p) => p.prop === prop);
5480
- if (currentSorted) {
5481
- if (currentSorted.direction === "asc") {
5482
- finalArr = sortedBy.filter((p) => p.prop !== prop);
5483
- } else {
5484
- finalArr = sortedBy.map((p) => {
5485
- if (p.prop !== prop) return p;
5486
- return {
5487
- prop: p.prop,
5488
- direction: toggleSortedDirection(p.direction)
5489
- };
5490
- });
5491
- }
5492
- } else {
5493
- finalArr = [...sortedBy, { prop, direction: "desc" }];
5494
- }
5495
- await updateGridContent({
5496
- page: currentPage,
5497
- sortedBy: finalArr,
5498
- rowsPerPage
5677
+ const token = req.headers.authorization?.split(" ")[1] || req.cookies[sessionTokenName];
5678
+ if (!token) {
5679
+ res.status(401).json({ error: "Token inv\xE1lido", code: "token.invalid" });
5680
+ return true;
5681
+ }
5682
+ const jwtDecode = (token2) => {
5683
+ if (validate) {
5684
+ return jwt.verify(token2, process.env.JWT_SECRET);
5685
+ }
5686
+ return jwt.decode(token2);
5687
+ };
5688
+ try {
5689
+ const decoded = jwtDecode(token);
5690
+ req.user = decoded.sub;
5691
+ } catch (_) {
5692
+ res.status(401).json({ error: "Token inv\xE1lido", code: "token.expired" });
5693
+ return true;
5694
+ }
5695
+ }
5696
+ var AuthHelper = class {
5697
+ constructor({
5698
+ cookies,
5699
+ oauth,
5700
+ tokenExpTimeInSeconds,
5701
+ onLogin,
5702
+ onValidateRefreshToken,
5703
+ onInvalidateRefreshToken,
5704
+ onCreateRefreshToken,
5705
+ onGetUserData
5706
+ }) {
5707
+ this.generateJwtAndRefreshToken = async (userId, payload = {}) => {
5708
+ const token = jwt.sign(payload, process.env.JWT_SECRET, {
5709
+ subject: String(userId),
5710
+ expiresIn: this.tokenExpTimeInSeconds || 60 * 15
5711
+ // 15 minutos
5499
5712
  });
5500
- },
5501
- [sortedBy, toggleSortedDirection, rowsPerPage, currentPage]
5502
- );
5503
- const set = useCallback7((data) => {
5504
- setDefaultData(data);
5505
- }, []);
5506
- const baseRequest = useCallback7(
5507
- async ({
5508
- page,
5509
- search: search2,
5510
- filters: filters2,
5511
- sortedBy: sortedBy2,
5512
- rowsPerPage: rowsPerPage2
5513
- }) => {
5514
- if (!axiosInstance) throw new Error("Axios instance not provided");
5515
- try {
5516
- const params = new URLSearchParams({
5517
- page: String(page),
5518
- rowsPerPage: String(rowsPerPage2),
5519
- searchText: search2?.value || "",
5520
- sort: sortedBy2.map(({ prop, direction }) => `${prop}:${direction}`).join(","),
5521
- filters: filters2.map(
5522
- (filter) => `${filter.prop}:${filter.compareType}:${filter.value}`
5523
- ).join(",")
5713
+ const uniqueToken = randomUUID();
5714
+ await this.onCreateRefreshToken(userId, uniqueToken);
5715
+ return {
5716
+ token,
5717
+ refreshToken: uniqueToken
5718
+ };
5719
+ };
5720
+ this.invalidateCookies = (res) => {
5721
+ return res.setHeader("Set-Cookie", [
5722
+ serialize2(this.cookies.sessionToken, "", {
5723
+ maxAge: -1,
5724
+ path: "/"
5725
+ }),
5726
+ serialize2(this.cookies.refreshToken, "", {
5727
+ maxAge: -1,
5728
+ path: "/"
5729
+ })
5730
+ ]);
5731
+ };
5732
+ this.cookies = cookies;
5733
+ this.oauth = oauth;
5734
+ this.tokenExpTimeInSeconds = tokenExpTimeInSeconds;
5735
+ this.onLogin = onLogin;
5736
+ this.onValidateRefreshToken = onValidateRefreshToken;
5737
+ this.onInvalidateRefreshToken = onInvalidateRefreshToken;
5738
+ this.onCreateRefreshToken = onCreateRefreshToken;
5739
+ this.onGetUserData = onGetUserData;
5740
+ }
5741
+ async handler(req, res) {
5742
+ if (!req.url) return res.status(400).json({ error: "url not sent" });
5743
+ if (req.url.endsWith("/login")) {
5744
+ const loginResult = await this.onLogin(req.body);
5745
+ if (loginResult.status === "success") {
5746
+ const { refreshToken, token } = await this.generateJwtAndRefreshToken(
5747
+ loginResult.userId,
5748
+ {}
5749
+ );
5750
+ setCookie({ res }, this.cookies.sessionToken, token, {
5751
+ secure: true,
5752
+ maxAge: 60 * 60 * 24 * 30,
5753
+ // 30 days
5754
+ path: "/",
5755
+ sameSite: true
5524
5756
  });
5525
- const pathWithParams = `${url}?${params.toString()}`;
5526
- const { data } = await axiosInstance.get(pathWithParams);
5527
- setTotalNumberOfItems(data.totalNumberOfItems);
5528
- return data.rows;
5529
- } catch (_) {
5530
- return [];
5757
+ setCookie({ res }, this.cookies.refreshToken, refreshToken, {
5758
+ secure: true,
5759
+ maxAge: 60 * 60 * 24 * 30,
5760
+ // 30 days
5761
+ path: "/",
5762
+ sameSite: true,
5763
+ httpOnly: true
5764
+ });
5765
+ return res.json({ token, refreshToken });
5531
5766
  }
5532
- },
5533
- [axiosInstance, url]
5534
- );
5535
- const updateGridContent = useCallback7(
5536
- async ({
5537
- page,
5538
- sortedBy: sortedBy2,
5539
- rowsPerPage: rowsPerPage2
5540
- }) => {
5541
- setIsLoading(true);
5542
- try {
5543
- const props = {
5544
- page,
5545
- rowsPerPage: rowsPerPage2,
5546
- sortedBy: sortedBy2,
5547
- search,
5548
- filters
5549
- };
5550
- const result = !onRequest ? await baseRequest(props) : await onRequest(props);
5551
- setSortedBy(sortedBy2);
5552
- setRowsPerPage(rowsPerPage2);
5553
- set(result);
5554
- setCurrentPage(page);
5555
- } finally {
5556
- setIsLoading(false);
5767
+ throw new HttpError(400, loginResult.response);
5768
+ }
5769
+ if (req.url.endsWith("/logout")) {
5770
+ this.invalidateCookies(res).end();
5771
+ }
5772
+ if (req.url.endsWith("/refresh")) {
5773
+ const error = decodeSessionToken({
5774
+ req,
5775
+ res,
5776
+ sessionTokenName: this.cookies.sessionToken,
5777
+ validate: false
5778
+ });
5779
+ if (error) return;
5780
+ const userId = String(req.user);
5781
+ const refreshToken = parseCookies({ req })[this.cookies.refreshToken];
5782
+ if (!refreshToken) {
5783
+ this.invalidateCookies(res);
5784
+ return res.status(400).json({
5785
+ error: "Refresh Token inv\xE1lido"
5786
+ });
5557
5787
  }
5558
- },
5559
- [set, search, filters, onRequest, baseRequest]
5560
- );
5561
- const onPageChange = useCallback7(
5562
- (pageNumber) => {
5563
- if (pageNumber < 0) return;
5564
- if (pageNumber > totalNumberOfPages) return;
5565
- updateGridContent({ page: pageNumber, sortedBy, rowsPerPage });
5566
- },
5567
- [updateGridContent, totalNumberOfPages, sortedBy, rowsPerPage]
5568
- );
5569
- const onChangeRowsPerPage = useCallback7(
5570
- (rows) => {
5571
- let totalNumberOfPages2 = Math.round(totalNumberOfItems / rows) - 1;
5572
- totalNumberOfPages2 = totalNumberOfPages2 <= 0 ? 0 : 1;
5573
- if (currentPage > totalNumberOfPages2)
5574
- updateGridContent({
5575
- page: totalNumberOfPages2,
5576
- sortedBy,
5577
- rowsPerPage: rows
5788
+ const isValidRefreshToken = await this.onValidateRefreshToken(userId, refreshToken);
5789
+ if (!isValidRefreshToken) {
5790
+ this.invalidateCookies(res);
5791
+ return res.status(400).json({
5792
+ error: "Refresh Token inv\xE1lido"
5578
5793
  });
5579
- updateGridContent({
5580
- page: currentPage,
5581
- sortedBy,
5582
- rowsPerPage: rows
5794
+ }
5795
+ await this.onInvalidateRefreshToken(userId, refreshToken);
5796
+ const { token, refreshToken: newRefreshToken } = await this.generateJwtAndRefreshToken(
5797
+ userId,
5798
+ {}
5799
+ );
5800
+ setCookie({ res }, this.cookies.sessionToken, token, {
5801
+ secure: true,
5802
+ maxAge: 60 * 60 * 24 * 30,
5803
+ // 30 days
5804
+ path: "/",
5805
+ sameSite: true
5583
5806
  });
5584
- },
5585
- [updateGridContent, totalNumberOfItems, sortedBy, currentPage]
5586
- );
5587
- const displayData = defaultData;
5588
- useEffect6(() => {
5589
- updateGridContent({ page: 0, sortedBy: [], rowsPerPage });
5590
- }, [updateGridContent, rowsPerPage]);
5591
- return {
5592
- data: displayData,
5593
- set,
5594
- onSortBy,
5595
- sortedBy,
5596
- defaultData,
5597
- columns,
5598
- currentPage,
5599
- totalNumberOfPages: totalNumberOfPages < 0 ? 0 : totalNumberOfPages,
5600
- onPageChange,
5601
- setRowsPerPage: onChangeRowsPerPage,
5602
- rowsPerPageOptions,
5603
- rowsPerPage,
5604
- setSort,
5605
- isLoading,
5606
- setIsLoading
5607
- };
5608
- }
5609
-
5610
- // src/hooks/useEvent.ts
5611
- import { useEffect as useEffect7 } from "react";
5612
- function useEvent(event, handler, passive = false) {
5613
- useEffect7(() => {
5614
- window.addEventListener(event, handler, passive);
5615
- return function cleanup() {
5616
- window.removeEventListener(event, handler);
5807
+ setCookie({ res }, this.cookies.refreshToken, newRefreshToken, {
5808
+ secure: true,
5809
+ maxAge: 60 * 60 * 24 * 30,
5810
+ // 30 days
5811
+ path: "/",
5812
+ sameSite: true,
5813
+ httpOnly: true
5814
+ });
5815
+ return res.json({
5816
+ token,
5817
+ refreshToken: newRefreshToken
5818
+ });
5819
+ }
5820
+ if (req.url.endsWith("/me")) {
5821
+ const error = decodeSessionToken({
5822
+ req,
5823
+ res,
5824
+ sessionTokenName: this.cookies.sessionToken,
5825
+ validate: true
5826
+ });
5827
+ if (error) return;
5828
+ if (!req.user) return res.status(400).json({ error: "Usu\xE1rio n\xE3o encontrado" });
5829
+ const userData = await this.onGetUserData(req.user);
5830
+ if (!userData) return res.status(400).json({ error: "Usu\xE1rio n\xE3o encontrado" });
5831
+ return res.json(userData);
5832
+ }
5833
+ if (req.url.endsWith("/oauth-url") && this.oauth) {
5834
+ const params = {
5835
+ client_id: this.oauth.client_id,
5836
+ redirect_uri: this.oauth.redirect_uri,
5837
+ scope: this.oauth.scope,
5838
+ response_type: "code",
5839
+ response_mode: "query"
5840
+ };
5841
+ const url = `https://login.microsoftonline.com/${this.oauth.tenant_id}/oauth2/v2.0/authorize?${new URLSearchParams(params)}`;
5842
+ return res.json({
5843
+ url
5844
+ });
5845
+ }
5846
+ return res.status(404).json({ error: "Route not found" });
5847
+ }
5848
+ async oauthSignInCallback(code) {
5849
+ if (!this.oauth) throw new Error("OAUTH variables is not defined");
5850
+ const body = {
5851
+ client_id: this.oauth.client_id,
5852
+ scope: this.oauth.scope,
5853
+ code,
5854
+ session_state: this.oauth.client_id,
5855
+ redirect_uri: this.oauth.redirect_uri,
5856
+ grant_type: "authorization_code",
5857
+ client_secret: this.oauth.client_secret
5617
5858
  };
5618
- });
5619
- }
5620
-
5621
- // src/contexts/AuthContext.tsx
5622
- import React33, { useCallback as useCallback8 } from "react";
5623
- import {
5624
- createContext as createContext5,
5625
- useEffect as useEffect8,
5626
- useState as useState11
5627
- } from "react";
5628
- function createAuthContext() {
5629
- return createContext5({});
5630
- }
5631
- function CreateAuthProvider({
5632
- api,
5633
- children,
5634
- sessionTokenName,
5635
- Provider
5636
- }) {
5637
- const [user, setUser] = useState11();
5638
- const [status, setStatus] = useState11("unauthenticated");
5639
- const { createAlert } = useAlert();
5640
- const signIn = useCallback8(
5641
- async ({ email, password }) => {
5642
- setStatus("loading");
5859
+ const response = await fetch(
5860
+ `https://login.microsoftonline.com/${this.oauth.tenant_id}/oauth2/v2.0/token`,
5861
+ {
5862
+ method: "POST",
5863
+ body: new URLSearchParams(body),
5864
+ headers: { "Content-Type": "application/x-www-form-urlencoded" }
5865
+ }
5866
+ );
5867
+ const data = await response.json();
5868
+ const decodedToken = jwt.decode(data.access_token);
5869
+ const email = decodedToken.upn;
5870
+ const fullName = `${decodedToken?.given_name} ${decodedToken?.family_name}`;
5871
+ return { decodedToken, email, fullName };
5872
+ }
5873
+ createOauthCallbackGetServerSideProps({
5874
+ onSuccessDestination,
5875
+ onFailedDestination
5876
+ }) {
5877
+ return async (ctx) => {
5878
+ if (!this.oauth) throw new Error("Oauth env variables are not defined");
5879
+ const code = ctx.query.code;
5880
+ if (!code)
5881
+ return {
5882
+ redirect: {
5883
+ permanent: false,
5884
+ destination: onFailedDestination || "/"
5885
+ }
5886
+ };
5643
5887
  try {
5644
- const response = await api.post("/auth/login", {
5645
- email,
5646
- password
5888
+ const { fullName, email } = await this.oauthSignInCallback(code);
5889
+ const userExists = await this.onGetUserData(email);
5890
+ if (!userExists && !this.oauth.onCreateUser) throw new Error("User does not exists");
5891
+ if (!userExists && this.oauth.onCreateUser) {
5892
+ await this.oauth.onCreateUser({ fullname: fullName, email });
5893
+ }
5894
+ const { token, refreshToken } = await this.generateJwtAndRefreshToken(email, {});
5895
+ setCookie(ctx, this.cookies.sessionToken, token, {
5896
+ secure: true,
5897
+ maxAge: 60 * 60 * 24 * 30,
5898
+ // 30 days
5899
+ path: "/"
5647
5900
  });
5648
- const { token } = response.data;
5649
- api.defaults.headers.common.Authorization = `Bearer ${token}`;
5650
- const { data } = await api.get("/auth/me");
5651
- setUser(data);
5652
- setStatus("autenticated");
5653
- return true;
5901
+ setCookie(ctx, this.cookies.refreshToken, refreshToken, {
5902
+ secure: true,
5903
+ maxAge: 60 * 60 * 24 * 30,
5904
+ // 30 days
5905
+ path: "/",
5906
+ httpOnly: true
5907
+ });
5908
+ return {
5909
+ redirect: {
5910
+ destination: onSuccessDestination,
5911
+ permanent: false
5912
+ }
5913
+ };
5654
5914
  } catch (error) {
5655
- createAlert(error?.response?.data?.error, "error");
5656
- setStatus("unauthenticated");
5657
- throw error;
5658
- }
5659
- },
5660
- [createAlert, api]
5661
- );
5662
- const ClientSignOut = useCallback8(async () => {
5663
- await api.get("/auth/logout");
5664
- setUser(void 0);
5665
- }, [api]);
5666
- useEffect8(() => {
5667
- const token = parseCookies()[sessionTokenName];
5668
- if (token) {
5669
- setStatus("loading");
5670
- api.get("/auth/me").then((response) => {
5671
- setStatus("autenticated");
5672
- setUser(response.data);
5673
- }).catch(() => {
5674
- setStatus("unauthenticated");
5675
- });
5676
- }
5677
- }, [api, sessionTokenName]);
5678
- return /* @__PURE__ */ React33.createElement(
5679
- Provider,
5680
- {
5681
- value: {
5682
- user,
5683
- signOut: ClientSignOut,
5684
- signIn,
5685
- status
5915
+ return {
5916
+ props: {
5917
+ error: JSON.stringify(error)
5918
+ }
5919
+ };
5686
5920
  }
5687
- },
5688
- children
5689
- );
5690
- }
5921
+ };
5922
+ }
5923
+ };
5691
5924
  export {
5692
5925
  AlertContext,
5693
5926
  AlertProvider,
@@ -5711,6 +5944,7 @@ export {
5711
5944
  FormHelperProvider,
5712
5945
  GetInputLabel,
5713
5946
  Grid_default as Grid,
5947
+ HttpClientError,
5714
5948
  HttpError,
5715
5949
  Input,
5716
5950
  InputMask2 as InputMask,
@@ -5725,6 +5959,7 @@ export {
5725
5959
  UseDialogConfirm,
5726
5960
  createAuthContext,
5727
5961
  createFilter,
5962
+ createHttpClient,
5728
5963
  destroyCookie,
5729
5964
  filterData,
5730
5965
  getTabProps,