@sincpro/web-framework 0.2.0 → 0.3.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 (64) hide show
  1. package/README.md +56 -19
  2. package/dist/core/copy.d.ts +2 -0
  3. package/dist/core/copy.js +2 -0
  4. package/dist/core/edit.d.ts +35 -3
  5. package/dist/core/edit.js +49 -5
  6. package/dist/core/entity.d.ts +14 -2
  7. package/dist/core/entity.js +33 -1
  8. package/dist/core/index.d.ts +3 -2
  9. package/dist/core/index.js +3 -2
  10. package/dist/core/lines.d.ts +53 -0
  11. package/dist/core/lines.js +120 -0
  12. package/dist/core/list.d.ts +1 -1
  13. package/dist/core/lookup.d.ts +2 -0
  14. package/dist/core/lookup.js +3 -1
  15. package/dist/core/rest.d.ts +5 -9
  16. package/dist/core/rest.js +14 -6
  17. package/dist/core/transport.d.ts +9 -1
  18. package/dist/react/context.d.ts +8 -0
  19. package/dist/react/index.d.ts +2 -1
  20. package/dist/react/index.js +1 -0
  21. package/dist/react/useGroups.d.ts +13 -1
  22. package/dist/react/useGroups.js +48 -7
  23. package/dist/react/useListing.d.ts +8 -4
  24. package/dist/react/useListing.js +11 -5
  25. package/dist/react/usePivot.d.ts +33 -0
  26. package/dist/react/usePivot.js +59 -0
  27. package/dist/react/useRecord.d.ts +13 -9
  28. package/dist/react/useRecord.js +55 -13
  29. package/dist/web/index.d.ts +7 -1
  30. package/dist/web/index.js +7 -1
  31. package/dist/web/list/EntityList.d.ts +46 -7
  32. package/dist/web/list/EntityList.js +132 -21
  33. package/dist/web/list/EntitySearchBar.js +19 -1
  34. package/dist/web/list/columns.d.ts +0 -13
  35. package/dist/web/list/columns.js +20 -1
  36. package/dist/web/list/groups.d.ts +3 -1
  37. package/dist/web/list/groups.js +8 -1
  38. package/dist/web/list/openIn.d.ts +41 -0
  39. package/dist/web/list/openIn.js +55 -0
  40. package/dist/web/list/pivot.d.ts +23 -0
  41. package/dist/web/list/pivot.js +64 -0
  42. package/dist/web/list/presentation.d.ts +51 -0
  43. package/dist/web/list/presentation.js +20 -0
  44. package/dist/web/record/EntityPicker.d.ts +3 -1
  45. package/dist/web/record/EntityPicker.js +15 -5
  46. package/dist/web/record/EntityTags.js +16 -5
  47. package/dist/web/record/RelatedList.d.ts +6 -0
  48. package/dist/web/record/RelatedList.js +26 -2
  49. package/dist/web/record/control.d.ts +42 -0
  50. package/dist/web/record/control.js +60 -0
  51. package/dist/web/record/edit.d.ts +16 -8
  52. package/dist/web/record/edit.js +57 -49
  53. package/dist/web/record/lines.d.ts +84 -0
  54. package/dist/web/record/lines.js +190 -0
  55. package/dist/web/record/opening.d.ts +8 -0
  56. package/dist/web/record/summary.js +14 -6
  57. package/dist/web/workspace/composer.d.ts +2 -1
  58. package/dist/web/workspace/composer.js +27 -16
  59. package/dist/web/workspace/open.d.ts +2 -14
  60. package/dist/web/workspace/open.js +2 -13
  61. package/dist/web/workspace/record.js +6 -3
  62. package/dist/web/workspace/workspace.d.ts +4 -2
  63. package/dist/web/workspace/workspace.js +10 -4
  64. package/package.json +9 -9
@@ -1,9 +1,9 @@
1
1
  import { type AnyRecord } from "@sincpro/criteria";
2
2
  import { type WorkspaceApi } from "@sincpro/web-composer";
3
- import type { NamedFilter } from "../../core/list.js";
3
+ import type { GroupLevel, NamedFilter } from "../../core/list.js";
4
4
  import type { Listing } from "../../react/useListing.js";
5
5
  import { type RowCommand } from "./rowCommands.js";
6
- import { type ListCrumb, type RowAction } from "@sincpro/web-ui";
6
+ import { type ListCrumb, type ListPresentProps, type ListSet, type OpenTarget, type RowAction } from "@sincpro/web-ui";
7
7
  import { type ReactNode } from "react";
