@plotdb/sheet 0.2.0 → 0.4.0

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,19 @@
1
1
  # Change Logs
2
2
 
3
+ ## v0.4.0
4
+
5
+ - support in-sheet cut / paste
6
+ - support row-wise / column-wise deletion by ctrl+`-`
7
+ - separate `_to-text` function from `copy`
8
+ - parameterize `render-selection` for possibly future features such as multiple selection
9
+
10
+
11
+ ## v0.3.0
12
+
13
+ - support shift-select a range
14
+ - support selection from idx cells
15
+ - support selection without boundary
16
+
3
17
 
4
18
  ## v0.2.0
5
19
 
package/README.md CHANGED
@@ -20,8 +20,8 @@ install:
20
20
 
21
21
  include:
22
22
 
23
- <script src="path-to/sheet.js"></script>
24
- <link rel="stylesheet" type="text/css" href="path-to/sheet.css"/>
23
+ <script src="path-to/sheet/index.min.js"></script>
24
+ <link rel="stylesheet" type="text/css" href="path-to/sheet/index.min.css"/>
25
25
  <div class="container"></div>
26
26
 
27
27
 
package/index.css CHANGED
@@ -52,7 +52,8 @@
52
52
  .sheet .cell.fixed.frozen {
53
53
  padding: 1px 3px;
54
54
  }
