@sincpro/web-framework 2.5.0 → 2.6.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 (42) hide show
  1. package/README.md +31 -28
  2. package/dist/core/edit.d.ts +19 -0
  3. package/dist/core/edit.js +46 -0
  4. package/dist/core/index.d.ts +3 -3
  5. package/dist/core/index.js +3 -3
  6. package/dist/core/list.d.ts +20 -0
  7. package/dist/core/list.js +32 -1
  8. package/dist/core/present.d.ts +22 -0
  9. package/dist/core/present.js +51 -19
  10. package/dist/react/index.d.ts +3 -0
  11. package/dist/react/index.js +3 -0
  12. package/dist/react/useCount.d.ts +18 -0
  13. package/dist/react/useCount.js +23 -0
  14. package/dist/react/useRecord.d.ts +4 -4
  15. package/dist/react/useRecord.js +10 -7
  16. package/dist/react/useService.d.ts +5 -1
  17. package/dist/react/useServiceReading.d.ts +35 -0
  18. package/dist/react/useServiceReading.js +75 -0
  19. package/dist/react/useTextOf.d.ts +16 -0
  20. package/dist/react/useTextOf.js +21 -0
  21. package/dist/web/list/EntityList.d.ts +4 -1
  22. package/dist/web/list/EntityList.js +6 -3
  23. package/dist/web/list/EntitySearchBar.d.ts +4 -1
  24. package/dist/web/list/EntitySearchBar.js +2 -2
  25. package/dist/web/list/groups.d.ts +13 -3
  26. package/dist/web/list/groups.js +21 -8
  27. package/dist/web/list/openIn.d.ts +4 -2
  28. package/dist/web/list/openIn.js +9 -2
  29. package/dist/web/record/control.d.ts +9 -3
  30. package/dist/web/record/control.js +13 -4
  31. package/dist/web/record/edit.js +1 -1
  32. package/dist/web/record/lines.js +1 -1
  33. package/dist/web/record/record.js +36 -3
  34. package/dist/web/workspace/composer.d.ts +6 -2
  35. package/dist/web/workspace/composer.js +31 -12
  36. package/dist/web/workspace/open.d.ts +1 -1
  37. package/dist/web/workspace/open.js +7 -1
  38. package/dist/web/workspace/record.d.ts +6 -2
  39. package/dist/web/workspace/record.js +6 -5
  40. package/dist/web/workspace/workspace.d.ts +7 -1
  41. package/dist/web/workspace/workspace.js +13 -4
  42. package/package.json +4 -4
