@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
@@ -13,8 +13,8 @@ export type FieldControl = {
13
13
  standalone?: boolean;
14
14
  };
15
15
  /**
16
- * The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
17
- * list of words, a text — or the one its `widget` names when the model names one of the
16
+ * The control a field's TYPE asks for — a choice, several of a choice (checks), a number, a
17
+ * date, a date and time, a yes/no, a list of words, a text — or the one its `widget` names when the model names one of the
18
18
  * framework's own: `textarea`, several lines of prose.
19
19
  * Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
20
20
  * one rule for what a value is edited with.
@@ -2,10 +2,10 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
4
4
  import { EntityPicker } from "./EntityPicker.js";
5
- import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
5
+ import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
6
6
  /**
7
- * The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
8
- * list of words, a text — or the one its `widget` names when the model names one of the
7
+ * The control a field's TYPE asks for — a choice, several of a choice (checks), a number, a
8
+ * date, a date and time, a yes/no, a list of words, a text — or the one its `widget` names when the model names one of the
9
9
  * framework's own: `textarea`, several lines of prose.
10
10
  * Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
11
11
  * one rule for what a value is edited with.
@@ -19,6 +19,10 @@ import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, T
19
19
  export function controlFor(control, type, exact, choices, widget) {
20
20
  const { value, set } = control;
21
21
  const named = control.standalone === true ? { "aria-label": control.label } : {};
22
+ // Several of the values at once — a list whose values are a choice: each one a check, the
23
+ // list's label above them.
24
+ if (choices.length > 0 && type.endsWith("[]"))
25
+ return (_jsx(CheckList, { label: control.label, items: choices.map((one) => ({ value: String(one.value), label: one.label })), value: Array.isArray(value) ? value.map(String) : [], onChange: set }));
22
26
  if (choices.length > 0)
23
27
  return (_jsx(Select, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set, ...named }));
24
28
  switch (type) {
@@ -26,9 +26,14 @@ import type { ReactNode } from "react";
26
26
  * A one2many is a block: its lines (`lines`) or its related list (`list`), each with every piece
27
27
  * replaceable the screen's way.
28
28
  *
29
+ * A value the record embeds (a payment's receipt) is drawn from its definition: `name="recibo"`
30
+ * is a section of its fields, and `name="recibo.numero"` is one of them — its label and type the
31
+ * definition's, read only when the embedded value is, and written back into the value whole.
32
+ *
29
33
  * <RecordField record={invoice} name="due_date" />
30
34
  * <RecordField record={invoice} name="customer_id" />
31
35
  * <RecordField record={invoice} name="lines" lines={{ controls: { qty: Stepper } }} />
36
+ * <RecordField record={pago} name="recibo.numero" />
32
37
  */
33
38
  export declare function RecordField<T extends Record<string, unknown>>({ record, name, as, bare, lines: look, list: listed, }: {
34
39
  record: RecordReading<T>;
@@ -42,7 +47,7 @@ export declare function RecordField<T extends Record<string, unknown>>({ record,
42
47
  /** A one2many of a declared entity, the screen's way: anything `EntityList` takes — its
43
48
  * cells, row actions, commands, faces of its own. What it passes wins over the defaults. */
44
49
  list?: Omit<EntityListProps<AnyRecord>, "listing" | "embedded">;
45
- }): import("react").JSX.Element | null;
50
+ }): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
46
51
  /**
47
52
  * The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
48
53
  * off while saving, and off with the reason while a required field is empty.
@@ -1,11 +1,11 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import {} from "@sincpro/client-framework";
4
4
  import { choicesOf } from "@sincpro/criteria";
5
5
  import { frameworkCopy } from "../../core/copy.js";
6
6
  import { errorAt } from "../../core/edit.js";
7
7
  import { editableLines } from "../../core/lines.js";
8
- import { textOf, viewOf } from "../../core/present.js";
8
+ import { fieldAt, fieldMetaOf, isMoneyDefinition, textOf, valueAt, viewOf, } from "../../core/present.js";
9
9
  import { relationFieldOf } from "../../core/relation.js";
10
10
  import { useEntityFor, useFramework } from "../../react/context.js";
11
11
  import { useNameOf } from "../../react/useNameOf.js";
@@ -15,6 +15,15 @@ import { useRecordOpening } from "./opening.js";
15
15
  import { RecordLines } from "./record.js";
16
16
  import { RelatedList } from "./RelatedList.js";
17
17
  import { Checkbox, Field, FormSection, ReadValue, RelationValue, } from "@sincpro/web-ui";
18
+ /** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
19
+ function setAt(value, path, next) {
20
+ const base = typeof value === "object" && value !== null ? value : {};
21
+ const dot = path.indexOf(".");
22
+ if (dot < 0)
23
+ return { ...base, [path]: next };
24
+ const head = path.slice(0, dot);
25
+ return { ...base, [head]: setAt(base[head], path.slice(dot + 1), next) };
26
+ }
18
27
  /** A key alone, read: the name of the record it points at, asked once by key — the key until
19
28
  * then, and when nothing answers. */
