@ninebone/datagrid 0.0.14 → 0.0.18

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.
@@ -69,6 +69,8 @@ var n = new class extends e.constructor {
69
69
  },
70
70
  EVENT: {
71
71
  LOAD: "load",
72
+ ROW_ADDED: "row-added",
73
+ ROW_REMOVED: "row-removed",
72
74
  CELL_BUTTON_CLICK: "cell-button-click"
73
75
  }
74
76
  }, i = class {
@@ -234,13 +236,19 @@ var n = new class extends e.constructor {
234
236
  #u = (e) => this.#t.rawRecords.findIndex((t) => !t || !t.m || !t.m._ ? !1 : t.m._[r.META.INDEX.ROWID] === e);
235
237
  add = (e, t = !0) => {
236
238
  e === void 0 && (e = {});
237
- let n = this.#c(e);
238
- this.#t.rawRecords = this.#t.rawRecords.concat(this.#l(n));
239
- let i = this.count() - 1;
239
+ let n = this.#c(e), i = this.#l(n);
240
+ this.#t.rawRecords = this.#t.rawRecords.concat(i);
241
+ let a = this.count() - 1;
240
242
  return t && n.forEach((e, t) => {
241
243
  let n = this.#t.rawRecords[this.#t.rawRecords.length - 1 - t];
242
244
  n && (n.m._[r.META.INDEX.ROW_STATE] = r.ROW_STATE.INSERT);
243
- }), this.#o(), i;
245
+ }), this.#o(), this.#e.dispatchEvent(new CustomEvent(r.EVENT.ROW_ADDED, {
246
+ bubbles: !0,
247
+ detail: {
248
+ target: this.#e,
249
+ rowid: i.length > 0 ? i[0].m._[r.META.INDEX.ROWID] : null
250
+ }
251
+ })), a;
244
252
  };
245
253
  insert = (e, t, n = !0) => {
246
254
  t === void 0 && (t = {});
@@ -250,7 +258,13 @@ var n = new class extends e.constructor {
250
258
  return this.#t.rawRecords.splice(a, 0, ...o), n && o.forEach((e, t) => {
251
259
  let n = this.#t.rawRecords[a + t];
252
260
  n && n.m && n.m._ && (n.m._[r.META.INDEX.ROW_STATE] = r.ROW_STATE.INSERT);
253
- }), this.#o(), o[0].m._[r.META.INDEX.ROWID];
261
+ }), this.#o(), this.#e.dispatchEvent(new CustomEvent(r.EVENT.ROW_ADDED, {
262
+ bubbles: !0,
263
+ detail: {
264
+ target: this.#e,
265
+ rowid: o.length > 0 ? o[0].m._[r.META.INDEX.ROWID] : null
266
+ }
267
+ })), o[0].m._[r.META.INDEX.ROWID];
254
268
  };
255
269
  remove = (e) => {
256
270
  let t = [];
@@ -265,7 +279,13 @@ var n = new class extends e.constructor {
265
279
  i[e].m._[r.META.INDEX.ROW_STATE] === r.ROW_STATE.INSERT ? this.#t.rawRecords = this.#t.rawRecords.filter((e) => e.m._[r.META.INDEX.ROWID] !== t) : this.#t.rawRecords.forEach((e) => {
266
280
  e.m._[r.META.INDEX.ROWID] === t && (e.m._[r.META.INDEX.ROW_STATE] = r.ROW_STATE.DELETE);
267
281
  });
268
- }), this.#o();
282
+ }), this.#o(), this.#e.dispatchEvent(new CustomEvent(r.EVENT.ROW_REMOVED, {
283
+ bubbles: !0,
284
+ detail: {
285
+ target: this.#e,
286
+ rowid: t.length > 0 ? t[0] : null
287
+ }
288
+ }));
269
289
  };
270
290
  setValue = (e, t, n) => {
271
291
  e = parseInt(e, 10);
@@ -274,6 +294,14 @@ var n = new class extends e.constructor {
274
294
  let a = this.#u(e), o = this.#t.rawRecords[a];
275
295
  o && (o.v[i] !== n && o.m._[r.META.INDEX.ROW_STATE] !== r.ROW_STATE.INSERT && (o.m._[r.META.INDEX.ROW_STATE] = r.ROW_STATE.UPDATE), o.v[i] = n);
276
296
  };
297
+ getChangedData = (e) => {
298
+ let t = this.#t.rawRecords;
299
+ return e ? this.#d(t.filter((t) => t.m._[r.META.INDEX.ROW_STATE] === e)) : {
300
+ C: this.#d(t.filter((e) => e.m._[r.META.INDEX.ROW_STATE] === r.ROW_STATE.INSERT)),
301
+ U: this.#d(t.filter((e) => e.m._[r.META.INDEX.ROW_STATE] === r.ROW_STATE.UPDATE)),
302
+ D: this.#d(t.filter((e) => e.m._[r.META.INDEX.ROW_STATE] === r.ROW_STATE.DELETE))
303
+ };
304
+ };
277
305
  #d = (e) => {
278
306
  if (!e) return e;
