@plotdb/sheet 0.1.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -0
- package/README.md +2 -2
- package/{dist/index.css → index.css} +0 -0
- package/{dist/index.js → index.js} +68 -24
- package/{dist/index.min.css → index.min.css} +0 -0
- package/index.min.js +1 -0
- package/package.json +1 -70
- package/dist/index.min.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Change Logs
|
|
2
|
+
|
|
3
|
+
## v0.3.0
|
|
4
|
+
|
|
5
|
+
- support shift-select a range
|
|
6
|
+
- support selection from idx cells
|
|
7
|
+
- support selection without boundary
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## v0.2.0
|
|
11
|
+
|
|
12
|
+
- add `style` in `package.json`
|
|
13
|
+
- add `main` and `browser` field in `package.json`.
|
|
14
|
+
- further minimize generated js file with mangling and compression
|
|
15
|
+
- upgrade modules
|
|
16
|
+
- patch test code to make it work with upgraded modules
|
|
17
|
+
- release with compact directory structure
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## v0.1.8
|
|
21
|
+
|
|
22
|
+
- add `overscroll-behavior` over `.sheet`
|
|
23
|
+
- swipe back note in README.md
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## v0.1.7
|
|
27
|
+
|
|
28
|
+
- support resizing after initialization
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## v0.1.6
|
|
32
|
+
|
|
33
|
+
- support custom class names in cells
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## v0.1.5
|
|
37
|
+
|
|
38
|
+
- make it possible to add node instead of pure text.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## v0.1.4
|
|
42
|
+
|
|
43
|
+
- fix bug: `0` wasn't shown when set cell content. fix this by checking `!(textContent?)` instead of `!(textContent)`.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## v0.1.3
|
|
47
|
+
|
|
48
|
+
- add `data(d)` api
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## v0.1.2
|
|
52
|
+
|
|
53
|
+
- add `scrollLock` option for locking body scrolling to prevent swipe gesture.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## v0.1.1
|
|
57
|
+
|
|
58
|
+
- fix bug: escape should cancel editing.
|
|
59
|
+
- fix bug: caret position incorrect after pressing enter.
|
|
60
|
+
- fix bug: should re-focus after enter.
|
|
61
|
+
- fix bug: caret and range should not be hidden after edited.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## v0.1.0
|
|
65
|
+
|
|
66
|
+
- rename `update` event to `change` event.
|
|
67
|
+
- check sheet focus before pasting data
|
|
68
|
+
- support copy tsv format text to clipboard. use `navigator.clipboard`, which doesn't support older browsers.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## v0.0.10
|
|
72
|
+
|
|
73
|
+
- fix selection issue across frozen cells
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## v0.0.9
|
|
77
|
+
|
|
78
|
+
- fix column label issue (plotdb/sheet#1)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## v0.0.8
|
|
82
|
+
|
|
83
|
+
- fix bug: cell overflow should be hidden so content won't overflow and cover following cells if size is fixed.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## v0.0.7
|
|
87
|
+
|
|
88
|
+
- support sheet in shadow DOM mode
|
|
89
|
+
- add editing option / api for togglgin editability
|
|
90
|
+
- add size option
|
|
91
|
+
- tweak style for `.fixed.frozen` cell.
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## v0.0.6
|
|
95
|
+
|
|
96
|
+
- re-focus sheet after selection moved to support quick editing
|
|
97
|
+
- remove outline of sheet to prevent unwanted focus style.
|
|
98
|
+
- tweak code for updating content
|
|
99
|
+
- add event handler
|
|
100
|
+
- fix bug of content updating issue when setting new data
|
|
101
|
+
- fire update event when data is changed.
|
|
102
|
+
- support range in `set` api.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
## v0.0.5
|
|
106
|
+
|
|
107
|
+
- add `tabindex` in root element to make it possible to capture key events.
|
|
108
|
+
- check some events for event source.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## v0.0.4
|
|
112
|
+
|
|
113
|
+
- tweak fixed cell style
|
|
114
|
+
- prevent fixed cell from being edited
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
## v0.0.3
|
|
118
|
+
|
|
119
|
+
- support fixed rows / columns, frozen rows / columns and idx cells toggling
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
## v0.0.2
|
|
123
|
+
|
|
124
|
+
- fix bug: edited failed if edited node is outside range of visible sheet.
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
## v0.0.1
|
|
128
|
+
|
|
129
|
+
init commit
|
package/README.md
CHANGED
|
@@ -20,8 +20,8 @@ install:
|
|
|
20
20
|
|
|
21
21
|
include:
|
|
22
22
|
|
|
23
|
-
<script src="path-to/sheet.js"></script>
|
|
24
|
-
<link rel="stylesheet" type="text/css" href="path-to/sheet.css"/>
|
|
23
|
+
<script src="path-to/sheet/index.min.js"></script>
|
|
24
|
+
<link rel="stylesheet" type="text/css" href="path-to/sheet/index.min.css"/>
|
|
25
25
|
<div class="container"></div>
|
|
26
26
|
|
|
27
27
|
|
|
File without changes
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Generated by LiveScript 1.6.0
|
|
2
1
|
(function(){
|
|
3
2
|
var parseCsv, parent, idxToLabel, labelToIdx, sheet;
|
|
4
3
|
parseCsv = function(txt){
|
|
@@ -187,21 +186,41 @@
|
|
|
187
186
|
col: ref$.col
|
|
188
187
|
};
|
|
189
188
|
if (idx.col < 0 || idx.row < 0) {
|
|
189
|
+
if (!(e.shiftKey && this$.les.start)) {
|
|
190
|
+
this$.les.node = this$.cell(this$.les.start);
|
|
191
|
+
this$.les.start = {
|
|
192
|
+
col: (ref$ = idx.col) > 0 ? ref$ : 0,
|
|
193
|
+
row: (ref$ = idx.row) > 0 ? ref$ : 0
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
this$.les.end = {
|
|
197
|
+
col: idx.col >= 0 ? idx.col : undefined,
|
|
198
|
+
row: idx.row >= 0 ? idx.row : undefined
|
|
199
|
+
};
|
|
200
|
+
this$.renderSelection();
|
|
190
201
|
return;
|
|
191
202
|
}
|
|
192
|
-
|
|
193
|
-
|
|
203
|
+
if (e.shiftKey && this$.les.start) {
|
|
204
|
+
this$.les.end = idx;
|
|
205
|
+
} else {
|
|
206
|
+
this$.les.start = this$.les.end = idx;
|
|
207
|
+
this$.les.node = p;
|
|
208
|
+
}
|
|
194
209
|
return this$.renderSelection();
|
|
195
210
|
});
|
|
196
211
|
dom.addEventListener('mousemove', function(e){
|
|
197
|
-
var p, ref
|
|
212
|
+
var p, ref$, idx;
|
|
198
213
|
if (this$.editing.on || !(e.buttons && (p = parent(e.target, '.cell', dom)))) {
|
|
199
214
|
return;
|
|
200
215
|
}
|
|
201
|
-
|
|
216
|
+
idx = {
|
|
202
217
|
row: (ref$ = this$.index(p)).row,
|
|
203
218
|
col: ref$.col
|
|
204
219
|
};
|
|
220
|
+
this$.les.end = {
|
|
221
|
+
col: idx.col >= 0 ? idx.col : undefined,
|
|
222
|
+
row: idx.row >= 0 ? idx.row : undefined
|
|
223
|
+
};
|
|
205
224
|
return this$.renderSelection();
|
|
206
225
|
});
|
|
207
226
|
dom.addEventListener('dblclick', function(e){
|
|
@@ -232,7 +251,7 @@
|
|
|
232
251
|
});
|
|
233
252
|
});
|
|
234
253
|
dom.addEventListener('keydown', function(e){
|
|
235
|
-
var code, ref$,
|
|
254
|
+
var code, ref$, sc, ec, sr, er, i$, row, j$, col, opt;
|
|
236
255
|
if (e.keyCode === 67 && (e.metaKey || e.ctrlKey)) {
|
|
237
256
|
return this$.copy();
|
|
238
257
|
}
|
|
@@ -244,16 +263,10 @@
|
|
|
244
263
|
if (!this$.les.node) {
|
|
245
264
|
return;
|
|
246
265
|
}
|
|
247
|
-
ref$ =
|
|
248
|
-
|
|
249
|
-
? [p1.col, p2.col]
|
|
250
|
-
: [p2.col, p1.col], c1 = ref$[0], c2 = ref$[1];
|
|
251
|
-
ref$ = p1.row < p2.row
|
|
252
|
-
? [p1.row, p2.row]
|
|
253
|
-
: [p2.row, p1.row], r1 = ref$[0], r2 = ref$[1];
|
|
254
|
-
for (i$ = r1; i$ <= r2; ++i$) {
|
|
266
|
+
ref$ = this$._bound(), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
|
|
267
|
+
for (i$ = sr; i$ <= er; ++i$) {
|
|
255
268
|
row = i$;
|
|
256
|
-
for (j$ =
|
|
269
|
+
for (j$ = sc; j$ <= ec; ++j$) {
|
|
257
270
|
col = j$;
|
|
258
271
|
this$.set({
|
|
259
272
|
row: row,
|
|
@@ -375,16 +388,44 @@
|
|
|
375
388
|
passive: false
|
|
376
389
|
});
|
|
377
390
|
},
|
|
391
|
+
_bound: function(o){
|
|
392
|
+
var ref$, p1, p2, sc, ec, sr, er;
|
|
393
|
+
o == null && (o = {});
|
|
394
|
+
ref$ = [this.les.start, this.les.end], p1 = ref$[0], p2 = ref$[1];
|
|
395
|
+
ref$ = p1.col < p2.col || p2.col == null
|
|
396
|
+
? [p1.col, p2.col]
|
|
397
|
+
: [p2.col, p1.col], sc = ref$[0], ec = ref$[1];
|
|
398
|
+
ref$ = p1.row < p2.row || p2.row == null
|
|
399
|
+
? [p1.row, p2.row]
|
|
400
|
+
: [p2.row, p1.row], sr = ref$[0], er = ref$[1];
|
|
401
|
+
if (o.defined == null || o.defined) {
|
|
402
|
+
if (ec == null) {
|
|
403
|
+
ec = Math.max.apply(Math, this._data.map(function(it){
|
|
404
|
+
return it.length;
|
|
405
|
+
}));
|
|
406
|
+
}
|
|
407
|
+
if (er == null) {
|
|
408
|
+
er = this._data.length;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
sc: sc,
|
|
413
|
+
ec: ec,
|
|
414
|
+
sr: sr,
|
|
415
|
+
er: er
|
|
416
|
+
};
|
|
417
|
+
},
|
|
378
418
|
copy: function(){
|
|
379
|
-
var c,
|
|
419
|
+
var c, ref$, sc, ec, sr, er, i$, row, r, j$, col, content, s;
|
|
380
420
|
if (!this.les.start) {
|
|
381
421
|
return;
|
|
382
422
|
}
|
|
383
423
|
c = [];
|
|
384
|
-
|
|
424
|
+
ref$ = this._bound(), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
|
|
425
|
+
for (i$ = sr; i$ <= er; ++i$) {
|
|
385
426
|
row = i$;
|
|
386
427
|
r = [];
|
|
387
|
-
for (j$ =
|
|
428
|
+
for (j$ = sc; j$ <= ec; ++j$) {
|
|
388
429
|
col = j$;
|
|
389
430
|
content = ((ref$ = this._data)[rpw] || (ref$[rpw] = []))[col];
|
|
390
431
|
if (typeof content === 'object') {
|
|
@@ -857,12 +898,9 @@
|
|
|
857
898
|
if (!this.les.start) {
|
|
858
899
|
return;
|
|
859
900
|
}
|
|
860
|
-
ref$ = this.
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
ref$ = this.les.start.row < this.les.end.row
|
|
864
|
-
? [this.les.start.row, this.les.end.row]
|
|
865
|
-
: [this.les.end.row, this.les.start.row], sr = ref$[0], er = ref$[1];
|
|
901
|
+
ref$ = this._bound({
|
|
902
|
+
defined: false
|
|
903
|
+
}), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
|
|
866
904
|
rbox = this.dom.inner.getBoundingClientRect();
|
|
867
905
|
c0 = this.cell({
|
|
868
906
|
col: this.pos.col + this.frozen.col,
|
|
@@ -899,6 +937,12 @@
|
|
|
899
937
|
y2 = (b2 || b4 || b0).y + (b2 || b4 || b0).height - rbox.y;
|
|
900
938
|
w = x2 - x1 + 1;
|
|
901
939
|
h = y2 - y1 + 1;
|
|
940
|
+
if (ec == null) {
|
|
941
|
+
w = this.root.getBoundingClientRect().width;
|
|
942
|
+
}
|
|
943
|
+
if (er == null) {
|
|
944
|
+
h = this.root.getBoundingClientRect().height;
|
|
945
|
+
}
|
|
902
946
|
snode = this.cell(this.les.start);
|
|
903
947
|
sbox = !snode
|
|
904
948
|
? null
|
|
File without changes
|
package/index.min.js
ADDED
|
@@ -0,0 +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);
|
package/package.json
CHANGED
|
@@ -1,70 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "zbryikt",
|
|
3
|
-
"name": "@plotdb/sheet",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"description": "spreadsheet",
|
|
6
|
-
"version": "0.1.8",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"homepage": "https://github.com/plotdb/sheet",
|
|
9
|
-
"files": [
|
|
10
|
-
"dist/**/*"
|
|
11
|
-
],
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/plotdb/sheet"
|
|
15
|
-
},
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": ">=10.14.1",
|
|
18
|
-
"npm": ">=6.4.1"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"start": "npx server -r web -o true",
|
|
22
|
-
"deploy": "npx deploy web/static"
|
|
23
|
-
},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"@loadingio/debounce.js": "0.0.1",
|
|
26
|
-
"@loadingio/ldquery": "^2.0.0",
|
|
27
|
-
"@plotdb/csscope": "^0.4.0",
|
|
28
|
-
"@plotdb/datadom": "0.0.4",
|
|
29
|
-
"@plotdb/json0": "0.0.1",
|
|
30
|
-
"@plotdb/rescope": "^1.1.8",
|
|
31
|
-
"body-parser": "^1.19.0",
|
|
32
|
-
"bootstrap": "^4.5.2",
|
|
33
|
-
"bootstrap.ldui": "github:loadingio/bootstrap.ldui",
|
|
34
|
-
"bootstrap.native": "^3.0.13",
|
|
35
|
-
"dompurify": "^2.2.6",
|
|
36
|
-
"fedep": "^0.0.12",
|
|
37
|
-
"jsoneditor": "^9.1.1",
|
|
38
|
-
"ldcover": "^1.3.1",
|
|
39
|
-
"ldiconfont": "^0.1.5",
|
|
40
|
-
"ldview": "^0.1.1",
|
|
41
|
-
"livescript": "^1.6.0",
|
|
42
|
-
"proxise": "^0.1.2",
|
|
43
|
-
"sharedb-wrapper": "github:zbryikt/sharedb-wrapper",
|
|
44
|
-
"stylus": "^0.54.5",
|
|
45
|
-
"template": "github:zbryikt/template#v2.3.13",
|
|
46
|
-
"uglify-js": "=3.2.0",
|
|
47
|
-
"uglifycss": "^0.0.29"
|
|
48
|
-
},
|
|
49
|
-
"frontendDependencies": {
|
|
50
|
-
"root": "web/static/assets/lib",
|
|
51
|
-
"modules": [
|
|
52
|
-
"bootstrap",
|
|
53
|
-
"bootstrap.ldui",
|
|
54
|
-
"bootstrap.native",
|
|
55
|
-
"@loadingio/ldquery",
|
|
56
|
-
"@loadingio/debounce.js",
|
|
57
|
-
"dompurify",
|
|
58
|
-
"ldview",
|
|
59
|
-
"ldcover",
|
|
60
|
-
"jsoneditor",
|
|
61
|
-
"ldiconfont",
|
|
62
|
-
"proxise",
|
|
63
|
-
"@plotdb/datadom",
|
|
64
|
-
"@plotdb/csscope",
|
|
65
|
-
"@plotdb/rescope",
|
|
66
|
-
"sharedb-wrapper",
|
|
67
|
-
"@plotdb/json0"
|
|
68
|
-
]
|
|
69
|
-
}
|
|
70
|
-
}
|
|
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"]}}
|
package/dist/index.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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);
|