@sincpro/web-framework 3.15.0 → 3.17.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.
@@ -1,5 +1,5 @@
1
1
  import { type AnyRecord, type Bucket, type Meta } from "@sincpro/criteria";
2
- import type { GroupLevel } from "../../react/useGroups.js";
2
+ import type { GroupLevel, Groups } from "../../react/useGroups.js";
3
3
  import { type GroupableField, type Pile } from "@sincpro/web-ui";
4
4
  /**
5
5
  * The fields the model says may split a set (`groupable`), in its words. The identity splits
@@ -14,10 +14,18 @@ import { type GroupableField, type Pile } from "@sincpro/web-ui";
14
14
  * names kept here.
15
15
  */
16
16
  export declare function groupableOf(meta: Meta | null, locale?: string, only?: readonly string[]): GroupableField[];
17
+ /** The levels below the first, as `useGroups` reads them: each when its group opens, a page at
18
+ * a time. Without it, the levels below are the ones each bucket carries (`bucket.groups`). */
19
+ export type GroupTree<T> = Pick<Groups<T>, "groupsOf" | "groupsCountOf" | "bringsGroups" | "isDeepest" | "errorOf">;
17
20
  /**
18
21
  * The server's groups as piles, with the words a person reads, and each pile's group so that
19
22
  * opening one reads its rows. Rows sit only on the deepest level, once read.
20
23
  *
24
+ * With `tree` (a `useGroups`), the level below a pile is the one read when it opened, and the
25
+ * pile says how many groups that level makes in all (`pilesCount`) and what its next page
26
+ * brings (`morePiles`) — web-ui 2.19 draws «Ver N grupos más» from them. A group whose reading
27
+ * failed says why beside its name.
28
+ *
21
29
  * What the server summed for a group is its `totals` — web-ui (2.9) says each figure under its
22
30
  * column in a grouped table and a sheet, as Odoo's grouped list — and, in words beside the
23
31
  * group's name (`detail`), what no column on screen says: a board's card has no columns.
@@ -26,7 +34,7 @@ export declare function pilesOf<T extends AnyRecord>(buckets: readonly Bucket<T>
26
34
  /** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
27
35
  brings?: (bucket: Bucket<T>) => number | false | undefined,
28
36
  /** The figures a column on screen already says under itself: not said again in words. */
