@clake/react-bootstrap4-window 0.6.3 → 0.7.1

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.3 | by Clake
2
- * Copyright (c) 2023 Clake,
3
- * 2023-06-16T14:07:02+0800
1
+ /* @clake/react-bootstrap4-window v0.7.1 | by Clake
2
+ * Copyright (c) 2024 Clake,
3
+ * 2024-03-13T11:37:05+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;
@@ -1402,13 +1438,19 @@ function (_React$Component) {
1402
1438
  value: function renderMenu() {
1403
1439
  var _this22 = this;
1404
1440
 
1405
- var lang = this.props.lang;
1441
+ var lang;
1406
1442
 
1407
- if (!lang) {
1443
+ if (!this.props.lang) {
1408
1444
  var i18 = _reactBootstrap.i18n.getLang();
1409
1445
 
1410
1446
  var langStr = typeof lang === 'string' ? lang : i18["short"];
1411
1447
  lang = _CTable2["default"][langStr];
1448
+ } else {
1449
+ if (typeof this.props.lang === 'string') {
1450
+ lang = _CTable2["default"][this.props.lang];
1451
+ } else {
1452
+ lang = this.props.lang;
1453
+ }
1412
1454
  }
1413
1455
 
1414
1456
  return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_reactBootstrap.Menu, {
@@ -1422,7 +1464,7 @@ function (_React$Component) {
1422
1464
  document.execCommand("copy");
1423
1465
  }
1424
1466
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1425
- className: "mr-1",
1467
+ className: "me-1",
1426
1468
  icon: "copy"
1427
1469
  }), lang['Copy']), this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1428
1470
  step: true
@@ -1434,7 +1476,7 @@ function (_React$Component) {
1434
1476
  _this22.filterHandler(select.toString(), data.field, 'contain');
1435
1477
  }
1436
1478
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1437
- className: "mr-1",
1479
+ className: "me-1",
1438
1480
  icon: "filter"
1439
1481
  }), lang['Filter By Selection']) : null, this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1440
1482
  field: "select_exclude",
@@ -1444,7 +1486,7 @@ function (_React$Component) {
1444
1486
  _this22.filterHandler(select.toString(), data.field, 'exclude');
1445
1487
  }
1446
1488
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1447
- className: "mr-1",
1489
+ className: "me-1",
1448
1490
  icon: "filter"
1449
1491
  }), lang['Filter Excluding Selection']) : null, this.is_filter || this.is_sort ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1450
1492
  field: "clear_filter",
@@ -1454,17 +1496,17 @@ function (_React$Component) {
1454
1496
  }, _react["default"].createElement("span", {
1455
1497
  className: "text-danger"
1456
1498
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1457
- className: "mr-1",
1499
+ className: "me-1",
1458
1500
  icon: "brush"
1459
1501
  }), lang['Clear Filter / Sort'])) : null, this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1460
1502
  step: true
1461
1503
  }) : null, this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1462
1504
  field: "equal"
1463
1505
  }, _react["default"].createElement("span", {
1464
- className: "mr-1",
1506
+ className: "me-1",
1465
1507
  style: inputStyle
1466
1508
  }, lang['Equal With']), _react["default"].createElement(_reactBootstrap.Input, {
1467
- className: "mr-1",
1509
+ className: "me-1",
1468
1510
  size: "xs",
1469
1511
  width: "120px",
1470
1512
  data: this.state.filter.equal,
@@ -1483,10 +1525,10 @@ function (_React$Component) {
1483
1525
  })) : null, this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1484
1526
  field: "filter"
1485
1527
  }, _react["default"].createElement("span", {
1486
- className: "mr-1",
1528
+ className: "me-1",
1487
1529
  style: inputStyle
1488
1530
  }, lang['Start With']), _react["default"].createElement(_reactBootstrap.Input, {
1489
- className: "mr-1",
1531
+ className: "me-1",
1490
1532
  size: "xs",
1491
1533
  width: "120px",
1492
1534
  data: this.state.filter.start,
@@ -1505,10 +1547,10 @@ function (_React$Component) {
1505
1547
  })) : null, this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1506
1548
  field: "filter"
1507
1549
  }, _react["default"].createElement("span", {
1508
- className: "mr-1",
1550
+ className: "me-1",
1509
1551
  style: inputStyle
1510
1552
  }, lang['End With']), _react["default"].createElement(_reactBootstrap.Input, {
1511
- className: "mr-1",
1553
+ className: "me-1",
1512
1554
  size: "xs",
1513
1555
  width: "120px",
1514
1556
  data: this.state.filter.end,
@@ -1527,10 +1569,10 @@ function (_React$Component) {
1527
1569
  })) : null, this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1528
1570
  field: "filter"
1529
1571
  }, _react["default"].createElement("span", {
1530
- className: "mr-1",
1572
+ className: "me-1",
1531
1573
  style: inputStyle
1532
1574
  }, lang['Contain with']), _react["default"].createElement(_reactBootstrap.Input, {
1533
- className: "mr-1",
1575
+ className: "me-1",
1534
1576
  size: "xs",
1535
1577
  width: "120px",
1536
1578
  data: this.state.filter.contain,
@@ -1579,13 +1621,19 @@ function (_React$Component) {
1579
1621
  value: function renderNumberMenu() {
1580
1622
  var _this23 = this;
1581
1623
 
1582
- var lang = this.props.lang;
1624
+ var lang;
1583
1625
 
1584
- if (!lang) {
1626
+ if (!this.props.lang) {
1585
1627
  var i18 = _reactBootstrap.i18n.getLang();
1586
1628
 
1587
1629
  var langStr = typeof lang === 'string' ? lang : i18["short"];
1588
1630
  lang = _CTable2["default"][langStr];
1631
+ } else {
1632
+ if (typeof this.props.lang === 'string') {
1633
+ lang = _CTable2["default"][this.props.lang];
1634
+ } else {
1635
+ lang = this.props.lang;
1636
+ }
1589
1637
  }
1590
1638
 
1591
1639
  return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_reactBootstrap.Menu, {
@@ -1599,7 +1647,7 @@ function (_React$Component) {
1599
1647
  document.execCommand("copy");
1600
1648
  }
1601
1649
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1602
- className: "mr-1",
1650
+ className: "me-1",
1603
1651
  icon: "copy"
1604
1652
  }), lang['Copy']), this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1605
1653
  step: true
@@ -1611,7 +1659,7 @@ function (_React$Component) {
1611
1659
  _this23.filterHandler(select.toString(), data.field, 'contain');
1612
1660
  }
1613
1661
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1614
- className: "mr-1",
1662
+ className: "me-1",
1615
1663
  icon: "filter"
1616
1664
  }), lang['Filter By Selection']) : null, this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1617
1665
  field: "select_exclude",
@@ -1621,7 +1669,7 @@ function (_React$Component) {
1621
1669
  _this23.filterHandler(select.toString(), data.field, 'exclude');
1622
1670
  }
1623
1671
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1624
- className: "mr-1",
1672
+ className: "me-1",
1625
1673
  icon: "filter"
1626
1674
  }), lang['Filter Excluding Selection']) : null, this.is_filter || this.is_sort ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1627
1675
  field: "clear_filter",
@@ -1631,7 +1679,7 @@ function (_React$Component) {
1631
1679
  }, _react["default"].createElement("span", {
1632
1680
  className: "text-danger"
1633
1681
  }, _react["default"].createElement(_reactBootstrap.Icon, {
1634
- className: "mr-1",
1682
+ className: "me-1",
1635
1683
  icon: "brush"
1636
1684
  }), lang['Clear Filter / Sort'])) : null, this.is_filter ? _react["default"].createElement(_reactBootstrap.Menu.Item, {
1637
1685
  step: true
@@ -1800,7 +1848,8 @@ CTable.defaultProps = {
1800
1848
  showNumbers: 30,
1801
1849
  showPages: 10,
1802
1850
  source: null,
1803
- total: null
1851
+ total: null,
1852
+ lang: 'en'
1804
1853
  };
1805
1854
  var _default = CTable;
1806
1855
  exports["default"] = _default;