ui-sdk-table-web 0.0.0-stage → 0.2.10

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -2
  3. package/dist/table-licenses.md +411 -0
  4. package/dist/table-reference-licenses.md +411 -0
  5. package/dist/table-reference.js +11119 -0
  6. package/dist/table.js +10635 -0
  7. package/docs/api-web-components.md +319 -0
  8. package/docs/cell-editing.md +234 -0
  9. package/docs/cells-and-slots.md +106 -0
  10. package/docs/component-body.md +42 -0
  11. package/docs/component-cell.md +31 -0
  12. package/docs/component-col.md +31 -0
  13. package/docs/component-edit-error.md +31 -0
  14. package/docs/component-editor.md +31 -0
  15. package/docs/component-fill-handle.md +31 -0
  16. package/docs/component-foot.md +33 -0
  17. package/docs/component-head.md +33 -0
  18. package/docs/component-header-cell.md +31 -0
  19. package/docs/component-header-row.md +33 -0
  20. package/docs/component-plain-row.md +33 -0
  21. package/docs/component-resizer.md +33 -0
  22. package/docs/component-root.md +40 -0
  23. package/docs/component-row.md +33 -0
  24. package/docs/component-spacer.md +31 -0
  25. package/docs/controller-and-view.md +108 -0
  26. package/docs/examples-agents.md +62 -0
  27. package/docs/examples-column-definitions.md +172 -0
  28. package/docs/examples-formula-writer.md +262 -0
  29. package/docs/examples-styling.md +180 -0
  30. package/docs/examples.md +125 -0
  31. package/docs/excel-formulas.md +119 -0
  32. package/docs/export.md +107 -0
  33. package/docs/fill.md +111 -0
  34. package/docs/first-table.md +111 -0
  35. package/docs/formats.md +158 -0
  36. package/docs/groups-and-totals.md +117 -0
  37. package/docs/history.md +126 -0
  38. package/docs/installation.md +52 -0
  39. package/docs/llms.txt +13 -0
  40. package/docs/pages-and-server-mode.md +219 -0
  41. package/docs/range-copy-and-paste.md +108 -0
  42. package/docs/reference-columns.md +179 -0
  43. package/docs/reference-controller.md +137 -0
  44. package/docs/reference-export.md +59 -0
  45. package/docs/reference-formulas.md +42 -0
  46. package/docs/reference-implementation.md +29 -0
  47. package/docs/reference-messages.md +55 -0
  48. package/docs/reference-view.md +116 -0
  49. package/docs/row-numbers-and-letters.md +109 -0
  50. package/docs/rows.md +310 -0
  51. package/docs/selection-and-keyboard.md +134 -0
  52. package/docs/sheet-formulas.md +322 -0
  53. package/docs/sheet-options.md +192 -0
  54. package/docs/skills.md +41 -0
  55. package/docs/sort-filter-and-search.md +268 -0
  56. package/docs/state-and-events.md +86 -0
  57. package/docs/styled-table.md +229 -0
  58. package/docs/table-components.md +100 -0
  59. package/docs/web-components.md +113 -0
  60. package/docs/webmcp.md +97 -0
  61. package/package.json +49 -3
  62. package/src/browser.ts +3 -0
  63. package/src/index.ts +77 -0
  64. package/src/reference-browser.ts +3 -0
  65. package/src/reference-dom.ts +206 -0
  66. package/src/reference.ts +63 -0
