@nanahoshi/mona-ui 0.39.1 → 0.40.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 (61) hide show
  1. package/docs/api/grid.md +214 -17
  2. package/docs/api/i18n.md +2 -0
  3. package/docs/api/locales.md +14 -14
  4. package/docs/grid-selection.md +134 -9
  5. package/docs/grid-state-export.md +56 -6
  6. package/docs/grid-tree.md +279 -0
  7. package/fesm2022/{nanahoshi-mona-ui-grid-grid-colgroup.component-Lv3GunpV.mjs → nanahoshi-mona-ui-grid-grid-colgroup.component-DpszxgFY.mjs} +2 -2
  8. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-BYH9XbCV.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-CpvzAcX8.mjs} +4 -3
  9. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BoSXXLKQ.mjs → nanahoshi-mona-ui-grid-grid-list.component-tRmEWiQR.mjs} +5 -5
  10. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-Df2gfS0X.mjs → nanahoshi-mona-ui-grid-grid-row.component-eET6dh2Q.mjs} +52 -35
  11. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-xjrcCXXF.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-8h2EMexB.mjs} +5 -5
  12. package/fesm2022/{nanahoshi-mona-ui-grid-grid.styles-aPD3c2A6.mjs → nanahoshi-mona-ui-grid-grid.styles-wAf6jsT9.mjs} +646 -20
  13. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1663 -22
  14. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +8 -0
  15. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +2 -0
  16. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +8 -0
  17. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +8 -0
  18. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +8 -0
  19. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +2 -0
  20. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +8 -0
  21. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +2 -0
  22. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +2 -0
  23. package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +2 -0
  24. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +8 -0
  25. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +2 -0
  26. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +2 -0
  27. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +2 -0
  28. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +2 -0
  29. package/i18n/catalogs/en-US.messages.json +2 -0
  30. package/llms.txt +4 -3
  31. package/locales/ar-sa/ar-sa.messages.json +2 -0
  32. package/locales/de-de/de-de.messages.json +2 -0
  33. package/locales/es-es/es-es.messages.json +2 -0
  34. package/locales/fr-fr/fr-fr.messages.json +2 -0
  35. package/locales/id-id/id-id.messages.json +2 -0
  36. package/locales/it-it/it-it.messages.json +2 -0
  37. package/locales/ja-jp/ja-jp.messages.json +2 -0
  38. package/locales/ko-kr/ko-kr.messages.json +2 -0
  39. package/locales/pl-pl/pl-pl.messages.json +2 -0
  40. package/locales/pt-br/pt-br.messages.json +2 -0
  41. package/locales/ru-ru/ru-ru.messages.json +2 -0
  42. package/locales/tr-tr/tr-tr.messages.json +2 -0
  43. package/locales/zh-cn/zh-cn.messages.json +2 -0
  44. package/locales/zh-tw/zh-tw.messages.json +2 -0
  45. package/package.json +1 -1
  46. package/types/nanahoshi-mona-ui-grid.d.ts +305 -3
  47. package/types/nanahoshi-mona-ui-i18n.d.ts +4 -0
  48. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +2 -0
  49. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +2 -0
  50. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +2 -0
  51. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +2 -0
  52. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +2 -0
  53. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +2 -0
  54. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +2 -0
  55. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +2 -0
  56. package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +2 -0
  57. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +2 -0
  58. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +2 -0
  59. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +2 -0
  60. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +2 -0
  61. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +2 -0
