dtable-ui-component 0.1.42 → 0.1.46

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.
@@ -4,14 +4,14 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
6
  import cn from 'astro-classname';
7
- import ColloboratorItem from '../common/collaborator-item';
7
+ import CollaboratorItem from '../common/collaborator-item';
8
8
  import DefaultAvatar from '../../assets/images/avatar/default_avatar.png';
9
9
 
10
10
  // there will be there conditions
11
11
  // 1 value is not exist, typeof value is array, but it's length is 0
12
12
  // 2 value is exist, but can't find in collaborators
13
13
  // 3 value is exist, typeof value is a string
14
- // 4 vlaue is exist, typeof value is array
14
+ // 4 value is exist, typeof value is array
15
15
  var CreatorFormatter = /*#__PURE__*/function (_React$PureComponent) {
16
16
  _inherits(CreatorFormatter, _React$PureComponent);
17
17
 
@@ -50,7 +50,7 @@ var CreatorFormatter = /*#__PURE__*/function (_React$PureComponent) {
50
50
  }
51
51
 
52
52
  ;
53
- return /*#__PURE__*/React.createElement(ColloboratorItem, {
53
+ return /*#__PURE__*/React.createElement(CollaboratorItem, {
54
54
  key: index,
55
55
  collaborator: collaborator
56
56
  });
@@ -13,7 +13,6 @@ import { isFunction } from '../../utils/utils';
13
13
  import TextFormatter from './text-formatter';
14
14
  var SIMPLE_CELL_FORMATTER_COLUMNS = [CellTypes.TEXT, CellTypes.NUMBER, CellTypes.DATE, CellTypes.CTIME, CellTypes.MTIME, CellTypes.GEOLOCATION, CellTypes.AUTO_NUMBER, CellTypes.URL, CellTypes.EMAIL, CellTypes.DURATION];
15
15
  var ARRAY_FORMAL_COLUMNS = [CellTypes.IMAGE, CellTypes.FILE, CellTypes.MULTIPLE_SELECT, CellTypes.COLLABORATOR];
16
- var FORMULA_COLUMN_TYPES = [CellTypes.FORMULA, CellTypes.LINK_FORMULA];
17
16
 
18
17
  var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
19
18
  _inherits(FormulaFormatter, _React$Component);
@@ -70,6 +69,19 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
70
69
  {
71
70
  formatterProps.column = column;
72
71
  Formatter = FormulaFormatter;
72
+ break;
73
+ }
74
+
75
+ case CellTypes.CREATOR:
76
+ case CellTypes.LAST_MODIFIER:
77
+ {
78
+ formatterProps.collaborators = collaborators;
79
+ break;
80
+ }
81
+
82
+ default:
83
+ {
84
+ break;
73
85
  }
74
86
  }
75
87
 
@@ -101,12 +113,7 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
101
113
  return column.key === display_column_key;
102
114
  });
103
115
  if (!linkedColumn) return null;
104
- var linkedColumnType = linkedColumn.type,
105
- linkedColumnData = linkedColumn.data;
106
-
107
- if (FORMULA_COLUMN_TYPES.includes(linkedColumnType) && linkedColumnData && linkedColumnData.result_type === FORMULA_RESULT_TYPE.COLUMN) {
108
- return null;
109
- }
116
+ var linkedColumnType = linkedColumn.type;
110
117
 
