@plotdb/sheet 0.5.9 → 0.6.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 +11 -0
- package/README.md +11 -1
- package/index.css +57 -1
- package/index.js +166 -23
- package/index.min.css +1 -1
- package/index.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.6.0
|
|
4
|
+
|
|
5
|
+
- optionally disable pasting if `papaparse` is not available (not yet implemented TODO)
|
|
6
|
+
- support slider with `slider` option to toggle it on
|
|
7
|
+
- let `tab` key stroke move cursor one cell forward in x direction.
|
|
8
|
+
- support shift + arrow key to extend selection.
|
|
9
|
+
- fix bug: IME composition isn't working at the first keystroke to enter editing mode.
|
|
10
|
+
- support `cellcfg()` for customizing cells with `readonly` and `class` type.
|
|
11
|
+
- check `Papa` for existency before parsing CSV with papaparse.
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
## v0.5.9
|
|
4
15
|
|
|
5
16
|
- add sorting API
|
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ 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
|
+
- example: `{col: ["300px", "12em"]}`
|
|
44
45
|
- `class`: {row, col}. additional cell class name, in array by order, as space separated string.
|
|
45
46
|
- default: {row: [], col: []}
|
|
46
47
|
- `editing`: false to disable editing. default true.
|
|
@@ -50,6 +51,14 @@ initialize:
|
|
|
50
51
|
- `scrollLock`: default true. prevent from horizontal scrolling of document.body if true.
|
|
51
52
|
- this affects how user interact with sheet with scrolling gestures. check src comment for more information.
|
|
52
53
|
- `data`: initial data, as array of arrays
|
|
54
|
+
- `slider`: default false. show slider widgets if true.
|
|
55
|
+
- `cellcfg(opt)`: custom cell definition function. return value based on the given `opt`, which contains:
|
|
56
|
+
- `row`: row of the cell to query
|
|
57
|
+
- `col`: col of the cell to query
|
|
58
|
+
- `type`: a string indicating what should we return. it can be:
|
|
59
|
+
- `class`: should return the CSS classes for the given cell
|
|
60
|
+
- `readonly`: return true if the given cell should be readonly.
|
|
61
|
+
|
|
53
62
|
|
|
54
63
|
## API
|
|
55
64
|
|
|
@@ -76,7 +85,8 @@ initialize:
|
|
|
76
85
|
- `insert()`: insert empty row/column at selected location.
|
|
77
86
|
- `sort(opt)`: sort data based on selected column. `opt` is an object with following fields as options:
|
|
78
87
|
- `dir`: direction. either `asc` or `desc`, by default `asc`.
|
|
79
|
-
|
|
88
|
+
- `edited(opt)`: force sheet enter non-edit mode. option:
|
|
89
|
+
- `cancel`: default false. if true, cancel current editing and remove content that are going to be inputted.
|
|
80
90
|
|
|
81
91
|
## Event
|
|
82
92
|
|
package/index.css
CHANGED
|
@@ -81,8 +81,10 @@
|
|
|
81
81
|
.sheet .edit {
|
|
82
82
|
z-index: 121;
|
|
83
83
|
border: 2px solid #27f;
|
|
84
|
+
pointer-events: none;
|
|
84
85
|
opacity: 0;
|
|
85
|
-
|
|
86
|
+
width: 0;
|
|
87
|
+
height: 0;
|
|
86
88
|
top: 0;
|
|
87
89
|
left: 0;
|
|
88
90
|
position: absolute;
|
|
@@ -107,3 +109,57 @@
|
|
|
107
109
|
opacity: 1 !important;
|
|
108
110
|
display: block;
|
|
109
111
|
}
|
|
112
|
+
.sheet .edit.show {
|
|
113
|
+
pointer-events: auto;
|
|
114
|
+
width: initial;
|
|
115
|
+
height: initial;
|
|
116
|
+
opacity: initial;
|
|
117
|
+
}
|
|
118
|
+
.sheet .slide-y,
|
|
119
|
+
.sheet .slide-x {
|
|
120
|
+
display: flex;
|
|
121
|
+
align-items: center;
|
|
122
|
+
justify-content: space-between;
|
|
123
|
+
position: absolute;
|
|
124
|
+
background: #fff;
|
|
125
|
+
color: rgba(0,0,0,0.5);
|
|
126
|
+
padding: 0.25em;
|
|
127
|
+
border: 1px solid #bbb;
|
|
128
|
+
border-radius: 0.25em;
|
|
129
|
+
}
|
|
130
|
+
.sheet .slide-y:before,
|
|
131
|
+
.sheet .slide-x:before,
|
|
132
|
+
.sheet .slide-y:after,
|
|
133
|
+
.sheet .slide-x:after {
|
|
134
|
+
display: block;
|
|
135
|
+
line-height: 1em;
|
|
136
|
+
}
|
|
137
|
+
.sheet .slide-y {
|
|
138
|
+
flex-direction: column;
|
|
139
|
+
width: 1em;
|
|
140
|
+
height: 3em;
|
|
141
|
+
right: 0;
|
|
142
|
+
transform: translate(0, -50%);
|
|
143
|
+
bottom: 50%;
|
|
144
|
+
cursor: ns-resize;
|
|
145
|
+
}
|
|
146
|
+
.sheet .slide-y:before {
|
|
147
|
+
content: "↑";
|
|
148
|
+
}
|
|
149
|
+
.sheet .slide-y:after {
|
|
150
|
+
content: "↓";
|
|
151
|
+
}
|
|
152
|
+
.sheet .slide-x {
|
|
153
|
+
width: 3em;
|
|
154
|
+
height: 1em;
|
|
155
|
+
bottom: 0;
|
|
156
|
+
left: 50%;
|
|
157
|
+
transform: translate(-50%, 0);
|
|
158
|
+
cursor: ew-resize;
|
|
159
|
+
}
|
|
160
|
+
.sheet .slide-x:before {
|
|
161
|
+
content: "←";
|
|
162
|
+
}
|
|
163
|
+
.sheet .slide-x:after {
|
|
164
|
+
content: "→";
|
|
165
|
+
}
|
package/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
(function(){
|
|
2
2
|
var parseCsv, parent, idxToLabel, labelToIdx, sheet;
|
|
3
3
|
parseCsv = function(txt){
|
|
4
|
-
|
|
4
|
+
if (typeof Papa != 'undefined' && Papa !== null) {
|
|
5
|
+
return Papa.parse(txt).data;
|
|
6
|
+
} else {
|
|
7
|
+
return [[txt]];
|
|
8
|
+
}
|
|
5
9
|
};
|
|
6
10
|
parent = function(n, s, e){
|
|
7
11
|
var m;
|
|
@@ -129,7 +133,7 @@
|
|
|
129
133
|
};
|
|
130
134
|
this.les = {};
|
|
131
135
|
this.editing = {};
|
|
132
|
-
this.dom = Object.fromEntries(['sheet', 'inner', 'caret', 'range', 'edit', 'layout', 'range-cut'].map(function(it){
|
|
136
|
+
this.dom = Object.fromEntries(['sheet', 'inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x'].map(function(it){
|
|
133
137
|
var x$, n;
|
|
134
138
|
x$ = n = document.createElement('div');
|
|
135
139
|
x$.classList.add(it);
|
|
@@ -138,9 +142,12 @@
|
|
|
138
142
|
this.dom.sheet.setAttribute('tabindex', -1);
|
|
139
143
|
this.dom.textarea = document.createElement('textarea');
|
|
140
144
|
this.root.appendChild(this.dom.sheet);
|
|
141
|
-
['inner', 'caret', 'range', 'edit', 'layout', 'range-cut'].map(function(it){
|
|
145
|
+
['inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x'].map(function(it){
|
|
142
146
|
return this$.dom.sheet.appendChild(this$.dom[it]);
|
|
143
147
|
});
|
|
148
|
+
if (!this.opt.slider) {
|
|
149
|
+
this.dom["slide-x"].style.display = this.dom["slide-y"].style.display = 'none';
|
|
150
|
+
}
|
|
144
151
|
this.dom.edit.appendChild(this.dom.textarea);
|
|
145
152
|
this._init();
|
|
146
153
|
return this;
|
|
@@ -164,7 +171,7 @@
|
|
|
164
171
|
return results$;
|
|
165
172
|
},
|
|
166
173
|
_init: function(){
|
|
167
|
-
var i$, to$, r, j$, to1$, c, dom, _dp, _dparse, this$ = this;
|
|
174
|
+
var i$, to$, r, j$, to1$, c, dom, _dp, _dparse, _obj, ref$, ref1$, ref2$, this$ = this;
|
|
168
175
|
for (i$ = 0, to$ = this.dim.row; i$ < to$; ++i$) {
|
|
169
176
|
r = i$;
|
|
170
177
|
for (j$ = 0, to1$ = this.dim.col; j$ < to1$; ++j$) {
|
|
@@ -214,12 +221,13 @@
|
|
|
214
221
|
col: ref$.col
|
|
215
222
|
};
|
|
216
223
|
if (idx.col < 0 || idx.row < 0) {
|
|
224
|
+
this$.les.node = this$.cell(this$.les.start);
|
|
217
225
|
if (!(e.shiftKey && this$.les.start)) {
|
|
218
|
-
this$.les.node = this$.cell(this$.les.start);
|
|
219
226
|
this$.les.start = {
|
|
220
227
|
col: (ref$ = idx.col) > 0 ? ref$ : 0,
|
|
221
228
|
row: (ref$ = idx.row) > 0 ? ref$ : 0
|
|
222
229
|
};
|
|
230
|
+
this$.les.node = this$.cell(this$.les.start);
|
|
223
231
|
}
|
|
224
232
|
this$.les.end = {
|
|
225
233
|
col: idx.col >= 0 ? idx.col : undefined,
|
|
@@ -238,6 +246,9 @@
|
|
|
238
246
|
});
|
|
239
247
|
dom.addEventListener('mousemove', function(e){
|
|
240
248
|
var p, ref$, idx;
|
|
249
|
+
if (this$._slider.y.on || this$._slider.x.on) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
241
252
|
if (this$.editing.on || !(e.buttons && (p = parent(e.target, '.cell', dom)))) {
|
|
242
253
|
return;
|
|
243
254
|
}
|
|
@@ -315,7 +326,7 @@
|
|
|
315
326
|
return this$.dom["range-cut"].classList.toggle('show', false);
|
|
316
327
|
}
|
|
317
328
|
});
|
|
318
|
-
dom.addEventListener('keydown', function(e){
|
|
329
|
+
this.dom.textarea.addEventListener('keydown', function(e){
|
|
319
330
|
var code, ref$, sc, ec, sr, er, data, res$, i$, row, lresult$, j$, col, opt;
|
|
320
331
|
code = e.keyCode;
|
|
321
332
|
if (e.keyCode === 67 && (e.metaKey || e.ctrlKey)) {
|
|
@@ -380,6 +391,11 @@
|
|
|
380
391
|
y: 1,
|
|
381
392
|
x: 0
|
|
382
393
|
};
|
|
394
|
+
case 9:
|
|
395
|
+
return {
|
|
396
|
+
y: 0,
|
|
397
|
+
x: 1
|
|
398
|
+
};
|
|
383
399
|
default:
|
|
384
400
|
return null;
|
|
385
401
|
}
|
|
@@ -390,12 +406,12 @@
|
|
|
390
406
|
if (this$.editing.on && !this$.editing.quick) {
|
|
391
407
|
return;
|
|
392
408
|
}
|
|
393
|
-
this$.move(opt);
|
|
409
|
+
this$.move((opt.select = e.shiftKey, opt));
|
|
394
410
|
e.stopPropagation();
|
|
395
411
|
e.preventDefault();
|
|
396
|
-
return this$.dom.
|
|
412
|
+
return this$.dom.textarea.focus();
|
|
397
413
|
});
|
|
398
|
-
dom.addEventListener('keypress', function(e){
|
|
414
|
+
this.dom.textarea.addEventListener('keypress', function(e){
|
|
399
415
|
var ref$;
|
|
400
416
|
if (((ref$ = e.keyCode) === 31 || ref$ === 61) && (e.metaKey || e.ctrlKey)) {
|
|
401
417
|
return;
|
|
@@ -411,14 +427,30 @@
|
|
|
411
427
|
}
|
|
412
428
|
});
|
|
413
429
|
this.dom.textarea.addEventListener('keydown', function(e){
|
|
414
|
-
var lbox, box
|
|
430
|
+
var ref$, lbox, box;
|
|
431
|
+
if (this$.les.node && !this$.editing.on) {
|
|
432
|
+
if ((ref$ = e.keyCode) === 37 || ref$ === 38 || ref$ === 39 || ref$ === 40 || ref$ === 9 || ref$ === 16 || ref$ === 18 || ref$ === 91 || ref$ === 27) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
this$.edit({
|
|
436
|
+
node: this$.les.node,
|
|
437
|
+
quick: e.keyCode === 13 ? false : true
|
|
438
|
+
});
|
|
439
|
+
if (e.keyCode === 13) {
|
|
440
|
+
e.preventDefault();
|
|
441
|
+
}
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if (!this$.editing.on) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
415
447
|
if (e.keyCode === 27) {
|
|
416
448
|
this$.edited({
|
|
417
449
|
cancel: true
|
|
418
450
|
});
|
|
419
451
|
e.stopPropagation();
|
|
420
452
|
e.preventDefault();
|
|
421
|
-
this$.dom.
|
|
453
|
+
this$.dom.textarea.focus();
|
|
422
454
|
return;
|
|
423
455
|
}
|
|
424
456
|
if (e.keyCode === 13 && !(e.altKey || e.metaKey)) {
|
|
@@ -428,7 +460,7 @@
|
|
|
428
460
|
});
|
|
429
461
|
e.stopPropagation();
|
|
430
462
|
e.preventDefault();
|
|
431
|
-
this$.dom.
|
|
463
|
+
this$.dom.textarea.focus();
|
|
432
464
|
return;
|
|
433
465
|
}
|
|
434
466
|
if (e.keyCode === 13 && (e.altKey || e.metaKey)) {
|
|
@@ -439,6 +471,59 @@
|
|
|
439
471
|
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$;
|
|
440
472
|
}
|
|
441
473
|
});
|
|
474
|
+
_obj = this;
|
|
475
|
+
this._slider = {
|
|
476
|
+
hd: function(evt){
|
|
477
|
+
var this$ = this;
|
|
478
|
+
this.on = true;
|
|
479
|
+
this.p = evt[this.t[2]];
|
|
480
|
+
document.addEventListener('mouseup', function(e){
|
|
481
|
+
return this$.hu(e);
|
|
482
|
+
});
|
|
483
|
+
return document.addEventListener('mousemove', function(e){
|
|
484
|
+
return this$.hm(e);
|
|
485
|
+
});
|
|
486
|
+
},
|
|
487
|
+
hu: function(evt){
|
|
488
|
+
this.on = false;
|
|
489
|
+
document.removeEventListener('mouseup', this.hu);
|
|
490
|
+
return document.removeEventListener('mousemove', this.hm);
|
|
491
|
+
},
|
|
492
|
+
hm: function(evt){
|
|
493
|
+
var d, v, ref$;
|
|
494
|
+
if (!this.on) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
d = this.p - evt[this.t[2]];
|
|
498
|
+
v = Math.sign(d) * this.dir * Math.round(Math.log((ref$ = Math.abs(d)) > 1 ? ref$ : 1));
|
|
499
|
+
if (v > 0) {
|
|
500
|
+
_obj[this.t[1]](v);
|
|
501
|
+
}
|
|
502
|
+
if (v < 0) {
|
|
503
|
+
_obj[this.t[0]](v);
|
|
504
|
+
}
|
|
505
|
+
return _obj.renderSelection();
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
this._slider.y = (ref1$ = {
|
|
509
|
+
n: 'slide-y',
|
|
510
|
+
on: false,
|
|
511
|
+
p: 0,
|
|
512
|
+
t: ['_mu', '_md', 'clientY'],
|
|
513
|
+
dir: -1
|
|
514
|
+
}, ref1$.hd = (ref$ = this._slider).hd, ref1$.hu = ref$.hu, ref1$.hm = ref$.hm, ref1$);
|
|
515
|
+
this._slider.x = (ref2$ = {
|
|
516
|
+
n: 'slide-x',
|
|
517
|
+
on: false,
|
|
518
|
+
p: 0,
|
|
519
|
+
t: ['_mr', '_ml', 'clientX'],
|
|
520
|
+
dir: 1
|
|
521
|
+
}, ref2$.hd = (ref1$ = this._slider).hd, ref2$.hu = ref1$.hu, ref2$.hm = ref1$.hm, ref2$);
|
|
522
|
+
['x', 'y'].map(function(n){
|
|
523
|
+
return this$.dom[this$._slider[n].n].addEventListener('mousedown', function(e){
|
|
524
|
+
return this$._slider[n].hd(e);
|
|
525
|
+
});
|
|
526
|
+
});
|
|
442
527
|
return document.addEventListener('wheel', function(e){
|
|
443
528
|
var inscope, spos, ref$, dx, dy, ox, oy;
|
|
444
529
|
inscope = this$.eventInScope(e);
|
|
@@ -701,7 +786,7 @@
|
|
|
701
786
|
});
|
|
702
787
|
},
|
|
703
788
|
_content: function(arg$){
|
|
704
|
-
var x, y, n, v, ref$, key$, content, className, clsext;
|
|
789
|
+
var x, y, n, v, ref$, key$, content, className, fr, clsext, clsopt;
|
|
705
790
|
x = arg$.x, y = arg$.y, n = arg$.n;
|
|
706
791
|
if (!n && !(n = this.dom.inner.childNodes[x + y * this.dim.col])) {
|
|
707
792
|
return;
|
|
@@ -734,8 +819,26 @@
|
|
|
734
819
|
if (!(content != null)) {
|
|
735
820
|
content = "";
|
|
736
821
|
}
|
|
737
|
-
|
|
738
|
-
|
|
822
|
+
fr = /frozen/.exec(className);
|
|
823
|
+
clsext = x >= this.xif.col[0] && y >= this.xif.row[0] ? (this.cls.col[(fr
|
|
824
|
+
? 0
|
|
825
|
+
: this.pos.col) + x - this.xif.col[1]] || '') + ' ' + (this.cls.row[(fr
|
|
826
|
+
? 0
|
|
827
|
+
: this.pos.row) + y - this.xif.row[1]] || '') : '';
|
|
828
|
+
clsopt = !this.opt.cellcfg
|
|
829
|
+
? ''
|
|
830
|
+
: this.opt.cellcfg({
|
|
831
|
+
type: 'class',
|
|
832
|
+
col: (fr
|
|
833
|
+
? 0
|
|
834
|
+
: this.pos.col) + x - this.xif.col[1],
|
|
835
|
+
row: (fr
|
|
836
|
+
? 0
|
|
837
|
+
: this.pos.row) + y - this.xif.row[1]
|
|
838
|
+
}) || '';
|
|
839
|
+
n.className = [className, clsext, clsopt].filter(function(it){
|
|
840
|
+
return it.trim();
|
|
841
|
+
}).join(' ').trim();
|
|
739
842
|
if (content !== null) {
|
|
740
843
|
if (typeof content === 'object') {
|
|
741
844
|
if (content.type === 'dom') {
|
|
@@ -894,7 +997,7 @@
|
|
|
894
997
|
return this.renderSelection();
|
|
895
998
|
},
|
|
896
999
|
move: function(opt){
|
|
897
|
-
var node, idx, box, sbox, ref
|
|
1000
|
+
var node, idx, box, sbox, ref$, ns;
|
|
898
1001
|
opt == null && (opt = {});
|
|
899
1002
|
if (this.editing.on) {
|
|
900
1003
|
this.edited();
|
|
@@ -935,10 +1038,40 @@
|
|
|
935
1038
|
return;
|
|
936
1039
|
}
|
|
937
1040
|
this.les.node = node;
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1041
|
+
if (opt.select) {
|
|
1042
|
+
ns = {
|
|
1043
|
+
col: (ref$ = this.index(node)).col,
|
|
1044
|
+
row: ref$.row
|
|
1045
|
+
};
|
|
1046
|
+
if (this.les.end === this.les.start) {
|
|
1047
|
+
this.les.end = JSON.parse(JSON.stringify(this.les.start));
|
|
1048
|
+
}
|
|
1049
|
+
if (ns.col < this.les.start.col && (ns.col < this.les.end.col || !(this.les.end.col != null))) {
|
|
1050
|
+
(this.les.start.col > this.les.end.col
|
|
1051
|
+
? this.les.end
|
|
1052
|
+
: this.les.start).col = ns.col;
|
|
1053
|
+
}
|
|
1054
|
+
if (ns.row < this.les.start.row && (ns.row < this.les.end.row || !(this.les.end.row != null))) {
|
|
1055
|
+
(this.les.start.row > this.les.end.row
|
|
1056
|
+
? this.les.end
|
|
1057
|
+
: this.les.start).row = ns.row;
|
|
1058
|
+
}
|
|
1059
|
+
if (ns.col > this.les.start.col && ns.col > this.les.end.col) {
|
|
1060
|
+
(this.les.start.col < this.les.end.col
|
|
1061
|
+
? this.les.end
|
|
1062
|
+
: this.les.start).col = ns.col;
|
|
1063
|
+
}
|
|
1064
|
+
if (ns.row > this.les.start.row && ns.row > this.les.end.row) {
|
|
1065
|
+
(this.les.start.row < this.les.end.row
|
|
1066
|
+
? this.les.end
|
|
1067
|
+
: this.les.start).row = ns.row;
|
|
1068
|
+
}
|
|
1069
|
+
} else {
|
|
1070
|
+
this.les.start = this.les.end = {
|
|
1071
|
+
col: (ref$ = this.index(node)).col,
|
|
1072
|
+
row: ref$.row
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
942
1075
|
return this.renderSelection();
|
|
943
1076
|
},
|
|
944
1077
|
edit: function(arg$){
|
|
@@ -948,6 +1081,13 @@
|
|
|
948
1081
|
return;
|
|
949
1082
|
}
|
|
950
1083
|
idx = this.index(node);
|
|
1084
|
+
if (this.opt.cellcfg && this.opt.cellcfg({
|
|
1085
|
+
row: idx.row,
|
|
1086
|
+
col: idx.col,
|
|
1087
|
+
type: 'readonly'
|
|
1088
|
+
})) {
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
951
1091
|
if (!idx || idx.col < 0 || idx.row < 0) {
|
|
952
1092
|
return;
|
|
953
1093
|
}
|
|
@@ -1073,7 +1213,7 @@
|
|
|
1073
1213
|
: this._editing = !!v;
|
|
1074
1214
|
},
|
|
1075
1215
|
renderSelection: function(sel, o){
|
|
1076
|
-
var ref$, sc, ec, sr, er, rbox, c0, c1, c2, c3, c4, c5, b0, b1, b2, b3, b4, b5, x1, y1, colOut, rowOut, x2, y2, w, h, snode, sbox, dom;
|
|
1216
|
+
var ref$, sc, ec, sr, er, rbox, c0, c1, c2, c3, c4, c5, b0, b1, b2, b3, b4, b5, x1, y1, colOut, rowOut, x2, y2, w, h, snode, sbox, dom, this$ = this;
|
|
1077
1217
|
o == null && (o = {});
|
|
1078
1218
|
if (!sel) {
|
|
1079
1219
|
sel = this.les;
|
|
@@ -1143,7 +1283,7 @@
|
|
|
1143
1283
|
if (er == null) {
|
|
1144
1284
|
h = this.root.getBoundingClientRect().height;
|
|
1145
1285
|
}
|
|
1146
|
-
snode = this.
|
|
1286
|
+
snode = this.les.node;
|
|
1147
1287
|
sbox = !snode
|
|
1148
1288
|
? null
|
|
1149
1289
|
: snode.getBoundingClientRect();
|
|
@@ -1171,8 +1311,11 @@
|
|
|
1171
1311
|
? 101
|
|
1172
1312
|
: sel.start.row + this.xif.row[1] < this.xif.row[2] || sel.start.col + this.xif.col[1] < this.xif.col[2] ? 20 : 15;
|
|
1173
1313
|
}
|
|
1174
|
-
|
|
1314
|
+
this.dom.caret.classList.toggle('show', !!sbox);
|
|
1175
1315
|
}
|
|
1316
|
+
return setTimeout(function(){
|
|
1317
|
+
return this$.dom.textarea.focus();
|
|
1318
|
+
}, 0);
|
|
1176
1319
|
},
|
|
1177
1320
|
data: function(it){
|
|
1178
1321
|
if (!(it != null)) {
|
package/index.min.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.sheet{position:relative;width:100%;height:100%;overflow:hidden;overscroll-behavior:contain;outline:0}.sheet .inner{z-index:1;display:grid;width:100%;height:100%;overflow:hidden}.sheet .cell{position:relative;user-select:none;border-width:0 1px 1px 0;border-style:solid;border-color:#ddd;padding:1px 3px;min-width:48px;line-height:26px;box-sizing:border-box;white-space:pre;overflow:hidden}.sheet .cell.idx{z-index:100;background:#f1f2f3;color:#919293;font-size:.85em;text-align:center;user-select:none}.sheet .cell.fixed,.sheet .cell.fixed.frozen{z-index:13}.sheet .cell.fixed{background:#fafbfc;white-space:initial;padding:0}.sheet .cell.frozen{z-index:12;background:#fdfeff}.sheet .cell.fixed.frozen{padding:1px 3px}.sheet .range,.sheet .range-cut{z-index:14;border:1px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .range-cut{border-style:dashed}.sheet .caret{z-index:15;border:2px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .edit{z-index:121;border:2px solid #27f;opacity:0;
|
|
1
|
+
.sheet{position:relative;width:100%;height:100%;overflow:hidden;overscroll-behavior:contain;outline:0}.sheet .inner{z-index:1;display:grid;width:100%;height:100%;overflow:hidden}.sheet .cell{position:relative;user-select:none;border-width:0 1px 1px 0;border-style:solid;border-color:#ddd;padding:1px 3px;min-width:48px;line-height:26px;box-sizing:border-box;white-space:pre;overflow:hidden}.sheet .cell.idx{z-index:100;background:#f1f2f3;color:#919293;font-size:.85em;text-align:center;user-select:none}.sheet .cell.fixed,.sheet .cell.fixed.frozen{z-index:13}.sheet .cell.fixed{background:#fafbfc;white-space:initial;padding:0}.sheet .cell.frozen{z-index:12;background:#fdfeff}.sheet .cell.fixed.frozen{padding:1px 3px}.sheet .range,.sheet .range-cut{z-index:14;border:1px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .range-cut{border-style:dashed}.sheet .caret{z-index:15;border:2px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .edit{z-index:121;border:2px solid #27f;pointer-events:none;opacity:0;width:0;height:0;top:0;left:0;position:absolute}.sheet .edit textarea{display:block;border:0;outline:0}.sheet .layout{display:inline-block;top:0;left:0;position:absolute;z-index:0;opacity:0;pointer-events:none;user-select:none;white-space:pre}.sheet .show{opacity:1 !important;display:block}.sheet .edit.show{pointer-events:auto;width:initial;height:initial;opacity:initial}.sheet .slide-y,.sheet .slide-x{display:flex;align-items:center;justify-content:space-between;position:absolute;background:#fff;color:rgba(0,0,0,0.5);padding:.25em;border:1px solid #bbb;border-radius:.25em}.sheet .slide-y:before,.sheet .slide-x:before,.sheet .slide-y:after,.sheet .slide-x:after{display:block;line-height:1em}.sheet .slide-y{flex-direction:column;width:1em;height:3em;right:0;transform:translate(0,-50%);bottom:50%;cursor:ns-resize}.sheet .slide-y:before{content:"↑"}.sheet .slide-y:after{content:"↓"}.sheet .slide-x{width:3em;height:1em;bottom:0;left:50%;transform:translate(-50%,0);cursor:ew-resize}.sheet .slide-x:before{content:"←"}.sheet .slide-x:after{content:"→"}
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var f,m,n,t;function o(t,e){var i,o={}.hasOwnProperty;for(i in e)o.call(e,i)&&(t[i]=e[i]);return t}f=function(t){return Papa.parse(t).data},m=function(t,e,i){for(var o=t;t&&t!==i;)t=t.parentNode;if(t!==i)return null;if(!e)return t;for(t=o;t&&t!==i&&(!t.matches||t.matches&&!t.matches(e));)t=t.parentNode;return t!==i||i.matches&&i.matches(e)?t:null},n=function(t){for(var e=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,i=t-((Math.pow(26,1+e)-1)/25-1),o="",r=0;r<=e;++r)o="ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i%26)+o,i=(i-i%26)/26;return o},(t=function(t){var e,i=this;return this.opt=t=null==t?{}:t,this.root="string"==typeof t.root?document.querySelector(t.root):t.root,this.evtHandler={},this._data=t.data||[],this._size={row:(e=o({row:[],col:[]},t.size)).row,col:e.col},this.cls={row:(e=o({row:[],col:[]},t.class)).row,col:e.col},this._editing=null==t.editing||!!t.editing,this.dim={col:(t.dim||(t.dim={})).col||30,row:(t.dim||(t.dim={})).row||30},this.frozen={col:(e=o({col:0,row:0},t.frozen||{})).col,row:e.row},this.idx={col:(e=o({row:!0,col:!0},t.idx||{})).col,row:e.row},this.fixed={col:(e=o({col:0,row:0},t.fixed||{})).col,row:e.row},this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]},["row","col"].map(function(t){return i.xif[t][1]=i.xif[t][0]+i.fixed[t],i.xif[t][2]=i.xif[t][1]+i.frozen[t]}),this.fix={row:this.xif.row[2],col:this.xif.col[2]},this.pos={col:0,row:0},this.scrollPos={x:0,y:0},this.sel={cut:{}},this.les={},this.editing={},this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout","range-cut"].map(function(t){var e;e=document.createElement("div");return e.classList.add(t),[t,e]})),this.dom.sheet.setAttribute("tabindex",-1),this.dom.textarea=document.createElement("textarea"),this.root.appendChild(this.dom.sheet),["inner","caret","range","edit","layout","range-cut"].map(function(t){return i.dom.sheet.appendChild(i.dom[t])}),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=o(Object.create(Object.prototype),{on:function(t,e){var i;return((i=this.evtHandler)[t]||(i[t]=[])).push(e)},fire:function(t){for(var e,i,o,r,n=[],s=[],l=1,h=arguments.length;l<h;++l)s.push(arguments[l]);for(e=s,l=0,o=(i=this.evtHandler[t]||[]).length;l<o;++l)r=i[l],n.push(r.apply(this,e));return n},_init:function(){for(var t,e,i,o,d,r,a,u=this,n=0,s=this.dim.row;n<s;++n)for(t=n,e=0,i=this.dim.col;e<i;++e)o=e,this.addCell(o,t);return this.regrid(),this.dom.textarea.addEventListener("mousedown",function(t){return t.stopPropagation()}),this.dom.sheet.addEventListener("contextmenu",function(t){if(u.fire("menu.on",{evt:t,node:t.target}),!u._menuOff)return u._menuOff=function(t){if("keydown"!==t.type||27===t.keyCode)return document.body.removeEventListener("click",u._menuOff),document.body.removeEventListener("keydown",u._menuOff),u._menuOff=null,u.fire("menu.off",{evt:t,node:t.target})},document.body.addEventListener("click",u._menuOff),document.body.addEventListener("keydown",u._menuOff)}),(d=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(!(1<t.button)&&(u.edited(),e=m(t.target,".cell",d)))return(o={row:(i=u.index(e)).row,col:i.col}).col<0||o.row<0?(t.shiftKey&&u.les.start||(u.les.node=u.cell(u.les.start),u.les.start={col:0<(i=o.col)?i:0,row:0<(i=o.row)?i:0}),u.les.end={col:0<=o.col?o.col:void 0,row:0<=o.row?o.row:void 0},void u.renderSelection()):(t.shiftKey&&u.les.start?u.les.end=o:(u.les.start=u.les.end=o,u.les.node=e),u.renderSelection())}),d.addEventListener("mousemove",function(t){var e;if(!u.editing.on&&t.buttons&&(e=m(t.target,".cell",d)))return e={row:(e=u.index(e)).row,col:e.col},u.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},u.renderSelection()}),d.addEventListener("dblclick",function(t){if(t=m(t.target,".cell",d))return u.edit({node:t,quick:!1})}),r=new DOMParser,a=function(t){return r.parseFromString(t,"text/html")},document.body.addEventListener("paste",function(t){var e,i,o,r,n,s,l,h,c;if(m(document.activeElement,".sheet",d)&&u.les.start&&(e=function(t,e){var i=-1,o=e.length>>>0;for(;++i<o;)if(t===e[i])return!0;return!1}("text/html",t.clipboardData.types||[])?(e=a(t.clipboardData.getData("text/html")),Array.from(e.querySelectorAll("tr")).map(function(t){return Array.from(t.querySelectorAll("th,td")).map(function(t){return t.textContent})})):(r=t.clipboardData.getData("text"),f(r)),u.set({row:u.les.start.row,col:u.les.start.col,data:e,range:!0}),u.sel.cut)){if(u._toText({sel:u.sel.cut})===r){for(i=(e=u._bound({sel:u.sel.cut})).sc,o=e.ec,r=e.sr,n=e.er,s=r;s<=n;++s)for(l=s,h=i;h<=o;++h)c=h,u.set({row:l,col:c,data:""});navigator.clipboard.writeText("")}return u.sel.cut=null,u.dom["range-cut"].classList.toggle("show",!1)}}),d.addEventListener("keydown",function(t){var e,i,o,r,n,s,l,h,c,d=t.keyCode;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return u.copy();if(88===t.keyCode&&(t.metaKey||t.ctrlKey))return u.copy({cut:!0});if(u.eventInScope(t)){if(8===d){if(!u.les.node)return;for(e=(c=u._bound()).sc,i=c.ec,o=c.sr,r=c.er,n=[],s=o;s<=r;++s){for(l=[],h=e;h<=i;++h)l.push("");n.push(l)}c=n,u.set({row:o,col:e,data:c,range:!0})}if(189===d&&(t.metaKey||t.ctrlKey)&&u.slice(),187===d&&(t.metaKey||t.ctrlKey)&&u.insert(),(c=function(){switch(d){case 37:return{y:0,x:-1};case 38:return{y:-1,x:0};case 39:return{y:0,x:1};case 40:return{y:1,x:0};default:return null}}())&&(!u.editing.on||u.editing.quick))return u.move(c),t.stopPropagation(),t.preventDefault(),u.dom.sheet.focus()}}),d.addEventListener("keypress",function(t){var e;if(31!==(e=t.keyCode)&&61!==e||!t.metaKey&&!t.ctrlKey)return u.les.node&&!u.editing.on&&(u.edit({node:u.les.node,quick:13!==t.keyCode}),13===t.keyCode)?t.preventDefault():void 0}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o;return 27===t.keyCode?(u.edited({cancel:!0}),t.stopPropagation(),t.preventDefault(),void u.dom.sheet.focus()):13!==t.keyCode||t.altKey||t.metaKey?13===t.keyCode&&(t.altKey||t.metaKey)?(u.dom.textarea.value+="\n",u.dom.layout.textContent=u.dom.textarea.value+" ",e=u.dom.layout.getBoundingClientRect(),i=u.editing.node.getBoundingClientRect(),(o=u.dom.textarea.style).width=Math.max(e.width,i.width+1)+"px",o.height=Math.max(e.height,i.height+1)+"px",o):void 0:(u.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void u.dom.sheet.focus())}),document.addEventListener("wheel",function(t){var e,i,o,r,n=u.eventInScope(t);return(null==u.opt.scrollLock||u.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!n&&t.target!==document.body||t.preventDefault()),!!n&&(e=u.scrollPos,i=(r=[t.deltaX,t.deltaY])[0],o=r[1],i=(r=Math.abs(i)>Math.abs(o)?[i,0]:[0,o])[0],o=r[1],n=(r=[e.x,e.y])[0],r=r[1],e.x+=i/30,e.y+=o/30,i=Math.round(e.x)-Math.round(n),0<(o=Math.round(e.y)-Math.round(r))?u._md(o):o<0?u._mu(o):0<i?u._mr(i):i<0&&u._ml(i),u.renderSelection(),t.preventDefault())},{passive:!1})},select:function(t){var e,i;if(!arguments.length)return this.les.start?((e={}).col=this.les.start.col,e.row=this.les.start.row,this.les.end?(null==this.les.end.col?delete e.col:e.colspan=this.les.end.col-e.col+1,null==this.les.end.row?delete e.row:e.rowspan=this.les.end.row-e.row+1):(e.colspan=1,e.rowspan=1),e):null;this.les={},t&&(this.les={start:{col:0,row:0},end:{}},null!=t.row&&(this.les.start.row=t.row,this.les.end.row=t.row+((i=t.rowspan)&&1<i?i:1)-1),null!=t.col&&(this.les.start.col=t.col,this.les.end.col=t.col+((i=t.colspan)&&1<i?i:1)-1)),this.renderSelection()},_bound:function(t){var e,i,o,r,n;return e=(n=[(o=(t=null==t?{}:t).sel||this.les).start,o.end])[1],(r=n[0])&&e?(i=(n=r.col<e.col||null==e.col?[r.col,e.col]:[e.col,r.col])[0],o=n[1],r=(n=r.row<e.row||null==e.row?[r.row,e.row]:[e.row,r.row])[0],n=n[1],null!=t.defined&&!t.defined||(null==o&&(o=Math.max.apply(Math,this._data.map(function(t){return t.length}))),null==n&&(n=this._data.length)),{sc:i,ec:o,sr:r,er:n}):{sc:0,ec:0,sr:0,er:0}},_toText:function(t){var e,i,o,r,n,s,l,h,c,d,t=t.sel;if(!t||!t.start)return"";for(e=[],o=(i=this._bound({sel:t})).sc,r=i.ec,t=i.sr,n=i.er,s=t;s<=n;++s){for(l=s,h=[],c=o;c<=r;++c)d=c,"object"!=typeof(d=null==(d=((i=this._data)[l]||(i[l]=[]))[d])?"":d)&&h.push('"'+(""+d||"").replace(/"/g,'""')+'"');e.push(h.join("\t"))}return e.join("\n")},copy:function(t){var e;if(null==t&&(t={}),this.les.start)return e=this._toText({sel:this.les}),navigator.clipboard.writeText(e),t.cut?(this.sel.cut={start:this.les.start,end:this.les.end},this.renderSelection(this.sel.cut,{cut:!0})):void 0},eventInScope:function(t){return m(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(t){return null==t?this._size:(this._size={row:(t=o({row:[],col:[]},t)).row,col:t.col},this.regrid())},regrid:function(){var e=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.col[2],i=this.dim.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t+e.pos.col-e.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.row[2],i=this.dim.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t+e.pos.row-e.xif.row[1]]||"max-content"}).join(" ")},addCell:function(t,e){var i=document.createElement("div");return this.dom.inner.insertBefore(i,this.dom.inner.childNodes[e*this.dim.col+t]),this._content({x:t,y:e,n:i})},set:function(t){var e,i,o,r,n,s,l,h,c=t.row,d=t.col,a=t.data,t=t.range;if(t)for(i=0,o=a.length;i<o;++i)for(n=0,s=a[r=i].length;n<s;++n)l=n,((e=this._data)[h=r+c]||(e[h]=[]))[l+d]=a[r][l],this._content({y:r+c-this.pos.row+this.xif.row[1],x:l+d-this.pos.col+this.xif.col[1]});else((e=this._data)[c]||(e[c]=[]))[d]=a,this._content({y:c-this.pos.row+this.xif.row[1],x:d-this.pos.col+this.xif.col[1]});return this.fire("change",{row:c,col:d,data:a,range:!!t})},_content:function(t){var e,i,o=t.x,r=t.y,t=t.n;if(t=t||this.dom.inner.childNodes[o+r*this.dim.col])return e=(i=o<this.xif.col[0]&&r<this.xif.col[0]?["","cell idx"]:o<this.xif.col[0]?[r<this.xif.row[1]?" ":r<this.xif.row[2]?r-this.xif.row[1]+1:r-this.xif.row[1]+this.pos.row+1,"cell idx"]:r<this.xif.row[0]?[o<this.xif.col[1]?" ":o<this.xif.col[2]?n(o-this.xif.col[1]):n(o-this.xif.col[1]+this.pos.col),"cell idx"]:o<this.xif.col[1]||r<this.xif.row[1]?[null,"cell fixed"]:o<this.xif.col[2]&&r<this.xif.row[2]?[((i=this._data)[e=r-this.xif.row[1]]||(i[e]=[]))[o-this.xif.col[1]],"cell frozen fixed"]:o<this.xif.col[2]?[((i=this._data)[e=this.pos.row+r-this.xif.row[1]]||(i[e]=[]))[o-this.xif.col[1]],"cell frozen"]:r<this.xif.row[2]?[((i=this._data)[e=r-this.xif.row[1]]||(i[e]=[]))[this.pos.col+o-this.xif.col[1]],"cell frozen"]:[((i=this._data)[e=this.pos.row+r-this.xif.row[1]]||(i[e]=[]))[this.pos.col+o-this.xif.col[1]],"cell"])[0],i=i[1],null==e&&(e=""),r=o>=this.xif.col[0]&&r>=this.xif.row[0]?(this.cls.col[this.pos.col+o-this.xif.col[1]]||"")+" "+(this.cls.row[this.pos.row+r-this.xif.row[1]]||""):"",t.className=(i+" "+r).trim(),null!==e?"object"!=typeof e?t.textContent=e:"dom"===e.type?(t.textContent="",t.appendChild(e.node)):void 0:void 0},_md:function(t){var e,i,o,r,n,s,l,h,c;for(null==t&&(t=1),e=this.dom.inner,o=i=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))?i:0;o<t;++o)for(r=o,n=0,s=this.dim.col;n<s&&(l=n,h=this.dim.col*this.fix.row,e.childNodes[h]);++n)e.removeChild(e.childNodes[h]);for(o=i;o<t;++o)for(r=o,n=0,s=this.dim.col;n<s;++n)l=n,c=document.createElement("div"),this._content({x:l,y:this.dim.row+r,n:c}),e.appendChild(c);return this.pos.row+=t},_mu:function(t){var e,i,o,r,n,s,l,h,c,d,a=[];if(null==t&&(t=1),e=this.dom.inner,!(this.pos.row<=0)){for(r=i=0<(o=(t=(t=Math.round(Math.abs(t)))>=this.pos.row?this.pos.row:t)-(this.dim.row-this.xif.row[2]))?o:0;r<t;++r)for(n=r,s=0,l=this.dim.col;s<l&&(h=s,e.childNodes.length);++s)e.removeChild(e.childNodes[e.childNodes.length-1]);for(this.pos.row-=t,r=i;r<t;++r){for(n=r,c=[],s=0,l=this.dim.col;s<l;++s)h=s,d=document.createElement("div"),this._content({x:h,y:n+this.xif.row[2],n:d}),c.push(e.insertBefore(d,e.childNodes[h+(n-i)*this.dim.col+this.dim.col*this.xif.row[2]]));a.push(c)}return a}},_mr:function(t){var e,i,o,r,n,s,l,h;for(null==t&&(t=1),e=this.dom.inner,o=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))?i:0;o<t;++o)for(r=o,n=0,s=this.dim.row;n<s;++n)l=n,e.removeChild(e.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+r,y:l,n:h}),e.insertBefore(h,e.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid()},_ml:function(t){var e,i,o,r,n,s,l,h,c;if(null==t&&(t=1),e=this.dom.inner,(t=Math.round(Math.abs(t)))>=this.pos.col&&(t=this.pos.col),!(this.pos.col<=0||t<=0)){for(i=0<(o=t-(this.dim.col-this.xif.col[2]))?o:0,this.pos.col-=t,r=i;r<t;++r)for(n=r,s=0,l=this.dim.row;s<l;++s)h=s,e.removeChild(e.childNodes[(h+1)*this.dim.col-1]),c=document.createElement("div"),this._content({x:n+this.xif.col[2],y:h,n:c}),e.insertBefore(c,e.childNodes[h*this.dim.col+this.xif.col[2]+n-i]);return this.regrid()}},goto:function(t){return o(this.pos,t=null==t?{row:0,col:0}:t),this.render()},render:function(){for(var t,e,i,o,r=0,n=this.dim.row;r<n;++r)for(t=r,e=0,i=this.dim.col;e<i;++e)o=e,this._content({x:o,y:t});return this.renderSelection()},move:function(t){var e,i,o,r;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(r=this.cell(t))){if(e=this.index(r),i=r.getBoundingClientRect(),o=this.dom.sheet.getBoundingClientRect(),i.x+i.width>o.x+o.width&&this._mr(1),i.y+i.height>o.y+o.height&&this._md(1),0===e.x){if(0===this.pos.col)return;this._ml(1)}if(0===e.y){if(0===this.pos.row)return;this._mu(1)}if((r=this.cell(t))||(r=this.cell({col:e.col,row:e.row})))return this.les.node=r,this.les.start=this.les.end={col:(r=this.index(r)).col,row:r.row},this.renderSelection()}},edit:function(t){var e,i,o,r,n,s=t.node,l=t.quick;if(this._editing&&!(!(n=this.index(s))||n.col<0||n.row<0))return(e=this.editing).node=s,e.quick=l,e.on=!0,this.dom.layout.textContent=s.textContent,i=this.dom.layout.getBoundingClientRect(),o=s.getBoundingClientRect(),r=this.dom.sheet.getBoundingClientRect(),t=(e=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],n=e[1],(e=this.dom.edit.style).left=o.x-r.x+t-2+"px",e.top=o.y-r.y+n-2+"px",e.width="fit-content",e.height="fit-content",this.dom.edit.classList.toggle("show",!0),(e=this.dom.textarea.style).width=Math.max(i.width,o.width+1)+"px",e.height=Math.max(i.height,o.height+1)+"px",this.dom.textarea.value=s=!l&&s.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(s.length,s.length)},edited:function(t){if(null==t&&(t={}),this.editing.on)return t.cancel||this.set({row:this.les.start.row,col:this.les.start.col,data:this.dom.textarea.value||""}),this.dom.edit.classList.toggle("show",!1),(t=this.editing).node=null,t.on=!1,t},index:function(t){var e=Array.from(this.dom.inner.childNodes).indexOf(t);return e<0?null:{x:t=e%this.dim.col,y:e=(e-t)/this.dim.col,col:t<this.xif.col[1]?-1:t<this.xif.col[2]?t-this.xif.col[1]:t-this.xif.col[1]+this.pos.col,row:e<this.xif.row[1]?-1:e<this.xif.row[2]?e-this.xif.row[1]:e-this.xif.row[1]+this.pos.row}},cell:function(t){var e,i,o,r=(t=null==t?{}:t).roughly;if(null!=t.col||null!=t.row){if(t.col<this.frozen.col)e=t.col;else if(t.col-this.pos.col<this.frozen.col){if(!r)return null;e=this.frozen.col}else e=t.col-this.pos.col;if(t.row<this.frozen.row)i=t.row;else if(t.row-this.pos.row<this.frozen.row){if(!r)return null;i=this.frozen.row}else i=t.row-this.pos.row;return i=(o=[e+this.xif.col[1],i+this.xif.row[1]])[1],(e=o[0])<0||i<0||e>=this.dim.col||i>=this.dim.row?null:this.dom.inner.childNodes[i*this.dim.col+e]}if(o=t.node?this.index(t.node):{y:0,x:0})return i=o.y+(t.y||0),e=o.x+(t.x||0),this.dom.inner.childNodes[i*this.dim.col+e]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(t,e){var i,o,r,n,s,l,h,c,d,a,u,f,m;return null==e&&(e={}),(t=t||this.les).start?(h=(i=this._bound({defined:!1,sel:t})).sc,m=i.ec,d=i.sr,f=i.er,o=this.dom.inner.getBoundingClientRect(),u=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:h,row:d,roughly:!0}),this.cell({col:h,row:f,roughly:!0}),this.cell({col:m,row:d,roughly:!0}),this.cell({col:m,row:f,roughly:!0}),this.cell({col:this.pos.col+this.dim.col-2,row:this.pos.row+this.dim.row-2})].map(function(t){return t?t.getBoundingClientRect():null}))[0],c=i[1],r=i[2],a=i[3],n=i[4],s=i[5],u.width=0,u.height=0,l=(c||r||(h>this.pos.col?s:u)).x-o.x,h=(c||a||(d>this.pos.row?s:u)).y-o.y,c=m-this.pos.col<0,d=f-this.pos.row<0,a=(a||n||s||u).x+(c?0:(a||n||s||u).width)-o.x-l+1,u=(r||n||s||u).y+(d?0:(r||n||s||u).height)-o.y-h+1,null==m&&(a=this.root.getBoundingClientRect().width),null==f&&(u=this.root.getBoundingClientRect().height),f=(m=this.cell(t.start))?m.getBoundingClientRect():null,(i=(m=e.cut?this.dom["range-cut"]:this.dom.range).style).left=l+"px",i.top=h+"px",i.width=a+"px",i.height=u+"px",m.classList.toggle("show",!0),e.cut?void 0:(f&&((i=this.dom.caret.style).left=f.x-o.x-1+"px",i.top=f.y-o.y-1+"px",i.width=(c?0:f.width)+2+"px",i.height=(d?0:f.height)+2+"px",i.zIndex=t.start.row+this.xif.row[1]<this.xif.row[2]&&t.start.col+this.xif.col[1]<this.xif.col[2]?101:t.start.row+this.xif.row[1]<this.xif.row[2]||t.start.col+this.xif.col[1]<this.xif.col[2]?20:15),this.dom.caret.classList.toggle("show",!!f))):(this.dom.caret.classList.toggle("show",!1),void this.dom.range.classList.toggle("show",!1))},data:function(t){return null==t?this._data:(this._data=t,this.render())},sort:function(i){var o,t,r=this;return null==i&&(i={}),t=this._bound({defined:!1}),o=t.sc,t.ec,t.sr,t.er,(t=this._data.map(function(t,e){return{d:t,i:e}})).sort(function(t,e){return t.i<r.frozen.row&&e.i>=r.frozen.row?-1:e.i<r.frozen.row&&t.i>=r.frozen.row?1:(t=isNaN(+t.d[o])?t.d[o]:+t.d[o],e=isNaN(+e.d[o])?e.d[o]:+e.d[o],("asc"===i.dir?1:-1)*(e<t?1:t<e?-1:0))}),this._data=t.map(function(t){return t.d}),this.fire("change",{row:0,col:0,data:this._data,range:!0}),this.renderSelection(),this.render()},insert:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,r=e.sr,e=e.er;null==o&&(t=this._data.splice(r,0,[])),null==e&&(t=this._data.map(function(t){return t.splice(i,0,"")})),this.fire("change",{row:r,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()},slice:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,r=e.sr,e=e.er;null==o&&(t=this._data.splice(r,e-r+1)),null==e&&(t=this._data.map(function(t){return t.splice(i,o-i+1)})),this.fire("change",{row:r,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.sheet=t)}.call(this);
|
|
1
|
+
!function(){var f,m,l,t;function o(t,e){var i,o={}.hasOwnProperty;for(i in e)o.call(e,i)&&(t[i]=e[i]);return t}f=function(t){return"undefined"!=typeof Papa&&null!==Papa?Papa.parse(t).data:[[t]]},m=function(t,e,i){for(var o=t;t&&t!==i;)t=t.parentNode;if(t!==i)return null;if(!e)return t;for(t=o;t&&t!==i&&(!t.matches||t.matches&&!t.matches(e));)t=t.parentNode;return t!==i||i.matches&&i.matches(e)?t:null},l=function(t){for(var e=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,i=t-((Math.pow(26,1+e)-1)/25-1),o="",s=0;s<=e;++s)o="ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i%26)+o,i=(i-i%26)/26;return o},(t=function(t){var e,i=this;return this.opt=t=null==t?{}:t,this.root="string"==typeof t.root?document.querySelector(t.root):t.root,this.evtHandler={},this._data=t.data||[],this._size={row:(e=o({row:[],col:[]},t.size)).row,col:e.col},this.cls={row:(e=o({row:[],col:[]},t.class)).row,col:e.col},this._editing=null==t.editing||!!t.editing,this.dim={col:(t.dim||(t.dim={})).col||30,row:(t.dim||(t.dim={})).row||30},this.frozen={col:(e=o({col:0,row:0},t.frozen||{})).col,row:e.row},this.idx={col:(e=o({row:!0,col:!0},t.idx||{})).col,row:e.row},this.fixed={col:(e=o({col:0,row:0},t.fixed||{})).col,row:e.row},this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]},["row","col"].map(function(t){return i.xif[t][1]=i.xif[t][0]+i.fixed[t],i.xif[t][2]=i.xif[t][1]+i.frozen[t]}),this.fix={row:this.xif.row[2],col:this.xif.col[2]},this.pos={col:0,row:0},this.scrollPos={x:0,y:0},this.sel={cut:{}},this.les={},this.editing={},this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout","range-cut","slide-y","slide-x"].map(function(t){var e;e=document.createElement("div");return e.classList.add(t),[t,e]})),this.dom.sheet.setAttribute("tabindex",-1),this.dom.textarea=document.createElement("textarea"),this.root.appendChild(this.dom.sheet),["inner","caret","range","edit","layout","range-cut","slide-y","slide-x"].map(function(t){return i.dom.sheet.appendChild(i.dom[t])}),this.opt.slider||(this.dom["slide-x"].style.display=this.dom["slide-y"].style.display="none"),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=o(Object.create(Object.prototype),{on:function(t,e){var i;return((i=this.evtHandler)[t]||(i[t]=[])).push(e)},fire:function(t){for(var e,i,o,s,r=[],n=[],l=1,h=arguments.length;l<h;++l)n.push(arguments[l]);for(e=n,l=0,o=(i=this.evtHandler[t]||[]).length;l<o;++l)s=i[l],r.push(s.apply(this,e));return r},_init:function(){for(var t,e,i,o,c,s,a,r,n,l,u=this,h=0,d=this.dim.row;h<d;++h)for(t=h,e=0,i=this.dim.col;e<i;++e)o=e,this.addCell(o,t);return this.regrid(),this.dom.textarea.addEventListener("mousedown",function(t){return t.stopPropagation()}),this.dom.sheet.addEventListener("contextmenu",function(t){if(u.fire("menu.on",{evt:t,node:t.target}),!u._menuOff)return u._menuOff=function(t){if("keydown"!==t.type||27===t.keyCode)return document.body.removeEventListener("click",u._menuOff),document.body.removeEventListener("keydown",u._menuOff),u._menuOff=null,u.fire("menu.off",{evt:t,node:t.target})},document.body.addEventListener("click",u._menuOff),document.body.addEventListener("keydown",u._menuOff)}),(c=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(!(1<t.button)&&(u.edited(),e=m(t.target,".cell",c)))return(o={row:(i=u.index(e)).row,col:i.col}).col<0||o.row<0?(u.les.node=u.cell(u.les.start),t.shiftKey&&u.les.start||(u.les.start={col:0<(i=o.col)?i:0,row:0<(i=o.row)?i:0},u.les.node=u.cell(u.les.start)),u.les.end={col:0<=o.col?o.col:void 0,row:0<=o.row?o.row:void 0},void u.renderSelection()):(t.shiftKey&&u.les.start?u.les.end=o:(u.les.start=u.les.end=o,u.les.node=e),u.renderSelection())}),c.addEventListener("mousemove",function(t){var e;if(!u._slider.y.on&&!u._slider.x.on&&!u.editing.on&&t.buttons&&(e=m(t.target,".cell",c)))return e={row:(e=u.index(e)).row,col:e.col},u.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},u.renderSelection()}),c.addEventListener("dblclick",function(t){if(t=m(t.target,".cell",c))return u.edit({node:t,quick:!1})}),s=new DOMParser,a=function(t){return s.parseFromString(t,"text/html")},document.body.addEventListener("paste",function(t){var e,i,o,s,r,n,l,h,d;if(m(document.activeElement,".sheet",c)&&u.les.start&&(e=function(t,e){var i=-1,o=e.length>>>0;for(;++i<o;)if(t===e[i])return!0;return!1}("text/html",t.clipboardData.types||[])?(e=a(t.clipboardData.getData("text/html")),Array.from(e.querySelectorAll("tr")).map(function(t){return Array.from(t.querySelectorAll("th,td")).map(function(t){return t.textContent})})):(s=t.clipboardData.getData("text"),f(s)),u.set({row:u.les.start.row,col:u.les.start.col,data:e,range:!0}),u.sel.cut)){if(u._toText({sel:u.sel.cut})===s){for(i=(e=u._bound({sel:u.sel.cut})).sc,o=e.ec,s=e.sr,r=e.er,n=s;n<=r;++n)for(l=n,h=i;h<=o;++h)d=h,u.set({row:l,col:d,data:""});navigator.clipboard.writeText("")}return u.sel.cut=null,u.dom["range-cut"].classList.toggle("show",!1)}}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o,s,r,n,l,h,d,c=t.keyCode;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return u.copy();if(88===t.keyCode&&(t.metaKey||t.ctrlKey))return u.copy({cut:!0});if(u.eventInScope(t)){if(8===c){if(!u.les.node)return;for(e=(d=u._bound()).sc,i=d.ec,o=d.sr,s=d.er,r=[],n=o;n<=s;++n){for(l=[],h=e;h<=i;++h)l.push("");r.push(l)}d=r,u.set({row:o,col:e,data:d,range:!0})}if(189===c&&(t.metaKey||t.ctrlKey)&&u.slice(),187===c&&(t.metaKey||t.ctrlKey)&&u.insert(),(d=function(){switch(c){case 37:return{y:0,x:-1};case 38:return{y:-1,x:0};case 39:return{y:0,x:1};case 40:return{y:1,x:0};case 9:return{y:0,x:1};default:return null}}())&&(!u.editing.on||u.editing.quick))return u.move((d.select=t.shiftKey,d)),t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}}),this.dom.textarea.addEventListener("keypress",function(t){var e;if(31!==(e=t.keyCode)&&61!==e||!t.metaKey&&!t.ctrlKey)return u.les.node&&!u.editing.on&&(u.edit({node:u.les.node,quick:13!==t.keyCode}),13===t.keyCode)?t.preventDefault():void 0}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o;return u.les.node&&!u.editing.on?37===(e=t.keyCode)||38===e||39===e||40===e||9===e||16===e||18===e||91===e||27===e?void 0:(u.edit({node:u.les.node,quick:13!==t.keyCode}),void(13===t.keyCode&&t.preventDefault())):u.editing.on?27===t.keyCode?(u.edited({cancel:!0}),t.stopPropagation(),t.preventDefault(),void u.dom.textarea.focus()):13!==t.keyCode||t.altKey||t.metaKey?13===t.keyCode&&(t.altKey||t.metaKey)?(u.dom.textarea.value+="\n",u.dom.layout.textContent=u.dom.textarea.value+" ",i=u.dom.layout.getBoundingClientRect(),o=u.editing.node.getBoundingClientRect(),(e=u.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:(u.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void u.dom.textarea.focus()):void 0}),(r=this)._slider={hd:function(t){var e=this;return this.on=!0,this.p=t[this.t[2]],document.addEventListener("mouseup",function(t){return e.hu(t)}),document.addEventListener("mousemove",function(t){return e.hm(t)})},hu:function(t){return this.on=!1,document.removeEventListener("mouseup",this.hu),document.removeEventListener("mousemove",this.hm)},hm:function(t){if(this.on)return t=this.p-t[this.t[2]],0<(t=Math.sign(t)*this.dir*Math.round(Math.log(1<(t=Math.abs(t))?t:1)))&&r[this.t[1]](t),t<0&&r[this.t[0]](t),r.renderSelection()}},this._slider.y=((n={n:"slide-y",on:!1,p:0,t:["_mu","_md","clientY"],dir:-1}).hd=(l=this._slider).hd,n.hu=l.hu,n.hm=l.hm,n),this._slider.x=((l={n:"slide-x",on:!1,p:0,t:["_mr","_ml","clientX"],dir:1}).hd=(n=this._slider).hd,l.hu=n.hu,l.hm=n.hm,l),["x","y"].map(function(e){return u.dom[u._slider[e].n].addEventListener("mousedown",function(t){return u._slider[e].hd(t)})}),document.addEventListener("wheel",function(t){var e,i,o,s,r=u.eventInScope(t);return(null==u.opt.scrollLock||u.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!r&&t.target!==document.body||t.preventDefault()),!!r&&(e=u.scrollPos,i=(s=[t.deltaX,t.deltaY])[0],o=s[1],i=(s=Math.abs(i)>Math.abs(o)?[i,0]:[0,o])[0],o=s[1],r=(s=[e.x,e.y])[0],s=s[1],e.x+=i/30,e.y+=o/30,i=Math.round(e.x)-Math.round(r),0<(o=Math.round(e.y)-Math.round(s))?u._md(o):o<0?u._mu(o):0<i?u._mr(i):i<0&&u._ml(i),u.renderSelection(),t.preventDefault())},{passive:!1})},select:function(t){var e,i;if(!arguments.length)return this.les.start?((e={}).col=this.les.start.col,e.row=this.les.start.row,this.les.end?(null==this.les.end.col?delete e.col:e.colspan=this.les.end.col-e.col+1,null==this.les.end.row?delete e.row:e.rowspan=this.les.end.row-e.row+1):(e.colspan=1,e.rowspan=1),e):null;this.les={},t&&(this.les={start:{col:0,row:0},end:{}},null!=t.row&&(this.les.start.row=t.row,this.les.end.row=t.row+((i=t.rowspan)&&1<i?i:1)-1),null!=t.col&&(this.les.start.col=t.col,this.les.end.col=t.col+((i=t.colspan)&&1<i?i:1)-1)),this.renderSelection()},_bound:function(t){var e,i,o,s,r;return e=(r=[(o=(t=null==t?{}:t).sel||this.les).start,o.end])[1],(s=r[0])&&e?(i=(r=s.col<e.col||null==e.col?[s.col,e.col]:[e.col,s.col])[0],o=r[1],s=(r=s.row<e.row||null==e.row?[s.row,e.row]:[e.row,s.row])[0],r=r[1],null!=t.defined&&!t.defined||(null==o&&(o=Math.max.apply(Math,this._data.map(function(t){return t.length}))),null==r&&(r=this._data.length)),{sc:i,ec:o,sr:s,er:r}):{sc:0,ec:0,sr:0,er:0}},_toText:function(t){var e,i,o,s,r,n,l,h,d,c,t=t.sel;if(!t||!t.start)return"";for(e=[],o=(i=this._bound({sel:t})).sc,s=i.ec,t=i.sr,r=i.er,n=t;n<=r;++n){for(l=n,h=[],d=o;d<=s;++d)c=d,"object"!=typeof(c=null==(c=((i=this._data)[l]||(i[l]=[]))[c])?"":c)&&h.push('"'+(""+c||"").replace(/"/g,'""')+'"');e.push(h.join("\t"))}return e.join("\n")},copy:function(t){var e;if(null==t&&(t={}),this.les.start)return e=this._toText({sel:this.les}),navigator.clipboard.writeText(e),t.cut?(this.sel.cut={start:this.les.start,end:this.les.end},this.renderSelection(this.sel.cut,{cut:!0})):void 0},eventInScope:function(t){return m(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(t){return null==t?this._size:(this._size={row:(t=o({row:[],col:[]},t)).row,col:t.col},this.regrid())},regrid:function(){var e=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.col[2],i=this.dim.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t+e.pos.col-e.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.row[2],i=this.dim.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t+e.pos.row-e.xif.row[1]]||"max-content"}).join(" ")},addCell:function(t,e){var i=document.createElement("div");return this.dom.inner.insertBefore(i,this.dom.inner.childNodes[e*this.dim.col+t]),this._content({x:t,y:e,n:i})},set:function(t){var e,i,o,s,r,n,l,h,d=t.row,c=t.col,a=t.data,t=t.range;if(t)for(i=0,o=a.length;i<o;++i)for(r=0,n=a[s=i].length;r<n;++r)l=r,((e=this._data)[h=s+d]||(e[h]=[]))[l+c]=a[s][l],this._content({y:s+d-this.pos.row+this.xif.row[1],x:l+c-this.pos.col+this.xif.col[1]});else((e=this._data)[d]||(e[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 e,i,o,s=t.x,r=t.y,n=t.n;if(n=n||this.dom.inner.childNodes[s+r*this.dim.col])return e=(o=s<this.xif.col[0]&&r<this.xif.col[0]?["","cell idx"]:s<this.xif.col[0]?[r<this.xif.row[1]?" ":r<this.xif.row[2]?r-this.xif.row[1]+1:r-this.xif.row[1]+this.pos.row+1,"cell idx"]:r<this.xif.row[0]?[s<this.xif.col[1]?" ":s<this.xif.col[2]?l(s-this.xif.col[1]):l(s-this.xif.col[1]+this.pos.col),"cell idx"]:s<this.xif.col[1]||r<this.xif.row[1]?[null,"cell fixed"]:s<this.xif.col[2]&&r<this.xif.row[2]?[((o=this._data)[i=r-this.xif.row[1]]||(o[i]=[]))[s-this.xif.col[1]],"cell frozen fixed"]:s<this.xif.col[2]?[((o=this._data)[i=this.pos.row+r-this.xif.row[1]]||(o[i]=[]))[s-this.xif.col[1]],"cell frozen"]:r<this.xif.row[2]?[((o=this._data)[i=r-this.xif.row[1]]||(o[i]=[]))[this.pos.col+s-this.xif.col[1]],"cell frozen"]:[((o=this._data)[i=this.pos.row+r-this.xif.row[1]]||(o[i]=[]))[this.pos.col+s-this.xif.col[1]],"cell"])[0],t=o[1],null==e&&(e=""),i=/frozen/.exec(t),o=s>=this.xif.col[0]&&r>=this.xif.row[0]?(this.cls.col[(i?0:this.pos.col)+s-this.xif.col[1]]||"")+" "+(this.cls.row[(i?0:this.pos.row)+r-this.xif.row[1]]||""):"",r=this.opt.cellcfg&&this.opt.cellcfg({type:"class",col:(i?0:this.pos.col)+s-this.xif.col[1],row:(i?0:this.pos.row)+r-this.xif.row[1]})||"",n.className=[t,o,r].filter(function(t){return t.trim()}).join(" ").trim(),null!==e?"object"!=typeof e?n.textContent=e:"dom"===e.type?(n.textContent="",n.appendChild(e.node)):void 0:void 0},_md:function(t){var e,i,o,s,r,n,l,h,d;for(null==t&&(t=1),e=this.dom.inner,o=i=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))?i:0;o<t;++o)for(s=o,r=0,n=this.dim.col;r<n&&(l=r,h=this.dim.col*this.fix.row,e.childNodes[h]);++r)e.removeChild(e.childNodes[h]);for(o=i;o<t;++o)for(s=o,r=0,n=this.dim.col;r<n;++r)l=r,d=document.createElement("div"),this._content({x:l,y:this.dim.row+s,n:d}),e.appendChild(d);return this.pos.row+=t},_mu:function(t){var e,i,o,s,r,n,l,h,d,c,a=[];if(null==t&&(t=1),e=this.dom.inner,!(this.pos.row<=0)){for(s=i=0<(o=(t=(t=Math.round(Math.abs(t)))>=this.pos.row?this.pos.row:t)-(this.dim.row-this.xif.row[2]))?o:0;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l&&(h=n,e.childNodes.length);++n)e.removeChild(e.childNodes[e.childNodes.length-1]);for(this.pos.row-=t,s=i;s<t;++s){for(r=s,d=[],n=0,l=this.dim.col;n<l;++n)h=n,c=document.createElement("div"),this._content({x:h,y:r+this.xif.row[2],n:c}),d.push(e.insertBefore(c,e.childNodes[h+(r-i)*this.dim.col+this.dim.col*this.xif.row[2]]));a.push(d)}return a}},_mr:function(t){var e,i,o,s,r,n,l,h;for(null==t&&(t=1),e=this.dom.inner,o=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))?i:0;o<t;++o)for(s=o,r=0,n=this.dim.row;r<n;++r)l=r,e.removeChild(e.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+s,y:l,n:h}),e.insertBefore(h,e.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid()},_ml:function(t){var e,i,o,s,r,n,l,h,d;if(null==t&&(t=1),e=this.dom.inner,(t=Math.round(Math.abs(t)))>=this.pos.col&&(t=this.pos.col),!(this.pos.col<=0||t<=0)){for(i=0<(o=t-(this.dim.col-this.xif.col[2]))?o:0,this.pos.col-=t,s=i;s<t;++s)for(r=s,n=0,l=this.dim.row;n<l;++n)h=n,e.removeChild(e.childNodes[(h+1)*this.dim.col-1]),d=document.createElement("div"),this._content({x:r+this.xif.col[2],y:h,n:d}),e.insertBefore(d,e.childNodes[h*this.dim.col+this.xif.col[2]+r-i]);return this.regrid()}},goto:function(t){return o(this.pos,t=null==t?{row:0,col:0}:t),this.render()},render:function(){for(var t,e,i,o,s=0,r=this.dim.row;s<r;++s)for(t=s,e=0,i=this.dim.col;e<i;++e)o=e,this._content({x:o,y:t});return this.renderSelection()},move:function(t){var e,i,o,s,r;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(e=this.cell(t))){if(i=this.index(e),o=e.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),o.x+o.width>s.x+s.width&&this._mr(1),o.y+o.height>s.y+s.height&&this._md(1),0===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((e=this.cell(t))||(e=this.cell({col:i.col,row:i.row})))return this.les.node=e,t.select?(t={col:(r=this.index(e)).col,row:r.row},this.les.end===this.les.start&&(this.les.end=JSON.parse(JSON.stringify(this.les.start))),t.col<this.les.start.col&&(t.col<this.les.end.col||null==this.les.end.col)&&((this.les.start.col>this.les.end.col?this.les.end:this.les.start).col=t.col),t.row<this.les.start.row&&(t.row<this.les.end.row||null==this.les.end.row)&&((this.les.start.row>this.les.end.row?this.les.end:this.les.start).row=t.row),t.col>this.les.start.col&&t.col>this.les.end.col&&((this.les.start.col<this.les.end.col?this.les.end:this.les.start).col=t.col),t.row>this.les.start.row&&t.row>this.les.end.row&&((this.les.start.row<this.les.end.row?this.les.end:this.les.start).row=t.row)):this.les.start=this.les.end={col:(r=this.index(e)).col,row:r.row},this.renderSelection()}},edit:function(t){var e,i,o,s,r,n=t.node,l=t.quick;if(this._editing&&(r=this.index(n),!(this.opt.cellcfg&&this.opt.cellcfg({row:r.row,col:r.col,type:"readonly"})||!r||r.col<0||r.row<0)))return(e=this.editing).node=n,e.quick=l,e.on=!0,this.dom.layout.textContent=n.textContent,i=this.dom.layout.getBoundingClientRect(),o=n.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),t=(e=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],r=e[1],(e=this.dom.edit.style).left=o.x-s.x+t-2+"px",e.top=o.y-s.y+r-2+"px",e.width="fit-content",e.height="fit-content",this.dom.edit.classList.toggle("show",!0),(e=this.dom.textarea.style).width=Math.max(i.width,o.width+1)+"px",e.height=Math.max(i.height,o.height+1)+"px",this.dom.textarea.value=n=!l&&n.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(n.length,n.length)},edited:function(t){if(null==t&&(t={}),this.editing.on)return t.cancel||this.set({row:this.les.start.row,col:this.les.start.col,data:this.dom.textarea.value||""}),this.dom.edit.classList.toggle("show",!1),(t=this.editing).node=null,t.on=!1,t},index:function(t){var e=Array.from(this.dom.inner.childNodes).indexOf(t);return e<0?null:{x:t=e%this.dim.col,y:e=(e-t)/this.dim.col,col:t<this.xif.col[1]?-1:t<this.xif.col[2]?t-this.xif.col[1]:t-this.xif.col[1]+this.pos.col,row:e<this.xif.row[1]?-1:e<this.xif.row[2]?e-this.xif.row[1]:e-this.xif.row[1]+this.pos.row}},cell:function(t){var e,i,o,s=(t=null==t?{}:t).roughly;if(null!=t.col||null!=t.row){if(t.col<this.frozen.col)e=t.col;else if(t.col-this.pos.col<this.frozen.col){if(!s)return null;e=this.frozen.col}else e=t.col-this.pos.col;if(t.row<this.frozen.row)i=t.row;else if(t.row-this.pos.row<this.frozen.row){if(!s)return null;i=this.frozen.row}else i=t.row-this.pos.row;return i=(o=[e+this.xif.col[1],i+this.xif.row[1]])[1],(e=o[0])<0||i<0||e>=this.dim.col||i>=this.dim.row?null:this.dom.inner.childNodes[i*this.dim.col+e]}if(o=t.node?this.index(t.node):{y:0,x:0})return i=o.y+(t.y||0),e=o.x+(t.x||0),this.dom.inner.childNodes[i*this.dim.col+e]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(t,e){var i,o,s,r,n,l,h,d,c,a,u,f,m,w=this;return null==e&&(e={}),(t=t||this.les).start?(h=(i=this._bound({defined:!1,sel:t})).sc,m=i.ec,c=i.sr,f=i.er,o=this.dom.inner.getBoundingClientRect(),u=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:h,row:c,roughly:!0}),this.cell({col:h,row:f,roughly:!0}),this.cell({col:m,row:c,roughly:!0}),this.cell({col:m,row:f,roughly:!0}),this.cell({col:this.pos.col+this.dim.col-2,row:this.pos.row+this.dim.row-2})].map(function(t){return t?t.getBoundingClientRect():null}))[0],d=i[1],s=i[2],a=i[3],r=i[4],n=i[5],u.width=0,u.height=0,l=(d||s||(h>this.pos.col?n:u)).x-o.x,h=(d||a||(c>this.pos.row?n:u)).y-o.y,d=m-this.pos.col<0,c=f-this.pos.row<0,a=(a||r||n||u).x+(d?0:(a||r||n||u).width)-o.x-l+1,u=(s||r||n||u).y+(c?0:(s||r||n||u).height)-o.y-h+1,null==m&&(a=this.root.getBoundingClientRect().width),null==f&&(u=this.root.getBoundingClientRect().height),f=(m=this.les.node)?m.getBoundingClientRect():null,(i=(m=e.cut?this.dom["range-cut"]:this.dom.range).style).left=l+"px",i.top=h+"px",i.width=a+"px",i.height=u+"px",m.classList.toggle("show",!0),e.cut||(f&&((i=this.dom.caret.style).left=f.x-o.x-1+"px",i.top=f.y-o.y-1+"px",i.width=(d?0:f.width)+2+"px",i.height=(c?0:f.height)+2+"px",i.zIndex=t.start.row+this.xif.row[1]<this.xif.row[2]&&t.start.col+this.xif.col[1]<this.xif.col[2]?101:t.start.row+this.xif.row[1]<this.xif.row[2]||t.start.col+this.xif.col[1]<this.xif.col[2]?20:15),this.dom.caret.classList.toggle("show",!!f)),setTimeout(function(){return w.dom.textarea.focus()},0)):(this.dom.caret.classList.toggle("show",!1),void this.dom.range.classList.toggle("show",!1))},data:function(t){return null==t?this._data:(this._data=t,this.render())},sort:function(i){var o,t,s=this;return null==i&&(i={}),t=this._bound({defined:!1}),o=t.sc,t.ec,t.sr,t.er,(t=this._data.map(function(t,e){return{d:t,i:e}})).sort(function(t,e){return t.i<s.frozen.row&&e.i>=s.frozen.row?-1:e.i<s.frozen.row&&t.i>=s.frozen.row?1:(t=isNaN(+t.d[o])?t.d[o]:+t.d[o],e=isNaN(+e.d[o])?e.d[o]:+e.d[o],("asc"===i.dir?1:-1)*(e<t?1:t<e?-1:0))}),this._data=t.map(function(t){return t.d}),this.fire("change",{row:0,col:0,data:this._data,range:!0}),this.renderSelection(),this.render()},insert:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,0,[])),null==e&&(t=this._data.map(function(t){return t.splice(i,0,"")})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()},slice:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,e-s+1)),null==e&&(t=this._data.map(function(t){return t.splice(i,o-i+1)})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.sheet=t)}.call(this);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.6.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":"^5.0.2","@plotdb/datadom":"^0.2.0","@plotdb/json0":"^0.0.5","@plotdb/rescope":"^5.0.3","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.3.0","ldiconfont":"^0.2.3","ldview":"^1.3.2","livescript":"^1.6.0","proxise":"^1.0.1","sharedb-wrapper":"^1.0.0","stylus":"^0.55.0","@zbryikt/template":"^2.3.45","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"]}}
|