@sincpro/web-framework 3.17.0 → 3.19.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.
Files changed (56) hide show
  1. package/README.md +76 -54
  2. package/dist/core/copy.d.ts +2 -0
  3. package/dist/core/copy.js +6 -2
  4. package/dist/core/explain.d.ts +4 -0
  5. package/dist/core/explain.js +4 -0
  6. package/dist/core/groups.d.ts +3 -1
  7. package/dist/core/groups.js +10 -0
  8. package/dist/core/index.d.ts +1 -1
  9. package/dist/core/index.js +1 -1
  10. package/dist/core/lines.d.ts +10 -0
  11. package/dist/core/lines.js +24 -0
  12. package/dist/core/list.d.ts +12 -0
  13. package/dist/react/context.d.ts +29 -0
  14. package/dist/react/context.js +46 -0
  15. package/dist/react/index.d.ts +2 -2
  16. package/dist/react/index.js +2 -2
  17. package/dist/react/useGroups.d.ts +6 -0
  18. package/dist/react/useGroups.js +84 -11
  19. package/dist/react/useNameOf.d.ts +13 -0
  20. package/dist/react/useNameOf.js +32 -0
  21. package/dist/react/useServiceReading.d.ts +8 -0
  22. package/dist/react/useServiceReading.js +12 -2
  23. package/dist/web/index.d.ts +4 -2
  24. package/dist/web/index.js +4 -2
  25. package/dist/web/list/EntityList.d.ts +36 -177
  26. package/dist/web/list/EntityList.js +175 -529
  27. package/dist/web/list/entityList/choosing.d.ts +50 -0
  28. package/dist/web/list/entityList/choosing.js +77 -0
  29. package/dist/web/list/entityList/faces.d.ts +53 -0
  30. package/dist/web/list/entityList/faces.js +155 -0
  31. package/dist/web/list/entityList/grouping.d.ts +50 -0
  32. package/dist/web/list/entityList/grouping.js +97 -0
  33. package/dist/web/list/entityList/opening.d.ts +68 -0
  34. package/dist/web/list/entityList/opening.js +144 -0
  35. package/dist/web/list/entityList/paging.d.ts +30 -0
  36. package/dist/web/list/entityList/paging.js +39 -0
  37. package/dist/web/list/entityList/props.d.ts +173 -0
  38. package/dist/web/list/entityList/props.js +16 -0
  39. package/dist/web/list/entityList/rowActions.d.ts +31 -0
  40. package/dist/web/list/entityList/rowActions.js +40 -0
  41. package/dist/web/list/groups.d.ts +17 -1
  42. package/dist/web/list/groups.js +43 -0
  43. package/dist/web/list/useEntityList.d.ts +183 -0
  44. package/dist/web/list/useEntityList.js +225 -0
  45. package/dist/web/parts.d.ts +42 -0
  46. package/dist/web/parts.js +88 -0
  47. package/dist/web/record/lines.d.ts +3 -0
  48. package/dist/web/record/lines.js +75 -9
  49. package/dist/web/workspace/RecordScreen.d.ts +156 -0
  50. package/dist/web/workspace/RecordScreen.js +197 -0
  51. package/dist/web/workspace/SincproApp.d.ts +3 -1
  52. package/dist/web/workspace/SincproApp.js +22 -4
  53. package/dist/web/workspace/composer.js +1 -1
  54. package/dist/web/workspace/record.d.ts +4 -22
  55. package/dist/web/workspace/record.js +5 -70
  56. package/package.json +3 -3
