@ttt-productions/ui-core 0.11.11 → 0.11.14

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.
@@ -1,8 +1,9 @@
1
1
  import type { ListPaginationState } from "../hooks/use-paged-list.js";
2
2
  export interface ListPaginationProps {
3
3
  /**
4
- * Page state from `usePagedList` (known total), `useCursorPage` (unknown
5
- * total), or any caller-owned state of the same shape.
4
+ * Page state from `usePagedList` (known total),
5
+ * `useCursorPage().paginationFor(hasMore)` (unknown total), or any
6
+ * caller-owned state of the same shape.
6
7
  */
7
8
  pagination: ListPaginationState;
8
9
  /**
@@ -18,8 +19,9 @@ export interface ListPaginationProps {
18
19
  * The ONE Previous / counter / Next control for paginated lists, in both
19
20
  * flavors. Pair it with the hook that owns the page state (`usePagedList` for a
20
21
  * client-side slice, `useCursorPage` — or the caller's own query state — for a
21
- * cursor feed); this component owns only the controls, so every paginated list
22
- * reads and behaves the same (ENG-002, FRONTEND-001).
22
+ * cursor feed; a cursor feed passes `pager.paginationFor(hasMore)`, which binds
23
+ * the query's answer to these controls); this component owns only the controls,
24
+ * so every paginated list reads and behaves the same (ENG-002, FRONTEND-001).
23
25
  *
24
26
  * The counter follows the flavor: a known `totalPages` reads "2 of 5", an
25
27
  * omitted one reads "Page 2". Everything else is identical in both flavors —
@@ -1 +1 @@
1
- {"version":3,"file":"list-pagination.d.ts","sourceRoot":"","sources":["../../../src/react/components/list-pagination.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,UAAU,EAAE,mBAAmB,CAAC;IAChC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,IAAY,EAAE,SAAS,EAAE,EAAE,mBAAmB,sCAuC1F"}
1
+ {"version":3,"file":"list-pagination.d.ts","sourceRoot":"","sources":["../../../src/react/components/list-pagination.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,UAAU,EAAE,mBAAmB,CAAC;IAChC;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,IAAY,EAAE,SAAS,EAAE,EAAE,mBAAmB,sCAuC1F"}
@@ -7,8 +7,9 @@ import { cn } from "../../lib/utils.js";
7
7
  * The ONE Previous / counter / Next control for paginated lists, in both
8
8
  * flavors. Pair it with the hook that owns the page state (`usePagedList` for a
9
9
  * client-side slice, `useCursorPage` — or the caller's own query state — for a
10
- * cursor feed); this component owns only the controls, so every paginated list
11
- * reads and behaves the same (ENG-002, FRONTEND-001).
10
+ * cursor feed; a cursor feed passes `pager.paginationFor(hasMore)`, which binds
11
+ * the query's answer to these controls); this component owns only the controls,
12
+ * so every paginated list reads and behaves the same (ENG-002, FRONTEND-001).
12
13
  *
13
14
  * The counter follows the flavor: a known `totalPages` reads "2 of 5", an
14
15
  * omitted one reads "Page 2". Everything else is identical in both flavors —
@@ -1 +1 @@
1
- {"version":3,"file":"list-pagination.js","sourceRoot":"","sources":["../../../src/react/components/list-pagination.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAmBxC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAAC,EAAE,UAAU,EAAE,IAAI,GAAG,KAAK,EAAE,SAAS,EAAuB;IACzF,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAC7F,UAAU,CAAC;IAEb,0EAA0E;IAC1E,qEAAqE;IACrE,yEAAyE;IACzE,0EAA0E;IAC1E,yEAAyE;IACzE,6DAA6D;IAC7D,IAAI,CAAC,eAAe,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAElD,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,qDAAqD,EAAE,SAAS,CAAC,aAClF,MAAC,MAAM,IACL,OAAO,EAAC,SAAS,EACjB,IAAI,EAAC,IAAI,EACT,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,IAAI,IAAI,CAAC,eAAe,EAClC,SAAS,EAAC,eAAe,aAEzB,KAAC,WAAW,IAAC,SAAS,EAAC,cAAc,GAAG,gBAEjC,EACT,eAAM,SAAS,EAAC,cAAc,EAAC,IAAI,EAAC,QAAQ,YACzC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,WAAW,OAAO,UAAU,EAAE,GAChF,EACP,MAAC,MAAM,IACL,OAAO,EAAC,SAAS,EACjB,IAAI,EAAC,IAAI,EACT,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,IAAI,IAAI,CAAC,WAAW,EAC9B,SAAS,EAAC,eAAe,qBAGzB,KAAC,YAAY,IAAC,SAAS,EAAC,cAAc,GAAG,IAClC,IACL,CACP,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport { ChevronLeft, ChevronRight } from \"lucide-react\";\nimport { Button } from \"./button.js\";\nimport { cn } from \"../../lib/utils.js\";\nimport type { ListPaginationState } from \"../hooks/use-paged-list.js\";\n\nexport interface ListPaginationProps {\n /**\n * Page state from `usePagedList` (known total), `useCursorPage` (unknown\n * total), or any caller-owned state of the same shape.\n */\n pagination: ListPaginationState;\n /**\n * Disables BOTH controls while the next page is in flight, without hiding the\n * row. Server-paged surfaces pass their query's `isFetching`; a slice-paged\n * list has nothing to wait for and omits it.\n */\n busy?: boolean;\n /** Optional extra classes. Merged with the component's own classes. */\n className?: string;\n}\n\n/**\n * The ONE Previous / counter / Next control for paginated lists, in both\n * flavors. Pair it with the hook that owns the page state (`usePagedList` for a\n * client-side slice, `useCursorPage` — or the caller's own query state — for a\n * cursor feed); this component owns only the controls, so every paginated list\n * reads and behaves the same (ENG-002, FRONTEND-001).\n *\n * The counter follows the flavor: a known `totalPages` reads \"2 of 5\", an\n * omitted one reads \"Page 2\". Everything else is identical in both flavors —\n * which is exactly why there is one component and not two.\n *\n * It renders NOTHING when neither direction is available, so no call site\n * repeats a `totalPages > 1` / `page > 1 || hasMore` guard. Edge state is real\n * `disabled` on the buttons (announced, and unclickable), and the counter is a\n * `status` live region so a page change is announced to screen readers.\n */\nexport function ListPagination({ pagination, busy = false, className }: ListPaginationProps) {\n const { currentPage, totalPages, canPreviousPage, canNextPage, goToPreviousPage, goToNextPage } =\n pagination;\n\n // One visibility rule for both flavors. For a known total this is exactly\n // `totalPages > 1`: page state is clamped into `1..totalPages`, so a\n // single-page list has no reachable neighbour in either direction, and a\n // multi-page list always has one. For a cursor feed it is the hand-rolled\n // `page > 1 || hasMore`. `busy` deliberately does not hide the row — the\n // controls grey out in place instead of vanishing mid-fetch.\n if (!canPreviousPage && !canNextPage) return null;\n\n return (\n <div className={cn(\"flex w-full items-center justify-between gap-4 mt-4\", className)}>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={goToPreviousPage}\n disabled={busy || !canPreviousPage}\n className=\"h-11 min-w-11\"\n >\n <ChevronLeft className=\"icon-xs mr-1\" />\n Previous\n </Button>\n <span className=\"text-counter\" role=\"status\">\n {totalPages === undefined ? `Page ${currentPage}` : `${currentPage} of ${totalPages}`}\n </span>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={goToNextPage}\n disabled={busy || !canNextPage}\n className=\"h-11 min-w-11\"\n >\n Next\n <ChevronRight className=\"icon-xs ml-1\" />\n </Button>\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"list-pagination.js","sourceRoot":"","sources":["../../../src/react/components/list-pagination.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAoBxC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAAC,EAAE,UAAU,EAAE,IAAI,GAAG,KAAK,EAAE,SAAS,EAAuB;IACzF,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAC7F,UAAU,CAAC;IAEb,0EAA0E;IAC1E,qEAAqE;IACrE,yEAAyE;IACzE,0EAA0E;IAC1E,yEAAyE;IACzE,6DAA6D;IAC7D,IAAI,CAAC,eAAe,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAElD,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,qDAAqD,EAAE,SAAS,CAAC,aAClF,MAAC,MAAM,IACL,OAAO,EAAC,SAAS,EACjB,IAAI,EAAC,IAAI,EACT,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,IAAI,IAAI,CAAC,eAAe,EAClC,SAAS,EAAC,eAAe,aAEzB,KAAC,WAAW,IAAC,SAAS,EAAC,cAAc,GAAG,gBAEjC,EACT,eAAM,SAAS,EAAC,cAAc,EAAC,IAAI,EAAC,QAAQ,YACzC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,WAAW,OAAO,UAAU,EAAE,GAChF,EACP,MAAC,MAAM,IACL,OAAO,EAAC,SAAS,EACjB,IAAI,EAAC,IAAI,EACT,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,IAAI,IAAI,CAAC,WAAW,EAC9B,SAAS,EAAC,eAAe,qBAGzB,KAAC,YAAY,IAAC,SAAS,EAAC,cAAc,GAAG,IAClC,IACL,CACP,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport { ChevronLeft, ChevronRight } from \"lucide-react\";\nimport { Button } from \"./button.js\";\nimport { cn } from \"../../lib/utils.js\";\nimport type { ListPaginationState } from \"../hooks/use-paged-list.js\";\n\nexport interface ListPaginationProps {\n /**\n * Page state from `usePagedList` (known total),\n * `useCursorPage().paginationFor(hasMore)` (unknown total), or any\n * caller-owned state of the same shape.\n */\n pagination: ListPaginationState;\n /**\n * Disables BOTH controls while the next page is in flight, without hiding the\n * row. Server-paged surfaces pass their query's `isFetching`; a slice-paged\n * list has nothing to wait for and omits it.\n */\n busy?: boolean;\n /** Optional extra classes. Merged with the component's own classes. */\n className?: string;\n}\n\n/**\n * The ONE Previous / counter / Next control for paginated lists, in both\n * flavors. Pair it with the hook that owns the page state (`usePagedList` for a\n * client-side slice, `useCursorPage` — or the caller's own query state — for a\n * cursor feed; a cursor feed passes `pager.paginationFor(hasMore)`, which binds\n * the query's answer to these controls); this component owns only the controls,\n * so every paginated list reads and behaves the same (ENG-002, FRONTEND-001).\n *\n * The counter follows the flavor: a known `totalPages` reads \"2 of 5\", an\n * omitted one reads \"Page 2\". Everything else is identical in both flavors —\n * which is exactly why there is one component and not two.\n *\n * It renders NOTHING when neither direction is available, so no call site\n * repeats a `totalPages > 1` / `page > 1 || hasMore` guard. Edge state is real\n * `disabled` on the buttons (announced, and unclickable), and the counter is a\n * `status` live region so a page change is announced to screen readers.\n */\nexport function ListPagination({ pagination, busy = false, className }: ListPaginationProps) {\n const { currentPage, totalPages, canPreviousPage, canNextPage, goToPreviousPage, goToNextPage } =\n pagination;\n\n // One visibility rule for both flavors. For a known total this is exactly\n // `totalPages > 1`: page state is clamped into `1..totalPages`, so a\n // single-page list has no reachable neighbour in either direction, and a\n // multi-page list always has one. For a cursor feed it is the hand-rolled\n // `page > 1 || hasMore`. `busy` deliberately does not hide the row — the\n // controls grey out in place instead of vanishing mid-fetch.\n if (!canPreviousPage && !canNextPage) return null;\n\n return (\n <div className={cn(\"flex w-full items-center justify-between gap-4 mt-4\", className)}>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={goToPreviousPage}\n disabled={busy || !canPreviousPage}\n className=\"h-11 min-w-11\"\n >\n <ChevronLeft className=\"icon-xs mr-1\" />\n Previous\n </Button>\n <span className=\"text-counter\" role=\"status\">\n {totalPages === undefined ? `Page ${currentPage}` : `${currentPage} of ${totalPages}`}\n </span>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={goToNextPage}\n disabled={busy || !canNextPage}\n className=\"h-11 min-w-11\"\n >\n Next\n <ChevronRight className=\"icon-xs ml-1\" />\n </Button>\n </div>\n );\n}\n"]}
@@ -1,32 +1,77 @@
1
1
  import type { ListPaginationState } from "./use-paged-list.js";
2
+ /**
3
+ * Render-time page state for a cursor feed, shaped as {@link ListPaginationState}
4
+ * so it drops straight into the ONE `ListPagination` control. Produced by
5
+ * {@link CursorPager.paginationFor} once the query for `currentPage` has
6
+ * answered with its `hasMore`.
7
+ */
2
8
  export interface CursorPage extends ListPaginationState {
3
9
  /** Never known for cursor pagination — the counter reads "Page N". */
4
10
  totalPages?: undefined;
5
- /**
6
- * Return to page 1 without walking back. Call it whenever the underlying
7
- * query's inputs change (a new filter, a new tag, a new sort) — page 4 of the
8
- * old result set is not page 4 of the new one.
9
- */
10
- reset: () => void;
11
11
  }
12
12
  export interface UseCursorPageOptions {
13
13
  /** Called after the page actually changed. Same contract as `usePagedList`. */
14
14
  onPageChange?: () => void;
15
+ /**
16
+ * A snapshot of the query inputs the page number belongs to — a tag, a filter,
17
+ * a sort. When it changes, the page is 1 again **in the same render**, so the
18
+ * query never fires for "page 4" of inputs whose page 4 may not exist.
19
+ *
20
+ * Use this when the input change arrives as a prop (there is no event handler
21
+ * of yours to hang the reset on); use {@link CursorPager.reset} when your own
22
+ * handler already owns the change. Compose several inputs into one string
23
+ * (`` `${type}|${projectId ?? ""}` ``) — the type is deliberately narrowed to
24
+ * primitives so a fresh object literal cannot pin the list to page 1 forever.
25
+ */
26
+ resetKey?: string | number | boolean | null;
27
+ }
28
+ /**
29
+ * What {@link useCursorPage} owns: the page number, the guarded step controls,
30
+ * and the return-to-page-1 control.
31
+ */
32
+ export interface CursorPager {
33
+ /** 1-based page to feed into the paged query. */
34
+ currentPage: number;
35
+ /**
36
+ * Return to page 1 without walking back. Call it from the handler that changes
37
+ * the query's inputs (a new filter, a new tag, a new sort) — page 4 of the old
38
+ * result set is not page 4 of the new one. A no-op on page 1, so it never
39
+ * fires `onPageChange` for nothing.
40
+ */
41
+ reset: () => void;
42
+ /**
43
+ * Bind the query's answer to the controls: pass the `hasMore` that came back
44
+ * for {@link currentPage} and render the result as
45
+ * `<ListPagination pagination={…} />`. `hasMore` binds HERE, after the query,
46
+ * because that is the only moment it exists — a cursor query needs
47
+ * `currentPage` as its input, so `hasMore` cannot be an argument to the hook
48
+ * that produces `currentPage`.
49
+ */
50
+ paginationFor: (hasMore: boolean) => CursorPage;
15
51
  }
16
52
  /**
17
53
  * Page state for a server-paged (cursor / `hasMore`) list: the 1-based page
18
- * number plus guarded step controls, shaped as {@link ListPaginationState} so it
19
- * drops straight into the ONE `ListPagination` control.
54
+ * number, the guarded step controls, and the reset — the pieces each
55
+ * server-paged surface was otherwise re-declaring as a local `useState(1)` plus
56
+ * its own clamped increment/decrement and its own "reset when the filter
57
+ * changed" adjustment (ENG-002, ENG-003).
58
+ *
59
+ * The data stays the caller's, and the two halves bind at different moments:
60
+ *
61
+ * ```tsx
62
+ * const pager = useCursorPage({ resetKey: tag });
63
+ * const { data, isFetching } = useThingsByTag(tag, pager.currentPage);
64
+ * …
65
+ * <ListPagination pagination={pager.paginationFor(data?.hasMore ?? false)} busy={isFetching} />
66
+ * ```
20
67
  *
21
- * The caller owns the data: it feeds `hasMore` from its query and passes
22
- * `currentPage` back into that query. This hook owns only the page number — the
23
- * piece each server-paged surface was otherwise re-declaring as a local
24
- * `useState(1)` plus its own clamped increment/decrement (ENG-002, ENG-003).
68
+ * The guards live in here, not at the call site: a step that cannot move the
69
+ * page changes nothing and does not fire `onPageChange`.
25
70
  *
26
71
  * A surface whose data hook ALREADY owns its page state (it returns
27
72
  * `page`/`hasNextPage`/`nextPage`/`prevPage` itself) does not need this hook —
28
- * it maps those fields onto `ListPaginationState` directly. The hook exists for
29
- * the surfaces that would otherwise hand-roll the state.
73
+ * it maps those fields onto {@link ListPaginationState} directly. The hook
74
+ * exists for the surfaces that would otherwise hand-roll the state.
30
75
  */
31
- export declare function useCursorPage(hasMore: boolean, options?: UseCursorPageOptions): CursorPage;
76
+ export declare function useCursorPage(options?: UseCursorPageOptions): CursorPager;
32
77
  //# sourceMappingURL=use-cursor-page.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-cursor-page.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-cursor-page.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,MAAM,WAAW,UAAW,SAAQ,mBAAmB;IACrD,sEAAsE;IACtE,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB;;;;OAIG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,oBAAyB,GACjC,UAAU,CAgCZ"}
1
+ {"version":3,"file":"use-cursor-page.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-cursor-page.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,WAAW,UAAW,SAAQ,mBAAmB;IACrD,sEAAsE;IACtE,UAAU,CAAC,EAAE,SAAS,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;CAC7C;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;;;;;OAOG;IACH,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,UAAU,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,WAAW,CAwD7E"}
@@ -2,49 +2,73 @@
2
2
  import { useCallback, useState } from "react";
3
3
  /**
4
4
  * Page state for a server-paged (cursor / `hasMore`) list: the 1-based page
5
- * number plus guarded step controls, shaped as {@link ListPaginationState} so it
6
- * drops straight into the ONE `ListPagination` control.
5
+ * number, the guarded step controls, and the reset — the pieces each
6
+ * server-paged surface was otherwise re-declaring as a local `useState(1)` plus
7
+ * its own clamped increment/decrement and its own "reset when the filter
8
+ * changed" adjustment (ENG-002, ENG-003).
7
9
  *
8
- * The caller owns the data: it feeds `hasMore` from its query and passes
9
- * `currentPage` back into that query. This hook owns only the page number — the
10
- * piece each server-paged surface was otherwise re-declaring as a local
11
- * `useState(1)` plus its own clamped increment/decrement (ENG-002, ENG-003).
10
+ * The data stays the caller's, and the two halves bind at different moments:
11
+ *
12
+ * ```tsx
13
+ * const pager = useCursorPage({ resetKey: tag });
14
+ * const { data, isFetching } = useThingsByTag(tag, pager.currentPage);
15
+ * …
16
+ * <ListPagination pagination={pager.paginationFor(data?.hasMore ?? false)} busy={isFetching} />
17
+ * ```
18
+ *
19
+ * The guards live in here, not at the call site: a step that cannot move the
20
+ * page changes nothing and does not fire `onPageChange`.
12
21
  *
13
22
  * A surface whose data hook ALREADY owns its page state (it returns
14
23
  * `page`/`hasNextPage`/`nextPage`/`prevPage` itself) does not need this hook —
15
- * it maps those fields onto `ListPaginationState` directly. The hook exists for
16
- * the surfaces that would otherwise hand-roll the state.
24
+ * it maps those fields onto {@link ListPaginationState} directly. The hook
25
+ * exists for the surfaces that would otherwise hand-roll the state.
17
26
  */
18
- export function useCursorPage(hasMore, options = {}) {
19
- const { onPageChange } = options;
20
- const [currentPage, setCurrentPage] = useState(1);
21
- // Guards live here, not at the call site: a click that cannot move the page
22
- // must not fire `onPageChange` and must not push the page past the data.
27
+ export function useCursorPage(options = {}) {
28
+ const { onPageChange, resetKey } = options;
29
+ // The stored page is only meaningful for the inputs it was reached under, so
30
+ // the key it belongs to is stored WITH it.
31
+ const [pageState, setPageState] = useState({ page: 1, key: resetKey });
32
+ // `Object.is`, the same comparison React uses for state and deps: a `NaN` key
33
+ // must compare equal to itself, or the adjustment below would re-fire forever.
34
+ const keyMatches = Object.is(pageState.key, resetKey);
35
+ // React's "adjusting state when a prop changes": a new key retires the stored
36
+ // page, because page 4 of the old result set is not page 4 of the new one.
37
+ // Retiring it (rather than only ignoring it) is what makes going BACK to
38
+ // earlier inputs start at page 1 too, instead of reviving a dead page.
39
+ if (!keyMatches) {
40
+ setPageState({ page: 1, key: resetKey });
41
+ }
42
+ // Derived as well as adjusted, so even the render that triggers the adjustment
43
+ // already reports page 1 — the caller's query is never asked for a page of the
44
+ // new inputs that the user never navigated to.
45
+ const currentPage = keyMatches ? pageState.page : 1;
23
46
  const goToPreviousPage = useCallback(() => {
24
47
  if (currentPage <= 1)
25
48
  return;
26
- setCurrentPage(currentPage - 1);
27
- onPageChange?.();
28
- }, [currentPage, onPageChange]);
29
- const goToNextPage = useCallback(() => {
30
- if (!hasMore)
31
- return;
32
- setCurrentPage(currentPage + 1);
49
+ setPageState({ page: currentPage - 1, key: resetKey });
33
50
  onPageChange?.();
34
- }, [currentPage, hasMore, onPageChange]);
51
+ }, [currentPage, resetKey, onPageChange]);
35
52
  const reset = useCallback(() => {
36
53
  if (currentPage === 1)
37
54
  return;
38
- setCurrentPage(1);
55
+ setPageState({ page: 1, key: resetKey });
39
56
  onPageChange?.();
40
- }, [currentPage, onPageChange]);
41
- return {
57
+ }, [currentPage, resetKey, onPageChange]);
58
+ // Memoized on the page state itself, so a consumer may hold it in a dep array
59
+ // and it changes only when the page (or the callback/inputs) actually change.
60
+ const paginationFor = useCallback((hasMore) => ({
42
61
  currentPage,
43
62
  canPreviousPage: currentPage > 1,
44
63
  canNextPage: hasMore,
45
64
  goToPreviousPage,
46
- goToNextPage,
47
- reset,
48
- };
65
+ goToNextPage: () => {
66
+ if (!hasMore)
67
+ return;
68
+ setPageState({ page: currentPage + 1, key: resetKey });
69
+ onPageChange?.();
70
+ },
71
+ }), [currentPage, resetKey, onPageChange, goToPreviousPage]);
72
+ return { currentPage, reset, paginationFor };
49
73
  }
