@dolusoft/query-table 3.1.0 → 3.2.1

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,4 +1,4 @@
1
- import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createStaticVNode, createTextVNode, createVNode, defineComponent, getCurrentInstance, guardReactiveProps, h, inject, mergeProps, nextTick, normalizeProps, onBeforeUnmount, onScopeDispose, openBlock, provide, renderList, renderSlot, shallowRef, toDisplayString, toHandlers, toValue, unref, useSlots, watch, withCtx, withKeys, withModifiers } from "vue";
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";
2
2
  import { columnTypeOf, columnTypeOf as columnTypeOf$1, conditionLabel, conditionOptions, isCursorQuery, parseFilterInput as parseFilterInput$1, rulesOf, searchOf } from "@dolusoft/query-protocol";
3
3
  import { dispose, filterInputFeature, projectServerQuery, serverQueryFeature } from "@dolusoft/query-table-core";
4
4
  import { columnFilteringFeature, columnOrderingFeature, columnPinningFeature, columnVisibilityFeature, functionalUpdate, globalFilteringFeature, rowExpandingFeature, rowPaginationFeature, rowPinningFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable } from "@tanstack/vue-table";
@@ -89,6 +89,7 @@ var defaultLabels = {
89
89
  filterOptions: (column) => `Filter options for ${column}`,
90
90
  resizeColumn: (column) => `Resize ${column}`,
91
91
  moveColumn: (column) => `Move ${column}`,
92
+ filterCondition: (condition, type) => conditionLabel(type, condition),
92
93
  boolAll: "All",
93
94
  boolTrue: "True",
94
95
  boolFalse: "False",
@@ -131,6 +132,18 @@ var focusFilterOf = (table, field) => {
131
132
  }
132
133
  return false;
133
134
  };
135
+ /**
136
+ * Focuses the first filter of this table's header that takes the focus, in
137
+ * column order (C-22). Returns whether one did.
138
+ */
139
+ var focusFirstFilter = (table) => {
140
+ const head = [...table?.children ?? []].find((child) => child.tagName === "THEAD");
141
+ for (const row of head?.children ?? []) for (const cell of row.children) {
142
+ const field = cell.getAttribute("data-field");
143
+ if (field !== null && focusFilterOf(table, field)) return true;
144
+ }
145
+ return false;
146
+ };
134
147
  //#endregion
135
148
  //#region src/core/column.ts
136
149
  /** Reads a dotted path (`'a.b'`) from a row. */
