@sincpro/web-framework 3.5.0 → 3.7.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 (63) hide show
  1. package/README.md +5 -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/crumbs.d.ts +4 -0
  7. package/dist/core/crumbs.js +24 -0
  8. package/dist/core/history.d.ts +16 -4
  9. package/dist/core/history.js +20 -17
  10. package/dist/core/index.d.ts +4 -3
  11. package/dist/core/index.js +3 -2
  12. package/dist/core/list.d.ts +12 -0
  13. package/dist/core/list.js +14 -0
  14. package/dist/core/present.d.ts +12 -0
  15. package/dist/core/present.js +39 -0
  16. package/dist/react/index.d.ts +2 -0
  17. package/dist/react/index.js +2 -0
  18. package/dist/react/useBatchCommand.d.ts +50 -0
  19. package/dist/react/useBatchCommand.js +124 -0
  20. package/dist/react/useCommand.js +3 -4
  21. package/dist/react/useSelection.d.ts +37 -0
  22. package/dist/react/useSelection.js +40 -0
  23. package/dist/web/index.d.ts +7 -3
  24. package/dist/web/index.js +7 -3
  25. package/dist/web/list/BatchProgress.d.ts +16 -0
  26. package/dist/web/list/BatchProgress.js +40 -0
  27. package/dist/web/list/EntityList.d.ts +31 -8
  28. package/dist/web/list/EntityList.js +122 -39
  29. package/dist/web/list/EntitySearchBar.d.ts +9 -0
  30. package/dist/web/list/EntitySearchBar.js +15 -5
  31. package/dist/web/list/columns.d.ts +4 -1
  32. package/dist/web/list/columns.js +14 -6
  33. package/dist/web/list/dock.d.ts +19 -0
  34. package/dist/web/list/dock.js +20 -0
  35. package/dist/web/list/groups.d.ts +7 -1
  36. package/dist/web/list/groups.js +25 -5
  37. package/dist/web/list/pivot.d.ts +5 -1
  38. package/dist/web/list/pivot.js +28 -11
  39. package/dist/web/list/records.d.ts +100 -0
  40. package/dist/web/list/records.js +219 -0
  41. package/dist/web/list/search.d.ts +0 -17
  42. package/dist/web/list/search.js +33 -5
  43. package/dist/web/record/ActionButton.d.ts +25 -0
  44. package/dist/web/record/ActionButton.js +39 -18
  45. package/dist/web/record/CommandButton.d.ts +22 -2
  46. package/dist/web/record/CommandButton.js +43 -17
  47. package/dist/web/record/EntityTags.d.ts +5 -2
  48. package/dist/web/record/EntityTags.js +34 -12
  49. package/dist/web/record/RecordLifecycle.d.ts +28 -7
  50. package/dist/web/record/RecordLifecycle.js +63 -10
  51. package/dist/web/record/ServiceButton.d.ts +20 -2
  52. package/dist/web/record/ServiceButton.js +35 -27
  53. package/dist/web/record/dock.d.ts +31 -0
  54. package/dist/web/record/dock.js +14 -0
  55. package/dist/web/record/opening.d.ts +6 -2
  56. package/dist/web/record/record.d.ts +14 -3
  57. package/dist/web/record/record.js +39 -6
  58. package/dist/web/workspace/SincproApp.js +13 -2
  59. package/dist/web/workspace/composer.d.ts +1 -1
  60. package/dist/web/workspace/composer.js +23 -25
  61. package/dist/web/workspace/record.d.ts +8 -3
  62. package/dist/web/workspace/record.js +20 -16
  63. package/package.json +9 -9