50
74
  //# sourceMappingURL=use-cursor-page.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-cursor-page.js","sourceRoot":"","sources":["../../../src/react/hooks/use-cursor-page.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAmB9C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAgB,EAChB,UAAgC,EAAE;IAElC,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IACjC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAElD,4EAA4E;IAC5E,yEAAyE;IACzE,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE;QACxC,IAAI,WAAW,IAAI,CAAC;YAAE,OAAO;QAC7B,cAAc,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QAChC,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;IAEhC,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE;QACpC,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,cAAc,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QAChC,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IAEzC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,IAAI,WAAW,KAAK,CAAC;YAAE,OAAO;QAC9B,cAAc,CAAC,CAAC,CAAC,CAAC;QAClB,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;IAEhC,OAAO;QACL,WAAW;QACX,eAAe,EAAE,WAAW,GAAG,CAAC;QAChC,WAAW,EAAE,OAAO;QACpB,gBAAgB;QAChB,YAAY;QACZ,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\nimport type { ListPaginationState } from \"./use-paged-list.js\";\n\nexport interface CursorPage extends ListPaginationState {\n /** Never known for cursor pagination — the counter reads \"Page N\". */\n totalPages?: undefined;\n /**\n * Return to page 1 without walking back. Call it whenever the underlying\n * query's inputs change (a new filter, a new tag, a new sort) — page 4 of the\n * old result set is not page 4 of the new one.\n */\n reset: () => void;\n}\n\nexport interface UseCursorPageOptions {\n /** Called after the page actually changed. Same contract as `usePagedList`. */\n onPageChange?: () => void;\n}\n\n/**\n * Page state for a server-paged (cursor / `hasMore`) list: the 1-based page\n * number plus guarded step controls, shaped as {@link ListPaginationState} so it\n * drops straight into the ONE `ListPagination` control.\n *\n * The caller owns the data: it feeds `hasMore` from its query and passes\n * `currentPage` back into that query. This hook owns only the page number — the\n * piece each server-paged surface was otherwise re-declaring as a local\n * `useState(1)` plus its own clamped increment/decrement (ENG-002, ENG-003).\n *\n * A surface whose data hook ALREADY owns its page state (it returns\n * `page`/`hasNextPage`/`nextPage`/`prevPage` itself) does not need this hook —\n * it maps those fields onto `ListPaginationState` directly. The hook exists for\n * the surfaces that would otherwise hand-roll the state.\n */\nexport function useCursorPage(\n hasMore: boolean,\n options: UseCursorPageOptions = {},\n): CursorPage {\n const { onPageChange } = options;\n const [currentPage, setCurrentPage] = useState(1);\n\n // Guards live here, not at the call site: a click that cannot move the page\n // must not fire `onPageChange` and must not push the page past the data.\n const goToPreviousPage = useCallback(() => {\n if (currentPage <= 1) return;\n setCurrentPage(currentPage - 1);\n onPageChange?.();\n }, [currentPage, onPageChange]);\n\n const goToNextPage = useCallback(() => {\n if (!hasMore) return;\n setCurrentPage(currentPage + 1);\n onPageChange?.();\n }, [currentPage, hasMore, onPageChange]);\n\n const reset = useCallback(() => {\n if (currentPage === 1) return;\n setCurrentPage(1);\n onPageChange?.();\n }, [currentPage, onPageChange]);\n\n return {\n currentPage,\n canPreviousPage: currentPage > 1,\n canNextPage: hasMore,\n goToPreviousPage,\n goToNextPage,\n reset,\n };\n}\n"]}