@@ -163,8 +176,10 @@ var pinAttrs = (side, offset, width) => {
163
176
  var useCellView = (options) => {
164
177
  /** Text of a cell, whole: the table never cuts it. */
165
178
  const cellText = (row, column) => String(valueAt(row, column.field) ?? "");
179
+ const types = computed(() => new Map(options.entries().map((entry) => [entry.column.field, columnTypeOf$1(entry.column)])));
166
180
  const cellAttrs = (entry) => ({
167
181
  "data-field": entry.column.field,
182
+ "data-type": types.value.get(entry.column.field),
168
183
  ...pinAttrs(sideOf(entry.column), options.offsets()[entry.column.field])
169
184
  });
170
185
  /**
@@ -219,19 +234,21 @@ var useCellView = (options) => {
219
234
  };
220
235
  //#endregion
221
236
  //#region src/parts/table-body.vue?vue&type=script&setup=true&lang.ts
222
- var _hoisted_1$9 = [
237
+ var _hoisted_1$9 = ["colspan"];
238
+ var _hoisted_2$5 = [
223
239
  "data-row-index",
240
+ "aria-rowindex",
224
241
  "data-pinned-row",
225
242
  "data-expanded",
226
243
  "data-selected"
227
244
  ];
228
- var _hoisted_2$5 = ["aria-label", "onClick"];
229
- var _hoisted_3$4 = [
245
+ var _hoisted_3$5 = ["aria-label", "onClick"];
246
+ var _hoisted_4$4 = [
230
247
  "aria-expanded",
231
248
  "aria-label",
232
249
  "onClick"
233
250
  ];
234
- var _hoisted_4$3 = {
251
+ var _hoisted_5$1 = {
235
252
  width: "14",
236
253
  height: "14",
237
254
  viewBox: "0 0 24 24",
@@ -242,31 +259,36 @@ var _hoisted_4$3 = {
242
259
  "stroke-linejoin": "round",
243
260
  "aria-hidden": "true"
244
261
  };
245
- var _hoisted_5$1 = {
262
+ var _hoisted_6$1 = {
246
263
  key: 0,
247
264
  points: "6 9 12 15 18 9"
248
265
  };
249
- var _hoisted_6$1 = {
266
+ var _hoisted_7$1 = {
250
267
  key: 1,
251
268
  points: "9 6 15 12 9 18"
252
269
  };
253
- var _hoisted_7$1 = [
270
+ var _hoisted_8$1 = [
254
271
  "aria-label",
255
272
  "checked",
256
273
  "onChange"
257
274
  ];
258
- var _hoisted_8$1 = ["data-pinned-row"];
259
- var _hoisted_9$1 = ["colspan"];
260
- var _hoisted_10 = {
275
+ var _hoisted_9$1 = ["aria-rowindex", "data-pinned-row"];
276
+ var _hoisted_10 = ["colspan"];
277
+ var _hoisted_11 = {
261
278
  key: 0,
262
279
  class: "qt-loading-row"
263
280
  };
264
- var _hoisted_11 = ["colspan"];
265
- var _hoisted_12 = {
281
+ var _hoisted_12 = ["colspan"];
282
+ var _hoisted_13 = {
266
283
  key: 1,
267
284
  class: "qt-empty-row"
268
285
  };
269
- var _hoisted_13 = ["colspan"];
286
+ var _hoisted_14 = ["colspan"];
287
+ var _hoisted_15 = {
288
+ key: 2,
289
+ class: "qt-load-more-row"
290
+ };
291
+ var _hoisted_16 = ["colspan"];
270
292
  //#endregion
271
293
  //#region src/parts/table-body.vue
272
294
  var table_body_default = /* @__PURE__ */ defineComponent({
@@ -289,7 +311,8 @@ var table_body_default = /* @__PURE__ */ defineComponent({
289
311
  isExpanded: { type: Function },
290
312
  toggle: { type: Function },
291
313
  labels: {},
292
- hasContextMenuListener: { type: Function }
314
+ hasContextMenuListener: { type: Function },
315
+ loadMore: {}
293
316
  },
294
317
  emits: ["rowRightPanelClick", "cellContextMenu"],
295
318
  setup(__props, { emit: __emit }) {
@@ -309,88 +332,103 @@ var table_body_default = /* @__PURE__ */ defineComponent({
309
332
  const rightPanelAttrs = () => utilityAttrs("right-panel");
310
333
  const expandAttrs = () => utilityAttrs("subtable");
311
334
  const selectAttrs = () => utilityAttrs("select");
335
+ const isSpacer = (item) => "spacer" in item;
336
+ /** `aria-rowindex` of the subtable row under a drawn row (C-86). */
337
+ const nextIndex = (aria) => aria === void 0 ? void 0 : aria + 1;
312
338
  return (_ctx, _cache) => {
313
- return openBlock(), createElementBlock("tbody", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onContextMenu) && unref(onContextMenu)(...args)) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.bodyRows, ({ row, index: i, pinned }) => {
314
- return openBlock(), createElementBlock(Fragment, { key: __props.keyOf(row, i) }, [createElementVNode("tr", {
315
- "data-row-index": i,
316
- "data-pinned-row": pinned || void 0,
317
- "data-expanded": __props.isExpanded(row, i) ? "" : void 0,
318
- "data-selected": __props.hasSelection && __props.isSelected(row, i) ? "" : void 0
319
- }, [
320
- __props.hasRightPanel ? (openBlock(), createElementBlock("td", mergeProps({
339
+ return openBlock(), createElementBlock("tbody", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onContextMenu) && unref(onContextMenu)(...args)) }, [
340
+ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.bodyRows, (item) => {
341
+ return openBlock(), createElementBlock(Fragment, { key: isSpacer(item) ? item.key : __props.keyOf(item.row, item.index) }, [isSpacer(item) ? (openBlock(), createElementBlock("tr", {
321
342
  key: 0,
322
- ref_for: true
323
- }, rightPanelAttrs()), [createElementVNode("button", {
324
- type: "button",
325
- class: "qt-right-panel-button",
326
- "aria-label": __props.labels.openRightPanel,
327
- onClick: withModifiers(($event) => emit("rowRightPanelClick", row), ["stop"])
328
- }, [..._cache[1] || (_cache[1] = [createElementVNode("svg", {
329
- width: "14",
330
- height: "14",
331
- viewBox: "0 0 24 24",
332
- fill: "none",
333
- stroke: "currentColor",
334
- "stroke-width": "2",
335
- "stroke-linecap": "round",
336
- "aria-hidden": "true"
337
- }, [createElementVNode("line", {
338
- x1: "12",
339
- y1: "5",
340
- x2: "12",
341
- y2: "19"
342
- }), createElementVNode("line", {
343
- x1: "5",
344
- y1: "12",
345
- x2: "19",
346
- y2: "12"
347
- })], -1)])], 8, _hoisted_2$5)], 16)) : createCommentVNode("", true),
348
- __props.hasSubtable ? (openBlock(), createElementBlock("td", mergeProps({
349
- key: 1,
350
- ref_for: true
351
- }, expandAttrs()), [createElementVNode("button", {
352
- type: "button",
353
- class: "qt-expand",
354
- "aria-expanded": __props.isExpanded(row, i),
355
- "aria-label": __props.labels.expandRow,
356
- onClick: ($event) => __props.toggle(row, i)
357
- }, [(openBlock(), createElementBlock("svg", _hoisted_4$3, [__props.isExpanded(row, i) ? (openBlock(), createElementBlock("polyline", _hoisted_5$1)) : (openBlock(), createElementBlock("polyline", _hoisted_6$1))]))], 8, _hoisted_3$4)], 16)) : createCommentVNode("", true),
358
- __props.hasSelection ? (openBlock(), createElementBlock("td", mergeProps({
359
- key: 2,
360
- ref_for: true
361
- }, selectAttrs()), [createElementVNode("input", {
362
- type: "checkbox",
363
- class: "qt-select-row",
364
- "aria-label": __props.labels.selectRow,
365
- checked: __props.isSelected(row, i),
366
- onChange: ($event) => __props.toggleSelected(row, i)
367
- }, null, 40, _hoisted_7$1)], 16)) : createCommentVNode("", true),
368
- (openBlock(true), createElementBlock(Fragment, null, renderList(__props.entries, (entry) => {
369
- return openBlock(), createElementBlock(Fragment, { key: entry.column.field }, [unref(hasCellSlot)(entry.column) ? (openBlock(), createElementBlock("td", mergeProps({
343
+ class: "qt-virtual-spacer",
344
+ "aria-hidden": "true",
345
+ 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", {
347
+ "data-row-index": item.index,
348
+ "aria-rowindex": item.aria,
349
+ "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
352
+ }, [
353
+ __props.hasRightPanel ? (openBlock(), createElementBlock("td", mergeProps({
370
354
  key: 0,
371
355
  ref_for: true
372
- }, unref(cellAttrs)(entry)), [renderSlot(_ctx.$slots, `cell-${entry.column.field}`, mergeProps({ ref_for: true }, unref(slotProps)(row, entry.column, i, pinned)))], 16)) : (openBlock(), createElementBlock("td", mergeProps({
356
+ }, rightPanelAttrs()), [createElementVNode("button", {
357
+ type: "button",
358
+ class: "qt-right-panel-button",
359
+ "aria-label": __props.labels.openRightPanel,
360
+ onClick: withModifiers(($event) => emit("rowRightPanelClick", item.row), ["stop"])
361
+ }, [..._cache[1] || (_cache[1] = [createElementVNode("svg", {
362
+ width: "14",
363
+ height: "14",
364
+ viewBox: "0 0 24 24",
365
+ fill: "none",
366
+ stroke: "currentColor",
367
+ "stroke-width": "2",
368
+ "stroke-linecap": "round",
369
+ "aria-hidden": "true"
370
+ }, [createElementVNode("line", {
371
+ x1: "12",
372
+ y1: "5",
373
+ x2: "12",
374
+ y2: "19"
375
+ }), createElementVNode("line", {
376
+ x1: "5",
377
+ y1: "12",
378
+ x2: "19",
379
+ y2: "12"
380
+ })], -1)])], 8, _hoisted_3$5)], 16)) : createCommentVNode("", true),
381
+ __props.hasSubtable ? (openBlock(), createElementBlock("td", mergeProps({
373
382
  key: 1,
374
383
  ref_for: true
375
- }, unref(cellAttrs)(entry)), toDisplayString(unref(cellText)(row, entry.column)), 17))], 64);
376
- }), 128))
377
- ], 8, _hoisted_1$9), __props.isExpanded(row, i) ? (openBlock(), createElementBlock("tr", {
378
- key: 0,
379
- class: "qt-subtable-row",
380
- "data-pinned-row": pinned || void 0
381
- }, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "subtable", {
382
- row,
383
- rowIndex: i
384
- })], 8, _hoisted_9$1)], 8, _hoisted_8$1)) : createCommentVNode("", true)], 64);
385
- }), 128)), __props.loading && slots.loading ? (openBlock(), createElementBlock("tr", _hoisted_10, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "loading")], 8, _hoisted_11)])) : !__props.loading && __props.rows.length === 0 && slots.empty ? (openBlock(), createElementBlock("tr", _hoisted_12, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "empty")], 8, _hoisted_13)])) : createCommentVNode("", true)], 32);
384
+ }, expandAttrs()), [createElementVNode("button", {
385
+ type: "button",
386
+ class: "qt-expand",
387
+ "aria-expanded": __props.isExpanded(item.row, item.index),
388
+ "aria-label": __props.labels.expandRow,
389
+ 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),
391
+ __props.hasSelection ? (openBlock(), createElementBlock("td", mergeProps({
392
+ key: 2,
393
+ ref_for: true
394
+ }, selectAttrs()), [createElementVNode("input", {
395
+ type: "checkbox",
396
+ class: "qt-select-row",
397
+ "aria-label": __props.labels.selectRow,
398
+ checked: __props.isSelected(item.row, item.index),
399
+ onChange: ($event) => __props.toggleSelected(item.row, item.index)
400
+ }, null, 40, _hoisted_8$1)], 16)) : createCommentVNode("", true),
401
+ (openBlock(true), createElementBlock(Fragment, null, renderList(__props.entries, (entry) => {
402
+ return openBlock(), createElementBlock(Fragment, { key: entry.column.field }, [unref(hasCellSlot)(entry.column) ? (openBlock(), createElementBlock("td", mergeProps({
403
+ key: 0,
404
+ 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({
406
+ key: 1,
407
+ ref_for: true
408
+ }, unref(cellAttrs)(entry)), toDisplayString(unref(cellText)(item.row, entry.column)), 17))], 64);
409
+ }), 128))
410
+ ], 8, _hoisted_2$5), __props.isExpanded(item.row, item.index) ? (openBlock(), createElementBlock("tr", {
411
+ key: 0,
412
+ class: "qt-subtable-row",
413
+ "aria-rowindex": nextIndex(item.aria),
414
+ "data-pinned-row": item.pinned || void 0
415
+ }, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "subtable", {
416
+ row: item.row,
417
+ rowIndex: item.index
418
+ })], 8, _hoisted_10)], 8, _hoisted_9$1)) : createCommentVNode("", true)], 64))], 64);
419
+ }), 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)
422
+ ], 32);
386
423
  };
387
424
  }
388
425
  });
389
426
  //#endregion
390
427
  //#region src/parts/table-footer.vue?vue&type=script&setup=true&lang.ts
