@sincpro/web-framework 3.18.0 → 3.20.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 (68) hide show
  1. package/README.md +83 -54
  2. package/dist/core/copy.d.ts +14 -0
  3. package/dist/core/copy.js +57 -2
  4. package/dist/core/edit.d.ts +13 -0
  5. package/dist/core/edit.js +14 -0
  6. package/dist/core/explain.d.ts +4 -0
  7. package/dist/core/explain.js +4 -0
  8. package/dist/core/export.d.ts +29 -0
  9. package/dist/core/export.js +47 -0
  10. package/dist/core/groups.d.ts +3 -1
  11. package/dist/core/groups.js +7 -0
  12. package/dist/core/index.d.ts +4 -3
  13. package/dist/core/index.js +4 -3
  14. package/dist/core/lines.d.ts +10 -0
  15. package/dist/core/lines.js +24 -0
  16. package/dist/core/list.d.ts +12 -0
  17. package/dist/react/context.d.ts +44 -1
  18. package/dist/react/context.js +50 -1
  19. package/dist/react/index.d.ts +4 -2
  20. package/dist/react/index.js +4 -2
  21. package/dist/react/useCounts.d.ts +23 -0
  22. package/dist/react/useCounts.js +43 -0
  23. package/dist/react/useGroups.js +38 -5
  24. package/dist/react/useNameOf.d.ts +13 -0
  25. package/dist/react/useNameOf.js +32 -0
  26. package/dist/react/usePeopleOf.d.ts +14 -0
  27. package/dist/react/usePeopleOf.js +35 -0
  28. package/dist/react/useRecord.js +2 -2
  29. package/dist/react/useServiceReading.d.ts +8 -0
  30. package/dist/react/useServiceReading.js +12 -2
  31. package/dist/web/index.d.ts +4 -2
  32. package/dist/web/index.js +4 -2
  33. package/dist/web/list/EntityList.d.ts +36 -177
  34. package/dist/web/list/EntityList.js +175 -536
  35. package/dist/web/list/entityList/choosing.d.ts +50 -0
  36. package/dist/web/list/entityList/choosing.js +77 -0
  37. package/dist/web/list/entityList/faces.d.ts +53 -0
  38. package/dist/web/list/entityList/faces.js +155 -0
  39. package/dist/web/list/entityList/grouping.d.ts +50 -0
  40. package/dist/web/list/entityList/grouping.js +97 -0
  41. package/dist/web/list/entityList/opening.d.ts +68 -0
  42. package/dist/web/list/entityList/opening.js +149 -0
  43. package/dist/web/list/entityList/paging.d.ts +30 -0
  44. package/dist/web/list/entityList/paging.js +39 -0
  45. package/dist/web/list/entityList/props.d.ts +174 -0
  46. package/dist/web/list/entityList/props.js +16 -0
  47. package/dist/web/list/entityList/rowActions.d.ts +31 -0
  48. package/dist/web/list/entityList/rowActions.js +40 -0
  49. package/dist/web/list/export.d.ts +13 -0
  50. package/dist/web/list/export.js +61 -0
  51. package/dist/web/list/groups.d.ts +16 -0
  52. package/dist/web/list/groups.js +39 -0
  53. package/dist/web/list/useEntityList.d.ts +183 -0
  54. package/dist/web/list/useEntityList.js +225 -0
  55. package/dist/web/parts.d.ts +42 -0
  56. package/dist/web/parts.js +88 -0
  57. package/dist/web/record/lines.d.ts +3 -0
  58. package/dist/web/record/lines.js +75 -9
  59. package/dist/web/workspace/RecordScreen.d.ts +206 -0
  60. package/dist/web/workspace/RecordScreen.js +251 -0
  61. package/dist/web/workspace/SincproApp.d.ts +14 -2
  62. package/dist/web/workspace/SincproApp.js +27 -9
  63. package/dist/web/workspace/composer.js +1 -1
  64. package/dist/web/workspace/record.d.ts +21 -27
  65. package/dist/web/workspace/record.js +29 -77
  66. package/dist/web/workspace/workspace.d.ts +2 -0
  67. package/dist/web/workspace/workspace.js +1 -1
  68. package/package.json +7 -7
@@ -4,11 +4,11 @@ import { processChanges, processContext, reportError, } from "@sincpro/client-fr
4
4
  import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
