@plotdb/sheet 0.7.5 → 0.7.7
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 +34 -0
- package/README.md +20 -0
- package/index.css +40 -0
- package/index.js +198 -94
- package/index.min.css +1 -1
- package/index.min.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v0.7.7
|
|
4
|
+
|
|
5
|
+
- add `guard` option: a click-to-interact overlay over the sheet. the sheet takes the
|
|
6
|
+
wheel for as long as the pointer is over it and never hands the gesture back, so a
|
|
7
|
+
page scroll passing over a sheet gets stuck in it. while the guard is armed the wheel
|
|
8
|
+
is not ours at all and the page scrolls; clicking it lets the sheet have the wheel,
|
|
9
|
+
and leaving the sheet re-arms it after a delay ( 2s by default, cancelled by coming
|
|
10
|
+
back ). a tap outside re-arms it on touch, where there is no `mouseleave`. the look is
|
|
11
|
+
the default dim overlay with a centered hint, or whatever `render` draws. the new
|
|
12
|
+
`guard(v)` method arms / disarms it, and the `guard` event reports the change.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## v0.7.6
|
|
16
|
+
|
|
17
|
+
- support `display`, a function translating the value a cell stores into the value it
|
|
18
|
+
shows. `cellcfg`'s `format` applies to whatever it returns, and editing keeps working
|
|
19
|
+
on the stored value, so a cell can now hold one thing and show another.
|
|
20
|
+
- fix bug: the class from `cellcfg` and from the `class` option lands on the wrong cell
|
|
21
|
+
in a frozen row / column once the sheet is scrolled, since the coordinate used to look
|
|
22
|
+
it up treated a cell frozen on one axis as frozen on both. the idx band, which
|
|
23
|
+
addresses no data of its own, was given a scrolled coordinate as well.
|
|
24
|
+
- fix bug: a sheet with an index column but no index row leaves the first row label
|
|
25
|
+
blank, the corner test comparing both axes against the column offset.
|
|
26
|
+
- refactor: grid position to data coordinate now lives in one place ( `_coord` ) rather
|
|
27
|
+
than three, and rendering a value goes through `_display` rather than formatting
|
|
28
|
+
inline.
|
|
29
|
+
- fix bug: editing a cell whose rendered text differs from what it stores ( a number
|
|
30
|
+
with a `format` from `cellcfg`, for one ) puts the rendered text into the editor, so
|
|
31
|
+
committing writes that back as the value. `1234567` shown as `1,234,567` becomes the
|
|
32
|
+
string `1,234,567`, which then renders as `NaN`. editing now starts from the raw
|
|
33
|
+
value in `@_data`. cells holding advanced content ( an object ) keep falling back to
|
|
34
|
+
what is rendered, there being no other textual form.
|
|
35
|
+
|
|
36
|
+
|
|
3
37
|
## v0.7.5
|
|
4
38
|
|
|
5
39
|
- fix bug: `enableScrolling: false` stops the wheel handler but the sheet still swallows
|
package/README.md
CHANGED
|
@@ -66,6 +66,23 @@ initialize:
|
|
|
66
66
|
the data plus one page. scrolling beyond it is still allowed - the thumb just sticks
|
|
67
67
|
to the end. the scrollbar hides itself when there is nothing to scroll.
|
|
68
68
|
- dragging the thumb moves the view; clicking on the track pages toward the clicked side.
|
|
69
|
+
- `guard`: default false. show a click-to-interact guard over the sheet if set.
|
|
70
|
+
- the sheet takes the wheel whenever the pointer is over it, and keeps the gesture to
|
|
71
|
+
the end - so a page scroll that happens to pass over the sheet gets stuck in it. the
|
|
72
|
+
guard is the way out: until it is clicked the wheel goes to the page, not to us.
|
|
73
|
+
- pass `true` for the default look ( a dim overlay with a centered hint ), or an object:
|
|
74
|
+
- `text`: hint text. default `click to interact`.
|
|
75
|
+
- `delay`: how long after the pointer leaves the sheet the guard comes back, in ms.
|
|
76
|
+
default 2000. re-entering within the delay cancels it.
|
|
77
|
+
- `render(node)`: fill the guard node yourself. `text` is ignored when given.
|
|
78
|
+
- a tap outside the sheet re-arms it too, there being no `mouseleave` on touch.
|
|
79
|
+
- the guard node is `.sheet-guard`, and the sheet gets a `guarded` class while armed.
|
|
80
|
+
- `display(opt)`: custom function translating the value a cell stores into the value it
|
|
81
|
+
shows. `opt` contains `raw` ( the stored value, which may be undefined for an empty
|
|
82
|
+
cell ), `row` and `col`. return what the cell should show.
|
|
83
|
+
- the `format` from `cellcfg` applies to whatever this returns, so a computed value
|
|
84
|
+
still gets formatted.
|
|
85
|
+
- editing always works on the stored value, never on what is shown.
|
|
69
86
|
- `cellcfg(opt)`: custom cell definition function. return value based on the given `opt`, which contains:
|
|
70
87
|
- `row`: row of the cell to query
|
|
71
88
|
- `col`: col of the cell to query
|
|
@@ -83,6 +100,9 @@ initialize:
|
|
|
83
100
|
- `goto({row, col})`: set grid view starting from coordinate {row, col}
|
|
84
101
|
- `render()`: force to re-render visible cells
|
|
85
102
|
- `editing(v)`: set edit status to v, or return edit status if v is not provided.
|
|
103
|
+
- `guard(v)`: arm ( `true` ) or disarm ( `false` ) the guard, or return whether it is
|
|
104
|
+
armed if `v` is not provided. does nothing when the `guard` option is off.
|
|
105
|
+
- the `guard` event fires with the new state on every change.
|
|
86
106
|
- `data(d)`: replace data completely with `d` and re-render.
|
|
87
107
|
- return current data if `d` is omitted.
|
|
88
108
|
- `d` is in the same format with the constructor `data` option
|
package/index.css
CHANGED
|
@@ -226,3 +226,43 @@
|
|
|
226
226
|
.sheet .slide-x:after {
|
|
227
227
|
content: "→";
|
|
228
228
|
}
|
|
229
|
+
/* click-to-interact guard: covers the grid until clicked, so a page scroll passing over
|
|
230
|
+
the sheet reaches the page instead of being taken by us. the wheel hand-off itself is the
|
|
231
|
+
`no-scrolling` class above - this is only what the user sees and clicks.
|
|
232
|
+
z-index sits above every part of the grid ( idx cells at 100, scrollbars at 130 ), and
|
|
233
|
+
`isolation` keeps the overlay inside the sheet's own stacking context, so it never paints
|
|
234
|
+
over whatever the host page stacks above the sheet ( a sticky nav, typically ). */
|
|
235
|
+
.sheet.has-guard {
|
|
236
|
+
isolation: isolate;
|
|
237
|
+
}
|
|
238
|
+
.sheet .sheet-guard {
|
|
239
|
+
top: 0;
|
|
240
|
+
left: 0;
|
|
241
|
+
position: absolute;
|
|
242
|
+
z-index: 200;
|
|
243
|
+
display: flex;
|
|
244
|
+
width: 100%;
|
|
245
|
+
height: 100%;
|
|
246
|
+
align-items: center;
|
|
247
|
+
justify-content: center;
|
|
248
|
+
cursor: pointer;
|
|
249
|
+
outline: none;
|
|
250
|
+
background: rgba(28,34,48,0.16);
|
|
251
|
+
opacity: 0;
|
|
252
|
+
pointer-events: none;
|
|
253
|
+
transition: opacity 0.2s;
|
|
254
|
+
}
|
|
255
|
+
.sheet .sheet-guard .hint {
|
|
256
|
+
font-size: 0.9375rem;
|
|
257
|
+
font-weight: 600;
|
|
258
|
+
color: #fff;
|
|
259
|
+
background: rgba(20,25,40,0.94);
|
|
260
|
+
border: 1px solid rgba(255,255,255,0.14);
|
|
261
|
+
border-radius: 999px;
|
|
262
|
+
padding: 9px 20px;
|
|
263
|
+
box-shadow: 0 8px 24px rgba(20,25,40,0.3);
|
|
264
|
+
}
|
|
265
|
+
.sheet.guarded .sheet-guard {
|
|
266
|
+
opacity: 1;
|
|
267
|
+
pointer-events: auto;
|
|
268
|
+
}
|
package/index.js
CHANGED
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
return val + base;
|
|
61
61
|
};
|
|
62
62
|
sheet = function(opt){
|
|
63
|
-
var ref$, this$ = this;
|
|
63
|
+
var ref$, x$, y$, this$ = this;
|
|
64
64
|
opt == null && (opt = {});
|
|
65
65
|
this.opt = opt;
|
|
66
66
|
this.root = typeof opt.root === 'string'
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
: opt.root;
|
|
69
69
|
this.evtHandler = {};
|
|
70
70
|
this._ccfg = typeof opt.cellcfg === 'function' ? opt.cellcfg : null;
|
|
71
|
+
this._dsp = typeof opt.display === 'function' ? opt.display : null;
|
|
71
72
|
this._data = opt.data || [];
|
|
72
73
|
this._size = {
|
|
73
74
|
row: (ref$ = import$({
|
|
@@ -167,6 +168,25 @@
|
|
|
167
168
|
if (!this.enableScrolling) {
|
|
168
169
|
this.dom.sheet.classList.add('no-scrolling');
|
|
169
170
|
}
|
|
171
|
+
this._guard = !this.opt.guard
|
|
172
|
+
? null
|
|
173
|
+
: typeof this.opt.guard === 'object'
|
|
174
|
+
? this.opt.guard
|
|
175
|
+
: {};
|
|
176
|
+
if (this._guard) {
|
|
177
|
+
x$ = this.dom.guard = document.createElement('div');
|
|
178
|
+
x$.classList.add('sheet-guard');
|
|
179
|
+
x$.setAttribute('tabindex', 0);
|
|
180
|
+
if (typeof this._guard.render === 'function') {
|
|
181
|
+
this._guard.render(this.dom.guard);
|
|
182
|
+
} else {
|
|
183
|
+
y$ = this.dom.guard.appendChild(document.createElement('div'));
|
|
184
|
+
y$.classList.add('hint');
|
|
185
|
+
y$.textContent = this._guard.text || "click to interact";
|
|
186
|
+
}
|
|
187
|
+
this.dom.sheet.classList.add('has-guard');
|
|
188
|
+
this.dom.sheet.appendChild(this.dom.guard);
|
|
189
|
+
}
|
|
170
190
|
this.dom.edit.appendChild(this.dom.textarea);
|
|
171
191
|
this._init();
|
|
172
192
|
return this;
|
|
@@ -607,6 +627,9 @@
|
|
|
607
627
|
if (!this$.enableScrolling) {
|
|
608
628
|
return;
|
|
609
629
|
}
|
|
630
|
+
if (this$._guardArmed) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
610
633
|
if (!(this$.opt.scrollLock != null) || this$.opt.scrollLock) {
|
|
611
634
|
if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) {
|
|
612
635
|
if (inscope || e.target === document.body) {
|
|
@@ -644,7 +667,67 @@
|
|
|
644
667
|
}, {
|
|
645
668
|
passive: false
|
|
646
669
|
});
|
|
647
|
-
|
|
670
|
+
this.renderScrollbar();
|
|
671
|
+
return this._initGuard();
|
|
672
|
+
},
|
|
673
|
+
_initGuard: function(){
|
|
674
|
+
var delay, disarm, rearm, this$ = this;
|
|
675
|
+
if (!this._guard) {
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
delay = this._guard.delay != null ? this._guard.delay : 2000;
|
|
679
|
+
disarm = function(e){
|
|
680
|
+
e.preventDefault();
|
|
681
|
+
e.stopPropagation();
|
|
682
|
+
return this$.guard(false);
|
|
683
|
+
};
|
|
684
|
+
rearm = function(){
|
|
685
|
+
if (this$._guardTimer) {
|
|
686
|
+
clearTimeout(this$._guardTimer);
|
|
687
|
+
}
|
|
688
|
+
return this$._guardTimer = setTimeout(function(){
|
|
689
|
+
return this$.guard(true);
|
|
690
|
+
}, delay);
|
|
691
|
+
};
|
|
692
|
+
this.dom.guard.addEventListener('click', disarm);
|
|
693
|
+
this.dom.guard.addEventListener('keydown', function(e){
|
|
694
|
+
if (e.keyCode === 13 || e.keyCode === 32) {
|
|
695
|
+
return disarm(e);
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
this.dom.sheet.addEventListener('mouseleave', rearm);
|
|
699
|
+
this.dom.sheet.addEventListener('mouseenter', function(){
|
|
700
|
+
if (!this$._guardTimer) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
clearTimeout(this$._guardTimer);
|
|
704
|
+
return this$._guardTimer = null;
|
|
705
|
+
});
|
|
706
|
+
document.addEventListener('pointerdown', function(e){
|
|
707
|
+
if (this$.guard() || this$.eventInScope(e)) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
return rearm();
|
|
711
|
+
}, {
|
|
712
|
+
passive: true
|
|
713
|
+
});
|
|
714
|
+
return this.guard(true);
|
|
715
|
+
},
|
|
716
|
+
guard: function(v){
|
|
717
|
+
if (!(v != null)) {
|
|
718
|
+
return !!this._guardArmed;
|
|
719
|
+
}
|
|
720
|
+
if (!this._guard) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (this._guardTimer) {
|
|
724
|
+
clearTimeout(this._guardTimer);
|
|
725
|
+
this._guardTimer = null;
|
|
726
|
+
}
|
|
727
|
+
this._guardArmed = v = !!v;
|
|
728
|
+
this.dom.sheet.classList.toggle('guarded', v);
|
|
729
|
+
this.dom.sheet.classList.toggle('no-scrolling', v || !this.enableScrolling);
|
|
730
|
+
return this.fire('guard', v);
|
|
648
731
|
},
|
|
649
732
|
select: function(o){
|
|
650
733
|
var ret, that;
|
|
@@ -1016,88 +1099,115 @@
|
|
|
1016
1099
|
});
|
|
1017
1100
|
}
|
|
1018
1101
|
},
|
|
1102
|
+
_coord: function(x, y){
|
|
1103
|
+
var ref$, fc, fr, ret, axis;
|
|
1104
|
+
ref$ = [x < this.xif.col[2], y < this.xif.row[2]], fc = ref$[0], fr = ref$[1];
|
|
1105
|
+
ret = {
|
|
1106
|
+
x: x,
|
|
1107
|
+
y: y,
|
|
1108
|
+
col: (fc
|
|
1109
|
+
? 0
|
|
1110
|
+
: this.pos.col) + x - this.xif.col[1],
|
|
1111
|
+
row: (fr
|
|
1112
|
+
? 0
|
|
1113
|
+
: this.pos.row) + y - this.xif.row[1],
|
|
1114
|
+
frozen: {
|
|
1115
|
+
col: fc,
|
|
1116
|
+
row: fr
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
if (x < this.xif.col[0] || y < this.xif.row[0]) {
|
|
1120
|
+
axis = x >= this.xif.col[0]
|
|
1121
|
+
? 'col'
|
|
1122
|
+
: y >= this.xif.row[0] ? 'row' : null;
|
|
1123
|
+
return ret.type = 'idx', ret.axis = axis, ret.className = "cell idx", ret;
|
|
1124
|
+
}
|
|
1125
|
+
if (x < this.xif.col[1] || y < this.xif.row[1]) {
|
|
1126
|
+
return ret.type = 'fixed', ret.className = "cell fixed", ret;
|
|
1127
|
+
}
|
|
1128
|
+
return import$(ret, {
|
|
1129
|
+
type: 'cell',
|
|
1130
|
+
className: fc && fr
|
|
1131
|
+
? "cell frozen fixed"
|
|
1132
|
+
: fc || fr ? "cell frozen" : "cell"
|
|
1133
|
+
});
|
|
1134
|
+
},
|
|
1135
|
+
_format: function(v, arg$){
|
|
1136
|
+
var row, col, fc;
|
|
1137
|
+
row = arg$.row, col = arg$.col;
|
|
1138
|
+
if (!this._ccfg || sheet._d3warning || isNaN(parseFloat(v))) {
|
|
1139
|
+
return v;
|
|
1140
|
+
}
|
|
1141
|
+
if (!(fc = this._ccfg({
|
|
1142
|
+
type: 'format',
|
|
1143
|
+
row: row,
|
|
1144
|
+
col: col
|
|
1145
|
+
}))) {
|
|
1146
|
+
return v;
|
|
1147
|
+
}
|
|
1148
|
+
if ((typeof d3 != 'undefined' && d3 !== null) && d3.format) {
|
|
1149
|
+
return d3.format(fc)(v);
|
|
1150
|
+
}
|
|
1151
|
+
console.warn("[@plotdb/sheet] cell format provided yet d3.format not available. skip formatting.");
|
|
1152
|
+
sheet._d3warning = true;
|
|
1153
|
+
return v;
|
|
1154
|
+
},
|
|
1155
|
+
_display: function(raw, arg$){
|
|
1156
|
+
var row, col, v;
|
|
1157
|
+
row = arg$.row, col = arg$.col;
|
|
1158
|
+
v = !this._dsp
|
|
1159
|
+
? raw
|
|
1160
|
+
: this._dsp({
|
|
1161
|
+
raw: raw,
|
|
1162
|
+
row: row,
|
|
1163
|
+
col: col
|
|
1164
|
+
});
|
|
1165
|
+
return this._format(v, {
|
|
1166
|
+
row: row,
|
|
1167
|
+
col: col
|
|
1168
|
+
});
|
|
1169
|
+
},
|
|
1019
1170
|
_content: function(arg$){
|
|
1020
|
-
var x, y, n,
|
|
1171
|
+
var x, y, n, c, content, ref$, key$, clsext, clsopt;
|
|
1021
1172
|
x = arg$.x, y = arg$.y, n = arg$.n;
|
|
1022
1173
|
if (!n && !(n = this.dom.inner.childNodes[x + y * this.dim.col])) {
|
|
1023
1174
|
return;
|
|
1024
1175
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
?
|
|
1176
|
+
c = this._coord(x, y);
|
|
1177
|
+
content = c.type === 'idx'
|
|
1178
|
+
? c.axis === 'row'
|
|
1179
|
+
? y < this.xif.row[1]
|
|
1180
|
+
? " "
|
|
1181
|
+
: c.row + 1
|
|
1182
|
+
: c.axis === 'col' ? x < this.xif.col[1]
|
|
1029
1183
|
? " "
|
|
1030
|
-
:
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
:
|
|
1034
|
-
? (v = x < this.xif.col[1]
|
|
1035
|
-
? " "
|
|
1036
|
-
: x < this.xif.col[2]
|
|
1037
|
-
? idxToLabel(x - this.xif.col[1])
|
|
1038
|
-
: idxToLabel(x - this.xif.col[1] + this.pos.col), [v, "cell idx"])
|
|
1039
|
-
: x < this.xif.col[1]
|
|
1040
|
-
? [null, "cell fixed"]
|
|
1041
|
-
: y < this.xif.row[1]
|
|
1042
|
-
? [null, "cell fixed"]
|
|
1043
|
-
: x < this.xif.col[2] && y < this.xif.row[2]
|
|
1044
|
-
? [((ref$ = this._data)[key$ = y - this.xif.row[1]] || (ref$[key$] = []))[x - this.xif.col[1]], "cell frozen fixed"]
|
|
1045
|
-
: x < this.xif.col[2]
|
|
1046
|
-
? [((ref$ = this._data)[key$ = this.pos.row + y - this.xif.row[1]] || (ref$[key$] = []))[x - this.xif.col[1]], "cell frozen"]
|
|
1047
|
-
: y < this.xif.row[2]
|
|
1048
|
-
? [((ref$ = this._data)[key$ = y - this.xif.row[1]] || (ref$[key$] = []))[this.pos.col + x - this.xif.col[1]], "cell frozen"]
|
|
1049
|
-
: [((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];
|
|
1184
|
+
: idxToLabel(c.col) : ""
|
|
1185
|
+
: c.type === 'fixed'
|
|
1186
|
+
? ""
|
|
1187
|
+
: this._display(((ref$ = this._data)[key$ = c.row] || (ref$[key$] = []))[c.col], c);
|
|
1050
1188
|
if (!(content != null)) {
|
|
1051
1189
|
content = "";
|
|
1052
1190
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
? 0
|
|
1058
|
-
: this.pos.row) + y - this.xif.row[1]] || '') : '';
|
|
1059
|
-
clsopt = !this._ccfg
|
|
1191
|
+
clsext = c.type === 'idx'
|
|
1192
|
+
? ''
|
|
1193
|
+
: (this.cls.col[c.col] || '') + ' ' + (this.cls.row[c.row] || '');
|
|
1194
|
+
clsopt = (!this._ccfg
|
|
1060
1195
|
? ''
|
|
1061
1196
|
: this._ccfg({
|
|
1062
1197
|
type: 'class',
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
? 0
|
|
1068
|
-
: this.pos.row) + y - this.xif.row[1]
|
|
1069
|
-
}) || '';
|
|
1070
|
-
n.className = [className, clsext, clsopt].filter(function(it){
|
|
1198
|
+
row: c.row,
|
|
1199
|
+
col: c.col
|
|
1200
|
+
})) || '';
|
|
1201
|
+
n.className = [c.className, clsext, clsopt].filter(function(it){
|
|
1071
1202
|
return it.trim();
|
|
1072
1203
|
}).join(' ').trim();
|
|
1073
|
-
if (content
|
|
1074
|
-
if (
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
return n.appendChild(content.node);
|
|
1078
|
-
}
|
|
1079
|
-
} else {
|
|
1080
|
-
if (this._ccfg && !sheet._d3warning && !isNaN(parseFloat(content))) {
|
|
1081
|
-
fc = this._ccfg({
|
|
1082
|
-
type: 'format',
|
|
1083
|
-
col: (fr
|
|
1084
|
-
? 0
|
|
1085
|
-
: this.pos.col) + x - this.xif.col[1],
|
|
1086
|
-
row: (fr
|
|
1087
|
-
? 0
|
|
1088
|
-
: this.pos.row) + y - this.xif.row[1]
|
|
1089
|
-
});
|
|
1090
|
-
if (fc) {
|
|
1091
|
-
if ((typeof d3 != 'undefined' && d3 !== null) && d3.format) {
|
|
1092
|
-
content = d3.format(fc)(content);
|
|
1093
|
-
} else {
|
|
1094
|
-
console.warn("[@plotdb/sheet] cell format provided yet d3.format not available. skip formatting.");
|
|
1095
|
-
sheet._d3warning = true;
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
return n.textContent = content;
|
|
1204
|
+
if (typeof content === 'object') {
|
|
1205
|
+
if (content.type === 'dom') {
|
|
1206
|
+
n.textContent = "";
|
|
1207
|
+
return n.appendChild(content.node);
|
|
1100
1208
|
}
|
|
1209
|
+
} else {
|
|
1210
|
+
return n.textContent = content;
|
|
1101
1211
|
}
|
|
1102
1212
|
},
|
|
1103
1213
|
_md: function(mag){
|
|
@@ -1328,7 +1438,7 @@
|
|
|
1328
1438
|
return this.renderSelection();
|
|
1329
1439
|
},
|
|
1330
1440
|
edit: function(arg$){
|
|
1331
|
-
var node, quick, idx, ref$, lbox, box, rbox, sx, sy, v;
|
|
1441
|
+
var node, quick, idx, raw, ref$, lbox, box, rbox, sx, sy, v;
|
|
1332
1442
|
node = arg$.node, quick = arg$.quick;
|
|
1333
1443
|
if (!this._editing) {
|
|
1334
1444
|
return;
|
|
@@ -1344,11 +1454,17 @@
|
|
|
1344
1454
|
})) {
|
|
1345
1455
|
return;
|
|
1346
1456
|
}
|
|
1457
|
+
raw = (this._data[idx.row] || [])[idx.col];
|
|
1458
|
+
raw = raw == null
|
|
1459
|
+
? ''
|
|
1460
|
+
: typeof raw === 'object'
|
|
1461
|
+
? node.textContent || ''
|
|
1462
|
+
: '' + raw;
|
|
1347
1463
|
ref$ = this.editing;
|
|
1348
1464
|
ref$.node = node;
|
|
1349
1465
|
ref$.quick = quick;
|
|
1350
1466
|
ref$.on = true;
|
|
1351
|
-
this.dom.layout.textContent =
|
|
1467
|
+
this.dom.layout.textContent = raw;
|
|
1352
1468
|
lbox = this.dom.layout.getBoundingClientRect();
|
|
1353
1469
|
box = node.getBoundingClientRect();
|
|
1354
1470
|
rbox = this.dom.sheet.getBoundingClientRect();
|
|
@@ -1362,9 +1478,7 @@
|
|
|
1362
1478
|
ref$ = this.dom.textarea.style;
|
|
1363
1479
|
ref$.width = Math.max(lbox.width, box.width + 1) + "px";
|
|
1364
1480
|
ref$.height = Math.max(lbox.height, box.height + 1) + "px";
|
|
1365
|
-
this.dom.textarea.value = v = quick
|
|
1366
|
-
? ''
|
|
1367
|
-
: node.textContent || '';
|
|
1481
|
+
this.dom.textarea.value = v = quick ? '' : raw;
|
|
1368
1482
|
this.dom.textarea.focus();
|
|
1369
1483
|
return this.dom.textarea.setSelectionRange(v.length, v.length);
|
|
1370
1484
|
},
|
|
@@ -1385,32 +1499,22 @@
|
|
|
1385
1499
|
return ref$ = this.editing, ref$.node = null, ref$.on = false, ref$;
|
|
1386
1500
|
},
|
|
1387
1501
|
index: function(node){
|
|
1388
|
-
var idx, x,
|
|
1502
|
+
var idx, x, c;
|
|
1389
1503
|
idx = Array.from(this.dom.inner.childNodes).indexOf(node);
|
|
1390
1504
|
if (idx < 0) {
|
|
1391
1505
|
return null;
|
|
1392
1506
|
}
|
|
1393
1507
|
x = idx % this.dim.col;
|
|
1394
|
-
|
|
1395
|
-
if (x < this.xif.col[1]) {
|
|
1396
|
-
col = -1;
|
|
1397
|
-
} else if (x < this.xif.col[2]) {
|
|
1398
|
-
col = x - this.xif.col[1];
|
|
1399
|
-
} else {
|
|
1400
|
-
col = x - this.xif.col[1] + this.pos.col;
|
|
1401
|
-
}
|
|
1402
|
-
if (y < this.xif.row[1]) {
|
|
1403
|
-
row = -1;
|
|
1404
|
-
} else if (y < this.xif.row[2]) {
|
|
1405
|
-
row = y - this.xif.row[1];
|
|
1406
|
-
} else {
|
|
1407
|
-
row = y - this.xif.row[1] + this.pos.row;
|
|
1408
|
-
}
|
|
1508
|
+
c = this._coord(x, (idx - x) / this.dim.col);
|
|
1409
1509
|
return {
|
|
1410
|
-
x: x,
|
|
1411
|
-
y: y,
|
|
1412
|
-
col: col
|
|
1413
|
-
|
|
1510
|
+
x: c.x,
|
|
1511
|
+
y: c.y,
|
|
1512
|
+
col: c.x < this.xif.col[1]
|
|
1513
|
+
? -1
|
|
1514
|
+
: c.col,
|
|
1515
|
+
row: c.y < this.xif.row[1]
|
|
1516
|
+
? -1
|
|
1517
|
+
: c.row
|
|
1414
1518
|
};
|
|
1415
1519
|
},
|
|
1416
1520
|
cell: function(opt){
|
package/index.min.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.sheet{position:relative;width:100%;height:100%;overflow:hidden;overscroll-behavior:contain;outline:0}.sheet.no-scrolling{overscroll-behavior-y:auto}.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;min-height:29px;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 .scroll-y,.sheet .scroll-x{position:absolute;z-index:130;background:rgba(0,0,0,0.04)}.sheet .scroll-y.idle,.sheet .scroll-x.idle{opacity:0;pointer-events:none}.sheet .scroll-y .thumb,.sheet .scroll-x .thumb{position:absolute;top:0;left:0;border-radius:4px;background:rgba(0,0,0,0.32);transition:background .1s ease}.sheet .scroll-y:hover .thumb,.sheet .scroll-x:hover .thumb,.sheet .scroll-y.active .thumb,.sheet .scroll-x.active .thumb{background:rgba(0,0,0,0.52)}.sheet .scroll-y{top:0;right:0;bottom:10px;width:10px;cursor:default}.sheet .scroll-y .thumb{width:100%}.sheet .scroll-x{left:0;right:10px;bottom:0;height:10px;cursor:default}.sheet .scroll-x .thumb{height:100%}.sheet.has-scrollbar .slide-y{right:12px}.sheet.has-scrollbar .slide-x{bottom:12px}.sheet .slide-y,.sheet .slide-x{display:flex;align-items:center;justify-content:space-between;position:absolute;z-index:1;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:"→"}
|
|
1
|
+
.sheet{position:relative;width:100%;height:100%;overflow:hidden;overscroll-behavior:contain;outline:0}.sheet.no-scrolling{overscroll-behavior-y:auto}.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;min-height:29px;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 .scroll-y,.sheet .scroll-x{position:absolute;z-index:130;background:rgba(0,0,0,0.04)}.sheet .scroll-y.idle,.sheet .scroll-x.idle{opacity:0;pointer-events:none}.sheet .scroll-y .thumb,.sheet .scroll-x .thumb{position:absolute;top:0;left:0;border-radius:4px;background:rgba(0,0,0,0.32);transition:background .1s ease}.sheet .scroll-y:hover .thumb,.sheet .scroll-x:hover .thumb,.sheet .scroll-y.active .thumb,.sheet .scroll-x.active .thumb{background:rgba(0,0,0,0.52)}.sheet .scroll-y{top:0;right:0;bottom:10px;width:10px;cursor:default}.sheet .scroll-y .thumb{width:100%}.sheet .scroll-x{left:0;right:10px;bottom:0;height:10px;cursor:default}.sheet .scroll-x .thumb{height:100%}.sheet.has-scrollbar .slide-y{right:12px}.sheet.has-scrollbar .slide-x{bottom:12px}.sheet .slide-y,.sheet .slide-x{display:flex;align-items:center;justify-content:space-between;position:absolute;z-index:1;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:"→"}.sheet.has-guard{isolation:isolate}.sheet .sheet-guard{top:0;left:0;position:absolute;z-index:200;display:flex;width:100%;height:100%;align-items:center;justify-content:center;cursor:pointer;outline:0;background:rgba(28,34,48,0.16);opacity:0;pointer-events:none;transition:opacity .2s}.sheet .sheet-guard .hint{font-size:.9375rem;font-weight:600;color:#fff;background:rgba(20,25,40,0.94);border:1px solid rgba(255,255,255,0.14);border-radius:999px;padding:9px 20px;box-shadow:0 8px 24px rgba(20,25,40,0.3)}.sheet.guarded .sheet-guard{opacity:1;pointer-events:auto}
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var f,m,h,c;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},h=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},(c=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._ccfg="function"==typeof t.cellcfg?t.cellcfg:null,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","scroll-y","scroll-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","scroll-y","scroll-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.scrollbar=!!this.opt.scrollbar,this.enableScrolling=null==this.opt.enableScrolling||!!this.opt.enableScrolling,["x","y"].map(function(t){var e;e=document.createElement("div");if(e.classList.add("thumb"),i.dom["scroll-"+t].appendChild(e),i.dom["thumb-"+t]=e,!i.scrollbar)return i.dom["scroll-"+t].style.display="none"}),this.scrollbar&&this.dom.sheet.classList.add("has-scrollbar"),this.enableScrolling||this.dom.sheet.classList.add("no-scrolling"),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,d,s,a,r,n,l,u=this,h=0,c=this.dim.row;h<c;++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)}),(d=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(!(1<t.button)&&(u.dom.textarea.focus(),u.edited(),e=m(t.target,".cell",d))){if(!((o={row:(i=u.index(e)).row,col:i.col}).col<0||o.row<0))return t.shiftKey&&u.les.start?u.les.end=o:(u.les.start=u.les.end=o,u.les.node=e),u.renderSelection();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},u.renderSelection()}}),d.addEventListener("mousemove",function(t){var e;if(!(u._slider.y.on||u._slider.x.on||u._scrolling)&&!u.editing.on&&t.buttons&&(e=m(t.target,".cell",d)))return e={row:(t=u.index(e)).row,col:t.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})}),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,c;if(m(document.activeElement,".sheet",d)&&u.les.start&&(s=function(t,e){var i=-1,o=e.length>>>0;for(;++i<o;)if(t===e[i])return 1;return}("text/html",t.clipboardData.types||[])?(s=a(t.clipboardData.getData("text/html")),Array.from(s.querySelectorAll("tr")).map(function(t){return Array.from(t.querySelectorAll("th,td")).map(function(t){return t.textContent})})):(e=t.clipboardData.getData("text"),f(e)),u.set({row:u.les.start.row,col:u.les.start.col,data:s,range:!0,src:"user"}),u.sel.cut)){if(u._toText({sel:u.sel.cut})===e){for(i=(t=u._bound({sel:u.sel.cut})).sc,o=t.ec,s=t.sr,r=t.er,n=s;n<=r;++n)for(l=n,h=i;h<=o;++h)c=h,u.set({row:l,col:c,data:"",src:"user"});navigator.clipboard.writeText("")}return u.sel.cut=null,u.dom["range-cut"].classList.toggle("show",!1)}}),this.dom.textarea.addEventListener("keypress",function(t){var e;return(31!==(e=t.keyCode)&&61!==e&&67!==e&&88!==e||!t.metaKey&&!t.ctrlKey)&&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,s,r,n,l,h,c,d,a=t.keyCode;if(86!==t.keyCode||!t.metaKey&&!t.ctrlKey){if(!u.editing.on){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===a){if(!u.les.node)return;for(i=(e=u._bound()).sc,o=e.ec,d=e.sr,s=e.er,r=[],n=d;n<=s;++n){for(l=[],h=i;h<=o;++h)l.push("");r.push(l)}c=r,u.set({row:d,col:i,data:c,range:!0,src:"user"}),u.render()}if(189===a&&(t.metaKey||t.ctrlKey)&&u.slice(),187===a&&(t.metaKey||t.ctrlKey)&&u.insert(),d=function(){switch(a){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}}()){if(u.editing.on&&!u.editing.quick)return;u.move((d.select=t.shiftKey,d)),t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}if(u.les.node&&!u.editing.on)return 37!==(e=t.keyCode)&&38!==e&&39!==e&&40!==e&&9!==e&&16!==e&&18!==e&&91!==e&&27!==e&&17!==e&&(31!==(e=t.keyCode)&&61!==e&&67!==e&&88!==e||!t.metaKey&&!t.ctrlKey)?(u.edit({node:u.les.node,quick:13!==t.keyCode}),void(13===t.keyCode&&t.preventDefault())):void 0;if(u.editing.on){if(27===t.keyCode)u.edited({cancel:!0});else{if(13!==t.keyCode||t.altKey||t.metaKey)return 13===t.keyCode&&(t.altKey||t.metaKey)?(u.dom.textarea.value+="\n",u.dom.layout.textContent=u.dom.textarea.value+" ",c=u.dom.layout.getBoundingClientRect(),d=u.editing.node.getBoundingClientRect(),(e=u.dom.textarea.style).width=Math.max(c.width,d.width+1)+"px",e.height=Math.max(c.height,d.height+1)+"px",e):void 0;u.move({y:1,x:0})}t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}}}}),(r=this)._slider={hc:function(t){var e=t.target.getBoundingClientRect(),e=e[this.t[3]]+e[this.t[4]]/2,t=this.dir*Math.sign(t[this.t[2]]-e);return r[t<0?this.t[1]:this.t[0]](1),r.renderSelection()},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){var e;if(this.on)return t=this.p-t[this.t[2]],(e=500<(e=Math.abs(t))?10:300<e?5:150<e?2:100<e?1:.3)<1&&(e=Math.random()<e?1:0),0<(t=Math.sign(t)*this.dir*e)&&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","y","height"],dir:-1}).hd=(l=this._slider).hd,n.hu=l.hu,n.hm=l.hm,n.hc=l.hc,n),this._slider.x=((l={n:"slide-x",on:!1,p:0,t:["_mr","_ml","clientX","x","width"],dir:1}).hd=(n=this._slider).hd,l.hu=n.hu,l.hm=n.hm,l.hc=n.hc,l),["x","y"].map(function(e){return u.dom[u._slider[e].n].addEventListener("mousedown",function(t){return u._slider[e].hd(t)}),u.dom[u._slider[e].n].addEventListener("click",function(t){return u._slider[e].hc(t)})}),this.scrollbar&&(["x","y"].map(function(n){return u.dom["scroll-"+n].addEventListener("mousedown",function(t){var e,i,o,s,r;return t.preventDefault(),t.stopPropagation(),t.target===u.dom["thumb-"+n]?u._scrollDrag(n,t):(i=(e="y"===n?["row","clientY"]:["col","clientX"])[0],o=e[1],s=u.dom["thumb-"+n].getBoundingClientRect(),r=u._scrollInfo(i),t=t[o]<s["y"===n?"top":"left"]?-1:1,u._scrollTo(i,u.pos[i]+t*(1<(e=r.vis)?e:1),r))})}),null!=window.ResizeObserver)&&(this._ro=new ResizeObserver(function(){return u.renderScrollbar()}),this._ro.observe(this.dom.sheet)),document.addEventListener("wheel",function(t){var e,i,o,s,r=u.eventInScope(t);if(u.enableScrolling)return(null==u.opt.scrollLock||u.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!r&&t.target!==document.body||t.preventDefault()),!!r&&(r=u.scrollPos,e=(s=[t.deltaX,t.deltaY])[0],i=s[1],t.shiftKey&&Math.abs(i)>Math.abs(e)&&(e=(s=[i,0])[0],i=s[1]),e=(s=Math.abs(e)>Math.abs(i)?[e,0]:[0,i])[0],i=s[1],o=(s=[r.x,r.y])[0],s=s[1],r.x+=e/30,r.y+=i/30,e=Math.round(r.x)-Math.round(o),0<(i=Math.round(r.y)-Math.round(s))?u._md(i):i<0?u._mu(i):0<e?u._mr(e):e<0&&u._ml(e),u.renderSelection(),t.preventDefault())},{passive:!1}),this.renderScrollbar()},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=(e=[(e=(t=null==t?{}:t).sel||this.les).start,e.end])[1];return(s=e[0])&&r?(i=(e=s.col<r.col||null==r.col?[s.col,r.col]:[r.col,s.col])[0],o=e[1],r=(e=s.row<r.row||null==r.row?[s.row,r.row]:[r.row,s.row])[0],s=e[1],null!=t.defined&&!t.defined||(null==o&&(o=this._dataSize("col")-1),null!=s)||(s=this._dataSize("row")-1),{sc:i,ec:o,sr:r,er:s}):{sc:0,ec:0,sr:0,er:0}},_toText:function(t){var e,i,o,s,r,n,l,h,c,d,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=[],c=o;c<=s;++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())},_template:function(o){var e=this;return[0<this.xif[o][1]?"repeat("+this.xif[o][1]+", max-content)":"",function(){for(var t=[],e=0,i=this.frozen[o];e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size[o][t]||"max-content"}).join(" "),function(){for(var t=[],e=this.xif[o][2],i=this.dim[o];e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size[o][t+e.pos[o]-e.xif[o][1]]||"max-content"}).join(" ")].filter(function(t){return t}).join(" ")},regrid:function(){return this.dom.inner.style.gridTemplateColumns=this._template("col"),this.dom.inner.style.gridTemplateRows=this._template("row")},_viewport:function(){for(var t,e,i,o=this.dom.sheet.getBoundingClientRect(),s=this.dom.inner,r={row:0,col:0},n=this.xif.row[2],l=this.dim.row;n<l&&(t=n,e=s.childNodes[t*this.dim.col])&&!(e.getBoundingClientRect().top>=o.bottom);++n)r.row++;for(n=this.xif.col[2],l=this.dim.col;n<l&&(i=n,e=s.childNodes[i])&&!(e.getBoundingClientRect().left>=o.right);++n)r.col++;return r},_dataSize:function(t){var e,i,o,s,r,n;if("col"===t){for(i=e=0,s=(o=this._data).length;i<s;++i)(r=o[i])&&r.length>e&&(e=r.length);return e}for(n=this._data.length;0<n&&!(this._data[n-1]||[]).length;)n--;return n},_scrollInfo:function(t){var e=this._viewport()[t],t=this._dataSize(t);return{vis:e,total:t,extent:t+e,max:t}},_scrollTo:function(t,e,i){var o;if(null==i&&(i=this._scrollInfo(t)),(e=0<(o=(o=Math.round(e))<(i=i.max)?o:i)?o:0)!==this.pos[t])return this.goto("row"===t?{row:e}:{col:e})},_scrollMetric:function(t,e){var i="y"===t?"height":"width",t=this.dom["scroll-"+t].getBoundingClientRect()[i];return 0<t&&0<e.extent?{dim:i,len:t,size:i=(e=20<(i=t*(e.vis/e.extent))?i:20)<t?e:t,span:t-i}:null},_scrollDrag:function(e,t){var i,o,s,r,n,l=this,h="y"===e?["row","clientY"]:["col","clientX"],c=h[0],d=h[1],a=this._scrollInfo(c);if((i=this._scrollMetric(e,a))&&!(i.span<=0||a.max<=0))return h=[t[d],(h=this.pos[c])<(t=a.max)?h:t],o=h[0],s=h[1],r=function(t){return l._scrollTo(c,s+(t[d]-o)/i.span*a.max,a)},n=function(t){return l._scrolling=!1,l.dom["scroll-"+e].classList.remove("active"),document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",n)},this._scrolling=!0,this.dom["scroll-"+e].classList.add("active"),document.addEventListener("mousemove",r),document.addEventListener("mouseup",n)},renderScrollbar:function(){var l=this;if(this.scrollbar)return[["row","y","top"],["col","x","left"]].map(function(t){var e=t[0],i=t[1],t=t[2],o=[l.dom["scroll-"+i],l.dom["thumb-"+i]],s=o[0],r=o[1],n=l._scrollInfo(e);if(i=l._scrollMetric(i,n))return s.classList.toggle("idle",n.max<=0),r.style[i.dim]=i.size+"px",r.style[t]=(n.max<=0?0:i.span*((o=l.pos[e]/n.max)<1?o:1))+"px";s.classList.add("idle")})},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,c,d=t.row,a=t.col,u=t.data,f=t.range,m=t.src;if(f)for(e=!1,o=0,s=(u=JSON.parse(JSON.stringify(u))).length;o<s;++o)for(n=0,l=u[r=o].length;n<l;++n)h=n,m&&this._ccfg&&this._ccfg({row:d+r,col:a+h,type:"readonly"})?u[r][h]=((i=this._data)[c=r+d]||(i[c]=[]))[h+a]:(e=!0,((i=this._data)[c=r+d]||(i[c]=[]))[h+a]=u[r][h],this._content({y:r+d-this.pos.row+this.xif.row[1],x:h+a-this.pos.col+this.xif.col[1]}));else{if(m&&this._ccfg&&this._ccfg({row:d,col:a,type:"readonly"}))return;e=!0,((i=this._data)[d]||(i[d]=[]))[a]=u,this._content({y:d-this.pos.row+this.xif.row[1],x:a-this.pos.col+this.xif.col[1]})}if(e)return this.fire("change",{row:d,col:a,data:u,range:!!f})},_content:function(t){var e,i,o,s,r,n=t.x,l=t.y,t=t.n;if(t||(t=this.dom.inner.childNodes[n+l*this.dim.col]))return e=(r=n<this.xif.col[0]&&l<this.xif.col[0]?["","cell idx"]:n<this.xif.col[0]?[l<this.xif.row[1]?" ":l<this.xif.row[2]?l-this.xif.row[1]+1:l-this.xif.row[1]+this.pos.row+1,"cell idx"]:l<this.xif.row[0]?[n<this.xif.col[1]?" ":n<this.xif.col[2]?h(n-this.xif.col[1]):h(n-this.xif.col[1]+this.pos.col),"cell idx"]:n<this.xif.col[1]||l<this.xif.row[1]?[null,"cell fixed"]:n<this.xif.col[2]&&l<this.xif.row[2]?[((r=this._data)[e=l-this.xif.row[1]]||(r[e]=[]))[n-this.xif.col[1]],"cell frozen fixed"]:n<this.xif.col[2]?[((r=this._data)[e=this.pos.row+l-this.xif.row[1]]||(r[e]=[]))[n-this.xif.col[1]],"cell frozen"]:l<this.xif.row[2]?[((r=this._data)[e=l-this.xif.row[1]]||(r[e]=[]))[this.pos.col+n-this.xif.col[1]],"cell frozen"]:[((r=this._data)[e=this.pos.row+l-this.xif.row[1]]||(r[e]=[]))[this.pos.col+n-this.xif.col[1]],"cell"])[0],r=r[1],null==e&&(e=""),i=/frozen/.exec(r),o=n>=this.xif.col[0]&&l>=this.xif.row[0]?(this.cls.col[(i?0:this.pos.col)+n-this.xif.col[1]]||"")+" "+(this.cls.row[(i?0:this.pos.row)+l-this.xif.row[1]]||""):"",s=this._ccfg&&this._ccfg({type:"class",col:(i?0:this.pos.col)+n-this.xif.col[1],row:(i?0:this.pos.row)+l-this.xif.row[1]})||"",t.className=[r,o,s].filter(function(t){return t.trim()}).join(" ").trim(),null!==e?"object"!=typeof e?(!this._ccfg||c._d3warning||isNaN(parseFloat(e))||(r=this._ccfg({type:"format",col:(i?0:this.pos.col)+n-this.xif.col[1],row:(i?0:this.pos.row)+l-this.xif.row[1]}))&&("undefined"!=typeof d3&&null!==d3&&d3.format?e=d3.format(r)(e):(console.warn("[@plotdb/sheet] cell format provided yet d3.format not available. skip formatting."),c._d3warning=!0)),t.textContent=e):"dom"===e.type?(t.textContent="",t.appendChild(e.node)):void 0:void 0},_md:function(t){var e,i,o,s,r,n,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(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,c=document.createElement("div"),this._content({x:l,y:this.dim.row+s,n:c}),e.appendChild(c);return this.pos.row+=t,this.renderScrollbar()},_mu:function(t){var e,i,o,s,r,n,l,h,c;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,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}),e.insertBefore(c,e.childNodes[h+(r-i)*this.dim.col+this.dim.col*this.xif.row[2]]);return this.renderScrollbar()}},_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(),this.renderScrollbar()},_ml:function(t){var e,i,o,s,r,n,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,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]),c=document.createElement("div"),this._content({x:r+this.xif.col[2],y:h,n:c}),e.insertBefore(c,e.childNodes[h*this.dim.col+this.xif.col[2]+r-i]);return this.regrid(),this.renderScrollbar()}},goto:function(t){return o(this.pos,t=null==t?{row:0,col:0}:t),this.regrid(),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(),this.renderScrollbar()},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),r=e.getBoundingClientRect(),o=this.dom.sheet.getBoundingClientRect(),r.x+r.width>o.x+o.width&&this._mr(1),r.y+r.height>o.y+o.height&&this._md(1),i.x<=this.frozen.col)if(0<this.pos.col)this._ml(1);else if(i.x<=0)return;if(i.y<=this.frozen.row)if(0<this.pos.row)this._mu(1);else if(i.y<=0)return;if((e=this.cell(t))||(e=this.cell({col:i.col,row:i.row})))return this.les.node=e,t.select?(r={col:(s=this.index(e)).col,row:s.row},this.les.end===this.les.start&&(this.les.end=JSON.parse(JSON.stringify(this.les.start))),r.col<this.les.start.col&&(r.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=r.col),r.row<this.les.start.row&&(r.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=r.row),r.col>this.les.start.col&&r.col>this.les.end.col&&((this.les.start.col<this.les.end.col?this.les.end:this.les.start).col=r.col),r.row>this.les.start.row&&r.row>this.les.end.row&&((this.les.start.row<this.les.end.row?this.les.end:this.les.start).row=r.row)):this.les.start=this.les.end={col:(s=this.index(e)).col,row:s.row},this.renderSelection()}},edit:function(t){var e,i,o,s,r,n,l=t.node,t=t.quick;if(this._editing&&!(!(e=this.index(l))||e.col<0||e.row<0||this._ccfg&&this._ccfg({row:e.row,col:e.col,type:"readonly"})))return(e=this.editing).node=l,e.quick=t,e.on=!0,this.dom.layout.textContent=l.textContent,i=this.dom.layout.getBoundingClientRect(),o=l.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),n=(e=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],r=e[1],(e=this.dom.edit.style).left=o.x-s.x+n-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=!t&&l.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,t=Array.from(this.dom.inner.childNodes).indexOf(t);return t<0?null:{x:e=t%this.dim.col,y:t=(t-e)/this.dim.col,col:e<this.xif.col[1]?-1:e<this.xif.col[2]?e-this.xif.col[1]:e-this.xif.col[1]+this.pos.col,row:t<this.xif.row[1]?-1:t<this.xif.row[2]?t-this.xif.row[1]:t-this.xif.row[1]+this.pos.row}},cell:function(t){var e,i,o=(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(!o)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(!o)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,c,d,a,u,f,m,w=this;if(null==e&&(e={}),(t=t||this.les).start)return n=(i=this._bound({defined:!1,sel:t})).sc,o=i.ec,h=i.sr,s=i.er,r=this.dom.inner.getBoundingClientRect(),m=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:n,row:h,roughly:!0}),this.cell({col:n,row:s,roughly:!0}),this.cell({col:o,row:h,roughly:!0}),this.cell({col:o,row:s,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],l=i[1],a=i[2],d=i[3],u=i[4],f=i[5],m.width=0,m.height=0,n=(l||a||(n>this.pos.col?f:m)).x-r.x,l=(l||d||(h>this.pos.row?f:m)).y-r.y,h=o-this.pos.col<0,c=s-this.pos.row<0,d=(d||u||f||m).x+(h?0:(d||u||f||m).width)-r.x-n+1,a=(a||u||f||m).y+(c?0:(a||u||f||m).height)-r.y-l+1,null==o&&(d=this.root.getBoundingClientRect().width),null==s&&(a=this.root.getBoundingClientRect().height),f=(u=this.les.node)?u.getBoundingClientRect():null,(i=(m=e.cut?this.dom["range-cut"]:this.dom.range).style).left=n+"px",i.top=l+"px",i.width=d+"px",i.height=a+"px",m.classList.toggle("show",!0),e.cut||(f&&((i=this.dom.caret.style).left=f.x-r.x-1+"px",i.top=f.y-r.y-1+"px",i.width=(h?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)),this.dom.textarea===document.activeElement?setTimeout(function(){return w.dom.textarea.focus({preventScroll:!0})},0):void 0;this.dom.caret.classList.toggle("show",!1),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=c:"undefined"!=typeof window&&null!==window&&(window.sheet=c)}.call(this);
|
|
1
|
+
!function(){var f,m,s,o;function n(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},s=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},(o=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._ccfg="function"==typeof t.cellcfg?t.cellcfg:null,this._dsp="function"==typeof t.display?t.display:null,this._data=t.data||[],this._size={row:(e=n({row:[],col:[]},t.size)).row,col:e.col},this.cls={row:(e=n({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=n({col:0,row:0},t.frozen||{})).col,row:e.row},this.idx={col:(e=n({row:!0,col:!0},t.idx||{})).col,row:e.row},this.fixed={col:(e=n({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","scroll-y","scroll-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","scroll-y","scroll-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.scrollbar=!!this.opt.scrollbar,this.enableScrolling=null==this.opt.enableScrolling||!!this.opt.enableScrolling,["x","y"].map(function(t){var e;e=document.createElement("div");if(e.classList.add("thumb"),i.dom["scroll-"+t].appendChild(e),i.dom["thumb-"+t]=e,!i.scrollbar)return i.dom["scroll-"+t].style.display="none"}),this.scrollbar&&this.dom.sheet.classList.add("has-scrollbar"),this.enableScrolling||this.dom.sheet.classList.add("no-scrolling"),this._guard=this.opt.guard?"object"==typeof this.opt.guard?this.opt.guard:{}:null,this._guard&&((t=this.dom.guard=document.createElement("div")).classList.add("sheet-guard"),t.setAttribute("tabindex",0),"function"==typeof this._guard.render?this._guard.render(this.dom.guard):((e=this.dom.guard.appendChild(document.createElement("div"))).classList.add("hint"),e.textContent=this._guard.text||"click to interact"),this.dom.sheet.classList.add("has-guard"),this.dom.sheet.appendChild(this.dom.guard)),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=n(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,s=[],n=[],l=1,d=arguments.length;l<d;++l)n.push(arguments[l]);for(e=n,l=0,o=(i=this.evtHandler[t]||[]).length;l<o;++l)r=i[l],s.push(r.apply(this,e));return s},_init:function(){for(var t,e,i,o,h,r,a,s,n,l,u=this,d=0,c=this.dim.row;d<c;++d)for(t=d,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)}),(h=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(!(1<t.button)&&(u.dom.textarea.focus(),u.edited(),e=m(t.target,".cell",h))){if(!((o={row:(i=u.index(e)).row,col:i.col}).col<0||o.row<0))return t.shiftKey&&u.les.start?u.les.end=o:(u.les.start=u.les.end=o,u.les.node=e),u.renderSelection();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},u.renderSelection()}}),h.addEventListener("mousemove",function(t){var e;if(!(u._slider.y.on||u._slider.x.on||u._scrolling)&&!u.editing.on&&t.buttons&&(e=m(t.target,".cell",h)))return e={row:(t=u.index(e)).row,col:t.col},u.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},u.renderSelection()}),h.addEventListener("dblclick",function(t){if(t=m(t.target,".cell",h))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,s,n,l,d,c;if(m(document.activeElement,".sheet",h)&&u.les.start&&(r=function(t,e){var i=-1,o=e.length>>>0;for(;++i<o;)if(t===e[i])return 1;return}("text/html",t.clipboardData.types||[])?(r=a(t.clipboardData.getData("text/html")),Array.from(r.querySelectorAll("tr")).map(function(t){return Array.from(t.querySelectorAll("th,td")).map(function(t){return t.textContent})})):(e=t.clipboardData.getData("text"),f(e)),u.set({row:u.les.start.row,col:u.les.start.col,data:r,range:!0,src:"user"}),u.sel.cut)){if(u._toText({sel:u.sel.cut})===e){for(i=(t=u._bound({sel:u.sel.cut})).sc,o=t.ec,r=t.sr,s=t.er,n=r;n<=s;++n)for(l=n,d=i;d<=o;++d)c=d,u.set({row:l,col:c,data:"",src:"user"});navigator.clipboard.writeText("")}return u.sel.cut=null,u.dom["range-cut"].classList.toggle("show",!1)}}),this.dom.textarea.addEventListener("keypress",function(t){var e;return(31!==(e=t.keyCode)&&61!==e&&67!==e&&88!==e||!t.metaKey&&!t.ctrlKey)&&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,r,s,n,l,d,c,h,a=t.keyCode;if(86!==t.keyCode||!t.metaKey&&!t.ctrlKey){if(!u.editing.on){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===a){if(!u.les.node)return;for(i=(e=u._bound()).sc,o=e.ec,h=e.sr,r=e.er,s=[],n=h;n<=r;++n){for(l=[],d=i;d<=o;++d)l.push("");s.push(l)}c=s,u.set({row:h,col:i,data:c,range:!0,src:"user"}),u.render()}if(189===a&&(t.metaKey||t.ctrlKey)&&u.slice(),187===a&&(t.metaKey||t.ctrlKey)&&u.insert(),h=function(){switch(a){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}}()){if(u.editing.on&&!u.editing.quick)return;u.move((h.select=t.shiftKey,h)),t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}if(u.les.node&&!u.editing.on)return 37!==(e=t.keyCode)&&38!==e&&39!==e&&40!==e&&9!==e&&16!==e&&18!==e&&91!==e&&27!==e&&17!==e&&(31!==(e=t.keyCode)&&61!==e&&67!==e&&88!==e||!t.metaKey&&!t.ctrlKey)?(u.edit({node:u.les.node,quick:13!==t.keyCode}),void(13===t.keyCode&&t.preventDefault())):void 0;if(u.editing.on){if(27===t.keyCode)u.edited({cancel:!0});else{if(13!==t.keyCode||t.altKey||t.metaKey)return 13===t.keyCode&&(t.altKey||t.metaKey)?(u.dom.textarea.value+="\n",u.dom.layout.textContent=u.dom.textarea.value+" ",c=u.dom.layout.getBoundingClientRect(),h=u.editing.node.getBoundingClientRect(),(e=u.dom.textarea.style).width=Math.max(c.width,h.width+1)+"px",e.height=Math.max(c.height,h.height+1)+"px",e):void 0;u.move({y:1,x:0})}t.stopPropagation(),t.preventDefault(),u.dom.textarea.focus()}}}}),(s=this)._slider={hc:function(t){var e=t.target.getBoundingClientRect(),e=e[this.t[3]]+e[this.t[4]]/2,t=this.dir*Math.sign(t[this.t[2]]-e);return s[t<0?this.t[1]:this.t[0]](1),s.renderSelection()},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){var e;if(this.on)return t=this.p-t[this.t[2]],(e=500<(e=Math.abs(t))?10:300<e?5:150<e?2:100<e?1:.3)<1&&(e=Math.random()<e?1:0),0<(t=Math.sign(t)*this.dir*e)&&s[this.t[1]](t),t<0&&s[this.t[0]](t),s.renderSelection()}},this._slider.y=((n={n:"slide-y",on:!1,p:0,t:["_mu","_md","clientY","y","height"],dir:-1}).hd=(l=this._slider).hd,n.hu=l.hu,n.hm=l.hm,n.hc=l.hc,n),this._slider.x=((l={n:"slide-x",on:!1,p:0,t:["_mr","_ml","clientX","x","width"],dir:1}).hd=(n=this._slider).hd,l.hu=n.hu,l.hm=n.hm,l.hc=n.hc,l),["x","y"].map(function(e){return u.dom[u._slider[e].n].addEventListener("mousedown",function(t){return u._slider[e].hd(t)}),u.dom[u._slider[e].n].addEventListener("click",function(t){return u._slider[e].hc(t)})}),this.scrollbar&&(["x","y"].map(function(n){return u.dom["scroll-"+n].addEventListener("mousedown",function(t){var e,i,o,r,s;return t.preventDefault(),t.stopPropagation(),t.target===u.dom["thumb-"+n]?u._scrollDrag(n,t):(i=(e="y"===n?["row","clientY"]:["col","clientX"])[0],o=e[1],r=u.dom["thumb-"+n].getBoundingClientRect(),s=u._scrollInfo(i),t=t[o]<r["y"===n?"top":"left"]?-1:1,u._scrollTo(i,u.pos[i]+t*(1<(e=s.vis)?e:1),s))})}),null!=window.ResizeObserver)&&(this._ro=new ResizeObserver(function(){return u.renderScrollbar()}),this._ro.observe(this.dom.sheet)),document.addEventListener("wheel",function(t){var e,i,o,r,s=u.eventInScope(t);if(u.enableScrolling&&!u._guardArmed)return(null==u.opt.scrollLock||u.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!s&&t.target!==document.body||t.preventDefault()),!!s&&(s=u.scrollPos,e=(r=[t.deltaX,t.deltaY])[0],i=r[1],t.shiftKey&&Math.abs(i)>Math.abs(e)&&(e=(r=[i,0])[0],i=r[1]),e=(r=Math.abs(e)>Math.abs(i)?[e,0]:[0,i])[0],i=r[1],o=(r=[s.x,s.y])[0],r=r[1],s.x+=e/30,s.y+=i/30,e=Math.round(s.x)-Math.round(o),0<(i=Math.round(s.y)-Math.round(r))?u._md(i):i<0?u._mu(i):0<e?u._mr(e):e<0&&u._ml(e),u.renderSelection(),t.preventDefault())},{passive:!1}),this.renderScrollbar(),this._initGuard()},_initGuard:function(){var t,e,i,o=this;if(this._guard)return t=null!=this._guard.delay?this._guard.delay:2e3,i=function(){return o._guardTimer&&clearTimeout(o._guardTimer),o._guardTimer=setTimeout(function(){return o.guard(!0)},t)},this.dom.guard.addEventListener("click",e=function(t){return t.preventDefault(),t.stopPropagation(),o.guard(!1)}),this.dom.guard.addEventListener("keydown",function(t){if(13===t.keyCode||32===t.keyCode)return e(t)}),this.dom.sheet.addEventListener("mouseleave",i),this.dom.sheet.addEventListener("mouseenter",function(){if(o._guardTimer)return clearTimeout(o._guardTimer),o._guardTimer=null}),document.addEventListener("pointerdown",function(t){if(!o.guard()&&!o.eventInScope(t))return i()},{passive:!0}),this.guard(!0)},guard:function(t){return null==t?!!this._guardArmed:this._guard?(this._guardTimer&&(clearTimeout(this._guardTimer),this._guardTimer=null),this._guardArmed=t=!!t,this.dom.sheet.classList.toggle("guarded",t),this.dom.sheet.classList.toggle("no-scrolling",t||!this.enableScrolling),this.fire("guard",t)):void 0},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,s=(e=[(e=(t=null==t?{}:t).sel||this.les).start,e.end])[1];return(r=e[0])&&s?(i=(e=r.col<s.col||null==s.col?[r.col,s.col]:[s.col,r.col])[0],o=e[1],s=(e=r.row<s.row||null==s.row?[r.row,s.row]:[s.row,r.row])[0],r=e[1],null!=t.defined&&!t.defined||(null==o&&(o=this._dataSize("col")-1),null!=r)||(r=this._dataSize("row")-1),{sc:i,ec:o,sr:s,er:r}):{sc:0,ec:0,sr:0,er:0}},_toText:function(t){var e,i,o,r,s,n,l,d,c,h,t=t.sel;if(!t||!t.start)return"";for(e=[],o=(i=this._bound({sel:t})).sc,r=i.ec,t=i.sr,s=i.er,n=t;n<=s;++n){for(l=n,d=[],c=o;c<=r;++c)h=c,"object"!=typeof(h=null==(h=((i=this._data)[l]||(i[l]=[]))[h])?"":h)&&d.push('"'+(""+h||"").replace(/"/g,'""')+'"');e.push(d.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=n({row:[],col:[]},t)).row,col:t.col},this.regrid())},_template:function(o){var e=this;return[0<this.xif[o][1]?"repeat("+this.xif[o][1]+", max-content)":"",function(){for(var t=[],e=0,i=this.frozen[o];e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size[o][t]||"max-content"}).join(" "),function(){for(var t=[],e=this.xif[o][2],i=this.dim[o];e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size[o][t+e.pos[o]-e.xif[o][1]]||"max-content"}).join(" ")].filter(function(t){return t}).join(" ")},regrid:function(){return this.dom.inner.style.gridTemplateColumns=this._template("col"),this.dom.inner.style.gridTemplateRows=this._template("row")},_viewport:function(){for(var t,e,i,o=this.dom.sheet.getBoundingClientRect(),r=this.dom.inner,s={row:0,col:0},n=this.xif.row[2],l=this.dim.row;n<l&&(t=n,e=r.childNodes[t*this.dim.col])&&!(e.getBoundingClientRect().top>=o.bottom);++n)s.row++;for(n=this.xif.col[2],l=this.dim.col;n<l&&(i=n,e=r.childNodes[i])&&!(e.getBoundingClientRect().left>=o.right);++n)s.col++;return s},_dataSize:function(t){var e,i,o,r,s,n;if("col"===t){for(i=e=0,r=(o=this._data).length;i<r;++i)(s=o[i])&&s.length>e&&(e=s.length);return e}for(n=this._data.length;0<n&&!(this._data[n-1]||[]).length;)n--;return n},_scrollInfo:function(t){var e=this._viewport()[t],t=this._dataSize(t);return{vis:e,total:t,extent:t+e,max:t}},_scrollTo:function(t,e,i){var o;if(null==i&&(i=this._scrollInfo(t)),(e=0<(o=(o=Math.round(e))<(i=i.max)?o:i)?o:0)!==this.pos[t])return this.goto("row"===t?{row:e}:{col:e})},_scrollMetric:function(t,e){var i="y"===t?"height":"width",t=this.dom["scroll-"+t].getBoundingClientRect()[i];return 0<t&&0<e.extent?{dim:i,len:t,size:i=(e=20<(i=t*(e.vis/e.extent))?i:20)<t?e:t,span:t-i}:null},_scrollDrag:function(e,t){var i,o,r,s,n,l=this,d="y"===e?["row","clientY"]:["col","clientX"],c=d[0],h=d[1],a=this._scrollInfo(c);if((i=this._scrollMetric(e,a))&&!(i.span<=0||a.max<=0))return d=[t[h],(d=this.pos[c])<(t=a.max)?d:t],o=d[0],r=d[1],s=function(t){return l._scrollTo(c,r+(t[h]-o)/i.span*a.max,a)},n=function(t){return l._scrolling=!1,l.dom["scroll-"+e].classList.remove("active"),document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",n)},this._scrolling=!0,this.dom["scroll-"+e].classList.add("active"),document.addEventListener("mousemove",s),document.addEventListener("mouseup",n)},renderScrollbar:function(){var l=this;if(this.scrollbar)return[["row","y","top"],["col","x","left"]].map(function(t){var e=t[0],i=t[1],t=t[2],o=[l.dom["scroll-"+i],l.dom["thumb-"+i]],r=o[0],s=o[1],n=l._scrollInfo(e);if(i=l._scrollMetric(i,n))return r.classList.toggle("idle",n.max<=0),s.style[i.dim]=i.size+"px",s.style[t]=(n.max<=0?0:i.span*((o=l.pos[e]/n.max)<1?o:1))+"px";r.classList.add("idle")})},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,s,n,l,d,c,h=t.row,a=t.col,u=t.data,f=t.range,m=t.src;if(f)for(e=!1,o=0,r=(u=JSON.parse(JSON.stringify(u))).length;o<r;++o)for(n=0,l=u[s=o].length;n<l;++n)d=n,m&&this._ccfg&&this._ccfg({row:h+s,col:a+d,type:"readonly"})?u[s][d]=((i=this._data)[c=s+h]||(i[c]=[]))[d+a]:(e=!0,((i=this._data)[c=s+h]||(i[c]=[]))[d+a]=u[s][d],this._content({y:s+h-this.pos.row+this.xif.row[1],x:d+a-this.pos.col+this.xif.col[1]}));else{if(m&&this._ccfg&&this._ccfg({row:h,col:a,type:"readonly"}))return;e=!0,((i=this._data)[h]||(i[h]=[]))[a]=u,this._content({y:h-this.pos.row+this.xif.row[1],x:a-this.pos.col+this.xif.col[1]})}if(e)return this.fire("change",{row:h,col:a,data:u,range:!!f})},_coord:function(t,e){var i,o=[t<this.xif.col[2],e<this.xif.row[2]],r=o[0],o=o[1],s={x:t,y:e,col:(r?0:this.pos.col)+t-this.xif.col[1],row:(o?0:this.pos.row)+e-this.xif.row[1],frozen:{col:r,row:o}};return t<this.xif.col[0]||e<this.xif.row[0]?(i=t>=this.xif.col[0]?"col":e>=this.xif.row[0]?"row":null,s.type="idx",s.axis=i,s.className="cell idx",s):t<this.xif.col[1]||e<this.xif.row[1]?(s.type="fixed",s.className="cell fixed",s):n(s,{type:"cell",className:r&&o?"cell frozen fixed":r||o?"cell frozen":"cell"})},_format:function(t,e){var i=e.row,e=e.col;if(this._ccfg&&!o._d3warning&&!isNaN(parseFloat(t))&&(i=this._ccfg({type:"format",row:i,col:e}))){if("undefined"!=typeof d3&&null!==d3&&d3.format)return d3.format(i)(t);console.warn("[@plotdb/sheet] cell format provided yet d3.format not available. skip formatting."),o._d3warning=!0}return t},_display:function(t,e){var i=e.row,e=e.col,t=this._dsp?this._dsp({raw:t,row:i,col:e}):t;return this._format(t,{row:i,col:e})},_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 null==(r="idx"===(e=this._coord(o,r)).type?"row"===e.axis?r<this.xif.row[1]?" ":e.row+1:"col"===e.axis?o<this.xif.col[1]?" ":s(e.col):"":"fixed"===e.type?"":this._display(((r=this._data)[o=e.row]||(r[o]=[]))[e.col],e))&&(r=""),o="idx"===e.type?"":(this.cls.col[e.col]||"")+" "+(this.cls.row[e.row]||""),i=(this._ccfg?this._ccfg({type:"class",row:e.row,col:e.col}):"")||"",t.className=[e.className,o,i].filter(function(t){return t.trim()}).join(" ").trim(),"object"!=typeof r?t.textContent=r:"dom"===r.type?(t.textContent="",t.appendChild(r.node)):void 0},_md:function(t){var e,i,o,r,s,n,l,d,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,s=0,n=this.dim.col;s<n&&(l=s,d=this.dim.col*this.fix.row,e.childNodes[d]);++s)e.removeChild(e.childNodes[d]);for(o=i;o<t;++o)for(r=o,s=0,n=this.dim.col;s<n;++s)l=s,c=document.createElement("div"),this._content({x:l,y:this.dim.row+r,n:c}),e.appendChild(c);return this.pos.row+=t,this.renderScrollbar()},_mu:function(t){var e,i,o,r,s,n,l,d,c;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(s=r,n=0,l=this.dim.col;n<l&&(d=n,e.childNodes.length);++n)e.removeChild(e.childNodes[e.childNodes.length-1]);for(this.pos.row-=t,r=i;r<t;++r)for(s=r,n=0,l=this.dim.col;n<l;++n)d=n,c=document.createElement("div"),this._content({x:d,y:s+this.xif.row[2],n:c}),e.insertBefore(c,e.childNodes[d+(s-i)*this.dim.col+this.dim.col*this.xif.row[2]]);return this.renderScrollbar()}},_mr:function(t){var e,i,o,r,s,n,l,d;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,s=0,n=this.dim.row;s<n;++s)l=s,e.removeChild(e.childNodes[l*this.dim.col+this.fix.col]),d=document.createElement("div"),this._content({x:this.dim.col+r,y:l,n:d}),e.insertBefore(d,e.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid(),this.renderScrollbar()},_ml:function(t){var e,i,o,r,s,n,l,d,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(s=r,n=0,l=this.dim.row;n<l;++n)d=n,e.removeChild(e.childNodes[(d+1)*this.dim.col-1]),c=document.createElement("div"),this._content({x:s+this.xif.col[2],y:d,n:c}),e.insertBefore(c,e.childNodes[d*this.dim.col+this.xif.col[2]+s-i]);return this.regrid(),this.renderScrollbar()}},goto:function(t){return n(this.pos,t=null==t?{row:0,col:0}:t),this.regrid(),this.render()},render:function(){for(var t,e,i,o,r=0,s=this.dim.row;r<s;++r)for(t=r,e=0,i=this.dim.col;e<i;++e)o=e,this._content({x:o,y:t});return this.renderSelection(),this.renderScrollbar()},move:function(t){var e,i,o,r,s;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(e=this.cell(t))){if(i=this.index(e),s=e.getBoundingClientRect(),o=this.dom.sheet.getBoundingClientRect(),s.x+s.width>o.x+o.width&&this._mr(1),s.y+s.height>o.y+o.height&&this._md(1),i.x<=this.frozen.col)if(0<this.pos.col)this._ml(1);else if(i.x<=0)return;if(i.y<=this.frozen.row)if(0<this.pos.row)this._mu(1);else if(i.y<=0)return;if((e=this.cell(t))||(e=this.cell({col:i.col,row:i.row})))return this.les.node=e,t.select?(s={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))),s.col<this.les.start.col&&(s.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=s.col),s.row<this.les.start.row&&(s.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=s.row),s.col>this.les.start.col&&s.col>this.les.end.col&&((this.les.start.col<this.les.end.col?this.les.end:this.les.start).col=s.col),s.row>this.les.start.row&&s.row>this.les.end.row&&((this.les.start.row<this.les.end.row?this.les.end:this.les.start).row=s.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,r,s,n,l=t.node,t=t.quick;if(this._editing&&!(!(e=this.index(l))||e.col<0||e.row<0||this._ccfg&&this._ccfg({row:e.row,col:e.col,type:"readonly"})))return e=null==(e=(this._data[e.row]||[])[e.col])?"":"object"==typeof e?l.textContent||"":""+e,(i=this.editing).node=l,i.quick=t,i.on=!0,this.dom.layout.textContent=e,o=this.dom.layout.getBoundingClientRect(),l=l.getBoundingClientRect(),r=this.dom.sheet.getBoundingClientRect(),n=(i=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],s=i[1],(i=this.dom.edit.style).left=l.x-r.x+n-2+"px",i.top=l.y-r.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,l.width+1)+"px",i.height=Math.max(o.height,l.height+1)+"px",this.dom.textarea.value=n=t?"":e,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,t=Array.from(this.dom.inner.childNodes).indexOf(t);return t<0?null:(e=t%this.dim.col,{x:(t=this._coord(e,(t-e)/this.dim.col)).x,y:t.y,col:t.x<this.xif.col[1]?-1:t.col,row:t.y<this.xif.row[1]?-1:t.row})},cell:function(t){var e,i,o=(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(!o)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(!o)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,s,n,l,d,c,h,a,u,f,m,w=this;if(null==e&&(e={}),(t=t||this.les).start)return n=(i=this._bound({defined:!1,sel:t})).sc,o=i.ec,d=i.sr,r=i.er,s=this.dom.inner.getBoundingClientRect(),m=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:n,row:d,roughly:!0}),this.cell({col:n,row:r,roughly:!0}),this.cell({col:o,row:d,roughly:!0}),this.cell({col:o,row:r,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],l=i[1],a=i[2],h=i[3],u=i[4],f=i[5],m.width=0,m.height=0,n=(l||a||(n>this.pos.col?f:m)).x-s.x,l=(l||h||(d>this.pos.row?f:m)).y-s.y,d=o-this.pos.col<0,c=r-this.pos.row<0,h=(h||u||f||m).x+(d?0:(h||u||f||m).width)-s.x-n+1,a=(a||u||f||m).y+(c?0:(a||u||f||m).height)-s.y-l+1,null==o&&(h=this.root.getBoundingClientRect().width),null==r&&(a=this.root.getBoundingClientRect().height),f=(u=this.les.node)?u.getBoundingClientRect():null,(i=(m=e.cut?this.dom["range-cut"]:this.dom.range).style).left=n+"px",i.top=l+"px",i.width=h+"px",i.height=a+"px",m.classList.toggle("show",!0),e.cut||(f&&((i=this.dom.caret.style).left=f.x-s.x-1+"px",i.top=f.y-s.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)),this.dom.textarea===document.activeElement?setTimeout(function(){return w.dom.textarea.focus({preventScroll:!0})},0):void 0;this.dom.caret.classList.toggle("show",!1),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=o:"undefined"!=typeof window&&null!==window&&(window.sheet=o)}.call(this);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.7.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.7.7","style":"index.min.css","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/sheet","repository":{"type":"git","url":"git+https://github.com/plotdb/sheet.git"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","deploy":"npx deploy web/static"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.12","@loadingio/debounce.js":"1.0.1","@loadingio/ldquery":"^3.0.6","@plotdb/csscope":"^5.0.4","@plotdb/datadom":"^0.2.0","@plotdb/guides":"github:plotdb/guides#master","@plotdb/json0":"^0.0.5","@plotdb/rescope":"^5.0.17","@zbryikt/template":"^2.4.3","body-parser":"^1.19.0","bootstrap":"^4.6.1","bootstrap.native":"^3.0.13","d3-format":"^3.1.0","dompurify":"^3.4.10","fedep":"^1.7.6","jsoneditor":"^9.1.1","ldcover":"^3.6.0","ldiconfont":"^0.3.0","ldview":"^1.7.2","livescript":"^1.6.0","papaparse":"^5.4.1","proxise":"^1.0.1","sharedb-wrapper":"^1.0.0","stylus":"^0.55.0","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","d3-format","dompurify","ldview","ldcover","jsoneditor","ldiconfont","proxise","papaparse","@plotdb/datadom","@plotdb/csscope","@plotdb/rescope","sharedb-wrapper","@plotdb/json0"]}}
|