20
29
  function KeyValue({ target, id, ...rest }) {
@@ -41,15 +50,32 @@ function KeyValue({ target, id, ...rest }) {
41
50
  * A one2many is a block: its lines (`lines`) or its related list (`list`), each with every piece
42
51
  * replaceable the screen's way.
43
52
  *
53
+ * A value the record embeds (a payment's receipt) is drawn from its definition: `name="recibo"`
54
+ * is a section of its fields, and `name="recibo.numero"` is one of them — its label and type the
55
+ * definition's, read only when the embedded value is, and written back into the value whole.
56
+ *
44
57
  * <RecordField record={invoice} name="due_date" />
45
58
  * <RecordField record={invoice} name="customer_id" />
46
59
  * <RecordField record={invoice} name="lines" lines={{ controls: { qty: Stepper } }} />
60
+ * <RecordField record={pago} name="recibo.numero" />
47
61
  */
48
62
  export function RecordField({ record, name, as, bare = false, lines: look, list: listed, }) {
49
63
  const { meta, locale, edit } = record;
50
64
  const view = viewOf(meta, name, locale);
51
- const state = edit.state(name);
52
- const relation = relationFieldOf(meta, name);
65
+ // A field of an embedded value (`recibo.numero`): the embedded value's state, its own hints.
66
+ const place = fieldAt(meta, name);
67
+ const nested = place.meta !== meta;
68
+ const head = nested ? name.slice(0, name.indexOf(".")) : name;
69
+ const part = nested ? place.meta?.fields[place.name] : undefined;
70
+ const whole = edit.state(head);
71
+ const state = nested
72
+ ? {
73
+ visible: whole.visible,
74
+ readonly: whole.readonly || part?.readonly === true,
75
+ required: !whole.readonly && part?.required === true,
76
+ }
77
+ : whole;
78
+ const relation = nested ? undefined : relationFieldOf(meta, name);
53
79
  const target = useEntityFor(relation?.target);
54
80
  const opening = useRecordOpening();
55
81
  const { metas } = useFramework();
@@ -67,6 +93,17 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
67
93
  // project's channels, an inventory's components) — no model of its own, no id — is edited the
68
94
  // same way as lines: a whole list, local keys, through the record's own save.
69
95
  const own = meta?.fields[name];
96
+ const parts = Object.keys(own?.definition?.fields ?? {});
97
+ if (as === undefined &&
98
+ own?.type === "embedded" &&
99
+ own.many !== true &&
100
+ own.definition &&
101
+ own.widget !== "money" &&
102
+ !isMoneyDefinition(own.definition)) {
103
+ // One value the record embeds: its fields, each by its label — a section of the record.
104
+ const block = parts.map((one) => (_jsx(RecordField, { record: record, name: `${name}.${one}` }, one)));
105
+ return bare ? _jsx(_Fragment, { children: block }) : _jsx(FormSection, { title: view.label, children: block });
106
+ }
70
107
  if (as === undefined && own?.type === "embedded" && own.many === true && own.definition) {
71
108
  // A page of them stays read only, as a one2many's: written back whole it would drop what
72
109
  // it did not bring.
@@ -102,16 +139,19 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
102
139
  })()), ...listed }));
