@sincpro/web-framework 3.12.1 → 3.13.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 (51) hide show
  1. package/README.md +65 -1
  2. package/dist/core/cache.js +11 -0
  3. package/dist/core/copy.d.ts +18 -0
  4. package/dist/core/copy.js +21 -0
  5. package/dist/core/edit.d.ts +3 -0
  6. package/dist/core/edit.js +9 -6
  7. package/dist/core/files.d.ts +58 -0
  8. package/dist/core/files.js +57 -15
  9. package/dist/core/index.d.ts +4 -3
  10. package/dist/core/index.js +4 -3
  11. package/dist/core/present.d.ts +16 -0
  12. package/dist/core/present.js +41 -4
  13. package/dist/core/richText.d.ts +39 -0
  14. package/dist/core/richText.js +45 -0
  15. package/dist/core/summary.js +5 -1
  16. package/dist/errors/index.d.ts +3 -1
  17. package/dist/errors/index.js +14 -2
  18. package/dist/errors/narrowed.d.ts +2 -0
  19. package/dist/errors/narrowed.js +7 -0
  20. package/dist/errors/server.js +1 -7
  21. package/dist/react/context.d.ts +20 -1
  22. package/dist/react/context.js +11 -4
  23. package/dist/react/index.d.ts +1 -0
  24. package/dist/react/index.js +1 -0
  25. package/dist/react/useTextOf.d.ts +3 -2
  26. package/dist/react/useTextOf.js +4 -4
  27. package/dist/react/useUpload.d.ts +33 -0
  28. package/dist/react/useUpload.js +69 -0
  29. package/dist/telemetry/index.d.ts +21 -1
  30. package/dist/telemetry/index.js +35 -1
  31. package/dist/web/index.d.ts +5 -1
  32. package/dist/web/index.js +5 -1
  33. package/dist/web/record/ActionButton.d.ts +1 -1
  34. package/dist/web/record/ActionButton.js +7 -2
  35. package/dist/web/record/ask.d.ts +18 -0
  36. package/dist/web/record/ask.js +15 -0
  37. package/dist/web/record/choice.d.ts +32 -0
  38. package/dist/web/record/choice.js +36 -0
  39. package/dist/web/record/control.d.ts +4 -0
  40. package/dist/web/record/control.js +52 -1
  41. package/dist/web/record/edit.js +37 -5
  42. package/dist/web/record/fileControl.d.ts +22 -0
  43. package/dist/web/record/fileControl.js +48 -0
  44. package/dist/web/record/person.d.ts +23 -0
  45. package/dist/web/record/person.js +27 -0
  46. package/dist/web/record/record.js +8 -2
  47. package/dist/web/record/richText.d.ts +27 -0
  48. package/dist/web/record/richText.js +59 -0
  49. package/dist/web/workspace/SincproApp.d.ts +10 -1
  50. package/dist/web/workspace/SincproApp.js +2 -2
  51. package/package.json +5 -5