@@ -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 | |
@@ -0,0 +1,279 @@
1
+ # Tree List
2
+
3
+ > Show hierarchical rows in a grid, nested or linked by a parent key, with expandable levels.
4
+
5
+ Entry point: `@nanahoshi/mona-ui/grid`
6
+
7
+ **Selector:** `mona-grid[monaGridTree]`
8
+
9
+ `monaGridTree` shows the grid's rows as a tree: each row can have child rows, which show below it, indented, while it's expanded. The data can hold each item's children, or be flat, with each item naming its parent. Sorting, filtering, paging, selection, editing and export all keep working, on the rows as a tree.
10
+
11
+ ## Overview
12
+
13
+ Tell the grid how to find each row's children in one of two ways:
14
+
15
+ | Your data | Use | Example |
16
+ | :--- | :--- | :--- |
17
+ | Root items that hold their children, at any depth | `children`: the field holding them, or a function returning them | `children="subtasks"` |
18
+ | One flat list, each item naming its parent's `rowKey` value | `parentKey`: the field holding it, or a function returning it, with the grid's `rowKey` | `rowKey="id" parentKey="managerId"` |
19
+
20
+ Rows start collapsed. The expanded rows are a list of row keys you bind with `[(treeExpandedKeys)]`, so they survive paging, sorting and reloading the data. It's apart from the grid's own `expandedKeys`, which opens [detail rows](grid-rows.md).
21
+
22
+ **Use something else when:**
23
+
24
+ - The rows fall into groups by a column's value, such as orders by country. Use [Grouping & Aggregates](grid-grouping.md): the groups come from the data's values, not from its structure.
25
+ - People only browse the hierarchy and pick an item, without columns to compare. Use a [Tree View](tree-view.md).
26
+ - Each row has details of a different shape, such as an order's lines under the order. Use [detail rows](grid-rows.md).
27
+
28
+ ## Import & Quick Start
29
+
30
+ ```typescript
31
+ import { GridColumnComponent, GridComponent, GridTreeDirective } from "@nanahoshi/mona-ui/grid";
32
+ ```
33
+
34
+ ```typescript
35
+ protected readonly expandedIds = signal<unknown[]>([]);
36
+ ```
37
+
38
+ ```html
39
+ <mona-grid
40
+ aria-label="Project tasks"
41
+ children="subtasks"
42
+ rowKey="id"
43
+ [data]="tasks()"
44
+ monaGridTree
45
+ [(treeExpandedKeys)]="expandedIds">
46
+ <mona-grid-column expandable field="name" title="Task" />
47
+ <mona-grid-column field="owner" title="Owner" />
48
+ </mona-grid>
49
+ ```
50
+
51
+ ## Examples
52
+
53
+ ### Nested Children
54
+
55
+ `tasks-example.component.ts`
56
+
57
+ ```typescript
58
+ import { Component, signal } from "@angular/core";
59
+ import { ButtonDirective } from "@nanahoshi/mona-ui/button";
60
+ import {
61
+ GridColumnComponent,
62
+ GridComponent,
63
+ GridSortableDirective,
64
+ GridToolbarTemplateDirective,
65
+ GridTreeDirective
66
+ } from "@nanahoshi/mona-ui/grid";
67
+
68
+ interface Task {
69
+ readonly hours: number;
70
+ readonly id: number;
71
+ readonly name: string;
72
+ readonly owner: string;
73
+ readonly subtasks?: readonly Task[];
74
+ }
75
+
76
+ @Component({
77
+ selector: "app-grid-tree-tasks-example",
78
+ imports: [
79
+ ButtonDirective,
80
+ GridColumnComponent,
81
+ GridComponent,
82
+ GridSortableDirective,
83
+ GridToolbarTemplateDirective,
84
+ GridTreeDirective
85
+ ],
86
+ templateUrl: "./tasks-example.component.html"
87
+ })
88
+ export class GridTreeTasksExampleComponent {
89
+ protected readonly expandedIds = signal<unknown[]>([1]);
90
+ protected readonly tasks: readonly Task[] = [
91
+ {
92
+ id: 1,
93
+ name: "Website relaunch",
94
+ owner: "Amara Okafor",
95
+ hours: 120,
96
+ subtasks: [
97
+ {
98
+ id: 2,
99
+ name: "Design",
100
+ owner: "Mei Tanaka",
101
+ hours: 40,
102
+ subtasks: [
103
+ { id: 3, name: "Wireframes", owner: "Mei Tanaka", hours: 16 },
104
+ { id: 4, name: "Visual design", owner: "Sofia Rossi", hours: 24 }
105
+ ]
106
+ },
107
+ {
108
+ id: 5,
109
+ name: "Build",
110
+ owner: "Lukas Weber",
111
+ hours: 64,
112
+ subtasks: [
113
+ { id: 6, name: "Templates", owner: "Lukas Weber", hours: 40 },
114
+ { id: 7, name: "Content migration", owner: "Noah Clarke", hours: 24 }
115
+ ]
116
+ },
117
+ { id: 8, name: "Launch review", owner: "Amara Okafor", hours: 16 }
118
+ ]
119
+ },
120
+ {
121
+ id: 9,
122
+ name: "Mobile app",
123
+ owner: "Diego Ramos",
124
+ hours: 90,
125
+ subtasks: [
126
+ { id: 10, name: "User research", owner: "Sofia Rossi", hours: 30 },
127
+ { id: 11, name: "Prototype", owner: "Mei Tanaka", hours: 60 }
128
+ ]
129
+ },
130
+ { id: 12, name: "Quarterly report", owner: "Noah Clarke", hours: 12 }
131
+ ];
132
+ }
133
+ ```
134
+
135
+ `tasks-example.component.html`
136
+
137
+ ```html
138
+ <mona-grid
139
+ #tree="monaGridTree"
140
+ aria-label="Project tasks"
141
+ children="subtasks"
142
+ rowKey="id"
143
+ [data]="tasks"
144
+ [pageSize]="20"
145
+ monaGridSortable
146
+ monaGridTree
147
+ [(treeExpandedKeys)]="expandedIds">
148
+ <ng-template monaGridToolbarTemplate>
149
+ <button monaButton type="button" (click)="tree.expandAll()">Expand all</button>
150
+ <button monaButton type="button" (click)="tree.collapseAll()">Collapse all</button>
151
+ </ng-template>
152
+ <mona-grid-column expandable field="name" title="Task" />
153
+ <mona-grid-column field="owner" title="Owner" />
154
+ <mona-grid-column field="hours" title="Hours" type="number" [width]="100" />
155
+ </mona-grid>
156
+ ```
157
+
158
+ Each task holds its subtasks, and the Task column has the toggles because it's `expandable`; without that on any column, the first visible data column has them. Sort a column, and each task's subtasks sort among themselves, under it. The toolbar's buttons call `expandAll()` and `collapseAll()` through the directive's `exportAs`, `monaGridTree`, and both report the new keys through `treeExpandedKeysChange`.
159
+
160
+ ### Flat Data with Parent Keys
161
+
162
+ `org-chart-example.component.ts`
163
+
164
+ ```typescript
165
+ import { Component } from "@angular/core";
166
+ import {
167
+ GridColumnComponent,
168
+ GridComponent,
169
+ GridFilterableDirective,
170
+ GridTreeDirective
171
+ } from "@nanahoshi/mona-ui/grid";
172
+
173
+ interface Employee {
174
+ readonly id: number;
175
+ readonly location: string;
176
+ readonly managerId: number | null;
177
+ readonly name: string;
178
+ readonly title: string;
179
+ }
180
+
181
+ @Component({
182
+ selector: "app-grid-tree-org-chart-example",
183
+ imports: [GridColumnComponent, GridComponent, GridFilterableDirective, GridTreeDirective],
184
+ templateUrl: "./org-chart-example.component.html"
185
+ })
186
+ export class GridTreeOrgChartExampleComponent {
187
+ /** Flat rows: each names its manager's id, and the CEO has none. */
188
+ protected readonly employees: readonly Employee[] = [
189
+ { id: 1, managerId: null, name: "Amara Okafor", title: "Chief executive", location: "Lagos" },
190
+ { id: 2, managerId: 1, name: "Lukas Weber", title: "VP engineering", location: "Berlin" },
191
+ { id: 3, managerId: 1, name: "Diego Ramos", title: "VP product", location: "Lima" },
192
+ { id: 4, managerId: 2, name: "Mei Tanaka", title: "Engineering manager", location: "Osaka" },
193
+ { id: 5, managerId: 4, name: "Noah Clarke", title: "Engineer", location: "Toronto" },
194
+ { id: 6, managerId: 4, name: "Priya Nair", title: "Engineer", location: "Pune" },
195
+ { id: 7, managerId: 2, name: "Jonas Berg", title: "Site reliability lead", location: "Oslo" },
196
+ { id: 8, managerId: 3, name: "Sofia Rossi", title: "Researcher", location: "Turin" },
197
+ { id: 9, managerId: 3, name: "Lucas Martin", title: "Designer", location: "Lyon" }
198
+ ];
199
+ }
200
+ ```
201
+
202
+ `org-chart-example.component.html`
203
+
204
+ ```html
205
+ <mona-grid
206
+ aria-label="Organization"
207
+ parentKey="managerId"
208
+ rowKey="id"
209
+ [data]="employees"
210
+ [monaGridFilterable]="{ enabled: true, type: 'row' }"
211
+ monaGridTree
212
+ [treeExpandedKeys]="[1]">
213
+ <mona-grid-column field="name" title="Name" />
214
+ <mona-grid-column field="title" title="Title" />
215
+ <mona-grid-column field="location" title="Location" />
216
+ </mona-grid>
217
+ ```
218
+
219
+ Every employee names a manager's `id` in `managerId`, and the chief executive names none. Type a name in the filter row, such as "Priya": the grid keeps the rows above each match, so you see where she sits, and expands them.
220
+
221
+ ## Behavior
222
+
223
+ ### Building the tree
224
+
225
+ - **With `children`**, the grid's `data` holds the root items, and the grid walks their children at any depth. An item that turns up again inside itself isn't repeated.
226
+ - **With `parentKey`**, an item is a root when its parent key is empty, names no row in the data, or names the item itself. Rows whose parents form a loop become roots, so no row is lost.
227
+ - Changing `data`, `children` or `parentKey` rebuilds the tree, and the expanded rows that still exist stay expanded.
228
+
229
+ ### Sorting, filtering and paging
230
+
231
+ - **Sorting** orders each row's children among themselves, so children always stay under their parent.
232
+ - **Filtering** keeps the rows that match and every row above them, and expands those, reporting the new keys through `treeExpandedKeysChange`. A row that only leads to matches shows even if it doesn't match itself.
233
+ - **Paging** counts the rows that show: the roots, and the children of expanded rows.
234
+ - **Grouping** and row reordering are off in a tree, because the tree already decides where each row goes.
235
+ - **Selection** and **editing** work on tree rows as on any other, and select-all takes the rows that show.
236
+
237
+ ### Export
238
+
239
+ `exportCsv`, `exportExcel` and `exportPdf` write every row, collapsed or not, in tree order. The workbook groups each row's children into an outline that the spreadsheet can collapse, and indents the tree column's cells by level, as the PDF does. See [State & Export](grid-state-export.md).
240
+
241
+ ## Accessibility
242
+
243
+ With a tree, the grid's role is `treegrid`, and each row says where it sits: its level, its position among its siblings and whether it's expanded. The toggle is a pointer convenience, hidden from assistive technology, since the keyboard does the same on the tree column's cell.
244
+
245
+ ### Keyboard
246
+
247
+ On the tree column's cell:
248
+
249
+ | Key | Action |
250
+ | --- | --- |
251
+ | `ArrowRight` | Expands a collapsed row. On an expanded row, or one without children, moves to the next cell. |
252
+ | `ArrowLeft` | Collapses an expanded row. Otherwise moves to the previous cell, or, when the tree column is the first, to the parent row's cell. |
253
+
254
+ `ArrowLeft` and `ArrowRight` swap in right-to-left layouts. The rest of the grid's keys are on [Grid Overview](grid.md#keyboard).
255
+
256
+ ### ARIA
257
+
258
+ | Attribute | When present | Value |
259
+ | --- | --- | --- |
260
+ | `role` | On the tabular content region | `"treegrid"` |
261
+ | `aria-level` | On every body row | The row's depth, from 1 for a root |
262
+ | `aria-setsize` / `aria-posinset` | On every body row | How many siblings the row has, and its place among them |
263
+ | `aria-expanded` | On a row with children | Whether its children show |
264
+
265
+ ## API
266
+
267
+ Everything below is imported from `@nanahoshi/mona-ui/grid`. Each name links to its reference page, with every input, output, property and method.
268
+
269
+ | Name | Kind | Description |
270
+ | --- | --- | --- |
271
+ | [`GridTreeDirective`](api/grid.md#gridtreedirective) | Directive | Shows the grid's rows as a tree: each row can have child rows, shown below it, indented, when it's expanded. |
272
+
273
+ ### Types
274
+
275
+ | Type | Kind | Description |
276
+ | --- | --- | --- |
277
+ | [`GridTreeChildren`](api/grid.md#gridtreechildren) | Type alias | The field holding a data item's children, or a function returning them. |
278
+
279
+ **Related types:** [`GridKeySelector`](api/grid.md#gridkeyselector)
@@ -1,4 +1,4 @@
1
- import { G as GridService } from "./nanahoshi-mona-ui-grid-grid.styles-aPD3c2A6.mjs";
1
+ import { q as GridService } from "./nanahoshi-mona-ui-grid-grid.styles-wAf6jsT9.mjs";
2
2
  import * as i0 from "@angular/core";
3
3
  import { Component, inject } from "@angular/core";
4
4
  import { take } from "rxjs";
@@ -74,4 +74,4 @@ i0.ɵɵngDeclareClassMetadata({
74
74
  });
75
75
  export { removeGridRow as n, GridColgroupComponent as t };
76
76
 
77
- //# sourceMappingURL=nanahoshi-mona-ui-grid-grid-colgroup.component-Lv3GunpV.mjs.map
77
+ //# sourceMappingURL=nanahoshi-mona-ui-grid-grid-colgroup.component-DpszxgFY.mjs.map
@@ -1,4 +1,4 @@
1
- import { B as GridLogicalCellDirective, G as GridService, W as GridLockedCellDirective, h as gridFooterTableRowThemeVariants, m as gridFooterTableCellThemeVariants } from "./nanahoshi-mona-ui-grid-grid.styles-aPD3c2A6.mjs";
1
+ import { H as GridLogicalCellDirective, K as GridLockedCellDirective, h as gridFooterTableRowThemeVariants, m as gridFooterTableCellThemeVariants, q as GridService } from "./nanahoshi-mona-ui-grid-grid.styles-wAf6jsT9.mjs";
2
2
  import * as i0 from "@angular/core";
3
3
  import { Component, Directive, computed, inject, input } from "@angular/core";
4
4
  import { NgTemplateOutlet } from "@angular/common";
@@ -401,7 +401,8 @@ var GridFooterRowComponent = class GridFooterRowComponent {
401
401
  "readOnly",
402
402
  "rowIndex",
403
403
  "rowUid",
404
- "section"
404
+ "section",
405
+ "treeCell"
405
406
  ],
406
407
  outputs: [
407
408
  "edit",
@@ -482,4 +483,4 @@ i0.ɵɵngDeclareClassMetadata({
482
483
  });
483
484
  export { GridFooterRowComponent };
484
485
 
485
- //# sourceMappingURL=nanahoshi-mona-ui-grid-grid-footer-row.component-BYH9XbCV.mjs.map
486
+ //# sourceMappingURL=nanahoshi-mona-ui-grid-grid-footer-row.component-CpvzAcX8.mjs.map