@sincpro/web-framework 3.6.0 → 3.8.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 (37) hide show
  1. package/README.md +4 -0
  2. package/dist/core/crumbs.d.ts +4 -0
  3. package/dist/core/crumbs.js +24 -0
  4. package/dist/core/files.d.ts +47 -0
  5. package/dist/core/files.js +35 -0
  6. package/dist/core/index.d.ts +1 -0
  7. package/dist/core/index.js +1 -0
  8. package/dist/core/present.d.ts +4 -3
  9. package/dist/core/present.js +9 -4
  10. package/dist/web/files.d.ts +9 -0
  11. package/dist/web/files.js +22 -0
  12. package/dist/web/index.d.ts +6 -3
  13. package/dist/web/index.js +6 -3
  14. package/dist/web/list/EntityList.d.ts +23 -6
  15. package/dist/web/list/EntityList.js +89 -21
  16. package/dist/web/list/columns.d.ts +4 -1
  17. package/dist/web/list/columns.js +31 -17
  18. package/dist/web/list/dock.d.ts +19 -0
  19. package/dist/web/list/dock.js +20 -0
  20. package/dist/web/list/groups.d.ts +7 -1
  21. package/dist/web/list/groups.js +25 -5
  22. package/dist/web/record/ActionButton.d.ts +25 -0
  23. package/dist/web/record/ActionButton.js +39 -18
  24. package/dist/web/record/CommandButton.d.ts +22 -2
  25. package/dist/web/record/CommandButton.js +43 -17
  26. package/dist/web/record/RecordLifecycle.d.ts +28 -7
  27. package/dist/web/record/RecordLifecycle.js +63 -10
  28. package/dist/web/record/ServiceButton.d.ts +20 -2
  29. package/dist/web/record/ServiceButton.js +35 -27
  30. package/dist/web/record/dock.d.ts +31 -0
  31. package/dist/web/record/dock.js +14 -0
  32. package/dist/web/record/edit.js +10 -1
  33. package/dist/web/record/record.d.ts +14 -3
  34. package/dist/web/record/record.js +39 -6
  35. package/dist/web/workspace/record.d.ts +8 -3
  36. package/dist/web/workspace/record.js +20 -16
  37. package/package.json +3 -3
@@ -3,6 +3,7 @@ import type { AnyRecord } from "@sincpro/criteria";
3
3
  import type { Rehearsal } from "../../react/useCommand.js";
4
4
  import { type ActionDialog, type Asked } from "./ActionButton.js";
5
5
  import { type AskField } from "./ask.js";
6
+ import { type ActionLook, type DockedAction } from "./dock.js";
6
7
  /**
7
8
  * One of the application's use cases as a button — its Feature or ApplicationService, run on its
8
9
  * bounded context.
@@ -28,13 +29,13 @@ import { type AskField } from "./ask.js";
28
29
  * <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
29
30
  * run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
30
31
  */
