@sincpro/web-framework 3.10.0 → 3.12.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.
@@ -20,7 +20,7 @@ import { EntitySearchBar } from "./EntitySearchBar.js";
20
20
  import { pilesOf } from "./groups.js";
21
21
  import { OpenInMenu, openOptions, targetsFor } from "./openIn.js";
22
22
  import { pivotOf } from "./pivot.js";
23
- import { over, presentationOf } from "./presentation.js";
23
+ import { over, presentationOf, } from "./presentation.js";
24
24
  import { RESTORE, useRowCommands, } from "./rowCommands.js";
25
25
  import { Button, Callout, List, Pagination, pathKey, RecordCard, SearchField, Tag, } from "@sincpro/web-ui";
26
26
  import { Plus, RotateCcw } from "lucide-react";
@@ -34,16 +34,33 @@ const NO_WORKSPACE = {
34
34
  };
35
35
  /** How many lists' trails are kept: the records opened from the last fifty lists page on. */
36
36
  const TRAILS = 50;
37
+ /** web-ui's empty for this list: what the screen said, over the framework's words. */
38
+ function emptyOf(asked, words) {
39
+ const own = typeof asked === "string" ? { sentence: asked } : (asked ?? {});
40
+ return {
41
+ ...own,
42
+ sentence: own.sentence ?? words.empty,
43
+ whenFiltered: {
44
+ ...own.whenFiltered,
45
+ sentence: own.whenFiltered?.sentence ?? words.emptyFiltered,
46
+ },
47
+ };
48
+ }
37
49
  /** No commands: one constant, so the hook is not handed a new array on every render. */
38
50
  const NO_COMMANDS = [];
39
51
  /** What a list offers when nobody said: every face that needs no configuration. */
40
52
  const EVERY_VIEW = ["table", "rows", "board", "sheet"];
41
- export function EntityList({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable = false, selection: held, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
53
+ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo, views: askedViews, title: askedTitle, description: askedDescription, crumbs, actions, onOpen, onPeek, openTargets, onOpenIn, pivot: pivotAsked, empty, search = "bar", recent: askedRecent = false, sums, filters: askedFilters, facets: askedFacets, groupable: askedGroupable, selectable = false, selection: held, selectionActions, embedded = false, create = true, commands = NO_COMMANDS, rowActions: askedRowActions, faces, }) {
42
54
  // A named list (`defineList`) brings its own columns, filters, faces and words; what the
43
55
  // screen passes wins.
44
56
  const definition = listing.definition;
45
- // The entity's own look (`presented`): its columns, the tones of its choices, its row and card.
57
+ // The entity's own look (`presented`): its columns, the tones of its choices, its row, card, tile.
46
58
  const look = presentationOf(listing.entity);
59
+ const recent = askedRecent === false
60
+ ? undefined
61
+ : askedRecent === true
62
+ ? (definition?.key ?? listing.entity.kind)
63
+ : askedRecent;
47
64
  const columns = askedColumns ?? definition?.columns ?? look.columns;
48
65
  const views = askedViews ??
49
66
  definition?.views ??
@@ -335,11 +352,11 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
335
352
  };
336
353
  })()),
337
354
  }, look.row?.(row));
338
- // Without a look of its own, the board's card is web-ui's, made of the row. With one, the
339
- // same card — the row's name, meta and tags — under it, and pressing it is still the list's:
340
- // web-ui (1.5) hands an own card the list's press rule (`ways.press`: open, or choose).
341
- const ownCard = look.card;
342
- const cardOfRow = ownCard === undefined
355
+ // Without a look of its own, the board's card — and the tile — is web-ui's, made of the row.
356
+ // With one, the same card — the row's name, meta and tags — under it, and pressing it is still
357
+ // the list's: web-ui (1.5) hands an own card the list's press rule (`ways.press`: open, or
358
+ // choose). A tile is the same card in its `tile` shape (web-ui 2.13), under its own look.
359
+ const cardFrom = (own, layout) => own === undefined
343
360
  ? undefined
