@sincpro/web-framework 3.12.0 → 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.
Files changed (54) hide show
  1. package/README.md +65 -1
  2. package/dist/core/cache.js +11 -0
  3. package/dist/core/copy.d.ts +18 -0
  4. package/dist/core/copy.js +21 -0
  5. package/dist/core/edit.d.ts +3 -0
  6. package/dist/core/edit.js +9 -6
  7. package/dist/core/files.d.ts +58 -0
  8. package/dist/core/files.js +57 -15
  9. package/dist/core/index.d.ts +4 -3
  10. package/dist/core/index.js +4 -3
  11. package/dist/core/list.d.ts +9 -0
  12. package/dist/core/present.d.ts +16 -0
  13. package/dist/core/present.js +41 -4
  14. package/dist/core/richText.d.ts +39 -0
  15. package/dist/core/richText.js +45 -0
  16. package/dist/core/summary.js +5 -1
  17. package/dist/errors/index.d.ts +3 -1
  18. package/dist/errors/index.js +14 -2
  19. package/dist/errors/narrowed.d.ts +2 -0
  20. package/dist/errors/narrowed.js +7 -0
  21. package/dist/errors/server.js +1 -7
  22. package/dist/react/context.d.ts +20 -1
  23. package/dist/react/context.js +11 -4
  24. package/dist/react/index.d.ts +1 -0
  25. package/dist/react/index.js +1 -0
  26. package/dist/react/useTextOf.d.ts +3 -2
  27. package/dist/react/useTextOf.js +4 -4
  28. package/dist/react/useUpload.d.ts +33 -0
  29. package/dist/react/useUpload.js +69 -0
  30. package/dist/telemetry/index.d.ts +21 -1
  31. package/dist/telemetry/index.js +35 -1
  32. package/dist/web/index.d.ts +5 -1
  33. package/dist/web/index.js +5 -1
  34. package/dist/web/list/EntitySearchBar.d.ts +5 -2
  35. package/dist/web/list/EntitySearchBar.js +43 -12
  36. package/dist/web/record/ActionButton.d.ts +1 -1
  37. package/dist/web/record/ActionButton.js +7 -2
  38. package/dist/web/record/ask.d.ts +18 -0
  39. package/dist/web/record/ask.js +15 -0
  40. package/dist/web/record/choice.d.ts +32 -0
  41. package/dist/web/record/choice.js +36 -0
  42. package/dist/web/record/control.d.ts +4 -0
  43. package/dist/web/record/control.js +52 -1
  44. package/dist/web/record/edit.js +37 -5
  45. package/dist/web/record/fileControl.d.ts +22 -0
  46. package/dist/web/record/fileControl.js +48 -0
  47. package/dist/web/record/person.d.ts +23 -0
  48. package/dist/web/record/person.js +27 -0
  49. package/dist/web/record/record.js +8 -2
  50. package/dist/web/record/richText.d.ts +27 -0
  51. package/dist/web/record/richText.js +59 -0
  52. package/dist/web/workspace/SincproApp.d.ts +10 -1
  53. package/dist/web/workspace/SincproApp.js +2 -2
  54. package/package.json +5 -5
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A field of formatted text — a notice's body, an article, the notes of an order: HTML in, HTML
3
+ * out. The model says so with the widget `html` (sincpro_framework's `Widget.HTML`,
4
+ * Sincpro-SRL/sincpro_framework#371; until it ships, `presentation(widgets={o.body: "html"})`).
5
+ *
6
+ * holdsRichText(meta.fields.cuerpo) -> true
7
+ * richTextPlainOf("<p>Hola <b>Ana</b></p>") -> "Hola Ana"
8
+ *
9
+ * Context: an application passed its own `RichTextInput` with `as` on every screen, and read it
10
+ * with its own sanitised `RichTextValue`. Drawn by its widget it is web-ui's editor when written
11
+ * and the cleaned HTML when read — and its plain words where a cell has one line.
12
+ */
13
+ /** The widget of a field whose value is HTML. */
14
+ export const RICH_TEXT_WIDGET = "html";
15
+ /** Whether a field holds formatted text — drawn by its widget. */
16
+ export function holdsRichText(field) {
17
+ return field?.widget === RICH_TEXT_WIDGET;
18
+ }
19
+ const ENTITIES = {
20
+ amp: "&",
21
+ lt: "<",
22
+ gt: ">",
23
+ quot: '"',
24
+ apos: "'",
25
+ nbsp: " ",
26
+ };
27
+ /**
28
+ * The words of an HTML value, for a place of one line — a list's cell, a chip, a search: tags
29
+ * dropped, a block's end a space, the usual entities read. Text, never HTML: what draws it
30
+ * escapes it.
31
+ */
32
+ export function richTextPlainOf(html) {
33
+ return html
34
+ .replace(/<(?:br|\/p|\/div|\/li|\/h[1-6]|\/tr|\/blockquote)\b[^>]*>/giu, " ")
35
+ .replace(/<[^>]*>/gu, "")
36
+ .replace(/&(#\d+|#x[0-9a-f]+|[a-z]+);/giu, (whole, name) => {
37
+ if (name.startsWith("#x") || name.startsWith("#X"))
38
+ return String.fromCodePoint(Number.parseInt(name.slice(2), 16));
39
+ if (name.startsWith("#"))
40
+ return String.fromCodePoint(Number.parseInt(name.slice(1), 10));
41
+ return ENTITIES[name.toLowerCase()] ?? whole;
42
+ })
43
+ .replace(/\s+/gu, " ")
44
+ .trim();
45
+ }
@@ -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 image = parts.image === undefined ? null : record[parts.image];
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),
@@ -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. */
@@ -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(client);
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;
@@ -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
+ }
@@ -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
@@ -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;
@@ -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
- if (styled.current !== `${dateStyle}|${currency ?? ""}`) {
36
+ const style = `${dateStyle}|${currency ?? ""}|${region ?? ""}`;
37
+ if (styled.current !== style) {
37
38
  installDateStyle(dateStyle);
38
39
  installCurrency(currency);
39
- styled.current = `${dateStyle}|${currency ?? ""}`;
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)
@@ -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";
@@ -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 `moneyTextOf`, in the
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;
@@ -1,14 +1,14 @@
1
1
  "use client";
2
- import { dayTextOf, instantTextOf, moneyTextOf, numberTextOf, } from "../core/present.js";
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 `moneyTextOf`, in the
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) => moneyTextOf(value, locale),
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>;
@@ -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) => ready === null ? SILENT : ready.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
  }
@@ -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";
@@ -24,11 +24,14 @@ import type { Listing } from "../../react/useListing.js";
24
24
  * what opens outside one cannot be used;
25
25
  * - the builder walks relations — «Cliente › País» — through the models along the path
26
26
  * (`useLoadModel`), and picks the related records themselves;
27
- * - a named filter is one click; the builder writes what nobody foresaw (all/any/not);
27
+ * - a named filter is one click; the ones of one `group` add up in one chip («Pedidos o
28
+ * Trabajando»), as Odoo's; the builder writes what nobody foresaw (all/any/not);
28
29
  * - everything put becomes ONE `selection` the SERVER answers (`listing.filter`) — web-ui
29
30
  * writes it in criteria's own shape, a filter through a relation included;
30
31
  * - with `groups`, «Group by» offers the fields the model says may split the set, and the
31
- * SERVER counts the groups (`useGroups`).
32
+ * SERVER counts the groups (`useGroups`); how the set is grouped is a facet of the bar too
33
+ * («⧉ Estado › Creado el · mes ×»), so a grouped list never looks ungrouped, and removing
34
+ * the chip ungroups it.
32
35
  *
33
36
  * <List.Search><EntitySearchBar listing={listing} filters={…} /></List.Search>
34
37
  */