@dolusoft/query-table 3.0.1 → 3.1.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,7 +1,84 @@
1
- import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, 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, onBeforeUnmount, onScopeDispose, openBlock, provide, renderList, renderSlot, shallowRef, toDisplayString, toHandlers, toValue, unref, useSlots, watch, 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
- import { columnFilteringFeature, columnPinningFeature, functionalUpdate, globalFilteringFeature, rowExpandingFeature, rowPaginationFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable } from "@tanstack/vue-table";
4
+ import { columnFilteringFeature, columnOrderingFeature, columnPinningFeature, columnVisibilityFeature, functionalUpdate, globalFilteringFeature, rowExpandingFeature, rowPaginationFeature, rowPinningFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable } from "@tanstack/vue-table";
5
+ //#region src/columns/column-layout.ts
6
+ var sideOf = (column) => column.pinned === "left" ? "left" : column.pinned === "right" ? "right" : false;
7
+ /** A copy of `column` without `key`: a default is removed, never set (C-68). */
8
+ var without = (column, key) => {
9
+ const copy = { ...column };
10
+ delete copy[key];
11
+ return copy;
12
+ };
13
+ /** The columns with the visibility of `visibility`; `null` when nothing changes. */
14
+ var applyVisibility = (columns, visibility) => {
15
+ let changed = false;
16
+ const next = columns.map((column) => {
17
+ const visible = visibility[column.field] ?? true;
18
+ if (visible === !column.hide) return column;
19
+ changed = true;
20
+ return visible ? without(column, "hide") : {
21
+ ...column,
22
+ hide: true
23
+ };
24
+ });
25
+ return changed ? next : null;
26
+ };
27
+ /** The columns in `order` (unknown fields skipped, missing ones kept last); `null` when unchanged. */
28
+ var applyOrder = (columns, order) => {
29
+ const byField = new Map(columns.map((column) => [column.field, column]));
30
+ const placed = /* @__PURE__ */ new Set();
31
+ const next = [];
32
+ for (const field of order) {
33
+ const column = byField.get(field);
34
+ if (column && !placed.has(field)) {
35
+ placed.add(field);
36
+ next.push(column);
37
+ }
38
+ }
39
+ next.push(...columns.filter((column) => !placed.has(column.field)));
40
+ return next.every((column, index) => column === columns[index]) ? null : next;
41
+ };
42
+ /** The columns with the sides of `pinning` (start = left, end = right); `null` when unchanged. */
43
+ var applyPinning = (columns, pinning) => {
44
+ const left = new Set(pinning.start ?? []);
45
+ const right = new Set(pinning.end ?? []);
46
+ let changed = false;
47
+ const next = columns.map((column) => {
48
+ const side = left.has(column.field) ? "left" : right.has(column.field) ? "right" : false;
49
+ if (side === sideOf(column)) return column;
50
+ changed = true;
51
+ return side ? {
52
+ ...column,
53
+ pinned: side
54
+ } : without(column, "pinned");
55
+ });
56
+ return changed ? next : null;
57
+ };
58
+ /** The columns with `field` at `width`; `null` when it already has it. */
59
+ var applyWidth = (columns, field, width) => {
60
+ const at = columns.findIndex((column) => column.field === field);
61
+ if (at < 0 || columns[at].width === width) return null;
62
+ const next = [...columns];
63
+ next[at] = {
64
+ ...columns[at],
65
+ width
66
+ };
67
+ return next;
68
+ };
69
+ /**
70
+ * `field` taken out and put right before or after `target` (C-69): the
71
+ * columns between keep their place, hidden ones included.
72
+ */
73
+ var moveField = (fields, field, target, place) => {
74
+ if (field === target || !fields.includes(field)) return fields;
75
+ const rest = fields.filter((name) => name !== field);
76
+ const at = rest.indexOf(target);
77
+ if (at < 0) return fields;
78
+ rest.splice(place === "before" ? at : at + 1, 0, field);
79
+ return rest;
80
+ };
81
+ //#endregion
5
82
  //#region src/core/labels.ts
6
83
  /** English defaults of the `labels` prop (C-44). */