279
307
  let t = !Array.isArray(e), n = t ? [e] : e, r = this.getHostFields(), i = n.filter((e) => !e.__ng?.deleted).map((e) => {
@@ -296,7 +324,7 @@ var n = new class extends e.constructor {
296
324
  if (!(t >= this.data.count())) return this.data.getValidData()[t]?.__ng?.rowState;
297
325
  }, this.getRowPosition = () => this.row.at, this.setRowPosition = (e) => {
298
326
  this.row.at = e;
299
- }, this.scrollTo_V1 = (e) => (e < 0 && (e = 0), e >= this.rawRecords.length && (e = this.rawRecords.length - 1), this.viewRecords.rawIndex = e, this.viewRecords.reset && this.viewRecords.reset(), !(e <= 0 || e >= this.rawRecords.length - 1)), this.getColumn = (e, t) => this.data.get(e, t), this.setColumn = (e, t, n) => {
327
+ }, this.getColumn = (e, t) => this.data.get(e, t), this.setColumn = (e, t, n) => {
300
328
  e = parseInt(e, 10), this.data.setValue(e, t, n);
301
329
  }, this.setDataSource([]);
302
330
  }
@@ -818,63 +846,61 @@ var m = {
818
846
  #n;
819
847
  #r;
820
848
  #i = /* @__PURE__ */ new Map();
821
- #a = [];
822
- #o = null;
823
- #s = null;
824
- #c = 0;
825
- #l;
826
- #u = !1;
827
- #d = !1;
849
+ #a = null;
850
+ #o = 0;
851
+ #s;
852
+ #c = !1;
853
+ #l = !1;
828
854
  constructor(e) {
829
- this.#t = e.getRootNode().host, this.#n = e, this.#x();
855
+ this.#t = e.getRootNode().host, this.#n = e, this.#y();
830
856
  }
831
857
  getRowHeight() {
832
- return this.#a.reduce((e, t) => e + t, 0);
858
+ return this.#n.template.height;
833
859
  }
834
860
  refresh = (e = !1) => {
835
861
  if (!this.#n.classList.contains("active")) return;
836
862
  let t = this.#n.querySelector(".ng-sheet-body");
837
- t && ((!this.#o || this.#o <= 0) && (this.#g(), this.#o && this.#o > 0 && this.#v()), this.#f(t.scrollTop, e), this.#n.querySelector("nine-table-vscrollbar")?.refresh());
863
+ t && ((!this.#n.template.height || this.#n.template.height <= 0) && (this.#m(), this.#n.template.height && this.#n.template.height > 0 && this.#g()), this.#u(t.scrollTop, e), this.#n.querySelector("nine-table-vscrollbar")?.refresh());
838
864
  };
839
- #f = (e, t = !1) => {
840
- if (this.#d) {
841
- this.#p(e, t);
865
+ #u = (e, t = !1) => {
866
+ if (this.#l) {
867
+ this.#d(e, t);
842
868
  return;
843
869
  }
844
- let n = this.#o;
870
+ let n = this.#n.template.height;
845
871
  if (!n || n <= 0) return;
846
872
  let i = this.#n.view.getArray(), a = i.length;
847
873
  if (a === 0) {
848
874
  this.#n.elements.scrollHolder.style.height = "0px";
849
875
  return;
850
876
  }
851
- let o = this.#n.templateLength, s = (this.#n.elements.body.thead?.offsetHeight || 0) + (this.#n.elements.body.tfoot?.offsetHeight || 0) + this.#n.elements.body.tbody.head.offsetHeight, c = this.#n.querySelector(".ng-sheet-body").offsetHeight || 0, l = Math.max(a * n - (c - s - n), 0), u = 15e6, d = l > u, f = 1, p = l;
852
- d && (f = u / l, p = u), this.#n.elements.scrollHolder.style.height = `${p}px`;
853
- let m = d ? e / f : e, h = Math.max(0, a - 1), g = Math.min(m, l), _ = Math.max(0, Math.min(Math.floor(g / n), h));
854
- this.#n.elements.left.tbody.body.style.transform = this.#n.elements.body.tbody.body.style.transform = this.#n.elements.right.tbody.body.style.transform = `translate3d(0px, -${g % n}px, 0px)`;
855
- let v = this.#r.firstTr, y = v && v.dataset.row !== void 0 ? parseInt(v.dataset.row, 10) : -1;
856
- (t || y !== _) && ([
877
+ let o = (this.#n.elements.body.thead?.offsetHeight || 0) + (this.#n.elements.body.tfoot?.offsetHeight || 0) + this.#n.elements.body.tbody.head.offsetHeight, s = this.#n.querySelector(".ng-sheet-body").offsetHeight || 0, c = Math.max(a * n - (s - o - n) - n, 0), l = 15e6, u = c > l, d = 1, f = c;
878
+ u && (d = l / c, f = l), this.#n.elements.scrollHolder.style.height = `${f}px`;
879
+ let p = u ? e / d : e, m = Math.max(0, a - 1), h = Math.min(p, c), g = Math.max(0, Math.min(Math.floor(h / n), m));
880
+ this.#n.elements.left.tbody.body.style.transform = this.#n.elements.body.tbody.body.style.transform = this.#n.elements.right.tbody.body.style.transform = `translate3d(0px, -${h % n}px, 0px)`;
881
+ let _ = this.#r.firstTr, v = _ && _.dataset.row !== void 0 ? parseInt(_.dataset.row, 10) : -1;
882
+ (t || v !== g) && ([
857
883
  this.#n.elements.left.tbody.body,
858
884
  this.#n.elements.body.tbody.body,
859
885
  this.#n.elements.right.tbody.body
860
886
  ].forEach((e, t) => {
861
887
  e && e.querySelectorAll("tbody.body tr").forEach((e, t) => {
862
- let n = _ + Math.floor(t / o);
888
+ let n = g + Math.floor(t / this.#n.template.length);
863
889
  if (n >= a) {
864
890
  e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null;
865
891
  return;
866
892
  }
867
- let s = i[n];
868
- if (!s) {
893
+ let o = i[n];
894
+ if (!o) {
869
895
  e.style.display = "none";
870
896
  return;
871
897
  }
872
- let c = s.m._[r.META.INDEX.ROWID];
873
- e.style.display = "", this.#h(e, s, c, n);
898
+ let s = o.m._[r.META.INDEX.ROWID];
899
+ e.style.display = "", this.#p(e, o, s, n);
874
900
  });
875
901
  }), this.#n.selection.refresh());
876
902
  };
877
- #p = (e, t = !1) => {
903
+ #d = (e, t = !1) => {
878
904
  let n = this.#n.view.getArray() || [], r = n.length;
879
905
  if (r === 0) {
880
906
  this.#n.elements.scrollHolder.style.height = "0px";
@@ -883,12 +909,12 @@ var m = {
883
909
  let i = this.#n.querySelector(".ng-sheet-body .ng-sheet-body-content"), a = this.#n.templateLength || 1, o = (e) => {
884
910
  if (e.type === "group") {
885
911
  let t = e.record[m.DEPTH] || 0;
886
- return this.#a[t] || this.#o / a;
912
+ return this.#n.template.height[t] || this.#n.template.height / a;
887
913
  }
888
914
  {
889
915
  let e = 0, t = this.#n.templateLength || 1, n = 0;
890
- for (let e = 0; e < t - 1; e++) n += this.#a[e] || 0;
891
- return e = this.#o - n, e > 0 ? e : this.#o;
916
+ for (let e = 0; e < t - 1; e++) n += this.#n.template.heights[e] || 0;
917
+ return e = this.#n.template.height - n, e > 0 ? e : this.#n.template.height;
892
918
  }
893
919
  }, s = 0, c = Array(r);
894
920
  for (let e = 0; e < r; e++) {
@@ -911,7 +937,7 @@ var m = {
911
937
  });
912
938
  let p = this.#r.firstTr, h = p && p.dataset.virtualIndex !== void 0 ? parseInt(p.dataset.virtualIndex, 10) : -1;
913
939
  if (!t && h === d) return;
914
- let g = Math.ceil(l / (this.#o / a)), _ = (this.#n.grouping.columns?.length || 1) * 15, v = d, y = Math.min(r, d + g + _), b = n.slice(v, y);
940
+ let g = Math.ceil(l / (this.#n.template.height / a)), _ = (this.#n.grouping.columns?.length || 1) * 15, v = d, y = Math.min(r, d + g + _), b = n.slice(v, y);
915
941
  [
916
942
  ".ng-container-body",
917
943
  ".ng-container-left",
@@ -933,18 +959,18 @@ var m = {
933
959
  let a = d + t;
934
960
  e.dataset.virtualIndex = a, e.dataset.row = i.type === "data" ? s : "";
935
961
  let o = e.getAttribute("grouping") === "true";
936
- if (i.type === "group") o && r === i.record[m.DEPTH] ? (e.style.display = "", this.#m(e, n, i.record, a)) : (e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null);
962
+ if (i.type === "group") o && r === i.record[m.DEPTH] ? (e.style.display = "", this.#f(e, n, i.record, a)) : (e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null);
937
963
  else if (o) e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null;
938
964
  else {
939
965
  e.style.display = "";
940
966
  let t = i.record.m?.rowid ?? 0;
941
- this.#h(e, i.record, t, a);
967
+ this.#p(e, i.record, t, a);
942
968
  }
943
969
  });
944
970
  }
945
971
  }), this.#n.selection.refresh();
946
972
  };
947
- #m = (e, t, n, r) => {
973
+ #f = (e, t, n, r) => {
948
974
  let i = this.#n.templateLength || 1, a = parseInt(e.dataset.subrow, 10) || 0, o = r * i + a, s = n[m.CHILDREN], c = this.#t.data.getArray(), l = s ? s.map((e) => c[e]).filter(Boolean) : [];
949
975
  e.dataset.virtualIndex = r, e.dataset.row = "", e.dataset.matrixRow = o, e.data = l, e.dataset.groupId = n[m.ID], Array.from(e.cells).forEach((e) => {
950
976
  e.dataset.row = r;
@@ -952,14 +978,14 @@ var m = {
952
978
  t !== void 0 && typeof t.refresh == "function" && t?.refresh();
953
979
  });
954
980
  };
955
- #h = (e, t, n, r) => {
981
+ #p = (e, t, n, r) => {
956
982
  let i = this.#n.templateLength || 1, a = parseInt(e.dataset.subrow, 10) || 0, o = r * i + a;
957
983
  e.dataset.index = r, e.dataset.row = n, e.dataset.matrixRow = o, e.data = t, Array.from(e.cells).forEach((e) => {
958
984
  e.dataset.index = r, e.dataset.row = n, Array.from(e.children).find((e) => e.tagName.toLowerCase().startsWith("cell-") && typeof e.refresh == "function")?.refresh();
959
985
  });
960
986
  };
961
987
  initialize = () => {
962
- this.#d = !!this.#n.sourceTable.querySelector("tbody tr[grouping='true']"), this.#o = null, this.#i.clear(), this.#r = {
988
+ this.#l = !!this.#n.sourceTable.querySelector("tbody tr[grouping='true']"), this.#i.clear(), this.#r = {
963
989
  scrollTables: this.#n.querySelectorAll(".ng-sheet-body table"),
964
990
  firstTr: this.#n.querySelector(".ng-sheet-body .ng-container-body tbody.body tr")
965
991
  }, [
@@ -977,62 +1003,52 @@ var m = {
977
1003
  this.#i.set(e, i);
978
1004
  });
979
1005
  let e = this.#n.querySelector(".ng-sheet-body");
980
- e && (this.#c = e.clientHeight, this.#g(), this.#v(), this.#f(e.scrollTop, !0), e.addEventListener("scroll", (t) => {
981
- if (this.#u) return;
982
- let n = this.#o || 0;
983
- (this.#n.view.getArray()?.length || 0) * n <= e.clientHeight || (this.#f(e.scrollTop), this.#n.querySelector("nine-table-vscrollbar").refresh());
1006
+ e && (this.#o = e.clientHeight, this.#m(), this.#g(), this.#u(e.scrollTop, !0), e.addEventListener("scroll", (t) => {
1007
+ if (this.#c) return;
1008
+ let n = this.#n.template.height || 0;
1009
+ (this.#n.view.getArray()?.length || 0) * n <= e.clientHeight || (this.#u(e.scrollTop), this.#n.querySelector("nine-table-vscrollbar").refresh());
984
1010
  }, { passive: !0 }));
985
1011
  };
986
1012
  scrollToDataRow(e, t = "top", n) {
987
1013
  let r = this.#n.querySelector(".ng-sheet-body"), i = this.#n.view.getArray()?.length || 0, a = Math.max(0, Math.min(e, i - 1)), o = 0;
988
- if (this.#d) {
1014
+ if (this.#l) {
989
1015
  let e = Math.max(r.scrollHeight - r.clientHeight, 1);
990
1016
  o = a / Math.max(i - 1, 1) * e;
991
1017
  } else {
992
- let e = this.#o, t = a * e, n = (this.#n.elements.body.thead?.offsetHeight || 0) + (this.#n.elements.body.tfoot?.offsetHeight || 0) + this.#n.elements.body.tbody.head.offsetHeight, s = r.offsetHeight || 0, c = Math.max(i * e + n - s, 0), l = 15e6, u = c > l, d = 1;
1018
+ let e = this.#n.template.height, t = a * e, n = (this.#n.elements.body.thead?.offsetHeight || 0) + (this.#n.elements.body.tfoot?.offsetHeight || 0) + this.#n.elements.body.tbody.head.offsetHeight, s = r.offsetHeight || 0, c = Math.max(i * e + n - s, 0), l = 15e6, u = c > l, d = 1;
993
1019
  u && (d = l / c), o = t * d;
994
1020
  }
995
- this.#u = !0, r.scrollTop = o, this.#f(o), requestAnimationFrame(() => {
1021
+ this.#c = !0, r.scrollTop = o, this.#u(o), requestAnimationFrame(() => {
996
1022
  requestAnimationFrame(() => {
997
- this.#u = !1, typeof n == "function" && n();
1023
+ this.#c = !1, typeof n == "function" && n();
998
1024
  });
999
1025
  });
1000
1026
  }
1001
1027
  destroy = () => {
1002
- this.#s &&= (this.#s.disconnect(), null);
1003
- };
1004
- #g = () => {
1005
- if (!this.#n.classList.contains("active") || !this.#n.sourceTable) return;
1006
- let e = this.#n.sourceTable?.querySelectorAll("tbody.body tr"), t = this.#n.querySelector(".ng-sheet-body .ng-container-body tbody.body");
1007
- t.querySelectorAll("tr").forEach((e) => e.remove());
1008
- let n = document.createDocumentFragment();
1009
- e.forEach((e) => n.appendChild(e.cloneNode(!0))), t.appendChild(n);
1010
- let r = t.querySelectorAll("tr");
1011
- this.#a = [], r.forEach((e) => {
1012
- this.#a.push(Math.max(e.offsetHeight, 24));
1013
- }), r.forEach((e) => e.remove()), this.#o = this.#a.reduce((e, t) => e + t, 0), this.#_();
1028
+ this.#a &&= (this.#a.disconnect(), null);
1014
1029
  };
1015
- #_ = () => {
1016
- if (this.#c > 0 && this.#o > 0) {
1017
- let e = Math.ceil(this.#c / this.#o), t = this.#e;
1018
- if (this.#d && this.#n.grouping) {
1030
+ #m = () => {};
1031
+ #h = () => {
1032
+ if (this.#o > 0 && this.#n.template.height > 0) {
1033
+ let e = Math.ceil(this.#o / this.#n.template.height), t = this.#e;
1034
+ if (this.#l && this.#n.grouping) {
1019
1035
  let e = this.#n.grouping.columns?.length || 1;
1020
1036
  t += e * 15;
1021
1037
  }
1022
- this.#l = e + t;
1038
+ this.#s = e + t;
1023
1039
  }
1024
1040
  };
1025
- #v = () => {
1041
+ #g = () => {
1026
1042
  [
1027
1043
  ".ng-container-body",
1028
1044
  ".ng-container-left",
1029
1045
  ".ng-container-right"
1030
1046
  ].forEach((e) => {
1031
1047
  let t = this.#n.querySelector(`.ng-sheet-body ${e}`);
1032
- t && t.querySelector("tbody") && this.#y(t);
1033
- }), this.#b();
1048
+ t && t.querySelector("tbody") && this.#_(t);
1049
+ }), this.#v();
1034
1050
  };
1035
- #y = (e) => {
1051
+ #_ = (e) => {
1036
1052
  let t = null;
1037
1053
  e.classList.contains("ng-container-left") ? t = "left" : e.classList.contains("ng-container-right") && (t = "right");
1038
1054
  let n = Array.from(this.#n.sourceTable.querySelectorAll("tbody.body tr")).map((e) => {
@@ -1050,10 +1066,10 @@ var m = {
1050
1066
  if (!r) return;
1051
1067
  r.querySelectorAll("tr").forEach((e) => e.remove());
1052
1068
  let i = document.createDocumentFragment();
1053
- for (let e = 0; e < this.#l; e++) n.forEach((e) => i.appendChild(e.cloneNode(!0)));
1069
+ for (let e = 0; e < this.#s; e++) n.forEach((e) => i.appendChild(e.cloneNode(!0)));
1054
1070
  r.appendChild(i), e.classList.contains("ng-container-body") && (this.#r.firstTr = r.querySelector("tr"));
1055
1071
  };
1056
- #b = () => {
1072
+ #v = () => {
1057
1073
  let e = this.#n.querySelector(".ng-sheet-body .ng-container-left table"), t = this.#n.querySelector(".ng-sheet-body .ng-container-body table"), n = this.#n.querySelector(".ng-sheet-body .ng-container-right table");
1058
1074
  if (t) {
1059
1075
  let r = e ? Array.from(e.querySelectorAll("tbody tr")) : [], i = Array.from(t.querySelectorAll("tbody tr")), a = n ? Array.from(n.querySelectorAll("tbody tr")) : [], o = Math.max(r.length, i.length, a.length);
@@ -1067,14 +1083,14 @@ var m = {
1067
1083
  }
1068
1084
  }
1069
1085
  };
1070
- #x = () => {
1071
- this.#n && this.#n instanceof HTMLElement && (this.#s = new ResizeObserver((e) => {
1086
+ #y = () => {
1087
+ this.#n && this.#n instanceof HTMLElement && (this.#a = new ResizeObserver((e) => {
1072
1088
  for (let t of e) {
1073
1089
  if (!t.target.classList.contains("active")) continue;
1074
1090
  let e = t.contentRect.height;
1075
- t.contentRect.width > 0 && this.#n.isAutoFitCol && this.#n.autoFit(!0), e > 0 && this.#c !== e && (this.#c = e, this.#_(), this.#o !== null && (this.#v(), this.refresh()));
1091
+ t.contentRect.width > 0 && this.#n.isAutoFitCol && this.#n.autoFit(!0), e > 0 && this.#o !== e && (this.#o = e, this.#h(), this.#n.template.height !== null && (this.#g(), this.refresh()));
1076
1092
  }
1077
- }), this.#s.observe(this.#n));
1093
+ }), this.#a.observe(this.#n));
1078
1094
  };
1079
1095
  }, v = class e {
1080
1096
  static compile(t) {
@@ -1193,13 +1209,15 @@ var m = {
1193
1209
  e.classList.remove("selected-start");
1194
1210
  });
1195
1211
  }), e < 0 || t < 0 || i.forEach((i) => {
1196
- Array.from(i.querySelectorAll("tbody tr")).filter((e) => e.style.display !== "none").forEach((i) => {
1197
- let { matrixRow: a } = this.#n(i);
1198
- a < 0 || (a >= e && a <= n && i.classList.add("selected"), i.querySelectorAll("td, th").forEach((i) => {
1199
- let o = parseInt(i.dataset.col, 10);
1200
- if (isNaN(o)) return;
1201
- let s = parseInt(i.rowSpan || 1, 10), c = parseInt(i.colSpan || 1, 10), l = a + s - 1, u = o + c - 1;
1202
- l >= e && a <= n && u >= t && o <= r && (i.classList.add("selected"), a <= e && i.classList.add("selected-top"), l >= n && i.classList.add("selected-bottom"), o <= t && i.classList.add("selected-left"), u >= r && i.classList.add("selected-right"));
1212
+ Array.from(i.querySelectorAll("tbody tr")).filter((e) => e.style.display !== "none").forEach((a) => {
1213
+ let { matrixRow: o } = this.#n(a);
1214
+ o < 0 || (o >= e && o <= n && i.querySelectorAll(`tbody tr[data-index="${a.dataset.index}"]`).forEach((e) => {
1215
+ e.classList.add("selected");
1216
+ }), a.querySelectorAll("td, th").forEach((i) => {
1217
+ let a = parseInt(i.dataset.col, 10);
1218
+ if (isNaN(a)) return;
1219
+ let s = parseInt(i.rowSpan || 1, 10), c = parseInt(i.colSpan || 1, 10), l = o + s - 1, u = a + c - 1;
1220
+ l >= e && o <= n && u >= t && a <= r && (i.classList.add("selected"), o <= e && i.classList.add("selected-top"), l >= n && i.classList.add("selected-bottom"), a <= t && i.classList.add("selected-left"), u >= r && i.classList.add("selected-right"));
1203
1221
  }));
1204
1222
  });
1205
1223
  });
@@ -1429,7 +1447,7 @@ var m = {
1429
1447
  this.#e.addEventListener("mousedown", (e) => {
1430
1448
  if (e.button !== 0) return;
1431
1449
  let t = e.target.closest("td, th");
1432
- t && t.dataset.index !== void 0 && t.dataset.col !== void 0 && (this.currentCell = t);
1450
+ t && t.dataset.index !== void 0 && t.dataset.col !== void 0 && (t.querySelector("cell-row-indicator") ? this.#e.row.focus(t.dataset.index) : this.currentCell = t);
1433
1451
  }), this.#e.addEventListener("keydown", (e) => {
1434
1452
  [
1435
1453
  "Enter",
@@ -2516,7 +2534,50 @@ var k = class {
2516
2534
  }
2517
2535
  });
2518
2536
  }
2519
- }, M = class extends HTMLElement {
2537
+ }, M = class {
2538
+ #e;
2539
+ #t;
2540
+ constructor(e) {
2541
+ this.#e = e, this.#t = e.getRootNode().host;
2542
+ }
2543
+ row = {
2544
+ at: () => Math.floor(this.#e.selection.minRow / this.#e.template.length),
2545
+ focus: (e) => {
2546
+ this.#e.row.isVisible(e) || this.#e.row.moveTo(e);
2547
+ let t = this.#e.querySelectorAll(`tbody.body tr[data-index="${e}"]`), n = Array.from(t, (e) => parseInt(e.dataset.matrixRow, 10)).filter((e) => !isNaN(e)), r = [];
2548
+ return t.forEach((e) => {
2549
+ e.querySelectorAll("td, th").forEach((e) => {
2550
+ parseInt(e.dataset.col, 10) != 0 && r.push(parseInt(e.dataset.col, 10));
2551
+ });
2552
+ }), this.#e.selection.setRange(Math.min(...n), Math.min(...r), Math.max(...n), Math.max(...r));
2553
+ },
2554
+ isVisible: (e) => {
2555
+ let t = this.#e.querySelector(".ng-sheet-body"), n = t.querySelectorAll(`.ng-container-body tbody.body tr[data-index="${e}"]`);
2556
+ if (!n || n.length === 0) return !1;
2557
+ let r = t.getBoundingClientRect(), i = t.querySelector("thead")?.offsetHeight || 0, a = t.querySelector("tfoot")?.offsetHeight || 0, o = r.top + i, s = r.bottom - a, c = !0;
2558
+ for (let e of n) {
2559
+ let t = e.getBoundingClientRect(), n = t.top < o, r = t.bottom > s;
2560
+ if (n || r) {
2561
+ c = !1;
2562
+ break;
2563
+ }
2564
+ }
2565
+ return c;
2566
+ },
2567
+ add: (e, t) => this.#t.data.add(e, t),
2568
+ moveTo: (e, t) => {
2569
+ this.#e.row.isVisible(e) || this.#e.scrollTo(e, t);
2570
+ },
2571
+ insert: (e, t, n = !0) => {
2572
+ let i = this.#e.view.get(e).m._[r.META.INDEX.ROWID], a = this.#t.data.insert(i, t, n);
2573
+ return this.#e.view.getArray().findIndex((e) => !e || !e.m || !e.m._ ? !1 : e.m._[r.META.INDEX.ROWID] === a);
2574
+ },
2575
+ remove: (e) => {
2576
+ let t = this.#e.view.get(e).m._[r.META.INDEX.ROWID];
2577
+ this.#t.data.remove(t);
2578
+ }
2579
+ };
2580
+ }, N = class extends HTMLElement {
2520
2581
  #e;
2521
2582
  #t;
2522
2583
  #n;
@@ -2529,14 +2590,23 @@ var k = class {
2529
2590
  #l;
2530
2591
  #u;
2531
2592
  #d;
2532
- #f = { table: null };
2533
- #p;
2593
+ #f;
2594
+ #p = { table: null };
2595
+ #m;
2596
+ #h = {
2597
+ length: 0,
2598
+ height: 0,
2599
+ heights: []
2600
+ };
2534
2601
  static SCROLLBAR_SIZE = 16;
2535
2602
  constructor() {
2536
- super(), this.#t = this.getRootNode().host, this.#n = new _(this);
2603
+ super(), this.#t = this.getRootNode().host, this.#n = new _(this), this.#d = new M(this), this.#D();
2537
2604
  }
2538
2605
  connectedCallback() {
2539
- this.#b();
2606
+ this.#S();
2607
+ }
2608
+ get template() {
2609
+ return this.#h;
2540
2610
  }
2541
2611
  get index() {
2542
2612
  return this.#e;
@@ -2566,29 +2636,29 @@ var k = class {
2566
2636
  return this.#i;
2567
2637
  }
2568
2638
  get templateLength() {
2569
- return this.#f.tbody.tr.length || 0;
2639
+ return this.#p.tbody.tr.length || 0;
2570
2640
  }
2571
2641
  get elements() {
2572
- return this.#p;
2642
+ return this.#m;
2573
2643
  }
2574
2644
  get isAutoFitCol() {
2575
- let e = this.getAttribute("auto-fit-col") === "true" || this.#t?.getAttribute("auto-fit-col") === "true", t = this.#f.table?.getAttribute("auto-fit-col") === "true";
2645
+ let e = this.getAttribute("auto-fit-col") === "true" || this.#t?.getAttribute("auto-fit-col") === "true", t = this.#p.table?.getAttribute("auto-fit-col") === "true";
2576
2646
  return e || t;
2577
2647
  }
2578
2648
  get sourceTable() {
2579
- return this.#f.table;
2649
+ return this.#p.table;
2580
2650
  }
2581
2651
  get source() {
2582
- return this.#f;
2652
+ return this.#p;
2583
2653
  }
2584
- get #m() {
2654
+ get #g() {
2585
2655
  return this.#t.hasAttribute("simple") || this.#t.getAttribute("theme") === "simple";
2586
2656
  }
2587
2657
  scrollTo = (e, t) => {
2588
2658
  this.rowManager.scrollToDataRow(e, "top", t);
2589
2659
  };
2590
2660
  recompileAndRefresh() {
2591
- this.#f.table && (v.recompile(this.#f.table), [
2661
+ this.#p.table && (v.recompile(this.#p.table), [
2592
2662
  "left",
2593
2663
  "right",
2594
2664
  "body"
@@ -2601,31 +2671,31 @@ var k = class {
2601
2671
  let n = this.querySelector(`.ng-sheet-${t} .ng-container-${e}`);
2602
2672
  n && n.querySelectorAll("table").forEach((e) => e.remove());
2603
2673
  });
2604
- }), this.#v(), this.#_(), this.#n.initialize(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar")?.refresh(), requestAnimationFrame(() => {
2605
- this.#_(), this.#n?.refresh();
2674
+ }), this.#b(), this.#y(), this.#n.initialize(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar")?.refresh(), requestAnimationFrame(() => {
2675
+ this.#y(), this.#n?.refresh();
2606
2676
  }));
2607
2677
  }
2608
2678
  refreshLayout() {
2609
2679
  requestAnimationFrame(() => {
2610
- this.classList.contains("active") && this.#f.table && (this.#_(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar")?.refresh(), this.#h(), this.#a?.refreshLayout(), this.#n?.refresh());
2680
+ this.classList.contains("active") && this.#p.table && (this.#y(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar")?.refresh(), this.#_(), this.#a?.refreshLayout(), this.#n?.refresh());
2611
2681
  });
2612
2682
  }
2613
- #h = () => {
2683
+ #_ = () => {
2614
2684
  let e = this.querySelector(".ng-container-body thead"), t = this.querySelector(".nodata-overlay");
2615
- t.style.top = `${e.offsetHeight}px`;
2685
+ t.style.top = `${e?.offsetHeight}px`;
2616
2686
  };
2617
2687
  get view() {
2618
- return !this.#d && this.#t?.data && (this.#d = new A(this)), this.#d;
2688
+ return !this.#f && this.#t?.data && (this.#f = new A(this)), this.#f;
2619
2689
  }
2620
2690
  invalidate = () => {
2621
2691
  this.view.refresh(), this.#n.refresh(!0), this.isAutoFitCol && this.autoFit(!0);
2622
2692
  };
2623
2693
  autoFit = (e = !0) => {
2624
2694
  requestAnimationFrame(() => {
2625
- this.#g?.(e);
2695
+ this.#v?.(e);
2626
2696
  });
2627
2697
  };
2628
- #g = (e = !0) => {
2698
+ #v = (e = !0) => {
2629
2699
  let t = this.querySelector(".ng-sheet-body .ng-container-body");
2630
2700
  if (!t) return;
2631
2701
  let n = this.querySelector(".ng-container-body table colgroup");
@@ -2684,17 +2754,28 @@ var k = class {
2684
2754
  this.querySelector("nine-table-hscrollbar")?.refresh();
2685
2755
  }
2686
2756
  };
2687
- generate = (e, t) => {
2688
- e.style.display = "none", this.#e = t, j.initializeTable(this.#t, e), e.style.display = "", this.#f = {
2757
+ generateTemplate = (e, t) => {
2758
+ if (this.#e = t, this.#p = {
2689
2759
  table: v.compile(e),
2690
2760
  tbody: { tr: e.querySelectorAll("tbody tr") }
2691
- }, this.#v(), this.#_(), this.#S(), this.#w(), [
2761
+ }, this.querySelector(".ng-container-body").appendChild(this.#p.table), this.#h.height = this.#h.length = 0, this.#h.heights = [], this.querySelectorAll(".ng-container-body tbody.body tr").forEach((e) => {
2762
+ this.#h.height += e.offsetHeight || 0, this.#h.heights.push(e.offsetHeight || 0);
2763
+ }), this.#h.length = this.#h.heights.length, this.#e === 0) {
2764
+ let e = parseInt(this.#t.getAttribute("display-min-rows"), 10), t = parseInt(this.#t.getAttribute("display-max-rows"), 10), n = (this.querySelector("nine-table-toolbar")?.offsetHeight || 0) + (this.querySelector("nine-table-footer")?.offsetHeight || 0) + (this.querySelector("thead")?.offsetHeight || 0) + (this.querySelector("tfoot")?.offsetHeight || 0) + (this.querySelector("tbody.head")?.offsetHeight || 0);
2765
+ this.#t.getAttribute("auto-height") !== "true" && isNaN(e) && isNaN(t) || this.#t.setAttribute("scroll-bar", "none"), isNaN(e) || (this.#t.style.minHeight = n + this.#h.height * e + "px"), isNaN(t) || (this.#t.style.maxHeight = n + this.#h.height * t + "px");
2766
+ }
2767
+ this.querySelectorAll("tbody.body tr").forEach((e) => {
2768
+ e.style.display = "none";
2769
+ }), this.querySelector(".ng-container-body table").remove();
2770
+ };
2771
+ generate = () => {
2772
+ this.#b(), this.#y(), this.#w(), this.#E(), [
2692
2773
  "left",
2693
2774
  "body",
2694
2775
  "right"
2695
2776
  ].forEach((e) => {
2696
2777
  let t = `.ng-container-${e}`;
2697
- this.#p[e] = {
2778
+ this.#m[e] = {
2698
2779
  thead: this.querySelector(`${t} thead`),
2699
2780
  tbody: {
2700
2781
  head: this.querySelector(`${t} tbody.head`),
@@ -2705,7 +2786,7 @@ var k = class {
2705
2786
  };
2706
2787
  }), this.#n.initialize(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar").refresh(), this.#u.initialize(), this.loaded = !0;
2707
2788
  };
2708
- #_ = () => {
2789
+ #y = () => {
2709
2790
  [
2710
2791
  "left",
2711
2792
  "right",
@@ -2724,7 +2805,7 @@ var k = class {
2724
2805
  });
2725
2806
  });
2726
2807
  };
