@yeverlibs/ds 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -529,10 +529,6 @@ type TableProps<T> = {
529
529
  noBackground?: boolean
530
530
  linkAccessor?: (row: T) => string
531
531
  isLink?: boolean
532
- // Funções opcionais para gerenciamento de URL
533
- getUrlParam?: (key: string, defaultValue?: string | number) => string | number
534
- updateUrlParam?: (key: string, value: string) => void
535
- getPathname?: () => string | null
536
532
  }
537
533
 
538
534
  declare const Table: <T>(props: TableProps<T>) => react_jsx_runtime.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -529,10 +529,6 @@ type TableProps<T> = {
529
529
  noBackground?: boolean
530
530
  linkAccessor?: (row: T) => string
531
531
  isLink?: boolean
532
- // Funções opcionais para gerenciamento de URL
533
- getUrlParam?: (key: string, defaultValue?: string | number) => string | number
534
- updateUrlParam?: (key: string, value: string) => void
535
- getPathname?: () => string | null
536
532
  }
537
533
 
538
534
  declare const Table: <T>(props: TableProps<T>) => react_jsx_runtime.JSX.Element;
package/dist/index.js CHANGED
@@ -6165,26 +6165,6 @@ var Skeleton = ({ className }) => {
6165
6165
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("animate-pulse rounded-md bg-gray-200", className) });
6166
6166
  };
6167
6167
  var RESET_PAGE = 1;
