@sincpro/web-framework 2.4.0 → 2.6.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 (68) hide show
  1. package/README.md +117 -86
  2. package/dist/core/cache.d.ts +19 -7
  3. package/dist/core/cache.js +81 -44
  4. package/dist/core/changes.d.ts +25 -0
  5. package/dist/core/changes.js +39 -0
  6. package/dist/core/edit.d.ts +19 -0
  7. package/dist/core/edit.js +46 -0
  8. package/dist/core/index.d.ts +3 -3
  9. package/dist/core/index.js +3 -3
  10. package/dist/core/list.d.ts +20 -0
  11. package/dist/core/list.js +32 -1
  12. package/dist/core/names.d.ts +25 -0
  13. package/dist/core/names.js +79 -0
  14. package/dist/core/present.d.ts +22 -0
  15. package/dist/core/present.js +51 -19
  16. package/dist/react/context.d.ts +15 -2
  17. package/dist/react/context.js +11 -4
  18. package/dist/react/index.d.ts +4 -0
  19. package/dist/react/index.js +4 -0
  20. package/dist/react/useCount.d.ts +18 -0
  21. package/dist/react/useCount.js +23 -0
  22. package/dist/react/useGroups.js +4 -1
  23. package/dist/react/useHistory.js +4 -1
  24. package/dist/react/useListing.js +9 -6
  25. package/dist/react/useNameOf.d.ts +5 -4
  26. package/dist/react/useNameOf.js +25 -26
  27. package/dist/react/usePivot.js +4 -1
  28. package/dist/react/useRecord.d.ts +4 -4
  29. package/dist/react/useRecord.js +20 -13
  30. package/dist/react/useService.d.ts +5 -1
  31. package/dist/react/useServiceReading.d.ts +35 -0
  32. package/dist/react/useServiceReading.js +75 -0
  33. package/dist/react/useTextOf.d.ts +16 -0
  34. package/dist/react/useTextOf.js +21 -0
  35. package/dist/react/useWrites.d.ts +19 -0
  36. package/dist/react/useWrites.js +35 -0
  37. package/dist/web/index.d.ts +1 -0
  38. package/dist/web/index.js +1 -0
  39. package/dist/web/list/EntityList.d.ts +4 -1
  40. package/dist/web/list/EntityList.js +6 -3
  41. package/dist/web/list/EntitySearchBar.d.ts +4 -1
  42. package/dist/web/list/EntitySearchBar.js +2 -2
  43. package/dist/web/list/groups.d.ts +13 -3
  44. package/dist/web/list/groups.js +21 -8
  45. package/dist/web/list/openIn.d.ts +4 -2
  46. package/dist/web/list/openIn.js +9 -2
  47. package/dist/web/record/ActionButton.d.ts +34 -0
  48. package/dist/web/record/ActionButton.js +41 -0
  49. package/dist/web/record/CommandButton.d.ts +5 -6
  50. package/dist/web/record/CommandButton.js +16 -33
  51. package/dist/web/record/ServiceButton.d.ts +31 -0
  52. package/dist/web/record/ServiceButton.js +40 -0
  53. package/dist/web/record/control.d.ts +9 -3
  54. package/dist/web/record/control.js +13 -4
  55. package/dist/web/record/edit.js +1 -1
  56. package/dist/web/record/lines.js +1 -1
  57. package/dist/web/record/record.js +36 -3
  58. package/dist/web/workspace/SincproApp.d.ts +8 -2
  59. package/dist/web/workspace/SincproApp.js +13 -7
  60. package/dist/web/workspace/composer.d.ts +6 -2
  61. package/dist/web/workspace/composer.js +31 -12
  62. package/dist/web/workspace/open.d.ts +1 -1
  63. package/dist/web/workspace/open.js +7 -1
  64. package/dist/web/workspace/record.d.ts +6 -2
  65. package/dist/web/workspace/record.js +6 -5
  66. package/dist/web/workspace/workspace.d.ts +7 -1
  67. package/dist/web/workspace/workspace.js +13 -4
  68. package/package.json +6 -6