7
84
  var defaultLabels = {
@@ -11,6 +88,7 @@ var defaultLabels = {
11
88
  filterInput: (column) => `Filter ${column}`,
12
89
  filterOptions: (column) => `Filter options for ${column}`,
13
90
  resizeColumn: (column) => `Resize ${column}`,
91
+ moveColumn: (column) => `Move ${column}`,
14
92
  boolAll: "All",
15
93
  boolTrue: "True",
16
94
  boolFalse: "False",
@@ -62,17 +140,18 @@ var valueAt = (row, path) => path.split(".").reduce((value, key) => value === nu
62
140
  /** Geometry key of a utility cell; a column's key is its `field`. */
63
141
  var utilityKey = (utility) => `utility:${utility}`;
64
142
  /**
65
- * Attributes of a pinned cell (C-47): `data-pinned` and, once measured, the
66
- * `--qt-pin-left` offset in pixels, next to an optional `width`. Nothing but
143
+ * Attributes of a pinned cell (C-47, C-71): `data-pinned` (`''` on the left,
144
+ * `'right'` on the right) and, once measured, the `--qt-pin-left` or
145
+ * `--qt-pin-right` offset in pixels, next to an optional `width`. Nothing but
67
146
  * the width for a cell that is not pinned; no `style` when both are absent.
68
147
  */
69
- var pinAttrs = (pinned, offset, width) => {
148
+ var pinAttrs = (side, offset, width) => {
70
149
  const style = {};
71
150
  if (width) style.width = width;
72
- if (pinned && offset !== void 0) style["--qt-pin-left"] = `${offset}px`;
151
+ if (side && offset !== void 0) style[side === "left" ? "--qt-pin-left" : "--qt-pin-right"] = `${offset}px`;
73
152
  return {
74
- "data-pinned": pinned ? "" : void 0,
75
- style: width || style["--qt-pin-left"] ? style : void 0
153
+ "data-pinned": side === "left" ? "" : side === "right" ? "right" : void 0,
154
+ style: Object.keys(style).length > 0 ? style : void 0
76
155
  };
77
156
  };
78
157
  //#endregion
@@ -86,7 +165,7 @@ var useCellView = (options) => {
86
165
  const cellText = (row, column) => String(valueAt(row, column.field) ?? "");
87
166
  const cellAttrs = (entry) => ({
88
167
  "data-field": entry.column.field,
89
- ...pinAttrs(entry.column.pinned === "left", options.offsets()[entry.column.field])
168
+ ...pinAttrs(sideOf(entry.column), options.offsets()[entry.column.field])
90
169
  });
91
170
  /**
92
171
  * One listener on the `tbody` serves every cell (C-28): a listener per cell
@@ -122,11 +201,13 @@ var useCellView = (options) => {
122
201
  });
123
202
  };
124
203
  const hasCellSlot = (column) => !!options.slots[`cell-${column.field}`];
125
- const slotProps = (row, column, rowIndex) => ({
204
+ const slotProps = (row, column, rowIndex, rowPinned) => ({
126
205
  row,
127
206
  rowIndex,
128
207
  column,
129
- cellValue: valueAt(row, column.field)
208
+ cellValue: valueAt(row, column.field),
209
+ rowPinned,
210
+ pinRow: (position) => options.pinRow(row, rowIndex, position)
130
211
  });
131
212
  return {
132
213
  cellText,
@@ -138,8 +219,9 @@ var useCellView = (options) => {
138
219
  };
139
220
  //#endregion
140
221
  //#region src/parts/table-body.vue?vue&type=script&setup=true&lang.ts
141
- var _hoisted_1$8 = [
222
+ var _hoisted_1$9 = [
142
223
  "data-row-index",
224
+ "data-pinned-row",
143
225
  "data-expanded",
144
226
  "data-selected"
145
227
  ];
@@ -173,10 +255,7 @@ var _hoisted_7$1 = [
173
255
  "checked",
174
256
  "onChange"
175
257
  ];
176
- var _hoisted_8$1 = {
177
- key: 0,
178
- class: "qt-subtable-row"
179
- };
258
+ var _hoisted_8$1 = ["data-pinned-row"];
180
259
  var _hoisted_9$1 = ["colspan"];
181
260
  var _hoisted_10 = {
182
261
  key: 0,
@@ -194,6 +273,8 @@ var table_body_default = /* @__PURE__ */ defineComponent({
194
273
  __name: "table-body",
195
274
  props: {
196
275
  rows: {},
276
+ bodyRows: {},
277
+ pinRow: { type: Function },
197
278
  loading: { type: Boolean },
198
279
  entries: {},
199
280
  columnCount: {},
@@ -221,15 +302,18 @@ var table_body_default = /* @__PURE__ */ defineComponent({
221
302
  entries: () => props.entries,
222
303
  offsets: () => props.offsets,
223
304
  listening: () => props.hasContextMenuListener(),
224
- onContextMenu: (payload) => emit("cellContextMenu", payload)
305
+ onContextMenu: (payload) => emit("cellContextMenu", payload),
306
+ pinRow: (row, index, position) => props.pinRow(row, index, position)
225
307
  });
226
- const rightPanelAttrs = () => pinAttrs(props.hasPinned, props.offsets[utilityKey("right-panel")]);
227
- const expandAttrs = () => pinAttrs(props.hasPinned, props.offsets[utilityKey("subtable")]);
228
- const selectAttrs = () => pinAttrs(props.hasPinned, props.offsets[utilityKey("select")]);
308
+ const utilityAttrs = (utility) => pinAttrs(props.hasPinned ? "left" : false, props.offsets[utilityKey(utility)]);
309
+ const rightPanelAttrs = () => utilityAttrs("right-panel");
310
+ const expandAttrs = () => utilityAttrs("subtable");
311
+ const selectAttrs = () => utilityAttrs("select");
229
312
  return (_ctx, _cache) => {
230
- return openBlock(), createElementBlock("tbody", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onContextMenu) && unref(onContextMenu)(...args)) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.rows, (row, i) => {
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 }) => {
231
314
  return openBlock(), createElementBlock(Fragment, { key: __props.keyOf(row, i) }, [createElementVNode("tr", {
232
315
  "data-row-index": i,
316
+ "data-pinned-row": pinned || void 0,
233
317
  "data-expanded": __props.isExpanded(row, i) ? "" : void 0,
234
318
  "data-selected": __props.hasSelection && __props.isSelected(row, i) ? "" : void 0
235
319
  }, [
@@ -285,22 +369,26 @@ var table_body_default = /* @__PURE__ */ defineComponent({
285
369
  return openBlock(), createElementBlock(Fragment, { key: entry.column.field }, [unref(hasCellSlot)(entry.column) ? (openBlock(), createElementBlock("td", mergeProps({
286
370
  key: 0,
287
371
  ref_for: true
288
- }, unref(cellAttrs)(entry)), [renderSlot(_ctx.$slots, `cell-${entry.column.field}`, mergeProps({ ref_for: true }, unref(slotProps)(row, entry.column, i)))], 16)) : (openBlock(), createElementBlock("td", mergeProps({
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({
289
373
  key: 1,
290
374
  ref_for: true
291
375
  }, unref(cellAttrs)(entry)), toDisplayString(unref(cellText)(row, entry.column)), 17))], 64);
292
376
  }), 128))
293
- ], 8, _hoisted_1$8), __props.isExpanded(row, i) ? (openBlock(), createElementBlock("tr", _hoisted_8$1, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "subtable", {
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", {
294
382
  row,
295
383
  rowIndex: i
296
- })], 8, _hoisted_9$1)])) : createCommentVNode("", true)], 64);
384
+ })], 8, _hoisted_9$1)], 8, _hoisted_8$1)) : createCommentVNode("", true)], 64);
297
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);
298
386
  };
299
387
  }
300
388
  });
301
389
  //#endregion
302
390
  //#region src/parts/table-footer.vue?vue&type=script&setup=true&lang.ts
303
- var _hoisted_1$7 = { class: "qt-footer" };
391
+ var _hoisted_1$8 = { class: "qt-footer" };
304
392
  var _hoisted_2$4 = ["colspan"];
305
393
  var _hoisted_3$3 = ["data-field"];
306
394
  //#endregion
@@ -317,15 +405,15 @@ var table_footer_default = /* @__PURE__ */ defineComponent({
317
405
  setup(__props) {
318
406
  const footerText = (row, column) => row.cells.find((cell) => cell.field === column.field)?.text;
319
407
  return (_ctx, _cache) => {
320
- return openBlock(), createElementBlock("tfoot", _hoisted_1$7, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.footerRows, (footerRow, i) => {
408
+ return openBlock(), createElementBlock("tfoot", _hoisted_1$8, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.footerRows, (footerRow, i) => {
321
409
  return openBlock(), createElementBlock("tr", { key: i }, [__props.utilityCount > 0 ? (openBlock(), createElementBlock("td", mergeProps({
322
410
  key: 0,
323
411
  colspan: __props.utilityCount
324
- }, { ref_for: true }, unref(pinAttrs)(__props.hasPinned, 0)), null, 16, _hoisted_2$4)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(__props.entries, (entry) => {
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) => {
325
413
  return openBlock(), createElementBlock("td", mergeProps({
326
414
  key: entry.column.field,
327
415
  "data-field": entry.column.field
328
- }, { ref_for: true }, unref(pinAttrs)(entry.column.pinned === "left", __props.offsets[entry.column.field])), toDisplayString(footerText(footerRow, entry.column)), 17, _hoisted_3$3);
416
+ }, { ref_for: true }, unref(pinAttrs)(unref(sideOf)(entry.column), __props.offsets[entry.column.field])), toDisplayString(footerText(footerRow, entry.column)), 17, _hoisted_3$3);
329
417
  }), 128))]);
330
418
  }), 128))]);
