dtable-ui-component 0.3.2-alpha4 → 0.3.2-alpha6

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.
@@ -23,25 +23,11 @@ var ButtonFormatter = /*#__PURE__*/function (_React$Component) {
23
23
  _this = _super.call.apply(_super, [this].concat(args));
24
24
 
25
25
  _this.handleClick = function () {
26
- var _this$props$data = _this.props.data,
27
- button_type = _this$props$data.button_type,
28
- url_address = _this$props$data.url_address;
29
-
30
- if (button_type === 'open_url' && url_address) {
31
- _this.openUrlLink(url_address);
26
+ if (_this.props.onClickButton) {
27
+ _this.props.onClickButton(_this.props.data);
32
28
  }
33
29
  };
34
30
 
35
- _this.openUrlLink = function (url) {
36
- var a = document.createElement('a');
37
- document.body.appendChild(a);
38
- a.href = url;
39
- a.target = '_blank';
40
- a.rel = 'noopener noreferrer';
41
- a.click();
42
- document.body.removeChild(a);
43
- };
44
-
45
31
  return _this;
46
32
  }
47
33
 
@@ -0,0 +1,73 @@
1
+ .dtable-row-expand-formatter {
2
+ width: 100%;
3
+ max-width: 100%;
4
+ }
5
+
6
+ .dtable-row-expand-formatter .row-cell-empty {
7
+ height: 8px;
8
+ width: 20px;
9
+ background-color: #f1f1f1;
10
+ border-radius: 4px;
11
+ display: inline-block;
12
+ }
13
+
14
+ .dtable-row-expand-formatter .dtable-ui.collaborator-item {
15
+ margin: 5px 10px 5px 0;
16
+ }
17
+
18
+ .dtable-row-expand-formatter .dtable-ui.text-formatter,
19
+ .dtable-row-expand-formatter .dtable-ui.url-formatter,
20
+ .dtable-row-expand-formatter .dtable-ui.email-formatter {
21
+ overflow: hidden;
22
+ text-overflow: ellipsis;
23
+ white-space: nowrap;
24
+ }
25
+
26
+ .dtable-row-expand-formatter .dtable-ui.multiple-select-formatter .dtable-ui.select-item {
27
+ margin: 5px 0;
28
+ }
29
+
30
+ .dtable-row-expand-formatter .dtable-ui.geolocation-formatter {
31
+ width: fit-content;
32
+ min-width: 80px;
33
+ max-width: 100%;
34
+ height: 28px;
35
+ line-height: 24px;
36
+ border: 2px solid transparent;
37
+ padding: 0 10px;
38
+ background-color: #f0f0f0;
39
+ border-radius: 3px;
40
+ font-size: 14px;
41
+ text-align: center;
42
+ }
43
+
44
+ .dtable-row-expand-formatter .form-control {
45
+ background-color: #f8f9fa;
46
+ }
47
+
48
+ .dtable-row-expand-formatter .checkbox-formatter-container {
49
+ width: 24px;
50
+ height: 24px;
51
+ border: 2px solid #e0e0e0;
52
+ border-radius: 3px;
53
+ display: flex;
54
+ justify-content: center;
55
+ }
56
+
57
+ .dtable-row-expand-formatter .longtext-formatter-container {
58
+ border: 1px solid rgba(0, 40, 100, 0.12);
59
+ border-radius: 3px;
60
+ padding: 0.375rem 0.75rem;
61
+ height: auto;
62
+ background-color: #fff;
63
+ }
64
+
65
+ .dtable-row-expand-formatter .geolocation-formatter-container {
66
+ height: 38px;
67
+ display: flex;
68
+ align-items: center;
69
+ }
70
+
71
+ .dtable-row-expand-formatter .dtable-link-formatter {
72
+ padding-top: 8px;
73
+ }
@@ -0,0 +1,426 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
+
8
+ var _emptyTypeMap;
9
+
10
+ import React from 'react';
11
+ import { CellType } from 'dtable-store';
12
+ import classnames from 'classnames';
13
+ import { TextFormatter, NumberFormatter, CheckboxFormatter, DateFormatter, SingleSelectFormatter, MultipleSelectFormatter, CollaboratorFormatter, LongTextFormatter, GeolocationFormatter, CTimeFormatter, CreatorFormatter, LastModifierFormatter, MTimeFormatter, AutoNumberFormatter, UrlFormatter, EmailFormatter, DurationFormatter, RateFormatter, ButtonFormatter, RowExpandImageFormatter, RowExpandFileFormatter, RowExpandLinkFormatter } from '../index';
14
+ import './index.css';
15
+ var emptyTypeMap = (_emptyTypeMap = {}, _defineProperty(_emptyTypeMap, CellType.TEXT, true), _defineProperty(_emptyTypeMap, CellType.LONG_TEXT, true), _defineProperty(_emptyTypeMap, CellType.GEOLOCATION, true), _defineProperty(_emptyTypeMap, CellType.SINGLE_SELECT, true), _defineProperty(_emptyTypeMap, CellType.MULTIPLE_SELECT, true), _defineProperty(_emptyTypeMap, CellType.CTIME, true), _defineProperty(_emptyTypeMap, CellType.MTIME, true), _defineProperty(_emptyTypeMap, CellType.DATE, true), _defineProperty(_emptyTypeMap, CellType.AUTO_NUMBER, true), _defineProperty(_emptyTypeMap, CellType.URL, true), _defineProperty(_emptyTypeMap, CellType.EMAIL, true), _defineProperty(_emptyTypeMap, CellType.DURATION, true), _defineProperty(_emptyTypeMap, CellType.IMAGE, true), _defineProperty(_emptyTypeMap, CellType.FILE, true), _defineProperty(_emptyTypeMap, CellType.CREATOR, true), _defineProperty(_emptyTypeMap, CellType.LAST_MODIFIER, true), _emptyTypeMap);
16
+
17
+ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
18
+ _inherits(EditorFormatter, _React$Component);
19
+
20
+ var _super = _createSuper(EditorFormatter);
21
+
22
+ function EditorFormatter(_props) {
23
+ var _this;
24
+
25
+ _classCallCheck(this, EditorFormatter);
26
+
27
+ _this = _super.call(this, _props);
28
+
29
+ _this.updateCollaborators = function () {
30
+ _this.setState({
31
+ collaborators: _this.getCollaborator()
32
+ });
33
+ };
34
+
35
+ _this.calculateCollaboratorData = function (props) {
36
+ var row = props.row,
37
+ column = props.column;
38
+
39
+ if (column.type === CellType.CREATOR || column.type === CellType.LAST_MODIFIER) {
40
+ var email = row[column.name];
41
+
42
+ _this.loadCollaborator(email);
43
+ } else if (column.type === CellType.COLLABORATOR) {
44
+ var emails = row[column.name];
45
+
46
+ if (Array.isArray(emails)) {
47
+ emails.forEach(function (email) {
48
+ _this.loadCollaborator(email);
49
+ });
50
+ }
51
+ }
52
+ };
53
+
54
+ _this.getCollaborator = function () {
55
+ var _this$props = _this.props,
56
+ context = _this$props.context,
57
+ collaborators = _this$props.collaborators;
58
+
59
+ if (context && context.getCollaboratorsFromCache) {
60
+ return context.getCollaboratorsFromCache();
61
+ }
62
+
63
+ return collaborators || [];
64
+ };
65
+
66
+ _this.loadCollaborator = function (email) {
67
+ var context = _this.props.context;
68
+
69
+ if (context && context.loadCollaborator) {
70
+ context.loadCollaborator(email);
71
+ }
72
+ };
73
+
74
+ _this.renderEmpty = function () {
75
+ return /*#__PURE__*/React.createElement("span", {
76
+ className: "row-cell-empty"
77
+ });
78
+ };
79
+
80
+ _this.renderFormatter = function () {
81
+ var _this$props2 = _this.props,
82
+ column = _this$props2.column,
83
+ row = _this$props2.row,
84
+ className = _this$props2.className;
85
+ var _column = column,
86
+ columnType = _column.type;
87
+ var collaborators = _this.state.collaborators;
88
+ var containerClassName = "dtable-".concat(columnType, "-formatter ").concat(className || '');
89
+ var cellValue = row[column.key] || row[column.name];
90
+
91
+ if (!cellValue && emptyTypeMap[columnType]) {
92
+ return _this.renderEmpty();
93
+ }
94
+
95
+ switch (columnType) {
96
+ case CellType.TEXT:
97
+ {
98
+ return /*#__PURE__*/React.createElement("div", {
99
+ className: "form-control d-flex align-items-center w-100"
100
+ }, /*#__PURE__*/React.createElement(TextFormatter, {
101
+ value: cellValue,
102
+ containerClassName: containerClassName
103
+ }));
104
+ }
105
+
106
+ case CellType.COLLABORATOR:
107
+ {
108
+ if (!cellValue || cellValue.length === 0) {
109
+ return _this.renderEmpty();
110
+ }
111
+
112
+ return /*#__PURE__*/React.createElement("div", {
113
+ className: "form-control d-flex align-items-center w-100 h-auto"
114
+ }, /*#__PURE__*/React.createElement(CollaboratorFormatter, {
115
+ value: cellValue,
116
+ collaborators: collaborators,
117
+ containerClassName: containerClassName
118
+ }));
119
+ }
120
+
121
+ case CellType.LONG_TEXT:
122
+ {
123
+ return /*#__PURE__*/React.createElement("div", {
124
+ className: "longtext-formatter-container"
125
+ }, /*#__PURE__*/React.createElement(LongTextFormatter, {
126
+ value: cellValue,
127
+ containerClassName: containerClassName,
128
+ isSample: false
129
+ }));
130
+ }
131
+
132
+ case CellType.GEOLOCATION:
133
+ {
134
+ return /*#__PURE__*/React.createElement("div", {
135
+ className: "geolocation-formatter-container"
136
+ }, /*#__PURE__*/React.createElement(GeolocationFormatter, {
137
+ value: cellValue,
138
+ data: column.data,
139
+ containerClassName: containerClassName
140
+ }));
141
+ }
142
+
143
+ case CellType.NUMBER:
144
+ {
145
+ if (!cellValue && cellValue !== 0) {
146
+ return _this.renderEmpty();
147
+ }
148
+
149
+ return /*#__PURE__*/React.createElement("div", {
150
+ className: "form-control d-flex align-items-center w-100"
151
+ }, /*#__PURE__*/React.createElement(NumberFormatter, {
152
+ value: cellValue,
153
+ data: column.data,
154
+ containerClassName: containerClassName
155
+ }));
156
+ }
157
+
158
+ case CellType.DATE:
159
+ {
160
+ return /*#__PURE__*/React.createElement("div", {
161
+ className: "form-control d-flex align-items-center w-100"
162
+ }, /*#__PURE__*/React.createElement(DateFormatter, {
163
+ value: cellValue,
164
+ format: column.data.format,
165
+ containerClassName: containerClassName
166
+ }));
167
+ }
168
+
169
+ case CellType.CTIME:
170
+ {
171
+ if (!row._ctime) {
172
+ return _this.renderEmpty();
173
+ }
174
+
175
+ return /*#__PURE__*/React.createElement("div", {
176
+ className: "form-control d-flex align-items-center w-100"
177
+ }, /*#__PURE__*/React.createElement(CTimeFormatter, {
178
+ value: row._ctime,
179
+ containerClassName: containerClassName
180
+ }));
181
+ }
182
+
183
+ case CellType.MTIME:
184
+ {
185
+ if (!row._mtime) {
186
+ return _this.renderEmpty();
187
+ }
188
+
189
+ return /*#__PURE__*/React.createElement("div", {
190
+ className: "form-control d-flex align-items-center w-100"
191
+ }, /*#__PURE__*/React.createElement(MTimeFormatter, {
192
+ value: row._mtime,
193
+ containerClassName: containerClassName
194
+ }));
195
+ }
196
+
197
+ case CellType.MULTIPLE_SELECT:
198
+ {
199
+ if (!cellValue || cellValue.length === 0) {
200
+ return _this.renderEmpty();
201
+ }
202
+
203
+ var options = column.data ? column.data.options : [];
204
+ return /*#__PURE__*/React.createElement("div", {
205
+ className: "form-control d-flex align-items-center w-100 h-auto"
206
+ }, /*#__PURE__*/React.createElement(MultipleSelectFormatter, {
207
+ value: cellValue,
208
+ options: options,
209
+ containerClassName: containerClassName
210
+ }));
211
+ }
212
+
213
+ case CellType.SINGLE_SELECT:
214
+ {
215
+ var _options = column.data ? column.data.options : [];
216
+
217
+ return /*#__PURE__*/React.createElement("div", {
218
+ className: "form-control d-flex align-items-center w-100"
219
+ }, /*#__PURE__*/React.createElement(SingleSelectFormatter, {
220
+ value: cellValue,
221
+ options: _options,
222
+ containerClassName: containerClassName
223
+ }));
224
+ }
225
+
226
+ case CellType.FILE:
227
+ {
228
+ return /*#__PURE__*/React.createElement(RowExpandFileFormatter, {
229
+ value: cellValue,
230
+ column: column,
231
+ downloadFile: _this.props.downloadFile,
232
+ deleteFile: _this.props.deleteFile
233
+ });
234
+ }
235
+
236
+ case CellType.IMAGE:
237
+ {
238
+ return /*#__PURE__*/React.createElement(RowExpandImageFormatter, {
239
+ value: cellValue,
240
+ column: column,
241
+ downloadFile: _this.props.downloadFile,
242
+ deleteFile: _this.props.deleteFile,
243
+ onRotateImage: _this.props.onRotateImage
244
+ });
245
+ }
246
+
247
+ case CellType.CHECKBOX:
248
+ {
249
+ return /*#__PURE__*/React.createElement("div", {
250
+ className: "checkbox-formatter-container"
251
+ }, /*#__PURE__*/React.createElement(CheckboxFormatter, {
252
+ value: cellValue
253
+ }));
254
+ }
255
+
256
+ case CellType.CREATOR:
257
+ {
258
+ return /*#__PURE__*/React.createElement(CreatorFormatter, {
259
+ collaborators: collaborators,
260
+ value: cellValue,
261
+ containerClassName: containerClassName
262
+ });
263
+ }
264
+
265
+ case CellType.LAST_MODIFIER:
266
+ {
267
+ return /*#__PURE__*/React.createElement(LastModifierFormatter, {
268
+ collaborators: collaborators,
269
+ value: cellValue,
270
+ containerClassName: containerClassName
271
+ });
272
+ }
273
+
274
+ case CellType.FORMULA:
275
+ case CellType.LINK_FORMULA:
276
+ {
277
+ if (!cellValue && cellValue !== 0) {
278
+ return _this.renderEmpty();
279
+ }
280
+
281
+ return /*#__PURE__*/React.createElement(TextFormatter, {
282
+ value: cellValue,
283
+ containerClassName: containerClassName
284
+ });
285
+ }
286
+
287
+ case CellType.LINK:
288
+ {
289
+ // handle link column do not have column.data.display_column
290
+ var _column2 = column,
291
+ data = _column2.data;
292
+ var display_column_key = data.display_column_key,
293
+ array_type = data.array_type,
294
+ array_data = data.array_data;
295
+
296
+ if (!data.display_column) {
297
+ column = _objectSpread(_objectSpread({}, column), {}, {
298
+ data: _objectSpread(_objectSpread({}, data), {}, {
299
+ display_column: {
300
+ key: display_column_key || '0000',
301
+ type: array_type || CellType.TEXT,
302
+ data: array_data || null
303
+ }
304
+ })
305
+ });
306
+ }
307
+
308
+ if (!Array.isArray(cellValue) || cellValue.length === 0) {
309
+ return _this.renderEmpty();
310
+ }
311
+
312
+ return /*#__PURE__*/React.createElement(RowExpandLinkFormatter, {
313
+ value: cellValue,
314
+ column: column,
315
+ collaborators: collaborators,
316
+ containerClassName: containerClassName,
317
+ renderEmpty: _this.renderEmpty
318
+ });
319
+ }
320
+
321
+ case CellType.AUTO_NUMBER:
322
+ {
323
+ return /*#__PURE__*/React.createElement(AutoNumberFormatter, {
324
+ value: cellValue,
325
+ containerClassName: containerClassName
326
+ });
327
+ }
328
+
329
+ case CellType.URL:
330
+ {
331
+ return /*#__PURE__*/React.createElement("div", {
332
+ className: "form-control d-flex align-items-center w-100"
333
+ }, /*#__PURE__*/React.createElement(UrlFormatter, {
334
+ value: cellValue,
335
+ containerClassName: containerClassName
336
+ }));
337
+ }
338
+
339
+ case CellType.EMAIL:
340
+ {
341
+ return /*#__PURE__*/React.createElement("div", {
342
+ className: "form-control d-flex align-items-center w-100"
343
+ }, /*#__PURE__*/React.createElement(EmailFormatter, {
344
+ value: cellValue,
345
+ containerClassName: containerClassName
346
+ }));
347
+ }
348
+
349
+ case CellType.DURATION:
350
+ {
351
+ return /*#__PURE__*/React.createElement("div", {
352
+ className: "form-control d-flex align-items-center w-100"
353
+ }, /*#__PURE__*/React.createElement(DurationFormatter, {
354
+ value: cellValue,
355
+ format: column.data.duration_format,
356
+ containerClassName: containerClassName
357
+ }));
358
+ }
359
+
360
+ case CellType.RATE:
361
+ {
362
+ return /*#__PURE__*/React.createElement("div", {
363
+ className: "form-control d-flex align-items-center w-100"
364
+ }, /*#__PURE__*/React.createElement(RateFormatter, {
365
+ value: cellValue,
366
+ data: column.data,
367
+ containerClassName: containerClassName
368
+ }));
369
+ }
370
+
371
+ case CellType.BUTTON:
372
+ {
373
+ return /*#__PURE__*/React.createElement(ButtonFormatter, {
374
+ data: column.data,
375
+ containerClassName: containerClassName,
376
+ onClickButton: _this.props.onClickButton
377
+ });
378
+ }
379
+
380
+ default:
381
+ return null;
382
+ }
383
+ };
384
+
385
+ _this.state = {
386
+ collaborators: _this.getCollaborator()
387
+ };
388
+ return _this;
389
+ }
390
+
391
+ _createClass(EditorFormatter, [{
392
+ key: "componentDidMount",
393
+ value: function componentDidMount() {
394
+ this.calculateCollaboratorData(this.props);
395
+
396
+ if (this.props.eventBus) {
397
+ this.listenCollaboratorsUpdated = this.props.eventBus.subscribe('collaborators-updated', this.updateCollaborators);
398
+ }
399
+ }
400
+ }, {
401
+ key: "componentWillReceiveProps",
402
+ value: function componentWillReceiveProps(nextProps) {
403
+ this.calculateCollaboratorData(nextProps);
404
+ }
405
+ }, {
406
+ key: "componentWillUnmount",
407
+ value: function componentWillUnmount() {
408
+ this.listenCollaboratorsUpdated();
409
+ }
410
+ }, {
411
+ key: "render",
412
+ value: function render() {
413
+ var className = this.props.className;
414
+ return /*#__PURE__*/React.createElement("div", {
415
+ className: classnames('dtable-row-expand-formatter', _defineProperty({}, className, className))
416
+ }, this.renderFormatter());
417
+ }
418
+ }]);
419
+
420
+ return EditorFormatter;
421
+ }(React.Component);
422
+
423
+ EditorFormatter.defaultProps = {
424
+ className: ''
425
+ };
426
+ export { EditorFormatter as default };
@@ -0,0 +1,79 @@
1
+ @import url('../css/cell-formatter.css');
2
+
3
+ .dtable-ui.row-expand-image-formatter {
4
+ display: flex;
5
+ flex-wrap: wrap;
6
+ justify-content: flex-start;
7
+ width: 550px;
8
+ }
9
+
10
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image {
11
+ height: 100px;
12
+ width: 100px;
13
+ border: 2px solid #ededed;
14
+ border-radius: 4px;
15
+ cursor: pointer;
16
+ display: flex;
17
+ align-items: center;
18
+ justify-content: center;
19
+ margin: 5px;
20
+ position: relative;
21
+ }
22
+
23
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image:nth-child(5n + 1) {
24
+ margin-left: 0;
25
+ }
26
+
27
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image:hover {
28
+ border-color: #c9c9c9;
29
+ }
30
+
31
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image .dtable-image-icons-choice {
32
+ height: 20px;
33
+ width: 100%;
34
+ top: 0;
35
+ position: absolute;
36
+ color: #fff;
37
+ display: none;
38
+ padding: 0 3px;
39
+ justify-content: flex-end;
40
+ align-items: center;
41
+ }
42
+
43
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image:hover .dtable-image-icons-choice {
44
+ display: flex;
45
+ }
46
+
47
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image .dtable-image-icons-choice .image-icon {
48
+ height: 16px;
49
+ width: 16px;
50
+ border-radius: 50%;
51
+ background: rgba(0,0,0,.5);
52
+ color: #fff;
53
+ cursor: pointer;
54
+ display: flex;
55
+ justify-content: center;
56
+ align-items: center;
57
+ }
58
+
59
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image .dtable-image-icons-choice .image-icon:nth-child(2) {
60
+ margin-left: 5px;
61
+ }
62
+
63
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image .dtable-image-icons-choice .image-icon .dtable-font {
64
+ font-size: 12px;
65
+ transform: scale(.7);
66
+ }
67
+
68
+ .dtable-ui.row-expand-image-formatter .row-expand-item-image img {
69
+ display: block;
70
+ max-width: 96px;
71
+ max-height: 96px;
72
+ border-radius: 4px;
73
+ }
74
+
75
+ .tooltip-inner {
76
+ font-weight: lighter;
77
+ text-align: justify;
78
+ background-color: #303133;
79
+ }