@sincpro/web-framework 3.12.1 → 3.14.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 (56) hide show
  1. package/README.md +65 -1
  2. package/dist/core/cache.js +11 -0
  3. package/dist/core/copy.d.ts +20 -0
  4. package/dist/core/copy.js +23 -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 +5 -3
  10. package/dist/core/index.js +5 -3
  11. package/dist/core/present.d.ts +16 -0
  12. package/dist/core/present.js +41 -4
  13. package/dist/core/reorder.d.ts +59 -0
  14. package/dist/core/reorder.js +106 -0
  15. package/dist/core/richText.d.ts +39 -0
  16. package/dist/core/richText.js +45 -0
  17. package/dist/core/summary.js +5 -1
  18. package/dist/errors/index.d.ts +3 -1
  19. package/dist/errors/index.js +14 -2
  20. package/dist/errors/narrowed.d.ts +2 -0
  21. package/dist/errors/narrowed.js +7 -0
  22. package/dist/errors/server.js +1 -7
  23. package/dist/react/context.d.ts +20 -1
  24. package/dist/react/context.js +11 -4
  25. package/dist/react/index.d.ts +1 -0
  26. package/dist/react/index.js +1 -0
  27. package/dist/react/useTextOf.d.ts +3 -2
  28. package/dist/react/useTextOf.js +4 -4
  29. package/dist/react/useUpload.d.ts +33 -0
  30. package/dist/react/useUpload.js +69 -0
  31. package/dist/telemetry/index.d.ts +21 -1
  32. package/dist/telemetry/index.js +35 -1
  33. package/dist/web/index.d.ts +6 -1
  34. package/dist/web/index.js +6 -1
  35. package/dist/web/list/EntityList.js +11 -5
  36. package/dist/web/list/reorder.d.ts +31 -0
  37. package/dist/web/list/reorder.js +67 -0
  38. package/dist/web/record/ActionButton.d.ts +1 -1
  39. package/dist/web/record/ActionButton.js +7 -2
  40. package/dist/web/record/ask.d.ts +18 -0
  41. package/dist/web/record/ask.js +15 -0
  42. package/dist/web/record/choice.d.ts +32 -0
  43. package/dist/web/record/choice.js +36 -0
  44. package/dist/web/record/control.d.ts +4 -0
  45. package/dist/web/record/control.js +52 -1
  46. package/dist/web/record/edit.js +37 -5
  47. package/dist/web/record/fileControl.d.ts +22 -0
  48. package/dist/web/record/fileControl.js +48 -0
  49. package/dist/web/record/person.d.ts +23 -0
  50. package/dist/web/record/person.js +27 -0
  51. package/dist/web/record/record.js +8 -2
  52. package/dist/web/record/richText.d.ts +27 -0
  53. package/dist/web/record/richText.js +59 -0
  54. package/dist/web/workspace/SincproApp.d.ts +10 -1
  55. package/dist/web/workspace/SincproApp.js +2 -2
  56. package/package.json +5 -5
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useUpload } from "../../react/useUpload.js";
4
+ import { attachmentOf } from "../files.js";
5
+ import { DropZone, FileValue } from "@sincpro/web-ui";
6
+ import { useRef, useState } from "react";
7
+ /**
8
+ * A record's file or picture, given by a person: what it holds now — its picture or its kind,
9
+ * the name it was sent with —, and the zone that takes another — dropped, pasted or chosen —, its
10
+ * bytes sent where the application says (`uploads`) with their progress, a cancel, a retry, and a
11
+ * refusal in the copy's words by the backend's reason.
12
+ *
13
+ * Context: an application saved the record first, then uploaded through a picker of its own.
14
+ * sincpro_framework takes no file inside a Command (#364): its Command asks for an upload id, the
15
+ * bytes go there (`uploadTo`), and the save names it. Once the bytes are there the field holds
16
+ * what the application answered (`Published.value`: the id the save's Command names), and the
17
+ * record is dirty as with any field; when it answered none, the backend already put the file in
18
+ * the record, and `onKept` reads it again.
19
+ */
20
+ export function FileControl({ control, image = false, onKept, }) {
21
+ const upload = useUpload(control.about ?? { entity: "", id: null, field: control.label });
22
+ // The file just sent, shown by its name while the field holds what it answered — until the
23
+ // record holds it as a stored file, or the edit is discarded.
24
+ const [sent, setSent] = useState(null);
25
+ const stored = attachmentOf(control.value);
26
+ const shown = stored ??
27
+ (sent !== null && (sent.value === undefined || sent.value === control.value)
28
+ ? sent.file
29
+ : null);
30
+ const last = useRef(null);
31
+ const take = async (file) => {
32
+ last.current = file;
33
+ const published = await upload.send(file);
34
+ if (published === undefined)
35
+ return;
36
+ setSent({
37
+ file: { id: file.name, name: file.name, type: file.type, size: file.size },
38
+ value: published.value,
39
+ });
40
+ if (onKept !== undefined)
41
+ onKept(published);
42
+ else if (published.value !== undefined)
43
+ control.set(published.value);
44
+ };
45
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [shown === null ? null : _jsx(FileValue, { file: shown, size: "md" }), control.readonly || !upload.available ? null : (_jsx(DropZone, { onFile: (file) => void take(file), ...(image ? { accept: "image/*" } : {}), busy: upload.busy, progress: Math.round((upload.progress ?? 0) * 100), ...(upload.name === null ? {} : { fileName: upload.name }), error: upload.error, onCancel: upload.cancel,
46
+ // Again through `take`: the field takes what the new link answers.
47
+ onRetry: () => (last.current === null ? undefined : void take(last.current)), invalid: control.invalid || upload.error !== null }))] }));
48
+ }
@@ -0,0 +1,23 @@
1
+ import type { Entity } from "@sincpro/client-framework";
2
+ import type { AnyRecord } from "@sincpro/criteria";
3
+ import type { RecordOpening } from "./opening.js";
4
+ /** Whether a relation's records are people (or companies): `entity(…, { summary: { person } })`. */
5
+ export declare function isPersonEntity(entity: Entity | undefined): boolean;
6
+ /**
7
+ * A relation to a person, read: their face — the photo the record holds, else their initials —
8
+ * and their name; pressed, the card that opens their record where the view says. With no place
9
+ * to open it, the face and the name alone: a chip that leads nowhere is not a button.
10
+ *
11
+ * Context: pickers already chose a person by their face, but once chosen a record read them as
12
+ * a plain link, so every application wrote its own chip. web-ui's `UserChip` is the same face
13
+ * and name its audit and attachments draw. The photo comes with the record held beside the key;
14
+ * a key alone (`EntityID`) is named by key and drawn with the initials.
15
+ */
16
+ export declare function PersonValue({ target, id, name, held, opening, }: {
17
+ target: Entity;
18
+ id: string;
19
+ name: string;
20
+ /** The related record, when the read brought it beside its key: its photo. */
21
+ held?: AnyRecord | null | undefined;
22
+ opening: RecordOpening | null;
23
+ }): import("react").JSX.Element;
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useSummaryOf } from "../../react/useSummary.js";
4
+ import { UserChip } from "@sincpro/web-ui";
5
+ /** Whether a relation's records are people (or companies): `entity(…, { summary: { person } })`. */
6
+ export function isPersonEntity(entity) {
7
+ return entity?.summary.person === true;
8
+ }
9
+ /**
10
+ * A relation to a person, read: their face — the photo the record holds, else their initials —
11
+ * and their name; pressed, the card that opens their record where the view says. With no place
12
+ * to open it, the face and the name alone: a chip that leads nowhere is not a button.
13
+ *
14
+ * Context: pickers already chose a person by their face, but once chosen a record read them as
15
+ * a plain link, so every application wrote its own chip. web-ui's `UserChip` is the same face
16
+ * and name its audit and attachments draw. The photo comes with the record held beside the key;
17
+ * a key alone (`EntityID`) is named by key and drawn with the initials.
18
+ */
19
+ export function PersonValue({ target, id, name, held, opening, }) {
20
+ const summarize = useSummaryOf(target);
21
+ const image = held === null || held === undefined || typeof held !== "object"
22
+ ? null
23
+ : summarize(held).image;
24
+ return (_jsx(UserChip, { name: name, size: "sm", ...(image === null ? {} : { src: image }), ...(opening === null || id === ""
25
+ ? {}
26
+ : { onOpen: () => opening.open(target.ref(id), opening.targets[0] ?? "page") }) }));
27
+ }
@@ -2,14 +2,17 @@
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { describeRows } from "@sincpro/criteria";
4
4
  import { frameworkCopy } from "../../core/copy.js";