5
5
  import { createRegistry, formatRef, PHONE_WIDTH } from "@sincpro/web-composer/domain";
6
6
  import { cachedTransport, } from "../../core/cache.js";
7
- import { installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "../../core/copy.js";
8
- import { FrameworkProvider } from "../../react/context.js";
7
+ import { installFrameworkCopy, SPANISH_FRAMEWORK_COPY, SPANISH_FRAMEWORK_COPY_TU, } from "../../core/copy.js";
8
+ import { FrameworkProvider, ModelDefinitions, useFrameworkIfAny, } from "../../react/context.js";
9
9
  import { useSearchRecords } from "../list/records.js";
10
10
  import { webUiSkin } from "./skin.js";
11
- import { installCopy, SearchProvider, SPANISH_COPY, ToastProvider, useSearchSettings, } from "@sincpro/web-ui";
11
+ import { installCopy, SearchProvider, SPANISH_COPY, SPANISH_COPY_TU, ToastProvider, useSearchSettings, } from "@sincpro/web-ui";
12
12
  import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
13
13
  /**
14
14
  * The application context in one place: who answers (the transport), in which language, which
@@ -25,6 +25,17 @@ import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
25
25
  *
26
26
  * const workspace = useWorkspace();
27
27
  * <SincproApp workspace={workspace} bar={<Menu onOpen={(ref) => workspace.push(ref)} />} … />
28
+ *
29
+ * Inside a product with several faces it is ONE of them: without `transport` it joins the
30
+ * `FrameworkProvider` around it — its transport and cache, its context, its zone and currency —
31
+ * and brings only what is its own: its entities, the definitions of their models and their facts
32
+ * (`ModelDefinitions`). The configuration of the provider's (`timeZone`, `currency`, `region`,
33
+ * `dateStyle`, `richText`, `uploads`, `people`, `cache`, `changes`) is then the provider's: said once.
34
+ *
35
+ * <FrameworkProvider transport={transport} timeZone="America/La_Paz" currency="BOB">
36
+ * <Site />
37
+ * <SincproApp views={views} entities={billing.entities} metas={metasOf(billing)} />
38
+ * </FrameworkProvider>
28
39
  */
29
40
  /** Narrower than composer's phone (`PHONE_WIDTH`): the workspace fills the window here, so the
30
41
  * window's width is the workspace's. */
@@ -51,17 +62,20 @@ function FrameworkSearch({ children }) {
51
62
  }
52
63
  /** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
53
64
  const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
54
- export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, region, richText, uploads, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
65
+ export function SincproApp({ transport, views, start, language = "es", voice = "vos", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, region, richText, uploads, people, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
55
66
  // Installed once, before anything draws: the three tables are module state of their packages.
56
67
  useState(() => {
57
68
  if (language === "es") {
58
- installCopy(SPANISH_COPY);
69
+ installCopy(voice === "tú" ? SPANISH_COPY_TU : SPANISH_COPY);
59
70
  installComposerCopy(SPANISH_COMPOSER_COPY);
60
- installFrameworkCopy(SPANISH_FRAMEWORK_COPY);
71
+ installFrameworkCopy(voice === "tú" ? SPANISH_FRAMEWORK_COPY_TU : SPANISH_FRAMEWORK_COPY);
61
72
  }
62
73
  return null;
63
74
  });
64
- const cached = useMemo(() => cache === false
75
+ const around = useFrameworkIfAny();
76
+ if (transport === undefined && around === null)
77
+ throw new Error("SincproApp needs a transport, or a FrameworkProvider around it.");
78
+ const cached = useMemo(() => transport === undefined || cache === false
65
79
  ? transport
66
80
  : cachedTransport(transport, {
67
81
  ...(entities === undefined ? {} : { entities }),
@@ -74,7 +88,7 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
74
88
  // read: a change of context forgets every answer, a write what it touched — whoever wrote it, a
75
89
  // use case's client as much as a screen — before the screens read again.
76
90
  useEffect(() => {
77
- if (cache === false)
91
+ if (cached === undefined || cache === false)
78
92
  return;
79
93
  const forgetting = cached;
80
94
  const unwatch = processContext.watch(() => forgetting.invalidate());
@@ -96,5 +110,9 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
96
110
  // The first screen only: a re-render must not push it again.
97
111
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
112
  }, [workspace]);
99
- return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), dateStyle: dateStyle ?? (phone ? "literal" : "numeric"), ...(currency === undefined ? {} : { currency }), ...(region === undefined ? {} : { region }), ...(richText === undefined ? {} : { richText }), ...(uploads === undefined ? {} : { uploads }), ...(events === undefined ? {} : { events }), children: _jsx(FrameworkSearch, { children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }) }));
113
+ const shell = (_jsx(FrameworkSearch, { children: _jsx(ToastProvider, { children: _jsxs("div", { className: "flex h-dvh min-h-0 flex-col bg-ground", children: [bar, _jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: _jsx(Composer, { workspace: workspace, registry: registry, skin: skin, onViewError: onViewError, ...(empty === undefined ? {} : { empty }) }) })] }) }) }));
114
+ // One face of a product: the provider around it is the app's, and this brings only its own.
115
+ if (cached === undefined)
116
+ return (_jsx(ModelDefinitions, { ...(entities === undefined ? {} : { entities }), ...(metas === undefined ? {} : { metas }), ...(events === undefined ? {} : { events }), ...(people === undefined ? {} : { people }), children: shell }));
117
+ return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), dateStyle: dateStyle ?? (phone ? "literal" : "numeric"), ...(currency === undefined ? {} : { currency }), ...(region === undefined ? {} : { region }), ...(richText === undefined ? {} : { richText }), ...(uploads === undefined ? {} : { uploads }), ...(people === undefined ? {} : { people }), ...(events === undefined ? {} : { events }), children: shell }));
100
118
  }
@@ -11,7 +11,7 @@ import { EntityList } from "../list/EntityList.js";
11
11
  import { findChoices, recordsBrowser, RecordsBrowserProvider, refusalNotice, useSearchRecords, } from "../list/records.js";
12
12
  import { RecordOpeningProvider, } from "../record/opening.js";
13
13
  import { openIn, RECORD_SIZE, targetsFor } from "./open.js";
14
- import { EntityRecord } from "./record.js";
14
+ import { EntityRecord } from "./RecordScreen.js";
15
15
  import { useToastIfAny } from "@sincpro/web-ui";
16
16
  import { useMemo } from "react";
17
17
  /**
@@ -2,13 +2,17 @@ import { type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type ViewProps } from "@sincpro/web-composer";
4
4
  import type { RecordRead } from "../../core/server.js";
5
- import { type RecordReading } from "../../react/useRecord.js";
6
- import { type ScreenActions } from "../list/dock.js";
5
+ import type { DockMoment } from "@sincpro/web-ui";
7
6
  /** Who made a record, or changed it last, and when: `Record.Audit`'s. */
8
7
  export type Stamp = {
9
8
  at: string;
10
9
  by?: string;
11
10
  };
11
+ /** A record's tag in its heading: its word, and the tone that says how it is going. */
12
+ export type RecordTag = {
13
+ label: string;
14
+ tone?: "neutral" | "good" | "warn" | "bad" | "info" | "accent";
15
+ };
12
16
  /**
13
17
  * What every record screen in a workspace does before drawing its own — what `EntityRecord`
14
18
  * does, as values: read the record for editing, follow the workspace's breadcrumb, tell the
@@ -40,13 +44,25 @@ export type Stamp = {
40
44
  */
41
45
  export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>, { api, resource }: Pick<ViewProps, "api" | "resource">, options?: {
42
46
  title?: ((record: T) => string | null) | undefined;
47
+ /** The line under its name, the screen's way (an enrollment's course, an order's detail).
48
+ * Without it, or when it answers `null`, the record's type when the model has one. */
49
+ subtitle?: ((record: T) => string | null) | undefined;
50
+ /** Its tag, the screen's way («Publicada», good). Without it, or `null`, the record's state
51
+ * in the tone the entity declared. */
52
+ tag?: ((record: T) => RecordTag | null | undefined) | undefined;
53
+ /** How a new one is named in its heading and its tab: «Nueva noticia». Without it, the
54
+ * model's name and «nuevo». */
55
+ creating?: string | undefined;
56
+ /** The dock's word on the record's moment, the screen's way — one that depends on who looks
57
+ * («Comprobante por revisar» for whoever reviews it). Without it, the entity's (`presented`). */
58
+ moment?: ((record: T) => DockMoment | undefined) | undefined;
43
59
  /** `false`: the screen draws its own history — it is not read here. */
44
60
  history?: boolean | undefined;
45
61
  /** The record and its model already read on the server that renders the screen
46
62
  * (`readRecordOnServer`): it starts from it, filled in the HTML (`useRecord`). */
47
63
  initial?: RecordRead<T> | undefined;
48
64
  }): {
49
- reading: RecordReading<T>;
65
+ reading: import("../../react/useRecord.js").RecordReading<T>;
50
66
  crumbs: readonly import("@sincpro/web-composer").Crumb[];
51
67
  history: import("../../index.js").HistoryEntry[] | undefined;
52
68
  summary: import("../../core/summary.js").RecordSummary | undefined;
@@ -56,16 +72,13 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
56
72
  dirty?: import("@sincpro/web-ui").DirtyState | undefined;
57
73
  placement: "page" | "card";
58
74
  identity: {
59
- tag?: {
60
- tone?: import("@sincpro/web-ui").Tone | undefined;
61
- label: string;
62
- } | undefined;
75
+ tag?: RecordTag | undefined;
63
76
  subtitle?: string | undefined;
64
77
  title: string;
65
78
  };
66
79
  };
