@plotdb/sheet 0.5.3 → 0.5.5
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 +7 -0
- package/index.js +49 -0
- 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.5.5
|
|
4
|
+
|
|
5
|
+
- support `menu.on` and `menu.off` event
|
|
6
|
+
- fix bug: right click incorrectly considered as selection.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## v0.5.4
|
|
10
|
+
|
|
11
|
+
- add `insert` api
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
## v0.5.3
|
|
4
15
|
|
|
5
16
|
- cell lookup now doesn't throw exception if node not found.
|
package/README.md
CHANGED
|
@@ -91,6 +91,13 @@ Following are a list of possible events:
|
|
|
91
91
|
- `col`: base col of the updated cell
|
|
92
92
|
- `data`: data used to update. If it's a 2D array and `range` is true, then cells are updated with values in `data` correspondingly relative to `row` and `col` as the original cell
|
|
93
93
|
- `range`: true if a range of cells are updated.
|
|
94
|
+
- `menu.on`: fired when a `contextmenu` event is fired within sheet. Option is an object with following fields:
|
|
95
|
+
- `evt`: corresponding event object
|
|
96
|
+
- `node`: target node from which this event was fired.
|
|
97
|
+
- `menu.off`: fired when a context menu is expected to dismiss. Option is an object with following fields:
|
|
98
|
+
- `evt`: corresponding event object
|
|
99
|
+
- `node`: target node from which this event was fired.
|
|
100
|
+
|
|
94
101
|
|
|
95
102
|
## Rich Text
|
|
96
103
|
|
package/index.js
CHANGED
|
@@ -176,9 +176,35 @@
|
|
|
176
176
|
this.dom.textarea.addEventListener('mousedown', function(e){
|
|
177
177
|
return e.stopPropagation();
|
|
178
178
|
});
|
|
179
|
+
this.dom.sheet.addEventListener('contextmenu', function(e){
|
|
180
|
+
this$.fire('menu.on', {
|
|
181
|
+
evt: e,
|
|
182
|
+
node: e.target
|
|
183
|
+
});
|
|
184
|
+
if (this$._menuOff) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this$._menuOff = function(e){
|
|
188
|
+
if (e.type === 'keydown' && e.keyCode !== 27) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
document.body.removeEventListener('click', this$._menuOff);
|
|
192
|
+
document.body.removeEventListener('keydown', this$._menuOff);
|
|
193
|
+
this$._menuOff = null;
|
|
194
|
+
return this$.fire('menu.off', {
|
|
195
|
+
evt: e,
|
|
196
|
+
node: e.target
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
document.body.addEventListener('click', this$._menuOff);
|
|
200
|
+
return document.body.addEventListener('keydown', this$._menuOff);
|
|
201
|
+
});
|
|
179
202
|
dom = this.dom.sheet;
|
|
180
203
|
dom.addEventListener('mousedown', function(e){
|
|
181
204
|
var p, ref$, idx;
|
|
205
|
+
if (e.button > 1) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
182
208
|
this$.edited();
|
|
183
209
|
if (!(p = parent(e.target, '.cell', dom))) {
|
|
184
210
|
return;
|
|
@@ -1131,6 +1157,29 @@
|
|
|
1131
1157
|
this._data = it;
|
|
1132
1158
|
return this.render();
|
|
1133
1159
|
},
|
|
1160
|
+
insert: function(){
|
|
1161
|
+
var ref$, sc, ec, sr, er, d;
|
|
1162
|
+
ref$ = this._bound({
|
|
1163
|
+
defined: false
|
|
1164
|
+
}), sc = ref$.sc, ec = ref$.ec, sr = ref$.sr, er = ref$.er;
|
|
1165
|
+
if (ec == null) {
|
|
1166
|
+
d = this._data.splice(sr, 0, []);
|
|
1167
|
+
}
|
|
1168
|
+
if (er == null) {
|
|
1169
|
+
d = this._data.map(function(it){
|
|
1170
|
+
return it.splice(sc, 0, '');
|
|
1171
|
+
});
|
|
1172
|
+
}
|
|
1173
|
+
this.fire('change', {
|
|
1174
|
+
row: sr,
|
|
1175
|
+
col: sc,
|
|
1176
|
+
data: d,
|
|
1177
|
+
range: true
|
|
1178
|
+
});
|
|
1179
|
+
this.les.end = this.les.start;
|
|
1180
|
+
this.renderSelection();
|
|
1181
|
+
this.render();
|
|
1182
|
+
},
|
|
1134
1183
|
slice: function(){
|
|
1135
1184
|
var ref$, sc, ec, sr, er, d;
|
|
1136
1185
|
ref$ = this._bound({
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var u,f,r,t;function o(t,e){var i,o={}.hasOwnProperty;for(i in e)o.call(e,i)&&(t[i]=e[i]);return t}u=function(t){return Papa.parse(t).data},f=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},r=function(t){for(var e=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,i=t-((Math.pow(26,1+e)-1)/25-1),o="",s=0;s<=e;++s)o="ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i%26)+o,i=(i-i%26)/26;return o},(t=function(t){var e,i=this;return this.opt=t=null==t?{}:t,this.root="string"==typeof t.root?document.querySelector(t.root):t.root,this.evtHandler={},this._data=t.data||[],this._size={row:(e=o({row:[],col:[]},t.size)).row,col:e.col},this.cls={row:(e=o({row:[],col:[]},t.class)).row,col:e.col},this._editing=null==t.editing||!!t.editing,this.dim={col:(t.dim||(t.dim={})).col||30,row:(t.dim||(t.dim={})).row||30},this.frozen={col:(e=o({col:0,row:0},t.frozen||{})).col,row:e.row},this.idx={col:(e=o({row:!0,col:!0},t.idx||{})).col,row:e.row},this.fixed={col:(e=o({col:0,row:0},t.fixed||{})).col,row:e.row},this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]},["row","col"].map(function(t){return i.xif[t][1]=i.xif[t][0]+i.fixed[t],i.xif[t][2]=i.xif[t][1]+i.frozen[t]}),this.fix={row:this.xif.row[2],col:this.xif.col[2]},this.pos={col:0,row:0},this.scrollPos={x:0,y:0},this.sel={cut:{}},this.les={},this.editing={},this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout","range-cut"].map(function(t){var e;e=document.createElement("div");return e.classList.add(t),[t,e]})),this.dom.sheet.setAttribute("tabindex",-1),this.dom.textarea=document.createElement("textarea"),this.root.appendChild(this.dom.sheet),["inner","caret","range","edit","layout","range-cut"].map(function(t){return i.dom.sheet.appendChild(i.dom[t])}),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=o(Object.create(Object.prototype),{on:function(t,e){var i;return((i=this.evtHandler)[t]||(i[t]=[])).push(e)},fire:function(t){for(var e,i,o,s,r=[],n=[],l=1,h=arguments.length;l<h;++l)n.push(arguments[l]);for(e=n,l=0,o=(i=this.evtHandler[t]||[]).length;l<o;++l)s=i[l],r.push(s.apply(this,e));return r},_init:function(){for(var t,e,i,o,d,a=this,s=0,r=this.dim.row;s<r;++s)for(t=s,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()}),(d=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(a.edited(),e=f(t.target,".cell",d))return(o={row:(i=a.index(e)).row,col:i.col}).col<0||o.row<0?(t.shiftKey&&a.les.start||(a.les.node=a.cell(a.les.start),a.les.start={col:0<(i=o.col)?i:0,row:0<(i=o.row)?i:0}),a.les.end={col:0<=o.col?o.col:void 0,row:0<=o.row?o.row:void 0},void a.renderSelection()):(t.shiftKey&&a.les.start?a.les.end=o:(a.les.start=a.les.end=o,a.les.node=e),a.renderSelection())}),d.addEventListener("mousemove",function(t){var e;if(!a.editing.on&&t.buttons&&(e=f(t.target,".cell",d)))return e={row:(e=a.index(e)).row,col:e.col},a.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},a.renderSelection()}),d.addEventListener("dblclick",function(t){if(t=f(t.target,".cell",d))return a.edit({node:t,quick:!1})}),document.body.addEventListener("paste",function(t){var e,i,o,s,r,n,l,h,c;if(f(document.activeElement,".sheet",d)&&a.les.start&&(s=t.clipboardData.getData("text"),e=u(s),a.set({row:a.les.start.row,col:a.les.start.col,data:e,range:!0}),a.sel.cut)){if(a._toText({sel:a.sel.cut})===s){for(i=(e=a._bound({sel:a.sel.cut})).sc,o=e.ec,s=e.sr,r=e.er,n=s;n<=r;++n)for(l=n,h=i;h<=o;++h)c=h,a.set({row:l,col:c,data:""});navigator.clipboard.writeText("")}return a.sel.cut=null,a.dom["range-cut"].classList.toggle("show",!1)}}),d.addEventListener("keydown",function(t){var e,i,o,s,r,n,l,h,c,d=t.keyCode;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return a.copy();if(88===t.keyCode&&(t.metaKey||t.ctrlKey))return a.copy({cut:!0});if(a.eventInScope(t)){if(8===d){if(!a.les.node)return;for(e=(c=a._bound()).sc,i=c.ec,o=c.sr,s=c.er,r=[],n=o;n<=s;++n){for(l=[],h=e;h<=i;++h)l.push("");r.push(l)}c=r,a.set({row:o,col:e,data:c,range:!0})}if(189===d&&(t.metaKey||t.ctrlKey)&&a.slice(),(c=function(){switch(d){case 37:return{y:0,x:-1};case 38:return{y:-1,x:0};case 39:return{y:0,x:1};case 40:return{y:1,x:0};default:return null}}())&&(!a.editing.on||a.editing.quick))return a.move(c),t.stopPropagation(),t.preventDefault(),a.dom.sheet.focus()}}),d.addEventListener("keypress",function(t){if(31!==t.keyCode||!t.metaKey&&!t.ctrlKey)return a.les.node&&!a.editing.on?a.edit({node:a.les.node,quick:13!==t.keyCode}):void 0}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o;return 27===t.keyCode?(a.edited({cancel:!0}),t.stopPropagation(),t.preventDefault(),void a.dom.sheet.focus()):13!==t.keyCode||t.altKey||t.metaKey?13===t.keyCode&&(t.altKey||t.metaKey)?(a.dom.textarea.value+="\n",a.dom.layout.textContent=a.dom.textarea.value+" ",e=a.dom.layout.getBoundingClientRect(),i=a.editing.node.getBoundingClientRect(),(o=a.dom.textarea.style).width=Math.max(e.width,i.width+1)+"px",o.height=Math.max(e.height,i.height+1)+"px",o):void 0:(a.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void a.dom.sheet.focus())}),document.addEventListener("wheel",function(t){var e,i,o,s,r=a.eventInScope(t);return(null==a.opt.scrollLock||a.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!r&&t.target!==document.body||t.preventDefault()),!!r&&(e=a.scrollPos,i=(s=[t.deltaX,t.deltaY])[0],o=s[1],i=(s=Math.abs(i)>Math.abs(o)?[i,0]:[0,o])[0],o=s[1],r=(s=[e.x,e.y])[0],s=s[1],e.x+=i/30,e.y+=o/30,i=Math.round(e.x)-Math.round(r),0<(o=Math.round(e.y)-Math.round(s))?a._md(o):o<0?a._mu(o):0<i?a._mr(i):i<0&&a._ml(i),a.renderSelection(),t.preventDefault())},{passive:!1})},select:function(t){var e,i;if(!arguments.length)return this.les.start?((e={}).col=this.les.start.col,e.row=this.les.start.row,this.les.end?(null==this.les.end.col?delete e.col:e.colspan=this.les.end.col-e.col+1,null==this.les.end.row?delete e.row:e.rowspan=this.les.end.row-e.row+1):(e.colspan=1,e.rowspan=1),e):null;this.les={},t&&(this.les={start:{col:0,row:0},end:{}},null!=t.row&&(this.les.start.row=t.row,this.les.end.row=t.row+((i=t.rowspan)&&1<i?i:1)-1),null!=t.col&&(this.les.start.col=t.col,this.les.end.col=t.col+((i=t.colspan)&&1<i?i:1)-1)),this.renderSelection()},_bound:function(t){var e,i,o,s,r;return e=(r=[(o=(t=null==t?{}:t).sel||this.les).start,o.end])[1],(s=r[0])&&e?(i=(r=s.col<e.col||null==e.col?[s.col,e.col]:[e.col,s.col])[0],o=r[1],s=(r=s.row<e.row||null==e.row?[s.row,e.row]:[e.row,s.row])[0],r=r[1],null!=t.defined&&!t.defined||(null==o&&(o=Math.max.apply(Math,this._data.map(function(t){return t.length}))),null==r&&(r=this._data.length)),{sc:i,ec:o,sr:s,er:r}):{sc:0,ec:0,sr:0,er:0}},_toText:function(t){var e,i,o,s,r,n,l,h,c,d,t=t.sel;if(!t||!t.start)return"";for(e=[],o=(i=this._bound({sel:t})).sc,s=i.ec,t=i.sr,r=i.er,n=t;n<=r;++n){for(l=n,h=[],c=o;c<=s;++c)d=c,"object"!=typeof(d=null==(d=((i=this._data)[l]||(i[l]=[]))[d])?"":d)&&h.push('"'+(""+d||"").replace(/"/g,'""')+'"');e.push(h.join("\t"))}return e.join("\n")},copy:function(t){var e;if(null==t&&(t={}),this.les.start)return e=this._toText({sel:this.les}),navigator.clipboard.writeText(e),t.cut?(this.sel.cut={start:this.les.start,end:this.les.end},this.renderSelection(this.sel.cut,{cut:!0})):void 0},eventInScope:function(t){return f(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(t){return null==t?this._size:(this._size={row:(t=o({row:[],col:[]},t)).row,col:t.col},this.regrid())},regrid:function(){var e=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.col[2],i=this.dim.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t+e.pos.col-e.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.row[2],i=this.dim.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t+e.pos.row-e.xif.row[1]]||"max-content"}).join(" ")},addCell:function(t,e){var i=document.createElement("div");return this.dom.inner.insertBefore(i,this.dom.inner.childNodes[e*this.dim.col+t]),this._content({x:t,y:e,n:i})},set:function(t){var e,i,o,s,r,n,l,h,c=t.row,d=t.col,a=t.data,t=t.range;if(t)for(i=0,o=a.length;i<o;++i)for(r=0,n=a[s=i].length;r<n;++r)l=r,((e=this._data)[h=s+c]||(e[h]=[]))[l+d]=a[s][l],this._content({y:s+c-this.pos.row+this.xif.row[1],x:l+d-this.pos.col+this.xif.col[1]});else((e=this._data)[c]||(e[c]=[]))[d]=a,this._content({y:c-this.pos.row+this.xif.row[1],x:d-this.pos.col+this.xif.col[1]});return this.fire("change",{row:c,col:d,data:a,range:!!t})},_content:function(t){var e,i,o=t.x,s=t.y,t=t.n;if(t=t||this.dom.inner.childNodes[o+s*this.dim.col])return e=(i=o<this.xif.col[0]&&s<this.xif.col[0]?["","cell idx"]:o<this.xif.col[0]?[s<this.xif.row[1]?" ":s<this.xif.row[2]?s-this.xif.row[1]+1:s-this.xif.row[1]+this.pos.row+1,"cell idx"]:s<this.xif.row[0]?[o<this.xif.col[1]?" ":o<this.xif.col[2]?r(o-this.xif.col[1]):r(o-this.xif.col[1]+this.pos.col),"cell idx"]:o<this.xif.col[1]||s<this.xif.row[1]?[null,"cell fixed"]:o<this.xif.col[2]&&s<this.xif.row[2]?[((i=this._data)[e=s-this.xif.row[1]]||(i[e]=[]))[o-this.xif.col[1]],"cell frozen fixed"]:o<this.xif.col[2]?[((i=this._data)[e=this.pos.row+s-this.xif.row[1]]||(i[e]=[]))[o-this.xif.col[1]],"cell frozen"]:s<this.xif.row[2]?[((i=this._data)[e=s-this.xif.row[1]]||(i[e]=[]))[this.pos.col+o-this.xif.col[1]],"cell frozen"]:[((i=this._data)[e=this.pos.row+s-this.xif.row[1]]||(i[e]=[]))[this.pos.col+o-this.xif.col[1]],"cell"])[0],i=i[1],null==e&&(e=""),s=o>=this.xif.col[0]&&s>=this.xif.row[0]?(this.cls.col[this.pos.col+o-this.xif.col[1]]||"")+" "+(this.cls.row[this.pos.row+s-this.xif.row[1]]||""):"",t.className=(i+" "+s).trim(),null!==e?"object"!=typeof e?t.textContent=e:"dom"===e.type?(t.textContent="",t.appendChild(e.node)):void 0:void 0},_md:function(t){var e,i,o,s,r,n,l,h,c;for(null==t&&(t=1),e=this.dom.inner,o=i=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))?i:0;o<t;++o)for(s=o,r=0,n=this.dim.col;r<n&&(l=r,h=this.dim.col*this.fix.row,e.childNodes[h]);++r)e.removeChild(e.childNodes[h]);for(o=i;o<t;++o)for(s=o,r=0,n=this.dim.col;r<n;++r)l=r,c=document.createElement("div"),this._content({x:l,y:this.dim.row+s,n:c}),e.appendChild(c);return this.pos.row+=t},_mu:function(t){var e,i,o,s,r,n,l,h,c,d,a=[];if(null==t&&(t=1),e=this.dom.inner,!(this.pos.row<=0)){for(s=i=0<(o=(t=(t=Math.round(Math.abs(t)))>=this.pos.row?this.pos.row:t)-(this.dim.row-this.xif.row[2]))?o:0;s<t;++s)for(r=s,n=0,l=this.dim.col;n<l&&(h=n,e.childNodes.length);++n)e.removeChild(e.childNodes[e.childNodes.length-1]);for(this.pos.row-=t,s=i;s<t;++s){for(r=s,c=[],n=0,l=this.dim.col;n<l;++n)h=n,d=document.createElement("div"),this._content({x:h,y:r+this.xif.row[2],n:d}),c.push(e.insertBefore(d,e.childNodes[h+(r-i)*this.dim.col+this.dim.col*this.xif.row[2]]));a.push(c)}return a}},_mr:function(t){var e,i,o,s,r,n,l,h;for(null==t&&(t=1),e=this.dom.inner,o=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))?i:0;o<t;++o)for(s=o,r=0,n=this.dim.row;r<n;++r)l=r,e.removeChild(e.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+s,y:l,n:h}),e.insertBefore(h,e.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid()},_ml:function(t){var e,i,o,s,r,n,l,h,c;if(null==t&&(t=1),e=this.dom.inner,(t=Math.round(Math.abs(t)))>=this.pos.col&&(t=this.pos.col),!(this.pos.col<=0||t<=0)){for(i=0<(o=t-(this.dim.col-this.xif.col[2]))?o:0,this.pos.col-=t,s=i;s<t;++s)for(r=s,n=0,l=this.dim.row;n<l;++n)h=n,e.removeChild(e.childNodes[(h+1)*this.dim.col-1]),c=document.createElement("div"),this._content({x:r+this.xif.col[2],y:h,n:c}),e.insertBefore(c,e.childNodes[h*this.dim.col+this.xif.col[2]+r-i]);return this.regrid()}},goto:function(t){return o(this.pos,t=null==t?{row:0,col:0}:t),this.render()},render:function(){for(var t,e,i,o,s=0,r=this.dim.row;s<r;++s)for(t=s,e=0,i=this.dim.col;e<i;++e)o=e,this._content({x:o,y:t});return this.renderSelection()},move:function(t){var e,i,o,s;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(s=this.cell(t))){if(e=this.index(s),i=s.getBoundingClientRect(),o=this.dom.sheet.getBoundingClientRect(),i.x+i.width>o.x+o.width&&this._mr(1),i.y+i.height>o.y+o.height&&this._md(1),0===e.x){if(0===this.pos.col)return;this._ml(1)}if(0===e.y){if(0===this.pos.row)return;this._mu(1)}if((s=this.cell(t))||(s=this.cell({col:e.col,row:e.row})))return this.les.node=s,this.les.start=this.les.end={col:(s=this.index(s)).col,row:s.row},this.renderSelection()}},edit:function(t){var e,i,o,s,r,n=t.node,l=t.quick;if(this._editing&&!(!(r=this.index(n))||r.col<0||r.row<0))return(e=this.editing).node=n,e.quick=l,e.on=!0,this.dom.layout.textContent=n.textContent,i=this.dom.layout.getBoundingClientRect(),o=n.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),t=(e=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],r=e[1],(e=this.dom.edit.style).left=o.x-s.x+t-2+"px",e.top=o.y-s.y+r-2+"px",e.width="fit-content",e.height="fit-content",this.dom.edit.classList.toggle("show",!0),(e=this.dom.textarea.style).width=Math.max(i.width,o.width+1)+"px",e.height=Math.max(i.height,o.height+1)+"px",this.dom.textarea.value=n=!l&&n.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(n.length,n.length)},edited:function(t){if(null==t&&(t={}),this.editing.on)return t.cancel||this.set({row:this.les.start.row,col:this.les.start.col,data:this.dom.textarea.value||""}),this.dom.edit.classList.toggle("show",!1),(t=this.editing).node=null,t.on=!1,t},index:function(t){var e=Array.from(this.dom.inner.childNodes).indexOf(t);return e<0?null:{x:t=e%this.dim.col,y:e=(e-t)/this.dim.col,col:t<this.xif.col[1]?-1:t<this.xif.col[2]?t-this.xif.col[1]:t-this.xif.col[1]+this.pos.col,row:e<this.xif.row[1]?-1:e<this.xif.row[2]?e-this.xif.row[1]:e-this.xif.row[1]+this.pos.row}},cell:function(t){var e,i,o,s=(t=null==t?{}:t).roughly;if(null!=t.col){if(t.col<this.frozen.col)e=t.col;else if(t.col-this.pos.col<this.frozen.col){if(!s)return null;e=this.frozen.col}else e=t.col-this.pos.col;if(t.row<this.frozen.row)i=t.row;else if(t.row-this.pos.row<this.frozen.row){if(!s)return null;i=this.frozen.row}else i=t.row-this.pos.row;return i=(o=[e+this.xif.col[1],i+this.xif.row[1]])[1],(e=o[0])<0||i<0||e>=this.dim.col||i>=this.dim.row?null:this.dom.inner.childNodes[i*this.dim.col+e]}if(o=t.node?this.index(t.node):{y:0,x:0})return i=o.y+(t.y||0),e=o.x+(t.x||0),this.dom.inner.childNodes[i*this.dim.col+e]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(t,e){var i,o,s,r,n,l,h,c,d,a,u,f;return null==e&&(e={}),(t=t||this.les).start?(l=(i=this._bound({defined:!1,sel:t})).sc,f=i.ec,h=i.sr,u=i.er,o=this.dom.inner.getBoundingClientRect(),a=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:l,row:h,roughly:!0}),this.cell({col:l,row:u,roughly:!0}),this.cell({col:f,row:h,roughly:!0}),this.cell({col:f,row:u,roughly:!0})].map(function(t){return t?t.getBoundingClientRect():null}))[0],c=i[1],s=i[2],d=i[3],r=i[4],a.width=0,a.height=0,n=(c||s||a).x-o.x,l=(c||d||a).y-o.y,h=f-this.pos.col<0,c=u-this.pos.row<0,d=(d||r||a).x+(h?0:(d||r||a).width)-o.x-n+1,a=(s||r||a).y+(c?0:(s||r||a).height)-o.y-l+1,null==f&&(d=this.root.getBoundingClientRect().width),null==u&&(a=this.root.getBoundingClientRect().height),u=(f=this.cell(t.start))?f.getBoundingClientRect():null,(i=(f=e.cut?this.dom["range-cut"]:this.dom.range).style).left=n+"px",i.top=l+"px",i.width=d+"px",i.height=a+"px",f.classList.toggle("show",!0),e.cut?void 0:(u&&((i=this.dom.caret.style).left=u.x-o.x-1+"px",i.top=u.y-o.y-1+"px",i.width=(h?0:u.width)+2+"px",i.height=(c?0:u.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",!!u))):(this.dom.caret.classList.toggle("show",!1),void this.dom.range.classList.toggle("show",!1))},data:function(t){return null==t?this._data:(this._data=t,this.render())},slice:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,e-s+1)),null==e&&(t=this._data.map(function(t){return t.splice(i,o-i+1)})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.sheet=t)}.call(this);
|
|
1
|
+
!function(){var u,f,n,t;function o(t,e){var i,o={}.hasOwnProperty;for(i in e)o.call(e,i)&&(t[i]=e[i]);return t}u=function(t){return Papa.parse(t).data},f=function(t,e,i){for(var o=t;t&&t!==i;)t=t.parentNode;if(t!==i)return null;if(!e)return t;for(t=o;t&&t!==i&&(!t.matches||t.matches&&!t.matches(e));)t=t.parentNode;return t!==i||i.matches&&i.matches(e)?t:null},n=function(t){for(var e=Math.floor(Math.log(25*(t+1)+1)/Math.log(26))-1,i=t-((Math.pow(26,1+e)-1)/25-1),o="",s=0;s<=e;++s)o="ABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i%26)+o,i=(i-i%26)/26;return o},(t=function(t){var e,i=this;return this.opt=t=null==t?{}:t,this.root="string"==typeof t.root?document.querySelector(t.root):t.root,this.evtHandler={},this._data=t.data||[],this._size={row:(e=o({row:[],col:[]},t.size)).row,col:e.col},this.cls={row:(e=o({row:[],col:[]},t.class)).row,col:e.col},this._editing=null==t.editing||!!t.editing,this.dim={col:(t.dim||(t.dim={})).col||30,row:(t.dim||(t.dim={})).row||30},this.frozen={col:(e=o({col:0,row:0},t.frozen||{})).col,row:e.row},this.idx={col:(e=o({row:!0,col:!0},t.idx||{})).col,row:e.row},this.fixed={col:(e=o({col:0,row:0},t.fixed||{})).col,row:e.row},this.xif={row:[this.idx.row?1:0,0,0],col:[this.idx.col?1:0,0,0]},["row","col"].map(function(t){return i.xif[t][1]=i.xif[t][0]+i.fixed[t],i.xif[t][2]=i.xif[t][1]+i.frozen[t]}),this.fix={row:this.xif.row[2],col:this.xif.col[2]},this.pos={col:0,row:0},this.scrollPos={x:0,y:0},this.sel={cut:{}},this.les={},this.editing={},this.dom=Object.fromEntries(["sheet","inner","caret","range","edit","layout","range-cut"].map(function(t){var e;e=document.createElement("div");return e.classList.add(t),[t,e]})),this.dom.sheet.setAttribute("tabindex",-1),this.dom.textarea=document.createElement("textarea"),this.root.appendChild(this.dom.sheet),["inner","caret","range","edit","layout","range-cut"].map(function(t){return i.dom.sheet.appendChild(i.dom[t])}),this.dom.edit.appendChild(this.dom.textarea),this._init(),this}).prototype=o(Object.create(Object.prototype),{on:function(t,e){var i;return((i=this.evtHandler)[t]||(i[t]=[])).push(e)},fire:function(t){for(var e,i,o,s,n=[],r=[],l=1,h=arguments.length;l<h;++l)r.push(arguments[l]);for(e=r,l=0,o=(i=this.evtHandler[t]||[]).length;l<o;++l)s=i[l],n.push(s.apply(this,e));return n},_init:function(){for(var t,e,i,o,d,a=this,s=0,n=this.dim.row;s<n;++s)for(t=s,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(a.fire("menu.on",{evt:t,node:t.target}),!a._menuOff)return a._menuOff=function(t){if("keydown"!==t.type||27===t.keyCode)return document.body.removeEventListener("click",a._menuOff),document.body.removeEventListener("keydown",a._menuOff),a._menuOff=null,a.fire("menu.off",{evt:t,node:t.target})},document.body.addEventListener("click",a._menuOff),document.body.addEventListener("keydown",a._menuOff)}),(d=this.dom.sheet).addEventListener("mousedown",function(t){var e,i,o;if(!(1<t.button)&&(a.edited(),e=f(t.target,".cell",d)))return(o={row:(i=a.index(e)).row,col:i.col}).col<0||o.row<0?(t.shiftKey&&a.les.start||(a.les.node=a.cell(a.les.start),a.les.start={col:0<(i=o.col)?i:0,row:0<(i=o.row)?i:0}),a.les.end={col:0<=o.col?o.col:void 0,row:0<=o.row?o.row:void 0},void a.renderSelection()):(t.shiftKey&&a.les.start?a.les.end=o:(a.les.start=a.les.end=o,a.les.node=e),a.renderSelection())}),d.addEventListener("mousemove",function(t){var e;if(!a.editing.on&&t.buttons&&(e=f(t.target,".cell",d)))return e={row:(e=a.index(e)).row,col:e.col},a.les.end={col:0<=e.col?e.col:void 0,row:0<=e.row?e.row:void 0},a.renderSelection()}),d.addEventListener("dblclick",function(t){if(t=f(t.target,".cell",d))return a.edit({node:t,quick:!1})}),document.body.addEventListener("paste",function(t){var e,i,o,s,n,r,l,h,c;if(f(document.activeElement,".sheet",d)&&a.les.start&&(s=t.clipboardData.getData("text"),e=u(s),a.set({row:a.les.start.row,col:a.les.start.col,data:e,range:!0}),a.sel.cut)){if(a._toText({sel:a.sel.cut})===s){for(i=(e=a._bound({sel:a.sel.cut})).sc,o=e.ec,s=e.sr,n=e.er,r=s;r<=n;++r)for(l=r,h=i;h<=o;++h)c=h,a.set({row:l,col:c,data:""});navigator.clipboard.writeText("")}return a.sel.cut=null,a.dom["range-cut"].classList.toggle("show",!1)}}),d.addEventListener("keydown",function(t){var e,i,o,s,n,r,l,h,c,d=t.keyCode;if(67===t.keyCode&&(t.metaKey||t.ctrlKey))return a.copy();if(88===t.keyCode&&(t.metaKey||t.ctrlKey))return a.copy({cut:!0});if(a.eventInScope(t)){if(8===d){if(!a.les.node)return;for(e=(c=a._bound()).sc,i=c.ec,o=c.sr,s=c.er,n=[],r=o;r<=s;++r){for(l=[],h=e;h<=i;++h)l.push("");n.push(l)}c=n,a.set({row:o,col:e,data:c,range:!0})}if(189===d&&(t.metaKey||t.ctrlKey)&&a.slice(),(c=function(){switch(d){case 37:return{y:0,x:-1};case 38:return{y:-1,x:0};case 39:return{y:0,x:1};case 40:return{y:1,x:0};default:return null}}())&&(!a.editing.on||a.editing.quick))return a.move(c),t.stopPropagation(),t.preventDefault(),a.dom.sheet.focus()}}),d.addEventListener("keypress",function(t){if(31!==t.keyCode||!t.metaKey&&!t.ctrlKey)return a.les.node&&!a.editing.on?a.edit({node:a.les.node,quick:13!==t.keyCode}):void 0}),this.dom.textarea.addEventListener("keydown",function(t){var e,i,o;return 27===t.keyCode?(a.edited({cancel:!0}),t.stopPropagation(),t.preventDefault(),void a.dom.sheet.focus()):13!==t.keyCode||t.altKey||t.metaKey?13===t.keyCode&&(t.altKey||t.metaKey)?(a.dom.textarea.value+="\n",a.dom.layout.textContent=a.dom.textarea.value+" ",e=a.dom.layout.getBoundingClientRect(),i=a.editing.node.getBoundingClientRect(),(o=a.dom.textarea.style).width=Math.max(e.width,i.width+1)+"px",o.height=Math.max(e.height,i.height+1)+"px",o):void 0:(a.move({y:1,x:0}),t.stopPropagation(),t.preventDefault(),void a.dom.sheet.focus())}),document.addEventListener("wheel",function(t){var e,i,o,s,n=a.eventInScope(t);return(null==a.opt.scrollLock||a.opt.scrollLock)&&Math.abs(t.deltaX)>Math.abs(t.deltaY)&&(!n&&t.target!==document.body||t.preventDefault()),!!n&&(e=a.scrollPos,i=(s=[t.deltaX,t.deltaY])[0],o=s[1],i=(s=Math.abs(i)>Math.abs(o)?[i,0]:[0,o])[0],o=s[1],n=(s=[e.x,e.y])[0],s=s[1],e.x+=i/30,e.y+=o/30,i=Math.round(e.x)-Math.round(n),0<(o=Math.round(e.y)-Math.round(s))?a._md(o):o<0?a._mu(o):0<i?a._mr(i):i<0&&a._ml(i),a.renderSelection(),t.preventDefault())},{passive:!1})},select:function(t){var e,i;if(!arguments.length)return this.les.start?((e={}).col=this.les.start.col,e.row=this.les.start.row,this.les.end?(null==this.les.end.col?delete e.col:e.colspan=this.les.end.col-e.col+1,null==this.les.end.row?delete e.row:e.rowspan=this.les.end.row-e.row+1):(e.colspan=1,e.rowspan=1),e):null;this.les={},t&&(this.les={start:{col:0,row:0},end:{}},null!=t.row&&(this.les.start.row=t.row,this.les.end.row=t.row+((i=t.rowspan)&&1<i?i:1)-1),null!=t.col&&(this.les.start.col=t.col,this.les.end.col=t.col+((i=t.colspan)&&1<i?i:1)-1)),this.renderSelection()},_bound:function(t){var e,i,o,s,n;return e=(n=[(o=(t=null==t?{}:t).sel||this.les).start,o.end])[1],(s=n[0])&&e?(i=(n=s.col<e.col||null==e.col?[s.col,e.col]:[e.col,s.col])[0],o=n[1],s=(n=s.row<e.row||null==e.row?[s.row,e.row]:[e.row,s.row])[0],n=n[1],null!=t.defined&&!t.defined||(null==o&&(o=Math.max.apply(Math,this._data.map(function(t){return t.length}))),null==n&&(n=this._data.length)),{sc:i,ec:o,sr:s,er:n}):{sc:0,ec:0,sr:0,er:0}},_toText:function(t){var e,i,o,s,n,r,l,h,c,d,t=t.sel;if(!t||!t.start)return"";for(e=[],o=(i=this._bound({sel:t})).sc,s=i.ec,t=i.sr,n=i.er,r=t;r<=n;++r){for(l=r,h=[],c=o;c<=s;++c)d=c,"object"!=typeof(d=null==(d=((i=this._data)[l]||(i[l]=[]))[d])?"":d)&&h.push('"'+(""+d||"").replace(/"/g,'""')+'"');e.push(h.join("\t"))}return e.join("\n")},copy:function(t){var e;if(null==t&&(t={}),this.les.start)return e=this._toText({sel:this.les}),navigator.clipboard.writeText(e),t.cut?(this.sel.cut={start:this.les.start,end:this.les.end},this.renderSelection(this.sel.cut,{cut:!0})):void 0},eventInScope:function(t){return f(t.target,".sheet",this.dom.sheet)===this.dom.sheet},size:function(t){return null==t?this._size:(this._size={row:(t=o({row:[],col:[]},t)).row,col:t.col},this.regrid())},regrid:function(){var e=this;return this.dom.inner.style.gridTemplateColumns="repeat("+this.xif.col[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.col[2],i=this.dim.col;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.col[t+e.pos.col-e.xif.col[1]]||"max-content"}).join(" "),this.dom.inner.style.gridTemplateRows="repeat("+this.xif.row[1]+", max-content) "+function(){for(var t=[],e=0,i=this.frozen.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t]||"max-content"}).join(" ")+" "+function(){for(var t=[],e=this.xif.row[2],i=this.dim.row;e<i;++e)t.push(e);return t}.call(this).map(function(t){return e._size.row[t+e.pos.row-e.xif.row[1]]||"max-content"}).join(" ")},addCell:function(t,e){var i=document.createElement("div");return this.dom.inner.insertBefore(i,this.dom.inner.childNodes[e*this.dim.col+t]),this._content({x:t,y:e,n:i})},set:function(t){var e,i,o,s,n,r,l,h,c=t.row,d=t.col,a=t.data,t=t.range;if(t)for(i=0,o=a.length;i<o;++i)for(n=0,r=a[s=i].length;n<r;++n)l=n,((e=this._data)[h=s+c]||(e[h]=[]))[l+d]=a[s][l],this._content({y:s+c-this.pos.row+this.xif.row[1],x:l+d-this.pos.col+this.xif.col[1]});else((e=this._data)[c]||(e[c]=[]))[d]=a,this._content({y:c-this.pos.row+this.xif.row[1],x:d-this.pos.col+this.xif.col[1]});return this.fire("change",{row:c,col:d,data:a,range:!!t})},_content:function(t){var e,i,o=t.x,s=t.y,t=t.n;if(t=t||this.dom.inner.childNodes[o+s*this.dim.col])return e=(i=o<this.xif.col[0]&&s<this.xif.col[0]?["","cell idx"]:o<this.xif.col[0]?[s<this.xif.row[1]?" ":s<this.xif.row[2]?s-this.xif.row[1]+1:s-this.xif.row[1]+this.pos.row+1,"cell idx"]:s<this.xif.row[0]?[o<this.xif.col[1]?" ":o<this.xif.col[2]?n(o-this.xif.col[1]):n(o-this.xif.col[1]+this.pos.col),"cell idx"]:o<this.xif.col[1]||s<this.xif.row[1]?[null,"cell fixed"]:o<this.xif.col[2]&&s<this.xif.row[2]?[((i=this._data)[e=s-this.xif.row[1]]||(i[e]=[]))[o-this.xif.col[1]],"cell frozen fixed"]:o<this.xif.col[2]?[((i=this._data)[e=this.pos.row+s-this.xif.row[1]]||(i[e]=[]))[o-this.xif.col[1]],"cell frozen"]:s<this.xif.row[2]?[((i=this._data)[e=s-this.xif.row[1]]||(i[e]=[]))[this.pos.col+o-this.xif.col[1]],"cell frozen"]:[((i=this._data)[e=this.pos.row+s-this.xif.row[1]]||(i[e]=[]))[this.pos.col+o-this.xif.col[1]],"cell"])[0],i=i[1],null==e&&(e=""),s=o>=this.xif.col[0]&&s>=this.xif.row[0]?(this.cls.col[this.pos.col+o-this.xif.col[1]]||"")+" "+(this.cls.row[this.pos.row+s-this.xif.row[1]]||""):"",t.className=(i+" "+s).trim(),null!==e?"object"!=typeof e?t.textContent=e:"dom"===e.type?(t.textContent="",t.appendChild(e.node)):void 0:void 0},_md:function(t){var e,i,o,s,n,r,l,h,c;for(null==t&&(t=1),e=this.dom.inner,o=i=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.row-this.fix.row))?i:0;o<t;++o)for(s=o,n=0,r=this.dim.col;n<r&&(l=n,h=this.dim.col*this.fix.row,e.childNodes[h]);++n)e.removeChild(e.childNodes[h]);for(o=i;o<t;++o)for(s=o,n=0,r=this.dim.col;n<r;++n)l=n,c=document.createElement("div"),this._content({x:l,y:this.dim.row+s,n:c}),e.appendChild(c);return this.pos.row+=t},_mu:function(t){var e,i,o,s,n,r,l,h,c,d,a=[];if(null==t&&(t=1),e=this.dom.inner,!(this.pos.row<=0)){for(s=i=0<(o=(t=(t=Math.round(Math.abs(t)))>=this.pos.row?this.pos.row:t)-(this.dim.row-this.xif.row[2]))?o:0;s<t;++s)for(n=s,r=0,l=this.dim.col;r<l&&(h=r,e.childNodes.length);++r)e.removeChild(e.childNodes[e.childNodes.length-1]);for(this.pos.row-=t,s=i;s<t;++s){for(n=s,c=[],r=0,l=this.dim.col;r<l;++r)h=r,d=document.createElement("div"),this._content({x:h,y:n+this.xif.row[2],n:d}),c.push(e.insertBefore(d,e.childNodes[h+(n-i)*this.dim.col+this.dim.col*this.xif.row[2]]));a.push(c)}return a}},_mr:function(t){var e,i,o,s,n,r,l,h;for(null==t&&(t=1),e=this.dom.inner,o=0<(i=(t=Math.round(Math.abs(t)))-(this.dim.col-this.fix.col))?i:0;o<t;++o)for(s=o,n=0,r=this.dim.row;n<r;++n)l=n,e.removeChild(e.childNodes[l*this.dim.col+this.fix.col]),h=document.createElement("div"),this._content({x:this.dim.col+s,y:l,n:h}),e.insertBefore(h,e.childNodes[(l+1)*this.dim.col-1]);return this.pos.col+=t,this.regrid()},_ml:function(t){var e,i,o,s,n,r,l,h,c;if(null==t&&(t=1),e=this.dom.inner,(t=Math.round(Math.abs(t)))>=this.pos.col&&(t=this.pos.col),!(this.pos.col<=0||t<=0)){for(i=0<(o=t-(this.dim.col-this.xif.col[2]))?o:0,this.pos.col-=t,s=i;s<t;++s)for(n=s,r=0,l=this.dim.row;r<l;++r)h=r,e.removeChild(e.childNodes[(h+1)*this.dim.col-1]),c=document.createElement("div"),this._content({x:n+this.xif.col[2],y:h,n:c}),e.insertBefore(c,e.childNodes[h*this.dim.col+this.xif.col[2]+n-i]);return this.regrid()}},goto:function(t){return o(this.pos,t=null==t?{row:0,col:0}:t),this.render()},render:function(){for(var t,e,i,o,s=0,n=this.dim.row;s<n;++s)for(t=s,e=0,i=this.dim.col;e<i;++e)o=e,this._content({x:o,y:t});return this.renderSelection()},move:function(t){var e,i,o,s;if(null==t&&(t={}),this.editing.on&&this.edited(),(t.node=this.les.node)&&(s=this.cell(t))){if(e=this.index(s),i=s.getBoundingClientRect(),o=this.dom.sheet.getBoundingClientRect(),i.x+i.width>o.x+o.width&&this._mr(1),i.y+i.height>o.y+o.height&&this._md(1),0===e.x){if(0===this.pos.col)return;this._ml(1)}if(0===e.y){if(0===this.pos.row)return;this._mu(1)}if((s=this.cell(t))||(s=this.cell({col:e.col,row:e.row})))return this.les.node=s,this.les.start=this.les.end={col:(s=this.index(s)).col,row:s.row},this.renderSelection()}},edit:function(t){var e,i,o,s,n,r=t.node,l=t.quick;if(this._editing&&!(!(n=this.index(r))||n.col<0||n.row<0))return(e=this.editing).node=r,e.quick=l,e.on=!0,this.dom.layout.textContent=r.textContent,i=this.dom.layout.getBoundingClientRect(),o=r.getBoundingClientRect(),s=this.dom.sheet.getBoundingClientRect(),t=(e=[this.dom.sheet.scrollLeft,this.dom.sheet.scrollTop])[0],n=e[1],(e=this.dom.edit.style).left=o.x-s.x+t-2+"px",e.top=o.y-s.y+n-2+"px",e.width="fit-content",e.height="fit-content",this.dom.edit.classList.toggle("show",!0),(e=this.dom.textarea.style).width=Math.max(i.width,o.width+1)+"px",e.height=Math.max(i.height,o.height+1)+"px",this.dom.textarea.value=r=!l&&r.textContent||"",this.dom.textarea.focus(),this.dom.textarea.setSelectionRange(r.length,r.length)},edited:function(t){if(null==t&&(t={}),this.editing.on)return t.cancel||this.set({row:this.les.start.row,col:this.les.start.col,data:this.dom.textarea.value||""}),this.dom.edit.classList.toggle("show",!1),(t=this.editing).node=null,t.on=!1,t},index:function(t){var e=Array.from(this.dom.inner.childNodes).indexOf(t);return e<0?null:{x:t=e%this.dim.col,y:e=(e-t)/this.dim.col,col:t<this.xif.col[1]?-1:t<this.xif.col[2]?t-this.xif.col[1]:t-this.xif.col[1]+this.pos.col,row:e<this.xif.row[1]?-1:e<this.xif.row[2]?e-this.xif.row[1]:e-this.xif.row[1]+this.pos.row}},cell:function(t){var e,i,o,s=(t=null==t?{}:t).roughly;if(null!=t.col){if(t.col<this.frozen.col)e=t.col;else if(t.col-this.pos.col<this.frozen.col){if(!s)return null;e=this.frozen.col}else e=t.col-this.pos.col;if(t.row<this.frozen.row)i=t.row;else if(t.row-this.pos.row<this.frozen.row){if(!s)return null;i=this.frozen.row}else i=t.row-this.pos.row;return i=(o=[e+this.xif.col[1],i+this.xif.row[1]])[1],(e=o[0])<0||i<0||e>=this.dim.col||i>=this.dim.row?null:this.dom.inner.childNodes[i*this.dim.col+e]}if(o=t.node?this.index(t.node):{y:0,x:0})return i=o.y+(t.y||0),e=o.x+(t.x||0),this.dom.inner.childNodes[i*this.dim.col+e]},editing:function(t){return null==t?this._editing:this._editing=!!t},renderSelection:function(t,e){var i,o,s,n,r,l,h,c,d,a,u,f;return null==e&&(e={}),(t=t||this.les).start?(l=(i=this._bound({defined:!1,sel:t})).sc,f=i.ec,h=i.sr,u=i.er,o=this.dom.inner.getBoundingClientRect(),a=(i=[this.cell({col:this.pos.col+this.frozen.col,row:this.pos.row+this.frozen.row}),this.cell({col:l,row:h,roughly:!0}),this.cell({col:l,row:u,roughly:!0}),this.cell({col:f,row:h,roughly:!0}),this.cell({col:f,row:u,roughly:!0})].map(function(t){return t?t.getBoundingClientRect():null}))[0],c=i[1],s=i[2],d=i[3],n=i[4],a.width=0,a.height=0,r=(c||s||a).x-o.x,l=(c||d||a).y-o.y,h=f-this.pos.col<0,c=u-this.pos.row<0,d=(d||n||a).x+(h?0:(d||n||a).width)-o.x-r+1,a=(s||n||a).y+(c?0:(s||n||a).height)-o.y-l+1,null==f&&(d=this.root.getBoundingClientRect().width),null==u&&(a=this.root.getBoundingClientRect().height),u=(f=this.cell(t.start))?f.getBoundingClientRect():null,(i=(f=e.cut?this.dom["range-cut"]:this.dom.range).style).left=r+"px",i.top=l+"px",i.width=d+"px",i.height=a+"px",f.classList.toggle("show",!0),e.cut?void 0:(u&&((i=this.dom.caret.style).left=u.x-o.x-1+"px",i.top=u.y-o.y-1+"px",i.width=(h?0:u.width)+2+"px",i.height=(c?0:u.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",!!u))):(this.dom.caret.classList.toggle("show",!1),void this.dom.range.classList.toggle("show",!1))},data:function(t){return null==t?this._data:(this._data=t,this.render())},insert:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,0,[])),null==e&&(t=this._data.map(function(t){return t.splice(i,0,"")})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()},slice:function(){var t,e=this._bound({defined:!1}),i=e.sc,o=e.ec,s=e.sr,e=e.er;null==o&&(t=this._data.splice(s,e-s+1)),null==e&&(t=this._data.map(function(t){return t.splice(i,o-i+1)})),this.fire("change",{row:s,col:i,data:t,range:!0}),this.les.end=this.les.start,this.renderSelection(),this.render()}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.sheet=t)}.call(this);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.5.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/sheet","license":"MIT","description":"spreadsheet","version":"0.5.5","style":"index.min.css","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/plotdb/sheet","repository":{"type":"git","url":"https://github.com/plotdb/sheet"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true","deploy":"npx deploy web/static"},"devDependencies":{"@loadingio/debounce.js":"1.0.1","@loadingio/ldquery":"^3.0.4","@plotdb/csscope":"^5.0.2","@plotdb/datadom":"^0.2.0","@plotdb/json0":"^0.0.5","@plotdb/rescope":"^5.0.3","body-parser":"^1.19.0","bootstrap":"^4.5.2","@loadingio/bootstrap.ext":"^0.0.9","bootstrap.native":"^3.0.13","dompurify":"^2.2.6","fedep":"^1.1.7","jsoneditor":"^9.1.1","ldcover":"^3.3.0","ldiconfont":"^0.2.3","ldview":"^1.3.2","livescript":"^1.6.0","proxise":"^1.0.1","sharedb-wrapper":"^1.0.0","stylus":"^0.55.0","@zbryikt/template":"^2.3.45","uglify-js":"^3.13.1","uglifycss":"^0.0.29"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","@loadingio/bootstrap.ext","bootstrap.native","@loadingio/ldquery","@loadingio/debounce.js","dompurify","ldview","ldcover","jsoneditor","ldiconfont","proxise","@plotdb/datadom","@plotdb/csscope","@plotdb/rescope","sharedb-wrapper","@plotdb/json0"]}}
|