29
- underColumns?: ReadonlySet<string>): {
37
+ underColumns?: ReadonlySet<string>, tree?: GroupTree<T>): {
30
38
  piles: Pile<T>[];
31
39
  bucketAt: ReadonlyMap<string, Bucket<T>>;
32
40
  deepest: number;
@@ -1,5 +1,6 @@
1
1
  import { labelOf } from "@sincpro/criteria";
2
2
  import { frameworkCopy } from "../../core/copy.js";
3
+ import { explain } from "../../core/explain.js";
3
4
  import { detailOf } from "../../core/measure.js";
4
5
  import { textOf } from "../../core/present.js";
5
6
  import { dateLabel, pathKey, } from "@sincpro/web-ui";
@@ -51,6 +52,11 @@ function figureOf(value) {
51
52
  * The server's groups as piles, with the words a person reads, and each pile's group so that
52
53
  * opening one reads its rows. Rows sit only on the deepest level, once read.
53
54
  *
55
+ * With `tree` (a `useGroups`), the level below a pile is the one read when it opened, and the
56
+ * pile says how many groups that level makes in all (`pilesCount`) and what its next page
57
+ * brings (`morePiles`) — web-ui 2.19 draws «Ver N grupos más» from them. A group whose reading
58
+ * failed says why beside its name.
59
+ *
54
60
  * What the server summed for a group is its `totals` — web-ui (2.9) says each figure under its
55
61
  * column in a grouped table and a sheet, as Odoo's grouped list — and, in words beside the
56
62
  * group's name (`detail`), what no column on screen says: a board's card has no columns.
@@ -59,7 +65,7 @@ export function pilesOf(buckets, levels, meta, locale, rowsOf,
59
65
  /** What a group's next «more» brings (`Pile.more`); omitted, web-ui says nothing about it. */
60
66
  brings,
61
67
  /** The figures a column on screen already says under itself: not said again in words. */
62
- underColumns = new Set()) {
68
+ underColumns = new Set(), tree) {
63
69
  const bucketAt = new Map();
64
70
  const none = frameworkCopy().list.noValue;
65
71
  const labelFor = (bucket, depth, key) => {
@@ -81,7 +87,11 @@ underColumns = new Set()) {
81
87
  return figure === undefined ? [] : [[field, figure]];
82
88
  }));
83
89
  const inWords = measures.filter(([field]) => !underColumns.has(field));
84
- const detail = detailOf(meta, Object.fromEntries(inWords), locale);
90
+ const failure = tree?.errorOf(bucket);
91
+ const refused = failure === null || failure === undefined
92
+ ? undefined
93
+ : (({ heading, sentence }) => [heading, sentence].filter(Boolean).join(". "))(explain(failure));
94
+ const detail = refused ?? detailOf(meta, Object.fromEntries(inWords), locale);
85
95
  return {
86
96
  ...(Object.keys(totals).length === 0 ? {} : { totals }),
87
97
  ...(detail === undefined ? {} : { detail }),
@@ -95,7 +105,10 @@ underColumns = new Set()) {
95
105
  const key = bucket.value === null || bucket.value === undefined ? "" : String(bucket.value);
96
106
  const path = [...above, key];
97
107
  bucketAt.set(pathKey(path), bucket);
98
- const below = bucket.groups ?? [];
108
+ const deepest = tree === undefined ? (bucket.groups ?? []).length === 0 : tree.isDeepest(bucket);
109
+ const below = (tree === undefined ? bucket.groups : tree.groupsOf(bucket)) ?? [];
110
+ const counted = deepest ? undefined : tree?.groupsCountOf(bucket);
111
+ const next = deepest || tree === undefined ? undefined : tree.bringsGroups(bucket);
99
112
  return {
100
113
  path,
101
114
  depth,
@@ -104,9 +117,11 @@ underColumns = new Set()) {
104
117
  label: labelFor(bucket, depth, key),
105
118
  count: bucket.count,
106
119
  ...summed(bucket),
107
- items: below.length === 0 ? [...(rowsOf(bucket) ?? [])] : [],
108
- piles: walk(below, path, depth + 1),
109
- ...more(bucket, below.length === 0),
120
+ items: deepest ? [...(rowsOf(bucket) ?? [])] : [],
121
+ piles: deepest ? [] : walk(below, path, depth + 1),
122
+ ...more(bucket, deepest),
123
+ ...(counted === null || counted === undefined ? {} : { pilesCount: counted }),
124
+ ...(next === undefined ? {} : { morePiles: next }),
110
125
  };
111
126
  });
112
127
  return { piles: walk(buckets, [], 0), bucketAt, deepest: levels.length - 1 };
@@ -1,7 +1,7 @@
1
1
  import { type CommandAnswers, type CommandBodies, type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type ListDefinition } from "../../core/list.js";
4
- import type { PickerItem, RecordCard, RowOf, Tone } from "@sincpro/web-ui";
4
+ import type { DockMoment, PickerItem, RecordCard, RowOf, Tone } from "@sincpro/web-ui";
5
5
  import type { ComponentProps } from "react";
6
6
  /**
7
7
  * How a record of an entity looks at each size — a choice, a row, a card — declared ONCE with
@@ -66,6 +66,17 @@ export type Presentation<T> = {
66
66
  * dictionary per state and passed it to its rows, its record and its cells by hand.
67
67
  */
68
68
  tones?: ChoiceTones<T>;
69
+ /**
70
+ * What a record's action pill says while nothing is being edited — its moment, with its tone:
71
+ * `(colegiado) => colegiado.situacion === "OBSERVADO" ? { text: "Colegiado observado",
72
+ * detail: "Su portal está congelado hasta que levantes la observación.", tone: "warn" } :
73
+ * undefined`. Unsaved changes, saving and «Guardado» are the framework's and say themselves.
74
+ *
75
+ * Context: the header's tag already names the state; this is for what the state MEANS for
76
+ * whoever is looking — what waits, why an action is not there. Nothing by default: a pill
77
+ * repeating the tag would be the same word twice.
78
+ */
79
+ moment?: (record: T) => DockMoment | undefined;
69
80
  /** The colour of each kind of fact in its history, by its `name` — whole, or its last part
70
81
  * (`pago_aprobado`) — over the framework's own (`FACT_TONES`). */
