@dolusoft/query-table 3.3.0 → 3.5.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,4 +1,4 @@
1
- import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createStaticVNode, createTextVNode, createVNode, defineComponent, effectScope, getCurrentInstance, getCurrentScope, guardReactiveProps, h, inject, mergeProps, nextTick, normalizeProps, normalizeStyle, onActivated, onBeforeUnmount, onDeactivated, onMounted, onScopeDispose, openBlock, provide, renderList, renderSlot, shallowRef, toDisplayString, toHandlers, toValue, unref, useSlots, watch, watchEffect, withCtx, withKeys, withModifiers } from "vue";
1
+ import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createStaticVNode, createTextVNode, createVNode, defineComponent, effectScope, getCurrentInstance, getCurrentScope, guardReactiveProps, h, inject, mergeProps, nextTick, normalizeProps, normalizeStyle, onActivated, onBeforeUnmount, onBeforeUpdate, onDeactivated, onMounted, onScopeDispose, openBlock, provide, renderList, renderSlot, shallowRef, toDisplayString, toHandlers, toValue, unref, useSlots, watch, watchEffect, withCtx, withKeys, withModifiers } from "vue";
2
2
  import { columnTypeOf, columnTypeOf as columnTypeOf$1, conditionLabel, conditionOptions, isCursorQuery, parseFilterInput as parseFilterInput$1, rulesOf, searchOf } from "@dolusoft/query-protocol";
3
3
  import { createRowChangeTracker } from "@dolusoft/query-table-core/row-changes";
4
4
  import { dispose, filterInputFeature, projectServerQuery, serverQueryFeature } from "@dolusoft/query-table-core";
@@ -604,6 +604,37 @@ var useChangeFlash = (o) => {
604
604
  return view;
605
605
  };
606
606
  //#endregion
607
+ //#region src/header/use-header-context-menu.ts
608
+ /**
609
+ * One listener on the `thead` serves every header cell (C-96): a listener per
610
+ * cell would be a new closure per cell on every render. Only a data column
611
+ * header emits (`data-field`); utility cells keep the browser menu. A right
612
+ * click inside the filter row (`.qt-filter`) keeps the browser menu too, so
613
+ * paste and spell-check stay (issue #102 S1(a)).
614
+ */
615
+ var useHeaderContextMenu = (options) => {
616
+ const onContextMenu = (event) => {
617
+ if (!options.listening()) return;
618
+ const head = event.currentTarget;
619
+ let cell = event.target?.closest("th") ?? null;
620
+ while (cell && cell.parentElement?.parentElement !== head) cell = cell.parentElement?.closest("th") ?? null;
621
+ const field = cell?.getAttribute("data-field") ?? null;
622
+ if (field === null || !cell) return;
623
+ const target = event.target;
624
+ if (target?.closest(".qt-filter") && cell.contains(target.closest(".qt-filter"))) return;
625
+ const column = options.columns().find((c) => c.field === field);
626
+ const columnIndex = options.indexOf(field);
627
+ if (!column || columnIndex === void 0) return;
628
+ event.preventDefault();
629
+ options.onContextMenu({
630
+ event,
631
+ column,
632
+ columnIndex
633
+ });
634
+ };
635
+ return { onContextMenu };
636
+ };
637
+ //#endregion
607
638
  //#region src/core/column.ts
608
639
  /** Reads a dotted path (`'a.b'`) from a row. */
609
640
  var valueAt = (row, path) => path.split(".").reduce((value, key) => value === null || value === void 0 ? void 0 : value[key], row);