8
8
  /**
9
9
  * A whole collection from a `Listing`: the bar, the search, the set in the views it offers,
@@ -20,7 +20,8 @@ import { type ReactNode } from "react";
20
20
  *
21
21
  * Grouping obeys the same rule: «Group by» in the search bar asks the SERVER for the groups of
22
22
  * the whole set (`useGroups`), drawn as piles with their real count; a group's rows are read
23
- * when it is opened. Grouped, the list shows rows: web-ui's table groups the page it holds.
23
+ * when it is opened, and «See N more» reads its next page on the server's cursor. Since web-ui
24
+ * 1.4 every face draws piles counted elsewhere — the table too — so grouping keeps the face.
24
25
  *
25
26
  * Where a record opens is the composer's question: with `api`, a row opens the page and the
26
27
  * identity column is the composer's `RecordLink` (peek, side panel, window); without it, the
@@ -41,10 +42,23 @@ export type EntityListProps<T extends AnyRecord> = {
41
42
  cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
42
43
  /**
43
44
  * The ways to look at the set, the first one shown: `table` (columns), `rows` (a name and
44
- * its facts, what a narrow panel wants) and `board` (cards). The same set, the same search,
45
- * the same page in each.
45
+ * its facts, what a narrow panel wants), `board` (cards) and `sheet` (a spreadsheet, every
46
+ * cell a value — web-ui's, windowed). The same set, the same search, the same page in each.
47
+ * Without it, a named list's; else all four on a screen, and the table (rows when narrow)
48
+ * inside a record. The id of one of `faces` opens on that face.
46
49
  */
47
- views?: readonly ("table" | "rows" | "board")[];
50
+ views?: readonly (View | (string & {}))[];
51
+ /**
52
+ * The set crossed by two fields — `{ rows: "state", columns: "payment" }` — counted and added
53
+ * up by the server (`usePivot`), offered as the `pivot` face. Only while it is on screen does
54
+ * it ask; never folded from the page.
55
+ */
56
+ pivot?: {
57
+ rows: string | GroupLevel;
58
+ columns: string | GroupLevel;
59
+ /** What each crossing adds up. Without it, the figures the model computes. */
60
+ measures?: readonly string[];
61
+ };
48
62
  /** Without it, the model's own name. */
49
63
  title?: string;
50
64
  description?: string;
@@ -52,6 +66,14 @@ export type EntityListProps<T extends AnyRecord> = {
52
66
  actions?: ReactNode;
53
67
  onOpen?: (row: T) => void;
54
68
  onPeek?: (row: T) => void;
69
+ /**
70
+ * Where a row's record may open besides a press (the page): a look (👁), a modal, beside, a
71
+ * window — offered in «Abrir en…» by the row's name. With `api`, everywhere the workspace
72
+ * allows from here (`targetsFor`: no modal from inside a modal); `[]` or a few restrict it.
73
+ */
74
+ openTargets?: readonly OpenTarget[];
75
+ /** Open a row's record there — without `api`, how a screen (a one2many) places it. */
76
+ onOpenIn?: (row: T, to: OpenTarget) => void;
55
77
  /** What an empty list says. */
56
78
  empty?: string;
57
79
  /**
@@ -88,5 +110,22 @@ export type EntityListProps<T extends AnyRecord> = {
88
110
  commands?: readonly RowCommand<T>[];
89
111
  /** Any other action of a row — or the commands built by hand with `useRowCommands`. */
90
112
  rowActions?: (row: T) => readonly RowAction[];
113
+ /**
114
+ * Ways of looking at the set the SCREEN writes — a gallery, a map, a record with its lines and
115
+ * its buttons — offered beside the built-in ones (web-ui's `List.Present`). Each is handed the
116
+ * same set the others draw: the page, the search's grouping, the selection and what a press
117
+ * does (`ListSet`). Offered after `views`; name one in `views` to open on it.
118
+ */
119
+ faces?: readonly EntityFace<T>[];
120
+ };
121
+ /** A face of a list written by the screen: its name and icon in the switcher, and how it draws
122
+ * the set. `wide` when it needs width (a narrow list does not offer it). */
123
+ export type EntityFace<T> = {
124
+ id: string;
125
+ label: string;
126
+ icon: ListPresentProps<T>["icon"];
127
+ wide?: boolean;
128
+ render: (set: ListSet<T>) => ReactNode;
91
129
  };
92
- export declare function EntityList<T extends AnyRecord>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, }: EntityListProps<T>): import("react").JSX.Element;
130
+ export type View = "table" | "rows" | "board" | "sheet" | "pivot";
131
+ export declare function EntityList<T extends AnyRecord>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T>): import("react").JSX.Element;
@@ -8,12 +8,16 @@ import { textOf, viewOf } from "../../core/present.js";
8
8
  import { explain } from "../../core/transport.js";
9
9
  import { useFramework } from "../../react/context.js";
10
10
  import { useGroups } from "../../react/useGroups.js";
11
+ import { usePivot } from "../../react/usePivot.js";
11
12
  import { columnsOf } from "./columns.js";
12
13
  import { EntitySearchBar } from "./EntitySearchBar.js";
13
14
  import { pilesOf } from "./groups.js";
