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.
- package/css/Table/Props.d.ts +1 -1
- package/css/Table/Props.ts +1 -1
- package/css/Table/SimpleTable.js +3 -0
- package/css/Table/SimpleTable.tsx +7 -1
- package/css/Table/Thead.d.ts +4 -0
- package/css/Table/Thead.js +85 -15
- package/css/Table/Thead.tsx +63 -4
- package/css/Table/resizable.d.ts +1 -1
- package/css/Table/resizable.js +8 -5
- package/css/Table/resizable.tsx +9 -6
- package/css/index.js +1 -1
- package/dist/shineout.js +3262 -1625
- package/dist/shineout.js.map +1 -1
- package/dist/shineout.min.js +1 -1
- package/dist/shineout.min.js.map +1 -1
- package/es/Table/Props.d.ts +1 -1
- package/es/Table/Props.ts +1 -1
- package/es/Table/SimpleTable.js +3 -0
- package/es/Table/SimpleTable.tsx +7 -1
- package/es/Table/Thead.d.ts +4 -0
- package/es/Table/Thead.js +85 -15
- package/es/Table/Thead.tsx +63 -4
- package/es/Table/resizable.d.ts +1 -1
- package/es/Table/resizable.js +8 -5
- package/es/Table/resizable.tsx +9 -6
- package/es/index.js +1 -1
- package/lib/Table/Props.d.ts +1 -1
- package/lib/Table/Props.ts +1 -1
- package/lib/Table/SimpleTable.js +3 -0
- package/lib/Table/SimpleTable.tsx +7 -1
- package/lib/Table/Thead.d.ts +4 -0
- package/lib/Table/Thead.js +85 -15
- package/lib/Table/Thead.tsx +63 -4
- package/lib/Table/resizable.d.ts +1 -1
- package/lib/Table/resizable.js +8 -5
- package/lib/Table/resizable.tsx +9 -6
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/Table/Thead.tsx
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
-
|
|
200
|
+
const newColgroup = this.getNewColgroup()
|
|
201
|
+
if (onColChange) onColChange(this.resizingIndex, this.newResizingWidth, newColgroup, this.resizingColspan)
|
|
143
202
|
}
|
|
144
203
|
}
|
|
145
204
|
|
package/lib/Table/resizable.d.ts
CHANGED
|
@@ -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(
|
|
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;
|
package/lib/Table/resizable.js
CHANGED
|
@@ -60,14 +60,17 @@ var _default = exports.default = function _default(Table) {
|
|
|
60
60
|
}
|
|
61
61
|
return width;
|
|
62
62
|
};
|
|
63
|
-
_proto.handleResize = function handleResize(
|
|
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
|
-
|
|
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;
|
package/lib/Table/resizable.tsx
CHANGED
|
@@ -49,14 +49,17 @@ export default <DataItem, Value, Props extends SimpleTableProps<DataItem, Value>
|
|
|
49
49
|
return width
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
handleResize(
|
|
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
|
-
|
|
57
|
-
|
|
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