dtable-ui-component 0.2.7 → 0.2.8-beta

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 (109) hide show
  1. package/lib/DTableRadio/index.css +14 -2
  2. package/lib/DTableRadio/index.js +7 -5
  3. package/package.json +1 -1
  4. package/es/app.css +0 -20
  5. package/es/app.js +0 -91
  6. package/es/assets/images/avatar/default_avatar.png +0 -0
  7. package/es/assets/images/file/192/excel.png +0 -0
  8. package/es/assets/images/file/192/file.png +0 -0
  9. package/es/assets/images/file/192/music.png +0 -0
  10. package/es/assets/images/file/192/pdf.png +0 -0
  11. package/es/assets/images/file/192/pic.png +0 -0
  12. package/es/assets/images/file/192/ppt.png +0 -0
  13. package/es/assets/images/file/192/txt.png +0 -0
  14. package/es/assets/images/file/192/video.png +0 -0
  15. package/es/assets/images/file/192/word.png +0 -0
  16. package/es/assets/images/file/24/excel.png +0 -0
  17. package/es/assets/images/file/24/file.png +0 -0
  18. package/es/assets/images/file/24/music.png +0 -0
  19. package/es/assets/images/file/24/pdf.png +0 -0
  20. package/es/assets/images/file/24/pic.png +0 -0
  21. package/es/assets/images/file/24/ppt.png +0 -0
  22. package/es/assets/images/file/24/txt.png +0 -0
  23. package/es/assets/images/file/24/video.png +0 -0
  24. package/es/assets/images/file/24/word.png +0 -0
  25. package/es/assets/images/folder/folder-192.png +0 -0
  26. package/es/assets/images/folder/folder-24.png +0 -0
  27. package/es/components/cell-editor/checkbox-editor.js +0 -104
  28. package/es/components/cell-editor/collaborator-editor.js +0 -236
  29. package/es/components/cell-editor/date-editor.js +0 -151
  30. package/es/components/cell-editor/index.js +0 -9
  31. package/es/components/cell-editor/link-editor.js +0 -303
  32. package/es/components/cell-editor/multiple-select-editor.js +0 -237
  33. package/es/components/cell-editor/number-editor.js +0 -154
  34. package/es/components/cell-editor/single-select-editor.js +0 -202
  35. package/es/components/cell-editor/text-editor.js +0 -122
  36. package/es/components/cell-editor-dialog/pc-file-editor-dialog.js +0 -46
  37. package/es/components/cell-editor-dialog/pc-files-addition/index.js +0 -0
  38. package/es/components/cell-editor-dialog/pc-files-addition/pc-file-uploaded-item.js +0 -0
  39. package/es/components/cell-editor-dialog/pc-files-preview/index.js +0 -0
  40. package/es/components/cell-editor-dialog/pc-files-preview/pc-file-item-preview.js +0 -0
  41. package/es/components/cell-editor-popover/mb-collaborator-editor-popover.js +0 -177
  42. package/es/components/cell-editor-popover/mb-date-editor-popover.js +0 -245
  43. package/es/components/cell-editor-popover/mb-link-editor-popover.js +0 -170
  44. package/es/components/cell-editor-popover/mb-select-editor-popover.js +0 -230
  45. package/es/components/cell-editor-popover/pc-collaborator-editor-popover.js +0 -109
  46. package/es/components/cell-editor-popover/pc-date-editor-popover.js +0 -142
  47. package/es/components/cell-editor-popover/pc-link-editor-popover.js +0 -114
  48. package/es/components/cell-editor-popover/pc-select-editor-popover.js +0 -143
  49. package/es/components/cell-factory/cell-formatter-factory.js +0 -25
  50. package/es/components/cell-formatter/auto-number-formatter.js +0 -35
  51. package/es/components/cell-formatter/button-formatter.js +0 -55
  52. package/es/components/cell-formatter/checkbox-formatter.js +0 -44
  53. package/es/components/cell-formatter/collaborator-formatter.js +0 -91
  54. package/es/components/cell-formatter/creator-formatter.js +0 -87
  55. package/es/components/cell-formatter/ctime-formatter.js +0 -57
  56. package/es/components/cell-formatter/date-formatter.js +0 -59
  57. package/es/components/cell-formatter/duration-formatter.js +0 -37
  58. package/es/components/cell-formatter/email-formatter.js +0 -35
  59. package/es/components/cell-formatter/file-formatter.js +0 -63
  60. package/es/components/cell-formatter/formatter-config.js +0 -31
  61. package/es/components/cell-formatter/formula-formatter.js +0 -173
  62. package/es/components/cell-formatter/geolocation-formatter.js +0 -49
  63. package/es/components/cell-formatter/image-formatter.js +0 -153
  64. package/es/components/cell-formatter/index.js +0 -26
  65. package/es/components/cell-formatter/last-modifier-formatter.js +0 -87
  66. package/es/components/cell-formatter/link-formatter.js +0 -144
  67. package/es/components/cell-formatter/long-text-formatter.js +0 -106
  68. package/es/components/cell-formatter/mtime-formatter.js +0 -57
  69. package/es/components/cell-formatter/multiple-select-formatter.js +0 -70
  70. package/es/components/cell-formatter/number-formatter.js +0 -46
  71. package/es/components/cell-formatter/rate-formatter.js +0 -74
  72. package/es/components/cell-formatter/single-select-formatter.js +0 -69
  73. package/es/components/cell-formatter/text-formatter.js +0 -35
  74. package/es/components/cell-formatter/url-formatter.js +0 -35
  75. package/es/components/cell-formatter/widgets/file-item-formatter.js +0 -50
  76. package/es/components/cell-formatter/widgets/image-previewer-lightbox.js +0 -119
  77. package/es/components/common/collaborator-item.js +0 -63
  78. package/es/components/common/edit-editor-button.js +0 -56
  79. package/es/components/common/images-lazy-load.js +0 -148
  80. package/es/components/common/link-editor-option.js +0 -113
  81. package/es/components/common/mobile/mb-editor-header.js +0 -48
  82. package/es/components/common/modal-portal.js +0 -44
  83. package/es/components/common/select-editor-option.js +0 -106
  84. package/es/components/common/select-item.js +0 -58
  85. package/es/components/file-uploader/index.js +0 -53
  86. package/es/components/loading.js +0 -7
  87. package/es/components/toast/alert.js +0 -150
  88. package/es/components/toast/index.js +0 -3
  89. package/es/components/toast/toast.js +0 -179
  90. package/es/components/toast/toastManager.js +0 -170
  91. package/es/components/toast/toaster.js +0 -76
  92. package/es/css/cell-editor.css +0 -614
  93. package/es/css/cell-formatter.css +0 -241
  94. package/es/css/custom-rc-calendar.css +0 -118
  95. package/es/css/image-previewer-ligntbox.css +0 -87
  96. package/es/css/loading.css +0 -54
  97. package/es/index.js +0 -5
  98. package/es/lang/index.js +0 -50
  99. package/es/locals/de.js +0 -2
  100. package/es/locals/en.js +0 -17
  101. package/es/locals/fr.js +0 -2
  102. package/es/locals/zh-CN.js +0 -17
  103. package/es/utils/cell-types.js +0 -25
  104. package/es/utils/constants.js +0 -41
  105. package/es/utils/editor-utils.js +0 -71
  106. package/es/utils/normalize-long-text-value.js +0 -68
  107. package/es/utils/number-precision.js +0 -163
  108. package/es/utils/utils.js +0 -116
  109. package/es/utils/value-format-utils.js +0 -281
