@dust-tt/sparkle 0.2.225 → 0.2.226
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/cjs/index.js +283 -113
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/DataTable.d.ts +5 -2
- package/dist/esm/components/DataTable.d.ts.map +1 -1
- package/dist/esm/components/DataTable.js +48 -29
- package/dist/esm/components/DataTable.js.map +1 -1
- package/dist/esm/components/PaginatedCitationsGrid.d.ts.map +1 -1
- package/dist/esm/components/PaginatedCitationsGrid.js +8 -4
- package/dist/esm/components/PaginatedCitationsGrid.js.map +1 -1
- package/dist/esm/components/Pagination.d.ts +5 -4
- package/dist/esm/components/Pagination.d.ts.map +1 -1
- package/dist/esm/components/Pagination.js +35 -35
- package/dist/esm/components/Pagination.js.map +1 -1
- package/dist/esm/hooks/index.d.ts +3 -0
- package/dist/esm/hooks/index.d.ts.map +1 -0
- package/dist/esm/hooks/index.js +3 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/hooks/useHashParams.d.ts +18 -0
- package/dist/esm/hooks/useHashParams.d.ts.map +1 -0
- package/dist/esm/hooks/useHashParams.js +67 -0
- package/dist/esm/hooks/useHashParams.js.map +1 -0
- package/dist/esm/hooks/usePaginationFromUrl.d.ts +6 -0
- package/dist/esm/hooks/usePaginationFromUrl.d.ts.map +1 -0
- package/dist/esm/hooks/usePaginationFromUrl.js +23 -0
- package/dist/esm/hooks/usePaginationFromUrl.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/stories/DataTable.stories.d.ts +2 -0
- package/dist/esm/stories/DataTable.stories.d.ts.map +1 -1
- package/dist/esm/stories/DataTable.stories.js +133 -106
- package/dist/esm/stories/DataTable.stories.js.map +1 -1
- package/dist/esm/stories/Pagination.stories.d.ts +1 -0
- package/dist/esm/stories/Pagination.stories.d.ts.map +1 -1
- package/dist/esm/stories/Pagination.stories.js +25 -3
- package/dist/esm/stories/Pagination.stories.js.map +1 -1
- package/dist/sparkle.css +4 -0
- package/package.json +1 -1
- package/src/components/DataTable.tsx +114 -75
- package/src/components/PaginatedCitationsGrid.tsx +11 -6
- package/src/components/Pagination.tsx +48 -45
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useHashParams.ts +95 -0
- package/src/hooks/usePaginationFromUrl.ts +36 -0
- package/src/index.ts +1 -0
- package/src/stories/DataTable.stories.tsx +200 -130
- package/src/stories/Pagination.stories.tsx +38 -10
package/dist/cjs/index.js
CHANGED
|
@@ -101681,10 +101681,10 @@ const RowExpanding = {
|
|
|
101681
101681
|
//
|
|
101682
101682
|
|
|
101683
101683
|
const defaultPageIndex = 0;
|
|
101684
|
-
const defaultPageSize = 10;
|
|
101684
|
+
const defaultPageSize$1 = 10;
|
|
101685
101685
|
const getDefaultPaginationState = () => ({
|
|
101686
101686
|
pageIndex: defaultPageIndex,
|
|
101687
|
-
pageSize: defaultPageSize
|
|
101687
|
+
pageSize: defaultPageSize$1
|
|
101688
101688
|
});
|
|
101689
101689
|
const RowPagination = {
|
|
101690
101690
|
getInitialState: state => {
|
|
@@ -101749,7 +101749,7 @@ const RowPagination = {
|
|
|
101749
101749
|
};
|
|
101750
101750
|
table.resetPageSize = defaultState => {
|
|
101751
101751
|
var _table$initialState$p3, _table$initialState2;
|
|
101752
|
-
table.setPageSize(defaultState ? defaultPageSize : (_table$initialState$p3 = (_table$initialState2 = table.initialState) == null || (_table$initialState2 = _table$initialState2.pagination) == null ? void 0 : _table$initialState2.pageSize) != null ? _table$initialState$p3 : defaultPageSize);
|
|
101752
|
+
table.setPageSize(defaultState ? defaultPageSize$1 : (_table$initialState$p3 = (_table$initialState2 = table.initialState) == null || (_table$initialState2 = _table$initialState2.pagination) == null ? void 0 : _table$initialState2.pageSize) != null ? _table$initialState$p3 : defaultPageSize$1);
|
|
101753
101753
|
};
|
|
101754
101754
|
table.setPageSize = updater => {
|
|
101755
101755
|
table.setPagination(old => {
|
|
@@ -102873,6 +102873,22 @@ function getCoreRowModel() {
|
|
|
102873
102873
|
return rowModel;
|
|
102874
102874
|
}, getMemoOptions(table.options, 'debugTable', 'getRowModel', () => table._autoResetPageIndex()));
|
|
102875
102875
|
}
|
|
102876
|
+
function expandRows(rowModel) {
|
|
102877
|
+
const expandedRows = [];
|
|
102878
|
+
const handleRow = row => {
|
|
102879
|
+
var _row$subRows;
|
|
102880
|
+
expandedRows.push(row);
|
|
102881
|
+
if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
|
|
102882
|
+
row.subRows.forEach(handleRow);
|
|
102883
|
+
}
|
|
102884
|
+
};
|
|
102885
|
+
rowModel.rows.forEach(handleRow);
|
|
102886
|
+
return {
|
|
102887
|
+
rows: expandedRows,
|
|
102888
|
+
flatRows: rowModel.flatRows,
|
|
102889
|
+
rowsById: rowModel.rowsById
|
|
102890
|
+
};
|
|
102891
|
+
}
|
|
102876
102892
|
|
|
102877
102893
|
function filterRows(rows, filterRowImpl, table) {
|
|
102878
102894
|
if (table.options.filterFromLeafRows) {
|
|
@@ -103063,6 +103079,49 @@ function getFilteredRowModel() {
|
|
|
103063
103079
|
}, getMemoOptions(table.options, 'debugTable', 'getFilteredRowModel', () => table._autoResetPageIndex()));
|
|
103064
103080
|
}
|
|
103065
103081
|
|
|
103082
|
+
function getPaginationRowModel(opts) {
|
|
103083
|
+
return table => memo(() => [table.getState().pagination, table.getPrePaginationRowModel(), table.options.paginateExpandedRows ? undefined : table.getState().expanded], (pagination, rowModel) => {
|
|
103084
|
+
if (!rowModel.rows.length) {
|
|
103085
|
+
return rowModel;
|
|
103086
|
+
}
|
|
103087
|
+
const {
|
|
103088
|
+
pageSize,
|
|
103089
|
+
pageIndex
|
|
103090
|
+
} = pagination;
|
|
103091
|
+
let {
|
|
103092
|
+
rows,
|
|
103093
|
+
flatRows,
|
|
103094
|
+
rowsById
|
|
103095
|
+
} = rowModel;
|
|
103096
|
+
const pageStart = pageSize * pageIndex;
|
|
103097
|
+
const pageEnd = pageStart + pageSize;
|
|
103098
|
+
rows = rows.slice(pageStart, pageEnd);
|
|
103099
|
+
let paginatedRowModel;
|
|
103100
|
+
if (!table.options.paginateExpandedRows) {
|
|
103101
|
+
paginatedRowModel = expandRows({
|
|
103102
|
+
rows,
|
|
103103
|
+
flatRows,
|
|
103104
|
+
rowsById
|
|
103105
|
+
});
|
|
103106
|
+
} else {
|
|
103107
|
+
paginatedRowModel = {
|
|
103108
|
+
rows,
|
|
103109
|
+
flatRows,
|
|
103110
|
+
rowsById
|
|
103111
|
+
};
|
|
103112
|
+
}
|
|
103113
|
+
paginatedRowModel.flatRows = [];
|
|
103114
|
+
const handleRow = row => {
|
|
103115
|
+
paginatedRowModel.flatRows.push(row);
|
|
103116
|
+
if (row.subRows.length) {
|
|
103117
|
+
row.subRows.forEach(handleRow);
|
|
103118
|
+
}
|
|
103119
|
+
};
|
|
103120
|
+
paginatedRowModel.rows.forEach(handleRow);
|
|
103121
|
+
return paginatedRowModel;
|
|
103122
|
+
}, getMemoOptions(table.options, 'debugTable', 'getPaginationRowModel'));
|
|
103123
|
+
}
|
|
103124
|
+
|
|
103066
103125
|
function getSortedRowModel() {
|
|
103067
103126
|
return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
|
|
103068
103127
|
if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
|
|
@@ -103218,6 +103277,86 @@ function useReactTable(options) {
|
|
|
103218
103277
|
return tableRef.current;
|
|
103219
103278
|
}
|
|
103220
103279
|
|
|
103280
|
+
var pagesShownInControls = 7;
|
|
103281
|
+
function Pagination(_a) {
|
|
103282
|
+
var _b = _a.size, size = _b === void 0 ? "sm" : _b, _c = _a.showDetails, showDetails = _c === void 0 ? true : _c, _d = _a.showPageButtons, showPageButtons = _d === void 0 ? true : _d, rowCount = _a.rowCount, pagination = _a.pagination, setPagination = _a.setPagination;
|
|
103283
|
+
// pageIndex is 0-based
|
|
103284
|
+
var pageIndex = pagination.pageIndex, pageSize = pagination.pageSize;
|
|
103285
|
+
var numPages = Math.ceil(rowCount / pageSize);
|
|
103286
|
+
var canNextPage = pagination.pageIndex < numPages - 1;
|
|
103287
|
+
var canPreviousPage = pageIndex > 0;
|
|
103288
|
+
var nextPage = function () { return setPagination({ pageSize: pageSize, pageIndex: pageIndex + 1 }); };
|
|
103289
|
+
var previousPage = function () {
|
|
103290
|
+
return setPagination({ pageSize: pageSize, pageIndex: pageIndex - 1 });
|
|
103291
|
+
};
|
|
103292
|
+
var controlsAreHidden = Boolean(numPages <= 1);
|
|
103293
|
+
var firstItemOnPageIndex = pageIndex * pageSize + 1;
|
|
103294
|
+
var lastItemOnPageIndex = rowCount > (pageIndex + 1) * pageSize
|
|
103295
|
+
? (pageIndex + 1) * pageSize
|
|
103296
|
+
: rowCount;
|
|
103297
|
+
var onPaginationButtonClick = React.useCallback(function (pageIndex) {
|
|
103298
|
+
setPagination({ pageSize: pageSize, pageIndex: pageIndex });
|
|
103299
|
+
}, [pageIndex, setPagination]);
|
|
103300
|
+
var pageButtons = getPageButtons(pageIndex, numPages, pagesShownInControls, onPaginationButtonClick, size);
|
|
103301
|
+
return (React.createElement("div", { className: classNames("s-flex s-w-full s-items-center", controlsAreHidden ? "s-justify-end" : "s-justify-between") },
|
|
103302
|
+
React.createElement("div", { className: classNames("s-flex", controlsAreHidden ? "s-invisible" : "s-visible", showPageButtons ? "s-gap-0" : "s-gap-2") },
|
|
103303
|
+
React.createElement(Button, { variant: "tertiary", size: size === "xs" ? "xs" : "sm", label: "previous", labelVisible: false, disabledTooltip: true, disabled: !canPreviousPage, icon: SvgChevronLeft$1, onClick: previousPage }),
|
|
103304
|
+
React.createElement("div", { className: classNames("s-items-center", size === "xs" ? "s-gap-3 s-px-3" : "s-gap-4 s-px-4", showPageButtons ? "s-flex" : "s-hidden") }, pageButtons),
|
|
103305
|
+
React.createElement(Button, { variant: "tertiary", size: size === "xs" ? "xs" : "sm", label: "next", labelVisible: false, disabledTooltip: true, disabled: !canNextPage, icon: SvgChevronRight$1, onClick: nextPage })),
|
|
103306
|
+
React.createElement("span", { className: classNames("s-text-slate-400", size === "xs" ? "s-text-xs" : "s-text-sm", showDetails ? "s-visible" : "s-collapse") }, controlsAreHidden
|
|
103307
|
+
? "".concat(rowCount, " items")
|
|
103308
|
+
: "Showing ".concat(firstItemOnPageIndex, "-").concat(lastItemOnPageIndex, " of ").concat(rowCount, " items"))));
|
|
103309
|
+
}
|
|
103310
|
+
function renderPageNumber(pageNumber, currentPage, onPageClick, size) {
|
|
103311
|
+
return (React.createElement("button", { key: pageNumber, className: classNames("s-font-semibold s-transition-colors s-duration-100", currentPage === pageNumber ? "s-text-action-500" : "s-text-slate-400", size === "xs" ? "s-text-xs" : "s-text-sm"), onClick: function () { return onPageClick(pageNumber); } }, pageNumber + 1));
|
|
103312
|
+
}
|
|
103313
|
+
function renderEllipses(size) {
|
|
103314
|
+
return (React.createElement("span", { className: classNames("s-text-sm s-font-semibold s-text-slate-400", size === "xs" ? "s-text-xs" : "s-text-sm") }, "..."));
|
|
103315
|
+
}
|
|
103316
|
+
function getPageButtons(currentPage, totalPages, slots, onPageClick, size) {
|
|
103317
|
+
var pagination = [];
|
|
103318
|
+
// If total pages are less than or equal to slots, show all pages
|
|
103319
|
+
if (totalPages <= slots) {
|
|
103320
|
+
for (var i = 0; i < totalPages; i++) {
|
|
103321
|
+
pagination.push(renderPageNumber(i, currentPage, onPageClick, size));
|
|
103322
|
+
}
|
|
103323
|
+
return pagination;
|
|
103324
|
+
}
|
|
103325
|
+
var remainingSlots = slots - 2; // slots excluding first and last page
|
|
103326
|
+
var halfSlots = Math.floor(remainingSlots / 2);
|
|
103327
|
+
// Ensure current page is within bounds
|
|
103328
|
+
currentPage = Math.max(0, Math.min(currentPage, totalPages - 1));
|
|
103329
|
+
pagination.push(renderPageNumber(0, currentPage, onPageClick, size)); // Always show the first page
|
|
103330
|
+
// Determine the range of pages to display
|
|
103331
|
+
var start, end;
|
|
103332
|
+
if (currentPage <= halfSlots + 1) {
|
|
103333
|
+
start = 1;
|
|
103334
|
+
end = remainingSlots - 1;
|
|
103335
|
+
}
|
|
103336
|
+
else if (currentPage >= totalPages - halfSlots - 2) {
|
|
103337
|
+
start = totalPages - remainingSlots;
|
|
103338
|
+
end = totalPages - 2;
|
|
103339
|
+
}
|
|
103340
|
+
else {
|
|
103341
|
+
start = currentPage - halfSlots + 1;
|
|
103342
|
+
end = currentPage + halfSlots - 1;
|
|
103343
|
+
}
|
|
103344
|
+
// Add ellipsis if there is a gap between the first page and the start of the range
|
|
103345
|
+
if (start > 1) {
|
|
103346
|
+
pagination.push(renderEllipses(size));
|
|
103347
|
+
}
|
|
103348
|
+
// Add the range of pages
|
|
103349
|
+
for (var i = start; i <= end; i++) {
|
|
103350
|
+
pagination.push(renderPageNumber(i, currentPage, onPageClick, size));
|
|
103351
|
+
}
|
|
103352
|
+
// Add ellipsis if there is a gap between the end of the range and the last page
|
|
103353
|
+
if (end < totalPages - 2) {
|
|
103354
|
+
pagination.push(renderEllipses(size));
|
|
103355
|
+
}
|
|
103356
|
+
pagination.push(renderPageNumber(totalPages - 1, currentPage, onPageClick, size)); // Always show the last page
|
|
103357
|
+
return pagination;
|
|
103358
|
+
}
|
|
103359
|
+
|
|
103221
103360
|
// Define breakpoints
|
|
103222
103361
|
var breakpoints = {
|
|
103223
103362
|
xs: 0,
|
|
@@ -103276,22 +103415,37 @@ function shouldRenderColumn(windowWidth, breakpoint) {
|
|
|
103276
103415
|
return windowWidth >= breakpoints[breakpoint];
|
|
103277
103416
|
}
|
|
103278
103417
|
function DataTable(_a) {
|
|
103279
|
-
var data = _a.data, columns = _a.columns, className = _a.className, filter = _a.filter, filterColumn = _a.filterColumn, initialColumnOrder = _a.initialColumnOrder, _b = _a.columnsBreakpoints, columnsBreakpoints = _b === void 0 ? {} : _b;
|
|
103418
|
+
var data = _a.data, totalRowCount = _a.totalRowCount, columns = _a.columns, className = _a.className, filter = _a.filter, filterColumn = _a.filterColumn, initialColumnOrder = _a.initialColumnOrder, _b = _a.columnsBreakpoints, columnsBreakpoints = _b === void 0 ? {} : _b, pagination = _a.pagination, setPagination = _a.setPagination;
|
|
103280
103419
|
var windowSize = useWindowSize();
|
|
103281
103420
|
var _c = __read(React.useState(initialColumnOrder !== null && initialColumnOrder !== void 0 ? initialColumnOrder : []), 2), sorting = _c[0], setSorting = _c[1];
|
|
103282
103421
|
var _d = __read(React.useState([]), 2), columnFilters = _d[0], setColumnFilters = _d[1];
|
|
103422
|
+
var isServerSidePagination = !!totalRowCount && totalRowCount > data.length;
|
|
103423
|
+
var onPaginationChange = pagination && setPagination
|
|
103424
|
+
? function (updater) {
|
|
103425
|
+
var newValue = typeof updater === "function" ? updater(pagination) : updater;
|
|
103426
|
+
setPagination(newValue);
|
|
103427
|
+
}
|
|
103428
|
+
: undefined;
|
|
103283
103429
|
var table = useReactTable({
|
|
103284
103430
|
data: data,
|
|
103285
103431
|
columns: columns,
|
|
103432
|
+
rowCount: totalRowCount,
|
|
103433
|
+
manualPagination: isServerSidePagination,
|
|
103286
103434
|
onSortingChange: setSorting,
|
|
103287
103435
|
getCoreRowModel: getCoreRowModel(),
|
|
103288
103436
|
getSortedRowModel: getSortedRowModel(),
|
|
103289
103437
|
getFilteredRowModel: getFilteredRowModel(),
|
|
103438
|
+
getPaginationRowModel: pagination ? getPaginationRowModel() : undefined,
|
|
103290
103439
|
onColumnFiltersChange: setColumnFilters,
|
|
103291
103440
|
state: {
|
|
103292
103441
|
columnFilters: columnFilters,
|
|
103293
|
-
sorting: sorting,
|
|
103442
|
+
sorting: isServerSidePagination ? undefined : sorting,
|
|
103443
|
+
pagination: pagination,
|
|
103294
103444
|
},
|
|
103445
|
+
initialState: {
|
|
103446
|
+
pagination: pagination,
|
|
103447
|
+
},
|
|
103448
|
+
onPaginationChange: onPaginationChange,
|
|
103295
103449
|
});
|
|
103296
103450
|
React.useEffect(function () {
|
|
103297
103451
|
var _a;
|
|
@@ -103299,32 +103453,35 @@ function DataTable(_a) {
|
|
|
103299
103453
|
(_a = table.getColumn(filterColumn)) === null || _a === void 0 ? void 0 : _a.setFilterValue(filter);
|
|
103300
103454
|
}
|
|
103301
103455
|
}, [filter, filterColumn]);
|
|
103302
|
-
return (React.createElement(
|
|
103303
|
-
React.createElement(DataTable.
|
|
103304
|
-
|
|
103305
|
-
|
|
103306
|
-
!
|
|
103307
|
-
|
|
103308
|
-
|
|
103309
|
-
|
|
103310
|
-
React.createElement(
|
|
103311
|
-
|
|
103312
|
-
|
|
103313
|
-
|
|
103314
|
-
|
|
103315
|
-
|
|
103316
|
-
|
|
103317
|
-
|
|
103318
|
-
|
|
103319
|
-
|
|
103320
|
-
|
|
103321
|
-
|
|
103322
|
-
|
|
103323
|
-
!
|
|
103324
|
-
|
|
103325
|
-
|
|
103326
|
-
|
|
103327
|
-
|
|
103456
|
+
return (React.createElement("div", { className: "s-flex s-flex-col s-gap-2" },
|
|
103457
|
+
React.createElement(DataTable.Root, { className: className },
|
|
103458
|
+
React.createElement(DataTable.Header, null, table.getHeaderGroups().map(function (headerGroup) { return (React.createElement(DataTable.Row, { key: headerGroup.id }, headerGroup.headers.map(function (header) {
|
|
103459
|
+
var breakpoint = columnsBreakpoints[header.id];
|
|
103460
|
+
if (!windowSize.width ||
|
|
103461
|
+
!shouldRenderColumn(windowSize.width, breakpoint)) {
|
|
103462
|
+
return null;
|
|
103463
|
+
}
|
|
103464
|
+
return (React.createElement(DataTable.Head, { key: header.id, onClick: header.column.getToggleSortingHandler(), className: classNames(header.column.getCanSort() ? "s-cursor-pointer" : "") },
|
|
103465
|
+
React.createElement("div", { className: "s-flex s-items-center s-space-x-1 s-whitespace-nowrap" },
|
|
103466
|
+
flexRender(header.column.columnDef.header, header.getContext()),
|
|
103467
|
+
header.column.getCanSort() && (React.createElement(Icon, { visual: header.column.getIsSorted() === "asc"
|
|
103468
|
+
? SvgArrowUp$1
|
|
103469
|
+
: header.column.getIsSorted() === "desc"
|
|
103470
|
+
? SvgArrowDown$1
|
|
103471
|
+
: SvgArrowDown$1, size: "xs", className: classNames("s-ml-1", header.column.getIsSorted()
|
|
103472
|
+
? "s-opacity-100"
|
|
103473
|
+
: "s-opacity-0") })))));
|
|
103474
|
+
}))); })),
|
|
103475
|
+
React.createElement(DataTable.Body, null, table.getRowModel().rows.map(function (row) { return (React.createElement(DataTable.Row, { key: row.id, onClick: row.original.onClick, moreMenuItems: row.original.moreMenuItems }, row.getVisibleCells().map(function (cell) {
|
|
103476
|
+
var breakpoint = columnsBreakpoints[cell.column.id];
|
|
103477
|
+
if (!windowSize.width ||
|
|
103478
|
+
!shouldRenderColumn(windowSize.width, breakpoint)) {
|
|
103479
|
+
return null;
|
|
103480
|
+
}
|
|
103481
|
+
return (React.createElement(DataTable.Cell, { key: cell.id }, flexRender(cell.column.columnDef.cell, cell.getContext())));
|
|
103482
|
+
}))); }))),
|
|
103483
|
+
pagination && (React.createElement("div", { className: "s-p-1" },
|
|
103484
|
+
React.createElement(Pagination, { pagination: table.getState().pagination, setPagination: table.setPagination, rowCount: table.getRowCount() })))));
|
|
103328
103485
|
}
|
|
103329
103486
|
DataTable.Root = function DataTableRoot(_a) {
|
|
103330
103487
|
var children = _a.children, className = _a.className, props = __rest(_a, ["children", "className"]);
|
|
@@ -128626,102 +128783,28 @@ Page.Fluid = function (_a) {
|
|
|
128626
128783
|
return (React.createElement("div", { className: classNames("s-flex s-flex-wrap", sizing === "grow" ? "s-grow" : "", sizing === "shrink" ? "s-shrink" : "", gapSizes[gap], align === "left" ? "s-items-start" : "", align === "center" ? "s-items-center" : "", align === "right" ? "s-items-end" : "") }, children));
|
|
128627
128784
|
};
|
|
128628
128785
|
|
|
128629
|
-
var pagesShownInControls = 7;
|
|
128630
|
-
function Pagination(_a) {
|
|
128631
|
-
var itemsCount = _a.itemsCount, maxItemsPerPage = _a.maxItemsPerPage, onButtonClick = _a.onButtonClick, _b = _a.size, size = _b === void 0 ? "sm" : _b, _c = _a.showDetails, showDetails = _c === void 0 ? true : _c, _d = _a.showPageButtons, showPageButtons = _d === void 0 ? true : _d;
|
|
128632
|
-
var numPages = Math.ceil(itemsCount / maxItemsPerPage);
|
|
128633
|
-
var controlsAreHidden = Boolean(numPages <= 1);
|
|
128634
|
-
var _e = __read(React.useState(1), 2), currentPage = _e[0], setCurrentPage = _e[1];
|
|
128635
|
-
var firstFileOnPageIndex = currentPage * maxItemsPerPage - maxItemsPerPage + 1;
|
|
128636
|
-
var lastFileOnPageIndex = itemsCount > currentPage * maxItemsPerPage
|
|
128637
|
-
? currentPage * maxItemsPerPage
|
|
128638
|
-
: itemsCount;
|
|
128639
|
-
var onPaginationButtonClick = React.useCallback(function (pageNb) {
|
|
128640
|
-
setCurrentPage(pageNb);
|
|
128641
|
-
onButtonClick(pageNb);
|
|
128642
|
-
}, [onButtonClick, setCurrentPage]);
|
|
128643
|
-
var pageButtons = getPageButtons(currentPage, numPages, pagesShownInControls, onPaginationButtonClick, size);
|
|
128644
|
-
return (React.createElement("div", { className: classNames("s-flex s-w-full s-items-center", controlsAreHidden ? "s-justify-end" : "s-justify-between") },
|
|
128645
|
-
React.createElement("div", { className: classNames("s-flex", controlsAreHidden ? "s-invisible" : "s-visible", showPageButtons ? "s-gap-0" : "s-gap-2") },
|
|
128646
|
-
React.createElement(Button, { variant: "tertiary", size: size === "xs" ? "xs" : "sm", label: "previous", labelVisible: false, disabledTooltip: true, disabled: currentPage === 1 ? true : false, icon: SvgChevronLeft$1, onClick: function () {
|
|
128647
|
-
onPaginationButtonClick(currentPage - 1);
|
|
128648
|
-
} }),
|
|
128649
|
-
React.createElement("div", { className: classNames("s-items-center", size === "xs" ? "s-gap-3 s-px-3" : "s-gap-4 s-px-4", showPageButtons ? "s-flex" : "s-hidden") }, pageButtons),
|
|
128650
|
-
React.createElement(Button, { variant: "tertiary", size: size === "xs" ? "xs" : "sm", label: "next", labelVisible: false, disabledTooltip: true, disabled: currentPage === numPages ? true : false, icon: SvgChevronRight$1, onClick: function () {
|
|
128651
|
-
onPaginationButtonClick(currentPage + 1);
|
|
128652
|
-
} })),
|
|
128653
|
-
React.createElement("span", { className: classNames("s-text-slate-400", size === "xs" ? "s-text-xs" : "s-text-sm", showDetails ? "s-visible" : "s-collapse") }, controlsAreHidden
|
|
128654
|
-
? "".concat(itemsCount, " items")
|
|
128655
|
-
: "Showing ".concat(firstFileOnPageIndex, "-").concat(lastFileOnPageIndex, " of ").concat(itemsCount, " items"))));
|
|
128656
|
-
}
|
|
128657
|
-
function renderPageNumber(pageNumber, currentPage, onPageClick, size) {
|
|
128658
|
-
return (React.createElement("button", { key: pageNumber, className: classNames("s-font-semibold s-transition-colors s-duration-100", currentPage === pageNumber ? "s-text-action-500" : "s-text-slate-400", size === "xs" ? "s-text-xs" : "s-text-sm"), onClick: function () { return onPageClick(pageNumber); } }, pageNumber));
|
|
128659
|
-
}
|
|
128660
|
-
function renderEllipses(size) {
|
|
128661
|
-
return (React.createElement("span", { className: classNames("s-text-sm s-font-semibold s-text-slate-400", size === "xs" ? "s-text-xs" : "s-text-sm") }, "..."));
|
|
128662
|
-
}
|
|
128663
|
-
function getPageButtons(currentPage, totalPages, slots, onPageClick, size) {
|
|
128664
|
-
var pagination = [];
|
|
128665
|
-
// If total pages are less than or equal to slots, show all pages
|
|
128666
|
-
if (totalPages <= slots) {
|
|
128667
|
-
for (var i = 1; i <= totalPages; i++) {
|
|
128668
|
-
pagination.push(renderPageNumber(i, currentPage, onPageClick, size));
|
|
128669
|
-
}
|
|
128670
|
-
return pagination;
|
|
128671
|
-
}
|
|
128672
|
-
var remainingSlots = slots - 2; // slots excluding first and last page
|
|
128673
|
-
var halfSlots = Math.floor(remainingSlots / 2);
|
|
128674
|
-
// Ensure current page is within bounds
|
|
128675
|
-
currentPage = Math.max(1, Math.min(currentPage, totalPages));
|
|
128676
|
-
pagination.push(renderPageNumber(1, currentPage, onPageClick, size)); // Always show the first page
|
|
128677
|
-
// Determine the range of pages to display
|
|
128678
|
-
var start, end;
|
|
128679
|
-
if (currentPage <= halfSlots + 2) {
|
|
128680
|
-
start = 2;
|
|
128681
|
-
end = remainingSlots;
|
|
128682
|
-
}
|
|
128683
|
-
else if (currentPage >= totalPages - halfSlots - 1) {
|
|
128684
|
-
start = totalPages - remainingSlots + 1;
|
|
128685
|
-
end = totalPages - 1;
|
|
128686
|
-
}
|
|
128687
|
-
else {
|
|
128688
|
-
start = currentPage - halfSlots + 1;
|
|
128689
|
-
end = currentPage + halfSlots - 1;
|
|
128690
|
-
}
|
|
128691
|
-
// Add ellipsis if there is a gap between the first page and the start of the range
|
|
128692
|
-
if (start > 2) {
|
|
128693
|
-
pagination.push(renderEllipses(size));
|
|
128694
|
-
}
|
|
128695
|
-
// Add the range of pages
|
|
128696
|
-
for (var i = start; i <= end; i++) {
|
|
128697
|
-
pagination.push(renderPageNumber(i, currentPage, onPageClick, size));
|
|
128698
|
-
}
|
|
128699
|
-
// Add ellipsis if there is a gap between the end of the range and the last page
|
|
128700
|
-
if (end < totalPages - 1) {
|
|
128701
|
-
pagination.push(renderEllipses(size));
|
|
128702
|
-
}
|
|
128703
|
-
pagination.push(renderPageNumber(totalPages, currentPage, onPageClick, size)); // Always show the last page
|
|
128704
|
-
return pagination;
|
|
128705
|
-
}
|
|
128706
|
-
|
|
128707
128786
|
function PaginatedCitationsGrid(_a) {
|
|
128708
128787
|
var items = _a.items, _b = _a.maxItemsPerPage, maxItemsPerPage = _b === void 0 ? 9 : _b;
|
|
128709
|
-
var _c = __read(React.useState(
|
|
128788
|
+
var _c = __read(React.useState({
|
|
128789
|
+
pageIndex: 0,
|
|
128790
|
+
pageSize: maxItemsPerPage,
|
|
128791
|
+
}), 2), pagination = _c[0], setPagination = _c[1];
|
|
128710
128792
|
var cols = 3;
|
|
128711
128793
|
var rows = Math.ceil(Math.min(maxItemsPerPage, items.length) / cols);
|
|
128712
128794
|
if (items.length === 0) {
|
|
128713
128795
|
return null;
|
|
128714
128796
|
}
|
|
128797
|
+
var pageIndex = pagination.pageIndex, pageSize = pagination.pageSize;
|
|
128715
128798
|
// Calculate start index.
|
|
128716
|
-
var startIndex =
|
|
128799
|
+
var startIndex = pageIndex * pageSize;
|
|
128717
128800
|
// Slice items for current page.
|
|
128718
|
-
var paginatedItems = items.slice(startIndex, startIndex +
|
|
128801
|
+
var paginatedItems = items.slice(startIndex, startIndex + pageSize);
|
|
128719
128802
|
return (React.createElement("div", { className: "s-flex s-w-full s-flex-col" },
|
|
128720
128803
|
React.createElement("div", { className: classNames("s-grid s-w-full s-gap-2 s-overflow-x-hidden s-py-1", "s-grid-cols-".concat(cols), "s-grid-rows-".concat(rows)) }, paginatedItems.map(function (d, idx) {
|
|
128721
128804
|
return (React.createElement(Citation, { size: "xs", sizing: "fluid", key: idx, description: d.description, href: d.href, title: d.title, type: d.type }));
|
|
128722
128805
|
})),
|
|
128723
128806
|
React.createElement("div", { className: classNames("s-pt-3", items.length > maxItemsPerPage ? "s-visible" : "s-collapse") },
|
|
128724
|
-
React.createElement(Pagination, {
|
|
128807
|
+
React.createElement(Pagination, { rowCount: items.length, pagination: pagination, setPagination: setPagination, size: "xs", showDetails: false, showPageButtons: false }))));
|
|
128725
128808
|
}
|
|
128726
128809
|
|
|
128727
128810
|
function Popup(_a) {
|
|
@@ -129144,6 +129227,91 @@ function ZoomableImageCitationWrapper(_a) {
|
|
|
129144
129227
|
React.createElement("img", { src: imgSrc, alt: alt }))))));
|
|
129145
129228
|
}
|
|
129146
129229
|
|
|
129230
|
+
/**
|
|
129231
|
+
* Original code from : https://www.npmjs.com/package/use-hash-param
|
|
129232
|
+
* ISC License
|
|
129233
|
+
*/
|
|
129234
|
+
var getHashSearchParams = function (location) {
|
|
129235
|
+
var hash = location.hash.slice(1);
|
|
129236
|
+
var _a = __read(hash.split("?"), 2), prefix = _a[0], query = _a[1];
|
|
129237
|
+
return [prefix, new URLSearchParams(query)];
|
|
129238
|
+
};
|
|
129239
|
+
var getHashParam = function (key, defaultValue) {
|
|
129240
|
+
var _a;
|
|
129241
|
+
if (typeof window === "undefined") {
|
|
129242
|
+
return defaultValue;
|
|
129243
|
+
}
|
|
129244
|
+
var _b = __read(getHashSearchParams(window.location), 2), searchParams = _b[1];
|
|
129245
|
+
return (_a = searchParams.get(key)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
129246
|
+
};
|
|
129247
|
+
var setHashParam = function (key, value, shouldReplaceState) {
|
|
129248
|
+
if (typeof window !== "undefined") {
|
|
129249
|
+
var _a = __read(getHashSearchParams(window.location), 2), prefix = _a[0], searchParams = _a[1];
|
|
129250
|
+
if (typeof value === "undefined" || value === "") {
|
|
129251
|
+
searchParams.delete(key);
|
|
129252
|
+
}
|
|
129253
|
+
else {
|
|
129254
|
+
searchParams.set(key, value);
|
|
129255
|
+
}
|
|
129256
|
+
var search = searchParams.toString();
|
|
129257
|
+
var hash = search ? "".concat(prefix, "?").concat(search) : prefix;
|
|
129258
|
+
if (shouldReplaceState && "replaceState" in history) {
|
|
129259
|
+
history.replaceState(null, "", "#".concat(hash));
|
|
129260
|
+
}
|
|
129261
|
+
else {
|
|
129262
|
+
window.location.hash = hash;
|
|
129263
|
+
}
|
|
129264
|
+
}
|
|
129265
|
+
};
|
|
129266
|
+
/**
|
|
129267
|
+
* @param key The parameter-name to use from the hash-string query string.
|
|
129268
|
+
* @param defaultValue A default value to use if the parameter is not specified and on the server.
|
|
129269
|
+
* @returns A two-tuple, the first element is the selected param value (either extracted from the hash param or the default value).
|
|
129270
|
+
* The second element is a setter function to change the param value.
|
|
129271
|
+
*/
|
|
129272
|
+
var useHashParam = function (key, defaultValue) {
|
|
129273
|
+
var _a = __read(React.useState(function () {
|
|
129274
|
+
return getHashParam(key, defaultValue);
|
|
129275
|
+
}), 2), innerValue = _a[0], setInnerValue = _a[1];
|
|
129276
|
+
React.useEffect(function () {
|
|
129277
|
+
var handleHashChange = function () {
|
|
129278
|
+
return setInnerValue(getHashParam(key, defaultValue));
|
|
129279
|
+
};
|
|
129280
|
+
handleHashChange();
|
|
129281
|
+
window.addEventListener("hashchange", handleHashChange);
|
|
129282
|
+
return function () { return window.removeEventListener("hashchange", handleHashChange); };
|
|
129283
|
+
}, [key]);
|
|
129284
|
+
var setValue = React.useCallback(function (newValue, options) {
|
|
129285
|
+
if (options === void 0) { options = { history: "replace" }; }
|
|
129286
|
+
var newInnerValue = typeof newValue === "function"
|
|
129287
|
+
? newValue(getHashParam(key, defaultValue))
|
|
129288
|
+
: newValue;
|
|
129289
|
+
setInnerValue(newInnerValue);
|
|
129290
|
+
setHashParam(key, newInnerValue, options.history === "replace");
|
|
129291
|
+
}, [key]);
|
|
129292
|
+
return [innerValue || defaultValue, setValue];
|
|
129293
|
+
};
|
|
129294
|
+
|
|
129295
|
+
var defaultPageSize = 25;
|
|
129296
|
+
var usePaginationFromUrl = function (urlPrefix, initialPageSize) {
|
|
129297
|
+
if (initialPageSize === void 0) { initialPageSize = defaultPageSize; }
|
|
129298
|
+
var _a = __read(useHashParam(urlPrefix ? "".concat(urlPrefix, "PageIndex") : "pageIndex"), 2), pageIndexParam = _a[0], setPageIndexParam = _a[1];
|
|
129299
|
+
var _b = __read(useHashParam(urlPrefix ? "".concat(urlPrefix, "PageSize") : "pageSize"), 2), pageSizeParam = _b[0], setPageSizeParam = _b[1];
|
|
129300
|
+
var pageIndex = pageIndexParam ? parseInt(pageIndexParam) : 0;
|
|
129301
|
+
var pageSize = pageSizeParam ? parseInt(pageSizeParam) : initialPageSize;
|
|
129302
|
+
var res = React.useMemo(function () {
|
|
129303
|
+
var pagination = { pageIndex: pageIndex, pageSize: pageSize };
|
|
129304
|
+
var setPagination = function (newValue) {
|
|
129305
|
+
if (newValue.pageIndex !== pageIndex || newValue.pageSize !== pageSize) {
|
|
129306
|
+
setPageIndexParam(newValue.pageIndex.toString());
|
|
129307
|
+
setPageSizeParam(newValue.pageSize.toString());
|
|
129308
|
+
}
|
|
129309
|
+
};
|
|
129310
|
+
return { pagination: pagination, setPagination: setPagination };
|
|
129311
|
+
}, [pageIndex, pageSize, urlPrefix]);
|
|
129312
|
+
return res;
|
|
129313
|
+
};
|
|
129314
|
+
|
|
129147
129315
|
var SvgLogoHorizontalColor = function (props) { return (React__namespace.createElement("svg", __assign({ xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", fill: "none", viewBox: "0 0 96 24" }, props),
|
|
129148
129316
|
React__namespace.createElement("path", { fill: "#FCD34D", d: "M84 12H72v12h12V12Z" }),
|
|
129149
129317
|
React__namespace.createElement("path", { fill: "#6EE7B7", d: "M12 24c6.627 0 12-5.373 12-12S18.627 0 12 0 0 5.373 0 12s5.373 12 12 12Z" }),
|
|
@@ -129602,4 +129770,6 @@ exports.ZapierLogo = SvgZapier;
|
|
|
129602
129770
|
exports.ZendeskLogo = SvgZendesk;
|
|
129603
129771
|
exports.ZoomableImageCitationWrapper = ZoomableImageCitationWrapper;
|
|
129604
129772
|
exports.avatarUtils = utils;
|
|
129773
|
+
exports.useHashParam = useHashParam;
|
|
129774
|
+
exports.usePaginationFromUrl = usePaginationFromUrl;
|
|
129605
129775
|
//# sourceMappingURL=index.js.map
|