1
+ {"version":3,"file":"use-cursor-page.js","sourceRoot":"","sources":["../../../src/react/hooks/use-cursor-page.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAwD9C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,aAAa,CAAC,UAAgC,EAAE;IAC9D,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE3C,6EAA6E;IAC7E,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AAG,WAAW,CAC/B,CAAC,OAAgB,EAAc,EAAE,CAAC,CAAC;QACjC,WAAW;QACX,eAAe,EAAE,WAAW,GAAG,CAAC;QAChC,WAAW,EAAE,OAAO;QACpB,gBAAgB;QAChB,YAAY,EAAE,GAAG,EAAE;YACjB,IAAI,CAAC,OAAO;gBAAE,OAAO;YACrB,YAAY,CAAC,EAAE,IAAI,EAAE,WAAW,GAAG,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;YACvD,YAAY,EAAE,EAAE,CAAC;QACnB,CAAC;KACF,CAAC,EACF,CAAC,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,CAAC,CACxD,CAAC;IAEF,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\nimport type { ListPaginationState } from \"./use-paged-list.js\";\n\n/**\n * Render-time page state for a cursor feed, shaped as {@link ListPaginationState}\n * so it drops straight into the ONE `ListPagination` control. Produced by\n * {@link CursorPager.paginationFor} once the query for `currentPage` has\n * answered with its `hasMore`.\n */\nexport interface CursorPage extends ListPaginationState {\n /** Never known for cursor pagination — the counter reads \"Page N\". */\n totalPages?: undefined;\n}\n\nexport interface UseCursorPageOptions {\n /** Called after the page actually changed. Same contract as `usePagedList`. */\n onPageChange?: () => void;\n /**\n * A snapshot of the query inputs the page number belongs to — a tag, a filter,\n * a sort. When it changes, the page is 1 again **in the same render**, so the\n * query never fires for \"page 4\" of inputs whose page 4 may not exist.\n *\n * Use this when the input change arrives as a prop (there is no event handler\n * of yours to hang the reset on); use {@link CursorPager.reset} when your own\n * handler already owns the change. Compose several inputs into one string\n * (`` `${type}|${projectId ?? \"\"}` ``) — the type is deliberately narrowed to\n * primitives so a fresh object literal cannot pin the list to page 1 forever.\n */\n resetKey?: string | number | boolean | null;\n}\n\n/**\n * What {@link useCursorPage} owns: the page number, the guarded step controls,\n * and the return-to-page-1 control.\n */\nexport interface CursorPager {\n /** 1-based page to feed into the paged query. */\n currentPage: number;\n /**\n * Return to page 1 without walking back. Call it from the handler that changes\n * the query's inputs (a new filter, a new tag, a new sort) — page 4 of the old\n * result set is not page 4 of the new one. A no-op on page 1, so it never\n * fires `onPageChange` for nothing.\n */\n reset: () => void;\n /**\n * Bind the query's answer to the controls: pass the `hasMore` that came back\n * for {@link currentPage} and render the result as\n * `<ListPagination pagination={…} />`. `hasMore` binds HERE, after the query,\n * because that is the only moment it exists — a cursor query needs\n * `currentPage` as its input, so `hasMore` cannot be an argument to the hook\n * that produces `currentPage`.\n */\n paginationFor: (hasMore: boolean) => CursorPage;\n}\n\n/**\n * Page state for a server-paged (cursor / `hasMore`) list: the 1-based page\n * number, the guarded step controls, and the reset — the pieces each\n * server-paged surface was otherwise re-declaring as a local `useState(1)` plus\n * its own clamped increment/decrement and its own \"reset when the filter\n * changed\" adjustment (ENG-002, ENG-003).\n *\n * The data stays the caller's, and the two halves bind at different moments:\n *\n * ```tsx\n * const pager = useCursorPage({ resetKey: tag });\n * const { data, isFetching } = useThingsByTag(tag, pager.currentPage);\n * …\n * <ListPagination pagination={pager.paginationFor(data?.hasMore ?? false)} busy={isFetching} />\n * ```\n *\n * The guards live in here, not at the call site: a step that cannot move the\n * page changes nothing and does not fire `onPageChange`.\n *\n * A surface whose data hook ALREADY owns its page state (it returns\n * `page`/`hasNextPage`/`nextPage`/`prevPage` itself) does not need this hook —\n * it maps those fields onto {@link ListPaginationState} directly. The hook\n * exists for the surfaces that would otherwise hand-roll the state.\n */\nexport function useCursorPage(options: UseCursorPageOptions = {}): CursorPager {\n const { onPageChange, resetKey } = options;\n\n // The stored page is only meaningful for the inputs it was reached under, so\n // the key it belongs to is stored WITH it.\n const [pageState, setPageState] = useState<{\n page: number;\n key: UseCursorPageOptions[\"resetKey\"];\n }>({ page: 1, key: resetKey });\n\n // `Object.is`, the same comparison React uses for state and deps: a `NaN` key\n // must compare equal to itself, or the adjustment below would re-fire forever.\n const keyMatches = Object.is(pageState.key, resetKey);\n\n // React's \"adjusting state when a prop changes\": a new key retires the stored\n // page, because page 4 of the old result set is not page 4 of the new one.\n // Retiring it (rather than only ignoring it) is what makes going BACK to\n // earlier inputs start at page 1 too, instead of reviving a dead page.\n if (!keyMatches) {\n setPageState({ page: 1, key: resetKey });\n }\n // Derived as well as adjusted, so even the render that triggers the adjustment\n // already reports page 1 — the caller's query is never asked for a page of the\n // new inputs that the user never navigated to.\n const currentPage = keyMatches ? pageState.page : 1;\n\n const goToPreviousPage = useCallback(() => {\n if (currentPage <= 1) return;\n setPageState({ page: currentPage - 1, key: resetKey });\n onPageChange?.();\n }, [currentPage, resetKey, onPageChange]);\n\n const reset = useCallback(() => {\n if (currentPage === 1) return;\n setPageState({ page: 1, key: resetKey });\n onPageChange?.();\n }, [currentPage, resetKey, onPageChange]);\n\n // Memoized on the page state itself, so a consumer may hold it in a dep array\n // and it changes only when the page (or the callback/inputs) actually change.\n const paginationFor = useCallback(\n (hasMore: boolean): CursorPage => ({\n currentPage,\n canPreviousPage: currentPage > 1,\n canNextPage: hasMore,\n goToPreviousPage,\n goToNextPage: () => {\n if (!hasMore) return;\n setPageState({ page: currentPage + 1, key: resetKey });\n onPageChange?.();\n },\n }),\n [currentPage, resetKey, onPageChange, goToPreviousPage],\n );\n\n return { currentPage, reset, paginationFor };\n}\n"]}
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * - **Known total** (client-side slice pagination — {@link usePagedList}):
10
10
  * `totalPages` is a number and the counter reads `"2 of 5"`.
