@plotdb/sheet 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Change Logs
2
2
 
3
+ ## v0.7.2
4
+
5
+ - support horizontal scrolling with shift + wheel, for mouse with vertical wheel only
6
+ - add `scrollbar` option for optional overlay scrollbars
7
+ - fix bug: `Math.max.apply` over `@_data` gives NaN once `@_data` becomes sparse, which
8
+ happens after scrolling far away. this made `select all` produce a NaN column bound.
9
+ - fix bug: `select all` bound grows as we scroll, since rendering out of range cells
10
+ extends `@_data` with empty rows
11
+ - upgrade dependencies
12
+ - add context dev dependency
13
+
14
+
15
+ ## v0.7.1
16
+
17
+ - fix bug: pasting HTML table with whitespace/newlines in cell content causes unexpected line breaks due to `white-space: pre`
18
+ - fix bug: row headers collapse and become invisible after deleting all cell content
19
+ - fix bug: `_content` accessing wrong DOM node when pasted data exceeds visible column range
20
+ - fix bug: `cellcfg` option causes exception if non-function value is provided
21
+ - upgrade dev dependencies for vulnerability fixing
22
+
23
+
3
24
  ## v0.7.0
4
25
 
5
26
  - support number formatting based on d3-format
package/README.md CHANGED
@@ -57,6 +57,12 @@ initialize:
57
57
  - `enableScrolling` is for mouse / trackpad scrolling behavior
58
58
  - `data`: initial data, as array of arrays
59
59
  - `slider`: default false. show slider widgets if true.
60
+ - `scrollbar`: default false. show overlay scrollbars if true.
61
+ - scrolling is index based ( we move by cells, not by pixels ), so is the scrollbar.
62
+ - the grid has no hard boundary when moving down / right, so the scrollbar is bound to
63
+ the data plus one page. scrolling beyond it is still allowed - the thumb just sticks
64
+ to the end. the scrollbar hides itself when there is nothing to scroll.
65
+ - dragging the thumb moves the view; clicking on the track pages toward the clicked side.
60
66
  - `cellcfg(opt)`: custom cell definition function. return value based on the given `opt`, which contains:
61
67
  - `row`: row of the cell to query
62
68
  - `col`: col of the cell to query
package/index.css CHANGED
@@ -115,6 +115,59 @@
115
115
  height: initial;
116
116
  opacity: initial;
117
117
  }
118
+ .sheet .scroll-y,
119
+ .sheet .scroll-x {
120
+ position: absolute;
121
+ z-index: 130;
122
+ background: rgba(0,0,0,0.04);
123
+ /* overlay scrollbar. it should never take space from the grid. */
124
+ }
125
+ .sheet .scroll-y.idle,
126
+ .sheet .scroll-x.idle {
127
+ opacity: 0;
128
+ pointer-events: none;
129
+ }
130
+ .sheet .scroll-y .thumb,
131
+ .sheet .scroll-x .thumb {
132
+ position: absolute;
133
+ top: 0;
134
+ left: 0;
135
+ border-radius: 4px;
136
+ background: rgba(0,0,0,0.32);
137
+ transition: background 0.1s ease;
138
+ }
139
+ .sheet .scroll-y:hover .thumb,
140
+ .sheet .scroll-x:hover .thumb,
141
+ .sheet .scroll-y.active .thumb,
142
+ .sheet .scroll-x.active .thumb {
143
+ background: rgba(0,0,0,0.52);
144
+ }
145
+ .sheet .scroll-y {
146
+ top: 0;
147
+ right: 0;
148
+ bottom: 10px;
149
+ width: 10px;
150
+ cursor: default;
151
+ }
152
+ .sheet .scroll-y .thumb {
153
+ width: 100%;
154
+ }
155
+ .sheet .scroll-x {
156
+ left: 0;
157
+ right: 10px;
158
+ bottom: 0;
159
+ height: 10px;
160
+ cursor: default;
161
+ }
162
+ .sheet .scroll-x .thumb {
163
+ height: 100%;
164
+ }
165
+ .sheet.has-scrollbar .slide-y {
166
+ right: 12px;
167
+ }
168
+ .sheet.has-scrollbar .slide-x {
169
+ bottom: 12px;
170
+ }
118
171
  .sheet .slide-y,
