@sincpro/web-framework 3.5.0 → 3.6.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 (41) hide show
  1. package/README.md +2 -0
  2. package/dist/core/command.d.ts +16 -0
  3. package/dist/core/command.js +17 -0
  4. package/dist/core/copy.d.ts +16 -0
  5. package/dist/core/copy.js +26 -0
  6. package/dist/core/history.d.ts +16 -4
  7. package/dist/core/history.js +20 -17
  8. package/dist/core/index.d.ts +4 -3
  9. package/dist/core/index.js +3 -2
  10. package/dist/core/list.d.ts +12 -0
  11. package/dist/core/list.js +14 -0
  12. package/dist/core/present.d.ts +12 -0
  13. package/dist/core/present.js +39 -0
  14. package/dist/react/index.d.ts +2 -0
  15. package/dist/react/index.js +2 -0
  16. package/dist/react/useBatchCommand.d.ts +50 -0
  17. package/dist/react/useBatchCommand.js +124 -0
  18. package/dist/react/useCommand.js +3 -4
  19. package/dist/react/useSelection.d.ts +37 -0
  20. package/dist/react/useSelection.js +40 -0
  21. package/dist/web/index.d.ts +2 -0
  22. package/dist/web/index.js +2 -0
  23. package/dist/web/list/BatchProgress.d.ts +16 -0
  24. package/dist/web/list/BatchProgress.js +40 -0
  25. package/dist/web/list/EntityList.d.ts +12 -6
  26. package/dist/web/list/EntityList.js +37 -22
  27. package/dist/web/list/EntitySearchBar.d.ts +9 -0
  28. package/dist/web/list/EntitySearchBar.js +15 -5
  29. package/dist/web/list/pivot.d.ts +5 -1
  30. package/dist/web/list/pivot.js +28 -11
  31. package/dist/web/list/records.d.ts +100 -0
  32. package/dist/web/list/records.js +219 -0
  33. package/dist/web/list/search.d.ts +0 -17
  34. package/dist/web/list/search.js +33 -5
  35. package/dist/web/record/EntityTags.d.ts +5 -2
  36. package/dist/web/record/EntityTags.js +34 -12
  37. package/dist/web/record/opening.d.ts +6 -2
  38. package/dist/web/workspace/SincproApp.js +13 -2
  39. package/dist/web/workspace/composer.d.ts +1 -1
  40. package/dist/web/workspace/composer.js +23 -25
  41. package/package.json +9 -9
@@ -1,5 +1,6 @@
1
1
  "use client";
2
- import { bodyFor, pathFor, retryKeys, } from "@sincpro/client-framework";
2
+ import { retryKeys, } from "@sincpro/client-framework";
3
+ import { sendRoute } from "../core/command.js";
3
4
  import { useFramework } from "./context.js";
4
5
  import { useCallback, useEffect, useRef, useState } from "react";
