@dolusoft/query-table 3.2.1 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
- import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createStaticVNode, createTextVNode, createVNode, defineComponent, getCurrentInstance, guardReactiveProps, h, inject, mergeProps, nextTick, normalizeProps, normalizeStyle, onBeforeUnmount, onScopeDispose, openBlock, provide, renderList, renderSlot, shallowRef, toDisplayString, toHandlers, toValue, unref, useSlots, watch, watchEffect, withCtx, withKeys, withModifiers } from "vue";
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
2
  import { columnTypeOf, columnTypeOf as columnTypeOf$1, conditionLabel, conditionOptions, isCursorQuery, parseFilterInput as parseFilterInput$1, rulesOf, searchOf } from "@dolusoft/query-protocol";
3
+ import { createRowChangeTracker } from "@dolusoft/query-table-core/row-changes";
3
4
  import { dispose, filterInputFeature, projectServerQuery, serverQueryFeature } from "@dolusoft/query-table-core";
4
5
  import { columnFilteringFeature, columnOrderingFeature, columnPinningFeature, columnVisibilityFeature, functionalUpdate, globalFilteringFeature, rowExpandingFeature, rowPaginationFeature, rowPinningFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable } from "@tanstack/vue-table";
5
6
  //#region src/columns/column-layout.ts
@@ -145,6 +146,495 @@ var focusFirstFilter = (table) => {
145
146
  return false;
146
147
  };
147
148
  //#endregion