67
80
  /** `Record.Dock moment`: the application's word on the record's moment (`presented`). */
68
- moment: import("@sincpro/web-ui").DockMoment | undefined;
81
+ moment: DockMoment | undefined;
69
82
  /** `Record.Pager`'s props, when it was opened from a list and nothing is typed. */
70
83
  pager: {
71
84
  index: number;
@@ -79,22 +92,3 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
79
92
  created?: Stamp | undefined;
80
93
  } | undefined;
81
94
  };
82
- export declare function EntityRecord<T extends AnyRecord>({ api, resource, entity, fields, pages, actions, title, initial, }: ViewProps & {
83
- entity: Entity<T>;
84
- /** The record and its model already read on the server that renders the screen
85
- * (`readRecordOnServer`): drawn filled there, and not asked again in the browser. */
86
- initial?: RecordRead<T> | undefined;
87
- /** Its name, the screen's way — for a record whose model has no display field. */
88
- title?: (record: T) => string | null;
89
- /** The fields, in this order. Without it, the model's (`formOf`). */
90
- fields?: readonly string[];
91
- /** The one2many shown as pages, in this order. Without it, every one the model has. */
92
- pages?: readonly string[];
93
- /**
94
- * The record's own actions, beside «save / discard» and its lifecycle («Eliminar»). As data
95
- * (`DockAction`s) the application's view style draws them with the lifecycle's: the rail's
96
- * buttons in `traditional`, one pill floating at the bottom in `modern` (web-ui's
97
- * `Record.Dock`). A node drawn by hand stays in the rail.
98
- */
99
- actions?: (record: RecordReading<T>) => ScreenActions;
100
- }): import("react").JSX.Element;
@@ -1,41 +1,19 @@
1
1
  "use client";
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
2
  import { TRAIL_PARAM } from "@sincpro/client-framework";