2727
- #v = () => {
2808
+ #b = () => {
2728
2809
  [
2729
2810
  {
2730
2811
  selector: ".ng-container-left",
@@ -2739,11 +2820,11 @@ var k = class {
2739
2820
  type: "right"
2740
2821
  }
2741
2822
  ].forEach(({ selector: e, type: t }) => {
2742
- this.querySelector(`.ng-sheet-body ${e}`).appendChild(this.#y(t));
2823
+ this.querySelector(`.ng-sheet-body ${e}`).appendChild(this.#x(t));
2743
2824
  });
2744
2825
  };
2745
- #y = (e) => {
2746
- let t = this.#f.table.cloneNode(!0);
2826
+ #x = (e) => {
2827
+ let t = this.#p.table.cloneNode(!0);
2747
2828
  return e === "left" ? t.querySelectorAll("col, th, td").forEach((e) => {
2748
2829
  e.getAttribute("fixed") !== "left" && e.remove();
2749
2830
  }) : e === "right" ? t.querySelectorAll("col, th, td").forEach((e) => {
@@ -2753,9 +2834,9 @@ var k = class {
2753
2834
  }), t;
2754
2835
  };
2755
2836
  getRowHeight = () => this.#n.getRowHeight();
2756
- getViewHeight = () => (this.#p.content.offsetHeight || 0) - ((this.#p.body.thead?.offsetHeight || 0) + (this.#p.body.tfoot?.offsetHeight || 0) + (this.#p.body.tbody.head.offsetHeight || 0));
2837
+ getViewHeight = () => (this.#m.content.offsetHeight || 0) - ((this.#m.body.thead?.offsetHeight || 0) + (this.#m.body.tfoot?.offsetHeight || 0) + (this.#m.body.tbody.head.offsetHeight || 0));
2757
2838
  isLastRow = () => {
2758
- let e = this.querySelector(".ng-sheet-body"), t = this.querySelector(".ng-container-body tbody.body"), n = this.#p.body.tfoot?.offsetHeight || 0, r = e.getBoundingClientRect().bottom, i = t.getBoundingClientRect().bottom;
2839
+ let e = this.querySelector(".ng-sheet-body"), t = this.querySelector(".ng-container-body tbody.body"), n = this.#m.body.tfoot?.offsetHeight || 0, r = e.getBoundingClientRect().bottom, i = t.getBoundingClientRect().bottom;
2759
2840
  return r - n >= i;
2760
2841
  };
2761
2842
  scrollToX = (e) => {
@@ -2766,13 +2847,13 @@ var k = class {
2766
2847
  let t = this.querySelector(".ng-sheet-body");
2767
2848
  t && (t.scrollTop = e);
2768
2849
  };
2769
- #b = () => {
2770
- this.#x(), this.#r = new y(this), this.#i = new b(this), this.#a = new S(this), this.#o = new w(this), this.#s = new T(this), this.#d = new A(this), this.#l = new O(this), this.#u = new h(this), this.#m || (this.#c = new k(this)), this.#p.mainBody.addEventListener("scroll", () => {
2850
+ #S = () => {
2851
+ this.#C(), this.#r = new y(this), this.#i = new b(this), this.#a = new S(this), this.#o = new w(this), this.#s = new T(this), this.#f = new A(this), this.#l = new O(this), this.#u = new h(this), this.#g || (this.#c = new k(this)), this.#m.mainBody.addEventListener("scroll", () => {
2771
2852
  this.querySelector("nine-table-hscrollbar").refresh();
2772
2853
  });
2773
2854
  };
2774
- #x = () => {
2775
- this.innerHTML = "\n <div class=\"ng-sheet-body\">\n <div class=\"ng-sheet-body-content\">\n <div class=\"ng-container-left\"></div>\n <div class=\"ng-container-body\"></div>\n <div class=\"ng-container-right\"></div>\n </div>\n <div class=\"ng-virtual-height-holder\"></div>\n </div>\n\n <div class=\"nodata-overlay\">Data Not Found</div>\n\n <nine-table-vscrollbar></nine-table-vscrollbar>\n <nine-table-hscrollbar></nine-table-hscrollbar>\n <div class=\"scroll-edge\"></div>\n \n <nine-table-col-resizer-panel></nine-table-col-resizer-panel>\n \n <div class=\"ng-col-mover-grip\"></div>\n <div class=\"ng-col-mover-indi\"></div>\n ", this.#p = {
2855
+ #C = () => {
2856
+ this.innerHTML = "\n <div class=\"ng-sheet-body\">\n <div class=\"ng-sheet-body-content\">\n <div class=\"ng-container-left\"></div>\n <div class=\"ng-container-body\">\n \n </div>\n <div class=\"ng-container-right\"></div>\n </div>\n <div class=\"ng-virtual-height-holder\"></div>\n </div>\n\n <div class=\"nodata-overlay\">Data Not Found</div>\n\n <nine-table-vscrollbar></nine-table-vscrollbar>\n <nine-table-hscrollbar></nine-table-hscrollbar>\n <div class=\"scroll-edge\"></div>\n \n <nine-table-col-resizer-panel></nine-table-col-resizer-panel>\n \n <div class=\"ng-col-mover-grip\"></div>\n <div class=\"ng-col-mover-indi\"></div>\n ", this.#m = {
2776
2857
  mainBody: this.querySelector(".ng-sheet-body .ng-container-body"),
2777
2858
  hscrollbar: this.querySelector("nine-table-hscrollbar"),
2778
2859
  vscrollbar: this.querySelector("nine-table-vscrollbar"),
@@ -2780,13 +2861,13 @@ var k = class {
2780
2861
  scrollHolder: this.querySelector(".ng-sheet-body .ng-virtual-height-holder")
2781
2862
  };
2782
2863
  };
2783
- #S = () => {
2864
+ #w = () => {
2784
2865
  let e = this.querySelector(".ng-container-left table"), t = this.querySelector(".ng-container-body table"), n = this.querySelector(".ng-container-right table"), r = Array.from(e.querySelectorAll("thead tr:not(.col-indicator-rowgroup)")), i = Array.from(t.querySelectorAll("thead tr:not(.col-indicator-rowgroup)")), a = Array.from(n.querySelectorAll("thead tr:not(.col-indicator-rowgroup)"));
2785
- this.#C(r, i, a);
2866
+ this.#T(r, i, a);
2786
2867
  let o = Array.from(e.querySelectorAll("tfoot tr")), s = Array.from(t.querySelectorAll("tfoot tr")), c = Array.from(n.querySelectorAll("tfoot tr"));
2787
- this.#C(o, s, c);
2868
+ this.#T(o, s, c);
2788
2869
  };
