sea-chart 1.1.21 → 1.1.22-alpha.2

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 (64) hide show
  1. package/dist/components/data-process-setter/data-setting-header.js +11 -0
  2. package/dist/components/data-process-setter/hide-column-setter.js +79 -0
  3. package/dist/components/data-process-setter/index.js +4 -0
  4. package/dist/components/data-process-setter/sort-setter.js +75 -0
  5. package/dist/components/popover/hide-column-popover/hide-column-popover-widgets/hide-column-item.js +60 -0
  6. package/dist/components/popover/hide-column-popover/hide-column-popover.css +38 -0
  7. package/dist/components/popover/hide-column-popover/hide-column-popover.js +208 -0
  8. package/dist/components/popover/sort-popover/sort-popover-widgets/sort-utils.js +71 -0
  9. package/dist/components/popover/sort-popover/sort-popover.css +83 -0
  10. package/dist/components/popover/sort-popover/sort-popover.js +290 -0
  11. package/dist/components/types-dialog/index.js +5 -2
  12. package/dist/constants/common-constants.js +3 -1
  13. package/dist/constants/index.js +1 -1
  14. package/dist/constants/type-image.js +2 -1
  15. package/dist/constants/type.js +5 -3
  16. package/dist/context.js +1 -1
  17. package/dist/locale/lang/de.js +17 -2
  18. package/dist/locale/lang/en.js +16 -1
  19. package/dist/locale/lang/es.js +16 -1
  20. package/dist/locale/lang/fr.js +17 -2
  21. package/dist/locale/lang/pt.js +16 -1
  22. package/dist/locale/lang/ru.js +16 -1
  23. package/dist/locale/lang/zh_CN.js +16 -1
  24. package/dist/model/index.js +3 -1
  25. package/dist/model/table-element.js +22 -0
  26. package/dist/settings/data-settings.js +5 -0
  27. package/dist/settings/table-element-settings/components/data-filter.css +17 -0
  28. package/dist/settings/table-element-settings/components/data-filter.js +89 -0
  29. package/dist/settings/table-element-settings/data-settings.js +100 -0
  30. package/dist/settings/table-element-settings/index.css +190 -0
  31. package/dist/settings/table-element-settings/index.js +2 -0
  32. package/dist/settings/widgets/chart-type/index.js +3 -1
  33. package/dist/settings/widgets/common-data-settings.js +1 -0
  34. package/dist/settings/widgets/data-filter/index.css +1 -1
  35. package/dist/utils/chart-utils/base-utils.js +7 -1
  36. package/dist/utils/chart-utils/index.js +5 -5
  37. package/dist/utils/chart-utils/original-data-utils/index.js +2 -2
  38. package/dist/utils/chart-utils/sql-statistics-utils.js +10 -4
  39. package/dist/utils/chart.js +9 -1
  40. package/dist/utils/hotkey.js +5 -0
  41. package/dist/utils/row-utils.js +10 -1
  42. package/dist/utils/sql/chart-data-sql.js +4 -0
  43. package/dist/utils/sql/column-2-sql-column.js +4 -0
  44. package/dist/view/index.css +5 -1
  45. package/dist/view/index.js +56 -14
  46. package/dist/view/wrapper/bar-group.js +1 -1
  47. package/dist/view/wrapper/index.js +7 -0
  48. package/dist/view/wrapper/table-element/components/dataset-utils.js +123 -0
  49. package/dist/view/wrapper/table-element/components/formatter.js +309 -0
  50. package/dist/view/wrapper/table-element/components/formula-formatter.js +36 -0
  51. package/dist/view/wrapper/table-element/components/link-formatter.js +269 -0
  52. package/dist/view/wrapper/table-element/components/record.js +67 -0
  53. package/dist/view/wrapper/table-element/components/records-body.js +117 -0
  54. package/dist/view/wrapper/table-element/components/records-header/index.js +41 -0
  55. package/dist/view/wrapper/table-element/components/records-header/records-header-cell.js +51 -0
  56. package/dist/view/wrapper/table-element/components/records.js +117 -0
  57. package/dist/view/wrapper/table-element/components/resize-column-handle/index.css +11 -0
  58. package/dist/view/wrapper/table-element/components/resize-column-handle/resize-column-handle.js +48 -0
  59. package/dist/view/wrapper/table-element/components/value-display-utils.js +13 -0
  60. package/dist/view/wrapper/table-element/components/vertical-scrollbar/index.css +12 -0
  61. package/dist/view/wrapper/table-element/components/vertical-scrollbar/index.js +36 -0
  62. package/dist/view/wrapper/table-element/css/index.css +239 -0
  63. package/dist/view/wrapper/table-element/index.js +101 -0
  64. package/package.json +1 -1
