@plotdb/sheet 0.7.7 → 0.8.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 -0
- package/index.css +48 -0
- package/index.js +210 -14
- 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.8.0
|
|
4
|
+
|
|
5
|
+
- add `options` to `cellcfg`: a cell returning a list of options ( `{value, label}` or
|
|
6
|
+
strings ) becomes a pick list. it stores the value and shows the label, and editing
|
|
7
|
+
opens the list below the cell - typing narrows it down, up / down picks, enter or a
|
|
8
|
+
click commits, esc cancels. typed or pasted text naming an option by value or label
|
|
9
|
+
is stored as its value; anything else is kept and marked with an `invalid` class.
|
|
10
|
+
- user input ( editing, pasting ) now goes through `set` with `src`, so a committed edit
|
|
11
|
+
also honours `readonly`.
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
## v0.7.7
|
|
4
15
|
|
|
5
16
|
- add `guard` option: a click-to-interact overlay over the sheet. the sheet takes the
|
package/README.md
CHANGED
|
@@ -91,6 +91,17 @@ initialize:
|
|
|
91
91
|
- `readonly`: return true if the given cell should be readonly.
|
|
92
92
|
- `format`: return cell format for number. Use `d3-format` syntax.
|
|
93
93
|
- depends on `d3.format`. if not available, no formatting will be applied.
|
|
94
|
+
- `options`: return a list of options to make the cell a pick list, or nothing for a
|
|
95
|
+
plain cell. each option is either `{value, label}` or a string, standing for both.
|
|
96
|
+
- the cell stores `value` and shows `label`. `display` and `format` don't apply to
|
|
97
|
+
a cell showing an option label.
|
|
98
|
+
- editing ( double click, enter, or simply typing ) opens the list below the cell.
|
|
99
|
+
typing narrows it down, up / down picks, enter or a click commits, esc cancels.
|
|
100
|
+
- typed and pasted text naming an option, by value or by label ( case and
|
|
101
|
+
surrounding space ignored ), is stored as its value. anything else is kept as is,
|
|
102
|
+
and the cell gets an `invalid` class - checking the data is up to you.
|
|
103
|
+
- cells with options get a `has-options` class.
|
|
104
|
+
- this is per cell, so returning nothing for a header row keeps it a plain cell.
|
|
94
105
|
|
|
95
106
|
|
|
96
107
|
## API
|
package/index.css
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
/* with `enableScrolling: false` we no longer take the wheel, so the page should get it.
|
|
10
10
|
the horizontal axis keeps `contain` - that is the axis the swipe back gesture lives on,
|
|
11
11
|
and nothing here scrolls horizontally either way. */
|
|
12
|
+
/* cells with options ( see `options` in cellcfg ): a hint they take a pick, and a
|
|
13
|
+
mark on those holding something no option stands for. */
|
|
12
14
|
}
|
|
13
15
|
.sheet.no-scrolling {
|
|
14
16
|
overscroll-behavior-y: auto;
|
|
@@ -103,6 +105,52 @@
|
|
|
103
105
|
border: none;
|
|
104
106
|
outline: none;
|
|
105
107
|
}
|
|
108
|
+
.sheet .cell.has-options {
|
|
109
|
+
padding-right: 14px;
|
|
110
|
+
}
|
|
111
|
+
.sheet .cell.has-options:after {
|
|
112
|
+
content: "▾";
|
|
113
|
+
position: absolute;
|
|
114
|
+
top: 0;
|
|
115
|
+
right: 3px;
|
|
116
|
+
line-height: inherit;
|
|
117
|
+
font-size: 0.75em;
|
|
118
|
+
color: #aaa;
|
|
119
|
+
}
|
|
120
|
+
.sheet .cell.invalid {
|
|
121
|
+
color: #d33;
|
|
122
|
+
background: #fff3f3;
|
|
123
|
+
}
|
|
124
|
+
.sheet .options {
|
|
125
|
+
top: 0;
|
|
126
|
+
left: 0;
|
|
127
|
+
position: absolute;
|
|
128
|
+
z-index: 125;
|
|
129
|
+
display: none;
|
|
130
|
+
max-height: 12em;
|
|
131
|
+
overflow-y: auto;
|
|
132
|
+
overscroll-behavior: contain;
|
|
133
|
+
box-sizing: border-box;
|
|
134
|
+
padding: 2px 0;
|
|
135
|
+
background: #fff;
|
|
136
|
+
border: 1px solid #bbb;
|
|
137
|
+
border-radius: 3px;
|
|
138
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.12);
|
|
139
|
+
}
|
|
140
|
+
.sheet .options .option {
|
|
141
|
+
padding: 0 10px;
|
|
142
|
+
line-height: 26px;
|
|
143
|
+
white-space: nowrap;
|
|
144
|
+
cursor: pointer;
|
|
145
|
+
user-select: none;
|
|
146
|
+
}
|
|
147
|
+
.sheet .options .option:hover {
|
|
148
|
+
background: #f1f2f3;
|
|
149
|
+
}
|
|
150
|
+
.sheet .options .option.active {
|
|
151
|
+
background: #27f;
|
|
152
|
+
color: #fff;
|
|
153
|
+
}
|
|
106
154
|
.sheet .layout {
|
|
107
155
|
display: inline-block;
|
|
108
156
|
top: 0;
|
package/index.js
CHANGED
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
};
|
|
136
136
|
this.les = {};
|
|
137
137
|
this.editing = {};
|
|
138
|
-
this.dom = Object.fromEntries(['sheet', 'inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x', 'scroll-y', 'scroll-x'].map(function(it){
|
|
138
|
+
this.dom = Object.fromEntries(['sheet', 'inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x', 'scroll-y', 'scroll-x', 'options'].map(function(it){
|
|
139
139
|
var x$, n;
|
|
140
140
|
x$ = n = document.createElement('div');
|
|
141
141
|
x$.classList.add(it);
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
this.dom.sheet.setAttribute('tabindex', -1);
|
|
145
145
|
this.dom.textarea = document.createElement('textarea');
|
|
146
146
|
this.root.appendChild(this.dom.sheet);
|
|
147
|
-
['inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x', 'scroll-y', 'scroll-x'].map(function(it){
|
|
147
|
+
['inner', 'caret', 'range', 'edit', 'layout', 'range-cut', 'slide-y', 'slide-x', 'scroll-y', 'scroll-x', 'options'].map(function(it){
|
|
148
148
|
return this$.dom.sheet.appendChild(this$.dom[it]);
|
|
149
149
|
});
|
|
150
150
|
if (!this.opt.slider) {
|
|
@@ -222,6 +222,23 @@
|
|
|
222
222
|
this.dom.textarea.addEventListener('mousedown', function(e){
|
|
223
223
|
return e.stopPropagation();
|
|
224
224
|
});
|
|
225
|
+
this.dom.options.addEventListener('mousedown', function(e){
|
|
226
|
+
var n;
|
|
227
|
+
e.stopPropagation();
|
|
228
|
+
e.preventDefault();
|
|
229
|
+
if (!(n = parent(e.target, '.option', this$.dom.options))) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
this$.editing.hi = +n.dataset.idx;
|
|
233
|
+
this$.edited();
|
|
234
|
+
return this$.renderSelection();
|
|
235
|
+
});
|
|
236
|
+
this.dom.textarea.addEventListener('input', function(e){
|
|
237
|
+
if (!this$.editing.on || !this$.editing.opts) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
return this$._optFilter(this$.dom.textarea.value);
|
|
241
|
+
});
|
|
225
242
|
this.dom.sheet.addEventListener('contextmenu', function(e){
|
|
226
243
|
this$.fire('menu.on', {
|
|
227
244
|
evt: e,
|
|
@@ -384,7 +401,7 @@
|
|
|
384
401
|
}
|
|
385
402
|
});
|
|
386
403
|
this.dom.textarea.addEventListener('keydown', function(e){
|
|
387
|
-
var code, ref$, sc, ec, sr, er, data, res$, i$, row, lresult$, j$, col, opt, lbox, box;
|
|
404
|
+
var code, ref$, sc, ec, sr, er, data, res$, i$, row, lresult$, j$, col, len, opt, lbox, box;
|
|
388
405
|
code = e.keyCode;
|
|
389
406
|
if (e.keyCode === 86 && (e.metaKey || e.ctrlKey)) {
|
|
390
407
|
return;
|
|
@@ -433,6 +450,21 @@
|
|
|
433
450
|
if (code === 187 && (e.metaKey || e.ctrlKey)) {
|
|
434
451
|
this$.insert();
|
|
435
452
|
}
|
|
453
|
+
if (this$.editing.on && this$.editing.opts && (code === 38 || code === 40)) {
|
|
454
|
+
e.stopPropagation();
|
|
455
|
+
e.preventDefault();
|
|
456
|
+
if (len = this$.editing.list.length) {
|
|
457
|
+
this$.editing.hi = this$.editing.hi < 0
|
|
458
|
+
? code === 40
|
|
459
|
+
? 0
|
|
460
|
+
: len - 1
|
|
461
|
+
: (this$.editing.hi + (code === 40
|
|
462
|
+
? 1
|
|
463
|
+
: -1) + len) % len;
|
|
464
|
+
this$._optRender();
|
|
465
|
+
}
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
436
468
|
opt = (function(){
|
|
437
469
|
switch (code) {
|
|
438
470
|
case 37:
|
|
@@ -627,6 +659,9 @@
|
|
|
627
659
|
if (!this$.enableScrolling) {
|
|
628
660
|
return;
|
|
629
661
|
}
|
|
662
|
+
if (this$.dom.options.contains(e.target)) {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
630
665
|
if (this$._guardArmed) {
|
|
631
666
|
return;
|
|
632
667
|
}
|
|
@@ -1060,6 +1095,12 @@
|
|
|
1060
1095
|
})) {
|
|
1061
1096
|
return;
|
|
1062
1097
|
}
|
|
1098
|
+
if (src) {
|
|
1099
|
+
data = this._resolve(data, {
|
|
1100
|
+
row: row,
|
|
1101
|
+
col: col
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1063
1104
|
touched = true;
|
|
1064
1105
|
((ref$ = this._data)[row] || (ref$[row] = []))[col] = data;
|
|
1065
1106
|
this._content({
|
|
@@ -1082,6 +1123,10 @@
|
|
|
1082
1123
|
continue;
|
|
1083
1124
|
}
|
|
1084
1125
|
touched = true;
|
|
1126
|
+
data[r][c] = this._resolve(data[r][c], {
|
|
1127
|
+
row: row + r,
|
|
1128
|
+
col: col + c
|
|
1129
|
+
});
|
|
1085
1130
|
((ref$ = this._data)[key$ = r + row] || (ref$[key$] = []))[c + col] = data[r][c];
|
|
1086
1131
|
this._content({
|
|
1087
1132
|
y: r + row - this.pos.row + this.xif.row[1],
|
|
@@ -1153,8 +1198,14 @@
|
|
|
1153
1198
|
return v;
|
|
1154
1199
|
},
|
|
1155
1200
|
_display: function(raw, arg$){
|
|
1156
|
-
var row, col, v;
|
|
1201
|
+
var row, col, opts, o, v;
|
|
1157
1202
|
row = arg$.row, col = arg$.col;
|
|
1203
|
+
if ((opts = this._options({
|
|
1204
|
+
row: row,
|
|
1205
|
+
col: col
|
|
1206
|
+
})) && (o = this._match(opts, raw, true))) {
|
|
1207
|
+
return o.label;
|
|
1208
|
+
}
|
|
1158
1209
|
v = !this._dsp
|
|
1159
1210
|
? raw
|
|
1160
1211
|
: this._dsp({
|
|
@@ -1167,8 +1218,64 @@
|
|
|
1167
1218
|
col: col
|
|
1168
1219
|
});
|
|
1169
1220
|
},
|
|
1221
|
+
_options: function(arg$){
|
|
1222
|
+
var row, col, o;
|
|
1223
|
+
row = arg$.row, col = arg$.col;
|
|
1224
|
+
if (!this._ccfg) {
|
|
1225
|
+
return null;
|
|
1226
|
+
}
|
|
1227
|
+
if (!(Array.isArray(o = this._ccfg({
|
|
1228
|
+
type: 'options',
|
|
1229
|
+
row: row,
|
|
1230
|
+
col: col
|
|
1231
|
+
})) && o.length)) {
|
|
1232
|
+
return null;
|
|
1233
|
+
}
|
|
1234
|
+
return o.map(function(it){
|
|
1235
|
+
if (it != null && typeof it === 'object') {
|
|
1236
|
+
return {
|
|
1237
|
+
value: it.value,
|
|
1238
|
+
label: it.label != null
|
|
1239
|
+
? it.label
|
|
1240
|
+
: it.value
|
|
1241
|
+
};
|
|
1242
|
+
} else {
|
|
1243
|
+
return {
|
|
1244
|
+
value: it,
|
|
1245
|
+
label: it
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
},
|
|
1250
|
+
_match: function(opts, v, strict){
|
|
1251
|
+
var s, o;
|
|
1252
|
+
if (!(v != null) || typeof v === 'object' || (s = '' + v) === '') {
|
|
1253
|
+
return null;
|
|
1254
|
+
}
|
|
1255
|
+
if ((o = opts.find(function(it){
|
|
1256
|
+
return '' + it.value === s;
|
|
1257
|
+
})) || strict) {
|
|
1258
|
+
return o;
|
|
1259
|
+
}
|
|
1260
|
+
if (o = opts.find(function(it){
|
|
1261
|
+
return '' + it.label === s;
|
|
1262
|
+
})) {
|
|
1263
|
+
return o;
|
|
1264
|
+
}
|
|
1265
|
+
s = s.trim().toLowerCase();
|
|
1266
|
+
return opts.find(function(it){
|
|
1267
|
+
return ('' + it.value).toLowerCase() === s || ('' + it.label).toLowerCase() === s;
|
|
1268
|
+
});
|
|
1269
|
+
},
|
|
1270
|
+
_resolve: function(v, c){
|
|
1271
|
+
var opts, o;
|
|
1272
|
+
if (!(opts = this._options(c)) || !(o = this._match(opts, v))) {
|
|
1273
|
+
return v;
|
|
1274
|
+
}
|
|
1275
|
+
return o.value;
|
|
1276
|
+
},
|
|
1170
1277
|
_content: function(arg$){
|
|
1171
|
-
var x, y, n, c, content, ref$, key$, clsext, clsopt;
|
|
1278
|
+
var x, y, n, c, content, ref$, key$, clsext, clsopt, clsopts, opts, raw;
|
|
1172
1279
|
x = arg$.x, y = arg$.y, n = arg$.n;
|
|
1173
1280
|
if (!n && !(n = this.dom.inner.childNodes[x + y * this.dim.col])) {
|
|
1174
1281
|
return;
|
|
@@ -1198,7 +1305,10 @@
|
|
|
1198
1305
|
row: c.row,
|
|
1199
1306
|
col: c.col
|
|
1200
1307
|
})) || '';
|
|
1201
|
-
|
|
1308
|
+
clsopts = c.type !== 'cell' || !(opts = this._options(c))
|
|
1309
|
+
? ''
|
|
1310
|
+
: (raw = this._data[c.row][c.col], "has-options" + (!(raw != null) || raw === '' || this._match(opts, raw, true) ? '' : ' invalid'));
|
|
1311
|
+
n.className = [c.className, clsext, clsopt, clsopts].filter(function(it){
|
|
1202
1312
|
return it.trim();
|
|
1203
1313
|
}).join(' ').trim();
|
|
1204
1314
|
if (typeof content === 'object') {
|
|
@@ -1438,7 +1548,7 @@
|
|
|
1438
1548
|
return this.renderSelection();
|
|
1439
1549
|
},
|
|
1440
1550
|
edit: function(arg$){
|
|
1441
|
-
var node, quick, idx, raw, ref$, lbox, box, rbox, sx, sy, v;
|
|
1551
|
+
var node, quick, idx, raw, opts, cur, ref$, lbox, box, rbox, sx, sy, v;
|
|
1442
1552
|
node = arg$.node, quick = arg$.quick;
|
|
1443
1553
|
if (!this._editing) {
|
|
1444
1554
|
return;
|
|
@@ -1455,15 +1565,20 @@
|
|
|
1455
1565
|
return;
|
|
1456
1566
|
}
|
|
1457
1567
|
raw = (this._data[idx.row] || [])[idx.col];
|
|
1568
|
+
opts = this._options(idx);
|
|
1569
|
+
cur = opts ? this._match(opts, raw, true) : null;
|
|
1458
1570
|
raw = raw == null
|
|
1459
1571
|
? ''
|
|
1460
|
-
:
|
|
1461
|
-
?
|
|
1462
|
-
: ''
|
|
1572
|
+
: cur
|
|
1573
|
+
? '' + cur.label
|
|
1574
|
+
: typeof raw === 'object'
|
|
1575
|
+
? node.textContent || ''
|
|
1576
|
+
: '' + raw;
|
|
1463
1577
|
ref$ = this.editing;
|
|
1464
1578
|
ref$.node = node;
|
|
1465
1579
|
ref$.quick = quick;
|
|
1466
1580
|
ref$.on = true;
|
|
1581
|
+
ref$.opts = opts;
|
|
1467
1582
|
this.dom.layout.textContent = raw;
|
|
1468
1583
|
lbox = this.dom.layout.getBoundingClientRect();
|
|
1469
1584
|
box = node.getBoundingClientRect();
|
|
@@ -1480,23 +1595,104 @@
|
|
|
1480
1595
|
ref$.height = Math.max(lbox.height, box.height + 1) + "px";
|
|
1481
1596
|
this.dom.textarea.value = v = quick ? '' : raw;
|
|
1482
1597
|
this.dom.textarea.focus();
|
|
1483
|
-
|
|
1598
|
+
this.dom.textarea.setSelectionRange(v.length, v.length);
|
|
1599
|
+
if (opts) {
|
|
1600
|
+
ref$ = this.editing;
|
|
1601
|
+
ref$.list = opts;
|
|
1602
|
+
ref$.hi = cur
|
|
1603
|
+
? opts.indexOf(cur)
|
|
1604
|
+
: -1;
|
|
1605
|
+
return this._optRender();
|
|
1606
|
+
}
|
|
1607
|
+
},
|
|
1608
|
+
_optFilter: function(txt){
|
|
1609
|
+
var e, s, has, i;
|
|
1610
|
+
e = this.editing;
|
|
1611
|
+
s = (txt || '').trim().toLowerCase();
|
|
1612
|
+
has = function(o, f){
|
|
1613
|
+
return ('' + o.label).toLowerCase()[f](s) || ('' + o.value).toLowerCase()[f](s);
|
|
1614
|
+
};
|
|
1615
|
+
e.list = !s
|
|
1616
|
+
? e.opts
|
|
1617
|
+
: e.opts.filter(function(it){
|
|
1618
|
+
return has(it, 'includes');
|
|
1619
|
+
});
|
|
1620
|
+
e.hi = !s
|
|
1621
|
+
? -1
|
|
1622
|
+
: (i = e.list.findIndex(function(it){
|
|
1623
|
+
return ('' + it.label).toLowerCase() === s || ('' + it.value).toLowerCase() === s;
|
|
1624
|
+
}), i >= 0
|
|
1625
|
+
? i
|
|
1626
|
+
: (i = e.list.findIndex(function(it){
|
|
1627
|
+
return has(it, 'startsWith');
|
|
1628
|
+
})) >= 0
|
|
1629
|
+
? i
|
|
1630
|
+
: e.list.length
|
|
1631
|
+
? 0
|
|
1632
|
+
: -1);
|
|
1633
|
+
return this._optRender();
|
|
1634
|
+
},
|
|
1635
|
+
_optRender: function(){
|
|
1636
|
+
var ref$, e, n, box, rbox, sx, sy, h, below, a;
|
|
1637
|
+
ref$ = [this.editing, this.dom.options], e = ref$[0], n = ref$[1];
|
|
1638
|
+
n.textContent = '';
|
|
1639
|
+
if (!(e.on && e.opts && e.list.length)) {
|
|
1640
|
+
return n.classList.toggle('show', false);
|
|
1641
|
+
}
|
|
1642
|
+
e.list.map(function(o, i){
|
|
1643
|
+
var x$;
|
|
1644
|
+
x$ = n.appendChild(document.createElement('div'));
|
|
1645
|
+
x$.className = "option" + (i === e.hi ? " active" : "");
|
|
1646
|
+
x$.dataset.idx = i;
|
|
1647
|
+
x$.textContent = o.label;
|
|
1648
|
+
return x$;
|
|
1649
|
+
});
|
|
1650
|
+
n.classList.toggle('show', true);
|
|
1651
|
+
box = e.node.getBoundingClientRect();
|
|
1652
|
+
rbox = this.dom.sheet.getBoundingClientRect();
|
|
1653
|
+
ref$ = [this.dom.sheet.scrollLeft, this.dom.sheet.scrollTop], sx = ref$[0], sy = ref$[1];
|
|
1654
|
+
ref$ = n.style;
|
|
1655
|
+
ref$.left = (box.x - rbox.x + sx - 2) + "px";
|
|
1656
|
+
ref$.minWidth = (box.width + 4) + "px";
|
|
1657
|
+
h = n.offsetHeight;
|
|
1658
|
+
below = rbox.bottom - box.bottom;
|
|
1659
|
+
n.style.top = below < h && box.top - rbox.top > below
|
|
1660
|
+
? (box.top - rbox.top + sy - h - 2) + "px"
|
|
1661
|
+
: (box.bottom - rbox.top + sy + 2) + "px";
|
|
1662
|
+
if (a = n.childNodes[e.hi]) {
|
|
1663
|
+
if (a.offsetTop < n.scrollTop) {
|
|
1664
|
+
return n.scrollTop = a.offsetTop;
|
|
1665
|
+
} else if (a.offsetTop + a.offsetHeight > n.scrollTop + n.clientHeight) {
|
|
1666
|
+
return n.scrollTop = a.offsetTop + a.offsetHeight - n.clientHeight;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1484
1669
|
},
|
|
1485
1670
|
edited: function(opt){
|
|
1486
|
-
var v, ref$;
|
|
1671
|
+
var e, v, ref$;
|
|
1487
1672
|
opt == null && (opt = {});
|
|
1488
1673
|
if (!this.editing.on) {
|
|
1489
1674
|
return;
|
|
1490
1675
|
}
|
|
1491
1676
|
if (!opt.cancel) {
|
|
1677
|
+
e = this.editing;
|
|
1678
|
+
v = e.opts && e.hi >= 0 && e.list[e.hi]
|
|
1679
|
+
? e.list[e.hi].value
|
|
1680
|
+
: this.dom.textarea.value || '';
|
|
1492
1681
|
this.set({
|
|
1493
1682
|
row: this.les.start.row,
|
|
1494
1683
|
col: this.les.start.col,
|
|
1495
|
-
data: v
|
|
1684
|
+
data: v,
|
|
1685
|
+
src: 'user'
|
|
1496
1686
|
});
|
|
1497
1687
|
}
|
|
1498
1688
|
this.dom.edit.classList.toggle('show', false);
|
|
1499
|
-
|
|
1689
|
+
ref$ = this.editing;
|
|
1690
|
+
ref$.node = null;
|
|
1691
|
+
ref$.on = false;
|
|
1692
|
+
ref$.opts = null;
|
|
1693
|
+
ref$.list = null;
|
|
1694
|
+
ref$.hi = -1;
|
|
1695
|
+
return this._optRender();
|
|
1500
1696
|
},
|
|
1501
1697
|
index: function(node){
|
|
1502
1698
|
var idx, x, c;
|
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:"→"}.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}
|
|
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 .cell.has-options{padding-right:14px}.sheet .cell.has-options:after{content:"▾";position:absolute;top:0;right:3px;line-height:inherit;font-size:.75em;color:#aaa}.sheet .cell.invalid{color:#d33;background:#fff3f3}.sheet .options{top:0;left:0;position:absolute;z-index:125;display:none;max-height:12em;overflow-y:auto;overscroll-behavior:contain;box-sizing:border-box;padding:2px 0;background:#fff;border:1px solid #bbb;border-radius:3px;box-shadow:0 4px 12px rgba(0,0,0,0.12)}.sheet .options .option{padding:0 10px;line-height:26px;white-space:nowrap;cursor:pointer;user-select:none}.sheet .options .option:hover{background:#f1f2f3}.sheet .options .option.active{background:#27f;color:#fff}.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,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);
|
|
1
|
+
!function(){var f,m,l,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},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="",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","options"].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","options"].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.options.addEventListener("mousedown",function(t){if(t.stopPropagation(),t.preventDefault(),t=m(t.target,".option",u.dom.options))return u.editing.hi=+t.dataset.idx,u.edited(),u.renderSelection()}),this.dom.textarea.addEventListener("input",function(t){if(u.editing.on&&u.editing.opts)return u._optFilter(u.dom.textarea.value)}),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,c=e.sr,r=e.er,s=[],n=c;n<=r;++n){for(l=[],d=i;d<=o;++d)l.push("");s.push(l)}h=s,u.set({row:c,col:i,data:h,range:!0,src:"user"}),u.render()}if(189===a&&(t.metaKey||t.ctrlKey)&&u.slice(),187===a&&(t.metaKey||t.ctrlKey)&&u.insert(),u.editing.on&&u.editing.opts&&(38===a||40===a))t.stopPropagation(),t.preventDefault(),(c=u.editing.list.length)&&(u.editing.hi=u.editing.hi<0?40===a?0:c-1:(u.editing.hi+(40===a?1:-1)+c)%c,u._optRender());else{if(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.dom.options.contains(t.target)&&!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,u[s][d]=this._resolve(u[s][d],{row:h+s,col:a+d}),((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;m&&(u=this._resolve(u,{row:h,col:a})),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,o=e.row,e=e.col;return(i=this._options({row:o,col:e}))&&(i=this._match(i,t,!0))?i.label:(i=this._dsp?this._dsp({raw:t,row:o,col:e}):t,this._format(i,{row:o,col:e}))},_options:function(t){var e=t.row,t=t.col;return this._ccfg&&Array.isArray(e=this._ccfg({type:"options",row:e,col:t}))&&e.length?e.map(function(t){return null!=t&&"object"==typeof t?{value:t.value,label:null!=t.label?t.label:t.value}:{value:t,label:t}}):null},_match:function(t,e,i){var o;return null!=e&&"object"!=typeof e&&(o=""+e)?(e=t.find(function(t){return""+t.value===o}))||i?e:t.find(function(t){return""+t.label===o})||(o=o.trim().toLowerCase(),t.find(function(t){return(""+t.value).toLowerCase()===o||(""+t.label).toLowerCase()===o})):null},_resolve:function(t,e){return(e=this._options(e))&&(e=this._match(e,t))?e.value:t},_content:function(t){var e,i,o,r,s=t.x,n=t.y,t=t.n;if(t||(t=this.dom.inner.childNodes[s+n*this.dim.col]))return null==(n="idx"===(e=this._coord(s,n)).type?"row"===e.axis?n<this.xif.row[1]?" ":e.row+1:"col"===e.axis?s<this.xif.col[1]?" ":l(e.col):"":"fixed"===e.type?"":this._display(((n=this._data)[s=e.row]||(n[s]=[]))[e.col],e))&&(n=""),s="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}):"")||"",o="cell"===e.type&&(o=this._options(e))?"has-options"+(null==(r=this._data[e.row][e.col])||""===r||this._match(o,r,!0)?"":" invalid"):"",t.className=[e.className,s,i,o].filter(function(t){return t.trim()}).join(" ").trim(),"object"!=typeof n?t.textContent=n:"dom"===n.type?(t.textContent="",t.appendChild(n.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,d,c=t.node,t=t.quick;if(this._editing&&!(!(i=this.index(c))||i.col<0||i.row<0||this._ccfg&&this._ccfg({row:i.row,col:i.col,type:"readonly"})))return e=(this._data[i.row]||[])[i.col],o=(i=this._options(i))?this._match(i,e,!0):null,e=null==e?"":o?""+o.label:"object"==typeof e?c.textContent||"":""+e,(r=this.editing).node=c,r.quick=t,r.on=!0,r.opts=i,this.dom.layout.textContent=e,s=this.dom.layout.getBoundingClientRect(),c=c.getBoundingClientRect(),n=this.dom.sheet.getBoundingClientRect(),d=(r=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],l=r[1],(r=this.dom.edit.style).left=c.x-n.x+d-2+"px",r.top=c.y-n.y+l-2+"px",r.width="fit-content",r.height="fit-content",this.dom.edit.classList.toggle("show",!0),(r=this.dom.textarea.style).width=Math.max(s.width,c.width+1)+"px",r.height=Math.max(s.height,c.height+1)+"px",this.dom.textarea.value=d=t?"":e,this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(d.length,d.length),i?((r=this.editing).list=i,r.hi=o?i.indexOf(o):-1,this._optRender()):void 0},_optFilter:function(t){var e=this.editing,i=(t||"").trim().toLowerCase(),o=function(t,e){return(""+t.label).toLowerCase()[e](i)||(""+t.value).toLowerCase()[e](i)};return e.list=i?e.opts.filter(function(t){return o(t,"includes")}):e.opts,e.hi=i?0<=(t=e.list.findIndex(function(t){return(""+t.label).toLowerCase()===i||(""+t.value).toLowerCase()===i}))||0<=(t=e.list.findIndex(function(t){return o(t,"startsWith")}))?t:e.list.length?0:-1:-1,this._optRender()},_optRender:function(){var t,e,i,o,r=[this.editing,this.dom.options],s=r[0],n=r[1];return n.textContent="",s.on&&s.opts&&s.list.length?(s.list.map(function(t,e){var i=n.appendChild(document.createElement("div"));return i.className="option"+(e===s.hi?" active":""),i.dataset.idx=e,i.textContent=t.label,i}),n.classList.toggle("show",!0),t=s.node.getBoundingClientRect(),e=this.dom.sheet.getBoundingClientRect(),o=(r=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],i=r[1],(r=n.style).left=t.x-e.x+o-2+"px",r.minWidth=t.width+4+"px",o=n.offsetHeight,r=e.bottom-t.bottom,n.style.top=r<o&&t.top-e.top>r?t.top-e.top+i-o-2+"px":t.bottom-e.top+i+2+"px",(r=n.childNodes[s.hi])?r.offsetTop<n.scrollTop?n.scrollTop=r.offsetTop:r.offsetTop+r.offsetHeight>n.scrollTop+n.clientHeight?n.scrollTop=r.offsetTop+r.offsetHeight-n.clientHeight:void 0:void 0):n.classList.toggle("show",!1)},edited:function(t){if(null==t&&(t={}),this.editing.on)return t.cancel||(t=(t=this.editing).opts&&0<=t.hi&&t.list[t.hi]?t.list[t.hi].value:this.dom.textarea.value||"",this.set({row:this.les.start.row,col:this.les.start.col,data:t,src:"user"})),this.dom.edit.classList.toggle("show",!1),(t=this.editing).node=null,t.on=!1,t.opts=null,t.list=null,t.hi=-1,this._optRender()},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,p=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 p.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.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.8.0","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"]}}
|