2789
- #C = (e, t, n) => {
2870
+ #T = (e, t, n) => {
2790
2871
  setTimeout(() => {
2791
2872
  let r = Math.max(e.length, t.length, n.length);
2792
2873
  for (let i = 0; i < r; i++) {
@@ -2799,7 +2880,7 @@ var k = class {
2799
2880
  }
2800
2881
  });
2801
2882
  };
2802
- #w = () => {
2883
+ #E = () => {
2803
2884
  let e = this.querySelector(".ng-sheet-body");
2804
2885
  if (!e) return;
2805
2886
  let t = null;
@@ -2819,40 +2900,41 @@ var k = class {
2819
2900
  }), t = null);
2820
2901
  });
2821
2902
  };
2903
+ #D = () => {
2904
+ [this.#d].forEach((e) => {
2905
+ (/* @__PURE__ */ new Set([...Reflect.ownKeys(e), ...Reflect.ownKeys(Object.getPrototypeOf(e))])).forEach((t) => {
2906
+ if (t === "constructor" || String(t).startsWith("#")) return;
2907
+ let n = e[t];
2908
+ typeof n == "function" ? this[t] || (this[t] = (...t) => n.apply(e, t)) : typeof n == "object" && n && (this[t] || (this[t] = n));
2909
+ });
2910
+ });
2911
+ };
2822
2912
  disconnectedCallback() {
2823
2913
  this.#a?.destroy(), this.#o?.destroy(), this.innerHTML = "";
2824
2914
  }