71
82
  facts?: Readonly<Record<string, Tone>>;
@@ -12,6 +12,13 @@ export type FieldControl = {
12
12
  /** No `Field` names it — a cell of a table: the control carries its label itself. Inside a
13
13
  * `Field` it must not, or React Aria reads both and names it «Precio Precio». */
14
14
  standalone?: boolean;
15
+ /** No `Field` names it, yet it keeps its full look — a `RecordField bare`, inside a section
16
+ * that already says what it is: it carries `label` as its accessible name, a textarea still
17
+ * a textarea (`standalone` would make it a cell's one-line input). */
18
+ unlabelled?: boolean;
19
+ /** With `unlabelled`, the id of what is said under it — its refusal —, so the control reads it
20
+ * as its description (what `Field` wires when it wraps one). */
21
+ describedBy?: string;
15
22
  /** Whose field it is — the entity, the record's id, the field —, for what is sent apart from
16
23
  * the record: a file, a picture inside a rich text. `RecordField` says it. */
17
24
  about?: UploadAbout;
@@ -27,7 +27,16 @@ const SHORT_LABEL = 24;
27
27
  */
28
28
  export function controlFor(control, type, exact, choices, widget, segmented = false) {
29
29
  const { value, set } = control;
30
- const named = control.standalone === true ? { "aria-label": control.label } : {};
30
+ const named = control.standalone === true || control.unlabelled === true
31
+ ? {
32
+ "aria-label": control.label,
33
+ // No `Field` around it says it is wrong and why: the control says it itself.
34
+ ...(control.unlabelled === true ? { invalid: control.invalid } : {}),
35
+ ...(control.unlabelled === true && control.describedBy !== undefined
36
+ ? { describedBy: control.describedBy }
37
+ : {}),
38
+ }
39
+ : {};
31
40
  // Several of the values at once — a list whose values are a choice: each one a check, the
32
41
  // list's label above them.
33
42
  if (choices.length > 0 && type.endsWith("[]"))
@@ -5,7 +5,7 @@ import { type FieldControl } from "./control.js";
5
5
  import { type LinesLook } from "./lines.js";
6
6
  export type { FieldControl } from "./control.js";
7
7
  import { type DirtyState } from "@sincpro/web-ui";
8
- import type { ReactNode } from "react";
8
+ import { type ReactNode } from "react";
9
9
  /**
10
10
  * One field of a record being edited, from the model: its word, whether it is required or
11
11
  * read-only now (the hints, evaluated over what is on screen), the server's error for it, and a
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } 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";
@@ -21,6 +21,7 @@ import { RecordLines } from "./record.js";
21
21
  import { RelatedList } from "./RelatedList.js";
22
22
  import { RichTextControl } from "./richText.js";
23
23
  import { Checkbox, Field, FileValue, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
24
+ import { useId } from "react";
24
25
  /** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
25
26
  function setAt(value, path, next) {
26
27
  const base = typeof value === "object" && value !== null ? value : {};
@@ -104,6 +105,8 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
104
105
  const opening = useRecordOpening();
105
106
  const { metas, uploads } = useFramework();
106
107
  const settings = useFormStyle() === "settings";
108
+ // Bare, its refusal is said under the control — and tied to it by this id.
109
+ const refusalId = useId();
107
110
  if (!state.visible)
108
111
  return null;
109
112
  // A one2many is a BLOCK, named by a section — never a `Field`: web-ui's controls read the
@@ -177,6 +180,11 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
177
180
  invalid: error !== undefined,
178
181
  label: view.label,
179
182
  about: aboutOf(record, name),
183
+ // Bare, no `Field` names it: the control carries its label as its accessible name, and
184
+ // what is wrong with it as its description.
185
+ ...(bare
186
+ ? { unlabelled: true, ...(error === undefined ? {} : { describedBy: refusalId }) }
187
+ : {}),
180
188
  };
181
189
  const field = fieldMetaOf(meta, name);
182
190
  if (as === undefined && holdsFile(field)) {
@@ -231,11 +239,16 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
231
239
  return controlFor(control, view.type, false, choices, field?.widget);
232
240
  if (view.type === "boolean" && as === undefined)
233
241
  return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
242
+ const input = as !== undefined ? (as(control)) : relation !== undefined && !relation.many && target !== undefined ? (manyToOne()) : holdsRichText(field) ? (_jsx(RichTextControl, { control: control })) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choices,
243
+ // A value object of an amount and a currency is a money, whatever it is called.
244
+ field?.widget ?? (isMoneyDefinition(field?.definition) ? "money" : undefined), settings && state.required));
245
+ // Bare: the section around it already names it — the control takes the whole width, and only
246
+ // a refusal is said under it.
247
+ if (bare)
248
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-1", children: [input, error === undefined ? null : (_jsx("p", { id: refusalId, role: "alert", className: "text-meta text-bad", children: error }))] }));
234
249
  return (_jsx(Field, { label: view.label, required: state.required && !state.readonly,
235
250
  // Said only in web-ui's «settings» form style: a field that may stay empty, and is typed in.
236
- optional: !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()) : holdsRichText(field) ? (_jsx(RichTextControl, { control: control })) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choices,
237
- // A value object of an amount and a currency is a money, whatever it is called.
238
- field?.widget ?? (isMoneyDefinition(field?.definition) ? "money" : undefined), settings && state.required)) }));
251
+ optional: !state.required && !state.readonly, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: input }));
239
252
  }
240
253
  /**
241
254
  * The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
@@ -246,10 +259,14 @@ export function dirtyOf(record) {
246
259
  if (!edit.dirty)
247
260
  return undefined;
248
261
  const missing = edit.missing.map((name) => viewOf(meta, name, locale).label);
262
+ // How many fields changed: the floating pill writes «3 cambios sin guardar» — the marks of
263
+ // the fields themselves may be far up the form, out of sight.
264
+ const changes = Object.keys(edit.changed).length;
249
265
  return {
250
266
  onSave: () => void edit.save(),
251
267
  onDiscard: edit.discard,
252
268
  saving: edit.saving,
269
+ ...(changes === 0 ? {} : { changes }),
253
270
  ...(missing.length === 0 ? {} : { blocked: frameworkCopy().record.missing(missing) }),
254
271
  };
255
272
  }
@@ -47,7 +47,9 @@ export function RichTextControl({ control }) {
47
47
  }, [uploads, about, transport]);
48
48
  if (control.readonly)
49
49
  return (_jsx(RichTextValue, { value: html, ...(richText.embeds === undefined ? {} : { embeds: richText.embeds }), ...(richText.sanitized === undefined ? {} : { sanitized: richText.sanitized }) }));
50
- return (_jsx(RichTextInput, { value: html, onChange: (next) => control.set(next), invalid: control.invalid, toolbar: richText.toolbar ?? "full", ...(richText.embeds === undefined ? {} : { embeds: richText.embeds }), ...(images === undefined ? {} : { images }), ...(control.standalone === true ? { "aria-label": control.label } : {}) }));
50
+ return (_jsx(RichTextInput, { value: html, onChange: (next) => control.set(next), invalid: control.invalid, toolbar: richText.toolbar ?? "full", ...(richText.embeds === undefined ? {} : { embeds: richText.embeds }), ...(images === undefined ? {} : { images }), ...(control.standalone === true || control.unlabelled === true
51
+ ? { "aria-label": control.label }
52
+ : {}) }));
51
53
  }
52
54
  /** `RichTextControl` as a field's control, by reference: `<RecordField … as={richTextControl} />`. */
53
55
  export const richTextControl = (control) => (_jsx(RichTextControl, { control: control }));
@@ -64,6 +64,8 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
64
64
  title: string;
65
65
  };
66
66
  };