149
+ //#region src/flash/marks.ts
150
+ /** A mark that is still running at `now`, else `null`. */
151
+ var live = (mark, now) => mark && mark.end > now ? mark : null;
152
+ /**
153
+ * The marks of one table (C-94): row and cell flashes by row key. Starting
154
+ * a flash that runs already restarts it, and the phase changes at most once
155
+ * a frame, so changes within one frame are one visual restart (K33-4).
156
+ */
157
+ var createMarks = () => {
158
+ const byKey = /* @__PURE__ */ new Map();
159
+ let gen = 0;
160
+ const restart = (mark, now, duration, frame) => {
161
+ gen++;
162
+ if (!mark) return {
163
+ start: now,
164
+ end: now + duration,
165
+ gen,
166
+ phase: "a",
167
+ flipFrame: frame
168
+ };
169
+ mark.start = now;
170
+ mark.end = now + duration;
171
+ mark.gen = gen;
172
+ if (mark.flipFrame !== frame) {
173
+ mark.phase = mark.phase === "a" ? "b" : "a";
174
+ mark.flipFrame = frame;
175
+ }
176
+ return mark;
177
+ };
178
+ const entry = (key) => {
179
+ let marks = byKey.get(key);
180
+ if (!marks) {
181
+ marks = {
182
+ row: null,
183
+ cells: null
184
+ };
185
+ byKey.set(key, marks);
186
+ }
187
+ return marks;
188
+ };
189
+ /** Flash the row of `key`; its cell flashes go (a new row is new as a whole). */
190
+ const flashRow = (key, now, duration, frame) => {
191
+ const marks = entry(key);
192
+ marks.row = restart(marks.row, now, duration, frame);
193
+ marks.cells?.clear();
194
+ };
195
+ const flashCell = (key, field, now, duration, frame) => {
196
+ const marks = entry(key);
197
+ const cells = marks.cells ??= /* @__PURE__ */ new Map();
198
+ cells.set(field, restart(cells.get(field), now, duration, frame));
199
+ };
200
+ const isEmpty = (marks) => marks.row === null && (marks.cells === null || marks.cells.size === 0);
201
+ /** Drop every row flash (`flash.rows` turned off). True when one went. */
202
+ const clearRows = () => {
203
+ let dropped = false;
204
+ for (const [key, marks] of byKey) {
205
+ if (marks.row) {
206
+ marks.row = null;
207
+ dropped = true;
208
+ }
209
+ if (isEmpty(marks)) byKey.delete(key);
210
+ }
211
+ return dropped;
212
+ };
213
+ /** Drop the cell flashes of `fields`, or of every field. True when one went. */
214
+ const clearCells = (fields) => {
215
+ let dropped = false;
216
+ for (const [key, marks] of byKey) {
217
+ const cells = marks.cells;
218
+ if (cells && cells.size > 0) {
219
+ if (fields) for (const field of fields) dropped = cells.delete(field) || dropped;
220
+ else {
221
+ cells.clear();
222
+ dropped = true;
223
+ }
224
+ }
225
+ if (isEmpty(marks)) byKey.delete(key);
226
+ }
227
+ return dropped;
228
+ };
229
+ /** Drop everything. True when something went. */
230
+ const clear = () => {
231
+ const had = byKey.size > 0;
232
+ byKey.clear();
233
+ return had;
234
+ };
235
+ /**
236
+ * Drop the marks that end by `until`; the nearest end of the ones left,
237
+ * or `Infinity`. True in `dropped` when one went.
238
+ */
239
+ const prune = (until) => {
240
+ let nearest = Infinity;
241
+ let dropped = false;
242
+ for (const [key, marks] of byKey) {
243
+ if (marks.row) {
244
+ if (marks.row.end <= until) {
245
+ marks.row = null;
246
+ dropped = true;
247
+ } else nearest = Math.min(nearest, marks.row.end);
248
+ }
249
+ if (marks.cells) for (const [field, mark] of marks.cells) if (mark.end <= until) {
250
+ marks.cells.delete(field);
251
+ dropped = true;
252
+ } else nearest = Math.min(nearest, mark.end);
253
+ if (isEmpty(marks)) byKey.delete(key);
254
+ }
255
+ return {
256
+ nearest,
257
+ dropped
258
+ };
259
+ };
260
+ return {
261
+ get: (key) => byKey.get(key),
262
+ get size() {
263
+ return byKey.size;
264
+ },
265
+ /** The generation of the last start. */
266
+ get gen() {
267
+ return gen;
268
+ },
269
+ flashRow,
270
+ flashCell,
271
+ clearRows,
272
+ clearCells,
273
+ clear,
274
+ prune
275
+ };
276
+ };
277
+ //#endregion
278
+ //#region src/flash/read-duration.ts
279
+ /** The custom property a skin sets the flash duration with (C-94). */
280
+ var durationProperty = "--qt-flash-duration";
281
+ /**
282
+ * A CSS time in milliseconds: `250ms`, `2s`, `.5s`. Anything else (a
283
+ * missing value, `calc()`, a negative or a zero time, a number without a
284
+ * unit) is `0`: no flash.
285
+ */
286
+ var parseDuration = (text) => {
287
+ const match = /^\s*(\d*\.?\d+(?:e[+-]?\d+)?)(ms|s)\s*$/i.exec(text);
288
+ if (!match) return 0;
289
+ const value = Number(match[1]) * (match[2].toLowerCase() === "s" ? 1e3 : 1);
290
+ return Number.isFinite(value) && value > 0 ? value : 0;
291
+ };
292
+ /**
293
+ * The flash duration the skin set on the table root (`.qt-datatable`) or
294
+ * above it, in milliseconds; `0` without one. One style read: the caller
295
+ * reads it at most once a frame, and only for an update that marks
296
+ * something (C-94).
297
+ */
298
+ var readDuration = (table) => {
299
+ const root = table?.closest(".qt-datatable");
300
+ if (!root) return 0;
301
+ return parseDuration(getComputedStyle(root).getPropertyValue(durationProperty));
302
+ };
303
+ //#endregion
304
+ //#region src/flash/use-change-flash.ts
305
+ var warn = (message) => {
306
+ try {
307
+ if (process.env.NODE_ENV === "production") return;
308
+ } catch {}
309
+ console.warn(`[QueryTable] ${message}`);
310
+ };
311
+ /** The inline custom property of an element bound after its flash began. */
312
+ var elapsedProperty = "--qt-flash-elapsed";
313
+ var kindsOf = (value) => typeof value === "object" ? {
314
+ rows: value.rows !== false,
315
+ cells: value.cells !== false
316
+ } : {
317
+ rows: true,
318
+ cells: true
319
+ };
320
+ var keyReader = (rowKey) => (row, index) => typeof rowKey === "function" ? rowKey(row, index) : row[rowKey];
321
+ /**
322
+ * The flash of one table while `flash` is on: feeds the tracker, keeps the
323
+ * marks, reads the duration, runs the one timer and binds the elapsed time.
324
+ * It lives in the effect scope it is created in and goes with it.
325
+ */
326
+ var startFlash = (o) => {
327
+ let rowKey = o.rowKey();
328
+ let keyOf = rowKey === void 0 ? null : keyReader(rowKey);
329
+ const newTracker = () => createRowChangeTracker((row, index) => keyOf(row, index));
330
+ let tracker = newTracker();
331
+ const marks = createMarks();
332
+ /** Bumped when the drawn marks change: the body reads it. */
333
+ const version = shallowRef(0);
334
+ let kinds = kindsOf(o.flash());
335
+ let active = true;
336
+ let warnedKey = false;
337
+ let warnedBadKeys = false;
338
+ let frame = 0;
339
+ let frameRequest;
340
+ /** The duration read in this frame (valid while a frame is requested). */
341
+ let duration = 0;
342
+ let timer;
343
+ /** The end the timer wakes at. */
344
+ let timerAt = Infinity;
345
+ /**
346
+ * The first generation started in the update being drawn: an element
347
+ * bound to it in the same render gets no elapsed time.
348
+ */
349
+ let freshFrom = Infinity;
350
+ /** A frame went by: the next change flips the phase, the duration is read again. */
351
+ const requestFrame = () => {
352
+ frameRequest ??= requestAnimationFrame(() => {
353
+ frameRequest = void 0;
354
+ frame++;
355
+ });
356
+ };
357
+ const durationNow = () => {
358
+ if (frameRequest === void 0) {
359
+ duration = readDuration(o.table.value);
360
+ requestFrame();
361
+ }
362
+ return duration;
363
+ };
364
+ const stopClock = () => {
365
+ if (timer !== void 0) {
366
+ clearTimeout(timer);
367
+ timer = void 0;
368
+ timerAt = Infinity;
369
+ }
370
+ if (frameRequest !== void 0) {
371
+ cancelAnimationFrame(frameRequest);
372
+ frameRequest = void 0;
373
+ }
374
+ };
375
+ /** Wake at `end`: drop what ended, then wake at the next end. */
376
+ const wakeAt = (end) => {
377
+ if (timer !== void 0) clearTimeout(timer);
378
+ timerAt = end;
379
+ timer = setTimeout(() => {
380
+ timer = void 0;
381
+ timerAt = Infinity;
382
+ const { nearest, dropped } = marks.prune(performance.now());
383
+ if (dropped) version.value++;
384
+ if (nearest !== Infinity) wakeAt(nearest);
385
+ }, Math.max(0, end - performance.now()));
386
+ };
387
+ /** Everything goes: marks, timer, frame and the rows compared against. */
388
+ const resetAll = () => {
389
+ tracker.clear();
390
+ stopClock();
391
+ if (marks.clear()) version.value++;
392
+ };
393
+ const update = () => {
394
+ if (!active) return;
395
+ if (o.rowKey() !== rowKey) {
396
+ rowKey = o.rowKey();
397
+ keyOf = rowKey === void 0 ? null : keyReader(rowKey);
398
+ resetAll();
399
+ tracker = newTracker();
400
+ }
401
+ if (keyOf === null) {
402
+ if (!warnedKey) {
403
+ warnedKey = true;
404
+ warn("`flash` needs `rowKey`; it is ignored without one (C-93).");
405
+ }
406
+ return;
407
+ }
408
+ let changed = false;
409
+ const next = kindsOf(o.flash());
410
+ if (!next.rows && kinds.rows) changed = marks.clearRows() || changed;
411
+ if (!next.cells && kinds.cells) changed = marks.clearCells() || changed;
412
+ kinds = next;
413
+ const result = tracker.update({
414
+ rows: o.rows(),
415
+ query: o.query(),
416
+ loading: o.loading(),
417
+ fields: kinds.cells ? o.fields() : [],
418
+ hint: o.rowsUpdate(),
419
+ quiet: document.hidden
420
+ });
421
+ if (result.badKeys && !warnedBadKeys) {
422
+ warnedBadKeys = true;
423
+ warn("`flash` found a row without a `rowKey` value, or a key two rows share; the index is never used instead (C-93).");
424
+ }
425
+ if (result.reset) {
426
+ stopClock();
427
+ changed = marks.clear() || changed;
428
+ }
429
+ if (result.droppedFields.length > 0) changed = marks.clearCells(result.droppedFields) || changed;
430
+ const added = kinds.rows ? result.added : [];
431
+ const cells = kinds.cells ? result.changed : null;
432
+ if (added.length > 0 || cells !== null && cells.size > 0) {
433
+ const length = durationNow();
434
+ if (length > 0) {
435
+ const at = performance.now();
436
+ const firstGen = marks.gen + 1;
437
+ for (const key of added) marks.flashRow(key, at, length, frame);
438
+ cells?.forEach((fields, key) => {
439
+ for (const field of fields) marks.flashCell(key, field, at, length, frame);
440
+ });
441
+ changed = true;
442
+ if (freshFrom === Infinity) {
443
+ freshFrom = firstGen;
444
+ nextTick(() => {
445
+ freshFrom = Infinity;
446
+ });
447
+ }
448
+ requestFrame();
449
+ if (at + length < timerAt) wakeAt(at + length);
450
+ }
451
+ }
452
+ if (changed) version.value++;
453
+ };
454
+ update();
455
+ const rowMarksOf = (row, index) => {
456
+ version.value;
457
+ return keyOf === null ? void 0 : marks.get(keyOf(row, index));
458
+ };
459
+ /** The generation bound to an element, and the elapsed value written on it. */
460
+ const bound = /* @__PURE__ */ new WeakMap();
461
+ const written = /* @__PURE__ */ new WeakMap();
462
+ /** Rows with something bound on them or on one of their cells. */
463
+ const boundRows = /* @__PURE__ */ new WeakSet();
464
+ /** The row flash a cell was last seen under. */
465
+ const seenUnder = /* @__PURE__ */ new WeakMap();
466
+ const bindTo = (el, mark, now, blockInherited) => {
467
+ const gen = bound.get(el);
468
+ if (!mark) {
469
+ if (gen !== void 0) {
470
+ bound.delete(el);
471
+ written.delete(el);
472
+ el.style.removeProperty(elapsedProperty);
473
+ }
474
+ return;
475
+ }
476
+ if (gen === mark.gen) {
477
+ const value = written.get(el) ?? "";
478
+ if (value !== "" && el.style.getPropertyValue(elapsedProperty) === "") el.style.setProperty(elapsedProperty, value);
479
+ return;
480
+ }
481
+ const elapsed = mark.gen >= freshFrom ? 0 : now - mark.start;
482
+ const value = elapsed >= 1 ? `${Math.round(elapsed)}ms` : blockInherited ? "0ms" : "";
483
+ if (value === "") el.style.removeProperty(elapsedProperty);
484
+ else el.style.setProperty(elapsedProperty, value);
485
+ bound.set(el, mark.gen);
486
+ written.set(el, value);
487
+ };
488
+ const view = {
489
+ row: (row, index) => {
490
+ const mark = rowMarksOf(row, index)?.row;
491
+ return mark ? live(mark, performance.now())?.phase : void 0;
492
+ },
493
+ cell: (row, index, field) => {
494
+ const mark = rowMarksOf(row, index)?.cells?.get(field);
495
+ return mark ? live(mark, performance.now())?.phase : void 0;
496
+ },
497
+ bind: (vnode) => {
498
+ const tr = vnode.el;
499
+ const index = Number(vnode.props?.["data-row-index"]);
500
+ const row = o.rows()[index];
501
+ if (!tr || row === void 0 || keyOf === null) return;
502
+ const rowMarks = marks.get(keyOf(row, index));
503
+ if (!rowMarks && !boundRows.has(tr)) return;
504
+ const now = performance.now();
505
+ const rowMark = live(rowMarks?.row, now);
506
+ const rowWasBound = rowMark !== null && bound.get(tr) === rowMark.gen;
507
+ bindTo(tr, rowMark, now, false);
508
+ const rowValue = written.get(tr) ?? "";
509
+ let any = bound.has(tr);
510
+ const cells = tr.children;
511
+ for (let i = 0; i < cells.length; i++) {
512
+ const td = cells[i];
513
+ const field = td.getAttribute("data-field");
514
+ const own = field === null ? null : live(rowMarks?.cells?.get(field), now);
515
+ if (own) bindTo(td, own, now, rowValue !== "");
516
+ else if (rowMark && (bound.get(td) === rowMark.gen || rowWasBound && seenUnder.get(td) !== rowMark.gen)) bindTo(td, rowMark, now, false);
517
+ else bindTo(td, null, now, false);
518
+ if (rowMark) seenUnder.set(td, rowMark.gen);
519
+ any ||= bound.has(td);
520
+ }
521
+ if (any) boundRows.add(tr);
522
+ else boundRows.delete(tr);
523
+ }
524
+ };
525
+ /** Remove the elapsed times written on the body. */
526
+ const unbindAll = () => {
527
+ const body = o.table.value?.tBodies[0];
528
+ if (!body) return;
529
+ const rows = body.children;
530
+ for (let i = 0; i < rows.length; i++) {
531
+ const tr = rows[i];
532
+ tr.style.removeProperty(elapsedProperty);
533
+ const cells = tr.children;
534
+ for (let j = 0; j < cells.length; j++) cells[j].style.removeProperty(elapsedProperty);
535
+ }
536
+ };
537
+ onScopeDispose(stopClock);
538
+ return {
539
+ view,
540
+ unbind: unbindAll,
541
+ update,
542
+ deactivate: () => {
543
+ active = false;
544
+ resetAll();
545
+ unbindAll();
546
+ },
547
+ activate: () => {
548
+ active = true;
549
+ update();
550
+ }
551
+ };
552
+ };
553
+ /**
554
+ * The change flash of `QueryTable` (C-93 to C-95). Off, it sets up one
555
+ * watcher that reads `flash` and nothing else: no comparison, timer, frame
556
+ * callback, listener, style read or memory per row. On, the same watcher
557
+ * also reads what the tracker compares, and the flash runs in an effect
558
+ * scope of its own; stopping that scope undoes everything. Nothing runs on
559
+ * the server: the flash starts once the table is mounted.
560
+ */
561
+ var useChangeFlash = (o) => {
562
+ const view = shallowRef(null);
563
+ const instance = getCurrentInstance();
564
+ const owner = getCurrentScope();
565
+ let scope = null;
566
+ let controller = null;
567
+ let hooked = false;
568
+ let mounted = false;
569
+ const start = () => {
570
+ scope = owner.run(() => effectScope());
571
+ controller = scope.run(() => startFlash(o));
572
+ view.value = controller.view;
573
+ if (!hooked) {
574
+ hooked = true;
575
+ onDeactivated(() => controller?.deactivate(), instance);
576
+ onActivated(() => controller?.activate(), instance);
577
+ }
578
+ };
579
+ const stop = () => {
580
+ controller?.unbind();
581
+ scope?.stop();
582
+ scope = null;
583
+ controller = null;
584
+ view.value = null;
585
+ };
586
+ watch(() => o.flash() ? [
587
+ o.flash(),
588
+ o.rows(),
589
+ o.query(),
590
+ o.loading(),
591
+ o.rowsUpdate(),
592
+ o.rowKey(),
593
+ o.fields()
594
+ ] : null, (on) => {
595
+ if (!mounted) return;
596
+ if (!on) stop();
597
+ else if (controller) controller.update();
598
+ else start();
599
+ });
600
+ onMounted(() => {
601
+ mounted = true;
602
+ if (o.flash()) start();
603
+ });
604
+ return view;
605
+ };
606
+ //#endregion
607
+ //#region src/header/use-header-context-menu.ts
608
+ /**
609
+ * One listener on the `thead` serves every header cell (C-96): a listener per
610
+ * cell would be a new closure per cell on every render. Only a data column
611
+ * header emits (`data-field`); utility cells keep the browser menu. A right
612
+ * click inside the filter row (`.qt-filter`) keeps the browser menu too, so
613
+ * paste and spell-check stay (issue #102 S1(a)).
614
+ */
615
+ var useHeaderContextMenu = (options) => {
616
+ const onContextMenu = (event) => {
617
+ if (!options.listening()) return;
618
+ const head = event.currentTarget;
619
+ let cell = event.target?.closest("th") ?? null;
620
+ while (cell && cell.parentElement?.parentElement !== head) cell = cell.parentElement?.closest("th") ?? null;
621
+ const field = cell?.getAttribute("data-field") ?? null;
622
+ if (field === null || !cell) return;
623
+ const target = event.target;
624
+ if (target?.closest(".qt-filter") && cell.contains(target.closest(".qt-filter"))) return;
625
+ const column = options.columns().find((c) => c.field === field);
626
+ const columnIndex = options.indexOf(field);
627
+ if (!column || columnIndex === void 0) return;
628
+ event.preventDefault();
629
+ options.onContextMenu({
630
+ event,
631
+ column,
632
+ columnIndex
633
+ });
634
+ };
635
+ return { onContextMenu };
636
+ };
637
+ //#endregion
148
638
  //#region src/core/column.ts