@@ -14,15 +14,22 @@ import { AppWindow, Eye, FileText, PanelRight, SquareArrowOutUpRight, SquareStac
14
14
  *
15
15
  * The places allowed depend on where the list is: from inside a modal, no modal (a second one
16
16
  * would replace the first and lose what was typed in it) — composer says where a view is
17
- * (`api.over`).
17
+ * (`api.over`). On a phone a side panel and a window both open as the page (composer 1.7,
18
+ * `api.layout`), so neither is offered: three entries that do the same are a lie. A screen that
19
+ * draws the menu follows the mode (`usePhone(api)`) so it redraws when it changes.
18
20
  */
19
21
  /** A record's form fits; a short task (register a payment) passes its own size. */
20
22
  export const RECORD_SIZE = { w: 760, h: 560 };
21
23
  const EVERYWHERE = ["modal", "peek", "side", "page", "window"];
22
24
  const FROM_A_MODAL = ["side", "peek", "page", "window"];
25
+ const ON_A_PHONE = ["modal", "peek", "page"];
26
+ const ON_A_PHONE_FROM_A_MODAL = ["peek", "page"];
23
27
  /** Where a record may open from this view, the default first. */
24
28
  export function targetsFor(api) {
25
- return api.over === null ? EVERYWHERE : FROM_A_MODAL;
29
+ const phone = api.layout?.phone() === true;
30
+ if (api.over === null)
31
+ return phone ? ON_A_PHONE : EVERYWHERE;
32
+ return phone ? ON_A_PHONE_FROM_A_MODAL : FROM_A_MODAL;
26
33
  }
27
34
  /** web-ui's target as composer's options. Destinations share their names, so only the size is
28
35
  * added — to the two that have one. */
@@ -0,0 +1,34 @@
1
+ import type { Rehearsal } from "../../react/useCommand.js";
2
+ /**
3
+ * What a button needs of an action to draw it — whatever runs behind: an entity's Command
4
+ * (`useCommand`) or one of the application's use cases (`useService`).
5
+ */
6
+ export type ButtonAction<R> = {
7
+ /** Does it; `undefined` when it failed — the failure is in `error`. */
8
+ run: () => Promise<R | undefined>;
9
+ /** Asks first what it would do — a dry run: the action destroys something. */
10
+ rehearse?: () => Promise<Rehearsal | undefined>;
11
+ busy: boolean;
12
+ error: unknown;
13
+ /** What the last dry run said it would do. */
14
+ rehearsal: Rehearsal | null;
15
+ reset: () => void;
16
+ };
17
+ /**
18
+ * An action as a button — the gesture `CommandButton` and `ServiceButton` share.
19
+ *
20
+ * Context: two kinds of action, two gestures. One that can be undone runs on the click — asking
21
+ * «are you sure?» before every confirm teaches people to click «yes» without reading. One that
22
+ * destroys (it can `rehearse`) asks FIRST what it would do and shows THAT in the window: the
23
+ * confirmation is the consequence, in the server's words, not a question. A refusal is shown
24
+ * where it happened, with what to do. Off while it runs: a click twice is one action.
25
+ *
26
+ * Internal: the gesture is drawn here once; what runs behind is each button's own.
27
+ */
28
+ export declare function ActionButton<R>({ action, label, role, disabled, onDone, }: {
29
+ action: ButtonAction<R>;
30
+ label: string;
31
+ role?: "primary" | "secondary" | "ghost";
32
+ disabled?: boolean;
33
+ onDone?: (answer: R) => void;
34
+ }): import("react").JSX.Element;
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { frameworkCopy } from "../../core/copy.js";
4
+ import { Refused } from "../Refused.js";
5
+ import { Button, Dialog } from "@sincpro/web-ui";
6
+ import { useState } from "react";
7
+ /**
8
+ * An action as a button — the gesture `CommandButton` and `ServiceButton` share.
9
+ *
10
+ * Context: two kinds of action, two gestures. One that can be undone runs on the click — asking
11
+ * «are you sure?» before every confirm teaches people to click «yes» without reading. One that
12
+ * destroys (it can `rehearse`) asks FIRST what it would do and shows THAT in the window: the
13
+ * confirmation is the consequence, in the server's words, not a question. A refusal is shown
14
+ * where it happened, with what to do. Off while it runs: a click twice is one action.
15
+ *
16
+ * Internal: the gesture is drawn here once; what runs behind is each button's own.
17
+ */
18
+ export function ActionButton({ action, label, role = "secondary", disabled = false, onDone, }) {
19
+ const copy = frameworkCopy().command;
20
+ const [open, setOpen] = useState(false);
21
+ const destructive = action.rehearse !== undefined;
22
+ const run = async () => {
23
+ const answer = await action.run();
24
+ if (answer !== undefined) {
25
+ setOpen(false);
26
+ action.reset();
27
+ onDone?.(answer);
28
+ }
29
+ else
30
+ setOpen(true);
31
+ };
32
+ const ask = async () => {
33
+ setOpen(true);
34
+ await action.rehearse?.();
35
+ };
36
+ const close = () => {
37
+ setOpen(false);
38
+ action.reset();
39
+ };
40
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || action.busy, onClick: () => void (destructive ? ask() : run()), children: label }), open ? (_jsx(Dialog, { open: true, title: label, onClose: close, footer: destructive && action.error === null ? (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: close, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || action.rehearsal === null, onClick: () => void run(), children: copy.confirm })] })) : undefined, children: action.error !== null ? (_jsx(Refused, { error: action.error })) : action.rehearsal === null ? (_jsx("p", { className: "text-meta text-muted", children: copy.rehearsing })) : (_jsx("p", { className: "text-ink", children: action.rehearsal.text })) })) : null] }));
41
+ }
@@ -2,13 +2,12 @@ import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/c
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type AnswerOf } from "../../react/useCommand.js";
4
4
  /**
5
- * An entity's Command as a button.
5
+ * An entity's Command as a button: sent as it is, over the screens' transport.
6
6
  *
7
- * Context: two kinds of action, two gestures. One that can be undone runs on the click — asking
8
- * «are you sure?» before every confirm teaches people to click «yes» without reading. One that
9
- * destroys (`destructive`) asks the server FIRST what it would do — the Command's dry run — and
10
- * shows THAT in the window: the confirmation is the consequence, in the server's words, not a
11
- * question. A refusal is shown where it happened, with what to do.
7
+ * Context: the gesture is `ActionButton`'s — run on the click, or (`destructive`) ask the
8
+ * server's dry run first and show what it would do; a refusal where it happened. An action that is
9
+ * one of the application's own use cases — logic of its own, composed, traced as
10
+ * `<context>/<Service>` — is a `ServiceButton`.
12
11
  */