@@ -0,0 +1,144 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { TRAIL_PARAM } from "@sincpro/client-framework";
4
+ import { frameworkCopy } from "../../../core/copy.js";
5
+ import { trailKeyOf } from "../../../core/trail.js";
6
+ import { useFramework } from "../../../react/context.js";
7
+ import { actionsOf } from "../dock.js";
8
+ import { OpenInMenu, openOptions, targetsFor } from "../openIn.js";
9
+ import { Plus } from "lucide-react";
10
+ import { useEffect, useId, useRef } from "react";
11
+ /** How many lists' trails are kept: the records opened from the last fifty lists page on. */
12
+ const TRAILS = 50;
13
+ /**
14
+ * The trail a record opened from this list walks on: «3 / 64» and its neighbours.
15
+ *
16
+ * Kept current with the page on screen, so the row and its name (`RecordLink`) open the same
17
+ * reference and the record finds where it came from. Never forgotten when the list unmounts —
18
+ * the record it opened replaced it and still walks on it — so the oldest go past a ceiling
19
+ * instead: one per list ever shown, fifty at most.
20
+ */
21
+ export function useListTrail(listing, api, identity, idOf) {
22
+ const { trails } = useFramework();
23
+ const trailKey = trailKeyOf(useId());
24
+ useEffect(() => {
25
+ if (api === undefined)
26
+ return;
27
+ const pages = listing.paging === "pages";
28
+ trails.set(trailKey, {
29
+ route: listing.route,
30
+ question: listing.question,
31
+ key: identity,
32
+ ids: listing.rows.map(idOf),
33
+ offset: pages ? Math.max(0, listing.page.from - 1) : 0,
34
+ size: listing.page.size,
35
+ cursors: pages ? listing.page.cursors : [null],
36
+ after: pages ? listing.page.after : null,
37
+ total: pages ? (listing.count?.value ?? null) : listing.rows.length,
38
+ });
39
+ for (const old of trails.keys()) {
40
+ if (trails.size <= TRAILS)
41
+ break;
42
+ if (old !== trailKey)
43
+ trails.delete(old);
44
+ }
45
+ // The page on screen is what the trail is: its rows, its cursors, its count.
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ }, [
48
+ api,
49
+ trails,
50
+ trailKey,
51
+ listing.rows,
52
+ listing.count,
53
+ listing.page.from,
54
+ listing.page.after,
55
+ ]);
56
+ return trailKey;
57
+ }
58
+ /**
59
+ * What a row does, and where its record may open.
60
+ *
61
+ * A press opens the page — the composer's one predictable gesture —, answers whoever asked
62
+ * (a chooser), or ticks the row (a chooser of several). Every other place the record may open is
63
+ * among the row's ways in, web-ui's (`openTargets` + `onOpenIn`): 👁 for a look, and «Abrir en…»
64
+ * with the rest, in ONE place at the row's end. A chooser only chooses.
65
+ */
66
+ export function useListOpening({ listing, api, idOf, chosen, choosing, choosingMany, embedded, create, actions, onOpen, onPeek, openTargets, onOpenIn, }) {
67
+ const trailKey = useListTrail(listing, api, listing.meta?.identity ?? "id", idOf);
68
+ const refOf = (row) => {
69
+ const ref = listing.entity.ref(idOf(row));
70
+ return { ...ref, params: { ...ref.params, [TRAIL_PARAM]: trailKey } };
71
+ };
72
+ const openWithTrail = (row) => api?.open(refOf(row));
73
+ const opening = onOpen ??
74
+ (api === undefined
75
+ ? undefined
76
+ : choosingMany
77
+ ? (row) => chosen.toggle(idOf(row))
78
+ : choosing
79
+ ? (row) => api.answer(listing.entity.ref(idOf(row)))
80
+ : openWithTrail);
81
+ // «Nuevo» opens the record's form with no id, where the entity can be created.
82
+ const creating = create &&
83
+ api !== undefined &&
84
+ !choosing &&
85
+ !embedded &&
86
+ listing.entity.create !== undefined
87
+ ? () => api.open(listing.entity.newRef())
88
+ : undefined;
89
+ // What the list starts, as data: «Nuevo» — the primary — and the screen's, drawn by the view
90
+ // style (`List.Dock`). Actions drawn by hand stay in the bar, with «Nuevo» beside them.
91
+ const started = actionsOf(actions);
92
+ const startDock = started.drawn !== null
93
+ ? []
94
+ : [
95
+ ...(creating === undefined
96
+ ? []
97
+ : [
98
+ {
99
+ id: "create",
100
+ label: frameworkCopy().record.create,
101
+ icon: Plus,
102
+ primary: true,
103
+ onSelect: creating,
104
+ },
105
+ ]),
106
+ ...started.dock,
107
+ ];
108
+ const openingIn = onOpenIn ??
109
+ (api === undefined
110
+ ? undefined
111
+ : (row, to) => to === "page" ? openWithTrail(row) : api.open(refOf(row), openOptions(to)));
112
+ const targets = choosing || openingIn === undefined
113
+ ? []
114
+ : (openTargets ?? (api === undefined ? [] : targetsFor(api)));
115
+ const elsewhere = targets.filter((to) => to !== "page");
116
+ const peeking = onPeek ??
117
+ (targets.includes("peek") && openingIn !== undefined
118
+ ? (row) => openingIn(row, "peek")
119
+ : undefined);
120
+ // The cells are memoised and web-ui holds the row ways: both reach the opener through a ref,
121
+ // so a screen's inline `onOpenIn` is always the current one without redrawing.
122
+ const openingNow = useRef(openingIn);
123
+ openingNow.current = openingIn;
124
+ const openIn = (row, to) => openingNow.current?.(row, to);
125
+ return {
126
+ refOf,
127
+ /** Whether a row may open elsewhere at all (the cells' link depends on it). */
128
+ opens: openingIn !== undefined,
129
+ /** The places other than the page a row's record may open in. */
130
+ elsewhere,
131
+ /** The rows face takes «Abrir en…» as its row's actions. */
132
+ openInOf: (row) => elsewhere.length === 0 || openingIn === undefined ? null : (_jsx(OpenInMenu, { targets: elsewhere, name: idOf(row), onOpen: (to) => openIn(row, to) })),
133
+ /** What the bar starts: drawn by hand, «Nuevo» beside it; as data, in the dock. */
134
+ started: { drawn: started.drawn, creating, dock: startDock },
135
+ /** web-ui `List`'s props for what a row does. */
136
+ ways: {
137
+ ...(opening === undefined ? {} : { onOpen: opening }),
138
+ ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }),
139
+ ...(elsewhere.length === 0 || openingIn === undefined
140
+ ? {}
141
+ : { openTargets: elsewhere, onOpenIn: openIn }),
142
+ },
143
+ };
144
+ }
@@ -0,0 +1,30 @@
1
+ import type { CommandBodies } from "@sincpro/client-framework";
2
+ import type { AnyRecord } from "@sincpro/criteria";
3
+ import type { Groups } from "../../../react/useGroups.js";
4
+ import type { Listing } from "../../../react/useListing.js";
5
+ import { type DataColumn } from "@sincpro/web-ui";
6
+ import type { ReactNode } from "react";
7
+ /**
8
+ * The way through the set, and whether its figures add up.
9
+ *
10
+ * In `pages` mode the pager walks the server's cursor; in `more` mode «Cargar más» grows the page
11
+ * up to its ceiling; grouped, the server's count of groups and records. Inside a record or a
12
+ * panel only while there is more than what is on screen: «1–5 / 5» repeats the rows.
13
+ *
14
+ * The foot adds up what the model says adds up — over the rows in hand, never a grouped set
15
+ * (each group says its own). While the rows are not the whole set the list says the figures are
16
+ * this page's; inside a record or a panel a page's sum reads as THE total, so an embedded list
17
+ * adds up only when every row is in hand.
18
+ */
19
+ export declare function useListPaging<T extends AnyRecord, C extends CommandBodies>({ listing, groups, grouped, records, columns, embedded, present, }: {
20
+ listing: Listing<T, C>;
21
+ groups: Groups<T>;
22
+ grouped: boolean;
23
+ records: number;
24
+ columns: readonly DataColumn<T>[];
25
+ embedded: boolean;
26
+ present: string;
27
+ }): {
28
+ totalled: boolean;
29
+ paging: ReactNode;
30
+ };
@@ -0,0 +1,39 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { frameworkCopy } from "../../../core/copy.js";
4
+ import { viewOf } from "../../../core/present.js";
5
+ import { Button, Pagination, Tag } from "@sincpro/web-ui";
6
+ /**
7
+ * The way through the set, and whether its figures add up.
8
+ *
9
+ * In `pages` mode the pager walks the server's cursor; in `more` mode «Cargar más» grows the page
10
+ * up to its ceiling; grouped, the server's count of groups and records. Inside a record or a
11
+ * panel only while there is more than what is on screen: «1–5 / 5» repeats the rows.
12
+ *
13
+ * The foot adds up what the model says adds up — over the rows in hand, never a grouped set
14
+ * (each group says its own). While the rows are not the whole set the list says the figures are
15
+ * this page's; inside a record or a panel a page's sum reads as THE total, so an embedded list
16
+ * adds up only when every row is in hand.
17
+ */
18
+ export function useListPaging({ listing, groups, grouped, records, columns, embedded, present, }) {
19
+ const copy = frameworkCopy().list;
20
+ const { page, count, meta, locale } = listing;
21
+ const partial = listing.paging === "pages"
22
+ ? page.hasPrev || page.hasNext
23
+ : listing.hasMore || listing.capped;
24
+ const totalled = !grouped &&
25
+ !(embedded && partial) &&
26
+ listing.rows.length > 0 &&
27
+ columns.some((column) => column.aggregate !== undefined && !column.defaultHidden);
28
+ const fits = embedded && !partial;
29
+ const through = grouped ? (groups.status !== "ready" ? null : (_jsx("span", { className: "text-meta text-muted", children: copy.groups(groups.groupsCount ?? groups.buckets.length, records) }))) : fits ? null : listing.paging === "pages" ? (page.from === 0 ? null : (_jsx(Pagination, { from: page.from, to: page.to, total: count?.value ?? page.to,
30
+ /* The range is touched to choose how many rows fit — in both styles. */
31
+ pageSize: page.size, onPageSizeChange: listing.resize, ...(page.hasPrev ? { onPrev: listing.prev } : {}), ...(page.hasNext ? { onNext: listing.next } : {}) }))) : (_jsxs(_Fragment, { children: [count === null ? null : (_jsx("span", { className: "text-meta text-muted", children: copy.shown(listing.rows.length, count.value, count.exact) })), listing.capped ? (_jsx("span", { className: "text-meta text-muted", children: copy.capped(listing.rows.length) })) : listing.hasMore ? (_jsx(Button, { size: "sm", role: "secondary", disabled: listing.status === "loadingMore", onClick: listing.more, children: listing.status === "loadingMore" ? copy.loading : copy.loadMore })) : null] }));
32
+ // The conditions the server could not apply, said where the set is counted.
33
+ const dropped = listing.dropped.map((d) => viewOf(meta, d.field, locale).label);
34
+ const pageTotals = totalled && partial && present === "table";
35
+ // Its parts side by side and apart: the slot does not space them, and «Totales de esta
36
+ // página» read glued to «1–50 / 112».
37
+ const paging = !pageTotals && dropped.length === 0 && through === null ? null : (_jsxs("span", { className: "flex items-center gap-3", children: [pageTotals ? _jsx("span", { className: "text-meta text-muted", children: copy.pageTotals }) : null, dropped.length === 0 ? null : (_jsx(Tag, { tone: "warn", title: copy.dropped(dropped), children: copy.dropped(dropped) })), through] }));
38
+ return { totalled, paging };
39
+ }
@@ -0,0 +1,173 @@
1
+ import type { CommandBodies } from "@sincpro/client-framework";
2
+ import type { AnyRecord } from "@sincpro/criteria";
3
+ import type { WorkspaceApi } from "@sincpro/web-composer";
4
+ import type { GroupLevel, NamedFilter } from "../../../core/list.js";
5
+ import type { Listing } from "../../../react/useListing.js";
6
+ import type { ListSelection } from "../../../react/useSelection.js";
7
+ import type { ScreenActions } from "../dock.js";
8
+ import type { RowCommand } from "../rowCommands.js";
9
+ import type { ListCrumb, ListEmpty, ListPresentProps, ListSet, OpenTarget, RowAction, YesNoColumn } from "@sincpro/web-ui";
10
+ import type { ReactNode } from "react";
11
+ export type { NamedFilter };
12
+ /**
13
+ * What a screen says to an `EntityList`: values, never regions — a region is a part
14
+ * (`EntityList.Bar`, `EntityList.Table`…).
15
+ */
16
+ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = CommandBodies> = {
17
+ listing: Listing<T, C>;
18
+ /**
19
+ * The workspace this list is a view of. With it, a row opens its record as a page, the
20
+ * identity column is the composer's `RecordLink` (peek, side panel, window on hover) and the
21
+ * breadcrumb is the composer's — nothing for the screen to write.
22
+ */
23
+ api?: WorkspaceApi;
24
+ /** The fields shown, in order. Without it, the named list's, or every scalar field. */
25
+ columns?: readonly string[];
26
+ /** The cells that are not plain text: a link, a tag. Memoise it: compared by identity. */
27
+ cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
28
+ /**
29
+ * How a yes/no column reads, by field — web-ui's `yesNo`: `check` (the default: ✓ and
30
+ * nothing), `icon` (a green ✓ and a quiet ✕), `word` — or a `checkbox` / `switch` that
31
+ * changes it from the list with `onToggle` (an update, a Command). Memoise it.
32
+ *
33
+ * yesNo={{ published: { look: "switch", onToggle: (course, on) => publish.run(course.id, on) } }}
34
+ */
35
+ yesNo?: Readonly<Partial<Record<string, YesNoColumn<T>>>>;
36
+ /**
37
+ * The ways to look at the set, the first one shown: `table` (columns), `rows` (a name and
38
+ * its facts, what a narrow panel wants), `board` (cards), `sheet` (a spreadsheet, every
39
+ * cell a value — web-ui's, windowed) and `tiles` (a grid of pictures — a till's products, a
40
+ * shop's items; asked for, never offered by itself: a set of invoices has no picture). The
41
+ * same set, the same search, the same page in each. Without it, a named list's; else the
42
+ * first four on a screen, and the table (rows when narrow) inside a record. The id of one
43
+ * of `faces` opens on that face.
44
+ */
45
+ views?: readonly (View | (string & {}))[];
46
+ /**
47
+ * The set crossed by two fields — `{ rows: "state", columns: "payment" }` — counted and added
48
+ * up by the server (`usePivot`), offered as the `pivot` face. Only while it is on screen does
49
+ * it ask; never folded from the page.
50
+ */
51
+ pivot?: {
52
+ rows: string | GroupLevel;
53
+ columns: string | GroupLevel;
54
+ /** What each crossing adds up. Without it, the figures the model computes. */
55
+ measures?: readonly string[];
56
+ };
57
+ /** Without it, the model's own name. */
58
+ title?: string;
59
+ description?: string;
60
+ crumbs?: readonly ListCrumb[];
61
+ /**
62
+ * What the list starts — «Importar», «Exportar ▸» —, beside «Nuevo». As data (`DockAction`s)
63
+ * the application's view style draws them with «Nuevo»: the bar's buttons in `traditional`,
64
+ * one pill floating at the bottom in `modern` (web-ui's `ViewStyleProvider`). A node drawn
65
+ * by hand stays in the bar.
66
+ */
67
+ actions?: ScreenActions;
68
+ onOpen?: (row: T) => void;
69
+ onPeek?: (row: T) => void;
70
+ /**
71
+ * Where a row's record may open besides a press (the page): a look (👁), a modal, beside, a
72
+ * window — offered in «Abrir en…» by the row's name. With `api`, everywhere the workspace
73
+ * allows from here (`targetsFor`: no modal from inside a modal); `[]` or a few restrict it.
74
+ */
75
+ openTargets?: readonly OpenTarget[];
76
+ /** Open a row's record there — without `api`, how a screen (a one2many) places it. */
77
+ onOpenIn?: (row: T, to: OpenTarget) => void;
78
+ /**
79
+ * What an empty list says. A text is its sentence; an object is web-ui's empty (2.14) — a
80
+ * `title`, an `icon` or the application's `illustration`, an `action` — for a list that IS the
81
+ * screen («Todavía no hay facturas» with a button to create one). What it leaves out is the
82
+ * framework's words, and `whenFiltered` is what it says when a search emptied it.
83
+ */
84
+ empty?: string | EntityEmpty;
85
+ /**
86
+ * `"bar"` (the default) is the full search bar with the criteria builder; `"box"` is one
87
+ * text box over the entity's search template — a chooser, a narrow panel; `false` is none.
88
+ * Both ask the server on Enter, never per keystroke: a table is searched on purpose.
89
+ */
90
+ search?: "bar" | "box" | false;
91
+ /**
92
+ * The bar remembers, in this browser, the last searches put on this list, and offers them
93
+ * when it takes the focus empty («Recientes»). `true` keeps them under the list's key (a
94
+ * named list's, else its entity's); a text, under that name — one per tenant, say. Off by
95
+ * default: what was searched may name a customer, and whether a browser may keep it is the
96
+ * application's call.
97
+ */
98
+ recent?: boolean | string;
99
+ /** What each group adds up when the list is grouped — «Total 1.204.933,00» in its header,
100
+ * summed by the server over every row of it. Without it, the figures the model computes
101
+ * (read-only exact numbers, `sumsOf`); `false` adds nothing up. */
102
+ sums?: readonly string[] | false;
103
+ /** The cuts this list offers by name: «sólo pagadas», «vencidas». */
104
+ filters?: readonly NamedFilter<T>[];
105
+ /** The fields the search bar offers to look a typed text up in. Without it, the list
106
+ * definition's, else the entity's search template's, else its display (`facetsOf`). */
107
+ facets?: readonly string[];
108
+ /** The fields «Group by» offers, in this order — among those the model lets split the set.
109
+ * Without it, the list definition's, else every one the model does. */
110
+ groupable?: readonly string[];
111
+ /**
112
+ * Rows can be ticked — and, past the page, «Elegir los 187 que coinciden». With `api`, what is
113
+ * chosen is PUBLISHED to the workspace (`api.select`): a panel beside it follows the selection
114
+ * without knowing this list.
115
+ */
116
+ selectable?: boolean;
117
+ /** The selection, held by the screen (`useSelection(listing)`): read and set from outside the
118
+ * list. Without it the list holds its own. */
119
+ selection?: ListSelection<T>;
120
+ /** What to do with what is chosen, while something is — handed the selection to act on it
121
+ * (`useBatchCommand`). As data, the view style draws it: in the bar in place of the search
122
+ * in `traditional`, a pill floating at the bottom in `modern` («3 elegidas ✕ · Confirmar»).
123
+ * Giving it makes the rows choosable: `selectable` is not needed with it. */
124
+ selectionActions?: ScreenActions | ((selection: ListSelection<T>) => ScreenActions);
125
+ /** The list is a FIELD of a record — its lines, its members — and not a screen. */
126
+ embedded?: boolean;
127
+ /**
128
+ * With `api` and an entity that declares `create`, the bar offers «New», which opens the
129
+ * record's form with no id (`entity.newRef()`). `false` hides it — a list of what only a
130
+ * Command produces, or a caller who may not create.
131
+ */
132
+ create?: boolean;
133
+ /**
134
+ * The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
135
+ * the list is read again when one is done (`useRowCommands`).
136
+ */
137
+ commands?: readonly RowCommand<T, C>[];
138
+ /** Any other action of a row — or the commands built by hand with `useRowCommands`. */
139
+ rowActions?: (row: T) => readonly RowAction[];
140
+ /**
141
+ * Ways of looking at the set the SCREEN writes — a gallery, a map, a record with its lines and
142
+ * its buttons — offered beside the built-in ones (web-ui's `List.Present`). Each is handed the
143
+ * same set the others draw: the page, the search's grouping, the selection and what a press
144
+ * does (`ListSet`). Offered after `views`; name one in `views` to open on it.
145
+ */
146
+ faces?: readonly EntityFace<T>[];
147
+ };
148
+ /** A face of a list written by the screen: its name and icon in the switcher, and how it draws
149
+ * the set. `wide` when it needs width (a narrow list does not offer it). */
150
+ export type EntityFace<T> = {
151
+ id: string;
152
+ label: string;
153
+ icon: ListPresentProps<T>["icon"];
154
+ wide?: boolean;
155
+ render: (set: ListSet<T>) => ReactNode;
156
+ };
157
+ /** An empty list as web-ui draws it (`ListEmpty`), every sentence optional: the copy's words. */
158
+ export type EntityEmpty = Omit<ListEmpty, "sentence" | "whenFiltered"> & {
159
+ sentence?: string;
160
+ whenFiltered?: Omit<NonNullable<ListEmpty["whenFiltered"]>, "sentence"> & {
161
+ sentence?: string;
162
+ };
163
+ };
164
+ /** web-ui's empty for this list: what the screen said, over the framework's words. */
165
+ export declare function emptyOf(asked: string | EntityEmpty | undefined, words: {
166
+ empty: string;
167
+ emptyFiltered: string;
168
+ }): ListEmpty;
169
+ /** No commands: one constant, so the hook is not handed a new array on every render. */
170
+ export declare const NO_COMMANDS: readonly never[];
171
+ export type View = "table" | "rows" | "board" | "tiles" | "sheet" | "pivot";
172
+ /** What a list offers when nobody said: every face that needs no configuration. */
173
+ export declare const EVERY_VIEW: readonly View[];
@@ -0,0 +1,16 @@
1
+ /** web-ui's empty for this list: what the screen said, over the framework's words. */
2
+ export function emptyOf(asked, words) {
3
+ const own = typeof asked === "string" ? { sentence: asked } : (asked ?? {});
4
+ return {
5
+ ...own,
6
+ sentence: own.sentence ?? words.empty,
7
+ whenFiltered: {
8
+ ...own.whenFiltered,
9
+ sentence: own.whenFiltered?.sentence ?? words.emptyFiltered,
10
+ },
11
+ };
12
+ }
13
+ /** No commands: one constant, so the hook is not handed a new array on every render. */
14
+ export const NO_COMMANDS = [];
15
+ /** What a list offers when nobody said: every face that needs no configuration. */
16
+ export const EVERY_VIEW = ["table", "rows", "board", "sheet"];
@@ -0,0 +1,31 @@
1
+ import type { CommandBodies } from "@sincpro/client-framework";
2
+ import type { AnyRecord } from "@sincpro/criteria";
3
+ import type { Listing } from "../../../react/useListing.js";
4
+ import { type RowCommand } from "../rowCommands.js";
5
+ import type { RowAction } from "@sincpro/web-ui";
6
+ /**
7
+ * What can be done to one row: the entity's Commands, then whatever else the screen offers —
8
+ * and moving it, when the rows are put in their order by hand.
9
+ *
10
+ * In the trash (`trashOf`) each row is brought back with the entity's own `restore`: it can be
11
+ * undone, so it runs on the click, and the list reads again after. Rows are reordered only on the
12
+ * whole order, never grouped or while choosing.
13
+ */
14
+ export declare function useListRowActions<T extends AnyRecord, C extends CommandBodies>({ listing, idOf, commands, rowActions: asked, grouped, choosing, }: {
15
+ listing: Listing<T, C>;
16
+ idOf: (row: T) => string;
17
+ commands: readonly RowCommand<T, C>[];
18
+ rowActions: ((row: T) => readonly RowAction[]) | undefined;
19
+ grouped: boolean;
20
+ choosing: boolean;
21
+ }): {
22
+ /** The row's actions, for the table; none at all when nothing is offered. */
23
+ rowActions: ((row: T) => RowAction[]) | undefined;
24
+ reorder: import("../reorder.js").Reorder<T>;
25
+ /** A Command or a move the server refused, in words. */
26
+ refused: {
27
+ heading: string;
28
+ sentence: string;
29
+ retryable: boolean;
30
+ } | null;
31
+ };
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { frameworkCopy } from "../../../core/copy.js";
3
+ import { explain } from "../../../core/explain.js";
4
+ import { useReorder } from "../reorder.js";
5
+ import { RESTORE, useRowCommands, } from "../rowCommands.js";
6
+ import { RotateCcw } from "lucide-react";
7
+ import { useMemo } from "react";
8
+ /**
9
+ * What can be done to one row: the entity's Commands, then whatever else the screen offers —
10
+ * and moving it, when the rows are put in their order by hand.
11
+ *
12
+ * In the trash (`trashOf`) each row is brought back with the entity's own `restore`: it can be
13
+ * undone, so it runs on the click, and the list reads again after. Rows are reordered only on the
14
+ * whole order, never grouped or while choosing.
15
+ */
16
+ export function useListRowActions({ listing, idOf, commands, rowActions: asked, grouped, choosing, }) {
17
+ const restoring = listing.definition?.trash === true && listing.entity.restore !== undefined;
18
+ const offered = useMemo(() => restoring
19
+ ? [
20
+ ...commands,
21
+ {
22
+ command: RESTORE,
23
+ label: frameworkCopy().record.restore,
24
+ icon: RotateCcw,
25
+ },
26
+ ]
27
+ : commands, [restoring, commands]);
28
+ const rowCommands = useRowCommands(listing, offered);
29
+ const reorder = useReorder(listing, idOf, !grouped && !choosing);
30
+ const refusal = rowCommands.error ?? reorder.error;
31
+ return {
32
+ /** The row's actions, for the table; none at all when nothing is offered. */
33
+ rowActions: offered.length === 0 && asked === undefined
34
+ ? undefined
35
+ : (row) => [...rowCommands.rowActions(row), ...(asked?.(row) ?? [])],
36
+ reorder,
37
+ /** A Command or a move the server refused, in words. */
38
+ refused: refusal === null ? null : explain(refusal),
39
+ };
40
+ }
@@ -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.
@@ -39,3 +39,19 @@ underColumns?: ReadonlySet<string>, tree?: GroupTree<T>): {
39
39
  bucketAt: ReadonlyMap<string, Bucket<T>>;
40
40
  deepest: number;
41
41
  };