@@ -0,0 +1,32 @@
1
+ import type { Entity } from "@sincpro/client-framework";
2
+ import type { AnyRecord, Meta } from "@sincpro/criteria";
3
+ import { type Tone } from "@sincpro/web-ui";
4
+ /** A choice's value as a tag: its word and its tone. */
5
+ export type ChoiceTagLook = {
6
+ label: string;
7
+ tone: Tone;
8
+ };
9
+ /**
10
+ * A value of a choice as a tag: its word, the model's (`textOf`), in the tone the entity declared
11
+ * for it (`presented(entity, { tones })`), `neutral` when none was.
12
+ *
13
+ * choiceTagOf(pagos, meta, "estado", "PAGADO", "es") -> { label: "Pagado", tone: "good" }
14
+ *
15
+ * Context: a member's own page showed a payment's state outside any list. The tone was declared
16
+ * once and the word was the model's, but nothing public drew the pair, so the application wrote
17
+ * `presentationOf(entity).tones` plus `textOf` by hand (#42).
18
+ */
19
+ export declare function choiceTagOf<T extends AnyRecord>(entity: Entity<T>, meta: Meta | null | undefined, field: keyof T & string, value: unknown, locale?: string): ChoiceTagLook;
20
+ /**
21
+ * A value of a choice, drawn as the framework draws it in a list — anywhere: a panel, a page of
22
+ * the application's own. Its model is the one given, else the one the provider already read for
23
+ * the entity; without either, the value itself is the word.
24
+ *
25
+ * <ChoiceTag entity={pagos} field="estado" value={pago.estado} />
26
+ */
27
+ export declare function ChoiceTag<T extends AnyRecord>({ entity, field, value, meta, }: {
28
+ entity: Entity<T>;
29
+ field: keyof T & string;
30
+ value: unknown;
31
+ meta?: Meta | null;
32
+ }): import("react").JSX.Element;
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { textOf } from "../../core/present.js";
4
+ import { useFrameworkIfAny } from "../../react/context.js";
5
+ import { presentationOf } from "../list/presentation.js";
6
+ import { Tag } from "@sincpro/web-ui";
7
+ /**
8
+ * A value of a choice as a tag: its word, the model's (`textOf`), in the tone the entity declared
9
+ * for it (`presented(entity, { tones })`), `neutral` when none was.
10
+ *
11
+ * choiceTagOf(pagos, meta, "estado", "PAGADO", "es") -> { label: "Pagado", tone: "good" }
12
+ *
13
+ * Context: a member's own page showed a payment's state outside any list. The tone was declared
14
+ * once and the word was the model's, but nothing public drew the pair, so the application wrote
15
+ * `presentationOf(entity).tones` plus `textOf` by hand (#42).
16
+ */
17
+ export function choiceTagOf(entity, meta, field, value, locale) {
18
+ const tones = presentationOf(entity).tones?.[field];
19
+ return {
20
+ label: textOf(meta, field, value, locale) ?? String(value ?? ""),
21
+ tone: tones?.[String(value)] ?? "neutral",
22
+ };
23
+ }
24
+ /**
25
+ * A value of a choice, drawn as the framework draws it in a list — anywhere: a panel, a page of
26
+ * the application's own. Its model is the one given, else the one the provider already read for
27
+ * the entity; without either, the value itself is the word.
28
+ *
29
+ * <ChoiceTag entity={pagos} field="estado" value={pago.estado} />
30
+ */
31
+ export function ChoiceTag({ entity, field, value, meta, }) {
32
+ const framework = useFrameworkIfAny();
33
+ const model = meta ?? framework?.metas.get(entity.key) ?? null;
34
+ const look = choiceTagOf(entity, model, field, value, framework?.locale);
35
+ return _jsx(Tag, { tone: look.tone, children: look.label });
36
+ }
@@ -1,5 +1,6 @@
1
1
  import { type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
+ import type { UploadAbout } from "../../core/files.js";
3
4
  import type { ReactNode } from "react";
4
5
  /** What a control of a field receives: its value, how to change it, and its state now. */
5
6
  export type FieldControl = {
@@ -11,6 +12,9 @@ export type FieldControl = {
11
12
  /** No `Field` names it — a cell of a table: the control carries its label itself. Inside a
12
13
  * `Field` it must not, or React Aria reads both and names it «Precio Precio». */
13
14
  standalone?: boolean;
15
+ /** Whose field it is — the entity, the record's id, the field —, for what is sent apart from
16
+ * the record: a file, a picture inside a rich text. `RecordField` says it. */
17
+ about?: UploadAbout;
14
18
  };
15
19
  /**
16
20
  * The control a field's TYPE asks for — a choice, several of a choice (checks), a number, a
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
3
+ import { dayOf, instantOf, Money, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
4
+ import { currencyNow } from "../../core/present.js";
4
5
  import { EntityPicker } from "./EntityPicker.js";
5
6
  import { Checkbox, CheckList, DatePicker, DateTimePicker, NumberInput, SegmentedControl, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
6
7
  /** A choice answered with one press — a segmented control — instead of a select: up to three
@@ -39,6 +40,8 @@ export function controlFor(control, type, exact, choices, widget, segmented = fa
39
40
  return (_jsx(SegmentedControl, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set }));
40
41
  if (choices.length > 0)
41
42
  return (_jsx(Select, { value: value === null || value === undefined ? "" : String(value), options: choices.map((one) => ({ value: String(one.value), label: one.label })), onChange: set, ...named }));
43
+ if (widget === "money")
44
+ return moneyInput(control, exact, named);
42
45
  switch (type) {
43
46
  case "boolean":
44
47
  return _jsx(Checkbox, { checked: value === true, onChange: set, label: control.label });
@@ -85,3 +88,51 @@ export function RelationPicker({ target, value, onChange, label, ownChooser = fa
85
88
  // «Buscar más…» is an option of the picker already: no second button beside it.
86
89
  browse: false, ownChooser: ownChooser, ...(onClear === undefined ? {} : { onClear }), ...(standalone ? { "aria-label": label } : {}) }));
87
90
  }
91
+ /** Whether `Intl` writes `code` as a currency — an ISO 4217 code —, asked once per code. */
92
+ const knownCurrencies = new Map();
93
+ function isCurrency(code) {
94
+ let known = knownCurrencies.get(code);
95
+ if (known === undefined) {
96
+ try {
97
+ new Intl.NumberFormat(undefined, { style: "currency", currency: code });
98
+ known = true;
99
+ }
100
+ catch {
101
+ known = false;
102
+ }
103
+ knownCurrencies.set(code, known);
104
+ }
105
+ return known;
106
+ }
107
+ /**
108
+ * An amount typed as money — «Bs 1.150,50» while it is typed, grouped and in its currency's
109
+ * decimals: a money (`{ amount, currency }`) keeps its own currency, a bare amount the model draws
110
+ * as money is in the business's (`FrameworkProvider currency`). What is typed goes back in the
111
+ * shape it came: a money whole, its amount as text; a bare exact amount as text — no digit passes
112
+ * through a float on its way to the server.
113
+ *
114
+ * Context: a money field was edited with a plain number input — no currency, no grouping —,
115
+ * while the same value read beside it as «Bs 1.150,50». web-ui's `NumberInput` types a currency
116
+ * through `format`; a code `Intl` does not know (a loyalty point) is its unit instead.
117
+ */
118
+ function moneyInput(control, exact, named) {
119
+ const { value, set } = control;
120
+ const held = Money.isMoney(value) ? value : null;
121
+ const code = held?.currency ?? currencyNow();
122
+ const amount = held === null ? value : held.amount;
123
+ const typed = amount === null || amount === undefined || amount === "" ? "" : Number(amount);
124
+ const decimals = code === undefined ? 2 : Money.decimalsOf(code);
125
+ const known = code !== undefined && isCurrency(code);
126
+ const format = {
127
+ ...(known ? { style: "currency", currency: code } : {}),
128
+ minimumFractionDigits: decimals,
129
+ maximumFractionDigits: decimals,
130
+ };
131
+ return (_jsx(NumberInput, { value: Number.isNaN(typed) ? "" : typed, format: format, ...(code !== undefined && !known ? { unit: code } : {}), onChange: (next) => {
132
+ if (next === "")
133
+ return set(null);
134
+ if (held !== null)
135
+ return set({ amount: String(next), currency: held.currency });
136
+ set(exact ? String(next) : next);
137
+ }, ...named }));
138
+ }
@@ -8,14 +8,18 @@ import { holdsFile } from "../../core/files.js";
8
8
  import { editableLines } from "../../core/lines.js";
9
9
  import { fieldAt, fieldMetaOf, isMoneyDefinition, textOf, valueAt, viewOf, } from "../../core/present.js";
10
10
  import { relationFieldOf } from "../../core/relation.js";
11
+ import { holdsRichText } from "../../core/richText.js";
11
12
  import { useEntityFor, useFramework } from "../../react/context.js";
12
13
  import { useNameOf } from "../../react/useNameOf.js";
13
14
  import { attachmentOf } from "../files.js";
14
15
  import { controlFor, RelationPicker, } from "./control.js";
16
+ import { FileControl } from "./fileControl.js";
15
17
  import { RecordLinesEditor } from "./lines.js";
16
- import { useRecordOpening } from "./opening.js";
18
+ import { useRecordOpening, } from "./opening.js";
19
+ import { isPersonEntity, PersonValue } from "./person.js";
17
20
  import { RecordLines } from "./record.js";
18
21
  import { RelatedList } from "./RelatedList.js";
22
+ import { RichTextControl } from "./richText.js";
19
23
  import { Checkbox, Field, FileValue, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
20
24
  /** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
21
25
  function setAt(value, path, next) {
@@ -32,6 +36,24 @@ function KeyValue({ target, id, ...rest }) {
32
36
  const name = useNameOf(target, id);
33
37
  return _jsx(RelationValue, { name: name ?? id, ...rest });
34
38
  }
39
+ /** Whose a field is, for what is sent apart from the record: the entity, the record's id — a
40
+ * new one's too, the id it was given here (`newEntityId`) —, the field. */
41
+ function aboutOf(record, name) {
42
+ const { meta, edit } = record;
43
+ const key = meta?.get_id || meta?.identity || "id";
44
+ const held = edit.values[key];
45
+ const id = record.id !== "" ? record.id : held === null || held === undefined ? "" : String(held);
46
+ return {
47
+ entity: meta?.aggregate ?? record.entity.key,
48
+ id: id === "" ? null : id,
49
+ field: name,
50
+ };
51
+ }
52
+ /** A key alone to a person, read: named by key, drawn with their initials. */
53
+ function KeyPerson({ target, id, opening, }) {
54
+ const name = useNameOf(target, id);
55
+ return _jsx(PersonValue, { target: target, id: id, name: name ?? id, opening: opening });
56
+ }
35
57
  /**
36
58
  * One field of a record being edited, from the model: its word, whether it is required or
37
59
  * read-only now (the hints, evaluated over what is on screen), the server's error for it, and a
@@ -80,7 +102,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
80
102
  const relation = nested ? undefined : relationFieldOf(meta, name);
81
103
  const target = useEntityFor(relation?.target);
82
104
  const opening = useRecordOpening();
83
- const { metas } = useFramework();
105
+ const { metas, uploads } = useFramework();
84
106
  const settings = useFormStyle() === "settings";
85
107
  if (!state.visible)
86
108
  return null;
@@ -154,13 +176,18 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
154
176
  readonly: state.readonly,
155
177
  invalid: error !== undefined,
156
178
  label: view.label,
179
+ about: aboutOf(record, name),
157
180
  };
158
181
  const field = fieldMetaOf(meta, name);
159
182
  if (as === undefined && holdsFile(field)) {
160
183
  // A file is ONE value — its picture or its kind, the name it was sent with, its type and
161
- // size —, never a section of its parts. Sending another is the upload's, not this field's.
184
+ // size —, never a section of its parts. Another one is given through the application's
185
+ // uploads (`FrameworkProvider uploads`); without them, it is only read.
162
186
  const file = attachmentOf(value);
163
- return (_jsx(Field, { label: view.label, ...(view.help === undefined ? {} : { hint: view.help }), children: file === null ? _jsx(ReadValue, { value: "\u2014" }) : _jsx(FileValue, { file: file, size: "md" }) }));
187
+ const editable = !state.readonly && uploads !== undefined && !nested;
188
+ return (_jsx(Field, { label: view.label, ...(view.help === undefined ? {} : { hint: view.help }), ...(error === undefined ? {} : { error }), children: editable ? (_jsx(FileControl, { control: control, image: field?.widget === "image",
189
+ // Answered no value: the backend already put the file in the record — read it again.
190
+ onKept: (published) => published.value === undefined ? record.reload() : control.set(published.value) })) : file === null ? (_jsx(ReadValue, { value: "\u2014" })) : (_jsx(FileValue, { file: file, size: "md" })) }));
164
191
  }
165
192
  /** A many2one of a declared entity: chosen by the server's literal search, opened where the
166
193
  * view says. Written by its key; read by the record it points at. */
@@ -176,6 +203,9 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
176
203
  onOpenIn: (to) => opening.open(target.ref(id), to),
177
204
  openTargets: opening.targets,
178
205
  };
206
+ // A person reads as their face and name; their card opens their record.
207
+ if (isPersonEntity(target) && id !== "")
208
+ return relation.held ? (_jsx(PersonValue, { target: target, id: id, name: textOf(meta, relation.relation, edit.values[relation.relation], locale) ?? id, held: edit.values[relation.relation], opening: opening })) : (_jsx(KeyPerson, { target: target, id: id, opening: opening }));
179
209
  // A relation held beside its key names itself; a key alone (`EntityID`) asks its name.
180
210
  if (!relation.held)
181
211
  return _jsx(KeyValue, { target: target, id: id, ...opens });
@@ -203,7 +233,9 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
203
233
  return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
204
234
  return (_jsx(Field, { label: view.label, required: state.required && !state.readonly,
205
235
  // Said only in web-ui's «settings» form style: a field that may stay empty, and is typed in.
206
- 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()) : state.readonly ? (_jsx(ReadValue, { value: textOf(meta, name, value, locale) ?? "—" })) : (controlFor(control, view.type, field?.exact === true, choices, field?.widget, settings && state.required)) }));
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)) }));
207
239
  }