149
639
  /** Reads a dotted path (`'a.b'`) from a row. */
150
640
  var valueAt = (row, path) => path.split(".").reduce((value, key) => value === null || value === void 0 ? void 0 : value[key], row);
@@ -240,7 +730,10 @@ var _hoisted_2$5 = [
240
730
  "aria-rowindex",
241
731
  "data-pinned-row",
242
732
  "data-expanded",
243
- "data-selected"
733
+ "data-selected",
734
+ "data-flash",
735
+ "onVnodeBeforeMount",
736
+ "onVnodeUpdated"
244
737
  ];
245
738
  var _hoisted_3$5 = ["aria-label", "onClick"];
246
739
  var _hoisted_4$4 = [
@@ -272,23 +765,25 @@ var _hoisted_8$1 = [
272
765
  "checked",
273
766
  "onChange"
274
767
  ];
275
- var _hoisted_9$1 = ["aria-rowindex", "data-pinned-row"];
276
- var _hoisted_10 = ["colspan"];
277
- var _hoisted_11 = {
768
+ var _hoisted_9$1 = ["data-flash"];
769
+ var _hoisted_10 = ["data-flash"];
770
+ var _hoisted_11 = ["aria-rowindex", "data-pinned-row"];
771
+ var _hoisted_12 = ["colspan"];
772
+ var _hoisted_13 = {
278
773
  key: 0,
279
774
  class: "qt-loading-row"
280
775
  };
281
- var _hoisted_12 = ["colspan"];
282
- var _hoisted_13 = {
776
+ var _hoisted_14 = ["colspan"];
777
+ var _hoisted_15 = {
283
778
  key: 1,
284
779
  class: "qt-empty-row"
285
780
  };
286
- var _hoisted_14 = ["colspan"];
287
- var _hoisted_15 = {
781
+ var _hoisted_16 = ["colspan"];
782
+ var _hoisted_17 = {
288
783
  key: 2,
289
784
  class: "qt-load-more-row"
290
785
  };
291
- var _hoisted_16 = ["colspan"];
786
+ var _hoisted_18 = ["colspan"];
292
787
  //#endregion
293
788
  //#region src/parts/table-body.vue
294
789
  var table_body_default = /* @__PURE__ */ defineComponent({
@@ -312,7 +807,8 @@ var table_body_default = /* @__PURE__ */ defineComponent({
312
807
  toggle: { type: Function },
313
808
  labels: {},
314
809
  hasContextMenuListener: { type: Function },
315
- loadMore: {}
810
+ loadMore: {},
811
+ flash: {}
316
812
  },
317
813
  emits: ["rowRightPanelClick", "cellContextMenu"],
318
814
  setup(__props, { emit: __emit }) {
@@ -335,6 +831,21 @@ var table_body_default = /* @__PURE__ */ defineComponent({
335
831
  const isSpacer = (item) => "spacer" in item;
336
832
  /** `aria-rowindex` of the subtable row under a drawn row (C-86). */
337
833
  const nextIndex = (aria) => aria === void 0 ? void 0 : aria + 1;
834
+ let expandedSnapshot = null;
835
+ onBeforeUpdate(() => {
836
+ expandedSnapshot = null;
837
+ });
838
+ const isRowExpanded = (item) => {
839
+ if (isSpacer(item)) return false;
840
+ if (!expandedSnapshot) {
841
+ const open = /* @__PURE__ */ new Map();
842
+ if (props.hasSubtable) {
843
+ for (const row of props.bodyRows) if (!isSpacer(row)) open.set(String(props.keyOf(row.row, row.index)), props.isExpanded(row.row, row.index));
844
+ }
845
+ expandedSnapshot = open;
846
+ }
847
+ return expandedSnapshot.get(String(props.keyOf(item.row, item.index))) === true;
848
+ };
338
849
  return (_ctx, _cache) => {
339
850
  return openBlock(), createElementBlock("tbody", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onContextMenu) && unref(onContextMenu)(...args)) }, [
340
851
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.bodyRows, (item) => {
@@ -343,12 +854,16 @@ var table_body_default = /* @__PURE__ */ defineComponent({
343
854
  class: "qt-virtual-spacer",
344
855
  "aria-hidden": "true",
345
856
  style: normalizeStyle({ height: `${item.spacer}px` })
346
- }, [createElementVNode("td", { colspan: __props.columnCount }, null, 8, _hoisted_1$9)], 4)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createElementVNode("tr", {
857
+ }, [createElementVNode("td", { colspan: __props.columnCount }, null, 8, _hoisted_1$9)], 4)) : (openBlock(), createElementBlock("tr", {
858
+ key: 1,
347
859
  "data-row-index": item.index,
348
860
  "aria-rowindex": item.aria,
349
861
  "data-pinned-row": item.pinned || void 0,
350
- "data-expanded": __props.isExpanded(item.row, item.index) ? "" : void 0,
351
- "data-selected": __props.hasSelection && __props.isSelected(item.row, item.index) ? "" : void 0
862
+ "data-expanded": isRowExpanded(item) ? "" : void 0,
863
+ "data-selected": __props.hasSelection && __props.isSelected(item.row, item.index) ? "" : void 0,
864
+ "data-flash": __props.flash ? __props.flash.row(item.row, item.index) : void 0,
865
+ onVnodeBeforeMount: __props.flash ? __props.flash.bind : void 0,
866
+ onVnodeUpdated: __props.flash ? __props.flash.bind : void 0
352
867
  }, [
353
868
  __props.hasRightPanel ? (openBlock(), createElementBlock("td", mergeProps({
354
869
  key: 0,
@@ -384,10 +899,10 @@ var table_body_default = /* @__PURE__ */ defineComponent({
384
899
  }, expandAttrs()), [createElementVNode("button", {
385
900
  type: "button",
386
901
  class: "qt-expand",
387
- "aria-expanded": __props.isExpanded(item.row, item.index),
902
+ "aria-expanded": isRowExpanded(item),
388
903
  "aria-label": __props.labels.expandRow,
389
904
  onClick: ($event) => __props.toggle(item.row, item.index)
390
- }, [(openBlock(), createElementBlock("svg", _hoisted_5$1, [__props.isExpanded(item.row, item.index) ? (openBlock(), createElementBlock("polyline", _hoisted_6$1)) : (openBlock(), createElementBlock("polyline", _hoisted_7$1))]))], 8, _hoisted_4$4)], 16)) : createCommentVNode("", true),
905
+ }, [(openBlock(), createElementBlock("svg", _hoisted_5$1, [isRowExpanded(item) ? (openBlock(), createElementBlock("polyline", _hoisted_6$1)) : (openBlock(), createElementBlock("polyline", _hoisted_7$1))]))], 8, _hoisted_4$4)], 16)) : createCommentVNode("", true),
391
906
  __props.hasSelection ? (openBlock(), createElementBlock("td", mergeProps({
392
907
  key: 2,
393
908
  ref_for: true
@@ -402,23 +917,23 @@ var table_body_default = /* @__PURE__ */ defineComponent({
402
917
  return openBlock(), createElementBlock(Fragment, { key: entry.column.field }, [unref(hasCellSlot)(entry.column) ? (openBlock(), createElementBlock("td", mergeProps({
403
918
  key: 0,
404
919
  ref_for: true
405
- }, unref(cellAttrs)(entry)), [renderSlot(_ctx.$slots, `cell-${entry.column.field}`, mergeProps({ ref_for: true }, unref(slotProps)(item.row, entry.column, item.index, item.pinned)))], 16)) : (openBlock(), createElementBlock("td", mergeProps({
920
+ }, unref(cellAttrs)(entry), { "data-flash": __props.flash ? __props.flash.cell(item.row, item.index, entry.column.field) : void 0 }), [renderSlot(_ctx.$slots, `cell-${entry.column.field}`, mergeProps({ ref_for: true }, unref(slotProps)(item.row, entry.column, item.index, item.pinned)))], 16, _hoisted_9$1)) : (openBlock(), createElementBlock("td", mergeProps({
406
921
  key: 1,
407
922
  ref_for: true
408
- }, unref(cellAttrs)(entry)), toDisplayString(unref(cellText)(item.row, entry.column)), 17))], 64);
923
+ }, unref(cellAttrs)(entry), { "data-flash": __props.flash ? __props.flash.cell(item.row, item.index, entry.column.field) : void 0 }), toDisplayString(unref(cellText)(item.row, entry.column)), 17, _hoisted_10))], 64);
409
924
  }), 128))
410
- ], 8, _hoisted_2$5), __props.isExpanded(item.row, item.index) ? (openBlock(), createElementBlock("tr", {
411
- key: 0,
925
+ ], 8, _hoisted_2$5)), !isSpacer(item) && isRowExpanded(item) ? (openBlock(), createElementBlock("tr", {
926
+ key: 2,
412
927
  class: "qt-subtable-row",
413
928
  "aria-rowindex": nextIndex(item.aria),
414
929
  "data-pinned-row": item.pinned || void 0
415
930
  }, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "subtable", {
416
931
  row: item.row,
417
932
  rowIndex: item.index
418
- })], 8, _hoisted_10)], 8, _hoisted_9$1)) : createCommentVNode("", true)], 64))], 64);
933
+ })], 8, _hoisted_12)], 8, _hoisted_11)) : createCommentVNode("", true)], 64);
419
934
  }), 128)),