2825
2915
  };
2826
- customElements.get("nine-table-sheet") || customElements.define("nine-table-sheet", M);
2916
+ customElements.get("nine-table-sheet") || customElements.define("nine-table-sheet", N);
2827
2917
  // src/layout/core/LayoutManager.js
2828
- var N = class {
2918
+ var P = class {
2829
2919
  #e;
2830
2920
  constructor(e) {
2831
2921
  this.#e = e, this.#t();
2832
2922
  }
2833
2923
  #t = () => {
2834
- this.#r(), new ResizeObserver((e) => {
2835
- for (let t of e) this.#e.getAttribute("auto-height") === "true" && this.#n();
2836
- }).observe(this.#e);
2924
+ this.#n(), this.#r();
2837
2925
  };
2838
2926
  set loading(e) {
2839
2927
  e ? this.#e.classList.add("loading") : this.#e.classList.remove("loading");
2840
2928
  }
2841
2929
  #n = () => {
2842
- let e = Array.from(this.#e.shadowRoot.querySelectorAll("nine-table-sheet.active"));
2843
- if (e.length === 0) return;
2844
- let t = parseInt(this.#e.getAttribute("max-display-row"), 10) || 10, n = Math.max(...e.map((e) => e.getRowHeight())), r = this.#e.shadowRoot.querySelector("nine-table-toolbar"), i = this.#e.shadowRoot.querySelector("nine-table-sheets-footer"), a = r ? r.getBoundingClientRect().height : 0, o = i ? i.getBoundingClientRect().height : 0, s = M.SCROLLBAR_SIZE, c = t * n + a + o + s;
2845
- this.#e.style.height = `${c}px`;
2846
- };
2847
- #r = () => {
2848
- let e = Array.from(this.#e.children).filter((e) => e.tagName.toUpperCase() === "TABLE"), t = this.#e.getAttribute("auto-height") === "true", n = e.length, r = e.map((e, t) => {
2849
- let r = t === 0 ? "active" : "", i = e.id || `sheet${t + 1}`;
2850
- return `<nine-table-sheet class="${r}" data-index="${t}" data-sheet-id="${i}" id="${i}"></nine-table-sheet>` + (t < n - 1 ? `<nine-splitter class="h" data-split-index="${t}"></nine-splitter>` : "");
2851
- }).join(""), i = ["@import \"https://cdn.jsdelivr.net/npm/@ninebone/datagrid@0.0.14/dist/css/nine-table.css\";"];
2852
- nine["nine-table"] && nine["nine-table"].cssFile && i.push(`@import "${nine["nine-table"].cssFile}";`), this.#e.shadowRoot.innerHTML = `
2930
+ let e = Array.from(this.#e.children).filter((e) => e.tagName.toUpperCase() === "TABLE"), t = e.length, n = e.map((e, n) => {
2931
+ let r = n === 0 ? "active" : "", i = e.id || `sheet${n + 1}`;
2932
+ return `<nine-table-sheet class="${r}" data-index="${n}" data-sheet-id="${i}" id="${i}"></nine-table-sheet>` + (n < t - 1 ? `<nine-splitter class="h" data-split-index="${n}"></nine-splitter>` : "");
2933
+ }).join(""), r = ["@import \"https://cdn.jsdelivr.net/npm/@ninebone/datagrid@0.0.18/dist/css/nine-table.css\";"];
2934
+ nine["nine-table"] && nine["nine-table"].cssFile && r.push(`@import "${nine["nine-table"].cssFile}";`), this.#e.shadowRoot.innerHTML = `
2853
2935
  <style>