55
- .sheet .range {
55
+ .sheet .range,
56
+ .sheet .range-cut {
56
57
  z-index: 14;
57
58
  border: 1px solid #27f;
58
59
  user-select: none;
@@ -63,6 +64,9 @@
63
64
  left: 0;
64
65
  position: absolute;
65
66
  }
67
+ .sheet .range-cut {
68
+ border-style: dashed;
69
+ }
66
70
  .sheet .caret {
67
71
  z-index: 15;
68
72
  border: 2px solid #27f;
package/index.js CHANGED
@@ -124,10 +124,12 @@
124
124
  x: 0,
125
125
  y: 0
126
126
  };
127
- this.sel = {};
127
+ this.sel = {
128
+ cut: {}
129
+ };
128
130
  this.les = {};
129
131
  this.editing = {};
130
- this.dom = Object.fromEntries(['sheet', 'inner', 'caret', 'range', 'edit', 'layout'].map(function(it){
132
+ this.dom = Object.fromEntries(['sheet', 'inner', 'caret', 'range', 'edit', 'layout', 'range-cut'].map(function(it){
131
133
  var x$, n;
132
134
  x$ = n = document.createElement('div');
133
135
  x$.classList.add(it);
@@ -136,7 +138,7 @@
136
138
  this.dom.sheet.setAttribute('tabindex', -1);
137
139
  this.dom.textarea = document.createElement('textarea');
138
140
  this.root.appendChild(this.dom.sheet);
139
- ['inner', 'caret', 'range', 'edit', 'layout'].map(function(it){
141
+ ['inner', 'caret', 'range', 'edit', 'layout', 'range-cut'].map(function(it){
140
142
  return this$.dom.sheet.appendChild(this$.dom[it]);
141
143
  });
142
144
  this.dom.edit.appendChild(this.dom.textarea);
@@ -186,21 +188,41 @@
186
188
  col: ref$.col
187
189
  };
188
190
  if (idx.col < 0 || idx.row < 0) {
191
+ if (!(e.shiftKey && this$.les.start)) {
192
+ this$.les.node = this$.cell(this$.les.start);
193
+ this$.les.start = {
194
+ col: (ref$ = idx.col) > 0 ? ref$ : 0,
195
+ row: (ref$ = idx.row) > 0 ? ref$ : 0
196
+ };
197
+ }
198
+ this$.les.end = {
199
+ col: idx.col >= 0 ? idx.col : undefined,
200
+ row: idx.row >= 0 ? idx.row : undefined
201
+ };
202
+ this$.renderSelection();
189
203
  return;
190
204
  }
191
- this$.les.start = this$.les.end = idx;
192
- this$.les.node = p;
205
+ if (e.shiftKey && this$.les.start) {
206
+ this$.les.end = idx;
207
+ } else {
208
+ this$.les.start = this$.les.end = idx;
209
+ this$.les.node = p;
210
+ }
193
211
  return this$.renderSelection();
194
212
  });
195
213
  dom.addEventListener('mousemove', function(e){
196
- var p, ref$;
214
+ var p, ref$, idx;
197
215
  if (this$.editing.on || !(e.buttons && (p = parent(e.target, '.cell', dom)))) {
198
216
  return;
199
217
  }
200
- this$.les.end = {
218
+ idx = {
201
219
  row: (ref$ = this$.index(p)).row,
202
220
  col: ref$.col
203
221
  };
222
+ this$.les.end = {
223
+ col: idx.col >= 0 ? idx.col : undefined,
224
+ row: idx.row >= 0 ? idx.row : undefined
225
+ };
204
226
  return this$.renderSelection();
205
227
  });
206
228
  dom.addEventListener('dblclick', function(e){
@@ -214,45 +236,68 @@
214
236
  });
215
237
  });
216
238
  document.body.addEventListener('paste', function(e){
217
- var data;
239
+ var raw, data, s, ref$, sc, ec, sr, er, i$, row, j$, col;
218
240
  if (!parent(document.activeElement, '.sheet', dom)) {
219
241
  return;
220
242
  }
221
243
  if (!this$.les.start) {
222
244
  return;
223
245
  }
224
- data = e.clipboardData.getData('text');
225
- data = parseCsv(data);
226
- return this$.set({
246
+ raw = e.clipboardData.getData('text');
247
+ data = parseCsv(raw);
248
+ this$.set({
227
249
  row: this$.les.start.row,
228
250
  col: this$.les.start.col,
229
251
  data: data,
230
252
  range: true
231
253
  });
254
+ if (this$.sel.cut) {
255
+ s = this$._toText({
256
+ sel: this$.sel.cut
257
+ });
258
+ if (s === raw) {
259
+ ref$ = this$._bound({
260
+ sel: this$.sel.cut
261
+ }), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
262
+ for (i$ = sr; i$ <= er; ++i$) {
263
+ row = i$;
264
+ for (j$ = sc; j$ <= ec; ++j$) {
265
+ col = j$;
266
+ this$.set({
267
+ row: row,
268
+ col: col,
269
+ data: ""
270
+ });
271
+ }
272
+ }
273
+ navigator.clipboard.writeText('');
274
+ }
275
+ this$.sel.cut = null;
276
+ return this$.dom["range-cut"].classList.toggle('show', false);
277
+ }
232
278
  });
233
279
  dom.addEventListener('keydown', function(e){
234
- var code, ref$, p1, p2, c1, c2, r1, r2, i$, row, j$, col, opt;
280
+ var code, ref$, sc, ec, sr, er, i$, row, j$, col, opt;
281
+ code = e.keyCode;
235
282
  if (e.keyCode === 67 && (e.metaKey || e.ctrlKey)) {
236
283
  return this$.copy();
237
284
  }
285
+ if (e.keyCode === 88 && (e.metaKey || e.ctrlKey)) {
286
+ return this$.copy({
287
+ cut: true
288
+ });
289
+ }
238
290
  if (!this$.eventInScope(e)) {
239
291
  return;
240
292
  }
241
- code = e.keyCode;
242
293
  if (code === 8) {
243
294
  if (!this$.les.node) {
244
295
  return;
245
296
  }
246
- ref$ = [this$.les.start, this$.les.end], p1 = ref$[0], p2 = ref$[1];
247
- ref$ = p1.col < p2.col
248
- ? [p1.col, p2.col]
249
- : [p2.col, p1.col], c1 = ref$[0], c2 = ref$[1];
250
- ref$ = p1.row < p2.row
251
- ? [p1.row, p2.row]
252
- : [p2.row, p1.row], r1 = ref$[0], r2 = ref$[1];
253
- for (i$ = r1; i$ <= r2; ++i$) {
297
+ ref$ = this$._bound(), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
298
+ for (i$ = sr; i$ <= er; ++i$) {
254
299
  row = i$;
255
- for (j$ = c1; j$ <= c2; ++j$) {
300
+ for (j$ = sc; j$ <= ec; ++j$) {
256
301
  col = j$;
257
302
  this$.set({
258
303
  row: row,
@@ -262,6 +307,26 @@
262
307
  }
263
308
  }
264
309
  }
310
+ if (code === 189 && (e.metaKey || e.ctrlKey)) {
311
+ if (!this$.les.node) {
312
+ return;
313
+ }
314
+ ref$ = this$._bound({
315
+ defined: false
316
+ }), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
317
+ if (ec == null) {
318
+ this$._data.splice(sr, er - sr + 1);
319
+ }
320
+ if (er == null) {
321
+ this$._data.map(function(it){
322
+ return it.splice(sc, ec - sc + 1);
323
+ });
324
+ }
325
+ this$.les.end = this$.les.start;
326
+ this$.renderSelection();
327
+ this$.render();
328
+ return;
329
+ }
265
330
  opt = (function(){
266
331
  switch (code) {
267
332
  case 37:
@@ -300,6 +365,9 @@
300
365
  return this$.dom.sheet.focus();
301
366
  });
302
367
  dom.addEventListener('keypress', function(e){
368
+ if (e.keyCode === 31 && (e.metaKey || e.ctrlKey)) {
369
+ return;
370
+ }
303
371
  if (this$.les.node && !this$.editing.on) {
304
372
  return this$.edit({
305
373
  node: this$.les.node,
@@ -374,18 +442,52 @@
374
442
  passive: false
375
443
  });
376
444
  },
377
- copy: function(){
378
- var c, i$, to$, row, r, j$, to1$, col, content, ref$, s;
379
- if (!this.les.start) {
380
- return;
445
+ _bound: function(o){
446
+ var sel, ref$, p1, p2, sc, ec, sr, er;
447
+ o == null && (o = {});
448
+ sel = o.sel || this.les;
449
+ ref$ = [sel.start, sel.end], p1 = ref$[0], p2 = ref$[1];
450
+ ref$ = p1.col < p2.col || p2.col == null
451
+ ? [p1.col, p2.col]
452
+ : [p2.col, p1.col], sc = ref$[0], ec = ref$[1];
453
+ ref$ = p1.row < p2.row || p2.row == null
454
+ ? [p1.row, p2.row]
455
+ : [p2.row, p1.row], sr = ref$[0], er = ref$[1];
456
+ if (o.defined == null || o.defined) {
457
+ if (ec == null) {
458
+ ec = Math.max.apply(Math, this._data.map(function(it){
459
+ return it.length;
460
+ }));
461
+ }
462
+ if (er == null) {
463
+ er = this._data.length;
464
+ }
465
+ }
466
+ return {
467
+ sc: sc,
468
+ ec: ec,
469
+ sr: sr,
470
+ er: er
471
+ };
472
+ },
473
+ _toText: function(arg$){
474
+ var sel, c, ref$, sc, ec, sr, er, i$, row, r, j$, col, content, s;
475
+ sel = arg$.sel;
476
+ if (!(sel && sel.start)) {
477
+ return '';
381
478
  }
382
479
  c = [];
383
- for (i$ = this.les.start.row, to$ = this.les.end.row + 1; i$ < to$; ++i$) {
480
+ ref$ = this._bound({
481
+ sel: sel
482
+ }), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
483
+ for (i$ = sr; i$ <= er; ++i$) {
384
484
  row = i$;
385
485
  r = [];
386
- for (j$ = this.les.start.col, to1$ = this.les.end.col + 1; j$ < to1$; ++j$) {
486
+ for (j$ = sc; j$ <= ec; ++j$) {
387
487
  col = j$;
388
- content = ((ref$ = this._data)[rpw] || (ref$[rpw] = []))[col];
488
+ if ((content = ((ref$ = this._data)[row] || (ref$[row] = []))[col]) == null) {
489
+ content = '';
490
+ }
389
491
  if (typeof content === 'object') {
390
492
  continue;
391
493
  }
@@ -394,7 +496,27 @@
394
496
  c.push(r.join('\t'));
395
497
  }
396
498
  s = c.join('\n');
397
- return navigator.clipboard.writeText(s);
499
+ return s;
500
+ },
501
+ copy: function(o){
502
+ var s;
503
+ o == null && (o = {});
504
+ if (!this.les.start) {
505
+ return;
506
+ }
507
+ s = this._toText({
508
+ sel: this.les
509
+ });
510
+ navigator.clipboard.writeText(s);
511
+ if (o.cut) {
512
+ this.sel.cut = {
513
+ start: this.les.start,
514
+ end: this.les.end
515
+ };
516
+ return this.renderSelection(this.sel.cut, {
517
+ cut: true
518
+ });
519
+ }
398
520
  },
399
521
  eventInScope: function(e){
400
522
  return parent(e.target, '.sheet', this.dom.sheet) === this.dom.sheet;
@@ -851,17 +973,19 @@
851
973
  ? this._editing
852
974
  : this._editing = !!v;
853
975
  },
854
- renderSelection: function(){
855
- var ref$, sc, ec, sr, er, rbox, c0, c1, c2, c3, c4, b0, b1, b2, b3, b4, x1, y1, x2, y2, w, h, snode, sbox;
856
- if (!this.les.start) {
976
+ renderSelection: function(sel, o){
977
+ var ref$, sc, ec, sr, er, rbox, c0, c1, c2, c3, c4, b0, b1, b2, b3, b4, x1, y1, x2, y2, w, h, snode, sbox, dom;
978
+ o == null && (o = {});
979
+ if (!sel) {
980
+ sel = this.les;
981
+ }
982
+ if (!sel.start) {
857
983
  return;
858
984
  }
859
- ref$ = this.les.start.col < this.les.end.col
860
- ? [this.les.start.col, this.les.end.col]
861
- : [this.les.end.col, this.les.start.col], sc = ref$[0], ec = ref$[1];
862
- ref$ = this.les.start.row < this.les.end.row
863
- ? [this.les.start.row, this.les.end.row]
864
- : [this.les.end.row, this.les.start.row], sr = ref$[0], er = ref$[1];
985
+ ref$ = this._bound({
986
+ defined: false,
987
+ sel: sel
988
+ }), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
865
989
  rbox = this.dom.inner.getBoundingClientRect();
866
990
  c0 = this.cell({
867
991
  col: this.pos.col + this.frozen.col,
@@ -898,27 +1022,38 @@
898
1022
  y2 = (b2 || b4 || b0).y + (b2 || b4 || b0).height - rbox.y;
899
1023
  w = x2 - x1 + 1;
900
1024
  h = y2 - y1 + 1;
901
- snode = this.cell(this.les.start);
1025
+ if (ec == null) {
1026
+ w = this.root.getBoundingClientRect().width;
1027
+ }
1028
+ if (er == null) {
1029
+ h = this.root.getBoundingClientRect().height;
1030
+ }
1031
+ snode = this.cell(sel.start);
902
1032
  sbox = !snode
903
1033
  ? null
904
1034
  : snode.getBoundingClientRect();
905
- ref$ = this.dom.range.style;
1035
+ dom = o.cut
1036
+ ? this.dom["range-cut"]
1037
+ : this.dom.range;
1038
+ ref$ = dom.style;
906
1039
  ref$.left = x1 + "px";
907
1040
  ref$.top = y1 + "px";
908
1041
  ref$.width = w + "px";
909
1042
  ref$.height = h + "px";
910
- this.dom.range.classList.toggle('show', true);
911
- if (sbox) {
912
- ref$ = this.dom.caret.style;
913
- ref$.left = (sbox.x - rbox.x - 1) + "px";
914
- ref$.top = (sbox.y - rbox.y - 1) + "px";
915
- ref$.width = (sbox.width + 2) + "px";
916
- ref$.height = (sbox.height + 2) + "px";
917
- ref$.zIndex = this.les.start.row + this.xif.row[1] < this.xif.row[2] && this.les.start.col + this.xif.col[1] < this.xif.col[2]
918
- ? 101
919
- : this.les.start.row + this.xif.row[1] < this.xif.row[2] || this.les.start.col + this.xif.col[1] < this.xif.col[2] ? 20 : 15;
920
- }
921
- return this.dom.caret.classList.toggle('show', !!sbox);
1043
+ dom.classList.toggle('show', true);
1044
+ if (!o.cut) {
1045
+ if (sbox) {
1046
+ ref$ = this.dom.caret.style;
1047
+ ref$.left = (sbox.x - rbox.x - 1) + "px";
1048
+ ref$.top = (sbox.y - rbox.y - 1) + "px";
1049
+ ref$.width = (sbox.width + 2) + "px";
1050
+ ref$.height = (sbox.height + 2) + "px";
1051
+ ref$.zIndex = sel.start.row + this.xif.row[1] < this.xif.row[2] && sel.start.col + this.xif.col[1] < this.xif.col[2]
1052
+ ? 101
1053
+ : sel.start.row + this.xif.row[1] < this.xif.row[2] || sel.start.col + this.xif.col[1] < this.xif.col[2] ? 20 : 15;
1054
+ }
1055
+ return this.dom.caret.classList.toggle('show', !!sbox);
1056
+ }
922
1057
  },
923
1058
  data: function(it){
924
1059
  if (!(it != null)) {
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{z-index:14;border:1px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.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;opacity:0;display:none;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}
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;opacity:0;display:none;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}
package/index.min.js CHANGED
@@ -1 +1 @@
1
- (function(){function t(t,i){var e={}.hasOwnProperty;for(var o in i)e.call(i,o)&&(t[o]=i[o]);return t}var i,e,o,s;i=function(t){return Papa.parse(t).data},e=function(t,i,e){var o;for(o=t;t&&t!==e;)t=t.parentNode;if(t!==e)return null;if(!i)return t;for(t=o;t&&t!==e&&(!t.matches||t.matches&&!t.matches(i));)t=t.parentNode;return t!==e||e.matches&&e.matches(i)?t:null},o=function(t){var i,e,o,s,r;for(i=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,e=t-((Math.pow(26,i+1)-1)/25-1),o="ABCDEFGHIJKLMNOPQRSTUVWXYZ",s="",r=0;r<=i;++r)r,s=o.charAt(e%26)+s,e=(e-e%26)/26;return s},(s=function(i){var e,o=this;return null==i&&(i={}),this.opt=i,this.root="string"==typeof i.root?document.querySelector(i.root):i.root,this.evtHandler={},this._data=i.data||[],this._size={row:(e=t({row:[],col:[]},i.size)).row,col:e.col},this.cls={row:(e=t({row:[],col:[]},i.class)).row,col:e.col},this._editing=null==i.editing||!!i.editing,this.dim={col:(i.dim||(i.dim={})).col||30,row:(i.dim||(i.dim={})).row||30},this.frozen={col:(e=t({col:0,row:0},i.frozen||{})).col,row:e.row},this.idx={col:(e=t({row:!0,col:!0},i.idx||{})).col,row:e.row},this.fixed={col:(e=t({col:0,row:0},i.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 o.xif[t][1]=o.xif[t][0]+o.fixed[t],o.xif[t][2]=o.xif[t][1]+o.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={},this.les={},this.editing={},this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout"].map(function(t){var i;return(i=document.createElement("div")).classList.add(t),[t,i]})),this.dom.sheet.setAttribute("tabindex",-1),this.dom.textarea=document.createElement("textarea"),this.root.appendChild(this.dom.sheet),["inner","caret","range","edit","layout"].map(function(t){return o.dom.sheet.appendChild(o.dom[t])}),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=t(Object.create(Object.prototype),{on:function(t,i){var e;return((e=this.evtHandler)[t]||(e[t]=[])).push(i)},fire:function(t){var i,e,o,s,r,n,l,h=[];for(e=[],o=1,s=arguments.length;o<s;++o)e.push(arguments[o]);for(i=e,o=0,n=(r=this.evtHandler[t]||[]).length;o<n;++o)l=r[o],h.push(l.apply(this,i));return h},_init:function(){var t,o,s,r,n,l,h,d=this;for(t=0,o=this.dim.row;t<o;++t)for(s=t,r=0,n=this.dim.col;r<n;++r)l=r,this.addCell(l,s);return this.regrid(),this.dom.textarea.addEventListener("mousedown",function(t){return t.stopPropagation()}),(h=this.dom.sheet).addEventListener("mousedown",function(t){var i,o,s;if(d.edited(),(i=e(t.target,".cell",h))&&!((s={row:(o=d.index(i)).row,col:o.col}).col<0||s.row<0))return d.les.start=d.les.end=s,d.les.node=i,d.renderSelection()}),h.addEventListener("mousemove",function(t){var i,o;if(!d.editing.on&&t.buttons&&(i=e(t.target,".cell",h)))return d.les.end={row:(o=d.index(i)).row,col:o.col},d.renderSelection()}),h.addEventListener("dblclick",function(t){var i;if(i=e(t.target,".cell",h))return d.edit({node:i,quick:!1})}),document.body.addEventListener("paste",function(t){var o;if(e(document.activeElement,".sheet",h)&&d.les.start)return o=t.clipboardData.getData("text"),o=i(o),d.set({row:d.les.start.row,col:d.les.start.col,data:o,range:!0})}),h.addEventListener("keydown",function(t){var i,e,o,s,r,n,l,h,c,a,f,u,x;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return d.copy();if(d.eventInScope(t)){if(8===(i=t.keyCode)){if(!d.les.node)return;for(o=(e=[d.les.start,d.les.end])[0],s=e[1],r=(e=o.col<s.col?[o.col,s.col]:[s.col,o.col])[0],n=e[1],l=(e=o.row<s.row?[o.row,s.row]:[s.row,o.row])[0],h=e[1],c=l;c<=h;++c)for(a=c,f=r;f<=n;++f)u=f,d.set({row:a,col:u,data:""})}if((x=function(){switch(i){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};default:return null}}())&&(!d.editing.on||d.editing.quick))return d.move(x),t.stopPropagation(),t.preventDefault(),d.dom.sheet.focus()}}),h.addEventListener("keypress",function(t){if(d.les.node&&!d.editing.on)return d.edit({node:d.les.node,quick:13!==t.keyCode})}),this.dom.textarea.addEventListener("keydown",function(t){var i,e,o;return 27===t.keyCode?(d.edited({cancel:!0}),t.stopPropagation(),t.preventDefault(),void d.dom.sheet.focus()):13!==t.keyCode||t.altKey||t.metaKey?13===t.keyCode&&(t.altKey||t.metaKey)?(d.dom.textarea.value+="\n",d.dom.layout.textContent=d.dom.textarea.value+" ",i=d.dom.layout.getBoundingClientRect(),e=d.editing.node.getBoundingClientRect(),o=d.dom.textarea.style,o.width=Math.max(i.width,e.width+1)+"px",o.height=Math.max(i.height,e.height+1)+"px",o):void 0:(d.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void d.dom.sheet.focus())}),document.addEventListener("wheel",function(t){var i,e,o,s,r,n,l;return i=d.eventInScope(t),(null==d.opt.scrollLock||d.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(i||t.target===document.body)&&t.preventDefault(),!!i&&(e=d.scrollPos,o=[t.deltaX,t.deltaY],s=o[0],r=o[1],o=Math.abs(s)>Math.abs(r)?[s,0]:[0,r],s=o[0],r=o[1],o=[e.x,e.y],n=o[0],l=o[1],e.x+=s/30,e.y+=r/30,s=Math.round(e.x)-Math.round(n),(r=Math.round(e.y)-Math.round(l))>0?d._md(r):r<0?d._mu(r):s>0?d._mr(s):s<0&&d._ml(s),d.renderSelection(),t.preventDefault())},{passive:!1})},copy:function(){var t,i,e,o,s,r,n,l,h,d;if(this.les.start){for(t=[],i=this.les.start.row,e=this.les.end.row+1;i<e;++i){for(i,o=[],s=this.les.start.col,r=this.les.end.col+1;s<r;++s)n=s,"object"!=typeof(l=((h=this._data)[rpw]||(h[rpw]=[]))[n])&&o.push('"'+(""+l||"").replace(/"/g,'""')+'"');t.push(o.join("\t"))}return d=t.join("\n"),navigator.clipboard.writeText(d)}},eventInScope:function(t){return e(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(i){var e;return null==i?this._size:(this._size={row:(e=t({row:[],col:[]},i)).row,col:e.col},this.regrid())},regrid:function(){var t=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){var t,i,e=[];for(t=0,i=this.frozen.col;t<i;++t)e.push(t);return e}.call(this).map(function(i){return t._size.col[i]||"max-content"}).join(" ")+" "+function(){var t,i,e=[];for(t=this.xif.col[2],i=this.dim.col;t<i;++t)e.push(t);return e}.call(this).map(function(i){return t._size.col[i+t.pos.col-t.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){var t,i,e=[];for(t=0,i=this.frozen.row;t<i;++t)e.push(t);return e}.call(this).map(function(i){return t._size.row[i]||"max-content"}).join(" ")+" "+function(){var t,i,e=[];for(t=this.xif.row[2],i=this.dim.row;t<i;++t)e.push(t);return e}.call(this).map(function(i){return t._size.row[i+t.pos.row-t.xif.row[1]]||"max-content"}).join(" ")},addCell:function(t,i){var e;return e=document.createElement("div"),this.dom.inner.insertBefore(e,this.dom.inner.childNodes[i*this.dim.col+t]),this._content({x:t,y:i,n:e})},set:function(t){var i,e,o,s,r,n,l,h,d,c,a,f;if(i=t.row,e=t.col,o=t.data,s=t.range)for(n=0,l=o.length;n<l;++n)for(d=0,c=o[h=n].length;d<c;++d)a=d,((r=this._data)[f=h+i]||(r[f]=[]))[a+e]=o[h][a],this._content({y:h+i-this.pos.row+this.xif.row[1],x:a+e-this.pos.col+this.xif.col[1]});else((r=this._data)[i]||(r[i]=[]))[e]=o,this._content({y:i-this.pos.row+this.xif.row[1],x:e-this.pos.col+this.xif.col[1]});return this.fire("change",{row:i,col:e,data:o,range:!!s})},_content:function(t){var i,e,s,r,n,l,h,d,c;if(i=t.x,e=t.y,((s=t.n)||(s=this.dom.inner.childNodes[i+e*this.dim.col]))&&(n=i<this.xif.col[0]&&e<this.xif.col[0]?["","cell idx"]:i<this.xif.col[0]?(r=e<this.xif.row[1]?" ":e<this.xif.row[2]?e-this.xif.row[1]+1:e-this.xif.row[1]+this.pos.row+1,[r,"cell idx"]):e<this.xif.row[0]?(r=i<this.xif.col[1]?" ":o(i<this.xif.col[2]?i-this.xif.col[1]:i-this.xif.col[1]+this.pos.col),[r,"cell idx"]):i<this.xif.col[1]?[null,"cell fixed"]:e<this.xif.row[1]?[null,"cell fixed"]:i<this.xif.col[2]&&e<this.xif.row[2]?[((n=this._data)[l=e-this.xif.row[1]]||(n[l]=[]))[i-this.xif.col[1]],"cell frozen fixed"]:i<this.xif.col[2]?[((n=this._data)[l=this.pos.row+e-this.xif.row[1]]||(n[l]=[]))[i-this.xif.col[1]],"cell frozen"]:e<this.xif.row[2]?[((n=this._data)[l=e-this.xif.row[1]]||(n[l]=[]))[this.pos.col+i-this.xif.col[1]],"cell frozen"]:[((n=this._data)[l=this.pos.row+e-this.xif.row[1]]||(n[l]=[]))[this.pos.col+i-this.xif.col[1]],"cell"],h=n[0],d=n[1],null==h&&(h=""),c=i>=this.xif.col[0]&&e>=this.xif.row[0]?(this.cls.col[this.pos.col+i-this.xif.col[1]]||"")+" "+(this.cls.row[this.pos.row+e-this.xif.row[1]]||""):"",s.className=d+" "+c,null!==h)){if("object"!=typeof h)return s.textContent=h;if("dom"===h.type)return s.textContent="",s.appendChild(h.node)}},_md:function(t){var i,e,o,s,r,n,l,h,d,c;for(null==t&&(t=1),i=this.dom.inner,s=e=(o=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))>0?o:0;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l&&(h=n,d=this.dim.col*this.fix.row,i.childNodes[d]);++n)i.removeChild(i.childNodes[d]);for(s=e;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:this.dim.row+r,n:c}),i.appendChild(c);return this.pos.row+=t},_mu:function(t){var i,e,o,s,r,n,l,h,d,c,a=[];if(null==t&&(t=1),i=this.dom.inner,!(this.pos.row<=0)){for((t=Math.round(Math.abs(t)))>=this.pos.row&&(t=this.pos.row),s=e=(o=t-(this.dim.row-this.xif.row[2]))>0?o:0;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l&&(h=n,i.childNodes.length);++n)i.removeChild(i.childNodes[i.childNodes.length-1]);for(this.pos.row-=t,s=e;s<t;++s){for(r=s,d=[],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}),d.push(i.insertBefore(c,i.childNodes[h+(r-e)*this.dim.col+this.dim.col*this.xif.row[2]]));a.push(d)}return a}},_mr:function(t){var i,e,o,s,r,n,l,h;for(null==t&&(t=1),i=this.dom.inner,o=(e=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))>0?e:0;o<t;++o)for(s=o,r=0,n=this.dim.row;r<n;++r)l=r,i.removeChild(i.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+s,y:l,n:h}),i.insertBefore(h,i.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid()},_ml:function(t){var i,e,o,s,r,n,l,h,d;if(null==t&&(t=1),i=this.dom.inner,(t=Math.round(Math.abs(t)))>=this.pos.col&&(t=this.pos.col),!(this.pos.col<=0||t<=0)){for(e=(o=t-(this.dim.col-this.xif.col[2]))>0?o:0,this.pos.col-=t,s=e;s<t;++s)for(r=s,n=0,l=this.dim.row;n<l;++n)h=n,i.removeChild(i.childNodes[(h+1)*this.dim.col-1]),d=document.createElement("div"),this._content({x:r+this.xif.col[2],y:h,n:d}),i.insertBefore(d,i.childNodes[h*this.dim.col+this.xif.col[2]+r-e]);return this.regrid()}},goto:function(i){return null==i&&(i={row:0,col:0}),t(this.pos,i),this.render()},render:function(){var t,i,e,o,s,r,n,l=[];for(t=0,i=this.dim.row;t<i;++t){for(e=t,o=[],s=0,r=this.dim.col;s<r;++s)n=s,o.push(this._content({x:n,y:e}));l.push(o)}return l},move:function(t){var i,e,o,s,r;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(i=this.cell(t))){if(e=this.index(i),o=i.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),o.x+o.width>s.x+s.width&&this._mr(1),o.y+o.height>s.y+s.height&&this._md(1),0===e.x){if(0===this.pos.col)return;this._ml(1)}if(0===e.y){if(0===this.pos.row)return;this._mu(1)}if(i=this.cell(t))return this.les.node=i,this.les.start=this.les.end={col:(r=this.index(i)).col,row:r.row},this.renderSelection()}},edit:function(t){var i,e,o,s,r,n,l,h,d,c;if(i=t.node,e=t.quick,this._editing&&!(!(o=this.index(i))||o.col<0||o.row<0))return s=this.editing,s.node=i,s.quick=e,s.on=!0,this.dom.layout.textContent=i.textContent,r=this.dom.layout.getBoundingClientRect(),n=i.getBoundingClientRect(),l=this.dom.sheet.getBoundingClientRect(),s=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop],h=s[0],d=s[1],s=this.dom.edit.style,s.left=n.x-l.x+h-2+"px",s.top=n.y-l.y+d-2+"px",s.width="fit-content",s.height="fit-content",this.dom.edit.classList.toggle("show",!0),s=this.dom.textarea.style,s.width=Math.max(r.width,n.width+1)+"px",s.height=Math.max(r.height,n.height+1)+"px",this.dom.textarea.value=c=e?"":i.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(c.length,c.length)},edited:function(t){var i;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),i=this.editing,i.node=null,i.on=!1,i},index:function(t){var i,e,o,s,r;return(i=Array.from(this.dom.inner.childNodes).indexOf(t))<0?null:(e=i%this.dim.col,o=(i-e)/this.dim.col,s=e<this.xif.col[1]?-1:e<this.xif.col[2]?e-this.xif.col[1]:e-this.xif.col[1]+this.pos.col,r=o<this.xif.row[1]?-1:o<this.xif.row[2]?o-this.xif.row[1]:o-this.xif.row[1]+this.pos.row,{x:e,y:o,col:s,row:r})},cell:function(t){var i,e,o,s;if(null==t&&(t={}),null!=t.col){if(t.col<this.frozen.col)i=t.col;else{if(t.col-this.pos.col<this.frozen.col)return null;i=t.col-this.pos.col}if(t.row<this.frozen.row)e=t.row;else{if(t.row-this.pos.row<this.frozen.row)return null;e=t.row-this.pos.row}return o=[i+this.xif.col[1],e+this.xif.row[1]],i=o[0],e=o[1],i<0||e<0||i>=this.dim.col||e>=this.dim.row?null:this.dom.inner.childNodes[e*this.dim.col+i]}if(!(s=t.node?this.index(t.node):{y:0,x:0}))throw new Error("node not found in sheet");return e=s.y+(t.y||0),i=s.x+(t.x||0),this.dom.inner.childNodes[e*this.dim.col+i]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(){var t,i,e,o,s,r,n,l,h,d,c,a,f,u,x,w,m,p,g,v,y,_,C,M;if(this.les.start)return t=this.les.start.col<this.les.end.col?[this.les.start.col,this.les.end.col]:[this.les.end.col,this.les.start.col],i=t[0],e=t[1],t=this.les.start.row<this.les.end.row?[this.les.start.row,this.les.end.row]:[this.les.end.row,this.les.start.row],o=t[0],s=t[1],r=this.dom.inner.getBoundingClientRect(),n=this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),l=this.cell({col:i,row:o}),h=this.cell({col:i,row:s}),d=this.cell({col:e,row:o}),c=this.cell({col:e,row:s}),t=[n,l,h,d,c].map(function(t){return t?t.getBoundingClientRect():null}),a=t[0],f=t[1],u=t[2],x=t[3],w=t[4],a.width=0,a.height=0,m=(f||u||a).x-r.x,p=(f||x||a).y-r.y,g=(x||w||a).x+(x||w||a).width-r.x,v=(u||w||a).y+(u||w||a).height-r.y,y=g-m+1,_=v-p+1,C=this.cell(this.les.start),M=C?C.getBoundingClientRect():null,t=this.dom.range.style,t.left=m+"px",t.top=p+"px",t.width=y+"px",t.height=_+"px",this.dom.range.classList.toggle("show",!0),M&&((t=this.dom.caret.style).left=M.x-r.x-1+"px",t.top=M.y-r.y-1+"px",t.width=M.width+2+"px",t.height=M.height+2+"px",t.zIndex=this.les.start.row+this.xif.row[1]<this.xif.row[2]&&this.les.start.col+this.xif.col[1]<this.xif.col[2]?101:this.les.start.row+this.xif.row[1]<this.xif.row[2]||this.les.start.col+this.xif.col[1]<this.xif.col[2]?20:15),this.dom.caret.classList.toggle("show",!!M)},data:function(t){return null==t?this._data:(this._data=t,this.render())}}),"undefined"!=typeof module&&null!==module?module.exports=s:"undefined"!=typeof window&&null!==window&&(window.sheet=s)}).call(this);
1
+ !function(){var u,f,r,t;function o(t,e){var i,o={}.hasOwnProperty;for(i in e)o.call(e,i)&&(t[i]=e[i]);return t}u=function(t){return Papa.parse(t).data},f=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},r=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="",n=0;n<=e;++n)o="ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i%26)+o,i=(i-i%26)/26;return o},(t=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._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"].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"].map(function(t){return i.dom.sheet.appendChild(i.dom[t])}),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,n,r=[],s=[],l=1,h=arguments.length;l<h;++l)s.push(arguments[l]);for(e=s,l=0,o=(i=this.evtHandler[t]||[]).length;l<o;++l)n=i[l],r.push(n.apply(this,e));return r},_init:function(){for(var t,e,i,o,d,a=this,n=0,r=this.dim.row;n<r;++n)for(t=n,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()}),(d=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(a.edited(),e=f(t.target,".cell",d))return(o={row:(i=a.index(e)).row,col:i.col}).col<0||o.row<0?(t.shiftKey&&a.les.start||(a.les.node=a.cell(a.les.start),a.les.start={col:0<(i=o.col)?i:0,row:0<(i=o.row)?i:0}),a.les.end={col:0<=o.col?o.col:void 0,row:0<=o.row?o.row:void 0},void a.renderSelection()):(t.shiftKey&&a.les.start?a.les.end=o:(a.les.start=a.les.end=o,a.les.node=e),a.renderSelection())}),d.addEventListener("mousemove",function(t){var e;if(!a.editing.on&&t.buttons&&(e=f(t.target,".cell",d)))return e={row:(e=a.index(e)).row,col:e.col},a.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},a.renderSelection()}),d.addEventListener("dblclick",function(t){if(t=f(t.target,".cell",d))return a.edit({node:t,quick:!1})}),document.body.addEventListener("paste",function(t){var e,i,o,n,r,s,l,h,c;if(f(document.activeElement,".sheet",d)&&a.les.start&&(n=t.clipboardData.getData("text"),e=u(n),a.set({row:a.les.start.row,col:a.les.start.col,data:e,range:!0}),a.sel.cut)){if(a._toText({sel:a.sel.cut})===n){for(i=(e=a._bound({sel:a.sel.cut})).sc,o=e.ec,n=e.sr,r=e.er,s=n;s<=r;++s)for(l=s,h=i;h<=o;++h)c=h,a.set({row:l,col:c,data:""});navigator.clipboard.writeText("")}return a.sel.cut=null,a.dom["range-cut"].classList.toggle("show",!1)}}),d.addEventListener("keydown",function(t){var e,i,o,n,r,s,l,h,c,d=t.keyCode;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return a.copy();if(88===t.keyCode&&(t.metaKey||t.ctrlKey))return a.copy({cut:!0});if(a.eventInScope(t)){if(8===d){if(!a.les.node)return;for(e=a._bound(),i=e.sc,o=e.ec,c=e.sr,n=e.er,r=c;r<=n;++r)for(s=r,l=i;l<=o;++l)h=l,a.set({row:s,col:h,data:""})}return 189===d&&(t.metaKey||t.ctrlKey)?a.les.node?(e=a._bound({defined:!1}),i=e.sc,o=e.ec,c=e.sr,n=e.er,null==o&&a._data.splice(c,n-c+1),null==n&&a._data.map(function(t){return t.splice(i,o-i+1)}),a.les.end=a.les.start,a.renderSelection(),void a.render()):void 0:!(c=function(){switch(d){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};default:return null}}())||a.editing.on&&!a.editing.quick?void 0:(a.move(c),t.stopPropagation(),t.preventDefault(),a.dom.sheet.focus())}}),d.addEventListener("keypress",function(t){if(31!==t.keyCode||!t.metaKey&&!t.ctrlKey)return a.les.node&&!a.editing.on?a.edit({node:a.les.node,quick:13!==t.keyCode}):void 0}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o;return 27===t.keyCode?(a.edited({cancel:!0}),t.stopPropagation(),t.preventDefault(),void a.dom.sheet.focus()):13!==t.keyCode||t.altKey||t.metaKey?13===t.keyCode&&(t.altKey||t.metaKey)?(a.dom.textarea.value+="\n",a.dom.layout.textContent=a.dom.textarea.value+" ",e=a.dom.layout.getBoundingClientRect(),i=a.editing.node.getBoundingClientRect(),(o=a.dom.textarea.style).width=Math.max(e.width,i.width+1)+"px",o.height=Math.max(e.height,i.height+1)+"px",o):void 0:(a.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void a.dom.sheet.focus())}),document.addEventListener("wheel",function(t){var e,i,o,n,r=a.eventInScope(t);return(null==a.opt.scrollLock||a.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!r&&t.target!==document.body||t.preventDefault()),!!r&&(e=a.scrollPos,i=(n=[t.deltaX,t.deltaY])[0],o=n[1],i=(n=Math.abs(i)>Math.abs(o)?[i,0]:[0,o])[0],o=n[1],r=(n=[e.x,e.y])[0],n=n[1],e.x+=i/30,e.y+=o/30,i=Math.round(e.x)-Math.round(r),0<(o=Math.round(e.y)-Math.round(n))?a._md(o):o<0?a._mu(o):0<i?a._mr(i):i<0&&a._ml(i),a.renderSelection(),t.preventDefault())},{passive:!1})},_bound:function(t){var e,i=(r=(n=(r=[(o=(t=null==t?{}:t).sel||this.les).start,o.end])[0]).col<(e=r[1]).col||null==e.col?[n.col,e.col]:[e.col,n.col])[0],o=r[1],n=(r=n.row<e.row||null==e.row?[n.row,e.row]:[e.row,n.row])[0],r=r[1];return null!=t.defined&&!t.defined||(null==o&&(o=Math.max.apply(Math,this._data.map(function(t){return t.length}))),null==r&&(r=this._data.length)),{sc:i,ec:o,sr:n,er:r}},_toText:function(t){var e,i,o,n,r,s,l,h,c,d,t=t.sel;if(!t||!t.start)return"";for(e=[],o=(i=this._bound({sel:t})).sc,n=i.ec,t=i.sr,r=i.er,s=t;s<=r;++s){for(l=s,h=[],c=o;c<=n;++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 f(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,n,r,s,l,h,c=t.row,d=t.col,a=t.data,t=t.range;if(t)for(i=0,o=a.length;i<o;++i)for(r=0,s=a[n=i].length;r<s;++r)l=r,((e=this._data)[h=n+c]||(e[h]=[]))[l+d]=a[n][l],this._content({y:n+c-this.pos.row+this.xif.row[1],x:l+d-this.pos.col+this.xif.col[1]});else((e=this._data)[c]||(e[c]=[]))[d]=a,this._content({y:c-this.pos.row+this.xif.row[1],x:d-this.pos.col+this.xif.col[1]});return this.fire("change",{row:c,col:d,data:a,range:!!t})},_content:function(t){var e,i,o=t.x,n=t.y,t=t.n;if(t=t||this.dom.inner.childNodes[o+n*this.dim.col])return e=(i=o<this.xif.col[0]&&n<this.xif.col[0]?["","cell idx"]:o<this.xif.col[0]?[n<this.xif.row[1]?" ":n<this.xif.row[2]?n-this.xif.row[1]+1:n-this.xif.row[1]+this.pos.row+1,"cell idx"]:n<this.xif.row[0]?[o<this.xif.col[1]?" ":o<this.xif.col[2]?r(o-this.xif.col[1]):r(o-this.xif.col[1]+this.pos.col),"cell idx"]:o<this.xif.col[1]||n<this.xif.row[1]?[null,"cell fixed"]:o<this.xif.col[2]&&n<this.xif.row[2]?[((i=this._data)[e=n-this.xif.row[1]]||(i[e]=[]))[o-this.xif.col[1]],"cell frozen fixed"]:o<this.xif.col[2]?[((i=this._data)[e=this.pos.row+n-this.xif.row[1]]||(i[e]=[]))[o-this.xif.col[1]],"cell frozen"]:n<this.xif.row[2]?[((i=this._data)[e=n-this.xif.row[1]]||(i[e]=[]))[this.pos.col+o-this.xif.col[1]],"cell frozen"]:[((i=this._data)[e=this.pos.row+n-this.xif.row[1]]||(i[e]=[]))[this.pos.col+o-this.xif.col[1]],"cell"])[0],i=i[1],null==e&&(e=""),n=o>=this.xif.col[0]&&n>=this.xif.row[0]?(this.cls.col[this.pos.col+o-this.xif.col[1]]||"")+" "+(this.cls.row[this.pos.row+n-this.xif.row[1]]||""):"",t.className=i+" "+n,null!==e?"object"!=typeof e?t.textContent=e:"dom"===e.type?(t.textContent="",t.appendChild(e.node)):void 0:void 0},_md:function(t){var e,i,o,n,r,s,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(n=o,r=0,s=this.dim.col;r<s&&(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(n=o,r=0,s=this.dim.col;r<s;++r)l=r,c=document.createElement("div"),this._content({x:l,y:this.dim.row+n,n:c}),e.appendChild(c);return this.pos.row+=t},_mu:function(t){var e,i,o,n,r,s,l,h,c,d,a=[];if(null==t&&(t=1),e=this.dom.inner,!(this.pos.row<=0)){for(n=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;n<t;++n)for(r=n,s=0,l=this.dim.col;s<l&&(h=s,e.childNodes.length);++s)e.removeChild(e.childNodes[e.childNodes.length-1]);for(this.pos.row-=t,n=i;n<t;++n){for(r=n,c=[],s=0,l=this.dim.col;s<l;++s)h=s,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,n,r,s,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(n=o,r=0,s=this.dim.row;r<s;++r)l=r,e.removeChild(e.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+n,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,n,r,s,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,n=i;n<t;++n)for(r=n,s=0,l=this.dim.row;s<l;++s)h=s,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,n,r=[],s=0,l=this.dim.row;s<l;++s){for(t=s,e=[],i=0,o=this.dim.col;i<o;++i)n=i,e.push(this._content({x:n,y:t}));r.push(e)}return r},move:function(t){var e,i,o,n;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(n=this.cell(t))){if(e=this.index(n),i=n.getBoundingClientRect(),o=this.dom.sheet.getBoundingClientRect(),i.x+i.width>o.x+o.width&&this._mr(1),i.y+i.height>o.y+o.height&&this._md(1),0===e.x){if(0===this.pos.col)return;this._ml(1)}if(0===e.y){if(0===this.pos.row)return;this._mu(1)}if(n=this.cell(t))return this.les.node=n,this.les.start=this.les.end={col:(n=this.index(n)).col,row:n.row},this.renderSelection()}},edit:function(t){var e,i,o,n,r,s=t.node,l=t.quick;if(this._editing&&!(!(r=this.index(s))||r.col<0||r.row<0))return(e=this.editing).node=s,e.quick=l,e.on=!0,this.dom.layout.textContent=s.textContent,i=this.dom.layout.getBoundingClientRect(),o=s.getBoundingClientRect(),n=this.dom.sheet.getBoundingClientRect(),t=(e=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],r=e[1],(e=this.dom.edit.style).left=o.x-n.x+t-2+"px",e.top=o.y-n.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=s=!l&&s.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(s.length,s.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=Array.from(this.dom.inner.childNodes).indexOf(t);return e<0?null:{x:t=e%this.dim.col,y:e=(e-t)/this.dim.col,col:t<this.xif.col[1]?-1:t<this.xif.col[2]?t-this.xif.col[1]:t-this.xif.col[1]+this.pos.col,row:e<this.xif.row[1]?-1:e<this.xif.row[2]?e-this.xif.row[1]:e-this.xif.row[1]+this.pos.row}},cell:function(t){var e,i,o;if(null!=(t=null==t?{}:t).col){if(t.col<this.frozen.col)e=t.col;else{if(t.col-this.pos.col<this.frozen.col)return null;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)return null;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}))throw new Error("node not found in sheet");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,n,r,s,l,h,c,d,a;if(null==e&&(e={}),(t=t||this.les).start)return r=(i=this._bound({defined:!1,sel:t})).sc,a=i.ec,s=i.sr,d=i.er,o=this.dom.inner.getBoundingClientRect(),c=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:r,row:s}),this.cell({col:r,row:d}),this.cell({col:a,row:s}),this.cell({col:a,row:d})].map(function(t){return t?t.getBoundingClientRect():null}))[0],l=i[1],n=i[2],h=i[3],r=i[4],c.width=0,c.height=0,s=(l||n||c).x-o.x,l=(l||h||c).y-o.y,h=(h||r||c).x+(h||r||c).width-o.x-s+1,c=(n||r||c).y+(n||r||c).height-o.y-l+1,null==a&&(h=this.root.getBoundingClientRect().width),null==d&&(c=this.root.getBoundingClientRect().height),d=(a=this.cell(t.start))?a.getBoundingClientRect():null,(i=(a=e.cut?this.dom["range-cut"]:this.dom.range).style).left=s+"px",i.top=l+"px",i.width=h+"px",i.height=c+"px",a.classList.toggle("show",!0),e.cut?void 0:(d&&((i=this.dom.caret.style).left=d.x-o.x-1+"px",i.top=d.y-o.y-1+"px",i.width=d.width+2+"px",i.height=d.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",!!d))},data:function(t){return null==t?this._data:(this._data=t,this.render())}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.sheet=t)}.call(this);
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.2.0","style":"index.min.css","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/sheet","repository":{"type":"git","url":"https://github.com/plotdb/sheet"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","deploy":"npx deploy web/static"},"devDependencies":{"@loadingio/debounce.js":"1.0.1","@loadingio/ldquery":"^3.0.1","@plotdb/csscope":"^4.0.0","@plotdb/datadom":"^0.2.0","@plotdb/json0":"^0.0.5","@plotdb/rescope":"^4.1.0","body-parser":"^1.19.0","bootstrap":"^4.5.2","@loadingio/bootstrap.ext":"^0.0.4","bootstrap.native":"^3.0.13","dompurify":"^2.2.6","fedep":"^1.1.2","jsoneditor":"^9.1.1","ldcover":"^3.0.1","ldiconfont":"^0.1.10","ldview":"^1.0.0","livescript":"^1.6.0","proxise":"^1.0.1","sharedb-wrapper":"^1.0.0","stylus":"^0.55.0","@zbryikt/template":"^2.3.33","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","dompurify","ldview","ldcover","jsoneditor","ldiconfont","proxise","@plotdb/datadom","@plotdb/csscope","@plotdb/rescope","sharedb-wrapper","@plotdb/json0"]}}
1
+ {"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.4.0","style":"index.min.css","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/sheet","repository":{"type":"git","url":"https://github.com/plotdb/sheet"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","deploy":"npx deploy web/static"},"devDependencies":{"@loadingio/debounce.js":"1.0.1","@loadingio/ldquery":"^3.0.4","@plotdb/csscope":"^4.0.8","@plotdb/datadom":"^0.2.0","@plotdb/json0":"^0.0.5","@plotdb/rescope":"^4.1.7","body-parser":"^1.19.0","bootstrap":"^4.5.2","@loadingio/bootstrap.ext":"^0.0.9","bootstrap.native":"^3.0.13","dompurify":"^2.2.6","fedep":"^1.1.7","jsoneditor":"^9.1.1","ldcover":"^3.2.1","ldiconfont":"^0.2.3","ldview":"^1.2.1","livescript":"^1.6.0","proxise":"^1.0.1","sharedb-wrapper":"^1.0.0","stylus":"^0.55.0","@zbryikt/template":"^2.3.38","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","dompurify","ldview","ldcover","jsoneditor","ldiconfont","proxise","@plotdb/datadom","@plotdb/csscope","@plotdb/rescope","sharedb-wrapper","@plotdb/json0"]}}