@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
@@ -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";
@@ -1,4 +1,4 @@
1
- import type { CommandBodies, Entity } from "@sincpro/client-framework";
1
+ import type { Entity, EntityOperations } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import type { Listing } from "../../react/useListing.js";
4
4
  import { type EntityListProps, type EntityListState } from "./useEntityList.js";
@@ -15,7 +15,7 @@ export type { EntityEmpty, EntityFace, EntityListProps, NamedFilter, View, } fro
15
15
  * }
16
16
  */
17
17
  export declare function useScreenListing<T extends AnyRecord>(_entity?: Entity<T>): Listing<T>;
18
- declare function EntityListRoot<T extends AnyRecord, C extends CommandBodies = CommandBodies>(props: EntityListProps<T, C> & {
18
+ declare function EntityListRoot<T extends AnyRecord, O extends EntityOperations = EntityOperations>(props: EntityListProps<T, O> & {
19
19
  /** The list's tree. Without it, the default: the bar, the faces of `views`, the notices. */
20
20
  children?: ReactNode;
21
21
  }): import("react").JSX.Element;
@@ -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 { WorkspaceApi } from "@sincpro/web-composer";
4
4
  import type { Listing } from "../../../react/useListing.js";
@@ -23,8 +23,8 @@ export declare function purposeOf(api: WorkspaceApi | undefined): {
23
23
  * without knowing this list. Its actions — answering whoever asked for several, else the
24
24
  * screen's — go to the dock as data, or into the bar when drawn by hand.
25
25
  */
26
- export declare function useListChoosing<T extends AnyRecord, C extends CommandBodies>({ listing, api, idOf, held, selectable, selectionActions, choosingMany, }: {
27
- listing: Listing<T, C>;
26
+ export declare function useListChoosing<T extends AnyRecord, O extends EntityOperations>({ listing, api, idOf, held, selectable, selectionActions, choosingMany, }: {
27
+ listing: Listing<T, O>;
28
28
  api: WorkspaceApi | undefined;
29
29
  idOf: (row: T) => string;
30
30
  held: ListSelection<T> | undefined;
@@ -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 ResourceRef, type WorkspaceApi } from "@sincpro/web-composer";
4
4
  import type { Listing } from "../../../react/useListing.js";
@@ -14,13 +14,13 @@ import { type ReactNode } from "react";
14
14
  * same columns — never a second list of fields. The pivot asks the server only while it is the
15
15
  * face on screen.
16
16
  */
17
- export declare function useListFaces<T extends AnyRecord, C extends CommandBodies>({ listing, api, idOf, columns, cells, yesNo, choosing, refOf, elsewhere, opens, openInOf, present, views, pivot: pivotAsked, }: {
18
- listing: Listing<T, C>;
17
+ export declare function useListFaces<T extends AnyRecord, O extends EntityOperations>({ listing, api, idOf, columns, cells, yesNo, choosing, refOf, elsewhere, opens, openInOf, present, views, pivot: pivotAsked, }: {
18
+ listing: Listing<T, O>;
19
19
  api: WorkspaceApi | undefined;
20
20
  idOf: (row: T) => string;
21
21
  columns: readonly string[] | undefined;
22
- cells: EntityListProps<T, C>["cells"];
23
- yesNo: EntityListProps<T, C>["yesNo"];
22
+ cells: EntityListProps<T, O>["cells"];
23
+ yesNo: EntityListProps<T, O>["yesNo"];
24
24
  choosing: boolean;
25
25
  refOf: (row: T) => ResourceRef;
26
26
  elsewhere: readonly string[];
@@ -28,7 +28,7 @@ export declare function useListFaces<T extends AnyRecord, C extends CommandBodie
28
28
  openInOf: (row: T) => ReactNode;
29
29
  present: string;
30
30
  views: readonly string[];
31
- pivot: EntityListProps<T, C>["pivot"];
31
+ pivot: EntityListProps<T, O>["pivot"];
32
32
  }): {
33
33
  columns: import("@sincpro/web-ui").DataColumn<T>[];
34
34
  sheetColumns: {
@@ -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 { Listing } from "../../../react/useListing.js";
4
4
  import { type DataColumn, type Pile } from "@sincpro/web-ui";
@@ -13,8 +13,8 @@ import { type DataColumn, type Pile } from "@sincpro/web-ui";
13
13
  * than it counts offers the next page of them. A table and a sheet say a group's sums under their
14
14
  * columns: beside the group's name, only what no column shown adds up.
15
15
  */
16
- export declare function useListGrouping<T extends AnyRecord, C extends CommandBodies>({ listing, sums, columns, present, }: {
17
- listing: Listing<T, C>;
16
+ export declare function useListGrouping<T extends AnyRecord, O extends EntityOperations>({ listing, sums, columns, present, }: {
17
+ listing: Listing<T, O>;
18
18
  sums: readonly string[] | false | undefined;
19
19
  columns: readonly DataColumn<T>[];
20
20
  present: string;
@@ -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 { WorkspaceApi } from "@sincpro/web-composer";
4
4
  import type { Listing } from "../../../react/useListing.js";
@@ -13,7 +13,7 @@ import type { DockAction, OpenTarget } from "@sincpro/web-ui";
13
13
  * the record it opened replaced it and still walks on it — so the oldest go past a ceiling
14
14
  * instead: one per list ever shown, fifty at most.
15
15
  */
16
- export declare function useListTrail<T extends AnyRecord, C extends CommandBodies>(listing: Listing<T, C>, api: WorkspaceApi | undefined, identity: string, idOf: (row: T) => string): string;
16
+ export declare function useListTrail<T extends AnyRecord, O extends EntityOperations>(listing: Listing<T, O>, api: WorkspaceApi | undefined, identity: string, idOf: (row: T) => string): string;
17
17
  /**
18
18
  * What a row does, and where its record may open.
19
19
  *
@@ -22,8 +22,8 @@ export declare function useListTrail<T extends AnyRecord, C extends CommandBodie
22
22
  * among the row's ways in, web-ui's (`openTargets` + `onOpenIn`): 👁 for a look, and «Abrir en…»
23
23
  * with the rest, in ONE place at the row's end. A chooser only chooses.
24
24
  */
25
- export declare function useListOpening<T extends AnyRecord, C extends CommandBodies>({ listing, api, idOf, chosen, choosing, choosingMany, embedded, create, actions, onOpen, onPeek, openTargets, onOpenIn, }: {
26
- listing: Listing<T, C>;
25
+ export declare function useListOpening<T extends AnyRecord, O extends EntityOperations>({ listing, api, idOf, chosen, choosing, choosingMany, embedded, create, actions, onOpen, onPeek, openTargets, onOpenIn, }: {
26
+ listing: Listing<T, O>;
27
27
  api: WorkspaceApi | undefined;
28
28
  idOf: (row: T) => string;
29
29
  chosen: ListSelection<T>;
@@ -28,7 +28,8 @@ export function useListTrail(listing, api, identity, idOf) {
28
28
  return;
29
29
  const pages = listing.paging === "pages";
30
30
  trails.set(trailKey, {
31
- route: listing.route,
31
+ entity: listing.entity,
32
+ input: listing.input,
32
33
  question: listing.question,
33
34
  key: identity,
34
35
  ids: listing.rows.map(idOf),
@@ -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 { Groups } from "../../../react/useGroups.js";
4
4
  import type { Listing } from "../../../react/useListing.js";
@@ -16,8 +16,8 @@ import type { ReactNode } from "react";
16
16
  * this page's; inside a record or a panel a page's sum reads as THE total, so an embedded list
17
17
  * adds up only when every row is in hand.
18
18
  */
19
- export declare function useListPaging<T extends AnyRecord, C extends CommandBodies>({ listing, groups, grouped, records, columns, embedded, present, }: {
20
- listing: Listing<T, C>;
19
+ export declare function useListPaging<T extends AnyRecord, O extends EntityOperations>({ listing, groups, grouped, records, columns, embedded, present, }: {
20
+ listing: Listing<T, O>;
21
21
  groups: Groups<T>;
22
22
  grouped: boolean;
23
23
  records: number;
@@ -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 { WorkspaceApi } from "@sincpro/web-composer";
4
4
  import type { GroupLevel, NamedFilter } from "../../../core/list.js";
@@ -13,8 +13,8 @@ export type { NamedFilter };
13
13
  * What a screen says to an `EntityList`: values, never regions — a region is a part
14
14
  * (`EntityList.Bar`, `EntityList.Table`…).
15
15
  */
16
- export type EntityListProps<T extends AnyRecord, C extends CommandBodies = CommandBodies> = {
17
- listing: Listing<T, C>;
16
+ export type EntityListProps<T extends AnyRecord, O extends EntityOperations = EntityOperations> = {
17
+ listing: Listing<T, O>;
18
18
  /**
19
19
  * The workspace this list is a view of. With it, a row opens its record as a page, the
20
20
  * identity column is the composer's `RecordLink` (peek, side panel, window on hover) and the
@@ -135,7 +135,7 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
135
135
  * The entity's Commands offered on each row («Confirmar»), sent with their idempotency key;
136
136
  * the list is read again when one is done (`useRowCommands`).
137
137
  */
138
- commands?: readonly RowCommand<T, C>[];
138
+ commands?: readonly RowCommand<T, O>[];
139
139
  /** Any other action of a row — or the commands built by hand with `useRowCommands`. */
140
140
  rowActions?: (row: T) => readonly RowAction[];
141
141
  /**
@@ -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 { Listing } from "../../../react/useListing.js";
4
4
  import { type RowCommand } from "../rowCommands.js";
@@ -11,10 +11,10 @@ import type { RowAction } from "@sincpro/web-ui";
11
11
  * undone, so it runs on the click, and the list reads again after. Rows are reordered only on the
12
12
  * whole order, never grouped or while choosing.
13
13
  */
14
- export declare function useListRowActions<T extends AnyRecord, C extends CommandBodies>({ listing, idOf, commands, rowActions: asked, grouped, choosing, }: {
15
- listing: Listing<T, C>;
14
+ export declare function useListRowActions<T extends AnyRecord, O extends EntityOperations>({ listing, idOf, commands, rowActions: asked, grouped, choosing, }: {
15
+ listing: Listing<T, O>;
16
16
  idOf: (row: T) => string;
17
- commands: readonly RowCommand<T, C>[];
17
+ commands: readonly RowCommand<T, O>[];
18
18
  rowActions: ((row: T) => readonly RowAction[]) | undefined;
19
19
  grouped: boolean;
20
20
  choosing: boolean;
@@ -14,7 +14,7 @@ import { useMemo } from "react";
14
14
  * whole order, never grouped or while choosing.
15
15
  */
16
16
  export function useListRowActions({ listing, idOf, commands, rowActions: asked, grouped, choosing, }) {
17
- const restoring = listing.definition?.trash === true && listing.entity.restore !== undefined;
17
+ const restoring = listing.definition?.trash === true && listing.entity.operations.restore !== undefined;
18
18
  const offered = useMemo(() => restoring
19
19
  ? [
20
20
  ...commands,
@@ -3,8 +3,8 @@ import type { Listing } from "../../react/useListing.js";
3
3
  import { type DockAction } from "@sincpro/web-ui";
4
4
  /**
5
5
  * «Exportar»: the list's records — its question on screen, filter and order, every page — as a
6
- * spreadsheet (`core/export`), saved by the browser. Offered when the entity declares its export
7
- * (`entity(…, { export: "/invoices/export" })`); `null` otherwise.
6
+ * spreadsheet (`core/export`), saved by the browser. Offered when the entity has an `export`
7
+ * operation (its contract publishes one); `null` otherwise.
8
8
  *
9
9
  * Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
10
10
  * fetched to build it, so a million rows is the server's work, not the page's), and this writes
@@ -1,5 +1,4 @@
1
1
  "use client";
2
- import { downloadRoute, exportRoute } from "@sincpro/client-framework";
3
2
  import { nameOf } from "@sincpro/criteria";
4
3
  import { frameworkCopy } from "../../core/copy.js";
5
4
  import { csvOf, exportColumnsOf } from "../../core/export.js";
@@ -9,20 +8,19 @@ import { useToastIfAny } from "@sincpro/web-ui";
9
8
  import { Download } from "lucide-react";
10
9
  /**
11
10
  * «Exportar»: the list's records — its question on screen, filter and order, every page — as a
12
- * spreadsheet (`core/export`), saved by the browser. Offered when the entity declares its export
13
- * (`entity(…, { export: "/invoices/export" })`); `null` otherwise.
11
+ * spreadsheet (`core/export`), saved by the browser. Offered when the entity has an `export`
12
+ * operation (its contract publishes one); `null` otherwise.
14
13
  *
15
14
  * Context: the server writes the export (JSON Lines, read as it streams: no page of the list is
16
15
  * fetched to build it, so a million rows is the server's work, not the page's), and this writes
17
16
  * what a person opens: the model's words as headers, the region's separator and decimal.
18
17
  */
19
18
  export function useListExport(listing, enabled) {
20
- const { transport, locale } = useFramework();
19
+ const { operations, locale } = useFramework();
21
20
  const toast = useToastIfAny();
22
- const entity = listing.entity;
23
- if (!enabled || entity.export === undefined)
21
+ const exporting = listing.entity.operations.export;
22
+ if (!enabled || exporting === undefined)
24
23
  return null;
25
- const path = entity.export;
26
24
  return {
27
25
  id: "export",
28
26
  label: frameworkCopy().list.export,
@@ -31,7 +29,8 @@ export function useListExport(listing, enabled) {
31
29
  onSelect: () => {
32
30
  // The question on screen without its page: every record it keeps, in its order.
33
31
  const { pagination: _page, ...asked } = listing.question;
34
- void downloadRoute(transport, exportRoute(path, asked, "jsonl"))
32
+ void operations
33
+ .call(exporting, { ...listing.input, criteria: asked, format: "jsonl" })
35
34
  .then((download) => download.blob())
36
35
  .then((blob) => blob.text())
37
36
  .then((text) => {
@@ -1,4 +1,4 @@
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
3
  import { type ListDefinition } from "../../core/list.js";
4
4
  import type { DockMoment, PickerItem, RecordCard, RowOf, Tone } from "@sincpro/web-ui";
@@ -106,11 +106,11 @@ export type PartOf<V> = unknown extends V ? AnyRecord : NonNullable<V> extends {
106
106
  export type PartLooks<T> = {
107
107
  readonly [K in keyof T & string as [PartOf<T[K]>] extends [never] ? never : K]?: PartLook<PartOf<T[K]>>;
108
108
  };
109
- export type Presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers> = Entity<T, C, A> & {
109
+ export type Presented<T extends AnyRecord, O extends EntityOperations = EntityOperations> = Entity<T, O> & {
110
110
  readonly presentation: Presentation<T>;
111
111
  };
112
112
  /** The entity with how its records look: pass it wherever an entity goes. */
113
- export declare function presented<T extends AnyRecord, C extends CommandBodies = CommandBodies, A extends CommandAnswers = CommandAnswers>(entity: Entity<T, C, A>, presentation: Presentation<T>): Presented<T, C, A>;
113
+ export declare function presented<T extends AnyRecord, O extends EntityOperations = EntityOperations>(entity: Entity<T, O>, presentation: Presentation<T>): Presented<T, O>;
114
114
  /** The presentation an entity — or the entity of a named list — was declared with; none is `{}`. */
115
115
  export declare function presentationOf<T extends AnyRecord>(source: Entity<T> | ListDefinition<T>): Presentation<T>;
116
116
  /** How the parts an entity's records hold under `name` look; `{}` when it declares nothing. */
@@ -1,6 +1,6 @@
1
- import { type Entity, type MetaStore, type Selection, type Transport } from "@sincpro/client-framework";
1
+ import { type Entity, type MetaStore, type OperationTransport, type Selection } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Expression, type Meta } from "@sincpro/criteria";
3
- import type { NameBook } from "../../core/names.js";
3
+ import { type NameBook } from "../../core/names.js";
4
4
  import type { BrowseRecords, LoadModel, SearchRecords, ToastSpec } from "@sincpro/web-ui";
5
5
  import { type ReactNode } from "react";
6
6
  /** A record as a person picks it by name: its key, its name, and what tells it apart. */
@@ -15,7 +15,7 @@ export type Choice = {
15
15
  * template and a short page), each record whole, read as its name and, beside it, what tells it
16
16
  * apart — the entity's `option` look, else its summary's description or type. Never its key.
17
17
  *
18
- * await findChoices(transport, clientes, clienteMeta, "/clientes", "andres", "es")
18
+ * await findChoices(operations, clientes, clienteMeta, "andres", "es")
19
19
  * -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
20
20
  *
21
21
  * Context: `matching` asks for references (identity and display), and the `option` look and the
@@ -23,11 +23,14 @@ export type Choice = {
23
23
  * backend (#48). The question keeps `matching`'s template and its page, and brings each record
24
24
  * whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
25
25
  */
26
- export declare function findChoices<T extends AnyRecord>(transport: Transport, entity: Entity<T>, meta: Meta, route: string, text: string, locale: string | undefined, signal?: AbortSignal): Promise<Choice[]>;
27
- /** What the searches of records ask of the framework: its transport, its definitions, its
28
- * names and its entities — `useFramework()`'s. */
26
+ export declare function findChoices<T extends AnyRecord>(operations: OperationTransport, entity: Entity<T>, meta: Meta, text: string, locale: string | undefined, options?: {
27
+ signal?: AbortSignal;
28
+ input?: Readonly<Record<string, unknown>>;
29
+ }): Promise<Choice[]>;
30
+ /** What the searches of records ask of the framework: the screens' operations, its definitions,
31
+ * its names and its entities — `useFramework()`'s. */
29
32
  export type FrameworkReads = {
30
- transport: Transport;
33
+ operations: OperationTransport;
31
34
  metas: MetaStore;
32
35
  names: NameBook;
33
36
  entities: readonly Entity[];
@@ -41,10 +44,10 @@ export type FrameworkReads = {
41
44
  * application did not declare finds nothing — the bar still offers the relation's text.
42
45
  * 2. Keys instead of a text (a filter read back from a link): their names, through the book every
43
46
  * cell asks (`NameBook`: one request per entity, kept) — a key without one reads as itself.
44
- * 3. Else the entity's literal search (`findChoices`), its definition known or read once.
47
+ * 3. Else the entity's literal search (`findChoices`), by its definition (the contract's, `metas`).
45
48
  */
46
49
  export declare function recordsSearch(framework: FrameworkReads, locale: string | undefined): SearchRecords;
47
- /** `recordsSearch` over the framework's context: the screens' transport, its definitions and
50
+ /** `recordsSearch` over the framework's context: the screens' operations, its definitions and
48
51
  * its names, in the provider's language. */
49
52
  export declare function useSearchRecords(): SearchRecords;
50
53
  /**
@@ -56,7 +59,7 @@ export declare function useSearchRecords(): SearchRecords;
56
59
  *
57
60
  * 1. From the root's definition, each name of the path is a relation of the model before it.
58
61
  * 2. Its model is the relation's own definition, when the server published it inside; else its
59
- * entity's (`entityFor` by the aggregate it names), known or read once.
62
+ * entity's (`entityFor` by the aggregate it names), as the screens know it (`metas`).
60
63
  * Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
61
64
  * the model lacks, a relation to an entity the application did not declare — is refused.
62
65
  */
@@ -1,10 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { keysOf, listRoute, SelectionTooLarge, } from "@sincpro/client-framework";
3
+ import { keysOf, readPage, SelectionTooLarge, } from "@sincpro/client-framework";
4
4
  import { matching } from "@sincpro/criteria";
5
5
  import { frameworkCopy } from "../../core/copy.js";
6
6
  import { explain } from "../../core/explain.js";
7
7
  import { lookupOf } from "../../core/lookup.js";
8
+ import { searchedAlone } from "../../core/names.js";
8
9
  import { entityFor } from "../../core/relation.js";
9
10
  import { summaryOf } from "../../core/summary.js";
10
11
  import { useFramework } from "../../react/context.js";
@@ -18,7 +19,7 @@ import { createContext, useContext, useMemo } from "react";
18
19
  * template and a short page), each record whole, read as its name and, beside it, what tells it
19
20
  * apart — the entity's `option` look, else its summary's description or type. Never its key.
20
21
  *
21
- * await findChoices(transport, clientes, clienteMeta, "/clientes", "andres", "es")
22
+ * await findChoices(operations, clientes, clienteMeta, "andres", "es")
22
23
  * -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
23
24
  *
24
25
  * Context: `matching` asks for references (identity and display), and the `option` look and the
@@ -26,9 +27,9 @@ import { createContext, useContext, useMemo } from "react";
26
27
  * backend (#48). The question keeps `matching`'s template and its page, and brings each record
27
28
  * whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
28
29
  */
29
- export async function findChoices(transport, entity, meta, route, text, locale, signal) {
30
+ export async function findChoices(operations, entity, meta, text, locale, options = {}) {
30
31
  const { specification: _reference, ...question } = matching(meta, text);
31
- const page = await transport.list(route, question, signal);
32
+ const page = await readPage(operations, entity, question, { ...options, meta });
32
33
  const look = presentationOf(entity).option;
33
34
  return lookupOf(meta, page.rows, entity.summary).map((one) => {
34
35
  const own = look === undefined || one.record === undefined ? {} : look(one.record);
@@ -46,30 +47,6 @@ export async function findChoices(transport, entity, meta, route, text, locale,
46
47
  };
47
48
  });
48
49
  }
49
- /** Where an entity is listed, or `undefined` when only under another record (`/{id}/lines`). */
50
- function routeOf(entity) {
51
- try {
52
- return listRoute(entity.list);
53
- }
54
- catch {
55
- return undefined;
56
- }
57
- }
58
- /** An entity's definition: known, or read once (one row) and kept for every place after. */
59
- async function metaOf(framework, entity, signal) {
60
- const known = framework.metas.get(entity.key);
61
- if (known !== undefined)
62
- return known;
63
- const route = routeOf(entity);
64
- if (route === undefined)
65
- return undefined;
66
- const read = (await framework.transport.list(route, { pagination: { limit: 1 } }, signal))
67
- .meta;
68
- if (read == null)
69
- return undefined;
70
- framework.metas.set(entity.key, read);
71
- return read;
72
- }
73
50
  /**
74
51
  * web-ui's `searchRecords` (2.7) answered by the framework: the records of a relation the search
75
52
  * bar unfolds and the criteria builder picks — «andres» → the customers that match —, each
@@ -79,7 +56,7 @@ async function metaOf(framework, entity, signal) {
79
56
  * application did not declare finds nothing — the bar still offers the relation's text.
80
57
  * 2. Keys instead of a text (a filter read back from a link): their names, through the book every
81
58
  * cell asks (`NameBook`: one request per entity, kept) — a key without one reads as itself.
82
- * 3. Else the entity's literal search (`findChoices`), its definition known or read once.
59
+ * 3. Else the entity's literal search (`findChoices`), by its definition (the contract's, `metas`).
83
60
  */
84
61
  export function recordsSearch(framework, locale) {
85
62
  return async ({ relation, text, keys, signal }) => {
@@ -91,11 +68,14 @@ export function recordsSearch(framework, locale) {
91
68
  id: key,
92
69
  name: (await framework.names.nameOf(entity, String(key))) ?? String(key),
93
70
  })));
94
- const route = routeOf(entity);
95
- const meta = await metaOf(framework, entity, signal);
96
- if (route === undefined || meta === undefined)
71
+ if (!searchedAlone(entity))
72
+ return [];
73
+ const meta = framework.metas.get(entity.key);
74
+ if (meta === undefined)
97
75
  return [];
98
- const choices = await findChoices(framework.transport, entity, meta, route, text, locale, signal);
76
+ const choices = await findChoices(framework.operations, entity, meta, text, locale, {
77
+ signal,
78
+ });
99
79
  return choices.map((one) => ({
100
80
  id: one.id,
101
81
  name: one.name,
@@ -103,11 +83,11 @@ export function recordsSearch(framework, locale) {
103
83
  }));
104
84
  };
105
85
  }
106
- /** `recordsSearch` over the framework's context: the screens' transport, its definitions and
86
+ /** `recordsSearch` over the framework's context: the screens' operations, its definitions and
107
87
  * its names, in the provider's language. */
108
88
  export function useSearchRecords() {
109
- const { transport, metas, names, entities, locale } = useFramework();
110
- return useMemo(() => recordsSearch({ transport, metas, names, entities }, locale), [transport, metas, names, entities, locale]);
89
+ const { operations, metas, names, entities, locale } = useFramework();
90
+ return useMemo(() => recordsSearch({ operations, metas, names, entities }, locale), [operations, metas, names, entities, locale]);
111
91
  }
112
92
  /**
113
93
  * web-ui's `loadModel` (2.8) answered by the framework: the model at the end of a path of
@@ -118,7 +98,7 @@ export function useSearchRecords() {
118
98
  *
119
99
  * 1. From the root's definition, each name of the path is a relation of the model before it.
120
100
  * 2. Its model is the relation's own definition, when the server published it inside; else its
121
- * entity's (`entityFor` by the aggregate it names), known or read once.
101
+ * entity's (`entityFor` by the aggregate it names), as the screens know it (`metas`).
122
102
  * Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
123
103
  * the model lacks, a relation to an entity the application did not declare — is refused.
124
104
  */
@@ -132,7 +112,7 @@ export function modelLoader(framework, root, locale) {
132
112
  const entity = typeof field.relation === "string"
133
113
  ? entityFor(framework.entities, field.relation, framework.metas.get)
134
114
  : undefined;
135
- return entity === undefined ? undefined : metaOf(framework, entity);
115
+ return entity === undefined ? undefined : framework.metas.get(entity.key);
136
116
  };
137
117
  return async (path) => {
138
118
  let meta = root;
@@ -147,10 +127,10 @@ export function modelLoader(framework, root, locale) {
147
127
  }
148
128
  /** `modelLoader` over the framework's context, from a list's definition (none yet: none). */
149
129
  export function useLoadModel(root) {
150
- const { transport, metas, names, entities, locale } = useFramework();
130
+ const { operations, metas, names, entities, locale } = useFramework();
151
131
  return useMemo(() => root == null
152
132
  ? undefined
153
- : modelLoader({ transport, metas, names, entities }, root, locale), [root, transport, metas, names, entities, locale]);
133
+ : modelLoader({ operations, metas, names, entities }, root, locale), [root, operations, metas, names, entities, locale]);
154
134
  }
155
135
  /**
156
136
  * web-ui's `browseRecords` (2.8) answered by the framework: «Buscar más…» under the records of a
@@ -182,11 +162,10 @@ export function recordsBrowser(framework, open, names, refused) {
182
162
  keys,
183
163
  signal: new AbortController().signal,
184
164
  }).then(browse.choose, refused);
185
- const route = routeOf(entity);
186
- if (browse.many && open.chooseMany !== undefined && route !== undefined)
165
+ if (browse.many && open.chooseMany !== undefined && searchedAlone(entity))
187
166
  open.chooseMany(entity, (selection) => void keysOf(selection, {
188
- transport: framework.transport,
189
- route,
167
+ transport: framework.operations,
168
+ entity,
190
169
  identity,
191
170
  limit: BATCH_LIMIT,
192
171
  }).then(answer, refused), browse.text, scope);