@@ -698,6 +729,7 @@ var _hoisted_2$5 = [
698
729
  "data-row-index",
699
730
  "aria-rowindex",
700
731
  "data-pinned-row",
732
+ "data-row-kind",
701
733
  "data-expanded",
702
734
  "data-selected",
703
735
  "data-flash",
@@ -772,8 +804,10 @@ var table_body_default = /* @__PURE__ */ defineComponent({
772
804
  hasPinned: { type: Boolean },
773
805
  offsets: {},
774
806
  keyOf: { type: Function },
807
+ canExpand: { type: Function },
775
808
  isExpanded: { type: Function },
776
809
  toggle: { type: Function },
810
+ rowKind: { type: Function },
777
811
  labels: {},
778
812
  hasContextMenuListener: { type: Function },
779
813
  loadMore: {},
@@ -798,8 +832,25 @@ var table_body_default = /* @__PURE__ */ defineComponent({
798
832
  const expandAttrs = () => utilityAttrs("subtable");
799
833
  const selectAttrs = () => utilityAttrs("select");
800
834
  const isSpacer = (item) => "spacer" in item;
835
+ /** `data-row-kind` of a drawn row (C-97): no attribute for an empty kind. */
836
+ const kindOf = (item) => props.rowKind ? props.rowKind(item.row, item.index) || void 0 : void 0;
801
837
  /** `aria-rowindex` of the subtable row under a drawn row (C-86). */
802
838
  const nextIndex = (aria) => aria === void 0 ? void 0 : aria + 1;
839
+ let expandedSnapshot = null;
840
+ onBeforeUpdate(() => {
841
+ expandedSnapshot = null;
842
+ });
843
+ const isRowExpanded = (item) => {
844
+ if (isSpacer(item)) return false;
845
+ if (!expandedSnapshot) {
846
+ const open = /* @__PURE__ */ new Map();
847
+ if (props.hasSubtable) {
848
+ for (const row of props.bodyRows) if (!isSpacer(row)) open.set(String(props.keyOf(row.row, row.index)), props.isExpanded(row.row, row.index));
849
+ }
850
+ expandedSnapshot = open;
851
+ }
852
+ return expandedSnapshot.get(String(props.keyOf(item.row, item.index))) === true;
853
+ };
803
854
  return (_ctx, _cache) => {
804
855
  return openBlock(), createElementBlock("tbody", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onContextMenu) && unref(onContextMenu)(...args)) }, [
805
856
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.bodyRows, (item) => {
@@ -808,11 +859,13 @@ var table_body_default = /* @__PURE__ */ defineComponent({
808
859
  class: "qt-virtual-spacer",
809
860
  "aria-hidden": "true",
810
861
  style: normalizeStyle({ height: `${item.spacer}px` })
811
- }, [createElementVNode("td", { colspan: __props.columnCount }, null, 8, _hoisted_1$9)], 4)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createElementVNode("tr", {
862
+ }, [createElementVNode("td", { colspan: __props.columnCount }, null, 8, _hoisted_1$9)], 4)) : (openBlock(), createElementBlock("tr", {
863
+ key: 1,
812
864
  "data-row-index": item.index,
813
865
  "aria-rowindex": item.aria,
814
866
  "data-pinned-row": item.pinned || void 0,
815
- "data-expanded": __props.isExpanded(item.row, item.index) ? "" : void 0,
867
+ "data-row-kind": kindOf(item),
868
+ "data-expanded": isRowExpanded(item) ? "" : void 0,
816
869
  "data-selected": __props.hasSelection && __props.isSelected(item.row, item.index) ? "" : void 0,
817
870
  "data-flash": __props.flash ? __props.flash.row(item.row, item.index) : void 0,
818
871
  onVnodeBeforeMount: __props.flash ? __props.flash.bind : void 0,
@@ -849,13 +902,14 @@ var table_body_default = /* @__PURE__ */ defineComponent({
849
902
  __props.hasSubtable ? (openBlock(), createElementBlock("td", mergeProps({
850
903
  key: 1,
851
904
  ref_for: true
852
- }, expandAttrs()), [createElementVNode("button", {
905
+ }, expandAttrs()), [__props.canExpand(item.row, item.index) ? (openBlock(), createElementBlock("button", {
906
+ key: 0,
853
907
  type: "button",
854
908
  class: "qt-expand",
855
- "aria-expanded": __props.isExpanded(item.row, item.index),
909
+ "aria-expanded": isRowExpanded(item),
856
910
  "aria-label": __props.labels.expandRow,
857
911
  onClick: ($event) => __props.toggle(item.row, item.index)
858
- }, [(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),
912
+ }, [(openBlock(), createElementBlock("svg", _hoisted_5$1, [isRowExpanded(item) ? (openBlock(), createElementBlock("polyline", _hoisted_6$1)) : (openBlock(), createElementBlock("polyline", _hoisted_7$1))]))], 8, _hoisted_4$4)) : createCommentVNode("", true)], 16)) : createCommentVNode("", true),
859
913
  __props.hasSelection ? (openBlock(), createElementBlock("td", mergeProps({
860
914
  key: 2,
861
915
  ref_for: true
@@ -875,15 +929,15 @@ var table_body_default = /* @__PURE__ */ defineComponent({
875
929
  ref_for: true
876
930
  }, unref(cellAttrs)(entry), { "data-flash": __props.flash ? __props.flash.cell(item.row, item.index, entry.column.field) : void 0 }), toDisplayString(unref(cellText)(item.row, entry.column)), 17, _hoisted_10))], 64);
877
931
  }), 128))
878
- ], 8, _hoisted_2$5), __props.isExpanded(item.row, item.index) ? (openBlock(), createElementBlock("tr", {
879
- key: 0,
932
+ ], 8, _hoisted_2$5)), !isSpacer(item) && isRowExpanded(item) ? (openBlock(), createElementBlock("tr", {
933
+ key: 2,
880
934
  class: "qt-subtable-row",
881
935
  "aria-rowindex": nextIndex(item.aria),
882
936
  "data-pinned-row": item.pinned || void 0
883
937
  }, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "subtable", {
884
938
  row: item.row,
885
939
  rowIndex: item.index
886
- })], 8, _hoisted_12)], 8, _hoisted_11)) : createCommentVNode("", true)], 64))], 64);
940
+ })], 8, _hoisted_12)], 8, _hoisted_11)) : createCommentVNode("", true)], 64);
887
941
  }), 128)),
