@iyulab/flex-table 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.33.0] - 2026-09-08
4
+
5
+ ### Fixed
6
+
7
+ - **A page could outlive the result set that holds it, leaving an empty table next
8
+ to a non-zero total and a pager pointing at a page that no longer exists.**
9
+ Three axes change the size of a result set, and only two of them moved the page.
10
+
11
+ - **`useODataSource`: changing `fixedFilter` now resets the page to `0`**, the
12
+ same way `setSearch` and `onSortChange` already did. Narrowing a filter while
13
+ on page 5 previously kept the old `$skip` and asked for a range the new set
14
+ does not have. Comparison is by value, so passing a fresh object literal on
15
+ every render does not reset anything on its own, and the reset does not run on
16
+ mount, so it never overrides `initialPage`.
17
+ - **`useODataSource`: a response reporting fewer rows than the current page needs
18
+ falls back to the last page that exists.** A result set can shrink without
19
+ being asked. Reaching that state costs one extra request, only in that case;
20
+ the page only ever moves down, so it cannot loop.
21
+ - **`useArraySource`: paging is clamped to the array passed in.** Shrinking the
22
+ array — the in-memory equivalent of narrowing a filter — falls back to the last
23
+ page that exists instead of rendering nothing.
24
+
25
+ Shrinking clamps rather than resets on purpose: an array or a total can change on
26
+ a routine refresh, and resetting there would move the page out from under the
27
+ reader. The dividing question is whether the change was asked for.
28
+
29
+ ### Changed
30
+
31
+ - **`computeArrayView` returns the last page that exists when given a page past the
32
+ end**, instead of an empty array. It is exported, so a direct caller had the same
33
+ defect; returning nothing for an out-of-range page was never the intended
34
+ contract.
35
+
36
+ ### Internal
37
+
38
+ - First hook tests for this package — everything here was pure functions until now,
39
+ so contracts the README states had no executed evidence behind them. They cover
40
+ the reset and clamp on both hooks, request abort on re-request and on unmount,
41
+ `onUnauthorized` firing on `401`/`403` but not on `500`, initial state being read
42
+ on first render only, and `refresh` being a no-op on the array source.
43
+
3
44
  ## [0.32.0] - 2026-09-08
4
45
 
5
46
  ### Added
package/README.md CHANGED
@@ -587,13 +587,26 @@ const source = useODataSource('/api/orders', {
587
587
  | `initialPage` | `0` | Initial page, **zero-based** — the same axis as the returned `page`/`setPage`, and `$skip` is `page * pageSize` |
588
588
  | `initialSearch` | `''` | Initial search term |
589
589
  | `initialSort` | — | Initial sort as `SortCriteria[]`. Takes precedence over `defaultOrderBy` — it is the shape `onSortChange` hands you, so a stored sort round-trips without re-serializing it |
590
- | `fixedFilter` | — | Filter always applied in addition to search |
590
+ | `fixedFilter` | — | Filter always applied in addition to search. Changing it resets the page to 0 — see below |
591
591
  | `baseUrl` | `window.location.origin` | Override the request origin (proxy/BFF setups) |
592
592
  | `fetcher` | global `fetch` | Custom transport — pass a wrapper that injects auth headers |
593
593
  | `onUnauthorized` | — | Called on `401`/`403` responses, before the generic error is set |
594
594
 
595
595
  `fetcher`/`onUnauthorized` should be stable references (e.g. wrap in `useCallback`) — they are intentionally excluded from the hook's internal effect dependencies to avoid refetch loops on every render.
596
596
 
597
+ Changing `fixedFilter` resets the page to `0`, the same way `setSearch` and `onSortChange`
598
+ already do. All three change the size of the result set, so keeping the old `$skip` would
599
+ request a range the new set no longer has — a filter applied while on page 5 would come back
600
+ empty. Comparison is by value, not by reference, so passing a fresh object literal on every
601
+ render (`fixedFilter={{ IsActive: true }}`) does not reset anything on its own. The reset
602
+ does not run on mount, so it never overrides `initialPage`.
603
+
604
+ If a response reports fewer rows than the current page needs, the page falls back to the
605
+ last page that exists — a result set can shrink without you asking (another user deleting
606
+ rows, a `refresh` landing after a change), and holding the old `$skip` would leave an empty
607
+ table next to a non-zero total. Reaching that state costs one extra request, only in that
608
+ case; the page only ever moves down, so it cannot loop.
609
+
597
610
  The three `initial*` options are read **on the first render only** (the same contract
598
611
  `defaultOrderBy` has always had); use `setPage`/`setSearch` to move afterwards. Reach for
599
612
  them when a list has to come back the way the user left it — going to a detail screen and
@@ -650,6 +663,12 @@ returns the **same shape** as `useODataSource` — `data`/`totalCount`/`loading`
650
663
  `page`/`setPage`/`sortCriteria`/`onSortChange`/`search`/`setSearch`/`refresh` — so the
651
664
  same `<FlexTableReact dataMode="server" ...>` binding code works with either source.
652
665
 
666
+ Paging is clamped to the data you pass: if the array shrinks below the current page — the
667
+ in-memory equivalent of narrowing a filter, usually `rows.filter(...)` upstream — the hook
668
+ falls back to the last page that exists instead of rendering an empty table. It only ever
669
+ moves the page down, so an array that changes identity on every poll without changing length
670
+ leaves the current page alone.
671
+
653
672
  Reach for this when the rows come from a client-side join a server query can't express —
654
673
  e.g. a lookup table whose display name lives on a different endpoint than the row itself,
655
674
  so search/sort has to run after the join, in memory:
@@ -1,13 +1,13 @@
1
1
  import { t as e } from "../sorting-CjfjRxwL.js";
2
- import { r as t } from "../use-odata-source--wXFYeqA.js";
2
+ import { r as t } from "../use-odata-source-6fVz-CLu.js";
3
3
  import { useCallback as n, useMemo as r, useState as i } from "react";
4
4
  //#region src/array/use-array-source.ts
5
5
  function a(t, { search: n, sortCriteria: r, page: i, pageSize: a, columns: o, searchFields: s }) {
6
6
  let c = n.trim().toLowerCase(), l = c ? t.filter((e) => (s ? s(e) : Object.values(e)).some((e) => e != null && String(e).toLowerCase().includes(c))) : t, u = l;
7
7
  r.length > 0 && (u = e(l, r, o ?? []).map((e) => l[e]));
8
- let d = u.length, f = i * a;
8
+ let d = u.length, f = d === 0 ? 0 : Math.ceil(d / a) - 1, p = Math.min(Math.max(i, 0), f) * a;
9
9
  return {
10
- data: u.slice(f, f + a),
10
+ data: u.slice(p, p + a),
11
11
  totalCount: d
12
12
  };
13
13
  }
@@ -37,8 +37,8 @@ function o(e, o = {}) {
37
37
  s,
38
38
  f,
39
39
  p
40
- ]);
41
- return {
40
+ ]), E = T === 0 ? 0 : Math.ceil(T / s) - 1;
41
+ return h > E && g(E), {
42
42
  data: w,
43
43
  totalCount: T,
44
44
  loading: !1,
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,2 @@
1
- import { i as e, n as t, t as n } from "../use-odata-source--wXFYeqA.js";
1
+ import { i as e, n as t, t as n } from "../use-odata-source-6fVz-CLu.js";
2
2
  export { n as buildSearchExpression, t as parseOrderBy, e as useODataSource };
@@ -0,0 +1 @@
1
+ export {};
@@ -19,18 +19,20 @@ function s(s, c = {}) {
19
19
  initialPage: d,
20
20
  initialSearch: f,
21
21
  initialSort: p
22
- }), [O, k] = r(D.page), [A, j] = r(D.sortCriteria), [M, N] = r(D.search), [P, F] = r(0), I = n(null), L = e(() => {
22
+ }), [O, k] = r(D.page), [A, j] = r(D.sortCriteria), [M, N] = r(D.search), [P, F] = r(0), [I, L] = r(v);
23
+ v !== I && (L(v), k(0));
24
+ let R = n(null), z = e(() => {
23
25
  F((e) => e + 1);
24
- }, []), R = e((e) => {
26
+ }, []), B = e((e) => {
25
27
  N(e), k(0);
26
- }, []), z = e((e) => {
28
+ }, []), V = e((e) => {
27
29
  let t = e.detail?.criteria;
28
30
  t && (j(t), k(0));
29
31
  }, []);
