@casoon/opengrid 0.15.0 → 0.16.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 (32) hide show
  1. package/CHANGELOG.md +247 -1
  2. package/README.md +6 -4
  3. package/engine/opengrid_wasm_bg.wasm +0 -0
  4. package/loader.d.ts +390 -18
  5. package/loader.js +473 -90
  6. package/package.json +8 -1
  7. package/pkg/opengrid_web_components.d.ts +73 -7
  8. package/pkg/opengrid_web_components.js +339 -53
  9. package/pkg/opengrid_web_components_bg.wasm +0 -0
  10. package/pkg/opengrid_web_components_bg.wasm.d.ts +15 -6
  11. package/react/index.d.ts +8 -2
  12. package/react/index.js +9 -3
  13. package/svelte/Opengrid.svelte +7 -1
  14. package/svelte/OpengridGrid.svelte +5 -1
  15. package/svelte/OpengridPivot.svelte +3 -3
  16. package/svelte/OpengridTable.svelte +1 -1
  17. package/svelte/index.d.ts +12 -2
  18. package/svelte/index.js +1 -1
  19. package/texts/de.d.ts +5 -0
  20. package/texts/de.js +245 -0
  21. package/vue/index.d.ts +12 -2
  22. package/vue/index.js +10 -6
  23. package/worker.js +1 -2
  24. package/xlsx/opengrid_xlsx.d.ts +69 -0
  25. package/xlsx/opengrid_xlsx.js +375 -0
  26. package/xlsx/opengrid_xlsx_bg.wasm +0 -0
  27. package/xlsx/opengrid_xlsx_bg.wasm.d.ts +16 -0
  28. /package/pkg/snippets/{opengrid-web-components-ef3def04de0cb619 → opengrid-web-components-35ed06b453a9b215}/inline0.js +0 -0
  29. /package/pkg/snippets/{opengrid-web-components-ef3def04de0cb619 → opengrid-web-components-35ed06b453a9b215}/inline1.js +0 -0
  30. /package/pkg/snippets/{opengrid-web-core-78fdded9b8a374ed → opengrid-web-core-b41714d4e7311909}/inline0.js +0 -0
  31. /package/pkg/snippets/{opengrid-web-core-78fdded9b8a374ed → opengrid-web-core-b41714d4e7311909}/inline1.js +0 -0
  32. /package/pkg/snippets/{opengrid-web-core-78fdded9b8a374ed → opengrid-web-core-b41714d4e7311909}/inline2.js +0 -0
package/loader.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference lib="dom" />
2
2
  /**
3
- * Types for `@casoon/opengrid` (plan point 75).
3
+ * Types for `@casoon/opengrid`.
4
4
  *
5
5
  * Written by hand after `docs/api.md`, which is the source: everything a page
6
6
  * can rely on is typed here, and nothing else. The freeze test in
@@ -66,6 +66,13 @@ export interface OpengridModule {
66
66
  * table and the pivot.
67
67
  */
68
68
  get_query(host: HTMLElement): ViewQuery | null;
69
+ /**
70
+ * The header texts of the columns shown that stand under a band, by field name:
71
+ * `{ city: "Address · City" }` (issue #353). Pass it to `exportRows` as
72
+ * `headers`; the print table uses the same texts. Columns without a band are
73
+ * not in it.
74
+ */
75
+ get_export_headers(host: HTMLElement): Record<string, string>;
69
76
  /**
70
77
  * The pivot as it is shown, as CSV text: one header line (`2025 · total`),
71
78
  * every row including subtotals and the grand total, the element's labels.
@@ -75,6 +82,15 @@ export interface OpengridModule {
75
82
  * Values are in the canonical wire notation: a float `2` reads `2.0`.
76
83
  */
77
84
  get_pivot(host: HTMLElement, options?: CsvOptions): string | null;
85
+ /**
86
+ * Builds the grid's print table (issue #334): every match of the view as a
87
+ * native table that only `@media print` shows, in place of the grid, until
88
+ * `afterprint`. Await it, then call `window.print()`. Resolves with the
89
+ * number of rows; with `null` where `get_query` answers `null`, and for the
90
+ * table and the pivot, which print as they are. Rejects with the provider's
91
+ * error, and with the code `too_many_rows` for more than 10 000 matches.
92
+ */
93
+ prepare_print(host: HTMLElement): Promise<number | null>;
78
94
  /**
79
95
  * What became of an edit the page saves (issue #153). `key` is the record's
80
96
  * `row-key` value as `opengrid-cell-change` gave it. `saved` clears the
@@ -118,6 +134,22 @@ export interface OpengridModule {
118
134
  * blocks the commit; `{ validate, block: true }` blocks on an `error`.
119
135
  */