31
- export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, ask, entity, record, dialog, onDone, }: {
32
+ /** What a use case's button and dock action are given. */
33
+ export type ServiceActionProps<R> = {
32
34
  label: string;
33
35
  /** The use case, executed on its bounded context — with what was asked, when it asks. */
34
36
  run: (asked: Asked) => Promise<R>;
35
37
  /** The same use case run dry — what it would do, nothing touched —, asked before `run`. */
36
38
  rehearse?: (asked: Asked) => Promise<Rehearsal>;
37
- role?: "primary" | "secondary" | "ghost";
38
39
  /** Not offered right now. The use case still decides. */
39
40
  disabled?: boolean;
40
41
  /** The fields it asks for before it runs: `["areas"]`. */
@@ -46,4 +47,21 @@ export declare function ServiceButton<R>({ label, run, rehearse, role, disabled,
46
47
  /** What its window says — its title (the label without «…» by default), a sentence under it. */
47
48
  dialog?: ActionDialog;
48
49
  onDone?: (answer: R) => void;
50
+ };
51
+ export declare function ServiceButton<R>({ role, ...props }: ServiceActionProps<R> & {
52
+ role?: "primary" | "secondary" | "ghost";
49
53
  }): import("react").JSX.Element;
54
+ /**
55
+ * One of the application's use cases as an action of a dock — what `ServiceButton` is as a
56
+ * button, for web-ui's `Record.Dock`: the view style draws it (a rail's button, or the modern
57
+ * style's floating pill), and its window — what it asks, what it would do, a refusal — is put
58
+ * on the screen by whoever uses it.
59
+ *
60
+ * const aprobar = useServiceAction({
61
+ * label: "Aprobar", icon: Check, primary: true,
62
+ * run: () => pagosBoundedContext.execute(new CommandAprobarPago(pago.id)),
63
+ * });
64
+ * <Record.Dock actions={[aprobar.action]} />
65
+ * {aprobar.dialog}
66
+ */
67
+ export declare function useServiceAction<R>({ icon, primary, danger, tucked, shortcut, hint, id, ...props }: ServiceActionProps<R> & ActionLook): DockedAction;
@@ -3,38 +3,43 @@ 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";
7
- import { askFormOf } from "./ask.js";
6
+ import { ActionButton, useActionGesture, } from "./ActionButton.js";
7
+ import { askFormOf, } from "./ask.js";
8
+ import { dockedOf, } from "./dock.js";
8
9
  /** What the button runs when there is no dry run: nothing. */
9
10
  const NO_REHEARSAL = async (_asked) => undefined;
10
11
  /** What a use case that asks nothing receives. */
11
12
  const NOTHING_ASKED = {};
13
+ export function ServiceButton({ role = "secondary", ...props }) {
14
+ const { action, form } = useServiceBehind(props);
15
+ return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(props.dialog === undefined ? {} : { dialog: props.dialog }), action: action, label: props.label, role: role, disabled: props.disabled ?? false, ...(props.onDone === undefined ? {} : { onDone: props.onDone }) }));
16
+ }
12
17
  /**
13
- * One of the application's use cases as a button — its Feature or ApplicationService, run on its
14
- * bounded context.
15
- *
16
- * <ServiceButton
17
- * label="Cancelar"
18
- * run={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id))}
19
- * rehearse={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id, true))}
20
- * />
21
- *
22
- * Context: an action of an application is a use case — its logic, its composition, its span
23
- * `<context>/<Service>`, its request carrying the run's trace to the server —, never a request a
24
- * screen sends; what the screen adds is the state of running it (`useService`). The gesture is
25
- * `CommandButton`'s, drawn once by `ActionButton`: run on the click, off while it runs, a refusal
26
- * where it happened; and an action that destroys asks first (`rehearse`, the use case run dry)
27
- * and shows what it would do. What it changed, every screen hears by itself: the use case's
28
- * client announces its write (`processChanges`), so `onDone` is for what only this screen does
29
- * next — a toast, closing a window —, never to read again.
18
+ * One of the application's use cases as an action of a dock — what `ServiceButton` is as a
19
+ * button, for web-ui's `Record.Dock`: the view style draws it (a rail's button, or the modern
20
+ * style's floating pill), and its window — what it asks, what it would do, a refusal — is put
21
+ * on the screen by whoever uses it.
30
22
  *
31
- * A use case that needs input names the fields it asks for (`ask`), read as `entity`'s fields of
32
- * the same name and filled from `record`; `run` and `rehearse` receive what was filled.
33
- *
34
- * <ServiceButton label="Delegar áreas" entity={cuentas} record={cuenta} ask={["areas"]}
35
- * run={(asked) => cuentaBoundedContext.execute(new CommandDelegarAreas(cuenta.id, asked.areas))} />
23
+ * const aprobar = useServiceAction({
24
+ * label: "Aprobar", icon: Check, primary: true,
25
+ * run: () => pagosBoundedContext.execute(new CommandAprobarPago(pago.id)),
26
+ * });
27
+ * <Record.Dock actions={[aprobar.action]} />
28
+ * {aprobar.dialog}
36
29
  */