420
- __props.loading && slots.loading ? (openBlock(), createElementBlock("tr", _hoisted_11, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "loading")], 8, _hoisted_12)])) : !__props.loading && __props.rows.length === 0 && slots.empty ? (openBlock(), createElementBlock("tr", _hoisted_13, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "empty")], 8, _hoisted_14)])) : createCommentVNode("", true),
421
- !__props.loading && __props.rows.length > 0 && __props.loadMore && slots["load-more"] ? (openBlock(), createElementBlock("tr", _hoisted_15, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "load-more", normalizeProps(guardReactiveProps(__props.loadMore)))], 8, _hoisted_16)])) : createCommentVNode("", true)
935
+ __props.loading && slots.loading ? (openBlock(), createElementBlock("tr", _hoisted_13, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "loading")], 8, _hoisted_14)])) : !__props.loading && __props.rows.length === 0 && slots.empty ? (openBlock(), createElementBlock("tr", _hoisted_15, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "empty")], 8, _hoisted_16)])) : createCommentVNode("", true),
936
+ !__props.loading && __props.rows.length > 0 && __props.loadMore && slots["load-more"] ? (openBlock(), createElementBlock("tr", _hoisted_17, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "load-more", normalizeProps(guardReactiveProps(__props.loadMore)))], 8, _hoisted_18)])) : createCommentVNode("", true)
422
937
  ], 32);