888
942
  __props.loading && slots.loading ? (openBlock(), createElementBlock("tr", _hoisted_13, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "loading")], 8, _hoisted_14)])) : !__props.loading && __props.rows.length === 0 && slots.empty ? (openBlock(), createElementBlock("tr", _hoisted_15, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "empty")], 8, _hoisted_16)])) : createCommentVNode("", true),
889
943
  !__props.loading && __props.rows.length > 0 && __props.loadMore && slots["load-more"] ? (openBlock(), createElementBlock("tr", _hoisted_17, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "load-more", normalizeProps(guardReactiveProps(__props.loadMore)))], 8, _hoisted_18)])) : createCommentVNode("", true)
@@ -1618,7 +1672,7 @@ var useHeaderGeometry = (options) => {
1618
1672
  let observer = null;
1619
1673
  const headerCells = (table) => table.querySelectorAll(":scope > thead > tr > *");
1620
1674
  const measure = (table) => {
1621
- tableWidth.value = table.getBoundingClientRect().width;
1675
+ tableWidth.value = Math.round(table.getBoundingClientRect().width);
1622
1676
  const cells = options.cells();
1623
1677
  const next = {};
1624
1678
  const nextOffsets = {};
@@ -1627,7 +1681,7 @@ var useHeaderGeometry = (options) => {
1627
1681
  headerCells(table).forEach((cell, index) => {
1628
1682
  const drawn = cells[index];
1629
1683
  if (drawn) {
1630
- const width = cell.getBoundingClientRect().width;
1684
+ const width = Math.round(cell.getBoundingClientRect().width);
1631
1685
  next[drawn.key] = width;
1632
1686
  if (drawn.side === "left") {
1633
1687
  nextOffsets[drawn.key] = left;
@@ -1866,6 +1920,11 @@ function useQueryTable(options) {
1866
1920
  const columns = () => toValue(options.columns);
1867
1921
  const rowKey = () => toValue(options.rowKey);
1868
1922
  const hasSubtable = () => toValue(options.hasSubtable) ?? false;
1923
+ const canExpand = (row, index) => {
1924
+ if (!hasSubtable()) return false;
1925
+ const expandable = toValue(options.rowExpandable);
1926
+ return expandable === void 0 || expandable(row, index);
1927
+ };
1869
1928
  const pinnedRows = () => toValue(options.rowPinning);
1870
1929
  const pinningEnabled = computed(() => rowKey() !== void 0 && pinnedRows() !== void 0);
1871
1930
  const rowPinningState = computed(() => {
@@ -1938,7 +1997,7 @@ function useQueryTable(options) {
1938
1997
  },
1939
1998
  enableRowSelection: true,
1940
1999
  manualExpanding: true,
1941
- getRowCanExpand: () => hasSubtable(),
2000
+ getRowCanExpand: (row) => canExpand(row.original, row.index),
1942
2001
  onRowSelectionChange: (updater) => {
1943
2002
  const current = toValue(options.selection) ?? {};
1944
2003
  options.onSelectionChange?.(selectedOnly(functionalUpdate(updater, current)));
@@ -2195,17 +2254,19 @@ function useQueryTable(options) {
2195
2254
  cursorMode
2196
2255
  };
2197
2256
  });
2198
- const expanded = () => {
2257
+ const expandedState = computed(() => {
2199
2258
  const state = table.atoms.expanded.get();
2200
2259
  return state === true ? {} : state;
2201
- };
2260
+ });
2202
2261
  const setExpanded = (update) => {
2203
2262
  table.setExpanded((old) => update(old === true ? {} : { ...old }));
2204
2263
  };
2205
2264
  const expansion = {
2206
2265
  keyOf,
2207
- isExpanded: (row, index) => hasSubtable() && !!expanded()[idOf(row, index)],
2266
+ canExpand,
2267
+ isExpanded: (row, index) => !!expandedState.value[idOf(row, index)] && canExpand(row, index),
2208
2268
  toggle: (row, index) => {
2269
+ if (!canExpand(row, index)) return;
2209
2270
  const id = idOf(row, index);
2210
2271
  setExpanded((state) => {
2211
2272
  if (state[id]) delete state[id];
@@ -2217,7 +2278,7 @@ function useQueryTable(options) {
2217
2278
  expandAll: () => {
2218
2279
  if (hasSubtable()) setExpanded((state) => {
2219
2280
  rows().forEach((row, index) => {
2220
- state[idOf(row, index)] = true;
2281
+ if (canExpand(row, index)) state[idOf(row, index)] = true;
2221
2282
  });
2222
2283
  return state;
2223
2284
  });
@@ -2232,7 +2293,8 @@ function useQueryTable(options) {
2232
2293
  }
2233
2294
  if (hasSubtable()) current.forEach((row, index) => {
2234
2295
  const seeded = row.isExpanded;
2235
- if (seeded === true) state[idOf(row, index)] = true;
2296
+ if (!canExpand(row, index)) delete state[idOf(row, index)];
2297
+ else if (seeded === true) state[idOf(row, index)] = true;
2236
2298
  else if (seeded === false) delete state[idOf(row, index)];
2237
2299
  });
2238
2300
  return state;
@@ -3000,6 +3062,14 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3000
3062
  type: Boolean,
3001
3063
  default: false
3002
3064
  },
3065
+ rowExpandable: {
3066
+ type: Function,
3067
+ default: void 0
3068
+ },
3069
+ rowKind: {
3070
+ type: Function,
3071
+ default: void 0
3072
+ },
3003
3073
  hasRightPanel: {
3004
3074
  type: Boolean,
3005
3075
  default: false
@@ -3028,6 +3098,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3028
3098
  "update:selection",
3029
3099
  "rowRightPanelClick",
3030
3100
  "cellContextMenu",
3101
+ "headerContextMenu",
3031
3102
  "columnResize",
3032
3103
  "update:columns",
3033
3104
  "update:rowPinning"
@@ -3050,6 +3121,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3050
3121
  rowPinning: () => props.rowPinning,
3051
3122
  rowKey: () => props.rowKey,
3052
3123
  hasSubtable: () => props.hasSubtable,
3124
+ rowExpandable: () => props.rowExpandable,
3053
3125
  pageSizeOptions: () => props.pagination?.pageSizeOptions,
3054
3126
  onQueryChange: (query, reason) => emit("update:query", query, reason),
3055
3127
  onSelectionChange: (selection) => emit("update:selection", selection),
@@ -3065,8 +3137,18 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3065
3137
  const vnodeProps = instance?.vnode.props;
3066
3138
  return !!(vnodeProps?.onCellContextMenu || vnodeProps?.onCellContextMenuOnce);
3067
3139
  };
3140
+ const hasHeaderContextMenuListener = () => {
3141
+ const vnodeProps = instance?.vnode.props;
3142
+ return !!(vnodeProps?.onHeaderContextMenu || vnodeProps?.onHeaderContextMenuOnce);
3143
+ };
3068
3144
  const entries = state.columns;
3069
3145
  const visibleColumns = computed(() => entries.value.map((e) => e.column));
3146
+ const { onContextMenu: onHeaderContextMenu } = useHeaderContextMenu({
3147
+ columns: () => visibleColumns.value,
3148
+ indexOf: (field) => entries.value.find((e) => e.column.field === field)?.index,
3149
+ listening: () => hasHeaderContextMenuListener(),
3150
+ onContextMenu: (payload) => emit("headerContextMenu", payload)
3151
+ });
3070
3152
  const hasPinned = state.hasPinned;
3071
3153
  /** Right panel first, then subtable, then selection (C-22: the first hosts clear-all). */
3072
3154
  const utilities = computed(() => [
@@ -3203,7 +3285,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3203
3285
  class: "qt-table",
3204
3286
  "aria-rowcount": ariaRowCount.value
3205
3287
  }, [
3206
- createElementVNode("thead", null, [createVNode(table_header_default, {
3288
+ createElementVNode("thead", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onHeaderContextMenu) && unref(onHeaderContextMenu)(...args)) }, [createVNode(table_header_default, {
3207
3289
  columns: visibleColumns.value,
3208
3290
  query: __props.query,
3209
3291
  filterable: __props.filterable,
@@ -3226,7 +3308,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3226
3308
  "offsets",
3227
3309
  "slot-names",
3228
3310
  "aria-rowindex"
3229
- ])]),
3311
+ ])], 32),
3230
3312
  createVNode(table_body_default, {
3231
3313
  rows: __props.rows,
3232
3314
  "body-rows": unref(rowWindow).drawn.value,
@@ -3242,14 +3324,16 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3242
3324
  "has-pinned": unref(hasPinned),
3243
3325
  offsets: unref(offsets),
3244
3326
  "key-of": unref(expansion).keyOf,
3327
+ "can-expand": unref(expansion).canExpand,
3245
3328
  "is-expanded": unref(expansion).isExpanded,
3246
3329
  toggle: unref(expansion).toggle,
3330
+ "row-kind": __props.rowKind,
3247
3331
  labels: labels.value,
3248
3332
  "has-context-menu-listener": hasContextMenuListener,
3249
3333
  "load-more": loadMoreProps.value,
3250
3334
  flash: unref(flashView),
3251
- onRowRightPanelClick: _cache[0] || (_cache[0] = (row) => emit("rowRightPanelClick", row)),
3252
- onCellContextMenu: _cache[1] || (_cache[1] = (payload) => emit("cellContextMenu", payload)),
3335
+ onRowRightPanelClick: _cache[1] || (_cache[1] = (row) => emit("rowRightPanelClick", row)),
3336
+ onCellContextMenu: _cache[2] || (_cache[2] = (payload) => emit("cellContextMenu", payload)),
3253
3337
  onFocusin: unref(rowWindow).onFocusIn,
3254
3338
  onFocusout: unref(rowWindow).onFocusOut
3255
3339
  }, createSlots({ _: 2 }, [renderList(bodySlotNames(), (name) => {
@@ -3272,8 +3356,10 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3272
3356
  "has-pinned",
3273
3357
  "offsets",
3274
3358
  "key-of",
3359
+ "can-expand",
3275
3360
  "is-expanded",
3276
3361
  "toggle",
3362
+ "row-kind",
3277
3363
  "labels",
3278
3364
  "load-more",
3279
3365
  "flash",