@sincpro/web-framework 3.19.0 → 3.21.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 +59 -51
- package/dist/core/copy.d.ts +12 -0
- package/dist/core/copy.js +51 -0
- package/dist/core/edit.d.ts +13 -0
- package/dist/core/edit.js +14 -0
- package/dist/core/export.d.ts +29 -0
- package/dist/core/export.js +47 -0
- package/dist/core/groups.js +1 -4
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +3 -2
- package/dist/react/context.d.ts +16 -2
- package/dist/react/context.js +7 -4
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.js +2 -0
- package/dist/react/useCounts.d.ts +23 -0
- package/dist/react/useCounts.js +43 -0
- package/dist/react/usePeopleOf.d.ts +14 -0
- package/dist/react/usePeopleOf.js +35 -0
- package/dist/react/useRecord.js +2 -2
- package/dist/web/index.d.ts +2 -2
- package/dist/web/index.js +2 -2
- package/dist/web/list/entityList/opening.d.ts +1 -1
- package/dist/web/list/entityList/opening.js +7 -2
- package/dist/web/list/entityList/props.d.ts +3 -2
- package/dist/web/list/export.d.ts +13 -0
- package/dist/web/list/export.js +61 -0
- package/dist/web/record/lines.js +6 -6
- package/dist/web/workspace/RecordScreen.d.ts +73 -7
- package/dist/web/workspace/RecordScreen.js +101 -23
- package/dist/web/workspace/SincproApp.d.ts +11 -1
- package/dist/web/workspace/SincproApp.js +8 -8
- package/dist/web/workspace/record.d.ts +17 -5
- package/dist/web/workspace/record.js +24 -7
- package/dist/web/workspace/workspace.d.ts +2 -0
- package/dist/web/workspace/workspace.js +1 -1
- package/package.json +7 -7
|
@@ -5,14 +5,15 @@ import { usePhone } from "@sincpro/web-composer";
|
|
|
5
5
|
import { frameworkCopy } from "../../core/copy.js";
|
|
6
6
|
import { formOf } from "../../core/form.js";
|
|
7
7
|
import { summaryFieldsOf } from "../../core/summary.js";
|
|
8
|
+
import { useCounts } from "../../react/useCounts.js";
|
|
8
9
|
import { actionsOf } from "../list/dock.js";
|
|
9
10
|
import { part, resolveParts, written } from "../parts.js";
|
|
10
11
|
import { RecordField } from "../record/edit.js";
|
|
11
12
|
import { LifecycleButtons, useRecordLifecycleActions, } from "../record/RecordLifecycle.js";
|
|
12
13
|
import { Refused } from "../Refused.js";
|
|
13
14
|
import { useRecordScreen } from "./record.js";
|
|
14
|
-
import { Button, FormSection, Record, Skeleton, useFormStyle } from "@sincpro/web-ui";
|
|
15
|
-
import { createContext, useContext, useState } from "react";
|
|
15
|
+
import { Button, FormSection, Record, Skeleton, useFormStyle, } from "@sincpro/web-ui";
|
|
16
|
+
import { createContext, Fragment, useContext, useState } from "react";
|
|
16
17
|
const RecordScreenContext = createContext(null);
|
|
17
18
|
function useScreenState(part) {
|
|
18
19
|
const state = useContext(RecordScreenContext);
|
|
@@ -34,6 +35,15 @@ function useScreenState(part) {
|
|
|
34
35
|
export function useScreenRecord(_entity) {
|
|
35
36
|
return useScreenState("useScreenRecord").reading;
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* How many columns the record's form takes where the screen is mounted — two on a page or in a
|
|
40
|
+
* modal, one in a panel, a peek or a phone —, for a block of the application that lays itself out
|
|
41
|
+
* the same way («three figures side by side when wide»). The screen decided it; a block never
|
|
42
|
+
* asks the workspace where it opened.
|
|
43
|
+
*/
|
|
44
|
+
export function useScreenColumns() {
|
|
45
|
+
return useScreenState("useScreenColumns").columns;
|
|
46
|
+
}
|
|
37
47
|
/* ----------------------------------------------------------------------------------------- *
|
|
38
48
|
* Parts that become web-ui slots
|
|
39
49
|
* ----------------------------------------------------------------------------------------- */
|
|
@@ -47,18 +57,25 @@ const Crumbs = screenPart("Crumbs", (_props, { screen }) => screen.crumbs.length
|
|
|
47
57
|
const Pager = screenPart("Pager", (_props, { screen }) => screen.pager === undefined ? null : _jsx(Record.Pager, { ...screen.pager }));
|
|
48
58
|
/** The screen's actions and the record's lifecycle — floating in the dock, or in the rail when
|
|
49
59
|
* the screen draws them by hand. The application's word on the record's moment goes with them. */
|
|
50
|
-
const Actions = screenPart("Actions", (
|
|
60
|
+
const Actions = screenPart("Actions", ({ visible }, state) => {
|
|
51
61
|
const { docked, drawn, screen } = state;
|
|
52
62
|
const moment = screen.moment;
|
|
53
63
|
return [
|
|
54
64
|
drawn === null ? null : _jsx(Record.Actions, { children: drawn }, "actions"),
|
|
55
|
-
docked.length === 0 && moment === undefined ? null : (_jsx(Record.Dock, { actions: docked, ...(moment === undefined ? {} : { moment }) }, "dock")),
|
|
65
|
+
docked.length === 0 && moment === undefined ? null : (_jsx(Record.Dock, { actions: docked, ...(moment === undefined ? {} : { moment }), ...(visible === undefined ? {} : { visible }) }, "dock")),
|
|
56
66
|
];
|
|
57
67
|
});
|
|
58
|
-
/**
|
|
68
|
+
/** What hangs off the record — its payments, its members —, as web-ui's smart buttons. */
|
|
69
|
+
const Smart = screenPart("Smart", (_props, { links }) => links.length === 0 ? null : _jsx(Record.Smart, { links: links }));
|
|
70
|
+
/** The band in front of the record. Empty, it draws crumbs, pager, links and actions — and no band at
|
|
59
71
|
* all when none of them has anything to say (an empty one is a blank strip in a modal). */
|
|
60
72
|
const Rail = screenPart("Rail", ({ children }, state) => {
|
|
61
|
-
const inside = written(resolveParts(children ?? [
|
|
73
|
+
const inside = written(resolveParts(children ?? [
|
|
74
|
+
_jsx(Crumbs, {}, "crumbs"),
|
|
75
|
+
_jsx(Pager, {}, "pager"),
|
|
76
|
+
_jsx(Smart, {}, "smart"),
|
|
77
|
+
_jsx(Actions, {}, "actions"),
|
|
78
|
+
], state));
|
|
62
79
|
return inside.length === 0 ? null : _jsx(Record.Rail, { children: inside });
|
|
63
80
|
});
|
|
64
81
|
/** Who made it and who changed it last, when the record says so. */
|
|
@@ -78,34 +95,65 @@ const Pages = screenPart("Pages", ({ names }, state) => {
|
|
|
78
95
|
* What happened to the edit itself, as web-ui's notices of the record — never among the fields:
|
|
79
96
|
* someone else saved first (`bad`: it blocks, so it stays in view between the rail and the
|
|
80
97
|
* paper, with «Read it again»), or a kept draft came back (`info`: into the rail's indicator,
|
|
81
|
-
* and it can be put away).
|
|
98
|
+
* and it can be put away). Elements of web-ui's slot, written straight into `Record` or its paper.
|
|
82
99
|
*/
|
|
83
|
-
|
|
84
|
-
const { reading, restoredAway, putRestoredAway } = state;
|
|
100
|
+
function noticesOf(reading, restoredAway, putRestoredAway) {
|
|
85
101
|
const copy = frameworkCopy().record;
|
|
86
102
|
const { conflict, restored } = reading.edit;
|
|
87
103
|
return [
|
|
88
104
|
conflict ? (_jsx(Record.Notice, { tone: "bad", action: _jsx(Button, { size: "sm", role: "secondary", onClick: reading.reload, children: copy.reload }), children: copy.conflict }, "conflict")) : null,
|
|
89
105
|
restored && !restoredAway ? (_jsx(Record.Notice, { tone: "info", onDismiss: putRestoredAway, children: copy.restored }, "restored")) : null,
|
|
90
106
|
];
|
|
91
|
-
}
|
|
107
|
+
}
|
|
92
108
|
/**
|
|
93
109
|
* What the server advised about the record or one of its fields, as notices of the record: one
|
|
94
110
|
* the save will refuse while it holds is a warning. A line's warning goes on its line.
|
|
95
111
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
112
|
+
function adviceOf(reading) {
|
|
113
|
+
return reading.edit.advice
|
|
114
|
+
.filter((one) => (one.path?.length ?? 0) <= 1)
|
|
115
|
+
.map((one) => (_jsx(Record.Notice, { tone: one.blocks_save === true ? "warn" : "info", children: one.message }, one.message)));
|
|
116
|
+
}
|
|
117
|
+
/** The edit's notices, at the top of the screen or inside the paper (`noticesOf`). */
|
|
118
|
+
const Notices = screenPart("Notices", (_props, state) => noticesOf(state.reading, state.restoredAway, state.putRestoredAway));
|
|
119
|
+
/** The server's advice, as notices of the record (`adviceOf`). */
|
|
120
|
+
const Advice = screenPart("Advice", (_props, { reading }) => adviceOf(reading));
|
|
121
|
+
/**
|
|
122
|
+
* The record's notices for a screen that writes web-ui's `Record` itself (`useRecordScreen`):
|
|
123
|
+
* the edit's and the server's advice, as `RecordScreen.Notices` and `.Advice` draw them —
|
|
124
|
+
* elements of web-ui's slot, written straight among `Record`'s children. Nothing while the record
|
|
125
|
+
* is not read.
|
|
126
|
+
*
|
|
127
|
+
* const notices = useRecordNotices(screen.reading);
|
|
128
|
+
* <Record {...screen.record}>{notices}<Record.Rail>…</Record.Rail>…</Record>
|
|
129
|
+
*
|
|
130
|
+
* Context: a screen at the hooks level copied the framework's notices — as `Callout`s among the
|
|
131
|
+
* fields, which web-ui says not to do (#112).
|
|
132
|
+
*/
|
|
133
|
+
export function useRecordNotices(reading) {
|
|
134
|
+
const [restoredAway, setRestoredAway] = useState(false);
|
|
135
|
+
if (reading.status !== "ready")
|
|
136
|
+
return [];
|
|
137
|
+
const read = reading;
|
|
138
|
+
return [...noticesOf(read, restoredAway, () => setRestoredAway(true)), ...adviceOf(read)];
|
|
139
|
+
}
|
|
102
140
|
/**
|
|
103
141
|
* The record's fields in web-ui's form grid: two columns on a page and in a modal, one in a
|
|
104
|
-
* panel, a peek or a phone. `names` chooses and orders them; `title` heads the section
|
|
142
|
+
* panel, a peek or a phone. `names` chooses and orders them; `title` heads the section and
|
|
143
|
+
* `hint` says what it is for. A field the model cannot draw as the screen wants — a body with
|
|
144
|
+
* pictures, a year — is drawn by `controls`, with the field's control and the record. A section
|
|
145
|
+
* of one field that bears its name («Sesiones», the sessions) does not name it twice: the field
|
|
146
|
+
* is drawn bare under the section's title.
|
|
105
147
|
*/
|
|
106
|
-
function Fields({ names, title, }) {
|
|
148
|
+
function Fields({ names, title, hint, controls, }) {
|
|
107
149
|
const state = useScreenState("Fields");
|
|
108
|
-
|
|
150
|
+
const shown = names ?? state.fields;
|
|
151
|
+
const { meta, locale } = state.reading;
|
|
152
|
+
const named = title !== undefined && shown.length === 1 && labelOf(meta, shown[0], locale) === title;
|
|
153
|
+
return (_jsx(FormSection, { columns: state.columns, ...(title === undefined ? {} : { title }), ...(hint === undefined ? {} : { hint }), children: shown.map((name) => {
|
|
154
|
+
const own = controls?.[name];
|
|
155
|
+
return (_jsx(RecordField, { record: state.reading, name: name, ...(named ? { bare: true } : {}), ...(own === undefined ? {} : { as: (control) => own(control, state.reading) }) }, name));
|
|
156
|
+
}) }));
|
|
109
157
|
}
|
|
110
158
|
/** Each value the record embeds (a payment's receipt) as a section of its own fields. */
|
|
111
159
|
function Sections() {
|
|
@@ -120,11 +168,16 @@ function paperContent(titled) {
|
|
|
120
168
|
}
|
|
121
169
|
/** The paper: the record itself. Empty, it draws the default content. */
|
|
122
170
|
const Paper = screenPart("Paper", ({ children, layout, width }, state) => (_jsx(Record.Paper, { layout: layout ?? (state.phone ? "stacked" : "horizontal"), ...(width === undefined ? {} : { width }), children: resolveParts(children ?? paperContent(state.settings && state.sections.length > 0), state) })));
|
|
123
|
-
function RecordScreenRoot({ api, resource, entity, initial, title, subtitle, fields, pages, actions, history, children, }) {
|
|
124
|
-
const screen = useRecordScreen(entity, { api, resource }, { title, subtitle, initial, history });
|
|
171
|
+
function RecordScreenRoot({ api, resource, entity, initial, title, subtitle, tag, creating, moment, links, fields, pages, actions, history, children, }) {
|
|
172
|
+
const screen = useRecordScreen(entity, { api, resource }, { title, subtitle, tag, creating, moment, initial, history });
|
|
125
173
|
const { reading } = screen;
|
|
126
174
|
const [page, setPage] = useState(undefined);
|
|
127
175
|
const [restoredAway, setRestoredAway] = useState(false);
|
|
176
|
+
// The related lists it links to, counted together — before anything returns early: the hook
|
|
177
|
+
// asks nothing while the record is not read.
|
|
178
|
+
const linked = reading.status === "ready" && !reading.isNew ? (links?.(reading.record) ?? []) : [];
|
|
179
|
+
const related = linked.filter(isRelated);
|
|
180
|
+
const counts = useCounts(related.map((one) => ({ entity: one.list, where: one.where })));
|
|
128
181
|
const phone = usePhone(api);
|
|
129
182
|
const settings = useFormStyle() === "settings";
|
|
130
183
|
// Its own lifecycle (`Delete`, the trash): once it is out of every reading the surface closes,
|
|
@@ -140,7 +193,13 @@ function RecordScreenRoot({ api, resource, entity, initial, title, subtitle, fie
|
|
|
140
193
|
// field, unless it can be typed in now: then the field is its control, not a repetition.
|
|
141
194
|
const parts = summaryFieldsOf(meta, reading.record, entity.summary);
|
|
142
195
|
const said = new Set([meta?.display, parts.state, parts.type]);
|
|
143
|
-
|
|
196
|
+
// An action may bring its own dialog (`DockedAction`): its action goes to the dock, its dialog
|
|
197
|
+
// is drawn by the screen — the screen calls its hook, never passes it.
|
|
198
|
+
const asked = actions?.(reading) ?? null;
|
|
199
|
+
const docked = Array.isArray(asked) ? asked.filter(isDocked) : [];
|
|
200
|
+
const own = actionsOf(Array.isArray(asked)
|
|
201
|
+
? asked.map((one) => (isDocked(one) ? one.action : one))
|
|
202
|
+
: asked);
|
|
144
203
|
const state = {
|
|
145
204
|
screen: screen,
|
|
146
205
|
reading: reading,
|
|
@@ -160,9 +219,20 @@ function RecordScreenRoot({ api, resource, entity, initial, title, subtitle, fie
|
|
|
160
219
|
drawn: own.drawn === null ? null : (_jsxs(_Fragment, { children: [own.drawn, _jsx(LifecycleButtons, { actions: lifecycle.actions })] })),
|
|
161
220
|
restoredAway,
|
|
162
221
|
putRestoredAway: () => setRestoredAway(true),
|
|
222
|
+
links: linked.map((one) => {
|
|
223
|
+
if (!isRelated(one))
|
|
224
|
+
return one;
|
|
225
|
+
const count = counts[related.indexOf(one)];
|
|
226
|
+
return {
|
|
227
|
+
icon: one.icon,
|
|
228
|
+
label: one.label,
|
|
229
|
+
...(count === null || count === undefined ? {} : { count }),
|
|
230
|
+
onClick: () => api.open(one.list.listRef(one.where, one.title)),
|
|
231
|
+
};
|
|
232
|
+
}),
|
|
163
233
|
};
|
|
164
234
|
const tree = children ?? (_jsxs(_Fragment, { children: [_jsx(Rail, {}), _jsx(Paper, {}), _jsx(Activity, {})] }));
|
|
165
|
-
return (_jsxs(RecordScreenContext.Provider, { value: state, children: [_jsx(Record, { ...screen.record, children: resolveParts(tree, state) }), lifecycle.dialog] }));
|
|
235
|
+
return (_jsxs(RecordScreenContext.Provider, { value: state, children: [_jsx(Record, { ...screen.record, children: resolveParts(tree, state) }), lifecycle.dialog, docked.map((one) => (_jsx(Fragment, { children: one.dialog }, one.action.id)))] }));
|
|
166
236
|
}
|
|
167
237
|
/**
|
|
168
238
|
* A record screen by parts: the framework's default, or any part of it replaced. See the top of
|
|
@@ -172,6 +242,7 @@ export const RecordScreen = Object.assign(RecordScreenRoot, {
|
|
|
172
242
|
Rail,
|
|
173
243
|
Crumbs,
|
|
174
244
|
Pager,
|
|
245
|
+
Smart,
|
|
175
246
|
Actions,
|
|
176
247
|
Paper,
|
|
177
248
|
Notices,
|
|
@@ -195,3 +266,10 @@ export const RecordScreen = Object.assign(RecordScreenRoot, {
|
|
|
195
266
|
export function EntityRecord(props) {
|
|
196
267
|
return _jsx(RecordScreen, { ...props });
|
|
197
268
|
}
|
|
269
|
+
/** An action that brings its own dialog, told from one that is only data. */
|
|
270
|
+
function isDocked(one) {
|
|
271
|
+
return typeof one === "object" && one !== null && "action" in one && "dialog" in one;
|
|
272
|
+
}
|
|
273
|
+
function isRelated(one) {
|
|
274
|
+
return "list" in one;
|
|
275
|
+
}
|
|
@@ -5,8 +5,9 @@ import { type CacheOptions } from "../../core/cache.js";
|
|
|
5
5
|
import type { Uploads } from "../../core/files.js";
|
|
6
6
|
import type { DateStyle } from "../../core/present.js";
|
|
7
7
|
import type { RichTextSettings } from "../../core/richText.js";
|
|
8
|
+
import { type People } from "../../react/context.js";
|
|
8
9
|
import { type ReactNode } from "react";
|
|
9
|
-
export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, region, richText, uploads, events, workspace: given, bar, onViewError, changes, }: {
|
|
10
|
+
export declare function SincproApp({ transport, views, start, language, voice, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, region, richText, uploads, people, events, workspace: given, bar, onViewError, changes, }: {
|
|
10
11
|
/** Who answers. Without it, the `FrameworkProvider` around the app — one provider for every
|
|
11
12
|
* face of a product. */
|
|
12
13
|
transport?: Transport;
|
|
@@ -18,6 +19,13 @@ export declare function SincproApp({ transport, views, start, language, metas, e
|
|
|
18
19
|
start?: ResourceRef;
|
|
19
20
|
/** The interface's language: web-ui's, the composer's and the framework's words. */
|
|
20
21
|
language?: "es" | "en";
|
|
22
|
+
/**
|
|
23
|
+
* How the Spanish addresses the person: `vos` («Elegí», «podés») — the default —, or `tú`
|
|
24
|
+
* («Elige», «puedes»), what most of the region writes. Web-ui's and the framework's tables in
|
|
25
|
+
* the same voice: two voices on one screen read as two authors. The composer's Spanish never
|
|
26
|
+
* addresses the person, so it has one table.
|
|
27
|
+
*/
|
|
28
|
+
voice?: "vos" | "tú";
|
|
21
29
|
/** Definitions known before any request, by entity key. */
|
|
22
30
|
metas?: Readonly<Record<string, Meta>>;
|
|
23
31
|
/** Drawn when nothing is open. */
|
|
@@ -45,6 +53,8 @@ export declare function SincproApp({ transport, views, start, language, metas, e
|
|
|
45
53
|
richText?: RichTextSettings;
|
|
46
54
|
/** Where a file a person gives goes — the application's (`FrameworkProvider uploads`). */
|
|
47
55
|
uploads?: Uploads;
|
|
56
|
+
/** Who is who: a record's history and authorship by name (`FrameworkProvider people`). */
|
|
57
|
+
people?: People;
|
|
48
58
|
/** Each domain event's definition by its wire name (`eventMetasOf(contract)`): a history
|
|
49
59
|
* names each fact's own fields in its words. */
|
|
50
60
|
events?: Readonly<Record<string, Meta>>;
|
|
@@ -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";
|
|
7
|
+
import { installFrameworkCopy, SPANISH_FRAMEWORK_COPY, SPANISH_FRAMEWORK_COPY_TU, } from "../../core/copy.js";
|
|
8
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
|
|
@@ -30,7 +30,7 @@ import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
|
30
30
|
* `FrameworkProvider` around it — its transport and cache, its context, its zone and currency —
|
|
31
31
|
* and brings only what is its own: its entities, the definitions of their models and their facts
|
|
32
32
|
* (`ModelDefinitions`). The configuration of the provider's (`timeZone`, `currency`, `region`,
|
|
33
|
-
* `dateStyle`, `richText`, `uploads`, `cache`, `changes`) is then the provider's: said once.
|
|
33
|
+
* `dateStyle`, `richText`, `uploads`, `people`, `cache`, `changes`) is then the provider's: said once.
|
|
34
34
|
*
|
|
35
35
|
* <FrameworkProvider transport={transport} timeZone="America/La_Paz" currency="BOB">
|
|
36
36
|
* <Site />
|
|
@@ -62,13 +62,13 @@ function FrameworkSearch({ children }) {
|
|
|
62
62
|
}
|
|
63
63
|
/** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
|
|
64
64
|
const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
|
|
65
|
-
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, }) {
|
|
66
66
|
// Installed once, before anything draws: the three tables are module state of their packages.
|
|
67
67
|
useState(() => {
|
|
68
68
|
if (language === "es") {
|
|
69
|
-
installCopy(SPANISH_COPY);
|
|
69
|
+
installCopy(voice === "tú" ? SPANISH_COPY_TU : SPANISH_COPY);
|
|
70
70
|
installComposerCopy(SPANISH_COMPOSER_COPY);
|
|
71
|
-
installFrameworkCopy(SPANISH_FRAMEWORK_COPY);
|
|
71
|
+
installFrameworkCopy(voice === "tú" ? SPANISH_FRAMEWORK_COPY_TU : SPANISH_FRAMEWORK_COPY);
|
|
72
72
|
}
|
|
73
73
|
return null;
|
|
74
74
|
});
|
|
@@ -113,6 +113,6 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
|
|
|
113
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
114
|
// One face of a product: the provider around it is the app's, and this brings only its own.
|
|
115
115
|
if (cached === undefined)
|
|
116
|
-
return (_jsx(ModelDefinitions, { ...(entities === undefined ? {} : { entities }), ...(metas === undefined ? {} : { metas }), ...(events === undefined ? {} : { events }), 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 }), ...(events === undefined ? {} : { events }), children: shell }));
|
|
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 }));
|
|
118
118
|
}
|
|
@@ -2,11 +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 { DockMoment } from "@sincpro/web-ui";
|
|
5
6
|
/** Who made a record, or changed it last, and when: `Record.Audit`'s. */
|
|
6
7
|
export type Stamp = {
|
|
7
8
|
at: string;
|
|
8
9
|
by?: string;
|
|
9
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
|
+
};
|
|
10
16
|
/**
|
|
11
17
|
* What every record screen in a workspace does before drawing its own — what `EntityRecord`
|
|
12
18
|
* does, as values: read the record for editing, follow the workspace's breadcrumb, tell the
|
|
@@ -41,6 +47,15 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
|
|
|
41
47
|
/** The line under its name, the screen's way (an enrollment's course, an order's detail).
|
|
42
48
|
* Without it, or when it answers `null`, the record's type when the model has one. */
|
|
43
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;
|
|
44
59
|
/** `false`: the screen draws its own history — it is not read here. */
|
|
45
60
|
history?: boolean | undefined;
|
|
46
61
|
/** The record and its model already read on the server that renders the screen
|
|
@@ -57,16 +72,13 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
|
|
|
57
72
|
dirty?: import("@sincpro/web-ui").DirtyState | undefined;
|
|
58
73
|
placement: "page" | "card";
|
|
59
74
|
identity: {
|
|
60
|
-
tag?:
|
|
61
|
-
tone?: import("@sincpro/web-ui").Tone | undefined;
|
|
62
|
-
label: string;
|
|
63
|
-
} | undefined;
|
|
75
|
+
tag?: RecordTag | undefined;
|
|
64
76
|
subtitle?: string | undefined;
|
|
65
77
|
title: string;
|
|
66
78
|
};
|
|
67
79
|
};
|
|
68
80
|
/** `Record.Dock moment`: the application's word on the record's moment (`presented`). */
|
|
69
|
-
moment:
|
|
81
|
+
moment: DockMoment | undefined;
|
|
70
82
|
/** `Record.Pager`'s props, when it was opened from a list and nothing is typed. */
|
|
71
83
|
pager: {
|
|
72
84
|
index: number;
|
|
@@ -8,6 +8,7 @@ import { summaryFieldsOf } from "../../core/summary.js";
|
|
|
8
8
|
import { placeOf, stepIn } from "../../core/trail.js";
|
|
9
9
|
import { useFramework } from "../../react/context.js";
|
|
10
10
|
import { useHistory } from "../../react/useHistory.js";
|
|
11
|
+
import { usePeopleOf } from "../../react/usePeopleOf.js";
|
|
11
12
|
import { useRecord } from "../../react/useRecord.js";
|
|
12
13
|
import { useSummaryOf } from "../../react/useSummary.js";
|
|
13
14
|
import { presentationOf } from "../list/presentation.js";
|
|
@@ -52,7 +53,7 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
|
|
|
52
53
|
const crumbs = useCrumbs(api);
|
|
53
54
|
useRecordInWorkspace(api, reading, options);
|
|
54
55
|
const look = presentationOf(entity);
|
|
55
|
-
const
|
|
56
|
+
const read = useHistory(entity, reading.isNew || options.history === false ? "" : reading.id, [reading.record], { tones: look.facts });
|
|
56
57
|
const summarize = useSummaryOf(entity);
|
|
57
58
|
const copy = frameworkCopy().record;
|
|
58
59
|
// Opened from a list: where it stands in it, and its neighbours (`Trail`).
|
|
@@ -83,11 +84,23 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
|
|
|
83
84
|
const dirty = ready ? dirtyOf(reading) : undefined;
|
|
84
85
|
// What the application says of this record's moment — while nothing is being edited: then the
|
|
85
86
|
// pill says the unsaved changes itself.
|
|
86
|
-
const moment = ready && dirty === undefined
|
|
87
|
+
const moment = ready && dirty === undefined
|
|
88
|
+
? (options.moment?.(reading.record) ?? look.moment?.(reading.record))
|
|
89
|
+
: undefined;
|
|
87
90
|
const failure = reading.edit.failure;
|
|
88
91
|
// Who, only when the record says it (an author is optional: the line then says only when).
|
|
89
|
-
const stamp = (one) => one?.at == null
|
|
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) });
|
|
90
102
|
const created = stamp(summary?.created);
|
|
103
|
+
const ownTag = ready && !reading.isNew ? options.tag?.(reading.record) : undefined;
|
|
91
104
|
const subtitle = (ready && !reading.isNew ? options.subtitle?.(reading.record) : null) ?? summary?.type;
|
|
92
105
|
const updated = stamp(summary?.updated);
|
|
93
106
|
// Moving away with something typed would lose it: «save / discard» comes first.
|
|
@@ -109,11 +122,15 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
|
|
|
109
122
|
// A new record is «creating»; an existing one has no name until it is read.
|
|
110
123
|
title: (ready && !reading.isNew ? options.title?.(reading.record) : null) ??
|
|
111
124
|
summary?.name ??
|
|
112
|
-
(reading.isNew
|
|
125
|
+
(reading.isNew
|
|
126
|
+
? (options.creating ?? copy.creating(nameOf(reading.meta, reading.locale) || ""))
|
|
127
|
+
: ""),
|
|
113
128
|
...(subtitle == null ? {} : { subtitle }),
|
|
114
|
-
...(
|
|
115
|
-
? {}
|
|
116
|
-
:
|
|
129
|
+
...(ownTag != null
|
|
130
|
+
? { tag: ownTag }
|
|
131
|
+
: summary?.state == null
|
|
132
|
+
? {}
|
|
133
|
+
: { tag: { label: summary.state, ...(tone === undefined ? {} : { tone }) } }),
|
|
117
134
|
},
|
|
118
135
|
...(dirty === undefined ? {} : { dirty }),
|
|
119
136
|
// The refusal in words; its heading when the server said nothing more (no detail).
|
|
@@ -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.
|
|
3
|
+
"version": "3.21.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.
|
|
55
|
-
"@sincpro/criteria": "^2.
|
|
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.
|
|
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.
|
|
99
|
-
"@sincpro/criteria": "^2.
|
|
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.
|
|
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",
|