foldkit-data-grid 0.3.1 → 0.4.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 (60) hide show
  1. package/dist/clipboard.d.ts +44 -0
  2. package/dist/clipboard.d.ts.map +1 -0
  3. package/dist/clipboard.js +109 -0
  4. package/dist/clipboard.js.map +1 -0
  5. package/dist/columnState.d.ts +53 -0
  6. package/dist/columnState.d.ts.map +1 -0
  7. package/dist/columnState.js +201 -0
  8. package/dist/columnState.js.map +1 -0
  9. package/dist/{rows-D8siEVqF.d.mts → columns.d.ts} +15 -81
  10. package/dist/columns.d.ts.map +1 -0
  11. package/dist/columns.js +73 -0
  12. package/dist/columns.js.map +1 -0
  13. package/dist/{crud.d.mts → crud.d.ts} +3 -2
  14. package/dist/{crud.d.mts.map → crud.d.ts.map} +1 -1
  15. package/dist/{crud.mjs → crud.js} +3 -2
  16. package/dist/crud.js.map +1 -0
  17. package/dist/fill.d.ts +49 -0
  18. package/dist/fill.d.ts.map +1 -0
  19. package/dist/fill.js +113 -0
  20. package/dist/fill.js.map +1 -0
  21. package/dist/focus.d.ts +119 -0
  22. package/dist/focus.d.ts.map +1 -0
  23. package/dist/focus.js +150 -0
  24. package/dist/focus.js.map +1 -0
  25. package/dist/{index.d.mts → grid.d.ts} +13 -564
  26. package/dist/grid.d.ts.map +1 -0
  27. package/dist/{index.mjs → grid.js} +11 -1024
  28. package/dist/grid.js.map +1 -0
  29. package/dist/index.d.ts +13 -0
  30. package/dist/index.js +13 -0
  31. package/dist/layout.d.ts +20 -0
  32. package/dist/layout.d.ts.map +1 -0
  33. package/dist/layout.js +27 -0
  34. package/dist/layout.js.map +1 -0
  35. package/dist/projection.d.ts +87 -0
  36. package/dist/projection.d.ts.map +1 -0
  37. package/dist/projection.js +102 -0
  38. package/dist/projection.js.map +1 -0
  39. package/dist/rows.d.ts +70 -0
  40. package/dist/rows.d.ts.map +1 -0
  41. package/dist/{rows-Dy1HPpGX.mjs → rows.js} +3 -71
  42. package/dist/rows.js.map +1 -0
  43. package/dist/selection.d.ts +65 -0
  44. package/dist/selection.d.ts.map +1 -0
  45. package/dist/selection.js +137 -0
  46. package/dist/selection.js.map +1 -0
  47. package/dist/viewport.d.ts +74 -0
  48. package/dist/viewport.d.ts.map +1 -0
  49. package/dist/viewport.js +116 -0
  50. package/dist/viewport.js.map +1 -0
  51. package/dist/virtual.d.ts +73 -0
  52. package/dist/virtual.d.ts.map +1 -0
  53. package/dist/virtual.js +112 -0
  54. package/dist/virtual.js.map +1 -0
  55. package/package.json +15 -15
  56. package/dist/crud.mjs.map +0 -1
  57. package/dist/index.d.mts.map +0 -1
  58. package/dist/index.mjs.map +0 -1
  59. package/dist/rows-D8siEVqF.d.mts.map +0 -1
  60. package/dist/rows-Dy1HPpGX.mjs.map +0 -1
@@ -1,311 +1,10 @@
1
- import { a as CellEditor, c as ColumnId, d as EditValue, f as EditableId, i as addressableRows, l as ColumnSpec, n as RowModel, o as Column, r as RowStatus, s as ColumnEdit, t as RowCount, u as Columns } from "./rows-D8siEVqF.mjs";
2
1
  import { Option, Schema } from "effect";
2
+ import { CellEditor, ColumnSpec, Columns, EditValue, EditableId } from "./columns.js";
3
+ import { RowModel } from "./rows.js";
3
4
  import { Bundle } from "foldkit-bundle";