119
172
  .sheet .slide-x {
120
173
  display: flex;
package/index.js CHANGED
@@ -67,7 +67,7 @@
67
67
  ? document.querySelector(opt.root)
68
68
  : opt.root;
69
69
  this.evtHandler = {};
70
- this._ccfg = opt.cellcfg;
70
+ this._ccfg = typeof opt.cellcfg === 'function' ? opt.cellcfg : null;
71
71
  this._data = opt.data || [];
72
72
  this._size = {
73
73
  row: (ref$ = import$({
@@ -134,7 +134,7 @@
134
134
  };
135
135
  this.les = {};
136
136
  this.editing = {};
137
- this.dom = Object.fromEntries(['sheet', 'inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x'].map(function(it){
137
+ this.dom = Object.fromEntries(['sheet', 'inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x', 'scroll-y', 'scroll-x'].map(function(it){
138
138
  var x$, n;
139
139
  x$ = n = document.createElement('div');
140
140
  x$.classList.add(it);
@@ -143,12 +143,26 @@
143
143
  this.dom.sheet.setAttribute('tabindex', -1);
144
144
  this.dom.textarea = document.createElement('textarea');
145
145
  this.root.appendChild(this.dom.sheet);
146
- ['inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x'].map(function(it){
146
+ ['inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x', 'scroll-y', 'scroll-x'].map(function(it){
147
147
  return this$.dom.sheet.appendChild(this$.dom[it]);
148
148
  });
149
149
  if (!this.opt.slider) {
150
150
  this.dom["slide-x"].style.display = this.dom["slide-y"].style.display = 'none';
151
151
  }
152
+ this.scrollbar = !!this.opt.scrollbar;
153
+ ['x', 'y'].map(function(it){
154
+ var x$, n;
155
+ x$ = n = document.createElement('div');
156
+ x$.classList.add('thumb');
157
+ this$.dom["scroll-" + it].appendChild(n);
158
+ this$.dom["thumb-" + it] = n;
159
+ if (!this$.scrollbar) {
160
+ return this$.dom["scroll-" + it].style.display = 'none';
161
+ }
162
+ });
163
+ if (this.scrollbar) {
164
+ this.dom.sheet.classList.add('has-scrollbar');
165
+ }
152
166
  this.dom.edit.appendChild(this.dom.textarea);
153
167
  this._init();
154
168
  return this;
@@ -248,7 +262,7 @@
248
262
  });
249
263
  dom.addEventListener('mousemove', function(e){
250
264
  var p, ref$, idx;
251
- if (this$._slider.y.on || this$._slider.x.on) {
265
+ if (this$._slider.y.on || this$._slider.x.on || this$._scrolling) {
252
266
  return;
253
267
  }
254
268
  if (this$.editing.on || !(e.buttons && (p = parent(e.target, '.cell', dom)))) {
@@ -387,6 +401,7 @@
387
401
  range: true,
388
402
  src: 'user'
389
403
  });
404
+ this$.render();
390
405
  }
391
406
  if (code === 189 && (e.metaKey || e.ctrlKey)) {
392
407
  this$.slice();
@@ -557,7 +572,32 @@
557
572
  return this$._slider[n].hc(e);
558
573
  });
559
574
  });
560
- return document.addEventListener('wheel', function(e){
575
+ if (this.scrollbar) {
576
+ ['x', 'y'].map(function(n){
577
+ return this$.dom["scroll-" + n].addEventListener('mousedown', function(e){
578
+ var ref$, t, cl, box, info, d;
579
+ e.preventDefault();
580
+ e.stopPropagation();
581
+ if (e.target === this$.dom["thumb-" + n]) {
582
+ return this$._scrollDrag(n, e);
583
+ }
584
+ ref$ = n === 'y'
585
+ ? ['row', 'clientY']
586
+ : ['col', 'clientX'], t = ref$[0], cl = ref$[1];
587
+ box = this$.dom["thumb-" + n].getBoundingClientRect();
588
+ info = this$._scrollInfo(t);
589
+ d = e[cl] < box[n === 'y' ? 'top' : 'left'] ? -1 : 1;
590
+ return this$._scrollTo(t, this$.pos[t] + d * ((ref$ = info.vis) > 1 ? ref$ : 1), info);
591
+ });
592
+ });
593
+ if (window.ResizeObserver != null) {
594
+ this._ro = new ResizeObserver(function(){
595
+ return this$.renderScrollbar();
596
+ });
597
+ this._ro.observe(this.dom.sheet);
598
+ }
599
+ }
600
+ document.addEventListener('wheel', function(e){
561
601
  var inscope, spos, ref$, dx, dy, ox, oy;
562
602
  inscope = this$.eventInScope(e);
563
603
  if (this$.opt.enableScrolling != null && !this$.opt.enableScrolling) {
@@ -575,6 +615,9 @@
575
615
  }
576
616
  spos = this$.scrollPos;
577
617
  ref$ = [e.deltaX, e.deltaY], dx = ref$[0], dy = ref$[1];
618
+ if (e.shiftKey && Math.abs(dy) > Math.abs(dx)) {
619
+ ref$ = [dy, 0], dx = ref$[0], dy = ref$[1];
620
+ }
578
621
  ref$ = Math.abs(dx) > Math.abs(dy)
579
622
  ? [dx, 0]
580
623
  : [0, dy], dx = ref$[0], dy = ref$[1];
@@ -597,6 +640,7 @@
597
640
  }, {
598
641
  passive: false
599
642
  });
643
+ return this.renderScrollbar();
600
644
  },
601
645
  select: function(o){
602
646
  var ret, that;
@@ -665,12 +709,10 @@
665
709
  : [p2.row, p1.row], sr = ref$[0], er = ref$[1];
666
710
  if (o.defined == null || o.defined) {
667
711
  if (ec == null) {
668
- ec = Math.max.apply(Math, this._data.map(function(it){
669
- return it.length;
670
- }));
712
+ ec = this._dataSize('col');
671
713
  }
672
714
  if (er == null) {
673
- er = this._data.length;
715
+ er = this._dataSize('row');
674
716
  }
675
717
  }
676
718
  return {
@@ -782,6 +824,143 @@
782
824
  return this$._size.row[it + this$.pos.row - this$.xif.row[1]] || "max-content";
783
825
  }).join(' ');
784
826
  },
827
+ _viewport: function(){
828
+ var sbox, inner, ret, i$, to$, y, n, x;
829
+ sbox = this.dom.sheet.getBoundingClientRect();
830
+ inner = this.dom.inner;
831
+ ret = {
832
+ row: 0,
833
+ col: 0
834
+ };
835
+ for (i$ = this.xif.row[2], to$ = this.dim.row; i$ < to$; ++i$) {
836
+ y = i$;
837
+ if (!(n = inner.childNodes[y * this.dim.col])) {
838
+ break;
839
+ }
840
+ if (n.getBoundingClientRect().top >= sbox.bottom) {
841
+ break;
842
+ }
843
+ ret.row++;
844
+ }
845
+ for (i$ = this.xif.col[2], to$ = this.dim.col; i$ < to$; ++i$) {
846
+ x = i$;
847
+ if (!(n = inner.childNodes[x])) {
848
+ break;
849
+ }
850
+ if (n.getBoundingClientRect().left >= sbox.right) {
851
+ break;
852
+ }
853
+ ret.col++;
854
+ }
855
+ return ret;
856
+ },
857
+ _dataSize: function(t){
858
+ var ret, i$, ref$, len$, r, i;
859
+ if (t === 'col') {
860
+ ret = 0;
861
+ for (i$ = 0, len$ = (ref$ = this._data).length; i$ < len$; ++i$) {
862
+ r = ref$[i$];
863
+ if (r && r.length > ret) {
864
+ ret = r.length;
865
+ }
866
+ }
867
+ return ret;
868
+ }
869
+ i = this._data.length;
870
+ while (i > 0 && !(this._data[i - 1] || []).length) {
871
+ i--;
872
+ }
873
+ return i;
874
+ },
875
+ _scrollInfo: function(t){
876
+ var vis, total;
877
+ vis = this._viewport()[t];
878
+ total = this._dataSize(t);
879
+ return {
880
+ vis: vis,
881
+ total: total,
882
+ extent: total + vis,
883
+ max: total
884
+ };
885
+ },
886
+ _scrollTo: function(t, v, info){
887
+ var ref$, ref1$, ref2$;
888
+ info == null && (info = this._scrollInfo(t));
889
+ v = (ref$ = (ref1$ = Math.round(v)) < (ref2$ = info.max) ? ref1$ : ref2$) > 0 ? ref$ : 0;
890
+ if (v === this.pos[t]) {
891
+ return;
892
+ }
893
+ return this.goto(t === 'row'
894
+ ? {
895
+ row: v
896
+ }
897
+ : {
898
+ col: v
899
+ });
900
+ },
901
+ _scrollMetric: function(n, info){
902
+ var dim, len, size, ref$, ref1$;
903
+ dim = n === 'y' ? 'height' : 'width';
904
+ len = this.dom["scroll-" + n].getBoundingClientRect()[dim];
905
+ if (!(len > 0) || !(info.extent > 0)) {
906
+ return null;
907
+ }
908
+ size = (ref$ = (ref1$ = len * (info.vis / info.extent)) > 20 ? ref1$ : 20) < len ? ref$ : len;
909
+ return {
910
+ dim: dim,
911
+ len: len,
912
+ size: size,
913
+ span: len - size
914
+ };
915
+ },
916
+ _scrollDrag: function(n, evt){
917
+ var ref$, t, cl, info, m, ref1$, base, start, hm, hu, this$ = this;
918
+ ref$ = n === 'y'
919
+ ? ['row', 'clientY']
920
+ : ['col', 'clientX'], t = ref$[0], cl = ref$[1];
921
+ info = this._scrollInfo(t);
922
+ if (!(m = this._scrollMetric(n, info))) {
923
+ return;
924
+ }
925
+ if (m.span <= 0 || info.max <= 0) {
926
+ return;
927
+ }
928
+ ref$ = [evt[cl], (ref$ = this.pos[t]) < (ref1$ = info.max) ? ref$ : ref1$], base = ref$[0], start = ref$[1];
929
+ hm = function(e){
930
+ return this$._scrollTo(t, start + ((e[cl] - base) / m.span) * info.max, info);
931
+ };
932
+ hu = function(e){
933
+ this$._scrolling = false;
934
+ this$.dom["scroll-" + n].classList.remove('active');
935
+ document.removeEventListener('mousemove', hm);
936
+ return document.removeEventListener('mouseup', hu);
937
+ };
938
+ this._scrolling = true;
939
+ this.dom["scroll-" + n].classList.add('active');
940
+ document.addEventListener('mousemove', hm);
941
+ return document.addEventListener('mouseup', hu);
942
+ },
943
+ renderScrollbar: function(){
944
+ var this$ = this;
945
+ if (!this.scrollbar) {
946
+ return;
947
+ }
948
+ return [['row', 'y', 'top'], ['col', 'x', 'left']].map(function(arg$){
949
+ var t, n, side, ref$, track, thumb, info, m;
950
+ t = arg$[0], n = arg$[1], side = arg$[2];
951
+ ref$ = [this$.dom["scroll-" + n], this$.dom["thumb-" + n]], track = ref$[0], thumb = ref$[1];
952
+ info = this$._scrollInfo(t);
953
+ if (!(m = this$._scrollMetric(n, info))) {
954
+ track.classList.add('idle');
955
+ return;
956
+ }
957
+ track.classList.toggle('idle', info.max <= 0);
958
+ thumb.style[m.dim] = m.size + "px";
959
+ return thumb.style[side] = (info.max <= 0
960
+ ? 0
961
+ : m.span * ((ref$ = this$.pos[t] / info.max) < 1 ? ref$ : 1)) + "px";
962
+ });
963
+ },
785
964
  addCell: function(x, y){
786
965
  var div;
787
966
  div = document.createElement('div');
@@ -903,7 +1082,7 @@
903
1082
  return n.appendChild(content.node);
904
1083
  }
905
1084
  } else {
906
- if (!sheet._d3warning && !isNaN(parseFloat(content))) {
1085
+ if (this._ccfg && !sheet._d3warning && !isNaN(parseFloat(content))) {
907
1086
  fc = this._ccfg({
908
1087
  type: 'format',
909
1088
  col: (fr
@@ -956,10 +1135,11 @@
956
1135
  inner.appendChild(n);
957
1136
  }
958
1137
  }
959
- return this.pos.row += mag;
1138
+ this.pos.row += mag;
1139
+ return this.renderScrollbar();
960
1140
  },
961
1141
  _mu: function(mag){
962
- var inner, start, ref$, i$, j, j$, to$, i, lresult$, n, results$ = [];
1142
+ var inner, start, ref$, i$, j, j$, to$, i, n;
963
1143
  mag == null && (mag = 1);
964
1144
  inner = this.dom.inner;
965
1145
  if (this.pos.row <= 0) {
@@ -983,7 +1163,6 @@
983
1163
  this.pos.row -= mag;
984
1164
  for (i$ = start; i$ < mag; ++i$) {
985
1165
  j = i$;
986
- lresult$ = [];
987
1166
  for (j$ = 0, to$ = this.dim.col; j$ < to$; ++j$) {
988
1167
  i = j$;
989
1168
  n = document.createElement('div');
@@ -992,11 +1171,10 @@
992
1171
  y: j + this.xif.row[2],
993
1172
  n: n
994
1173
  });
995
- lresult$.push(inner.insertBefore(n, inner.childNodes[i + (j - start) * this.dim.col + this.dim.col * this.xif.row[2]]));
1174
+ inner.insertBefore(n, inner.childNodes[i + (j - start) * this.dim.col + this.dim.col * this.xif.row[2]]);
996
1175
  }
997
- results$.push(lresult$);
998
1176
  }
999
- return results$;
1177
+ return this.renderScrollbar();
1000
1178
  },
1001
1179
  _mr: function(mag){
1002
1180
  var inner, start, ref$, i$, j, j$, to$, i, n;
@@ -1019,7 +1197,8 @@
1019
1197
  }
1020
1198
  }
1021
1199
  this.pos.col += mag;
1022
- return this.regrid();
1200
+ this.regrid();
1201
+ return this.renderScrollbar();
1023
1202
  },
1024
1203
  _ml: function(mag){
1025
1204
  var inner, start, ref$, i$, j, j$, to$, i, n;
@@ -1048,7 +1227,8 @@
1048
1227
  inner.insertBefore(n, inner.childNodes[i * this.dim.col + this.xif.col[2] + j - start]);
1049
1228
  }
1050
1229
  }
1051
- return this.regrid();
1230
+ this.regrid();
1231
+ return this.renderScrollbar();
1052
1232
  },
1053
1233
  goto: function(opt){
1054
1234
  opt == null && (opt = {
@@ -1056,6 +1236,7 @@
1056
1236
  col: 0
1057
1237
  });
1058
1238
  import$(this.pos, opt);
1239
+ this.regrid();
1059
1240
  return this.render();
1060
1241
  },
1061
1242
  render: function(){
@@ -1070,7 +1251,8 @@
1070
1251
  });
1071
1252
  }
1072
1253
  }
1073
- return this.renderSelection();
1254
+ this.renderSelection();
1255
+ return this.renderScrollbar();
1074
1256
  },
1075
1257
  move: function(opt){
1076
1258
  var node, idx, box, sbox, ref$, ns;
package/index.min.css CHANGED
@@ -1 +1 @@
1
- .sheet{position:relative;width:100%;height:100%;overflow:hidden;overscroll-behavior:contain;outline:0}.sheet .inner{z-index:1;display:grid;width:100%;height:100%;overflow:hidden}.sheet .cell{position:relative;user-select:none;border-width:0 1px 1px 0;border-style:solid;border-color:#ddd;padding:1px 3px;min-width:48px;line-height:26px;box-sizing:border-box;white-space:pre;overflow:hidden}.sheet .cell.idx{z-index:100;background:#f1f2f3;color:#919293;font-size:.85em;text-align:center;user-select:none}.sheet .cell.fixed,.sheet .cell.fixed.frozen{z-index:13}.sheet .cell.fixed{background:#fafbfc;white-space:initial;padding:0}.sheet .cell.frozen{z-index:12;background:#fdfeff}.sheet .cell.fixed.frozen{padding:1px 3px}.sheet .range,.sheet .range-cut{z-index:14;border:1px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .range-cut{border-style:dashed}.sheet .caret{z-index:15;border:2px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .edit{z-index:121;border:2px solid #27f;pointer-events:none;opacity:0;width:0;height:0;top:0;left:0;position:absolute}.sheet .edit textarea{display:block;border:0;outline:0}.sheet .layout{display:inline-block;top:0;left:0;position:absolute;z-index:0;opacity:0;pointer-events:none;user-select:none;white-space:pre}.sheet .show{opacity:1 !important;display:block}.sheet .edit.show{pointer-events:auto;width:initial;height:initial;opacity:initial}.sheet .slide-y,.sheet .slide-x{display:flex;align-items:center;justify-content:space-between;position:absolute;z-index:1;background:#fff;color:rgba(0,0,0,0.5);padding:.25em;border:1px solid #bbb;border-radius:.25em}.sheet .slide-y:before,.sheet .slide-x:before,.sheet .slide-y:after,.sheet .slide-x:after{display:block;line-height:1em}.sheet .slide-y{flex-direction:column;width:1em;height:3em;right:0;transform:translate(0,-50%);bottom:50%;cursor:ns-resize}.sheet .slide-y:before{content:"↑"}.sheet .slide-y:after{content:"↓"}.sheet .slide-x{width:3em;height:1em;bottom:0;left:50%;transform:translate(-50%,0);cursor:ew-resize}.sheet .slide-x:before{content:"←"}.sheet .slide-x:after{content:"→"}
1
+ .sheet{position:relative;width:100%;height:100%;overflow:hidden;overscroll-behavior:contain;outline:0}.sheet .inner{z-index:1;display:grid;width:100%;height:100%;overflow:hidden}.sheet .cell{position:relative;user-select:none;border-width:0 1px 1px 0;border-style:solid;border-color:#ddd;padding:1px 3px;min-width:48px;line-height:26px;box-sizing:border-box;white-space:pre;overflow:hidden}.sheet .cell.idx{z-index:100;background:#f1f2f3;color:#919293;font-size:.85em;text-align:center;user-select:none}.sheet .cell.fixed,.sheet .cell.fixed.frozen{z-index:13}.sheet .cell.fixed{background:#fafbfc;white-space:initial;padding:0}.sheet .cell.frozen{z-index:12;background:#fdfeff}.sheet .cell.fixed.frozen{padding:1px 3px}.sheet .range,.sheet .range-cut{z-index:14;border:1px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .range-cut{border-style:dashed}.sheet .caret{z-index:15;border:2px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .edit{z-index:121;border:2px solid #27f;pointer-events:none;opacity:0;width:0;height:0;top:0;left:0;position:absolute}.sheet .edit textarea{display:block;border:0;outline:0}.sheet .layout{display:inline-block;top:0;left:0;position:absolute;z-index:0;opacity:0;pointer-events:none;user-select:none;white-space:pre}.sheet .show{opacity:1 !important;display:block}.sheet .edit.show{pointer-events:auto;width:initial;height:initial;opacity:initial}.sheet .scroll-y,.sheet .scroll-x{position:absolute;z-index:130;background:rgba(0,0,0,0.04)}.sheet .scroll-y.idle,.sheet .scroll-x.idle{opacity:0;pointer-events:none}.sheet .scroll-y .thumb,.sheet .scroll-x .thumb{position:absolute;top:0;left:0;border-radius:4px;background:rgba(0,0,0,0.32);transition:background .1s ease}.sheet .scroll-y:hover .thumb,.sheet .scroll-x:hover .thumb,.sheet .scroll-y.active .thumb,.sheet .scroll-x.active .thumb{background:rgba(0,0,0,0.52)}.sheet .scroll-y{top:0;right:0;bottom:10px;width:10px;cursor:default}.sheet .scroll-y .thumb{width:100%}.sheet .scroll-x{left:0;right:10px;bottom:0;height:10px;cursor:default}.sheet .scroll-x .thumb{height:100%}.sheet.has-scrollbar .slide-y{right:12px}.sheet.has-scrollbar .slide-x{bottom:12px}.sheet .slide-y,.sheet .slide-x{display:flex;align-items:center;justify-content:space-between;position:absolute;z-index:1;background:#fff;color:rgba(0,0,0,0.5);padding:.25em;border:1px solid #bbb;border-radius:.25em}.sheet .slide-y:before,.sheet .slide-x:before,.sheet .slide-y:after,.sheet .slide-x:after{display:block;line-height:1em}.sheet .slide-y{flex-direction:column;width:1em;height:3em;right:0;transform:translate(0,-50%);bottom:50%;cursor:ns-resize}.sheet .slide-y:before{content:"↑"}.sheet .slide-y:after{content:"↓"}.sheet .slide-x{width:3em;height:1em;bottom:0;left:50%;transform:translate(-50%,0);cursor:ew-resize}.sheet .slide-x:before{content:"←"}.sheet .slide-x:after{content:"→"}
package/index.min.js CHANGED
@@ -1 +1 @@
1
- !function(){var f,m,h,c;function o(t,e){var i,o={}.hasOwnProperty;for(i in e)o.call(e,i)&&(t[i]=e[i]);return t}f=function(t){return"undefined"!=typeof Papa&&null!==Papa?Papa.parse(t).data:[[t]]},m=function(t,e,i){for(var o=t;t&&t!==i;)t=t.parentNode;if(t!==i)return null;if(!e)return t;for(t=o;t&&t!==i&&(!t.matches||t.matches&&!t.matches(e));)t=t.parentNode;return t!==i||i.matches&&i.matches(e)?t:null},h=function(t){for(var e=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,i=t-((Math.pow(26,1+e)-1)/25-1),o="",s=0;s<=e;++s)o="ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i%26)+o,i=(i-i%26)/26;return o},(c=function(t){var e,i=this;return this.opt=t=null==t?{}:t,this.root="string"==typeof t.root?document.querySelector(t.root):t.root,this.evtHandler={},this._ccfg=t.cellcfg,this._data=t.data||[],this._size={row:(e=o({row:[],col:[]},t.size)).row,col:e.col},this.cls={row:(e=o({row:[],col:[]},t.class)).row,col:e.col},this._editing=null==t.editing||!!t.editing,this.dim={col:(t.dim||(t.dim={})).col||30,row:(t.dim||(t.dim={})).row||30},this.frozen={col:(e=o({col:0,row:0},t.frozen||{})).col,row:e.row},this.idx={col:(e=o({row:!0,col:!0},t.idx||{})).col,row:e.row},this.fixed={col:(e=o({col:0,row:0},t.fixed||{})).col,row:e.row},this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]},["row","col"].map(function(t){return i.xif[t][1]=i.xif[t][0]+i.fixed[t],i.xif[t][2]=i.xif[t][1]+i.frozen[t]}),this.fix={row:this.xif.row[2],col:this.xif.col[2]},this.pos={col:0,row:0},this.scrollPos={x:0,y:0},this.sel={cut:{}},this.les={},this.editing={},this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout","range-cut","slide-y","slide-x"].map(function(t){var e;e=document.createElement("div");return e.classList.add(t),[t,e]})),this.dom.sheet.setAttribute("tabindex",-1),this.dom.textarea=document.createElement("textarea"),this.root.appendChild(this.dom.sheet),["inner","caret","range","edit","layout","range-cut","slide-y","slide-x"].map(function(t){return i.dom.sheet.appendChild(i.dom[t])}),this.opt.slider||(this.dom["slide-x"].style.display=this.dom["slide-y"].style.display="none"),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=o(Object.create(Object.prototype),{on:function(t,e){var i;return((i=this.evtHandler)[t]||(i[t]=[])).push(e)},fire:function(t){for(var e,i,o,s,r=[],n=[],l=1,h=arguments.length;l<h;++l)n.push(arguments[l]);for(e=n,l=0,o=(i=this.evtHandler[t]||[]).length;l<o;++l)s=i[l],r.push(s.apply(this,e));return r},_init:function(){for(var t,e,i,o,d,s,a,r,n,l,u=this,h=0,c=this.dim.row;h<c;++h)for(t=h,e=0,i=this.dim.col;e<i;++e)o=e,this.addCell(o,t);return this.regrid(),this.dom.textarea.addEventListener("mousedown",function(t){return t.stopPropagation()}),this.dom.sheet.addEventListener("contextmenu",function(t){if(u.fire("menu.on",{evt:t,node:t.target}),!u._menuOff)return u._menuOff=function(t){if("keydown"!==t.type||27===t.keyCode)return document.body.removeEventListener("click",u._menuOff),document.body.removeEventListener("keydown",u._menuOff),u._menuOff=null,u.fire("menu.off",{evt:t,node:t.target})},document.body.addEventListener("click",u._menuOff),document.body.addEventListener("keydown",u._menuOff)}),(d=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(!(1<t.button)&&(u.dom.textarea.focus(),u.edited(),e=m(t.target,".cell",d))){if(!((o={row:(i=u.index(e)).row,col:i.col}).col<0||o.row<0))return t.shiftKey&&u.les.start?u.les.end=o:(u.les.start=u.les.end=o,u.les.node=e),u.renderSelection();u.les.node=u.cell(u.les.start),t.shiftKey&&u.les.start||(u.les.start={col:0<(i=o.col)?i:0,row:0<(i=o.row)?i:0},u.les.node=u.cell(u.les.start)),u.les.end={col:0<=o.col?o.col:void 0,row:0<=o.row?o.row:void 0},u.renderSelection()}}),d.addEventListener("mousemove",function(t){var e;if(!u._slider.y.on&&!u._slider.x.on&&!u.editing.on&&t.buttons&&(e=m(t.target,".cell",d)))return e={row:(t=u.index(e)).row,col:t.col},u.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},u.renderSelection()}),d.addEventListener("dblclick",function(t){if(t=m(t.target,".cell",d))return u.edit({node:t,quick:!1})}),s=new DOMParser,a=function(t){return s.parseFromString(t,"text/html")},document.body.addEventListener("paste",function(t){var e,i,o,s,r,n,l,h,c;if(m(document.activeElement,".sheet",d)&&u.les.start&&(s=function(t,e){var i=-1,o=e.length>>>0;for(;++i<o;)if(t===e[i])return 1;return}("text/html",t.clipboardData.types||[])?(s=a(t.clipboardData.getData("text/html")),Array.from(s.querySelectorAll("tr")).map(function(t){return Array.from(t.querySelectorAll("th,td")).map(function(t){return t.textContent})})):(e=t.clipboardData.getData("text"),f(e)),u.set({row:u.les.start.row,col:u.les.start.col,data:s,range:!0,src:"user"}),u.sel.cut)){if(u._toText({sel:u.sel.cut})===e){for(i=(t=u._bound({sel:u.sel.cut})).sc,o=t.ec,s=t.sr,r=t.er,n=s;n<=r;++n)for(l=n,h=i;h<=o;++h)c=h,u.set({row:l,col:c,data:"",src:"user"});navigator.clipboard.writeText("")}return u.sel.cut=null,u.dom["range-cut"].classList.toggle("show",!1)}}),this.dom.textarea.addEventListener("keypress",function(t){var e;return(31!==(e=t.keyCode)&&61!==e&&67!==e&&88!==e||!t.metaKey&&!t.ctrlKey)&&u.les.node&&!u.editing.on&&(u.edit({node:u.les.node,quick:13!==t.keyCode}),13===t.keyCode)?t.preventDefault():void 0}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o,s,r,n,l,h,c,d,a=t.keyCode;if(86!==t.keyCode||!t.metaKey&&!t.ctrlKey){if(!u.editing.on){if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return u.copy();if(88===t.keyCode&&(t.metaKey||t.ctrlKey))return u.copy({cut:!0})}if(u.eventInScope(t)){if(8===a){if(!u.les.node)return;for(i=(e=u._bound()).sc,o=e.ec,d=e.sr,s=e.er,r=[],n=d;n<=s;++n){for(l=[],h=i;h<=o;++h)l.push("");r.push(l)}c=r,u.set({row:d,col:i,data:c,range:!0,src:"user"})}if(189===a&&(t.metaKey||t.ctrlKey)&&u.slice(),187===a&&(t.metaKey||t.ctrlKey)&&u.insert(),d=function(){switch(a){case 37:return{y:0,x:-1};case 38:return{y:-1,x:0};case 39:return{y:0,x:1};case 40:return{y:1,x:0};case 9:return{y:0,x:1};default:return null}}()){if(u.editing.on&&!u.editing.quick)return;u.move((d.select=t.shiftKey,d)),t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}if(u.les.node&&!u.editing.on)return 37!==(e=t.keyCode)&&38!==e&&39!==e&&40!==e&&9!==e&&16!==e&&18!==e&&91!==e&&27!==e&&17!==e&&(31!==(e=t.keyCode)&&61!==e&&67!==e&&88!==e||!t.metaKey&&!t.ctrlKey)?(u.edit({node:u.les.node,quick:13!==t.keyCode}),void(13===t.keyCode&&t.preventDefault())):void 0;if(u.editing.on){if(27===t.keyCode)u.edited({cancel:!0});else{if(13!==t.keyCode||t.altKey||t.metaKey)return 13===t.keyCode&&(t.altKey||t.metaKey)?(u.dom.textarea.value+="\n",u.dom.layout.textContent=u.dom.textarea.value+" ",c=u.dom.layout.getBoundingClientRect(),d=u.editing.node.getBoundingClientRect(),(e=u.dom.textarea.style).width=Math.max(c.width,d.width+1)+"px",e.height=Math.max(c.height,d.height+1)+"px",e):void 0;u.move({y:1,x:0})}t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}}}}),(r=this)._slider={hc:function(t){var e=t.target.getBoundingClientRect(),e=e[this.t[3]]+e[this.t[4]]/2,t=this.dir*Math.sign(t[this.t[2]]-e);return r[t<0?this.t[1]:this.t[0]](1),r.renderSelection()},hd:function(t){var e=this;return this.on=!0,this.p=t[this.t[2]],document.addEventListener("mouseup",function(t){return e.hu(t)}),document.addEventListener("mousemove",function(t){return e.hm(t)})},hu:function(t){return this.on=!1,document.removeEventListener("mouseup",this.hu),document.removeEventListener("mousemove",this.hm)},hm:function(t){var e;if(this.on)return t=this.p-t[this.t[2]],(e=500<(e=Math.abs(t))?10:300<e?5:150<e?2:100<e?1:.3)<1&&(e=Math.random()<e?1:0),0<(t=Math.sign(t)*this.dir*e)&&r[this.t[1]](t),t<0&&r[this.t[0]](t),r.renderSelection()}},this._slider.y=((n={n:"slide-y",on:!1,p:0,t:["_mu","_md","clientY","y","height"],dir:-1}).hd=(l=this._slider).hd,n.hu=l.hu,n.hm=l.hm,n.hc=l.hc,n),this._slider.x=((l={n:"slide-x",on:!1,p:0,t:["_mr","_ml","clientX","x","width"],dir:1}).hd=(n=this._slider).hd,l.hu=n.hu,l.hm=n.hm,l.hc=n.hc,l),["x","y"].map(function(e){return u.dom[u._slider[e].n].addEventListener("mousedown",function(t){return u._slider[e].hd(t)}),u.dom[u._slider[e].n].addEventListener("click",function(t){return u._slider[e].hc(t)})}),document.addEventListener("wheel",function(t){var e,i,o,s,r=u.eventInScope(t);if(null==u.opt.enableScrolling||u.opt.enableScrolling)return(null==u.opt.scrollLock||u.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!r&&t.target!==document.body||t.preventDefault()),!!r&&(r=u.scrollPos,e=(s=[t.deltaX,t.deltaY])[0],i=s[1],e=(s=Math.abs(e)>Math.abs(i)?[e,0]:[0,i])[0],i=s[1],o=(s=[r.x,r.y])[0],s=s[1],r.x+=e/30,r.y+=i/30,e=Math.round(r.x)-Math.round(o),0<(i=Math.round(r.y)-Math.round(s))?u._md(i):i<0?u._mu(i):0<e?u._mr(e):e<0&&u._ml(e),u.renderSelection(),t.preventDefault())},{passive:!1})},select:function(t){var e,i;if(!arguments.length)return this.les.start?((e={}).col=this.les.start.col,e.row=this.les.start.row,this.les.end?(null==this.les.end.col?delete e.col:e.colspan=this.les.end.col-e.col+1,null==this.les.end.row?delete e.row:e.rowspan=this.les.end.row-e.row+1):(e.colspan=1,e.rowspan=1),e):null;this.les={},t&&(this.les={start:{col:0,row:0},end:{}},null!=t.row&&(this.les.start.row=t.row,this.les.end.row=t.row+((i=t.rowspan)&&1<i?i:1)-1),null!=t.col)&&(this.les.start.col=t.col,this.les.end.col=t.col+((i=t.colspan)&&1<i?i:1)-1),this.renderSelection()},_bound:function(t){var e,i,o,s,r=(e=[(e=(t=null==t?{}:t).sel||this.les).start,e.end])[1];return(s=e[0])&&r?(i=(e=s.col<r.col||null==r.col?[s.col,r.col]:[r.col,s.col])[0],o=e[1],r=(e=s.row<r.row||null==r.row?[s.row,r.row]:[r.row,s.row])[0],s=e[1],null!=t.defined&&!t.defined||(null==o&&(o=Math.max.apply(Math,this._data.map(function(t){return t.length}))),null!=s)||(s=this._data.length),{sc:i,ec:o,sr:r,er:s}):{sc:0,ec:0,sr:0,er:0}},_toText:function(t){var e,i,o,s,r,n,l,h,c,d,t=t.sel;if(!t||!t.start)return"";for(e=[],o=(i=this._bound({sel:t})).sc,s=i.ec,t=i.sr,r=i.er,n=t;n<=r;++n){for(l=n,h=[],c=o;c<=s;++c)d=c,"object"!=typeof(d=null==(d=((i=this._data)[l]||(i[l]=[]))[d])?"":d)&&h.push('"'+(""+d||"").replace(/"/g,'""')+'"');e.push(h.join("\t"))}return e.join("\n")},copy:function(t){var e;if(null==t&&(t={}),this.les.start)return e=this._toText({sel:this.les}),navigator.clipboard.writeText(e),t.cut?(this.sel.cut={start:this.les.start,end:this.les.end},this.renderSelection(this.sel.cut,{cut:!0})):void 0},eventInScope:function(t){return m(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(t){return null==t?this._size:(this._size={row:(t=o({row:[],col:[]},t)).row,col:t.col},this.regrid())},regrid:function(){var e=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.col[2],i=this.dim.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t+e.pos.col-e.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.row[2],i=this.dim.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t+e.pos.row-e.xif.row[1]]||"max-content"}).join(" ")},addCell:function(t,e){var i=document.createElement("div");return this.dom.inner.insertBefore(i,this.dom.inner.childNodes[e*this.dim.col+t]),this._content({x:t,y:e,n:i})},set:function(t){var e,i,o,s,r,n,l,h,c,d=t.row,a=t.col,u=t.data,f=t.range,m=t.src;if(f)for(e=!1,o=0,s=(u=JSON.parse(JSON.stringify(u))).length;o<s;++o)for(n=0,l=u[r=o].length;n<l;++n)h=n,m&&this._ccfg&&this._ccfg({row:d+r,col:a+h,type:"readonly"})?u[r][h]=((i=this._data)[c=r+d]||(i[c]=[]))[h+a]:(e=!0,((i=this._data)[c=r+d]||(i[c]=[]))[h+a]=u[r][h],this._content({y:r+d-this.pos.row+this.xif.row[1],x:h+a-this.pos.col+this.xif.col[1]}));else{if(m&&this._ccfg&&this._ccfg({row:d,col:a,type:"readonly"}))return;e=!0,((i=this._data)[d]||(i[d]=[]))[a]=u,this._content({y:d-this.pos.row+this.xif.row[1],x:a-this.pos.col+this.xif.col[1]})}if(e)return this.fire("change",{row:d,col:a,data:u,range:!!f})},_content:function(t){var e,i,o,s,r,n=t.x,l=t.y,t=t.n;if(t||(t=this.dom.inner.childNodes[n+l*this.dim.col]))return e=(r=n<this.xif.col[0]&&l<this.xif.col[0]?["","cell idx"]:n<this.xif.col[0]?[l<this.xif.row[1]?" ":l<this.xif.row[2]?l-this.xif.row[1]+1:l-this.xif.row[1]+this.pos.row+1,"cell idx"]:l<this.xif.row[0]?[n<this.xif.col[1]?" ":n<this.xif.col[2]?h(n-this.xif.col[1]):h(n-this.xif.col[1]+this.pos.col),"cell idx"]:n<this.xif.col[1]||l<this.xif.row[1]?[null,"cell fixed"]:n<this.xif.col[2]&&l<this.xif.row[2]?[((r=this._data)[e=l-this.xif.row[1]]||(r[e]=[]))[n-this.xif.col[1]],"cell frozen fixed"]:n<this.xif.col[2]?[((r=this._data)[e=this.pos.row+l-this.xif.row[1]]||(r[e]=[]))[n-this.xif.col[1]],"cell frozen"]:l<this.xif.row[2]?[((r=this._data)[e=l-this.xif.row[1]]||(r[e]=[]))[this.pos.col+n-this.xif.col[1]],"cell frozen"]:[((r=this._data)[e=this.pos.row+l-this.xif.row[1]]||(r[e]=[]))[this.pos.col+n-this.xif.col[1]],"cell"])[0],r=r[1],null==e&&(e=""),i=/frozen/.exec(r),o=n>=this.xif.col[0]&&l>=this.xif.row[0]?(this.cls.col[(i?0:this.pos.col)+n-this.xif.col[1]]||"")+" "+(this.cls.row[(i?0:this.pos.row)+l-this.xif.row[1]]||""):"",s=this._ccfg&&this._ccfg({type:"class",col:(i?0:this.pos.col)+n-this.xif.col[1],row:(i?0:this.pos.row)+l-this.xif.row[1]})||"",t.className=[r,o,s].filter(function(t){return t.trim()}).join(" ").trim(),null!==e?"object"!=typeof e?(c._d3warning||isNaN(parseFloat(e))||(r=this._ccfg({type:"format",col:(i?0:this.pos.col)+n-this.xif.col[1],row:(i?0:this.pos.row)+l-this.xif.row[1]}))&&("undefined"!=typeof d3&&null!==d3&&d3.format?e=d3.format(r)(e):(console.warn("[@plotdb/sheet] cell format provided yet d3.format not available. skip formatting."),c._d3warning=!0)),t.textContent=e):"dom"===e.type?(t.textContent="",t.appendChild(e.node)):void 0:void 0},_md:function(t){var e,i,o,s,r,n,l,h,c;for(null==t&&(t=1),e=this.dom.inner,o=i=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))?i:0;o<t;++o)for(s=o,r=0,n=this.dim.col;r<n&&(l=r,h=this.dim.col*this.fix.row,e.childNodes[h]);++r)e.removeChild(e.childNodes[h]);for(o=i;o<t;++o)for(s=o,r=0,n=this.dim.col;r<n;++r)l=r,c=document.createElement("div"),this._content({x:l,y:this.dim.row+s,n:c}),e.appendChild(c);return this.pos.row+=t},_mu:function(t){var e,i,o,s,r,n,l,h,c,d,a=[];if(null==t&&(t=1),e=this.dom.inner,!(this.pos.row<=0)){for(s=i=0<(o=(t=(t=Math.round(Math.abs(t)))>=this.pos.row?this.pos.row:t)-(this.dim.row-this.xif.row[2]))?o:0;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l&&(h=n,e.childNodes.length);++n)e.removeChild(e.childNodes[e.childNodes.length-1]);for(this.pos.row-=t,s=i;s<t;++s){for(r=s,c=[],n=0,l=this.dim.col;n<l;++n)h=n,d=document.createElement("div"),this._content({x:h,y:r+this.xif.row[2],n:d}),c.push(e.insertBefore(d,e.childNodes[h+(r-i)*this.dim.col+this.dim.col*this.xif.row[2]]));a.push(c)}return a}},_mr:function(t){var e,i,o,s,r,n,l,h;for(null==t&&(t=1),e=this.dom.inner,o=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))?i:0;o<t;++o)for(s=o,r=0,n=this.dim.row;r<n;++r)l=r,e.removeChild(e.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+s,y:l,n:h}),e.insertBefore(h,e.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid()},_ml:function(t){var e,i,o,s,r,n,l,h,c;if(null==t&&(t=1),e=this.dom.inner,(t=Math.round(Math.abs(t)))>=this.pos.col&&(t=this.pos.col),!(this.pos.col<=0||t<=0)){for(i=0<(o=t-(this.dim.col-this.xif.col[2]))?o:0,this.pos.col-=t,s=i;s<t;++s)for(r=s,n=0,l=this.dim.row;n<l;++n)h=n,e.removeChild(e.childNodes[(h+1)*this.dim.col-1]),c=document.createElement("div"),this._content({x:r+this.xif.col[2],y:h,n:c}),e.insertBefore(c,e.childNodes[h*this.dim.col+this.xif.col[2]+r-i]);return this.regrid()}},goto:function(t){return o(this.pos,t=null==t?{row:0,col:0}:t),this.render()},render:function(){for(var t,e,i,o,s=0,r=this.dim.row;s<r;++s)for(t=s,e=0,i=this.dim.col;e<i;++e)o=e,this._content({x:o,y:t});return this.renderSelection()},move:function(t){var e,i,o,s,r;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(e=this.cell(t))){if(i=this.index(e),r=e.getBoundingClientRect(),o=this.dom.sheet.getBoundingClientRect(),r.x+r.width>o.x+o.width&&this._mr(1),r.y+r.height>o.y+o.height&&this._md(1),i.x<=this.frozen.col)if(0<this.pos.col)this._ml(1);else if(i.x<=0)return;if(i.y<=this.frozen.row)if(0<this.pos.row)this._mu(1);else if(i.y<=0)return;if((e=this.cell(t))||(e=this.cell({col:i.col,row:i.row})))return this.les.node=e,t.select?(r={col:(s=this.index(e)).col,row:s.row},this.les.end===this.les.start&&(this.les.end=JSON.parse(JSON.stringify(this.les.start))),r.col<this.les.start.col&&(r.col<this.les.end.col||null==this.les.end.col)&&((this.les.start.col>this.les.end.col?this.les.end:this.les.start).col=r.col),r.row<this.les.start.row&&(r.row<this.les.end.row||null==this.les.end.row)&&((this.les.start.row>this.les.end.row?this.les.end:this.les.start).row=r.row),r.col>this.les.start.col&&r.col>this.les.end.col&&((this.les.start.col<this.les.end.col?this.les.end:this.les.start).col=r.col),r.row>this.les.start.row&&r.row>this.les.end.row&&((this.les.start.row<this.les.end.row?this.les.end:this.les.start).row=r.row)):this.les.start=this.les.end={col:(s=this.index(e)).col,row:s.row},this.renderSelection()}},edit:function(t){var e,i,o,s,r,n,l=t.node,t=t.quick;if(this._editing&&!(!(e=this.index(l))||e.col<0||e.row<0||this._ccfg&&this._ccfg({row:e.row,col:e.col,type:"readonly"})))return(e=this.editing).node=l,e.quick=t,e.on=!0,this.dom.layout.textContent=l.textContent,i=this.dom.layout.getBoundingClientRect(),o=l.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),n=(e=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],r=e[1],(e=this.dom.edit.style).left=o.x-s.x+n-2+"px",e.top=o.y-s.y+r-2+"px",e.width="fit-content",e.height="fit-content",this.dom.edit.classList.toggle("show",!0),(e=this.dom.textarea.style).width=Math.max(i.width,o.width+1)+"px",e.height=Math.max(i.height,o.height+1)+"px",this.dom.textarea.value=n=!t&&l.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(n.length,n.length)},edited:function(t){if(null==t&&(t={}),this.editing.on)return t.cancel||this.set({row:this.les.start.row,col:this.les.start.col,data:this.dom.textarea.value||""}),this.dom.edit.classList.toggle("show",!1),(t=this.editing).node=null,t.on=!1,t},index:function(t){var e,t=Array.from(this.dom.inner.childNodes).indexOf(t);return t<0?null:{x:e=t%this.dim.col,y:t=(t-e)/this.dim.col,col:e<this.xif.col[1]?-1:e<this.xif.col[2]?e-this.xif.col[1]:e-this.xif.col[1]+this.pos.col,row:t<this.xif.row[1]?-1:t<this.xif.row[2]?t-this.xif.row[1]:t-this.xif.row[1]+this.pos.row}},cell:function(t){var e,i,o=(t=null==t?{}:t).roughly;if(null!=t.col||null!=t.row){if(t.col<this.frozen.col)e=t.col;else if(t.col-this.pos.col<this.frozen.col){if(!o)return null;e=this.frozen.col}else e=t.col-this.pos.col;if(t.row<this.frozen.row)i=t.row;else if(t.row-this.pos.row<this.frozen.row){if(!o)return null;i=this.frozen.row}else i=t.row-this.pos.row;return i=(o=[e+this.xif.col[1],i+this.xif.row[1]])[1],(e=o[0])<0||i<0||e>=this.dim.col||i>=this.dim.row?null:this.dom.inner.childNodes[i*this.dim.col+e]}if(o=t.node?this.index(t.node):{y:0,x:0})return i=o.y+(t.y||0),e=o.x+(t.x||0),this.dom.inner.childNodes[i*this.dim.col+e]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(t,e){var i,o,s,r,n,l,h,c,d,a,u,f,m,w=this;if(null==e&&(e={}),(t=t||this.les).start)return n=(i=this._bound({defined:!1,sel:t})).sc,o=i.ec,h=i.sr,s=i.er,r=this.dom.inner.getBoundingClientRect(),m=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:n,row:h,roughly:!0}),this.cell({col:n,row:s,roughly:!0}),this.cell({col:o,row:h,roughly:!0}),this.cell({col:o,row:s,roughly:!0}),this.cell({col:this.pos.col+this.dim.col-2,row:this.pos.row+this.dim.row-2})].map(function(t){return t?t.getBoundingClientRect():null}))[0],l=i[1],a=i[2],d=i[3],u=i[4],f=i[5],m.width=0,m.height=0,n=(l||a||(n>this.pos.col?f:m)).x-r.x,l=(l||d||(h>this.pos.row?f:m)).y-r.y,h=o-this.pos.col<0,c=s-this.pos.row<0,d=(d||u||f||m).x+(h?0:(d||u||f||m).width)-r.x-n+1,a=(a||u||f||m).y+(c?0:(a||u||f||m).height)-r.y-l+1,null==o&&(d=this.root.getBoundingClientRect().width),null==s&&(a=this.root.getBoundingClientRect().height),f=(u=this.les.node)?u.getBoundingClientRect():null,(i=(m=e.cut?this.dom["range-cut"]:this.dom.range).style).left=n+"px",i.top=l+"px",i.width=d+"px",i.height=a+"px",m.classList.toggle("show",!0),e.cut||(f&&((i=this.dom.caret.style).left=f.x-r.x-1+"px",i.top=f.y-r.y-1+"px",i.width=(h?0:f.width)+2+"px",i.height=(c?0:f.height)+2+"px",i.zIndex=t.start.row+this.xif.row[1]<this.xif.row[2]&&t.start.col+this.xif.col[1]<this.xif.col[2]?101:t.start.row+this.xif.row[1]<this.xif.row[2]||t.start.col+this.xif.col[1]<this.xif.col[2]?20:15),this.dom.caret.classList.toggle("show",!!f)),this.dom.textarea===document.activeElement?setTimeout(function(){return w.dom.textarea.focus({preventScroll:!0})},0):void 0;this.dom.caret.classList.toggle("show",!1),this.dom.range.classList.toggle("show",!1)},data:function(t){return null==t?this._data:(this._data=t,this.render())},sort:function(i){var o,t,s=this;return null==i&&(i={}),t=this._bound({defined:!1}),o=t.sc,t.ec,t.sr,t.er,(t=this._data.map(function(t,e){return{d:t,i:e}})).sort(function(t,e){return t.i<s.frozen.row&&e.i>=s.frozen.row?-1:e.i<s.frozen.row&&t.i>=s.frozen.row?1:(t=isNaN(+t.d[o])?t.d[o]:+t.d[o],e=isNaN(+e.d[o])?e.d[o]:+e.d[o],("asc"===i.dir?1:-1)*(e<t?1:t<e?-1:0))}),this._data=t.map(function(t){return t.d}),this.fire("change",{row:0,col:0,data:this._data,range:!0}),this.renderSelection(),this.render()},insert:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,0,[])),null==e&&(t=this._data.map(function(t){return t.splice(i,0,"")})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()},slice:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,e-s+1)),null==e&&(t=this._data.map(function(t){return t.splice(i,o-i+1)})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()}}),"undefined"!=typeof module&&null!==module?module.exports=c:"undefined"!=typeof window&&null!==window&&(window.sheet=c)}.call(this);
1
+ !function(){var f,m,h,c;function o(t,e){var i,o={}.hasOwnProperty;for(i in e)o.call(e,i)&&(t[i]=e[i]);return t}f=function(t){return"undefined"!=typeof Papa&&null!==Papa?Papa.parse(t).data:[[t]]},m=function(t,e,i){for(var o=t;t&&t!==i;)t=t.parentNode;if(t!==i)return null;if(!e)return t;for(t=o;t&&t!==i&&(!t.matches||t.matches&&!t.matches(e));)t=t.parentNode;return t!==i||i.matches&&i.matches(e)?t:null},h=function(t){for(var e=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,i=t-((Math.pow(26,1+e)-1)/25-1),o="",s=0;s<=e;++s)o="ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i%26)+o,i=(i-i%26)/26;return o},(c=function(t){var e,i=this;return this.opt=t=null==t?{}:t,this.root="string"==typeof t.root?document.querySelector(t.root):t.root,this.evtHandler={},this._ccfg="function"==typeof t.cellcfg?t.cellcfg:null,this._data=t.data||[],this._size={row:(e=o({row:[],col:[]},t.size)).row,col:e.col},this.cls={row:(e=o({row:[],col:[]},t.class)).row,col:e.col},this._editing=null==t.editing||!!t.editing,this.dim={col:(t.dim||(t.dim={})).col||30,row:(t.dim||(t.dim={})).row||30},this.frozen={col:(e=o({col:0,row:0},t.frozen||{})).col,row:e.row},this.idx={col:(e=o({row:!0,col:!0},t.idx||{})).col,row:e.row},this.fixed={col:(e=o({col:0,row:0},t.fixed||{})).col,row:e.row},this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]},["row","col"].map(function(t){return i.xif[t][1]=i.xif[t][0]+i.fixed[t],i.xif[t][2]=i.xif[t][1]+i.frozen[t]}),this.fix={row:this.xif.row[2],col:this.xif.col[2]},this.pos={col:0,row:0},this.scrollPos={x:0,y:0},this.sel={cut:{}},this.les={},this.editing={},this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout","range-cut","slide-y","slide-x","scroll-y","scroll-x"].map(function(t){var e;e=document.createElement("div");return e.classList.add(t),[t,e]})),this.dom.sheet.setAttribute("tabindex",-1),this.dom.textarea=document.createElement("textarea"),this.root.appendChild(this.dom.sheet),["inner","caret","range","edit","layout","range-cut","slide-y","slide-x","scroll-y","scroll-x"].map(function(t){return i.dom.sheet.appendChild(i.dom[t])}),this.opt.slider||(this.dom["slide-x"].style.display=this.dom["slide-y"].style.display="none"),this.scrollbar=!!this.opt.scrollbar,["x","y"].map(function(t){var e;e=document.createElement("div");if(e.classList.add("thumb"),i.dom["scroll-"+t].appendChild(e),i.dom["thumb-"+t]=e,!i.scrollbar)return i.dom["scroll-"+t].style.display="none"}),this.scrollbar&&this.dom.sheet.classList.add("has-scrollbar"),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=o(Object.create(Object.prototype),{on:function(t,e){var i;return((i=this.evtHandler)[t]||(i[t]=[])).push(e)},fire:function(t){for(var e,i,o,s,r=[],n=[],l=1,h=arguments.length;l<h;++l)n.push(arguments[l]);for(e=n,l=0,o=(i=this.evtHandler[t]||[]).length;l<o;++l)s=i[l],r.push(s.apply(this,e));return r},_init:function(){for(var t,e,i,o,d,s,a,r,n,l,u=this,h=0,c=this.dim.row;h<c;++h)for(t=h,e=0,i=this.dim.col;e<i;++e)o=e,this.addCell(o,t);return this.regrid(),this.dom.textarea.addEventListener("mousedown",function(t){return t.stopPropagation()}),this.dom.sheet.addEventListener("contextmenu",function(t){if(u.fire("menu.on",{evt:t,node:t.target}),!u._menuOff)return u._menuOff=function(t){if("keydown"!==t.type||27===t.keyCode)return document.body.removeEventListener("click",u._menuOff),document.body.removeEventListener("keydown",u._menuOff),u._menuOff=null,u.fire("menu.off",{evt:t,node:t.target})},document.body.addEventListener("click",u._menuOff),document.body.addEventListener("keydown",u._menuOff)}),(d=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(!(1<t.button)&&(u.dom.textarea.focus(),u.edited(),e=m(t.target,".cell",d))){if(!((o={row:(i=u.index(e)).row,col:i.col}).col<0||o.row<0))return t.shiftKey&&u.les.start?u.les.end=o:(u.les.start=u.les.end=o,u.les.node=e),u.renderSelection();u.les.node=u.cell(u.les.start),t.shiftKey&&u.les.start||(u.les.start={col:0<(i=o.col)?i:0,row:0<(i=o.row)?i:0},u.les.node=u.cell(u.les.start)),u.les.end={col:0<=o.col?o.col:void 0,row:0<=o.row?o.row:void 0},u.renderSelection()}}),d.addEventListener("mousemove",function(t){var e;if(!(u._slider.y.on||u._slider.x.on||u._scrolling)&&!u.editing.on&&t.buttons&&(e=m(t.target,".cell",d)))return e={row:(t=u.index(e)).row,col:t.col},u.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},u.renderSelection()}),d.addEventListener("dblclick",function(t){if(t=m(t.target,".cell",d))return u.edit({node:t,quick:!1})}),s=new DOMParser,a=function(t){return s.parseFromString(t,"text/html")},document.body.addEventListener("paste",function(t){var e,i,o,s,r,n,l,h,c;if(m(document.activeElement,".sheet",d)&&u.les.start&&(s=function(t,e){var i=-1,o=e.length>>>0;for(;++i<o;)if(t===e[i])return 1;return}("text/html",t.clipboardData.types||[])?(s=a(t.clipboardData.getData("text/html")),Array.from(s.querySelectorAll("tr")).map(function(t){return Array.from(t.querySelectorAll("th,td")).map(function(t){return t.textContent})})):(e=t.clipboardData.getData("text"),f(e)),u.set({row:u.les.start.row,col:u.les.start.col,data:s,range:!0,src:"user"}),u.sel.cut)){if(u._toText({sel:u.sel.cut})===e){for(i=(t=u._bound({sel:u.sel.cut})).sc,o=t.ec,s=t.sr,r=t.er,n=s;n<=r;++n)for(l=n,h=i;h<=o;++h)c=h,u.set({row:l,col:c,data:"",src:"user"});navigator.clipboard.writeText("")}return u.sel.cut=null,u.dom["range-cut"].classList.toggle("show",!1)}}),this.dom.textarea.addEventListener("keypress",function(t){var e;return(31!==(e=t.keyCode)&&61!==e&&67!==e&&88!==e||!t.metaKey&&!t.ctrlKey)&&u.les.node&&!u.editing.on&&(u.edit({node:u.les.node,quick:13!==t.keyCode}),13===t.keyCode)?t.preventDefault():void 0}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o,s,r,n,l,h,c,d,a=t.keyCode;if(86!==t.keyCode||!t.metaKey&&!t.ctrlKey){if(!u.editing.on){if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return u.copy();if(88===t.keyCode&&(t.metaKey||t.ctrlKey))return u.copy({cut:!0})}if(u.eventInScope(t)){if(8===a){if(!u.les.node)return;for(i=(e=u._bound()).sc,o=e.ec,d=e.sr,s=e.er,r=[],n=d;n<=s;++n){for(l=[],h=i;h<=o;++h)l.push("");r.push(l)}c=r,u.set({row:d,col:i,data:c,range:!0,src:"user"}),u.render()}if(189===a&&(t.metaKey||t.ctrlKey)&&u.slice(),187===a&&(t.metaKey||t.ctrlKey)&&u.insert(),d=function(){switch(a){case 37:return{y:0,x:-1};case 38:return{y:-1,x:0};case 39:return{y:0,x:1};case 40:return{y:1,x:0};case 9:return{y:0,x:1};default:return null}}()){if(u.editing.on&&!u.editing.quick)return;u.move((d.select=t.shiftKey,d)),t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}if(u.les.node&&!u.editing.on)return 37!==(e=t.keyCode)&&38!==e&&39!==e&&40!==e&&9!==e&&16!==e&&18!==e&&91!==e&&27!==e&&17!==e&&(31!==(e=t.keyCode)&&61!==e&&67!==e&&88!==e||!t.metaKey&&!t.ctrlKey)?(u.edit({node:u.les.node,quick:13!==t.keyCode}),void(13===t.keyCode&&t.preventDefault())):void 0;if(u.editing.on){if(27===t.keyCode)u.edited({cancel:!0});else{if(13!==t.keyCode||t.altKey||t.metaKey)return 13===t.keyCode&&(t.altKey||t.metaKey)?(u.dom.textarea.value+="\n",u.dom.layout.textContent=u.dom.textarea.value+" ",c=u.dom.layout.getBoundingClientRect(),d=u.editing.node.getBoundingClientRect(),(e=u.dom.textarea.style).width=Math.max(c.width,d.width+1)+"px",e.height=Math.max(c.height,d.height+1)+"px",e):void 0;u.move({y:1,x:0})}t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}}}}),(r=this)._slider={hc:function(t){var e=t.target.getBoundingClientRect(),e=e[this.t[3]]+e[this.t[4]]/2,t=this.dir*Math.sign(t[this.t[2]]-e);return r[t<0?this.t[1]:this.t[0]](1),r.renderSelection()},hd:function(t){var e=this;return this.on=!0,this.p=t[this.t[2]],document.addEventListener("mouseup",function(t){return e.hu(t)}),document.addEventListener("mousemove",function(t){return e.hm(t)})},hu:function(t){return this.on=!1,document.removeEventListener("mouseup",this.hu),document.removeEventListener("mousemove",this.hm)},hm:function(t){var e;if(this.on)return t=this.p-t[this.t[2]],(e=500<(e=Math.abs(t))?10:300<e?5:150<e?2:100<e?1:.3)<1&&(e=Math.random()<e?1:0),0<(t=Math.sign(t)*this.dir*e)&&r[this.t[1]](t),t<0&&r[this.t[0]](t),r.renderSelection()}},this._slider.y=((n={n:"slide-y",on:!1,p:0,t:["_mu","_md","clientY","y","height"],dir:-1}).hd=(l=this._slider).hd,n.hu=l.hu,n.hm=l.hm,n.hc=l.hc,n),this._slider.x=((l={n:"slide-x",on:!1,p:0,t:["_mr","_ml","clientX","x","width"],dir:1}).hd=(n=this._slider).hd,l.hu=n.hu,l.hm=n.hm,l.hc=n.hc,l),["x","y"].map(function(e){return u.dom[u._slider[e].n].addEventListener("mousedown",function(t){return u._slider[e].hd(t)}),u.dom[u._slider[e].n].addEventListener("click",function(t){return u._slider[e].hc(t)})}),this.scrollbar&&(["x","y"].map(function(n){return u.dom["scroll-"+n].addEventListener("mousedown",function(t){var e,i,o,s,r;return t.preventDefault(),t.stopPropagation(),t.target===u.dom["thumb-"+n]?u._scrollDrag(n,t):(i=(e="y"===n?["row","clientY"]:["col","clientX"])[0],o=e[1],s=u.dom["thumb-"+n].getBoundingClientRect(),r=u._scrollInfo(i),t=t[o]<s["y"===n?"top":"left"]?-1:1,u._scrollTo(i,u.pos[i]+t*(1<(e=r.vis)?e:1),r))})}),null!=window.ResizeObserver)&&(this._ro=new ResizeObserver(function(){return u.renderScrollbar()}),this._ro.observe(this.dom.sheet)),document.addEventListener("wheel",function(t){var e,i,o,s,r=u.eventInScope(t);if(null==u.opt.enableScrolling||u.opt.enableScrolling)return(null==u.opt.scrollLock||u.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!r&&t.target!==document.body||t.preventDefault()),!!r&&(r=u.scrollPos,e=(s=[t.deltaX,t.deltaY])[0],i=s[1],t.shiftKey&&Math.abs(i)>Math.abs(e)&&(e=(s=[i,0])[0],i=s[1]),e=(s=Math.abs(e)>Math.abs(i)?[e,0]:[0,i])[0],i=s[1],o=(s=[r.x,r.y])[0],s=s[1],r.x+=e/30,r.y+=i/30,e=Math.round(r.x)-Math.round(o),0<(i=Math.round(r.y)-Math.round(s))?u._md(i):i<0?u._mu(i):0<e?u._mr(e):e<0&&u._ml(e),u.renderSelection(),t.preventDefault())},{passive:!1}),this.renderScrollbar()},select:function(t){var e,i;if(!arguments.length)return this.les.start?((e={}).col=this.les.start.col,e.row=this.les.start.row,this.les.end?(null==this.les.end.col?delete e.col:e.colspan=this.les.end.col-e.col+1,null==this.les.end.row?delete e.row:e.rowspan=this.les.end.row-e.row+1):(e.colspan=1,e.rowspan=1),e):null;this.les={},t&&(this.les={start:{col:0,row:0},end:{}},null!=t.row&&(this.les.start.row=t.row,this.les.end.row=t.row+((i=t.rowspan)&&1<i?i:1)-1),null!=t.col)&&(this.les.start.col=t.col,this.les.end.col=t.col+((i=t.colspan)&&1<i?i:1)-1),this.renderSelection()},_bound:function(t){var e,i,o,s,r=(e=[(e=(t=null==t?{}:t).sel||this.les).start,e.end])[1];return(s=e[0])&&r?(i=(e=s.col<r.col||null==r.col?[s.col,r.col]:[r.col,s.col])[0],o=e[1],r=(e=s.row<r.row||null==r.row?[s.row,r.row]:[r.row,s.row])[0],s=e[1],null!=t.defined&&!t.defined||(null==o&&(o=this._dataSize("col")),null!=s)||(s=this._dataSize("row")),{sc:i,ec:o,sr:r,er:s}):{sc:0,ec:0,sr:0,er:0}},_toText:function(t){var e,i,o,s,r,n,l,h,c,d,t=t.sel;if(!t||!t.start)return"";for(e=[],o=(i=this._bound({sel:t})).sc,s=i.ec,t=i.sr,r=i.er,n=t;n<=r;++n){for(l=n,h=[],c=o;c<=s;++c)d=c,"object"!=typeof(d=null==(d=((i=this._data)[l]||(i[l]=[]))[d])?"":d)&&h.push('"'+(""+d||"").replace(/"/g,'""')+'"');e.push(h.join("\t"))}return e.join("\n")},copy:function(t){var e;if(null==t&&(t={}),this.les.start)return e=this._toText({sel:this.les}),navigator.clipboard.writeText(e),t.cut?(this.sel.cut={start:this.les.start,end:this.les.end},this.renderSelection(this.sel.cut,{cut:!0})):void 0},eventInScope:function(t){return m(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(t){return null==t?this._size:(this._size={row:(t=o({row:[],col:[]},t)).row,col:t.col},this.regrid())},regrid:function(){var e=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.col[2],i=this.dim.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t+e.pos.col-e.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.row[2],i=this.dim.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t+e.pos.row-e.xif.row[1]]||"max-content"}).join(" ")},_viewport:function(){for(var t,e,i,o=this.dom.sheet.getBoundingClientRect(),s=this.dom.inner,r={row:0,col:0},n=this.xif.row[2],l=this.dim.row;n<l&&(t=n,e=s.childNodes[t*this.dim.col])&&!(e.getBoundingClientRect().top>=o.bottom);++n)r.row++;for(n=this.xif.col[2],l=this.dim.col;n<l&&(i=n,e=s.childNodes[i])&&!(e.getBoundingClientRect().left>=o.right);++n)r.col++;return r},_dataSize:function(t){var e,i,o,s,r,n;if("col"===t){for(i=e=0,s=(o=this._data).length;i<s;++i)(r=o[i])&&r.length>e&&(e=r.length);return e}for(n=this._data.length;0<n&&!(this._data[n-1]||[]).length;)n--;return n},_scrollInfo:function(t){var e=this._viewport()[t],t=this._dataSize(t);return{vis:e,total:t,extent:t+e,max:t}},_scrollTo:function(t,e,i){var o;if(null==i&&(i=this._scrollInfo(t)),(e=0<(o=(o=Math.round(e))<(i=i.max)?o:i)?o:0)!==this.pos[t])return this.goto("row"===t?{row:e}:{col:e})},_scrollMetric:function(t,e){var i="y"===t?"height":"width",t=this.dom["scroll-"+t].getBoundingClientRect()[i];return 0<t&&0<e.extent?{dim:i,len:t,size:i=(e=20<(i=t*(e.vis/e.extent))?i:20)<t?e:t,span:t-i}:null},_scrollDrag:function(e,t){var i,o,s,r,n,l=this,h="y"===e?["row","clientY"]:["col","clientX"],c=h[0],d=h[1],a=this._scrollInfo(c);if((i=this._scrollMetric(e,a))&&!(i.span<=0||a.max<=0))return h=[t[d],(h=this.pos[c])<(t=a.max)?h:t],o=h[0],s=h[1],r=function(t){return l._scrollTo(c,s+(t[d]-o)/i.span*a.max,a)},n=function(t){return l._scrolling=!1,l.dom["scroll-"+e].classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",n)},this._scrolling=!0,this.dom["scroll-"+e].classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",n)},renderScrollbar:function(){var l=this;if(this.scrollbar)return[["row","y","top"],["col","x","left"]].map(function(t){var e=t[0],i=t[1],t=t[2],o=[l.dom["scroll-"+i],l.dom["thumb-"+i]],s=o[0],r=o[1],n=l._scrollInfo(e);if(i=l._scrollMetric(i,n))return s.classList.toggle("idle",n.max<=0),r.style[i.dim]=i.size+"px",r.style[t]=(n.max<=0?0:i.span*((o=l.pos[e]/n.max)<1?o:1))+"px";s.classList.add("idle")})},addCell:function(t,e){var i=document.createElement("div");return this.dom.inner.insertBefore(i,this.dom.inner.childNodes[e*this.dim.col+t]),this._content({x:t,y:e,n:i})},set:function(t){var e,i,o,s,r,n,l,h,c,d=t.row,a=t.col,u=t.data,f=t.range,m=t.src;if(f)for(e=!1,o=0,s=(u=JSON.parse(JSON.stringify(u))).length;o<s;++o)for(n=0,l=u[r=o].length;n<l;++n)h=n,m&&this._ccfg&&this._ccfg({row:d+r,col:a+h,type:"readonly"})?u[r][h]=((i=this._data)[c=r+d]||(i[c]=[]))[h+a]:(e=!0,((i=this._data)[c=r+d]||(i[c]=[]))[h+a]=u[r][h],this._content({y:r+d-this.pos.row+this.xif.row[1],x:h+a-this.pos.col+this.xif.col[1]}));else{if(m&&this._ccfg&&this._ccfg({row:d,col:a,type:"readonly"}))return;e=!0,((i=this._data)[d]||(i[d]=[]))[a]=u,this._content({y:d-this.pos.row+this.xif.row[1],x:a-this.pos.col+this.xif.col[1]})}if(e)return this.fire("change",{row:d,col:a,data:u,range:!!f})},_content:function(t){var e,i,o,s,r,n=t.x,l=t.y,t=t.n;if(t||(t=this.dom.inner.childNodes[n+l*this.dim.col]))return e=(r=n<this.xif.col[0]&&l<this.xif.col[0]?["","cell idx"]:n<this.xif.col[0]?[l<this.xif.row[1]?" ":l<this.xif.row[2]?l-this.xif.row[1]+1:l-this.xif.row[1]+this.pos.row+1,"cell idx"]:l<this.xif.row[0]?[n<this.xif.col[1]?" ":n<this.xif.col[2]?h(n-this.xif.col[1]):h(n-this.xif.col[1]+this.pos.col),"cell idx"]:n<this.xif.col[1]||l<this.xif.row[1]?[null,"cell fixed"]:n<this.xif.col[2]&&l<this.xif.row[2]?[((r=this._data)[e=l-this.xif.row[1]]||(r[e]=[]))[n-this.xif.col[1]],"cell frozen fixed"]:n<this.xif.col[2]?[((r=this._data)[e=this.pos.row+l-this.xif.row[1]]||(r[e]=[]))[n-this.xif.col[1]],"cell frozen"]:l<this.xif.row[2]?[((r=this._data)[e=l-this.xif.row[1]]||(r[e]=[]))[this.pos.col+n-this.xif.col[1]],"cell frozen"]:[((r=this._data)[e=this.pos.row+l-this.xif.row[1]]||(r[e]=[]))[this.pos.col+n-this.xif.col[1]],"cell"])[0],r=r[1],null==e&&(e=""),i=/frozen/.exec(r),o=n>=this.xif.col[0]&&l>=this.xif.row[0]?(this.cls.col[(i?0:this.pos.col)+n-this.xif.col[1]]||"")+" "+(this.cls.row[(i?0:this.pos.row)+l-this.xif.row[1]]||""):"",s=this._ccfg&&this._ccfg({type:"class",col:(i?0:this.pos.col)+n-this.xif.col[1],row:(i?0:this.pos.row)+l-this.xif.row[1]})||"",t.className=[r,o,s].filter(function(t){return t.trim()}).join(" ").trim(),null!==e?"object"!=typeof e?(!this._ccfg||c._d3warning||isNaN(parseFloat(e))||(r=this._ccfg({type:"format",col:(i?0:this.pos.col)+n-this.xif.col[1],row:(i?0:this.pos.row)+l-this.xif.row[1]}))&&("undefined"!=typeof d3&&null!==d3&&d3.format?e=d3.format(r)(e):(console.warn("[@plotdb/sheet] cell format provided yet d3.format not available. skip formatting."),c._d3warning=!0)),t.textContent=e):"dom"===e.type?(t.textContent="",t.appendChild(e.node)):void 0:void 0},_md:function(t){var e,i,o,s,r,n,l,h,c;for(null==t&&(t=1),e=this.dom.inner,o=i=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))?i:0;o<t;++o)for(s=o,r=0,n=this.dim.col;r<n&&(l=r,h=this.dim.col*this.fix.row,e.childNodes[h]);++r)e.removeChild(e.childNodes[h]);for(o=i;o<t;++o)for(s=o,r=0,n=this.dim.col;r<n;++r)l=r,c=document.createElement("div"),this._content({x:l,y:this.dim.row+s,n:c}),e.appendChild(c);return this.pos.row+=t,this.renderScrollbar()},_mu:function(t){var e,i,o,s,r,n,l,h,c;if(null==t&&(t=1),e=this.dom.inner,!(this.pos.row<=0)){for(s=i=0<(o=(t=(t=Math.round(Math.abs(t)))>=this.pos.row?this.pos.row:t)-(this.dim.row-this.xif.row[2]))?o:0;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l&&(h=n,e.childNodes.length);++n)e.removeChild(e.childNodes[e.childNodes.length-1]);for(this.pos.row-=t,s=i;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l;++n)h=n,c=document.createElement("div"),this._content({x:h,y:r+this.xif.row[2],n:c}),e.insertBefore(c,e.childNodes[h+(r-i)*this.dim.col+this.dim.col*this.xif.row[2]]);return this.renderScrollbar()}},_mr:function(t){var e,i,o,s,r,n,l,h;for(null==t&&(t=1),e=this.dom.inner,o=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))?i:0;o<t;++o)for(s=o,r=0,n=this.dim.row;r<n;++r)l=r,e.removeChild(e.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+s,y:l,n:h}),e.insertBefore(h,e.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid(),this.renderScrollbar()},_ml:function(t){var e,i,o,s,r,n,l,h,c;if(null==t&&(t=1),e=this.dom.inner,(t=Math.round(Math.abs(t)))>=this.pos.col&&(t=this.pos.col),!(this.pos.col<=0||t<=0)){for(i=0<(o=t-(this.dim.col-this.xif.col[2]))?o:0,this.pos.col-=t,s=i;s<t;++s)for(r=s,n=0,l=this.dim.row;n<l;++n)h=n,e.removeChild(e.childNodes[(h+1)*this.dim.col-1]),c=document.createElement("div"),this._content({x:r+this.xif.col[2],y:h,n:c}),e.insertBefore(c,e.childNodes[h*this.dim.col+this.xif.col[2]+r-i]);return this.regrid(),this.renderScrollbar()}},goto:function(t){return o(this.pos,t=null==t?{row:0,col:0}:t),this.regrid(),this.render()},render:function(){for(var t,e,i,o,s=0,r=this.dim.row;s<r;++s)for(t=s,e=0,i=this.dim.col;e<i;++e)o=e,this._content({x:o,y:t});return this.renderSelection(),this.renderScrollbar()},move:function(t){var e,i,o,s,r;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(e=this.cell(t))){if(i=this.index(e),r=e.getBoundingClientRect(),o=this.dom.sheet.getBoundingClientRect(),r.x+r.width>o.x+o.width&&this._mr(1),r.y+r.height>o.y+o.height&&this._md(1),i.x<=this.frozen.col)if(0<this.pos.col)this._ml(1);else if(i.x<=0)return;if(i.y<=this.frozen.row)if(0<this.pos.row)this._mu(1);else if(i.y<=0)return;if((e=this.cell(t))||(e=this.cell({col:i.col,row:i.row})))return this.les.node=e,t.select?(r={col:(s=this.index(e)).col,row:s.row},this.les.end===this.les.start&&(this.les.end=JSON.parse(JSON.stringify(this.les.start))),r.col<this.les.start.col&&(r.col<this.les.end.col||null==this.les.end.col)&&((this.les.start.col>this.les.end.col?this.les.end:this.les.start).col=r.col),r.row<this.les.start.row&&(r.row<this.les.end.row||null==this.les.end.row)&&((this.les.start.row>this.les.end.row?this.les.end:this.les.start).row=r.row),r.col>this.les.start.col&&r.col>this.les.end.col&&((this.les.start.col<this.les.end.col?this.les.end:this.les.start).col=r.col),r.row>this.les.start.row&&r.row>this.les.end.row&&((this.les.start.row<this.les.end.row?this.les.end:this.les.start).row=r.row)):this.les.start=this.les.end={col:(s=this.index(e)).col,row:s.row},this.renderSelection()}},edit:function(t){var e,i,o,s,r,n,l=t.node,t=t.quick;if(this._editing&&!(!(e=this.index(l))||e.col<0||e.row<0||this._ccfg&&this._ccfg({row:e.row,col:e.col,type:"readonly"})))return(e=this.editing).node=l,e.quick=t,e.on=!0,this.dom.layout.textContent=l.textContent,i=this.dom.layout.getBoundingClientRect(),o=l.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),n=(e=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],r=e[1],(e=this.dom.edit.style).left=o.x-s.x+n-2+"px",e.top=o.y-s.y+r-2+"px",e.width="fit-content",e.height="fit-content",this.dom.edit.classList.toggle("show",!0),(e=this.dom.textarea.style).width=Math.max(i.width,o.width+1)+"px",e.height=Math.max(i.height,o.height+1)+"px",this.dom.textarea.value=n=!t&&l.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(n.length,n.length)},edited:function(t){if(null==t&&(t={}),this.editing.on)return t.cancel||this.set({row:this.les.start.row,col:this.les.start.col,data:this.dom.textarea.value||""}),this.dom.edit.classList.toggle("show",!1),(t=this.editing).node=null,t.on=!1,t},index:function(t){var e,t=Array.from(this.dom.inner.childNodes).indexOf(t);return t<0?null:{x:e=t%this.dim.col,y:t=(t-e)/this.dim.col,col:e<this.xif.col[1]?-1:e<this.xif.col[2]?e-this.xif.col[1]:e-this.xif.col[1]+this.pos.col,row:t<this.xif.row[1]?-1:t<this.xif.row[2]?t-this.xif.row[1]:t-this.xif.row[1]+this.pos.row}},cell:function(t){var e,i,o=(t=null==t?{}:t).roughly;if(null!=t.col||null!=t.row){if(t.col<this.frozen.col)e=t.col;else if(t.col-this.pos.col<this.frozen.col){if(!o)return null;e=this.frozen.col}else e=t.col-this.pos.col;if(t.row<this.frozen.row)i=t.row;else if(t.row-this.pos.row<this.frozen.row){if(!o)return null;i=this.frozen.row}else i=t.row-this.pos.row;return i=(o=[e+this.xif.col[1],i+this.xif.row[1]])[1],(e=o[0])<0||i<0||e>=this.dim.col||i>=this.dim.row?null:this.dom.inner.childNodes[i*this.dim.col+e]}if(o=t.node?this.index(t.node):{y:0,x:0})return i=o.y+(t.y||0),e=o.x+(t.x||0),this.dom.inner.childNodes[i*this.dim.col+e]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(t,e){var i,o,s,r,n,l,h,c,d,a,u,f,m,w=this;if(null==e&&(e={}),(t=t||this.les).start)return n=(i=this._bound({defined:!1,sel:t})).sc,o=i.ec,h=i.sr,s=i.er,r=this.dom.inner.getBoundingClientRect(),m=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:n,row:h,roughly:!0}),this.cell({col:n,row:s,roughly:!0}),this.cell({col:o,row:h,roughly:!0}),this.cell({col:o,row:s,roughly:!0}),this.cell({col:this.pos.col+this.dim.col-2,row:this.pos.row+this.dim.row-2})].map(function(t){return t?t.getBoundingClientRect():null}))[0],l=i[1],a=i[2],d=i[3],u=i[4],f=i[5],m.width=0,m.height=0,n=(l||a||(n>this.pos.col?f:m)).x-r.x,l=(l||d||(h>this.pos.row?f:m)).y-r.y,h=o-this.pos.col<0,c=s-this.pos.row<0,d=(d||u||f||m).x+(h?0:(d||u||f||m).width)-r.x-n+1,a=(a||u||f||m).y+(c?0:(a||u||f||m).height)-r.y-l+1,null==o&&(d=this.root.getBoundingClientRect().width),null==s&&(a=this.root.getBoundingClientRect().height),f=(u=this.les.node)?u.getBoundingClientRect():null,(i=(m=e.cut?this.dom["range-cut"]:this.dom.range).style).left=n+"px",i.top=l+"px",i.width=d+"px",i.height=a+"px",m.classList.toggle("show",!0),e.cut||(f&&((i=this.dom.caret.style).left=f.x-r.x-1+"px",i.top=f.y-r.y-1+"px",i.width=(h?0:f.width)+2+"px",i.height=(c?0:f.height)+2+"px",i.zIndex=t.start.row+this.xif.row[1]<this.xif.row[2]&&t.start.col+this.xif.col[1]<this.xif.col[2]?101:t.start.row+this.xif.row[1]<this.xif.row[2]||t.start.col+this.xif.col[1]<this.xif.col[2]?20:15),this.dom.caret.classList.toggle("show",!!f)),this.dom.textarea===document.activeElement?setTimeout(function(){return w.dom.textarea.focus({preventScroll:!0})},0):void 0;this.dom.caret.classList.toggle("show",!1),this.dom.range.classList.toggle("show",!1)},data:function(t){return null==t?this._data:(this._data=t,this.render())},sort:function(i){var o,t,s=this;return null==i&&(i={}),t=this._bound({defined:!1}),o=t.sc,t.ec,t.sr,t.er,(t=this._data.map(function(t,e){return{d:t,i:e}})).sort(function(t,e){return t.i<s.frozen.row&&e.i>=s.frozen.row?-1:e.i<s.frozen.row&&t.i>=s.frozen.row?1:(t=isNaN(+t.d[o])?t.d[o]:+t.d[o],e=isNaN(+e.d[o])?e.d[o]:+e.d[o],("asc"===i.dir?1:-1)*(e<t?1:t<e?-1:0))}),this._data=t.map(function(t){return t.d}),this.fire("change",{row:0,col:0,data:this._data,range:!0}),this.renderSelection(),this.render()},insert:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,0,[])),null==e&&(t=this._data.map(function(t){return t.splice(i,0,"")})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()},slice:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,e-s+1)),null==e&&(t=this._data.map(function(t){return t.splice(i,o-i+1)})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()}}),"undefined"!=typeof module&&null!==module?module.exports=c:"undefined"!=typeof window&&null!==window&&(window.sheet=c)}.call(this);
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.7.0","style":"index.min.css","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/sheet","repository":{"type":"git","url":"git+https://github.com/plotdb/sheet.git"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","deploy":"npx deploy web/static"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.12","@loadingio/debounce.js":"1.0.1","@loadingio/ldquery":"^3.0.6","@plotdb/csscope":"^5.0.3","@plotdb/datadom":"^0.2.0","@plotdb/json0":"^0.0.5","@plotdb/rescope":"^5.0.14","@zbryikt/template":"^2.3.46","body-parser":"^1.19.0","bootstrap":"^4.5.2","bootstrap.native":"^3.0.13","d3-format":"^3.1.0","dompurify":"^2.2.6","fedep":"^1.3.0","jsoneditor":"^9.1.1","ldcover":"^3.5.4","ldiconfont":"^0.2.8","ldview":"^1.5.0","livescript":"^1.6.0","papaparse":"^5.4.1","proxise":"^1.0.1","sharedb-wrapper":"^1.0.0","stylus":"^0.55.0","uglify-js":"^3.13.1","uglifycss":"^0.0.29"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","@loadingio/bootstrap.ext","bootstrap.native","@loadingio/ldquery","@loadingio/debounce.js","d3-format","dompurify","ldview","ldcover","jsoneditor","ldiconfont","proxise","papaparse","@plotdb/datadom","@plotdb/csscope","@plotdb/rescope","sharedb-wrapper","@plotdb/json0"]}}
1
+ {"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.7.2","style":"index.min.css","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/sheet","repository":{"type":"git","url":"git+https://github.com/plotdb/sheet.git"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","deploy":"npx deploy web/static"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.12","@loadingio/debounce.js":"1.0.1","@loadingio/ldquery":"^3.0.6","@plotdb/csscope":"^5.0.4","@plotdb/datadom":"^0.2.0","@plotdb/guides":"github:plotdb/guides#master","@plotdb/json0":"^0.0.5","@plotdb/rescope":"^5.0.17","@zbryikt/template":"^2.4.3","body-parser":"^1.19.0","bootstrap":"^4.6.1","bootstrap.native":"^3.0.13","d3-format":"^3.1.0","dompurify":"^3.4.10","fedep":"^1.7.6","jsoneditor":"^9.1.1","ldcover":"^3.6.0","ldiconfont":"^0.3.0","ldview":"^1.7.2","livescript":"^1.6.0","papaparse":"^5.4.1","proxise":"^1.0.1","sharedb-wrapper":"^1.0.0","stylus":"^0.55.0","uglify-js":"^3.13.1","uglifycss":"^0.0.29"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","@loadingio/bootstrap.ext","bootstrap.native","@loadingio/ldquery","@loadingio/debounce.js","d3-format","dompurify","ldview","ldcover","jsoneditor","ldiconfont","proxise","papaparse","@plotdb/datadom","@plotdb/csscope","@plotdb/rescope","sharedb-wrapper","@plotdb/json0"]}}