@@ -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;
@@ -0,0 +1,219 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { keysOf, listRoute, SelectionTooLarge, } from "@sincpro/client-framework";
4
+ import { matching } from "@sincpro/criteria";
5
+ import { frameworkCopy } from "../../core/copy.js";
6
+ import { explain } from "../../core/explain.js";
7
+ import { lookupOf } from "../../core/lookup.js";
8
+ import { entityFor } from "../../core/relation.js";
9
+ import { summaryOf } from "../../core/summary.js";
10
+ import { useFramework } from "../../react/context.js";
11
+ import { BATCH_LIMIT } from "../../react/useBatchCommand.js";
12
+ import { presentationOf } from "./presentation.js";
13
+ import { modelOf } from "./search.js";
14
+ import { createContext, useContext, useMemo } from "react";
15
+ /**
16
+ * The records of an entity that match a typed text, as a person picks them by name — a ⌘K hit,
17
+ * a relation's record in the search bar: the entity's LITERAL search (`matching`: its search
18
+ * template and a short page), each record whole, read as its name and, beside it, what tells it
19
+ * apart — the entity's `option` look, else its summary's description or type. Never its key.
20
+ *
21
+ * await findChoices(transport, clientes, clienteMeta, "/clientes", "andres", "es")
22
+ * -> [{ id: "C-7", name: "Andrés Pérez", detail: "NIT 4455667" }, …]
23
+ *
24
+ * Context: `matching` asks for references (identity and display), and the `option` look and the
25
+ * summary read fields a reference does not carry: ⌘K's detail was always empty against the real
26
+ * backend (#48). The question keeps `matching`'s template and its page, and brings each record
27
+ * whole. ⌘K and the search bar's records (web-ui 2.7) read a record the same way, here.
28
+ */
29
+ export async function findChoices(transport, entity, meta, route, text, locale, signal) {
30
+ const { specification: _reference, ...question } = matching(meta, text);
31
+ const page = await transport.list(route, question, signal);
32
+ const look = presentationOf(entity).option;
33
+ return lookupOf(meta, page.rows, entity.summary).map((one) => {
34
+ const own = look === undefined || one.record === undefined ? {} : look(one.record);
35
+ const summary = one.record === undefined
36
+ ? undefined
37
+ : summaryOf(meta, one.record, {
38
+ fields: entity.summary ?? {},
39
+ ...(locale === undefined ? {} : { locale }),
40
+ });
41
+ const detail = own.meta ?? summary?.description ?? summary?.type ?? undefined;
42
+ return {
43
+ id: one.id,
44
+ name: own.name ?? one.label,
45
+ ...(detail === undefined ? {} : { detail }),
46
+ };
47
+ });
48
+ }
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
+ /**
74
+ * web-ui's `searchRecords` (2.7) answered by the framework: the records of a relation the search
75
+ * bar unfolds and the criteria builder picks — «andres» → the customers that match —, each
76
+ * chosen by its key and read by its name.
77
+ *
78
+ * 1. The relation names an aggregate: its entity among the application's (`entityFor`); one the
79
+ * application did not declare finds nothing — the bar still offers the relation's text.
80
+ * 2. Keys instead of a text (a filter read back from a link): their names, through the book every
81
+ * 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.
83
+ */
84
+ export function recordsSearch(framework, locale) {
85
+ return async ({ relation, text, keys, signal }) => {
86
+ const entity = entityFor(framework.entities, relation, framework.metas.get);
87
+ if (entity === undefined)
88
+ return [];
89
+ if (keys !== undefined)
90
+ return Promise.all(keys.map(async (key) => ({
91
+ id: key,
92
+ name: (await framework.names.nameOf(entity, String(key))) ?? String(key),
93
+ })));
94
+ const route = routeOf(entity);
95
+ const meta = await metaOf(framework, entity, signal);
96
+ if (route === undefined || meta === undefined)
97
+ return [];
98
+ const choices = await findChoices(framework.transport, entity, meta, route, text, locale, signal);
99
+ return choices.map((one) => ({
100
+ id: one.id,
101
+ name: one.name,
102
+ ...(one.detail === undefined ? {} : { meta: one.detail }),
103
+ }));
104
+ };
105
+ }
106
+ /** `recordsSearch` over the framework's context: the screens' transport, its definitions and
107
+ * its names, in the provider's language. */
108
+ 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]);
111
+ }
112
+ /**
113
+ * web-ui's `loadModel` (2.8) answered by the framework: the model at the end of a path of
114
+ * relations — «Cliente › País» —, what the criteria builder walks to offer a related record's
115
+ * fields and the records themselves.
116
+ *
117
+ * await modelLoader(framework, facturaMeta, "es")(["customer"]) -> the customers' model
118
+ *
119
+ * 1. From the root's definition, each name of the path is a relation of the model before it.
120
+ * 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.
122
+ * Final: that definition as web-ui reads a model (`modelOf`); a path that leads nowhere — a name
123
+ * the model lacks, a relation to an entity the application did not declare — is refused.
124
+ */
125
+ export function modelLoader(framework, root, locale) {
126
+ const next = async (meta, name) => {
127
+ const field = meta.fields[name];
128
+ if (field === undefined)
129
+ return undefined;
130
+ if (field.definition)
131
+ return field.definition;
132
+ const entity = typeof field.relation === "string"
133
+ ? entityFor(framework.entities, field.relation, framework.metas.get)
134
+ : undefined;
135
+ return entity === undefined ? undefined : metaOf(framework, entity);
136
+ };
137
+ return async (path) => {
138
+ let meta = root;
139
+ for (const name of path) {
140
+ const found = await next(meta, name);
141
+ if (found === undefined)
142
+ throw new Error(`no model at ${path.join(" › ")}`);
143
+ meta = found;
144
+ }
145
+ return modelOf(meta, locale);
146
+ };
147
+ }
148
+ /** `modelLoader` over the framework's context, from a list's definition (none yet: none). */
149
+ export function useLoadModel(root) {
150
+ const { transport, metas, names, entities, locale } = useFramework();
151
+ return useMemo(() => root == null
152
+ ? undefined
153
+ : modelLoader({ transport, metas, names, entities }, root, locale), [root, transport, metas, names, entities, locale]);
154
+ }
155
+ /**
156
+ * web-ui's `browseRecords` (2.8) answered by the framework: «Buscar más…» under the records of a
157
+ * relation opens its entity's list to choose — several when the place takes several, one
158
+ * otherwise —, on what was typed and without what is already chosen; the keys chosen are answered
159
+ * named.
160
+ *
161
+ * 1. The relation's entity (`entityFor`); one the application did not declare is not browsed.
162
+ * 2. What is chosen is left out of the chooser (`not in` its keys), as a picker's chooser does.
163
+ * 3. Several: the chooser answers a `Selection`, read as keys with a ceiling (`keysOf`,
164
+ * `BATCH_LIMIT`) — past it nothing is chosen and `refused` says why. One: its key.
165
+ * Final: the keys, named through `names` (the `NameBook`), handed to web-ui (`choose`).
166
+ */
167
+ export function recordsBrowser(framework, open, names, refused) {
168
+ return (browse) => {
169
+ const entity = entityFor(framework.entities, browse.relation, framework.metas.get);
170
+ if (entity === undefined)
171
+ return;
172
+ const meta = framework.metas.get(entity.key);
173
+ const identity = meta?.get_id || meta?.identity || "id";
174
+ const chosen = browse.chosen.map((one) => String(one.id));
175
+ const scope = chosen.length === 0
176
+ ? undefined
177
+ : { field: identity, operator: "not in", value: chosen };
178
+ const answer = (keys) => names({
179
+ relation: browse.relation,
180
+ path: browse.path,
181
+ text: "",
182
+ keys,
183
+ signal: new AbortController().signal,
184
+ }).then(browse.choose, refused);
185
+ const route = routeOf(entity);
186
+ if (browse.many && open.chooseMany !== undefined && route !== undefined)
187
+ open.chooseMany(entity, (selection) => void keysOf(selection, {
188
+ transport: framework.transport,
189
+ route,
190
+ identity,
191
+ limit: BATCH_LIMIT,
192
+ }).then(answer, refused), browse.text, scope);
193
+ else
194
+ open.choose?.(entity, (id) => void answer([id]), browse.text, scope);
195
+ };
196
+ }
197
+ /**
198
+ * What a person is told when choosing records failed — too many chosen to take at once
199
+ * (`SelectionTooLarge`), in the framework's words; anything else, as the server explained it —,
200
+ * as a web-ui toast.
201
+ */
202
+ export function refusalNotice(failure) {
203
+ if (failure instanceof SelectionTooLarge)
204
+ return {
205
+ tone: "warn",
206
+ message: frameworkCopy().batch.tooMany(failure.size, failure.limit),
207
+ };
208
+ const { heading, sentence } = explain(failure);
209
+ return { tone: "bad", message: heading, detail: sentence };
210
+ }
211
+ const Browser = createContext(null);
212
+ /** «Buscar más…» for every search bar below — what a workspace view gives its screens. */
213
+ export function RecordsBrowserProvider({ value, children, }) {
214
+ return _jsx(Browser.Provider, { value: value, children: children });
215
+ }
216
+ /** The view's «Buscar más…», or `null` outside a workspace. */
217
+ export function useRecordsBrowser() {
218
+ return useContext(Browser);
219
+ }
@@ -1,22 +1,5 @@
1
1
  import { type Meta } from "@sincpro/criteria";