208
240
  /**
209
241
  * The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
@@ -0,0 +1,22 @@
1
+ import type { Published } from "../../core/files.js";
2
+ import type { FieldControl } from "./control.js";
3
+ /**
4
+ * A record's file or picture, given by a person: what it holds now — its picture or its kind,
5
+ * the name it was sent with —, and the zone that takes another — dropped, pasted or chosen —, its
6
+ * bytes sent where the application says (`uploads`) with their progress, a cancel, a retry, and a
7
+ * refusal in the copy's words by the backend's reason.
8
+ *
9
+ * Context: an application saved the record first, then uploaded through a picker of its own.
10
+ * sincpro_framework takes no file inside a Command (#364): its Command asks for an upload id, the
11
+ * bytes go there (`uploadTo`), and the save names it. Once the bytes are there the field holds
12
+ * what the application answered (`Published.value`: the id the save's Command names), and the
13
+ * record is dirty as with any field; when it answered none, the backend already put the file in
14
+ * the record, and `onKept` reads it again.
15
+ */
16
+ export declare function FileControl({ control, image, onKept, }: {
17
+ control: FieldControl;
18
+ /** A picture: the zone's dialog offers images only. What it may be is still the backend's. */
19
+ image?: boolean;
20
+ /** What to do once the bytes are there; by default the field takes `Published.value`. */
21
+ onKept?: (published: Published) => void;
22
+ }): import("react").JSX.Element;
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useUpload } from "../../react/useUpload.js";
4
+ import { attachmentOf } from "../files.js";
5
+ import { DropZone, FileValue } from "@sincpro/web-ui";
6
+ import { useRef, useState } from "react";
7
+ /**
8
+ * A record's file or picture, given by a person: what it holds now — its picture or its kind,
9
+ * the name it was sent with —, and the zone that takes another — dropped, pasted or chosen —, its
10
+ * bytes sent where the application says (`uploads`) with their progress, a cancel, a retry, and a
11
+ * refusal in the copy's words by the backend's reason.
12
+ *
13
+ * Context: an application saved the record first, then uploaded through a picker of its own.
14
+ * sincpro_framework takes no file inside a Command (#364): its Command asks for an upload id, the
15
+ * bytes go there (`uploadTo`), and the save names it. Once the bytes are there the field holds
16
+ * what the application answered (`Published.value`: the id the save's Command names), and the
17
+ * record is dirty as with any field; when it answered none, the backend already put the file in
18
+ * the record, and `onKept` reads it again.
19
+ */
20
+ export function FileControl({ control, image = false, onKept, }) {
21
+ const upload = useUpload(control.about ?? { entity: "", id: null, field: control.label });
22
+ // The file just sent, shown by its name while the field holds what it answered — until the
23
+ // record holds it as a stored file, or the edit is discarded.
24
+ const [sent, setSent] = useState(null);
25
+ const stored = attachmentOf(control.value);
26
+ const shown = stored ??
27
+ (sent !== null && (sent.value === undefined || sent.value === control.value)
28
+ ? sent.file
29
+ : null);
30
+ const last = useRef(null);
31
+ const take = async (file) => {
32
+ last.current = file;
33
+ const published = await upload.send(file);
34
+ if (published === undefined)
35
+ return;
36
+ setSent({
37
+ file: { id: file.name, name: file.name, type: file.type, size: file.size },
38
+ value: published.value,
39
+ });
40
+ if (onKept !== undefined)
41
+ onKept(published);
42
+ else if (published.value !== undefined)
43
+ control.set(published.value);
44
+ };
45
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [shown === null ? null : _jsx(FileValue, { file: shown, size: "md" }), control.readonly || !upload.available ? null : (_jsx(DropZone, { onFile: (file) => void take(file), ...(image ? { accept: "image/*" } : {}), busy: upload.busy, progress: Math.round((upload.progress ?? 0) * 100), ...(upload.name === null ? {} : { fileName: upload.name }), error: upload.error, onCancel: upload.cancel,
46
+ // Again through `take`: the field takes what the new link answers.
47
+ onRetry: () => (last.current === null ? undefined : void take(last.current)), invalid: control.invalid || upload.error !== null }))] }));
48
+ }
@@ -0,0 +1,23 @@
1
+ import type { Entity } from "@sincpro/client-framework";
2
+ import type { AnyRecord } from "@sincpro/criteria";
3
+ import type { RecordOpening } from "./opening.js";
4
+ /** Whether a relation's records are people (or companies): `entity(…, { summary: { person } })`. */
5
+ export declare function isPersonEntity(entity: Entity | undefined): boolean;
6
+ /**
7
+ * A relation to a person, read: their face — the photo the record holds, else their initials —
8
+ * and their name; pressed, the card that opens their record where the view says. With no place
9
+ * to open it, the face and the name alone: a chip that leads nowhere is not a button.
10
+ *
11
+ * Context: pickers already chose a person by their face, but once chosen a record read them as
12
+ * a plain link, so every application wrote its own chip. web-ui's `UserChip` is the same face
13
+ * and name its audit and attachments draw. The photo comes with the record held beside the key;
14
+ * a key alone (`EntityID`) is named by key and drawn with the initials.
15
+ */
16
+ export declare function PersonValue({ target, id, name, held, opening, }: {
17
+ target: Entity;
18
+ id: string;
19
+ name: string;
20
+ /** The related record, when the read brought it beside its key: its photo. */
21
+ held?: AnyRecord | null | undefined;
22
+ opening: RecordOpening | null;
23
+ }): import("react").JSX.Element;
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useSummaryOf } from "../../react/useSummary.js";
4
+ import { UserChip } from "@sincpro/web-ui";
5
+ /** Whether a relation's records are people (or companies): `entity(…, { summary: { person } })`. */
6
+ export function isPersonEntity(entity) {
7
+ return entity?.summary.person === true;
8
+ }
9
+ /**
10
+ * A relation to a person, read: their face — the photo the record holds, else their initials —
11
+ * and their name; pressed, the card that opens their record where the view says. With no place
12
+ * to open it, the face and the name alone: a chip that leads nowhere is not a button.
13
+ *
14
+ * Context: pickers already chose a person by their face, but once chosen a record read them as
15
+ * a plain link, so every application wrote its own chip. web-ui's `UserChip` is the same face
16
+ * and name its audit and attachments draw. The photo comes with the record held beside the key;
17
+ * a key alone (`EntityID`) is named by key and drawn with the initials.
18
+ */
19
+ export function PersonValue({ target, id, name, held, opening, }) {
20
+ const summarize = useSummaryOf(target);
21
+ const image = held === null || held === undefined || typeof held !== "object"
22
+ ? null
23
+ : summarize(held).image;
24
+ return (_jsx(UserChip, { name: name, size: "sm", ...(image === null ? {} : { src: image }), ...(opening === null || id === ""
25
+ ? {}
26
+ : { onOpen: () => opening.open(target.ref(id), opening.targets[0] ?? "page") }) }));
27
+ }
@@ -2,14 +2,17 @@
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, valueAt, viewOf } from "../../core/present.js";
5
+ import { fieldMetaOf, textOf, valueAt, viewOf } from "../../core/present.js";
6
6
  import { relatedOf } from "../../core/related.js";
