@sincpro/web-framework 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +10 -10
  2. package/dist/core/copy.d.ts +3 -1
  3. package/dist/core/copy.js +2 -2
  4. package/dist/core/index.d.ts +2 -2
  5. package/dist/core/index.js +2 -2
  6. package/dist/core/lines.d.ts +12 -4
  7. package/dist/core/lines.js +15 -3
  8. package/dist/core/present.d.ts +1 -0
  9. package/dist/core/present.js +54 -6
  10. package/dist/core/related.d.ts +5 -1
  11. package/dist/core/related.js +13 -12
  12. package/dist/core/relation.d.ts +23 -1
  13. package/dist/core/relation.js +33 -1
  14. package/dist/react/context.d.ts +5 -1
  15. package/dist/react/context.js +11 -2
  16. package/dist/react/useGroups.js +2 -2
  17. package/dist/react/useHistory.js +2 -2
  18. package/dist/react/useListing.js +10 -1
  19. package/dist/react/useLookup.js +2 -2
  20. package/dist/react/useNameOf.js +2 -2
  21. package/dist/react/usePivot.js +2 -2
  22. package/dist/react/useRecord.js +17 -2
  23. package/dist/react/useRelated.d.ts +5 -4
  24. package/dist/react/useRelated.js +14 -13
  25. package/dist/web/index.d.ts +1 -1
  26. package/dist/web/index.js +1 -1
  27. package/dist/web/record/EntityPicker.d.ts +7 -4
  28. package/dist/web/record/EntityPicker.js +5 -5
  29. package/dist/web/record/RelatedList.js +9 -6
  30. package/dist/web/record/control.d.ts +3 -1
  31. package/dist/web/record/control.js +8 -5
  32. package/dist/web/record/edit.js +23 -3
  33. package/dist/web/record/lines.js +13 -2
  34. package/dist/web/record/record.d.ts +12 -2
  35. package/dist/web/record/record.js +10 -2
  36. package/dist/web/workspace/SincproApp.d.ts +8 -18
  37. package/dist/web/workspace/SincproApp.js +17 -5
  38. package/dist/web/workspace/record.d.ts +59 -12
  39. package/dist/web/workspace/record.js +88 -27
  40. package/package.json +11 -11
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import {} from "@sincpro/client-framework";
3
+ import { relatedScope } from "../core/relation.js";
3
4
  import { useListing } from "./useListing.js";
4
5
  /**
5
6
  * The records a relation of ONE record points to, as a live listing of the related entity.
@@ -7,27 +8,27 @@ import { useListing } from "./useListing.js";
7
8
  * Context: sincpro_framework sends a one2many inside its record as ONE page (`RecordLines` draws
8
9
  * it). A customer with forty thousand invoices, a tenant with a thousand members, the lines of a
9
10
  * big order need more than that page: search in them, order them, walk them. The model says how
10
- * to ask — the related aggregate's key that points back (`identified_by`) — so the relation is
11
- * a criteria over the related entity, `where <that key> = <this record's key>`, answered by the
12
- * server like any list. The relation's scope is AND-ed with everything else, so no search, filter
13
- * or page can ever leave it.
11
+ * to ask — the related aggregate's key that points back (`identified_by`), or the two fields of a
12
+ * relation by a business key (`parent_field`, `related_field`) — so the relation is a criteria
13
+ * over the related entity (@sincpro/client-framework's `relatedCriteria`), answered by the server
14
+ * like any list. The relation's scope is AND-ed with everything else, so no search, filter or
15
+ * page can ever leave it.
14
16
  *
15
17
  * const facturas = useRelated(cliente, "invoices", invoicesEntity);
16
18
  * <EntityList listing={facturas} embedded />
17
19
  */
