@sincpro/web-framework 3.17.0 → 3.18.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.
@@ -77,6 +77,12 @@ export type Groups<T> = {
77
77
  * has no next page, or the ceiling was reached), `undefined` while the group is unread.
78
78
  * web-ui's `Pile.more`: «Show 50 more of 49,950», or «Showing 500 of 49,950». */
79
79
  brings: (bucket: Bucket<T>) => number | false | undefined;
80
+ /** Turn a group's page — `1` the next, `-1` the one before — in place of the rows it shows,
81
+ * as Odoo's pager on a group's line. Nothing while it reads, or with no page that way. */
82
+ page: (bucket: Bucket<T>, step: 1 | -1) => void;
83
+ /** Where the rows shown start among the group's — `0` on its first page —: web-ui's
84
+ * `Pile.from`, which its pager reads as «51–100 / 2.328». */
85
+ fromOf: (bucket: Bucket<T>) => number;
80
86
  /** Why reading what a group holds failed — its level below or its rows —, or `null`. */
81
87
  errorOf: (bucket: Bucket<T>) => unknown;
82
88
  };
@@ -71,7 +71,9 @@ export function useGroups(listing, options = {}) {
71
71
  if (inFlight.current.has(tag))
72
72
  return;
73
73
  const had = now.current.rows.get(key);
74
- if (mode === "more" && (had === undefined || had.after === null))
74
+ if ((mode === "more" || mode === "next") && (had === undefined || had.after === null))
75
+ return;
76
+ if (mode === "prev" && (had === undefined || had.back.length === 0))
75
77
  return;
76
78
  inFlight.current.add(tag);
77
79
  const { id, signal } = generation.current;
@@ -80,7 +82,14 @@ export function useGroups(listing, options = {}) {
80
82
  ? Math.min(maxRows, Math.max(pageSize, had?.rows.length ?? 0))
81
83
  : pageSize;
82
84
  const first = rowsQuestion(bucket, limit);
83
- const criteria = mode === "more" && had !== undefined ? resumingFrom(first, had.after) : first;
85
+ // The page turned back to: where it started, as it was read then.
86
+ const before = mode === "prev" ? had?.back.at(-1) : undefined;
87
+ // Where this reading starts: after the rows in hand («more», «next»), where the page
88
+ // stepped back to started, or the group's first row.
89
+ const at = (mode === "more" || mode === "next") && had !== undefined
90
+ ? had.after
91
+ : (before?.at ?? null);
92
+ const criteria = at === null ? first : resumingFrom(first, at);
84
93
  if (had !== undefined)
85
94
  setRows((map) => new Map(map).set(key, { ...had, reading: true, error: null }));
86
95
  transport.list(route, criteria, signal).then((page) => {
@@ -88,13 +97,27 @@ export function useGroups(listing, options = {}) {
88
97
  if (generation.current.id !== id)
89
98
  return;
90
99
  setRows((map) => {
91
- const before = mode === "more" ? (map.get(key)?.rows ?? []) : [];
100
+ const held = map.get(key);
101
+ const kept = mode === "more" ? (held?.rows ?? []) : [];
102
+ // «more» adds to the page on screen; «next» and «prev» turn it; the rest start over.
103
+ const place = mode === "more" && held !== undefined
104
+ ? { from: held.from, at: held.at, back: held.back }
105
+ : mode === "next" && held !== undefined
106
+ ? {
107
+ from: held.from + held.rows.length,
108
+ at,
109
+ back: [...held.back, { from: held.from, at: held.at }],
110
+ }
111
+ : mode === "prev" && held !== undefined && before !== undefined
112
+ ? { from: before.from, at: before.at, back: held.back.slice(0, -1) }
113
+ : { from: 0, at: null, back: [] };
92
114
  return new Map(map).set(key, {
93
115
  path,
94
- rows: [...before, ...page.rows],
116
+ rows: [...kept, ...page.rows],
95
117
  after: page.cursor,
96
118
  reading: false,
97
119
  error: null,
120
+ ...place,
98
121
  });
99
122
  });
100
123
  }, (error) => {
@@ -102,7 +125,14 @@ export function useGroups(listing, options = {}) {
102
125
  if (generation.current.id !== id)
103
126
  return;
104
127
  setRows((map) => new Map(map).set(key, {
105
- ...(map.get(key) ?? { path, rows: [], after: null }),
128
+ ...(map.get(key) ?? {
129
+ path,
130
+ rows: [],
131
+ after: null,
132
+ from: 0,
133
+ at: null,
134
+ back: [],
135
+ }),
106
136
  reading: false,
107
137
  error,
108
138
  }));
@@ -372,9 +402,19 @@ export function useGroups(listing, options = {}) {
372
402
  return undefined;
373
403
  if (!hasMore(bucket))
374
404
  return false;
375
- const left = Math.min(maxRows, bucket.count) - read.rows.length;
405
+ // What is left after the rows shown — a group turned to its third page has left what
406
+ // follows it, not what precedes it.
407
+ const left = Math.min(maxRows, bucket.count - read.from) - read.rows.length;
376
408
  return Math.max(0, Math.min(pageSize, left));
377
409
  },
410
+ page: (bucket, step) => {
411
+ const read = readOf(bucket);
412
+ if (read === undefined || read.reading)
413
+ return;
414
+ if (step === 1 ? read.after !== null : read.back.length > 0)
415
+ readRows(bucket, pathOf(bucket), step === 1 ? "next" : "prev");
416
+ },
417
+ fromOf: (bucket) => readOf(bucket)?.from ?? 0,
378
418
  errorOf: (bucket) => (isDeepest(bucket) ? readOf(bucket) : levelOf(bucket))?.error ?? null,
379
419
  };
380
420
  }
@@ -418,6 +418,13 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
418
418
  if (bucket !== undefined)
419
419
  groups.more(bucket);
420
420
  },
421
+ // Odoo's pager on an open group's line — «51–100 / 2.328 ‹ ›» — turns its page in
422
+ // place of its rows (web-ui's `onPage`); «See N more» stays under it.
423
+ onPage: (pile, step) => {
424
+ const bucket = bucketAt.get(pathKey(pile.path));
425
+ if (bucket !== undefined)
426
+ groups.page(bucket, step);
427
+ },
421
428
  // «Ver N grupos más» after the last group of a level: the first level, or the one
422
429
  // under an open group — counted by the server (`groups_count`).
423
430
  ...(groups.groupsCount === null ? {} : { pilesCount: groups.groupsCount }),
@@ -16,7 +16,7 @@ import { type GroupableField, type Pile } from "@sincpro/web-ui";
16
16
  export declare function groupableOf(meta: Meta | null, locale?: string, only?: readonly string[]): GroupableField[];
17
17
  /** The levels below the first, as `useGroups` reads them: each when its group opens, a page at
18
18
  * a time. Without it, the levels below are the ones each bucket carries (`bucket.groups`). */
19
- export type GroupTree<T> = Pick<Groups<T>, "groupsOf" | "groupsCountOf" | "bringsGroups" | "isDeepest" | "errorOf">;
19
+ export type GroupTree<T> = Pick<Groups<T>, "groupsOf" | "groupsCountOf" | "bringsGroups" | "isDeepest" | "errorOf"> & Partial<Pick<Groups<T>, "fromOf">>;
20
20
  /**
21
21
  * The server's groups as piles, with the words a person reads, and each pile's group so that
22
22
  * opening one reads its rows. Rows sit only on the deepest level, once read.
@@ -118,6 +118,10 @@ underColumns = new Set(), tree) {
118
118
  count: bucket.count,
119
119
  ...summed(bucket),
120
120
  items: deepest ? [...(rowsOf(bucket) ?? [])] : [],
121
+ // Where those rows start among the group's, when a page was turned (web-ui's pager).
122
+ ...(deepest && (tree?.fromOf?.(bucket) ?? 0) > 0
123
+ ? { from: tree?.fromOf?.(bucket) }
124
+ : {}),
121
125
  piles: deepest ? [] : walk(below, path, depth + 1),
122
126
  ...more(bucket, deepest),
123
127
  ...(counted === null || counted === undefined ? {} : { pilesCount: counted }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.17.0",
3
+ "version": "3.18.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -55,7 +55,7 @@
55
55
  "@sincpro/criteria": "^2.5.1",
56
56
  "@sincpro/criteria-react": "^2.5.1",
57
57
  "@sincpro/web-composer": "^1.7.0",
58
- "@sincpro/web-ui": "^2.19.0",
58
+ "@sincpro/web-ui": "^2.20.0",
59
59
  "react": ">=19",
60
60
  "react-dom": ">=19"
61
61
  },
@@ -99,7 +99,7 @@
99
99
  "@sincpro/criteria": "^2.5.1",
100
100
  "@sincpro/criteria-react": "^2.5.1",
101
101
  "@sincpro/web-composer": "^1.9.0",
102
- "@sincpro/web-ui": "^2.19.0",
102
+ "@sincpro/web-ui": "^2.20.0",
103
103
  "@storybook/addon-a11y": "10.6.5",
104
104
  "@storybook/addon-docs": "10.6.5",
105
105
  "@storybook/addon-mcp": "10.6.5",