@plotdb/sheet 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Change Logs
2
2
 
3
+ ## v0.4.1
4
+
5
+ - fix bug: `change` event should be fired for row-wise / col-wise deletion
6
+ - fix bug: `change` event for range update should be fired in one batch
7
+
8
+
9
+ ## v0.4.0
10
+
11
+ - support in-sheet cut / paste
12
+ - support row-wise / column-wise deletion by ctrl+`-`
13
+ - separate `_to-text` function from `copy`
14
+ - parameterize `render-selection` for possibly future features such as multiple selection
15
+
16
+
3
17
  ## v0.3.0
4
18
 
5
19
  - support shift-select a range
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);
@@ -234,47 +236,108 @@
234
236
  });
235
237
  });
236
238
  document.body.addEventListener('paste', function(e){
237
- var data;
239
+ var raw, data, s, ref$, sc, ec, sr, er, i$, row, j$, col;
238
240
  if (!parent(document.activeElement, '.sheet', dom)) {
239
241
  return;
240
242
  }
241
243
  if (!this$.les.start) {
242
244
  return;
243
245
  }
244
- data = e.clipboardData.getData('text');
245
- data = parseCsv(data);
246
- return this$.set({
246
+ raw = e.clipboardData.getData('text');
247
+ data = parseCsv(raw);
248
+ this$.set({
247
249
  row: this$.les.start.row,
248
250
  col: this$.les.start.col,
249
251
  data: data,
250
252
  range: true
251
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
+ }
252
278
  });
253
279
  dom.addEventListener('keydown', function(e){
254
- var code, ref$, sc, ec, sr, er, i$, row, j$, col, opt;
280
+ var code, ref$, sc, ec, sr, er, data, res$, i$, row, lresult$, j$, col, d, opt;
281
+ code = e.keyCode;
255
282
  if (e.keyCode === 67 && (e.metaKey || e.ctrlKey)) {
256
283
  return this$.copy();
257
284
  }
285
+ if (e.keyCode === 88 && (e.metaKey || e.ctrlKey)) {
286
+ return this$.copy({
287
+ cut: true
288
+ });
289
+ }
258
290
  if (!this$.eventInScope(e)) {
259
291
  return;
260
292
  }
261
- code = e.keyCode;
262
293
  if (code === 8) {
263
294
  if (!this$.les.node) {
264
295
  return;
265
296
  }
266
297
  ref$ = this$._bound(), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
298
+ res$ = [];
267
299
  for (i$ = sr; i$ <= er; ++i$) {
268
300
  row = i$;
301
+ lresult$ = [];
269
302
  for (j$ = sc; j$ <= ec; ++j$) {
270
303
  col = j$;
271
- this$.set({
272
- row: row,
273
- col: col,
274
- data: ""
275
- });
304
+ lresult$.push('');
276
305
  }
306
+ res$.push(lresult$);
277
307
  }
308
+ data = res$;
309
+ this$.set({
310
+ row: sr,
311
+ col: sc,
312
+ data: data,
313
+ range: true
314
+ });
315
+ }
316
+ if (code === 189 && (e.metaKey || e.ctrlKey)) {
317
+ if (!this$.les.node) {
318
+ return;
319
+ }
320
+ ref$ = this$._bound({
321
+ defined: false
322
+ }), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
323
+ if (ec == null) {
324
+ d = this$._data.splice(sr, er - sr + 1);
325
+ }
326
+ if (er == null) {
327
+ d = this$._data.map(function(it){
328
+ return it.splice(sc, ec - sc + 1);
329
+ });
330
+ }
331
+ this$.fire('change', {
332
+ row: sr,
333
+ col: sc,
334
+ data: d,
335
+ range: true
336
+ });
337
+ this$.les.end = this$.les.start;
338
+ this$.renderSelection();
339
+ this$.render();
340
+ return;
278
341
  }
279
342
  opt = (function(){
280
343
  switch (code) {
@@ -314,6 +377,9 @@
314
377
  return this$.dom.sheet.focus();
315
378
  });
316
379
  dom.addEventListener('keypress', function(e){
380
+ if (e.keyCode === 31 && (e.metaKey || e.ctrlKey)) {
381
+ return;
382
+ }
317
383
  if (this$.les.node && !this$.editing.on) {
318
384
  return this$.edit({
319
385
  node: this$.les.node,
@@ -389,9 +455,10 @@
389
455
  });
390
456
  },
391
457
  _bound: function(o){
392
- var ref$, p1, p2, sc, ec, sr, er;
458
+ var sel, ref$, p1, p2, sc, ec, sr, er;
393
459
  o == null && (o = {});
394
- ref$ = [this.les.start, this.les.end], p1 = ref$[0], p2 = ref$[1];
460
+ sel = o.sel || this.les;
461
+ ref$ = [sel.start, sel.end], p1 = ref$[0], p2 = ref$[1];
395
462
  ref$ = p1.col < p2.col || p2.col == null
396
463
  ? [p1.col, p2.col]
397
464
  : [p2.col, p1.col], sc = ref$[0], ec = ref$[1];
@@ -415,19 +482,24 @@
415
482
  er: er
416
483
  };
417
484
  },
418
- copy: function(){
419
- var c, ref$, sc, ec, sr, er, i$, row, r, j$, col, content, s;
420
- if (!this.les.start) {
421
- return;
485
+ _toText: function(arg$){
486
+ var sel, c, ref$, sc, ec, sr, er, i$, row, r, j$, col, content, s;
487
+ sel = arg$.sel;
488
+ if (!(sel && sel.start)) {
489
+ return '';
422
490
  }
423
491
  c = [];
424
- ref$ = this._bound(), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
492
+ ref$ = this._bound({
493
+ sel: sel
494
+ }), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
425
495
  for (i$ = sr; i$ <= er; ++i$) {
426
496
  row = i$;
427
497
  r = [];
428
498
  for (j$ = sc; j$ <= ec; ++j$) {
429
499
  col = j$;
430
- content = ((ref$ = this._data)[rpw] || (ref$[rpw] = []))[col];
500
+ if ((content = ((ref$ = this._data)[row] || (ref$[row] = []))[col]) == null) {
501
+ content = '';
502
+ }
431
503
  if (typeof content === 'object') {
432
504
  continue;
433
505
  }
@@ -436,7 +508,27 @@
436
508
  c.push(r.join('\t'));
437
509
  }
438
510
  s = c.join('\n');
439
- return navigator.clipboard.writeText(s);
511
+ return s;
512
+ },
513
+ copy: function(o){
514
+ var s;
515
+ o == null && (o = {});
516
+ if (!this.les.start) {
517
+ return;
518
+ }
519
+ s = this._toText({
520
+ sel: this.les
521
+ });
522
+ navigator.clipboard.writeText(s);
523
+ if (o.cut) {
524
+ this.sel.cut = {
525
+ start: this.les.start,
526
+ end: this.les.end
527
+ };
528
+ return this.renderSelection(this.sel.cut, {
529
+ cut: true
530
+ });
531
+ }
440
532
  },
441
533
  eventInScope: function(e){
442
534
  return parent(e.target, '.sheet', this.dom.sheet) === this.dom.sheet;
@@ -893,13 +985,18 @@
893
985
  ? this._editing
894
986
  : this._editing = !!v;
895
987
  },
896
- renderSelection: function(){
897
- 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;
898
- if (!this.les.start) {
988
+ renderSelection: function(sel, o){
989
+ 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;
990
+ o == null && (o = {});
991
+ if (!sel) {
992
+ sel = this.les;
993
+ }
994
+ if (!sel.start) {
899
995
  return;
900
996
  }
901
997
  ref$ = this._bound({
902
- defined: false
998
+ defined: false,
999
+ sel: sel
903
1000
  }), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
904
1001
  rbox = this.dom.inner.getBoundingClientRect();
905
1002
  c0 = this.cell({
@@ -943,27 +1040,32 @@
943
1040
  if (er == null) {
944
1041
  h = this.root.getBoundingClientRect().height;
945
1042
  }
946
- snode = this.cell(this.les.start);
1043
+ snode = this.cell(sel.start);
947
1044
  sbox = !snode
948
1045
  ? null
949
1046
  : snode.getBoundingClientRect();
950
- ref$ = this.dom.range.style;
1047
+ dom = o.cut
1048
+ ? this.dom["range-cut"]
1049
+ : this.dom.range;
1050
+ ref$ = dom.style;
951
1051
  ref$.left = x1 + "px";
952
1052
  ref$.top = y1 + "px";
953
1053
  ref$.width = w + "px";
954
1054
  ref$.height = h + "px";
955
- this.dom.range.classList.toggle('show', true);
956
- if (sbox) {
957
- ref$ = this.dom.caret.style;
958
- ref$.left = (sbox.x - rbox.x - 1) + "px";
959
- ref$.top = (sbox.y - rbox.y - 1) + "px";
960
- ref$.width = (sbox.width + 2) + "px";
961
- ref$.height = (sbox.height + 2) + "px";
962
- 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]
963
- ? 101
964
- : 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;
965
- }
966
- return this.dom.caret.classList.toggle('show', !!sbox);
1055
+ dom.classList.toggle('show', true);
1056
+ if (!o.cut) {
1057
+ if (sbox) {
1058
+ ref$ = this.dom.caret.style;
1059
+ ref$.left = (sbox.x - rbox.x - 1) + "px";
1060
+ ref$.top = (sbox.y - rbox.y - 1) + "px";
1061
+ ref$.width = (sbox.width + 2) + "px";
1062
+ ref$.height = (sbox.height + 2) + "px";
1063
+ ref$.zIndex = sel.start.row + this.xif.row[1] < this.xif.row[2] && sel.start.col + this.xif.col[1] < this.xif.col[2]
1064
+ ? 101
1065
+ : sel.start.row + this.xif.row[1] < this.xif.row[2] || sel.start.col + this.xif.col[1] < this.xif.col[2] ? 20 : 15;
1066
+ }
1067
+ return this.dom.caret.classList.toggle('show', !!sbox);
1068
+ }
967
1069
  },
968
1070
  data: function(it){
969
1071
  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(){var l,h,s,t;function e(t,i){var o,e={}.hasOwnProperty;for(o in i)e.call(i,o)&&(t[o]=i[o]);return t}l=function(t){return Papa.parse(t).data},h=function(t,i,o){for(var e=t;t&&t!==o;)t=t.parentNode;if(t!==o)return null;if(!i)return t;for(t=e;t&&t!==o&&(!t.matches||t.matches&&!t.matches(i));)t=t.parentNode;return t!==o||o.matches&&o.matches(i)?t:null},s=function(t){for(var i=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,o=t-((Math.pow(26,1+i)-1)/25-1),e="",n=0;n<=i;++n)e="ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(o%26)+e,o=(o-o%26)/26;return e},(t=function(t){var i,o=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:(i=e({row:[],col:[]},t.size)).row,col:i.col},this.cls={row:(i=e({row:[],col:[]},t.class)).row,col:i.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:(i=e({col:0,row:0},t.frozen||{})).col,row:i.row},this.idx={col:(i=e({row:!0,col:!0},t.idx||{})).col,row:i.row},this.fixed={col:(i=e({col:0,row:0},t.fixed||{})).col,row:i.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;i=document.createElement("div");return i.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=e(Object.create(Object.prototype),{on:function(t,i){var o;return((o=this.evtHandler)[t]||(o[t]=[])).push(i)},fire:function(t){for(var i,o,e,n,s=[],r=[],l=1,h=arguments.length;l<h;++l)r.push(arguments[l]);for(i=r,l=0,e=(o=this.evtHandler[t]||[]).length;l<e;++l)n=o[l],s.push(n.apply(this,i));return s},_init:function(){for(var t,i,o,e,n,a=this,s=0,r=this.dim.row;s<r;++s)for(t=s,i=0,o=this.dim.col;i<o;++i)e=i,this.addCell(e,t);return this.regrid(),this.dom.textarea.addEventListener("mousedown",function(t){return t.stopPropagation()}),(n=this.dom.sheet).addEventListener("mousedown",function(t){var i,o,e;if(a.edited(),i=h(t.target,".cell",n))return(e={row:(o=a.index(i)).row,col:o.col}).col<0||e.row<0?(t.shiftKey&&a.les.start||(a.les.node=a.cell(a.les.start),a.les.start={col:0<(o=e.col)?o:0,row:0<(o=e.row)?o:0}),a.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},void a.renderSelection()):(t.shiftKey&&a.les.start?a.les.end=e:(a.les.start=a.les.end=e,a.les.node=i),a.renderSelection())}),n.addEventListener("mousemove",function(t){var i;if(!a.editing.on&&t.buttons&&(i=h(t.target,".cell",n)))return i={row:(i=a.index(i)).row,col:i.col},a.les.end={col:0<=i.col?i.col:void 0,row:0<=i.row?i.row:void 0},a.renderSelection()}),n.addEventListener("dblclick",function(t){if(t=h(t.target,".cell",n))return a.edit({node:t,quick:!1})}),document.body.addEventListener("paste",function(t){if(h(document.activeElement,".sheet",n)&&a.les.start)return t=t.clipboardData.getData("text"),t=l(t),a.set({row:a.les.start.row,col:a.les.start.col,data:t,range:!0})}),n.addEventListener("keydown",function(t){var i,o,e,n,s,r,l,h,d,c;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return a.copy();if(a.eventInScope(t)){if(8===(i=t.keyCode)){if(!a.les.node)return;for(e=(o=a._bound()).sc,n=o.ec,c=o.sr,s=o.er,r=c;r<=s;++r)for(l=r,h=e;h<=n;++h)d=h,a.set({row:l,col:d,data:""})}if((c=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}}())&&(!a.editing.on||a.editing.quick))return a.move(c),t.stopPropagation(),t.preventDefault(),a.dom.sheet.focus()}}),n.addEventListener("keypress",function(t){if(a.les.node&&!a.editing.on)return a.edit({node:a.les.node,quick:13!==t.keyCode})}),this.dom.textarea.addEventListener("keydown",function(t){var i,o,e;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+" ",i=a.dom.layout.getBoundingClientRect(),o=a.editing.node.getBoundingClientRect(),(e=a.dom.textarea.style).width=Math.max(i.width,o.width+1)+"px",e.height=Math.max(i.height,o.height+1)+"px",e):void 0:(a.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void a.dom.sheet.focus())}),document.addEventListener("wheel",function(t){var i,o,e,n,s=a.eventInScope(t);return(null==a.opt.scrollLock||a.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!s&&t.target!==document.body||t.preventDefault()),!!s&&(i=a.scrollPos,o=(n=[t.deltaX,t.deltaY])[0],e=n[1],o=(n=Math.abs(o)>Math.abs(e)?[o,0]:[0,e])[0],e=n[1],s=(n=[i.x,i.y])[0],n=n[1],i.x+=o/30,i.y+=e/30,o=Math.round(i.x)-Math.round(s),0<(e=Math.round(i.y)-Math.round(n))?a._md(e):e<0?a._mu(e):0<o?a._mr(o):o<0&&a._ml(o),a.renderSelection(),t.preventDefault())},{passive:!1})},_bound:function(t){var i,o=(s=(n=(s=[this.les.start,this.les.end])[0]).col<(i=s[1]).col||null==i.col?[n.col,i.col]:[i.col,n.col])[0],e=s[1],n=(s=n.row<i.row||null==i.row?[n.row,i.row]:[i.row,n.row])[0],s=s[1];return null!=(t=null==t?{}:t).defined&&!t.defined||(null==e&&(e=Math.max.apply(Math,this._data.map(function(t){return t.length}))),null==s&&(s=this._data.length)),{sc:o,ec:e,sr:n,er:s}},copy:function(){var t,i,o,e,n,s,r,l,h,d;if(this.les.start){for(t=[],o=(i=this._bound()).sc,e=i.ec,d=i.sr,n=i.er,s=d;s<=n;++s){for(r=[],l=o;l<=e;++l)h=l,"object"!=typeof(h=((i=this._data)[rpw]||(i[rpw]=[]))[h])&&r.push('"'+(""+h||"").replace(/"/g,'""')+'"');t.push(r.join("\t"))}return d=t.join("\n"),navigator.clipboard.writeText(d)}},eventInScope:function(t){return h(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(t){return null==t?this._size:(this._size={row:(t=e({row:[],col:[]},t)).row,col:t.col},this.regrid())},regrid:function(){var i=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){for(var t=[],i=0,o=this.frozen.col;i<o;++i)t.push(i);return t}.call(this).map(function(t){return i._size.col[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],i=this.xif.col[2],o=this.dim.col;i<o;++i)t.push(i);return t}.call(this).map(function(t){return i._size.col[t+i.pos.col-i.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){for(var t=[],i=0,o=this.frozen.row;i<o;++i)t.push(i);return t}.call(this).map(function(t){return i._size.row[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],i=this.xif.row[2],o=this.dim.row;i<o;++i)t.push(i);return t}.call(this).map(function(t){return i._size.row[t+i.pos.row-i.xif.row[1]]||"max-content"}).join(" ")},addCell:function(t,i){var o=document.createElement("div");return this.dom.inner.insertBefore(o,this.dom.inner.childNodes[i*this.dim.col+t]),this._content({x:t,y:i,n:o})},set:function(t){var i,o,e,n,s,r,l,h,d=t.row,c=t.col,a=t.data,t=t.range;if(t)for(o=0,e=a.length;o<e;++o)for(s=0,r=a[n=o].length;s<r;++s)l=s,((i=this._data)[h=n+d]||(i[h]=[]))[l+c]=a[n][l],this._content({y:n+d-this.pos.row+this.xif.row[1],x:l+c-this.pos.col+this.xif.col[1]});else((i=this._data)[d]||(i[d]=[]))[c]=a,this._content({y:d-this.pos.row+this.xif.row[1],x:c-this.pos.col+this.xif.col[1]});return this.fire("change",{row:d,col:c,data:a,range:!!t})},_content:function(t){var i,o,e=t.x,n=t.y,t=t.n;if(t=t||this.dom.inner.childNodes[e+n*this.dim.col])return i=(o=e<this.xif.col[0]&&n<this.xif.col[0]?["","cell idx"]:e<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]?[e<this.xif.col[1]?" ":e<this.xif.col[2]?s(e-this.xif.col[1]):s(e-this.xif.col[1]+this.pos.col),"cell idx"]:e<this.xif.col[1]||n<this.xif.row[1]?[null,"cell fixed"]:e<this.xif.col[2]&&n<this.xif.row[2]?[((o=this._data)[i=n-this.xif.row[1]]||(o[i]=[]))[e-this.xif.col[1]],"cell frozen fixed"]:e<this.xif.col[2]?[((o=this._data)[i=this.pos.row+n-this.xif.row[1]]||(o[i]=[]))[e-this.xif.col[1]],"cell frozen"]:n<this.xif.row[2]?[((o=this._data)[i=n-this.xif.row[1]]||(o[i]=[]))[this.pos.col+e-this.xif.col[1]],"cell frozen"]:[((o=this._data)[i=this.pos.row+n-this.xif.row[1]]||(o[i]=[]))[this.pos.col+e-this.xif.col[1]],"cell"])[0],o=o[1],null==i&&(i=""),n=e>=this.xif.col[0]&&n>=this.xif.row[0]?(this.cls.col[this.pos.col+e-this.xif.col[1]]||"")+" "+(this.cls.row[this.pos.row+n-this.xif.row[1]]||""):"",t.className=o+" "+n,null!==i?"object"!=typeof i?t.textContent=i:"dom"===i.type?(t.textContent="",t.appendChild(i.node)):void 0:void 0},_md:function(t){var i,o,e,n,s,r,l,h,d;for(null==t&&(t=1),i=this.dom.inner,e=o=0<(o=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))?o:0;e<t;++e)for(n=e,s=0,r=this.dim.col;s<r&&(l=s,h=this.dim.col*this.fix.row,i.childNodes[h]);++s)i.removeChild(i.childNodes[h]);for(e=o;e<t;++e)for(n=e,s=0,r=this.dim.col;s<r;++s)l=s,d=document.createElement("div"),this._content({x:l,y:this.dim.row+n,n:d}),i.appendChild(d);return this.pos.row+=t},_mu:function(t){var i,o,e,n,s,r,l,h,d,c,a=[];if(null==t&&(t=1),i=this.dom.inner,!(this.pos.row<=0)){for(n=o=0<(e=(t=(t=Math.round(Math.abs(t)))>=this.pos.row?this.pos.row:t)-(this.dim.row-this.xif.row[2]))?e:0;n<t;++n)for(s=n,r=0,l=this.dim.col;r<l&&(h=r,i.childNodes.length);++r)i.removeChild(i.childNodes[i.childNodes.length-1]);for(this.pos.row-=t,n=o;n<t;++n){for(s=n,d=[],r=0,l=this.dim.col;r<l;++r)h=r,c=document.createElement("div"),this._content({x:h,y:s+this.xif.row[2],n:c}),d.push(i.insertBefore(c,i.childNodes[h+(s-o)*this.dim.col+this.dim.col*this.xif.row[2]]));a.push(d)}return a}},_mr:function(t){var i,o,e,n,s,r,l,h;for(null==t&&(t=1),i=this.dom.inner,e=0<(o=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))?o:0;e<t;++e)for(n=e,s=0,r=this.dim.row;s<r;++s)l=s,i.removeChild(i.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+n,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,o,e,n,s,r,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(o=0<(e=t-(this.dim.col-this.xif.col[2]))?e:0,this.pos.col-=t,n=o;n<t;++n)for(s=n,r=0,l=this.dim.row;r<l;++r)h=r,i.removeChild(i.childNodes[(h+1)*this.dim.col-1]),d=document.createElement("div"),this._content({x:s+this.xif.col[2],y:h,n:d}),i.insertBefore(d,i.childNodes[h*this.dim.col+this.xif.col[2]+s-o]);return this.regrid()}},goto:function(t){return e(this.pos,t=null==t?{row:0,col:0}:t),this.render()},render:function(){for(var t,i,o,e,n,s=[],r=0,l=this.dim.row;r<l;++r){for(t=r,i=[],o=0,e=this.dim.col;o<e;++o)n=o,i.push(this._content({x:n,y:t}));s.push(i)}return s},move:function(t){var i,o,e,n;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(n=this.cell(t))){if(i=this.index(n),o=n.getBoundingClientRect(),e=this.dom.sheet.getBoundingClientRect(),o.x+o.width>e.x+e.width&&this._mr(1),o.y+o.height>e.y+e.height&&this._md(1),0===i.x){if(0===this.pos.col)return;this._ml(1)}if(0===i.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 i,o,e,n,s,r=t.node,l=t.quick;if(this._editing&&!(!(s=this.index(r))||s.col<0||s.row<0))return(i=this.editing).node=r,i.quick=l,i.on=!0,this.dom.layout.textContent=r.textContent,o=this.dom.layout.getBoundingClientRect(),e=r.getBoundingClientRect(),n=this.dom.sheet.getBoundingClientRect(),t=(i=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],s=i[1],(i=this.dom.edit.style).left=e.x-n.x+t-2+"px",i.top=e.y-n.y+s-2+"px",i.width="fit-content",i.height="fit-content",this.dom.edit.classList.toggle("show",!0),(i=this.dom.textarea.style).width=Math.max(o.width,e.width+1)+"px",i.height=Math.max(o.height,e.height+1)+"px",this.dom.textarea.value=r=!l&&r.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(r.length,r.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 i=Array.from(this.dom.inner.childNodes).indexOf(t);return i<0?null:{x:t=i%this.dim.col,y:i=(i-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:i<this.xif.row[1]?-1:i<this.xif.row[2]?i-this.xif.row[1]:i-this.xif.row[1]+this.pos.row}},cell:function(t){var i,o,e;if(null!=(t=null==t?{}: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)o=t.row;else{if(t.row-this.pos.row<this.frozen.row)return null;o=t.row-this.pos.row}return o=(e=[i+this.xif.col[1],o+this.xif.row[1]])[1],(i=e[0])<0||o<0||i>=this.dim.col||o>=this.dim.row?null:this.dom.inner.childNodes[o*this.dim.col+i]}if(!(e=t.node?this.index(t.node):{y:0,x:0}))throw new Error("node not found in sheet");return o=e.y+(t.y||0),i=e.x+(t.x||0),this.dom.inner.childNodes[o*this.dim.col+i]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(){var t,i,o,e,n,s,r,l,h,d;if(this.les.start)return n=(t=this._bound({defined:!1})).sc,i=t.ec,s=t.sr,d=t.er,o=this.dom.inner.getBoundingClientRect(),h=(t=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:n,row:s}),this.cell({col:n,row:d}),this.cell({col:i,row:s}),this.cell({col:i,row:d})].map(function(t){return t?t.getBoundingClientRect():null}))[0],r=t[1],e=t[2],l=t[3],n=t[4],h.width=0,h.height=0,s=(r||e||h).x-o.x,r=(r||l||h).y-o.y,l=(l||n||h).x+(l||n||h).width-o.x-s+1,h=(e||n||h).y+(e||n||h).height-o.y-r+1,null==i&&(l=this.root.getBoundingClientRect().width),null==d&&(h=this.root.getBoundingClientRect().height),d=(d=this.cell(this.les.start))?d.getBoundingClientRect():null,(t=this.dom.range.style).left=s+"px",t.top=r+"px",t.width=l+"px",t.height=h+"px",this.dom.range.classList.toggle("show",!0),d&&((t=this.dom.caret.style).left=d.x-o.x-1+"px",t.top=d.y-o.y-1+"px",t.width=d.width+2+"px",t.height=d.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",!!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);
1
+ !function(){var a,u,r,t;function o(t,e){var i,o={}.hasOwnProperty;for(i in e)o.call(e,i)&&(t[i]=e[i]);return t}a=function(t){return Papa.parse(t).data},u=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,f=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(f.edited(),e=u(t.target,".cell",d))return(o={row:(i=f.index(e)).row,col:i.col}).col<0||o.row<0?(t.shiftKey&&f.les.start||(f.les.node=f.cell(f.les.start),f.les.start={col:0<(i=o.col)?i:0,row:0<(i=o.row)?i:0}),f.les.end={col:0<=o.col?o.col:void 0,row:0<=o.row?o.row:void 0},void f.renderSelection()):(t.shiftKey&&f.les.start?f.les.end=o:(f.les.start=f.les.end=o,f.les.node=e),f.renderSelection())}),d.addEventListener("mousemove",function(t){var e;if(!f.editing.on&&t.buttons&&(e=u(t.target,".cell",d)))return e={row:(e=f.index(e)).row,col:e.col},f.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},f.renderSelection()}),d.addEventListener("dblclick",function(t){if(t=u(t.target,".cell",d))return f.edit({node:t,quick:!1})}),document.body.addEventListener("paste",function(t){var e,i,o,n,r,s,l,h,c;if(u(document.activeElement,".sheet",d)&&f.les.start&&(n=t.clipboardData.getData("text"),e=a(n),f.set({row:f.les.start.row,col:f.les.start.col,data:e,range:!0}),f.sel.cut)){if(f._toText({sel:f.sel.cut})===n){for(i=(e=f._bound({sel:f.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,f.set({row:l,col:c,data:""});navigator.clipboard.writeText("")}return f.sel.cut=null,f.dom["range-cut"].classList.toggle("show",!1)}}),d.addEventListener("keydown",function(t){var e,i,o,n,r,s,l,h,c,d,a,u=t.keyCode;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return f.copy();if(88===t.keyCode&&(t.metaKey||t.ctrlKey))return f.copy({cut:!0});if(f.eventInScope(t)){if(8===u){if(!f.les.node)return;for(e=f._bound(),i=e.sc,o=e.ec,n=e.sr,r=e.er,l=[],h=n;h<=r;++h){for(c=[],d=i;d<=o;++d)c.push("");l.push(c)}s=l,f.set({row:n,col:i,data:s,range:!0})}return 189===u&&(t.metaKey||t.ctrlKey)?f.les.node?(e=f._bound({defined:!1}),i=e.sc,o=e.ec,n=e.sr,r=e.er,null==o&&(a=f._data.splice(n,r-n+1)),null==r&&(a=f._data.map(function(t){return t.splice(i,o-i+1)})),f.fire("change",{row:n,col:i,data:a,range:!0}),f.les.end=f.les.start,f.renderSelection(),void f.render()):void 0:!(a=function(){switch(u){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}}())||f.editing.on&&!f.editing.quick?void 0:(f.move(a),t.stopPropagation(),t.preventDefault(),f.dom.sheet.focus())}}),d.addEventListener("keypress",function(t){if(31!==t.keyCode||!t.metaKey&&!t.ctrlKey)return f.les.node&&!f.editing.on?f.edit({node:f.les.node,quick:13!==t.keyCode}):void 0}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o;return 27===t.keyCode?(f.edited({cancel:!0}),t.stopPropagation(),t.preventDefault(),void f.dom.sheet.focus()):13!==t.keyCode||t.altKey||t.metaKey?13===t.keyCode&&(t.altKey||t.metaKey)?(f.dom.textarea.value+="\n",f.dom.layout.textContent=f.dom.textarea.value+" ",e=f.dom.layout.getBoundingClientRect(),i=f.editing.node.getBoundingClientRect(),(o=f.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:(f.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void f.dom.sheet.focus())}),document.addEventListener("wheel",function(t){var e,i,o,n,r=f.eventInScope(t);return(null==f.opt.scrollLock||f.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!r&&t.target!==document.body||t.preventDefault()),!!r&&(e=f.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))?f._md(o):o<0?f._mu(o):0<i?f._mr(i):i<0&&f._ml(i),f.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 u(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.3.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"]}}
1
+ {"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.4.1","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"]}}