13
12
  export declare function CommandButton<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ entity, command, id, body, label, destructive, role, disabled, onDone, }: {
14
13
  entity: Entity<T, C, A>;
@@ -1,41 +1,24 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import {} from "@sincpro/client-framework";
4
- import { frameworkCopy } from "../../core/copy.js";
5
4
  import { useCommand } from "../../react/useCommand.js";
6
- import { Refused } from "../Refused.js";
7
- import { Button, Dialog } from "@sincpro/web-ui";
8
- import { useState } from "react";
5
+ import { ActionButton } from "./ActionButton.js";
9
6
  /**
10
- * An entity's Command as a button.
7
+ * An entity's Command as a button: sent as it is, over the screens' transport.
11
8
  *
12
- * Context: two kinds of action, two gestures. One that can be undone runs on the click — asking
13
- * «are you sure?» before every confirm teaches people to click «yes» without reading. One that
14
- * destroys (`destructive`) asks the server FIRST what it would do — the Command's dry run — and
15
- * shows THAT in the window: the confirmation is the consequence, in the server's words, not a
16
- * question. A refusal is shown where it happened, with what to do.
9
+ * Context: the gesture is `ActionButton`'s — run on the click, or (`destructive`) ask the
10
+ * server's dry run first and show what it would do; a refusal where it happened. An action that is
11
+ * one of the application's own use cases — logic of its own, composed, traced as
12
+ * `<context>/<Service>` — is a `ServiceButton`.
17
13
  */
18
14
  export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, onDone, }) {
19
- const copy = frameworkCopy().command;
20
- const action = useCommand(entity, command);
21
- const [open, setOpen] = useState(false);
22
- const run = async () => {
23
- const answer = await action.run(id, body);
24
- if (answer !== undefined) {
25
- setOpen(false);
26
- action.reset();
27
- onDone?.(answer);
28
- }
29
- else
30
- setOpen(true);
31
- };
32
- const ask = async () => {
33
- setOpen(true);
34
- await action.rehearse(id, body);
35
- };
36
- const close = () => {
37
- setOpen(false);
38
- action.reset();
39
- };
40
- return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || action.busy, onClick: () => void (destructive ? ask() : run()), children: label }), open ? (_jsx(Dialog, { open: true, title: label, onClose: close, footer: destructive && action.error === null ? (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: close, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || action.rehearsal === null, onClick: () => void run(), children: copy.confirm })] })) : undefined, children: action.error !== null ? (_jsx(Refused, { error: action.error })) : action.rehearsal === null ? (_jsx("p", { className: "text-meta text-muted", children: copy.rehearsing })) : (_jsx("p", { className: "text-ink", children: action.rehearsal.text })) })) : null] }));
15
+ const sending = useCommand(entity, command);
16
+ return (_jsx(ActionButton, { action: {
17
+ run: () => sending.run(id, body),
18
+ ...(destructive ? { rehearse: () => sending.rehearse(id, body) } : {}),
19
+ busy: sending.busy,
20
+ error: sending.error,
21
+ rehearsal: sending.rehearsal,
22
+ reset: sending.reset,
23
+ }, label: label, role: role, disabled: disabled, ...(onDone === undefined ? {} : { onDone }) }));
41
24
  }
