ui-sdk-table-react 0.0.0-stage → 0.2.7

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/docs/api-react.md +312 -0
  4. package/docs/cell-editing.md +246 -0
  5. package/docs/cells-and-slots.md +127 -0
  6. package/docs/component-body.md +33 -0
  7. package/docs/component-cell.md +31 -0
  8. package/docs/component-col.md +31 -0
  9. package/docs/component-edit-error.md +31 -0
  10. package/docs/component-editor.md +31 -0
  11. package/docs/component-fill-handle.md +31 -0
  12. package/docs/component-foot.md +31 -0
  13. package/docs/component-head.md +31 -0
  14. package/docs/component-header-cell.md +31 -0
  15. package/docs/component-header-row.md +33 -0
  16. package/docs/component-plain-row.md +31 -0
  17. package/docs/component-resizer.md +33 -0
  18. package/docs/component-root.md +36 -0
  19. package/docs/component-row.md +33 -0
  20. package/docs/component-spacer.md +31 -0
  21. package/docs/controller-and-view.md +104 -0
  22. package/docs/examples-agents.md +50 -0
  23. package/docs/examples-column-definitions.md +179 -0
  24. package/docs/examples-formula-writer.md +276 -0
  25. package/docs/examples-styling.md +173 -0
  26. package/docs/examples.md +114 -0
  27. package/docs/excel-formulas.md +115 -0
  28. package/docs/export.md +96 -0
  29. package/docs/fill.md +126 -0
  30. package/docs/first-table.md +150 -0
  31. package/docs/formats.md +176 -0
  32. package/docs/groups-and-totals.md +118 -0
  33. package/docs/history.md +126 -0
  34. package/docs/installation.md +52 -0
  35. package/docs/llms.txt +13 -0
  36. package/docs/pages-and-server-mode.md +246 -0
  37. package/docs/range-copy-and-paste.md +115 -0
  38. package/docs/react.md +85 -0
  39. package/docs/reference-columns.md +179 -0
  40. package/docs/reference-controller.md +137 -0
  41. package/docs/reference-export.md +59 -0
  42. package/docs/reference-formulas.md +42 -0
  43. package/docs/reference-implementation.md +29 -0
  44. package/docs/reference-messages.md +55 -0
  45. package/docs/reference-view.md +116 -0
  46. package/docs/row-numbers-and-letters.md +112 -0
  47. package/docs/rows.md +350 -0
  48. package/docs/selection-and-keyboard.md +151 -0
  49. package/docs/sheet-formulas.md +329 -0
  50. package/docs/sheet-options.md +214 -0
  51. package/docs/skills.md +41 -0
  52. package/docs/sort-filter-and-search.md +260 -0
  53. package/docs/state-and-events.md +90 -0
  54. package/docs/styled-table.md +237 -0
  55. package/docs/table-components.md +105 -0
  56. package/package.json +45 -3
  57. package/src/index.ts +62 -0
  58. package/src/reference.ts +113 -0
