@gmfe/table-x 2.14.15 → 2.14.19-beta.0

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/util/index.js CHANGED
@@ -1,191 +1,191 @@
1
- import React from 'react'
2
- import { getLocale } from '@gmfe/locales'
3
- import classNames from 'classnames'
4
- import PropTypes from 'prop-types'
5
- import _ from 'lodash'
6
- import SVGEmpty from '../../svg/empty.svg'
7
- import { Flex, EVENT_TYPE } from '@gmfe/react'
8
- import BatchActionBar from './batch_action_bar'
9
- import SortHeader from './sort_header'
10
- import {
11
- OperationHeader,
12
- OperationDelete,
13
- OperationRecover,
14
- OperationDetail,
15
- OperationCell,
16
- OperationRowEdit,
17
- OperationIconTip
18
- } from './operation'
19
- import { EditButton, EditOperation } from './edit'
20
-
21
- const TABLE_X_SELECT_ID = 'table_x_select_id'
22
- const TABLE_X_EXPAND_ID = 'table_x_expand_id'
23
- const TABLE_X_DIY_ID = 'table_x_diy_id'
24
- const TABLE_X_SUB_TABLE_ID = 'table_x_sub_table_id'
25
- const TABLE_X = {
26
- HEIGHT_HEAD_TR: 46,
27
- HEIGHT_TR: 60,
28
- WIDTH_FUN: 40,
29
- // 序号
30
- WIDTH_NO: 56,
31
- // 操作区
32
- WIDTH_OPERATION: 100,
33
- // MoreSelect 类似
34
- WIDTH_SEARCH: 168,
35
- // number input
36
- WIDTH_NUMBER: 80,
37
- // Select
38
- WIDTH_SELECT: 148,
39
- // DatePicker
40
- WIDTH_DATE: 110
41
- }
42
-
43
- // 私有。这些默认值都不会被tableX真正使用到,所以就这么定义了。
44
- const __DEFAULT_COLUMN = {
45
- minWidth: 7.77,
46
- width: 17.77,
47
- maxWidth: 1777.77
48
- }
49
-
50
- const Mask = ({ style, children }) => {
51
- return (
52
- <Flex
53
- column
54
- alignCenter
55
- justifyCenter
56
- style={{
57
- position: 'absolute',
58
- top: 0,
59
- bottom: 0,
60
- left: 0,
61
- right: 0,
62
- marginTop: '46px',
63
- ...style
64
- }}
65
- >
66
- {children}
67
- </Flex>
68
- )
69
- }
70
-
71
- Mask.propTypes = {
72
- style: PropTypes.object
73
- }
74
-
75
- const Empty = () => {
76
- return (
77
- <Mask>
78
- <div style={{ padding: '10px' }}>
79
- <SVGEmpty style={{ width: '70px', height: '70px' }} />
80
- <div className='gm-text-desc'>{getLocale('没有数据了')}</div>
81
- </div>
82
- </Mask>
83
- )
84
- }
85
-
86
- const Loading = () => {
87
- return (
88
- <Mask
89
- style={{
90
- backgroundColor: 'rgba(255,255,255,0.8)'
91
- }}
92
- >
93
- {getLocale('加载数据中...')}
94
- </Mask>
95
- )
96
- }
97
-
98
- const Resizer = props => (
99
- <div
100
- {...props}
101
- className={classNames('gm-table-x-resizer', props.className)}
102
- />
103
- )
104
-
105
- Resizer.propTypes = {
106
- className: PropTypes.string
107
- }
108
-
109
- const CellEmpty = () => <span className='gm-text-desc'>-</span>
110
-
111
- const asPx = value => {
112
- value = Number(value)
113
- return Number.isNaN(value) ? null : `${value}px`
114
- }
115
-
116
- const getFirstDefined = (a, b) => {
117
- // 如果取的是默认值
118
- if (
119
- a === __DEFAULT_COLUMN.width &&
120
- (b === __DEFAULT_COLUMN.minWidth || b === __DEFAULT_COLUMN.maxWidth)
121
- ) {
122
- return undefined
123
- } else if (a !== __DEFAULT_COLUMN.width) {
124
- return a
125
- } else {
126
- return b
127
- }
128
- }
129
-
130
- // width 200 =>👉 flex: 200 0 auto; width: 200px; max-width: 200px;
131
- // maxWidth 300 =>👉 max-width: 300px;
132
- // minWidth 200 =>👉 flex: 200 0 auto; width: 200px;
133
- // minWidth 50 width 100 =>👉 flex: 100 0 auto; width: 100px; max-width: 100px;
134
- const getColumnStyle = ({ width, minWidth, maxWidth }) => {
135
- const _width = getFirstDefined(width, minWidth)
136
- const _maxWidth = getFirstDefined(width, maxWidth)
137
- return {
138
- flex: `${_width} 0 auto`,
139
- width: asPx(_width),
140
- maxWidth: asPx(_maxWidth)
141
- }
142
- }
143
-
144
- const afterScroll = () => {
145
- window.dispatchEvent(new window.CustomEvent(EVENT_TYPE.TABLE_SCROLL))
146
- }
147
-
148
- function getColumnKey(column) {
149
- // 如果是字符串就取 accessor
150
- if (_.isString(column.accessor)) {
151
- return column.accessor
152
- }
153
- // 如果 accessor 是函数,则一定会提供 id,否则 react-table 会报错
154
- else if (_.isFunction(column.accessor) && column.id) {
155
- return column.id
156
- }
157
- // 额外的情况,有些时候只有id,比如 diy 存储就只存了 id,因为 函数没法存储
158
- else if (column.id) {
159
- return column.id
160
- }
161
-
162
- // 其他情况没法获得 key
163
- return null
164
- }
165
-
166
- export {
167
- TABLE_X,
168
- TABLE_X_SELECT_ID,
169
- TABLE_X_EXPAND_ID,
170
- TABLE_X_DIY_ID,
171
- TABLE_X_SUB_TABLE_ID,
172
- __DEFAULT_COLUMN,
173
- Empty,
174
- Loading,
175
- SortHeader,
176
- Resizer,
177
- CellEmpty,
178
- OperationHeader,
179
- OperationDelete,
180
- OperationRecover,
181
- OperationDetail,
182
- OperationCell,
183
- OperationRowEdit,
184
- OperationIconTip,
185
- EditButton,
186
- EditOperation,
187
- BatchActionBar,
188
- getColumnStyle,
189
- afterScroll,
190
- getColumnKey
191
- }
1
+ import React from 'react'
2
+ import { getLocale } from '@gmfe/locales'
3
+ import classNames from 'classnames'
4
+ import PropTypes from 'prop-types'
5
+ import _ from 'lodash'
6
+ import SVGEmpty from '../../svg/empty.svg'
7
+ import { Flex, EVENT_TYPE } from '@gmfe/react'
8
+ import BatchActionBar from './batch_action_bar'
9
+ import SortHeader from './sort_header'
10
+ import {
11
+ OperationHeader,
12
+ OperationDelete,
13
+ OperationRecover,
14
+ OperationDetail,
15
+ OperationCell,
16
+ OperationRowEdit,
17
+ OperationIconTip
18
+ } from './operation'
19
+ import { EditButton, EditOperation } from './edit'
20
+
21
+ const TABLE_X_SELECT_ID = 'table_x_select_id'
22
+ const TABLE_X_EXPAND_ID = 'table_x_expand_id'
23
+ const TABLE_X_DIY_ID = 'table_x_diy_id'
24
+ const TABLE_X_SUB_TABLE_ID = 'table_x_sub_table_id'
25
+ const TABLE_X = {
26
+ HEIGHT_HEAD_TR: 46,
27
+ HEIGHT_TR: 60,
28
+ WIDTH_FUN: 40,
29
+ // 序号
30
+ WIDTH_NO: 56,
31
+ // 操作区
32
+ WIDTH_OPERATION: 100,
33
+ // MoreSelect 类似
34
+ WIDTH_SEARCH: 168,
35
+ // number input
36
+ WIDTH_NUMBER: 80,
37
+ // Select
38
+ WIDTH_SELECT: 148,
39
+ // DatePicker
40
+ WIDTH_DATE: 110
41
+ }
42
+
43
+ // 私有。这些默认值都不会被tableX真正使用到,所以就这么定义了。
44
+ const __DEFAULT_COLUMN = {
45
+ minWidth: 7.77,
46
+ width: 17.77,
47
+ maxWidth: 1777.77
48
+ }
49
+
50
+ const Mask = ({ style, children }) => {
51
+ return (
52
+ <Flex
53
+ column
54
+ alignCenter
55
+ justifyCenter
56
+ style={{
57
+ position: 'absolute',
58
+ top: 0,
59
+ bottom: 0,
60
+ left: 0,
61
+ right: 0,
62
+ marginTop: '46px',
63
+ ...style
64
+ }}
65
+ >
66
+ {children}
67
+ </Flex>
68
+ )
69
+ }
70
+
71
+ Mask.propTypes = {
72
+ style: PropTypes.object
73
+ }
74
+
75
+ const Empty = () => {
76
+ return (
77
+ <Mask>
78
+ <div style={{ padding: '10px' }}>
79
+ <SVGEmpty style={{ width: '70px', height: '70px' }} />
80
+ <div className='gm-text-desc'>{getLocale('没有数据了')}</div>
81
+ </div>
82
+ </Mask>
83
+ )
84
+ }
85
+
86
+ const Loading = () => {
87
+ return (
88
+ <Mask
89
+ style={{
90
+ backgroundColor: 'rgba(255,255,255,0.8)'
91
+ }}
92
+ >
93
+ {getLocale('加载数据中...')}
94
+ </Mask>
95
+ )
96
+ }
97
+
98
+ const Resizer = props => (
99
+ <div
100
+ {...props}
101
+ className={classNames('gm-table-x-resizer', props.className)}
102
+ />
103
+ )
104
+
105
+ Resizer.propTypes = {
106
+ className: PropTypes.string
107
+ }
108
+
109
+ const CellEmpty = () => <span className='gm-text-desc'>-</span>
110
+
111
+ const asPx = value => {
112
+ value = Number(value)
113
+ return Number.isNaN(value) ? null : `${value}px`
114
+ }
115
+
116
+ const getFirstDefined = (a, b) => {
117
+ // 如果取的是默认值
118
+ if (
119
+ a === __DEFAULT_COLUMN.width &&
120
+ (b === __DEFAULT_COLUMN.minWidth || b === __DEFAULT_COLUMN.maxWidth)
121
+ ) {
122
+ return undefined
123
+ } else if (a !== __DEFAULT_COLUMN.width) {
124
+ return a
125
+ } else {
126
+ return b
127
+ }
128
+ }
129
+
130
+ // width 200 =>👉 flex: 200 0 auto; width: 200px; max-width: 200px;
131
+ // maxWidth 300 =>👉 max-width: 300px;
132
+ // minWidth 200 =>👉 flex: 200 0 auto; width: 200px;
133
+ // minWidth 50 width 100 =>👉 flex: 100 0 auto; width: 100px; max-width: 100px;
134
+ const getColumnStyle = ({ width, minWidth, maxWidth }) => {
135
+ const _width = getFirstDefined(width, minWidth)
136
+ const _maxWidth = getFirstDefined(width, maxWidth)
137
+ return {
138
+ flex: `${_width} 0 auto`,
139
+ width: asPx(_width),
140
+ maxWidth: asPx(_maxWidth)
141
+ }
142
+ }
143
+
144
+ const afterScroll = () => {
145
+ window.dispatchEvent(new window.CustomEvent(EVENT_TYPE.TABLE_SCROLL))
146
+ }
147
+
148
+ function getColumnKey(column) {
149
+ // 如果是字符串就取 accessor
150
+ if (_.isString(column.accessor)) {
151
+ return column.accessor
152
+ }
153
+ // 如果 accessor 是函数,则一定会提供 id,否则 react-table 会报错
154
+ else if (_.isFunction(column.accessor) && column.id) {
155
+ return column.id
156
+ }
157
+ // 额外的情况,有些时候只有id,比如 diy 存储就只存了 id,因为 函数没法存储
158
+ else if (column.id) {
159
+ return column.id
160
+ }
161
+
162
+ // 其他情况没法获得 key
163
+ return null
164
+ }
165
+
166
+ export {
167
+ TABLE_X,
168
+ TABLE_X_SELECT_ID,
169
+ TABLE_X_EXPAND_ID,
170
+ TABLE_X_DIY_ID,
171
+ TABLE_X_SUB_TABLE_ID,
172
+ __DEFAULT_COLUMN,
173
+ Empty,
174
+ Loading,
175
+ SortHeader,
176
+ Resizer,
177
+ CellEmpty,
178
+ OperationHeader,
179
+ OperationDelete,
180
+ OperationRecover,
181
+ OperationDetail,
182
+ OperationCell,
183
+ OperationRowEdit,
184
+ OperationIconTip,
185
+ EditButton,
186
+ EditOperation,
187
+ BatchActionBar,
188
+ getColumnStyle,
189
+ afterScroll,
190
+ getColumnKey
191
+ }