5
6
  export function useCommand(entity, name) {
@@ -35,10 +36,8 @@ export function useRouteCommand(route, owner) {
35
36
  setBusy(true);
36
37
  setError(null);
37
38
  const idempotencyKey = gesture.keyFor({ id, body });
38
- // A Command whose body names its record (`target`) gets the id there.
39
- const sent = bodyFor(route, id, body);
40
39
  try {
41
- const answer = await transport.send(route.method, pathFor(route, id, sent), sent, undefined, { idempotencyKey });
40
+ const answer = await sendRoute(transport, route, id, body, { idempotencyKey });
42
41
  gesture.settle(null);
43
42
  return answer;
44
43
  }
@@ -0,0 +1,37 @@
1
+ import { type Selection } from "@sincpro/client-framework";
2
+ import type { AnyRecord } from "@sincpro/criteria";
3
+ import type { Listing } from "./useListing.js";
4
+ /**
5
+ * What is chosen in a list, and how a screen changes it — one state, reachable from outside the
6
+ * list: a bulk action reads it, a screen sets it, a chooser answers it.
7
+ */
8
+ export type ListSelection<T extends AnyRecord = AnyRecord> = {
9
+ /** The value (@sincpro/client-framework's `Selection`): these keys, or every record the
10
+ * list's question matches but some. */
11
+ selection: Selection<T>;
12
+ /** How many are chosen; `null` when «all that match» has no exact count. */
13
+ size: number | null;
14
+ isChosen: (key: string) => boolean;
15
+ toggle: (key: string) => void;
16
+ /** Every record the list's question matches, as the server counted them. */
17
+ chooseAllMatching: () => void;
18
+ clear: () => void;
19
+ set: (selection: Selection<T>) => void;
20
+ };
21
+ /**
22
+ * The selection of a list: ticking chooses keys, «Elegir los 187 que coinciden» chooses the
23
+ * list's question — its scope, search and filter — with the total the server counted.
24
+ *
25
+ * const listing = useListing(invoices);
26
+ * const chosen = useSelection(listing);
27
+ * <EntityList listing={listing} selectable selection={chosen} />
28
+ * <ConfirmAll selection={chosen.selection} />
29
+ *
30
+ * Context: `EntityList` kept what was ticked in its own state — the page's keys, reachable by
31
+ * nothing outside it. The value is client-framework's, the same a phone or a script holds; this
32
+ * is only where a screen keeps it.
33
+ *
34
+ * Another question is another set: a selection made under one filter is forgotten when the
35
+ * list's question changes — what was chosen is not among what is on screen anymore.
36
+ */
37
+ export declare function useSelection<T extends AnyRecord>(listing: Listing<T>): ListSelection<T>;
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { allMatching, isChosen, NOTHING_CHOSEN, sizeOf, toggled, } from "@sincpro/client-framework";
3
+ import { useCallback, useMemo, useState } from "react";
4
+ /**
5
+ * The selection of a list: ticking chooses keys, «Elegir los 187 que coinciden» chooses the
6
+ * list's question — its scope, search and filter — with the total the server counted.
7
+ *
8
+ * const listing = useListing(invoices);
9
+ * const chosen = useSelection(listing);
10
+ * <EntityList listing={listing} selectable selection={chosen} />
11
+ * <ConfirmAll selection={chosen.selection} />
12
+ *
13
+ * Context: `EntityList` kept what was ticked in its own state — the page's keys, reachable by
14
+ * nothing outside it. The value is client-framework's, the same a phone or a script holds; this
15
+ * is only where a screen keeps it.
16
+ *
17
+ * Another question is another set: a selection made under one filter is forgotten when the
18
+ * list's question changes — what was chosen is not among what is on screen anymore.
19
+ */
20
+ export function useSelection(listing) {
21
+ const asked = listing.question.selection;
22
+ const question = useMemo(() => JSON.stringify(asked ?? null), [asked]);
23
+ const [held, setHeld] = useState({
24
+ question,
25
+ selection: NOTHING_CHOSEN,
26
+ });
27
+ // Held under the question it was made for: under another one, nothing is chosen.
28
+ const selection = held.question === question ? held.selection : NOTHING_CHOSEN;
29
+ const set = useCallback((next) => setHeld({ question, selection: next }), [question]);
30
+ const total = listing.count?.exact === true ? listing.count.value : null;
31
+ return {
32
+ selection,
33
+ size: sizeOf(selection),
34
+ isChosen: (key) => isChosen(selection, key),
35
+ toggle: (key) => set(toggled(selection, key)),
36
+ chooseAllMatching: () => set(allMatching(asked, total)),
37
+ clear: () => set(NOTHING_CHOSEN),
38
+ set,
39
+ };
40
+ }
@@ -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 { BatchProgress } from "./list/BatchProgress.js";
4
5
  export { aggregateOf, type ColumnOptions, columnsOf, } from "./list/columns.js";
5
6
  export { type EntityFace, EntityList, type EntityListProps, type View, } from "./list/EntityList.js";
6
7
  export { EntitySearchBar } from "./list/EntitySearchBar.js";
@@ -8,6 +9,7 @@ export { groupableOf, pilesOf } from "./list/groups.js";
8
9
  export { OpenInMenu } from "./list/openIn.js";
9
10
  export { pivotOf } from "./list/pivot.js";
10
11
  export { type CardLook, type ChoiceTones, type OptionLook, type PartLook, partLookOf, type PartLooks, type PartOf, type Presentation, presentationOf, type Presented, presented, type RowLook, tonesOver, } from "./list/presentation.js";
12
+ export { type Choice, type Chooser, findChoices, type FrameworkReads, modelLoader, recordsBrowser, RecordsBrowserProvider, recordsSearch, refusalNotice, useLoadModel, useRecordsBrowser, useSearchRecords, } from "./list/records.js";
11
13
  export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
12
14
  export { facetsOf, modelOf } from "./list/search.js";
13
15
  export { type ActionDialog, type Asked, } from "./record/ActionButton.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 { BatchProgress } from "./list/BatchProgress.js";
4
5
  export { aggregateOf, columnsOf, } from "./list/columns.js";
5
6
  export { EntityList, } from "./list/EntityList.js";
6
7
  export { EntitySearchBar } from "./list/EntitySearchBar.js";
@@ -8,6 +9,7 @@ export { groupableOf, pilesOf } from "./list/groups.js";
8
9
  export { OpenInMenu } from "./list/openIn.js";
9
10
  export { pivotOf } from "./list/pivot.js";
10
11
  export { partLookOf, presentationOf, presented, tonesOver, } from "./list/presentation.js";
12
+ export { findChoices, modelLoader, recordsBrowser, RecordsBrowserProvider, recordsSearch, refusalNotice, useLoadModel, useRecordsBrowser, useSearchRecords, } from "./list/records.js";
11
13
  export { useRowCommands, } from "./list/rowCommands.js";
12
14
  export { facetsOf, modelOf } from "./list/search.js";
13
15
  export {} from "./record/ActionButton.js";
@@ -0,0 +1,16 @@
1
+ import type { BatchCommandState } from "../../react/useBatchCommand.js";
2
+ /**
3
+ * A Command running once per record, drawn: how far it is while it runs, then what became of
4
+ * each — «2 hechos · 1 falló», every failure named by its record and its reason, «Reintentar los
5
+ * que fallaron». Before it starts, why it did not: too many chosen.
6
+ *
7
+ * const confirm = useBatchCommand(invoices, "confirm");
8
+ * <BatchProgress batch={confirm} />
9
+ *
10
+ * Context: a batch's result is one outcome per record, and a person needs the ones that failed —
11
+ * by name, with the server's reason —, not a count. web-ui draws (`ProgressBar`, `Callout`); the
12
+ * words are the framework's copy, the reasons the server's (`explain`).
13
+ */
14
+ export declare function BatchProgress<R>({ batch, }: {
15
+ batch: Pick<BatchCommandState<R>, "running" | "progress" | "result" | "error" | "retry" | "stop" | "reset">;
16
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { SelectionTooLarge } from "@sincpro/client-framework";
4
+ import { frameworkCopy } from "../../core/copy.js";
5
+ import { explain } from "../../core/explain.js";
6
+ import { Button, Callout, ProgressBar } from "@sincpro/web-ui";
7
+ /**
8
+ * A Command running once per record, drawn: how far it is while it runs, then what became of
9
+ * each — «2 hechos · 1 falló», every failure named by its record and its reason, «Reintentar los
10
+ * que fallaron». Before it starts, why it did not: too many chosen.
11
+ *
12
+ * const confirm = useBatchCommand(invoices, "confirm");
13
+ * <BatchProgress batch={confirm} />
14
+ *
15
+ * Context: a batch's result is one outcome per record, and a person needs the ones that failed —
16
+ * by name, with the server's reason —, not a count. web-ui draws (`ProgressBar`, `Callout`); the
17
+ * words are the framework's copy, the reasons the server's (`explain`).
18
+ */
19
+ export function BatchProgress({ batch, }) {
20
+ const copy = frameworkCopy().batch;
21
+ const { running, progress, result, error } = batch;
22
+ if (running && progress !== null)
23
+ return (_jsxs("div", { className: "flex items-center gap-3", children: [_jsx(ProgressBar, { label: copy.running, value: progress.settled, maxValue: progress.total, valueLabel: copy.progress(progress.settled, progress.total), tone: "brand" }), _jsx(Button, { role: "ghost", size: "sm", onClick: batch.stop, children: copy.stop })] }));
24
+ if (error instanceof SelectionTooLarge)
25
+ return (_jsx(Callout, { tone: "warn", onDismiss: batch.reset, children: copy.tooMany(error.size, error.limit) }));
26
+ if (error !== null && error !== undefined) {
27
+ const { heading, sentence } = explain(error);
28
+ return (_jsx(Callout, { tone: "bad", title: heading, onDismiss: batch.reset, children: sentence }));
29
+ }
30
+ if (result === null || result.outcomes.length === 0)
31
+ return null;
32
+ const left = result.outcomes.filter((one) => one.status !== "done");
33
+ return (_jsx(Callout, { tone: left.length === 0 ? "good" : result.done === 0 ? "bad" : "warn", title: copy.outcome(result.done, result.failed, result.skipped), onDismiss: batch.reset, ...(left.length === 0
34
+ ? {}
35
+ : {
36
+ action: (_jsx(Button, { role: "secondary", size: "sm", onClick: () => void batch.retry(), children: copy.retry })),
37
+ }), children: left.length === 0 ? null : (_jsx("ul", { className: "flex flex-col gap-1", children: left
38
+ .filter((one) => one.status === "failed")
39
+ .map((one) => (_jsxs("li", { children: [_jsx("span", { className: "font-medium", children: one.item }), " — ", explain(one.error).sentence] }, one.item))) })) }));
40
+ }
@@ -1,8 +1,9 @@
1
1
  import { type CommandBodies } from "@sincpro/client-framework";
2
2
  import { type AnyRecord } from "@sincpro/criteria";
3
3
  import { type WorkspaceApi } from "@sincpro/web-composer";
4
- import type { GroupLevel, NamedFilter } from "../../core/list.js";
4
+ import { type GroupLevel, type NamedFilter } from "../../core/list.js";
5
5
  import type { Listing } from "../../react/useListing.js";
6
+ import { type ListSelection } from "../../react/useSelection.js";
6
7
  import { type RowCommand } from "./rowCommands.js";
7
8
  import { type ListCrumb, type ListPresentProps, type ListSet, type OpenTarget, type RowAction } from "@sincpro/web-ui";
8
9
  import { type ReactNode } from "react";
@@ -96,12 +97,17 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
96
97
  * Without it, the list definition's, else every one the model does. */
97
98
  groupable?: readonly string[];
98
99
  /**
99
- * Rows can be ticked. With `api`, what is ticked is PUBLISHED to the workspace
100
- * (`api.select`): a panel beside it follows the selection without knowing this list.
100
+ * Rows can be ticked — and, past the page, «Elegir los 187 que coinciden». With `api`, what is
101
+ * chosen is PUBLISHED to the workspace (`api.select`): a panel beside it follows the selection
102
+ * without knowing this list.
101
103
  */
102
104
  selectable?: boolean;
103
- /** What to do with what is ticked: drawn in the bar while something is. */
104
- selectionActions?: ReactNode;
105
+ /** The selection, held by the screen (`useSelection(listing)`): read and set from outside the
106
+ * list. Without it the list holds its own. */
107
+ selection?: ListSelection<T>;
108
+ /** What to do with what is chosen, drawn in the bar while something is — handed the selection
109
+ * to act on it (`useBatchCommand`). */
110
+ selectionActions?: ReactNode | ((selection: ListSelection<T>) => ReactNode);
105
111
  /** The list is a FIELD of a record — its lines, its members — and not a screen. */
106
112
  embedded?: boolean;
107
113
  /**
@@ -135,4 +141,4 @@ export type EntityFace<T> = {
135
141
  render: (set: ListSet<T>) => ReactNode;
136
142
  };
137
143
  export type View = "table" | "rows" | "board" | "sheet" | "pivot";
138
- export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
144
+ export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable, selection: held, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
@@ -5,11 +5,13 @@ import { nameOf } from "@sincpro/criteria";
5
5
  import { RecordLink, useCrumbs, usePhone } from "@sincpro/web-composer";
6
6
  import { frameworkCopy } from "../../core/copy.js";
7
7
  import { explain } from "../../core/explain.js";
8
+ import { choosesMany, } from "../../core/list.js";
8
9
  import { textOf, viewOf } from "../../core/present.js";
9
10
  import { summaryFieldsOf } from "../../core/summary.js";
10
11
  import { useFramework } from "../../react/context.js";
11
12
  import { useGroups } from "../../react/useGroups.js";
12
13
  import { usePivot } from "../../react/usePivot.js";
14
+ import { useSelection } from "../../react/useSelection.js";
13
15
  import { columnsOf } from "./columns.js";
14
16
  import { EntitySearchBar } from "./EntitySearchBar.js";
15
17
  import { pilesOf } from "./groups.js";
@@ -33,7 +35,7 @@ const TRAILS = 50;
33
35
  const NO_COMMANDS = [];
34
36
  /** What a list offers when nobody said: every face that needs no configuration. */
35
37
  const EVERY_VIEW = ["table", "rows", "board", "sheet"];
36
- export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
38
+ export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable = false, selection: held, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
37
39
  // A named list (`defineList`) brings its own columns, filters, faces and words; what the
38
40
  // screen passes wins.
39
41
  const definition = listing.definition;
@@ -67,6 +69,12 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
67
69
  }, []);
68
70
  // Opened by `api.pick` (`entity.chooserRef()`): a row ANSWERS whoever asked, it does not open.
69
71
  const choosing = api?.self.params?.[PICK_PARAM] !== undefined;
72
+ // Asked for SEVERAL (`CHOOSE_MANY`, a many2many's «Buscar más…»): a row press ticks it, and
73
+ // «Agregar (N)» answers what was chosen — the keys, or every record the list matches.
74
+ const choosingMany = choosing && choosesMany(api?.choosing?.question);
75
+ const own = useSelection(listing);
76
+ const chosen = held ?? own;
77
+ const ticking = selectable || choosingMany;
70
78
  // The record opened from a row knows the page it came from: «3 / 64» and its neighbours.
71
79
  const { trails, dateStyle } = useFramework();
72
80
  const trailKey = `trail:${useId()}`;
@@ -114,9 +122,11 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
114
122
  const opening = onOpen ??
115
123
  (api === undefined
116
124
  ? undefined
117
- : choosing
118
- ? (row) => api.answer(listing.entity.ref(idOf(row)))
119
- : openWithTrail);
125
+ : choosingMany
126
+ ? (row) => chosen.toggle(idOf(row))
127
+ : choosing
128
+ ? (row) => api.answer(listing.entity.ref(idOf(row)))
129
+ : openWithTrail);
120
130
  const creating = create &&
121
131
  api !== undefined &&
122
132
  !choosing &&
@@ -163,25 +173,30 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
163
173
  const following = useCrumbs(api ?? NO_WORKSPACE);
164
174
  usePhone(api ?? NO_WORKSPACE); // where a row opens follows the mode (`targetsFor`)
165
175
  const trail = crumbs ?? (embedded || api === undefined ? undefined : following);
166
- const [ticked, setTicked] = useState(() => new Set());
167
- const tick = (next) => {
168
- setTicked(next);
169
- api?.select([...next].map((id) => listing.entity.ref(id)));
170
- };
171
- const selection = selectable
176
+ // The workspace hears what is chosen: the keys, or — «all that match» — the ones on screen.
177
+ const published = (chosen.selection.by === "keys"
178
+ ? chosen.selection.keys
179
+ : listing.rows.map((row) => idOf(row)).filter((id) => chosen.isChosen(id))).join("\u0000");
180
+ const heard = useRef(published);
181
+ useEffect(() => {
182
+ if (!ticking || heard.current === published)
183
+ return;
184
+ heard.current = published;
185
+ api?.select(published === "" ? [] : published.split("\u0000").map((id) => listing.entity.ref(id)));
186
+ }, [api, ticking, published, listing.entity]);
187
+ // «Elegir los 187 que coinciden» only past the page, and only with the server's exact count.
188
+ const total = listing.count?.exact === true ? listing.count.value : null;
189
+ const onChosen = choosingMany ? (_jsx(Button, { role: "primary", size: "sm", onClick: () => api?.answer(chosen.selection), children: frameworkCopy().picker.addChosen(chosen.size) })) : typeof selectionActions === "function" ? (selectionActions(chosen)) : (selectionActions);
190
+ const selection = ticking
172
191
  ? {
173
- has: (id) => ticked.has(id),
174
- toggle: (id) => {
175
- const next = new Set(ticked);
176
- if (next.has(id))
177
- next.delete(id);
178
- else
179
- next.add(id);
180
- tick(next);
181
- },
182
- count: ticked.size,
183
- clear: () => tick(new Set()),
184
- ...(selectionActions === undefined ? {} : { actions: selectionActions }),
192
+ has: chosen.isChosen,
193
+ toggle: chosen.toggle,
194
+ count: chosen.size ?? 0,
195
+ clear: chosen.clear,
196
+ ...(total !== null && total > listing.rows.length
197
+ ? { matching: { total, onSelect: chosen.chooseAllMatching } }
198
+ : {}),
199
+ ...(onChosen === undefined ? {} : { actions: onChosen }),
185
200
  }
186
201
  : undefined;
187
202
  // Rebuilt only when what it reads changes: a new set of columns on every render redraws
@@ -15,6 +15,15 @@ import type { Listing } from "../../react/useListing.js";
15
15
  * - «search by name»: facets are the fields the screen names (`facets`), else the ones the
16
16
  * entity's search template names — never every text field;
17
17
  * - a typed question («total > 5000») is checked against each field's operators;
18
+ * - a relation unfolds into its RECORDS that match what was typed — «andres» → the customers
19
+ * —, chosen by key and read by name («Cliente: Andrés Pérez»), and an enum into its words
20
+ * («Estado: Pagada», sent as `paid`): the related entity's literal search
21
+ * (`useSearchRecords`), unless the application put its own in a web-ui `SearchProvider`;
22
+ * inside a workspace, «Buscar más…» under them opens the entity's list to choose
23
+ * (`useRecordsBrowser`) — the bar's, never the builder's: the builder is a modal dialog, and
24
+ * what opens outside one cannot be used;
25
+ * - the builder walks relations — «Cliente › País» — through the models along the path
26
+ * (`useLoadModel`), and picks the related records themselves;
18
27
  * - a named filter is one click; the builder writes what nobody foresaw (all/any/not);
19
28
  * - everything put becomes ONE `selection` the SERVER answers (`listing.filter`) — web-ui
20
29
  * writes it in criteria's own shape, a filter through a relation included;
@@ -3,8 +3,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  import { matching } from "@sincpro/criteria";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
5
  import { groupableOf } from "./groups.js";
6
+ import { useLoadModel, useRecordsBrowser, useSearchRecords, } from "./records.js";
6
7
  import { facetsOf, modelOf } from "./search.js";
7
- import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, selectionOf, toggleNamed, useGroupingControl, useUiCopy, } from "@sincpro/web-ui";
8
+ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, selectionOf, toggleNamed, useGroupingControl, useSearchSettings, useUiCopy, } from "@sincpro/web-ui";
8
9
  import { useEffect, useMemo, useRef, useState } from "react";
