@sincpro/web-framework 3.2.0 → 3.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.
@@ -69,6 +69,8 @@ export type FrameworkCopy = {
69
69
  archive: string;
70
70
  /** Out of the trash (`Restore`): read again. */
71
71
  restore: string;
72
+ /** The record's main card in web-ui's «settings» form style, beside its other sections. */
73
+ general: string;
72
74
  };
73
75
  picker: {
74
76
  /** The button beside a many2one that opens the chooser over the whole set. */
package/dist/core/copy.js CHANGED
@@ -36,6 +36,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
36
36
  delete: "Delete",
37
37
  archive: "Move to the trash",
38
38
  restore: "Restore",
39
+ general: "General",
39
40
  },
40
41
  picker: {
41
42
  browse: "Search all",
@@ -125,6 +126,7 @@ export const SPANISH_FRAMEWORK_COPY = {
125
126
  delete: "Eliminar",
126
127
  archive: "Mover a la papelera",
127
128
  restore: "Restaurar",
129
+ general: "Datos generales",
128
130
  },
129
131
  picker: {
130
132
  browse: "Buscar en todos",
@@ -7,9 +7,10 @@ export { EntitySearchBar } from "./list/EntitySearchBar.js";
7
7
  export { groupableOf, pilesOf } from "./list/groups.js";
8
8
  export { OpenInMenu } from "./list/openIn.js";
9
9
  export { pivotOf } from "./list/pivot.js";
10
- export { type CardLook, type ChoiceTones, type OptionLook, type Presentation, presentationOf, type Presented, presented, type RowLook, } from "./list/presentation.js";
10
+ export { type CardLook, type ChoiceTones, type OptionLook, type PartLook, partLookOf, type PartLooks, type PartOf, type Presentation, presentationOf, type Presented, presented, type RowLook, tonesOver, } from "./list/presentation.js";
11
11
  export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
12
12
  export { facetsOf, modelOf } from "./list/search.js";
13
+ export { type ActionDialog, type Asked, } from "./record/ActionButton.js";
13
14
  export { type AskedField, type AskField, type AskForm, askFormOf, } from "./record/ask.js";
14
15
  export { CommandButton } from "./record/CommandButton.js";
15
16
  export { RelationPicker } from "./record/control.js";
@@ -18,7 +19,7 @@ export { EntityPicker } from "./record/EntityPicker.js";
18
19
  export { EntityTags } from "./record/EntityTags.js";
19
20
  export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, } from "./record/lines.js";
20
21
  export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
21
- export { countOf, factsOf, RecordLines } from "./record/record.js";
22
+ export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
22
23
  export { RecordLifecycle } from "./record/RecordLifecycle.js";
23
24
  export { RelatedList } from "./record/RelatedList.js";
24
25
  export { ServiceButton } from "./record/ServiceButton.js";
package/dist/web/index.js CHANGED
@@ -7,9 +7,10 @@ export { EntitySearchBar } from "./list/EntitySearchBar.js";
7
7
  export { groupableOf, pilesOf } from "./list/groups.js";
8
8
  export { OpenInMenu } from "./list/openIn.js";
9
9
  export { pivotOf } from "./list/pivot.js";
10
- export { presentationOf, presented, } from "./list/presentation.js";
10
+ export { partLookOf, presentationOf, presented, tonesOver, } from "./list/presentation.js";
11
11
  export { useRowCommands, } from "./list/rowCommands.js";
12
12
  export { facetsOf, modelOf } from "./list/search.js";
13
+ export {} from "./record/ActionButton.js";
13
14
  export { askFormOf, } from "./record/ask.js";
14
15
  export { CommandButton } from "./record/CommandButton.js";
15
16
  export { RelationPicker } from "./record/control.js";
@@ -18,7 +19,7 @@ export { EntityPicker } from "./record/EntityPicker.js";
18
19
  export { EntityTags } from "./record/EntityTags.js";
19
20
  export { RecordLinesEditor, } from "./record/lines.js";
20
21
  export { RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
21
- export { countOf, factsOf, RecordLines } from "./record/record.js";
22
+ export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
22
23
  export { RecordLifecycle } from "./record/RecordLifecycle.js";
23
24
  export { RelatedList } from "./record/RelatedList.js";
24
25
  export { ServiceButton } from "./record/ServiceButton.js";
@@ -58,6 +58,28 @@ export type Presentation<T> = {
58
58
  /** The fields a table of its records shows when the screen names none — on its own list and
59
59
  * inside another record (a one2many) alike. Without it, every field but the stamps. */
60
60
  columns?: readonly (keyof T & string)[];
61
+ /**
62
+ * How the parts its records hold look — the rows of a relation with no entity of its own (an
63
+ * issue's runs, a tenant's members), by the relation's name, typed by the part:
64
+ *
65
+ * presented(issues, { tones: { status: ISSUE_TONE }, parts: { runs: { tones: { status: RUN_TONE } } } })
66
+ *
67
+ * Context: a part has no route, so there is no `presented(runs, …)` to declare it with; its
68
+ * look belongs to the record that holds it. Declared here, every place that draws those rows
69
+ * reads it — `RecordLines`, the lines editor, a `RecordField` — and a screen passes its own
70
+ * only to change it.
71
+ */
72
+ parts?: PartLooks<T>;
73
+ };
74
+ /** How a record's part looks: what `Presentation` says of an entity, for a row it holds. */
75
+ export type PartLook<P> = Pick<Presentation<P>, "tones" | "columns">;
76
+ /** The record a field holds many of — an `EntityCollection<Run>`, a `Run[]` — or `never`. */
77
+ export type PartOf<V> = unknown extends V ? AnyRecord : NonNullable<V> extends {
78
+ readonly items: readonly (infer P)[];
79
+ } ? P : NonNullable<V> extends readonly (infer P)[] ? P : never;
80
+ /** A part's look by the name of the field that holds it — only fields that hold many. */
81
+ export type PartLooks<T> = {
82
+ readonly [K in keyof T & string as [PartOf<T[K]>] extends [never] ? never : K]?: PartLook<PartOf<T[K]>>;
61
83
  };
62
84
  export type Presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers> = Entity<T, C, A> & {
63
85
  readonly presentation: Presentation<T>;
@@ -66,5 +88,13 @@ export type Presented<T extends AnyRecord, C extends CommandBodies = CommandBodi
66
88
  export declare function presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, presentation: Presentation<T>): Presented<T, C, A>;
67
89
  /** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
68
90
  export declare function presentationOf<T extends AnyRecord>(source: Entity<T> | ListDefinition<T>): Presentation<T>;
91
+ /** How the parts an entity's records hold under `name` look; `{}` when it declares nothing. */
92
+ export declare function partLookOf(entity: Entity | ListDefinition<AnyRecord> | undefined, name: string): PartLook<AnyRecord>;
93
+ /**
94
+ * The tones of each layer over the one before, value by value — the entity's, then a part's
95
+ * declaration, then the screen's: a screen that colours `failed` keeps the declared `done`.
96
+ * `undefined` when no layer says anything.
97
+ */
98
+ export declare function tonesOver<T>(...layers: readonly (ChoiceTones<T> | undefined)[]): ChoiceTones<T> | undefined;
69
99
  /** `look` over `base`, leaving out what `look` sets to `undefined`: «no tags» is not a hole. */
70
100
  export declare function over<B extends object, L extends object>(base: B, look: L | undefined): B;
@@ -10,6 +10,30 @@ export function presentationOf(source) {
10
10
  const base = isList(source) ? source.entity : source;
11
11
  return "presentation" in base ? base.presentation : {};
12
12
  }
13
+ /** How the parts an entity's records hold under `name` look; `{}` when it declares nothing. */
14
+ export function partLookOf(entity, name) {
15
+ if (entity === undefined)
16
+ return {};
17
+ const parts = presentationOf(entity).parts;
18
+ return parts?.[name] ?? {};
19
+ }
20
+ /**
21
+ * The tones of each layer over the one before, value by value — the entity's, then a part's
22
+ * declaration, then the screen's: a screen that colours `failed` keeps the declared `done`.
23
+ * `undefined` when no layer says anything.
24
+ */
25
+ export function tonesOver(...layers) {
26
+ const said = layers.filter((one) => one !== undefined);
27
+ if (said.length === 0)
28
+ return undefined;
29
+ if (said.length === 1)
30
+ return said[0];
31
+ const out = {};
32
+ for (const layer of said)
33
+ for (const [field, tones] of Object.entries(layer))
34
+ out[field] = { ...out[field], ...tones };
35
+ return out;
36
+ }
13
37
  /** `look` over `base`, leaving out what `look` sets to `undefined`: «no tags» is not a hole. */
14
38
  export function over(base, look) {
15
39
  if (look === undefined)
@@ -2,6 +2,13 @@ import type { Rehearsal } from "../../react/useCommand.js";
2
2
  import type { AskForm } from "./ask.js";
3
3
  /** What a person filled in before the action runs, by field name. */
4
4
  export type Asked = Readonly<Record<string, unknown>>;
5
+ /** What an action's window says, when the screen says it its way. */
6
+ export type ActionDialog = {
7
+ /** Its title — the button's label without the «…» that said a window would open. */
8
+ title?: string;
9
+ /** One sentence under the title: what the action does, or what it takes. */
10
+ subtitle?: string;
11
+ };
5
12
  /**
6
13
  * What a button needs of an action to draw it — whatever runs behind: an entity's Command
7
14
  * (`useCommand`) or one of the application's use cases (`useService`).
@@ -31,14 +38,19 @@ export type ButtonAction<R> = {
31
38
  * «Confirmar»; when it can rehearse, the first «Confirmar» asks what it would do with them and
32
39
  * the second does it. A refusal stays in the dialog over the fields, so they can be put right.
33
40
  *
41
+ * Its window is titled by the label without its «…», and says more only when the screen does
42
+ * (`dialog`: its own title, a sentence under it).
43
+ *
34
44
  * Internal: the gesture is drawn here once; what runs behind is each button's own.
35
45
  */
36
- export declare function ActionButton<R>({ action, label, role, disabled, ask: form, onDone, }: {
46
+ export declare function ActionButton<R>({ action, label, role, disabled, ask: form, dialog, onDone, }: {
37
47
  action: ButtonAction<R>;
38
48
  label: string;
39
49
  role?: "primary" | "secondary" | "ghost";
40
50
  disabled?: boolean;
41
51
  /** What it asks for before it runs — `askFormOf`. */
42
52
  ask?: AskForm;
53
+ /** What its window says, over the default. */
54
+ dialog?: ActionDialog;
43
55
  onDone?: (answer: R) => void;
44
56
  }): import("react").JSX.Element;
@@ -4,8 +4,18 @@ import { frameworkCopy } from "../../core/copy.js";
4
4
  import { Refused } from "../Refused.js";
5
5
  import { Button, Dialog, Field, FormSection } from "@sincpro/web-ui";
6
6
  import { useState } from "react";
7
+ /**
8
+ * The words of an action's window. A button that opens one says so with «…» — «Agregar a un
9
+ * tenant…» —; the window is already open, so its title says it once, without them.
10
+ */
11
+ function wordsOf(label, dialog) {
12
+ return {
13
+ title: dialog?.title ?? label.replace(/\s*(?:…|\.\.\.)$/u, ""),
14
+ ...(dialog?.subtitle === undefined ? {} : { subtitle: dialog.subtitle }),
15
+ };
16
+ }
7
17
  /** The fields of an action that asks, its refusal over them and what its dry run said. */
8
- function AskDialog({ action, form, label, onClose, onDone, }) {
18
+ function AskDialog({ action, form, words, onClose, onDone, }) {
9
19
  const copy = frameworkCopy().command;
10
20
  const [values, setValues] = useState(() => ({ ...form.initial }));
11
21
  const rehearsing = action.rehearse !== undefined;
@@ -18,7 +28,7 @@ function AskDialog({ action, form, label, onClose, onDone, }) {
18
28
  if (answer !== undefined)
19
29
  onDone(answer);
20
30
  };
21
- return (_jsxs(Dialog, { open: true, title: label, onClose: onClose, footer: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
31
+ return (_jsxs(Dialog, { open: true, ...words, onClose: onClose, footer: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
22
32
  const control = {
23
33
  value: values[field.name],
24
34
  set: (next) => {
@@ -31,7 +41,9 @@ function AskDialog({ action, form, label, onClose, onDone, }) {
31
41
  invalid: false,
32
42
  label: field.label,
33
43
  };
34
- return field.labelled ? (_jsx("div", { children: field.draw(control) }, field.name)) : (_jsx(Field, { label: field.label, children: field.draw(control) }, field.name));
44
+ // A control that names itself is not wrapped in a `Field` (its name would double):
45
+ // what is expected goes under it.
46
+ return field.labelled ? (_jsxs("div", { className: "flex flex-col gap-1", children: [field.draw(control), field.hint === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: field.hint }))] }, field.name)) : (_jsx(Field, { label: field.label, ...(field.hint === undefined ? {} : { hint: field.hint }), children: field.draw(control) }, field.name));
35
47
  }) }), action.rehearsal === null ? null : _jsx("p", { className: "text-ink", children: action.rehearsal.text })] }));
36
48
  }
37
49
  /**
@@ -47,13 +59,17 @@ function AskDialog({ action, form, label, onClose, onDone, }) {
47
59
  * «Confirmar»; when it can rehearse, the first «Confirmar» asks what it would do with them and
48
60
  * the second does it. A refusal stays in the dialog over the fields, so they can be put right.
49
61
  *
62
+ * Its window is titled by the label without its «…», and says more only when the screen does
63
+ * (`dialog`: its own title, a sentence under it).
64
+ *
50
65
  * Internal: the gesture is drawn here once; what runs behind is each button's own.
51
66
  */
52
- export function ActionButton({ action, label, role = "secondary", disabled = false, ask: form, onDone, }) {
67
+ export function ActionButton({ action, label, role = "secondary", disabled = false, ask: form, dialog, onDone, }) {
53
68
  const copy = frameworkCopy().command;
54
69
  const [open, setOpen] = useState(false);
70
+ const words = wordsOf(label, dialog);
55
71
  if (form !== undefined)
56
- return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: role, disabled: disabled || action.busy, onClick: () => setOpen(true), children: label }), open ? (_jsx(AskDialog, { action: action, form: form, label: label, onClose: () => {
72
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: role, disabled: disabled || action.busy, onClick: () => setOpen(true), children: label }), open ? (_jsx(AskDialog, { action: action, form: form, words: words, onClose: () => {
57
73
  setOpen(false);
58
74
  action.reset();
59
75
  }, onDone: (answer) => {
@@ -80,5 +96,5 @@ export function ActionButton({ action, label, role = "secondary", disabled = fal
80
96
  setOpen(false);
81
97
  action.reset();
82
98
  };
83
- 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] }));
99
+ 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, ...words, 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] }));
84
100
  }
@@ -1,6 +1,7 @@
1
1
  import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type AnswerOf } from "../../react/useCommand.js";