4
- import * as Mount from "foldkit/mount";
5
- import { KeyboardModifiers } from "foldkit/html";
6
- import { Command } from "foldkit/command";
7
- /**
8
- * Where each column stands: the start, center and end regions in display
9
- * order, and which columns are hidden. Hiding keeps a column's place, so
10
- * showing it again puts it back where it was. The grid owns this state; it
11
- * holds column ids only, so it can be saved and restored.
12
- */
13
- export interface ColumnLayout<Id extends string> {
14
- /** Pinned to the start edge, outside horizontal scrolling. */
15
- readonly start: ReadonlyArray<Id>;
16
- readonly center: ReadonlyArray<Id>;
17
- /** Pinned to the end edge, outside horizontal scrolling. */
18
- readonly end: ReadonlyArray<Id>;
19
- readonly hidden: ReadonlyArray<Id>;
20
- }
21
- export declare const ColumnLayout: {
22
- /** The layout the columns declare: definition order, each in its `pinned` region. */
23
- initial: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(columns: Columns<Row, Specs>) => ColumnLayout<keyof Specs & string>;
24
- };
25
- /** A cell named by identity, so it stays the same cell through a sort or a reorder. */
26
- export interface CellAddress<Id extends string> {
27
- readonly row: string;
28
- readonly column: Id;
29
- }
30
- export declare const CellAddress: {
31
- /**
32
- * An address as stored or sent: the row key as text, and the column as one
33
- * of these columns' ids, so a saved address naming a removed column fails
34
- * to decode instead of naming nothing.
35
- */
36
- schema: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(columns: Columns<Row, Specs>) => Schema.Struct<{
37
- readonly row: Schema.String;
38
- readonly column: Schema.Literals<readonly (keyof Specs & string)[]>;
39
- }>;
40
- };
41
- /** Where a cell is drawn now: its row index, and its column's index in display order. */
42
- interface CellPosition {
43
- readonly row: number;
44
- readonly column: number;
45
- }
46
- /** A rectangle of cells: row indexes `[start, end)` and the columns it spans, in display order. */
47
- interface CellBox<Id extends string> {
48
- readonly rows: {
49
- readonly start: number;
50
- readonly end: number;
51
- };
52
- readonly columns: ReadonlyArray<Id>;
53
- }
54
- interface CellOffset {
55
- readonly rows?: number;
56
- readonly columns?: number;
57
- }
58
- /**
59
- * The grid as presented: rows in the application's order, crossed with the
60
- * visible columns in display order. It is the one source of geometry for
61
- * focus, selection, virtualization and the clipboard; none of them reads
62
- * positions from the DOM. A pure value, cheap to rebuild: it reads the
63
- * column layout once and asks the row model for rows only on lookup.
64
- *
65
- * Every lookup is an `Option`. A cell is absent when its column is hidden,
66
- * its row is gone, or its row is in range but not loaded yet.
67
- */
68
- export interface GridProjection<Row, Id extends string> {
69
- readonly rows: RowModel<Row>;
70
- readonly rowCount: RowCount;
71
- /** Visible columns in display order: the start region, the center, the end. */
72
- readonly columns: ReadonlyArray<Id>;
73
- /** The visible columns of each region, in display order. */
74
- readonly start: ReadonlyArray<Id>;
75
- readonly center: ReadonlyArray<Id>;
76
- readonly end: ReadonlyArray<Id>;
77
- columnIndex(id: Id): Option.Option<number>;
78
- rowIndex(key: string): Option.Option<number>;
79
- cellAt(position: CellPosition): Option.Option<CellAddress<Id>>;
80
- positionOf(address: CellAddress<Id>): Option.Option<CellPosition>;
81
- /**
82
- * The cell `offset` away, stopping at the grid's edges. A fractional offset
83
- * (a page of rows worked out from a height) drops its fraction.
84
- */
85
- moveBy(address: CellAddress<Id>, offset: CellOffset): Option.Option<CellAddress<Id>>;
86
- rowStart(address: CellAddress<Id>): Option.Option<CellAddress<Id>>;
87
- rowEnd(address: CellAddress<Id>): Option.Option<CellAddress<Id>>;
88
- first(): Option.Option<CellAddress<Id>>;
89
- last(): Option.Option<CellAddress<Id>>;
90
- /** The rectangle two cells span, in either order. */
91
- box(anchor: CellAddress<Id>, focus: CellAddress<Id>): Option.Option<CellBox<Id>>;
92
- }
93
- interface ProjectionOptions<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {
94
- readonly rows: RowModel<Row>;
95
- readonly columns: Columns<Row, Specs>;
96
- readonly layout: ColumnLayout<keyof Specs & string>;
97
- }
98
- export declare const GridProjection: {
99
- /**
100
- * Projects rows through a column layout. A layout saved before a column
101
- * was added does not mention it, so the column joins the center region in
102
- * definition order; an id the columns do not define, or one named twice,
103
- * keeps only its first place.
104
- */
105
- make: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(options: ProjectionOptions<Row, Specs>) => GridProjection<Row, keyof Specs & string>;
106
- };
107
- /** One cell's text in a paste, by identity: what the grid hands the application. */
108
- interface CellText<Id extends string> {
109
- readonly row: string;
110
- readonly column: Id;
111
- readonly text: string;
112
- }
113
- /** A pasted cell, with the text it showed before, so an unchanged one is no edit. */
114
- interface PastedCell<Id extends string> extends CellText<Id> {
115
- readonly from: string;
116
- }
117
- /** Rows of cells as tab-separated text, the form spreadsheets copy and paste. */
118
- declare const toTsv: (rows: ReadonlyArray<ReadonlyArray<string>>) => string;
119
- /**
120
- * Tab-separated text as rows of cells. Quoted cells may hold tabs, line
121
- * breaks and doubled quotes; `\r\n` and `\r` end a row as `\n` does; the line
122
- * break a spreadsheet adds after the last row makes no empty row.
123
- */
124
- declare const parseTsv: (text: string) => ReadonlyArray<ReadonlyArray<string>>;
125
- /**
126
- * The text of the cells a box covers, row by row in the projection's order
127
- * and column by column in display order. A row counted but not loaded copies
128
- * as empty cells, so the shape is the box's.
129
- */
130
- declare const copy: <Row, Id extends string>(projection: GridProjection<Row, Id>, box: CellBox<Id>, textOf: (address: CellAddress<Id>) => string) => string;
131
- /**
132
- * Where pasted cells land: the matrix laid from `anchor` across rows in the
133
- * projection's order and columns in display order. Cells past the grid's
134
- * edges are dropped, as are those landing on a column that does not edit or
135
- * a row not loaded; the rest keep their place, each with `from`, the text
136
- * the cell showed (the text an edit of it would begin from).
137
- */
138
- declare const pasteAt: <Row, Id extends string>(projection: GridProjection<Row, Id>, anchor: CellAddress<Id>, matrix: ReadonlyArray<ReadonlyArray<string>>, cells: {
139
- readonly editable: (column: Id) => boolean;
140
- readonly from: (address: CellAddress<Id>) => string;
141
- }) => ReadonlyArray<PastedCell<Id>>;
142
- export declare const Clipboard: {
143
- toTsv: typeof toTsv;
144
- parseTsv: typeof parseTsv;
145
- copy: typeof copy;
146
- pasteAt: typeof pasteAt;
147
- };
148
- /** A fill: the range whose cells are carried on, and the cell it was carried to. */
149
- interface FillRequest<Id extends string> {
150
- readonly source: {
151
- readonly anchor: CellAddress<Id>;
152
- readonly focus: CellAddress<Id>;
153
- };
154
- readonly to: CellAddress<Id>;
155
- }
156
- /**
157
- * Where a fill lands: the source's box, and the box it fills beyond it, down,
158
- * up, right or left, whichever way `to` lies further outside the source. A
159
- * fill carries on along one axis only, as spreadsheets do.
160
- */
161
- interface FillPlan<Id extends string> {
162
- readonly source: CellBox<Id>;
163
- readonly target: CellBox<Id>;
164
- /** Rows (`down`/`up`) or columns (`right`/`left`), away from the source. */
165
- readonly toward: 'down' | 'up' | 'right' | 'left';
166
- }
167
- /**
168
- * The texts that carry `source` on for `count` cells, the first of them next
169
- * to it. Two or more numbers a constant step apart continue their step, with
170
- * as many decimals as the most precise of them; anything else repeats, in
171
- * order. `backward` carries the source on before its first text, as filling
172
- * up or left does.
173
- */
174
- declare const series: (source: ReadonlyArray<string>, count: number, backward: boolean) => ReadonlyArray<string>;
175
- /** The source's box and the box beyond it toward `to`; none when `to` is inside it. */
176
- declare const plan: <Row, Id extends string>(projection: GridProjection<Row, Id>, request: FillRequest<Id>) => Option.Option<FillPlan<Id>>;
177
- /**
178
- * The cells a fill writes: each lane of the source (a column for a fill down
179
- * or up, a row for one right or left) carried on through the target by
180
- * `series`. Cells on a column that does not edit, or on a row not loaded, are
181
- * dropped; each kept cell has `from`, the text it showed.
182
- */
183
- declare const cells: <Row, Id extends string>(projection: GridProjection<Row, Id>, fill: FillPlan<Id>, options: {
184
- readonly editable: (column: Id) => boolean;
185
- readonly from: (address: CellAddress<Id>) => string;
186
- }) => ReadonlyArray<PastedCell<Id>>;
187
- export declare const Fill: {
188
- series: typeof series;
189
- plan: typeof plan;
190
- cells: typeof cells;
191
- };
192
- type Region = 'start' | 'center' | 'end';
193
- /**
194
- * Where each column stands and how wide the resized ones are. Widths list only
195
- * the columns resized; the rest take their spec's. The grid owns it, and it is
196
- * plain data, so an application can save it and restore it.
197
- */
198
- export interface ColumnState<Id extends string> extends ColumnLayout<Id> {
199
- readonly widths: ReadonlyArray<{
200
- readonly column: Id;
201
- readonly width: number;
202
- }>;
203
- }
204
- /** What `restore` made of a saved state: the state, and the ids it had to drop. */
205
- interface Restored<Id extends string> {
206
- readonly state: ColumnState<Id>;
207
- /** Ids the saved state named that these columns do not define, or named twice. */
208
- readonly dropped: ReadonlyArray<string>;
209
- }
210
- /**
211
- * Column state for one grid's columns: its Schema, which decodes only these
212
- * columns' ids, and the operations a grid's Messages run. Every operation
213
- * returns the state it was given when it changes nothing, so a no-op draws
214
- * nothing.
215
- */
216
- declare const make$2: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(columns: Columns<Row, Specs>) => {
217
- Model: Schema.Struct<{
218
- readonly start: Schema.$Array<Schema.Literals<readonly (keyof Specs & string)[]>>;
219
- readonly center: Schema.$Array<Schema.Literals<readonly (keyof Specs & string)[]>>;
220
- readonly end: Schema.$Array<Schema.Literals<readonly (keyof Specs & string)[]>>;
221
- readonly hidden: Schema.$Array<Schema.Literals<readonly (keyof Specs & string)[]>>;
222
- readonly widths: Schema.$Array<Schema.Struct<{
223
- readonly column: Schema.Literals<readonly (keyof Specs & string)[]>;
224
- readonly width: Schema.Number;
225
- }>>;
226
- }>;
227
- initial: () => ColumnState<keyof Specs & string>;
228
- widthOf: (state: ColumnState<keyof Specs & string>) => ((id: keyof Specs & string) => number);
229
- regionOf: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => Region;
230
- resize: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, width: number) => ColumnState<keyof Specs & string>;
231
- hide: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => ColumnState<keyof Specs & string>;
232
- show: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => ColumnState<keyof Specs & string>;
233
- move: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, region: Region, index: number) => ColumnState<keyof Specs & string>;
234
- dropAt: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, delta: number) => number;
235
- restore: (saved: unknown) => Restored<keyof Specs & string>;
236
- };
237
- export declare const ColumnState: {
238
- make: typeof make$2;
239
- };
240
- /** The scroll container's offsets and size, in pixels. */
241
- interface Viewport {
242
- readonly top: number;
243
- readonly left: number;
244
- readonly width: number;
245
- readonly height: number;
246
- }
247
- /** Rendered items `[start, end)` on one axis, with the space the rest take before and after. */
248
- interface AxisWindow {
249
- readonly start: number;
250
- readonly end: number;
251
- readonly before: number;
252
- readonly after: number;
253
- }
254
- interface GridWindow<Id extends string> {
255
- /** Row indexes to render; every row is `rowHeight` tall. */
256
- readonly rows: AxisWindow;
257
- /** Center columns to render, as indexes into `projection.center`. */
258
- readonly center: AxisWindow;
259
- /** The center columns in that window, in display order. */
260
- readonly centerColumns: ReadonlyArray<Id>;
261
- /** Pinned columns are always rendered: they never scroll horizontally. */
262
- readonly start: ReadonlyArray<Id>;
263
- readonly end: ReadonlyArray<Id>;
264
- /** The scrollable content's full size. */
265
- readonly width: number;
266
- readonly height: number;
267
- }
268
- interface Geometry<Row, Id extends string> {
269
- readonly projection: GridProjection<Row, Id>;
270
- readonly rowHeight: number;
271
- /** Width of each visible column. */
272
- readonly width: (column: NoInfer<Id>) => number;
273
- /** Height of the header rows inside the scroll container, above the body. */
274
- readonly headerHeight?: number;
275
- }
276
- interface WindowOptions<Row, Id extends string> extends Geometry<Row, Id> {
277
- readonly viewport: Viewport;
278
- /** Extra rows and columns rendered beyond each edge, so a fast scroll shows no gap. */
279
- readonly overscan?: {
280
- readonly rows?: number;
281
- readonly columns?: number;
282
- };
283
- }
284
- /**
285
- * What to render for a viewport: the rows and center columns it shows, plus
286
- * overscan, and the space the rest take. Rows are one fixed height, so the
287
- * row window is arithmetic on the scroll offset and never walks the rows; the
288
- * column window is a binary search over the center columns' widths. The
289
- * pinned columns are always rendered, outside the horizontal window.
290
- */
291
- declare const window: <Row, Id extends string>(options: WindowOptions<Row, Id>) => GridWindow<Id>;
292
- interface RevealOptions<Row, Id extends string> extends Geometry<Row, Id> {
293
- readonly viewport: Viewport;
294
- readonly position: CellPosition;
295
- }
296
- /**
297
- * The scroll offsets that bring a cell fully into view, moving each axis the
298
- * least it can, or none when it is already in view. A pinned column never
299
- * scrolls, so only its row is brought in.
300
- */
301
- declare const reveal: <Row, Id extends string>(options: RevealOptions<Row, Id>) => Option.Option<{
302
- readonly top: number;
303
- readonly left: number;
304
- }>;
305
- export declare const VirtualGrid: {
306
- window: typeof window;
307
- reveal: typeof reveal;
308
- };
5
+ import { GridProjection } from "./projection.js";
6
+ import { ColumnState } from "./columnState.js";
7
+ import { GridWindow, Viewport } from "./virtual.js";
309
8
  /**
310
9
  * One grid's interaction state: focus, the viewport and the column state, as
311
10
  * one Bundle. Its update is the parts' own, joined: a key that moves focus
@@ -317,7 +16,7 @@ export declare const VirtualGrid: {
317
16
  * `cellSelection` lets a rectangle of cells be selected; without them their
318
17
  * Messages change nothing.
319
18
  */