2854
- ${i.join("\n")}
2855
- ${this.#e.customStyle}
2936
+ ${r.join("\n")}
2937
+ ${this.#e.provider.style.value}
2856
2938
  </style>
2857
2939
 
2858
2940
  <nine-table-toolbar></nine-table-toolbar>
@@ -2862,20 +2944,52 @@ var N = class {
2862
2944
  <div class="ng-loading-bar"></div>
2863
2945
  <nine-table-sheets>
2864
2946
  <nine-table-sheets-body>
2865
- ${r}
2947
+ ${n}
2866
2948
  </nine-table-sheets-body>
2867
2949
  <nine-table-sheets-footer></nine-table-sheets-footer>
2868
2950
  </nine-table-sheets>
2869
2951
  <nine-table-analysis></nine-table-analysis>
2870
2952
  </nine-table-body>
2871
2953
  <nine-table-footer></nine-table-footer>
2872
- `, this.#e.shadowRoot.querySelectorAll("nine-table-sheet").forEach((n, r) => {
2873
- e[r] && setTimeout(() => {
2874
- n.generate(e[r], r), t && this.#n();
2954
+ `, e.forEach((e) => {
2955
+ j.initializeTable(this.#e, e);
2956
+ }), this.#e.shadowRoot.querySelectorAll("nine-table-sheet").forEach((t, n) => {
2957
+ t.classList.add("active"), t.generateTemplate(e[n], n);
2958
+ }), this.#e.shadowRoot.querySelectorAll("nine-table-sheet").forEach((e) => {
2959
+ setTimeout(() => {
2960
+ e.generate(), this.#a && this.#i();
2875
2961
  });
2962
+ }), setTimeout(() => {
2963
+ this.#e.data.clear();
2964
+ });
2965
+ };
2966
+ #r = () => {
2967
+ this.#e.addEventListener(r.EVENT.ROW_ADDED, () => {
2968
+ this.#a && this.#i();
2969
+ }), this.#e.addEventListener(r.EVENT.ROW_REMOVED, () => {
2970
+ this.#a && this.#i();
2876
2971
  });
2972
+ let e = 0;
2973
+ new ResizeObserver((t) => {
2974
+ for (let n of t) if (n.target.tagName === "NINE-TABLE") {
2975
+ let t = n.contentRect.height;
2976
+ t !== e && (e = t, this.#a && this.#i());
2977
+ }
2978
+ }).observe(this.#e);
2877
2979
  };
2878
- }, P = class {
2980
+ #i = () => {
2981
+ this.#e.shadowRoot.querySelectorAll("nine-table-sheet").forEach((e) => {
2982
+ if (e.index === 0) {
2983
+ n.log(e, e.template.height, e.view.count());
2984
+ let t = (e.querySelector("thead")?.offsetHeight || 0) + (e.querySelector("tfoot")?.offsetHeight || 0) + (e.querySelector("tbody.head")?.offsetHeight || 0), r = this.#e.offsetHeight - e.offsetHeight + t, i = Math.min(e.template.height * e.view.count(), window.innerHeight * .8);
2985
+ this.#e.style.height = r + i + "px";
2986
+ }
2987
+ });
2988
+ };
2989
+ get #a() {
2990
+ return this.#e.getAttribute("auto-height") === "true";
2991
+ }
2992
+ }, F = class {
2879
2993
  #e;
2880
2994
  #t;
2881
2995
  #n = /* @__PURE__ */ new Map();
@@ -2910,30 +3024,67 @@ var N = class {
2910
3024
  return e;
2911
3025
  }
2912
3026
  }