@@ -0,0 +1,269 @@
1
+ import _LongTextFormatter from "dtable-ui-component/lib/LongTextFormatter";
2
+ import _CheckboxFormatter from "dtable-ui-component/lib/CheckboxFormatter";
3
+ import _MultipleSelectFormatter from "dtable-ui-component/lib/MultipleSelectFormatter";
4
+ import _LastModifierFormatter from "dtable-ui-component/lib/LastModifierFormatter";
5
+ import _CreatorFormatter from "dtable-ui-component/lib/CreatorFormatter";
6
+ import _MTimeFormatter from "dtable-ui-component/lib/MTimeFormatter";
7
+ import _CTimeFormatter from "dtable-ui-component/lib/CTimeFormatter";
8
+ import _DateFormatter from "dtable-ui-component/lib/DateFormatter";
9
+ import _NumberFormatter from "dtable-ui-component/lib/NumberFormatter";
10
+ import React from 'react';
11
+ import { CellType, FORMULA_RESULT_TYPE, getDurationDisplayString, getGeolocationDisplayString, getMultipleOptionName } from 'dtable-utils';
12
+ import { getCellDisplayValue } from './value-display-utils';
13
+ import { getFormulaArrayValue, isArrayFormalColumn } from './dataset-utils';
14
+ function LinkFormatter(props) {
15
+ const {
16
+ column,
17
+ value,
18
+ containerClassName,
19
+ collaborators
20
+ } = props;
21
+ const {
22
+ data
23
+ } = column;
24
+ if (!Array.isArray(value) || value.length === 0) return props.renderEmptyFormatter();
25
+ let {
26
+ display_column: displayColumn
27
+ } = data || {};
28
+ if (!displayColumn) return props.renderEmptyFormatter();
29
+ const {
30
+ type: displayColumnType,
31
+ data: displayColumnData
32
+ } = displayColumn;
33
+ const cellValue = getFormulaArrayValue(value, !isArrayFormalColumn(displayColumnType));
34
+ if (!Array.isArray(cellValue) || cellValue.length === 0) return props.renderEmptyFormatter();
35
+ switch (displayColumnType) {
36
+ case CellType.TEXT:
37
+ case CellType.AUTO_NUMBER:
38
+ case CellType.EMAIL:
39
+ case CellType.URL:
40
+ {
41
+ return /*#__PURE__*/React.createElement("div", {
42
+ className: containerClassName
43
+ }, cellValue.map((value, index) => {
44
+ if (!value) return null;
45
+ return /*#__PURE__*/React.createElement("div", {
46
+ key: "link-".concat(displayColumnType, "-").concat(index),
47
+ className: "table-element-link-item"
48
+ }, value);
49
+ }));
50
+ }
51
+ case CellType.NUMBER:
52
+ {
53
+ return /*#__PURE__*/React.createElement("div", {
54
+ className: containerClassName
55
+ }, cellValue.map((value, index) => {
56
+ if (!value && value !== 0) return null;
57
+ return /*#__PURE__*/React.createElement(_NumberFormatter, {
58
+ key: "link-".concat(displayColumnType, "-").concat(index),
59
+ containerClassName: "table-element-link-item",
60
+ data: displayColumnData || {},
61
+ value: value
62
+ });
63
+ }));
64
+ }
65
+ case CellType.DATE:
66
+ {
67
+ return /*#__PURE__*/React.createElement("div", {
68
+ className: containerClassName
69
+ }, cellValue.map((value, index) => {
70
+ if (!value || typeof value !== 'string') return null;
71
+ const {
72
+ format
73
+ } = displayColumnData || {};
74
+ return /*#__PURE__*/React.createElement(_DateFormatter, {
75
+ key: "link-".concat(displayColumnType, "-").concat(index),
76
+ value: value,
77
+ format: format,
78
+ containerClassName: "table-element-link-item"
79
+ });
80
+ }));
81
+ }
82
+ case CellType.CTIME:
83
+ {
84
+ return /*#__PURE__*/React.createElement("div", {
85
+ className: containerClassName
86
+ }, cellValue.map((value, index) => {
87
+ if (!value) return null;
88
+ return /*#__PURE__*/React.createElement(_CTimeFormatter, {
89
+ key: "link-".concat(displayColumnType, "-").concat(index),
90
+ value: value,
91
+ containerClassName: "table-element-link-item"
92
+ });
93
+ }));
94
+ }
95
+ case CellType.MTIME:
96
+ {
97
+ return /*#__PURE__*/React.createElement("div", {
98
+ className: containerClassName
99
+ }, cellValue.map((value, index) => {
100
+ if (!value) return null;
101
+ return /*#__PURE__*/React.createElement(_MTimeFormatter, {
102
+ key: "link-".concat(displayColumnType, "-").concat(index),
103
+ value: value,
104
+ containerClassName: "table-element-link-item"
105
+ });
106
+ }));
107
+ }
108
+ case CellType.DURATION:
109
+ {
110
+ return /*#__PURE__*/React.createElement("div", {
111
+ className: containerClassName
112
+ }, cellValue.map((value, index) => {
113
+ if (!value) return null;
114
+ return /*#__PURE__*/React.createElement("div", {
115
+ key: "link-".concat(displayColumnType, "-").concat(index),
116
+ className: "table-element-link-item"
117
+ }, getDurationDisplayString(value, displayColumnData));
118
+ }));
119
+ }
120
+ case CellType.CREATOR:
121
+ {
122
+ props.queryUsers([cellValue]);
123
+ return /*#__PURE__*/React.createElement(_CreatorFormatter, {
124
+ collaborators: collaborators,
125
+ value: cellValue
126
+ });
127
+ }
128
+ case CellType.LAST_MODIFIER:
129
+ {
130
+ props.queryUsers([cellValue]);
131
+ return /*#__PURE__*/React.createElement(_LastModifierFormatter, {
132
+ collaborators: collaborators,
133
+ value: cellValue
134
+ });
135
+ }
136
+ case CellType.SINGLE_SELECT:
137
+ {
138
+ if (!cellValue || cellValue.length === 0) {
139
+ return props.renderEmptyFormatter();
140
+ }
141
+ const options = displayColumnData && Array.isArray(displayColumnData.options) ? displayColumnData.options : [];
142
+ return /*#__PURE__*/React.createElement(_MultipleSelectFormatter, {
143
+ value: cellValue,
144
+ options: options || [],
145
+ containerClassName: "table-element-".concat(displayColumnType, "-formatter")
146
+ });
147
+ }
148
+ case CellType.MULTIPLE_SELECT:
149
+ {
150
+ if (!cellValue || cellValue.length === 0) {
151
+ return props.renderEmptyFormatter();
152
+ }
153
+ const options = displayColumnData && Array.isArray(displayColumnData.options) ? displayColumnData.options : [];
154
+ return /*#__PURE__*/React.createElement("div", {
155
+ className: containerClassName
156
+ }, cellValue.map((value, index) => {
157
+ if (!value) return null;
158
+ const valueDisplayString = Array.isArray(value) ? getMultipleOptionName(options, value) : getMultipleOptionName(options, [value]);
159
+ return /*#__PURE__*/React.createElement("div", {
160
+ key: "link-".concat(displayColumnType, "-").concat(index),
161
+ className: "table-element-link-item"
162
+ }, valueDisplayString);
163
+ }));
164
+ }
165
+ case CellType.COLLABORATOR:
166
+ {
167
+ if (!cellValue || cellValue.length === 0) {
168
+ return props.renderEmptyFormatter();
169
+ }
170
+ props.queryUsers(cellValue);
171
+ return /*#__PURE__*/React.createElement("div", {
172
+ className: containerClassName
173
+ }, cellValue.map((value, index) => {
174
+ if (!value) return null;
175
+ const valueDisplayString = Array.isArray(value) ? getCellDisplayValue({
176
+ [displayColumn.key]: value
177
+ }, displayColumn, collaborators) : getCellDisplayValue({
178
+ [displayColumn.key]: [value]
179
+ }, displayColumn, collaborators);
180
+ return /*#__PURE__*/React.createElement("div", {
181
+ key: "link-".concat(displayColumnType, "-").concat(index),
182
+ className: "table-element-link-item"
183
+ }, valueDisplayString);
184
+ }));
185
+ }
186
+ case CellType.CHECKBOX:
187
+ {
188
+ return /*#__PURE__*/React.createElement("div", {
189
+ className: containerClassName
190
+ }, cellValue.map((value, index) => {
191
+ return /*#__PURE__*/React.createElement(_CheckboxFormatter, {
192
+ key: "link-".concat(displayColumnType, "-").concat(index),
193
+ value: Boolean(value),
194
+ containerClassName: "table-element-".concat(displayColumnType, "-item")
195
+ });
196
+ }));
197
+ }
198
+ case CellType.GEOLOCATION:
199
+ {
200
+ return /*#__PURE__*/React.createElement("div", {
201
+ className: containerClassName
202
+ }, cellValue.map((value, index) => {
203
+ if (!value) return null;
204
+ return /*#__PURE__*/React.createElement("div", {
205
+ key: "link-".concat(displayColumnType, "-").concat(index),
206
+ className: "table-element-link-item"
207
+ }, getGeolocationDisplayString(value, displayColumnData, {
208
+ hyphen: ' '
209
+ }));
210
+ }));
211
+ }
212
+ case CellType.LONG_TEXT:
213
+ {
214
+ return /*#__PURE__*/React.createElement("div", {
215
+ className: containerClassName
216
+ }, cellValue.map((value, index) => {
217
+ if (!value) return null;
218
+ return /*#__PURE__*/React.createElement(_LongTextFormatter, {
219
+ key: "link-".concat(displayColumnType, "-").concat(index),
220
+ value: value,
221
+ containerClassName: "table-element-".concat(displayColumnType, "-item")
222
+ });
223
+ }));
224
+ }
225
+ case CellType.FORMULA:
226
+ case CellType.LINK_FORMULA:
227
+ {
228
+ return /*#__PURE__*/React.createElement("div", {
229
+ className: containerClassName
230
+ }, cellValue.map((value, index) => {
231
+ if (!value) return null;
232
+ return /*#__PURE__*/React.createElement("div", {
233
+ key: "link-".concat(displayColumnType, "-").concat(index),
234
+ className: "table-element-link-item"
235
+ }, getCellDisplayValue({
236
+ [displayColumn.key]: value
237
+ }, displayColumn, collaborators));
238
+ }));
239
+ }
240
+ case FORMULA_RESULT_TYPE.BOOL:
241
+ {
242
+ return /*#__PURE__*/React.createElement("div", {
243
+ className: containerClassName
244
+ }, cellValue.map((value, index) => {
245
+ return /*#__PURE__*/React.createElement("div", {
246
+ key: "link-".concat(displayColumnType, "-").concat(index),
247
+ className: "table-element-link-item"
248
+ }, value + '');
249
+ }));
250
+ }
251
+ case FORMULA_RESULT_TYPE.STRING:
252
+ {
253
+ return /*#__PURE__*/React.createElement("div", {
254
+ className: containerClassName
255
+ }, cellValue.map((value, index) => {
256
+ if (!value) return null;
257
+ return /*#__PURE__*/React.createElement("div", {
258
+ key: "link-".concat(displayColumnType, "-").concat(index),
259
+ className: "table-element-link-item"
260
+ }, value);
261
+ }));
262
+ }
263
+ default:
264
+ {
265
+ return props.renderEmptyFormatter();
266
+ }
267
+ }
268
+ }
269
+ export default LinkFormatter;
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ import { CellType } from 'dtable-utils';
3
+ import Formatter from './formatter';
4
+ function Record(_ref) {
5
+ let {
6
+ columns,
7
+ record,
8
+ index,
9
+ collaborators,
10
+ queryUsers
11
+ } = _ref;
12
+ return /*#__PURE__*/React.createElement("div", {
13
+ className: 'table-element-result-table-row'
14
+ }, columns.map(column => {
15
+ const {
16
+ key,
17
+ name,
18
+ width,
19
+ type,
20
+ data
21
+ } = column;
22
+ const value = record[name] !== undefined && record[name] !== null ? record[name] : record[key];
23
+ let className = 'table-element-result-table-cell ';
24
+ if (type === CellType.FORMULA || type === CellType.LINK_FORMULA) {
25
+ className += 'table-element-result-table-formula-cell ';
26
+ const {
27
+ array_type
28
+ } = data || {};
29
+ if (array_type === CellType.IMAGE || array_type === CellType.FILE) {
30
+ className += 'table-element-result-table-formula-image-cell';
31
+ }
32
+ } else {
33
+ className += "table-element-result-table-".concat(type, "-cell");
34
+ }
35
+ return /*#__PURE__*/React.createElement("div", {
36
+ key: "".concat(key, "-").concat({
37
+ index
38
+ }),
39
+ className: className,
40
+ style: {
41
+ width,
42
+ maxWidth: width,
43
+ minWidth: width
44
+ }
45
+ }, /*#__PURE__*/React.createElement(Formatter, {
46
+ collaborators: collaborators,
47
+ cellValue: value,
48
+ column: column,
49
+ row: record,
50
+ queryUsers: queryUsers
51
+ }));
52
+ }));
53
+ }
54
+ const memoized = React.memo(Record, (prevProps, nextProps) => {
55
+ const {
56
+ record: prevRecord
57
+ } = prevProps;
58
+ const {
59
+ record: nextRecord
60
+ } = nextProps;
61
+ if (prevRecord._id !== nextRecord._id) {
62
+ return true;
63
+ } else {
64
+ return false;
65
+ }
66
+ });
67
+ export default memoized;
@@ -0,0 +1,117 @@
1
+ import React, { Component } from 'react';
2
+ import { throttle } from 'lodash-es';
3
+ import Record from './record';
4
+ const ROW_HEIGHT = 33;
5
+ const RENDER_MORE_NUMBER = 10;
6
+ class RecordsBody extends Component {
7
+ constructor(props) {
8
+ super(props);
9
+ this.getInitEndIndex = () => {
10
+ var _this$props$records;
11
+ const recordsCount = ((_this$props$records = this.props.records) === null || _this$props$records === void 0 ? void 0 : _this$props$records.length) || 0;
12
+ const containerHeight = this.tableElementResultContentRef.clientHeight;
13
+ const endVisibleIndex = Math.min(Math.ceil(containerHeight / ROW_HEIGHT), recordsCount);
14
+ const endRenderIndex = Math.min(endVisibleIndex + RENDER_MORE_NUMBER, recordsCount);
15
+ return {
16
+ endVisibleIndex,
17
+ endRenderIndex
18
+ };
19
+ };
20
+ this.handleContainerResize = throttle(() => {
21
+ this.recalculate();
22
+ }, 100);
23
+ this.recalculate = () => {
24
+ if (!this.tableElementResultContentRef) return;
25
+ const {
26
+ setVerticalScrollbarTop,
27
+ records
28
+ } = this.props;
29
+ const {
30
+ startRenderIndex,
31
+ endRenderIndex
32
+ } = this.state;
33
+ const recordsCount = (records === null || records === void 0 ? void 0 : records.length) || 0;
34
+ const {
35
+ clientHeight,
36
+ scrollTop
37
+ } = this.tableElementResultContentRef;
38
+ const newStart = Math.max(0, Math.ceil(scrollTop / ROW_HEIGHT) - RENDER_MORE_NUMBER);
39
+ const newEnd = Math.min(recordsCount, Math.ceil((scrollTop + clientHeight) / ROW_HEIGHT) + RENDER_MORE_NUMBER);
40
+ if (Math.abs(newStart - startRenderIndex) > 5 || newStart < 5) {
41
+ this.setState({
42
+ startRenderIndex: newStart
43
+ });
44
+ }
45
+ if (Math.abs(newEnd - endRenderIndex) > 5 || newEnd > recordsCount - 5) {
46
+ this.setState({
47
+ endRenderIndex: newEnd
48
+ });
49
+ }
50
+ setVerticalScrollbarTop(scrollTop);
51
+ };
52
+ this.onScroll = () => {
53
+ this.recalculate();
54
+ };
55
+ this.setContentScrollTop = scrollTop => {
56
+ this.tableElementResultContentRef.scrollTop = scrollTop;
57
+ };
58
+ this.state = {
59
+ startRenderIndex: 0,
60
+ endRenderIndex: 0
61
+ };
62
+ this.startVisibleIndex = 0;
63
+ this.endVisibleIndex = 0;
64
+ this.tableElementResultContentRef = null;
65
+ }
66
+ componentDidMount() {
67
+ const {
68
+ endVisibleIndex,
69
+ endRenderIndex
70
+ } = this.getInitEndIndex();
71
+ this.endVisibleIndex = endVisibleIndex;
72
+ this.setState({
73
+ endRenderIndex
74
+ });
75
+ const resizeObserver = new ResizeObserver(() => {
76
+ this.handleContainerResize();
77
+ });
78
+ resizeObserver.observe(this.tableElementResultContentRef);
79
+ }
80
+ render() {
81
+ const {
82
+ records,
83
+ collaborators,
84
+ columns
85
+ } = this.props;
86
+ const {
87
+ startRenderIndex,
88
+ endRenderIndex
89
+ } = this.state;
90
+ const recordsCount = (records === null || records === void 0 ? void 0 : records.length) || 0;
91
+ const renderingRecords = records.slice(startRenderIndex, endRenderIndex);
92
+ const upperHeight = startRenderIndex * ROW_HEIGHT;
93
+ const belowHeight = (recordsCount - endRenderIndex) * ROW_HEIGHT;
94
+ return /*#__PURE__*/React.createElement("div", {
95
+ className: "table-element-result-table-content",
96
+ onScroll: this.onScroll,
97
+ ref: ref => this.tableElementResultContentRef = ref
98
+ }, /*#__PURE__*/React.createElement("div", {
99
+ className: "table-element-result-table",
100
+ style: {
101
+ paddingTop: upperHeight,
102
+ paddingBottom: belowHeight
103
+ }
104
+ }, renderingRecords.map((record, index) => {
105
+ return /*#__PURE__*/React.createElement(Record, {
106
+ key: record._id || index,
107
+ columns: columns,
108
+ record: record,
109
+ index: index,
110
+ collaborators: collaborators,
111
+ isLastRecord: records.length - 1 === index,
112
+ queryUsers: this.props.queryUsers
113
+ });
114
+ })));
115
+ }
116
+ }
117
+ export default RecordsBody;
@@ -0,0 +1,41 @@
1
+ import React, { Component } from 'react';
2
+ import RecordsHeaderCell from './records-header-cell';
3
+ class RecordsHeader extends Component {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.onMouseEnter = () => {
7
+ const dragHandles = document.querySelectorAll('.sea-chart-record-HeaderCell__draggable');
8
+ if (!dragHandles) return;
9
+ dragHandles.forEach(dragHandle => {
10
+ dragHandle.style.backgroundColor = '#999999';
11
+ });
12
+ };
13
+ this.onMouseLeave = () => {
14
+ const dragHandles = document.querySelectorAll('.sea-chart-record-HeaderCell__draggable');
15
+ if (!dragHandles) return;
16
+ dragHandles.forEach(dragHandle => {
17
+ dragHandle.style.backgroundColor = 'unset';
18
+ });
19
+ };
20
+ }
21
+ render() {
22
+ const {
23
+ columns,
24
+ resizeColumnWidth,
25
+ resizeColumnWidthEnd
26
+ } = this.props;
27
+ return /*#__PURE__*/React.createElement("div", {
28
+ className: "static-table-element-result-content",
29
+ onMouseEnter: this.onMouseEnter,
30
+ onMouseLeave: this.onMouseLeave
31
+ }, /*#__PURE__*/React.createElement("div", {
32
+ className: "table-element-result-table-row"
33
+ }, columns.map((column, index) => /*#__PURE__*/React.createElement(RecordsHeaderCell, {
34
+ column: column,
35
+ key: index,
36
+ resizeColumnWidth: resizeColumnWidth,
37
+ resizeColumnWidthEnd: resizeColumnWidthEnd
38
+ }))));
39
+ }
40
+ }
41
+ export default RecordsHeader;
@@ -0,0 +1,51 @@
1
+ import React, { useRef } from 'react';
2
+ import ResizeColumnHandle from '../resize-column-handle/resize-column-handle';
3
+ export default function RecordsHeaderCell(_ref) {
4
+ let {
5
+ column,
6
+ resizeColumnWidth,
7
+ resizeColumnWidthEnd
8
+ // onDrag, onDragEnd
9
+ } = _ref;
10
+ const {
11
+ name,
12
+ width
13
+ } = column;
14
+ const headerCellRef = useRef(null);
15
+ const getWidthFromMouseEvent = e => {
16
+ let right = e.pageX || e.touches && e.touches[0] && e.touches[0].pageX || e.changedTouches && e.changedTouches[e.changedTouches.length - 1].pageX;
17
+ if (e.pageX === 0) {
18
+ right = 0;
19
+ }
20
+ const left = headerCellRef.current.getBoundingClientRect().left;
21
+ return right - left;
22
+ };
23
+ const onDragEnd = e => {
24
+ const width = getWidthFromMouseEvent(e);
25
+ if (width > 0) {
26
+ resizeColumnWidthEnd(column, width);
27
+ }
28
+ };
29
+ const onDrag = e => {
30
+ const width = getWidthFromMouseEvent(e);
31
+ if (width > 0) {
32
+ resizeColumnWidth(column, width);
33
+ }
34
+ };
35
+ return /*#__PURE__*/React.createElement("div", {
36
+ className: "table-element-header-cell"
37
+ }, /*#__PURE__*/React.createElement("div", {
38
+ ref: headerCellRef,
39
+ className: "table-element-result-table-cell column",
40
+ style: {
41
+ width,
42
+ maxWidth: width,
43
+ minWidth: width
44
+ }
45
+ }, /*#__PURE__*/React.createElement("div", {
46
+ className: "table-element-result-column-content text-truncate"
47
+ }, name)), /*#__PURE__*/React.createElement(ResizeColumnHandle, {
48
+ onDrag: onDrag,
49
+ onDragEnd: onDragEnd
50
+ }));
51
+ }
@@ -0,0 +1,117 @@
1
+ import React, { Component } from 'react';
2
+ import { CellType } from 'dtable-utils';
3
+ // import { resizeColumn } from '../../../../../../seatable-app-universal/src/data-search/utils/column-metrics';
4
+ import { resizeColumn } from '../../../../utils/row-utils';
5
+ import RecordsHeader from './records-header';
6
+ import RecordsBody from './records-body';
7
+ // import RecordsFooter from './records-footer';
8
+ import { DATASET_NOT_SUPPORT_COLUMN_TYPES, getCellRecordWidth } from './dataset-utils';
9
+ import VerticalScrollbar from './vertical-scrollbar';
10
+ class Records extends Component {
11
+ constructor(props) {
12
+ super(props);
13
+ this.calcuteDisplayColumns = shownColumns => {
14
+ return shownColumns.filter(column => !DATASET_NOT_SUPPORT_COLUMN_TYPES.includes(column.type)).map(column => {
15
+ const {
16
+ type
17
+ } = column;
18
+ if (type === CellType.LINK) {
19
+ const {
20
+ data
21
+ } = column;
22
+ const {
23
+ display_column_key,
24
+ array_type,
25
+ array_data
26
+ } = data;
27
+ const display_column = {
28
+ key: display_column_key || '0000',
29
+ type: array_type || CellType.TEXT,
30
+ data: array_data || null
31
+ };
32
+ return {
33
+ ...column,
34
+ width: getCellRecordWidth(column),
35
+ data: {
36
+ ...data,
37
+ display_column
38
+ }
39
+ };
40
+ }
41
+ return {
42
+ ...column,
43
+ width: getCellRecordWidth(column)
44
+ };
45
+ });
46
+ };
47
+ this.resizeColumnWidth = (column, width) => {
48
+ const {
49
+ displayColumns
50
+ } = this.state;
51
+ const newDisplayColumns = resizeColumn(column.key, Math.max(width, 50), displayColumns);
52
+ this.setState({
53
+ headerDisplayColumns: newDisplayColumns
54
+ });
55
+ };
56
+ this.resizeColumnWidthEnd = (column, width) => {
57
+ this.setState({
58
+ displayColumns: this.state.headerDisplayColumns
59
+ });
60
+ };
61
+ this.setVerticalScrollbarTop = scrollTop => {
62
+ if (this.verticalScrollbar) {
63
+ this.verticalScrollbar.setScrollTop(scrollTop);
64
+ }
65
+ };
66
+ this.onVerticalScrollbarScroll = scrollTop => {
67
+ this.recordsBody.setContentScrollTop(scrollTop);
68
+ };
69
+ this.state = {
70
+ scrollLeft: 0
71
+ };
72
+ this.resultContainerRef = null;
73
+ const _displayColumns = this.calcuteDisplayColumns(props.shownColumns);
74
+ this.state = {
75
+ displayColumns: _displayColumns,
76
+ headerDisplayColumns: _displayColumns
77
+ };
78
+ }
79
+ render() {
80
+ const {
81
+ records,
82
+ collaborators
83
+ } = this.props;
84
+ const {
85
+ displayColumns,
86
+ headerDisplayColumns
87
+ } = this.state;
88
+ const totalWidth = displayColumns.reduce((cur, nextItem) => {
89
+ return cur + nextItem.width;
90
+ }, 0);
91
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
92
+ className: "table-element-container",
93
+ ref: ref => this.resultContainerRef = ref
94
+ }, /*#__PURE__*/React.createElement("div", {
95
+ className: "table-element-result-content",
96
+ style: {
97
+ width: totalWidth
98
+ }
99
+ }, /*#__PURE__*/React.createElement(RecordsHeader, {
100
+ columns: headerDisplayColumns,
101
+ resizeColumnWidth: this.resizeColumnWidth,
102
+ resizeColumnWidthEnd: this.resizeColumnWidthEnd
103
+ }), /*#__PURE__*/React.createElement(RecordsBody, {
104
+ ref: ref => this.recordsBody = ref,
105
+ records: records,
106
+ columns: displayColumns,
107
+ collaborators: collaborators,
108
+ queryUsers: this.props.queryUsers,
109
+ setVerticalScrollbarTop: this.setVerticalScrollbarTop
110
+ })), /*#__PURE__*/React.createElement(VerticalScrollbar, {
111
+ contentHeight: 33 * records.length,
112
+ ref: ref => this.verticalScrollbar = ref,
113
+ onScrollbarScroll: this.onVerticalScrollbarScroll
114
+ })));
115
+ }
116
+ }
117
+ export default Records;
@@ -0,0 +1,11 @@
1
+ .sea-chart-record-HeaderCell__draggable {
2
+ position: absolute;
3
+ top: 0px;
4
+ right: -2px;
5
+ width: 3px;
6
+ border-radius: 2px;
7
+ margin: 3px 0px;
8
+ height: 80%;
9
+ cursor: col-resize;
10
+ z-index: 1;
11
+ }