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.
@@ -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/lib/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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shineout",
3
- "version": "2.0.23",
3
+ "version": "2.0.24",
4
4
  "description": "Shein 前端组件库",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",