@sincpro/web-framework 3.0.0 → 3.2.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 (62) hide show
  1. package/README.md +29 -0
  2. package/dist/core/copy.d.ts +13 -1
  3. package/dist/core/copy.js +30 -0
  4. package/dist/core/explain.d.ts +12 -4
  5. package/dist/core/explain.js +18 -6
  6. package/dist/core/form.d.ts +7 -3
  7. package/dist/core/form.js +11 -5
  8. package/dist/core/groups.d.ts +17 -0
  9. package/dist/core/groups.js +31 -0
  10. package/dist/core/history.d.ts +41 -4
  11. package/dist/core/history.js +79 -12
  12. package/dist/core/index.d.ts +4 -3
  13. package/dist/core/index.js +4 -3
  14. package/dist/core/list.d.ts +3 -0
  15. package/dist/core/measure.d.ts +14 -5
  16. package/dist/core/measure.js +32 -7
  17. package/dist/core/present.d.ts +51 -3
  18. package/dist/core/present.js +162 -15
  19. package/dist/core/summary.d.ts +6 -2
  20. package/dist/react/context.d.ts +26 -2
  21. package/dist/react/context.js +56 -2
  22. package/dist/react/useGroups.js +15 -4
  23. package/dist/react/useHistory.d.ts +4 -2
  24. package/dist/react/useHistory.js +20 -5
  25. package/dist/react/usePivot.js +18 -3
  26. package/dist/react/useRecord.d.ts +3 -0
  27. package/dist/react/useRecord.js +14 -2
  28. package/dist/web/Refused.d.ts +3 -3
  29. package/dist/web/Refused.js +3 -3
  30. package/dist/web/index.d.ts +3 -2
  31. package/dist/web/index.js +2 -1
  32. package/dist/web/list/EntityList.d.ts +4 -1
  33. package/dist/web/list/EntityList.js +69 -21
  34. package/dist/web/list/EntitySearchBar.d.ts +6 -2
  35. package/dist/web/list/EntitySearchBar.js +11 -3
  36. package/dist/web/list/columns.d.ts +6 -1
  37. package/dist/web/list/columns.js +81 -9
  38. package/dist/web/list/presentation.d.ts +20 -1
  39. package/dist/web/list/search.d.ts +14 -5
  40. package/dist/web/list/search.js +29 -14
  41. package/dist/web/record/ActionButton.d.ts +14 -4
  42. package/dist/web/record/ActionButton.js +45 -2
  43. package/dist/web/record/CommandButton.d.ts +10 -1
  44. package/dist/web/record/CommandButton.js +23 -4
  45. package/dist/web/record/RelatedList.d.ts +0 -15
  46. package/dist/web/record/RelatedList.js +35 -6
  47. package/dist/web/record/ServiceButton.d.ts +20 -4
  48. package/dist/web/record/ServiceButton.js +30 -5
  49. package/dist/web/record/ask.d.ts +59 -0
  50. package/dist/web/record/ask.js +59 -0
  51. package/dist/web/record/control.d.ts +2 -2
  52. package/dist/web/record/control.js +7 -3
  53. package/dist/web/record/edit.d.ts +6 -1
  54. package/dist/web/record/edit.js +56 -8
  55. package/dist/web/record/record.js +5 -2
  56. package/dist/web/workspace/SincproApp.d.ts +10 -1
  57. package/dist/web/workspace/SincproApp.js +18 -4
  58. package/dist/web/workspace/composer.d.ts +7 -2
  59. package/dist/web/workspace/composer.js +24 -4
  60. package/dist/web/workspace/record.d.ts +7 -2
  61. package/dist/web/workspace/record.js +31 -6
  62. package/package.json +7 -7
@@ -1,18 +1,31 @@
1
1
  import { labelOf, measure } from "@sincpro/criteria";
2
- import { BOOKKEEPING, textOf } from "./present.js";
2
+ import { BOOKKEEPING, fieldMetaOf, textOf } from "./present.js";
3
+ const TOTALS = new Set(["sum", "avg", "min", "max"]);
4
+ export function totalOf(meta, name) {
5
+ const total = fieldMetaOf(meta, name)?.total;
6
+ if (typeof total !== "string")
7
+ return undefined;
8
+ // `mean` is the same function by web-ui's name.
9
+ const said = total === "mean" ? "avg" : total;
10
+ return TOTALS.has(said) ? said : undefined;
11
+ }
3
12
  /**
4
13
  * What a group ADDS UP TO — «Total 1.204.933,00» beside «Pagadas · 187» — summed by the server
5
14
  * over every row of the group, never the page.
6
15
  *
7
16
  * Context: a count says how many; whoever groups invoices by state wants to know how much. Which
8
- * fields add up is the domain's, and the model does not say it yet, so the default is the
9
- * figure a record computes: an exact number that is read-only (a total, a subtotal, a balance).
10
- * What a person types — a discount, a percentage, a limit — is not added up: a sum of
17
+ * fields add up is the domain's: the model says it with `total` (sincpro_framework's
18
+ * `Presentation.totals`), and those are the default. A model that says nothing falls back to
19
+ * the figure a record computes: an exact number that is read-only (a total, a subtotal, a
20
+ * balance). What a person types — a discount, a percentage, a limit — is not added up: a sum of
11
21
  * percentages means nothing. A screen names its own (`EntityList sums`).
12
22
  */
