@sincpro/web-framework 3.12.0 → 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 (54) 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/list.d.ts +9 -0
  12. package/dist/core/present.d.ts +16 -0
  13. package/dist/core/present.js +41 -4
  14. package/dist/core/richText.d.ts +39 -0
  15. package/dist/core/richText.js +45 -0
  16. package/dist/core/summary.js +5 -1
  17. package/dist/errors/index.d.ts +3 -1
  18. package/dist/errors/index.js +14 -2
  19. package/dist/errors/narrowed.d.ts +2 -0
  20. package/dist/errors/narrowed.js +7 -0
  21. package/dist/errors/server.js +1 -7
  22. package/dist/react/context.d.ts +20 -1
  23. package/dist/react/context.js +11 -4
  24. package/dist/react/index.d.ts +1 -0
  25. package/dist/react/index.js +1 -0
  26. package/dist/react/useTextOf.d.ts +3 -2
  27. package/dist/react/useTextOf.js +4 -4
  28. package/dist/react/useUpload.d.ts +33 -0
  29. package/dist/react/useUpload.js +69 -0
  30. package/dist/telemetry/index.d.ts +21 -1
  31. package/dist/telemetry/index.js +35 -1
  32. package/dist/web/index.d.ts +5 -1
  33. package/dist/web/index.js +5 -1
  34. package/dist/web/list/EntitySearchBar.d.ts +5 -2
  35. package/dist/web/list/EntitySearchBar.js +43 -12
  36. package/dist/web/record/ActionButton.d.ts +1 -1
  37. package/dist/web/record/ActionButton.js +7 -2
  38. package/dist/web/record/ask.d.ts +18 -0
  39. package/dist/web/record/ask.js +15 -0
  40. package/dist/web/record/choice.d.ts +32 -0
  41. package/dist/web/record/choice.js +36 -0
  42. package/dist/web/record/control.d.ts +4 -0
  43. package/dist/web/record/control.js +52 -1
  44. package/dist/web/record/edit.js +37 -5
  45. package/dist/web/record/fileControl.d.ts +22 -0
  46. package/dist/web/record/fileControl.js +48 -0
  47. package/dist/web/record/person.d.ts +23 -0
  48. package/dist/web/record/person.js +27 -0
  49. package/dist/web/record/record.js +8 -2
  50. package/dist/web/record/richText.d.ts +27 -0
  51. package/dist/web/record/richText.js +59 -0
  52. package/dist/web/workspace/SincproApp.d.ts +10 -1
  53. package/dist/web/workspace/SincproApp.js +2 -2
  54. package/package.json +5 -5
@@ -5,10 +5,34 @@ import { frameworkCopy } from "../../core/copy.js";
5
5
  import { groupableOf } from "./groups.js";
6
6
  import { useLoadModel, useRecordsBrowser, useSearchRecords, } from "./records.js";
7
7
  import { facetsOf, modelOf } from "./search.js";
8
- import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, GroupingLevels, hasNamed, SearchBar, selectionOf, toggleNamed, useGroupingControl, useSearchSettings, useUiCopy, } from "@sincpro/web-ui";
8
+ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, filtersOf, GroupingLevels, hasNamed, levelLabeler, levelsOf, SearchBar, selectionOf, toggleNamed, useGroupingControl, useSearchSettings, useUiCopy, withLevels, } from "@sincpro/web-ui";
9
9
  import { useEffect, useMemo, useRef, useState } from "react";
10
10
  /** No grouping: one constant, so the control is not handed a new array on every render. */
11
11
  const NO_LEVELS = [];
12
+ /** The same levels, in the same order: the bar asks to group only when they changed. */
13
+ const sameLevels = (one, other) => one.length === other.length &&
14
+ one.every((level, at) => level.field === other[at]?.field && level.grain === other[at]?.grain);
15
+ /** The named filters as the panel lists them: each `group` apart, in the order declared; the
16
+ * ones without a group together, where the first of them was. */
17
+ function panelOf(filters, isSet) {
18
+ const order = [];
19
+ const by = new Map();
20
+ for (const one of filters) {
21
+ const key = one.group ?? "";
22
+ if (!by.has(key)) {
23
+ by.set(key, []);
24
+ order.push(key);
25
+ }
26
+ by.get(key).push(one);
27
+ }
28
+ return order.map((key) => ({
29
+ options: (by.get(key) ?? []).map((one) => ({
30
+ id: one.id,
31
+ label: one.label,
32
+ checked: isSet(one.id),
33
+ })),
34
+ }));
35
+ }
12
36
  export function EntitySearchBar({ listing, filters = [], groups, groupable: only, facets: named, seed, recentKey, }) {
13
37
  const copy = frameworkCopy().list;
14
38
  const { meta, locale } = listing;
@@ -45,6 +69,13 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
45
69
  // Once the definition is known; what the person changes afterwards is theirs.
46
70
  // eslint-disable-next-line react-hooks/exhaustive-deps
47
71
  }, [meta, seed]);