15
+ import { OpenInMenu, openOptions, targetsFor } from "./openIn.js";
16
+ import { pivotOf } from "./pivot.js";
17
+ import { over, presentationOf } from "./presentation.js";
14
18
  import { useRowCommands } from "./rowCommands.js";
15
- import { Button, Callout, List, Pagination, SearchField, Tag, } from "@sincpro/web-ui";
16
- import { useEffect, useId, useMemo, useState } from "react";
19
+ import { Button, Callout, List, Pagination, pathKey, RecordCard, SearchField, Tag, } from "@sincpro/web-ui";
20
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
17
21
  /** What `useCrumbs` reads when the list is not in a workspace: no trail, and nothing to follow. */
18
22
  const NO_TRAIL = [];
19
23
  const NO_WORKSPACE = {
@@ -24,12 +28,16 @@ const NO_WORKSPACE = {
24
28
  const TRAILS = 50;
25
29
  /** No commands: one constant, so the hook is not handed a new array on every render. */
26
30
  const NO_COMMANDS = [];
27
- export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, empty, search = "bar", sums, filters: askedFilters, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, }) {
31
+ /** What a list offers when nobody said: every face that needs no configuration. */
32
+ const EVERY_VIEW = ["table", "rows", "board", "sheet"];
33
+ export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
28
34
  // A named list (`defineList`) brings its own columns, filters, faces and words; what the
29
35
  // screen passes wins.
30
36
  const definition = listing.definition;
31
37
  const columns = askedColumns ?? definition?.columns;
32
- const views = askedViews ?? definition?.views ?? ["table"];
38
+ const views = askedViews ??
39
+ definition?.views ??
40
+ (embedded ? ["table"] : pivotAsked === undefined ? EVERY_VIEW : [...EVERY_VIEW, "pivot"]);
33
41
  const filters = askedFilters ?? definition?.filters ?? [];
34
42
  const title = askedTitle ?? definition?.title;
35
43
  const description = askedDescription ?? definition?.description;
@@ -109,14 +117,33 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
109
117
  listing.entity.create !== undefined
110
118
  ? () => api.open(listing.entity.newRef())
111
119
  : undefined;
112
- // A row click opens the page — the composer's one predictable gesture. web-ui's table turns a
113
- // row click into a PEEK whenever `onPeek` is given, so the list never passes one by itself:
114
- // the peek, the side panel and the window are the composer's `RecordLink` on the identity.
115
- const linked = api === undefined || choosing || cells?.[identity] !== undefined
120
+ // A press opens the page — the composer's one predictable gesture. Every other place the
121
+ // record may open is offered beside its name («Abrir en…») and, for a look, as web-ui's 👁
122
+ // (`onPeek` with `rowClick="open"`: the press stays «open»). A chooser only chooses.
123
+ const openingIn = onOpenIn ??
124
+ (api === undefined
125
+ ? undefined
126
+ : (row, to) => to === "page" ? openWithTrail(row) : api.open(refOf(row), openOptions(to)));
127
+ const targets = choosing || openingIn === undefined
128
+ ? []
129
+ : (openTargets ?? (api === undefined ? [] : targetsFor(api)));
130
+ const elsewhere = targets.filter((to) => to !== "page");
131
+ const peeking = onPeek ??
132
+ (targets.includes("peek") && openingIn !== undefined
133
+ ? (row) => openingIn(row, "peek")
134
+ : undefined);
135
+ // The cells are memoised (below): they reach the opener through a ref, so a screen's inline
136
+ // `onOpenIn` is always the current one without redrawing every cell.
137
+ const openingNow = useRef(openingIn);
138
+ openingNow.current = openingIn;
139
+ const openInOf = (row) => elsewhere.length === 0 || openingIn === undefined ? null : (_jsx(OpenInMenu, { targets: elsewhere, name: idOf(row), onOpen: (to) => openingNow.current?.(row, to) }));
140
+ const linked = choosing ||
141
+ cells?.[identity] !== undefined ||
142
+ (api === undefined && elsewhere.length === 0)
116
143
  ? cells
117
144
  : {
118
145
  ...cells,
119
- [identity]: (row) => (_jsx(RecordLink, { api: api, resource: refOf(row), children: idOf(row) })),
146
+ [identity]: (row) => (_jsxs("span", { className: "inline-flex items-center gap-1", children: [api === undefined ? (idOf(row)) : (_jsx(RecordLink, { api: api, resource: refOf(row), children: idOf(row) })), openInOf(row)] })),
120
147
  };
121
148
  // `useCrumbs`, not `api.crumbs()`: the crumb must follow a name given later (`setTitle`).
122
149
  // Without a workspace it reads a trail that never changes — a hook cannot be skipped.
@@ -149,25 +176,81 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
149
176
  const names = columns?.join("\u0000");
150
177
  const shown = useMemo(() => columnsOf(meta, columns, { locale, ...(linked ? { cells: linked } : {}) }),
151
178
  // eslint-disable-next-line react-hooks/exhaustive-deps
152
- [meta, locale, names, cells, api]);
179
+ [meta, locale, names, cells, api, elsewhere.join(), openingIn === undefined]);
153
180
  // A row and a card read the record by its display and the first fields shown beside it.