2913
- }, F = class extends HTMLElement {
3027
+ }, I = class {
3028
+ #e;
3029
+ constructor(e) {
3030
+ this.#e = e;
3031
+ }
3032
+ provider = {
3033
+ style: { value: "" },
3034
+ add: (e) => {
3035
+ if (!e || typeof e != "object") return;
3036
+ let { style: t, ...n } = e;
3037
+ t && typeof t == "string" && (this.provider.style.value = t), Object.keys(n).length > 0 && setTimeout(() => {
3038
+ Object.entries(n).forEach(([e, t]) => {
3039
+ typeof t == "function" && (this.#e[e] = t);
3040
+ }), this.#e.rerenderer();
3041
+ });
3042
+ }
3043
+ };
3044
+ }, L = class {
3045
+ #e;
3046
+ constructor(e) {
3047
+ this.#e = e, ["row"].forEach((e) => {
3048
+ this[e] = new Proxy({}, { get: (t, n) => {
3049
+ let r = this.#t();
3050
+ if (!r || !r[e]) return;
3051
+ let i = r[e][n];
3052
+ return typeof i == "function" ? (...t) => i.apply(r[e], t) : i;
3053
+ } });
3054
+ });
3055
+ }
3056
+ getActiveSheets() {
3057
+ return this.#e.shadow.querySelectorAll("nine-table-sheet.active");
3058
+ }
3059
+ #t() {
3060
+ let e = this.getActiveSheets();
3061
+ return e.length > 0 ? e[0] : null;
3062
+ }
3063
+ }, R = class extends HTMLElement {
2914
3064
  #e;
2915
3065
  #t;
2916
3066
  #n;
2917
- #r = 0;
2918
- #i = "";
3067
+ #r;
3068
+ #i;
3069
+ #a = 0;
2919
3070
  constructor() {
2920
- super(), ["NINE-TABLE"].includes(this.tagName) && n.log("Welcome nine-table", "0.0.14"), this.#e = this.attachShadow({ mode: "open" }), this.#t = new o(this);
3071
+ super(), ["NINE-TABLE"].includes(this.tagName) && n.log("Welcome nine-table", "0.0.18"), this.#e = this.attachShadow({ mode: "open" }), this.#t = new o(this), this.#r = new I(this), this.#i = new L(this), this.#c();
2921
3072
  }
2922
3073
  connectedCallback() {
2923
3074
  setTimeout(() => {
2924
- this.#r = this.querySelectorAll("table")?.length, this.fields = new s(this), this.exprEngine = new P(this), this.#o(), this.#n = new N(this), this.#a();
3075
+ this.#a = this.querySelectorAll("table")?.length, this.fields = new s(this), this.exprEngine = new F(this), this.#s(), this.#n = new P(this), this.#o();
2925
3076
  });
2926
3077
  }
2927
3078
  disconnectedCallback() {}
2928
- #a = () => {
3079
+ #o = () => {
2929
3080
  let e = 0, t = setInterval(() => {
2930
3081
  e++;
2931
3082
  let n = this.shadow.querySelectorAll("nine-table-sheet");
2932
- if (e >= 50 && clearInterval(t), n.length >= this.#r) {
3083
+ if (e >= 50 && clearInterval(t), n.length >= this.#a) {
2933
3084
  let e = 0;
2934
3085
  n.forEach((t) => {
2935
3086
  t.loaded && e++;
2936
- }), e >= this.#r && (clearInterval(t), this.loaded = !0, this.dispatchEvent(new CustomEvent(r.EVENT.LOAD, {
3087
+ }), e >= this.#a && (clearInterval(t), this.loaded = !0, this.dispatchEvent(new CustomEvent(r.EVENT.LOAD, {
2937
3088
  bubbles: !0,
2938
3089
  detail: { target: this }
2939
3090
  })));
@@ -2949,65 +3100,6 @@ var N = class {
2949
3100
  get data() {
2950
3101
  return this.#t.data;
2951
3102
  }
2952
- get row() {
2953
- return this.#t.row;
2954
- }
2955
- get customStyle() {
2956
- return this.#i;
2957
- }
2958
- scrollTo = (e, t) => {
2959
- this.#e.querySelectorAll("nine-table-sheet.active").forEach((n) => {
2960
- n.scrollTo(e, t);
2961
- });
2962
- };
2963
- currentRow = () => {
2964
- let e = this.currentRows();
2965
- return e.length === 0 ? -1 : e[0];
2966
- };
2967
- currentRows = () => {
2968
- let e = [];
2969
- return this.#e.querySelectorAll("nine-table-sheet.active").forEach((t) => {
2970
- let n = t.view.getArray(t.selection.minRow).m._[r.META.INDEX.ROWID];
2971
- e.push(n);
2972
- }), e;
2973
- };
2974
- addRow = (e, t = !0) => this.data.add(e, t);
2975
- insertRow = (e, t, n = !0) => {
2976
- let i = this.#e.querySelector("nine-table-sheet.active");
2977
- if (!i) return;
2978
- let a = i.view.get(e).m._[r.META.INDEX.ROWID], o = this.data.insert(a, t, n);
2979
- return i.view.getArray().findIndex((e) => !e || !e.m || !e.m._ ? !1 : e.m._[r.META.INDEX.ROWID] === o);
2980
- };
2981
- removeRow = (e) => {
2982
- let t = this.#e.querySelector("nine-table-sheet.active");
2983
- if (!t) return;
2984
- let n = t.view.get(e).m._[r.META.INDEX.ROWID];
2985
- this.data.remove(n);
2986
- };
2987
- currentIndex = () => {
2988
- let e = this.currentIndexs();
2989
- return e.length === 0 ? -1 : e[0];
2990
- };
2991
- currentIndexs = () => {
2992
- let e = [];
2993
- return this.#e.querySelectorAll("nine-table-sheet.active").forEach((t) => {
2994
- e.push(t.selection.minRow);
2995
- }), e;
2996
- };
2997
- addProvider(e) {
2998
- if (!e || typeof e != "object") return;
2999
- let { style: t, ...n } = e;
3000
- if (t && typeof t == "string") {
3001
- this.#i = t;
3002
- let e = this.#e.getElementById("nine-table-scoped-custom-style");
3003
- e && (e.textContent = t);
3004
- }
3005
- Object.keys(n).length > 0 && setTimeout(() => {
3006
- Object.entries(n).forEach(([e, t]) => {
3007
- typeof t == "function" && (this[e] = t);
3008
- }), this.rerenderer();
3009
- });
3010
- }
3011
3103
  setData(e) {
3012
3104
  this.#t.data.set(e), this.refresh();
3013
3105
  }
@@ -3033,7 +3125,7 @@ var N = class {
3033
3125
  get activeSheet() {
3034
3126
  return this.shadow.querySelector("nine-table-sheet.active") || null;
3035
3127
  }
3036
- #o() {
3128
+ #s() {
3037
3129
  let e = /* @__PURE__ */ new Set();
3038
3130
  this.querySelectorAll("[data-source]").forEach((t) => {
3039
3131
  let n = t.getAttribute("data-source");
@@ -3066,20 +3158,29 @@ var N = class {
3066
3158
  });
3067
3159
  });
3068
3160
  };
3161
+ #c() {
3162
+ [this.#r, this.#i].forEach((e) => {
3163
+ (/* @__PURE__ */ new Set([...Reflect.ownKeys(e), ...Reflect.ownKeys(Object.getPrototypeOf(e))])).forEach((t) => {
3164
+ if (t === "constructor" || String(t).startsWith("#")) return;
3165
+ let n = e[t];
3166
+ typeof n == "function" ? this[t] || (this[t] = (...t) => n.apply(e, t)) : typeof n == "object" && n && (this[t] || (this[t] = n));
3167
+ });
3168
+ });
3169
+ }
3069
3170
  };