@@ -1,151 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
- import React, { Fragment } from 'react';
6
- import MediaQuery from 'react-responsive';
7
- import moment from 'moment';
8
- import { formatDateToString } from '../../utils/value-format-utils';
9
- import PCDateEditorPopover from '../cell-editor-popover/pc-date-editor-popover';
10
- import MBDateEditorPopover from '../cell-editor-popover/mb-date-editor-popover';
11
-
12
- var DateEditor = /*#__PURE__*/function (_React$Component) {
13
- _inherits(DateEditor, _React$Component);
14
-
15
- var _super = _createSuper(DateEditor);
16
-
17
- function DateEditor(props) {
18
- var _this;
19
-
20
- _classCallCheck(this, DateEditor);
21
-
22
- _this = _super.call(this, props);
23
-
24
- _this.getDateFormat = function () {
25
- var column = _this.props.column;
26
- var defaultDateFormat = 'YYYY-MM-DD';
27
- var dateFormat = column.data && column.data.format;
28
- return dateFormat || defaultDateFormat;
29
- };
30
-
31
- _this.onDateEditorToggle = function () {
32
- var isReadOnly = _this.props.isReadOnly;
33
-
34
- if (isReadOnly) {
35
- return;
36
- }
37
-
38
- _this.setState({
39
- isPopoverShow: !_this.state.isPopoverShow
40
- });
41
- };
42
-
43
- _this.onValueChanged = function (value) {
44
- if (value !== _this.state.newValue) {
45
- _this.setState({
46
- newValue: value
47
- });
48
-
49
- _this.onCommit(value);
50
- }
51
- };
52
-
53
- _this.onCommit = function (newValue) {
54
- var updated = {};
55
- var column = _this.props.column;
56
- updated[column.key] = newValue;
57
-
58
- _this.props.onCommit(updated);
59
- };
60
-
61
- _this.onClosePopover = function () {
62
- _this.setState({
63
- isPopoverShow: false
64
- });
65
- };
66
-
67
- _this.state = {
68
- isDateInit: false,
69
- newValue: '',
70
- isPopoverShow: false,
71
- showHourAndMinute: false,
72
- defaultCalendarValue: null
73
- };
74
- return _this;
75
- }
76
-
77
- _createClass(DateEditor, [{
78
- key: "componentDidMount",
79
- value: function componentDidMount() {
80
- var _this$props = this.props,
81
- value = _this$props.value,
82
- lang = _this$props.lang;
83
- moment.locale(lang);
84
- var dateFormat = this.getDateFormat();
85
- this.setState({
86
- isDateInit: true,
87
- newValue: value,
88
- dateFormat: dateFormat,
89
- showHourAndMinute: dateFormat.indexOf('HH:mm') > -1
90
- });
91
- }
92
- }, {
93
- key: "render",
94
- value: function render() {
95
- if (!this.state.isDateInit) {
96
- return /*#__PURE__*/React.createElement("div", {
97
- className: "cell-editor date-editor"
98
- }, /*#__PURE__*/React.createElement("div", {
99
- className: "date-editor-conteinr"
100
- }, /*#__PURE__*/React.createElement("div", {
101
- className: "control-form"
102
- })));
103
- }
104
-
105
- var _this$props2 = this.props,
106
- lang = _this$props2.lang,
107
- column = _this$props2.column;
108
- var _this$state = this.state,
109
- newValue = _this$state.newValue,
110
- isPopoverShow = _this$state.isPopoverShow,
111
- dateFormat = _this$state.dateFormat,
112
- showHourAndMinute = _this$state.showHourAndMinute;
113
- return /*#__PURE__*/React.createElement("div", {
114
- className: "cell-editor dtable-ui-date-editor"
115
- }, !isPopoverShow && /*#__PURE__*/React.createElement("div", {
116
- className: "dtable-ui-date-editor-container"
117
- }, /*#__PURE__*/React.createElement("div", {
118
- className: "form-control",
119
- onClick: this.onDateEditorToggle
120
- }, formatDateToString(newValue, dateFormat))), isPopoverShow && /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(MediaQuery, {
121
- query: '(min-width: 768px)'
122
- }, /*#__PURE__*/React.createElement(PCDateEditorPopover, {
123
- lang: lang,
124
- value: newValue,
125
- dateFormat: dateFormat,
126
- showHourAndMinute: showHourAndMinute,
127
- onValueChanged: this.onValueChanged
128
- })), /*#__PURE__*/React.createElement(MediaQuery, {
129
- query: '(max-width: 767.8px)'
130
- }, /*#__PURE__*/React.createElement(MBDateEditorPopover, {
131
- isReadOnly: this.props.isReadOnly,
132
- lang: lang,
133
- value: newValue,
134
- dateFormat: dateFormat,
135
- showHourAndMinute: showHourAndMinute,
136
- column: column,
137
- onValueChanged: this.onValueChanged,
138
- onClosePopover: this.onClosePopover
139
- }))));
140
- }
141
- }]);
142
-
143
- return DateEditor;
144
- }(React.Component);
145
-
146
- DateEditor.defaultProps = {
147
- isReadOnly: false,
148
- value: '',
149
- lang: 'en'
150
- };
151
- export default DateEditor;
@@ -1,9 +0,0 @@
1
- import "../../css/cell-editor.css";
2
- export { default as NumberEditor } from './number-editor';
3
- export { default as TextEditor } from './text-editor';
4
- export { default as CheckboxEditor } from './checkbox-editor';
5
- export { default as SingleSelectEdtior } from './single-select-editor';
6
- export { default as MultipleSelectEditor } from './multiple-select-editor';
7
- export { default as CollaboratorEditor } from './collaborator-editor';
8
- export { default as LinkEditor } from './link-editor';
9
- export { default as DateEditor } from './date-editor';
@@ -1,303 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
- import React, { Fragment } from 'react';
6
- import MediaQuery from 'react-responsive';
7
- import { getLocale } from '../../lang';
8
- import * as CellTypes from '../../utils/cell-types';
9
- import { formatNumberToString, formatDateToString } from '../../utils/value-format-utils';
10
- import EditEditorButton from '../common/edit-editor-button';
11
- import LinkEditorOption from '../common/link-editor-option';
12
- import PCLinkEditorPopover from '../cell-editor-popover/pc-link-editor-popover';
13
- import MBLinkEditorPopover from '../cell-editor-popover/mb-link-editor-popover';
14
-
15
- var LinkEditor = /*#__PURE__*/function (_React$Component) {
16
- _inherits(LinkEditor, _React$Component);
17
-
18
- var _super = _createSuper(LinkEditor);
19
-
20
- function LinkEditor(props) {
21
- var _this;
22
-
23
- _classCallCheck(this, LinkEditor);
24
-
25
- _this = _super.call(this, props);
26
-
27
- _this.onDocumentToggle = function (e) {
28
- if (_this.editorContainer !== e.target && !_this.editorContainer.contains(e.target)) {
29
- _this.onClosePopover();
30
- }
31
- };
32
-
33
- _this.getLinkedCellValue = function () {
34
- var _this$props = _this.props,
35
- row = _this$props.row,
36
- column = _this$props.column,
37
- linkMetaData = _this$props.linkMetaData;
38
-
39
- var _ref = column.data || {},
40
- link_id = _ref.link_id,
41
- table_id = _ref.table_id,
42
- other_table_id = _ref.other_table_id;
43
-
44
- _this.linkId = link_id;
45
- _this.tableId = table_id;
46
- _this.otherTableId = other_table_id;
47
- return linkMetaData.getLinkedCellValue(_this.linkId, _this.tableId, _this.otherTableId, row._id);
48
- };
49
-
50
- _this.formatLinkedValuesToOptions = function () {
51
- var _this$props2 = _this.props,
52
- column = _this$props2.column,
53
- linkMetaData = _this$props2.linkMetaData;
54
- var rowIds = _this.state.newValue;
55
-
56
- if (rowIds && Array.isArray(rowIds) && rowIds.length > 0) {
57
- var linkedRows = linkMetaData.getLinkedRows(_this.otherTableId, rowIds);
58
- var linkedTable = linkMetaData.getLinkedTable(_this.otherTableId);
59
- return linkedRows.map(function (linkedRow) {
60
- var displayColumnKey = column.data.display_column_key; // format value to display
61
-
62
- var displayValue = _this.getDisplayValue(linkedTable, linkedRow, displayColumnKey);
63
-
64
- return {
65
- id: linkedRow._id,
66
- name: displayValue
67
- };
68
- });
69
- }
70
-
71
- return [];
72
- };
73
-
74
- _this.getDisplayValue = function (linkedTable, linkedRow, displayColumnKey) {
75
- var value = linkedRow[displayColumnKey];
76
- var linkedColumn = linkedTable.columns.find(function (column) {
77
- return column.key === displayColumnKey;
78
- });
79
- var type = linkedColumn.type,
80
- data = linkedColumn.data;
81
-
82
- switch (type) {
83
- case CellTypes.NUMBER:
84
- {
85
- return formatNumberToString(value, data);
86
- }
87
-
88
- case CellTypes.DATE:
89
- {
90
- var format = data.format;
91
- return formatDateToString(value, format);
92
- }
93
-
94
- default:
95
- return value;
96
- }
97
- };
98
-
99
- _this.getAvailableLinkedOptions = function () {
100
- var _this$props3 = _this.props,
101
- column = _this$props3.column,
102
- linkMetaData = _this$props3.linkMetaData;
103
- var displayColumnKey = column.data.display_column_key;
104
- var linkedTable = linkMetaData.getLinkedTable(_this.otherTableId);
105
- var availableRows = linkedTable.rows.filter(function (row) {
106
- return !!row[displayColumnKey];
107
- });
108
- var availableOptions = availableRows.map(function (row) {
109
- var displayValue = _this.getDisplayValue(linkedTable, row, displayColumnKey);
110
-
111
- return {
112
- id: row._id,
113
- name: displayValue
114
- };
115
- });
116
- return availableOptions;
117
- };
118
-
119
- _this.onCommit = function (newValue) {// nothing todo
120
- };
121
-
122
- _this.onAddOptionToggle = function (event) {
123
- event.nativeEvent.stopImmediatePropagation();
124
- event.stopPropagation();
125
-
126
- if (_this.props.isReadOnly) {
127
- return;
128
- }
129
-
130
- var isPopoverShow = !_this.state.isPopoverShow;
131
-
132
- if (isPopoverShow) {
133
- var popoverPosition = _this.caculatePopoverPosition();
134
-
135
- _this.setState({
136
- isPopoverShow: isPopoverShow,
137
- popoverPosition: popoverPosition
138
- });
139
- } else {
140
- _this.setState({
141
- isPopoverShow: isPopoverShow
142
- });
143
- }
144
- };
145
-
146
- _this.onOptionItemToggle = function (option) {
147
- var _this$props4 = _this.props,
148
- row = _this$props4.row,
149
- linkMetaData = _this$props4.linkMetaData;
150
-
151
- var newValue = _this.state.newValue.slice();
152
-
153
- var optionIndex = newValue.findIndex(function (option_id) {
154
- return option_id === option.id;
155
- });
156
-
157
- if (optionIndex !== -1) {
158
- newValue.splice(optionIndex, 1);
159
- linkMetaData.removeLink(_this.linkId, _this.tableId, _this.otherTableId, row._id, option.id);
160
- } else {
161
- newValue.push(option.id);
162
- linkMetaData.addLink(_this.linkId, _this.tableId, _this.otherTableId, row._id, option.id);
163
- }
164
-
165
- _this.setState({
166
- newValue: newValue
167
- });
168
- };
169
-
170
- _this.onDeleteOption = function (option) {
171
- var _this$props5 = _this.props,
172
- row = _this$props5.row,
173
- linkMetaData = _this$props5.linkMetaData;
174
-
175
- var newValue = _this.state.newValue.slice();
176
-
177
- var optionIndex = newValue.findIndex(function (option_id) {
178
- return option_id === option.id;
179
- });
180
- newValue.splice(optionIndex, 1);
181
-
182
- _this.setState({
183
- newValue: newValue
184
- }, function () {
185
- linkMetaData.removeLink(_this.linkId, _this.tableId, _this.otherTableId, row._id, option.id);
186
- });
187
- };
188
-
189
- _this.caculatePopoverPosition = function () {
190
- var POPOVER_MAX_HEIGHT = 200;
191
- var innerHeight = window.innerHeight;
192
-
193
- var _this$editor$getClien = _this.editor.getClientRects()[0],
194
- top = _this$editor$getClien.top,
195
- height = _this$editor$getClien.height;
196
-
197
- var isBelow = innerHeight - (top + height) > POPOVER_MAX_HEIGHT;
198
- var position = {
199
- top: height + 1,
200
- left: 0
201
- };
202
-
203
- if (!isBelow) {
204
- var bottom = height + 1;
205
- position = {
206
- bottom: bottom,
207
- left: 0
208
- };
209
- }
210
-
211
- return position;
212
- };
213
-
214
- _this.onClosePopover = function () {
215
- _this.setState({
216
- isPopoverShow: false
217
- });
218
- };
219
-
220
- _this.setEditorContainerRef = function (editorContainer) {
221
- _this.editorContainer = editorContainer;
222
- };
223
-
224
- _this.setEditorRef = function (editor) {
225
- _this.editor = editor;
226
- };
227
-
228
- _this.linkId = '';
229
- _this.tableId = '';
230
- _this.otherTableId = '';
231
- _this.state = {
232
- newValue: _this.getLinkedCellValue(),
233
- isPopoverShow: false,
234
- popoverPosition: {}
235
- };
236
- return _this;
237
- }
238
-
239
- _createClass(LinkEditor, [{
240
- key: "componentDidMount",
241
- value: function componentDidMount() {
242
- document.addEventListener('click', this.onDocumentToggle);
243
- }
244
- }, {
245
- key: "componentWillUnmount",
246
- value: function componentWillUnmount() {
247
- document.removeEventListener('click', this.onDocumentToggle);
248
- }
249
- }, {
250
- key: "render",
251
- value: function render() {
252
- var _this2 = this;
253
-
254
- var isReadOnly = this.props.isReadOnly;
255
- var _this$state = this.state,
256
- isPopoverShow = _this$state.isPopoverShow,
257
- popoverPosition = _this$state.popoverPosition;
258
- var options = this.getAvailableLinkedOptions();
259
- var selectedOptions = this.formatLinkedValuesToOptions();
260
- var isShowRemoveIcon = !isReadOnly;
261
- return /*#__PURE__*/React.createElement("div", {
262
- ref: this.setEditorContainerRef,
263
- className: "cell-editor dtable-ui-link-editor"
264
- }, /*#__PURE__*/React.createElement("div", {
265
- ref: this.setEditorRef,
266
- className: "dtable-ui-link-editor-container",
267
- onClick: this.onAddOptionToggle
268
- }, selectedOptions.length === 0 && /*#__PURE__*/React.createElement(EditEditorButton, {
269
- text: getLocale('Add_an_option')
270
- }), selectedOptions.length !== 0 && selectedOptions.map(function (option) {
271
- return /*#__PURE__*/React.createElement(LinkEditorOption, {
272
- key: option.id,
273
- option: option,
274
- isShowRemoveIcon: isShowRemoveIcon,
275
- onDeleteLinkOption: _this2.onDeleteOption
276
- });
277
- })), isPopoverShow && /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(MediaQuery, {
278
- query: "(min-width: 768px)"
279
- }, /*#__PURE__*/React.createElement(PCLinkEditorPopover, {
280
- popoverPosition: popoverPosition,
281
- options: options,
282
- selectedOptions: selectedOptions,
283
- onOptionItemToggle: this.onOptionItemToggle
284
- })), /*#__PURE__*/React.createElement(MediaQuery, {
285
- query: "(max-width: 767.8px)"
286
- }, /*#__PURE__*/React.createElement(MBLinkEditorPopover, {
287
- isReadOnly: this.props.isReadOnly,
288
- value: this.state.newValue,
289
- column: this.props.column,
290
- options: options,
291
- onOptionItemToggle: this.onOptionItemToggle,
292
- onClosePopover: this.onClosePopover
293
- }))));
294
- }
295
- }]);
296
-
297
- return LinkEditor;
298
- }(React.Component);
299
-
300
- LinkEditor.defaultProps = {
301
- isReadOnly: false
302
- };
303
- export default LinkEditor;
@@ -1,237 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _inherits from "@babel/runtime/helpers/esm/inherits";
4
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
- import React, { Fragment } from 'react';
6
- import MediaQuery from 'react-responsive';
7
- import { getLocale } from '../../lang';
8
- import EditEditorButton from '../common/edit-editor-button';
9
- import SelectEditorOption from '../common/select-editor-option';
10
- import PCSelectEditorPopover from '../cell-editor-popover/pc-select-editor-popover';
11
- import MBSingleSelectPopover from '../cell-editor-popover/mb-select-editor-popover';
12
-
13
- var MultipleSelectEditor = /*#__PURE__*/function (_React$Component) {
14
- _inherits(MultipleSelectEditor, _React$Component);
15
-
16
- var _super = _createSuper(MultipleSelectEditor);
17
-
18
- function MultipleSelectEditor(props) {
19
- var _this;
20
-
21
- _classCallCheck(this, MultipleSelectEditor);
22
-
23
- _this = _super.call(this, props);
24
-
25
- _this.onDocumentToggle = function (e) {
26
- if (_this.editorContainer !== e.target && !_this.editorContainer.contains(e.target)) {
27
- _this.onClosePopover();
28
- }
29
- };
30
-
31
- _this.getFormattedOptions = function () {
32
- var newValue = _this.state.newValue;
33
-
34
- if (Array.isArray(newValue) && newValue.length > 0) {
35
- return newValue.map(function (option_id) {
36
- return _this.options.find(function (option) {
37
- return option.id === option_id;
38
- });
39
- }).filter(function (option) {
40
- return !!option;
41
- });
42
- }
43
-
44
- return [];
45
- };
46
-
47
- _this.onAddOptionToggle = function (event) {
48
- event.nativeEvent.stopImmediatePropagation();
49
- event.stopPropagation();
50
-
51
- if (_this.props.isReadOnly) {
52
- return;
53
- }
54
-
55
- var isPopoverShow = !_this.state.isPopoverShow;
56
-
57
- if (isPopoverShow) {
58
- var popoverPosition = _this.caculatePopoverPosition();
59
-
60
- _this.setState({
61
- isPopoverShow: isPopoverShow,
62
- popoverPosition: popoverPosition
63
- });
64
- } else {
65
- _this.setState({
66
- isPopoverShow: isPopoverShow
67
- });
68
- }
69
- };
70
-
71
- _this.onCommit = function (newValue) {
72
- var updated = {};
73
- var column = _this.props.column;
74
- updated[column.key] = newValue;
75
-
76
- _this.props.onCommit(updated);
77
- };
78
-
79
- _this.onOptionItemToggle = function (option) {
80
- var newValue = _this.state.newValue.slice();
81
-
82
- var optionIndex = newValue.findIndex(function (option_id) {
83
- return option_id === option.id;
84
- });
85
-
86
- if (optionIndex !== -1) {
87
- newValue.splice(optionIndex, 1);
88
- } else {
89
- newValue.push(option.id);
90
- }
91
-
92
- _this.setState({
93
- newValue: newValue
94
- }, function () {
95
- _this.onCommit(newValue);
96
- });
97
- };
98
-
99
- _this.onDeleteOption = function (option) {
100
- var newValue = _this.state.newValue.slice();
101
-
102
- var optionIndex = newValue.findIndex(function (option_id) {
103
- return option_id === option.id;
104
- });
105
- newValue.splice(optionIndex, 1);
106
-
107
- _this.setState({
108
- newValue: newValue
109
- }, function () {
110
- _this.onCommit(newValue);
111
- });
112
- };
113
-
114
- _this.onAddNewOption = function (optionName) {
115
- _this.props.onAddNewOption(optionName);
116
-
117
- _this.onClosePopover();
118
- };
119
-
120
- _this.caculatePopoverPosition = function () {
121
- var POPOVER_MAX_HEIGHT = 200;
122
- var innerHeight = window.innerHeight;
123
-
124
- var _this$editor$getClien = _this.editor.getClientRects()[0],
125
- top = _this$editor$getClien.top,
126
- height = _this$editor$getClien.height;
127
-
128
- var isBelow = innerHeight - (top + height) > POPOVER_MAX_HEIGHT;
129
- var position = {
130
- top: height + 1,
131
- left: 0
132
- };
133
-
134
- if (!isBelow) {
135
- var bottom = height + 1;
136
- position = {
137
- bottom: bottom,
138
- left: 0
139
- };
140
- }
141
-
142
- return position;
143
- };
144
-
145
- _this.onClosePopover = function () {
146
- _this.setState({
147
- isPopoverShow: false
148
- });
149
- };
150
-
151
- _this.setEditorContainerRef = function (editorContainer) {
152
- _this.editorContainer = editorContainer;
153
- };
154
-
155
- _this.setEditorRef = function (editor) {
156
- _this.editor = editor;
157
- };
158
-
159
- _this.state = {
160
- newValue: Array.isArray(props.value) ? props.value : [],
161
- isPopoverShow: false,
162
- popoverPosition: {}
163
- };
164
- var _column = _this.props.column;
165
- _this.options = _column.data && (_column.data.options || []);
166
- return _this;
167
- }
168
-
169
- _createClass(MultipleSelectEditor, [{
170
- key: "componentDidMount",
171
- value: function componentDidMount() {
172
- document.addEventListener('click', this.onDocumentToggle);
173
- }
174
- }, {
175
- key: "componentWillUnmount",
176
- value: function componentWillUnmount() {
177
- document.removeEventListener('click', this.onDocumentToggle);
178
- }
179
- }, {
180
- key: "render",
181
- value: function render() {
182
- var _this2 = this;
183
-
184
- var _this$state = this.state,
185
- isPopoverShow = _this$state.isPopoverShow,
186
- popoverPosition = _this$state.popoverPosition;
187
- var options = this.options;
188
- var selectedOptions = this.getFormattedOptions();
189
- return /*#__PURE__*/React.createElement("div", {
190
- ref: this.setEditorContainerRef,
191
- className: "cell-editor dtable-ui-multiple-select-editor"
192
- }, /*#__PURE__*/React.createElement("div", {
193
- ref: this.setEditorRef,
194
- className: "dtable-ui-select-editor-container",
195
- onClick: this.onAddOptionToggle
196
- }, selectedOptions.length === 0 && /*#__PURE__*/React.createElement(EditEditorButton, {
197
- text: getLocale('Add_an_option')
198
- }), selectedOptions.length !== 0 && selectedOptions.map(function (option) {
199
- return /*#__PURE__*/React.createElement(SelectEditorOption, {
200
- key: option.id,
201
- option: option,
202
- isShowRemoveIcon: true,
203
- onDeleteSelectOption: _this2.onDeleteOption
204
- });
205
- })), isPopoverShow && /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(MediaQuery, {
206
- query: "(min-width: 768px)"
207
- }, /*#__PURE__*/React.createElement(PCSelectEditorPopover, {
208
- popoverPosition: popoverPosition,
209
- options: options,
210
- selectedOptions: selectedOptions,
211
- onOptionItemToggle: this.onOptionItemToggle,
212
- isSupportNewOption: this.props.isSupportNewOption,
213
- onAddNewOption: this.onAddNewOption
214
- })), /*#__PURE__*/React.createElement(MediaQuery, {
215
- query: "(max-width: 767.8px)"
216
- }, /*#__PURE__*/React.createElement(MBSingleSelectPopover, {
217
- isReadOnly: this.props.isReadOnly,
218
- value: this.state.newValue,
219
- column: this.props.column,
220
- options: options,
221
- onOptionItemToggle: this.onOptionItemToggle,
222
- isShowRemoveIcon: true,
223
- isSupportNewOption: this.props.isSupportNewOption,
224
- onAddNewOption: this.onAddNewOption,
225
- onClosePopover: this.onClosePopover
226
- }))));
227
- }
228
- }]);
229
-
230
- return MultipleSelectEditor;
231
- }(React.Component);
232
-
233
- MultipleSelectEditor.defaultProps = {
234
- isReadOnly: false,
235
- value: []
236
- };
237
- export default MultipleSelectEditor;