@lemon-fe/kits 1.0.0-192 → 1.0.0-194

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.
@@ -52,7 +52,7 @@ export default class DataGrid<TData extends Record<string, any>> extends Compone
52
52
  Text: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & import("./typings").TextEditorParams<any> & React.RefAttributes<import("@ag-grid-community/react").ICellEditorReactComp>>;
53
53
  Date: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & import("./typings").DateEditorParams<any> & React.RefAttributes<import("@ag-grid-community/react").ICellEditorReactComp>>;
54
54
  Number: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & import("./typings").NumberEditorParams<any> & React.RefAttributes<import("@ag-grid-community/react").ICellEditorReactComp>>;
55
- Select: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & Pick<import("antd").SelectProps<any, import("antd/lib/select").BaseOptionType>, "disabled" | "mode" | "virtual" | "allowClear" | "options" | "showSearch" | "listHeight"> & {
55
+ Select: React.ForwardRefExoticComponent<import("@ag-grid-community/core").ICellEditorParams<any, any, any> & Pick<import("antd").SelectProps<any, import("antd/lib/select").BaseOptionType>, "disabled" | "allowClear" | "mode" | "options" | "virtual" | "showSearch" | "listHeight"> & {
56
56
  fieldNames?: {
57
57
  label: string;
58
58
  value: string;
@@ -79,6 +79,7 @@ export default class DataGrid<TData extends Record<string, any>> extends Compone
79
79
  private syncSelection;
80
80
  private syncRowData;
81
81
  private getFieldsSummary;
82
+ private updateColumnDefs;
82
83
  private getColumnDefs;
83
84
  private isClientMode;
84
85
  private clearReadyQueue;
@@ -495,7 +495,6 @@ var DataGrid = /*#__PURE__*/function (_Component) {
495
495
  });
496
496
 
497
497
  _this.state = _objectSpread({
498
- colDefs: [],
499
498
  loading: false
500
499
  }, _this.getPagination());
501
500
  _this.store = new Store({
@@ -527,9 +526,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
527
526
  this.fields.push(field);
528
527
  }
529
528
 
530
- this.setState({
531
- colDefs: this.getColumnDefs()
532
- });
529
+ this.updateColumnDefs(this.columnApi.getColumnState());
533
530
  }
534
531
  }, {
535
532
  key: "getField",
@@ -547,9 +544,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
547
544
 
548
545
  if (idx >= 0) {
549
546
  this.fields.splice(idx, 1);
550
- this.setState({
551
- colDefs: this.getColumnDefs()
552
- });
547
+ this.updateColumnDefs(this.columnApi.getColumnState());
553
548
  }
554
549
  }
555
550
  }, {
@@ -592,11 +587,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
592
587
  key: "resetFields",
593
588
  value: function resetFields() {
594
589
  this.fields = [];
595
- var columns = this.getColumnDefs();
596
- this.api.setColumnDefs([]);
597
- this.setState({
598
- colDefs: columns
599
- });
590
+ this.updateColumnDefs();
600
591
  }
601
592
  }, {
602
593
  key: "getPagination",
@@ -644,8 +635,11 @@ var DataGrid = /*#__PURE__*/function (_Component) {
644
635
 
645
636
  if (columns !== prevProps.columns) {
646
637
  this.syncColRender();
647
- this.setState({
648
- colDefs: this.getColumnDefs()
638
+ this.updateColumnDefs(this.columnApi.getColumnState());
639
+ this.api.refreshCells({
640
+ columns: this.fields.map(function (item) {
641
+ return item.id;
642
+ })
649
643
  });
650
644
  }
651
645
 
@@ -673,9 +667,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
673
667
  key: "componentDidMount",
674
668
  value: function () {
675
669
  var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
676
- var _this2 = this;
677
-
678
- var _this$props5, customColumnPanelStorage, autoLoad, done, data;
670
+ var _this$props5, customColumnPanelStorage, autoLoad, state, data;
679
671
 
680
672
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
681
673
  while (1) {
@@ -684,13 +676,11 @@ var DataGrid = /*#__PURE__*/function (_Component) {
684
676
  window.addEventListener('blur', this.handleFocus);
685
677
  _this$props5 = this.props, customColumnPanelStorage = _this$props5.customColumnPanelStorage, autoLoad = _this$props5.autoLoad;
686
678
 
687
- done = function done() {
688
- if (_this2.isClientMode()) {
689
- _this2.syncRowData();
690
- } else if (autoLoad) {
691
- _this2.getDataFromServer();
692
- }
693
- };
679
+ if (this.isClientMode()) {
680
+ this.syncRowData();
681
+ } else if (autoLoad) {
682
+ this.getDataFromServer();
683
+ }
694
684
 
695
685
  if (!customColumnPanelStorage) {
696
686
  _context3.next = 19;
@@ -709,46 +699,34 @@ var DataGrid = /*#__PURE__*/function (_Component) {
709
699
 
710
700
  if (data) {
711
701
  this.fields = data.fields;
712
- this.afterReady(function () {
713
- _this2.columnApi.applyColumnState({
714
- state: data.columState,
715
- applyOrder: true
716
- });
717
-
718
- done();
719
- });
702
+ state = data.columState;
720
703
  }
721
704
 
722
- this.setState({
723
- colDefs: this.getColumnDefs()
724
- });
725
- _context3.next = 16;
705
+ _context3.next = 15;
726
706
  break;
727
707
 
728
- case 13:
729
- _context3.prev = 13;
708
+ case 12:
709
+ _context3.prev = 12;
730
710
  _context3.t0 = _context3["catch"](5);
731
711
  console.log('获取列定制失败', _context3.t0.message);
732
712
 
733
- case 16:
713
+ case 15:
714
+ this.updateColumnDefs(state);
734
715
  this.setState({
735
716
  loading: false
736
717
  });
737
- _context3.next = 21;
718
+ _context3.next = 20;
738
719
  break;
739
720
 
740
721
  case 19:
741
- this.setState({
742
- colDefs: this.getColumnDefs()
743
- });
744
- done();
722
+ this.updateColumnDefs();
745
723
 
746
- case 21:
724
+ case 20:
747
725
  case "end":
748
726
  return _context3.stop();
749
727
  }
750
728
  }
751
- }, _callee3, this, [[5, 13]]);
729
+ }, _callee3, this, [[5, 12]]);
752
730
  }));