42
+ /**
43
+ * The levels that split by a key of another record (`organo`: an `EntityID[Organo]`, or
44
+ * `customer_id` beside its relation), by the aggregate each key names. Their groups are the
45
+ * keys; a person reads the records' names (`namedPiles`).
46
+ */
47
+ export declare function keyedLevels(meta: Meta | null | undefined, levels: readonly GroupLevel[]): ReadonlyMap<string, string>;
48
+ /** The keys a person reads as names in these piles, each with the aggregate it names. */
49
+ export declare function keysOfPiles<T>(piles: readonly Pile<T>[], keyed: ReadonlyMap<string, string>): {
50
+ target: string;
51
+ id: string;
52
+ }[];
53
+ /**
54
+ * The piles with each key named by its record — «Consejo Técnico», not «CONSEJO_TECNICO» —, as a
55
+ * column of the same key reads. The key until the name arrives, or when nobody names it.
56
+ */
57
+ export declare function namedPiles<T>(piles: readonly Pile<T>[], keyed: ReadonlyMap<string, string>, nameOf: (target: string, id: string) => string | undefined): Pile<T>[];
@@ -3,6 +3,7 @@ import { frameworkCopy } from "../../core/copy.js";
3
3
  import { explain } from "../../core/explain.js";
4
4
  import { detailOf } from "../../core/measure.js";