@@ -0,0 +1,75 @@
1
+ "use client";
2
+ import { listRoute } from "@sincpro/client-framework";
3
+ import { touches } from "../core/changes.js";
4
+ import { useFramework } from "./context.js";
5
+ import { useCallback, useEffect, useRef, useState } from "react";
6
+ /** Where `entity` is listed — or nothing to follow when it is listed only under a record. */
7
+ function routeOf(entity) {
8
+ try {
9
+ return listRoute(entity.list);
10
+ }
11
+ catch {
12
+ return undefined;
13
+ }
14
+ }
15
+ /**
16
+ * A use case that READS, run by the screen that shows it: on mount, again whenever its
17
+ * arguments change, when the process's context changes (another company), and when a write
18
+ * touches an entity it follows.
19
+ *
20
+ * const balance = useServiceReading(members.Accounts.balance, [{ member_id }], {
21
+ * follows: [payments],
22
+ * });
23
+ * balance.status === "ready" ? <Stat value={text.money(balance.answer)} /> : <Skeleton />
24
+ *
25
+ * Context: `useService` is an ACTION's — it runs when a person presses, never on mount — and a
26
+ * screen that read with it re-ran it by hand when a route param changed: easy to miss, and the
27
+ * screen kept showing the answer of the tab it left. Here a reading is keyed by its arguments
28
+ * (as JSON): the answer of other arguments is never shown — another member starts as `loading`,
29
+ * as `useRecord` does for another id — while reading the same ones again keeps the answer on
30
+ * screen until the new one lands. The last question wins: an answer to arguments no longer on
31
+ * screen is dropped. The use case is the latest the screen gave (a bounded context answers a new
32
+ * function per `scoped(…)`); its trace and report are the service's, never this hook's.
33
+ */
34
+ export function useServiceReading(useCase, args, options = {}) {
35
+ const { context, changes, entities } = useFramework();
36
+ const key = JSON.stringify(args);
37
+ const latest = useRef({ useCase, args });
38
+ latest.current = { useCase, args };
39
+ const [answered, setAnswered] = useState(null);
40
+ const [again, setAgain] = useState(0);
41
+ // A write anyone sends — a save, another use case, a panel beside — to what it follows.
42
+ const followed = (options.follows ?? [])
43
+ .map(routeOf)
44
+ .filter((route) => route !== undefined)
45
+ .join("\n");
46
+ useEffect(() => {
47
+ if (followed === "")
48
+ return;
49
+ const routes = followed.split("\n");
50
+ return changes.follow((change) => {
51
+ if (routes.some((route) => touches(change, route, entities)))
52
+ setAgain((n) => n + 1);
53
+ });
54
+ }, [changes, entities, followed]);
55
+ useEffect(() => {
56
+ let current = true;
57
+ const { useCase: read, args: now } = latest.current;
58
+ // Through the promise: a use case that throws before it answers is a failure like any other.
59
+ Promise.resolve()
60
+ .then(() => read(...now))
61
+ .then((answer) => {
62
+ if (current)
63
+ setAnswered({ key, status: "ready", answer: answer, error: null });
64
+ }, (error) => {
65
+ if (current)
66
+ setAnswered({ key, status: "failed", answer: undefined, error });
67
+ });
68
+ return () => void (current = false);
69
+ // `context` and `again` read again: another company, a followed write, a `reload()`.
70
+ }, [key, context, again]);
71
+ const reload = useCallback(() => setAgain((n) => n + 1), []);
72
+ if (answered === null || answered.key !== key)
73
+ return { status: "loading", answer: undefined, error: null, reload };
74
+ return { status: answered.status, answer: answered.answer, error: answered.error, reload };
75
+ }
@@ -0,0 +1,16 @@
1
+ /** What a value a screen holds reads as — each `null` when there is nothing to read. */
2
+ export type ValueTexts = {
3
+ number: (value: unknown) => string | null;
4
+ day: (value: unknown) => string | null;
5
+ instant: (value: unknown) => string | null;
6
+ money: (value: unknown) => string | null;
7
+ };
8
+ /**
9
+ * The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `moneyTextOf`, in the
10
+ * provider's locale and on the zone it installed — for what a screen of its own holds outside a
11
+ * model: a total it added up, a balance a use case answered.
12
+ *
13
+ * const text = useTextOf();
14
+ * <Stat label="Saldo" value={text.money(balance) ?? "—"} />
15
+ */
16
+ export declare function useTextOf(): ValueTexts;
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { dayTextOf, instantTextOf, moneyTextOf, numberTextOf, } from "../core/present.js";
3
+ import { useFramework } from "./context.js";
4
+ import { useMemo } from "react";
5
+ /**
6
+ * The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `moneyTextOf`, in the
7
+ * provider's locale and on the zone it installed — for what a screen of its own holds outside a
8
+ * model: a total it added up, a balance a use case answered.
9
+ *
10
+ * const text = useTextOf();
11
+ * <Stat label="Saldo" value={text.money(balance) ?? "—"} />
12
+ */
13
+ export function useTextOf() {
14
+ const { locale } = useFramework();
15
+ return useMemo(() => ({
16
+ number: (value) => numberTextOf(value, locale),
17
+ day: (value) => dayTextOf(value, locale),
18
+ instant: (value) => instantTextOf(value, locale),
19
+ money: (value) => moneyTextOf(value, locale),
20
+ }), [locale]);
21
+ }
@@ -89,6 +89,9 @@ export type EntityListProps<T extends AnyRecord, C extends CommandBodies = Comma
89
89
  sums?: readonly string[] | false;
90
90
  /** The cuts this list offers by name: «sólo pagadas», «vencidas». */
91
91
  filters?: readonly NamedFilter<T>[];
92
+ /** The fields «Group by» offers, in this order — among those the model lets split the set.
93
+ * Without it, the list definition's, else every one the model does. */
94
+ groupable?: readonly string[];
92
95
  /**
93
96
  * Rows can be ticked. With `api`, what is ticked is PUBLISHED to the workspace
94
97
  * (`api.select`): a panel beside it follows the selection without knowing this list.
@@ -129,4 +132,4 @@ export type EntityFace<T> = {
129
132
  render: (set: ListSet<T>) => ReactNode;
130
133
  };
131
134
  export type View = "table" | "rows" | "board" | "sheet" | "pivot";
132
- export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
135
+ export declare function EntityList<T extends AnyRecord, C extends CommandBodies = CommandBodies>({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search, sums, filters: askedFilters, groupable: askedGroupable, selectable, selectionActions, embedded, create, commands, rowActions: askedRowActions, faces, }: EntityListProps<T, C>): import("react").JSX.Element;
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { PICK_PARAM, QUERY_PARAM, TRAIL_PARAM, } from "@sincpro/client-framework";
4
4
  import { nameOf } from "@sincpro/criteria";
5
- import { RecordLink, useCrumbs } from "@sincpro/web-composer";
5
+ import { RecordLink, useCrumbs, usePhone } from "@sincpro/web-composer";
6
6
  import { frameworkCopy } from "../../core/copy.js";
7
7
  import { explain } from "../../core/explain.js";
8
8
  import { textOf, viewOf } from "../../core/present.js";
@@ -23,6 +23,7 @@ const NO_TRAIL = [];
23
23
  const NO_WORKSPACE = {
24
24
  crumbs: () => NO_TRAIL,
25
25
  context: { subscribe: () => () => undefined },
26
+ layout: { phone: () => false, subscribe: () => () => undefined },
26
27
  };
27
28
  /** How many lists' trails are kept: the records opened from the last fifty lists page on. */