320
- declare const make$1: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(options: {
19
+ declare const make: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(options: {
321
20
  readonly id: string;
322
21
  readonly columns: Columns<Row, Specs>;
323
22
  readonly rowSelection?: 'single' | 'multiple';
@@ -392,12 +91,6 @@ declare const make$1: <Row, Specs extends Record<string, ColumnSpec<Row, unknown
392
91
  readonly column: keyof Specs & string;
393
92
  }>;
394
93
  readonly header: Option.Option<keyof Specs & string>;
395
- } | {
396
- readonly current: Option.Option<{
397
- readonly row: string;
398
- readonly column: keyof Specs & string;
399
- }>;
400
- readonly header: Option.Option<keyof Specs & string>;
401
94
  }, {
402
95
  readonly _tag: "Focused";
403
96
  readonly address: {
@@ -422,13 +115,13 @@ declare const make$1: <Row, Specs extends Record<string, ColumnSpec<Row, unknown
422
115
  }>;
423
116
  initial: () => ColumnState<keyof Specs & string>;
424
117
  widthOf: (state: ColumnState<keyof Specs & string>) => (id: keyof Specs & string) => number;
425
- regionOf: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => Region;
118
+ regionOf: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => import("./columnState.js").Region;
426
119
  resize: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, width: number) => ColumnState<keyof Specs & string>;
427
120
  hide: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => ColumnState<keyof Specs & string>;
428
121
  show: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => ColumnState<keyof Specs & string>;
429
- move: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, region: Region, index: number) => ColumnState<keyof Specs & string>;
122
+ move: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, region: import("./columnState.js").Region, index: number) => ColumnState<keyof Specs & string>;
430
123
  dropAt: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, delta: number) => number;