4
- import { labelOf, nameOf } from "@sincpro/criteria";
5
- import { useCrumbs, usePhone } from "@sincpro/web-composer";
3
+ import { nameOf } from "@sincpro/criteria";
4
+ import { useCrumbs } from "@sincpro/web-composer";
6
5
  import { frameworkCopy } from "../../core/copy.js";
7
6
  import { explain } from "../../core/explain.js";
8
- import { formOf } from "../../core/form.js";
9
7
  import { summaryFieldsOf } from "../../core/summary.js";
10
8
  import { placeOf, stepIn } from "../../core/trail.js";
11
9
  import { useFramework } from "../../react/context.js";
12
10
  import { useHistory } from "../../react/useHistory.js";
11
+ import { usePeopleOf } from "../../react/usePeopleOf.js";
13
12
  import { useRecord } from "../../react/useRecord.js";
14
13
  import { useSummaryOf } from "../../react/useSummary.js";
15
- import { actionsOf } from "../list/dock.js";
16
14
  import { presentationOf } from "../list/presentation.js";
17
- import { dirtyOf, RecordField } from "../record/edit.js";
18
- import { LifecycleButtons, useRecordLifecycleActions, } from "../record/RecordLifecycle.js";
19
- import { Refused } from "../Refused.js";
15
+ import { dirtyOf } from "../record/edit.js";
20
16
  import { useRecordInWorkspace } from "./workspace.js";