344
361
  : (row, ways) => {
345
362
  const d = rowOf(row);
@@ -347,8 +364,10 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
347
364
  title: d.name,
348
365
  ...(d.tags === undefined ? {} : { tags: d.tags }),
349
366
  ...(d.meta === undefined ? {} : { meta: d.meta }),
350
- }, ownCard(row)), ...(ways.press === undefined ? {} : { onOpen: ways.press }) }));
367
+ }, own(row)), ...(layout === undefined ? {} : { layout }), ...(ways.press === undefined ? {} : { onOpen: ways.press }) }));
351
368
  };
369
+ const cardOfRow = cardFrom(look.card);
370
+ const tileOfRow = cardFrom(look.tile, "tile");
352
371
  // Grouped: the SERVER counts the groups; a group's rows are read when it is opened, so every
353
372
  // group starts closed. Every face of web-ui (1.4) draws these piles, the table included, and
354
373
  // each says what its next «more» brings (1.5).
@@ -458,15 +477,12 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
458
477
  error: failure === null
459
478
  ? null
460
479
  : [failure.heading, failure.sentence].filter(Boolean).join(". "),
461
- }, filtered: listing.selection !== undefined || listing.text !== "", empty: {
462
- sentence: empty ?? copy.empty,
463
- whenFiltered: { sentence: copy.emptyFiltered },
464
- }, ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), ...(elsewhere.length === 0 || openingIn === undefined
480
+ }, filtered: listing.selection !== undefined || listing.text !== "", empty: emptyOf(empty, copy), ...(selection === undefined ? {} : { selection }), ...(opening === undefined ? {} : { onOpen: opening }), ...(peeking === undefined ? {} : { onPeek: peeking, rowClick: "open" }), ...(elsewhere.length === 0 || openingIn === undefined
465
481
  ? {}
466
482
  : {
467
483
  openTargets: elsewhere,
468
484
  onOpenIn: (row, to) => openingNow.current?.(row, to),
469
- }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(groupable === undefined ? {} : { groupable }), ...(facets === undefined ? {} : { facets }), ...(asked === "" ? {} : { seed: asked }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
485
+ }), children: [_jsxs(List.Bar, { children: [trail === undefined || trail.length === 0 ? null : _jsx(List.Crumbs, { crumbs: trail }), embedded ? null : (_jsx(List.Identity, { title: title ?? nameOf(meta, locale), ...(description === undefined ? {} : { description }) })), search === "bar" ? (_jsx(List.Search, { children: _jsx(EntitySearchBar, { listing: listing, filters: filters, groups: groups, ...(groupable === undefined ? {} : { groupable }), ...(facets === undefined ? {} : { facets }), ...(asked === "" ? {} : { seed: asked }), ...(recent === undefined ? {} : { recentKey: recent }) }) })) : null, search === "box" && meta?.search != null ? (_jsx(List.Search, { children: _jsx(SearchField, { value: draft, onChange: (next) => {
470
486
  setDraft(next);
471
487
  // Emptied (or cleared with ×): the whole set again, at once.
472
488
  if (next === "" && listing.text !== "")
@@ -485,5 +501,5 @@ export function EntityList({ listing, api, columns: askedColumns, cells, yesNo,
485
501
  measures: [],
486
502
  meta,
487
503
  locale,
488
- }) })) : null, views.includes("board") ? (_jsx(List.Board, { ...(cardOfRow === undefined ? {} : { card: cardOfRow }) })) : null, (faces ?? []).map((face) => (_jsx(List.Present, { id: face.id, label: face.label, icon: face.icon, ...(face.wide === undefined ? {} : { wide: face.wide }), children: face.render }, face.id))), refused === null ? null : (_jsx(Callout, { tone: "bad", title: refused.heading, children: refused.sentence }))] }));
504
+ }) })) : null, views.includes("board") ? (_jsx(List.Board, { ...(cardOfRow === undefined ? {} : { card: cardOfRow }) })) : null, views.includes("tiles") ? (_jsx(List.Tiles, { ...(tileOfRow === undefined ? {} : { card: tileOfRow }) })) : null, (faces ?? []).map((face) => (_jsx(List.Present, { id: face.id, label: face.label, icon: face.icon, ...(face.wide === undefined ? {} : { wide: face.wide }), children: face.render }, face.id))), refused === null ? null : (_jsx(Callout, { tone: "bad", title: refused.heading, children: refused.sentence }))] }));
489
505
  }
