@ninebone/datagrid 0.0.15 → 0.0.21

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);
@@ -826,63 +846,61 @@ var m = {
826
846
  #n;
827
847
  #r;
828
848
  #i = /* @__PURE__ */ new Map();
829
- #a = [];
830
- #o = null;
831
- #s = null;
832
- #c = 0;
833
- #l;
834
- #u = !1;
835
- #d = !1;
849
+ #a = null;
850
+ #o = 0;
851
+ #s;
852
+ #c = !1;
853
+ #l = !1;
836
854
  constructor(e) {
837
- this.#t = e.getRootNode().host, this.#n = e, this.#x();
855
+ this.#t = e.getRootNode().host, this.#n = e, this.#y();
838
856
  }
839
857
  getRowHeight() {
840
- return this.#a.reduce((e, t) => e + t, 0);
858
+ return this.#n.template.height;
841
859
  }
842
860
  refresh = (e = !1) => {
843
861
  if (!this.#n.classList.contains("active")) return;
844
862
  let t = this.#n.querySelector(".ng-sheet-body");
845
- 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());
846
864
  };
847
- #f = (e, t = !1) => {
848
- if (this.#d) {
849
- this.#p(e, t);
865
+ #u = (e, t = !1) => {
866
+ if (this.#l) {
867
+ this.#d(e, t);
850
868
  return;
851
869
  }
852
- let n = this.#o;
870
+ let n = this.#n.template.height;
853
871
  if (!n || n <= 0) return;
854
872
  let i = this.#n.view.getArray(), a = i.length;
855
873
  if (a === 0) {
856
874
  this.#n.elements.scrollHolder.style.height = "0px";
857
875
  return;
858
876
  }
859
- 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;
860
- d && (f = u / l, p = u), this.#n.elements.scrollHolder.style.height = `${p}px`;
861
- 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));
862
- 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)`;
863
- let v = this.#r.firstTr, y = v && v.dataset.row !== void 0 ? parseInt(v.dataset.row, 10) : -1;
864
- (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) && ([
865
883
  this.#n.elements.left.tbody.body,
866
884
  this.#n.elements.body.tbody.body,
867
885
  this.#n.elements.right.tbody.body
868
886
  ].forEach((e, t) => {
869
887
  e && e.querySelectorAll("tbody.body tr").forEach((e, t) => {
870
- let n = _ + Math.floor(t / o);
888
+ let n = g + Math.floor(t / this.#n.template.length);
871
889
  if (n >= a) {
872
890
  e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null;
873
891
  return;
874
892
  }
875
- let s = i[n];
876
- if (!s) {
893
+ let o = i[n];
894
+ if (!o) {
877
895
  e.style.display = "none";
878
896
  return;
879
897
  }
880
- let c = s.m._[r.META.INDEX.ROWID];
881
- 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);
882
900
  });
883
901
  }), this.#n.selection.refresh());
884
902
  };
885
- #p = (e, t = !1) => {
903
+ #d = (e, t = !1) => {
886
904
  let n = this.#n.view.getArray() || [], r = n.length;
887
905
  if (r === 0) {
888
906
  this.#n.elements.scrollHolder.style.height = "0px";
@@ -891,12 +909,12 @@ var m = {
891
909
  let i = this.#n.querySelector(".ng-sheet-body .ng-sheet-body-content"), a = this.#n.templateLength || 1, o = (e) => {
892
910
  if (e.type === "group") {
893
911
  let t = e.record[m.DEPTH] || 0;
894
- return this.#a[t] || this.#o / a;
912
+ return this.#n.template.height[t] || this.#n.template.height / a;
895
913
  }
896
914
  {
897
915
  let e = 0, t = this.#n.templateLength || 1, n = 0;
898
- for (let e = 0; e < t - 1; e++) n += this.#a[e] || 0;
899
- 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;
900
918
  }
901
919
  }, s = 0, c = Array(r);
902
920
  for (let e = 0; e < r; e++) {
@@ -919,7 +937,7 @@ var m = {
919
937
  });
920
938
  let p = this.#r.firstTr, h = p && p.dataset.virtualIndex !== void 0 ? parseInt(p.dataset.virtualIndex, 10) : -1;
921
939
  if (!t && h === d) return;
922
- 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);
923
941
  [
924
942
  ".ng-container-body",
925
943
  ".ng-container-left",
@@ -941,18 +959,18 @@ var m = {
941
959
  let a = d + t;
942
960
  e.dataset.virtualIndex = a, e.dataset.row = i.type === "data" ? s : "";
943
961
  let o = e.getAttribute("grouping") === "true";
944
- 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);
945
963
  else if (o) e.style.display = "none", e.dataset.matrixRow = null, e.dataset.row = null, e.dataset.index = null;
946
964
  else {
947
965
  e.style.display = "";
948
966
  let t = i.record.m?.rowid ?? 0;
949
- this.#h(e, i.record, t, a);
967
+ this.#p(e, i.record, t, a);
950
968
  }
951
969
  });
952
970
  }
953
971
  }), this.#n.selection.refresh();
954
972
  };
955
- #m = (e, t, n, r) => {
973
+ #f = (e, t, n, r) => {
956
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) : [];
957
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) => {
958
976
  e.dataset.row = r;
@@ -960,14 +978,14 @@ var m = {
960
978
  t !== void 0 && typeof t.refresh == "function" && t?.refresh();
961
979
  });
962
980
  };
963
- #h = (e, t, n, r) => {
981
+ #p = (e, t, n, r) => {
964
982
  let i = this.#n.templateLength || 1, a = parseInt(e.dataset.subrow, 10) || 0, o = r * i + a;
965
983
  e.dataset.index = r, e.dataset.row = n, e.dataset.matrixRow = o, e.data = t, Array.from(e.cells).forEach((e) => {
966
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();
967
985
  });
968
986
  };
969
987
  initialize = () => {
970
- 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 = {
971
989
  scrollTables: this.#n.querySelectorAll(".ng-sheet-body table"),
972
990
  firstTr: this.#n.querySelector(".ng-sheet-body .ng-container-body tbody.body tr")
973
991
  }, [
@@ -985,62 +1003,52 @@ var m = {
985
1003
  this.#i.set(e, i);
986
1004
  });
987
1005
  let e = this.#n.querySelector(".ng-sheet-body");
988
- e && (this.#c = e.clientHeight, this.#g(), this.#v(), this.#f(e.scrollTop, !0), e.addEventListener("scroll", (t) => {
989
- if (this.#u) return;
990
- let n = this.#o || 0;
991
- (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());
992
1010
  }, { passive: !0 }));
993
1011
  };
994
1012
  scrollToDataRow(e, t = "top", n) {
995
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;
996
- if (this.#d) {
1014
+ if (this.#l) {
997
1015
  let e = Math.max(r.scrollHeight - r.clientHeight, 1);
998
1016
  o = a / Math.max(i - 1, 1) * e;
999
1017
  } else {
1000
- 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;
1001
1019
  u && (d = l / c), o = t * d;
1002
1020
  }
1003
- this.#u = !0, r.scrollTop = o, this.#f(o), requestAnimationFrame(() => {
1021
+ this.#c = !0, r.scrollTop = o, this.#u(o), requestAnimationFrame(() => {
1004
1022
  requestAnimationFrame(() => {
1005
- this.#u = !1, typeof n == "function" && n();
1023
+ this.#c = !1, typeof n == "function" && n();
1006
1024
  });
1007
1025
  });
1008
1026
  }
1009
1027
  destroy = () => {
1010
- this.#s &&= (this.#s.disconnect(), null);
1011
- };
1012
- #g = () => {
1013
- if (!this.#n.classList.contains("active") || !this.#n.sourceTable) return;
1014
- let e = this.#n.sourceTable?.querySelectorAll("tbody.body tr"), t = this.#n.querySelector(".ng-sheet-body .ng-container-body tbody.body");
1015
- t.querySelectorAll("tr").forEach((e) => e.remove());
1016
- let n = document.createDocumentFragment();
1017
- e.forEach((e) => n.appendChild(e.cloneNode(!0))), t.appendChild(n);
1018
- let r = t.querySelectorAll("tr");
1019
- this.#a = [], r.forEach((e) => {
1020
- this.#a.push(Math.max(e.offsetHeight, 24));
1021
- }), r.forEach((e) => e.remove()), this.#o = this.#a.reduce((e, t) => e + t, 0), this.#_();
1028
+ this.#a &&= (this.#a.disconnect(), null);
1022
1029
  };
1023
- #_ = () => {
1024
- if (this.#c > 0 && this.#o > 0) {
1025
- let e = Math.ceil(this.#c / this.#o), t = this.#e;
1026
- 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) {
1027
1035
  let e = this.#n.grouping.columns?.length || 1;
1028
1036
  t += e * 15;
1029
1037
  }
1030
- this.#l = e + t;
1038
+ this.#s = e + t;
1031
1039
  }
1032
1040
  };
1033
- #v = () => {
1041
+ #g = () => {
1034
1042
  [
1035
1043
  ".ng-container-body",
1036
1044
  ".ng-container-left",
1037
1045
  ".ng-container-right"
1038
1046
  ].forEach((e) => {
1039
1047
  let t = this.#n.querySelector(`.ng-sheet-body ${e}`);
1040
- t && t.querySelector("tbody") && this.#y(t);
1041
- }), this.#b();
1048
+ t && t.querySelector("tbody") && this.#_(t);
1049
+ }), this.#v();
1042
1050
  };
1043
- #y = (e) => {
1051
+ #_ = (e) => {
1044
1052
  let t = null;
1045
1053
  e.classList.contains("ng-container-left") ? t = "left" : e.classList.contains("ng-container-right") && (t = "right");
1046
1054
  let n = Array.from(this.#n.sourceTable.querySelectorAll("tbody.body tr")).map((e) => {
@@ -1058,10 +1066,10 @@ var m = {
1058
1066
  if (!r) return;
1059
1067
  r.querySelectorAll("tr").forEach((e) => e.remove());
1060
1068
  let i = document.createDocumentFragment();
1061
- 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)));
1062
1070
  r.appendChild(i), e.classList.contains("ng-container-body") && (this.#r.firstTr = r.querySelector("tr"));
1063
1071
  };
1064
- #b = () => {
1072
+ #v = () => {
1065
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");
1066
1074
  if (t) {
1067
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);
@@ -1075,14 +1083,14 @@ var m = {
1075
1083
  }
1076
1084
  }
1077
1085
  };
1078
- #x = () => {
1079
- 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) => {
1080
1088
  for (let t of e) {
1081
1089
  if (!t.target.classList.contains("active")) continue;
1082
1090
  let e = t.contentRect.height;
1083
- 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()));
1084
1092
  }
1085
- }), this.#s.observe(this.#n));
1093
+ }), this.#a.observe(this.#n));
1086
1094
  };
1087
1095
  }, v = class e {
1088
1096
  static compile(t) {
@@ -2585,12 +2593,20 @@ var k = class {
2585
2593
  #f;
2586
2594
  #p = { table: null };
2587
2595
  #m;
2596
+ #h = {
2597
+ length: 0,
2598
+ height: 0,
2599
+ heights: []
2600
+ };
2588
2601
  static SCROLLBAR_SIZE = 16;
2589
2602
  constructor() {
2590
- super(), this.#t = this.getRootNode().host, this.#n = new _(this), this.#d = new M(this), this.#E();
2603
+ super(), this.#t = this.getRootNode().host, this.#n = new _(this), this.#d = new M(this), this.#D();
2591
2604
  }
2592
2605
  connectedCallback() {
2593
- this.#x();
2606
+ this.#S();
2607
+ }
2608
+ get template() {
2609
+ return this.#h;
2594
2610
  }
2595
2611
  get index() {
2596
2612
  return this.#e;
@@ -2625,12 +2641,6 @@ var k = class {
2625
2641
  get elements() {
2626
2642
  return this.#m;
2627
2643
  }
2628
- get template() {
2629
- return {
2630
- length: this.#p?.tbody?.tr?.length || 0,
2631
- trs: this.#p?.tbody?.tr || []
2632
- };
2633
- }
2634
2644
  get isAutoFitCol() {
2635
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";
2636
2646
  return e || t;
@@ -2641,7 +2651,7 @@ var k = class {
2641
2651
  get source() {
2642
2652
  return this.#p;
2643
2653
  }
2644
- get #h() {
2654
+ get #g() {
2645
2655
  return this.#t.hasAttribute("simple") || this.#t.getAttribute("theme") === "simple";
2646
2656
  }
2647
2657
  scrollTo = (e, t) => {
@@ -2661,18 +2671,18 @@ var k = class {
2661
2671
  let n = this.querySelector(`.ng-sheet-${t} .ng-container-${e}`);
2662
2672
  n && n.querySelectorAll("table").forEach((e) => e.remove());
2663
2673
  });
2664
- }), this.#y(), this.#v(), this.#n.initialize(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar")?.refresh(), requestAnimationFrame(() => {
2665
- this.#v(), 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();
2666
2676
  }));
2667
2677
  }
2668
2678
  refreshLayout() {
2669
2679
  requestAnimationFrame(() => {
2670
- this.classList.contains("active") && this.#p.table && (this.#v(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar")?.refresh(), this.#g(), 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());
2671
2681
  });
2672
2682
  }
2673
- #g = () => {
2683
+ #_ = () => {
2674
2684
  let e = this.querySelector(".ng-container-body thead"), t = this.querySelector(".nodata-overlay");
2675
- t.style.top = `${e.offsetHeight}px`;
2685
+ t.style.top = `${e?.offsetHeight}px`;
2676
2686
  };
2677
2687
  get view() {
2678
2688
  return !this.#f && this.#t?.data && (this.#f = new A(this)), this.#f;
@@ -2682,10 +2692,10 @@ var k = class {
2682
2692
  };
2683
2693
  autoFit = (e = !0) => {
2684
2694
  requestAnimationFrame(() => {
2685
- this.#_?.(e);
2695
+ this.#v?.(e);
2686
2696
  });
2687
2697
  };
2688
- #_ = (e = !0) => {
2698
+ #v = (e = !0) => {
2689
2699
  let t = this.querySelector(".ng-sheet-body .ng-container-body");
2690
2700
  if (!t) return;
2691
2701
  let n = this.querySelector(".ng-container-body table colgroup");
@@ -2744,11 +2754,22 @@ var k = class {
2744
2754
  this.querySelector("nine-table-hscrollbar")?.refresh();
2745
2755
  }
2746
2756
  };
2747
- generate = (e, t) => {
2748
- e.style.display = "none", this.#e = t, j.initializeTable(this.#t, e), e.style.display = "", this.#p = {
2757
+ generateTemplate = (e, t) => {
2758
+ if (this.#e = t, this.#p = {
2749
2759
  table: v.compile(e),
2750
2760
  tbody: { tr: e.querySelectorAll("tbody tr") }
2751
- }, this.#y(), this.#v(), this.#C(), this.#T(), [
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(), [
2752
2773
  "left",
2753
2774
  "body",
2754
2775
  "right"
@@ -2765,7 +2786,7 @@ var k = class {
2765
2786
  };
2766
2787
  }), this.#n.initialize(), this.isAutoFitCol ? this.autoFit(!0) : this.querySelector("nine-table-hscrollbar").refresh(), this.#u.initialize(), this.loaded = !0;
2767
2788
  };
2768
- #v = () => {
2789
+ #y = () => {
2769
2790
  [
2770
2791
  "left",
2771
2792
  "right",
@@ -2784,7 +2805,7 @@ var k = class {
2784
2805
  });
2785
2806
  });
2786
2807
  };
2787
- #y = () => {
2808
+ #b = () => {
2788
2809
  [
2789
2810
  {
2790
2811
  selector: ".ng-container-left",
@@ -2799,10 +2820,10 @@ var k = class {
2799
2820
  type: "right"
2800
2821
  }
2801
2822
  ].forEach(({ selector: e, type: t }) => {
2802
- this.querySelector(`.ng-sheet-body ${e}`).appendChild(this.#b(t));
2823
+ this.querySelector(`.ng-sheet-body ${e}`).appendChild(this.#x(t));
2803
2824
  });
2804
2825
  };
2805
- #b = (e) => {
2826
+ #x = (e) => {
2806
2827
  let t = this.#p.table.cloneNode(!0);
2807
2828
  return e === "left" ? t.querySelectorAll("col, th, td").forEach((e) => {
2808
2829
  e.getAttribute("fixed") !== "left" && e.remove();
@@ -2826,13 +2847,13 @@ var k = class {
2826
2847
  let t = this.querySelector(".ng-sheet-body");
2827
2848
  t && (t.scrollTop = e);
2828
2849
  };
2829
- #x = () => {
2830
- this.#S(), 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.#h || (this.#c = new k(this)), this.#m.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", () => {
2831
2852
  this.querySelector("nine-table-hscrollbar").refresh();
2832
2853
  });
2833
2854
  };
2834
- #S = () => {
2835
- 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.#m = {
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 = {
2836
2857
  mainBody: this.querySelector(".ng-sheet-body .ng-container-body"),
2837
2858
  hscrollbar: this.querySelector("nine-table-hscrollbar"),
2838
2859
  vscrollbar: this.querySelector("nine-table-vscrollbar"),
@@ -2840,13 +2861,13 @@ var k = class {
2840
2861
  scrollHolder: this.querySelector(".ng-sheet-body .ng-virtual-height-holder")
2841
2862
  };
2842
2863
  };
2843
- #C = () => {
2864
+ #w = () => {
2844
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)"));
2845
- this.#w(r, i, a);
2866
+ this.#T(r, i, a);
2846
2867
  let o = Array.from(e.querySelectorAll("tfoot tr")), s = Array.from(t.querySelectorAll("tfoot tr")), c = Array.from(n.querySelectorAll("tfoot tr"));
2847
- this.#w(o, s, c);
2868
+ this.#T(o, s, c);
2848
2869
  };
2849
- #w = (e, t, n) => {
2870
+ #T = (e, t, n) => {
2850
2871
  setTimeout(() => {
2851
2872
  let r = Math.max(e.length, t.length, n.length);
2852
2873
  for (let i = 0; i < r; i++) {
@@ -2859,7 +2880,7 @@ var k = class {
2859
2880
  }
2860
2881
  });
2861
2882
  };
2862
- #T = () => {
2883
+ #E = () => {
2863
2884
  let e = this.querySelector(".ng-sheet-body");
2864
2885
  if (!e) return;
2865
2886
  let t = null;
@@ -2879,7 +2900,7 @@ var k = class {
2879
2900
  }), t = null);
2880
2901
  });
2881
2902
  };
2882
- #E = () => {
2903
+ #D = () => {
2883
2904
  [this.#d].forEach((e) => {
2884
2905
  (/* @__PURE__ */ new Set([...Reflect.ownKeys(e), ...Reflect.ownKeys(Object.getPrototypeOf(e))])).forEach((t) => {
2885
2906
  if (t === "constructor" || String(t).startsWith("#")) return;
@@ -2900,28 +2921,20 @@ var P = class {
2900
2921
  this.#e = e, this.#t();
2901
2922
  }
2902
2923
  #t = () => {
2903
- this.#r(), new ResizeObserver((e) => {
2904
- for (let t of e) this.#e.getAttribute("auto-height") === "true" && this.#n();
2905
- }).observe(this.#e);
2924
+ this.#n(), this.#r();
2906
2925
  };
2907
2926
  set loading(e) {
2908
2927
  e ? this.#e.classList.add("loading") : this.#e.classList.remove("loading");
2909
2928
  }
2910
2929
  #n = () => {
2911
- let e = Array.from(this.#e.shadowRoot.querySelectorAll("nine-table-sheet.active"));
2912
- if (e.length === 0) return;
2913
- 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 = N.SCROLLBAR_SIZE, c = t * n + a + o + s;
2914
- this.#e.style.height = `${c}px`;
2915
- };
2916
- #r = () => {
2917
- 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) => {
2918
- let r = t === 0 ? "active" : "", i = e.id || `sheet${t + 1}`;
2919
- 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>` : "");
2920
- }).join(""), i = ["@import \"https://cdn.jsdelivr.net/npm/@ninebone/datagrid@0.0.15/dist/css/nine-table.css\";"];
2921
- 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.21/dist/css/nine-table.css\";"];
2934
+ nine["nine-table"] && nine["nine-table"].cssFile && r.push(`@import "${nine["nine-table"].cssFile}";`), this.#e.shadowRoot.innerHTML = `
2922
2935
  <style>
