@sincpro/web-framework 0.2.0 → 0.4.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 (70) 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 +4 -2
  9. package/dist/core/index.js +4 -2
  10. package/dist/core/lines.d.ts +52 -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/present.js +7 -2
  16. package/dist/core/rest.d.ts +5 -9
  17. package/dist/core/rest.js +14 -6
  18. package/dist/core/transport.d.ts +9 -1
  19. package/dist/core/zone.d.ts +27 -0
  20. package/dist/core/zone.js +75 -0
  21. package/dist/react/context.d.ts +13 -1
  22. package/dist/react/context.js +10 -2
  23. package/dist/react/index.d.ts +2 -1
  24. package/dist/react/index.js +1 -0
  25. package/dist/react/useGroups.d.ts +13 -1
  26. package/dist/react/useGroups.js +48 -7
  27. package/dist/react/useListing.d.ts +8 -4
  28. package/dist/react/useListing.js +11 -5
  29. package/dist/react/usePivot.d.ts +33 -0
  30. package/dist/react/usePivot.js +59 -0
  31. package/dist/react/useRecord.d.ts +13 -9
  32. package/dist/react/useRecord.js +55 -13
  33. package/dist/web/index.d.ts +7 -1
  34. package/dist/web/index.js +7 -1
  35. package/dist/web/list/EntityList.d.ts +46 -7
  36. package/dist/web/list/EntityList.js +132 -21
  37. package/dist/web/list/EntitySearchBar.js +19 -1
  38. package/dist/web/list/columns.d.ts +0 -13
  39. package/dist/web/list/columns.js +20 -1
  40. package/dist/web/list/groups.d.ts +3 -1
  41. package/dist/web/list/groups.js +8 -1
  42. package/dist/web/list/openIn.d.ts +41 -0
  43. package/dist/web/list/openIn.js +55 -0
  44. package/dist/web/list/pivot.d.ts +23 -0
  45. package/dist/web/list/pivot.js +64 -0
  46. package/dist/web/list/presentation.d.ts +51 -0
  47. package/dist/web/list/presentation.js +20 -0
  48. package/dist/web/record/EntityPicker.d.ts +3 -1
  49. package/dist/web/record/EntityPicker.js +15 -5
  50. package/dist/web/record/EntityTags.js +16 -5
  51. package/dist/web/record/RelatedList.d.ts +6 -0
  52. package/dist/web/record/RelatedList.js +26 -2
  53. package/dist/web/record/control.d.ts +43 -0
  54. package/dist/web/record/control.js +67 -0
  55. package/dist/web/record/edit.d.ts +16 -8
  56. package/dist/web/record/edit.js +57 -49
  57. package/dist/web/record/lines.d.ts +84 -0
  58. package/dist/web/record/lines.js +190 -0
  59. package/dist/web/record/opening.d.ts +8 -0
  60. package/dist/web/record/summary.js +14 -6
  61. package/dist/web/workspace/SincproApp.d.ts +4 -1
  62. package/dist/web/workspace/SincproApp.js +2 -2
  63. package/dist/web/workspace/composer.d.ts +2 -1
  64. package/dist/web/workspace/composer.js +27 -16
  65. package/dist/web/workspace/open.d.ts +2 -14
  66. package/dist/web/workspace/open.js +2 -13
  67. package/dist/web/workspace/record.js +6 -3
  68. package/dist/web/workspace/workspace.d.ts +4 -2
  69. package/dist/web/workspace/workspace.js +10 -4
  70. package/package.json +9 -9
@@ -1,14 +1,19 @@
1
1
  "use client";
2
- import { changesOf, creationOf, defaultsOf, errorsByField, fieldStateOf, missingOf, } from "../core/edit.js";
3
- import { pathFor } from "../core/entity.js";
2
+ import { changesOf, creationOf, defaultsOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, } from "../core/edit.js";
3
+ import { pathFor, startingValuesOf, WITH_PARAM, } from "../core/entity.js";
4
+ import { linesAnswered } from "../core/lines.js";
4
5
  import { retryKeys } from "../core/retry.js";
5
6
  import { TransportError } from "../core/transport.js";
6
7
  import { useFramework } from "./context.js";
7
8
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8
9
  /** How long typing has to pause before the server is asked what the record becomes. */
9
10
  const PREVIEW_PAUSE = 300;
