@yeverlibs/ds 1.0.6 → 1.0.8
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 +0 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.js +48 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -96
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import { twMerge } from 'tailwind-merge';
|
|
3
3
|
import * as React107 from 'react';
|
|
4
|
-
import React107__default, { forwardRef, createContext, useState, useEffect, memo, useCallback, useContext, useRef } from 'react';
|
|
4
|
+
import React107__default, { forwardRef, createContext, useState, useEffect, memo, useCallback, useContext, useRef, Suspense } from 'react';
|
|
5
5
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
6
6
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
7
7
|
import tw5 from 'tailwind-styled-components';
|
|
@@ -6135,26 +6135,6 @@ var Skeleton = ({ className }) => {
|
|
|
6135
6135
|
return /* @__PURE__ */ jsx("div", { className: cn("animate-pulse rounded-md bg-gray-200", className) });
|
|
6136
6136
|
};
|
|
6137
6137
|
var RESET_PAGE = 1;
|
|
6138
|
-
var defaultUpdateUrlParam = (key, value) => {
|
|
6139
|
-
if (typeof window === "undefined") return;
|
|
6140
|
-
const params = new URLSearchParams(window.location.search);
|
|
6141
|
-
if (value) {
|
|
6142
|
-
params.set(key, value);
|
|
6143
|
-
} else {
|
|
6144
|
-
params.delete(key);
|
|
6145
|
-
}
|
|
6146
|
-
const queryString = params.toString();
|
|
6147
|
-
const newUrl = queryString ? `${window.location.pathname}?${queryString}` : window.location.pathname;
|
|
6148
|
-
window.history.replaceState(null, "", newUrl);
|
|
6149
|
-
};
|
|
6150
|
-
var defaultGetUrlParam = (key, defaultValue = "") => {
|
|
6151
|
-
if (typeof window === "undefined") return defaultValue;
|
|
6152
|
-
const params = new URLSearchParams(window.location.search);
|
|
6153
|
-
const value = params.get(key);
|
|
6154
|
-
if (value === null) return defaultValue;
|
|
6155
|
-
if (typeof defaultValue === "number") return Number(value) || defaultValue;
|
|
6156
|
-
return value;
|
|
6157
|
-
};
|
|
6158
6138
|
var TableContent = ({
|
|
6159
6139
|
columns,
|
|
6160
6140
|
data,
|
|
@@ -6170,11 +6150,9 @@ var TableContent = ({
|
|
|
6170
6150
|
onPaginateAction,
|
|
6171
6151
|
noPagination,
|
|
6172
6152
|
wrapperClassName,
|
|
6173
|
-
noBackground = false
|
|
6174
|
-
getUrlParam,
|
|
6175
|
-
updateUrlParam,
|
|
6176
|
-
getPathname
|
|
6153
|
+
noBackground = false
|
|
6177
6154
|
}) => {
|
|
6155
|
+
const pathname = usePathname();
|
|
6178
6156
|
const actionMenuRef = useRef(null);
|
|
6179
6157
|
const [visibleActionRow, setVisibleActionRow] = useState(null);
|
|
6180
6158
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -6182,29 +6160,20 @@ var TableContent = ({
|
|
|
6182
6160
|
const [searchQuery, setSearchQuery] = useState("");
|
|
6183
6161
|
const [itemsPerPage, setItemsPerPage] = useState(10);
|
|
6184
6162
|
const [selectedRows, setSelectedRows] = useState(/* @__PURE__ */ new Set());
|
|
6185
|
-
const
|
|
6186
|
-
const
|
|
6187
|
-
|
|
6188
|
-
const
|
|
6189
|
-
getUrlParamValue("search", "");
|
|
6190
|
-
const handlePagination = useCallback(async () => {
|
|
6191
|
-
if (!onPaginateAction) return;
|
|
6192
|
-
setIsLoading(true);
|
|
6193
|
-
await onPaginateAction();
|
|
6194
|
-
setIsLoading(false);
|
|
6195
|
-
}, [onPaginateAction]);
|
|
6163
|
+
const searchParams = useSearchParams();
|
|
6164
|
+
const perPage = Number(searchParams?.get("perPage")) || 10;
|
|
6165
|
+
const page = Number(searchParams?.get("page")) || 1;
|
|
6166
|
+
const searchParam = searchParams?.get("search") || "";
|
|
6196
6167
|
useEffect(() => {
|
|
6197
6168
|
setCurrentPage(page);
|
|
6198
6169
|
}, [page]);
|
|
6199
6170
|
useEffect(() => {
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
if (searchParams.toString().length > 0) {
|
|
6171
|
+
const searchParams2 = new URLSearchParams(window.location.search);
|
|
6172
|
+
if (searchParams2.toString().length > 0) {
|
|
6203
6173
|
onPaginateAction?.();
|
|
6204
6174
|
}
|
|
6205
|
-
}, [
|
|
6175
|
+
}, []);
|
|
6206
6176
|
useEffect(() => {
|
|
6207
|
-
if (typeof window === "undefined") return;
|
|
6208
6177
|
const shouldReset = document.cookie.includes("reset-table-params=true");
|
|
6209
6178
|
if (shouldReset) {
|
|
6210
6179
|
document.cookie = "reset-table-params=; max-age=0; path=/";
|
|
@@ -6220,39 +6189,38 @@ var TableContent = ({
|
|
|
6220
6189
|
}
|
|
6221
6190
|
window.history.replaceState({}, "", url);
|
|
6222
6191
|
}
|
|
6223
|
-
}, []);
|
|
6192
|
+
}, [pathname]);
|
|
6224
6193
|
useEffect(() => {
|
|
6225
|
-
if (!
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6194
|
+
if (!pathname) return;
|
|
6195
|
+
if (searchParams?.has("perPage")) {
|
|
6196
|
+
setItemsPerPage(perPage);
|
|
6197
|
+
nextReplaceUrl("perPage", String(perPage), pathname);
|
|
6198
|
+
handlePagination();
|
|
6199
|
+
}
|
|
6200
|
+
if (searchParams?.has("search")) {
|
|
6201
|
+
setSearchQuery(searchParam);
|
|
6202
|
+
nextReplaceUrl("search", searchParam, pathname);
|
|
6203
|
+
handlePagination();
|
|
6204
|
+
}
|
|
6205
|
+
}, [perPage, searchParam]);
|
|
6206
|
+
const handlePagination = async () => {
|
|
6207
|
+
if (!onPaginateAction) return;
|
|
6208
|
+
setIsLoading(true);
|
|
6209
|
+
await onPaginateAction();
|
|
6210
|
+
setIsLoading(false);
|
|
6211
|
+
};
|
|
6241
6212
|
const totalPages = pagination ? Math.ceil(pagination.total / itemsPerPage) : 1;
|
|
6242
|
-
const paginatedData = data
|
|
6213
|
+
const paginatedData = data;
|
|
6243
6214
|
const visibleColumns = columns.filter((column) => !hiddenColumns.includes(column.accessor));
|
|
6244
6215
|
const headersWithContent = visibleColumns.filter((column) => column.Header);
|
|
6245
|
-
if (visibleColumns.length === 0 && columns.length > 0) {
|
|
6246
|
-
console.warn("Table: Todas as colunas est\xE3o ocultas. Verifique a prop hiddenColumns.");
|
|
6247
|
-
}
|
|
6248
6216
|
const handleSearch = (e) => {
|
|
6249
6217
|
setSearchQuery(e.target.value);
|
|
6250
6218
|
};
|
|
6251
6219
|
const handleSearchSubmit = () => {
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6220
|
+
if (!pathname) return;
|
|
6221
|
+
Promise.all([nextReplaceUrl("search", searchQuery, pathname), nextReplaceUrl("page", "1", pathname)]).then(() => {
|
|
6222
|
+
handlePagination();
|
|
6223
|
+
});
|
|
6256
6224
|
};
|
|
6257
6225
|
const handleClickOutside = useCallback((event) => {
|
|
6258
6226
|
if (actionMenuRef.current && !actionMenuRef.current.contains(event.target)) {
|
|
@@ -6307,7 +6275,7 @@ var TableContent = ({
|
|
|
6307
6275
|
return cellValue;
|
|
6308
6276
|
}
|
|
6309
6277
|
};
|
|
6310
|
-
return isLink && linkHref ? /* @__PURE__ */ jsx(
|
|
6278
|
+
return isLink && linkHref ? /* @__PURE__ */ jsx(Link2, { href: linkHref, children: content() }) : content();
|
|
6311
6279
|
};
|
|
6312
6280
|
if (isLoading) {
|
|
6313
6281
|
return /* @__PURE__ */ jsxs(
|
|
@@ -6411,7 +6379,7 @@ var TableContent = ({
|
|
|
6411
6379
|
onChange: handleSelectAllRows
|
|
6412
6380
|
}
|
|
6413
6381
|
) }),
|
|
6414
|
-
headersWithContent.length === 1
|
|
6382
|
+
headersWithContent.length === 1 ? /* @__PURE__ */ jsx(
|
|
6415
6383
|
"th",
|
|
6416
6384
|
{
|
|
6417
6385
|
colSpan: visibleColumns.length,
|
|
@@ -6425,10 +6393,10 @@ var TableContent = ({
|
|
|
6425
6393
|
style: { minWidth: columnWidths[index] },
|
|
6426
6394
|
children: column.Header ?? ""
|
|
6427
6395
|
},
|
|
6428
|
-
column.id ||
|
|
6396
|
+
column.id || index
|
|
6429
6397
|
))
|
|
6430
6398
|
] }) }),
|
|
6431
|
-
/* @__PURE__ */ jsx("tbody", { children: paginatedData
|
|
6399
|
+
/* @__PURE__ */ jsx("tbody", { children: paginatedData?.length > 0 ? paginatedData?.map((row, rowIndex) => /* @__PURE__ */ jsxs(
|
|
6432
6400
|
"tr",
|
|
6433
6401
|
{
|
|
6434
6402
|
className: cn(
|
|
@@ -6487,18 +6455,15 @@ var TableContent = ({
|
|
|
6487
6455
|
]
|
|
6488
6456
|
},
|
|
6489
6457
|
rowIndex
|
|
6490
|
-
)) : /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan:
|
|
6458
|
+
)) : /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columns.length + (selectable ? 1 : 0), style: { textAlign: "center" }, children: /* @__PURE__ */ jsxs("div", { className: "py-6", children: [
|
|
6491
6459
|
/* @__PURE__ */ jsx(
|
|
6492
|
-
|
|
6460
|
+
Image4,
|
|
6493
6461
|
{
|
|
6494
6462
|
src: "/empty-table.svg",
|
|
6495
6463
|
width: 666,
|
|
6496
6464
|
height: 329,
|
|
6497
6465
|
alt: "Nenhum resultado encontrado",
|
|
6498
|
-
className: "mx-auto"
|
|
6499
|
-
onError: (e) => {
|
|
6500
|
-
e.currentTarget.style.display = "none";
|
|
6501
|
-
}
|
|
6466
|
+
className: "mx-auto"
|
|
6502
6467
|
}
|
|
6503
6468
|
),
|
|
6504
6469
|
/* @__PURE__ */ jsxs("div", { className: "mt-8", children: [
|
|
@@ -6529,12 +6494,16 @@ var TableContent = ({
|
|
|
6529
6494
|
{
|
|
6530
6495
|
value: itemsPerPage,
|
|
6531
6496
|
onChange: async (e) => {
|
|
6497
|
+
if (!pathname) return;
|
|
6532
6498
|
const newPerPage = Number(e.target.value);
|
|
6533
6499
|
setItemsPerPage(newPerPage);
|
|
6534
6500
|
setCurrentPage(RESET_PAGE);
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6501
|
+
Promise.all([
|
|
6502
|
+
nextReplaceUrl("page", "1", pathname),
|
|
6503
|
+
nextReplaceUrl("perPage", String(newPerPage), pathname)
|
|
6504
|
+
]).then(() => {
|
|
6505
|
+
handlePagination();
|
|
6506
|
+
});
|
|
6538
6507
|
},
|
|
6539
6508
|
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",
|
|
6540
6509
|
children: [
|
|
@@ -6564,23 +6533,7 @@ var TableContent = ({
|
|
|
6564
6533
|
] }) });
|
|
6565
6534
|
};
|
|
6566
6535
|
var Table = (props) => {
|
|
6567
|
-
|
|
6568
|
-
return /* @__PURE__ */ jsx(
|
|
6569
|
-
Box,
|
|
6570
|
-
{
|
|
6571
|
-
className: cn(
|
|
6572
|
-
"flex flex-col overflow-hidden",
|
|
6573
|
-
props.wrapperClassName,
|
|
6574
|
-
props.noBackground ? "bg-transparent border-none p-0" : ""
|
|
6575
|
-
),
|
|
6576
|
-
children: /* @__PURE__ */ jsx("div", { className: "p-6", children: /* @__PURE__ */ jsx(Text, { $as: "p", children: "Nenhuma coluna definida para a tabela." }) })
|
|
6577
|
-
}
|
|
6578
|
-
);
|
|
6579
|
-
}
|
|
6580
|
-
if (!props.data) {
|
|
6581
|
-
console.warn('Table: A prop "data" n\xE3o foi fornecida ou \xE9 undefined.');
|
|
6582
|
-
}
|
|
6583
|
-
return /* @__PURE__ */ jsx(TableContent, { ...props });
|
|
6536
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(TableContent, { ...props }) });
|
|
6584
6537
|
};
|
|
6585
6538
|
var Tabs = ({ headers, children, noGap, active, alignDiv = "full" }) => {
|
|
6586
6539
|
const [activeTab, setActiveTab] = useState(active || 0);
|