120
136
  set_validators(host: HTMLElement, validators: Record<string, Validator | ValidatorRule>): void;
137
+ /**
138
+ * The DOM node a cell shows instead of its text (issue #317). A function per
139
+ * column; never an HTML string. The source's value stays what search, export
140
+ * and events read. The grid only.
141
+ */
142
+ set_cell_templates(host: HTMLElement, templates: Record<string, CellTemplate>): void;
143
+ /**
144
+ * The function that builds the panel under an open row (issue #318); `null`
145
+ * takes the panels away. Needs a `row-key`; not offered grouped or as a tree.
146
+ */
147
+ set_detail_renderer(host: HTMLElement, renderer: DetailRenderer | null): void;
148
+ /**
149
+ * Runs the grid's query again over a source that changed, keeping the view,
150
+ * the focus by record, the selection by key and the history (issue #328).
151
+ */
152
+ refresh(host: HTMLElement): void;
121
153
  /** Defines the three elements. `loadOpengrid()` calls it. */
122
154
  register(): void;
123
155
  }
@@ -153,6 +185,10 @@ export interface ConnectOptions {
153
185
  onCellChange?: (detail: CellChangeDetail) => void;
154
186
  /** `set_actions`: compared by value. The grid only. */
155
187
  actions?: RowAction[];
188
+ /** `set_cell_templates`: functions compare by identity, as in `formats`. The grid only. */
189
+ cellTemplates?: Record<string, CellTemplate>;
190
+ /** `set_detail_renderer`: compared by identity. The grid only. */
191
+ detailRenderer?: DetailRenderer | null;
156
192
  /** `set_validators`: functions compare by identity, as in `formats`. The grid only. */
157
193
  validators?: Record<string, Validator | ValidatorRule>;
158
194
  /**
@@ -166,6 +202,8 @@ export interface ConnectOptions {
166
202
  onPaste?: (detail: PasteDetail) => void;
167
203
  onBulkChange?: (detail: BulkChangeDetail) => void;
168
204
  onRowAction?: (detail: RowActionDetail) => void;
205
+ /** A value of a pivot with `drill-down` was pressed. The pivot only. */
206
+ onDrillDown?: (detail: DrillDownDetail) => void;
169
207
  /** The provider loaded the grid's source again (`loadRows`); the grid asks anew. */
170
208
  onSourceReplaced?: (detail: SourceReplacedDetail) => void;
171
209
  }
@@ -340,6 +378,20 @@ export interface RestProvider extends Provider {
340
378
  * `onProgress` hears the end, `signal` aborts the download too.
341
379
  */
342
380
  export(query: ViewQuery, options?: ProviderExportOptions): Promise<Blob>;
381
+ /** `POST /pivot/{source}?format=xlsx`: see {@link PivotProvider.exportPivot}. */
382
+ exportPivot(pivotQuery: PivotQuery, options: ProviderPivotExportOptions): Promise<Blob>;
383
+ }
384
+
385
+ /** What `createPivotProvider` answers. */
386
+ export interface PivotProvider extends Provider {
387
+ /**
388
+ * `POST /pivot/{source}?format=xlsx`: the pivot of `pivotQuery` as an XLSX
389
+ * file — one flat sheet, the table a pivot's CSV is, with numbers and dates
390
+ * as cells of their type. The server's rules are `/pivot`'s; its bounds are
391
+ * the pivot's limits and `max_xlsx_rows`. `exportPivot` builds the query
392
+ * from an element, and takes its words from it.
393
+ */
394
+ exportPivot(pivotQuery: PivotQuery, options: ProviderPivotExportOptions): Promise<Blob>;
343
395
  }
344
396
 
345
397
  /** The `Planner` of the engine module, as `createHybridProvider` uses it. */
@@ -370,6 +422,12 @@ export interface ServerOptions {
370
422
  source: string;
371
423
  /** Bearer token; the server refuses without one. */
372
424
  token?: string;
425
+ /**
426
+ * Opens `GET /watch/{source}` and tells the grids on this provider with
427
+ * `opengrid-source-changed` when the server says the source changed (issue #328).
428
+ * Off by default; a server may not offer it.
429
+ */
430
+ watch?: boolean;
373
431
  }