9
10
  /** No grouping: one constant, so the control is not handed a new array on every render. */
10
11
  const NO_LEVELS = [];
@@ -25,6 +26,11 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
25
26
  : undefined, [meta, locale, facets]);
26
27
  const groupable = useMemo(() => groupableOf(meta, locale, only), [meta, locale, only]);
27
28
  const ui = useUiCopy();
29
+ // The application's own search of records wins; the framework's is the default.
30
+ const framework = useSearchRecords();
31
+ const searchRecords = useSearchSettings().searchRecords ?? framework;
32
+ const browseRecords = useRecordsBrowser();
33
+ const loadModel = useLoadModel(meta);
28
34
  const seeded = useRef(false);
29
35
  useEffect(() => {
30
36
  if (seeded.current || seed === undefined || seed === "" || meta?.search == null)
@@ -51,7 +57,7 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
51
57
  };
52
58
  // What the bar holds, as one selection: what the builder opens on.
53
59
  const current = selectionOf(put);
54
- return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, ...(filters.length === 0
60
+ return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, searchRecords: searchRecords, ...(browseRecords === null ? {} : { browseRecords }), ...(filters.length === 0
55
61
  ? {}
56
62
  : {
57
63
  filters: [
@@ -78,7 +84,7 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
78
84
  ? {}
79
85
  : {
80
86
  literal: (text) => matching(meta, text).selection ?? null,
81
- }) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, ...(current === undefined && listing.order.length === 0
87
+ }) }), building ? (_jsx(Dialog, { open: true, width: "lg", title: copy.builder, onClose: () => setBuilding(false), children: _jsx(CriteriaBuilder, { model: model, searchRecords: searchRecords, ...(loadModel === undefined ? {} : { loadModel }), ...(current === undefined && listing.order.length === 0
82
88
  ? {}
83
89
  : {
84
90
  initial: {
@@ -92,10 +98,14 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
92
98
  })),
93
99
  }),
94
100
  },
95
- }), onApply: (built) => {
101
+ }),
102
+ // The chip reads as the builder says it — a chosen record by its name, never its key.
103
+ onApply: (built, said) => {
96
104
  place(built?.selection === undefined
97
105
  ? []
98
- : [filterCriteria(built.selection, describeFilter(built.selection, model))]);
106
+ : [
107
+ filterCriteria(built.selection, said ?? describeFilter(built.selection, model)),
108
+ ]);
99
109
  listing.orderBy((built?.order ?? []).map((one) => ({
100
110
  field: one.field,
101
111
  ...(one.descending === true ? { descending: true } : {}),
@@ -8,7 +8,11 @@ import type { Pivot } from "@sincpro/web-ui";
8
8
  * Nothing is added up here — a margin is read from the base, never summed from cells.
9
9
  *
10
10
  * A key is how its value READS («Pagada», «Efectivo»): the grid draws keys, and the server's
11
- * value («paid») is not a word for a person.
11
+ * value («paid») is not a word for a person. A level cut by a grain is the exception: its key
12
+ * is the period the server counted («2026-11»), which web-ui reads by the level's grain —
13
+ * «Noviembre de 2026» in the grid, «nov» under a chart's tick — and which lets a chart fill the
14
+ * months nothing fell in. Read as the field's value, a month was an instant: «31/10/2026 20:00»
15
+ * in La Paz.
12
16
  */
13
17
  export declare function pivotOf<T extends AnyRecord>({ crossed, byColumn, rows, columns, measures, meta, locale, }: {
14
18
  /** Grouped by rows, then columns (`usePivot().crossed`). */
@@ -1,6 +1,7 @@
1
1
  import { labelOf } from "@sincpro/criteria";
2
2
  import { frameworkCopy } from "../../core/copy.js";
3
- import { textOf } from "../../core/present.js";
3
+ import { totalOf } from "../../core/measure.js";
4
+ import { shortTextOf, textOf } from "../../core/present.js";
4
5
  /**
5
6
  * web-ui's `Pivot` (`folded`), from what the SERVER counted (`usePivot`): the rows axis is the
6
7
  * outer groups, the columns axis every inner value that appeared, each crossing an inner group,
@@ -8,13 +9,24 @@ import { textOf } from "../../core/present.js";
8
9
  * Nothing is added up here — a margin is read from the base, never summed from cells.
9
10
  *
10
11
  * A key is how its value READS («Pagada», «Efectivo»): the grid draws keys, and the server's
11
- * value («paid») is not a word for a person.
12
+ * value («paid») is not a word for a person. A level cut by a grain is the exception: its key
13
+ * is the period the server counted («2026-11»), which web-ui reads by the level's grain —
14
+ * «Noviembre de 2026» in the grid, «nov» under a chart's tick — and which lets a chart fill the
15
+ * months nothing fell in. Read as the field's value, a month was an instant: «31/10/2026 20:00»
16
+ * in La Paz.
12
17
  */
13
18
  export function pivotOf({ crossed, byColumn, rows, columns, measures, meta, locale, }) {
14
19
  const none = frameworkCopy().list.noValue;
15
- const keyOf = (bucket) => bucket.value === null || bucket.value === undefined || bucket.value === ""
16
- ? none
17
- : (textOf(meta, bucket.field, bucket.value, locale) ?? String(bucket.value));
20
+ // A period without a date is web-ui's empty key: it says «sin fecha» and a chart keeps it last.
21
+ const keyFor = (level) => (bucket) => bucket.value === null || bucket.value === undefined || bucket.value === ""
22
+ ? level.grain === undefined
23
+ ? none
24
+ : ""
25
+ : level.grain === undefined
26
+ ? (textOf(meta, bucket.field, bucket.value, locale) ?? String(bucket.value))
27
+ : String(bucket.value);
28
+ const rowKeyOf = keyFor(rows);
29
+ const columnKeyOf = keyFor(columns);
18
30
  const cellOf = (bucket) => ({
19
31
  count: bucket.count,
20
32
  values: Object.fromEntries(measures.map((name) => {
@@ -22,13 +34,13 @@ export function pivotOf({ crossed, byColumn, rows, columns, measures, meta, loca
22
34
  return [name, value === null || value === undefined ? null : Number(value)];
23
35
  })),
24
36
  });
25
- const rowKeys = crossed.map((bucket) => [keyOf(bucket)]);
37
+ const rowKeys = crossed.map((bucket) => [rowKeyOf(bucket)]);
26
38
  // Columns in the server's order of the columns alone; any value only a crossing has, after.
27
- const seen = new Set(byColumn.map(keyOf));
39
+ const seen = new Set(byColumn.map(columnKeyOf));
28
40
  const columnKeys = [...seen];
29
41
  for (const outer of crossed)
30
42
  for (const inner of outer.groups ?? []) {
31
- const key = keyOf(inner);
43
+ const key = columnKeyOf(inner);
32
44
  if (!seen.has(key)) {
33
45
  seen.add(key);
34
46
  columnKeys.push(key);
@@ -37,12 +49,12 @@ export function pivotOf({ crossed, byColumn, rows, columns, measures, meta, loca
37
49
  const at = new Map();
38
50
  const rowTotals = new Map();
39
51
  for (const outer of crossed) {
40
- const row = keyOf(outer);
52
+ const row = rowKeyOf(outer);
41
53
  rowTotals.set(row, cellOf(outer));
42
54
  for (const inner of outer.groups ?? [])
43
- at.set(`${row}\u0000${keyOf(inner)}`, cellOf(inner));
55
+ at.set(`${row}\u0000${columnKeyOf(inner)}`, cellOf(inner));
44
56
  }
45
- const columnTotals = new Map(byColumn.map((bucket) => [keyOf(bucket), cellOf(bucket)]));
57
+ const columnTotals = new Map(byColumn.map((bucket) => [columnKeyOf(bucket), cellOf(bucket)]));
46
58
  return {
47
59
  rows: {
48
60
  levels: [{ ...rows, label: labelOf(meta, rows.field, locale) }],
@@ -56,6 +68,11 @@ export function pivotOf({ crossed, byColumn, rows, columns, measures, meta, loca
56
68
  id: name,
57
69
  header: labelOf(meta, name, locale),
58
70
  format: (value) => textOf(meta, name, value, locale) ?? String(value),
71
+ // Under a chart's tick: «Bs 120 k», never the bare number.
72
+ formatShort: (value) => shortTextOf(meta, name, value, locale) ?? String(value),
73
+ // Folded by a sum (`measuresOf`'s default): two piles together are the sum of their folds,
74
+ // so a chart may gather a tail into «otros». An average, a minimum, a maximum are not.
75
+ additive: (totalOf(meta, name) ?? "sum") === "sum",
59
76
  })),
60
77
  cell: (row, column) => at.get(`${row[0] ?? ""}\u0000${column[0] ?? ""}`),
61
78
  rowTotal: (row) => rowTotals.get(row[0] ?? ""),
@@ -0,0 +1,100 @@
1
+ import { type Entity, type MetaStore, type Selection, type Transport } from "@sincpro/client-framework";
2
+ import { type AnyRecord, type Expression, type Meta } from "@sincpro/criteria";
3
+ import type { NameBook } from "../../core/names.js";
4
+ import type { BrowseRecords, LoadModel, SearchRecords, ToastSpec } from "@sincpro/web-ui";
5
+ import { type ReactNode } from "react";
6
+ /** A record as a person picks it by name: its key, its name, and what tells it apart. */
7
+ export type Choice = {
8
+ id: string;
9
+ name: string;
10
+ detail?: string;
11
+ };
12
+ /**
13
+ * The records of an entity that match a typed text, as a person picks them by name — a ⌘K hit,
14
+ * a relation's record in the search bar: the entity's LITERAL search (`matching`: its search
15
+ * template and a short page), each record whole, read as its name and, beside it, what tells it
16
+ * apart — the entity's `option` look, else its summary's description or type. Never its key.
17
+ *
18
+ * await findChoices(transport, clientes, clienteMeta, "/clientes", "andres", "es")
19
+ * -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
20
+ *
21
+ * Context: `matching` asks for references (identity and display), and the `option` look and the
22
+ * summary read fields a reference does not carry: ⌘K's detail was always empty against the real
23
+ * backend (#48). The question keeps `matching`'s template and its page, and brings each record
24
+ * whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
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. */
29
+ export type FrameworkReads = {
30
+ transport: Transport;
31
+ metas: MetaStore;
32
+ names: NameBook;
33
+ entities: readonly Entity[];
34
+ };
35
+ /**
36
+ * web-ui's `searchRecords` (2.7) answered by the framework: the records of a relation the search
37
+ * bar unfolds and the criteria builder picks — «andres» → the customers that match —, each
38
+ * chosen by its key and read by its name.
39
+ *
40
+ * 1. The relation names an aggregate: its entity among the application's (`entityFor`); one the
41
+ * application did not declare finds nothing — the bar still offers the relation's text.
42
+ * 2. Keys instead of a text (a filter read back from a link): their names, through the book every
43
+ * 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.
45
+ */
46
+ export declare function recordsSearch(framework: FrameworkReads, locale: string | undefined): SearchRecords;
47
+ /** `recordsSearch` over the framework's context: the screens' transport, its definitions and
48
+ * its names, in the provider's language. */
49
+ export declare function useSearchRecords(): SearchRecords;
50
+ /**
51
+ * web-ui's `loadModel` (2.8) answered by the framework: the model at the end of a path of
52
+ * relations — «Cliente › País» —, what the criteria builder walks to offer a related record's
53
+ * fields and the records themselves.
54
+ *
55
+ * await modelLoader(framework, facturaMeta, "es")(["customer"]) -> the customers' model
56
+ *
57
+ * 1. From the root's definition, each name of the path is a relation of the model before it.
58
+ * 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.
60
+ * Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
61
+ * the model lacks, a relation to an entity the application did not declare — is refused.
62
+ */
63
+ export declare function modelLoader(framework: FrameworkReads, root: Meta, locale: string | undefined): LoadModel;
64
+ /** `modelLoader` over the framework's context, from a list's definition (none yet: none). */
65
+ export declare function useLoadModel(root: Meta | null | undefined): LoadModel | undefined;
66
+ /**
67
+ * How a chooser of an entity is opened, and what it answers: one record by its key (`choose`)
68
+ * or what was chosen of several (`chooseMany`, a `Selection`) — the workspace's, given to the
69
+ * fields of a record (`RecordOpening`) and to the search bar (`RecordsBrowserProvider`).
70
+ */
71
+ export type Chooser<A> = (entity: Entity, answer: (value: A) => void, query: string, scope?: Expression) => void;
72
+ /**
73
+ * web-ui's `browseRecords` (2.8) answered by the framework: «Buscar más…» under the records of a
74
+ * relation opens its entity's list to choose — several when the place takes several, one
75
+ * otherwise —, on what was typed and without what is already chosen; the keys chosen are answered
76
+ * named.
77
+ *
78
+ * 1. The relation's entity (`entityFor`); one the application did not declare is not browsed.
79
+ * 2. What is chosen is left out of the chooser (`not in` its keys), as a picker's chooser does.
80
+ * 3. Several: the chooser answers a `Selection`, read as keys with a ceiling (`keysOf`,
81
+ * `BATCH_LIMIT`) — past it nothing is chosen and `refused` says why. One: its key.
82
+ * Final: the keys, named through `names` (the `NameBook`), handed to web-ui (`choose`).
83
+ */
84
+ export declare function recordsBrowser(framework: FrameworkReads, open: {
85
+ choose?: Chooser<string> | undefined;
86
+ chooseMany?: Chooser<Selection> | undefined;
87
+ }, names: SearchRecords, refused: (failure: unknown) => void): BrowseRecords;
88
+ /**
89
+ * What a person is told when choosing records failed — too many chosen to take at once
90
+ * (`SelectionTooLarge`), in the framework's words; anything else, as the server explained it —,
91
+ * as a web-ui toast.
92
+ */
93
+ export declare function refusalNotice(failure: unknown): ToastSpec;
94
+ /** «Buscar más…» for every search bar below — what a workspace view gives its screens. */
95
+ export declare function RecordsBrowserProvider({ value, children, }: {
96
+ value: BrowseRecords;
97
+ children: ReactNode;
98
+ }): import("react").JSX.Element;
99
+ /** The view's «Buscar más…», or `null` outside a workspace. */
100
+ export declare function useRecordsBrowser(): BrowseRecords | null;