431
- restore: (saved: unknown) => Restored<keyof Specs & string>;
124
+ restore: (saved: unknown) => import("./columnState.js").Restored<keyof Specs & string>;
432
125
  };
433
126
  project: (rows: RowModel<Row>, state: {
434
127
  readonly start: readonly (keyof Specs & string)[];
@@ -1390,253 +1083,9 @@ declare const make$1: <Row, Specs extends Record<string, ColumnSpec<Row, unknown
1390
1083
  }, never, never, void, {}, {}>;
1391
1084
  };
1392
1085
  export declare const DataGrid: {
1393
- make: typeof make$1;
1394
- };
1395
- /** What `DataGrid.make` returns for these columns: the grid a view draws. */
1396
- type DataGridOf<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> = ReturnType<typeof make$1<Row, Specs>>;
1397
- type Direction = 'ltr' | 'rtl';
1398
- interface KeyOptions<Id extends string> {
1399
- readonly current: Option.Option<CellAddress<Id>>;
1400
- readonly key: string;
1401
- readonly modifiers: KeyboardModifiers;
1402
- /** Default `'ltr'`; under `'rtl'` the left and right arrows swap. */
1403
- readonly direction?: Direction;
1404
- /** How many rows PageUp and PageDown move: the rows a viewport shows. */
1405
- readonly pageRows: number;
1406
- }
1407
- /**
1408
- * The cell that holds the grid's one tab stop: the focused cell while it is
1409
- * shown, and otherwise the first cell. A focused cell whose column was hidden
1410
- * or whose row went away stays in the Model, so focus returns to it if it
1411
- * comes back, but the tab stop moves on until then.
1412
- */
1413
- declare const tabStop: <Row, Id extends string>(projection: GridProjection<Row, Id>, current: Option.Option<CellAddress<Id>>) => Option.Option<CellAddress<Id>>;
1414
- /**
1415
- * The cell a key moves focus to, or none when the key is not the grid's to
1416
- * handle, so the caller leaves it to the page. Arrows step one cell, Home and
1417
- * End go to the row's edges and, with Ctrl, to the grid's corners; PageUp and
1418
- * PageDown move `pageRows`. A key the grid handles always lands somewhere: at
1419
- * an edge, or onto a row that is counted but not loaded, focus stays where it
1420
- * is. Shift, Alt and Meta combinations are left alone: Shift extends a
1421
- * selection, which is not focus's to decide.
1422
- */
1423
- declare const target: <Row, Id extends string>(projection: GridProjection<Row, Id>, options: KeyOptions<Id>) => Option.Option<CellAddress<Id>>;
1424
- /**
1425
- * A cell's DOM id: the grid's id, the row key and the column id, each
1426
- * URI-encoded and joined by `:`, which encoding never leaves in a part, so no
1427
- * two cells share an id. The container points at it with
1428
- * `aria-activedescendant`.
1429
- */
1430
- declare const cellId: <Id extends string>(grid: string, address: CellAddress<Id>) => string;
1431
- /**
1432
- * The address a `cellId` names, if it is one of this grid's: its row key and
1433
- * its column id as written, for the grid's columns to check. An id from
1434
- * another grid, or with a malformed escape, is none.
1435
- */
1436
- declare const cellOf: (grid: string, id: string) => Option.Option<{
1437
- readonly row: string;
1438
- readonly column: string;
1439
- }>;
1440
- /**
1441
- * A column header's DOM id: the grid's id and the column id, URI-encoded and
1442
- * joined by `:`. It has two parts where a cell's has three, so the two never
1443
- * meet.
1444
- */
1445
- declare const headerId: (grid: string, column: string) => string;
1446
- /** The column a `headerId` names, if it is one of this grid's, as written. */
1447
- declare const headerOf: (grid: string, id: string) => Option.Option<string>;
1448
- /**
1449
- * Focus for one grid: which cell is current, by identity. Make it once per
1450
- * grid from its columns, so a focus saved in the Model decodes only against
1451
- * columns that exist.
1452
- */
1453
- declare const make: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(columns: Columns<Row, Specs>) => {
1454
- Address: Schema.Struct<{
1455
- readonly row: Schema.String;
1456
- readonly column: Schema.Literals<readonly (keyof Specs & string)[]>;
1457
- }>;
1458
- Model: Schema.Struct<{
1459
- /** The focused cell; stored as `null` when none is. */
1460
- readonly current: Schema.OptionFromNullOr<Schema.Struct<{
1461
- readonly row: Schema.String;
1462
- readonly column: Schema.Literals<readonly (keyof Specs & string)[]>;
1463
- }>>;
1464
- /**
1465
- * The column header focus is on, when it is on the header row. The cell
1466
- * focused before stays in `current`, so going back down returns to it.
1467
- */
1468
- readonly header: Schema.OptionFromNullOr<Schema.Literals<readonly (keyof Specs & string)[]>>;
1469
- }>;
1470
- Message: import("foldkit/message").MessageUnion<{
1471
- /** A cell became current: the user focused it, or a key moved there. */
1472
- readonly Focused: {
1473
- address: Schema.Struct<{
1474
- readonly row: Schema.String;
1475
- readonly column: Schema.Literals<readonly (keyof Specs & string)[]>;
1476
- }>;
1477
- };
1478
- /** Focus went up to a column's header. */
1479
- readonly HeaderFocused: {
1480
- column: Schema.Literals<readonly (keyof Specs & string)[]>;
1481
- };
1482
- }>;
1483
- bundle: Bundle.Bundle<"GridFocus", void, {
1484
- readonly current: Option.Option<{
1485
- readonly row: string;
1486
- readonly column: keyof Specs & string;
1487
- }>;
1488
- readonly header: Option.Option<keyof Specs & string>;
1489
- } | {
1490
- readonly current: Option.Option<{
1491
- readonly row: string;
1492
- readonly column: keyof Specs & string;
1493
- }>;
1494
- readonly header: Option.Option<keyof Specs & string>;
1495
- }, {
1496
- readonly _tag: "Focused";
1497
- readonly address: {
1498
- readonly row: string;
1499
- readonly column: keyof Specs & string;
1500
- };
1501
- } | {
1502
- readonly _tag: "HeaderFocused";
1503
- readonly column: keyof Specs & string;
1504
- }, never, never, never, void, {}, {}>;
1505
- };
1506
- export declare const GridFocus: {
1507
1086
  make: typeof make;
1508
- target: typeof target;
1509
- tabStop: typeof tabStop;
1510
- cellId: typeof cellId;
1511
- cellOf: typeof cellOf;
1512
- headerId: typeof headerId;
1513
- headerOf: typeof headerOf;
1514
- };
1515
- /**
1516
- * Which rows are selected. `Keys` names them; `AllExcept` is every row but
1517
- * these, so select-all holds whatever the rows are, loaded or not, and
1518
- * however many there turn out to be.
1519
- */
1520
- export declare const RowSelection: import("foldkit/schema").TaggedUnion<{
1521
- readonly Keys: {
1522
- keys: Schema.$Array<Schema.String>;
1523
- };
1524
- readonly AllExcept: {
1525
- except: Schema.$Array<Schema.String>;
1526
- };
1527
- }>;
1528
- export type RowSelection = typeof RowSelection.Type;
1529
- /** Whether a row is selected. Call it once per selection: it indexes the keys. */
1530
- declare const isSelected: (selection: RowSelection) => ((key: string) => boolean);
1531
- /** Selects a row, or deselects it if it is selected. */
1532
- declare const toggle: (selection: RowSelection, key: string) => RowSelection;
1533
- /** Selects every row in `keys`, keeping what was selected. */
1534
- declare const add: (selection: RowSelection, keys: ReadonlyArray<string>) => RowSelection;
1535
- /** The keys of the rows from `from` to `to`, in the projection's order, both included. */
1536
- declare const rowsBetween: <Row, Id extends string>(projection: GridProjection<Row, Id>, from: string, to: string) => ReadonlyArray<string>;
1537
- /** A rectangle of cells, named by its corners, so it survives a re-sort as two cells. */
1538
- interface CellRange<Id extends string> {
1539
- readonly anchor: CellAddress<Id>;
1540
- readonly focus: CellAddress<Id>;
1541
- }
1542
- /** The cells a range covers now, or none when a corner is hidden or gone. */
1543
- declare const boxOf: <Row, Id extends string>(projection: GridProjection<Row, Id>, range: CellRange<Id>) => Option.Option<CellBox<Id>>;
1544
- interface ExtendOptions<Id extends string> {
1545
- readonly range: Option.Option<CellRange<Id>>;
1546
- /** The focused cell: a range grows from it when there is none. */
1547
- readonly current: Option.Option<CellAddress<Id>>;
1548
- readonly key: string;
1549
- readonly modifiers: KeyboardModifiers;
1550
- readonly pageRows: number;
1551
- readonly direction?: Direction;
1552
- }
1553
- /**
1554
- * The range a Shift key makes, or none when the key is not one: Shift with an
1555
- * arrow moves the range's far corner a cell, with PageUp or PageDown a page,
1556
- * with Home or End to the row's edge. The near corner stays where the range
1557
- * began, the focused cell when there was none. As with focus, a key the grid
1558
- * handles always lands: at an edge, or before a row not loaded, the range
1559
- * stays as it is.
1560
- */
1561
- declare const extend: <Row, Id extends string>(projection: GridProjection<Row, Id>, options: ExtendOptions<Id>) => Option.Option<CellRange<Id>>;
1562
- export declare const GridSelection: {
1563
- none: {
1564
- readonly _tag: "Keys";
1565
- readonly keys: readonly string[];
1566
- };
1567
- isSelected: typeof isSelected;
1568
- toggle: typeof toggle;
1569
- add: typeof add;
1570
- rowsBetween: typeof rowsBetween;
1571
- boxOf: typeof boxOf;
1572
- extend: typeof extend;
1573
- };
1574
- declare const Message: import("foldkit/message").MessageUnion<{
1575
- /** The scroll container moved or changed size; the Mount reports it. */
1576
- readonly Measured: {
1577
- top: Schema.Number;
1578
- left: Schema.Number;
1579
- width: Schema.Number;
1580
- height: Schema.Number;
1581
- };
1582
- /** A reveal set the scroll offsets; the container's own scroll event confirms it later. */
1583
- readonly Revealed: {
1584
- top: Schema.Number;
1585
- left: Schema.Number;
1586
- };
1587
- }>;
1588
- type Message = typeof Message.Type;
1589
- /**
1590
- * Scrolls the container with this DOM id to `offsets` (from
1591
- * `VirtualGrid.reveal`) and reports `Revealed`, so the next window is drawn
1592
- * from the new offsets at once rather than after the scroll event.
1593
- */
1594
- declare const scrollTo: (viewportId: string, offsets: Pick<Viewport, 'top' | 'left'>) => Command<Message>;
1595
- export declare const GridViewport: {
1596
- Model: Schema.Struct<{
1597
- readonly top: Schema.Number;
1598
- readonly left: Schema.Number;
1599
- readonly width: Schema.Number;
1600
- readonly height: Schema.Number;
1601
- }>;
1602
- Message: import("foldkit/message").MessageUnion<{
1603
- /** The scroll container moved or changed size; the Mount reports it. */
1604
- readonly Measured: {
1605
- top: Schema.Number;
1606
- left: Schema.Number;
1607
- width: Schema.Number;
1608
- height: Schema.Number;
1609
- };
1610
- /** A reveal set the scroll offsets; the container's own scroll event confirms it later. */
1611
- readonly Revealed: {
1612
- top: Schema.Number;
1613
- left: Schema.Number;
1614
- };
1615
- }>;
1616
- bundle: Bundle.Bundle<"GridViewport", void, {
1617
- readonly top: number;
1618
- readonly left: number;
1619
- readonly width: number;
1620
- readonly height: number;
1621
- }, {
1622
- readonly _tag: "Measured";
1623
- readonly top: number;
1624
- readonly left: number;
1625
- readonly width: number;
1626
- readonly height: number;
1627
- } | {
1628
- readonly _tag: "Revealed";
1629
- readonly top: number;
1630
- readonly left: number;
1631
- }, never, never, never, void, {}, {}>;
1632
- Measure: Mount.MountDefinitionNoArgs<"GridViewportMeasure", {
1633
- readonly _tag: "Measured";
1634
- readonly top: number;
1635
- readonly left: number;
1636
- readonly width: number;
1637
- readonly height: number;
1638
- }>;
1639
- scrollTo: typeof scrollTo;
1640
1087
  };
