@sincpro/web-framework 3.21.0 → 4.0.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 (88) hide show
  1. package/README.md +114 -112
  2. package/dist/core/cache.d.ts +20 -23
  3. package/dist/core/cache.js +37 -52
  4. package/dist/core/changes.d.ts +10 -18
  5. package/dist/core/changes.js +11 -30
  6. package/dist/core/command.d.ts +25 -11
  7. package/dist/core/command.js +9 -12
  8. package/dist/core/copy.d.ts +4 -0
  9. package/dist/core/copy.js +2 -0
  10. package/dist/core/edit.d.ts +16 -2
  11. package/dist/core/edit.js +13 -2
  12. package/dist/core/groups.d.ts +3 -2
  13. package/dist/core/groups.js +4 -3
  14. package/dist/core/index.d.ts +2 -2
  15. package/dist/core/index.js +2 -2
  16. package/dist/core/list.d.ts +17 -11
  17. package/dist/core/list.js +17 -11
  18. package/dist/core/names.d.ts +8 -6
  19. package/dist/core/names.js +14 -18
  20. package/dist/core/server.d.ts +9 -7
  21. package/dist/core/server.js +17 -21
  22. package/dist/core/trail.d.ts +6 -3
  23. package/dist/core/trail.js +2 -2
  24. package/dist/react/context.d.ts +13 -6
  25. package/dist/react/context.js +11 -9
  26. package/dist/react/index.d.ts +1 -1
  27. package/dist/react/index.js +1 -1
  28. package/dist/react/useBatchCommand.d.ts +5 -5
  29. package/dist/react/useBatchCommand.js +10 -12
  30. package/dist/react/useCommand.d.ts +11 -15
  31. package/dist/react/useCommand.js +15 -13
  32. package/dist/react/useCount.d.ts +2 -2
  33. package/dist/react/useCounts.js +10 -9
  34. package/dist/react/useGroups.d.ts +1 -1
  35. package/dist/react/useGroups.js +22 -13
  36. package/dist/react/useHistory.js +7 -7
  37. package/dist/react/useListing.d.ts +14 -7
  38. package/dist/react/useListing.js +33 -9
  39. package/dist/react/useLookup.js +5 -7
  40. package/dist/react/useNameOf.d.ts +2 -2
  41. package/dist/react/useNameOf.js +4 -13
  42. package/dist/react/usePivot.d.ts +1 -1
  43. package/dist/react/usePivot.js +13 -7
  44. package/dist/react/useRecord.js +49 -57
  45. package/dist/react/useRecordLifecycle.js +8 -9
  46. package/dist/react/useServiceReading.js +6 -18
  47. package/dist/react/useUpload.js +9 -2
  48. package/dist/react/useWrites.d.ts +13 -12
  49. package/dist/react/useWrites.js +17 -16
  50. package/dist/web/board/Dashboard.d.ts +112 -0
  51. package/dist/web/board/Dashboard.js +106 -0
  52. package/dist/web/board/index.d.ts +1 -0
  53. package/dist/web/board/index.js +1 -0
  54. package/dist/web/index.d.ts +2 -0
  55. package/dist/web/index.js +2 -0
  56. package/dist/web/list/EntityList.d.ts +2 -2
  57. package/dist/web/list/entityList/choosing.d.ts +3 -3
  58. package/dist/web/list/entityList/faces.d.ts +6 -6
  59. package/dist/web/list/entityList/grouping.d.ts +3 -3
  60. package/dist/web/list/entityList/opening.d.ts +4 -4
  61. package/dist/web/list/entityList/opening.js +2 -1
  62. package/dist/web/list/entityList/paging.d.ts +3 -3
  63. package/dist/web/list/entityList/props.d.ts +4 -4
  64. package/dist/web/list/entityList/rowActions.d.ts +4 -4
  65. package/dist/web/list/entityList/rowActions.js +1 -1
  66. package/dist/web/list/export.d.ts +2 -2
  67. package/dist/web/list/export.js +7 -8
  68. package/dist/web/list/presentation.d.ts +3 -3
  69. package/dist/web/list/records.d.ts +13 -10
  70. package/dist/web/list/records.js +23 -44
  71. package/dist/web/list/reorder.d.ts +1 -1
  72. package/dist/web/list/reorder.js +8 -6
  73. package/dist/web/list/rowCommands.d.ts +10 -9
  74. package/dist/web/list/rowCommands.js +14 -15
  75. package/dist/web/list/useEntityList.d.ts +4 -4
  76. package/dist/web/record/CommandButton.d.ts +8 -8
  77. package/dist/web/record/EntityTags.js +4 -4
  78. package/dist/web/record/RelatedList.js +2 -2
  79. package/dist/web/record/Wizard.d.ts +65 -0
  80. package/dist/web/record/Wizard.js +90 -0
  81. package/dist/web/record/lines.js +4 -4
  82. package/dist/web/record/richText.js +1 -1
  83. package/dist/web/workspace/SincproApp.d.ts +8 -6
  84. package/dist/web/workspace/SincproApp.js +17 -19
  85. package/dist/web/workspace/composer.d.ts +14 -9
  86. package/dist/web/workspace/composer.js +29 -8
  87. package/dist/web/workspace/record.js +2 -2
  88. package/package.json +3 -3