21
- import { Button, Callout, FormSection, Record, Skeleton, useFormStyle, } from "@sincpro/web-ui";
22
- import { useState } from "react";
23
- /**
24
- * The record of an entity, drawn from its model — the screen `entityView` opens when the
25
- * application writes none: in the page, a modal, the preview or a panel, the same.
26
- *
27
- * Context: every Sincpro record screen was the same hundred lines: read it, tell the workspace
28
- * its name and its unsaved work, draw its name and state on top, its fields, its lines, the
29
- * conflict and the restored draft, who made it, its history. Here once, from what the model and
30
- * the entity already say (`formOf`, `summaryOf`): a new entity has a useful screen before anyone
31
- * writes it. It is a default, not a cage — `fields`/`pages` choose and order, `actions` puts the
32
- * record's commands, and any screen can drop this and keep `useRecord` + `RecordField`.
33
- *
34
- * entityView(invoices, { transport, name: "Facturas" }) // this screen
35
- * entityView(invoices, { …, record: (props) =>
36
- * <EntityRecord {...props} entity={invoices} fields={["customer_id", "due_date"]}
37
- * actions={(invoice) => <CommandButton entity={invoices} command="post" … />} /> })
38
- */
39
17
  /** A save's refusal as a sentence — its heading when the server gave no detail. */
40
18
  function refusalOf(failure) {
41
19
  const said = explain(failure);
@@ -75,7 +53,7 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
75
53
  const crumbs = useCrumbs(api);
76
54
  useRecordInWorkspace(api, reading, options);
77
55
  const look = presentationOf(entity);
78
- const history = useHistory(entity, reading.isNew || options.history === false ? "" : reading.id, [reading.record], { tones: look.facts });
56
+ const read = useHistory(entity, reading.isNew || options.history === false ? "" : reading.id, [reading.record], { tones: look.facts });
79
57
  const summarize = useSummaryOf(entity);
80
58
  const copy = frameworkCopy().record;
81
59
  // Opened from a list: where it stands in it, and its neighbours (`Trail`).
@@ -106,11 +84,24 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
106
84
  const dirty = ready ? dirtyOf(reading) : undefined;
107
85
  // What the application says of this record's moment — while nothing is being edited: then the
108
86
  // pill says the unsaved changes itself.
109
- const moment = ready && dirty === undefined ? look.moment?.(reading.record) : undefined;
87
+ const moment = ready && dirty === undefined
88
+ ? (options.moment?.(reading.record) ?? look.moment?.(reading.record))
89
+ : undefined;
110
90
  const failure = reading.edit.failure;
111
91
  // Who, only when the record says it (an author is optional: the line then says only when).
112
- const stamp = (one) => one?.at == null ? undefined : { at: one.at, ...(one.by == null ? {} : { by: one.by }) };
92
+ const stamp = (one) => one?.at == null
93
+ ? undefined
94
+ : { at: one.at, ...(one.by == null ? {} : { by: personOf(one.by) }) };
95
+ // Who did it reads as a person, not a username, when the application names its people.
96
+ const personOf = usePeopleOf([
97
+ ...(read ?? []).map((one) => one.by),
98
+ summary?.created?.by,
99
+ summary?.updated?.by,
100
+ ]);
101
+ const history = read?.map((one) => one.by == null ? one : { ...one, by: personOf(one.by) });
113
102
  const created = stamp(summary?.created);
103
+ const ownTag = ready && !reading.isNew ? options.tag?.(reading.record) : undefined;
104
+ const subtitle = (ready && !reading.isNew ? options.subtitle?.(reading.record) : null) ?? summary?.type;
114
105
  const updated = stamp(summary?.updated);
115
106
  // Moving away with something typed would lose it: «save / discard» comes first.
116
107
  const place = trail === undefined || reading.isNew || reading.edit.dirty
@@ -131,11 +122,15 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
131
122
  // A new record is «creating»; an existing one has no name until it is read.
132
123
  title: (ready && !reading.isNew ? options.title?.(reading.record) : null) ??
133
124
  summary?.name ??
134
- (reading.isNew ? copy.creating(nameOf(reading.meta, reading.locale) || "") : ""),
135
- ...(summary?.type == null ? {} : { subtitle: summary.type }),
136
- ...(summary?.state == null
137
- ? {}
138
- : { tag: { label: summary.state, ...(tone === undefined ? {} : { tone }) } }),
125
+ (reading.isNew
126
+ ? (options.creating ?? copy.creating(nameOf(reading.meta, reading.locale) || ""))
127
+ : ""),
128
+ ...(subtitle == null ? {} : { subtitle }),
129
+ ...(ownTag != null
130
+ ? { tag: ownTag }
131
+ : summary?.state == null
132
+ ? {}
133
+ : { tag: { label: summary.state, ...(tone === undefined ? {} : { tone }) } }),
139
134
  },