30
32
  return t(() => {
31
- I.current?.abort();
33
+ R.current?.abort();
32
34
  let e = new AbortController();
33
- I.current = e, w(!0), E(null);
35
+ R.current = e, w(!0), E(null);
34
36
  let t = A.length > 0 ? A.map((e) => `${e.key} ${e.direction}`).join(", ") : u, n = {
35
37
  top: l,
36
38
  skip: O * l,
@@ -53,7 +55,11 @@ function s(s, c = {}) {
53
55
  }
54
56
  return e.json();
55
57
  }).then((t) => {
56
- e.signal.aborted || (b(t.value ?? t), S(t["@odata.count"] ?? 0), E(null));
58
+ if (e.signal.aborted) return;
59
+ let n = t["@odata.count"] ?? 0;
60
+ b(t.value ?? t), S(n), E(null);
61
+ let r = n === 0 ? 0 : Math.ceil(n / l) - 1;
62
+ O > r && k(r);
57
63
  }).catch((t) => {
58
64
  e.signal.aborted || t.name !== "AbortError" && (E(t.message), b([]), S(0));
59
65
  }).finally(() => {
@@ -77,10 +83,10 @@ function s(s, c = {}) {
77
83
  page: O,
78
84
  setPage: k,
79
85
  sortCriteria: A,
80
- onSortChange: z,
86
+ onSortChange: V,
81
87
  search: M,
82
- setSearch: R,
83
- refresh: L
88
+ setSearch: B,
89
+ refresh: z
84
90
  };
85
91
  }
86
92
  function c(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iyulab/flex-table",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "description": "A minimalist, input-centric data grid web component",
5
5
  "type": "module",
6
6
  "main": "./dist/flex-table.js",
@@ -88,6 +88,7 @@
88
88
  "@lit/react": "^1.0.8",
89
89
  "@types/node": "^26.1.1",
90
90
  "@types/react": "^19.2.17",
91
+ "@types/react-dom": "^19.2.7",
91
92
  "@typescript-eslint/eslint-plugin": "^8.64.0",
92
93
  "@typescript-eslint/parser": "^8.64.0",
93
94
  "eslint": "^10.1.0",
@@ -95,6 +96,7 @@
95
96
  "jsdom": "^29.1.1",
96
97
  "loupe": "^3.2.1",
97
98
  "react": "^19.2.7",
99
+ "react-dom": "^19.2.8",
98
100
  "strip-literal": "^3.1.0",
99
101
  "typescript": "~5.7.0",
100
102
  "vite": "^8.1.4",