@gmfe/table-x 2.14.17 → 2.14.20

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.
Files changed (44) hide show
  1. package/README.md +13 -13
  2. package/package.json +4 -4
  3. package/src/base/index.js +142 -142
  4. package/src/base/td.js +56 -56
  5. package/src/base/th.js +48 -48
  6. package/src/base/thead.js +26 -26
  7. package/src/base/tr.js +53 -53
  8. package/src/base/virtualized.js +219 -219
  9. package/src/hoc/diy_table_x/components/diy_table_x_modal.js +135 -135
  10. package/src/hoc/diy_table_x/components/modal_list.js +78 -78
  11. package/src/hoc/diy_table_x/components/modal_selector.js +56 -56
  12. package/src/hoc/diy_table_x/index.js +196 -196
  13. package/src/hoc/edit_table_x.js +20 -20
  14. package/src/hoc/expand_table_x/index.js +140 -140
  15. package/src/hoc/expand_table_x/util.js +27 -27
  16. package/src/hoc/fixed_columns_table_x.js +29 -29
  17. package/src/hoc/select_table_x/cell.js +51 -51
  18. package/src/hoc/select_table_x/header.js +28 -28
  19. package/src/hoc/select_table_x/index.js +139 -139
  20. package/src/hoc/select_table_x/util.js +10 -10
  21. package/src/hoc/sortable_table_x.js +52 -52
  22. package/src/hoc/sub_table_x.js +44 -44
  23. package/src/index.js +53 -53
  24. package/src/index.less +515 -515
  25. package/src/stories/table_x.stories.js +324 -324
  26. package/src/stories/table_x_hoc.stories.js +427 -427
  27. package/src/stories/table_x_hoc_select_expand.stories.js +256 -256
  28. package/src/util/batch_action_bar.js +124 -124
  29. package/src/util/edit.js +83 -83
  30. package/src/util/index.js +191 -191
  31. package/src/util/operation.js +249 -249
  32. package/src/util/sort_header.js +49 -49
  33. package/src/variables.less +28 -28
  34. package/svg/business.svg +20 -20
  35. package/svg/check-detail.svg +18 -18
  36. package/svg/closeup.svg +20 -20
  37. package/svg/delete.svg +10 -10
  38. package/svg/edit-pen.svg +17 -17
  39. package/svg/empty.svg +27 -27
  40. package/svg/expand.svg +21 -21
  41. package/svg/pen.svg +12 -12
  42. package/svg/recover.svg +33 -33
  43. package/svg/remove.svg +1 -1
  44. package/svg/setting.svg +17 -17
