@sincpro/web-framework 3.21.0 → 3.22.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.
@@ -122,6 +122,10 @@ export type FrameworkCopy = {
122
122
  /** More were chosen than a Command runs on at once. */
123
123
  tooMany: (size: number | null, limit: number) => string;
124
124
  };
125
+ board: {
126
+ /** The name of a board's period row: what every tile reads over. */
127
+ period: string;
128
+ };
125
129
  failure: {
126
130
  /** The server could not be reached at all — nothing it said is known. */
127
131
  unreachable: string;
package/dist/core/copy.js CHANGED
@@ -88,6 +88,7 @@ export const ENGLISH_FRAMEWORK_COPY = {
88
88
  stop: "Stop",
89
89
  tooMany: (size, limit) => `${size === null ? "More than " + limit : size} records are chosen; at most ${limit} at once. Narrow the search.`,
90
90
  },
91
+ board: { period: "Period" },
91
92
  failure: {
92
93
  unreachable: "The server could not be reached",
93
94
  unexpected: "The server answered something else",
@@ -197,6 +198,7 @@ export const SPANISH_FRAMEWORK_COPY = {
197
198
  stop: "Detener",
198
199
  tooMany: (size, limit) => `${size === null ? "Son más de " + limit : "Son " + size} registros elegidos; a la vez, como mucho ${limit}. Acotá la búsqueda.`,
199
200
  },
201
+ board: { period: "Período" },
200
202
  failure: {
201
203
  unreachable: "No se pudo hablar con el servidor",
202
204
  unexpected: "El servidor contestó otra cosa",
@@ -69,6 +69,8 @@ export function useRecord(entity, opened, options = {}) {
69
69
  const [advice, setAdvice] = useState([]);
70
70
  const [saving, setSaving] = useState(false);
71
71
  const [failure, setFailure] = useState(null);
72
+ // The fields written since the last refusal: what the server said of them no longer holds.
73
+ const [rewritten, setRewritten] = useState(() => new Set());
72
74
  const [conflict, setConflict] = useState(false);
73
75
  const [draft, setDraft] = useState(served?.draft ?? null);
74
76
  const pause = useRef(null);
@@ -270,8 +272,10 @@ export function useRecord(entity, opened, options = {}) {
270
272
  const refused = (error) => {
271
273
  if (error instanceof TransportError && error.problem?.kind === "conflict")
272
274
  setConflict(true);
273
- else
275
+ else {
274
276
  setFailure(error);
277
+ setRewritten(new Set());
278
+ }
275
279
  };
276
280
  // sincpro_framework's `Edit`: what the form writes; the fields changed; the draft version read
277
281
  // (`0`: none) — another tab that kept first wins —, and the stored version the edit started
@@ -299,6 +303,8 @@ export function useRecord(entity, opened, options = {}) {
299
303
  const next = { ...typedNow.current, [name]: value };
300
304
  typedNow.current = next;
301
305
  setTyped(next);
306
+ if (failure !== null && !rewritten.has(name))
307
+ setRewritten((before) => new Set(before).add(name));
302
308
  ask(next, name);
303
309
  },
304
310
  writable,
@@ -312,7 +318,11 @@ export function useRecord(entity, opened, options = {}) {
312
318
  const said = fieldStateOf(definition, field, line ?? {}, lineStatesOf(fromServer, name, line, index, definition?.identity || "id"));
313
319
  return writable ? said : { ...said, readonly: true, required: false };
314
320
  },
315
- errors: failure instanceof TransportError ? errorsByField(failure.problem?.errors) : {},
321
+ // A refusal's word on a field holds until the field is written again: corrected, it is
322
+ // the next save's to judge — a flow would otherwise stay blocked by what no longer holds.
323
+ errors: failure instanceof TransportError
324
+ ? Object.fromEntries(Object.entries(errorsByField(failure.problem?.errors)).filter(([at]) => !rewritten.has(at.split("/")[0] ?? at)))
325
+ : {},
316
326
  advice,
317
327
  missing: missingOf(state.meta, values, fromServer),
318
328
  saving,
@@ -0,0 +1,112 @@
1
+ /**
2
+ * A dashboard: ONE period chosen above everything, and every tile reading its own entity over it
3
+ * — figures, charts —, each saying in its own place whether it is reading, ready or refused.
4
+ *
5
+ * <Dashboard title="Ventas y cobros" periods={PERIODS}
6
+ * stats={<>
7
+ * <Dashboard.Count entity={invoices} over="invoice_date" label="Facturas emitidas" />
8
+ * <Dashboard.Count entity={payments} over="sent_on" label="Pagos recibidos" />
9
+ * </>}>
10
+ * <Dashboard.Chart entity={invoices} over="invoice_date" title="Facturas por mes"
11
+ * rows={{ field: "invoice_date", grain: "month" }} columns={{ field: "state" }} />
12
+ * </Dashboard>
13
+ *
14
+ * Context: web-ui's `Board` draws the tiles and folds nothing; what it asks of the application —
15
+ * one filter row that scopes EVERY tile, one state per tile — is what every board wrote by hand,
16
+ * N readings that each built its own cut and mapped its own status (#30). Here the root holds the
17
+ * period and gives it to its parts by context; a tile names the field the period cuts on (`over`,
18
+ * each entity has its own date), and its reading ANDs that cut under its own criteria. A tile
19
+ * that names no `over` is not cut — said in code, never by accident. What a tile reads is counted
20
+ * and summed by the SERVER (`useListing`'s count, `usePivot`): never a page folded here.
21
+ *
22
+ * Three levels, as every root here: the root and its parts; the hooks (`useBoardListing`,
23
+ * `useBoardPeriod`, `boardStateOf`) for a tile of the application's own — a table, a list, a
24
+ * map — inside the same board; and web-ui's `Board` below them, for a board with no period.
25
+ */
26
+ import type { CommandBodies, Entity } from "@sincpro/client-framework";
27
+ import { type AnyRecord, type Criteria, type Expression, type Period } from "@sincpro/criteria";
28
+ import type { GroupLevel } from "../../core/list.js";
29
+ import { type Listing } from "../../react/useListing.js";
30
+ import { type BoardState, type ChartKind, type Tone } from "@sincpro/web-ui";
31
+ import type { LucideIcon } from "lucide-react";
32
+ import { type ReactNode } from "react";
33
+ /**
34
+ * A span a board may be read over: a period the server names (`dynamic.period("this_month")`,
35
+ * read on ITS calendar and zone) or two days, both included.
36
+ */
37
+ export type BoardPeriod = {
38
+ id: string;
39
+ label: string;
40
+ range: Period | readonly [string, string];
41
+ };
42
+ /** The period of the board around, or none outside a board. */
43
+ export declare function useBoardPeriod(): BoardPeriod | null;
44
+ /** The cut a period makes on a field: `field between range`. */
45
+ export declare function periodCut<T extends AnyRecord>(period: BoardPeriod, over: string): Expression<T>;
46
+ export type BoardReadingOptions<T> = {
47
+ /** The date the board's period cuts this reading on. Without it, the period does not. */
48
+ over?: string;
49
+ /** What this tile always asks: the period ANDs under it. */
50
+ criteria?: Criteria<T>;
51
+ };
52
+ /**
53
+ * A listing of `entity` as a board tile reads it: one row a page (the count and the question are
54
+ * what a tile wants), cut by the board's period over `over`.
55
+ */
56
+ export declare function useBoardListing<T extends AnyRecord, C extends CommandBodies = CommandBodies>(entity: Entity<T, C>, { over, criteria }?: BoardReadingOptions<T>): Listing<T, C>;
57
+ /**
58
+ * web-ui's state of a tile from a reading: reading while it asks, the refusal in the server's
59
+ * words when it failed — with «Reintentar» when there is a way to ask again.
60
+ */
61
+ export declare function boardStateOf(reading: {
62
+ status: string;
63
+ error: unknown;
64
+ }, retry?: () => void): BoardState;
65
+ export type DashboardProps = {
66
+ title: string;
67
+ description?: ReactNode;
68
+ /** The spans offered, in order; the first is read unless `defaultPeriod` says otherwise. */
69
+ periods?: readonly BoardPeriod[];
70
+ /** The period read first, by id, when the board holds it. */
71
+ defaultPeriod?: string;
72
+ /** The period on screen, by id, when the screen holds it (a window's `params`). */
73
+ period?: string;
74
+ onPeriodChange?: (id: string) => void;
75
+ /** The headline figures: `Dashboard.Count`s, read before the tiles. */
76
+ stats?: ReactNode;
77
+ /** The tiles: `Dashboard.Chart`, or a web-ui `BoardTile` the screen reads itself. */
78
+ children: ReactNode;
79
+ };
80
+ /** The root: the period row above every tile, and the period given to each. */
81
+ export declare function Dashboard({ title, description, periods, defaultPeriod, period: controlled, onPeriodChange, stats, children, }: DashboardProps): import("react").JSX.Element;
82
+ export declare namespace Dashboard {
83
+ var Count: <T extends AnyRecord>({ entity, over, criteria, label, icon, hint, hero, tone, }: BoardReadingOptions<T> & TileLook & {
84
+ entity: Entity<T>;
85
+ label: string;
86
+ /** The one figure the board leads with. */
87
+ hero?: boolean;
88
+ /** The state the figure means — say why in `hint`. */
89
+ tone?: Tone;
90
+ }) => import("react").JSX.Element;
91
+ var Chart: typeof ChartTile;
92
+ }
93
+ type TileLook = {
94
+ icon?: LucideIcon;
95
+ hint?: ReactNode;
96
+ };
97
+ /**
98
+ * A tile that crosses `entity` by two fields — the rows below, the columns as series — counted,
99
+ * or added up by `measure`, by the server over the board's period.
100
+ */
101
+ declare function ChartTile<T extends AnyRecord>({ entity, over, criteria, title, icon, hint, description, rows, columns, measure, kind, span, }: BoardReadingOptions<T> & TileLook & {
102
+ entity: Entity<T>;
103
+ title: string;
104
+ description?: ReactNode;
105
+ rows: GroupLevel;
106
+ columns: GroupLevel;
107
+ /** The field added up in each crossing; the count without it. */
108
+ measure?: string;
109
+ kind?: ChartKind;
110
+ span?: 1 | 2 | "full";
111
+ }): import("react").JSX.Element;
112
+ export {};
@@ -0,0 +1,106 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { merge, } from "@sincpro/criteria";
4
+ import { frameworkCopy } from "../../core/copy.js";
5
+ import { explain } from "../../core/explain.js";
6
+ import { useFramework } from "../../react/context.js";
7
+ import { useListing } from "../../react/useListing.js";
8
+ import { usePivot } from "../../react/usePivot.js";
9
+ import { pivotOf } from "../list/pivot.js";
10
+ import { Board, BoardStat, BoardStats, BoardTile, Chart, chartFromPivot, COUNT_MEASURE, SegmentedControl, } from "@sincpro/web-ui";
11
+ import { createContext, useContext, useMemo, useState } from "react";
12
+ const Scope = createContext(null);
13
+ /** The period of the board around, or none outside a board. */
14
+ export function useBoardPeriod() {
15
+ return useContext(Scope);
16
+ }
17
+ /** The cut a period makes on a field: `field between range`. */
18
+ export function periodCut(period, over) {
19
+ return { field: over, operator: "between", value: period.range };
20
+ }
21
+ /**
22
+ * A listing of `entity` as a board tile reads it: one row a page (the count and the question are
23
+ * what a tile wants), cut by the board's period over `over`.
24
+ */
25
+ export function useBoardListing(entity, { over, criteria } = {}) {
26
+ const period = useBoardPeriod();
27
+ const cut = period === null || over === undefined
28
+ ? undefined
29
+ : { selection: periodCut(period, over) };
30
+ const asked = cut === undefined ? criteria : criteria === undefined ? cut : merge(criteria, cut);
31
+ return useListing(entity, {
32
+ pageSize: 1,
33
+ ...(asked === undefined ? {} : { criteria: asked }),
34
+ });
35
+ }
36
+ /**
37
+ * web-ui's state of a tile from a reading: reading while it asks, the refusal in the server's
38
+ * words when it failed — with «Reintentar» when there is a way to ask again.
39
+ */
40
+ export function boardStateOf(reading, retry) {
41
+ if (reading.status === "failed") {
42
+ const said = explain(reading.error);
43
+ return {
44
+ status: "failed",
45
+ sentence: said.sentence || said.heading,
46
+ ...(retry === undefined ? {} : { onRetry: retry }),
47
+ };
48
+ }
49
+ return reading.status === "ready" ? { status: "ready" } : { status: "loading" };
50
+ }
51
+ /** The root: the period row above every tile, and the period given to each. */
52
+ export function Dashboard({ title, description, periods = [], defaultPeriod, period: controlled, onPeriodChange, stats, children, }) {
53
+ const [own, setOwn] = useState(defaultPeriod ?? periods[0]?.id);
54
+ const id = controlled ?? own;
55
+ const period = useMemo(() => periods.find((one) => one.id === id) ?? periods[0] ?? null, [periods, id]);
56
+ const choose = (next) => {
57
+ if (controlled === undefined)
58
+ setOwn(next);
59
+ onPeriodChange?.(next);
60
+ };
61
+ return (_jsx(Scope.Provider, { value: period, children: _jsx(Board, { title: title, ...(description === undefined ? {} : { description }), ...(periods.length < 2 || period === null
62
+ ? {}
63
+ : {
64
+ filters: (_jsx(SegmentedControl, { "aria-label": frameworkCopy().board.period, size: "sm", value: period.id, onChange: choose, options: periods.map((one) => ({ value: one.id, label: one.label })) })),
65
+ }), ...(stats === undefined ? {} : { metrics: _jsx(BoardStats, { children: stats }) }), children: children }) }));
66
+ }
67
+ /** A headline figure: how many records of `entity` the period holds, counted by the server. */
68
+ function Count({ entity, over, criteria, label, icon, hint, hero, tone, }) {
69
+ const listing = useBoardListing(entity, {
70
+ ...(over === undefined ? {} : { over }),
71
+ ...(criteria === undefined ? {} : { criteria }),
72
+ });
73
+ const state = boardStateOf(listing, listing.reload);
74
+ return (_jsx(BoardStat, { label: label, state: state, ...(listing.count === null ? {} : { value: listing.count.value }), ...(icon === undefined ? {} : { icon }), ...(hint === undefined ? {} : { hint }), ...(hero === undefined ? {} : { hero }), ...(tone === undefined ? {} : { tone }) }));
75
+ }
76
+ /**
77
+ * A tile that crosses `entity` by two fields — the rows below, the columns as series — counted,
78
+ * or added up by `measure`, by the server over the board's period.
79
+ */
80
+ function ChartTile({ entity, over, criteria, title, icon, hint, description, rows, columns, measure, kind, span, }) {
81
+ const { locale } = useFramework();
82
+ const listing = useBoardListing(entity, {
83
+ ...(over === undefined ? {} : { over }),
84
+ ...(criteria === undefined ? {} : { criteria }),
85
+ });
86
+ const measures = measure === undefined ? [] : [measure];
87
+ const pivot = usePivot(listing, { rows, columns, measures });
88
+ // The listing refused is the tile refused: the crossing never asks then.
89
+ const state = listing.status === "failed"
90
+ ? boardStateOf(listing, listing.reload)
91
+ : boardStateOf(pivot.status === "idle" ? { ...pivot, status: "loading" } : pivot);
92
+ const data = pivot.status !== "ready"
93
+ ? null
94
+ : chartFromPivot(pivotOf({
95
+ crossed: pivot.crossed,
96
+ byColumn: pivot.columns,
97
+ rows,
98
+ columns,
99
+ measures: pivot.measures,
100
+ meta: listing.meta,
101
+ locale,
102
+ }), { measure: measure ?? COUNT_MEASURE });
103
+ return (_jsx(BoardTile, { title: title, state: state, ...(icon === undefined ? {} : { icon }), ...(hint === undefined ? {} : { hint }), ...(description === undefined ? {} : { description }), ...(span === undefined ? {} : { span }), children: data === null ? null : (_jsx(Chart, { data: data, label: title, ...(kind === undefined ? {} : { kind }) })) }));
104
+ }
105
+ Dashboard.Count = Count;
106
+ Dashboard.Chart = ChartTile;
@@ -0,0 +1 @@
1
+ export { type BoardPeriod, type BoardReadingOptions, boardStateOf, Dashboard, type DashboardProps, periodCut, useBoardListing, useBoardPeriod, } from "./Dashboard.js";
@@ -0,0 +1 @@
1
+ export { boardStateOf, Dashboard, periodCut, useBoardListing, useBoardPeriod, } from "./Dashboard.js";
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * The web bindings: what draws a `Listing` and a record with `@sincpro/web-ui`.
3
3
  */
4
+ export * from "./board/index.js";
4
5
  export { attachmentOf } from "./files.js";
5
6
  export { BatchProgress } from "./list/BatchProgress.js";
6
7
  export { aggregateOf, type ColumnOptions, columnsOf, } from "./list/columns.js";
@@ -35,6 +36,7 @@ export { RelatedList } from "./record/RelatedList.js";
35
36
  export { RichTextControl, richTextControl, RichTextFact, } from "./record/richText.js";
36
37
  export { type ServiceActionProps, ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
37
38
  export { cardOf, relationOf } from "./record/summary.js";
39
+ export { useWizardRecord, Wizard, type WizardProps, type WizardStepProps, } from "./record/Wizard.js";
38
40
  export { Refused } from "./Refused.js";
39
41
  export { RouteError, type RouteErrorProps } from "./RouteError.js";
40
42
  export { entityView, type EntityViewOptions, listView, type ListViewOptions, } from "./workspace/composer.js";
package/dist/web/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * The web bindings: what draws a `Listing` and a record with `@sincpro/web-ui`.
3
3
  */
4
+ export * from "./board/index.js";
4
5
  export { attachmentOf } from "./files.js";
5
6
  export { BatchProgress } from "./list/BatchProgress.js";
6
7
  export { aggregateOf, columnsOf, } from "./list/columns.js";
@@ -35,6 +36,7 @@ export { RelatedList } from "./record/RelatedList.js";
35
36
  export { RichTextControl, richTextControl, RichTextFact, } from "./record/richText.js";
36
37
  export { ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
37
38
  export { cardOf, relationOf } from "./record/summary.js";
39
+ export { useWizardRecord, Wizard, } from "./record/Wizard.js";
38
40
  export { Refused } from "./Refused.js";
39
41
  export { RouteError } from "./RouteError.js";
40
42
  export { entityView, listView, } from "./workspace/composer.js";
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A wizard: ONE record filled in steps. Each step names its fields; «Next» stays off while one of
3
+ * them lacks something — the reason beside it, in the model's words —; the last step names what
4
+ * finishing does, and finishing saves the record. What the server refuses then takes the person
5
+ * back to the step that holds the field, its message on it.
6
+ *
7
+ * <Wizard entity={invoices} resource={invoices.newRef()} onDone={(invoice) => …}>
8
+ * <Wizard.Step id="customer" title="Cliente" fields={["customer_id", "invoice_date"]} />
9
+ * <Wizard.Step id="payment" title="Cobro" fields={["payment"]} nextLabel="Registrar factura">
10
+ * <Summary />
11
+ * </Wizard.Step>
12
+ * </Wizard>
13
+ *
14
+ * Context: a flow over one entity is that entity's record, not a state of its own — the draft,
15
+ * the preview, the rules and the refusals are `useRecord`'s, and what may move on is what the
16
+ * backend publishes (a required field, a field's error), never a rule written here. web-ui's
17
+ * `StepFlow` draws the strip, the buttons and the blocked reason; its `Step` is a slot, so a
18
+ * `Wizard.Step` is a MARK the root resolves (`web/parts.tsx`), never a component that draws one.
19
+ * The step on screen can be the screen's (`step` / `onStepChange`: a window's `params`, so a
20
+ * reload lands on it). Inside a step, a part of the application's reads the record with
21
+ * `useWizardRecord()`.
22
+ */
23
+ import type { Entity, ResourceRef } from "@sincpro/client-framework";
24
+ import { type AnyRecord } from "@sincpro/criteria";
25
+ import { type RecordReading } from "../../react/useRecord.js";
26
+ import { type Part } from "../parts.js";
27
+ import { type ReactNode } from "react";
28
+ export type WizardStepProps = {
29
+ /** Who the step is: what `step` and `onStepChange` speak. */
30
+ id: string;
31
+ title: string;
32
+ /** One sentence under the title: what this step asks for. */
33
+ description?: string;
34
+ /** The record's fields this step writes, drawn as the record draws them, in this order. */
35
+ fields?: readonly string[];
36
+ /** What the forward button says from this step: on the last, what finishing does. */
37
+ nextLabel?: string;
38
+ /** What the step adds under its fields: a summary, a block of the application's. */
39
+ children?: ReactNode;
40
+ };
41
+ type WizardState = {
42
+ reading: RecordReading<AnyRecord>;
43
+ blockedOf: (fields: readonly string[]) => string | undefined;
44
+ };
45
+ /** The record the wizard around is filling — for a part of the application's inside a step. */
46
+ export declare function useWizardRecord<T extends AnyRecord = AnyRecord>(): RecordReading<T>;
47
+ export type WizardProps<T extends AnyRecord> = {
48
+ entity: Entity<T>;
49
+ /** The record it fills: `entity.newRef()` to create one, its id or reference to go on one. */
50
+ resource: string | ResourceRef;
51
+ /** The step on screen, when the screen holds it (a window's `params`). */
52
+ step?: string;
53
+ onStepChange?: (id: string) => void;
54
+ /** Saved: the record as the server answered it. */
55
+ onDone?: (record: unknown) => void;
56
+ /** Leave without finishing. Without it there is no «Cancel» — the window has its own way out. */
57
+ onCancel?: () => void;
58
+ /** `Wizard.Step`s, in order. */
59
+ children: ReactNode;
60
+ };
61
+ export declare function Wizard<T extends AnyRecord>({ entity, resource, step, onStepChange, onDone, onCancel, children, }: WizardProps<T>): import("react").JSX.Element | null;
62
+ export declare namespace Wizard {
63
+ var Step: Part<WizardStepProps, WizardState>;
64
+ }
65
+ export {};
@@ -0,0 +1,90 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { labelOf } from "@sincpro/criteria";
4
+ import { frameworkCopy } from "../../core/copy.js";
5
+ import { useRecord } from "../../react/useRecord.js";
6
+ import { part, resolveParts } from "../parts.js";
7
+ import { RecordField } from "./edit.js";
8
+ import { FormSection, StepFlow } from "@sincpro/web-ui";
9
+ import { Children, createContext, isValidElement, useContext, useEffect, useRef, useState, } from "react";
10
+ const Held = createContext(null);
11
+ /** The record the wizard around is filling — for a part of the application's inside a step. */
12
+ export function useWizardRecord() {
13
+ const reading = useContext(Held);
14
+ if (reading === null)
15
+ throw new Error("useWizardRecord is read inside a Wizard.");
16
+ return reading;
17
+ }
18
+ const Step = part("Wizard.Step", ({ id, title, description, fields = [], nextLabel, children }, { reading, blockedOf }) => {
19
+ const blocked = blockedOf(fields);
20
+ return (_jsxs(StepFlow.Step, { id: id, title: title, ...(description === undefined ? {} : { description }), ...(blocked === undefined ? {} : { blocked }), ...(nextLabel === undefined ? {} : { nextLabel }), children: [fields.length === 0 ? null : (_jsx(FormSection, { children: fields.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) })), children] }, id));
21
+ });
22
+ /** The steps written under the root, as marks: which fields each one holds. */
23
+ function stepsIn(children) {
24
+ return Children.toArray(children)
25
+ .filter((child) => isValidElement(child) && child.type === Step)
26
+ .map((child) => child.props);
27
+ }
28
+ export function Wizard({ entity, resource, step, onStepChange, onDone, onCancel, children, }) {
29
+ const reading = useRecord(entity, resource);
30
+ const { edit, meta, locale } = reading;
31
+ const [own, setOwn] = useState(undefined);
32
+ const go = (id) => {
33
+ if (step === undefined)
34
+ setOwn(id);
35
+ onStepChange?.(id);
36
+ };
37
+ // Finishing is a save; what it ends in arrives in the renders after it.
38
+ const finishing = useRef(false);
39
+ const [finished, setFinished] = useState(false);
40
+ const reported = useRef(false);
41
+ const steps = stepsIn(children);
42
+ // Refused: back to the first step that holds a field the server named.
43
+ const failing = Object.keys(edit.errors).join(",");
44
+ useEffect(() => {
45
+ if (!finishing.current || failing === "")
46
+ return;
47
+ finishing.current = false;
48
+ const named = failing.split(",");
49
+ const back = steps.find((one) => (one.fields ?? []).some((f) => named.includes(f)));
50
+ if (back !== undefined)
51
+ go(back.id);
52
+ // Only a new refusal moves the flow; the steps are read as written now.
53
+ // eslint-disable-next-line react-hooks/exhaustive-deps
54
+ }, [failing]);
55
+ // Saved: the record the hook became, or what a create answered without an identity.
56
+ useEffect(() => {
57
+ if (!finished || reported.current)
58
+ return;
59
+ if (!reading.isNew && reading.status === "ready") {
60
+ reported.current = true;
61
+ onDone?.(reading.record);
62
+ }
63
+ else if (reading.isNew && edit.created !== null) {
64
+ reported.current = true;
65
+ onDone?.(edit.created);
66
+ }
67
+ }, [finished, reading.isNew, reading.status, reading.record, edit.created, onDone]);
68
+ if (reading.status !== "ready")
69
+ return null;
70
+ const copy = frameworkCopy().record;
71
+ const blockedOf = (fields) => {
72
+ const wrong = fields.find((name) => edit.errors[name] !== undefined);
73
+ if (wrong !== undefined)
74
+ return edit.errors[wrong];
75
+ const missing = fields.filter((name) => edit.missing.includes(name));
76
+ return missing.length === 0
77
+ ? undefined
78
+ : copy.missing(missing.map((name) => labelOf(meta, name, locale ?? "en")));
79
+ };
80
+ const finish = async () => {
81
+ finishing.current = true;
82
+ if (await edit.save()) {
83
+ finishing.current = false;
84
+ setFinished(true);
85
+ }
86
+ };
87
+ const current = step ?? own;
88
+ return (_jsx(Held.Provider, { value: reading, children: _jsx(StepFlow, { ...(current === undefined ? {} : { current }), onCurrentChange: go, onFinish: () => void finish(), ...(onCancel === undefined ? {} : { onCancel }), busy: edit.saving, children: resolveParts(children, { reading, blockedOf }) }) }));
89
+ }
90
+ Wizard.Step = Step;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.21.0",
3
+ "version": "3.22.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",