occulite-ui 0.0.0-stage → 0.2.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 (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +290 -2
  3. package/THIRD_PARTY_NOTICES.md +36 -0
  4. package/dist/clipboard.d.ts +26 -0
  5. package/dist/clipboard.js +70 -0
  6. package/dist/components/ContextMenu.svelte +158 -0
  7. package/dist/components/ContextMenu.svelte.d.ts +14 -0
  8. package/dist/components/DataTable.svelte +1990 -0
  9. package/dist/components/DataTable.svelte.d.ts +154 -0
  10. package/dist/components/Dialog.svelte +420 -0
  11. package/dist/components/Dialog.svelte.d.ts +55 -0
  12. package/dist/components/GithubLink.svelte +74 -0
  13. package/dist/components/GithubLink.svelte.d.ts +16 -0
  14. package/dist/components/Header.svelte +196 -0
  15. package/dist/components/Header.svelte.d.ts +42 -0
  16. package/dist/components/Icon.svelte +51 -0
  17. package/dist/components/Icon.svelte.d.ts +12 -0
  18. package/dist/components/LanguageSwitch.svelte +63 -0
  19. package/dist/components/LanguageSwitch.svelte.d.ts +17 -0
  20. package/dist/components/Loader.svelte +65 -0
  21. package/dist/components/Loader.svelte.d.ts +9 -0
  22. package/dist/components/MultiSelect.svelte +467 -0
  23. package/dist/components/MultiSelect.svelte.d.ts +28 -0
  24. package/dist/components/Notices.svelte +146 -0
  25. package/dist/components/Notices.svelte.d.ts +16 -0
  26. package/dist/components/PrimaryToolbarButton.svelte +189 -0
  27. package/dist/components/PrimaryToolbarButton.svelte.d.ts +34 -0
  28. package/dist/components/Tabs.svelte +118 -0
  29. package/dist/components/Tabs.svelte.d.ts +16 -0
  30. package/dist/components/ThemeSwitch.svelte +46 -0
  31. package/dist/components/ThemeSwitch.svelte.d.ts +11 -0
  32. package/dist/components/Toolbar.svelte +57 -0
  33. package/dist/components/Toolbar.svelte.d.ts +11 -0
  34. package/dist/components/ToolbarButton.svelte +126 -0
  35. package/dist/components/ToolbarButton.svelte.d.ts +22 -0
  36. package/dist/components/Tooltip.svelte +106 -0
  37. package/dist/components/Tooltip.svelte.d.ts +31 -0
  38. package/dist/components/TooltipBubble.svelte +65 -0
  39. package/dist/components/TooltipBubble.svelte.d.ts +18 -0
  40. package/dist/components/contextMenu.d.ts +19 -0
  41. package/dist/components/contextMenu.js +6 -0
  42. package/dist/components/dialogGeometry.d.ts +91 -0
  43. package/dist/components/dialogGeometry.js +140 -0
  44. package/dist/components/index.d.ts +22 -0
  45. package/dist/components/index.js +22 -0
  46. package/dist/components/multiSelect.d.ts +27 -0
  47. package/dist/components/multiSelect.js +26 -0
  48. package/dist/components/navigation.d.ts +34 -0
  49. package/dist/components/navigation.js +19 -0
  50. package/dist/components/tooltip.d.ts +29 -0
  51. package/dist/components/tooltip.js +27 -0
  52. package/dist/css/app.css +3 -0
  53. package/dist/css/base.css +84 -0
  54. package/dist/css/tokens.css +170 -0
  55. package/dist/dialog/index.d.ts +6 -0
  56. package/dist/dialog/index.js +6 -0
  57. package/dist/embedding/ShellEmbedding.svelte.d.ts +27 -0
  58. package/dist/embedding/ShellEmbedding.svelte.js +79 -0
  59. package/dist/embedding/constants.d.ts +23 -0
  60. package/dist/embedding/constants.js +54 -0
  61. package/dist/embedding/index.d.ts +2 -0
  62. package/dist/embedding/index.js +2 -0
  63. package/dist/externalLink.d.ts +15 -0
  64. package/dist/externalLink.js +20 -0
  65. package/dist/format.d.ts +6 -0
  66. package/dist/format.js +16 -0
  67. package/dist/i18n/i18n.svelte.d.ts +112 -0
  68. package/dist/i18n/i18n.svelte.js +211 -0
  69. package/dist/i18n/index.d.ts +3 -0
  70. package/dist/i18n/index.js +3 -0
  71. package/dist/i18n/messages.d.ts +9 -0
  72. package/dist/i18n/messages.js +58 -0
  73. package/dist/i18n/translator.d.ts +65 -0
  74. package/dist/i18n/translator.js +99 -0
  75. package/dist/icons/index.d.ts +17 -0
  76. package/dist/icons/index.js +11 -0
  77. package/dist/index.d.ts +16 -0
  78. package/dist/index.js +16 -0
  79. package/dist/notices/NoticesStore.svelte.d.ts +64 -0
  80. package/dist/notices/NoticesStore.svelte.js +127 -0
  81. package/dist/notices/index.d.ts +1 -0
  82. package/dist/notices/index.js +1 -0
  83. package/dist/storage.d.ts +11 -0
  84. package/dist/storage.js +27 -0
  85. package/dist/table/LocalColumnWidths.svelte.d.ts +32 -0
  86. package/dist/table/LocalColumnWidths.svelte.js +91 -0
  87. package/dist/table/columnMeasure.d.ts +24 -0
  88. package/dist/table/columnMeasure.js +82 -0
  89. package/dist/table/columnWidths.d.ts +60 -0
  90. package/dist/table/columnWidths.js +86 -0
  91. package/dist/table/dataTableContext.d.ts +26 -0
  92. package/dist/table/dataTableContext.js +16 -0
  93. package/dist/table/index.d.ts +6 -0
  94. package/dist/table/index.js +6 -0
  95. package/dist/table/metrics.d.ts +10 -0
  96. package/dist/table/metrics.js +10 -0
  97. package/dist/table/tableModel.d.ts +306 -0
  98. package/dist/table/tableModel.js +437 -0
  99. package/dist/theme/choices.d.ts +8 -0
  100. package/dist/theme/choices.js +6 -0
  101. package/dist/theme/index.d.ts +2 -0
  102. package/dist/theme/index.js +2 -0
  103. package/dist/theme/theme.svelte.d.ts +60 -0
  104. package/dist/theme/theme.svelte.js +108 -0
  105. package/package.json +137 -4
@@ -0,0 +1,1990 @@
1
+ <script lang="ts" generics="T">
2
+ import {untrack, type Snippet} from 'svelte';
3
+
4
+ import {copyText} from '../clipboard.js';
5
+ import {t as kitT} from '../i18n/i18n.svelte.js';
6
+ import type {MessageParams} from '../i18n/translator.js';
7
+ import {fullText, isTruncated, measureNaturalWidths} from '../table/columnMeasure.js';
8
+ import {
9
+ clampColumnWidth,
10
+ fitColumnWidth,
11
+ isResizable,
12
+ MIN_COLUMN_WIDTH,
13
+ minimumColumnWidth,
14
+ RESIZE_KEY_STEP,
15
+ type ColumnWidths,
16
+ } from '../table/columnWidths.js';
17
+ import ContextMenu from './ContextMenu.svelte';
18
+ import type {ContextMenuItem} from './contextMenu.js';
19
+ import {getDataTableEnvironment} from '../table/dataTableContext.js';
20
+ import {ROW_HEIGHT} from '../table/metrics.js';
21
+ import {
22
+ buildRows,
23
+ cellText,
24
+ groupSpans,
25
+ hasActiveFilter,
26
+ isFilterable,
27
+ isSortable,
28
+ layoutWidths,
29
+ nextSelection,
30
+ sizedTemplate,
31
+ tableLayout,
32
+ visibleWindow,
33
+ type DataTableColumn,
34
+ type DataTableColumnGroup,
35
+ type FlatRow,
36
+ type SortState,
37
+ } from '../table/tableModel.js';
38
+ import {TOOLTIP_DELAY_MS, type TooltipAnchor} from './tooltip.js';
39
+ import TooltipBubble from './TooltipBubble.svelte';
40
+
41
+ interface Props {
42
+ rows: T[];
43
+ columns: DataTableColumn<T>[];
44
+ /**
45
+ * Header cells spanning several columns, in a row above the column labels (jqGrid's
46
+ * `setGroupHeaders`): the Funk grid puts every BidCos interface over its own columns.
47
+ */
48
+ columnGroups?: DataTableColumnGroup[] | undefined;
49
+ /**
50
+ * What the rows belong to - the interface, in every grid of this app. When it changes the
51
+ * column filters are cleared and the body scrolls to the top: a filter typed for one
52
+ * interface's addresses hid every device of the next one while the count still said how
53
+ * many there were.
54
+ */
55
+ scope?: string | undefined;
56
+ /** Stable identity of a row - the address, in every grid of this app. */
57
+ getId: (row: T) => string;
58
+ /** Sub-rows of a row; a device's channels. Absent means no expander column. */
59
+ subRows?: ((row: T) => readonly T[]) | undefined;
60
+ /**
61
+ * The columns of the sub-rows, when they differ from the parent's - the channel sub-grid of
62
+ * 2.x had its own (INDEX, TYPE, DIRECTION, roles, ...). Given, the sub-rows are drawn with
63
+ * these columns under their own label row; absent, a channel shares the device columns.
64
+ */
65
+ subColumns?: DataTableColumn<T>[] | undefined;
66
+ /** Row height in pixels; the virtualiser needs it to be uniform. `--hmm-row-height`. */
67
+ rowHeight?: number;
68
+ /** Fixed body height. Without one the body fills its parent and is measured. */
69
+ height?: number | undefined;
70
+ overscan?: number;
71
+ /** Show the per-column filter row under the column labels, as the 2.x filter toolbar did. */
72
+ columnFilterRow?: boolean;
73
+ caption?: string | undefined;
74
+ /** What the body says when there are no rows at all. */
75
+ emptyText?: string;
76
+ /** What the body says when there are rows but the filters hide every one of them. */
77
+ noMatchText?: string | undefined;
78
+ /** The button under that text; it empties the column filters. */
79
+ clearFilterLabel?: string | undefined;
80
+ /** Replaces `countText` while a filter is active: "Showing 0 of 31". */
81
+ showingText?: ((shown: number, total: number) => string) | undefined;
82
+ filterLabel?: string | undefined;
83
+ /**
84
+ * The tab's actions - buttons, selection controls - drawn at the left of the header band.
85
+ * A tab has no toolbar strip of its own above the grid any more.
86
+ */
87
+ toolbar?: Snippet | undefined;
88
+ /** Accessible name of that group of actions; the caption when none is given. */
89
+ toolbarLabel?: string | undefined;
90
+ /** Right of the band, before the count: what a tab has to say about its own state. */
91
+ status?: Snippet | undefined;
92
+ /** Right of the band: "4 Geräte". */
93
+ countText?: string | undefined;
94
+ selected?: string[];
95
+ expanded?: string[];
96
+ /**
97
+ * The needle every filterable column is searched for, on top of the per-column fields.
98
+ *
99
+ * No control of the table draws it. It exists because a page may set it from outside: a link
100
+ * that opens another page already narrowed to one item, where no per-column field means
101
+ * "this column **or** that one".
102
+ */
103
+ filter?: string;
104
+ /**
105
+ * Draw a search field in the header band that edits {@link filter}: one needle over every
106
+ * filterable column, beside - or, with `columnFilterRow={false}`, instead of - the fields
107
+ * of the single columns.
108
+ */
109
+ searchBox?: boolean;
110
+ /** The search field's placeholder and name; the kit's "Filter all columns" by default. */
111
+ searchLabel?: string | undefined;
112
+ /**
113
+ * What the fields of the filter row hold, by column key. Bindable, like {@link filter} and
114
+ * {@link sort}: an app that keeps the three in its address sets them from it and writes them
115
+ * back when they change - a reload, a link and the back button then show the same rows.
116
+ */
117
+ columnFilters?: Record<string, string>;
118
+ sort?: SortState | undefined;
119
+ /** The user changed the sorting: a click on a column label. `undefined` is "as the rows came". */
120
+ onsortchange?: ((sort: SortState | undefined) => void) | undefined;
121
+ /** The user changed a filter: typed into a field, chose from a list, cleared them. */
122
+ onfilterchange?: ((filters: {filter: string; columnFilters: Record<string, string>}) => void) | undefined;
123
+ /**
124
+ * The locale text is sorted in. German by default (`DEFAULT_COLLATION`), which is the same
125
+ * order for English text, so a table has one order on every machine.
126
+ */
127
+ locale?: string | undefined;
128
+ /** The first choice of a column's filter list, which filters nothing; the kit's "All". */
129
+ allLabel?: string | undefined;
130
+ /** A test id for a row, where a page's tests name its rows. */
131
+ rowTestId?: ((row: T) => string | undefined) | undefined;
132
+ /** Extra classes for a row - a row the page draws paler. The rules for them are the page's. */
133
+ rowClass?: ((row: T) => string | undefined) | undefined;
134
+ /** Double click, or Enter on the focused row. */
135
+ onactivate?: ((row: T) => void) | undefined;
136
+ /** Right click on a row; the table has already called `preventDefault()`. */
137
+ onrowcontextmenu?: ((row: T, event: MouseEvent) => void) | undefined;
138
+ /**
139
+ * The column whose cell renames its row on a double click - the name, in every grid
140
+ * of this app. A double click anywhere else on the row still goes to `onactivate`.
141
+ */
142
+ renameColumn?: string;
143
+ /** Whether a row can be renamed at all; absent, every row can. The `:0` channel cannot. */
144
+ canRename?: ((row: T) => boolean) | undefined;
145
+ /**
146
+ * Opens the rename dialog for a row - on a double click on its name cell, on F2, and
147
+ * on Enter where the table has no `onactivate`. Absent, the table renames nothing.
148
+ */
149
+ onrename?: ((row: T) => void) | undefined;
150
+ /** Draws one cell; without it the cell is the column's text value. */
151
+ cell?: Snippet<[T, DataTableColumn<T>, FlatRow<T>]> | undefined;
152
+ /**
153
+ * The name the column widths of this table are kept under, per profile.
154
+ * A storage key rather than a test id, so it stays the same when a test id is renamed.
155
+ * Without one - or outside the app - the widths last as long as the table does.
156
+ */
157
+ tableId?: string | undefined;
158
+ /**
159
+ * The name the widths of the columns only the sub-grid has are kept under -
160
+ * `devices-channels`, `radio-peers`. Every expanded sub-grid of the table is drawn on the
161
+ * one template, so one width applies to all of them. Without one they last as long as the
162
+ * table does.
163
+ */
164
+ subTableId?: string | undefined;
165
+ testId?: string | undefined;
166
+ }
167
+
168
+ let {
169
+ rows,
170
+ columns,
171
+ columnGroups = undefined,
172
+ scope = undefined,
173
+ getId,
174
+ subRows = undefined,
175
+ subColumns = undefined,
176
+ rowHeight = ROW_HEIGHT,
177
+ height = undefined,
178
+ overscan = 6,
179
+ columnFilterRow = true,
180
+ caption = undefined,
181
+ emptyText = '',
182
+ noMatchText: noMatchTextProp = undefined,
183
+ clearFilterLabel: clearFilterLabelProp = undefined,
184
+ showingText = undefined,
185
+ filterLabel: filterLabelProp = undefined,
186
+ toolbar = undefined,
187
+ toolbarLabel = undefined,
188
+ status = undefined,
189
+ countText = undefined,
190
+ selected = $bindable([]),
191
+ expanded = $bindable([]),
192
+ filter = $bindable(''),
193
+ searchBox = false,
194
+ searchLabel: searchLabelProp = undefined,
195
+ columnFilters = $bindable({}),
196
+ sort = $bindable(undefined),
197
+ onsortchange = undefined,
198
+ onfilterchange = undefined,
199
+ locale = undefined,
200
+ allLabel: allLabelProp = undefined,
201
+ rowTestId = undefined,
202
+ rowClass = undefined,
203
+ onactivate = undefined,
204
+ onrowcontextmenu = undefined,
205
+ renameColumn = 'name',
206
+ canRename = undefined,
207
+ onrename = undefined,
208
+ cell = undefined,
209
+ tableId = undefined,
210
+ subTableId = undefined,
211
+ testId = undefined,
212
+ }: Props = $props();
213
+
214
+ /** The app's column-width store and translation; absent, the kit's own catalogue speaks. */
215
+ const environment = getDataTableEnvironment();
216
+
217
+ function t(key: string, params: MessageParams = {}): string {
218
+ return environment?.t === undefined ? kitT(key, params) : environment.t(key, params);
219
+ }
220
+
221
+ // the table's own words, read reactively so a language switch re-renders them
222
+ const noMatchText = $derived(noMatchTextProp ?? t('No row matches the filter'));
223
+ const clearFilterLabel = $derived(clearFilterLabelProp ?? t('Clear filter'));
224
+ const filterLabel = $derived(filterLabelProp ?? t('Filter'));
225
+ const searchLabel = $derived(searchLabelProp ?? t('Filter all columns'));
226
+ const allLabel = $derived(allLabelProp ?? t('All'));
227
+
228
+ let scrollTop = $state(0);
229
+ let measuredHeight = $state(0);
230
+ let focusIndex = $state(0);
231
+ /**
232
+ * Width of the body's vertical scrollbar. The head and the filter row are siblings of the
233
+ * scrolling body, so without this the proportional columns of the head would be a scrollbar
234
+ * wider than the columns of the rows as soon as a device is expanded and the body scrolls.
235
+ */
236
+ let gutter = $state(0);
237
+ let anchorId = $state<string | undefined>(undefined);
238
+ let viewport = $state<HTMLDivElement | undefined>(undefined);
239
+ let root = $state<HTMLDivElement | undefined>(undefined);
240
+ let groupStrip = $state<HTMLDivElement | undefined>(undefined);
241
+ let headStrip = $state<HTMLDivElement | undefined>(undefined);
242
+ let filterStrip = $state<HTMLDivElement | undefined>(undefined);
243
+
244
+ const visibleColumns = $derived(columns.filter((column) => column.hidden !== true));
245
+ const visibleSubColumns = $derived((subColumns ?? columns).filter((column) => column.hidden !== true));
246
+ const hasExpander = $derived(subRows !== undefined);
247
+ /**
248
+ * One template for the whole table. The head, the filter row, the device rows and the
249
+ * channel sub-grid all sit on the same tracks, so a column never moves when a device is
250
+ * expanded and the sub-grid stands under the columns it belongs to.
251
+ *
252
+ * The layout - which column sits on which track - does not depend on the widths, so a drag
253
+ * never re-runs anything in a cell; only the template below changes.
254
+ */
255
+ const layout = $derived(tableLayout(columns, subColumns, hasExpander));
256
+
257
+ /** The widths the user gave this table and kept. */
258
+ let localWidths = $state.raw<ColumnWidths>({});
259
+ /** The same for the columns only the sub-grid has, when there is no store for them. */
260
+ let localSubWidths = $state.raw<ColumnWidths>({});
261
+ /** The width of the column under the pointer while it is dragged; stored when it is let go. */
262
+ let draft = $state.raw<{key: string; width: number} | undefined>(undefined);
263
+ const storedWidths = $derived.by((): ColumnWidths => {
264
+ const store = environment?.columnWidths;
265
+ return tableId === undefined || store === undefined ? localWidths : store.widths(tableId);
266
+ });
267
+ const storedSubWidths = $derived.by((): ColumnWidths => {
268
+ const store = environment?.columnWidths;
269
+ return subTableId === undefined || store === undefined ? localSubWidths : store.widths(subTableId);
270
+ });
271
+ const hasUserWidths = $derived(Object.keys(storedWidths).length > 0);
272
+ const hasSubWidths = $derived(Object.keys(storedSubWidths).length > 0);
273
+ /**
274
+ * The tracks only the sub-grid has. Their handles are in the sub-grid's label rows and
275
+ * their widths are kept under `subTableId`; every other column is sized from the head.
276
+ */
277
+ const subKeys = $derived(new Set(layout.subKeys));
278
+ /**
279
+ * Those columns leave a gap in the head (the Funk tab's ← dBm / → dBm between ADDRESS and
280
+ * TYPE). The head gets their handle as well, over the gap, so they can be sized while no row is
281
+ * expanded; the width is the sub-grid's, whichever of the two handles set it.
282
+ */
283
+ const subOnlyColumns = $derived(
284
+ visibleSubColumns.filter((column) => subKeys.has(column.key) && isResizable(column)),
285
+ );
286
+ /**
287
+ * The template with the user's widths in it. It is set once, as a custom property on the grid,
288
+ * and every row reads it from CSS: a pointer move during a drag changes one style attribute,
289
+ * not one per rendered row - a sub-grid's label row included.
290
+ */
291
+ const sized = $derived.by(() => {
292
+ const widths = layoutWidths(layout, storedWidths, storedSubWidths);
293
+ return sizedTemplate(layout, draft === undefined ? widths : {...widths, [draft.key]: draft.width});
294
+ });
295
+ const spans = $derived(groupSpans(columnGroups ?? [], columns, layout));
296
+ const expandedSet = $derived(new Set(expanded));
297
+ /**
298
+ * One header band per table: the actions and the filter
299
+ * box on the left, what the tab has to say and the row count on the right, the column labels in
300
+ * the row underneath. It is part of the head, so it stays put while the body scrolls.
301
+ */
302
+ const hasBand = $derived(
303
+ caption !== undefined || toolbar !== undefined || status !== undefined || countText !== undefined || searchBox,
304
+ );
305
+ const selectedSet = $derived(new Set(selected));
306
+
307
+ const flat = $derived(
308
+ buildRows<T>({
309
+ rows,
310
+ columns,
311
+ getId,
312
+ children: subRows,
313
+ expanded: expandedSet,
314
+ globalFilter: filter,
315
+ columnFilters,
316
+ sort,
317
+ locale,
318
+ subColumns,
319
+ subHeader: subColumns !== undefined,
320
+ }),
321
+ );
322
+
323
+ const bodyHeight = $derived(height ?? measuredHeight);
324
+ const window_ = $derived(visibleWindow(flat.length, scrollTop, bodyHeight, rowHeight, overscan));
325
+ const windowRows = $derived(flat.slice(window_.start, window_.end));
326
+
327
+ const filterActive = $derived(hasActiveFilter(filter, columnFilters));
328
+ /** Top-level rows left after the filters - what "Showing n of m" counts. */
329
+ const shownCount = $derived(flat.filter((entry) => entry.depth === 0).length);
330
+ /** Rows exist, the filters hide all of them: the count and the empty text must say so. */
331
+ const hiddenByFilter = $derived(filterActive && rows.length > 0);
332
+
333
+ function clearFilters(): void {
334
+ columnFilters = {};
335
+ // the search field is the table's own: what was typed into it is cleared with the rest. A
336
+ // needle a page set from outside, with no field of the table for it, stays the page's.
337
+ if (searchBox) {
338
+ filter = '';
339
+ }
340
+ }
341
+
342
+ function filtersChanged(): void {
343
+ onfilterchange?.({filter, columnFilters});
344
+ }
345
+
346
+ function setColumnFilter(key: string, value: string): void {
347
+ const next = {...columnFilters};
348
+ if (value === '') {
349
+ // no entry rather than an empty one: what an app writes into its address stays short
350
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete -- a record by column key
351
+ delete next[key];
352
+ } else {
353
+ next[key] = value;
354
+ }
355
+ columnFilters = next;
356
+ filtersChanged();
357
+ }
358
+
359
+ function setSearch(value: string): void {
360
+ filter = value;
361
+ filtersChanged();
362
+ }
363
+
364
+ // The scope is the interface; a filter belongs to the rows it was typed for.
365
+ let lastScope = untrack(() => scope);
366
+ $effect(() => {
367
+ if (scope === lastScope) {
368
+ return;
369
+ }
370
+ lastScope = scope;
371
+ clearFilters();
372
+ // The filter set from outside is the one a link uses to open another page on a
373
+ // channel. It names an address of the interface it was set for, so it hides every row of
374
+ // the next one - the same trap as the column filters, one prop further out.
375
+ filter = '';
376
+ if (viewport) {
377
+ viewport.scrollTop = 0;
378
+ scrollTop = 0;
379
+ }
380
+ });
381
+
382
+ $effect(() => {
383
+ const element = viewport;
384
+ if (!element) {
385
+ return;
386
+ }
387
+ const measure = (): void => {
388
+ if (height === undefined) {
389
+ measuredHeight = element.clientHeight;
390
+ }
391
+ gutter = element.offsetWidth - element.clientWidth;
392
+ };
393
+ measure();
394
+ const observer = new ResizeObserver(measure);
395
+ observer.observe(element);
396
+ return () => {
397
+ observer.disconnect();
398
+ };
399
+ });
400
+
401
+ /**
402
+ * The body is the only part that scrolls. When the widths add up to more than the window it
403
+ * scrolls sideways too, and the group row, the labels and the filter fields have to follow it
404
+ * or they would stand over the wrong columns - moved by a transform on those three elements
405
+ * alone, and only while there is something to move.
406
+ */
407
+ function onBodyScroll(element: HTMLDivElement): void {
408
+ scrollTop = element.scrollTop;
409
+ const shift = element.scrollLeft === 0 ? '' : `translateX(${String(-element.scrollLeft)}px)`;
410
+ for (const strip of [groupStrip, headStrip, filterStrip]) {
411
+ if (strip && strip.style.transform !== shift) {
412
+ strip.style.transform = shift;
413
+ }
414
+ }
415
+ forgetTooltip();
416
+ // "Copied" stood under a button that has moved on
417
+ clearCopied();
418
+ }
419
+
420
+ function toggleSort(column: DataTableColumn<T>): void {
421
+ if (!isSortable(column)) {
422
+ return;
423
+ }
424
+ if (sort?.key !== column.key) {
425
+ sort = {key: column.key, direction: 'asc'};
426
+ } else if (sort.direction === 'asc') {
427
+ sort = {key: column.key, direction: 'desc'};
428
+ } else {
429
+ sort = undefined;
430
+ }
431
+ onsortchange?.(sort);
432
+ }
433
+
434
+ function toggleExpanded(id: string): void {
435
+ expanded = expandedSet.has(id) ? expanded.filter((entry) => entry !== id) : [...expanded, id];
436
+ }
437
+
438
+ function selectRow(row: FlatRow<T>, modifiers: {ctrl?: boolean; shift?: boolean}): void {
439
+ if (row.kind === 'header') {
440
+ return;
441
+ }
442
+ const next = nextSelection(flat, selected, anchorId, row.id, modifiers);
443
+ selected = next.selected;
444
+ anchorId = next.anchorId;
445
+ focusIndex = flat.findIndex((entry) => entry.id === row.id);
446
+ }
447
+
448
+ function onRowClick(row: FlatRow<T>, event: MouseEvent): void {
449
+ selectRow(row, {ctrl: event.ctrlKey || event.metaKey, shift: event.shiftKey});
450
+ }
451
+
452
+ function onRowContextMenu(row: FlatRow<T>, event: MouseEvent): void {
453
+ if (!onrowcontextmenu || row.kind === 'header') {
454
+ return;
455
+ }
456
+ event.preventDefault();
457
+ if (!selectedSet.has(row.id)) {
458
+ selectRow(row, {});
459
+ }
460
+ onrowcontextmenu(row.row, event);
461
+ }
462
+
463
+ // ------------------------------------------------------------------ rename
464
+
465
+ /**
466
+ * What a key or a double click is meant for when it comes from inside a control of the grid: a
467
+ * filter field, a paramset button, the copy button in the name cell. It stays
468
+ * with that control.
469
+ */
470
+ const CONTROL_SELECTOR = 'button, input, select, textarea, a[href], [contenteditable="true"]';
471
+
472
+ function fromControl(event: Event): boolean {
473
+ return event.target instanceof Element && event.target.closest(CONTROL_SELECTOR) !== null;
474
+ }
475
+
476
+ /**
477
+ * The fields a key edits text or picks a value in - a column filter above all. The arrow
478
+ * keys, Home and End move the cursor there, so the grid leaves them alone; from a button in a
479
+ * cell they still move the row focus.
480
+ */
481
+ const TEXT_ENTRY_SELECTOR = 'input, select, textarea, [contenteditable="true"]';
482
+ const NAVIGATION_KEYS = new Set(['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight', 'Home', 'End']);
483
+
484
+ function fromTextEntry(event: Event): boolean {
485
+ return event.target instanceof Element && event.target.closest(TEXT_ENTRY_SELECTOR) !== null;
486
+ }
487
+
488
+ function renamable(row: FlatRow<T> | undefined): row is FlatRow<T> {
489
+ return row?.kind === 'row' && onrename !== undefined && (canRename?.(row.row) ?? true);
490
+ }
491
+
492
+ /**
493
+ * A double click on a row. On the name cell it renames, and the word the browser selected on the
494
+ * way is let go again, as 2.7's `removeSelectionAfterDblClick` did; everywhere else - and on the
495
+ * name of a row that cannot be renamed - it is the row's activation, as before. The two clicks
496
+ * in front of it have selected the row the way a single click does, so the dialog acts on exactly
497
+ * the row that is highlighted. A sub-grid's label row, where the resize handles are, is neither.
498
+ *
499
+ * A column with an `onactivate` of its own - Rooms, Functions - takes the double click
500
+ * on its cell the same way, before the row's activation; a sub-row's cell asks the sub-columns.
501
+ */
502
+ function onRowDblClick(row: FlatRow<T>, event: MouseEvent): void {
503
+ if (row.kind !== 'row') {
504
+ return;
505
+ }
506
+ const key = cellAt(event)?.dataset['columnKey'];
507
+ if (key === renameColumn && !fromControl(event) && renamable(row)) {
508
+ window.getSelection()?.removeAllRanges();
509
+ onrename?.(row.row);
510
+ return;
511
+ }
512
+ const column = (row.depth > 0 ? visibleSubColumns : visibleColumns).find((entry) => entry.key === key);
513
+ if (column?.onactivate !== undefined && !fromControl(event)) {
514
+ window.getSelection()?.removeAllRanges();
515
+ column.onactivate(row.row);
516
+ return;
517
+ }
518
+ onactivate?.(row.row);
519
+ }
520
+
521
+ /**
522
+ * The cell a pointer event is in. An empty cell has no height of its own - the row's grid centres
523
+ * every cell on its content - so a double click into the Rooms column of a device without rooms
524
+ * lands on the row, not on a cell (seen on a real system). The column is then the one
525
+ * whose track spans the pointer's x.
526
+ */
527
+ function cellAt(event: MouseEvent): HTMLElement | null {
528
+ if (!(event.target instanceof Element)) {
529
+ return null;
530
+ }
531
+ const direct = event.target.closest<HTMLElement>('[data-column-key]');
532
+ if (direct !== null) {
533
+ return direct;
534
+ }
535
+ const rowElement = event.target.closest<HTMLElement>('[data-row-id]');
536
+ if (rowElement === null) {
537
+ return null;
538
+ }
539
+ for (const cell of rowElement.querySelectorAll<HTMLElement>('[data-column-key]')) {
540
+ const box = cell.getBoundingClientRect();
541
+ if (event.clientX >= box.left && event.clientX < box.right) {
542
+ return cell;
543
+ }
544
+ }
545
+ return null;
546
+ }
547
+
548
+ /**
549
+ * F2, or Enter on a table without `onactivate`: the focused row, but only when it is selected -
550
+ * the focus starts on the first row with nothing selected, and a key must not rename a row the
551
+ * user cannot see highlighted - and only when the key came from the grid, not from a control.
552
+ */
553
+ function renameByKey(row: FlatRow<T> | undefined, event: KeyboardEvent): void {
554
+ if (!renamable(row) || !selectedSet.has(row.id) || fromControl(event)) {
555
+ return;
556
+ }
557
+ event.preventDefault();
558
+ onrename?.(row.row);
559
+ }
560
+
561
+ function scrollFocusIntoView(): void {
562
+ const element = viewport;
563
+ if (!element) {
564
+ return;
565
+ }
566
+ const top = focusIndex * rowHeight;
567
+ const view = bodyHeight === 0 ? element.clientHeight : bodyHeight;
568
+ if (top < element.scrollTop) {
569
+ element.scrollTop = top;
570
+ } else if (top + rowHeight > element.scrollTop + view) {
571
+ element.scrollTop = top + rowHeight - view;
572
+ }
573
+ }
574
+
575
+ function moveFocus(delta: number, shift: boolean): void {
576
+ if (flat.length === 0) {
577
+ return;
578
+ }
579
+ const next = Math.min(flat.length - 1, Math.max(0, focusIndex + delta));
580
+ const row = flat[next];
581
+ if (!row) {
582
+ return;
583
+ }
584
+ focusIndex = next;
585
+ selectRow(row, {shift});
586
+ scrollFocusIntoView();
587
+ }
588
+
589
+ function onKeyDown(event: KeyboardEvent): void {
590
+ if (NAVIGATION_KEYS.has(event.key) && fromTextEntry(event)) {
591
+ return;
592
+ }
593
+ const row = flat[focusIndex];
594
+ switch (event.key) {
595
+ case 'ArrowDown':
596
+ event.preventDefault();
597
+ moveFocus(1, event.shiftKey);
598
+ break;
599
+ case 'ArrowUp':
600
+ event.preventDefault();
601
+ moveFocus(-1, event.shiftKey);
602
+ break;
603
+ case 'Home':
604
+ event.preventDefault();
605
+ moveFocus(-flat.length, event.shiftKey);
606
+ break;
607
+ case 'End':
608
+ event.preventDefault();
609
+ moveFocus(flat.length, event.shiftKey);
610
+ break;
611
+ case 'ArrowRight':
612
+ if (row?.hasChildren === true && !row.expanded) {
613
+ event.preventDefault();
614
+ toggleExpanded(row.id);
615
+ }
616
+ break;
617
+ case 'ArrowLeft':
618
+ if (row?.hasChildren === true && row.expanded) {
619
+ event.preventDefault();
620
+ toggleExpanded(row.id);
621
+ }
622
+ break;
623
+ case 'Enter':
624
+ // Enter on a control in the grid - the copy button, a paramset button - presses that control
625
+ if (fromControl(event)) {
626
+ break;
627
+ }
628
+ if (row && onactivate) {
629
+ event.preventDefault();
630
+ onactivate(row.row);
631
+ } else {
632
+ renameByKey(row, event);
633
+ }
634
+ break;
635
+ case 'F2':
636
+ renameByKey(row, event);
637
+ break;
638
+ case ' ':
639
+ // And Space presses a button or is typed into a filter field, rather than toggling the row
640
+ if (row && !fromControl(event)) {
641
+ event.preventDefault();
642
+ selectRow(row, {ctrl: true});
643
+ }
644
+ break;
645
+ case 'Escape':
646
+ // The tooltip of a cut-off cell goes; the key itself is left to whoever else wants it
647
+ hideTooltip();
648
+ break;
649
+ default:
650
+ break;
651
+ }
652
+ }
653
+
654
+ // ------------------------------------------------------------------ column widths
655
+
656
+ /** A pointer that moved less than this between down and up clicked - half a double click. */
657
+ const DRAG_THRESHOLD_PX = 2;
658
+ /**
659
+ * A finger wobbles more than a mouse. Under this, a touch on the handle is a tap, and a tap
660
+ * sorts like one on the rest of the label: the handle is 24 px wide for a finger, so a
661
+ * tap near the right edge of a label landed on the handle and did nothing a user could see.
662
+ */
663
+ const TAP_SLOP_PX = 4;
664
+ /** Room for the ▲ of a sorted label, so fitting a column and then sorting it cuts nothing off. */
665
+ const SORT_MARK_PX = 14;
666
+
667
+ /**
668
+ * Where a width is sized and kept - the table's columns from the head under `tableId`,
669
+ * the columns only the sub-grid has from its label rows under `subTableId`.
670
+ */
671
+ type WidthScope = 'table' | 'sub';
672
+
673
+ function scopeOf(key: string): WidthScope {
674
+ return subKeys.has(key) ? 'sub' : 'table';
675
+ }
676
+
677
+ /**
678
+ * The narrowest the user can make a column from where it is sized - its own minimum for a
679
+ * column of buttons, the table's for every other one.
680
+ */
681
+ function floorOf(key: string): number {
682
+ const column = (scopeOf(key) === 'sub' ? visibleSubColumns : visibleColumns).find(
683
+ (candidate) => candidate.key === key,
684
+ );
685
+ return column === undefined ? MIN_COLUMN_WIDTH : minimumColumnWidth(column);
686
+ }
687
+
688
+ /** A drag, a key and a fit all store through here, so all of them stop at {@link floorOf}. */
689
+ function saveWidth(key: string, width: number): void {
690
+ const store = environment?.columnWidths;
691
+ const scope = scopeOf(key);
692
+ const id = scope === 'sub' ? subTableId : tableId;
693
+ const clamped = clampColumnWidth(width, floorOf(key));
694
+ if (id !== undefined && store !== undefined) {
695
+ store.set(id, key, clamped);
696
+ } else if (scope === 'sub') {
697
+ localSubWidths = {...localSubWidths, [key]: clamped};
698
+ } else {
699
+ localWidths = {...localWidths, [key]: clamped};
700
+ }
701
+ }
702
+
703
+ /** Back to the designed widths: the table's columns, or the sub-grid's own alone. */
704
+ function resetWidths(scope: WidthScope): void {
705
+ const store = environment?.columnWidths;
706
+ const id = scope === 'sub' ? subTableId : tableId;
707
+ if (id !== undefined && store !== undefined) {
708
+ store.reset(id);
709
+ } else if (scope === 'sub') {
710
+ localSubWidths = {};
711
+ } else {
712
+ localWidths = {};
713
+ }
714
+ }
715
+
716
+ /**
717
+ * A column that can be sized from where the user is: a column of the head from the head, a
718
+ * column only the sub-grid has from the sub-grid's label row. A column both depths share is the
719
+ * table's; its sub-grid label has no handle.
720
+ */
721
+ function resizableColumn(key: string | undefined, scope: WidthScope): DataTableColumn<T> | undefined {
722
+ if (key === undefined || scopeOf(key) !== scope) {
723
+ return undefined;
724
+ }
725
+ const column = (scope === 'sub' ? visibleSubColumns : visibleColumns).find(
726
+ (candidate) => candidate.key === key,
727
+ );
728
+ return column !== undefined && isResizable(column) ? column : undefined;
729
+ }
730
+
731
+ /** The label of a column: its cell in the head, or in the first rendered label row of a sub-grid. */
732
+ function labelCell(key: string): HTMLElement | undefined {
733
+ const selector = `[data-column-key="${CSS.escape(key)}"]`;
734
+ const cell =
735
+ scopeOf(key) === 'sub'
736
+ ? viewport?.querySelector<HTMLElement>(`.hmm-tr-subhead ${selector}`)
737
+ : headStrip?.querySelector<HTMLElement>(selector);
738
+ return cell ?? undefined;
739
+ }
740
+
741
+ /**
742
+ * Double click on the handle: as wide as the label and the widest of the cells that are
743
+ * rendered - the window of rows, never every row of a list of a thousand devices - up to
744
+ * `FIT_MAX_WIDTH`.
745
+ */
746
+ function fitColumn(key: string): void {
747
+ const scope = scopeOf(key);
748
+ const column = resizableColumn(key, scope);
749
+ const header = labelCell(key);
750
+ if (!root || !column || !header) {
751
+ return;
752
+ }
753
+ const cells = viewport
754
+ ? [...viewport.querySelectorAll<HTMLElement>(`.hmm-td[data-column-key="${CSS.escape(key)}"]`)]
755
+ : [];
756
+ const [label = 0, ...values] = measureNaturalWidths(root, [header, ...cells]);
757
+ // a label of the head can get the sort mark; a label row of a sub-grid is not sorted
758
+ const labelWidth = scope === 'table' && isSortable(column) && sort?.key !== key ? label + SORT_MARK_PX : label;
759
+ const width = fitColumnWidth([labelWidth, ...values], minimumColumnWidth(column));
760
+ if (width !== undefined) {
761
+ saveWidth(key, width);
762
+ }
763
+ }
764
+
765
+ interface Resize {
766
+ readonly key: string;
767
+ readonly pointerId: number;
768
+ readonly startX: number;
769
+ /** The column's width when the handle was pressed, as drawn - a proportional one included. */
770
+ readonly startWidth: number;
771
+ /** The narrowest the drag makes the column, its own minimum for a column of buttons. */
772
+ readonly min: number;
773
+ /** Pressed by a finger or a pen, where only a drag resizes and a tap sorts. */
774
+ readonly touch: boolean;
775
+ moved: boolean;
776
+ }
777
+
778
+ /** Plain state: nothing is drawn from it but the one class below. */
779
+ let resize: Resize | undefined;
780
+ /** The last press on a handle was a finger's, so the double click that follows two taps fits nothing. */
781
+ let pressedByTouch = false;
782
+ let resizingKey = $state<string | undefined>(undefined);
783
+
784
+ /** The cell a handle sits in: a label of the head, or of the sub-grid row whose handle was used. */
785
+ function cellOfHandle(event: Event): HTMLElement | null {
786
+ return (event.currentTarget as HTMLElement).closest<HTMLElement>('[data-column-key]');
787
+ }
788
+
789
+ function onResizeStart(event: PointerEvent, key: string): void {
790
+ const cell = cellOfHandle(event);
791
+ if (event.button !== 0 || !cell) {
792
+ return;
793
+ }
794
+ event.preventDefault();
795
+ try {
796
+ // the moves keep arriving here when the pointer leaves the 7 px of the handle
797
+ (event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
798
+ } catch {
799
+ // a pointer that is already gone, or a DOM without capture: the drag works while over the handle
800
+ }
801
+ pressedByTouch = event.pointerType === 'touch' || event.pointerType === 'pen';
802
+ resize = {
803
+ key,
804
+ pointerId: event.pointerId,
805
+ startX: event.clientX,
806
+ startWidth: cell.getBoundingClientRect().width,
807
+ min: floorOf(key),
808
+ touch: pressedByTouch,
809
+ moved: false,
810
+ };
811
+ hideTooltip();
812
+ }
813
+
814
+ /**
815
+ * The column is as much wider as the pointer moved. The columns nobody sized share what is left,
816
+ * those in front of it too, so the handle of a column further right trails the pointer a little;
817
+ * a width that kept the edge under the pointer would have to grow by more than the pointer
818
+ * moved - without bound for the last column, whose right edge is the window's.
819
+ *
820
+ * A move changes the draft and with it the one template on the grid; the browser lays the
821
+ * rendered rows out once per frame, however many pointer events arrive in it.
822
+ */
823
+ function onResizeMove(event: PointerEvent): void {
824
+ const current = resize;
825
+ if (current?.pointerId !== event.pointerId) {
826
+ return;
827
+ }
828
+ const dx = event.clientX - current.startX;
829
+ if (!current.moved && Math.abs(dx) < (current.touch ? TAP_SLOP_PX : DRAG_THRESHOLD_PX)) {
830
+ return;
831
+ }
832
+ if (!current.moved) {
833
+ current.moved = true;
834
+ resizingKey = current.key;
835
+ }
836
+ const width = clampColumnWidth(current.startWidth + dx, current.min);
837
+ if (draft?.key !== current.key || draft.width !== width) {
838
+ draft = {key: current.key, width};
839
+ }
840
+ }
841
+
842
+ /** Stores what is drawn: the last move's width, not whatever position the release reports. */
843
+ function onResizeEnd(event: PointerEvent): void {
844
+ const current = resize;
845
+ if (current?.pointerId !== event.pointerId) {
846
+ return;
847
+ }
848
+ resize = undefined;
849
+ resizingKey = undefined;
850
+ if (current.moved && draft?.key === current.key) {
851
+ saveWidth(current.key, draft.width);
852
+ }
853
+ draft = undefined;
854
+ }
855
+
856
+ /**
857
+ * The finger let go. A drag was a resize and is stored like a mouse's; a tap that never
858
+ * moved past {@link TAP_SLOP_PX} sorts the column, because the press was meant for its label.
859
+ * The handle holds the pointer capture, so the click that follows lands on the handle and not on
860
+ * the label's button - the sort has to happen here. A sub-grid's label row is not sorted.
861
+ */
862
+ function onResizeUp(event: PointerEvent, column: DataTableColumn<T>): void {
863
+ const current = resize;
864
+ onResizeEnd(event);
865
+ if (
866
+ current?.pointerId === event.pointerId &&
867
+ current.touch &&
868
+ !current.moved &&
869
+ scopeOf(column.key) === 'table'
870
+ ) {
871
+ toggleSort(column);
872
+ }
873
+ }
874
+
875
+ function onResizeKey(event: KeyboardEvent, key: string): void {
876
+ if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
877
+ const cell = cellOfHandle(event);
878
+ if (cell) {
879
+ const step = event.key === 'ArrowRight' ? RESIZE_KEY_STEP : -RESIZE_KEY_STEP;
880
+ saveWidth(key, cell.getBoundingClientRect().width + step);
881
+ }
882
+ } else if (event.key === 'Enter') {
883
+ fitColumn(key);
884
+ } else if (event.key !== 'Tab') {
885
+ return;
886
+ }
887
+ if (event.key !== 'Tab') {
888
+ // the grid around the head moves the row selection on the same keys
889
+ event.preventDefault();
890
+ event.stopPropagation();
891
+ }
892
+ }
893
+
894
+ let headMenuOpen = $state(false);
895
+ let headMenuX = $state(0);
896
+ let headMenuY = $state(0);
897
+ let headMenuKey = $state<string | undefined>(undefined);
898
+ /** The menu of a sub-grid's label row fits and resets the sub-grid's own columns. */
899
+ let headMenuScope = $state<WidthScope>('table');
900
+ const headMenuItems = $derived.by((): ContextMenuItem[] => [
901
+ {
902
+ id: 'fit',
903
+ label: t('Fit column to content'),
904
+ disabled: resizableColumn(headMenuKey, headMenuScope) === undefined,
905
+ },
906
+ {
907
+ id: 'reset',
908
+ label: t('Reset column widths'),
909
+ disabled: headMenuScope === 'sub' ? !hasSubWidths : !hasUserWidths,
910
+ },
911
+ ]);
912
+
913
+ /**
914
+ * Right click on the column labels: fit the column under the pointer, or reset them all. One
915
+ * listener on the grid; a right click on a row is the row's own menu and is left alone. The
916
+ * label row of an expanded sub-grid is not a row anybody selects, and has the same menu for
917
+ * the sub-grid's columns.
918
+ */
919
+ function onGridContextMenu(event: MouseEvent): void {
920
+ const target = event.target instanceof Element ? event.target : null;
921
+ if (!target) {
922
+ return;
923
+ }
924
+ const inHead = headStrip?.contains(target) === true || groupStrip?.contains(target) === true;
925
+ if (!inHead && target.closest('.hmm-tr-subhead') === null) {
926
+ return;
927
+ }
928
+ event.preventDefault();
929
+ const cell = target.closest<HTMLElement>('[data-column-key]');
930
+ headMenuKey = cell?.dataset['columnKey'];
931
+ // The head's cell over a sub-grid-only column is the sub-grid's
932
+ headMenuScope = inHead && (headMenuKey === undefined || !subKeys.has(headMenuKey)) ? 'table' : 'sub';
933
+ headMenuX = event.clientX;
934
+ headMenuY = event.clientY;
935
+ headMenuOpen = true;
936
+ hideTooltip();
937
+ }
938
+
939
+ function onHeadMenuSelect(id: string): void {
940
+ if (id === 'fit' && headMenuKey !== undefined) {
941
+ fitColumn(headMenuKey);
942
+ } else if (id === 'reset') {
943
+ resetWidths(headMenuScope);
944
+ }
945
+ }
946
+
947
+ // ------------------------------------------------------- the full text of a cut-off cell
948
+
949
+ let tooltip = $state.raw<{text: string; anchor: TooltipAnchor} | undefined>(undefined);
950
+ /** The cell under the pointer; plain, because only the handlers read it. */
951
+ let hovered: HTMLElement | undefined;
952
+ /**
953
+ * The cell the tooltip that is shown - or on its way - belongs to, and what brought it
954
+ * there. The pointer and the keyboard share the one bubble, so a cell they meet on shows it once.
955
+ */
956
+ let tipCell: HTMLElement | undefined;
957
+ let tipSource: 'pointer' | 'focus' | undefined;
958
+ let tooltipTimer: ReturnType<typeof setTimeout> | undefined;
959
+
960
+ /**
961
+ * Whether a cell gets a tooltip: its text is cut off. Asked when the cell is reached, for this
962
+ * cell only - two numbers the browser has at hand - never for every cell up front. Fixed columns
963
+ * clip on purpose.
964
+ */
965
+ function wantsTooltip(cell: HTMLElement): boolean {
966
+ return resize === undefined && !cell.classList.contains('hmm-td-fixed') && isTruncated(cell);
967
+ }
968
+
969
+ /** The bubble after the app's tooltip delay, unless the cell is left before. */
970
+ function scheduleTooltip(cell: HTMLElement, source: 'pointer' | 'focus'): void {
971
+ hideTooltip();
972
+ tipCell = cell;
973
+ tipSource = source;
974
+ tooltipTimer = setTimeout(() => {
975
+ tooltipTimer = undefined;
976
+ showTooltip(cell);
977
+ }, TOOLTIP_DELAY_MS);
978
+ }
979
+
980
+ /** The pointer entered a cell (delegated: one listener for the whole grid, not one per cell). */
981
+ function onGridPointerOver(event: PointerEvent): void {
982
+ const target = event.target instanceof Element ? event.target.closest<HTMLElement>('.hmm-td, .hmm-th') : null;
983
+ const cell = target ?? undefined;
984
+ if (cell === hovered) {
985
+ return;
986
+ }
987
+ hovered = cell;
988
+ if (cell !== undefined && cell === tipCell) {
989
+ // the keyboard has brought this cell's tooltip already, or is about to
990
+ return;
991
+ }
992
+ if (cell !== undefined && wantsTooltip(cell)) {
993
+ scheduleTooltip(cell, 'pointer');
994
+ } else if (tipSource === 'pointer') {
995
+ hideTooltip();
996
+ }
997
+ }
998
+
999
+ /**
1000
+ * `:focus-visible` is the browser's own answer to "did this focus come from the keyboard". A
1001
+ * focus that came with a click belongs to the pointer: that press has just hidden the tooltip,
1002
+ * and the focus must not bring it back a second time.
1003
+ */
1004
+ function isKeyboardFocus(element: HTMLElement): boolean {
1005
+ try {
1006
+ return element.matches(':focus-visible');
1007
+ } catch {
1008
+ return false;
1009
+ }
1010
+ }
1011
+
1012
+ /**
1013
+ * Keyboard focus arrived in a cell - the sort button of a cut-off column label, a
1014
+ * button in a row. The same bubble after the same delay as on hover. A resize handle names
1015
+ * itself and gets none.
1016
+ */
1017
+ function onGridFocusIn(event: FocusEvent): void {
1018
+ const target = event.target instanceof HTMLElement ? event.target : undefined;
1019
+ const cell = target?.closest<HTMLElement>('.hmm-td, .hmm-th') ?? undefined;
1020
+ if (
1021
+ target === undefined ||
1022
+ cell === undefined ||
1023
+ cell === tipCell ||
1024
+ target.classList.contains('hmm-th-resize') ||
1025
+ !isKeyboardFocus(target)
1026
+ ) {
1027
+ return;
1028
+ }
1029
+ if (wantsTooltip(cell)) {
1030
+ scheduleTooltip(cell, 'focus');
1031
+ }
1032
+ }
1033
+
1034
+ /** The focus moved on, or left the grid: a tooltip it brought goes with it. */
1035
+ function onGridFocusOut(): void {
1036
+ if (tipSource === 'focus') {
1037
+ hideTooltip();
1038
+ }
1039
+ }
1040
+
1041
+ function showTooltip(cell: HTMLElement): void {
1042
+ if (tipCell !== cell || !cell.isConnected) {
1043
+ return;
1044
+ }
1045
+ const text = fullText(cell.querySelector<HTMLElement>('.hmm-th-label') ?? cell);
1046
+ if (text === '') {
1047
+ return;
1048
+ }
1049
+ const {left, top, bottom} = cell.getBoundingClientRect();
1050
+ tooltip = {text, anchor: {left, top, bottom}};
1051
+ }
1052
+
1053
+ function hideTooltip(): void {
1054
+ if (tooltipTimer !== undefined) {
1055
+ clearTimeout(tooltipTimer);
1056
+ tooltipTimer = undefined;
1057
+ }
1058
+ tipCell = undefined;
1059
+ tipSource = undefined;
1060
+ if (tooltip !== undefined) {
1061
+ tooltip = undefined;
1062
+ }
1063
+ }
1064
+
1065
+ /** Hidden, and the next cell the pointer is over counts as entered again. */
1066
+ function forgetTooltip(): void {
1067
+ hideTooltip();
1068
+ hovered = undefined;
1069
+ }
1070
+
1071
+ /** The pointer left the grid: its own tooltip goes; one the keyboard brought stays with the focus. */
1072
+ function onGridPointerLeave(): void {
1073
+ if (tipSource === 'pointer') {
1074
+ hideTooltip();
1075
+ }
1076
+ hovered = undefined;
1077
+ }
1078
+
1079
+ $effect(() => () => {
1080
+ if (tooltipTimer !== undefined) {
1081
+ clearTimeout(tooltipTimer);
1082
+ }
1083
+ });
1084
+
1085
+ // ------------------------------------------------------------------ the copy button
1086
+
1087
+ /** How long "Copied" stays under the button, with the check mark in it. */
1088
+ const COPIED_MS = 1500;
1089
+ /** A failure has more to say: the text is selected, copy it by hand. */
1090
+ const COPY_FAILED_MS = 4000;
1091
+
1092
+ /** The button that has just copied, and what the bubble under it says. One at a time. */
1093
+ let copied = $state.raw<{key: string; ok: boolean; text: string; anchor: TooltipAnchor} | undefined>(undefined);
1094
+ let copiedTimer: ReturnType<typeof setTimeout> | undefined;
1095
+
1096
+ /** A cell of a rendered line: the line's key is unique where a row id is not (the Funk peers). */
1097
+ function copyKey(flatRow: FlatRow<T>, column: DataTableColumn<T>): string {
1098
+ return `${flatRow.key}${column.key}`;
1099
+ }
1100
+
1101
+ function clearCopied(): void {
1102
+ if (copiedTimer !== undefined) {
1103
+ clearTimeout(copiedTimer);
1104
+ copiedTimer = undefined;
1105
+ }
1106
+ if (copied !== undefined) {
1107
+ copied = undefined;
1108
+ }
1109
+ }
1110
+
1111
+ /**
1112
+ * The click of a copy button - Enter and Space on it included. It stays with the button: no
1113
+ * selection, no activation, no rename. It copies the column's value, the full text however narrow
1114
+ * the cell is. When no way of copying works the cell's text is selected in the page instead, so
1115
+ * Ctrl+C takes it by hand.
1116
+ */
1117
+ async function copyCell(event: MouseEvent, flatRow: FlatRow<T>, column: DataTableColumn<T>): Promise<void> {
1118
+ event.stopPropagation();
1119
+ const button = event.currentTarget;
1120
+ if (!(button instanceof HTMLElement)) {
1121
+ return;
1122
+ }
1123
+ const outcome = await copyText(cellText(flatRow.row, column), {host: root});
1124
+ // the cut-off tooltip of the cell, shown or on its way, makes room for the answer
1125
+ hideTooltip();
1126
+ clearCopied();
1127
+ if (!button.isConnected) {
1128
+ // the row scrolled out of the window while the clipboard answered
1129
+ return;
1130
+ }
1131
+ const ok = outcome !== 'failed';
1132
+ if (!ok) {
1133
+ selectCellText(button);
1134
+ }
1135
+ const {left, top, bottom} = button.getBoundingClientRect();
1136
+ copied = {
1137
+ key: copyKey(flatRow, column),
1138
+ ok,
1139
+ text: ok ? t('Copied') : t('Could not copy - the text is selected'),
1140
+ anchor: {left, top, bottom},
1141
+ };
1142
+ copiedTimer = setTimeout(clearCopied, ok ? COPIED_MS : COPY_FAILED_MS);
1143
+ }
1144
+
1145
+ /** The whole text of the button's cell, the button left out: what Ctrl+C copies after a failure. */
1146
+ function selectCellText(button: HTMLElement): void {
1147
+ const cell = button.closest('.hmm-td');
1148
+ const selection = window.getSelection();
1149
+ if (!cell || !selection) {
1150
+ return;
1151
+ }
1152
+ const range = document.createRange();
1153
+ range.selectNodeContents(cell);
1154
+ range.setEndBefore(button);
1155
+ selection.removeAllRanges();
1156
+ selection.addRange(range);
1157
+ }
1158
+
1159
+ $effect(() => () => {
1160
+ if (copiedTimer !== undefined) {
1161
+ clearTimeout(copiedTimer);
1162
+ }
1163
+ });
1164
+ </script>
1165
+
1166
+ <!--
1167
+ Drag to resize, double click to fit, arrow keys and Enter from the keyboard.
1168
+ `data-measure-skip` keeps it out of the fit. A focusable separator is a widget in WAI-ARIA (the
1169
+ window splitter pattern); Svelte's role table counts every separator as static. The same
1170
+ handle sits in the label row of an expanded sub-grid, on the columns only the sub-grid has.
1171
+ -->
1172
+ {#snippet resizeHandle(column: DataTableColumn<T>, handleTestId: string | undefined)}
1173
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
1174
+ <div
1175
+ class="hmm-th-resize"
1176
+ class:hmm-th-resize-active={resizingKey === column.key}
1177
+ role="separator"
1178
+ aria-orientation="vertical"
1179
+ aria-label={t('Resize column {column}', {column: column.label})}
1180
+ tabindex="0"
1181
+ data-measure-skip
1182
+ data-testid={handleTestId}
1183
+ onpointerdown={(event) => onResizeStart(event, column.key)}
1184
+ onpointermove={onResizeMove}
1185
+ onpointerup={(event) => onResizeUp(event, column)}
1186
+ onpointercancel={onResizeEnd}
1187
+ onlostpointercapture={onResizeEnd}
1188
+ ondblclick={(event) => {
1189
+ event.preventDefault();
1190
+ // Two taps sorted twice; under a finger only a drag changes a width
1191
+ if (!pressedByTouch) {
1192
+ fitColumn(column.key);
1193
+ }
1194
+ }}
1195
+ onkeydown={(event) => onResizeKey(event, column.key)}
1196
+ ></div>
1197
+ {/snippet}
1198
+
1199
+ <div class="hmm-table" data-testid={testId} bind:this={root}>
1200
+ {#if hasBand}
1201
+ <div class="hmm-table-band">
1202
+ {#if caption !== undefined}<span class="hmm-table-caption">{caption}</span>{/if}
1203
+ {#if toolbar}
1204
+ <div class="hmm-table-actions" role="toolbar" aria-label={toolbarLabel ?? caption ?? filterLabel}>
1205
+ {@render toolbar()}
1206
+ </div>
1207
+ {/if}
1208
+ <div class="hmm-table-trailing">
1209
+ {#if searchBox}
1210
+ <input
1211
+ class="hmm-input hmm-table-search"
1212
+ type="search"
1213
+ placeholder={searchLabel}
1214
+ aria-label={searchLabel}
1215
+ value={filter}
1216
+ data-testid={testId === undefined ? undefined : `${testId}-search`}
1217
+ oninput={(event) => {
1218
+ setSearch(event.currentTarget.value);
1219
+ }}
1220
+ />
1221
+ {/if}
1222
+ {#if status}{@render status()}{/if}
1223
+ {#if hiddenByFilter && showingText !== undefined}
1224
+ <span class="hmm-table-count" data-testid={testId === undefined ? undefined : `${testId}-count`}
1225
+ >{showingText(shownCount, rows.length)}</span
1226
+ >
1227
+ {:else if countText !== undefined}
1228
+ <span class="hmm-table-count" data-testid={testId === undefined ? undefined : `${testId}-count`}
1229
+ >{countText}</span
1230
+ >
1231
+ {/if}
1232
+ </div>
1233
+ </div>
1234
+ {/if}
1235
+
1236
+ <div
1237
+ class="hmm-table-grid"
1238
+ class:hmm-table-resizing={resizingKey !== undefined}
1239
+ role="grid"
1240
+ aria-rowcount={flat.length}
1241
+ aria-colcount={visibleColumns.length}
1242
+ tabindex="0"
1243
+ style:--hmm-table-columns={sized.template}
1244
+ style:--hmm-table-min-width={`${String(sized.minWidth)}px`}
1245
+ style:--hmm-table-gutter={`${String(gutter)}px`}
1246
+ onkeydown={onKeyDown}
1247
+ oncontextmenu={onGridContextMenu}
1248
+ onpointerover={onGridPointerOver}
1249
+ onpointerleave={onGridPointerLeave}
1250
+ onpointerdown={hideTooltip}
1251
+ onfocusin={onGridFocusIn}
1252
+ onfocusout={onGridFocusOut}
1253
+ >
1254
+ {#if spans.length > 0}
1255
+ <!-- The 2.x Funk grid's second header row: one cell per interface over its columns. -->
1256
+ <div class="hmm-table-groups" role="row" bind:this={groupStrip}>
1257
+ {#each spans as span (span.key)}
1258
+ <div
1259
+ class="hmm-th hmm-th-group"
1260
+ role="columnheader"
1261
+ aria-colspan={span.end - span.start}
1262
+ style:grid-column={`${String(span.start)} / ${String(span.end)}`}
1263
+ data-testid={testId === undefined ? undefined : `${testId}-group-${span.key}`}
1264
+ >
1265
+ <span class="hmm-th-group-label">{span.label}</span>
1266
+ {#if span.sublabel !== undefined && span.sublabel !== ''}
1267
+ <span class="hmm-th-group-sub">{span.sublabel}</span>
1268
+ {/if}
1269
+ </div>
1270
+ {/each}
1271
+ </div>
1272
+ {/if}
1273
+
1274
+ <div class="hmm-table-head" role="row" bind:this={headStrip}>
1275
+ {#if hasExpander}<div class="hmm-th hmm-th-expander" role="columnheader"></div>{/if}
1276
+ {#each visibleColumns as column (column.key)}
1277
+ <!--
1278
+ The label is the header's name - without it the resize handle's own
1279
+ label would be read as part of every column header.
1280
+ -->
1281
+ <div
1282
+ class="hmm-th"
1283
+ role="columnheader"
1284
+ aria-label={column.label === '' ? undefined : column.label}
1285
+ data-column-key={column.key}
1286
+ style:grid-column={layout.track[column.key]}
1287
+ aria-sort={sort?.key === column.key
1288
+ ? sort.direction === 'asc'
1289
+ ? 'ascending'
1290
+ : 'descending'
1291
+ : 'none'}
1292
+ style:text-align={column.align ?? 'left'}
1293
+ >
1294
+ {#if isSortable(column)}
1295
+ <!--
1296
+ The label of a right- or centre-aligned column has to follow the
1297
+ values. `justify-content: inherit` took `normal` from the grid cell, so
1298
+ every sortable label sat on the left while its values sat on the right -
1299
+ "CONNECTED" over one column, its tick over the next.
1300
+ -->
1301
+ <button
1302
+ type="button"
1303
+ class="hmm-th-button"
1304
+ style:justify-content={column.align === 'right'
1305
+ ? 'flex-end'
1306
+ : column.align === 'center'
1307
+ ? 'center'
1308
+ : 'flex-start'}
1309
+ onclick={() => toggleSort(column)}
1310
+ >
1311
+ <span class="hmm-th-label">{column.label}</span>
1312
+ {#if sort?.key === column.key}
1313
+ <span class="hmm-th-sort" aria-hidden="true"
1314
+ >{sort.direction === 'asc' ? '▲' : '▼'}</span
1315
+ >
1316
+ {/if}
1317
+ </button>
1318
+ {:else}
1319
+ <span class="hmm-th-label">{column.label}</span>
1320
+ {/if}
1321
+ {#if isResizable(column)}
1322
+ {@render resizeHandle(
1323
+ column,
1324
+ testId === undefined ? undefined : `${testId}-resize-${column.key}`,
1325
+ )}
1326
+ {/if}
1327
+ </div>
1328
+ {/each}
1329
+ <!--
1330
+ The gap a sub-grid-only column leaves in the head, with that column's handle. No
1331
+ label and no column header role: no row of the table has a cell there. `grid-row: 1`,
1332
+ because these come after the labels in the DOM and auto-placement would otherwise put
1333
+ a column that lies before the last label into a second head row.
1334
+ -->
1335
+ {#each subOnlyColumns as column (column.key)}
1336
+ <div
1337
+ class="hmm-th hmm-th-sub-only"
1338
+ data-column-key={column.key}
1339
+ style:grid-column={layout.track[column.key]}
1340
+ style:grid-row="1"
1341
+ >
1342
+ {@render resizeHandle(column, testId === undefined ? undefined : `${testId}-resize-${column.key}`)}
1343
+ </div>
1344
+ {/each}
1345
+ </div>
1346
+
1347
+ {#if columnFilterRow}
1348
+ <div class="hmm-table-filters" bind:this={filterStrip}>
1349
+ {#if hasExpander}<div class="hmm-tf-spacer"></div>{/if}
1350
+ {#each visibleColumns as column (column.key)}
1351
+ <div class="hmm-tf" style:grid-column={layout.track[column.key]}>
1352
+ {#if isFilterable(column) && column.filterOptions !== undefined}
1353
+ <select
1354
+ class="hmm-select hmm-tf-input hmm-tf-select"
1355
+ aria-label={`${filterLabel}: ${column.label}`}
1356
+ value={columnFilters[column.key] ?? ''}
1357
+ data-filter-key={column.key}
1358
+ onchange={(event) => {
1359
+ setColumnFilter(column.key, event.currentTarget.value);
1360
+ }}
1361
+ >
1362
+ <option value="">{allLabel}</option>
1363
+ {#each column.filterOptions as option (option.value)}
1364
+ <option value={option.value}>{option.label}</option>
1365
+ {/each}
1366
+ </select>
1367
+ {:else if isFilterable(column)}
1368
+ <input
1369
+ class="hmm-input hmm-tf-input"
1370
+ type="search"
1371
+ aria-label={`${filterLabel}: ${column.label}`}
1372
+ value={columnFilters[column.key] ?? ''}
1373
+ data-filter-key={column.key}
1374
+ oninput={(event) => {
1375
+ setColumnFilter(column.key, event.currentTarget.value);
1376
+ }}
1377
+ />
1378
+ {/if}
1379
+ </div>
1380
+ {/each}
1381
+ </div>
1382
+ {/if}
1383
+
1384
+ <div
1385
+ class="hmm-table-body"
1386
+ bind:this={viewport}
1387
+ onscroll={(event) => onBodyScroll(event.currentTarget)}
1388
+ style:height={height === undefined ? undefined : `${height}px`}
1389
+ >
1390
+ {#if flat.length === 0}
1391
+ <div class="hmm-table-empty">
1392
+ {#if hiddenByFilter}
1393
+ <span>{noMatchText}</span>
1394
+ <button
1395
+ type="button"
1396
+ class="hmm-button hmm-table-clear"
1397
+ data-testid={testId === undefined ? undefined : `${testId}-clear-filter`}
1398
+ onclick={() => {
1399
+ clearFilters();
1400
+ filtersChanged();
1401
+ }}>{clearFilterLabel}</button
1402
+ >
1403
+ {:else}
1404
+ {emptyText}
1405
+ {/if}
1406
+ </div>
1407
+ {:else}
1408
+ <div class="hmm-table-spacer" style:height={`${flat.length * rowHeight}px`}>
1409
+ <div class="hmm-table-rows" style:transform={`translateY(${window_.start * rowHeight}px)`}>
1410
+ {#each windowRows as flatRow, index (flatRow.key)}
1411
+ <!-- The grid itself carries the keyboard handling; a row is a plain
1412
+ target for the pointer, which is what every 2.x grid row was. -->
1413
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
1414
+ <div
1415
+ class={['hmm-tr', flatRow.kind === 'row' && rowClass?.(flatRow.row)]}
1416
+ data-testid={flatRow.kind === 'row' && flatRow.depth === 0
1417
+ ? rowTestId?.(flatRow.row)
1418
+ : undefined}
1419
+ class:hmm-tr-even={(window_.start + index) % 2 === 1}
1420
+ class:hmm-tr-selected={selectedSet.has(flatRow.id)}
1421
+ class:hmm-tr-child={flatRow.depth > 0 && flatRow.kind === 'row'}
1422
+ class:hmm-tr-subhead={flatRow.kind === 'header'}
1423
+ role="row"
1424
+ tabindex="-1"
1425
+ aria-selected={flatRow.kind === 'header' ? undefined : selectedSet.has(flatRow.id)}
1426
+ data-row-id={flatRow.id}
1427
+ data-row-kind={flatRow.kind}
1428
+ style:height={`${rowHeight}px`}
1429
+ onclick={(event) => onRowClick(flatRow, event)}
1430
+ ondblclick={(event) => onRowDblClick(flatRow, event)}
1431
+ oncontextmenu={(event) => onRowContextMenu(flatRow, event)}
1432
+ >
1433
+ {#if hasExpander}
1434
+ <div class="hmm-td hmm-td-expander">
1435
+ {#if flatRow.hasChildren}
1436
+ <button
1437
+ type="button"
1438
+ class="hmm-expander"
1439
+ aria-expanded={flatRow.expanded}
1440
+ aria-label={flatRow.expanded ? t('Collapse row') : t('Expand row')}
1441
+ onclick={(event) => {
1442
+ event.stopPropagation();
1443
+ toggleExpanded(flatRow.id);
1444
+ }}>{flatRow.expanded ? '−' : '+'}</button
1445
+ >
1446
+ {/if}
1447
+ </div>
1448
+ {/if}
1449
+ {#each flatRow.depth > 0 ? visibleSubColumns : visibleColumns as column (column.key)}
1450
+ <div
1451
+ class="hmm-td"
1452
+ class:hmm-td-fixed={column.fixed === true}
1453
+ class:hmm-td-copy={column.copy !== undefined && flatRow.kind === 'row'}
1454
+ class:hmm-mono={column.mono === true && flatRow.kind === 'row'}
1455
+ role="gridcell"
1456
+ data-column-key={column.key}
1457
+ style:grid-column={layout.track[column.key]}
1458
+ style:text-align={column.align ?? 'left'}
1459
+ >
1460
+ {#if flatRow.kind === 'header'}
1461
+ {column.label}
1462
+ {#if subKeys.has(column.key) && isResizable(column)}
1463
+ {@render resizeHandle(
1464
+ column,
1465
+ testId === undefined
1466
+ ? undefined
1467
+ : `${testId}-sub-resize-${column.key}`,
1468
+ )}
1469
+ {/if}
1470
+ {:else if cell}
1471
+ {@render cell(flatRow.row, column, flatRow)}
1472
+ {:else}
1473
+ {cellText(flatRow.row, column)}
1474
+ {/if}
1475
+ {#if column.copy !== undefined && flatRow.kind === 'row' && cellText(flatRow.row, column) !== ''}
1476
+ {@const copyId = copyKey(flatRow, column)}
1477
+ <!--
1478
+ Over the end of the text, not beside it - the column keeps
1479
+ its width and the cut-off tooltip its measurement, and
1480
+ `data-measure-skip` keeps it out of a fit. An icon without text, so
1481
+ the tooltip and a cell's text content stay the value alone. Only
1482
+ the buttons of the row the keyboard is on are tab stops.
1483
+ -->
1484
+ <button
1485
+ type="button"
1486
+ class="hmm-copy"
1487
+ class:hmm-copy-shown={copied?.key === copyId}
1488
+ tabindex={window_.start + index === focusIndex ? 0 : -1}
1489
+ aria-label={column.copy === 'name' ? t('Copy name') : t('Copy address')}
1490
+ data-measure-skip
1491
+ onclick={(event) => void copyCell(event, flatRow, column)}
1492
+ ondblclick={(event) => {
1493
+ // two clicks copy twice; the row neither activates nor renames
1494
+ event.stopPropagation();
1495
+ }}
1496
+ >
1497
+ <svg class="hmm-copy-icon" viewBox="0 0 10 10" aria-hidden="true">
1498
+ {#if copied?.key === copyId && copied.ok}
1499
+ <path d="M1.5 5.2 4 7.7 8.5 2.3" />
1500
+ {:else}
1501
+ <rect x="3.5" y="3.5" width="5.5" height="5.5" rx="1" />
1502
+ <path d="M6.5 1.5h-4a1 1 0 0 0-1 1v4" />
1503
+ {/if}
1504
+ </svg>
1505
+ </button>
1506
+ {/if}
1507
+ </div>
1508
+ {/each}
1509
+ </div>
1510
+ {/each}
1511
+ </div>
1512
+ </div>
1513
+ {/if}
1514
+ </div>
1515
+ </div>
1516
+
1517
+ <!--
1518
+ Outside the grid on purpose: the row window has a transform, and a `position: fixed` bubble
1519
+ inside it would be placed against the rows instead of the window.
1520
+ -->
1521
+ {#if tooltip !== undefined}
1522
+ <TooltipBubble
1523
+ text={tooltip.text}
1524
+ anchor={tooltip.anchor}
1525
+ testId={testId === undefined ? undefined : `${testId}-tooltip`}
1526
+ />
1527
+ {/if}
1528
+ {#if copied !== undefined}
1529
+ <TooltipBubble
1530
+ text={copied.text}
1531
+ anchor={copied.anchor}
1532
+ testId={testId === undefined ? undefined : `${testId}-copied`}
1533
+ />
1534
+ {/if}
1535
+ <!-- The same words for a screen reader, to which a tooltip bubble is not read. -->
1536
+ <span class="hmm-table-announce" role="status" aria-live="polite">{copied?.text ?? ''}</span>
1537
+ {#if headMenuOpen}
1538
+ <ContextMenu
1539
+ bind:open={headMenuOpen}
1540
+ items={headMenuItems}
1541
+ x={headMenuX}
1542
+ y={headMenuY}
1543
+ label={t('Column widths')}
1544
+ testId={testId === undefined ? undefined : `${testId}-columns-menu`}
1545
+ onselect={onHeadMenuSelect}
1546
+ />
1547
+ {/if}
1548
+ </div>
1549
+
1550
+ <style>
1551
+ .hmm-table {
1552
+ display: flex;
1553
+ flex-direction: column;
1554
+ font-size: var(--hmm-font-size-grid);
1555
+ min-height: 0;
1556
+ height: 100%;
1557
+ border: 1px solid var(--hmm-border);
1558
+ border-radius: var(--hmm-radius);
1559
+ background: var(--hmm-bg);
1560
+ overflow: hidden;
1561
+ }
1562
+
1563
+ /* The header band and the column labels under it are one block on the same ground, so the
1564
+ grid reads as a table with a head rather than as a strip with a table under it. */
1565
+ .hmm-table-band {
1566
+ display: flex;
1567
+ /* a narrow window: the count and the search go under the actions rather than out of the band */
1568
+ flex-wrap: wrap;
1569
+ align-items: center;
1570
+ gap: 4px 8px;
1571
+ /* as tall with a plain button or a search field in it as with the 26 px toolbar buttons */
1572
+ box-sizing: border-box;
1573
+ min-height: 33px;
1574
+ padding: 3px 6px;
1575
+ background: var(--hmm-header-bg);
1576
+ border-bottom: 1px solid var(--hmm-border-muted);
1577
+ }
1578
+
1579
+ .hmm-table-caption {
1580
+ font-weight: bold;
1581
+ }
1582
+
1583
+ /* Tasks 28 and 33: the actions take the free space of the band, so a tab's main action
1584
+ (`PrimaryToolbarButton`) has room for its caption when there is some, and is the one thing
1585
+ that gives way - down to its icon - when there is not. */
1586
+ .hmm-table-actions {
1587
+ display: flex;
1588
+ align-items: center;
1589
+ gap: 2px;
1590
+ flex: 1 1 auto;
1591
+ }
1592
+
1593
+ /* `margin-left: auto` rather than a spacer: the count sits on the right edge of the band
1594
+ whatever the actions on the left add up to. */
1595
+ .hmm-table-trailing {
1596
+ display: flex;
1597
+ align-items: center;
1598
+ gap: 8px;
1599
+ margin-left: auto;
1600
+ padding-left: 8px;
1601
+ color: var(--hmm-fg-muted);
1602
+ white-space: nowrap;
1603
+ }
1604
+
1605
+ .hmm-table-count {
1606
+ white-space: nowrap;
1607
+ }
1608
+
1609
+ /* The search over all columns: as tall as a toolbar button, and it gives way before the band wraps. */
1610
+ .hmm-table-search {
1611
+ flex: 0 1 14rem;
1612
+ width: 14rem;
1613
+ min-width: 6rem;
1614
+ color: var(--hmm-fg);
1615
+ }
1616
+
1617
+ .hmm-table-grid {
1618
+ display: flex;
1619
+ flex-direction: column;
1620
+ min-height: 0;
1621
+ flex: 1 1 auto;
1622
+ outline-offset: -2px;
1623
+ }
1624
+
1625
+ /* A drag keeps its cursor and selects no text, wherever the pointer strays to. */
1626
+ .hmm-table-resizing {
1627
+ cursor: col-resize;
1628
+ user-select: none;
1629
+ }
1630
+
1631
+ /*
1632
+ * Every strip of the grid is drawn on the one template that the grid element carries as
1633
+ * `--hmm-table-columns`, and is at least as wide as the columns need: a row whose box
1634
+ * stopped at the window would leave its background behind when the body scrolls sideways. The
1635
+ * head strips carry the body's scrollbar gutter as padding, hence the sum.
1636
+ */
1637
+ .hmm-table-head,
1638
+ .hmm-table-filters,
1639
+ .hmm-table-groups {
1640
+ display: grid;
1641
+ grid-template-columns: var(--hmm-table-columns);
1642
+ /* not left to app.css: the padding has to be inside the minimum wherever the table is drawn */
1643
+ box-sizing: border-box;
1644
+ min-width: calc(var(--hmm-table-min-width) + var(--hmm-table-gutter));
1645
+ padding-right: var(--hmm-table-gutter);
1646
+ background: var(--hmm-header-bg);
1647
+ }
1648
+
1649
+ .hmm-table-head,
1650
+ .hmm-table-filters {
1651
+ border-bottom: 1px solid var(--hmm-border);
1652
+ }
1653
+
1654
+ .hmm-table-groups {
1655
+ border-bottom: 1px solid var(--hmm-border-muted);
1656
+ }
1657
+
1658
+ /* Two lines, centred over the columns the group spans, with a rule on its left so the eye
1659
+ can tell where one interface's columns end and the next one's begin. */
1660
+ .hmm-th-group {
1661
+ display: flex;
1662
+ flex-direction: column;
1663
+ align-items: center;
1664
+ padding: 3px 6px 2px;
1665
+ border-left: 1px solid var(--hmm-border-muted);
1666
+ line-height: 1.2;
1667
+ text-align: center;
1668
+ }
1669
+
1670
+ .hmm-th-group-sub {
1671
+ font-weight: normal;
1672
+ color: var(--hmm-fg-faint);
1673
+ }
1674
+
1675
+ /* A column label the way the she UI writes one - small, semibold, muted, and with no vertical
1676
+ rule between the columns. The 2.x grid drew a full lattice; the header line alone is enough. */
1677
+ .hmm-th {
1678
+ position: relative;
1679
+ padding: 6px 6px;
1680
+ font-size: var(--hmm-font-size-small);
1681
+ font-weight: 600;
1682
+ letter-spacing: 0.02em;
1683
+ color: var(--hmm-fg-muted);
1684
+ overflow: hidden;
1685
+ text-overflow: ellipsis;
1686
+ white-space: nowrap;
1687
+ }
1688
+
1689
+ .hmm-th-button {
1690
+ display: inline-flex;
1691
+ gap: 4px;
1692
+ align-items: center;
1693
+ width: 100%;
1694
+ padding: 0;
1695
+ border: none;
1696
+ background: none;
1697
+ font: inherit;
1698
+ color: inherit;
1699
+ cursor: pointer;
1700
+ justify-content: inherit;
1701
+ }
1702
+
1703
+ .hmm-th-button:hover {
1704
+ color: var(--hmm-fg);
1705
+ }
1706
+
1707
+ .hmm-th-sort {
1708
+ font-size: var(--hmm-font-size-small);
1709
+ }
1710
+
1711
+ /*
1712
+ * The handle is the label's right padding. There is no rule between the columns, so
1713
+ * the edge only shows while the pointer is over the labels - a faint line where a column can be
1714
+ * dragged - and turns into the accent under the pointer, on focus and during a drag.
1715
+ */
1716
+ /*
1717
+ * Above its neighbours. The cells of the head that stand over a sub-grid-only column
1718
+ * come after the labels in the DOM and so paint over them; a finger is hit-tested with an
1719
+ * area rather than a point, and 3 px inside TYPE's handle it landed on the DIRECTION cell next
1720
+ * to it - found when the Msgs column became resizable and moved the columns by a few pixels.
1721
+ */
1722
+ .hmm-th-resize {
1723
+ position: absolute;
1724
+ z-index: 1;
1725
+ top: 0;
1726
+ right: 0;
1727
+ bottom: 0;
1728
+ width: 7px;
1729
+ cursor: col-resize;
1730
+ touch-action: none;
1731
+ outline: none;
1732
+ }
1733
+
1734
+ .hmm-th-resize::after {
1735
+ content: '';
1736
+ position: absolute;
1737
+ top: 5px;
1738
+ bottom: 5px;
1739
+ right: 0;
1740
+ width: 1px;
1741
+ background: transparent;
1742
+ }
1743
+
1744
+ /*
1745
+ * 7 px is a mouse's target, not a finger's - the addon is opened on tablets. Under a
1746
+ * coarse pointer the handle keeps its box and its line, and an invisible extension of it reaches
1747
+ * 24 px into the label, where a press still lands on the handle. Towards the left only: the cell
1748
+ * clips at its right edge, so anything past it could not be hit anyway. `touch-action: none`
1749
+ * above keeps the page from scrolling while a finger drags.
1750
+ */
1751
+ @media (pointer: coarse) {
1752
+ .hmm-th-resize::before {
1753
+ content: '';
1754
+ position: absolute;
1755
+ top: 0;
1756
+ bottom: 0;
1757
+ right: 0;
1758
+ width: 24px;
1759
+ }
1760
+ }
1761
+
1762
+ /* A sub-grid's label row carries the handles of the columns only the sub-grid has. */
1763
+ .hmm-tr-subhead .hmm-td {
1764
+ position: relative;
1765
+ }
1766
+
1767
+ .hmm-table-head:hover .hmm-th-resize::after,
1768
+ .hmm-tr-subhead:hover .hmm-th-resize::after {
1769
+ background: var(--hmm-border);
1770
+ }
1771
+
1772
+ .hmm-table-head .hmm-th-resize:hover::after,
1773
+ .hmm-tr-subhead .hmm-th-resize:hover::after,
1774
+ .hmm-th-resize:focus-visible::after,
1775
+ .hmm-table-head .hmm-th-resize-active::after,
1776
+ .hmm-tr-subhead .hmm-th-resize-active::after {
1777
+ top: 2px;
1778
+ bottom: 2px;
1779
+ width: 3px;
1780
+ background: var(--hmm-accent);
1781
+ }
1782
+
1783
+ .hmm-tf {
1784
+ padding: 3px 4px;
1785
+ min-width: 0;
1786
+ }
1787
+
1788
+ .hmm-tf-input {
1789
+ width: 100%;
1790
+ height: 20px;
1791
+ }
1792
+
1793
+ /* a list of choices in the filter row: the field's box, the text not cut by the control's own padding */
1794
+ .hmm-tf-select {
1795
+ padding: 0 2px;
1796
+ }
1797
+
1798
+ .hmm-table-body {
1799
+ flex: 1 1 auto;
1800
+ min-height: 0;
1801
+ overflow: auto;
1802
+ /* The head is a sibling and does not scroll; a gutter that appears and disappears with the
1803
+ row count would move every proportional column under it. */
1804
+ scrollbar-gutter: stable;
1805
+ position: relative;
1806
+ }
1807
+
1808
+ .hmm-table-spacer {
1809
+ position: relative;
1810
+ }
1811
+
1812
+ .hmm-table-rows {
1813
+ position: absolute;
1814
+ top: 0;
1815
+ left: 0;
1816
+ right: 0;
1817
+ min-width: var(--hmm-table-min-width);
1818
+ will-change: transform;
1819
+ }
1820
+
1821
+ .hmm-tr {
1822
+ display: grid;
1823
+ grid-template-columns: var(--hmm-table-columns);
1824
+ align-items: center;
1825
+ border-bottom: 1px solid var(--hmm-border-muted);
1826
+ background: var(--hmm-row-odd);
1827
+ cursor: default;
1828
+ }
1829
+
1830
+ /* The she UI gives its tables no zebra; the row separator carries the eye instead. The class stays
1831
+ and follows the absolute row index, so bringing the stripes back is one token. */
1832
+ .hmm-tr-even {
1833
+ background: var(--hmm-row-even);
1834
+ }
1835
+
1836
+ .hmm-tr:hover {
1837
+ background: var(--hmm-row-hover);
1838
+ }
1839
+
1840
+ .hmm-tr-child {
1841
+ background: var(--hmm-bg-sunken);
1842
+ }
1843
+
1844
+ /* The 2.x subgrid drew its own header line above a device's channels. */
1845
+ .hmm-tr-subhead,
1846
+ .hmm-tr-subhead:hover {
1847
+ background: var(--hmm-header-solid);
1848
+ font-weight: bold;
1849
+ cursor: default;
1850
+ }
1851
+
1852
+ .hmm-tr-selected,
1853
+ .hmm-tr-selected:hover {
1854
+ background: var(--hmm-row-selected);
1855
+ color: var(--hmm-row-selected-text);
1856
+ }
1857
+
1858
+ .hmm-td {
1859
+ padding: 0 6px;
1860
+ overflow: hidden;
1861
+ text-overflow: ellipsis;
1862
+ white-space: nowrap;
1863
+ }
1864
+
1865
+ /*
1866
+ * A fixed column holds a picture, a glyph or a control, never running text, and a
1867
+ * control a pixel wider than its track made the browser draw the ellipsis of `text-overflow`
1868
+ * beside it - the "überflüssiger Punkt" behind every receiver marker of the Funk grid, in
1869
+ * every row. There is nothing to abbreviate in such a cell, so it clips instead.
1870
+ */
1871
+ .hmm-td-fixed {
1872
+ text-overflow: clip;
1873
+ }
1874
+
1875
+ /*
1876
+ * The copy button of a name or an address cell. It lies over the end of the text rather
1877
+ * than beside it, so the column keeps its width, the text does not move and the cut-off check
1878
+ * measures what it measured before. `background-color: inherit` through the cell gives the button
1879
+ * the row's own ground - hovered, selected, a channel - so the text under it does not show through.
1880
+ */
1881
+ .hmm-td-copy {
1882
+ position: relative;
1883
+ background-color: inherit;
1884
+ }
1885
+
1886
+ .hmm-copy {
1887
+ position: absolute;
1888
+ top: 50%;
1889
+ right: 2px;
1890
+ display: flex;
1891
+ align-items: center;
1892
+ justify-content: center;
1893
+ width: 16px;
1894
+ height: 16px;
1895
+ padding: 0;
1896
+ border: none;
1897
+ border-radius: 2px;
1898
+ background-color: inherit;
1899
+ color: var(--hmm-fg-muted);
1900
+ cursor: pointer;
1901
+ opacity: 0;
1902
+ transform: translateY(-50%);
1903
+ }
1904
+
1905
+ /* Opacity, not visibility: a button that is not shown is still one the keyboard can reach. */
1906
+ .hmm-tr:hover .hmm-copy,
1907
+ .hmm-copy:focus-visible,
1908
+ .hmm-copy-shown {
1909
+ opacity: 1;
1910
+ }
1911
+
1912
+ .hmm-copy:hover {
1913
+ color: var(--hmm-fg);
1914
+ background-color: var(--hmm-control-bg-hover);
1915
+ }
1916
+
1917
+ .hmm-copy:focus-visible {
1918
+ outline: 1px solid var(--hmm-accent);
1919
+ outline-offset: -1px;
1920
+ }
1921
+
1922
+ .hmm-tr-selected .hmm-copy {
1923
+ color: inherit;
1924
+ }
1925
+
1926
+ .hmm-copy-icon {
1927
+ width: 10px;
1928
+ height: 10px;
1929
+ fill: none;
1930
+ stroke: currentColor;
1931
+ stroke-width: 1.1;
1932
+ stroke-linecap: round;
1933
+ stroke-linejoin: round;
1934
+ }
1935
+
1936
+ /* A touch screen has no hover: the button is always there, and big enough for a finger. */
1937
+ @media (pointer: coarse) {
1938
+ .hmm-copy {
1939
+ width: 22px;
1940
+ height: 22px;
1941
+ opacity: 1;
1942
+ }
1943
+ }
1944
+
1945
+ .hmm-table-announce {
1946
+ position: absolute;
1947
+ width: 1px;
1948
+ height: 1px;
1949
+ overflow: hidden;
1950
+ clip-path: inset(50%);
1951
+ white-space: nowrap;
1952
+ }
1953
+
1954
+ .hmm-td-expander,
1955
+ .hmm-th-expander {
1956
+ padding: 0;
1957
+ text-align: center;
1958
+ }
1959
+
1960
+ .hmm-expander {
1961
+ width: 18px;
1962
+ height: 18px;
1963
+ padding: 0;
1964
+ line-height: 1;
1965
+ border: 1px solid var(--hmm-border);
1966
+ border-radius: 2px;
1967
+ background: none;
1968
+ color: var(--hmm-fg-muted);
1969
+ cursor: pointer;
1970
+ }
1971
+
1972
+ .hmm-expander:hover {
1973
+ background: var(--hmm-control-bg-hover);
1974
+ color: var(--hmm-fg);
1975
+ }
1976
+
1977
+ .hmm-table-empty {
1978
+ display: flex;
1979
+ align-items: center;
1980
+ gap: 8px;
1981
+ padding: 8px;
1982
+ color: var(--hmm-fg-muted);
1983
+ }
1984
+
1985
+ .hmm-table-clear {
1986
+ height: 22px;
1987
+ padding: 0 8px;
1988
+ font-size: var(--hmm-font-size-small);
1989
+ }
1990
+ </style>