@iyulab/flex-table 0.55.2 → 0.56.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.
@@ -1059,25 +1059,25 @@ function E(e, t) {
1059
1059
  //#endregion
1060
1060
  //#region src/renderers/cell-renderer.ts
1061
1061
  function D(e, t, n) {
1062
- return n.render ? n.render(e, t, n) : n.format ? typeof n.format == "function" ? n.format(e, t, n) : C(e, n.format) : O(e, n);
1062
+ return n.render ? n.render(e, t, n) : n.format ? typeof n.format == "function" ? n.format(e, t, n) : C(e, n.format) : ee(e, n);
1063
1063
  }
1064
- function O(e, t) {
1064
+ function ee(e, t) {
1065
1065
  if (e == null) return "";
1066
1066
  switch (t.type) {
1067
- case "number": return ne(e);
1067
+ case "number": return re(e);
1068
1068
  case "boolean": return a`<span class="ft-bool">${e ? "✔" : ""}</span>`;
1069
- case "date": return re(e);
1070
- case "datetime": return ie(e);
1071
- case "select": return ee(e, t);
1069
+ case "date": return ie(e);
1070
+ case "datetime": return ae(e);
1071
+ case "select": return te(e, t);
1072
1072
  default: return String(e);
1073
1073
  }
1074
1074
  }
1075
- function ee(e, t) {
1075
+ function te(e, t) {
1076
1076
  if (!t.options || t.options.length === 0 || typeof t.options[0] == "string") return e == null ? "" : String(e);
1077
1077
  let n = t.options.find((t) => t.value === e);
1078
1078
  return n ? n.label : e == null ? "" : String(e);
1079
1079
  }
1080
- var te = {
1080
+ var ne = {
1081
1081
  year: "numeric",
1082
1082
  month: "numeric",
1083
1083
  day: "numeric",
@@ -1085,18 +1085,18 @@ var te = {
1085
1085
  minute: "numeric",
1086
1086
  second: "numeric"
1087
1087
  };
1088
- function ne(e) {
1088
+ function re(e) {
1089
1089
  return typeof e == "number" ? Number.isInteger(e) ? f(e) : f(e, { minimumFractionDigits: 1 }) : String(e);
1090
1090
  }
1091
- function re(e) {
1091
+ function ie(e) {
1092
1092
  return e instanceof Date || typeof e == "string" ? d(e) : String(e);
1093
1093
  }
1094
- function ie(e) {
1095
- return e instanceof Date || typeof e == "string" ? d(e, te) : String(e);
1094
+ function ae(e) {
1095
+ return e instanceof Date || typeof e == "string" ? d(e, ne) : String(e);
1096
1096
  }
1097
1097
  //#endregion
1098
1098
  //#region src/core/selection.ts
1099
- function ae(e) {
1099
+ function oe(e) {
1100
1100
  return {
1101
1101
  startRow: Math.min(e.startRow, e.endRow),
1102
1102
  startCol: Math.min(e.startCol, e.endCol),
@@ -1104,7 +1104,7 @@ function ae(e) {
1104
1104
  endCol: Math.max(e.startCol, e.endCol)
1105
1105
  };
1106
1106
  }
1107
- var oe = class {
1107
+ var se = class {
1108
1108
  constructor() {
1109
1109
  this.activeCell = null, this.rangeAnchor = null, this.range = null, this.extraRanges = [], this._rowCount = 0, this._colCount = 0;
1110
1110
  }
@@ -1131,7 +1131,7 @@ var oe = class {
1131
1131
  return e < 0 || e >= this._rowCount || t < 0 || t >= this._colCount ? this.activeCell : (!this.rangeAnchor && this.activeCell && (this.rangeAnchor = { ...this.activeCell }), this.activeCell = {
1132
1132
  row: e,
1133
1133
  col: t
1134
- }, this.rangeAnchor && (this.range = ae({
1134
+ }, this.rangeAnchor && (this.range = oe({
1135
1135
  startRow: this.rangeAnchor.row,
1136
1136
  startCol: this.rangeAnchor.col,
1137
1137
  endRow: e,
@@ -1202,14 +1202,15 @@ var oe = class {
1202
1202
  shiftMoveRight() {
1203
1203
  return this.activeCell ? this.setActiveWithRange(this.activeCell.row, this.activeCell.col + 1) : null;
1204
1204
  }
1205
- }, se = class {
1205
+ }, ce = class {
1206
1206
  constructor() {
1207
1207
  this.current = null;
1208
1208
  }
1209
- start(e, t) {
1209
+ start(e, t, n) {
1210
1210
  this.current = {
1211
1211
  position: e,
1212
- originalValue: t
1212
+ originalValue: t,
1213
+ row: n
1213
1214
  };
1214
1215
  }
1215
1216
  isEditing(e, t) {
@@ -1223,9 +1224,9 @@ var oe = class {
1223
1224
  let e = this.current;
1224
1225
  return this.current = null, e;
1225
1226
  }
1226
- }, k = class {
1227
+ }, O = class {
1227
1228
  constructor() {
1228
- this._selected = /* @__PURE__ */ new Set(), this._mode = "multi", this._rowCount = 0;
1229
+ this._selected = /* @__PURE__ */ new Set(), this._mode = "multi";
1229
1230
  }
1230
1231
  get mode() {
1231
1232
  return this._mode;
@@ -1236,27 +1237,24 @@ var oe = class {
1236
1237
  this._selected.clear(), e !== void 0 && this._selected.add(e);
1237
1238
  }
1238
1239
  }
1239
- setRowCount(e) {
1240
- this._rowCount = e;
1241
- for (let t of this._selected) t >= e && this._selected.delete(t);
1242
- }
1243
- get selectedIndices() {
1244
- return [...this._selected].sort((e, t) => e - t);
1240
+ get selectedIds() {
1241
+ return [...this._selected];
1245
1242
  }
1246
1243
  get selectedCount() {
1247
1244
  return this._selected.size;
1248
1245
  }
1249
- get isAllSelected() {
1250
- return this._rowCount > 0 && this._selected.size === this._rowCount;
1251
- }
1252
- get isSomeSelected() {
1253
- return this._selected.size > 0 && this._selected.size < this._rowCount;
1254
- }
1255
1246
  isSelected(e) {
1256
1247
  return this._selected.has(e);
1257
1248
  }
1249
+ isAllSelected(e) {
1250
+ return e.length > 0 && e.every((e) => this._selected.has(e));
1251
+ }
1252
+ isSomeSelected(e) {
1253
+ let t = e.reduce((e, t) => e + +!!this._selected.has(t), 0);
1254
+ return t > 0 && t < e.length;
1255
+ }
1258
1256
  toggle(e) {
1259
- this._mode === "single" ? this._selected.has(e) ? this._selected.clear() : (this._selected.clear(), this._selected.add(e)) : this._selected.has(e) ? this._selected.delete(e) : this._selected.add(e);
1257
+ this._selected.has(e) ? this._selected.delete(e) : this.select(e);
1260
1258
  }
1261
1259
  select(e) {
1262
1260
  this._mode === "single" && this._selected.clear(), this._selected.add(e);
@@ -1264,27 +1262,36 @@ var oe = class {
1264
1262
  deselect(e) {
1265
1263
  this._selected.delete(e);
1266
1264
  }
1267
- selectAll() {
1268
- if (this._mode !== "single") {
1269
- this._selected.clear();
1270
- for (let e = 0; e < this._rowCount; e++) this._selected.add(e);
1271
- }
1265
+ selectAll(e) {
1266
+ if (this._mode !== "single") for (let t of e) this._selected.add(t);
1267
+ }
1268
+ deselectMany(e) {
1269
+ for (let t of e) this._selected.delete(t);
1272
1270
  }
1273
1271
  deselectAll() {
1274
1272
  this._selected.clear();
1275
1273
  }
1276
- selectRange(e, t) {
1277
- if (this._mode === "single") {
1278
- this.select(t);
1274
+ set(e) {
1275
+ let t = [...new Set(e)], n = this._mode === "single" ? t.slice(-1) : t;
1276
+ return n.length === this._selected.size && n.every((e) => this._selected.has(e)) ? !1 : (this._selected = new Set(n), !0);
1277
+ }
1278
+ retain(e) {
1279
+ let t = !1;
1280
+ for (let n of this._selected) e(n) || (this._selected.delete(n), t = !0);
1281
+ return t;
1282
+ }
1283
+ selectRange(e, t, n) {
1284
+ let r = e.indexOf(t), i = e.indexOf(n);
1285
+ if (this._mode === "single" || r < 0 || i < 0) {
1286
+ this.select(n);
1279
1287
  return;
1280
1288
  }
1281
- let n = Math.min(e, t), r = Math.max(e, t);
1282
- for (let e = n; e <= r; e++) e >= 0 && e < this._rowCount && this._selected.add(e);
1289
+ for (let t = Math.min(r, i); t <= Math.max(r, i); t++) this._selected.add(e[t]);
1283
1290
  }
1284
1291
  };
1285
1292
  //#endregion
1286
1293
  //#region src/core/filtering.ts
1287
- function ce(e, t, n) {
1294
+ function k(e, t, n) {
1288
1295
  if (t.length === 0) return Array.from({ length: e.length }, (e, t) => t);
1289
1296
  let r = [];
1290
1297
  for (let i = 0; i < e.length; i++) {
@@ -1756,7 +1763,9 @@ var K = {
1756
1763
  lte: "≤"
1757
1764
  }, q = 120, J = 40, Y = 20, X = 32, Z = 5, Xe = 200, Q = class extends r {
1758
1765
  constructor(...e) {
1759
- super(...e), this.columns = [], this._data = [], this._inUndoRedo = !1, this.clearUndoOnDataChange = !1, this.clearSelectionOnDataChange = !1, this._rowHeightFromCss = X, this._targetFloor = 0, this.showRowNumbers = !1, this.theme = void 0, this.maxRows = 0, this.editable = !0, this.showFilters = !1, this.showContextMenu = !1, this.frozenRows = 0, this.emptyMessage = "", this.noMatchingMessage = "", this.error = null, this.loading = !1, this.importEnabled = !1, this.selectable = !1, this.dataMode = "client", this.footerData = null, this.stylesheets = [], this._scrollTop = 0, this._scrollLeft = 0, this._viewportHeight = 0, this._viewportWidth = 0, this._colLeftOffsets = [], this._totalRowWidth = 0, this._baseStyleSheets = [], this._activeCell = null, this._headerCol = null, this._focusedCellEl = null, this._editingCell = null, this._sortCriteria = [], this._selection = new oe(), this._editing = new se(), this._rowSelection = new k(), this._undo = new A(), this._filters = [], this._filteredIndices = [], this._sortedIndices = [], this._openFilterKey = null, this._rowSelectionVersion = 0, this._lastCheckboxRowIndex = null, this._checkboxShiftPending = !1, this._autocompleteState = null, this._headerMenu = null, this._bodyContextMenu = null, this._commentPopup = null, this._viewDirty = !0, this._isDragging = !1, this._wasDrag = !1, this._resizing = null, this._resizeCleanup = null, this._wasHeaderDrag = !1, this._wasRowDrag = !1, this._colDrag = null, this._colDragIndicatorLeft = null, this._fillDrag = null, this._rowDrag = null, this._rowDragIndicatorY = null, this._findState = null, this._columnWidths = /* @__PURE__ */ new Map(), this._hostResizeObserver = null, this._comments = /* @__PURE__ */ new Map(), this._isDragOver = !1, this._warnedUnconstrained = !1, this._onHostFocus = (e) => {
1766
+ super(...e), this.columns = [], this._data = [], this._inUndoRedo = !1, this.clearUndoOnDataChange = !1, this.clearSelectionOnDataChange = !1, this.rowKey = "_id", this._rowHeightFromCss = X, this._targetFloor = 0, this.showRowNumbers = !1, this.theme = void 0, this.maxRows = 0, this.editable = !0, this.showFilters = !1, this.showContextMenu = !1, this.frozenRows = 0, this.emptyMessage = "", this.noMatchingMessage = "", this.error = null, this.loading = !1, this.importEnabled = !1, this.selectable = !1, this.dataMode = "client", this.footerData = null, this.stylesheets = [], this._scrollTop = 0, this._scrollLeft = 0, this._viewportHeight = 0, this._viewportWidth = 0, this._colLeftOffsets = [], this._totalRowWidth = 0, this._baseStyleSheets = [], this._activeCell = null, this._headerCol = null, this._focusedCellEl = null, this._editingCell = null, this._sortCriteria = [], this._selection = new se(), this._editing = new ce(), this._rowSelection = new O(), this._undo = new A(), this._filters = [], this._filteredIndices = [], this._sortedIndices = [], this._openFilterKey = null, this._rowSelectionVersion = 0, this._lastCheckboxRowId = null, this._unkeyedIds = /* @__PURE__ */ new WeakMap(), this._unkeyedSeq = 0, this._visibleIdsCache = null, this._checkboxShiftPending = !1, this._autocompleteState = null, this._headerMenu = null, this._bodyContextMenu = null, this._commentPopup = null, this._viewDirty = !0, this._isDragging = !1, this._wasDrag = !1, this._resizing = null, this._resizeCleanup = null, this._wasHeaderDrag = !1, this._wasRowDrag = !1, this._colDrag = null, this._colDragIndicatorLeft = null, this._fillDrag = null, this._rowDrag = null, this._rowDragIndicatorY = null, this._findState = null, this._columnWidths = /* @__PURE__ */ new Map(), this._hostResizeObserver = null, this._comments = /* @__PURE__ */ new Map(), this._isDragOver = !1, this._editorMoving = !1, this._onEditorBlur = (e) => {
1767
+ !this._editorMoving && e.currentTarget?.isConnected && this._commitEdit();
1768
+ }, this._warnedUnconstrained = !1, this._onHostFocus = (e) => {
1760
1769
  e.composedPath()[0] !== this || this._activeCell || this._headerCol !== null || this.visibleColumns.length !== 0 && this.matches(":focus-visible") && (this._visibleRowCount > 0 ? (this._selection.setActive(0, 0), this._syncActiveCell()) : this._headerCol = 0);
1761
1770
  }, this._onFocusIn = (e) => {
1762
1771
  let t = e.composedPath()[0];
@@ -1784,7 +1793,7 @@ var K = {
1784
1793
  }
1785
1794
  set data(e) {
1786
1795
  let t = this._data, n = e !== t;
1787
- this._data = e, n && !this._inUndoRedo && (this.clearUndoOnDataChange && this._undo.clear(), this.clearSelectionOnDataChange && this._rowSelection.selectedCount > 0 && (this._rowSelection.deselectAll(), this._rowSelectionVersion++, this._dispatchRowSelectionEvent())), this.requestUpdate("data", t);
1796
+ this._data = e, n && !this._inUndoRedo && (this.clearUndoOnDataChange && this._undo.clear(), this._comments.size > 0 && this._pruneGoneUnkeyedComments(), this._rowSelection.selectedCount > 0 && (this.clearSelectionOnDataChange ? (this._rowSelection.deselectAll(), 1) : this._pruneGoneUnkeyedRows()) && (this._rowSelectionVersion++, this._dispatchRowSelectionEvent())), this.requestUpdate("data", t);
1788
1797
  }
1789
1798
  get rowHeight() {
1790
1799
  let e = this._rowHeightExplicit ?? this._rowHeightFromCss ?? X;
@@ -1835,14 +1844,28 @@ var K = {
1835
1844
  return this._filteredIndices.length;
1836
1845
  }
1837
1846
  getSelectedRows() {
1838
- let e = this._rowSelection.selectedIndices.map((e) => this._toDataIndex(e)).filter((e) => e >= 0 && e < this.data.length);
1847
+ let e = [];
1848
+ if (this._rowSelection.selectedCount > 0) for (let t = 0; t < this.data.length; t++) this._rowSelection.isSelected(this.getRowId(this.data[t])) && e.push(t);
1839
1849
  return {
1850
+ selectedIds: this._rowSelection.selectedIds,
1840
1851
  selectedIndices: e,
1841
1852
  selectedRows: e.map((e) => this.data[e])
1842
1853
  };
1843
1854
  }
1855
+ getRowId(e) {
1856
+ let t = this.rowKey, n = typeof t == "function" ? t(e) : e[t];
1857
+ if (n != null && n !== "") return String(n);
1858
+ let r = this._unkeyedIds.get(e);
1859
+ return r === void 0 && (r = `#${++this._unkeyedSeq}`, this._unkeyedIds.set(e, r)), r;
1860
+ }
1861
+ get selectedRowIds() {
1862
+ return new Set(this._rowSelection.selectedIds);
1863
+ }
1864
+ setSelection(e) {
1865
+ this.selectable && this._rowSelection.set(e) && (this._rowSelectionVersion++, this._dispatchRowSelectionEvent(), this.requestUpdate());
1866
+ }
1844
1867
  selectAll() {
1845
- this.selectable && (this._rowSelection.selectAll(), this._rowSelectionVersion++, this._dispatchRowSelectionEvent());
1868
+ this.selectable && (this._rowSelection.selectAll(this._visibleRowIds()), this._rowSelectionVersion++, this._dispatchRowSelectionEvent());
1846
1869
  }
1847
1870
  deselectAll() {
1848
1871
  this.selectable && (this._rowSelection.deselectAll(), this._rowSelectionVersion++, this._dispatchRowSelectionEvent());
@@ -1851,17 +1874,38 @@ var K = {
1851
1874
  if (this.selectable) {
1852
1875
  for (let t = 0; t < this._visibleRowCount; t++) {
1853
1876
  let n = this._toDataIndex(t), r = this.data[n];
1854
- r !== void 0 && e(r, n) && this._rowSelection.select(t);
1877
+ r !== void 0 && e(r, n) && this._rowSelection.select(this.getRowId(r));
1855
1878
  }
1856
1879
  this._rowSelectionVersion++, this._dispatchRowSelectionEvent(), this.requestUpdate();
1857
1880
  }
1858
1881
  }
1859
1882
  _dispatchRowSelectionEvent() {
1860
- let { selectedIndices: e, selectedRows: t } = this.getSelectedRows();
1861
- this._emit("selection-change", {
1862
- selectedIndices: e,
1863
- selectedRows: t
1864
- });
1883
+ this._emit("selection-change", this.getSelectedRows());
1884
+ }
1885
+ _visibleRowIds() {
1886
+ let e = this._visibleIdsCache;
1887
+ if (e && e.order === this._sortedIndices && e.data === this.data && e.key === this.rowKey && e.ids.length === this._visibleRowCount) return e.ids;
1888
+ let t = [];
1889
+ for (let e = 0; e < this._visibleRowCount; e++) {
1890
+ let n = this.data[this._toDataIndex(e)];
1891
+ n !== void 0 && t.push(this.getRowId(n));
1892
+ }
1893
+ return this._visibleIdsCache = {
1894
+ order: this._sortedIndices,
1895
+ data: this.data,
1896
+ key: this.rowKey,
1897
+ ids: t
1898
+ }, t;
1899
+ }
1900
+ _pruneGoneUnkeyedComments() {
1901
+ if (![...this._comments.keys()].some((e) => e.startsWith("#"))) return;
1902
+ let e = new Set(this.data.map((e) => this.getRowId(e)));
1903
+ for (let t of [...this._comments.keys()]) t.startsWith("#") && !e.has(t) && this._comments.delete(t);
1904
+ }
1905
+ _pruneGoneUnkeyedRows() {
1906
+ if (!this._rowSelection.selectedIds.some((e) => e.startsWith("#"))) return !1;
1907
+ let e = new Set(this.data.map((e) => this.getRowId(e)));
1908
+ return this._rowSelection.retain((t) => !t.startsWith("#") || e.has(t));
1865
1909
  }
1866
1910
  setFilter(e, t) {
1867
1911
  this._filters = this._filters.filter((t) => t.key !== e), this._filters.push({
@@ -2037,57 +2081,68 @@ var K = {
2037
2081
  }), this._dispatchUndoStateEvent(), n;
2038
2082
  }
2039
2083
  deleteRows(e) {
2040
- let t = e ?? this._getSelectedDataRows();
2084
+ let t = e ?? (this.selectable ? this.getSelectedRows().selectedIndices : this._getSelectedDataRows());
2041
2085
  if (t.length === 0) return;
2042
2086
  let n = [...t].sort((e, t) => t - e), r = [];
2043
2087
  for (let e of n) e >= 0 && e < this.data.length && (r.push({
2044
2088
  index: e,
2045
2089
  row: this.data[e]
2046
2090
  }), this.data.splice(e, 1));
2047
- if (r.length !== 0) {
2048
- if (r.reverse(), this._undo.push({
2049
- label: "row-delete",
2050
- undo: () => {
2051
- for (let { index: e, row: t } of r) this.data.splice(e, 0, t);
2052
- this.requestUpdate();
2053
- },
2054
- redo: () => {
2055
- let e = [...r].reverse();
2056
- for (let { index: t } of e) this.data.splice(t, 1);
2057
- this.requestUpdate();
2058
- }
2059
- }), this._activeCell) {
2060
- let e = this._toDataIndex(this._activeCell.row);
2061
- t.includes(e) && (this._selection.clear(), this._activeCell = null);
2091
+ if (r.length === 0) return;
2092
+ r.reverse();
2093
+ let i = /* @__PURE__ */ new Map();
2094
+ for (let { row: e } of r) {
2095
+ let t = this.getRowId(e), n = this._comments.get(t);
2096
+ n && (i.set(t, n), this._comments.delete(t));
2097
+ }
2098
+ this._undo.push({
2099
+ label: "row-delete",
2100
+ undo: () => {
2101
+ for (let { index: e, row: t } of r) this.data.splice(e, 0, t);
2102
+ for (let [e, t] of i) this._comments.set(e, t);
2103
+ this.requestUpdate();
2104
+ },
2105
+ redo: () => {
2106
+ let e = [...r].reverse();
2107
+ for (let { index: t } of e) this.data.splice(t, 1);
2108
+ for (let e of i.keys()) this._comments.delete(e);
2109
+ this.requestUpdate();
2062
2110
  }
2063
- this.requestUpdate(), this._emit("row-delete", {
2064
- indices: r.map((e) => e.index),
2065
- rows: r.map((e) => e.row)
2066
- }), this._dispatchUndoStateEvent();
2111
+ });
2112
+ let a = r.map((e) => this.getRowId(e.row)).filter((e) => this._rowSelection.isSelected(e));
2113
+ if (a.length > 0 && (this._rowSelection.deselectMany(a), this._rowSelectionVersion++, this._dispatchRowSelectionEvent()), this._activeCell) {
2114
+ let e = this._toDataIndex(this._activeCell.row);
2115
+ t.includes(e) && (this._selection.clear(), this._activeCell = null);
2067
2116
  }
2117
+ this.requestUpdate(), this._emit("row-delete", {
2118
+ indices: r.map((e) => e.index),
2119
+ rows: r.map((e) => e.row)
2120
+ }), this._dispatchUndoStateEvent();
2068
2121
  }
2069
2122
  updateRows(e) {
2070
2123
  if (e.length === 0) return;
2071
- let t = [];
2072
- for (let n of e) {
2073
- if (n.row < 0 || n.row >= this.data.length) continue;
2074
- let e = this.data[n.row][n.key];
2075
- this.data[n.row][n.key] = n.value, t.push({
2076
- row: n.row,
2077
- key: n.key,
2124
+ let t = [], n = [];
2125
+ for (let r of e) {
2126
+ if (r.row < 0 || r.row >= this.data.length) continue;
2127
+ let e = this.data[r.row][r.key];
2128
+ this.data[r.row][r.key] = r.value, t.push({
2129
+ row: r.row,
2130
+ key: r.key,
2078
2131
  oldValue: e,
2079
- newValue: n.value
2080
- });
2132
+ newValue: r.value
2133
+ }), n.push(this.data[r.row]);
2081
2134
  }
2082
2135
  t.length !== 0 && (this._undo.push({
2083
2136
  label: "batch-update",
2084
2137
  undo: () => {
2085
- for (let e of t) this.data[e.row][e.key] = e.oldValue;
2086
- this.requestUpdate();
2138
+ t.forEach((e, t) => {
2139
+ n[t][e.key] = e.oldValue;
2140
+ }), this.requestUpdate();
2087
2141
  },
2088
2142
  redo: () => {
2089
- for (let e of t) this.data[e.row][e.key] = e.newValue;
2090
- this.requestUpdate();
2143
+ t.forEach((e, t) => {
2144
+ n[t][e.key] = e.newValue;
2145
+ }), this.requestUpdate();
2091
2146
  }
2092
2147
  }), this.requestUpdate(), this._emit("batch-update", { changes: t }), this._dispatchUndoStateEvent());
2093
2148
  }
@@ -2135,14 +2190,16 @@ var K = {
2135
2190
  };
2136
2191
  }
2137
2192
  setComment(e, t, n) {
2138
- let r = this.getComment(e, t);
2139
- this._applyComment(e, t, n), this._undo.push({
2193
+ let r = this.data[e];
2194
+ if (!r) return;
2195
+ let i = this.getRowId(r), a = this._comments.get(i)?.get(t) ?? null;
2196
+ this._applyComment(i, t, n), this._undo.push({
2140
2197
  label: "comment",
2141
2198
  undo: () => {
2142
- this._applyComment(e, t, r);
2199
+ this._applyComment(i, t, a);
2143
2200
  },
2144
2201
  redo: () => {
2145
- this._applyComment(e, t, n);
2202
+ this._applyComment(i, t, n);
2146
2203
  }
2147
2204
  });
2148
2205
  }
@@ -2152,23 +2209,29 @@ var K = {
2152
2209
  let n = this._comments.get(e);
2153
2210
  n && (n.delete(t), n.size === 0 && this._comments.delete(e));
2154
2211
  }
2212
+ let r = this.data.findIndex((t) => this.getRowId(t) === e);
2155
2213
  this._emit("comment-change", {
2156
- dataIndex: e,
2214
+ dataIndex: r,
2215
+ id: e,
2157
2216
  colKey: t,
2158
2217
  text: n ?? null
2159
2218
  }), this.requestUpdate();
2160
2219
  }
2161
2220
  getComment(e, t) {
2162
- return this._comments.get(e)?.get(t) ?? null;
2221
+ let n = this.data[e];
2222
+ return n ? this._comments.get(this.getRowId(n))?.get(t) ?? null : null;
2163
2223
  }
2164
2224
  getAllComments() {
2165
2225
  let e = [];
2166
- for (let [t, n] of this._comments) for (let [r, i] of n) e.push({
2167
- dataIndex: t,
2168
- colKey: r,
2169
- text: i
2170
- });
2171
- return e;
2226
+ return this._comments.size === 0 || this.data.forEach((t, n) => {
2227
+ let r = this.getRowId(t);
2228
+ for (let [t, i] of this._comments.get(r) ?? []) e.push({
2229
+ dataIndex: n,
2230
+ id: r,
2231
+ colKey: t,
2232
+ text: i
2233
+ });
2234
+ }), e;
2172
2235
  }
2173
2236
  clearComments() {
2174
2237
  let e = new Map([...this._comments].map(([e, t]) => [e, new Map(t)]));
@@ -2354,10 +2417,10 @@ var K = {
2354
2417
  };
2355
2418
  }
2356
2419
  willUpdate(e) {
2357
- (!(e.size <= 2 && !e.has("data") && !e.has("columns") && !e.has("_openFilterKey") && !e.has("_editingCell") && !e.has("_activeCell") && (e.has("_scrollTop") || e.has("_scrollLeft"))) || this._viewDirty) && (this._recomputeView(), this._viewDirty = !1), this._updateColOffsets(), this._selection.setDimensions(this._visibleRowCount, this.visibleColumns.length), this._rowSelection.setRowCount(this._visibleRowCount);
2420
+ (!(e.size <= 2 && !e.has("data") && !e.has("columns") && !e.has("_openFilterKey") && !e.has("_editingCell") && !e.has("_activeCell") && (e.has("_scrollTop") || e.has("_scrollLeft"))) || this._viewDirty) && (this._recomputeView(), this._viewDirty = !1, this._followEditingRow()), this._updateColOffsets(), this._selection.setDimensions(this._visibleRowCount, this.visibleColumns.length);
2358
2421
  }
2359
2422
  updated(e) {
2360
- this._focusEditor(), this._syncGridFocus(), this._adjustFilterDropdown(), e.has("_headerMenu") && this._keepMenuInView(".ft-header-menu"), e.has("_bodyContextMenu") && this._bodyContextMenu && (this._keepMenuInView(".ft-body-context-menu"), this.shadowRoot?.querySelector(".ft-body-context-menu [role=\"menuitem\"]")?.focus()), e.has("stylesheets") && this._syncStylesheets();
2423
+ this._focusEditor(), this._editorMoving = !1, this._syncGridFocus(), this._adjustFilterDropdown(), e.has("_headerMenu") && this._keepMenuInView(".ft-header-menu"), e.has("_bodyContextMenu") && this._bodyContextMenu && (this._keepMenuInView(".ft-body-context-menu"), this.shadowRoot?.querySelector(".ft-body-context-menu [role=\"menuitem\"]")?.focus()), e.has("stylesheets") && this._syncStylesheets();
2361
2424
  let t = String(1 + this._visibleRowCount + +!!this.footerData), n = String(this.visibleColumns.length);
2362
2425
  if (this.getAttribute("aria-rowcount") !== t && this.setAttribute("aria-rowcount", t), this.getAttribute("aria-colcount") !== n && this.setAttribute("aria-colcount", n), this.loading ? this.getAttribute("aria-busy") !== "true" && this.setAttribute("aria-busy", "true") : this.hasAttribute("aria-busy") && this.removeAttribute("aria-busy"), e.has("_commentPopup") && this._commentPopup) {
2363
2426
  let e = this.shadowRoot?.querySelector(".ft-comment-popup textarea");
@@ -2369,7 +2432,7 @@ var K = {
2369
2432
  this._filteredIndices = Array.from({ length: this.data.length }, (e, t) => t), this._sortedIndices = this._filteredIndices;
2370
2433
  return;
2371
2434
  }
2372
- if (this._filteredIndices = ce(this.data, this._filters, (e, t, n) => {
2435
+ if (this._filteredIndices = k(this.data, this._filters, (e, t, n) => {
2373
2436
  this._emit("filter-error", {
2374
2437
  error: e,
2375
2438
  row: t,
@@ -2382,12 +2445,32 @@ var K = {
2382
2445
  this._sortedIndices = t.map((e) => this._filteredIndices[e]);
2383
2446
  }
2384
2447
  }
2448
+ _followEditingRow() {
2449
+ let e = this._editing.current;
2450
+ if (!e) return;
2451
+ let t = this.data.indexOf(e.row), n = t < 0 ? -1 : this._sortedIndices.indexOf(t);
2452
+ if (n < 0) {
2453
+ this._cancelEdit();
2454
+ return;
2455
+ }
2456
+ if (n === e.position.row) return;
2457
+ let r = this.shadowRoot?.querySelector(".ft-editor");
2458
+ r && "value" in r && (e.draft = r.value), this._editorMoving = !0, e.position = {
2459
+ row: n,
2460
+ col: e.position.col
2461
+ }, this._editingCell = { ...e.position }, this._activeCell = this._selection.setActive(n, e.position.col);
2462
+ }
2385
2463
  _toDataIndex(e) {
2386
2464
  return this._sortedIndices[e] ?? e;
2387
2465
  }
2388
2466
  _focusEditor() {
2389
2467
  if (!this._editingCell) return;
2390
- let e = this.shadowRoot?.querySelector(".ft-editor");
2468
+ let e = this.shadowRoot?.querySelector(".ft-editor"), t = this._editing.current;
2469
+ if (e && t?.draft !== void 0) {
2470
+ let n = t.draft;
2471
+ t.draft = void 0, e.value = n, e.focus(), e.type === "text" && e.setSelectionRange(e.value.length, e.value.length);
2472
+ return;
2473
+ }
2391
2474
  if (e && this.shadowRoot.activeElement !== e) {
2392
2475
  if (e.localName === "u-date-picker") {
2393
2476
  let t = e;
@@ -2492,6 +2575,7 @@ var K = {
2492
2575
  let t = this._toDataIndex(this._activeCell.row), n = this.data[t];
2493
2576
  n && this._emit("row-activate", {
2494
2577
  row: n,
2578
+ id: this.getRowId(n),
2495
2579
  index: t,
2496
2580
  col: this._activeCell.col,
2497
2581
  key: e?.key
@@ -2507,7 +2591,7 @@ var K = {
2507
2591
  return;
2508
2592
  }
2509
2593
  let t = this._toDataIndex(this._activeCell.row), n = this.data[t];
2510
- this._editing.start(this._activeCell, n[e.key]), this._editingCell = { ...this._activeCell }, this._emit("cell-edit-start", {
2594
+ this._editing.start(this._activeCell, n[e.key], n), this._editingCell = { ...this._activeCell }, this._emit("cell-edit-start", {
2511
2595
  row: t,
2512
2596
  col: this._activeCell.col,
2513
2597
  key: e.key,
@@ -2550,12 +2634,20 @@ var K = {
2550
2634
  this._autocompleteState = null;
2551
2635
  let n = this._editing.commit();
2552
2636
  if (this._editingCell = null, !n) return;
2553
- let { row: r, col: i } = n.position, a = this._toDataIndex(r), o = this.visibleColumns[i], s = n.originalValue;
2637
+ let { col: r } = n.position, i = n.row, a = this.data.indexOf(i);
2638
+ if (a < 0) {
2639
+ this._emit("cell-edit-cancel", {
2640
+ row: -1,
2641
+ col: r
2642
+ });
2643
+ return;
2644
+ }
2645
+ let o = this.visibleColumns[r], s = n.originalValue;
2554
2646
  if (o.autocomplete === "strict" && t != null && t !== "" && !this._getAutocompleteCandidates(o, "").includes(String(t))) {
2555
2647
  let n = e("notInList");
2556
- this._markCellInvalid(r, i, () => e("notInList")), this._emit("validation-error", {
2648
+ this._markCellInvalid(i, o, () => e("notInList")), this._emit("validation-error", {
2557
2649
  row: a,
2558
- col: i,
2650
+ col: r,
2559
2651
  key: o.key,
2560
2652
  value: t,
2561
2653
  error: n
@@ -2564,9 +2656,9 @@ var K = {
2564
2656
  }
2565
2657
  if (o.type === "number" && typeof t == "string" || o.type === "date" && typeof t == "string" && p(t) === null || o.type === "datetime" && typeof t == "string" && m(t) === null) {
2566
2658
  let n = o.type === "number" ? "notANumber" : o.type === "date" ? "notADate" : "notADateTime", s = e(n);
2567
- this._markCellInvalid(r, i, () => e(n)), this._emit("validation-error", {
2659
+ this._markCellInvalid(i, o, () => e(n)), this._emit("validation-error", {
2568
2660
  row: a,
2569
- col: i,
2661
+ col: r,
2570
2662
  key: o.key,
2571
2663
  value: t,
2572
2664
  error: s
@@ -2574,11 +2666,11 @@ var K = {
2574
2666
  return;
2575
2667
  }
2576
2668
  if (o.validator) {
2577
- let e = o.validator(t, this.data[a], o);
2669
+ let e = o.validator(t, i, o);
2578
2670
  if (e) {
2579
- this._markCellInvalid(r, i, e), this._emit("validation-error", {
2671
+ this._markCellInvalid(i, o, e), this._emit("validation-error", {
2580
2672
  row: a,
2581
- col: i,
2673
+ col: r,
2582
2674
  key: o.key,
2583
2675
  value: t,
2584
2676
  error: e
@@ -2586,17 +2678,17 @@ var K = {
2586
2678
  return;
2587
2679
  }
2588
2680
  }
2589
- this.data[a][o.key] = t, this._undo.push({
2681
+ i[o.key] = t, this._undo.push({
2590
2682
  label: "cell-edit",
2591
2683
  undo: () => {
2592
- this.data[a][o.key] = s, this.requestUpdate();
2684
+ i[o.key] = s, this.requestUpdate();
2593
2685
  },
2594
2686
  redo: () => {
2595
- this.data[a][o.key] = t, this.requestUpdate();
2687
+ i[o.key] = t, this.requestUpdate();
2596
2688
  }
2597
2689
  }), this.requestUpdate(), this._emit("cell-edit-commit", {
2598
2690
  row: a,
2599
- col: i,
2691
+ col: r,
2600
2692
  key: o.key,
2601
2693
  oldValue: s,
2602
2694
  newValue: t
@@ -2606,7 +2698,7 @@ var K = {
2606
2698
  this._autocompleteState = null;
2607
2699
  let e = this._editing.cancel();
2608
2700
  this._editingCell = null, e && this._emit("cell-edit-cancel", {
2609
- row: e.position.row,
2701
+ row: this.data.indexOf(e.row),
2610
2702
  col: e.position.col
2611
2703
  });
2612
2704
  }
@@ -2722,7 +2814,11 @@ var K = {
2722
2814
  }
2723
2815
  if (!this._handleCtrlKey(e) && !this._handleAltKey(e, t)) {
2724
2816
  if (e.key === " " && e.shiftKey && this.selectable && this._activeCell && !e.ctrlKey && !e.metaKey && !e.altKey) {
2725
- e.preventDefault(), this._rowSelection.toggle(this._activeCell.row), this._lastCheckboxRowIndex = this._activeCell.row, this._rowSelectionVersion++, this._dispatchRowSelectionEvent();
2817
+ e.preventDefault();
2818
+ let t = this.data[this._toDataIndex(this._activeCell.row)];
2819
+ if (!t) return;
2820
+ let n = this.getRowId(t);
2821
+ this._rowSelection.toggle(n), this._lastCheckboxRowId = n, this._rowSelectionVersion++, this._dispatchRowSelectionEvent();
2726
2822
  return;
2727
2823
  }
2728
2824
  if (this._activeCell && e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
@@ -2887,17 +2983,24 @@ var K = {
2887
2983
  if (t.length === 0) return;
2888
2984
  let n = this._expandRowsForPaste(this._activeCell.row, t.length), r = this._applyPasteData(this._activeCell, t);
2889
2985
  if (this._selectPastedRange(this._activeCell, t), r.length > 0 || n.length > 0) {
2890
- let e = n.length;
2986
+ let e = r.map((e) => this.data[e.row]), t = n.map((e) => this.data[e]);
2891
2987
  this._undo.push({
2892
2988
  label: "paste",
2893
2989
  undo: () => {
2894
- for (let e of r) this.data[e.row][e.key] = e.oldValue;
2895
- e > 0 && this.data.splice(this.data.length - e, e), this.requestUpdate();
2990
+ r.forEach((t, n) => {
2991
+ e[n][t.key] = t.oldValue;
2992
+ });
2993
+ for (let e of t) {
2994
+ let t = this.data.indexOf(e);
2995
+ t >= 0 && this.data.splice(t, 1);
2996
+ }
2997
+ this.requestUpdate();
2896
2998
  },
2897
2999
  redo: () => {
2898
- if (e > 0) for (let t = 0; t < e; t++) this.data.push(this._createEmptyRow());
2899
- for (let e of r) this.data[e.row][e.key] = e.newValue;
2900
- this.requestUpdate();
3000
+ for (let e of t) this.data.push(e);
3001
+ r.forEach((t, n) => {
3002
+ e[n][t.key] = t.newValue;
3003
+ }), this.requestUpdate();
2901
3004
  }
2902
3005
  }), this._dispatchUndoStateEvent();
2903
3006
  }
@@ -3021,7 +3124,7 @@ var K = {
3021
3124
  r.add(i);
3022
3125
  let o = t[e], s = this.data[a][o.key], c = o.type === "boolean" ? !1 : o.type === "number" ? 0 : "";
3023
3126
  this.data[a][o.key] = c, n.push({
3024
- dataRow: a,
3127
+ target: this.data[a],
3025
3128
  key: o.key,
3026
3129
  oldValue: s,
3027
3130
  clearValue: c
@@ -3031,11 +3134,11 @@ var K = {
3031
3134
  n.length > 0 && (this._undo.push({
3032
3135
  label: "clear",
3033
3136
  undo: () => {
3034
- for (let e of n) this.data[e.dataRow][e.key] = e.oldValue;
3137
+ for (let e of n) e.target[e.key] = e.oldValue;
3035
3138
  this.requestUpdate();
3036
3139
  },
3037
3140
  redo: () => {
3038
- for (let e of n) this.data[e.dataRow][e.key] = e.clearValue;
3141
+ for (let e of n) e.target[e.key] = e.clearValue;
3039
3142
  this.requestUpdate();
3040
3143
  }
3041
3144
  }), this._dispatchUndoStateEvent()), this.requestUpdate();
@@ -3047,7 +3150,7 @@ var K = {
3047
3150
  for (let r = e.startCol; r <= e.endCol; r++) {
3048
3151
  let e = t[r], a = this.data[i][e.key], o = e.type === "boolean" ? !1 : e.type === "number" ? 0 : "";
3049
3152
  this.data[i][e.key] = o, n.push({
3050
- dataRow: i,
3153
+ target: this.data[i],
3051
3154
  key: e.key,
3052
3155
  oldValue: a,
3053
3156
  clearValue: o
@@ -3057,11 +3160,11 @@ var K = {
3057
3160
  n.length > 0 && (this._undo.push({
3058
3161
  label: "clear",
3059
3162
  undo: () => {
3060
- for (let e of n) this.data[e.dataRow][e.key] = e.oldValue;
3163
+ for (let e of n) e.target[e.key] = e.oldValue;
3061
3164
  this.requestUpdate();
3062
3165
  },
3063
3166
  redo: () => {
3064
- for (let e of n) this.data[e.dataRow][e.key] = e.clearValue;
3167
+ for (let e of n) e.target[e.key] = e.clearValue;
3065
3168
  this.requestUpdate();
3066
3169
  }
3067
3170
  }), this._dispatchUndoStateEvent()), this.requestUpdate();
@@ -3654,7 +3757,7 @@ var K = {
3654
3757
  `;
3655
3758
  }
3656
3759
  _cellKey(e, t) {
3657
- return `${e}:${t}`;
3760
+ return `${this.getRowId(e)}\u0000${t.key}`;
3658
3761
  }
3659
3762
  _markCellInvalid(e, t, n) {
3660
3763
  let r = this._cellKey(e, t), i = this._invalidCells.get(r);
@@ -3846,38 +3949,40 @@ var K = {
3846
3949
  }, this._fillDrag.targetRange = u, this.requestUpdate();
3847
3950
  }
3848
3951
  _applyFillHandle(e, t) {
3849
- let n = this.visibleColumns, r = [];
3850
- for (let i = t.startCol; i <= t.endCol; i++) {
3851
- let a = n[i], o = [];
3852
- for (let t = e.startRow; t <= e.endRow; t++) o.push(this.data[this._toDataIndex(t)][a.key]);
3853
- let s = this._detectNumericSeries(o);
3952
+ let n = this.visibleColumns, r = [], i = [];
3953
+ for (let a = t.startCol; a <= t.endCol; a++) {
3954
+ let o = n[a], s = [];
3955
+ for (let t = e.startRow; t <= e.endRow; t++) s.push(this.data[this._toDataIndex(t)][o.key]);
3956
+ let c = this._detectNumericSeries(s);
3854
3957
  for (let n = t.startRow; n <= t.endRow; n++) {
3855
3958
  if (n >= e.startRow && n <= e.endRow) continue;
3856
- let t = this._toDataIndex(n), i = this.data[t][a.key], c;
3857
- if (s && n > e.endRow) {
3858
- let t = n - e.endRow, r = s.last + s.diff * t;
3859
- c = a.type === "number" ? r : String(r);
3959
+ let t = this._toDataIndex(n), a = this.data[t][o.key], l;
3960
+ if (c && n > e.endRow) {
3961
+ let t = n - e.endRow, r = c.last + c.diff * t;
3962
+ l = o.type === "number" ? r : String(r);
3860
3963
  } else {
3861
- let t = (n - e.startRow) % o.length;
3862
- c = o[t < 0 ? t + o.length : t];
3964
+ let t = (n - e.startRow) % s.length;
3965
+ l = s[t < 0 ? t + s.length : t];
3863
3966
  }
3864
- this.data[t][a.key] = c, r.push({
3967
+ this.data[t][o.key] = l, r.push({
3865
3968
  dataRow: t,
3866
- key: a.key,
3867
- oldValue: i,
3868
- newValue: c
3869
- });
3969
+ key: o.key,
3970
+ oldValue: a,
3971
+ newValue: l
3972
+ }), i.push(this.data[t]);
3870
3973
  }
3871
3974
  }
3872
3975
  r.length > 0 && (this._undo.push({
3873
3976
  label: "fill-handle",
3874
3977
  undo: () => {
3875
- for (let e of r) this.data[e.dataRow][e.key] = e.oldValue;
3876
- this.requestUpdate();
3978
+ r.forEach((e, t) => {
3979
+ i[t][e.key] = e.oldValue;
3980
+ }), this.requestUpdate();
3877
3981
  },
3878
3982
  redo: () => {
3879
- for (let e of r) this.data[e.dataRow][e.key] = e.newValue;
3880
- this.requestUpdate();
3983
+ r.forEach((e, t) => {
3984
+ i[t][e.key] = e.newValue;
3985
+ }), this.requestUpdate();
3881
3986
  }
3882
3987
  }), this._dispatchUndoStateEvent(), this._emit("fill-handle-apply", {
3883
3988
  sourceRange: e,
@@ -4041,25 +4146,27 @@ var K = {
4041
4146
  }
4042
4147
  _replaceAll() {
4043
4148
  if (!this._findState || this._findState.results.length === 0) return;
4044
- let { results: e, replaceWith: t } = this._findState, n = this.visibleColumns, r = [];
4045
- for (let { row: i, col: a } of e) {
4046
- let e = this._toDataIndex(i), o = n[a].key, s = this.data[e][o];
4047
- this.data[e][o] = t, r.push({
4149
+ let { results: e, replaceWith: t } = this._findState, n = this.visibleColumns, r = [], i = [];
4150
+ for (let { row: a, col: o } of e) {
4151
+ let e = this._toDataIndex(a), s = n[o].key, c = this.data[e][s];
4152
+ this.data[e][s] = t, r.push({
4048
4153
  dataRow: e,
4049
- key: o,
4050
- oldValue: s,
4154
+ key: s,
4155
+ oldValue: c,
4051
4156
  newValue: t
4052
- });
4157
+ }), i.push(this.data[e]);
4053
4158
  }
4054
4159
  r.length > 0 && (this._undo.push({
4055
4160
  label: "replace-all",
4056
4161
  undo: () => {
4057
- for (let e of r) this.data[e.dataRow][e.key] = e.oldValue;
4058
- this.requestUpdate();
4162
+ r.forEach((e, t) => {
4163
+ i[t][e.key] = e.oldValue;
4164
+ }), this.requestUpdate();
4059
4165
  },
4060
4166
  redo: () => {
4061
- for (let e of r) this.data[e.dataRow][e.key] = e.newValue;
4062
- this.requestUpdate();
4167
+ r.forEach((e, t) => {
4168
+ i[t][e.key] = e.newValue;
4169
+ }), this.requestUpdate();
4063
4170
  }
4064
4171
  }), this._dispatchUndoStateEvent(), this._emit("find-replace", {
4065
4172
  type: "replace-all",
@@ -4073,21 +4180,21 @@ var K = {
4073
4180
  }
4074
4181
  _replaceOne() {
4075
4182
  if (!this._findState || this._findState.results.length === 0) return;
4076
- let { currentIndex: e, results: t, replaceWith: n } = this._findState, { row: r, col: i } = t[e], a = this._toDataIndex(r), o = this.visibleColumns[i].key, s = this.data[a][o];
4077
- this.data[a][o] = n, this._undo.push({
4183
+ let { currentIndex: e, results: t, replaceWith: n } = this._findState, { row: r, col: i } = t[e], a = this._toDataIndex(r), o = this.visibleColumns[i].key, s = this.data[a], c = s[o];
4184
+ s[o] = n, this._undo.push({
4078
4185
  label: "replace",
4079
4186
  undo: () => {
4080
- this.data[a][o] = s, this.requestUpdate();
4187
+ s[o] = c, this.requestUpdate();
4081
4188
  },
4082
4189
  redo: () => {
4083
- this.data[a][o] = n, this.requestUpdate();
4190
+ s[o] = n, this.requestUpdate();
4084
4191
  }
4085
4192
  }), this._dispatchUndoStateEvent(), this._emit("find-replace", {
4086
4193
  type: "replace",
4087
4194
  cells: [{
4088
4195
  row: a,
4089
4196
  col: o,
4090
- oldValue: s,
4197
+ oldValue: c,
4091
4198
  newValue: n
4092
4199
  }]
4093
4200
  }), this._findSearch(), this._findGoTo(Math.min(e, this._findState.results.length - 1));
@@ -4146,8 +4253,8 @@ var K = {
4146
4253
  ${this._rowSelection.mode === "multi" ? a`
4147
4254
  <!-- 칸 전체가 누르는 자리다(라벨) — 체크 상자는 16px 그대로. -->
4148
4255
  <label class="ft-checkbox-hit"><input type="checkbox" tabindex="-1" aria-label=${e("selectAllRows")}
4149
- .checked=${this._rowSelection.isAllSelected}
4150
- .indeterminate=${this._rowSelection.isSomeSelected}
4256
+ .checked=${this._rowSelection.isAllSelected(this._visibleRowIds())}
4257
+ .indeterminate=${this._rowSelection.isSomeSelected(this._visibleRowIds())}
4151
4258
  @change=${this._onSelectAllChange}></label>
4152
4259
  ` : ""}
4153
4260
  </div>` : "";
@@ -4194,10 +4301,14 @@ var K = {
4194
4301
  `;
4195
4302
  }
4196
4303
  _onSelectAllChange(e) {
4197
- e.target.checked ? this._rowSelection.selectAll() : this._rowSelection.deselectAll(), this._rowSelectionVersion++, this._dispatchRowSelectionEvent();
4304
+ e.target.checked ? this._rowSelection.selectAll(this._visibleRowIds()) : this._rowSelection.deselectMany(this._visibleRowIds()), this._rowSelectionVersion++, this._dispatchRowSelectionEvent();
4198
4305
  }
4199
4306
  _onRowCheckboxChange(e, t) {
4200
- e.stopPropagation(), this._checkboxShiftPending && this._lastCheckboxRowIndex !== null ? this._rowSelection.selectRange(this._lastCheckboxRowIndex, t) : this._rowSelection.toggle(t), this._lastCheckboxRowIndex = t, this._checkboxShiftPending = !1, this._rowSelectionVersion++, this._dispatchRowSelectionEvent();
4307
+ e.stopPropagation();
4308
+ let n = this.data[this._toDataIndex(t)];
4309
+ if (!n) return;
4310
+ let r = this.getRowId(n);
4311
+ this._checkboxShiftPending && this._lastCheckboxRowId !== null ? this._rowSelection.selectRange(this._visibleRowIds(), this._lastCheckboxRowId, r) : this._rowSelection.toggle(r), this._lastCheckboxRowId = r, this._checkboxShiftPending = !1, this._rowSelectionVersion++, this._dispatchRowSelectionEvent();
4201
4312
  }
4202
4313
  _onRowCheckboxClick(e) {
4203
4314
  this._checkboxShiftPending = e.shiftKey;
@@ -4242,7 +4353,7 @@ var K = {
4242
4353
  `;
4243
4354
  }
4244
4355
  _renderRow(t, n, r, i, o) {
4245
- let s = this.visibleColumns, c = this._toDataIndex(t), l = this.data[c], u = o ?? t * this.rowHeight, d = this.rowHeight, f = this._totalRowWidth, p = t % 2 == 0 ? "ft-row-even" : "ft-row-odd", m = this.selectable && this._rowSelection.isSelected(t), h = this._scrollLeft, g = 0, _ = this.selectable ? a`
4356
+ let s = this.visibleColumns, c = this._toDataIndex(t), l = this.data[c], u = o ?? t * this.rowHeight, d = this.rowHeight, f = this._totalRowWidth, p = t % 2 == 0 ? "ft-row-even" : "ft-row-odd", m = this.selectable && l !== void 0 && this._rowSelection.isSelected(this.getRowId(l)), h = this._scrollLeft, g = 0, _ = this.selectable ? a`
4246
4357
  <div class="ft-checkbox-cell"
4247
4358
  style="position: absolute; top: 0; left: ${h + g}px; width: ${this._checkboxColWidth}px; height: ${d}px; z-index: 2;">
4248
4359
  <!-- 행 체크박스는 Tab 정지점이 아니다 — 그리드(호스트)가 하나의 정지점이고 행 선택은 Shift+Space 다.
@@ -4317,7 +4428,7 @@ var K = {
4317
4428
  ${this._renderEditor(e, t)}
4318
4429
  </div>
4319
4430
  `;
4320
- let v = s || l, y = this._isCellInvalid(n, r), b = (this._findState?.results ?? []).findIndex((e) => e.row === n && e.col === r), x = b >= 0, S = x && b === this._findState.currentIndex, C = [
4431
+ let v = s || l, y = this._isCellInvalid(e, t), b = (this._findState?.results ?? []).findIndex((e) => e.row === n && e.col === r), x = b >= 0, S = x && b === this._findState.currentIndex, C = [
4321
4432
  "ft-cell",
4322
4433
  `ft-type-${t.type ?? "text"}`,
4323
4434
  `ft-align-${W(t)}`,
@@ -4330,9 +4441,9 @@ var K = {
4330
4441
  i?.continues ? "ft-merge-continued" : "",
4331
4442
  i?.opensDown ? "ft-merge-open" : "",
4332
4443
  t.reveal === "hover" ? "ft-reveal-hover" : ""
4333
- ].filter(Boolean).join(" "), w = this._toDataIndex(n), T = this._comments.get(w)?.get(t.key) ?? null, E = T !== null, O = E ? a`<div class="ft-comment-indicator" title=${T}></div>` : o;
4444
+ ].filter(Boolean).join(" "), w = this._comments.size > 0 ? this._comments.get(this.getRowId(e))?.get(t.key) ?? null : null, T = w !== null, E = T ? a`<div class="ft-comment-indicator" title=${w}></div>` : o;
4334
4445
  return a`
4335
- <div class=${E ? C + " ft-has-comment" : C}
4446
+ <div class=${T ? C + " ft-has-comment" : C}
4336
4447
  role="gridcell"
4337
4448
  tabindex="-1"
4338
4449
  aria-colindex=${r + 1}
@@ -4346,7 +4457,7 @@ var K = {
4346
4457
  @mouseenter=${() => this._onCellMouseEnter(n, r)}
4347
4458
  @click=${(e) => this._onCellClickEvent(e, n, r)}
4348
4459
  @dblclick=${() => this._onCellDblClick(n, r)}>
4349
- ${O}
4460
+ ${E}
4350
4461
  ${D(e[t.key], e, t)}
4351
4462
  </div>
4352
4463
  `;
@@ -4358,7 +4469,7 @@ var K = {
4358
4469
  <input class="ft-editor ft-editor-number" type="text" inputmode="decimal" aria-label=${t.label}
4359
4470
  .value=${typeof n == "number" ? M(n) : r}
4360
4471
  @keydown=${this._onEditorKeyDown}
4361
- @blur=${() => this._commitEdit()}>
4472
+ @blur=${this._onEditorBlur}>
4362
4473
  `;
4363
4474
  if (t.type === "date" || t.type === "datetime") {
4364
4475
  let e = t.type === "datetime";
@@ -4368,7 +4479,7 @@ var K = {
4368
4479
  .value=${Ze(n, e)}
4369
4480
  @keydown=${this._onEditorKeyDown}
4370
4481
  @change=${() => this._commitEdit()}
4371
- @blur=${() => this._commitEdit()}></u-date-picker>
4482
+ @blur=${this._onEditorBlur}></u-date-picker>
4372
4483
  `;
4373
4484
  }
4374
4485
  if (t.type === "select" && t.options && t.options.length > 0) {
@@ -4376,7 +4487,7 @@ var K = {
4376
4487
  return a`
4377
4488
  <select class="ft-editor" aria-label=${t.label}
4378
4489
  @keydown=${this._onEditorKeyDown}
4379
- @blur=${() => this._commitEdit()}
4490
+ @blur=${this._onEditorBlur}
4380
4491
  @change=${() => this._commitEdit()}>
4381
4492
  ${r ? e.map((e) => a`<option value=${e} ?selected=${e === n}>${e}</option>`) : e.map((e) => a`<option value=${String(e.value)} ?selected=${e.value === n}>${e.label}</option>`)}
4382
4493
  </select>
@@ -4393,7 +4504,7 @@ var K = {
4393
4504
  .value=${r}
4394
4505
  @input=${(e) => this._onAutocompleteInput(e, t)}
4395
4506
  @keydown=${this._onEditorKeyDown}
4396
- @blur=${() => this._commitEdit()}>
4507
+ @blur=${this._onEditorBlur}>
4397
4508
  ${e.length > 0 ? a`
4398
4509
  <div class="ft-autocomplete-dropdown" id="ft-autocomplete-list" role="listbox" aria-label=${t.label}>
4399
4510
  ${e.map((e, t) => a`
@@ -4413,7 +4524,7 @@ var K = {
4413
4524
  <input class="ft-editor" type="text" aria-label=${t.label}
4414
4525
  .value=${r}
4415
4526
  @keydown=${this._onEditorKeyDown}
4416
- @blur=${() => this._commitEdit()}>
4527
+ @blur=${this._onEditorBlur}>
4417
4528
  `;
4418
4529
  }
4419
4530
  };
@@ -4426,7 +4537,7 @@ G([c({ type: Array })], Q.prototype, "columns", void 0), G([c({
4426
4537
  })], Q.prototype, "clearUndoOnDataChange", void 0), G([c({
4427
4538
  type: Boolean,
4428
4539
  attribute: "clear-selection-on-data-change"
4429
- })], Q.prototype, "clearSelectionOnDataChange", void 0), G([c({
4540
+ })], Q.prototype, "clearSelectionOnDataChange", void 0), G([c({ attribute: "row-key" })], Q.prototype, "rowKey", void 0), G([c({
4430
4541
  type: Number,
4431
4542
  attribute: "row-height"
4432
4543
  })], Q.prototype, "rowHeight", null), G([c({
@@ -4488,4 +4599,4 @@ function $(e) {
4488
4599
  }
4489
4600
  }
4490
4601
  //#endregion
4491
- export { k as a, A as i, W as n, D as o, z as r, Q as t };
4602
+ export { O as a, A as i, W as n, D as o, z as r, Q as t };