6168
- var defaultUpdateUrlParam = (key, value) => {
6169
- if (typeof window === "undefined") return;
6170
- const params = new URLSearchParams(window.location.search);
6171
- if (value) {
6172
- params.set(key, value);
6173
- } else {
6174
- params.delete(key);
6175
- }
6176
- const queryString = params.toString();
6177
- const newUrl = queryString ? `${window.location.pathname}?${queryString}` : window.location.pathname;
6178
- window.history.replaceState(null, "", newUrl);
6179
- };
6180
- var defaultGetUrlParam = (key, defaultValue = "") => {
6181
- if (typeof window === "undefined") return defaultValue;
6182
- const params = new URLSearchParams(window.location.search);
6183
- const value = params.get(key);
6184
- if (value === null) return defaultValue;
6185
- if (typeof defaultValue === "number") return Number(value) || defaultValue;
6186
- return value;
6187
- };
6188
6168
  var TableContent = ({
6189
6169
  columns,
6190
6170
  data,
@@ -6200,11 +6180,9 @@ var TableContent = ({
6200
6180
  onPaginateAction,
6201
6181
  noPagination,
6202
6182
  wrapperClassName,
6203
- noBackground = false,
6204
- getUrlParam,
6205
- updateUrlParam,
6206
- getPathname
6183
+ noBackground = false
6207
6184
  }) => {
6185
+ const pathname = navigation.usePathname();
6208
6186
  const actionMenuRef = React107.useRef(null);
6209
6187
  const [visibleActionRow, setVisibleActionRow] = React107.useState(null);
6210
6188
  const [isLoading, setIsLoading] = React107.useState(false);
@@ -6212,29 +6190,20 @@ var TableContent = ({
6212
6190
  const [searchQuery, setSearchQuery] = React107.useState("");
6213
6191
  const [itemsPerPage, setItemsPerPage] = React107.useState(10);
6214
6192
  const [selectedRows, setSelectedRows] = React107.useState(/* @__PURE__ */ new Set());
6215
- const getUrlParamValue = getUrlParam || defaultGetUrlParam;
6216
- const updateUrlParamValue = updateUrlParam || defaultUpdateUrlParam;
6217
- getUrlParamValue("perPage", 10);
6218
- const page = getUrlParamValue("page", 1);
6219
- getUrlParamValue("search", "");
6220
- const handlePagination = React107.useCallback(async () => {
6221
- if (!onPaginateAction) return;
6222
- setIsLoading(true);
6223
- await onPaginateAction();
6224
- setIsLoading(false);
6225
- }, [onPaginateAction]);
6193
+ const searchParams = navigation.useSearchParams();
6194
+ const perPage = Number(searchParams?.get("perPage")) || 10;
6195
+ const page = Number(searchParams?.get("page")) || 1;
6196
+ const searchParam = searchParams?.get("search") || "";
6226
6197
  React107.useEffect(() => {
6227
6198
  setCurrentPage(page);
6228
6199
  }, [page]);
6229
6200
  React107.useEffect(() => {
6230
- if (typeof window === "undefined") return;
6231
- const searchParams = new URLSearchParams(window.location.search);
6232
- if (searchParams.toString().length > 0) {
6201
+ const searchParams2 = new URLSearchParams(window.location.search);
6202
+ if (searchParams2.toString().length > 0) {
6233
6203
  onPaginateAction?.();
6234
6204
  }
6235
- }, [onPaginateAction]);
6205
+ }, []);
6236
6206
  React107.useEffect(() => {
6237
- if (typeof window === "undefined") return;
6238
6207
  const shouldReset = document.cookie.includes("reset-table-params=true");
6239
6208
  if (shouldReset) {
6240
6209
  document.cookie = "reset-table-params=; max-age=0; path=/";
@@ -6250,39 +6219,38 @@ var TableContent = ({
6250
6219
  }
6251
6220
  window.history.replaceState({}, "", url);
6252
6221
  }
6253
- }, []);
6222
+ }, [pathname]);
6254
6223
  React107.useEffect(() => {
6255
- if (!getUrlParam && typeof window === "undefined") return;
6256
- const urlPerPage = getUrlParamValue("perPage", 10);
6257
- const urlSearch = getUrlParamValue("search", "");
6258
- if (urlPerPage !== itemsPerPage) {
6259
- setItemsPerPage(urlPerPage);
6260
- if (onPaginateAction) {
6261
- handlePagination();
6262
- }
6263
- }
6264
- if (urlSearch !== searchQuery) {
6265
- setSearchQuery(urlSearch);
6266
- if (onPaginateAction) {
6267
- handlePagination();
6268
- }
6269
- }
6270
- }, [itemsPerPage, searchQuery, handlePagination, getUrlParam, getUrlParamValue, onPaginateAction]);
6224
+ if (!pathname) return;
6225
+ if (searchParams?.has("perPage")) {
6226
+ setItemsPerPage(perPage);
6227
+ nextReplaceUrl("perPage", String(perPage), pathname);
6228
+ handlePagination();
6229
+ }
6230
+ if (searchParams?.has("search")) {
6231
+ setSearchQuery(searchParam);
6232
+ nextReplaceUrl("search", searchParam, pathname);
6233
+ handlePagination();
6234
+ }
6235
+ }, [perPage, searchParam]);
6236
+ const handlePagination = async () => {
6237
+ if (!onPaginateAction) return;
6238
+ setIsLoading(true);
6239
+ await onPaginateAction();
6240
+ setIsLoading(false);
6241
+ };
6271
6242
  const totalPages = pagination ? Math.ceil(pagination.total / itemsPerPage) : 1;
6272
- const paginatedData = data || [];
6243
+ const paginatedData = data;
6273
6244
  const visibleColumns = columns.filter((column) => !hiddenColumns.includes(column.accessor));
6274
6245
  const headersWithContent = visibleColumns.filter((column) => column.Header);
6275
- if (visibleColumns.length === 0 && columns.length > 0) {
6276
- console.warn("Table: Todas as colunas est\xE3o ocultas. Verifique a prop hiddenColumns.");
6277
- }
6278
6246
  const handleSearch = (e) => {
6279
6247
  setSearchQuery(e.target.value);
6280
6248
  };
6281
6249
  const handleSearchSubmit = () => {
6282
- updateUrlParamValue("search", searchQuery);
6283
- updateUrlParamValue("page", "1");
6284
- setCurrentPage(1);
6285
- handlePagination();
6250
+ if (!pathname) return;
6251
+ Promise.all([nextReplaceUrl("search", searchQuery, pathname), nextReplaceUrl("page", "1", pathname)]).then(() => {
6252
+ handlePagination();
6253
+ });
6286
6254
  };
6287
6255
  const handleClickOutside = React107.useCallback((event) => {
6288
6256
  if (actionMenuRef.current && !actionMenuRef.current.contains(event.target)) {
@@ -6337,7 +6305,7 @@ var TableContent = ({
6337
6305
  return cellValue;
6338
6306
  }
6339
6307
  };
6340
- return isLink && linkHref ? /* @__PURE__ */ jsxRuntime.jsx("a", { href: linkHref, className: "text-blue-600 hover:text-blue-800 underline", children: content() }) : content();
6308
+ return isLink && linkHref ? /* @__PURE__ */ jsxRuntime.jsx(Link2__default.default, { href: linkHref, children: content() }) : content();
6341
6309
  };
6342
6310
  if (isLoading) {
6343
6311
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -6441,7 +6409,7 @@ var TableContent = ({
6441
6409
  onChange: handleSelectAllRows
6442
6410
  }
6443
6411
  ) }),
6444
- headersWithContent.length === 1 && visibleColumns.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
6412
+ headersWithContent.length === 1 ? /* @__PURE__ */ jsxRuntime.jsx(
6445
6413
  "th",
6446
6414
  {
6447
6415
  colSpan: visibleColumns.length,
@@ -6455,10 +6423,10 @@ var TableContent = ({
6455
6423
  style: { minWidth: columnWidths[index] },
6456
6424
  children: column.Header ?? ""
6457
6425
  },
6458
- column.id || `column-${index}`
6426
+ column.id || index
6459
6427
  ))
6460
6428
  ] }) }),
