shineout 2.0.23 → 2.0.24

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.
@@ -281,7 +281,7 @@ export interface SimpleTableProps<DataItem, Value> {
281
281
  * @en
282
282
  * @cn
283
283
  */
284
- onResize?: (index: number, width: number, colgroup?: number[]) => void;
284
+ onResize?: (index: number, width: number, colgroup?: number[], colspan?: number) => void;
285
285
  /**
286
286
  * @en sticky header, When it is true, the distance from the top is 0. When it is an object, the attribute value reference [Sticky component](/components/Sticky)
287
287
  * @cn 表头是否附着顶部,为 true 时距离顶部为0,为对象时属性值参考 [Sticky](/components/Sticky) 组件
@@ -330,7 +330,7 @@ export interface SimpleTableProps<DataItem, Value> {
330
330
  * @en
331
331
  * @cn
332
332
  */
333
- onResize?: (index: number, width: number, colgroup?: number[]) => void
333
+ onResize?: (index: number, width: number, colgroup?: number[], colspan?: number) => void
334
334
  /**
335
335
  * @en sticky header, When it is true, the distance from the top is 0. When it is an object, the attribute value reference [Sticky component](/components/Sticky)
336
336
  * @cn 表头是否附着顶部,为 true 时距离顶部为0,为对象时属性值参考 [Sticky](/components/Sticky) 组件
@@ -251,6 +251,9 @@ var SimpleTable = /*#__PURE__*/function (_PureComponent) {
251
251
  var minWidthSup = columns.find(function (d) {
252
252
  return d.minWidth;
253
253
  });
254
+ console.log('======================');
255
+ console.log('renderBody width: >>', width);
256
+ console.log('======================');
254
257
  return /*#__PURE__*/_react.default.createElement("div", {
255
258
  key: "body",
256
259
  className: (0, _styles.tableClass)('simple-body'),
@@ -135,7 +135,10 @@ class SimpleTable<DataItem, Value> extends PureComponent<SimpleTableProps<DataIt
135
135
  const { width } = tds[i].getBoundingClientRect()
136
136
  const colSpan = parseInt(tds[i].getAttribute('colspan') || '', 10)
137
137
  if (colSpan > 1) {
138
- split(width, range(colSpan).map(j => columns[i + j].width!)).forEach(w => colgroup.push(w))
138
+ split(
139
+ width,
140
+ range(colSpan).map(j => columns[i + j].width!)
141
+ ).forEach(w => colgroup.push(w))
139
142
  } else {
140
143
  colgroup.push(width)
141
144
  }
@@ -218,6 +221,9 @@ class SimpleTable<DataItem, Value> extends PureComponent<SimpleTableProps<DataIt
218
221
  const { columns, width, fixed, columnResizable, bordered, ...others } = this.props
219
222
  const { colgroup, resize } = this.state
220
223
  const minWidthSup = columns.find(d => d.minWidth)
224
+ console.log('======================')
225
+ console.log('renderBody width: >>', width)
226
+ console.log('======================')
221
227
  return (
222
228
  <div key="body" className={tableClass('simple-body')} ref={this.bindBody} onScroll={this.handleScroll}>
223
229
  <table
@@ -14,10 +14,14 @@ declare class Thead<DataItem, Value> extends PureComponent<TheadProps<DataItem,
14
14
  resizingIndex: number;
15
15
  resizingCol: HTMLTableColElement;
16
16
  lastX?: number;
17
+ newResizingWidth: number;
17
18
  rightBorderRecord: ObjectType<boolean>;
18
19
  constructor(props: TheadProps<DataItem, Value>);
19
20
  setColumns(columns: TheadColumn<DataItem>[], col: ColumnItemWithFixed<DataItem>, level: number, index?: number): number;
21
+ get resizingColspan(): number;
22
+ getNewColgroup(): number[];
20
23
  resizeColgroup(deltaX: number): void;
24
+ resizeMultipleColgroup(deltaX: number, colspan: number): void;
21
25
  handleResize(type: 'mousedown' | 'mousemove' | 'mouseup', e: MouseEvent): void;
22
26
  createTh(trs: ReactElement[][], col: TheadColumn<DataItem>, level: number): void;
23
27
  ignoreRightBorder(column: TheadColumn<DataItem>): void;
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  exports.__esModule = true;
5
5
  exports.default = void 0;
6
6
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
7
8
  var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _react = _interopRequireWildcard(require("react"));
@@ -31,6 +32,7 @@ var Thead = /*#__PURE__*/function (_PureComponent) {
31
32
  (0, _defineProperty2.default)(_this, "resizingIndex", void 0);
32
33
  (0, _defineProperty2.default)(_this, "resizingCol", void 0);
33
34
  (0, _defineProperty2.default)(_this, "lastX", void 0);
35
+ (0, _defineProperty2.default)(_this, "newResizingWidth", void 0);
34
36
  (0, _defineProperty2.default)(_this, "rightBorderRecord", void 0);
35
37
  _this.handleMouseDown = _this.handleResize.bind(_this, 'mousedown');
36
38
  _this.handleMouseMove = _this.handleResize.bind(_this, 'mousemove');
@@ -76,6 +78,21 @@ var Thead = /*#__PURE__*/function (_PureComponent) {
76
78
  }
77
79
  return colSpan;
78
80
  };
81
+ _proto.getNewColgroup = function getNewColgroup() {
82
+ var _this$resizingCol$par;
83
+ var colgroup = this.props.colgroup;
84
+ if (!colgroup) return [];
85
+ var colElements = (_this$resizingCol$par = this.resizingCol.parentElement) == null ? void 0 : _this$resizingCol$par.children;
86
+ var startIndex = this.resizingIndex;
87
+ var endIndex = startIndex + this.resizingColspan - 1;
88
+ var colElementsArray = Array.from(colElements);
89
+ return colgroup.map(function (col, index) {
90
+ if (index >= startIndex && index <= endIndex) {
91
+ return colElementsArray[index].getBoundingClientRect().width || col;
92
+ }
93
+ return col;
94
+ });
95
+ };
79
96
  _proto.resizeColgroup = function resizeColgroup(deltaX) {
80
97
  var columns = this.props.columns;
81
98
  var item = columns[this.resizingIndex];
@@ -95,6 +112,51 @@ var Thead = /*#__PURE__*/function (_PureComponent) {
95
112
  w = Math.min(w, maxWidth);
96
113
  }
97
114
  this.resizingCol.style.width = w + "px";
115
+ this.newResizingWidth = w;
116
+ };
117
+ _proto.resizeMultipleColgroup = function resizeMultipleColgroup(deltaX, colspan) {
118
+ var _this$resizingCol$par2;
119
+ var columns = this.props.columns;
120
+ var siblings = (_this$resizingCol$par2 = this.resizingCol.parentElement) == null ? void 0 : _this$resizingCol$par2.children;
121
+ var startIndex = this.resizingIndex;
122
+ var endIndex = startIndex + colspan - 1;
123
+ var resizingCols = Array.from(siblings).filter(function (_, index) {
124
+ return index >= startIndex && index <= endIndex;
125
+ });
126
+ var resizingItems = columns.filter(function (_, index) {
127
+ return index >= startIndex && index <= endIndex;
128
+ });
129
+ var minWidthTotal = resizingItems.reduce(function (total, item) {
130
+ return item.minWidth ? total + (item.minWidth || 0) : 0;
131
+ }, 0);
132
+ var maxWidthTotal = resizingItems.reduce(function (total, item) {
133
+ return item.maxWidth ? total + (item.maxWidth || 0) : 0;
134
+ }, 0);
135
+ var oWidth = resizingCols.reduce(function (total, col) {
136
+ return total + parseInt(col.style.width, 10);
137
+ }, 0);
138
+ var colWidthRate = resizingCols.map(function (col) {
139
+ return col.getBoundingClientRect().width / oWidth;
140
+ });
141
+ if (Number.isNaN(oWidth) || oWidth === 0) {
142
+ oWidth = resizingCols.reduce(function (total, col) {
143
+ return total + col.getBoundingClientRect().width;
144
+ }, 0);
145
+ }
146
+ var w = oWidth + deltaX;
147
+ if ((0, _is.isNumber)(minWidthTotal) && minWidthTotal > 0) {
148
+ w = Math.max(w, minWidthTotal);
149
+ } else {
150
+ w = Math.max(w, MIN_RESIZABLE_WIDTH);
151
+ }
152
+ if ((0, _is.isNumber)(maxWidthTotal) && maxWidthTotal > 0) {
153
+ w = Math.min(w, maxWidthTotal);
154
+ }
155
+ // 将w按照它们原本的比例分配
156
+ resizingCols.forEach(function (col, index) {
157
+ col.style.width = w * colWidthRate[index] + "px";
158
+ });
159
+ this.newResizingWidth = w;
98
160
  };
99
161
  _proto.handleResize = function handleResize(type, e) {
100
162
  if (type === 'mousedown') {
@@ -116,19 +178,22 @@ var Thead = /*#__PURE__*/function (_PureComponent) {
116
178
  var x = e.clientX;
117
179
  if (typeof this.lastX === 'number') {
118
180
  var deltaX = x - this.lastX;
119
- this.resizeColgroup(deltaX);
181
+ if (this.resizingColspan > 1) {
182
+ this.resizeMultipleColgroup(deltaX, this.resizingColspan);
183
+ } else {
184
+ this.resizeColgroup(deltaX);
185
+ }
120
186
  }
121
187
  this.lastX = x;
122
188
  } else if (type === 'mouseup') {
123
- var _this$props = this.props,
124
- onColChange = _this$props.onColChange,
125
- colgroup = _this$props.colgroup;
189
+ var onColChange = this.props.onColChange;
126
190
  document.removeEventListener('mousemove', this.handleMouseMove);
127
191
  document.removeEventListener('mouseup', this.handleMouseUp);
128
192
  this.resizingTable.classList.remove((0, _styles.tableClass)('resizing'));
129
193
  this.resizingTh.classList.remove((0, _styles.tableClass)('resizing-item'));
130
194
  this.lastX = undefined;
131
- if (onColChange) onColChange(this.resizingIndex, parseInt(this.resizingCol.style.width, 10), colgroup);
195
+ var newColgroup = this.getNewColgroup();
196
+ if (onColChange) onColChange(this.resizingIndex, this.newResizingWidth, newColgroup, this.resizingColspan);
132
197
  }
133
198
  };
134
199
  _proto.createTh = function createTh(trs, col, level) {
@@ -140,15 +205,15 @@ var Thead = /*#__PURE__*/function (_PureComponent) {
140
205
  if (col.fixed) fixed.push("fixed-" + col.fixed);
141
206
  if (col.firstFixed) fixed.push('fixed-first');
142
207
  if (col.lastFixed) fixed.push('fixed-last');
143
- var _this$props2 = this.props,
144
- sorter = _this$props2.sorter,
145
- onSortChange = _this$props2.onSortChange,
146
- data = _this$props2.data,
147
- datum = _this$props2.datum,
148
- showSelectAll = _this$props2.showSelectAll,
149
- disabled = _this$props2.disabled,
150
- treeColumnsName = _this$props2.treeColumnsName,
151
- treeCheckAll = _this$props2.treeCheckAll;
208
+ var _this$props = this.props,
209
+ sorter = _this$props.sorter,
210
+ onSortChange = _this$props.onSortChange,
211
+ data = _this$props.data,
212
+ datum = _this$props.datum,
213
+ showSelectAll = _this$props.showSelectAll,
214
+ disabled = _this$props.disabled,
215
+ treeColumnsName = _this$props.treeColumnsName,
216
+ treeCheckAll = _this$props.treeCheckAll;
152
217
  var isEmpty = !(data && data.length);
153
218
  var align = colTemp.align && "align-" + colTemp.align;
154
219
  var ignoreBorderRight = this.rightBorderRecord[col.key] && 'ignore-right-border';
@@ -239,7 +304,12 @@ var Thead = /*#__PURE__*/function (_PureComponent) {
239
304
  }, tr);
240
305
  }));
241
306
  };
242
- return Thead;
307
+ return (0, _createClass2.default)(Thead, [{
308
+ key: "resizingColspan",
309
+ get: function get() {
310
+ return parseInt(this.resizingTh.getAttribute('colspan') || '', 10);
311
+ }
312
+ }]);
243
313
  }(_react.PureComponent);
244
314
  (0, _defineProperty2.default)(Thead, "defaultProps", {
245
315
  showSelectAll: true
@@ -34,6 +34,8 @@ class Thead<DataItem, Value> extends PureComponent<TheadProps<DataItem, Value>>
34
34
 
35
35
  lastX?: number
36
36
 
37
+ newResizingWidth: number
38
+
37
39
  rightBorderRecord: ObjectType<boolean>
38
40
 
39
41
  constructor(props: TheadProps<DataItem, Value>) {
@@ -81,10 +83,28 @@ class Thead<DataItem, Value> extends PureComponent<TheadProps<DataItem, Value>>
81
83
  columns: sub,
82
84
  })
83
85
  }
84
-
85
86
  return colSpan
86
87
  }
87
88
 
89
+ get resizingColspan() {
90
+ return parseInt(this.resizingTh.getAttribute('colspan') || '', 10)
91
+ }
92
+
93
+ getNewColgroup() {
94
+ const { colgroup } = this.props
95
+ if (!colgroup) return []
96
+ const colElements = this.resizingCol.parentElement?.children as HTMLCollection
97
+ const startIndex = this.resizingIndex
98
+ const endIndex = startIndex + this.resizingColspan - 1
99
+ const colElementsArray = Array.from(colElements)
100
+ return colgroup.map((col, index) => {
101
+ if (index >= startIndex && index <= endIndex) {
102
+ return colElementsArray[index].getBoundingClientRect().width || col
103
+ }
104
+ return col
105
+ })
106
+ }
107
+
88
108
  resizeColgroup(deltaX: number) {
89
109
  const { columns } = this.props
90
110
  const item = columns[this.resizingIndex]
@@ -104,6 +124,40 @@ class Thead<DataItem, Value> extends PureComponent<TheadProps<DataItem, Value>>
104
124
  w = Math.min(w, maxWidth)
105
125
  }
106
126
  this.resizingCol.style.width = `${w}px`
127
+ this.newResizingWidth = w
128
+ }
129
+
130
+ resizeMultipleColgroup(deltaX: number, colspan: number) {
131
+ const { columns } = this.props
132
+ const siblings = this.resizingCol.parentElement?.children as HTMLCollection
133
+ const startIndex = this.resizingIndex
134
+ const endIndex = startIndex + colspan - 1
135
+ const resizingCols = Array.from(siblings).filter((_, index) => index >= startIndex && index <= endIndex)
136
+ const resizingItems = columns.filter((_, index) => index >= startIndex && index <= endIndex)
137
+ const minWidthTotal = resizingItems.reduce((total, item) => (item.minWidth ? total + (item.minWidth || 0) : 0), 0)
138
+ const maxWidthTotal = resizingItems.reduce((total, item) => (item.maxWidth ? total + (item.maxWidth || 0) : 0), 0)
139
+
140
+ let oWidth = resizingCols.reduce((total, col: HTMLTableColElement) => total + parseInt(col.style.width, 10), 0)
141
+ const colWidthRate = resizingCols.map((col: HTMLTableColElement) => col.getBoundingClientRect().width / oWidth)
142
+
143
+ if (Number.isNaN(oWidth) || oWidth === 0) {
144
+ oWidth = resizingCols.reduce((total, col: HTMLTableColElement) => total + col.getBoundingClientRect().width, 0)
145
+ }
146
+ let w = oWidth + deltaX
147
+ if (isNumber(minWidthTotal) && minWidthTotal > 0) {
148
+ w = Math.max(w, minWidthTotal)
149
+ } else {
150
+ w = Math.max(w, MIN_RESIZABLE_WIDTH)
151
+ }
152
+
153
+ if (isNumber(maxWidthTotal) && maxWidthTotal > 0) {
154
+ w = Math.min(w, maxWidthTotal)
155
+ }
156
+ // 将w按照它们原本的比例分配
157
+ resizingCols.forEach((col: HTMLTableColElement, index: number) => {
158
+ col.style.width = `${w * colWidthRate[index]}px`
159
+ })
160
+ this.newResizingWidth = w
107
161
  }