391
428
  var _hoisted_1$8 = { class: "qt-footer" };
392
- var _hoisted_2$4 = ["colspan"];
393
- var _hoisted_3$3 = ["data-field"];
429
+ var _hoisted_2$4 = ["aria-rowindex"];
430
+ var _hoisted_3$4 = ["colspan"];
431
+ var _hoisted_4$3 = ["data-field", "data-type"];
394
432
  //#endregion
395
433
  //#region src/parts/table-footer.vue
396
434
  var table_footer_default = /* @__PURE__ */ defineComponent({
@@ -400,21 +438,26 @@ var table_footer_default = /* @__PURE__ */ defineComponent({
400
438
  entries: {},
401
439
  utilityCount: {},
402
440
  hasPinned: { type: Boolean },
403
- offsets: {}
441
+ offsets: {},
442
+ firstRowIndex: {}
404
443
  },
405
444
  setup(__props) {
406
445
  const footerText = (row, column) => row.cells.find((cell) => cell.field === column.field)?.text;
407
446
  return (_ctx, _cache) => {
408
447
  return openBlock(), createElementBlock("tfoot", _hoisted_1$8, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.footerRows, (footerRow, i) => {
409
- return openBlock(), createElementBlock("tr", { key: i }, [__props.utilityCount > 0 ? (openBlock(), createElementBlock("td", mergeProps({
448
+ return openBlock(), createElementBlock("tr", {
449
+ key: i,
450
+ "aria-rowindex": __props.firstRowIndex === void 0 ? void 0 : __props.firstRowIndex + i
451
+ }, [__props.utilityCount > 0 ? (openBlock(), createElementBlock("td", mergeProps({
410
452
  key: 0,
411
453
  colspan: __props.utilityCount
412
- }, { ref_for: true }, unref(pinAttrs)(__props.hasPinned ? "left" : false, 0)), null, 16, _hoisted_2$4)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(__props.entries, (entry) => {
454
+ }, { 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) => {
413
455
  return openBlock(), createElementBlock("td", mergeProps({
414
456
  key: entry.column.field,
415
- "data-field": entry.column.field
416
- }, { ref_for: true }, unref(pinAttrs)(unref(sideOf)(entry.column), __props.offsets[entry.column.field])), toDisplayString(footerText(footerRow, entry.column)), 17, _hoisted_3$3);
417
- }), 128))]);
457
+ "data-field": entry.column.field,
458
+ "data-type": unref(columnTypeOf$1)(entry.column)
459
+ }, { ref_for: true }, unref(pinAttrs)(unref(sideOf)(entry.column), __props.offsets[entry.column.field])), toDisplayString(footerText(footerRow, entry.column)), 17, _hoisted_4$3);
460
+ }), 128))], 8, _hoisted_2$4);
418
461
  }), 128))]);
419
462
  };
420
463
  }
