@sincpro/web-framework 3.16.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.
@@ -282,6 +282,8 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
282
282
  elsewhere.join(),
283
283
  openingIn === undefined,
284
284
  dateStyle,
285
+ // The tags' colours: a new map of tones redraws the table's cells, as it does the sheet's.
286
+ look.tones,
285
287
  ]);
286
288
  // A state the application gave colours to is the row's tag — and not again among its facts.
287
289
  const stateField = summaryFieldsOf(meta, {}, listing.entity.summary).state;
@@ -325,7 +327,12 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
325
327
  id: column.id,
326
328
  header: String(column.header),
327
329
  ...(column.numeric === true ? { numeric: true } : {}),
328
- })), [shown]);
330
+ // A state in a toned tag, as the table draws it — not a painted cell, which is how
331
+ // a sheet marks a value out of range.
332
+ ...(look.tones?.[column.id] === undefined
333
+ ? {}
334
+ : { look: "tag" }),
335
+ })), [shown, look.tones]);
329
336
  const sortStates = useMemo(() => listing.order.map((one) => ({
330
337
  key: one.field,
331
338
  direction: one.descending ? "desc" : "asc",
@@ -503,11 +510,23 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
503
510
  // Emptied (or cleared with ×): the whole set again, at once.
504
511
  if (next === "" && listing.text !== "")
505
512
  listing.search("", { now: true });
506
- }, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, started.drawn === null ? null : (_jsxs(List.Actions, { children: [started.drawn, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })), startDock.length === 0 && forChosen.dock.length === 0 ? null : (_jsx(List.Dock, { ...(startDock.length === 0 ? {} : { actions: startDock }), ...(forChosen.dock.length === 0 ? {} : { selection: forChosen.dock }) })), paging === null ? null : _jsx(List.Pagination, { children: paging })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(totalled ? { totals: true } : {}), ...(rowActions === undefined ? {} : { rowActions }), ...(reorder.move === undefined ? {} : { onReorder: reorder.move }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, { columns: sheetColumns, cell: (row, column) => {
513
+ }, onSubmit: (text) => listing.search(text, { now: true }), placeholder: copy.search, "aria-label": copy.search }) })) : null, started.drawn === null ? null : (_jsxs(List.Actions, { children: [started.drawn, creating === undefined ? null : (_jsx(Button, { role: "primary", size: "sm", onClick: creating, children: frameworkCopy().record.create }))] })), startDock.length === 0 && forChosen.dock.length === 0 ? null : (_jsx(List.Dock, { ...(startDock.length === 0 ? {} : { actions: startDock }), ...(forChosen.dock.length === 0 ? {} : { selection: forChosen.dock }) })), paging === null ? null : _jsx(List.Pagination, { children: paging })] }), views.includes("table") ? (_jsx(List.Table, { columns: shown, ...(totalled ? { totals: true } : {}), ...(rowActions === undefined ? {} : { rowActions }), ...(reorder.move === undefined ? {} : { onReorder: reorder.move }) })) : null, _jsx(List.Rows, { row: rowOf }), views.includes("sheet") ? (_jsx(List.Sheet, {
514
+ // The set comes in pages (50 by default): the sheet grows with its page, as the table
515
+ // does, instead of web-ui's fixed box — which suits a sheet of thousands, not a page.
516
+ height: "auto", columns: sheetColumns, cell: (row, column) => {
507
517
  const value = row[column.id];
508
518
  return value === null || value === undefined
509
519
  ? null
510
520
  : (textOf(meta, column.id, value, locale) ?? String(value));
521
+ },
522
+ // The tones the application gave its choices (`presented(entity, { tones })`): the
523
+ // same colour a state has in the table, the record and its tag.
524
+ tone: (row, column) => {
525
+ const tones = look.tones?.[column.id];
526
+ const value = row[column.id];
527
+ return tones === undefined || value === null || value === undefined
528
+ ? undefined
529
+ : (tones[String(value)] ?? "neutral");
511
530
  } })) : null, views.includes("pivot") ? (_jsx(List.Pivot, { folded: folded ??
512
531
  pivotOf({
513
532
  crossed: [],
@@ -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.16.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",