@casoon/opengrid 0.1.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.
package/loader.d.ts ADDED
@@ -0,0 +1,683 @@
1
+ /// <reference lib="dom" />
2
+ /**
3
+ * Types for `@casoon/opengrid` (plan point 75).
4
+ *
5
+ * Written by hand after `docs/api.md`, which is the source: everything a page
6
+ * can rely on is typed here, and nothing else. The freeze test in
7
+ * `crates/opengrid-web-components/src/api.rs` fails when a frozen name is
8
+ * missing from this file, so the two cannot drift apart silently.
9
+ *
10
+ * The module functions (`set_provider`, `set_view`, …) are reached through
11
+ * `loadOpengrid()`: `(await loadOpengrid()).module`.
12
+ */
13
+
14
+ // ---------------------------------------------------------------------------
15
+ // Loading
16
+ // ---------------------------------------------------------------------------
17
+
18
+ export interface LoadOptions {
19
+ /** The wasm-bindgen glue of the element module; defaults to the packaged one. */
20
+ moduleUrl?: URL | string;
21
+ /** An explicit `.wasm` URL, if it is not next to the glue. */
22
+ wasmUrl?: URL | string;
23
+ }
24
+
25
+ /**
26
+ * What `loadOpengrid()` answers. `fallback` is `true` when the WebAssembly
27
+ * module could not be loaded and a plain-DOM stand-in was installed instead —
28
+ * then there is no module to call.
29
+ */
30
+ export type LoadResult =
31
+ | { fallback: false; module: OpengridModule }
32
+ | { fallback: true; module?: undefined };
33
+
34
+ /** Loads the WASM module and registers the three elements; runs once. */
35
+ export function loadOpengrid(options?: LoadOptions): Promise<LoadResult>;
36
+
37
+ /** The functions of the element module. */
38
+ export interface OpengridModule {
39
+ /** Attaches the data source. Call {@link OpengridModule.set_texts} first. */
40
+ set_provider(host: HTMLElement, provider: Provider): void;
41
+ /** Overrides any subset of the texts; call it before `set_provider`. */
42
+ set_texts(host: HTMLElement, texts: Texts): void;
43
+ /** Per-column display formatting. Never reaches a query. */
44
+ set_formats(host: HTMLElement, formats: Formats): void;
45
+ /** Per-column editor choices: `{ customer: ["Alpha", "Beta"] }`. */
46
+ set_choices(host: HTMLElement, choices: Choices): void;
47
+ /** The whole view as one value; `null` before the grid is connected. */
48
+ get_view(host: HTMLElement): View | null;
49
+ /** Applies a view in one step and one query. Parts left out keep their default. */
50
+ set_view(host: HTMLElement, view: ViewInput): void;
51
+ /** Per-column presentation; narrows what the schema allows, never widens it. */
52
+ set_columns(host: HTMLElement, columns: Columns): void;
53
+ /**
54
+ * The query of the current view without a window — what an export sends.
55
+ * `null` without a query, with a filter that does not hold, and for the
56
+ * table and the pivot.
57
+ */
58
+ get_query(host: HTMLElement): ViewQuery | null;
59
+ /**
60
+ * The pivot as it is shown, as CSV text: one header line (`2025 · total`),
61
+ * every row including subtotals and the grand total, the element's labels.
62
+ * `null` while nothing is shown, and for the grid and the table. Throws on an
63
+ * unknown or mistyped option, and on a shown answer it cannot read (cells
64
+ * that do not match its row dimensions and columns — a custom provider's).
65
+ * Values are in the canonical wire notation: a float `2` reads `2.0`.
66
+ */
67
+ get_pivot(host: HTMLElement, options?: CsvOptions): string | null;
68
+ /** Defines the three elements. `loadOpengrid()` calls it. */
69
+ register(): void;
70
+ }
71
+
72
+ // ---------------------------------------------------------------------------
73
+ // Connecting
74
+ // ---------------------------------------------------------------------------
75
+
76
+ /**
77
+ * What `connect` supplies an element with. Each is one module function —
78
+ * `presentation` is `set_columns`, named apart from the `columns` attribute —
79
+ * and the three callbacks receive the event's `detail`.
80
+ */
81
+ export interface ConnectOptions {
82
+ provider?: Provider;
83
+ texts?: Texts;
84
+ formats?: Formats;
85
+ /** Per-column presentation, as `set_columns` takes it (type {@link Columns}). */
86
+ presentation?: Columns;
87
+ choices?: Choices;
88
+ /**
89
+ * The view, controlled: written whenever it differs from what the grid shows
90
+ * — after the reader sorted, passing the same view again puts it back. Writing
91
+ * back what the grid just reported costs nothing. `undefined` or `null`: the
92
+ * grid leads.
93
+ */
94
+ view?: ViewInput | null;
95
+ /** The view, uncontrolled: applied once, then the grid leads. */
96
+ defaultView?: ViewInput;
97
+ /** The reader changed the view. Not called for views `connect` wrote. */
98
+ onViewChange?: (view: View) => void;
99
+ onSelectionChange?: (detail: SelectionChangeDetail) => void;
100
+ onCellChange?: (detail: CellChangeDetail) => void;
101
+ }
102
+
103
+ export interface Connection {
104
+ /** Settles once the module is loaded and the options are applied. */
105
+ ready: Promise<LoadResult>;
106
+ /**
107
+ * Applies what changed. A key left out keeps its value; a key given as
108
+ * `undefined` resets it — except `provider`, and `view`, where it means the
109
+ * grid leads.
110
+ */
111
+ update(options?: ConnectOptions): void;
112
+ /** Removes the listeners. The element keeps its state. */
113
+ disconnect(): void;
114
+ }
115
+
116
+ /**
117
+ * Supplies an element from one options object — in the right order, once the
118
+ * module is loaded, asking once — and keeps it supplied. The view needs the
119
+ * element in the document: on one that is not, the view and the provider wait
120
+ * together for the next `update`. The module is loaded with `loadOpengrid()`;
121
+ * a page that needs its own URLs calls `loadOpengrid(options)` first.
122
+ */
123
+ export function connect(host: HTMLElement, options?: ConnectOptions): Connection;
124
+
125
+ // ---------------------------------------------------------------------------
126
+ // Providers
127
+ // ---------------------------------------------------------------------------
128
+
129
+ /**
130
+ * Where the data comes from. A seam, not a class: anything with an `execute`
131
+ * method fits. `queryJson` is the query as JSON; the answer is the result as
132
+ * JSON, or a Promise of it. `mode` is the element's `mode` attribute, `""`
133
+ * without one. `options` is optional and new: a provider written for two
134
+ * arguments still fits.
135
+ */
136
+ export interface Provider {
137
+ execute(queryJson: string, mode: string, options?: ExecuteOptions): string | Promise<string>;
138
+ /**
139
+ * Optional: the whole export of `query` in one go. `exportRows` uses it when
140
+ * it is there instead of fetching pieces over `execute` —
141
+ * `createRestProvider` has it, as `POST /export/{source}`.
142
+ */
143
+ export?(query: ViewQuery, options?: ProviderExportOptions): Promise<Blob>;
144
+ }
145
+
146
+ /**
147
+ * The third argument of `execute`. `signal` aborts the request: the REST,
148
+ * pivot and hybrid providers hand it to `fetch`; the tab and the worker cannot
149
+ * stop a query that has started and ignore it — their answer is dropped.
150
+ */
151
+ export interface ExecuteOptions {
152
+ signal?: AbortSignal;
153
+ }
154
+
155
+ /** A provider over an engine that holds data: the tab or a worker. */
156
+ export interface EngineProvider extends Provider {
157
+ /** Loads CSV bytes as the source `name`, against a schema (JSON). */
158
+ load(name: string, bytes: ArrayBuffer | Uint8Array, schema: string): Promise<void>;
159
+ /** Stops a worker; a no-op in the tab. */
160
+ terminate(): void;
161
+ }
162
+
163
+ /** The engine of the engine module, as `createLocalProvider` uses it. */
164
+ export interface Engine {
165
+ load_csv(name: string, bytes: Uint8Array, schema: string): void;
166
+ execute(queryJson: string): string;
167
+ }
168
+
169
+ /** What a server says a source is. */
170
+ export interface SourceDescription {
171
+ name: string;
172
+ schema: unknown;
173
+ capabilities: unknown;
174
+ pivot_limits: unknown;
175
+ }
176
+
177
+ export interface RestProvider extends Provider {
178
+ /** `GET /source/{name}`: what a `Planner` needs to split queries. */
179
+ describe(): Promise<SourceDescription>;
180
+ /**
181
+ * `POST /export/{source}`: every row of `query` in one streamed request, in
182
+ * the notation `exportRows` writes. The server's rules are `/query`'s; its
183
+ * bound is `max_export_rows`. `maxRows` refuses before the body is read,
184
+ * `onProgress` hears the end, `signal` aborts the download too.
185
+ */
186
+ export(query: ViewQuery, options?: ProviderExportOptions): Promise<Blob>;
187
+ }
188
+
189
+ /** The `Planner` of the engine module, as `createHybridProvider` uses it. */
190
+ export interface PlannerLike {
191
+ /** The plan as JSON: `{ mode, describe, steps, source, client }`. */
192
+ plan(queryJson: string, mode: string): string;
193
+ /** Finishes the client half over the source's answer; the result as JSON. */
194
+ finish(clientQueryJson: string, resultJson: string): string;
195
+ }
196
+
197
+ /** The plan `createHybridProvider` hands to `onPlan` before anything is sent. */
198
+ export interface ExecutionPlan {
199
+ mode: Mode;
200
+ /** One line for tools: `source: filter · sort | client: group · aggregate`. */
201
+ describe: string;
202
+ steps: string[];
203
+ source: unknown;
204
+ /** The half the tab finishes; `null` when the source answers everything. */
205
+ client: unknown;
206
+ }
207
+
208
+ export interface ServerOptions {
209
+ /** The server's base URL. */
210
+ url: string;
211
+ /** The configured data source name. */
212
+ source: string;
213
+ /** Bearer token; the server refuses without one. */
214
+ token?: string;
215
+ }
216
+
217
+ /** The engine on the main thread. */
218
+ export function createLocalProvider(engine: Engine): EngineProvider;
219
+
220
+ /**
221
+ * The engine in a module worker, started lazily and once. Without `moduleUrl`
222
+ * it is the engine the package ships, `engine/opengrid_wasm.js` next to the
223
+ * loader. `moduleUrl` and `wasmUrl` travel to the worker by `postMessage`, so
224
+ * they are strings — a `URL` object cannot be copied there; pass `url.href`.
225
+ */
226
+ export function createWorkerProvider(options?: {
227
+ moduleUrl?: string;
228
+ wasmUrl?: string;
229
+ workerUrl?: URL | string;
230
+ }): EngineProvider & { readonly worker: Worker | undefined };
231
+
232
+ /** `POST /query/{source}` of an `opengrid-server`. */
233
+ export function createRestProvider(options: ServerOptions): RestProvider;
234
+
235
+ /** `POST /pivot/{source}` — a whole pivot in one request. */
236
+ export function createPivotProvider(options: ServerOptions): Provider;
237
+
238
+ /** Splits each query between a remote source and the engine in the tab. */
239
+ export function createHybridProvider(options: {
240
+ remote: Provider;
241
+ planner: PlannerLike;
242
+ mode?: Mode;
243
+ onPlan?: (plan: ExecutionPlan) => void;
244
+ }): Provider;
245
+
246
+ // ---------------------------------------------------------------------------
247
+ // Exporting
248
+ // ---------------------------------------------------------------------------
249
+
250
+ /** What `onProgress` hears after each piece. */
251
+ export interface ExportProgress {
252
+ /** Rows written so far. */
253
+ rows: number;
254
+ /** Every match, from the first piece's `total_count`. */
255
+ total: number;
256
+ }
257
+
258
+ /**
259
+ * How `exportRows` fetches and writes: its own keys, plus the
260
+ * {@link CsvOptions} `get_pivot` takes too. Any other key is an error, and so
261
+ * is a CSV option on a JSON export.
262
+ */
263
+ export interface ExportOptions extends CsvOptions {
264
+ /** `"csv"` (the default) or `"json"` — an array of row objects. */
265
+ format?: "csv" | "json";
266
+ /** Rows per request; 10 000 by default, the server's `max_limit`. */
267
+ chunkSize?: number;
268
+ /** More matches than this is an error, never a truncated file; 1 000 000 by default. */
269
+ maxRows?: number;
270
+ /** Called after each piece. */
271
+ onProgress?: (progress: ExportProgress) => void;
272
+ /** Aborts the export: it rejects with an `AbortError` and gives no `Blob`. */
273
+ signal?: AbortSignal;
274
+ }
275
+
276
+ /**
277
+ * What a provider's `export` takes: {@link ExportOptions} without
278
+ * `chunkSize` — there are no pieces to size. Any other key is an error.
279
+ */
280
+ export type ProviderExportOptions = Omit<ExportOptions, "chunkSize">;
281
+
282
+ /**
283
+ * Every match of `query` — as `get_query(host)` gives it — through `provider`,
284
+ * in pieces, as a `Blob` of `text/csv;charset=utf-8` or `application/json`.
285
+ * Raw values in the wire notation, a header of field names. The sort is made
286
+ * total by appending every selected column not yet in it, ascending; within a
287
+ * tie the export follows the columns, not the grid. A source whose count
288
+ * changes between two pieces is refused with an error, not exported. A
289
+ * provider with an `export` method gets the same query in one request instead.
290
+ */
291
+ export function exportRows(provider: Provider, query: ViewQuery, options?: ExportOptions): Promise<Blob>;
292
+
293
+ // ---------------------------------------------------------------------------
294
+ // Errors
295
+ // ---------------------------------------------------------------------------
296
+
297
+ /**
298
+ * What went wrong, as a closed list a page can switch on. The first seven are
299
+ * the server's, from its error form; the last three are `exportRows`' own.
300
+ */
301
+ export type ErrorCode =
302
+ | "validation"
303
+ | "unknown_source"
304
+ | "limit_exceeded"
305
+ | "busy"
306
+ | "unauthorized"
307
+ | "backend"
308
+ | "malformed"
309
+ | "too_many_rows"
310
+ | "source_changed"
311
+ | "module_not_loaded";
312
+
313
+ /**
314
+ * What the REST and pivot providers and `exportRows` reject with: a plain
315
+ * `Error` with these fields — not a class of its own, so test `error.code`,
316
+ * not `instanceof`. The message is a sentence for the developer, the same as
317
+ * without the fields. A wrong option is a `TypeError`, an abort a
318
+ * `DOMException` named `"AbortError"` — test its `name`: its `code` is the
319
+ * DOM's legacy number, never one of these strings.
320
+ *
321
+ * ```ts
322
+ * try {
323
+ * await exportRows(provider, query);
324
+ * } catch (error) {
325
+ * if ((error as Error).name === "AbortError") return;
326
+ * switch ((error as CodedError).code) {
327
+ * case "busy": // try again in a moment
328
+ * case "too_many_rows": // narrow the view
329
+ * default: // the export failed
330
+ * }
331
+ * }
332
+ * ```
333
+ */
334
+ export interface CodedError extends Error {
335
+ /** The HTTP status, when a server refused the request. */
336
+ status?: number;
337
+ /**
338
+ * Absent when neither the server nor the loader named one. A newer server
339
+ * may send a code this list does not have yet: keep a `default:` branch.
340
+ */
341
+ code?: ErrorCode;
342
+ /** Where in the query, when the server says: `filter.and[1].value`. */
343
+ path?: string;
344
+ }
345
+
346
+ // ---------------------------------------------------------------------------
347
+ // Configuration
348
+ // ---------------------------------------------------------------------------
349
+
350
+ /** Where a query may run; handed to the provider unchanged. */
351
+ export type Mode = "local" | "remote" | "hybrid" | "auto";
352
+
353
+ export type Density = "compact" | "normal" | "comfortable";
354
+
355
+ /** The filter operators, by wire token. */
356
+ export type FilterOperator =
357
+ | "eq"
358
+ | "ne"
359
+ | "gt"
360
+ | "gte"
361
+ | "lt"
362
+ | "lte"
363
+ | "contains"
364
+ | "starts_with"
365
+ | "is_null"
366
+ | "is_not_null";
367
+
368
+ /** An aggregate in group rows and the grand total. */
369
+ export type Aggregate = "sum" | "avg" | "count" | "min" | "max" | "range";
370
+
371
+ /** How a column is offered as a facet. */
372
+ export type FacetKind = "list" | "pills" | "range" | "period";
373
+
374
+ /** A value as the wire format writes it: decimals and dates are strings. */
375
+ export type WireValue = string | number | boolean | null;
376
+
377
+ /** Per-column presentation for `set_columns` — `presentation` in `connect`. */
378
+ export interface ColumnConfig {
379
+ /** The starting width in pixels; a reader's resize leads after that. */
380
+ width?: number;
381
+ align?: "start" | "end" | "center";
382
+ mono?: boolean;
383
+ emphasis?: boolean;
384
+ muted?: boolean;
385
+ aggregate?: Aggregate;
386
+ facet?: FacetKind;
387
+ }
388
+
389
+ export type Columns = Record<string, ColumnConfig>;
390
+
391
+ /** A display format: a function, or `Intl` options with a `kind`. */
392
+ export type Format =
393
+ | ((text: string, value: WireValue) => string)
394
+ | ({ kind?: "number"; locale?: string } & Intl.NumberFormatOptions)
395
+ | ({ kind: "date"; locale?: string } & Intl.DateTimeFormatOptions);
396
+
397
+ export type Formats = Record<string, Format>;
398
+
399
+ export type Choices = Record<string, string[]>;
400
+
401
+ // ---------------------------------------------------------------------------
402
+ // The view
403
+ // ---------------------------------------------------------------------------
404
+
405
+ export interface SortKey {
406
+ field: string;
407
+ direction: "asc" | "desc";
408
+ }
409
+
410
+ /** A sort key of a query, which may also say where NULLs land. */
411
+ export interface QuerySortKey extends SortKey {
412
+ /**
413
+ * `"last"` when left out, whatever the direction. `get_query` writes it for
414
+ * the group keys.
415
+ */
416
+ nulls?: "first" | "last";
417
+ }
418
+
419
+ export interface FilterEntry {
420
+ column: string;
421
+ op: FilterOperator;
422
+ /** The value as typed, in the notation of the column's type. */
423
+ value: string;
424
+ }
425
+
426
+ /** A facet selection: values for `list`/`pills`, bounds for `range`/`period`. */
427
+ export type FacetSelection =
428
+ | { values: WireValue[] }
429
+ | { min: string; max: string }
430
+ | { from: string; to: string };
431
+
432
+ /**
433
+ * Sort, filters, column layout, density, grouping, aggregates and facets as
434
+ * one value — as `get_view` writes it, every field present. `set_view` reads
435
+ * some fields more leniently (a missing direction is `asc`, a missing operator
436
+ * `eq`); the types ask for the full form on purpose, so a saved view says what
437
+ * it means. A saved view is this value with a name on it. The selection and
438
+ * the free-text search are deliberately not part of it.
439
+ */
440
+ export interface View {
441
+ sort: SortKey[];
442
+ filters: FilterEntry[];
443
+ columns: { order: string[]; hidden: string[]; widths: Record<string, number> };
444
+ density: Density;
445
+ group: string[];
446
+ /** The open groups, each as its path of keys. */
447
+ expanded: WireValue[][];
448
+ /** The reader's aggregate per column; leads over `set_columns`. */
449
+ aggregates: Record<string, Aggregate>;
450
+ /** Whether the filter row shows. */
451
+ filterRow: boolean;
452
+ facets: Record<string, FacetSelection>;
453
+ }
454
+
455
+ /** The query of a view, as `get_query` gives it: every match, no window. */
456
+ export interface ViewQuery {
457
+ source: string;
458
+ select: string[];
459
+ /** The filter expression of the query model, when anything restricts. */
460
+ filter?: unknown;
461
+ /** Never empty: a grid without a sort pages under its first column. */
462
+ sort: QuerySortKey[];
463
+ }
464
+
465
+ /** How a CSV is written. Every key is optional; no other key is accepted. */
466
+ export interface CsvOptions {
467
+ /** One character: `,` by default, `;` for a German Excel. */
468
+ delimiter?: string;
469
+ /** Start with a UTF-8 byte order mark. `true` by default (Excel). */
470
+ bom?: boolean;
471
+ /** Prefix a text cell that a spreadsheet would run as a formula. `true` by default. */
472
+ protectFormulas?: boolean;
473
+ /** How NULL is written. Empty by default; `"\\N"` reads back into opengrid. */
474
+ null?: string;
475
+ }
476
+
477
+ /**
478
+ * What `set_view` takes: any part of a view. A part left out is not "unchanged"
479
+ * but its default — no sort falls back to the first column, no filters is none.
480
+ */
481
+ export type ViewInput = Partial<Omit<View, "columns">> & {
482
+ columns?: Partial<View["columns"]>;
483
+ };
484
+
485
+ // ---------------------------------------------------------------------------
486
+ // Texts
487
+ // ---------------------------------------------------------------------------
488
+
489
+ /** Every text key, `lang` and `operators` aside. */
490
+ export type TextKey =
491
+ | "loading"
492
+ | "matchesOne"
493
+ | "matchesOther"
494
+ | "empty"
495
+ | "error"
496
+ | "errorUnknown"
497
+ | "filterGroup"
498
+ | "operatorLabel"
499
+ | "valueLabel"
500
+ | "clear"
501
+ | "selectAll"
502
+ | "selectedAll"
503
+ | "groupRow"
504
+ | "rowsOne"
505
+ | "rowsOther"
506
+ | "groupExpanded"
507
+ | "groupCollapsed"
508
+ | "groupInvalid"
509
+ | "totalRow"
510
+ | "aggregateCell"
511
+ | "aggregateSum"
512
+ | "aggregateAvg"
513
+ | "aggregateCount"
514
+ | "aggregateMin"
515
+ | "aggregateMax"
516
+ | "aggregateRange"
517
+ | "columnMenu"
518
+ | "sortAscending"
519
+ | "sortDescending"
520
+ | "filterColumn"
521
+ | "aggregateGroup"
522
+ | "aggregateNone"
523
+ | "groupByColumn"
524
+ | "groupSecondLevel"
525
+ | "ungroupColumn"
526
+ | "hideColumn"
527
+ | "toolbarGroup"
528
+ | "filterRowToggle"
529
+ | "densityGroup"
530
+ | "densityCompact"
531
+ | "densityNormal"
532
+ | "densityComfortable"
533
+ | "chipsGroup"
534
+ | "chipsClear"
535
+ | "chipRemove"
536
+ | "filterRemoved"
537
+ | "filtersCleared"
538
+ | "groupChip"
539
+ | "facetsGroup"
540
+ | "facetsToggle"
541
+ | "facetsReset"
542
+ | "facetFrom"
543
+ | "facetTo"
544
+ | "facetQueries"
545
+ | "facetChipValues"
546
+ | "searchLabel"
547
+ | "searchPlaceholder"
548
+ | "queryAnd"
549
+ | "searchHint"
550
+ | "searchSuggestions"
551
+ | "typeText"
552
+ | "typeBool"
553
+ | "typeInteger"
554
+ | "typeNumber"
555
+ | "typeDate"
556
+ | "typeTime"
557
+ | "searchChip"
558
+ | "queryUnknownColumn"
559
+ | "queryMissingValue"
560
+ | "queryWrongOperator"
561
+ | "emptyFiltered"
562
+ | "emptySource"
563
+ | "emptyReset"
564
+ | "filterInvalid"
565
+ | "cellRequired"
566
+ | "selectionCleared"
567
+ | "columnWidth"
568
+ | "columnMoved"
569
+ | "columnAtEdge"
570
+ | "columnHidden"
571
+ | "columnShown"
572
+ | "columnsGroup"
573
+ | "pageFirst"
574
+ | "pagePrevious"
575
+ | "pageNext"
576
+ | "pageLast"
577
+ | "pageOf"
578
+ | "total"
579
+ | "subtotal"
580
+ | "noValue"
581
+ | "emptyValue";
582
+
583
+ /**
584
+ * Any subset of the texts; what is left out keeps its English default. `lang`
585
+ * goes onto the elements that carry these texts, never onto the data.
586
+ */
587
+ export type Texts = Partial<Record<TextKey, string>> & {
588
+ lang?: string;
589
+ operators?: Partial<Record<FilterOperator, string>>;
590
+ };
591
+
592
+ // ---------------------------------------------------------------------------
593
+ // Events
594
+ // ---------------------------------------------------------------------------
595
+
596
+ /** `opengrid-selection-change`: logical row numbers, ascending. */
597
+ export interface SelectionChangeDetail {
598
+ rows: number[];
599
+ count: number;
600
+ }
601
+
602
+ /** `opengrid-cell-change`: everything a page needs to persist an edit. */
603
+ export interface CellChangeDetail {
604
+ row: number;
605
+ column: string;
606
+ value: string;
607
+ previous: string;
608
+ }
609
+
610
+ /** `opengrid-view-change`: the whole view after the change. */
611
+ export interface ViewChangeDetail {
612
+ view: View;
613
+ }
614
+
615
+ /** The events, by name. All bubble, all are composed, none is cancelable. */
616
+ export interface OpengridEventMap {
617
+ "opengrid-selection-change": CustomEvent<SelectionChangeDetail>;
618
+ "opengrid-cell-change": CustomEvent<CellChangeDetail>;
619
+ "opengrid-view-change": CustomEvent<ViewChangeDetail>;
620
+ }
621
+
622
+ // ---------------------------------------------------------------------------
623
+ // Elements and their attributes
624
+ // ---------------------------------------------------------------------------
625
+
626
+ /**
627
+ * The attributes of `<opengrid-grid>`, as strings the way HTML has them — for
628
+ * adapters and JSX typings to build on. For
629
+ * the boolean ones — `selection`, `toolbar`, `search`, `facets`,
630
+ * `column-menu` — presence is what counts, whatever the value.
631
+ */
632
+ export interface OpengridGridAttributes {
633
+ label?: string;
634
+ datasource?: string;
635
+ columns?: string;
636
+ "window-size"?: string;
637
+ "page-size"?: string;
638
+ mode?: Mode;
639
+ "group-by"?: string;
640
+ search?: string;
641
+ facets?: string;
642
+ toolbar?: string;
643
+ "column-menu"?: string;
644
+ selection?: string;
645
+ density?: Density;
646
+ }
647
+
648
+ export interface OpengridTableAttributes {
649
+ label?: string;
650
+ datasource?: string;
651
+ columns?: string;
652
+ }
653
+
654
+ export interface OpengridPivotAttributes {
655
+ label?: string;
656
+ datasource?: string;
657
+ /** Comma-separated row dimensions, outermost first. */
658
+ rows?: string;
659
+ /** Comma-separated column dimensions; V1 allows one. */
660
+ columns?: string;
661
+ /** The measures as the contract's JSON: `[{"field":"qty","fn":"sum","as":"total"}]`. */
662
+ values?: string;
663
+ }
664
+
665
+ /** `<opengrid-grid>`; it fires the three events. */
666
+ export interface OpengridGridElement extends HTMLElement {}
667
+ /** `<opengrid-table>`. */
668
+ export interface OpengridTableElement extends HTMLElement {}
669
+ /** `<opengrid-pivot>`. */
670
+ export interface OpengridPivotElement extends HTMLElement {}
671
+
672
+ declare global {
673
+ interface HTMLElementTagNameMap {
674
+ "opengrid-grid": OpengridGridElement;
675
+ "opengrid-table": OpengridTableElement;
676
+ "opengrid-pivot": OpengridPivotElement;
677
+ }
678
+ /**
679
+ * The events bubble and are composed, so a listener on an ancestor, the
680
+ * document or the window hears them too — hence the global handler map.
681
+ */
682
+ interface GlobalEventHandlersEventMap extends OpengridEventMap {}
683
+ }