2
2
  import type { ModelDefinition, SearchFacet } from "@sincpro/web-ui";
3
- /**
4
- * The model, as web-ui's search bar and criteria builder read it.
5
- *
6
- * Context: web-ui keeps its OWN vocabulary of a model (`ModelDefinition`), written before the
7
- * framework settled its wire, and the two drifted: `identifiedBy` against `identified_by`, one
8
- * `translations` object against a `label` on each field. web-ui is right to own it — it is a
9
- * design system and must not depend on one backend — so the translation lives here, the one
10
- * place that knows both.
11
- *
12
- * Known gap: web-ui's field has `choices` but no word for each choice, so the bar offers an
13
- * enum's raw values («paid») where a cell says «Pagada». Fixing it is web-ui's.
14
- *
15
- * `texts` keeps only those plain text fields: web-ui's bar offers a typed word in EVERY text
16
- * field of the model it is handed (its `facets` are read only without one), so the bar is handed
17
- * the model with the text fields a person types into (`facetsOf`) — and the criteria builder the
18
- * whole one.
19
- */
20
3
  export declare function modelOf(meta: Meta, locale?: string, texts?: readonly string[]): ModelDefinition;
21
4
  /**
22
5
  * Where a typed text can be looked for: the fields the screen names (`defineList facets`), else
@@ -1,4 +1,4 @@
1
- import { labelOf } from "@sincpro/criteria";
1
+ import { choiceLabelOf, isRelational, labelOf } from "@sincpro/criteria";
2
2
  /**
3
3
  * The model, as web-ui's search bar and criteria builder read it.
4
4
  *
@@ -8,19 +8,33 @@ import { labelOf } from "@sincpro/criteria";
8
8
  * design system and must not depend on one backend — so the translation lives here, the one
9
9
  * place that knows both.
10
10
  *
11
- * Known gap: web-ui's field has `choices` but no word for each choice, so the bar offers an
12
- * enum's raw values («paid») where a cell says «Pagada». Fixing it is web-ui's.
11
+ * An enum carries the word of each value (`translations.choices`, web-ui 2.7): the bar offers
12
+ * «Estado: Pagada» for «pagada» typed and sends `paid` — before, it offered the raw value where
13
+ * a cell said «Pagada». A to-many relation carries the key of the records on the other side
14
+ * (`relationKey`, from the related definition): what the bar's records are compared by through
15
+ * it once chosen.
13
16
  *
14
17
  * `texts` keeps only those plain text fields: web-ui's bar offers a typed word in EVERY text
15
18
  * field of the model it is handed (its `facets` are read only without one), so the bar is handed
16
19
  * the model with the text fields a person types into (`facetsOf`) — and the criteria builder the
17
20
  * whole one.
18
21
  */
