@lemon-fe/kits 1.0.0-196 → 1.0.0-197

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.
@@ -625,7 +625,8 @@ var DataGrid = /*#__PURE__*/function (_Component) {
625
625
  }, {
626
626
  key: "componentDidUpdate",
627
627
  value: function componentDidUpdate(prevProps) {
628
- var _prevProps$rowSelecti;
628
+ var _this2 = this,
629
+ _prevProps$rowSelecti;
629
630
 
630
631
  var _this$props4 = this.props,
631
632
  columns = _this$props4.columns,
@@ -633,13 +634,22 @@ var DataGrid = /*#__PURE__*/function (_Component) {
633
634
  dataSource = _this$props4.dataSource,
634
635
  context = _this$props4.context;
635
636
 
637
+ if (!this.ready) {
638
+ console.warn('表格初始化尚未完成,但部分属性发生了变化,请检查属性设置是否合理');
639
+ }
640
+
636
641
  if (columns !== prevProps.columns) {
637
642
  this.syncColRender();
638
- this.updateColumnDefs(this.columnApi.getColumnState());
639
- this.api.refreshCells({
640
- columns: this.fields.map(function (item) {
641
- return item.id;
642
- })
643
+ this.afterReady(function () {
644
+ _this2.updateColumnDefs(_this2.columnApi.getColumnState());
645
+
646
+ if (_this2.fields.length > 0) {
647
+ _this2.api.refreshCells({
648
+ columns: _this2.fields.map(function (item) {
649
+ return item.id;
650
+ })
651
+ });
652
+ }
643
653
  });
644
654
  }
645
655
 
@@ -791,18 +801,18 @@ var DataGrid = /*#__PURE__*/function (_Component) {
791
801
  }, {
792
802
  key: "syncSelection",
793
803
  value: function syncSelection() {
794
- var _this2 = this;
804
+ var _this3 = this;
795
805
 
796
806
  this.afterReady(function () {
797
- var _this2$props$rowSelec = _this2.props.rowSelection;
798
- _this2$props$rowSelec = _this2$props$rowSelec === void 0 ? {} : _this2$props$rowSelec;
799
- var selectedRowKeys = _this2$props$rowSelec.selectedRowKeys;
807
+ var _this3$props$rowSelec = _this3.props.rowSelection;
808
+ _this3$props$rowSelec = _this3$props$rowSelec === void 0 ? {} : _this3$props$rowSelec;
809
+ var selectedRowKeys = _this3$props$rowSelec.selectedRowKeys;
800
810
 
801
- if (selectedRowKeys !== undefined && !_this2.selected.isSameKeys(selectedRowKeys)) {
811
+ if (selectedRowKeys !== undefined && !_this3.selected.isSameKeys(selectedRowKeys)) {
802
812
  var newSelected = new Map();
803
813
 
804
- _this2.selected.forEach(function (id) {
805
- var node = _this2.api.getRowNode(id);
814
+ _this3.selected.forEach(function (id) {
815
+ var node = _this3.api.getRowNode(id);
806
816
 
807
817
  if (node !== undefined) {
808
818
  node.setSelected(false, false, true);
@@ -810,7 +820,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
810
820
  });
811
821
 
812
822
  selectedRowKeys.forEach(function (id) {
813
- var node = _this2.api.getRowNode(id);
823
+ var node = _this3.api.getRowNode(id);
814
824
 
815
825
  var data;
816
826
 
@@ -819,12 +829,12 @@ var DataGrid = /*#__PURE__*/function (_Component) {
819
829
  data = node.data;
820
830
  }
821
831
 
822
- newSelected.set(id, data || _this2.selected.get(id) || null);
832
+ newSelected.set(id, data || _this3.selected.get(id) || null);
823
833
  });
824
834
 
825
- _this2.selected.clone(newSelected);
835
+ _this3.selected.clone(newSelected);
826
836
 
827
- _this2.api.dispatchEvent({
837
+ _this3.api.dispatchEvent({
828
838
  type: 'selectionChanged'
829
839
  });
830
840
  }
@@ -833,7 +843,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
833
843
  }, {
834
844
  key: "syncRowData",
835
845
  value: function syncRowData() {
836
- var _this3 = this;
846
+ var _this4 = this;
837
847
 
838
848
  var dataSource = this.props.dataSource;
839
849
 
@@ -848,8 +858,8 @@ var DataGrid = /*#__PURE__*/function (_Component) {
848
858
  total: dataSource.length,
849
859
  page: newPage
850
860
  }, function () {
851
- if (newPage !== page && _this3.isClientMode()) {
852
- _this3.api.paginationGoToPage(newPage - 1);
861
+ if (newPage !== page && _this4.isClientMode()) {
862
+ _this4.api.paginationGoToPage(newPage - 1);
853
863
  }
854
864
  });
855
865
  }
@@ -857,7 +867,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
857
867
  }, {
858
868
  key: "updateColumnDefs",
859
869
  value: function updateColumnDefs(state) {
860
- var _this4 = this;
870
+ var _this5 = this;
861
871
 
862
872
  var _this$getColumnDefs = this.getColumnDefs(),
863
873
  _this$getColumnDefs2 = _slicedToArray(_this$getColumnDefs, 2),
@@ -865,7 +875,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
865
875
  leafColIds = _this$getColumnDefs2[1];
866
876
 
867
877
  this.afterReady(function () {
868
- _this4.api.setColumnDefs(defs);
878
+ _this5.api.setColumnDefs(defs);
869
879
 
870
880
  if (state) {
871
881
  var newState = _toConsumableArray(state);
@@ -886,7 +896,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
886
896
  }
887
897
  });
888
898
 
889
- _this4.columnApi.applyColumnState({
899
+ _this5.columnApi.applyColumnState({
890
900
  state: newState,
891
901
  applyOrder: true
892
902
  });
@@ -896,7 +906,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
896
906
  }, {
897
907
  key: "getColumnDefs",
898
908
  value: function getColumnDefs() {
899
- var _this5 = this;
909
+ var _this6 = this;
900
910
 
901
911
  var _this$props6 = this.props,
902
912
  _this$props6$columns = _this$props6.columns,
@@ -1135,7 +1145,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1135
1145
  if (DataGrid.isSummaryRow({
1136
1146
  node: node
1137
1147
  }) && field.summaryType === 1) {
1138
- var summary = _this5.getFieldsSummary(_this5.dataSource, _this5.fields);
1148
+ var summary = _this6.getFieldsSummary(_this6.dataSource, _this6.fields);
1139
1149
 
1140
1150
  return get(summary, field.id);
1141
1151
  }
@@ -1238,7 +1248,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1238
1248
  headerClass: prefix('operator-cell'),
1239
1249
  cellRendererParams: {
1240
1250
  render: function render(_, data) {
1241
- var actions = _this5.props.rowActions;
1251
+ var actions = _this6.props.rowActions;
1242
1252
 
1243
1253
  if (actions !== undefined) {
1244
1254
  return /*#__PURE__*/React.createElement(Actions, {
@@ -1295,21 +1305,21 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1295
1305
  }, {
1296
1306
  key: "updateRowData",
1297
1307
  value: function updateRowData() {
1298
- var _this6 = this;
1308
+ var _this7 = this;
1299
1309
 
1300
1310
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1301
1311
  this.afterReady(function () {
1302
- _this6.dataSource = data;
1312
+ _this7.dataSource = data;
1303
1313
 
1304
- _this6.api.setRowData(data);
1314
+ _this7.api.setRowData(data);
1305
1315
 
1306
- if (_this6.isPreserveSelected()) {
1307
- _this6.api.forEachNode(function (node) {
1308
- if (node.id && _this6.selected.has(node.id)) {
1309
- var rowData = _this6.selected.get(node.id);
1316
+ if (_this7.isPreserveSelected()) {
1317
+ _this7.api.forEachNode(function (node) {
1318
+ if (node.id && _this7.selected.has(node.id)) {
1319
+ var rowData = _this7.selected.get(node.id);
1310
1320
 
1311
1321
  if (node.data !== undefined && rowData !== node.data) {
1312
- _this6.selected.set(node.id, node.data);
1322
+ _this7.selected.set(node.id, node.data);
1313
1323
  }
1314
1324
 
1315
1325
  if (!node.isSelected()) {
@@ -1319,20 +1329,20 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1319
1329
  });
1320
1330
  } else {
1321
1331
  var keys = new Map(data.map(function (item) {
1322
- return [_this6.getRowId({
1332
+ return [_this7.getRowId({
1323
1333
  data: item
1324
1334
  }), item];
1325
1335
  }));
1326
1336
 
1327
- _this6.selected.forEach(function (id) {
1337
+ _this7.selected.forEach(function (id) {
1328
1338
  if (!keys.has(id)) {
1329
- _this6.selected.delete(id);
1339
+ _this7.selected.delete(id);
1330
1340
  } else {
1331
- var node = _this6.api.getRowNode(id);
1341
+ var node = _this7.api.getRowNode(id);
1332
1342
 
1333
1343
  if (node !== undefined) {
1334
- if (node.data !== undefined && _this6.selected.get(id) !== node.data) {
1335
- _this6.selected.set(id, node.data);
1344
+ if (node.data !== undefined && _this7.selected.get(id) !== node.data) {
1345
+ _this7.selected.set(id, node.data);
1336
1346
  }
1337
1347
 
1338
1348
  if (!node.isSelected()) {
@@ -1343,8 +1353,8 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1343
1353
  });
1344
1354
  }
1345
1355
 
1346
- if (_this6.selected.isDirty()) {
1347
- _this6.api.dispatchEvent({
1356
+ if (_this7.selected.isDirty()) {
1357
+ _this7.api.dispatchEvent({
1348
1358
  type: 'selectionChanged'
1349
1359
  });
1350
1360
  }
@@ -1378,7 +1388,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1378
1388
  }, {
1379
1389
  key: "getDataFromServer",
1380
1390
  value: function getDataFromServer() {
1381
- var _this7 = this;
1391
+ var _this8 = this;
1382
1392
 
1383
1393
  var _this$props7 = this.props,
1384
1394
  fetch = _this$props7.fetch,
@@ -1389,7 +1399,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1389
1399
  if (onLoading) {
1390
1400
  onLoading(flag);
1391
1401
  } else {
1392
- _this7.setState({
1402
+ _this8.setState({
1393
1403
  loading: flag
1394
1404
  });
1395
1405
  }
@@ -1418,74 +1428,74 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1418
1428
  };
1419
1429
  })
1420
1430
  }).then(function (res) {
1421
- if (id !== _this7.requestId) {
1431
+ if (id !== _this8.requestId) {
1422
1432
  return;
1423
1433
  }
1424
1434
 
1425
1435
  loadingChange(false);
1426
1436
 
1427
1437
  if (res.total !== undefined) {
1428
- _this7.setState({
1438
+ _this8.setState({
1429
1439
  page: page,
1430
1440
  pageSize: pageSize,
1431
1441
  total: res.total
1432
1442
  });
1433
1443
  }
1434
1444
 
1435
- var summary = _this7.props.summary;
1445
+ var summary = _this8.props.summary;
1436
1446
 
1437
- _this7.updateRowData(res.data);
1447
+ _this8.updateRowData(res.data);
1438
1448
 
1439
- _this7.api.setPinnedBottomRowData(_this7.getSummaryRowData(summary, res.summary));
1449
+ _this8.api.setPinnedBottomRowData(_this8.getSummaryRowData(summary, res.summary));
1440
1450
 
1441
1451
  if (res.data.length > 0) {
1442
- _this7.api.ensureIndexVisible(0);
1452
+ _this8.api.ensureIndexVisible(0);
1443
1453
  }
1444
1454
 
1445
1455
  if (onLoad) {
1446
1456
  onLoad(res.extra);
1447
1457
  }
1448
1458
 
1449
- _this7.store.setState({
1459
+ _this8.store.setState({
1450
1460
  fetchError: undefined
1451
1461
  });
1452
1462
  }).catch(function (err) {
1453
- _this7.store.setState({
1463
+ _this8.store.setState({
1454
1464
  fetchError: err
1455
1465
  });
1456
1466
 
1457
1467
  loadingChange(false);
1458
1468
  /** 如果当前是在第一页说明根本没有数据,会误杀其他情况,但不重要 */
1459
1469
 
1460
- _this7.setState(function (prev) {
1470
+ _this8.setState(function (prev) {
1461
1471
  return {
1462
1472
  total: prev.page === 1 ? 0 : prev.total
1463
1473
  };
1464
1474
  });
1465
1475
 
1466
- _this7.updateRowData([]);
1476
+ _this8.updateRowData([]);
1467
1477
 
1468
- _this7.api.setPinnedBottomRowData([]);
1478
+ _this8.api.setPinnedBottomRowData([]);
1469
1479
  });
1470
1480
  }
1471
1481
  }
1472
1482
  }, {
1473
1483
  key: "pagination",
1474
1484
  value: function pagination(page, pageSize) {
1475
- var _this8 = this;
1485
+ var _this9 = this;
1476
1486
 
1477
1487
  this.setState({
1478
1488
  page: page,
1479
1489
  pageSize: pageSize
1480
1490
  }, function () {
1481
- if (_this8.isClientMode()) {
1491
+ if (_this9.isClientMode()) {
1482
1492
  withSyncRender(function () {
1483
- _this8.api.paginationGoToPage(page - 1);
1493
+ _this9.api.paginationGoToPage(page - 1);
1484
1494
 
1485
- _this8.api.paginationSetPageSize(pageSize);
1495
+ _this9.api.paginationSetPageSize(pageSize);
1486
1496
  });
1487
1497
  } else {
1488
- _this8.getDataFromServer();
1498
+ _this9.getDataFromServer();
1489
1499
  }
1490
1500
  });
1491
1501
  }
@@ -1501,7 +1511,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1501
1511
  }, {
1502
1512
  key: "validateRecord",
1503
1513
  value: function validateRecord(record) {
1504
- var _this9 = this;
1514
+ var _this10 = this;
1505
1515
 
1506
1516
  if (this.validator === null) {
1507
1517
  return;
@@ -1511,7 +1521,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1511
1521
  data: record
1512
1522
  });
1513
1523
  return this.validator.validate(record).then(function () {
1514
- var errors = new Map(_this9.store.getState().errors);
1524
+ var errors = new Map(_this10.store.getState().errors);
1515
1525
  var error = errors.get(rowId);
1516
1526
 
1517
1527
  if (error === undefined) {
@@ -1520,12 +1530,12 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1520
1530
 
1521
1531
  errors.delete(rowId);
1522
1532
 
1523
- _this9.store.setState({
1533
+ _this10.store.setState({
1524
1534
  errors: errors
1525
1535
  });
1526
1536
  }).catch(function (_ref3) {
1527
1537
  var fields = _ref3.fields;
1528
- var errors = new Map(_this9.store.getState().errors);
1538
+ var errors = new Map(_this10.store.getState().errors);
1529
1539
  var error = new Map();
1530
1540
  Object.entries(fields).forEach(function (item) {
1531
1541
  error.set(item[0], item[1].map(function (err) {
@@ -1534,7 +1544,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1534
1544
  });
1535
1545
  errors.set(rowId, error);
1536
1546
 
1537
- _this9.store.setState({
1547
+ _this10.store.setState({
1538
1548
  errors: errors
1539
1549
  });
1540
1550
  });
@@ -1543,7 +1553,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1543
1553
  key: "validate",
1544
1554
  value: function () {
1545
1555
  var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
1546
- var _this10 = this;
1556
+ var _this11 = this;
1547
1557
 
1548
1558
  var promises, result, flag, errors, failed;
1549
1559
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
@@ -1558,14 +1568,14 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1558
1568
  return;
1559
1569
  }
1560
1570
 
1561
- var rowId = _this10.getRowId({
1571
+ var rowId = _this11.getRowId({
1562
1572
  data: record
1563
1573
  });
1564
1574
 
1565
- if (_this10.validator === null) {
1575
+ if (_this11.validator === null) {
1566
1576
  promises.push(Promise.resolve(true));
1567
1577
  } else {
1568
- promises.push(_this10.validator.validate(record).catch(function (_ref4) {
1578
+ promises.push(_this11.validator.validate(record).catch(function (_ref4) {
1569
1579
  var fields = _ref4.fields;
1570
1580
  return Promise.reject({
1571
1581
  id: rowId,
@@ -1633,13 +1643,13 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1633
1643
  }, {
1634
1644
  key: "fetch",
1635
1645
  value: function fetch(page) {
1636
- var _this11 = this;
1646
+ var _this12 = this;
1637
1647
 
1638
1648
  var curr = page || 1;
1639
1649
 
1640
1650
  var delay = function delay() {
1641
- if (_this11.isReady) {
1642
- _this11.getDataFromServer();
1651
+ if (_this12.isReady) {
1652
+ _this12.getDataFromServer();
1643
1653
  } else {
1644
1654
  requestAnimationFrame(delay);
1645
1655
  }
@@ -1697,7 +1707,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1697
1707
  }, {
1698
1708
  key: "render",
1699
1709
  value: function render() {
1700
- var _this12 = this,
1710
+ var _this13 = this,
1701
1711
  _classNames;
1702
1712
 
1703
1713
  var _this$props8 = this.props,
@@ -1765,7 +1775,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1765
1775
  current: page,
1766
1776
  total: total,
1767
1777
  onChange: function onChange(curr, limit) {
1768
- _this12.pagination(curr, limit);
1778
+ _this13.pagination(curr, limit);
1769
1779
 
1770
1780
  if (mPage.onChange) {
1771
1781
  mPage.onChange(curr, limit);
@@ -1786,7 +1796,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1786
1796
  return;
1787
1797
  }
1788
1798
 
1789
- _this12.handleBlur();
1799
+ _this13.handleBlur();
1790
1800
  },
1791
1801
  onFocus: this.handleFocus
1792
1802
  }, /*#__PURE__*/React.createElement(AgGridReact, _extends({
@@ -1,5 +1,5 @@
1
1
  import Icon from '@ant-design/icons';
2
2
  import type { ComponentProps } from 'react';
3
3
  export default function Tip(props: {
4
- type?: 'success' | 'error' | 'warning' | 'info';
4
+ type?: 'success' | 'error' | 'warning' | 'info' | 'warn';
5
5
  } & ComponentProps<typeof Icon>): JSX.Element;
@@ -133,6 +133,7 @@ export default function Tip(props) {
133
133
 
134
134
  switch (type) {
135
135
  case 'warning':
136
+ case 'warn':
136
137
  comp = WarningSvg;
137
138
  break;
138
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/kits",
3
- "version": "1.0.0-196",
3
+ "version": "1.0.0-197",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",