103
140
  return bare ? list : _jsx(FormSection, { title: view.label, children: list });
104
141
  }
105
- const value = edit.values[name];
142
+ const value = nested ? valueAt(meta, edit.values, name) : edit.values[name];
106
143
  const error = errorAt(edit.errors, name);
107
144
  const control = {
108
145
  value,
109
- set: (next) => edit.set(name, next),
146
+ // A field of an embedded value is written back into the value, whole.
147
+ set: nested
148
+ ? (next) => edit.set(head, setAt(edit.values[head], name.slice(head.length + 1), next))
149
+ : (next) => edit.set(name, next),
110
150
  readonly: state.readonly,
111
151
  invalid: error !== undefined,
112
152
  label: view.label,
113
153
  };
114
- const field = meta?.fields[name];
154
+ const field = fieldMetaOf(meta, name);
115
155
  /** A many2one of a declared entity: chosen by the server's literal search, opened where the
116
156
  * view says. Written by its key; read by the record it points at. */
117
157
  function manyToOne() {
@@ -141,9 +181,17 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
141
181
  },
142
182
  }) }));
143
183
  }
184
+ // A list of checks names itself, as a checkbox does: inside a `Field` it would read twice.
185
+ const choices = choicesOf(place.meta, place.name, locale);
186
+ if (as === undefined &&
187
+ !state.readonly &&
188
+ view.type.endsWith("[]") &&
189
+ choices.length > 0 &&
190
+ relation === undefined)
191
+ return controlFor(control, view.type, false, choices, field?.widget);
144
192
  if (view.type === "boolean" && as === undefined)
145
193
  return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
146
- return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choicesOf(meta, name, locale), field?.widget)) }));
194
+ return (_jsx(Field, { label: view.label, required: state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choices, field?.widget)) }));
147
195
  }
148
196
  /**
149
197
  * The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { describeRows } from "@sincpro/criteria";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
- import { textOf, viewOf } from "../../core/present.js";
5
+ import { textOf, valueAt, viewOf } from "../../core/present.js";
6
6
  import { relatedOf } from "../../core/related.js";
7
7
  import { relationFieldOf } from "../../core/relation.js";
8
8
  import { useEntityFor } from "../../react/context.js";
@@ -20,6 +20,7 @@ import { List, RelationValue, } from "@sincpro/web-ui";
20
20
  *
21
21
  * <Record.Paper>
22
22
  * <Record.Facts fields={factsOf(record, meta, ["number", "customer", "due"])} />
23
+ * <Record.Facts fields={factsOf(pago, meta, ["recibo.numero", "recibo.concepto"])} />
23
24
  * <Record.Pages>
24
25
  * <Record.Page id="lines" label={labelOf(meta, "lines")} count={countOf(record, "lines")}>
25
26
  * <RecordLines record={record} meta={meta} name="lines" />
@@ -35,7 +36,9 @@ export function factsOf(record, meta, names, options = {}) {
35
36
  const relation = relationFieldOf(meta, name);
36
37
  return {
37
38
  label: view.label,
38
- value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : ((textOf(meta, name, record[name], options.locale) ?? EMPTY)),
39
+ value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : (
40
+ // A field of an embedded value is named by its path: `recibo.numero`.
41
+ (textOf(meta, name, valueAt(meta, record, name), options.locale) ?? EMPTY)),
39
42
  ...(view.help === undefined ? {} : { hint: view.help }),
40
43
  ...(name === meta?.identity ? { mono: true } : {}),
41
44
  };
@@ -2,8 +2,9 @@ import { type ChangeFeed, type Entity, type Transport } from "@sincpro/client-fr
2
2
  import type { Meta } from "@sincpro/criteria";
3
3
  import { type ComposerSkin, type OnViewError, type ResourceRef, type ViewSpec, type WorkspaceStore } from "@sincpro/web-composer";
4
4
  import { type CacheOptions } from "../../core/cache.js";
5
+ import type { DateStyle } from "../../core/present.js";
5
6
  import { type ReactNode } from "react";
6
- export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, onViewError, changes, }: {
7
+ export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, events, workspace: given, bar, onViewError, changes, }: {
7
8
  transport: Transport;
8
9
  /** The entities as composer views — `entityView(…)` — and any other view of the app. */
