@dloizides/ui-tables 1.12.0 → 1.13.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/CHANGELOG.md +25 -0
- package/dist/index.d.mts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.13.0
|
|
4
|
+
|
|
5
|
+
De-fork wave W1.1: pagination logic promoted from the byte-identical `PaginatedList`
|
|
6
|
+
twins in erevna-web and katalogos-web.
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- `usePagedRows(rows, { pageSize })` — client-side pagination state for an already
|
|
11
|
+
in-memory array. Returns `pageRows`, `currentPage`, `totalPages`, `setPage`,
|
|
12
|
+
`hasPages`, `pageSize`. No new translation keys; no action required.
|
|
13
|
+
|
|
14
|
+
Promoted as a **hook, not a component**, deliberately: the app-side `PaginatedList`
|
|
15
|
+
hard-bound a `FlatList` plus app-specific empty and loading states. Only the paging
|
|
16
|
+
maths is genuinely shared, so only that moved — callers keep their own list renderer.
|
|
17
|
+
For server-side paging keep using `DataTable`'s pager.
|
|
18
|
+
|
|
19
|
+
### Fixed (behaviour differs from the app-side original)
|
|
20
|
+
|
|
21
|
+
- The original only clamped the page index when `totalPages > 0`, so emptying the list
|
|
22
|
+
left a stale non-zero page behind and the next non-empty render started on the wrong
|
|
23
|
+
page. `usePagedRows` clamps to 0 in that case.
|
|
24
|
+
- A `pageSize` of 0 divided by zero (`Math.ceil(n / 0)` → `Infinity` pages). Now floored
|
|
25
|
+
to 1.
|
|
26
|
+
- `setPage` clamps out-of-range input; the original trusted the caller.
|
|
27
|
+
|
|
3
28
|
## 1.12.0
|
|
4
29
|
|
|
5
30
|
Accessibility fix: controls that announced a **bare number** now say what they are. Confirmed in
|
package/dist/index.d.mts
CHANGED
|
@@ -729,4 +729,33 @@ declare const FILTERS_I18N: {
|
|
|
729
729
|
readonly to: "uiTables.filters.to";
|
|
730
730
|
};
|
|
731
731
|
|
|
732
|
-
|
|
732
|
+
/** Rows to show per page when the caller does not specify. */
|
|
733
|
+
declare const DEFAULT_PAGE_SIZE = 10;
|
|
734
|
+
interface UsePagedRowsOptions {
|
|
735
|
+
/** Rows per page. Values < 1 are treated as 1 — a 0 page size would divide by zero. */
|
|
736
|
+
pageSize?: number;
|
|
737
|
+
}
|
|
738
|
+
interface PagedRows<T> {
|
|
739
|
+
/** The slice of `rows` belonging to the current page. */
|
|
740
|
+
pageRows: T[];
|
|
741
|
+
/** Zero-based index of the current page. */
|
|
742
|
+
currentPage: number;
|
|
743
|
+
/** Total number of pages; 0 when there are no rows. */
|
|
744
|
+
totalPages: number;
|
|
745
|
+
/** Jump to a page. Out-of-range values are clamped into `[0, totalPages - 1]`. */
|
|
746
|
+
setPage: (page: number) => void;
|
|
747
|
+
/** Whether a pager is worth rendering at all (more than one page exists). */
|
|
748
|
+
hasPages: boolean;
|
|
749
|
+
/** Effective page size after the `< 1` guard. */
|
|
750
|
+
pageSize: number;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Slice `rows` into pages and track the current one.
|
|
754
|
+
*
|
|
755
|
+
* The current page is kept valid as `rows` changes: if rows are removed while the
|
|
756
|
+
* user is on the last page, the page index clamps down rather than leaving the
|
|
757
|
+
* caller rendering an empty slice of a non-empty list.
|
|
758
|
+
*/
|
|
759
|
+
declare function usePagedRows<T>(rows: readonly T[], options?: UsePagedRowsOptions): PagedRows<T>;
|
|
760
|
+
|
|
761
|
+
export { type BooleanFilterField, CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DataTable, type DataTableColumn, type DataTableProps, type DataTableStyleOverrides, type DateRangeFilterField, type DateRangeValue, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, type FieldStrings, FilterBar, type FilterBarProps, type FilterBarStyleOverrides, type FilterDraft, type FilterField, type FilterFieldKind, type FilterOption, type FilterValue, type FilterValues, Filters, type FiltersProps, type NumberFilterField, type PagedRows, Pager, type PagerProps, type PagerStyleOverrides, type RenderSelectArgs, type SelectFilterField, StatCard, type StatCardProps, TABLE_I18N, TABLE_TEST_IDS, type TextFilterField, type TypeaheadFilterField, type UseFilterDraftOptions, type UsePagedRowsOptions, applyTestID, clearTestID, fieldTestID, isUnmatched, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, suggestOptions, useFilterDraft, usePagedRows };
|
package/dist/index.d.ts
CHANGED
|
@@ -729,4 +729,33 @@ declare const FILTERS_I18N: {
|
|
|
729
729
|
readonly to: "uiTables.filters.to";
|
|
730
730
|
};
|
|
731
731
|
|
|
732
|
-
|
|
732
|
+
/** Rows to show per page when the caller does not specify. */
|
|
733
|
+
declare const DEFAULT_PAGE_SIZE = 10;
|
|
734
|
+
interface UsePagedRowsOptions {
|
|
735
|
+
/** Rows per page. Values < 1 are treated as 1 — a 0 page size would divide by zero. */
|
|
736
|
+
pageSize?: number;
|
|
737
|
+
}
|
|
738
|
+
interface PagedRows<T> {
|
|
739
|
+
/** The slice of `rows` belonging to the current page. */
|
|
740
|
+
pageRows: T[];
|
|
741
|
+
/** Zero-based index of the current page. */
|
|
742
|
+
currentPage: number;
|
|
743
|
+
/** Total number of pages; 0 when there are no rows. */
|
|
744
|
+
totalPages: number;
|
|
745
|
+
/** Jump to a page. Out-of-range values are clamped into `[0, totalPages - 1]`. */
|
|
746
|
+
setPage: (page: number) => void;
|
|
747
|
+
/** Whether a pager is worth rendering at all (more than one page exists). */
|
|
748
|
+
hasPages: boolean;
|
|
749
|
+
/** Effective page size after the `< 1` guard. */
|
|
750
|
+
pageSize: number;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Slice `rows` into pages and track the current one.
|
|
754
|
+
*
|
|
755
|
+
* The current page is kept valid as `rows` changes: if rows are removed while the
|
|
756
|
+
* user is on the last page, the page index clamps down rather than leaving the
|
|
757
|
+
* caller rendering an empty slice of a non-empty list.
|
|
758
|
+
*/
|
|
759
|
+
declare function usePagedRows<T>(rows: readonly T[], options?: UsePagedRowsOptions): PagedRows<T>;
|
|
760
|
+
|
|
761
|
+
export { type BooleanFilterField, CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DataTable, type DataTableColumn, type DataTableProps, type DataTableStyleOverrides, type DateRangeFilterField, type DateRangeValue, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, type FieldStrings, FilterBar, type FilterBarProps, type FilterBarStyleOverrides, type FilterDraft, type FilterField, type FilterFieldKind, type FilterOption, type FilterValue, type FilterValues, Filters, type FiltersProps, type NumberFilterField, type PagedRows, Pager, type PagerProps, type PagerStyleOverrides, type RenderSelectArgs, type SelectFilterField, StatCard, type StatCardProps, TABLE_I18N, TABLE_TEST_IDS, type TextFilterField, type TypeaheadFilterField, type UseFilterDraftOptions, type UsePagedRowsOptions, applyTestID, clearTestID, fieldTestID, isUnmatched, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, suggestOptions, useFilterDraft, usePagedRows };
|
package/dist/index.js
CHANGED
|
@@ -2043,8 +2043,39 @@ function useFilterDraft({ initial, onApply, onReset }) {
|
|
|
2043
2043
|
const dirty = React4.useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
|
|
2044
2044
|
return { draft, committed, setField, setDraft, apply, reset, dirty };
|
|
2045
2045
|
}
|
|
2046
|
+
var DEFAULT_PAGE_SIZE = 10;
|
|
2047
|
+
function usePagedRows(rows, options = {}) {
|
|
2048
|
+
const pageSize = Math.max(1, options.pageSize ?? DEFAULT_PAGE_SIZE);
|
|
2049
|
+
const [currentPage, setCurrentPage] = React4.useState(0);
|
|
2050
|
+
const totalPages = Math.ceil(rows.length / pageSize);
|
|
2051
|
+
React4.useEffect(() => {
|
|
2052
|
+
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
2053
|
+
if (currentPage > lastValidPage) setCurrentPage(lastValidPage);
|
|
2054
|
+
}, [currentPage, totalPages]);
|
|
2055
|
+
const pageRows = React4.useMemo(() => {
|
|
2056
|
+
const start = currentPage * pageSize;
|
|
2057
|
+
return rows.slice(start, start + pageSize);
|
|
2058
|
+
}, [rows, currentPage, pageSize]);
|
|
2059
|
+
const setPage = React4.useCallback(
|
|
2060
|
+
(page) => {
|
|
2061
|
+
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
2062
|
+
const clamped = Math.min(Math.max(0, page), lastValidPage);
|
|
2063
|
+
setCurrentPage(clamped);
|
|
2064
|
+
},
|
|
2065
|
+
[totalPages]
|
|
2066
|
+
);
|
|
2067
|
+
return {
|
|
2068
|
+
pageRows,
|
|
2069
|
+
currentPage,
|
|
2070
|
+
totalPages,
|
|
2071
|
+
setPage,
|
|
2072
|
+
hasPages: totalPages > 1,
|
|
2073
|
+
pageSize
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2046
2076
|
|
|
2047
2077
|
exports.CARD_STACK_BREAKPOINT = CARD_STACK_BREAKPOINT;
|
|
2078
|
+
exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
|
|
2048
2079
|
exports.DEFAULT_PAGE_SIZE_OPTIONS = DEFAULT_PAGE_SIZE_OPTIONS;
|
|
2049
2080
|
exports.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
|
|
2050
2081
|
exports.DEFAULT_TYPEAHEAD_MIN_CHARS = DEFAULT_TYPEAHEAD_MIN_CHARS;
|
|
@@ -2068,5 +2099,6 @@ exports.rowTestID = rowTestID;
|
|
|
2068
2099
|
exports.selectAllTestID = selectAllTestID;
|
|
2069
2100
|
exports.suggestOptions = suggestOptions;
|
|
2070
2101
|
exports.useFilterDraft = useFilterDraft;
|
|
2102
|
+
exports.usePagedRows = usePagedRows;
|
|
2071
2103
|
//# sourceMappingURL=index.js.map
|
|
2072
2104
|
//# sourceMappingURL=index.js.map
|