18
20
  export function useRelated(record, name, related, options = {}) {
19
21
  const field = record.meta?.fields[name];
20
- const key = field?.identified_by ?? "";
21
22
  const own = record.meta?.get_id || record.meta?.identity || "id";
22
- const value = record.record === null ? null : record.record[own];
23
- const scope = {
23
+ const asked = relatedScope(record.record, field, own, options.criteria);
24
+ // No key to ask by yet — the record or its definition has not arrived, or the record is new: a
25
+ // question that matches nothing (an empty `in`), never one that would list every orphan. It is
26
+ // asked over the field that points back when the definition names it: the related entity has
27
+ // that one, and it may have no `id`.
28
+ const nothing = field?.related_field || field?.identified_by || "id";
29
+ const scope = asked ?? {
24
30
  ...options.criteria,
25
- selection: {
26
- all: [
27
- ...(options.criteria?.selection ? [options.criteria.selection] : []),
28
- { field: key, operator: "=", value: value },
29
- ],
30
- },
31
+ selection: { field: nothing, operator: "in", value: [] },
31
32
  };
32
33
  return useListing(related, { pageSize: 10, ...options, criteria: scope });
33
34
  }
@@ -23,7 +23,7 @@ export { cardOf, relationOf } from "./record/summary.js";
23
23
  export { Refused } from "./Refused.js";
24
24
  export { entityView, type EntityViewOptions, listView, type ListViewOptions, } from "./workspace/composer.js";
25
25
  export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
26
- export { EntityRecord } from "./workspace/record.js";
26
+ export { EntityRecord, type Stamp, useRecordScreen, } from "./workspace/record.js";
27
27
  export { SincproApp } from "./workspace/SincproApp.js";
28
28
  export { webUiSkin } from "./workspace/skin.js";
29
29
  export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
package/dist/web/index.js CHANGED
@@ -23,7 +23,7 @@ export { cardOf, relationOf } from "./record/summary.js";
23
23
  export { Refused } from "./Refused.js";
24
24
  export { entityView, listView, } from "./workspace/composer.js";
25
25
  export { openIn, openOptions, RECORD_SIZE, RelatedRecord, targetsFor, } from "./workspace/open.js";
26
- export { EntityRecord } from "./workspace/record.js";
26
+ export { EntityRecord, useRecordScreen, } from "./workspace/record.js";
27
27
  export { SincproApp } from "./workspace/SincproApp.js";
28
28
  export { webUiSkin } from "./workspace/skin.js";
29
29
  export { chooserIn, useFollowed, useRecordInWorkspace, } from "./workspace/workspace.js";
@@ -32,9 +32,9 @@ import { type OpenTarget } from "@sincpro/web-ui";
32
32
  * way to the server's literal search. The chooser is a table — the columns the list declares,
33
33
  * or `columns` — searched by the entity's literal search on the server.
34
34
  *
35
- * A field that may stay empty offers that as a choice (`none`): «Ninguno», or the screen's own
36
- * word («Sin tenant»), answered as `""`. web-ui's `Picker` has no way to clear a choice, so it
37
- * is the first option, while nothing is typed. `exclude` leaves keys out of the choices — the
35
+ * A field that may stay empty says so with `onClear`: a × beside the chosen name, or the name
36
+ * erased and the field left (web-ui's `Picker onClear`). Where the empty choice has a word of its
37
+ * own («Sin tenant»), `none` also offers it as the first option, answered as `""`. `exclude` leaves keys out of the choices — the
38
38
  * tenants a project is already shared with —, in the picker and its chooser, and the SERVER
39
39
  * leaves them out (`useLookup exclude`).
40
40
  *
@@ -42,7 +42,7 @@ import { type OpenTarget } from "@sincpro/web-ui";
42
42
  * <EntityPicker entity={activeCustomers} columns={["name", "tax_id", "city"]} … />
43
43
  * <EntityPicker entity={tenants} none="Sin tenant" exclude={sharedWith} … />
44
44
  */
45
- export declare function EntityPicker<T extends AnyRecord>({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser, criteria, columns, browse, none, exclude, placeholder, disabled, "aria-label": ariaLabel, }: {
45
+ export declare function EntityPicker<T extends AnyRecord>({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser, criteria, columns, browse, none, onClear, exclude, placeholder, disabled, "aria-label": ariaLabel, }: {
46
46
  /** What is chosen from: an entity, or a named list of it (its cut, columns and title). */
47
47
  entity: Entity<T> | ListDefinition<T>;
48
48
  /** The chooser's columns. Without it, the named list's, or every scalar field. */
@@ -54,6 +54,9 @@ export declare function EntityPicker<T extends AnyRecord>({ entity, value, onCha
54
54
  /** The field may stay empty: a first choice that answers `""` — `true` says «Ninguno», a
55
55
  * text is the screen's own word for it. */
56
56
  none?: boolean | string;
57
+ /** The choice can be removed: a × beside it, and erasing the name and leaving the field
58
+ * (web-ui's `Picker onClear`). A field that is not required passes it. */
59
+ onClear?: () => void;
57
60
  /** Keys never offered — those already chosen elsewhere. Left out by the server. */
58
61
  exclude?: readonly string[];
59
62
  value?: string;
@@ -43,9 +43,9 @@ import { useState } from "react";
43
43
  * way to the server's literal search. The chooser is a table — the columns the list declares,
44
44
  * or `columns` — searched by the entity's literal search on the server.
45
45
  *
46
- * A field that may stay empty offers that as a choice (`none`): «Ninguno», or the screen's own
47
- * word («Sin tenant»), answered as `""`. web-ui's `Picker` has no way to clear a choice, so it
48
- * is the first option, while nothing is typed. `exclude` leaves keys out of the choices — the
46
+ * A field that may stay empty says so with `onClear`: a × beside the chosen name, or the name
47
+ * erased and the field left (web-ui's `Picker onClear`). Where the empty choice has a word of its
48
+ * own («Sin tenant»), `none` also offers it as the first option, answered as `""`. `exclude` leaves keys out of the choices — the
49
49
  * tenants a project is already shared with —, in the picker and its chooser, and the SERVER
50
50
  * leaves them out (`useLookup exclude`).
51
51
  *
@@ -53,7 +53,7 @@ import { useState } from "react";
53
53
  * <EntityPicker entity={activeCustomers} columns={["name", "tax_id", "city"]} … />
54
54
  * <EntityPicker entity={tenants} none="Sin tenant" exclude={sharedWith} … />
55
55
  */
56
- export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser = false, criteria, columns, browse = true, none, exclude, placeholder, disabled, "aria-label": ariaLabel, }) {
56
+ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onBrowseAll, ownChooser = false, criteria, columns, browse = true, none, onClear, exclude, placeholder, disabled, "aria-label": ariaLabel, }) {
57
57
  const base = isList(entity) ? entity.entity : entity;
58
58
  const { metas } = useFramework();
59
59
  const opening = useRecordOpening();
@@ -101,7 +101,7 @@ export function EntityPicker({ entity, value, onChange, onOpen, openTargets, onB
101
101
  : look(lookup.chosen.record).name) ?? lookup.chosen.label,
102
102
  }), onChange: (id) => onChange(id, lookup.options.find((one) => one.id === id)?.record), ...(lookup.searchable ? { onSearch: lookup.search } : {}),
103
103
  // «Loading» only before there is anything: refining keeps the ten on screen.
104
- loading: lookup.loading && lookup.options.length === 0, ...(opens === undefined || value === "" ? {} : { onOpen: opens }), ...(targets === undefined ? {} : { openTargets: targets }), onBrowseAll: browseAll, ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
104
+ loading: lookup.loading && lookup.options.length === 0, ...(onClear === undefined || disabled === true ? {} : { onClear }), ...(opens === undefined || value === "" ? {} : { onOpen: opens }), ...(targets === undefined ? {} : { openTargets: targets }), onBrowseAll: browseAll, ...(placeholder === undefined ? {} : { placeholder }), ...(disabled === undefined ? {} : { disabled }), ...(ariaLabel === undefined ? {} : { "aria-label": ariaLabel }) }));
105
105
  return (_jsxs(_Fragment, { children: [browse ? (_jsxs("span", { className: "flex min-w-0 items-start gap-1", children: [_jsx("span", { className: "min-w-0 flex-1", children: picker }), _jsx(IconButton, { icon: TextSearch, label: frameworkCopy().picker.browse, onClick: () => browseAll(lookup.text), ...(disabled === undefined ? {} : { disabled }) })] })) : (picker), choosing ? (_jsx(Chooser, { entity: entity, ...(columns === undefined ? {} : { columns }), ...(scope === undefined ? {} : { criteria: scope }), onChoose: (id, row) => {
106
106
  onChange(id, row);
107
107
  setChoosing(false);
@@ -3,6 +3,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  import {} from "@sincpro/client-framework";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
5
  import { defaultFields } from "../../core/present.js";
6
+ import { backReference, isKeyValue } from "../../core/relation.js";
6
7
  import { useRelated } from "../../react/useRelated.js";
7
8
  import { EntityList } from "../list/EntityList.js";
8
9
  import { useRecordOpening } from "./opening.js";
@@ -26,22 +27,24 @@ import { useMemo } from "react";
26
27
  export function RelatedList({ record, name, entity, pageSize, ...list }) {
27
28
  const listing = useRelated(record, name, entity, pageSize === undefined ? {} : { pageSize });
28
29
  const opening = useRecordOpening();
29
- // Every row points back to THIS record: the column that says so is the same on all of them.
30
- const back = record.meta?.fields[name]?.identified_by;
30
+ // Every row points back to THIS record: the column that says so is the same on all of them —
31
+ // the same key `useRelated` scopes the list by, by identity or by a business key.
32
+ const identity = record.meta?.get_id || record.meta?.identity || "id";
33
+ const pointing = backReference(record.record, record.meta?.fields[name], identity);
34
+ const back = pointing?.field;
31
35
  const own = list.columns;
32
36
  const columns = useMemo(() => own ??
33
37
  (listing.meta === null || !back
34
38
  ? undefined
35
39
  : defaultFields(listing.meta).filter((field) => field !== back)), [own, listing.meta, back]);
36
40
  const create = opening?.create;
37
- // The value the rows point back with — the same key `useRelated` scopes the list by.
38
- const identity = record.meta?.get_id || record.meta?.identity || "id";
39
- const here = record.record === null ? undefined : record.record[identity];
41
+ // The value the rows point back with.
42
+ const here = pointing?.value;
40
43
  const adding = create === undefined ||
41
44
  entity.create === undefined ||
42
45
  !back ||
43
46
  record.isNew ||
44
- here === undefined ||
47
+ !isKeyValue(here) ||
45
48
  record.edit.state(name).readonly ? null : (_jsx(Button, { size: "sm", role: "secondary", onClick: () => create(entity, { [back]: here }, listing.reload), children: frameworkCopy().record.add }));
46
49
  return (_jsx(EntityList, { listing: listing, embedded: true, ...list, ...(columns === undefined ? {} : { columns }), ...(adding === null && list.actions === undefined
47
50
  ? {}
@@ -32,12 +32,14 @@ export declare function controlFor(control: FieldControl, type: string, exact: b
32
32
  * workspace's chooser (`RecordLinesEditor`), so «Buscar más…» is the picker's own there;
33
33
  * `ownChooser` asks for it anywhere else.
34
34
  */
35
- export declare function RelationPicker({ target, value, onChange, label, ownChooser, standalone, }: {
35
+ export declare function RelationPicker({ target, value, onChange, label, ownChooser, standalone, onClear, }: {
36
36
  target: Entity;
37
37
  value: string;
38
38
  onChange: (id: string, chosen?: AnyRecord) => void;
39
39
  label: string;
40
40
  ownChooser?: boolean;
41
+ /** The choice can be removed — a field that is not required. */
42
+ onClear?: () => void;
41
43
  /** No `Field` names it (a cell): it carries `label` itself — as `FieldControl.standalone`. */
42
44
  standalone?: boolean;
43
45
  }): import("react").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { instantOf, timeZoneNow, wallTimeOf } from "@sincpro/client-framework";
3
+ import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
4
4
  import { EntityPicker } from "./EntityPicker.js";
5
5
  import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
6
6
  /**
@@ -28,8 +28,11 @@ export function controlFor(control, type, exact, choices) {
28
28
  const zone = timeZoneNow();
29
29
  return (_jsx(DateTimePicker, { value: typeof value === "string" && value !== "" ? wallTimeOf(value, zone) : null, onChange: (wall) => set(wall === null ? null : instantOf(wall, zone)), ...named }));
30
30
  }
31
- case "date":
32
- return (_jsx(DatePicker, { value: typeof value === "string" && value !== "" ? value : null, onChange: set, ...named }));
31
+ case "date": {
32
+ // «Today» is the business's day, on the installed zone — never the browser's.
33
+ const today = dayOf(new Date().toISOString(), timeZoneNow());
34
+ return (_jsx(DatePicker, { ...(today === null ? {} : { today }), value: typeof value === "string" && value !== "" ? value : null, onChange: set, ...named }));
35
+ }
33
36
  case "text[]": {
34
37
  // A list of words is chips: each word is its own key, and typing a new one adds it.
35
38
  const words = Array.isArray(value) ? value.map(String) : [];
@@ -48,10 +51,10 @@ export function controlFor(control, type, exact, choices) {
48
51
  * workspace's chooser (`RecordLinesEditor`), so «Buscar más…» is the picker's own there;
49
52
  * `ownChooser` asks for it anywhere else.
50
53
  */
51
- export function RelationPicker({ target, value, onChange, label, ownChooser = false, standalone = false, }) {
54
+ export function RelationPicker({ target, value, onChange, label, ownChooser = false, standalone = false, onClear, }) {
52
55
  // Opening the chosen record and «Buscar más…» are the workspace's when there is one: the
53
56
  // picker reads it (`RecordOpening`); a line keeps its own chooser.
54
57
  return (_jsx(EntityPicker, { entity: target, value: value, onChange: onChange,
55
58
  // «Buscar más…» is an option of the picker already: no second button beside it.
56
- browse: false, ownChooser: ownChooser, ...(standalone ? { "aria-label": label } : {}) }));
59
+ browse: false, ownChooser: ownChooser, ...(onClear === undefined ? {} : { onClear }), ...(standalone ? { "aria-label": label } : {}) }));
57
60
  }
@@ -63,12 +63,24 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
63
63
  // A one2many of no declared entity (the lines of an invoice): edited inside the record as a
64
64
  // whole list (`RecordLinesEditor`) — or, when the record brought only a page, that page read
65
65
  // only with its real total.
66
- if (as === undefined && relation?.field.type === "one2many" && target === undefined) {
67
- // Editable when the record holds ALL its lines; a page of them stays read only.
66
+ // A list of values inside the record (`field.embedded(definition, { many: true })`: a
67
+ // project's channels, an inventory's components) — no model of its own, no id — is edited the
68
+ // same way as lines: a whole list, local keys, through the record's own save.
69
+ const own = meta?.fields[name];
70
+ if (as === undefined && own?.type === "embedded" && own.many === true && own.definition) {
71
+ // A page of them stays read only, as a one2many's: written back whole it would drop what
72
+ // it did not bring.
68
73
  const whole = editableLines(edit.values[name]);
69
74
  const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, locale: locale })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
70
75
  return bare ? lines : _jsx(FormSection, { title: view.label, children: lines });
71
76
  }
77
+ if (as === undefined && relation?.field.type === "one2many" && target === undefined) {
78
+ // Editable when the record holds ALL its lines; a page of them stays read only, and so do
79
+ // the records it only references — nothing it saves writes them.
80
+ const whole = editableLines(edit.values[name], relation.field);
81
+ const lines = whole === null ? (_jsx(RecordLines, { record: record.record ?? {}, meta: meta, name: name, locale: locale })) : (_jsx(RecordLinesEditor, { record: record, name: name, lines: whole, ...(look === undefined ? {} : { look }) }));
82
+ return bare ? lines : _jsx(FormSection, { title: view.label, children: lines });
83
+ }
72
84
  if (as === undefined && relation?.field.type === "one2many" && target !== undefined) {
73
85
  const list = (_jsx(RelatedList, { record: record, name: name, entity: target, ...(opening === null
74
86
  ? {}
@@ -119,7 +131,15 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
119
131
  return _jsx(KeyValue, { target: target, id: id, ...opens });
120
132
  return (_jsx(RelationValue, { name: textOf(meta, relation.relation, edit.values[relation.relation], locale) ?? id, ...opens }));
121
133
  }
122
- return (_jsx(RelationPicker, { target: target, value: id, onChange: (next) => edit.set(relation.key, next), label: view.label }));
134
+ return (_jsx(RelationPicker, { target: target, value: id, onChange: (next) => edit.set(relation.key, next), label: view.label, ...(state.required || edit.state(relation.key).required
135
+ ? {}
136
+ : {
137
+ onClear: () => {
138
+ edit.set(relation.key, null);
139
+ if (relation.held)
140
+ edit.set(relation.relation, null);
141
+ },
142
+ }) }));
123
143
  }
124
144
  if (view.type === "boolean" && as === undefined)
125
145
  return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
@@ -48,7 +48,14 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
48
48
  // would put the record IN the key.
49
49
  write(relation.held
50
50
  ? { [relation.key]: id, [relation.relation]: chosen ?? null }
51
- : { [relation.key]: id }) }));
51
+ : { [relation.key]: id }), ...(definition?.fields[relation.key]?.required === true ||
52
+ definition?.fields[relation.key]?.required_when !== undefined
53
+ ? {}
54
+ : {
55
+ onClear: () => write(relation.held
56
+ ? { [relation.key]: null, [relation.relation]: null }
57
+ : { [relation.key]: null }),
58
+ }) }));
52
59
  }
53
60
  return controlFor({
54
61
  value: line[field],
@@ -92,7 +99,11 @@ export function RecordLinesEditor({ record, name, lines, look = {}, }) {
92
99
  const { entities, metas } = useFramework();
93
100
  const opening = useRecordOpening();
94
101
  const definition = meta?.fields[name]?.definition ?? null;
95
- const identity = definition?.identity || "id";
102
+ // A value inside the record (an embedded list) has no identity of its own: every line is
103
+ // keyed locally — falling back to `id` would key it by whatever it holds under that name.
104
+ const identity = meta?.fields[name]?.type === "embedded"
105
+ ? (definition?.identity ?? "")
106
+ : definition?.identity || "id";
96
107
  const fields = lineFields(definition);
97
108
  const shown = look.columns === undefined ? fields : look.columns.filter((one) => fields.includes(one));
98
109
  const controls = look.controls ?? {};
@@ -1,5 +1,5 @@
1
1
  import { type AnyRecord, type Meta } from "@sincpro/criteria";
2
- import { type SheetField } from "@sincpro/web-ui";
2
+ import { type RowAction, type SheetField } from "@sincpro/web-ui";
3
3
  import type { ReactNode } from "react";
4
4
  export declare function factsOf<T extends AnyRecord>(record: T, meta: Meta | null | undefined, names: readonly string[], options?: {
5
5
  locale?: string | undefined;
@@ -13,8 +13,16 @@ export declare function countOf(record: AnyRecord, name: string): number;
13
13
  * Its columns come from the relation's own definition when the server expanded it, and are
14
14
  * read off the rows otherwise. When the record brought only one page of them, it says so —
15
15
  * «se muestran 50 de 1000» — instead of drawing 50 as if they were all.
16
+ *
17
+ * `rowActions` acts on a part from its row — a group's member, a project's share — with a
18
+ * Command of the record (`useCommand(projects, "unshareProject")`): the parts have no route of
19
+ * their own, so what removes one is the record's, and the screen names it.
20
+ *
21
+ * <RecordLines record={project} meta={meta} name="shares"
22
+ * rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
23
+ * onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
16
24
  */
17
- export declare function RecordLines<T extends AnyRecord>({ record, meta, name, columns, cells, locale, onOpen, }: {
25
+ export declare function RecordLines<T extends AnyRecord>({ record, meta, name, columns, cells, locale, onOpen, rowActions, }: {
18
26
  record: AnyRecord;
19
27
  meta: Meta | null | undefined;
20
28
  name: string;
@@ -22,4 +30,6 @@ export declare function RecordLines<T extends AnyRecord>({ record, meta, name, c
22
30
  cells?: Readonly<Partial<Record<string, (row: T) => ReactNode>>>;
23
31
  locale?: string | undefined;
24
32
  onOpen?: (row: T) => void;
33
+ /** What a row's part can be acted on with — a Command of the record. */
34
+ rowActions?: (row: T) => readonly RowAction[];
25
35
  }): import("react").JSX.Element;
@@ -46,11 +46,19 @@ export function countOf(record, name) {
46
46
  * Its columns come from the relation's own definition when the server expanded it, and are
47
47
  * read off the rows otherwise. When the record brought only one page of them, it says so —
48
48
  * «se muestran 50 de 1000» — instead of drawing 50 as if they were all.
49
+ *
50
+ * `rowActions` acts on a part from its row — a group's member, a project's share — with a
51
+ * Command of the record (`useCommand(projects, "unshareProject")`): the parts have no route of
52
+ * their own, so what removes one is the record's, and the screen names it.
53
+ *
54
+ * <RecordLines record={project} meta={meta} name="shares"
55
+ * rowActions={(share) => [{ id: "unshare", label: "Quitar", icon: X, tone: "danger",
56
+ * onSelect: () => unshare.run(project.id, { tenant_id: share.tenant_id }) }]} />
49
57
  */
50
- export function RecordLines({ record, meta, name, columns, cells, locale, onOpen, }) {
58
+ export function RecordLines({ record, meta, name, columns, cells, locale, onOpen, rowActions, }) {
51
59
  const related = relatedOf(record[name]);
52
60
  const definition = meta?.fields[name]?.definition ?? describeRows(related.items);
53
61
  const identity = definition.identity || "id";
54
62
  const copy = frameworkCopy();
55
- return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(List, { embedded: true, items: related.items, keyOf: (row) => String(row[identity]), present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), children: _jsx(List.Table, { columns: columnsOf(definition, columns, { locale, ...(cells ? { cells } : {}) }) }) }), related.partial ? (_jsx("p", { className: "text-meta text-muted", children: copy.record.partial(related.items.length, related.count.value) })) : null] }));
63
+ return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(List, { embedded: true, items: related.items, keyOf: (row) => String(row[identity]), present: "table", empty: { sentence: copy.list.empty }, ...(onOpen === undefined ? {} : { onOpen }), children: _jsx(List.Table, { columns: columnsOf(definition, columns, { locale, ...(cells ? { cells } : {}) }), ...(rowActions === undefined ? {} : { rowActions }) }) }), related.partial ? (_jsx("p", { className: "text-meta text-muted", children: copy.record.partial(related.items.length, related.count.value, related.count.exact) })) : null] }));
56
64
  }
@@ -1,25 +1,9 @@
1
1
  import { type Entity, type Transport } from "@sincpro/client-framework";
2
2
  import type { Meta } from "@sincpro/criteria";
3
- import { type ComposerSkin, type ResourceRef, type ViewSpec, type WorkspaceStore } from "@sincpro/web-composer";
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
5
  import { type ReactNode } from "react";
6
- /**
7
- * The application context in one place: who answers (the transport), in which language, which
8
- * model definitions are already known, the toasts, and the workspace with its views, ⌘K and
9
- * shortcuts.
10
- *
11
- * Context: forge's `main.tsx` + `console.tsx` installed three copy tables, a toast provider, a
12
- * context of its own and a composer by hand. This is that, once. It is a convenience, not the
13
- * only door: everything it mounts is exported, and an app with its own shell mounts them itself.
14
- * What it does NOT own: the session (the app builds the transport with its headers) and what the
15
- * application bar says. The bar is the app's (`bar`), drawn above the workspace inside every
16
- * provider; a menu in it opens views through the workspace the app holds (`workspace`, from
17
- * composer's `useWorkspace()`) — a workspace owned in here could not be reached from outside.
18
- *
19
- * const workspace = useWorkspace();
20
- * <SincproApp workspace={workspace} bar={<Menu onOpen={(ref) => workspace.push(ref)} />} … />
21
- */
22
- export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, }: {
6
+ export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, onViewError, }: {
23
7
  transport: Transport;
24
8
  /** The entities as composer views — `entityView(…)` — and any other view of the app. */
25
9
  views: readonly ViewSpec[];
@@ -50,4 +34,10 @@ export declare function SincproApp({ transport, views, start, language, metas, e
50
34
  /** The application's bar, above the workspace and inside the providers: its menus may read
51
35
  * the framework (`useFramework`) and open views through `workspace`. */
52
36
  bar?: ReactNode;
37
+ /**
38
+ * Told when a view breaks while drawing. By default it reaches the process's error reporter
39
+ * (`reportError`, @sincpro/client-framework) — the one the use cases report to — as
40
+ * `view <ref>`; without a reporter configured, nothing is sent.
41
+ */
42
+ onViewError?: OnViewError;
53
43
  }): import("react").JSX.Element;
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import {} from "@sincpro/client-framework";
3
+ import { processContext, reportError, } from "@sincpro/client-framework";
4
4
  import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
5
- import { createRegistry } from "@sincpro/web-composer/domain";
6
- import { cachedTransport } from "../../core/cache.js";
5
+ import { createRegistry, formatRef } from "@sincpro/web-composer/domain";
6
+ import { cachedTransport, } from "../../core/cache.js";
7
7
  import { installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "../../core/copy.js";
8
8
  import { FrameworkProvider } from "../../react/context.js";
9
9
  import { webUiSkin } from "./skin.js";
@@ -25,7 +25,9 @@ import { useEffect, useMemo, useState } from "react";
25
25
  * const workspace = useWorkspace();
26
26
  * <SincproApp workspace={workspace} bar={<Menu onOpen={(ref) => workspace.push(ref)} />} … />
27
27
  */
28
- export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, workspace: given, bar, }) {
28
+ /** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
29
+ const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
30
+ export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, workspace: given, bar, onViewError = reportViewError, }) {
29
31
  // Installed once, before anything draws: the three tables are module state of their packages.
30
32
  useState(() => {
31
33
  if (language === "es") {
@@ -44,6 +46,16 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
44
46
  // The options are read once: a cache that changes shape mid-session forgets everything.
45
47
  // eslint-disable-next-line react-hooks/exhaustive-deps
46
48
  [transport]);
49
+ // What was read in one company is not the other's: a change of context forgets every answer
50
+ // before the screens read again (`FrameworkProvider` gives them another transport).
51
+ useEffect(() => {
52
+ if (cache === false)
53
+ return;
54
+ const forgetting = cached;
55
+ return processContext.watch(() => forgetting.invalidate());
56
+ // The cache is read once, as `cached` is.
57
+ // eslint-disable-next-line react-hooks/exhaustive-deps
58
+ }, [cached]);
47
59
  const own = useWorkspace();
48
60
  const workspace = given ?? own;
49
61
  const registry = useMemo(() => createRegistry(views), [views]);
@@ -53,5 +65,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
53
65
  // The first screen only: a re-render must not push it again.
54
66
  // eslint-disable-next-line react-hooks/exhaustive-deps
55
67
  }, [workspace]);
56
- return (_jsx(FrameworkProvider, { transport: cached, locale: language, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
68
+ return (_jsx(FrameworkProvider, { transport: cached, locale: language, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
57
69
  }
@@ -3,22 +3,69 @@ import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type ViewProps } from "@sincpro/web-composer";
4
4
  import { type RecordReading } from "../../react/useRecord.js";
5
5
  import { type ReactNode } from "react";
6
+ /** Who made a record, or changed it last, and when: `Record.Audit`'s. */
7
+ export type Stamp = {
8
+ at: string;
9
+ by?: string;
10
+ };
6
11
  /**
7
- * The record of an entity, drawn from its model — the screen `entityView` opens when the
8
- * application writes none: in the page, a modal, the preview or a panel, the same.
12
+ * What every record screen in a workspace does before drawing its own — what `EntityRecord`
13
+ * does, as values: read the record for editing, follow the workspace's breadcrumb, tell the
14
+ * workspace its name and its unsaved work, read its history, step to its neighbours in the list
15
+ * it was opened from, and say its name, state, unsaved work, refusal and authorship the way
16
+ * web-ui's `Record` takes them.
9
17
  *
10
- * Context: every Sincpro record screen was the same hundred lines: read it, tell the workspace
11
- * its name and its unsaved work, draw its name and state on top, its fields, its lines, the
12
- * conflict and the restored draft, who made it, its history. Here once, from what the model and
13
- * the entity already say (`formOf`, `summaryOf`): a new entity has a useful screen before anyone
14
- * writes it. It is a default, not a cage — `fields`/`pages` choose and order, `actions` puts the
15
- * record's commands, and any screen can drop this and keep `useRecord` + `RecordField`.
18
+ * function InvoiceScreen(props: ViewProps) {
19
+ * const screen = useRecordScreen(invoices, props);
20
+ * if (screen.reading.status !== "ready") return <Skeleton rows={6} />;
21
+ * return (
22
+ * <Record {...screen.record}>
23
+ * <Record.Rail>
24
+ * <Record.Crumbs crumbs={screen.crumbs} />
25
+ * {screen.pager ? <Record.Pager {...screen.pager} /> : null}
26
+ * </Record.Rail>
27
+ * <Record.Paper>…your own fields…</Record.Paper>
28
+ * </Record>
29
+ * );
30
+ * }
16
31
  *
17
- * entityView(invoices, { transport, name: "Facturas" }) // this screen
18
- * entityView(invoices, { …, record: (props) =>
19
- * <EntityRecord {...props} entity={invoices} fields={["customer_id", "due_date"]}
20
- * actions={(invoice) => <CommandButton entity={invoices} command="post" … />} /> })
32
+ * Context: the level between `EntityRecord` and `useRecord` — a screen of its own keeps every
33
+ * behaviour of the framework's record and writes its own tree. It answers PROPS, never
34
+ * components: web-ui finds a record's regions by type (`Record.Crumbs` a direct child of
35
+ * `Record.Rail`), and a region wrapped in one of ours is not found. Before it, forge's console
36
+ * carried these 150 lines itself (`shared/record_screen.tsx`).
21
37
  */
38
+ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>, { api, resource }: Pick<ViewProps, "api" | "resource">): {
39
+ reading: RecordReading<T>;
40
+ crumbs: readonly import("@sincpro/web-composer").Crumb[];
41
+ history: import("../../index.js").HistoryEntry[] | undefined;
42
+ summary: import("../../index.js").RecordSummary | undefined;
43
+ /** web-ui `Record`'s own props: where it is drawn, its name, its unsaved work, its refusal. */
44
+ record: {
45
+ error?: string | undefined;
46
+ dirty?: import("@sincpro/web-ui").DirtyState | undefined;
47
+ placement: "page" | "card";
48
+ identity: {
49
+ tag?: {
50
+ label: string;
51
+ } | undefined;
52
+ subtitle?: string | undefined;
53
+ title: string;
54
+ };
55
+ };
56
+ /** `Record.Pager`'s props, when it was opened from a list and nothing is typed. */
57
+ pager: {
58
+ index: number;
59
+ total: number;
60
+ onPrev: () => void;
61
+ onNext: () => void;
62
+ } | undefined;
63
+ /** `Record.Audit`'s props, when the record says who made it or changed it. */
64
+ audit: {
65
+ updated?: Stamp | undefined;
66
+ created?: Stamp | undefined;
67
+ } | undefined;
68
+ };
22
69
  export declare function EntityRecord<T extends AnyRecord>({ api, resource, entity, fields, pages, actions, }: ViewProps & {
23
70
  entity: Entity<T>;
24
71
  /** The fields, in this order. Without it, the model's (`formOf`). */