5
- import { textOf, valueAt, viewOf } from "../../core/present.js";
5
+ import { fieldMetaOf, textOf, valueAt, viewOf } from "../../core/present.js";
6
6
  import { relatedOf } from "../../core/related.js";
7
7
  import { entityFor, relationFieldOf, } from "../../core/relation.js";
8
+ import { holdsRichText } from "../../core/richText.js";
8
9
  import { useEntityFor, useFrameworkIfAny } from "../../react/context.js";
9
10
  import { useNameOf } from "../../react/useNameOf.js";
10
11
  import { columnsOf } from "../list/columns.js";
11
12
  import { partLookOf, presentationOf, tonesOver, } from "../list/presentation.js";
12
13
  import { useRecordOpening } from "./opening.js";
14
+ import { isPersonEntity, PersonValue } from "./person.js";
15
+ import { RichTextFact } from "./richText.js";
13
16
  import { List, RelationValue, } from "@sincpro/web-ui";
14
17
  import { useState } from "react";
15
18
  /**
@@ -38,7 +41,7 @@ export function factsOf(record, meta, names, options = {}) {
38
41
  const relation = relationFieldOf(meta, name);
39
42
  return {
40
43
  label: view.label,
41
- value: own ? (own(record)) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : (
44
+ value: own ? (own(record)) : holdsRichText(fieldMetaOf(meta, name)) ? (_jsx(RichTextFact, { value: valueAt(meta, record, name) })) : relation !== undefined && !relation.many ? (_jsx(RelationFact, { record: record, meta: meta, name: name, relation: relation, locale: options.locale })) : (
42
45
  // A field of an embedded value is named by its path: `recibo.numero`.
43
46
  (textOf(meta, name, valueAt(meta, record, name), options.locale) ?? EMPTY)),
44
47
  ...(view.help === undefined ? {} : { hint: view.help }),
@@ -67,6 +70,9 @@ function RelationFact({ record, meta, name, relation, locale, }) {
67
70
  const held = relation.held
68
71
  ? textOf(meta, relation.relation, record[relation.relation], locale)
69
72
  : null;
73
+ // A person reads as their face and name; their card opens their record.
74
+ if (isPersonEntity(target))
75
+ return (_jsx(PersonValue, { target: target, id: key, name: held ?? asked ?? key, held: relation.held ? record[relation.relation] : null, opening: opening }));
70
76
  return (_jsx(RelationValue, { name: held ?? asked ?? key, ...(opening === null
71
77
  ? {}
72
78
  : {
@@ -0,0 +1,27 @@
1
+ import type { FieldControl } from "./control.js";
2
+ /**
3
+ * A field of formatted text: web-ui's editor while it is written, the HTML cleaned of anything
4
+ * that runs when it is read. How much the editor offers, the video hosts it embeds and whether
5
+ * the backend cleans what it stores are the application's, said once (`FrameworkProvider
6
+ * richText`); pictures go where the application sends files (`uploads`), filed under the record
7
+ * they belong to (`control.about`).
8
+ *
9
+ * <RecordField record={aviso} name="cuerpo" /> // widget "html": by itself
10
+ * <RecordField record={aviso} name="cuerpo" as={richTextControl} /> // a field the model does not mark
11
+ *
12
+ * Context: `RecordField` draws it for a field whose widget is `html`
13
+ * (Sincpro-SRL/sincpro_framework#371). Before the backend names it — or for a field it never
14
+ * will — the screen asks for it in code, by reference: `as={richTextControl}`, never a widget
15
+ * named in a string. Without `uploads` the editor takes no pictures; without `about` it does not
16
+ * know whose they would be, and takes none either.
17
+ */
18
+ export declare function RichTextControl({ control }: {
19
+ control: FieldControl;
20
+ }): import("react").JSX.Element;
21
+ /** `RichTextControl` as a field's control, by reference: `<RecordField … as={richTextControl} />`. */
22
+ export declare const richTextControl: (control: FieldControl) => import("react").JSX.Element;
23
+ /** Formatted text read — a record's fact: the HTML cleaned of what runs, with the players of the
24
+ * application's video hosts (`FrameworkProvider richText`). */
25
+ export declare function RichTextFact({ value }: {
26
+ value: unknown;
27
+ }): import("react").JSX.Element;
@@ -0,0 +1,59 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { sendFile, uploadRefusalOf } from "../../core/files.js";
4
+ import { useFramework, useFrameworkIfAny } from "../../react/context.js";
5
+ import { RichTextInput, RichTextValue } from "@sincpro/web-ui";
6
+ import { useMemo } from "react";
7
+ /**
8
+ * A field of formatted text: web-ui's editor while it is written, the HTML cleaned of anything
9
+ * that runs when it is read. How much the editor offers, the video hosts it embeds and whether
10
+ * the backend cleans what it stores are the application's, said once (`FrameworkProvider
11
+ * richText`); pictures go where the application sends files (`uploads`), filed under the record
12
+ * they belong to (`control.about`).
13
+ *
14
+ * <RecordField record={aviso} name="cuerpo" /> // widget "html": by itself
15
+ * <RecordField record={aviso} name="cuerpo" as={richTextControl} /> // a field the model does not mark
16
+ *
17
+ * Context: `RecordField` draws it for a field whose widget is `html`
18
+ * (Sincpro-SRL/sincpro_framework#371). Before the backend names it — or for a field it never
19
+ * will — the screen asks for it in code, by reference: `as={richTextControl}`, never a widget
20
+ * named in a string. Without `uploads` the editor takes no pictures; without `about` it does not
21
+ * know whose they would be, and takes none either.
22
+ */
23
+ export function RichTextControl({ control }) {
24
+ const { richText, uploads, transport } = useFramework();
25
+ const { about } = control;
26
+ const html = typeof control.value === "string" ? control.value : "";
27
+ const images = useMemo(() => uploads === undefined || about === undefined
28
+ ? undefined
29
+ : {
30
+ upload: async (file) => {
31
+ try {
32
+ const published = await sendFile(transport, uploads, file, about, {
33
+ signal: new AbortController().signal,
34
+ });
35
+ if (published.src === undefined)
36
+ throw new Error("uploads.publish answered no `src`: a picture inside a rich text needs where it is seen");
37
+ return {
38
+ src: published.src,
39
+ ...(published.alt === undefined ? {} : { alt: published.alt }),
40
+ };
41
+ }
42
+ catch (error) {
43
+ // web-ui shows the thrown message as the failure: the copy's words, by reason.
44
+ throw new Error(uploadRefusalOf(error), { cause: error });
45
+ }
46
+ },
47
+ }, [uploads, about, transport]);
48
+ if (control.readonly)
49
+ return (_jsx(RichTextValue, { value: html, ...(richText.embeds === undefined ? {} : { embeds: richText.embeds }), ...(richText.sanitized === undefined ? {} : { sanitized: richText.sanitized }) }));
50
+ return (_jsx(RichTextInput, { value: html, onChange: (next) => control.set(next), invalid: control.invalid, toolbar: richText.toolbar ?? "full", ...(richText.embeds === undefined ? {} : { embeds: richText.embeds }), ...(images === undefined ? {} : { images }), ...(control.standalone === true ? { "aria-label": control.label } : {}) }));
51
+ }
52
+ /** `RichTextControl` as a field's control, by reference: `<RecordField … as={richTextControl} />`. */
53
+ export const richTextControl = (control) => (_jsx(RichTextControl, { control: control }));
54
+ /** Formatted text read — a record's fact: the HTML cleaned of what runs, with the players of the
55
+ * application's video hosts (`FrameworkProvider richText`). */
56
+ export function RichTextFact({ value }) {
57
+ const settings = useFrameworkIfAny()?.richText ?? {};
58
+ return (_jsx(RichTextValue, { value: typeof value === "string" ? value : null, ...(settings.embeds === undefined ? {} : { embeds: settings.embeds }), ...(settings.sanitized === undefined ? {} : { sanitized: settings.sanitized }) }));
59
+ }
@@ -2,9 +2,11 @@ import { type ChangeFeed, type Entity, type Transport } from "@sincpro/client-fr
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
+ import type { Uploads } from "../../core/files.js";
5
6
  import type { DateStyle } from "../../core/present.js";