9
10
  views: readonly ViewSpec[];
@@ -28,6 +29,14 @@ export declare function SincproApp({ transport, views, start, language, metas, e
28
29
  /** Where the business is (`"America/La_Paz"`): every date and time on its wall clock.
29
30
  * Without it, the browser's. */
30
31
  timeZone?: string;
32
+ /** How dates are written. Without it, numeric — «16/11/2026» — and the month in words on a
33
+ * phone, where a word reads better than a column of digits. */
34
+ dateStyle?: DateStyle;
35
+ /** The business's currency (`"BOB"`): an amount the model draws as money is written in it. */
36
+ currency?: string;
37
+ /** Each domain event's definition by its wire name (`eventMetasOf(contract)`): a history
38
+ * names each fact's own fields in its words. */
39
+ events?: Readonly<Record<string, Meta>>;
31
40
  /** The workspace, when the app needs to reach it (a menu of its bar): composer's
32
41
  * `useWorkspace()`. Without it, the app keeps one of its own. */
33
42
  workspace?: WorkspaceStore;
@@ -2,13 +2,13 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { processChanges, processContext, reportError, } from "@sincpro/client-framework";
4
4
  import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
5
- import { createRegistry, formatRef } from "@sincpro/web-composer/domain";
5
+ import { createRegistry, formatRef, PHONE_WIDTH } from "@sincpro/web-composer/domain";
6
6
  import { cachedTransport, } from "../../core/cache.js";
7
7
  import { installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "../../core/copy.js";
8
8
  import { FrameworkProvider } from "../../react/context.js";
9
9
  import { webUiSkin } from "./skin.js";
10
10
  import { installCopy, SPANISH_COPY, ToastProvider } from "@sincpro/web-ui";
11
- import { useEffect, useMemo, useState } from "react";
11
+ import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
12
12
  /**
13
13
  * The application context in one place: who answers (the transport), in which language, which
14
14
  * model definitions are already known, the toasts, and the workspace with its views, ⌘K and
@@ -25,9 +25,22 @@ import { useEffect, useMemo, useState } from "react";
25
25
  * const workspace = useWorkspace();
26
26
  * <SincproApp workspace={workspace} bar={<Menu onOpen={(ref) => workspace.push(ref)} />} … />
27
27
  */
28
+ /** Narrower than composer's phone (`PHONE_WIDTH`): the workspace fills the window here, so the
29
+ * window's width is the workspace's. */
30
+ const PHONE = `(max-width: ${PHONE_WIDTH - 1}px)`;
31
+ function onPhone(changed) {
32
+ if (typeof window === "undefined" || window.matchMedia === undefined)
33
+ return () => undefined;
34
+ const query = window.matchMedia(PHONE);
35
+ query.addEventListener("change", changed);
36
+ return () => query.removeEventListener("change", changed);
37
+ }
38
+ const isPhone = () => typeof window !== "undefined" && window.matchMedia !== undefined
39
+ ? window.matchMedia(PHONE).matches
40
+ : false;
28
41
  /** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
29
42
  const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
30
- export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
43
+ export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
31
44
  // Installed once, before anything draws: the three tables are module state of their packages.
32
45
  useState(() => {
33
46
  if (language === "es") {
@@ -62,6 +75,7 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
62
75
  // The cache is read once, as `cached` is.
63
76
  // eslint-disable-next-line react-hooks/exhaustive-deps
64
77
  }, [cached, changes]);
78
+ const phone = useSyncExternalStore(onPhone, isPhone, () => false);
65
79
  const own = useWorkspace();
66
80
  const workspace = given ?? own;
67
81
  const registry = useMemo(() => createRegistry(views), [views]);
@@ -71,5 +85,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
71
85
  // The first screen only: a re-render must not push it again.
72
86
  // eslint-disable-next-line react-hooks/exhaustive-deps
73
87
  }, [workspace]);
74
- return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
88
+ return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), dateStyle: dateStyle ?? (phone ? "literal" : "numeric"), ...(currency === undefined ? {} : { currency }), ...(events === undefined ? {} : { events }), children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
75
89
  }
@@ -18,8 +18,10 @@ import { type ComponentType } from "react";
18
18
  * (`entity.newRef(values)`), which `useRecord(entity, resource)` fills with the model's defaults
19
19
  * and what the reference carries.
20
20
  *
21
- * ⌘K asks the server with `matching` — 8 records, identity and display — the same question a
22
- * many2one asks. The model definition is asked for once, on the first search, unless `meta`
21
+ * ⌘K asks the server with `matching` — 8 records — the same question a many2one asks. Each hit
22
+ * says what it is (`noun`, composer's) and, beside it, what tells it apart: the entity's own
23
+ * `option` look, else its summary's description or type — never its key, which tells a person
24
+ * nothing a UUID long («María Fernanda Apaza Quispe 01a1ebd4…»). The model definition is asked for once, on the first search, unless `meta`
23
25
  * is handed over. A list whose route answers a SCOPE by its params (forge's `/projects`
24
26
  * without `tenant_id` is the projects with NO tenant) is searched in the one ⌘K should see:
25
27
  * `search: { params }`.
@@ -35,6 +37,9 @@ export type EntityViewOptions = {
35
37
  transport: Transport;
36
38
  /** How it reads in the palette, a panel's frame and the breadcrumb. */
37
39
  name: string;
40
+ /** What ONE of its records is called — «Colegiado» —, beside each record ⌘K finds, so two
41
+ * «María» of different kinds say which is which. Without it, the model's own name. */
42
+ noun?: string;
38
43
  /** Its list. Without it, `EntityList` over the entity: search bar, pages, «Nuevo». */
39
44
  list?: ComponentType<ViewProps>;
40
45
  /** Its record. Without it, `EntityRecord`: the form the model describes. */
@@ -1,9 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { isEntityId, listRoute, NEW_PARAM, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
4
- import { matching } from "@sincpro/criteria";
3
+ import { isEntityId, listRoute, NEW_PARAM, processContext, scopeNameOf, scopeOfRef, } from "@sincpro/client-framework";
4
+ import { matching, nameOf } from "@sincpro/criteria";
5
5
  import { usePhone, } from "@sincpro/web-composer";
6
6
  import { lookupOf } from "../../core/lookup.js";
7
+ import { summaryOf } from "../../core/summary.js";
7
8
  import { ListScopeProvider } from "../../react/scope.js";
8
9
  import { useListing } from "../../react/useListing.js";
9
10
  import { EntityList } from "../list/EntityList.js";
@@ -49,6 +50,11 @@ function recordOf(entity, title) {
49
50
  return (_jsx(EntityRecord, { ...props, entity: entity, ...(title === undefined ? {} : { title }) }));
50
51
  };
51
52
  }
53
+ /** The language the screens speak now — the provider puts it in the process's context. */
54
+ function localeNow() {
55
+ const lang = processContext.get("lang");
56
+ return typeof lang === "string" && lang !== "" ? lang : undefined;
57
+ }
52
58
  /**
53
59
  * What a reference reads as before its view names it — a crumb whose view is not mounted, a
54
60
  * record still loading: the list is the view's name (with its cut's, `entity.listRef`); a record
@@ -85,6 +91,12 @@ export function entityView(entity, options) {
85
91
  return {
86
92
  domain: entity.domain,
87
93
  kind: entity.kind,
94
+ // Read when ⌘K draws a hit, so the model's own name is there once a search brought it.
95
+ get noun() {
96
+ if (options.noun !== undefined)
97
+ return options.noun;
98
+ return meta?.name === undefined ? undefined : nameOf(meta, localeNow());
99
+ },
88
100
  title: (ref) => titleOf(ref, options.name),
89
101
  goto: options.goto ?? true,
90
102
  ...(options.icon === undefined ? {} : { icon: options.icon }),
@@ -97,11 +109,19 @@ export function entityView(entity, options) {
97
109
  if (meta?.search == null)
98
110
  return [];
99
111
  const page = await options.transport.list(route, matching(meta, query));
112
+ const known = meta;
113
+ const locale = localeNow();
100
114
  // ⌘K writes text: of the entity's look of a choice, its name and its meta.
101
115
  const look = presentationOf(entity).option;
102
- return lookupOf(meta, page.rows, entity.summary).map((one) => {
116
+ return lookupOf(known, page.rows, entity.summary).map((one) => {
103
117
  const own = look === undefined || one.record === undefined ? {} : look(one.record);
104
- const detail = own.meta ?? one.detail;
118
+ const summary = one.record === undefined
119
+ ? undefined
120
+ : summaryOf(known, one.record, {
121
+ fields: entity.summary ?? {},
122
+ ...(locale === undefined ? {} : { locale }),
123
+ });
124
+ const detail = own.meta ?? summary?.description ?? summary?.type ?? undefined;
105
125
  return {
106
126
  ref: entity.ref(one.id),
107
127
  label: own.name ?? one.label,
@@ -13,7 +13,9 @@ export type Stamp = {
13
13
  * does, as values: read the record for editing, follow the workspace's breadcrumb, tell the
14
14
  * workspace its name and its unsaved work, read its history, step to its neighbours in the list
15
15
  * it was opened from, and say its name, state, unsaved work, refusal and authorship the way
16
- * web-ui's `Record` takes them.
16
+ * web-ui's `Record` takes them. A screen that draws its own history passes `history: false`, and
17
+ * nothing asks for it. The state's tag and each fact of the history take the colours the entity
18
+ * was presented with (`presented(entity, { tones, facts })`).
17
19
  *
18
20
  * function InvoiceScreen(props: ViewProps) {
19
21
  * const screen = useRecordScreen(invoices, props);
@@ -37,11 +39,13 @@ export type Stamp = {
37
39
  */
38
40
  export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>, { api, resource }: Pick<ViewProps, "api" | "resource">, options?: {
39
41
  title?: ((record: T) => string | null) | undefined;
42
+ /** `false`: the screen draws its own history — it is not read here. */
43
+ history?: boolean | undefined;
40
44
  }): {
41
45
  reading: RecordReading<T>;
42
46
  crumbs: readonly import("@sincpro/web-composer").Crumb[];
43
47
  history: import("../../index.js").HistoryEntry[] | undefined;
44
- summary: import("../../index.js").RecordSummary | undefined;
48
+ summary: import("../../core/summary.js").RecordSummary | undefined;
45
49
  /** web-ui `Record`'s own props: where it is drawn, its name, its unsaved work, its refusal. */
46
50
  record: {
47
51
  error?: string | undefined;
@@ -49,6 +53,7 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
49
53
  placement: "page" | "card";
50
54
  identity: {
51
55
  tag?: {
56
+ tone?: import("@sincpro/web-ui").Tone | undefined;
52
57
  label: string;
53
58
  } | undefined;
54
59
  subtitle?: string | undefined;
@@ -2,15 +2,17 @@
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { TRAIL_PARAM } from "@sincpro/client-framework";
4
4
  import { labelOf, nameOf } from "@sincpro/criteria";
5
- import { useCrumbs } from "@sincpro/web-composer";
5
+ import { useCrumbs, usePhone } from "@sincpro/web-composer";
6
6
  import { frameworkCopy } from "../../core/copy.js";
7
7
  import { explain } from "../../core/explain.js";
8
8
  import { formOf } from "../../core/form.js";
9
+ import { summaryFieldsOf } from "../../core/summary.js";
9
10
  import { placeOf, stepIn } from "../../core/trail.js";
10
11
  import { useFramework } from "../../react/context.js";
11
12
  import { useHistory } from "../../react/useHistory.js";
12
13
  import { useRecord } from "../../react/useRecord.js";
13
14
  import { useSummaryOf } from "../../react/useSummary.js";
15
+ import { presentationOf } from "../list/presentation.js";
14
16
  import { dirtyOf, RecordField } from "../record/edit.js";
15
17
  import { RecordLifecycle } from "../record/RecordLifecycle.js";
16
18
  import { Refused } from "../Refused.js";
@@ -43,7 +45,9 @@ function refusalOf(failure) {
43
45
  * does, as values: read the record for editing, follow the workspace's breadcrumb, tell the
44
46
  * workspace its name and its unsaved work, read its history, step to its neighbours in the list
45
47
  * it was opened from, and say its name, state, unsaved work, refusal and authorship the way
46
- * web-ui's `Record` takes them.
48
+ * web-ui's `Record` takes them. A screen that draws its own history passes `history: false`, and
49
+ * nothing asks for it. The state's tag and each fact of the history take the colours the entity
50
+ * was presented with (`presented(entity, { tones, facts })`).
47
51
  *
48
52
  * function InvoiceScreen(props: ViewProps) {
49
53
  * const screen = useRecordScreen(invoices, props);
@@ -69,7 +73,8 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
69
73
  const reading = useRecord(entity, resource);
70
74
  const crumbs = useCrumbs(api);
71
75
  useRecordInWorkspace(api, reading, options);
72
- const history = useHistory(entity, reading.isNew ? "" : reading.id, [reading.record]);
76
+ const look = presentationOf(entity);
77
+ const history = useHistory(entity, reading.isNew || options.history === false ? "" : reading.id, [reading.record], { tones: look.facts });
73
78
  const summarize = useSummaryOf(entity);
74
79
  const copy = frameworkCopy().record;
75
80
  // Opened from a list: where it stands in it, and its neighbours (`Trail`).
@@ -90,6 +95,13 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
90
95
  };
91
96
  const ready = reading.status === "ready";
92
97
  const summary = ready && !reading.isNew ? summarize(reading.record, reading.meta) : undefined;
98
+ // The state's colour is the application's, declared once with the entity.
99
+ const stateField = ready
100
+ ? summaryFieldsOf(reading.meta, reading.record, entity.summary).state
101
+ : undefined;
102
+ const tone = stateField === undefined || !ready
103
+ ? undefined
104
+ : look.tones?.[stateField]?.[String(reading.record[stateField])];
93
105
  const dirty = ready ? dirtyOf(reading) : undefined;
94
106
  const failure = reading.edit.failure;
95
107
  // Who, only when the record says it (an author is optional: the line then says only when).
@@ -117,7 +129,9 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
117
129
  summary?.name ??
118
130
  (reading.isNew ? copy.creating(nameOf(reading.meta, reading.locale) || "") : ""),
119
131
  ...(summary?.type == null ? {} : { subtitle: summary.type }),
120
- ...(summary?.state == null ? {} : { tag: { label: summary.state } }),
132
+ ...(summary?.state == null
133
+ ? {}
134
+ : { tag: { label: summary.state, ...(tone === undefined ? {} : { tone }) } }),
121
135
  },
122
136
  ...(dirty === undefined ? {} : { dirty }),
123
137
  // The refusal in words; its heading when the server said nothing more (no detail).
@@ -141,13 +155,22 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
141
155
  const { reading, crumbs, history, pager } = screen;
142
156
  const [page, setPage] = useState(undefined);
143
157
  const copy = frameworkCopy().record;
158
+ // On a phone a form is one column, its label over its value: two side by side at 400 px
159
+ // squeezed a text area beside its word (web-ui's grid does not narrow by itself).
160
+ const phone = usePhone(api);
144
161
  if (reading.status === "loading")
145
162
  return _jsx(Skeleton, { rows: 6, label: copy.loading });
146
163
  if (reading.status === "failed")
147
164
  return _jsx(Refused, { error: reading.error, onRetry: reading.reload });
148
165
  const { meta, locale, edit } = reading;
149
166
  const layout = formOf(meta, entity.summary);
150
- const shown = fields ?? layout.fields;
167
+ // What the header already says — the name, the state, the type — is not said again as a
168
+ // field, unless it can be typed in now: then the field is its control, not a repetition.
169
+ const parts = summaryFieldsOf(meta, reading.record ?? {}, entity.summary);
170
+ const said = new Set([meta?.display, parts.state, parts.type]);
171
+ const shown = fields ??
172
+ layout.fields.filter((name) => reading.isNew || !said.has(name) || !edit.state(name).readonly);
173
+ const columns = phone || (api.surface !== "page" && api.surface !== "modal") ? 1 : 2;
151
174
  // The record's own lifecycle (its `Delete`, its trash) beside the screen's commands; once it is
152
175
  // out of every reading the surface closes — every list that showed it reads again by itself.
153
176
  const lifecycle = reading.isNew ||
@@ -157,7 +180,9 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
157
180
  const own = actions?.(reading) ?? null;
158
181
  const ownActions = own === null && lifecycle === null ? null : (_jsxs(_Fragment, { children: [own, lifecycle] }));
159
182
  const tabs = pages ?? layout.pages;
160
- return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: api.surface === "page" || api.surface === "modal" ? 2 : 1, children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), edit.advice
183
+ return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: phone ? "stacked" : "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: columns, children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), fields !== undefined
184
+ ? null
185
+ : layout.sections.map((name) => (_jsx(FormSection, { title: labelOf(meta, name, locale), columns: columns, children: Object.keys(meta?.fields[name]?.definition?.fields ?? {}).map((part) => (_jsx(RecordField, { record: reading, name: `${name}.${part}` }, part))) }, name))), edit.advice
161
186
  .filter((one) => (one.path?.length ?? 0) <= 1)
162
187
  .map((one) => (_jsx(Callout, { tone: "info", title: one.message, children: null }, one.message))), tabs.length === 0 || reading.isNew ? null : (_jsx(Record.Pages, { current: page ?? tabs[0], onChange: setPage, children: tabs.map((name) => (_jsx(Record.Page, { id: name, label: labelOf(meta, name, locale), children: _jsx(RecordField, { record: reading, name: name, bare: true }) }, name))) })), screen.audit === undefined ? null : _jsx(Record.Audit, { ...screen.audit })] }), history === undefined ? null : _jsx(Record.Activity, { events: history })] }));