3070
- customElements.get("nine-table") || customElements.define("nine-table", F), customElements.get("nine-table-simple") || customElements.define("nine-table-simple", class extends F {
3171
+ customElements.get("nine-table") || customElements.define("nine-table", R), customElements.get("nine-table-simple") || customElements.define("nine-table-simple", class extends R {
3071
3172
  connectedCallback() {
3072
3173
  this.setAttribute("theme", "simple"), super.connectedCallback();
3073
3174
  }
3074
3175
  });
3075
3176
  // src/cell/core/BasicCellElement.js
3076
- var I = class extends HTMLElement {
3177
+ var z = class extends HTMLElement {
3077
3178
  constructor() {
3078
3179
  super();
3079
3180
  }
3080
3181
  applyBaseStyle() {}
3081
3182
  connectedCallback() {}
3082
- }, L = /* @__PURE__ */ new Map(), R = class extends I {
3183
+ }, B = /* @__PURE__ */ new Map(), V = class extends z {
3083
3184
  #e;
3084
3185
  #t;
3085
3186
  #n;
@@ -3251,7 +3352,7 @@ var I = class extends HTMLElement {
3251
3352
  }
3252
3353
  if (this.#e && typeof this.#e.exprFunction == "function") return this.#e.exprFunction(e).call(this, t, n, this.#e.data);
3253
3354
  if (e.includes("data.") || e.includes("childRecords") || e.includes("groupRecord")) {
3254
- let i = L.get("grp_" + e);
3355
+ let i = B.get("grp_" + e);
3255
3356
  return i || (i = Function("groupRecord", "row", "cell", "host", `
3256
3357
  const indices = groupRecord[3]; // GROUP_IDX.CHILDREN = 3
3257
3358
  const allRecords = host?.data?.getArray ? host.data.getArray() : [];
@@ -3276,14 +3377,14 @@ var I = class extends HTMLElement {
3276
3377
 
3277
3378
  const data = childRecords; // data.length 등을 쓸 수 있도록 호환
3278
3379
  return ${e};
3279
- `), L.set("grp_" + e, i)), i(t, n, r, this.#e);
3380
+ `), B.set("grp_" + e, i)), i(t, n, r, this.#e);
3280
3381
  }
3281
3382
  return e;
3282
3383
  } catch (t) {
3283
3384
  return console.error("Group expr evaluation error:", e, t), e;
3284
3385
  }
3285
3386
  };
3286
- }, z = class extends R {
3387
+ }, H = class extends V {
3287
3388
  get host() {
3288
3389
  return super.host;
3289
3390
  }
@@ -3314,7 +3415,7 @@ var I = class extends HTMLElement {
3314
3415
  getExprValue = (e, t, n, r) => super.getExprValue(e, t, n, r);
3315
3416
  isValid = () => super.isValid();
3316
3417
  isInvalid = () => super.isInvalid();
3317
- }, B = class extends z {
3418
+ }, U = class extends H {
3318
3419
  #e;
3319
3420
  constructor() {
3320
3421
  super();
@@ -3343,9 +3444,9 @@ var I = class extends HTMLElement {
3343
3444
  return this.cell.getAttribute("maxbyte") || this.cell.getAttribute("max-byte");
3344
3445
  }
3345
3446
  };
3346
- customElements.get("cell-input") || customElements.define("cell-input", B);
3447
+ customElements.get("cell-input") || customElements.define("cell-input", U);
3347
3448
  // src/cell/cell-input-number.js
3348
- var V = class extends z {
3449
+ var W = class extends H {
3349
3450
  #e;
3350
3451
  constructor() {
3351
3452
  super();
@@ -3429,9 +3530,9 @@ var V = class extends z {
3429
3530
  return this.cell.getAttribute("maxbyte") || this.cell.getAttribute("max-byte");
3430
3531
  }
3431
3532
  };
3432
- customElements.get("cell-input-number") || customElements.define("cell-input-number", V);
3533
+ customElements.get("cell-input-number") || customElements.define("cell-input-number", W);
3433
3534
  // src/cell/cell-input-color.js
3434
- var H = class extends z {
3535
+ var G = class extends H {
3435
3536
  #e;
3436
3537
  #t;
3437
3538
  #n;
@@ -3487,9 +3588,9 @@ var H = class extends z {
3487
3588
  return !(isNaN(t) || isNaN(n) || isNaN(r) || t < 0 || t > 255 || n < 0 || n > 255 || r < 0 || r > 255);
3488
3589
  };
3489
3590
  };
3490
- customElements.get("cell-input-color") || customElements.define("cell-input-color", H);
3591
+ customElements.get("cell-input-color") || customElements.define("cell-input-color", G);
3491
3592
  // src/cell/cell-input-date.js
3492
- var U = class extends z {
3593
+ var K = class extends H {
3493
3594
  #e;
3494
3595
  #t;
3495
3596
  constructor() {
@@ -3595,9 +3696,9 @@ var U = class extends z {
3595
3696
  return this.cell.getAttribute("max");
3596
3697
  }
3597
3698
  };
3598
- customElements.get("cell-input-date") || customElements.define("cell-input-date", U);
3699
+ customElements.get("cell-input-date") || customElements.define("cell-input-date", K);
3599
3700
  // src/cell/cell-checkbox.js
3600
- var W = class extends z {
3701
+ var q = class extends H {
3601
3702
  #e;
3602
3703
  #t;
3603
3704
  constructor() {
@@ -3670,9 +3771,9 @@ var W = class extends z {
3670
3771
  return this.cell.getAttribute("visible") || !1;
3671
3772
  }
3672
3773
  };
3673
- customElements.get("cell-checkbox") || customElements.define("cell-checkbox", W);
3774
+ customElements.get("cell-checkbox") || customElements.define("cell-checkbox", q);
3674
3775
  // src/cell/cell-radio.js
3675
- var G = class extends z {
3776
+ var J = class extends H {
3676
3777
  #e;
3677
3778
  #t = [];
3678
3779
  #n = [];
@@ -3735,9 +3836,9 @@ var G = class extends z {
3735
3836
  return this.cell.getAttribute("value-name") || "v";
3736
3837
  }
3737
3838
  };
3738
- customElements.get("cell-radio") || customElements.define("cell-radio", G);
3839
+ customElements.get("cell-radio") || customElements.define("cell-radio", J);
3739
3840
  // src/cell/cell-combo-panel.js
3740
- var K = class extends HTMLElement {
3841
+ var Y = class extends HTMLElement {
3741
3842
  #e;
3742
3843
  #t;
3743
3844
  #n;
@@ -3835,9 +3936,9 @@ var K = class extends HTMLElement {
3835
3936
  this.innerHTML = "\n <div class=\"head\">\n <input type=\"text\" class=\"search-input\" placeholder=\"Search...\" />\n </div>\n \n <nine-table-simple class=\"combo-list\" theme=\"simple\">\n <table auto-fit-col=\"true\">\n <colgroup>\n <col width=\"30\" fixed=\"left\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"100\" />\n <col width=\"0\" />\n </colgroup>\n <tbody>\n <tr>\n <td cell-type=\"checkbox\" data-bind=\"CHK\"></td>\n <td data-bind=\"tmp1\" />\n <td data-bind=\"tmp2\" />\n <td data-bind=\"tmp3\" />\n <td data-bind=\"tmp4\" />\n <td data-bind=\"tmp5\" />\n <td data-bind=\"tmp6\" />\n <td data-bind=\"tmp7\" />\n <td data-bind=\"tmp8\" />\n <td data-bind=\"tmp9\" />\n <td data-bind=\"tmp10\" />\n <td data-bind=\"k\" />\n </tr>\n </tbody>\n </table>\n </nine-table-simple>\n \n <div class=\"footer\">\n <div>\n <input id=\"chkAll\" type=\"checkbox\" checked>\n <label for=\"chkAll\">Select All</label>\n </div>\n <button id=\"btnOk\">OK</button>\n </div>\n ";
3836
3937
  };
3837
3938
  };
3838
- customElements.get("cell-combo-panel") || customElements.define("cell-combo-panel", K);
3939
+ customElements.get("cell-combo-panel") || customElements.define("cell-combo-panel", Y);
3839
3940
  // src/cell/cell-combo.js
3840
- var q = class extends z {
3941
+ var X = class extends H {
3841
3942
  #e;
3842
3943
  #t = [];
3843
3944
  #n;
@@ -3899,9 +4000,9 @@ var q = class extends z {
3899
4000
  return this.#t;
3900
4001
  }
3901
4002
  };
3902
- customElements.get("cell-combo") || customElements.define("cell-combo", q);
4003
+ customElements.get("cell-combo") || customElements.define("cell-combo", X);
3903
4004
  // src/cell/cell-renderer.js
3904
- var J = class extends R {
4005
+ var Z = class extends V {
3905
4006
  #e;
3906
4007
  constructor() {
3907
4008
  super();
@@ -3916,9 +4017,9 @@ var J = class extends R {
3916
4017
  this.innerHTML = "\n <span class=\"wrapper\"></span>\n ";
3917
4018
  };
3918
4019
  };
3919
- customElements.get("cell-renderer") || customElements.define("cell-renderer", J);
4020
+ customElements.get("cell-renderer") || customElements.define("cell-renderer", Z);
3920
4021
  // src/cell/cell-button.js
3921
- var Y = class extends R {
4022
+ var Q = class extends V {
3922
4023
  #e;
3923
4024
  constructor() {
3924
4025
  super();
@@ -3951,9 +4052,9 @@ var Y = class extends R {
3951
4052
  this.innerHTML = "\n <button class=\"button\">...</button>\n ";
3952
4053
  };
3953
4054
  };
3954
- customElements.get("cell-button") || customElements.define("cell-button", Y);
4055
+ customElements.get("cell-button") || customElements.define("cell-button", Q);
3955
4056
  // src/cell/cell-row-indicator.js
3956
- var X = class extends R {
4057
+ var $ = class extends V {
3957
4058
  #e;
3958
4059
  #t;
3959
4060
  #n;
@@ -3994,9 +4095,9 @@ var X = class extends R {
3994
4095
  this.#t.innerHTML = e, this.#t.style.display = a || o ? "" : "none";
3995
4096
  };
3996
4097
  };
3997
- customElements.get("cell-row-indicator") || customElements.define("cell-row-indicator", X);
4098
+ customElements.get("cell-row-indicator") || customElements.define("cell-row-indicator", $);
3998
4099
  // src/col/col-expand.js
3999
- var Z = class extends HTMLElement {
4100
+ var ee = class extends HTMLElement {
4000
4101
  #e;
4001
4102
  #t;
4002
4103
  constructor() {
@@ -4044,9 +4145,9 @@ var Z = class extends HTMLElement {
4044
4145
  this.removeEventListener("click", this.#n);
4045
4146
  }
4046
4147
  };
4047
- customElements.get("nine-table-col-expand") || customElements.define("nine-table-col-expand", Z);
4148
+ customElements.get("nine-table-col-expand") || customElements.define("nine-table-col-expand", ee);
4048
4149
  // src/menu/nine-table-menu.js
4049
- var Q = class extends HTMLElement {
4150
+ var te = class extends HTMLElement {
4050
4151
  #e;
4051
4152
  #t;
4052
4153
  connectedCallback() {
@@ -4215,9 +4316,9 @@ var Q = class extends HTMLElement {
4215
4316
  this.#e?.removeEventListener("contextmenu", this.#n);
4216
4317
  }
4217
4318
  };
4218
- customElements.get("nine-table-menu") || customElements.define("nine-table-menu", Q);
4319
+ customElements.get("nine-table-menu") || customElements.define("nine-table-menu", te);
4219
4320
  // src/menu/nine-table-menu-panel.js
4220
- var $ = class extends HTMLElement {
4321
+ var ne = class extends HTMLElement {
4221
4322
  #e;
4222
4323
  #t = null;
4223
4324
  constructor() {
@@ -4294,7 +4395,7 @@ var $ = class extends HTMLElement {
4294
4395
  this.close();
4295
4396
  }
4296
4397
  };
4297
- customElements.get("nine-table-menu-panel") || customElements.define("nine-table-menu-panel", $);
4398
+ customElements.get("nine-table-menu-panel") || customElements.define("nine-table-menu-panel", ne);
4298
4399
  export { r as NINE_TABLE };
4299
4400
 
4300
4401
  //# sourceMappingURL=nine-table.js.map