753
731
 
754
732
  function componentDidMount() {
@@ -813,18 +791,18 @@ var DataGrid = /*#__PURE__*/function (_Component) {
813
791
  }, {
814
792
  key: "syncSelection",
815
793
  value: function syncSelection() {
816
- var _this3 = this;
794
+ var _this2 = this;
817
795
 
818
796
  this.afterReady(function () {
819
- var _this3$props$rowSelec = _this3.props.rowSelection;
820
- _this3$props$rowSelec = _this3$props$rowSelec === void 0 ? {} : _this3$props$rowSelec;
821
- var selectedRowKeys = _this3$props$rowSelec.selectedRowKeys;
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;
822
800
 
823
- if (selectedRowKeys !== undefined && !_this3.selected.isSameKeys(selectedRowKeys)) {
801
+ if (selectedRowKeys !== undefined && !_this2.selected.isSameKeys(selectedRowKeys)) {
824
802
  var newSelected = new Map();
825
803
 
826
- _this3.selected.forEach(function (id) {
827
- var node = _this3.api.getRowNode(id);
804
+ _this2.selected.forEach(function (id) {
805
+ var node = _this2.api.getRowNode(id);
828
806
 
829
807
  if (node !== undefined) {
830
808
  node.setSelected(false, false, true);
@@ -832,7 +810,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
832
810
  });
833
811
 
834
812
  selectedRowKeys.forEach(function (id) {
835
- var node = _this3.api.getRowNode(id);
813
+ var node = _this2.api.getRowNode(id);
836
814
 
837
815
  var data;
838
816
 
@@ -841,12 +819,12 @@ var DataGrid = /*#__PURE__*/function (_Component) {
841
819
  data = node.data;
842
820
  }
843
821
 
844
- newSelected.set(id, data || _this3.selected.get(id) || null);
822
+ newSelected.set(id, data || _this2.selected.get(id) || null);
845
823
  });
846
824
 
847
- _this3.selected.clone(newSelected);
825
+ _this2.selected.clone(newSelected);
848
826
 
849
- _this3.api.dispatchEvent({
827
+ _this2.api.dispatchEvent({
850
828
  type: 'selectionChanged'
851
829
  });
852
830
  }
@@ -855,7 +833,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
855
833
  }, {
856
834
  key: "syncRowData",
857
835
  value: function syncRowData() {
858
- var _this4 = this;
836
+ var _this3 = this;
859
837
 
860
838
  var dataSource = this.props.dataSource;
861
839
 
@@ -870,12 +848,51 @@ var DataGrid = /*#__PURE__*/function (_Component) {
870
848
  total: dataSource.length,
871
849
  page: newPage
872
850
  }, function () {
873
- if (newPage !== page && _this4.isClientMode()) {
874
- _this4.api.paginationGoToPage(newPage - 1);
851
+ if (newPage !== page && _this3.isClientMode()) {
852
+ _this3.api.paginationGoToPage(newPage - 1);
875
853
  }
876
854
  });
877
855
  }
878
856
  }
857
+ }, {
858
+ key: "updateColumnDefs",
859
+ value: function updateColumnDefs(state) {
860
+ var _this4 = this;
861
+
862
+ var _this$getColumnDefs = this.getColumnDefs(),
863
+ _this$getColumnDefs2 = _slicedToArray(_this$getColumnDefs, 2),
864
+ defs = _this$getColumnDefs2[0],
865
+ leafColIds = _this$getColumnDefs2[1];
866
+
867
+ this.afterReady(function () {
868
+ _this4.api.setColumnDefs(defs);
869
+
870
+ if (state) {
871
+ var newState = _toConsumableArray(state);
872
+
873
+ leafColIds.forEach(function (colId, index) {
874
+ if (!colId) {
875
+ return;
876
+ }
877
+
878
+ var idx = state.findIndex(function (item) {
879
+ return item.colId === colId;
880
+ });
881
+
882
+ if (idx < 0) {
883
+ newState.splice(index, 0, {
884
+ colId: colId
885
+ });
886
+ }
887
+ });
888
+
889
+ _this4.columnApi.applyColumnState({
890
+ state: newState,
891
+ applyOrder: true
892
+ });
893
+ }
894
+ });
895
+ }
879
896
  }, {
880
897
  key: "getColumnDefs",
881
898
  value: function getColumnDefs() {
@@ -888,6 +905,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
888
905
  rowSelection = _this$props6.rowSelection,
889
906
  columnTypesProp = _this$props6.columnTypes;
890
907
  var colTypes = this.getMemoizedColumnTypes(columnTypesProp);
908
+ var leafColIds = [];
891
909
 
892
910
  var map = function map(cols) {
893
911
  return cols.map(function (item) {
@@ -930,6 +948,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
930
948
  }
931
949
  }
932
950
 
951
+ leafColIds.push(colId);
933
952
  var _opts = {
934
953
  cellClass: className,
935
954
  lockPinned: true,
@@ -1100,6 +1119,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1100
1119
 
1101
1120
  return match;
1102
1121
  });
1122
+ leafColIds.push(field.id);
1103
1123
  var code = parse(expression).compile();
1104
1124
  result.push({
1105
1125
  colId: field.id,
@@ -1160,8 +1180,8 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1160
1180
  try {
1161
1181
  return code.evaluate(scope);
1162
1182
  } catch (err) {
1163
- console.error(err);
1164
- return NaN;
1183
+ console.warn('DataGrid field evaluate', err);
1184
+ return null;
1165
1185
  }
1166
1186
  }
1167
1187
 
@@ -1189,10 +1209,12 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1189
1209
  sortable: false,
1190
1210
  suppressAutoSize: true,
1191
1211
  suppressMovable: true,
1212
+ suppressMenu: true,
1192
1213
  lockPinned: true,
1193
1214
  lockVisible: true,
1194
1215
  suppressColumnsToolPanel: true,
1195
1216
  cellClass: prefix('cell-selection'),
1217
+ headerClass: prefix('cell-selection'),
1196
1218
  pinned: rowSelection.fixed
1197
1219
  });
1198
1220
  }
@@ -1231,7 +1253,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1231
1253
  });
1232
1254
  }
1233
1255
 
1234
- return result;
1256
+ return [result, leafColIds];
1235
1257
  }
1236
1258
  }, {
1237
1259
  key: "isClientMode",
@@ -1701,7 +1723,6 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1701
1723
  restProps = _objectWithoutProperties(_this$props8, _excluded4);
1702
1724
 
1703
1725
  var _this$state3 = this.state,
1704
- colDefs = _this$state3.colDefs,
1705
1726
  enablePagination = _this$state3.pagination,
1706
1727
  page = _this$state3.page,
1707
1728
  pageSize = _this$state3.pageSize,
@@ -1794,7 +1815,6 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1794
1815
  onCellFocused: this.cellFocused,
1795
1816
  pagination: enablePagination,
1796
1817
  paginationPageSize: pageSize,
1797
- columnDefs: colDefs,
1798
1818
  getRowId: this.getRowId,
1799
1819
  onGridReady: this.init,
1800
1820
  context: context,
@@ -85,7 +85,6 @@ export declare type SortType = {
85
85
  order: SortOrder;
86
86
  };
87
87
  export declare type DataGridState<TData> = {
88
- colDefs: (ColDef<TData> | ColGroupDef<TData>)[];
89
88
  pagination: boolean;
90
89
  page: number;
91
90
  pageSize: number;
@@ -1,6 +1,6 @@
1
1
  @spaceX: 16px;
2
2
  @spaceY: 8px;
3
- @labelWidth: 94px;
3
+ @labelWidth: 92px;
4
4
  @minWidth: (1366px - 160px - 4 * @space-h + @spaceX) / 4;
5
5
  @maxWidth: (1920px - 200px - 4 * @space-h + @spaceX) / 5;
6
6
 
@@ -49,7 +49,7 @@
49
49
 
50
50
  &-required::before {
51
51
  position: absolute;
52
- left: -11px;
52
+ left: -8px;
53
53
  }
54
54
 
55
55
  &-with-help &-explain {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/kits",
3
- "version": "1.0.0-192",
3
+ "version": "1.0.0-194",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",