dtable-ui-component 0.3.7 → 0.3.8-alpha2

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.
@@ -7,7 +7,7 @@ import React from 'react';
7
7
  import { CellType, FORMULA_RESULT_TYPE, getFormulaDisplayString } from 'dtable-utils';
8
8
  import BaseFormatterConfig from '../formatterConfig/base-formatter-config';
9
9
  import TextFormatter from '../TextFormatter';
10
- import { isArrayFormalColumn, isSimpleCellFormatter, isFunction, getFormulaArrayValue, convertValueToDtableLongTextValue } from './utils';
10
+ import { isArrayFormatColumn, isSimpleCellFormatter, isFunction, getFormulaArrayValue, convertValueToDtableLongTextValue } from './utils';
11
11
  import cellValueValidator from './cell-value-validator';
12
12
  import './index.css';
13
13
 
@@ -58,7 +58,7 @@ var FormulaFormatter = /*#__PURE__*/function (_React$Component) {
58
58
 
59
59
  var formatterProps = _this.getFormatterProps(array_type, array_data, collaborators);
60
60
 
61
- if (isArrayFormalColumn(array_type)) {
61
+ if (isArrayFormatColumn(array_type)) {
62
62
  formatterProps.value = value;
63
63
  return _this.createColumnFormatter(Formatter, formatterProps);
64
64
  }
@@ -1,10 +1,10 @@
1
- import { ARRAY_FORMAL_COLUMNS, SIMPLE_CELL_COLUMNS, SIMPLE_CELL_FORMULA_RESULTS } from '../constants';
1
+ import { ARRAY_FORMAT_COLUMNS, SIMPLE_CELL_COLUMNS, SIMPLE_CELL_FORMULA_RESULTS } from '../constants';
2
2
  import getPreviewContent from '../SimpleLongTextFormatter/normalize-long-text-value';
3
3
  export function isSimpleCellFormatter(type) {
4
4
  return SIMPLE_CELL_COLUMNS.includes(type) || SIMPLE_CELL_FORMULA_RESULTS.includes(type);
5
5
  }
6
- export function isArrayFormalColumn(columnType) {
7
- return ARRAY_FORMAL_COLUMNS.includes(columnType);
6
+ export function isArrayFormatColumn(columnType) {
7
+ return ARRAY_FORMAT_COLUMNS.includes(columnType);
8
8
  }
9
9
  export var isFunction = function isFunction(functionToCheck) {
10
10
  var getType = {};
@@ -1,18 +1,30 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
4
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
5
  import _inherits from "@babel/runtime/helpers/esm/inherits";
5
6
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
6
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
-
8
- var _emptyTypeMap;
9
-
10
7
  import React from 'react';
11
8
  import classnames from 'classnames';
12
- import { TextFormatter, NumberFormatter, CheckboxFormatter, DateFormatter, SingleSelectFormatter, MultipleSelectFormatter, CollaboratorFormatter, LongTextFormatter, GeolocationFormatter, CTimeFormatter, CreatorFormatter, LastModifierFormatter, MTimeFormatter, AutoNumberFormatter, DurationFormatter, ButtonFormatter, RowExpandUrlFormatter, RowExpandEmailFormatter, RowExpandRateFormatter, RowExpandImageFormatter, RowExpandFileFormatter, RowExpandLinkFormatter, DigitalSignFormatter, FormulaFormatter } from '../index';
9
+ import { TextFormatter, NumberFormatter, CheckboxFormatter, DateFormatter, SingleSelectFormatter, MultipleSelectFormatter, CollaboratorFormatter, LongTextFormatter, GeolocationFormatter, CTimeFormatter, CreatorFormatter, LastModifierFormatter, MTimeFormatter, AutoNumberFormatter, DurationFormatter, ButtonFormatter, RowExpandUrlFormatter, RowExpandEmailFormatter, RowExpandRateFormatter, RowExpandImageFormatter, RowExpandFileFormatter, RowExpandLinkFormatter, RowExpandFormulaFormatter, DigitalSignFormatter } from '../index';
13
10
  import { CellType } from '../constants';
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.IMAGE, true), _defineProperty(_emptyTypeMap, CellType.FILE, true), _defineProperty(_emptyTypeMap, CellType.CREATOR, true), _defineProperty(_emptyTypeMap, CellType.LAST_MODIFIER, true), _emptyTypeMap);
11
+ import './index.css'; // const emptyTypeMap = {
12
+ // [CellType.TEXT]: true,
13
+ // [CellType.LONG_TEXT]: true,
14
+ // [CellType.GEOLOCATION]: true,
15
+ // [CellType.SINGLE_SELECT]: true,
16
+ // [CellType.MULTIPLE_SELECT]: true,
17
+ // [CellType.CTIME]: true,
18
+ // [CellType.MTIME]: true,
19
+ // [CellType.DATE]: true,
20
+ // [CellType.AUTO_NUMBER]: true,
21
+ // [CellType.URL]: true,
22
+ // [CellType.EMAIL]: true,
23
+ // [CellType.IMAGE]: true,
24
+ // [CellType.FILE]: true,
25
+ // [CellType.CREATOR]: true,
26
+ // [CellType.LAST_MODIFIER]: true,
27
+ // };
16
28
 
17
29
  var EditorFormatter = /*#__PURE__*/function (_React$Component) {
18
30
  _inherits(EditorFormatter, _React$Component);
@@ -72,8 +84,8 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
72
84
  };
73
85
 
74
86
  _this.renderEmpty = function () {
75
- return /*#__PURE__*/React.createElement("span", {
76
- className: "row-cell-empty"
87
+ return /*#__PURE__*/React.createElement("div", {
88
+ className: "d-flex align-items-center form-control disabled h-auto"
77
89
  });
78
90
  };
79
91
 
@@ -86,11 +98,9 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
86
98
  columnType = _column.type;
87
99
  var collaborators = _this.state.collaborators;
88
100
  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
- }
101
+ var cellValue = row[column.key] || row[column.name]; // if (!cellValue && emptyTypeMap[columnType]) {
102
+ // return this.renderEmpty();
103
+ // }
94
104
 
95
105
  switch (columnType) {
96
106
  case CellType.TEXT:
@@ -105,10 +115,9 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
105
115
 
106
116
  case CellType.COLLABORATOR:
107
117
  {
108
- if (!cellValue || cellValue.length === 0) {
109
- return _this.renderEmpty();
110
- }
111
-
118
+ // if (!cellValue || cellValue.length === 0) {
119
+ // return this.renderEmpty();
120
+ // }
112
121
  return /*#__PURE__*/React.createElement("div", {
113
122
  className: "form-control d-flex align-items-center w-100 h-auto"
114
123
  }, /*#__PURE__*/React.createElement(CollaboratorFormatter, {
@@ -142,10 +151,9 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
142
151
 
143
152
  case CellType.NUMBER:
144
153
  {
145
- if (!cellValue && cellValue !== 0) {
146
- return _this.renderEmpty();
147
- }
148
-
154
+ // if (!cellValue && cellValue !== 0) {
155
+ // return this.renderEmpty();
156
+ // }
149
157
  return /*#__PURE__*/React.createElement("div", {
150
158
  className: "form-control d-flex align-items-center",
151
159
  style: {
@@ -174,10 +182,9 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
174
182
 
175
183
  case CellType.CTIME:
176
184
  {
177
- if (!row._ctime) {
178
- return _this.renderEmpty();
179
- }
180
-
185
+ // if (!row._ctime) {
186
+ // return this.renderEmpty();
187
+ // }
181
188
  return /*#__PURE__*/React.createElement("div", {
182
189
  className: "form-control d-flex align-items-center ctime-formatter-container",
183
190
  style: {
@@ -191,10 +198,9 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
191
198
 
192
199
  case CellType.MTIME:
193
200
  {
194
- if (!row._mtime) {
195
- return _this.renderEmpty();
196
- }
197
-
201
+ // if (!row._mtime) {
202
+ // return this.renderEmpty();
203
+ // }
198
204
  return /*#__PURE__*/React.createElement("div", {
199
205
  className: "form-control d-flex align-items-center mtime-formatter-container",
200
206
  style: {
@@ -208,10 +214,9 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
208
214
 
209
215
  case CellType.MULTIPLE_SELECT:
210
216
  {
211
- if (!cellValue || cellValue.length === 0) {
212
- return _this.renderEmpty();
213
- }
214
-
217
+ // if (!cellValue || cellValue.length === 0) {
218
+ // return this.renderEmpty();
219
+ // }
215
220
  var options = column.data ? column.data.options : [];
216
221
  return /*#__PURE__*/React.createElement("div", {
217
222
  className: "form-control d-flex align-items-center w-100 h-auto"
@@ -286,11 +291,10 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
286
291
  case CellType.FORMULA:
287
292
  case CellType.LINK_FORMULA:
288
293
  {
289
- if (!cellValue && cellValue !== 0 && cellValue !== false) {
290
- return _this.renderEmpty();
291
- }
292
-
293
- return /*#__PURE__*/React.createElement(FormulaFormatter, {
294
+ // if (!cellValue && cellValue !== 0 && cellValue !== false) {
295
+ // return this.renderEmpty();
296
+ // }
297
+ return /*#__PURE__*/React.createElement(RowExpandFormulaFormatter, {
294
298
  value: cellValue,
295
299
  column: column,
296
300
  collaborators: collaborators,
@@ -317,11 +321,10 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
317
321
  }
318
322
  })
319
323
  });
320
- }
324
+ } // if (!Array.isArray(cellValue) || cellValue.length === 0) {
325
+ // return this.renderEmpty();
326
+ // }
321
327
 
322
- if (!Array.isArray(cellValue) || cellValue.length === 0) {
323
- return _this.renderEmpty();
324
- }
325
328
 
326
329
  return /*#__PURE__*/React.createElement(RowExpandLinkFormatter, {
327
330
  value: cellValue,
@@ -362,10 +365,9 @@ var EditorFormatter = /*#__PURE__*/function (_React$Component) {
362
365
 
363
366
  case CellType.DURATION:
364
367
  {
365
- if (!cellValue && cellValue !== 0) {
366
- return _this.renderEmpty();
367
- }
368
-
368
+ // if (!cellValue && cellValue !== 0) {
369
+ // return this.renderEmpty();
370
+ // }
369
371
  return /*#__PURE__*/React.createElement("div", {
370
372
  className: "form-control d-flex align-items-center",
371
373
  style: {
@@ -0,0 +1,188 @@
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 React from 'react';
7
+ import { CellType, FORMULA_RESULT_TYPE, getFormulaDisplayString } from 'dtable-utils';
8
+ import BaseFormatterConfig from '../formatterConfig/base-formatter-config';
9
+ import TextFormatter from '../TextFormatter';
10
+ import { isArrayFormatColumn, isSimpleCellFormatter, isFunction, getFormulaArrayValue, convertValueToDtableLongTextValue } from '../FormulaFormatter/utils';
11
+ import cellValueValidator from '../FormulaFormatter/cell-value-validator';
12
+ import '../FormulaFormatter/index.css';
13
+
14
+ var RowExpandFormulaFormatter = /*#__PURE__*/function (_React$Component) {
15
+ _inherits(RowExpandFormulaFormatter, _React$Component);
16
+
17
+ var _super = _createSuper(RowExpandFormulaFormatter);
18
+
19
+ function RowExpandFormulaFormatter() {
20
+ var _this;
21
+
22
+ _classCallCheck(this, RowExpandFormulaFormatter);
23
+
24
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
25
+ args[_key] = arguments[_key];
26
+ }
27
+
28
+ _this = _super.call.apply(_super, [this].concat(args));
29
+
30
+ _this.renderBorder = function (dom) {
31
+ var column = _this.props.column;
32
+ var result_type = column.data.result_type;
33
+ var style = {
34
+ minHeight: '38px'
35
+ };
36
+
37
+ if (result_type === FORMULA_RESULT_TYPE.DATE || result_type === FORMULA_RESULT_TYPE.NUMBER) {
38
+ style = {
39
+ width: '320px'
40
+ };
41
+ }
42
+
43
+ return /*#__PURE__*/React.createElement("div", {
44
+ className: "d-flex align-items-center form-control disabled h-auto",
45
+ style: style
46
+ }, dom);
47
+ };
48
+
49
+ _this.renderOtherColumnFormatter = function () {
50
+ var _this$props = _this.props,
51
+ value = _this$props.value,
52
+ column = _this$props.column,
53
+ collaborators = _this$props.collaborators;
54
+ var _column$data = column.data,
55
+ array_type = _column$data.array_type,
56
+ array_data = _column$data.array_data;
57
+
58
+ if (!array_type || array_type === CellType.LINK) {
59
+ return null;
60
+ }
61
+
62
+ var Formatter = BaseFormatterConfig[array_type];
63
+
64
+ var formatterProps = _this.getFormatterProps(array_type, array_data, collaborators);
65
+
66
+ if (isArrayFormatColumn(array_type)) {
67
+ formatterProps.value = value;
68
+ return _this.renderBorder(_this.createColumnFormatter(Formatter, formatterProps));
69
+ }
70
+
71
+ var cellValue = value;
72
+
73
+ if (!Array.isArray(value)) {
74
+ cellValue = cellValueValidator(value, array_type) ? [value] : [];
75
+ }
76
+
77
+ return _this.renderBorder( /*#__PURE__*/React.createElement("div", {
78
+ className: "dtable-ui formula-formatter multiple"
79
+ }, cellValue.map(function (v, index) {
80
+ formatterProps.value = v;
81
+ return /*#__PURE__*/React.createElement("div", {
82
+ className: "formula-formatter-content-item ".concat(isSimpleCellFormatter(array_type) ? 'simple-cell-formatter' : ''),
83
+ key: "formula-formatter-content-item-".concat(index)
84
+ }, _this.createColumnFormatter(Formatter, formatterProps));
85
+ })));
86
+ };
87
+
88
+ _this.getFormatterProps = function (array_type, array_data, collaborators) {
89
+ switch (array_type) {
90
+ case CellType.DURATION:
91
+ {
92
+ var duration_format = array_data.duration_format;
93
+ return {
94
+ format: duration_format
95
+ };
96
+ }
97
+
98
+ case CellType.NUMBER:
99
+ case CellType.RATE:
100
+ case CellType.GEOLOCATION:
101
+ {
102
+ return {
103
+ data: array_data
104
+ };
105
+ }
106
+
107
+ default:
108
+ {
109
+ return _objectSpread(_objectSpread({}, array_data), {}, {
110
+ collaborators: collaborators
111
+ });
112
+ }
113
+ }
114
+ };
115
+
116
+ return _this;
117
+ }
118
+
119
+ _createClass(RowExpandFormulaFormatter, [{
120
+ key: "createColumnFormatter",
121
+ value: function createColumnFormatter(Formatter, formatterProps) {
122
+ if (React.isValidElement(Formatter)) {
123
+ return React.cloneElement(Formatter, _objectSpread({}, formatterProps));
124
+ } else if (isFunction(Formatter)) {
125
+ return /*#__PURE__*/React.createElement(Formatter, formatterProps);
126
+ } else {
127
+ return /*#__PURE__*/React.createElement(TextFormatter, formatterProps);
128
+ }
129
+ }
130
+ }, {
131
+ key: "render",
132
+ value: function render() {
133
+ var _this$props2 = this.props,
134
+ containerClassName = _this$props2.containerClassName,
135
+ column = _this$props2.column,
136
+ collaborators = _this$props2.collaborators,
137
+ value = _this$props2.value;
138
+ var data = column.data;
139
+ var array_type = data.array_type,
140
+ result_type = data.result_type;
141
+
142
+ if (Array.isArray(value)) {
143
+ value = getFormulaArrayValue(value);
144
+
145
+ if (array_type === CellType.DATE || result_type === FORMULA_RESULT_TYPE.DATE) {
146
+ value = value.map(function (item) {
147
+ return item.replace('T', ' ').replace('Z', '');
148
+ });
149
+ } else if (array_type === CellType.LONG_TEXT) {
150
+ value = value.map(function (item) {
151
+ return convertValueToDtableLongTextValue(item);
152
+ });
153
+ }
154
+ } else {
155
+ if (result_type === FORMULA_RESULT_TYPE.DATE) {
156
+ value = value.replace('T', ' ').replace('Z', '');
157
+ }
158
+ }
159
+
160
+ if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
161
+ return this.renderOtherColumnFormatter();
162
+ }
163
+
164
+ if (typeof value === 'object') {
165
+ return null;
166
+ }
167
+
168
+ var formattedValue = getFormulaDisplayString(value, data, {
169
+ collaborators: collaborators
170
+ });
171
+ var className = "dtable-ui cell-formatter-container formula-formatter ".concat(containerClassName);
172
+
173
+ if (result_type === FORMULA_RESULT_TYPE.NUMBER) {
174
+ className = className + ' text-right';
175
+ }
176
+
177
+ return this.renderBorder( /*#__PURE__*/React.createElement("div", {
178
+ className: className,
179
+ title: formattedValue,
180
+ "aria-label": formattedValue
181
+ }, formattedValue));
182
+ }
183
+ }]);
184
+
185
+ return RowExpandFormulaFormatter;
186
+ }(React.Component);
187
+
188
+ export { RowExpandFormulaFormatter as default };
@@ -7,7 +7,7 @@ import React, { Component } from 'react';
7
7
  import { CellType } from '../constants';
8
8
  import { MultipleSelectFormatter, DateFormatter, CTimeFormatter, MTimeFormatter } from '../index';
9
9
  import CollaboratorItemFormatter from './collaborator-item-formatter';
10
- import { getFormulaArrayValue, isArrayFormalColumn } from './utils';
10
+ import { getFormulaArrayValue, isArrayFormatColumn } from './utils';
11
11
  import { getCellDisplayValue } from './value-display-utils';
12
12
  import './index.css';
13
13
 
@@ -45,7 +45,7 @@ var RowExpandLinkFormatter = /*#__PURE__*/function (_Component) {
45
45
 
46
46
  var displayColumnType = displayColumn.type,
47
47
  displayColumnData = displayColumn.data;
48
- var cellValue = getFormulaArrayValue(value, !isArrayFormalColumn(displayColumnType));
48
+ var cellValue = getFormulaArrayValue(value, !isArrayFormatColumn(displayColumnType));
49
49
 
50
50
  if (!Array.isArray(cellValue) || cellValue.length === 0) {
51
51
  return props.renderEmpty();
@@ -53,6 +53,6 @@ export var getTwoDimensionArrayValue = function getTwoDimensionArrayValue(value)
53
53
  });
54
54
  });
55
55
  };
56
- export function isArrayFormalColumn(columnType) {
56
+ export function isArrayFormatColumn(columnType) {
57
57
  return [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR].includes(columnType);
58
58
  }
@@ -17,6 +17,6 @@ var DATE_TYPES = {
17
17
  'YYYY-MM-DD HH:mm': 'YYYY-MM-DD HH:mm'
18
18
  };
19
19
  var SIMPLE_CELL_COLUMNS = [CellType.TEXT, CellType.NUMBER, CellType.DATE, CellType.CTIME, CellType.MTIME, CellType.AUTO_NUMBER, CellType.URL, CellType.EMAIL, CellType.DURATION, CellType.CHECKBOX, CellType.RATE];
20
- var ARRAY_FORMAL_COLUMNS = [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR];
20
+ var ARRAY_FORMAT_COLUMNS = [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR];
21
21
  var SIMPLE_CELL_FORMULA_RESULTS = [FORMULA_RESULT_TYPE.NUMBER, FORMULA_RESULT_TYPE.STRING, FORMULA_RESULT_TYPE.DATE, FORMULA_RESULT_TYPE.BOOL];
22
- export { CellType, NUMBER_TYPES, DATE_TYPES, FORMULA_RESULT_TYPE, SIMPLE_CELL_COLUMNS, ARRAY_FORMAL_COLUMNS, SIMPLE_CELL_FORMULA_RESULTS };
22
+ export { CellType, NUMBER_TYPES, DATE_TYPES, FORMULA_RESULT_TYPE, SIMPLE_CELL_COLUMNS, ARRAY_FORMAT_COLUMNS, SIMPLE_CELL_FORMULA_RESULTS };
package/lib/index.js CHANGED
@@ -40,6 +40,7 @@ export { default as RowExpandLinkFormatter } from './RowExpandLinkFormatter';
40
40
  export { default as RowExpandRateFormatter } from './RowExpandRateFormatter';
41
41
  export { default as RowExpandEmailFormatter } from './RowExpandEmailFormatter';
42
42
  export { default as RowExpandUrlFormatter } from './RowExpandUrlFormatter';
43
+ export { default as RowExpandFormulaFormatter } from './RowExpandFormulaFormatter';
43
44
  export { default as RowExpandFormatter } from './RowExpandFormatter'; // editor
44
45
 
45
46
  export { default as TextEditor } from './TextEditor';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "0.3.7",
3
+ "version": "0.3.8-alpha2",
4
4
  "main": "./lib/index.js",
5
5
  "dependencies": {
6
6
  "dtable-utils": "0.0.2",