108
162
 
109
163
  handleResize(type: 'mousedown' | 'mousemove' | 'mouseup', e: MouseEvent) {
@@ -129,17 +183,22 @@ class Thead<DataItem, Value> extends PureComponent<TheadProps<DataItem, Value>>
129
183
  const x = e.clientX
130
184
  if (typeof this.lastX === 'number') {
131
185
  const deltaX = x - this.lastX
132
- this.resizeColgroup(deltaX)
186
+ if (this.resizingColspan > 1) {
187
+ this.resizeMultipleColgroup(deltaX, this.resizingColspan)
188
+ } else {
189
+ this.resizeColgroup(deltaX)
190
+ }
133
191
  }
134
192
  this.lastX = x
135
193
  } else if (type === 'mouseup') {
136
- const { onColChange, colgroup } = this.props
194
+ const { onColChange } = this.props
137
195
  document.removeEventListener('mousemove', this.handleMouseMove)
138
196
  document.removeEventListener('mouseup', this.handleMouseUp)
139
197
  this.resizingTable.classList.remove(tableClass('resizing'))
140
198
  this.resizingTh.classList.remove(tableClass('resizing-item'))
141
199
  this.lastX = undefined
142
- if (onColChange) onColChange(this.resizingIndex, parseInt(this.resizingCol.style.width, 10), colgroup)
200
+ const newColgroup = this.getNewColgroup()
201
+ if (onColChange) onColChange(this.resizingIndex, this.newResizingWidth, newColgroup, this.resizingColspan)
143
202
  }
