@dolusoft/query-table 3.17.0 → 3.19.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.
@@ -0,0 +1,4928 @@
1
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createStaticVNode, createTextVNode, createVNode, defineComponent, effectScope, getCurrentInstance, getCurrentScope, guardReactiveProps, h, inject, mergeProps, nextTick, normalizeProps, normalizeStyle, onActivated, onBeforeUnmount, onBeforeUpdate, onDeactivated, onMounted, onScopeDispose, openBlock, provide, renderList, renderSlot, shallowRef, toDisplayString, toHandlers, toValue, unref, useSlots, watch, watchEffect, withCtx, withKeys, withModifiers } from "vue";
2
+ import { cloneQuery, columnTypeOf, columnTypeOf as columnTypeOf$1, conditionArity, conditionLabel, conditionOptions, isCursorQuery, parseFilterInput, rulesOf, sameQuery, searchOf } from "@dolusoft/query-protocol";
3
+ import { createRowChangeTracker } from "@dolusoft/query-table-core/row-changes";
4
+ import { dispose, filterInputFeature, projectServerQuery, serverQueryFeature } from "@dolusoft/query-table-core";
5
+ import { columnFilteringFeature, columnOrderingFeature, columnPinningFeature, columnVisibilityFeature, functionalUpdate, globalFilteringFeature, rowExpandingFeature, rowPaginationFeature, rowPinningFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable } from "@tanstack/vue-table";
6
+ //#region src/body/use-row-navigation.ts
7
+ /**
8
+ * The first focusable element of a row, when no `focus` selector is given.
9
+ * Controls that use the arrow keys themselves (text fields, `select`, radio
10
+ * buttons, editable content) are left out: they keep their keys (C-109).
11
+ */
12
+ var focusable$1 = [
13
+ "a[href]",
14
+ "button:not([disabled])",
15
+ "input[type=\"checkbox\"]:not([disabled])",
16
+ "[tabindex]:not([tabindex=\"-1\"]):not(input, select, textarea, [contenteditable])"
17
+ ].join(", ");
18
+ var keys = /* @__PURE__ */ new Set([
19
+ "ArrowUp",
20
+ "ArrowDown",
21
+ "Home",
22
+ "End"
23
+ ]);
24
+ /** Frames a move waits for its row to be drawn and to keep the focus. */
25
+ var maxFrames = 30;
26
+ /** Frames the focus must stay on the target before a move is done. */
27
+ var keepFrames = 2;
28
+ /**
29
+ * Keyboard navigation between the data rows (C-109 to C-111): one `keydown`
30
+ * listener on the `tbody`, only while `rowNavigation` is on. A move goes by
31
+ * the row's key, not its index: the rows may change while a virtual body
32
+ * draws the row (C-110), and the focus is put back when moving DOM nodes
33
+ * drops it.
34
+ */
35
+ var useRowNavigation = (o) => {
36
+ const settings = computed(() => {
37
+ const value = o.rowNavigation();
38
+ return value === true ? {} : value || null;
39
+ });
40
+ const enabled = () => settings.value !== null;
41
+ const body = () => o.table.value?.tBodies[0] ?? null;
42
+ /** The focus target of a drawn row, or `null`. */
43
+ const targetOf = (tr) => tr.querySelector(settings.value?.focus ?? focusable$1);
44
+ /** The data row of the body that holds `element`, or `null`. */
45
+ const rowOf = (element, tbody) => {
46
+ let tr = element?.closest?.("tr") ?? null;
47
+ while (tr && tr.parentElement !== tbody) tr = tr.parentElement?.closest("tr") ?? null;
48
+ return tr?.hasAttribute("data-row-index") ? tr : null;
49
+ };
50
+ /** Position in drawing order of the move's row, or -1. */
51
+ const positionOf = (rows, m) => o.hasRowKey() ? rows.findIndex((item) => o.keyOf(item.row, item.index) === m.key) : rows.findIndex((item) => item.row === m.row);
52
+ /** The next stop from `from` for `key`: a row `skip` does not name. */
53
+ const stopFrom = (rows, from, key) => {
54
+ const skip = settings.value?.skip;
55
+ const stop = (p) => !skip || !skip(rows[p].row, rows[p].index);
56
+ const step = key === "ArrowUp" || key === "End" ? -1 : 1;
57
+ let p = key === "Home" ? 0 : key === "End" ? rows.length - 1 : from + step;
58
+ while (p >= 0 && p < rows.length && !stop(p)) p += step;
59
+ return p >= 0 && p < rows.length ? p : -1;
60
+ };
61
+ let move = null;
62
+ let frame = 0;
63
+ const stop = () => {
64
+ move = null;
65
+ cancelAnimationFrame(frame);
66
+ frame = 0;
67
+ removeEventListener("pointerdown", stop, true);
68
+ };
69
+ const again = () => {
70
+ if (!frame) frame = requestAnimationFrame(tick);
71
+ };
72
+ /**
73
+ * The focus is where the move left it, or nowhere: a click or a script
74
+ * that moved it elsewhere ends the move.
75
+ */
76
+ const free = (m) => {
77
+ const active = document.activeElement;
78
+ return !active || active === document.body || active === m.origin || active === m.landed || !active.isConnected;
79
+ };
80
+ /**
81
+ * Puts the focus on the move's row; `true` when it has it. A row of a
82
+ * virtual body that is not drawn is scrolled to (C-110): again when the
83
+ * window dropped the scroll because `rows` changed (C-87), and right away
84
+ * with `scroll`.
85
+ */
86
+ const land = (m, scroll = false) => {
87
+ const tbody = body();
88
+ const rows = o.bodyRows();
89
+ const p = positionOf(rows, m);
90
+ if (!tbody || p < 0) {
91
+ stop();
92
+ return false;
93
+ }
94
+ const { index, pinned } = rows[p];
95
+ const tr = tbody.querySelector(`:scope > tr[data-row-index="${index}"]`);
96
+ if (!tr) {
97
+ if (o.virtual() && !pinned && (scroll || !o.busy())) o.scrollToIndex(index, { align: "auto" });
98
+ return false;
99
+ }
100
+ const target = targetOf(tr);
101
+ if (!target) {
102
+ stop();
103
+ return false;
104
+ }
105
+ target.focus({ preventScroll: true });
106
+ if (document.activeElement !== target) return false;
107
+ const first = m.landed === null;
108
+ m.landed = target;
109
+ if (first) {
110
+ o.reveal(index);
111
+ o.onFocus({
112
+ row: rows[p].row,
113
+ rowIndex: index,
114
+ key: m.pressed
115
+ });
116
+ }
117
+ return true;
118
+ };
119
+ function tick() {
120
+ frame = 0;
121
+ const m = move;
122
+ if (!m) return;
123
+ if (++m.frames > maxFrames || !free(m)) {
124
+ stop();
125
+ return;
126
+ }
127
+ if (m.landed && document.activeElement === m.landed) {
128
+ if (!o.busy() && ++m.kept >= keepFrames) {
129
+ stop();
130
+ return;
131
+ }
132
+ again();
133
+ return;
134
+ }
135
+ if (!o.busy()) land(m);
136
+ if (move) again();
137
+ }
138
+ const onKeyDown = (event) => {
139
+ if (!enabled() || !keys.has(event.key) || event.defaultPrevented || event.isComposing || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
140
+ const tbody = event.currentTarget;
141
+ const target = event.target;
142
+ const waiting = move && !move.landed && target === move.origin ? move : null;
143
+ const tr = rowOf(target, tbody);
144
+ if (!waiting && (!tr || targetOf(tr) !== target)) return;
145
+ const rows = o.bodyRows();
146
+ const from = waiting ? positionOf(rows, waiting) : rows.findIndex((item) => item.index === Number(tr.getAttribute("data-row-index")));
147
+ if (from < 0) return;
148
+ event.preventDefault();
149
+ const to = stopFrom(rows, from, event.key);
150
+ if (to < 0 || to === from) return;
151
+ stop();
152
+ const { row, index } = rows[to];
153
+ const m = {
154
+ key: o.keyOf(row, index),
155
+ row,
156
+ pressed: event.key,
157
+ origin: waiting ? waiting.origin : target,
158
+ landed: null,
159
+ frames: 0,
160
+ kept: 0
161
+ };
162
+ move = m;
163
+ addEventListener("pointerdown", stop, true);
164
+ land(m, true);
165
+ if (move) again();
166
+ };
167
+ onBeforeUnmount(stop);
168
+ return {
169
+ enabled,
170
+ onKeyDown
171
+ };
172
+ };
173
+ //#endregion
174
+ //#region src/columns/column-layout.ts
175
+ var sideOf = (column) => column.pinned === "left" ? "left" : column.pinned === "right" ? "right" : false;
176
+ /** A copy of `column` without `key`: a default is removed, never set (C-68). */
177
+ var without = (column, key) => {
178
+ const copy = { ...column };
179
+ delete copy[key];
180
+ return copy;
181
+ };
182
+ /** The columns with the visibility of `visibility`; `null` when nothing changes. */
183
+ var applyVisibility = (columns, visibility) => {
184
+ let changed = false;
185
+ const next = columns.map((column) => {
186
+ const visible = visibility[column.field] ?? true;
187
+ if (visible === !column.hide) return column;
188
+ changed = true;
189
+ return visible ? without(column, "hide") : {
190
+ ...column,
191
+ hide: true
192
+ };
193
+ });
194
+ return changed ? next : null;
195
+ };
196
+ /** The columns in `order` (unknown fields skipped, missing ones kept last); `null` when unchanged. */
197
+ var applyOrder = (columns, order) => {
198
+ const byField = new Map(columns.map((column) => [column.field, column]));
199
+ const placed = /* @__PURE__ */ new Set();
200
+ const next = [];
201
+ for (const field of order) {
202
+ const column = byField.get(field);
203
+ if (column && !placed.has(field)) {
204
+ placed.add(field);
205
+ next.push(column);
206
+ }
207
+ }
208
+ next.push(...columns.filter((column) => !placed.has(column.field)));
209
+ return next.every((column, index) => column === columns[index]) ? null : next;
210
+ };
211
+ /** The columns with the sides of `pinning` (start = left, end = right); `null` when unchanged. */
212
+ var applyPinning = (columns, pinning) => {
213
+ const left = new Set(pinning.start ?? []);
214
+ const right = new Set(pinning.end ?? []);
215
+ let changed = false;
216
+ const next = columns.map((column) => {
217
+ const side = left.has(column.field) ? "left" : right.has(column.field) ? "right" : false;
218
+ if (side === sideOf(column)) return column;
219
+ changed = true;
220
+ return side ? {
221
+ ...column,
222
+ pinned: side
223
+ } : without(column, "pinned");
224
+ });
225
+ return changed ? next : null;
226
+ };
227
+ /** The columns with `field` at `width`; `null` when it already has it. */
228
+ var applyWidth = (columns, field, width) => {
229
+ const at = columns.findIndex((column) => column.field === field);
230
+ if (at < 0 || columns[at].width === width) return null;
231
+ const next = [...columns];
232
+ next[at] = {
233
+ ...columns[at],
234
+ width
235
+ };
236
+ return next;
237
+ };
238
+ /**
239
+ * `field` taken out and put right before or after `target` (C-69): the
240
+ * columns between keep their place, hidden ones included.
241
+ */
242
+ var moveField = (fields, field, target, place) => {
243
+ if (field === target || !fields.includes(field)) return fields;
244
+ const rest = fields.filter((name) => name !== field);
245
+ const at = rest.indexOf(target);
246
+ if (at < 0) return fields;
247
+ rest.splice(place === "before" ? at : at + 1, 0, field);
248
+ return rest;
249
+ };
250
+ //#endregion
251
+ //#region src/core/labels.ts
252
+ /** English defaults of the `labels` prop (C-44). */
253
+ var defaultLabels = {
254
+ clearAllFilters: "Clear all filters",
255
+ expandRow: "Expand row",
256
+ openRightPanel: "Open right panel",
257
+ filterInput: (column) => `Filter ${column}`,
258
+ filterInputFrom: (column) => `Filter ${column} from`,
259
+ filterInputTo: (column) => `Filter ${column} to`,
260
+ filterOptions: (column) => `Filter options for ${column}`,
261
+ resizeColumn: (column) => `Resize ${column}`,
262
+ moveColumn: (column) => `Move ${column}`,
263
+ filterCondition: (condition, type) => conditionLabel(type, condition),
264
+ boolAll: "All",
265
+ boolTrue: "True",
266
+ boolFalse: "False",
267
+ selectRow: "Select row",
268
+ selectAllRows: "Select all rows"
269
+ };
270
+ var resolveLabels = (labels) => ({
271
+ ...defaultLabels,
272
+ ...labels
273
+ });
274
+ /** The name of a column in a label: its `title`, else its `field`. */
275
+ var columnName = (column) => column.title || column.field;
276
+ //#endregion
277
+ //#region src/core/table-context.ts
278
+ var tableContextKey = Symbol("query-table");
279
+ var provideTableContext = (context) => {
280
+ provide(tableContextKey, context);
281
+ };
282
+ var useTableContext = () => {
283
+ const context = inject(tableContextKey);
284
+ if (!context) throw new Error("Header parts must be rendered inside a QueryTable");
285
+ return context;
286
+ };
287
+ //#endregion
288
+ //#region src/filter/focus-filter.ts
289
+ var focusable = "input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
290
+ /**
291
+ * Focuses the filter of `field` in this table's own header (C-54). Header
292
+ * cells are walked directly, so a table nested in a slot is never searched.
293
+ * Returns whether the element took focus.
294
+ */
295
+ var focusFilterOf = (table, field) => {
296
+ const head = [...table?.children ?? []].find((child) => child.tagName === "THEAD");
297
+ for (const row of head?.children ?? []) for (const cell of row.children) {
298
+ if (cell.getAttribute("data-field") !== field) continue;
299
+ const target = [...[...cell.children].find((child) => child.classList.contains("qt-filter"))?.querySelectorAll(focusable) ?? []].find((element) => !element.classList.contains("qt-filter-button"));
300
+ if (!target) return false;
301
+ target.focus();
302
+ return target.ownerDocument.activeElement === target;
303
+ }
304
+ return false;
305
+ };
306
+ /**
307
+ * Focuses the first filter of this table's header that takes the focus, in
308
+ * column order (C-22). Returns whether one did.
309
+ */
310
+ var focusFirstFilter = (table) => {
311
+ const head = [...table?.children ?? []].find((child) => child.tagName === "THEAD");
312
+ for (const row of head?.children ?? []) for (const cell of row.children) {
313
+ const field = cell.getAttribute("data-field");
314
+ if (field !== null && focusFilterOf(table, field)) return true;
315
+ }
316
+ return false;
317
+ };
318
+ //#endregion
319
+ //#region src/flash/marks.ts
320
+ /** A mark that is still running at `now`, else `null`. */
321
+ var live = (mark, now) => mark && mark.end > now ? mark : null;
322
+ /**
323
+ * The marks of one table (C-94): row and cell flashes by row key. Starting
324
+ * a flash that runs already restarts it, and the phase changes at most once
325
+ * a frame, so changes within one frame are one visual restart (K33-4).
326
+ */
327
+ var createMarks = () => {
328
+ const byKey = /* @__PURE__ */ new Map();
329
+ let gen = 0;
330
+ const restart = (mark, now, duration, frame) => {
331
+ gen++;
332
+ if (!mark) return {
333
+ start: now,
334
+ end: now + duration,
335
+ gen,
336
+ phase: "a",
337
+ flipFrame: frame
338
+ };
339
+ mark.start = now;
340
+ mark.end = now + duration;
341
+ mark.gen = gen;
342
+ if (mark.flipFrame !== frame) {
343
+ mark.phase = mark.phase === "a" ? "b" : "a";
344
+ mark.flipFrame = frame;
345
+ }
346
+ return mark;
347
+ };
348
+ const entry = (key) => {
349
+ let marks = byKey.get(key);
350
+ if (!marks) {
351
+ marks = {
352
+ row: null,
353
+ cells: null
354
+ };
355
+ byKey.set(key, marks);
356
+ }
357
+ return marks;
358
+ };
359
+ /** Flash the row of `key`; its cell flashes go (a new row is new as a whole). */
360
+ const flashRow = (key, now, duration, frame) => {
361
+ const marks = entry(key);
362
+ marks.row = restart(marks.row, now, duration, frame);
363
+ marks.cells?.clear();
364
+ };
365
+ const flashCell = (key, field, now, duration, frame) => {
366
+ const marks = entry(key);
367
+ const cells = marks.cells ??= /* @__PURE__ */ new Map();
368
+ cells.set(field, restart(cells.get(field), now, duration, frame));
369
+ };
370
+ const isEmpty = (marks) => marks.row === null && (marks.cells === null || marks.cells.size === 0);
371
+ /** Drop every row flash (`flash.rows` turned off). True when one went. */
372
+ const clearRows = () => {
373
+ let dropped = false;
374
+ for (const [key, marks] of byKey) {
375
+ if (marks.row) {
376
+ marks.row = null;
377
+ dropped = true;
378
+ }
379
+ if (isEmpty(marks)) byKey.delete(key);
380
+ }
381
+ return dropped;
382
+ };
383
+ /** Drop the cell flashes of `fields`, or of every field. True when one went. */
384
+ const clearCells = (fields) => {
385
+ let dropped = false;
386
+ for (const [key, marks] of byKey) {
387
+ const cells = marks.cells;
388
+ if (cells && cells.size > 0) {
389
+ if (fields) for (const field of fields) dropped = cells.delete(field) || dropped;
390
+ else {
391
+ cells.clear();
392
+ dropped = true;
393
+ }
394
+ }
395
+ if (isEmpty(marks)) byKey.delete(key);
396
+ }
397
+ return dropped;
398
+ };
399
+ /** Drop everything. True when something went. */
400
+ const clear = () => {
401
+ const had = byKey.size > 0;
402
+ byKey.clear();
403
+ return had;
404
+ };
405
+ /**
406
+ * Drop the marks that end by `until`; the nearest end of the ones left,
407
+ * or `Infinity`. True in `dropped` when one went.
408
+ */
409
+ const prune = (until) => {
410
+ let nearest = Infinity;
411
+ let dropped = false;
412
+ for (const [key, marks] of byKey) {
413
+ if (marks.row) {
414
+ if (marks.row.end <= until) {
415
+ marks.row = null;
416
+ dropped = true;
417
+ } else nearest = Math.min(nearest, marks.row.end);
418
+ }
419
+ if (marks.cells) for (const [field, mark] of marks.cells) if (mark.end <= until) {
420
+ marks.cells.delete(field);
421
+ dropped = true;
422
+ } else nearest = Math.min(nearest, mark.end);
423
+ if (isEmpty(marks)) byKey.delete(key);
424
+ }
425
+ return {
426
+ nearest,
427
+ dropped
428
+ };
429
+ };
430
+ return {
431
+ get: (key) => byKey.get(key),
432
+ get size() {
433
+ return byKey.size;
434
+ },
435
+ /** The generation of the last start. */
436
+ get gen() {
437
+ return gen;
438
+ },
439
+ flashRow,
440
+ flashCell,
441
+ clearRows,
442
+ clearCells,
443
+ clear,
444
+ prune
445
+ };
446
+ };
447
+ //#endregion
448
+ //#region src/flash/read-duration.ts
449
+ /** The custom property a skin sets the flash duration with (C-94). */
450
+ var durationProperty = "--qt-flash-duration";
451
+ /**
452
+ * A CSS time in milliseconds: `250ms`, `2s`, `.5s`. Anything else (a
453
+ * missing value, `calc()`, a negative or a zero time, a number without a
454
+ * unit) is `0`: no flash.
455
+ */
456
+ var parseDuration = (text) => {
457
+ const match = /^\s*(\d*\.?\d+(?:e[+-]?\d+)?)(ms|s)\s*$/i.exec(text);
458
+ if (!match) return 0;
459
+ const value = Number(match[1]) * (match[2].toLowerCase() === "s" ? 1e3 : 1);
460
+ return Number.isFinite(value) && value > 0 ? value : 0;
461
+ };
462
+ /**
463
+ * The flash duration the skin set on the table root (`.qt-datatable`) or
464
+ * above it, in milliseconds; `0` without one. One style read: the caller
465
+ * reads it at most once a frame, and only for an update that marks
466
+ * something (C-94).
467
+ */
468
+ var readDuration = (table) => {
469
+ const root = table?.closest(".qt-datatable");
470
+ if (!root) return 0;
471
+ return parseDuration(getComputedStyle(root).getPropertyValue(durationProperty));
472
+ };
473
+ //#endregion
474
+ //#region src/flash/use-change-flash.ts
475
+ var warn = (message) => {
476
+ try {
477
+ if (process.env.NODE_ENV === "production") return;
478
+ } catch {}
479
+ console.warn(`[QueryTable] ${message}`);
480
+ };
481
+ /** The inline custom property of an element bound after its flash began. */
482
+ var elapsedProperty = "--qt-flash-elapsed";
483
+ var kindsOf = (value) => typeof value === "object" ? {
484
+ rows: value.rows !== false,
485
+ cells: value.cells !== false
486
+ } : {
487
+ rows: true,
488
+ cells: true
489
+ };
490
+ var keyReader = (rowKey) => (row, index) => typeof rowKey === "function" ? rowKey(row, index) : row[rowKey];
491
+ /**
492
+ * The flash of one table while `flash` is on: feeds the tracker, keeps the
493
+ * marks, reads the duration, runs the one timer and binds the elapsed time.
494
+ * It lives in the effect scope it is created in and goes with it.
495
+ */
496
+ var startFlash = (o) => {
497
+ let rowKey = o.rowKey();
498
+ let keyOf = rowKey === void 0 ? null : keyReader(rowKey);
499
+ const newTracker = () => createRowChangeTracker((row, index) => keyOf(row, index));
500
+ let tracker = newTracker();
501
+ const marks = createMarks();
502
+ /** Bumped when the drawn marks change: the body reads it. */
503
+ const version = shallowRef(0);
504
+ let kinds = kindsOf(o.flash());
505
+ let active = true;
506
+ let warnedKey = false;
507
+ let warnedBadKeys = false;
508
+ let frame = 0;
509
+ let frameRequest;
510
+ /** The duration read in this frame (valid while a frame is requested). */
511
+ let duration = 0;
512
+ let timer;
513
+ /** The end the timer wakes at. */
514
+ let timerAt = Infinity;
515
+ /**
516
+ * The first generation started in the update being drawn: an element
517
+ * bound to it in the same render gets no elapsed time.
518
+ */
519
+ let freshFrom = Infinity;
520
+ /** A frame went by: the next change flips the phase, the duration is read again. */
521
+ const requestFrame = () => {
522
+ frameRequest ??= requestAnimationFrame(() => {
523
+ frameRequest = void 0;
524
+ frame++;
525
+ });
526
+ };
527
+ const durationNow = () => {
528
+ if (frameRequest === void 0) {
529
+ duration = readDuration(o.table.value);
530
+ requestFrame();
531
+ }
532
+ return duration;
533
+ };
534
+ const stopClock = () => {
535
+ if (timer !== void 0) {
536
+ clearTimeout(timer);
537
+ timer = void 0;
538
+ timerAt = Infinity;
539
+ }
540
+ if (frameRequest !== void 0) {
541
+ cancelAnimationFrame(frameRequest);
542
+ frameRequest = void 0;
543
+ }
544
+ };
545
+ /** Wake at `end`: drop what ended, then wake at the next end. */
546
+ const wakeAt = (end) => {
547
+ if (timer !== void 0) clearTimeout(timer);
548
+ timerAt = end;
549
+ timer = setTimeout(() => {
550
+ timer = void 0;
551
+ timerAt = Infinity;
552
+ const { nearest, dropped } = marks.prune(performance.now());
553
+ if (dropped) {
554
+ pruneDrawn();
555
+ version.value++;
556
+ }
557
+ if (nearest !== Infinity) wakeAt(nearest);
558
+ }, Math.max(0, end - performance.now()));
559
+ };
560
+ /** Everything goes: marks, timer, frame and the rows compared against. */
561
+ const resetAll = () => {
562
+ tracker.clear();
563
+ stopClock();
564
+ drawn.clear();
565
+ if (marks.clear()) version.value++;
566
+ };
567
+ /**
568
+ * The last `RowFlash` of each row key, with the live marks it was made
569
+ * from as a text of copied numbers (field, phase, generation): never the
570
+ * `Mark` objects, which a restart updates in place. Pruned with the marks.
571
+ */
572
+ const drawn = /* @__PURE__ */ new Map();
573
+ const pruneDrawn = () => {
574
+ for (const key of drawn.keys()) if (!marks.get(key)) drawn.delete(key);
575
+ };
576
+ const update = () => {
577
+ if (!active) return;
578
+ if (o.rowKey() !== rowKey) {
579
+ rowKey = o.rowKey();
580
+ keyOf = rowKey === void 0 ? null : keyReader(rowKey);
581
+ resetAll();
582
+ tracker = newTracker();
583
+ }
584
+ if (keyOf === null) {
585
+ if (!warnedKey) {
586
+ warnedKey = true;
587
+ warn("`flash` needs `rowKey`; it is ignored without one (C-93).");
588
+ }
589
+ return;
590
+ }
591
+ let changed = false;
592
+ const next = kindsOf(o.flash());
593
+ if (!next.rows && kinds.rows) changed = marks.clearRows() || changed;
594
+ if (!next.cells && kinds.cells) changed = marks.clearCells() || changed;
595
+ kinds = next;
596
+ const result = tracker.update({
597
+ rows: o.rows(),
598
+ query: o.query(),
599
+ loading: o.loading(),
600
+ fields: kinds.cells ? o.fields() : [],
601
+ hint: o.rowsUpdate(),
602
+ quiet: document.hidden
603
+ });
604
+ if (result.badKeys && !warnedBadKeys) {
605
+ warnedBadKeys = true;
606
+ warn("`flash` found a row without a `rowKey` value, or a key two rows share; the index is never used instead (C-93).");
607
+ }
608
+ if (result.reset) {
609
+ stopClock();
610
+ changed = marks.clear() || changed;
611
+ }
612
+ if (result.droppedFields.length > 0) changed = marks.clearCells(result.droppedFields) || changed;
613
+ const added = kinds.rows ? result.added : [];
614
+ const cells = kinds.cells ? result.changed : null;
615
+ if (added.length > 0 || cells !== null && cells.size > 0) {
616
+ const length = durationNow();
617
+ if (length > 0) {
618
+ const at = performance.now();
619
+ const firstGen = marks.gen + 1;
620
+ for (const key of added) marks.flashRow(key, at, length, frame);
621
+ cells?.forEach((fields, key) => {
622
+ for (const field of fields) marks.flashCell(key, field, at, length, frame);
623
+ });
624
+ changed = true;
625
+ if (freshFrom === Infinity) {
626
+ freshFrom = firstGen;
627
+ nextTick(() => {
628
+ freshFrom = Infinity;
629
+ });
630
+ }
631
+ requestFrame();
632
+ if (at + length < timerAt) wakeAt(at + length);
633
+ }
634
+ }
635
+ if (changed) {
636
+ pruneDrawn();
637
+ version.value++;
638
+ }
639
+ };
640
+ update();
641
+ /** The generation bound to an element, and the elapsed value written on it. */
642
+ const bound = /* @__PURE__ */ new WeakMap();
643
+ const written = /* @__PURE__ */ new WeakMap();
644
+ /** Rows with something bound on them or on one of their cells. */
645
+ const boundRows = /* @__PURE__ */ new WeakSet();
646
+ /** The row flash a cell was last seen under. */
647
+ const seenUnder = /* @__PURE__ */ new WeakMap();
648
+ const bindTo = (el, mark, now, blockInherited) => {
649
+ const gen = bound.get(el);
650
+ if (!mark) {
651
+ if (gen !== void 0) {
652
+ bound.delete(el);
653
+ written.delete(el);
654
+ el.style.removeProperty(elapsedProperty);
655
+ }
656
+ return;
657
+ }
658
+ if (gen === mark.gen) {
659
+ const value = written.get(el) ?? "";
660
+ if (value !== "" && el.style.getPropertyValue(elapsedProperty) === "") el.style.setProperty(elapsedProperty, value);
661
+ return;
662
+ }
663
+ const elapsed = mark.gen >= freshFrom ? 0 : now - mark.start;
664
+ const value = elapsed >= 1 ? `${Math.round(elapsed)}ms` : blockInherited ? "0ms" : "";
665
+ if (value === "") el.style.removeProperty(elapsedProperty);
666
+ else el.style.setProperty(elapsedProperty, value);
667
+ bound.set(el, mark.gen);
668
+ written.set(el, value);
669
+ };
670
+ const view = {
671
+ of: (key) => {
672
+ version.value;
673
+ const rowMarks = keyOf === null ? void 0 : marks.get(key);
674
+ if (!rowMarks) {
675
+ drawn.delete(key);
676
+ return;
677
+ }
678
+ const now = performance.now();
679
+ const rowMark = live(rowMarks.row, now);
680
+ let text = rowMark ? `${rowMark.phase}${rowMark.gen}` : "";
681
+ rowMarks.cells?.forEach((mark, field) => {
682
+ if (live(mark, now)) text += `|${field}:${mark.phase}${mark.gen}`;
683
+ });
684
+ if (text === "") {
685
+ drawn.delete(key);
686
+ return;
687
+ }
688
+ const last = drawn.get(key);
689
+ if (last?.live === text) return last.flash;
690
+ const flash = {};
691
+ if (rowMark) flash.row = rowMark.phase;
692
+ let cells;
693
+ rowMarks.cells?.forEach((mark, field) => {
694
+ if (live(mark, now)) (cells ??= {})[field] = mark.phase;
695
+ });
696
+ if (cells) flash.cells = cells;
697
+ drawn.set(key, {
698
+ live: text,
699
+ flash
700
+ });
701
+ return flash;
702
+ },
703
+ bind: (tr, key) => {
704
+ if (keyOf === null) return;
705
+ const rowMarks = marks.get(key);
706
+ if (!rowMarks && !boundRows.has(tr)) return;
707
+ const now = performance.now();
708
+ const rowMark = live(rowMarks?.row, now);
709
+ const rowWasBound = rowMark !== null && bound.get(tr) === rowMark.gen;
710
+ bindTo(tr, rowMark, now, false);
711
+ const rowValue = written.get(tr) ?? "";
712
+ let any = bound.has(tr);
713
+ const cells = tr.children;
714
+ for (let i = 0; i < cells.length; i++) {
715
+ const td = cells[i];
716
+ const field = td.getAttribute("data-field");
717
+ const own = field === null ? null : live(rowMarks?.cells?.get(field), now);
718
+ if (own) bindTo(td, own, now, rowValue !== "");
719
+ else if (rowMark && (bound.get(td) === rowMark.gen || rowWasBound && seenUnder.get(td) !== rowMark.gen)) bindTo(td, rowMark, now, false);
720
+ else bindTo(td, null, now, false);
721
+ if (rowMark) seenUnder.set(td, rowMark.gen);
722
+ any ||= bound.has(td);
723
+ }
724
+ if (any) boundRows.add(tr);
725
+ else boundRows.delete(tr);
726
+ }
727
+ };
728
+ /** Remove the elapsed times written on the body. */
729
+ const unbindAll = () => {
730
+ const body = o.table.value?.tBodies[0];
731
+ if (!body) return;
732
+ const rows = body.children;
733
+ for (let i = 0; i < rows.length; i++) {
734
+ const tr = rows[i];
735
+ tr.style.removeProperty(elapsedProperty);
736
+ const cells = tr.children;
737
+ for (let j = 0; j < cells.length; j++) cells[j].style.removeProperty(elapsedProperty);
738
+ }
739
+ };
740
+ onScopeDispose(stopClock);
741
+ return {
742
+ view,
743
+ unbind: unbindAll,
744
+ update,
745
+ deactivate: () => {
746
+ active = false;
747
+ resetAll();
748
+ unbindAll();
749
+ },
750
+ activate: () => {
751
+ active = true;
752
+ update();
753
+ }
754
+ };
755
+ };
756
+ /**
757
+ * The change flash of `QueryTable` (C-93 to C-95). Off, it sets up one
758
+ * watcher that reads `flash` and nothing else: no comparison, timer, frame
759
+ * callback, listener, style read or memory per row. On, the same watcher
760
+ * also reads what the tracker compares, and the flash runs in an effect
761
+ * scope of its own; stopping that scope undoes everything. Nothing runs on
762
+ * the server: the flash starts once the table is mounted.
763
+ */
764
+ var useChangeFlash = (o) => {
765
+ const view = shallowRef(null);
766
+ const instance = getCurrentInstance();
767
+ const owner = getCurrentScope();
768
+ let scope = null;
769
+ let controller = null;
770
+ let hooked = false;
771
+ let mounted = false;
772
+ const start = () => {
773
+ scope = owner.run(() => effectScope());
774
+ controller = scope.run(() => startFlash(o));
775
+ view.value = controller.view;
776
+ if (!hooked) {
777
+ hooked = true;
778
+ onDeactivated(() => controller?.deactivate(), instance);
779
+ onActivated(() => controller?.activate(), instance);
780
+ }
781
+ };
782
+ const stop = () => {
783
+ controller?.unbind();
784
+ scope?.stop();
785
+ scope = null;
786
+ controller = null;
787
+ view.value = null;
788
+ };
789
+ watch(() => o.flash() ? [
790
+ o.flash(),
791
+ o.rows(),
792
+ o.query(),
793
+ o.loading(),
794
+ o.rowsUpdate(),
795
+ o.rowKey(),
796
+ o.fields()
797
+ ] : null, (on) => {
798
+ if (!mounted) return;
799
+ if (!on) stop();
800
+ else if (controller) controller.update();
801
+ else start();
802
+ });
803
+ onMounted(() => {
804
+ mounted = true;
805
+ if (o.flash()) start();
806
+ });
807
+ return view;
808
+ };
809
+ //#endregion
810
+ //#region src/header/use-header-context-menu.ts
811
+ /**
812
+ * One listener on the `thead` serves every header cell (C-96): a listener per
813
+ * cell would be a new closure per cell on every render. Only a data column
814
+ * header emits (`data-field`); utility cells keep the browser menu. A right
815
+ * click inside the filter row (`.qt-filter`) keeps the browser menu too, so
816
+ * paste and spell-check stay (issue #102 S1(a)).
817
+ */
818
+ var useHeaderContextMenu = (options) => {
819
+ const onContextMenu = (event) => {
820
+ if (!options.listening()) return;
821
+ const head = event.currentTarget;
822
+ let cell = event.target?.closest("th") ?? null;
823
+ while (cell && cell.parentElement?.parentElement !== head) cell = cell.parentElement?.closest("th") ?? null;
824
+ const field = cell?.getAttribute("data-field") ?? null;
825
+ if (field === null || !cell) return;
826
+ const target = event.target;
827
+ if (target?.closest(".qt-filter") && cell.contains(target.closest(".qt-filter"))) return;
828
+ const column = options.columns().find((c) => c.field === field);
829
+ const columnIndex = options.indexOf(field);
830
+ if (!column || columnIndex === void 0) return;
831
+ event.preventDefault();
832
+ options.onContextMenu({
833
+ event,
834
+ column,
835
+ columnIndex
836
+ });
837
+ };
838
+ return { onContextMenu };
839
+ };
840
+ //#endregion
841
+ //#region src/core/column.ts
842
+ /** Reads a dotted path (`'a.b'`) from a row. */
843
+ var valueAt = (row, path) => path.split(".").reduce((value, key) => value === null || value === void 0 ? void 0 : value[key], row);
844
+ //#endregion
845
+ //#region src/body/use-cell-view.ts
846
+ /**
847
+ * The context menu event of the body cells (C-28). What a cell shows is
848
+ * drawn by its row (`parts/table-row.ts`).
849
+ */
850
+ var useCellView = (options) => {
851
+ /**
852
+ * One listener on the `tbody` serves every cell (C-28): a listener per cell
853
+ * would be a new closure per cell on every render. The cell is the nearest
854
+ * `td` whose row is a direct child of this body. A table nested in a
855
+ * subtable row: the walk ends on the subtable `td`, which has no
856
+ * `data-field`, so this body stays quiet and the inner table answers for its
857
+ * own cells. A table nested in a `cell-<field>` slot: the inner table emits
858
+ * for its cell, then this body emits for the outer cell that holds it (the
859
+ * same as a listener on every cell did). Only a data cell counts: it carries
860
+ * `data-field`, and its row carries `data-row-index`.
861
+ */
862
+ const onContextMenu = (event) => {
863
+ if (!options.listening()) return;
864
+ const body = event.currentTarget;
865
+ let cell = event.target?.closest("td") ?? null;
866
+ while (cell && cell.parentElement?.parentElement !== body) cell = cell.parentElement?.closest("td") ?? null;
867
+ const field = cell?.getAttribute("data-field") ?? null;
868
+ const index = cell?.parentElement?.getAttribute("data-row-index") ?? null;
869
+ if (field === null || index === null) return;
870
+ const rowIndex = Number(index);
871
+ const row = options.rows()[rowIndex];
872
+ const entry = options.entries().find((e) => e.column.field === field);
873
+ if (row === void 0 || !entry) return;
874
+ event.preventDefault();
875
+ options.onContextMenu({
876
+ event,
877
+ row,
878
+ column: entry.column,
879
+ cellValue: valueAt(row, field),
880
+ rowIndex,
881
+ columnIndex: entry.index
882
+ });
883
+ };
884
+ return { onContextMenu };
885
+ };
886
+ //#endregion
887
+ //#region src/parts/table-row.ts
888
+ var value = () => ({ type: null });
889
+ var needed = () => ({
890
+ type: null,
891
+ required: true
892
+ });
893
+ var off = () => createCommentVNode("", true);
894
+ var panelIcon = () => createElementVNode("svg", {
895
+ width: "14",
896
+ height: "14",
897
+ viewBox: "0 0 24 24",
898
+ fill: "none",
899
+ stroke: "currentColor",
900
+ "stroke-width": "2",
901
+ "stroke-linecap": "round",
902
+ "aria-hidden": "true"
903
+ }, [createElementVNode("line", {
904
+ x1: "12",
905
+ y1: "5",
906
+ x2: "12",
907
+ y2: "19"
908
+ }), createElementVNode("line", {
909
+ x1: "5",
910
+ y1: "12",
911
+ x2: "19",
912
+ y2: "12"
913
+ })], -1);
914
+ var expandIcon = {
915
+ width: "14",
916
+ height: "14",
917
+ viewBox: "0 0 24 24",
918
+ fill: "none",
919
+ stroke: "currentColor",
920
+ "stroke-width": "2",
921
+ "stroke-linecap": "round",
922
+ "stroke-linejoin": "round",
923
+ "aria-hidden": "true"
924
+ };
925
+ var chevronDown = {
926
+ key: 0,
927
+ points: "6 9 12 15 18 9"
928
+ };
929
+ var chevronRight = {
930
+ key: 1,
931
+ points: "9 6 15 12 9 18"
932
+ };
933
+ var rowDynamic = [
934
+ "role",
935
+ "data-row-index",
936
+ "aria-rowindex",
937
+ "data-pinned-row",
938
+ "data-row-kind",
939
+ "data-expanded",
940
+ "data-selected",
941
+ "data-flash"
942
+ ];
943
+ var panelDynamic = ["aria-label", "onClick"];
944
+ var expandDynamic = [
945
+ "aria-expanded",
946
+ "aria-label",
947
+ "onClick"
948
+ ];
949
+ var selectDynamic = [
950
+ "aria-label",
951
+ "checked",
952
+ "onChange"
953
+ ];
954
+ /** Text of a cell, whole: the table never cuts it. */
955
+ var cellText = (row, column) => String(valueAt(row, column.field) ?? "");
956
+ /**
957
+ * One data row of the body (ADR 0017, C-106 to C-108): its `tr`, the
958
+ * utility cells and the column cells with their `cell-<field>` slots.
959
+ * Internal: not exported from the package.
960
+ *
961
+ * Every prop is a value the body computed for this row (K311-2), so Vue
962
+ * skips a row whose props did not change; the row's render calls no
963
+ * function that reads shared state. Its cell slots are called here, so what
964
+ * a slot reads reactively belongs to this row (K311-4). The render is
965
+ * written with the helpers compiled templates use, and draws the vnodes the
966
+ * `tr` branch of the body's template drew in 3.10 (C-108).
967
+ */
968
+ var tableRow = defineComponent({
969
+ name: "TableRow",
970
+ inheritAttrs: false,
971
+ props: {
972
+ row: needed(),
973
+ /** The row's key, as the body keys it (C-26). */
974
+ rowKey: needed(),
975
+ /** `data-row-index`: the row's index in `rows`. */
976
+ index: needed(),
977
+ /** `aria-rowindex`, with `virtual` only (C-86). */
978
+ aria: value(),
979
+ pinned: needed(),
980
+ /** `data-row-kind` (C-97); `undefined` for none. */
981
+ kind: value(),
982
+ selected: needed(),
983
+ expanded: needed(),
984
+ /** An expand button is drawn (C-98). */
985
+ expandable: needed(),
986
+ /** The row's flash marks (C-94), or `undefined`. */
987
+ flash: value(),
988
+ cells: needed(),
989
+ utilities: needed(),
990
+ labelPanel: needed(),
991
+ labelExpand: needed(),
992
+ labelSelect: needed(),
993
+ /** `scrollBody`: the ARIA roles of C-102. */
994
+ roles: value(),
995
+ /** The body's slots object: the same object for the body's life (K311-3). */
996
+ slots: needed(),
997
+ /** With `flash`: binds the elapsed time after a render (K311-6). */
998
+ flashBind: value(),
999
+ pinRow: needed()
1000
+ },
1001
+ emits: [
1002
+ "toggle",
1003
+ "toggleSelected",
1004
+ "rightPanel"
1005
+ ],
1006
+ setup(props, { emit }) {
1007
+ const onPanel = withModifiers(() => emit("rightPanel"), ["stop"]);
1008
+ const onToggle = () => emit("toggle");
1009
+ const onSelect = () => emit("toggleSelected");
1010
+ const bind = (vnode) => {
1011
+ props.flashBind?.(vnode.el, props.rowKey);
1012
+ };
1013
+ let panelCache = null;
1014
+ return () => {
1015
+ const { row, index, pinned, cells, utilities, flash, slots } = props;
1016
+ const cellFlash = flash?.cells;
1017
+ return openBlock(), createElementBlock("tr", {
1018
+ role: props.roles ? "row" : void 0,
1019
+ "data-row-index": index,
1020
+ "aria-rowindex": props.aria,
1021
+ "data-pinned-row": pinned || void 0,
1022
+ "data-row-kind": props.kind,
1023
+ "data-expanded": props.expanded ? "" : void 0,
1024
+ "data-selected": props.selected ? "" : void 0,
1025
+ "data-flash": flash?.row,
1026
+ onVnodeBeforeMount: props.flashBind ? bind : void 0,
1027
+ onVnodeUpdated: props.flashBind ? bind : void 0
1028
+ }, [
1029
+ utilities.panel ? (openBlock(), createElementBlock("td", mergeProps({ key: 0 }, utilities.panel), [createElementVNode("button", {
1030
+ type: "button",
1031
+ class: "qt-right-panel-button",
1032
+ "aria-label": props.labelPanel,
1033
+ onClick: onPanel
1034
+ }, [...panelCache ??= [panelIcon()]], 8, panelDynamic)], 16)) : off(),
1035
+ utilities.expand ? (openBlock(), createElementBlock("td", mergeProps({ key: 1 }, utilities.expand), [props.expandable ? (openBlock(), createElementBlock("button", {
1036
+ key: 0,
1037
+ type: "button",
1038
+ class: "qt-expand",
1039
+ "aria-expanded": props.expanded,
1040
+ "aria-label": props.labelExpand,
1041
+ onClick: onToggle
1042
+ }, [(openBlock(), createElementBlock("svg", expandIcon, [props.expanded ? (openBlock(), createElementBlock("polyline", chevronDown)) : (openBlock(), createElementBlock("polyline", chevronRight))]))], 8, expandDynamic)) : off()], 16)) : off(),
1043
+ utilities.select ? (openBlock(), createElementBlock("td", mergeProps({ key: 2 }, utilities.select), [createElementVNode("input", {
1044
+ type: "checkbox",
1045
+ class: "qt-select-row",
1046
+ "aria-label": props.labelSelect,
1047
+ checked: props.selected,
1048
+ onChange: onSelect
1049
+ }, null, 40, selectDynamic)], 16)) : off(),
1050
+ (openBlock(true), createElementBlock(Fragment, null, renderList(cells, (cell) => (openBlock(), createElementBlock(Fragment, { key: cell.field }, [cell.slot ? (openBlock(), createElementBlock("td", mergeProps({ key: 0 }, cell.attrs, { "data-flash": cellFlash?.[cell.field] }), [renderSlot(slots, cell.slot, {
1051
+ row,
1052
+ rowIndex: index,
1053
+ column: cell.column,
1054
+ cellValue: valueAt(row, cell.field),
1055
+ rowPinned: pinned,
1056
+ pinRow: (position) => props.pinRow(row, index, position)
1057
+ })], 16)) : (openBlock(), createElementBlock("td", mergeProps({ key: 1 }, cell.attrs, { "data-flash": cellFlash?.[cell.field] }), toDisplayString(cellText(row, cell.column)), 17))], 64))), 128))
1058
+ ], 8, rowDynamic);
1059
+ };
1060
+ }
1061
+ });
1062
+ //#endregion
1063
+ //#region src/pin/pin.ts
1064
+ /** Geometry key of a utility cell; a column's key is its `field`. */
1065
+ var utilityKey = (utility) => `utility:${utility}`;
1066
+ /**
1067
+ * Attributes of a pinned cell (C-47, C-71): `data-pinned` (`''` on the left,
1068
+ * `'right'` on the right) and, once measured, the `--qt-pin-left` or
1069
+ * `--qt-pin-right` offset in pixels, next to an optional `width`. Nothing but
1070
+ * the width for a cell that is not pinned; no `style` when both are absent.
1071
+ */
1072
+ var pinAttrs = (side, offset, width) => {
1073
+ const style = {};
1074
+ if (width) style.width = width;
1075
+ if (side && offset !== void 0) style[side === "left" ? "--qt-pin-left" : "--qt-pin-right"] = `${offset}px`;
1076
+ return {
1077
+ "data-pinned": side === "left" ? "" : side === "right" ? "right" : void 0,
1078
+ style: Object.keys(style).length > 0 ? style : void 0
1079
+ };
1080
+ };
1081
+ //#endregion
1082
+ //#region src/parts/table-body.vue?vue&type=script&setup=true&lang.ts
1083
+ var _hoisted_1$9 = ["role"];
1084
+ var _hoisted_2$5 = ["role"];
1085
+ var _hoisted_3$5 = ["role", "aria-rowindex"];
1086
+ var _hoisted_4$5 = [
1087
+ "colspan",
1088
+ "role",
1089
+ "aria-colspan"
1090
+ ];
1091
+ var _hoisted_5$3 = [
1092
+ "role",
1093
+ "aria-rowindex",
1094
+ "data-pinned-row"
1095
+ ];
1096
+ var _hoisted_6$2 = ["role"];
1097
+ var _hoisted_7$2 = ["role"];
1098
+ var _hoisted_8$2 = ["role"];
1099
+ //#endregion
1100
+ //#region src/parts/table-body.vue
1101
+ var table_body_default = /* @__PURE__ */ defineComponent({
1102
+ __name: "table-body",
1103
+ props: {
1104
+ rows: {},
1105
+ bodyRows: {},
1106
+ pinRow: { type: Function },
1107
+ loading: { type: Boolean },
1108
+ entries: {},
1109
+ slotNames: {},
1110
+ columnCount: {},
1111
+ hasSubtable: { type: Boolean },
1112
+ hasRightPanel: { type: Boolean },
1113
+ hasSelection: { type: Boolean },
1114
+ isSelected: { type: Function },
1115
+ toggleSelected: { type: Function },
1116
+ hasPinned: { type: Boolean },
1117
+ offsets: {},
1118
+ keyOf: { type: Function },
1119
+ canExpand: { type: Function },
1120
+ isExpanded: { type: Function },
1121
+ toggle: { type: Function },
1122
+ rowKind: { type: Function },
1123
+ labels: {},
1124
+ hasContextMenuListener: { type: Function },
1125
+ loadMore: {},
1126
+ flash: {},
1127
+ roles: { type: Boolean }
1128
+ },
1129
+ emits: ["rowRightPanelClick", "cellContextMenu"],
1130
+ setup(__props, { emit: __emit }) {
1131
+ const props = __props;
1132
+ const emit = __emit;
1133
+ const slots = useSlots();
1134
+ /**
1135
+ * The body's slots object: the same object for the life of the body, whose
1136
+ * functions Vue replaces before each render. Every row gets it as a prop and
1137
+ * calls the latest `cell-<field>` function when it renders (K311-3).
1138
+ */
1139
+ const rawSlots = useSlots();
1140
+ const { onContextMenu } = useCellView({
1141
+ rows: () => props.rows,
1142
+ entries: () => props.entries,
1143
+ listening: () => props.hasContextMenuListener(),
1144
+ onContextMenu: (payload) => emit("cellContextMenu", payload)
1145
+ });
1146
+ /** `role` of a row and of a cell with `scrollBody` (C-102). */
1147
+ const rowRole = () => props.roles ? "row" : void 0;
1148
+ const cellRole = () => props.roles ? "cell" : void 0;
1149
+ /** A cell over every column; with `scrollBody` also its `aria-colspan`. */
1150
+ const spanAttrs = () => ({
1151
+ colspan: props.columnCount,
1152
+ role: cellRole(),
1153
+ "aria-colspan": props.roles ? props.columnCount : void 0
1154
+ });
1155
+ const cells = computed((previous) => {
1156
+ const names = new Set(props.slotNames.split("\n"));
1157
+ const role = cellRole();
1158
+ let same = previous?.length === props.entries.length;
1159
+ const next = props.entries.map((entry, i) => {
1160
+ const { column } = entry;
1161
+ const field = column.field;
1162
+ const type = columnTypeOf$1(column);
1163
+ const side = sideOf(column);
1164
+ const offset = props.offsets[field];
1165
+ const slot = names.has(`cell-${field}`) ? `cell-${field}` : null;
1166
+ const old = previous?.[i];
1167
+ if (old && old.column === column && old.type === type && old.side === side && old.offset === offset && old.slot === slot && old.role === role) return old;
1168
+ same = false;
1169
+ return {
1170
+ field,
1171
+ column,
1172
+ type,
1173
+ side,
1174
+ offset,
1175
+ role,
1176
+ slot,
1177
+ attrs: {
1178
+ role,
1179
+ "data-field": field,
1180
+ "data-type": type,
1181
+ ...pinAttrs(side, offset)
1182
+ }
1183
+ };
1184
+ });
1185
+ return same && previous ? previous : next;
1186
+ });
1187
+ const utilities = computed((previous) => {
1188
+ const role = cellRole();
1189
+ const side = props.hasPinned ? "left" : false;
1190
+ const offsetOf = (utility) => props.offsets[utilityKey(utility)];
1191
+ const signature = [
1192
+ role,
1193
+ side,
1194
+ props.hasRightPanel && `p${offsetOf("right-panel")}`,
1195
+ props.hasSubtable && `e${offsetOf("subtable")}`,
1196
+ props.hasSelection && `s${offsetOf("select")}`
1197
+ ].join("|");
1198
+ if (previous?.signature === signature) return previous;
1199
+ const attrs = (on, utility) => on ? {
1200
+ role,
1201
+ ...pinAttrs(side, offsetOf(utility))
1202
+ } : null;
1203
+ return {
1204
+ panel: attrs(props.hasRightPanel, "right-panel"),
1205
+ expand: attrs(props.hasSubtable, "subtable"),
1206
+ select: attrs(props.hasSelection, "select"),
1207
+ signature
1208
+ };
1209
+ });
1210
+ const isSpacer = (item) => "spacer" in item;
1211
+ const isGroup = (item) => "group" in item;
1212
+ /** A data row: neither a spacer nor a group row. */
1213
+ const isRow = (item) => !isSpacer(item) && !isGroup(item);
1214
+ /** The identity of a body item in the `v-for`. */
1215
+ const itemKey = (item) => isRow(item) ? props.keyOf(item.row, item.index) : item.key;
1216
+ /** `data-row-kind` of a drawn row (C-97): no attribute for an empty kind. */
1217
+ const kindOf = (item) => props.rowKind ? props.rowKind(item.row, item.index) || void 0 : void 0;
1218
+ /** `aria-rowindex` of the subtable row under a drawn row (C-86). */
1219
+ const nextIndex = (aria) => aria === void 0 ? void 0 : aria + 1;
1220
+ let expandedSnapshot = null;
1221
+ onBeforeUpdate(() => {
1222
+ expandedSnapshot = null;
1223
+ });
1224
+ const isRowExpanded = (item) => {
1225
+ if (!isRow(item)) return false;
1226
+ if (!expandedSnapshot) {
1227
+ const open = /* @__PURE__ */ new Map();
1228
+ if (props.hasSubtable) {
1229
+ for (const row of props.bodyRows) if (isRow(row)) open.set(String(props.keyOf(row.row, row.index)), props.isExpanded(row.row, row.index));
1230
+ }
1231
+ expandedSnapshot = open;
1232
+ }
1233
+ return expandedSnapshot.get(String(props.keyOf(item.row, item.index))) === true;
1234
+ };
1235
+ return (_ctx, _cache) => {
1236
+ return openBlock(), createElementBlock("tbody", {
1237
+ role: __props.roles ? "rowgroup" : void 0,
1238
+ onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onContextMenu) && unref(onContextMenu)(...args))
1239
+ }, [
1240
+ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.bodyRows, (item) => {
1241
+ return openBlock(), createElementBlock(Fragment, { key: itemKey(item) }, [isSpacer(item) ? (openBlock(), createElementBlock("tr", {
1242
+ key: 0,
1243
+ class: "qt-virtual-spacer",
1244
+ "aria-hidden": "true",
1245
+ role: rowRole(),
1246
+ style: normalizeStyle({ height: `${item.spacer}px` })
1247
+ }, [createElementVNode("td", mergeProps({ ref_for: true }, spanAttrs()), null, 16)], 12, _hoisted_2$5)) : isGroup(item) ? (openBlock(), createElementBlock("tr", {
1248
+ key: 1,
1249
+ class: "qt-group-row",
1250
+ role: rowRole(),
1251
+ "aria-rowindex": item.aria
1252
+ }, [createElementVNode("th", {
1253
+ scope: "row",
1254
+ colspan: __props.columnCount,
1255
+ role: __props.roles ? "rowheader" : void 0,
1256
+ "aria-colspan": __props.roles ? __props.columnCount : void 0
1257
+ }, [renderSlot(_ctx.$slots, "group", {
1258
+ groupKey: item.group.key,
1259
+ count: item.group.count,
1260
+ row: item.group.row,
1261
+ rowIndex: item.group.index
1262
+ }, () => [createTextVNode(toDisplayString(item.group.key), 1)])], 8, _hoisted_4$5)], 8, _hoisted_3$5)) : (openBlock(), createBlock(unref(tableRow), {
1263
+ key: 2,
1264
+ row: item.row,
1265
+ "row-key": __props.keyOf(item.row, item.index),
1266
+ index: item.index,
1267
+ aria: item.aria,
1268
+ pinned: item.pinned,
1269
+ kind: kindOf(item),
1270
+ selected: __props.hasSelection && __props.isSelected(item.row, item.index),
1271
+ expanded: isRowExpanded(item),
1272
+ expandable: __props.hasSubtable && __props.canExpand(item.row, item.index),
1273
+ flash: __props.flash ? __props.flash.of(__props.keyOf(item.row, item.index)) : void 0,
1274
+ cells: cells.value,
1275
+ utilities: utilities.value,
1276
+ "label-panel": __props.labels.openRightPanel,
1277
+ "label-expand": __props.labels.expandRow,
1278
+ "label-select": __props.labels.selectRow,
1279
+ roles: __props.roles,
1280
+ slots: unref(rawSlots),
1281
+ "flash-bind": __props.flash ? __props.flash.bind : void 0,
1282
+ "pin-row": __props.pinRow,
1283
+ onToggle: ($event) => __props.toggle(item.row, item.index),
1284
+ onToggleSelected: ($event) => __props.toggleSelected(item.row, item.index),
1285
+ onRightPanel: ($event) => emit("rowRightPanelClick", item.row)
1286
+ }, null, 8, [
1287
+ "row",
1288
+ "row-key",
1289
+ "index",
1290
+ "aria",
1291
+ "pinned",
1292
+ "kind",
1293
+ "selected",
1294
+ "expanded",
1295
+ "expandable",
1296
+ "flash",
1297
+ "cells",
1298
+ "utilities",
1299
+ "label-panel",
1300
+ "label-expand",
1301
+ "label-select",
1302
+ "roles",
1303
+ "slots",
1304
+ "flash-bind",
1305
+ "pin-row",
1306
+ "onToggle",
1307
+ "onToggleSelected",
1308
+ "onRightPanel"
1309
+ ])), isRow(item) && isRowExpanded(item) ? (openBlock(), createElementBlock("tr", {
1310
+ key: 3,
1311
+ class: "qt-subtable-row",
1312
+ role: rowRole(),
1313
+ "aria-rowindex": nextIndex(item.aria),
1314
+ "data-pinned-row": item.pinned || void 0
1315
+ }, [createElementVNode("td", mergeProps({ ref_for: true }, spanAttrs()), [renderSlot(_ctx.$slots, "subtable", {
1316
+ row: item.row,
1317
+ rowIndex: item.index
1318
+ })], 16)], 8, _hoisted_5$3)) : createCommentVNode("", true)], 64);
1319
+ }), 128)),
1320
+ __props.loading && slots.loading ? (openBlock(), createElementBlock("tr", {
1321
+ key: 0,
1322
+ class: "qt-loading-row",
1323
+ role: rowRole()
1324
+ }, [createElementVNode("td", normalizeProps(guardReactiveProps(spanAttrs())), [renderSlot(_ctx.$slots, "loading")], 16)], 8, _hoisted_6$2)) : !__props.loading && __props.rows.length === 0 && slots.empty ? (openBlock(), createElementBlock("tr", {
1325
+ key: 1,
1326
+ class: "qt-empty-row",
1327
+ role: rowRole()
1328
+ }, [createElementVNode("td", normalizeProps(guardReactiveProps(spanAttrs())), [renderSlot(_ctx.$slots, "empty")], 16)], 8, _hoisted_7$2)) : createCommentVNode("", true),
1329
+ !__props.loading && __props.rows.length > 0 && __props.loadMore && slots["load-more"] ? (openBlock(), createElementBlock("tr", {
1330
+ key: 2,
1331
+ class: "qt-load-more-row",
1332
+ role: rowRole()
1333
+ }, [createElementVNode("td", normalizeProps(guardReactiveProps(spanAttrs())), [renderSlot(_ctx.$slots, "load-more", normalizeProps(guardReactiveProps(__props.loadMore)))], 16)], 8, _hoisted_8$2)) : createCommentVNode("", true)
1334
+ ], 40, _hoisted_1$9);
1335
+ };
1336
+ }
1337
+ });
1338
+ //#endregion
1339
+ //#region src/parts/table-footer.vue?vue&type=script&setup=true&lang.ts
1340
+ var _hoisted_1$8 = ["role"];
1341
+ var _hoisted_2$4 = ["role", "aria-rowindex"];
1342
+ var _hoisted_3$4 = [
1343
+ "colspan",
1344
+ "role",
1345
+ "aria-colspan"
1346
+ ];
1347
+ var _hoisted_4$4 = [
1348
+ "data-field",
1349
+ "data-type",
1350
+ "role"
1351
+ ];
1352
+ //#endregion
1353
+ //#region src/parts/table-footer.vue
1354
+ var table_footer_default = /* @__PURE__ */ defineComponent({
1355
+ __name: "table-footer",
1356
+ props: {
1357
+ footerRows: {},
1358
+ entries: {},
1359
+ utilityCount: {},
1360
+ hasPinned: { type: Boolean },
1361
+ offsets: {},
1362
+ firstRowIndex: {},
1363
+ roles: { type: Boolean }
1364
+ },
1365
+ setup(__props) {
1366
+ const footerText = (row, column) => row.cells.find((cell) => cell.field === column.field)?.text;
1367
+ return (_ctx, _cache) => {
1368
+ return openBlock(), createElementBlock("tfoot", {
1369
+ class: "qt-footer",
1370
+ role: __props.roles ? "rowgroup" : void 0
1371
+ }, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.footerRows, (footerRow, i) => {
1372
+ return openBlock(), createElementBlock("tr", {
1373
+ key: i,
1374
+ role: __props.roles ? "row" : void 0,
1375
+ "aria-rowindex": __props.firstRowIndex === void 0 ? void 0 : __props.firstRowIndex + i
1376
+ }, [__props.utilityCount > 0 ? (openBlock(), createElementBlock("td", mergeProps({
1377
+ key: 0,
1378
+ colspan: __props.utilityCount,
1379
+ role: __props.roles ? "cell" : void 0,
1380
+ "aria-colspan": __props.roles ? __props.utilityCount : void 0
1381
+ }, { ref_for: true }, unref(pinAttrs)(__props.hasPinned ? "left" : false, 0)), null, 16, _hoisted_3$4)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(__props.entries, (entry) => {
1382
+ return openBlock(), createElementBlock("td", mergeProps({
1383
+ key: entry.column.field,
1384
+ "data-field": entry.column.field,
1385
+ "data-type": unref(columnTypeOf$1)(entry.column),
1386
+ role: __props.roles ? "cell" : void 0
1387
+ }, { ref_for: true }, unref(pinAttrs)(unref(sideOf)(entry.column), __props.offsets[entry.column.field])), toDisplayString(footerText(footerRow, entry.column)), 17, _hoisted_4$4);
1388
+ }), 128))], 8, _hoisted_2$4);
1389
+ }), 128))], 8, _hoisted_1$8);
1390
+ };
1391
+ }
1392
+ });
1393
+ //#endregion
1394
+ //#region src/parts/filter-icon.vue?vue&type=script&setup=true&lang.ts
1395
+ var _hoisted_1$7 = ["fill"];
1396
+ //#endregion
1397
+ //#region src/parts/filter-icon.vue
1398
+ var filter_icon_default = /* @__PURE__ */ defineComponent({
1399
+ __name: "filter-icon",
1400
+ props: { filled: { type: Boolean } },
1401
+ setup(__props) {
1402
+ return (_ctx, _cache) => {
1403
+ return openBlock(), createElementBlock("svg", {
1404
+ viewBox: "0 0 24 24",
1405
+ width: "14",
1406
+ height: "14",
1407
+ stroke: "currentColor",
1408
+ "stroke-width": "1.5",
1409
+ fill: __props.filled ? "currentColor" : "none",
1410
+ "stroke-linecap": "round",
1411
+ "stroke-linejoin": "round",
1412
+ "aria-hidden": "true"
1413
+ }, [..._cache[0] || (_cache[0] = [createElementVNode("polygon", { points: "22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" }, null, -1)])], 8, _hoisted_1$7);
1414
+ };
1415
+ }
1416
+ });
1417
+ //#endregion
1418
+ //#region src/filter/use-filter-trigger.ts
1419
+ /**
1420
+ * The filter button a `filter-menu` slot receives as `trigger` (C-34). It is
1421
+ * created once, so a popover wrapped around it does not remount the button on
1422
+ * every render. It reads reactive state when it renders, so it still updates:
1423
+ * the column and the labels come from getters on each render, not from a
1424
+ * capture, so a new title or label shows at once.
1425
+ */
1426
+ var useFilterTrigger = (options) => defineComponent({
1427
+ name: "FilterTrigger",
1428
+ setup: () => () => {
1429
+ const name = options.labels().filterOptions(columnName(options.column()));
1430
+ const filtered = options.isFiltered();
1431
+ return h("button", {
1432
+ type: "button",
1433
+ class: "qt-filter-button",
1434
+ title: name,
1435
+ "aria-label": name,
1436
+ "data-filtered": filtered ? "" : void 0
1437
+ }, [h(filter_icon_default, { filled: filtered })]);
1438
+ }
1439
+ });
1440
+ //#endregion
1441
+ //#region src/parts/filter-cell.vue?vue&type=script&setup=true&lang.ts
1442
+ var _hoisted_1$6 = { class: "qt-filter" };
1443
+ var _hoisted_2$3 = [
1444
+ "type",
1445
+ "aria-label",
1446
+ "value",
1447
+ "onInput"
1448
+ ];
1449
+ var _hoisted_3$3 = [
1450
+ "aria-label",
1451
+ "value",
1452
+ "readonly",
1453
+ "aria-invalid"
1454
+ ];
1455
+ var _hoisted_4$3 = [
1456
+ "aria-label",
1457
+ "value",
1458
+ "readonly",
1459
+ "aria-invalid"
1460
+ ];
1461
+ var _hoisted_5$2 = [
1462
+ "aria-label",
1463
+ "value",
1464
+ "disabled"
1465
+ ];
1466
+ var _hoisted_6$1 = { value: "" };
1467
+ var _hoisted_7$1 = { value: "true" };
1468
+ var _hoisted_8$1 = { value: "false" };
1469
+ var _hoisted_9 = ["value"];
1470
+ var _hoisted_10 = [
1471
+ "type",
1472
+ "aria-label",
1473
+ "value",
1474
+ "readonly"
1475
+ ];
1476
+ var _hoisted_11 = {
1477
+ key: 7,
1478
+ class: "qt-filter-condition"
1479
+ };
1480
+ //#endregion
1481
+ //#region src/parts/filter-cell.vue
1482
+ var filter_cell_default = /* @__PURE__ */ defineComponent({
1483
+ __name: "filter-cell",
1484
+ props: {
1485
+ column: {},
1486
+ type: {},
1487
+ query: {}
1488
+ },
1489
+ setup(__props) {
1490
+ const props = __props;
1491
+ const { filters, sort, layout, labels } = useTableContext();
1492
+ const inputName = () => labels().filterInput(columnName(props.column));
1493
+ const isFiltered = () => rulesOf(props.query.filters, props.column.field).length > 0;
1494
+ const trigger = useFilterTrigger({
1495
+ column: () => props.column,
1496
+ labels,
1497
+ isFiltered
1498
+ });
1499
+ const labelOf = () => {
1500
+ const label = filters.labelOf(props.column.field);
1501
+ if (!label) return "";
1502
+ const text = labels().filterCondition(label.condition, props.type);
1503
+ return label.count > 1 ? `${text} (${label.count})` : text;
1504
+ };
1505
+ const inputText = () => {
1506
+ const count = filters.multiOf(props.column.field);
1507
+ return count > 0 ? `(${count})` : filters.draftOf(props.column.field).text;
1508
+ };
1509
+ const draft = () => filters.draftOf(props.column.field);
1510
+ const isMulti = () => filters.multiOf(props.column.field) > 0;
1511
+ const isInvalid = () => !isFiltered() && !isMulti() && draft().text.trim() !== "" && filters.labelOf(props.column.field)?.count === 0;
1512
+ const ordered = [
1513
+ "number",
1514
+ "integer",
1515
+ "date",
1516
+ "datetime",
1517
+ "ip"
1518
+ ];
1519
+ const isDated = () => props.type === "date" || props.type === "datetime";
1520
+ const hidesInput = () => {
1521
+ const { condition } = draft();
1522
+ return !isMulti() && props.type !== "bool" && condition !== null && conditionArity(condition) === 0;
1523
+ };
1524
+ const isRange = () => !isMulti() && draft().condition === "Between" && ordered.includes(props.type);
1525
+ const bounds = ["lower", "upper"];
1526
+ const boundText = (bound) => bound === "upper" ? draft().text2 ?? "" : draft().text;
1527
+ const boundName = (bound) => {
1528
+ const name = columnName(props.column);
1529
+ return bound === "upper" ? labels().filterInputTo(name) : labels().filterInputFrom(name);
1530
+ };
1531
+ const takes = (condition) => condition === "Between" ? ordered.includes(props.type) : conditionArity(condition) === 0 || conditionOptions[props.type].some((option) => option.value === condition);
1532
+ const offered = () => {
1533
+ const own = props.column.filterConditions;
1534
+ return own ? [...new Set(own)].filter(takes) : conditionOptions[props.type].map(({ value }) => value);
1535
+ };
1536
+ const currentCondition = () => rulesOf(props.query.filters, props.column.field)[0]?.condition ?? filters.draftOf(props.column.field).condition;
1537
+ const menuProps = () => {
1538
+ const { column } = props;
1539
+ return {
1540
+ column,
1541
+ rules: rulesOf(props.query.filters, column.field),
1542
+ condition: currentCondition(),
1543
+ conditions: offered().map((value) => ({
1544
+ value,
1545
+ label: labels().filterCondition(value, props.type)
1546
+ })),
1547
+ setCondition: (condition) => filters.setCondition(column.field, condition),
1548
+ clear: () => filters.clear(column.field),
1549
+ sortable: sort.isSortable(column),
1550
+ sortDirection: sort.sortOf(column),
1551
+ setSort: (direction) => sort.sortBy(column, direction),
1552
+ trigger,
1553
+ control: layout.controlOf(column.field)
1554
+ };
1555
+ };
1556
+ const datetimeProps = (bound = null) => ({
1557
+ column: props.column,
1558
+ value: bound ? boundText(bound) : draft().text,
1559
+ updateValue: (value) => filters.setInput(props.column.field, value, bound ?? void 0),
1560
+ bound
1561
+ });
1562
+ const inputValue = (event) => event.target.value;
1563
+ const pick = (event) => {
1564
+ filters.setInput(props.column.field, inputValue(event));
1565
+ filters.apply(props.column.field);
1566
+ };
1567
+ const noValue = (condition) => condition !== null && conditionArity(condition) === 0;
1568
+ const boolNulls = () => {
1569
+ const listed = props.column.filterConditions ? offered().filter(noValue) : [];
1570
+ const { condition } = draft();
1571
+ return noValue(condition) && !listed.includes(condition) ? [...listed, condition] : listed;
1572
+ };
1573
+ const boolValue = () => {
1574
+ const { condition, text } = draft();
1575
+ return noValue(condition) ? condition : text;
1576
+ };
1577
+ const pickBool = (event) => {
1578
+ const { field } = props.column;
1579
+ const value = inputValue(event);
1580
+ if (value === "") filters.clear(field);
1581
+ else if (value === "true" || value === "false") {
1582
+ if (noValue(draft().condition)) {
1583
+ filters.setInput(field, value);
1584
+ filters.setCondition(field, "Equal");
1585
+ } else pick(event);
1586
+ } else filters.setCondition(field, value);
1587
+ };
1588
+ return (_ctx, _cache) => {
1589
+ return openBlock(), createElementBlock("div", _hoisted_1$6, [
1590
+ isRange() ? (openBlock(), createElementBlock(Fragment, { key: 0 }, renderList(bounds, (bound) => {
1591
+ return openBlock(), createElementBlock(Fragment, { key: bound }, [isDated() && _ctx.$slots["filter-datetime"] ? renderSlot(_ctx.$slots, "filter-datetime", mergeProps({ ref_for: true }, datetimeProps(bound)), void 0, void 0, 0) : (openBlock(), createElementBlock("input", {
1592
+ key: 1,
1593
+ type: isDated() ? "date" : __props.type === "ip" ? "text" : "number",
1594
+ class: "qt-filter-input",
1595
+ "aria-label": boundName(bound),
1596
+ value: boundText(bound),
1597
+ onInput: ($event) => unref(filters).setInput(__props.column.field, inputValue($event), bound),
1598
+ onKeydown: _cache[0] || (_cache[0] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1599
+ }, null, 40, _hoisted_2$3))], 64);
1600
+ }), 64)) : hidesInput() ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [], 64)) : __props.type === "string" ? (openBlock(), createElementBlock("input", {
1601
+ key: 2,
1602
+ type: "text",
1603
+ class: "qt-filter-input",
1604
+ "aria-label": inputName(),
1605
+ value: inputText(),
1606
+ readonly: isMulti(),
1607
+ "aria-invalid": isInvalid() || void 0,
1608
+ onInput: _cache[1] || (_cache[1] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1609
+ onKeydown: _cache[2] || (_cache[2] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1610
+ }, null, 40, _hoisted_3$3)) : __props.type === "number" || __props.type === "integer" || __props.type === "ip" ? (openBlock(), createElementBlock("input", {
1611
+ key: 3,
1612
+ type: "text",
1613
+ class: "qt-filter-input",
1614
+ "aria-label": inputName(),
1615
+ value: inputText(),
1616
+ readonly: isMulti(),
1617
+ "aria-invalid": isInvalid() || void 0,
1618
+ onInput: _cache[3] || (_cache[3] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1619
+ onKeydown: _cache[4] || (_cache[4] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1620
+ }, null, 40, _hoisted_4$3)) : __props.type === "bool" ? (openBlock(), createElementBlock("select", {
1621
+ key: 4,
1622
+ class: "qt-filter-input",
1623
+ "aria-label": inputName(),
1624
+ value: boolValue(),
1625
+ disabled: unref(filters).multiOf(__props.column.field) > 0,
1626
+ onChange: _cache[5] || (_cache[5] = ($event) => pickBool($event))
1627
+ }, [
1628
+ createElementVNode("option", _hoisted_6$1, toDisplayString(unref(labels)().boolAll), 1),
1629
+ createElementVNode("option", _hoisted_7$1, toDisplayString(unref(labels)().boolTrue), 1),
1630
+ createElementVNode("option", _hoisted_8$1, toDisplayString(unref(labels)().boolFalse), 1),
1631
+ (openBlock(true), createElementBlock(Fragment, null, renderList(boolNulls(), (condition) => {
1632
+ return openBlock(), createElementBlock("option", {
1633
+ key: condition,
1634
+ value: condition
1635
+ }, toDisplayString(unref(labels)().filterCondition(condition, "bool")), 9, _hoisted_9);
1636
+ }), 128))
1637
+ ], 40, _hoisted_5$2)) : (openBlock(), createElementBlock(Fragment, { key: 5 }, [_ctx.$slots["filter-datetime"] ? renderSlot(_ctx.$slots, "filter-datetime", normalizeProps(guardReactiveProps(datetimeProps())), void 0, void 0, 0) : (openBlock(), createElementBlock("input", {
1638
+ key: 1,
1639
+ type: unref(filters).multiOf(__props.column.field) ? "text" : "date",
1640
+ class: "qt-filter-input",
1641
+ "aria-label": inputName(),
1642
+ value: inputText(),
1643
+ readonly: unref(filters).multiOf(__props.column.field) > 0,
1644
+ onInput: _cache[6] || (_cache[6] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1645
+ onKeydown: _cache[7] || (_cache[7] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1646
+ }, null, 40, _hoisted_10))], 64)),
1647
+ __props.type !== "bool" ? renderSlot(_ctx.$slots, "filter-menu", normalizeProps(guardReactiveProps(menuProps())), void 0, void 0, 6) : createCommentVNode("", true),
1648
+ labelOf() ? (openBlock(), createElementBlock("small", _hoisted_11, toDisplayString(labelOf()), 1)) : createCommentVNode("", true)
1649
+ ]);
1650
+ };
1651
+ }
1652
+ });
1653
+ //#endregion
1654
+ //#region src/parts/reorder-handle.vue?vue&type=script&setup=true&lang.ts
1655
+ var _hoisted_1$5 = ["aria-label"];
1656
+ //#endregion
1657
+ //#region src/parts/reorder-handle.vue
1658
+ var reorder_handle_default = /* @__PURE__ */ defineComponent({
1659
+ __name: "reorder-handle",
1660
+ props: { column: {} },
1661
+ setup(__props) {
1662
+ const props = __props;
1663
+ const { reorder, labels } = useTableContext();
1664
+ const on = reorder.listeners(() => props.column);
1665
+ return (_ctx, _cache) => {
1666
+ return openBlock(), createElementBlock("button", mergeProps({
1667
+ type: "button",
1668
+ class: "qt-reorder-handle",
1669
+ "aria-label": unref(labels)().moveColumn(unref(columnName)(__props.column)),
1670
+ "aria-keyshortcuts": "ArrowLeft ArrowRight Home End"
1671
+ }, toHandlers(unref(on), true)), [..._cache[0] || (_cache[0] = [createStaticVNode("<svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\"><circle cx=\"9\" cy=\"6\" r=\"1.5\"></circle><circle cx=\"15\" cy=\"6\" r=\"1.5\"></circle><circle cx=\"9\" cy=\"12\" r=\"1.5\"></circle><circle cx=\"15\" cy=\"12\" r=\"1.5\"></circle><circle cx=\"9\" cy=\"18\" r=\"1.5\"></circle><circle cx=\"15\" cy=\"18\" r=\"1.5\"></circle></svg>", 1)])], 16, _hoisted_1$5);
1672
+ };
1673
+ }
1674
+ });
1675
+ //#endregion
1676
+ //#region src/resize/measure-widths.ts
1677
+ /**
1678
+ * What must not count, inside the table: the filter row and the resize handle
1679
+ * of a header cell (C-50 counts the label only), the footer, and every body
1680
+ * row that is not a data row (subtable, virtual spacer, loading, empty,
1681
+ * load-more). A subtable or a spanning cell would otherwise widen the
1682
+ * columns it spans with content that is not theirs.
1683
+ */
1684
+ var notCountedParts = [
1685
+ ":scope > thead > tr > th[data-field] > .qt-resize-handle",
1686
+ ":scope > tbody > tr:not([data-row-index])",
1687
+ ":scope > tfoot"
1688
+ ];
1689
+ var filterRow = ":scope > thead > tr > th[data-field] > .qt-filter";
1690
+ var notCounted = [filterRow, ...notCountedParts].join(", ");
1691
+ var notCountedWithFilters = notCountedParts.join(", ");
1692
+ /**
1693
+ * The room a text, number or date filter input keeps for its text when the
1694
+ * filter row counts (C-100): six characters of the input's own font.
1695
+ */
1696
+ var filterText = "6ch";
1697
+ /**
1698
+ * Sets inline declarations for one read and puts every `style` attribute
1699
+ * back exactly as it was, absent included, so the markup after the call is
1700
+ * the markup before it (C-31). `!important` so a consumer's `!important`
1701
+ * rule cannot keep the fixed layout during the read.
1702
+ */
1703
+ var styleSwap = () => {
1704
+ const saved = /* @__PURE__ */ new Map();
1705
+ return {
1706
+ set(element, property, value) {
1707
+ if (!saved.has(element)) saved.set(element, element.getAttribute("style"));
1708
+ element.style.setProperty(property, value, "important");
1709
+ },
1710
+ restore() {
1711
+ for (const [element, style] of saved) if (style === null) {
1712
+ element.getAttribute("style");
1713
+ element.removeAttribute("style");
1714
+ } else element.setAttribute("style", style);
1715
+ saved.clear();
1716
+ }
1717
+ };
1718
+ };
1719
+ /**
1720
+ * The max-content width of each drawn column, by `field`: header label and
1721
+ * the cells of the drawn data rows, padding and border included, in whole
1722
+ * pixels rounded up. The browser lays the table out once with its automatic
1723
+ * layout and no widths, the parts that do not count taken out, and every
1724
+ * style is put back before the function returns: nothing is painted in
1725
+ * between, and slot content that draws a block or a flex box counts with the
1726
+ * width its content needs, not the width its cell gives it. Only `fields`
1727
+ * when given; a column with no box (the table not displayed) is left out.
1728
+ * With `scrollBody` the data rows are in a table of their own, `body`
1729
+ * (C-101): it is laid out the same way, its `col` widths left out, and a
1730
+ * column takes the wider of its header cell and its body cells.
1731
+ */
1732
+ var measureColumnWidths = (table, fields, body, options = {}) => {
1733
+ const widths = {};
1734
+ if (!table?.tHead) return widths;
1735
+ const wanted = fields ? new Set(fields) : null;
1736
+ const headers = Array.from(table.querySelectorAll(":scope > thead > tr > th[data-field]"));
1737
+ const swap = styleSwap();
1738
+ try {
1739
+ swap.set(table, "table-layout", "auto");
1740
+ swap.set(table, "width", "max-content");
1741
+ swap.set(table, "min-width", "0");
1742
+ for (const th of headers) swap.set(th, "width", "auto");
1743
+ for (const part of Array.from(table.querySelectorAll(options.filters ? notCountedWithFilters : notCounted))) swap.set(part, "display", "none");
1744
+ if (options.filters) countFilters(table, swap);
1745
+ const split = body && body !== table ? body : null;
1746
+ if (split) {
1747
+ swap.set(split, "table-layout", "auto");
1748
+ swap.set(split, "width", "max-content");
1749
+ swap.set(split, "min-width", "0");
1750
+ for (const col of Array.from(split.querySelectorAll(":scope > colgroup > col"))) swap.set(col, "width", "auto");
1751
+ for (const part of Array.from(split.querySelectorAll(":scope > tbody > tr:not([data-row-index])"))) swap.set(part, "display", "none");
1752
+ }
1753
+ const firstRow = split?.querySelector(":scope > tbody > tr[data-row-index]");
1754
+ const measured = [];
1755
+ for (const th of headers) {
1756
+ const field = th.dataset.field;
1757
+ if (field === void 0 || wanted && !wanted.has(field)) continue;
1758
+ const own = th.getBoundingClientRect().width;
1759
+ if (own === 0) continue;
1760
+ const cell = firstRow?.querySelector(`:scope > td[data-field="${CSS.escape(field)}"]`);
1761
+ measured.push([
1762
+ field,
1763
+ th,
1764
+ Math.max(own, cell?.getBoundingClientRect().width ?? 0)
1765
+ ]);
1766
+ }
1767
+ const floors = options.filters ? filterFloors(measured.map(([, th]) => th), swap) : null;
1768
+ for (const [field, th, width] of measured) widths[field] = Math.ceil(Math.max(width, floors?.get(th) ?? 0));
1769
+ } finally {
1770
+ swap.restore();
1771
+ }
1772
+ return widths;
1773
+ };
1774
+ /**
1775
+ * Takes the filter rows out of the read (C-100): out of the cell's flow
1776
+ * (`position: absolute`), so nothing in them widens the column by being
1777
+ * there, and no size container, which would switch the row to its narrow
1778
+ * form. Each control of the table stops growing and shrinking: a text or
1779
+ * number input six characters wide (padding and border on top), a select
1780
+ * and a date or time input as wide as they draw themselves, a filter button
1781
+ * at its own width, back in the row's flow when a skin's narrow form laid it
1782
+ * `absolute` over the input. A control `fixed` over the page (a panel)
1783
+ * stays out.
1784
+ */
1785
+ var countFilters = (table, swap) => {
1786
+ const rows = Array.from(table.querySelectorAll(filterRow));
1787
+ for (const row of rows) {
1788
+ swap.set(row, "position", "absolute");
1789
+ swap.set(row, "container-type", "normal");
1790
+ swap.set(row, "contain", "none");
1791
+ swap.set(row, "box-sizing", "content-box");
1792
+ for (const input of Array.from(row.querySelectorAll(":scope > .qt-filter-input"))) {
1793
+ swap.set(input, "flex", "none");
1794
+ swap.set(input, "min-width", "0");
1795
+ if (input instanceof HTMLInputElement && textTypes.has(input.type)) {
1796
+ swap.set(input, "box-sizing", "content-box");
1797
+ swap.set(input, "width", filterText);
1798
+ } else swap.set(input, "width", "auto");
1799
+ }
1800
+ for (const button of Array.from(row.querySelectorAll(":scope > .qt-filter-button"))) swap.set(button, "flex", "none");
1801
+ }
1802
+ for (const row of rows) for (const button of Array.from(row.querySelectorAll(":scope > .qt-filter-button"))) if (getComputedStyle(button).position === "absolute") swap.set(button, "position", "static");
1803
+ };
1804
+ /** The inputs that keep six characters of text; the others draw their own. */
1805
+ var textTypes = /* @__PURE__ */ new Set([
1806
+ "text",
1807
+ "number",
1808
+ "search"
1809
+ ]);
1810
+ var horizontal = (style) => (parseFloat(style.paddingLeft) || 0) + (parseFloat(style.paddingRight) || 0) + (parseFloat(style.borderLeftWidth) || 0) + (parseFloat(style.borderRightWidth) || 0);
1811
+ /** The table's own filter controls, the row's children, that take room. */
1812
+ var controlsOf = (row) => Array.from(row.querySelectorAll(":scope > :is(.qt-filter-input, .qt-filter-button)")).filter((control) => {
1813
+ const { position } = getComputedStyle(control);
1814
+ return position !== "fixed" && position !== "absolute";
1815
+ });
1816
+ /** The row's content width the probes draw it at: `0` and this. */
1817
+ var probe = 1e3;
1818
+ /**
1819
+ * The width each header cell needs for its filter controls, from the
1820
+ * controls alone: the row's width is never read, so slot content in it
1821
+ * cannot count, by its own width or by a width it took from the column. The
1822
+ * controls are drawn side by side in rows `0` and `probe` pixels wide, and
1823
+ * each width (a control, the gap) is taken as a fixed part plus a share of
1824
+ * the row, which is what a percentage padding is. The row then needs `R`
1825
+ * with `R = fixed + share * R`, the cell `R` plus the row's and the cell's
1826
+ * padding and border.
1827
+ */
1828
+ var filterFloors = (headers, swap) => {
1829
+ const rows = headers.flatMap((th) => {
1830
+ const row = th.querySelector(":scope > .qt-filter");
1831
+ const controls = row ? controlsOf(row) : [];
1832
+ return row && controls.length > 0 ? [{
1833
+ th,
1834
+ row,
1835
+ controls
1836
+ }] : [];
1837
+ });
1838
+ const read = (width) => {
1839
+ for (const { row } of rows) swap.set(row, "width", `${width}px`);
1840
+ return rows.map(({ row, controls }) => {
1841
+ const drawn = controls.map((control) => control.getBoundingClientRect().width).filter((each) => each > 0);
1842
+ const gap = parseFloat(getComputedStyle(row).columnGap) || 0;
1843
+ return drawn.length === 0 ? 0 : drawn.reduce((sum, each) => sum + each, 0) + gap * (drawn.length - 1);
1844
+ });
1845
+ };
1846
+ const atZero = read(0);
1847
+ const atProbe = read(probe);
1848
+ const floors = /* @__PURE__ */ new Map();
1849
+ rows.forEach(({ th, row }, index) => {
1850
+ const fixed = atZero[index];
1851
+ if (fixed === 0) return;
1852
+ const share = Math.min(.9, Math.max(0, (atProbe[index] - fixed) / probe));
1853
+ floors.set(th, fixed / (1 - share) + horizontal(getComputedStyle(row)) + horizontal(getComputedStyle(th)));
1854
+ });
1855
+ return floors;
1856
+ };
1857
+ //#endregion
1858
+ //#region src/resize/width-scale.ts
1859
+ var same = (width) => width;
1860
+ var sum = (widths) => widths.reduce((a, b) => a + b, 0);
1861
+ /** The declared width is the drawn one. */
1862
+ var identityScale = {
1863
+ declared: same,
1864
+ rendered: same
1865
+ };
1866
+ /**
1867
+ * A table whose cells take `space` (a container's width, with
1868
+ * `min-width: 100%`) and whose columns are declared narrower: the fixed
1869
+ * layout spreads the rest over the columns by their declared widths, so a
1870
+ * column declared `w` next to `others` is drawn `w * space / (w + others)`
1871
+ * wide until the columns fill the space, and `w` from there on. With no other
1872
+ * column the one column takes the space whatever its width: the identity.
1873
+ */
1874
+ var stretchedScale = (space, others) => others > 0 && space > others ? {
1875
+ declared: (rendered) => rendered >= space - others ? rendered : rendered * others / (space - rendered),
1876
+ rendered: (declared) => declared + others >= space ? declared : declared * space / (declared + others)
1877
+ } : identityScale;
1878
+ /**
1879
+ * How the declared width of the column of `th` maps to its drawn width, read
1880
+ * from the layout. The column is drawn once at the width it is drawn at now.
1881
+ * Wider there, the table stretches it: its row's cells take the whole space,
1882
+ * and the other columns' declared widths follow from the stretch; the fit
1883
+ * must then give back the width the column is drawn at now. Not wider, the
1884
+ * column is drawn once more at `low`, the narrowest width a resize writes. A
1885
+ * table that stretches it there widens every cell of the row by one factor,
1886
+ * the column at least as much (content the fixed layout keeps wider than
1887
+ * `low` only adds to it), and its cells then take the space the columns can
1888
+ * shrink into before the table stretches them. Any other layout gets the
1889
+ * identity: one that never stretches, a column without a width that takes
1890
+ * what is left, one that spreads the space otherwise. Every style is put back before the
1891
+ * function returns (C-31), so nothing is painted in between.
1892
+ */
1893
+ var measureWidthScale = (th, low) => {
1894
+ const now = th.getBoundingClientRect().width;
1895
+ const others = Array.from(th.parentElement?.children ?? []).filter((cell) => cell !== th);
1896
+ const widths = () => others.map((cell) => cell.getBoundingClientRect().width);
1897
+ const swap = styleSwap();
1898
+ /** Draws the column `width` wide; the width it takes. */
1899
+ const draw = (width) => {
1900
+ swap.set(th, "width", `${width}px`);
1901
+ return th.getBoundingClientRect().width;
1902
+ };
1903
+ try {
1904
+ const drawn = draw(now);
1905
+ const before = widths();
1906
+ const rest = sum(before);
1907
+ if (drawn > now + .5) {
1908
+ const scale = stretchedScale(drawn + rest, now * rest / drawn);
1909
+ return Math.abs(draw(scale.declared(now)) - now) <= 1 ? scale : identityScale;
1910
+ }
1911
+ const narrow = draw(low);
1912
+ const after = widths();
1913
+ const factor = sum(after) / rest;
1914
+ return factor > 1 && narrow >= low * factor - 1 && after.every((width, i) => Math.abs(width - before[i] * factor) <= 1) ? stretchedScale(narrow + sum(after), rest) : identityScale;
1915
+ } finally {
1916
+ swap.restore();
1917
+ }
1918
+ };
1919
+ //#endregion
1920
+ //#region src/resize/use-column-resize.ts
1921
+ /** Default `Column.minWidth`, in pixels. */
1922
+ var defaultMinWidth = 40;
1923
+ /**
1924
+ * A width limit a consumer gave, or `undefined` when it cannot be one. The
1925
+ * types say `number`, but a loosely typed consumer can pass `''`, `NaN`,
1926
+ * `0` or a negative: those count as unset instead of clamping to 0.
1927
+ */
1928
+ var limitOf = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
1929
+ /**
1930
+ * The smallest width: `Column.minWidth`, else the default 40 (which gives way
1931
+ * to a smaller `Column.maxWidth`, so a maximum alone keeps working).
1932
+ */
1933
+ var minWidthOf = (column) => limitOf(column.minWidth) ?? Math.min(defaultMinWidth, limitOf(column.maxWidth) ?? defaultMinWidth);
1934
+ /** The largest width, or `undefined` for none. A `minWidth` above it wins. */
1935
+ var maxWidthOf = (column) => {
1936
+ const max = limitOf(column.maxWidth);
1937
+ return max === void 0 ? void 0 : Math.max(max, minWidthOf(column));
1938
+ };
1939
+ var clampWidth = (column, width) => Math.round(Math.min(maxWidthOf(column) ?? Infinity, Math.max(minWidthOf(column), width)));
1940
+ var cellOf = (event) => event.currentTarget.closest("th");
1941
+ /**
1942
+ * Which edge of the column the handle stands for: `1` for the right edge,
1943
+ * `-1` for the left one. A right-pinned column stays at the right edge of the
1944
+ * scroll container, so it grows to the left: its handle stands for its left
1945
+ * edge, and moving that edge to the left widens it (C-71).
1946
+ */
1947
+ var edgeOf = (column) => column.pinned === "right" ? -1 : 1;
1948
+ /**
1949
+ * The scale of a column's widths, read from the layout once per drag or key:
1950
+ * a table stretched to its container draws a column wider than declared.
1951
+ */
1952
+ var scaleOf = (th, column) => measureWidthScale(th, clampWidth(column, 0));
1953
+ /**
1954
+ * Resizing a column (C-48 to C-50). The table holds a width only while a
1955
+ * drag is under way (the preview, P2); every committed width goes out as a
1956
+ * `columnResize` event and comes back, if the consumer wants it, as
1957
+ * `Column.width`. The handle captures the pointer, so all drag events arrive
1958
+ * at the handle itself, and it has the focus, so Escape does too. The pointer
1959
+ * and the arrow keys move the drawn width; what the table writes and emits is
1960
+ * the declared width that draws it (`measureWidthScale`).
1961
+ */
1962
+ var useColumnResize = (options) => {
1963
+ /** `width` is declared (the inline style), `rendered` drawn. */
1964
+ const preview = shallowRef(null);
1965
+ let drag = null;
1966
+ const isResizable = (column) => options.resizable() && column.resizable !== false;
1967
+ /** The width the header shows: the preview while dragging, else measured. */
1968
+ const widthOf = (column) => preview.value?.field === column.field ? preview.value.rendered : Math.round(options.measuredWidth(column.field) ?? 0);
1969
+ /** Emits the declared width `width`, unless it is the declared `from`. */
1970
+ const commit = (column, from, width) => {
1971
+ const next = clampWidth(column, width);
1972
+ if (next !== Math.round(from)) options.emit({
1973
+ field: column.field,
1974
+ width: next
1975
+ });
1976
+ };
1977
+ /** The declared width that draws the column where the pointer is. */
1978
+ const dragged = (current) => current.scale.declared(current.startWidth + edgeOf(current.column) * (current.lastX - current.startX));
1979
+ const end = (apply) => {
1980
+ const current = drag;
1981
+ if (current) {
1982
+ drag = null;
1983
+ cancelAnimationFrame(current.frame);
1984
+ preview.value = null;
1985
+ if (apply) commit(current.column, current.scale.declared(current.startWidth), dragged(current));
1986
+ }
1987
+ };
1988
+ /** Every pointer event of a handle; one listener for the whole drag. */
1989
+ const onPointer = (event, column) => {
1990
+ if (event.type === "pointerdown") {
1991
+ const th = cellOf(event);
1992
+ if (event.button !== 0 || drag || !th) return;
1993
+ const handle = event.currentTarget;
1994
+ event.preventDefault();
1995
+ handle.focus({ preventScroll: true });
1996
+ handle.setPointerCapture(event.pointerId);
1997
+ drag = {
1998
+ column,
1999
+ pointerId: event.pointerId,
2000
+ startX: event.clientX,
2001
+ startWidth: th.getBoundingClientRect().width,
2002
+ scale: scaleOf(th, column),
2003
+ lastX: event.clientX,
2004
+ frame: 0
2005
+ };
2006
+ return;
2007
+ }
2008
+ if (!drag || event.pointerId !== drag.pointerId) return;
2009
+ drag.lastX = event.clientX;
2010
+ if (event.type === "pointermove") drag.frame ||= requestAnimationFrame(() => {
2011
+ if (drag) {
2012
+ drag.frame = 0;
2013
+ const width = clampWidth(drag.column, dragged(drag));
2014
+ preview.value = {
2015
+ field: drag.column.field,
2016
+ width,
2017
+ rendered: Math.round(drag.scale.rendered(width))
2018
+ };
2019
+ }
2020
+ });
2021
+ else end(event.type === "pointerup");
2022
+ };
2023
+ /**
2024
+ * Arrow keys step the drawn width, Enter fits it to the content (the
2025
+ * declared width `measureColumnWidths` gives, as it is).
2026
+ */
2027
+ const onKey = (event, column) => {
2028
+ const { key } = event;
2029
+ if (drag) {
2030
+ if (key === "Escape") {
2031
+ event.preventDefault();
2032
+ event.stopPropagation();
2033
+ end(false);
2034
+ }
2035
+ return;
2036
+ }
2037
+ const sign = (key === "ArrowRight" ? 1 : key === "ArrowLeft" ? -1 : 0) * edgeOf(column);
2038
+ const th = cellOf(event);
2039
+ if (th && (sign || key === "Enter" || event.type === "dblclick")) {
2040
+ event.preventDefault();
2041
+ const drawn = th.getBoundingClientRect().width;
2042
+ const scale = scaleOf(th, column);
2043
+ const from = scale.declared(drawn);
2044
+ const step = scale.declared(Math.round(drawn) + sign * (event.shiftKey ? 50 : 10));
2045
+ const to = sign ? from + sign * Math.max(1, Math.abs(step - from)) : measureColumnWidths(th.closest("table"), [column.field], options.body(), { filters: true })[column.field];
2046
+ if (to !== void 0) commit(column, from, to);
2047
+ }
2048
+ };
2049
+ /**
2050
+ * The listeners of one handle, as one `v-on` object made once per handle.
2051
+ * Pointer capture sends every drag event to the handle itself.
2052
+ */
2053
+ const listeners = (column) => {
2054
+ const pointer = (event) => {
2055
+ onPointer(event, column());
2056
+ };
2057
+ const key = (event) => {
2058
+ onKey(event, column());
2059
+ };
2060
+ return {
2061
+ pointerdown: pointer,
2062
+ pointermove: pointer,
2063
+ pointerup: pointer,
2064
+ pointercancel: pointer,
2065
+ lostpointercapture: pointer,
2066
+ keydown: key,
2067
+ dblclick: key,
2068
+ click: (event) => {
2069
+ event.stopPropagation();
2070
+ }
2071
+ };
2072
+ };
2073
+ /** `aria-valuemax`: `maxWidth`, or else the table width (what can show). */
2074
+ const maxOf = (column) => maxWidthOf(column) ?? Math.max(widthOf(column), Math.round(options.tableWidth()));
2075
+ onBeforeUnmount(() => {
2076
+ if (drag) {
2077
+ cancelAnimationFrame(drag.frame);
2078
+ drag = null;
2079
+ }
2080
+ });
2081
+ return {
2082
+ preview,
2083
+ isResizable,
2084
+ widthOf,
2085
+ maxOf,
2086
+ listeners
2087
+ };
2088
+ };
2089
+ //#endregion
2090
+ //#region src/parts/resize-handle.vue?vue&type=script&setup=true&lang.ts
2091
+ var _hoisted_1$4 = [
2092
+ "aria-label",
2093
+ "aria-valuenow",
2094
+ "aria-valuemin",
2095
+ "aria-valuemax"
2096
+ ];
2097
+ //#endregion
2098
+ //#region src/parts/resize-handle.vue
2099
+ var resize_handle_default = /* @__PURE__ */ defineComponent({
2100
+ __name: "resize-handle",
2101
+ props: { column: {} },
2102
+ setup(__props) {
2103
+ const props = __props;
2104
+ const { resize, labels } = useTableContext();
2105
+ const on = resize.listeners(() => props.column);
2106
+ return (_ctx, _cache) => {
2107
+ return openBlock(), createElementBlock("div", mergeProps({
2108
+ class: "qt-resize-handle",
2109
+ role: "separator",
2110
+ "aria-orientation": "vertical",
2111
+ tabindex: "0",
2112
+ "aria-label": unref(labels)().resizeColumn(unref(columnName)(__props.column)),
2113
+ "aria-valuenow": unref(resize).widthOf(__props.column),
2114
+ "aria-valuemin": unref(minWidthOf)(__props.column),
2115
+ "aria-valuemax": unref(resize).maxOf(__props.column)
2116
+ }, toHandlers(unref(on), true)), null, 16, _hoisted_1$4);
2117
+ };
2118
+ }
2119
+ });
2120
+ //#endregion
2121
+ //#region src/parts/sort-button.vue?vue&type=script&setup=true&lang.ts
2122
+ var _hoisted_1$3 = ["aria-label"];
2123
+ var _hoisted_2$2 = {
2124
+ key: 0,
2125
+ class: "qt-sort-icon",
2126
+ width: "14",
2127
+ height: "14",
2128
+ viewBox: "0 0 16 16",
2129
+ "aria-hidden": "true"
2130
+ };
2131
+ var _hoisted_3$2 = {
2132
+ key: 1,
2133
+ class: "qt-sort-icon",
2134
+ width: "14",
2135
+ height: "14",
2136
+ viewBox: "0 0 16 16",
2137
+ "aria-hidden": "true"
2138
+ };
2139
+ var _hoisted_4$2 = {
2140
+ key: 2,
2141
+ class: "qt-sort-icon",
2142
+ width: "14",
2143
+ height: "14",
2144
+ viewBox: "0 0 16 16",
2145
+ "aria-hidden": "true"
2146
+ };
2147
+ //#endregion
2148
+ //#region src/parts/sort-button.vue
2149
+ var sort_button_default = /* @__PURE__ */ defineComponent({
2150
+ __name: "sort-button",
2151
+ props: {
2152
+ column: {},
2153
+ direction: {}
2154
+ },
2155
+ emits: ["click"],
2156
+ setup(__props) {
2157
+ return (_ctx, _cache) => {
2158
+ return openBlock(), createElementBlock("button", {
2159
+ type: "button",
2160
+ class: "qt-sort",
2161
+ "aria-label": __props.column.title ? void 0 : __props.column.field,
2162
+ onClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("click"))
2163
+ }, [createTextVNode(toDisplayString(__props.column.title) + " ", 1), __props.direction === "asc" ? (openBlock(), createElementBlock("svg", _hoisted_2$2, [..._cache[1] || (_cache[1] = [createElementVNode("path", {
2164
+ d: "M8 3.5L12.5 9.5H3.5L8 3.5Z",
2165
+ fill: "currentColor"
2166
+ }, null, -1)])])) : __props.direction === "desc" ? (openBlock(), createElementBlock("svg", _hoisted_3$2, [..._cache[2] || (_cache[2] = [createElementVNode("path", {
2167
+ d: "M8 12.5L3.5 6.5H12.5L8 12.5Z",
2168
+ fill: "currentColor"
2169
+ }, null, -1)])])) : (openBlock(), createElementBlock("svg", _hoisted_4$2, [..._cache[3] || (_cache[3] = [createElementVNode("path", {
2170
+ d: "M8 3L11.5 7H4.5L8 3Z",
2171
+ fill: "currentColor"
2172
+ }, null, -1), createElementVNode("path", {
2173
+ d: "M8 13L4.5 9H11.5L8 13Z",
2174
+ fill: "currentColor"
2175
+ }, null, -1)])]))], 8, _hoisted_1$3);
2176
+ };
2177
+ }
2178
+ });
2179
+ //#endregion
2180
+ //#region src/sort/sort.ts
2181
+ /** Value of the `aria-sort` attribute for a direction. */
2182
+ var ariaSort = (direction) => direction === "asc" ? "ascending" : direction === "desc" ? "descending" : void 0;
2183
+ //#endregion
2184
+ //#region src/parts/table-header.vue?vue&type=script&setup=true&lang.ts
2185
+ var _hoisted_1$2 = ["role"];
2186
+ var _hoisted_2$1 = ["role"];
2187
+ var _hoisted_3$1 = [
2188
+ "aria-label",
2189
+ "checked",
2190
+ "indeterminate"
2191
+ ];
2192
+ var _hoisted_4$1 = ["role"];
2193
+ var _hoisted_5$1 = ["role"];
2194
+ var _hoisted_6 = [
2195
+ "title",
2196
+ "aria-label",
2197
+ "disabled"
2198
+ ];
2199
+ var _hoisted_7 = [
2200
+ "role",
2201
+ "data-field",
2202
+ "data-type",
2203
+ "data-sort",
2204
+ "data-sortable",
2205
+ "data-filtered",
2206
+ "aria-sort"
2207
+ ];
2208
+ var _hoisted_8 = {
2209
+ key: 3,
2210
+ class: "qt-title"
2211
+ };
2212
+ //#endregion
2213
+ //#region src/parts/table-header.vue
2214
+ var table_header_default = /* @__PURE__ */ defineComponent({
2215
+ __name: "table-header",
2216
+ props: {
2217
+ columns: {},
2218
+ query: {},
2219
+ filterable: { type: Boolean },
2220
+ utilities: {},
2221
+ hasPinned: { type: Boolean },
2222
+ offsets: {},
2223
+ autoWidths: {},
2224
+ slotNames: {},
2225
+ roles: { type: Boolean }
2226
+ },
2227
+ setup(__props) {
2228
+ const props = __props;
2229
+ const given = (name) => props.slotNames.split("\n").includes(name);
2230
+ const { filters, sort, layout, resize, reorder, selection, labels } = useTableContext();
2231
+ const dragAttrs = (column) => {
2232
+ const drag = reorder.dragging.value;
2233
+ return {
2234
+ "data-dragging": drag?.field === column.field ? "" : void 0,
2235
+ "data-drop": drag?.target === column.field ? drag.place : void 0
2236
+ };
2237
+ };
2238
+ const canClearAll = computed(() => filters.canClearAll());
2239
+ const onClearAll = async (event) => {
2240
+ const button = event.currentTarget;
2241
+ const doc = button.ownerDocument;
2242
+ const keyed = event.detail === 0 && doc.activeElement === button;
2243
+ filters.clearAll();
2244
+ if (!keyed) return;
2245
+ await nextTick();
2246
+ const active = doc.activeElement;
2247
+ if (button.disabled && (active === button || active === doc.body || active === null)) focusFirstFilter(button.closest("table"));
2248
+ };
2249
+ const isFiltered = (column) => rulesOf(props.query.filters, column.field).length > 0;
2250
+ const hasFilter = (column) => props.filterable && column.filterable !== false;
2251
+ const hostsClearAll = (utility) => props.filterable && utility === props.utilities.find((candidate) => candidate !== "select");
2252
+ const utilityAttrs = (utility) => pinAttrs(props.hasPinned ? "left" : false, props.offsets[utilityKey(utility)]);
2253
+ const widthOf = (column) => {
2254
+ if (column.width) return column.width;
2255
+ const auto = props.autoWidths[column.field];
2256
+ return auto === void 0 ? void 0 : `${auto}px`;
2257
+ };
2258
+ const cellAttrs = (column) => {
2259
+ const preview = resize.preview.value;
2260
+ return pinAttrs(sideOf(column), props.offsets[column.field], preview?.field === column.field ? `${preview.width}px` : widthOf(column));
2261
+ };
2262
+ const headerSlotProps = (column) => ({
2263
+ column,
2264
+ sortDirection: sort.sortOf(column),
2265
+ sortable: sort.isSortable(column),
2266
+ toggleSort: () => {
2267
+ sort.sortBy(column);
2268
+ },
2269
+ control: layout.controlOf(column.field)
2270
+ });
2271
+ return (_ctx, _cache) => {
2272
+ return openBlock(), createElementBlock("tr", { role: __props.roles ? "row" : void 0 }, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.utilities, (utility) => {
2273
+ return openBlock(), createElementBlock(Fragment, { key: utility }, [utility === "select" ? (openBlock(), createElementBlock("th", mergeProps({
2274
+ key: 0,
2275
+ scope: "col",
2276
+ role: __props.roles ? "columnheader" : void 0
2277
+ }, { ref_for: true }, utilityAttrs(utility)), [createElementVNode("input", {
2278
+ type: "checkbox",
2279
+ class: "qt-select-all",
2280
+ "aria-label": unref(labels)().selectAllRows,
2281
+ checked: unref(selection).allSelected.value,
2282
+ indeterminate: unref(selection).someSelected.value,
2283
+ onChange: _cache[0] || (_cache[0] = ($event) => unref(selection).toggleAll($event.target.checked))
2284
+ }, null, 40, _hoisted_3$1)], 16, _hoisted_2$1)) : !hostsClearAll(utility) ? (openBlock(), createElementBlock("td", mergeProps({
2285
+ key: 1,
2286
+ role: __props.roles ? "cell" : void 0
2287
+ }, { ref_for: true }, utilityAttrs(utility)), null, 16, _hoisted_4$1)) : (openBlock(), createElementBlock("th", mergeProps({
2288
+ key: 2,
2289
+ scope: "col",
2290
+ role: __props.roles ? "columnheader" : void 0
2291
+ }, { ref_for: true }, utilityAttrs(utility)), [createElementVNode("button", {
2292
+ type: "button",
2293
+ class: "qt-clear-all-button",
2294
+ title: unref(labels)().clearAllFilters,
2295
+ "aria-label": unref(labels)().clearAllFilters,
2296
+ disabled: !canClearAll.value,
2297
+ onClick: withModifiers(onClearAll, ["stop"])
2298
+ }, [..._cache[1] || (_cache[1] = [createElementVNode("svg", {
2299
+ width: "14",
2300
+ height: "14",
2301
+ viewBox: "0 0 24 24",
2302
+ fill: "none",
2303
+ stroke: "currentColor",
2304
+ "stroke-width": "2",
2305
+ "stroke-linecap": "round",
2306
+ "stroke-linejoin": "round",
2307
+ "aria-hidden": "true"
2308
+ }, [createElementVNode("line", {
2309
+ x1: "18",
2310
+ y1: "6",
2311
+ x2: "6",
2312
+ y2: "18"
2313
+ }), createElementVNode("line", {
2314
+ x1: "6",
2315
+ y1: "6",
2316
+ x2: "18",
2317
+ y2: "18"
2318
+ })], -1)])], 8, _hoisted_6)], 16, _hoisted_5$1))], 64);
2319
+ }), 128)), (openBlock(true), createElementBlock(Fragment, null, renderList(__props.columns, (column) => {
2320
+ return openBlock(), createElementBlock("th", mergeProps({
2321
+ key: column.field,
2322
+ scope: "col",
2323
+ role: __props.roles ? "columnheader" : void 0,
2324
+ "data-field": column.field,
2325
+ "data-type": unref(columnTypeOf$1)(column),
2326
+ "data-sort": unref(sort).sortOf(column) ?? void 0,
2327
+ "data-sortable": unref(sort).isSortable(column) ? "" : void 0,
2328
+ "data-filtered": isFiltered(column) ? "" : void 0,
2329
+ "aria-sort": unref(ariaSort)(unref(sort).sortOf(column))
2330
+ }, { ref_for: true }, {
2331
+ ...cellAttrs(column),
2332
+ ...dragAttrs(column)
2333
+ }), [
2334
+ unref(reorder).isReorderable(column) ? (openBlock(), createBlock(reorder_handle_default, {
2335
+ key: 0,
2336
+ column
2337
+ }, null, 8, ["column"])) : createCommentVNode("", true),
2338
+ given(`header-${column.field}`) ? renderSlot(_ctx.$slots, "header", mergeProps({ ref_for: true }, headerSlotProps(column)), void 0, void 0, 1) : unref(sort).isSortable(column) ? (openBlock(), createBlock(sort_button_default, {
2339
+ key: 2,
2340
+ column,
2341
+ direction: unref(sort).sortOf(column),
2342
+ onClick: ($event) => unref(sort).sortBy(column)
2343
+ }, null, 8, [
2344
+ "column",
2345
+ "direction",
2346
+ "onClick"
2347
+ ])) : (openBlock(), createElementBlock("span", _hoisted_8, toDisplayString(column.title), 1)),
2348
+ hasFilter(column) ? (openBlock(), createBlock(filter_cell_default, {
2349
+ key: 4,
2350
+ column,
2351
+ type: unref(columnTypeOf$1)(column),
2352
+ query: __props.query
2353
+ }, createSlots({ _: 2 }, [given("filter-datetime") ? {
2354
+ name: "filter-datetime",
2355
+ fn: withCtx((p) => [renderSlot(_ctx.$slots, "filter-datetime", mergeProps({ ref_for: true }, p))]),
2356
+ key: "0"
2357
+ } : void 0, given("filter-menu") ? {
2358
+ name: "filter-menu",
2359
+ fn: withCtx((p) => [renderSlot(_ctx.$slots, "filter-menu", mergeProps({ ref_for: true }, p))]),
2360
+ key: "1"
2361
+ } : void 0]), 1032, [
2362
+ "column",
2363
+ "type",
2364
+ "query"
2365
+ ])) : createCommentVNode("", true),
2366
+ unref(resize).isResizable(column) ? (openBlock(), createBlock(resize_handle_default, {
2367
+ key: 5,
2368
+ column
2369
+ }, null, 8, ["column"])) : createCommentVNode("", true)
2370
+ ], 16, _hoisted_7);
2371
+ }), 128))], 8, _hoisted_1$2);
2372
+ };
2373
+ }
2374
+ });
2375
+ //#endregion
2376
+ //#region src/parts/table-pagination.vue?vue&type=script&setup=true&lang.ts
2377
+ var _hoisted_1$1 = { class: "qt-pagination" };
2378
+ //#endregion
2379
+ //#region src/parts/table-pagination.vue
2380
+ var table_pagination_default = /* @__PURE__ */ defineComponent({
2381
+ __name: "table-pagination",
2382
+ props: { paginationProps: {} },
2383
+ setup(__props) {
2384
+ return (_ctx, _cache) => {
2385
+ return openBlock(), createElementBlock("div", _hoisted_1$1, [renderSlot(_ctx.$slots, "pagination", normalizeProps(guardReactiveProps(__props.paginationProps)))]);
2386
+ };
2387
+ }
2388
+ });
2389
+ //#endregion
2390
+ //#region src/pin/use-header-geometry.ts
2391
+ /** One string per map: compares two maps in one step. */
2392
+ var signature = (numbers) => JSON.stringify(numbers);
2393
+ /**
2394
+ * Measured header geometry (C-47, C-48, C-71): the rendered width of every
2395
+ * header cell and, for the pinned cells, the cumulative offset: from the left
2396
+ * for a left-pinned cell (`--qt-pin-left`), from the right for a
2397
+ * right-pinned one (`--qt-pin-right`). One `ResizeObserver` watches the header cells and the
2398
+ * table; it reports width changes from any cause (a resize, a font that
2399
+ * loads, a container that narrows) in one batched callback, after layout, so
2400
+ * reading the cells there forces no extra layout. The observer is rebuilt
2401
+ * only when the drawn cells change, not when a width does. Nothing is
2402
+ * measured while inactive, and the observer is disconnected on unmount.
2403
+ */
2404
+ var useHeaderGeometry = (options) => {
2405
+ /** Rendered width of each header cell, by key. */
2406
+ const widths = shallowRef({});
2407
+ /** Rendered width of the table. */
2408
+ const tableWidth = shallowRef(0);
2409
+ /**
2410
+ * `--qt-pin-left` of each left-pinned cell and `--qt-pin-right` of each
2411
+ * right-pinned one, by key, in pixels.
2412
+ */
2413
+ const offsets = shallowRef({});
2414
+ /**
2415
+ * The exact width of every header cell, in drawing order: the `col` widths
2416
+ * of the body and footer tables with `scrollBody` (C-101).
2417
+ */
2418
+ const columns = shallowRef([]);
2419
+ let observer = null;
2420
+ const headerCells = (table) => table.querySelectorAll(":scope > thead > tr > *");
2421
+ const measure = (table) => {
2422
+ tableWidth.value = Math.round(table.getBoundingClientRect().width);
2423
+ const cells = options.cells();
2424
+ const next = {};
2425
+ const nextOffsets = {};
2426
+ const rights = [];
2427
+ const nextColumns = [];
2428
+ let left = 0;
2429
+ headerCells(table).forEach((cell, index) => {
2430
+ const drawn = cells[index];
2431
+ if (drawn) {
2432
+ const exact = cell.getBoundingClientRect().width;
2433
+ nextColumns.push(exact);
2434
+ next[drawn.key] = Math.round(exact);
2435
+ if (drawn.side === "left") {
2436
+ nextOffsets[drawn.key] = left;
2437
+ left += exact;
2438
+ } else if (drawn.side === "right") rights.push([drawn.key, exact]);
2439
+ }
2440
+ });
2441
+ let right = 0;
2442
+ for (let i = rights.length - 1; i >= 0; i--) {
2443
+ const [key, width] = rights[i];
2444
+ nextOffsets[key] = right;
2445
+ right += width;
2446
+ }
2447
+ if (signature(next) !== signature(widths.value)) widths.value = next;
2448
+ if (signature(nextOffsets) !== signature(offsets.value)) offsets.value = nextOffsets;
2449
+ if (signature(nextColumns) !== signature(columns.value)) columns.value = nextColumns;
2450
+ };
2451
+ const observe = () => {
2452
+ observer?.disconnect();
2453
+ observer = null;
2454
+ const table = options.table.value;
2455
+ if (!table || !options.active() || typeof ResizeObserver === "undefined") {
2456
+ if (Object.keys(offsets.value).length > 0) offsets.value = {};
2457
+ if (columns.value.length > 0) columns.value = [];
2458
+ return;
2459
+ }
2460
+ const current = new ResizeObserver(() => {
2461
+ measure(table);
2462
+ });
2463
+ observer = current;
2464
+ current.observe(table);
2465
+ headerCells(table).forEach((cell) => {
2466
+ current.observe(cell);
2467
+ });
2468
+ measure(table);
2469
+ };
2470
+ watch([
2471
+ () => options.table.value,
2472
+ options.active,
2473
+ () => options.cells().map((cell) => cell.side === "left" ? `${cell.key}*` : cell.side === "right" ? `${cell.key}>` : cell.key).join("|")
2474
+ ], () => {
2475
+ nextTick(observe);
2476
+ }, {
2477
+ immediate: true,
2478
+ flush: "post"
2479
+ });
2480
+ onBeforeUnmount(() => {
2481
+ observer?.disconnect();
2482
+ observer = null;
2483
+ });
2484
+ return {
2485
+ widths,
2486
+ tableWidth,
2487
+ offsets,
2488
+ columns
2489
+ };
2490
+ };
2491
+ //#endregion
2492
+ //#region src/reorder/use-column-reorder.ts
2493
+ var placeOf = (key) => key === "ArrowLeft" || key === "Home" ? "before" : "after";
2494
+ /**
2495
+ * Reordering a column with its handle (C-73): a pointer drag or the arrow
2496
+ * keys, Home and End, inside the column's region. The table keeps only the
2497
+ * drag in progress (P15); the order itself goes out as `update:columns` and
2498
+ * comes back, if the consumer wants it, as the order of `columns`. Like the
2499
+ * resize handle, the handle captures the pointer, so every drag event
2500
+ * arrives at the handle itself, and it has the focus, so Escape does too.
2501
+ */
2502
+ var useColumnReorder = (options) => {
2503
+ const dragging = shallowRef(null);
2504
+ let drag = null;
2505
+ /** The column whose handle moved it by key and still has the focus. */
2506
+ let refocus = null;
2507
+ /** Between the new `columns` and their render: a blur then is the move's. */
2508
+ let patching = false;
2509
+ const isReorderable = (column) => options.reorderable() && column.reorderable !== false;
2510
+ /** This table's own header cell, never one of a nested table. */
2511
+ const headerCell = (field) => options.table.value?.querySelector(`:scope > thead > tr > th[data-field="${CSS.escape(field)}"]`) ?? null;
2512
+ const end = () => {
2513
+ drag = null;
2514
+ dragging.value = null;
2515
+ };
2516
+ /** Every pointer event of a handle; one listener for the whole drag. */
2517
+ const onPointer = (event, column) => {
2518
+ if (event.type === "pointerdown") {
2519
+ if (event.button !== 0 || drag) return;
2520
+ const handle = event.currentTarget;
2521
+ event.preventDefault();
2522
+ handle.focus({ preventScroll: true });
2523
+ handle.setPointerCapture(event.pointerId);
2524
+ refocus = null;
2525
+ drag = {
2526
+ field: column.field,
2527
+ pointerId: event.pointerId,
2528
+ cells: options.layout.regionOf(column.field).flatMap((field) => {
2529
+ const box = headerCell(field)?.getBoundingClientRect();
2530
+ return box ? [{
2531
+ field,
2532
+ left: box.left,
2533
+ right: box.right
2534
+ }] : [];
2535
+ })
2536
+ };
2537
+ dragging.value = {
2538
+ field: column.field,
2539
+ target: null,
2540
+ place: "after"
2541
+ };
2542
+ return;
2543
+ }
2544
+ if (!drag || event.pointerId !== drag.pointerId) return;
2545
+ if (event.type === "pointermove") {
2546
+ const x = event.clientX;
2547
+ const over = drag.cells.find((cell) => x >= cell.left && x < cell.right);
2548
+ const target = over && over.field !== drag.field ? over.field : null;
2549
+ const place = over && x < (over.left + over.right) / 2 ? "before" : "after";
2550
+ const current = dragging.value;
2551
+ if (current?.target !== target || current.place !== place) dragging.value = {
2552
+ field: drag.field,
2553
+ target,
2554
+ place
2555
+ };
2556
+ return;
2557
+ }
2558
+ const done = dragging.value;
2559
+ end();
2560
+ if (event.type === "pointerup" && done?.target) options.layout.moveColumn(done.field, done.target, done.place);
2561
+ };
2562
+ const onKey = (event, column) => {
2563
+ const { key } = event;
2564
+ if (drag) {
2565
+ if (key === "Escape") {
2566
+ event.preventDefault();
2567
+ event.stopPropagation();
2568
+ end();
2569
+ }
2570
+ return;
2571
+ }
2572
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
2573
+ const region = options.layout.regionOf(column.field);
2574
+ const at = region.indexOf(column.field);
2575
+ const target = key === "ArrowLeft" ? region[at - 1] : key === "ArrowRight" ? region[at + 1] : key === "Home" ? region[0] : key === "End" ? region[region.length - 1] : void 0;
2576
+ if (at < 0 || target === void 0) return;
2577
+ event.preventDefault();
2578
+ if (target !== column.field) {
2579
+ refocus = column.field;
2580
+ options.layout.moveColumn(column.field, target, placeOf(key));
2581
+ }
2582
+ };
2583
+ watch(options.columns, () => {
2584
+ patching = true;
2585
+ });
2586
+ watch(options.columns, () => {
2587
+ patching = false;
2588
+ if (drag) end();
2589
+ const field = refocus;
2590
+ if (field !== null) nextTick(() => {
2591
+ const handle = headerCell(field)?.querySelector(":scope > .qt-reorder-handle");
2592
+ if (handle && refocus === field && document.activeElement !== handle) handle.focus({ preventScroll: true });
2593
+ });
2594
+ }, { flush: "post" });
2595
+ onBeforeUnmount(end);
2596
+ /**
2597
+ * The listeners of one handle, as one `v-on` object made once per handle.
2598
+ * Pointer capture sends every drag event to the handle itself.
2599
+ */
2600
+ const listeners = (column) => {
2601
+ const pointer = (event) => {
2602
+ onPointer(event, column());
2603
+ };
2604
+ return {
2605
+ pointerdown: pointer,
2606
+ pointermove: pointer,
2607
+ pointerup: pointer,
2608
+ pointercancel: pointer,
2609
+ lostpointercapture: pointer,
2610
+ keydown: (event) => {
2611
+ onKey(event, column());
2612
+ },
2613
+ blur: () => {
2614
+ if (!patching) refocus = null;
2615
+ },
2616
+ click: (event) => {
2617
+ event.stopPropagation();
2618
+ }
2619
+ };
2620
+ };
2621
+ return {
2622
+ isReorderable,
2623
+ dragging,
2624
+ listeners
2625
+ };
2626
+ };
2627
+ //#endregion
2628
+ //#region src/resize/use-auto-width.ts
2629
+ /**
2630
+ * The query without what moves inside one result: the paging position, the
2631
+ * page size and the sort. Two queries alike in the rest ask for the same
2632
+ * rows, in another order or slice (C-100).
2633
+ */
2634
+ var resultOf = (query) => isCursorQuery(query) ? {
2635
+ ...query,
2636
+ cursor: null,
2637
+ pageSize: 0,
2638
+ sort: null
2639
+ } : {
2640
+ ...query,
2641
+ page: 1,
2642
+ pageSize: 0,
2643
+ sort: null
2644
+ };
2645
+ var sameWidths = (a, b) => {
2646
+ const keys = Object.keys(a);
2647
+ return keys.length === Object.keys(b).length && keys.every((key) => a[key] === b[key]);
2648
+ };
2649
+ var none = Object.freeze({});
2650
+ /**
2651
+ * Automatic column widths (C-100, ADR 0014). With `autoWidth`, every visible
2652
+ * column without `Column.width` is measured (C-99) after the drawn rows
2653
+ * change, clamped as a resize is (C-49), and drawn at that width. The widths
2654
+ * are UI state (P2): never emitted, never written to `columns`, gone when
2655
+ * `autoWidth` is off or the column gets a width. Within one result (the query
2656
+ * apart from its paging position, page size and sort) they only grow, so a
2657
+ * page, a sort or a live tick never narrows a column.
2658
+ */
2659
+ var useAutoWidth = (options) => {
2660
+ const widths = shallowRef(none);
2661
+ /** The result the widths were last measured for, `null` before one. */
2662
+ let result = null;
2663
+ /** The next measure starts over: the result moved before it could run. */
2664
+ let fromScratch = false;
2665
+ /** A measure found the table not displayed: measure once it is. */
2666
+ let waiting = false;
2667
+ let observer = null;
2668
+ const autoColumns = () => options.columns().filter((column) => !column.width);
2669
+ const clear = () => {
2670
+ widths.value = none;
2671
+ result = null;
2672
+ fromScratch = false;
2673
+ waiting = false;
2674
+ observer?.disconnect();
2675
+ observer = null;
2676
+ };
2677
+ const measure = (rowsChanged) => {
2678
+ const table = options.table.value;
2679
+ const columns = autoColumns();
2680
+ if (!table || columns.length === 0) return;
2681
+ const query = options.query();
2682
+ if (result === null || rowsChanged && (options.rowsUpdate() === "reset" || !sameQuery(resultOf(result), resultOf(query)))) {
2683
+ fromScratch = true;
2684
+ result = cloneQuery(query);
2685
+ }
2686
+ if (options.rows().length === 0) return;
2687
+ const measured = measureColumnWidths(table, columns.map((column) => column.field), options.body(), { filters: true });
2688
+ if (Object.keys(measured).length === 0) {
2689
+ waiting = true;
2690
+ return;
2691
+ }
2692
+ waiting = false;
2693
+ const previous = widths.value;
2694
+ const next = {};
2695
+ for (const column of columns) {
2696
+ const width = measured[column.field];
2697
+ if (width === void 0) continue;
2698
+ const fitted = clampWidth({
2699
+ ...column,
2700
+ maxWidth: limitOf(column.maxWidth) ?? options.max()
2701
+ }, width);
2702
+ next[column.field] = fromScratch ? fitted : Math.max(fitted, previous[column.field] ?? 0);
2703
+ }
2704
+ fromScratch = false;
2705
+ if (!sameWidths(next, previous)) widths.value = next;
2706
+ };
2707
+ const observe = (table) => {
2708
+ observer?.disconnect();
2709
+ observer = null;
2710
+ if (!table || typeof ResizeObserver === "undefined") return;
2711
+ observer = new ResizeObserver(() => {
2712
+ if (waiting) measure(false);
2713
+ });
2714
+ observer.observe(table);
2715
+ };
2716
+ watch([
2717
+ () => options.enabled(),
2718
+ () => options.max(),
2719
+ () => options.table.value,
2720
+ () => options.rows(),
2721
+ () => autoColumns().map((column) => column.field).join("|")
2722
+ ], ([enabled, max, table, rows], [wasEnabled, oldMax, oldTable, oldRows]) => {
2723
+ if (!enabled) {
2724
+ if (wasEnabled) clear();
2725
+ return;
2726
+ }
2727
+ if (!wasEnabled || max !== oldMax) fromScratch = true;
2728
+ if (table !== oldTable || !wasEnabled) observe(table);
2729
+ measure(rows !== oldRows);
2730
+ }, {
2731
+ immediate: true,
2732
+ flush: "post"
2733
+ });
2734
+ onBeforeUnmount(() => {
2735
+ observer?.disconnect();
2736
+ observer = null;
2737
+ });
2738
+ return { widths };
2739
+ };
2740
+ //#endregion
2741
+ //#region src/scroll/use-scroll-body.ts
2742
+ var isDevelopment$1 = () => {
2743
+ try {
2744
+ return process.env.NODE_ENV !== "production";
2745
+ } catch {
2746
+ return true;
2747
+ }
2748
+ };
2749
+ var automaticLayout = "[QueryTable] `scrollBody`: the body table has the automatic layout, so its columns follow its rows, not the header. Give the body and footer tables `table-layout: fixed` and a width that is a length or a percentage, such as `width: 100%`: with `width: auto` or `max-content` the browser uses the automatic layout whatever `table-layout` says (C-101).";
2750
+ /**
2751
+ * Header, body and footer of `scrollBody` scroll sideways together (C-101):
2752
+ * one passive `scroll` listener on each wrapper sets the `scrollLeft` of the
2753
+ * others to its own. A position written here is remembered, so the `scroll`
2754
+ * event it fires is not taken for one of the user's. The table writes no
2755
+ * style and no attribute to the wrappers. Off, nothing is listened to.
2756
+ */
2757
+ var useScrollBody = (options) => {
2758
+ let attached = [];
2759
+ /** The `scrollLeft` this table wrote to a wrapper, until its event. */
2760
+ const written = /* @__PURE__ */ new WeakMap();
2761
+ let warned = false;
2762
+ let clamped = false;
2763
+ /** Every wrapper but `source` to `left`, remembering what was written. */
2764
+ const follow = (source, left) => {
2765
+ for (const element of attached) if (element !== source && element.scrollLeft !== left) {
2766
+ element.scrollLeft = left;
2767
+ written.set(element, element.scrollLeft);
2768
+ if (!clamped && source === options.wrappers().body && left - element.scrollLeft >= 1 && isDevelopment$1()) {
2769
+ clamped = true;
2770
+ console.warn("[QueryTable] `scrollBody`: `.qt-table-head` or `.qt-table-foot` cannot scroll sideways as far as `.qt-table-body`, so its columns end shifted. Give it a vertical scrollbar as wide as that of the body (`overflow-y: scroll`; a transparent `scrollbar-color` hides it) (C-101).");
2771
+ }
2772
+ }
2773
+ };
2774
+ const onScroll = (event) => {
2775
+ const source = event.currentTarget;
2776
+ const left = source.scrollLeft;
2777
+ const echo = written.get(source);
2778
+ written.delete(source);
2779
+ if (echo !== left) follow(source, left);
2780
+ };
2781
+ const detach = () => {
2782
+ for (const element of attached) element.removeEventListener("scroll", onScroll);
2783
+ attached = [];
2784
+ };
2785
+ watch(() => options.enabled() ? options.wrappers() : null, (wrappers) => {
2786
+ detach();
2787
+ if (!wrappers) return;
2788
+ attached = [
2789
+ wrappers.head,
2790
+ wrappers.body,
2791
+ wrappers.foot
2792
+ ].filter((element) => element !== null);
2793
+ for (const element of attached) element.addEventListener("scroll", onScroll, { passive: true });
2794
+ if (wrappers.body) follow(wrappers.body, wrappers.body.scrollLeft);
2795
+ const table = options.bodyTable();
2796
+ if (table && !warned && isDevelopment$1() && getComputedStyle(table).tableLayout !== "fixed") {
2797
+ warned = true;
2798
+ console.warn(automaticLayout);
2799
+ }
2800
+ }, {
2801
+ flush: "post",
2802
+ immediate: true
2803
+ });
2804
+ /**
2805
+ * `table-layout: fixed` applies only to a table with a definite width:
2806
+ * under `width: auto` or `max-content` the browser lays the body out
2807
+ * automatically while `tableLayout` still reads `fixed`, and a cell wider
2808
+ * than its `col` widens its column and the table. That shows once the
2809
+ * rows hold such a cell, so it is checked whenever the rows or the `col`
2810
+ * widths change, against `col` widths that match the header cells (not
2811
+ * ones a change of the drawn columns has made stale until measured).
2812
+ */
2813
+ const checkLayout = () => {
2814
+ const head = options.headTable();
2815
+ const body = options.bodyTable();
2816
+ if (warned || !head || !body) return;
2817
+ const cells = head.querySelectorAll(":scope > thead > tr > *");
2818
+ const widths = options.colWidths();
2819
+ if (cells.length === 0 || cells.length !== widths.length || [...cells].some((cell, i) => {
2820
+ const width = widths[i];
2821
+ return width === void 0 || Math.abs(cell.getBoundingClientRect().width - width) >= .5;
2822
+ })) return;
2823
+ if (body.getBoundingClientRect().width - head.getBoundingClientRect().width >= 1) {
2824
+ warned = true;
2825
+ console.warn(automaticLayout);
2826
+ }
2827
+ };
2828
+ if (isDevelopment$1()) watch(() => options.enabled() ? [
2829
+ options.colWidths(),
2830
+ options.rows(),
2831
+ options.bodyTable()
2832
+ ] : null, (sources) => {
2833
+ if (sources) checkLayout();
2834
+ }, { flush: "post" });
2835
+ onBeforeUnmount(detach);
2836
+ };
2837
+ //#endregion
2838
+ //#region src/use-query-table.ts
2839
+ /** The TanStack features of a Query Table, the two plugins included. */
2840
+ var features = tableFeatures({
2841
+ rowSortingFeature,
2842
+ rowPaginationFeature,
2843
+ columnFilteringFeature,
2844
+ globalFilteringFeature,
2845
+ rowSelectionFeature,
2846
+ rowExpandingFeature,
2847
+ columnVisibilityFeature,
2848
+ columnOrderingFeature,
2849
+ columnPinningFeature,
2850
+ rowPinningFeature,
2851
+ serverQueryFeature,
2852
+ filterInputFeature
2853
+ });
2854
+ var blank = Object.freeze({
2855
+ text: "",
2856
+ condition: null
2857
+ });
2858
+ var defaultPageSizes = [
2859
+ 10,
2860
+ 20,
2861
+ 30,
2862
+ 50,
2863
+ 100
2864
+ ];
2865
+ /** Only the `true` entries: the selection a consumer stores. */
2866
+ var selectedOnly = (selection) => Object.fromEntries(Object.entries(selection).filter(([, value]) => value));
2867
+ var noPinnedRows = Object.freeze({
2868
+ top: Object.freeze([]),
2869
+ bottom: Object.freeze([])
2870
+ });
2871
+ var sameKeys = (a, b) => a.length === b.length && a.every((key, i) => key === b[i]);
2872
+ /**
2873
+ * The state and actions of a server-side table: TanStack Table with
2874
+ * `serverQueryFeature` and `filterInputFeature`, in a Vue scope. Disposed
2875
+ * with the scope (C-62).
2876
+ */
2877
+ function useQueryTable(options) {
2878
+ const query = () => toValue(options.query);
2879
+ const rows = () => toValue(options.rows) ?? [];
2880
+ const totalRows = () => toValue(options.totalRows) ?? null;
2881
+ const cursors = () => toValue(options.cursors) ?? null;
2882
+ const columns = () => toValue(options.columns);
2883
+ const rowKey = () => toValue(options.rowKey);
2884
+ const hasSubtable = () => toValue(options.hasSubtable) ?? false;
2885
+ const canExpand = (row, index) => {
2886
+ if (!hasSubtable()) return false;
2887
+ const expandable = toValue(options.rowExpandable);
2888
+ return expandable === void 0 || expandable(row, index);
2889
+ };
2890
+ const pinnedRows = () => toValue(options.rowPinning);
2891
+ const pinningEnabled = computed(() => rowKey() !== void 0 && pinnedRows() !== void 0);
2892
+ const rowPinningState = computed(() => {
2893
+ if (!pinningEnabled.value) return noPinnedRows;
2894
+ const map = pinnedRows();
2895
+ return {
2896
+ top: map.top ?? [],
2897
+ bottom: map.bottom ?? []
2898
+ };
2899
+ });
2900
+ const keyOf = (row, index) => {
2901
+ const key = rowKey();
2902
+ if (typeof key === "function") return key(row, index);
2903
+ if (typeof key === "string") return row[key];
2904
+ return index;
2905
+ };
2906
+ const idOf = (row, index) => String(keyOf(row, index));
2907
+ const projection = computed(() => projectServerQuery({
2908
+ query: query(),
2909
+ rowCount: totalRows(),
2910
+ cursors: cursors(),
2911
+ pageRows: rows().length
2912
+ }));
2913
+ const columnDefs = computed(() => columns().map((column) => ({
2914
+ id: column.field,
2915
+ accessorFn: (row) => valueAt(row, column.field),
2916
+ enableSorting: column.sortable !== false,
2917
+ filterType: columnTypeOf(column),
2918
+ filterDefaultCondition: column.filterDefaultCondition
2919
+ })));
2920
+ const columnVisibility = computed(() => Object.fromEntries(columns().map((column) => [column.field, !column.hide])));
2921
+ const columnOrder = computed(() => columns().map((column) => column.field));
2922
+ const columnPinning = computed(() => ({
2923
+ start: columns().filter((column) => sideOf(column) === "left").map((column) => column.field),
2924
+ end: columns().filter((column) => sideOf(column) === "right").map((column) => column.field)
2925
+ }));
2926
+ /** A layout change goes to the consumer; an equal result is no change (C-68). */
2927
+ const tell = (next, reason) => {
2928
+ if (next) options.onColumnsChange?.(next, reason);
2929
+ };
2930
+ /** Updates emitted so far: tells whether an action emitted one. */
2931
+ let emits = 0;
2932
+ const table = useTable({
2933
+ features,
2934
+ columns: columnDefs,
2935
+ get data() {
2936
+ return rows();
2937
+ },
2938
+ getRowId: (row, index) => idOf(row, index),
2939
+ get query() {
2940
+ return query();
2941
+ },
2942
+ onQueryChange: (next, reason) => {
2943
+ emits += 1;
2944
+ options.onQueryChange(next, reason);
2945
+ },
2946
+ get cursors() {
2947
+ return cursors();
2948
+ },
2949
+ get rowCount() {
2950
+ return totalRows() ?? void 0;
2951
+ },
2952
+ get pageCount() {
2953
+ return projection.value.pageCount;
2954
+ },
2955
+ get enableSorting() {
2956
+ return toValue(options.sortable) ?? false;
2957
+ },
2958
+ get filterDebounce() {
2959
+ return toValue(options.filterDebounce) ?? 100;
2960
+ },
2961
+ enableRowSelection: true,
2962
+ manualExpanding: true,
2963
+ getRowCanExpand: (row) => canExpand(row.original, row.index),
2964
+ onRowSelectionChange: (updater) => {
2965
+ const current = toValue(options.selection) ?? {};
2966
+ options.onSelectionChange?.(selectedOnly(functionalUpdate(updater, current)));
2967
+ },
2968
+ onColumnVisibilityChange: (updater) => tell(applyVisibility(columns(), functionalUpdate(updater, columnVisibility.value)), "visibility"),
2969
+ onColumnOrderChange: (updater) => tell(applyOrder(columns(), functionalUpdate(updater, columnOrder.value)), "order"),
2970
+ onColumnPinningChange: (updater) => tell(applyPinning(columns(), functionalUpdate(updater, columnPinning.value)), "pin"),
2971
+ get enableRowPinning() {
2972
+ return pinningEnabled.value;
2973
+ },
2974
+ onRowPinningChange: (updater) => {
2975
+ if (!pinningEnabled.value) return;
2976
+ const current = rowPinningState.value;
2977
+ const next = functionalUpdate(updater, current);
2978
+ if (!sameKeys(next.top, current.top) || !sameKeys(next.bottom, current.bottom)) options.onRowPinningChange?.({
2979
+ top: [...next.top],
2980
+ bottom: [...next.bottom]
2981
+ });
2982
+ },
2983
+ state: {
2984
+ get sorting() {
2985
+ return projection.value.state.sorting;
2986
+ },
2987
+ get columnFilters() {
2988
+ return projection.value.state.columnFilters;
2989
+ },
2990
+ get pagination() {
2991
+ return projection.value.state.pagination;
2992
+ },
2993
+ get globalFilter() {
2994
+ return projection.value.state.globalFilter;
2995
+ },
2996
+ get rowSelection() {
2997
+ return toValue(options.selection) ?? {};
2998
+ },
2999
+ get columnVisibility() {
3000
+ return columnVisibility.value;
3001
+ },
3002
+ get columnOrder() {
3003
+ return columnOrder.value;
3004
+ },
3005
+ get columnPinning() {
3006
+ return columnPinning.value;
3007
+ },
3008
+ get rowPinning() {
3009
+ return rowPinningState.value;
3010
+ }
3011
+ }
3012
+ });
3013
+ onScopeDispose(() => dispose(table));
3014
+ const columnById = (field) => table.getAllLeafColumns().find((column) => column.id === field);
3015
+ const entries = computed(() => {
3016
+ const byField = new Map(columns().map((column, index) => [column.field, {
3017
+ column,
3018
+ index
3019
+ }]));
3020
+ return [
3021
+ ...table.getStartVisibleLeafColumns(),
3022
+ ...table.getCenterVisibleLeafColumns(),
3023
+ ...table.getEndVisibleLeafColumns()
3024
+ ].map((column) => byField.get(column.id)).filter((entry) => !!entry);
3025
+ });
3026
+ const hasPinned = computed(() => entries.value.some((entry) => sideOf(entry.column) === "left"));
3027
+ const regionOf = (field) => {
3028
+ const own = entries.value.find((entry) => entry.column.field === field);
3029
+ if (!own) return [];
3030
+ const side = sideOf(own.column);
3031
+ return entries.value.filter((entry) => sideOf(entry.column) === side).map((entry) => entry.column.field);
3032
+ };
3033
+ const moveColumn = (field, target, place) => {
3034
+ if (field !== target && regionOf(field).includes(target)) table.setColumnOrder(moveField(columnOrder.value, field, target, place));
3035
+ };
3036
+ /**
3037
+ * A column's control. Every slot of every column gets one, so making it
3038
+ * does no work: `pinned`, `canMoveLeft` and `canMoveRight` read the layout
3039
+ * when they are read (a region is O(n)), and a slot that never reads them
3040
+ * costs nothing. A control kept past a re-render reads the current layout.
3041
+ */
3042
+ const controlOf = (field) => {
3043
+ const place = () => {
3044
+ const region = regionOf(field);
3045
+ return {
3046
+ at: region.indexOf(field),
3047
+ size: region.length
3048
+ };
3049
+ };
3050
+ return {
3051
+ get pinned() {
3052
+ const column = columns().find((candidate) => candidate.field === field);
3053
+ return column ? sideOf(column) : false;
3054
+ },
3055
+ pin: (side) => columnById(field)?.pin(side === "left" ? "start" : side === "right" ? "end" : false),
3056
+ hide: () => columnById(field)?.toggleVisibility(false),
3057
+ get canMoveLeft() {
3058
+ return place().at > 0;
3059
+ },
3060
+ get canMoveRight() {
3061
+ const { at, size } = place();
3062
+ return at >= 0 && at < size - 1;
3063
+ },
3064
+ move: (direction) => {
3065
+ const current = regionOf(field);
3066
+ const from = current.indexOf(field);
3067
+ const target = current[from + (direction === "left" ? -1 : 1)];
3068
+ if (from >= 0 && target !== void 0) moveColumn(field, target, direction === "left" ? "before" : "after");
3069
+ }
3070
+ };
3071
+ };
3072
+ const layout = {
3073
+ controlOf,
3074
+ regionOf,
3075
+ moveColumn
3076
+ };
3077
+ /** Typed and not yet answered; `null` when the input shows the query. */
3078
+ const typed = shallowRef(null);
3079
+ let searchTimer;
3080
+ const cancelSearch = () => {
3081
+ if (searchTimer !== void 0) {
3082
+ clearTimeout(searchTimer);
3083
+ searchTimer = void 0;
3084
+ }
3085
+ };
3086
+ const applySearch = () => {
3087
+ const pending = searchTimer !== void 0;
3088
+ cancelSearch();
3089
+ if (!pending || typed.value === null) return false;
3090
+ const text = typed.value;
3091
+ const before = emits;
3092
+ table.setGlobalFilter(text);
3093
+ const emitted = emits !== before;
3094
+ if (!emitted || searchOf(query()) === text) typed.value = null;
3095
+ return emitted;
3096
+ };
3097
+ const setSearch = (text) => {
3098
+ typed.value = text;
3099
+ cancelSearch();
3100
+ const wait = toValue(options.searchDebounce) ?? 300;
3101
+ searchTimer = setTimeout(applySearch, Math.max(0, wait));
3102
+ if (wait <= 0 || text.trim() === "") applySearch();
3103
+ };
3104
+ watch(() => searchOf(query()), () => {
3105
+ if (searchTimer === void 0) typed.value = null;
3106
+ }, { flush: "sync" });
3107
+ onScopeDispose(cancelSearch);
3108
+ const search = {
3109
+ text: computed(() => typed.value ?? searchOf(query())),
3110
+ set: setSearch,
3111
+ apply: applySearch
3112
+ };
3113
+ const draftOf = (field) => columnById(field)?.getFilterInput() ?? blank;
3114
+ const filters = {
3115
+ draftOf,
3116
+ setInput: (field, text, bound) => columnById(field)?.setFilterInput(text, bound),
3117
+ apply: (field) => columnById(field)?.applyFilterInput(),
3118
+ flushAll: () => table.flushPendingFilters(),
3119
+ setCondition: (field, condition) => columnById(field)?.setFilterCondition(condition),
3120
+ clear: (field) => columnById(field)?.clearFilterInput(),
3121
+ clearAll: () => table.clearAllFilters(),
3122
+ canClearAll: () => table.getCanClearAllFilters(),
3123
+ labelOf: (field) => columnById(field)?.getFilterLabel() ?? null,
3124
+ multiOf: (field) => draftOf(field).multi ?? 0
3125
+ };
3126
+ const isSortable = (column) => (toValue(options.sortable) ?? false) && column.sortable !== false;
3127
+ const sort = {
3128
+ isSortable,
3129
+ sortOf: (column) => {
3130
+ const current = query().sort;
3131
+ return current?.field === column.field ? current.direction : null;
3132
+ },
3133
+ sortBy: (column, direction) => {
3134
+ const target = columnById(column.field);
3135
+ if (!isSortable(column) || !target) return;
3136
+ applySearch();
3137
+ if (direction) target.toggleSorting(direction === "desc", false);
3138
+ else target.toggleQuerySorting();
3139
+ }
3140
+ };
3141
+ const pageCountFor = (pageSize) => {
3142
+ const total = totalRows();
3143
+ return total !== null && pageSize >= 1 ? Math.max(1, Math.ceil(total / pageSize)) : null;
3144
+ };
3145
+ /** Page mode: there is a page after `base.page` (C-23). */
3146
+ const hasNext = (base) => {
3147
+ const count = pageCountFor(base.pageSize);
3148
+ return count !== null ? base.page < count : rows().length >= base.pageSize;
3149
+ };
3150
+ const baseQuery = () => table.getBaseQuery();
3151
+ /**
3152
+ * Applies pending search and filter text before a page action; `true`
3153
+ * when that changed the query, so the page asked for is dropped (C-14).
3154
+ */
3155
+ const flushBeforePage = () => {
3156
+ const searched = applySearch();
3157
+ const filtered = table.flushPendingFilters();
3158
+ return searched || filtered;
3159
+ };
3160
+ const goTo = (page) => {
3161
+ table.setPagination((old) => ({
3162
+ ...old,
3163
+ pageIndex: page - 1
3164
+ }));
3165
+ };
3166
+ const step = (by) => {
3167
+ table.setPagination((old) => ({
3168
+ ...old,
3169
+ pageIndex: old.pageIndex + by
3170
+ }));
3171
+ };
3172
+ const setPage = (page) => {
3173
+ if (!Number.isFinite(page) || flushBeforePage()) return;
3174
+ const base = baseQuery();
3175
+ if (isCursorQuery(base)) return;
3176
+ const count = pageCountFor(base.pageSize);
3177
+ const target = Math.max(1, Math.trunc(page));
3178
+ goTo(count === null ? target : Math.min(target, count));
3179
+ };
3180
+ const nextPage = () => {
3181
+ if (flushBeforePage()) return;
3182
+ const base = baseQuery();
3183
+ if (isCursorQuery(base)) step(1);
3184
+ else if (hasNext(base)) goTo(base.page + 1);
3185
+ };
3186
+ const previousPage = () => {
3187
+ if (flushBeforePage()) return;
3188
+ const base = baseQuery();
3189
+ if (isCursorQuery(base)) step(-1);
3190
+ else goTo(Math.max(1, base.page - 1));
3191
+ };
3192
+ const setPageSize = (size) => {
3193
+ if (!Number.isInteger(size) || size < 1) return;
3194
+ applySearch();
3195
+ table.flushPendingFilters();
3196
+ table.setPagination((old) => ({
3197
+ ...old,
3198
+ pageSize: size
3199
+ }));
3200
+ };
3201
+ const pagination = computed(() => {
3202
+ const current = query();
3203
+ const cursorMode = isCursorQuery(current);
3204
+ const around = cursors();
3205
+ return {
3206
+ page: cursorMode ? 1 : current.page,
3207
+ pageSize: current.pageSize,
3208
+ pageCount: cursorMode ? null : pageCountFor(current.pageSize),
3209
+ totalRows: totalRows(),
3210
+ pageSizeOptions: toValue(options.pageSizeOptions) ?? defaultPageSizes,
3211
+ canPrevious: cursorMode ? !!around?.prev : current.page > 1,
3212
+ canNext: cursorMode ? !!around?.next : hasNext(current),
3213
+ setPage,
3214
+ nextPage,
3215
+ previousPage,
3216
+ setPageSize,
3217
+ cursorMode
3218
+ };
3219
+ });
3220
+ const expandedState = computed(() => {
3221
+ const state = table.atoms.expanded.get();
3222
+ return state === true ? {} : state;
3223
+ });
3224
+ const setExpanded = (update) => {
3225
+ table.setExpanded((old) => update(old === true ? {} : { ...old }));
3226
+ };
3227
+ const single = () => toValue(options.expandMode) === "single";
3228
+ const keepFirstOpen = (state, current) => {
3229
+ const first = current.map(idOf).find((id) => state[id]);
3230
+ return first === void 0 ? {} : { [first]: true };
3231
+ };
3232
+ const expansion = {
3233
+ keyOf,
3234
+ canExpand,
3235
+ isExpanded: (row, index) => !!expandedState.value[idOf(row, index)] && canExpand(row, index),
3236
+ toggle: (row, index) => {
3237
+ if (!canExpand(row, index)) return;
3238
+ const id = idOf(row, index);
3239
+ const expanded = !expandedState.value[id];
3240
+ const closed = [];
3241
+ if (expanded && single()) rows().forEach((other, otherIndex) => {
3242
+ const otherId = idOf(other, otherIndex);
3243
+ if (otherId !== id && expandedState.value[otherId]) closed.push({
3244
+ row: other,
3245
+ index: otherIndex
3246
+ });
3247
+ });
3248
+ setExpanded((state) => {
3249
+ if (expanded) {
3250
+ if (single()) return { [id]: true };
3251
+ state[id] = true;
3252
+ } else delete state[id];
3253
+ return state;
3254
+ });
3255
+ for (const other of closed) options.onRowExpansionChange?.({
3256
+ row: other.row,
3257
+ rowIndex: other.index,
3258
+ rowKey: keyOf(other.row, other.index),
3259
+ expanded: false
3260
+ });
3261
+ options.onRowExpansionChange?.({
3262
+ row,
3263
+ rowIndex: index,
3264
+ rowKey: keyOf(row, index),
3265
+ expanded
3266
+ });
3267
+ },
3268
+ collapseAll: () => table.setExpanded({}),
3269
+ expandAll: () => {
3270
+ if (hasSubtable() && !single()) setExpanded((state) => {
3271
+ rows().forEach((row, index) => {
3272
+ if (canExpand(row, index)) state[idOf(row, index)] = true;
3273
+ });
3274
+ return state;
3275
+ });
3276
+ }
3277
+ };
3278
+ watch(rows, (current) => {
3279
+ setExpanded((state) => {
3280
+ if (rowKey() === void 0) state = {};
3281
+ else {
3282
+ const present = new Set(current.map(idOf));
3283
+ for (const id of Object.keys(state)) if (!present.has(id)) delete state[id];
3284
+ }
3285
+ let firstSeeded;
3286
+ if (hasSubtable()) current.forEach((row, index) => {
3287
+ const seeded = row.isExpanded;
3288
+ if (!canExpand(row, index)) delete state[idOf(row, index)];
3289
+ else if (seeded === true) {
3290
+ state[idOf(row, index)] = true;
3291
+ firstSeeded ??= idOf(row, index);
3292
+ } else if (seeded === false) delete state[idOf(row, index)];
3293
+ });
3294
+ if (single()) return firstSeeded === void 0 ? keepFirstOpen(state, current) : { [firstSeeded]: true };
3295
+ return state;
3296
+ });
3297
+ }, { immediate: true });
3298
+ watch(single, (isSingle) => {
3299
+ if (isSingle) setExpanded((state) => keepFirstOpen(state, rows()));
3300
+ });
3301
+ const selection = {
3302
+ enabled: computed(() => toValue(options.selection) !== void 0),
3303
+ isSelected: (row, index) => !!toValue(options.selection)?.[idOf(row, index)],
3304
+ toggle: (row, index) => {
3305
+ const id = idOf(row, index);
3306
+ table.setRowSelection((old) => {
3307
+ const next = { ...old };
3308
+ if (next[id]) delete next[id];
3309
+ else next[id] = true;
3310
+ return next;
3311
+ });
3312
+ },
3313
+ allSelected: computed(() => table.getIsAllPageRowsSelected()),
3314
+ someSelected: computed(() => table.getIsSomePageRowsSelected()),
3315
+ toggleAll: (value) => table.toggleAllPageRowsSelected(value)
3316
+ };
3317
+ const bodyRows = computed(() => {
3318
+ if (!pinningEnabled.value) return rows().map((row, index) => ({
3319
+ row,
3320
+ index,
3321
+ pinned: false
3322
+ }));
3323
+ const of = (row, pinned) => ({
3324
+ row: row.original,
3325
+ index: row.index,
3326
+ pinned
3327
+ });
3328
+ return [
3329
+ ...table.getTopRows().map((row) => of(row, "top")),
3330
+ ...table.getCenterRows().map((row) => of(row, false)),
3331
+ ...table.getBottomRows().map((row) => of(row, "bottom"))
3332
+ ];
3333
+ });
3334
+ const positionOf = (id) => {
3335
+ const { top, bottom } = rowPinningState.value;
3336
+ return top.includes(id) ? "top" : bottom.includes(id) ? "bottom" : false;
3337
+ };
3338
+ return {
3339
+ table,
3340
+ columns: entries,
3341
+ hasPinned,
3342
+ layout,
3343
+ sort,
3344
+ filters,
3345
+ search,
3346
+ pagination,
3347
+ expansion,
3348
+ selection,
3349
+ rowPinning: {
3350
+ enabled: pinningEnabled,
3351
+ rows: bodyRows,
3352
+ pin: (row, index, position) => {
3353
+ const id = idOf(row, index);
3354
+ if (!pinningEnabled.value || positionOf(id) === position) return;
3355
+ table.getRow(id, true)?.pin(position);
3356
+ }
3357
+ },
3358
+ baseQuery
3359
+ };
3360
+ }
3361
+ //#endregion
3362
+ //#region src/virtual/use-load-more.ts
3363
+ /**
3364
+ * Infinite scroll (C-88 to C-90): whether there is more to load, the
3365
+ * automatic request near the end of `rows` and `loadMore`. The rows are
3366
+ * the consumer's; the table only emits the next page action.
3367
+ */
3368
+ var useLoadMore = (o) => {
3369
+ const enabled = computed(() => !!o.infinite() && o.rowKey() !== void 0);
3370
+ const threshold = () => {
3371
+ const value = o.infinite();
3372
+ const given = typeof value === "object" ? value.threshold : void 0;
3373
+ return given !== void 0 && given >= 0 ? Math.trunc(given) : 5;
3374
+ };
3375
+ const canLoadMore = computed(() => {
3376
+ const query = o.query();
3377
+ if (isCursorQuery(query)) return !!o.cursors()?.next;
3378
+ const total = o.totalRows();
3379
+ return total !== null ? query.page < Math.max(1, Math.ceil(total / query.pageSize)) : o.rows().length >= query.page * query.pageSize;
3380
+ });
3381
+ const loadMore = () => {
3382
+ if (enabled.value && canLoadMore.value && !o.loading()) o.nextPage();
3383
+ };
3384
+ const seen = shallowRef(false);
3385
+ let observer = null;
3386
+ watch([
3387
+ enabled,
3388
+ o.virtual,
3389
+ o.rows,
3390
+ o.table
3391
+ ], () => {
3392
+ observer?.disconnect();
3393
+ observer = null;
3394
+ seen.value = false;
3395
+ const count = o.rows().length;
3396
+ const tbody = o.table.value?.tBodies[0];
3397
+ if (!enabled.value || o.virtual() || !tbody || count === 0 || typeof IntersectionObserver === "undefined") return;
3398
+ const others = tbody.querySelectorAll(":scope > tr[data-row-index]:not([data-pinned-row])");
3399
+ const target = others[Math.max(0, others.length - 1 - threshold())];
3400
+ if (target) {
3401
+ observer = new IntersectionObserver((entries) => {
3402
+ seen.value = entries.some((entry) => entry.isIntersecting);
3403
+ });
3404
+ observer.observe(target);
3405
+ }
3406
+ }, {
3407
+ flush: "post",
3408
+ immediate: true
3409
+ });
3410
+ onBeforeUnmount(() => observer?.disconnect());
3411
+ let asked = "";
3412
+ watchEffect(() => {
3413
+ if (!enabled.value || !canLoadMore.value || o.loading()) return;
3414
+ const range = o.window();
3415
+ if (!(o.virtual() ? range !== null && range.end >= range.count - threshold() : seen.value)) return;
3416
+ const signature = `${JSON.stringify(o.query())}#${o.rows().length}`;
3417
+ if (signature !== asked) {
3418
+ asked = signature;
3419
+ o.nextPage();
3420
+ }
3421
+ }, { flush: "post" });
3422
+ let warned = false;
3423
+ watchEffect(() => {
3424
+ if (!warned && o.infinite() && o.rowKey() === void 0) {
3425
+ warned = true;
3426
+ try {
3427
+ if (process.env.NODE_ENV === "production") return;
3428
+ } catch {}
3429
+ console.warn("[QueryTable] `infinite` needs `rowKey`; it is ignored without one (C-88).");
3430
+ }
3431
+ });
3432
+ return {
3433
+ enabled,
3434
+ canLoadMore,
3435
+ loadMore
3436
+ };
3437
+ };
3438
+ //#endregion
3439
+ //#region src/body/group-runs.ts
3440
+ /** The runs as a string (start and count of each), or `null` without groups. */
3441
+ var groupShape = (groups) => groups ? groups.runs.map((run) => `${run.start}:${run.count}`).join(",") : null;
3442
+ /**
3443
+ * Splits `rows` into runs of consecutive rows with the same `groupBy` key
3444
+ * (C-103). The rows are not reordered: a key that comes back after another
3445
+ * starts a new run. `null` and `undefined` mean no group.
3446
+ */
3447
+ var groupRuns = (rows, groupBy) => {
3448
+ const runs = [];
3449
+ const groupOf = new Int32Array(rows.length);
3450
+ const headersThrough = new Int32Array(rows.length);
3451
+ const seen = /* @__PURE__ */ new Map();
3452
+ let current = null;
3453
+ for (let p = 0; p < rows.length; p++) {
3454
+ const { row, index } = rows[p];
3455
+ const key = groupBy(row, index);
3456
+ if (key === null || key === void 0 || Number.isNaN(key)) {
3457
+ current = null;
3458
+ groupOf[p] = -1;
3459
+ } else if (current && current.key === key) {
3460
+ current.count++;
3461
+ groupOf[p] = runs.length - 1;
3462
+ } else {
3463
+ const nth = seen.get(key) ?? 0;
3464
+ seen.set(key, nth + 1);
3465
+ current = {
3466
+ key,
3467
+ count: 1,
3468
+ row,
3469
+ index,
3470
+ start: p,
3471
+ id: `${typeof key}:${String(key)}#${nth}`
3472
+ };
3473
+ runs.push(current);
3474
+ groupOf[p] = runs.length - 1;
3475
+ }
3476
+ headersThrough[p] = runs.length;
3477
+ }
3478
+ return {
3479
+ runs,
3480
+ groupOf,
3481
+ headersThrough
3482
+ };
3483
+ };
3484
+ //#endregion
3485
+ //#region src/virtual/compute-window.ts
3486
+ /**
3487
+ * Fills `offsets` from `heights`, starting at position `from` (the offsets
3488
+ * before it are kept): `offsets[i + 1] = offsets[i] + heights[i]`.
3489
+ */
3490
+ var fillOffsets = (heights, offsets, from = 0) => {
3491
+ for (let i = from; i < heights.length; i++) offsets[i + 1] = offsets[i] + heights[i];
3492
+ };
3493
+ /**
3494
+ * The item that holds the point `y`: the last position whose top is at most
3495
+ * `y`, clamped to the items (0 for a point above them, the last item for a
3496
+ * point below them). `-1` when there is no item.
3497
+ */
3498
+ var indexAt = (offsets, y) => {
3499
+ let low = 0;
3500
+ let high = offsets.length - 2;
3501
+ if (high < 0) return -1;
3502
+ while (low < high) {
3503
+ const mid = low + high + 1 >> 1;
3504
+ if (offsets[mid] <= y) low = mid;
3505
+ else high = mid - 1;
3506
+ }
3507
+ return low;
3508
+ };
3509
+ /** The items to draw: the ones in view and `overscan` more on each side. */
3510
+ var computeWindow = ({ offsets, scrollTop, viewportHeight, overscan }) => {
3511
+ const count = offsets.length - 1;
3512
+ if (count <= 0) return {
3513
+ start: 0,
3514
+ end: 0
3515
+ };
3516
+ const first = indexAt(offsets, scrollTop);
3517
+ const bottom = scrollTop + Math.max(0, viewportHeight);
3518
+ let last = indexAt(offsets, bottom);
3519
+ if (last > first && offsets[last] >= bottom) last -= 1;
3520
+ return {
3521
+ start: Math.max(0, first - overscan),
3522
+ end: Math.min(count, last + 1 + overscan)
3523
+ };
3524
+ };
3525
+ /**
3526
+ * The body between the pinned rows: an upper spacer, the drawn items and a
3527
+ * lower spacer. A `kept` item outside the range (it holds the focus, C-86)
3528
+ * is drawn on its own, with a spacer of its own between it and the range.
3529
+ * Spacers of height 0 are left out. `slot` names a spacer's place, so a
3530
+ * spacer keeps its identity while its height changes.
3531
+ */
3532
+ var segmentsOf = (offsets, range, kept) => {
3533
+ const count = offsets.length - 1;
3534
+ const total = count > 0 ? offsets[count] : 0;
3535
+ const out = [];
3536
+ const spacer = (height, slot) => {
3537
+ if (height > 0) out.push({
3538
+ spacer: height,
3539
+ slot
3540
+ });
3541
+ };
3542
+ const run = (from, to) => {
3543
+ if (to > from) out.push({
3544
+ from,
3545
+ to
3546
+ });
3547
+ };
3548
+ const { start, end } = range;
3549
+ if (kept !== null && kept >= 0 && kept < start) {
3550
+ spacer(offsets[kept], 0);
3551
+ run(kept, kept + 1);
3552
+ spacer(offsets[start] - offsets[kept + 1], 1);
3553
+ run(start, end);
3554
+ spacer(total - offsets[end], 2);
3555
+ } else if (kept !== null && kept >= end && kept < count) {
3556
+ spacer(offsets[start], 0);
3557
+ run(start, end);
3558
+ spacer(offsets[kept] - offsets[end], 1);
3559
+ run(kept, kept + 1);
3560
+ spacer(total - offsets[kept + 1], 2);
3561
+ } else {
3562
+ spacer(offsets[start], 0);
3563
+ run(start, end);
3564
+ spacer(total - offsets[end], 2);
3565
+ }
3566
+ return out;
3567
+ };
3568
+ //#endregion
3569
+ //#region src/virtual/use-row-window.ts
3570
+ var isDevelopment = () => {
3571
+ try {
3572
+ return process.env.NODE_ENV !== "production";
3573
+ } catch {
3574
+ return true;
3575
+ }
3576
+ };
3577
+ /** One identity per spacer place: above, between, below (`segmentsOf`). */
3578
+ var spacerKeys = [
3579
+ Symbol("above"),
3580
+ Symbol("between"),
3581
+ Symbol("below")
3582
+ ];
3583
+ /**
3584
+ * The virtual body (C-83 to C-87): which rows are drawn, the spacers that
3585
+ * stand for the others, the measured heights, the focused row kept drawn,
3586
+ * printing and `scrollToIndex`. Without `virtual` it draws `bodyRows` as
3587
+ * they are and touches no DOM.
3588
+ */
3589
+ var useRowWindow = (o) => {
3590
+ const settings = computed((previous) => {
3591
+ const value = o.virtual();
3592
+ const next = value === true ? {} : value || null;
3593
+ return previous && next && previous.overscan === next.overscan && previous.rowHeight === next.rowHeight && previous.estimateRowHeight === next.estimateRowHeight && previous.groupRowHeight === next.groupRowHeight && previous.scrollElement === next.scrollElement && previous.keepAnchor === next.keepAnchor ? previous : next;
3594
+ });
3595
+ const enabled = () => settings.value !== null;
3596
+ const overscan = () => Math.max(0, settings.value?.overscan ?? 10);
3597
+ const fixed = () => settings.value?.rowHeight;
3598
+ /** Pinned rows sit at both ends of `bodyRows`; the window is the middle. */
3599
+ const parts = computed(() => {
3600
+ const all = o.bodyRows();
3601
+ let top = 0;
3602
+ while (top < all.length && all[top].pinned === "top") top++;
3603
+ let bottom = all.length;
3604
+ while (bottom > top && all[bottom - 1].pinned === "bottom") bottom--;
3605
+ return {
3606
+ all,
3607
+ top,
3608
+ center: top === 0 && bottom === all.length ? all : all.slice(top, bottom)
3609
+ };
3610
+ });
3611
+ const center = () => parts.value.center;
3612
+ /** The groups of the center rows (C-103), or `null` without `groupBy`. */
3613
+ const groups = computed(() => {
3614
+ const groupBy = o.groupBy?.();
3615
+ return groupBy ? groupRuns(center(), groupBy) : null;
3616
+ });
3617
+ /** The center position starts a group: its group row is drawn above it. */
3618
+ const startsGroup = (position) => {
3619
+ const g = groups.value;
3620
+ if (!g) return false;
3621
+ const at = g.groupOf[position];
3622
+ return at >= 0 && g.runs[at].start === position;
3623
+ };
3624
+ let groupKeys = /* @__PURE__ */ new Map();
3625
+ watch(groups, (g) => {
3626
+ if (!g) {
3627
+ groupKeys = /* @__PURE__ */ new Map();
3628
+ return;
3629
+ }
3630
+ const kept = /* @__PURE__ */ new Map();
3631
+ for (const run of g.runs) {
3632
+ const known = groupKeys.get(run.id);
3633
+ if (known) kept.set(run.id, known);
3634
+ }
3635
+ groupKeys = kept;
3636
+ });
3637
+ const groupKey = (id) => {
3638
+ let key = groupKeys.get(id);
3639
+ if (!key) {
3640
+ key = Symbol(id);
3641
+ groupKeys.set(id, key);
3642
+ }
3643
+ return key;
3644
+ };
3645
+ const groupRowOf = (run, aria) => ({
3646
+ group: run,
3647
+ key: groupKey(run.id),
3648
+ aria
3649
+ });
3650
+ /** Position of a row index among center rows (ascending), or -1. */
3651
+ const positionIn = (rows, index) => {
3652
+ if (rows[index]?.index === index) return index;
3653
+ let low = 0;
3654
+ let high = rows.length - 1;
3655
+ while (low <= high) {
3656
+ const mid = low + high >> 1;
3657
+ const at = rows[mid].index;
3658
+ if (at === index) return mid;
3659
+ if (at < index) low = mid + 1;
3660
+ else high = mid - 1;
3661
+ }
3662
+ return -1;
3663
+ };
3664
+ const positionOf = (index) => positionIn(center(), index);
3665
+ let heights = /* @__PURE__ */ new Float64Array(0);
3666
+ /** Item heights without the group row above an item (C-104). */
3667
+ let base = /* @__PURE__ */ new Float64Array(0);
3668
+ let measured = /* @__PURE__ */ new Uint8Array(0);
3669
+ /** The measured height of a group row, `0` until one is measured. */
3670
+ let groupMeasured = 0;
3671
+ let offsets = /* @__PURE__ */ new Float64Array(1);
3672
+ let byKey = /* @__PURE__ */ new Map();
3673
+ /** The first measured height, the estimate when none is given. */
3674
+ let firstMeasured = 0;
3675
+ /** Bumped whenever `offsets` change, so the spacers are drawn again. */
3676
+ const version = shallowRef(0);
3677
+ const estimate = () => fixed() ?? settings.value?.estimateRowHeight ?? (firstMeasured || 32);
3678
+ /** Height counted for a group row (C-104). */
3679
+ const groupHeight = () => {
3680
+ const height = fixed();
3681
+ if (height !== void 0) return settings.value?.groupRowHeight ?? height;
3682
+ return groupMeasured || estimate();
3683
+ };
3684
+ /** An item's height: its row and, above it, its group row. */
3685
+ const withGroup = (position) => base[position] + (startsGroup(position) ? groupHeight() : 0);
3686
+ const rebuild = () => {
3687
+ const rows = enabled() ? center() : [];
3688
+ const height = fixed();
3689
+ heights = new Float64Array(rows.length);
3690
+ base = groups.value ? new Float64Array(rows.length) : heights;
3691
+ measured = new Uint8Array(rows.length);
3692
+ const kept = /* @__PURE__ */ new Map();
3693
+ for (let i = 0; i < rows.length; i++) {
3694
+ if (height !== void 0) base[i] = height;
3695
+ else {
3696
+ const key = o.keyOf(rows[i].row, rows[i].index);
3697
+ const known = byKey.get(key);
3698
+ if (known === void 0) base[i] = estimate();
3699
+ else {
3700
+ kept.set(key, known);
3701
+ base[i] = known;
3702
+ measured[i] = 1;
3703
+ }
3704
+ }
3705
+ heights[i] = withGroup(i);
3706
+ }
3707
+ byKey = kept;
3708
+ pending = null;
3709
+ offsets = new Float64Array(rows.length + 1);
3710
+ fillOffsets(heights, offsets);
3711
+ version.value++;
3712
+ };
3713
+ const body = () => o.table.value?.tBodies[0] ?? null;
3714
+ /** The drawn data row at a center position. */
3715
+ const rowElement = (tbody, position) => {
3716
+ const row = center()[position];
3717
+ return row ? tbody.querySelector(`:scope > tr[data-row-index="${row.index}"]:not([data-pinned-row])`) : null;
3718
+ };
3719
+ /** Height of a drawn item: its row and its subtable row. */
3720
+ const itemHeight = (tr) => {
3721
+ const next = tr.nextElementSibling;
3722
+ return tr.getBoundingClientRect().height + (next?.classList.contains("qt-subtable-row") ? next.getBoundingClientRect().height : 0);
3723
+ };
3724
+ /** Reads the drawn items; `true` when a height changed. */
3725
+ const measure = (tbody) => {
3726
+ if (fixed() !== void 0) return false;
3727
+ const rows = center();
3728
+ let from = -1;
3729
+ for (const tr of tbody.children) {
3730
+ if (groups.value && tr.classList.contains("qt-group-row")) {
3731
+ const height = tr.getBoundingClientRect().height;
3732
+ if (height > 0 && Math.abs(height - groupMeasured) > .5) {
3733
+ groupMeasured = height;
3734
+ from = 0;
3735
+ }
3736
+ continue;
3737
+ }
3738
+ const at = tr.getAttribute("data-row-index");
3739
+ if (at === null || tr.hasAttribute("data-pinned-row")) continue;
3740
+ const position = positionOf(Number(at));
3741
+ if (position < 0) continue;
3742
+ const height = itemHeight(tr);
3743
+ if (!firstMeasured && height > 0 && settings.value?.estimateRowHeight === void 0) {
3744
+ firstMeasured = height;
3745
+ for (let i = 0; i < base.length; i++) if (!measured[i]) base[i] = height;
3746
+ from = 0;
3747
+ }
3748
+ if (!measured[position] || Math.abs(base[position] - height) > .5) {
3749
+ base[position] = height;
3750
+ measured[position] = 1;
3751
+ byKey.set(o.keyOf(rows[position].row, rows[position].index), height);
3752
+ from = from < 0 ? position : Math.min(from, position);
3753
+ }
3754
+ }
3755
+ if (from >= 0) {
3756
+ for (let i = from; i < heights.length; i++) heights[i] = withGroup(i);
3757
+ fillOffsets(heights, offsets, from);
3758
+ version.value++;
3759
+ return true;
3760
+ }
3761
+ return false;
3762
+ };
3763
+ const range = shallowRef({
3764
+ start: 0,
3765
+ end: Math.ceil((globalThis.innerHeight || 800) / 32) + 10
3766
+ });
3767
+ /** The window was computed from the layout at least once. */
3768
+ const ready = shallowRef(false);
3769
+ let container = null;
3770
+ let frame = 0;
3771
+ /** The first visible item and its top before the window moved (C-84). */
3772
+ let anchor = null;
3773
+ /**
3774
+ * The container's scroll position the window was computed for. The
3775
+ * browser's own scroll anchoring may move it when the drawn rows change
3776
+ * (it anchors to a spacer when no row is in view); it is put back.
3777
+ */
3778
+ let expected = null;
3779
+ /**
3780
+ * A row to correct once it is drawn: a `scrollToIndex` (C-87), or an
3781
+ * anchor kept across a change of `rows`, back at its client `top` (C-119).
3782
+ */
3783
+ let pending = null;
3784
+ /** Frames a `scrollToIndex` waits for its row before it is given up. */
3785
+ const pendingFrames = 6;
3786
+ const viewport = (target = container) => {
3787
+ if (target === null || target === window) return {
3788
+ top: 0,
3789
+ height: globalThis.innerHeight
3790
+ };
3791
+ const element = target;
3792
+ return {
3793
+ top: element.getBoundingClientRect().top + element.clientTop,
3794
+ height: element.clientHeight
3795
+ };
3796
+ };
3797
+ /** Client top of the first center item: below the top-pinned rows. */
3798
+ const itemsTop = (tbody) => {
3799
+ for (const tr of tbody.children) if (tr.getAttribute("data-pinned-row") !== "top") return tr.getBoundingClientRect().top;
3800
+ return tbody.getBoundingClientRect().bottom;
3801
+ };
3802
+ const scrollTopOf = (target) => target === window ? window.scrollY : target.scrollTop;
3803
+ const scrollBy = (delta, target = container) => {
3804
+ if (Math.abs(delta) < 1 || !target) return;
3805
+ target.scrollTo({
3806
+ top: scrollTopOf(target) + delta,
3807
+ behavior: "instant"
3808
+ });
3809
+ };
3810
+ /** Height of a sticky header over the top (client `viewTop`) of the view. */
3811
+ const headCover = (viewTop) => {
3812
+ const head = o.table.value?.tHead?.getBoundingClientRect();
3813
+ return head && head.top <= viewTop + 1 && head.bottom > viewTop ? head.bottom - viewTop : 0;
3814
+ };
3815
+ /** How far to scroll to show an item at `top` (client) with `height`. */
3816
+ const alignDelta = (top, height, align, groupCover = 0, target = container) => {
3817
+ const view = viewport(target);
3818
+ const viewTop = view.top + headCover(view.top) + groupCover;
3819
+ const viewBottom = view.top + view.height;
3820
+ const bottom = top + height;
3821
+ switch (align) {
3822
+ case "start": return top - viewTop;
3823
+ case "end": return bottom - viewBottom;
3824
+ case "center": return (top + bottom - viewTop - viewBottom) / 2;
3825
+ default: return top < viewTop ? top - viewTop : bottom > viewBottom ? bottom - viewBottom : 0;
3826
+ }
3827
+ };
3828
+ /**
3829
+ * Height of a group row the consumer's CSS made sticky, which covers a
3830
+ * row aligned to the top of its group (C-104); `0` without one.
3831
+ */
3832
+ const stickyGroupCover = (tbody) => {
3833
+ if (!groups.value) return 0;
3834
+ const cell = tbody.querySelector(":scope > tr.qt-group-row > th");
3835
+ return cell && getComputedStyle(cell).position === "sticky" ? cell.getBoundingClientRect().height : 0;
3836
+ };
3837
+ /** The sticky cover over a row: only a grouped row that does not start its group. */
3838
+ const coverOf = (position, tbody) => {
3839
+ const g = groups.value;
3840
+ return g && g.groupOf[position] >= 0 && !startsGroup(position) ? stickyGroupCover(tbody) : 0;
3841
+ };
3842
+ /**
3843
+ * Scrolls `target` so the drawn row `tr` (at a center position, or `-1`
3844
+ * for a pinned row) is shown as `align` asks, below a sticky header and a
3845
+ * sticky group row (C-87, C-104).
3846
+ */
3847
+ const alignRow = (tbody, tr, position, align, target, whole = true) => {
3848
+ const above = startsGroup(position) ? tr.previousElementSibling : null;
3849
+ const head = above?.classList.contains("qt-group-row") ? above : null;
3850
+ scrollBy(alignDelta((head ?? tr).getBoundingClientRect().top, (whole ? itemHeight(tr) : tr.getBoundingClientRect().height) + (head ? head.getBoundingClientRect().height : 0), align, head ? 0 : coverOf(position, tbody), target), target);
3851
+ };
3852
+ /**
3853
+ * The anchor of `keepAnchor` in the drawn body, read before it is drawn
3854
+ * again (C-119): the key and client top of the first data row whose top is
3855
+ * in the view, below a sticky header. `null` when nothing is to be kept,
3856
+ * the first center row being that row included.
3857
+ */
3858
+ const anchorOf = (before) => {
3859
+ const tbody = body();
3860
+ if (!settings.value?.keepAnchor || !o.hasRowKey?.() || !tbody || !container || printing.value) return null;
3861
+ const view = viewport();
3862
+ const viewTop = view.top + headCover(view.top);
3863
+ for (const tr of tbody.children) {
3864
+ const at = tr.getAttribute("data-row-index");
3865
+ if (at === null || tr.hasAttribute("data-pinned-row")) continue;
3866
+ const top = tr.getBoundingClientRect().top;
3867
+ if (top < viewTop - .5) continue;
3868
+ if (top >= view.top + view.height) return null;
3869
+ const position = positionIn(before, Number(at));
3870
+ if (position <= 0) return null;
3871
+ const { row, index } = before[position];
3872
+ return {
3873
+ key: o.keyOf(row, index),
3874
+ top
3875
+ };
3876
+ }
3877
+ return null;
3878
+ };
3879
+ /** After a render: correct the drift (C-84) or a `scrollToIndex` (C-87). */
3880
+ const settle = () => {
3881
+ const tbody = body();
3882
+ if (!tbody) return;
3883
+ if (expected !== null && container) {
3884
+ scrollBy(expected - scrollTopOf(container));
3885
+ expected = null;
3886
+ }
3887
+ if (pending) {
3888
+ const tr = rowElement(tbody, pending.position);
3889
+ if (tr) {
3890
+ const done = pending;
3891
+ pending = null;
3892
+ if ("top" in done) scrollBy(tr.getBoundingClientRect().top - done.top);
3893
+ else alignRow(tbody, tr, done.position, done.align, container);
3894
+ return;
3895
+ }
3896
+ if ("top" in pending && pending.tries === 0) scrollBy(itemsTop(tbody) + offsets[pending.position] - pending.top);
3897
+ if (++pending.tries <= pendingFrames) {
3898
+ schedule();
3899
+ return;
3900
+ }
3901
+ pending = null;
3902
+ }
3903
+ if (anchor) {
3904
+ const tr = rowElement(tbody, anchor.position);
3905
+ if (tr) scrollBy(tr.getBoundingClientRect().top - anchor.top);
3906
+ anchor = null;
3907
+ }
3908
+ };
3909
+ const update = () => {
3910
+ frame = 0;
3911
+ const tbody = body();
3912
+ if (!tbody || !container || printing.value) return;
3913
+ measure(tbody);
3914
+ const view = viewport();
3915
+ const scrollTop = view.top - itemsTop(tbody);
3916
+ const next = computeWindow({
3917
+ offsets,
3918
+ scrollTop,
3919
+ viewportHeight: view.height,
3920
+ overscan: overscan()
3921
+ });
3922
+ ready.value = true;
3923
+ const current = range.value;
3924
+ if (next.start === current.start && next.end === current.end) {
3925
+ settle();
3926
+ return;
3927
+ }
3928
+ if (!pending && fixed() === void 0) {
3929
+ const position = Math.min(Math.max(indexAt(offsets, scrollTop), current.start), current.end - 1);
3930
+ const tr = position < 0 ? null : rowElement(tbody, position);
3931
+ anchor = tr ? {
3932
+ position,
3933
+ top: tr.getBoundingClientRect().top
3934
+ } : null;
3935
+ }
3936
+ expected = scrollTopOf(container);
3937
+ range.value = next;
3938
+ };
3939
+ const schedule = () => {
3940
+ if (!frame) frame = requestAnimationFrame(update);
3941
+ };
3942
+ const printing = shallowRef(false);
3943
+ const startPrint = () => {
3944
+ printing.value = true;
3945
+ };
3946
+ const endPrint = () => {
3947
+ printing.value = false;
3948
+ schedule();
3949
+ };
3950
+ const onPrintMedia = (event) => {
3951
+ if (event.matches) startPrint();
3952
+ else endPrint();
3953
+ };
3954
+ let printMedia = null;
3955
+ const kept = shallowRef(null);
3956
+ /** The row index of the item (data row or subtable row) holding `target`. */
3957
+ const itemOf = (target, tbody) => {
3958
+ let tr = target?.closest?.("tr") ?? null;
3959
+ while (tr && tr.parentElement !== tbody) tr = tr.parentElement?.closest("tr") ?? null;
3960
+ if (tr?.classList.contains("qt-subtable-row")) tr = tr.previousElementSibling;
3961
+ const at = tr?.getAttribute("data-row-index");
3962
+ return !tr || at === null || at === void 0 || tr.hasAttribute("data-pinned-row") ? -1 : positionOf(Number(at));
3963
+ };
3964
+ const onFocusIn = (event) => {
3965
+ if (!enabled()) return;
3966
+ const position = itemOf(event.target, event.currentTarget);
3967
+ if (position >= 0) kept.value = {
3968
+ row: center()[position].row,
3969
+ position
3970
+ };
3971
+ };
3972
+ const onFocusOut = (event) => {
3973
+ if (kept.value && itemOf(event.relatedTarget, event.currentTarget) !== kept.value.position) kept.value = null;
3974
+ };
3975
+ const keptPosition = () => {
3976
+ const focus = kept.value;
3977
+ if (!focus) return null;
3978
+ const rows = center();
3979
+ if (rows[focus.position]?.row === focus.row) return focus.position;
3980
+ const found = rows.findIndex((row) => row.row === focus.row);
3981
+ return found < 0 ? null : found;
3982
+ };
3983
+ /** Open subtable rows before each row of `bodyRows`, and in all (C-86). */
3984
+ const expandedBefore = computed(() => {
3985
+ const all = enabled() ? parts.value.all : [];
3986
+ const counts = new Int32Array(all.length + 1);
3987
+ for (let i = 0; i < all.length; i++) counts[i + 1] = counts[i] + (o.isExpanded(all[i].row, all[i].index) ? 1 : 0);
3988
+ return counts;
3989
+ });
3990
+ /** Group rows drawn up to and with the center position (C-104). */
3991
+ const groupsThrough = (position) => groups.value ? groups.value.headersThrough[position] : 0;
3992
+ const groupCount = () => groups.value?.runs.length ?? 0;
3993
+ const drawn = computed(() => {
3994
+ const { all, top } = parts.value;
3995
+ const g = groups.value;
3996
+ if (!enabled()) {
3997
+ if (!g) return all;
3998
+ const out = [];
3999
+ for (let q = 0; q < all.length; q++) {
4000
+ const p = q - top;
4001
+ if (p >= 0 && p < g.groupOf.length && startsGroup(p)) out.push(groupRowOf(g.runs[g.groupOf[p]]));
4002
+ out.push(all[q]);
4003
+ }
4004
+ return out;
4005
+ }
4006
+ version.value;
4007
+ const rows = center();
4008
+ const before = expandedBefore.value;
4009
+ const first = 1 + (o.headerRows?.() ?? 1);
4010
+ const headersBefore = (q) => q < top ? 0 : q < top + rows.length ? groupsThrough(q - top) : groupCount();
4011
+ const ariaOf = (q) => q + before[q] + headersBefore(q) + first;
4012
+ const at = (q) => ({
4013
+ ...all[q],
4014
+ aria: ariaOf(q)
4015
+ });
4016
+ const out = [];
4017
+ /** The group whose row was drawn last, or -1. */
4018
+ let drawnGroup = -1;
4019
+ /** The center row at `p`, after its group row when it needs one. */
4020
+ const push = (p, carry) => {
4021
+ const group = g ? g.groupOf[p] : -1;
4022
+ if (g && group >= 0 && group !== drawnGroup) {
4023
+ const run = g.runs[group];
4024
+ if (run.start === p) out.push(groupRowOf(run, ariaOf(top + p) - 1));
4025
+ else if (carry) {
4026
+ const last = out[out.length - 1];
4027
+ if (last && "spacer" in last) {
4028
+ const height = Math.max(0, last.spacer - groupHeight());
4029
+ out[out.length - 1] = {
4030
+ spacer: height,
4031
+ key: last.key
4032
+ };
4033
+ }
4034
+ out.push(groupRowOf(run, ariaOf(top + run.start) - 1));
4035
+ }
4036
+ }
4037
+ drawnGroup = group;
4038
+ out.push(at(top + p));
4039
+ };
4040
+ for (let q = 0; q < top; q++) out.push(at(q));
4041
+ if (printing.value) for (let p = 0; p < rows.length; p++) push(p, false);
4042
+ else {
4043
+ const end = Math.min(range.value.end, rows.length);
4044
+ const win = {
4045
+ start: Math.min(range.value.start, end),
4046
+ end
4047
+ };
4048
+ for (const segment of segmentsOf(offsets, win, keptPosition())) if ("spacer" in segment) out.push({
4049
+ spacer: segment.spacer,
4050
+ key: spacerKeys[segment.slot]
4051
+ });
4052
+ else for (let p = segment.from; p < segment.to; p++) push(p, p === segment.from);
4053
+ }
4054
+ for (let q = top + rows.length; q < all.length; q++) out.push(at(q));
4055
+ return g ? out.filter((item) => !("spacer" in item) || item.spacer > 0) : out;
4056
+ });
4057
+ let box = null;
4058
+ let rowsObserver = null;
4059
+ /**
4060
+ * Watches the table for coming into the layout: a table mounted inside
4061
+ * `display: none` has no scrolling ancestor yet, so the container is
4062
+ * looked for again once it has a size.
4063
+ */
4064
+ let shown = null;
4065
+ let hadSize = false;
4066
+ let watchedTable = null;
4067
+ const watchShown = (table) => {
4068
+ if (table === watchedTable) return;
4069
+ shown?.disconnect();
4070
+ shown = null;
4071
+ watchedTable = table;
4072
+ if (!table || typeof ResizeObserver === "undefined") return;
4073
+ hadSize = table.getBoundingClientRect().height > 0;
4074
+ shown = new ResizeObserver(() => {
4075
+ const hasSize = table.getBoundingClientRect().height > 0;
4076
+ if (hasSize !== hadSize) {
4077
+ hadSize = hasSize;
4078
+ if (hasSize) attach();
4079
+ }
4080
+ });
4081
+ shown.observe(table);
4082
+ };
4083
+ const observed = /* @__PURE__ */ new Set();
4084
+ let warned = false;
4085
+ const findContainer = (table) => {
4086
+ const given = settings.value?.scrollElement?.();
4087
+ if (given) return given;
4088
+ for (let element = table.parentElement; element && element !== document.body && element !== document.documentElement; element = element.parentElement) {
4089
+ const overflow = getComputedStyle(element).overflowY;
4090
+ if ((overflow === "auto" || overflow === "scroll") && element.scrollHeight > element.clientHeight) return element;
4091
+ }
4092
+ return window;
4093
+ };
4094
+ const detach = () => {
4095
+ container?.removeEventListener("scroll", schedule);
4096
+ container = null;
4097
+ box?.disconnect();
4098
+ box = null;
4099
+ removeEventListener("resize", schedule);
4100
+ };
4101
+ const attach = () => {
4102
+ const table = o.table.value;
4103
+ if (!table || !enabled()) {
4104
+ watchShown(null);
4105
+ detach();
4106
+ return;
4107
+ }
4108
+ watchShown(table);
4109
+ const next = findContainer(table);
4110
+ if (next !== container) {
4111
+ detach();
4112
+ container = next;
4113
+ next.addEventListener("scroll", schedule, { passive: true });
4114
+ addEventListener("resize", schedule);
4115
+ if (next !== window && typeof ResizeObserver !== "undefined") {
4116
+ box = new ResizeObserver(schedule);
4117
+ box.observe(next);
4118
+ }
4119
+ }
4120
+ if (!warned && isDevelopment() && getComputedStyle(table).tableLayout !== "fixed") {
4121
+ warned = true;
4122
+ console.warn("[QueryTable] `virtual` with `table-layout: auto`: column widths follow the drawn rows. Set `table-layout: fixed` (C-85).");
4123
+ }
4124
+ schedule();
4125
+ };
4126
+ /** Watches the drawn rows for size changes; measured on the next frame. */
4127
+ const observeRows = () => {
4128
+ const tbody = body();
4129
+ if (!tbody || !enabled() || fixed() !== void 0 || typeof ResizeObserver === "undefined") {
4130
+ rowsObserver?.disconnect();
4131
+ observed.clear();
4132
+ return;
4133
+ }
4134
+ rowsObserver ??= new ResizeObserver(schedule);
4135
+ for (const element of observed) if (element.parentElement !== tbody) {
4136
+ rowsObserver.unobserve(element);
4137
+ observed.delete(element);
4138
+ }
4139
+ for (const tr of tbody.children) if (!observed.has(tr) && !tr.classList.contains("qt-virtual-spacer")) {
4140
+ rowsObserver.observe(tr);
4141
+ observed.add(tr);
4142
+ }
4143
+ };
4144
+ watch([
4145
+ () => parts.value.center,
4146
+ () => settings.value?.rowHeight,
4147
+ () => settings.value?.estimateRowHeight,
4148
+ () => settings.value?.groupRowHeight,
4149
+ () => groupShape(groups.value),
4150
+ enabled
4151
+ ], (now, before) => {
4152
+ const old = before?.[0];
4153
+ const keep = old && now[0] !== old && now[5] && before[5] ? anchorOf(old) : null;
4154
+ rebuild();
4155
+ if (keep) {
4156
+ const position = center().findIndex((item) => o.keyOf(item.row, item.index) === keep.key);
4157
+ if (position >= 0) {
4158
+ anchor = null;
4159
+ pending = {
4160
+ position,
4161
+ top: keep.top,
4162
+ tries: 0
4163
+ };
4164
+ }
4165
+ }
4166
+ }, { immediate: true });
4167
+ watch([
4168
+ () => o.table.value,
4169
+ enabled,
4170
+ () => settings.value?.scrollElement,
4171
+ () => parts.value.center
4172
+ ], attach, {
4173
+ flush: "post",
4174
+ immediate: true
4175
+ });
4176
+ watch(drawn, () => {
4177
+ observeRows();
4178
+ settle();
4179
+ }, { flush: "post" });
4180
+ watch(enabled, (on) => {
4181
+ printMedia?.removeEventListener("change", onPrintMedia);
4182
+ removeEventListener("beforeprint", startPrint);
4183
+ removeEventListener("afterprint", endPrint);
4184
+ printMedia = null;
4185
+ if (on && typeof window !== "undefined") {
4186
+ addEventListener("beforeprint", startPrint);
4187
+ addEventListener("afterprint", endPrint);
4188
+ printMedia = window.matchMedia?.("print") ?? null;
4189
+ printMedia?.addEventListener("change", onPrintMedia);
4190
+ }
4191
+ }, { immediate: true });
4192
+ onBeforeUnmount(() => {
4193
+ detach();
4194
+ watchShown(null);
4195
+ cancelAnimationFrame(frame);
4196
+ rowsObserver?.disconnect();
4197
+ printMedia?.removeEventListener("change", onPrintMedia);
4198
+ removeEventListener("beforeprint", startPrint);
4199
+ removeEventListener("afterprint", endPrint);
4200
+ });
4201
+ const scrollToIndex = (index, options = {}) => {
4202
+ const align = options.align ?? "auto";
4203
+ const tbody = body();
4204
+ if (!tbody || !Number.isInteger(index) || index < 0) return;
4205
+ const position = enabled() && container && !printing.value ? positionOf(index) : -1;
4206
+ if (position < 0) {
4207
+ tbody.querySelector(`:scope > tr[data-row-index="${index}"]`)?.scrollIntoView({
4208
+ block: align === "auto" ? "nearest" : align,
4209
+ behavior: "instant"
4210
+ });
4211
+ return;
4212
+ }
4213
+ anchor = null;
4214
+ pending = {
4215
+ position,
4216
+ align,
4217
+ tries: 0
4218
+ };
4219
+ scrollBy(alignDelta(itemsTop(tbody) + offsets[position], heights[position], align, coverOf(position, tbody)));
4220
+ schedule();
4221
+ };
4222
+ /**
4223
+ * Shows the drawn row with this index in `rows` whole, below a sticky
4224
+ * header and a sticky group row, in its scroll container (C-110); with
4225
+ * `virtual` that is the container of C-85, else the nearest scrolling
4226
+ * ancestor of the table or the window. Only the row: an open subtable row
4227
+ * taller than the view would push it out. A `scrollToIndex` still waiting
4228
+ * is dropped, so it cannot move the view away after. A row not drawn does
4229
+ * nothing.
4230
+ */
4231
+ const reveal = (index) => {
4232
+ const tbody = body();
4233
+ const table = o.table.value;
4234
+ const tr = tbody?.querySelector(`:scope > tr[data-row-index="${index}"]`);
4235
+ if (!tbody || !table || !tr) return;
4236
+ pending = null;
4237
+ const target = enabled() && container ? container : findContainer(table);
4238
+ alignRow(tbody, tr, tr.hasAttribute("data-pinned-row") ? -1 : positionOf(index), "auto", target, false);
4239
+ };
4240
+ return {
4241
+ enabled,
4242
+ drawn,
4243
+ range,
4244
+ ready,
4245
+ centerCount: () => center().length,
4246
+ expandedCount: () => expandedBefore.value[expandedBefore.value.length - 1],
4247
+ /** Group rows of the body, drawn or not (C-104). */
4248
+ groupCount,
4249
+ scrollToIndex,
4250
+ reveal,
4251
+ /** A `scrollToIndex` or a window update is still to come (C-110). */
4252
+ busy: () => pending !== null || frame !== 0,
4253
+ onFocusIn,
4254
+ onFocusOut
4255
+ };
4256
+ };
4257
+ //#endregion
4258
+ //#region src/query-table.vue?vue&type=script&setup=true&lang.ts
4259
+ var _hoisted_1 = [
4260
+ "data-empty",
4261
+ "data-loading",
4262
+ "aria-busy"
4263
+ ];
4264
+ var _hoisted_2 = ["role", "aria-rowcount"];
4265
+ var _hoisted_3 = {
4266
+ class: "qt-table",
4267
+ role: "presentation"
4268
+ };
4269
+ var _hoisted_4 = ["aria-rowcount"];
4270
+ var _hoisted_5 = { key: 0 };
4271
+ //#endregion
4272
+ //#region src/query-table.vue
4273
+ var query_table_default = /* @__PURE__ */ defineComponent({
4274
+ name: "QueryTable",
4275
+ __name: "query-table",
4276
+ props: {
4277
+ query: {},
4278
+ cursors: { default: null },
4279
+ selection: { default: void 0 },
4280
+ rowPinning: { default: void 0 },
4281
+ searchDebounce: { default: 300 },
4282
+ columns: {},
4283
+ rows: { default: () => [] },
4284
+ totalRows: { default: null },
4285
+ footerRows: { default: () => [] },
4286
+ loading: {
4287
+ type: Boolean,
4288
+ default: false
4289
+ },
4290
+ sortable: {
4291
+ type: Boolean,
4292
+ default: false
4293
+ },
4294
+ filterable: {
4295
+ type: Boolean,
4296
+ default: false
4297
+ },
4298
+ resizable: {
4299
+ type: Boolean,
4300
+ default: false
4301
+ },
4302
+ autoWidth: {
4303
+ type: Boolean,
4304
+ default: false
4305
+ },
4306
+ autoWidthMax: { default: void 0 },
4307
+ reorderable: {
4308
+ type: Boolean,
4309
+ default: false
4310
+ },
4311
+ filterDebounce: { default: 100 },
4312
+ pagination: {},
4313
+ hasSubtable: {
4314
+ type: Boolean,
4315
+ default: false
4316
+ },
4317
+ rowExpandable: {
4318
+ type: Function,
4319
+ default: void 0
4320
+ },
4321
+ expandMode: { default: "multiple" },
4322
+ rowKind: {
4323
+ type: Function,
4324
+ default: void 0
4325
+ },
4326
+ groupBy: {
4327
+ type: Function,
4328
+ default: void 0
4329
+ },
4330
+ hasRightPanel: {
4331
+ type: Boolean,
4332
+ default: false
4333
+ },
4334
+ rowKey: {
4335
+ type: [String, Function],
4336
+ default: void 0
4337
+ },
4338
+ labels: { default: void 0 },
4339
+ virtual: {
4340
+ type: [Boolean, Object],
4341
+ default: false
4342
+ },
4343
+ rowNavigation: {
4344
+ type: [Boolean, Object],
4345
+ default: false
4346
+ },
4347
+ scrollBody: {
4348
+ type: Boolean,
4349
+ default: false
4350
+ },
4351
+ header: {
4352
+ type: Boolean,
4353
+ default: true
4354
+ },
4355
+ infinite: {
4356
+ type: [Boolean, Object],
4357
+ default: false
4358
+ },
4359
+ flash: {
4360
+ type: [Boolean, Object],
4361
+ default: false
4362
+ },
4363
+ rowsUpdate: { default: void 0 }
4364
+ },
4365
+ emits: [
4366
+ "update:query",
4367
+ "update:selection",
4368
+ "rowRightPanelClick",
4369
+ "cellContextMenu",
4370
+ "headerContextMenu",
4371
+ "columnResize",
4372
+ "update:columns",
4373
+ "update:rowPinning",
4374
+ "rowFocus",
4375
+ "rowExpansionChange"
4376
+ ],
4377
+ setup(__props, { expose: __expose, emit: __emit }) {
4378
+ const props = __props;
4379
+ const emit = __emit;
4380
+ const slots = useSlots();
4381
+ const rawSlots = useSlots();
4382
+ const split = () => props.header && props.scrollBody;
4383
+ /** Rows of the header in the row count (C-86): none without it. */
4384
+ const headerRows = () => props.header ? 1 : 0;
4385
+ const unpinned = computed(() => props.columns.map((column) => {
4386
+ if (!column.pinned) return column;
4387
+ const copy = { ...column };
4388
+ delete copy.pinned;
4389
+ return copy;
4390
+ }));
4391
+ const state = useQueryTable({
4392
+ query: () => props.query,
4393
+ columns: () => props.header ? props.columns : unpinned.value,
4394
+ rows: () => props.rows,
4395
+ totalRows: () => props.totalRows,
4396
+ cursors: () => props.cursors,
4397
+ sortable: () => props.sortable,
4398
+ filterDebounce: () => props.filterDebounce,
4399
+ searchDebounce: () => props.searchDebounce,
4400
+ selection: () => props.selection,
4401
+ rowPinning: () => props.rowPinning,
4402
+ rowKey: () => props.rowKey,
4403
+ hasSubtable: () => props.hasSubtable,
4404
+ rowExpandable: () => props.rowExpandable,
4405
+ expandMode: () => props.expandMode,
4406
+ pageSizeOptions: () => props.pagination?.pageSizeOptions,
4407
+ onQueryChange: (query, reason) => emit("update:query", query, reason),
4408
+ onSelectionChange: (selection) => emit("update:selection", selection),
4409
+ onColumnsChange: (columns, reason) => emit("update:columns", columns, reason),
4410
+ onRowPinningChange: (rowPinning) => emit("update:rowPinning", rowPinning),
4411
+ onRowExpansionChange: (payload) => emit("rowExpansionChange", payload)
4412
+ });
4413
+ const { filters, sort, search, expansion } = state;
4414
+ const rowSelection = state.selection;
4415
+ const paginationProps = state.pagination;
4416
+ const labels = computed(() => resolveLabels(props.labels));
4417
+ const instance = getCurrentInstance();
4418
+ const hasContextMenuListener = () => {
4419
+ const vnodeProps = instance?.vnode.props;
4420
+ return !!(vnodeProps?.onCellContextMenu || vnodeProps?.onCellContextMenuOnce);
4421
+ };
4422
+ const hasHeaderContextMenuListener = () => {
4423
+ const vnodeProps = instance?.vnode.props;
4424
+ return !!(vnodeProps?.onHeaderContextMenu || vnodeProps?.onHeaderContextMenuOnce);
4425
+ };
4426
+ const entries = state.columns;
4427
+ const visibleColumns = computed(() => entries.value.map((e) => e.column));
4428
+ const { onContextMenu: onHeaderContextMenu } = useHeaderContextMenu({
4429
+ columns: () => visibleColumns.value,
4430
+ indexOf: (field) => entries.value.find((e) => e.column.field === field)?.index,
4431
+ listening: () => hasHeaderContextMenuListener(),
4432
+ onContextMenu: (payload) => emit("headerContextMenu", payload)
4433
+ });
4434
+ const hasPinned = state.hasPinned;
4435
+ /** Right panel first, then subtable, then selection (C-22: the first hosts clear-all). */
4436
+ const utilities = computed(() => [
4437
+ props.hasRightPanel ? "right-panel" : null,
4438
+ props.hasSubtable ? "subtable" : null,
4439
+ rowSelection.enabled.value ? "select" : null
4440
+ ].filter((name) => name !== null));
4441
+ const utilityCount = computed(() => utilities.value.length);
4442
+ const columnCount = computed(() => entries.value.length + utilityCount.value);
4443
+ /** Utilities are pinned only with a left-pinned column (C-46, C-71). */
4444
+ const utilitySide = () => hasPinned.value ? "left" : false;
4445
+ /** The table of the header: with `scrollBody` the first of three (C-101). */
4446
+ const tableEl = shallowRef(null);
4447
+ const bodyTableEl = shallowRef(null);
4448
+ const headWrap = shallowRef(null);
4449
+ const bodyWrap = shallowRef(null);
4450
+ const footWrap = shallowRef(null);
4451
+ /** The table of the body rows. */
4452
+ const bodyTable = computed(() => bodyTableEl.value ?? tableEl.value);
4453
+ /** With `scrollBody`, the body table to measure apart from the header. */
4454
+ const splitBody = () => split() ? bodyTableEl.value : null;
4455
+ const { widths, tableWidth, offsets, columns: cellWidths } = useHeaderGeometry({
4456
+ table: tableEl,
4457
+ cells: () => [...utilities.value.map((utility) => ({
4458
+ key: utilityKey(utility),
4459
+ side: utilitySide()
4460
+ })), ...entries.value.map(({ column }) => ({
4461
+ key: column.field,
4462
+ side: sideOf(column)
4463
+ }))],
4464
+ active: () => split() || entries.value.some((entry) => sideOf(entry.column) !== false) || props.header && props.resizable && entries.value.some((entry) => entry.column.resizable !== false)
4465
+ });
4466
+ /** The `col` widths of the body and footer tables (C-101), in pixels. */
4467
+ const colWidths = computed(() => Array.from({ length: columnCount.value }, (_, i) => cellWidths.value[i]));
4468
+ useScrollBody({
4469
+ enabled: split,
4470
+ wrappers: () => ({
4471
+ head: headWrap.value,
4472
+ body: bodyWrap.value,
4473
+ foot: footWrap.value
4474
+ }),
4475
+ headTable: () => tableEl.value,
4476
+ bodyTable: () => bodyTableEl.value,
4477
+ colWidths: () => colWidths.value,
4478
+ rows: () => props.rows
4479
+ });
4480
+ const resize = useColumnResize({
4481
+ resizable: () => props.resizable,
4482
+ measuredWidth: (field) => widths.value[field],
4483
+ tableWidth: () => tableWidth.value,
4484
+ body: splitBody,
4485
+ emit: (payload) => {
4486
+ emit("columnResize", payload);
4487
+ const next = applyWidth(props.columns, payload.field, `${payload.width}px`);
4488
+ if (next) emit("update:columns", next, "resize");
4489
+ }
4490
+ });
4491
+ const autoWidth = useAutoWidth({
4492
+ enabled: () => props.header && props.autoWidth,
4493
+ max: () => props.autoWidthMax,
4494
+ table: tableEl,
4495
+ body: splitBody,
4496
+ columns: () => visibleColumns.value,
4497
+ rows: () => props.rows,
4498
+ query: () => props.query,
4499
+ rowsUpdate: () => props.rowsUpdate
4500
+ });
4501
+ const rowWindow = useRowWindow({
4502
+ virtual: () => props.virtual,
4503
+ table: bodyTable,
4504
+ bodyRows: () => state.rowPinning.rows.value,
4505
+ keyOf: expansion.keyOf,
4506
+ hasRowKey: () => props.rowKey !== void 0,
4507
+ isExpanded: expansion.isExpanded,
4508
+ groupBy: () => props.groupBy,
4509
+ headerRows: () => headerRows()
4510
+ });
4511
+ const navigation = useRowNavigation({
4512
+ rowNavigation: () => props.rowNavigation,
4513
+ table: bodyTable,
4514
+ bodyRows: () => state.rowPinning.rows.value,
4515
+ keyOf: expansion.keyOf,
4516
+ hasRowKey: () => props.rowKey !== void 0,
4517
+ virtual: rowWindow.enabled,
4518
+ scrollToIndex: rowWindow.scrollToIndex,
4519
+ reveal: rowWindow.reveal,
4520
+ busy: rowWindow.busy,
4521
+ onFocus: (payload) => emit("rowFocus", payload)
4522
+ });
4523
+ /** The `tbody` listener of the navigation: none while it is off (C-111). */
4524
+ const navigationListeners = () => navigation.enabled() ? { keydown: navigation.onKeyDown } : {};
4525
+ const infinite = useLoadMore({
4526
+ infinite: () => props.infinite,
4527
+ rowKey: () => props.rowKey,
4528
+ rows: () => props.rows,
4529
+ query: () => props.query,
4530
+ totalRows: () => props.totalRows,
4531
+ cursors: () => props.cursors,
4532
+ loading: () => props.loading,
4533
+ nextPage: () => paginationProps.value.nextPage(),
4534
+ table: bodyTable,
4535
+ virtual: rowWindow.enabled,
4536
+ window: () => rowWindow.ready.value ? {
4537
+ end: rowWindow.range.value.end,
4538
+ count: rowWindow.centerCount()
4539
+ } : null
4540
+ });
4541
+ const loadMoreProps = computed(() => infinite.enabled.value ? {
4542
+ loadMore: infinite.loadMore,
4543
+ canLoadMore: infinite.canLoadMore.value,
4544
+ loading: props.loading
4545
+ } : null);
4546
+ const footerCount = computed(() => props.footerRows.length);
4547
+ /** More to load in an infinite list: the count is not the rows given (C-86). */
4548
+ const growing = () => infinite.enabled.value && infinite.canLoadMore.value;
4549
+ const ariaRowCount = computed(() => {
4550
+ if (!rowWindow.enabled()) return;
4551
+ const total = props.totalRows;
4552
+ if (growing() && (total === null || rowWindow.groupCount() > 0)) return -1;
4553
+ const rows = growing() && total !== null ? total : props.rows.length;
4554
+ return headerRows() + rows + rowWindow.expandedCount() + rowWindow.groupCount() + footerCount.value;
4555
+ });
4556
+ /** `aria-rowindex` of the first footer row, or `undefined` (C-86). */
4557
+ const footerRowIndex = computed(() => !rowWindow.enabled() || growing() ? void 0 : 1 + headerRows() + props.rows.length + rowWindow.expandedCount() + rowWindow.groupCount());
4558
+ const flashView = useChangeFlash({
4559
+ flash: () => props.flash,
4560
+ rowsUpdate: () => props.rowsUpdate,
4561
+ rows: () => props.rows,
4562
+ query: () => props.query,
4563
+ loading: () => props.loading,
4564
+ fields: () => entries.value.map((entry) => entry.column.field),
4565
+ rowKey: () => props.rowKey,
4566
+ table: bodyTable
4567
+ });
4568
+ const reorder = useColumnReorder({
4569
+ reorderable: () => props.reorderable,
4570
+ table: tableEl,
4571
+ layout: state.layout,
4572
+ columns: () => props.columns
4573
+ });
4574
+ provideTableContext({
4575
+ filters,
4576
+ sort,
4577
+ layout: state.layout,
4578
+ resize,
4579
+ reorder,
4580
+ selection: rowSelection,
4581
+ labels: () => labels.value
4582
+ });
4583
+ const showPagination = computed(() => !!slots.pagination && (props.rows.length > 0 || (props.totalRows ?? 0) > 0 || (props.pagination?.alwaysShow ?? false)));
4584
+ const canClearFilters = computed(() => filters.canClearAll());
4585
+ const toolbarProps = () => ({
4586
+ canClearFilters: canClearFilters.value,
4587
+ clearFilters: () => {
4588
+ filters.clearAll();
4589
+ },
4590
+ search: search.text.value,
4591
+ setSearch: search.set,
4592
+ applySearch: () => {
4593
+ search.apply();
4594
+ }
4595
+ });
4596
+ const bodySlotNames = () => Object.keys(rawSlots).filter((name) => name.startsWith("cell-") || name === "subtable" || name === "empty" || name === "loading" || name === "load-more" || name === "group");
4597
+ const headerSlotNames = () => Object.keys(rawSlots).filter((name) => name.startsWith("header-") || name === "filter-datetime" || name === "filter-menu").sort().join("\n");
4598
+ const cellSlotNames = () => Object.keys(rawSlots).filter((name) => name.startsWith("cell-")).sort().join("\n");
4599
+ __expose({
4600
+ collapseAll: expansion.collapseAll,
4601
+ expandAll: expansion.expandAll,
4602
+ focusFilter: (field) => focusFilterOf(tableEl.value, field),
4603
+ flushPendingFilters: () => {
4604
+ filters.flushAll();
4605
+ },
4606
+ scrollToIndex: rowWindow.scrollToIndex,
4607
+ loadMore: infinite.loadMore,
4608
+ measureColumnWidths: (fields) => measureColumnWidths(tableEl.value, fields, splitBody())
4609
+ });
4610
+ return (_ctx, _cache) => {
4611
+ return openBlock(), createElementBlock("div", {
4612
+ class: "qt-datatable",
4613
+ "data-empty": !__props.loading && __props.rows.length === 0 ? "" : void 0,
4614
+ "data-loading": __props.loading ? "" : void 0,
4615
+ "aria-busy": __props.loading ? "true" : void 0
4616
+ }, [
4617
+ renderSlot(_ctx.$slots, "toolbar", normalizeProps(guardReactiveProps(toolbarProps()))),
4618
+ createElementVNode("div", {
4619
+ class: "qt-table-responsive",
4620
+ role: split() ? "table" : void 0,
4621
+ "aria-rowcount": split() ? ariaRowCount.value : void 0
4622
+ }, [split() ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
4623
+ createElementVNode("div", {
4624
+ ref_key: "headWrap",
4625
+ ref: headWrap,
4626
+ class: "qt-table-head"
4627
+ }, [createElementVNode("table", {
4628
+ ref_key: "tableEl",
4629
+ ref: tableEl,
4630
+ class: "qt-table",
4631
+ role: "presentation"
4632
+ }, [createElementVNode("thead", {
4633
+ role: "rowgroup",
4634
+ onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onHeaderContextMenu) && unref(onHeaderContextMenu)(...args))
4635
+ }, [createVNode(table_header_default, {
4636
+ columns: visibleColumns.value,
4637
+ query: __props.query,
4638
+ filterable: __props.filterable,
4639
+ utilities: utilities.value,
4640
+ "has-pinned": unref(hasPinned),
4641
+ offsets: unref(offsets),
4642
+ "auto-widths": unref(autoWidth).widths.value,
4643
+ "slot-names": headerSlotNames(),
4644
+ "aria-rowindex": unref(rowWindow).enabled() ? 1 : void 0,
4645
+ roles: ""
4646
+ }, {
4647
+ header: withCtx((p) => [renderSlot(_ctx.$slots, `header-${p.column.field}`, normalizeProps(guardReactiveProps(p)))]),
4648
+ "filter-datetime": withCtx((p) => [renderSlot(_ctx.$slots, "filter-datetime", normalizeProps(guardReactiveProps(p)))]),
4649
+ "filter-menu": withCtx((p) => [renderSlot(_ctx.$slots, "filter-menu", normalizeProps(guardReactiveProps(p)))]),
4650
+ _: 3
4651
+ }, 8, [
4652
+ "columns",
4653
+ "query",
4654
+ "filterable",
4655
+ "utilities",
4656
+ "has-pinned",
4657
+ "offsets",
4658
+ "auto-widths",
4659
+ "slot-names",
4660
+ "aria-rowindex"
4661
+ ])], 32)], 512)], 512),
4662
+ createElementVNode("div", {
4663
+ ref_key: "bodyWrap",
4664
+ ref: bodyWrap,
4665
+ class: "qt-table-body"
4666
+ }, [createElementVNode("table", {
4667
+ ref_key: "bodyTableEl",
4668
+ ref: bodyTableEl,
4669
+ class: "qt-table",
4670
+ role: "presentation"
4671
+ }, [createElementVNode("colgroup", null, [(openBlock(true), createElementBlock(Fragment, null, renderList(colWidths.value, (width, i) => {
4672
+ return openBlock(), createElementBlock("col", {
4673
+ key: i,
4674
+ style: normalizeStyle(width === void 0 ? void 0 : { width: `${width}px` })
4675
+ }, null, 4);
4676
+ }), 128))]), createVNode(table_body_default, mergeProps({
4677
+ rows: __props.rows,
4678
+ "body-rows": unref(rowWindow).drawn.value,
4679
+ "pin-row": unref(state).rowPinning.pin,
4680
+ loading: __props.loading,
4681
+ entries: unref(entries),
4682
+ "slot-names": cellSlotNames(),
4683
+ "column-count": columnCount.value,
4684
+ "has-subtable": __props.hasSubtable,
4685
+ "has-right-panel": __props.hasRightPanel,
4686
+ "has-selection": unref(rowSelection).enabled.value,
4687
+ "is-selected": unref(rowSelection).isSelected,
4688
+ "toggle-selected": unref(rowSelection).toggle,
4689
+ "has-pinned": unref(hasPinned),
4690
+ offsets: unref(offsets),
4691
+ "key-of": unref(expansion).keyOf,
4692
+ "can-expand": unref(expansion).canExpand,
4693
+ "is-expanded": unref(expansion).isExpanded,
4694
+ toggle: unref(expansion).toggle,
4695
+ "row-kind": __props.rowKind,
4696
+ labels: labels.value,
4697
+ "has-context-menu-listener": hasContextMenuListener,
4698
+ "load-more": loadMoreProps.value,
4699
+ flash: unref(flashView),
4700
+ roles: "",
4701
+ onRowRightPanelClick: _cache[1] || (_cache[1] = (row) => emit("rowRightPanelClick", row)),
4702
+ onCellContextMenu: _cache[2] || (_cache[2] = (payload) => emit("cellContextMenu", payload)),
4703
+ onFocusin: unref(rowWindow).onFocusIn,
4704
+ onFocusout: unref(rowWindow).onFocusOut
4705
+ }, toHandlers(navigationListeners())), createSlots({ _: 2 }, [renderList(bodySlotNames(), (name) => {
4706
+ return {
4707
+ name,
4708
+ fn: withCtx((p) => [renderSlot(_ctx.$slots, name, normalizeProps(guardReactiveProps(p)))])
4709
+ };
4710
+ })]), 1040, [
4711
+ "rows",
4712
+ "body-rows",
4713
+ "pin-row",
4714
+ "loading",
4715
+ "entries",
4716
+ "slot-names",
4717
+ "column-count",
4718
+ "has-subtable",
4719
+ "has-right-panel",
4720
+ "has-selection",
4721
+ "is-selected",
4722
+ "toggle-selected",
4723
+ "has-pinned",
4724
+ "offsets",
4725
+ "key-of",
4726
+ "can-expand",
4727
+ "is-expanded",
4728
+ "toggle",
4729
+ "row-kind",
4730
+ "labels",
4731
+ "load-more",
4732
+ "flash",
4733
+ "onFocusin",
4734
+ "onFocusout"
4735
+ ])], 512)], 512),
4736
+ __props.footerRows.length > 0 ? (openBlock(), createElementBlock("div", {
4737
+ key: 0,
4738
+ ref_key: "footWrap",
4739
+ ref: footWrap,
4740
+ class: "qt-table-foot"
4741
+ }, [createElementVNode("table", _hoisted_3, [createElementVNode("colgroup", null, [(openBlock(true), createElementBlock(Fragment, null, renderList(colWidths.value, (width, i) => {
4742
+ return openBlock(), createElementBlock("col", {
4743
+ key: i,
4744
+ style: normalizeStyle(width === void 0 ? void 0 : { width: `${width}px` })
4745
+ }, null, 4);
4746
+ }), 128))]), createVNode(table_footer_default, {
4747
+ "footer-rows": __props.footerRows,
4748
+ entries: unref(entries),
4749
+ "utility-count": utilityCount.value,
4750
+ "has-pinned": unref(hasPinned),
4751
+ offsets: unref(offsets),
4752
+ "first-row-index": footerRowIndex.value,
4753
+ roles: ""
4754
+ }, null, 8, [
4755
+ "footer-rows",
4756
+ "entries",
4757
+ "utility-count",
4758
+ "has-pinned",
4759
+ "offsets",
4760
+ "first-row-index"
4761
+ ])])], 512)) : createCommentVNode("", true)
4762
+ ], 64)) : (openBlock(), createElementBlock("table", {
4763
+ key: 1,
4764
+ ref_key: "tableEl",
4765
+ ref: tableEl,
4766
+ class: "qt-table",
4767
+ "aria-rowcount": ariaRowCount.value
4768
+ }, [
4769
+ !__props.header ? (openBlock(), createElementBlock("colgroup", _hoisted_5, [(openBlock(true), createElementBlock(Fragment, null, renderList(utilities.value, (utility) => {
4770
+ return openBlock(), createElementBlock("col", { key: utility });
4771
+ }), 128)), (openBlock(true), createElementBlock(Fragment, null, renderList(unref(entries), (entry) => {
4772
+ return openBlock(), createElementBlock("col", {
4773
+ key: entry.column.field,
4774
+ style: normalizeStyle(entry.column.width ? { width: entry.column.width } : void 0)
4775
+ }, null, 4);
4776
+ }), 128))])) : (openBlock(), createElementBlock("thead", {
4777
+ key: 1,
4778
+ onContextmenu: _cache[3] || (_cache[3] = (...args) => unref(onHeaderContextMenu) && unref(onHeaderContextMenu)(...args))
4779
+ }, [createVNode(table_header_default, {
4780
+ columns: visibleColumns.value,
4781
+ query: __props.query,
4782
+ filterable: __props.filterable,
4783
+ utilities: utilities.value,
4784
+ "has-pinned": unref(hasPinned),
4785
+ offsets: unref(offsets),
4786
+ "auto-widths": unref(autoWidth).widths.value,
4787
+ "slot-names": headerSlotNames(),
4788
+ "aria-rowindex": unref(rowWindow).enabled() ? 1 : void 0
4789
+ }, {
4790
+ header: withCtx((p) => [renderSlot(_ctx.$slots, `header-${p.column.field}`, normalizeProps(guardReactiveProps(p)))]),
4791
+ "filter-datetime": withCtx((p) => [renderSlot(_ctx.$slots, "filter-datetime", normalizeProps(guardReactiveProps(p)))]),
4792
+ "filter-menu": withCtx((p) => [renderSlot(_ctx.$slots, "filter-menu", normalizeProps(guardReactiveProps(p)))]),
4793
+ _: 3
4794
+ }, 8, [
4795
+ "columns",
4796
+ "query",
4797
+ "filterable",
4798
+ "utilities",
4799
+ "has-pinned",
4800
+ "offsets",
4801
+ "auto-widths",
4802
+ "slot-names",
4803
+ "aria-rowindex"
4804
+ ])], 32)),
4805
+ createVNode(table_body_default, mergeProps({
4806
+ rows: __props.rows,
4807
+ "body-rows": unref(rowWindow).drawn.value,
4808
+ "pin-row": unref(state).rowPinning.pin,
4809
+ loading: __props.loading,
4810
+ entries: unref(entries),
4811
+ "slot-names": cellSlotNames(),
4812
+ "column-count": columnCount.value,
4813
+ "has-subtable": __props.hasSubtable,
4814
+ "has-right-panel": __props.hasRightPanel,
4815
+ "has-selection": unref(rowSelection).enabled.value,
4816
+ "is-selected": unref(rowSelection).isSelected,
4817
+ "toggle-selected": unref(rowSelection).toggle,
4818
+ "has-pinned": unref(hasPinned),
4819
+ offsets: unref(offsets),
4820
+ "key-of": unref(expansion).keyOf,
4821
+ "can-expand": unref(expansion).canExpand,
4822
+ "is-expanded": unref(expansion).isExpanded,
4823
+ toggle: unref(expansion).toggle,
4824
+ "row-kind": __props.rowKind,
4825
+ labels: labels.value,
4826
+ "has-context-menu-listener": hasContextMenuListener,
4827
+ "load-more": loadMoreProps.value,
4828
+ flash: unref(flashView),
4829
+ onRowRightPanelClick: _cache[4] || (_cache[4] = (row) => emit("rowRightPanelClick", row)),
4830
+ onCellContextMenu: _cache[5] || (_cache[5] = (payload) => emit("cellContextMenu", payload)),
4831
+ onFocusin: unref(rowWindow).onFocusIn,
4832
+ onFocusout: unref(rowWindow).onFocusOut
4833
+ }, toHandlers(navigationListeners())), createSlots({ _: 2 }, [renderList(bodySlotNames(), (name) => {
4834
+ return {
4835
+ name,
4836
+ fn: withCtx((p) => [renderSlot(_ctx.$slots, name, normalizeProps(guardReactiveProps(p)))])
4837
+ };
4838
+ })]), 1040, [
4839
+ "rows",
4840
+ "body-rows",
4841
+ "pin-row",
4842
+ "loading",
4843
+ "entries",
4844
+ "slot-names",
4845
+ "column-count",
4846
+ "has-subtable",
4847
+ "has-right-panel",
4848
+ "has-selection",
4849
+ "is-selected",
4850
+ "toggle-selected",
4851
+ "has-pinned",
4852
+ "offsets",
4853
+ "key-of",
4854
+ "can-expand",
4855
+ "is-expanded",
4856
+ "toggle",
4857
+ "row-kind",
4858
+ "labels",
4859
+ "load-more",
4860
+ "flash",
4861
+ "onFocusin",
4862
+ "onFocusout"
4863
+ ]),
4864
+ __props.footerRows.length > 0 ? (openBlock(), createBlock(table_footer_default, {
4865
+ key: 2,
4866
+ "footer-rows": __props.footerRows,
4867
+ entries: unref(entries),
4868
+ "utility-count": utilityCount.value,
4869
+ "has-pinned": unref(hasPinned),
4870
+ offsets: unref(offsets),
4871
+ "first-row-index": footerRowIndex.value
4872
+ }, null, 8, [
4873
+ "footer-rows",
4874
+ "entries",
4875
+ "utility-count",
4876
+ "has-pinned",
4877
+ "offsets",
4878
+ "first-row-index"
4879
+ ])) : createCommentVNode("", true)
4880
+ ], 8, _hoisted_4))], 8, _hoisted_2),
4881
+ showPagination.value ? (openBlock(), createBlock(table_pagination_default, {
4882
+ key: 0,
4883
+ "pagination-props": unref(paginationProps)
4884
+ }, {
4885
+ pagination: withCtx((p) => [renderSlot(_ctx.$slots, "pagination", normalizeProps(guardReactiveProps(p)))]),
4886
+ _: 3
4887
+ }, 8, ["pagination-props"])) : createCommentVNode("", true)
4888
+ ], 8, _hoisted_1);
4889
+ };
4890
+ }
4891
+ });
4892
+ //#endregion
4893
+ //#region src/filter/parse-filter-input.ts
4894
+ /**
4895
+ * The rules the table emits when `text` is typed into the filter input of
4896
+ * `column` (C-53): the same grammar and the same coercion per column type.
4897
+ *
4898
+ * - `string`: operator shortcuts (`*a*`, `a*`, `*a`, `!a`, `!*a*`, `a,b`);
4899
+ * a segment without an operator uses `condition`.
4900
+ * - `number`: one rule per comma-separated number value; a value after `!`
4901
+ * is `NotEqual` (`80,443`, `!80,!443`). A value that is not a finite
4902
+ * number, a list that mixes `!` and plain values, or a list without `!`
4903
+ * whose `condition` is a comparison (`0,5` with `GreaterThan`), gives
4904
+ * `[]`. The comma always separates; a decimal is written with a dot.
4905
+ * - `integer`: the same, but only whole numbers in the safe range; `2.5`
4906
+ * and `9007199254740993` give `[]`.
4907
+ * - `bool`: `'true'` or `'false'` gives one rule with a boolean value;
4908
+ * anything else gives `[]`.
4909
+ * - `date` and `datetime`: one rule with the trimmed text as its value; the
4910
+ * text is not validated, as the input already gives an ISO date.
4911
+ *
4912
+ * `condition` is the one picked in the filter menu; without it the column's
4913
+ * `filterDefaultCondition` applies (C-117), else the type's default
4914
+ * (`Contains` for text, `Equal` otherwise). Empty or
4915
+ * blank text, and text that is only operators (`*`, `!`, `!*`), gives `[]`.
4916
+ * Invalid input never throws. Pure: no Vue, no DOM; the column is not written.
4917
+ * The grammar is the protocol's (`@dolusoft/query-protocol`).
4918
+ */
4919
+ function parseFilterInput$1(text, column, condition = null) {
4920
+ return parseFilterInput(text, column, condition);
4921
+ }
4922
+ //#endregion
4923
+ //#region src/index.ts
4924
+ var src_default = query_table_default;
4925
+ //#endregion
4926
+ export { useQueryTable as i, parseFilterInput$1 as n, query_table_default as r, src_default as t };
4927
+
4928
+ //# sourceMappingURL=src-BTIXBmwM.js.map