7
+ import type { RichTextSettings } from "../../core/richText.js";
6
8
  import { type ReactNode } from "react";
7
- export declare function SincproApp({ transport, views, start, language, metas, entities, empty, skin, cache, timeZone, dateStyle, currency, events, workspace: given, bar, onViewError, changes, }: {
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, }: {
8
10
  transport: Transport;
9
11
  /** The entities as composer views — `entityView(…)` — and any other view of the app. */
10
12
  views: readonly ViewSpec[];
@@ -34,6 +36,13 @@ export declare function SincproApp({ transport, views, start, language, metas, e
34
36
  dateStyle?: DateStyle;
35
37
  /** The business's currency (`"BOB"`): an amount the model draws as money is written in it. */
36
38
  currency?: string;
39
+ /** Where numbers and money are written as the business writes them (`"es-BO"`), apart from
40
+ * the language of the words. */
41
+ region?: string;
42
+ /** How a field of formatted text is written and read (`FrameworkProvider richText`). */
43
+ richText?: RichTextSettings;
44
+ /** Where a file a person gives goes — the application's (`FrameworkProvider uploads`). */
45
+ uploads?: Uploads;
37
46
  /** Each domain event's definition by its wire name (`eventMetasOf(contract)`): a history
38
47
  * names each fact's own fields in its words. */
39
48
  events?: Readonly<Record<string, Meta>>;
@@ -51,7 +51,7 @@ function FrameworkSearch({ children }) {
51
51
  }
52
52
  /** A view that broke while drawing, told to the process's error reporter: `view <ref>`. */
53
53
  const reportViewError = (error, { resource }) => reportError(error, `view ${formatRef(resource)}`);
54
- export function SincproApp({ transport, views, start, language = "es", metas, entities, empty, skin = webUiSkin, cache = {}, timeZone, dateStyle, currency, events, workspace: given, bar, onViewError = reportViewError, changes = processChanges, }) {
54
+ 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, }) {
55
55
  // Installed once, before anything draws: the three tables are module state of their packages.
56
56
  useState(() => {
57
57
  if (language === "es") {
@@ -96,5 +96,5 @@ export function SincproApp({ transport, views, start, language = "es", metas, en
96
96
  // The first screen only: a re-render must not push it again.
97
97
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
98
  }, [workspace]);
99
- 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 }), ...(events === undefined ? {} : { events }), children: _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 }) }) })] }) }) }) }));
99
+ 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: _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 }) }) })] }) }) }) }));
100
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.12.1",
3
+ "version": "3.14.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.3.0",
54
+ "@sincpro/client-framework": "^2.7.0",
55
55
  "@sincpro/criteria": "^2.4.0",
56
56
  "@sincpro/criteria-react": "^2.4.0",
57
57
  "@sincpro/web-composer": "^1.7.0",
58
- "@sincpro/web-ui": "^2.14.1",
58
+ "@sincpro/web-ui": "^2.18.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.6.0",
98
+ "@sincpro/client-framework": "^2.7.0",
99
99
  "@sincpro/criteria": "^2.5.0",
100
100
  "@sincpro/criteria-react": "^2.5.0",
101
101
  "@sincpro/web-composer": "^1.9.0",
102
- "@sincpro/web-ui": "^2.14.1",
102
+ "@sincpro/web-ui": "^2.18.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",