@sincpro/web-framework 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/core/copy.d.ts +3 -1
- package/dist/core/copy.js +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/core/lines.d.ts +12 -4
- package/dist/core/lines.js +15 -3
- package/dist/core/present.d.ts +1 -0
- package/dist/core/present.js +54 -6
- package/dist/core/related.d.ts +5 -1
- package/dist/core/related.js +13 -12
- package/dist/core/relation.d.ts +23 -1
- package/dist/core/relation.js +33 -1
- package/dist/react/context.d.ts +5 -1
- package/dist/react/context.js +11 -2
- package/dist/react/useGroups.js +2 -2
- package/dist/react/useHistory.js +2 -2
- package/dist/react/useListing.js +10 -1
- package/dist/react/useLookup.js +2 -2
- package/dist/react/useNameOf.js +2 -2
- package/dist/react/usePivot.js +2 -2
- package/dist/react/useRecord.js +17 -2
- package/dist/react/useRelated.d.ts +5 -4
- package/dist/react/useRelated.js +14 -13
- package/dist/web/index.d.ts +1 -1
- package/dist/web/index.js +1 -1
- package/dist/web/record/EntityPicker.d.ts +7 -4
- package/dist/web/record/EntityPicker.js +5 -5
- package/dist/web/record/RelatedList.js +9 -6
- package/dist/web/record/control.d.ts +3 -1
- package/dist/web/record/control.js +8 -5
- package/dist/web/record/edit.js +23 -3
- package/dist/web/record/lines.js +13 -2
- package/dist/web/record/record.d.ts +12 -2
- package/dist/web/record/record.js +10 -2
- package/dist/web/workspace/SincproApp.d.ts +8 -18
- package/dist/web/workspace/SincproApp.js +17 -5
- package/dist/web/workspace/record.d.ts +59 -12
- package/dist/web/workspace/record.js +88 -27
- package/package.json +11 -11
|
@@ -4,6 +4,7 @@ import { TRAIL_PARAM } from "@sincpro/client-framework";
|
|
|
4
4
|
import { labelOf, nameOf } from "@sincpro/criteria";
|
|
5
5
|
import { useCrumbs } from "@sincpro/web-composer";
|
|
6
6
|
import { frameworkCopy } from "../../core/copy.js";
|
|
7
|
+
import { explain } from "../../core/explain.js";
|
|
7
8
|
import { formOf } from "../../core/form.js";
|
|
8
9
|
import { placeOf, stepIn } from "../../core/trail.js";
|
|
9
10
|
import { useFramework } from "../../react/context.js";
|
|
@@ -31,13 +32,44 @@ import { useState } from "react";
|
|
|
31
32
|
* <EntityRecord {...props} entity={invoices} fields={["customer_id", "due_date"]}
|
|
32
33
|
* actions={(invoice) => <CommandButton entity={invoices} command="post" … />} /> })
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
+
/** A save's refusal as a sentence — its heading when the server gave no detail. */
|
|
36
|
+
function refusalOf(failure) {
|
|
37
|
+
const said = explain(failure);
|
|
38
|
+
return said.sentence || said.heading;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* What every record screen in a workspace does before drawing its own — what `EntityRecord`
|
|
42
|
+
* does, as values: read the record for editing, follow the workspace's breadcrumb, tell the
|
|
43
|
+
* workspace its name and its unsaved work, read its history, step to its neighbours in the list
|
|
44
|
+
* it was opened from, and say its name, state, unsaved work, refusal and authorship the way
|
|
45
|
+
* web-ui's `Record` takes them.
|
|
46
|
+
*
|
|
47
|
+
* function InvoiceScreen(props: ViewProps) {
|
|
48
|
+
* const screen = useRecordScreen(invoices, props);
|
|
49
|
+
* if (screen.reading.status !== "ready") return <Skeleton rows={6} />;
|
|
50
|
+
* return (
|
|
51
|
+
* <Record {...screen.record}>
|
|
52
|
+
* <Record.Rail>
|
|
53
|
+
* <Record.Crumbs crumbs={screen.crumbs} />
|
|
54
|
+
* {screen.pager ? <Record.Pager {...screen.pager} /> : null}
|
|
55
|
+
* </Record.Rail>
|
|
56
|
+
* <Record.Paper>…your own fields…</Record.Paper>
|
|
57
|
+
* </Record>
|
|
58
|
+
* );
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* Context: the level between `EntityRecord` and `useRecord` — a screen of its own keeps every
|
|
62
|
+
* behaviour of the framework's record and writes its own tree. It answers PROPS, never
|
|
63
|
+
* components: web-ui finds a record's regions by type (`Record.Crumbs` a direct child of
|
|
64
|
+
* `Record.Rail`), and a region wrapped in one of ours is not found. Before it, forge's console
|
|
65
|
+
* carried these 150 lines itself (`shared/record_screen.tsx`).
|
|
66
|
+
*/
|
|
67
|
+
export function useRecordScreen(entity, { api, resource }) {
|
|
35
68
|
const reading = useRecord(entity, resource);
|
|
36
69
|
const crumbs = useCrumbs(api);
|
|
37
70
|
useRecordInWorkspace(api, reading);
|
|
38
71
|
const history = useHistory(entity, reading.isNew ? "" : reading.id, [reading.record]);
|
|
39
72
|
const summarize = useSummaryOf(entity);
|
|
40
|
-
const [page, setPage] = useState(undefined);
|
|
41
73
|
const copy = frameworkCopy().record;
|
|
42
74
|
// Opened from a list: where it stands in it, and its neighbours (`Trail`).
|
|
43
75
|
const { trails, transport } = useFramework();
|
|
@@ -55,6 +87,58 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, })
|
|
|
55
87
|
api.replace({ ...ref, params: { ...ref.params, [TRAIL_PARAM]: trailKey } });
|
|
56
88
|
});
|
|
57
89
|
};
|
|
90
|
+
const ready = reading.status === "ready";
|
|
91
|
+
const summary = ready && !reading.isNew ? summarize(reading.record, reading.meta) : undefined;
|
|
92
|
+
const dirty = ready ? dirtyOf(reading) : undefined;
|
|
93
|
+
const failure = reading.edit.failure;
|
|
94
|
+
// Who, only when the record says it (an author is optional: the line then says only when).
|
|
95
|
+
const stamp = (one) => one?.at == null ? undefined : { at: one.at, ...(one.by == null ? {} : { by: one.by }) };
|
|
96
|
+
const created = stamp(summary?.created);
|
|
97
|
+
const updated = stamp(summary?.updated);
|
|
98
|
+
// Moving away with something typed would lose it: «save / discard» comes first.
|
|
99
|
+
const place = trail === undefined || reading.isNew || reading.edit.dirty
|
|
100
|
+
? null
|
|
101
|
+
: placeOf(trail, reading.id);
|
|
102
|
+
return {
|
|
103
|
+
reading,
|
|
104
|
+
crumbs,
|
|
105
|
+
history,
|
|
106
|
+
summary,
|
|
107
|
+
/** web-ui `Record`'s own props: where it is drawn, its name, its unsaved work, its refusal. */
|
|
108
|
+
record: {
|
|
109
|
+
// Where it is mounted decides the paper, not what the rail carries: crumbs, pager and
|
|
110
|
+
// actions come and go while it is on screen, and the paper flipping with them remounted
|
|
111
|
+
// the form under the field being typed in. A modal is already a card.
|
|
112
|
+
placement: api.surface === "modal" ? "card" : "page",
|
|
113
|
+
identity: {
|
|
114
|
+
// A new record is «creating»; an existing one has no name until it is read.
|
|
115
|
+
title: summary?.name ??
|
|
116
|
+
(reading.isNew ? copy.creating(nameOf(reading.meta, reading.locale) || "") : ""),
|
|
117
|
+
...(summary?.type == null ? {} : { subtitle: summary.type }),
|
|
118
|
+
...(summary?.state == null ? {} : { tag: { label: summary.state } }),
|
|
119
|
+
},
|
|
120
|
+
...(dirty === undefined ? {} : { dirty }),
|
|
121
|
+
// The refusal in words; its heading when the server said nothing more (no detail).
|
|
122
|
+
...(failure === null || failure === undefined ? {} : { error: refusalOf(failure) }),
|
|
123
|
+
},
|
|
124
|
+
/** `Record.Pager`'s props, when it was opened from a list and nothing is typed. */
|
|
125
|
+
pager: place === null
|
|
126
|
+
? undefined
|
|
127
|
+
: { index: place.index, total: place.total, onPrev: go(-1), onNext: go(1) },
|
|
128
|
+
/** `Record.Audit`'s props, when the record says who made it or changed it. */
|
|
129
|
+
audit: created === undefined && updated === undefined
|
|
130
|
+
? undefined
|
|
131
|
+
: {
|
|
132
|
+
...(created === undefined ? {} : { created }),
|
|
133
|
+
...(updated === undefined ? {} : { updated }),
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export function EntityRecord({ api, resource, entity, fields, pages, actions, }) {
|
|
138
|
+
const screen = useRecordScreen(entity, { api, resource });
|
|
139
|
+
const { reading, crumbs, history, pager } = screen;
|
|
140
|
+
const [page, setPage] = useState(undefined);
|
|
141
|
+
const copy = frameworkCopy().record;
|
|
58
142
|
if (reading.status === "loading")
|
|
59
143
|
return _jsx(Skeleton, { rows: 6, label: copy.loading });
|
|
60
144
|
if (reading.status === "failed")
|
|
@@ -64,30 +148,7 @@ export function EntityRecord({ api, resource, entity, fields, pages, actions, })
|
|
|
64
148
|
const shown = fields ?? layout.fields;
|
|
65
149
|
const ownActions = actions?.(reading) ?? null;
|
|
66
150
|
const tabs = pages ?? layout.pages;
|
|
67
|
-
|
|
68
|
-
const dirty = dirtyOf(reading);
|
|
69
|
-
const created = summary?.created;
|
|
70
|
-
const updated = summary?.updated;
|
|
71
|
-
// Who, only when the record says it (web-ui 1.9: an author is optional, the line then says
|
|
72
|
-
// only when). The moment goes as the framework writes every fact of the record.
|
|
73
|
-
const stamp = (one) => one?.at == null ? undefined : { at: one.at, ...(one.by == null ? {} : { by: one.by }) };
|
|
74
|
-
const createdStamp = stamp(created);
|
|
75
|
-
const updatedStamp = stamp(updated);
|
|
76
|
-
// Moving away with something typed would lose it: «save / discard» comes first.
|
|
77
|
-
const place = trail === undefined || reading.isNew || edit.dirty ? null : placeOf(trail, reading.id);
|
|
78
|
-
return (_jsxs(Record
|
|
79
|
-
// Where it is mounted decides the paper, not what the rail carries: crumbs, pager and
|
|
80
|
-
// actions come and go while it is on screen (loading, a draft), and the paper flipping
|
|
81
|
-
// with them remounted the form under the field being typed in. A modal is already a card.
|
|
82
|
-
, {
|
|
83
|
-
// Where it is mounted decides the paper, not what the rail carries: crumbs, pager and
|
|
84
|
-
// actions come and go while it is on screen (loading, a draft), and the paper flipping
|
|
85
|
-
// with them remounted the form under the field being typed in. A modal is already a card.
|
|
86
|
-
placement: api.surface === "modal" ? "card" : "page", identity: {
|
|
87
|
-
title: summary?.name ?? copy.creating(nameOf(meta, locale) || ""),
|
|
88
|
-
...(summary?.type == null ? {} : { subtitle: summary.type }),
|
|
89
|
-
...(summary?.state == null ? {} : { tag: { label: summary.state } }),
|
|
90
|
-
}, ...(dirty === undefined ? {} : { dirty }), ...(edit.failure === null ? {} : { error: String(edit.failure.message) }), children: [crumbs.length === 0 && place === null && ownActions === null ? null : (_jsxs(Record.Rail, { children: [crumbs.length === 0 ? null : _jsx(Record.Crumbs, { crumbs: crumbs }), place === null ? null : (_jsx(Record.Pager, { index: place.index, total: place.total, onPrev: go(-1), onNext: go(1) })), 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: api.surface === "page" || api.surface === "modal" ? 2 : 1, children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), edit.advice
|
|
151
|
+
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: api.surface === "page" || api.surface === "modal" ? 2 : 1, children: shown.map((name) => (_jsx(RecordField, { record: reading, name: name }, name))) }), edit.advice
|
|
91
152
|
.filter((one) => (one.path?.length ?? 0) <= 1)
|
|
92
|
-
.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))) })),
|
|
153
|
+
.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 })] }));
|
|
93
154
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.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,11 +40,11 @@
|
|
|
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": "^0.
|
|
44
|
-
"@sincpro/criteria": "^2.
|
|
45
|
-
"@sincpro/criteria-react": "^2.
|
|
46
|
-
"@sincpro/web-composer": "^1.
|
|
47
|
-
"@sincpro/web-ui": "^2.
|
|
43
|
+
"@sincpro/client-framework": "^0.6.0",
|
|
44
|
+
"@sincpro/criteria": "^2.1.0",
|
|
45
|
+
"@sincpro/criteria-react": "^2.1.0",
|
|
46
|
+
"@sincpro/web-composer": "^1.6.0",
|
|
47
|
+
"@sincpro/web-ui": "^2.1.0",
|
|
48
48
|
"react": ">=19",
|
|
49
49
|
"react-dom": ">=19"
|
|
50
50
|
},
|
|
@@ -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": "^0.
|
|
76
|
-
"@sincpro/criteria": "^2.
|
|
77
|
-
"@sincpro/criteria-react": "^2.
|
|
78
|
-
"@sincpro/web-composer": "^1.
|
|
79
|
-
"@sincpro/web-ui": "^2.
|
|
75
|
+
"@sincpro/client-framework": "^0.6.0",
|
|
76
|
+
"@sincpro/criteria": "^2.1.0",
|
|
77
|
+
"@sincpro/criteria-react": "^2.1.0",
|
|
78
|
+
"@sincpro/web-composer": "^1.6.0",
|
|
79
|
+
"@sincpro/web-ui": "^2.1.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",
|