154
181
  const display = meta?.display || identity;
155
182
  const facts = shown
156
183
  .filter((c) => c.id !== display && c.id !== identity && !c.defaultHidden)
157
184
  .slice(0, 3);
158
- const rowOf = (row) => ({
185
+ // The entity's own look of a row and a card (`presented`) goes over these defaults.
186
+ const look = presentationOf(listing.entity);
187
+ // The pivot asks the server only while it is the face on screen.
188
+ const axes = pivotAsked === undefined || present !== "pivot" || !views.includes("pivot")
189
+ ? null
190
+ : {
191
+ rows: typeof pivotAsked.rows === "string"
192
+ ? { field: pivotAsked.rows }
193
+ : pivotAsked.rows,
194
+ columns: typeof pivotAsked.columns === "string"
195
+ ? { field: pivotAsked.columns }
196
+ : pivotAsked.columns,
197
+ ...(pivotAsked.measures === undefined ? {} : { measures: pivotAsked.measures }),
198
+ };
199
+ const crossing = usePivot(listing, axes);
200
+ const folded = axes === null
201
+ ? null
202
+ : pivotOf({
203
+ crossed: crossing.crossed,
204
+ byColumn: crossing.columns,
205
+ rows: axes.rows,
206
+ columns: axes.columns,
207
+ measures: crossing.measures,
208
+ meta,
209
+ locale,
210
+ });
211
+ // The sheet's columns are the table's on screen: one set of fields, two ways to read them.
212
+ const sheetColumns = useMemo(() => shown
213
+ .filter((column) => !column.defaultHidden)
214
+ .map((column) => ({
215
+ id: column.id,
216
+ header: String(column.header),
217
+ ...(column.numeric === true ? { numeric: true } : {}),
218
+ })), [shown]);
219
+ const sortStates = useMemo(() => listing.order.map((one) => ({
220
+ key: one.field,
221
+ direction: one.descending ? "desc" : "asc",
222
+ })), [listing.order]);
223
+ const sortable = useMemo(() => shown
224
+ .filter((column) => column.sortable === true && column.field !== undefined)
225
+ .map((column) => ({ field: column.field, label: String(column.header) })), [shown]);
226
+ const rowOf = (row) => over({
159
227
  name: textOf(meta, display, row[display], locale) ?? idOf(row),
160
228
  meta: [
161
229
  ...(display === identity ? [] : [idOf(row)]),
162
230
  ...facts.map((c) => textOf(meta, c.id, row[c.id], locale)).filter(Boolean),
163
231
  ].join(" · "),
164
- });
232
+ ...(elsewhere.length === 0 ? {} : { actions: openInOf(row) }),
233
+ }, look.row?.(row));
234
+ // Without a look of its own, the board's card is web-ui's, made of the row. With one, the
235
+ // same card — the row's name, meta and tags — under it, and pressing it is still the list's:
236
+ // web-ui (1.5) hands an own card the list's press rule (`ways.press`: open, or choose).
237
+ const ownCard = look.card;
238
+ const cardOfRow = ownCard === undefined
239
+ ? undefined
240
+ : (row, ways) => {
241
+ const d = rowOf(row);
242
+ return (_jsx(RecordCard, { ...over({
243
+ title: d.name,
244
+ ...(d.tags === undefined ? {} : { tags: d.tags }),
245
+ ...(d.meta === undefined ? {} : { meta: d.meta }),
246
+ }, ownCard(row)), ...(ways.press === undefined ? {} : { onOpen: ways.press }) }));
247
+ };
165
248
  // Grouped: the SERVER counts the groups; a group's rows are read when it is opened, so every
166
- // group starts closed. web-ui's table groups the rows it holds — the page — so a grouped list
167
- // shows rows, the face that draws the piles it is given.
249
+ // group starts closed. Every face of web-ui (1.4) draws these piles, the table included, and
250
+ // each says what its next «more» brings (1.5).
168
251
  const groups = useGroups(listing, sums === undefined ? {} : { sums: sums || [] });
169
252
  const grouped = groups.levels.length > 0;
170
- const { piles, bucketAt } = pilesOf(groups.buckets, groups.levels, meta, locale, groups.rowsOf);
253
+ const { piles, bucketAt } = pilesOf(groups.buckets, groups.levels, meta, locale, groups.rowsOf, groups.brings);
171
254
  const [opened, setOpened] = useState(() => new Set());
172
255
  useEffect(() => setOpened(new Set()), [groups.buckets]);
173
256
  const collapsed = [...bucketAt.keys()].filter((key) => !opened.has(key));
@@ -193,6 +276,12 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
193
276
  piles,