37
- export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, ask, entity, record, dialog, onDone, }) {
30
+ export function useServiceAction({ icon, primary, danger, tucked, shortcut, hint, id, ...props }) {
31
+ const { action, form } = useServiceBehind(props);
32
+ const gesture = useActionGesture(action, {
33
+ label: props.label,
34
+ ...(form === undefined ? {} : { ask: form }),
35
+ ...(props.dialog === undefined ? {} : { dialog: props.dialog }),
36
+ ...(props.onDone === undefined ? {} : { onDone: props.onDone }),
37
+ });
38
+ const look = { icon, primary, danger, tucked, shortcut, hint, id };
39
+ return dockedOf(gesture, props.label, look, props.disabled);
40
+ }
41
+ /** What runs behind a use case's button or dock action: the run, its dry run, what it asks. */
42
+ function useServiceBehind({ run, rehearse, ask, entity, record }) {
38
43
  const running = useService((asked) => run(asked ?? NOTHING_ASKED));
39
44
  const rehearsing = useService((asked) => (rehearse ?? NO_REHEARSAL)(asked ?? NOTHING_ASKED));
40
45
  // Outside a provider it still runs: the asked fields are then drawn by what `ask` says.
@@ -51,7 +56,8 @@ export function ServiceButton({ label, run, rehearse, role = "secondary", disabl
51
56
  entityFor: (target) => entityFor(framework.entities, target, framework.metas.get),
52
57
  }),
53
58
  });
54
- return (_jsx(ActionButton, { ...(form === undefined ? {} : { ask: form }), ...(dialog === undefined ? {} : { dialog }), action: {
59
+ return {
60
+ action: {
55
61
  run: running.run,
56
62
  ...(rehearse === undefined ? {} : { rehearse: rehearsing.run }),
57
63
  busy: running.busy || rehearsing.busy,
@@ -61,5 +67,7 @@ export function ServiceButton({ label, run, rehearse, role = "secondary", disabl
61
67
  running.reset();
62
68
  rehearsing.reset();
63
69
  },
64
- }, label: label, role: role, disabled: disabled, ...(onDone === undefined ? {} : { onDone }) }));
70
+ },
71
+ form,
72
+ };
65
73
  }
@@ -0,0 +1,31 @@
1
+ import type { ActionGesture } from "./ActionButton.js";
2
+ import type { DockAction } from "@sincpro/web-ui";
3
+ import type { ReactNode } from "react";
4
+ /**
5
+ * An action for a dock — web-ui's `Record.Dock` and `List.Dock`, which the application's view
6
+ * style draws: the rail's buttons in `traditional`, one pill floating at the bottom in `modern`
7
+ * — and the window its gesture opens (what it asks, what it would do, a refusal).
8
+ *
9
+ * const aprobar = useServiceAction({ label: "Aprobar", primary: true, run: aprobarPago });
10
+ * <Record.Rail>
11
+ * <Record.Dock actions={[aprobar.action]} />
12
+ * </Record.Rail>
13
+ * {aprobar.dialog}
14
+ */
15
+ export type DockedAction = {
16
+ action: DockAction;
17
+ /** Put it anywhere on the screen — it opens over everything —; `null` while closed. */
18
+ dialog: ReactNode;
19
+ };
20
+ /** How an action is drawn in a dock — everything but its words and what it does. Its `id`
21
+ * defaults to its label. */
22
+ export type ActionLook = Pick<DockAction, "icon" | "primary" | "danger" | "tucked" | "shortcut" | "hint"> & {
23
+ id?: string;
24
+ };
25
+ /** A look as a hook receives it: a field the screen left out is `undefined`. */
26
+ type LookGiven = {
27
+ [K in keyof ActionLook]?: ActionLook[K] | undefined;
28
+ };
29
+ /** The dock's action started by a gesture: off while it runs. */
30
+ export declare function dockedOf(gesture: ActionGesture, label: string, look: LookGiven, disabled?: boolean): DockedAction;
31
+ export {};
@@ -0,0 +1,14 @@
1
+ /** The dock's action started by a gesture: off while it runs. */
2
+ export function dockedOf(gesture, label, look, disabled = false) {
3
+ const { id, ...drawn } = Object.fromEntries(Object.entries(look).filter(([, value]) => value !== undefined));
4
+ return {
5
+ action: {
6
+ ...drawn,
7
+ id: id ?? label,
8
+ label,
9
+ disabled: disabled || gesture.busy,
10
+ onSelect: gesture.start,
11
+ },
12
+ dialog: gesture.dialog,
13
+ };
14
+ }
@@ -4,17 +4,19 @@ import {} from "@sincpro/client-framework";
4
4
  import { choicesOf } from "@sincpro/criteria";
