@dolusoft/query-table 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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);
@@ -800,6 +831,21 @@ var table_body_default = /* @__PURE__ */ defineComponent({
800
831
  const isSpacer = (item) => "spacer" in item;
801
832
  /** `aria-rowindex` of the subtable row under a drawn row (C-86). */
802
833
  const nextIndex = (aria) => aria === void 0 ? void 0 : aria + 1;
834
+ let expandedSnapshot = null;
835
+ onBeforeUpdate(() => {
836
+ expandedSnapshot = null;
837
+ });
838
+ const isRowExpanded = (item) => {
839
+ if (isSpacer(item)) return false;
840
+ if (!expandedSnapshot) {
841
+ const open = /* @__PURE__ */ new Map();
842
+ if (props.hasSubtable) {
843
+ for (const row of props.bodyRows) if (!isSpacer(row)) open.set(String(props.keyOf(row.row, row.index)), props.isExpanded(row.row, row.index));
844
+ }
845
+ expandedSnapshot = open;
846
+ }
847
+ return expandedSnapshot.get(String(props.keyOf(item.row, item.index))) === true;
848
+ };
803
849
  return (_ctx, _cache) => {
804
850
  return openBlock(), createElementBlock("tbody", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onContextMenu) && unref(onContextMenu)(...args)) }, [
805
851
  (openBlock(true), createElementBlock(Fragment, null, renderList(__props.bodyRows, (item) => {
@@ -808,11 +854,12 @@ var table_body_default = /* @__PURE__ */ defineComponent({
808
854
  class: "qt-virtual-spacer",
809
855
  "aria-hidden": "true",
810
856
  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", {
857
+ }, [createElementVNode("td", { colspan: __props.columnCount }, null, 8, _hoisted_1$9)], 4)) : (openBlock(), createElementBlock("tr", {
858
+ key: 1,
812
859
  "data-row-index": item.index,
813
860
  "aria-rowindex": item.aria,
814
861
  "data-pinned-row": item.pinned || void 0,
815
- "data-expanded": __props.isExpanded(item.row, item.index) ? "" : void 0,
862
+ "data-expanded": isRowExpanded(item) ? "" : void 0,
816
863
  "data-selected": __props.hasSelection && __props.isSelected(item.row, item.index) ? "" : void 0,
817
864
  "data-flash": __props.flash ? __props.flash.row(item.row, item.index) : void 0,
818
865
  onVnodeBeforeMount: __props.flash ? __props.flash.bind : void 0,
@@ -852,10 +899,10 @@ var table_body_default = /* @__PURE__ */ defineComponent({
852
899
  }, expandAttrs()), [createElementVNode("button", {
853
900
  type: "button",
854
901
  class: "qt-expand",
855
- "aria-expanded": __props.isExpanded(item.row, item.index),
902
+ "aria-expanded": isRowExpanded(item),
856
903
  "aria-label": __props.labels.expandRow,
857
904
  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),
905
+ }, [(openBlock(), createElementBlock("svg", _hoisted_5$1, [isRowExpanded(item) ? (openBlock(), createElementBlock("polyline", _hoisted_6$1)) : (openBlock(), createElementBlock("polyline", _hoisted_7$1))]))], 8, _hoisted_4$4)], 16)) : createCommentVNode("", true),
859
906
  __props.hasSelection ? (openBlock(), createElementBlock("td", mergeProps({
860
907
  key: 2,
861
908
  ref_for: true
@@ -875,15 +922,15 @@ var table_body_default = /* @__PURE__ */ defineComponent({
875
922
  ref_for: true
876
923
  }, unref(cellAttrs)(entry), { "data-flash": __props.flash ? __props.flash.cell(item.row, item.index, entry.column.field) : void 0 }), toDisplayString(unref(cellText)(item.row, entry.column)), 17, _hoisted_10))], 64);
877
924
  }), 128))
878
- ], 8, _hoisted_2$5), __props.isExpanded(item.row, item.index) ? (openBlock(), createElementBlock("tr", {
879
- key: 0,
925
+ ], 8, _hoisted_2$5)), !isSpacer(item) && isRowExpanded(item) ? (openBlock(), createElementBlock("tr", {
926
+ key: 2,
880
927
  class: "qt-subtable-row",
881
928
  "aria-rowindex": nextIndex(item.aria),
882
929
  "data-pinned-row": item.pinned || void 0
883
930
  }, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "subtable", {
884
931
  row: item.row,
885
932
  rowIndex: item.index
886
- })], 8, _hoisted_12)], 8, _hoisted_11)) : createCommentVNode("", true)], 64))], 64);
933
+ })], 8, _hoisted_12)], 8, _hoisted_11)) : createCommentVNode("", true)], 64);
887
934
  }), 128)),
888
935
  __props.loading && slots.loading ? (openBlock(), createElementBlock("tr", _hoisted_13, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "loading")], 8, _hoisted_14)])) : !__props.loading && __props.rows.length === 0 && slots.empty ? (openBlock(), createElementBlock("tr", _hoisted_15, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "empty")], 8, _hoisted_16)])) : createCommentVNode("", true),
889
936
  !__props.loading && __props.rows.length > 0 && __props.loadMore && slots["load-more"] ? (openBlock(), createElementBlock("tr", _hoisted_17, [createElementVNode("td", { colspan: __props.columnCount }, [renderSlot(_ctx.$slots, "load-more", normalizeProps(guardReactiveProps(__props.loadMore)))], 8, _hoisted_18)])) : createCommentVNode("", true)