111
118
  if (!ARRAY_FORMAL_COLUMNS.includes(linkedColumnType) && Object.prototype.toString.call(value) === '[object Array]') {
112
119
  var contentItemClassName = cn('formula-formatter-content-item', {
@@ -152,7 +159,6 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
152
159
  containerClassName = _this$props2.containerClassName,
153
160
  column = _this$props2.column;
154
161
  var columnData = column.data;
155
- if (!columnData) return null;
156
162
  var resultType = columnData.result_type;
157
163
 
158
164
  if (resultType === FORMULA_RESULT_TYPE.COLUMN) {
@@ -4,6 +4,7 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
6
  import cn from 'astro-classname';
7
+ import { getGeolocationDisplayString } from '../../utils/value-format-utils';
7
8
 
8
9
  var GeolocationFormatter = /*#__PURE__*/function (_React$Component) {
9
10
  _inherits(GeolocationFormatter, _React$Component);
@@ -21,16 +22,17 @@ var GeolocationFormatter = /*#__PURE__*/function (_React$Component) {
21
22
  value: function render() {
22
23
  var _this$props = this.props,
23
24
  value = _this$props.value,
25
+ data = _this$props.data,
24
26
  containerClassName = _this$props.containerClassName;
25
- var classname = cn('dtable-ui cell-formatter-container geolocation-formatter', containerClassName);
27
+ var className = cn('dtable-ui cell-formatter-container geolocation-formatter', containerClassName);
26
28
 
27
29
  if (typeof value !== 'object') {
28
30
  return null;
29
31
  }
30
32
 
31
33
  return /*#__PURE__*/React.createElement("div", {
32
- className: classname
33
- }, "".concat(value.province || '', " ").concat(value.city || '', " ").concat(value.district || '', " ").concat(value.detail || ''));
34
+ className: className
35
+ }, getGeolocationDisplayString(value, data));
34
36
  }
35
37
  }]);
36
38
 
@@ -44,6 +46,7 @@ GeolocationFormatter.defaultProps = {
44
46
  district: '',
45
47
  detail: ''
46
48
  },
49
+ data: {},
47
50
  containerClassName: ''
48
51
  };
49
52
  export default GeolocationFormatter;
@@ -23,4 +23,5 @@ export { default as DurationFormatter } from './duration-formatter';
23
23
  export { default as RateFormatter } from './rate-formatter';
24
24
  export { default as ButtonFormatter } from './button-formatter';
25
25
  export { default as FileItemFormatter } from './widgets/file-item-formatter';
