@gmfe/table-x 2.14.21-beta.1 → 2.14.26-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 (45) hide show
  1. package/LICENSE.md +4 -0
  2. package/README.md +13 -13
  3. package/package.json +4 -4
  4. package/src/base/index.js +142 -142
  5. package/src/base/td.js +56 -56
  6. package/src/base/th.js +48 -48
  7. package/src/base/thead.js +26 -26
  8. package/src/base/tr.js +53 -53
  9. package/src/base/virtualized.js +219 -219
  10. package/src/hoc/diy_table_x/components/diy_table_x_modal.js +135 -135
  11. package/src/hoc/diy_table_x/components/modal_list.js +78 -78
  12. package/src/hoc/diy_table_x/components/modal_selector.js +56 -56
  13. package/src/hoc/diy_table_x/index.js +196 -196
  14. package/src/hoc/edit_table_x.js +20 -20
  15. package/src/hoc/expand_table_x/index.js +140 -140
  16. package/src/hoc/expand_table_x/util.js +27 -27
  17. package/src/hoc/fixed_columns_table_x.js +29 -29
  18. package/src/hoc/select_table_x/cell.js +51 -51
  19. package/src/hoc/select_table_x/header.js +28 -28
  20. package/src/hoc/select_table_x/index.js +139 -139
  21. package/src/hoc/select_table_x/util.js +10 -10
  22. package/src/hoc/sortable_table_x.js +52 -52
  23. package/src/hoc/sub_table_x.js +44 -44
  24. package/src/index.js +53 -53
  25. package/src/index.less +515 -515
  26. package/src/stories/table_x.stories.js +324 -324
  27. package/src/stories/table_x_hoc.stories.js +427 -427
  28. package/src/stories/table_x_hoc_select_expand.stories.js +256 -256
  29. package/src/util/batch_action_bar.js +124 -124
  30. package/src/util/edit.js +83 -83
  31. package/src/util/index.js +191 -191
  32. package/src/util/operation.js +249 -249
  33. package/src/util/sort_header.js +49 -49
  34. package/src/variables.less +28 -28
  35. package/svg/business.svg +20 -20
  36. package/svg/check-detail.svg +18 -18
  37. package/svg/closeup.svg +20 -20
  38. package/svg/delete.svg +10 -10
  39. package/svg/edit-pen.svg +17 -17
  40. package/svg/empty.svg +27 -27
  41. package/svg/expand.svg +21 -21
  42. package/svg/pen.svg +12 -12
  43. package/svg/recover.svg +33 -33
  44. package/svg/remove.svg +1 -1
  45. package/svg/setting.svg +17 -17