22
+ /** The comparisons of a text a person types: never asked of a key. */
23
+ const TYPED_TEXT = new Set(["like", "starts with"]);
19
24
  export function modelOf(meta, locale, texts) {
25
+ // The column a to-one relation is identified by — sincpro_framework's `identified_by`, its
26
+ // foreign key — stays: web-ui compares a chosen record by it and never offers it on its own.
27
+ // It holds a KEY, so it is handed without the comparisons of a text a person types («like»,
28
+ // «starts with»): with them web-ui read it as a column that names the record, and «globex» on
29
+ // «Cliente» became «customer_id contains globex» instead of unfolding the customers.
30
+ const identifying = new Set(Object.values(meta.fields)
31
+ .filter((field) => isRelational(field) && field.many !== true)
32
+ .map((field) => field.identified_by)
33
+ .filter((name) => typeof name === "string" && name !== ""));
20
34
  const kept = (name) => {
21
35
  const field = meta.fields[name];
22
36
  const text = field?.type === "text" && !field.choices?.length;
23
- return texts === undefined || !text || texts.includes(name);
37
+ return texts === undefined || !text || texts.includes(name) || identifying.has(name);
24
38
  };
25
39
  const names = Object.keys(meta.fields).filter(kept);
26
40
  return {
@@ -34,7 +48,9 @@ export function modelOf(meta, locale, texts) {
34
48
  type: field.type,
35
49
  nullable: field.nullable,
36
50
  sortable: field.sortable,
37
- ops: field.ops,
51
+ ops: identifying.has(name)
52
+ ? field.ops.filter((op) => !TYPED_TEXT.has(op))
53
+ : field.ops,
38
54
  kind: field.kind,
39
55
  ...(field.many === undefined ? {} : { many: field.many }),
40
56
  ...(field.relation === undefined ? {} : { relation: field.relation }),
@@ -42,6 +58,9 @@ export function modelOf(meta, locale, texts) {
42
58
  ? {}
43
59
  : { identifiedBy: field.identified_by }),
44
60
  ...(field.choices && field.choices.length > 0 ? { choices: field.choices } : {}),
61
+ ...(field.many === true && field.definition
62
+ ? { relationKey: field.definition.get_id || field.definition.identity }
63
+ : {}),
45
64
  },
46
65
  ])),