7
7
  import { entityFor, relationFieldOf, } from "../../core/relation.js";
8
+ import { holdsRichText } from "../../core/richText.js";
8
9
  import { useEntityFor, useFrameworkIfAny } from "../../react/context.js";
9
10
  import { useNameOf } from "../../react/useNameOf.js";
10
11
  import { columnsOf } from "../list/columns.js";
11
12
  import { partLookOf, presentationOf, tonesOver, } from "../list/presentation.js";
12
13
  import { useRecordOpening } from "./opening.js";
14
+ import { isPersonEntity, PersonValue } from "./person.js";
15
+ import { RichTextFact } from "./richText.js";
13
16
  import { List, RelationValue, } from "@sincpro/web-ui";
14
17
  import { useState } from "react";
15
18
  /**
@@ -38,7 +41,7 @@ export function factsOf(record, meta, names, options = {}) {
38
41
  const relation = relationFieldOf(meta, name);
39
42
  return {
40
43
  label: view.label,
41
- value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : (
44
+ value: own ? (own(record)) : holdsRichText(fieldMetaOf(meta, name)) ? (_jsx(RichTextFact, { value: valueAt(meta, record, name) })) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : (
42
45
  // A field of an embedded value is named by its path: `recibo.numero`.
43
46
  (textOf(meta, name, valueAt(meta, record, name), options.locale) ?? EMPTY)),
44
47
  ...(view.help === undefined ? {} : { hint: view.help }),
@@ -67,6 +70,9 @@ function RelationFact({ record, meta, name, relation, locale, }) {
67
70
  const held = relation.held
68
71
  ? textOf(meta, relation.relation, record[relation.relation], locale)
69
72
  : null;
73
+ // A person reads as their face and name; their card opens their record.
74
+ if (isPersonEntity(target))
75
+ return (_jsx(PersonValue, { target: target, id: key, name: held ?? asked ?? key, held: relation.held ? record[relation.relation] : null, opening: opening }));
70
76
  return (_jsx(RelationValue, { name: held ?? asked ?? key, ...(opening === null
71
77
  ? {}
72
78
  : {
@@ -0,0 +1,27 @@
1
+ import type { FieldControl } from "./control.js";
2
+ /**
3
+ * A field of formatted text: web-ui's editor while it is written, the HTML cleaned of anything
4
+ * that runs when it is read. How much the editor offers, the video hosts it embeds and whether
5
+ * the backend cleans what it stores are the application's, said once (`FrameworkProvider
6
+ * richText`); pictures go where the application sends files (`uploads`), filed under the record
7
+ * they belong to (`control.about`).
8
+ *
9
+ * <RecordField record={aviso} name="cuerpo" /> // widget "html": by itself
10
+ * <RecordField record={aviso} name="cuerpo" as={richTextControl} /> // a field the model does not mark
11
+ *
12
+ * Context: `RecordField` draws it for a field whose widget is `html`
13
+ * (Sincpro-SRL/sincpro_framework#371). Before the backend names it — or for a field it never
14
+ * will — the screen asks for it in code, by reference: `as={richTextControl}`, never a widget
15
+ * named in a string. Without `uploads` the editor takes no pictures; without `about` it does not
16
+ * know whose they would be, and takes none either.
17
+ */
18
+ export declare function RichTextControl({ control }: {
19
+ control: FieldControl;
20
+ }): import("react").JSX.Element;
21
+ /** `RichTextControl` as a field's control, by reference: `<RecordField … as={richTextControl} />`. */
22
+ export declare const richTextControl: (control: FieldControl) => import("react").JSX.Element;
23
+ /** Formatted text read — a record's fact: the HTML cleaned of what runs, with the players of the
24
+ * application's video hosts (`FrameworkProvider richText`). */
25
+ export declare function RichTextFact({ value }: {
26
+ value: unknown;
27
+ }): import("react").JSX.Element;
@@ -0,0 +1,59 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { sendFile, uploadRefusalOf } from "../../core/files.js";
4
+ import { useFramework, useFrameworkIfAny } from "../../react/context.js";
5
+ import { RichTextInput, RichTextValue } from "@sincpro/web-ui";
6
+ import { useMemo } from "react";
7
+ /**
8
+ * A field of formatted text: web-ui's editor while it is written, the HTML cleaned of anything
9
+ * that runs when it is read. How much the editor offers, the video hosts it embeds and whether
10
+ * the backend cleans what it stores are the application's, said once (`FrameworkProvider
11
+ * richText`); pictures go where the application sends files (`uploads`), filed under the record
12
+ * they belong to (`control.about`).
13
+ *
14
+ * <RecordField record={aviso} name="cuerpo" /> // widget "html": by itself
15
+ * <RecordField record={aviso} name="cuerpo" as={richTextControl} /> // a field the model does not mark
16
+ *
17
+ * Context: `RecordField` draws it for a field whose widget is `html`
18
+ * (Sincpro-SRL/sincpro_framework#371). Before the backend names it — or for a field it never
19
+ * will — the screen asks for it in code, by reference: `as={richTextControl}`, never a widget
20
+ * named in a string. Without `uploads` the editor takes no pictures; without `about` it does not
21
+ * know whose they would be, and takes none either.
22
+ */
23
+ export function RichTextControl({ control }) {
24
+ const { richText, uploads, transport } = useFramework();
25
+ const { about } = control;
26
+ const html = typeof control.value === "string" ? control.value : "";
27
+ const images = useMemo(() => uploads === undefined || about === undefined
28
+ ? undefined
29
+ : {
30
+ upload: async (file) => {
31
+ try {
32
+ const published = await sendFile(transport, uploads, file, about, {
33
+ signal: new AbortController().signal,
34
+ });
35
+ if (published.src === undefined)
36
+ throw new Error("uploads.publish answered no `src`: a picture inside a rich text needs where it is seen");
37
+ return {
38
+ src: published.src,
39
+ ...(published.alt === undefined ? {} : { alt: published.alt }),
40
+ };
41
+ }
42
+ catch (error) {
43
+ // web-ui shows the thrown message as the failure: the copy's words, by reason.
44
+ throw new Error(uploadRefusalOf(error), { cause: error });
45
+ }
46
+ },
47
+ }, [uploads, about, transport]);
48
+ if (control.readonly)
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 } : {}) }));
51
+ }
52
+ /** `RichTextControl` as a field's control, by reference: `<RecordField … as={richTextControl} />`. */
53
+ export const richTextControl = (control) => (_jsx(RichTextControl, { control: control }));
54
+ /** Formatted text read — a record's fact: the HTML cleaned of what runs, with the players of the
55
+ * application's video hosts (`FrameworkProvider richText`). */
56
+ export function RichTextFact({ value }) {
57
+ const settings = useFrameworkIfAny()?.richText ?? {};
58
+ return (_jsx(RichTextValue, { value: typeof value === "string" ? value : null, ...(settings.embeds === undefined ? {} : { embeds: settings.embeds }), ...(settings.sanitized === undefined ? {} : { sanitized: settings.sanitized }) }));
59
+ }
@@ -2,9 +2,11 @@ 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 { Uploads } from "../../core/files.js";
5
6
  import type { DateStyle } from "../../core/present.js";