@@ -1,139 +1,139 @@
1
- import React, { useMemo } from 'react'
2
- import PropTypes from 'prop-types'
3
- import TableX from '../../base'
4
- import { TABLE_X, TABLE_X_SELECT_ID } from '../../util'
5
- import { Flex } from '@gmfe/react'
6
- import { devWarn } from '@gm-common/tool'
7
- import { SelectContext } from './util'
8
- import SelectHeader from './header'
9
- import SelectCell from './cell'
10
- import _ from 'lodash'
11
-
12
- // 利用 Context 做到按需更新
13
-
14
- function getNewColumns(
15
- columns,
16
- fixedSelect,
17
- selectType,
18
- keyField,
19
- isSelectorDisable
20
- ) {
21
- return [
22
- {
23
- id: TABLE_X_SELECT_ID,
24
- width: TABLE_X.WIDTH_FUN,
25
- maxWidth: TABLE_X.WIDTH_FUN,
26
- thClassName: 'gm-table-x-icon',
27
- tdClassName: 'gm-table-x-icon',
28
- fixed: fixedSelect ? 'left' : null,
29
- Header: () => <SelectHeader selectType={selectType} />,
30
- // eslint-disable-next-line
31
- Cell: ({ row }) => (
32
- <SelectCell
33
- selectType={selectType}
34
- keyField={keyField}
35
- row={row}
36
- isSelectorDisable={isSelectorDisable}
37
- />
38
- )
39
- }
40
- ].concat(columns)
41
- }
42
-
43
- function selectTableXHOC(Component) {
44
- const SelectTableX = props => {
45
- const {
46
- selected,
47
- onSelect,
48
- batchActionBar,
49
- isSelectorDisable,
50
- selectType,
51
- keyField,
52
- fixedSelect,
53
- columns,
54
- data,
55
- ...rest
56
- } = props
57
-
58
- devWarn(() => {
59
- if (props.onSelectAll) {
60
- throw Error('onSelectAll已经废弃,使用onSelect即可!')
61
- }
62
- })
63
-
64
- const canSelectData = data.filter(row => !isSelectorDisable(row))
65
-
66
- let isSelectAll = false
67
- if (selected.length > 0) {
68
- isSelectAll = selected.length === canSelectData.length
69
- }
70
-
71
- const handleSelect = selected => {
72
- onSelect(selected)
73
- }
74
-
75
- const handleSelectAll = () => {
76
- onSelect(!isSelectAll ? _.map(canSelectData, v => v[keyField]) : [])
77
- }
78
-
79
- // columns 即可,其他都是死的。 isSelectorDisable 呢?
80
- const newColumns = useMemo(() => {
81
- return getNewColumns(
82
- columns,
83
- fixedSelect,
84
- selectType,
85
- keyField,
86
- isSelectorDisable
87
- )
88
- }, [columns])
89
-
90
- return (
91
- <SelectContext.Provider
92
- value={{
93
- selected,
94
- onSelect: handleSelect,
95
- isSelectAll,
96
- onSelectAll: handleSelectAll
97
- }}
98
- >
99
- <div className='gm-table-x-select-container'>
100
- {batchActionBar && (
101
- <div className='gm-table-x-select-batch-action-bar-container'>
102
- <Flex
103
- column
104
- justifyCenter
105
- className='gm-table-x-select-batch-action-bar'
106
- >
107
- {batchActionBar}
108
- </Flex>
109
- </div>
110
- )}
111
- <Component {...rest} columns={newColumns} data={data} />
112
- </div>
113
- </SelectContext.Provider>
114
- )
115
- }
116
-
117
- SelectTableX.propTypes = {
118
- ...TableX.propTypes,
119
-
120
- // select 专有
121
- selected: PropTypes.array.isRequired,
122
- onSelect: PropTypes.func.isRequired,
123
- batchActionBar: PropTypes.element,
124
- isSelectorDisable: PropTypes.func,
125
- selectType: PropTypes.oneOf(['checkbox', 'radio']),
126
- keyField: PropTypes.string,
127
- fixedSelect: PropTypes.bool
128
- }
129
-
130
- SelectTableX.defaultProps = {
131
- selectType: 'checkbox',
132
- keyField: 'value',
133
- isSelectorDisable: () => false
134
- }
135
-
136
- return SelectTableX
137
- }
138
-
139
- export default selectTableXHOC
1
+ import React, { useMemo } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import TableX from '../../base'
4
+ import { TABLE_X, TABLE_X_SELECT_ID } from '../../util'
5
+ import { Flex } from '@gmfe/react'
6
+ import { devWarn } from '@gm-common/tool'
7
+ import { SelectContext } from './util'
8
+ import SelectHeader from './header'
9
+ import SelectCell from './cell'
10
+ import _ from 'lodash'
11
+
12
+ // 利用 Context 做到按需更新
13
+
14
+ function getNewColumns(
15
+ columns,
16
+ fixedSelect,
17
+ selectType,
18
+ keyField,
19
+ isSelectorDisable
20
+ ) {
21
+ return [
22
+ {
23
+ id: TABLE_X_SELECT_ID,
24
+ width: TABLE_X.WIDTH_FUN,
25
+ maxWidth: TABLE_X.WIDTH_FUN,
26
+ thClassName: 'gm-table-x-icon',
27
+ tdClassName: 'gm-table-x-icon',
28
+ fixed: fixedSelect ? 'left' : null,
29
+ Header: () => <SelectHeader selectType={selectType} />,
30
+ // eslint-disable-next-line
31
+ Cell: ({ row }) => (
32
+ <SelectCell
33
+ selectType={selectType}
34
+ keyField={keyField}
35
+ row={row}
36
+ isSelectorDisable={isSelectorDisable}
37
+ />
38
+ )
39
+ }
40
+ ].concat(columns)
41
+ }
42
+
43
+ function selectTableXHOC(Component) {
44
+ const SelectTableX = props => {
45
+ const {
46
+ selected,
47
+ onSelect,
48
+ batchActionBar,
49
+ isSelectorDisable,
50
+ selectType,
51
+ keyField,
52
+ fixedSelect,
53
+ columns,
54
+ data,
55
+ ...rest
56
+ } = props
57
+
58
+ devWarn(() => {
59
+ if (props.onSelectAll) {
60
+ throw Error('onSelectAll已经废弃,使用onSelect即可!')
61
+ }
62
+ })
63
+
64
+ const canSelectData = data.filter(row => !isSelectorDisable(row))
65
+
66
+ let isSelectAll = false
67
+ if (selected.length > 0) {
68
+ isSelectAll = selected.length === canSelectData.length
69
+ }
70
+
71
+ const handleSelect = selected => {
72
+ onSelect(selected)
73
+ }
74
+
75
+ const handleSelectAll = () => {
76
+ onSelect(!isSelectAll ? _.map(canSelectData, v => v[keyField]) : [])
77
+ }
78
+
79
+ // columns 即可,其他都是死的。 isSelectorDisable 呢?
80
+ const newColumns = useMemo(() => {
81
+ return getNewColumns(
82
+ columns,
83
+ fixedSelect,
84
+ selectType,
85
+ keyField,
86
+ isSelectorDisable
87
+ )
88
+ }, [columns])
89
+
90
+ return (
91
+ <SelectContext.Provider
92
+ value={{
93
+ selected,
94
+ onSelect: handleSelect,
95
+ isSelectAll,
96
+ onSelectAll: handleSelectAll
97
+ }}
98
+ >
99
+ <div className='gm-table-x-select-container'>
100
+ {batchActionBar && (
101
+ <div className='gm-table-x-select-batch-action-bar-container'>
102
+ <Flex
103
+ column
104
+ justifyCenter
105
+ className='gm-table-x-select-batch-action-bar'
106
+ >
107
+ {batchActionBar}
108
+ </Flex>
109
+ </div>
110
+ )}
111
+ <Component {...rest} columns={newColumns} data={data} />
112
+ </div>
113
+ </SelectContext.Provider>
114
+ )
115
+ }
116
+
117
+ SelectTableX.propTypes = {
118
+ ...TableX.propTypes,
119
+
120
+ // select 专有
121
+ selected: PropTypes.array.isRequired,
122
+ onSelect: PropTypes.func.isRequired,
123
+ batchActionBar: PropTypes.element,
124
+ isSelectorDisable: PropTypes.func,
125
+ selectType: PropTypes.oneOf(['checkbox', 'radio']),
126
+ keyField: PropTypes.string,
127
+ fixedSelect: PropTypes.bool
128
+ }
129
+
130
+ SelectTableX.defaultProps = {
131
+ selectType: 'checkbox',
132
+ keyField: 'value',
133
+ isSelectorDisable: () => false
134
+ }
135
+
136
+ return SelectTableX
137
+ }
138
+
139
+ export default selectTableXHOC
@@ -1,10 +1,10 @@
1
- import { createContext } from 'react'
2
-
3
- const SelectContext = createContext({
4
- selected: [],
5
- isSelectAll: false,
6
- onSelect: () => {},
7
- onSelectAll: () => {}
8
- })
9
-
10
- export { SelectContext }
1
+ import { createContext } from 'react'
2
+
3
+ const SelectContext = createContext({
4
+ selected: [],
5
+ isSelectAll: false,
6
+ onSelect: () => {},
7
+ onSelectAll: () => {}
8
+ })
9
+
10
+ export { SelectContext }
@@ -1,52 +1,52 @@
1
- import React, { useEffect } from 'react'
2
- import PropTypes from 'prop-types'
3
- import TableX from '../base'
4
- import SortableJS from 'sortablejs'
5
- import _ from 'lodash'
6
-
7
- function sortableTableX(Component) {
8
- const SortableTableX = ({ id, data, onSortChange, keyField, ...rest }) => {
9
- id = id || 'id' + +new Date() + '' + String(Math.random()).slice(2)
10
-
11
- useEffect(() => {
12
- const target = document.querySelector(`#${id} .gm-table-x-tbody`)
13
-
14
- const sortable = new SortableJS(target, {
15
- animation: 150,
16
- onStart: () => {
17
- target.classList.add('gm-table-x-sortable-active')
18
- },
19
- onEnd: () => {
20
- target.classList.remove('gm-table-x-sortable-active')
21
- },
22
- onUpdate: evt => {
23
- const newIds = sortable.toArray()
24
- const newData = _.sortBy(data.slice(), v =>
25
- newIds.indexOf(v[keyField])
26
- )
27
- onSortChange(newData)
28
- }
29
- })
30
-
31
- return () => {
32
- sortable.destroy()
33
- }
34
- }, [data])
35
- return <Component {...rest} id={id} data={data} keyField={keyField} />
36
- }
37
-
38
- SortableTableX.propTypes = {
39
- ...TableX.propTypes,
40
-
41
- keyField: PropTypes.string,
42
- onSortChange: PropTypes.func.isRequired
43
- }
44
-
45
- SortableTableX.defaultProps = {
46
- keyField: 'value'
47
- }
48
-
49
- return SortableTableX
50
- }
51
-
52
- export default sortableTableX
1
+ import React, { useEffect } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import TableX from '../base'
4
+ import SortableJS from 'sortablejs'
5
+ import _ from 'lodash'
6
+
7
+ function sortableTableX(Component) {
8
+ const SortableTableX = ({ id, data, onSortChange, keyField, ...rest }) => {
9
+ id = id || 'id' + +new Date() + '' + String(Math.random()).slice(2)
10
+
11
+ useEffect(() => {
12
+ const target = document.querySelector(`#${id} .gm-table-x-tbody`)
13
+
14
+ const sortable = new SortableJS(target, {
15
+ animation: 150,
16
+ onStart: () => {
17
+ target.classList.add('gm-table-x-sortable-active')
18
+ },
19
+ onEnd: () => {
20
+ target.classList.remove('gm-table-x-sortable-active')
21
+ },
22
+ onUpdate: evt => {
23
+ const newIds = sortable.toArray()
24
+ const newData = _.sortBy(data.slice(), v =>
25
+ newIds.indexOf(v[keyField])
26
+ )
27
+ onSortChange(newData)
28
+ }
29
+ })
30
+
31
+ return () => {
32
+ sortable.destroy()
33
+ }
34
+ }, [data])
35
+ return <Component {...rest} id={id} data={data} keyField={keyField} />
36
+ }
37
+
38
+ SortableTableX.propTypes = {
39
+ ...TableX.propTypes,
40
+
41
+ keyField: PropTypes.string,
42
+ onSortChange: PropTypes.func.isRequired
43
+ }
44
+
45
+ SortableTableX.defaultProps = {
46
+ keyField: 'value'
47
+ }
48
+
49
+ return SortableTableX
50
+ }
51
+
52
+ export default sortableTableX
@@ -1,44 +1,44 @@
1
- import React from 'react'
2
- import classNames from 'classnames'
3
- import PropTypes from 'prop-types'
4
- import TableX from '../base'
5
- import { TABLE_X, TABLE_X_SUB_TABLE_ID } from '../util'
6
-
7
- const subTableXHOC = Component => {
8
- const SubTable = ({ subTableIndent, columns, className, ...rest }) => {
9
- const _columns = React.useMemo(
10
- () =>
11
- [
12
- {
13
- id: TABLE_X_SUB_TABLE_ID,
14
- width: subTableIndent,
15
- maxWidth: subTableIndent,
16
- Header: ''
17
- }
18
- ].concat(columns),
19
- [columns, subTableIndent]
20
- )
21
-
22
- return (
23
- <Component
24
- {...rest}
25
- columns={_columns}
26
- className={classNames('gm-table-x-sub-table', className)}
27
- />
28
- )
29
- }
30
-
31
- SubTable.propTypes = {
32
- ...TableX.propTypes,
33
- /** 默认功能区的宽度 */
34
- subTableIndent: PropTypes.number
35
- }
36
-
37
- SubTable.defaultProps = {
38
- subTableIndent: TABLE_X.WIDTH_FUN
39
- }
40
-
41
- return SubTable
42
- }
43
-
44
- export default subTableXHOC
1
+ import React from 'react'
2
+ import classNames from 'classnames'
3
+ import PropTypes from 'prop-types'
4
+ import TableX from '../base'
5
+ import { TABLE_X, TABLE_X_SUB_TABLE_ID } from '../util'
6
+
7
+ const subTableXHOC = Component => {
8
+ const SubTable = ({ subTableIndent, columns, className, ...rest }) => {
9
+ const _columns = React.useMemo(
10
+ () =>
11
+ [
12
+ {
13
+ id: TABLE_X_SUB_TABLE_ID,
14
+ width: subTableIndent,
15
+ maxWidth: subTableIndent,
16
+ Header: ''
17
+ }
18
+ ].concat(columns),
19
+ [columns, subTableIndent]
20
+ )
21
+
22
+ return (
23
+ <Component
24
+ {...rest}
25
+ columns={_columns}
26
+ className={classNames('gm-table-x-sub-table', className)}
27
+ />
28
+ )
29
+ }
30
+
31
+ SubTable.propTypes = {
32
+ ...TableX.propTypes,
33
+ /** 默认功能区的宽度 */
34
+ subTableIndent: PropTypes.number
35
+ }
36
+
37
+ SubTable.defaultProps = {
38
+ subTableIndent: TABLE_X.WIDTH_FUN
39
+ }
40
+
41
+ return SubTable
42
+ }
43
+
44
+ export default subTableXHOC
package/src/index.js CHANGED
@@ -1,53 +1,53 @@
1
- import TableX from './base'
2
- import TableXVirtualized from './base/virtualized'
3
- import selectTableXHOC from './hoc/select_table_x'
4
- import expandTableXHOC from './hoc/expand_table_x'
5
- import fixedColumnsTableXHOC from './hoc/fixed_columns_table_x'
6
- import sortableTableXHOC from './hoc/sortable_table_x'
7
- import subTableXHOC from './hoc/sub_table_x'
8
- import editTableXHOC from './hoc/edit_table_x'
9
- import diyTableXHOC from './hoc/diy_table_x'
10
-
11
- import {
12
- TABLE_X,
13
- BatchActionBar,
14
- OperationHeader,
15
- OperationDelete,
16
- OperationRecover,
17
- OperationDetail,
18
- OperationCell,
19
- OperationRowEdit,
20
- OperationIconTip,
21
- EditButton,
22
- EditOperation,
23
- SortHeader
24
- } from './util'
25
-
26
- const TableXUtil = {
27
- TABLE_X,
28
-
29
- BatchActionBar,
30
- SortHeader,
31
- OperationRecover,
32
- OperationHeader,
33
- OperationDelete,
34
- OperationDetail,
35
- OperationCell,
36
- OperationRowEdit,
37
- OperationIconTip,
38
- EditButton,
39
- EditOperation
40
- }
41
-
42
- export {
43
- TableXUtil,
44
- TableX,
45
- TableXVirtualized,
46
- selectTableXHOC,
47
- expandTableXHOC,
48
- fixedColumnsTableXHOC,
49
- subTableXHOC,
50
- editTableXHOC,
51
- diyTableXHOC,
52
- sortableTableXHOC
53
- }
1
+ import TableX from './base'
2
+ import TableXVirtualized from './base/virtualized'
3
+ import selectTableXHOC from './hoc/select_table_x'
4
+ import expandTableXHOC from './hoc/expand_table_x'
5
+ import fixedColumnsTableXHOC from './hoc/fixed_columns_table_x'
6
+ import sortableTableXHOC from './hoc/sortable_table_x'
7
+ import subTableXHOC from './hoc/sub_table_x'
8
+ import editTableXHOC from './hoc/edit_table_x'
9
+ import diyTableXHOC from './hoc/diy_table_x'
10
+
11
+ import {
12
+ TABLE_X,
13
+ BatchActionBar,
14
+ OperationHeader,
15
+ OperationDelete,
16
+ OperationRecover,
17
+ OperationDetail,
18
+ OperationCell,
19
+ OperationRowEdit,
20
+ OperationIconTip,
21
+ EditButton,
22
+ EditOperation,
23
+ SortHeader
24
+ } from './util'
25
+
26
+ const TableXUtil = {
27
+ TABLE_X,
28
+
29
+ BatchActionBar,
30
+ SortHeader,
31
+ OperationRecover,
32
+ OperationHeader,
33
+ OperationDelete,
34
+ OperationDetail,
35
+ OperationCell,
36
+ OperationRowEdit,
37
+ OperationIconTip,
38
+ EditButton,
39
+ EditOperation
40
+ }
41
+
42
+ export {
43
+ TableXUtil,
44
+ TableX,
45
+ TableXVirtualized,
46
+ selectTableXHOC,
47
+ expandTableXHOC,
48
+ fixedColumnsTableXHOC,
49
+ subTableXHOC,
50
+ editTableXHOC,
51
+ diyTableXHOC,
52
+ sortableTableXHOC
53
+ }