@sincpro/web-framework 3.0.0 → 3.1.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.
- package/README.md +29 -0
- package/dist/core/copy.d.ts +11 -1
- package/dist/core/copy.js +28 -0
- package/dist/core/explain.d.ts +12 -4
- package/dist/core/explain.js +18 -6
- package/dist/core/form.d.ts +7 -3
- package/dist/core/form.js +11 -5
- package/dist/core/groups.d.ts +17 -0
- package/dist/core/groups.js +31 -0
- package/dist/core/history.d.ts +41 -4
- package/dist/core/history.js +79 -12
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +4 -3
- package/dist/core/measure.d.ts +14 -5
- package/dist/core/measure.js +32 -7
- package/dist/core/present.d.ts +51 -3
- package/dist/core/present.js +162 -15
- package/dist/core/summary.d.ts +6 -2
- package/dist/react/context.d.ts +23 -2
- package/dist/react/context.js +51 -2
- package/dist/react/useGroups.js +15 -4
- package/dist/react/useHistory.d.ts +4 -2
- package/dist/react/useHistory.js +20 -5
- package/dist/react/usePivot.js +18 -3
- package/dist/react/useRecord.d.ts +3 -0
- package/dist/react/useRecord.js +14 -2
- package/dist/web/Refused.d.ts +3 -3
- package/dist/web/Refused.js +3 -3
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.js +1 -1
- package/dist/web/list/EntityList.js +53 -14
- package/dist/web/list/columns.d.ts +6 -1
- package/dist/web/list/columns.js +53 -8
- package/dist/web/list/presentation.d.ts +20 -1
- package/dist/web/record/RelatedList.d.ts +0 -15
- package/dist/web/record/RelatedList.js +35 -6
- package/dist/web/record/edit.d.ts +5 -0
- package/dist/web/record/edit.js +48 -8
- package/dist/web/record/record.js +5 -2
- package/dist/web/workspace/SincproApp.d.ts +10 -1
- package/dist/web/workspace/SincproApp.js +18 -4
- package/dist/web/workspace/record.d.ts +7 -2
- package/dist/web/workspace/record.js +31 -6
- package/package.json +6 -6
package/dist/web/record/edit.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import {} from "@sincpro/client-framework";
|
|
4
4
|
import { choicesOf } from "@sincpro/criteria";
|
|
5
5
|
import { frameworkCopy } from "../../core/copy.js";
|
|
6
6
|
import { errorAt } from "../../core/edit.js";
|
|
7
7
|
import { editableLines } from "../../core/lines.js";
|
|
8
|
-
import { textOf, viewOf } from "../../core/present.js";
|
|
8
|
+
import { fieldAt, fieldMetaOf, isMoneyDefinition, textOf, valueAt, viewOf, } from "../../core/present.js";
|
|
9
9
|
import { relationFieldOf } from "../../core/relation.js";
|
|
10
10
|
import { useEntityFor, useFramework } from "../../react/context.js";
|
|
11
11
|
import { useNameOf } from "../../react/useNameOf.js";
|
|
@@ -15,6 +15,15 @@ import { useRecordOpening } from "./opening.js";
|
|
|
15
15
|
import { RecordLines } from "./record.js";
|
|
16
16
|
import { RelatedList } from "./RelatedList.js";
|
|
17
17
|
import { Checkbox, Field, FormSection, ReadValue, RelationValue, } from "@sincpro/web-ui";
|
|
18
|
+
/** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
|
|
19
|
+
function setAt(value, path, next) {
|
|
20
|
+
const base = typeof value === "object" && value !== null ? value : {};
|
|
21
|
+
const dot = path.indexOf(".");
|
|
22
|
+
if (dot < 0)
|
|
23
|
+
return { ...base, [path]: next };
|
|
24
|
+
const head = path.slice(0, dot);
|
|
25
|
+
return { ...base, [head]: setAt(base[head], path.slice(dot + 1), next) };
|
|
26
|
+
}
|
|
18
27
|
/** A key alone, read: the name of the record it points at, asked once by key — the key until
|
|
19
28
|
* then, and when nothing answers. */
|
|
20
29
|
function KeyValue({ target, id, ...rest }) {
|
|
@@ -41,15 +50,32 @@ function KeyValue({ target, id, ...rest }) {
|
|
|
41
50
|
* A one2many is a block: its lines (`lines`) or its related list (`list`), each with every piece
|
|
42
51
|
* replaceable the screen's way.
|
|
43
52
|
*
|
|
53
|
+
* A value the record embeds (a payment's receipt) is drawn from its definition: `name="recibo"`
|
|
54
|
+
* is a section of its fields, and `name="recibo.numero"` is one of them — its label and type the
|
|
55
|
+
* definition's, read only when the embedded value is, and written back into the value whole.
|
|
56
|
+
*
|
|
44
57
|
* <RecordField record={invoice} name="due_date" />
|
|
45
58
|
* <RecordField record={invoice} name="customer_id" />
|
|
46
59
|
* <RecordField record={invoice} name="lines" lines={{ controls: { qty: Stepper } }} />
|
|
60
|
+
* <RecordField record={pago} name="recibo.numero" />
|
|
47
61
|
*/
|
|
48
62
|
export function RecordField({ record, name, as, bare = false, lines: look, list: listed, }) {
|
|
49
63
|
const { meta, locale, edit } = record;
|
|
50
64
|
const view = viewOf(meta, name, locale);
|
|
51
|
-
|
|
52
|
-
const
|
|
65
|
+
// A field of an embedded value (`recibo.numero`): the embedded value's state, its own hints.
|
|
66
|
+
const place = fieldAt(meta, name);
|
|
67
|
+
const nested = place.meta !== meta;
|
|
68
|
+
const head = nested ? name.slice(0, name.indexOf(".")) : name;
|
|
69
|
+
const part = nested ? place.meta?.fields[place.name] : undefined;
|
|
70
|
+
const whole = edit.state(head);
|
|
71
|
+
const state = nested
|
|
72
|
+
? {
|
|
73
|
+
visible: whole.visible,
|
|
74
|
+
readonly: whole.readonly || part?.readonly === true,
|
|
75
|
+
required: !whole.readonly && part?.required === true,
|
|
76
|
+
}
|
|
77
|
+
: whole;
|
|
78
|
+
const relation = nested ? undefined : relationFieldOf(meta, name);
|
|
53
79
|
const target = useEntityFor(relation?.target);
|
|
54
80
|
const opening = useRecordOpening();
|
|
55
81
|
const { metas } = useFramework();
|
|
@@ -67,6 +93,17 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
67
93
|
// project's channels, an inventory's components) — no model of its own, no id — is edited the
|
|
68
94
|
// same way as lines: a whole list, local keys, through the record's own save.
|
|
69
95
|
const own = meta?.fields[name];
|
|
96
|
+
const parts = Object.keys(own?.definition?.fields ?? {});
|
|
97
|
+
if (as === undefined &&
|
|
98
|
+
own?.type === "embedded" &&
|
|
99
|
+
own.many !== true &&
|
|
100
|
+
own.definition &&
|
|
101
|
+
own.widget !== "money" &&
|
|
102
|
+
!isMoneyDefinition(own.definition)) {
|
|
103
|
+
// One value the record embeds: its fields, each by its label — a section of the record.
|
|
104
|
+
const block = parts.map((one) => (_jsx(RecordField, { record: record, name: `${name}.${one}` }, one)));
|
|
105
|
+
return bare ? _jsx(_Fragment, { children: block }) : _jsx(FormSection, { title: view.label, children: block });
|
|
106
|
+
}
|
|
70
107
|
if (as === undefined && own?.type === "embedded" && own.many === true && own.definition) {
|
|
71
108
|
// A page of them stays read only, as a one2many's: written back whole it would drop what
|
|
72
109
|
// it did not bring.
|
|
@@ -102,16 +139,19 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
102
139
|
})()), ...listed }));
|
|
103
140
|
return bare ? list : _jsx(FormSection, { title: view.label, children: list });
|
|
104
141
|
}
|
|
105
|
-
const value = edit.values[name];
|
|
142
|
+
const value = nested ? valueAt(meta, edit.values, name) : edit.values[name];
|
|
106
143
|
const error = errorAt(edit.errors, name);
|
|
107
144
|
const control = {
|
|
108
145
|
value,
|
|
109
|
-
|
|
146
|
+
// A field of an embedded value is written back into the value, whole.
|
|
147
|
+
set: nested
|
|
148
|
+
? (next) => edit.set(head, setAt(edit.values[head], name.slice(head.length + 1), next))
|
|
149
|
+
: (next) => edit.set(name, next),
|
|
110
150
|
readonly: state.readonly,
|
|
111
151
|
invalid: error !== undefined,
|
|
112
152
|
label: view.label,
|
|
113
153
|
};
|
|
114
|
-
const field = meta
|
|
154
|
+
const field = fieldMetaOf(meta, name);
|
|
115
155
|
/** A many2one of a declared entity: chosen by the server's literal search, opened where the
|
|
116
156
|
* view says. Written by its key; read by the record it points at. */
|
|
117
157
|
function manyToOne() {
|
|
@@ -143,7 +183,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
|
|
|
143
183
|
}
|
|
144
184
|
if (view.type === "boolean" && as === undefined)
|
|
145
185
|
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), field?.widget)) }));
|
|
186
|
+
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(place.meta, place.name, locale), field?.widget)) }));
|
|
147
187
|
}
|
|
148
188
|
/**
|
|
149
189
|
* The record's «save / discard», for `<Record dirty={…}>`: present only while something changed,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { describeRows } from "@sincpro/criteria";
|
|
4
4
|
import { frameworkCopy } from "../../core/copy.js";
|
|
5
|
-
import { textOf, viewOf } from "../../core/present.js";
|
|
5
|
+
import { textOf, valueAt, viewOf } from "../../core/present.js";
|
|
6
6
|
import { relatedOf } from "../../core/related.js";
|
|
7
7
|
import { relationFieldOf } from "../../core/relation.js";
|
|
8
8
|
import { useEntityFor } from "../../react/context.js";
|
|
@@ -20,6 +20,7 @@ import { List, RelationValue, } from "@sincpro/web-ui";
|
|
|
20
20
|
*
|
|
21
21
|
* <Record.Paper>
|
|
22
22
|
* <Record.Facts fields={factsOf(record, meta, ["number", "customer", "due"])} />
|
|
23
|
+
* <Record.Facts fields={factsOf(pago, meta, ["recibo.numero", "recibo.concepto"])} />
|
|
23
24
|
* <Record.Pages>
|
|
24
25
|
* <Record.Page id="lines" label={labelOf(meta, "lines")} count={countOf(record, "lines")}>
|
|
25
26
|
* <RecordLines record={record} meta={meta} name="lines" />
|
|
@@ -35,7 +36,9 @@ export function factsOf(record, meta, names, options = {}) {
|
|
|
35
36
|
const relation = relationFieldOf(meta, name);
|
|
36
37
|
return {
|
|
37
38
|
label: view.label,
|
|
38
|
-
value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : (
|
|
39
|
+
value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : (
|
|
40
|
+
// A field of an embedded value is named by its path: `recibo.numero`.
|
|
41
|
+
(textOf(meta, name, valueAt(meta, record, name), options.locale) ?? EMPTY)),
|
|
39
42
|
...(view.help === undefined ? {} : { hint: view.help }),
|
|
40
43
|
...(name === meta?.identity ? { mono: true } : {}),
|
|
41
44
|
};
|
|
@@ -2,8 +2,9 @@ import { type ChangeFeed, type Entity, type Transport } from "@sincpro/client-fr
|
|
|
2
2
|
import type { Meta } from "@sincpro/criteria";
|
|
3
3
|
import { type ComposerSkin, type OnViewError, type ResourceRef, type ViewSpec, type WorkspaceStore } from "@sincpro/web-composer";
|
|
4
4
|
import { type CacheOptions } from "../../core/cache.js";
|
|
5
|
+
import type { DateStyle } from "../../core/present.js";
|
|
5
6
|
import { type ReactNode } from "react";
|
|
6
|
-
export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, onViewError, changes, }: {
|
|
7
|
+
export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, events, workspace: given, bar, onViewError, changes, }: {
|
|
7
8
|
transport: Transport;
|
|
8
9
|
/** The entities as composer views — `entityView(…)` — and any other view of the app. */
|
|
9
10
|
views: readonly ViewSpec[];
|
|
@@ -28,6 +29,14 @@ export declare function SincproApp({ transport, views, start, language, metas, e
|
|
|
28
29
|
/** Where the business is (`"America/La_Paz"`): every date and time on its wall clock.
|
|
29
30
|
* Without it, the browser's. */
|
|
30
31
|
timeZone?: string;
|
|
32
|
+
/** How dates are written. Without it, numeric — «16/11/2026» — and the month in words on a
|
|
33
|
+
* phone, where a word reads better than a column of digits. */
|
|
34
|
+
dateStyle?: DateStyle;
|
|
35
|
+
/** The business's currency (`"BOB"`): an amount the model draws as money is written in it. */
|
|
36
|
+
currency?: string;
|
|
37
|
+
/** Each domain event's definition by its wire name (`eventMetasOf(contract)`): a history
|
|
38
|
+
* names each fact's own fields in its words. */
|
|
39
|
+
events?: Readonly<Record<string, Meta>>;
|
|
31
40
|
/** The workspace, when the app needs to reach it (a menu of its bar): composer's
|
|
32
41
|
* `useWorkspace()`. Without it, the app keeps one of its own. */
|
|
33
42
|
workspace?: WorkspaceStore;
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { processChanges, processContext, reportError, } from "@sincpro/client-framework";
|
|
4
4
|
import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
|
|
5
|
-
import { createRegistry, formatRef } from "@sincpro/web-composer/domain";
|
|
5
|
+
import { createRegistry, formatRef, PHONE_WIDTH } from "@sincpro/web-composer/domain";
|
|
6
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";
|
|
10
10
|
import { installCopy, SPANISH_COPY, ToastProvider } from "@sincpro/web-ui";
|
|
11
|
-
import { useEffect, useMemo, useState } from "react";
|
|
11
|
+
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
12
12
|
/**
|
|
13
13
|
* The application context in one place: who answers (the transport), in which language, which
|
|
14
14
|
* model definitions are already known, the toasts, and the workspace with its views, ⌘K and
|
|
@@ -25,9 +25,22 @@ 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
|
+
/** Narrower than composer's phone (`PHONE_WIDTH`): the workspace fills the window here, so the
|
|
29
|
+
* window's width is the workspace's. */
|
|
30
|
+
const PHONE = `(max-width: ${PHONE_WIDTH - 1}px)`;
|
|
31
|
+
function onPhone(changed) {
|
|
32
|
+
if (typeof window === "undefined" || window.matchMedia === undefined)
|
|
33
|
+
return () => undefined;
|
|
34
|
+
const query = window.matchMedia(PHONE);
|
|
35
|
+
query.addEventListener("change", changed);
|
|
36
|
+
return () => query.removeEventListener("change", changed);
|
|
37
|
+
}
|
|
38
|
+
const isPhone = () => typeof window !== "undefined" && window.matchMedia !== undefined
|
|
39
|
+
? window.matchMedia(PHONE).matches
|
|
40
|
+
: false;
|
|
28
41
|
/** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
|
|
29
42
|
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, changes = processChanges, }) {
|
|
43
|
+
export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
|
|
31
44
|
// Installed once, before anything draws: the three tables are module state of their packages.
|
|
32
45
|
useState(() => {
|
|
33
46
|
if (language === "es") {
|
|
@@ -62,6 +75,7 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
|
|
|
62
75
|
// The cache is read once, as `cached` is.
|
|
63
76
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
77
|
}, [cached, changes]);
|
|
78
|
+
const phone = useSyncExternalStore(onPhone, isPhone, () => false);
|
|
65
79
|
const own = useWorkspace();
|
|
66
80
|
const workspace = given ?? own;
|
|
67
81
|
const registry = useMemo(() => createRegistry(views), [views]);
|
|
@@ -71,5 +85,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
|
|
|
71
85
|
// The first screen only: a re-render must not push it again.
|
|
72
86
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
87
|
}, [workspace]);
|
|
74
|
-
return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(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 }) }) })] }) }) }));
|
|
88
|
+
return (_jsx(FrameworkProvider, { transport: cached, locale: language, changes: changes, ...(metas === undefined ? {} : { metas }), ...(entities === undefined ? {} : { entities }), ...(timeZone === undefined ? {} : { timeZone }), dateStyle: dateStyle ?? (phone ? "literal" : "numeric"), ...(currency === undefined ? {} : { currency }), ...(events === undefined ? {} : { events }), children: _jsx(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 }) }) })] }) }) }));
|
|
75
89
|
}
|
|
@@ -13,7 +13,9 @@ export type Stamp = {
|
|
|
13
13
|
* does, as values: read the record for editing, follow the workspace's breadcrumb, tell the
|
|
14
14
|
* workspace its name and its unsaved work, read its history, step to its neighbours in the list
|
|
15
15
|
* it was opened from, and say its name, state, unsaved work, refusal and authorship the way
|
|
16
|
-
* web-ui's `Record` takes them.
|
|
16
|
+
* web-ui's `Record` takes them. A screen that draws its own history passes `history: false`, and
|
|
17
|
+
* nothing asks for it. The state's tag and each fact of the history take the colours the entity
|
|
18
|
+
* was presented with (`presented(entity, { tones, facts })`).
|
|
17
19
|
*
|
|
18
20
|
* function InvoiceScreen(props: ViewProps) {
|
|
19
21
|
* const screen = useRecordScreen(invoices, props);
|
|
@@ -37,11 +39,13 @@ export type Stamp = {
|
|
|
37
39
|
*/
|
|
38
40
|
export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>, { api, resource }: Pick<ViewProps, "api" | "resource">, options?: {
|
|
39
41
|
title?: ((record: T) => string | null) | undefined;
|
|
42
|
+
/** `false`: the screen draws its own history — it is not read here. */
|
|
43
|
+
history?: boolean | undefined;
|
|
40
44
|
}): {
|
|
41
45
|
reading: RecordReading<T>;
|
|
42
46
|
crumbs: readonly import("@sincpro/web-composer").Crumb[];
|
|
43
47
|
history: import("../../index.js").HistoryEntry[] | undefined;
|
|
44
|
-
summary: import("../../
|
|
48
|
+
summary: import("../../core/summary.js").RecordSummary | undefined;
|
|
45
49
|
/** web-ui `Record`'s own props: where it is drawn, its name, its unsaved work, its refusal. */
|
|
46
50
|
record: {
|
|
47
51
|
error?: string | undefined;
|
|
@@ -49,6 +53,7 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
|
|
|
49
53
|
placement: "page" | "card";
|
|
50
54
|
identity: {
|
|
51
55
|
tag?: {
|
|
56
|
+
tone?: import("@sincpro/web-ui").Tone | undefined;
|
|
52
57
|
label: string;
|
|
53
58
|
} | undefined;
|
|
54
59
|
subtitle?: string | undefined;
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { TRAIL_PARAM } from "@sincpro/client-framework";
|
|
4
4
|
import { labelOf, nameOf } from "@sincpro/criteria";
|
|
5
|
-
import { useCrumbs } from "@sincpro/web-composer";
|
|
5
|
+
import { 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 { formOf } from "../../core/form.js";
|
|
9
|
+
import { summaryFieldsOf } from "../../core/summary.js";
|
|
9
10
|
import { placeOf, stepIn } from "../../core/trail.js";
|
|
10
11
|
import { useFramework } from "../../react/context.js";
|
|
11
12
|
import { useHistory } from "../../react/useHistory.js";
|
|
12
13
|
import { useRecord } from "../../react/useRecord.js";
|
|
13
14
|
import { useSummaryOf } from "../../react/useSummary.js";
|
|
15
|
+
import { presentationOf } from "../list/presentation.js";
|
|
14
16
|
import { dirtyOf, RecordField } from "../record/edit.js";
|
|
15
17
|
import { RecordLifecycle } from "../record/RecordLifecycle.js";
|
|
16
18
|
import { Refused } from "../Refused.js";
|
|
@@ -43,7 +45,9 @@ function refusalOf(failure) {
|
|
|
43
45
|
* does, as values: read the record for editing, follow the workspace's breadcrumb, tell the
|
|
44
46
|
* workspace its name and its unsaved work, read its history, step to its neighbours in the list
|
|
45
47
|
* it was opened from, and say its name, state, unsaved work, refusal and authorship the way
|
|
46
|
-
* web-ui's `Record` takes them.
|
|
48
|
+
* web-ui's `Record` takes them. A screen that draws its own history passes `history: false`, and
|
|
49
|
+
* nothing asks for it. The state's tag and each fact of the history take the colours the entity
|
|
50
|
+
* was presented with (`presented(entity, { tones, facts })`).
|
|
47
51
|
*
|
|
48
52
|
* function InvoiceScreen(props: ViewProps) {
|
|
49
53
|
* const screen = useRecordScreen(invoices, props);
|
|
@@ -69,7 +73,8 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
|
|
|
69
73
|
const reading = useRecord(entity, resource);
|
|
70
74
|
const crumbs = useCrumbs(api);
|
|
71
75
|
useRecordInWorkspace(api, reading, options);
|
|
72
|
-
const
|
|
76
|
+
const look = presentationOf(entity);
|
|
77
|
+
const history = useHistory(entity, reading.isNew || options.history === false ? "" : reading.id, [reading.record], { tones: look.facts });
|
|
73
78
|
const summarize = useSummaryOf(entity);
|
|
74
79
|
const copy = frameworkCopy().record;
|
|
75
80
|
// Opened from a list: where it stands in it, and its neighbours (`Trail`).
|
|
@@ -90,6 +95,13 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
|
|
|
90
95
|
};
|
|
91
96
|
const ready = reading.status === "ready";
|
|
92
97
|
const summary = ready && !reading.isNew ? summarize(reading.record, reading.meta) : undefined;
|
|
98
|
+
// The state's colour is the application's, declared once with the entity.
|
|
99
|
+
const stateField = ready
|
|
100
|
+
? summaryFieldsOf(reading.meta, reading.record, entity.summary).state
|
|
101
|
+
: undefined;
|
|
102
|
+
const tone = stateField === undefined || !ready
|
|
103
|
+
? undefined
|
|
104
|
+
: look.tones?.[stateField]?.[String(reading.record[stateField])];
|
|
93
105
|
const dirty = ready ? dirtyOf(reading) : undefined;
|
|
94
106
|
const failure = reading.edit.failure;
|
|
95
107
|
// Who, only when the record says it (an author is optional: the line then says only when).
|
|
@@ -117,7 +129,9 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
|
|
|
117
129
|
summary?.name ??
|
|
118
130
|
(reading.isNew ? copy.creating(nameOf(reading.meta, reading.locale) || "") : ""),
|
|
119
131
|
...(summary?.type == null ? {} : { subtitle: summary.type }),
|
|
120
|
-
...(summary?.state == null
|
|
132
|
+
...(summary?.state == null
|
|
133
|
+
? {}
|
|
134
|
+
: { tag: { label: summary.state, ...(tone === undefined ? {} : { tone }) } }),
|
|
121
135
|
},
|
|
122
136
|
...(dirty === undefined ? {} : { dirty }),
|
|
123
137
|
// The refusal in words; its heading when the server said nothing more (no detail).
|
|
@@ -141,13 +155,22 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
|
|
|
141
155
|
const { reading, crumbs, history, pager } = screen;
|
|
142
156
|
const [page, setPage] = useState(undefined);
|
|
143
157
|
const copy = frameworkCopy().record;
|
|
158
|
+
// On a phone a form is one column, its label over its value: two side by side at 400 px
|
|
159
|
+
// squeezed a text area beside its word (web-ui's grid does not narrow by itself).
|
|
160
|
+
const phone = usePhone(api);
|
|
144
161
|
if (reading.status === "loading")
|
|
145
162
|
return _jsx(Skeleton, { rows: 6, label: copy.loading });
|
|
146
163
|
if (reading.status === "failed")
|
|
147
164
|
return _jsx(Refused, { error: reading.error, onRetry: reading.reload });
|
|
148
165
|
const { meta, locale, edit } = reading;
|
|
149
166
|
const layout = formOf(meta, entity.summary);
|
|
150
|
-
|
|
167
|
+
// What the header already says — the name, the state, the type — is not said again as a
|
|
168
|
+
// field, unless it can be typed in now: then the field is its control, not a repetition.
|
|
169
|
+
const parts = summaryFieldsOf(meta, reading.record ?? {}, entity.summary);
|
|
170
|
+
const said = new Set([meta?.display, parts.state, parts.type]);
|
|
171
|
+
const shown = fields ??
|
|
172
|
+
layout.fields.filter((name) => reading.isNew || !said.has(name) || !edit.state(name).readonly);
|
|
173
|
+
const columns = phone || (api.surface !== "page" && api.surface !== "modal") ? 1 : 2;
|
|
151
174
|
// The record's own lifecycle (its `Delete`, its trash) beside the screen's commands; once it is
|
|
152
175
|
// out of every reading the surface closes — every list that showed it reads again by itself.
|
|
153
176
|
const lifecycle = reading.isNew ||
|
|
@@ -157,7 +180,9 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, ti
|
|
|
157
180
|
const own = actions?.(reading) ?? null;
|
|
158
181
|
const ownActions = own === null && lifecycle === null ? null : (_jsxs(_Fragment, { children: [own, lifecycle] }));
|
|
159
182
|
const tabs = pages ?? layout.pages;
|
|
160
|
-
return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _jsxs(Record.Paper, { layout: "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:
|
|
183
|
+
return (_jsxs(Record, { ...screen.record, children: [crumbs.length === 0 && pager === undefined && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), pager === undefined ? null : _jsx(Record.Pager, { ...pager }), ownActions === null ? null : _jsx(Record.Actions, { children: ownActions })] })), _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, children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), fields !== undefined
|
|
184
|
+
? null
|
|
185
|
+
: 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
|
|
161
186
|
.filter((one) => (one.path?.length ?? 0) <= 1)
|
|
162
187
|
.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 })] }));
|
|
163
188
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.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",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@opentelemetry/resources": "^3.1.0",
|
|
41
41
|
"@opentelemetry/sdk-trace": "^3.1.0",
|
|
42
42
|
"@sentry/browser": "^11.11.0",
|
|
43
|
-
"@sincpro/client-framework": "^2.
|
|
44
|
-
"@sincpro/criteria": "^2.
|
|
43
|
+
"@sincpro/client-framework": "^2.2.0",
|
|
44
|
+
"@sincpro/criteria": "^2.2.2",
|
|
45
45
|
"@sincpro/criteria-react": "^2.1.0",
|
|
46
46
|
"@sincpro/web-composer": "^1.7.0",
|
|
47
47
|
"@sincpro/web-ui": "^2.1.0",
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
"@opentelemetry/resources": "3.1.0",
|
|
73
73
|
"@opentelemetry/sdk-trace": "3.1.0",
|
|
74
74
|
"@sentry/browser": "11.11.0",
|
|
75
|
-
"@sincpro/client-framework": "^2.
|
|
76
|
-
"@sincpro/criteria": "^2.
|
|
75
|
+
"@sincpro/client-framework": "^2.2.0",
|
|
76
|
+
"@sincpro/criteria": "^2.2.2",
|
|
77
77
|
"@sincpro/criteria-react": "^2.1.0",
|
|
78
78
|
"@sincpro/web-composer": "^1.7.0",
|
|
79
|
-
"@sincpro/web-ui": "^2.
|
|
79
|
+
"@sincpro/web-ui": "^2.3.0",
|
|
80
80
|
"@storybook/addon-a11y": "10.6.5",
|
|
81
81
|
"@storybook/addon-docs": "10.6.5",
|
|
82
82
|
"@storybook/addon-mcp": "10.6.5",
|