47
66
  translations: {
@@ -49,6 +68,15 @@ export function modelOf(meta, locale, texts) {
49
68
  default: meta.name?.[locale ?? ""] ?? meta.name?.["default"] ?? meta.aggregate,
50
69
  },
51
70
  labels: Object.fromEntries(names.map((name) => [name, { default: labelOf(meta, name, locale) }])),
71
+ choices: Object.fromEntries(names
72
+ .filter((name) => (meta.fields[name]?.choices?.length ?? 0) > 0)
73
+ .map((name) => [
74
+ name,
75
+ Object.fromEntries((meta.fields[name]?.choices ?? []).map((value) => [
76
+ String(value),
77
+ { default: choiceLabelOf(meta, name, value, locale) },
78
+ ])),
79
+ ])),
52
80
  },
53
81
  };
54
82
  }
@@ -1,5 +1,6 @@
1
1
  import type { Rehearsal } from "../../react/useCommand.js";
2
2
  import type { AskForm } from "./ask.js";
3
+ import { type ReactNode } from "react";
3
4
  /** What a person filled in before the action runs, by field name. */
4
5
  export type Asked = Readonly<Record<string, unknown>>;
5
6
  /** What an action's window says, when the screen says it its way. */
@@ -54,3 +55,27 @@ export declare function ActionButton<R>({ action, label, role, disabled, ask: fo
54
55
  dialog?: ActionDialog;
55
56
  onDone?: (answer: R) => void;
56
57
  }): import("react").JSX.Element;
58
+ /** An action's gesture, for whatever starts it — a button, a dock's action, a shortcut. */
59
+ export type ActionGesture = {
60
+ /** Starts it: opens what it asks, asks first what it would do (it destroys), or runs. */
61
+ start: () => void;
62
+ /** It runs: not offered again until it ends. */
63
+ busy: boolean;
64
+ /** Its window — what it asks, what it would do, a refusal —; `null` while closed. Put it
65
+ * anywhere on the screen: it opens over everything. */
66
+ dialog: ReactNode;
67
+ };
68
+ /**
69
+ * `ActionButton`'s gesture without the button: started by anything, its window put where the
70
+ * screen puts it.
71
+ *
72
+ * Context: web-ui's dock (`Record.Dock`, the modern style's floating pill) takes actions as
73
+ * data — a label and an `onSelect` —, not buttons. The gesture is the same: `start` is the
74
+ * button's click, and `dialog` the window it opened.
75
+ */
76
+ export declare function useActionGesture<R>(action: ButtonAction<R>, { label, ask: form, dialog, onDone, }: {
77
+ label: string;
78
+ ask?: AskForm;
79
+ dialog?: ActionDialog;
80
+ onDone?: (answer: R) => void;
81
+ }): ActionGesture;
@@ -65,36 +65,57 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
65
65
  * Internal: the gesture is drawn here once; what runs behind is each button's own.
