@toolbox-web/grid 1.19.0 → 1.19.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.
package/all.js CHANGED
@@ -5595,7 +5595,8 @@ class Bn extends F {
5595
5595
  return {
5596
5596
  mode: "cell",
5597
5597
  triggerOn: "click",
5598
- enabled: !0
5598
+ enabled: !0,
5599
+ multiSelect: !0
5599
5600
  };
5600
5601
  }
5601
5602
  selected = /* @__PURE__ */ new Set();
@@ -5661,13 +5662,13 @@ class Bn extends F {
5661
5662
  if (r === "row") {
5662
5663
  if (!this.isRowSelectable(t))
5663
5664
  return !1;
5664
- const d = n.shiftKey, c = n.ctrlKey || n.metaKey, u = s?.meta?.checkboxColumn === !0;
5665
- if (d && this.anchor !== null) {
5666
- const h = Math.min(this.anchor, t), f = Math.max(this.anchor, t);
5667
- c || this.selected.clear();
5668
- for (let g = h; g <= f; g++)
5669
- this.isRowSelectable(g) && this.selected.add(g);
5670
- } else if (c || u)
5665
+ const d = this.config.multiSelect !== !1, c = n.shiftKey && d, u = (n.ctrlKey || n.metaKey) && d, h = s?.meta?.checkboxColumn === !0;
5666
+ if (c && this.anchor !== null) {
5667
+ const f = Math.min(this.anchor, t), g = Math.max(this.anchor, t);
5668
+ u || this.selected.clear();
5669
+ for (let p = f; p <= g; p++)
5670
+ this.isRowSelectable(p) && this.selected.add(p);
5671
+ } else if (u || h && d)
5671
5672
  this.selected.has(t) ? this.selected.delete(t) : this.selected.add(t), this.anchor = t;
5672
5673
  else {
5673
5674
  if (this.selected.size === 1 && this.selected.has(t))
@@ -5679,7 +5680,7 @@ class Bn extends F {
5679
5680
  if (r === "range") {
5680
5681
  if (l || !this.isCellSelectable(t, i))
5681
5682
  return !1;
5682
- const d = n.shiftKey, c = n.ctrlKey || n.metaKey;
5683
+ const d = n.shiftKey, c = (n.ctrlKey || n.metaKey) && this.config.multiSelect !== !1;
5683
5684
  if (d && this.cellAnchor) {
5684
5685
  const u = ge(this.cellAnchor, { row: t, col: i }), h = this.ranges.length > 0 ? this.ranges[this.ranges.length - 1] : null;
5685
5686
  if (h && ee(h, u))
@@ -5719,28 +5720,29 @@ class Bn extends F {
5719
5720
  this.isCellSelectable(r, o) ? this.selectedCell = { row: r, col: o } : this.selectedCell = null, this.emit("selection-change", this.#i()), this.requestAfterRender();
5720
5721
  }), !1;
5721
5722
  if (t === "row") {
5723
+ const r = this.config.multiSelect !== !1;
5722
5724
  if (e.key === "ArrowUp" || e.key === "ArrowDown") {
5723
- const r = e.shiftKey;
5724
- return r && this.anchor === null && (this.anchor = this.grid._focusRow), queueMicrotask(() => {
5725
- const o = this.grid._focusRow;
5726
- if (r && this.anchor !== null) {
5725
+ const o = e.shiftKey && r;
5726
+ return o && this.anchor === null && (this.anchor = this.grid._focusRow), queueMicrotask(() => {
5727
+ const s = this.grid._focusRow;
5728
+ if (o && this.anchor !== null) {
5727
5729
  this.selected.clear();
5728
- const s = Math.min(this.anchor, o), l = Math.max(this.anchor, o);
5729
- for (let d = s; d <= l; d++)
5730
- this.isRowSelectable(d) && this.selected.add(d);
5730
+ const l = Math.min(this.anchor, s), d = Math.max(this.anchor, s);
5731
+ for (let c = l; c <= d; c++)
5732
+ this.isRowSelectable(c) && this.selected.add(c);
5731
5733
  } else
5732
- this.isRowSelectable(o) ? (this.selected.clear(), this.selected.add(o), this.anchor = o) : this.selected.clear();
5733
- this.lastSelected = o, this.explicitSelection = !0, this.emit("selection-change", this.#i()), this.requestAfterRender();
5734
+ this.isRowSelectable(s) ? (this.selected.clear(), this.selected.add(s), this.anchor = s) : this.selected.clear();
5735
+ this.lastSelected = s, this.explicitSelection = !0, this.emit("selection-change", this.#i()), this.requestAfterRender();
5734
5736
  }), !1;
5735
5737
  }
5736
- if (e.key === "a" && (e.ctrlKey || e.metaKey))
5738
+ if (r && e.key === "a" && (e.ctrlKey || e.metaKey))
5737
5739
  return this.grid.query("isEditing").some(Boolean) ? !1 : (e.preventDefault(), e.stopPropagation(), this.selectAll(), !0);
5738
5740
  }
5739
5741
  if (t === "range" && n) {
5740
5742
  const r = e.key === "Tab", o = e.shiftKey && !r;
5741
5743
  return o && !this.cellAnchor && (this.cellAnchor = { row: this.grid._focusRow, col: this.grid._focusCol }), this.pendingKeyboardUpdate = { shiftKey: o }, queueMicrotask(() => this.requestAfterRender()), !1;
5742
5744
  }
5743
- return t === "range" && e.key === "a" && (e.ctrlKey || e.metaKey) ? this.grid.query("isEditing").some(Boolean) ? !1 : (e.preventDefault(), e.stopPropagation(), this.selectAll(), !0) : !1;
5745
+ return t === "range" && this.config.multiSelect !== !1 && e.key === "a" && (e.ctrlKey || e.metaKey) ? this.grid.query("isEditing").some(Boolean) ? !1 : (e.preventDefault(), e.stopPropagation(), this.selectAll(), !0) : !1;
5744
5746
  }
5745
5747
  onCellMouseDown(e) {
5746
5748
  if (!this.isSelectionEnabled() || this.config.mode !== "range" || e.rowIndex === void 0 || e.colIndex === void 0 || e.rowIndex < 0) return;
@@ -5748,7 +5750,7 @@ class Bn extends F {
5748
5750
  if (t && W(t) || !this.isCellSelectable(e.rowIndex, e.colIndex) || e.originalEvent.shiftKey && this.cellAnchor)
5749
5751
  return;
5750
5752
  this.isDragging = !0;
5751
- const i = e.rowIndex, n = e.colIndex, r = e.originalEvent.ctrlKey || e.originalEvent.metaKey, o = {
5753
+ const i = e.rowIndex, n = e.colIndex, r = (e.originalEvent.ctrlKey || e.originalEvent.metaKey) && this.config.multiSelect !== !1, o = {
5752
5754
  startRow: i,
5753
5755
  startCol: n,
5754
5756
  endRow: i,
@@ -5795,7 +5797,7 @@ class Bn extends F {
5795
5797
  },
5796
5798
  headerRenderer: () => {
5797
5799
  const e = document.createElement("div");
5798
- e.className = "tbw-checkbox-header";
5800
+ if (e.className = "tbw-checkbox-header", this.config.multiSelect === !1) return e;
5799
5801
  const t = document.createElement("input");
5800
5802
  return t.type = "checkbox", t.className = "tbw-select-all-checkbox", t.addEventListener("click", (i) => {
5801
5803
  i.stopPropagation(), i.target.checked ? this.selectAll() : this.clearSelection();
@@ -5920,32 +5922,34 @@ class Bn extends F {
5920
5922
  return cn(e, t, this.ranges);
5921
5923
  }
5922
5924
  selectAll() {
5923
- const { mode: e } = this.config;
5924
- if (e === "row") {
5925
- this.selected.clear();
5926
- for (let t = 0; t < this.rows.length; t++)
5927
- this.isRowSelectable(t) && this.selected.add(t);
5928
- this.explicitSelection = !0, this.emit("selection-change", this.#i()), this.requestAfterRender();
5929
- } else if (e === "range") {
5930
- const t = this.rows.length, i = this.columns.length;
5931
- if (t > 0 && i > 0) {
5932
- const n = {
5933
- startRow: 0,
5934
- startCol: 0,
5935
- endRow: t - 1,
5936
- endCol: i - 1
5937
- };
5938
- this.ranges = [n], this.activeRange = n, this.emit("selection-change", this.#i()), this.requestAfterRender();
5925
+ const { mode: e, multiSelect: t } = this.config;
5926
+ if (t !== !1) {
5927
+ if (e === "row") {
5928
+ this.selected.clear();
5929
+ for (let i = 0; i < this.rows.length; i++)
5930
+ this.isRowSelectable(i) && this.selected.add(i);
5931
+ this.explicitSelection = !0, this.emit("selection-change", this.#i()), this.requestAfterRender();
5932
+ } else if (e === "range") {
5933
+ const i = this.rows.length, n = this.columns.length;
5934
+ if (i > 0 && n > 0) {
5935
+ const r = {
5936
+ startRow: 0,
5937
+ startCol: 0,
5938
+ endRow: i - 1,
5939
+ endCol: n - 1
5940
+ };
5941
+ this.ranges = [r], this.activeRange = r, this.emit("selection-change", this.#i()), this.requestAfterRender();
5942
+ }
5939
5943
  }
5940
5944
  }
5941
5945
  }
5942
5946
  selectRows(e) {
5943
- if (this.config.mode === "row") {
5944
- this.selected.clear();
5945
- for (const t of e)
5946
- t >= 0 && t < this.rows.length && this.isRowSelectable(t) && this.selected.add(t);
5947
- this.anchor = e.length > 0 ? e[e.length - 1] : null, this.explicitSelection = !0, this.emit("selection-change", this.#i()), this.requestAfterRender();
5948
- }
5947
+ if (this.config.mode !== "row") return;
5948
+ const t = this.config.multiSelect === !1 && e.length > 1 ? [e[e.length - 1]] : e;
5949
+ this.selected.clear();
5950
+ for (const i of t)
5951
+ i >= 0 && i < this.rows.length && this.isRowSelectable(i) && this.selected.add(i);
5952
+ this.anchor = t.length > 0 ? t[t.length - 1] : null, this.explicitSelection = !0, this.emit("selection-change", this.#i()), this.requestAfterRender();
5949
5953
  }
5950
5954
  getSelectedRowIndices() {
5951
5955
  return [...this.selected].sort((e, t) => e - t);