@@ -1618,7 +1665,7 @@ var useHeaderGeometry = (options) => {
1618
1665
  let observer = null;
1619
1666
  const headerCells = (table) => table.querySelectorAll(":scope > thead > tr > *");
1620
1667
  const measure = (table) => {
1621
- tableWidth.value = table.getBoundingClientRect().width;
1668
+ tableWidth.value = Math.round(table.getBoundingClientRect().width);
1622
1669
  const cells = options.cells();
1623
1670
  const next = {};
1624
1671
  const nextOffsets = {};
@@ -1627,7 +1674,7 @@ var useHeaderGeometry = (options) => {
1627
1674
  headerCells(table).forEach((cell, index) => {
1628
1675
  const drawn = cells[index];
1629
1676
  if (drawn) {
1630
- const width = cell.getBoundingClientRect().width;
1677
+ const width = Math.round(cell.getBoundingClientRect().width);
1631
1678
  next[drawn.key] = width;
1632
1679
  if (drawn.side === "left") {
1633
1680
  nextOffsets[drawn.key] = left;
@@ -2195,16 +2242,16 @@ function useQueryTable(options) {
2195
2242
  cursorMode
2196
2243
  };
2197
2244
  });
2198
- const expanded = () => {
2245
+ const expandedState = computed(() => {
2199
2246
  const state = table.atoms.expanded.get();
2200
2247
  return state === true ? {} : state;
2201
- };
2248
+ });
2202
2249
  const setExpanded = (update) => {
2203
2250
  table.setExpanded((old) => update(old === true ? {} : { ...old }));
2204
2251
  };
2205
2252
  const expansion = {
2206
2253
  keyOf,
2207
- isExpanded: (row, index) => hasSubtable() && !!expanded()[idOf(row, index)],
2254
+ isExpanded: (row, index) => hasSubtable() && !!expandedState.value[idOf(row, index)],
2208
2255
  toggle: (row, index) => {
2209
2256
  const id = idOf(row, index);
2210
2257
  setExpanded((state) => {
@@ -3028,6 +3075,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3028
3075
  "update:selection",
3029
3076
  "rowRightPanelClick",
3030
3077
  "cellContextMenu",
3078
+ "headerContextMenu",
3031
3079
  "columnResize",
3032
3080
  "update:columns",
3033
3081
  "update:rowPinning"
@@ -3065,8 +3113,18 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3065
3113
  const vnodeProps = instance?.vnode.props;
3066
3114
  return !!(vnodeProps?.onCellContextMenu || vnodeProps?.onCellContextMenuOnce);
3067
3115
  };
3116
+ const hasHeaderContextMenuListener = () => {
3117
+ const vnodeProps = instance?.vnode.props;
3118
+ return !!(vnodeProps?.onHeaderContextMenu || vnodeProps?.onHeaderContextMenuOnce);
3119
+ };
3068
3120
  const entries = state.columns;
3069
3121
  const visibleColumns = computed(() => entries.value.map((e) => e.column));
3122
+ const { onContextMenu: onHeaderContextMenu } = useHeaderContextMenu({
3123
+ columns: () => visibleColumns.value,
3124
+ indexOf: (field) => entries.value.find((e) => e.column.field === field)?.index,
3125
+ listening: () => hasHeaderContextMenuListener(),
3126
+ onContextMenu: (payload) => emit("headerContextMenu", payload)
3127
+ });
3070
3128
  const hasPinned = state.hasPinned;
3071
3129
  /** Right panel first, then subtable, then selection (C-22: the first hosts clear-all). */
3072
3130
  const utilities = computed(() => [
@@ -3203,7 +3261,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3203
3261
  class: "qt-table",
3204
3262
  "aria-rowcount": ariaRowCount.value
3205
3263
  }, [
3206
- createElementVNode("thead", null, [createVNode(table_header_default, {
3264
+ createElementVNode("thead", { onContextmenu: _cache[0] || (_cache[0] = (...args) => unref(onHeaderContextMenu) && unref(onHeaderContextMenu)(...args)) }, [createVNode(table_header_default, {
3207
3265
  columns: visibleColumns.value,
3208
3266
  query: __props.query,
3209
3267
  filterable: __props.filterable,
@@ -3226,7 +3284,7 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3226
3284
  "offsets",
3227
3285
  "slot-names",
3228
3286
  "aria-rowindex"
3229
- ])]),
3287
+ ])], 32),
3230
3288
  createVNode(table_body_default, {
3231
3289
  rows: __props.rows,
3232
3290
  "body-rows": unref(rowWindow).drawn.value,
@@ -3248,8 +3306,8 @@ var query_table_default = /* @__PURE__ */ defineComponent({
3248
3306
  "has-context-menu-listener": hasContextMenuListener,
3249
3307
  "load-more": loadMoreProps.value,
3250
3308
  flash: unref(flashView),
3251
- onRowRightPanelClick: _cache[0] || (_cache[0] = (row) => emit("rowRightPanelClick", row)),
3252
- onCellContextMenu: _cache[1] || (_cache[1] = (payload) => emit("cellContextMenu", payload)),
3309
+ onRowRightPanelClick: _cache[1] || (_cache[1] = (row) => emit("rowRightPanelClick", row)),
3310
+ onCellContextMenu: _cache[2] || (_cache[2] = (payload) => emit("cellContextMenu", payload)),
3253
3311
  onFocusin: unref(rowWindow).onFocusIn,
3254
3312
  onFocusout: unref(rowWindow).onFocusOut
3255
3313
  }, createSlots({ _: 2 }, [renderList(bodySlotNames(), (name) => {