67
+ /** `Record.Dock moment`: the application's word on the record's moment (`presented`). */
68
+ moment: import("@sincpro/web-ui").DockMoment | undefined;
67
69
  /** `Record.Pager`'s props, when it was opened from a list and nothing is typed. */
68
70
  pager: {
69
71
  index: number;
@@ -104,6 +104,9 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
104
104
  ? undefined
105
105
  : look.tones?.[stateField]?.[String(reading.record[stateField])];
106
106
  const dirty = ready ? dirtyOf(reading) : undefined;
107
+ // What the application says of this record's moment — while nothing is being edited: then the
108
+ // pill says the unsaved changes itself.
109
+ const moment = ready && dirty === undefined ? look.moment?.(reading.record) : undefined;
107
110
  const failure = reading.edit.failure;
108
111
  // Who, only when the record says it (an author is optional: the line then says only when).
109
112
  const stamp = (one) => one?.at == null ? undefined : { at: one.at, ...(one.by == null ? {} : { by: one.by }) };
@@ -138,6 +141,8 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
138
141
  // The refusal in words; its heading when the server said nothing more (no detail).
139
142
  ...(failure === null || failure === undefined ? {} : { error: refusalOf(failure) }),
140
143
  },
144
+ /** `Record.Dock moment`: the application's word on the record's moment (`presented`). */
145
+ moment,
141
146
  /** `Record.Pager`'s props, when it was opened from a list and nothing is typed. */