@@ -0,0 +1,31 @@
1
+ import type { Rehearsal } from "../../react/useCommand.js";
2
+ /**
3
+ * One of the application's use cases as a button — its Feature or ApplicationService, run on its
4
+ * bounded context.
5
+ *
6
+ * <ServiceButton
7
+ * label="Cancelar"
8
+ * run={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id))}
9
+ * rehearse={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id, true))}
10
+ * />
11
+ *
12
+ * Context: an action of an application is a use case — its logic, its composition, its span
13
+ * `<context>/<Service>`, its request carrying the run's trace to the server —, never a request a
14
+ * screen sends; what the screen adds is the state of running it (`useService`). The gesture is
15
+ * `CommandButton`'s, drawn once by `ActionButton`: run on the click, off while it runs, a refusal
16
+ * where it happened; and an action that destroys asks first (`rehearse`, the use case run dry)
17
+ * and shows what it would do. What it changed, every screen hears by itself: the use case's
18
+ * client announces its write (`processChanges`), so `onDone` is for what only this screen does
19
+ * next — a toast, closing a window —, never to read again.
20
+ */
21
+ export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, onDone, }: {
22
+ label: string;
23
+ /** The use case, executed on its bounded context. */
24
+ run: () => Promise<R>;
25
+ /** The same use case run dry — what it would do, nothing touched —, asked before `run`. */
26
+ rehearse?: () => Promise<Rehearsal>;
27
+ role?: "primary" | "secondary" | "ghost";
28
+ /** Not offered right now. The use case still decides. */
29
+ disabled?: boolean;
30
+ onDone?: (answer: R) => void;
31
+ }): import("react").JSX.Element;
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useService } from "../../react/useService.js";
4
+ import { ActionButton } from "./ActionButton.js";
5
+ /** What the button runs when there is no dry run: nothing. */
6
+ const NO_REHEARSAL = async () => undefined;
7
+ /**
8
+ * One of the application's use cases as a button — its Feature or ApplicationService, run on its
9
+ * bounded context.
10
+ *
11
+ * <ServiceButton
12
+ * label="Cancelar"
13
+ * run={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id))}
14
+ * rehearse={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id, true))}
15
+ * />
16
+ *
17
+ * Context: an action of an application is a use case — its logic, its composition, its span
18
+ * `<context>/<Service>`, its request carrying the run's trace to the server —, never a request a
19
+ * screen sends; what the screen adds is the state of running it (`useService`). The gesture is
20
+ * `CommandButton`'s, drawn once by `ActionButton`: run on the click, off while it runs, a refusal
21
+ * where it happened; and an action that destroys asks first (`rehearse`, the use case run dry)
22
+ * and shows what it would do. What it changed, every screen hears by itself: the use case's
23
+ * client announces its write (`processChanges`), so `onDone` is for what only this screen does
24
+ * next — a toast, closing a window —, never to read again.
25
+ */
26
+ export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, onDone, }) {
27
+ const running = useService(run);
28
+ const rehearsing = useService(rehearse ?? NO_REHEARSAL);
29
+ return (_jsx(ActionButton, { action: {
30
+ run: running.run,
31
+ ...(rehearse === undefined ? {} : { rehearse: rehearsing.run }),
32
+ busy: running.busy || rehearsing.busy,
33
+ error: running.error ?? rehearsing.error,
34
+ rehearsal: rehearsing.answer ?? null,
35
+ reset: () => {
36
+ running.reset();
37
+ rehearsing.reset();
38
+ },
39
+ }, label: label, role: role, disabled: disabled, ...(onDone === undefined ? {} : { onDone }) }));
40
+ }
@@ -14,15 +14,21 @@ export type FieldControl = {
14
14
  };
15
15
  /**
16
16
  * The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
17
- * list of words,
18
- * a text.
17
+ * list of words, a text — or the one its `widget` names when the model names one of the
18
+ * framework's own: `textarea`, several lines of prose.
19
19
  * Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
20
20
  * one rule for what a value is edited with.
21
+ *
22
+ * Context: sincpro_framework publishes each field's widget — its type's, or the one
23
+ * `presentation(widgets=…)` names — and a screen that ignored it drew a one-line input for a
24
+ * note, so every application passed `as` for each long text. Only the framework's own names are
25
+ * read here: a name an application registers is drawn with `as`, never looked up in a registry
26
+ * of strings.
21
27
  */
