@atlaskit/table-tree 9.0.9 → 9.0.13
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/CHANGELOG.md +35 -0
- package/dist/cjs/components/cell.js +79 -0
- package/dist/cjs/components/{Header.js → header.js} +22 -8
- package/dist/cjs/components/{Headers.js → headers.js} +12 -8
- package/dist/cjs/components/{Chevron.js → internal/chevron.js} +8 -4
- package/dist/cjs/components/internal/common-cell.js +45 -0
- package/dist/cjs/components/{Item.js → internal/item.js} +9 -9
- package/dist/cjs/components/{Items.js → internal/items.js} +11 -7
- package/dist/cjs/components/{LoaderItem.js → internal/loader-item.js} +17 -13
- package/dist/cjs/components/internal/overflow-container.js +35 -0
- package/dist/cjs/components/internal/styled.js +92 -0
- package/dist/cjs/components/{withColumnWidth.js → internal/with-column-width.js} +13 -6
- package/dist/cjs/components/{Row.js → row.js} +12 -8
- package/dist/cjs/components/{Rows.js → rows.js} +9 -6
- package/dist/cjs/components/{TableTree.js → table-tree.js} +17 -15
- package/dist/cjs/index.js +14 -14
- package/dist/cjs/utils/{TableTreeDataHelper.js → table-tree-data-helper.js} +1 -3
- package/dist/cjs/utils/{toItemId.js → to-item-id.js} +0 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/cell.js +31 -0
- package/dist/es2019/components/header.js +35 -0
- package/dist/es2019/components/headers.js +24 -0
- package/dist/es2019/components/internal/chevron.js +51 -0
- package/dist/es2019/components/internal/common-cell.js +30 -0
- package/dist/es2019/components/internal/item.js +46 -0
- package/dist/es2019/components/internal/items.js +76 -0
- package/dist/es2019/components/internal/loader-item.js +60 -0
- package/dist/es2019/components/internal/overflow-container.js +21 -0
- package/dist/es2019/components/internal/styled.js +63 -0
- package/dist/es2019/components/internal/with-column-width.js +40 -0
- package/dist/es2019/components/row.js +148 -0
- package/dist/es2019/components/rows.js +15 -0
- package/dist/es2019/components/table-tree.js +107 -0
- package/dist/es2019/index.js +7 -0
- package/dist/es2019/utils/table-tree-data-helper.js +130 -0
- package/dist/es2019/utils/to-item-id.js +3 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/{Cell.js → cell.js} +22 -8
- package/dist/esm/components/{Header.js → header.js} +23 -7
- package/dist/esm/components/{Headers.js → headers.js} +14 -6
- package/dist/esm/components/{Chevron.js → internal/chevron.js} +4 -2
- package/dist/esm/components/internal/common-cell.js +33 -0
- package/dist/esm/components/{Item.js → internal/item.js} +11 -7
- package/dist/esm/components/{Items.js → internal/items.js} +3 -3
- package/dist/esm/components/{LoaderItem.js → internal/loader-item.js} +12 -11
- package/dist/esm/components/internal/overflow-container.js +24 -0
- package/dist/esm/components/internal/styled.js +72 -0
- package/dist/esm/components/{withColumnWidth.js → internal/with-column-width.js} +7 -4
- package/dist/esm/components/{Row.js → row.js} +6 -6
- package/dist/esm/components/{Rows.js → rows.js} +2 -3
- package/dist/esm/components/{TableTree.js → table-tree.js} +7 -8
- package/dist/esm/index.js +7 -7
- package/dist/esm/utils/{TableTreeDataHelper.js → table-tree-data-helper.js} +1 -5
- package/dist/esm/utils/{toItemId.js → to-item-id.js} +0 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/components/cell.d.ts +66 -0
- package/dist/types/components/header.d.ts +60 -0
- package/dist/types/components/headers.d.ts +5 -0
- package/dist/types/components/internal/chevron.d.ts +17 -0
- package/dist/types/components/internal/common-cell.d.ts +10 -0
- package/dist/types/components/internal/item.d.ts +12 -0
- package/dist/types/components/internal/items.d.ts +24 -0
- package/dist/types/components/internal/loader-item.d.ts +20 -0
- package/dist/types/components/internal/overflow-container.d.ts +10 -0
- package/dist/types/components/internal/styled.d.ts +25 -0
- package/dist/types/components/internal/with-column-width.d.ts +64 -0
- package/dist/types/components/row.d.ts +19 -0
- package/dist/types/components/rows.d.ts +12 -0
- package/dist/types/components/table-tree.d.ts +23 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/utils/table-tree-data-helper.d.ts +25 -0
- package/dist/types/utils/to-item-id.d.ts +1 -0
- package/package.json +31 -14
- package/dist/cjs/components/Cell.js +0 -60
- package/dist/cjs/styled.js +0 -107
- package/dist/esm/styled.js +0 -68
- package/styled/package.json +0 -6
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
|
|
3
|
+
/** @jsx jsx */
|
|
4
|
+
import { css, jsx } from '@emotion/core';
|
|
5
|
+
const overflowContainerStyles = css({
|
|
6
|
+
overflow: 'hidden',
|
|
7
|
+
textOverflow: 'ellipsis',
|
|
8
|
+
whiteSpace: 'nowrap'
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* __Overflow container__
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const OverflowContainer = ({
|
|
15
|
+
isSingleLine,
|
|
16
|
+
...props
|
|
17
|
+
}) => jsx("span", _extends({
|
|
18
|
+
css: isSingleLine && overflowContainerStyles
|
|
19
|
+
}, props));
|
|
20
|
+
|
|
21
|
+
export default OverflowContainer;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
|
|
3
|
+
/** @jsx jsx */
|
|
4
|
+
import { css, jsx } from '@emotion/core';
|
|
5
|
+
import { N30, N800 } from '@atlaskit/theme/colors';
|
|
6
|
+
export const iconColor = `var(--ds-text-highEmphasis, ${N800})`;
|
|
7
|
+
const treeRowContainerStyles = css({
|
|
8
|
+
display: 'flex',
|
|
9
|
+
borderBottom: `1px solid ${`var(--ds-border-neutral, ${N30})`}`
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* __Tree row container__
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const TreeRowContainer = props => jsx("div", _extends({
|
|
16
|
+
css: treeRowContainerStyles
|
|
17
|
+
}, props));
|
|
18
|
+
const commonChevronContainerStyles = css({
|
|
19
|
+
display: 'flex',
|
|
20
|
+
marginLeft: -25,
|
|
21
|
+
position: 'absolute',
|
|
22
|
+
top: 7,
|
|
23
|
+
alignItems: 'center'
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* __Chevron container__
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export const ChevronContainer = props => jsx("span", _extends({}, props, {
|
|
30
|
+
css: commonChevronContainerStyles
|
|
31
|
+
}));
|
|
32
|
+
const chevronIconContainerStyles = css({
|
|
33
|
+
position: 'relative',
|
|
34
|
+
top: 1
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* __Chevron icon container__
|
|
38
|
+
*
|
|
39
|
+
* A chevron icon container.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
export const ChevronIconContainer = props => jsx("span", _extends({}, props, {
|
|
43
|
+
css: chevronIconContainerStyles
|
|
44
|
+
}));
|
|
45
|
+
const loadingItemContainerStyles = css({
|
|
46
|
+
width: '100%',
|
|
47
|
+
paddingTop: 5
|
|
48
|
+
});
|
|
49
|
+
const paddingLeftStyles = css({
|
|
50
|
+
paddingLeft: '50%'
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* __Loader item container__
|
|
54
|
+
*
|
|
55
|
+
* A loader item container.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
export const LoaderItemContainer = ({
|
|
59
|
+
isRoot,
|
|
60
|
+
...props
|
|
61
|
+
}) => jsx("span", _extends({
|
|
62
|
+
css: [commonChevronContainerStyles, loadingItemContainerStyles, isRoot && paddingLeftStyles]
|
|
63
|
+
}, props));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
|
|
4
|
+
/* eslint-disable react/prop-types */
|
|
5
|
+
import React, { Component } from 'react';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
export default function withColumnWidth(Cell) {
|
|
8
|
+
var _class, _temp;
|
|
9
|
+
|
|
10
|
+
return _temp = _class = class CellWithColumnWidth extends Component {
|
|
11
|
+
UNSAFE_componentWillMount() {
|
|
12
|
+
this.setColumnWidth(this.props.width);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
setColumnWidth(width) {
|
|
16
|
+
if (width !== undefined) {
|
|
17
|
+
this.context.tableTree.setColumnWidth(this.props.columnIndex, width);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
22
|
+
this.setColumnWidth(nextProps.width);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
const {
|
|
27
|
+
width,
|
|
28
|
+
columnIndex,
|
|
29
|
+
...other
|
|
30
|
+
} = this.props;
|
|
31
|
+
const columnWidth = width !== null && width !== undefined ? width : this.context.tableTree.getColumnWidth(columnIndex);
|
|
32
|
+
return /*#__PURE__*/React.createElement(Cell, _extends({
|
|
33
|
+
width: columnWidth
|
|
34
|
+
}, other));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}, _defineProperty(_class, "contextTypes", {
|
|
38
|
+
tableTree: PropTypes.object.isRequired
|
|
39
|
+
}), _temp;
|
|
40
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @repo/internal/react/no-clone-element */
|
|
5
|
+
import React, { Component, Fragment } from 'react';
|
|
6
|
+
import { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
7
|
+
import toItemId from '../utils/to-item-id';
|
|
8
|
+
import Chevron from './internal/chevron';
|
|
9
|
+
import { TreeRowContainer } from './internal/styled';
|
|
10
|
+
const packageName = "@atlaskit/table-tree";
|
|
11
|
+
const packageVersion = "9.0.13";
|
|
12
|
+
|
|
13
|
+
class Row extends Component {
|
|
14
|
+
constructor(...args) {
|
|
15
|
+
super(...args);
|
|
16
|
+
|
|
17
|
+
_defineProperty(this, "state", {
|
|
18
|
+
isExpanded: this.props.isDefaultExpanded || false
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
_defineProperty(this, "onExpandToggle", () => {
|
|
22
|
+
const {
|
|
23
|
+
isExpanded
|
|
24
|
+
} = this.props;
|
|
25
|
+
|
|
26
|
+
if (isExpanded !== undefined) {
|
|
27
|
+
this.onExpandStateChange(!isExpanded);
|
|
28
|
+
} else {
|
|
29
|
+
this.setState({
|
|
30
|
+
isExpanded: !this.state.isExpanded
|
|
31
|
+
});
|
|
32
|
+
this.onExpandStateChange(!this.state.isExpanded);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
componentDidUpdate(prevProps) {
|
|
38
|
+
const {
|
|
39
|
+
isDefaultExpanded,
|
|
40
|
+
isExpanded
|
|
41
|
+
} = this.props;
|
|
42
|
+
|
|
43
|
+
if (isExpanded === undefined && isDefaultExpanded !== undefined && prevProps.isDefaultExpanded !== isDefaultExpanded && this.state.isExpanded !== isDefaultExpanded) {
|
|
44
|
+
// eslint-disable-next-line react/no-did-update-set-state
|
|
45
|
+
this.setState({
|
|
46
|
+
isExpanded: isDefaultExpanded
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
onExpandStateChange(isExpanded) {
|
|
52
|
+
if (this.props.data) {
|
|
53
|
+
if (isExpanded && this.props.onExpand) {
|
|
54
|
+
this.props.onExpand(this.props.data);
|
|
55
|
+
} else if (!isExpanded && this.props.onCollapse) {
|
|
56
|
+
this.props.onCollapse(this.props.data);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
isExpanded() {
|
|
62
|
+
const {
|
|
63
|
+
isExpanded
|
|
64
|
+
} = this.props;
|
|
65
|
+
return isExpanded !== undefined ? isExpanded : this.state.isExpanded;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
renderCell(cell, cellIndex) {
|
|
69
|
+
const {
|
|
70
|
+
props
|
|
71
|
+
} = this;
|
|
72
|
+
const isExpanded = this.isExpanded();
|
|
73
|
+
const {
|
|
74
|
+
hasChildren,
|
|
75
|
+
depth
|
|
76
|
+
} = props;
|
|
77
|
+
const isFirstCell = cellIndex === 0;
|
|
78
|
+
const indentLevel = isFirstCell ? depth : 0;
|
|
79
|
+
let cellContent = cell.props.children || [];
|
|
80
|
+
|
|
81
|
+
if (isFirstCell && hasChildren) {
|
|
82
|
+
cellContent = [/*#__PURE__*/React.createElement(Chevron, {
|
|
83
|
+
key: "chevron",
|
|
84
|
+
expandLabel: props.expandLabel,
|
|
85
|
+
collapseLabel: props.collapseLabel,
|
|
86
|
+
isExpanded: isExpanded,
|
|
87
|
+
onExpandToggle: this.onExpandToggle,
|
|
88
|
+
ariaControls: toItemId(props.itemId)
|
|
89
|
+
})].concat(cellContent);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return /*#__PURE__*/React.cloneElement(cell, {
|
|
93
|
+
key: cellIndex,
|
|
94
|
+
columnIndex: cellIndex,
|
|
95
|
+
indentLevel
|
|
96
|
+
}, cellContent);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
render() {
|
|
100
|
+
const {
|
|
101
|
+
hasChildren,
|
|
102
|
+
depth,
|
|
103
|
+
renderChildren
|
|
104
|
+
} = this.props;
|
|
105
|
+
const isExpanded = this.isExpanded();
|
|
106
|
+
const ariaAttrs = {};
|
|
107
|
+
|
|
108
|
+
if (hasChildren) {
|
|
109
|
+
ariaAttrs['aria-expanded'] = isExpanded;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (depth !== undefined) {
|
|
113
|
+
ariaAttrs['aria-level'] = depth;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(TreeRowContainer, _extends({
|
|
117
|
+
role: "row"
|
|
118
|
+
}, ariaAttrs), React.Children.map(this.props.children, (cell, index) => this.renderCell(cell, index))), hasChildren && isExpanded && renderChildren && renderChildren());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { Row as RowWithoutAnalytics };
|
|
124
|
+
const createAndFireEventOnAtlaskit = createAndFireEvent('atlaskit');
|
|
125
|
+
export default withAnalyticsContext({
|
|
126
|
+
componentName: 'row',
|
|
127
|
+
packageName,
|
|
128
|
+
packageVersion
|
|
129
|
+
})(withAnalyticsEvents({
|
|
130
|
+
onExpand: createAndFireEventOnAtlaskit({
|
|
131
|
+
action: 'expanded',
|
|
132
|
+
actionSubject: 'tableTree',
|
|
133
|
+
attributes: {
|
|
134
|
+
componentName: 'row',
|
|
135
|
+
packageName,
|
|
136
|
+
packageVersion
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
onCollapse: createAndFireEventOnAtlaskit({
|
|
140
|
+
action: 'collapsed',
|
|
141
|
+
actionSubject: 'tableTree',
|
|
142
|
+
attributes: {
|
|
143
|
+
componentName: 'row',
|
|
144
|
+
packageName,
|
|
145
|
+
packageVersion
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
})(Row));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import Items from './internal/items';
|
|
3
|
+
export default class Rows extends Component {
|
|
4
|
+
render() {
|
|
5
|
+
const {
|
|
6
|
+
items,
|
|
7
|
+
render
|
|
8
|
+
} = this.props;
|
|
9
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Items, {
|
|
10
|
+
items: items,
|
|
11
|
+
render: render
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable react/prop-types */
|
|
4
|
+
import React, { Component } from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import Cell from './cell';
|
|
7
|
+
import Header from './header';
|
|
8
|
+
import Headers from './headers';
|
|
9
|
+
import Row from './row';
|
|
10
|
+
import Rows from './rows';
|
|
11
|
+
export default class TableTree extends Component {
|
|
12
|
+
constructor(...args) {
|
|
13
|
+
super(...args);
|
|
14
|
+
|
|
15
|
+
_defineProperty(this, "state", {
|
|
16
|
+
columnWidths: []
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
_defineProperty(this, "setColumnWidth", (columnIndex, width) => {
|
|
20
|
+
const {
|
|
21
|
+
columnWidths
|
|
22
|
+
} = this.state;
|
|
23
|
+
|
|
24
|
+
if (width === columnWidths[columnIndex]) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
columnWidths[columnIndex] = width;
|
|
29
|
+
this.setState({
|
|
30
|
+
columnWidths
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "getColumnWidth", columnIndex => {
|
|
35
|
+
return this.state && this.state.columnWidths[columnIndex] || null;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
componentDidMount() {
|
|
40
|
+
const widths = this.props.columnWidths;
|
|
41
|
+
|
|
42
|
+
if (widths) {
|
|
43
|
+
this.setState({
|
|
44
|
+
columnWidths: widths
|
|
45
|
+
}); // eslint-disable-line
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getChildContext() {
|
|
50
|
+
return {
|
|
51
|
+
tableTree: {
|
|
52
|
+
columnWidths: this.state.columnWidths,
|
|
53
|
+
setColumnWidth: this.setColumnWidth,
|
|
54
|
+
getColumnWidth: this.getColumnWidth
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
render() {
|
|
60
|
+
const {
|
|
61
|
+
items,
|
|
62
|
+
headers,
|
|
63
|
+
columns,
|
|
64
|
+
columnWidths = []
|
|
65
|
+
} = this.props;
|
|
66
|
+
const heads = headers && /*#__PURE__*/React.createElement(Headers, null, headers.map((header, index) =>
|
|
67
|
+
/*#__PURE__*/
|
|
68
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
69
|
+
React.createElement(Header, {
|
|
70
|
+
key: index,
|
|
71
|
+
columnIndex: index,
|
|
72
|
+
width: columnWidths[index]
|
|
73
|
+
}, header)));
|
|
74
|
+
let rows = null;
|
|
75
|
+
|
|
76
|
+
if (columns && items) {
|
|
77
|
+
rows = /*#__PURE__*/React.createElement(Rows, {
|
|
78
|
+
items: items,
|
|
79
|
+
render: ({
|
|
80
|
+
id,
|
|
81
|
+
children,
|
|
82
|
+
hasChildren,
|
|
83
|
+
content
|
|
84
|
+
}) => /*#__PURE__*/React.createElement(Row, {
|
|
85
|
+
itemId: id,
|
|
86
|
+
items: children,
|
|
87
|
+
hasChildren: hasChildren
|
|
88
|
+
}, columns.map((CellContent, index) => /*#__PURE__*/React.createElement(Cell // eslint-disable-next-line react/no-array-index-key
|
|
89
|
+
, {
|
|
90
|
+
key: index,
|
|
91
|
+
columnIndex: index,
|
|
92
|
+
width: columnWidths[index]
|
|
93
|
+
}, /*#__PURE__*/React.createElement(CellContent, content))))
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
98
|
+
role: "treegrid",
|
|
99
|
+
"aria-readonly": true
|
|
100
|
+
}, heads, rows, this.props.children);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_defineProperty(TableTree, "childContextTypes", {
|
|
106
|
+
tableTree: PropTypes.object.isRequired
|
|
107
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default } from './components/table-tree';
|
|
2
|
+
export { default as Headers } from './components/headers';
|
|
3
|
+
export { default as Header } from './components/header';
|
|
4
|
+
export { default as Cell } from './components/cell';
|
|
5
|
+
export { default as Rows } from './components/rows';
|
|
6
|
+
export { default as Row } from './components/row';
|
|
7
|
+
export { default as TableTreeDataHelper } from './utils/table-tree-data-helper';
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
import set from 'lodash/set';
|
|
3
|
+
|
|
4
|
+
function updateRootItems(rootItems, allItems = [], {
|
|
5
|
+
key,
|
|
6
|
+
keysCache,
|
|
7
|
+
operation
|
|
8
|
+
}) {
|
|
9
|
+
const newKeysCache = { ...keysCache
|
|
10
|
+
}; // If it is not an append operation we can ignore allItems as they will be swaped with new items
|
|
11
|
+
|
|
12
|
+
const allBaseItems = operation === 'UPDATE' ? [] : [...allItems];
|
|
13
|
+
const startIndexWith = allBaseItems.length;
|
|
14
|
+
rootItems.forEach((rootItem, index) => {
|
|
15
|
+
const rootItemKey = rootItem[key];
|
|
16
|
+
|
|
17
|
+
if (rootItemKey === undefined) {
|
|
18
|
+
throw new Error(`[ERROR] Property '${key}' not found in rootItem[${index}]`);
|
|
19
|
+
} else {
|
|
20
|
+
newKeysCache[rootItem[key]] = index + startIndexWith;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
keysCache: newKeysCache,
|
|
25
|
+
items: allBaseItems.concat(rootItems)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function updateChildItems(newitems, allTableItems, itemParent, {
|
|
30
|
+
key,
|
|
31
|
+
keysCache,
|
|
32
|
+
operation
|
|
33
|
+
}) {
|
|
34
|
+
const newKeysCache = { ...keysCache
|
|
35
|
+
};
|
|
36
|
+
const parentCacheKey = itemParent[key];
|
|
37
|
+
|
|
38
|
+
if (parentCacheKey === undefined) {
|
|
39
|
+
throw new Error(`[Table Tree] Property '${key}' not found in parent item`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const parentLocation = newKeysCache[parentCacheKey];
|
|
43
|
+
const allItemsCopy = [...allTableItems];
|
|
44
|
+
const objectToChange = get(allItemsCopy, parentLocation);
|
|
45
|
+
const baseChildrenOfObjectToChange = operation === 'UPDATE' ? [] : get(objectToChange, 'children', []);
|
|
46
|
+
objectToChange.children = baseChildrenOfObjectToChange.concat(newitems); // Update cache
|
|
47
|
+
|
|
48
|
+
newitems.forEach((item, index) => {
|
|
49
|
+
newKeysCache[item[key]] = `${parentLocation}.children[${index + baseChildrenOfObjectToChange.length}]`;
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
keysCache: newKeysCache,
|
|
53
|
+
items: set(allItemsCopy, parentLocation, objectToChange)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* This helper class will create a cache of all the id's in the items object and
|
|
58
|
+
* path to the object.
|
|
59
|
+
* Example:
|
|
60
|
+
* [{
|
|
61
|
+
* // item 1,
|
|
62
|
+
* id: 1,
|
|
63
|
+
* children:[{
|
|
64
|
+
* // item 1.1,
|
|
65
|
+
* id: '2'
|
|
66
|
+
* }]
|
|
67
|
+
* }]
|
|
68
|
+
*
|
|
69
|
+
* Cache will look something like:
|
|
70
|
+
* {1: 0, 2: '0.children[0]'}
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
export default class TableTreeDataHelper {
|
|
75
|
+
constructor({
|
|
76
|
+
key = 'key'
|
|
77
|
+
} = {}) {
|
|
78
|
+
this.key = key;
|
|
79
|
+
this.keysCache = {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
updateItems(items, allItems = [], parentItem) {
|
|
83
|
+
const options = {
|
|
84
|
+
key: this.key,
|
|
85
|
+
keysCache: this.keysCache,
|
|
86
|
+
operation: 'UPDATE'
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (!parentItem) {
|
|
90
|
+
const {
|
|
91
|
+
keysCache,
|
|
92
|
+
items: updatedRootItems
|
|
93
|
+
} = updateRootItems(items, allItems, options);
|
|
94
|
+
this.keysCache = keysCache;
|
|
95
|
+
return updatedRootItems;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const {
|
|
99
|
+
keysCache,
|
|
100
|
+
items: updatedItems
|
|
101
|
+
} = updateChildItems(items, allItems, parentItem, options);
|
|
102
|
+
this.keysCache = keysCache;
|
|
103
|
+
return updatedItems;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
appendItems(items, allItems = [], parentItem) {
|
|
107
|
+
const options = {
|
|
108
|
+
key: this.key,
|
|
109
|
+
keysCache: this.keysCache,
|
|
110
|
+
operation: 'APPEND'
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (!parentItem) {
|
|
114
|
+
const {
|
|
115
|
+
keysCache,
|
|
116
|
+
items: updatedRootItems
|
|
117
|
+
} = updateRootItems(items, allItems, options);
|
|
118
|
+
this.keysCache = keysCache;
|
|
119
|
+
return updatedRootItems;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const {
|
|
123
|
+
keysCache,
|
|
124
|
+
items: updatedItems
|
|
125
|
+
} = updateChildItems(items, allItems, parentItem, options);
|
|
126
|
+
this.keysCache = keysCache;
|
|
127
|
+
return updatedItems;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
4
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
5
|
import _inherits from "@babel/runtime/helpers/inherits";
|
|
@@ -7,11 +8,12 @@ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
|
7
8
|
|
|
8
9
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
10
|
|
|
10
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
11
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
11
12
|
|
|
12
13
|
import React, { Component } from 'react';
|
|
13
|
-
import
|
|
14
|
-
import
|
|
14
|
+
import CommonCell from './internal/common-cell';
|
|
15
|
+
import OverflowContainer from './internal/overflow-container';
|
|
16
|
+
import withColumnWidth from './internal/with-column-width';
|
|
15
17
|
|
|
16
18
|
var Cell = /*#__PURE__*/function (_Component) {
|
|
17
19
|
_inherits(Cell, _Component);
|
|
@@ -27,12 +29,24 @@ var Cell = /*#__PURE__*/function (_Component) {
|
|
|
27
29
|
_createClass(Cell, [{
|
|
28
30
|
key: "render",
|
|
29
31
|
value: function render() {
|
|
30
|
-
var props = this.props
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
var _this$props = this.props,
|
|
33
|
+
children = _this$props.children,
|
|
34
|
+
singleLine = _this$props.singleLine,
|
|
35
|
+
indentLevel = _this$props.indentLevel,
|
|
36
|
+
width = _this$props.width,
|
|
37
|
+
className = _this$props.className,
|
|
38
|
+
props = _objectWithoutProperties(_this$props, ["children", "singleLine", "indentLevel", "width", "className"]);
|
|
39
|
+
|
|
40
|
+
return /*#__PURE__*/React.createElement(CommonCell, _extends({
|
|
41
|
+
role: "gridcell",
|
|
42
|
+
indent: indentLevel ? "".concat(25 * indentLevel) : undefined,
|
|
43
|
+
style: {
|
|
44
|
+
width: width
|
|
45
|
+
},
|
|
46
|
+
className: className
|
|
33
47
|
}, props), /*#__PURE__*/React.createElement(OverflowContainer, {
|
|
34
|
-
|
|
35
|
-
},
|
|
48
|
+
isSingleLine: singleLine
|
|
49
|
+
}, children));
|
|
36
50
|
}
|
|
37
51
|
}]);
|
|
38
52
|
|
|
@@ -7,11 +7,23 @@ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
|
7
7
|
|
|
8
8
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
9
|
|
|
10
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
11
|
+
|
|
12
|
+
/** @jsx jsx */
|
|
13
|
+
|
|
14
|
+
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
15
|
+
import { Component } from 'react';
|
|
16
|
+
import { css, jsx } from '@emotion/core';
|
|
17
|
+
import { N300 } from '@atlaskit/theme/colors';
|
|
18
|
+
import ColumnCell from './internal/common-cell';
|
|
19
|
+
import withColumnWidth from './internal/with-column-width';
|
|
20
|
+
var headerStyles = css({
|
|
21
|
+
color: "var(--ds-text-mediumEmphasis, ".concat(N300, ")"),
|
|
22
|
+
fontSize: 12,
|
|
23
|
+
fontWeight: 'bold',
|
|
24
|
+
letterSpacing: -0.1,
|
|
25
|
+
lineHeight: '1.67'
|
|
26
|
+
});
|
|
15
27
|
|
|
16
28
|
var Header = /*#__PURE__*/function (_Component) {
|
|
17
29
|
_inherits(Header, _Component);
|
|
@@ -28,8 +40,12 @@ var Header = /*#__PURE__*/function (_Component) {
|
|
|
28
40
|
key: "render",
|
|
29
41
|
value: function render() {
|
|
30
42
|
var props = this.props;
|
|
31
|
-
return
|
|
32
|
-
|
|
43
|
+
return jsx(ColumnCell, _extends({
|
|
44
|
+
css: headerStyles,
|
|
45
|
+
role: "columnheader",
|
|
46
|
+
style: {
|
|
47
|
+
width: props.width
|
|
48
|
+
}
|
|
33
49
|
}, props), props.children);
|
|
34
50
|
}
|
|
35
51
|
}]);
|
|
@@ -6,10 +6,17 @@ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
|
6
6
|
|
|
7
7
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
8
|
|
|
9
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
9
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** @jsx jsx */
|
|
12
|
+
|
|
13
|
+
/* eslint-disable @repo/internal/react/no-clone-element */
|
|
14
|
+
import { Children, cloneElement, Component } from 'react';
|
|
15
|
+
import { css, jsx } from '@emotion/core';
|
|
16
|
+
var containerStyles = css({
|
|
17
|
+
display: 'flex',
|
|
18
|
+
borderBottom: "solid 2px ".concat("var(--ds-border-neutral, #dfe1e6)")
|
|
19
|
+
});
|
|
13
20
|
|
|
14
21
|
var Headers = /*#__PURE__*/function (_Component) {
|
|
15
22
|
_inherits(Headers, _Component);
|
|
@@ -25,13 +32,14 @@ var Headers = /*#__PURE__*/function (_Component) {
|
|
|
25
32
|
_createClass(Headers, [{
|
|
26
33
|
key: "render",
|
|
27
34
|
value: function render() {
|
|
28
|
-
return
|
|
35
|
+
return jsx("div", {
|
|
36
|
+
css: containerStyles,
|
|
29
37
|
role: "row"
|
|
30
|
-
},
|
|
38
|
+
}, Children.map(this.props.children, function (header, index) {
|
|
31
39
|
return (
|
|
32
40
|
/*#__PURE__*/
|
|
33
41
|
// eslint-disable-next-line react/no-array-index-key
|
|
34
|
-
|
|
42
|
+
cloneElement(header, {
|
|
35
43
|
key: index,
|
|
36
44
|
columnIndex: index
|
|
37
45
|
})
|