194
277
  collapsed,
195
278
  onToggle: toggle,
279
+ // «See N more» inside an open group: its next page, on the server's cursor (web-ui 1.4).
280
+ onMore: (pile) => {
281
+ const bucket = bucketAt.get(pathKey(pile.path));
282
+ if (bucket !== undefined)
283
+ groups.more(bucket);
284
+ },
196
285
  },
197
286
  }
198
287
  : {};
@@ -203,27 +292,49 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
203
292
  ? undefined
204
293
  : (row) => [...rowCommands.rowActions(row), ...(askedRowActions?.(row) ?? [])];
205
294
  const refused = rowCommands.error === null ? null : explain(rowCommands.error);
206
- return (_jsxs(List, { items: listing.rows, keyOf: idOf, embedded: embedded, present: grouped ? "rows" : present, onPresentChange: (next) => setPresent(next), ...grouping, sort: listing.order === null
207
- ? null
208
- : { key: listing.order.field, direction: listing.order.descending ? "desc" : "asc" }, onSortChange: (next) => listing.orderBy(next === null ? null : { field: next.key, descending: next.direction === "desc" }), state: {
295
+ return (_jsxs(List, { items: listing.rows, keyOf: idOf, embedded: embedded, present: present, onPresentChange: setPresent, ...grouping,
296
+ // The whole order, as web-ui 1.7 shows and sets it: ⇧-click on a header adds a field,
297
+ // the sort menu reorders them — the same list the criteria builder writes.
298
+ sort: sortStates,
299
+ // The faces with no headers (rows, board) sort too, by the fields the model marks
300
+ // sortable — on the server, so no `value` is given.
301
+ sortable: sortable, onSortChange: (next) => listing.orderBy(next.map((one) => ({ field: one.key, descending: one.direction === "desc" }))), state: {
209
302
  // Only the FIRST reading shows the skeleton. Refining (typing, a filter, the next
210
303
  // page) keeps the rows on screen until the server answers: web-ui swaps the body for
211
304
  // a skeleton while `loading`, and a row that vanished under the pointer lost a click.
305
+ // Meanwhile `refreshing` (web-ui 1.4) draws a quiet bar over the rows: asking, not gone.
212
306
  loading: grouped
213
- ? groups.status === "loading"
307
+ ? groups.status === "loading" && groups.buckets.length === 0
214
308
  : listing.status === "loading" && listing.rows.length === 0,
309
+ refreshing: grouped
310
+ ? groups.status === "loading" && groups.buckets.length > 0
311
+ : listing.status === "loading" && listing.rows.length > 0,
215
312
  error: failure === null
216
313
  ? null
217
314
  : [failure.heading, failure.sentence].filter(Boolean).join(". "),
218
315
  }, filtered: listing.where !== undefined || listing.text !== "", empty: {
219
316
  sentence: empty ?? copy.empty,
220
317
  whenFiltered: { sentence: copy.emptyFiltered },
221
- }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(onPeek === undefined ? {} : { onPeek }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
318
+ }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
222
319
  setDraft(next);
223
320
  // Emptied (or cleared with ×): the whole set again, at once.
224
321
  if (next === "" && listing.text !== "")
225
322
  listing.search("", { now: true });
226
323
  }, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, actions === undefined && creating === undefined ? null : (_jsxs(List.Actions, { children: [actions, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })), _jsxs(List.Pagination, { children: [dropped.length === 0 ? null : (_jsx(Tag, { tone: "warn", title: copy.dropped(dropped), children: copy.dropped(dropped) })), grouped ? (groups.status !== "ready" ? null : (_jsx("span", { className: "text-meta text-muted", children: groups.capped
227
324
  ? copy.groupsCapped(groups.buckets.length)
228
- : copy.groups(groups.buckets.length, records) }))) : listing.paging === "pages" ? (page.from === 0 ? null : (_jsx(Pagination, { from: page.from, to: page.to, total: count?.value ?? page.to, ...(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] }))] })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(rowActions === undefined ? {} : { rowActions }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("board") ? _jsx(List.Board, {}) : null, refused === null ? null : (_jsx(Callout, { tone: "bad", title: refused.heading, children: refused.sentence }))] }));
325
+ : copy.groups(groups.buckets.length, records) }))) : listing.paging === "pages" ? (page.from === 0 ? null : (_jsx(Pagination, { from: page.from, to: page.to, total: count?.value ?? page.to, ...(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] }))] })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(rowActions === undefined ? {} : { rowActions }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, { columns: sheetColumns, cell: (row, column) => {
326
+ const value = row[column.id];
327
+ return value === null || value === undefined
328
+ ? null
329
+ : (textOf(meta, column.id, value, locale) ?? String(value));
330
+ } })) : null, views.includes("pivot") ? (_jsx(List.Pivot, { folded: folded ??
331
+ pivotOf({
332
+ crossed: [],
333
+ byColumn: [],
334
+ rows: { field: "" },
335
+ columns: { field: "" },
336
+ measures: [],
337
+ meta,
338
+ locale,
339
+ }) })) : null, views.includes("board") ? (_jsx(List.Board, { ...(cardOfRow === undefined ? {} : { card: cardOfRow }) })) : null, (faces ?? []).map((face) => (_jsx(List.Present, { id: face.id, label: face.label, icon: face.icon, ...(face.wide === undefined ? {} : { wide: face.wide }), children: face.render }, face.id))), refused === null ? null : (_jsx(Callout, { tone: "bad", title: refused.heading, children: refused.sentence }))] }));
229
340
  }