72
+ // How a level reads in the bar's chain: the field's label, and its grain for a date.
73
+ const levelName = useMemo(() => levelLabeler(groupableOf(meta, locale)), [meta, locale]);
74
+ const levels = groups?.levels ?? NO_LEVELS;
75
+ // What the bar draws: how the set is grouped (always first), then what narrows it.
76
+ const shown = useMemo(() => (groups === undefined ? put : withLevels(put, levels, levelName)),
77
+ // eslint-disable-next-line react-hooks/exhaustive-deps
78
+ [put, levels, levelName, groups === undefined]);
48
79
  const control = useGroupingControl({
49
80
  levels: groups?.levels ?? NO_LEVELS,
50
81
  onLevelsChange: (next) => groups?.group(next),
@@ -55,20 +86,19 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
55
86
  setPut(next);
56
87
  listing.filter(selectionOf(next));
57
88
  };
89
+ // A change made in the bar: the grouping chain to the grouping, the rest to the filter.
90
+ const changed = (next) => {
91
+ const asked = levelsOf(next);
92
+ if (groups !== undefined && !sameLevels(asked, levels))
93
+ groups.group(asked);
94
+ place(filtersOf(next));
95
+ };
58
96
  // What the bar holds, as one selection: what the builder opens on.
59
97
  const current = selectionOf(put);
60
- return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria: put, onCriteriaChange: place, placeholder: copy.searchBar, searchRecords: searchRecords, ...(browseRecords === null ? {} : { browseRecords }), ...(filters.length === 0
98
+ return (_jsxs(_Fragment, { children: [_jsx(SearchBar, { facets: facets, model: asked ?? model, criteria: shown, onCriteriaChange: changed, placeholder: copy.searchBar, searchRecords: searchRecords, ...(browseRecords === null ? {} : { browseRecords }), ...(filters.length === 0
61
99
  ? {}
62
100
  : {
63
- filters: [
64
- {
65
- options: filters.map((one) => ({
66
- id: one.id,
67
- label: one.label,
68
- checked: hasNamed(put, one.id),
69
- })),
70
- },
71
- ],
101
+ filters: panelOf(filters, (id) => hasNamed(put, id)),
72
102
  onFilterSelect: (id) => {
73
103
  const named = filters.find((one) => one.id === id);
74
104
  if (named !== undefined)
@@ -76,7 +106,8 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
76
106
  id: named.id,
77
107
  label: named.label,
78
108
  selection: named.selection,
79
- }));
109
+ ...(named.group === undefined ? {} : { group: named.group }),
110
+ }, { or: ui.search.or }));
80
111
  },
81
112
  }), ...(groups === undefined || groupable.length === 0
82
113
  ? {}
@@ -1,5 +1,5 @@
1
1
  import type { Rehearsal } from "../../react/useCommand.js";
2
- import type { AskForm } from "./ask.js";
2
+ import { type AskForm } from "./ask.js";
3
3
  import { type ReactNode } from "react";
4
4
  /** What a person filled in before the action runs, by field name. */
5
5
  export type Asked = Readonly<Record<string, unknown>>;
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { frameworkCopy } from "../../core/copy.js";
4
+ import { unansweredOf } from "./ask.js";
4
5
  import { Refused } from "../Refused.js";
5
6
  import { Button, Dialog, Field, FormSection } from "@sincpro/web-ui";
6
7
  import { useState } from "react";
@@ -19,7 +20,11 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
19
20
  const copy = frameworkCopy().command;
20
21
  const [values, setValues] = useState(() => ({ ...form.initial }));
21
22
  const rehearsing = action.rehearse !== undefined;
23
+ // A required answer left empty keeps it from running — the server would only refuse it.
24
+ const unanswered = unansweredOf(form, values);
22
25
  const confirm = async () => {
26
+ if (unanswered.length > 0)
27
+ return;
23
28
  if (rehearsing && action.rehearsal === null) {
24
29
  await action.rehearse?.(values);
25
30
  return;
@@ -28,7 +33,7 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
28
33
  if (answer !== undefined)
29
34
  onDone(answer);
30
35
  };
31
- return (_jsxs(Dialog, { open: true, ...words, onClose: onClose, footer: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
36
+ return (_jsxs(Dialog, { open: true, ...words, onClose: onClose, footer: _jsxs("div", { className: "flex items-center justify-end gap-2", children: [unanswered.length === 0 ? null : (_jsx("p", { className: "mr-auto text-meta text-muted", children: frameworkCopy().record.missing(unanswered) })), _jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || unanswered.length > 0, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
32
37
  const control = {
33
38
  value: values[field.name],
34
39
  set: (next) => {
@@ -43,7 +48,7 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
43
48
  };
44
49
  // A control that names itself is not wrapped in a `Field` (its name would double):
45
50
  // what is expected goes under it.
46
- return field.labelled ? (_jsxs("div", { className: "flex flex-col gap-1", children: [field.draw(control), field.hint === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: field.hint }))] }, field.name)) : (_jsx(Field, { label: field.label, ...(field.hint === undefined ? {} : { hint: field.hint }), children: field.draw(control) }, field.name));
51
+ return field.labelled ? (_jsxs("div", { className: "flex flex-col gap-1", children: [field.draw(control), field.hint === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: field.hint }))] }, field.name)) : (_jsx(Field, { label: field.label, required: field.required, ...(field.hint === undefined ? {} : { hint: field.hint }), children: field.draw(control) }, field.name));
47
52
  }) }), action.rehearsal === null ? null : _jsx("p", { className: "text-ink", children: action.rehearsal.text })] }));