@@ -0,0 +1,173 @@
1
+ # React: Styling
2
+
3
+ [All examples and setup](./examples.md)
4
+
5
+ ## sticky
6
+
7
+ ```tsx title="sticky.tsx"
8
+ 'use client'
9
+
10
+ import { Toggle } from '@ui-sdk/react/toggle'
11
+ import { useState } from 'react'
12
+ import type { ColumnDef } from 'ui-sdk-table-core'
13
+ import { Table } from 'ui-sdk-table-react/reference'
14
+
15
+ const stations = [
16
+ { station: 'Bergen', low: 3, high: 8, rain: 12, wind: 34 },
17
+ { station: 'Cork', low: 6, high: 12, rain: 4, wind: 28 },
18
+ { station: 'Porto', low: 11, high: 18, rain: 0, wind: 16 },
19
+ { station: 'Gdańsk', low: 2, high: 7, rain: 1, wind: 22 },
20
+ { station: 'Tromsø', low: -4, high: 1, rain: 2, wind: 31 },
21
+ { station: 'Nantes', low: 7, high: 14, rain: 3, wind: 19 },
22
+ ]
23
+ const readings = [0, 1, 2].flatMap((day) =>
24
+ stations.map(({ station, low, high, rain, wind }, i) => ({
25
+ id: `r${day * stations.length + i}`,
26
+ station,
27
+ day: `${10 + day} Nov`,
28
+ low: low - day,
29
+ high: high + day,
30
+ rain: Math.max(0, rain - day),
31
+ wind: wind + day * 2,
32
+ })),
33
+ )
34
+ type Reading = (typeof readings)[number]
35
+ const columns: ColumnDef<Reading>[] = [
36
+ { id: 'station', header: 'Station', aggregate: () => 'Extremes' },
37
+ { id: 'low', header: 'Low °C', format: 'integer', aggregate: 'min' },
38
+ { id: 'high', header: 'High °C', format: 'integer', aggregate: 'max' },
39
+ { id: 'rain', header: 'Rain mm', format: 'integer', aggregate: 'max' },
40
+ { id: 'wind', header: 'Gust km/h', format: 'integer', aggregate: 'max' },
41
+ { id: 'day', header: 'Date' },
42
+ ]
43
+ const pinning = { start: ['station'] }
44
+ const styles = `
45
+ .weather-log {
46
+ --paper: light-dark(#fff, #191d1c);
47
+ --ink: light-dark(#18382f, #e2eee8);
48
+ --secondary: light-dark(#52665e, #b0bfb7);
49
+ --rule: light-dark(#dce4de, #36443c);
50
+ --band: light-dark(#edf3ef, #25332c);
51
+ inline-size: 100%;
52
+ min-inline-size: 0;
53
+ color: var(--ink);
54
+ font: 14px/1.4 system-ui, sans-serif;
55
+ }
56
+ .weather-log header { margin-block-end: 18px; }
57
+ .weather-log h2 {
58
+ margin: 0;
59
+ font: 500 clamp(25px, 3vw, 32px)/1.15 Georgia, serif;
60
+ letter-spacing: -0.03em;
61
+ color: var(--ink);
62
+ }
63
+ .weather-log p, .weather-log .log-tools {
64
+ margin: 6px 0 0;
65
+ font-size: 13px;
66
+ color: var(--secondary);
67
+ }
68
+ .weather-log .frame {
69
+ max-block-size: 23rem;
70
+ overflow: auto;
71
+ scrollbar-width: thin;
72
+ background: var(--paper);
73
+ }
74
+ .weather-log [data-slot='table'] {
75
+ display: table;
76
+ inline-size: 100%;
77
+ min-inline-size: 29rem;
78
+ border-collapse: separate;
79
+ border-spacing: 0;
80
+ font: inherit;
81
+ font-variant-numeric: tabular-nums;
82
+ }
83
+ .weather-log [data-wide] [data-slot='table'] { min-inline-size: max(48rem, 130%); table-layout: fixed; }
84
+ .weather-log [data-wide] col[data-column='station'] { width: 7rem; }
85
+ .weather-log :is(td, th) {
86
+ box-sizing: border-box;
87
+ block-size: 46px;
88
+ padding: 0 10px;
89
+ white-space: nowrap;
90
+ text-align: start;
91
+ border: 0;
92
+ border-block-end: 1px solid var(--rule);
93
+ background: var(--paper);
94
+ color: var(--ink);
95
+ }
96
+ .weather-log [data-format='integer'] { text-align: end; }
97
+ .weather-log tbody [data-column='station'] { font-weight: 650; }
98
+ .weather-log tbody [data-column='low'] { color: light-dark(#30617a, #a3cada); }
99
+ .weather-log tbody [data-column='high'] { color: light-dark(#92522f, #e6b18e); }
100
+ .weather-log tbody [data-column='day'] { color: var(--secondary); }
101
+ .weather-log [data-pinned='start'] {
102
+ position: sticky;
103
+ inset-inline-start: var(--table-pin-offset, 0px);
104
+ z-index: 1;
105
+ }
106
+ .weather-log tr[data-sticky] > * {
107
+ position: sticky;
108
+ z-index: 2;
109
+ background: var(--band);
110
+ font-weight: 600;
111
+ }
112
+ .weather-log tr[data-sticky='top'] > * {
113
+ inset-block-start: var(--table-sticky-offset, 0px);
114
+ block-size: 38px;
115
+ font-size: 12px;
116
+ }
117
+ .weather-log tr[data-sticky='bottom'] > * {
118
+ inset-block-end: var(--table-sticky-offset, 0px);
119
+ border-block: 1px solid var(--rule);
120
+ }
121
+ .weather-log tr[data-sticky] > [data-pinned] { z-index: 3; }
122
+ .weather-log :focus-visible { outline: 2px solid currentColor; outline-offset: -2px; }
123
+ .weather-log .log-tools {
124
+ display: flex;
125
+ align-items: center;
126
+ justify-content: space-between;
127
+ gap: 8px;
128
+ flex-wrap: wrap;
129
+ margin-block-start: 12px;
130
+ }
131
+ .weather-log .log-tools button {
132
+ padding: 5px 10px;
133
+ border: 1px solid var(--secondary);
134
+ border-radius: 5px;
135
+ background: transparent;
136
+ color: var(--ink);
137
+ font: inherit;
138
+ cursor: pointer;
139
+ }
140
+ .weather-log .log-tools button[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
141
+ `
142
+
143
+ export default function Sticky() {
144
+ const [wide, setWide] = useState(false)
145
+ return (
146
+ <section className="weather-log">
147
+ <style>{styles}</style>
148
+ <header>
149
+ <h2>Coastal weather log</h2>
150
+ <p>Sample observations · 10–12 November 2026</p>
151
+ </header>
152
+ <div className="frame" data-wide={wide || undefined}>
153
+ <Table
154
+ rows={readings}
155
+ columns={columns}
156
+ defaultColumnPinning={pinning}
157
+ stickyHeader
158
+ stickyFooter
159
+ aria-label="Weather readings"
160
+ />
161
+ </div>
162
+ <div className="log-tools">
163
+ <span>
164
+ {readings.length} readings · {stations.length} stations
165
+ </span>
166
+ <Toggle pressed={wide} onPressedChange={(value) => setWide(value)}>
167
+ Wide columns
168
+ </Toggle>
169
+ </div>
170
+ </section>
171
+ )
172
+ }
173
+ ```
@@ -0,0 +1,114 @@
1
+ # React examples
2
+
3
+ Start with the [React parts](./react.md). Each link opens a complete example source file. Examples that import the adapter's `/reference` entry demonstrate the opt-in complete table. Install any packages the file imports directly, including `ui-sdk-table-core` if present.
4
+
5
+ ## First table
6
+
7
+ - [first-table/people](./first-table.md)
8
+ - [first-table/styled](./first-table.md)
9
+
10
+ ## Table components
11
+
12
+ - [table-components/parts](./table-components.md)
13
+
14
+ ## Selection and keyboard
15
+
16
+ - [selection-and-keyboard/select](./selection-and-keyboard.md)
17
+
18
+ ## Editing
19
+
20
+ - [cell-editing/prices](./cell-editing.md)
21
+ - [cell-editing/entry](./cell-editing.md)
22
+
23
+ ## Range, copy and paste
24
+
25
+ - [range-copy-and-paste/range](./range-copy-and-paste.md)
26
+
27
+ ## Fill
28
+
29
+ - [fill/fill](./fill.md)
30
+
31
+ ## History
32
+
33
+ - [history/undo](./history.md)
34
+
35
+ ## Column definitions
36
+
37
+ - [column-definitions/formats](./examples-column-definitions.md#formats)
38
+ - [column-definitions/layout](./examples-column-definitions.md#layout)
39
+
40
+ ## Cells and slots
41
+
42
+ - [cells-and-slots/slots](./cells-and-slots.md)
43
+
44
+ ## A styled table for an app
45
+
46
+ - [styled-table/toolbar](./styled-table.md)
47
+
48
+ ## Styling
49
+
50
+ - [styling/sticky](./examples-styling.md#sticky)
51
+
52
+ ## State and events
53
+
54
+ - [state-and-events/controlled](./state-and-events.md)
55
+
56
+ ## Controller and view
57
+
58
+ - [controller-and-view/outside](./controller-and-view.md)
59
+
60
+ ## Sort, filter and search
61
+
62
+ - [sort-filter-and-search/sort](./sort-filter-and-search.md)
63
+ - [sort-filter-and-search/search](./sort-filter-and-search.md)
64
+ - [sort-filter-and-search/facets](./sort-filter-and-search.md)
65
+
66
+ ## Groups and totals
67
+
68
+ - [groups-and-totals/groups](./groups-and-totals.md)
69
+
70
+ ## Pages and server mode
71
+
72
+ - [pages-and-server-mode/pages](./pages-and-server-mode.md)
73
+ - [pages-and-server-mode/server](./pages-and-server-mode.md)
74
+
75
+ ## Rows
76
+
77
+ - [rows/tree](./rows.md)
78
+ - [rows/detail](./rows.md)
79
+ - [rows/pinned](./rows.md)
80
+ - [rows/window](./rows.md)
81
+
82
+ ## Export
83
+
84
+ - [export/files](./export.md)
85
+
86
+ ## The sheet options
87
+
88
+ - [sheet-options/sheet](./sheet-options.md)
89
+ - [sheet-options/totals](./sheet-options.md)
90
+
91
+ ## Formats
92
+
93
+ - [formats/formats](./formats.md)
94
+
95
+ ## Row numbers and letters
96
+
97
+ - [row-numbers-and-letters/letters](./row-numbers-and-letters.md)
98
+
99
+ ## Formulas
100
+
101
+ - [sheet-formulas/column](./sheet-formulas.md)
102
+ - [sheet-formulas/cells](./sheet-formulas.md)
103
+
104
+ ## A formula writer
105
+
106
+ - [formula-writer/writer](./examples-formula-writer.md#writer)
107
+
108
+ ## An Excel file with formulas
109
+
110
+ - [excel-formulas/file](./excel-formulas.md)
111
+
112
+ ## Agents
113
+
114
+ - [agents/agent](./examples-agents.md#agent)
@@ -0,0 +1,115 @@
1
+ # An Excel file with formulas
2
+
3
+ Download a sheet as an Excel file whose cells keep their formulas, where Excel computes them the same way.
4
+
5
+ Use it for a sheet with formulas that a person goes on with in a spreadsheet. Without it, the file holds the results only.
6
+
7
+ ```tsx title="file.tsx"
8
+ 'use client'
9
+
10
+ import { useState } from 'react'
11
+ import { createTableController } from 'ui-sdk-table-react'
12
+ import { Table } from 'ui-sdk-table-react/reference'
13
+ import { applyEdits, rowNumberColumn, type CellFormulas, type ColumnDef } from 'ui-sdk-table-core'
14
+ import { createFormulaEngine, excelFormulas } from 'ui-sdk-table-core/formulas'
15
+ import { Button } from '@ui-sdk/react/button'
16
+
17
+ type Month = { id: string; month: string; income: number; costs: number; profit?: unknown }
18
+
19
+ const initialRows: Month[] = [
20
+ { id: 'm1', month: 'January', income: 8200, costs: 5100, profit: 3100 },
21
+ { id: 'm2', month: 'February', income: 7600, costs: 5400, profit: 2200 },
22
+ { id: 'm3', month: 'March', income: 9100, costs: 5050, profit: 4050 },
23
+ ]
24
+
25
+ const columns: ColumnDef<Month>[] = [
26
+ rowNumberColumn<Month>(),
27
+ { id: 'month', header: 'Month', editable: false },
28
+ { id: 'income', header: 'Income', format: 'integer' },
29
+ { id: 'costs', header: 'Costs', format: 'integer' },
30
+ { id: 'profit', header: 'Profit', format: 'integer' },
31
+ ]
32
+
33
+ const initialFormulas: CellFormulas = {
34
+ cells: {
35
+ m1: { profit: '=[income]-[costs]' },
36
+ m2: { profit: '=[income]-[costs]' },
37
+ m3: { profit: '=[income]-[costs]' },
38
+ },
39
+ }
40
+
41
+ export default function File() {
42
+ const [rows, setRows] = useState<Month[]>(initialRows)
43
+ const [formulas, setFormulas] = useState<CellFormulas>(initialFormulas)
44
+ const [controller] = useState(createTableController)
45
+ const [engine] = useState(createFormulaEngine)
46
+ async function download() {
47
+ const { downloadXlsx } = await import('ui-sdk-table-core/export')
48
+ await downloadXlsx(controller.exportData(), 'profit', { formula: excelFormulas() })
49
+ }
50
+ return (
51
+ <>
52
+ <div>
53
+ <Button onClick={() => download()}>Download Excel</Button>
54
+ </div>
55
+ <Table
56
+ rows={rows}
57
+ columns={columns}
58
+ aria-label="Profit by month"
59
+ controller={controller}
60
+ locale="en-US"
61
+ sheet
62
+ columnLetters
63
+ cellFormulas={formulas}
64
+ onCellFormulasChange={setFormulas}
65
+ formulas={engine}
66
+ onCellEdit={(edits) => setRows((current) => applyEdits(current, edits))}
67
+ />
68
+ </>
69
+ )
70
+ }
71
+ ```
72
+
73
+ Press Download Excel. In profit.xlsx, each cell under Profit holds the formula of its row, such as B2-C2, with its result beside it.
74
+
75
+ ## Turn it on
76
+
77
+ Load the writer when the person asks for the file, and pass it `excelFormulas()`:
78
+
79
+ ```ts
80
+ await downloadXlsx(controller.exportData(), 'profit', { formula: excelFormulas() })
81
+ ```
82
+
83
+ - `excelFormulas()` of the formulas entry is the `formula` option of `toXlsx` and `downloadXlsx`.
84
+ - A cell with a formula, of its own or of its column, gets the formula of the file (`<f>`) with its result beside it, when the formula means the same in Excel (below).
85
+ - The addresses are places in the file. A sorted or filtered export keeps the formulas that read their own row.
86
+ - An error of a formula is an error cell of the file. `#CYCLE!` stays a text.
87
+ - A CSV holds the results.
88
+ - `ExportCell.formula`, `ExportRow.id` and `ExportData.document` carry the formulas to a writer of your own.
89
+
90
+ ## Dates of the `period` format
91
+
92
+ With or without the option, a column with the format `period` whose unit is `day`, `month` or `year` is a date cell with a pattern when a spreadsheet shows the pattern as the screen does: `Nov 21, 2026`, `November 2026` and `2026` in `en-US`. Else it is its text. A week, a quarter, an hour and a day of the week are texts.
93
+
94
+ ## When a formula goes into the file
95
+
96
+ A cell gets the formula of the file only when the whole formula means the same in Excel:
97
+
98
+ - every cell that it reads is in the file and holds there the value that it holds in the table: no day, no cell written as its text;
99
+ - a range is one column whose rows are in the file in the order of the document and next to each other;
100
+ - each function is in `EXCEL_FUNCTIONS`.
101
+
102
+ A function that came after Excel 2007 (`CONCAT`, `IFS`, `SWITCH`, `IFNA`, `TEXTJOIN`) is written with the prefix `_xlfn.` that the file format asks for. `SUMIF`, `AVERAGEIF`, the lookups, `VALUE`, `TEXT`, `TODAY`, `NOW`, `EOMONTH` and the date functions go as their result: Excel stretches a smaller range of `SUMIF`, searches sorted data in halves, reads its own locale in `VALUE` and `TEXT`, computes `TODAY` and `NOW` again when it opens the file, and has no day text.
103
+
104
+ Else the cell holds its result, as without the option. A file without the option holds the same bytes as the file of a table without formulas.
105
+
106
+ See the [Formula tiles of the sink](https://ui-sdk-table.fdts.dev/?page=sink&only=formula) and the page [Export](./export.md).
107
+
108
+ ## Names
109
+
110
+ - `ui-sdk-table-core/formulas` exports `excelFormulas` and `EXCEL_FUNCTIONS`.
111
+ - `ui-sdk-table-core/export` exports `downloadXlsx`, `toXlsx` and the type `XlsxFormulas`.
112
+
113
+ For shared methods and result types, see [Controller](./reference-controller.md) and [View](./reference-view.md).
114
+
115
+ For props, callbacks and render functions, see the [React API reference](./api-react.md).
package/docs/export.md ADDED
@@ -0,0 +1,96 @@
1
+ # Export
2
+
3
+ Write the rows of the table to a CSV or an Excel file, with the text that the screen shows.
4
+
5
+ `controller.exportData()` collects the cells as plain data. The writers are in the entry `ui-sdk-table-core/export`, so a page without an export does not carry them: load it with `import()` where a person asks for a file.
6
+
7
+ ```tsx title="files.tsx"
8
+ 'use client'
9
+
10
+ import { useState } from 'react'
11
+ import { createTableController } from 'ui-sdk-table-react'
12
+ import { Table } from 'ui-sdk-table-react/reference'
13
+ import type { ColumnDef } from 'ui-sdk-table-core'
14
+ import { Button } from '@ui-sdk/react/button'
15
+
16
+ type Order = { id: string; customer: string; city: string; total: number }
17
+
18
+ const orders: Order[] = [
19
+ { id: 'o1', customer: 'Northway', city: 'Oslo', total: 1240 },
20
+ { id: 'o2', customer: 'Sola', city: 'Seville', total: 860.5 },
21
+ { id: 'o3', customer: 'Arc', city: 'Lyon', total: 2310 },
22
+ ]
23
+
24
+ const columns: ColumnDef<Order>[] = [
25
+ { id: 'customer', header: 'Customer', sortable: true },
26
+ { id: 'city', header: 'City' },
27
+ { id: 'total', header: 'Total', format: 'decimal', aggregate: 'sum' },
28
+ // The id is for the screen only.
29
+ { id: 'id', header: 'Id', exportable: false },
30
+ ]
31
+
32
+ export default function Files() {
33
+ const [controller] = useState(createTableController)
34
+ const [csv, setCsv] = useState('')
35
+ async function preview() {
36
+ const { toCsv } = await import('ui-sdk-table-core/export')
37
+ setCsv(toCsv(controller.exportData({ totals: true })))
38
+ }
39
+ async function download() {
40
+ const { downloadXlsx } = await import('ui-sdk-table-core/export')
41
+ await downloadXlsx(controller.exportData(), 'orders')
42
+ }
43
+ return (
44
+ <>
45
+ <div>
46
+ <Button onClick={() => preview()}>Show the CSV</Button>
47
+ <Button onClick={() => download()}>Download Excel</Button>
48
+ </div>
49
+ <Table
50
+ rows={orders}
51
+ columns={columns}
52
+ aria-label="Orders to export"
53
+ controller={controller}
54
+ locale="en-US"
55
+ />
56
+ {csv && <pre data-testid="csv">{csv}</pre>}
57
+ </>
58
+ )
59
+ }
60
+ ```
61
+
62
+ Press Show the CSV. The file holds the customer, the city and the total of each order and a row of totals, and no id. Download Excel saves the same rows as orders.xlsx.
63
+
64
+ ## What goes in
65
+
66
+ `exportData(options)` takes:
67
+
68
+ - `rows`: `'filtered'` (the default, every row that passes the filters, on all pages, in the order of the screen), `'page'`, `'all'` (in the order of the data) or `'selected'`.
69
+ - `columns`: `'visible'` (the default, in their order), `'all'` (the hidden columns after them) or a list of ids.
70
+ - `children`: whether the child rows of a tree come with it, open or not. Defaults to true.
71
+ - `groups`: whether each group gets a row of its own before its rows. Defaults to false.
72
+ - `totals`: whether a last row holds the totals. Defaults to false.
73
+
74
+ A column with `exportable: false` is in no file. `exportValue(row)` of a column gives the value of a file in place of the value and its format, when a cell displays custom content.
75
+
76
+ ## The text of a cell
77
+
78
+ The text of a cell in a file is the text of the screen. An Excel cell is a number or a date with a pattern only when a spreadsheet shows it as the screen does; else the cell is text.
79
+
80
+ ## The writers
81
+
82
+ - `toCsv(data, options)` returns the text. Its options: `separator` (a comma), `lineEnd` (`\r\n`), `header` (true), `bom` (true, so Excel reads UTF-8), `escapeFormulas` (true: a text that a spreadsheet would read as a formula gets a `'` before it).
83
+ - `toXlsx(data, options)` returns the bytes of the file. Its options: `sheetName`, `freezeHeader` (true), `compress` (true), and `formula` for a table with formulas: see [An Excel file with formulas](./excel-formulas.md).
84
+ - `downloadCsv(data, filename, options)` and `downloadXlsx(data, filename, options)` save a file in the browser.
85
+
86
+ With `manualPage`, the table has one page of a server, so each set of rows is of that page.
87
+
88
+ ## Names
89
+
90
+ - **Export entry:** `toCsv`, `toXlsx`, `downloadCsv`, `downloadXlsx`, `downloadFile`, `zip`, `XLSX_TYPE`, and the type `XlsxFormulas`.
91
+
92
+ For shared methods and result types, see [Controller](./reference-controller.md) and [View](./reference-view.md).
93
+
94
+ For props, callbacks and render functions, see the [React API reference](./api-react.md).
95
+
96
+ See the [More tiles of the sink](https://ui-sdk-table.fdts.dev/?page=sink&only=more).
package/docs/fill.md ADDED
@@ -0,0 +1,126 @@
1
+ # Fill
2
+
3
+ Let a person drag the corner of a range to fill more cells, with a series where the values have one step.
4
+
5
+ Use it in a sheet where rows repeat a value or go on with a series: weeks, days, numbers.
6
+
7
+ ```tsx title="fill.tsx"
8
+ 'use client'
9
+
10
+ import { useState } from 'react'
11
+ import { createTableController } from 'ui-sdk-table-react'
12
+ import { Table } from 'ui-sdk-table-react/reference'
13
+ import { applyEdits, type ColumnDef } from 'ui-sdk-table-core'
14
+ import { Button } from '@ui-sdk/react/button'
15
+
16
+ type Lesson = { id: string; week: number | null; day: string; room: string }
17
+
18
+ const columns: ColumnDef<Lesson>[] = [
19
+ { id: 'week', header: 'Week', format: 'integer' },
20
+ { id: 'day', header: 'Day' },
21
+ { id: 'room', header: 'Room' },
22
+ ]
23
+
24
+ const initialRows: Lesson[] = [
25
+ { id: 'l1', week: 1, day: '2027-01-04', room: 'A1' },
26
+ { id: 'l2', week: 2, day: '2027-01-11', room: 'B2' },
27
+ { id: 'l3', week: null, day: '', room: '' },
28
+ { id: 'l4', week: null, day: '', room: '' },
29
+ { id: 'l5', week: null, day: '', room: '' },
30
+ ]
31
+
32
+ const styles = `
33
+ .demo-fill-fill td { position: relative; }
34
+ .demo-fill-fill td[data-selected] { background: var(--picked, light-dark(#dbeafe, #24375b)); }
35
+ .demo-fill-fill [data-slot='table-fill-handle'] {
36
+ position: absolute;
37
+ inset-block-end: -3px;
38
+ inset-inline-end: -3px;
39
+ width: 8px;
40
+ height: 8px;
41
+ background: Highlight;
42
+ cursor: crosshair;
43
+ touch-action: none;
44
+ z-index: 1;
45
+ }
46
+ `
47
+
48
+ export default function Fill() {
49
+ const [rows, setRows] = useState<Lesson[]>(initialRows)
50
+ const [controller] = useState(createTableController)
51
+ function fillDown() {
52
+ controller.selectCells({ rowId: 'l1', columnId: 'week' }, { rowId: 'l5', columnId: 'room' })
53
+ void controller.fillCells('down', 2)
54
+ }
55
+ return (
56
+ <div className="demo-fill-fill">
57
+ <style>{styles}</style>
58
+ <div>
59
+ <Button onClick={() => fillDown()}>Fill down from two rows</Button>
60
+ </div>
61
+ <Table
62
+ rows={rows}
63
+ columns={columns}
64
+ aria-label="Lessons of a course"
65
+ sheet
66
+ controller={controller}
67
+ onCellEdit={(edits) => setRows((current) => applyEdits(current, edits))}
68
+ />
69
+ </div>
70
+ )
71
+ }
72
+ ```
73
+
74
+ Press Fill down from two rows: weeks 3, 4 and 5 and the days 2027-01-18, 01-25 and 02-01 follow, and the rooms repeat A1, B2. Or select a cell and drag the small square at its corner down.
75
+
76
+ ## The handle
77
+
78
+ The fill handle is the part `[data-slot='table-fill-handle']`: an empty `span` inside the cell at the end corner of the selected cells.
79
+
80
+ - Place it with `position: absolute` at `inset-block-end` and `inset-inline-end` of its cell, which needs `position: relative`. The logical sides put it at the left corner from right to left.
81
+ - Give it `touch-action: none`.
82
+ - Setting `fillHandle` to `'vertical'` or `'horizontal'` keeps the handle and the keys on one axis. Set it to `false` to disable both even with `sheet`.
83
+
84
+ ## A drag
85
+
86
+ - A drag fills along the rows or along the columns, whichever the pointer went further on.
87
+ - While it runs, the table has `data-filling`. Each cell that would be filled has `data-fill-target` and `data-fill-edge` (`top`, `right`, `bottom`, `left`), so a line around the target is the same CSS as the line around a range.
88
+ - Near an edge of the scroll frame the table scrolls, also with a row window.
89
+ - Escape ends the drag and changes nothing.
90
+
91
+ ## What it writes
92
+
93
+ - A source of one line repeats.
94
+ - A source of two or more lines goes on when it is numbers with one step (also negative, a fraction, upward and backward) or days with one step: `2028-02-22`, `2028-02-29` goes on with `2028-03-07`. Everything else repeats in its order.
95
+ - A fill along the rows passes values. A fill along the columns passes text through the `parse` of the next column.
96
+ - A cell that cannot be edited keeps its value and its place in the line.
97
+ - A fill from pinned rows into the rows of the list is refused: they are no neighbours in the data.
98
+
99
+ ## All or nothing, one step
100
+
101
+ Each value passes the schema of its column. One refusal stops the fill before any cell changes, and the table says which column refused which text. A fill is one report to the cell edit listener with the reason `fill`, and one step of the history. Its undo puts back the values of before, also for rows that were sorted, filtered or removed since.
102
+
103
+ ## From code
104
+
105
+ `controller.fillCells('down' | 'up' | 'forward' | 'back', source = 1)` fills the selected cells from their first `source` lines. It works without the `fillHandle` option, which is about the handle and the keys. It throws for one selected line, for a wrong direction (with the valid ones), and with the reason of a refusal.
106
+
107
+ ## Keys
108
+
109
+ | Key | With `fillHandle` |
110
+ | --- | --- |
111
+ | Control or Command with D | Fills the selected cells down from their first row |
112
+ | Control or Command with R | Fills the selected cells forward from their first column |
113
+ | Escape during a drag | Ends the drag and changes nothing |
114
+
115
+ With one line selected the keys stay the browser's: Control+R is its reload.
116
+
117
+ See the [Sheet tiles of the sink](https://ui-sdk-table.fdts.dev/?page=sink&only=sheet).
118
+
119
+ ## Names
120
+
121
+ - **Attributes:** `data-filling` on the table; `data-fill-target` and `data-fill-edge` on a cell; the part `table-fill-handle`.
122
+ - **Exports:** `fillValues`, `fillLine`, `TableFillHandle`, and the types `FillWay`, `FillDirection`, `FillDraft`.
123
+
124
+ For shared methods and result types, see [Controller](./reference-controller.md) and [View](./reference-view.md).
125
+
126
+ For props, callbacks and render functions, see the [React API reference](./api-react.md).