22
28
  export declare function controlFor(control: FieldControl, type: string, exact: boolean, choices: {
23
29
  value: unknown;
24
30
  label: string;
25
- }[]): ReactNode;
31
+ }[], widget?: string): ReactNode;
26
32
  /**
27
33
  * A many2one's control: the picker of the entity it points at — the server's literal search,
28
34
  * the first ten, «Buscar más…» — opening the chosen one where the view says.
@@ -2,15 +2,21 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
4
4
  import { EntityPicker } from "./EntityPicker.js";
5
- import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
5
+ import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
6
6
  /**
7
7
  * The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
8
- * list of words,
9
- * a text.
8
+ * list of words, a text — or the one its `widget` names when the model names one of the
9
+ * framework's own: `textarea`, several lines of prose.
10
10
  * Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
11
11
  * one rule for what a value is edited with.
12
+ *
13
+ * Context: sincpro_framework publishes each field's widget — its type's, or the one
14
+ * `presentation(widgets=…)` names — and a screen that ignored it drew a one-line input for a
15
+ * note, so every application passed `as` for each long text. Only the framework's own names are
16
+ * read here: a name an application registers is drawn with `as`, never looked up in a registry
17
+ * of strings.
12
18
  */
13
- export function controlFor(control, type, exact, choices) {
19
+ export function controlFor(control, type, exact, choices, widget) {
14
20
  const { value, set } = control;
15
21
  const named = control.standalone === true ? { "aria-label": control.label } : {};
16
22
  if (choices.length > 0)
@@ -39,6 +45,9 @@ export function controlFor(control, type, exact, choices) {
39
45
  return (_jsx(TagsField, { value: words, options: words.map((word) => ({ value: word, label: word })), onChange: set, onCreate: (word) => word, ...named }));
40
46
  }
41
47
  default:
48
+ // Not in a cell: a row of a table is one line high, and the dialog has the room.
49
+ if (widget === "textarea" && control.standalone !== true)
50
+ return (_jsx(TextArea, { value: value === null || value === undefined ? "" : String(value), onChange: set }));
42
51
  return (_jsx(TextInput, { value: value === null || value === undefined ? "" : String(value), onChange: set, ...named }));
43
52
  }
44
53
  }
@@ -143,7 +143,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
143
143
  }
144
144
  if (view.type === "boolean" && as === undefined)
145
145
  return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
146
- return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choicesOf(meta, name, locale))) }));
146
+ return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choicesOf(meta, name, locale), field?.widget)) }));
147
147
  }
148
148
  /**
149
149
  * The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
@@ -64,7 +64,7 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
64
64
  invalid,
65
65
  label,
66
66
  standalone: inCell,
67
- }, viewOf(definition, field, locale).type, definition?.fields[field]?.exact === true, choicesOf(definition, field, locale));
67
+ }, viewOf(definition, field, locale).type, definition?.fields[field]?.exact === true, choicesOf(definition, field, locale), definition?.fields[field]?.widget);
68
68
  }
69
69
  /**
70
70
  * The lines of an aggregate, edited inside its record: web-ui's `LineItems` over the record's
@@ -1,11 +1,15 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { describeRows } from "@sincpro/criteria";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
5
  import { textOf, viewOf } from "../../core/present.js";
6
6
  import { relatedOf } from "../../core/related.js";
7
+ import { relationFieldOf } from "../../core/relation.js";
8
+ import { useEntityFor } from "../../react/context.js";
9
+ import { useNameOf } from "../../react/useNameOf.js";
7
10
  import { columnsOf } from "../list/columns.js";
8
- import { List } from "@sincpro/web-ui";
11
+ import { useRecordOpening } from "./opening.js";
12
+ import { List, RelationValue, } from "@sincpro/web-ui";
9
13
  /**
10
14
  * The parts of ONE record, from the model.
11
15
  *
@@ -28,14 +32,43 @@ export function factsOf(record, meta, names, options = {}) {
28
32
  return names.map((name) => {
29
33
  const view = viewOf(meta, name, options.locale);
30
34
  const own = options.cells?.[name];
35
+ const relation = relationFieldOf(meta, name);
31
36
  return {
32
37
  label: view.label,
33
- value: own ? own(record) : (textOf(meta, name, record[name], options.locale) ?? EMPTY),
38
+ value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : ((textOf(meta, name, record[name], options.locale) ?? EMPTY)),
34
39
  ...(view.help === undefined ? {} : { hint: view.help }),
35
40
  ...(name === meta?.identity ? { mono: true } : {}),
36
41
  };
37
42
  });
38
43
  }
44
+ /**
45
+ * A many2one read as a fact: the name of the record it points at, as a link that opens it where
46
+ * the view says (`RecordOpening`: the workspace's places, «Abrir en…») — when the application
47
+ * declared its entity. A key alone (`EntityID[Tenant]`) is named by key (`useNameOf`). Of an
48
+ * entity nobody declared, it is the text it always was.
49
+ *
50
+ * Context: a fact a person read as «Globex Bolivia» led nowhere, so an application wrote its own
51
+ * link for «this payment's member», or misused a smart button for it. A component inside the
52
+ * fact's VALUE is fine: what web-ui finds by type are the slots, never their content.
53
+ */
54
+ function RelationFact({ record, meta, name, relation, locale, }) {
55
+ const target = useEntityFor(relation.target);
56
+ const opening = useRecordOpening();
57
+ const raw = record[relation.key];
58
+ const key = raw === null || raw === undefined ? "" : String(raw);
59
+ const asked = useNameOf(relation.held ? undefined : target, key);
60
+ if (target === undefined || key === "")
61
+ return _jsx(_Fragment, { children: textOf(meta, name, record[name], locale) ?? EMPTY });
62
+ const held = relation.held
63
+ ? textOf(meta, relation.relation, record[relation.relation], locale)
64
+ : null;
65
+ return (_jsx(RelationValue, { name: held ?? asked ?? key, ...(opening === null
66
+ ? {}
67
+ : {
68
+ onOpenIn: (to) => opening.open(target.ref(key), to),
69
+ openTargets: opening.targets,
70
+ }) }));
71
+ }
39
72
  /** How many records a relation of this record holds — the TOTAL, not the page it brought. */