7
+ import type { RichTextSettings } from "../../core/richText.js";
6
8
  import { type ReactNode } from "react";
7
- export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, events, workspace: given, bar, onViewError, changes, }: {
9
+ export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, region, richText, uploads, events, workspace: given, bar, onViewError, changes, }: {
8
10
  transport: Transport;
9
11
  /** The entities as composer views — `entityView(…)` — and any other view of the app. */
10
12
  views: readonly ViewSpec[];
@@ -34,6 +36,13 @@ export declare function SincproApp({ transport, views, start, language, metas, e
34
36
  dateStyle?: DateStyle;
35
37
  /** The business's currency (`"BOB"`): an amount the model draws as money is written in it. */
36
38
  currency?: string;
39
+ /** Where numbers and money are written as the business writes them (`"es-BO"`), apart from
40
+ * the language of the words. */
41
+ region?: string;
42
+ /** How a field of formatted text is written and read (`FrameworkProvider richText`). */
43
+ richText?: RichTextSettings;
44
+ /** Where a file a person gives goes — the application's (`FrameworkProvider uploads`). */
45
+ uploads?: Uploads;
37
46
  /** Each domain event's definition by its wire name (`eventMetasOf(contract)`): a history
38
47
  * names each fact's own fields in its words. */
39
48
  events?: Readonly<Record<string, Meta>>;
@@ -51,7 +51,7 @@ function FrameworkSearch({ children }) {
51
51
  }
52
52
  /** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
53
53
  const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
54
- 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, }) {
54
+ export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, region, richText, uploads, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
55
55
  // Installed once, before anything draws: the three tables are module state of their packages.
56
56
  useState(() => {
57
57
  if (language === "es") {
@@ -96,5 +96,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
96
96
  // The first screen only: a re-render must not push it again.
97
97
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
98
  }, [workspace]);
99
- 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(FrameworkSearch, { 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 }) }) })] }) }) }) }));
99
+ 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 }), ...(region === undefined ? {} : { region }), ...(richText === undefined ? {} : { richText }), ...(uploads === undefined ? {} : { uploads }), ...(events === undefined ? {} : { events }), children: _jsx(FrameworkSearch, { 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 }) }) })] }) }) }) }));
100
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.12.1",
3
+ "version": "3.13.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",
@@ -51,11 +51,11 @@
51
51
  "@opentelemetry/sdk-trace": "^3.1.0",
52
52
  "@sentry/browser": "^11.11.0",
53
53
  "@sentry/core": "^11.11.0",
54
- "@sincpro/client-framework": "^2.3.0",
54
+ "@sincpro/client-framework": "^2.7.0",
55
55
  "@sincpro/criteria": "^2.4.0",
56
56
  "@sincpro/criteria-react": "^2.4.0",
57
57
  "@sincpro/web-composer": "^1.7.0",
58
- "@sincpro/web-ui": "^2.14.1",
58
+ "@sincpro/web-ui": "^2.15.0",
59
59
  "react": ">=19",
60
60
  "react-dom": ">=19"
61
61
  },
@@ -95,11 +95,11 @@
95
95
  "@opentelemetry/sdk-trace": "3.1.0",
96
96
  "@sentry/browser": "11.11.0",
97
97
  "@sentry/core": "11.11.0",
98
- "@sincpro/client-framework": "^2.6.0",
98
+ "@sincpro/client-framework": "^2.7.0",
99
99
  "@sincpro/criteria": "^2.5.0",
100
100
  "@sincpro/criteria-react": "^2.5.0",
101
101
  "@sincpro/web-composer": "^1.9.0",
102
- "@sincpro/web-ui": "^2.14.1",
102
+ "@sincpro/web-ui": "^2.16.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",