@bluemarble/bm-components 1.16.0 → 1.16.2

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.mjs CHANGED
@@ -258,7 +258,7 @@ var require_react_is_development = __commonJS({
258
258
  var Fragment3 = REACT_FRAGMENT_TYPE;
259
259
  var Lazy = REACT_LAZY_TYPE;
260
260
  var Memo = REACT_MEMO_TYPE;
261
- var Portal = REACT_PORTAL_TYPE;
261
+ var Portal2 = REACT_PORTAL_TYPE;
262
262
  var Profiler = REACT_PROFILER_TYPE;
263
263
  var StrictMode = REACT_STRICT_MODE_TYPE;
264
264
  var Suspense = REACT_SUSPENSE_TYPE;
@@ -317,7 +317,7 @@ var require_react_is_development = __commonJS({
317
317
  exports.Fragment = Fragment3;
318
318
  exports.Lazy = Lazy;
319
319
  exports.Memo = Memo;
320
- exports.Portal = Portal;
320
+ exports.Portal = Portal2;
321
321
  exports.Profiler = Profiler;
322
322
  exports.StrictMode = StrictMode;
323
323
  exports.Suspense = Suspense;
@@ -2404,7 +2404,7 @@ function createBox(options = {}) {
2404
2404
  const BoxRoot = styled("div", {
2405
2405
  shouldForwardProp: (prop) => prop !== "theme" && prop !== "sx" && prop !== "as"
2406
2406
  })(styleFunctionSx_default);
2407
- const Box7 = /* @__PURE__ */ React3.forwardRef(function Box8(inProps, ref) {
2407
+ const Box8 = /* @__PURE__ */ React3.forwardRef(function Box9(inProps, ref) {
2408
2408
  const theme = useTheme_default(defaultTheme);
2409
2409
  const _extendSxProp = extendSxProp(inProps), {
2410
2410
  className,
@@ -2417,7 +2417,7 @@ function createBox(options = {}) {
2417
2417
  theme: themeId ? theme[themeId] || theme : theme
2418
2418
  }, other));
2419
2419
  });
2420
- return Box7;
2420
+ return Box8;
2421
2421
  }
2422
2422
 
2423
2423
  // node_modules/@mui/utils/generateUtilityClass/generateUtilityClass.js
@@ -3202,7 +3202,7 @@ var BaseInputMask = (_a) => {
3202
3202
  const { ref, value, setValue, maskRef, unmaskedValue } = useIMask2(
3203
3203
  mask,
3204
3204
  {
3205
- onComplete: (...params) => {
3205
+ onAccept: (...params) => {
3206
3206
  if (onChangeValue)
3207
3207
  onChangeValue(params[0], unmaskedValue);
3208
3208
  }
@@ -4062,6 +4062,101 @@ var Dialog = (_a) => {
4062
4062
  }))));
4063
4063
  };
4064
4064
 
4065
+ // src/components/DialogConfirm/DialogConfirm.view.tsx
4066
+ import React24 from "react";
4067
+ import { Box as Box7, Portal, Stack as Stack2, Typography as Typography3 } from "@mui/material";
4068
+ import { grey, orange } from "@mui/material/colors";
4069
+ import { MdOutlineWarningAmber } from "react-icons/md";
4070
+
4071
+ // src/components/DialogConfirm/DialogConfirm.model.ts
4072
+ import { useRef as useRef3, useState as useState4 } from "react";
4073
+ function UseDialogConfirm() {
4074
+ const [opened, setOpened] = useState4(false);
4075
+ const [isLoading, setLoading] = useState4(false);
4076
+ const onConfirmFn = useRef3();
4077
+ const paramsFn = useRef3([]);
4078
+ const onConfirm = (fn) => {
4079
+ onConfirmFn.current = fn;
4080
+ return (...params) => __async(this, null, function* () {
4081
+ paramsFn.current = params;
4082
+ setOpened(true);
4083
+ });
4084
+ };
4085
+ const onProceed = (event) => __async(this, null, function* () {
4086
+ event == null ? void 0 : event.preventDefault();
4087
+ event == null ? void 0 : event.stopPropagation();
4088
+ setLoading(true);
4089
+ try {
4090
+ if (!onConfirmFn.current)
4091
+ return;
4092
+ yield onConfirmFn.current(...paramsFn.current);
4093
+ } finally {
4094
+ setOpened(false);
4095
+ setLoading(false);
4096
+ }
4097
+ });
4098
+ const onCancel = (event) => {
4099
+ event == null ? void 0 : event.preventDefault();
4100
+ event == null ? void 0 : event.stopPropagation();
4101
+ setOpened(false);
4102
+ };
4103
+ const onCloseModal = () => {
4104
+ if (isLoading)
4105
+ return;
4106
+ setOpened(false);
4107
+ };
4108
+ return {
4109
+ isLoading,
4110
+ opened,
4111
+ onConfirm,
4112
+ onCloseModal,
4113
+ onCancel,
4114
+ onProceed
4115
+ };
4116
+ }
4117
+
4118
+ // src/components/DialogConfirm/DialogConfirm.view.tsx
4119
+ var DEFAULT_ICON = MdOutlineWarningAmber;
4120
+ var DialogConfirm = (props) => {
4121
+ const model = UseDialogConfirm();
4122
+ const Icon = props.icon || DEFAULT_ICON;
4123
+ return /* @__PURE__ */ React24.createElement(React24.Fragment, null, props.children({
4124
+ onConfirm: model.onConfirm,
4125
+ onCancel: model.onCancel
4126
+ }), /* @__PURE__ */ React24.createElement(Portal, null, /* @__PURE__ */ React24.createElement(Modal, { open: model.opened, onClose: model.onCloseModal }, /* @__PURE__ */ React24.createElement(Box7, { sx: { p: 2, maxWidth: 400, textAlign: "center" } }, /* @__PURE__ */ React24.createElement(
4127
+ Stack2,
4128
+ {
4129
+ mx: "auto",
4130
+ color: orange[800],
4131
+ bgcolor: orange[50],
4132
+ borderRadius: "50%",
4133
+ height: 8 * 5,
4134
+ width: 8 * 5,
4135
+ direction: "row",
4136
+ justifyContent: "center",
4137
+ alignItems: "center"
4138
+ },
4139
+ /* @__PURE__ */ React24.createElement(Icon, { size: 8 * 3 })
4140
+ ), /* @__PURE__ */ React24.createElement(Typography3, { fontWeight: "bold", variant: "h6", mt: 1 }, props.title || "Aten\xE7\xE3o"), /* @__PURE__ */ React24.createElement(Typography3, { my: 1 }, props.body || "Tem certeza que deseja realizar essa a\xE7\xE3o?"), /* @__PURE__ */ React24.createElement(Stack2, { gap: 1, mt: 3, color: grey[600] }, /* @__PURE__ */ React24.createElement(
4141
+ LargeButton,
4142
+ {
4143
+ color: "warning",
4144
+ loading: model.isLoading,
4145
+ onClick: model.onProceed
4146
+ },
4147
+ props.confirmButtonText || "Confirmar"
4148
+ ), /* @__PURE__ */ React24.createElement(
4149
+ LargeButton,
4150
+ {
4151
+ variant: "outlined",
4152
+ disabled: model.isLoading,
4153
+ onClick: model.onCancel,
4154
+ color: "inherit"
4155
+ },
4156
+ props.cancelButtonText || "Confirmar"
4157
+ ))))));
4158
+ };
4159
+
4065
4160
  // src/errors/HttpError.ts
4066
4161
  var HttpError = class extends Error {
4067
4162
  constructor(status, message) {
@@ -4175,21 +4270,21 @@ var ApiHelper = class _ApiHelper {
4175
4270
  };
4176
4271
 
4177
4272
  // src/hooks/useFormHelper.ts
4178
- import { useCallback as useCallback3, useContext as useContext3, useEffect as useEffect4, useRef as useRef3 } from "react";
4273
+ import { useCallback as useCallback3, useContext as useContext3, useEffect as useEffect4, useRef as useRef4 } from "react";
4179
4274
 
4180
4275
  // src/hooks/useAlert.ts
4181
4276
  import { useContext as useContext2 } from "react";
4182
4277
 
4183
4278
  // src/contexts/AlertContext.tsx
4184
- import React25, { useCallback } from "react";
4185
- import { createContext, useState as useState4 } from "react";
4279
+ import React26, { useCallback } from "react";
4280
+ import { createContext, useState as useState5 } from "react";
4186
4281
 
4187
4282
  // src/components/Toast/index.tsx
4188
- import React24 from "react";
4283
+ import React25 from "react";
4189
4284
  import { Alert, IconButton as IconButton4, Snackbar } from "@mui/material";
4190
4285
  import { MdClose as MdClose2 } from "react-icons/md";
4191
4286
  var Toast = ({ open, onClose, severity, message }) => {
4192
- return /* @__PURE__ */ React24.createElement(React24.Fragment, null, /* @__PURE__ */ React24.createElement(
4287
+ return /* @__PURE__ */ React25.createElement(React25.Fragment, null, /* @__PURE__ */ React25.createElement(
4193
4288
  Snackbar,
4194
4289
  {
4195
4290
  open,
@@ -4198,12 +4293,12 @@ var Toast = ({ open, onClose, severity, message }) => {
4198
4293
  anchorOrigin: { vertical: "top", horizontal: "right" },
4199
4294
  sx: { zIndex: 99999999 }
4200
4295
  },
4201
- /* @__PURE__ */ React24.createElement(
4296
+ /* @__PURE__ */ React25.createElement(
4202
4297
  Alert,
4203
4298
  {
4204
4299
  severity,
4205
4300
  elevation: 2,
4206
- action: /* @__PURE__ */ React24.createElement(
4301
+ action: /* @__PURE__ */ React25.createElement(
4207
4302
  IconButton4,
4208
4303
  {
4209
4304
  "aria-label": "close",
@@ -4211,7 +4306,7 @@ var Toast = ({ open, onClose, severity, message }) => {
4211
4306
  size: "small",
4212
4307
  onClick: onClose
4213
4308
  },
4214
- /* @__PURE__ */ React24.createElement(MdClose2, { fontSize: "inherit" })
4309
+ /* @__PURE__ */ React25.createElement(MdClose2, { fontSize: "inherit" })
4215
4310
  )
4216
4311
  },
4217
4312
  message
@@ -4222,9 +4317,9 @@ var Toast = ({ open, onClose, severity, message }) => {
4222
4317
  // src/contexts/AlertContext.tsx
4223
4318
  var AlertContext = createContext({});
4224
4319
  var AlertProvider = ({ children }) => {
4225
- const [severity, setSeverity] = useState4("info");
4226
- const [message, setMessage] = useState4("");
4227
- const [isVisible, setIsVisible] = useState4(false);
4320
+ const [severity, setSeverity] = useState5("info");
4321
+ const [message, setMessage] = useState5("");
4322
+ const [isVisible, setIsVisible] = useState5(false);
4228
4323
  const createAlert = useCallback(
4229
4324
  (newMessage, severity2) => {
4230
4325
  setMessage(newMessage);
@@ -4236,7 +4331,7 @@ var AlertProvider = ({ children }) => {
4236
4331
  const onCloseToast = useCallback(() => {
4237
4332
  setIsVisible(false);
4238
4333
  }, []);
4239
- return /* @__PURE__ */ React25.createElement(AlertContext.Provider, { value: { createAlert } }, children, /* @__PURE__ */ React25.createElement(
4334
+ return /* @__PURE__ */ React26.createElement(AlertContext.Provider, { value: { createAlert } }, children, /* @__PURE__ */ React26.createElement(
4240
4335
  Toast,
4241
4336
  {
4242
4337
  open: isVisible,
@@ -4253,9 +4348,9 @@ var useAlert = () => {
4253
4348
  };
4254
4349
 
4255
4350
  // src/hooks/useLoading.ts
4256
- import { useCallback as useCallback2, useState as useState5 } from "react";
4351
+ import { useCallback as useCallback2, useState as useState6 } from "react";
4257
4352
  function useLoading() {
4258
- const [state, setState] = useState5([]);
4353
+ const [state, setState] = useState6([]);
4259
4354
  const isLoading = useCallback2((prop) => state.includes(prop), [state]);
4260
4355
  const setLoading = useCallback2((prop, remove) => {
4261
4356
  if (remove)
@@ -4267,11 +4362,11 @@ function useLoading() {
4267
4362
  }
4268
4363
 
4269
4364
  // src/contexts/FormHelperProvider.tsx
4270
- import React26 from "react";
4365
+ import React27 from "react";
4271
4366
  import { createContext as createContext2 } from "react";
4272
4367
  var FormHelperContext = createContext2({});
4273
4368
  var FormHelperProvider = ({ formatErrorMessage, api, children }) => {
4274
- return /* @__PURE__ */ React26.createElement(FormHelperContext.Provider, { value: { formatErrorMessage, api } }, children);
4369
+ return /* @__PURE__ */ React27.createElement(FormHelperContext.Provider, { value: { formatErrorMessage, api } }, children);
4275
4370
  };
4276
4371
 
4277
4372
  // src/hooks/useFormHelper.ts
@@ -4281,7 +4376,7 @@ function useFormHelper() {
4281
4376
  const { api, formatErrorMessage } = useContext3(FormHelperContext);
4282
4377
  const { createAlert } = alertProps;
4283
4378
  const { setLoading } = loadingProps;
4284
- const sourceRef = useRef3(new AbortController());
4379
+ const sourceRef = useRef4(new AbortController());
4285
4380
  const onSubmitWrapper = useCallback3(
4286
4381
  (fn, { name }) => {
4287
4382
  return (fields, methods) => __async(this, null, function* () {
@@ -4680,11 +4775,11 @@ var AuthHelper = class {
4680
4775
  };
4681
4776
 
4682
4777
  // src/hooks/useGrid.ts
4683
- import { useCallback as useCallback5, useEffect as useEffect5, useMemo as useMemo3, useState as useState7 } from "react";
4778
+ import { useCallback as useCallback5, useEffect as useEffect5, useMemo as useMemo3, useState as useState8 } from "react";
4684
4779
 
4685
4780
  // src/hooks/useFilter.ts
4686
4781
  import moment2 from "moment";
4687
- import { useCallback as useCallback4, useState as useState6 } from "react";
4782
+ import { useCallback as useCallback4, useState as useState7 } from "react";
4688
4783
 
4689
4784
  // src/components/utils/getObjectValue.ts
4690
4785
  function getObjectValue(obj) {
@@ -4699,7 +4794,7 @@ function getObjectValue(obj) {
4699
4794
 
4700
4795
  // src/hooks/useFilter.ts
4701
4796
  function useFilter(props = { defaultFilters: [] }) {
4702
- const [selectedFilters, setSelectedFilters] = useState6(() => {
4797
+ const [selectedFilters, setSelectedFilters] = useState7(() => {
4703
4798
  const { defaultFilters } = props;
4704
4799
  return defaultFilters || [];
4705
4800
  });
@@ -4790,12 +4885,12 @@ function useGrid({
4790
4885
  defaultCurrentPage,
4791
4886
  defaultSortedBy
4792
4887
  }) {
4793
- const [defaultData, setDefaultData] = useState7(externalDefaultData || []);
4794
- const [sortedBy, setSortedBy] = useState7(
4888
+ const [defaultData, setDefaultData] = useState8(externalDefaultData || []);
4889
+ const [sortedBy, setSortedBy] = useState8(
4795
4890
  defaultSortedBy || []
4796
4891
  );
4797
- const [currentPage, setCurrentPage] = useState7(defaultCurrentPage || 0);
4798
- const [rowsPerPage, setRowsPerPage] = useState7(rowsPerPageOptions[0]);
4892
+ const [currentPage, setCurrentPage] = useState8(defaultCurrentPage || 0);
4893
+ const [rowsPerPage, setRowsPerPage] = useState8(rowsPerPageOptions[0]);
4799
4894
  const toggleSortedDirection = useCallback5(
4800
4895
  (direction) => {
4801
4896
  if (direction === "asc")
@@ -4876,8 +4971,15 @@ function useGrid({
4876
4971
  },
4877
4972
  [currentPage]
4878
4973
  );
4974
+ const orderedData = useMemo3(() => {
4975
+ if (sortedBy.length === 0)
4976
+ return defaultData;
4977
+ const newData = defaultData.slice(0);
4978
+ const sortedData = sortData(newData);
4979
+ return sortedData;
4980
+ }, [defaultData, sortData, sortedBy]);
4879
4981
  const filteredData = useMemo3(() => {
4880
- let newData = defaultData.slice(0);
4982
+ let newData = orderedData.slice(0);
4881
4983
  if (search && search.value !== "") {
4882
4984
  const searchBy = createSearch(search);
4883
4985
  newData = newData.filter(searchBy);
@@ -4886,16 +4988,12 @@ function useGrid({
4886
4988
  return newData;
4887
4989
  const newFilter = createFilter(filters);
4888
4990
  return newData.filter(newFilter.apply);
4889
- }, [defaultData, search, filters]);
4890
- const orderedData = useMemo3(() => {
4891
- const sortedData = sortData(filteredData);
4892
- return sortedData;
4893
- }, [filteredData, sortData]);
4991
+ }, [orderedData, search, filters]);
4894
4992
  const paginatedData = useMemo3(() => {
4895
4993
  const startPage = currentPage * rowsPerPage;
4896
4994
  const endPage = startPage + rowsPerPage;
4897
- return orderedData.slice(startPage, endPage);
4898
- }, [currentPage, rowsPerPage, orderedData]);
4995
+ return filteredData.slice(startPage, endPage);
4996
+ }, [currentPage, rowsPerPage, filteredData]);
4899
4997
  const totalNumberOfPages = Math.ceil(filteredData.length / rowsPerPage) - 1;
4900
4998
  useEffect5(() => {
4901
4999
  if (externalDefaultData)
@@ -4959,7 +5057,7 @@ function createSearch(options) {
4959
5057
  }
4960
5058
 
4961
5059
  // src/hooks/useAsyncGrid.ts
4962
- import { useCallback as useCallback6, useEffect as useEffect6, useState as useState8 } from "react";
5060
+ import { useCallback as useCallback6, useEffect as useEffect6, useState as useState9 } from "react";
4963
5061
  function useAsyncGrid({
4964
5062
  columns,
4965
5063
  filters = [],
@@ -4972,14 +5070,14 @@ function useAsyncGrid({
4972
5070
  defaultCurrentPage,
4973
5071
  defaultSortedBy
4974
5072
  }) {
4975
- const [defaultData, setDefaultData] = useState8(externalDefaultData || []);
4976
- const [sortedBy, setSortedBy] = useState8(
5073
+ const [defaultData, setDefaultData] = useState9(externalDefaultData || []);
5074
+ const [sortedBy, setSortedBy] = useState9(
4977
5075
  defaultSortedBy || []
4978
5076
  );
4979
- const [totalNumberOfItems, setTotalNumberOfItems] = useState8(0);
4980
- const [isLoading, setIsLoading] = useState8(false);
4981
- const [currentPage, setCurrentPage] = useState8(defaultCurrentPage || 0);
4982
- const [rowsPerPage, setRowsPerPage] = useState8(rowsPerPageOptions[0]);
5077
+ const [totalNumberOfItems, setTotalNumberOfItems] = useState9(0);
5078
+ const [isLoading, setIsLoading] = useState9(false);
5079
+ const [currentPage, setCurrentPage] = useState9(defaultCurrentPage || 0);
5080
+ const [rowsPerPage, setRowsPerPage] = useState9(rowsPerPageOptions[0]);
4983
5081
  const totalNumberOfPages = Math.ceil(totalNumberOfItems / rowsPerPage) - 1;
4984
5082
  const toggleSortedDirection = useCallback6(
4985
5083
  (direction) => {
@@ -5144,11 +5242,11 @@ function useEvent(event, handler, passive = false) {
5144
5242
  }
5145
5243
 
5146
5244
  // src/contexts/AuthContext.tsx
5147
- import React27, { useCallback as useCallback7 } from "react";
5245
+ import React28, { useCallback as useCallback7 } from "react";
5148
5246
  import {
5149
5247
  createContext as createContext3,
5150
5248
  useEffect as useEffect8,
5151
- useState as useState9
5249
+ useState as useState10
5152
5250
  } from "react";
5153
5251
  import { parseCookies as parseCookies2 } from "nookies";
5154
5252
  function createAuthContext() {
@@ -5160,8 +5258,8 @@ function CreateAuthProvider({
5160
5258
  sessionTokenName,
5161
5259
  Provider
5162
5260
  }) {
5163
- const [user, setUser] = useState9();
5164
- const [status, setStatus] = useState9("unauthenticated");
5261
+ const [user, setUser] = useState10();
5262
+ const [status, setStatus] = useState10("unauthenticated");
5165
5263
  const { createAlert } = useAlert();
5166
5264
  const signIn = useCallback7(
5167
5265
  (_0) => __async(this, [_0], function* ({ email, password }) {
@@ -5202,7 +5300,7 @@ function CreateAuthProvider({
5202
5300
  });
5203
5301
  }
5204
5302
  }, [api, sessionTokenName]);
5205
- return /* @__PURE__ */ React27.createElement(
5303
+ return /* @__PURE__ */ React28.createElement(
5206
5304
  Provider,
5207
5305
  {
5208
5306
  value: {
@@ -5226,6 +5324,7 @@ export {
5226
5324
  Checkbox,
5227
5325
  CreateAuthProvider,
5228
5326
  Dialog,
5327
+ DialogConfirm,
5229
5328
  DomainError,
5230
5329
  EditableTableCell,
5231
5330
  FormHelperContext,
@@ -5243,6 +5342,7 @@ export {
5243
5342
  TabPanel,
5244
5343
  Td,
5245
5344
  Tr,
5345
+ UseDialogConfirm,
5246
5346
  createAuthContext,
5247
5347
  createFilter,
5248
5348
  filterData,