|
67 | 67 | ? document.querySelector(opt.root) |
68 | 68 | : opt.root; |
69 | 69 | this.evtHandler = {}; |
| 70 | + this._ccfg = opt.cellcfg; |
70 | 71 | this._data = opt.data || []; |
71 | 72 | this._size = { |
72 | 73 | row: (ref$ = import$({ |
|
299 | 300 | row: this$.les.start.row, |
300 | 301 | col: this$.les.start.col, |
301 | 302 | data: data, |
302 | | - range: true |
| 303 | + range: true, |
| 304 | + src: 'user' |
303 | 305 | }); |
304 | 306 | if (this$.sel.cut) { |
305 | 307 | s = this$._toText({ |
|
316 | 318 | this$.set({ |
317 | 319 | row: row, |
318 | 320 | col: col, |
319 | | - data: "" |
| 321 | + data: "", |
| 322 | + src: 'user' |
320 | 323 | }); |
321 | 324 | } |
322 | 325 | } |
|
326 | 329 | return this$.dom["range-cut"].classList.toggle('show', false); |
327 | 330 | } |
328 | 331 | }); |
| 332 | + this.dom.textarea.addEventListener('keypress', function(e){ |
| 333 | + var ref$; |
| 334 | + if (((ref$ = e.keyCode) === 31 || ref$ === 61 || ref$ === 67 || ref$ === 88) && (e.metaKey || e.ctrlKey)) { |
| 335 | + return; |
| 336 | + } |
| 337 | + if (this$.les.node && !this$.editing.on) { |
| 338 | + this$.edit({ |
| 339 | + node: this$.les.node, |
| 340 | + quick: e.keyCode === 13 ? false : true |
| 341 | + }); |
| 342 | + if (e.keyCode === 13) { |
| 343 | + return e.preventDefault(); |
| 344 | + } |
| 345 | + } |
| 346 | + }); |
329 | 347 | this.dom.textarea.addEventListener('keydown', function(e){ |
330 | | - var code, ref$, sc, ec, sr, er, data, res$, i$, row, lresult$, j$, col, opt; |
| 348 | + var code, ref$, sc, ec, sr, er, data, res$, i$, row, lresult$, j$, col, opt, lbox, box; |
331 | 349 | code = e.keyCode; |
| 350 | + if (e.keyCode === 86 && (e.metaKey || e.ctrlKey)) { |
| 351 | + return; |
| 352 | + } |
332 | 353 | if (e.keyCode === 67 && (e.metaKey || e.ctrlKey)) { |
333 | 354 | return this$.copy(); |
334 | 355 | } |
|
360 | 381 | row: sr, |
361 | 382 | col: sc, |
362 | 383 | data: data, |
363 | | - range: true |
| 384 | + range: true, |
| 385 | + src: 'user' |
364 | 386 | }); |
365 | 387 | } |
366 | 388 | if (code === 189 && (e.metaKey || e.ctrlKey)) { |
|
400 | 422 | return null; |
401 | 423 | } |
402 | 424 | }()); |
403 | | - if (!opt) { |
404 | | - return; |
405 | | - } |
406 | | - if (this$.editing.on && !this$.editing.quick) { |
407 | | - return; |
408 | | - } |
409 | | - this$.move((opt.select = e.shiftKey, opt)); |
410 | | - e.stopPropagation(); |
411 | | - e.preventDefault(); |
412 | | - return this$.dom.textarea.focus(); |
413 | | - }); |
414 | | - this.dom.textarea.addEventListener('keypress', function(e){ |
415 | | - var ref$; |
416 | | - if (((ref$ = e.keyCode) === 31 || ref$ === 61) && (e.metaKey || e.ctrlKey)) { |
417 | | - return; |
418 | | - } |
419 | | - if (this$.les.node && !this$.editing.on) { |
420 | | - this$.edit({ |
421 | | - node: this$.les.node, |
422 | | - quick: e.keyCode === 13 ? false : true |
423 | | - }); |
424 | | - if (e.keyCode === 13) { |
425 | | - return e.preventDefault(); |
| 425 | + if (opt) { |
| 426 | + if (this$.editing.on && !this$.editing.quick) { |
| 427 | + return; |
426 | 428 | } |
| 429 | + this$.move((opt.select = e.shiftKey, opt)); |
| 430 | + e.stopPropagation(); |
| 431 | + e.preventDefault(); |
| 432 | + this$.dom.textarea.focus(); |
427 | 433 | } |
428 | | - }); |
429 | | - this.dom.textarea.addEventListener('keydown', function(e){ |
430 | | - var ref$, lbox, box; |
431 | 434 | if (this$.les.node && !this$.editing.on) { |
432 | 435 | if ((ref$ = e.keyCode) === 37 || ref$ === 38 || ref$ === 39 || ref$ === 40 || ref$ === 9 || ref$ === 16 || ref$ === 18 || ref$ === 91 || ref$ === 27) { |
433 | 436 | return; |
434 | 437 | } |
| 438 | + if (((ref$ = e.keyCode) === 31 || ref$ === 61 || ref$ === 67 || ref$ === 88) && (e.metaKey || e.ctrlKey)) { |
| 439 | + return; |
| 440 | + } |
435 | 441 | this$.edit({ |
436 | 442 | node: this$.les.node, |
437 | 443 | quick: e.keyCode === 13 ? false : true |
|
757 | 763 | }); |
758 | 764 | }, |
759 | 765 | set: function(arg$){ |
760 | | - var row, col, data, range, ref$, i$, to$, r, j$, to1$, c, key$; |
761 | | - row = arg$.row, col = arg$.col, data = arg$.data, range = arg$.range; |
| 766 | + var row, col, data, range, src, ref$, touched, i$, to$, r, j$, to1$, c, key$; |
| 767 | + row = arg$.row, col = arg$.col, data = arg$.data, range = arg$.range, src = arg$.src; |
762 | 768 | if (!range) { |
| 769 | + if (src && this._ccfg({ |
| 770 | + row: row, |
| 771 | + col: col, |
| 772 | + type: 'readonly' |
| 773 | + })) { |
| 774 | + return; |
| 775 | + } |
763 | 776 | ((ref$ = this._data)[row] || (ref$[row] = []))[col] = data; |
764 | 777 | this._content({ |
765 | 778 | y: row - this.pos.row + this.xif.row[1], |
766 | 779 | x: col - this.pos.col + this.xif.col[1] |
767 | 780 | }); |
768 | 781 | } else { |
| 782 | + touched = false; |
| 783 | + data = JSON.parse(JSON.stringify(data)); |
769 | 784 | for (i$ = 0, to$ = data.length; i$ < to$; ++i$) { |
770 | 785 | r = i$; |
771 | 786 | for (j$ = 0, to1$ = data[r].length; j$ < to1$; ++j$) { |
772 | 787 | c = j$; |
| 788 | + if (src && this._ccfg({ |
| 789 | + row: row + r, |
| 790 | + col: col + c, |
| 791 | + type: 'readonly' |
| 792 | + })) { |
| 793 | + data[r][c] = ((ref$ = this._data)[key$ = r + row] || (ref$[key$] = []))[c + col]; |
| 794 | + continue; |
| 795 | + } |
| 796 | + touched = true; |
773 | 797 | ((ref$ = this._data)[key$ = r + row] || (ref$[key$] = []))[c + col] = data[r][c]; |
774 | 798 | this._content({ |
775 | 799 | y: r + row - this.pos.row + this.xif.row[1], |
|
778 | 802 | } |
779 | 803 | } |
780 | 804 | } |
781 | | - return this.fire('change', { |
782 | | - row: row, |
783 | | - col: col, |
784 | | - data: data, |
785 | | - range: !!range |
786 | | - }); |
| 805 | + if (touched) { |
| 806 | + return this.fire('change', { |
| 807 | + row: row, |
| 808 | + col: col, |
| 809 | + data: data, |
| 810 | + range: !!range |
| 811 | + }); |
| 812 | + } |
787 | 813 | }, |
788 | 814 | _content: function(arg$){ |
789 | 815 | var x, y, n, v, ref$, key$, content, className, fr, clsext, clsopt; |
|
825 | 851 | : this.pos.col) + x - this.xif.col[1]] || '') + ' ' + (this.cls.row[(fr |
826 | 852 | ? 0 |
827 | 853 | : this.pos.row) + y - this.xif.row[1]] || '') : ''; |
828 | | - clsopt = !this.opt.cellcfg |
| 854 | + clsopt = !this._ccfg |
829 | 855 | ? '' |
830 | | - : this.opt.cellcfg({ |
| 856 | + : this._ccfg({ |
831 | 857 | type: 'class', |
832 | 858 | col: (fr |
833 | 859 | ? 0 |
|
1081 | 1107 | return; |
1082 | 1108 | } |
1083 | 1109 | idx = this.index(node); |
1084 | | - if (this.opt.cellcfg && this.opt.cellcfg({ |
| 1110 | + if (this._ccfg && this._ccfg({ |
1085 | 1111 | row: idx.row, |
1086 | 1112 | col: idx.col, |
1087 | 1113 | type: 'readonly' |
|
0 commit comments