dtable-ui-component 0.1.50 → 0.1.58

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 (39) hide show
  1. package/es/components/cell-editor/date-editor.js +2 -2
  2. package/es/components/cell-editor/index.js +1 -1
  3. package/es/components/cell-editor/link-editor.js +4 -4
  4. package/es/components/cell-editor/number-editor.js +13 -13
  5. package/es/components/cell-formatter/date-formatter.js +2 -2
  6. package/es/components/cell-formatter/formatter-config.js +1 -1
  7. package/es/components/cell-formatter/formula-formatter.js +62 -104
  8. package/es/components/cell-formatter/link-formatter.js +4 -4
  9. package/es/components/cell-formatter/multiple-select-formatter.js +9 -10
  10. package/es/components/cell-formatter/number-formatter.js +2 -2
  11. package/es/{utils → constants}/cell-types.js +0 -0
  12. package/es/{utils/constants.js → constants/index.js} +7 -0
  13. package/es/index.js +2 -2
  14. package/es/utils/cell-value-validator.js +32 -0
  15. package/es/utils/column-utils.js +7 -0
  16. package/es/utils/value-format-utils.js +196 -16
  17. package/lib/components/cell-editor/date-editor.js +1 -1
  18. package/lib/components/cell-editor/index.js +2 -2
  19. package/lib/components/cell-editor/link-editor.js +3 -3
  20. package/lib/components/cell-editor/number-editor.js +11 -11
  21. package/lib/components/cell-formatter/date-formatter.js +1 -1
  22. package/lib/components/cell-formatter/formatter-config.js +1 -1
  23. package/lib/components/cell-formatter/formula-formatter.js +67 -110
  24. package/lib/components/cell-formatter/index.js +1 -1
  25. package/lib/components/cell-formatter/link-formatter.js +3 -3
  26. package/lib/components/cell-formatter/multiple-select-formatter.js +9 -10
  27. package/lib/components/cell-formatter/number-formatter.js +1 -1
  28. package/lib/{utils → constants}/cell-types.js +1 -1
  29. package/lib/constants/index.js +70 -0
  30. package/lib/index.js +4 -4
  31. package/lib/lang/index.js +1 -1
  32. package/lib/utils/cell-value-validator.js +41 -0
  33. package/lib/utils/column-utils.js +15 -0
  34. package/lib/utils/editor-utils.js +1 -1
  35. package/lib/utils/number-precision.js +8 -8
  36. package/lib/utils/utils.js +1 -1
  37. package/lib/utils/value-format-utils.js +222 -19
  38. package/package.json +1 -1
  39. package/lib/utils/constants.js +0 -52
@@ -5,7 +5,7 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React, { Fragment } from 'react';
6
6
  import MediaQuery from 'react-responsive';
7
7
  import moment from 'moment';
8
- import { formatDateToString } from '../../utils/value-format-utils';
8
+ import { getDateDisplayString } from '../../utils/value-format-utils';
9
9
  import PCDateEditorPopover from '../cell-editor-popover/pc-date-editor-popover';
10
10
  import MBDateEditorPopover from '../cell-editor-popover/mb-date-editor-popover';
11
11
 
