@sincpro/web-ui 2.4.0 → 2.6.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 (69) hide show
  1. package/README.md +75 -8
  2. package/dist/components/activity/Activity.d.ts +28 -2
  3. package/dist/components/activity/Activity.js +53 -11
  4. package/dist/components/activity/Messages.d.ts +4 -0
  5. package/dist/components/activity/index.d.ts +1 -1
  6. package/dist/components/attachments/Attachments.d.ts +1 -28
  7. package/dist/components/attachments/Attachments.js +5 -24
  8. package/dist/components/attachments/FileList.d.ts +28 -0
  9. package/dist/components/attachments/FileList.js +91 -0
  10. package/dist/components/attachments/FileThumb.d.ts +13 -0
  11. package/dist/components/attachments/FileThumb.js +34 -0
  12. package/dist/components/attachments/download.d.ts +9 -0
  13. package/dist/components/attachments/download.js +36 -0
  14. package/dist/components/attachments/files.d.ts +28 -0
  15. package/dist/components/attachments/index.d.ts +4 -2
  16. package/dist/components/attachments/index.js +4 -1
  17. package/dist/components/board/Board.d.ts +74 -2
  18. package/dist/components/board/Board.js +65 -2
  19. package/dist/components/board/index.d.ts +1 -1
  20. package/dist/components/board/index.js +1 -1
  21. package/dist/components/calendar/RecordCalendar.d.ts +2 -1
  22. package/dist/components/calendar/RecordCalendar.js +4 -1
  23. package/dist/components/calendar/calendar.css +37 -0
  24. package/dist/components/canvas/canvas.css +6 -1
  25. package/dist/components/chat/ChatThread.d.ts +8 -1
  26. package/dist/components/chat/ChatThread.js +9 -4
  27. package/dist/components/chat/model.d.ts +4 -0
  28. package/dist/components/form/Form.js +11 -0
  29. package/dist/components/form/FormIndex.d.ts +11 -0
  30. package/dist/components/form/FormIndex.js +96 -0
  31. package/dist/components/form/Sheet.js +5 -0
  32. package/dist/components/gantt/RecordGantt.d.ts +9 -1
  33. package/dist/components/gantt/RecordGantt.js +16 -3
  34. package/dist/components/gantt/gantt.css +52 -0
  35. package/dist/components/listing/ChartExplorer.js +10 -5
  36. package/dist/components/record/DirtyActions.d.ts +10 -1
  37. package/dist/components/record/DirtyActions.js +77 -6
  38. package/dist/components/record/RecordHeader.js +17 -11
  39. package/dist/foundations/calendar.d.ts +12 -0
  40. package/dist/foundations/calendar.js +50 -0
  41. package/dist/foundations/chart.d.ts +10 -1
  42. package/dist/foundations/chart.js +17 -1
  43. package/dist/foundations/copy.d.ts +26 -0
  44. package/dist/foundations/copy.es.js +12 -0
  45. package/dist/foundations/copy.js +12 -0
  46. package/dist/foundations/form.d.ts +6 -0
  47. package/dist/foundations/form.js +7 -0
  48. package/dist/foundations/index.d.ts +2 -2
  49. package/dist/foundations/index.js +2 -2
  50. package/dist/foundations/pivot.d.ts +6 -0
  51. package/dist/foundations/pivot.js +1 -0
  52. package/dist/primitives/button/Button.d.ts +5 -1
  53. package/dist/primitives/button/Button.js +9 -2
  54. package/dist/primitives/chart/BarList.d.ts +30 -0
  55. package/dist/primitives/chart/BarList.js +27 -0
  56. package/dist/primitives/chart/Chart.d.ts +13 -0
  57. package/dist/primitives/chart/Chart.js +71 -19
  58. package/dist/primitives/chart/Sparkline.d.ts +30 -0
  59. package/dist/primitives/chart/Sparkline.js +53 -0
  60. package/dist/primitives/chart/index.d.ts +2 -0
  61. package/dist/primitives/chart/index.js +2 -0
  62. package/dist/primitives/field/Field.d.ts +6 -2
  63. package/dist/primitives/field/Field.js +35 -6
  64. package/dist/primitives/value/Markdown.d.ts +1 -0
  65. package/dist/primitives/value/Markdown.js +1 -0
  66. package/dist/primitives/value/Metric.d.ts +7 -0
  67. package/dist/primitives/value/Metric.js +5 -2
  68. package/dist/tokens.css +59 -87
  69. package/package.json +1 -1