26
- export { default as ImagePreviewerLightbox } from './widgets/image-previewer-lightbox';
26
+ export { default as ImagePreviewerLightbox } from './widgets/image-previewer-lightbox';
27
+ export { default as CollaboratorItem } from '../common/collaborator-item';
@@ -26,16 +26,17 @@ var MultipleSelectFormatter = /*#__PURE__*/function (_React$PureComponent) {
26
26
  var _this$props = _this.props,
27
27
  value = _this$props.value,
28
28
  options = _this$props.options;
29
- if (!Array.isArray(value)) return [];
30
- var selectedOptions = options.filter(function (option) {
31
- return value.includes(option.id);
32
- });
33
- if (selectedOptions.length === 0) return [];
34
- return selectedOptions.map(function (option) {
35
- return /*#__PURE__*/React.createElement(SelectItem, {
36
- key: option.id,
37
- option: option
29
+ return value.map(function (item) {
30
+ var option = options.find(function (option) {
31
+ return option.id === item || option.name === item;
38
32
  });
33
+
34
+ if (option) {
35
+ return /*#__PURE__*/React.createElement(SelectItem, {
36
+ key: item,
37
+ option: option
38
+ });
39
+ }
39
40
  });
40
41
  };
41
42
 
package/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { setLocale } from './lang';
2
2
  export { formatDateToString, formatNumberToString, formatStringToNumber, formatNumberString } from './utils/value-format-utils';
3
3
  export { default as Loading } from './components/loading';
4
- export { TextFormatter, NumberFormatter, CheckboxFormatter, DateFormatter, SingleSelectFormatter, MultipleSelectFormatter, CollaboratorFormatter, ImageFormatter, FileFormatter, LongTextFormatter, GeolocationFormatter, LinkFormatter, FormulaFormatter, CTimeFormatter, CreatorFormatter, LastModifierFormatter, MTimeFormatter, AutoNumberFormatter, UrlFormatter, EmailFormatter, DurationFormatter, RateFormatter, ButtonFormatter, FileItemFormatter, ImagePreviewerLightbox } from './components/cell-formatter';
4
+ export { TextFormatter, NumberFormatter, CheckboxFormatter, DateFormatter, SingleSelectFormatter, MultipleSelectFormatter, CollaboratorFormatter, ImageFormatter, FileFormatter, LongTextFormatter, GeolocationFormatter, LinkFormatter, FormulaFormatter, CTimeFormatter, CreatorFormatter, LastModifierFormatter, MTimeFormatter, AutoNumberFormatter, UrlFormatter, EmailFormatter, DurationFormatter, RateFormatter, ButtonFormatter, FileItemFormatter, ImagePreviewerLightbox, CollaboratorItem } from './components/cell-formatter';
5
5
  export { TextEditor, NumberEditor, CheckboxEditor, SingleSelectEdtior, CollaboratorEditor, DateEditor, LinkEditor } from './components/cell-editor';
@@ -278,4 +278,38 @@ var getDurationDecimalSuffix = function getDurationDecimalSuffix(duration_format
278
278
  }
279
279
 
280
280
  return '';
281
+ };
282
+
283
+ export var getGeolocationDisplayString = function getGeolocationDisplayString(value, columnData) {
284
+ var _ref3 = columnData || {},
285
+ geo_format = _ref3.geo_format;
286
+
287
+ var cellValue = value || {};
288
+
289
+ if (!value) {
290
+ return null;
291
+ }
292
+
293
+ if (geo_format === 'lng_lat' && value.lng && value.lat) {
294
+ return "".concat(cellValue.lng, ", ").concat(cellValue.lat);
295
+ }
296
+
297
+ if (geo_format === 'country_region' && cellValue.country_region) {
298
+ return value.country_region || '';
299
+ }
300
+
301
+ var province = cellValue.province,
302
+ city = cellValue.city,
303
+ district = cellValue.district,
304
+ detail = cellValue.detail;
305
+
306
+ if (geo_format === 'province') {
307
+ return "".concat(province || '');
308
+ }
309
+
310
+ if (geo_format === 'province_city') {
311
+ return "".concat(province || '').concat(city || '');
312
+ }
313
+
314
+ return "".concat(province || '').concat(city || '').concat(district || '').concat(detail || '');
281
315
  };
@@ -34,7 +34,7 @@ var propTypes = {
34
34
  // 1 value is not exist, typeof value is array, but it's length is 0
35
35
  // 2 value is exist, but can't find in collaborators
36
36
  // 3 value is exist, typeof value is a string
37
- // 4 vlaue is exist, typeof value is array
37
+ // 4 value is exist, typeof value is array
38
38
 
39
39
  var CreatorFormatter = /*#__PURE__*/function (_React$PureComponent) {
40
40
  (0, _inheritsLoose2.default)(CreatorFormatter, _React$PureComponent);
@@ -39,7 +39,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
39
39
 
40
40
  var SIMPLE_CELL_FORMATTER_COLUMNS = [CellTypes.TEXT, CellTypes.NUMBER, CellTypes.DATE, CellTypes.CTIME, CellTypes.MTIME, CellTypes.GEOLOCATION, CellTypes.AUTO_NUMBER, CellTypes.URL, CellTypes.EMAIL, CellTypes.DURATION];
41
41
  var ARRAY_FORMAL_COLUMNS = [CellTypes.IMAGE, CellTypes.FILE, CellTypes.MULTIPLE_SELECT, CellTypes.COLLABORATOR];
42
- var FORMULA_COLUMN_TYPES = [CellTypes.FORMULA, CellTypes.LINK_FORMULA];
43
42
  var propTypes = {
44
43
  value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.object, _propTypes.default.bool]),
45
44
  column: _propTypes.default.Object,
@@ -99,6 +98,19 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
99
98
  {
100
99
  formatterProps.column = column;
101
100
  Formatter = FormulaFormatter;
101
+ break;
102
+ }
103
+
104
+ case CellTypes.CREATOR:
105
+ case CellTypes.LAST_MODIFIER:
106
+ {
107
+ formatterProps.collaborators = collaborators;
108
+ break;
109
+ }
110
+
111
+ default:
112
+ {
113
+ break;
102
114
  }
103
115
  }
104
116
 
@@ -129,12 +141,7 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
129
141
  return column.key === display_column_key;
130
142
  });
131
143
  if (!linkedColumn) return null;
132
- var linkedColumnType = linkedColumn.type,
133
- linkedColumnData = linkedColumn.data;
134
-
135
- if (FORMULA_COLUMN_TYPES.includes(linkedColumnType) && linkedColumnData && linkedColumnData.result_type === _constants.FORMULA_RESULT_TYPE.COLUMN) {
136
- return null;
137
- }
144
+ var linkedColumnType = linkedColumn.type;
138
145
 
139
146
  if (!ARRAY_FORMAL_COLUMNS.includes(linkedColumnType) && Object.prototype.toString.call(value) === '[object Array]') {
140
147
  var contentItemClassName = (0, _astroClassname.default)('formula-formatter-content-item', {
@@ -178,7 +185,6 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
178
185
  containerClassName = _this$props2.containerClassName,
179
186
  column = _this$props2.column;
180
187
  var columnData = column.data;
181
- if (!columnData) return null;
182
188
  var resultType = columnData.result_type;
183
189
 
184
190
  if (resultType === _constants.FORMULA_RESULT_TYPE.COLUMN) {
@@ -15,8 +15,11 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
15
15
 
16
16
  var _astroClassname = _interopRequireDefault(require("astro-classname"));
17
17
 
18
+ var _valueFormatUtils = require("../../utils/value-format-utils");
19
+
18
20
  var propTypes = {
19
21
  value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object]),
22
+ data: _propTypes.default.object,
20
23
  containerClassName: _propTypes.default.string
21
24
  };
22
25
 
@@ -32,16 +35,17 @@ var GeolocationFormatter = /*#__PURE__*/function (_React$Component) {
32
35
  _proto.render = function render() {
33
36
  var _this$props = this.props,
34
37
  value = _this$props.value,
38
+ data = _this$props.data,
35
39
  containerClassName = _this$props.containerClassName;
36
- var classname = (0, _astroClassname.default)('dtable-ui cell-formatter-container geolocation-formatter', containerClassName);
40
+ var className = (0, _astroClassname.default)('dtable-ui cell-formatter-container geolocation-formatter', containerClassName);
37
41
 
38
42
  if (typeof value !== 'object') {
39
43
  return null;
40
44
  }
41
45
 
42
46
  return /*#__PURE__*/_react.default.createElement("div", {
43
- className: classname
44
- }, (value.province || '') + " " + (value.city || '') + " " + (value.district || '') + " " + (value.detail || ''));
47
+ className: className
48
+ }, (0, _valueFormatUtils.getGeolocationDisplayString)(value, data));
45
49
  };
46
50
 
47
51
  return GeolocationFormatter;
@@ -54,6 +58,7 @@ var GeolocationFormatter = /*#__PURE__*/function (_React$Component) {
54
58
  district: '',
55
59
  detail: ''
56
60
  },
61
+ data: {},
57
62
  containerClassName: ''
58
63
  });
