@kdcloudjs/table 1.1.5 → 1.1.6-canary.2

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.
@@ -1,70 +1,152 @@
1
+ import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
2
+ import _Number$MAX_SAFE_INTEGER from "@babel/runtime-corejs3/core-js-stable/number/max-safe-integer";
1
3
  import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
2
4
  import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
3
5
  import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/splice";
6
+ import _Map from "@babel/runtime-corejs3/core-js-stable/map";
4
7
  import { getLeftNestedLockCount } from '../../base/calculations';
5
8
  import { isLeafNode, makeRecursiveMapper } from '../../utils';
6
9
  import { Classes } from '../../base/styles';
7
- import { COLUMN_RESIZE_KEY } from './columnResizeWidth';
10
+ import { COLUMN_SIZE_KEY, RESIZED_COLUMN_KEY } from './columnResizeWidth';
8
11
  export var FILL_COLUMN_CODE = '$_fill_column_&';
9
12
  export var tableWidthKey = 'tableWidth';
10
- var fillColumnWidthKey = 'fillColumnWidth';
13
+
14
+ var FLEX_COLUMN_COUNT = _Symbol('flexCount');
15
+
11
16
  export var autoFillTableWidth = function autoFillTableWidth() {
12
17
  return function (pipeline) {
13
- var width = pipeline.getStateAtKey(fillColumnWidthKey, 0);
14
- var columns = pipeline.getColumns();
18
+ var flexColumnResult = findFlexColumns(pipeline);
19
+ var flexCount = flexColumnResult.get(FLEX_COLUMN_COUNT);
20
+
21
+ if (flexCount) {
22
+ // 设置了flex宽度,flex列平分剩余宽度
23
+ var remainingWidth = getTableRemainingWidth(pipeline) || 0;
15
24
 
16
- var fillColumns = _findInstanceProperty(columns).call(columns, function (col) {
17
- return col.code === FILL_COLUMN_CODE;
18
- });
25
+ if (remainingWidth > 0) {
26
+ // 保存剩余的flex总和和剩余宽度总和宽度
27
+ var residualFlexCount = flexCount;
28
+ var residualFlexWidth = remainingWidth;
29
+ var columnSize = pipeline.getFeatureOptions(COLUMN_SIZE_KEY) || {};
30
+ pipeline.mapColumns(makeRecursiveMapper(function (col, recursiveFlatMapInfo) {
31
+ var isLeaf = recursiveFlatMapInfo.isLeaf;
19
32
 
20
- if (fillColumns) {
21
- fillColumns.width = width;
33
+ if (isLeaf && isValidFlexColumn(col, pipeline)) {
34
+ var code = col.code,
35
+ _col$features = col.features,
36
+ features = _col$features === void 0 ? {} : _col$features;
37
+ var flex = features.flex,
38
+ _features$minWidth = features.minWidth,
39
+ minWidth = _features$minWidth === void 0 ? 0 : _features$minWidth,
40
+ _features$maxWidth = features.maxWidth,
41
+ maxWidth = _features$maxWidth === void 0 ? _Number$MAX_SAFE_INTEGER : _features$maxWidth;
42
+ var usedRemainingWidth = Math.floor(remainingWidth * flex / flexCount);
43
+ var preColWidth = col.width; // 如果当前已经是最后一个flex列,将剩余的宽度添加到该列,其他计算相应的列
44
+
45
+ col.width = clamp(minWidth, preColWidth + (residualFlexCount === flex ? residualFlexWidth : usedRemainingWidth), maxWidth);
46
+ residualFlexCount -= flex;
47
+ residualFlexWidth -= col.width - preColWidth;
48
+ columnSize[code] = col.width;
49
+ }
50
+
51
+ return col;
52
+ }));
53
+ pipeline.setFeatureOptions(COLUMN_SIZE_KEY, columnSize);
54
+ }
22
55
  } else {
23
- var rightNestedLockCount = getLeftNestedLockCount(_sliceInstanceProperty(columns).call(columns).reverse());
24
- var spliceIndex = columns.length - rightNestedLockCount;
25
- var _fillColumns = {
26
- name: '',
27
- code: FILL_COLUMN_CODE,
28
- width: width,
29
- features: {
30
- resizeable: false
31
- },
32
- getCellProps: function getCellProps(value, record, rowIndex) {
33
- return {
34
- className: Classes.emptyColCell
35
- };
36
- }
37
- };
38
-
39
- _spliceInstanceProperty(columns).call(columns, spliceIndex || columns.length, 0, _fillColumns);
56
+ // 未设置了flex宽度,创建占位列
57
+ var columns = pipeline.getColumns();
58
+
59
+ var fillColumns = _findInstanceProperty(columns).call(columns, function (col) {
60
+ return col.code === FILL_COLUMN_CODE;
61
+ });
62
+
63
+ var width = getTableRemainingWidth(pipeline) || 0;
64
+
65
+ if (fillColumns) {
66
+ fillColumns.width = width;
67
+ } else {
68
+ var rightNestedLockCount = getLeftNestedLockCount(_sliceInstanceProperty(columns).call(columns).reverse());
69
+ var spliceIndex = columns.length - rightNestedLockCount;
70
+ var _fillColumns = {
71
+ name: '',
72
+ code: FILL_COLUMN_CODE,
73
+ width: width,
74
+ features: {
75
+ resizeable: false
76
+ },
77
+ getCellProps: function getCellProps(value, record, rowIndex) {
78
+ return {
79
+ className: Classes.emptyColCell
80
+ };
81
+ }
82
+ };
83
+
84
+ _spliceInstanceProperty(columns).call(columns, spliceIndex || columns.length, 0, _fillColumns);
85
+ }
86
+
87
+ pipeline.columns(columns);
40
88
  }
41
89
 
42
- pipeline.columns(columns);
43
- setAutoFillWidth(pipeline);
44
90
  return pipeline;
91
+
92
+ function findFlexColumns(pipeline) {
93
+ var result = new _Map([[FLEX_COLUMN_COUNT, 0]]);
94
+ dfs(pipeline.getColumns(), result);
95
+ return result;
96
+
97
+ function dfs(columns, result) {
98
+ columns.forEach(function (col) {
99
+ if (isLeafNode(col)) {
100
+ if (isValidFlexColumn(col, pipeline)) {
101
+ result.set(FLEX_COLUMN_COUNT, result.get(FLEX_COLUMN_COUNT) + col.features.flex);
102
+ }
103
+ } else {
104
+ dfs(col.children, result);
105
+ }
106
+ });
107
+ }
108
+ }
45
109
  };
46
110
  };
47
111
 
48
- var setAutoFillWidth = function setAutoFillWidth(pipeline) {
112
+ function getColumnWidthSum(pipeline) {
113
+ return dfs(pipeline.getColumns());
114
+
115
+ function dfs(columns) {
116
+ return columns.reduce(function (acc, col) {
117
+ var width = col.width,
118
+ code = col.code;
119
+
120
+ if (isLeafNode(col) && code !== FILL_COLUMN_CODE) {
121
+ var resizeColumn = pipeline.getFeatureOptions(COLUMN_SIZE_KEY);
122
+ return acc + (resizeColumn && resizeColumn[code] || width);
123
+ } else {
124
+ return acc + dfs(col.children);
125
+ }
126
+ }, 0);
127
+ }
128
+ }
129
+
130
+ function getTableRemainingWidth(pipeline) {
49
131
  var tableWidth = pipeline.getStateAtKey(tableWidthKey);
50
132
  if (!tableWidth) return;
51
- var columnWidthSum = 0;
52
- pipeline.mapColumns(makeRecursiveMapper(function (col) {
53
- var width = col.width,
54
- code = col.code;
55
-
56
- if (isLeafNode(col) && code !== FILL_COLUMN_CODE) {
57
- var resizeColumn = pipeline.getFeatureOptions(COLUMN_RESIZE_KEY);
58
- columnWidthSum += resizeColumn && resizeColumn[code] || width;
59
- }
133
+ var remainingWidth = Math.floor(tableWidth - getColumnWidthSum(pipeline));
134
+ return remainingWidth > 0 ? remainingWidth : 0;
135
+ }
136
+
137
+ function isValidFlexColumn(col, pipeline) {
138
+ var _a;
60
139
 
61
- return col;
62
- }));
63
- var fillColumnWidth = Math.floor(tableWidth - columnWidthSum);
64
- fillColumnWidth = fillColumnWidth > 0 ? fillColumnWidth : 0;
65
- var preWidth = pipeline.getStateAtKey(fillColumnWidthKey, 0);
140
+ var resizeColumn = pipeline.getFeatureOptions(RESIZED_COLUMN_KEY); // 拖拽列自动禁止flex
66
141
 
67
- if (preWidth !== fillColumnWidth) {
68
- pipeline.setStateAtKey('fillColumnWidth', fillColumnWidth);
142
+ if (resizeColumn === null || resizeColumn === void 0 ? void 0 : resizeColumn.has(col.code)) {
143
+ return false;
69
144
  }
70
- };
145
+
146
+ var flex = (_a = col.features) === null || _a === void 0 ? void 0 : _a.flex;
147
+ return typeof flex === 'number' && flex > 0;
148
+ }
149
+
150
+ function clamp(min, x, max) {
151
+ return Math.max(min, Math.min(max, x));
152
+ }
@@ -20,6 +20,7 @@ export interface ColumnResizeOptions {
20
20
  onChangeSize?(nextSize: ColumnSize): void;
21
21
  afterChangeSize?(nextSize: ColumnSize, changedColumnSize: ChangedColumnSize[]): void;
22
22
  }
23
- export declare const COLUMN_RESIZE_KEY = "columnResize";
23
+ export declare const COLUMN_SIZE_KEY = "columnResize";
24
+ export declare const RESIZED_COLUMN_KEY = "resizedColumn";
24
25
  export declare function columnResize(opts?: ColumnResizeOptions): (pipeline: TablePipeline) => TablePipeline;
25
26
  export {};
@@ -3,8 +3,9 @@ import _taggedTemplateLiteral from "@babel/runtime-corejs3/helpers/taggedTemplat
3
3
 
4
4
  var _templateObject, _templateObject2;
5
5
 
6
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
6
+ import _Set from "@babel/runtime-corejs3/core-js-stable/set";
7
7
  import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
8
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
8
9
  import React from 'react';
9
10
  import styled from 'styled-components';
10
11
  import { fromEvent } from 'rxjs';
@@ -24,7 +25,8 @@ function disableSelect(event) {
24
25
  }
25
26
 
26
27
  var stateKey = 'columnResize';
27
- export var COLUMN_RESIZE_KEY = 'columnResize';
28
+ export var COLUMN_SIZE_KEY = 'columnResize';
29
+ export var RESIZED_COLUMN_KEY = 'resizedColumn';
28
30
  export function columnResize() {
29
31
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
30
32
 
@@ -49,10 +51,10 @@ export function columnResize() {
49
51
  columnSize[code] = fallbackSize;
50
52
  }
51
53
  }
52
- }); // 为了autofill时能取到最新值,实时存储一份最新的columnSize
54
+ }); // 实时存储一份最新的columnSize,与autoFill共用一份数据
53
55
  // 存在state里可能存到取不到最新的