13
23
  export function sumsOf(meta) {
14
24
  if (!meta)
15
25
  return [];
26
+ const totalled = Object.keys(meta.fields).filter((name) => totalOf(meta, name) !== undefined);
27
+ if (totalled.length > 0)
28
+ return totalled;
16
29
  return Object.entries(meta.fields)
17
30
  .filter(([name, field]) => !BOOKKEEPING.has(name) &&
18
31
  (field.type === "number" || field.type === "integer") &&
@@ -20,9 +33,21 @@ export function sumsOf(meta) {
20
33
  field.readonly === true)
21
34
  .map(([name]) => name);
22
35
  }
23
- /** The grouping's measures for these fields, each under its own name. */
24
- export function measuresOf(fields) {
25
- return Object.fromEntries(fields.map((field) => [field, measure.sum(field)]));
36
+ /** The grouping's measures for these fields, each under its own name — by the function the
37
+ * model adds it up with (`total`), a sum when it names none. */
38
+ export function measuresOf(fields, meta) {
39
+ return Object.fromEntries(fields.map((field) => {
40
+ switch (totalOf(meta, field)) {
41
+ case "avg":
42
+ return [field, measure.avg(field)];
43
+ case "min":
44
+ return [field, measure.min(field)];
45
+ case "max":
46
+ return [field, measure.max(field)];
47
+ default:
48
+ return [field, measure.sum(field)];
49
+ }
50
+ }));
26
51
  }
27
52
  /** What a group's measures read as: «Total 1.204.933,00 · Saldo 12,50». */
28
53
  export function detailOf(meta, measures, locale) {
@@ -21,6 +21,24 @@ export type FieldView = {
21
21
  required: boolean;
22
22
  readonly: boolean;
23
23
  };
24
+ /**
25
+ * Where a name lives: a field of the model, or — written `recibo.numero` — a field of the
26
+ * definition of a value the record embeds. The model the field is described by, and its own
27
+ * name there.
28
+ *
29
+ * Context: the Meta publishes an embedded value with its fields, their labels and types (a
30
+ * payment's receipt: number, issued, concept, amount); an application wrote each of them by
31
+ * hand because nothing here could name one. A path is the same name a screen writes in a form.
32
+ */
33
+ export declare function fieldAt(meta: Meta | null | undefined, name: string): {
34
+ meta: Meta | null | undefined;
35
+ name: string;
36
+ };
37
+ /** The value a name holds in a record: a field, or a field of an embedded value
38
+ * (`recibo.numero`). */
39
+ export declare function valueAt(meta: Meta | null | undefined, record: Readonly<Record<string, unknown>> | null | undefined, name: string): unknown;
40
+ /** What the model says of a name — a field, or a field of an embedded value — if it says it. */
41
+ export declare function fieldMetaOf(meta: Meta | null | undefined, name: string): FieldMeta | undefined;
24
42
  export declare function viewOf(meta: Meta | null | undefined, name: string, locale?: string): FieldView;
25
43
  /**
26
44
  * The fields a screen shows when it names none: every scalar the model holds, in the order it
@@ -30,6 +48,27 @@ export declare function viewOf(meta: Meta | null | undefined, name: string, loca
30
48
  export declare function defaultFields(meta: Meta | null | undefined): string[];
31
49
  /** The bookkeeping every framework entity carries; shown on demand, never by default. */
32
50
  export declare const BOOKKEEPING: ReadonlySet<string>;
51
+ /**
52
+ * What the framework writes on every record of its own: when and by whom it was made and last
53
+ * changed, its version, when it went to the trash. A record's audit and its activity say these;
54
+ * a form, a list inside a record and a record's facts never repeat them.
55
+ */
56
+ export declare const STAMPS: ReadonlySet<string>;
57
+ /**
58
+ * How a date is written: `numeric` — «16/11/2026», «16/11/2026 15:36» — or `literal`, its month
59
+ * in words — «16 nov 2026, 15:36» —, where space asks for a word (a phone).
60
+ *
61
+ * Context: Sincpro's standard is numeric, day first, whatever the language: a back office reads
62
+ * columns of dates, and «16 nov» and «6 nov» do not line up. The month in words was the only
63
+ * style, chosen by `Intl` for the locale. An application installs its style once
64
+ * (`FrameworkProvider dateStyle`), as it installs its zone, and every cell, field, fact and
65
+ * `useTextOf` writes it.
66
+ */
67
+ export type DateStyle = "numeric" | "literal";
68
+ /** Install how dates are written; `undefined` puts the default back (numeric). */
69
+ export declare function installDateStyle(style: DateStyle | undefined): void;
70
+ /** The style dates are written in now. */
71
+ export declare const dateStyleNow: () => DateStyle;
33
72
  /**
34
73
  * What a value reads as when a screen holds it outside any model — a total it added up, a
35
74
  * due date of its own: the same text `textOf` gives a field of that type, in `locale`, on the
@@ -37,8 +76,8 @@ export declare const BOOKKEEPING: ReadonlySet<string>;
37
76
  * to the provider's locale.
38
77
  *
39
78
  * numberTextOf("1150.5", "es-BO") -> "1.150,5"
40
- * dayTextOf("2026-03-12", "es") -> "12 mar 2026"
41
- * instantTextOf("2026-03-12T14:00:00Z", "es") -> "12 mar 2026, 10:00" (La Paz)
79
+ * dayTextOf("2026-03-12", "es") -> "12/03/2026"
80
+ * instantTextOf("2026-03-12T14:00:00Z", "es") -> "12/03/2026 10:00" (La Paz)
42
81
  * moneyTextOf({ amount: "1150.5", currency: "BOB" }, "es-BO") -> "Bs 1.150,50"
43
82
  *
44
83
  * Context: every application wrote its own money and date formatting for its own screens, on
@@ -52,15 +91,24 @@ export declare function instantTextOf(value: unknown, locale?: string): string |
52
91
  /** A money (`{ amount, currency }`) as a person reads it, rounded to its currency's decimals;
53
92
  * `null` when the value is not one. */
54
93
  export declare function moneyTextOf(value: unknown, locale?: string): string | null;
94
+ /** Install the business's currency (`"BOB"`); `undefined` forgets it. */
95
+ export declare function installCurrency(code: string | undefined): void;
96
+ /** The business's currency now, if one was installed. */
97
+ export declare const currencyNow: () => string | undefined;
98
+ /** A definition of exactly an amount and a currency: a money, whatever the entity calls it. */
99
+ export declare function isMoneyDefinition(definition: Meta | null | undefined): boolean;
55
100
  /**
56
101
  * The text a value reads as. `null` when there is nothing to read — the caller draws its own
57
102
  * «empty» (a dash in a fact, nothing in a cell).
58
103
  *
59
104
  * textOf(meta, "state", "paid", "es") -> "Pagada" (choice_labels)
60
105
  * textOf(meta, "active", true, "es") -> "sí"
61
- * textOf(meta, "due", "2026-03-12", "es") -> "12 mar 2026"
106
+ * textOf(meta, "due", "2026-03-12", "es") -> "12/03/2026" («12 mar 2026» literal)
62
107
  * textOf(meta, "total", "1150.5", "es") -> "1150,5" (exact: digits kept)
63
108
  * textOf(meta, "price", { amount: "19.9", currency: "BOB" }, "es") -> "19,90 Bs"
109
+ * textOf(meta, "monto", "25", "es") -> "Bs 25,00" (widget money, BOB installed)
110
+ * textOf(meta, "recibo", {numero: "0042", …}) -> "N.º de recibo: 0042 · …"
111
+ * textOf(meta, "recibo.numero", "0042") -> "0042"
64
112
  * textOf(meta, "lines", {items, count: {value: 30}}) -> "30 elementos"
65
113
  */
66
114
  export declare function textOf(meta: Meta | null | undefined, name: string, value: unknown, locale?: string): string | null;
@@ -10,8 +10,45 @@ const UNKNOWN = {
10
10
  sortable: false,
11
11
  ops: [],
12
12
  };
13
+ /**
14
+ * Where a name lives: a field of the model, or — written `recibo.numero` — a field of the
15
+ * definition of a value the record embeds. The model the field is described by, and its own
16
+ * name there.
17
+ *
18
+ * Context: the Meta publishes an embedded value with its fields, their labels and types (a
19
+ * payment's receipt: number, issued, concept, amount); an application wrote each of them by
20
+ * hand because nothing here could name one. A path is the same name a screen writes in a form.
21
+ */
22
+ export function fieldAt(meta, name) {
23
+ const dot = name.indexOf(".");
24
+ if (dot < 0 || meta?.fields[name] !== undefined)
25
+ return { meta, name };
26
+ const head = meta?.fields[name.slice(0, dot)];
27
+ if (head?.kind !== "embedded" || head.many === true || !head.definition)
28
+ return { meta, name };
29
+ return fieldAt(head.definition, name.slice(dot + 1));
30
+ }
31
+ /** The value a name holds in a record: a field, or a field of an embedded value
32
+ * (`recibo.numero`). */
33
+ export function valueAt(meta, record, name) {
34
+ if (record === null || record === undefined)
35
+ return undefined;
36
+ const dot = name.indexOf(".");
37
+ if (dot < 0 || meta?.fields[name] !== undefined || Object.hasOwn(record, name))
38
+ return record[name];
39
+ const head = name.slice(0, dot);
40
+ const inner = record[head];
41
+ return typeof inner === "object" && inner !== null
42
+ ? valueAt(meta?.fields[head]?.definition, inner, name.slice(dot + 1))
43
+ : undefined;
44
+ }
45
+ /** What the model says of a name — a field, or a field of an embedded value — if it says it. */
46
+ export function fieldMetaOf(meta, name) {
47
+ const place = fieldAt(meta, name);
48
+ return place.meta?.fields[place.name];
49
+ }
13
50
  function fieldOf(meta, name) {
14
- return meta?.fields[name] ?? UNKNOWN;
51
+ return fieldMetaOf(meta, name) ?? UNKNOWN;
15
52
  }
16
53
  function helpOf(field, locale) {
17
54
  const help = field.help;
@@ -21,9 +58,10 @@ function helpOf(field, locale) {
21
58
  }
22
59
  export function viewOf(meta, name, locale) {
23
60
  const field = fieldOf(meta, name);
61
+ const place = fieldAt(meta, name);
24
62
  return {
25
63
  name,
26
- label: labelOf(meta, name, locale),
64
+ label: labelOf(place.meta, place.name, locale),
27
65
  help: helpOf(field, locale),
28
66
  type: field.type,
29
67
  kind: field.kind,
@@ -47,6 +85,19 @@ export function defaultFields(meta) {
47
85
  }
48
86
  /** The bookkeeping every framework entity carries; shown on demand, never by default. */
49
87
  export const BOOKKEEPING = new Set(["version", "updated_at"]);
88
+ /**
89
+ * What the framework writes on every record of its own: when and by whom it was made and last
90
+ * changed, its version, when it went to the trash. A record's audit and its activity say these;
91
+ * a form, a list inside a record and a record's facts never repeat them.
92
+ */
93
+ export const STAMPS = new Set([
94
+ "version",
95
+ "created_at",
96
+ "created_by",
97
+ "updated_at",
98
+ "updated_by",
99
+ "archived_at",
100
+ ]);
50
101
  /** `"2026-03-12"` as a LOCAL date: `new Date("2026-03-12")` is UTC midnight, the day before
51
102
  * anywhere west of Greenwich. */
52
103
  function localDate(text) {
@@ -63,19 +114,52 @@ function decimals(text) {
63
114
  * every page. The set of shapes is tiny (three date/number styles × decimals × locales).
64
115
  */
65
116
  const formatters = new Map();
117
+ let dateStyle = "numeric";
118
+ /** Install how dates are written; `undefined` puts the default back (numeric). */
119
+ export function installDateStyle(style) {
120
+ dateStyle = style ?? "numeric";
121
+ }
122
+ /** The style dates are written in now. */
123
+ export const dateStyleNow = () => dateStyle;
66
124
  function dateFormat(locale, withTime) {
67
125
  // An instant reads on the wall clock of the installed zone; a calendar day has no zone.
68
126
  const zone = withTime ? timeZoneNow() : "";
69
- const key = `d|${locale ?? ""}|${withTime}|${zone}`;
127
+ const numeric = dateStyle === "numeric";
128
+ // Numeric is the same everywhere — day, month, year — so its locale does not matter: only
129
+ // its parts are read (`numericDate`), in Latin digits.
130
+ const key = `d|${numeric ? "" : (locale ?? "")}|${withTime}|${zone}|${dateStyle}`;
70
131
  let format = formatters.get(key);
71
132
  if (format === undefined) {
72
- format = new Intl.DateTimeFormat(locale, withTime
73
- ? { dateStyle: "medium", timeStyle: "short", timeZone: zone }
74
- : { dateStyle: "medium" });
133
+ format = numeric
134
+ ? new Intl.DateTimeFormat("en-GB", {
135
+ day: "2-digit",
136
+ month: "2-digit",
137
+ year: "numeric",
138
+ numberingSystem: "latn",
139
+ ...(withTime
140
+ ? { hour: "2-digit", minute: "2-digit", hourCycle: "h23", timeZone: zone }
141
+ : {}),
142
+ })
143
+ : new Intl.DateTimeFormat(locale, withTime
144
+ ? { dateStyle: "medium", timeStyle: "short", timeZone: zone }
145
+ : { dateStyle: "medium" });
75
146
  formatters.set(key, format);
76
147
  }
77
148
  return format;
78
149
  }
150
+ /** «DD/MM/YYYY», and « HH:mm» after it for an instant — assembled from the parts, so no
151
+ * locale reorders them (`en-US` would write the month first). */
152
+ function numericDate(date, withTime) {
153
+ const parts = dateFormat(undefined, withTime).formatToParts(date);
154
+ const part = (type) => parts.find((one) => one.type === type)?.value ?? "";
155
+ const day = `${part("day")}/${part("month")}/${part("year")}`;
156
+ return withTime ? `${day} ${part("hour")}:${part("minute")}` : day;
157
+ }
158
+ function dateText(date, locale, withTime) {
159
+ return dateStyle === "numeric"
160
+ ? numericDate(date, withTime)
161
+ : dateFormat(locale, withTime).format(date);
162
+ }
79
163
  function numberFormat(locale, kept) {
80
164
  const key = `n|${locale ?? ""}|${kept ?? ""}`;
81
165
  let format = formatters.get(key);
@@ -144,8 +228,8 @@ function displayOf(field, value) {
144
228
  * to the provider's locale.
145
229
  *
146
230
  * numberTextOf("1150.5", "es-BO") -> "1.150,5"
147
- * dayTextOf("2026-03-12", "es") -> "12 mar 2026"
148
- * instantTextOf("2026-03-12T14:00:00Z", "es") -> "12 mar 2026, 10:00" (La Paz)
231
+ * dayTextOf("2026-03-12", "es") -> "12/03/2026"
232
+ * instantTextOf("2026-03-12T14:00:00Z", "es") -> "12/03/2026 10:00" (La Paz)
149
233
  * moneyTextOf({ amount: "1150.5", currency: "BOB" }, "es-BO") -> "Bs 1.150,50"
150
234
  *
151
235
  * Context: every application wrote its own money and date formatting for its own screens, on
@@ -166,40 +250,103 @@ export function numberTextOf(value, locale) {
166
250
  export function dayTextOf(value, locale) {
167
251
  if (value === null || value === undefined || value === "")
168
252
  return null;
169
- return typeof value === "string"
170
- ? dateFormat(locale, false).format(localDate(value))
171
- : String(value);
253
+ if (typeof value !== "string")
254
+ return String(value);
255
+ const day = localDate(value.slice(0, 10));
256
+ return Number.isNaN(day.getTime()) ? value : dateText(day, locale, false);
172
257
  }
173
258
  /** An instant as a person reads it, on the wall clock of the zone the application installed. */
174
259
  export function instantTextOf(value, locale) {
175
260
  if (value === null || value === undefined || value === "")
176
261
  return null;
177
262
  const date = new Date(String(value));
178
- return Number.isNaN(date.getTime()) ? String(value) : dateFormat(locale, true).format(date);
263
+ return Number.isNaN(date.getTime()) ? String(value) : dateText(date, locale, true);
179
264
  }
180
265
  /** A money (`{ amount, currency }`) as a person reads it, rounded to its currency's decimals;
181
266
  * `null` when the value is not one. */
182
267
  export function moneyTextOf(value, locale) {
183
268
  return Money.isMoney(value) ? moneyText(value, locale) : null;
184
269
  }
270
+ /**
271
+ * The currency an amount is in when it carries none — a decimal the model draws as money
272
+ * (`widget: "money"`, «Monto (Bs.)»): the business's, installed once with the zone
273
+ * (`FrameworkProvider currency`). Without one, such an amount is rounded to two decimals and
274
+ * written with no symbol.
275
+ */
276
+ let currency;
277
+ /** Install the business's currency (`"BOB"`); `undefined` forgets it. */
278
+ export function installCurrency(code) {
279
+ currency = code;
280
+ }
281
+ /** The business's currency now, if one was installed. */
282
+ export const currencyNow = () => currency;
283
+ /** A bare amount drawn as money: in the business's currency, or rounded to cents. */
284
+ function amountText(value, locale) {
285
+ const amount = typeof value === "number" ? String(value) : value;
286
+ if (typeof amount !== "string" || Number.isNaN(Number(amount)))
287
+ return null;
288
+ if (currency !== undefined)
289
+ return moneyText({ amount, currency }, locale);
290
+ return numberFormat(locale, 2).format(Number(amount));
291
+ }
292
+ /** A definition of exactly an amount and a currency: a money, whatever the entity calls it. */
293
+ export function isMoneyDefinition(definition) {
294
+ const parts = Object.keys(definition?.fields ?? {});
295
+ return parts.length === 2 && parts.includes("amount") && parts.includes("currency");
296
+ }
297
+ /**
298
+ * A value object read through its definition: «N.º de recibo: 0042 · Concepto: Cuota» — each
299
+ * field by its label, in the order the definition declares them, the empty ones left out. A
300
+ * money stays a money; a list of values reads as how many there are.
301
+ */
302
+ function embeddedText(field, value, locale) {
303
+ const definition = field.definition;
304
+ // A money — by its value, or by a definition of an amount and a currency — is one, or nothing:
305
+ // an amount that is not one never reads as «amount: 1,50 · currency: BOB».
306
+ if (Money.isMoney(value) || isMoneyDefinition(definition))
307
+ return moneyTextOf(value, locale);
308
+ if (Array.isArray(value))
309
+ return value.length === 0 ? null : frameworkCopy().value.items(value.length, true);
310
+ if (!definition || typeof value !== "object" || value === null)
311
+ return null;
312
+ const parts = Object.keys(definition.fields)
313
+ .map((name) => {
314
+ const text = textOf(definition, name, value[name], locale);
315
+ return text === null ? null : `${labelOf(definition, name, locale)}: ${text}`;
316
+ })
317
+ .filter((part) => part !== null);
318
+ return parts.length === 0 ? null : parts.join(" · ");
319
+ }
185
320
  /**
186
321
  * The text a value reads as. `null` when there is nothing to read — the caller draws its own
187
322
  * «empty» (a dash in a fact, nothing in a cell).
188
323
  *
189
324
  * textOf(meta, "state", "paid", "es") -> "Pagada" (choice_labels)
190
325
  * textOf(meta, "active", true, "es") -> "sí"
191
- * textOf(meta, "due", "2026-03-12", "es") -> "12 mar 2026"
326
+ * textOf(meta, "due", "2026-03-12", "es") -> "12/03/2026" («12 mar 2026» literal)
192
327
  * textOf(meta, "total", "1150.5", "es") -> "1150,5" (exact: digits kept)
193
328
  * textOf(meta, "price", { amount: "19.9", currency: "BOB" }, "es") -> "19,90 Bs"
329
+ * textOf(meta, "monto", "25", "es") -> "Bs 25,00" (widget money, BOB installed)
330
+ * textOf(meta, "recibo", {numero: "0042", …}) -> "N.º de recibo: 0042 · …"
331
+ * textOf(meta, "recibo.numero", "0042") -> "0042"
194
332
  * textOf(meta, "lines", {items, count: {value: 30}}) -> "30 elementos"
195
333
  */
196
334
  export function textOf(meta, name, value, locale) {
197
335
  if (value === null || value === undefined || value === "")
198
336
  return null;
337
+ const place = fieldAt(meta, name);
338
+ if (place.meta !== meta)
339
+ return textOf(place.meta, place.name, value, locale);
199
340
  const field = fieldOf(meta, name);
200
341
  const copy = frameworkCopy();
201
342
  if (field.choices && field.choices.length > 0)
202
343
  return choiceLabelOf(meta, name, value, locale);
344
+ // An amount the model draws as money is money, though it travels bare.
345
+ if (field.widget === "money" && field.kind === "scalar") {
346
+ const amount = amountText(value, locale);
347
+ if (amount !== null)
348
+ return amount;
349
+ }
203
350
  switch (field.type) {
204
351
  case "boolean":
205
352
  return value ? copy.value.yes : copy.value.no;
@@ -224,8 +371,8 @@ export function textOf(meta, name, value, locale) {
224
371
  case "many2one":
225
372
  return typeof value === "object" ? displayOf(field, value) : String(value);
226
373
  case "embedded":
227
- // A value object has no text of its own — but a money, the one every ERP holds, does.
228
- return moneyTextOf(value, locale);
374
+ // A value object reads through its definition; a money, the one every ERP holds, as one.
375
+ return embeddedText(field, value, locale);
229
376
  default:
230
377
  return typeof value === "object" ? JSON.stringify(value) : String(value);
231
378
  }
@@ -11,8 +11,12 @@ import type { AnyRecord, Meta } from "@sincpro/criteria";
11
11
  *
12
12
  * Which field plays each part: the one the entity declares (`entity(…, { summary })`), else
13
13
  * the first conventional name the model holds (`description`, `state`/`status`, `created_at`,
14
- * …). The name is the model's own `display`. When the backend publishes these parts in its
15
- * model definition, they are read from there and the convention steps aside.
14
+ * …). The name is the model's own `display`. The convention only knows English names: a model
15
+ * whose state is `estado` and its description `descripcion` declares them —
16
+ * `entity(…, { summary: { state: "estado", description: "descripcion" } })` — or plays no such
17
+ * part (no tag on top, no colour on its rows). Nothing is guessed: an entity may hold two
18
+ * choices. It is the client's to say, never the Meta's: which field a screen shows as the state
19
+ * is presentation, and sincpro_framework does not publish it (#266, decided).
16
20
  */
17
21
  export type RecordSummary = {
18
22
  id: string;
@@ -1,6 +1,7 @@
1
1
  import { type ChangeFeed, type Entity, type MetaStore, type Transport } from "@sincpro/client-framework";
2
2
  import type { Meta } from "@sincpro/criteria";
3
3
  import { type NameBook } from "../core/names.js";
4
+ import { type DateStyle } from "../core/present.js";
4
5
  import type { Trail } from "../core/trail.js";
5
6
  import { type ReactNode } from "react";
6
7
  /**
@@ -19,7 +20,10 @@ import { type ReactNode } from "react";
19
20
  * here. A value the backend must see on every request (the active company) goes in the
20
21
  * process's context (`processContext.set({ company_id })`, @sincpro/client-framework): every
21
22
  * request under this provider carries it in `sincpro-context` (`screensTransport`), and a change
22
- * reads every screen again.
23
+ * reads every screen again. The language is one of those values: the provider puts its `locale`
24
+ * there as `lang`, so what the server writes in the call's language — a dry run's «Se eliminará
25
+ * «F-0042»», a use case's message — comes in the screen's. An application that sets `lang`
26
+ * itself keeps its own.
23
27
  *
24
28
  * What was written is the process's too (`processChanges`, @sincpro/client-framework): every write
25
29
  * a transport of the framework sends is announced there, whoever sent it — a screen, or a use
@@ -41,8 +45,15 @@ type FrameworkContextValue = {
41
45
  changes: ChangeFeed;
42
46
  /** The names of records by key, asked one request per entity (`useNameOf`). */
43
47
  names: NameBook;
48
+ /** How dates are written now — a piece that keeps its texts compares it to know when to
49
+ * write them again. */
50
+ dateStyle: DateStyle;
51
+ /** The business's currency, when one was installed. */
52
+ currency: string | undefined;
53
+ /** Each domain event's definition, by its wire name: what a history calls a fact's fields. */
54
+ events: Readonly<Record<string, Meta>>;
44
55
  };
45
- export declare function FrameworkProvider({ transport, locale, metas: seed, entities, timeZone, changes, children, }: {
56
+ export declare function FrameworkProvider({ transport, locale, metas: seed, entities, timeZone, dateStyle, currency, events, changes, children, }: {
46
57
  transport: Transport;
47
58
  /** The language labels and values are read in (`"es"`); the model's `default` without it. */
48
59
  locale?: string;
@@ -55,11 +66,24 @@ export declare function FrameworkProvider({ transport, locale, metas: seed, enti
55
66
  * the user works in: every date and time reads and is typed on its wall clock. Without it,
56
67
  * the browser's. */
57
68
  timeZone?: string;
69
+ /** How every date is written: `numeric` (the default) — «16/11/2026», «16/11/2026 15:36»,
70
+ * day first whatever the language — or `literal`, the month in words, where space asks
71
+ * for a word (a phone: `SincproApp` switches by itself). */
72
+ dateStyle?: DateStyle;
73
+ /** The business's currency (`"BOB"`): an amount the model draws as money (`widget: money`)
74
+ * travels bare, and is written in it. Without it, rounded to cents with no symbol. */
75
+ currency?: string;
76
+ /** Each domain event's definition, by its wire name — `eventMetasOf(contract)`
77
+ * (client-framework): a record's history names each fact's own fields in its words. */
78
+ events?: Readonly<Record<string, Meta>>;
58
79
  /** Where writes are announced — the process's (`processChanges`) unless a test gives another. */
59
80
  changes?: ChangeFeed;
60
81
  children: ReactNode;
61
82
  }): import("react").JSX.Element;
62
83
  export declare function useFramework(): FrameworkContextValue;
84
+ /** The provider's values, or `null` outside one: for a piece that works without it
85
+ * (`ServiceButton` runs a use case, which needs no provider). */
86
+ export declare function useFrameworkIfAny(): FrameworkContextValue | null;
63
87
  /** The declared entity a relation points at (`"Cliente"`), or `undefined`. */
64
88
  export declare function useEntityFor(target: string | undefined): Entity | undefined;
65
89
  export {};
@@ -2,11 +2,12 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { installTimeZone, metaStore, processChanges, processContext, screensTransport, } from "@sincpro/client-framework";
4
4
  import { nameBook } from "../core/names.js";
5
+ import { installCurrency, installDateStyle, } from "../core/present.js";
5
6
  import { entityFor } from "../core/relation.js";
6
7
  import { useContextValues } from "./useContextValues.js";
7
8
  import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
8
9
  const FrameworkContext = createContext(null);
9
- export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, changes = processChanges, children, }) {
10
+ export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, dateStyle = "numeric", currency, events = NO_EVENTS, changes = processChanges, children, }) {
10
11
  // Installed before the children draw, and again when it changes (another company): the
11
12
  // formatters read it, so it cannot wait for an effect.
12
13
  const zoned = useRef(null);
@@ -14,6 +15,29 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
14
15
  installTimeZone(timeZone);
15
16
  zoned.current = timeZone;
16
17
  }
18
+ // The same for how dates and money are written: read by every text, so before any draws.
19
+ // The screens' language is the call's (`lang`, sincpro_framework's `ContextKey.LANG`): before
20
+ // anything reads, so the first requests already carry it — never over one the app set.
21
+ const spoke = useRef(null);
22
+ const speak = () => {
23
+ const now = processContext.get("lang");
24
+ if (locale === undefined || now === locale)
25
+ return;
26
+ if (now !== undefined && now !== spoke.current)
27
+ return;
28
+ spoke.current = locale;
29
+ processContext.set({ lang: locale });
30
+ };
31
+ if (spoke.current === null)
32
+ speak();
33
+ // Only a new language says it again.
34
+ useEffect(speak, [locale]);
35
+ const styled = useRef(null);
36
+ if (styled.current !== `${dateStyle}|${currency ?? ""}`) {
37
+ installDateStyle(dateStyle);
38
+ installCurrency(currency);
39
+ styled.current = `${dateStyle}|${currency ?? ""}`;
40
+ }
17
41
  // One store for the provider's life: a new seed object on a re-render must not forget what
18
42
  // the screens already learned.
19
43
  const [metas] = useState(() => metaStore(seed));
@@ -32,16 +56,46 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
32
56
  // eslint-disable-next-line react-hooks/exhaustive-deps
33
57
  [screens, metas, entities, context]);
34
58
  useEffect(() => changes.follow((change) => names.changed(change)), [changes, names]);
35
- const value = useMemo(() => ({ transport: screens, locale, metas, entities, trails, context, changes, names }), [screens, locale, metas, entities, trails, context, changes, names]);
59
+ const value = useMemo(() => ({
60
+ transport: screens,
61
+ locale,
62
+ metas,
63
+ entities,
64
+ trails,
65
+ context,
66
+ changes,
67
+ names,
68
+ dateStyle,
69
+ currency,
70
+ events,
71
+ }), [
72
+ screens,
73
+ locale,
74
+ metas,
75
+ entities,
76
+ trails,
77
+ context,
78
+ changes,
79
+ names,
80
+ dateStyle,
81
+ currency,
82
+ events,
83
+ ]);
36
84
  return _jsx(FrameworkContext.Provider, { value: value, children: children });
37
85
  }
38
86
  const NO_ENTITIES = [];
87
+ const NO_EVENTS = {};
39
88
  export function useFramework() {
40
89
  const value = useContext(FrameworkContext);
41
90
  if (value === null)
42
91
  throw new Error("useFramework outside a FrameworkProvider");
43
92
  return value;
44
93
  }
94
+ /** The provider's values, or `null` outside one: for a piece that works without it
95
+ * (`ServiceButton` runs a use case, which needs no provider). */
96
+ export function useFrameworkIfAny() {
97
+ return useContext(FrameworkContext);
98
+ }
45
99
  /** The declared entity a relation points at (`"Cliente"`), or `undefined`. */
46
100
  export function useEntityFor(target) {
47
101
  const { entities, metas } = useFramework();
@@ -1,5 +1,6 @@
1
1
  "use client";
2
- import { resumingFrom } from "@sincpro/criteria";
2
+ import { resumingFrom, } from "@sincpro/criteria";
3
+ import { areGroups, NotGrouped } from "../core/groups.js";
3
4
  import { measuresOf, sumsOf } from "../core/measure.js";
4
5
  import { useFramework } from "./context.js";
5
6
  import { useWrites } from "./useWrites.js";
@@ -25,6 +26,8 @@ export function useGroups(listing, options = {}) {
25
26
  // Written by anyone — a save, a use case, a panel beside: the groups are counted again.
26
27
  const writes = useWrites(route);
27
28
  const sums = (options.sums ?? sumsOf(listing.meta)).join(",");
29
+ // Each by the function the model adds it up with (`total`), as text: compared by content.
30
+ const measured = sums === "" ? "" : JSON.stringify(measuresOf(sums.split(","), listing.meta));
28
31
  // What adds up by default is read from the model: without it yet, asking now and again when
29
32
  // it arrives would be two questions — and the groups on screen replaced under the pointer.
30
33
  const waiting = options.sums === undefined && listing.meta === null;
@@ -43,21 +46,29 @@ export function useGroups(listing, options = {}) {
43
46
  ...JSON.parse(question),
44
47
  grouping: {
45
48
  group_by: levels.map((level) => ({ ...level })),
46
- ...(sums === "" ? {} : { measures: measuresOf(sums.split(",")) }),
49
+ ...(measured === ""
50
+ ? {}
51
+ : { measures: JSON.parse(measured) }),
47
52
  pagination: { limit: MAX_GROUPS },
48
53
  },
49
54
  // One id per group is the least a grouped answer carries; the rows come on opening.
50
55
  pagination: { limit: 1 },
51
56
  };
52
57
  transport.list(route, criteria, aborter.signal).then((page) => {
53
- if (!aborter.signal.aborted)
58
+ if (aborter.signal.aborted)
59
+ return;
60
+ // Records answered to a grouped question are not groups: the list's failure, never a
61
+ // table drawing piles without a count.
62
+ if (!areGroups(page.rows))
63
+ setState({ status: "failed", buckets: [], error: new NotGrouped(route) });
64
+ else
54
65
  setState({ status: "ready", buckets: page.rows, error: null });
55
66
  }, (error) => {
56
67
  if (!aborter.signal.aborted)
57
68
  setState({ status: "failed", buckets: [], error });
58
69
  });
59
70
  return () => aborter.abort();
60
- }, [transport, route, question, levels, sums, waiting, context, writes]);
71
+ }, [transport, route, question, levels, measured, waiting, context, writes]);
61
72
  /** One page of a group: the first (`after` null) or the one the cursor points at. */
62
73
  const read = useCallback((bucket, after) => {
63
74
  const key = keyOf(bucket);
@@ -1,5 +1,7 @@
1
1
  import { type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
- import { type HistoryEntry } from "../core/history.js";
3
+ import { type FactTone, type HistoryEntry } from "../core/history.js";
4
4
  import { type DependencyList } from "react";
5
- export declare function useHistory<T extends AnyRecord>(entity: Entity<T>, id: string, deps?: DependencyList): HistoryEntry[] | undefined;
5
+ export declare function useHistory<T extends AnyRecord>(entity: Entity<T>, id: string, deps?: DependencyList, options?: {
6
+ tones?: Readonly<Record<string, FactTone>> | undefined;
7
+ }): HistoryEntry[] | undefined;