5
5
  import { textOf } from "../../core/present.js";
6
+ import { relationFieldOf } from "../../core/relation.js";
6
7
  import { dateLabel, pathKey, } from "@sincpro/web-ui";
7
8
  /**
8
9
  * Grouping, as web-ui draws it: which fields may split a set, and the server's groups as the
@@ -118,6 +119,10 @@ underColumns = new Set(), tree) {
118
119
  count: bucket.count,
119
120
  ...summed(bucket),
120
121
  items: deepest ? [...(rowsOf(bucket) ?? [])] : [],
122
+ // Where those rows start among the group's, when a page was turned (web-ui's pager).
123
+ ...(deepest && (tree?.fromOf?.(bucket) ?? 0) > 0
124
+ ? { from: tree?.fromOf?.(bucket) }
125
+ : {}),
121
126
  piles: deepest ? [] : walk(below, path, depth + 1),
122
127
  ...more(bucket, deepest),
123
128
  ...(counted === null || counted === undefined ? {} : { pilesCount: counted }),
@@ -126,3 +131,41 @@ underColumns = new Set(), tree) {
126
131
  });
127
132
  return { piles: walk(buckets, [], 0), bucketAt, deepest: levels.length - 1 };
128
133
  }
134
+ /**
135
+ * The levels that split by a key of another record (`organo`: an `EntityID[Organo]`, or
136
+ * `customer_id` beside its relation), by the aggregate each key names. Their groups are the
137
+ * keys; a person reads the records' names (`namedPiles`).
138
+ */
139
+ export function keyedLevels(meta, levels) {
140
+ return new Map(levels.flatMap((level) => {
141
+ const relation = relationFieldOf(meta, level.field);
142
+ return relation !== undefined && !relation.many && relation.key === level.field
143
+ ? [[level.field, relation.target]]
144
+ : [];
145
+ }));
146
+ }
147
+ /** The keys a person reads as names in these piles, each with the aggregate it names. */
148
+ export function keysOfPiles(piles, keyed) {
149
+ return piles.flatMap((pile) => {
150
+ const target = pile.field === undefined ? undefined : keyed.get(pile.field);
151
+ const own = target === undefined || pile.key === "" ? [] : [{ target, id: pile.key }];
152
+ return [...own, ...keysOfPiles(pile.piles ?? [], keyed)];
153
+ });
154
+ }
155
+ /**
156
+ * The piles with each key named by its record — «Consejo Técnico», not «CONSEJO_TECNICO» —, as a
157
+ * column of the same key reads. The key until the name arrives, or when nobody names it.
158
+ */
159
+ export function namedPiles(piles, keyed, nameOf) {
160
+ if (keyed.size === 0)
161
+ return [...piles];
162
+ return piles.map((pile) => {
163
+ const target = pile.field === undefined ? undefined : keyed.get(pile.field);
164
+ const name = target === undefined ? undefined : nameOf(target, pile.key);
165
+ return {
166
+ ...pile,
167
+ ...(name === undefined ? {} : { label: name }),
168
+ ...(pile.piles === undefined ? {} : { piles: namedPiles(pile.piles, keyed, nameOf) }),
169
+ };
170
+ });
171
+ }