package/README.md CHANGED
@@ -83,7 +83,7 @@ the tokens once — fonts, theme and Tailwind come with it:
83
83
  ```tsx
84
84
  import { Field, installCopy, SPANISH_COPY, TextInput } from "@sincpro/web-ui";
85
85
 
86
- installCopy(SPANISH_COPY); // optional: the interface in Spanish
86
+ installCopy(SPANISH_COPY); // optional: the interface in Spanish — once, where the app starts
87
87
 
88
88
  export function CompanyName({
89
89
  value,
@@ -103,10 +103,56 @@ export function CompanyName({
103
103
  Each level is also its own entry — `@sincpro/web-ui/foundations`, `/primitives`,
104
104
  `/components`, `/views` — so what a level offers is one import away.
105
105
 
106
- **React Server Components.** Every module that needs the browser (hooks, context, events)
107
- starts with `"use client"`, and a test keeps it that way; pure logic (calendar, pivot,
108
- criteria) stays callable from the server. The views are client components: compose
109
- `Record` inside a client component of your own.
106
+ **What your application ships.** Only what it uses: a `Button` alone is ~2.5 KB gzip, a form
107
+ ~74, a `Record` ~130, a `List` ~283 — React aside. The heavy pieces (calendar, Gantt, rich-text
108
+ and JSON editors, charts, PDF) load in their own chunk when they are drawn, and a library's
109
+ stylesheet comes with the component that draws it (the Gantt's alone is ~160 KB), not with
110
+ `tokens.css`. `tests/bundle.test.ts` holds those numbers. Your bundler only needs to handle a
111
+ CSS import from a dependency — Vite, webpack, Turbopack and Next.js do. Tests that load the
112
+ package in Node (Vitest's `node` environment) inline it so those imports go through Vite:
113
+ `test: { server: { deps: { inline: [/@sincpro\/web-ui/] } } }`.
114
+
115
+ ### Server rendering (Next.js)
116
+
117
+ It works as it is with the App Router and the Pages Router, under Turbopack and webpack.
118
+ `tokens.css` goes in your global stylesheet, with Tailwind's PostCSS plugin:
119
+
120
+ ```js
121
+ // postcss.config.mjs
122
+ export default { plugins: { "@tailwindcss/postcss": {} } };
123
+ ```
124
+
125
+ - **Server Components** may import from `@sincpro/web-ui`. Every module that needs the browser
126
+ (hooks, context, events) starts with `"use client"`, and a test keeps it that way; pure logic
127
+ (calendar, pivot, criteria) stays callable from the server. The views are client components:
128
+ compose `Record` or `List` inside a client component of your own.
129
+ - **The language.** `installCopy` sets the one global there is — and on a server, one process
130
+ renders every page and every request. Installed in one page, it leaks into the next page the
131
+ server renders, which the browser then draws in English: a hydration error. Install it in a
132
+ module EVERY page loads (your root layout's client providers), or — when the language changes
133
+ per user — give it with `UiCopyProvider`, which never writes the global:
134
+
135
+ ```tsx
136
+ // app/providers.tsx — rendered by app/layout.tsx around {children}
137
+ "use client";
138
+ import { SPANISH_COPY, UiCopyProvider } from "@sincpro/web-ui";
139
+
140
+ export function Providers({ children }: { children: React.ReactNode }) {
141
+ return <UiCopyProvider copy={SPANISH_COPY}>{children}</UiCopyProvider>;
142
+ }
143
+ ```
144
+
145
+ - **webpack** (`next build --webpack`): a Server Component that imports from the package root
146
+ makes webpack send the WHOLE library to the browser (~1.2 MB gzip for one `Button`). Let Next
147
+ rewrite those imports — Turbopack, the default, does not need it:
148
+
149
+ ```js
150
+ // next.config.mjs
151
+ export default { experimental: { optimizePackageImports: ["@sincpro/web-ui"] } };
152
+ ```
153
+
154
+ - What only a browser can draw is drawn there: the Gantt (SVAR paints its grid on a canvas)
155
+ renders its skeleton on the server and the chart after hydration.
110
156
 
111
157
  ### Theming (light / dark)
112
158
 
@@ -195,7 +241,8 @@ follows:
195
241
  | Menus, lists, popovers, the cuts panel | `--ui-popover-radius`, `--ui-popover-bg`, `--ui-popover-border`, `--ui-popover-shadow` |
196
242
  | A row inside them (menu item, option) | `--ui-option-radius`, `--ui-option-active-bg` |
197
243
  | `Dialog` | `--ui-dialog-radius`, `--ui-dialog-bg` |
198
- | `Block`, `RecordCard`, `BoardTile`, `Metric` | `--ui-card-radius`, `--ui-card-bg`, `--ui-card-border` |
244
+ | `Block`, `RecordCard`, `Metric` | `--ui-card-radius`, `--ui-card-bg`, `--ui-card-border` |
245
+ | A board's `BoardTile` and `BoardStat` | `--ui-tile-radius`, `--ui-tile-bg`, `--ui-tile-border` (fall back to the card's) |
199
246
  | `Tag`, `Tags`, the search bar's chips | `--ui-tag-radius` |
200
247
  | `SearchBar`'s field | `--ui-search-radius` (and the control's bg and border) |
201
248
  | The sidebar on the canvas | `--ui-sidebar-bg`, `--ui-sidebar-border` |
@@ -219,16 +266,36 @@ of classes that change with the next refactor:
219
266
 
220
267
  The parts: `button`, `icon-button`, `control`, `popover`, `menu`, `menu.trigger`,
221
268
  `menu.section`, `menu.item`, `menu.fold`, `dialog`, `block`, `record-card`, `board.tile`,
222
- `metric`, `metric.detail`, `tag`, `tags.item`, `search`, `search.field`, `search.chip`,
269
+ `board.stat`, `board.stat.value`, `activity.changes`, `file-list`, `file-list.file`, `metric`, `metric.detail`, `tag`, `tags.item`, `search`, `search.field`, `search.chip`,
223
270
  `search.panel`, `search.suggestions`, `search-entry`, `search-entry.keys`, `table`,
224
271
  `table.head`, `topbar`, `topbar.brand`, `topbar.menus`, `topbar.actions`, `topbar.user`,
225
272
  `frame`, `frame.bar`, `frame.sidebar`, `frame.main`, `sidebar`, `sidebar.brand`,
226
273
  `sidebar.user`, `sidebar.search`, `sidebar.nav`, `sidebar.account`, `navigation`,
227
- `navigation.item`, `dirty.blocked`, `guide`, `guide.veil`, `guide.spot`, `guide.card`,
274
+ `navigation.item`, `dirty.blocked`, `dirty.bar`, `field`, `field.label`, `form.section`,
275
+ `form.index`, `guide`, `guide.veil`, `guide.spot`, `guide.card`,
228
276
  `guide.progress`, `guide.title`, `guide.body`, `guide.actions`. A part that is one of many
229
277
  carries `data-key` too (`navigation.item`). Put your rules in a cascade layer above web-ui's, or
230
278
  outside any layer.
231
279
 
280
+ #### A form that explains itself: the «settings» style
281
+
282
+ The default form is the dense sheet of an ERP — label | control, two columns, help behind a
283
+ `?`. An application whose forms are filled once in a while and read before they are typed into
284
+ (a back office's settings, an account) can choose the **settings** style, once, around the app:
285
+
286
+ ```tsx
287
+ <FormStyleProvider value="settings">
288
+ <App />
289
+ </FormStyleProvider>
290
+ ```
291
+
292
+ Then every `Field` is a row — the label with `*` or «(opcional)» (`optional`) and its `hint`
293
+ written out under it on the left, the control on the right —, every `FormSection` is a card
294
+ (`form.section`) with an index of the titled ones at the sheet's left (`form.index`), and a
295
+ `Record` with `dirty` floats Discard · Save at the bottom of the screen (`dirty.bar`) instead of
296
+ the rail. The layout (`stacked` / `horizontal`) is still the screen's: stacked, the help and the
297
+ control go under the label. Without the provider nothing changes.
298
+
232
299
  #### A guided tour: the screen says what each thing is
233
300
 
234
301
  `Guide` walks a person through a screen: the rest dims, the thing being explained is cut out,
@@ -1,4 +1,5 @@
1
1
  import type { Message } from "./Messages.js";
2
+ import type { AttachmentFile } from "../attachments/files.js";
2
3
  import type { Tone } from "../../foundations/types.js";
3
4
  import { type CalloutProps } from "../../primitives/notice/Callout.js";
4
5
  import type { LucideIcon } from "lucide-react";
@@ -11,6 +12,7 @@ import { type ReactNode } from "react";
11
12
  *
12
13
  * by WHO. Absent = the system did it, which is also an answer.
13
14
  * moved FROM WHAT TO WHAT. «borrador → confirmado» reads at a glance.
15
+ * changes WHICH FIELDS, each as it was → as it is: the edit an audit asks about.
14
16
  * error WHAT failed, whole and verbatim: whoever looks at this screen many
15
17
  * times has no access to the logs.
16
18
  */
@@ -31,8 +33,26 @@ export type ActivityEvent = {
31
33
  detail?: ReactNode;
32
34
  /** What failed, verbatim. The FIRST line is shown and the rest opens. */
33
35
  error?: string;
34
- /** The dot's icon, when the bolt does not say enough. */
36
+ /** The dot's icon, when the bolt does not say enough. An event with `changes` and no
37
+ * icon of its own gets the pencil: it is an edit. */
35
38
  icon?: LucideIcon;
39
+ /**
40
+ * The fields an edit changed, each as it WAS and as it IS — Odoo's tracked values. Drawn
41
+ * under the event, always in sight (the first three, the rest one press away): an audit
42
+ * reads «who changed what, from what to what, when» without opening anything. Prefer it to
43
+ * writing «Observación: — → test» into `detail`, which can only be read, not scanned.
44
+ */
45
+ changes?: readonly ActivityChange[];
46
+ };
47
+ /**
48
+ * One field an edit changed: what it is called, what it held, what it holds. `from` / `to`
49
+ * absent, `null` or `""` mean EMPTY — written «vacío», because «—» beside an arrow reads as
50
+ * a dash somebody typed.
51
+ */
52
+ export type ActivityChange = {
53
+ field: string;
54
+ from?: ReactNode;
55
+ to?: ReactNode;
36
56
  };
37
57
  /** A notice of the record, as the panel lists it: a `Callout` without its × label. */
38
58
  export type ActivityAlert = Omit<CalloutProps, "dismissLabel">;
@@ -56,8 +76,14 @@ export type ActivityProps = {
56
76
  /** The panel's name. «Actividad» by default. */
57
77
  label?: string;
58
78
  layout?: ActivityLayout;
79
+ /** Open a file a message carries. Present = its name is a button; WHERE it opens — a
80
+ * peek, a `FilePreview` — is the application's. */
81
+ onOpenFile?: (file: AttachmentFile, message: Message) => void;
82
+ /** Download a file a message carries by code (a token, a signed URL). Without it, a file
83
+ * with a `url` downloads by link. Busy while the promise runs; a rejection is said. */
84
+ onDownloadFile?: (file: AttachmentFile, message: Message) => void | Promise<unknown>;
59
85
  };
60
- export declare function Activity({ messages, events, alerts, alertsId: ownAlertsId, composer, open, onToggle, label: ownLabel, layout, }: ActivityProps): import("react").JSX.Element;
86
+ export declare function Activity({ messages, events, alerts, alertsId: ownAlertsId, composer, open, onToggle, label: ownLabel, layout, onOpenFile, onDownloadFile, }: ActivityProps): import("react").JSX.Element;
61
87
  /** Whether a standalone activity panel is open. Inside a `Record`, `Record.Activity`
62
88
  * keeps this state itself (open by default: on a big screen you see what the record has). */
63
89
  export declare function useActivity(initial?: boolean): {
@@ -1,8 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { FileList } from "../attachments/FileList.js";
3
4
  import { usePagination } from "../listing/pages.js";
4
5
  import { Pagination } from "../listing/Pagination.js";
5
6
  import { fillCopy, useUiCopy } from "../../foundations/copy.js";
7
+ import { useFormStyle } from "../../foundations/form.js";
6
8
  import { cn } from "../../foundations/variants.js";
7
9
  import { IconButton } from "../../primitives/button/Button.js";
8
10
  import { SegmentedControl } from "../../primitives/choice/SegmentedControl.js";
@@ -11,7 +13,7 @@ import { Callout } from "../../primitives/notice/Callout.js";
11
13
  import { Tag } from "../../primitives/tag/Tag.js";
12
14
  import { DateValue } from "../../primitives/value/DateValue.js";
13
15
  import { Avatar } from "../../primitives/value/Person.js";
14
- import { Activity as ActivityIcon, ArrowRight, CheckCircle2, ChevronDown, ChevronRight, ChevronUp, CornerDownRight, History, Info, Lock, MessageSquare, OctagonAlert, PanelRightClose, PanelRightOpen, TriangleAlert, Zap, } from "lucide-react";
16
+ import { Activity as ActivityIcon, ArrowRight, CheckCircle2, ChevronDown, ChevronRight, ChevronUp, CornerDownRight, History, Info, Lock, MessageSquare, OctagonAlert, PanelRightClose, PanelRightOpen, PencilLine, TriangleAlert, Zap, } from "lucide-react";
15
17
  import { Fragment, useId, useState } from "react";
16
18
  /** The day an instant falls on, here — a `YYYY-MM-DD` key in local time. */
17
19
  function dayKey(time) {
@@ -70,16 +72,53 @@ function at(when) {
70
72
  /* The stream's two kinds of entry share one GEOMETRY: a 1.5rem disc (the face, or the
71
73
  event's node) on the left, the text beside it, the meta line under it. Two geometries
72
74
  in one list read as two lists glued together. */
73
- function MessageEntry({ message }) {
75
+ function MessageEntry({ message, onOpenFile, onDownloadFile, }) {
74
76
  const copy = useUiCopy();
75
77
  const internal = message.internal === true;
76
- return (_jsxs("li", { className: "flex min-w-0 gap-2.5 px-2 py-2", children: [_jsx(Avatar, { name: message.author, size: "md" }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [_jsxs("div", { className: "flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5", children: [_jsx("span", { className: "truncate text-meta font-medium text-ink", children: message.author }), _jsx("span", { className: "text-micro text-muted", children: _jsx(DateValue, { when: message.at, format: "relative" }) }), internal ? (_jsxs("span", { className: "inline-flex items-center gap-1 text-micro text-muted", title: copy.activity.internalNote, children: [_jsx(Lock, { className: "size-3", "aria-hidden": true }), copy.activity.internal] })) : null] }), _jsx("p", { className: cn("max-w-(--container-prose) rounded-box px-2.5 py-1.5 text-body whitespace-pre-line text-ink", internal ? "border border-warn/35 bg-warn/6" : "bg-ground"), children: message.body })] })] }));
78
+ return (_jsxs("li", { className: "flex min-w-0 gap-2.5 px-2 py-2", children: [_jsx(Avatar, { name: message.author, size: "md" }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [_jsxs("div", { className: "flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5", children: [_jsx("span", { className: "truncate text-meta font-medium text-ink", children: message.author }), _jsx("span", { className: "text-micro text-muted", children: _jsx(DateValue, { when: message.at, format: "relative" }) }), internal ? (_jsxs("span", { className: "inline-flex items-center gap-1 text-micro text-muted", title: copy.activity.internalNote, children: [_jsx(Lock, { className: "size-3", "aria-hidden": true }), copy.activity.internal] })) : null] }), message.body === "" ? null : (_jsx("p", { className: cn("max-w-(--container-prose) rounded-box px-2.5 py-1.5 text-body whitespace-pre-line text-ink", internal ? "border border-warn/35 bg-warn/6" : "bg-ground"), children: message.body })), message.files === undefined ? null : (_jsx(FileList, { files: message.files, ...(onOpenFile === undefined
79
+ ? {}
80
+ : { onOpen: (file) => onOpenFile(file, message) }), ...(onDownloadFile === undefined
81
+ ? {}
82
+ : { onDownload: (file) => onDownloadFile(file, message) }) }))] })] }));
77
83
  }
78
84
  /** The change of state: from what to what. The old one quiet, the new one in ink. */
79
85
  const STATE_CHIP = "inline-flex max-w-32 min-w-0 items-center truncate rounded-pill border border-line-strong bg-ink/5 px-2 py-0.5 text-micro";
80
86
  function Moved({ from, to }) {
81
87
  return (_jsxs("span", { className: "inline-flex min-w-0 items-center gap-1", children: [from === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("span", { className: `${STATE_CHIP} text-muted`, children: from }), _jsx(ArrowRight, { className: "size-3 shrink-0 text-muted", strokeWidth: 2.5, "aria-hidden": true })] })), _jsx("span", { className: `${STATE_CHIP} font-medium text-ink`, children: to })] }));
82
88
  }
89
+ /* ── A change you can audit ─────────────────────────────────────────
90
+ *
91
+ * It used to be one grey line in the event's folded detail — «Observación: — → test» — read
92
+ * only after a press, the old value and the new one in the same weight, the empty one a dash.
93
+ * An audit asks three things of an edit, and each gets its own channel:
94
+ *
95
+ * WHICH field — its name on its own line, small: the column an eye runs down;
96
+ * WAS — `<del>`, muted and struck through: it is gone;
97
+ * IS — `<ins>`, in ink: what holds now.
98
+ *
99
+ * Not red and green: before and after are not bad and good (PRINCIPLES §3), and the strike
100
+ * plus the weight already say which is which — to a screen reader too, through `del`/`ins`
101
+ * and a word before each. An empty value is the word «vacío», never a dash. */
102
+ const MANY_CHANGES = 3;
103
+ function isEmpty(value) {
104
+ return value === undefined || value === null || value === "" || value === false;
105
+ }
106
+ function ChangeValue({ value, was }) {
107
+ const copy = useUiCopy();
108
+ const lead = (_jsxs("span", { className: "sr-only", children: [was ? copy.activity.before : copy.activity.after, " "] }));
109
+ if (isEmpty(value)) {
110
+ return (_jsxs("span", { className: "text-muted italic", children: [lead, copy.activity.empty] }));
111
+ }
112
+ return was ? (_jsxs("del", { className: "min-w-0 break-words text-muted decoration-muted/70", children: [lead, value] })) : (_jsxs("ins", { className: "min-w-0 break-words font-medium text-ink no-underline", children: [lead, value] }));
113
+ }
114
+ function Changes({ changes }) {
115
+ const copy = useUiCopy();
116
+ const [all, setAll] = useState(false);
117
+ const shown = all ? changes : changes.slice(0, MANY_CHANGES);
118
+ return (_jsxs("div", { "data-ui": "activity.changes", className: "mb-1 ml-10.5 flex min-w-0 flex-col gap-1.5 rounded-control border border-line px-2.5 py-2", children: [_jsx("dl", { className: "flex min-w-0 flex-col divide-y divide-line", children: shown.map((change, at) => (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5 py-1.5 first:pt-0 last:pb-0", children: [_jsx("dt", { className: "truncate text-micro text-muted", children: change.field }), _jsxs("dd", { className: "flex min-w-0 flex-wrap items-baseline gap-x-1.5 gap-y-0.5 text-meta", children: [_jsx(ChangeValue, { value: change.from, was: true }), _jsx(ArrowRight, { className: "size-3 shrink-0 self-center text-muted", strokeWidth: 2.5, "aria-hidden": true }), _jsx(ChangeValue, { value: change.to, was: false })] })] }, `${change.field}\u0000${String(at)}`))) }), changes.length <= MANY_CHANGES ? null : (_jsx("button", { type: "button", onClick: () => setAll(!all), "aria-expanded": all, className: "self-start cursor-pointer text-micro text-muted underline-offset-2 hover:text-ink hover:underline focus-visible:outline-2 focus-visible:outline-primary", children: all
119
+ ? copy.activity.less
120
+ : fillCopy(copy.activity.allChanges, { count: changes.length }) }))] }));
121
+ }
83
122
  /** The error: the first line, and the rest one press away — kept, not dropped. */
84
123
  function ErrorLine({ error }) {
85
124
  const copy = useUiCopy();
@@ -101,12 +140,13 @@ function EventEntry({ event }) {
101
140
  const copy = useUiCopy();
102
141
  const failed = event.tone === "bad" || event.error !== undefined;
103
142
  const skin = failed ? "failed" : "ok";
104
- const Icon = event.icon ?? EVENT_ICON;
143
+ const edited = event.changes !== undefined && event.changes.length > 0;
144
+ const Icon = event.icon ?? (edited ? PencilLine : EVENT_ICON);
105
145
  const [open, setOpen] = useState(false);
106
146
  const more = event.moved !== undefined || event.detail !== undefined || event.error !== undefined;
107
- const row = (_jsxs(_Fragment, { children: [_jsx("span", { className: `relative z-10 flex size-6 shrink-0 items-center justify-center rounded-pill ring-2 ring-surface ${NODE_SKIN[skin]}`, children: _jsx(Icon, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }) }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [_jsx("span", { className: "line-clamp-2 text-meta text-ink", children: event.label }), _jsxs("span", { className: "flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-micro text-muted", children: [_jsx("span", { className: "truncate", children: event.by ?? copy.activity.bySystem }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsx(DateValue, { when: event.at, format: "relative" })] })] }), more ? (_jsx(ChevronRight, { className: `mt-1 size-3.5 shrink-0 text-muted transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2.5, "aria-hidden": true })) : null] }));
147
+ const row = (_jsxs(_Fragment, { children: [_jsx("span", { className: `relative z-10 flex size-6 shrink-0 items-center justify-center rounded-pill ring-2 ring-surface ${NODE_SKIN[skin]}`, children: _jsx(Icon, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }) }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [_jsx("span", { className: "line-clamp-2 text-meta text-ink", children: event.label }), _jsxs("span", { className: "flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-micro text-muted", children: [_jsx("span", { className: "truncate font-medium text-ink", children: event.by ?? copy.activity.bySystem }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsx(DateValue, { when: event.at, format: "relative" })] })] }), more ? (_jsx(ChevronRight, { className: `mt-1 size-3.5 shrink-0 text-muted transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2.5, "aria-hidden": true })) : null] }));
108
148
  const box = `flex w-full min-w-0 items-start gap-2.5 rounded-control px-2 py-2 text-left ${failed ? "bg-bad/6" : ""}`;
109
- return (_jsxs("li", { className: "group/event relative", children: [_jsx("span", { "aria-hidden": true, className: "absolute top-8 bottom-0 left-5 w-px bg-line group-last/event:hidden" }), more ? (_jsx("button", { type: "button", onClick: () => setOpen(!open), "aria-expanded": open, className: `${box} cursor-pointer transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-primary ${failed ? "hover:bg-bad/10" : "hover:bg-ink/4"}`, children: row })) : (_jsx("div", { className: box, children: row })), !open ? null : (_jsxs("div", { className: "mb-1 ml-10.5 flex min-w-0 flex-col gap-1.5 rounded-control bg-ground px-2.5 py-2", children: [event.moved === undefined ? null : (_jsx(Moved, { ...(event.moved.from === undefined ? {} : { from: event.moved.from }), to: event.moved.to })), event.detail === undefined ? null : (_jsx("div", { className: "min-w-0 text-micro text-muted", children: event.detail })), event.error === undefined ? null : _jsx(ErrorLine, { error: event.error })] }))] }));
149
+ return (_jsxs("li", { className: "group/event relative", children: [_jsx("span", { "aria-hidden": true, className: "absolute top-8 bottom-0 left-5 w-px bg-line group-last/event:hidden" }), more ? (_jsx("button", { type: "button", onClick: () => setOpen(!open), "aria-expanded": open, className: `${box} cursor-pointer transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-primary ${failed ? "hover:bg-bad/10" : "hover:bg-ink/4"}`, children: row })) : (_jsx("div", { className: box, children: row })), edited ? _jsx(Changes, { changes: event.changes ?? [] }) : null, !open ? null : (_jsxs("div", { className: "mb-1 ml-10.5 flex min-w-0 flex-col gap-1.5 rounded-control bg-ground px-2.5 py-2", children: [event.moved === undefined ? null : (_jsx(Moved, { ...(event.moved.from === undefined ? {} : { from: event.moved.from }), to: event.moved.to })), event.detail === undefined ? null : (_jsx("div", { className: "min-w-0 text-micro text-muted", children: event.detail })), event.error === undefined ? null : _jsx(ErrorLine, { error: event.error })] }))] }));
110
150
  }
111
151
  /** Takes you to the field or row a note belongs to, and lights it for a moment so the eye
112
152
  * lands on it. The light is the system's focus colour, faded out; with reduced motion it
@@ -142,13 +182,16 @@ const TONE_TEXT = {
142
182
  info: "text-info",
143
183
  good: "text-good",
144
184
  };
145
- export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId, composer, open, onToggle, label: ownLabel, layout = "auto", }) {
185
+ export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId, composer, open, onToggle, label: ownLabel, layout = "auto", onOpenFile, onDownloadFile, }) {
146
186
  const copy = useUiCopy();
147
187
  const label = ownLabel ?? copy.activity.title;
148
188
  const titleId = useId();
149
189
  const autoAlertsId = useId();
150
190
  const alertsId = ownAlertsId ?? autoAlertsId;
151
191
  const auto = layout === "auto";
192
+ /* Beside the sheet it is joined to it — the sheet's right edge is the line between the two.
193
+ In the «settings» form style there is no sheet, only cards on the ground: it stands apart. */
194
+ const joined = useFormStyle() !== "settings";
152
195
  /* The notes of the fields and rows of the record around — `Record` keeps them. */
153
196
  const notes = useNoteEntries();
154
197
  const byTime = (items) => [...items].sort((x, y) => at(y.at) - at(x.at));
@@ -204,7 +247,7 @@ export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId,
204
247
  where the eye starts, and under it the counts, stacked — nothing hidden
205
248
  silently. The sheet's own right edge is the hairline between the two. */
206
249
  auto &&
207
- "@beside/page:w-auto @beside/page:flex-col @beside/page:justify-start @beside/page:gap-3 @beside/page:rounded-l-none @beside/page:border-l-0 @beside/page:px-2 @beside/page:py-3"), children: [_jsx("span", { className: cn("hidden shrink-0 text-muted", auto && "@beside/page:block"), children: _jsx(PanelRightOpen, { className: "size-(--size-icon-md)", "aria-hidden": true }) }), _jsx(ActivityIcon, { className: cn("size-(--size-icon-md) shrink-0 text-muted", auto && "@beside/page:hidden"), "aria-hidden": true }), _jsx("span", { className: cn("min-w-0 truncate text-meta font-medium text-ink", auto && "@beside/page:sr-only"), children: label }), alertTone === undefined ? null : (_jsxs(Tag, { tone: alertTone, children: [_jsxs("span", { className: cn("hidden items-center gap-1", auto && "@beside/page:inline-flex"), children: [_jsx(AlertIcon, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }), notices] }), _jsx("span", { className: cn(auto && "@beside/page:sr-only"), children: fillCopy(notices === 1 ? copy.record.noticeOne : copy.record.noticeMany, {
250
+ "@beside/page:w-auto @beside/page:flex-col @beside/page:justify-start @beside/page:gap-3 @beside/page:px-2 @beside/page:py-3", auto && joined && "@beside/page:rounded-l-none @beside/page:border-l-0"), children: [_jsx("span", { className: cn("hidden shrink-0 text-muted", auto && "@beside/page:block"), children: _jsx(PanelRightOpen, { className: "size-(--size-icon-md)", "aria-hidden": true }) }), _jsx(ActivityIcon, { className: cn("size-(--size-icon-md) shrink-0 text-muted", auto && "@beside/page:hidden"), "aria-hidden": true }), _jsx("span", { className: cn("min-w-0 truncate text-meta font-medium text-ink", auto && "@beside/page:sr-only"), children: label }), alertTone === undefined ? null : (_jsxs(Tag, { tone: alertTone, children: [_jsxs("span", { className: cn("hidden items-center gap-1", auto && "@beside/page:inline-flex"), children: [_jsx(AlertIcon, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }), notices] }), _jsx("span", { className: cn(auto && "@beside/page:sr-only"), children: fillCopy(notices === 1 ? copy.record.noticeOne : copy.record.noticeMany, {
208
251
  count: notices,
209
252
  }) })] })), messages === undefined
210
253
  ? null
@@ -212,8 +255,7 @@ export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId,
212
255
  }
213
256
  return (_jsxs("section", { "aria-labelledby": titleId, "data-activity": "open", className: cn("flex w-full min-w-0 flex-col rounded-box border border-line bg-surface",
214
257
  /* Beside the sheet: its column, joined to it — the sheet's right edge is the line. */
215
- auto &&
216
- "@beside/page:w-(--container-activity) @beside/page:rounded-l-none @beside/page:border-l-0"), children: [_jsxs("header", { className: "flex min-w-0 items-center gap-2 border-b border-line py-1.5 pr-1.5 pl-3", children: [_jsx(ActivityIcon, { className: "size-(--size-icon-md) shrink-0 text-muted", "aria-hidden": true }), _jsx("h2", { id: titleId, className: "min-w-0 truncate text-meta font-semibold text-ink", children: label }), _jsxs("span", { className: "ml-auto flex shrink-0", children: [_jsx("span", { className: cn("flex", auto && "@beside/page:hidden"), children: _jsx(IconButton, { icon: ChevronUp, label: fillCopy(copy.activity.fold, { label }), onClick: onToggle }) }), auto ? (_jsx("span", { className: "hidden @beside/page:flex", children: _jsx(IconButton, { icon: PanelRightClose, label: fillCopy(copy.activity.fold, { label }), onClick: onToggle }) })) : null] })] }), notices === 0 ? null : (
258
+ auto && "@beside/page:w-(--container-activity)", auto && joined && "@beside/page:rounded-l-none @beside/page:border-l-0"), children: [_jsxs("header", { className: "flex min-w-0 items-center gap-2 border-b border-line py-1.5 pr-1.5 pl-3", children: [_jsx(ActivityIcon, { className: "size-(--size-icon-md) shrink-0 text-muted", "aria-hidden": true }), _jsx("h2", { id: titleId, className: "min-w-0 truncate text-meta font-semibold text-ink", children: label }), _jsxs("span", { className: "ml-auto flex shrink-0", children: [_jsx("span", { className: cn("flex", auto && "@beside/page:hidden"), children: _jsx(IconButton, { icon: ChevronUp, label: fillCopy(copy.activity.fold, { label }), onClick: onToggle }) }), auto ? (_jsx("span", { className: "hidden @beside/page:flex", children: _jsx(IconButton, { icon: PanelRightClose, label: fillCopy(copy.activity.fold, { label }), onClick: onToggle }) })) : null] })] }), notices === 0 ? null : (
217
259
  /* NOW, before what happened. The rail's indicator sends the focus here, so it is
218
260
  focusable without being a tab stop. */
219
261
  _jsxs("section", { id: alertsId, tabIndex: -1, "aria-label": copy.activity.alerts, "data-activity-alerts": "", className: "flex min-w-0 scroll-mt-(--size-appbar) flex-col gap-2 border-b border-line px-3 py-3 outline-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary", children: [_jsxs("h3", { className: "flex items-center gap-2 px-1 text-micro font-medium text-muted", children: [copy.activity.alerts, _jsx(Tag, { tone: alertTone ?? "info", children: notices })] }), (() => {
@@ -263,7 +305,7 @@ export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId,
263
305
  _jsxs("li", { "aria-hidden": true, className: "flex items-center gap-2 px-1 pt-2 pb-1 text-micro font-medium text-muted first:pt-0", children: [_jsx("span", { className: "first-letter:uppercase", children: dayLabel(day, copy.locale, {
264
306
  today: copy.activity.today,
265
307
  yesterday: copy.activity.yesterday,
266
- }) }), _jsx("span", { className: "h-px flex-1 bg-line" })] })) : null, entry.kind === "message" ? (_jsx(MessageEntry, { message: entry.message })) : (_jsx(EventEntry, { event: entry.event }))] }, entry.id));
308
+ }) }), _jsx("span", { className: "h-px flex-1 bg-line" })] })) : null, entry.kind === "message" ? (_jsx(MessageEntry, { message: entry.message, onOpenFile: onOpenFile, onDownloadFile: onDownloadFile })) : (_jsx(EventEntry, { event: entry.event }))] }, entry.id));
267
309
  }) }), kept.length <= 20 ? null : _jsx(Pagination, { ...pages.bridge })] }))] })] }));
268
310
  }
269
311
  /** Whether a standalone activity panel is open. Inside a `Record`, `Record.Activity`
@@ -1,3 +1,4 @@
1
+ import type { AttachmentFile } from "../attachments/files.js";
1
2
  import { type UiCopy } from "../../foundations/copy.js";
2
3
  import { type ReactNode } from "react";
3
4
  /**
@@ -33,6 +34,9 @@ export type Message = {
33
34
  body: string;
34
35
  /** An internal note: it stays inside. Drawn differently on purpose. */
35
36
  internal?: boolean;
37
+ /** What it carries — the receipt, the signed contract —, drawn under the text as cards
38
+ * (`FileList`). A message may be only its files: then `body` is empty. */
39
+ files?: readonly AttachmentFile[];
36
40
  };
37
41
  /** A way of writing. `note` stays inside; everything else leaves, and what
38
42
  * changes between them is only the channel and who is on the other side. */
@@ -1,4 +1,4 @@
1
- export { Activity, type ActivityAlert, type ActivityEvent, type ActivityLayout, type ActivityProps, useActivity, } from "./Activity.js";
1
+ export { Activity, type ActivityAlert, type ActivityChange, type ActivityEvent, type ActivityLayout, type ActivityProps, useActivity, } from "./Activity.js";
2
2
  export { ActivityBadge, type ActivityState, } from "./ActivityBadge.js";
3
3
  export { type Message, MessageComposer, type MessageComposerProps, type MessageKind, writeANote, } from "./Messages.js";
4
4
  export { Timeline, type TimelineItemProps, type TimelineProps, } from "./Timeline.js";
@@ -1,32 +1,5 @@
1
+ import { type AttachmentFile } from "./files.js";
1
2
  import { type FormMode } from "../../foundations/form.js";
2
- export type AttachmentStatus = "ready" | "uploading" | "failed";
3
- export type AttachmentFile = {
4
- /** The attachment's identity: the server's id, or a local key while it uploads. */
5
- id: string;
6
- /** The file name as it was saved: «Factura proveedor 0418.pdf». */
7
- name: string;
8
- /** In bytes. Written in the copy's locale: «1,2 MB». */
9
- size?: number;
10
- /** The MIME type, when the server knows it. With the name, it picks the icon. */
11
- type?: string;
12
- /** Where it downloads from. Absent = no download (still uploading, or not allowed). */
13
- url?: string;
14
- /** A small image for the thumbnail. Defaults to `url` for an image — pass a smaller one
15
- * when the server has it, so a list of 4 MB photos does not load 4 MB photos. */
16
- thumbnail?: string;
17
- /** Who added it. */
18
- by?: string;
19
- /** Their face, for the chip. */
20
- byAvatar?: string;
21
- /** When it was added. */
22
- at?: Date | string | number;
23
- /** `ready` by default. The application owns it: it is what the upload is really doing. */
24
- status?: AttachmentStatus;
25
- /** 0 to 100 while `uploading`. Absent = under way without a figure yet. */
26
- progress?: number;
27
- /** Why it `failed`, in the server's words. */
28
- error?: string;
29
- };
30
3
  export type AttachmentsProps = {
31
4
  files: readonly AttachmentFile[];
32
5
  /** Files to add: dropped, pasted or chosen. Present = the drop zone is drawn (in edit
@@ -1,6 +1,7 @@
1
1
  "use client";
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { attachmentKind, fileExtension, formatFileSize, } from "./files.js";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { attachmentKind, formatFileSize, } from "./files.js";
4
+ import { FileThumb } from "./FileThumb.js";
4
5
  import { fillCopy, useUiCopy } from "../../foundations/copy.js";
5
6
  import { useFormMode } from "../../foundations/form.js";
6
7
  import { Button, IconButton, IconLink } from "../../primitives/button/Button.js";
@@ -10,28 +11,8 @@ import { useToastIfAny } from "../../primitives/notice/Toast.js";
10
11
  import { DateValue } from "../../primitives/value/DateValue.js";
11
12
  import { UserChip } from "../../primitives/value/Person.js";
12
13
  import { ProgressBar } from "../../primitives/value/ProgressBar.js";
13
- import { Download, File, FileImage, FileSpreadsheet, FileText, FileType, RotateCcw, Trash2, TriangleAlert, X, } from "lucide-react";
14
+ import { Download, RotateCcw, Trash2, TriangleAlert, X } from "lucide-react";
14
15
  import { useEffect, useId, useRef } from "react";
15
- const KIND_ICON = {
16
- image: FileImage,
17
- pdf: FileText,
18
- sheet: FileSpreadsheet,
19
- doc: FileType,
20
- other: File,
21
- };
22
- /** The type, at the size of a row: the image itself when there is one, otherwise the icon
23
- * of its kind over its extension. The extension is written because three of the five
24
- * icons are a page with lines on it — «PDF» and «DOCX» are what tell them apart, and a
25
- * word is never a colour that only some people see. */
26
- function Thumb({ file, kind }) {
27
- const picture = kind === "image" && file.status !== "failed" ? (file.thumbnail ?? file.url) : undefined;
28
- const Icon = KIND_ICON[kind];
29
- const extension = fileExtension(file.name).slice(0, 4);
30
- return (
31
- /* Decorative: the name next to it says which file it is, and the image's `alt` would
32
- say it twice. */
33
- _jsx("span", { "aria-hidden": true, className: "flex size-(--size-control-lg) shrink-0 flex-col items-center justify-center gap-0.5 overflow-clip rounded-control border border-line bg-ink/4 text-muted", children: picture === undefined ? (_jsxs(_Fragment, { children: [_jsx(Icon, { className: "size-(--size-icon-md)", strokeWidth: 1.75 }), extension === "" ? null : (_jsx("span", { className: "text-micro leading-none font-medium uppercase", children: extension }))] })) : (_jsx("img", { src: picture, alt: "", loading: "lazy", className: "size-full object-cover" })) }));
34
- }
35
16
  export function Attachments({ files, onAdd, onRemove, onRestore, onOpen, onRetry, accept, multiple = true, max, mode, label, empty, now, }) {
36
17
  const copy = useUiCopy();
37
18
  const toast = useToastIfAny();
@@ -84,7 +65,7 @@ export function Attachments({ files, onAdd, onRemove, onRestore, onOpen, onRetry
84
65
  const nameId = `${base}-${index}-name`;
85
66
  const detailId = `${base}-${index}-detail`;
86
67
  const kind = attachmentKind(file.name, file.type);
87
- return (_jsxs("li", { "data-attachment-id": file.id, "data-status": status, className: "flex min-w-0 items-center gap-3 py-2", children: [_jsx(Thumb, { file: file, kind: kind }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [onOpen === undefined || status !== "ready" ? (_jsx("span", { id: nameId, title: file.name, className: "max-w-full truncate text-body font-medium text-ink", children: file.name })) : (_jsx("button", { type: "button", id: nameId, title: file.name, "data-attachment-name": true, "aria-describedby": detailId, onClick: () => onOpen(file), className: "max-w-full cursor-pointer truncate rounded-control text-left text-body font-medium text-ink outline-primary outline-offset-2 hover:underline hover:underline-offset-4 focus-visible:outline-2 forced-colors:outline-[Highlight]", children: file.name })), status === "uploading" ? (_jsx("div", { className: "w-full", children: _jsx(ProgressBar, { label: fillCopy(copy.attachments.uploading, { name: file.name }), width: "w-full", ...(file.progress === undefined ? {} : { value: file.progress }) }) })) : status === "failed" ? (
68
+ return (_jsxs("li", { "data-attachment-id": file.id, "data-status": status, className: "flex min-w-0 items-center gap-3 py-2", children: [_jsx(FileThumb, { file: file, kind: kind }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [onOpen === undefined || status !== "ready" ? (_jsx("span", { id: nameId, title: file.name, className: "max-w-full truncate text-body font-medium text-ink", children: file.name })) : (_jsx("button", { type: "button", id: nameId, title: file.name, "data-attachment-name": true, "aria-describedby": detailId, onClick: () => onOpen(file), className: "max-w-full cursor-pointer truncate rounded-control text-left text-body font-medium text-ink outline-primary outline-offset-2 hover:underline hover:underline-offset-4 focus-visible:outline-2 forced-colors:outline-[Highlight]", children: file.name })), status === "uploading" ? (_jsx("div", { className: "w-full", children: _jsx(ProgressBar, { label: fillCopy(copy.attachments.uploading, { name: file.name }), width: "w-full", ...(file.progress === undefined ? {} : { value: file.progress }) }) })) : status === "failed" ? (
88
69
  /* The icon AND the words: red alone is a colour some people do not see. */
89
70
  _jsxs("p", { id: detailId, role: "alert", className: "flex min-w-0 items-start gap-1.5 text-meta text-bad", children: [_jsx(TriangleAlert, { "aria-hidden": true, className: "mt-px size-(--size-icon-sm) shrink-0", strokeWidth: 2 }), _jsx("span", { className: "min-w-0", children: file.error ?? copy.attachments.failed })] })) : (_jsxs("p", { id: detailId, className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-meta text-muted", children: [file.size === undefined ? null : (_jsx("span", { className: "tabular-nums whitespace-nowrap", children: formatFileSize(file.size, copy.locale) })), file.by === undefined ? null : (_jsx(UserChip, { name: file.by, size: "sm", ...(file.byAvatar === undefined ? {} : { src: file.byAvatar }) })), file.at === undefined ? null : (_jsx(DateValue, { when: file.at, ...(now === undefined ? {} : { now }) }))] }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [status === "failed" && onRetry !== undefined ? (_jsx(Button, { role: "ghost", size: "sm", icon: RotateCcw, "aria-describedby": nameId, onClick: () => onRetry(file), children: copy.attachments.retry })) : null, status === "ready" && file.url !== undefined ? (_jsx(IconLink, { icon: Download, label: copy.attachments.download, href: file.url, download: file.name, tone: "normal", "aria-describedby": nameId })) : null, editable && onRemove !== undefined ? (_jsx(IconButton, { icon: status === "ready" ? Trash2 : X, label: status === "uploading"
90
71
  ? copy.attachments.cancelUpload
@@ -0,0 +1,28 @@
1
+ import { type AttachmentFile } from "./files.js";
2
+ export type FileListLayout = "cards" | "rows";
3
+ export type FileListProps = {
4
+ files: readonly AttachmentFile[];
5
+ /** `cards` (default): a file someone sent, under a message. `rows`: the files of
6
+ * something, in a bordered list. */
7
+ layout?: FileListLayout;
8
+ /** What these files are — «Assets», «Comprobantes» —, drawn with their count. Without it
9
+ * the list is named by `label`. */
10
+ title?: string;
11
+ /** The title folds the list (it needs a `title`). Open by default; `defaultOpen={false}`
12
+ * starts it folded. */
13
+ collapsible?: boolean;
14
+ defaultOpen?: boolean;
15
+ /** Open the file. Present = its name is a button; WHERE it opens is the application's. */
16
+ onOpen?: (file: AttachmentFile) => void;
17
+ /** Download by code. Present = every ready file has a download button that calls it,
18
+ * busy while its promise runs. Without it, a file with a `url` downloads by link. */
19
+ onDownload?: (file: AttachmentFile) => void | Promise<unknown>;
20
+ /** «Download all», shown when there are two or more files. */
21
+ onDownloadAll?: (files: readonly AttachmentFile[]) => void | Promise<unknown>;
22
+ /** The accessible name when there is no `title`. «Archivos» by default. */
23
+ label?: string;
24
+ /** The «now» the dates are relative to — so a story or a test does not change its text
25
+ * every minute. */
26
+ now?: Date;
27
+ };
28
+ export declare function FileList({ files, layout, title, collapsible, defaultOpen, onOpen, onDownload, onDownloadAll, label, now, }: FileListProps): import("react").JSX.Element | null;
@@ -0,0 +1,91 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { attachmentKind, fileExtension, formatFileSize, } from "./files.js";
4
+ import { FileThumb } from "./FileThumb.js";
5
+ import { fillCopy, useUiCopy } from "../../foundations/copy.js";
6
+ import { Button, IconButton, IconLink } from "../../primitives/button/Button.js";
7
+ import { Disclosure } from "../../primitives/disclosure/Disclosure.js";
8
+ import { DateValue } from "../../primitives/value/DateValue.js";
9
+ import { ProgressBar } from "../../primitives/value/ProgressBar.js";
10
+ import { Download, TriangleAlert } from "lucide-react";
11
+ import { useId, useState } from "react";
12
+ const add = (marks, id) => new Set(marks).add(id);
13
+ const drop = (marks, id) => {
14
+ const next = new Set(marks);
15
+ next.delete(id);
16
+ return next;
17
+ };
18
+ /* The ring every name shares, as a button or as a link. */
19
+ const NAME = "max-w-full cursor-pointer truncate rounded-control text-left font-medium text-ink outline-primary outline-offset-2 hover:underline hover:underline-offset-4 focus-visible:outline-2 forced-colors:outline-[Highlight]";
20
+ export function FileList({ files, layout = "cards", title, collapsible = false, defaultOpen = true, onOpen, onDownload, onDownloadAll, label, now, }) {
21
+ const copy = useUiCopy();
22
+ const base = useId();
23
+ const titleId = `${base}-title`;
24
+ const [pending, setPending] = useState(() => new Set());
25
+ const [failed, setFailed] = useState(() => new Set());
26
+ const [allPending, setAllPending] = useState(false);
27
+ const [allFailed, setAllFailed] = useState(false);
28
+ if (files.length === 0)
29
+ return null;
30
+ const download = async (file) => {
31
+ if (onDownload === undefined)
32
+ return;
33
+ setFailed((marks) => drop(marks, file.id));
34
+ setPending((marks) => add(marks, file.id));
35
+ try {
36
+ await onDownload(file);
37
+ }
38
+ catch {
39
+ setFailed((marks) => add(marks, file.id));
40
+ }
41
+ finally {
42
+ setPending((marks) => drop(marks, file.id));
43
+ }
44
+ };
45
+ const downloadAll = async () => {
46
+ if (onDownloadAll === undefined)
47
+ return;
48
+ setAllFailed(false);
49
+ setAllPending(true);
50
+ try {
51
+ await onDownloadAll(files);
52
+ }
53
+ catch {
54
+ setAllFailed(true);
55
+ }
56
+ finally {
57
+ setAllPending(false);
58
+ }
59
+ };
60
+ const cards = layout === "cards";
61
+ const list = (_jsx("ul", { ...(title === undefined
62
+ ? { "aria-label": label ?? copy.attachments.files }
63
+ : { "aria-labelledby": titleId }), className: cards
64
+ ? "flex min-w-0 flex-wrap gap-2"
65
+ : "flex min-w-0 flex-col divide-y divide-line rounded-box border border-line bg-surface", children: files.map((file, index) => {
66
+ const status = file.status ?? "ready";
67
+ const ready = status === "ready";
68
+ const nameId = `${base}-${index}-name`;
69
+ const kind = attachmentKind(file.name, file.type);
70
+ const busy = pending.has(file.id);
71
+ const extension = fileExtension(file.name).toUpperCase();
72
+ const name = ready && onOpen !== undefined ? (_jsx("button", { type: "button", id: nameId, title: file.name, onClick: () => onOpen(file), className: NAME, children: file.name })) : ready && file.url !== undefined && onDownload === undefined ? (_jsx("a", { id: nameId, href: file.url, download: file.name, title: file.name, className: NAME, children: file.name })) : (_jsx("span", { id: nameId, title: file.name, className: "max-w-full truncate font-medium text-ink", children: file.name }));
73
+ /* What the file is, or what is happening to it — in words: red alone is a colour some
74
+ people do not see. */
75
+ const detail = status === "uploading" ? (_jsx(ProgressBar, { label: fillCopy(copy.attachments.uploading, { name: file.name }), width: "w-full", ...(file.progress === undefined ? {} : { value: file.progress }) })) : status === "failed" || failed.has(file.id) ? (_jsxs("span", { role: "alert", className: "flex min-w-0 items-start gap-1.5 text-micro text-bad", children: [_jsx(TriangleAlert, { "aria-hidden": true, className: "mt-px size-(--size-icon-sm) shrink-0" }), _jsx("span", { className: "min-w-0", children: status === "failed"
76
+ ? (file.error ?? copy.attachments.failed)
77
+ : fillCopy(copy.attachments.downloadFailed, { name: file.name }) })] })) : (_jsxs("span", { className: "flex min-w-0 flex-wrap items-center gap-x-2 text-micro text-muted tabular-nums", children: [cards && extension !== "" ? _jsx("span", { children: extension }) : null, cards && extension !== "" && file.size !== undefined ? (_jsx("span", { "aria-hidden": true, children: "\u00B7" })) : null, file.size === undefined ? null : (_jsx("span", { className: "whitespace-nowrap", children: formatFileSize(file.size, copy.locale) })), !cards && file.at !== undefined ? (_jsx(DateValue, { when: file.at, ...(now === undefined ? {} : { now }) })) : null] }));
78
+ const action = !ready ? null : onDownload !== undefined ? (_jsx(IconButton, { icon: Download, label: copy.attachments.download, busy: busy, "aria-describedby": nameId, onClick: () => void download(file) })) : file.url !== undefined ? (_jsx(IconLink, { icon: Download, label: copy.attachments.download, href: file.url, download: file.name, tone: "normal", "aria-describedby": nameId })) : null;
79
+ return (_jsxs("li", { "data-ui": "file-list.file", "data-status": status, className: cards
80
+ ? "flex w-full max-w-sm min-w-0 items-center gap-3 rounded-box border border-line bg-surface p-2"
81
+ : "flex min-w-0 items-center gap-3 px-3 py-2", children: [_jsx(FileThumb, { file: file, kind: kind, size: cards ? "md" : "sm" }), cards ? (_jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5 text-meta", children: [name, detail] })) : (_jsxs("div", { className: "flex min-w-0 flex-1 flex-wrap items-center justify-between gap-x-3 gap-y-0.5 text-body", children: [name, detail] })), action] }, file.id));
82
+ }) }));
83
+ const all = onDownloadAll !== undefined && files.length > 1 ? (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [_jsx(Button, { role: "ghost", size: "sm", icon: Download, busy: allPending, onClick: () => void downloadAll(), children: copy.attachments.downloadAll }), allFailed ? (_jsx("span", { role: "alert", className: "text-micro text-bad", children: fillCopy(copy.attachments.downloadFailed, {
84
+ name: title ?? copy.attachments.files,
85
+ }) })) : null] })) : null;
86
+ const count = (_jsx("span", { className: "rounded-pill bg-ink/6 px-1.5 text-micro font-medium text-muted tabular-nums", children: files.length }));
87
+ if (title !== undefined && collapsible) {
88
+ return (_jsx("div", { "data-ui": "file-list", "data-layout": layout, className: "min-w-0", children: _jsx(Disclosure, { title: _jsxs("span", { id: titleId, className: "inline-flex items-center gap-2", children: [title, count] }), defaultExpanded: defaultOpen, children: _jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [list, all] }) }) }));
89
+ }
90
+ return (_jsxs("div", { "data-ui": "file-list", "data-layout": layout, className: "flex min-w-0 flex-col gap-2", children: [title === undefined ? null : (_jsxs("p", { id: titleId, className: "flex items-center gap-2 text-meta font-medium text-ink", children: [title, count] })), list, all] }));
91
+ }
@@ -0,0 +1,13 @@
1
+ import { type AttachmentFile, type AttachmentKind } from "./files.js";
2
+ /** The type, at the size of a row: the image itself when there is one, otherwise the icon
3
+ * of its kind over its extension. The extension is written because three of the five
4
+ * icons are a page with lines on it — «PDF» and «DOCX» are what tell them apart, and a
5
+ * word is never a colour that only some people see.
6
+ *
7
+ * `sm` is the icon alone, for a line of text (a list of a release's assets): the name next
8
+ * to it already ends in its extension. */
9
+ export declare function FileThumb({ file, kind, size, }: {
10
+ file: AttachmentFile;
11
+ kind: AttachmentKind;
12
+ size?: "sm" | "md";
13
+ }): import("react").JSX.Element;