@@ -0,0 +1,180 @@
1
+ # Web Components: Styling
2
+
3
+ [All examples and setup](./examples.md)
4
+
5
+ ## sticky
6
+
7
+ ```ts title="sticky.ts"
8
+ import '@ui-sdk/web/toggle'
9
+ import type { ColumnDef } from 'ui-sdk-table-core'
10
+ import { defineReferenceTable, type ReferenceTableElement } from 'ui-sdk-table-web/reference'
11
+
12
+ const stations = [
13
+ { station: 'Bergen', low: 3, high: 8, rain: 12, wind: 34 },
14
+ { station: 'Cork', low: 6, high: 12, rain: 4, wind: 28 },
15
+ { station: 'Porto', low: 11, high: 18, rain: 0, wind: 16 },
16
+ { station: 'Gdańsk', low: 2, high: 7, rain: 1, wind: 22 },
17
+ { station: 'Tromsø', low: -4, high: 1, rain: 2, wind: 31 },
18
+ { station: 'Nantes', low: 7, high: 14, rain: 3, wind: 19 },
19
+ ]
20
+ const readings = [0, 1, 2].flatMap((day) =>
21
+ stations.map(({ station, low, high, rain, wind }, i) => ({
22
+ id: `r${day * stations.length + i}`,
23
+ station,
24
+ day: `${10 + day} Nov`,
25
+ low: low - day,
26
+ high: high + day,
27
+ rain: Math.max(0, rain - day),
28
+ wind: wind + day * 2,
29
+ })),
30
+ )
31
+ type Reading = (typeof readings)[number]
32
+ const columns: ColumnDef<Reading>[] = [
33
+ { id: 'station', header: 'Station', aggregate: () => 'Extremes' },
34
+ { id: 'low', header: 'Low °C', format: 'integer', aggregate: 'min' },
35
+ { id: 'high', header: 'High °C', format: 'integer', aggregate: 'max' },
36
+ { id: 'rain', header: 'Rain mm', format: 'integer', aggregate: 'max' },
37
+ { id: 'wind', header: 'Gust km/h', format: 'integer', aggregate: 'max' },
38
+ { id: 'day', header: 'Date' },
39
+ ]
40
+
41
+ const styles = `
42
+ .weather-log {
43
+ --paper: light-dark(#fff, #191d1c);
44
+ --ink: light-dark(#18382f, #e2eee8);
45
+ --secondary: light-dark(#52665e, #b0bfb7);
46
+ --rule: light-dark(#dce4de, #36443c);
47
+ --band: light-dark(#edf3ef, #25332c);
48
+ inline-size: 100%;
49
+ min-inline-size: 0;
50
+ color: var(--ink);
51
+ font: 14px/1.4 system-ui, sans-serif;
52
+ }
53
+ .weather-log header { margin-block-end: 18px; }
54
+ .weather-log h2 {
55
+ margin: 0;
56
+ font: 500 clamp(25px, 3vw, 32px)/1.15 Georgia, serif;
57
+ letter-spacing: -0.03em;
58
+ color: var(--ink);
59
+ }
60
+ .weather-log p, .weather-log .log-tools {
61
+ margin: 6px 0 0;
62
+ font-size: 13px;
63
+ color: var(--secondary);
64
+ }
65
+ .weather-log .frame {
66
+ max-block-size: 23rem;
67
+ overflow: auto;
68
+ scrollbar-width: thin;
69
+ background: var(--paper);
70
+ }
71
+ .weather-log [data-slot='table'] {
72
+ display: table;
73
+ inline-size: 100%;
74
+ min-inline-size: 29rem;
75
+ border-collapse: separate;
76
+ border-spacing: 0;
77
+ font: inherit;
78
+ font-variant-numeric: tabular-nums;
79
+ }
80
+ .weather-log [data-wide] [data-slot='table'] { min-inline-size: max(48rem, 130%); table-layout: fixed; }
81
+ .weather-log [data-wide] col[data-column='station'] { width: 7rem; }
82
+ .weather-log :is(td, th) {
83
+ box-sizing: border-box;
84
+ block-size: 46px;
85
+ padding: 0 10px;
86
+ white-space: nowrap;
87
+ text-align: start;
88
+ border: 0;
89
+ border-block-end: 1px solid var(--rule);
90
+ background: var(--paper);
91
+ color: var(--ink);
92
+ }
93
+ .weather-log [data-format='integer'] { text-align: end; }
94
+ .weather-log tbody [data-column='station'] { font-weight: 650; }
95
+ .weather-log tbody [data-column='low'] { color: light-dark(#30617a, #a3cada); }
96
+ .weather-log tbody [data-column='high'] { color: light-dark(#92522f, #e6b18e); }
97
+ .weather-log tbody [data-column='day'] { color: var(--secondary); }
98
+ .weather-log [data-pinned='start'] {
99
+ position: sticky;
100
+ inset-inline-start: var(--table-pin-offset, 0px);
101
+ z-index: 1;
102
+ }
103
+ .weather-log tr[data-sticky] > * {
104
+ position: sticky;
105
+ z-index: 2;
106
+ background: var(--band);
107
+ font-weight: 600;
108
+ }
109
+ .weather-log tr[data-sticky='top'] > * {
110
+ inset-block-start: var(--table-sticky-offset, 0px);
111
+ block-size: 38px;
112
+ font-size: 12px;
113
+ }
114
+ .weather-log tr[data-sticky='bottom'] > * {
115
+ inset-block-end: var(--table-sticky-offset, 0px);
116
+ border-block: 1px solid var(--rule);
117
+ }
118
+ .weather-log tr[data-sticky] > [data-pinned] { z-index: 3; }
119
+ .weather-log :focus-visible { outline: 2px solid currentColor; outline-offset: -2px; }
120
+ .weather-log .log-tools {
121
+ display: flex;
122
+ align-items: center;
123
+ justify-content: space-between;
124
+ gap: 8px;
125
+ flex-wrap: wrap;
126
+ margin-block-start: 12px;
127
+ }
128
+ .weather-log .log-tools button {
129
+ padding: 5px 10px;
130
+ border: 1px solid var(--secondary);
131
+ border-radius: 5px;
132
+ background: transparent;
133
+ color: var(--ink);
134
+ font: inherit;
135
+ cursor: pointer;
136
+ }
137
+ .weather-log .log-tools button[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
138
+ `
139
+
140
+ export default function mount(host: HTMLElement) {
141
+ defineReferenceTable()
142
+ const style = document.createElement('style')
143
+ style.textContent = styles
144
+ const log = document.createElement('section')
145
+ log.className = 'weather-log'
146
+ const header = document.createElement('header')
147
+ const title = document.createElement('h2')
148
+ title.textContent = 'Coastal weather log'
149
+ const description = document.createElement('p')
150
+ description.textContent = 'Sample observations · 10–12 November 2026'
151
+ header.append(title, description)
152
+
153
+ const frame = document.createElement('div')
154
+ frame.className = 'frame weather-readings'
155
+ const table = document.createElement('ui-reference-table') as ReferenceTableElement<Reading>
156
+ table.setAttribute('aria-label', 'Weather readings')
157
+ table.rows = readings
158
+ table.columns = columns
159
+ table.defaultColumnPinning = { start: ['station'] }
160
+ table.stickyHeader = true
161
+ table.stickyFooter = true
162
+ frame.append(table)
163
+
164
+ const tools = document.createElement('div')
165
+ tools.className = 'log-tools'
166
+ const count = document.createElement('span')
167
+ count.textContent = `${readings.length} readings · ${stations.length} stations`
168
+ const toggle = document.createElement('ui-toggle')
169
+ const button = document.createElement('button')
170
+ button.type = 'button'
171
+ button.textContent = 'Wide columns'
172
+ toggle.append(button)
173
+ toggle.addEventListener('pressedchange', ({ detail }) =>
174
+ frame.toggleAttribute('data-wide', detail.value),
175
+ )
176
+ tools.append(count, toggle)
177
+ log.append(header, frame, tools)
178
+ host.append(style, log)
179
+ }
180
+ ```
@@ -0,0 +1,125 @@
1
+ # Web Components examples
2
+
3
+ Start with the [Web Components parts](./web-components.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
+ Use a TypeScript bundler for these modules. Save the [first table](./first-table.md) as `people.ts`. Put an element with `id="people"` on the page, then call the module’s default export with that element:
6
+
7
+ ```ts
8
+ import mount from './people'
9
+
10
+ const host = document.getElementById('people')
11
+ if (host) mount(host)
12
+ ```
13
+
14
+ If an example returns a cleanup function, call it before you remove the host. For a standalone HTML page without npm imports, follow the [Web Components guide](./web-components.md).
15
+
16
+ ## First table
17
+
18
+ - [first-table/people](./first-table.md)
19
+ - [first-table/styled](./first-table.md)
20
+
21
+ ## Table components
22
+
23
+ - [table-components/parts](./table-components.md)
24
+
25
+ ## Selection and keyboard
26
+
27
+ - [selection-and-keyboard/select](./selection-and-keyboard.md)
28
+
29
+ ## Editing
30
+
31
+ - [cell-editing/prices](./cell-editing.md)
32
+ - [cell-editing/entry](./cell-editing.md)
33
+
34
+ ## Range, copy and paste
35
+
36
+ - [range-copy-and-paste/range](./range-copy-and-paste.md)
37
+
38
+ ## Fill
39
+
40
+ - [fill/fill](./fill.md)
41
+
42
+ ## History
43
+
44
+ - [history/undo](./history.md)
45
+
46
+ ## Column definitions
47
+
48
+ - [column-definitions/formats](./examples-column-definitions.md#formats)
49
+ - [column-definitions/layout](./examples-column-definitions.md#layout)
50
+
51
+ ## Cells and slots
52
+
53
+ - [cells-and-slots/slots](./cells-and-slots.md)
54
+
55
+ ## A styled table for an app
56
+
57
+ - [styled-table/toolbar](./styled-table.md)
58
+
59
+ ## Styling
60
+
61
+ - [styling/sticky](./examples-styling.md#sticky)
62
+
63
+ ## State and events
64
+
65
+ - [state-and-events/controlled](./state-and-events.md)
66
+
67
+ ## Controller and view
68
+
69
+ - [controller-and-view/outside](./controller-and-view.md)
70
+
71
+ ## Sort, filter and search
72
+
73
+ - [sort-filter-and-search/sort](./sort-filter-and-search.md)
74
+ - [sort-filter-and-search/search](./sort-filter-and-search.md)
75
+ - [sort-filter-and-search/facets](./sort-filter-and-search.md)
76
+
77
+ ## Groups and totals
78
+
79
+ - [groups-and-totals/groups](./groups-and-totals.md)
80
+
81
+ ## Pages and server mode
82
+
83
+ - [pages-and-server-mode/pages](./pages-and-server-mode.md)
84
+ - [pages-and-server-mode/server](./pages-and-server-mode.md)
85
+
86
+ ## Rows
87
+
88
+ - [rows/tree](./rows.md)
89
+ - [rows/detail](./rows.md)
90
+ - [rows/pinned](./rows.md)
91
+ - [rows/window](./rows.md)
92
+
93
+ ## Export
94
+
95
+ - [export/files](./export.md)
96
+
97
+ ## The sheet options
98
+
99
+ - [sheet-options/sheet](./sheet-options.md)
100
+ - [sheet-options/totals](./sheet-options.md)
101
+
102
+ ## Formats
103
+
104
+ - [formats/formats](./formats.md)
105
+
106
+ ## Row numbers and letters
107
+
108
+ - [row-numbers-and-letters/letters](./row-numbers-and-letters.md)
109
+
110
+ ## Formulas
111
+
112
+ - [sheet-formulas/column](./sheet-formulas.md)
113
+ - [sheet-formulas/cells](./sheet-formulas.md)
114
+
115
+ ## A formula writer
116
+
117
+ - [formula-writer/writer](./examples-formula-writer.md#writer)
118
+
119
+ ## An Excel file with formulas
120
+
121
+ - [excel-formulas/file](./excel-formulas.md)
122
+
123
+ ## Agents
124
+
125
+ - [agents/agent](./examples-agents.md#agent)
@@ -0,0 +1,119 @@
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
+ ```ts title="file.ts"
8
+ import { type ColumnDef, applyEdits, rowNumberColumn, type CellFormulas } from 'ui-sdk-table-core'
9
+ import { createFormulaEngine, excelFormulas } from 'ui-sdk-table-core/formulas'
10
+ import { defineReferenceTable, type ReferenceTableElement } from 'ui-sdk-table-web/reference'
11
+
12
+ type Month = { id: string; month: string; income: number; costs: number; profit?: unknown }
13
+
14
+ const rows: Month[] = [
15
+ { id: 'm1', month: 'January', income: 8200, costs: 5100, profit: 3100 },
16
+ { id: 'm2', month: 'February', income: 7600, costs: 5400, profit: 2200 },
17
+ { id: 'm3', month: 'March', income: 9100, costs: 5050, profit: 4050 },
18
+ ]
19
+
20
+ const columns: ColumnDef<Month>[] = [
21
+ rowNumberColumn<Month>(),
22
+ { id: 'month', header: 'Month', editable: false },
23
+ { id: 'income', header: 'Income', format: 'integer' },
24
+ { id: 'costs', header: 'Costs', format: 'integer' },
25
+ { id: 'profit', header: 'Profit', format: 'integer' },
26
+ ]
27
+
28
+ const formulas: CellFormulas = {
29
+ cells: {
30
+ m1: { profit: '=[income]-[costs]' },
31
+ m2: { profit: '=[income]-[costs]' },
32
+ m3: { profit: '=[income]-[costs]' },
33
+ },
34
+ }
35
+
36
+ function button(label: string, action: () => void) {
37
+ const el = document.createElement('button')
38
+ el.type = 'button'
39
+ el.textContent = label
40
+ el.addEventListener('click', action)
41
+ return el
42
+ }
43
+
44
+ export default function mount(host: HTMLElement) {
45
+ defineReferenceTable()
46
+ const table = document.createElement('ui-reference-table') as ReferenceTableElement<Month>
47
+ table.setAttribute('aria-label', 'Profit by month')
48
+ table.rows = rows
49
+ table.columns = columns
50
+ table.sheet = true
51
+ table.columnLetters = true
52
+ table.locale = 'en-US'
53
+ table.addEventListener('celledit', ({ detail }) => {
54
+ table.rows = applyEdits(table.rows ?? [], detail.value)
55
+ })
56
+ table.formulas = createFormulaEngine()
57
+ table.cellFormulas = formulas
58
+ table.addEventListener('cellformulaschange', ({ detail }) => {
59
+ table.cellFormulas = detail.value
60
+ })
61
+
62
+ host.append(table)
63
+ async function download() {
64
+ const api = table.api
65
+ if (!api) return
66
+ const { downloadXlsx } = await import('ui-sdk-table-core/export')
67
+ await downloadXlsx(api.exportData(), 'profit', { formula: excelFormulas() })
68
+ }
69
+ host.prepend(
70
+ button('Download Excel', () => {
71
+ void download()
72
+ }),
73
+ )
74
+ }
75
+ ```
76
+
77
+ 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.
78
+
79
+ ## Turn it on
80
+
81
+ Load the writer when the person asks for the file, and pass it `excelFormulas()`:
82
+
83
+ ```ts
84
+ await downloadXlsx(controller.exportData(), 'profit', { formula: excelFormulas() })
85
+ ```
86
+
87
+ - `excelFormulas()` of the formulas entry is the `formula` option of `toXlsx` and `downloadXlsx`.
88
+ - 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).
89
+ - The addresses are places in the file. A sorted or filtered export keeps the formulas that read their own row.
90
+ - An error of a formula is an error cell of the file. `#CYCLE!` stays a text.
91
+ - A CSV holds the results.
92
+ - `ExportCell.formula`, `ExportRow.id` and `ExportData.document` carry the formulas to a writer of your own.
93
+
94
+ ## Dates of the `period` format
95
+
96
+ 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.
97
+
98
+ ## When a formula goes into the file
99
+
100
+ A cell gets the formula of the file only when the whole formula means the same in Excel:
101
+
102
+ - 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;
103
+ - a range is one column whose rows are in the file in the order of the document and next to each other;
104
+ - each function is in `EXCEL_FUNCTIONS`.
105
+
106
+ 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.
107
+
108
+ 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.
109
+
110
+ See the [Formula tiles of the sink](https://ui-sdk-table.fdts.dev/?page=sink&only=formula) and the page [Export](./export.md).
111
+
112
+ ## Names
113
+
114
+ - `ui-sdk-table-core/formulas` exports `excelFormulas` and `EXCEL_FUNCTIONS`.
115
+ - `ui-sdk-table-core/export` exports `downloadXlsx`, `toXlsx` and the type `XlsxFormulas`.
116
+
117
+ For shared methods and result types, see [Controller](./reference-controller.md) and [View](./reference-view.md).
118
+
119
+ For custom elements, properties and DOM events, see the [Web Components API reference](./api-web-components.md).
package/docs/export.md ADDED
@@ -0,0 +1,107 @@
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
+ ```ts title="files.ts"
8
+ import { type ColumnDef } from 'ui-sdk-table-core'
9
+
10
+ import { defineReferenceTable, type ReferenceTableElement } from 'ui-sdk-table-web/reference'
11
+
12
+ type Order = { id: string; customer: string; city: string; total: number }
13
+
14
+ const orders: Order[] = [
15
+ { id: 'o1', customer: 'Northway', city: 'Oslo', total: 1240 },
16
+ { id: 'o2', customer: 'Sola', city: 'Seville', total: 860.5 },
17
+ { id: 'o3', customer: 'Arc', city: 'Lyon', total: 2310 },
18
+ ]
19
+
20
+ const columns: ColumnDef<Order>[] = [
21
+ { id: 'customer', header: 'Customer', sortable: true },
22
+ { id: 'city', header: 'City' },
23
+ { id: 'total', header: 'Total', format: 'decimal', aggregate: 'sum' },
24
+ // The id is for the screen only.
25
+ { id: 'id', header: 'Id', exportable: false },
26
+ ]
27
+
28
+ function button(label: string, action: () => void) {
29
+ const el = document.createElement('button')
30
+ el.type = 'button'
31
+ el.textContent = label
32
+ el.addEventListener('click', action)
33
+ return el
34
+ }
35
+
36
+ export default function mount(host: HTMLElement) {
37
+ defineReferenceTable()
38
+ const table = document.createElement('ui-reference-table') as ReferenceTableElement<Order>
39
+ table.setAttribute('aria-label', 'Orders to export')
40
+ table.rows = orders
41
+ table.columns = columns
42
+ table.locale = 'en-US'
43
+
44
+ host.append(table)
45
+ const csv = document.createElement('pre')
46
+ csv.dataset.testid = 'csv'
47
+ csv.hidden = true
48
+ host.append(csv)
49
+ async function preview() {
50
+ const api = table.api
51
+ if (!api) return
52
+ const { toCsv } = await import('ui-sdk-table-core/export')
53
+ csv.textContent = toCsv(api.exportData({ totals: true }))
54
+ csv.hidden = false
55
+ }
56
+ async function download() {
57
+ const api = table.api
58
+ if (!api) return
59
+ const { downloadXlsx } = await import('ui-sdk-table-core/export')
60
+ await downloadXlsx(api.exportData(), 'orders')
61
+ }
62
+ host.prepend(
63
+ button('Show the CSV', () => {
64
+ void preview()
65
+ }),
66
+ button('Download Excel', () => {
67
+ void download()
68
+ }),
69
+ )
70
+ }
71
+ ```
72
+
73
+ 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.
74
+
75
+ ## What goes in
76
+
77
+ `exportData(options)` takes:
78
+
79
+ - `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'`.
80
+ - `columns`: `'visible'` (the default, in their order), `'all'` (the hidden columns after them) or a list of ids.
81
+ - `children`: whether the child rows of a tree come with it, open or not. Defaults to true.
82
+ - `groups`: whether each group gets a row of its own before its rows. Defaults to false.
83
+ - `totals`: whether a last row holds the totals. Defaults to false.
84
+
85
+ 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.
86
+
87
+ ## The text of a cell
88
+
89
+ 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.
90
+
91
+ ## The writers
92
+
93
+ - `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).
94
+ - `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).
95
+ - `downloadCsv(data, filename, options)` and `downloadXlsx(data, filename, options)` save a file in the browser.
96
+
97
+ With `manualPage`, the table has one page of a server, so each set of rows is of that page.
98
+
99
+ ## Names
100
+
101
+ - **Export entry:** `toCsv`, `toXlsx`, `downloadCsv`, `downloadXlsx`, `downloadFile`, `zip`, `XLSX_TYPE`, and the type `XlsxFormulas`.
102
+
103
+ For shared methods and result types, see [Controller](./reference-controller.md) and [View](./reference-view.md).
104
+
105
+ For custom elements, properties and DOM events, see the [Web Components API reference](./api-web-components.md).
106
+
107
+ 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,111 @@
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
+ ```ts title="fill.ts"
8
+ import { type ColumnDef, applyEdits } from 'ui-sdk-table-core'
9
+
10
+ import { defineReferenceTable, type ReferenceTableElement } from 'ui-sdk-table-web/reference'
11
+
12
+ type Lesson = { id: string; week: number | null; day: string; room: string }
13
+
14
+ const columns: ColumnDef<Lesson>[] = [
15
+ { id: 'week', header: 'Week', format: 'integer' },
16
+ { id: 'day', header: 'Day' },
17
+ { id: 'room', header: 'Room' },
18
+ ]
19
+
20
+ const rows: Lesson[] = [
21
+ { id: 'l1', week: 1, day: '2027-01-04', room: 'A1' },
22
+ { id: 'l2', week: 2, day: '2027-01-11', room: 'B2' },
23
+ { id: 'l3', week: null, day: '', room: '' },
24
+ { id: 'l4', week: null, day: '', room: '' },
25
+ { id: 'l5', week: null, day: '', room: '' },
26
+ ]
27
+
28
+ function button(label: string, action: () => void) {
29
+ const el = document.createElement('button')
30
+ el.type = 'button'
31
+ el.textContent = label
32
+ el.addEventListener('click', action)
33
+ return el
34
+ }
35
+
36
+ export default function mount(host: HTMLElement) {
37
+ defineReferenceTable()
38
+ const table = document.createElement('ui-reference-table') as ReferenceTableElement<Lesson>
39
+ table.setAttribute('aria-label', 'Lessons of a course')
40
+ table.rows = rows
41
+ table.columns = columns
42
+ table.sheet = true
43
+ table.addEventListener('celledit', ({ detail }) => {
44
+ table.rows = applyEdits(table.rows ?? [], detail.value)
45
+ })
46
+
47
+ host.append(table)
48
+ host.prepend(
49
+ button('Fill down from two rows', () => {
50
+ const api = table.api
51
+ if (!api) return
52
+ api.selectCells({ rowId: 'l1', columnId: 'week' }, { rowId: 'l5', columnId: 'room' })
53
+ void api.fillCells('down', 2)
54
+ }),
55
+ )
56
+ }
57
+ ```
58
+
59
+ 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.
60
+
61
+ ## The handle
62
+
63
+ 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.
64
+
65
+ - 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.
66
+ - Give it `touch-action: none`.
67
+ - 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`.
68
+
69
+ ## A drag
70
+
71
+ - A drag fills along the rows or along the columns, whichever the pointer went further on.
72
+ - 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.
73
+ - Near an edge of the scroll frame the table scrolls, also with a row window.
74
+ - Escape ends the drag and changes nothing.
75
+
76
+ ## What it writes
77
+
78
+ - A source of one line repeats.
79
+ - 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.
80
+ - A fill along the rows passes values. A fill along the columns passes text through the `parse` of the next column.
81
+ - A cell that cannot be edited keeps its value and its place in the line.
82
+ - A fill from pinned rows into the rows of the list is refused: they are no neighbours in the data.
83
+
84
+ ## All or nothing, one step
85
+
86
+ 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.
87
+
88
+ ## From code
89
+
90
+ `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.
91
+
92
+ ## Keys
93
+
94
+ | Key | With `fillHandle` |
95
+ | --- | --- |
96
+ | Control or Command with D | Fills the selected cells down from their first row |
97
+ | Control or Command with R | Fills the selected cells forward from their first column |
98
+ | Escape during a drag | Ends the drag and changes nothing |
99
+
100
+ With one line selected the keys stay the browser's: Control+R is its reload.
101
+
102
+ See the [Sheet tiles of the sink](https://ui-sdk-table.fdts.dev/?page=sink&only=sheet).
103
+
104
+ ## Names
105
+
106
+ - **Attributes:** `data-filling` on the table; `data-fill-target` and `data-fill-edge` on a cell; the part `table-fill-handle`.
107
+ - **Exports:** `fillValues`, `fillLine`, `TableFillHandle`, and the types `FillWay`, `FillDirection`, `FillDraft`.
108
+
109
+ For shared methods and result types, see [Controller](./reference-controller.md) and [View](./reference-view.md).
110
+
111
+ For custom elements, properties and DOM events, see the [Web Components API reference](./api-web-components.md).