59
64
  GeolocationFormatter.propTypes = propTypes;
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports.ImagePreviewerLightbox = exports.FileItemFormatter = exports.ButtonFormatter = exports.RateFormatter = exports.DurationFormatter = exports.EmailFormatter = exports.UrlFormatter = exports.AutoNumberFormatter = exports.LinkFormatter = exports.FormulaFormatter = exports.MTimeFormatter = exports.LastModifierFormatter = exports.CreatorFormatter = exports.CTimeFormatter = exports.GeolocationFormatter = exports.ImageFormatter = exports.FileFormatter = exports.LongTextFormatter = exports.MultipleSelectFormatter = exports.SingleSelectFormatter = exports.CollaboratorFormatter = exports.CheckboxFormatter = exports.DateFormatter = exports.NumberFormatter = exports.TextFormatter = void 0;
6
+ exports.CollaboratorItem = exports.ImagePreviewerLightbox = exports.FileItemFormatter = exports.ButtonFormatter = exports.RateFormatter = exports.DurationFormatter = exports.EmailFormatter = exports.UrlFormatter = exports.AutoNumberFormatter = exports.LinkFormatter = exports.FormulaFormatter = exports.MTimeFormatter = exports.LastModifierFormatter = exports.CreatorFormatter = exports.CTimeFormatter = exports.GeolocationFormatter = exports.ImageFormatter = exports.FileFormatter = exports.LongTextFormatter = exports.MultipleSelectFormatter = exports.SingleSelectFormatter = exports.CollaboratorFormatter = exports.CheckboxFormatter = exports.DateFormatter = exports.NumberFormatter = exports.TextFormatter = void 0;
7
7
 