5
5
  import { frameworkCopy } from "../../core/copy.js";
6
6
  import { errorAt } from "../../core/edit.js";
7
+ import { holdsFile } from "../../core/files.js";
7
8
  import { editableLines } from "../../core/lines.js";
8
9
  import { fieldAt, fieldMetaOf, isMoneyDefinition, textOf, valueAt, viewOf, } from "../../core/present.js";
9
10
  import { relationFieldOf } from "../../core/relation.js";
10
11
  import { useEntityFor, useFramework } from "../../react/context.js";
11
12
  import { useNameOf } from "../../react/useNameOf.js";
13
+ import { attachmentOf } from "../files.js";
12
14
  import { controlFor, RelationPicker, } from "./control.js";
13
15
  import { RecordLinesEditor } from "./lines.js";
14
16
  import { useRecordOpening } from "./opening.js";
15
17
  import { RecordLines } from "./record.js";
16
18
  import { RelatedList } from "./RelatedList.js";
17
- import { Checkbox, Field, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
19
+ import { Checkbox, Field, FileValue, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
18
20
  /** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
19
21
  function setAt(value, path, next) {
20
22
  const base = typeof value === "object" && value !== null ? value : {};
@@ -100,6 +102,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
100
102
  own.many !== true &&
101
103
  own.definition &&
102
104
  own.widget !== "money" &&
105
+ !holdsFile(own) &&
103
106
  !isMoneyDefinition(own.definition)) {
104
107
  // One value the record embeds: its fields, each by its label — a section of the record.
105
108
  const block = parts.map((one) => (_jsx(RecordField, { record: record, name: `${name}.${one}` }, one)));
@@ -153,6 +156,12 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
153
156
  label: view.label,
154
157
  };
155
158
  const field = fieldMetaOf(meta, name);
159
+ if (as === undefined && holdsFile(field)) {
160
+ // A file is ONE value — its picture or its kind, the name it was sent with, its type and
161
+ // size —, never a section of its parts. Sending another is the upload's, not this field's.
162
+ const file = attachmentOf(value);
163
+ return (_jsx(Field, { label: view.label, ...(view.help === undefined ? {} : { hint: view.help }), children: file === null ? _jsx(ReadValue, { value: "\u2014" }) : _jsx(FileValue, { file: file, size: "md" }) }));
164
+ }
156
165
  /** A many2one of a declared entity: chosen by the server's literal search, opened where the
157
166
  * view says. Written by its key; read by the record it points at. */
158
167
  function manyToOne() {
@@ -1,8 +1,8 @@
1
1
  import type { Entity } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Meta } from "@sincpro/criteria";
3
3
  import { type ChoiceTones, type PartLook } from "../list/presentation.js";
4
- import { type RowAction, type SheetField } from "@sincpro/web-ui";
5
- import type { ReactNode } from "react";
4
+ import { type DockAction, type RowAction, type SheetField } from "@sincpro/web-ui";
5
+ import { type ReactNode } from "react";
6
6
  export declare function factsOf<T extends AnyRecord>(record: T, meta: Meta | null | undefined, names: readonly string[], options?: {
7
7
  locale?: string | undefined;
8
8
  cells?: Readonly<Partial<Record<string, (record: T) => ReactNode>>>;
@@ -40,8 +40,16 @@ export declare function usePartLook<T extends AnyRecord>(meta: Meta | null | und
40
40
  * <RecordLines record={project} meta={meta} name="shares"
41
41
  * rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
42
42
  * onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
43
+ *
44
+ * `selectionActions` acts on SEVERAL: the parts get ticks, and what is done to the chosen ones
45
+ * is web-ui's dock — in the collection's line in the traditional style, floating in the modern
46
+ * one, where it takes the record's place while parts are chosen. It is handed the chosen parts
47
+ * and a way to clear the choice once done.
48
+ *
49
+ * selectionActions={(chosen, clear) => [{ id: "unshare", label: `Quitar ${chosen.length}`,
50
+ * icon: X, onSelect: () => { void unshareAll(chosen); clear(); } }]}
43
51
  */
44
- export declare function RecordLines<T extends AnyRecord>({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }: {
52
+ export declare function RecordLines<T extends AnyRecord>({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, selectionActions, }: {
45
53
  record: AnyRecord;
46
54
  meta: Meta | null | undefined;
47
55
  name: string;
@@ -56,4 +64,7 @@ export declare function RecordLines<T extends AnyRecord>({ record, meta, name, e
56
64
  onOpen?: (row: T) => void;
57
65
  /** What a row's part can be acted on with — a Command of the record. */
58
66
  rowActions?: (row: T) => readonly RowAction[];
67
+ /** What is done to several parts at once; giving it makes the parts choosable. Handed the
68
+ * chosen parts, and `clear` to drop the choice once done. */
69
+ selectionActions?: (chosen: readonly T[], clear: () => void) => readonly DockAction[];
59
70
  }): import("react").JSX.Element;
@@ -11,6 +11,7 @@ import { columnsOf } from "../list/columns.js";
11
11
  import { partLookOf, presentationOf, tonesOver, } from "../list/presentation.js";
12
12
  import { useRecordOpening } from "./opening.js";
13
13
  import { List, RelationValue, } from "@sincpro/web-ui";
14
+ import { useState } from "react";
14
15
  /**
15
16
  * The parts of ONE record, from the model.
16
17
  *
@@ -119,16 +120,48 @@ export function usePartLook(meta, name, own) {
119
120
  * <RecordLines record={project} meta={meta} name="shares"
120
121
  * rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
121
122
  * onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
123
+ *
124
+ * `selectionActions` acts on SEVERAL: the parts get ticks, and what is done to the chosen ones
125
+ * is web-ui's dock — in the collection's line in the traditional style, floating in the modern
126
+ * one, where it takes the record's place while parts are chosen. It is handed the chosen parts
127
+ * and a way to clear the choice once done.
128
+ *
129
+ * selectionActions={(chosen, clear) => [{ id: "unshare", label: `Quitar ${chosen.length}`,
130
+ * icon: X, onSelect: () => { void unshareAll(chosen); clear(); } }]}
122
131
  */
123
- export function RecordLines({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, }) {
132
+ export function RecordLines({ record, meta, name, entity, columns, cells, tones, locale, onOpen, rowActions, selectionActions, }) {
124
133
  const look = usePartLook(meta, name, { entity, columns, tones });
125
134
  const related = relatedOf(record[name]);
126
135
  const definition = meta?.fields[name]?.definition ?? describeRows(related.items);
127
136
  const identity = definition.identity || "id";
128
137
  const copy = frameworkCopy();
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] }));
138
+ const keyOf = (row) => String(row[identity]);
139
+ // The choice is the screen's moment, not the record's: held here, by key, and dropped of the
140
+ // keys no longer among the parts (a part the Command removed is not chosen any more).
141
+ const [picked, setPicked] = useState(() => new Set());
142
+ const present = new Set(related.items.map(keyOf));
143
+ const chosenKeys = [...picked].filter((key) => present.has(key));
144
+ const clear = () => setPicked(new Set());
145
+ const chosen = related.items.filter((row) => picked.has(keyOf(row)));
146
+ return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs(List, { embedded: true, items: related.items, keyOf: keyOf, present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), ...(selectionActions === undefined
147
+ ? {}
148
+ : {
149
+ selection: {
150
+ has: (key) => picked.has(key),
151
+ toggle: (key) => setPicked((now) => {
152
+ const next = new Set(now);
153
+ if (next.has(key))
154
+ next.delete(key);
155
+ else
156
+ next.add(key);
157
+ return next;
158
+ }),
159
+ count: chosenKeys.length,
160
+ clear,
161
+ },
162
+ }), children: [selectionActions === undefined || chosen.length === 0 ? null : (_jsx(List.Bar, { children: _jsx(List.Dock, { selection: selectionActions(chosen, clear) }) })), _jsx(List.Table, { columns: columnsOf(definition, look.columns, {
163
+ locale,
164
+ ...(cells ? { cells } : {}),
165
+ ...(look.tones === undefined ? {} : { tones: look.tones }),
166
+ }), ...(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] }));
134
167
  }
@@ -2,7 +2,7 @@ import { type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type ViewProps } from "@sincpro/web-composer";
4
4
  import { type RecordReading } from "../../react/useRecord.js";
5
- import { type ReactNode } from "react";
5
+ import { type ScreenActions } from "../list/dock.js";
6
6
  /** Who made a record, or changed it last, and when: `Record.Audit`'s. */
7
7
  export type Stamp = {
8
8
  at: string;
@@ -81,6 +81,11 @@ export declare function EntityRecord<T extends AnyRecord>({ api, resource, entit
81
81
  fields?: readonly string[];
82
82
  /** The one2many shown as pages, in this order. Without it, every one the model has. */
83
83
  pages?: readonly string[];
84
- /** The record's own commands, beside «save / discard». */
85
- actions?: (record: RecordReading<T>) => ReactNode;
84
+ /**
85
+ * The record's own actions, beside «save / discard» and its lifecycle («Eliminar»). As data
86
+ * (`DockAction`s) the application's view style draws them with the lifecycle's: the rail's
87
+ * buttons in `traditional`, one pill floating at the bottom in `modern` (web-ui's
88
+ * `Record.Dock`). A node drawn by hand stays in the rail.
89
+ */
90
+ actions?: (record: RecordReading<T>) => ScreenActions;
86
91
  }): import("react").JSX.Element;
@@ -12,9 +12,10 @@ import { useFramework } from "../../react/context.js";
12
12
  import { useHistory } from "../../react/useHistory.js";
13
13
  import { useRecord } from "../../react/useRecord.js";
14
14
  import { useSummaryOf } from "../../react/useSummary.js";
15
+ import { actionsOf } from "../list/dock.js";
15
16
  import { presentationOf } from "../list/presentation.js";
16
17
  import { dirtyOf, RecordField } from "../record/edit.js";
17
- import { RecordLifecycle } from "../record/RecordLifecycle.js";
18
+ import { LifecycleButtons, useRecordLifecycleActions, } from "../record/RecordLifecycle.js";
18
19
  import { Refused } from "../Refused.js";
19
20
  import { useRecordInWorkspace } from "./workspace.js";
20
21
  import { Button, Callout, FormSection, Record, Skeleton, useFormStyle, } from "@sincpro/web-ui";
@@ -159,6 +160,9 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
159
160
  // squeezed a text area beside its word (web-ui's grid does not narrow by itself).
160
161
  const phone = usePhone(api);
161
162
  const settings = useFormStyle() === "settings";
163
+ // The record's own lifecycle (its `Delete`, its trash); once it is out of every reading the
164
+ // surface closes — every list that showed it reads again by itself.
165
+ const lifecycle = useRecordLifecycleActions(reading, (done) => done === "restore" ? reading.reload() : api.close());
162
166
  if (reading.status === "loading")
163
167
  return _jsx(Skeleton, { rows: 6, label: copy.loading });
164
168
  if (reading.status === "failed")
@@ -172,20 +176,20 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
172
176
  const shown = fields ??
173
177
  layout.fields.filter((name) => reading.isNew || !said.has(name) || !edit.state(name).readonly);
174
178
  const columns = phone || (api.surface !== "page" && api.surface !== "modal") ? 1 : 2;
175
- // The record's own lifecycle (its `Delete`, its trash) beside the screen's commands; once it is
176
- // out of every reading the surface closes — every list that showed it reads again by itself.
177
- const lifecycle = reading.isNew ||
178
- (entity.delete === undefined &&
179
- entity.archive === undefined &&
180
- entity.restore === undefined) ? null : (_jsx(RecordLifecycle, { record: reading, onDone: (done) => (done === "restore" ? reading.reload() : api.close()) }));
181
- const own = actions?.(reading) ?? null;
182
- const ownActions = own === null && lifecycle === null ? null : (_jsxs(_Fragment, { children: [own, lifecycle] }));
179
+ // The screen's actions and the lifecycle's. As data they go to the dock, where the view style
180
+ // draws them; drawn by hand, in the rail with the lifecycle's buttons beside them.
181
+ const own = actionsOf(actions?.(reading) ?? null);
182
+ const docked = own.drawn === null ? [...own.dock, ...lifecycle.actions] : [];
183
+ const drawn = own.drawn === null ? null : (_jsxs(_Fragment, { children: [own.drawn, _jsx(LifecycleButtons, { actions: lifecycle.actions })] }));
183
184
  const tabs = pages ?? layout.pages;
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
187
- ? null
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
189
- .filter((one) => (one.path?.length ?? 0) <= 1)
190
- .map((one) => (_jsx(Callout, { tone: "info", title: one.message, children: null }, one.message))), tabs.length === 0 || reading.isNew ? null : (_jsx(Record.Pages, { current: page ?? tabs[0], onChange: setPage, children: tabs.map((name) => (_jsx(Record.Page, { id: name, label: labelOf(meta, name, locale), children: _jsx(RecordField, { record: reading, name: name, bare: true }) }, name))) })), screen.audit === undefined ? null : _jsx(Record.Audit, { ...screen.audit })] }), history === undefined ? null : _jsx(Record.Activity, { events: history })] }));
185
+ return (_jsxs(_Fragment, { children: [_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 &&
186
+ pager === undefined &&
187
+ docked.length === 0 &&
188
+ drawn === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), drawn === null ? null : _jsx(Record.Actions, { children: drawn }), docked.length === 0 ? null : _jsx(Record.Dock, { actions: docked })] })), _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
189
+ ? { title: copy.general }
190
+ : {}), children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), fields !== undefined
191
+ ? null
192
+ : 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
193
+ .filter((one) => (one.path?.length ?? 0) <= 1)
194
+ .map((one) => (_jsx(Callout, { tone: "info", title: one.message, children: null }, one.message))), tabs.length === 0 || reading.isNew ? null : (_jsx(Record.Pages, { current: page ?? tabs[0], onChange: setPage, children: tabs.map((name) => (_jsx(Record.Page, { id: name, label: labelOf(meta, name, locale), children: _jsx(RecordField, { record: reading, name: name, bare: true }) }, name))) })), screen.audit === undefined ? null : _jsx(Record.Audit, { ...screen.audit })] }), history === undefined ? null : _jsx(Record.Activity, { events: history })] }), lifecycle.dialog] }));
191
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.6.0",
3
+ "version": "3.8.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.4.0",
45
45
  "@sincpro/criteria-react": "^2.4.0",
46
46
  "@sincpro/web-composer": "^1.7.0",
47
- "@sincpro/web-ui": "^2.8.0",
47
+ "@sincpro/web-ui": "^2.11.0",
48
48
  "react": ">=19",
49
49
  "react-dom": ">=19"
50
50
  },
@@ -76,7 +76,7 @@
76
76
  "@sincpro/criteria": "^2.4.0",
77
77
  "@sincpro/criteria-react": "^2.4.0",
78
78
  "@sincpro/web-composer": "^1.8.0",
79
- "@sincpro/web-ui": "^2.8.0",
79
+ "@sincpro/web-ui": "^2.11.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",