144
203
  }
145
204
 
@@ -8,7 +8,7 @@ declare const _default: <DataItem, Value, Props extends SimpleTableProps<DataIte
8
8
  new (props: GetResizeProps<Props, DataItem>): {
9
9
  componentDidUpdate(prevProps: GetResizeProps<Props, DataItem>): void;
10
10
  getWidth(): number | GetResizeProps<Props, DataItem>["width"] | undefined;
11
- handleResize(index: number, width: number, colgroup: number[]): void;
11
+ handleResize(startIndex: number, newResizingwidth: number, colgroup: number[], colspan: number): void;
12
12
  render(): JSX.Element;
13
13
  context: any;
14
14
  setState<K extends keyof ScrollState<DataItem, Value>>(state: ScrollState<DataItem, Value> | ((prevState: Readonly<ScrollState<DataItem, Value>>, props: Readonly<GetResizeProps<Props, DataItem>>) => ScrollState<DataItem, Value> | Pick<ScrollState<DataItem, Value>, K> | null) | Pick<ScrollState<DataItem, Value>, K> | null, callback?: (() => void) | undefined): void;
@@ -60,14 +60,17 @@ var _default = exports.default = function _default(Table) {
60
60
  }
61
61
  return width;
62
62
  };
63
- _proto.handleResize = function handleResize(index, width, colgroup) {
63
+ _proto.handleResize = function handleResize(startIndex, newResizingwidth, colgroup, colspan) {
64
64
  if (colgroup === undefined) return;
65
65
  var onColumnResize = this.props.onColumnResize;
66
+ var endIndex = startIndex + colspan - 1;
67
+ var oldRsizingColsWidth = colgroup.filter(function (_, i) {
68
+ return i >= startIndex && i <= endIndex;
69
+ }).reduce(function (sum, w) {
70
+ return sum + w;
71
+ }, 0);
66
72
  var changed = (0, _immer.default)(this.state, function (draft) {
67
- var column = draft.columns[index];
68
- // @ts-ignore
69
- draft.delta += parseFloat(width - (column.width || colgroup[index] || 0));
70
- colgroup[index] = width;
73
+ draft.delta += newResizingwidth - oldRsizingColsWidth;
71
74
  draft.columns.forEach(function (col, i) {
72
75
  var w = colgroup[i];
73
76
  if (w) col.width = w;
@@ -49,14 +49,17 @@ export default <DataItem, Value, Props extends SimpleTableProps<DataItem, Value>
49
49
  return width
50
50
  }
51
51
 
52
- handleResize(index: number, width: number, colgroup: number[]) {
52
+ handleResize(startIndex: number, newResizingwidth: number, colgroup: number[], colspan: number) {
53
53
  if (colgroup === undefined) return
54
54
  const { onColumnResize } = this.props
55
+ const endIndex = startIndex + colspan - 1
56
+ const oldRsizingColsWidth = colgroup
57
+ .filter((_, i) => i >= startIndex && i <= endIndex)
58
+ .reduce((sum, w) => sum + w, 0)
59
+
55
60
  const changed = immer(this.state, draft => {
56
- const column = draft.columns[index]
57
- // @ts-ignore
58
- draft.delta += parseFloat(width - (column.width || colgroup[index] || 0))
59
- colgroup[index] = width
61
+ draft.delta += newResizingwidth - oldRsizingColsWidth
62
+
60
63
  draft.columns.forEach((col, i) => {
61
64
  const w = colgroup[i]
62
65
  if (w) col.width = w
@@ -73,6 +76,6 @@ export default <DataItem, Value, Props extends SimpleTableProps<DataItem, Value>
73
76
  const { columns } = this.state
74
77
  const { onColumnResize, ...other } = this.props
75
78
  const width = this.getWidth()
76
- return <Table {...other as Props} width={width} columns={columns} onResize={this.handleResize} />
79
+ return <Table {...(other as Props)} width={width} columns={columns} onResize={this.handleResize} />
77
80
  }
78
81
  }
package/css/index.js CHANGED
@@ -115,5 +115,5 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
115
115
  // Created by scripts/src-index.js.
116
116
  var _default = exports.default = {
117
117
  utils: utils,
118
- version: '2.0.23'
118
+ version: '2.0.24'
119
119
  };