@clake/react-bootstrap4-window 0.6.2 → 0.7.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/lib/CTable.js CHANGED
@@ -1,6 +1,6 @@
1
- /* @clake/react-bootstrap4-window v0.6.2 | by Clake
2
- * Copyright (c) 2023 Clake,
3
- * 2023-06-15T17:08:03+0800
1
+ /* @clake/react-bootstrap4-window v0.7.0 | by Clake
2
+ * Copyright (c) 2024 Clake,
3
+ * 2024-03-08T17:34:46+0800
4
4
  */
5
5
  "use strict";
6
6
 
@@ -37,6 +37,14 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
37
37
 
38
38
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
39
39
 
40
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
41
+
42
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
43
+
44
+ function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
45
+
46
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
47
+
40
48
  function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
41
49
 
42
50
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -81,6 +89,27 @@ function (_React$Component) {
81
89
  });
82
90
  });
83
91
 
92
+ _defineProperty(_assertThisInitialized(_this), "selectAll", function (checked) {
93
+ _this.select_all = checked; // Common.map(this.refs, (item,key,idx) => {
94
+ // item.setChecked(this.select_all);
95
+ // this.setRowCheck(this.select_all,idx);
96
+ // });
97
+
98
+ var selectRows = [];
99
+
100
+ if (checked) {
101
+ _this.state.data.forEach(function (item, key) {
102
+ selectRows.push(key);
103
+ });
104
+ }
105
+
106
+ _this.setState({
107
+ selectRows: selectRows,
108
+ selectAll: checked,
109
+ selectHalf: false
110
+ });
111
+ });
112
+
84
113
  _defineProperty(_assertThisInitialized(_this), "sortHandler", function (e) {
85
114
  var dom = e.currentTarget;
86
115
  var sort_type = dom.dataset.sort || 'asc';
@@ -182,16 +211,6 @@ function (_React$Component) {
182
211
  }
183
212
  });
184
213
 
185
- _defineProperty(_assertThisInitialized(_this), "selectAll", function (checked) {
186
- _this.select_all = checked;
187
-
188
- _reactBootstrap.Common.map(_this.refs, function (item, key, idx) {
189
- item.setChecked(_this.select_all);
190
-
191
- _this.setRowCheck(_this.select_all, idx);
192
- });
193
- });
194
-
195
214
  _this.state = {
196
215
  data: _this.props.data || [],
197
216
  dataCount: _this.props.dataCount,
@@ -202,7 +221,10 @@ function (_React$Component) {
202
221
  start: '',
203
222
  end: '',
204
223
  contain: ''
205
- }
224
+ },
225
+ selectAll: false,
226
+ selectHalf: false,
227
+ selectRows: []
206
228
  };
207
229
  _this.originalData = _this.state.data.slice(0);
208
230
  _this.domId = 'table-' + _reactBootstrap.Common.RandomString(16);
@@ -245,15 +267,14 @@ function (_React$Component) {
245
267
 
246
268
  this.editRows = [];
247
269
  this.originalData = _reactBootstrap.Common.Clone(nextProps.data);
248
- }
270
+ } // if (this.allchk) {
271
+ // this.allchk.setHalf(false);
272
+ // this.selectRows = [];
273
+ // }
274
+ // this.select_all = false;
275
+ // this.selectRows = [];
249
276
 
250
- if (this.allchk) {
251
- this.allchk.setHalf(false);
252
- this.selectRows = [];
253
- }
254
277
 