40
73
  export function countOf(record, name) {
41
74
  return relatedOf(record[name]).count.value;
@@ -1,9 +1,9 @@
1
- import { type Entity, type Transport } from "@sincpro/client-framework";
1
+ import { type ChangeFeed, type Entity, type Transport } from "@sincpro/client-framework";
2
2
  import type { Meta } from "@sincpro/criteria";
3
3
  import { type ComposerSkin, type OnViewError, type ResourceRef, type ViewSpec, type WorkspaceStore } from "@sincpro/web-composer";
4
4
  import { type CacheOptions } from "../../core/cache.js";
5
5
  import { type ReactNode } from "react";
6
- export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, onViewError, }: {
6
+ export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, onViewError, changes, }: {
7
7
  transport: Transport;
8
8
  /** The entities as composer views — `entityView(…)` — and any other view of the app. */
9
9
  views: readonly ViewSpec[];
@@ -40,4 +40,10 @@ export declare function SincproApp({ transport, views, start, language, metas, e
40
40
  * `view <ref>`; without a reporter configured, nothing is sent.
41
41
  */
42
42
  onViewError?: OnViewError;
43
+ /**
44
+ * Where writes are announced — the process's (`processChanges`, @sincpro/client-framework),
45
+ * which every transport of the framework writes to, whoever sends: a screen, or a use case's
46
+ * generated client. The cache forgets what each write touches, and the screens read it again.
47
+ */
48
+ changes?: ChangeFeed;
43
49
  }): import("react").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { processContext, reportError, } from "@sincpro/client-framework";
3
+ import { processChanges, processContext, reportError, } from "@sincpro/client-framework";
4
4
  import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
5
5
  import { createRegistry, formatRef } from "@sincpro/web-composer/domain";
6
6
  import { cachedTransport, } from "../../core/cache.js";
@@ -27,7 +27,7 @@ import { useEffect, useMemo, useState } from "react";
27
27
  */
28
28
  /** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
29
29
  const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
30
- export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, workspace: given, bar, onViewError = reportViewError, }) {
30
+ export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
31
31
  // Installed once, before anything draws: the three tables are module state of their packages.
32
32
  useState(() => {
33
33
  if (language === "es") {
@@ -46,16 +46,22 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
46
46
  // The options are read once: a cache that changes shape mid-session forgets everything.
47
47
  // eslint-disable-next-line react-hooks/exhaustive-deps
48
48
  [transport]);
49
- // What was read in one company is not the other's: a change of context forgets every answer
50
- // before the screens read again (`FrameworkProvider` gives them another transport).
49
+ // What was read in one company is not the other's, and what anyone wrote is no longer what was
50
+ // read: a change of context forgets every answer, a write what it touched — whoever wrote it, a
51
+ // use case's client as much as a screen — before the screens read again.
51
52
  useEffect(() => {
52
53
  if (cache === false)
53
54
  return;
54
55
  const forgetting = cached;
55
- return processContext.watch(() => forgetting.invalidate());
56
+ const unwatch = processContext.watch(() => forgetting.invalidate());
57
+ const unfollow = changes.follow((change) => forgetting.changed(change));
58
+ return () => {
59
+ unwatch();
60
+ unfollow();
61
+ };
56
62
  // The cache is read once, as `cached` is.
57
63
  // eslint-disable-next-line react-hooks/exhaustive-deps
58
- }, [cached]);
64
+ }, [cached, changes]);
59
65
  const own = useWorkspace();
60
66
  const workspace = given ?? own;
61
67
  const registry = useMemo(() => createRegistry(views), [views]);
@@ -65,5 +71,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
65
71
  // The first screen only: a re-render must not push it again.
66
72
  // eslint-disable-next-line react-hooks/exhaustive-deps
67
73
  }, [workspace]);
68
- return (_jsx(FrameworkProvider, { transport: cached, locale: language, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
74
+ return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
69
75
  }
@@ -1,7 +1,7 @@
1
1
  import { type Entity, type Transport } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Meta } from "@sincpro/criteria";
3
- import type { ViewProps, ViewSpec } from "@sincpro/web-composer";
4
- import type { ListDefinition } from "../../core/list.js";
3
+ import { type ViewProps, type ViewSpec } from "@sincpro/web-composer";
4
+ import { type ListDefinition } from "../../core/list.js";
5
5
  import { type ComponentType } from "react";
6
6
  /**
7
7
  * An entity as the composer's view: one `ViewSpec` for its list (a reference without an id)
@@ -44,6 +44,10 @@ export type EntityViewOptions = {
44
44
  goto?: boolean;
45
45
  /** Known before any search: no request asks for it. */
46
46
  meta?: Meta;
47
+ /** A record's name, the screen's way — for a model with no display field (a singleton reads
48
+ * as its key). Used by the default record; a record of its own passes it to
49
+ * `useRecordInWorkspace` / `useRecordScreen`. */
50
+ title?: (record: AnyRecord) => string | null;
47
51
  actions?: ViewSpec["actions"];
48
52
  /** ⌘K's question: the list route's params that say which records it searches. */
49
53
  search?: {
@@ -1,7 +1,9 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { listRoute, NEW_PARAM, scopeOfRef, } from "@sincpro/client-framework";
3
+ import { isEntityId, listRoute, NEW_PARAM, scopeOfRef, } from "@sincpro/client-framework";
4
4
  import { matching } from "@sincpro/criteria";
5
+ import { usePhone, } from "@sincpro/web-composer";
6
+ import { scopeNameOf } from "../../core/list.js";
5
7
  import { lookupOf } from "../../core/lookup.js";
6
8
  import { ListScopeProvider } from "../../react/scope.js";
7
9
  import { useListing } from "../../react/useListing.js";
@@ -17,6 +19,7 @@ import { useMemo } from "react";
17
19
  * a one2many's «Agregar» as the new record's form that answers once it exists.
18
20
  */
19
21
  function InWorkspace({ api, children }) {
22
+ usePhone(api); // the places follow the mode: on a phone, no side panel and no window
20
23
  const targets = targetsFor(api);
21
24
  const opening = useMemo(() => {
22
25
  // Never a modal over a modal: from inside one, what answers docks beside it.
@@ -33,29 +36,45 @@ function InWorkspace({ api, children }) {
33
36
  }, [api, targets]);
34
37
  return _jsx(RecordOpeningProvider, { value: opening, children: children });
35
38
  }
36
- /** The entity's list when the application writes none. */
37
- function listOf(entity) {
38
- return function DefaultList({ api }) {
39
- return _jsx(EntityList, { listing: useListing(entity), api: api });
39
+ /** The entity's list when the application writes none: opened under a named cut, it says
40
+ * whose it is («Facturas · Globex Bolivia»). */
41
+ function listOf(entity, name) {
42
+ return function DefaultList({ api, resource }) {
43
+ const of = scopeNameOf(resource);
44
+ return (_jsx(EntityList, { listing: useListing(entity), api: api, ...(of === undefined ? {} : { title: `${name} · ${of}` }) }));
40
45
  };
41
46
  }
42
47
  /** The entity's record when the application writes none. */
43
- function recordOf(entity) {
48
+ function recordOf(entity, title) {
44
49
  return function DefaultRecord(props) {
45
- return _jsx(EntityRecord, { ...props, entity: entity });
50
+ return (_jsx(EntityRecord, { ...props, entity: entity, ...(title === undefined ? {} : { title }) }));
46
51
  };
47
52
  }
53
+ /**
54
+ * What a reference reads as before its view names it — a crumb whose view is not mounted, a
55
+ * record still loading: the list is the view's name (with its cut's, `scopedRef`); a record
56
+ * its key when the key is something a person reads (`F-2026-0004`), the view's name when it is
57
+ * a machine's (a UUID v7, `isEntityId`).
58
+ */
59
+ function titleOf(ref, name) {
60
+ if (ref.id === undefined) {
61
+ const of = scopeNameOf(ref);
62
+ return of === undefined ? name : `${name} · ${of}`;
63
+ }
64
+ return isEntityId(ref.id) ? name : ref.id;
65
+ }
48
66
  export function entityView(entity, options) {
49
67
  let meta = options.meta ?? null;
50
68
  const route = listRoute(entity.list, options.search?.params);
51
69
  async function screens() {
52
70
  const loaded = options.load === undefined ? {} : await options.load();
53
- const List = loaded.list ?? options.list ?? listOf(entity);
54
- const One = loaded.record ?? options.record ?? recordOf(entity);
71
+ const List = loaded.list ?? options.list ?? listOf(entity, options.name);
72
+ const One = loaded.record ?? options.record ?? recordOf(entity, options.title);
55
73
  return function EntityView(props) {
56
74
  const record = props.resource.id !== undefined || props.resource.params?.[NEW_PARAM] !== undefined;
57
- // A chooser opened by a picker offers only what the picker may choose: its cut travels in
58
- // the reference, and the list — the application's own too — reads under it.
75
+ // A chooser opened by a picker offers only what the picker may choose, and a list opened
76
+ // under a cut (`scopedRef`) shows only what it cuts: the cut travels in the reference, and
77
+ // the list — the application's own too — reads under it.
59
78
  const cut = record ? undefined : scopeOfRef(props.resource);
60
79
  const list = cut === undefined ? (_jsx(List, { ...props })) : (_jsx(ListScopeProvider, { value: { key: entity.key, selection: cut }, children: _jsx(List, { ...props }) }));
61
80
  return _jsx(InWorkspace, { api: props.api, children: record ? _jsx(One, { ...props }) : list });
@@ -67,7 +86,7 @@ export function entityView(entity, options) {
67
86
  return {
68
87
  domain: entity.domain,
69
88
  kind: entity.kind,
70
- title: (ref) => ref.id ?? options.name,
89
+ title: (ref) => titleOf(ref, options.name),
71
90
  goto: options.goto ?? true,
72
91
  ...(options.icon === undefined ? {} : { icon: options.icon }),
73
92
  ...(options.actions === undefined ? {} : { actions: options.actions }),
@@ -1,6 +1,6 @@
1
1
  import { type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
3
- import type { ResourceRef, WorkspaceApi } from "@sincpro/web-composer";
3
+ import { type ResourceRef, type WorkspaceApi } from "@sincpro/web-composer";
4
4
  import { type OpenTarget } from "@sincpro/web-ui";
5
5
  import type { ReactNode } from "react";
6
6
  /**
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import {} from "@sincpro/client-framework";
4
+ import { usePhone } from "@sincpro/web-composer";
5
+ import { useNameOf } from "../../react/useNameOf.js";
4
6
  import { useSummaryOf } from "../../react/useSummary.js";
5
7
  import { openOptions, targetsFor } from "../list/openIn.js";
6
8
  import { relationOf } from "../record/summary.js";
@@ -44,9 +46,13 @@ export function openIn(api, ref, to, size) {
44
46
  */
45
47
  export function RelatedRecord({ api, entity, value, meta, editor, }) {
46
48
  const summarize = useSummaryOf(entity);
49
+ usePhone(api); // «Abrir en…» follows the mode: on a phone, no side panel and no window
50
+ // A key alone (`payment_id`, an `EntityID`) is read by its name, asked once by key — the key
51
+ // until it answers, and when nothing does. It used to stay the key: «P-0192…» for a payment.
52
+ const named = useNameOf(entity, typeof value === "string" ? value : "");
47
53
  const extra = editor === undefined ? {} : { editor };
48
54
  if (value === null || value === undefined || value === "")
49
55
  return _jsx(RelationValue, { name: null, ...extra });
50
56
  const summary = summarize(typeof value === "string" ? { id: value } : value, meta);
51
- return (_jsx(RelationValue, { ...relationOf(summary), onOpenIn: (to) => openIn(api, entity.ref(summary.id), to), openTargets: targetsFor(api), ...extra }));
57
+ return (_jsx(RelationValue, { ...relationOf(named === undefined ? summary : { ...summary, name: named }), onOpenIn: (to) => openIn(api, entity.ref(summary.id), to), openTargets: targetsFor(api), ...extra }));
52
58
  }