4
+ import { type ActionDialog } from "./ActionButton.js";
4
5
  import { type AskField } from "./ask.js";
5
6
  /**
6
7
  * An entity's Command as a button: sent as it is, over the screens' transport.
@@ -14,7 +15,7 @@ import { type AskField } from "./ask.js";
14
15
  * record's fields of the same name, filled from `record`, and what is filled goes in the body
15
16
  * beside `body`.
16
17
  */
17
- 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, ask, record, onDone, }: {
18
+ 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, ask, record, dialog, onDone, }: {
18
19
  entity: Entity<T, C, A>;
19
20
  /** One the entity declares; a typed entity takes only its own names. */
20
21
  command: N;
@@ -31,5 +32,7 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
31
32
  ask?: readonly AskField[];
32
33
  /** The record it acts on: what the asked fields start with. */
33
34
  record?: AnyRecord;
35
+ /** What its window says — its title (the label without «…» by default), a sentence under it. */
36
+ dialog?: ActionDialog;
34
37
  onDone?: (answer: AnswerOf<R, A, N>) => void;
35
38
  }): import("react").JSX.Element;
@@ -4,7 +4,7 @@ import {} from "@sincpro/client-framework";
4
4
  import { entityFor } from "../../core/relation.js";
5
5
  import { useFramework } from "../../react/context.js";