331
419
  };
@@ -333,7 +421,7 @@ var table_footer_default = /* @__PURE__ */ defineComponent({
333
421
  });
334
422
  //#endregion
335
423
  //#region src/parts/filter-icon.vue?vue&type=script&setup=true&lang.ts
336
- var _hoisted_1$6 = ["fill"];
424
+ var _hoisted_1$7 = ["fill"];
337
425
  //#endregion
338
426
  //#region src/parts/filter-icon.vue
339
427
  var filter_icon_default = /* @__PURE__ */ defineComponent({
@@ -351,7 +439,7 @@ var filter_icon_default = /* @__PURE__ */ defineComponent({
351
439
  "stroke-linecap": "round",
352
440
  "stroke-linejoin": "round",
353
441
  "aria-hidden": "true"
354
- }, [..._cache[0] || (_cache[0] = [createElementVNode("polygon", { points: "22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" }, null, -1)])], 8, _hoisted_1$6);
442
+ }, [..._cache[0] || (_cache[0] = [createElementVNode("polygon", { points: "22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" }, null, -1)])], 8, _hoisted_1$7);
355
443
  };
356
444
  }
357
445
  });
@@ -380,7 +468,7 @@ var useFilterTrigger = (options) => defineComponent({
380
468
  });
381
469
  //#endregion
382
470
  //#region src/parts/filter-cell.vue?vue&type=script&setup=true&lang.ts
383
- var _hoisted_1$5 = { class: "qt-filter" };
471
+ var _hoisted_1$6 = { class: "qt-filter" };
384
472
  var _hoisted_2$3 = ["aria-label", "value"];
385
473
  var _hoisted_3$2 = [
386
474
  "type",
@@ -417,7 +505,7 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
417
505
  },