6461
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: paginatedData && paginatedData.length > 0 ? paginatedData.map((row, rowIndex) => /* @__PURE__ */ jsxRuntime.jsxs(
6429
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: paginatedData?.length > 0 ? paginatedData?.map((row, rowIndex) => /* @__PURE__ */ jsxRuntime.jsxs(
6462
6430
  "tr",
6463
6431
  {
6464
6432
  className: cn(
@@ -6517,18 +6485,15 @@ var TableContent = ({
6517
6485
  ]
6518
6486
  },
6519
6487
  rowIndex
6520
- )) : /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: visibleColumns.length + (selectable ? 1 : 0), style: { textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-6", children: [
6488
+ )) : /* @__PURE__ */ jsxRuntime.jsx("tr", { children: /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: columns.length + (selectable ? 1 : 0), style: { textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-6", children: [
6521
6489
  /* @__PURE__ */ jsxRuntime.jsx(
6522
- "img",
6490
+ Image4__default.default,
6523
6491
  {
6524
6492
  src: "/empty-table.svg",
6525
6493
  width: 666,
6526
6494
  height: 329,
6527
6495
  alt: "Nenhum resultado encontrado",
6528
- className: "mx-auto",
6529
- onError: (e) => {
6530
- e.currentTarget.style.display = "none";
6531
- }
6496
+ className: "mx-auto"
6532
6497
  }
6533
6498
  ),
6534
6499
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-8", children: [
@@ -6559,12 +6524,16 @@ var TableContent = ({
6559
6524
  {
6560
6525
  value: itemsPerPage,
6561
6526
  onChange: async (e) => {
6527
+ if (!pathname) return;
6562
6528
  const newPerPage = Number(e.target.value);
6563
6529
  setItemsPerPage(newPerPage);
6564
6530
  setCurrentPage(RESET_PAGE);
6565
- updateUrlParamValue("page", "1");
6566
- updateUrlParamValue("perPage", String(newPerPage));
6567
- handlePagination();
6531
+ Promise.all([
6532
+ nextReplaceUrl("page", "1", pathname),
6533
+ nextReplaceUrl("perPage", String(newPerPage), pathname)
6534
+ ]).then(() => {
6535
+ handlePagination();
6536
+ });
6568
6537
  },
6569
6538
  className: "block h-8 w-full cursor-pointer appearance-none rounded border border-gray-300 bg-white p-2 text-sm leading-tight text-gray-700 focus:border-gray-500 focus:bg-white focus:outline-none",
6570
6539
  children: [
@@ -6594,23 +6563,7 @@ var TableContent = ({
6594
6563
  ] }) });
6595
6564
  };
6596
6565
  var Table = (props) => {
6597
- if (!props.columns || props.columns.length === 0) {
6598
- return /* @__PURE__ */ jsxRuntime.jsx(
6599
- Box,
6600
- {
6601
- className: cn(
6602
- "flex flex-col overflow-hidden",
6603
- props.wrapperClassName,
6604
- props.noBackground ? "bg-transparent border-none p-0" : ""
6605
- ),
6606
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-6", children: /* @__PURE__ */ jsxRuntime.jsx(Text, { $as: "p", children: "Nenhuma coluna definida para a tabela." }) })
6607
- }
6608
- );
6609
- }
6610
- if (!props.data) {
6611
- console.warn('Table: A prop "data" n\xE3o foi fornecida ou \xE9 undefined.');
6612
- }
6613
- return /* @__PURE__ */ jsxRuntime.jsx(TableContent, { ...props });
6566
+ return /* @__PURE__ */ jsxRuntime.jsx(React107.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(TableContent, { ...props }) });
6614
6567
  };
6615
6568
  var Tabs = ({ headers, children, noGap, active, alignDiv = "full" }) => {
6616
6569
  const [activeTab, setActiveTab] = React107.useState(active || 0);