@@ -4,7 +4,7 @@ import type { Listing } from "../../react/useListing.js";
4
4
  /**
5
5
  * A listing's rows put in their order by hand: when they may be dragged (`reorderingOf`), the
6
6
  * rows as the screen shows them while a move travels, and the move itself — one `Edit` of the
7
- * record moved through its entity's own edit route, or one per row when its group is respaced.
7
+ * record moved through its entity's `edit` operation, or one per row when its group is respaced.
8
8
  *
9
9
  * const reorder = useReorder(listing, idOf);
10
10
  * <List.Table onReorder={reorder.move} /> // absent: no grip
@@ -1,22 +1,23 @@
1
1
  "use client";
2
- import { pathFor } from "@sincpro/client-framework";
2
+ import { targeted } from "@sincpro/client-framework";
3
+ import { withTargetsOf } from "../../core/edit.js";
3
4
  import { movesFor, placed, reorderingOf, } from "../../core/reorder.js";
4
5
  import { useFramework } from "../../react/context.js";
5
6
  import { useEffect, useMemo, useState } from "react";
6
7
  export function useReorder(listing, keyOf,
7
8
  /** `false` while the screen does not allow it (grouped, choosing). */
8
9
  allowed = true) {
9
- const { transport } = useFramework();
10
+ const { operations } = useFramework();
10
11
  const { entity, meta, order, rows: read } = listing;
11
- const route = entity.edit;
12
- const reordering = useMemo(() => (allowed && route !== undefined ? reorderingOf(meta, order) : undefined), [allowed, route, meta, order]);
12
+ const editing = entity.operations.edit;
13
+ const reordering = useMemo(() => (allowed && editing !== undefined ? reorderingOf(meta, order) : undefined), [allowed, editing, meta, order]);
13
14
  const [shown, setShown] = useState(null);
14
15
  const [error, setError] = useState(null);
15
16
  const [elsewhere, setElsewhere] = useState(false);
16
17
  // A new reading is what is stored: it replaces the order a move showed ahead of it.
17
18
  useEffect(() => setShown(null), [read]);
18
19
  const rows = shown ?? read;
19
- const move = reordering === undefined || route === undefined
20
+ const move = reordering === undefined || editing === undefined
20
21
  ? undefined
21
22
  : (id, before) => {
22
23
  const moves = movesFor(rows, keyOf, reordering, id, before);
@@ -33,7 +34,7 @@ allowed = true) {
33
34
  try {
34
35
  for (const one of moves) {
35
36
  const row = rows.find((candidate) => keyOf(candidate) === one.id) ?? {};
36
- await transport.send(route.method, pathFor(route, one.id, row), {
37
+ const edit = targeted(entity, editing, one.id, {
37
38
  id: one.id,
38
39
  values: { [reordering.handle]: one.value },
39
40
  changed: [reordering.handle],
@@ -43,6 +44,7 @@ allowed = true) {
43
44
  : {}),
44
45
  action: "save",
45
46
  });
47
+ await operations.call(editing, withTargetsOf(editing, row, edit));
46
48
  }
47
49
  }
48
50
  catch (failure) {
@@ -1,5 +1,6 @@
1
- import { type CommandBodies } from "@sincpro/client-framework";
1
+ import { type EntityOperations } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Expression } from "@sincpro/criteria";
3
+ import type { BodyOf, CommandName } from "../../core/command.js";
3
4
  import type { Listing } from "../../react/useListing.js";
4
5
  import type { RowAction } from "@sincpro/web-ui";
5
6
  import type { LucideIcon } from "lucide-react";
@@ -22,8 +23,8 @@ import type { LucideIcon } from "lucide-react";
22
23
  * ]);
23
24
  * <EntityList listing={listing} rowActions={commands.rowActions} />
24
25
  */
25
- export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
26
- [N in keyof C & string]: {
26
+ export type RowCommand<T, O extends EntityOperations = EntityOperations> = {
27
+ [N in CommandName<O>]: {
27
28
  /** A Command the entity declares (`entity({ commands })`); a typed entity, only its own. */
28
29
  command: N;
29
30
  label: string;
@@ -31,12 +32,12 @@ export type RowCommand<T, C extends CommandBodies = CommandBodies> = {
31
32
  tone?: RowAction["tone"];
32
33
  /** Offered only on rows that hold it — a hint, not protection: the server decides. */
33
34
  when?: Expression<T>;
34
- /** What the Command is sent with — checked against a typed entity's `C[command]`. Without
35
- * it, an empty body: the route (or the Command's `target`) names the row. */
36
- body?: (row: T) => C[N];
35
+ /** What the Command is sent with — checked against its operation's input. Without it, an
36
+ * empty body: the row's key goes where the operation names it. */
37
+ body?: (row: T) => BodyOf<O, N>;
37
38
  };
38
- }[keyof C & string];
39
- /** The row action of the trash (`trashOf`): the entity's `restore` route, run from the row. */
39
+ }[CommandName<O>];
40
+ /** The row action of the trash (`trashOf`): the entity's `restore`, run from the row. */
40
41
  export declare const RESTORE = "restore";
41
42
  export type RowCommands<T> = {
42
43
  rowActions: (row: T) => readonly RowAction[];
@@ -44,4 +45,4 @@ export type RowCommands<T> = {
44
45
  error: unknown;
45
46
  dismiss: () => void;
46
47
  };
47
- export declare function useRowCommands<T extends AnyRecord, C extends CommandBodies = CommandBodies>(listing: Listing<T, C>, commands: readonly RowCommand<T, C>[]): RowCommands<T>;
48
+ export declare function useRowCommands<T extends AnyRecord, O extends EntityOperations = EntityOperations>(listing: Listing<T, O>, commands: readonly RowCommand<T, O>[]): RowCommands<T>;
@@ -1,12 +1,13 @@
1
1
  "use client";
2
- import { bodyFor, pathFor, retryKeys } from "@sincpro/client-framework";
2
+ import { retryKeys, targeted } from "@sincpro/client-framework";
3
3
  import { matches } from "@sincpro/criteria";
4
+ import { withTargetsOf } from "../../core/edit.js";
4
5
  import { useFramework } from "../../react/context.js";
5
6
  import { useCallback, useState } from "react";
6
- /** The row action of the trash (`trashOf`): the entity's `restore` route, run from the row. */
7
+ /** The row action of the trash (`trashOf`): the entity's `restore`, run from the row. */
7
8
  export const RESTORE = "restore";
8
9
  export function useRowCommands(listing, commands) {
9
- const { transport } = useFramework();
10
+ const { operations } = useFramework();
10
11
  const [running, setRunning] = useState(new Set());
11
12
  const [error, setError] = useState(null);
12
13
  // One key per row and Command, kept while it goes unanswered: retrying is the same gesture.
@@ -14,25 +15,23 @@ export function useRowCommands(listing, commands) {
14
15
  const { entity, meta } = listing;
15
16
  const key = meta?.get_id || meta?.identity || "id";
16
17
  const run = useCallback(async (one, row) => {
17
- // «Restore» on a row of the trash runs the entity's own `restore` route (`trashOf`), unless
18
- // the entity declares a Command of that name.
19
- const route = entity.commands[one.command] ??
20
- (one.command === RESTORE ? entity.restore : undefined);
21
- if (route === undefined)
18
+ // «Restore» on a row of the trash runs the entity's own `restore` (`trashOf`), unless the
19
+ // entity declares a Command of that name.
20
+ const operation = entity.operations.commands?.[one.command] ??
21
+ (one.command === RESTORE ? entity.operations.restore : undefined);
22
+ if (operation === undefined)
22
23
  throw new Error(`${entity.key} declares no command "${one.command}"`);
23
24
  const id = String(row[key]);
24
25
  const gesture = `${one.command}\u0000${id}`;
25
26
  const retry = keys.get(gesture) ?? retryKeys();
26
27
  keys.set(gesture, retry);
27
- // A Command whose body names its record (`target`) gets the row's id there.
28
- const body = bodyFor(route, id, one.body?.(row) ?? {});
28
+ // The row's id where the operation names its record; what else it names (`tenant_id`)
29
+ // is the row's, unless the body says it.
30
+ const body = withTargetsOf(operation, row, targeted(entity, operation, id, one.body?.(row) ?? {}));
29
31
  setRunning((now) => new Set(now).add(gesture));
30
32
  setError(null);
31
33
  try {
32
- // A key of the route beyond `{id}` (`{tenant_id}`) is the row's, unless the body says it.
33
- await transport.send(route.method, pathFor(route, id, { ...row, ...body }), body, undefined, {
34
- idempotencyKey: retry.keyFor(body),
35
- });
34
+ await operations.call(operation, body, { idempotencyKey: retry.keyFor(body) });
36
35
  retry.settle(null);
37
36
  listing.reload();
38
37
  }
@@ -47,7 +46,7 @@ export function useRowCommands(listing, commands) {
47
46
  return next;
48
47
  });
49
48
  }
50
- }, [transport, entity, key, keys, listing]);
49
+ }, [operations, entity, key, keys, listing]);
51
50
  const rowActions = (row) => commands
52
51
  .filter((one) => meta === null || one.when === undefined || matches(row, one.when, meta))
53
52
  .map((one) => ({
@@ -1,4 +1,4 @@
1
- import { type CommandBodies } from "@sincpro/client-framework";
1
+ import { type EntityOperations } from "@sincpro/client-framework";
2
2
  import { type AnyRecord } from "@sincpro/criteria";
3
3
  import { type EntityListProps } from "./entityList/props.js";
4
4
  export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } from "./entityList/props.js";
@@ -21,10 +21,10 @@ export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } fro
21
21
  * What the screen asks wins over the named list's (`defineList`), which wins over the entity's
22
22
  * own look (`presented`), which wins over the model.
23
23
  */
24
- export declare function useEntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title, description, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot, empty, search, recent: askedRecent, sums, filters, facets, groupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>,
24
+ export declare function useEntityList<T extends AnyRecord, O extends EntityOperations = EntityOperations>({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title, description, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot, empty, search, recent: askedRecent, sums, filters, facets, groupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, O>,
25
25
  /** The faces the screen's tree writes, when it writes one (`EntityList.Table`…). */
26
26
  writtenViews?: readonly string[]): {
27
- listing: import("../../index.js").Listing<T, C>;
27
+ listing: import("../../index.js").Listing<T, O>;
28
28
  meta: import("@sincpro/criteria").Meta | null;
29
29
  locale: string | undefined;
30
30
  embedded: boolean;
@@ -180,4 +180,4 @@ writtenViews?: readonly string[]): {
180
180
  };
181
181
  };
182
182
  /** What a list's root and its parts read. */
183
- export type EntityListState<T extends AnyRecord = AnyRecord> = ReturnType<typeof useEntityList<T, CommandBodies>>;
183
+ export type EntityListState<T extends AnyRecord = AnyRecord> = ReturnType<typeof useEntityList<T, EntityOperations>>;
@@ -1,6 +1,6 @@
1
- import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
1
+ import { type Entity, type EntityOperations } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
- import { type AnswerOf } from "../../react/useCommand.js";
3
+ import type { BodyOf, CommandAnswer, CommandName } from "../../core/command.js";
4
4
  import { type ActionDialog } from "./ActionButton.js";
5
5
  import { type AskField } from "./ask.js";
6
6
  import { type ActionLook, type DockedAction } from "./dock.js";
@@ -17,13 +17,13 @@ import { type ActionLook, type DockedAction } from "./dock.js";
17
17
  * beside `body`.
18
18
  */
19
19
  /** What a Command's button and dock action are given. */
20
- export type CommandActionProps<T extends AnyRecord, R, C extends CommandBodies, N extends keyof C & string, A extends CommandAnswers> = {
21
- entity: Entity<T, C, A>;
20
+ export type CommandActionProps<T extends AnyRecord, R, O extends EntityOperations, N extends CommandName<O>> = {
21
+ entity: Entity<T, O>;
22
22
  /** One the entity declares; a typed entity takes only its own names. */
23
23
  command: N;
24
24
  id?: string;
25
25
  /** What it is sent with — checked against a typed entity's `C[command]`. */
26
- body?: C[N];
26
+ body?: BodyOf<O, N>;
27
27
  label: string;
28
28
  /** Asks the server what it would do before doing it. */
29
29
  destructive?: boolean;
@@ -35,9 +35,9 @@ export type CommandActionProps<T extends AnyRecord, R, C extends CommandBodies,
35
35
  record?: AnyRecord;
36
36
  /** What its window says — its title (the label without «…» by default), a sentence under it. */
37
37
  dialog?: ActionDialog;
38
- onDone?: (answer: AnswerOf<R, A, N>) => void;
38
+ onDone?: (answer: CommandAnswer<R, O, N>) => void;
39
39
  };
40
- 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>({ role, ...props }: CommandActionProps<T, R, C, N, A> & {
40
+ export declare function CommandButton<T extends AnyRecord, R = unknown, O extends EntityOperations = EntityOperations, N extends CommandName<O> = CommandName<O>>({ role, ...props }: CommandActionProps<T, R, O, N> & {
41
41
  role?: "primary" | "secondary" | "ghost";
42
42
  }): import("react").JSX.Element;
43
43
  /**
@@ -52,7 +52,7 @@ export declare function CommandButton<T extends AnyRecord, R = unknown, C extend
52
52
  * <Record.Dock actions={[confirmar.action, anular.action]} />
53
53
  * {anular.dialog}
54
54
  */
55
- export declare function useCommandAction<T extends AnyRecord, R = unknown, C extends CommandBodies = CommandBodies, N extends keyof C & string = keyof C & string, A extends CommandAnswers = CommandAnswers>({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }: CommandActionProps<T, R, C, N, A> & Omit<ActionLook, "id"> & {
55
+ export declare function useCommandAction<T extends AnyRecord, R = unknown, O extends EntityOperations = EntityOperations, N extends CommandName<O> = CommandName<O>>({ icon, primary, danger, tucked, shortcut, hint, actionId, ...props }: CommandActionProps<T, R, O, N> & Omit<ActionLook, "id"> & {
56
56
  /** The dock's id for it — the record's is `id`. Defaults to the label. */
57
57
  actionId?: string;
58
58
  }): DockedAction;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { keysOf, listRoute } from "@sincpro/client-framework";
3
+ import { keysOf } from "@sincpro/client-framework";
4
4
  import { isList } from "../../core/list.js";
5
5
  import { useFramework } from "../../react/context.js";
6
6
  import { BATCH_LIMIT } from "../../react/useBatchCommand.js";
@@ -33,7 +33,7 @@ import { useRef } from "react";
33
33
  * <EntityTags entity={people} value={followers} onChange={setFollowers} />
34
34
  */
35
35
  export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarget, onBrowseAll, placeholder, disabled, "aria-label": ariaLabel, }) {
36
- const { metas, transport } = useFramework();
36
+ const { metas, operations } = useFramework();
37
37
  const opening = useRecordOpening();
38
38
  const toast = useToastIfAny();
39
39
  const base = isList(entity) ? entity.entity : entity;
@@ -54,8 +54,8 @@ export function EntityTags({ entity, value, onChange, criteria, onOpen, openTarg
54
54
  const addChosen = (selection) => {
55
55
  const meta = metas.get(base.key);
56
56
  keysOf(selection, {
57
- transport,
58
- route: listRoute(base.list),
57
+ transport: operations,
58
+ entity: base,
59
59
  identity: meta?.get_id || meta?.identity || "id",
60
60
  limit: BATCH_LIMIT,
61
61
  }).then(add, (failure) => toast?.show(refusalNotice(failure)));
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import {} from "@sincpro/client-framework";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
- import { fieldStateOf } from "../../core/edit.js";
5
+ import { canCreate, fieldStateOf } from "../../core/edit.js";
6
6
  import { defaultFields, STAMPS } from "../../core/present.js";
7
7
  import { backReference, isKeyValue } from "../../core/relation.js";
8
8
  import { useRelated } from "../../react/useRelated.js";
@@ -65,7 +65,7 @@ export function RelatedList({ record, name, entity, pageSize, ...list }) {
65
65
  // The value the rows point back with.
66
66
  const here = pointing?.value;
67
67
  const adding = create === undefined ||
68
- entity.create === undefined ||
68
+ !canCreate(entity, listing.meta) ||
69
69
  !back ||
70
70
  record.isNew ||
71
71
  !isKeyValue(here) ||
@@ -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;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
- import { keysOf, listRoute } from "@sincpro/client-framework";
3
+ import { keysOf } from "@sincpro/client-framework";
4
4
  import { choicesOf } from "@sincpro/criteria";
5
5
  import { frameworkCopy } from "../../core/copy.js";
6
6
  import { adviceAt, defaultsOf, errorAt, linePlacesOf, pathOf, } from "../../core/edit.js";
@@ -122,7 +122,7 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
122
122
  */
123
123
  export function RecordLinesEditor({ record, name, lines, look = {}, }) {
124
124
  const { meta, locale, edit } = record;
125
- const { entities, metas, transport } = useFramework();
125
+ const { entities, metas, operations } = useFramework();
126
126
  const opening = useRecordOpening();
127
127
  const toast = useToastIfAny();
128
128
  const definition = meta?.fields[name]?.definition ?? null;
@@ -177,8 +177,8 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
177
177
  : () => chooseMany(manyEntity, (selection) => {
178
178
  const meta = metas.get(manyEntity.key);
179
179
  keysOf(selection, {
180
- transport,
181
- route: listRoute(manyEntity.list),
180
+ transport: operations,
181
+ entity: manyEntity,
182
182
  identity: meta?.get_id || meta?.identity || "id",
183
183
  limit: BATCH_LIMIT,
184
184
  }).then((keys) => write((all) => [
@@ -24,7 +24,7 @@ export function RichTextControl({ control }) {
24
24
  const { richText, uploads, transport } = useFramework();
25
25
  const { about } = control;
26
26
  const html = typeof control.value === "string" ? control.value : "";
27
- const images = useMemo(() => uploads === undefined || about === undefined
27
+ const images = useMemo(() => uploads === undefined || transport === undefined || about === undefined
28
28
  ? undefined
29
29
  : {
30
30
  upload: async (file) => {
@@ -1,4 +1,4 @@
1
- import { type ChangeFeed, type Entity, type Transport } from "@sincpro/client-framework";
1
+ import { type ChangeFeed, type Entity, type OperationTransport, type Transport } from "@sincpro/client-framework";
2
2
  import type { Meta } from "@sincpro/criteria";
3
3
  import { type ComposerSkin, type OnViewError, type ResourceRef, type ViewSpec, type WorkspaceStore } from "@sincpro/web-composer";
4
4
  import { type CacheOptions } from "../../core/cache.js";
@@ -7,9 +7,11 @@ import type { DateStyle } from "../../core/present.js";
7
7
  import type { RichTextSettings } from "../../core/richText.js";
8
8
  import { type People } from "../../react/context.js";
9
9
  import { type ReactNode } from "react";
10
- export declare function SincproApp({ transport, views, start, language, voice, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, region, richText, uploads, people, events, workspace: given, bar, onViewError, changes, }: {
11
- /** Who answers. Without it, the `FrameworkProvider` around the app — one provider for every
12
- * face of a product. */
10
+ export declare function SincproApp({ operations, transport, views, start, language, voice, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, region, richText, uploads, people, events, workspace: given, bar, onViewError, changes, }: {
11
+ /** Who answers: the client's operations over its wire (`restOperations(…)`). Without them,
12
+ * the `FrameworkProvider` around the app — one provider for every face of a product. */
13
+ operations?: OperationTransport;
14
+ /** Where a file goes (`uploadTo`): the REST transport, when the app takes files. */
13
15
  transport?: Transport;
14
16
  /** The entities as composer views — `entityView(…)` — and any other view of the app. */
15
17
  views: readonly ViewSpec[];
@@ -34,7 +36,7 @@ export declare function SincproApp({ transport, views, start, language, voice, m
34
36
  skin?: ComposerSkin;
35
37
  /**
36
38
  * Repeated reads served from memory — the list gone back to, the record reopened — and
37
- * forgotten the moment a write touches their entity (`cachedTransport`). 30 s by default;
39
+ * forgotten the moment a write touches their entity (`cachedOperations`). 30 s by default;
38
40
  * `false` asks the server every time.
39
41
  */
40
42
  cache?: CacheOptions | false;
@@ -72,7 +74,7 @@ export declare function SincproApp({ transport, views, start, language, voice, m
72
74
  onViewError?: OnViewError;
73
75
  /**
74
76
  * Where writes are announced — the process's (`processChanges`, @sincpro/client-framework),
75
- * which every transport of the framework writes to, whoever sends: a screen, or a use case's
77
+ * which every operation adapter of the framework writes to, whoever sends: a screen, or a use case's
76
78
  * generated client. The cache forgets what each write touches, and the screens read it again.
77
79
  */
78
80
  changes?: ChangeFeed;
@@ -3,22 +3,23 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { processChanges, processContext, reportError, } from "@sincpro/client-framework";
4
4
  import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
5
5
  import { createRegistry, formatRef, PHONE_WIDTH } from "@sincpro/web-composer/domain";
6
- import { cachedTransport, } from "../../core/cache.js";
6
+ import { cachedOperations, } from "../../core/cache.js";
7
7
  import { installFrameworkCopy, SPANISH_FRAMEWORK_COPY, SPANISH_FRAMEWORK_COPY_TU, } from "../../core/copy.js";
8
8
  import { FrameworkProvider, ModelDefinitions, useFrameworkIfAny, } from "../../react/context.js";
9
9
  import { useSearchRecords } from "../list/records.js";
10
+ import { WorkspaceModels } from "./composer.js";
10
11
  import { webUiSkin } from "./skin.js";
11
12
  import { installCopy, SearchProvider, SPANISH_COPY, SPANISH_COPY_TU, ToastProvider, useSearchSettings, } from "@sincpro/web-ui";
12
13
  import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
13
14
  /**
14
- * The application context in one place: who answers (the transport), in which language, which
15
+ * The application context in one place: who answers (the operations), in which language, which
15
16
  * model definitions are already known, the toasts, and the workspace with its views, ⌘K and
16
17
  * shortcuts.
17
18
  *
18
19
  * Context: forge's `main.tsx` + `console.tsx` installed three copy tables, a toast provider, a
19
20
  * context of its own and a composer by hand. This is that, once. It is a convenience, not the
20
21
  * only door: everything it mounts is exported, and an app with its own shell mounts them itself.
21
- * What it does NOT own: the session (the app builds the transport with its headers) and what the
22
+ * What it does NOT own: the session (the app builds the operations with its headers) and what the
22
23
  * application bar says. The bar is the app's (`bar`), drawn above the workspace inside every
23
24
  * provider; a menu in it opens views through the workspace the app holds (`workspace`, from
24
25
  * composer's `useWorkspace()`) — a workspace owned in here could not be reached from outside.
@@ -26,13 +27,13 @@ import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
26
27
  * const workspace = useWorkspace();
27
28
  * <SincproApp workspace={workspace} bar={<Menu onOpen={(ref) => workspace.push(ref)} />} … />
28
29
  *
29
- * Inside a product with several faces it is ONE of them: without `transport` it joins the
30
- * `FrameworkProvider` around it — its transport and cache, its context, its zone and currency —
30
+ * Inside a product with several faces it is ONE of them: without `operations` it joins the
31
+ * `FrameworkProvider` around it — its operations and cache, its context, its zone and currency —
31
32
  * and brings only what is its own: its entities, the definitions of their models and their facts
32
33
  * (`ModelDefinitions`). The configuration of the provider's (`timeZone`, `currency`, `region`,
33
34
  * `dateStyle`, `richText`, `uploads`, `people`, `cache`, `changes`) is then the provider's: said once.
34
35
  *
35
- * <FrameworkProvider transport={transport} timeZone="America/La_Paz" currency="BOB">
36
+ * <FrameworkProvider operations={operations} timeZone="America/La_Paz" currency="BOB">
36
37
  * <Site />
37
38
  * <SincproApp views={views} entities={billing.entities} metas={metasOf(billing)} />
38
39
  * </FrameworkProvider>
@@ -53,7 +54,7 @@ const isPhone = () => typeof window !== "undefined" && window.matchMedia !== und
53
54
  /**
54
55
  * The framework's search of a relation's records for every web-ui bar and builder below — a
55
56
  * screen's own `SearchBar` included —, unless the application put its own around the app.
56
- * Inside the `FrameworkProvider`: it searches through the screens' transport.
57
+ * Inside the `FrameworkProvider`: it searches through the screens' operations.
57
58
  */
58
59
  function FrameworkSearch({ children }) {
59
60
  const framework = useSearchRecords();
@@ -62,7 +63,7 @@ function FrameworkSearch({ children }) {
62
63
  }
63
64
  /** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
64
65
  const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
65
- export function SincproApp({ transport, views, start, language = "es", voice = "vos", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, region, richText, uploads, people, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
66
+ export function SincproApp({ operations, transport, views, start, language = "es", voice = "vos", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, region, richText, uploads, people, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
66
67
  // Installed once, before anything draws: the three tables are module state of their packages.
67
68
  useState(() => {
68
69
  if (language === "es") {
@@ -73,17 +74,14 @@ export function SincproApp({ transport, views, start, language = "es", voice = "
73
74
  return null;
74
75
  });
75
76
  const around = useFrameworkIfAny();
76
- if (transport === undefined && around === null)
77
- throw new Error("SincproApp needs a transport, or a FrameworkProvider around it.");
78
- const cached = useMemo(() => transport === undefined || cache === false
79
- ? transport
80
- : cachedTransport(transport, {
81
- ...(entities === undefined ? {} : { entities }),
82
- ...cache,
83
- }),
77
+ if (operations === undefined && around === null)
78
+ throw new Error("SincproApp needs operations, or a FrameworkProvider around it.");
79
+ const cached = useMemo(() => operations === undefined || cache === false
80
+ ? operations
81
+ : cachedOperations(operations, cache),
84
82
  // The options are read once: a cache that changes shape mid-session forgets everything.
85
83
  // eslint-disable-next-line react-hooks/exhaustive-deps
86
- [transport]);
84
+ [operations]);
87
85
  // What was read in one company is not the other's, and what anyone wrote is no longer what was
88
86
  // read: a change of context forgets every answer, a write what it touched — whoever wrote it, a
89
87
  // use case's client as much as a screen — before the screens read again.
@@ -110,9 +108,9 @@ export function SincproApp({ transport, views, start, language = "es", voice = "
110
108
  // The first screen only: a re-render must not push it again.
111
109
  // eslint-disable-next-line react-hooks/exhaustive-deps
112
110
  }, [workspace]);
113
- const shell = (_jsx(FrameworkSearch, { children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
111
+ const shell = (_jsxs(FrameworkSearch, { children: [_jsx(WorkspaceModels, {}), _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) })] }));
114
112
  // One face of a product: the provider around it is the app's, and this brings only its own.
115
113
  if (cached === undefined)
116
114
  return (_jsx(ModelDefinitions, { ...(entities === undefined ? {} : { entities }), ...(metas === undefined ? {} : { metas }), ...(events === undefined ? {} : { events }), ...(people === undefined ? {} : { people }), children: shell }));
117
- return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), dateStyle: dateStyle ?? (phone ? "literal" : "numeric"), ...(currency === undefined ? {} : { currency }), ...(region === undefined ? {} : { region }), ...(richText === undefined ? {} : { richText }), ...(uploads === undefined ? {} : { uploads }), ...(people === undefined ? {} : { people }), ...(events === undefined ? {} : { events }), children: shell }));
115
+ return (_jsx(FrameworkProvider, { operations: cached, ...(transport === undefined ? {} : { transport }), locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), dateStyle: dateStyle ?? (phone ? "literal" : "numeric"), ...(currency === undefined ? {} : { currency }), ...(region === undefined ? {} : { region }), ...(richText === undefined ? {} : { richText }), ...(uploads === undefined ? {} : { uploads }), ...(people === undefined ? {} : { people }), ...(events === undefined ? {} : { events }), children: shell }));
118
116
  }