@plotdb/sheet 0.1.5 → 0.2.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 +123 -0
- package/README.md +21 -1
- package/{dist/index.css → index.css} +1 -0
- package/{dist/index.js → index.js} +29 -8
- package/index.min.css +1 -0
- package/index.min.js +1 -0
- package/package.json +1 -70
- package/dist/index.min.css +0 -1
- package/dist/index.min.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Change Logs
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## v0.2.0
|
|
5
|
+
|
|
6
|
+
- add `style` in `package.json`
|
|
7
|
+
- add `main` and `browser` field in `package.json`.
|
|
8
|
+
- further minimize generated js file with mangling and compression
|
|
9
|
+
- upgrade modules
|
|
10
|
+
- patch test code to make it work with upgraded modules
|
|
11
|
+
- release with compact directory structure
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## v0.1.8
|
|
15
|
+
|
|
16
|
+
- add `overscroll-behavior` over `.sheet`
|
|
17
|
+
- swipe back note in README.md
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## v0.1.7
|
|
21
|
+
|
|
22
|
+
- support resizing after initialization
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## v0.1.6
|
|
26
|
+
|
|
27
|
+
- support custom class names in cells
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## v0.1.5
|
|
31
|
+
|
|
32
|
+
- make it possible to add node instead of pure text.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## v0.1.4
|
|
36
|
+
|
|
37
|
+
- fix bug: `0` wasn't shown when set cell content. fix this by checking `!(textContent?)` instead of `!(textContent)`.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## v0.1.3
|
|
41
|
+
|
|
42
|
+
- add `data(d)` api
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## v0.1.2
|
|
46
|
+
|
|
47
|
+
- add `scrollLock` option for locking body scrolling to prevent swipe gesture.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## v0.1.1
|
|
51
|
+
|
|
52
|
+
- fix bug: escape should cancel editing.
|
|
53
|
+
- fix bug: caret position incorrect after pressing enter.
|
|
54
|
+
- fix bug: should re-focus after enter.
|
|
55
|
+
- fix bug: caret and range should not be hidden after edited.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## v0.1.0
|
|
59
|
+
|
|
60
|
+
- rename `update` event to `change` event.
|
|
61
|
+
- check sheet focus before pasting data
|
|
62
|
+
- support copy tsv format text to clipboard. use `navigator.clipboard`, which doesn't support older browsers.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## v0.0.10
|
|
66
|
+
|
|
67
|
+
- fix selection issue across frozen cells
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## v0.0.9
|
|
71
|
+
|
|
72
|
+
- fix column label issue (plotdb/sheet#1)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## v0.0.8
|
|
76
|
+
|
|
77
|
+
- fix bug: cell overflow should be hidden so content won't overflow and cover following cells if size is fixed.
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## v0.0.7
|
|
81
|
+
|
|
82
|
+
- support sheet in shadow DOM mode
|
|
83
|
+
- add editing option / api for togglgin editability
|
|
84
|
+
- add size option
|
|
85
|
+
- tweak style for `.fixed.frozen` cell.
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
## v0.0.6
|
|
89
|
+
|
|
90
|
+
- re-focus sheet after selection moved to support quick editing
|
|
91
|
+
- remove outline of sheet to prevent unwanted focus style.
|
|
92
|
+
- tweak code for updating content
|
|
93
|
+
- add event handler
|
|
94
|
+
- fix bug of content updating issue when setting new data
|
|
95
|
+
- fire update event when data is changed.
|
|
96
|
+
- support range in `set` api.
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
## v0.0.5
|
|
100
|
+
|
|
101
|
+
- add `tabindex` in root element to make it possible to capture key events.
|
|
102
|
+
- check some events for event source.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
## v0.0.4
|
|
106
|
+
|
|
107
|
+
- tweak fixed cell style
|
|
108
|
+
- prevent fixed cell from being edited
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
## v0.0.3
|
|
112
|
+
|
|
113
|
+
- support fixed rows / columns, frozen rows / columns and idx cells toggling
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
## v0.0.2
|
|
117
|
+
|
|
118
|
+
- fix bug: edited failed if edited node is outside range of visible sheet.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## v0.0.1
|
|
122
|
+
|
|
123
|
+
init commit
|
package/README.md
CHANGED
|
@@ -41,6 +41,8 @@ initialize:
|
|
|
41
41
|
- `idx`: {row, col}. default {row: true, col: true}
|
|
42
42
|
- `size`: {row, col}. force cell size, in array by order.
|
|
43
43
|
- default: {row: [], col: []}
|
|
44
|
+
- `class`: {row, col}. additional cell class name, in array by order, as space separated string.
|
|
45
|
+
- default: {row: [], col: []}
|
|
44
46
|
- `editing`: false to disable editing. default true.
|
|
45
47
|
- (TBD) in the future we should be able to:
|
|
46
48
|
- set edit permission ( e.g., edit, comment )
|
|
@@ -59,6 +61,7 @@ initialize:
|
|
|
59
61
|
- `data(d)`: replace data completely with `d` and re-render.
|
|
60
62
|
- return current data if `d` is omitted.
|
|
61
63
|
- `d` is in the same format with the constructor `data` option
|
|
64
|
+
- `size({row, col})`: update grid size.
|
|
62
65
|
|
|
63
66
|
|
|
64
67
|
## Event
|
|
@@ -90,7 +93,24 @@ You can add more than texts in the grid of the sheet, by having an object with f
|
|
|
90
93
|
|
|
91
94
|
Currently, only `node` type is supported:
|
|
92
95
|
|
|
93
|
-
{ type: "
|
|
96
|
+
{ type: "dom", node: SomeElement }
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# Swipe Back Issue
|
|
100
|
+
|
|
101
|
+
On Chrome in Mac, scrolling left with trackpad with two finger gesture may also triggers swipe back action, which navigate the page back in browsing history. This happens in all websites needing similar actions, including Airtable and Google Spreadsheet.
|
|
102
|
+
|
|
103
|
+
This may be temporarily solved by setting `overscroll-behavior` to `contain` of the sheet container, however - if swipe back happens once anywhere outside the sheet container, it then always triggered even in sheet container.
|
|
104
|
+
|
|
105
|
+
If this happens, try setting `overscroll-behavior` to `contain` directly on `body` to see if it may solve this issue.
|
|
106
|
+
|
|
107
|
+
Reference:
|
|
108
|
+
|
|
109
|
+
- https://bugs.chromium.org/p/chromium/issues/detail?id=889846
|
|
110
|
+
- https://bugs.chromium.org/p/chromium/issues/detail?id=862693
|
|
111
|
+
- https://bugs.chromium.org/p/chromium/issues/detail?id=906886
|
|
112
|
+
- https://community.airtable.com/t/3074
|
|
113
|
+
|
|
94
114
|
|
|
95
115
|
|
|
96
116
|
## License
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Generated by LiveScript 1.6.0
|
|
2
1
|
(function(){
|
|
3
2
|
var parseCsv, parent, idxToLabel, labelToIdx, sheet;
|
|
4
3
|
parseCsv = function(txt){
|
|
@@ -65,13 +64,20 @@
|
|
|
65
64
|
: opt.root;
|
|
66
65
|
this.evtHandler = {};
|
|
67
66
|
this._data = opt.data || [];
|
|
68
|
-
this.
|
|
67
|
+
this._size = {
|
|
69
68
|
row: (ref$ = import$({
|
|
70
69
|
row: [],
|
|
71
70
|
col: []
|
|
72
71
|
}, opt.size)).row,
|
|
73
72
|
col: ref$.col
|
|
74
73
|
};
|
|
74
|
+
this.cls = {
|
|
75
|
+
row: (ref$ = import$({
|
|
76
|
+
row: [],
|
|
77
|
+
col: []
|
|
78
|
+
}, opt['class'])).row,
|
|
79
|
+
col: ref$.col
|
|
80
|
+
};
|
|
75
81
|
this._editing = opt.editing != null ? !!opt.editing : true;
|
|
76
82
|
this.dim = {
|
|
77
83
|
col: (opt.dim || (opt.dim = {})).col || 30,
|
|
@@ -393,6 +399,20 @@
|
|
|
393
399
|
eventInScope: function(e){
|
|
394
400
|
return parent(e.target, '.sheet', this.dom.sheet) === this.dom.sheet;
|
|
395
401
|
},
|
|
402
|
+
size: function(it){
|
|
403
|
+
var ref$;
|
|
404
|
+
if (it == null) {
|
|
405
|
+
return this._size;
|
|
406
|
+
}
|
|
407
|
+
this._size = {
|
|
408
|
+
row: (ref$ = import$({
|
|
409
|
+
row: [],
|
|
410
|
+
col: []
|
|
411
|
+
}, it)).row,
|
|
412
|
+
col: ref$.col
|
|
413
|
+
};
|
|
414
|
+
return this.regrid();
|
|
415
|
+
},
|
|
396
416
|
regrid: function(){
|
|
397
417
|
var this$ = this;
|
|
398
418
|
this.dom.inner.style.gridTemplateColumns = ("repeat(" + this.xif.col[1] + ", max-content) ") + (function(){
|
|
@@ -402,7 +422,7 @@
|
|
|
402
422
|
}
|
|
403
423
|
return results$;
|
|
404
424
|
}.call(this)).map(function(it){
|
|
405
|
-
return this$.
|
|
425
|
+
return this$._size.col[it] || "max-content";
|
|
406
426
|
}).join(' ') + ' ' + (function(){
|
|
407
427
|
var i$, to$, results$ = [];
|
|
408
428
|
for (i$ = this.xif.col[2], to$ = this.dim.col; i$ < to$; ++i$) {
|
|
@@ -410,7 +430,7 @@
|
|
|
410
430
|
}
|
|
411
431
|
return results$;
|
|
412
432
|
}.call(this)).map(function(it){
|
|
413
|
-
return this$.
|
|
433
|
+
return this$._size.col[it + this$.pos.col - this$.xif.col[1]] || "max-content";
|
|
414
434
|
}).join(' ');
|
|
415
435
|
return this.dom.inner.style.gridTemplateRows = ("repeat(" + this.xif.row[1] + ", max-content) ") + (function(){
|
|
416
436
|
var i$, to$, results$ = [];
|
|
@@ -419,7 +439,7 @@
|
|
|
419
439
|
}
|
|
420
440
|
return results$;
|
|
421
441
|
}.call(this)).map(function(it){
|
|
422
|
-
return this$.
|
|
442
|
+
return this$._size.row[it] || "max-content";
|
|
423
443
|
}).join(' ') + ' ' + (function(){
|
|
424
444
|
var i$, to$, results$ = [];
|
|
425
445
|
for (i$ = this.xif.row[2], to$ = this.dim.row; i$ < to$; ++i$) {
|
|
@@ -427,7 +447,7 @@
|
|
|
427
447
|
}
|
|
428
448
|
return results$;
|
|
429
449
|
}.call(this)).map(function(it){
|
|
430
|
-
return this$.
|
|
450
|
+
return this$._size.row[it + this$.pos.row - this$.xif.row[1]] || "max-content";
|
|
431
451
|
}).join(' ');
|
|
432
452
|
},
|
|
433
453
|
addCell: function(x, y){
|
|
@@ -470,7 +490,7 @@
|
|
|
470
490
|
});
|
|
471
491
|
},
|
|
472
492
|
_content: function(arg$){
|
|
473
|
-
var x, y, n, v, ref$, key$, content, className;
|
|
493
|
+
var x, y, n, v, ref$, key$, content, className, clsext;
|
|
474
494
|
x = arg$.x, y = arg$.y, n = arg$.n;
|
|
475
495
|
if (!n && !(n = this.dom.inner.childNodes[x + y * this.dim.col])) {
|
|
476
496
|
return;
|
|
@@ -503,7 +523,8 @@
|
|
|
503
523
|
if (!(content != null)) {
|
|
504
524
|
content = "";
|
|
505
525
|
}
|
|
506
|
-
|
|
526
|
+
clsext = x >= this.xif.col[0] && y >= this.xif.row[0] ? (this.cls.col[this.pos.col + x - this.xif.col[1]] || '') + ' ' + (this.cls.row[this.pos.row + y - this.xif.row[1]] || '') : '';
|
|
527
|
+
n.className = className + ' ' + clsext;
|
|
507
528
|
if (content !== null) {
|
|
508
529
|
if (typeof content === 'object') {
|
|
509
530
|
if (content.type === 'dom') {
|
package/index.min.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.sheet{position:relative;width:100%;height:100%;overflow:hidden;overscroll-behavior:contain;outline:0}.sheet .inner{z-index:1;display:grid;width:100%;height:100%;overflow:hidden}.sheet .cell{position:relative;user-select:none;border-width:0 1px 1px 0;border-style:solid;border-color:#ddd;padding:1px 3px;min-width:48px;line-height:26px;box-sizing:border-box;white-space:pre;overflow:hidden}.sheet .cell.idx{z-index:100;background:#f1f2f3;color:#919293;font-size:.85em;text-align:center;user-select:none}.sheet .cell.fixed,.sheet .cell.fixed.frozen{z-index:13}.sheet .cell.fixed{background:#fafbfc;white-space:initial;padding:0}.sheet .cell.frozen{z-index:12;background:#fdfeff}.sheet .cell.fixed.frozen{padding:1px 3px}.sheet .range{z-index:14;border:1px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .caret{z-index:15;border:2px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .edit{z-index:121;border:2px solid #27f;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .edit textarea{display:block;border:0;outline:0}.sheet .layout{display:inline-block;top:0;left:0;position:absolute;z-index:0;opacity:0;pointer-events:none;user-select:none;white-space:pre}.sheet .show{opacity:1 !important;display:block}
|
package/index.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){function t(t,i){var e={}.hasOwnProperty;for(var o in i)e.call(i,o)&&(t[o]=i[o]);return t}var i,e,o,s;i=function(t){return Papa.parse(t).data},e=function(t,i,e){var o;for(o=t;t&&t!==e;)t=t.parentNode;if(t!==e)return null;if(!i)return t;for(t=o;t&&t!==e&&(!t.matches||t.matches&&!t.matches(i));)t=t.parentNode;return t!==e||e.matches&&e.matches(i)?t:null},o=function(t){var i,e,o,s,r;for(i=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,e=t-((Math.pow(26,i+1)-1)/25-1),o="ABCDEFGHIJKLMNOPQRSTUVWXYZ",s="",r=0;r<=i;++r)r,s=o.charAt(e%26)+s,e=(e-e%26)/26;return s},(s=function(i){var e,o=this;return null==i&&(i={}),this.opt=i,this.root="string"==typeof i.root?document.querySelector(i.root):i.root,this.evtHandler={},this._data=i.data||[],this._size={row:(e=t({row:[],col:[]},i.size)).row,col:e.col},this.cls={row:(e=t({row:[],col:[]},i.class)).row,col:e.col},this._editing=null==i.editing||!!i.editing,this.dim={col:(i.dim||(i.dim={})).col||30,row:(i.dim||(i.dim={})).row||30},this.frozen={col:(e=t({col:0,row:0},i.frozen||{})).col,row:e.row},this.idx={col:(e=t({row:!0,col:!0},i.idx||{})).col,row:e.row},this.fixed={col:(e=t({col:0,row:0},i.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 o.xif[t][1]=o.xif[t][0]+o.fixed[t],o.xif[t][2]=o.xif[t][1]+o.frozen[t]}),this.fix={row:this.xif.row[2],col:this.xif.col[2]},this.pos={col:0,row:0},this.scrollPos={x:0,y:0},this.sel={},this.les={},this.editing={},this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout"].map(function(t){var i;return(i=document.createElement("div")).classList.add(t),[t,i]})),this.dom.sheet.setAttribute("tabindex",-1),this.dom.textarea=document.createElement("textarea"),this.root.appendChild(this.dom.sheet),["inner","caret","range","edit","layout"].map(function(t){return o.dom.sheet.appendChild(o.dom[t])}),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=t(Object.create(Object.prototype),{on:function(t,i){var e;return((e=this.evtHandler)[t]||(e[t]=[])).push(i)},fire:function(t){var i,e,o,s,r,n,l,h=[];for(e=[],o=1,s=arguments.length;o<s;++o)e.push(arguments[o]);for(i=e,o=0,n=(r=this.evtHandler[t]||[]).length;o<n;++o)l=r[o],h.push(l.apply(this,i));return h},_init:function(){var t,o,s,r,n,l,h,d=this;for(t=0,o=this.dim.row;t<o;++t)for(s=t,r=0,n=this.dim.col;r<n;++r)l=r,this.addCell(l,s);return this.regrid(),this.dom.textarea.addEventListener("mousedown",function(t){return t.stopPropagation()}),(h=this.dom.sheet).addEventListener("mousedown",function(t){var i,o,s;if(d.edited(),(i=e(t.target,".cell",h))&&!((s={row:(o=d.index(i)).row,col:o.col}).col<0||s.row<0))return d.les.start=d.les.end=s,d.les.node=i,d.renderSelection()}),h.addEventListener("mousemove",function(t){var i,o;if(!d.editing.on&&t.buttons&&(i=e(t.target,".cell",h)))return d.les.end={row:(o=d.index(i)).row,col:o.col},d.renderSelection()}),h.addEventListener("dblclick",function(t){var i;if(i=e(t.target,".cell",h))return d.edit({node:i,quick:!1})}),document.body.addEventListener("paste",function(t){var o;if(e(document.activeElement,".sheet",h)&&d.les.start)return o=t.clipboardData.getData("text"),o=i(o),d.set({row:d.les.start.row,col:d.les.start.col,data:o,range:!0})}),h.addEventListener("keydown",function(t){var i,e,o,s,r,n,l,h,c,a,f,u,x;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return d.copy();if(d.eventInScope(t)){if(8===(i=t.keyCode)){if(!d.les.node)return;for(o=(e=[d.les.start,d.les.end])[0],s=e[1],r=(e=o.col<s.col?[o.col,s.col]:[s.col,o.col])[0],n=e[1],l=(e=o.row<s.row?[o.row,s.row]:[s.row,o.row])[0],h=e[1],c=l;c<=h;++c)for(a=c,f=r;f<=n;++f)u=f,d.set({row:a,col:u,data:""})}if((x=function(){switch(i){case 37:return{y:0,x:-1};case 38:return{y:-1,x:0};case 39:return{y:0,x:1};case 40:return{y:1,x:0};default:return null}}())&&(!d.editing.on||d.editing.quick))return d.move(x),t.stopPropagation(),t.preventDefault(),d.dom.sheet.focus()}}),h.addEventListener("keypress",function(t){if(d.les.node&&!d.editing.on)return d.edit({node:d.les.node,quick:13!==t.keyCode})}),this.dom.textarea.addEventListener("keydown",function(t){var i,e,o;return 27===t.keyCode?(d.edited({cancel:!0}),t.stopPropagation(),t.preventDefault(),void d.dom.sheet.focus()):13!==t.keyCode||t.altKey||t.metaKey?13===t.keyCode&&(t.altKey||t.metaKey)?(d.dom.textarea.value+="\n",d.dom.layout.textContent=d.dom.textarea.value+" ",i=d.dom.layout.getBoundingClientRect(),e=d.editing.node.getBoundingClientRect(),o=d.dom.textarea.style,o.width=Math.max(i.width,e.width+1)+"px",o.height=Math.max(i.height,e.height+1)+"px",o):void 0:(d.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void d.dom.sheet.focus())}),document.addEventListener("wheel",function(t){var i,e,o,s,r,n,l;return i=d.eventInScope(t),(null==d.opt.scrollLock||d.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(i||t.target===document.body)&&t.preventDefault(),!!i&&(e=d.scrollPos,o=[t.deltaX,t.deltaY],s=o[0],r=o[1],o=Math.abs(s)>Math.abs(r)?[s,0]:[0,r],s=o[0],r=o[1],o=[e.x,e.y],n=o[0],l=o[1],e.x+=s/30,e.y+=r/30,s=Math.round(e.x)-Math.round(n),(r=Math.round(e.y)-Math.round(l))>0?d._md(r):r<0?d._mu(r):s>0?d._mr(s):s<0&&d._ml(s),d.renderSelection(),t.preventDefault())},{passive:!1})},copy:function(){var t,i,e,o,s,r,n,l,h,d;if(this.les.start){for(t=[],i=this.les.start.row,e=this.les.end.row+1;i<e;++i){for(i,o=[],s=this.les.start.col,r=this.les.end.col+1;s<r;++s)n=s,"object"!=typeof(l=((h=this._data)[rpw]||(h[rpw]=[]))[n])&&o.push('"'+(""+l||"").replace(/"/g,'""')+'"');t.push(o.join("\t"))}return d=t.join("\n"),navigator.clipboard.writeText(d)}},eventInScope:function(t){return e(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(i){var e;return null==i?this._size:(this._size={row:(e=t({row:[],col:[]},i)).row,col:e.col},this.regrid())},regrid:function(){var t=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){var t,i,e=[];for(t=0,i=this.frozen.col;t<i;++t)e.push(t);return e}.call(this).map(function(i){return t._size.col[i]||"max-content"}).join(" ")+" "+function(){var t,i,e=[];for(t=this.xif.col[2],i=this.dim.col;t<i;++t)e.push(t);return e}.call(this).map(function(i){return t._size.col[i+t.pos.col-t.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){var t,i,e=[];for(t=0,i=this.frozen.row;t<i;++t)e.push(t);return e}.call(this).map(function(i){return t._size.row[i]||"max-content"}).join(" ")+" "+function(){var t,i,e=[];for(t=this.xif.row[2],i=this.dim.row;t<i;++t)e.push(t);return e}.call(this).map(function(i){return t._size.row[i+t.pos.row-t.xif.row[1]]||"max-content"}).join(" ")},addCell:function(t,i){var e;return e=document.createElement("div"),this.dom.inner.insertBefore(e,this.dom.inner.childNodes[i*this.dim.col+t]),this._content({x:t,y:i,n:e})},set:function(t){var i,e,o,s,r,n,l,h,d,c,a,f;if(i=t.row,e=t.col,o=t.data,s=t.range)for(n=0,l=o.length;n<l;++n)for(d=0,c=o[h=n].length;d<c;++d)a=d,((r=this._data)[f=h+i]||(r[f]=[]))[a+e]=o[h][a],this._content({y:h+i-this.pos.row+this.xif.row[1],x:a+e-this.pos.col+this.xif.col[1]});else((r=this._data)[i]||(r[i]=[]))[e]=o,this._content({y:i-this.pos.row+this.xif.row[1],x:e-this.pos.col+this.xif.col[1]});return this.fire("change",{row:i,col:e,data:o,range:!!s})},_content:function(t){var i,e,s,r,n,l,h,d,c;if(i=t.x,e=t.y,((s=t.n)||(s=this.dom.inner.childNodes[i+e*this.dim.col]))&&(n=i<this.xif.col[0]&&e<this.xif.col[0]?["","cell idx"]:i<this.xif.col[0]?(r=e<this.xif.row[1]?" ":e<this.xif.row[2]?e-this.xif.row[1]+1:e-this.xif.row[1]+this.pos.row+1,[r,"cell idx"]):e<this.xif.row[0]?(r=i<this.xif.col[1]?" ":o(i<this.xif.col[2]?i-this.xif.col[1]:i-this.xif.col[1]+this.pos.col),[r,"cell idx"]):i<this.xif.col[1]?[null,"cell fixed"]:e<this.xif.row[1]?[null,"cell fixed"]:i<this.xif.col[2]&&e<this.xif.row[2]?[((n=this._data)[l=e-this.xif.row[1]]||(n[l]=[]))[i-this.xif.col[1]],"cell frozen fixed"]:i<this.xif.col[2]?[((n=this._data)[l=this.pos.row+e-this.xif.row[1]]||(n[l]=[]))[i-this.xif.col[1]],"cell frozen"]:e<this.xif.row[2]?[((n=this._data)[l=e-this.xif.row[1]]||(n[l]=[]))[this.pos.col+i-this.xif.col[1]],"cell frozen"]:[((n=this._data)[l=this.pos.row+e-this.xif.row[1]]||(n[l]=[]))[this.pos.col+i-this.xif.col[1]],"cell"],h=n[0],d=n[1],null==h&&(h=""),c=i>=this.xif.col[0]&&e>=this.xif.row[0]?(this.cls.col[this.pos.col+i-this.xif.col[1]]||"")+" "+(this.cls.row[this.pos.row+e-this.xif.row[1]]||""):"",s.className=d+" "+c,null!==h)){if("object"!=typeof h)return s.textContent=h;if("dom"===h.type)return s.textContent="",s.appendChild(h.node)}},_md:function(t){var i,e,o,s,r,n,l,h,d,c;for(null==t&&(t=1),i=this.dom.inner,s=e=(o=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))>0?o:0;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l&&(h=n,d=this.dim.col*this.fix.row,i.childNodes[d]);++n)i.removeChild(i.childNodes[d]);for(s=e;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:this.dim.row+r,n:c}),i.appendChild(c);return this.pos.row+=t},_mu:function(t){var i,e,o,s,r,n,l,h,d,c,a=[];if(null==t&&(t=1),i=this.dom.inner,!(this.pos.row<=0)){for((t=Math.round(Math.abs(t)))>=this.pos.row&&(t=this.pos.row),s=e=(o=t-(this.dim.row-this.xif.row[2]))>0?o:0;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l&&(h=n,i.childNodes.length);++n)i.removeChild(i.childNodes[i.childNodes.length-1]);for(this.pos.row-=t,s=e;s<t;++s){for(r=s,d=[],n=0,l=this.dim.col;n<l;++n)h=n,c=document.createElement("div"),this._content({x:h,y:r+this.xif.row[2],n:c}),d.push(i.insertBefore(c,i.childNodes[h+(r-e)*this.dim.col+this.dim.col*this.xif.row[2]]));a.push(d)}return a}},_mr:function(t){var i,e,o,s,r,n,l,h;for(null==t&&(t=1),i=this.dom.inner,o=(e=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))>0?e:0;o<t;++o)for(s=o,r=0,n=this.dim.row;r<n;++r)l=r,i.removeChild(i.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+s,y:l,n:h}),i.insertBefore(h,i.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid()},_ml:function(t){var i,e,o,s,r,n,l,h,d;if(null==t&&(t=1),i=this.dom.inner,(t=Math.round(Math.abs(t)))>=this.pos.col&&(t=this.pos.col),!(this.pos.col<=0||t<=0)){for(e=(o=t-(this.dim.col-this.xif.col[2]))>0?o:0,this.pos.col-=t,s=e;s<t;++s)for(r=s,n=0,l=this.dim.row;n<l;++n)h=n,i.removeChild(i.childNodes[(h+1)*this.dim.col-1]),d=document.createElement("div"),this._content({x:r+this.xif.col[2],y:h,n:d}),i.insertBefore(d,i.childNodes[h*this.dim.col+this.xif.col[2]+r-e]);return this.regrid()}},goto:function(i){return null==i&&(i={row:0,col:0}),t(this.pos,i),this.render()},render:function(){var t,i,e,o,s,r,n,l=[];for(t=0,i=this.dim.row;t<i;++t){for(e=t,o=[],s=0,r=this.dim.col;s<r;++s)n=s,o.push(this._content({x:n,y:e}));l.push(o)}return l},move:function(t){var i,e,o,s,r;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(i=this.cell(t))){if(e=this.index(i),o=i.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),o.x+o.width>s.x+s.width&&this._mr(1),o.y+o.height>s.y+s.height&&this._md(1),0===e.x){if(0===this.pos.col)return;this._ml(1)}if(0===e.y){if(0===this.pos.row)return;this._mu(1)}if(i=this.cell(t))return this.les.node=i,this.les.start=this.les.end={col:(r=this.index(i)).col,row:r.row},this.renderSelection()}},edit:function(t){var i,e,o,s,r,n,l,h,d,c;if(i=t.node,e=t.quick,this._editing&&!(!(o=this.index(i))||o.col<0||o.row<0))return s=this.editing,s.node=i,s.quick=e,s.on=!0,this.dom.layout.textContent=i.textContent,r=this.dom.layout.getBoundingClientRect(),n=i.getBoundingClientRect(),l=this.dom.sheet.getBoundingClientRect(),s=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop],h=s[0],d=s[1],s=this.dom.edit.style,s.left=n.x-l.x+h-2+"px",s.top=n.y-l.y+d-2+"px",s.width="fit-content",s.height="fit-content",this.dom.edit.classList.toggle("show",!0),s=this.dom.textarea.style,s.width=Math.max(r.width,n.width+1)+"px",s.height=Math.max(r.height,n.height+1)+"px",this.dom.textarea.value=c=e?"":i.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(c.length,c.length)},edited:function(t){var i;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),i=this.editing,i.node=null,i.on=!1,i},index:function(t){var i,e,o,s,r;return(i=Array.from(this.dom.inner.childNodes).indexOf(t))<0?null:(e=i%this.dim.col,o=(i-e)/this.dim.col,s=e<this.xif.col[1]?-1:e<this.xif.col[2]?e-this.xif.col[1]:e-this.xif.col[1]+this.pos.col,r=o<this.xif.row[1]?-1:o<this.xif.row[2]?o-this.xif.row[1]:o-this.xif.row[1]+this.pos.row,{x:e,y:o,col:s,row:r})},cell:function(t){var i,e,o,s;if(null==t&&(t={}),null!=t.col){if(t.col<this.frozen.col)i=t.col;else{if(t.col-this.pos.col<this.frozen.col)return null;i=t.col-this.pos.col}if(t.row<this.frozen.row)e=t.row;else{if(t.row-this.pos.row<this.frozen.row)return null;e=t.row-this.pos.row}return o=[i+this.xif.col[1],e+this.xif.row[1]],i=o[0],e=o[1],i<0||e<0||i>=this.dim.col||e>=this.dim.row?null:this.dom.inner.childNodes[e*this.dim.col+i]}if(!(s=t.node?this.index(t.node):{y:0,x:0}))throw new Error("node not found in sheet");return e=s.y+(t.y||0),i=s.x+(t.x||0),this.dom.inner.childNodes[e*this.dim.col+i]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(){var t,i,e,o,s,r,n,l,h,d,c,a,f,u,x,w,m,p,g,v,y,_,C,M;if(this.les.start)return t=this.les.start.col<this.les.end.col?[this.les.start.col,this.les.end.col]:[this.les.end.col,this.les.start.col],i=t[0],e=t[1],t=this.les.start.row<this.les.end.row?[this.les.start.row,this.les.end.row]:[this.les.end.row,this.les.start.row],o=t[0],s=t[1],r=this.dom.inner.getBoundingClientRect(),n=this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),l=this.cell({col:i,row:o}),h=this.cell({col:i,row:s}),d=this.cell({col:e,row:o}),c=this.cell({col:e,row:s}),t=[n,l,h,d,c].map(function(t){return t?t.getBoundingClientRect():null}),a=t[0],f=t[1],u=t[2],x=t[3],w=t[4],a.width=0,a.height=0,m=(f||u||a).x-r.x,p=(f||x||a).y-r.y,g=(x||w||a).x+(x||w||a).width-r.x,v=(u||w||a).y+(u||w||a).height-r.y,y=g-m+1,_=v-p+1,C=this.cell(this.les.start),M=C?C.getBoundingClientRect():null,t=this.dom.range.style,t.left=m+"px",t.top=p+"px",t.width=y+"px",t.height=_+"px",this.dom.range.classList.toggle("show",!0),M&&((t=this.dom.caret.style).left=M.x-r.x-1+"px",t.top=M.y-r.y-1+"px",t.width=M.width+2+"px",t.height=M.height+2+"px",t.zIndex=this.les.start.row+this.xif.row[1]<this.xif.row[2]&&this.les.start.col+this.xif.col[1]<this.xif.col[2]?101:this.les.start.row+this.xif.row[1]<this.xif.row[2]||this.les.start.col+this.xif.col[1]<this.xif.col[2]?20:15),this.dom.caret.classList.toggle("show",!!M)},data:function(t){return null==t?this._data:(this._data=t,this.render())}}),"undefined"!=typeof module&&null!==module?module.exports=s:"undefined"!=typeof window&&null!==window&&(window.sheet=s)}).call(this);
|
package/package.json
CHANGED
|
@@ -1,70 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "zbryikt",
|
|
3
|
-
"name": "@plotdb/sheet",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"description": "spreadsheet",
|
|
6
|
-
"version": "0.1.5",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"homepage": "https://github.com/plotdb/sheet",
|
|
9
|
-
"files": [
|
|
10
|
-
"dist/**/*"
|
|
11
|
-
],
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/plotdb/sheet"
|
|
15
|
-
},
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": ">=10.14.1",
|
|
18
|
-
"npm": ">=6.4.1"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"start": "npx server -r web -o true",
|
|
22
|
-
"deploy": "npx deploy web/static"
|
|
23
|
-
},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"@loadingio/debounce.js": "0.0.1",
|
|
26
|
-
"@loadingio/ldquery": "^2.0.0",
|
|
27
|
-
"@plotdb/csscope": "^0.4.0",
|
|
28
|
-
"@plotdb/datadom": "0.0.4",
|
|
29
|
-
"@plotdb/json0": "0.0.1",
|
|
30
|
-
"@plotdb/rescope": "^1.1.8",
|
|
31
|
-
"body-parser": "^1.19.0",
|
|
32
|
-
"bootstrap": "^4.5.2",
|
|
33
|
-
"bootstrap.ldui": "github:loadingio/bootstrap.ldui",
|
|
34
|
-
"bootstrap.native": "^3.0.13",
|
|
35
|
-
"dompurify": "^2.2.6",
|
|
36
|
-
"fedep": "^0.0.12",
|
|
37
|
-
"jsoneditor": "^9.1.1",
|
|
38
|
-
"ldcover": "^1.3.1",
|
|
39
|
-
"ldiconfont": "^0.1.5",
|
|
40
|
-
"ldview": "^0.1.1",
|
|
41
|
-
"livescript": "^1.6.0",
|
|
42
|
-
"proxise": "^0.1.2",
|
|
43
|
-
"sharedb-wrapper": "github:zbryikt/sharedb-wrapper",
|
|
44
|
-
"stylus": "^0.54.5",
|
|
45
|
-
"template": "github:zbryikt/template#v2.3.13",
|
|
46
|
-
"uglify-js": "=3.2.0",
|
|
47
|
-
"uglifycss": "^0.0.29"
|
|
48
|
-
},
|
|
49
|
-
"frontendDependencies": {
|
|
50
|
-
"root": "web/static/assets/lib",
|
|
51
|
-
"modules": [
|
|
52
|
-
"bootstrap",
|
|
53
|
-
"bootstrap.ldui",
|
|
54
|
-
"bootstrap.native",
|
|
55
|
-
"@loadingio/ldquery",
|
|
56
|
-
"@loadingio/debounce.js",
|
|
57
|
-
"dompurify",
|
|
58
|
-
"ldview",
|
|
59
|
-
"ldcover",
|
|
60
|
-
"jsoneditor",
|
|
61
|
-
"ldiconfont",
|
|
62
|
-
"proxise",
|
|
63
|
-
"@plotdb/datadom",
|
|
64
|
-
"@plotdb/csscope",
|
|
65
|
-
"@plotdb/rescope",
|
|
66
|
-
"sharedb-wrapper",
|
|
67
|
-
"@plotdb/json0"
|
|
68
|
-
]
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.2.0","style":"index.min.css","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/sheet","repository":{"type":"git","url":"https://github.com/plotdb/sheet"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","deploy":"npx deploy web/static"},"devDependencies":{"@loadingio/debounce.js":"1.0.1","@loadingio/ldquery":"^3.0.1","@plotdb/csscope":"^4.0.0","@plotdb/datadom":"^0.2.0","@plotdb/json0":"^0.0.5","@plotdb/rescope":"^4.1.0","body-parser":"^1.19.0","bootstrap":"^4.5.2","@loadingio/bootstrap.ext":"^0.0.4","bootstrap.native":"^3.0.13","dompurify":"^2.2.6","fedep":"^1.1.2","jsoneditor":"^9.1.1","ldcover":"^3.0.1","ldiconfont":"^0.1.10","ldview":"^1.0.0","livescript":"^1.6.0","proxise":"^1.0.1","sharedb-wrapper":"^1.0.0","stylus":"^0.55.0","@zbryikt/template":"^2.3.33","uglify-js":"^3.13.1","uglifycss":"^0.0.29"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","@loadingio/bootstrap.ext","bootstrap.native","@loadingio/ldquery","@loadingio/debounce.js","dompurify","ldview","ldcover","jsoneditor","ldiconfont","proxise","@plotdb/datadom","@plotdb/csscope","@plotdb/rescope","sharedb-wrapper","@plotdb/json0"]}}
|
package/dist/index.min.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.sheet{position:relative;width:100%;height:100%;overflow:hidden;outline:0}.sheet .inner{z-index:1;display:grid;width:100%;height:100%;overflow:hidden}.sheet .cell{position:relative;user-select:none;border-width:0 1px 1px 0;border-style:solid;border-color:#ddd;padding:1px 3px;min-width:48px;line-height:26px;box-sizing:border-box;white-space:pre;overflow:hidden}.sheet .cell.idx{z-index:100;background:#f1f2f3;color:#919293;font-size:.85em;text-align:center;user-select:none}.sheet .cell.fixed,.sheet .cell.fixed.frozen{z-index:13}.sheet .cell.fixed{background:#fafbfc;white-space:initial;padding:0}.sheet .cell.frozen{z-index:12;background:#fdfeff}.sheet .cell.fixed.frozen{padding:1px 3px}.sheet .range{z-index:14;border:1px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .caret{z-index:15;border:2px solid #27f;user-select:none;pointer-events:none;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .edit{z-index:121;border:2px solid #27f;opacity:0;display:none;top:0;left:0;position:absolute}.sheet .edit textarea{display:block;border:0;outline:0}.sheet .layout{display:inline-block;top:0;left:0;position:absolute;z-index:0;opacity:0;pointer-events:none;user-select:none;white-space:pre}.sheet .show{opacity:1 !important;display:block}
|
package/dist/index.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(){var parseCsv,parent,idxToLabel,labelToIdx,sheet;parseCsv=function(txt){return Papa.parse(txt).data};parent=function(n,s,e){var m;m=n;while(n&&n!==e){n=n.parentNode}if(n!==e){return null}if(!s){return n}n=m;while(n&&n!==e&&(!n.matches||n.matches&&!n.matches(s))){n=n.parentNode}if(n===e&&(!e.matches||!e.matches(s))){return null}return n};idxToLabel=function(val){var radix,base,v,map,ret,i$,i,c;radix=Math.floor(Math.log((val+1)*25+1)/Math.log(26))-1;base=(Math.pow(26,radix+1)-1)/25-1;v=val-base;map="ABCDEFGHIJKLMNOPQRSTUVWXYZ";ret="";for(i$=0;i$<=radix;++i$){i=i$;c=map.charAt(v%26);ret=c+ret;v=(v-v%26)/26}return ret};labelToIdx=function(label){var radix,base,map,val,i$,i,idx;radix=label.length-1;base=(Math.pow(26,radix+1)-1)/25-1;map="ABCDEFGHIJKLMNOPQRSTUVWXYZ";val=0;for(i$=0;i$<=radix;++i$){i=i$;idx=map.indexOf(label[i]);if(idx<0){throw new Error("incorrect label")}val=val*26+idx}return val+base};sheet=function(opt){var ref$,this$=this;opt==null&&(opt={});this.opt=opt;this.root=typeof opt.root==="string"?document.querySelector(opt.root):opt.root;this.evtHandler={};this._data=opt.data||[];this.size={row:(ref$=import$({row:[],col:[]},opt.size)).row,col:ref$.col};this._editing=opt.editing!=null?!!opt.editing:true;this.dim={col:(opt.dim||(opt.dim={})).col||30,row:(opt.dim||(opt.dim={})).row||30};this.frozen={col:(ref$=import$({col:0,row:0},opt.frozen||{})).col,row:ref$.row};this.idx={col:(ref$=import$({row:true,col:true},opt.idx||{})).col,row:ref$.row};this.fixed={col:(ref$=import$({col:0,row:0},opt.fixed||{})).col,row:ref$.row};this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]};["row","col"].map(function(t){this$.xif[t][1]=this$.xif[t][0]+this$.fixed[t];return this$.xif[t][2]=this$.xif[t][1]+this$.frozen[t]});this.fix={row:this.xif.row[2],col:this.xif.col[2]};this.pos={col:0,row:0};this.scrollPos={x:0,y:0};this.sel={};this.les={};this.editing={};this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout"].map(function(it){var x$,n;x$=n=document.createElement("div");x$.classList.add(it);return[it,n]}));this.dom.sheet.setAttribute("tabindex",-1);this.dom.textarea=document.createElement("textarea");this.root.appendChild(this.dom.sheet);["inner","caret","range","edit","layout"].map(function(it){return this$.dom.sheet.appendChild(this$.dom[it])});this.dom.edit.appendChild(this.dom.textarea);this._init();return this};sheet.prototype=import$(Object.create(Object.prototype),{on:function(n,cb){var ref$;return((ref$=this.evtHandler)[n]||(ref$[n]=[])).push(cb)},fire:function(n){var v,res$,i$,to$,ref$,len$,cb,results$=[];res$=[];for(i$=1,to$=arguments.length;i$<to$;++i$){res$.push(arguments[i$])}v=res$;for(i$=0,len$=(ref$=this.evtHandler[n]||[]).length;i$<len$;++i$){cb=ref$[i$];results$.push(cb.apply(this,v))}return results$},_init:function(){var i$,to$,r,j$,to1$,c,dom,this$=this;for(i$=0,to$=this.dim.row;i$<to$;++i$){r=i$;for(j$=0,to1$=this.dim.col;j$<to1$;++j$){c=j$;this.addCell(c,r)}}this.regrid();this.dom.textarea.addEventListener("mousedown",function(e){return e.stopPropagation()});dom=this.dom.sheet;dom.addEventListener("mousedown",function(e){var p,ref$,idx;this$.edited();if(!(p=parent(e.target,".cell",dom))){return}idx={row:(ref$=this$.index(p)).row,col:ref$.col};if(idx.col<0||idx.row<0){return}this$.les.start=this$.les.end=idx;this$.les.node=p;return this$.renderSelection()});dom.addEventListener("mousemove",function(e){var p,ref$;if(this$.editing.on||!(e.buttons&&(p=parent(e.target,".cell",dom)))){return}this$.les.end={row:(ref$=this$.index(p)).row,col:ref$.col};return this$.renderSelection()});dom.addEventListener("dblclick",function(e){var p;if(!(p=parent(e.target,".cell",dom))){return}return this$.edit({node:p,quick:false})});document.body.addEventListener("paste",function(e){var data;if(!parent(document.activeElement,".sheet",dom)){return}if(!this$.les.start){return}data=e.clipboardData.getData("text");data=parseCsv(data);return this$.set({row:this$.les.start.row,col:this$.les.start.col,data:data,range:true})});dom.addEventListener("keydown",function(e){var code,ref$,p1,p2,c1,c2,r1,r2,i$,row,j$,col,opt;if(e.keyCode===67&&(e.metaKey||e.ctrlKey)){return this$.copy()}if(!this$.eventInScope(e)){return}code=e.keyCode;if(code===8){if(!this$.les.node){return}ref$=[this$.les.start,this$.les.end],p1=ref$[0],p2=ref$[1];ref$=p1.col<p2.col?[p1.col,p2.col]:[p2.col,p1.col],c1=ref$[0],c2=ref$[1];ref$=p1.row<p2.row?[p1.row,p2.row]:[p2.row,p1.row],r1=ref$[0],r2=ref$[1];for(i$=r1;i$<=r2;++i$){row=i$;for(j$=c1;j$<=c2;++j$){col=j$;this$.set({row:row,col:col,data:""})}}}opt=function(){switch(code){case 37:return{y:0,x:-1};case 38:return{y:-1,x:0};case 39:return{y:0,x:1};case 40:return{y:1,x:0};default:return null}}();if(!opt){return}if(this$.editing.on&&!this$.editing.quick){return}this$.move(opt);e.stopPropagation();e.preventDefault();return this$.dom.sheet.focus()});dom.addEventListener("keypress",function(e){if(this$.les.node&&!this$.editing.on){return this$.edit({node:this$.les.node,quick:e.keyCode===13?false:true})}});this.dom.textarea.addEventListener("keydown",function(e){var lbox,box,ref$;if(e.keyCode===27){this$.edited({cancel:true});e.stopPropagation();e.preventDefault();this$.dom.sheet.focus();return}if(e.keyCode===13&&!(e.altKey||e.metaKey)){this$.move({y:1,x:0});e.stopPropagation();e.preventDefault();this$.dom.sheet.focus();return}if(e.keyCode===13&&(e.altKey||e.metaKey)){this$.dom.textarea.value+="\n";this$.dom.layout.textContent=this$.dom.textarea.value+" ";lbox=this$.dom.layout.getBoundingClientRect();box=this$.editing.node.getBoundingClientRect();return ref$=this$.dom.textarea.style,ref$.width=Math.max(lbox.width,box.width+1)+"px",ref$.height=Math.max(lbox.height,box.height+1)+"px",ref$}});return document.addEventListener("wheel",function(e){var inscope,spos,ref$,dx,dy,ox,oy;inscope=this$.eventInScope(e);if(!(this$.opt.scrollLock!=null)||this$.opt.scrollLock){if(Math.abs(e.deltaX)>Math.abs(e.deltaY)){if(inscope||e.target===document.body){e.preventDefault()}}}if(!inscope){return false}spos=this$.scrollPos;ref$=[e.deltaX,e.deltaY],dx=ref$[0],dy=ref$[1];ref$=Math.abs(dx)>Math.abs(dy)?[dx,0]:[0,dy],dx=ref$[0],dy=ref$[1];ref$=[spos.x,spos.y],ox=ref$[0],oy=ref$[1];spos.x+=dx/30;spos.y+=dy/30;dx=Math.round(spos.x)-Math.round(ox);dy=Math.round(spos.y)-Math.round(oy);if(dy>0){this$._md(dy)}else if(dy<0){this$._mu(dy)}else if(dx>0){this$._mr(dx)}else if(dx<0){this$._ml(dx)}this$.renderSelection();return e.preventDefault()},{passive:false})},copy:function(){var c,i$,to$,row,r,j$,to1$,col,content,ref$,s;if(!this.les.start){return}c=[];for(i$=this.les.start.row,to$=this.les.end.row+1;i$<to$;++i$){row=i$;r=[];for(j$=this.les.start.col,to1$=this.les.end.col+1;j$<to1$;++j$){col=j$;content=((ref$=this._data)[rpw]||(ref$[rpw]=[]))[col];if(typeof content==="object"){continue}r.push('"'+(""+content||"").replace(/"/g,'""')+'"')}c.push(r.join("\t"))}s=c.join("\n");return navigator.clipboard.writeText(s)},eventInScope:function(e){return parent(e.target,".sheet",this.dom.sheet)===this.dom.sheet},regrid:function(){var this$=this;this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){var i$,to$,results$=[];for(i$=0,to$=this.frozen.col;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$.size.col[it]||"max-content"}).join(" ")+" "+function(){var i$,to$,results$=[];for(i$=this.xif.col[2],to$=this.dim.col;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$.size.col[it+this$.pos.col-this$.xif.col[1]]||"max-content"}).join(" ");return this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){var i$,to$,results$=[];for(i$=0,to$=this.frozen.row;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$.size.row[it]||"max-content"}).join(" ")+" "+function(){var i$,to$,results$=[];for(i$=this.xif.row[2],to$=this.dim.row;i$<to$;++i$){results$.push(i$)}return results$}.call(this).map(function(it){return this$.size.row[it+this$.pos.row-this$.xif.row[1]]||"max-content"}).join(" ")},addCell:function(x,y){var div;div=document.createElement("div");this.dom.inner.insertBefore(div,this.dom.inner.childNodes[y*this.dim.col+x]);return this._content({x:x,y:y,n:div})},set:function(arg$){var row,col,data,range,ref$,i$,to$,r,j$,to1$,c,key$;row=arg$.row,col=arg$.col,data=arg$.data,range=arg$.range;if(!range){((ref$=this._data)[row]||(ref$[row]=[]))[col]=data;this._content({y:row-this.pos.row+this.xif.row[1],x:col-this.pos.col+this.xif.col[1]})}else{for(i$=0,to$=data.length;i$<to$;++i$){r=i$;for(j$=0,to1$=data[r].length;j$<to1$;++j$){c=j$;((ref$=this._data)[key$=r+row]||(ref$[key$]=[]))[c+col]=data[r][c];this._content({y:r+row-this.pos.row+this.xif.row[1],x:c+col-this.pos.col+this.xif.col[1]})}}}return this.fire("change",{row:row,col:col,data:data,range:!!range})},_content:function(arg$){var x,y,n,v,ref$,key$,content,className;x=arg$.x,y=arg$.y,n=arg$.n;if(!n&&!(n=this.dom.inner.childNodes[x+y*this.dim.col])){return}ref$=x<this.xif.col[0]&&y<this.xif.col[0]?["","cell idx"]:x<this.xif.col[0]?(v=y<this.xif.row[1]?" ":y<this.xif.row[2]?y-this.xif.row[1]+1:y-this.xif.row[1]+this.pos.row+1,[v,"cell idx"]):y<this.xif.row[0]?(v=x<this.xif.col[1]?" ":x<this.xif.col[2]?idxToLabel(x-this.xif.col[1]):idxToLabel(x-this.xif.col[1]+this.pos.col),[v,"cell idx"]):x<this.xif.col[1]?[null,"cell fixed"]:y<this.xif.row[1]?[null,"cell fixed"]:x<this.xif.col[2]&&y<this.xif.row[2]?[((ref$=this._data)[key$=y-this.xif.row[1]]||(ref$[key$]=[]))[x-this.xif.col[1]],"cell frozen fixed"]:x<this.xif.col[2]?[((ref$=this._data)[key$=this.pos.row+y-this.xif.row[1]]||(ref$[key$]=[]))[x-this.xif.col[1]],"cell frozen"]:y<this.xif.row[2]?[((ref$=this._data)[key$=y-this.xif.row[1]]||(ref$[key$]=[]))[this.pos.col+x-this.xif.col[1]],"cell frozen"]:[((ref$=this._data)[key$=this.pos.row+y-this.xif.row[1]]||(ref$[key$]=[]))[this.pos.col+x-this.xif.col[1]],"cell"],content=ref$[0],className=ref$[1];if(!(content!=null)){content=""}n.className=className;if(content!==null){if(typeof content==="object"){if(content.type==="dom"){n.textContent="";return n.appendChild(content.node)}}else{return n.textContent=content}}},_md:function(mag){var inner,start,ref$,i$,j,j$,to$,i,idx,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));start=(ref$=mag-(this.dim.row-this.fix.row))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;idx=this.dim.col*this.fix.row;if(!inner.childNodes[idx]){break}inner.removeChild(inner.childNodes[idx])}}for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;n=document.createElement("div");this._content({x:i,y:this.dim.row+j,n:n});inner.appendChild(n)}}return this.pos.row+=mag},_mu:function(mag){var inner,start,ref$,i$,j,j$,to$,i,lresult$,n,results$=[];mag==null&&(mag=1);inner=this.dom.inner;if(this.pos.row<=0){return}mag=Math.round(Math.abs(mag));if(mag>=this.pos.row){mag=this.pos.row}start=(ref$=mag-(this.dim.row-this.xif.row[2]))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;if(!inner.childNodes.length){break}inner.removeChild(inner.childNodes[inner.childNodes.length-1])}}this.pos.row-=mag;for(i$=start;i$<mag;++i$){j=i$;lresult$=[];for(j$=0,to$=this.dim.col;j$<to$;++j$){i=j$;n=document.createElement("div");this._content({x:i,y:j+this.xif.row[2],n:n});lresult$.push(inner.insertBefore(n,inner.childNodes[i+(j-start)*this.dim.col+this.dim.col*this.xif.row[2]]))}results$.push(lresult$)}return results$},_mr:function(mag){var inner,start,ref$,i$,j,j$,to$,i,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));start=(ref$=mag-(this.dim.col-this.fix.col))>0?ref$:0;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.row;j$<to$;++j$){i=j$;inner.removeChild(inner.childNodes[i*this.dim.col+this.fix.col]);n=document.createElement("div");this._content({x:this.dim.col+j,y:i,n:n});inner.insertBefore(n,inner.childNodes[(i+1)*this.dim.col-1])}}this.pos.col+=mag;return this.regrid()},_ml:function(mag){var inner,start,ref$,i$,j,j$,to$,i,n;mag==null&&(mag=1);inner=this.dom.inner;mag=Math.round(Math.abs(mag));if(mag>=this.pos.col){mag=this.pos.col}if(this.pos.col<=0||mag<=0){return}start=(ref$=mag-(this.dim.col-this.xif.col[2]))>0?ref$:0;this.pos.col-=mag;for(i$=start;i$<mag;++i$){j=i$;for(j$=0,to$=this.dim.row;j$<to$;++j$){i=j$;inner.removeChild(inner.childNodes[(i+1)*this.dim.col-1]);n=document.createElement("div");this._content({x:j+this.xif.col[2],y:i,n:n});inner.insertBefore(n,inner.childNodes[i*this.dim.col+this.xif.col[2]+j-start])}}return this.regrid()},goto:function(opt){opt==null&&(opt={row:0,col:0});import$(this.pos,opt);return this.render()},render:function(){var i$,to$,y,lresult$,j$,to1$,x,results$=[];for(i$=0,to$=this.dim.row;i$<to$;++i$){y=i$;lresult$=[];for(j$=0,to1$=this.dim.col;j$<to1$;++j$){x=j$;lresult$.push(this._content({x:x,y:y}))}results$.push(lresult$)}return results$},move:function(opt){var node,idx,box,sbox,ref$;opt==null&&(opt={});if(this.editing.on){this.edited()}if(!(opt.node=this.les.node)){return}if(!(node=this.cell(opt))){return}idx=this.index(node);box=node.getBoundingClientRect();sbox=this.dom.sheet.getBoundingClientRect();if(box.x+box.width>sbox.x+sbox.width){this._mr(1)}if(box.y+box.height>sbox.y+sbox.height){this._md(1)}if(idx.x===0){if(this.pos.col===0){return}else{this._ml(1)}}if(idx.y===0){if(this.pos.row===0){return}else{this._mu(1)}}if(!(node=this.cell(opt))){return}this.les.node=node;this.les.start=this.les.end={col:(ref$=this.index(node)).col,row:ref$.row};return this.renderSelection()},edit:function(arg$){var node,quick,idx,ref$,lbox,box,rbox,sx,sy,v;node=arg$.node,quick=arg$.quick;if(!this._editing){return}idx=this.index(node);if(!idx||idx.col<0||idx.row<0){return}ref$=this.editing;ref$.node=node;ref$.quick=quick;ref$.on=true;this.dom.layout.textContent=node.textContent;lbox=this.dom.layout.getBoundingClientRect();box=node.getBoundingClientRect();rbox=this.dom.sheet.getBoundingClientRect();ref$=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop],sx=ref$[0],sy=ref$[1];ref$=this.dom.edit.style;ref$.left=box.x-rbox.x+sx-2+"px";ref$.top=box.y-rbox.y+sy-2+"px";ref$.width="fit-content";ref$.height="fit-content";this.dom.edit.classList.toggle("show",true);ref$=this.dom.textarea.style;ref$.width=Math.max(lbox.width,box.width+1)+"px";ref$.height=Math.max(lbox.height,box.height+1)+"px";this.dom.textarea.value=v=quick?"":node.textContent||"";this.dom.textarea.focus();return this.dom.textarea.setSelectionRange(v.length,v.length)},edited:function(opt){var v,ref$;opt==null&&(opt={});if(!this.editing.on){return}if(!opt.cancel){this.set({row:this.les.start.row,col:this.les.start.col,data:v=this.dom.textarea.value||""})}this.dom.edit.classList.toggle("show",false);return ref$=this.editing,ref$.node=null,ref$.on=false,ref$},index:function(node){var idx,x,y,col,row;idx=Array.from(this.dom.inner.childNodes).indexOf(node);if(idx<0){return null}x=idx%this.dim.col;y=(idx-x)/this.dim.col;if(x<this.xif.col[1]){col=-1}else if(x<this.xif.col[2]){col=x-this.xif.col[1]}else{col=x-this.xif.col[1]+this.pos.col}if(y<this.xif.row[1]){row=-1}else if(y<this.xif.row[2]){row=y-this.xif.row[1]}else{row=y-this.xif.row[1]+this.pos.row}return{x:x,y:y,col:col,row:row}},cell:function(opt){var x,y,ref$,base;opt==null&&(opt={});if(opt.col!=null){if(opt.col<this.frozen.col){x=opt.col}else if(opt.col-this.pos.col<this.frozen.col){return null}else{x=opt.col-this.pos.col}if(opt.row<this.frozen.row){y=opt.row}else if(opt.row-this.pos.row<this.frozen.row){return null}else{y=opt.row-this.pos.row}ref$=[x+this.xif.col[1],y+this.xif.row[1]],x=ref$[0],y=ref$[1];if(x<0||y<0||x>=this.dim.col||y>=this.dim.row){return null}return this.dom.inner.childNodes[y*this.dim.col+x]}else{base=opt.node?this.index(opt.node):{y:0,x:0};if(!base){throw new Error("node not found in sheet")}y=base.y+(opt.y||0);x=base.x+(opt.x||0);return this.dom.inner.childNodes[y*this.dim.col+x]}},editing:function(v){return!(v!=null)?this._editing:this._editing=!!v},renderSelection:function(){var ref$,sc,ec,sr,er,rbox,c0,c1,c2,c3,c4,b0,b1,b2,b3,b4,x1,y1,x2,y2,w,h,snode,sbox;if(!this.les.start){return}ref$=this.les.start.col<this.les.end.col?[this.les.start.col,this.les.end.col]:[this.les.end.col,this.les.start.col],sc=ref$[0],ec=ref$[1];ref$=this.les.start.row<this.les.end.row?[this.les.start.row,this.les.end.row]:[this.les.end.row,this.les.start.row],sr=ref$[0],er=ref$[1];rbox=this.dom.inner.getBoundingClientRect();c0=this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row});c1=this.cell({col:sc,row:sr});c2=this.cell({col:sc,row:er});c3=this.cell({col:ec,row:sr});c4=this.cell({col:ec,row:er});ref$=[c0,c1,c2,c3,c4].map(function(it){if(it){return it.getBoundingClientRect()}else{return null}}),b0=ref$[0],b1=ref$[1],b2=ref$[2],b3=ref$[3],b4=ref$[4];b0.width=0;b0.height=0;x1=(b1||b2||b0).x-rbox.x;y1=(b1||b3||b0).y-rbox.y;x2=(b3||b4||b0).x+(b3||b4||b0).width-rbox.x;y2=(b2||b4||b0).y+(b2||b4||b0).height-rbox.y;w=x2-x1+1;h=y2-y1+1;snode=this.cell(this.les.start);sbox=!snode?null:snode.getBoundingClientRect();ref$=this.dom.range.style;ref$.left=x1+"px";ref$.top=y1+"px";ref$.width=w+"px";ref$.height=h+"px";this.dom.range.classList.toggle("show",true);if(sbox){ref$=this.dom.caret.style;ref$.left=sbox.x-rbox.x-1+"px";ref$.top=sbox.y-rbox.y-1+"px";ref$.width=sbox.width+2+"px";ref$.height=sbox.height+2+"px";ref$.zIndex=this.les.start.row+this.xif.row[1]<this.xif.row[2]&&this.les.start.col+this.xif.col[1]<this.xif.col[2]?101:this.les.start.row+this.xif.row[1]<this.xif.row[2]||this.les.start.col+this.xif.col[1]<this.xif.col[2]?20:15}return this.dom.caret.classList.toggle("show",!!sbox)},data:function(it){if(!(it!=null)){return this._data}this._data=it;return this.render()}});if(typeof module!="undefined"&&module!==null){module.exports=sheet}else if(typeof window!="undefined"&&window!==null){window.sheet=sheet}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}}).call(this);
|