48
53
  }
49
54
  /**
@@ -11,6 +11,7 @@ import type { ReactNode } from "react";
11
11
  * label="Delegar áreas…" ask={["areas"]} />
12
12
  * ask={[{ name: "motivo", label: "Motivo", widget: "textarea" }]}
13
13
  * ask={[{ name: "role", label: "Rol", choices: ROLES, initial: "member", hint: "Lo que podrá hacer" }]}
14
+ * ask={[{ name: "observacion", label: "Motivo", widget: "textarea", required: true }]}
14
15
  *
15
16
  * Context: a Command that needs input could not live among a record's actions, so a screen drew
16
17
  * its fields in the record's body with a button of their own. What the dialog shows is the
@@ -20,6 +21,11 @@ import type { ReactNode } from "react";
20
21
  * hint, `{ name: "motivo", label, widget }` a field the entity lacks. A control of the
21
22
  * application's goes in with `as`, never a widget named in a string (`widget` takes only the
22
23
  * framework's own).
24
+ *
25
+ * A required answer (`required`, or a field the model marks required) keeps «Confirmar» off
26
+ * until it is given, and the dialog says what is missing: a reason left empty used to reach the
27
+ * server only to be refused (422). Only the presence is checked here — how long or what shape an
28
+ * answer must have is the use case's rule, and its refusal lands on the field.
23
29
  */
24
30
  export type AskField = string | {
25
31
  name: string;
@@ -42,6 +48,9 @@ export type AskField = string | {
42
48
  initial?: unknown;
43
49
  /** What is expected, said by the field — over the backend's own help for it. */
44
50
  hint?: string;
51
+ /** It must be answered before the action runs — over the model's `required` for a field of
52
+ * the entity. «Confirmar» stays off while it is empty. */
53
+ required?: boolean;
45
54
  };
46
55
  /** A field ready to draw: its name, its label, its control. */
47
56
  export type AskedField = {
@@ -49,6 +58,8 @@ export type AskedField = {
49
58
  label: string;
50
59
  /** What is expected — the action's hint, or the model's help for the field. */
51
60
  hint?: string | undefined;
61
+ /** It must be answered before the action runs. */
62
+ required: boolean;
52
63
  /** It draws its own label — a yes/no, a list of checks —: not wrapped in a `Field`. */
53
64
  labelled: boolean;
54
65
  draw: (control: FieldControl) => ReactNode;
@@ -70,3 +81,10 @@ export declare function askFormOf(fields: readonly AskField[], options: {
70
81
  /** The declared entity a relation points at, to choose it with its picker. */
71
82
  entityFor?: (target: string) => Entity | undefined;
72
83
  }): AskForm;
84
+ /**
85
+ * The labels of the required answers still empty, in the order they are asked: what keeps an
86
+ * action from running, as the dialog says it.
87
+ *
88
+ * unansweredOf(form, { observacion: "" }) -> ["Motivo"]
89
+ */
90
+ export declare function unansweredOf(form: AskForm, values: Readonly<Record<string, unknown>>): string[];
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { choicesOf } from "@sincpro/criteria";
4
+ import { isEmptyValue } from "../../core/edit.js";
4
5
  import { fieldMetaOf, viewOf } from "../../core/present.js";
5
6
  import { relationFieldOf } from "../../core/relation.js";
6
7
  import { controlFor, RelationPicker, } from "./control.js";
@@ -41,10 +42,13 @@ export function askFormOf(fields, options) {
41
42
  const widget = said.widget ?? field?.widget;
42
43
  const label = said.label ?? view?.label ?? said.name;
43
44
  const hint = said.hint ?? view?.help;
45
+ // The model's fixed `required` only: a `required_when` speaks of the record's form.
46
+ const required = said.required ?? field?.required === true;
44
47
  asked.push({
45
48
  name,
46
49
  label,
47
50
  hint,
51
+ required,
48
52
  labelled: said.as === undefined && target === undefined && labels(type, [...choices]),
49
53
  draw: said.as ??
50
54
  (target === undefined
@@ -61,3 +65,14 @@ export function askFormOf(fields, options) {
61
65
  }
62
66
  return { fields: asked, initial };
63
67
  }
68
+ /**
69
+ * The labels of the required answers still empty, in the order they are asked: what keeps an
70
+ * action from running, as the dialog says it.
71
+ *
72
+ * unansweredOf(form, { observacion: "" }) -> ["Motivo"]
73
+ */
74
+ export function unansweredOf(form, values) {
75
+ return form.fields
76
+ .filter((one) => one.required && isEmptyValue(values[one.name]))
77
+ .map((one) => one.label);
78
+ }
@@ -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
  : {