@sincpro/web-framework 2.3.0 → 2.5.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 +91 -61
- package/dist/core/cache.d.ts +19 -7
- package/dist/core/cache.js +81 -44
- package/dist/core/changes.d.ts +25 -0
- package/dist/core/changes.js +39 -0
- package/dist/core/names.d.ts +25 -0
- package/dist/core/names.js +79 -0
- package/dist/errors/index.d.ts +2 -1
- package/dist/react/context.d.ts +15 -2
- package/dist/react/context.js +11 -4
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/react/useGroups.js +4 -1
- package/dist/react/useHistory.js +4 -1
- package/dist/react/useListing.js +9 -6
- package/dist/react/useNameOf.d.ts +5 -4
- package/dist/react/useNameOf.js +25 -26
- package/dist/react/usePivot.js +4 -1
- package/dist/react/useRecord.js +10 -6
- package/dist/react/useWrites.d.ts +19 -0
- package/dist/react/useWrites.js +35 -0
- package/dist/telemetry/index.d.ts +17 -6
- package/dist/telemetry/index.js +19 -9
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/record/ActionButton.d.ts +34 -0
- package/dist/web/record/ActionButton.js +41 -0
- package/dist/web/record/CommandButton.d.ts +5 -6
- package/dist/web/record/CommandButton.js +16 -33
- package/dist/web/record/ServiceButton.d.ts +31 -0
- package/dist/web/record/ServiceButton.js +40 -0
- package/dist/web/workspace/SincproApp.d.ts +8 -2
- package/dist/web/workspace/SincproApp.js +13 -7
- package/package.json +3 -3
|
@@ -1,41 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import {} from "@sincpro/client-framework";
|
|
4
|
-
import { frameworkCopy } from "../../core/copy.js";
|
|
5
4
|
import { useCommand } from "../../react/useCommand.js";
|
|
6
|
-
import {
|
|
7
|
-
import { Button, Dialog } from "@sincpro/web-ui";
|
|
8
|
-
import { useState } from "react";
|
|
5
|
+
import { ActionButton } from "./ActionButton.js";
|
|
9
6
|
/**
|
|
10
|
-
* An entity's Command as a button.
|
|
7
|
+
* An entity's Command as a button: sent as it is, over the screens' transport.
|
|
11
8
|
*
|
|
12
|
-
* Context:
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* question. A refusal is shown where it happened, with what to do.
|
|
9
|
+
* Context: the gesture is `ActionButton`'s — run on the click, or (`destructive`) ask the
|
|
10
|
+
* server's dry run first and show what it would do; a refusal where it happened. An action that is
|
|
11
|
+
* one of the application's own use cases — logic of its own, composed, traced as
|
|
12
|
+
* `<context>/<Service>` — is a `ServiceButton`.
|
|
17
13
|
*/
|
|
18
14
|
export function CommandButton({ entity, command, id, body, label, destructive = false, role = "secondary", disabled = false, onDone, }) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
else
|
|
30
|
-
setOpen(true);
|
|
31
|
-
};
|
|
32
|
-
const ask = async () => {
|
|
33
|
-
setOpen(true);
|
|
34
|
-
await action.rehearse(id, body);
|
|
35
|
-
};
|
|
36
|
-
const close = () => {
|
|
37
|
-
setOpen(false);
|
|
38
|
-
action.reset();
|
|
39
|
-
};
|
|
40
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { size: "sm", role: destructive ? "secondary" : role, disabled: disabled || action.busy, onClick: () => void (destructive ? ask() : run()), children: label }), open ? (_jsx(Dialog, { open: true, title: label, onClose: close, footer: destructive && action.error === null ? (_jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: close, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || action.rehearsal === null, onClick: () => void run(), children: copy.confirm })] })) : undefined, children: action.error !== null ? (_jsx(Refused, { error: action.error })) : action.rehearsal === null ? (_jsx("p", { className: "text-meta text-muted", children: copy.rehearsing })) : (_jsx("p", { className: "text-ink", children: action.rehearsal.text })) })) : null] }));
|
|
15
|
+
const sending = useCommand(entity, command);
|
|
16
|
+
return (_jsx(ActionButton, { action: {
|
|
17
|
+
run: () => sending.run(id, body),
|
|
18
|
+
...(destructive ? { rehearse: () => sending.rehearse(id, body) } : {}),
|
|
19
|
+
busy: sending.busy,
|
|
20
|
+
error: sending.error,
|
|
21
|
+
rehearsal: sending.rehearsal,
|
|
22
|
+
reset: sending.reset,
|
|
23
|
+
}, label: label, role: role, disabled: disabled, ...(onDone === undefined ? {} : { onDone }) }));
|
|
41
24
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Rehearsal } from "../../react/useCommand.js";
|
|
2
|
+
/**
|
|
3
|
+
* One of the application's use cases as a button — its Feature or ApplicationService, run on its
|
|
4
|
+
* bounded context.
|
|
5
|
+
*
|
|
6
|
+
* <ServiceButton
|
|
7
|
+
* label="Cancelar"
|
|
8
|
+
* run={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id))}
|
|
9
|
+
* rehearse={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id, true))}
|
|
10
|
+
* />
|
|
11
|
+
*
|
|
12
|
+
* Context: an action of an application is a use case — its logic, its composition, its span
|
|
13
|
+
* `<context>/<Service>`, its request carrying the run's trace to the server —, never a request a
|
|
14
|
+
* screen sends; what the screen adds is the state of running it (`useService`). The gesture is
|
|
15
|
+
* `CommandButton`'s, drawn once by `ActionButton`: run on the click, off while it runs, a refusal
|
|
16
|
+
* where it happened; and an action that destroys asks first (`rehearse`, the use case run dry)
|
|
17
|
+
* and shows what it would do. What it changed, every screen hears by itself: the use case's
|
|
18
|
+
* client announces its write (`processChanges`), so `onDone` is for what only this screen does
|
|
19
|
+
* next — a toast, closing a window —, never to read again.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ServiceButton<R>({ label, run, rehearse, role, disabled, onDone, }: {
|
|
22
|
+
label: string;
|
|
23
|
+
/** The use case, executed on its bounded context. */
|
|
24
|
+
run: () => Promise<R>;
|
|
25
|
+
/** The same use case run dry — what it would do, nothing touched —, asked before `run`. */
|
|
26
|
+
rehearse?: () => Promise<Rehearsal>;
|
|
27
|
+
role?: "primary" | "secondary" | "ghost";
|
|
28
|
+
/** Not offered right now. The use case still decides. */
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
onDone?: (answer: R) => void;
|
|
31
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useService } from "../../react/useService.js";
|
|
4
|
+
import { ActionButton } from "./ActionButton.js";
|
|
5
|
+
/** What the button runs when there is no dry run: nothing. */
|
|
6
|
+
const NO_REHEARSAL = async () => undefined;
|
|
7
|
+
/**
|
|
8
|
+
* One of the application's use cases as a button — its Feature or ApplicationService, run on its
|
|
9
|
+
* bounded context.
|
|
10
|
+
*
|
|
11
|
+
* <ServiceButton
|
|
12
|
+
* label="Cancelar"
|
|
13
|
+
* run={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id))}
|
|
14
|
+
* rehearse={() => projectBoundedContext.execute(new CommandCancelIssue(issue.id, true))}
|
|
15
|
+
* />
|
|
16
|
+
*
|
|
17
|
+
* Context: an action of an application is a use case — its logic, its composition, its span
|
|
18
|
+
* `<context>/<Service>`, its request carrying the run's trace to the server —, never a request a
|
|
19
|
+
* screen sends; what the screen adds is the state of running it (`useService`). The gesture is
|
|
20
|
+
* `CommandButton`'s, drawn once by `ActionButton`: run on the click, off while it runs, a refusal
|
|
21
|
+
* where it happened; and an action that destroys asks first (`rehearse`, the use case run dry)
|
|
22
|
+
* and shows what it would do. What it changed, every screen hears by itself: the use case's
|
|
23
|
+
* client announces its write (`processChanges`), so `onDone` is for what only this screen does
|
|
24
|
+
* next — a toast, closing a window —, never to read again.
|
|
25
|
+
*/
|
|
26
|
+
export function ServiceButton({ label, run, rehearse, role = "secondary", disabled = false, onDone, }) {
|
|
27
|
+
const running = useService(run);
|
|
28
|
+
const rehearsing = useService(rehearse ?? NO_REHEARSAL);
|
|
29
|
+
return (_jsx(ActionButton, { action: {
|
|
30
|
+
run: running.run,
|
|
31
|
+
...(rehearse === undefined ? {} : { rehearse: rehearsing.run }),
|
|
32
|
+
busy: running.busy || rehearsing.busy,
|
|
33
|
+
error: running.error ?? rehearsing.error,
|
|
34
|
+
rehearsal: rehearsing.answer ?? null,
|
|
35
|
+
reset: () => {
|
|
36
|
+
running.reset();
|
|
37
|
+
rehearsing.reset();
|
|
38
|
+
},
|
|
39
|
+
}, label: label, role: role, disabled: disabled, ...(onDone === undefined ? {} : { onDone }) }));
|
|
40
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type Entity, type Transport } from "@sincpro/client-framework";
|
|
1
|
+
import { type ChangeFeed, type Entity, type Transport } from "@sincpro/client-framework";
|
|
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
5
|
import { type ReactNode } from "react";
|
|
6
|
-
export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, onViewError, }: {
|
|
6
|
+
export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, workspace: given, bar, onViewError, changes, }: {
|
|
7
7
|
transport: Transport;
|
|
8
8
|
/** The entities as composer views — `entityView(…)` — and any other view of the app. */
|
|
9
9
|
views: readonly ViewSpec[];
|
|
@@ -40,4 +40,10 @@ export declare function SincproApp({ transport, views, start, language, metas, e
|
|
|
40
40
|
* `view <ref>`; without a reporter configured, nothing is sent.
|
|
41
41
|
*/
|
|
42
42
|
onViewError?: OnViewError;
|
|
43
|
+
/**
|
|
44
|
+
* Where writes are announced — the process's (`processChanges`, @sincpro/client-framework),
|
|
45
|
+
* which every transport of the framework writes to, whoever sends: a screen, or a use case's
|
|
46
|
+
* generated client. The cache forgets what each write touches, and the screens read it again.
|
|
47
|
+
*/
|
|
48
|
+
changes?: ChangeFeed;
|
|
43
49
|
}): import("react").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { processContext, reportError, } from "@sincpro/client-framework";
|
|
3
|
+
import { processChanges, processContext, reportError, } from "@sincpro/client-framework";
|
|
4
4
|
import { Composer, installComposerCopy, SPANISH_COMPOSER_COPY, useWorkspace, } from "@sincpro/web-composer";
|
|
5
5
|
import { createRegistry, formatRef } from "@sincpro/web-composer/domain";
|
|
6
6
|
import { cachedTransport, } from "../../core/cache.js";
|
|
@@ -27,7 +27,7 @@ import { useEffect, useMemo, useState } from "react";
|
|
|
27
27
|
*/
|
|
28
28
|
/** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
|
|
29
29
|
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, }) {
|
|
30
|
+
export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
|
|
31
31
|
// Installed once, before anything draws: the three tables are module state of their packages.
|
|
32
32
|
useState(() => {
|
|
33
33
|
if (language === "es") {
|
|
@@ -46,16 +46,22 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
|
|
|
46
46
|
// The options are read once: a cache that changes shape mid-session forgets everything.
|
|
47
47
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
48
|
[transport]);
|
|
49
|
-
// What was read in one company is not the other's
|
|
50
|
-
//
|
|
49
|
+
// What was read in one company is not the other's, and what anyone wrote is no longer what was
|
|
50
|
+
// read: a change of context forgets every answer, a write what it touched — whoever wrote it, a
|
|
51
|
+
// use case's client as much as a screen — before the screens read again.
|
|
51
52
|
useEffect(() => {
|
|
52
53
|
if (cache === false)
|
|
53
54
|
return;
|
|
54
55
|
const forgetting = cached;
|
|
55
|
-
|
|
56
|
+
const unwatch = processContext.watch(() => forgetting.invalidate());
|
|
57
|
+
const unfollow = changes.follow((change) => forgetting.changed(change));
|
|
58
|
+
return () => {
|
|
59
|
+
unwatch();
|
|
60
|
+
unfollow();
|
|
61
|
+
};
|
|
56
62
|
// The cache is read once, as `cached` is.
|
|
57
63
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
-
}, [cached]);
|
|
64
|
+
}, [cached, changes]);
|
|
59
65
|
const own = useWorkspace();
|
|
60
66
|
const workspace = given ?? own;
|
|
61
67
|
const registry = useMemo(() => createRegistry(views), [views]);
|
|
@@ -65,5 +71,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
|
|
|
65
71
|
// The first screen only: a re-render must not push it again.
|
|
66
72
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
73
|
}, [workspace]);
|
|
68
|
-
return (_jsx(FrameworkProvider, { transport: cached, locale: language, ...(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 }) }) })] }) }) }));
|
|
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 }) }) })] }) }) }));
|
|
69
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-framework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.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,7 +40,7 @@
|
|
|
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": "^1.
|
|
43
|
+
"@sincpro/client-framework": "^1.10.0",
|
|
44
44
|
"@sincpro/criteria": "^2.1.0",
|
|
45
45
|
"@sincpro/criteria-react": "^2.1.0",
|
|
46
46
|
"@sincpro/web-composer": "^1.6.0",
|
|
@@ -72,7 +72,7 @@
|
|
|
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": "^1.
|
|
75
|
+
"@sincpro/client-framework": "^1.10.0",
|
|
76
76
|
"@sincpro/criteria": "^2.1.0",
|
|
77
77
|
"@sincpro/criteria-react": "^2.1.0",
|
|
78
78
|
"@sincpro/web-composer": "^1.6.0",
|