@sincpro/web-framework 3.12.1 → 3.13.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 +65 -1
- package/dist/core/cache.js +11 -0
- package/dist/core/copy.d.ts +18 -0
- package/dist/core/copy.js +21 -0
- package/dist/core/edit.d.ts +3 -0
- package/dist/core/edit.js +9 -6
- package/dist/core/files.d.ts +58 -0
- package/dist/core/files.js +57 -15
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +4 -3
- package/dist/core/present.d.ts +16 -0
- package/dist/core/present.js +41 -4
- package/dist/core/richText.d.ts +39 -0
- package/dist/core/richText.js +45 -0
- package/dist/core/summary.js +5 -1
- package/dist/errors/index.d.ts +3 -1
- package/dist/errors/index.js +14 -2
- package/dist/errors/narrowed.d.ts +2 -0
- package/dist/errors/narrowed.js +7 -0
- package/dist/errors/server.js +1 -7
- package/dist/react/context.d.ts +20 -1
- 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/useTextOf.d.ts +3 -2
- package/dist/react/useTextOf.js +4 -4
- package/dist/react/useUpload.d.ts +33 -0
- package/dist/react/useUpload.js +69 -0
- package/dist/telemetry/index.d.ts +21 -1
- package/dist/telemetry/index.js +35 -1
- package/dist/web/index.d.ts +5 -1
- package/dist/web/index.js +5 -1
- package/dist/web/record/ActionButton.d.ts +1 -1
- package/dist/web/record/ActionButton.js +7 -2
- package/dist/web/record/ask.d.ts +18 -0
- package/dist/web/record/ask.js +15 -0
- package/dist/web/record/choice.d.ts +32 -0
- package/dist/web/record/choice.js +36 -0
- package/dist/web/record/control.d.ts +4 -0
- package/dist/web/record/control.js +52 -1
- package/dist/web/record/edit.js +37 -5
- package/dist/web/record/fileControl.d.ts +22 -0
- package/dist/web/record/fileControl.js +48 -0
- package/dist/web/record/person.d.ts +23 -0
- package/dist/web/record/person.js +27 -0
- package/dist/web/record/record.js +8 -2
- package/dist/web/record/richText.d.ts +27 -0
- package/dist/web/record/richText.js +59 -0
- package/dist/web/workspace/SincproApp.d.ts +10 -1
- package/dist/web/workspace/SincproApp.js +2 -2
- package/package.json +5 -5
package/dist/core/summary.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { renditionUrl, storedFileOf } from "./files.js";
|
|
1
2
|
import { textOf } from "./present.js";
|
|
2
3
|
const CONVENTION = {
|
|
3
4
|
description: ["description", "summary"],
|
|
@@ -39,7 +40,10 @@ export function summaryOf(meta, record, options = {}) {
|
|
|
39
40
|
const shown = display === undefined
|
|
40
41
|
? (record["display_name"] ?? record["name"])
|
|
41
42
|
: textOf(meta, display, record[display], locale);
|
|
42
|
-
const
|
|
43
|
+
const held = parts.image === undefined ? null : record[parts.image];
|
|
44
|
+
// A photo is a link, or a stored picture (`Widget.IMAGE`) seen by its small rendition.
|
|
45
|
+
const stored = storedFileOf(held);
|
|
46
|
+
const image = stored === null ? held : renditionUrl(stored, "thumb");
|
|
43
47
|
return {
|
|
44
48
|
id,
|
|
45
49
|
name: shown === undefined || shown === null || shown === "" ? id : String(shown),
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -25,7 +25,9 @@ export { reportUncaught } from "./uncaught.js";
|
|
|
25
25
|
* customer: no breadcrumbs or default integrations, and every event leaves without cookies,
|
|
26
26
|
* headers, request bodies, query strings or the user's address — of the person, only their id,
|
|
27
27
|
* what GlitchTip counts «users affected» by. `beforeSend` is the
|
|
28
|
-
* application's, run after that.
|
|
28
|
+
* application's, run after that. A failure that carries a `digest` — a page that broke while
|
|
29
|
+
* drawing on the server, reported by `RouteError` — is tagged with it, as the server's report of
|
|
30
|
+
* it is (`./errors/server`): the two reports of one failure are found by the same tag.
|
|
29
31
|
*/
|
|
30
32
|
export type GlitchtipOptions = {
|
|
31
33
|
/** The application's DSN. Public by nature: it ships to the browser. */
|
package/dist/errors/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { narrowed } from "./narrowed.js";
|
|
1
|
+
import { digestOf, narrowed } from "./narrowed.js";
|
|
2
2
|
export { reportUncaught } from "./uncaught.js";
|
|
3
3
|
const WAITING_AT_MOST = 20;
|
|
4
4
|
export function glitchtipReporter(options) {
|
|
@@ -26,7 +26,19 @@ export function glitchtipReporter(options) {
|
|
|
26
26
|
},
|
|
27
27
|
});
|
|
28
28
|
client.init();
|
|
29
|
-
ready = sentryReporter(
|
|
29
|
+
ready = sentryReporter({
|
|
30
|
+
// Tagged with the page's `digest` — the server's report of the same failure has it.
|
|
31
|
+
captureException: (error, hint) => {
|
|
32
|
+
const digest = digestOf(error);
|
|
33
|
+
if (digest === undefined)
|
|
34
|
+
return client.captureException(error, hint);
|
|
35
|
+
const said = hint?.captureContext;
|
|
36
|
+
return client.captureException(error, {
|
|
37
|
+
...hint,
|
|
38
|
+
captureContext: { ...said, tags: { ...said?.tags, digest } },
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
30
42
|
for (const [error, about] of waiting.splice(0))
|
|
31
43
|
ready.report(error, about);
|
|
32
44
|
}
|
|
@@ -16,3 +16,5 @@ export type SentEvent = {
|
|
|
16
16
|
};
|
|
17
17
|
/** Every event leaves without what may carry a person's or a customer's data. */
|
|
18
18
|
export declare function narrowed(event: SentEvent): SentEvent;
|
|
19
|
+
/** The code a server-rendering framework gave a failure — Next's `digest` — when it gave one. */
|
|
20
|
+
export declare function digestOf(error: unknown): string | undefined;
|
package/dist/errors/narrowed.js
CHANGED
|
@@ -23,3 +23,10 @@ export function narrowed(event) {
|
|
|
23
23
|
request: { ...request, ...(request.url ? { url: request.url.split("?")[0] } : {}) },
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
/** The code a server-rendering framework gave a failure — Next's `digest` — when it gave one. */
|
|
27
|
+
export function digestOf(error) {
|
|
28
|
+
if (typeof error !== "object" || error === null || !("digest" in error))
|
|
29
|
+
return undefined;
|
|
30
|
+
const digest = error.digest;
|
|
31
|
+
return typeof digest === "string" && digest !== "" ? digest : undefined;
|
|
32
|
+
}
|
package/dist/errors/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { outcomeOf } from "@sincpro/client-framework";
|
|
2
|
-
import { narrowed } from "./narrowed.js";
|
|
2
|
+
import { digestOf, narrowed } from "./narrowed.js";
|
|
3
3
|
const HELD = Symbol.for("@sincpro/web-framework/errors/server");
|
|
4
4
|
const WHO = "@sincpro/web-framework/errors/server";
|
|
5
5
|
function held() {
|
|
@@ -123,12 +123,6 @@ async function started(options) {
|
|
|
123
123
|
export function serverReporter() {
|
|
124
124
|
return { report: (error, about) => held().reporter?.report(error, about) };
|
|
125
125
|
}
|
|
126
|
-
function digestOf(error) {
|
|
127
|
-
if (typeof error !== "object" || error === null || !("digest" in error))
|
|
128
|
-
return undefined;
|
|
129
|
-
const digest = error.digest;
|
|
130
|
-
return typeof digest === "string" && digest !== "" ? digest : undefined;
|
|
131
|
-
}
|
|
132
126
|
/**
|
|
133
127
|
* A request that failed on the server — a page that broke while drawing —, reported with what
|
|
134
128
|
* finds it again: its `digest`, its route, its method and path (without the query), and
|
package/dist/react/context.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type ChangeFeed, type Entity, type MetaStore, type Transport } from "@sincpro/client-framework";
|
|
2
2
|
import type { Meta } from "@sincpro/criteria";
|
|
3
|
+
import type { Uploads } from "../core/files.js";
|
|
3
4
|
import { type NameBook } from "../core/names.js";
|
|
4
5
|
import { type DateStyle } from "../core/present.js";
|
|
6
|
+
import type { RichTextSettings } from "../core/richText.js";
|
|
5
7
|
import type { Trail } from "../core/trail.js";
|
|
6
8
|
import { type ReactNode } from "react";
|
|
7
9
|
/**
|
|
@@ -52,8 +54,12 @@ type FrameworkContextValue = {
|
|
|
52
54
|
currency: string | undefined;
|
|
53
55
|
/** Each domain event's definition, by its wire name: what a history calls a fact's fields. */
|
|
54
56
|
events: Readonly<Record<string, Meta>>;
|
|
57
|
+
/** How a rich text is written and read here (`FrameworkProvider richText`). */
|
|
58
|
+
richText: RichTextSettings;
|
|
59
|
+
/** Where a file a person gives goes — the application's (`FrameworkProvider uploads`). */
|
|
60
|
+
uploads: Uploads | undefined;
|
|
55
61
|
};
|
|
56
|
-
export declare function FrameworkProvider({ transport, locale, metas: seed, entities, timeZone, dateStyle, currency, events, changes, children, }: {
|
|
62
|
+
export declare function FrameworkProvider({ transport, locale, metas: seed, entities, timeZone, dateStyle, currency, region, events, richText, uploads, changes, children, }: {
|
|
57
63
|
transport: Transport;
|
|
58
64
|
/** The language labels and values are read in (`"es"`); the model's `default` without it. */
|
|
59
65
|
locale?: string;
|
|
@@ -73,9 +79,22 @@ export declare function FrameworkProvider({ transport, locale, metas: seed, enti
|
|
|
73
79
|
/** The business's currency (`"BOB"`): an amount the model draws as money (`widget: money`)
|
|
74
80
|
* travels bare, and is written in it. Without it, rounded to cents with no symbol. */
|
|
75
81
|
currency?: string;
|
|
82
|
+
/** Where numbers and money are written as the business writes them (`"es-BO"`: «Bs 1.150,50»),
|
|
83
|
+
* apart from the language of the words (`locale`). Without it, numbers follow `locale`. */
|
|
84
|
+
region?: string;
|
|
76
85
|
/** Each domain event's definition, by its wire name — `eventMetasOf(contract)`
|
|
77
86
|
* (client-framework): a record's history names each fact's own fields in its words. */
|
|
78
87
|
events?: Readonly<Record<string, Meta>>;
|
|
88
|
+
/** How a field of formatted text (`widget: "html"`) is written and read: the editor's toolbar,
|
|
89
|
+
* the video hosts it may embed, whether the backend cleans what it stores. */
|
|
90
|
+
richText?: RichTextSettings;
|
|
91
|
+
/**
|
|
92
|
+
* Where a file a person gives goes — a record's file or image field, a picture inside a rich
|
|
93
|
+
* text: the application's Command asks the backend for an upload id, and the framework sends
|
|
94
|
+
* the bytes there with their progress (`Uploads`). Without it, a file field is read only and a
|
|
95
|
+
* rich text takes no pictures.
|
|
96
|
+
*/
|
|
97
|
+
uploads?: Uploads;
|
|
79
98
|
/** Where writes are announced — the process's (`processChanges`) unless a test gives another. */
|
|
80
99
|
changes?: ChangeFeed;
|
|
81
100
|
children: ReactNode;
|
package/dist/react/context.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { installTimeZone, metaStore, processChanges, processContext, screensTransport, } from "@sincpro/client-framework";
|
|
4
4
|
import { nameBook } from "../core/names.js";
|
|
5
|
-
import { installCurrency, installDateStyle, } from "../core/present.js";
|
|
5
|
+
import { installCurrency, installDateStyle, installRegion, } from "../core/present.js";
|
|
6
6
|
import { entityFor } from "../core/relation.js";
|
|
7
7
|
import { useContextValues } from "./useContextValues.js";
|
|
8
8
|
import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
9
9
|
const FrameworkContext = createContext(null);
|
|
10
|
-
export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, dateStyle = "numeric", currency, events = NO_EVENTS, changes = processChanges, children, }) {
|
|
10
|
+
export function FrameworkProvider({ transport, locale, metas: seed, entities = NO_ENTITIES, timeZone, dateStyle = "numeric", currency, region, events = NO_EVENTS, richText = NO_RICH_TEXT, uploads, changes = processChanges, children, }) {
|
|
11
11
|
// Installed before the children draw, and again when it changes (another company): the
|
|
12
12
|
// formatters read it, so it cannot wait for an effect.
|
|
13
13
|
const zoned = useRef(null);
|
|
@@ -33,10 +33,12 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
|
|
|
33
33
|
// Only a new language says it again.
|
|
34
34
|
useEffect(speak, [locale]);
|
|
35
35
|
const styled = useRef(null);
|
|
36
|
-
|
|
36
|
+
const style = `${dateStyle}|${currency ?? ""}|${region ?? ""}`;
|
|
37
|
+
if (styled.current !== style) {
|
|
37
38
|
installDateStyle(dateStyle);
|
|
38
39
|
installCurrency(currency);
|
|
39
|
-
|
|
40
|
+
installRegion(region);
|
|
41
|
+
styled.current = style;
|
|
40
42
|
}
|
|
41
43
|
// One store for the provider's life: a new seed object on a re-render must not forget what
|
|
42
44
|
// the screens already learned.
|
|
@@ -68,6 +70,8 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
|
|
|
68
70
|
dateStyle,
|
|
69
71
|
currency,
|
|
70
72
|
events,
|
|
73
|
+
richText,
|
|
74
|
+
uploads,
|
|
71
75
|
}), [
|
|
72
76
|
screens,
|
|
73
77
|
locale,
|
|
@@ -80,11 +84,14 @@ export function FrameworkProvider({ transport, locale, metas: seed, entities = N
|
|
|
80
84
|
dateStyle,
|
|
81
85
|
currency,
|
|
82
86
|
events,
|
|
87
|
+
richText,
|
|
88
|
+
uploads,
|
|
83
89
|
]);
|
|
84
90
|
return _jsx(FrameworkContext.Provider, { value: value, children: children });
|
|
85
91
|
}
|
|
86
92
|
const NO_ENTITIES = [];
|
|
87
93
|
const NO_EVENTS = {};
|
|
94
|
+
const NO_RICH_TEXT = {};
|
|
88
95
|
export function useFramework() {
|
|
89
96
|
const value = useContext(FrameworkContext);
|
|
90
97
|
if (value === null)
|
package/dist/react/index.d.ts
CHANGED
|
@@ -23,4 +23,5 @@ export { type ServiceState, useService } from "./useService.js";
|
|
|
23
23
|
export { type ServiceReading, useServiceReading, } from "./useServiceReading.js";
|
|
24
24
|
export { useSummaryOf } from "./useSummary.js";
|
|
25
25
|
export { useTextOf, type ValueTexts } from "./useTextOf.js";
|
|
26
|
+
export { type Upload, useUpload } from "./useUpload.js";
|
|
26
27
|
export { useWrites } from "./useWrites.js";
|
package/dist/react/index.js
CHANGED
|
@@ -23,4 +23,5 @@ export { useService } from "./useService.js";
|
|
|
23
23
|
export { useServiceReading, } from "./useServiceReading.js";
|
|
24
24
|
export { useSummaryOf } from "./useSummary.js";
|
|
25
25
|
export { useTextOf } from "./useTextOf.js";
|
|
26
|
+
export { useUpload } from "./useUpload.js";
|
|
26
27
|
export { useWrites } from "./useWrites.js";
|
|
@@ -3,14 +3,15 @@ export type ValueTexts = {
|
|
|
3
3
|
number: (value: unknown) => string | null;
|
|
4
4
|
day: (value: unknown) => string | null;
|
|
5
5
|
instant: (value: unknown) => string | null;
|
|
6
|
+
/** A money (`{ amount, currency }`), or a bare amount in the business's currency. */
|
|
6
7
|
money: (value: unknown) => string | null;
|
|
7
8
|
};
|
|
8
9
|
/**
|
|
9
|
-
* The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `
|
|
10
|
+
* The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `amountTextOf`, in the
|
|
10
11
|
* provider's locale and on the zone it installed — for what a screen of its own holds outside a
|
|
11
12
|
* model: a total it added up, a balance a use case answered.
|
|
12
13
|
*
|
|
13
14
|
* const text = useTextOf();
|
|
14
|
-
* <Stat label="Saldo" value={text.money(balance) ?? "—"} />
|
|
15
|
+
* <Stat label="Saldo" value={text.money(balance) ?? "—"} /> // { amount, currency }, or 1150.5
|
|
15
16
|
*/
|
|
16
17
|
export declare function useTextOf(): ValueTexts;
|
package/dist/react/useTextOf.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { dayTextOf, instantTextOf,
|
|
2
|
+
import { amountTextOf, dayTextOf, instantTextOf, numberTextOf, } from "../core/present.js";
|
|
3
3
|
import { useFramework } from "./context.js";
|
|
4
4
|
import { useMemo } from "react";
|
|
5
5
|
/**
|
|
6
|
-
* The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `
|
|
6
|
+
* The texts of `numberTextOf`, `dayTextOf`, `instantTextOf` and `amountTextOf`, in the
|
|
7
7
|
* provider's locale and on the zone it installed — for what a screen of its own holds outside a
|
|
8
8
|
* model: a total it added up, a balance a use case answered.
|
|
9
9
|
*
|
|
10
10
|
* const text = useTextOf();
|
|
11
|
-
* <Stat label="Saldo" value={text.money(balance) ?? "—"} />
|
|
11
|
+
* <Stat label="Saldo" value={text.money(balance) ?? "—"} /> // { amount, currency }, or 1150.5
|
|
12
12
|
*/
|
|
13
13
|
export function useTextOf() {
|
|
14
14
|
const { locale } = useFramework();
|
|
@@ -16,6 +16,6 @@ export function useTextOf() {
|
|
|
16
16
|
number: (value) => numberTextOf(value, locale),
|
|
17
17
|
day: (value) => dayTextOf(value, locale),
|
|
18
18
|
instant: (value) => instantTextOf(value, locale),
|
|
19
|
-
money: (value) =>
|
|
19
|
+
money: (value) => amountTextOf(value, locale),
|
|
20
20
|
}), [locale]);
|
|
21
21
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Published, type UploadAbout, type Uploads } from "../core/files.js";
|
|
2
|
+
/** A file on its way, as a screen draws it. */
|
|
3
|
+
export type Upload = {
|
|
4
|
+
/** Whether files can be sent here at all: the application gave `uploads`. */
|
|
5
|
+
available: boolean;
|
|
6
|
+
busy: boolean;
|
|
7
|
+
/** 0 to 1 while it goes; `null` before. */
|
|
8
|
+
progress: number | null;
|
|
9
|
+
/** Why the last one was not taken, in the copy's words; `null` when nothing failed. */
|
|
10
|
+
error: string | null;
|
|
11
|
+
/** The name of the file being sent, or the last one that failed. */
|
|
12
|
+
name: string | null;
|
|
13
|
+
/** Sends it; the answer once its bytes are there, `undefined` when it failed or was cancelled. */
|
|
14
|
+
send: (file: File) => Promise<Published | undefined>;
|
|
15
|
+
/** Stops the one on its way: nothing is said, nothing is kept. */
|
|
16
|
+
cancel: () => void;
|
|
17
|
+
/** Sends the last file again — a new link is asked for, the old one may have ended. */
|
|
18
|
+
retry: () => Promise<Published | undefined>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A file sent to where the application says (`FrameworkProvider uploads`, or `own`): its
|
|
22
|
+
* progress, a cancel and a retry, and a refusal in the copy table's words — by the backend's
|
|
23
|
+
* reason (`FILE_TOO_LARGE` and its limit, `FILE_TYPE_NOT_ALLOWED` and what it takes).
|
|
24
|
+
*
|
|
25
|
+
* const upload = useUpload({ entity: "Organo", id, field: "foto" });
|
|
26
|
+
* <DropZone onFile={(file) => void upload.send(file)} busy={upload.busy}
|
|
27
|
+
* progress={(upload.progress ?? 0) * 100} error={upload.error} onCancel={upload.cancel} />
|
|
28
|
+
*
|
|
29
|
+
* Context: the state, never the drawing — `RecordField` of a file and a rich text's pictures draw
|
|
30
|
+
* it with web-ui, a screen of its own with whatever it likes. Leaving the screen cancels what is
|
|
31
|
+
* on its way.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useUpload(about: UploadAbout, own?: Uploads): Upload;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { sendFile, uploadRefusalOf, } from "../core/files.js";
|
|
3
|
+
import { useFramework } from "./context.js";
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
/**
|
|
6
|
+
* A file sent to where the application says (`FrameworkProvider uploads`, or `own`): its
|
|
7
|
+
* progress, a cancel and a retry, and a refusal in the copy table's words — by the backend's
|
|
8
|
+
* reason (`FILE_TOO_LARGE` and its limit, `FILE_TYPE_NOT_ALLOWED` and what it takes).
|
|
9
|
+
*
|
|
10
|
+
* const upload = useUpload({ entity: "Organo", id, field: "foto" });
|
|
11
|
+
* <DropZone onFile={(file) => void upload.send(file)} busy={upload.busy}
|
|
12
|
+
* progress={(upload.progress ?? 0) * 100} error={upload.error} onCancel={upload.cancel} />
|
|
13
|
+
*
|
|
14
|
+
* Context: the state, never the drawing — `RecordField` of a file and a rich text's pictures draw
|
|
15
|
+
* it with web-ui, a screen of its own with whatever it likes. Leaving the screen cancels what is
|
|
16
|
+
* on its way.
|
|
17
|
+
*/
|
|
18
|
+
export function useUpload(about, own) {
|
|
19
|
+
const { transport, uploads: given } = useFramework();
|
|
20
|
+
const uploads = own ?? given;
|
|
21
|
+
const [state, setState] = useState({ busy: false, progress: null, error: null, name: null });
|
|
22
|
+
const running = useRef(null);
|
|
23
|
+
const last = useRef(null);
|
|
24
|
+
// The latest of what it is for: a send that starts later reads the record's id now.
|
|
25
|
+
const now = useRef({ about, uploads, transport });
|
|
26
|
+
now.current = { about, uploads, transport };
|
|
27
|
+
useEffect(() => () => running.current?.abort(), []);
|
|
28
|
+
const send = useCallback(async (file) => {
|
|
29
|
+
const { about: target, uploads: where, transport: wire } = now.current;
|
|
30
|
+
if (where === undefined)
|
|
31
|
+
return undefined;
|
|
32
|
+
running.current?.abort();
|
|
33
|
+
const control = new AbortController();
|
|
34
|
+
running.current = control;
|
|
35
|
+
last.current = file;
|
|
36
|
+
setState({ busy: true, progress: 0, error: null, name: file.name });
|
|
37
|
+
try {
|
|
38
|
+
const published = await sendFile(wire, where, file, target, {
|
|
39
|
+
signal: control.signal,
|
|
40
|
+
onProgress: (fraction) => !control.signal.aborted &&
|
|
41
|
+
setState((was) => ({ ...was, progress: Math.min(1, Math.max(0, fraction)) })),
|
|
42
|
+
});
|
|
43
|
+
if (control.signal.aborted)
|
|
44
|
+
return undefined;
|
|
45
|
+
setState({ busy: false, progress: null, error: null, name: null });
|
|
46
|
+
return published;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// Cancelled is not a failure: nothing is said.
|
|
50
|
+
if (control.signal.aborted)
|
|
51
|
+
setState({ busy: false, progress: null, error: null, name: null });
|
|
52
|
+
else
|
|
53
|
+
setState({
|
|
54
|
+
busy: false,
|
|
55
|
+
progress: null,
|
|
56
|
+
error: uploadRefusalOf(error),
|
|
57
|
+
name: file.name,
|
|
58
|
+
});
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
if (running.current === control)
|
|
63
|
+
running.current = null;
|
|
64
|
+
}
|
|
65
|
+
}, []);
|
|
66
|
+
const cancel = useCallback(() => running.current?.abort(), []);
|
|
67
|
+
const retry = useCallback(() => (last.current === null ? Promise.resolve(undefined) : send(last.current)), [send]);
|
|
68
|
+
return { available: uploads !== undefined, ...state, send, cancel, retry };
|
|
69
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Attributes, type Tracer } from "@sincpro/client-framework";
|
|
1
|
+
import { type Attributes, type Span, type Tracer } from "@sincpro/client-framework";
|
|
2
2
|
/**
|
|
3
3
|
* A `Tracer` for the browser, built from the application's own settings: OpenTelemetry's SDK
|
|
4
4
|
* exporting OTLP/HTTP to the endpoint the application names.
|
|
@@ -51,7 +51,27 @@ export type BrowserTracerOptions = {
|
|
|
51
51
|
* as client-framework's (`openTelemetryTracer`'s `recordExceptions`, 2.6+; older ignore it).
|
|
52
52
|
*/
|
|
53
53
|
recordExceptions?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* The page's first use case continues the trace of the server that drew the page, when the
|
|
56
|
+
* page carries it (`<meta name="traceparent" content="00-…">`, which Next writes with
|
|
57
|
+
* `experimental.clientTraceMetadata`): its span is a child of the render's, one trace from the
|
|
58
|
+
* request to the first read the browser made. Only the first root span — what the page did
|
|
59
|
+
* while waking up —; what a person does later starts traces of its own, as OpenTelemetry's
|
|
60
|
+
* document-load instrumentation does. Default `false`.
|
|
61
|
+
*
|
|
62
|
+
* Never on a cached page (ISR, a static export, a CDN's copy): its meta was written once, so
|
|
63
|
+
* every visitor would continue the same trace, long over. Write the meta on dynamic pages only
|
|
64
|
+
* (Next writes it on dynamic renders only), and leave this off where that cannot be told.
|
|
65
|
+
*/
|
|
66
|
+
continueServerTrace?: boolean;
|
|
54
67
|
};
|
|
68
|
+
/** The W3C `traceparent` a page was drawn under, read once from its `<meta>`; `undefined` when
|
|
69
|
+
* the page carries none, or one that is not a valid sampled-or-not trace context. */
|
|
70
|
+
export declare function serverTraceOf(document?: {
|
|
71
|
+
querySelector(selector: string): {
|
|
72
|
+
getAttribute(name: string): string | null;
|
|
73
|
+
} | null;
|
|
74
|
+
} | undefined): Span | undefined;
|
|
55
75
|
export type BrowserTracer = Tracer & {
|
|
56
76
|
/** Sends what is buffered now. Called by itself when the page is hidden or left. */
|
|
57
77
|
flush: () => Promise<void>;
|
package/dist/telemetry/index.js
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import { identityOf, } from "@sincpro/client-framework";
|
|
2
|
+
/** The W3C `traceparent` a page was drawn under, read once from its `<meta>`; `undefined` when
|
|
3
|
+
* the page carries none, or one that is not a valid sampled-or-not trace context. */
|
|
4
|
+
export function serverTraceOf(document = globalThis.document) {
|
|
5
|
+
const content = document
|
|
6
|
+
?.querySelector('meta[name="traceparent"]')
|
|
7
|
+
?.getAttribute("content")
|
|
8
|
+
?.trim();
|
|
9
|
+
const parts = content === undefined
|
|
10
|
+
? null
|
|
11
|
+
: /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/.exec(content);
|
|
12
|
+
if (parts === null)
|
|
13
|
+
return undefined;
|
|
14
|
+
const [, traceId = "", spanId = "", flags = "00"] = parts;
|
|
15
|
+
// All zeros is no trace (W3C trace-context §3.2.2.3).
|
|
16
|
+
if (/^0+$/.test(traceId) || /^0+$/.test(spanId))
|
|
17
|
+
return undefined;
|
|
18
|
+
return {
|
|
19
|
+
traceId,
|
|
20
|
+
spanId,
|
|
21
|
+
sampled: (Number.parseInt(flags, 16) & 1) === 1,
|
|
22
|
+
set: () => undefined,
|
|
23
|
+
end: () => undefined,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
2
26
|
const SILENT = {
|
|
3
27
|
traceId: "",
|
|
4
28
|
spanId: "",
|
|
@@ -60,8 +84,18 @@ export function browserTracer(options) {
|
|
|
60
84
|
console.warn("@sincpro/web-framework/telemetry: tracing is off — OpenTelemetry's SDK did not load", error);
|
|
61
85
|
}
|
|
62
86
|
})();
|
|
87
|
+
// The server's trace, continued once: by the first root span recorded.
|
|
88
|
+
let server = options.continueServerTrace === true ? serverTraceOf() : undefined;
|
|
63
89
|
return {
|
|
64
|
-
start: (name, startOptions) =>
|
|
90
|
+
start: (name, startOptions) => {
|
|
91
|
+
if (ready === null)
|
|
92
|
+
return SILENT;
|
|
93
|
+
if (server === undefined || startOptions.parent !== undefined)
|
|
94
|
+
return ready.start(name, startOptions);
|
|
95
|
+
const parent = server;
|
|
96
|
+
server = undefined;
|
|
97
|
+
return ready.start(name, { ...startOptions, parent });
|
|
98
|
+
},
|
|
65
99
|
flush: () => flush(),
|
|
66
100
|
};
|
|
67
101
|
}
|
package/dist/web/index.d.ts
CHANGED
|
@@ -15,18 +15,22 @@ export { type Choice, type Chooser, findChoices, type FrameworkReads, modelLoade
|
|
|
15
15
|
export { type RowCommand, type RowCommands, useRowCommands, } from "./list/rowCommands.js";
|
|
16
16
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
17
17
|
export { type ActionDialog, type Asked, } from "./record/ActionButton.js";
|
|
18
|
-
export { type AskedField, type AskField, type AskForm, askFormOf, } from "./record/ask.js";
|
|
18
|
+
export { type AskedField, type AskField, type AskForm, askFormOf, unansweredOf, } from "./record/ask.js";
|
|
19
|
+
export { ChoiceTag, type ChoiceTagLook, choiceTagOf, } from "./record/choice.js";
|
|
19
20
|
export { type CommandActionProps, CommandButton, useCommandAction, } from "./record/CommandButton.js";
|
|
20
21
|
export { RelationPicker } from "./record/control.js";
|
|
21
22
|
export { type ActionLook, type DockedAction } from "./record/dock.js";
|
|
22
23
|
export { dirtyOf, type FieldControl, RecordField, } from "./record/edit.js";
|
|
23
24
|
export { EntityPicker } from "./record/EntityPicker.js";
|
|
24
25
|
export { EntityTags } from "./record/EntityTags.js";
|
|
26
|
+
export { FileControl } from "./record/fileControl.js";
|
|
25
27
|
export { type LineColumn, type LineControl, type LinesLook, RecordLinesEditor, } from "./record/lines.js";
|
|
26
28
|
export { type RecordOpening, RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
29
|
+
export { isPersonEntity, PersonValue } from "./record/person.js";
|
|
27
30
|
export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
|
|
28
31
|
export { type LifecycleDone, RecordLifecycle, useRecordLifecycleActions, } from "./record/RecordLifecycle.js";
|
|
29
32
|
export { RelatedList } from "./record/RelatedList.js";
|
|
33
|
+
export { RichTextControl, richTextControl, RichTextFact, } from "./record/richText.js";
|
|
30
34
|
export { type ServiceActionProps, ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
|
|
31
35
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
32
36
|
export { Refused } from "./Refused.js";
|
package/dist/web/index.js
CHANGED
|
@@ -15,18 +15,22 @@ export { findChoices, modelLoader, recordsBrowser, RecordsBrowserProvider, recor
|
|
|
15
15
|
export { useRowCommands, } from "./list/rowCommands.js";
|
|
16
16
|
export { facetsOf, modelOf } from "./list/search.js";
|
|
17
17
|
export {} from "./record/ActionButton.js";
|
|
18
|
-
export { askFormOf, } from "./record/ask.js";
|
|
18
|
+
export { askFormOf, unansweredOf, } from "./record/ask.js";
|
|
19
|
+
export { ChoiceTag, choiceTagOf, } from "./record/choice.js";
|
|
19
20
|
export { CommandButton, useCommandAction, } from "./record/CommandButton.js";
|
|
20
21
|
export { RelationPicker } from "./record/control.js";
|
|
21
22
|
export {} from "./record/dock.js";
|
|
22
23
|
export { dirtyOf, RecordField, } from "./record/edit.js";
|
|
23
24
|
export { EntityPicker } from "./record/EntityPicker.js";
|
|
24
25
|
export { EntityTags } from "./record/EntityTags.js";
|
|
26
|
+
export { FileControl } from "./record/fileControl.js";
|
|
25
27
|
export { RecordLinesEditor, } from "./record/lines.js";
|
|
26
28
|
export { RecordOpeningProvider, useRecordOpening, } from "./record/opening.js";
|
|
29
|
+
export { isPersonEntity, PersonValue } from "./record/person.js";
|
|
27
30
|
export { countOf, factsOf, RecordLines, usePartLook, } from "./record/record.js";
|
|
28
31
|
export { RecordLifecycle, useRecordLifecycleActions, } from "./record/RecordLifecycle.js";
|
|
29
32
|
export { RelatedList } from "./record/RelatedList.js";
|
|
33
|
+
export { RichTextControl, richTextControl, RichTextFact, } from "./record/richText.js";
|
|
30
34
|
export { ServiceButton, useServiceAction, } from "./record/ServiceButton.js";
|
|
31
35
|
export { cardOf, relationOf } from "./record/summary.js";
|
|
32
36
|
export { Refused } from "./Refused.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Rehearsal } from "../../react/useCommand.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type AskForm } from "./ask.js";
|
|
3
3
|
import { type ReactNode } from "react";
|
|
4
4
|
/** What a person filled in before the action runs, by field name. */
|
|
5
5
|
export type Asked = Readonly<Record<string, unknown>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { frameworkCopy } from "../../core/copy.js";
|
|
4
|
+
import { unansweredOf } from "./ask.js";
|
|
4
5
|
import { Refused } from "../Refused.js";
|
|
5
6
|
import { Button, Dialog, Field, FormSection } from "@sincpro/web-ui";
|
|
6
7
|
import { useState } from "react";
|
|
@@ -19,7 +20,11 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
|
|
|
19
20
|
const copy = frameworkCopy().command;
|
|
20
21
|
const [values, setValues] = useState(() => ({ ...form.initial }));
|
|
21
22
|
const rehearsing = action.rehearse !== undefined;
|
|
23
|
+
// A required answer left empty keeps it from running — the server would only refuse it.
|
|
24
|
+
const unanswered = unansweredOf(form, values);
|
|
22
25
|
const confirm = async () => {
|
|
26
|
+
if (unanswered.length > 0)
|
|
27
|
+
return;
|
|
23
28
|
if (rehearsing && action.rehearsal === null) {
|
|
24
29
|
await action.rehearse?.(values);
|
|
25
30
|
return;
|
|
@@ -28,7 +33,7 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
|
|
|
28
33
|
if (answer !== undefined)
|
|
29
34
|
onDone(answer);
|
|
30
35
|
};
|
|
31
|
-
return (_jsxs(Dialog, { open: true, ...words, onClose: onClose, footer: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
|
|
36
|
+
return (_jsxs(Dialog, { open: true, ...words, onClose: onClose, footer: _jsxs("div", { className: "flex items-center justify-end gap-2", children: [unanswered.length === 0 ? null : (_jsx("p", { className: "mr-auto text-meta text-muted", children: frameworkCopy().record.missing(unanswered) })), _jsx(Button, { size: "sm", role: "secondary", onClick: onClose, children: copy.cancel }), _jsx(Button, { size: "sm", role: "primary", disabled: action.busy || unanswered.length > 0, onClick: () => void confirm(), children: rehearsing && action.rehearsal !== null ? copy.confirm : copy.send })] }), children: [action.error === null ? null : _jsx(Refused, { error: action.error }), _jsx(FormSection, { children: form.fields.map((field) => {
|
|
32
37
|
const control = {
|
|
33
38
|
value: values[field.name],
|
|
34
39
|
set: (next) => {
|
|
@@ -43,7 +48,7 @@ function AskDialog({ action, form, words, onClose, onDone, }) {
|
|
|
43
48
|
};
|
|
44
49
|
// A control that names itself is not wrapped in a `Field` (its name would double):
|
|
45
50
|
// what is expected goes under it.
|
|
46
|
-
return field.labelled ? (_jsxs("div", { className: "flex flex-col gap-1", children: [field.draw(control), field.hint === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: field.hint }))] }, field.name)) : (_jsx(Field, { label: field.label, ...(field.hint === undefined ? {} : { hint: field.hint }), children: field.draw(control) }, field.name));
|
|
51
|
+
return field.labelled ? (_jsxs("div", { className: "flex flex-col gap-1", children: [field.draw(control), field.hint === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: field.hint }))] }, field.name)) : (_jsx(Field, { label: field.label, required: field.required, ...(field.hint === undefined ? {} : { hint: field.hint }), children: field.draw(control) }, field.name));
|
|
47
52
|
}) }), action.rehearsal === null ? null : _jsx("p", { className: "text-ink", children: action.rehearsal.text })] }));
|
|
48
53
|
}
|
|
49
54
|
/**
|
package/dist/web/record/ask.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import type { ReactNode } from "react";
|
|
|
11
11
|
* label="Delegar áreas…" ask={["areas"]} />
|
|
12
12
|
* ask={[{ name: "motivo", label: "Motivo", widget: "textarea" }]}
|
|
13
13
|
* ask={[{ name: "role", label: "Rol", choices: ROLES, initial: "member", hint: "Lo que podrá hacer" }]}
|
|
14
|
+
* ask={[{ name: "observacion", label: "Motivo", widget: "textarea", required: true }]}
|
|
14
15
|
*
|
|
15
16
|
* Context: a Command that needs input could not live among a record's actions, so a screen drew
|
|
16
17
|
* its fields in the record's body with a button of their own. What the dialog shows is the
|
|
@@ -20,6 +21,11 @@ import type { ReactNode } from "react";
|
|
|
20
21
|
* hint, `{ name: "motivo", label, widget }` a field the entity lacks. A control of the
|
|
21
22
|
* application's goes in with `as`, never a widget named in a string (`widget` takes only the
|
|
22
23
|
* framework's own).
|
|
24
|
+
*
|
|
25
|
+
* A required answer (`required`, or a field the model marks required) keeps «Confirmar» off
|
|
26
|
+
* until it is given, and the dialog says what is missing: a reason left empty used to reach the
|
|
27
|
+
* server only to be refused (422). Only the presence is checked here — how long or what shape an
|
|
28
|
+
* answer must have is the use case's rule, and its refusal lands on the field.
|
|
23
29
|
*/
|
|
24
30
|
export type AskField = string | {
|
|
25
31
|
name: string;
|
|
@@ -42,6 +48,9 @@ export type AskField = string | {
|
|
|
42
48
|
initial?: unknown;
|
|
43
49
|
/** What is expected, said by the field — over the backend's own help for it. */
|
|
44
50
|
hint?: string;
|
|
51
|
+
/** It must be answered before the action runs — over the model's `required` for a field of
|
|
52
|
+
* the entity. «Confirmar» stays off while it is empty. */
|
|
53
|
+
required?: boolean;
|
|
45
54
|
};
|
|
46
55
|
/** A field ready to draw: its name, its label, its control. */
|
|
47
56
|
export type AskedField = {
|
|
@@ -49,6 +58,8 @@ export type AskedField = {
|
|
|
49
58
|
label: string;
|
|
50
59
|
/** What is expected — the action's hint, or the model's help for the field. */
|
|
51
60
|
hint?: string | undefined;
|
|
61
|
+
/** It must be answered before the action runs. */
|
|
62
|
+
required: boolean;
|
|
52
63
|
/** It draws its own label — a yes/no, a list of checks —: not wrapped in a `Field`. */
|
|
53
64
|
labelled: boolean;
|
|
54
65
|
draw: (control: FieldControl) => ReactNode;
|
|
@@ -70,3 +81,10 @@ export declare function askFormOf(fields: readonly AskField[], options: {
|
|
|
70
81
|
/** The declared entity a relation points at, to choose it with its picker. */
|
|
71
82
|
entityFor?: (target: string) => Entity | undefined;
|
|
72
83
|
}): AskForm;
|
|
84
|
+
/**
|
|
85
|
+
* The labels of the required answers still empty, in the order they are asked: what keeps an
|
|
86
|
+
* action from running, as the dialog says it.
|
|
87
|
+
*
|
|
88
|
+
* unansweredOf(form, { observacion: "" }) -> ["Motivo"]
|
|
89
|
+
*/
|
|
90
|
+
export declare function unansweredOf(form: AskForm, values: Readonly<Record<string, unknown>>): string[];
|
package/dist/web/record/ask.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { choicesOf } from "@sincpro/criteria";
|
|
4
|
+
import { isEmptyValue } from "../../core/edit.js";
|
|
4
5
|
import { fieldMetaOf, viewOf } from "../../core/present.js";
|
|
5
6
|
import { relationFieldOf } from "../../core/relation.js";
|
|
6
7
|
import { controlFor, RelationPicker, } from "./control.js";
|
|
@@ -41,10 +42,13 @@ export function askFormOf(fields, options) {
|
|
|
41
42
|
const widget = said.widget ?? field?.widget;
|
|
42
43
|
const label = said.label ?? view?.label ?? said.name;
|
|
43
44
|
const hint = said.hint ?? view?.help;
|
|
45
|
+
// The model's fixed `required` only: a `required_when` speaks of the record's form.
|
|
46
|
+
const required = said.required ?? field?.required === true;
|
|
44
47
|
asked.push({
|
|
45
48
|
name,
|
|
46
49
|
label,
|
|
47
50
|
hint,
|
|
51
|
+
required,
|
|
48
52
|
labelled: said.as === undefined && target === undefined && labels(type, [...choices]),
|
|
49
53
|
draw: said.as ??
|
|
50
54
|
(target === undefined
|
|
@@ -61,3 +65,14 @@ export function askFormOf(fields, options) {
|
|
|
61
65
|
}
|
|
62
66
|
return { fields: asked, initial };
|
|
63
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* The labels of the required answers still empty, in the order they are asked: what keeps an
|
|
70
|
+
* action from running, as the dialog says it.
|
|
71
|
+
*
|
|
72
|
+
* unansweredOf(form, { observacion: "" }) -> ["Motivo"]
|
|
73
|
+
*/
|
|
74
|
+
export function unansweredOf(form, values) {
|
|
75
|
+
return form.fields
|
|
76
|
+
.filter((one) => one.required && isEmptyValue(values[one.name]))
|
|
77
|
+
.map((one) => one.label);
|
|
78
|
+
}
|