@sincpro/web-framework 3.7.0 → 3.8.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 CHANGED
@@ -480,6 +480,7 @@ hook and draw your own, or go straight to the loose piece.
480
480
  | What happened, what broke | `./telemetry`, `./errors` (optional) | — | `configureProcess({ tracer, reporter })` |
481
481
  | What is each field? | `Meta` from the server, or `defineMeta` | — | `textOf`, `viewOf`, `metaFromSchema` |
482
482
  | A value outside a model | — | `useTextOf` | `moneyTextOf`, `dayTextOf`, `instantTextOf`, `numberTextOf` |
483
+ | A file or a photo it holds | `EntityList`, `RecordField`: by its widget, as a `FileValue` | — | `attachmentOf`, `storedFileOf`, `renditionUrl` |
483
484
  | What is a record, at any size? | `cardOf`, `relationOf` | `useSummaryOf` | `summaryOf` |
484
485
  | How does a record look? | `presented(entity, { option, row, card })` | — | `presentationOf` |
485
486
  | N records: search, filter, page | `EntityList`, `EntitySearchBar` | `useListing`, `useGroups` | `transport.list(route, criteria)` |
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A file a record holds — sincpro_framework's `StoredFile`, as a read answers it: its name as it
3
+ * was sent, its type, its size, a link to see it (`url`), and for a picture its renditions,
4
+ * `thumb` for a list's line and `view` for a record.
5
+ *
6
+ * holdsFile(meta.fields.foto) -> true (widget "image" or "file")
7
+ * storedFileOf({ key: "fotos/01a1e.jpg", name: "Directorio.jpg", … }) -> StoredFileValue
8
+ * storedFileOf("fotos/01a1e.jpg") -> null (a bare key names nothing)
9
+ * renditionUrl(foto, "thumb") -> "/files/cGhv…" (else the original's)
10
+ *
11
+ * Context: the model publishes such a field as `embedded` with the widget `file` — or `image`,
12
+ * by its presentation —; read as any embedded value it was a section of its parts (key, name,
13
+ * type…) and a list's cell its JSON. Drawn by its widget it is ONE value: the picture and the
14
+ * name it was sent with, the name downloading it (web-ui's `FileValue`).
15
+ */
16
+ /** A rendition of a stored picture, as answered. */
17
+ export type RenditionValue = {
18
+ name: string;
19
+ key: string;
20
+ content_type: string;
21
+ size: number;
22
+ width: number;
23
+ height: number;
24
+ url?: string;
25
+ };
26
+ /** A stored file, as answered. */
27
+ export type StoredFileValue = {
28
+ key: string;
29
+ name: string;
30
+ content_type: string;
31
+ size: number;
32
+ width?: number | null;
33
+ height?: number | null;
34
+ url?: string;
35
+ renditions?: readonly RenditionValue[];
36
+ };
37
+ /** The widgets that draw a field as one file: sincpro_framework's `Widget.FILE` / `IMAGE`. */
38
+ export declare const FILE_WIDGETS: ReadonlySet<string>;
39
+ /** Whether a field holds a file — drawn as one value, by its widget. */
40
+ export declare function holdsFile(field: {
41
+ widget?: string | undefined;
42
+ } | null | undefined): boolean;
43
+ /** The stored file a value is — `null` for nothing, or for anything that is not one. */
44
+ export declare function storedFileOf(value: unknown): StoredFileValue | null;
45
+ /** Where to see the rendition `name` of a stored picture — the original's link when it has
46
+ * none (a file put whole, a picture smaller than the rendition). */
47
+ export declare function renditionUrl(file: StoredFileValue, name: string): string | undefined;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A file a record holds — sincpro_framework's `StoredFile`, as a read answers it: its name as it
3
+ * was sent, its type, its size, a link to see it (`url`), and for a picture its renditions,
4
+ * `thumb` for a list's line and `view` for a record.
5
+ *
6
+ * holdsFile(meta.fields.foto) -> true (widget "image" or "file")
7
+ * storedFileOf({ key: "fotos/01a1e.jpg", name: "Directorio.jpg", … }) -> StoredFileValue
8
+ * storedFileOf("fotos/01a1e.jpg") -> null (a bare key names nothing)
9
+ * renditionUrl(foto, "thumb") -> "/files/cGhv…" (else the original's)
10
+ *
11
+ * Context: the model publishes such a field as `embedded` with the widget `file` — or `image`,
12
+ * by its presentation —; read as any embedded value it was a section of its parts (key, name,
13
+ * type…) and a list's cell its JSON. Drawn by its widget it is ONE value: the picture and the
14
+ * name it was sent with, the name downloading it (web-ui's `FileValue`).
15
+ */
16
+ /** The widgets that draw a field as one file: sincpro_framework's `Widget.FILE` / `IMAGE`. */
17
+ export const FILE_WIDGETS = new Set(["file", "image"]);
18
+ /** Whether a field holds a file — drawn as one value, by its widget. */
19
+ export function holdsFile(field) {
20
+ return field?.widget !== undefined && FILE_WIDGETS.has(field.widget);
21
+ }
22
+ /** The stored file a value is — `null` for nothing, or for anything that is not one. */
23
+ export function storedFileOf(value) {
24
+ if (typeof value !== "object" || value === null)
25
+ return null;
26
+ const held = value;
27
+ return typeof held.key === "string" && typeof held.name === "string"
28
+ ? held
29
+ : null;
30
+ }
31
+ /** Where to see the rendition `name` of a stored picture — the original's link when it has
32
+ * none (a file put whole, a picture smaller than the rendition). */
33
+ export function renditionUrl(file, name) {
34
+ return file.renditions?.find((one) => one.name === name)?.url ?? file.url;
35
+ }
@@ -12,6 +12,7 @@ export { sendRoute } from "./command.js";
12
12
  export { ENGLISH_FRAMEWORK_COPY, type FrameworkCopy, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
13
13
  export { type Advice, adviceAt, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorAt, errorsByField, type FieldState, fieldStateOf, type FieldStates, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, type ServerFieldState, } from "./edit.js";
14
14
  export { explain } from "./explain.js";
15
+ export { FILE_WIDGETS, holdsFile, renditionUrl, type RenditionValue, storedFileOf, type StoredFileValue, } from "./files.js";
15
16
  export { type FormLayout, formOf } from "./form.js";
16
17
  export { areGroups, NotGrouped } from "./groups.js";
17
18
  export { FACT_TONES, type FactTone, type HistoryChange, type HistoryEntry, historyOf, toneOfFact, } from "./history.js";
@@ -12,6 +12,7 @@ export { sendRoute } from "./command.js";
12
12
  export { ENGLISH_FRAMEWORK_COPY, frameworkCopy, installFrameworkCopy, SPANISH_FRAMEWORK_COPY, } from "./copy.js";
13
13
  export { adviceAt, changesOf, computedLocally, creationOf, defaultsOf, editedOf, errorAt, errorsByField, fieldStateOf, linePlacesOf, lineStatesOf, missingOf, needsPreview, pathOf, } from "./edit.js";
14
14
  export { explain } from "./explain.js";
15
+ export { FILE_WIDGETS, holdsFile, renditionUrl, storedFileOf, } from "./files.js";
15
16
  export { formOf } from "./form.js";
16
17
  export { areGroups, NotGrouped } from "./groups.js";
17
18
  export { FACT_TONES, historyOf, toneOfFact, } from "./history.js";
@@ -41,9 +41,10 @@ export declare function valueAt(meta: Meta | null | undefined, record: Readonly<
41
41
  export declare function fieldMetaOf(meta: Meta | null | undefined, name: string): FieldMeta | undefined;
42
42
  export declare function viewOf(meta: Meta | null | undefined, name: string, locale?: string): FieldView;
43
43
  /**
44
- * The fields a screen shows when it names none: every scalar the model holds, in the order it
45
- * declares them. Relations and value objects are left out — they are not a column, they are a
46
- * page of their own (`RecordLines`) or a section.
44
+ * The fields a screen shows when it names none: every scalar the model holds, and every file
45
+ * (`holdsFile` — one value, though it travels as an object), in the order it declares them.
46
+ * Relations and other value objects are left out — they are not a column, they are a page of
47
+ * their own (`RecordLines`) or a section.
47
48
  */
48
49
  export declare function defaultFields(meta: Meta | null | undefined): string[];
49
50
  /** The bookkeeping every framework entity carries; shown on demand, never by default. */
@@ -1,6 +1,7 @@
1
1
  import { Money, timeZoneNow } from "@sincpro/client-framework";
2
2
  import { choiceLabelOf, labelOf, } from "@sincpro/criteria";
3
3
  import { frameworkCopy } from "./copy.js";
4
+ import { holdsFile, storedFileOf } from "./files.js";
4
5
  import { relatedOf } from "./related.js";
5
6
  /** Present when a field is named that the model does not declare: drawn plain, never thrown. */
6
7
  const UNKNOWN = {
@@ -72,15 +73,16 @@ export function viewOf(meta, name, locale) {
72
73
  };
73
74
  }
74
75
  /**
75
- * The fields a screen shows when it names none: every scalar the model holds, in the order it
76
- * declares them. Relations and value objects are left out — they are not a column, they are a
77
- * page of their own (`RecordLines`) or a section.
76
+ * The fields a screen shows when it names none: every scalar the model holds, and every file
77
+ * (`holdsFile` — one value, though it travels as an object), in the order it declares them.
78
+ * Relations and other value objects are left out — they are not a column, they are a page of
79
+ * their own (`RecordLines`) or a section.
78
80
  */
79
81
  export function defaultFields(meta) {
80
82
  if (!meta)
81
83
  return [];
82
84
  return Object.entries(meta.fields)
83
- .filter(([, field]) => field.kind === "scalar")
85
+ .filter(([, field]) => field.kind === "scalar" || holdsFile(field))
84
86
  .map(([name]) => name);
85
87
  }
86
88
  /** The bookkeeping every framework entity carries; shown on demand, never by default. */
@@ -341,6 +343,9 @@ export function textOf(meta, name, value, locale) {
341
343
  const copy = frameworkCopy();
342
344
  if (field.choices && field.choices.length > 0)
343
345
  return choiceLabelOf(meta, name, value, locale);
346
+ // A file reads as the name it was sent with — never its storage key, never its JSON.
347
+ if (holdsFile(field))
348
+ return storedFileOf(value)?.name ?? null;
344
349
  // An amount the model draws as money is money, though it travels bare.
345
350
  if (field.widget === "money" && field.kind === "scalar") {
346
351
  const amount = amountText(value, locale);
@@ -0,0 +1,9 @@
1
+ import type { AttachmentFile } from "@sincpro/web-ui";
2
+ /**
3
+ * A stored file as web-ui draws one (`AttachmentFile`): its name, type and size, its link, and
4
+ * the `thumb` rendition as its thumbnail — so a list of fifty photos loads fifty thumbnails.
5
+ * `null` when the value is no file.
6
+ *
7
+ * attachmentOf(organo.foto) -> { id: "fotos/01a1e.jpg", name: "Directorio.jpg", url, thumbnail }
8
+ */
9
+ export declare function attachmentOf(value: unknown): AttachmentFile | null;
@@ -0,0 +1,22 @@
1
+ import { renditionUrl, storedFileOf } from "../core/files.js";
2
+ /**
3
+ * A stored file as web-ui draws one (`AttachmentFile`): its name, type and size, its link, and
4
+ * the `thumb` rendition as its thumbnail — so a list of fifty photos loads fifty thumbnails.
5
+ * `null` when the value is no file.
6
+ *
7
+ * attachmentOf(organo.foto) -> { id: "fotos/01a1e.jpg", name: "Directorio.jpg", url, thumbnail }
8
+ */
9
+ export function attachmentOf(value) {
10
+ const file = storedFileOf(value);
11
+ if (file === null)
12
+ return null;
13
+ const thumbnail = renditionUrl(file, "thumb");
14
+ return {
15
+ id: file.key,
16
+ name: file.name,
17
+ type: file.content_type,
18
+ size: file.size,
19
+ ...(file.url === undefined ? {} : { url: file.url }),
20
+ ...(thumbnail === undefined ? {} : { thumbnail }),
21
+ };
22
+ }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * The web bindings: what draws a `Listing` and a record with `@sincpro/web-ui`.
3
3
  */
4
+ export { attachmentOf } from "./files.js";
4
5
  export { BatchProgress } from "./list/BatchProgress.js";
5
6
  export { aggregateOf, type ColumnOptions, columnsOf, } from "./list/columns.js";
6
7
  export { actionsOf, type ScreenActions } from "./list/dock.js";
package/dist/web/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * The web bindings: what draws a `Listing` and a record with `@sincpro/web-ui`.
3
3
  */
4
+ export { attachmentOf } from "./files.js";
4
5
  export { BatchProgress } from "./list/BatchProgress.js";
5
6
  export { aggregateOf, columnsOf, } from "./list/columns.js";
6
7
  export { actionsOf } from "./list/dock.js";
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
+ import { holdsFile } from "../../core/files.js";
3
4
  import { totalOf } from "../../core/measure.js";
4
5
  import { BOOKKEEPING, defaultFields, fieldMetaOf, sortKeyOf, textOf, valueAt, viewOf, } from "../../core/present.js";
5
6
  import { relationFieldOf } from "../../core/relation.js";
6
7
  import { useEntityFor } from "../../react/context.js";
7
8
  import { useNameOf } from "../../react/useNameOf.js";
8
- import { Tag } from "@sincpro/web-ui";
9
+ import { attachmentOf } from "../files.js";
10
+ import { FileValue, Tag, } from "@sincpro/web-ui";
9
11
  /**
10
12
  * The columns of a table, from the model: name the fields, the rest follows.
11
13
  *
@@ -57,6 +59,8 @@ function columnOf(meta, name, options, hidden) {
57
59
  const tones = options.tones?.[name];
58
60
  const choice = (field?.choices?.length ?? 0) > 0;
59
61
  const boolean = view.type === "boolean";
62
+ // A file — a photo, a scan — is ONE value: its thumbnail and the name it was sent with.
63
+ const file = holdsFile(field);
60
64
  const aggregate = aggregateOf(meta, name);
61
65
  // The column IS a key of another record: `customer_id` beside its relation, or a key alone.
62
66
  const relation = relationFieldOf(meta, name);
@@ -77,21 +81,23 @@ function columnOf(meta, name, options, hidden) {
77
81
  id: name,
78
82
  header: view.label,
79
83
  field: name,
80
- value: (row) => sortKeyOf(meta, name, raw(row)),
84
+ value: file ? text : (row) => sortKeyOf(meta, name, raw(row)),
81
85
  cell: own ??
82
86
  named ??
83
- (choice
84
- ? // A state reads at a glance: its word in a tag, in the tone the application gave it.
85
- (row) => {
86
- const word = text(row);
87
- return word === "" ? null : (_jsx(Tag, { tone: tones?.[String(raw(row))] ?? "neutral", children: word }));
88
- }
89
- : boolean
90
- ? // Drawn by web-ui from the value (`yesNo`, below): no cell of its own.
91
- undefined
92
- : whole
93
- ? (row) => _jsx("span", { className: "whitespace-nowrap", children: text(row) })
94
- : text),
87
+ (file
88
+ ? (row) => _jsx(FileValue, { file: attachmentOf(raw(row)) })
89
+ : choice
90
+ ? // A state reads at a glance: its word in a tag, in the tone the application gave it.
91
+ (row) => {
92
+ const word = text(row);
93
+ return word === "" ? null : (_jsx(Tag, { tone: tones?.[String(raw(row))] ?? "neutral", children: word }));
94
+ }
95
+ : boolean
96
+ ? // Drawn by web-ui from the value (`yesNo`, below): no cell of its own.
97
+ undefined
98
+ : whole
99
+ ? (row) => _jsx("span", { className: "whitespace-nowrap", children: text(row) })
100
+ : text),
95
101
  // A yes/no reads by its look (web-ui's `YesNo`): with a `text` of its own the table would
96
102
  // draw the words instead.
97
103
  ...(boolean ? {} : { text }),
@@ -4,17 +4,19 @@ import {} from "@sincpro/client-framework";
4
4
  import { choicesOf } from "@sincpro/criteria";
5
5
  import { frameworkCopy } from "../../core/copy.js";
6
6
  import { errorAt } from "../../core/edit.js";
7
+ import { holdsFile } from "../../core/files.js";
7
8
  import { editableLines } from "../../core/lines.js";
8
9
  import { fieldAt, fieldMetaOf, isMoneyDefinition, textOf, valueAt, viewOf, } from "../../core/present.js";
9
10
  import { relationFieldOf } from "../../core/relation.js";
10
11
  import { useEntityFor, useFramework } from "../../react/context.js";
11
12
  import { useNameOf } from "../../react/useNameOf.js";
13
+ import { attachmentOf } from "../files.js";
12
14
  import { controlFor, RelationPicker, } from "./control.js";
13
15
  import { RecordLinesEditor } from "./lines.js";
14
16
  import { useRecordOpening } from "./opening.js";
15
17
  import { RecordLines } from "./record.js";
16
18
  import { RelatedList } from "./RelatedList.js";
17
- import { Checkbox, Field, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
19
+ import { Checkbox, Field, FileValue, FormSection, ReadValue, RelationValue, useFormStyle, } from "@sincpro/web-ui";
18
20
  /** `value` with `path` (`numero`, or `emisor.nit`) set to `next` — a new object, the rest kept. */
19
21
  function setAt(value, path, next) {
20
22
  const base = typeof value === "object" && value !== null ? value : {};
@@ -100,6 +102,7 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
100
102
  own.many !== true &&
101
103
  own.definition &&
102
104
  own.widget !== "money" &&
105
+ !holdsFile(own) &&
103
106
  !isMoneyDefinition(own.definition)) {
104
107
  // One value the record embeds: its fields, each by its label — a section of the record.
105
108
  const block = parts.map((one) => (_jsx(RecordField, { record: record, name: `${name}.${one}` }, one)));
@@ -153,6 +156,12 @@ export function RecordField({ record, name, as, bare = false, lines: look, list:
153
156
  label: view.label,
154
157
  };
155
158
  const field = fieldMetaOf(meta, name);
159
+ if (as === undefined && holdsFile(field)) {
160
+ // A file is ONE value — its picture or its kind, the name it was sent with, its type and
161
+ // size —, never a section of its parts. Sending another is the upload's, not this field's.
162
+ const file = attachmentOf(value);
163
+ return (_jsx(Field, { label: view.label, ...(view.help === undefined ? {} : { hint: view.help }), children: file === null ? _jsx(ReadValue, { value: "\u2014" }) : _jsx(FileValue, { file: file, size: "md" }) }));
164
+ }
156
165
  /** A many2one of a declared entity: chosen by the server's literal search, opened where the
157
166
  * view says. Written by its key; read by the record it points at. */
158
167
  function manyToOne() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.7.0",
3
+ "version": "3.8.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",
@@ -44,7 +44,7 @@
44
44
  "@sincpro/criteria": "^2.4.0",
45
45
  "@sincpro/criteria-react": "^2.4.0",
46
46
  "@sincpro/web-composer": "^1.7.0",
47
- "@sincpro/web-ui": "^2.10.0",
47
+ "@sincpro/web-ui": "^2.11.0",
48
48
  "react": ">=19",
49
49
  "react-dom": ">=19"
50
50
  },
@@ -76,7 +76,7 @@
76
76
  "@sincpro/criteria": "^2.4.0",
77
77
  "@sincpro/criteria-react": "^2.4.0",
78
78
  "@sincpro/web-composer": "^1.8.0",
79
- "@sincpro/web-ui": "^2.10.0",
79
+ "@sincpro/web-ui": "^2.11.0",
80
80
  "@storybook/addon-a11y": "10.6.5",
81
81
  "@storybook/addon-docs": "10.6.5",
82
82
  "@storybook/addon-mcp": "10.6.5",