54
56
 
55
- pipeline.setFeatureOptions(COLUMN_RESIZE_KEY, columnSize);
57
+ pipeline.setFeatureOptions(COLUMN_SIZE_KEY, columnSize);
56
58
 
57
59
  var onChangeSize = function onChangeSize(nextColumnSize) {
58
60
  window.requestAnimationFrame(function () {
@@ -64,7 +66,9 @@ export function columnResize() {
64
66
  };
65
67
 
66
68
  var handleDoubleClick = function handleDoubleClick(e, col) {
67
- opts === null || opts === void 0 ? void 0 : opts.doubleClickCallback(e, col);
69
+ var _a;
70
+
71
+ (_a = opts.doubleClickCallback) === null || _a === void 0 ? void 0 : _a.call(opts, e, col);
68
72
  };
69
73
 
70
74
  var handleMouseDown = function handleMouseDown(e, col) {
@@ -72,7 +76,14 @@ export function columnResize() {
72
76
  var changedColumnSize = {};
73
77
  var startX = e.clientX;
74
78
  var children = col.children,
75
- code = col.code;
79
+ code = col.code,
80
+ _col$features = col.features,
81
+ features = _col$features === void 0 ? {} : _col$features;
82
+ var minWidth = features.minWidth,
83
+ maxWidth = features.maxWidth;
84
+ var realMinSize = typeof minWidth === 'number' ? minWidth : minSize;
85
+ var realMaxSize = typeof maxWidth === 'number' ? maxWidth : maxSize;
86
+ var columnSize = pipeline.getFeatureOptions(COLUMN_SIZE_KEY);
76
87
  var recordColumnSize = columnSize;
77
88
  e.stopPropagation();
78
89
  var nextSize$ = fromEvent(window, 'mousemove').pipe(op.takeUntil(fromEvent(window, 'mouseup')), op.map(function (e) {
@@ -95,17 +106,17 @@ export function columnResize() {
95
106
  var currentDeltaWidth = Math.round(deltaSum * startSize / childrenWidthSum);
96
107
 
97
108
  if (index < leafChildColumns.length - 1) {
98
- nextColumnSize[code] = clamp(minSize, startSize + currentDeltaWidth, maxSize);
109
+ nextColumnSize[code] = clamp(realMinSize, startSize + currentDeltaWidth, realMaxSize);
99
110
  changedColumnSize[code] = nextColumnSize[code];
100
111
  deltaRemaining -= currentDeltaWidth;
101
112
  } else {
102
- nextColumnSize[code] = clamp(minSize, startSize + deltaRemaining, maxSize);
113
+ nextColumnSize[code] = clamp(realMinSize, startSize + deltaRemaining, realMaxSize);
103
114
  changedColumnSize[code] = nextColumnSize[code];
104
115
  }
105
116
  });
106
117
  } else {
107
118
  var startSize = columnSize[code];
108
- nextColumnSize[code] = clamp(minSize, startSize + deltaSum, maxSize);
119
+ nextColumnSize[code] = clamp(realMinSize, startSize + deltaSum, realMaxSize);
109
120
  changedColumnSize[code] = nextColumnSize[code];
110
121
  }
111
122
 
@@ -113,7 +124,17 @@ export function columnResize() {
113
124
  return nextColumnSize;
114
125
  }));
115
126
  nextSize$.subscribe({
116
- next: onChangeSize,
127
+ next: function next(nextColumnSize) {
128
+ onChangeSize(nextColumnSize); // 由于COLUMN_RESIZE_KEY记录的是全量的列宽,此处记录被改变过的列宽
129
+
130
+ var resizedColumnSet = pipeline.getFeatureOptions(RESIZED_COLUMN_KEY) || new _Set();
131
+
132
+ _Object$keys(changedColumnSize).forEach(function (code) {
133
+ resizedColumnSet.add(code, changedColumnSize[code]);
134
+ });
135
+
136
+ pipeline.setFeatureOptions(RESIZED_COLUMN_KEY, resizedColumnSet);
137
+ },
117
138
  complete: function complete() {
118
139
  var _context;
119
140
 
@@ -300,8 +300,9 @@ export function useTablePipeline(ctx) {
300
300
  state = _useState2[0],
301
301
  setState = _useState2[1];
302
302
 
303
- var ref = useRef({});
304
- ref.current.featureOptions = {};
303
+ var ref = useRef({
304
+ featureOptions: {}
305
+ });
305
306
  return new TablePipeline({
306
307
  state: state,
307
308
  setState: setState,
@@ -7,12 +7,18 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.tableWidthKey = exports.autoFillTableWidth = exports.FILL_COLUMN_CODE = void 0;
9
9
 
10
+ var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol"));
11
+
12
+ var _maxSafeInteger = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/max-safe-integer"));
13
+
10
14
  var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
11
15
 
12
16
  var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
13
17
 
14
18
  var _splice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/splice"));
15
19
 
20
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/map"));
21
+
16
22
  var _calculations = require("../../base/calculations");
17
23
 
18
24
  var _utils = require("../../utils");
@@ -25,65 +31,141 @@ var FILL_COLUMN_CODE = '$_fill_column_&';
25
31
  exports.FILL_COLUMN_CODE = FILL_COLUMN_CODE;
26
32
  var tableWidthKey = 'tableWidth';
27
33
  exports.tableWidthKey = tableWidthKey;
28
- var fillColumnWidthKey = 'fillColumnWidth';
34
+ var FLEX_COLUMN_COUNT = (0, _symbol.default)('flexCount');
29
35
 
30
36
  var autoFillTableWidth = function autoFillTableWidth() {
31
37
  return function (pipeline) {
32
- var width = pipeline.getStateAtKey(fillColumnWidthKey, 0);
33
- var columns = pipeline.getColumns();
34
- var fillColumns = (0, _find.default)(columns).call(columns, function (col) {
35
- return col.code === FILL_COLUMN_CODE;
36
- });
37
-
38
- if (fillColumns) {
39
- fillColumns.width = width;
38
+ var flexColumnResult = findFlexColumns(pipeline);
39
+ var flexCount = flexColumnResult.get(FLEX_COLUMN_COUNT);
40
+
41
+ if (flexCount) {
42
+ // 设置了flex宽度,flex列平分剩余宽度
43
+ var remainingWidth = getTableRemainingWidth(pipeline) || 0;
44
+
45
+ if (remainingWidth > 0) {
46
+ // 保存剩余的flex总和和剩余宽度总和宽度
47
+ var residualFlexCount = flexCount;
48
+ var residualFlexWidth = remainingWidth;
49
+ var columnSize = pipeline.getFeatureOptions(_columnResizeWidth.COLUMN_SIZE_KEY) || {};
50
+ pipeline.mapColumns((0, _utils.makeRecursiveMapper)(function (col, recursiveFlatMapInfo) {
51
+ var isLeaf = recursiveFlatMapInfo.isLeaf;
52
+
53
+ if (isLeaf && isValidFlexColumn(col, pipeline)) {
54
+ var code = col.code,
55
+ _col$features = col.features,
56
+ features = _col$features === void 0 ? {} : _col$features;
57
+ var flex = features.flex,
58
+ _features$minWidth = features.minWidth,
59
+ minWidth = _features$minWidth === void 0 ? 0 : _features$minWidth,
60
+ _features$maxWidth = features.maxWidth,
61
+ maxWidth = _features$maxWidth === void 0 ? _maxSafeInteger.default : _features$maxWidth;
62
+ var usedRemainingWidth = Math.floor(remainingWidth * flex / flexCount);
63
+ var preColWidth = col.width; // 如果当前已经是最后一个flex列,将剩余的宽度添加到该列,其他计算相应的列
64
+
65
+ col.width = clamp(minWidth, preColWidth + (residualFlexCount === flex ? residualFlexWidth : usedRemainingWidth), maxWidth);
66
+ residualFlexCount -= flex;
67
+ residualFlexWidth -= col.width - preColWidth;
68
+ columnSize[code] = col.width;
69
+ }
70
+
71
+ return col;
72
+ }));
73
+ pipeline.setFeatureOptions(_columnResizeWidth.COLUMN_SIZE_KEY, columnSize);
74
+ }
40
75
  } else {
41
- var rightNestedLockCount = (0, _calculations.getLeftNestedLockCount)((0, _slice.default)(columns).call(columns).reverse());
42
- var spliceIndex = columns.length - rightNestedLockCount;
43
- var _fillColumns = {
44
- name: '',
45
- code: FILL_COLUMN_CODE,
46
- width: width,
47
- features: {
48
- resizeable: false
49
- },
50
- getCellProps: function getCellProps(value, record, rowIndex) {
51
- return {
52
- className: _styles.Classes.emptyColCell
53
- };
54
- }
55
- };
56
- (0, _splice.default)(columns).call(columns, spliceIndex || columns.length, 0, _fillColumns);
76
+ // 未设置了flex宽度,创建占位列
77
+ var columns = pipeline.getColumns();
78
+ var fillColumns = (0, _find.default)(columns).call(columns, function (col) {
79
+ return col.code === FILL_COLUMN_CODE;
80
+ });
81
+ var width = getTableRemainingWidth(pipeline) || 0;
82
+
83
+ if (fillColumns) {
84
+ fillColumns.width = width;
85
+ } else {
86
+ var rightNestedLockCount = (0, _calculations.getLeftNestedLockCount)((0, _slice.default)(columns).call(columns).reverse());
87
+ var spliceIndex = columns.length - rightNestedLockCount;
88
+ var _fillColumns = {
89
+ name: '',
90
+ code: FILL_COLUMN_CODE,
91
+ width: width,
92
+ features: {
93
+ resizeable: false
94
+ },
95
+ getCellProps: function getCellProps(value, record, rowIndex) {
96
+ return {
97
+ className: _styles.Classes.emptyColCell
98
+ };
99
+ }
100
+ };
101
+ (0, _splice.default)(columns).call(columns, spliceIndex || columns.length, 0, _fillColumns);
102
+ }
103
+
104
+ pipeline.columns(columns);
57
105
  }
58
106
 
59
- pipeline.columns(columns);
60
- setAutoFillWidth(pipeline);
61
107
  return pipeline;
108
+
109
+ function findFlexColumns(pipeline) {
110
+ var result = new _map.default([[FLEX_COLUMN_COUNT, 0]]);
111
+ dfs(pipeline.getColumns(), result);
112
+ return result;
113
+
114
+ function dfs(columns, result) {
115
+ columns.forEach(function (col) {
116
+ if ((0, _utils.isLeafNode)(col)) {
117
+ if (isValidFlexColumn(col, pipeline)) {
118
+ result.set(FLEX_COLUMN_COUNT, result.get(FLEX_COLUMN_COUNT) + col.features.flex);
119
+ }
120
+ } else {
121
+ dfs(col.children, result);
122
+ }
123
+ });
124
+ }
125
+ }
62
126
  };
63
127
  };
64
128
 
65
129
  exports.autoFillTableWidth = autoFillTableWidth;
66
130
 
67
- var setAutoFillWidth = function setAutoFillWidth(pipeline) {
131
+ function getColumnWidthSum(pipeline) {
132
+ return dfs(pipeline.getColumns());
133
+
134
+ function dfs(columns) {
135
+ return columns.reduce(function (acc, col) {
136
+ var width = col.width,
137
+ code = col.code;
138
+
139
+ if ((0, _utils.isLeafNode)(col) && code !== FILL_COLUMN_CODE) {
140
+ var resizeColumn = pipeline.getFeatureOptions(_columnResizeWidth.COLUMN_SIZE_KEY);
141
+ return acc + (resizeColumn && resizeColumn[code] || width);
142
+ } else {
143
+ return acc + dfs(col.children);
144
+ }
145
+ }, 0);
146
+ }
147
+ }
148
+
149
+ function getTableRemainingWidth(pipeline) {
68
150
  var tableWidth = pipeline.getStateAtKey(tableWidthKey);
69
151
  if (!tableWidth) return;
70
- var columnWidthSum = 0;
71
- pipeline.mapColumns((0, _utils.makeRecursiveMapper)(function (col) {
72
- var width = col.width,
73
- code = col.code;
74
-
75
- if ((0, _utils.isLeafNode)(col) && code !== FILL_COLUMN_CODE) {
76
- var resizeColumn = pipeline.getFeatureOptions(_columnResizeWidth.COLUMN_RESIZE_KEY);
77
- columnWidthSum += resizeColumn && resizeColumn[code] || width;
78
- }
152
+ var remainingWidth = Math.floor(tableWidth - getColumnWidthSum(pipeline));
153
+ return remainingWidth > 0 ? remainingWidth : 0;
154
+ }
155
+
156
+ function isValidFlexColumn(col, pipeline) {
157
+ var _a;
79
158
 
80
- return col;
81
- }));
82
- var fillColumnWidth = Math.floor(tableWidth - columnWidthSum);
83
- fillColumnWidth = fillColumnWidth > 0 ? fillColumnWidth : 0;
84
- var preWidth = pipeline.getStateAtKey(fillColumnWidthKey, 0);
159
+ var resizeColumn = pipeline.getFeatureOptions(_columnResizeWidth.RESIZED_COLUMN_KEY); // 拖拽列自动禁止flex
85
160
 
86
- if (preWidth !== fillColumnWidth) {
87
- pipeline.setStateAtKey('fillColumnWidth', fillColumnWidth);
161
+ if (resizeColumn === null || resizeColumn === void 0 ? void 0 : resizeColumn.has(col.code)) {
162
+ return false;
88
163
  }
89
- };
164
+
165
+ var flex = (_a = col.features) === null || _a === void 0 ? void 0 : _a.flex;
166
+ return typeof flex === 'number' && flex > 0;
167
+ }
168
+
169
+ function clamp(min, x, max) {
170
+ return Math.max(min, Math.min(max, x));
171
+ }
@@ -20,6 +20,7 @@ export interface ColumnResizeOptions {
20
20
  onChangeSize?(nextSize: ColumnSize): void;
21
21
  afterChangeSize?(nextSize: ColumnSize, changedColumnSize: ChangedColumnSize[]): void;
22
22
  }
23
- export declare const COLUMN_RESIZE_KEY = "columnResize";
23
+ export declare const COLUMN_SIZE_KEY = "columnResize";
24
+ export declare const RESIZED_COLUMN_KEY = "resizedColumn";
24
25
  export declare function columnResize(opts?: ColumnResizeOptions): (pipeline: TablePipeline) => TablePipeline;
25
26
  export {};
@@ -11,13 +11,15 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
11
11
  Object.defineProperty(exports, "__esModule", {
12
12
  value: true
13
13
  });
14
- exports.COLUMN_RESIZE_KEY = void 0;
14
+ exports.RESIZED_COLUMN_KEY = exports.COLUMN_SIZE_KEY = void 0;
15
15
  exports.columnResize = columnResize;
16
16
 
17
- var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
17
+ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
18
18
 
19
19
  var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
20
20
 
21
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
22
+
21
23
  var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
22
24
 
23
25
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/taggedTemplateLiteral"));
@@ -55,8 +57,10 @@ function disableSelect(event) {
55
57
  }
56
58
 
57
59
  var stateKey = 'columnResize';
58
- var COLUMN_RESIZE_KEY = 'columnResize';
59
- exports.COLUMN_RESIZE_KEY = COLUMN_RESIZE_KEY;
60
+ var COLUMN_SIZE_KEY = 'columnResize';
61
+ exports.COLUMN_SIZE_KEY = COLUMN_SIZE_KEY;
62
+ var RESIZED_COLUMN_KEY = 'resizedColumn';
63
+ exports.RESIZED_COLUMN_KEY = RESIZED_COLUMN_KEY;
60
64
 
61
65
  function columnResize() {
62
66
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -82,10 +86,10 @@ function columnResize() {
82
86
  columnSize[code] = fallbackSize;
83
87
  }
84
88
  }
85
- }); // 为了autofill时能取到最新值,实时存储一份最新的columnSize
89
+ }); // 实时存储一份最新的columnSize,与autoFill共用一份数据
86
90
  // 存在state里可能存到取不到最新的
87
91
 
88
- pipeline.setFeatureOptions(COLUMN_RESIZE_KEY, columnSize);
92
+ pipeline.setFeatureOptions(COLUMN_SIZE_KEY, columnSize);
89
93
 
90
94
  var onChangeSize = function onChangeSize(nextColumnSize) {
91
95
  window.requestAnimationFrame(function () {
@@ -97,7 +101,9 @@ function columnResize() {
97
101
  };
98
102
 
99
103
  var handleDoubleClick = function handleDoubleClick(e, col) {
100
- opts === null || opts === void 0 ? void 0 : opts.doubleClickCallback(e, col);
104
+ var _a;
105
+
106
+ (_a = opts.doubleClickCallback) === null || _a === void 0 ? void 0 : _a.call(opts, e, col);
101
107
  };
102
108
 
103
109
  var handleMouseDown = function handleMouseDown(e, col) {
@@ -105,7 +111,14 @@ function columnResize() {
105
111
  var changedColumnSize = {};
106
112
  var startX = e.clientX;
107
113
  var children = col.children,
108
- code = col.code;
114
+ code = col.code,
115
+ _col$features = col.features,
116
+ features = _col$features === void 0 ? {} : _col$features;
117
+ var minWidth = features.minWidth,
118
+ maxWidth = features.maxWidth;
119
+ var realMinSize = typeof minWidth === 'number' ? minWidth : minSize;
120
+ var realMaxSize = typeof maxWidth === 'number' ? maxWidth : maxSize;
121
+ var columnSize = pipeline.getFeatureOptions(COLUMN_SIZE_KEY);
109
122
  var recordColumnSize = columnSize;
110
123
  e.stopPropagation();
111
124
  var nextSize$ = (0, _rxjs.fromEvent)(window, 'mousemove').pipe(op.takeUntil((0, _rxjs.fromEvent)(window, 'mouseup')), op.map(function (e) {
@@ -126,17 +139,17 @@ function columnResize() {
126
139
  var currentDeltaWidth = Math.round(deltaSum * startSize / childrenWidthSum);
127
140
 
128
141
  if (index < leafChildColumns.length - 1) {
129
- nextColumnSize[code] = clamp(minSize, startSize + currentDeltaWidth, maxSize);
142
+ nextColumnSize[code] = clamp(realMinSize, startSize + currentDeltaWidth, realMaxSize);
130
143
  changedColumnSize[code] = nextColumnSize[code];
131
144
  deltaRemaining -= currentDeltaWidth;
132
145
  } else {
133
- nextColumnSize[code] = clamp(minSize, startSize + deltaRemaining, maxSize);
146
+ nextColumnSize[code] = clamp(realMinSize, startSize + deltaRemaining, realMaxSize);
134
147
  changedColumnSize[code] = nextColumnSize[code];
135
148
  }
136
149
  });
137
150
  } else {
138
151
  var startSize = columnSize[code];
139
- nextColumnSize[code] = clamp(minSize, startSize + deltaSum, maxSize);
152
+ nextColumnSize[code] = clamp(realMinSize, startSize + deltaSum, realMaxSize);
140
153
  changedColumnSize[code] = nextColumnSize[code];
141
154
  }
142
155
 
@@ -144,7 +157,15 @@ function columnResize() {
144
157
  return nextColumnSize;
145
158
  }));
146
159
  nextSize$.subscribe({
147
- next: onChangeSize,
160
+ next: function next(nextColumnSize) {
161
+ onChangeSize(nextColumnSize); // 由于COLUMN_RESIZE_KEY记录的是全量的列宽,此处记录被改变过的列宽
162
+
163
+ var resizedColumnSet = pipeline.getFeatureOptions(RESIZED_COLUMN_KEY) || new _set.default();
164
+ (0, _keys.default)(changedColumnSize).forEach(function (code) {
165
+ resizedColumnSet.add(code, changedColumnSize[code]);
166
+ });
167
+ pipeline.setFeatureOptions(RESIZED_COLUMN_KEY, resizedColumnSet);
168
+ },
148
169
  complete: function complete() {
149
170
  var _context;
150
171
 
@@ -318,8 +318,9 @@ function useTablePipeline(ctx) {
318
318
  state = _useState2[0],
319
319
  setState = _useState2[1];
320
320
 
321
- var ref = (0, _react.useRef)({});
322
- ref.current.featureOptions = {};
321
+ var ref = (0, _react.useRef)({
322
+ featureOptions: {}
323
+ });
323
324
  return new TablePipeline({
324
325
  state: state,
325
326
  setState: setState,