6
6
  import { useCommand } from "../../react/useCommand.js";
7
- import { ActionButton } from "./ActionButton.js";
7
+ import { ActionButton, } from "./ActionButton.js";
8
8
  import { askFormOf } from "./ask.js";
9
9
  /**
10
10
  * An entity's Command as a button: sent as it is, over the screens' transport.
@@ -18,7 +18,7 @@ import { askFormOf } from "./ask.js";
18
18
  * record's fields of the same name, filled from `record`, and what is filled goes in the body
19
19
  * beside `body`.
20
20
  */
21
- export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, ask, record, onDone, }) {
21
+ export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, ask, record, dialog, onDone, }) {
22
22
  const sending = useCommand(entity, command);
23
23
  const { metas, entities, locale } = useFramework();
24
24
  const form = ask === undefined
@@ -30,7 +30,7 @@ export function CommandButton({ entity, command, id, body, label, destructive =
30
30
  entityFor: (target) => entityFor(entities, target, metas.get),
31
31
  });
32
32
  const bodyWith = (asked) => (asked === undefined ? body : { ...body, ...asked });
33
- return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), action: {
33
+ return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(dialog === undefined ? {} : { dialog }), action: {
34
34
  run: (asked) => sending.run(id, bodyWith(asked)),
35
35
  ...(destructive
36
36
  ? { rehearse: (asked) => sending.rehearse(id, bodyWith(asked)) }
@@ -1,7 +1,7 @@
1
1
  import type { Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import type { Rehearsal } from "../../react/useCommand.js";
4
- import { type Asked } from "./ActionButton.js";
4
+ import { type ActionDialog, type Asked } from "./ActionButton.js";
5
5
  import { type AskField } from "./ask.js";
6
6
  /**
7
7
  * One of the application's use cases as a button — its Feature or ApplicationService, run on its
@@ -28,7 +28,7 @@ import { type AskField } from "./ask.js";
28
28
  * <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
29
29
  * run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
30
30
  */
31
- export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, ask, entity, record, onDone, }: {
31
+ export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, ask, entity, record, dialog, onDone, }: {
32
32
  label: string;
33
33
  /** The use case, executed on its bounded context — with what was asked, when it asks. */
34
34
  run: (asked: Asked) => Promise<R>;
@@ -43,5 +43,7 @@ export declare function ServiceButton<R>({ label, run, rehearse, role, disabled,
43
43
  entity?: Entity;
44
44
  /** The record it acts on: what the asked fields start with. */
45
45
  record?: AnyRecord;
46
+ /** What its window says — its title (the label without «…» by default), a sentence under it. */
47
+ dialog?: ActionDialog;
46
48
  onDone?: (answer: R) => void;
47
49
  }): import("react").JSX.Element;
@@ -3,7 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { entityFor } from "../../core/relation.js";
4
4
  import { useFrameworkIfAny } from "../../react/context.js";
5
5
  import { useService } from "../../react/useService.js";
6
- import { ActionButton } from "./ActionButton.js";
6
+ import { ActionButton, } from "./ActionButton.js";
7
7
  import { askFormOf } from "./ask.js";
8
8
  /** What the button runs when there is no dry run: nothing. */
9
9
  const NO_REHEARSAL = async (_asked) => undefined;
@@ -34,7 +34,7 @@ const NOTHING_ASKED = {};
34
34
  * <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
35
35
  * run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
36
36
  */
37
- export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, ask, entity, record, onDone, }) {
37
+ export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, ask, entity, record, dialog, onDone, }) {
38
38
  const running = useService((asked) => run(asked ?? NOTHING_ASKED));
39
39
  const rehearsing = useService((asked) => (rehearse ?? NO_REHEARSAL)(asked ?? NOTHING_ASKED));
40
40
  // Outside a provider it still runs: the asked fields are then drawn by what `ask` says.
@@ -51,7 +51,7 @@ export function ServiceButton({ label, run, rehearse, role = "secondary", disabl
51
51
  entityFor: (target) => entityFor(framework.entities, target, framework.metas.get),
52
52
  }),
53
53
  });