8
8
  require("../../css/cell-formatter.css");
9
9
 
@@ -105,4 +105,8 @@ exports.FileItemFormatter = _fileItemFormatter.default;
105
105
 
106
106
  var _imagePreviewerLightbox = _interopRequireDefault(require("./widgets/image-previewer-lightbox"));
107
107
 
108
- exports.ImagePreviewerLightbox = _imagePreviewerLightbox.default;
108
+ exports.ImagePreviewerLightbox = _imagePreviewerLightbox.default;
109
+
110
+ var _collaboratorItem = _interopRequireDefault(require("../common/collaborator-item"));
111
+
112
+ exports.CollaboratorItem = _collaboratorItem.default;
@@ -41,16 +41,17 @@ var MultipleSelectFormatter = /*#__PURE__*/function (_React$PureComponent) {
41
41
  var _this$props = _this.props,
42
42
  value = _this$props.value,
43
43
  options = _this$props.options;
44
- if (!Array.isArray(value)) return [];
45
- var selectedOptions = options.filter(function (option) {
46
- return value.includes(option.id);
47
- });
48
- if (selectedOptions.length === 0) return [];
49
- return selectedOptions.map(function (option) {
50
- return /*#__PURE__*/_react.default.createElement(_selectItem.default, {
51
- key: option.id,
52
- option: option
44
+ return value.map(function (item) {
45
+ var option = options.find(function (option) {
46
+ return option.id === item || option.name === item;
53
47
  });
48
+
49
+ if (option) {
50
+ return /*#__PURE__*/_react.default.createElement(_selectItem.default, {
51
+ key: item,
52
+ option: option
53
+ });
54
+ }
54
55
  });
55
56
  });
56
57
  return _this;
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports.LinkEditor = exports.DateEditor = exports.CollaboratorEditor = exports.SingleSelectEdtior = exports.CheckboxEditor = exports.NumberEditor = exports.TextEditor = exports.ImagePreviewerLightbox = exports.FileItemFormatter = exports.ButtonFormatter = exports.RateFormatter = exports.DurationFormatter = exports.EmailFormatter = exports.UrlFormatter = exports.AutoNumberFormatter = exports.MTimeFormatter = exports.LastModifierFormatter = exports.CreatorFormatter = exports.CTimeFormatter = exports.FormulaFormatter = exports.LinkFormatter = exports.GeolocationFormatter = exports.LongTextFormatter = exports.FileFormatter = exports.ImageFormatter = exports.CollaboratorFormatter = exports.MultipleSelectFormatter = exports.SingleSelectFormatter = exports.DateFormatter = exports.CheckboxFormatter = exports.NumberFormatter = exports.TextFormatter = exports.Loading = exports.formatNumberString = exports.formatStringToNumber = exports.formatNumberToString = exports.formatDateToString = exports.setLocale = void 0;
6
+ exports.LinkEditor = exports.DateEditor = exports.CollaboratorEditor = exports.SingleSelectEdtior = exports.CheckboxEditor = exports.NumberEditor = exports.TextEditor = exports.CollaboratorItem = exports.ImagePreviewerLightbox = exports.FileItemFormatter = exports.ButtonFormatter = exports.RateFormatter = exports.DurationFormatter = exports.EmailFormatter = exports.UrlFormatter = exports.AutoNumberFormatter = exports.MTimeFormatter = exports.LastModifierFormatter = exports.CreatorFormatter = exports.CTimeFormatter = exports.FormulaFormatter = exports.LinkFormatter = exports.GeolocationFormatter = exports.LongTextFormatter = exports.FileFormatter = exports.ImageFormatter = exports.CollaboratorFormatter = exports.MultipleSelectFormatter = exports.SingleSelectFormatter = exports.DateFormatter = exports.CheckboxFormatter = exports.NumberFormatter = exports.TextFormatter = exports.Loading = exports.formatNumberString = exports.formatStringToNumber = exports.formatNumberToString = exports.formatDateToString = exports.setLocale = void 0;
7
7
 
8
8
  var _lang = require("./lang");
9
9
 
@@ -47,6 +47,7 @@ exports.RateFormatter = _cellFormatter.RateFormatter;
47
47
  exports.ButtonFormatter = _cellFormatter.ButtonFormatter;
48
48
  exports.FileItemFormatter = _cellFormatter.FileItemFormatter;
49
49
  exports.ImagePreviewerLightbox = _cellFormatter.ImagePreviewerLightbox;
50
+ exports.CollaboratorItem = _cellFormatter.CollaboratorItem;
50
51
 
51
52
  var _cellEditor = require("./components/cell-editor");
52
53
 
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports.getDurationDisplayString = exports.formatDateToString = exports.formatNumberString = exports.formatStringToNumber = exports.formatNumberToString = void 0;
6
+ exports.getGeolocationDisplayString = exports.getDurationDisplayString = exports.formatDateToString = exports.formatNumberString = exports.formatStringToNumber = exports.formatNumberToString = void 0;
7
7
 
8
8
  var _moment = _interopRequireDefault(require("moment"));
9
9
 
@@ -303,4 +303,40 @@ var getDurationDecimalSuffix = function getDurationDecimalSuffix(duration_format
303
303
  }
304
304
 
305
305
  return '';
306
- };
306
+ };
307
+
308
+ var getGeolocationDisplayString = function getGeolocationDisplayString(value, columnData) {
309
+ var _ref3 = columnData || {},
310
+ geo_format = _ref3.geo_format;
311
+
312
+ var cellValue = value || {};
313
+
314
+ if (!value) {
315
+ return null;
316
+ }
317
+
318
+ if (geo_format === 'lng_lat' && value.lng && value.lat) {
319
+ return cellValue.lng + ", " + cellValue.lat;
320
+ }
321
+
322
+ if (geo_format === 'country_region' && cellValue.country_region) {
323
+ return value.country_region || '';
324
+ }
325
+
326
+ var province = cellValue.province,
327
+ city = cellValue.city,
328
+ district = cellValue.district,
329
+ detail = cellValue.detail;
330
+
331
+ if (geo_format === 'province') {
332
+ return "" + (province || '');
333
+ }
334
+
335
+ if (geo_format === 'province_city') {
336
+ return "" + (province || '') + (city || '');
337
+ }
338
+
339
+ return "" + (province || '') + (city || '') + (district || '') + (detail || '');
340
+ };
341
+
342
+ exports.getGeolocationDisplayString = getGeolocationDisplayString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "0.1.42",
3
+ "version": "0.1.46",
4
4
  "main": "./es/index.js",
5
5
  "dependencies": {
6
6
  "@seafile/seafile-calendar": "0.0.15",