255
- this.select_all = false;
256
- this.selectRows = [];
257
278
  this.setState({
258
279
  data: nextProps.data,
259
280
  dataCount: nextProps.dataCount,
@@ -265,6 +286,10 @@ function (_React$Component) {
265
286
  }, {
266
287
  key: "shouldComponentUpdate",
267
288
  value: function shouldComponentUpdate(nextProps, nextState) {
289
+ if (nextState.selectRows !== this.state.selectRows) {
290
+ return true;
291
+ }
292
+
268
293
  if (this.state.filter !== nextState.filter) {
269
294
  return true;
270
295
  }
@@ -377,56 +402,63 @@ function (_React$Component) {
377
402
  var _this5 = this;
378
403
 
379
404
  return function (checked, e) {
380
- _this5.setRowCheck(checked, i);
405
+ var selectRows = _this5.setRowCheck(checked, i);
406
+
407
+ var _this5$checkAllCheckH = _this5.checkAllCheckHalf(selectRows),
408
+ _this5$checkAllCheckH2 = _slicedToArray(_this5$checkAllCheckH, 2),
409
+ allChecked = _this5$checkAllCheckH2[0],
410
+ half = _this5$checkAllCheckH2[1];
381
411
 
382
- _this5.checkAllCheckHalf();
412
+ _this5.setState({
413
+ selectRows: selectRows,
414
+ selectAll: allChecked,
415
+ selectHalf: half
416
+ });
383
417
 
384
418
  if (typeof _this5.props.onCheck === "function") {
385
- _this5.props.onCheck(e.target.checked, row);
419
+ _this5.props.onCheck(checked, row);
386
420
  }
387
421
  };
388
422
  }
389
423
  }, {
390
424
  key: "checkAllCheckHalf",
391
- value: function checkAllCheckHalf() {
392
- if (this.props.selectOnce) return;
425
+ value: function checkAllCheckHalf(selectRows) {
426
+ if (!this.allchk || this.props.selectOnce) {
427
+ return [false, false];
428
+ }
393
429
 
394
- if (this.selectRows.length > 0 && this.selectRows.length !== this.state.data.length) {
395
- this.allchk.setHalf(true);
430
+ if (selectRows.length > 0 && selectRows.length !== this.state.data.length) {
431
+ return [false, true];
396
432
  }
397
433
 
398
- if (this.selectRows.length === 0) {
399
- this.allchk.setHalf(false);
400
- this.allchk.setChecked(false);
401
- } else if (this.selectRows.length === this.state.data.length) {
402
- this.allchk.setHalf(false);
403
- this.allchk.setChecked(true);
434
+ if (selectRows.length === 0) {
435
+ return [false, false];
436
+ } else if (selectRows.length === this.state.data.length) {
437
+ return [true, false];
404
438
  }
439
+
440
+ return [false, false];
405
441
  }
406
442
  }, {
407
443
  key: "setRowCheck",
408
444
  value: function setRowCheck(checked, rowIdx) {
409
- var row = this.refs['row_' + rowIdx];
445
+ // let row = this.refs['row_'+rowIdx];
446
+ var selectRows = this.props.selectOnce ? [] : this.state.selectRows.slice();
410
447
 
411
448
  if (checked) {
412
- if (this.props.selectOnce && this.selectRows.length > 0) {
413
- var reIdx = this.selectRows[0];
414
- this.refs['row_' + reIdx].setChecked(false);
415
- this.setRowCheck(false, reIdx);
416
- }
449
+ if (selectRows.indexOf(rowIdx) === -1) {
450
+ selectRows.push(rowIdx);
451
+ } // ReactDOM.findDOMNode(row).parentNode.parentNode.classList.add('ck-table-selected');
417
452
 
418
- if (this.selectRows.indexOf(rowIdx) === -1) {
419
- this.selectRows.push(rowIdx);
420
- }
421
-
422
- ReactDOM.findDOMNode(row).parentNode.parentNode.classList.add('ck-table-selected');
423
453
  } else {
424
- if (this.selectRows.indexOf(rowIdx) !== -1) {
425
- this.selectRows.splice(this.selectRows.indexOf(rowIdx), 1);
426
- }
454
+ if (selectRows.indexOf(rowIdx) !== -1) {
455
+ selectRows.splice(this.selectRows.indexOf(rowIdx), 1);
456
+ } // ReactDOM.findDOMNode(row).parentNode.parentNode.classList.remove('ck-table-selected');
427
457
 
428
- ReactDOM.findDOMNode(row).parentNode.parentNode.classList.remove('ck-table-selected');
429
- }
458
+ } // this.setState({selectRows: selectRows});
459
+
460
+
461
+ return selectRows;
430
462
  }
431
463
  }, {
432
464
  key: "clickHandler",
@@ -741,13 +773,13 @@ function (_React$Component) {
741
773
  });
742
774
  } //****************************
743
775
 
744
- }, {
745
- key: "getSelectRows",
746
-
747
776
  /**
748
777
  * 得到所有选中的行
749
778
  * @returns {*}
750
779
  */
780
+
781
+ }, {
782
+ key: "getSelectRows",
751
783
  value: function getSelectRows() {
752
784
  var _this10 = this;
753
785
 
@@ -1039,7 +1071,9 @@ function (_React$Component) {
1039
1071
  ref: function ref(c) {
1040
1072
  return _this15.allchk = c;
1041
1073
  },
1042
- onChange: this.selectAll
1074
+ onChange: this.selectAll,
1075
+ checked: this.state.selectAll,
1076
+ half: this.state.selectHalf
1043
1077
  })) : null, _react["default"].Children.map(this.props.children, function (item, key) {
1044
1078
  _this15.cacheRow[item.props.field] = '';
1045
1079
 
@@ -1116,8 +1150,9 @@ function (_React$Component) {
1116
1150
  value: function renderRow(row, i, parentRow) {
1117
1151
  var _this17 = this;
1118
1152
 
1153
+ var checked = this.state.selectRows.indexOf(i) !== -1;
1119
1154
  return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement("tr", {
1120
- className: this.props.onClick ? 'click-row' : null,
1155
+ className: checked ? 'ck-table-selected' : null,
1121
1156
  onClick: this.clickHandler(row, i)
1122
1157
  }, this.state.select ? _react["default"].createElement("th", {
1123
1158
  style: {
@@ -1126,7 +1161,8 @@ function (_React$Component) {
1126
1161
  }
1127
1162
  }, _react["default"].createElement(_reactBootstrap.CCheckbox, {
1128
1163
  ref: 'row_' + i,
1129
- onChange: this.changeHandler(row, i)
1164
+ onChange: this.changeHandler(row, i),
1165
+ checked: checked
1130
1166
  })) : null, _react["default"].Children.map(this.props.children, function (item, key) {
1131
1167
  if (!item || item.props.hide) {
1132
1168
  return null;
@@ -1310,6 +1346,7 @@ function (_React$Component) {
1310
1346
 
1311
1347
  case "checkbox":
1312
1348
  return _react["default"].createElement(_reactBootstrap.CCheckbox, {
1349
+ className: "d-inline",
1313
1350
  width: "20px",
1314
1351
  onChange: function onChange(chk, e) {
1315
1352
  _this20.editHandler(e, chk, 'chk');
@@ -1317,7 +1354,8 @@ function (_React$Component) {
1317
1354
  "data-row": i,
1318
1355
  "data-field": item.field,
1319
1356
  checked: !!row[item.field],
1320
- disabled: item.disabled
1357
+ disabled: item.disabled,
1358
+ tabIndex: "0"
1321
1359
  });
1322
1360
 
1323
1361
  default:
@@ -1370,7 +1408,7 @@ function (_React$Component) {
1370
1408
  id: "table-total-".concat(this.domId),
1371
1409
  className: this.getClasses(),
1372
1410
  style: this.getTableStyles()
1373
- }, _react["default"].createElement("tbody", null, _react["default"].createElement("tr", null, this.state.select ? _react["default"].createElement("td", {
1411
+ }, _react["default"].createElement("tbody", null, _react["default"].createElement("tr", null, this.state.select || this.props.edit ? _react["default"].createElement("td", {
1374
1412
  width: "20px"
1375
1413
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1376
1414
  icon: "chart-line"