@tristan2828/ui-foundation 4.130.2 → 4.131.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.
@@ -3,42 +3,43 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [Palettes](#palettes) · lines 51–160
7
- - [Glow](#glow) · lines 162–181
8
- - [Semantic tones](#semantic-tones) · lines 183–211
9
- - [The three badge styles](#the-three-badge-styles) · lines 213–230
10
- - [Status marks](#status-marks) · lines 232–277
11
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 279–308
12
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 310–323
13
- - [Logos and brand marks](#logos-and-brand-marks) · lines 325–369
14
- - [Categorical colour](#categorical-colour) · lines 371–441
15
- - [Heat scale](#heat-scale) · lines 443–504
16
- - [Depth ramps](#depth-ramps) · lines 506–591
17
- - [A stored colour](#a-stored-colour) · lines 593–650
18
- - [Shapes and sizes](#shapes-and-sizes) · lines 652–673
19
- - [Typography](#typography) · lines 675–846
20
- - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 709–742
21
- - [Written text (notes)](#written-text-notes) · lines 744–846
22
- - [Density](#density) · lines 848–941
23
- - [Rows on this device](#rows-on-this-device) · lines 914–941
24
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 943–1057
25
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1059–1136
26
- - [Notices](#notices) · lines 1138–1166
27
- - [A value over time](#a-value-over-time) · lines 1168–1254
28
- - [Several values over time](#several-values-over-time) · lines 1217–1254
29
- - [A list as a board](#a-list-as-a-board) · lines 1256–1307
30
- - [A list as cards](#a-list-as-cards) · lines 1309–1355
31
- - [Images full screen](#images-full-screen) · lines 1357–1403
32
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1405–1441
33
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1443–1513
34
- - [A few equal things](#a-few-equal-things) · lines 1515–1635
35
- - [An overview page](#an-overview-page) · lines 1637–1708
36
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1709–1775
37
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1777–1914
38
- - [Picking at random](#picking-at-random) · lines 1916–1947
39
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1949–2016
40
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 2018–2043
41
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2045–2141
6
+ - [Palettes](#palettes) · lines 52–161
7
+ - [Glow](#glow) · lines 163–182
8
+ - [Semantic tones](#semantic-tones) · lines 184–212
9
+ - [The three badge styles](#the-three-badge-styles) · lines 214–231
10
+ - [Status marks](#status-marks) · lines 233–278
11
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 280–309
12
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 311–324
13
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 326–370
14
+ - [Categorical colour](#categorical-colour) · lines 372–442
15
+ - [Heat scale](#heat-scale) · lines 444–505
16
+ - [Depth ramps](#depth-ramps) · lines 507–592
17
+ - [A stored colour](#a-stored-colour) · lines 594–651
18
+ - [Shapes and sizes](#shapes-and-sizes) · lines 653–674
19
+ - [Typography](#typography) · lines 676–847
20
+ - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 710–743
21
+ - [Written text (notes)](#written-text-notes) · lines 745–847
22
+ - [Density](#density) · lines 849–942
23
+ - [Rows on this device](#rows-on-this-device) · lines 915–942
24
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 944–1058
25
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1060–1137
26
+ - [Notices](#notices) · lines 1139–1167
27
+ - [A value over time](#a-value-over-time) · lines 1169–1255
28
+ - [Several values over time](#several-values-over-time) · lines 1218–1255
29
+ - [A list as a board](#a-list-as-a-board) · lines 1257–1373
30
+ - [Order, groups and the header (4.131)](#order-groups-and-the-header-4131) · lines 1310–1373
31
+ - [A list as cards](#a-list-as-cards) · lines 1375–1421
32
+ - [Images full screen](#images-full-screen) · lines 1423–1469
33
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1471–1507
34
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1509–1579
35
+ - [A few equal things](#a-few-equal-things) · lines 1581–1701
36
+ - [An overview page](#an-overview-page) · lines 1703–1774
37
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1775–1841
38
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1843–1980
39
+ - [Picking at random](#picking-at-random) · lines 1982–2013
40
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 2015–2082
41
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 2084–2109
42
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2111–2207
42
43
 
43
44
  <!-- /index -->
44
45
 
@@ -1306,6 +1307,71 @@ the table's.
1306
1307
  snap points; a phone shows one column at a time, with the edge of the
1307
1308
  next one showing.
1308
1309
 
1310
+ ### Order, groups and the header (4.131)
1311
+
1312
+ ```tsx
1313
+ <Board<Job, Stage, Size>
1314
+ aria-label="Jobs"
1315
+ columns={[
1316
+ { value: 'idea', label: 'Idea', lead: true, action: <AddButton />, description: 'Worth doing one day',
1317
+ groups: [{ value: 'quick', label: 'Quick' }, { value: 'big', label: 'Big', defaultOpen: false }],
1318
+ footer: <Link to="/jobs?size=someday">Someday {somedayCount}</Link> },
1319
+ { value: 'active', label: 'Active', note: `${waiting} waiting` },
1320
+ { value: 'done', label: 'Done', ordered: false },
1321
+ ]}
1322
+ getGroup={(job) => job.size}
1323
+ ordered
1324
+ pageSize={20}
1325
+ pageKey={filtersKey}
1326
+ phone="counts"
1327
+ menu={(job) => <JobMenuItems job={job} />}
1328
+ onMove={(job, stage, place) => save(job, stage, place.group, place.beforeId ?? afterOf(place.afterId))}
1329
+ {...rest}
1330
+ />
1331
+ ```
1332
+
1333
+ - **Order:** with `ordered`, cards keep `items`' order within their
1334
+ column (and group). A drag within a column reorders, and a 3px line in
1335
+ the text colour (`data-slot="board-drop-line"`) in the gap shows where
1336
+ the card lands; the card dragged is faded where it was. The card's menu
1337
+ has an Order section (Move Up, Move Down, Move to Top, disabled where
1338
+ they can't apply). After any menu move the focus is on the card's menu
1339
+ button wherever it now is, and the status line says "Moved <name> up"
1340
+ (or "down", "to the top"), "to <column>, <group>", or "to place 3 of 8
1341
+ in <column>" for a drag.
1342
+ - **`onMove(item, value, place)`:** `place.beforeId` is the card it now
1343
+ sits before and `place.afterId` the one after, among `items` in that
1344
+ column (and group), null at the end and the start. A server that orders
1345
+ by "before this id" takes `beforeId`; one that keeps a position takes
1346
+ the halfway point. The place counts every card in `items`, not only
1347
+ those shown: a drop after the last shown card is before the first one
1348
+ "Show N More" hides. A drop that leaves the card where it was calls
1349
+ nothing. A column with `ordered: false` (Done, by date) has no line, no
1350
+ Order items, and a drop there only changes the column.
1351
+ - **Groups:** a column's `groups` split its cards by `getGroup`, each a
1352
+ heading one level under the column's: a chevron, the label in small
1353
+ capitals and its count, a button that folds the group (`defaultOpen:
1354
+ false` starts folded). A drop on a group's cards reports that group; a
1355
+ drop on a folded group's heading outlines it and lands at the group's
1356
+ end. A card whose group isn't one of the column's isn't on the board.
1357
+ The keyboard's way to change group is the app's own field in `menu`
1358
+ (Priority, Size): Board's menu has no group section.
1359
+ - **Paging:** `pageSize` shows a column's (or each group's) first cards,
1360
+ then "Show N More"; `pageKey` changing (the filters) folds them back.
1361
+ - **The header's slots:** `description` is a caption under the name,
1362
+ `note` short muted text, `action` a control at the end (a +; the other
1363
+ columns keep the header's height), and `lead` outlines the column a
1364
+ list starts in.
1365
+ - **The phone's counts:** `phone="counts"` puts a row of buttons over the
1366
+ columns below `lg`, each a column's count over its `shortName`, that
1367
+ shows that one column (`aria-pressed`); from `lg` up, the columns as
1368
+ usual.
1369
+ - **The menu:** `menu(item)` appends the app's own items after a
1370
+ separator; the button is then ⋯, "Actions for <name>", holding Move To,
1371
+ Order and the app's items. Without it, the Move button as before.
1372
+ - **No grip:** a card that drags shows a grab hand over it, and is picked
1373
+ up whole, from its title link too.
1374
+
1309
1375
  ## A list as cards
1310
1376
 
1311
1377
  `DataTable`'s `layouts` (4.39) draw the same rows as cards beside the
@@ -0,0 +1,34 @@
1
+ export type BoardId = string | number;
2
+ /** Where a card now sits in its zone: the card it is before, and the one after it (null at the end, the start). */
3
+ export type BoardNeighbours = {
4
+ beforeId: BoardId | null;
5
+ afterId: BoardId | null;
6
+ };
7
+ /**
8
+ * A drop at `index` (0 to the cards shown) in a zone whose cards are `ids`
9
+ * (all of them, not only those shown: after the last shown card the card
10
+ * lands before the first hidden one). `dragged` is the card dropped. Null
11
+ * when the drop leaves the card between the neighbours it has now.
12
+ */
13
+ export declare function dropPlace(ids: readonly BoardId[], index: number, dragged: BoardId): BoardNeighbours | null;
14
+ /** The end of a zone, for a card that isn't in it yet (or is, and leaves its place for the end). */
15
+ export declare function endPlace(ids: readonly BoardId[], card: BoardId): BoardNeighbours;
16
+ /** The card's neighbours in its zone now. */
17
+ export declare function neighboursOf(ids: readonly BoardId[], card: BoardId): BoardNeighbours | null;
18
+ export type BoardOrderKind = 'up' | 'down' | 'top';
19
+ /**
20
+ * Where the menu's Order items put a card within its zone: up (before the
21
+ * card above it), down (after the card below it), to the top (before the
22
+ * zone's first card). Undefined where one can't apply: the first card can't
23
+ * go up or to the top, the last can't go down.
24
+ */
25
+ export declare function orderTargets(ids: readonly BoardId[], card: BoardId): Record<BoardOrderKind, BoardNeighbours | undefined>;
26
+ /** The card's place (1 to n) in its zone once it sits between `place`'s neighbours. */
27
+ export declare function placeNumber(ids: readonly BoardId[], card: BoardId, place: BoardNeighbours): {
28
+ k: number;
29
+ n: number;
30
+ };
31
+ /** The cards a zone shows: its first `pageSize` times the pages opened, or all of them. */
32
+ export declare function shownCount(total: number, pageSize: number | undefined, pages: number): number;
33
+ /** "Show N More": the smaller of a page and what's left. 0 when nothing is left. */
34
+ export declare function moreCount(total: number, pageSize: number | undefined, pages: number): number;
@@ -0,0 +1,60 @@
1
+ const same = (a, b) => (a === null || b === null ? a === b : String(a) === String(b));
2
+ /**
3
+ * A drop at `index` (0 to the cards shown) in a zone whose cards are `ids`
4
+ * (all of them, not only those shown: after the last shown card the card
5
+ * lands before the first hidden one). `dragged` is the card dropped. Null
6
+ * when the drop leaves the card between the neighbours it has now.
7
+ */
8
+ export function dropPlace(ids, index, dragged) {
9
+ const at = Math.max(0, Math.min(index, ids.length));
10
+ const afterId = at > 0 ? ids[at - 1] : null;
11
+ const beforeId = at < ids.length ? ids[at] : null;
12
+ if (same(afterId, dragged) || same(beforeId, dragged))
13
+ return null;
14
+ return { beforeId, afterId };
15
+ }
16
+ /** The end of a zone, for a card that isn't in it yet (or is, and leaves its place for the end). */
17
+ export function endPlace(ids, card) {
18
+ const rest = ids.filter((id) => !same(id, card));
19
+ return { beforeId: null, afterId: rest.length > 0 ? rest[rest.length - 1] : null };
20
+ }
21
+ /** The card's neighbours in its zone now. */
22
+ export function neighboursOf(ids, card) {
23
+ const at = ids.findIndex((id) => same(id, card));
24
+ if (at < 0)
25
+ return null;
26
+ return { beforeId: at + 1 < ids.length ? ids[at + 1] : null, afterId: at > 0 ? ids[at - 1] : null };
27
+ }
28
+ /**
29
+ * Where the menu's Order items put a card within its zone: up (before the
30
+ * card above it), down (after the card below it), to the top (before the
31
+ * zone's first card). Undefined where one can't apply: the first card can't
32
+ * go up or to the top, the last can't go down.
33
+ */
34
+ export function orderTargets(ids, card) {
35
+ const at = ids.findIndex((id) => same(id, card));
36
+ if (at < 0)
37
+ return { up: undefined, down: undefined, top: undefined };
38
+ return {
39
+ up: at > 0 ? { beforeId: ids[at - 1], afterId: at > 1 ? ids[at - 2] : null } : undefined,
40
+ down: at < ids.length - 1 ? { beforeId: at + 2 < ids.length ? ids[at + 2] : null, afterId: ids[at + 1] } : undefined,
41
+ top: at > 0 ? { beforeId: ids[0], afterId: null } : undefined,
42
+ };
43
+ }
44
+ /** The card's place (1 to n) in its zone once it sits between `place`'s neighbours. */
45
+ export function placeNumber(ids, card, place) {
46
+ const rest = ids.filter((id) => !same(id, card));
47
+ const before = place.beforeId === null ? -1 : rest.findIndex((id) => same(id, place.beforeId));
48
+ const k = (before < 0 ? rest.length : before) + 1;
49
+ return { k, n: rest.length + 1 };
50
+ }
51
+ /** The cards a zone shows: its first `pageSize` times the pages opened, or all of them. */
52
+ export function shownCount(total, pageSize, pages) {
53
+ return pageSize === undefined ? total : Math.min(total, pageSize * pages);
54
+ }
55
+ /** "Show N More": the smaller of a page and what's left. 0 when nothing is left. */
56
+ export function moreCount(total, pageSize, pages) {
57
+ if (pageSize === undefined)
58
+ return 0;
59
+ return Math.min(pageSize, total - shownCount(total, pageSize, pages));
60
+ }
@@ -1,6 +1,30 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { AppError } from '../../api/contracts.js';
3
- export type BoardColumn<V extends string> = {
3
+ import { type BoardId } from './board-order.js';
4
+ /** A group of a column's cards: a heading that folds them. */
5
+ export type BoardGroup<G extends string = string> = {
6
+ /** The value `getGroup` gives this group's cards. */
7
+ value: G;
8
+ /** The heading, plain text: shown in small capitals, and heard after a move. */
9
+ label: string;
10
+ /** Beside the heading. Omitted: the group's cards on the board are counted. */
11
+ count?: number;
12
+ /** Open at first. Default true. */
13
+ defaultOpen?: boolean;
14
+ /** The line an empty group shows. Default "Nothing here". */
15
+ empty?: ReactNode;
16
+ /** Under the group's cards. */
17
+ footer?: ReactNode;
18
+ };
19
+ /** Where a move put a card: its group, and its new neighbours on an ordered column (both null otherwise). */
20
+ export type BoardPlace<G extends string = string> = {
21
+ group?: G;
22
+ /** The card it now sits before, among `items` in that column (and group); null at the end. */
23
+ beforeId: BoardId | null;
24
+ /** The card it now sits after; null at the start. */
25
+ afterId: BoardId | null;
26
+ };
27
+ export type BoardColumn<V extends string, G extends string = string> = {
4
28
  /** The field's value this column holds. */
5
29
  value: V;
6
30
  /** The column's heading: a word, or a glyph and a word. */
@@ -17,16 +41,30 @@ export type BoardColumn<V extends string> = {
17
41
  empty?: ReactNode;
18
42
  /** Under the cards: "Showing 100 of 240", a link to the whole list. */
19
43
  footer?: ReactNode;
44
+ /** The column's groups, in order (4.131). Needs the board's `getGroup`. */
45
+ groups?: readonly BoardGroup<G>[];
46
+ /** Default: the board's `ordered`. `false` gives this column no order (4.131). */
47
+ ordered?: boolean;
48
+ /** A caption under the column's name (4.131). */
49
+ description?: ReactNode;
50
+ /** A control at the end of the header, a + (4.131). */
51
+ action?: ReactNode;
52
+ /** Short muted text in the header before the action: "3 need review" (4.131). */
53
+ note?: ReactNode;
54
+ /** The lead column, outlined: where the list starts (4.131). */
55
+ lead?: boolean;
56
+ /** Its name in the phone's row of counts (4.131). Default: its name. */
57
+ shortName?: string;
20
58
  };
21
59
  /** A value a card can be moved to from its Move menu. */
22
60
  export type BoardMoveTarget<V extends string> = {
23
61
  value: V;
24
62
  label: string;
25
63
  };
26
- export type BoardProps<T, V extends string> = {
64
+ export type BoardProps<T, V extends string, G extends string = string> = {
27
65
  /** Names the board as a whole ("Tasks by status"). */
28
66
  'aria-label': string;
29
- columns: readonly BoardColumn<V>[];
67
+ columns: readonly BoardColumn<V, G>[];
30
68
  items: readonly T[];
31
69
  getId: (item: T) => string | number;
32
70
  /** The record's value of the field: which column its card is in. */
@@ -34,12 +72,24 @@ export type BoardProps<T, V extends string> = {
34
72
  /** What the Move button calls the record: "Move <name>". */
35
73
  getName: (item: T) => string;
36
74
  renderCard: (item: T) => ReactNode;
37
- /** Saves the record's new value. Omitted: a read-only board. */
38
- onMove?: (item: T, value: V) => void;
75
+ /** Saves the record's new value, and its place. Omitted: a read-only board. */
76
+ onMove?: (item: T, value: V, place: BoardPlace<G>) => void;
39
77
  /** The Move menu's choices. Default: the columns, by their `name`. */
40
78
  moveTo?: readonly BoardMoveTarget<V>[];
41
79
  /** The columns' heading level: 2 under the page's h1 (the default), deeper under a section. */
42
80
  headingLevel?: 2 | 3 | 4 | 5 | 6;
81
+ /** Cards keep `items`' order and can be reordered (4.131). Only with `onMove`. */
82
+ ordered?: boolean;
83
+ /** Which group of its column a card is in (4.131), for a column with `groups`. */
84
+ getGroup?: (item: T) => G;
85
+ /** Each column, or group, shows this many cards, then "Show N More" (4.131). */
86
+ pageSize?: number;
87
+ /** When it changes, every column and group goes back to its first page (4.131). */
88
+ pageKey?: string;
89
+ /** The app's own items, after the board's in the card's menu (4.131). */
90
+ menu?: (item: T) => ReactNode;
91
+ /** Below lg: one column with the next one's edge (`swipe`, the default), or a row of counts that picks it (4.131). */
92
+ phone?: 'swipe' | 'counts';
43
93
  isLoading?: boolean;
44
94
  error?: AppError | null;
45
95
  onRetry?: () => void;
@@ -47,4 +97,4 @@ export type BoardProps<T, V extends string> = {
47
97
  emptyDescription?: ReactNode;
48
98
  emptyAction?: ReactNode;
49
99
  };
50
- export declare function Board<T, V extends string>({ 'aria-label': ariaLabel, columns, items, getId, getColumn, getName, renderCard, onMove, moveTo, headingLevel, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, }: BoardProps<T, V>): import("react").JSX.Element;
100
+ export declare function Board<T, V extends string, G extends string = string>({ 'aria-label': ariaLabel, columns, items, getId, getColumn, getName, renderCard, onMove, moveTo, headingLevel, ordered, getGroup, pageSize, pageKey, menu, phone, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, }: BoardProps<T, V, G>): import("react").JSX.Element;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  // A board: a column per value of one choice field (a status, a stage), a
3
3
  // card per record, and a record moved by moving its card. A second way to
4
4
  // look at a list, beside its DataTable, never instead of it: filters, sort
@@ -9,22 +9,37 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
9
  // which may be more than the cards loaded), an `empty` line, and a
10
10
  // `footer` ("Showing 100 of 240", a link to the filtered list). A
11
11
  // column whose `label` isn't plain text gives its `name` for the Move
12
- // menu and what a screen reader hears after a move.
12
+ // menu and what a screen reader hears after a move. A column's header
13
+ // may also hold a `description` (a caption under the name), a `note`
14
+ // and an `action` (a +); `lead` outlines the column the list starts in.
13
15
  // - Cards: every record in `items` whose `getColumn` is one of the
14
16
  // columns' values, in `items`' order; a record whose value has no column
15
17
  // isn't shown. `renderCard` is the card's content: the title (a link to
16
18
  // the record's page) and a few values.
19
+ // - Groups (4.131): a column with `groups` splits its cards by `getGroup`,
20
+ // each group a heading with its count that folds its cards. A card whose
21
+ // group isn't one of the column's isn't shown.
22
+ // - Order (4.131): with `ordered`, cards keep `items`' order and a drag
23
+ // within a column (or a group) reorders them, a line showing where the
24
+ // card will land; the menu has Move Up, Move Down and Move to Top. A
25
+ // column with `ordered: false` (a Done column, by date) has none of it.
26
+ // - Paging (4.131): with `pageSize`, a column or a group shows its first
27
+ // cards, then "Show N More". `pageKey` changing (the filters) folds every
28
+ // one back to its first page.
17
29
  // - Moving: with `onMove`, a card drags to another column (a pointer) and
18
30
  // has a Move button (a menu of `moveTo`, by default the columns: the
19
31
  // keyboard and a phone, where there is no drag). `moveTo` may add values
20
32
  // with no column, such as Dropped, which take the card off the board.
21
- // After a move from the menu the focus goes back to the card's Move
22
- // button in its new column (to the board, if the card left it), and a
23
- // status line says where the card went.
33
+ // With `menu`, the button is ⋯ ("Actions for <name>") and holds the app's
34
+ // own items too. After a move from the menu the focus goes back to the
35
+ // card's menu button where it now is (to the board, if the card left it),
36
+ // and a status line says where the card went.
24
37
  // Without `onMove` the board is read-only: a computed field.
25
- // `onMove(item, value)` is the save; the app makes it optimistic
26
- // (useRecordUpdate), so placing cards by `getColumn` on the record shows
27
- // a move at once, and a refusal puts the card back.
38
+ // `onMove(item, value, place)` is the save: `place` is the card's group
39
+ // and its new neighbours (`beforeId`, `afterId`) on an ordered column.
40
+ // The app makes it optimistic (useRecordUpdate), so placing cards by
41
+ // `getColumn` on the record shows a move at once, and a refusal puts the
42
+ // card back.
28
43
  // - States: `isLoading` (skeleton columns), `error` (ErrorState with
29
44
  // `onRetry`), and an empty board (`emptyTitle`, `emptyDescription`,
30
45
  // `emptyAction`), each for the board as a whole; an empty column is not
@@ -32,100 +47,331 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
32
47
  //
33
48
  // Columns share the width, at least 16rem each, and scroll sideways with
34
49
  // snap points when they don't fit. A phone shows one column at a time,
35
- // with the edge of the next one showing.
50
+ // with the edge of the next one showing; `phone="counts"` shows a row of
51
+ // the columns' counts instead, below lg, that picks the one column shown.
36
52
  import { useEffect, useId, useRef, useState } from 'react';
37
- import { ArrowRightLeftIcon } from 'lucide-react';
53
+ import { ArrowRightLeftIcon, ChevronDownIcon, ChevronRightIcon, EllipsisIcon } from 'lucide-react';
38
54
  import { cn } from 'cn';
39
55
  import { ErrorState } from './error-state.js';
40
56
  import { Button } from '../ui/button.js';
41
57
  import { Card } from '../ui/card.js';
42
- import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
58
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
43
59
  import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle } from '../ui/empty.js';
44
60
  import { Skeleton } from '../ui/skeleton.js';
61
+ import { dropPlace, endPlace, moreCount, neighboursOf, orderTargets, placeNumber, shownCount, } from './board-order.js';
45
62
  // The drag's data type: a card of this board, and nothing a drop from
46
63
  // elsewhere (a file, a link) carries.
47
64
  const DRAG_TYPE = 'application/x-ui-foundation-board-card';
48
65
  // At least 16rem, sharing the width; on a phone the board's width less 2rem,
49
66
  // so the next column's edge shows there is more to scroll to.
50
67
  const COLUMN_WIDTH = 'min-w-[calc(100%-2rem)] flex-1 basis-0 sm:min-w-64';
68
+ // The phone's counts row picks one column, the board's whole width below lg.
69
+ const COUNTS_COLUMN_WIDTH = 'min-w-0 flex-1 basis-0 lg:min-w-64';
70
+ // The drop line (1A): 3px in the text colour, inset 4px, centred in the
71
+ // 8px gap above (or below) a card.
72
+ const DROP_LINE = 'pointer-events-none absolute inset-x-1 h-[3px] rounded-full bg-foreground';
51
73
  const columnName = (column) => column.name ?? (typeof column.label === 'string' ? column.label : column.value);
52
- export function Board({ 'aria-label': ariaLabel, columns, items, getId, getColumn, getName, renderCard, onMove, moveTo, headingLevel = 2, isLoading = false, error = null, onRetry, emptyTitle = 'Nothing here yet', emptyDescription, emptyAction, }) {
74
+ const sameId = (a, b) => (a === null || b === null ? a === b : String(a) === String(b));
75
+ const zoneKey = (value, group) => (group === undefined ? value : `${value}\u0000${group}`);
76
+ const ORDER_WORDS = { up: 'up', down: 'down', top: 'to the top' };
77
+ // Where in a zone's shown cards a drag's pointer is: before or after the
78
+ // card under it (its top or bottom half), or after the last when on none.
79
+ function pointerIndex(event, shownIds) {
80
+ const card = event.target.closest('[data-board-card]');
81
+ const at = card ? shownIds.findIndex((id) => String(id) === card.getAttribute('data-board-card')) : -1;
82
+ if (card === null || at < 0)
83
+ return shownIds.length;
84
+ const box = card.getBoundingClientRect();
85
+ return at + (event.clientY > box.top + box.height / 2 ? 1 : 0);
86
+ }
87
+ export function Board({ 'aria-label': ariaLabel, columns, items, getId, getColumn, getName, renderCard, onMove, moveTo, headingLevel = 2, ordered = false, getGroup, pageSize, pageKey, menu, phone = 'swipe', isLoading = false, error = null, onRetry, emptyTitle = 'Nothing here yet', emptyDescription, emptyAction, }) {
53
88
  const boardRef = useRef(null);
89
+ const boardId = useId();
54
90
  const [announcement, setAnnouncement] = useState('');
55
- // A move from the Move menu, until its card is in its new column or off
56
- // the board. The card is remounted there, so the Move button that had
57
- // the focus is gone: its new one takes the focus, or the board does.
91
+ // The card being dragged: the native events come faster than React
92
+ // renders, and dragover can't read the drag's data, so a ref holds it.
93
+ const dragging = useRef(null);
94
+ const [dragId, setDragId] = useState(null);
95
+ const [over, setOver] = useState(null);
96
+ const [pages, setPages] = useState({ key: pageKey, open: {} });
97
+ const [folded, setFolded] = useState({});
98
+ const [phoneColumn, setPhoneColumn] = useState(undefined);
99
+ // A move from the menu, until its card is where it was sent. A card moved
100
+ // to another column is remounted there, so the button that had the focus
101
+ // is gone: its new one takes the focus, or the board does.
58
102
  const moved = useRef(null);
59
103
  useEffect(() => {
60
104
  const pending = moved.current;
61
105
  if (pending === null)
62
106
  return;
63
107
  const item = items.find((candidate) => String(getId(candidate)) === pending.id);
64
- if (item !== undefined && getColumn(item) !== pending.value)
65
- return;
108
+ if (item !== undefined) {
109
+ if (getColumn(item) !== pending.value)
110
+ return;
111
+ if (pending.group !== undefined && getGroup?.(item) !== pending.group)
112
+ return;
113
+ if (pending.neighbours !== undefined) {
114
+ const ids = items
115
+ .filter((candidate) => getColumn(candidate) === pending.value && (pending.group === undefined || getGroup?.(candidate) === pending.group))
116
+ .map(getId);
117
+ const now = neighboursOf(ids, pending.id);
118
+ if (now === null || !sameId(now.beforeId, pending.neighbours.beforeId) || !sameId(now.afterId, pending.neighbours.afterId))
119
+ return;
120
+ }
121
+ }
66
122
  moved.current = null;
67
123
  const board = boardRef.current;
68
- // Only when the focus was lost with the old button, never taken from
69
- // wherever the user has gone since.
70
- if (board === null || (document.activeElement !== null && document.activeElement !== document.body))
124
+ if (board === null)
71
125
  return;
72
126
  const button = Array.from(board.querySelectorAll('[data-board-move]')).find((candidate) => candidate.dataset.boardMove === pending.id);
127
+ // Only when the focus was lost with the old button (or is still on it),
128
+ // never taken from wherever the user has gone since.
129
+ const active = document.activeElement;
130
+ if (active !== null && active !== document.body && active !== button)
131
+ return;
73
132
  (button ?? board).focus();
74
- }, [items, getId, getColumn]);
133
+ }, [items, getId, getColumn, getGroup]);
75
134
  if (error) {
76
135
  return (_jsx("div", { "data-slot": "board", "data-state": "error", children: _jsx(ErrorState, { error: error, onRetry: onRetry }) }));
77
136
  }
78
137
  if (isLoading) {
79
138
  return (_jsx("div", { "data-slot": "board", "data-state": "loading", role: "group", "aria-busy": "true", "aria-label": ariaLabel, className: "flex gap-3 overflow-x-auto pb-2", children: columns.map((column) => (_jsxs("div", { className: cn('flex flex-col gap-2 rounded-lg bg-muted p-2 [--muted-foreground:var(--table-highlight-muted-foreground)]', COLUMN_WIDTH), children: [_jsx(Skeleton, { className: "h-5 w-24" }), _jsx(Skeleton, { className: "h-20 w-full" }), _jsx(Skeleton, { className: "h-20 w-full" })] }, column.value))) }));
80
139
  }
81
- const shown = items.filter((item) => columns.some((column) => column.value === getColumn(item)));
140
+ const groupOf = (item) => getGroup?.(item);
141
+ const inColumn = (item, column) => getColumn(item) === column.value && (column.groups === undefined || column.groups.some((group) => group.value === groupOf(item)));
142
+ const shown = items.filter((item) => columns.some((column) => inColumn(item, column)));
82
143
  if (shown.length === 0) {
83
144
  return (_jsx("div", { "data-slot": "board", "data-state": "empty", children: _jsxs(Empty, { children: [_jsxs(EmptyHeader, { children: [_jsx(EmptyTitle, { children: emptyTitle }), emptyDescription && _jsx(EmptyDescription, { children: emptyDescription })] }), emptyAction && _jsx(EmptyContent, { children: emptyAction })] }) }));
84
145
  }
85
146
  const targets = moveTo ?? columns.map((column) => ({ value: column.value, label: columnName(column) }));
86
- const move = (id, value, from) => {
87
- const item = items.find((candidate) => String(getId(candidate)) === id);
147
+ const isOrdered = (column) => onMove !== undefined && column !== undefined && (column.ordered ?? ordered);
148
+ const zoneItems = (value, group) => items.filter((item) => getColumn(item) === value && (group === undefined || groupOf(item) === group));
149
+ const zoneIds = (value, group) => zoneItems(value, group).map(getId);
150
+ const pagesOf = (zone) => (pages.key === pageKey ? (pages.open[zone] ?? 1) : 1);
151
+ const showMore = (zone) => setPages((was) => {
152
+ const open = was.key === pageKey ? was.open : {};
153
+ return { key: pageKey, open: { ...open, [zone]: (open[zone] ?? 1) + 1 } };
154
+ });
155
+ const whereLabel = (value, group) => {
156
+ const column = columns.find((candidate) => candidate.value === value);
157
+ const where = targets.find((target) => target.value === value)?.label ?? (column ? columnName(column) : value);
158
+ const groupLabel = group === undefined ? undefined : column?.groups?.find((candidate) => candidate.value === group)?.label;
159
+ return groupLabel === undefined ? where : `${where}, ${groupLabel}`;
160
+ };
161
+ const save = (item, value, place, message, pending) => {
162
+ setAnnouncement(message);
163
+ if (pending)
164
+ moved.current = pending;
165
+ onMove?.(item, value, place);
166
+ };
167
+ const find = (id) => items.find((candidate) => String(getId(candidate)) === id);
168
+ // The Move To menu: to the end of the column (the card's own group, when
169
+ // it's one of the column's), or off the board.
170
+ const moveToValue = (id, value) => {
171
+ const item = find(id);
88
172
  if (onMove === undefined || item === undefined || getColumn(item) === value)
89
173
  return;
90
174
  const column = columns.find((candidate) => candidate.value === value);
91
- const where = targets.find((target) => target.value === value)?.label ?? (column ? columnName(column) : value);
92
- setAnnouncement(`Moved ${getName(item)} to ${where}`);
93
- if (from === 'menu')
94
- moved.current = { id, value };
95
- onMove(item, value);
175
+ const own = groupOf(item);
176
+ const group = column?.groups?.some((candidate) => candidate.value === own) ? own : undefined;
177
+ const place = isOrdered(column) && (column?.groups === undefined || group !== undefined)
178
+ ? { group, ...endPlace(zoneIds(value, group), id) }
179
+ : { group, beforeId: null, afterId: null };
180
+ save(item, value, place, `Moved ${getName(item)} to ${whereLabel(value, group)}`, { id, value, group });
96
181
  };
97
- return (_jsxs("div", { ref: boardRef, "data-slot": "board", "data-state": "success", role: "group", "aria-label": ariaLabel, tabIndex: -1, className: "flex snap-x snap-mandatory gap-3 overflow-x-auto pb-2 outline-none", children: [columns.map((column) => {
98
- const cards = shown.filter((item) => getColumn(item) === column.value);
99
- return (_jsxs(BoardColumnView, { column: column, count: column.count ?? cards.length, headingLevel: headingLevel, onDrop: onMove ? (id) => move(id, column.value, 'drag') : undefined, children: [cards.map((item) => (_jsx(Card, { size: "sm", "data-slot": "board-card", draggable: onMove ? true : undefined, onDragStart: onMove
100
- ? (event) => {
101
- event.dataTransfer.setData(DRAG_TYPE, String(getId(item)));
102
- event.dataTransfer.effectAllowed = 'move';
103
- }
104
- : undefined, className: cn('glow-edge gap-2 px-3 py-3', onMove && 'cursor-grab active:cursor-grabbing'), children: _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: renderCard(item) }), onMove && (_jsx(MoveMenu, { id: String(getId(item)), name: getName(item), value: getColumn(item), targets: targets, onMove: (value) => move(String(getId(item)), value, 'menu') }))] }) }, getId(item)))), cards.length === 0 && (_jsx("p", { className: "px-1 py-6 text-center type-caption text-muted-foreground", children: column.empty ?? 'Nothing here' })), column.footer && _jsx("div", { className: "px-1 type-caption text-muted-foreground", children: column.footer })] }, column.value));
105
- }), _jsx("span", { role: "status", className: "sr-only", children: announcement })] }));
106
- }
107
- function BoardColumnView({ column, count, headingLevel, onDrop, children, }) {
108
- const [over, setOver] = useState(false);
109
- const headingId = useId();
110
- const Heading = `h${headingLevel}`;
111
- const accepts = (event) => onDrop !== undefined && event.dataTransfer.types.includes(DRAG_TYPE);
112
- return (_jsxs("section", { "aria-labelledby": headingId, "data-slot": "board-column", "data-over": over || undefined, className: cn('flex snap-start flex-col gap-2 rounded-lg bg-muted p-2 [--muted-foreground:var(--table-highlight-muted-foreground)] outline-2 outline-offset-2 outline-transparent data-over:outline-ring', COLUMN_WIDTH), onDragOver: (event) => {
182
+ // The menu's Order items, within the card's own zone.
183
+ const orderCard = (item, kind) => {
184
+ const value = getColumn(item);
185
+ const column = columns.find((candidate) => candidate.value === value);
186
+ const group = column?.groups ? groupOf(item) : undefined;
187
+ const id = String(getId(item));
188
+ const target = orderTargets(zoneIds(value, group), id)[kind];
189
+ if (target === undefined)
190
+ return;
191
+ save(item, value, { group, ...target }, `Moved ${getName(item)} ${ORDER_WORDS[kind]}`, { id, value, group, neighbours: target });
192
+ };
193
+ // A drop into a zone at an index of its cards (its end, for a folded group).
194
+ const dropInto = (value, group, index) => {
195
+ const id = dragging.current;
196
+ const item = id === null ? undefined : find(id);
197
+ if (onMove === undefined || id === null || item === undefined)
198
+ return;
199
+ const column = columns.find((candidate) => candidate.value === value);
200
+ const sameZone = getColumn(item) === value && (group === undefined || groupOf(item) === group);
201
+ let place;
202
+ if (isOrdered(column)) {
203
+ const ids = zoneIds(value, group);
204
+ const at = dropPlace(ids, index, id);
205
+ if (at === null)
206
+ return;
207
+ place = { group, ...at };
208
+ if (sameZone) {
209
+ const { k, n } = placeNumber(ids, id, at);
210
+ save(item, value, place, `Moved ${getName(item)} to place ${k} of ${n} in ${column ? columnName(column) : value}`);
211
+ return;
212
+ }
213
+ }
214
+ else {
215
+ if (sameZone)
216
+ return;
217
+ place = { group, beforeId: null, afterId: null };
218
+ }
219
+ save(item, value, place, `Moved ${getName(item)} to ${whereLabel(value, group)}`);
220
+ };
221
+ const endDrag = () => {
222
+ dragging.current = null;
223
+ setDragId(null);
224
+ setOver(null);
225
+ };
226
+ const accepts = (event) => onMove !== undefined && event.dataTransfer.types.includes(DRAG_TYPE);
227
+ // The drag-over and drop handlers of an ordered zone (a column, or a
228
+ // group): the line follows the pointer; a folded group drops at its end.
229
+ const zoneHandlers = (zone, value, group, shownIds, foldedTo) => ({
230
+ onDragOver: (event) => {
113
231
  if (!accepts(event))
114
232
  return;
115
233
  event.preventDefault();
234
+ event.stopPropagation();
116
235
  event.dataTransfer.dropEffect = 'move';
117
- setOver(true);
118
- }, onDragLeave: (event) => {
236
+ const index = foldedTo ?? pointerIndex(event, shownIds);
237
+ if (over?.zone !== zone || over.index !== index)
238
+ setOver({ zone, index });
239
+ },
240
+ onDragLeave: (event) => {
119
241
  if (!event.currentTarget.contains(event.relatedTarget))
120
- setOver(false);
121
- }, onDrop: (event) => {
122
- setOver(false);
242
+ setOver((was) => (was?.zone === zone ? null : was));
243
+ },
244
+ onDrop: (event) => {
123
245
  if (!accepts(event))
124
246
  return;
125
247
  event.preventDefault();
126
- onDrop?.(event.dataTransfer.getData(DRAG_TYPE));
127
- }, children: [_jsxs(Heading, { id: headingId, className: "flex items-center gap-2 px-1 pt-0.5 type-label", children: [column.label, _jsx("span", { className: "font-normal tabular-nums text-muted-foreground", children: count })] }), children] }));
248
+ event.stopPropagation();
249
+ dropInto(value, group, foldedTo ?? pointerIndex(event, shownIds));
250
+ endDrag();
251
+ },
252
+ });
253
+ const anyAction = columns.some((column) => column.action !== undefined);
254
+ const counts = phone === 'counts';
255
+ const chosen = phoneColumn ?? columns[0]?.value;
256
+ const columnId = (value) => `${boardId}-column-${value}`;
257
+ // One card. On an ordered column it sits in a slot that holds the drop
258
+ // line (the card itself clips what overflows it).
259
+ const cardView = (item, column, zone, index, shownLength) => {
260
+ const id = String(getId(item));
261
+ const ordering = isOrdered(column);
262
+ const value = getColumn(item);
263
+ const group = column.groups ? groupOf(item) : undefined;
264
+ const order = ordering ? orderTargets(zoneIds(value, group), id) : undefined;
265
+ const card = (_jsx(Card, { size: "sm", "data-slot": "board-card", "data-board-card": ordering ? id : undefined, draggable: onMove ? true : undefined, onDragStart: onMove
266
+ ? (event) => {
267
+ // Picked up by its title link or anywhere else: the whole
268
+ // card is what's dragged, not the link's text.
269
+ const box = event.currentTarget.getBoundingClientRect();
270
+ event.dataTransfer.setDragImage(event.currentTarget, event.clientX - box.left, event.clientY - box.top);
271
+ event.dataTransfer.setData(DRAG_TYPE, id);
272
+ event.dataTransfer.effectAllowed = 'move';
273
+ dragging.current = id;
274
+ setDragId(id);
275
+ }
276
+ : undefined, onDragEnd: onMove ? endDrag : undefined, className: cn('glow-edge gap-2 px-3 py-3', onMove && 'cursor-grab active:cursor-grabbing', ordering && dragId === id && 'opacity-50'), children: _jsxs("div", { className: "flex items-start gap-2", children: [_jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: renderCard(item) }), onMove && (_jsx(CardMenu, { id: id, name: getName(item), value: value, targets: targets, onMove: (next) => moveToValue(id, next), order: order && {
277
+ allowed: { up: order.up !== undefined, down: order.down !== undefined, top: order.top !== undefined },
278
+ run: (kind) => orderCard(item, kind),
279
+ }, extra: menu?.(item) }))] }) }, getId(item)));
280
+ if (!ordering)
281
+ return card;
282
+ const line = over?.zone === zone ? (over.index === index ? 'before' : over.index >= shownLength && index === shownLength - 1 ? 'after' : null) : null;
283
+ return (_jsxs("div", { "data-slot": "board-card-slot", className: "relative", children: [line && _jsx("span", { "aria-hidden": "true", "data-slot": "board-drop-line", className: cn(DROP_LINE, line === 'before' ? '-top-[5.5px]' : '-bottom-[5.5px]') }), card] }, getId(item)));
284
+ };
285
+ // A zone's cards: its first page, "Show N More", or its empty line.
286
+ const zoneCards = (column, zone, cards, empty) => {
287
+ const page = pagesOf(zone);
288
+ const visible = cards.slice(0, shownCount(cards.length, pageSize, page));
289
+ const more = moreCount(cards.length, pageSize, page);
290
+ const lineInEmpty = isOrdered(column) && cards.length === 0 && over?.zone === zone;
291
+ return (_jsxs(_Fragment, { children: [visible.map((item, index) => cardView(item, column, zone, index, visible.length)), more > 0 && (_jsxs(Button, { variant: "ghost", size: "sm", className: "self-start", onClick: () => showMore(zone), children: ["Show ", more, " More"] })), cards.length === 0 && (_jsxs("p", { className: cn('px-1 py-6 text-center type-caption text-muted-foreground', lineInEmpty && 'relative'), children: [empty ?? 'Nothing here', lineInEmpty && _jsx("span", { "aria-hidden": "true", "data-slot": "board-drop-line", className: cn(DROP_LINE, 'top-0') })] }))] }));
292
+ };
293
+ // A drop on a column with no order: only a change of column.
294
+ const moveToValueByDrag = (id, value) => {
295
+ dragging.current = id;
296
+ dropInto(value, undefined, 0);
297
+ endDrag();
298
+ };
299
+ const columnsView = columns.map((column) => {
300
+ const ordering = isOrdered(column);
301
+ const headingId = `${columnId(column.value)}-heading`;
302
+ let body;
303
+ let count;
304
+ let handlers;
305
+ if (column.groups) {
306
+ const groups = column.groups.map((group) => ({ group, cards: zoneItems(column.value, group.value) }));
307
+ count = column.count ?? groups.reduce((sum, { cards }) => sum + cards.length, 0);
308
+ const GroupHeading = `h${Math.min(headingLevel + 1, 6)}`;
309
+ body = groups.map(({ group, cards }) => {
310
+ const zone = zoneKey(column.value, group.value);
311
+ const open = !(folded[zone] ?? group.defaultOpen === false);
312
+ const visible = cards.slice(0, shownCount(cards.length, pageSize, pagesOf(zone))).map(getId);
313
+ const groupId = `${columnId(column.value)}-group-${group.value}`;
314
+ const dropHere = onMove === undefined
315
+ ? undefined
316
+ : ordering
317
+ ? zoneHandlers(zone, column.value, group.value, open ? visible : [], open ? undefined : cards.length)
318
+ : zoneHandlers(zone, column.value, group.value, [], 0);
319
+ const overFolded = !open && over?.zone === zone;
320
+ return (_jsxs("div", { role: "group", "aria-labelledby": `${groupId}-heading`, "data-slot": "board-group", className: "flex flex-col gap-2", ...dropHere, children: [_jsx(GroupHeading, { id: `${groupId}-heading`, className: "m-0", children: _jsxs("button", { type: "button", "aria-expanded": open, "aria-controls": groupId, onClick: () => setFolded((was) => ({ ...was, [zone]: open })), className: cn('flex min-h-9 w-full items-center gap-1.5 rounded-md px-1 text-left text-xs font-semibold tracking-wide text-muted-foreground uppercase outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50', overFolded && 'ring-2 ring-foreground'), children: [open ? _jsx(ChevronDownIcon, { "aria-hidden": "true", className: "size-4" }) : _jsx(ChevronRightIcon, { "aria-hidden": "true", className: "size-4" }), group.label, " ", _jsx("span", { className: "font-normal tracking-normal tabular-nums", children: group.count ?? cards.length })] }) }), _jsxs("div", { id: groupId, hidden: !open, className: "flex flex-col gap-2", children: [open && zoneCards(column, zone, cards, group.empty), open && group.footer && _jsx("div", { className: "px-1 type-caption text-muted-foreground", children: group.footer })] })] }, group.value));
321
+ });
322
+ }
323
+ else {
324
+ const zone = zoneKey(column.value);
325
+ const cards = shown.filter((item) => getColumn(item) === column.value);
326
+ count = column.count ?? cards.length;
327
+ const visible = cards.slice(0, shownCount(cards.length, pageSize, pagesOf(zone))).map(getId);
328
+ if (ordering)
329
+ handlers = zoneHandlers(zone, column.value, undefined, visible);
330
+ body = zoneCards(column, zone, cards, column.empty);
331
+ }
332
+ return (_jsxs(BoardColumnView, { id: counts ? columnId(column.value) : undefined, headingId: counts || column.groups ? headingId : undefined, column: column, count: count, headingLevel: headingLevel, actionSpace: anyAction, className: counts ? cn(COUNTS_COLUMN_WIDTH, chosen !== column.value && 'hidden lg:flex') : COLUMN_WIDTH, handlers: handlers, onDrop: onMove && !ordering && !column.groups ? (id) => moveToValueByDrag(id, column.value) : undefined, children: [body, column.footer && _jsx("div", { className: "px-1 type-caption text-muted-foreground", children: column.footer })] }, column.value));
333
+ });
334
+ const board = (_jsxs("div", { ref: boardRef, "data-slot": "board", "data-state": "success", role: "group", "aria-label": ariaLabel, tabIndex: -1, className: "flex snap-x snap-mandatory gap-3 overflow-x-auto pb-2 outline-none", children: [columnsView, _jsx("span", { role: "status", className: "sr-only", children: announcement })] }));
335
+ if (!counts)
336
+ return board;
337
+ return (_jsxs("div", { "data-slot": "board-frame", className: "flex min-w-0 flex-col gap-3", children: [_jsx("div", { role: "group", "aria-label": `${ariaLabel}: columns`, "data-slot": "board-counts", className: "grid gap-1 lg:hidden", style: { gridTemplateColumns: `repeat(${columns.length}, minmax(0, 1fr))` }, children: columns.map((column) => {
338
+ const total = column.count ??
339
+ (column.groups ? items.filter((item) => inColumn(item, column)).length : items.filter((item) => getColumn(item) === column.value).length);
340
+ return (_jsxs("button", { type: "button", "aria-pressed": chosen === column.value, "aria-controls": columnId(column.value), onClick: () => setPhoneColumn(column.value), className: cn('flex min-h-11 min-w-0 flex-col items-center justify-center gap-0.5 rounded-lg border px-0.5 py-1.5 outline-none focus-visible:ring-3 focus-visible:ring-ring/50', chosen === column.value ? 'border-primary bg-primary/10 text-foreground' : 'border-transparent bg-muted/50 text-muted-foreground'), children: [_jsx("span", { className: "text-base font-semibold tabular-nums", children: total }), ' ', _jsx("span", { className: "max-w-full truncate text-[0.6875rem] font-medium", children: column.shortName ?? columnName(column) })] }, column.value));
341
+ }) }), board] }));
342
+ }
343
+ function BoardColumnView({ id, headingId: givenHeadingId, column, count, headingLevel, actionSpace, className, handlers, onDrop, children, }) {
344
+ const [over, setOver] = useState(false);
345
+ const ownHeadingId = useId();
346
+ const headingId = givenHeadingId ?? ownHeadingId;
347
+ const Heading = `h${headingLevel}`;
348
+ const accepts = (event) => onDrop !== undefined && event.dataTransfer.types.includes(DRAG_TYPE);
349
+ const slotted = column.note !== undefined || column.action !== undefined || actionSpace || column.description !== undefined;
350
+ const heading = (_jsxs(Heading, { id: headingId, className: slotted ? 'flex items-center gap-2 type-label' : 'flex items-center gap-2 px-1 pt-0.5 type-label', children: [column.label, _jsx("span", { className: "font-normal tabular-nums text-muted-foreground", children: count })] }));
351
+ return (_jsxs("section", { id: id, "aria-labelledby": headingId, "data-slot": "board-column", "data-over": over || undefined, className: cn(column.lead
352
+ ? 'flex snap-start flex-col gap-2 rounded-lg border-2 border-foreground bg-background p-2 outline-2 outline-offset-2 outline-transparent data-over:outline-ring'
353
+ : 'flex snap-start flex-col gap-2 rounded-lg bg-muted p-2 [--muted-foreground:var(--table-highlight-muted-foreground)] outline-2 outline-offset-2 outline-transparent data-over:outline-ring', className), ...(handlers ?? {
354
+ onDragOver: (event) => {
355
+ if (!accepts(event))
356
+ return;
357
+ event.preventDefault();
358
+ event.dataTransfer.dropEffect = 'move';
359
+ setOver(true);
360
+ },
361
+ onDragLeave: (event) => {
362
+ if (!event.currentTarget.contains(event.relatedTarget))
363
+ setOver(false);
364
+ },
365
+ onDrop: (event) => {
366
+ setOver(false);
367
+ if (!accepts(event))
368
+ return;
369
+ event.preventDefault();
370
+ onDrop?.(event.dataTransfer.getData(DRAG_TYPE));
371
+ },
372
+ }), children: [slotted ? (_jsxs("div", { className: "flex flex-col gap-0.5 px-1 pt-0.5", children: [_jsxs("div", { className: "flex min-h-9 items-center gap-2", children: [heading, _jsx("span", { "aria-hidden": "true", className: "flex-1" }), column.note !== undefined && _jsx("span", { className: "type-caption text-muted-foreground", children: column.note }), column.action ?? (actionSpace && _jsx("span", { "aria-hidden": "true", className: "size-9 shrink-0" }))] }), column.description !== undefined && _jsx("p", { className: "type-caption text-muted-foreground", children: column.description })] })) : (heading), children] }));
128
373
  }
129
- function MoveMenu({ id, name, value, targets, onMove, }) {
130
- return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { variant: "ghost", size: "icon-xs", "aria-label": `Move ${name}`, title: "Move To\u2026", "data-board-move": id }), children: _jsx(ArrowRightLeftIcon, { "aria-hidden": "true" }) }), _jsx(DropdownMenuContent, { align: "end", className: "w-44", children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Move To" }), _jsx(DropdownMenuRadioGroup, { value: value, onValueChange: (next) => onMove(next), children: targets.map((target) => (_jsx(DropdownMenuRadioItem, { value: target.value, closeOnClick: true, children: target.label }, target.value))) })] }) })] }));
374
+ function CardMenu({ id, name, value, targets, onMove, order, extra, }) {
375
+ const actions = extra !== undefined && extra !== null && extra !== false;
376
+ return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: actions ? (_jsx(Button, { variant: "ghost", size: "icon-xs", "aria-label": `Actions for ${name}`, title: "Actions", "data-board-move": id })) : (_jsx(Button, { variant: "ghost", size: "icon-xs", "aria-label": `Move ${name}`, title: "Move To\u2026", "data-board-move": id })), children: actions ? _jsx(EllipsisIcon, { "aria-hidden": "true" }) : _jsx(ArrowRightLeftIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-44", children: [_jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Move To" }), _jsx(DropdownMenuRadioGroup, { value: value, onValueChange: (next) => onMove(next), children: targets.map((target) => (_jsx(DropdownMenuRadioItem, { value: target.value, closeOnClick: true, children: target.label }, target.value))) })] }), order && (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { children: "Order" }), _jsx(DropdownMenuItem, { disabled: !order.allowed.up, onClick: () => order.run('up'), children: "Move Up" }), _jsx(DropdownMenuItem, { disabled: !order.allowed.down, onClick: () => order.run('down'), children: "Move Down" }), _jsx(DropdownMenuItem, { disabled: !order.allowed.top, onClick: () => order.run('top'), children: "Move to Top" })] })] })), actions && (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), extra] }))] })] }));
131
377
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { AppShell, type AppShellProps, type AppShellSearch, type RecentRecord, type SearchRecord, type AppShellVersion, type BottomBarItem, type NavEntry, type NavItem, type NavLook, type NavSection, } from './components/app/app-shell.js';
2
2
  export type { IconComponent } from './components/app/icon-component.js';
3
- export { Board, type BoardColumn, type BoardMoveTarget, type BoardProps } from './components/app/board.js';
3
+ export { Board, type BoardColumn, type BoardGroup, type BoardMoveTarget, type BoardPlace, type BoardProps } from './components/app/board.js';
4
4
  export { SpinWheel, type SpinWheelProps } from './components/app/spin-wheel.js';
5
5
  export { pickSpinWheelIndex, type SpinWheelItem } from './components/app/spin-wheel-pick.js';
6
6
  export { FillInChoice, FillInQueue, type FillInChoiceProps, type FillInQueueGroup, type FillInQueueProgress, type FillInQueueProps, } from './components/app/fill-in-queue.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.130.2",
3
+ "version": "4.131.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -70,7 +70,8 @@
70
70
  "build-harness": "vite build -c vite.harness.config.ts",
71
71
  "preview-harness": "vite preview -c vite.harness.config.ts",
72
72
  "verify:fast": "npm run gen:api && git diff --exit-code -- src/api/schema.ts && node scripts/doc-index.mjs --check && tsc -b && eslint . --max-warnings 0 && node bin/ui-foundation.mjs check-deps && npm run build && vitest run",
73
- "verify": "npm run verify:fast && playwright test -c playwright.harness.config.ts"
73
+ "verify:harness": "playwright test -c playwright.harness.config.ts",
74
+ "verify": "npm run verify:fast && npm run verify:harness"
74
75
  },
75
76
  "peerDependencies": {
76
77
  "@axe-core/playwright": "^4.13.0",