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.
- package/lib/ButtonFormatter/index.js +2 -16
- package/lib/RowExpandFormatter/index.css +73 -0
- package/lib/RowExpandFormatter/index.js +426 -0
- package/lib/RowExpandImageFormatter/index.css +79 -0
- package/lib/RowExpandImageFormatter/index.js +127 -0
- package/lib/RowExpandImageFormatter/row-expand-image-item-formatter.js +128 -0
- package/lib/RowExpandImageFormatter/utils.js +7 -0
- package/lib/RowExpandLinkFormatter/collaborator-item-formatter.js +164 -0
- package/lib/RowExpandLinkFormatter/column-data-constants.js +20 -0
- package/lib/RowExpandLinkFormatter/date-utils.js +127 -0
- package/lib/RowExpandLinkFormatter/formula-constants.js +9 -0
- package/lib/RowExpandLinkFormatter/index.css +25 -0
- package/lib/RowExpandLinkFormatter/index.js +174 -0
- package/lib/RowExpandLinkFormatter/number-precision.js +116 -0
- package/lib/RowExpandLinkFormatter/utils.js +58 -0
- package/lib/RowExpandLinkFormatter/value-display-utils.js +401 -0
- package/lib/common/delete-tip.js +3 -2
- package/lib/common/modal-portal.js +44 -0
- package/lib/data/dtable-value.js +7 -0
- package/lib/index.js +4 -1
- package/lib/locals/en.js +1 -0
- package/lib/locals/zh-CN.js +1 -0
- package/package.json +1 -1
- package/lib/editor-formatter.js +0 -369
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
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, { Component } from 'react';
|
|
7
|
+
import { CellType } from 'dtable-store';
|
|
8
|
+
import { MultipleSelectFormatter, DateFormatter, CTimeFormatter, MTimeFormatter } from '../index';
|
|
9
|
+
import CollaboratorItemFormatter from './collaborator-item-formatter';
|
|
10
|
+
import { getFormulaArrayValue, isArrayFormalColumn } from './utils';
|
|
11
|
+
import { getCellDisplayValue } from './value-display-utils';
|
|
12
|
+
import './index.css';
|
|
13
|
+
|
|
14
|
+
var RowExpandLinkFormatter = /*#__PURE__*/function (_Component) {
|
|
15
|
+
_inherits(RowExpandLinkFormatter, _Component);
|
|
16
|
+
|
|
17
|
+
var _super = _createSuper(RowExpandLinkFormatter);
|
|
18
|
+
|
|
19
|
+
function RowExpandLinkFormatter() {
|
|
20
|
+
_classCallCheck(this, RowExpandLinkFormatter);
|
|
21
|
+
|
|
22
|
+
return _super.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_createClass(RowExpandLinkFormatter, [{
|
|
26
|
+
key: "render",
|
|
27
|
+
value: function render() {
|
|
28
|
+
var props = this.props;
|
|
29
|
+
var column = props.column,
|
|
30
|
+
value = props.value,
|
|
31
|
+
containerClassName = props.containerClassName,
|
|
32
|
+
collaborators = props.collaborators;
|
|
33
|
+
var data = column.data;
|
|
34
|
+
|
|
35
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
36
|
+
return props.renderEmpty();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var _ref = data || {},
|
|
40
|
+
displayColumn = _ref.display_column;
|
|
41
|
+
|
|
42
|
+
if (!displayColumn) {
|
|
43
|
+
return props.renderEmpty();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var displayColumnType = displayColumn.type,
|
|
47
|
+
displayColumnData = displayColumn.data;
|
|
48
|
+
var cellValue = getFormulaArrayValue(value, !isArrayFormalColumn(displayColumnType));
|
|
49
|
+
|
|
50
|
+
if (!Array.isArray(cellValue) || cellValue.length === 0) {
|
|
51
|
+
return props.renderEmpty();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
switch (displayColumnType) {
|
|
55
|
+
case CellType.TEXT:
|
|
56
|
+
case CellType.AUTO_NUMBER:
|
|
57
|
+
case CellType.EMAIL:
|
|
58
|
+
case CellType.URL:
|
|
59
|
+
case CellType.DURATION:
|
|
60
|
+
case CellType.NUMBER:
|
|
61
|
+
{
|
|
62
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
className: containerClassName
|
|
64
|
+
}, cellValue.map(function (value, index) {
|
|
65
|
+
if (!value) return null;
|
|
66
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
67
|
+
key: "link-".concat(displayColumnType, "-").concat(index),
|
|
68
|
+
className: "row-expand-link-item"
|
|
69
|
+
}, value);
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
case CellType.DATE:
|
|
74
|
+
{
|
|
75
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
76
|
+
className: containerClassName
|
|
77
|
+
}, cellValue.map(function (value, index) {
|
|
78
|
+
if (!value || typeof value !== 'string') return null;
|
|
79
|
+
|
|
80
|
+
var _ref2 = displayColumnData || {},
|
|
81
|
+
format = _ref2.format;
|
|
82
|
+
|
|
83
|
+
return /*#__PURE__*/React.createElement(DateFormatter, {
|
|
84
|
+
key: "link-".concat(displayColumnType, "-").concat(index),
|
|
85
|
+
value: value.replace('T', ' ').replace('Z', ''),
|
|
86
|
+
format: format,
|
|
87
|
+
containerClassName: "row-expand-link-item"
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
case CellType.CTIME:
|
|
93
|
+
{
|
|
94
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: containerClassName
|
|
96
|
+
}, cellValue.map(function (value, index) {
|
|
97
|
+
if (!value) return null;
|
|
98
|
+
return /*#__PURE__*/React.createElement(CTimeFormatter, {
|
|
99
|
+
key: "link-".concat(displayColumnType, "-").concat(index),
|
|
100
|
+
value: value,
|
|
101
|
+
containerClassName: "row-expand-link-item"
|
|
102
|
+
});
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
case CellType.MTIME:
|
|
107
|
+
{
|
|
108
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
className: containerClassName
|
|
110
|
+
}, cellValue.map(function (value, index) {
|
|
111
|
+
if (!value) return null;
|
|
112
|
+
return /*#__PURE__*/React.createElement(MTimeFormatter, {
|
|
113
|
+
key: "link-".concat(displayColumnType, "-").concat(index),
|
|
114
|
+
value: value,
|
|
115
|
+
containerClassName: "row-expand-link-item"
|
|
116
|
+
});
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
case CellType.CREATOR:
|
|
121
|
+
case CellType.LAST_MODIFIER:
|
|
122
|
+
{
|
|
123
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
124
|
+
className: "dtable-ui cell-formatter-container collaborator-formatter sql-query-collaborator-formatter"
|
|
125
|
+
}, cellValue.map(function (value, index) {
|
|
126
|
+
if (!value) return null;
|
|
127
|
+
return /*#__PURE__*/React.createElement(CollaboratorItemFormatter, {
|
|
128
|
+
key: "link-".concat(displayColumnType, "-").concat(index),
|
|
129
|
+
cellValue: value,
|
|
130
|
+
collaborators: collaborators,
|
|
131
|
+
context: props.context,
|
|
132
|
+
renderEmpty: props.renderEmpty
|
|
133
|
+
});
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
case CellType.SINGLE_SELECT:
|
|
138
|
+
{
|
|
139
|
+
if (!cellValue || cellValue.length === 0) {
|
|
140
|
+
return props.renderEmpty();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var options = displayColumnData && Array.isArray(displayColumnData.options) ? displayColumnData.options : [];
|
|
144
|
+
return /*#__PURE__*/React.createElement(MultipleSelectFormatter, {
|
|
145
|
+
value: cellValue,
|
|
146
|
+
options: options || []
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
case CellType.FORMULA:
|
|
151
|
+
{
|
|
152
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
153
|
+
className: containerClassName
|
|
154
|
+
}, cellValue.map(function (value, index) {
|
|
155
|
+
if (!value) return null;
|
|
156
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
157
|
+
key: "link-".concat(displayColumnType, "-").concat(index),
|
|
158
|
+
className: "row-expand-link-item"
|
|
159
|
+
}, getCellDisplayValue(_defineProperty({}, displayColumn.key, value), displayColumn, collaborators));
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
default:
|
|
164
|
+
{
|
|
165
|
+
return props.renderEmpty();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}]);
|
|
170
|
+
|
|
171
|
+
return RowExpandLinkFormatter;
|
|
172
|
+
}(Component);
|
|
173
|
+
|
|
174
|
+
export { RowExpandLinkFormatter as default };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
|
|
3
|
+
function strip(num) {
|
|
4
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
|
|
5
|
+
return +parseFloat(num.toPrecision(precision));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function digitLength(num) {
|
|
9
|
+
// Get digit length of e
|
|
10
|
+
var eSplit = num.toString().split(/[eE]/);
|
|
11
|
+
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
12
|
+
return len > 0 ? len : 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function float2Fixed(num) {
|
|
16
|
+
if (num.toString().indexOf('e') === -1) {
|
|
17
|
+
return Number(num.toString().replace('.', ''));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var dLen = digitLength(num);
|
|
21
|
+
return dLen > 0 ? strip(num * Math.pow(10, dLen)) : num;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function checkBoundary(num) {
|
|
25
|
+
if (_boundaryCheckingState) {
|
|
26
|
+
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
|
|
27
|
+
// eslint-disable-next-line no-console
|
|
28
|
+
console.warn("".concat(num, " is beyond boundary when transfer to integer, the results may not be accurate"));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function times(num1, num2) {
|
|
34
|
+
for (var _len = arguments.length, others = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
35
|
+
others[_key - 2] = arguments[_key];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (others.length > 0) {
|
|
39
|
+
return times.apply(void 0, [times(num1, num2), others[0]].concat(_toConsumableArray(others.slice(1))));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var num1Changed = float2Fixed(num1);
|
|
43
|
+
var num2Changed = float2Fixed(num2);
|
|
44
|
+
var baseNum = digitLength(num1) + digitLength(num2);
|
|
45
|
+
var leftValue = num1Changed * num2Changed;
|
|
46
|
+
checkBoundary(leftValue);
|
|
47
|
+
return leftValue / Math.pow(10, baseNum);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function plus(num1, num2) {
|
|
51
|
+
for (var _len2 = arguments.length, others = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
52
|
+
others[_key2 - 2] = arguments[_key2];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (others.length > 0) {
|
|
56
|
+
return plus.apply(void 0, [plus(num1, num2), others[0]].concat(_toConsumableArray(others.slice(1))));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
60
|
+
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function minus(num1, num2) {
|
|
64
|
+
for (var _len3 = arguments.length, others = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
65
|
+
others[_key3 - 2] = arguments[_key3];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (others.length > 0) {
|
|
69
|
+
return minus.apply(void 0, [minus(num1, num2), others[0]].concat(_toConsumableArray(others.slice(1))));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
73
|
+
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function divide(num1, num2) {
|
|
77
|
+
for (var _len4 = arguments.length, others = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
|
|
78
|
+
others[_key4 - 2] = arguments[_key4];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (others.length > 0) {
|
|
82
|
+
return divide.apply(void 0, [divide(num1, num2), others[0]].concat(_toConsumableArray(others.slice(1))));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var num1Changed = float2Fixed(num1);
|
|
86
|
+
var num2Changed = float2Fixed(num2);
|
|
87
|
+
checkBoundary(num1Changed);
|
|
88
|
+
checkBoundary(num2Changed); // fix: Similar to 10 ** -4 is 0.00009999999999999999, strip correction
|
|
89
|
+
|
|
90
|
+
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function round(num, ratio) {
|
|
94
|
+
var base = Math.pow(10, ratio);
|
|
95
|
+
return divide(Math.round(times(num, base)), base);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var _boundaryCheckingState = true;
|
|
99
|
+
|
|
100
|
+
function enableBoundaryChecking() {
|
|
101
|
+
var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
102
|
+
_boundaryCheckingState = flag;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { strip, plus, minus, times, divide, round, digitLength, float2Fixed, enableBoundaryChecking };
|
|
106
|
+
export default {
|
|
107
|
+
strip: strip,
|
|
108
|
+
plus: plus,
|
|
109
|
+
minus: minus,
|
|
110
|
+
times: times,
|
|
111
|
+
divide: divide,
|
|
112
|
+
round: round,
|
|
113
|
+
digitLength: digitLength,
|
|
114
|
+
float2Fixed: float2Fixed,
|
|
115
|
+
enableBoundaryChecking: enableBoundaryChecking
|
|
116
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { CellType } from 'dtable-store';
|
|
2
|
+
export var isValidCellValue = function isValidCellValue(value) {
|
|
3
|
+
if (value === undefined) return false;
|
|
4
|
+
if (value === null) return false;
|
|
5
|
+
if (value === '') return false;
|
|
6
|
+
if (JSON.stringify(value) === '{}') return false;
|
|
7
|
+
if (JSON.stringify(value) === '[]') return false;
|
|
8
|
+
return true;
|
|
9
|
+
};
|
|
10
|
+
export var getFormulaArrayValue = function getFormulaArrayValue(value) {
|
|
11
|
+
var isFlat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
12
|
+
if (!Array.isArray(value)) return [];
|
|
13
|
+
if (!isFlat) return getTwoDimensionArrayValue(value);
|
|
14
|
+
return value.map(function (item) {
|
|
15
|
+
if (Object.prototype.toString.call(item) !== '[object Object]') {
|
|
16
|
+
return item;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!Object.prototype.hasOwnProperty.call(item, 'display_value')) return item;
|
|
20
|
+
var display_value = item.display_value;
|
|
21
|
+
if (!Array.isArray(display_value) || display_value.length === 0) return display_value;
|
|
22
|
+
return display_value.map(function (i) {
|
|
23
|
+
if (Object.prototype.toString.call(i) === '[object Object]') {
|
|
24
|
+
if (!Object.prototype.hasOwnProperty.call(i, 'display_value')) return i;
|
|
25
|
+
var _display_value = i.display_value;
|
|
26
|
+
return _display_value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return i;
|
|
30
|
+
});
|
|
31
|
+
}).flat().filter(function (item) {
|
|
32
|
+
return isValidCellValue(item);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export var getTwoDimensionArrayValue = function getTwoDimensionArrayValue(value) {
|
|
36
|
+
if (!Array.isArray(value)) return [];
|
|
37
|
+
return value.map(function (item) {
|
|
38
|
+
if (Object.prototype.toString.call(item) !== '[object Object]') {
|
|
39
|
+
return item;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!Object.prototype.hasOwnProperty.call(item, 'display_value')) return item;
|
|
43
|
+
var display_value = item.display_value;
|
|
44
|
+
if (!Array.isArray(display_value) || display_value.length === 0) return display_value;
|
|
45
|
+
return display_value.map(function (i) {
|
|
46
|
+
if (Object.prototype.toString.call(i) === '[object Object]') {
|
|
47
|
+
if (!Object.prototype.hasOwnProperty.call(i, 'display_value')) return i;
|
|
48
|
+
var _display_value2 = i.display_value;
|
|
49
|
+
return _display_value2;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return i;
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
export function isArrayFormalColumn(columnType) {
|
|
57
|
+
return [CellType.IMAGE, CellType.FILE, CellType.MULTIPLE_SELECT, CellType.COLLABORATOR].includes(columnType);
|
|
58
|
+
}
|