itsa-react-table 16.8.3 → 16.10.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.
Files changed (2) hide show
  1. package/lib/component.jsx +72 -6
  2. package/package.json +1 -1
package/lib/component.jsx CHANGED
@@ -339,7 +339,7 @@ class Table extends React.Component {
339
339
  }
340
340
 
341
341
  if (
342
- (editValueBeforeEdit === editValueBeforeBlur && !selectedRange) ||
342
+ (editValueBeforeEdit === editValueBeforeBlur && !selectedRange && !force) ||
343
343
  editValueBeforeBlur === undefined
344
344
  ) {
345
345
  // nothing changed
@@ -419,7 +419,9 @@ class Table extends React.Component {
419
419
  }
420
420
  }
421
421
  }
422
- changed && onChangeCell(cells, editValueBeforeBlur);
422
+ if (changed) {
423
+ onChangeCell(cells, editValueBeforeBlur);
424
+ }
423
425
  }
424
426
  }
425
427
  if (selectedRange) {
@@ -427,6 +429,39 @@ class Table extends React.Component {
427
429
  }
428
430
  }
429
431
 
432
+ /**
433
+ * Returns the current selected range information
434
+ * @method getSelectedRange
435
+ * @return {Object|null} Range object with {x1, y1, x2, y2} or null if no range
436
+ * @since 2.0.0
437
+ */
438
+ getSelectedRange() {
439
+ return this.state.selectedRange;
440
+ }
441
+
442
+ /**
443
+ * Returns the current range start position
444
+ * @method getRangeStart
445
+ * @return {Object|null} Range start with {x, y} or null if no range start
446
+ * @since 2.0.0
447
+ */
448
+ getRangeStart() {
449
+ return this.state.selectedRangeStart;
450
+ }
451
+
452
+ /**
453
+ * Returns complete range information including start and selected range
454
+ * @method getRangeInfo
455
+ * @return {Object} Object with {rangeStart, selectedRange}
456
+ * @since 2.0.0
457
+ */
458
+ getRangeInfo() {
459
+ return {
460
+ rangeStart: this.state.selectedRangeStart,
461
+ selectedRange: this.state.selectedRange
462
+ };
463
+ }
464
+
430
465
  focus() {
431
466
  let editableCol, columns, hasColumns, item, editValue, editableCols;
432
467
  const instance = this,
@@ -1026,6 +1061,7 @@ class Table extends React.Component {
1026
1061
  const instance = this,
1027
1062
  props = instance.props,
1028
1063
  state = instance.state,
1064
+ editableBlurCols = props.editableBlurCols,
1029
1065
  keyCode = e.keyCode,
1030
1066
  shiftKey = e.shiftKey,
1031
1067
  ctrlKey = e.metaKey || e.ctrlKey,
@@ -1041,6 +1077,16 @@ class Table extends React.Component {
1041
1077
  columns = props.columns,
1042
1078
  hasColumns = columns && columns.length > 0;
1043
1079
 
1080
+ let preventDomFocus = false;
1081
+ if (typeof editableBlurCols !== "undefined") {
1082
+ if (typeof editableBlurCols === "number") {
1083
+ preventDomFocus = editableBlurCols === state.editableCol;
1084
+ }
1085
+ if (Array.isArray(editableBlurCols)) {
1086
+ preventDomFocus = editableBlurCols.includes(state.editableCol);
1087
+ }
1088
+ }
1089
+
1044
1090
  const implementChanges = (keepFocus) => {
1045
1091
  if (props.editable === true || state.selectedRange) {
1046
1092
  // NOT 'full' for that would take care of itself
@@ -1211,7 +1257,22 @@ class Table extends React.Component {
1211
1257
  },
1212
1258
  selectedRange: null,
1213
1259
  });
1214
- instance._focusActiveCell();
1260
+ if (preventDomFocus) {
1261
+ instance.setState(
1262
+ (prevState) => {
1263
+ return {
1264
+ // editValue: instance._editValueBeforeEdit,
1265
+ editableRow: null,
1266
+ editableCol: null,
1267
+ };
1268
+ },
1269
+ () => {
1270
+ instance._blurActiveCell();
1271
+ }
1272
+ );
1273
+ } else {
1274
+ instance._focusActiveCell();
1275
+ }
1215
1276
  implementChanges();
1216
1277
  }
1217
1278
  }
@@ -1235,10 +1296,14 @@ class Table extends React.Component {
1235
1296
  prevRowId,
1236
1297
  prevColId,
1237
1298
  selectedRangeStart;
1238
- node.tagName === "TD" || (node = node.parentNode);
1299
+ while (node && node.tagName !== "TD") {
1300
+ node = node.parentNode;
1301
+ }
1302
+ if (!node) {
1303
+ return;
1304
+ }
1239
1305
  colId = parseInt(node.getAttribute("data-colid"), 10);
1240
- node = node.parentNode;
1241
- rowId = parseInt(node.getAttribute("data-rowid"), 10);
1306
+ rowId = parseInt(node.parentNode.getAttribute("data-rowid"), 10);
1242
1307
  if (typeof editableCols === "number") {
1243
1308
  editableCols = [editableCols];
1244
1309
  }
@@ -1481,6 +1546,7 @@ Table.propTypes = {
1481
1546
  data: PropTypes.array,
1482
1547
  disabled: PropTypes.bool,
1483
1548
  editable: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
1549
+ editableBlurCols: PropTypes.oneOfType([PropTypes.array, PropTypes.number]),
1484
1550
  editableCols: PropTypes.oneOfType([PropTypes.array, PropTypes.number]),
1485
1551
  editDirectionDown: PropTypes.bool,
1486
1552
  extendableX: PropTypes.bool,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itsa-react-table",
3
- "version": "16.8.3",
3
+ "version": "16.10.0",
4
4
  "description": "Editable React.js table",
5
5
  "author": [
6
6
  {