418
506
  setup(__props) {
419
507
  const props = __props;
420
- const { filters, sort, labels } = useTableContext();
508
+ const { filters, sort, layout, labels } = useTableContext();
421
509
  const inputName = () => labels().filterInput(columnName(props.column));
422
510
  const isFiltered = () => rulesOf(props.query.filters, props.column.field).length > 0;
423
511
  const trigger = useFilterTrigger({
@@ -448,7 +536,8 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
448
536
  sortable: sort.isSortable(column),
449
537
  sortDirection: sort.sortOf(column),
450
538
  setSort: (direction) => sort.sortBy(column, direction),
451
- trigger
539
+ trigger,
540
+ control: layout.controlOf(column.field)
452
541
  };
453
542
  };
454
543
  const datetimeProps = () => ({
@@ -462,7 +551,7 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
462
551
  filters.apply(props.column.field);
463
552
  };
464
553
  return (_ctx, _cache) => {
465
- return openBlock(), createElementBlock("div", _hoisted_1$5, [
554
+ return openBlock(), createElementBlock("div", _hoisted_1$6, [
466
555
  __props.type === "string" ? (openBlock(), createElementBlock("input", {
467
556
  key: 0,
468
557
  type: "text",
@@ -508,6 +597,28 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
508
597
  }
509
598
  });
510
599
  //#endregion
600
+ //#region src/parts/reorder-handle.vue?vue&type=script&setup=true&lang.ts
601
+ var _hoisted_1$5 = ["aria-label"];
602
+ //#endregion
603
+ //#region src/parts/reorder-handle.vue
604
+ var reorder_handle_default = /* @__PURE__ */ defineComponent({
605
+ __name: "reorder-handle",
606
+ props: { column: {} },
607
+ setup(__props) {
608
+ const props = __props;
609
+ const { reorder, labels } = useTableContext();
610
+ const on = reorder.listeners(() => props.column);
611
+ return (_ctx, _cache) => {
612
+ return openBlock(), createElementBlock("button", mergeProps({
613
+ type: "button",
614
+ class: "qt-reorder-handle",
615
+ "aria-label": unref(labels)().moveColumn(unref(columnName)(__props.column)),
616
+ "aria-keyshortcuts": "ArrowLeft ArrowRight Home End"
617
+ }, toHandlers(unref(on), true)), [..._cache[0] || (_cache[0] = [createStaticVNode("<svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\"><circle cx=\"9\" cy=\"6\" r=\"1.5\"></circle><circle cx=\"15\" cy=\"6\" r=\"1.5\"></circle><circle cx=\"9\" cy=\"12\" r=\"1.5\"></circle><circle cx=\"15\" cy=\"12\" r=\"1.5\"></circle><circle cx=\"9\" cy=\"18\" r=\"1.5\"></circle><circle cx=\"15\" cy=\"18\" r=\"1.5\"></circle></svg>", 1)])], 16, _hoisted_1$5);
618
+ };
619
+ }
620
+ });
621
+ //#endregion
511
622
  //#region src/resize/use-column-resize.ts
512
623
  /** Default `Column.minWidth`, in pixels. */
513
624
  var defaultMinWidth = 40;
@@ -553,6 +664,13 @@ var autofitWidth = (th, field) => {
553
664
  };
554
665
  var cellOf = (event) => event.currentTarget.closest("th");
555
666
  /**
667
+ * Which edge of the column the handle stands for: `1` for the right edge,
668
+ * `-1` for the left one. A right-pinned column stays at the right edge of the
669
+ * scroll container, so it grows to the left: its handle stands for its left
670
+ * edge, and moving that edge to the left widens it (C-71).
671
+ */
672
+ var edgeOf = (column) => column.pinned === "right" ? -1 : 1;
673
+ /**
556
674
  * Resizing a column (C-48 to C-50). The table holds a width only while a
557
675
  * drag is under way (the preview, P2); every committed width goes out as a
558
676
  * `columnResize` event and comes back, if the consumer wants it, as
@@ -572,7 +690,7 @@ var useColumnResize = (options) => {
572
690
  width: next
573
691
  });
574
692
  };
575
- const dragged = (current) => current.startWidth + current.lastX - current.startX;
693
+ const dragged = (current) => current.startWidth + edgeOf(current.column) * (current.lastX - current.startX);
576
694
  const end = (apply) => {
577
695
  const current = drag;
578
696
  if (current) {
@@ -625,7 +743,7 @@ var useColumnResize = (options) => {
625
743
  }
626
744
  return;
627
745
  }
628
- const sign = key === "ArrowRight" ? 1 : key === "ArrowLeft" ? -1 : 0;
746
+ const sign = (key === "ArrowRight" ? 1 : key === "ArrowLeft" ? -1 : 0) * edgeOf(column);
629
747
  const th = cellOf(event);
630
748
  if (th && (sign || key === "Enter" || event.type === "dblclick")) {
631
749
  event.preventDefault();
@@ -787,7 +905,7 @@ var _hoisted_3 = [
787
905
  "aria-sort"
788
906
  ];
789
907
  var _hoisted_4 = {
790
- key: 2,
908
+ key: 3,
791
909
  class: "qt-title"
792
910
  };
793
911
  //#endregion
@@ -806,15 +924,22 @@ var table_header_default = /* @__PURE__ */ defineComponent({
806
924
  setup(__props) {
807
925
  const props = __props;
808
926
  const given = (name) => props.slotNames.split(" ").includes(name);
809
- const { filters, sort, resize, selection, labels } = useTableContext();
927
+ const { filters, sort, layout, resize, reorder, selection, labels } = useTableContext();
928
+ const dragAttrs = (column) => {
929
+ const drag = reorder.dragging.value;
930
+ return {
931
+ "data-dragging": drag?.field === column.field ? "" : void 0,
932
+ "data-drop": drag?.target === column.field ? drag.place : void 0
933
+ };
934
+ };
810
935
  const canClearAll = computed(() => filters.canClearAll());
811
936
  const isFiltered = (column) => rulesOf(props.query.filters, column.field).length > 0;
812
937
  const hasFilter = (column) => props.filterable && column.filterable !== false;
813
938
  const hostsClearAll = (utility) => props.filterable && utility === props.utilities.find((candidate) => candidate !== "select");
814
- const utilityAttrs = (utility) => pinAttrs(props.hasPinned, props.offsets[utilityKey(utility)]);
939
+ const utilityAttrs = (utility) => pinAttrs(props.hasPinned ? "left" : false, props.offsets[utilityKey(utility)]);
815
940
  const cellAttrs = (column) => {
816
941
  const preview = resize.preview.value;
817
- return pinAttrs(column.pinned === "left", props.offsets[column.field], preview?.field === column.field ? `${preview.width}px` : column.width);
942
+ return pinAttrs(sideOf(column), props.offsets[column.field], preview?.field === column.field ? `${preview.width}px` : column.width);
818
943
  };
819
944
  const headerSlotProps = (column) => ({
820
945
  column,
@@ -822,7 +947,8 @@ var table_header_default = /* @__PURE__ */ defineComponent({
822
947
  sortable: sort.isSortable(column),
823
948
  toggleSort: () => {
824
949
  sort.sortBy(column);
825
- }
950
+ },
951
+ control: layout.controlOf(column.field)
826
952
  });
827
953
  return (_ctx, _cache) => {
828
954
  return openBlock(), createElementBlock("tr", null, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.utilities, (utility) => {
@@ -879,9 +1005,16 @@ var table_header_default = /* @__PURE__ */ defineComponent({
879
1005
  "data-sortable": unref(sort).isSortable(column) ? "" : void 0,
880
1006
  "data-filtered": isFiltered(column) ? "" : void 0,
881
1007
  "aria-sort": unref(ariaSort)(unref(sort).sortOf(column))
882
- }, { ref_for: true }, cellAttrs(column)), [
883
- given(`header-${column.field}`) ? renderSlot(_ctx.$slots, "header", mergeProps({ ref_for: true }, headerSlotProps(column)), void 0, void 0, 0) : unref(sort).isSortable(column) ? (openBlock(), createBlock(sort_button_default, {
884
- key: 1,
1008
+ }, { ref_for: true }, {
1009
+ ...cellAttrs(column),
1010
+ ...dragAttrs(column)
1011
+ }), [
1012
+ unref(reorder).isReorderable(column) ? (openBlock(), createBlock(reorder_handle_default, {
1013
+ key: 0,
1014
+ column
1015
+ }, null, 8, ["column"])) : createCommentVNode("", true),
1016
+ given(`header-${column.field}`) ? renderSlot(_ctx.$slots, "header", mergeProps({ ref_for: true }, headerSlotProps(column)), void 0, void 0, 1) : unref(sort).isSortable(column) ? (openBlock(), createBlock(sort_button_default, {
1017
+ key: 2,
885
1018
  column,
886
1019
  direction: unref(sort).sortOf(column),
887
1020
  onClick: ($event) => unref(sort).sortBy(column)
@@ -891,7 +1024,7 @@ var table_header_default = /* @__PURE__ */ defineComponent({
891
1024
  "onClick"
892
1025
  ])) : (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(column.title), 1)),
893
1026
  hasFilter(column) ? (openBlock(), createBlock(filter_cell_default, {
894
- key: 3,
1027
+ key: 4,
895
1028
  column,
896
1029
  type: unref(columnTypeOf$1)(column),
897
1030
  query: __props.query
@@ -909,7 +1042,7 @@ var table_header_default = /* @__PURE__ */ defineComponent({
909
1042
  "query"
910
1043
  ])) : createCommentVNode("", true),
911
1044
  unref(resize).isResizable(column) ? (openBlock(), createBlock(resize_handle_default, {
912
- key: 4,
1045
+ key: 5,
913
1046
  column
914
1047
  }, null, 8, ["column"])) : createCommentVNode("", true)
915
1048
  ], 16, _hoisted_3);
@@ -936,9 +1069,10 @@ var table_pagination_default = /* @__PURE__ */ defineComponent({
936
1069
  /** One string per map: compares two maps in one step. */
937
1070
  var signature = (numbers) => JSON.stringify(numbers);
938
1071
  /**
939
- * Measured header geometry (C-47, C-48): the rendered width of every header
940
- * cell and, for the pinned cells, the cumulative left offset written as
941
- * `--qt-pin-left`. One `ResizeObserver` watches the header cells and the
1072
+ * Measured header geometry (C-47, C-48, C-71): the rendered width of every
1073
+ * header cell and, for the pinned cells, the cumulative offset: from the left
1074
+ * for a left-pinned cell (`--qt-pin-left`), from the right for a
1075
+ * right-pinned one (`--qt-pin-right`). One `ResizeObserver` watches the header cells and the
942
1076
  * table; it reports width changes from any cause (a resize, a font that
943
1077
  * loads, a container that narrows) in one batched callback, after layout, so
944
1078
  * reading the cells there forces no extra layout. The observer is rebuilt
@@ -950,7 +1084,10 @@ var useHeaderGeometry = (options) => {
950
1084
  const widths = shallowRef({});
951
1085
  /** Rendered width of the table. */
952
1086
  const tableWidth = shallowRef(0);
953
- /** `--qt-pin-left` of each pinned cell, by key, in pixels. */
1087
+ /**
1088
+ * `--qt-pin-left` of each left-pinned cell and `--qt-pin-right` of each
1089
+ * right-pinned one, by key, in pixels.
1090
+ */
954
1091
  const offsets = shallowRef({});
955
1092
  let observer = null;
956
1093
  const headerCells = (table) => table.querySelectorAll(":scope > thead > tr > *");
@@ -959,18 +1096,25 @@ var useHeaderGeometry = (options) => {
959
1096
  const cells = options.cells();
960
1097
  const next = {};
961
1098
  const nextOffsets = {};
1099
+ const rights = [];
962
1100
  let left = 0;
963
1101
  headerCells(table).forEach((cell, index) => {
964
1102
  const drawn = cells[index];
965
1103
  if (drawn) {
966
1104
  const width = cell.getBoundingClientRect().width;
967
1105
  next[drawn.key] = width;
968
- if (drawn.pinned) {
1106
+ if (drawn.side === "left") {
969
1107
  nextOffsets[drawn.key] = left;
970
1108
  left += width;
971
- }
1109
+ } else if (drawn.side === "right") rights.push([drawn.key, width]);
972
1110
  }
973
1111
  });
1112
+ let right = 0;
1113
+ for (let i = rights.length - 1; i >= 0; i--) {
1114
+ const [key, width] = rights[i];
1115
+ nextOffsets[key] = right;
1116
+ right += width;
1117
+ }
974
1118
  if (signature(next) !== signature(widths.value)) widths.value = next;
975
1119
  if (signature(nextOffsets) !== signature(offsets.value)) offsets.value = nextOffsets;
976
1120
  };
@@ -995,7 +1139,7 @@ var useHeaderGeometry = (options) => {
995
1139
  watch([
996
1140
  () => options.table.value,
997
1141
  options.active,
998
- () => options.cells().map((cell) => cell.pinned ? `${cell.key}*` : cell.key).join("|")
1142
+ () => options.cells().map((cell) => cell.side === "left" ? `${cell.key}*` : cell.side === "right" ? `${cell.key}>` : cell.key).join("|")
999
1143
  ], () => {
1000
1144
  nextTick(observe);
1001
1145
  }, {
@@ -1013,6 +1157,142 @@ var useHeaderGeometry = (options) => {
1013
1157
  };
1014
1158
  };
1015
1159
  //#endregion
1160
+ //#region src/reorder/use-column-reorder.ts
1161
+ var placeOf = (key) => key === "ArrowLeft" || key === "Home" ? "before" : "after";
1162
+ /**
1163
+ * Reordering a column with its handle (C-73): a pointer drag or the arrow
1164
+ * keys, Home and End, inside the column's region. The table keeps only the
1165
+ * drag in progress (P15); the order itself goes out as `update:columns` and
1166
+ * comes back, if the consumer wants it, as the order of `columns`. Like the
1167
+ * resize handle, the handle captures the pointer, so every drag event
1168
+ * arrives at the handle itself, and it has the focus, so Escape does too.
1169
+ */
1170
+ var useColumnReorder = (options) => {
1171
+ const dragging = shallowRef(null);
1172
+ let drag = null;
1173
+ /** The column whose handle moved it by key and still has the focus. */
1174
+ let refocus = null;
1175
+ /** Between the new `columns` and their render: a blur then is the move's. */
1176
+ let patching = false;
1177
+ const isReorderable = (column) => options.reorderable() && column.reorderable !== false;
1178
+ /** This table's own header cell, never one of a nested table. */
1179
+ const headerCell = (field) => options.table.value?.querySelector(`:scope > thead > tr > th[data-field="${CSS.escape(field)}"]`) ?? null;
1180
+ const end = () => {
1181
+ drag = null;
1182
+ dragging.value = null;
1183
+ };
1184
+ /** Every pointer event of a handle; one listener for the whole drag. */
1185
+ const onPointer = (event, column) => {
1186
+ if (event.type === "pointerdown") {
1187
+ if (event.button !== 0 || drag) return;
1188
+ const handle = event.currentTarget;
1189
+ event.preventDefault();
1190
+ handle.focus({ preventScroll: true });
1191
+ handle.setPointerCapture(event.pointerId);
1192
+ refocus = null;
1193
+ drag = {
1194
+ field: column.field,
1195
+ pointerId: event.pointerId,
1196
+ cells: options.layout.regionOf(column.field).flatMap((field) => {
1197
+ const box = headerCell(field)?.getBoundingClientRect();
1198
+ return box ? [{
1199
+ field,
1200
+ left: box.left,
1201
+ right: box.right
1202
+ }] : [];
1203
+ })
1204
+ };
1205
+ dragging.value = {
1206
+ field: column.field,
1207
+ target: null,
1208
+ place: "after"
1209
+ };
1210
+ return;
1211
+ }
1212
+ if (!drag || event.pointerId !== drag.pointerId) return;
1213
+ if (event.type === "pointermove") {
1214
+ const x = event.clientX;
1215
+ const over = drag.cells.find((cell) => x >= cell.left && x < cell.right);
1216
+ const target = over && over.field !== drag.field ? over.field : null;
1217
+ const place = over && x < (over.left + over.right) / 2 ? "before" : "after";
1218
+ const current = dragging.value;
1219
+ if (current?.target !== target || current.place !== place) dragging.value = {
1220
+ field: drag.field,
1221
+ target,
1222
+ place
1223
+ };
1224
+ return;
1225
+ }
1226
+ const done = dragging.value;
1227
+ end();
1228
+ if (event.type === "pointerup" && done?.target) options.layout.moveColumn(done.field, done.target, done.place);
1229
+ };
1230
+ const onKey = (event, column) => {
1231
+ const { key } = event;
1232
+ if (drag) {
1233
+ if (key === "Escape") {
1234
+ event.preventDefault();
1235
+ event.stopPropagation();
1236
+ end();
1237
+ }
1238
+ return;
1239
+ }
1240
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
1241
+ const region = options.layout.regionOf(column.field);
1242
+ const at = region.indexOf(column.field);
1243
+ const target = key === "ArrowLeft" ? region[at - 1] : key === "ArrowRight" ? region[at + 1] : key === "Home" ? region[0] : key === "End" ? region[region.length - 1] : void 0;
1244
+ if (at < 0 || target === void 0) return;
1245
+ event.preventDefault();
1246
+ if (target !== column.field) {
1247
+ refocus = column.field;
1248
+ options.layout.moveColumn(column.field, target, placeOf(key));
1249
+ }
1250
+ };
1251
+ watch(options.columns, () => {
1252
+ patching = true;
1253
+ });
1254
+ watch(options.columns, () => {
1255
+ patching = false;
1256
+ if (drag) end();
1257
+ const field = refocus;
1258
+ if (field !== null) nextTick(() => {
1259
+ const handle = headerCell(field)?.querySelector(":scope > .qt-reorder-handle");
1260
+ if (handle && refocus === field && document.activeElement !== handle) handle.focus({ preventScroll: true });
1261
+ });
1262
+ }, { flush: "post" });
1263
+ onBeforeUnmount(end);
1264
+ /**
1265
+ * The listeners of one handle, as one `v-on` object made once per handle.
1266
+ * Pointer capture sends every drag event to the handle itself.
1267
+ */
1268
+ const listeners = (column) => {
1269
+ const pointer = (event) => {
1270
+ onPointer(event, column());
1271
+ };
1272
+ return {
1273
+ pointerdown: pointer,
1274
+ pointermove: pointer,
1275
+ pointerup: pointer,
1276
+ pointercancel: pointer,
1277
+ lostpointercapture: pointer,
1278
+ keydown: (event) => {
1279
+ onKey(event, column());
1280
+ },
1281
+ blur: () => {
1282
+ if (!patching) refocus = null;
1283
+ },
1284
+ click: (event) => {
1285
+ event.stopPropagation();
1286
+ }
1287
+ };
1288
+ };
1289
+ return {
1290
+ isReorderable,
1291
+ dragging,
1292
+ listeners
1293
+ };
1294
+ };
1295
+ //#endregion
1016
1296
  //#region src/use-query-table.ts
1017
1297
  /** The TanStack features of a Query Table, the two plugins included. */
1018
1298
  var features = tableFeatures({
@@ -1022,7 +1302,10 @@ var features = tableFeatures({
1022
1302
  globalFilteringFeature,
1023
1303
  rowSelectionFeature,
1024
1304
  rowExpandingFeature,
1305
+ columnVisibilityFeature,
1306
+ columnOrderingFeature,
1025
1307
  columnPinningFeature,
1308
+ rowPinningFeature,
1026
1309
  serverQueryFeature,
1027
1310
  filterInputFeature
1028
1311
  });
@@ -1039,6 +1322,11 @@ var defaultPageSizes = [
1039
1322
  ];
1040
1323
  /** Only the `true` entries: the selection a consumer stores. */
1041
1324
  var selectedOnly = (selection) => Object.fromEntries(Object.entries(selection).filter(([, value]) => value));
1325
+ var noPinnedRows = Object.freeze({
1326
+ top: Object.freeze([]),
1327
+ bottom: Object.freeze([])
1328
+ });
1329
+ var sameKeys = (a, b) => a.length === b.length && a.every((key, i) => key === b[i]);
1042
1330
  /**
1043
1331
  * The state and actions of a server-side table: TanStack Table with
1044
1332
  * `serverQueryFeature` and `filterInputFeature`, in a Vue scope. Disposed
@@ -1052,6 +1340,16 @@ function useQueryTable(options) {
1052
1340
  const columns = () => toValue(options.columns);
1053
1341
  const rowKey = () => toValue(options.rowKey);
1054
1342
  const hasSubtable = () => toValue(options.hasSubtable) ?? false;
1343
+ const pinnedRows = () => toValue(options.rowPinning);
1344
+ const pinningEnabled = computed(() => rowKey() !== void 0 && pinnedRows() !== void 0);
1345
+ const rowPinningState = computed(() => {
1346
+ if (!pinningEnabled.value) return noPinnedRows;
1347
+ const map = pinnedRows();
1348
+ return {
1349
+ top: map.top ?? [],
1350
+ bottom: map.bottom ?? []
1351
+ };
1352
+ });
1055
1353
  const keyOf = (row, index) => {
1056
1354
  const key = rowKey();
1057
1355
  if (typeof key === "function") return key(row, index);
@@ -1071,10 +1369,16 @@ function useQueryTable(options) {
1071
1369
  enableSorting: column.sortable !== false,
1072
1370
  filterType: columnTypeOf(column)
1073
1371
  })));
1372
+ const columnVisibility = computed(() => Object.fromEntries(columns().map((column) => [column.field, !column.hide])));
1373
+ const columnOrder = computed(() => columns().map((column) => column.field));
1074
1374
  const columnPinning = computed(() => ({
1075
- start: columns().filter((column) => column.pinned === "left").map((column) => column.field),
1076
- end: []
1375
+ start: columns().filter((column) => sideOf(column) === "left").map((column) => column.field),
1376
+ end: columns().filter((column) => sideOf(column) === "right").map((column) => column.field)
1077
1377
  }));
1378
+ /** A layout change goes to the consumer; an equal result is no change (C-68). */
1379
+ const tell = (next, reason) => {
1380
+ if (next) options.onColumnsChange?.(next, reason);
1381
+ };
1078
1382
  /** Updates emitted so far: tells whether an action emitted one. */
1079
1383
  let emits = 0;
1080
1384
  const table = useTable({
@@ -1113,6 +1417,21 @@ function useQueryTable(options) {
1113
1417
  const current = toValue(options.selection) ?? {};
1114
1418
  options.onSelectionChange?.(selectedOnly(functionalUpdate(updater, current)));
1115
1419
  },
1420
+ onColumnVisibilityChange: (updater) => tell(applyVisibility(columns(), functionalUpdate(updater, columnVisibility.value)), "visibility"),
1421
+ onColumnOrderChange: (updater) => tell(applyOrder(columns(), functionalUpdate(updater, columnOrder.value)), "order"),
1422
+ onColumnPinningChange: (updater) => tell(applyPinning(columns(), functionalUpdate(updater, columnPinning.value)), "pin"),
1423
+ get enableRowPinning() {
1424
+ return pinningEnabled.value;
1425
+ },
1426
+ onRowPinningChange: (updater) => {
1427
+ if (!pinningEnabled.value) return;
1428
+ const current = rowPinningState.value;
1429
+ const next = functionalUpdate(updater, current);
1430
+ if (!sameKeys(next.top, current.top) || !sameKeys(next.bottom, current.bottom)) options.onRowPinningChange?.({
1431
+ top: [...next.top],
1432
+ bottom: [...next.bottom]
1433
+ });
1434
+ },
1116
1435
  state: {
1117
1436
  get sorting() {
1118
1437
  return projection.value.state.sorting;
@@ -1129,8 +1448,17 @@ function useQueryTable(options) {
1129
1448
  get rowSelection() {
1130
1449
  return toValue(options.selection) ?? {};
1131
1450
  },
1451
+ get columnVisibility() {
1452
+ return columnVisibility.value;
1453
+ },
1454
+ get columnOrder() {
1455
+ return columnOrder.value;
1456
+ },
1132
1457
  get columnPinning() {
1133
1458
  return columnPinning.value;
1459
+ },
1460
+ get rowPinning() {
1461
+ return rowPinningState.value;
1134
1462
  }
1135
1463
  }
1136
1464
  });
@@ -1141,9 +1469,63 @@ function useQueryTable(options) {
1141
1469
  column,
1142
1470
  index
1143
1471
  }]));
1144
- return [...table.getStartLeafColumns(), ...table.getCenterLeafColumns()].map((column) => byField.get(column.id)).filter((entry) => !!entry && !entry.column.hide);
1472
+ return [
1473
+ ...table.getStartVisibleLeafColumns(),
1474
+ ...table.getCenterVisibleLeafColumns(),
1475
+ ...table.getEndVisibleLeafColumns()
1476
+ ].map((column) => byField.get(column.id)).filter((entry) => !!entry);
1145
1477
  });
1146
- const hasPinned = computed(() => entries.value.some((entry) => entry.column.pinned === "left"));
1478
+ const hasPinned = computed(() => entries.value.some((entry) => sideOf(entry.column) === "left"));
1479
+ const regionOf = (field) => {
1480
+ const own = entries.value.find((entry) => entry.column.field === field);
1481
+ if (!own) return [];
1482
+ const side = sideOf(own.column);
1483
+ return entries.value.filter((entry) => sideOf(entry.column) === side).map((entry) => entry.column.field);
1484
+ };
1485
+ const moveColumn = (field, target, place) => {
1486
+ if (field !== target && regionOf(field).includes(target)) table.setColumnOrder(moveField(columnOrder.value, field, target, place));
1487
+ };
1488
+ /**
1489
+ * A column's control. Every slot of every column gets one, so making it
1490
+ * does no work: `pinned`, `canMoveLeft` and `canMoveRight` read the layout
1491
+ * when they are read (a region is O(n)), and a slot that never reads them
1492
+ * costs nothing. A control kept past a re-render reads the current layout.
1493
+ */
1494
+ const controlOf = (field) => {
1495
+ const place = () => {
1496
+ const region = regionOf(field);
1497
+ return {
1498
+ at: region.indexOf(field),
1499
+ size: region.length
1500
+ };
1501
+ };
1502
+ return {
1503
+ get pinned() {
1504
+ const column = columns().find((candidate) => candidate.field === field);
1505
+ return column ? sideOf(column) : false;
1506
+ },
1507
+ pin: (side) => columnById(field)?.pin(side === "left" ? "start" : side === "right" ? "end" : false),
1508
+ hide: () => columnById(field)?.toggleVisibility(false),
1509
+ get canMoveLeft() {
1510
+ return place().at > 0;
1511
+ },
1512
+ get canMoveRight() {
1513
+ const { at, size } = place();
1514
+ return at >= 0 && at < size - 1;
1515
+ },
1516
+ move: (direction) => {
1517
+ const current = regionOf(field);
1518
+ const from = current.indexOf(field);
1519
+ const target = current[from + (direction === "left" ? -1 : 1)];
1520
+ if (from >= 0 && target !== void 0) moveColumn(field, target, direction === "left" ? "before" : "after");
1521
+ }
1522
+ };
1523
+ };
1524
+ const layout = {
1525
+ controlOf,
1526
+ regionOf,
1527
+ moveColumn
1528
+ };
1147
1529
  /** Typed and not yet answered; `null` when the input shows the query. */
1148
1530
  const typed = shallowRef(null);
1149
1531
  let searchTimer;
@@ -1330,30 +1712,62 @@ function useQueryTable(options) {
1330
1712
  return state;
1331
1713
  });
1332
1714
  }, { immediate: true });
1715
+ const selection = {
1716
+ enabled: computed(() => toValue(options.selection) !== void 0),
1717
+ isSelected: (row, index) => !!toValue(options.selection)?.[idOf(row, index)],
1718
+ toggle: (row, index) => {
1719
+ const id = idOf(row, index);
1720
+ table.setRowSelection((old) => {
1721
+ const next = { ...old };
1722
+ if (next[id]) delete next[id];
1723
+ else next[id] = true;
1724
+ return next;
1725
+ });
1726
+ },
1727
+ allSelected: computed(() => table.getIsAllPageRowsSelected()),
1728
+ someSelected: computed(() => table.getIsSomePageRowsSelected()),
1729
+ toggleAll: (value) => table.toggleAllPageRowsSelected(value)
1730
+ };
1731
+ const bodyRows = computed(() => {
1732
+ if (!pinningEnabled.value) return rows().map((row, index) => ({
1733
+ row,
1734
+ index,
1735
+ pinned: false
1736
+ }));
1737
+ const of = (row, pinned) => ({
1738
+ row: row.original,
1739
+ index: row.index,
1740
+ pinned
1741
+ });
1742
+ return [
1743
+ ...table.getTopRows().map((row) => of(row, "top")),
1744
+ ...table.getCenterRows().map((row) => of(row, false)),
1745
+ ...table.getBottomRows().map((row) => of(row, "bottom"))
1746
+ ];
1747
+ });
1748
+ const positionOf = (id) => {
1749
+ const { top, bottom } = rowPinningState.value;
1750
+ return top.includes(id) ? "top" : bottom.includes(id) ? "bottom" : false;
1751
+ };
1333
1752
  return {
1334
1753
  table,
1335
1754
  columns: entries,
1336
1755
  hasPinned,
1756
+ layout,
1337
1757
  sort,
1338
1758
  filters,
1339
1759
  search,
1340
1760
  pagination,
1341
1761
  expansion,
1342
- selection: {
1343
- enabled: computed(() => toValue(options.selection) !== void 0),
1344
- isSelected: (row, index) => !!toValue(options.selection)?.[idOf(row, index)],
1345
- toggle: (row, index) => {
1762
+ selection,
1763
+ rowPinning: {
1764
+ enabled: pinningEnabled,
1765
+ rows: bodyRows,
1766
+ pin: (row, index, position) => {
1346
1767
  const id = idOf(row, index);
1347
- table.setRowSelection((old) => {
1348
- const next = { ...old };
1349
- if (next[id]) delete next[id];
1350
- else next[id] = true;
1351
- return next;
1352
- });
1353
- },
1354
- allSelected: computed(() => table.getIsAllPageRowsSelected()),
1355
- someSelected: computed(() => table.getIsSomePageRowsSelected()),
1356
- toggleAll: (value) => table.toggleAllPageRowsSelected(value)
1768
+ if (!pinningEnabled.value || positionOf(id) === position) return;
1769
+ table.getRow(id, true)?.pin(position);
1770
+ }
1357
1771
  },
1358
1772
  baseQuery
1359
1773
  };
@@ -1375,6 +1789,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1375
1789
  query: {},
1376
1790
  cursors: { default: null },
1377
1791
  selection: { default: void 0 },
1792
+ rowPinning: { default: void 0 },
1378
1793
  searchDebounce: { default: 300 },
1379
1794
  columns: {},
1380
1795
  rows: { default: () => [] },
@@ -1396,6 +1811,10 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1396
1811
  type: Boolean,
1397
1812
  default: false
1398
1813
  },
1814
+ reorderable: {
1815
+ type: Boolean,
1816
+ default: false
1817
+ },
1399
1818
  filterDebounce: { default: 100 },
1400
1819
  pagination: {},
1401
1820
  hasSubtable: {
@@ -1417,7 +1836,9 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1417
1836
  "update:selection",
1418
1837
  "rowRightPanelClick",
1419
1838
  "cellContextMenu",
1420
- "columnResize"
1839
+ "columnResize",
1840
+ "update:columns",
1841
+ "update:rowPinning"
1421
1842
  ],
1422
1843
  setup(__props, { expose: __expose, emit: __emit }) {
1423
1844
  const props = __props;
@@ -1434,11 +1855,14 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1434
1855
  filterDebounce: () => props.filterDebounce,
1435
1856
  searchDebounce: () => props.searchDebounce,
1436
1857
  selection: () => props.selection,
1858
+ rowPinning: () => props.rowPinning,
1437
1859
  rowKey: () => props.rowKey,
1438
1860
  hasSubtable: () => props.hasSubtable,
1439
1861
  pageSizeOptions: () => props.pagination?.pageSizeOptions,
1440
1862
  onQueryChange: (query, reason) => emit("update:query", query, reason),
1441
- onSelectionChange: (selection) => emit("update:selection", selection)
1863
+ onSelectionChange: (selection) => emit("update:selection", selection),
1864
+ onColumnsChange: (columns, reason) => emit("update:columns", columns, reason),
1865
+ onRowPinningChange: (rowPinning) => emit("update:rowPinning", rowPinning)
1442
1866
  });
1443
1867
  const { filters, sort, search, expansion } = state;
1444
1868
  const rowSelection = state.selection;
@@ -1460,27 +1884,42 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1460
1884
  ].filter((name) => name !== null));
1461
1885
  const utilityCount = computed(() => utilities.value.length);
1462
1886
  const columnCount = computed(() => entries.value.length + utilityCount.value);
1887
+ /** Utilities are pinned only with a left-pinned column (C-46, C-71). */
1888
+ const utilitySide = () => hasPinned.value ? "left" : false;
1463
1889
  const tableEl = shallowRef(null);
1464
1890
  const { widths, tableWidth, offsets } = useHeaderGeometry({
1465
1891
  table: tableEl,
1466
1892
  cells: () => [...utilities.value.map((utility) => ({
1467
1893
  key: utilityKey(utility),
1468
- pinned: hasPinned.value
1894
+ side: utilitySide()
1469
1895
  })), ...entries.value.map(({ column }) => ({
1470
1896
  key: column.field,
1471
- pinned: column.pinned === "left"
1897
+ side: sideOf(column)
1472
1898
  }))],
1473
- active: () => hasPinned.value || props.resizable && entries.value.some((entry) => entry.column.resizable !== false)
1899
+ active: () => entries.value.some((entry) => sideOf(entry.column) !== false) || props.resizable && entries.value.some((entry) => entry.column.resizable !== false)
1900
+ });
1901
+ const resize = useColumnResize({
1902
+ resizable: () => props.resizable,
1903
+ measuredWidth: (field) => widths.value[field],
1904
+ tableWidth: () => tableWidth.value,
1905
+ emit: (payload) => {
1906
+ emit("columnResize", payload);
1907
+ const next = applyWidth(props.columns, payload.field, `${payload.width}px`);
1908
+ if (next) emit("update:columns", next, "resize");
1909
+ }
1910
+ });
1911
+ const reorder = useColumnReorder({
1912
+ reorderable: () => props.reorderable,
1913
+ table: tableEl,
1914
+ layout: state.layout,
1915
+ columns: () => props.columns
1474
1916
  });
1475
1917
  provideTableContext({
1476
1918
  filters,
1477
1919
  sort,
1478
- resize: useColumnResize({
1479
- resizable: () => props.resizable,
1480
- measuredWidth: (field) => widths.value[field],
1481
- tableWidth: () => tableWidth.value,
1482
- emit: (payload) => emit("columnResize", payload)
1483
- }),
1920
+ layout: state.layout,
1921
+ resize,
1922
+ reorder,
1484
1923
  selection: rowSelection,
1485
1924
  labels: () => labels.value
1486
1925
  });
@@ -1544,6 +1983,8 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1544
1983
  ])]),
1545
1984
  createVNode(table_body_default, {
1546
1985
  rows: __props.rows,
1986
+ "body-rows": unref(state).rowPinning.rows.value,
1987
+ "pin-row": unref(state).rowPinning.pin,
1547
1988
  loading: __props.loading,
1548
1989
  entries: unref(entries),
1549
1990
  "column-count": columnCount.value,
@@ -1568,6 +2009,8 @@ var query_table_default = /* @__PURE__ */ defineComponent({
1568
2009
  };
1569
2010
  })]), 1032, [
1570
2011
  "rows",
2012
+ "body-rows",
2013
+ "pin-row",
1571
2014
  "loading",
1572
2015
  "entries",
1573
2016
  "column-count",