140
135
  ...(dirty === undefined ? {} : { dirty }),
141
136
  // The refusal in words; its heading when the server said nothing more (no detail).
@@ -156,46 +151,3 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
156
151
  },
157
152
  };
158
153
  }
159
- export function EntityRecord({ api, resource, entity, fields, pages, actions, title, initial, }) {
160
- const screen = useRecordScreen(entity, { api, resource }, { title, initial });
161
- const { reading, crumbs, history, pager, moment } = screen;
162
- const [page, setPage] = useState(undefined);
163
- const copy = frameworkCopy().record;
164
- // On a phone a form is one column, its label over its value: two side by side at 400 px
165
- // squeezed a text area beside its word (web-ui's grid does not narrow by itself).
166
- const phone = usePhone(api);
167
- const settings = useFormStyle() === "settings";
168
- // The record's own lifecycle (its `Delete`, its trash); once it is out of every reading the
169
- // surface closes — every list that showed it reads again by itself.
170
- const lifecycle = useRecordLifecycleActions(reading, (done) => done === "restore" ? reading.reload() : api.close());
171
- if (reading.status === "loading")
172
- return _jsx(Skeleton, { rows: 6, label: copy.loading });
173
- if (reading.status === "failed")
174
- return _jsx(Refused, { error: reading.error, onRetry: reading.reload });
175
- const { meta, locale, edit } = reading;
176
- const layout = formOf(meta, entity.summary);
177
- // What the header already says — the name, the state, the type — is not said again as a
178
- // field, unless it can be typed in now: then the field is its control, not a repetition.
179
- const parts = summaryFieldsOf(meta, reading.record ?? {}, entity.summary);
180
- const said = new Set([meta?.display, parts.state, parts.type]);
181
- const shown = fields ??
182
- layout.fields.filter((name) => reading.isNew || !said.has(name) || !edit.state(name).readonly);
183
- const columns = phone || (api.surface !== "page" && api.surface !== "modal") ? 1 : 2;
184
- // The screen's actions and the lifecycle's. As data they go to the dock, where the view style
185
- // draws them; drawn by hand, in the rail with the lifecycle's buttons beside them.
186
- const own = actionsOf(actions?.(reading) ?? null);
187
- const docked = own.drawn === null ? [...own.dock, ...lifecycle.actions] : [];
188
- const drawn = own.drawn === null ? null : (_jsxs(_Fragment, { children: [own.drawn, _jsx(LifecycleButtons, { actions: lifecycle.actions })] }));
189
- const tabs = pages ?? layout.pages;
190
- return (_jsxs(_Fragment, { children: [_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 &&
191
- pager === undefined &&
192
- docked.length === 0 &&
193
- moment === undefined &&
194
- drawn === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), drawn === null ? null : _jsx(Record.Actions, { children: drawn }), docked.length === 0 && moment === undefined ? null : (_jsx(Record.Dock, { actions: docked, ...(moment === undefined ? {} : { moment }) }))] })), _jsxs(Record.Paper, { layout: phone ? "stacked" : "horizontal", children: [edit.conflict || edit.restored ? (_jsxs("div", { className: "flex flex-col gap-3", children: [edit.conflict ? (_jsx(Callout, { tone: "warn", title: copy.conflict, children: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }) })) : null, edit.restored ? (_jsx(Callout, { tone: "info", title: copy.restored, children: null })) : null] })) : null, _jsx(FormSection, { columns: columns, ...(settings && fields === undefined && layout.sections.length > 0
195
- ? { title: copy.general }
196
- : {}), children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), fields !== undefined
197
- ? null
198
- : layout.sections.map((name) => (_jsx(FormSection, { title: labelOf(meta, name, locale), columns: columns, children: Object.keys(meta?.fields[name]?.definition?.fields ?? {}).map((part) => (_jsx(RecordField, { record: reading, name: `${name}.${part}` }, part))) }, name))), edit.advice
199
- .filter((one) => (one.path?.length ?? 0) <= 1)
200
- .map((one) => (_jsx(Callout, { tone: "info", title: one.message, children: null }, one.message))), tabs.length === 0 || reading.isNew ? null : (_jsx(Record.Pages, { current: page ?? tabs[0], onChange: setPage, children: tabs.map((name) => (_jsx(Record.Page, { id: name, label: labelOf(meta, name, locale), children: _jsx(RecordField, { record: reading, name: name, bare: true }) }, name))) })), screen.audit === undefined ? null : _jsx(Record.Audit, { ...screen.audit })] }), history === undefined ? null : _jsx(Record.Activity, { events: history })] }), lifecycle.dialog] }));
201
- }
@@ -26,6 +26,8 @@ import type { RecordReading } from "../../react/useRecord.js";
26
26
  */