1641
- export { type AxisWindow, type CellBox, CellEditor, type CellOffset, type CellPosition, type CellRange, type CellText, type Column, type ColumnEdit, type ColumnId, type ColumnSpec, Columns, type DataGridOf, type Direction, type EditableId, type ExtendOptions, type FillPlan, type FillRequest, type Geometry, type GridWindow, type KeyOptions, type PastedCell, type ProjectionOptions, type Region, type Restored, type RevealOptions, RowCount, RowModel, RowStatus, type Viewport, type WindowOptions, addressableRows };
1642
- //# sourceMappingURL=index.d.mts.map
1088
+ /** What `DataGrid.make` returns for these columns: the grid a view draws. */
1089
+ export type DataGridOf<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> = ReturnType<typeof make<Row, Specs>>;
1090
+ export {};
1091
+ //# sourceMappingURL=grid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid.d.ts","names":[],"sources":["../src/grid.ts"],"mappings":";;;;;;;;;;;;;;;;;;cAwCM,OAAQ,KAAK,cAAc,eAAe,WAAW,gBAAc;WAC9D;WACA,SAAS,QAAQ,KAAK;WACtB;WACA;;;EA2UD,kBAAA,6BACM,KAAK,WAAW,UAAU;aACzB;aACA,OAAO,UAAU,MAAM;oBAEnC;aAEgB;aAAsB,cAAM;aAAe;KAAc,UAChE,uBACE,KAAK,cAAc,UAAU,WAAW,uBAEnD,WAAW,SAAS,WAAW;EA7BF,YAAA,cAAA,mBAAA,OAAO,OAAO;;;MAjQrC,QAAM,OAAA;;;;MAEL,QAAM,OAAA,yBAAA;;;;;;;;;;;;KAgeN,cAAM,mBACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAofK,UAAA,MAAA,SAAS,MAAI;;;;;;;;;QAElB,eAAe,WAAW;EAYN,SAAA;aACZ,MAAM,SAAS;aACf;eA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