@nanahoshi/mona-ui 0.39.1 → 0.41.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 (76) hide show
  1. package/docs/api/common.md +1 -1
  2. package/docs/api/grid.md +214 -17
  3. package/docs/api/i18n.md +36 -0
  4. package/docs/api/kanban.md +222 -0
  5. package/docs/api/locales.md +14 -14
  6. package/docs/api/sortable.md +189 -0
  7. package/docs/api/tabs.md +20 -0
  8. package/docs/grid-selection.md +134 -9
  9. package/docs/grid-state-export.md +56 -6
  10. package/docs/grid-tree.md +279 -0
  11. package/docs/kanban.md +293 -0
  12. package/docs/sortable.md +320 -0
  13. package/docs/tabs.md +59 -10
  14. package/fesm2022/{nanahoshi-mona-ui-grid-grid-colgroup.component-Lv3GunpV.mjs → nanahoshi-mona-ui-grid-grid-colgroup.component-DpszxgFY.mjs} +2 -2
  15. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-BYH9XbCV.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-CpvzAcX8.mjs} +4 -3
  16. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BoSXXLKQ.mjs → nanahoshi-mona-ui-grid-grid-list.component-tRmEWiQR.mjs} +5 -5
  17. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-Df2gfS0X.mjs → nanahoshi-mona-ui-grid-grid-row.component-eET6dh2Q.mjs} +52 -35
  18. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-xjrcCXXF.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-8h2EMexB.mjs} +5 -5
  19. package/fesm2022/{nanahoshi-mona-ui-grid-grid.styles-aPD3c2A6.mjs → nanahoshi-mona-ui-grid-grid.styles-wAf6jsT9.mjs} +646 -20
  20. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1663 -22
  21. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +56 -0
  22. package/fesm2022/nanahoshi-mona-ui-kanban.mjs +660 -0
  23. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +11 -0
  24. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +17 -0
  25. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +17 -0
  26. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +17 -0
  27. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +11 -0
  28. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +17 -0
  29. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +11 -0
  30. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +11 -0
  31. package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +21 -0
  32. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +17 -0
  33. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +21 -0
  34. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +11 -0
  35. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +11 -0
  36. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +11 -0
  37. package/fesm2022/nanahoshi-mona-ui-sortable.mjs +733 -0
  38. package/fesm2022/nanahoshi-mona-ui-tabs.mjs +112 -5
  39. package/i18n/catalogs/en-US.messages.json +11 -0
  40. package/kanban/package.json +4 -0
  41. package/llms.txt +10 -5
  42. package/locales/ar-sa/ar-sa.messages.json +11 -0
  43. package/locales/de-de/de-de.messages.json +11 -0
  44. package/locales/es-es/es-es.messages.json +11 -0
  45. package/locales/fr-fr/fr-fr.messages.json +11 -0
  46. package/locales/id-id/id-id.messages.json +11 -0
  47. package/locales/it-it/it-it.messages.json +11 -0
  48. package/locales/ja-jp/ja-jp.messages.json +11 -0
  49. package/locales/ko-kr/ko-kr.messages.json +11 -0
  50. package/locales/pl-pl/pl-pl.messages.json +11 -0
  51. package/locales/pt-br/pt-br.messages.json +11 -0
  52. package/locales/ru-ru/ru-ru.messages.json +11 -0
  53. package/locales/tr-tr/tr-tr.messages.json +11 -0
  54. package/locales/zh-cn/zh-cn.messages.json +11 -0
  55. package/locales/zh-tw/zh-tw.messages.json +11 -0
  56. package/package.json +9 -1
  57. package/sortable/package.json +4 -0
  58. package/types/nanahoshi-mona-ui-grid.d.ts +305 -3
  59. package/types/nanahoshi-mona-ui-i18n.d.ts +23 -0
  60. package/types/nanahoshi-mona-ui-kanban.d.ts +270 -0
  61. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +11 -0
  62. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +11 -0
  63. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +11 -0
  64. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +11 -0
  65. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +11 -0
  66. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +11 -0
  67. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +11 -0
  68. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +11 -0
  69. package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +11 -0
  70. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +11 -0
  71. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +11 -0
  72. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +11 -0
  73. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +11 -0
  74. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +11 -0
  75. package/types/nanahoshi-mona-ui-sortable.d.ts +245 -0
  76. package/types/nanahoshi-mona-ui-tabs.d.ts +46 -0