423
938
  };
424
939
  }
@@ -1150,7 +1665,7 @@ var useHeaderGeometry = (options) => {
1150
1665
  let observer = null;
1151
1666
  const headerCells = (table) => table.querySelectorAll(":scope > thead > tr > *");
1152
1667
  const measure = (table) => {
1153
- tableWidth.value = table.getBoundingClientRect().width;
1668
+ tableWidth.value = Math.round(table.getBoundingClientRect().width);
1154
1669
  const cells = options.cells();
1155
1670
  const next = {};
1156
1671
  const nextOffsets = {};
@@ -1159,7 +1674,7 @@ var useHeaderGeometry = (options) => {
1159
1674
  headerCells(table).forEach((cell, index) => {
1160
1675
  const drawn = cells[index];
1161
1676
  if (drawn) {
1162
- const width = cell.getBoundingClientRect().width;
1677
+ const width = Math.round(cell.getBoundingClientRect().width);
1163
1678
  next[drawn.key] = width;
1164
1679
  if (drawn.side === "left") {
1165
1680
  nextOffsets[drawn.key] = left;
@@ -1727,16 +2242,16 @@ function useQueryTable(options) {
1727
2242
  cursorMode
1728
2243
  };
1729
2244
  });
1730
- const expanded = () => {
2245
+ const expandedState = computed(() => {
1731
2246
  const state = table.atoms.expanded.get();
1732
2247
  return state === true ? {} : state;
1733
- };
2248
+ });
1734
2249
  const setExpanded = (update) => {
1735
2250
  table.setExpanded((old) => update(old === true ? {} : { ...old }));
1736
2251
  };
1737
2252
  const expansion = {
1738
2253
  keyOf,
1739
- isExpanded: (row, index) => hasSubtable() && !!expanded()[idOf(row, index)],
2254
+ isExpanded: (row, index) => hasSubtable() && !!expandedState.value[idOf(row, index)],
1740
2255
  toggle: (row, index) => {
1741
2256
  const id = idOf(row, index);
1742
2257
  setExpanded((state) => {
@@ -2548,13 +3063,19 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2548
3063
  infinite: {
2549
3064
  type: [Boolean, Object],
2550
3065
  default: false
2551
- }
3066
+ },
3067
+ flash: {
3068
+ type: [Boolean, Object],
3069
+ default: false
3070
+ },
3071
+ rowsUpdate: { default: void 0 }
2552
3072
  },
2553
3073
  emits: [
2554
3074
  "update:query",
2555
3075
  "update:selection",
2556
3076
  "rowRightPanelClick",
2557
3077
  "cellContextMenu",
3078
+ "headerContextMenu",
2558
3079
  "columnResize",
2559
3080
  "update:columns",
2560
3081
  "update:rowPinning"
@@ -2592,8 +3113,18 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2592
3113
  const vnodeProps = instance?.vnode.props;
2593
3114
  return !!(vnodeProps?.onCellContextMenu || vnodeProps?.onCellContextMenuOnce);
2594
3115
  };
3116
+ const hasHeaderContextMenuListener = () => {
3117
+ const vnodeProps = instance?.vnode.props;
3118
+ return !!(vnodeProps?.onHeaderContextMenu || vnodeProps?.onHeaderContextMenuOnce);
3119
+ };
2595
3120
  const entries = state.columns;
2596
3121
  const visibleColumns = computed(() => entries.value.map((e) => e.column));
3122
+ const { onContextMenu: onHeaderContextMenu } = useHeaderContextMenu({
3123
+ columns: () => visibleColumns.value,
3124
+ indexOf: (field) => entries.value.find((e) => e.column.field === field)?.index,
3125
+ listening: () => hasHeaderContextMenuListener(),
3126
+ onContextMenu: (payload) => emit("headerContextMenu", payload)
3127
+ });
2597
3128
  const hasPinned = state.hasPinned;
2598
3129
  /** Right panel first, then subtable, then selection (C-22: the first hosts clear-all). */
2599
3130
  const utilities = computed(() => [
@@ -2666,6 +3197,16 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2666
3197
  });
2667
3198
  /** `aria-rowindex` of the first footer row, or `undefined` (C-86). */
2668
3199
  const footerRowIndex = computed(() => !rowWindow.enabled() || growing() ? void 0 : 2 + props.rows.length + rowWindow.expandedCount());
3200
+ const flashView = useChangeFlash({
3201
+ flash: () => props.flash,
3202
+ rowsUpdate: () => props.rowsUpdate,
3203
+ rows: () => props.rows,
3204
+ query: () => props.query,
3205
+ loading: () => props.loading,
3206
+ fields: () => entries.value.map((entry) => entry.column.field),
3207
+ rowKey: () => props.rowKey,
3208
+ table: tableEl
3209
+ });
2669
3210
  const reorder = useColumnReorder({
2670
3211
  reorderable: () => props.reorderable,
2671
3212
  table: tableEl,
@@ -2720,7 +3261,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2720
3261
  class: "qt-table",
2721
3262
  "aria-rowcount": ariaRowCount.value
2722
3263
  }, [
2723
- createElementVNode("thead", null, [createVNode(table_header_default, {
3264
+ createElementVNode("thead", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onHeaderContextMenu) && unref(onHeaderContextMenu)(...args)) }, [createVNode(table_header_default, {
2724
3265
  columns: visibleColumns.value,
2725
3266
  query: __props.query,
2726
3267
  filterable: __props.filterable,
@@ -2743,7 +3284,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2743
3284
  "offsets",
2744
3285
  "slot-names",
2745
3286
  "aria-rowindex"
2746
- ])]),
3287
+ ])], 32),
2747
3288
  createVNode(table_body_default, {
2748
3289
  rows: __props.rows,
2749
3290
  "body-rows": unref(rowWindow).drawn.value,
@@ -2764,8 +3305,9 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2764
3305
  labels: labels.value,
2765
3306
  "has-context-menu-listener": hasContextMenuListener,
2766
3307
  "load-more": loadMoreProps.value,
2767
- onRowRightPanelClick: _cache[0] || (_cache[0] = (row) => emit("rowRightPanelClick", row)),
2768
- onCellContextMenu: _cache[1] || (_cache[1] = (payload) => emit("cellContextMenu", payload)),
3308
+ flash: unref(flashView),
3309
+ onRowRightPanelClick: _cache[1] || (_cache[1] = (row) => emit("rowRightPanelClick", row)),
3310
+ onCellContextMenu: _cache[2] || (_cache[2] = (payload) => emit("cellContextMenu", payload)),
2769
3311
  onFocusin: unref(rowWindow).onFocusIn,
2770
3312
  onFocusout: unref(rowWindow).onFocusOut
2771
3313
  }, createSlots({ _: 2 }, [renderList(bodySlotNames(), (name) => {
@@ -2792,6 +3334,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2792
3334
  "toggle",
2793
3335
  "labels",
2794
3336
  "load-more",
3337
+ "flash",
2795
3338
  "onFocusin",
2796
3339
  "onFocusout"
2797
3340
  ]),