@@ -64,10 +64,28 @@ export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
64
64
  ? {}
65
65
  : {
66
66
  literal: (text) => matching(meta, text).where ?? null,
67
- }) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(whereOf(put) === undefined ? {} : { initial: { where: whereOf(put) } }), onApply: (built) => {
67
+ }) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(whereOf(put) === undefined && listing.order.length === 0
68
+ ? {}
69
+ : {
70
+ initial: {
71
+ ...(whereOf(put) === undefined ? {} : { where: whereOf(put) }),
72
+ ...(listing.order.length === 0
73
+ ? {}
74
+ : {
75
+ order: listing.order.map((one) => ({
76
+ field: String(one.field),
77
+ ...(one.descending === true ? { descending: true } : {}),
78
+ })),
79
+ }),
80
+ },
81
+ }), onApply: (built) => {
68
82
  place(built?.where === undefined
69
83
  ? []
70
84
  : [filterCriteria(built.where, describeFilter(built.where, model))]);
85
+ listing.orderBy((built?.order ?? []).map((one) => ({
86
+ field: one.field,
87
+ ...(one.descending === true ? { descending: true } : {}),
88
+ })));
71
89
  setBuilding(false);
72
90
  }, onCancel: () => setBuilding(false) }) })) : null] }));
73
91
  }
@@ -1,19 +1,6 @@
1
1
  import type { AnyRecord, Meta } from "@sincpro/criteria";
2
2
  import type { DataColumn } from "@sincpro/web-ui";
3
3
  import type { ReactNode } from "react";