11
- * - **Unknown total** (server/cursor pagination — `useCursorPage`, or a
12
- * caller's own query hook): `totalPages` is omitted and the counter reads
11
+ * - **Unknown total** (server/cursor pagination — `useCursorPage().paginationFor(hasMore)`,
12
+ * or a caller's own query hook): `totalPages` is omitted and the counter reads
13
13
  * `"Page 2"`.
14
14
  *
15
15
  * Both flavors share one visibility rule, one disabled-edge rule, one live
@@ -1 +1 @@
1
- {"version":3,"file":"use-paged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AAG,EAAE;QACpC,IAAI,WAAW,IAAI,UAAU;YAAE,OAAO;QACtC,gBAAgB,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QAClC,YAAY,EAAE,EAAE,CAAC;IACnB,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE5C,OAAO;QACL,WAAW;QACX,UAAU;QACV,SAAS;QACT,eAAe,EAAE,WAAW,GAAG,CAAC;QAChC,WAAW,EAAE,WAAW,GAAG,UAAU;QACrC,gBAAgB;QAChB,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport { useCallback, useMemo, useState } from \"react\";\n\n/**\n * The control state a paginated list exposes to its paginator UI, rendered by\n * the ONE `ListPagination` component. Nothing else builds\n * Previous / counter / Next controls.\n *\n * `totalPages` is the flavor discriminant, and the ONLY difference between the\n * two flavors:\n *\n * - **Known total** (client-side slice pagination — {@link usePagedList}):\n * `totalPages` is a number and the counter reads `\"2 of 5\"`.\n * - **Unknown total** (server/cursor pagination — `useCursorPage`, or a\n * caller's own query hook): `totalPages` is omitted and the counter reads\n * `\"Page 2\"`.\n *\n * Both flavors share one visibility rule, one disabled-edge rule, one live\n * region, and one set of classes because they share one component (ENG-002,\n * FRONTEND-001).\n */\nexport interface ListPaginationState {\n /** 1-based page currently on screen. */\n currentPage: number;\n /**\n * Total page count when it is knowable — at least 1, even for an empty list\n * (an empty list is one empty page). Omitted for cursor/`hasMore` pagination,\n * where the total is unknown until the last page is reached.\n */\n totalPages?: number;\n canPreviousPage: boolean;\n canNextPage: boolean;\n goToPreviousPage: () => void;\n goToNextPage: () => void;\n}\n\nexport interface PagedList<T> extends ListPaginationState {\n /** Always known for a slice-paginated list. */\n totalPages: number;\n /** The slice of `items` belonging to `currentPage`. */\n pageItems: T[];\n}\n\nexport interface UsePagedListOptions {\n /**\n * Called after the page actually changed. Surfaces that keep a per-page\n * selection (an open detail row) clear it here — the old selection is not on\n * the new page.\n */\n onPageChange?: () => void;\n}\n\n/**\n * The single owner of client-side slice pagination: local page state, the page\n * math, and the current slice over an ALREADY-FETCHED list.\n *\n * Page size is the caller's — every surface passes its own page-size constant\n * (ENG-005), never a literal. Ordering and filtering stay with the caller: pass\n * the list already sorted and filtered.\n *\n * Not for server-paged lists — a cursor/`hasMore` feed pages through the\n * caller's data layer, not through a slice; use `useCursorPage` (or the query\n * hook's own page state) with the same `ListPagination` control.\n */\nexport function usePagedList<T>(\n items: readonly T[],\n pageSize: number,\n options: UsePagedListOptions = {},\n): PagedList<T> {\n const { onPageChange } = options;\n const [requestedPage, setRequestedPage] = useState(1);\n\n const totalPages = Math.max(1, Math.ceil(items.length / pageSize));\n // The list can shrink under a page that is already open (an item is deleted,\n // a filter narrows). Clamping keeps the paginator on a real page instead of\n // rendering an empty slice under an out-of-range \"4 of 2\".\n const currentPage = Math.min(Math.max(1, requestedPage), totalPages);\n\n const pageItems = useMemo(() => {\n const startIndex = (currentPage - 1) * pageSize;\n return items.slice(startIndex, startIndex + pageSize);\n }, [items, currentPage, pageSize]);\n\n const goToPreviousPage = useCallback(() => {\n if (currentPage <= 1) return;\n setRequestedPage(currentPage - 1);\n onPageChange?.();\n }, [currentPage, onPageChange]);\n\n const goToNextPage = useCallback(() => {\n if (currentPage >= totalPages) return;\n setRequestedPage(currentPage + 1);\n onPageChange?.();\n }, [currentPage, totalPages, onPageChange]);\n\n return {\n currentPage,\n totalPages,\n pageItems,\n canPreviousPage: currentPage > 1,\n canNextPage: currentPage < totalPages,\n goToPreviousPage,\n goToNextPage,\n };\n}\n"]}
1
+ {"version":3,"file":"use-paged-list.js","sourceRoot":"","sources":["../../../src/react/hooks/use-paged-list.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAmDvD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAmB,EACnB,QAAgB,EA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X,UAAU;QACV,SAAS;QACT,eAAe,EAAE,WAAW,GAAG,CAAC;QAChC,WAAW,EAAE,WAAW,GAAG,UAAU;QACrC,gBAAgB;QAChB,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport { useCallback, useMemo, useState } from \"react\";\n\n/**\n * The control state a paginated list exposes to its paginator UI, rendered by\n * the ONE `ListPagination` component. Nothing else builds\n * Previous / counter / Next controls.\n *\n * `totalPages` is the flavor discriminant, and the ONLY difference between the\n * two flavors:\n *\n * - **Known total** (client-side slice pagination — {@link usePagedList}):\n * `totalPages` is a number and the counter reads `\"2 of 5\"`.\n * - **Unknown total** (server/cursor pagination — `useCursorPage().paginationFor(hasMore)`,\n * or a caller's own query hook): `totalPages` is omitted and the counter reads\n * `\"Page 2\"`.\n *\n * Both flavors share one visibility rule, one disabled-edge rule, one live\n * region, and one set of classes because they share one component (ENG-002,\n * FRONTEND-001).\n */\nexport interface ListPaginationState {\n /** 1-based page currently on screen. */\n currentPage: number;\n /**\n * Total page count when it is knowable — at least 1, even for an empty list\n * (an empty list is one empty page). Omitted for cursor/`hasMore` pagination,\n * where the total is unknown until the last page is reached.\n */\n totalPages?: number;\n canPreviousPage: boolean;\n canNextPage: boolean;\n goToPreviousPage: () => void;\n goToNextPage: () => void;\n}\n\nexport interface PagedList<T> extends ListPaginationState {\n /** Always known for a slice-paginated list. */\n totalPages: number;\n /** The slice of `items` belonging to `currentPage`. */\n pageItems: T[];\n}\n\nexport interface UsePagedListOptions {\n /**\n * Called after the page actually changed. Surfaces that keep a per-page\n * selection (an open detail row) clear it here — the old selection is not on\n * the new page.\n */\n onPageChange?: () => void;\n}\n\n/**\n * The single owner of client-side slice pagination: local page state, the page\n * math, and the current slice over an ALREADY-FETCHED list.\n *\n * Page size is the caller's — every surface passes its own page-size constant\n * (ENG-005), never a literal. Ordering and filtering stay with the caller: pass\n * the list already sorted and filtered.\n *\n * Not for server-paged lists — a cursor/`hasMore` feed pages through the\n * caller's data layer, not through a slice; use `useCursorPage` (or the query\n * hook's own page state) with the same `ListPagination` control.\n */\nexport function usePagedList<T>(\n items: readonly T[],\n pageSize: number,\n options: UsePagedListOptions = {},\n): PagedList<T> {\n const { onPageChange } = options;\n const [requestedPage, setRequestedPage] = useState(1);\n\n const totalPages = Math.max(1, Math.ceil(items.length / pageSize));\n // The list can shrink under a page that is already open (an item is deleted,\n // a filter narrows). Clamping keeps the paginator on a real page instead of\n // rendering an empty slice under an out-of-range \"4 of 2\".\n const currentPage = Math.min(Math.max(1, requestedPage), totalPages);\n\n const pageItems = useMemo(() => {\n const startIndex = (currentPage - 1) * pageSize;\n return items.slice(startIndex, startIndex + pageSize);\n }, [items, currentPage, pageSize]);\n\n const goToPreviousPage = useCallback(() => {\n if (currentPage <= 1) return;\n setRequestedPage(currentPage - 1);\n onPageChange?.();\n }, [currentPage, onPageChange]);\n\n const goToNextPage = useCallback(() => {\n if (currentPage >= totalPages) return;\n setRequestedPage(currentPage + 1);\n onPageChange?.();\n }, [currentPage, totalPages, onPageChange]);\n\n return {\n currentPage,\n totalPages,\n pageItems,\n canPreviousPage: currentPage > 1,\n canNextPage: currentPage < totalPages,\n goToPreviousPage,\n goToNextPage,\n };\n}\n"]}
@@ -0,0 +1,26 @@
1
+ export interface ReturnScrollEntry {
2
+ /** The saved `window.scrollY`. */
3
+ y: number;
4
+ /** Epoch ms at save time (diagnostic; the caller decides eligibility, not the hook). */
5
+ savedAt: number;
6
+ }
7
+ export interface UseReturnScrollOptions {
8
+ /** The caller's CANONICAL list URL — equivalent list states must give the same key. */
9
+ key: string;
10
+ /** Decided by the caller ONCE at mount (e.g. "the list's data was already cached on first render"). */
11
+ eligible: boolean;
12
+ /** The list is displayed at its real height: data present, no error surface in its place. */
13
+ ready: boolean;
14
+ }
15
+ export interface UseReturnScrollResult {
16
+ /** Record the current window offset for `key`. Call right before navigating away. */
17
+ save: () => void;
18
+ }
19
+ /** The stored entry for `key`, or null when absent, unreadable, or malformed. */
20
+ export declare function readReturnScroll(key: string): ReturnScrollEntry | null;
21
+ /** Record `y` (default: the current `window.scrollY`) for `key`. No-op without storage. */
22
+ export declare function saveReturnScroll(key: string, y?: number): void;
23
+ /** Drop the entry for `key` (e.g. the list changed underneath the saved offset). */
24
+ export declare function clearReturnScroll(key: string): void;
25
+ export declare function useReturnScroll({ key, eligible, ready }: UseReturnScrollOptions): UseReturnScrollResult;
26
+ //# sourceMappingURL=use-return-scroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-return-scroll.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-return-scroll.ts"],"names":[],"mappings":"AA2BA,MAAM,WAAW,iBAAiB;IAChC,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,wFAAwF;IACxF,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,uFAAuF;IACvF,GAAG,EAAE,MAAM,CAAC;IACZ,uGAAuG;IACvG,QAAQ,EAAE,OAAO,CAAC;IAClB,6FAA6F;IAC7F,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,qFAAqF;IACrF,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAeD,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CActE;AAED,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAU9D;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAQnD;AASD,wBAAgB,eAAe,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,sBAAsB,GAAG,qBAAqB,CAuCvG"}
@@ -0,0 +1,123 @@
1
+ "use client";
2
+ // Return-scroll: bring a list back to where the user left it after a REAL route change.
3
+ //
4
+ // A same-page view swap keeps its component mounted and can restore from a ref; a list
5
+ // whose detail pages have their own URLs unmounts, so the offset has to survive in
6
+ // per-tab storage and the restore has to wait until the list is displayed at its real
7
+ // height again. This hook is the ONE owner of that mechanism. It knows nothing about
8
+ // what the list is — the caller supplies a canonical key, decides eligibility once at
9
+ // mount, and reports readiness.
10
+ //
11
+ // Contract (every rule below is tested):
12
+ // - `save()` writes { y, savedAt } for `key` — call it immediately before navigating
13
+ // away (inside any guarded-navigation callback, so a cancelled leave writes nothing).
14
+ // - `eligible` is latched per key the first time the hook sees that key. Not eligible
15
+ // ⇒ the entry is deleted immediately and permanently for that key; a later flip
16
+ // of `eligible` or `ready` never re-arms the restore.
17
+ // - `ready` ⇒ the restore fires ONCE, in a requestAnimationFrame, `behavior: "instant"`,
18
+ // then consumes the entry. The scheduled frame is cancelled on unmount or key change.
19
+ // React Strict Mode's mount/unmount/mount cancels and reschedules, so exactly one
20
+ // scroll happens and the entry is consumed exactly once.
21
+ // - Blocked, unavailable, or malformed storage is a silent no-op.
22
+ import * as React from "react";
23
+ const STORAGE_PREFIX = "return-scroll:";
24
+ function storageKey(key) {
25
+ return `${STORAGE_PREFIX}${key}`;
26
+ }
27
+ function sessionStorageOrNull() {
28
+ try {
29
+ if (typeof window === "undefined")
30
+ return null;
31
+ return window.sessionStorage ?? null;
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ }
37
+ /** The stored entry for `key`, or null when absent, unreadable, or malformed. */
38
+ export function readReturnScroll(key) {
39
+ const storage = sessionStorageOrNull();
40
+ if (!storage)
41
+ return null;
42
+ try {
43
+ const raw = storage.getItem(storageKey(key));
44
+ if (!raw)
45
+ return null;
46
+ const parsed = JSON.parse(raw);
47
+ if (typeof parsed !== "object" || parsed === null)
48
+ return null;
49
+ const { y, savedAt } = parsed;
50
+ if (typeof y !== "number" || !Number.isFinite(y) || y < 0)
51
+ return null;
52
+ return { y, savedAt: typeof savedAt === "number" ? savedAt : 0 };
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ }
58
+ /** Record `y` (default: the current `window.scrollY`) for `key`. No-op without storage. */
59
+ export function saveReturnScroll(key, y) {
60
+ const storage = sessionStorageOrNull();
61
+ if (!storage)
62
+ return;
63
+ try {
64
+ const offset = typeof y === "number" ? y : window.scrollY;
65
+ const entry = { y: offset, savedAt: Date.now() };
66
+ storage.setItem(storageKey(key), JSON.stringify(entry));
67
+ }
68
+ catch {
69
+ /* storage blocked or full — nothing to restore later, which is the honest outcome */
70
+ }
71
+ }
72
+ /** Drop the entry for `key` (e.g. the list changed underneath the saved offset). */
73
+ export function clearReturnScroll(key) {
74
+ const storage = sessionStorageOrNull();
75
+ if (!storage)
76
+ return;
77
+ try {
78
+ storage.removeItem(storageKey(key));
79
+ }
80
+ catch {
81
+ /* nothing to clear */
82
+ }
83
+ }
84
+ export function useReturnScroll({ key, eligible, ready }) {
85
+ const decisionRef = React.useRef(null);
86
+ // Decide ONCE per key, the first time the hook sees it. Effects may read and write refs;
87
+ // the decision is latched, so a later `eligible` flip finds it already made and returns.
88
+ React.useEffect(() => {
89
+ if (decisionRef.current?.key === key)
90
+ return;
91
+ const entry = readReturnScroll(key);
92
+ if (!entry) {
93
+ decisionRef.current = { key, y: null, done: true };
94
+ return;
95
+ }
96
+ if (!eligible) {
97
+ // A cold return: nothing cached to restore against. Discard permanently for this visit.
98
+ clearReturnScroll(key);
99
+ decisionRef.current = { key, y: null, done: true };
100
+ return;
101
+ }
102
+ decisionRef.current = { key, y: entry.y, done: false };
103
+ }, [key, eligible]);
104
+ // Restore once the list is displayed at its real height. The frame is cancelled on unmount
105
+ // or key change; Strict Mode's re-run reschedules it, so exactly one scroll happens.
106
+ React.useEffect(() => {
107
+ const decision = decisionRef.current;
108
+ if (!decision || decision.key !== key || decision.y === null || decision.done || !ready)
109
+ return;
110
+ if (typeof window === "undefined")
111
+ return;
112
+ const y = decision.y;
113
+ const frame = window.requestAnimationFrame(() => {
114
+ window.scrollTo({ top: y, left: 0, behavior: "instant" });
115
+ clearReturnScroll(key);
116
+ decision.done = true;
117
+ });
118
+ return () => window.cancelAnimationFrame(frame);
119
+ }, [key, ready]);
120
+ const save = React.useCallback(() => saveReturnScroll(key), [key]);
121
+ return { save };
122
+ }
123
+ //# sourceMappingURL=use-return-scroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-return-scroll.js","sourceRoot":"","sources":["../../../src/react/hooks/use-return-scroll.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,wFAAwF;AACxF,EAAE;AACF,uFAAuF;AACvF,mFAAmF;AACnF,sFAAsF;AACtF,qFAAqF;AACrF,sFAAsF;AACtF,gCAAgC;AAChC,EAAE;AACF,yCAAyC;AACzC,uFAAuF;AACvF,0FAA0F;AAC1F,wFAAwF;AACxF,oFAAoF;AACpF,0DAA0D;AAC1D,2FAA2F;AAC3F,0FAA0F;AAC1F,sFAAsF;AACtF,6DAA6D;AAC7D,oEAAoE;AAEpE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAuBxC,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,GAAG,cAAc,GAAG,GAAG,EAAE,CAAC;AACnC,CAAC;AAED,SAAS,oBAAoB;IAC3B,IAAI,CAAC;QACH,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC/C,OAAO,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,MAAM,OAAO,GAAG,oBAAoB,EAAE,CAAC;IACvC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC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AC,QAAQ,IAAI,QAAQ,CAAC,GAAG,KAAK,GAAG,IAAI,QAAQ,CAAC,CAAC,KAAK,IAAI,IAAI,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK;YAAE,OAAO;QAChG,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;QACrB,MAAM,KAAK,GAAG,MAAM,CAAC,qBAAqB,CAAC,GAAG,EAAE;YAC9C,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,SAA2B,EAAE,CAAC,CAAC;YAC5E,iBAAiB,CAAC,GAAG,CAAC,CAAC;YACvB,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAEjB,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEnE,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC","sourcesContent":["\"use client\";\n\n// Return-scroll: bring a list back to where the user left it after a REAL route change.\n//\n// A same-page view swap keeps its component mounted and can restore from a ref; a list\n// whose detail pages have their own URLs unmounts, so the offset has to survive in\n// per-tab storage and the restore has to wait until the list is displayed at its real\n// height again. This hook is the ONE owner of that mechanism. It knows nothing about\n// what the list is — the caller supplies a canonical key, decides eligibility once at\n// mount, and reports readiness.\n//\n// Contract (every rule below is tested):\n// - `save()` writes { y, savedAt } for `key` — call it immediately before navigating\n// away (inside any guarded-navigation callback, so a cancelled leave writes nothing).\n// - `eligible` is latched per key the first time the hook sees that key. Not eligible\n// ⇒ the entry is deleted immediately and permanently for that key; a later flip\n// of `eligible` or `ready` never re-arms the restore.\n// - `ready` ⇒ the restore fires ONCE, in a requestAnimationFrame, `behavior: \"instant\"`,\n// then consumes the entry. The scheduled frame is cancelled on unmount or key change.\n// React Strict Mode's mount/unmount/mount cancels and reschedules, so exactly one\n// scroll happens and the entry is consumed exactly once.\n// - Blocked, unavailable, or malformed storage is a silent no-op.\n\nimport * as React from \"react\";\n\nconst STORAGE_PREFIX = \"return-scroll:\";\n\nexport interface ReturnScrollEntry {\n /** The saved `window.scrollY`. */\n y: number;\n /** Epoch ms at save time (diagnostic; the caller decides eligibility, not the hook). */\n savedAt: number;\n}\n\nexport interface UseReturnScrollOptions {\n /** The caller's CANONICAL list URL — equivalent list states must give the same key. */\n key: string;\n /** Decided by the caller ONCE at mount (e.g. \"the list's data was already cached on first render\"). */\n eligible: boolean;\n /** The list is displayed at its real height: data present, no error surface in its place. */\n ready: boolean;\n}\n\nexport interface UseReturnScrollResult {\n /** Record the current window offset for `key`. Call right before navigating away. */\n save: () => void;\n}\n\nfunction storageKey(key: string): string {\n return `${STORAGE_PREFIX}${key}`;\n}\n\nfunction sessionStorageOrNull(): Storage | null {\n try {\n if (typeof window === \"undefined\") return null;\n return window.sessionStorage ?? null;\n } catch {\n return null;\n }\n}\n\n/** The stored entry for `key`, or null when absent, unreadable, or malformed. */\nexport function readReturnScroll(key: string): ReturnScrollEntry | null {\n const storage = sessionStorageOrNull();\n if (!storage) return null;\n try {\n const raw = storage.getItem(storageKey(key));\n if (!raw) return null;\n const parsed: unknown = JSON.parse(raw);\n if (typeof parsed !== \"object\" || parsed === null) return null;\n const { y, savedAt } = parsed as { y?: unknown; savedAt?: unknown };\n if (typeof y !== \"number\" || !Number.isFinite(y) || y < 0) return null;\n return { y, savedAt: typeof savedAt === \"number\" ? savedAt : 0 };\n } catch {\n return null;\n }\n}\n\n/** Record `y` (default: the current `window.scrollY`) for `key`. No-op without storage. */\nexport function saveReturnScroll(key: string, y?: number): void {\n const storage = sessionStorageOrNull();\n if (!storage) return;\n try {\n const offset = typeof y === \"number\" ? y : window.scrollY;\n const entry: ReturnScrollEntry = { y: offset, savedAt: Date.now() };\n storage.setItem(storageKey(key), JSON.stringify(entry));\n } catch {\n /* storage blocked or full — nothing to restore later, which is the honest outcome */\n }\n}\n\n/** Drop the entry for `key` (e.g. the list changed underneath the saved offset). */\nexport function clearReturnScroll(key: string): void {\n const storage = sessionStorageOrNull();\n if (!storage) return;\n try {\n storage.removeItem(storageKey(key));\n } catch {\n /* nothing to clear */\n }\n}\n\ninterface Decision {\n key: string;\n /** The offset to restore, or null when this key's return is not restorable. */\n y: number | null;\n done: boolean;\n}\n\nexport function useReturnScroll({ key, eligible, ready }: UseReturnScrollOptions): UseReturnScrollResult {\n const decisionRef = React.useRef<Decision | null>(null);\n\n // Decide ONCE per key, the first time the hook sees it. Effects may read and write refs;\n // the decision is latched, so a later `eligible` flip finds it already made and returns.\n React.useEffect(() => {\n if (decisionRef.current?.key === key) return;\n const entry = readReturnScroll(key);\n if (!entry) {\n decisionRef.current = { key, y: null, done: true };\n return;\n }\n if (!eligible) {\n // A cold return: nothing cached to restore against. Discard permanently for this visit.\n clearReturnScroll(key);\n decisionRef.current = { key, y: null, done: true };\n return;\n }\n decisionRef.current = { key, y: entry.y, done: false };\n }, [key, eligible]);\n\n // Restore once the list is displayed at its real height. The frame is cancelled on unmount\n // or key change; Strict Mode's re-run reschedules it, so exactly one scroll happens.\n React.useEffect(() => {\n const decision = decisionRef.current;\n if (!decision || decision.key !== key || decision.y === null || decision.done || !ready) return;\n if (typeof window === \"undefined\") return;\n const y = decision.y;\n const frame = window.requestAnimationFrame(() => {\n window.scrollTo({ top: y, left: 0, behavior: \"instant\" as ScrollBehavior });\n clearReturnScroll(key);\n decision.done = true;\n });\n return () => window.cancelAnimationFrame(frame);\n }, [key, ready]);\n\n const save = React.useCallback(() => saveReturnScroll(key), [key]);\n\n return { save };\n}\n"]}
@@ -56,5 +56,7 @@ export type { ListPaginationProps } from "./components/list-pagination.js";
56
56
  export { usePagedList } from "./hooks/use-paged-list.js";
57
57
  export type { ListPaginationState, PagedList, UsePagedListOptions } from "./hooks/use-paged-list.js";
58
58
  export { useCursorPage } from "./hooks/use-cursor-page.js";
59
- export type { CursorPage, UseCursorPageOptions } from "./hooks/use-cursor-page.js";
59
+ export type { CursorPage, CursorPager, UseCursorPageOptions } from "./hooks/use-cursor-page.js";
60
+ export { useReturnScroll, saveReturnScroll, clearReturnScroll, readReturnScroll } from "./hooks/use-return-scroll.js";
61
+ export type { ReturnScrollEntry, UseReturnScrollOptions, UseReturnScrollResult } from "./hooks/use-return-scroll.js";
60
62
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACpL,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,wBAA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B,CAAC;AAKhG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACtH,YAAY,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -46,4 +46,8 @@ export { ChunkErrorRecovery } from "./components/chunk-error-recovery.js";
46
46
  export { ListPagination } from "./components/list-pagination.js";
47
47
  export { usePagedList } from "./hooks/use-paged-list.js";
48
48
  export { useCursorPage } from "./hooks/use-cursor-page.js";
49
+ // Return-scroll: restore a list's window offset when the user comes back to it after a
50
+ // route change (save on leave, restore once on an eligible + ready return, keyed by the
51
+ // caller's canonical list URL).
52
+ export { useReturnScroll, saveReturnScroll, clearReturnScroll, readReturnScroll } from "./hooks/use-return-scroll.js";
49
53
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACpL,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACjG,OAAO,EA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AAM,uBAAuB,CAAC;AACzK,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAElG,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAEjF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,yBAAyB;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAGzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,kFAAkF;AAClF,iEAAiE;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["\"use client\";\n\nexport type { ButtonProps } from \"./components/button.js\";\nexport { Button, buttonVariants } from \"./components/button.js\";\nexport { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } from \"./components/card.js\";\nexport { Label } from \"./components/label.js\";\nexport { Textarea } from \"./components/textarea.js\";\nexport { Skeleton } from \"./components/skeleton.js\";\nexport { Dialog, DialogPortal, DialogOverlay, DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription } from \"./components/dialog.js\";\nexport { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } from \"./components/popover.js\";\nexport { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuGroup, DropdownMenuPortal, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuRadioGroup } from \"./components/dropdown-menu.js\";\nexport { Menubar, MenubarMenu, MenubarTrigger, MenubarContent, MenubarItem, MenubarSeparator, MenubarLabel, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarPortal, MenubarSubContent, MenubarSubTrigger, MenubarGroup, MenubarSub, MenubarShortcut } from \"./components/menubar.js\";\nexport { AlertDialog, AlertDialogPortal, AlertDialogOverlay, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel } from \"./components/alert-dialog.js\";\nexport { Alert, AlertTitle, AlertDescription } from \"./components/alert.js\";\nexport type { ToastProps, ToastActionElement } from \"./components/toast.js\";\nexport { ToastProvider, ToastViewport, Toast, ToastTitle, ToastDescription, ToastClose, ToastAction } from \"./components/toast.js\";\nexport { Toaster } from \"./components/toaster.js\";\nexport type { ToastVariant, ToasterToast } from \"./hooks/use-toast.js\";\nexport { toast, useToast } from \"./hooks/use-toast.js\";\nexport { Input } from \"./components/input.js\";\nexport { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton } from \"./components/select.js\";\nexport { Tabs, TabsList, TabsTrigger, TabsContent } from \"./components/tabs.js\";\nexport { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from \"./components/tooltip.js\";\nexport { useFormField, Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField } from \"./components/form.js\";\nexport { Checkbox } from \"./components/checkbox.js\";\nexport { Switch } from \"./components/switch.js\";\nexport type { BadgeProps } from \"./components/badge.js\";\nexport { Badge, badgeVariants } from \"./components/badge.js\";\nexport { Avatar, AvatarImage, AvatarFallback } from \"./components/avatar.js\";\nexport { Separator } from \"./components/separator.js\";\nexport { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from \"./components/accordion.js\";\nexport { RadioGroup, RadioGroupItem } from \"./components/radio-group.js\";\nexport { Progress } from \"./components/progress.js\";\nexport { Slider } from \"./components/slider.js\";\nexport type { DatePickerProps } from \"./components/date-picker.js\";\nexport { DatePicker } from \"./components/date-picker.js\";\nexport { ScrollArea, ScrollBar } from \"./components/scroll-area.js\";\nexport { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption } from \"./components/table.js\";\nexport { Sheet, SheetPortal, SheetOverlay, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetFooter, SheetTitle, SheetDescription } from \"./components/sheet.js\";\nexport { Collapsible, CollapsibleTrigger, CollapsibleContent } from \"./components/collapsible.js\";\nexport type { SearchDropdownProps } from \"./components/search-dropdown.js\";\nexport { SearchDropdown } from \"./components/search-dropdown.js\";\n\nexport type { ConsequenceDialogProps, ConsequenceDialogReason, ConsequenceDialogTypedConfirmation } from \"./components/consequence-dialog.js\";\nexport { ConsequenceDialog } from \"./components/consequence-dialog.js\";\n\nexport type { MaxWidthOption, ScreenAdaptiveViewProps } from \"./components/layout/screen-adaptive-view.js\";\nexport { ScreenAdaptiveView } from \"./components/layout/screen-adaptive-view.js\";\n\nexport { useMediaQuery } from \"./hooks/use-media-query.js\";\n\n// Shared building blocks\nexport { RelativeTime } from \"./components/relative-time.js\";\nexport type { RelativeTimeProps } from \"./components/relative-time.js\";\n\nexport { EndOfListIndicator } from \"./components/end-of-list-indicator.js\";\nexport type { EndOfListIndicatorProps } from \"./components/end-of-list-indicator.js\";\n\nexport { ScrollToTopButton } from \"./components/scroll-to-top-button.js\";\nexport type { ScrollToTopButtonProps } from \"./components/scroll-to-top-button.js\";\n\nexport { ChunkErrorRecovery } from \"./components/chunk-error-recovery.js\";\nexport type { ChunkErrorRecoveryProps } from \"./components/chunk-error-recovery.js\";\n\n// List pagination — the one Previous / counter / Next control plus the page-state\n// hooks for its two flavors (known total, and cursor/`hasMore`).\nexport { ListPagination } from \"./components/list-pagination.js\";\nexport type { ListPaginationProps } from \"./components/list-pagination.js\";\n\nexport { usePagedList } from \"./hooks/use-paged-list.js\";\nexport type { ListPaginationState, PagedList, UsePagedListOptions } from \"./hooks/use-paged-list.js\";\n\nexport { useCursorPage } from \"./hooks/use-cursor-page.js\";\nexport type { CursorPage, UseCursorPageOptions } from \"./hooks/use-cursor-page.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACpL,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,eAAe,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC1W,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,gBA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AAyB;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAG3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAGzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAG1E,kFAAkF;AAClF,iEAAiE;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,uFAAuF;AACvF,wFAAwF;AACxF,gCAAgC;AAChC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["\"use client\";\n\nexport type { ButtonProps } from \"./components/button.js\";\nexport { Button, buttonVariants } from \"./components/button.js\";\nexport { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } from \"./components/card.js\";\nexport { Label } from \"./components/label.js\";\nexport { Textarea } from \"./components/textarea.js\";\nexport { Skeleton } from \"./components/skeleton.js\";\nexport { Dialog, DialogPortal, DialogOverlay, DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription } from \"./components/dialog.js\";\nexport { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } from \"./components/popover.js\";\nexport { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, DropdownMenuRadioItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuGroup, DropdownMenuPortal, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuRadioGroup } from \"./components/dropdown-menu.js\";\nexport { Menubar, MenubarMenu, MenubarTrigger, MenubarContent, MenubarItem, MenubarSeparator, MenubarLabel, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarPortal, MenubarSubContent, MenubarSubTrigger, MenubarGroup, MenubarSub, MenubarShortcut } from \"./components/menubar.js\";\nexport { AlertDialog, AlertDialogPortal, AlertDialogOverlay, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel } from \"./components/alert-dialog.js\";\nexport { Alert, AlertTitle, AlertDescription } from \"./components/alert.js\";\nexport type { ToastProps, ToastActionElement } from \"./components/toast.js\";\nexport { ToastProvider, ToastViewport, Toast, ToastTitle, ToastDescription, ToastClose, ToastAction } from \"./components/toast.js\";\nexport { Toaster } from \"./components/toaster.js\";\nexport type { ToastVariant, ToasterToast } from \"./hooks/use-toast.js\";\nexport { toast, useToast } from \"./hooks/use-toast.js\";\nexport { Input } from \"./components/input.js\";\nexport { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton } from \"./components/select.js\";\nexport { Tabs, TabsList, TabsTrigger, TabsContent } from \"./components/tabs.js\";\nexport { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from \"./components/tooltip.js\";\nexport { useFormField, Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField } from \"./components/form.js\";\nexport { Checkbox } from \"./components/checkbox.js\";\nexport { Switch } from \"./components/switch.js\";\nexport type { BadgeProps } from \"./components/badge.js\";\nexport { Badge, badgeVariants } from \"./components/badge.js\";\nexport { Avatar, AvatarImage, AvatarFallback } from \"./components/avatar.js\";\nexport { Separator } from \"./components/separator.js\";\nexport { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from \"./components/accordion.js\";\nexport { RadioGroup, RadioGroupItem } from \"./components/radio-group.js\";\nexport { Progress } from \"./components/progress.js\";\nexport { Slider } from \"./components/slider.js\";\nexport type { DatePickerProps } from \"./components/date-picker.js\";\nexport { DatePicker } from \"./components/date-picker.js\";\nexport { ScrollArea, ScrollBar } from \"./components/scroll-area.js\";\nexport { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption } from \"./components/table.js\";\nexport { Sheet, SheetPortal, SheetOverlay, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetFooter, SheetTitle, SheetDescription } from \"./components/sheet.js\";\nexport { Collapsible, CollapsibleTrigger, CollapsibleContent } from \"./components/collapsible.js\";\nexport type { SearchDropdownProps } from \"./components/search-dropdown.js\";\nexport { SearchDropdown } from \"./components/search-dropdown.js\";\n\nexport type { ConsequenceDialogProps, ConsequenceDialogReason, ConsequenceDialogTypedConfirmation } from \"./components/consequence-dialog.js\";\nexport { ConsequenceDialog } from \"./components/consequence-dialog.js\";\n\nexport type { MaxWidthOption, ScreenAdaptiveViewProps } from \"./components/layout/screen-adaptive-view.js\";\nexport { ScreenAdaptiveView } from \"./components/layout/screen-adaptive-view.js\";\n\nexport { useMediaQuery } from \"./hooks/use-media-query.js\";\n\n// Shared building blocks\nexport { RelativeTime } from \"./components/relative-time.js\";\nexport type { RelativeTimeProps } from \"./components/relative-time.js\";\n\nexport { EndOfListIndicator } from \"./components/end-of-list-indicator.js\";\nexport type { EndOfListIndicatorProps } from \"./components/end-of-list-indicator.js\";\n\nexport { ScrollToTopButton } from \"./components/scroll-to-top-button.js\";\nexport type { ScrollToTopButtonProps } from \"./components/scroll-to-top-button.js\";\n\nexport { ChunkErrorRecovery } from \"./components/chunk-error-recovery.js\";\nexport type { ChunkErrorRecoveryProps } from \"./components/chunk-error-recovery.js\";\n\n// List pagination — the one Previous / counter / Next control plus the page-state\n// hooks for its two flavors (known total, and cursor/`hasMore`).\nexport { ListPagination } from \"./components/list-pagination.js\";\nexport type { ListPaginationProps } from \"./components/list-pagination.js\";\n\nexport { usePagedList } from \"./hooks/use-paged-list.js\";\nexport type { ListPaginationState, PagedList, UsePagedListOptions } from \"./hooks/use-paged-list.js\";\n\nexport { useCursorPage } from \"./hooks/use-cursor-page.js\";\nexport type { CursorPage, CursorPager, UseCursorPageOptions } from \"./hooks/use-cursor-page.js\";\n\n// Return-scroll: restore a list's window offset when the user comes back to it after a\n// route change (save on leave, restore once on an eligible + ready return, keyed by the\n// caller's canonical list URL).\nexport { useReturnScroll, saveReturnScroll, clearReturnScroll, readReturnScroll } from \"./hooks/use-return-scroll.js\";\nexport type { ReturnScrollEntry, UseReturnScrollOptions, UseReturnScrollResult } from \"./hooks/use-return-scroll.js\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttt-productions/ui-core",
3
- "version": "0.11.11",
3
+ "version": "0.11.14",
4
4
  "description": "Shared UI components for TTT Productions projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,7 +49,7 @@
49
49
  "react-dom": ">=19.0.0",
50
50
  "react-hook-form": ">=7.0.0",
51
51
  "@hookform/resolvers": ">=3.0.0",
52
- "@ttt-productions/firebase-helpers": "^0.12.4"
52
+ "@ttt-productions/firebase-helpers": "^0.12.7"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "react": {
@@ -99,7 +99,7 @@
99
99
  "typescript": "^5.8.3",
100
100
  "react-hook-form": "^7.69.0",
101
101
  "@hookform/resolvers": "^5.2.2",
102
- "@ttt-productions/firebase-helpers": "^0.12.4"
102
+ "@ttt-productions/firebase-helpers": "^0.12.7"
103
103
  },
104
104
  "author": "DJ (TTT Productions)",
105
105
  "license": "MIT"
@@ -7,8 +7,9 @@ import type { ListPaginationState } from "../hooks/use-paged-list.js";
7
7
 
8
8
  export interface ListPaginationProps {
9
9
  /**
10
- * Page state from `usePagedList` (known total), `useCursorPage` (unknown
11
- * total), or any caller-owned state of the same shape.
10
+ * Page state from `usePagedList` (known total),
11
+ * `useCursorPage().paginationFor(hasMore)` (unknown total), or any
12
+ * caller-owned state of the same shape.
12
13
  */
13
14
  pagination: ListPaginationState;
14
15
  /**
@@ -25,8 +26,9 @@ export interface ListPaginationProps {
25
26
  * The ONE Previous / counter / Next control for paginated lists, in both
26
27
  * flavors. Pair it with the hook that owns the page state (`usePagedList` for a
27
28
  * client-side slice, `useCursorPage` — or the caller's own query state — for a
28
- * cursor feed); this component owns only the controls, so every paginated list
29
- * reads and behaves the same (ENG-002, FRONTEND-001).
29
+ * cursor feed; a cursor feed passes `pager.paginationFor(hasMore)`, which binds
30
+ * the query's answer to these controls); this component owns only the controls,
31
+ * so every paginated list reads and behaves the same (ENG-002, FRONTEND-001).
30
32
  *
31
33
  * The counter follows the flavor: a known `totalPages` reads "2 of 5", an
32
34
  * omitted one reads "Page 2". Everything else is identical in both flavors —
@@ -3,70 +3,137 @@
3
3
  import { useCallback, useState } from "react";
4
4
  import type { ListPaginationState } from "./use-paged-list.js";
5
5
 
6
+ /**
7
+ * Render-time page state for a cursor feed, shaped as {@link ListPaginationState}
8
+ * so it drops straight into the ONE `ListPagination` control. Produced by
9
+ * {@link CursorPager.paginationFor} once the query for `currentPage` has
10
+ * answered with its `hasMore`.
11
+ */
6
12
  export interface CursorPage extends ListPaginationState {
7
13
  /** Never known for cursor pagination — the counter reads "Page N". */
8
14
  totalPages?: undefined;
9
- /**
10
- * Return to page 1 without walking back. Call it whenever the underlying
11
- * query's inputs change (a new filter, a new tag, a new sort) — page 4 of the
12
- * old result set is not page 4 of the new one.
13
- */
14
- reset: () => void;
15
15
  }
16
16
 
17
17
  export interface UseCursorPageOptions {
18
18
  /** Called after the page actually changed. Same contract as `usePagedList`. */
19
19
  onPageChange?: () => void;
20
+ /**
21
+ * A snapshot of the query inputs the page number belongs to — a tag, a filter,
22
+ * a sort. When it changes, the page is 1 again **in the same render**, so the
23
+ * query never fires for "page 4" of inputs whose page 4 may not exist.
24
+ *
25
+ * Use this when the input change arrives as a prop (there is no event handler
26
+ * of yours to hang the reset on); use {@link CursorPager.reset} when your own
27
+ * handler already owns the change. Compose several inputs into one string
28
+ * (`` `${type}|${projectId ?? ""}` ``) — the type is deliberately narrowed to
29
+ * primitives so a fresh object literal cannot pin the list to page 1 forever.
30
+ */
31
+ resetKey?: string | number | boolean | null;
32
+ }
33
+
34
+ /**
35
+ * What {@link useCursorPage} owns: the page number, the guarded step controls,
36
+ * and the return-to-page-1 control.
37
+ */
38
+ export interface CursorPager {
39
+ /** 1-based page to feed into the paged query. */
40
+ currentPage: number;
41
+ /**
42
+ * Return to page 1 without walking back. Call it from the handler that changes
43
+ * the query's inputs (a new filter, a new tag, a new sort) — page 4 of the old
44
+ * result set is not page 4 of the new one. A no-op on page 1, so it never
45
+ * fires `onPageChange` for nothing.
46
+ */
47
+ reset: () => void;
48
+ /**
49
+ * Bind the query's answer to the controls: pass the `hasMore` that came back
50
+ * for {@link currentPage} and render the result as
51
+ * `<ListPagination pagination={…} />`. `hasMore` binds HERE, after the query,
52
+ * because that is the only moment it exists — a cursor query needs
53
+ * `currentPage` as its input, so `hasMore` cannot be an argument to the hook
54
+ * that produces `currentPage`.
55
+ */
56
+ paginationFor: (hasMore: boolean) => CursorPage;
20
57
  }
21
58
 
22
59
  /**
23
60
  * Page state for a server-paged (cursor / `hasMore`) list: the 1-based page
24
- * number plus guarded step controls, shaped as {@link ListPaginationState} so it
25
- * drops straight into the ONE `ListPagination` control.
61
+ * number, the guarded step controls, and the reset — the pieces each
62
+ * server-paged surface was otherwise re-declaring as a local `useState(1)` plus
63
+ * its own clamped increment/decrement and its own "reset when the filter
64
+ * changed" adjustment (ENG-002, ENG-003).
65
+ *
66
+ * The data stays the caller's, and the two halves bind at different moments:
67
+ *
68
+ * ```tsx
69
+ * const pager = useCursorPage({ resetKey: tag });
70
+ * const { data, isFetching } = useThingsByTag(tag, pager.currentPage);
71
+ * …
72
+ * <ListPagination pagination={pager.paginationFor(data?.hasMore ?? false)} busy={isFetching} />
73
+ * ```
26
74
  *
27
- * The caller owns the data: it feeds `hasMore` from its query and passes
28
- * `currentPage` back into that query. This hook owns only the page number — the
29
- * piece each server-paged surface was otherwise re-declaring as a local
30
- * `useState(1)` plus its own clamped increment/decrement (ENG-002, ENG-003).
75
+ * The guards live in here, not at the call site: a step that cannot move the
76
+ * page changes nothing and does not fire `onPageChange`.
31
77
  *
32
78
  * A surface whose data hook ALREADY owns its page state (it returns
33
79
  * `page`/`hasNextPage`/`nextPage`/`prevPage` itself) does not need this hook —
34
- * it maps those fields onto `ListPaginationState` directly. The hook exists for
35
- * the surfaces that would otherwise hand-roll the state.
80
+ * it maps those fields onto {@link ListPaginationState} directly. The hook
81
+ * exists for the surfaces that would otherwise hand-roll the state.
36
82
  */
37
- export function useCursorPage(
38
- hasMore: boolean,
39
- options: UseCursorPageOptions = {},
40
- ): CursorPage {
41
- const { onPageChange } = options;
42
- const [currentPage, setCurrentPage] = useState(1);
83
+ export function useCursorPage(options: UseCursorPageOptions = {}): CursorPager {
84
+ const { onPageChange, resetKey } = options;
85
+
86
+ // The stored page is only meaningful for the inputs it was reached under, so
87
+ // the key it belongs to is stored WITH it.
88
+ const [pageState, setPageState] = useState<{
89
+ page: number;
90
+ key: UseCursorPageOptions["resetKey"];
91
+ }>({ page: 1, key: resetKey });
92
+
93
+ // `Object.is`, the same comparison React uses for state and deps: a `NaN` key
94
+ // must compare equal to itself, or the adjustment below would re-fire forever.
95
+ const keyMatches = Object.is(pageState.key, resetKey);
96
+
97
+ // React's "adjusting state when a prop changes": a new key retires the stored
98
+ // page, because page 4 of the old result set is not page 4 of the new one.
99
+ // Retiring it (rather than only ignoring it) is what makes going BACK to
100
+ // earlier inputs start at page 1 too, instead of reviving a dead page.
101
+ if (!keyMatches) {
102
+ setPageState({ page: 1, key: resetKey });
103
+ }
104
+ // Derived as well as adjusted, so even the render that triggers the adjustment
105
+ // already reports page 1 — the caller's query is never asked for a page of the
106
+ // new inputs that the user never navigated to.
107
+ const currentPage = keyMatches ? pageState.page : 1;
43
108
 
44
- // Guards live here, not at the call site: a click that cannot move the page
45
- // must not fire `onPageChange` and must not push the page past the data.
46
109
  const goToPreviousPage = useCallback(() => {
47
110
  if (currentPage <= 1) return;
48
- setCurrentPage(currentPage - 1);
111
+ setPageState({ page: currentPage - 1, key: resetKey });
49
112
  onPageChange?.();
50
- }, [currentPage, onPageChange]);
51
-
52
- const goToNextPage = useCallback(() => {
53
- if (!hasMore) return;
54
- setCurrentPage(currentPage + 1);
55
- onPageChange?.();
56
- }, [currentPage, hasMore, onPageChange]);
113
+ }, [currentPage, resetKey, onPageChange]);
57
114
 
58
115
  const reset = useCallback(() => {
59
116
  if (currentPage === 1) return;
60
- setCurrentPage(1);
117
+ setPageState({ page: 1, key: resetKey });
61
118
  onPageChange?.();
62
- }, [currentPage, onPageChange]);
119
+ }, [currentPage, resetKey, onPageChange]);
120
+
121
+ // Memoized on the page state itself, so a consumer may hold it in a dep array
122
+ // and it changes only when the page (or the callback/inputs) actually change.
123
+ const paginationFor = useCallback(
124
+ (hasMore: boolean): CursorPage => ({
125
+ currentPage,
126
+ canPreviousPage: currentPage > 1,
127
+ canNextPage: hasMore,
128
+ goToPreviousPage,
129
+ goToNextPage: () => {
130
+ if (!hasMore) return;
131
+ setPageState({ page: currentPage + 1, key: resetKey });
132
+ onPageChange?.();
133
+ },
134
+ }),
135
+ [currentPage, resetKey, onPageChange, goToPreviousPage],
136
+ );
63
137
 
64
- return {
65
- currentPage,
66
- canPreviousPage: currentPage > 1,
67
- canNextPage: hasMore,
68
- goToPreviousPage,
69
- goToNextPage,
70
- reset,
71
- };
138
+ return { currentPage, reset, paginationFor };
72
139
  }
@@ -12,8 +12,8 @@ import { useCallback, useMemo, useState } from "react";
12
12
  *
13
13
  * - **Known total** (client-side slice pagination — {@link usePagedList}):
14
14
  * `totalPages` is a number and the counter reads `"2 of 5"`.
15
- * - **Unknown total** (server/cursor pagination — `useCursorPage`, or a
16
- * caller's own query hook): `totalPages` is omitted and the counter reads
15
+ * - **Unknown total** (server/cursor pagination — `useCursorPage().paginationFor(hasMore)`,
16
+ * or a caller's own query hook): `totalPages` is omitted and the counter reads
17
17
  * `"Page 2"`.
18
18
  *
19
19
  * Both flavors share one visibility rule, one disabled-edge rule, one live
@@ -0,0 +1,149 @@
1
+ "use client";
2
+
3
+ // Return-scroll: bring a list back to where the user left it after a REAL route change.
4
+ //
5
+ // A same-page view swap keeps its component mounted and can restore from a ref; a list
6
+ // whose detail pages have their own URLs unmounts, so the offset has to survive in
7
+ // per-tab storage and the restore has to wait until the list is displayed at its real
8
+ // height again. This hook is the ONE owner of that mechanism. It knows nothing about
9
+ // what the list is — the caller supplies a canonical key, decides eligibility once at
10
+ // mount, and reports readiness.
11
+ //
12
+ // Contract (every rule below is tested):
13
+ // - `save()` writes { y, savedAt } for `key` — call it immediately before navigating
14
+ // away (inside any guarded-navigation callback, so a cancelled leave writes nothing).
15
+ // - `eligible` is latched per key the first time the hook sees that key. Not eligible
16
+ // ⇒ the entry is deleted immediately and permanently for that key; a later flip
17
+ // of `eligible` or `ready` never re-arms the restore.
18
+ // - `ready` ⇒ the restore fires ONCE, in a requestAnimationFrame, `behavior: "instant"`,
19
+ // then consumes the entry. The scheduled frame is cancelled on unmount or key change.
20
+ // React Strict Mode's mount/unmount/mount cancels and reschedules, so exactly one
21
+ // scroll happens and the entry is consumed exactly once.
22
+ // - Blocked, unavailable, or malformed storage is a silent no-op.
23
+
24
+ import * as React from "react";
25
+
26
+ const STORAGE_PREFIX = "return-scroll:";
27
+
28
+ export interface ReturnScrollEntry {
29
+ /** The saved `window.scrollY`. */
30
+ y: number;
31
+ /** Epoch ms at save time (diagnostic; the caller decides eligibility, not the hook). */
32
+ savedAt: number;
33
+ }
34
+
35
+ export interface UseReturnScrollOptions {
36
+ /** The caller's CANONICAL list URL — equivalent list states must give the same key. */
37
+ key: string;
38
+ /** Decided by the caller ONCE at mount (e.g. "the list's data was already cached on first render"). */
39
+ eligible: boolean;
40
+ /** The list is displayed at its real height: data present, no error surface in its place. */
41
+ ready: boolean;
42
+ }
43
+
44
+ export interface UseReturnScrollResult {
45
+ /** Record the current window offset for `key`. Call right before navigating away. */
46
+ save: () => void;
47
+ }
48
+
49
+ function storageKey(key: string): string {
50
+ return `${STORAGE_PREFIX}${key}`;
51
+ }
52
+
53
+ function sessionStorageOrNull(): Storage | null {
54
+ try {
55
+ if (typeof window === "undefined") return null;
56
+ return window.sessionStorage ?? null;
57
+ } catch {
58
+ return null;
59
+ }
60
+ }
61
+
62
+ /** The stored entry for `key`, or null when absent, unreadable, or malformed. */
63
+ export function readReturnScroll(key: string): ReturnScrollEntry | null {
64
+ const storage = sessionStorageOrNull();
65
+ if (!storage) return null;
66
+ try {
67
+ const raw = storage.getItem(storageKey(key));
68
+ if (!raw) return null;
69
+ const parsed: unknown = JSON.parse(raw);
70
+ if (typeof parsed !== "object" || parsed === null) return null;
71
+ const { y, savedAt } = parsed as { y?: unknown; savedAt?: unknown };
72
+ if (typeof y !== "number" || !Number.isFinite(y) || y < 0) return null;
73
+ return { y, savedAt: typeof savedAt === "number" ? savedAt : 0 };
74
+ } catch {
75
+ return null;
76
+ }
77
+ }
78
+
79
+ /** Record `y` (default: the current `window.scrollY`) for `key`. No-op without storage. */
80
+ export function saveReturnScroll(key: string, y?: number): void {
81
+ const storage = sessionStorageOrNull();
82
+ if (!storage) return;
83
+ try {
84
+ const offset = typeof y === "number" ? y : window.scrollY;
85
+ const entry: ReturnScrollEntry = { y: offset, savedAt: Date.now() };
86
+ storage.setItem(storageKey(key), JSON.stringify(entry));
87
+ } catch {
88
+ /* storage blocked or full — nothing to restore later, which is the honest outcome */
89
+ }
90
+ }
91
+
92
+ /** Drop the entry for `key` (e.g. the list changed underneath the saved offset). */
93
+ export function clearReturnScroll(key: string): void {
94
+ const storage = sessionStorageOrNull();
95
+ if (!storage) return;
96
+ try {
97
+ storage.removeItem(storageKey(key));
98
+ } catch {
99
+ /* nothing to clear */
100
+ }
101
+ }
102
+
103
+ interface Decision {
104
+ key: string;
105
+ /** The offset to restore, or null when this key's return is not restorable. */
106
+ y: number | null;
107
+ done: boolean;
108
+ }
109
+
110
+ export function useReturnScroll({ key, eligible, ready }: UseReturnScrollOptions): UseReturnScrollResult {
111
+ const decisionRef = React.useRef<Decision | null>(null);
112
+
113
+ // Decide ONCE per key, the first time the hook sees it. Effects may read and write refs;
114
+ // the decision is latched, so a later `eligible` flip finds it already made and returns.
115
+ React.useEffect(() => {
116
+ if (decisionRef.current?.key === key) return;
117
+ const entry = readReturnScroll(key);
118
+ if (!entry) {
119
+ decisionRef.current = { key, y: null, done: true };
120
+ return;
121
+ }
122
+ if (!eligible) {
123
+ // A cold return: nothing cached to restore against. Discard permanently for this visit.
124
+ clearReturnScroll(key);
125
+ decisionRef.current = { key, y: null, done: true };
126
+ return;
127
+ }
128
+ decisionRef.current = { key, y: entry.y, done: false };
129
+ }, [key, eligible]);
130
+
131
+ // Restore once the list is displayed at its real height. The frame is cancelled on unmount
132
+ // or key change; Strict Mode's re-run reschedules it, so exactly one scroll happens.
133
+ React.useEffect(() => {
134
+ const decision = decisionRef.current;
135
+ if (!decision || decision.key !== key || decision.y === null || decision.done || !ready) return;
136
+ if (typeof window === "undefined") return;
137
+ const y = decision.y;
138
+ const frame = window.requestAnimationFrame(() => {
139
+ window.scrollTo({ top: y, left: 0, behavior: "instant" as ScrollBehavior });
140
+ clearReturnScroll(key);
141
+ decision.done = true;
142
+ });
143
+ return () => window.cancelAnimationFrame(frame);
144
+ }, [key, ready]);
145
+
146
+ const save = React.useCallback(() => saveReturnScroll(key), [key]);
147
+
148
+ return { save };
149
+ }
@@ -71,4 +71,10 @@ export { usePagedList } from "./hooks/use-paged-list.js";
71
71
  export type { ListPaginationState, PagedList, UsePagedListOptions } from "./hooks/use-paged-list.js";
72
72
 
73
73
  export { useCursorPage } from "./hooks/use-cursor-page.js";
74
- export type { CursorPage, UseCursorPageOptions } from "./hooks/use-cursor-page.js";
74
+ export type { CursorPage, CursorPager, UseCursorPageOptions } from "./hooks/use-cursor-page.js";
75
+
76
+ // Return-scroll: restore a list's window offset when the user comes back to it after a
77
+ // route change (save on leave, restore once on an eligible + ready return, keyed by the
78
+ // caller's canonical list URL).
79
+ export { useReturnScroll, saveReturnScroll, clearReturnScroll, readReturnScroll } from "./hooks/use-return-scroll.js";
80
+ export type { ReturnScrollEntry, UseReturnScrollOptions, UseReturnScrollResult } from "./hooks/use-return-scroll.js";