@@ -117,7 +117,7 @@ var DateEditor = /*#__PURE__*/function (_React$Component) {
117
117
  }, /*#__PURE__*/React.createElement("div", {
118
118
  className: "form-control",
119
119
  onClick: this.onDateEditorToggle
120
- }, formatDateToString(newValue, dateFormat))), isPopoverShow && /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(MediaQuery, {
120
+ }, getDateDisplayString(newValue, dateFormat))), isPopoverShow && /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(MediaQuery, {
121
121
  query: '(min-width: 768px)'
122
122
  }, /*#__PURE__*/React.createElement(PCDateEditorPopover, {
123
123
  lang: lang,
@@ -2,7 +2,7 @@ import "../../css/cell-editor.css";
2
2
  export { default as NumberEditor } from './number-editor';
3
3
  export { default as TextEditor } from './text-editor';
4
4
  export { default as CheckboxEditor } from './checkbox-editor';
5
- export { default as SingleSelectEdtior } from './single-select-editor';
5
+ export { default as SingleSelectEditor } from './single-select-editor';
6
6
  export { default as MultipleSelectEditor } from './multiple-select-editor';
7
7
  export { default as CollaboratorEditor } from './collaborator-editor';
8
8
  export { default as LinkEditor } from './link-editor';
@@ -5,8 +5,8 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React, { Fragment } from 'react';
6
6
  import MediaQuery from 'react-responsive';
7
7
  import { getLocale } from '../../lang';
8
- import * as CellTypes from '../../utils/cell-types';
9
- import { formatNumberToString, formatDateToString } from '../../utils/value-format-utils';
8
+ import * as CellTypes from '../../constants/cell-types';
9
+ import { getNumberDisplayString, getDateDisplayString } from '../../utils/value-format-utils';
10
10
  import EditEditorButton from '../common/edit-editor-button';
11
11
  import LinkEditorOption from '../common/link-editor-option';
12
12
  import PCLinkEditorPopover from '../cell-editor-popover/pc-link-editor-popover';
@@ -82,13 +82,13 @@ var LinkEditor = /*#__PURE__*/function (_React$Component) {
82
82
  switch (type) {
83
83
  case CellTypes.NUMBER:
84
84
  {
85
- return formatNumberToString(value, data);
85
+ return getNumberDisplayString(value, data);
86
86
  }
87
87
 
88
88
  case CellTypes.DATE:
89
89
  {
90
90
  var format = data.format;
91
- return formatDateToString(value, format);
91
+ return getDateDisplayString(value, format);
92
92
  }
93
93
 
94
94
  default:
@@ -4,18 +4,18 @@ 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 isHotkey from 'is-hotkey';
7
- import { NUMBER_TYPES } from '../../utils/constants';
8
- import { formatNumberToString, formatStringToNumber, formatNumberString } from '../../utils/value-format-utils';
7
+ import { NUMBER_TYPES } from '../../constants';
8
+ import { getNumberDisplayString, formatStringToNumber, formatNumberString } from '../../utils/value-format-utils';
9
9
 
10
- var NumebrEditor = /*#__PURE__*/function (_React$Component) {
11
- _inherits(NumebrEditor, _React$Component);
10
+ var NumberEditor = /*#__PURE__*/function (_React$Component) {
11
+ _inherits(NumberEditor, _React$Component);
12
12
 
13
- var _super = _createSuper(NumebrEditor);
13
+ var _super = _createSuper(NumberEditor);
14
14
 
15
- function NumebrEditor(props) {
15
+ function NumberEditor(props) {
16
16
  var _this;
17
17
 
18
- _classCallCheck(this, NumebrEditor);
18
+ _classCallCheck(this, NumberEditor);
19
19
 
20
20
  _this = _super.call(this, props);
21
21
 
@@ -42,7 +42,7 @@ var NumebrEditor = /*#__PURE__*/function (_React$Component) {
42
42
 
43
43
  _this.props.onCommit(updated);
44
44
 
45
- var newValue = formatNumberToString(value, column.data); // format the number to display
45
+ var newValue = getNumberDisplayString(value, column.data); // format the number to display
46
46
 
47
47
  _this.setState({
48
48
  isEditorShow: false,
@@ -107,7 +107,7 @@ var NumebrEditor = /*#__PURE__*/function (_React$Component) {
107
107
  _column = _this$props.column;
108
108
  var dataFormat = _column.data && _column.data.format;
109
109
  _this.dataFormat = dataFormat || NUMBER_TYPES.NUMBER;
110
- var initValue = formatNumberToString(_value, _column.data); // format the number to display
110
+ var initValue = getNumberDisplayString(_value, _column.data); // format the number to display
111
111
 
112
112
  _this.state = {
113
113
  inputValue: initValue,
@@ -117,7 +117,7 @@ var NumebrEditor = /*#__PURE__*/function (_React$Component) {
117
117
  return _this;
118
118
  }
119
119
 
120
- _createClass(NumebrEditor, [{
120
+ _createClass(NumberEditor, [{
121
121
  key: "render",
122
122
  value: function render() {
123
123
  var style = this.getStyle();
@@ -144,11 +144,11 @@ var NumebrEditor = /*#__PURE__*/function (_React$Component) {
144
144
  }
145
145
  }]);
146
146
 
147
- return NumebrEditor;
147
+ return NumberEditor;
148
148
  }(React.Component);
149
149
 
150
- NumebrEditor.defaultProps = {
150
+ NumberEditor.defaultProps = {
151
151
  isReadOnly: false,
152
152
  value: ''
153
153
  };
154
- export default NumebrEditor;
154
+ export default NumberEditor;
@@ -4,7 +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 { formatDateToString } from '../../utils/value-format-utils';
7
+ import { getDateDisplayString } from '../../utils/value-format-utils';
8
8
 
9
9
  var DateFormatter = /*#__PURE__*/function (_React$Component) {
10
10
  _inherits(DateFormatter, _React$Component);
@@ -23,7 +23,7 @@ var DateFormatter = /*#__PURE__*/function (_React$Component) {
23
23
  _this = _super.call.apply(_super, [this].concat(args));
24
24
 
25
25
  _this.formatDate = function (date, format) {
26
- return formatDateToString(date, format);
26
+ return getDateDisplayString(date, format);
27
27
  };
28
28
 
29
29
  return _this;
@@ -3,7 +3,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
3
  var _FormatterConfig;
4
4
 
5
5
  import React from 'react';
6
- import * as CellTypes from '../../utils/cell-types';
6
+ import * as CellTypes from '../../constants/cell-types';
7
7
  import CheckboxFormatter from './checkbox-formatter';
8
8
  import ImageFormatter from './image-formatter';
9
9
  import LongTextFormatter from './long-text-formatter';
@@ -4,15 +4,14 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
4
4
  import _inherits from "@babel/runtime/helpers/esm/inherits";
5
5
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
6
  import React from 'react';
7
- import cn from 'astro-classname';
8
- import { FORMULA_RESULT_TYPE } from '../../utils/constants';
7
+ import { FORMULA_RESULT_TYPE } from '../../constants';
9
8
  import cellFormatterFactory from '../cell-factory/cell-formatter-factory';
10
- import * as CellTypes from '../../utils/cell-types';
11
- import { formatNumberToString, formatDateToString } from '../../utils/value-format-utils';
9
+ import * as CellType from '../../constants/cell-types';
12
10
  import { isFunction } from '../../utils/utils';
13
11
  import TextFormatter from './text-formatter';
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
- var ARRAY_FORMAL_COLUMNS = [CellTypes.IMAGE, CellTypes.FILE, CellTypes.MULTIPLE_SELECT, CellTypes.COLLABORATOR];
12
+ import { isArrayFormalColumn, isSimpleCellFormatter } from '../../utils/column-utils';
13
+ import cellValueValidator from '../../utils/cell-value-validator';
14
+ import { getFormulaDisplayString } from '../../utils/value-format-utils';
16
15
 
17
16
  var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
18
17
  _inherits(FormulaFormatter, _React$Component);
@@ -30,134 +29,92 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
30
29
 
31
30
  _this = _super.call.apply(_super, [this].concat(args));
32
31
 
33
- _this.getOtherColumnFormatter = function (value, column) {
34
- var collaborators = _this.props.collaborators;
35
- var formatterProps = {
36
- value: value
37
- };
38
- var columnType = column.type;
39
- var Formatter = cellFormatterFactory.createFormatter(columnType);
40
-
41
- switch (columnType) {
42
- case CellTypes.NUMBER:
43
- {
44
- formatterProps.data = column.data;
45
- break;
46
- }
47
-
48
- case CellTypes.DATE:
32
+ _this.getGridCellClassName = function (resultType) {
33
+ switch (resultType) {
34
+ case FORMULA_RESULT_TYPE.NUMBER:
49
35
  {
50
- formatterProps.format = column.format;
51
- break;
52
- }
53
-
54
- case CellTypes.SINGLE_SELECT:
55
- case CellTypes.MULTIPLE_SELECT:
56
- {
57
- formatterProps.options = column.data.options;
58
- break;
59
- }
60
-
61
- case CellTypes.COLLABORATOR:
62
- {
63
- formatterProps.collaborators = collaborators;
64
- break;
65
- }
66
-
67
- case CellTypes.FORMULA:
68
- case CellTypes.LINK_FORMULA:
69
- {
70
- formatterProps.column = column;
71
- Formatter = FormulaFormatter;
72
- break;
73
- }
74
-
75
- case CellTypes.CREATOR:
76
- case CellTypes.LAST_MODIFIER:
77
- {
78
- formatterProps.collaborators = collaborators;
79
- break;
36
+ return 'text-right';
80
37
  }
81
38
 
82
39
  default:
83
40
  {
84
- break;
41
+ return '';
85
42
  }
86
43
  }
87
-
88
- if (React.isValidElement(Formatter)) {
89
- return React.cloneElement(Formatter, _objectSpread({}, formatterProps));
90
- } else if (isFunction(Formatter)) {
91
- return /*#__PURE__*/React.createElement(Formatter, formatterProps);
92
- }
93
-
94
- return /*#__PURE__*/React.createElement(TextFormatter, formatterProps);
95
44
  };
96
45
 
97
46
  _this.renderOtherColumnFormatter = function () {
98
47
  var _this$props = _this.props,
99
48
  value = _this$props.value,
100
49
  column = _this$props.column,
101
- tables = _this$props.tables;
50
+ collaborators = _this$props.collaborators;
102
51
  var columnData = column.data;
52
+ var array_type = columnData.array_type,
53
+ array_data = columnData.array_data;
103
54
 
104
- var _ref = columnData || {},
105
- display_column_key = _ref.display_column_key,
106
- linked_table_id = _ref.linked_table_id;
55
+ if (!array_type || array_type === CellType.LINK) {
56
+ return null;
57
+ }
107
58
 
108
- var linkedTable = tables.find(function (table) {
109
- return table._id === linked_table_id;
110
- });
111
- if (!linkedTable) return null;
112
- var linkedColumn = linkedTable.columns.find(function (column) {
113
- return column.key === display_column_key;
59
+ var Formatter = cellFormatterFactory.createFormatter(array_type);
60
+
61
+ var formatterProps = _objectSpread(_objectSpread({}, array_data), {}, {
62
+ collaborators: collaborators
114
63
  });
115
- if (!linkedColumn) return null;
116
- var linkedColumnType = linkedColumn.type;
117
64
 
118
- if (!ARRAY_FORMAL_COLUMNS.includes(linkedColumnType) && Object.prototype.toString.call(value) === '[object Array]') {
119
- var contentItemClassName = cn('formula-formatter-content-item', {
120
- 'simple-cell-formatter': SIMPLE_CELL_FORMATTER_COLUMNS.includes(linkedColumnType)
121
- });
122
- return /*#__PURE__*/React.createElement("div", {
123
- className: "dtable-ui formula-formatter multiple"
124
- }, value.map(function (v, index) {
125
- return /*#__PURE__*/React.createElement("div", {
126
- className: contentItemClassName,
127
- key: "formula-formatter-content-item-".concat(index)
128
- }, _this.getOtherColumnFormatter(v, linkedColumn));
129
- }));
65
+ if (isArrayFormalColumn(array_type)) {
66
+ formatterProps.value = value;
67
+ return _this.createColumnFormatter(Formatter, formatterProps);
130
68
  }
131
69
 
132
- return _this.getOtherColumnFormatter(value, linkedColumn);
133
- };
70
+ if (array_type === CellType.FORMULA || array_type === CellType.FORMULA) {
71
+ formatterProps.column = {
72
+ data: array_data
73
+ };
74
+ }
75
+
76
+ var _isSimpleCellFormatterColumn = isSimpleCellFormatter(array_type);
134
77
 
135
- _this.getFormattedValue = function (cellValue, columnData) {
136
- if (!columnData) return '';
137
- var result_type = columnData.result_type;
78
+ var cellValue = value;
138
79
 
139
- if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
140
- cellValue = parseFloat(cellValue);
141
- return formatNumberToString(cellValue, columnData);
142
- } else if (result_type === FORMULA_RESULT_TYPE.DATE) {
143
- var format = columnData.format;
144
- return formatDateToString(cellValue, format);
80
+ if (!Array.isArray(value)) {
81
+ cellValue = cellValueValidator(value, array_type) ? [value] : [];
145
82
  }
146
83
 
147
- var formattedValue = Object.prototype.toString.call(cellValue) === '[object Boolean]' ? cellValue + '' : cellValue;
148
- return formattedValue;
84
+ var contentItemClassName = "formula-formatter-content-item ".concat(_isSimpleCellFormatterColumn ? 'simple-cell-formatter' : '');
85
+ return /*#__PURE__*/React.createElement("div", {
86
+ className: "dtable-ui formula-formatter multiple"
87
+ }, cellValue.map(function (v, index) {
88
+ formatterProps.value = v;
89
+ return /*#__PURE__*/React.createElement("div", {
90
+ className: contentItemClassName,
91
+ key: "formula-formatter-content-item-".concat(index)
92
+ }, _this.createColumnFormatter(Formatter, formatterProps));
93
+ }));
149
94
  };
150
95
 
151
96
  return _this;
152
97
  }
153
98
 
154
99
  _createClass(FormulaFormatter, [{
100
+ key: "createColumnFormatter",
101
+ value: function createColumnFormatter(Formatter, formatterProps) {
102
+ if (React.isValidElement(Formatter)) {
103
+ return React.cloneElement(Formatter, _objectSpread({}, formatterProps));
104
+ } else if (isFunction(Formatter)) {
105
+ return /*#__PURE__*/React.createElement(Formatter, formatterProps);
106
+ }
107
+
108
+ return /*#__PURE__*/React.createElement(TextFormatter, formatterProps);
109
+ }
110
+ }, {
155
111
  key: "render",
156
112
  value: function render() {
157
113
  var _this$props2 = this.props,
158
114
  value = _this$props2.value,
159
115
  containerClassName = _this$props2.containerClassName,
160
- column = _this$props2.column;
116
+ column = _this$props2.column,
117
+ collaborators = _this$props2.collaborators;
161
118
  var columnData = column.data;
162
119
  var resultType = columnData.result_type;
163
120
 
@@ -169,13 +126,14 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
169
126
  return null;
170
127
  }
171
128
 
172
- var isNumber = resultType === FORMULA_RESULT_TYPE.NUMBER;
173
- var classname = cn('dtable-ui cell-formatter-container formula-formatter', containerClassName, {
174
- "text-right": isNumber
129
+ var gridCellClassName = this.getGridCellClassName(resultType);
130
+ var formattedValue = getFormulaDisplayString(value, columnData, {
131
+ collaborators: collaborators
175
132
  });
176
- var formattedValue = this.getFormattedValue(value, columnData);
177
133
  return /*#__PURE__*/React.createElement("div", {
178
- className: classname
134
+ className: "dtable-ui cell-formatter-container formula-formatter ".concat(containerClassName, " ").concat(gridCellClassName),
135
+ title: formattedValue,
136
+ "aria-label": formattedValue
179
137
  }, formattedValue);
180
138
  }
181
139
  }]);
@@ -5,8 +5,8 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
5
5
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
6
  import React from 'react';
7
7
  import cn from 'astro-classname';
8
- import * as CellTypes from '../../utils/cell-types';
9
- import { formatNumberToString, formatDateToString } from '../../utils/value-format-utils';
8
+ import * as CellTypes from '../../constants/cell-types';
9
+ import { getNumberDisplayString, getDateDisplayString } from '../../utils/value-format-utils';
10
10
 
11
11
  // link value is get form parant's interface
12
12
  var LinkFormatter = /*#__PURE__*/function (_React$Component) {
@@ -88,13 +88,13 @@ var LinkFormatter = /*#__PURE__*/function (_React$Component) {
88
88
  switch (type) {
89
89
  case CellTypes.NUMBER:
90
90
  {
91
- return formatNumberToString(value, data);
91
+ return getNumberDisplayString(value, data);
92
92
  }
93
93
 
94
94
  case CellTypes.DATE:
95
95
  {
96
96
  var format = data.format;
97
- return formatDateToString(value, format);
97
+ return getDateDisplayString(value, format);
98
98
  }
99
99
 
100
100
  default:
@@ -26,17 +26,16 @@ 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
- return value.map(function (item) {
30
- var option = options.find(function (option) {
31
- return option.id === item || option.name === item;
29
+ if (!Array.isArray(value) || !Array.isArray(options)) 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: "multiple-".concat(option.id),
37
+ option: option
32
38
  });
33
-
34
- if (option) {
35
- return /*#__PURE__*/React.createElement(SelectItem, {
36
- key: item,
37
- option: option
38
- });
39
- }
40
39
  });
41
40
  };
42
41
 
@@ -4,7 +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 { formatNumberToString } from '../../utils/value-format-utils';
7
+ import { getNumberDisplayString } from '../../utils/value-format-utils';
8
8
 
9
9
  var NumberFormatter = /*#__PURE__*/function (_React$Component) {
10
10
  _inherits(NumberFormatter, _React$Component);
@@ -27,7 +27,7 @@ var NumberFormatter = /*#__PURE__*/function (_React$Component) {
27
27
  var classname = cn('dtable-ui cell-formatter-container number-formatter', containerClassName);
28
28
 
29
29
  if (number || number === 0) {
30
- number = formatNumberToString(number, data);
30
+ number = getNumberDisplayString(number, data);
31
31
  }
32
32
 
33
33
  return /*#__PURE__*/React.createElement("div", {
File without changes
@@ -2,6 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
 
3
3
  var _DURATION_ZERO_DISPLA, _DURATION_DECIMAL_DIG;
4
4
 
5
+ import * as CellType from './cell-types';
5
6
  export var NUMBER_TYPES = {
6
7
  'NUMBER': 'number',
7
8
  'NUMBER_WITH_COMMAS': 'number-with-commas',
@@ -25,7 +26,13 @@ export var FORMULA_RESULT_TYPE = {
25
26
  BOOL: 'bool',
26
27
  ARRAY: 'array'
27
28
  };
29
+ export var SIMPLE_CELL_COLUMNS = [CellType.TEXT, CellType.NUMBER, CellType.DATE, CellType.CTIME, CellType.MTIME, CellType.GEOLOCATION, CellType.AUTO_NUMBER, CellType.URL, CellType.EMAIL, CellType.DURATION, CellType.CHECKBOX, CellType.RATE];
30
+ export var ARRAY_FORMAL_COLUMNS = [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR];
31
+ export var SIMPLE_CELL_FORMULA_RESULTS = [FORMULA_RESULT_TYPE.NUMBER, FORMULA_RESULT_TYPE.STRING, FORMULA_RESULT_TYPE.DATE, FORMULA_RESULT_TYPE.BOOL];
32
+ export var COLLABORATOR_COLUMN_TYPES = [CellType.COLLABORATOR, CellType.CREATOR, CellType.LAST_MODIFIER];
33
+ export var ARRAY_FORMAL_COLUMNS_TYPES = [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR];
28
34
  export var DEFAULT_NUMBER_FORMAT = 'number';
35
+ export var DEFAULT_DATE_FORMAT = 'YYYY-MM-DD';
29
36
  export var DURATION_FORMATS_MAP = {
30
37
  H_MM: 'h:mm',
31
38
  H_MM_SS: 'h:mm:ss'
package/es/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { default as toaster } from './components/toast';
2
2
  export { setLocale } from './lang';
3
- export { formatDateToString, formatNumberToString, formatStringToNumber, formatNumberString } from './utils/value-format-utils';
3
+ export { getDateDisplayString, getNumberDisplayString, formatStringToNumber, formatNumberString } from './utils/value-format-utils';
4
4
  export { default as Loading } from './components/loading';
5
5
  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';
6
- export { TextEditor, NumberEditor, CheckboxEditor, SingleSelectEdtior, CollaboratorEditor, DateEditor, LinkEditor } from './components/cell-editor';
6
+ export { TextEditor, NumberEditor, CheckboxEditor, SingleSelectEditor, CollaboratorEditor, DateEditor, LinkEditor } from './components/cell-editor';
@@ -0,0 +1,32 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+
3
+ var _validators;
4
+
5
+ import * as CellType from '../constants/cell-types';
6
+ import { FORMULA_RESULT_TYPE } from '../constants';
7
+
8
+ var numberValidator = function numberValidator(value) {
9
+ return (value || value === 0) && Object.prototype.toString.call(value) === '[object Number]';
10
+ };
11
+
12
+ var textValidator = function textValidator(value) {
13
+ return !!value;
14
+ };
15
+
16
+ var checkboxValidator = function checkboxValidator(value) {
17
+ return typeof value === 'boolean';
18
+ };
19
+
20
+ var validators = (_validators = {}, _defineProperty(_validators, CellType.NUMBER, numberValidator), _defineProperty(_validators, CellType.RATE, numberValidator), _defineProperty(_validators, CellType.DURATION, numberValidator), _defineProperty(_validators, CellType.CHECKBOX, checkboxValidator), _defineProperty(_validators, CellType.TEXT, textValidator), _defineProperty(_validators, CellType.DATE, textValidator), _defineProperty(_validators, CellType.CTIME, textValidator), _defineProperty(_validators, CellType.MTIME, textValidator), _defineProperty(_validators, CellType.GEOLOCATION, textValidator), _defineProperty(_validators, CellType.AUTO_NUMBER, textValidator), _defineProperty(_validators, CellType.URL, textValidator), _defineProperty(_validators, CellType.EMAIL, textValidator), _defineProperty(_validators, FORMULA_RESULT_TYPE.DATE, textValidator), _defineProperty(_validators, FORMULA_RESULT_TYPE.STRING, textValidator), _defineProperty(_validators, FORMULA_RESULT_TYPE.NUMBER, numberValidator), _defineProperty(_validators, FORMULA_RESULT_TYPE.BOOL, checkboxValidator), _validators);
21
+
22
+ var cellValueValidator = function cellValueValidator(cellValue, type) {
23
+ var validator = validators[type];
24
+
25
+ if (validator) {
26
+ return validator(cellValue);
27
+ }
28
+
29
+ return true;
30
+ };
31
+
32
+ export default cellValueValidator;
@@ -0,0 +1,7 @@
1
+ import { ARRAY_FORMAL_COLUMNS, SIMPLE_CELL_COLUMNS, SIMPLE_CELL_FORMULA_RESULTS } from '../constants';
2
+ export function isSimpleCellFormatter(type) {
3
+ return SIMPLE_CELL_COLUMNS.includes(type) || SIMPLE_CELL_FORMULA_RESULTS.includes(type);
4
+ }
5
+ export function isArrayFormalColumn(columnType) {
6
+ return ARRAY_FORMAL_COLUMNS.includes(columnType);
7
+ }