28
29
  const TRAILS = 50;
@@ -30,7 +31,7 @@ const TRAILS = 50;
30
31
  const NO_COMMANDS = [];
31
32
  /** What a list offers when nobody said: every face that needs no configuration. */
32
33
  const EVERY_VIEW = ["table", "rows", "board", "sheet"];
33
- export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
34
+ export function EntityList({ listing, api, columns: askedColumns, cells, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, groupable: askedGroupable, selectable = false, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
34
35
  // A named list (`defineList`) brings its own columns, filters, faces and words; what the
35
36
  // screen passes wins.
36
37
  const definition = listing.definition;
@@ -39,6 +40,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
39
40
  definition?.views ??
40
41
  (embedded ? ["table"] : pivotAsked === undefined ? EVERY_VIEW : [...EVERY_VIEW, "pivot"]);
41
42
  const filters = askedFilters ?? definition?.filters ?? [];
43
+ const groupable = askedGroupable ?? definition?.groupable;
42
44
  const title = askedTitle ?? definition?.title;
43
45
  const description = askedDescription ?? definition?.description;
44
46
  const copy = frameworkCopy().list;
@@ -148,6 +150,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
148
150
  // `useCrumbs`, not `api.crumbs()`: the crumb must follow a name given later (`setTitle`).
149
151
  // Without a workspace it reads a trail that never changes — a hook cannot be skipped.
150
152
  const following = useCrumbs(api ?? NO_WORKSPACE);
153
+ usePhone(api ?? NO_WORKSPACE); // where a row opens follows the mode (`targetsFor`)
151
154
  const trail = crumbs ?? (embedded || api === undefined ? undefined : following);
152
155
  const [ticked, setTicked] = useState(() => new Set());
153
156
  const tick = (next) => {
@@ -315,7 +318,7 @@ export function EntityList({ listing, api, columns: askedColumns, cells, views:
315
318
  }, filtered: listing.selection !== undefined || listing.text !== "", empty: {
316
319
  sentence: empty ?? copy.empty,
317
320
  whenFiltered: { sentence: copy.emptyFiltered },
318
- }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
321
+ }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(groupable === undefined ? {} : { groupable }), ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
319
322
  setDraft(next);
320
323
  // Emptied (or cleared with ×): the whole set again, at once.
321
324
  if (next === "" && listing.text !== "")
@@ -23,12 +23,15 @@ import type { Listing } from "../../react/useListing.js";
23
23
  * <List.Search><EntitySearchBar listing={listing} filters={…} /></List.Search>
24
24
  */
25
25
  export type { NamedFilter };
26
- export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, seed, }: {
26
+ export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, groupable: only, seed, }: {
27
27
  listing: Listing<T>;
28
28
  /** The cuts this set offers by name: «sólo pagadas», «vencidas». */
29
29
  filters?: readonly NamedFilter<T>[];
30
30
  /** The grouping of the same set (`useGroups(listing)`): offers «Group by». */
31
31
  groups?: Groups<T>;
32
+ /** The fields «Group by» offers, in this order — among those the model lets split the set.
33
+ * Without it, every one it does. */
34
+ groupable?: readonly string[];
32
35
  /** A text to start on, put as the literal search chip — what was typed in a picker whose
33
36
  * «Buscar más…» opened this list. */
34
37
  seed?: string;
@@ -8,14 +8,14 @@ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, Grou
8
8
  import { useEffect, useMemo, useRef, useState } from "react";
9
9
  /** No grouping: one constant, so the control is not handed a new array on every render. */
10
10
  const NO_LEVELS = [];
11
- export function EntitySearchBar({ listing, filters = [], groups, seed, }) {
11
+ export function EntitySearchBar({ listing, filters = [], groups, groupable: only, seed, }) {
12
12
  const copy = frameworkCopy().list;
13
13
  const { meta, locale } = listing;
14
14
  const [put, setPut] = useState([]);
15
15
  const [building, setBuilding] = useState(false);
16
16
  const model = useMemo(() => (meta ? modelOf(meta, locale) : undefined), [meta, locale]);
17
17
  const facets = useMemo(() => (meta ? facetsOf(meta, locale) : []), [meta, locale]);
18
- const groupable = useMemo(() => groupableOf(meta, locale), [meta, locale]);
18
+ const groupable = useMemo(() => groupableOf(meta, locale, only), [meta, locale, only]);
19
19
  const ui = useUiCopy();
20
20
  const seeded = useRef(false);
21
21
  useEffect(() => {
@@ -1,9 +1,19 @@
1
1
  import { type AnyRecord, type Bucket, type Meta } from "@sincpro/criteria";
2
2
  import type { GroupLevel } from "../../react/useGroups.js";
3
3
  import { type GroupableField, type Pile } from "@sincpro/web-ui";
4
- /** The fields the model says may split a set (`groupable`), in its words. The identity splits
5
- * into groups of one, and the version means nothing to a person: neither is offered. */
6
- export declare function groupableOf(meta: Meta | null, locale?: string): GroupableField[];
4
+ /**
5
+ * The fields the model says may split a set (`groupable`), in its words. The identity splits
6
+ * into groups of one, and the version means nothing to a person: neither is offered. With
7
+ * `only`, the screen's own choice among them, in its order — a name the model does not let
8
+ * split the set is still not offered.
9
+ *
10
+ * Context: sincpro_framework marks a field groupable by its TYPE, so a context's log offered
11
+ * «group by» `correlation_id` and `causation_id`. Which of them mean something to a person is
12
+ * the model's to say (ROADMAP); until it does, and wherever a screen knows better, the screen
13
+ * names them (`EntityList groupable`, `defineList({ groupable })`). Never a list of technical
14
+ * names kept here.
15
+ */
16
+ export declare function groupableOf(meta: Meta | null, locale?: string, only?: readonly string[]): GroupableField[];
7
17
  /**
8
18
  * The server's groups as piles, with the words a person reads, and each pile's group so that
9
19
  * opening one reads its rows. Rows sit only on the deepest level, once read.
@@ -13,16 +13,29 @@ import { dateLabel, pathKey, } from "@sincpro/web-ui";
13
13
  */
14
14
  /** The cuts a date offers, coarse to fine — web-ui orders the levels by them. */
15
15
  const DATE_GRAINS = ["year", "quarter", "month", "week", "day"];
16
- /** The fields the model says may split a set (`groupable`), in its words. The identity splits
17
- * into groups of one, and the version means nothing to a person: neither is offered. */
18
- export function groupableOf(meta, locale) {
16
+ /**
17
+ * The fields the model says may split a set (`groupable`), in its words. The identity splits
18
+ * into groups of one, and the version means nothing to a person: neither is offered. With
19
+ * `only`, the screen's own choice among them, in its order — a name the model does not let
20
+ * split the set is still not offered.
21
+ *
22
+ * Context: sincpro_framework marks a field groupable by its TYPE, so a context's log offered
23
+ * «group by» `correlation_id` and `causation_id`. Which of them mean something to a person is
24
+ * the model's to say (ROADMAP); until it does, and wherever a screen knows better, the screen
25
+ * names them (`EntityList groupable`, `defineList({ groupable })`). Never a list of technical
26
+ * names kept here.
27
+ */
28
+ export function groupableOf(meta, locale, only) {
19
29
  if (meta === null)
20
30
  return [];
21
- return Object.entries(meta.fields)
22
- .filter(([name, field]) => field.groupable === true &&
23
- field.kind === "scalar" &&
24
- name !== meta.identity &&
25
- name !== "version")
31
+ const names = only ?? Object.keys(meta.fields);
32
+ return names
33
+ .map((name) => [name, meta.fields[name]])
34
+ .filter((entry) => entry[1] !== undefined &&
35
+ entry[1].groupable === true &&
36
+ entry[1].kind === "scalar" &&
37
+ entry[0] !== meta.identity &&
38
+ entry[0] !== "version")
26
39
  .map(([name, field]) => ({
27
40
  field: name,
28
41
  label: labelOf(meta, name, locale),
@@ -12,7 +12,9 @@ import { type OpenTarget } from "@sincpro/web-ui";
12
12
  *
13
13
  * The places allowed depend on where the list is: from inside a modal, no modal (a second one
14
14
  * would replace the first and lose what was typed in it) — composer says where a view is
15
- * (`api.over`).
15
+ * (`api.over`). On a phone a side panel and a window both open as the page (composer 1.7,
16
+ * `api.layout`), so neither is offered: three entries that do the same are a lie. A screen that
17
+ * draws the menu follows the mode (`usePhone(api)`) so it redraws when it changes.
16
18
  */
17
19
  /** A record's form fits; a short task (register a payment) passes its own size. */
18
20
  export declare const RECORD_SIZE: {
@@ -20,7 +22,7 @@ export declare const RECORD_SIZE: {
20
22
  readonly h: 560;
21
23
  };
22
24
  /** Where a record may open from this view, the default first. */
23
- export declare function targetsFor(api: Pick<WorkspaceApi, "over">): readonly OpenTarget[];
25
+ export declare function targetsFor(api: Pick<WorkspaceApi, "over"> & Partial<Pick<WorkspaceApi, "layout">>): readonly OpenTarget[];
24
26
  /** web-ui's target as composer's options. Destinations share their names, so only the size is
25
27
  * added — to the two that have one. */
26
28
  export declare function openOptions(to: OpenTarget, size?: {
@@ -14,15 +14,22 @@ import { AppWindow, Eye, FileText, PanelRight, SquareArrowOutUpRight, SquareStac
14
14
  *
15
15
  * The places allowed depend on where the list is: from inside a modal, no modal (a second one
16
16
  * would replace the first and lose what was typed in it) — composer says where a view is
17
- * (`api.over`).
17
+ * (`api.over`). On a phone a side panel and a window both open as the page (composer 1.7,
18
+ * `api.layout`), so neither is offered: three entries that do the same are a lie. A screen that
19
+ * draws the menu follows the mode (`usePhone(api)`) so it redraws when it changes.
18
20
  */
19
21
  /** A record's form fits; a short task (register a payment) passes its own size. */
20
22
  export const RECORD_SIZE = { w: 760, h: 560 };
21
23
  const EVERYWHERE = ["modal", "peek", "side", "page", "window"];
22
24
  const FROM_A_MODAL = ["side", "peek", "page", "window"];
25
+ const ON_A_PHONE = ["modal", "peek", "page"];
26
+ const ON_A_PHONE_FROM_A_MODAL = ["peek", "page"];
23
27
  /** Where a record may open from this view, the default first. */
24
28
  export function targetsFor(api) {
25
- return api.over === null ? EVERYWHERE : FROM_A_MODAL;
29
+ const phone = api.layout?.phone() === true;
30
+ if (api.over === null)
31
+ return phone ? ON_A_PHONE : EVERYWHERE;
32
+ return phone ? ON_A_PHONE_FROM_A_MODAL : FROM_A_MODAL;
26
33
  }
27
34
  /** web-ui's target as composer's options. Destinations share their names, so only the size is
28
35
  * added — to the two that have one. */
@@ -14,15 +14,21 @@ export type FieldControl = {
14
14
  };
15
15
  /**
16
16
  * The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
17
- * list of words,
18
- * a text.
17
+ * list of words, a text — or the one its `widget` names when the model names one of the
18
+ * framework's own: `textarea`, several lines of prose.
19
19
  * Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
20
20
  * one rule for what a value is edited with.
21
+ *
22
+ * Context: sincpro_framework publishes each field's widget — its type's, or the one
23
+ * `presentation(widgets=…)` names — and a screen that ignored it drew a one-line input for a
24
+ * note, so every application passed `as` for each long text. Only the framework's own names are
25
+ * read here: a name an application registers is drawn with `as`, never looked up in a registry
26
+ * of strings.
21
27
  */
22
28
  export declare function controlFor(control: FieldControl, type: string, exact: boolean, choices: {
23
29
  value: unknown;
24
30
  label: string;
25
- }[]): ReactNode;
31
+ }[], widget?: string): ReactNode;
26
32
  /**
27
33
  * A many2one's control: the picker of the entity it points at — the server's literal search,
28
34
  * the first ten, «Buscar más…» — opening the chosen one where the view says.
@@ -2,15 +2,21 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { dayOf, instantOf, timeZoneNow, wallTimeOf, } from "@sincpro/client-framework";
4
4
  import { EntityPicker } from "./EntityPicker.js";
5
- import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextInput, } from "@sincpro/web-ui";
5
+ import { Checkbox, DatePicker, DateTimePicker, NumberInput, Select, TagsField, TextArea, TextInput, } from "@sincpro/web-ui";
6
6
  /**
7
7
  * The control a field's TYPE asks for — a choice, a number, a date, a date and time, a yes/no, a
8
- * list of words,
9
- * a text.
8
+ * list of words, a text — or the one its `widget` names when the model names one of the
9
+ * framework's own: `textarea`, several lines of prose.
10
10
  * Shared by a record's field (`RecordField`) and a line's cell and dialog (`RecordLinesEditor`):
11
11
  * one rule for what a value is edited with.
12
+ *
13
+ * Context: sincpro_framework publishes each field's widget — its type's, or the one
14
+ * `presentation(widgets=…)` names — and a screen that ignored it drew a one-line input for a
15
+ * note, so every application passed `as` for each long text. Only the framework's own names are
16
+ * read here: a name an application registers is drawn with `as`, never looked up in a registry
17
+ * of strings.
12
18
  */
13
- export function controlFor(control, type, exact, choices) {
19
+ export function controlFor(control, type, exact, choices, widget) {
14
20
  const { value, set } = control;
15
21
  const named = control.standalone === true ? { "aria-label": control.label } : {};
16
22
  if (choices.length > 0)
@@ -39,6 +45,9 @@ export function controlFor(control, type, exact, choices) {
39
45
  return (_jsx(TagsField, { value: words, options: words.map((word) => ({ value: word, label: word })), onChange: set, onCreate: (word) => word, ...named }));
40
46
  }
41
47
  default:
48
+ // Not in a cell: a row of a table is one line high, and the dialog has the room.
49
+ if (widget === "textarea" && control.standalone !== true)
50
+ return (_jsx(TextArea, { value: value === null || value === undefined ? "" : String(value), onChange: set }));
42
51
  return (_jsx(TextInput, { value: value === null || value === undefined ? "" : String(value), onChange: set, ...named }));
43
52
  }
44
53
  }
@@ -143,7 +143,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
143
143
  }
144
144
  if (view.type === "boolean" && as === undefined)
145
145
  return (_jsx(Checkbox, { checked: value === true, onChange: control.set, label: view.label, disabled: state.readonly }));
146
- return (_jsx(Field, { label: view.label, required: 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, choicesOf(meta, name, locale))) }));
146
+ return (_jsx(Field, { label: view.label, required: 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, choicesOf(meta, name, locale), field?.widget)) }));
147
147
  }
148
148
  /**
149
149
  * The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
@@ -64,7 +64,7 @@ function LineValue({ definition, field, line, set, label, invalid, locale, inCel
64
64
  invalid,
65
65
  label,
66
66
  standalone: inCell,
67
- }, viewOf(definition, field, locale).type, definition?.fields[field]?.exact === true, choicesOf(definition, field, locale));
67
+ }, viewOf(definition, field, locale).type, definition?.fields[field]?.exact === true, choicesOf(definition, field, locale), definition?.fields[field]?.widget);
68
68
  }
69
69
  /**
70
70
  * The lines of an aggregate, edited inside its record: web-ui's `LineItems` over the record's
@@ -1,11 +1,15 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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
5
  import { textOf, viewOf } from "../../core/present.js";
6
6
  import { relatedOf } from "../../core/related.js";
7
+ import { relationFieldOf } from "../../core/relation.js";
8
+ import { useEntityFor } from "../../react/context.js";
9
+ import { useNameOf } from "../../react/useNameOf.js";
7
10
  import { columnsOf } from "../list/columns.js";
8
- import { List } from "@sincpro/web-ui";
11
+ import { useRecordOpening } from "./opening.js";
12
+ import { List, RelationValue, } from "@sincpro/web-ui";
9
13
  /**
10
14
  * The parts of ONE record, from the model.
11
15
  *
@@ -28,14 +32,43 @@ export function factsOf(record, meta, names, options = {}) {
28
32
  return names.map((name) => {
29
33
  const view = viewOf(meta, name, options.locale);
30
34
  const own = options.cells?.[name];
35
+ const relation = relationFieldOf(meta, name);
31
36
  return {
32
37
  label: view.label,
33
- value: own ? own(record) : (textOf(meta, name, record[name], options.locale) ?? EMPTY),
38
+ value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : ((textOf(meta, name, record[name], options.locale) ?? EMPTY)),
34
39
  ...(view.help === undefined ? {} : { hint: view.help }),
35
40
  ...(name === meta?.identity ? { mono: true } : {}),
36
41
  };
37
42
  });
38
43
  }
44
+ /**
45
+ * A many2one read as a fact: the name of the record it points at, as a link that opens it where
46
+ * the view says (`RecordOpening`: the workspace's places, «Abrir en…») — when the application
47
+ * declared its entity. A key alone (`EntityID[Tenant]`) is named by key (`useNameOf`). Of an
48
+ * entity nobody declared, it is the text it always was.
49
+ *
50
+ * Context: a fact a person read as «Globex Bolivia» led nowhere, so an application wrote its own
51
+ * link for «this payment's member», or misused a smart button for it. A component inside the
52
+ * fact's VALUE is fine: what web-ui finds by type are the slots, never their content.
53
+ */
54
+ function RelationFact({ record, meta, name, relation, locale, }) {
55
+ const target = useEntityFor(relation.target);
56
+ const opening = useRecordOpening();
57
+ const raw = record[relation.key];
58
+ const key = raw === null || raw === undefined ? "" : String(raw);
59
+ const asked = useNameOf(relation.held ? undefined : target, key);
60
+ if (target === undefined || key === "")
61
+ return _jsx(_Fragment, { children: textOf(meta, name, record[name], locale) ?? EMPTY });
62
+ const held = relation.held
63
+ ? textOf(meta, relation.relation, record[relation.relation], locale)
64
+ : null;
65
+ return (_jsx(RelationValue, { name: held ?? asked ?? key, ...(opening === null
66
+ ? {}
67
+ : {
68
+ onOpenIn: (to) => opening.open(target.ref(key), to),
69
+ openTargets: opening.targets,
70
+ }) }));
71
+ }
39
72
  /** How many records a relation of this record holds — the TOTAL, not the page it brought. */
40
73
  export function countOf(record, name) {
41
74
  return relatedOf(record[name]).count.value;
@@ -1,7 +1,7 @@
1
1
  import { type Entity, type Transport } from "@sincpro/client-framework";
2
2
  import { type AnyRecord, type Meta } from "@sincpro/criteria";
3
- import type { ViewProps, ViewSpec } from "@sincpro/web-composer";
4
- import type { ListDefinition } from "../../core/list.js";
3
+ import { type ViewProps, type ViewSpec } from "@sincpro/web-composer";
4
+ import { type ListDefinition } from "../../core/list.js";
5
5
  import { type ComponentType } from "react";
6
6
  /**
7
7
  * An entity as the composer's view: one `ViewSpec` for its list (a reference without an id)
@@ -44,6 +44,10 @@ export type EntityViewOptions = {
44
44
  goto?: boolean;
45
45
  /** Known before any search: no request asks for it. */
46
46
  meta?: Meta;
47
+ /** A record's name, the screen's way — for a model with no display field (a singleton reads
48
+ * as its key). Used by the default record; a record of its own passes it to
49
+ * `useRecordInWorkspace` / `useRecordScreen`. */
50
+ title?: (record: AnyRecord) => string | null;
47
51
  actions?: ViewSpec["actions"];
48
52
  /** ⌘K's question: the list route's params that say which records it searches. */
49
53
  search?: {
@@ -1,7 +1,9 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { listRoute, NEW_PARAM, scopeOfRef, } from "@sincpro/client-framework";
3
+ import { isEntityId, listRoute, NEW_PARAM, scopeOfRef, } from "@sincpro/client-framework";
4
4
  import { matching } from "@sincpro/criteria";
5
+ import { usePhone, } from "@sincpro/web-composer";
6
+ import { scopeNameOf } from "../../core/list.js";
5
7
  import { lookupOf } from "../../core/lookup.js";
6
8
  import { ListScopeProvider } from "../../react/scope.js";
7
9
  import { useListing } from "../../react/useListing.js";
@@ -17,6 +19,7 @@ import { useMemo } from "react";
17
19
  * a one2many's «Agregar» as the new record's form that answers once it exists.
18
20
  */
19
21
  function InWorkspace({ api, children }) {
22
+ usePhone(api); // the places follow the mode: on a phone, no side panel and no window
20
23
  const targets = targetsFor(api);
21
24
  const opening = useMemo(() => {
22
25
  // Never a modal over a modal: from inside one, what answers docks beside it.
@@ -33,29 +36,45 @@ function InWorkspace({ api, children }) {
33
36
  }, [api, targets]);
34
37
  return _jsx(RecordOpeningProvider, { value: opening, children: children });
35
38
  }
36
- /** The entity's list when the application writes none. */
37
- function listOf(entity) {
38
- return function DefaultList({ api }) {
39
- return _jsx(EntityList, { listing: useListing(entity), api: api });
39
+ /** The entity's list when the application writes none: opened under a named cut, it says
40
+ * whose it is («Facturas · Globex Bolivia»). */
41
+ function listOf(entity, name) {
42
+ return function DefaultList({ api, resource }) {
43
+ const of = scopeNameOf(resource);
44
+ return (_jsx(EntityList, { listing: useListing(entity), api: api, ...(of === undefined ? {} : { title: `${name} · ${of}` }) }));
40
45
  };
41
46
  }
42
47
  /** The entity's record when the application writes none. */
43
- function recordOf(entity) {
48
+ function recordOf(entity, title) {
44
49
  return function DefaultRecord(props) {
45
- return _jsx(EntityRecord, { ...props, entity: entity });
50
+ return (_jsx(EntityRecord, { ...props, entity: entity, ...(title === undefined ? {} : { title }) }));
46
51
  };
47
52
  }
53
+ /**
54
+ * What a reference reads as before its view names it — a crumb whose view is not mounted, a
55
+ * record still loading: the list is the view's name (with its cut's, `scopedRef`); a record
56
+ * its key when the key is something a person reads (`F-2026-0004`), the view's name when it is
57
+ * a machine's (a UUID v7, `isEntityId`).
58
+ */
59
+ function titleOf(ref, name) {
60
+ if (ref.id === undefined) {
61
+ const of = scopeNameOf(ref);
62
+ return of === undefined ? name : `${name} · ${of}`;
63
+ }
64
+ return isEntityId(ref.id) ? name : ref.id;
65
+ }
48
66
  export function entityView(entity, options) {
49
67
  let meta = options.meta ?? null;
50
68
  const route = listRoute(entity.list, options.search?.params);
51
69
  async function screens() {
52
70
  const loaded = options.load === undefined ? {} : await options.load();
53
- const List = loaded.list ?? options.list ?? listOf(entity);
54
- const One = loaded.record ?? options.record ?? recordOf(entity);
71
+ const List = loaded.list ?? options.list ?? listOf(entity, options.name);
72
+ const One = loaded.record ?? options.record ?? recordOf(entity, options.title);
55
73
  return function EntityView(props) {
56
74
  const record = props.resource.id !== undefined || props.resource.params?.[NEW_PARAM] !== undefined;
57
- // A chooser opened by a picker offers only what the picker may choose: its cut travels in
58
- // the reference, and the list — the application's own too — reads under it.
75
+ // A chooser opened by a picker offers only what the picker may choose, and a list opened
76
+ // under a cut (`scopedRef`) shows only what it cuts: the cut travels in the reference, and
77
+ // the list — the application's own too — reads under it.
59
78
  const cut = record ? undefined : scopeOfRef(props.resource);
60
79
  const list = cut === undefined ? (_jsx(List, { ...props })) : (_jsx(ListScopeProvider, { value: { key: entity.key, selection: cut }, children: _jsx(List, { ...props }) }));
61
80
  return _jsx(InWorkspace, { api: props.api, children: record ? _jsx(One, { ...props }) : list });
@@ -67,7 +86,7 @@ export function entityView(entity, options) {
67
86
  return {
68
87
  domain: entity.domain,
69
88
  kind: entity.kind,
70
- title: (ref) => ref.id ?? options.name,
89
+ title: (ref) => titleOf(ref, options.name),
71
90
  goto: options.goto ?? true,
72
91
  ...(options.icon === undefined ? {} : { icon: options.icon }),
73
92
  ...(options.actions === undefined ? {} : { actions: options.actions }),
@@ -1,6 +1,6 @@
1
1
  import { type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord, Meta } from "@sincpro/criteria";
3
- import type { ResourceRef, WorkspaceApi } from "@sincpro/web-composer";
3
+ import { type ResourceRef, type WorkspaceApi } from "@sincpro/web-composer";
4
4
  import { type OpenTarget } from "@sincpro/web-ui";
5
5
  import type { ReactNode } from "react";
6
6
  /**
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import {} from "@sincpro/client-framework";
4
+ import { usePhone } from "@sincpro/web-composer";
5
+ import { useNameOf } from "../../react/useNameOf.js";
4
6
  import { useSummaryOf } from "../../react/useSummary.js";
5
7
  import { openOptions, targetsFor } from "../list/openIn.js";
6
8
  import { relationOf } from "../record/summary.js";
@@ -44,9 +46,13 @@ export function openIn(api, ref, to, size) {
44
46
  */
45
47
  export function RelatedRecord({ api, entity, value, meta, editor, }) {
46
48
  const summarize = useSummaryOf(entity);
49
+ usePhone(api); // «Abrir en…» follows the mode: on a phone, no side panel and no window
50
+ // A key alone (`payment_id`, an `EntityID`) is read by its name, asked once by key — the key
51
+ // until it answers, and when nothing does. It used to stay the key: «P-0192…» for a payment.
52
+ const named = useNameOf(entity, typeof value === "string" ? value : "");
47
53
  const extra = editor === undefined ? {} : { editor };
48
54
  if (value === null || value === undefined || value === "")
49
55
  return _jsx(RelationValue, { name: null, ...extra });
50
56
  const summary = summarize(typeof value === "string" ? { id: value } : value, meta);
51
- return (_jsx(RelationValue, { ...relationOf(summary), onOpenIn: (to) => openIn(api, entity.ref(summary.id), to), openTargets: targetsFor(api), ...extra }));
57
+ return (_jsx(RelationValue, { ...relationOf(named === undefined ? summary : { ...summary, name: named }), onOpenIn: (to) => openIn(api, entity.ref(summary.id), to), openTargets: targetsFor(api), ...extra }));
52
58
  }