163
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -40,8 +40,8 @@
40
40
  "@opentelemetry/resources": "^3.1.0",
41
41
  "@opentelemetry/sdk-trace": "^3.1.0",
42
42
  "@sentry/browser": "^11.11.0",
43
- "@sincpro/client-framework": "^2.0.0",
44
- "@sincpro/criteria": "^2.1.0",
43
+ "@sincpro/client-framework": "^2.2.0",
44
+ "@sincpro/criteria": "^2.2.2",
45
45
  "@sincpro/criteria-react": "^2.1.0",
46
46
  "@sincpro/web-composer": "^1.7.0",
47
47
  "@sincpro/web-ui": "^2.1.0",
@@ -72,11 +72,11 @@
72
72
  "@opentelemetry/resources": "3.1.0",
73
73
  "@opentelemetry/sdk-trace": "3.1.0",
74
74
  "@sentry/browser": "11.11.0",
75
- "@sincpro/client-framework": "^2.0.0",
76
- "@sincpro/criteria": "^2.1.0",
75
+ "@sincpro/client-framework": "^2.2.0",
76
+ "@sincpro/criteria": "^2.2.2",
77
77
  "@sincpro/criteria-react": "^2.1.0",
78
- "@sincpro/web-composer": "^1.7.0",
79
- "@sincpro/web-ui": "^2.2.0",
78
+ "@sincpro/web-composer": "^1.8.0",
79
+ "@sincpro/web-ui": "^2.4.0",
80
80
  "@storybook/addon-a11y": "10.6.5",
81
81
  "@storybook/addon-docs": "10.6.5",
82
82
  "@storybook/addon-mcp": "10.6.5",