@@ -33,7 +33,7 @@ import type { Listing } from "../../react/useListing.js";
33
33
  * <List.Search><EntitySearchBar listing={listing} filters={…} /></List.Search>
34
34
  */
35
35
  export type { NamedFilter };
36
- export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, groupable: only, facets: named, seed, }: {
36
+ export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters, groups, groupable: only, facets: named, seed, recentKey, }: {
37
37
  listing: Listing<T>;
38
38
  /** The cuts this set offers by name: «sólo pagadas», «vencidas». */
39
39
  filters?: readonly NamedFilter<T>[];
@@ -48,4 +48,9 @@ export declare function EntitySearchBar<T extends AnyRecord>({ listing, filters,
48
48
  /** A text to start on, put as the literal search chip — what was typed in a picker whose
49
49
  * «Buscar más…» opened this list. */
50
50
  seed?: string;
51
+ /** Under which name this bar remembers, in this browser, the last searches put — offered
52
+ * when the empty bar takes the focus («Recientes», web-ui 2.14). Without it nothing is
53
+ * remembered: what was searched may name a customer, and only the application knows
54
+ * whether its browsers may keep that. */
55
+ recentKey?: string;
51
56
  }): import("react").JSX.Element | null;
@@ -9,7 +9,7 @@ import { CriteriaBuilder, describeFilter, Dialog, fillCopy, filterCriteria, Grou
9
9
  import { useEffect, useMemo, useRef, useState } from "react";
10
10
  /** No grouping: one constant, so the control is not handed a new array on every render. */
11
11
  const NO_LEVELS = [];
12
- export function EntitySearchBar({ listing, filters = [], groups, groupable: only, facets: named, seed, }) {
12
+ export function EntitySearchBar({ listing, filters = [], groups, groupable: only, facets: named, seed, recentKey, }) {
13
13
  const copy = frameworkCopy().list;
14
14
  const { meta, locale } = listing;
15
15
  const [put, setPut] = useState([]);
@@ -80,7 +80,7 @@ export function EntitySearchBar({ listing, filters = [], groups, groupable: only
80
80
  },
81
81
  }), ...(groups === undefined || groupable.length === 0
82
82
  ? {}
83
- : { grouping: _jsx(GroupingLevels, { fields: groupable, control: control }) }), onOpenBuilder: () => setBuilding(true), ...(meta?.search == null
83
+ : { grouping: _jsx(GroupingLevels, { fields: groupable, control: control }) }), onOpenBuilder: () => setBuilding(true), ...(recentKey === undefined ? {} : { recentKey }), ...(meta?.search == null
84
84
  ? {}
85
85
  : {
86
86
  literal: (text) => matching(meta, text).selection ?? null,
@@ -16,6 +16,7 @@ import type { ComponentProps } from "react";
16
16
  * option: (c) => ({ meta: c.tax_id, aside: <Saldo value={c.balance} /> }),
17
17
  * row: (c) => ({ tags: c.blocked ? <Tag tone="bad">Bloqueado</Tag> : undefined }),
18
18
  * card: (c) => ({ subtitle: c.city, figure: <Saldo value={c.balance} /> }),
19
+ * tile: (c) => ({ media: { src: c.photo_url, person: true } }),
19
20
  * });
20
21
  *
21
22
  * Each size answers the PROPS of web-ui's piece for it (`PickerItem`, `RowOf`, `RecordCard`),
@@ -35,6 +36,9 @@ export type OptionLook = Partial<Omit<PickerItem, "id">>;
35
36
  export type RowLook = Partial<RowOf>;
36
37
  /** The board's card. Opening it stays the list's: `onOpen` is not the presentation's. */
37
38
  export type CardLook = Partial<Omit<ComponentProps<typeof RecordCard>, "onOpen">>;
39
+ /** A tile of the «tiles» face — web-ui's `RecordCard layout="tile"`: the picture on top
40
+ * (`media`), the name, the figure (a price). Its shape stays the tile's. */
41
+ export type TileLook = Omit<CardLook, "layout">;
38
42
  /** The colour of each value of a choice, by field and by value as text (the Meta's own keys):
39
43
  * `{ estado: { APROBADO: "good", RECHAZADO: "bad" } }`. */
40
44
  export type ChoiceTones<T> = Readonly<Partial<Record<keyof T & string, Readonly<Record<string, Tone>>>>>;
@@ -42,6 +46,16 @@ export type Presentation<T> = {
42
46
  option?: (record: T) => OptionLook;
43
47
  row?: (record: T) => RowLook;
44
48
  card?: (record: T) => CardLook;
49
+ /**
50
+ * A tile of the «tiles» face — a product on a till's or a shop's grid: `media` (its
51
+ * picture), `figure` (its price), `badge`, `disabled` (out of stock). Without it, the tile
52
+ * is web-ui's, made of the row.
53
+ *
54
+ * Context: a tile is not a card. A card is told apart by its facts (`fields`, a figure beside
55
+ * the name); a tile by its picture and its price, and the whole tile is pressed. One look for
56
+ * both put a board's facts on a shop's grid, or a product's photo on a pipeline.
57
+ */
58
+ tile?: (record: T) => TileLook;
45
59
  /**
46
60
  * The colour of each value of a choice — a state, a priority. Declared once here and used
47
61
  * wherever the framework draws the value: a table's cell, a row's and a card's tag, the tag of
@@ -1,6 +1,7 @@
1
1
  import { type Entity } from "@sincpro/client-framework";
2
2
  import type { AnyRecord } from "@sincpro/criteria";
3
3
  import { type ViewProps } from "@sincpro/web-composer";
4
+ import type { RecordRead } from "../../core/server.js";
4
5
  import { type RecordReading } from "../../react/useRecord.js";
5
6
  import { type ScreenActions } from "../list/dock.js";
6
7
  /** Who made a record, or changed it last, and when: `Record.Audit`'s. */
@@ -41,6 +42,9 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
41
42
  title?: ((record: T) => string | null) | undefined;
42
43
  /** `false`: the screen draws its own history — it is not read here. */
43
44
  history?: boolean | undefined;
45
+ /** The record and its model already read on the server that renders the screen
46
+ * (`readRecordOnServer`): it starts from it, filled in the HTML (`useRecord`). */
47
+ initial?: RecordRead<T> | undefined;
44
48
  }): {
45
49
  reading: RecordReading<T>;
46
50
  crumbs: readonly import("@sincpro/web-composer").Crumb[];
@@ -73,8 +77,11 @@ export declare function useRecordScreen<T extends AnyRecord>(entity: Entity<T>,
73
77
  created?: Stamp | undefined;
74
78
  } | undefined;
75
79
  };
76
- export declare function EntityRecord<T extends AnyRecord>({ api, resource, entity, fields, pages, actions, title, }: ViewProps & {
80
+ export declare function EntityRecord<T extends AnyRecord>({ api, resource, entity, fields, pages, actions, title, initial, }: ViewProps & {
77
81
  entity: Entity<T>;
82
+ /** The record and its model already read on the server that renders the screen
83
+ * (`readRecordOnServer`): drawn filled there, and not asked again in the browser. */
84
+ initial?: RecordRead<T> | undefined;
78
85
  /** Its name, the screen's way — for a record whose model has no display field. */
79
86
  title?: (record: T) => string | null;
80
87
  /** The fields, in this order. Without it, the model's (`formOf`). */
@@ -71,7 +71,7 @@ function refusalOf(failure) {
71
71
  * carried these 150 lines itself (`shared/record_screen.tsx`).
72
72
  */
73
73
  export function useRecordScreen(entity, { api, resource }, options = {}) {
74
- const reading = useRecord(entity, resource);
74
+ const reading = useRecord(entity, resource, { initial: options.initial });
75
75
  const crumbs = useCrumbs(api);
76
76
  useRecordInWorkspace(api, reading, options);
77
77
  const look = presentationOf(entity);
@@ -151,8 +151,8 @@ export function useRecordScreen(entity, { api, resource }, options = {}) {
151
151
  },
152
152
  };
153
153
  }
154
- export function EntityRecord({ api, resource, entity, fields, pages, actions, title, }) {
155
- const screen = useRecordScreen(entity, { api, resource }, { title });
154
+ export function EntityRecord({ api, resource, entity, fields, pages, actions, title, initial, }) {
155
+ const screen = useRecordScreen(entity, { api, resource }, { title, initial });
156
156
  const { reading, crumbs, history, pager } = screen;
157
157
  const [page, setPage] = useState(undefined);
158
158
  const copy = frameworkCopy().record;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-framework",
3
- "version": "3.10.0",
3
+ "version": "3.12.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",
@@ -25,6 +25,10 @@
25
25
  "./errors": {
26
26
  "types": "./dist/errors/index.d.ts",
27
27
  "default": "./dist/errors/index.js"
28
+ },
29
+ "./errors/server": {
30
+ "types": "./dist/errors/server.d.ts",
31
+ "default": "./dist/errors/server.js"
28
32
  }
29
33
  },
30
34
  "publishConfig": {
@@ -41,15 +45,17 @@
41
45
  "peerDependencies": {
42
46
  "@opentelemetry/api": "^1.10.0",
43
47
  "@opentelemetry/context-async-hooks": "^3.1.0",
48
+ "@opentelemetry/core": "^3.1.0",
44
49
  "@opentelemetry/exporter-trace-otlp-http": "^0.301.0",
45
50
  "@opentelemetry/resources": "^3.1.0",
46
51
  "@opentelemetry/sdk-trace": "^3.1.0",
47
52
  "@sentry/browser": "^11.11.0",
53
+ "@sentry/core": "^11.11.0",
48
54
  "@sincpro/client-framework": "^2.3.0",
49
55
  "@sincpro/criteria": "^2.4.0",
50
56
  "@sincpro/criteria-react": "^2.4.0",
51
57
  "@sincpro/web-composer": "^1.7.0",
52
- "@sincpro/web-ui": "^2.11.0",
58
+ "@sincpro/web-ui": "^2.14.0",
53
59
  "react": ">=19",
54
60
  "react-dom": ">=19"
55
61
  },
@@ -60,6 +66,9 @@
60
66
  "@opentelemetry/context-async-hooks": {
61
67
  "optional": true
62
68
  },
69
+ "@opentelemetry/core": {
70
+ "optional": true
71
+ },
63
72
  "@opentelemetry/exporter-trace-otlp-http": {
64
73
  "optional": true
65
74
  },
@@ -71,21 +80,26 @@
71
80
  },
72
81
  "@sentry/browser": {
73
82
  "optional": true
83
+ },
84
+ "@sentry/core": {
85
+ "optional": true
74
86
  }
75
87
  },
76
88
  "devDependencies": {
77
89
  "@eslint/js": "^10.0.1",
78
90
  "@opentelemetry/api": "1.10.0",
79
91
  "@opentelemetry/context-async-hooks": "3.1.1",
92
+ "@opentelemetry/core": "3.1.0",
80
93
  "@opentelemetry/exporter-trace-otlp-http": "0.301.0",
81
94
  "@opentelemetry/resources": "3.1.0",
82
95
  "@opentelemetry/sdk-trace": "3.1.0",
83
96
  "@sentry/browser": "11.11.0",
84
- "@sincpro/client-framework": "^2.5.0",
85
- "@sincpro/criteria": "^2.4.0",
86
- "@sincpro/criteria-react": "^2.4.0",
87
- "@sincpro/web-composer": "^1.8.0",
88
- "@sincpro/web-ui": "^2.11.0",
97
+ "@sentry/core": "11.11.0",
98
+ "@sincpro/client-framework": "^2.6.0",
99
+ "@sincpro/criteria": "^2.5.0",
100
+ "@sincpro/criteria-react": "^2.5.0",
101
+ "@sincpro/web-composer": "^1.9.0",
102
+ "@sincpro/web-ui": "^2.14.0",
89
103
  "@storybook/addon-a11y": "10.6.5",
90
104
  "@storybook/addon-docs": "10.6.5",
91
105
  "@storybook/addon-mcp": "10.6.5",