package/src/base/tr.js CHANGED
@@ -1,53 +1,53 @@
1
- import classNames from 'classnames'
2
- import PropTypes from 'prop-types'
3
- import React from 'react'
4
- import Td from './td'
5
-
6
- const Tr = ({
7
- row,
8
- SubComponent,
9
- keyField,
10
- style,
11
- totalWidth,
12
- isTrDisable,
13
- isTrHighlight,
14
- }) => {
15
- const props = {
16
- ...row.getRowProps(),
17
- style,
18
- className: classNames('gm-table-x-tr', {
19
- 'gm-table-x-tr-disable': isTrDisable(row.original, row.index),
20
- 'gm-table-x-tr-highlight': isTrHighlight(row.original, row.index),
21
- 'gm-table-x-tr-odd': row.index % 2 === 0,
22
- 'gm-table-x-tr-even': row.index % 2 !== 0
23
- })
24
- }
25
-
26
- // 目前视为了 sortable 用。值可能是 undefined,keyField 没作用的情况
27
- const dataId = row.original[keyField]
28
-
29
- return (
30
- <>
31
- <tr data-id={dataId} {...props}>
32
- {row.cells.map((cell, cellIndex) => (
33
- <Td key={cellIndex} cell={cell} totalWidth={totalWidth} />
34
- ))}
35
- </tr>
36
- {SubComponent && SubComponent(row)}
37
- </>
38
- )
39
- }
40
-
41
- Tr.whyDidYouRender = true
42
-
43
- Tr.propTypes = {
44
- row: PropTypes.object.isRequired,
45
- SubComponent: PropTypes.func,
46
- keyField: PropTypes.string.isRequired,
47
- style: PropTypes.object.isRequired,
48
- totalWidth: PropTypes.number.isRequired,
49
- isTrDisable: PropTypes.func,
50
- isTrHighlight: PropTypes.func
51
- }
52
-
53
- export default React.memo(Tr)
1
+ import classNames from 'classnames'
2
+ import PropTypes from 'prop-types'
3
+ import React from 'react'
4
+ import Td from './td'
5
+
6
+ const Tr = ({
7
+ row,
8
+ SubComponent,
9
+ keyField,
10
+ style,
11
+ totalWidth,
12
+ isTrDisable,
13
+ isTrHighlight,
14
+ }) => {
15
+ const props = {
16
+ ...row.getRowProps(),
17
+ style,
18
+ className: classNames('gm-table-x-tr', {
19
+ 'gm-table-x-tr-disable': isTrDisable(row.original, row.index),
20
+ 'gm-table-x-tr-highlight': isTrHighlight(row.original, row.index),
21
+ 'gm-table-x-tr-odd': row.index % 2 === 0,
22
+ 'gm-table-x-tr-even': row.index % 2 !== 0
23
+ })
24
+ }
25
+
26
+ // 目前视为了 sortable 用。值可能是 undefined,keyField 没作用的情况
27
+ const dataId = row.original[keyField]
28
+
29
+ return (
30
+ <>
31
+ <tr data-id={dataId} {...props}>
32
+ {row.cells.map((cell, cellIndex) => (
33
+ <Td key={cellIndex} cell={cell} totalWidth={totalWidth} />
34
+ ))}
35
+ </tr>
36
+ {SubComponent && SubComponent(row)}
37
+ </>
38
+ )
39
+ }
40
+
41
+ Tr.whyDidYouRender = true
42
+
43
+ Tr.propTypes = {
44
+ row: PropTypes.object.isRequired,
45
+ SubComponent: PropTypes.func,
46
+ keyField: PropTypes.string.isRequired,
47
+ style: PropTypes.object.isRequired,
48
+ totalWidth: PropTypes.number.isRequired,
49
+ isTrDisable: PropTypes.func,
50
+ isTrHighlight: PropTypes.func
51
+ }
52
+
53
+ export default React.memo(Tr)
@@ -1,219 +1,219 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
- import { useTable } from 'react-table'
4
- import { Empty, Loading, afterScroll, __DEFAULT_COLUMN, TABLE_X } from '../util'
5
- import classNames from 'classnames'
6
- import _ from 'lodash'
7
- import THead from './thead'
8
- import Tr from './tr'
9
- import { VariableSizeList, areEqual } from 'react-window'
10
-
11
- // 见
12
- // https://react-window.now.sh/#/api/FixedSizeList innerElementType
13
- // https://react-window.now.sh/#/examples/list/memoized-list-items
14
-
15
- const RenderRow = React.memo(({ data, index, style }) => {
16
- if (index === 0) {
17
- return <div style={style} />
18
- }
19
-
20
- index = index - 1
21
-
22
- const {
23
- prepareRow,
24
- rows,
25
- SubComponent,
26
- keyField,
27
- totalWidth,
28
- isTrDisable,
29
- isTrHighlight
30
- } = data
31
-
32
- const row = rows[index]
33
- prepareRow(row)
34
-
35
- return (
36
- <Tr
37
- key={row.index}
38
- row={row}
39
- SubComponent={SubComponent}
40
- keyField={keyField}
41
- style={style}
42
- totalWidth={totalWidth}
43
- isTrDisable={isTrDisable}
44
- isTrHighlight={isTrHighlight}
45
- />
46
- )
47
- }, areEqual)
48
-
49
- RenderRow.propTypes = {
50
- data: PropTypes.object.isRequired,
51
- index: PropTypes.number.isRequired,
52
- style: PropTypes.object.isRequired
53
- }
54
-
55
- // 给定初始值,交由getColumnStyle控制。width逻辑保持跟react-table(v6)的用法一致。
56
- const defaultColumn = __DEFAULT_COLUMN
57
-
58
- const TableXVirtualized = ({
59
- columns,
60
- data,
61
- loading,
62
- SubComponent,
63
- keyField,
64
- className,
65
- tiled,
66
- onScroll,
67
- isTrDisable,
68
- isTrHighlight,
69
-
70
- virtualizedHeight,
71
- virtualizedItemSize,
72
- refVirtualized,
73
-
74
- ...rest
75
- }) => {
76
- // diy fixed(最新rc12不支持column.show,自己实现)
77
- columns = React.useMemo(() => columns.filter(c => c.show !== false), [
78
- columns
79
- ])
80
-
81
- const {
82
- getTableProps,
83
- headerGroups,
84
- getTableBodyProps,
85
- rows,
86
- prepareRow
87
- } = useTable({
88
- columns,
89
- data,
90
- defaultColumn
91
- })
92
-
93
- let totalWidth = 0
94
- if (rows[0] && rows[0].cells.length > 0) {
95
- prepareRow(rows[0])
96
- const last = rows[0].cells[rows[0].cells.length - 1].column
97
- totalWidth = last.totalLeft + last.totalWidth
98
- }
99
-
100
- const gtp = getTableProps()
101
- const tableProps = {
102
- ...gtp,
103
- className: classNames('gm-table-x-table', gtp.className)
104
- }
105
-
106
- const gtbp = getTableBodyProps()
107
- const tableBodyProps = {
108
- ...gtbp,
109
- className: 'gm-table-x-tbody'
110
- }
111
-
112
- const handleScroll = e => {
113
- onScroll && onScroll(e)
114
- afterScroll()
115
- }
116
-
117
- // 必须响应 columns totalWidth!!!
118
- const Container = React.useMemo(() => {
119
- return React.forwardRef(({ children, style, ...rest }, ref) => {
120
- return (
121
- <table
122
- ref={ref}
123
- {...rest}
124
- {...tableProps}
125
- style={{ ...style, minWidth: totalWidth + 'px' }}
126
- >
127
- <THead headerGroups={headerGroups} totalWidth={totalWidth} />
128
- <tbody {...tableBodyProps}>{children}</tbody>
129
- </table>
130
- )
131
- })
132
- }, [columns, totalWidth])
133
-
134
- const itemSize = index => {
135
- if (index === 0) {
136
- return TABLE_X.HEIGHT_HEAD_TR
137
- }
138
-
139
- if (_.isFunction(virtualizedItemSize)) {
140
- return virtualizedItemSize(index - 1)
141
- }
142
-
143
- return virtualizedItemSize
144
- }
145
-
146
- const itemData = {
147
- rows,
148
- prepareRow,
149
- SubComponent,
150
- keyField,
151
- totalWidth,
152
- isTrDisable,
153
- isTrHighlight
154
- }
155
-
156
- return (
157
- <div
158
- {...rest}
159
- className={classNames(
160
- 'gm-table-x',
161
- {
162
- 'gm-table-x-empty': data.length === 0,
163
- 'gm-table-x-tiled': tiled
164
- },
165
- className
166
- )}
167
- onScroll={handleScroll}
168
- >
169
- <VariableSizeList
170
- ref={refVirtualized}
171
- height={virtualizedHeight}
172
- itemCount={rows.length + 1}
173
- itemData={itemData}
174
- itemSize={itemSize}
175
- innerElementType={Container}
176
- className='gm-table-x-virtualized'
177
- >
178
- {RenderRow}
179
- </VariableSizeList>
180
- {loading && <Loading />}
181
- {!loading && data.length === 0 && <Empty />}
182
- </div>
183
- )
184
- }
185
-
186
- TableXVirtualized.propTypes = {
187
- columns: PropTypes.array.isRequired,
188
- data: PropTypes.array.isRequired,
189
- loading: PropTypes.bool,
190
- SubComponent: PropTypes.func,
191
- /** 由其他 hoc 传下来 */
192
- keyField: PropTypes.string,
193
- /** table是否平铺 */
194
- tiled: PropTypes.bool,
195
- /** 当前行是否disable */
196
- isTrDisable: PropTypes.func,
197
- /** 当前行是否高亮 */
198
- isTrHighlight: PropTypes.func,
199
- onScroll: PropTypes.func,
200
- className: PropTypes.string,
201
- style: PropTypes.object,
202
-
203
- // 虚拟列表相关
204
- /** 需要提供 table 的高度 */
205
- virtualizedHeight: PropTypes.number.isRequired,
206
- /** 行的高度 */
207
- virtualizedItemSize: PropTypes.oneOfType([PropTypes.number, PropTypes.func])
208
- .isRequired,
209
- refVirtualized: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
210
- }
211
-
212
- TableXVirtualized.defaultProps = {
213
- keyField: 'value',
214
- tiled: false,
215
- isTrDisable: () => false,
216
- isTrHighlight: () => false
217
- }
218
-
219
- export default TableXVirtualized
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import { useTable } from 'react-table'
4
+ import { Empty, Loading, afterScroll, __DEFAULT_COLUMN, TABLE_X } from '../util'
5
+ import classNames from 'classnames'
6
+ import _ from 'lodash'
7
+ import THead from './thead'
8
+ import Tr from './tr'
9
+ import { VariableSizeList, areEqual } from 'react-window'
10
+
11
+ // 见
12
+ // https://react-window.now.sh/#/api/FixedSizeList innerElementType
13
+ // https://react-window.now.sh/#/examples/list/memoized-list-items
14
+
15
+ const RenderRow = React.memo(({ data, index, style }) => {
16
+ if (index === 0) {
17
+ return <div style={style} />
18
+ }
19
+
20
+ index = index - 1
21
+
22
+ const {
23
+ prepareRow,
24
+ rows,
25
+ SubComponent,
26
+ keyField,
27
+ totalWidth,
28
+ isTrDisable,
29
+ isTrHighlight
30
+ } = data
31
+
32
+ const row = rows[index]
33
+ prepareRow(row)
34
+
35
+ return (
36
+ <Tr
37
+ key={row.index}
38
+ row={row}
39
+ SubComponent={SubComponent}
40
+ keyField={keyField}
41
+ style={style}
42
+ totalWidth={totalWidth}
43
+ isTrDisable={isTrDisable}
44
+ isTrHighlight={isTrHighlight}
45
+ />
46
+ )
47
+ }, areEqual)
48
+
49
+ RenderRow.propTypes = {
50
+ data: PropTypes.object.isRequired,
51
+ index: PropTypes.number.isRequired,
52
+ style: PropTypes.object.isRequired
53
+ }
54
+
55
+ // 给定初始值,交由getColumnStyle控制。width逻辑保持跟react-table(v6)的用法一致。
56
+ const defaultColumn = __DEFAULT_COLUMN
57
+
58
+ const TableXVirtualized = ({
59
+ columns,
60
+ data,
61
+ loading,
62
+ SubComponent,
63
+ keyField,
64
+ className,
65
+ tiled,
66
+ onScroll,
67
+ isTrDisable,
68
+ isTrHighlight,
69
+
70
+ virtualizedHeight,
71
+ virtualizedItemSize,
72
+ refVirtualized,
73
+
74
+ ...rest
75
+ }) => {
76
+ // diy fixed(最新rc12不支持column.show,自己实现)
77
+ columns = React.useMemo(() => columns.filter(c => c.show !== false), [
78
+ columns
79
+ ])
80
+
81
+ const {
82
+ getTableProps,
83
+ headerGroups,
84
+ getTableBodyProps,
85
+ rows,
86
+ prepareRow
87
+ } = useTable({
88
+ columns,
89
+ data,
90
+ defaultColumn
91
+ })
92
+
93
+ let totalWidth = 0
94
+ if (rows[0] && rows[0].cells.length > 0) {
95
+ prepareRow(rows[0])
96
+ const last = rows[0].cells[rows[0].cells.length - 1].column
97
+ totalWidth = last.totalLeft + last.totalWidth
98
+ }
99
+
100
+ const gtp = getTableProps()
101
+ const tableProps = {
102
+ ...gtp,
103
+ className: classNames('gm-table-x-table', gtp.className)
104
+ }
105
+
106
+ const gtbp = getTableBodyProps()
107
+ const tableBodyProps = {
108
+ ...gtbp,
109
+ className: 'gm-table-x-tbody'
110
+ }
111
+
112
+ const handleScroll = e => {
113
+ onScroll && onScroll(e)
114
+ afterScroll()
115
+ }
116
+
117
+ // 必须响应 columns totalWidth!!!
118
+ const Container = React.useMemo(() => {
119
+ return React.forwardRef(({ children, style, ...rest }, ref) => {
120
+ return (
121
+ <table
122
+ ref={ref}
123
+ {...rest}
124
+ {...tableProps}
125
+ style={{ ...style, minWidth: totalWidth + 'px' }}
126
+ >
127
+ <THead headerGroups={headerGroups} totalWidth={totalWidth} />
128
+ <tbody {...tableBodyProps}>{children}</tbody>
129
+ </table>
130
+ )
131
+ })
132
+ }, [columns, totalWidth])
133
+
134
+ const itemSize = index => {
135
+ if (index === 0) {
136
+ return TABLE_X.HEIGHT_HEAD_TR
137
+ }
138
+
139
+ if (_.isFunction(virtualizedItemSize)) {
140
+ return virtualizedItemSize(index - 1)
141
+ }
142
+
143
+ return virtualizedItemSize
144
+ }
145
+
146
+ const itemData = {
147
+ rows,
148
+ prepareRow,
149
+ SubComponent,
150
+ keyField,
151
+ totalWidth,
152
+ isTrDisable,
153
+ isTrHighlight
154
+ }
155
+
156
+ return (
157
+ <div
158
+ {...rest}
159
+ className={classNames(
160
+ 'gm-table-x',
161
+ {
162
+ 'gm-table-x-empty': data.length === 0,
163
+ 'gm-table-x-tiled': tiled
164
+ },
165
+ className
166
+ )}
167
+ onScroll={handleScroll}
168
+ >
169
+ <VariableSizeList
170
+ ref={refVirtualized}
171
+ height={virtualizedHeight}
172
+ itemCount={rows.length + 1}
173
+ itemData={itemData}
174
+ itemSize={itemSize}
175
+ innerElementType={Container}
176
+ className='gm-table-x-virtualized'
177
+ >
178
+ {RenderRow}
179
+ </VariableSizeList>
180
+ {loading && <Loading />}
181
+ {!loading && data.length === 0 && <Empty />}
182
+ </div>
183
+ )
184
+ }
185
+
186
+ TableXVirtualized.propTypes = {
187
+ columns: PropTypes.array.isRequired,
188
+ data: PropTypes.array.isRequired,
189
+ loading: PropTypes.bool,
190
+ SubComponent: PropTypes.func,
191
+ /** 由其他 hoc 传下来 */
192
+ keyField: PropTypes.string,
193
+ /** table是否平铺 */
194
+ tiled: PropTypes.bool,
195
+ /** 当前行是否disable */
196
+ isTrDisable: PropTypes.func,
197
+ /** 当前行是否高亮 */
198
+ isTrHighlight: PropTypes.func,
199
+ onScroll: PropTypes.func,
200
+ className: PropTypes.string,
201
+ style: PropTypes.object,
202
+
203
+ // 虚拟列表相关
204
+ /** 需要提供 table 的高度 */
205
+ virtualizedHeight: PropTypes.number.isRequired,
206
+ /** 行的高度 */
207
+ virtualizedItemSize: PropTypes.oneOfType([PropTypes.number, PropTypes.func])
208
+ .isRequired,
209
+ refVirtualized: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
210
+ }
211
+
212
+ TableXVirtualized.defaultProps = {
213
+ keyField: 'value',
214
+ tiled: false,
215
+ isTrDisable: () => false,
216
+ isTrHighlight: () => false
217
+ }
218
+
219
+ export default TableXVirtualized