374
432
 
375
433
  /** The engine on the main thread. */
@@ -391,7 +449,7 @@ export function createWorkerProvider(options?: {
391
449
  export function createRestProvider(options: ServerOptions): RestProvider;
392
450
 
393
451
  /** `POST /pivot/{source}` — a whole pivot in one request. */
394
- export function createPivotProvider(options: ServerOptions): Provider;
452
+ export function createPivotProvider(options: ServerOptions): PivotProvider;
395
453
 
396
454
  /** Splits each query between a remote source and the engine in the tab. */
397
455
  export function createHybridProvider(options: {
@@ -420,15 +478,30 @@ export interface ExportProgress {
420
478
  */
421
479
  export interface ExportOptions extends CsvOptions {
422
480
  /**
423
- * `"csv"` (the default), `"json"` — an array of row objects — or `"xlsx"`,
424
- * which only a provider that exports on the server (`createRestProvider`)
425
- * writes; with any other provider it is a `TypeError`.
481
+ * `"csv"` (the default), `"json"` — an array of row objects — or `"xlsx"`, a
482
+ * workbook: written by the server where the provider exports there
483
+ * (`createRestProvider`), and in the tab for any other provider by a module
484
+ * of its own that `exportRows` loads the first time (`@casoon/opengrid/xlsx/`,
485
+ * about 250 KB brotli). The tab holds the whole workbook in memory, so
486
+ * `maxRows` bounds it — 250 000 by default there — and more rows than an Excel
487
+ * sheet holds (1 048 575) is an error.
426
488
  */
427
489
  format?: "csv" | "json" | "xlsx";
428
490
  /** Rows per request; 10 000 by default, the server's `max_limit`. */
429
491
  chunkSize?: number;
430
- /** More matches than this is an error, never a truncated file; 1 000 000 by default. */
492
+ /**
493
+ * More matches than this is an error, never a truncated file; 1 000 000 by
494
+ * default, and 250 000 for an XLSX written in the tab.
495
+ */
431
496
  maxRows?: number;
497
+ /**
498
+ * Header texts by field name for CSV and XLSX, `{ city: "Address · City" }`
499
+ * (issue #353); `get_export_headers(grid)` answers them for a grid with bands.
500
+ * A column without one keeps its field name. A JSON export has no header row
501
+ * and refuses the option. The server takes each as a parameter,
502
+ * `header.<column>`.
503
+ */
504
+ headers?: Record<string, string>;
432
505
  /** Called after each piece. */
433
506
  onProgress?: (progress: ExportProgress) => void;
434
507
  /** Aborts the export: it rejects with an `AbortError` and gives no `Blob`. */
@@ -452,6 +525,64 @@ export type ProviderExportOptions = Omit<ExportOptions, "chunkSize">;
452
525
  */
453
526
  export function exportRows(provider: Provider, query: ViewQuery, options?: ExportOptions): Promise<Blob>;
454
527
 
528
+ /** A pivot query, as `POST /pivot/{source}` takes it. */
529
+ export interface PivotQuery {
530
+ source: string;
531
+ rows: string[];
532
+ columns: string[];
533
+ values: PivotMeasure[];
534
+ sort?: PivotSort[];
535
+ filter?: Record<string, unknown>;
536
+ }
537
+
538
+ /** How a pivot is exported as a workbook. Any other key is an error. */
539
+ export interface PivotExportOptions {
540
+ /** `"xlsx"`, the one format the server writes a pivot in; its CSV is `get_pivot`. */
541
+ format: "xlsx";
542
+ /** Aborts the request: it rejects with an `AbortError` and gives no `Blob`. */
543
+ signal?: AbortSignal;
544
+ }
545
+
546
+ /**
547
+ * What a provider's `exportPivot` takes: {@link PivotExportOptions}, and the
548
+ * words the server writes where the data has none. The method has a query and
549
+ * no element, so they are handed to it; the function `exportPivot` reads them
550
+ * from the element.
551
+ */
552
+ export interface ProviderPivotExportOptions extends PivotExportOptions {
553
+ /**
554
+ * `total`, `subtotal` (with `{value}`), `noValue` and `emptyValue`, and what
555
+ * a calculated measure is shown as — `shareOfRow`, `shareOfColumn`,
556
+ * `shareOfTotal`, `runningTotal`; any other key is ignored. Without them
557
+ * the server's English defaults.
558
+ */
559
+ texts?: Pick<
560
+ Texts,
561
+ | "total"
562
+ | "subtotal"
563
+ | "noValue"
564
+ | "emptyValue"
565
+ | "shareOfRow"
566
+ | "shareOfColumn"
567
+ | "shareOfTotal"
568
+ | "runningTotal"
569
+ >;
570
+ }
571
+
572
+ /**
573
+ * The pivot `host` shows as an XLSX file, written by the server: the
574
+ * element's view asked again through the provider's `exportPivot`, as one flat
575
+ * sheet — the header row and the rows of `get_pivot`'s CSV, numbers and dates
576
+ * typed, the totals and the NULL and empty groups in the element's own texts.
577
+ * A provider without `exportPivot` (the engine in the tab or a worker) is a
578
+ * `TypeError`.
579
+ */
580
+ export function exportPivot(
581
+ provider: Pick<PivotProvider, "exportPivot">,
582
+ host: HTMLElement,
583
+ options: PivotExportOptions,
584
+ ): Promise<Blob>;
585
+
455
586
  // ---------------------------------------------------------------------------
456
587
  // Errors
457
588
  // ---------------------------------------------------------------------------
@@ -550,6 +681,12 @@ export type FacetKind = "list" | "pills" | "range" | "period";
550
681
  /** A value as the wire format writes it: decimals and dates are strings. */
551
682
  export type WireValue = string | number | boolean | null;
552
683
 
684
+ /**
685
+ * Where a column is kept in place while the others scroll sideways: at the
686
+ * start of the row or at its end, by reading direction.
687
+ */
688
+ export type Pin = "start" | "end";
689
+
553
690
  /** Per-column presentation for `set_columns` — `presentation` in `connect`. */
554
691
  export interface ColumnConfig {
555
692
  /**
@@ -560,6 +697,18 @@ export interface ColumnConfig {
560
697
  title?: string;
561
698
  /** The starting width in pixels; a reader's resize leads after that. */
562
699
  width?: number;
700
+ /**
701
+ * Where the column starts pinned; the reader's own pin leads after that
702
+ * (`Alt`+`Shift`+`←`/`→` on the header, the column menu). The grid only.
703
+ */
704
+ pin?: Pin;
705
+ /**
706
+ * The band the column stands under: a header it shares with the other
707
+ * columns that name the same one. A band is always in one piece — its
708
+ * columns stand together, move inside it, and are pinned with it. The grid
709
+ * only.
710
+ */
711
+ band?: string;
563
712
  align?: "start" | "end" | "center";
564
713
  mono?: boolean;
565
714
  emphasis?: boolean;
@@ -571,6 +720,14 @@ export interface ColumnConfig {
571
720
  * its cells are announced as read-only. The grid only.
572
721
  */
573
722
  readonly?: boolean;
723
+ /**
724
+ * The labels of the keys the column stores, key → label: the cell, the
725
+ * editor, the filter row and the facets show and choose by label. The value
726
+ * stays the key — in the query, the view, events and exports — and **the
727
+ * column sorts and groups by the key, not by the label**. For a `utf8` or
728
+ * `int64` column. The grid only.
729
+ */
730
+ lookup?: Record<string | number, string>;
574
731
  }
575
732
 
576
733
  /** What `set_cell_state` says became of an edit. */
@@ -625,6 +782,23 @@ export interface FilterEntry {
625
782
  value: string;
626
783
  }
627
784
 
785
+ /**
786
+ * The nested filter of a view (`where`): conditions joined by `and` and `or`,
787
+ * in the wire form of a query's `filter` — values typed, so a number is a
788
+ * number and a decimal or a date a string. What the search expression and the
789
+ * builder dialog can write; `not` and the operator `in` are not part of it.
790
+ */
791
+ export type ViewFilter =
792
+ | { and: ViewFilter[] }
793
+ | { or: ViewFilter[] }
794
+ | {
795
+ field: string;
796
+ op: Exclude<FilterOperator, "is_null" | "is_not_null" | "is_empty" | "has_all">;
797
+ value: string | number | boolean;
798
+ }
799
+ | { field: string; op: "has_all"; value: Array<string | number> }
800
+ | { field: string; op: "is_null" | "is_not_null" | "is_empty" };
801
+
628
802
  /** A facet selection: values for `list`/`pills`, bounds for `range`/`period`. */
629
803
  export type FacetSelection =
630
804
  | { values: WireValue[] }
@@ -632,17 +806,27 @@ export type FacetSelection =
632
806
  | { from: string; to: string };
633
807
 
634
808
  /**
635
- * Sort, filters, column layout, density, grouping, aggregates and facets as
636
- * one value — as `get_view` writes it, every field present. `set_view` reads
809
+ * Sort, filters, the nested filter, column layout, density, grouping,
810
+ * aggregates and facets as one value — as `get_view` writes it, every field present. `set_view` reads
637
811
  * some fields more leniently (a missing direction is `asc`, a missing operator
638
812
  * `eq`); the types ask for the full form on purpose, so a saved view says what
639
- * it means. A saved view is this value with a name on it. The selection and
640
- * the free-text search are deliberately not part of it.
813
+ * it means. A saved view is this value with a name on it. A selection by key
814
+ * is part of it (`selected`); a selection by position and the free-text
815
+ * search are deliberately not.
641
816
  */
642
817
  export interface View {
643
818
  sort: SortKey[];
644
819
  filters: FilterEntry[];
645
- columns: { order: string[]; hidden: string[]; widths: Record<string, number> };
820
+ columns: {
821
+ order: string[];
822
+ hidden: string[];
823
+ widths: Record<string, number>;
824
+ /**
825
+ * The pins the reader changed: `none` is a pin of `set_columns` taken
826
+ * away. Leads over `set_columns`.
827
+ */
828
+ pinned: Record<string, Pin | "none">;
829
+ };
646
830
  density: Density;
647
831
  group: string[];
648
832
  /** The open groups, each as its path of keys. */
@@ -652,14 +836,46 @@ export interface View {
652
836
  /** Whether the filter row shows. */
653
837
  filterRow: boolean;
654
838
  facets: Record<string, FacetSelection>;
839
+ /**
840
+ * The keys of the selected records, where the grid selects by key (`row-key`,
841
+ * or a tree's `tree-key`). Left out while nothing is selected, and always for
842
+ * a selection by position. `set_view` asks the source which of them name a
843
+ * record before it selects; a view without the field selects nothing.
844
+ */
845
+ selected?: Array<string | number | boolean>;
846
+ /**
847
+ * The keys of the records whose detail panel is open (issue #318). Left out
848
+ * while none is. A restored view opens them as their rows load.
849
+ */
850
+ detail?: Array<string | number | boolean>;
851
+ /**
852
+ * The nested filter: the one filter with `or` across columns, and-ed onto
853
+ * the filter row's (`filters`), the facets' and the page's. Left out while
854
+ * there is none; a view without the field has none.
855
+ */
856
+ where?: ViewFilter;
655
857
  }
656
858
 
859
+ /**
860
+ * What a calculated measure shows in place of its aggregate: the cell as a
861
+ * fraction of its row's total, of its column's total or of the grand total —
862
+ * a number between 0 and 1, NULL where that total is NULL or zero — or the
863
+ * running total along the columns, which starts again in every row.
864
+ */
865
+ export type PivotCalc = "share_of_row" | "share_of_column" | "share_of_total" | "running_total";
866
+
657
867
  /** A pivot measure, as the contract writes it: `{ field: "qty", fn: "sum", as: "total" }`. */
658
868
  export interface PivotMeasure {
659
869
  /** Absent for `count`. */
660
870
  field?: string;
661
871
  fn: string;
662
872
  as: string;
873
+ /**
874
+ * Shows the measure as a calculation over the pivot's cells. A share is for
875
+ * `sum` and `count`; a running total also for `avg`, `min` and `max` over a
876
+ * number. The source refuses anything else.
877
+ */
878
+ calc?: PivotCalc;
663
879
  }
664
880
 
665
881
  /**
@@ -776,6 +992,12 @@ export type TextKey =
776
992
  | "groupSecondLevel"
777
993
  | "ungroupColumn"
778
994
  | "hideColumn"
995
+ | "hideBand"
996
+ | "bandKeep"
997
+ | "pinGroup"
998
+ | "pinNone"
999
+ | "pinStart"
1000
+ | "pinEnd"
779
1001
  | "toolbarGroup"
780
1002
  | "filterRowToggle"
781
1003
  | "densityGroup"
@@ -819,6 +1041,13 @@ export type TextKey =
819
1041
  | "pivotFilters"
820
1042
  | "pivotFilterLabel"
821
1043
  | "pivotFilterHint"
1044
+ | "pivotDrillDown"
1045
+ | "pivotShowAs"
1046
+ | "calcValue"
1047
+ | "shareOfRow"
1048
+ | "shareOfColumn"
1049
+ | "shareOfTotal"
1050
+ | "runningTotal"
822
1051
  | "treeContext"
823
1052
  | "subtreeCell"
824
1053
  | "subtreeOnly"
@@ -850,15 +1079,35 @@ export type TextKey =
850
1079
  | "queryUnknownColumn"
851
1080
  | "queryMissingValue"
852
1081
  | "queryWrongOperator"
1082
+ | "queryOr"
1083
+ | "queryUnclosed"
1084
+ | "queryUnopened"
1085
+ | "queryMissingCondition"
1086
+ | "queryMissingJoin"
1087
+ | "filterBuilder"
1088
+ | "filterBuilderJoin"
1089
+ | "filterBuilderAll"
1090
+ | "filterBuilderAny"
1091
+ | "filterBuilderCondition"
1092
+ | "filterBuilderGroup"
1093
+ | "filterBuilderAddCondition"
1094
+ | "filterBuilderAddGroup"
1095
+ | "filterBuilderEdit"
1096
+ | "filterApplied"
853
1097
  | "emptyFiltered"
854
1098
  | "emptySource"
855
1099
  | "emptyReset"
856
1100
  | "filterInvalid"
857
1101
  | "cellRequired"
858
1102
  | "selectionCleared"
1103
+ | "selectionMissing"
859
1104
  | "columnWidth"
860
1105
  | "columnMoved"
861
1106
  | "columnAtEdge"
1107
+ | "columnPinnedStart"
1108
+ | "columnPinnedEnd"
1109
+ | "columnUnpinned"
1110
+ | "pinsReleased"
862
1111
  | "columnHidden"
863
1112
  | "columnShown"
864
1113
  | "columnsGroup"
@@ -902,6 +1151,22 @@ export type TextKey =
902
1151
  | "undoAdded"
903
1152
  | "redoAdded"
904
1153
  | "undoPaste"
1154
+ | "undoRecord"
1155
+ | "redoRecord"
1156
+ | "recordTitle"
1157
+ | "recordSave"
1158
+ | "recordDone"
1159
+ | "recordNothing"
1160
+ | "rangeSize"
1161
+ | "rangeCopied"
1162
+ | "rangeUnloaded"
1163
+ | "sourceChanged"
1164
+ | "sourceRefresh"
1165
+ | "detailShow"
1166
+ | "detailHide"
1167
+ | "detailPanel"
1168
+ | "detailShown"
1169
+ | "detailHidden"
905
1170
  | "redoPaste"
906
1171
  | "undoNothing"
907
1172
  | "redoNothing";
@@ -920,11 +1185,10 @@ export type Texts = Partial<Record<TextKey, string>> & {
920
1185
  // ---------------------------------------------------------------------------
921
1186
 
922
1187
  /**
923
- * `opengrid-selection-change`: logical row numbers, ascending. In a tree
924
- * (`tree` set) `rows` are the display positions of the selected nodes shown,
925
- * `keys` names every selected node by its key and `count` counts them.
1188
+ * `opengrid-selection-change` of a grid that selects **by position** — no
1189
+ * `row-key`, no tree: logical row numbers, ascending.
926
1190
  */
927
- export interface SelectionChangeDetail {
1191
+ export interface SelectionByPosition {
928
1192
  rows: number[];
929
1193
  /**
930
1194
  * The same rows as runs of adjacent ones, ascending, both ends inclusive:
@@ -932,10 +1196,28 @@ export interface SelectionChangeDetail {
932
1196
  */
933
1197
  ranges: Array<{ from: number; to: number }>;
934
1198
  count: number;
935
- /** In a tree only: the selected nodes' keys, the shown ones first. */
936
- keys?: unknown[];
1199
+ keys?: undefined;
937
1200
  }
938
1201
 
1202
+ /**
1203
+ * `opengrid-selection-change` of a grid that selects **by key** — with
1204
+ * `row-key` (grouped or not), or a tree: the keys of the selected records, in
1205
+ * no particular order (a tree's: the nodes shown first), and their number.
1206
+ * There are no positions: a key names a record wherever it sits, loaded or not.
1207
+ */
1208
+ export interface SelectionByKey {
1209
+ count: number;
1210
+ keys: unknown[];
1211
+ rows?: undefined;
1212
+ ranges?: undefined;
1213
+ }
1214
+
1215
+ /**
1216
+ * `opengrid-selection-change`: one of the two, by what the grid's selection
1217
+ * names. `detail.keys` (or `"keys" in detail`) narrows it.
1218
+ */
1219
+ export type SelectionChangeDetail = SelectionByPosition | SelectionByKey;
1220
+
939
1221
  /** `opengrid-cell-change`: everything a page needs to persist an edit. */
940
1222
  export interface CellChangeDetail {
941
1223
  row: number;
@@ -955,6 +1237,31 @@ export interface CellChangeDetail {
955
1237
  /** What a validator says about a value, or `null` for nothing. */
956
1238
  export type Finding = { level: "warning" | "error"; message: string } | null | undefined;
957
1239
  /** `value` is the text in the editor, `row` the record as loaded, by field name. */
1240
+ /** What `set_cell_templates` gives a function (issue #317). */
1241
+ export interface CellTemplateArgument {
1242
+ /** The cell's value as it is on the wire. */
1243
+ value: WireValue;
1244
+ /** The text the column's format makes of it. */
1245
+ text: string;
1246
+ /** The record as loaded, by field name. */
1247
+ row: Record<string, WireValue>;
1248
+ /** The record's `row-key` value; `undefined` without one. */
1249
+ key: WireValue | undefined;
1250
+ }
1251
+
1252
+ /**
1253
+ * The panel under an open row (issue #318): the record as the grid holds it and
1254
+ * its `row-key` value. A node, or a string shown as text; `null` or
1255
+ * `undefined`: this record has no panel.
1256
+ */
1257
+ export type DetailRenderer = (
1258
+ record: Record<string, WireValue>,
1259
+ key: WireValue,
1260
+ ) => Node | string | null | undefined;
1261
+
1262
+ /** A node, or a string shown as text; `null` or `undefined` leaves the cell's text. */
1263
+ export type CellTemplate = (cell: CellTemplateArgument) => Node | string | null | undefined;
1264
+
958
1265
  export type Validator = (value: string, row: Record<string, WireValue>) => Finding;
959
1266
  /** A validator that may block the commit on an `error`. */
960
1267
  export interface ValidatorRule {
@@ -977,6 +1284,28 @@ export interface RowActionDetail {
977
1284
  key?: WireValue;
978
1285
  }
979
1286
 
1287
+ /**
1288
+ * `opengrid-drill-down`: a value of an `<opengrid-pivot>` with `drill-down`
1289
+ * was pressed (issue #330). The page shows the rows.
1290
+ */
1291
+ export interface DrillDownDetail {
1292
+ /**
1293
+ * The rows behind the cell, as the wire writes a query. `filter` is the
1294
+ * pivot's own filter and-ed with one clause per dimension the cell lies in
1295
+ * — a NULL group as `is_null`, the empty string as `eq ""` — and absent
1296
+ * when nothing restricts the rows.
1297
+ */
1298
+ query: { source: string; filter?: Record<string, unknown> };
1299
+ /** The row group's keys, down to the row's level; `[]` for the grand total. */
1300
+ row: WireValue[];
1301
+ /** The column group's keys, one per column dimension. */
1302
+ column: WireValue[];
1303
+ /** The measure's alias. */
1304
+ measure: string;
1305
+ /** The cell's value, as the answer carried it. */
1306
+ value: WireValue;
1307
+ }
1308
+
980
1309
  /** `opengrid-row-add`: a record was typed into the new row (issue #183). */
981
1310
  export interface RowAddDetail {
982
1311
  /** The values by field name, in the wire notation of a result. */
@@ -996,6 +1325,27 @@ export interface SourceReplacedDetail {
996
1325
  name: string;
997
1326
  }
998
1327
 
1328
+ /**
1329
+ * `opengrid-source-changed`: the source behind the grid changed (issue #328).
1330
+ * **Cancelable**: `preventDefault()` keeps the grid's notice and "Refresh" button
1331
+ * from showing; call `refresh(grid)` when it suits. Fired on the grid only; it
1332
+ * does not bubble.
1333
+ */
1334
+ export interface SourceChangedDetail {
1335
+ name: string | undefined;
1336
+ }
1337
+
1338
+ /**
1339
+ * `opengrid-detail-toggle`: a row's detail panel opened or closed (issue #318).
1340
+ */
1341
+ export interface DetailToggleDetail {
1342
+ /** The record's `row-key` value. */
1343
+ key: WireValue;
1344
+ /** The row in the result. */
1345
+ row: number;
1346
+ open: boolean;
1347
+ }
1348
+
999
1349
  /** `opengrid-bulk-change`: one value for the selected rows (issue #187). */
1000
1350
  export interface BulkChangeDetail {
1001
1351
  /** The `row-key` values of the selected records. */
@@ -1004,6 +1354,13 @@ export interface BulkChangeDetail {
1004
1354
  value: string;
1005
1355
  }
1006
1356
 
1357
+ /** `opengrid-record-open`: the reader asked for a record as a form (issue #325). Cancelable. */
1358
+ export interface RecordOpenDetail {
1359
+ /** The record's `row-key` value. */
1360
+ key: WireValue;
1361
+ row: number;
1362
+ }
1363
+
1007
1364
  /** `opengrid-paste`: a pasted block was applied (issue #184). */
1008
1365
  export interface PasteDetail {
1009
1366
  /** One per cell of an existing row. */
@@ -1058,8 +1415,14 @@ export interface OpengridEventMap {
1058
1415
  "opengrid-row-add": CustomEvent<RowAddDetail>;
1059
1416
  "opengrid-paste": CustomEvent<PasteDetail>;
1060
1417
  "opengrid-bulk-change": CustomEvent<BulkChangeDetail>;
1418
+ /** Cancelable: `preventDefault()` keeps the grid from opening its record form. */
1419
+ "opengrid-record-open": CustomEvent<RecordOpenDetail>;
1420
+ /** On `<opengrid-pivot>` with `drill-down`. */
1421
+ "opengrid-drill-down": CustomEvent<DrillDownDetail>;
1061
1422
  /** Dispatched by `loader.js` on the grid; it does not bubble. */
1062
1423
  "opengrid-source-replaced": CustomEvent<SourceReplacedDetail>;
1424
+ "opengrid-source-changed": CustomEvent<SourceChangedDetail>;
1425
+ "opengrid-detail-toggle": CustomEvent<DetailToggleDetail>;
1063
1426
  }
1064
1427
 
1065
1428
  // ---------------------------------------------------------------------------
@@ -1070,7 +1433,7 @@ export interface OpengridEventMap {
1070
1433
  * The attributes of `<opengrid-grid>`, as strings the way HTML has them — for
1071
1434
  * adapters and JSX typings to build on. For
1072
1435
  * the boolean ones — `selection`, `toolbar`, `search`, `facets`,
1073
- * `column-menu`, `add-row` — presence is what counts, whatever the value.
1436
+ * `column-menu`, `filter-builder`, `add-row` — presence is what counts, whatever the value.
1074
1437
  */
1075
1438
  export interface OpengridGridAttributes {
1076
1439
  label?: string;
@@ -1079,6 +1442,11 @@ export interface OpengridGridAttributes {
1079
1442
  "window-size"?: string;
1080
1443
  "page-size"?: string;
1081
1444
  mode?: Mode;
1445
+ /**
1446
+ * The page's filter, as the wire's JSON — `{"field":"country","op":"eq","value":"DE"}` —
1447
+ * and-ed onto every query the grid sends. Not the reader's and not in the view.
1448
+ */
1449
+ filter?: string;
1082
1450
  "group-by"?: string;
1083
1451
  /** The field holding a row's parent key: the rows show as a tree. */
1084
1452
  tree?: string;
@@ -1090,6 +1458,8 @@ export interface OpengridGridAttributes {
1090
1458
  facets?: string;
1091
1459
  toolbar?: string;
1092
1460
  "column-menu"?: string;
1461
+ /** *Advanced filter* in the toolbar: the builder of the nested filter (`where` in the view). */
1462
+ "filter-builder"?: string;
1093
1463
  /** An empty row after the last one to type a new record into (`opengrid-row-add`). */
1094
1464
  "add-row"?: string;
1095
1465
  selection?: string;
@@ -1126,6 +1496,8 @@ export interface OpengridPivotAttributes {
1126
1496
  measures?: string;
1127
1497
  /** The filter on the raw rows, as the wire's JSON: `{"field":"country","op":"eq","value":"DE"}`. */
1128
1498
  filter?: string;
1499
+ /** Makes every value a button that fires `opengrid-drill-down`; presence is what counts. */
1500
+ "drill-down"?: string;
1129
1501
  theme?: Theme;
1130
1502
  }
1131
1503