Skip to content

Commit 71eb8e3

Browse files
committed
- simplify opt.cellcfg to _ccfg
- prevent readonly cells to be edited by paste, cut or delete - add `papaparse` in demo page - bump version
1 parent f081b5c commit 71eb8e3

10 files changed

Lines changed: 200 additions & 114 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Logs
22

3+
## v0.6.1
4+
5+
- simplify `opt.cellcfg` to `_ccfg`
6+
- prevent readonly cells to be edited by paste, cut or delete
7+
- add `papaparse` in demo page
8+
9+
310
## v0.6.0
411

512
- optionally disable pasting if `papaparse` is not available (not yet implemented TODO)

dist/index.js

Lines changed: 67 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
? document.querySelector(opt.root)
6868
: opt.root;
6969
this.evtHandler = {};
70+
this._ccfg = opt.cellcfg;
7071
this._data = opt.data || [];
7172
this._size = {
7273
row: (ref$ = import$({
@@ -299,7 +300,8 @@
299300
row: this$.les.start.row,
300301
col: this$.les.start.col,
301302
data: data,
302-
range: true
303+
range: true,
304+
src: 'user'
303305
});
304306
if (this$.sel.cut) {
305307
s = this$._toText({
@@ -316,7 +318,8 @@
316318
this$.set({
317319
row: row,
318320
col: col,
319-
data: ""
321+
data: "",
322+
src: 'user'
320323
});
321324
}
322325
}
@@ -326,9 +329,27 @@
326329
return this$.dom["range-cut"].classList.toggle('show', false);
327330
}
328331
});
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+
});
329347
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;
331349
code = e.keyCode;
350+
if (e.keyCode === 86 && (e.metaKey || e.ctrlKey)) {
351+
return;
352+
}
332353
if (e.keyCode === 67 && (e.metaKey || e.ctrlKey)) {
333354
return this$.copy();
334355
}
@@ -360,7 +381,8 @@
360381
row: sr,
361382
col: sc,
362383
data: data,
363-
range: true
384+
range: true,
385+
src: 'user'
364386
});
365387
}
366388
if (code === 189 && (e.metaKey || e.ctrlKey)) {
@@ -400,38 +422,22 @@
400422
return null;
401423
}
402424
}());
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;
426428
}
429+
this$.move((opt.select = e.shiftKey, opt));
430+
e.stopPropagation();
431+
e.preventDefault();
432+
this$.dom.textarea.focus();
427433
}
428-
});
429-
this.dom.textarea.addEventListener('keydown', function(e){
430-
var ref$, lbox, box;
431434
if (this$.les.node && !this$.editing.on) {
432435
if ((ref$ = e.keyCode) === 37 || ref$ === 38 || ref$ === 39 || ref$ === 40 || ref$ === 9 || ref$ === 16 || ref$ === 18 || ref$ === 91 || ref$ === 27) {
433436
return;
434437
}
438+
if (((ref$ = e.keyCode) === 31 || ref$ === 61 || ref$ === 67 || ref$ === 88) && (e.metaKey || e.ctrlKey)) {
439+
return;
440+
}
435441
this$.edit({
436442
node: this$.les.node,
437443
quick: e.keyCode === 13 ? false : true
@@ -757,19 +763,37 @@
757763
});
758764
},
759765
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;
762768
if (!range) {
769+
if (src && this._ccfg({
770+
row: row,
771+
col: col,
772+
type: 'readonly'
773+
})) {
774+
return;
775+
}
763776
((ref$ = this._data)[row] || (ref$[row] = []))[col] = data;
764777
this._content({
765778
y: row - this.pos.row + this.xif.row[1],
766779
x: col - this.pos.col + this.xif.col[1]
767780
});
768781
} else {
782+
touched = false;
783+
data = JSON.parse(JSON.stringify(data));
769784
for (i$ = 0, to$ = data.length; i$ < to$; ++i$) {
770785
r = i$;
771786
for (j$ = 0, to1$ = data[r].length; j$ < to1$; ++j$) {
772787
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;
773797
((ref$ = this._data)[key$ = r + row] || (ref$[key$] = []))[c + col] = data[r][c];
774798
this._content({
775799
y: r + row - this.pos.row + this.xif.row[1],
@@ -778,12 +802,14 @@
778802
}
779803
}
780804
}
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+
}
787813
},
788814
_content: function(arg$){
789815
var x, y, n, v, ref$, key$, content, className, fr, clsext, clsopt;
@@ -825,9 +851,9 @@
825851
: this.pos.col) + x - this.xif.col[1]] || '') + ' ' + (this.cls.row[(fr
826852
? 0
827853
: this.pos.row) + y - this.xif.row[1]] || '') : '';
828-
clsopt = !this.opt.cellcfg
854+
clsopt = !this._ccfg
829855
? ''
830-
: this.opt.cellcfg({
856+
: this._ccfg({
831857
type: 'class',
832858
col: (fr
833859
? 0
@@ -1081,7 +1107,7 @@
10811107
return;
10821108
}
10831109
idx = this.index(node);
1084-
if (this.opt.cellcfg && this.opt.cellcfg({
1110+
if (this._ccfg && this._ccfg({
10851111
row: idx.row,
10861112
col: idx.col,
10871113
type: 'readonly'

dist/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "@plotdb/sheet",
44
"license": "MIT",
55
"description": "spreadsheet",
6-
"version": "0.6.0",
6+
"version": "0.6.1",
77
"style": "dist/index.min.css",
88
"browser": "dist/index.min.js",
99
"main": "dist/index.min.js",
@@ -24,15 +24,16 @@
2424
"deploy": "npx deploy web/static"
2525
},
2626
"devDependencies": {
27+
"@loadingio/bootstrap.ext": "^0.0.9",
2728
"@loadingio/debounce.js": "1.0.1",
2829
"@loadingio/ldquery": "^3.0.4",
2930
"@plotdb/csscope": "^5.0.2",
3031
"@plotdb/datadom": "^0.2.0",
3132
"@plotdb/json0": "^0.0.5",
3233
"@plotdb/rescope": "^5.0.3",
34+
"@zbryikt/template": "^2.3.45",
3335
"body-parser": "^1.19.0",
3436
"bootstrap": "^4.5.2",
35-
"@loadingio/bootstrap.ext": "^0.0.9",
3637
"bootstrap.native": "^3.0.13",
3738
"dompurify": "^2.2.6",
3839
"fedep": "^1.1.7",
@@ -41,10 +42,10 @@
4142
"ldiconfont": "^0.2.3",
4243
"ldview": "^1.3.2",
4344
"livescript": "^1.6.0",
45+
"papaparse": "^5.4.1",
4446
"proxise": "^1.0.1",
4547
"sharedb-wrapper": "^1.0.0",
4648
"stylus": "^0.55.0",
47-
"@zbryikt/template": "^2.3.45",
4849
"uglify-js": "^3.13.1",
4950
"uglifycss": "^0.0.29"
5051
},
@@ -62,6 +63,7 @@
6263
"jsoneditor",
6364
"ldiconfont",
6465
"proxise",
66+
"papaparse",
6567
"@plotdb/datadom",
6668
"@plotdb/csscope",
6769
"@plotdb/rescope",

0 commit comments

Comments
 (0)