142
147
  pager: place === null
143
148
  ? undefined
@@ -153,7 +158,7 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
153
158
  }
154
159
  export function EntityRecord({ api, resource, entity, fields, pages, actions, title, initial, }) {
155
160
  const screen = useRecordScreen(entity, { api, resource }, { title, initial });
156
- const { reading, crumbs, history, pager } = screen;
161
+ const { reading, crumbs, history, pager, moment } = screen;
157
162
  const [page, setPage] = useState(undefined);
158
163
  const copy = frameworkCopy().record;
159
164
  // On a phone a form is one column, its label over its value: two side by side at 400 px
@@ -185,7 +190,8 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
185
190
  return (_jsxs(_Fragment, { children: [_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 &&
186
191
  pager === undefined &&
187
192
  docked.length === 0 &&
188
- drawn === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), drawn === null ? null : _jsx(Record.Actions, { children: drawn }), docked.length === 0 ? null : _jsx(Record.Dock, { actions: docked })] })), _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, ...(settings && fields === undefined && layout.sections.length > 0
193
+ moment === undefined &&
194
+ drawn === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), drawn === null ? null : _jsx(Record.Actions, { children: drawn }), docked.length === 0 && moment === undefined ? null : (_jsx(Record.Dock, { actions: docked, ...(moment === undefined ? {} : { moment }) }))] })), _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, ...(settings && fields === undefined && layout.sections.length > 0
189
195
  ? { title: copy.general }
190
196
  : {}), children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), fields !== undefined
191
197
  ? null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.15.0",
3
+ "version": "3.17.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",
@@ -52,10 +52,10 @@
52
52
  "@sentry/browser": "^11.11.0",
53
53
  "@sentry/core": "^11.11.0",
54
54
  "@sincpro/client-framework": "^2.7.0",
55
- "@sincpro/criteria": "^2.4.0",
56
- "@sincpro/criteria-react": "^2.4.0",
55
+ "@sincpro/criteria": "^2.5.1",
56
+ "@sincpro/criteria-react": "^2.5.1",
57
57
  "@sincpro/web-composer": "^1.7.0",
58
- "@sincpro/web-ui": "^2.18.0",
58
+ "@sincpro/web-ui": "^2.19.0",
59
59
  "react": ">=19",
60
60
  "react-dom": ">=19"
61
61
  },
@@ -96,10 +96,10 @@
96
96
  "@sentry/browser": "11.11.0",
97
97
  "@sentry/core": "11.11.0",
98
98
  "@sincpro/client-framework": "^2.7.0",
99
- "@sincpro/criteria": "^2.5.0",
100
- "@sincpro/criteria-react": "^2.5.0",
99
+ "@sincpro/criteria": "^2.5.1",
100
+ "@sincpro/criteria-react": "^2.5.1",
101
101
  "@sincpro/web-composer": "^1.9.0",
102
- "@sincpro/web-ui": "^2.18.0",
102
+ "@sincpro/web-ui": "^2.19.0",
103
103
  "@storybook/addon-a11y": "10.6.5",
104
104
  "@storybook/addon-docs": "10.6.5",
105
105
  "@storybook/addon-mcp": "10.6.5",