@@ -0,0 +1,189 @@
1
+ # `@nanahoshi/mona-ui/sortable`
2
+
3
+ Everything `@nanahoshi/mona-ui/sortable` exports.
4
+
5
+ **Guides:** [Sortable](../sortable.md)
6
+
7
+ ## `SortableDirective`
8
+
9
+ Directive.
10
+
11
+ Lets the user reorder a list's items by dragging them, or with Control+Shift and the arrow keys (Command+Shift on
12
+ macOS), and announces each move. Mark each item with `monaSortableItem`, render every item of the array in order,
13
+ and bind the array two-way, `[(monaSortable)]`, or handle `sortableMove`. The list doesn't reorder its elements
14
+ itself. Lists inside one `monaSortableGroup` exchange items.
15
+
16
+ **Selector:** `[monaSortable]`
17
+ **Exported as:** `monaSortable`
18
+ **Type parameters:** `T = unknown`
19
+
20
+ ### Inputs
21
+
22
+ | Name | Type | Default | Description |
23
+ | --- | --- | --- | --- |
24
+ | `monaSortable` (required) | `readonly T[]` | — | The list's items, in the order they're shown. Bind it two-way, `[(monaSortable)]`, to take each new order. |
25
+ | `sortableCanEnter` | `((item: T) => boolean) \| null` | `null` | Whether an item from another list of the group may come into this one, such as to keep a list under a limit. The list's own items can always move within it. Without it, every item may come in. |
26
+ | `sortableDisabled` | `boolean` | `false` | Stops items from moving within the list, out of it or into it. |
27
+ | `sortableLabel` | `string` | `""` | The list's name in the announcement of a move into it from another list. Without it, the list's `aria-label` or `aria-labelledby` text. |
28
+ | `sortableLockAxis` | `boolean` | `false` | Keeps a dragged item on the list's axis: across for a horizontal list, up and down for a vertical one. A list whose rows wrap doesn't lock. |
29
+ | `sortableOrientation` | `SortableOrientation` | `"vertical"` | How the items are laid out, which sets the keys that move them: Up and Down in a column, Left and Right in a row, and all four in rows that wrap. |
30
+
31
+ ### Outputs
32
+
33
+ | Name | Type | Description |
34
+ | --- | --- | --- |
35
+ | `monaSortableChange` | `T[]` | Emitted with the list's new items after an item moves within it, out of it or into it, unless the move was refused. |
36
+ | `sortableMove` | `SortableMoveEvent<T>` | Emitted with a `SortableMoveEvent` when an item moves within this list or into it from another list, before the lists emit their new items. This event is preventable. |
37
+
38
+ ### Properties
39
+
40
+ | Name | Type | Description |
41
+ | --- | --- | --- |
42
+ | `keyShortcuts` (read-only) | `Signal<string \| null>` | The shortcuts that move an item, in `aria-keyshortcuts` form, or `null` while the list is disabled. Items put it on themselves; an item that's presentational can bind it on the element in it that takes focus. |
43
+
44
+ **Used by:** [`SortableMoveEvent`](sortable.md#sortablemoveevent), [`SortableMoveEventOptions`](sortable.md#sortablemoveeventoptions)
45
+
46
+ ## `SortableItemDirective`
47
+
48
+ Directive.
49
+
50
+ An item of a `monaSortable` list, given the array element it shows. Drag it, or focus it, or a control in it, and
51
+ press Control+Shift with an arrow key, Home or End (Command+Shift on macOS) to move it. On a touch screen, press and
52
+ hold it first, so a swipe still scrolls.
53
+
54
+ **Selector:** `[monaSortableItem]`
55
+ **Exported as:** `monaSortableItem`
56
+ **Type parameters:** `T = unknown`
57
+
58
+ ### Inputs
59
+
60
+ | Name | Type | Default | Description |
61
+ | --- | --- | --- | --- |
62
+ | `monaSortableItem` (required) | `T` | — | The element of the list's array that this item shows. |
63
+ | `sortableDisabled` | `boolean` | `false` | Stops this item from moving. Other items still move past it. |
64
+ | `sortableLabel` | `string` | `""` | The item's name in announcements of its moves. Without it, the item's `aria-label`, `aria-labelledby` text or own text. |
65
+
66
+ ### Properties
67
+
68
+ | Name | Type | Description |
69
+ | --- | --- | --- |
70
+ | `keyShortcuts` (read-only) | `Signal<string \| null>` | The shortcuts that move this item, in `aria-keyshortcuts` form, or `null` when it can't move. The item sets them on itself, unless it has `role="presentation"` or `role="none"`: then bind them on the element in it that takes focus. |
71
+
72
+ ## `SortableGroupDirective`
73
+
74
+ Directive.
75
+
76
+ Connects the sortable lists inside it, so an item can move from one to another: dragged, or with Control+Shift and
77
+ the arrow keys that cross the lists, such as Left and Right between columns. The lists keep their own items; the
78
+ one an item lands in emits the move.
79
+
80
+ **Selector:** `[monaSortableGroup]`
81
+ **Exported as:** `monaSortableGroup`
82
+
83
+ ## `SortableHandleDirective`
84
+
85
+ Directive.
86
+
87
+ Marks the part of a sortable item that starts a drag, such as a grip icon. With a handle, the rest of the item
88
+ doesn't start one, so its text can be selected. The keyboard still moves the item from anywhere in it.
89
+
90
+ **Selector:** `[monaSortableHandle]`
91
+
92
+ ## `SortableMoveEvent`
93
+
94
+ Class.
95
+
96
+ A move of an item, by pointer or keyboard, within a sortable list or into another list of its group. The list the
97
+ item lands in emits it. Call `preventDefault()` to refuse the move: the lists then don't emit their new items, and
98
+ the item goes back where it was.
99
+
100
+ **Type parameters:** `T = unknown`
101
+ **Extends:** `PreventableEvent`
102
+
103
+ ### Properties
104
+
105
+ | Name | Type | Description |
106
+ | --- | --- | --- |
107
+ | `currentIndex` (read-only) | `number` | The item's index in `currentItems`. |
108
+ | `currentItems` (read-only) | `readonly T[]` | The items of the list the item lands in, after the move. |
109
+ | `currentList` (read-only) | `SortableDirective<T>` | The list the item lands in: the one that emits this event. |
110
+ | `item` (read-only) | `T` | The item that moves. |
111
+ | `previousIndex` (read-only) | `number` | The item's index in its list before the move. |
112
+ | `previousItems` (read-only) | `readonly T[]` | The items of the list the item comes from, after the move. For a move within one list, the same array as `currentItems`. |
113
+ | `previousList` (read-only) | `SortableDirective<T>` | The list the item comes from. The same as `currentList` for a move within one list. |
114
+
115
+ ### Inherited from `PreventableEvent`
116
+
117
+ | Name | Type | Description |
118
+ | --- | --- | --- |
119
+ | `originalEvent` (read-only) | `E \| undefined` | The DOM event that caused this one, when there is one. |
120
+ | `type` (read-only) | `string \| undefined` | A name for the kind of event, when the component that emits it sets one. |
121
+
122
+ **Methods**
123
+
124
+ | Signature | Description |
125
+ | --- | --- |
126
+ | `isDefaultPrevented(): boolean` | Whether `preventDefault()` was called. |
127
+ | `preventDefault(): void` | Cancels what the event announces, such as opening or closing a popup, or closing a dialog. |
128
+
129
+ **Used by:** [`SortableDirective`](sortable.md#sortabledirective)
130
+
131
+ ## `moveItem`
132
+
133
+ Function.
134
+
135
+ A copy of `items` with the item at `from` moved to `to`, the index it has afterwards. Use it to apply a move that a
136
+ list reports by index, such as a reordered tab. Indexes out of range are clamped; the array isn't changed.
137
+
138
+ ```typescript
139
+ function moveItem<T>(items: readonly T[], from: number, to: number): T[];
140
+ ```
141
+
142
+ ## `SORTABLE_DEFAULT_MESSAGES`
143
+
144
+ Constant.
145
+
146
+ ```typescript
147
+ const SORTABLE_DEFAULT_MESSAGES: MonaSortableMessages;
148
+ ```
149
+
150
+ ## `SortableMoveEventOptions`
151
+
152
+ Interface.
153
+
154
+ **Type parameters:** `T`
155
+
156
+ ### Properties
157
+
158
+ | Name | Type |
159
+ | --- | --- |
160
+ | `currentIndex` (read-only) | `number` |
161
+ | `currentItems` (read-only) | `readonly T[]` |
162
+ | `currentList` (read-only) | `SortableDirective<T>` |
163
+ | `item` (read-only) | `T` |
164
+ | `previousIndex` (read-only) | `number` |
165
+ | `previousItems` (read-only) | `readonly T[]` |
166
+ | `previousList` (read-only) | `SortableDirective<T>` |
167
+
168
+ ## `SortableMoveKey`
169
+
170
+ Type alias.
171
+
172
+ The keys that move an item, held with Control and Shift (Command and Shift on macOS).
173
+
174
+ ```typescript
175
+ type SortableMoveKey = "ArrowDown" | "ArrowLeft" | "ArrowRight" | "ArrowUp" | "End" | "Home";
176
+ ```
177
+
178
+ ## `SortableOrientation`
179
+
180
+ Type alias.
181
+
182
+ How a sortable list lays out its items: in a column (`vertical`), in a row (`horizontal`), or in rows that wrap
183
+ (`mixed`), such as a grid of cards.
184
+
185
+ ```typescript
186
+ type SortableOrientation = "horizontal" | "mixed" | "vertical";
187
+ ```
188
+
189
+ **Used by:** [`SortableDirective`](sortable.md#sortabledirective)
package/docs/api/tabs.md CHANGED
@@ -23,6 +23,7 @@ Component.
23
23
  | `position` | `"bottom" \| "left" \| "right" \| "top"` | `"top"` | Placement of the tab list relative to the tab content. |
24
24
  | `selectedIndex` (two-way) | `number` | `0` | The zero-based index of the selected tab. Writing it selects that tab, unless it's disabled or out of range, in which case the value goes back to the selected tab's index. It also changes when the component moves the selection itself, such as when the selected tab is removed. |
25
25
  | `size` | `"large" \| "medium" \| "small"` | `"medium"` | Size preset controlling the tabs' dimensions. |
26
+ | `sortable` | `boolean` | `false` | Lets the user reorder the tabs: by dragging them, or with Control+Shift and the arrow keys along the strip, Home or End (Command+Shift on macOS). The component emits `tabReorder` and doesn't move the tabs itself. |
26
27
 
27
28
  ### Outputs
28
29
 
@@ -30,6 +31,7 @@ Component.
30
31
  | --- | --- | --- |
31
32
  | `selectedIndexChange` | `number` | Emitted when `selectedIndex` changes. |
32
33
  | `tabClose` | `TabCloseEvent` | Emitted with a `TabCloseEvent` when a close is requested. The component doesn't remove the tab: remove it from whatever renders the `mona-tab` elements. |
34
+ | `tabReorder` | `TabReorderEvent` | Emitted with a `TabReorderEvent` when a tab of a `sortable` strip is moved. The component doesn't reorder the tabs: move the tab in whatever renders the `mona-tab` elements. The selected tab stays selected. |
33
35
  | `tabSelect` | `TabSelectEvent` | Emitted with a `TabSelectEvent` before a click or key selects a tab. This event is preventable. It doesn't fire for selections made through `selectedIndex` or `selected`, or when the selected tab is removed. |
34
36
 
35
37
  ## `TabComponent`
@@ -94,6 +96,24 @@ Class.
94
96
 
95
97
  **Used by:** [`TabsComponent`](tabs.md#tabscomponent)
96
98
 
99
+ ## `TabReorderEvent`
100
+
101
+ Class.
102
+
103
+ A tab dragged, or moved with Control+Shift and an arrow key, Home or End, to a new place in a sortable tab strip.
104
+ The component doesn't reorder the tabs: move the tab in whatever renders the `mona-tab` elements, such as with
105
+ `moveItem` from `@nanahoshi/mona-ui/sortable`.
106
+
107
+ ### Properties
108
+
109
+ | Name | Type | Description |
110
+ | --- | --- | --- |
111
+ | `currentIndex` (read-only) | `number` | The index the tab moves to. |
112
+ | `originalEvent` (read-only) | `Event \| undefined` | The DOM event that moved the tab: the key press, or the pointer release that dropped it. |
113
+ | `previousIndex` (read-only) | `number` | The index the tab had. |
114
+
115
+ **Used by:** [`TabsComponent`](tabs.md#tabscomponent)
116
+
97
117
  ## `TabSelectEvent`
98
118
 
99
119
  Class.
@@ -1,12 +1,12 @@
1
1
  # Selection
2
2
 
3
- > Select single or multiple rows by key, with checkboxes, row clicks and the keyboard.
3
+ > Select rows by key with checkboxes, clicks and the keyboard, or a range of cells to copy and paste.
4
4
 
5
5
  Entry point: `@nanahoshi/mona-ui/grid`
6
6
 
7
- **Selector:** `mona-grid[monaGridSelectable]`
7
+ **Selectors:** `mona-grid[monaGridSelectable]`, `mona-grid[monaGridRangeSelectable]`
8
8
 
9
- `monaGridSelectable` lets people select one row or several, with built-in checkboxes, row clicks or the keyboard. The selection is a list of row keys you bind with `[(selectedKeys)]`, so it survives paging, sorting and reloading the data.
9
+ `monaGridSelectable` lets people select one row or several, with built-in checkboxes, row clicks or the keyboard. The selection is a list of row keys you bind with `[(selectedKeys)]`, so it survives paging, sorting and reloading the data. `monaGridRangeSelectable` selects a rectangle of cells instead, which people copy to a spreadsheet and paste into from one.
10
10
 
11
11
  ## Overview
12
12
 
@@ -19,6 +19,8 @@ Selection state always lives in `selectedKeys`. Checkboxes, row clicks, keys and
19
19
  - People pick one value to fill a field. Use a [Dropdown List](dropdown-list.md) or [List Box](list-box.md).
20
20
  - The selection drives actions on the rows, such as deleting them: keep the selection, and put the actions in a [toolbar](grid.md#toolbar-and-the-columns-button) that reads `selectedKeys`.
21
21
 
22
+ **Use `monaGridRangeSelectable` when** people work with values rather than records: copying a block of numbers into a spreadsheet, or pasting one from it to fill many cells at once.
23
+
22
24
  ## Import & Quick Start
23
25
 
24
26
  ```typescript
@@ -114,8 +116,122 @@ protected selectOverdue(): void {
114
116
  }
115
117
  ```
116
118
 
119
+ ### Cell Ranges, Copy and Paste
120
+
121
+ `range-example.component.ts`
122
+
123
+ ```typescript
124
+ import { Component, signal } from "@angular/core";
125
+ import {
126
+ type GridCellRange,
127
+ GridColumnComponent,
128
+ GridComponent,
129
+ GridEditableDirective,
130
+ type GridRangePasteEvent,
131
+ GridRangeSelectableDirective,
132
+ type GridSaveEvent
133
+ } from "@nanahoshi/mona-ui/grid";
134
+
135
+ /**
136
+ * A type alias rather than an interface, so a forecast is also a `Record<PropertyKey, unknown>`: the rows' type in
137
+ * the events, since the directives can't know the type of the grid's data.
138
+ */
139
+ type Forecast = {
140
+ readonly id: number;
141
+ readonly q1: number;
142
+ readonly q2: number;
143
+ readonly q3: number;
144
+ readonly q4: number;
145
+ readonly region: string;
146
+ };
147
+
148
+ /** "1 row" or "2 rows". */
149
+ function count(amount: number, noun: string): string {
150
+ return `${amount} ${noun}${amount === 1 ? "" : "s"}`;
151
+ }
152
+
153
+ @Component({
154
+ selector: "app-grid-selection-range-example",
155
+ imports: [GridColumnComponent, GridComponent, GridEditableDirective, GridRangeSelectableDirective],
156
+ templateUrl: "./range-example.component.html"
157
+ })
158
+ export class GridRangeSelectionExampleComponent {
159
+ protected readonly forecasts = signal<Forecast[]>([
160
+ { id: 1, region: "North", q1: 120, q2: 135, q3: 128, q4: 150 },
161
+ { id: 2, region: "South", q1: 98, q2: 102, q3: 110, q4: 125 },
162
+ { id: 3, region: "East", q1: 143, q2: 139, q3: 152, q4: 160 },
163
+ { id: 4, region: "West", q1: 87, q2: 95, q3: 101, q4: 99 },
164
+ { id: 5, region: "Central", q1: 110, q2: 118, q3: 121, q4: 130 }
165
+ ]);
166
+ protected readonly status = signal("No cells selected.");
167
+
168
+ protected onRangeChange(range: GridCellRange | null): void {
169
+ if (range == null) {
170
+ this.status.set("No cells selected.");
171
+ return;
172
+ }
173
+ const [rows, columns] = [range.rows.length, range.fields.length];
174
+ this.status.set(rows * columns === 1 ? "1 cell selected." : `${rows} × ${columns} cells selected.`);
175
+ }
176
+
177
+ /** The grid never changes `data` itself: write the pasted rows back. */
178
+ protected onRangePaste(event: GridRangePasteEvent): void {
179
+ const pasted = new Map(event.changes.map(change => [change.originalRowData, change.rowData as Forecast]));
180
+ this.forecasts.update(rows => rows.map(row => pasted.get(row) ?? row));
181
+ const skipped = event.skippedCells === 0 ? "" : `, skipping ${count(event.skippedCells, "cell")}`;
182
+ this.status.set(`Pasted into ${count(event.changes.length, "row")}${skipped}.`);
183
+ }
184
+
185
+ protected onSave(event: GridSaveEvent): void {
186
+ const saved = event.rowData as Forecast;
187
+ this.forecasts.update(rows => rows.map(row => (row === event.originalRowData ? saved : row)));
188
+ }
189
+ }
190
+ ```
191
+
192
+ `range-example.component.html`
193
+
194
+ ```html
195
+ <div class="flex flex-col gap-2">
196
+ <mona-grid
197
+ aria-label="Sales forecast"
198
+ rowKey="id"
199
+ [data]="forecasts()"
200
+ [monaGridEditable]="{ mode: 'cell' }"
201
+ monaGridRangeSelectable
202
+ (rangeChange)="onRangeChange($event)"
203
+ (rangePaste)="onRangePaste($event)"
204
+ (save)="onSave($event)">
205
+ <mona-grid-column field="region" title="Region" [editable]="false" />
206
+ <mona-grid-column field="q1" title="Q1" type="number" />
207
+ <mona-grid-column field="q2" title="Q2" type="number" />
208
+ <mona-grid-column field="q3" title="Q3" type="number" />
209
+ <mona-grid-column field="q4" title="Q4" type="number" />
210
+ </mona-grid>
211
+ <span aria-live="polite" class="text-sm">{{ status() }}</span>
212
+ </div>
213
+ ```
214
+
215
+ Drag across cells, Shift+click the far corner, or hold Shift and use the arrow keys, then press Ctrl+C and paste into a spreadsheet. Copy a block of cells from a spreadsheet, focus a quarter's cell and press Ctrl+V to paste it there, or select a range and paste one value to fill it. The Region column isn't editable, so pasting over it keeps its values.
216
+
217
+ `rangeChange` reports the selected range as the data items of its rows and the fields of its columns, in the order the grid shows them, or `null` once it's cleared. `clearRange()` and `selectAll()` do the same from code. `[monaGridRangeSelectable]="false"` turns the directive off.
218
+
117
219
  ## Behavior
118
220
 
221
+ ### Copying and pasting cells
222
+
223
+ Ctrl+C copies the range as tab-separated text, with each cell's text as the grid shows it, so a spreadsheet pastes it as cells; a cell holding a tab, a line break or a quote is quoted, as spreadsheets do. The grid says how many cells it copied.
224
+
225
+ Pasting needs editing on (`monaGridEditable`) and no editor open, and never changes the grid's data. The grid reads the pasted text, works out the new values and emits `rangePaste` with each changed row's data as it was (`originalRowData`) and with the new values in (`rowData`), for you to save, and with `skippedCells`, the cells that kept their value. Then it says how many cells it pasted.
226
+
227
+ - **One value** fills every cell of the range. **A block** of rows and columns pastes from the focused cell, or the range's first cell, and stops at the last row and column the view has: it never adds rows.
228
+ - **Values** take each column's type: numbers as written in the grid's locale, `true`/`false`, `yes`/`no` or `1`/`0` for booleans, and dates as `2024-03-15` or in the locale's own order. Empty text clears the cell.
229
+ - **A cell keeps its value** when its column can't be edited, or when the text doesn't fit the column's type, such as a word in a number column.
230
+
231
+ ### Ranges with row selection
232
+
233
+ The two directives work together. Space, the checkboxes and row clicks select rows, while Shift with the arrows, dragging and Ctrl+A select cells. Without `monaGridRangeSelectable`, Shift+ArrowUp and Shift+ArrowDown extend the row selection instead.
234
+
119
235
  ### Row clicks
120
236
 
121
237
  Off by default, so clicking a row's content (a link, a button, an editable cell) never silently discards the selection. With `selectOnRowClick`: in single mode, clicking a row replaces the selection; in multiple mode, a plain click selects just that row, Ctrl/Cmd-click toggles one row without disturbing the rest, and Shift-click selects the range from the last clicked row. Checkbox clicks always toggle their row, whatever `selectOnRowClick` says.
@@ -130,7 +246,7 @@ Provide a stable `rowKey` or `selectBy` when the selection must survive data rel
130
246
 
131
247
  ## Accessibility
132
248
 
133
- Selected rows carry `aria-selected`, and the grid says it allows several with `aria-multiselectable`. Name the checkboxes with `rowAriaLabel` when the position alone wouldn't tell people which row they're on.
249
+ Selected rows carry `aria-selected`, and the grid says it allows several with `aria-multiselectable`. With range selection, the cells in the range carry `aria-selected` instead, and the grid announces what Ctrl+C copied and Ctrl+V pasted. Name the checkboxes with `rowAriaLabel` when the position alone wouldn't tell people which row they're on.
134
250
 
135
251
  ### Keyboard
136
252
 
@@ -139,7 +255,11 @@ Selected rows carry `aria-selected`, and the grid says it allows several with `a
139
255
  | `Space` | Toggles the focused row's selection. |
140
256
  | `Shift+Space` | Selects the rows from the last selected row to this one. |
141
257
  | `Shift+ArrowDown` / `Shift+ArrowUp` | Moves to the next/previous row and extends the selection to it. |
142
- | `Ctrl+A` / `Cmd+A` | In multiple mode, selects every row in the select-all scope. |
258
+ | `Ctrl+A` / `Cmd+A` | In multiple mode, selects every row in the select-all scope. With range selection, selects every cell of the page, or of the whole view with virtual scrolling. |
259
+ | `Shift+Arrow keys` | With range selection, extends the range of cells from where it started. Moving without Shift leaves it. |
260
+ | `Escape` | With range selection, clears the range. |
261
+ | `Ctrl+C` / `Cmd+C` | Copies the range, or the focused cell. |
262
+ | `Ctrl+V` / `Cmd+V` | With range selection and editing on, pastes into the cells. |
143
263
 
144
264
  The rest of the grid's keys are on [Grid Overview](grid.md#keyboard).
145
265
 
@@ -147,21 +267,26 @@ The rest of the grid's keys are on [Grid Overview](grid.md#keyboard).
147
267
 
148
268
  | Attribute | When present | Value |
149
269
  | --- | --- | --- |
150
- | `aria-multiselectable` | On the tabular content region | `"true"` with multiple selection |
270
+ | `aria-multiselectable` | On the tabular content region | `"true"` with multiple selection or range selection |
151
271
  | `aria-selected` | On a row, while `monaGridSelectable` is enabled | Whether the row is selected |
272
+ | `aria-selected` | On a cell, while `monaGridRangeSelectable` is enabled | Whether the cell is in the range |
152
273
  | `aria-label` | On a row's checkbox / the select-all checkbox | `rowAriaLabel`'s text or `"Select row 3"` (`selectRow`) / `selectAllRows` |
153
274
 
154
275
  ## API
155
276
 
156
277
  Everything below is imported from `@nanahoshi/mona-ui/grid`. Each name links to its reference page, with every input, output, property and method.
157
278
 
158
- | Name | Kind |
159
- | --- | --- |
160
- | [`GridSelectableDirective`](api/grid.md#gridselectabledirective) | Directive |
279
+ | Name | Kind | Description |
280
+ | --- | --- | --- |
281
+ | [`GridRangeSelectableDirective`](api/grid.md#gridrangeselectabledirective) | Directive | Lets the user select a rectangle of cells: drag across them with the mouse, Shift+click the far corner, or extend from the focused cell with Shift and the arrow keys. |
282
+ | [`GridSelectableDirective`](api/grid.md#gridselectabledirective) | Directive | |
161
283
 
162
284
  ### Types
163
285
 
164
286
  | Type | Kind | Description |
165
287
  | --- | --- | --- |
288
+ | [`GridCellRange`](api/grid.md#gridcellrange) | Interface | The cells a range selection covers: the data items of its rows and the fields of its columns, each in the order the grid shows them. |
289
+ | [`GridRangePasteChange`](api/grid.md#gridrangepastechange) | Interface | One row's pasted values: the row as it was, and as it is with the values in. |
290
+ | [`GridRangePasteEvent`](api/grid.md#gridrangepasteevent) | Interface | What a paste into the grid's cells would change. |
166
291
  | [`SelectableOptions`](api/grid.md#selectableoptions) | Interface | |
167
292
  | [`GridKeySelector`](api/grid.md#gridkeyselector) | Type alias | The field holding a row's key, or a function returning it. |
@@ -1,26 +1,26 @@
1
1
  # State & Export
2
2
 
3
- > Save and restore the grid's columns, sort, filter, groups and page size, and export rows as CSV or Excel.
3
+ > Save and restore the grid's columns, sort, filter, groups and page size, and export rows as CSV, Excel or PDF.
4
4
 
5
5
  Entry point: `@nanahoshi/mona-ui/grid`
6
6
 
7
7
  **Selectors:** `mona-grid[monaGridStatePersistence]`, `mona-grid[monaGridExport]`
8
8
 
9
- `monaGridStatePersistence` captures what people changed (column order, widths and visibility, sort, filter, groups and page size) as a plain `GridState` object you can store and give back later. `monaGridExport` writes the rows of the current view to a CSV file or an Excel workbook.
9
+ `monaGridStatePersistence` captures what people changed (column order, widths and visibility, sort, filter, groups and page size) as a plain `GridState` object you can store and give back later. `monaGridExport` writes the rows of the current view to a CSV file, an Excel workbook or a PDF document.
10
10
 
11
11
  ## Overview
12
12
 
13
13
  | Directive | State you bind | Methods |
14
14
  | :--- | :--- | :--- |
15
15
  | `monaGridStatePersistence` | `[(state)]`: `GridState \| null` | `captureState()`, `loadState(state)` |
16
- | `monaGridExport` | — | `exportCsv(filename?)`, `exportExcel(filename?)` |
16
+ | `monaGridExport` | — | `exportCsv(filename?)`, `exportExcel(filename?)`, `exportPdf(options?)` |
17
17
 
18
18
  A `GridState` is JSON-safe, so it can go to `localStorage`, a user profile on your server, or a URL. The grid doesn't store it anywhere itself.
19
19
 
20
20
  **Use something else when:**
21
21
 
22
22
  - You need one value back, such as the sort. Bind that feature's own model (`[(sort)]`, `[(filter)]`, `[(group)]`, `[(pageSize)]`) instead.
23
- - The export needs every record from a server, or a format other than CSV and Excel, such as PDF. Produce it in your application from your data.
23
+ - The export needs every record from a server, or a document of its own, such as an invoice or a report with charts. Produce it in your application from your data.
24
24
 
25
25
  ## Import & Quick Start
26
26
 
@@ -35,6 +35,7 @@ protected readonly state = signal<GridState | null>(null);
35
35
  ```html
36
36
  <button monaButton type="button" (click)="gridExport.exportCsv('orders.csv')">Export as CSV</button>
37
37
  <button monaButton type="button" (click)="gridExport.exportExcel('orders.xlsx')">Export as Excel</button>
38
+ <button monaButton type="button" (click)="gridExport.exportPdf('orders.pdf')">Export as PDF</button>
38
39
  <mona-grid
39
40
  #gridExport="monaGridExport"
40
41
  aria-label="Orders"
@@ -131,6 +132,7 @@ export class GridSavedStateExampleComponent {
131
132
  <ng-template monaGridToolbarTemplate>
132
133
  <button monaButton type="button" (click)="gridExport.exportCsv('orders.csv')">Export as CSV</button>
133
134
  <button monaButton type="button" (click)="gridExport.exportExcel('orders.xlsx')">Export as Excel</button>
135
+ <button monaButton type="button" (click)="gridExport.exportPdf('orders.pdf')">Export as PDF</button>
134
136
  </ng-template>
135
137
  <mona-grid-column field="orderId" title="Order" type="number" />
136
138
  <mona-grid-column field="customer" title="Customer" />
@@ -139,7 +141,39 @@ export class GridSavedStateExampleComponent {
139
141
  </mona-grid>
140
142
  ```
141
143
 
142
- The example reads a saved state when it starts and writes every new one to `localStorage`. Sort a column, change the page size or move a column, then reload the page: the grid comes back the same. The toolbar's buttons download the rows as `orders.csv` and `orders.xlsx`. In the CSV file the customer `=Island Trading` is written as `'=Island Trading`, so a spreadsheet doesn't run it as a formula; the workbook holds it as text, so it needs no quote. The Order Date column is a real date in the workbook, shown in your spreadsheet's date format.
144
+ The example reads a saved state when it starts and writes every new one to `localStorage`. Sort a column, change the page size or move a column, then reload the page: the grid comes back the same. The toolbar's buttons download the rows as `orders.csv`, `orders.xlsx` and `orders.pdf`. In the CSV file the customer `=Island Trading` is written as `'=Island Trading`, so a spreadsheet doesn't run it as a formula; the workbook holds it as text, so it needs no quote. The Order Date column is a real date in the workbook, shown in your spreadsheet's date format.
145
+
146
+ ### PDF Options and Fonts
147
+
148
+ `exportPdf` takes a file name, or options:
149
+
150
+ ```typescript
151
+ private readonly gridExport = viewChild.required(GridExportDirective);
152
+
153
+ protected exportPdf(): Promise<void> {
154
+ return this.gridExport().exportPdf({
155
+ filename: "orders.pdf",
156
+ font: { regular: "/fonts/NotoSansJP-Regular.ttf", bold: "/fonts/NotoSansJP-Bold.ttf" },
157
+ orientation: "landscape",
158
+ paperSize: "Letter",
159
+ title: "Orders, January"
160
+ });
161
+ }
162
+ ```
163
+
164
+ | Option | Default | What it does |
165
+ | :--- | :--- | :--- |
166
+ | `filename` | `"export.pdf"` | The downloaded file's name. |
167
+ | `title` | none | A heading above the table on the first page, and the document's title in the reader. |
168
+ | `paperSize` | `"A4"` | `"A3"`, `"A4"`, `"Legal"`, `"Letter"`, or `[width, height]` in points (1/72 inch). |
169
+ | `orientation` | `"portrait"` | `"portrait"` or `"landscape"`. |
170
+ | `margin` | `36` | The space around the table, in points. |
171
+ | `fontSize` | `9` | The text size in points, before a wide table shrinks to fit. |
172
+ | `font` | none | A TrueType font to embed: `regular`, an optional `bold`, and `collectionIndex` for a `.ttc` collection. |
173
+
174
+ Without `font`, the text is set in Helvetica, which every PDF reader has, so nothing is embedded and the file stays small. Helvetica shows Western European text only (the Windows-1252 characters); anything else, such as Chinese, Japanese, Korean, Greek or Cyrillic, prints as `?`. Give a font that has those characters, as a URL or as bytes you've loaded, and the export embeds only the glyphs the document uses, so the file grows by tens of kilobytes rather than by the font's size. Characters the font hasn't still print in Helvetica, or as `?`. Without a `bold` face, the header and title are drawn in the regular face, thickened.
175
+
176
+ The font needs TrueType outlines: a `.ttf` file, or a `.ttc` collection with `collectionIndex`. The export rejects most `.otf` files, which have CFF outlines, and web fonts (`.woff`, `.woff2`), with an error that says so. A variable font prints at its default instance, often its lightest weight, so use a static font of the weight you want. A URL is fetched at each export, so serve it with caching headers, or load it once and pass the bytes.
143
177
 
144
178
  ### Applying a State from Code
145
179
 
@@ -191,7 +225,19 @@ The `state` model updates after each change people make, and a column resize is
191
225
  | Column widths | The columns' widths. |
192
226
  | A right-to-left layout | A right-to-left sheet. |
193
227
 
194
- Footers, aggregates and row groups aren't exported, in either format. The workbook is built in the browser, without a dependency, and compressed where the browser supports `CompressionStream`.
228
+ `exportPdf(options?)` prints the same rows and columns as a table, and returns a promise that resolves once the download starts, or rejects when a font can't be loaded or read.
229
+
230
+ | In the grid | In the PDF |
231
+ | :--- | :--- |
232
+ | Cell values | The text the cells show: each column's `format`, and numbers and dates in the grid's locale. Cell templates aren't used. |
233
+ | `number` columns | Aligned to the end of their cells. |
234
+ | Long text | Wrapped, at spaces or between Chinese, Japanese and Korean characters. A row never splits across pages; a cell taller than a page is cut short with an ellipsis. |
235
+ | Column groups | Header cells spanning their columns, above the column titles. |
236
+ | Column widths | The columns' widths, at 3/4 of a point per pixel. A table wider than the page shrinks to fit, and its text with it, to 65% at most and never below 5 points. |
237
+ | Many rows | Pages, each with the header on top and its number, such as `2 / 5`, at the bottom. |
238
+ | A right-to-left layout | The first column on the right. The text inside a cell isn't reordered or shaped, so Arabic and Hebrew don't read correctly: export those as CSV or Excel. |
239
+
240
+ Footers, aggregates and row groups aren't exported, in any format. In a [tree list](grid-tree.md), every row is exported, collapsed or not, in tree order: the workbook groups each row's children into an outline you can collapse, and indents the tree column, as the PDF does. The workbook and the PDF are built in the browser, without a dependency, and compressed where the browser supports `CompressionStream`.
195
241
 
196
242
  ## Accessibility
197
243
 
@@ -215,12 +261,16 @@ Everything below is imported from `@nanahoshi/mona-ui/grid`. Each name links to
215
261
  | Type | Kind | Description |
216
262
  | --- | --- | --- |
217
263
  | [`GridColumnState`](api/grid.md#gridcolumnstate) | Interface | |
264
+ | [`GridPdfExportOptions`](api/grid.md#gridpdfexportoptions) | Interface | |
265
+ | [`GridPdfFont`](api/grid.md#gridpdffont) | Interface | The font a PDF export embeds for the text Helvetica can't show, such as Chinese, Japanese or Korean. |
218
266
  | [`GridState`](api/grid.md#gridstate) | Interface | |
219
267
  | [`GridStateCompositeFilterDescriptor`](api/grid.md#gridstatecompositefilterdescriptor) | Interface | |
220
268
  | [`GridStateFilterDescriptor`](api/grid.md#gridstatefilterdescriptor) | Interface | |
221
269
  | [`GridStateLoadResult`](api/grid.md#gridstateloadresult) | Interface | |
222
270
  | [`GridStatePersistenceOptions`](api/grid.md#gridstatepersistenceoptions) | Interface | |
223
271
  | [`GridStateSortDescriptor`](api/grid.md#gridstatesortdescriptor) | Interface | |
272
+ | [`GridPdfFontSource`](api/grid.md#gridpdffontsource) | Type alias | A TrueType font file (`.ttf` or `.ttc`): its bytes, or the URL to fetch it from. |
273
+ | [`GridPdfPaperSize`](api/grid.md#gridpdfpapersize) | Type alias | A paper size by name, or a page's width and height in points (1/72 inch). |
224
274
  | [`GridStateFilterValue`](api/grid.md#gridstatefiltervalue) | Type alias | |
225
275
  | [`GridStateLoadStatus`](api/grid.md#gridstateloadstatus) | Type alias | The outcome of loading a state. |
226
276
  | [`GridStateVersion`](api/grid.md#gridstateversion) | Type alias | |