@plotdb/sheet 0.1.4 → 0.1.8
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/README.md +35 -1
- package/dist/index.css +1 -0
- package/dist/index.js +48 -15
- package/dist/index.min.css +1 -1
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,13 +41,15 @@ initialize:
|
|
|
41
41
|
- `idx`: {row, col}. default {row: true, col: true}
|
|
42
42
|
- `size`: {row, col}. force cell size, in array by order.
|
|
43
43
|
- default: {row: [], col: []}
|
|
44
|
+
- `class`: {row, col}. additional cell class name, in array by order, as space separated string.
|
|
45
|
+
- default: {row: [], col: []}
|
|
44
46
|
- `editing`: false to disable editing. default true.
|
|
45
47
|
- (TBD) in the future we should be able to:
|
|
46
48
|
- set edit permission ( e.g., edit, comment )
|
|
47
49
|
- apply on range
|
|
48
50
|
- `scrollLock`: default true. prevent from horizontal scrolling of document.body if true.
|
|
49
51
|
- this affects how user interact with sheet with scrolling gestures. check src comment for more information.
|
|
50
|
-
|
|
52
|
+
- `data`: initial data, as array of arrays
|
|
51
53
|
|
|
52
54
|
## API
|
|
53
55
|
|
|
@@ -58,6 +60,8 @@ initialize:
|
|
|
58
60
|
- `editing(v)`: set edit status to v, or return edit status if v is not provided.
|
|
59
61
|
- `data(d)`: replace data completely with `d` and re-render.
|
|
60
62
|
- return current data if `d` is omitted.
|
|
63
|
+
- `d` is in the same format with the constructor `data` option
|
|
64
|
+
- `size({row, col})`: update grid size.
|
|
61
65
|
|
|
62
66
|
|
|
63
67
|
## Event
|
|
@@ -78,6 +82,36 @@ Following are a list of possible events:
|
|
|
78
82
|
- `data`: data used to update. If it's a 2D array and `range` is true, then cells are updated with values in `data` correspondingly relative to `row` and `col` as the original cell
|
|
79
83
|
- `range`: true if a range of cells are updated.
|
|
80
84
|
|
|
85
|
+
## Rich Text
|
|
86
|
+
|
|
87
|
+
You can add more than texts in the grid of the sheet, by having an object with following structure in data:
|
|
88
|
+
|
|
89
|
+
{
|
|
90
|
+
type: "data-type",
|
|
91
|
+
... /* members according to type */
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Currently, only `node` type is supported:
|
|
95
|
+
|
|
96
|
+
{ type: "dom", node: SomeElement }
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# Swipe Back Issue
|
|
100
|
+
|
|
101
|
+
On Chrome in Mac, scrolling left with trackpad with two finger gesture may also triggers swipe back action, which navigate the page back in browsing history. This happens in all websites needing similar actions, including Airtable and Google Spreadsheet.
|
|
102
|
+
|
|
103
|
+
This may be temporarily solved by setting `overscroll-behavior` to `contain` of the sheet container, however - if swipe back happens once anywhere outside the sheet container, it then always triggered even in sheet container.
|
|
104
|
+
|
|
105
|
+
If this happens, try setting `overscroll-behavior` to `contain` directly on `body` to see if it may solve this issue.
|
|
106
|
+
|
|
107
|
+
Reference:
|
|
108
|
+
|
|
109
|
+
- https://bugs.chromium.org/p/chromium/issues/detail?id=889846
|
|
110
|
+
- https://bugs.chromium.org/p/chromium/issues/detail?id=862693
|
|
111
|
+
- https://bugs.chromium.org/p/chromium/issues/detail?id=906886
|
|
112
|
+
- https://community.airtable.com/t/3074
|
|
113
|
+
|
|
114
|
+
|
|
81
115
|
|
|
82
116
|
## License
|
|
83
117
|
|
package/dist/index.css
CHANGED
package/dist/index.js
CHANGED
|
@@ -65,13 +65,20 @@
|
|
|
65
65
|
: opt.root;
|
|
66
66
|
this.evtHandler = {};
|
|
67
67
|
this._data = opt.data || [];
|
|
68
|
-
this.
|
|
68
|
+
this._size = {
|
|
69
69
|
row: (ref$ = import$({
|
|
70
70
|
row: [],
|
|
71
71
|
col: []
|
|
72
72
|
}, opt.size)).row,
|
|
73
73
|
col: ref$.col
|
|
74
74
|
};
|
|
75
|
+
this.cls = {
|
|
76
|
+
row: (ref$ = import$({
|
|
77
|
+
row: [],
|
|
78
|
+
col: []
|
|
79
|
+
}, opt['class'])).row,
|
|
80
|
+
col: ref$.col
|
|
81
|
+
};
|
|
75
82
|
this._editing = opt.editing != null ? !!opt.editing : true;
|
|
76
83
|
this.dim = {
|
|
77
84
|
col: (opt.dim || (opt.dim = {})).col || 30,
|
|
@@ -369,7 +376,7 @@
|
|
|
369
376
|
});
|
|
370
377
|
},
|
|
371
378
|
copy: function(){
|
|
372
|
-
var c, i$, to$, row, r, j$, to1$, col, ref$, s;
|
|
379
|
+
var c, i$, to$, row, r, j$, to1$, col, content, ref$, s;
|
|
373
380
|
if (!this.les.start) {
|
|
374
381
|
return;
|
|
375
382
|
}
|
|
@@ -379,7 +386,11 @@
|
|
|
379
386
|
r = [];
|
|
380
387
|
for (j$ = this.les.start.col, to1$ = this.les.end.col + 1; j$ < to1$; ++j$) {
|
|
381
388
|
col = j$;
|
|
382
|
-
|
|
389
|
+
content = ((ref$ = this._data)[rpw] || (ref$[rpw] = []))[col];
|
|
390
|
+
if (typeof content === 'object') {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
r.push('"' + ('' + content || '').replace(/"/g, '""') + '"');
|
|
383
394
|
}
|
|
384
395
|
c.push(r.join('\t'));
|
|
385
396
|
}
|
|
@@ -389,6 +400,20 @@
|
|
|
389
400
|
eventInScope: function(e){
|
|
390
401
|
return parent(e.target, '.sheet', this.dom.sheet) === this.dom.sheet;
|
|
391
402
|
},
|
|
403
|
+
size: function(it){
|
|
404
|
+
var ref$;
|
|
405
|
+
if (it == null) {
|
|
406
|
+
return this._size;
|
|
407
|
+
}
|
|
408
|
+
this._size = {
|
|
409
|
+
row: (ref$ = import$({
|
|
410
|
+
row: [],
|
|
411
|
+
col: []
|
|
412
|
+
}, it)).row,
|
|
413
|
+
col: ref$.col
|
|
414
|
+
};
|
|
415
|
+
return this.regrid();
|
|
416
|
+
},
|
|
392
417
|
regrid: function(){
|
|
393
418
|
var this$ = this;
|
|
394
419
|
this.dom.inner.style.gridTemplateColumns = ("repeat(" + this.xif.col[1] + ", max-content) ") + (function(){
|
|
@@ -398,7 +423,7 @@
|
|
|
398
423
|
}
|
|
399
424
|
return results$;
|
|
400
425
|
}.call(this)).map(function(it){
|
|
401
|
-
return this$.
|
|
426
|
+
return this$._size.col[it] || "max-content";
|
|
402
427
|
}).join(' ') + ' ' + (function(){
|
|
403
428
|
var i$, to$, results$ = [];
|
|
404
429
|
for (i$ = this.xif.col[2], to$ = this.dim.col; i$ < to$; ++i$) {
|
|
@@ -406,7 +431,7 @@
|
|
|
406
431
|
}
|
|
407
432
|
return results$;
|
|
408
433
|
}.call(this)).map(function(it){
|
|
409
|
-
return this$.
|
|
434
|
+
return this$._size.col[it + this$.pos.col - this$.xif.col[1]] || "max-content";
|
|
410
435
|
}).join(' ');
|
|
411
436
|
return this.dom.inner.style.gridTemplateRows = ("repeat(" + this.xif.row[1] + ", max-content) ") + (function(){
|
|
412
437
|
var i$, to$, results$ = [];
|
|
@@ -415,7 +440,7 @@
|
|
|
415
440
|
}
|
|
416
441
|
return results$;
|
|
417
442
|
}.call(this)).map(function(it){
|
|
418
|
-
return this$.
|
|
443
|
+
return this$._size.row[it] || "max-content";
|
|
419
444
|
}).join(' ') + ' ' + (function(){
|
|
420
445
|
var i$, to$, results$ = [];
|
|
421
446
|
for (i$ = this.xif.row[2], to$ = this.dim.row; i$ < to$; ++i$) {
|
|
@@ -423,7 +448,7 @@
|
|
|
423
448
|
}
|
|
424
449
|
return results$;
|
|
425
450
|
}.call(this)).map(function(it){
|
|
426
|
-
return this$.
|
|
451
|
+
return this$._size.row[it + this$.pos.row - this$.xif.row[1]] || "max-content";
|
|
427
452
|
}).join(' ');
|
|
428
453
|
},
|
|
429
454
|
addCell: function(x, y){
|
|
@@ -466,7 +491,7 @@
|
|
|
466
491
|
});
|
|
467
492
|
},
|
|
468
493
|
_content: function(arg$){
|
|
469
|
-
var x, y, n, v, ref$, key$,
|
|
494
|
+
var x, y, n, v, ref$, key$, content, className, clsext;
|
|
470
495
|
x = arg$.x, y = arg$.y, n = arg$.n;
|
|
471
496
|
if (!n && !(n = this.dom.inner.childNodes[x + y * this.dim.col])) {
|
|
472
497
|
return;
|
|
@@ -495,13 +520,21 @@
|
|
|
495
520
|
? [((ref$ = this._data)[key$ = this.pos.row + y - this.xif.row[1]] || (ref$[key$] = []))[x - this.xif.col[1]], "cell frozen"]
|
|
496
521
|
: y < this.xif.row[2]
|
|
497
522
|
? [((ref$ = this._data)[key$ = y - this.xif.row[1]] || (ref$[key$] = []))[this.pos.col + x - this.xif.col[1]], "cell frozen"]
|
|
498
|
-
: [((ref$ = this._data)[key$ = this.pos.row + y - this.xif.row[1]] || (ref$[key$] = []))[this.pos.col + x - this.xif.col[1]], "cell"],
|
|
499
|
-
if (!(
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
523
|
+
: [((ref$ = this._data)[key$ = this.pos.row + y - this.xif.row[1]] || (ref$[key$] = []))[this.pos.col + x - this.xif.col[1]], "cell"], content = ref$[0], className = ref$[1];
|
|
524
|
+
if (!(content != null)) {
|
|
525
|
+
content = "";
|
|
526
|
+
}
|
|
527
|
+
clsext = x >= this.xif.col[0] && y >= this.xif.row[0] ? (this.cls.col[this.pos.col + x - this.xif.col[1]] || '') + ' ' + (this.cls.row[this.pos.row + y - this.xif.row[1]] || '') : '';
|
|
528
|
+
n.className = className + ' ' + clsext;
|
|
529
|
+
if (content !== null) {
|
|
530
|
+
if (typeof content === 'object') {
|
|
531
|
+
if (content.type === 'dom') {
|
|
532
|
+
n.textContent = "";
|
|
533
|
+
return n.appendChild(content.node);
|
|
534
|
+
}
|
|
535
|
+
} else {
|
|
536
|
+
return n.textContent = content;
|
|
537
|
+
}
|
|
505
538
|
}
|
|
506
539
|
},
|
|
507
540
|
_md: function(mag){
|
package/dist/index.min.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.sheet{position:relative;width:100%;height:100%;overflow:hidden;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{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}
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var parseCsv,parent,idxToLabel,labelToIdx,sheet;parseCsv=function(txt){return Papa.parse(txt).data};parent=function(n,s,e){var m;m=n;while(n&&n!==e){n=n.parentNode}if(n!==e){return null}if(!s){return n}n=m;while(n&&n!==e&&(!n.matches||n.matches&&!n.matches(s))){n=n.parentNode}if(n===e&&(!e.matches||!e.matches(s))){return null}return n};idxToLabel=function(val){var radix,base,v,map,ret,i$,i,c;radix=Math.floor(Math.log((val+1)*25+1)/Math.log(26))-1;base=(Math.pow(26,radix+1)-1)/25-1;v=val-base;map="ABCDEFGHIJKLMNOPQRSTUVWXYZ";ret="";for(i$=0;i$<=radix;++i$){i=i$;c=map.charAt(v%26);ret=c+ret;v=(v-v%26)/26}return ret};labelToIdx=function(label){var radix,base,map,val,i$,i,idx;radix=label.length-1;base=(Math.pow(26,radix+1)-1)/25-1;map="ABCDEFGHIJKLMNOPQRSTUVWXYZ";val=0;for(i$=0;i$<=radix;++i$){i=i$;idx=map.indexOf(label[i]);if(idx<0){throw new Error("incorrect label")}val=val*26+idx}return val+base};sheet=function(opt){var ref$,this$=this;opt==null&&(opt={});this.opt=opt;this.root=typeof opt.root==="string"?document.querySelector(opt.root):opt.root;this.evtHandler={};this._data=opt.data||[];this.size={row:(ref$=import$({row:[],col:[]},opt.size)).row,col:ref$.col};this._editing=opt.editing!=null?!!opt.editing:true;this.dim={col:(opt.dim||(opt.dim={})).col||30,row:(opt.dim||(opt.dim={})).row||30};this.frozen={col:(ref$=import$({col:0,row:0},opt.frozen||{})).col,row:ref$.row};this.idx={col:(ref$=import$({row:true,col:true},opt.idx||{})).col,row:ref$.row};this.fixed={col:(ref$=import$({col:0,row:0},opt.fixed||{})).col,row:ref$.row};this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]};["row","col"].map(function(t){this$.xif[t][1]=this$.xif[t][0]+this$.fixed[t];return this$.xif[t][2]=this$.xif[t][1]+this$.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(it){var x$,n;x$=n=document.createElement("div");x$.classList.add(it);return[it,n]}));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(it){return this$.dom.sheet.appendChild(this$.dom[it])});this.dom.edit.appendChild(this.dom.textarea);this._init();return this};sheet.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var ref$;return((ref$=this.evtHandler)[n]||(ref$[n]=[])).push(cb)},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},_init:function(){var i$,to$,r,j$,to1$,c,dom,this$=this;for(i$=0,to$=this.dim.row;i$<to$;++i$){r=i$;for(j$=0,to1$=this.dim.col;j$<to1$;++j$){c=j$;this.addCell(c,r)}}this.regrid();this.dom.textarea.addEventListener("mousedown",function(e){return e.stopPropagation()});dom=this.dom.sheet;dom.addEventListener("mousedown",function(e){var p,ref$,idx;this$.edited();if(!(p=parent(e.target,".cell",dom))){return}idx={row:(ref$=this$.index(p)).row,col:ref$.col};if(idx.col<0||idx.row<0){return}this$.les.start=this$.les.end=idx;this$.les.node=p;return this$.renderSelection()});dom.addEventListener("mousemove",function(e){var p,ref$;if(this$.editing.on||!(e.buttons&&(p=parent(e.target,".cell",dom)))){return}this$.les.end={row:(ref$=this$.index(p)).row,col:ref$.col};return this$.renderSelection()});dom.addEventListener("dblclick",function(e){var p;if(!(p=parent(e.target,".cell",dom))){return}return this$.edit({node:p,quick:false})});document.body.addEventListener("paste",function(e){var data;if(!parent(document.activeElement,".sheet",dom)){return}if(!this$.les.start){return}data=e.clipboardData.getData("text");data=parseCsv(data);return this$.set({row:this$.les.start.row,col:this$.les.start.col,data:data,range:true})});dom.addEventListener("keydown",function(e){var code,ref$,p1,p2,c1,c2,r1,r2,i$,row,j$,col,opt;if(e.keyCode===67&&(e.metaKey||e.ctrlKey)){return this$.copy()}if(!this$.eventInScope(e)){return}code=e.keyCode;if(code===8){if(!this$.les.node){return}ref$=[this$.les.start,this$.les.end],p1=ref$[0],p2=ref$[1];ref$=p1.col<p2.col?[p1.col,p2.col]:[p2.col,p1.col],c1=ref$[0],c2=ref$[1];ref$=p1.row<p2.row?[p1.row,p2.row]:[p2.row,p1.row],r1=ref$[0],r2=ref$[1];for(i$=r1;i$<=r2;++i$){row=i$;for(j$=c1;j$<=c2;++j$){col=j$;this$.set({row:row,col:col,data:""})}}}opt=function(){switch(code){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}}();if(!opt){return}if(this$.editing.on&&!this$.editing.quick){return}this$.move(opt);e.stopPropagation();e.preventDefault();return this$.dom.sheet.focus()});dom.addEventListener("keypress",function(e){if(this$.les.node&&!this$.editing.on){return this$.edit({node:this$.les.node,quick:e.keyCode===13?false:true})}});this.dom.textarea.addEventListener("keydown",function(e){var lbox,box,ref$;if(e.keyCode===27){this$.edited({cancel:true});e.stopPropagation();e.preventDefault();this$.dom.sheet.focus();return}if(e.keyCode===13&&!(e.altKey||e.metaKey)){this$.move({y:1,x:0});e.stopPropagation();e.preventDefault();this$.dom.sheet.focus();return}if(e.keyCode===13&&(e.altKey||e.metaKey)){this$.dom.textarea.value+="\n";this$.dom.layout.textContent=this$.dom.textarea.value+" ";lbox=this$.dom.layout.getBoundingClientRect();box=this$.editing.node.getBoundingClientRect();return ref$=this$.dom.textarea.style,ref$.width=Math.max(lbox.width,box.width+1)+"px",ref$.height=Math.max(lbox.height,box.height+1)+"px",ref$}});return document.addEventListener("wheel",function(e){var inscope,spos,ref$,dx,dy,ox,oy;inscope=this$.eventInScope(e);if(!(this$.opt.scrollLock!=null)||this$.opt.scrollLock){if(Math.abs(e.deltaX)>Math.abs(e.deltaY)){if(inscope||e.target===document.body){e.preventDefault()}}}if(!inscope){return false}spos=this$.scrollPos;ref$=[e.deltaX,e.deltaY],dx=ref$[0],dy=ref$[1];ref$=Math.abs(dx)>Math.abs(dy)?[dx,0]:[0,dy],dx=ref$[0],dy=ref$[1];ref$=[spos.x,spos.y],ox=ref$[0],oy=ref$[1];spos.x+=dx/30;spos.y+=dy/30;dx=Math.round(spos.x)-Math.round(ox);dy=Math.round(spos.y)-Math.round(oy);if(dy>0){this$._md(dy)}else if(dy<0){this$._mu(dy)}else if(dx>0){this$._mr(dx)}else if(dx<0){this$._ml(dx)}this$.renderSelection();return e.preventDefault()},{passive:false})},copy:function(){var c,i$,to$,row,r,j$,to1$,col,ref$,s;if(!this.les.start){return}c=[];for(i$=this.les.start.row,to$=this.les.end.row+1;i$<to$;++i$){row=i$;r=[];for(j$=this.les.start.col,to1$=this.les.end.col+1;j$<to1$;++j$){col=j$;r.push('"'+(""+((ref$=this._data)[row]||(ref$[row]=[]))[col]||"").replace(/"/g,'""')+'"')}c.push(r.join("\t"))}s=c.join("\n");return navigator.clipboard.writeText(s)},eventInScope:function(e){return parent(e.target,".sheet",this.dom.sheet)===this.dom.sheet},regrid:function(){var this$=this;this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){var i$,to$,results$=[];for(i$=0,to$=this.frozen.col;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$.size.col[it]||"max-content"}).join(" ")+" "+function(){var i$,to$,results$=[];for(i$=this.xif.col[2],to$=this.dim.col;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$.size.col[it+this$.pos.col-this$.xif.col[1]]||"max-content"}).join(" ");return this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){var i$,to$,results$=[];for(i$=0,to$=this.frozen.row;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$.size.row[it]||"max-content"}).join(" ")+" "+function(){var i$,to$,results$=[];for(i$=this.xif.row[2],to$=this.dim.row;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$.size.row[it+this$.pos.row-this$.xif.row[1]]||"max-content"}).join(" ")},addCell:function(x,y){var div;div=document.createElement("div");this.dom.inner.insertBefore(div,this.dom.inner.childNodes[y*this.dim.col+x]);return this._content({x:x,y:y,n:div})},set:function(arg$){var row,col,data,range,ref$,i$,to$,r,j$,to1$,c,key$;row=arg$.row,col=arg$.col,data=arg$.data,range=arg$.range;if(!range){((ref$=this._data)[row]||(ref$[row]=[]))[col]=data;this._content({y:row-this.pos.row+this.xif.row[1],x:col-this.pos.col+this.xif.col[1]})}else{for(i$=0,to$=data.length;i$<to$;++i$){r=i$;for(j$=0,to1$=data[r].length;j$<to1$;++j$){c=j$;((ref$=this._data)[key$=r+row]||(ref$[key$]=[]))[c+col]=data[r][c];this._content({y:r+row-this.pos.row+this.xif.row[1],x:c+col-this.pos.col+this.xif.col[1]})}}}return this.fire("change",{row:row,col:col,data:data,range:!!range})},_content:function(arg$){var x,y,n,v,ref$,key$,textContent,className;x=arg$.x,y=arg$.y,n=arg$.n;if(!n&&!(n=this.dom.inner.childNodes[x+y*this.dim.col])){return}ref$=x<this.xif.col[0]&&y<this.xif.col[0]?["","cell idx"]:x<this.xif.col[0]?(v=y<this.xif.row[1]?" ":y<this.xif.row[2]?y-this.xif.row[1]+1:y-this.xif.row[1]+this.pos.row+1,[v,"cell idx"]):y<this.xif.row[0]?(v=x<this.xif.col[1]?" ":x<this.xif.col[2]?idxToLabel(x-this.xif.col[1]):idxToLabel(x-this.xif.col[1]+this.pos.col),[v,"cell idx"]):x<this.xif.col[1]?[null,"cell fixed"]:y<this.xif.row[1]?[null,"cell fixed"]:x<this.xif.col[2]&&y<this.xif.row[2]?[((ref$=this._data)[key$=y-this.xif.row[1]]||(ref$[key$]=[]))[x-this.xif.col[1]],"cell frozen fixed"]:x<this.xif.col[2]?[((ref$=this._data)[key$=this.pos.row+y-this.xif.row[1]]||(ref$[key$]=[]))[x-this.xif.col[1]],"cell frozen"]:y<this.xif.row[2]?[((ref$=this._data)[key$=y-this.xif.row[1]]||(ref$[key$]=[]))[this.pos.col+x-this.xif.col[1]],"cell frozen"]:[((ref$=this._data)[key$=this.pos.row+y-this.xif.row[1]]||(ref$[key$]=[]))[this.pos.col+x-this.xif.col[1]],"cell"],textContent=ref$[0],className=ref$[1];if(!(textContent!=null)){textContent=""}n.className=className;if(textContent!==null){return n.textContent=textContent}},_md:function(mag){var inner,start,ref$,i$,j,j$,to$,i,idx,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));start=(ref$=mag-(this.dim.row-this.fix.row))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;idx=this.dim.col*this.fix.row;if(!inner.childNodes[idx]){break}inner.removeChild(inner.childNodes[idx])}}for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;n=document.createElement("div");this._content({x:i,y:this.dim.row+j,n:n});inner.appendChild(n)}}return this.pos.row+=mag},_mu:function(mag){var inner,start,ref$,i$,j,j$,to$,i,lresult$,n,results$=[];mag==null&&(mag=1);inner=this.dom.inner;if(this.pos.row<=0){return}mag=Math.round(Math.abs(mag));if(mag>=this.pos.row){mag=this.pos.row}start=(ref$=mag-(this.dim.row-this.xif.row[2]))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;if(!inner.childNodes.length){break}inner.removeChild(inner.childNodes[inner.childNodes.length-1])}}this.pos.row-=mag;for(i$=start;i$<mag;++i$){j=i$;lresult$=[];for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;n=document.createElement("div");this._content({x:i,y:j+this.xif.row[2],n:n});lresult$.push(inner.insertBefore(n,inner.childNodes[i+(j-start)*this.dim.col+this.dim.col*this.xif.row[2]]))}results$.push(lresult$)}return results$},_mr:function(mag){var inner,start,ref$,i$,j,j$,to$,i,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));start=(ref$=mag-(this.dim.col-this.fix.col))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.row;j$<to$;++j$){i=j$;inner.removeChild(inner.childNodes[i*this.dim.col+this.fix.col]);n=document.createElement("div");this._content({x:this.dim.col+j,y:i,n:n});inner.insertBefore(n,inner.childNodes[(i+1)*this.dim.col-1])}}this.pos.col+=mag;return this.regrid()},_ml:function(mag){var inner,start,ref$,i$,j,j$,to$,i,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));if(mag>=this.pos.col){mag=this.pos.col}if(this.pos.col<=0||mag<=0){return}start=(ref$=mag-(this.dim.col-this.xif.col[2]))>0?ref$:0;this.pos.col-=mag;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.row;j$<to$;++j$){i=j$;inner.removeChild(inner.childNodes[(i+1)*this.dim.col-1]);n=document.createElement("div");this._content({x:j+this.xif.col[2],y:i,n:n});inner.insertBefore(n,inner.childNodes[i*this.dim.col+this.xif.col[2]+j-start])}}return this.regrid()},goto:function(opt){opt==null&&(opt={row:0,col:0});import$(this.pos,opt);return this.render()},render:function(){var i$,to$,y,lresult$,j$,to1$,x,results$=[];for(i$=0,to$=this.dim.row;i$<to$;++i$){y=i$;lresult$=[];for(j$=0,to1$=this.dim.col;j$<to1$;++j$){x=j$;lresult$.push(this._content({x:x,y:y}))}results$.push(lresult$)}return results$},move:function(opt){var node,idx,box,sbox,ref$;opt==null&&(opt={});if(this.editing.on){this.edited()}if(!(opt.node=this.les.node)){return}if(!(node=this.cell(opt))){return}idx=this.index(node);box=node.getBoundingClientRect();sbox=this.dom.sheet.getBoundingClientRect();if(box.x+box.width>sbox.x+sbox.width){this._mr(1)}if(box.y+box.height>sbox.y+sbox.height){this._md(1)}if(idx.x===0){if(this.pos.col===0){return}else{this._ml(1)}}if(idx.y===0){if(this.pos.row===0){return}else{this._mu(1)}}if(!(node=this.cell(opt))){return}this.les.node=node;this.les.start=this.les.end={col:(ref$=this.index(node)).col,row:ref$.row};return this.renderSelection()},edit:function(arg$){var node,quick,idx,ref$,lbox,box,rbox,sx,sy,v;node=arg$.node,quick=arg$.quick;if(!this._editing){return}idx=this.index(node);if(!idx||idx.col<0||idx.row<0){return}ref$=this.editing;ref$.node=node;ref$.quick=quick;ref$.on=true;this.dom.layout.textContent=node.textContent;lbox=this.dom.layout.getBoundingClientRect();box=node.getBoundingClientRect();rbox=this.dom.sheet.getBoundingClientRect();ref$=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop],sx=ref$[0],sy=ref$[1];ref$=this.dom.edit.style;ref$.left=box.x-rbox.x+sx-2+"px";ref$.top=box.y-rbox.y+sy-2+"px";ref$.width="fit-content";ref$.height="fit-content";this.dom.edit.classList.toggle("show",true);ref$=this.dom.textarea.style;ref$.width=Math.max(lbox.width,box.width+1)+"px";ref$.height=Math.max(lbox.height,box.height+1)+"px";this.dom.textarea.value=v=quick?"":node.textContent||"";this.dom.textarea.focus();return this.dom.textarea.setSelectionRange(v.length,v.length)},edited:function(opt){var v,ref$;opt==null&&(opt={});if(!this.editing.on){return}if(!opt.cancel){this.set({row:this.les.start.row,col:this.les.start.col,data:v=this.dom.textarea.value||""})}this.dom.edit.classList.toggle("show",false);return ref$=this.editing,ref$.node=null,ref$.on=false,ref$},index:function(node){var idx,x,y,col,row;idx=Array.from(this.dom.inner.childNodes).indexOf(node);if(idx<0){return null}x=idx%this.dim.col;y=(idx-x)/this.dim.col;if(x<this.xif.col[1]){col=-1}else if(x<this.xif.col[2]){col=x-this.xif.col[1]}else{col=x-this.xif.col[1]+this.pos.col}if(y<this.xif.row[1]){row=-1}else if(y<this.xif.row[2]){row=y-this.xif.row[1]}else{row=y-this.xif.row[1]+this.pos.row}return{x:x,y:y,col:col,row:row}},cell:function(opt){var x,y,ref$,base;opt==null&&(opt={});if(opt.col!=null){if(opt.col<this.frozen.col){x=opt.col}else if(opt.col-this.pos.col<this.frozen.col){return null}else{x=opt.col-this.pos.col}if(opt.row<this.frozen.row){y=opt.row}else if(opt.row-this.pos.row<this.frozen.row){return null}else{y=opt.row-this.pos.row}ref$=[x+this.xif.col[1],y+this.xif.row[1]],x=ref$[0],y=ref$[1];if(x<0||y<0||x>=this.dim.col||y>=this.dim.row){return null}return this.dom.inner.childNodes[y*this.dim.col+x]}else{base=opt.node?this.index(opt.node):{y:0,x:0};if(!base){throw new Error("node not found in sheet")}y=base.y+(opt.y||0);x=base.x+(opt.x||0);return this.dom.inner.childNodes[y*this.dim.col+x]}},editing:function(v){return!(v!=null)?this._editing:this._editing=!!v},renderSelection:function(){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;if(!this.les.start){return}ref$=this.les.start.col<this.les.end.col?[this.les.start.col,this.les.end.col]:[this.les.end.col,this.les.start.col],sc=ref$[0],ec=ref$[1];ref$=this.les.start.row<this.les.end.row?[this.les.start.row,this.les.end.row]:[this.les.end.row,this.les.start.row],sr=ref$[0],er=ref$[1];rbox=this.dom.inner.getBoundingClientRect();c0=this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row});c1=this.cell({col:sc,row:sr});c2=this.cell({col:sc,row:er});c3=this.cell({col:ec,row:sr});c4=this.cell({col:ec,row:er});ref$=[c0,c1,c2,c3,c4].map(function(it){if(it){return it.getBoundingClientRect()}else{return null}}),b0=ref$[0],b1=ref$[1],b2=ref$[2],b3=ref$[3],b4=ref$[4];b0.width=0;b0.height=0;x1=(b1||b2||b0).x-rbox.x;y1=(b1||b3||b0).y-rbox.y;x2=(b3||b4||b0).x+(b3||b4||b0).width-rbox.x;y2=(b2||b4||b0).y+(b2||b4||b0).height-rbox.y;w=x2-x1+1;h=y2-y1+1;snode=this.cell(this.les.start);sbox=!snode?null:snode.getBoundingClientRect();ref$=this.dom.range.style;ref$.left=x1+"px";ref$.top=y1+"px";ref$.width=w+"px";ref$.height=h+"px";this.dom.range.classList.toggle("show",true);if(sbox){ref$=this.dom.caret.style;ref$.left=sbox.x-rbox.x-1+"px";ref$.top=sbox.y-rbox.y-1+"px";ref$.width=sbox.width+2+"px";ref$.height=sbox.height+2+"px";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]?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}return this.dom.caret.classList.toggle("show",!!sbox)},data:function(it){if(!(it!=null)){return this._data}this._data=it;return this.render()}});if(typeof module!="undefined"&&module!==null){module.exports=sheet}else if(typeof window!="undefined"&&window!==null){window.sheet=sheet}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}}).call(this);
|
|
1
|
+
(function(){var parseCsv,parent,idxToLabel,labelToIdx,sheet;parseCsv=function(txt){return Papa.parse(txt).data};parent=function(n,s,e){var m;m=n;while(n&&n!==e){n=n.parentNode}if(n!==e){return null}if(!s){return n}n=m;while(n&&n!==e&&(!n.matches||n.matches&&!n.matches(s))){n=n.parentNode}if(n===e&&(!e.matches||!e.matches(s))){return null}return n};idxToLabel=function(val){var radix,base,v,map,ret,i$,i,c;radix=Math.floor(Math.log((val+1)*25+1)/Math.log(26))-1;base=(Math.pow(26,radix+1)-1)/25-1;v=val-base;map="ABCDEFGHIJKLMNOPQRSTUVWXYZ";ret="";for(i$=0;i$<=radix;++i$){i=i$;c=map.charAt(v%26);ret=c+ret;v=(v-v%26)/26}return ret};labelToIdx=function(label){var radix,base,map,val,i$,i,idx;radix=label.length-1;base=(Math.pow(26,radix+1)-1)/25-1;map="ABCDEFGHIJKLMNOPQRSTUVWXYZ";val=0;for(i$=0;i$<=radix;++i$){i=i$;idx=map.indexOf(label[i]);if(idx<0){throw new Error("incorrect label")}val=val*26+idx}return val+base};sheet=function(opt){var ref$,this$=this;opt==null&&(opt={});this.opt=opt;this.root=typeof opt.root==="string"?document.querySelector(opt.root):opt.root;this.evtHandler={};this._data=opt.data||[];this._size={row:(ref$=import$({row:[],col:[]},opt.size)).row,col:ref$.col};this.cls={row:(ref$=import$({row:[],col:[]},opt["class"])).row,col:ref$.col};this._editing=opt.editing!=null?!!opt.editing:true;this.dim={col:(opt.dim||(opt.dim={})).col||30,row:(opt.dim||(opt.dim={})).row||30};this.frozen={col:(ref$=import$({col:0,row:0},opt.frozen||{})).col,row:ref$.row};this.idx={col:(ref$=import$({row:true,col:true},opt.idx||{})).col,row:ref$.row};this.fixed={col:(ref$=import$({col:0,row:0},opt.fixed||{})).col,row:ref$.row};this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]};["row","col"].map(function(t){this$.xif[t][1]=this$.xif[t][0]+this$.fixed[t];return this$.xif[t][2]=this$.xif[t][1]+this$.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(it){var x$,n;x$=n=document.createElement("div");x$.classList.add(it);return[it,n]}));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(it){return this$.dom.sheet.appendChild(this$.dom[it])});this.dom.edit.appendChild(this.dom.textarea);this._init();return this};sheet.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var ref$;return((ref$=this.evtHandler)[n]||(ref$[n]=[])).push(cb)},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},_init:function(){var i$,to$,r,j$,to1$,c,dom,this$=this;for(i$=0,to$=this.dim.row;i$<to$;++i$){r=i$;for(j$=0,to1$=this.dim.col;j$<to1$;++j$){c=j$;this.addCell(c,r)}}this.regrid();this.dom.textarea.addEventListener("mousedown",function(e){return e.stopPropagation()});dom=this.dom.sheet;dom.addEventListener("mousedown",function(e){var p,ref$,idx;this$.edited();if(!(p=parent(e.target,".cell",dom))){return}idx={row:(ref$=this$.index(p)).row,col:ref$.col};if(idx.col<0||idx.row<0){return}this$.les.start=this$.les.end=idx;this$.les.node=p;return this$.renderSelection()});dom.addEventListener("mousemove",function(e){var p,ref$;if(this$.editing.on||!(e.buttons&&(p=parent(e.target,".cell",dom)))){return}this$.les.end={row:(ref$=this$.index(p)).row,col:ref$.col};return this$.renderSelection()});dom.addEventListener("dblclick",function(e){var p;if(!(p=parent(e.target,".cell",dom))){return}return this$.edit({node:p,quick:false})});document.body.addEventListener("paste",function(e){var data;if(!parent(document.activeElement,".sheet",dom)){return}if(!this$.les.start){return}data=e.clipboardData.getData("text");data=parseCsv(data);return this$.set({row:this$.les.start.row,col:this$.les.start.col,data:data,range:true})});dom.addEventListener("keydown",function(e){var code,ref$,p1,p2,c1,c2,r1,r2,i$,row,j$,col,opt;if(e.keyCode===67&&(e.metaKey||e.ctrlKey)){return this$.copy()}if(!this$.eventInScope(e)){return}code=e.keyCode;if(code===8){if(!this$.les.node){return}ref$=[this$.les.start,this$.les.end],p1=ref$[0],p2=ref$[1];ref$=p1.col<p2.col?[p1.col,p2.col]:[p2.col,p1.col],c1=ref$[0],c2=ref$[1];ref$=p1.row<p2.row?[p1.row,p2.row]:[p2.row,p1.row],r1=ref$[0],r2=ref$[1];for(i$=r1;i$<=r2;++i$){row=i$;for(j$=c1;j$<=c2;++j$){col=j$;this$.set({row:row,col:col,data:""})}}}opt=function(){switch(code){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}}();if(!opt){return}if(this$.editing.on&&!this$.editing.quick){return}this$.move(opt);e.stopPropagation();e.preventDefault();return this$.dom.sheet.focus()});dom.addEventListener("keypress",function(e){if(this$.les.node&&!this$.editing.on){return this$.edit({node:this$.les.node,quick:e.keyCode===13?false:true})}});this.dom.textarea.addEventListener("keydown",function(e){var lbox,box,ref$;if(e.keyCode===27){this$.edited({cancel:true});e.stopPropagation();e.preventDefault();this$.dom.sheet.focus();return}if(e.keyCode===13&&!(e.altKey||e.metaKey)){this$.move({y:1,x:0});e.stopPropagation();e.preventDefault();this$.dom.sheet.focus();return}if(e.keyCode===13&&(e.altKey||e.metaKey)){this$.dom.textarea.value+="\n";this$.dom.layout.textContent=this$.dom.textarea.value+" ";lbox=this$.dom.layout.getBoundingClientRect();box=this$.editing.node.getBoundingClientRect();return ref$=this$.dom.textarea.style,ref$.width=Math.max(lbox.width,box.width+1)+"px",ref$.height=Math.max(lbox.height,box.height+1)+"px",ref$}});return document.addEventListener("wheel",function(e){var inscope,spos,ref$,dx,dy,ox,oy;inscope=this$.eventInScope(e);if(!(this$.opt.scrollLock!=null)||this$.opt.scrollLock){if(Math.abs(e.deltaX)>Math.abs(e.deltaY)){if(inscope||e.target===document.body){e.preventDefault()}}}if(!inscope){return false}spos=this$.scrollPos;ref$=[e.deltaX,e.deltaY],dx=ref$[0],dy=ref$[1];ref$=Math.abs(dx)>Math.abs(dy)?[dx,0]:[0,dy],dx=ref$[0],dy=ref$[1];ref$=[spos.x,spos.y],ox=ref$[0],oy=ref$[1];spos.x+=dx/30;spos.y+=dy/30;dx=Math.round(spos.x)-Math.round(ox);dy=Math.round(spos.y)-Math.round(oy);if(dy>0){this$._md(dy)}else if(dy<0){this$._mu(dy)}else if(dx>0){this$._mr(dx)}else if(dx<0){this$._ml(dx)}this$.renderSelection();return e.preventDefault()},{passive:false})},copy:function(){var c,i$,to$,row,r,j$,to1$,col,content,ref$,s;if(!this.les.start){return}c=[];for(i$=this.les.start.row,to$=this.les.end.row+1;i$<to$;++i$){row=i$;r=[];for(j$=this.les.start.col,to1$=this.les.end.col+1;j$<to1$;++j$){col=j$;content=((ref$=this._data)[rpw]||(ref$[rpw]=[]))[col];if(typeof content==="object"){continue}r.push('"'+(""+content||"").replace(/"/g,'""')+'"')}c.push(r.join("\t"))}s=c.join("\n");return navigator.clipboard.writeText(s)},eventInScope:function(e){return parent(e.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(it){var ref$;if(it==null){return this._size}this._size={row:(ref$=import$({row:[],col:[]},it)).row,col:ref$.col};return this.regrid()},regrid:function(){var this$=this;this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){var i$,to$,results$=[];for(i$=0,to$=this.frozen.col;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$._size.col[it]||"max-content"}).join(" ")+" "+function(){var i$,to$,results$=[];for(i$=this.xif.col[2],to$=this.dim.col;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$._size.col[it+this$.pos.col-this$.xif.col[1]]||"max-content"}).join(" ");return this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){var i$,to$,results$=[];for(i$=0,to$=this.frozen.row;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$._size.row[it]||"max-content"}).join(" ")+" "+function(){var i$,to$,results$=[];for(i$=this.xif.row[2],to$=this.dim.row;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$._size.row[it+this$.pos.row-this$.xif.row[1]]||"max-content"}).join(" ")},addCell:function(x,y){var div;div=document.createElement("div");this.dom.inner.insertBefore(div,this.dom.inner.childNodes[y*this.dim.col+x]);return this._content({x:x,y:y,n:div})},set:function(arg$){var row,col,data,range,ref$,i$,to$,r,j$,to1$,c,key$;row=arg$.row,col=arg$.col,data=arg$.data,range=arg$.range;if(!range){((ref$=this._data)[row]||(ref$[row]=[]))[col]=data;this._content({y:row-this.pos.row+this.xif.row[1],x:col-this.pos.col+this.xif.col[1]})}else{for(i$=0,to$=data.length;i$<to$;++i$){r=i$;for(j$=0,to1$=data[r].length;j$<to1$;++j$){c=j$;((ref$=this._data)[key$=r+row]||(ref$[key$]=[]))[c+col]=data[r][c];this._content({y:r+row-this.pos.row+this.xif.row[1],x:c+col-this.pos.col+this.xif.col[1]})}}}return this.fire("change",{row:row,col:col,data:data,range:!!range})},_content:function(arg$){var x,y,n,v,ref$,key$,content,className,clsext;x=arg$.x,y=arg$.y,n=arg$.n;if(!n&&!(n=this.dom.inner.childNodes[x+y*this.dim.col])){return}ref$=x<this.xif.col[0]&&y<this.xif.col[0]?["","cell idx"]:x<this.xif.col[0]?(v=y<this.xif.row[1]?" ":y<this.xif.row[2]?y-this.xif.row[1]+1:y-this.xif.row[1]+this.pos.row+1,[v,"cell idx"]):y<this.xif.row[0]?(v=x<this.xif.col[1]?" ":x<this.xif.col[2]?idxToLabel(x-this.xif.col[1]):idxToLabel(x-this.xif.col[1]+this.pos.col),[v,"cell idx"]):x<this.xif.col[1]?[null,"cell fixed"]:y<this.xif.row[1]?[null,"cell fixed"]:x<this.xif.col[2]&&y<this.xif.row[2]?[((ref$=this._data)[key$=y-this.xif.row[1]]||(ref$[key$]=[]))[x-this.xif.col[1]],"cell frozen fixed"]:x<this.xif.col[2]?[((ref$=this._data)[key$=this.pos.row+y-this.xif.row[1]]||(ref$[key$]=[]))[x-this.xif.col[1]],"cell frozen"]:y<this.xif.row[2]?[((ref$=this._data)[key$=y-this.xif.row[1]]||(ref$[key$]=[]))[this.pos.col+x-this.xif.col[1]],"cell frozen"]:[((ref$=this._data)[key$=this.pos.row+y-this.xif.row[1]]||(ref$[key$]=[]))[this.pos.col+x-this.xif.col[1]],"cell"],content=ref$[0],className=ref$[1];if(!(content!=null)){content=""}clsext=x>=this.xif.col[0]&&y>=this.xif.row[0]?(this.cls.col[this.pos.col+x-this.xif.col[1]]||"")+" "+(this.cls.row[this.pos.row+y-this.xif.row[1]]||""):"";n.className=className+" "+clsext;if(content!==null){if(typeof content==="object"){if(content.type==="dom"){n.textContent="";return n.appendChild(content.node)}}else{return n.textContent=content}}},_md:function(mag){var inner,start,ref$,i$,j,j$,to$,i,idx,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));start=(ref$=mag-(this.dim.row-this.fix.row))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;idx=this.dim.col*this.fix.row;if(!inner.childNodes[idx]){break}inner.removeChild(inner.childNodes[idx])}}for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;n=document.createElement("div");this._content({x:i,y:this.dim.row+j,n:n});inner.appendChild(n)}}return this.pos.row+=mag},_mu:function(mag){var inner,start,ref$,i$,j,j$,to$,i,lresult$,n,results$=[];mag==null&&(mag=1);inner=this.dom.inner;if(this.pos.row<=0){return}mag=Math.round(Math.abs(mag));if(mag>=this.pos.row){mag=this.pos.row}start=(ref$=mag-(this.dim.row-this.xif.row[2]))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;if(!inner.childNodes.length){break}inner.removeChild(inner.childNodes[inner.childNodes.length-1])}}this.pos.row-=mag;for(i$=start;i$<mag;++i$){j=i$;lresult$=[];for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;n=document.createElement("div");this._content({x:i,y:j+this.xif.row[2],n:n});lresult$.push(inner.insertBefore(n,inner.childNodes[i+(j-start)*this.dim.col+this.dim.col*this.xif.row[2]]))}results$.push(lresult$)}return results$},_mr:function(mag){var inner,start,ref$,i$,j,j$,to$,i,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));start=(ref$=mag-(this.dim.col-this.fix.col))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.row;j$<to$;++j$){i=j$;inner.removeChild(inner.childNodes[i*this.dim.col+this.fix.col]);n=document.createElement("div");this._content({x:this.dim.col+j,y:i,n:n});inner.insertBefore(n,inner.childNodes[(i+1)*this.dim.col-1])}}this.pos.col+=mag;return this.regrid()},_ml:function(mag){var inner,start,ref$,i$,j,j$,to$,i,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));if(mag>=this.pos.col){mag=this.pos.col}if(this.pos.col<=0||mag<=0){return}start=(ref$=mag-(this.dim.col-this.xif.col[2]))>0?ref$:0;this.pos.col-=mag;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.row;j$<to$;++j$){i=j$;inner.removeChild(inner.childNodes[(i+1)*this.dim.col-1]);n=document.createElement("div");this._content({x:j+this.xif.col[2],y:i,n:n});inner.insertBefore(n,inner.childNodes[i*this.dim.col+this.xif.col[2]+j-start])}}return this.regrid()},goto:function(opt){opt==null&&(opt={row:0,col:0});import$(this.pos,opt);return this.render()},render:function(){var i$,to$,y,lresult$,j$,to1$,x,results$=[];for(i$=0,to$=this.dim.row;i$<to$;++i$){y=i$;lresult$=[];for(j$=0,to1$=this.dim.col;j$<to1$;++j$){x=j$;lresult$.push(this._content({x:x,y:y}))}results$.push(lresult$)}return results$},move:function(opt){var node,idx,box,sbox,ref$;opt==null&&(opt={});if(this.editing.on){this.edited()}if(!(opt.node=this.les.node)){return}if(!(node=this.cell(opt))){return}idx=this.index(node);box=node.getBoundingClientRect();sbox=this.dom.sheet.getBoundingClientRect();if(box.x+box.width>sbox.x+sbox.width){this._mr(1)}if(box.y+box.height>sbox.y+sbox.height){this._md(1)}if(idx.x===0){if(this.pos.col===0){return}else{this._ml(1)}}if(idx.y===0){if(this.pos.row===0){return}else{this._mu(1)}}if(!(node=this.cell(opt))){return}this.les.node=node;this.les.start=this.les.end={col:(ref$=this.index(node)).col,row:ref$.row};return this.renderSelection()},edit:function(arg$){var node,quick,idx,ref$,lbox,box,rbox,sx,sy,v;node=arg$.node,quick=arg$.quick;if(!this._editing){return}idx=this.index(node);if(!idx||idx.col<0||idx.row<0){return}ref$=this.editing;ref$.node=node;ref$.quick=quick;ref$.on=true;this.dom.layout.textContent=node.textContent;lbox=this.dom.layout.getBoundingClientRect();box=node.getBoundingClientRect();rbox=this.dom.sheet.getBoundingClientRect();ref$=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop],sx=ref$[0],sy=ref$[1];ref$=this.dom.edit.style;ref$.left=box.x-rbox.x+sx-2+"px";ref$.top=box.y-rbox.y+sy-2+"px";ref$.width="fit-content";ref$.height="fit-content";this.dom.edit.classList.toggle("show",true);ref$=this.dom.textarea.style;ref$.width=Math.max(lbox.width,box.width+1)+"px";ref$.height=Math.max(lbox.height,box.height+1)+"px";this.dom.textarea.value=v=quick?"":node.textContent||"";this.dom.textarea.focus();return this.dom.textarea.setSelectionRange(v.length,v.length)},edited:function(opt){var v,ref$;opt==null&&(opt={});if(!this.editing.on){return}if(!opt.cancel){this.set({row:this.les.start.row,col:this.les.start.col,data:v=this.dom.textarea.value||""})}this.dom.edit.classList.toggle("show",false);return ref$=this.editing,ref$.node=null,ref$.on=false,ref$},index:function(node){var idx,x,y,col,row;idx=Array.from(this.dom.inner.childNodes).indexOf(node);if(idx<0){return null}x=idx%this.dim.col;y=(idx-x)/this.dim.col;if(x<this.xif.col[1]){col=-1}else if(x<this.xif.col[2]){col=x-this.xif.col[1]}else{col=x-this.xif.col[1]+this.pos.col}if(y<this.xif.row[1]){row=-1}else if(y<this.xif.row[2]){row=y-this.xif.row[1]}else{row=y-this.xif.row[1]+this.pos.row}return{x:x,y:y,col:col,row:row}},cell:function(opt){var x,y,ref$,base;opt==null&&(opt={});if(opt.col!=null){if(opt.col<this.frozen.col){x=opt.col}else if(opt.col-this.pos.col<this.frozen.col){return null}else{x=opt.col-this.pos.col}if(opt.row<this.frozen.row){y=opt.row}else if(opt.row-this.pos.row<this.frozen.row){return null}else{y=opt.row-this.pos.row}ref$=[x+this.xif.col[1],y+this.xif.row[1]],x=ref$[0],y=ref$[1];if(x<0||y<0||x>=this.dim.col||y>=this.dim.row){return null}return this.dom.inner.childNodes[y*this.dim.col+x]}else{base=opt.node?this.index(opt.node):{y:0,x:0};if(!base){throw new Error("node not found in sheet")}y=base.y+(opt.y||0);x=base.x+(opt.x||0);return this.dom.inner.childNodes[y*this.dim.col+x]}},editing:function(v){return!(v!=null)?this._editing:this._editing=!!v},renderSelection:function(){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;if(!this.les.start){return}ref$=this.les.start.col<this.les.end.col?[this.les.start.col,this.les.end.col]:[this.les.end.col,this.les.start.col],sc=ref$[0],ec=ref$[1];ref$=this.les.start.row<this.les.end.row?[this.les.start.row,this.les.end.row]:[this.les.end.row,this.les.start.row],sr=ref$[0],er=ref$[1];rbox=this.dom.inner.getBoundingClientRect();c0=this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row});c1=this.cell({col:sc,row:sr});c2=this.cell({col:sc,row:er});c3=this.cell({col:ec,row:sr});c4=this.cell({col:ec,row:er});ref$=[c0,c1,c2,c3,c4].map(function(it){if(it){return it.getBoundingClientRect()}else{return null}}),b0=ref$[0],b1=ref$[1],b2=ref$[2],b3=ref$[3],b4=ref$[4];b0.width=0;b0.height=0;x1=(b1||b2||b0).x-rbox.x;y1=(b1||b3||b0).y-rbox.y;x2=(b3||b4||b0).x+(b3||b4||b0).width-rbox.x;y2=(b2||b4||b0).y+(b2||b4||b0).height-rbox.y;w=x2-x1+1;h=y2-y1+1;snode=this.cell(this.les.start);sbox=!snode?null:snode.getBoundingClientRect();ref$=this.dom.range.style;ref$.left=x1+"px";ref$.top=y1+"px";ref$.width=w+"px";ref$.height=h+"px";this.dom.range.classList.toggle("show",true);if(sbox){ref$=this.dom.caret.style;ref$.left=sbox.x-rbox.x-1+"px";ref$.top=sbox.y-rbox.y-1+"px";ref$.width=sbox.width+2+"px";ref$.height=sbox.height+2+"px";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]?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}return this.dom.caret.classList.toggle("show",!!sbox)},data:function(it){if(!(it!=null)){return this._data}this._data=it;return this.render()}});if(typeof module!="undefined"&&module!==null){module.exports=sheet}else if(typeof window!="undefined"&&window!==null){window.sheet=sheet}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}}).call(this);
|