@@ -470,7 +513,7 @@ var useFilterTrigger = (options) => defineComponent({
470
513
  //#region src/parts/filter-cell.vue?vue&type=script&setup=true&lang.ts
471
514
  var _hoisted_1$6 = { class: "qt-filter" };
472
515
  var _hoisted_2$3 = ["aria-label", "value"];
473
- var _hoisted_3$2 = [
516
+ var _hoisted_3$3 = [
474
517
  "type",
475
518
  "aria-label",
476
519
  "value",
@@ -516,7 +559,7 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
516
559
  const labelOf = () => {
517
560
  const label = filters.labelOf(props.column.field);
518
561
  if (!label) return "";
519
- const text = conditionLabel(props.type, label.condition);
562
+ const text = labels().filterCondition(label.condition, props.type);
520
563
  return label.count > 1 ? `${text} (${label.count})` : text;
521
564
  };
522
565
  const inputText = () => {
@@ -530,7 +573,10 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
530
573
  column,
531
574
  rules: rulesOf(props.query.filters, column.field),
532
575
  condition: currentCondition(),
533
- conditions: conditionOptions[props.type],
576
+ conditions: conditionOptions[props.type].map(({ value }) => ({
577
+ value,
578
+ label: labels().filterCondition(value, props.type)
579
+ })),
534
580
  setCondition: (condition) => filters.setCondition(column.field, condition),
535
581
  clear: () => filters.clear(column.field),
536
582
  sortable: sort.isSortable(column),
@@ -569,7 +615,7 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
569
615
  readonly: unref(filters).multiOf(__props.column.field) > 0,
570
616
  onInput: _cache[2] || (_cache[2] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
571
617
  onKeydown: _cache[3] || (_cache[3] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
572
- }, null, 40, _hoisted_3$2)) : __props.type === "bool" ? (openBlock(), createElementBlock("select", {
618
+ }, null, 40, _hoisted_3$3)) : __props.type === "bool" ? (openBlock(), createElementBlock("select", {
573
619
  key: 2,
574
620
  class: "qt-filter-input",
575
621
  "aria-label": inputName(),
@@ -833,7 +879,7 @@ var _hoisted_2$2 = {
833
879
  viewBox: "0 0 16 16",
834
880
  "aria-hidden": "true"
835
881
  };
836
- var _hoisted_3$1 = {
882
+ var _hoisted_3$2 = {
837
883
  key: 1,
838
884
  class: "qt-sort-icon",
839
885
  width: "14",
@@ -868,7 +914,7 @@ var sort_button_default = /* @__PURE__ */ defineComponent({
868
914
  }, [createTextVNode(toDisplayString(__props.column.title) + " ", 1), __props.direction === "asc" ? (openBlock(), createElementBlock("svg", _hoisted_2$2, [..._cache[1] || (_cache[1] = [createElementVNode("path", {
869
915
  d: "M8 3.5L12.5 9.5H3.5L8 3.5Z",
870
916
  fill: "currentColor"
871
- }, null, -1)])])) : __props.direction === "desc" ? (openBlock(), createElementBlock("svg", _hoisted_3$1, [..._cache[2] || (_cache[2] = [createElementVNode("path", {
917
+ }, null, -1)])])) : __props.direction === "desc" ? (openBlock(), createElementBlock("svg", _hoisted_3$2, [..._cache[2] || (_cache[2] = [createElementVNode("path", {
872
918
  d: "M8 12.5L3.5 6.5H12.5L8 12.5Z",
873
919
  fill: "currentColor"
874
920
  }, null, -1)])])) : (openBlock(), createElementBlock("svg", _hoisted_4$1, [..._cache[3] || (_cache[3] = [createElementVNode("path", {
@@ -897,8 +943,9 @@ var _hoisted_2$1 = [
897
943
  "aria-label",
898
944
  "disabled"
899
945
  ];
900
- var _hoisted_3 = [
946
+ var _hoisted_3$1 = [
901
947
  "data-field",
948
+ "data-type",
902
949
  "data-sort",
903
950
  "data-sortable",
904
951
  "data-filtered",
@@ -933,6 +980,16 @@ var table_header_default = /* @__PURE__ */ defineComponent({
933
980
  };
934
981
  };
935
982
  const canClearAll = computed(() => filters.canClearAll());
983
+ const onClearAll = async (event) => {
984
+ const button = event.currentTarget;
985
+ const doc = button.ownerDocument;
986
+ const keyed = event.detail === 0 && doc.activeElement === button;
987
+ filters.clearAll();
988
+ if (!keyed) return;
989
+ await nextTick();
990
+ const active = doc.activeElement;
991
+ if (button.disabled && (active === button || active === doc.body || active === null)) focusFirstFilter(button.closest("table"));
992
+ };
936
993
  const isFiltered = (column) => rulesOf(props.query.filters, column.field).length > 0;
937
994
  const hasFilter = (column) => props.filterable && column.filterable !== false;
938
995
  const hostsClearAll = (utility) => props.filterable && utility === props.utilities.find((candidate) => candidate !== "select");
@@ -974,8 +1031,8 @@ var table_header_default = /* @__PURE__ */ defineComponent({
974
1031
  title: unref(labels)().clearAllFilters,
975
1032
  "aria-label": unref(labels)().clearAllFilters,
976
1033
  disabled: !canClearAll.value,
977
- onClick: _cache[1] || (_cache[1] = withModifiers(($event) => unref(filters).clearAll(), ["stop"]))
978
- }, [..._cache[2] || (_cache[2] = [createElementVNode("svg", {
1034
+ onClick: withModifiers(onClearAll, ["stop"])
1035
+ }, [..._cache[1] || (_cache[1] = [createElementVNode("svg", {
979
1036
  width: "14",
980
1037
  height: "14",
981
1038
  viewBox: "0 0 24 24",
@@ -1001,6 +1058,7 @@ var table_header_default = /* @__PURE__ */ defineComponent({
1001
1058
  key: column.field,
1002
1059
  scope: "col",
1003
1060
  "data-field": column.field,
1061
+ "data-type": unref(columnTypeOf$1)(column),
1004
1062
  "data-sort": unref(sort).sortOf(column) ?? void 0,
1005
1063
  "data-sortable": unref(sort).isSortable(column) ? "" : void 0,
1006
1064
  "data-filtered": isFiltered(column) ? "" : void 0,
@@ -1045,7 +1103,7 @@ var table_header_default = /* @__PURE__ */ defineComponent({
1045
1103
  key: 5,
1046
1104
  column
1047
1105
  }, null, 8, ["column"])) : createCommentVNode("", true)
1048
- ], 16, _hoisted_3);
1106
+ ], 16, _hoisted_3$1);
1049
1107
  }), 128))]);
1050
1108
  };
1051
1109
  }
@@ -1773,6 +1831,658 @@ function useQueryTable(options) {
1773
1831
  };
1774
1832
  }
1775
1833
  //#endregion
1834
+ //#region src/virtual/use-load-more.ts
1835
+ /**
1836
+ * Infinite scroll (C-88 to C-90): whether there is more to load, the
1837
+ * automatic request near the end of `rows` and `loadMore`. The rows are
1838
+ * the consumer's; the table only emits the next page action.
1839
+ */
1840
+ var useLoadMore = (o) => {
1841
+ const enabled = computed(() => !!o.infinite() && o.rowKey() !== void 0);
1842
+ const threshold = () => {
1843
+ const value = o.infinite();
1844
+ const given = typeof value === "object" ? value.threshold : void 0;
1845
+ return given !== void 0 && given >= 0 ? Math.trunc(given) : 5;
1846
+ };
1847
+ const canLoadMore = computed(() => {
1848
+ const query = o.query();
1849
+ if (isCursorQuery(query)) return !!o.cursors()?.next;
1850
+ const total = o.totalRows();
1851
+ return total !== null ? query.page < Math.max(1, Math.ceil(total / query.pageSize)) : o.rows().length >= query.page * query.pageSize;
1852
+ });
1853
+ const loadMore = () => {
1854
+ if (enabled.value && canLoadMore.value && !o.loading()) o.nextPage();
1855
+ };
1856
+ const seen = shallowRef(false);
1857
+ let observer = null;
1858
+ watch([
1859
+ enabled,
1860
+ o.virtual,
1861
+ o.rows,
1862
+ o.table
1863
+ ], () => {
1864
+ observer?.disconnect();
1865
+ observer = null;
1866
+ seen.value = false;
1867
+ const count = o.rows().length;
1868
+ const tbody = o.table.value?.tBodies[0];
1869
+ if (!enabled.value || o.virtual() || !tbody || count === 0 || typeof IntersectionObserver === "undefined") return;
1870
+ const others = tbody.querySelectorAll(":scope > tr[data-row-index]:not([data-pinned-row])");
1871
+ const target = others[Math.max(0, others.length - 1 - threshold())];
1872
+ if (target) {
1873
+ observer = new IntersectionObserver((entries) => {
1874
+ seen.value = entries.some((entry) => entry.isIntersecting);
1875
+ });
1876
+ observer.observe(target);
1877
+ }
1878
+ }, {
1879
+ flush: "post",
1880
+ immediate: true
1881
+ });
1882
+ onBeforeUnmount(() => observer?.disconnect());
1883
+ let asked = "";
1884
+ watchEffect(() => {
1885
+ if (!enabled.value || !canLoadMore.value || o.loading()) return;
1886
+ const range = o.window();
1887
+ if (!(o.virtual() ? range !== null && range.end >= range.count - threshold() : seen.value)) return;
1888
+ const signature = `${JSON.stringify(o.query())}#${o.rows().length}`;
1889
+ if (signature !== asked) {
1890
+ asked = signature;
1891
+ o.nextPage();
1892
+ }
1893
+ }, { flush: "post" });
1894
+ let warned = false;
1895
+ watchEffect(() => {
1896
+ if (!warned && o.infinite() && o.rowKey() === void 0) {
1897
+ warned = true;
1898
+ try {
1899
+ if (process.env.NODE_ENV === "production") return;
1900
+ } catch {}
1901
+ console.warn("[QueryTable] `infinite` needs `rowKey`; it is ignored without one (C-88).");
1902
+ }
1903
+ });
1904
+ return {
1905
+ enabled,
1906
+ canLoadMore,
1907
+ loadMore
1908
+ };
1909
+ };
1910
+ //#endregion
1911
+ //#region src/virtual/compute-window.ts
1912
+ /**
1913
+ * Fills `offsets` from `heights`, starting at position `from` (the offsets
1914
+ * before it are kept): `offsets[i + 1] = offsets[i] + heights[i]`.
1915
+ */
1916
+ var fillOffsets = (heights, offsets, from = 0) => {
1917
+ for (let i = from; i < heights.length; i++) offsets[i + 1] = offsets[i] + heights[i];
1918
+ };
1919
+ /**
1920
+ * The item that holds the point `y`: the last position whose top is at most
1921
+ * `y`, clamped to the items (0 for a point above them, the last item for a
1922
+ * point below them). `-1` when there is no item.
1923
+ */
1924
+ var indexAt = (offsets, y) => {
1925
+ let low = 0;
1926
+ let high = offsets.length - 2;
1927
+ if (high < 0) return -1;
1928
+ while (low < high) {
1929
+ const mid = low + high + 1 >> 1;
1930
+ if (offsets[mid] <= y) low = mid;
1931
+ else high = mid - 1;
1932
+ }
1933
+ return low;
1934
+ };
1935
+ /** The items to draw: the ones in view and `overscan` more on each side. */
1936
+ var computeWindow = ({ offsets, scrollTop, viewportHeight, overscan }) => {
1937
+ const count = offsets.length - 1;
1938
+ if (count <= 0) return {
1939
+ start: 0,
1940
+ end: 0
1941
+ };
1942
+ const first = indexAt(offsets, scrollTop);
1943
+ const bottom = scrollTop + Math.max(0, viewportHeight);
1944
+ let last = indexAt(offsets, bottom);
1945
+ if (last > first && offsets[last] >= bottom) last -= 1;
1946
+ return {
1947
+ start: Math.max(0, first - overscan),
1948
+ end: Math.min(count, last + 1 + overscan)
1949
+ };
1950
+ };
1951
+ /**
1952
+ * The body between the pinned rows: an upper spacer, the drawn items and a
1953
+ * lower spacer. A `kept` item outside the range (it holds the focus, C-86)
1954
+ * is drawn on its own, with a spacer of its own between it and the range.
1955
+ * Spacers of height 0 are left out. `slot` names a spacer's place, so a
1956
+ * spacer keeps its identity while its height changes.
1957
+ */
1958
+ var segmentsOf = (offsets, range, kept) => {
1959
+ const count = offsets.length - 1;
1960
+ const total = count > 0 ? offsets[count] : 0;
1961
+ const out = [];
1962
+ const spacer = (height, slot) => {
1963
+ if (height > 0) out.push({
1964
+ spacer: height,
1965
+ slot
1966
+ });
1967
+ };
1968
+ const run = (from, to) => {
1969
+ if (to > from) out.push({
1970
+ from,
1971
+ to
1972
+ });
1973
+ };
1974
+ const { start, end } = range;
1975
+ if (kept !== null && kept >= 0 && kept < start) {
1976
+ spacer(offsets[kept], 0);
1977
+ run(kept, kept + 1);
1978
+ spacer(offsets[start] - offsets[kept + 1], 1);
1979
+ run(start, end);
1980
+ spacer(total - offsets[end], 2);
1981
+ } else if (kept !== null && kept >= end && kept < count) {
1982
+ spacer(offsets[start], 0);
1983
+ run(start, end);
1984
+ spacer(offsets[kept] - offsets[end], 1);
1985
+ run(kept, kept + 1);
1986
+ spacer(total - offsets[kept + 1], 2);
1987
+ } else {
1988
+ spacer(offsets[start], 0);
1989
+ run(start, end);
1990
+ spacer(total - offsets[end], 2);
1991
+ }
1992
+ return out;
1993
+ };
1994
+ //#endregion
1995
+ //#region src/virtual/use-row-window.ts
1996
+ var isDevelopment = () => {
1997
+ try {
1998
+ return process.env.NODE_ENV !== "production";
1999
+ } catch {
2000
+ return true;
2001
+ }
2002
+ };
2003
+ /** One identity per spacer place: above, between, below (`segmentsOf`). */
2004
+ var spacerKeys = [
2005
+ Symbol("above"),
2006
+ Symbol("between"),
2007
+ Symbol("below")
2008
+ ];
2009
+ /**
2010
+ * The virtual body (C-83 to C-87): which rows are drawn, the spacers that
2011
+ * stand for the others, the measured heights, the focused row kept drawn,
2012
+ * printing and `scrollToIndex`. Without `virtual` it draws `bodyRows` as
2013
+ * they are and touches no DOM.
2014
+ */
2015
+ var useRowWindow = (o) => {
2016
+ const settings = computed((previous) => {
2017
+ const value = o.virtual();
2018
+ const next = value === true ? {} : value || null;
2019
+ return previous && next && previous.overscan === next.overscan && previous.rowHeight === next.rowHeight && previous.estimateRowHeight === next.estimateRowHeight && previous.scrollElement === next.scrollElement ? previous : next;
2020
+ });
2021
+ const enabled = () => settings.value !== null;
2022
+ const overscan = () => Math.max(0, settings.value?.overscan ?? 10);
2023
+ const fixed = () => settings.value?.rowHeight;
2024
+ /** Pinned rows sit at both ends of `bodyRows`; the window is the middle. */
2025
+ const parts = computed(() => {
2026
+ const all = o.bodyRows();
2027
+ let top = 0;
2028
+ while (top < all.length && all[top].pinned === "top") top++;
2029
+ let bottom = all.length;
2030
+ while (bottom > top && all[bottom - 1].pinned === "bottom") bottom--;
2031
+ return {
2032
+ all,
2033
+ top,
2034
+ center: top === 0 && bottom === all.length ? all : all.slice(top, bottom)
2035
+ };
2036
+ });
2037
+ const center = () => parts.value.center;
2038
+ /** Position of a row index among the center rows (ascending), or -1. */
2039
+ const positionOf = (index) => {
2040
+ const rows = center();
2041
+ if (rows[index]?.index === index) return index;
2042
+ let low = 0;
2043
+ let high = rows.length - 1;
2044
+ while (low <= high) {
2045
+ const mid = low + high >> 1;
2046
+ const at = rows[mid].index;
2047
+ if (at === index) return mid;
2048
+ if (at < index) low = mid + 1;
2049
+ else high = mid - 1;
2050
+ }
2051
+ return -1;
2052
+ };
2053
+ let heights = /* @__PURE__ */ new Float64Array(0);
2054
+ let measured = /* @__PURE__ */ new Uint8Array(0);
2055
+ let offsets = /* @__PURE__ */ new Float64Array(1);
2056
+ let byKey = /* @__PURE__ */ new Map();
2057
+ /** The first measured height, the estimate when none is given. */
2058
+ let firstMeasured = 0;
2059
+ /** Bumped whenever `offsets` change, so the spacers are drawn again. */
2060
+ const version = shallowRef(0);
2061
+ const estimate = () => fixed() ?? settings.value?.estimateRowHeight ?? (firstMeasured || 32);
2062
+ const rebuild = () => {
2063
+ const rows = enabled() ? center() : [];
2064
+ const height = fixed();
2065
+ heights = new Float64Array(rows.length);
2066
+ measured = new Uint8Array(rows.length);
2067
+ const kept = /* @__PURE__ */ new Map();
2068
+ for (let i = 0; i < rows.length; i++) {
2069
+ if (height !== void 0) {
2070
+ heights[i] = height;
2071
+ continue;
2072
+ }
2073
+ const key = o.keyOf(rows[i].row, rows[i].index);
2074
+ const known = byKey.get(key);
2075
+ if (known === void 0) heights[i] = estimate();
2076
+ else {
2077
+ kept.set(key, known);
2078
+ heights[i] = known;
2079
+ measured[i] = 1;
2080
+ }
2081
+ }
2082
+ byKey = kept;
2083
+ pending = null;
2084
+ offsets = new Float64Array(rows.length + 1);
2085
+ fillOffsets(heights, offsets);
2086
+ version.value++;
2087
+ };
2088
+ const body = () => o.table.value?.tBodies[0] ?? null;
2089
+ /** The drawn data row at a center position. */
2090
+ const rowElement = (tbody, position) => {
2091
+ const row = center()[position];
2092
+ return row ? tbody.querySelector(`:scope > tr[data-row-index="${row.index}"]:not([data-pinned-row])`) : null;
2093
+ };
2094
+ /** Height of a drawn item: its row and its subtable row. */
2095
+ const itemHeight = (tr) => {
2096
+ const next = tr.nextElementSibling;
2097
+ return tr.getBoundingClientRect().height + (next?.classList.contains("qt-subtable-row") ? next.getBoundingClientRect().height : 0);
2098
+ };
2099
+ /** Reads the drawn items; `true` when a height changed. */
2100
+ const measure = (tbody) => {
2101
+ if (fixed() !== void 0) return false;
2102
+ const rows = center();
2103
+ let from = -1;
2104
+ for (const tr of tbody.children) {
2105
+ const at = tr.getAttribute("data-row-index");
2106
+ if (at === null || tr.hasAttribute("data-pinned-row")) continue;
2107
+ const position = positionOf(Number(at));
2108
+ if (position < 0) continue;
2109
+ const height = itemHeight(tr);
2110
+ if (!firstMeasured && height > 0 && settings.value?.estimateRowHeight === void 0) {
2111
+ firstMeasured = height;
2112
+ for (let i = 0; i < heights.length; i++) if (!measured[i]) heights[i] = height;
2113
+ from = 0;
2114
+ }
2115
+ if (!measured[position] || Math.abs(heights[position] - height) > .5) {
2116
+ heights[position] = height;
2117
+ measured[position] = 1;
2118
+ byKey.set(o.keyOf(rows[position].row, rows[position].index), height);
2119
+ from = from < 0 ? position : Math.min(from, position);
2120
+ }
2121
+ }
2122
+ if (from >= 0) {
2123
+ fillOffsets(heights, offsets, from);
2124
+ version.value++;
2125
+ return true;
2126
+ }
2127
+ return false;
2128
+ };
2129
+ const range = shallowRef({
2130
+ start: 0,
2131
+ end: Math.ceil((globalThis.innerHeight || 800) / 32) + 10
2132
+ });
2133
+ /** The window was computed from the layout at least once. */
2134
+ const ready = shallowRef(false);
2135
+ let container = null;
2136
+ let frame = 0;
2137
+ /** The first visible item and its top before the window moved (C-84). */
2138
+ let anchor = null;
2139
+ /**
2140
+ * The container's scroll position the window was computed for. The
2141
+ * browser's own scroll anchoring may move it when the drawn rows change
2142
+ * (it anchors to a spacer when no row is in view); it is put back.
2143
+ */
2144
+ let expected = null;
2145
+ /** A `scrollToIndex` to correct once its row is drawn (C-87). */
2146
+ let pending = null;
2147
+ /** Frames a `scrollToIndex` waits for its row before it is given up. */
2148
+ const pendingFrames = 6;
2149
+ const viewport = () => {
2150
+ if (container === null || container === window) return {
2151
+ top: 0,
2152
+ height: globalThis.innerHeight
2153
+ };
2154
+ const element = container;
2155
+ return {
2156
+ top: element.getBoundingClientRect().top + element.clientTop,
2157
+ height: element.clientHeight
2158
+ };
2159
+ };
2160
+ /** Client top of the first center item: below the top-pinned rows. */
2161
+ const itemsTop = (tbody) => {
2162
+ for (const tr of tbody.children) if (tr.getAttribute("data-pinned-row") !== "top") return tr.getBoundingClientRect().top;
2163
+ return tbody.getBoundingClientRect().bottom;
2164
+ };
2165
+ const scrollTopOf = (target) => target === window ? window.scrollY : target.scrollTop;
2166
+ const scrollBy = (delta) => {
2167
+ if (Math.abs(delta) < 1 || !container) return;
2168
+ container.scrollTo({
2169
+ top: scrollTopOf(container) + delta,
2170
+ behavior: "instant"
2171
+ });
2172
+ };
2173
+ /** How far to scroll to show an item at `top` (client) with `height`. */
2174
+ const alignDelta = (top, height, align) => {
2175
+ const view = viewport();
2176
+ const head = o.table.value?.tHead?.getBoundingClientRect();
2177
+ const cover = head && head.top <= view.top + 1 && head.bottom > view.top ? head.bottom - view.top : 0;
2178
+ const viewTop = view.top + cover;
2179
+ const viewBottom = view.top + view.height;
2180
+ const bottom = top + height;
2181
+ switch (align) {
2182
+ case "start": return top - viewTop;
2183
+ case "end": return bottom - viewBottom;
2184
+ case "center": return (top + bottom - viewTop - viewBottom) / 2;
2185
+ default: return top < viewTop ? top - viewTop : bottom > viewBottom ? bottom - viewBottom : 0;
2186
+ }
2187
+ };
2188
+ /** After a render: correct the drift (C-84) or a `scrollToIndex` (C-87). */
2189
+ const settle = () => {
2190
+ const tbody = body();
2191
+ if (!tbody) return;
2192
+ if (expected !== null && container) {
2193
+ scrollBy(expected - scrollTopOf(container));
2194
+ expected = null;
2195
+ }
2196
+ if (pending) {
2197
+ const tr = rowElement(tbody, pending.position);
2198
+ if (tr) {
2199
+ const { align } = pending;
2200
+ pending = null;
2201
+ scrollBy(alignDelta(tr.getBoundingClientRect().top, itemHeight(tr), align));
2202
+ return;
2203
+ }
2204
+ if (++pending.tries <= pendingFrames) {
2205
+ schedule();
2206
+ return;
2207
+ }
2208
+ pending = null;
2209
+ }
2210
+ if (anchor) {
2211
+ const tr = rowElement(tbody, anchor.position);
2212
+ if (tr) scrollBy(tr.getBoundingClientRect().top - anchor.top);
2213
+ anchor = null;
2214
+ }
2215
+ };
2216
+ const update = () => {
2217
+ frame = 0;
2218
+ const tbody = body();
2219
+ if (!tbody || !container || printing.value) return;
2220
+ measure(tbody);
2221
+ const view = viewport();
2222
+ const scrollTop = view.top - itemsTop(tbody);
2223
+ const next = computeWindow({
2224
+ offsets,
2225
+ scrollTop,
2226
+ viewportHeight: view.height,
2227
+ overscan: overscan()
2228
+ });
2229
+ ready.value = true;
2230
+ const current = range.value;
2231
+ if (next.start === current.start && next.end === current.end) {
2232
+ settle();
2233
+ return;
2234
+ }
2235
+ if (!pending && fixed() === void 0) {
2236
+ const position = Math.min(Math.max(indexAt(offsets, scrollTop), current.start), current.end - 1);
2237
+ const tr = position < 0 ? null : rowElement(tbody, position);
2238
+ anchor = tr ? {
2239
+ position,
2240
+ top: tr.getBoundingClientRect().top
2241
+ } : null;
2242
+ }
2243
+ expected = scrollTopOf(container);
2244
+ range.value = next;
2245
+ };
2246
+ const schedule = () => {
2247
+ if (!frame) frame = requestAnimationFrame(update);
2248
+ };
2249
+ const printing = shallowRef(false);
2250
+ const startPrint = () => {
2251
+ printing.value = true;
2252
+ };
2253
+ const endPrint = () => {
2254
+ printing.value = false;
2255
+ schedule();
2256
+ };
2257
+ const onPrintMedia = (event) => {
2258
+ if (event.matches) startPrint();
2259
+ else endPrint();
2260
+ };
2261
+ let printMedia = null;
2262
+ const kept = shallowRef(null);
2263
+ /** The row index of the item (data row or subtable row) holding `target`. */
2264
+ const itemOf = (target, tbody) => {
2265
+ let tr = target?.closest?.("tr") ?? null;
2266
+ while (tr && tr.parentElement !== tbody) tr = tr.parentElement?.closest("tr") ?? null;
2267
+ if (tr?.classList.contains("qt-subtable-row")) tr = tr.previousElementSibling;
2268
+ const at = tr?.getAttribute("data-row-index");
2269
+ return !tr || at === null || at === void 0 || tr.hasAttribute("data-pinned-row") ? -1 : positionOf(Number(at));
2270
+ };
2271
+ const onFocusIn = (event) => {
2272
+ if (!enabled()) return;
2273
+ const position = itemOf(event.target, event.currentTarget);
2274
+ if (position >= 0) kept.value = {
2275
+ row: center()[position].row,
2276
+ position
2277
+ };
2278
+ };
2279
+ const onFocusOut = (event) => {
2280
+ if (kept.value && itemOf(event.relatedTarget, event.currentTarget) !== kept.value.position) kept.value = null;
2281
+ };
2282
+ const keptPosition = () => {
2283
+ const focus = kept.value;
2284
+ if (!focus) return null;
2285
+ const rows = center();
2286
+ if (rows[focus.position]?.row === focus.row) return focus.position;
2287
+ const found = rows.findIndex((row) => row.row === focus.row);
2288
+ return found < 0 ? null : found;
2289
+ };
2290
+ /** Open subtable rows before each row of `bodyRows`, and in all (C-86). */
2291
+ const expandedBefore = computed(() => {
2292
+ const all = enabled() ? parts.value.all : [];
2293
+ const counts = new Int32Array(all.length + 1);
2294
+ for (let i = 0; i < all.length; i++) counts[i + 1] = counts[i] + (o.isExpanded(all[i].row, all[i].index) ? 1 : 0);
2295
+ return counts;
2296
+ });
2297
+ const drawn = computed(() => {
2298
+ const { all, top } = parts.value;
2299
+ if (!enabled()) return all;
2300
+ version.value;
2301
+ const rows = center();
2302
+ const before = expandedBefore.value;
2303
+ const at = (q) => ({
2304
+ ...all[q],
2305
+ aria: q + before[q] + 2
2306
+ });
2307
+ const out = [];
2308
+ for (let q = 0; q < top; q++) out.push(at(q));
2309
+ if (printing.value) for (let p = 0; p < rows.length; p++) out.push(at(top + p));
2310
+ else {
2311
+ const end = Math.min(range.value.end, rows.length);
2312
+ const win = {
2313
+ start: Math.min(range.value.start, end),
2314
+ end
2315
+ };
2316
+ for (const segment of segmentsOf(offsets, win, keptPosition())) if ("spacer" in segment) out.push({
2317
+ spacer: segment.spacer,
2318
+ key: spacerKeys[segment.slot]
2319
+ });
2320
+ else for (let p = segment.from; p < segment.to; p++) out.push(at(top + p));
2321
+ }
2322
+ for (let q = top + rows.length; q < all.length; q++) out.push(at(q));
2323
+ return out;
2324
+ });
2325
+ let box = null;
2326
+ let rowsObserver = null;
2327
+ /**
2328
+ * Watches the table for coming into the layout: a table mounted inside
2329
+ * `display: none` has no scrolling ancestor yet, so the container is
2330
+ * looked for again once it has a size.
2331
+ */
2332
+ let shown = null;
2333
+ let hadSize = false;
2334
+ let watchedTable = null;
2335
+ const watchShown = (table) => {
2336
+ if (table === watchedTable) return;
2337
+ shown?.disconnect();
2338
+ shown = null;
2339
+ watchedTable = table;
2340
+ if (!table || typeof ResizeObserver === "undefined") return;
2341
+ hadSize = table.getBoundingClientRect().height > 0;
2342
+ shown = new ResizeObserver(() => {
2343
+ const hasSize = table.getBoundingClientRect().height > 0;
2344
+ if (hasSize !== hadSize) {
2345
+ hadSize = hasSize;
2346
+ if (hasSize) attach();
2347
+ }
2348
+ });
2349
+ shown.observe(table);
2350
+ };
2351
+ const observed = /* @__PURE__ */ new Set();
2352
+ let warned = false;
2353
+ const findContainer = (table) => {
2354
+ const given = settings.value?.scrollElement?.();
2355
+ if (given) return given;
2356
+ for (let element = table.parentElement; element && element !== document.body && element !== document.documentElement; element = element.parentElement) {
2357
+ const overflow = getComputedStyle(element).overflowY;
2358
+ if ((overflow === "auto" || overflow === "scroll") && element.scrollHeight > element.clientHeight) return element;
2359
+ }
2360
+ return window;
2361
+ };
2362
+ const detach = () => {
2363
+ container?.removeEventListener("scroll", schedule);
2364
+ container = null;
2365
+ box?.disconnect();
2366
+ box = null;
2367
+ removeEventListener("resize", schedule);
2368
+ };
2369
+ const attach = () => {
2370
+ const table = o.table.value;
2371
+ if (!table || !enabled()) {
2372
+ watchShown(null);
2373
+ detach();
2374
+ return;
2375
+ }
2376
+ watchShown(table);
2377
+ const next = findContainer(table);
2378
+ if (next !== container) {
2379
+ detach();
2380
+ container = next;
2381
+ next.addEventListener("scroll", schedule, { passive: true });
2382
+ addEventListener("resize", schedule);
2383
+ if (next !== window && typeof ResizeObserver !== "undefined") {
2384
+ box = new ResizeObserver(schedule);
2385
+ box.observe(next);
2386
+ }
2387
+ }
2388
+ if (!warned && isDevelopment() && getComputedStyle(table).tableLayout !== "fixed") {
2389
+ warned = true;
2390
+ console.warn("[QueryTable] `virtual` with `table-layout: auto`: column widths follow the drawn rows. Set `table-layout: fixed` (C-85).");
2391
+ }
2392
+ schedule();
2393
+ };
2394
+ /** Watches the drawn rows for size changes; measured on the next frame. */
2395
+ const observeRows = () => {
2396
+ const tbody = body();
2397
+ if (!tbody || !enabled() || fixed() !== void 0 || typeof ResizeObserver === "undefined") {
2398
+ rowsObserver?.disconnect();
2399
+ observed.clear();
2400
+ return;
2401
+ }
2402
+ rowsObserver ??= new ResizeObserver(schedule);
2403
+ for (const element of observed) if (element.parentElement !== tbody) {
2404
+ rowsObserver.unobserve(element);
2405
+ observed.delete(element);
2406
+ }
2407
+ for (const tr of tbody.children) if (!observed.has(tr) && !tr.classList.contains("qt-virtual-spacer")) {
2408
+ rowsObserver.observe(tr);
2409
+ observed.add(tr);
2410
+ }
2411
+ };
2412
+ watch([
2413
+ () => parts.value.center,
2414
+ () => settings.value?.rowHeight,
2415
+ () => settings.value?.estimateRowHeight,
2416
+ enabled
2417
+ ], rebuild, { immediate: true });
2418
+ watch([
2419
+ () => o.table.value,
2420
+ enabled,
2421
+ () => settings.value?.scrollElement,
2422
+ () => parts.value.center
2423
+ ], attach, {
2424
+ flush: "post",
2425
+ immediate: true
2426
+ });
2427
+ watch(drawn, () => {
2428
+ observeRows();
2429
+ settle();
2430
+ }, { flush: "post" });
2431
+ watch(enabled, (on) => {
2432
+ printMedia?.removeEventListener("change", onPrintMedia);
2433
+ removeEventListener("beforeprint", startPrint);
2434
+ removeEventListener("afterprint", endPrint);
2435
+ printMedia = null;
2436
+ if (on && typeof window !== "undefined") {
2437
+ addEventListener("beforeprint", startPrint);
2438
+ addEventListener("afterprint", endPrint);
2439
+ printMedia = window.matchMedia?.("print") ?? null;
2440
+ printMedia?.addEventListener("change", onPrintMedia);
2441
+ }
2442
+ }, { immediate: true });
2443
+ onBeforeUnmount(() => {
2444
+ detach();
2445
+ watchShown(null);
2446
+ cancelAnimationFrame(frame);
2447
+ rowsObserver?.disconnect();
2448
+ printMedia?.removeEventListener("change", onPrintMedia);
2449
+ removeEventListener("beforeprint", startPrint);
2450
+ removeEventListener("afterprint", endPrint);
2451
+ });
2452
+ const scrollToIndex = (index, options = {}) => {
2453
+ const align = options.align ?? "auto";
2454
+ const tbody = body();
2455
+ if (!tbody || !Number.isInteger(index) || index < 0) return;
2456
+ const position = enabled() && container && !printing.value ? positionOf(index) : -1;
2457
+ if (position < 0) {
2458
+ tbody.querySelector(`:scope > tr[data-row-index="${index}"]`)?.scrollIntoView({
2459
+ block: align === "auto" ? "nearest" : align,
2460
+ behavior: "instant"
2461
+ });
2462
+ return;
2463
+ }
2464
+ anchor = null;
2465
+ pending = {
2466
+ position,
2467
+ align,
2468
+ tries: 0
2469
+ };
2470
+ scrollBy(alignDelta(itemsTop(tbody) + offsets[position], heights[position], align));
2471
+ schedule();
2472
+ };
2473
+ return {
2474
+ enabled,
2475
+ drawn,
2476
+ range,
2477
+ ready,
2478
+ centerCount: () => center().length,
2479
+ expandedCount: () => expandedBefore.value[expandedBefore.value.length - 1],
2480
+ scrollToIndex,
2481
+ onFocusIn,
2482
+ onFocusOut
2483
+ };
2484
+ };
2485
+ //#endregion
1776
2486
  //#region src/query-table.vue?vue&type=script&setup=true&lang.ts
1777
2487
  var _hoisted_1 = [
1778
2488
  "data-empty",
@@ -1780,6 +2490,7 @@ var _hoisted_1 = [
1780
2490
  "aria-busy"
1781
2491
  ];
1782
2492
  var _hoisted_2 = { class: "qt-table-responsive" };
2493
+ var _hoisted_3 = ["aria-rowcount"];
1783
2494
  //#endregion
1784
2495
  //#region src/query-table.vue
1785
2496
  var query_table_default = /* @__PURE__ */ defineComponent({
@@ -1829,7 +2540,15 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1829
2540
  type: [String, Function],
1830
2541
  default: void 0
1831
2542
  },
1832
- labels: { default: void 0 }
2543
+ labels: { default: void 0 },
2544
+ virtual: {
2545
+ type: [Boolean, Object],
2546
+ default: false
2547
+ },
2548
+ infinite: {
2549
+ type: [Boolean, Object],
2550
+ default: false
2551
+ }
1833
2552
  },
1834
2553
  emits: [
1835
2554
  "update:query",
@@ -1908,6 +2627,45 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1908
2627
  if (next) emit("update:columns", next, "resize");
1909
2628
  }
1910
2629
  });
2630
+ const rowWindow = useRowWindow({
2631
+ virtual: () => props.virtual,
2632
+ table: tableEl,
2633
+ bodyRows: () => state.rowPinning.rows.value,
2634
+ keyOf: expansion.keyOf,
2635
+ isExpanded: expansion.isExpanded
2636
+ });
2637
+ const infinite = useLoadMore({
2638
+ infinite: () => props.infinite,
2639
+ rowKey: () => props.rowKey,
2640
+ rows: () => props.rows,
2641
+ query: () => props.query,
2642
+ totalRows: () => props.totalRows,
2643
+ cursors: () => props.cursors,
2644
+ loading: () => props.loading,
2645
+ nextPage: () => paginationProps.value.nextPage(),
2646
+ table: tableEl,
2647
+ virtual: rowWindow.enabled,
2648
+ window: () => rowWindow.ready.value ? {
2649
+ end: rowWindow.range.value.end,
2650
+ count: rowWindow.centerCount()
2651
+ } : null
2652
+ });
2653
+ const loadMoreProps = computed(() => infinite.enabled.value ? {
2654
+ loadMore: infinite.loadMore,
2655
+ canLoadMore: infinite.canLoadMore.value,
2656
+ loading: props.loading
2657
+ } : null);
2658
+ const footerCount = computed(() => props.footerRows.length);
2659
+ /** More to load in an infinite list: the count is not the rows given (C-86). */
2660
+ const growing = () => infinite.enabled.value && infinite.canLoadMore.value;
2661
+ const ariaRowCount = computed(() => {
2662
+ if (!rowWindow.enabled()) return;
2663
+ const total = props.totalRows;
2664
+ if (growing() && total === null) return -1;
2665
+ return 1 + (growing() && total !== null ? total : props.rows.length) + rowWindow.expandedCount() + footerCount.value;
2666
+ });
2667
+ /** `aria-rowindex` of the first footer row, or `undefined` (C-86). */
2668
+ const footerRowIndex = computed(() => !rowWindow.enabled() || growing() ? void 0 : 2 + props.rows.length + rowWindow.expandedCount());
1911
2669
  const reorder = useColumnReorder({
1912
2670
  reorderable: () => props.reorderable,
1913
2671
  table: tableEl,
@@ -1936,7 +2694,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1936
2694
  search.apply();
1937
2695
  }
1938
2696
  });
1939
- const bodySlotNames = () => Object.keys(rawSlots).filter((name) => name.startsWith("cell-") || name === "subtable" || name === "empty" || name === "loading");
2697
+ const bodySlotNames = () => Object.keys(rawSlots).filter((name) => name.startsWith("cell-") || name === "subtable" || name === "empty" || name === "loading" || name === "load-more");
1940
2698
  const headerSlotNames = () => Object.keys(rawSlots).filter((name) => name.startsWith("header-") || name === "filter-datetime" || name === "filter-menu").sort().join(" ");
1941
2699
  __expose({
1942
2700
  collapseAll: expansion.collapseAll,
@@ -1944,7 +2702,9 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1944
2702
  focusFilter: (field) => focusFilterOf(tableEl.value, field),
1945
2703
  flushPendingFilters: () => {
1946
2704
  filters.flushAll();
1947
- }
2705
+ },
2706
+ scrollToIndex: rowWindow.scrollToIndex,
2707
+ loadMore: infinite.loadMore
1948
2708
  });
1949
2709
  return (_ctx, _cache) => {
1950
2710
  return openBlock(), createElementBlock("div", {
@@ -1957,7 +2717,8 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1957
2717
  createElementVNode("div", _hoisted_2, [createElementVNode("table", {
1958
2718
  ref_key: "tableEl",
1959
2719
  ref: tableEl,
1960
- class: "qt-table"
2720
+ class: "qt-table",
2721
+ "aria-rowcount": ariaRowCount.value
1961
2722
  }, [
1962
2723
  createElementVNode("thead", null, [createVNode(table_header_default, {
1963
2724
  columns: visibleColumns.value,
@@ -1966,7 +2727,8 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1966
2727
  utilities: utilities.value,
1967
2728
  "has-pinned": unref(hasPinned),
1968
2729
  offsets: unref(offsets),
1969
- "slot-names": headerSlotNames()
2730
+ "slot-names": headerSlotNames(),
2731
+ "aria-rowindex": unref(rowWindow).enabled() ? 1 : void 0
1970
2732
  }, {
1971
2733
  header: withCtx((p) => [renderSlot(_ctx.$slots, `header-${p.column.field}`, normalizeProps(guardReactiveProps(p)))]),
1972
2734
  "filter-datetime": withCtx((p) => [renderSlot(_ctx.$slots, "filter-datetime", normalizeProps(guardReactiveProps(p)))]),
@@ -1979,11 +2741,12 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1979
2741
  "utilities",
1980
2742
  "has-pinned",
1981
2743
  "offsets",
1982
- "slot-names"
2744
+ "slot-names",
2745
+ "aria-rowindex"
1983
2746
  ])]),
1984
2747
  createVNode(table_body_default, {
1985
2748
  rows: __props.rows,
1986
- "body-rows": unref(state).rowPinning.rows.value,
2749
+ "body-rows": unref(rowWindow).drawn.value,
1987
2750
  "pin-row": unref(state).rowPinning.pin,
1988
2751
  loading: __props.loading,
1989
2752
  entries: unref(entries),
@@ -2000,8 +2763,11 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2000
2763
  toggle: unref(expansion).toggle,
2001
2764
  labels: labels.value,
2002
2765
  "has-context-menu-listener": hasContextMenuListener,
2766
+ "load-more": loadMoreProps.value,
2003
2767
  onRowRightPanelClick: _cache[0] || (_cache[0] = (row) => emit("rowRightPanelClick", row)),
2004
- onCellContextMenu: _cache[1] || (_cache[1] = (payload) => emit("cellContextMenu", payload))
2768
+ onCellContextMenu: _cache[1] || (_cache[1] = (payload) => emit("cellContextMenu", payload)),
2769
+ onFocusin: unref(rowWindow).onFocusIn,
2770
+ onFocusout: unref(rowWindow).onFocusOut
2005
2771
  }, createSlots({ _: 2 }, [renderList(bodySlotNames(), (name) => {
2006
2772
  return {
2007
2773
  name,
@@ -2024,7 +2790,10 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2024
2790
  "key-of",
2025
2791
  "is-expanded",
2026
2792
  "toggle",
2027
- "labels"
2793
+ "labels",
2794
+ "load-more",
2795
+ "onFocusin",
2796
+ "onFocusout"
2028
2797
  ]),
2029
2798
  __props.footerRows.length > 0 ? (openBlock(), createBlock(table_footer_default, {
2030
2799
  key: 0,
@@ -2032,15 +2801,17 @@ var query_table_default = /* @__PURE__ */ defineComponent({
2032
2801
  entries: unref(entries),
2033
2802
  "utility-count": utilityCount.value,
2034
2803
  "has-pinned": unref(hasPinned),
2035
- offsets: unref(offsets)
2804
+ offsets: unref(offsets),
2805
+ "first-row-index": footerRowIndex.value
2036
2806
  }, null, 8, [
2037
2807
  "footer-rows",
2038
2808
  "entries",
2039
2809
  "utility-count",
2040
2810
  "has-pinned",
2041
- "offsets"
2811
+ "offsets",
2812
+ "first-row-index"
2042
2813
  ])) : createCommentVNode("", true)
2043
- ], 512)]),
2814
+ ], 8, _hoisted_3)]),
2044
2815
  showPagination.value ? (openBlock(), createBlock(table_pagination_default, {
2045
2816
  key: 0,
2046
2817
  "pagination-props": unref(paginationProps)