54
- return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), action: {
54
+ return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(dialog === undefined ? {} : { dialog }), action: {
55
55
  run: running.run,
56
56
  ...(rehearse === undefined ? {} : { rehearse: rehearsing.run }),
57
57
  busy: running.busy || rehearsing.busy,
@@ -3,23 +3,28 @@ import { type AnyRecord, type Meta } from "@sincpro/criteria";
3
3
  import { type FieldControl } from "./control.js";
4
4
  import type { ReactNode } from "react";
5
5
  /**
6
- * A field an action asks for before it runs: a field of the entity by its name — `"areas"` —, or
7
- * one the entity does not have, described by the action.
6
+ * A field an action asks for before it runs: a field of the entity by its name — `"areas"` —,
7
+ * or an object that says more about it — its starting value, a hint, its own control —, or
8
+ * describes one the entity does not have.
8
9
  *
9
10
  * <CommandButton entity={cuentas} command="delegar_areas" id={cuenta.id} record={cuenta}
10
- * label="Delegar áreas" ask={["areas"]} />
11
+ * label="Delegar áreas…" ask={["areas"]} />
11
12
  * ask={[{ name: "motivo", label: "Motivo", widget: "textarea" }]}
13
+ * ask={[{ name: "role", label: "Rol", choices: ROLES, initial: "member", hint: "Lo que podrá hacer" }]}
12
14
  *
13
15
  * Context: a Command that needs input could not live among a record's actions, so a screen drew
14
16
  * its fields in the record's body with a button of their own. What the dialog shows is the
15
- * screen's: the backend adds nothing for it. A field named by the entity reads as the record's
16
- * field of that name — its label, its choices in their words, its control —; a control of the
17
+ * screen's: the backend adds nothing for it. A field is read as the entity's field of that name
18
+ * when it has one — its label, its choices in their words, its control, its help — and what the
19
+ * object says goes OVER that, key by key: `{ name: "areas", hint }` is the entity's field with a
20
+ * hint, `{ name: "motivo", label, widget }` a field the entity lacks. A control of the
17
21
  * application's goes in with `as`, never a widget named in a string (`widget` takes only the
18
22
  * framework's own).
19
23
  */
20
24
  export type AskField = string | {
21
25
  name: string;
22
- label: string;
26
+ /** Its word on screen — the entity's label for a field of that name when not given. */
27
+ label?: string;
23
28
  /** The type of its value as the model writes it — `text` (the default), `number`, `date`,
24
29
  * `boolean`, `text[]`. */
25
30
  type?: string;
@@ -32,11 +37,18 @@ export type AskField = string | {
32
37
  widget?: "textarea";
33
38
  /** The application's own control. */
34
39
  as?: (control: FieldControl) => ReactNode;
40
+ /** What it starts with when the record holds nothing under its name: a role that starts at
41
+ * «Miembro». What the record holds still wins — the action starts from the record. */
42
+ initial?: unknown;
43
+ /** What is expected, said by the field — over the backend's own help for it. */
44
+ hint?: string;
35
45
  };
36
46
  /** A field ready to draw: its name, its label, its control. */
37
47
  export type AskedField = {
38
48
  name: string;
39
49
  label: string;
50
+ /** What is expected — the action's hint, or the model's help for the field. */
51
+ hint?: string | undefined;
40
52
  /** It draws its own label — a yes/no, a list of checks —: not wrapped in a `Field`. */
41
53
  labelled: boolean;
42
54
  draw: (control: FieldControl) => ReactNode;
@@ -47,8 +59,9 @@ export type AskForm = {
47
59
  initial: Readonly<Record<string, unknown>>;
48
60
  };
49
61
  /**
50
- * The asked fields, drawn from the entity's model, and what they start with: the record's own
51
- * values. Its key is never asked — the action already knows whose record it is.
62
+ * The asked fields, drawn from the entity's model with what each says over it, and what they
63
+ * start with: the record's own values, else the field's `initial`. Its key is never asked by
64
+ * name — the action already knows whose record it is.
52
65
  */
53
66
  export declare function askFormOf(fields: readonly AskField[], options: {
54
67
  meta: Meta | null | undefined;
@@ -9,8 +9,9 @@ function labels(type, choices) {
9
9
  return type === "boolean" || (type.endsWith("[]") && choices.length > 0);
10
10
  }
11
11
  /**
12
- * The asked fields, drawn from the entity's model, and what they start with: the record's own
13
- * values. Its key is never asked — the action already knows whose record it is.
12
+ * The asked fields, drawn from the entity's model with what each says over it, and what they
13
+ * start with: the record's own values, else the field's `initial`. Its key is never asked by
14
+ * name — the action already knows whose record it is.
14
15
  */
15
16
  export function askFormOf(fields, options) {
16
17
  const { meta, locale, record } = options;
@@ -18,42 +19,45 @@ export function askFormOf(fields, options) {
18
19
  const asked = [];
19
20
  const initial = {};
20
21
  for (const one of fields) {
21
- if (typeof one !== "string") {
22
- const choices = [...(one.choices ?? [])];
23
- const type = one.type ?? "text";
24
- asked.push({
25
- name: one.name,
26
- label: one.label,
27
- labelled: one.as === undefined && labels(type, choices),
28
- draw: (control) => one.as?.(control) ?? controlFor(control, type, false, choices, one.widget),
29
- });
30
- if (record !== undefined && record[one.name] !== undefined)
31
- initial[one.name] = record[one.name];
22
+ if (typeof one === "string" && (one === key || one === "id"))
32
23
  continue;
33
- }
34
- if (one === key || one === "id")
35
- continue;
36
- const view = viewOf(meta, one, locale);
37
- const field = fieldMetaOf(meta, one);
38
- const relation = relationFieldOf(meta, one);
39
- const target = relation === undefined || relation.many
24
+ const said = typeof one === "string" ? { name: one } : one;
25
+ const field = fieldMetaOf(meta, said.name);
26
+ // A field of the entity is read from the model; one it lacks only as the action says.
27
+ const view = field === undefined ? undefined : viewOf(meta, said.name, locale);
28
+ const relation = field === undefined ? undefined : relationFieldOf(meta, said.name);
29
+ // A many2one is chosen by its key, with the picker of the entity it points at — unless the
30
+ // action says how it is written: then it writes the name it gave.
31
+ const target = relation === undefined ||
32
+ relation.many ||
33
+ said.as !== undefined ||
34
+ said.type !== undefined ||
35
+ said.choices !== undefined
40
36
  ? undefined
41
37
  : options.entityFor?.(relation.target);
42
- // A many2one is chosen by its key, with the picker of the entity it points at.
43
- const name = target === undefined || relation === undefined ? one : relation.key;
44
- const choices = choicesOf(meta, one, locale);
38
+ const name = target === undefined || relation === undefined ? said.name : relation.key;
39
+ const type = said.type ?? view?.type ?? "text";
40
+ const choices = said.choices ?? (field === undefined ? [] : choicesOf(meta, said.name, locale));
41
+ const widget = said.widget ?? field?.widget;
42
+ const label = said.label ?? view?.label ?? said.name;
43
+ const hint = said.hint ?? view?.help;
45
44
  asked.push({
46
45
  name,
47
- label: view.label,
48
- labelled: target === undefined && labels(view.type, choices),
49
- draw: target === undefined
50
- ? (control) => controlFor(control, view.type, field?.exact === true, choices, field?.widget)
51
- : (control) => (_jsx(RelationPicker, { target: target, value: control.value === null || control.value === undefined
52
- ? ""
53
- : String(control.value), onChange: (id) => control.set(id), label: control.label, onClear: () => control.set(null) })),
46
+ label,
47
+ hint,
48
+ labelled: said.as === undefined && target === undefined && labels(type, [...choices]),
49
+ draw: said.as ??
50
+ (target === undefined
51
+ ? (control) => controlFor(control, type, field?.exact === true, [...choices], widget)
52
+ : (control) => (_jsx(RelationPicker, { target: target, value: control.value === null || control.value === undefined
53
+ ? ""
54
+ : String(control.value), onChange: (id) => control.set(id), label: control.label, onClear: () => control.set(null) }))),
54
55
  });
55
- if (record !== undefined && record[name] !== undefined)
56
- initial[name] = record[name];
56
+ // What the record holds wins; a field it leaves empty starts at what the action says.
57
+ const held = record?.[name];
58
+ const start = held === undefined || held === null ? (said.initial ?? held) : held;
59
+ if (start !== undefined)
60
+ initial[name] = start;
57
61
  }
58
62
  return { fields: asked, initial };
59
63
  }
@@ -24,11 +24,15 @@ export type FieldControl = {
24
24
  * note, so every application passed `as` for each long text. Only the framework's own names are
25
25
  * read here: a name an application registers is drawn with `as`, never looked up in a registry
26
26
  * of strings.
27
+ *
28
+ * `segmented`: the form asks for a short choice to be a segmented control — web-ui's «settings»
29
+ * form style, for a REQUIRED choice (a segmented control cannot be emptied). It still is a select
30
+ * in a cell, and with more than three options or a label that would not fit beside the others.
27
31
  */
28
32
  export declare function controlFor(control: FieldControl, type: string, exact: boolean, choices: {
29
33
  value: unknown;
30
34
  label: string;
31
- }[], widget?: string): ReactNode;
35
+ }[], widget?: string, segmented?: boolean): ReactNode;
32
36
  /**
33
37
  * A many2one's control: the picker of the entity it points at — the server's literal search,
34
38
  * the first ten, «Buscar más…» — opening the chosen one where the view says.
@@ -2,7 +2,11 @@
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, CheckList, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
5
+ import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, SegmentedControl, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
6
+ /** A choice answered with one press — a segmented control — instead of a select: up to three
7
+ * options that fit side by side. */
8
+ const FEW_CHOICES = 3;
9
+ const SHORT_LABEL = 24;
6
10
  /**
7
11
  * The control a field's TYPE asks for — a choice, several of a choice (checks), a number, a
8
12
  * date, a date and time, a yes/no, a list of words, a text — or the one its `widget` names when the model names one of the
@@ -15,14 +19,24 @@ import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, Select, T
15
19
  * note, so every application passed `as` for each long text. Only the framework's own names are
16
20
  * read here: a name an application registers is drawn with `as`, never looked up in a registry
17
21
  * of strings.
22
+ *
23
+ * `segmented`: the form asks for a short choice to be a segmented control — web-ui's «settings»
24
+ * form style, for a REQUIRED choice (a segmented control cannot be emptied). It still is a select
25
+ * in a cell, and with more than three options or a label that would not fit beside the others.
18
26
  */
19
- export function controlFor(control, type, exact, choices, widget) {
27
+ export function controlFor(control, type, exact, choices, widget, segmented = false) {
20
28
  const { value, set } = control;
21
29
  const named = control.standalone === true ? { "aria-label": control.label } : {};
22
30
  // Several of the values at once — a list whose values are a choice: each one a check, the
23
31
  // list's label above them.
24
32
  if (choices.length > 0 && type.endsWith("[]"))
25
33
  return (_jsx(CheckList, { label: control.label, items: choices.map((one) => ({ value: String(one.value), label: one.label })), value: Array.isArray(value) ? value.map(String) : [], onChange: set }));
34
+ if (segmented &&
35
+ control.standalone !== true &&
36
+ choices.length > 0 &&
37
+ choices.length <= FEW_CHOICES &&
38
+ choices.every((one) => one.label.length <= SHORT_LABEL))
39
+ return (_jsx(SegmentedControl, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set }));
26
40
  if (choices.length > 0)
27
41
  return (_jsx(Select, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set, ...named }));
28
42
  switch (type) {
@@ -14,7 +14,7 @@ import { RecordLinesEditor } from "./lines.js";
14
14
  import { useRecordOpening } from "./opening.js";
15
15
  import { RecordLines } from "./record.js";
16
16
  import { RelatedList } from "./RelatedList.js";
17
- import { Checkbox, Field, FormSection, ReadValue, RelationValue, } from "@sincpro/web-ui";
17
+ import { Checkbox, Field, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
18
18
  /** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
19
19
  function setAt(value, path, next) {
20
20
  const base = typeof value === "object" && value !== null ? value : {};
@@ -79,6 +79,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
79
79
  const target = useEntityFor(relation?.target);
80
80
  const opening = useRecordOpening();
81
81
  const { metas } = useFramework();
82
+ const settings = useFormStyle() === "settings";
82
83
  if (!state.visible)
83
84
  return null;
84
85
  // A one2many is a BLOCK, named by a section — never a `Field`: web-ui's controls read the
@@ -108,14 +109,14 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
108
109
  // A page of them stays read only, as a one2many's: written back whole it would drop what
109
110
  // it did not bring.
110
111
  const whole = editableLines(edit.values[name]);
111
- const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, locale: locale })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
112
+ const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, entity: record.entity, locale: locale, ...(look?.columns === undefined ? {} : { columns: look.columns }), ...(look?.tones === undefined ? {} : { tones: look.tones }) })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
112
113
  return bare ? lines : _jsx(FormSection, { title: view.label, children: lines });
113
114
  }
114
115
  if (as === undefined && relation?.field.type === "one2many" && target === undefined) {
115
116
  // Editable when the record holds ALL its lines; a page of them stays read only, and so do
116
117
  // the records it only references — nothing it saves writes them.
117
118
  const whole = editableLines(edit.values[name], relation.field);
118
- const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, locale: locale })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
119
+ const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, entity: record.entity, locale: locale, ...(look?.columns === undefined ? {} : { columns: look.columns }), ...(look?.tones === undefined ? {} : { tones: look.tones }) })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
119
120
  return bare ? lines : _jsx(FormSection, { title: view.label, children: lines });
120
121
  }
121
122
  if (as === undefined && relation?.field.type === "one2many" && target !== undefined) {
@@ -191,7 +192,9 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
191
192
  return controlFor(control, view.type, false, choices, field?.widget);
192
193
  if (view.type === "boolean" && as === undefined)
193
194
  return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
194
- 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, choices, field?.widget)) }));
195
+ return (_jsx(Field, { label: view.label, required: state.required && !state.readonly,
196
+ // Said only in web-ui's «settings» form style: a field that may stay empty, and is typed in.
197
+ optional: !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, choices, field?.widget, settings && state.required)) }));
195
198
  }
196
199
  /**
197
200
  * The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
@@ -1,6 +1,7 @@
1
1
  import { type AnyRecord } from "@sincpro/criteria";
2
2
  import { type LineAdding } from "../../core/lines.js";
3
3
  import type { RecordReading } from "../../react/useRecord.js";
4
+ import type { ChoiceTones } from "../list/presentation.js";
4
5
  import { type FieldControl } from "./control.js";
5
6
  import { type LineEditorState } from "@sincpro/web-ui";
6
7
  import { type ReactNode } from "react";
@@ -39,6 +40,9 @@ export type LinesLook = {
39
40
  columns?: readonly string[];
40
41
  /** A field's cell drawn the screen's way, while it reads. */
41
42
  cells?: Readonly<Partial<Record<string, (line: AnyRecord) => ReactNode>>>;
43
+ /** The colour of each value of a choice, read as a tag — over what the record's entity
44
+ * declared for these lines (`presented(…, { parts })`). */
45
+ tones?: ChoiceTones<AnyRecord>;
42
46
  /** A field written with the screen's own widget — in its cell and in the dialog. */
43
47
  controls?: Readonly<Partial<Record<string, (control: LineControl) => ReactNode>>>;
44
48
  /** Columns that are not fields, after the fields. */
@@ -8,7 +8,8 @@ import { entityFor, relationFieldOf, } from "../../core/relation.js";
8
8
  import { useEntityFor, useFramework } from "../../react/context.js";
9
9
  import { controlFor, RelationPicker, } from "./control.js";
10
10
  import { RecordOpeningProvider, useRecordOpening, } from "./opening.js";
11
- import { Field, LineItems, ReadValue, } from "@sincpro/web-ui";
11
+ import { usePartLook } from "./record.js";
12
+ import { Field, LineItems, ReadValue, Tag, } from "@sincpro/web-ui";
12
13
  import { useRef } from "react";
13
14
  /** How a field of a line reads: a many2one's key by the name of what it points at. */
14
15
  function textIn(definition, field, relation, line, locale) {
@@ -105,7 +106,13 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
105
106
  ? (definition?.identity ?? "")
106
107
  : definition?.identity || "id";
107
108
  const fields = lineFields(definition);
108
- const shown = look.columns === undefined ? fields : look.columns.filter((one) => fields.includes(one));
109
+ // What the record's entity declared for these lines, under what the screen says.
110
+ const part = usePartLook(meta, name, {
111
+ entity: record.entity,
112
+ columns: look.columns,
113
+ tones: look.tones,
114
+ });
115
+ const shown = part.columns === undefined ? fields : part.columns.filter((one) => fields.includes(one));
109
116
  const controls = look.controls ?? {};
110
117
  const own = new Set(Object.keys(controls));
111
118
  const declared = (target) => entityFor(entities, target, metas.get) !== undefined;
@@ -139,12 +146,20 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
139
146
  definition.fields[field]?.readonly !== true &&
140
147
  (own.has(field) || writtenInCell(definition, field, declared));
141
148
  const ownCell = look.cells?.[field];
149
+ const tones = part.tones?.[field];
150
+ const toned = tones !== undefined && (definition?.fields[field]?.choices?.length ?? 0) > 0
151
+ ? (line) => {
152
+ const word = textIn(definition, field, relation, line, locale);
153
+ return word === "" ? null : (_jsx(Tag, { tone: tones[String(line[field])] ?? "neutral", children: word }));
154
+ }
155
+ : undefined;
142
156
  return {
143
157
  id: field,
144
158
  header: view.label,
145
159
  value: (line) => line[field],
146
160
  // Drawn as read: «Cemento 50 kg», not «CEM-50»; «1.552,00», not «1552.00».
147
- cell: ownCell ?? ((line) => textIn(definition, field, relation, line, locale)),
161
+ // A choice the record's entity coloured reads as its tag, as in a list.
162
+ cell: ownCell ?? toned ?? ((line) => textIn(definition, field, relation, line, locale)),
148
163
  text: (line) => textIn(definition, field, relation, line, locale),
149
164
  numeric: view.type === "number" || view.type === "integer",
150
165
  ...(inCell
@@ -1,4 +1,6 @@
1
+ import type { Entity } from "@sincpro/client-framework";
1
2
  import { type AnyRecord, type Meta } from "@sincpro/criteria";
3
+ import { type ChoiceTones, type PartLook } from "../list/presentation.js";
2
4
  import { type RowAction, type SheetField } from "@sincpro/web-ui";
3
5
  import type { ReactNode } from "react";
4
6
  export declare function factsOf<T extends AnyRecord>(record: T, meta: Meta | null | undefined, names: readonly string[], options?: {
@@ -7,6 +9,19 @@ export declare function factsOf<T extends AnyRecord>(record: T, meta: Meta | nul
7
9
  }): SheetField[];
8
10
  /** How many records a relation of this record holds — the TOTAL, not the page it brought. */
9
11
  export declare function countOf(record: AnyRecord, name: string): number;
12
+ /**
13
+ * How the rows of `name` look, layer over layer: the related entity's own presentation (when the
14
+ * relation points at a declared one), the parts the record's entity declared
15
+ * (`presented(issues, { parts: { runs: … } })`), and what the screen passes — each over the one
16
+ * before, so a screen changes one colour and keeps the rest.
17
+ *
18
+ * The record's entity is the one given, or the provider's entity of the model's aggregate.
19
+ */
20
+ export declare function usePartLook<T extends AnyRecord>(meta: Meta | null | undefined, name: string, own: {
21
+ entity?: Entity | undefined;
22
+ columns?: readonly string[] | undefined;
23
+ tones?: ChoiceTones<T> | undefined;
24
+ }): PartLook<T>;
10
25
  /**
11
26
  * A one2many / many2many of the record, as an embedded list.
12
27
  *
@@ -14,6 +29,10 @@ export declare function countOf(record: AnyRecord, name: string): number;
14
29
  * read off the rows otherwise. When the record brought only one page of them, it says so —
15
30
  * «se muestran 50 de 1000» — instead of drawing 50 as if they were all.
16
31
  *
32
+ * A choice of a row — a run's state, a member's role — is a tag in the colour declared ONCE
33
+ * with the record's entity (`presented(issues, { parts: { runs: { tones } } })`); `tones` here
34
+ * changes it for this screen, value by value.
35
+ *
17
36
  * `rowActions` acts on a part from its row — a group's member, a project's share — with a
18
37
  * Command of the record (`useCommand(projects, "unshareProject")`): the parts have no route of
19
38
  * their own, so what removes one is the record's, and the screen names it.
@@ -22,12 +41,17 @@ export declare function countOf(record: AnyRecord, name: string): number;
22
41
  * rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
23
42
  * onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
24
43
  */
25
- export declare function RecordLines<T extends AnyRecord>({ record, meta, name, columns, cells, locale, onOpen, rowActions, }: {
44
+ export declare function RecordLines<T extends AnyRecord>({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }: {
26
45
  record: AnyRecord;
27
46
  meta: Meta | null | undefined;
28
47
  name: string;
48
+ /** The record's entity, whose presentation says how these rows look (`parts`). Without it,
49
+ * the provider's entity of the model's aggregate. */
50
+ entity?: Entity | undefined;
29
51
  columns?: readonly string[];
30
52
  cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
53
+ /** The colour of each value of a choice of a row, over what the entities declared. */
54
+ tones?: ChoiceTones<T> | undefined;
31
55
  locale?: string | undefined;
32
56
  onOpen?: (row: T) => void;
33
57
  /** What a row's part can be acted on with — a Command of the record. */
@@ -4,10 +4,11 @@ import { describeRows } from "@sincpro/criteria";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
5
  import { textOf, valueAt, 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";
7
+ import { entityFor, relationFieldOf, } from "../../core/relation.js";
8
+ import { useEntityFor, useFrameworkIfAny } from "../../react/context.js";
9
9
  import { useNameOf } from "../../react/useNameOf.js";
10
10
  import { columnsOf } from "../list/columns.js";
11
+ import { partLookOf, presentationOf, tonesOver, } from "../list/presentation.js";
11
12
  import { useRecordOpening } from "./opening.js";
12
13
  import { List, RelationValue, } from "@sincpro/web-ui";
13
14
  /**
@@ -76,6 +77,30 @@ function RelationFact({ record, meta, name, relation, locale, }) {
76
77
  export function countOf(record, name) {
77
78
  return relatedOf(record[name]).count.value;
78
79
  }
80
+ /**
81
+ * How the rows of `name` look, layer over layer: the related entity's own presentation (when the
82
+ * relation points at a declared one), the parts the record's entity declared
83
+ * (`presented(issues, { parts: { runs: … } })`), and what the screen passes — each over the one
84
+ * before, so a screen changes one colour and keeps the rest.
85
+ *
86
+ * The record's entity is the one given, or the provider's entity of the model's aggregate.
87
+ */
88
+ export function usePartLook(meta, name, own) {
89
+ const framework = useFrameworkIfAny();
90
+ const find = (target) => target === undefined || framework === null
91
+ ? undefined
92
+ : entityFor(framework.entities, target, framework.metas.get);
93
+ const declared = partLookOf(own.entity ?? find(meta?.aggregate), name);
94
+ const relation = relationFieldOf(meta, name);
95
+ const related = relation?.many === true ? find(relation.target) : undefined;
96
+ const itself = related === undefined ? {} : presentationOf(related);
97
+ const columns = own.columns ?? declared.columns ?? itself.columns;
98
+ const tones = tonesOver(itself.tones, declared.tones, own.tones);
99
+ return {
100
+ ...(columns === undefined ? {} : { columns: columns }),
101
+ ...(tones === undefined ? {} : { tones }),
102
+ };
103
+ }
79
104
  /**
80
105
  * A one2many / many2many of the record, as an embedded list.
81
106
  *
@@ -83,6 +108,10 @@ export function countOf(record, name) {
83
108
  * read off the rows otherwise. When the record brought only one page of them, it says so —
84
109
  * «se muestran 50 de 1000» — instead of drawing 50 as if they were all.
85
110
  *
111
+ * A choice of a row — a run's state, a member's role — is a tag in the colour declared ONCE
112
+ * with the record's entity (`presented(issues, { parts: { runs: { tones } } })`); `tones` here
113
+ * changes it for this screen, value by value.
114
+ *
86
115
  * `rowActions` acts on a part from its row — a group's member, a project's share — with a
87
116
  * Command of the record (`useCommand(projects, "unshareProject")`): the parts have no route of
88
117
  * their own, so what removes one is the record's, and the screen names it.
@@ -91,10 +120,15 @@ export function countOf(record, name) {
91
120
  * rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
92
121
  * onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
93
122
  */
94
- export function RecordLines({ record, meta, name, columns, cells, locale, onOpen, rowActions, }) {
123
+ export function RecordLines({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }) {
124
+ const look = usePartLook(meta, name, { entity, columns, tones });
95
125
  const related = relatedOf(record[name]);
96
126
  const definition = meta?.fields[name]?.definition ?? describeRows(related.items);
97
127
  const identity = definition.identity || "id";
98
128
  const copy = frameworkCopy();
99
- return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(List, { embedded: true, items: related.items, keyOf: (row) => String(row[identity]), present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), children: _jsx(List.Table, { columns: columnsOf(definition, columns, { locale, ...(cells ? { cells } : {}) }), ...(rowActions === undefined ? {} : { rowActions }) }) }), related.partial ? (_jsx("p", { className: "text-meta text-muted", children: copy.record.partial(related.items.length, related.count.value, related.count.exact) })) : null] }));
129
+ return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(List, { embedded: true, items: related.items, keyOf: (row) => String(row[identity]), present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), children: _jsx(List.Table, { columns: columnsOf(definition, look.columns, {
130
+ locale,
131
+ ...(cells ? { cells } : {}),
132
+ ...(look.tones === undefined ? {} : { tones: look.tones }),
133
+ }), ...(rowActions === undefined ? {} : { rowActions }) }) }), related.partial ? (_jsx("p", { className: "text-meta text-muted", children: copy.record.partial(related.items.length, related.count.value, related.count.exact) })) : null] }));
100
134
  }
@@ -50,7 +50,7 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
50
50
  record: {
51
51
  error?: string | undefined;
52
52
  dirty?: import("@sincpro/web-ui").DirtyState | undefined;
53
- placement: "page" | "card";
53
+ placement: "card" | "page";
54
54
  identity: {
55
55
  tag?: {
56
56
  tone?: import("@sincpro/web-ui").Tone | undefined;
@@ -17,7 +17,7 @@ import { dirtyOf, RecordField } from "../record/edit.js";
17
17
  import { RecordLifecycle } from "../record/RecordLifecycle.js";
18
18
  import { Refused } from "../Refused.js";
19
19
  import { useRecordInWorkspace } from "./workspace.js";
20
- import { Button, Callout, FormSection, Record, Skeleton } from "@sincpro/web-ui";
20
+ import { Button, Callout, FormSection, Record, Skeleton, useFormStyle, } from "@sincpro/web-ui";
21
21
  import { useState } from "react";
22
22
  /**
23
23
  * The record of an entity, drawn from its model — the screen `entityView` opens when the
@@ -158,6 +158,7 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
158
158
  // On a phone a form is one column, its label over its value: two side by side at 400 px
159
159
  // squeezed a text area beside its word (web-ui's grid does not narrow by itself).
160
160
  const phone = usePhone(api);
161
+ const settings = useFormStyle() === "settings";
161
162
  if (reading.status === "loading")
162
163
  return _jsx(Skeleton, { rows: 6, label: copy.loading });
163
164
  if (reading.status === "failed")
@@ -180,7 +181,9 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
180
181
  const own = actions?.(reading) ?? null;
181
182
  const ownActions = own === null && lifecycle === null ? null : (_jsxs(_Fragment, { children: [own, lifecycle] }));
182
183
  const tabs = pages ?? layout.pages;
183
- return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: phone ? "stacked" : "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: columns, children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), fields !== undefined
184
+ return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: phone ? "stacked" : "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: columns, ...(settings && fields === undefined && layout.sections.length > 0
185
+ ? { title: copy.general }
186
+ : {}), children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), fields !== undefined
184
187
  ? null
185
188
  : layout.sections.map((name) => (_jsx(FormSection, { title: labelOf(meta, name, locale), columns: columns, children: Object.keys(meta?.fields[name]?.definition?.fields ?? {}).map((part) => (_jsx(RecordField, { record: reading, name: `${name}.${part}` }, part))) }, name))), edit.advice
186
189
  .filter((one) => (one.path?.length ?? 0) <= 1)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,7 +44,7 @@
44
44
  "@sincpro/criteria": "^2.2.2",
45
45
  "@sincpro/criteria-react": "^2.1.0",
46
46
  "@sincpro/web-composer": "^1.7.0",
47
- "@sincpro/web-ui": "^2.1.0",
47
+ "@sincpro/web-ui": "^2.5.0",
48
48
  "react": ">=19",
49
49
  "react-dom": ">=19"
50
50
  },
@@ -76,7 +76,7 @@
76
76
  "@sincpro/criteria": "^2.2.2",
77
77
  "@sincpro/criteria-react": "^2.1.0",
78
78
  "@sincpro/web-composer": "^1.8.0",
79
- "@sincpro/web-ui": "^2.4.0",
79
+ "@sincpro/web-ui": "^2.5.0",
80
80
  "@storybook/addon-a11y": "10.6.5",
81
81
  "@storybook/addon-docs": "10.6.5",
82
82
  "@storybook/addon-mcp": "10.6.5",