2923
- ${i.join("\n")}
2924
- ${this.#e.customStyle}
2936
+ ${r.join("\n")}
2937
+ ${this.#e.provider.style.value}
2925
2938
  </style>
2926
2939
 
2927
2940
  <nine-table-toolbar></nine-table-toolbar>
@@ -2931,19 +2944,51 @@ var P = class {
2931
2944
  <div class="ng-loading-bar"></div>
2932
2945
  <nine-table-sheets>
2933
2946
  <nine-table-sheets-body>
2934
- ${r}
2947
+ ${n}
2935
2948
  </nine-table-sheets-body>
2936
2949
  <nine-table-sheets-footer></nine-table-sheets-footer>
2937
2950
  </nine-table-sheets>
2938
2951
  <nine-table-analysis></nine-table-analysis>
2939
2952
  </nine-table-body>
2940
2953
  <nine-table-footer></nine-table-footer>
2941
- `, this.#e.shadowRoot.querySelectorAll("nine-table-sheet").forEach((n, r) => {
2942
- e[r] && setTimeout(() => {
2943
- 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();
2944
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();
2945
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);
2946
2979
  };
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
+ }
2947
2992
  }, F = class {
2948
2993
  #e;
2949
2994
  #t;
@@ -2984,12 +3029,24 @@ var P = class {
2984
3029
  constructor(e) {
2985
3030
  this.#e = e;
2986
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
+ };
2987
3044
  }, L = class {
2988
3045
  #e;
2989
3046
  constructor(e) {
2990
3047
  this.#e = e, ["row"].forEach((e) => {
2991
3048
  this[e] = new Proxy({}, { get: (t, n) => {
2992
- let r = this.getActiveSheet();
3049
+ let r = this.#t();
2993
3050
  if (!r || !r[e]) return;
2994
3051
  let i = r[e][n];
2995
3052
  return typeof i == "function" ? (...t) => i.apply(r[e], t) : i;
@@ -2999,7 +3056,7 @@ var P = class {
2999
3056
  getActiveSheets() {
3000
3057
  return this.#e.shadow.querySelectorAll("nine-table-sheet.active");
3001
3058
  }
3002
- getActiveSheet() {
3059
+ #t() {
3003
3060
  let e = this.getActiveSheets();
3004
3061
  return e.length > 0 ? e[0] : null;
3005
3062
  }
@@ -3010,17 +3067,16 @@ var P = class {
3010
3067
  #r;
3011
3068
  #i;
3012
3069
  #a = 0;
3013
- #o = "";
3014
3070
  constructor() {
3015
- super(), ["NINE-TABLE"].includes(this.tagName) && n.log("Welcome nine-table", "0.0.15"), this.#e = this.attachShadow({ mode: "open" }), this.#t = new o(this), this.#r = new I(this), this.#i = new L(this), this.#l();
3071
+ super(), ["NINE-TABLE"].includes(this.tagName) && n.log("Welcome nine-table", "0.0.21"), this.#e = this.attachShadow({ mode: "open" }), this.#t = new o(this), this.#r = new I(this), this.#i = new L(this), this.#c();
3016
3072
  }
3017
3073
  connectedCallback() {
3018
3074
  setTimeout(() => {
3019
- this.#a = this.querySelectorAll("table")?.length, this.fields = new s(this), this.exprEngine = new F(this), this.#c(), this.#n = new P(this), this.#s();
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();
3020
3076
  });
3021
3077
  }
3022
3078
  disconnectedCallback() {}
3023
- #s = () => {
3079
+ #o = () => {
3024
3080
  let e = 0, t = setInterval(() => {
3025
3081
  e++;
3026
3082
  let n = this.shadow.querySelectorAll("nine-table-sheet");
@@ -3044,23 +3100,6 @@ var P = class {
3044
3100
  get data() {
3045
3101
  return this.#t.data;
3046
3102
  }
3047
- get customStyle() {
3048
- return this.#o;
3049
- }
3050
- addProvider(e) {
3051
- if (!e || typeof e != "object") return;
3052
- let { style: t, ...n } = e;
3053
- if (t && typeof t == "string") {
3054
- this.#o = t;
3055
- let e = this.#e.getElementById("nine-table-scoped-custom-style");
3056
- e && (e.textContent = t);
3057
- }
3058
- Object.keys(n).length > 0 && setTimeout(() => {
3059
- Object.entries(n).forEach(([e, t]) => {
3060
- typeof t == "function" && (this[e] = t);
3061
- }), this.rerenderer();
3062
- });
3063
- }
3064
3103
  setData(e) {
3065
3104
  this.#t.data.set(e), this.refresh();
3066
3105
  }
@@ -3086,7 +3125,7 @@ var P = class {
3086
3125
  get activeSheet() {
3087
3126
  return this.shadow.querySelector("nine-table-sheet.active") || null;
3088
3127
  }
3089
- #c() {
3128
+ #s() {
3090
3129
  let e = /* @__PURE__ */ new Set();
3091
3130
  this.querySelectorAll("[data-source]").forEach((t) => {
3092
3131
  let n = t.getAttribute("data-source");
@@ -3119,8 +3158,8 @@ var P = class {
3119
3158
  });
3120
3159
  });
3121
3160
  };
3122
- #l() {
3123
- [this.#i].forEach((e) => {
3161
+ #c() {
3162
+ [this.#r, this.#i].forEach((e) => {
3124
3163
  (/* @__PURE__ */ new Set([...Reflect.ownKeys(e), ...Reflect.ownKeys(Object.getPrototypeOf(e))])).forEach((t) => {
3125
3164
  if (t === "constructor" || String(t).startsWith("#")) return;
3126
3165
  let n = e[t];