4
- /**
5
- * The columns of a table, from the model: name the fields, the rest follows.
6
- *
7
- * Context: forge's lists wrote every column by hand — `header: "nombre"`, `value: (p) =>
8
- * p.display_name`, a date formatter per screen — while the server already said what each field
9
- * is called and what type it holds. Here a column is a NAME: its header is the model's label,
10
- * its cell the text the value reads as (`textOf`), its sort key the raw value, and whether it
11
- * can be ordered is what the server said (`sortable`). A cell that needs more than text — a
12
- * link, a tag — is the one thing a screen writes (`cells`).
13
- *
14
- * The fields NOT named still exist: they come after, `optional` and hidden, so the columns
15
- * menu offers them and nobody edits the screen to see a field the server already sends.
16
- */
17
4
  export type ColumnOptions<T> = {
18
5
  locale?: string | undefined;
19
6
  /** The cells that are not plain text, by field name. */
@@ -1,14 +1,33 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  import { BOOKKEEPING, defaultFields, sortKeyOf, textOf, viewOf, } from "../../core/present.js";
3
+ /**
4
+ * The columns of a table, from the model: name the fields, the rest follows.
5
+ *
6
+ * Context: forge's lists wrote every column by hand — `header: "nombre"`, `value: (p) =>
7
+ * p.display_name`, a date formatter per screen — while the server already said what each field
8
+ * is called and what type it holds. Here a column is a NAME: its header is the model's label,
9
+ * its cell the text the value reads as (`textOf`), its sort key the raw value, and whether it
10
+ * can be ordered is what the server said (`sortable`). A cell that needs more than text — a
11
+ * link, a tag — is the one thing a screen writes (`cells`).
12
+ *
13
+ * The fields NOT named still exist: they come after, `optional` and hidden, so the columns
14
+ * menu offers them and nobody edits the screen to see a field the server already sends.
15
+ */
16
+ /** The types whose value is one short thing, read whole. */
17
+ const DATES = new Set(["date", "datetime", "time"]);
2
18
  function columnOf(meta, name, options, hidden) {
3
19
  const view = viewOf(meta, name, options.locale);
4
20
  const text = (row) => textOf(meta, name, row[name], options.locale) ?? "";
5
21
  const own = options.cells?.[name];
22
+ // A code, a date, an amount is read whole: «F-2026-0060» in three lines is three values.
23
+ const whole = view.name === meta?.identity || view.numeric || DATES.has(view.type);
6
24
  return {
7
25
  id: name,
8
26
  header: view.label,
9
27
  field: name,
10
28
  value: (row) => sortKeyOf(meta, name, row[name]),
11
- cell: own ?? text,
29
+ cell: own ??
30
+ (whole ? (row) => _jsx("span", { className: "whitespace-nowrap", children: text(row) }) : text),
12
31
  text,
13
32
  numeric: view.numeric,
14
33
  sortable: view.sortable,
@@ -8,7 +8,9 @@ export declare function groupableOf(meta: Meta | null, locale?: string): Groupab
8
8
  * The server's groups as piles, with the words a person reads, and each pile's group so that
9
9
  * opening one reads its rows. Rows sit only on the deepest level, once read.
10
10
  */
11
- export declare function pilesOf<T extends AnyRecord>(buckets: readonly Bucket<T>[], levels: readonly GroupLevel[], meta: Meta | null, locale: string | undefined, rowsOf: (bucket: Bucket<T>) => readonly T[] | undefined): {
11
+ export declare function pilesOf<T extends AnyRecord>(buckets: readonly Bucket<T>[], levels: readonly GroupLevel[], meta: Meta | null, locale: string | undefined, rowsOf: (bucket: Bucket<T>) => readonly T[] | undefined,
12
+ /** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
13
+ brings?: (bucket: Bucket<T>) => number | false | undefined): {
12
14
  piles: Pile<T>[];
13
15
  bucketAt: ReadonlyMap<string, Bucket<T>>;
14
16
  deepest: number;
@@ -33,7 +33,9 @@ export function groupableOf(meta, locale) {
33
33
  * The server's groups as piles, with the words a person reads, and each pile's group so that
34
34
  * opening one reads its rows. Rows sit only on the deepest level, once read.
35
35
  */
36
- export function pilesOf(buckets, levels, meta, locale, rowsOf) {
36
+ export function pilesOf(buckets, levels, meta, locale, rowsOf,
37
+ /** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
38
+ brings) {
37
39
  const bucketAt = new Map();
38
40
  const none = frameworkCopy().list.noValue;
39
41
  const labelFor = (bucket, depth, key) => {
@@ -52,6 +54,10 @@ export function pilesOf(buckets, levels, meta, locale, rowsOf) {
52
54
  const detail = detailOf(meta, bucket.measures, locale);
53
55
  return detail === undefined ? {} : { detail };
54
56
  };
57
+ const more = (bucket, deepest) => {
58
+ const next = deepest ? brings?.(bucket) : undefined;
59
+ return next === undefined ? {} : { more: next };
60
+ };
55
61
  const walk = (level, above, depth) => level.map((bucket) => {
56
62
  const key = bucket.value === null || bucket.value === undefined ? "" : String(bucket.value);
57
63
  const path = [...above, key];
@@ -67,6 +73,7 @@ export function pilesOf(buckets, levels, meta, locale, rowsOf) {
67
73
  ...detailed(bucket),
68
74
  items: below.length === 0 ? [...(rowsOf(bucket) ?? [])] : [],
69
75
  piles: walk(below, path, depth + 1),
76
+ ...more(bucket, below.length === 0),
70
77
  };
71
78
  });
72
79
  return { piles: walk(buckets, [], 0), bucketAt, deepest: levels.length - 1 };
@@ -0,0 +1,41 @@
1
+ import type { OpenOptions, WorkspaceApi } from "@sincpro/web-composer";
2
+ import { type OpenTarget } from "@sincpro/web-ui";
3
+ /**
4
+ * Where a record may open, and the menu that offers it.
5
+ *
6
+ * Context: a record opened from a list used to go one way — a press opened the page — and the
7
+ * other places (a look, beside, a window) were the composer's `RecordLink` icons, shown only to
8
+ * a pointer hovering the name of a TABLE row: nothing from the rows, the board, a one2many, and
9
+ * never a modal. A record opens anywhere the workspace can put it unless the screen says
10
+ * otherwise (`openTargets`), and «Abrir en…» says so where it is seen, in web-ui's own words
11
+ * (`openIn`) — the same menu a many2one already has.
12
+ *
13
+ * The places allowed depend on where the list is: from inside a modal, no modal (a second one
14
+ * would replace the first and lose what was typed in it) — composer says where a view is
15
+ * (`api.over`).
16
+ */
17
+ /** A record's form fits; a short task (register a payment) passes its own size. */
18
+ export declare const RECORD_SIZE: {
19
+ readonly w: 760;
20
+ readonly h: 560;
21
+ };
22
+ /** Where a record may open from this view, the default first. */
23
+ export declare function targetsFor(api: Pick<WorkspaceApi, "over">): readonly OpenTarget[];
24
+ /** web-ui's target as composer's options. Destinations share their names, so only the size is
25
+ * added — to the two that have one. */
26
+ export declare function openOptions(to: OpenTarget, size?: {
27
+ w: number;
28
+ h: number;
29
+ }): OpenOptions;
30
+ /**
31
+ * «Abrir en…»: a visible menu of the places a record may open, beside its name. Nothing when
32
+ * there is one place or none — then a press is all there is.
33
+ *
34
+ * <OpenInMenu targets={["modal", "side", "window"]} onOpen={(to) => openIn(api, ref, to)} />
35
+ */
36
+ export declare function OpenInMenu({ targets, onOpen, name, }: {
37
+ targets: readonly OpenTarget[];
38
+ onOpen: (to: OpenTarget) => void;
39
+ /** Whose menu it is, for a screen reader: «Abrir en… — F-2026-0004». */
40
+ name?: string;
41
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,55 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Menu, useUiCopy } from "@sincpro/web-ui";
4
+ import { AppWindow, Eye, FileText, PanelRight, SquareArrowOutUpRight, SquareStack, } from "lucide-react";
5
+ /**
6
+ * Where a record may open, and the menu that offers it.
7
+ *
8
+ * Context: a record opened from a list used to go one way — a press opened the page — and the
9
+ * other places (a look, beside, a window) were the composer's `RecordLink` icons, shown only to
10
+ * a pointer hovering the name of a TABLE row: nothing from the rows, the board, a one2many, and
11
+ * never a modal. A record opens anywhere the workspace can put it unless the screen says
12
+ * otherwise (`openTargets`), and «Abrir en…» says so where it is seen, in web-ui's own words
13
+ * (`openIn`) — the same menu a many2one already has.
14
+ *
15
+ * The places allowed depend on where the list is: from inside a modal, no modal (a second one
16
+ * would replace the first and lose what was typed in it) — composer says where a view is
17
+ * (`api.over`).
18
+ */
19
+ /** A record's form fits; a short task (register a payment) passes its own size. */
20
+ export const RECORD_SIZE = { w: 760, h: 560 };
21
+ const EVERYWHERE = ["modal", "peek", "side", "page", "window"];
22
+ const FROM_A_MODAL = ["side", "peek", "page", "window"];
23
+ /** Where a record may open from this view, the default first. */
24
+ export function targetsFor(api) {
25
+ return api.over === null ? EVERYWHERE : FROM_A_MODAL;
26
+ }
27
+ /** web-ui's target as composer's options. Destinations share their names, so only the size is
28
+ * added — to the two that have one. */
29
+ export function openOptions(to, size = RECORD_SIZE) {
30
+ return to === "modal" || to === "window" ? { to, size } : { to };
31
+ }
32
+ const ICON = {
33
+ page: FileText,
34
+ peek: Eye,
35
+ modal: SquareStack,
36
+ side: PanelRight,
37
+ window: AppWindow,
38
+ };
39
+ /**
40
+ * «Abrir en…»: a visible menu of the places a record may open, beside its name. Nothing when
41
+ * there is one place or none — then a press is all there is.
42
+ *
43
+ * <OpenInMenu targets={["modal", "side", "window"]} onOpen={(to) => openIn(api, ref, to)} />
44
+ */
45
+ export function OpenInMenu({ targets, onOpen, name, }) {
46
+ const copy = useUiCopy().picker;
47
+ if (targets.length === 0)
48
+ return null;
49
+ const options = targets.map((to) => ({
50
+ id: to,
51
+ label: copy.openIn[to],
52
+ icon: ICON[to],
53
+ }));
54
+ return (_jsx(Menu, { label: name === undefined ? copy.openMore : `${copy.openMore} ${name}`, title: copy.openMore, groups: [{ options }], onSelect: (id) => onOpen(id), icon: SquareArrowOutUpRight, iconOnly: true, size: "sm", role: "ghost", align: "end", width: "sm" }));
55
+ }
@@ -0,0 +1,23 @@
1
+ import { type AnyRecord, type Bucket, type Meta } from "@sincpro/criteria";
2
+ import type { GroupLevel } from "../../core/list.js";
3
+ import type { Pivot } from "@sincpro/web-ui";
4
+ /**
5
+ * web-ui's `Pivot` (`folded`), from what the SERVER counted (`usePivot`): the rows axis is the
6
+ * outer groups, the columns axis every inner value that appeared, each crossing an inner group,
7
+ * each row's total its outer group, each column's total the grouping by the columns alone.
8
+ * Nothing is added up here — a margin is read from the base, never summed from cells.
9
+ *
10
+ * A key is how its value READS («Pagada», «Efectivo»): the grid draws keys, and the server's
11
+ * value («paid») is not a word for a person.
12
+ */
13
+ export declare function pivotOf<T extends AnyRecord>({ crossed, byColumn, rows, columns, measures, meta, locale, }: {
14
+ /** Grouped by rows, then columns (`usePivot().crossed`). */
15
+ crossed: readonly Bucket<T>[];
16
+ /** Grouped by the columns alone (`usePivot().columns`). */
17
+ byColumn: readonly Bucket<T>[];
18
+ rows: GroupLevel;
19
+ columns: GroupLevel;
20
+ measures: readonly string[];
21
+ meta: Meta | null | undefined;
22
+ locale: string | undefined;
23
+ }): Pivot;