10
- export function useRecord(entity, given) {
11
+ export function useRecord(entity, opened) {
11
12
  const { transport, locale, metas } = useFramework();
13
+ const given = typeof opened === "string" ? opened : (opened.id ?? "");
14
+ // As written in the reference: a text compares by value, so a new render with the same
15
+ // reference is not a new start.
16
+ const start = typeof opened === "string" ? undefined : opened.params?.[WITH_PARAM];
12
17
  // A create that answered its identity turns this into that record — until the screen asks
13
18
  // for another one.
14
19
  const [born, setBorn] = useState(null);
@@ -78,9 +83,10 @@ export function useRecord(entity, given) {
78
83
  forget();
79
84
  setDraft(null);
80
85
  setReadFor(id);
86
+ const starting = start === undefined ? {} : startingValuesOf({ params: { [WITH_PARAM]: start } });
81
87
  setState({
82
88
  status: "ready",
83
- record: defaultsOf(meta),
89
+ record: { ...defaultsOf(meta), ...starting },
84
90
  meta: meta ?? null,
85
91
  error: null,
86
92
  });
@@ -100,7 +106,9 @@ export function useRecord(entity, given) {
100
106
  forget();
101
107
  setReadFor(id);
102
108
  setDraft(answer.draft);
103
- if (answer.draft)
109
+ // A server that answers the record FROM the draft (sincpro_framework) sends no values
110
+ // apart: the record is the draft. One that sends them apart, they are what was typed.
111
+ if (answer.draft?.values)
104
112
  setTyped(answer.draft.values);
105
113
  setState({
106
114
  status: "ready",
@@ -118,7 +126,7 @@ export function useRecord(entity, given) {
118
126
  // `forget` only resets this hook's own state; listing it would reload the record on every
119
127
  // render. What reloads it is the transport, the entity, the id or an explicit `reload()`.
120
128
  // eslint-disable-next-line react-hooks/exhaustive-deps
121
- }, [transport, metas, entity, id, isNew, round]);
129
+ }, [transport, metas, entity, id, isNew, start, round]);
122
130
  useEffect(() => {
123
131
  mounted.current = true;
124
132
  return () => {
@@ -148,9 +156,22 @@ export function useRecord(entity, given) {
148
156
  .then((answer) => {
149
157
  if (aborter.signal.aborted || !mounted.current)
150
158
  return;
151
- setComputed(answer.values ?? {});
152
- setFromServer(answer.fields ?? {});
153
- setAdvice(answer.advice ?? []);
159
+ // A list the form sent (the lines) comes back computed — subtotals — as a whole:
160
+ // it takes the place of what was typed, each line keeping its key by position (a
161
+ // new line has no id to be found by). Typing again cancels an answer in flight, so
162
+ // `next` is still what is on screen.
163
+ const fresh = answer.values ?? {};
164
+ const lists = Object.keys(fresh).filter((key) => Array.isArray(fresh[key]) && Array.isArray(next[key]));
165
+ if (lists.length > 0)
166
+ setTyped((now) => {
167
+ const out = { ...now };
168
+ for (const key of lists)
169
+ out[key] = linesAnswered(next[key], fresh[key]);
170
+ return out;
171
+ });
172
+ setComputed(Object.fromEntries(Object.entries(fresh).filter(([key]) => !lists.includes(key))));
173
+ setFromServer(answer.states ?? {});
174
+ setAdvice(answer.warnings ?? []);
154
175
  }, () => undefined);
155
176
  }, PREVIEW_PAUSE);
156
177
  };
@@ -170,13 +191,20 @@ export function useRecord(entity, given) {
170
191
  ask(next, name);
171
192
  },
172
193
  state: (name) => fieldStateOf(state.meta, name, values, fromServer),
194
+ cell: (name, index, field) => {
195
+ const line = (Array.isArray(values[name]) ? values[name] : [])[index];
196
+ const definition = state.meta?.fields[name]?.definition;
197
+ return fieldStateOf(definition, field, line ?? {}, lineStatesOf(fromServer, name)[index]);
198
+ },
173
199
  errors: failure instanceof TransportError ? errorsByField(failure.problem?.errors) : {},
174
200
  advice,
175
201
  missing: missingOf(state.meta, values, fromServer),
176
202
  saving,
177
203
  failure,
178
204
  conflict,
179
- restored: draft !== null && Object.keys(changed).length > 0,
205
+ // Restored: the draft's values were put back over the record (they came apart), or the
206
+ // record itself was answered from the draft (sincpro_framework: no values apart).
207
+ restored: draft !== null && (draft.values === undefined || Object.keys(changed).length > 0),
180
208
  draft,
181
209
  save: async () => {
182
210
  if (isNew)
@@ -215,12 +243,26 @@ export function useRecord(entity, given) {
215
243
  : {
216
244
  keep: async () => {
217
245
  const route = entity.draft;
246
+ // sincpro_framework's `Edit`: the record as the form holds it, whole; the fields
247
+ // changed; the draft version read (`0`: none) — another tab that kept first wins —,
248
+ // and the stored version the edit started from.
218
249
  try {
219
250
  const kept = await transport.send(route.method, pathFor(route, id), {
220
- values: changed,
221
- expected: draft?.version ?? 0,
251
+ id,
252
+ values,
253
+ changed: Object.keys(changed),
254
+ version: draft?.version ?? 0,
255
+ ...(typeof version === "number" ? { origin_version: version } : {}),
222
256
  });
223
- setDraft(kept);
257
+ const now = kept.draft;
258
+ if (now)
259
+ setDraft({
260
+ values: changed,
261
+ version: now.version,
262
+ ...(now.origin_version === undefined
263
+ ? {}
264
+ : { origin_version: now.origin_version }),
265
+ });
224
266
  }
225
267
  catch (error) {
226
268
  refused(error);
@@ -2,15 +2,21 @@
2
2
  * The web bindings: what draws a `Listing` and a record with `@sincpro/web-ui`.
3
3
  */
4
4
  export { type ColumnOptions, columnsOf } from "./list/columns.js";
5
- export { EntityList, type EntityListProps } from "./list/EntityList.js";
5
+ export { type EntityFace, EntityList, type EntityListProps, type View, } from "./list/EntityList.js";
6
6
  export { EntitySearchBar } from "./list/EntitySearchBar.js";
7
7
  export { groupableOf, pilesOf } from "./list/groups.js";
8
+ export { OpenInMenu } from "./list/openIn.js";
9
+ export { pivotOf } from "./list/pivot.js";
10
+ export { type CardLook, type OptionLook, type Presentation, presentationOf, type Presented, presented, type RowLook, } from "./list/presentation.js";
8
11
  export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
9
12
  export { facetsOf, modelOf } from "./list/search.js";
10
13
  export { CommandButton } from "./record/CommandButton.js";
14
+ export { RelationPicker } from "./record/control.js";
11
15
  export { dirtyOf, type FieldControl, RecordField, } from "./record/edit.js";
12
16
  export { EntityPicker } from "./record/EntityPicker.js";
13
17
  export { EntityTags } from "./record/EntityTags.js";
18
+ export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, } from "./record/lines.js";
19
+ export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
14
20
  export { countOf, factsOf, RecordLines } from "./record/record.js";
15
21
  export { RelatedList } from "./record/RelatedList.js";
16
22
  export { cardOf, relationOf } from "./record/summary.js";
package/dist/web/index.js CHANGED
@@ -2,15 +2,21 @@
2
2
  * The web bindings: what draws a `Listing` and a record with `@sincpro/web-ui`.
3
3
  */
4
4
  export { columnsOf } from "./list/columns.js";
5
- export { EntityList } from "./list/EntityList.js";
5
+ export { EntityList, } from "./list/EntityList.js";
6
6
  export { EntitySearchBar } from "./list/EntitySearchBar.js";
7
7
  export { groupableOf, pilesOf } from "./list/groups.js";
8
+ export { OpenInMenu } from "./list/openIn.js";
9
+ export { pivotOf } from "./list/pivot.js";
10
+ export { presentationOf, presented, } from "./list/presentation.js";
8
11
  export { useRowCommands, } from "./list/rowCommands.js";
9
12
  export { facetsOf, modelOf } from "./list/search.js";
10
13
  export { CommandButton } from "./record/CommandButton.js";
14
+ export { RelationPicker } from "./record/control.js";
11
15
  export { dirtyOf, RecordField, } from "./record/edit.js";
12
16
  export { EntityPicker } from "./record/EntityPicker.js";
13
17
  export { EntityTags } from "./record/EntityTags.js";
18
+ export { RecordLinesEditor, } from "./record/lines.js";
19
+ export { RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
14
20
  export { countOf, factsOf, RecordLines } from "./record/record.js";
15
21
  export { RelatedList } from "./record/RelatedList.js";
16
22
  export { cardOf, relationOf } from "./record/summary.js";
@@ -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;