27
27
  export declare function useRecordInWorkspace<T extends AnyRecord>(api: WorkspaceApi, record: RecordReading<T>, options?: {
28
28
  title?: ((record: T) => string | null) | undefined;
29
+ /** How a new one is named in its tab: «Nueva noticia». Without it, «Noticia · nuevo». */
30
+ creating?: string | undefined;
29
31
  }): void;
30
32
  /**
31
33
  * «Browse everything» as the composer's chooser: the entity's own list opens in a window and
@@ -33,7 +33,7 @@ export function useRecordInWorkspace(api, record, options = {}) {
33
33
  ? options.title(record.record)
34
34
  : null;
35
35
  const title = record.isNew
36
- ? newTitle(record.meta, record.locale)
36
+ ? (options.creating ?? newTitle(record.meta, record.locale))
37
37
  : named !== null
38
38
  ? named
39
39
  : record.status === "ready" && display !== ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.18.0",
3
+ "version": "3.20.0",
4
4
  "description": "The web client of sincpro_framework: entities, lists and records bound to the metadata the server publishes, drawn with @sincpro/web-ui and arranged with @sincpro/web-composer.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -51,11 +51,11 @@
51
51
  "@opentelemetry/sdk-trace": "^3.1.0",
52
52
  "@sentry/browser": "^11.11.0",
53
53
  "@sentry/core": "^11.11.0",
54
- "@sincpro/client-framework": "^2.7.0",
55
- "@sincpro/criteria": "^2.5.1",
54
+ "@sincpro/client-framework": "^2.8.0",
55
+ "@sincpro/criteria": "^2.6.0",
56
56
  "@sincpro/criteria-react": "^2.5.1",
57
57
  "@sincpro/web-composer": "^1.7.0",
58
- "@sincpro/web-ui": "^2.20.0",
58
+ "@sincpro/web-ui": "^2.22.0",
59
59
  "react": ">=19",
60
60
  "react-dom": ">=19"
61
61
  },
@@ -95,11 +95,11 @@
95
95
  "@opentelemetry/sdk-trace": "3.1.0",
96
96
  "@sentry/browser": "11.11.0",
97
97
  "@sentry/core": "11.11.0",
98
- "@sincpro/client-framework": "^2.7.0",
99
- "@sincpro/criteria": "^2.5.1",
98
+ "@sincpro/client-framework": "^2.8.0",
99
+ "@sincpro/criteria": "^2.6.0",
100
100
  "@sincpro/criteria-react": "^2.5.1",
101
101
  "@sincpro/web-composer": "^1.9.0",
102
- "@sincpro/web-ui": "^2.20.0",
102
+ "@sincpro/web-ui": "^2.22.0",
103
103
  "@storybook/addon-a11y": "10.6.5",
104
104
  "@storybook/addon-docs": "10.6.5",
105
105
  "@storybook/addon-mcp": "10.6.5",