66
66
  */
67
67
  export function ActionButton({ action, label, role = "secondary", disabled = false, ask: form, dialog, onDone, }) {
68
+ const gesture = useActionGesture(action, {
69
+ label,
70
+ ...(form === undefined ? {} : { ask: form }),
71
+ ...(dialog === undefined ? {} : { dialog }),
72
+ ...(onDone === undefined ? {} : { onDone }),
73
+ });
74
+ // One that destroys is never the gold button: what it would do is read first.
75
+ const destructive = form === undefined && action.rehearse !== undefined;
76
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || gesture.busy, onClick: gesture.start, children: label }), gesture.dialog] }));
77
+ }
78
+ /**
79
+ * `ActionButton`'s gesture without the button: started by anything, its window put where the
80
+ * screen puts it.
81
+ *
82
+ * Context: web-ui's dock (`Record.Dock`, the modern style's floating pill) takes actions as
83
+ * data — a label and an `onSelect` —, not buttons. The gesture is the same: `start` is the
84
+ * button's click, and `dialog` the window it opened.
85
+ */
86
+ export function useActionGesture(action, { label, ask: form, dialog, onDone, }) {
68
87
  const copy = frameworkCopy().command;
69
88
  const [open, setOpen] = useState(false);
70
89
  const words = wordsOf(label, dialog);
90
+ const close = () => {
91
+ setOpen(false);
92
+ action.reset();
93
+ };
94
+ const done = (answer) => {
95
+ close();
96
+ onDone?.(answer);
97
+ };
71
98
  if (form !== undefined)
72
- return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: role, disabled: disabled || action.busy, onClick: () => setOpen(true), children: label }), open ? (_jsx(AskDialog, { action: action, form: form, words: words, onClose: () => {
73
- setOpen(false);
74
- action.reset();
75
- }, onDone: (answer) => {
76
- setOpen(false);
77
- action.reset();
78
- onDone?.(answer);
79
- } })) : null] }));
99
+ return {
100
+ start: () => setOpen(true),
101
+ busy: action.busy,
102
+ dialog: open ? (_jsx(AskDialog, { action: action, form: form, words: words, onClose: close, onDone: done })) : null,
103
+ };
80
104
  const destructive = action.rehearse !== undefined;
81
105
  const run = async () => {
82
106
  const answer = await action.run();
83
- if (answer !== undefined) {
84
- setOpen(false);
85
- action.reset();
86
- onDone?.(answer);
87
- }
107
+ if (answer !== undefined)
108
+ done(answer);
88
109
  else
89
110
  setOpen(true);
90
111
  };
91
- const ask = async () => {
112
+ const rehearse = async () => {
92
113
  setOpen(true);
93
114
  await action.rehearse?.();
94
115
  };
95
- const close = () => {
96
- setOpen(false);
97
- action.reset();
116
+ return {
117
+ start: () => void (destructive ? rehearse() : run()),
118
+ busy: action.busy,
119
+ dialog: open ? (_jsx(Dialog, { open: true, ...words, onClose: close, footer: destructive && action.error === null ? (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: close, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || action.rehearsal === null, onClick: () => void run(), children: copy.confirm })] })) : undefined, children: action.error !== null ? (_jsx(Refused, { error: action.error })) : action.rehearsal === null ? (_jsx("p", { className: "text-meta text-muted", children: copy.rehearsing })) : (_jsx("p", { className: "text-ink", children: action.rehearsal.text })) })) : null,
98
120
  };
99
- return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || action.busy, onClick: () => void (destructive ? ask() : run()), children: label }), open ? (_jsx(Dialog, { open: true, ...words, onClose: close, footer: destructive && action.error === null ? (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: close, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || action.rehearsal === null, onClick: () => void run(), children: copy.confirm })] })) : undefined, children: action.error !== null ? (_jsx(Refused, { error: action.error })) : action.rehearsal === null ? (_jsx("p", { className: "text-meta text-muted", children: copy.rehearsing })) : (_jsx("p", { className: "text-ink", children: action.rehearsal.text })) })) : null] }));
100
121
  }