@sincpro/web-framework 3.19.0 → 3.20.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.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The name of each person among `who`, by the application's port (`FrameworkProvider people`):
3
+ * every username asked at once, and asked again only when the set changes. A username nobody
4
+ * names — or every one, without the port — reads as itself.
5
+ *
6
+ * const nameOf = usePeopleOf(history.map((one) => one.by));
7
+ * nameOf("jperez") // "Juana Pérez", once the port answers
8
+ *
9
+ * Context: a record's history and authorship say who by username — the fact's `actor` —, and an
10
+ * application showed «jperez» or wrote its own hook to rename them on every screen (quipu's
11
+ * `usePorNombre`). Who is who is the application's to answer (its accounts are a bounded context
12
+ * of their own); asking it, once per screen, is the framework's.
13
+ */
14
+ export declare function usePeopleOf(who: readonly (string | null | undefined)[]): (who: string) => string;
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import { useFramework } from "./context.js";
3
+ import { useEffect, useState } from "react";
4
+ /**
5
+ * The name of each person among `who`, by the application's port (`FrameworkProvider people`):
6
+ * every username asked at once, and asked again only when the set changes. A username nobody
7
+ * names — or every one, without the port — reads as itself.
8
+ *
9
+ * const nameOf = usePeopleOf(history.map((one) => one.by));
10
+ * nameOf("jperez") // "Juana Pérez", once the port answers
11
+ *
12
+ * Context: a record's history and authorship say who by username — the fact's `actor` —, and an
13
+ * application showed «jperez» or wrote its own hook to rename them on every screen (quipu's
14
+ * `usePorNombre`). Who is who is the application's to answer (its accounts are a bounded context
15
+ * of their own); asking it, once per screen, is the framework's.
16
+ */
17
+ export function usePeopleOf(who) {
18
+ const { people, context } = useFramework();
19
+ const [named, setNamed] = useState({});
20
+ // The set as its content: a new array of the same people asks nothing again.
21
+ const asked = [...new Set(who.filter((one) => !!one))].sort().join("\n");
22
+ useEffect(() => {
23
+ if (people === undefined || asked === "")
24
+ return;
25
+ let current = true;
26
+ void people(asked.split("\n")).then((names) => {
27
+ if (current)
28
+ setNamed(names);
29
+ },
30
+ // Unnamed is no error: the username stays.
31
+ () => undefined);
32
+ return () => void (current = false);
33
+ }, [people, asked, context]);
34
+ return (one) => named[one] ?? one;
35
+ }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { newEntityId, pathFor, retryKeys, startingValuesOf, TransportError, WITH_PARAM, } from "@sincpro/client-framework";
3
- import { changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
3
+ import { canCreate, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorsByField, fieldStateOf, lineStatesOf, missingOf, needsPreview, } from "../core/edit.js";
4
4
  import { linesAnswered } from "../core/lines.js";
5
5
  import { useFramework } from "./context.js";
6
6
  import { useWrites } from "./useWrites.js";
@@ -200,7 +200,7 @@ export function useRecord(entity, opened, options = {}) {
200
200
  // neither — every field of it is read only, whatever the model's hints say: an input nothing
201
201
  // can save is an invitation that lies.
202
202
  const writable = isNew
203
- ? byEdit || entity.create !== undefined
203
+ ? canCreate(entity, state.meta)
204
204
  : (entity.edit ?? entity.save) !== undefined;
205
205
  /** The record's key for a write: its own, or the one minted for it while it is new. */
206
206
  const keyNow = () => {
@@ -39,8 +39,8 @@ export { Refused } from "./Refused.js";
39
39
  export { RouteError, type RouteErrorProps } from "./RouteError.js";
40
40
  export { entityView, type EntityViewOptions, listView, type ListViewOptions, } from "./workspace/composer.js";
41
41
  export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
42
- export { type Stamp, useRecordScreen } from "./workspace/record.js";
43
- export { EntityRecord, type ReadyRecord, RecordScreen, type RecordScreenProps, useScreenRecord, } from "./workspace/RecordScreen.js";
42
+ export { type RecordTag, type Stamp, useRecordScreen, } from "./workspace/record.js";
43
+ export { EntityRecord, type FieldDrawn, type ReadyRecord, RecordScreen, type RecordScreenProps, type RelatedLink, useScreenColumns, useScreenRecord, } from "./workspace/RecordScreen.js";
44
44
  export { SincproApp } from "./workspace/SincproApp.js";
45
45
  export { webUiSkin } from "./workspace/skin.js";
46
46
  export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
package/dist/web/index.js CHANGED
@@ -39,8 +39,8 @@ export { Refused } from "./Refused.js";
39
39
  export { RouteError } from "./RouteError.js";
40
40
  export { entityView, listView, } from "./workspace/composer.js";
41
41
  export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
42
- export { useRecordScreen } from "./workspace/record.js";
43
- export { EntityRecord, RecordScreen, useScreenRecord, } from "./workspace/RecordScreen.js";
42
+ export { useRecordScreen, } from "./workspace/record.js";
43
+ export { EntityRecord, RecordScreen, useScreenColumns, useScreenRecord, } from "./workspace/RecordScreen.js";
44
44
  export { SincproApp } from "./workspace/SincproApp.js";
45
45
  export { webUiSkin } from "./workspace/skin.js";
46
46
  export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
@@ -30,7 +30,7 @@ export declare function useListOpening<T extends AnyRecord, C extends CommandBod
30
30
  choosing: boolean;
31
31
  choosingMany: boolean;
32
32
  embedded: boolean;
33
- create: boolean;
33
+ create: boolean | string;
34
34
  actions: ScreenActions | undefined;
35
35
  onOpen: ((row: T) => void) | undefined;
36
36
  onPeek: ((row: T) => void) | undefined;
@@ -2,9 +2,11 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { TRAIL_PARAM } from "@sincpro/client-framework";
4
4
  import { frameworkCopy } from "../../../core/copy.js";
5
+ import { canCreate } from "../../../core/edit.js";
5
6
  import { trailKeyOf } from "../../../core/trail.js";
6
7
  import { useFramework } from "../../../react/context.js";
7
8
  import { actionsOf } from "../dock.js";
9
+ import { useListExport } from "../export.js";
8
10
  import { OpenInMenu, openOptions, targetsFor } from "../openIn.js";
9
11
  import { Plus } from "lucide-react";
10
12
  import { useEffect, useId, useRef } from "react";
@@ -83,12 +85,14 @@ export function useListOpening({ listing, api, idOf, chosen, choosing, choosingM
83
85
  api !== undefined &&
84
86
  !choosing &&
85
87
  !embedded &&
86
- listing.entity.create !== undefined
88
+ canCreate(listing.entity, listing.meta)
87
89
  ? () => api.open(listing.entity.newRef())
88
90
  : undefined;
89
91
  // What the list starts, as data: «Nuevo» — the primary — and the screen's, drawn by the view
90
92
  // style (`List.Dock`). Actions drawn by hand stay in the bar, with «Nuevo» beside them.
91
93
  const started = actionsOf(actions);
94
+ // «Exportar», tucked: the list's question as a spreadsheet, when the entity declares its export.
95
+ const exporting = useListExport(listing, !embedded && !choosing);
92
96
  const startDock = started.drawn !== null
93
97
  ? []
94
98
  : [
@@ -97,13 +101,14 @@ export function useListOpening({ listing, api, idOf, chosen, choosing, choosingM
97
101
  : [
98
102
  {
99
103
  id: "create",
100
- label: frameworkCopy().record.create,
104
+ label: typeof create === "string" ? create : frameworkCopy().record.create,
101
105
  icon: Plus,
102
106
  primary: true,
103
107
  onSelect: creating,
104
108
  },
105
109
  ]),
106
110
  ...started.dock,
111
+ ...(exporting === null ? [] : [exporting]),
107
112
  ];
108
113
  const openingIn = onOpenIn ??
109
114
  (api === undefined
@@ -127,9 +127,10 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
127
127
  /**
128
128
  * With `api` and an entity that declares `create`, the bar offers «New», which opens the
129
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.
130
+ * Command produces, or a caller who may not create. A text is its words, the business's way:
131
+ * `create="Nueva noticia"`.
131
132
  */
132
- create?: boolean;
133
+ create?: boolean | string;
133
134
  /**
134
135
  * The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
135
136
  * the list is read again when one is done (`useRowCommands`).
@@ -0,0 +1,13 @@
1
+ import { type AnyRecord } from "@sincpro/criteria";
2
+ import type { Listing } from "../../react/useListing.js";
3
+ import { type DockAction } from "@sincpro/web-ui";
4
+ /**
5
+ * «Exportar»: the list's records — its question on screen, filter and order, every page — as a
6
+ * spreadsheet (`core/export`), saved by the browser. Offered when the entity declares its export
7
+ * (`entity(…, { export: "/invoices/export" })`); `null` otherwise.
8
+ *
9
+ * Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
10
+ * fetched to build it, so a million rows is the server's work, not the page's), and this writes
11
+ * what a person opens: the model's words as headers, the region's separator and decimal.
12
+ */
13
+ export declare function useListExport<T extends AnyRecord>(listing: Listing<T>, enabled: boolean): DockAction | null;
@@ -0,0 +1,61 @@
1
+ "use client";
2
+ import { downloadRoute, exportRoute } from "@sincpro/client-framework";
3
+ import { nameOf } from "@sincpro/criteria";
4
+ import { frameworkCopy } from "../../core/copy.js";
5
+ import { csvOf, exportColumnsOf } from "../../core/export.js";
6
+ import { useFramework } from "../../react/context.js";
7
+ import { refusalNotice } from "./records.js";
8
+ import { useToastIfAny } from "@sincpro/web-ui";
9
+ import { Download } from "lucide-react";
10
+ /**
11
+ * «Exportar»: the list's records — its question on screen, filter and order, every page — as a
12
+ * spreadsheet (`core/export`), saved by the browser. Offered when the entity declares its export
13
+ * (`entity(…, { export: "/invoices/export" })`); `null` otherwise.
14
+ *
15
+ * Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
16
+ * fetched to build it, so a million rows is the server's work, not the page's), and this writes
17
+ * what a person opens: the model's words as headers, the region's separator and decimal.
18
+ */
19
+ export function useListExport(listing, enabled) {
20
+ const { transport, locale } = useFramework();
21
+ const toast = useToastIfAny();
22
+ const entity = listing.entity;
23
+ if (!enabled || entity.export === undefined)
24
+ return null;
25
+ const path = entity.export;
26
+ return {
27
+ id: "export",
28
+ label: frameworkCopy().list.export,
29
+ icon: Download,
30
+ tucked: true,
31
+ onSelect: () => {
32
+ // The question on screen without its page: every record it keeps, in its order.
33
+ const { pagination: _page, ...asked } = listing.question;
34
+ void downloadRoute(transport, exportRoute(path, asked, "jsonl"))
35
+ .then((download) => download.blob())
36
+ .then((blob) => blob.text())
37
+ .then((text) => {
38
+ const csv = csvOf(text.split("\n"), exportColumnsOf(listing.meta, locale), regionOf());
39
+ save(new Blob([csv], { type: "text/csv;charset=utf-8" }), fileNameOf(listing.meta, locale));
40
+ })
41
+ .catch((failure) => toast?.show(refusalNotice(failure)));
42
+ },
43
+ };
44
+ }
45
+ /** The region numbers are written in: the browser's, as a spreadsheet on this machine reads. */
46
+ function regionOf() {
47
+ return typeof navigator === "undefined" ? undefined : navigator.language;
48
+ }
49
+ function fileNameOf(meta, locale) {
50
+ const name = nameOf(meta, locale) || "export";
51
+ return `${name.toLowerCase().replace(/\s+/g, "-")}.csv`;
52
+ }
53
+ /** Saved by the browser, as a link the person followed. */
54
+ function save(blob, name) {
55
+ const url = URL.createObjectURL(blob);
56
+ const link = document.createElement("a");
57
+ link.href = url;
58
+ link.download = name;
59
+ link.click();
60
+ setTimeout(() => URL.revokeObjectURL(url), 0);
61
+ }
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
3
  import { keysOf, listRoute } from "@sincpro/client-framework";
4
4
  import { choicesOf } from "@sincpro/criteria";
5
5
  import { frameworkCopy } from "../../core/copy.js";
@@ -14,7 +14,7 @@ import { refusalNotice } from "../list/records.js";
14
14
  import { controlFor, RelationPicker, } from "./control.js";
15
15
  import { RecordOpeningProvider, useRecordOpening, } from "./opening.js";
16
16
  import { usePartLook } from "./record.js";
17
- import { Button, Field, LineItems, ReadValue, Tag, useToastIfAny, } from "@sincpro/web-ui";
17
+ import { Field, LineItems, ReadValue, Tag, useToastIfAny, } from "@sincpro/web-ui";
18
18
  import { useRef } from "react";
19
19
  /** How a field of a line reads: a many2one's key by the name of what it points at. */
20
20
  function textIn(definition, field, relation, line, locale) {
@@ -237,7 +237,9 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
237
237
  ...(one.numeric === undefined ? {} : { numeric: one.numeric }),
238
238
  })),
239
239
  ];
240
- const table = (_jsx(LineItems, { lines: lines, columns: columns, getLineId: keyOf, mode: writing ? "edit" : "read", adding: adding, onChange: (key, next) => write((all) => all.map((one) => (keyOf(one) === key ? sameLine(one, next) : one))), newLine: newLine, onAdd: (line) => write((all) => [...all, line]), onRemove: (key) => write((all) => all.filter((one) => keyOf(one) !== key)), onRestore: (line, index) => write((all) => [...all.slice(0, index), line, ...all.slice(index)]), onReorder: (key, before) => write((all) => moved(all, identity, key, before)),
240
+ const table = (_jsx(LineItems, { lines: lines, columns: columns, getLineId: keyOf, mode: writing ? "edit" : "read", adding: adding, onChange: (key, next) => write((all) => all.map((one) => (keyOf(one) === key ? sameLine(one, next) : one))), newLine: newLine, ...(addMany === undefined
241
+ ? {}
242
+ : { moreAdds: [{ label: frameworkCopy().record.addMany, onAdd: addMany }] }), onAdd: (line) => write((all) => [...all, line]), onRemove: (key) => write((all) => all.filter((one) => keyOf(one) !== key)), onRestore: (line, index) => write((all) => [...all.slice(0, index), line, ...all.slice(index)]), onReorder: (key, before) => write((all) => moved(all, identity, key, before)),
241
243
  // A cell says its own (web-ui 1.6 `cellState`): the line model's hints refined by the
242
244
  // server's `items[i]`, the error pointing at it (under its value) and its warning.
243
245
  cellState: (line, column) => {
@@ -291,9 +293,7 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
291
293
  // line's dialog, a modal over a modal). Opening a chosen record is still the workspace's.
292
294
  const inLine = opening === null ? null : withoutChoose(opening);
293
295
  const lined = inLine === null ? (table) : (_jsx(RecordOpeningProvider, { value: inLine, children: table }));
294
- if (addMany === undefined)
295
- return lined;
296
- return (_jsxs("div", { className: "flex flex-col gap-2", children: [lined, _jsx("div", { children: _jsx(Button, { size: "sm", role: "secondary", onClick: addMany, children: frameworkCopy().record.addMany }) })] }));
296
+ return lined;
297
297
  }
298
298
  /** The opening inside a line: without the workspace's chooser (see the end of the editor), or
299
299
  * `null` when there is none to take away. */
@@ -1,11 +1,14 @@
1
1
  import type { Entity } from "@sincpro/client-framework";
2
- import type { AnyRecord } from "@sincpro/criteria";
2
+ import type { AnyRecord, Expression } from "@sincpro/criteria";
3
3
  import { type ViewProps } from "@sincpro/web-composer";
4
4
  import type { RecordRead } from "../../core/server.js";
5
5
  import type { RecordReading } from "../../react/useRecord.js";
6
6
  import { actionsOf, type ScreenActions } from "../list/dock.js";
7
7
  import { type NoProps } from "../parts.js";
8
- import { useRecordScreen } from "./record.js";
8
+ import type { FieldControl } from "../record/control.js";
9
+ import type { DockedAction } from "../record/dock.js";
10
+ import { type RecordTag, useRecordScreen } from "./record.js";
11
+ import { type DockAction, type DockMoment, type SmartLink } from "@sincpro/web-ui";
9
12
  import { type ReactNode } from "react";
10
13
  /**
11
14
  * A record screen written as a tree of the framework's parts.
@@ -65,6 +68,8 @@ type RecordScreenState = {
65
68
  docked: ReturnType<typeof actionsOf>["dock"];
66
69
  /** The actions the screen draws by hand, with the lifecycle's buttons beside them. */
67
70
  drawn: ReactNode | null;
71
+ /** What hangs off the record, opened in the workspace (`links`). */
72
+ links: readonly SmartLink[];
68
73
  /** The restored draft's notice was put away: the draft stays, its notice is read. */
69
74
  restoredAway: boolean;
70
75
  putRestoredAway: () => void;
@@ -81,13 +86,28 @@ type RecordScreenState = {
81
86
  * The entity is only its type: the record is the screen's.
82
87
  */
83
88
  export declare function useScreenRecord<T extends AnyRecord>(_entity?: Entity<T>): ReadyRecord<T>;
89
+ /**
90
+ * How many columns the record's form takes where the screen is mounted — two on a page or in a
91
+ * modal, one in a panel, a peek or a phone —, for a block of the application that lays itself out
92
+ * the same way («three figures side by side when wide»). The screen decided it; a block never
93
+ * asks the workspace where it opened.
94
+ */
95
+ export declare function useScreenColumns(): 1 | 2;
96
+ /** A field drawn the screen's way inside `RecordScreen.Fields`: its control, and the record. */
97
+ export type FieldDrawn = (control: FieldControl, record: ReadyRecord<AnyRecord>) => ReactNode;
84
98
  /**
85
99
  * The record's fields in web-ui's form grid: two columns on a page and in a modal, one in a
86
- * panel, a peek or a phone. `names` chooses and orders them; `title` heads the section.
100
+ * panel, a peek or a phone. `names` chooses and orders them; `title` heads the section and
101
+ * `hint` says what it is for. A field the model cannot draw as the screen wants — a body with
102
+ * pictures, a year — is drawn by `controls`, with the field's control and the record. A section
103
+ * of one field that bears its name («Sesiones», the sessions) does not name it twice: the field
104
+ * is drawn bare under the section's title.
87
105
  */
88
- declare function Fields({ names, title, }: {
106
+ declare function Fields({ names, title, hint, controls, }: {
89
107
  names?: readonly string[] | undefined;
90
108
  title?: string | undefined;
109
+ hint?: string | undefined;
110
+ controls?: Readonly<Partial<Record<string, FieldDrawn>>> | undefined;
91
111
  }): import("react").JSX.Element;
92
112
  /** Each value the record embeds (a payment's receipt) as a section of its own fields. */
93
113
  declare function Sections(): import("react").JSX.Element;
@@ -100,6 +120,17 @@ export type RecordScreenProps<T extends AnyRecord> = ViewProps & {
100
120
  title?: ((record: T) => string | null) | undefined;
101
121
  /** The line under its name, the screen's way. Without it, the record's type, if any. */
102
122
  subtitle?: ((record: T) => string | null) | undefined;
123
+ /** Its tag, the screen's way («Publicada»). Without it, its state in the entity's tone. */
124
+ tag?: ((record: T) => RecordTag | null | undefined) | undefined;
125
+ /** How a new one is named: «Nueva noticia». Without it, the model's name and «nuevo». */
126
+ creating?: string | undefined;
127
+ /** The dock's word on its moment, the screen's way — one that depends on who looks. Without
128
+ * it, the entity's (`presented(entity, { moment })`). */
129
+ moment?: ((record: T) => DockMoment | undefined) | undefined;
130
+ /** What hangs off it, opened in the workspace — `RecordScreen.Smart`, in the rail: a list of
131
+ * related records declared (`RelatedLink`: counted and opened by the screen), or a link of the
132
+ * screen's own. Not while it is new: nothing hangs off a record that does not exist yet. */
133
+ links?: ((record: T) => readonly (SmartLink | RelatedLink)[]) | undefined;
103
134
  /** The fields `RecordScreen.Fields` shows, in this order. Without it, the model's (`formOf`). */
104
135
  fields?: readonly string[] | undefined;
105
136
  /** The one2many `RecordScreen.Pages` shows, in this order. Without it, every one the model has. */
@@ -109,13 +140,13 @@ export type RecordScreenProps<T extends AnyRecord> = ViewProps & {
109
140
  * (`DockAction`s) the view style draws them with the lifecycle's: the rail's buttons in
110
141
  * `traditional`, one floating pill in `modern`. A node drawn by hand stays in the rail.
111
142
  */
112
- actions?: ((record: RecordReading<T>) => ScreenActions) | undefined;
143
+ actions?: ((record: RecordReading<T>) => ScreenActions | readonly (DockAction | DockedAction)[]) | undefined;
113
144
  /** `false`: the screen draws its own history — it is not read. */
114
145
  history?: boolean | undefined;
115
146
  /** The screen's tree. Without it, the default screen. */
116
147
  children?: ReactNode;
117
148
  };
118
- declare function RecordScreenRoot<T extends AnyRecord>({ api, resource, entity, initial, title, subtitle, fields, pages, actions, history, children, }: RecordScreenProps<T>): import("react").JSX.Element;
149
+ declare function RecordScreenRoot<T extends AnyRecord>({ api, resource, entity, initial, title, subtitle, tag, creating, moment, links, fields, pages, actions, history, children, }: RecordScreenProps<T>): import("react").JSX.Element;
119
150
  /**
120
151
  * A record screen by parts: the framework's default, or any part of it replaced. See the top of
121
152
  * this file.
@@ -126,6 +157,7 @@ export declare const RecordScreen: typeof RecordScreenRoot & {
126
157
  }, RecordScreenState>;
127
158
  Crumbs: import("../parts.js").Part<NoProps, RecordScreenState>;
128
159
  Pager: import("../parts.js").Part<NoProps, RecordScreenState>;
160
+ Smart: import("../parts.js").Part<NoProps, RecordScreenState>;
129
161
  Actions: import("../parts.js").Part<NoProps, RecordScreenState>;
130
162
  Paper: import("../parts.js").Part<{
131
163
  children?: ReactNode;
@@ -153,4 +185,22 @@ export declare const RecordScreen: typeof RecordScreenRoot & {
153
185
  * actions={(invoice) => <CommandButton entity={invoices} command="post" … />} /> })
154
186
  */
155
187
  export declare function EntityRecord<T extends AnyRecord>(props: Omit<RecordScreenProps<T>, "children" | "history">): import("react").JSX.Element;
188
+ /**
189
+ * A list of records related to this one, declared — Odoo's smart button: its icon and words, the
190
+ * entity it lists and what keeps them (`where`, from the record), and the title its list opens
191
+ * with. The screen counts it and opens it; the application writes no hook for it.
192
+ *
193
+ * links={(pago) => [
194
+ * { icon: Receipt, label: "Sus pagos", list: pagos, title: pago.colegiado_nombre,
195
+ * where: { field: "colegiado_id", operator: "=", value: pago.colegiado_id } },
196
+ * ]}
197
+ */
198
+ export type RelatedLink = {
199
+ icon: SmartLink["icon"];
200
+ label: string;
201
+ list: Entity;
202
+ where: Expression;
203
+ /** Whose the list is: «María» of «Pagos · María». */
204
+ title?: string;
205
+ };
156
206
  export {};
@@ -5,14 +5,15 @@ import { usePhone } from "@sincpro/web-composer";
5
5
  import { frameworkCopy } from "../../core/copy.js";
6
6
  import { formOf } from "../../core/form.js";
7
7
  import { summaryFieldsOf } from "../../core/summary.js";
8
+ import { useCounts } from "../../react/useCounts.js";
8
9
  import { actionsOf } from "../list/dock.js";
9
10
  import { part, resolveParts, written } from "../parts.js";
10
11
  import { RecordField } from "../record/edit.js";
11
12
  import { LifecycleButtons, useRecordLifecycleActions, } from "../record/RecordLifecycle.js";
12
13
  import { Refused } from "../Refused.js";
13
14
  import { useRecordScreen } from "./record.js";
14
- import { Button, FormSection, Record, Skeleton, useFormStyle } from "@sincpro/web-ui";
15
- import { createContext, useContext, useState } from "react";
15
+ import { Button, FormSection, Record, Skeleton, useFormStyle, } from "@sincpro/web-ui";
16
+ import { createContext, Fragment, useContext, useState } from "react";
16
17
  const RecordScreenContext = createContext(null);
17
18
  function useScreenState(part) {
18
19
  const state = useContext(RecordScreenContext);
@@ -34,6 +35,15 @@ function useScreenState(part) {
34
35
  export function useScreenRecord(_entity) {
35
36
  return useScreenState("useScreenRecord").reading;
36
37
  }
38
+ /**
39
+ * How many columns the record's form takes where the screen is mounted — two on a page or in a
40
+ * modal, one in a panel, a peek or a phone —, for a block of the application that lays itself out
41
+ * the same way («three figures side by side when wide»). The screen decided it; a block never
42
+ * asks the workspace where it opened.
43
+ */
44
+ export function useScreenColumns() {
45
+ return useScreenState("useScreenColumns").columns;
46
+ }
37
47
  /* ----------------------------------------------------------------------------------------- *
38
48
  * Parts that become web-ui slots
39
49
  * ----------------------------------------------------------------------------------------- */
@@ -55,10 +65,17 @@ const Actions = screenPart("Actions", (_props, state) => {
55
65
  docked.length === 0 && moment === undefined ? null : (_jsx(Record.Dock, { actions: docked, ...(moment === undefined ? {} : { moment }) }, "dock")),
56
66
  ];
57
67
  });
58
- /** The band in front of the record. Empty, it draws crumbs, pager and actions — and no band at
68
+ /** What hangs off the record — its payments, its members —, as web-ui's smart buttons. */
69
+ const Smart = screenPart("Smart", (_props, { links }) => links.length === 0 ? null : _jsx(Record.Smart, { links: links }));
70
+ /** The band in front of the record. Empty, it draws crumbs, pager, links and actions — and no band at
59
71
  * all when none of them has anything to say (an empty one is a blank strip in a modal). */
60
72
  const Rail = screenPart("Rail", ({ children }, state) => {
61
- const inside = written(resolveParts(children ?? [_jsx(Crumbs, {}, "crumbs"), _jsx(Pager, {}, "pager"), _jsx(Actions, {}, "actions")], state));
73
+ const inside = written(resolveParts(children ?? [
74
+ _jsx(Crumbs, {}, "crumbs"),
75
+ _jsx(Pager, {}, "pager"),
76
+ _jsx(Smart, {}, "smart"),
77
+ _jsx(Actions, {}, "actions"),
78
+ ], state));
62
79
  return inside.length === 0 ? null : _jsx(Record.Rail, { children: inside });
63
80
  });
64
81
  /** Who made it and who changed it last, when the record says so. */
@@ -96,16 +113,23 @@ const Notices = screenPart("Notices", (_props, state) => {
96
113
  const Advice = screenPart("Advice", (_props, { reading }) => reading.edit.advice
97
114
  .filter((one) => (one.path?.length ?? 0) <= 1)
98
115
  .map((one) => (_jsx(Record.Notice, { tone: one.blocks_save === true ? "warn" : "info", children: one.message }, one.message))));
99
- /* ----------------------------------------------------------------------------------------- *
100
- * Parts drawn inside the paper
101
- * ----------------------------------------------------------------------------------------- */
102
116
  /**
103
117
  * The record's fields in web-ui's form grid: two columns on a page and in a modal, one in a
104
- * panel, a peek or a phone. `names` chooses and orders them; `title` heads the section.
118
+ * panel, a peek or a phone. `names` chooses and orders them; `title` heads the section and
119
+ * `hint` says what it is for. A field the model cannot draw as the screen wants — a body with
120
+ * pictures, a year — is drawn by `controls`, with the field's control and the record. A section
121
+ * of one field that bears its name («Sesiones», the sessions) does not name it twice: the field
122
+ * is drawn bare under the section's title.
105
123
  */
106
- function Fields({ names, title, }) {
124
+ function Fields({ names, title, hint, controls, }) {
107
125
  const state = useScreenState("Fields");
108
- return (_jsx(FormSection, { columns: state.columns, ...(title === undefined ? {} : { title }), children: (names ?? state.fields).map((name) => (_jsx(RecordField, { record: state.reading, name: name }, name))) }));
126
+ const shown = names ?? state.fields;
127
+ const { meta, locale } = state.reading;
128
+ const named = title !== undefined && shown.length === 1 && labelOf(meta, shown[0], locale) === title;
129
+ return (_jsx(FormSection, { columns: state.columns, ...(title === undefined ? {} : { title }), ...(hint === undefined ? {} : { hint }), children: shown.map((name) => {
130
+ const own = controls?.[name];
131
+ return (_jsx(RecordField, { record: state.reading, name: name, ...(named ? { bare: true } : {}), ...(own === undefined ? {} : { as: (control) => own(control, state.reading) }) }, name));
132
+ }) }));
109
133
  }
110
134
  /** Each value the record embeds (a payment's receipt) as a section of its own fields. */
111
135
  function Sections() {
@@ -120,11 +144,16 @@ function paperContent(titled) {
120
144
  }
121
145
  /** The paper: the record itself. Empty, it draws the default content. */
122
146
  const Paper = screenPart("Paper", ({ children, layout, width }, state) => (_jsx(Record.Paper, { layout: layout ?? (state.phone ? "stacked" : "horizontal"), ...(width === undefined ? {} : { width }), children: resolveParts(children ?? paperContent(state.settings && state.sections.length > 0), state) })));
123
- function RecordScreenRoot({ api, resource, entity, initial, title, subtitle, fields, pages, actions, history, children, }) {
124
- const screen = useRecordScreen(entity, { api, resource }, { title, subtitle, initial, history });
147
+ function RecordScreenRoot({ api, resource, entity, initial, title, subtitle, tag, creating, moment, links, fields, pages, actions, history, children, }) {
148
+ const screen = useRecordScreen(entity, { api, resource }, { title, subtitle, tag, creating, moment, initial, history });
125
149
  const { reading } = screen;
126
150
  const [page, setPage] = useState(undefined);
127
151
  const [restoredAway, setRestoredAway] = useState(false);
152
+ // The related lists it links to, counted together — before anything returns early: the hook
153
+ // asks nothing while the record is not read.
154
+ const linked = reading.status === "ready" && !reading.isNew ? (links?.(reading.record) ?? []) : [];
155
+ const related = linked.filter(isRelated);
156
+ const counts = useCounts(related.map((one) => ({ entity: one.list, where: one.where })));
128
157
  const phone = usePhone(api);
129
158
  const settings = useFormStyle() === "settings";
130
159
  // Its own lifecycle (`Delete`, the trash): once it is out of every reading the surface closes,
@@ -140,7 +169,13 @@ function RecordScreenRoot({ api, resource, entity, initial, title, subtitle, fie
140
169
  // field, unless it can be typed in now: then the field is its control, not a repetition.
141
170
  const parts = summaryFieldsOf(meta, reading.record, entity.summary);
142
171
  const said = new Set([meta?.display, parts.state, parts.type]);
143
- const own = actionsOf(actions?.(reading) ?? null);
172
+ // An action may bring its own dialog (`DockedAction`): its action goes to the dock, its dialog
173
+ // is drawn by the screen — the screen calls its hook, never passes it.
174
+ const asked = actions?.(reading) ?? null;
175
+ const docked = Array.isArray(asked) ? asked.filter(isDocked) : [];
176
+ const own = actionsOf(Array.isArray(asked)
177
+ ? asked.map((one) => (isDocked(one) ? one.action : one))
178
+ : asked);
144
179
  const state = {
145
180
  screen: screen,
146
181
  reading: reading,
@@ -160,9 +195,20 @@ function RecordScreenRoot({ api, resource, entity, initial, title, subtitle, fie
160
195
  drawn: own.drawn === null ? null : (_jsxs(_Fragment, { children: [own.drawn, _jsx(LifecycleButtons, { actions: lifecycle.actions })] })),
161
196
  restoredAway,
162
197
  putRestoredAway: () => setRestoredAway(true),
198
+ links: linked.map((one) => {
199
+ if (!isRelated(one))
200
+ return one;
201
+ const count = counts[related.indexOf(one)];
202
+ return {
203
+ icon: one.icon,
204
+ label: one.label,
205
+ ...(count === null || count === undefined ? {} : { count }),
206
+ onClick: () => api.open(one.list.listRef(one.where, one.title)),
207
+ };
208
+ }),
163
209
  };
164
210
  const tree = children ?? (_jsxs(_Fragment, { children: [_jsx(Rail, {}), _jsx(Paper, {}), _jsx(Activity, {})] }));
165
- return (_jsxs(RecordScreenContext.Provider, { value: state, children: [_jsx(Record, { ...screen.record, children: resolveParts(tree, state) }), lifecycle.dialog] }));
211
+ return (_jsxs(RecordScreenContext.Provider, { value: state, children: [_jsx(Record, { ...screen.record, children: resolveParts(tree, state) }), lifecycle.dialog, docked.map((one) => (_jsx(Fragment, { children: one.dialog }, one.action.id)))] }));
166
212
  }
167
213
  /**
168
214
  * A record screen by parts: the framework's default, or any part of it replaced. See the top of
@@ -172,6 +218,7 @@ export const RecordScreen = Object.assign(RecordScreenRoot, {
172
218
  Rail,
173
219
  Crumbs,
174
220
  Pager,
221
+ Smart,
175
222
  Actions,
176
223
  Paper,
177
224
  Notices,
@@ -195,3 +242,10 @@ export const RecordScreen = Object.assign(RecordScreenRoot, {
195
242
  export function EntityRecord(props) {
196
243
  return _jsx(RecordScreen, { ...props });
197
244
  }
245
+ /** An action that brings its own dialog, told from one that is only data. */
246
+ function isDocked(one) {
247
+ return typeof one === "object" && one !== null && "action" in one && "dialog" in one;
248
+ }
249
+ function isRelated(one) {
250
+ return "list" in one;
251
+ }
@@ -5,8 +5,9 @@ import { type CacheOptions } from "../../core/cache.js";
5
5
  import type { Uploads } from "../../core/files.js";
6
6
  import type { DateStyle } from "../../core/present.js";
7
7
  import type { RichTextSettings } from "../../core/richText.js";
8
+ import { type People } from "../../react/context.js";
8
9
  import { type ReactNode } from "react";
9
- export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, region, richText, uploads, events, workspace: given, bar, onViewError, changes, }: {
10
+ export declare function SincproApp({ transport, views, start, language, voice, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, region, richText, uploads, people, events, workspace: given, bar, onViewError, changes, }: {
10
11
  /** Who answers. Without it, the `FrameworkProvider` around the app — one provider for every
11
12
  * face of a product. */
12
13
  transport?: Transport;
@@ -18,6 +19,13 @@ export declare function SincproApp({ transport, views, start, language, metas, e
18
19
  start?: ResourceRef;
19
20
  /** The interface's language: web-ui's, the composer's and the framework's words. */
20
21
  language?: "es" | "en";
22
+ /**
23
+ * How the Spanish addresses the person: `vos` («Elegí», «podés») — the default —, or `tú`
24
+ * («Elige», «puedes»), what most of the region writes. Web-ui's and the framework's tables in
25
+ * the same voice: two voices on one screen read as two authors. The composer's Spanish never
26
+ * addresses the person, so it has one table.
27
+ */
28
+ voice?: "vos" | "tú";
21
29
  /** Definitions known before any request, by entity key. */
22
30
  metas?: Readonly<Record<string, Meta>>;
23
31
  /** Drawn when nothing is open. */
@@ -45,6 +53,8 @@ export declare function SincproApp({ transport, views, start, language, metas, e
45
53
  richText?: RichTextSettings;
46
54
  /** Where a file a person gives goes — the application's (`FrameworkProvider uploads`). */
47
55
  uploads?: Uploads;
56
+ /** Who is who: a record's history and authorship by name (`FrameworkProvider people`). */
57
+ people?: People;
48
58
  /** Each domain event's definition by its wire name (`eventMetasOf(contract)`): a history
49
59
  * names each fact's own fields in its words. */
50
60
  events?: Readonly<Record<string, Meta>>;