dtable-utils 0.0.3 → 0.0.4-beta.1
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/README.md +42 -5
- package/dist/index.js +1 -1
- package/es/cell-value-get/cell-value.js +250 -20
- package/es/cell-value-get/collaborator.js +16 -3
- package/es/cell-value-get/digital-sign.js +1 -1
- package/es/cell-value-get/duration.js +3 -3
- package/es/cell-value-get/geolocation.js +52 -30
- package/es/cell-value-get/long-text.js +1 -1
- package/es/cell-value-get/number.js +51 -19
- package/es/cell-value-get/option.js +33 -9
- package/es/cell-value-get/rate.js +11 -0
- package/es/cell-value-set/date.js +26 -0
- package/es/cell-value-set/number.js +53 -1
- package/es/color/column-color.js +437 -0
- package/es/color/gradient-color.js +100 -0
- package/es/color/row-color.js +289 -0
- package/es/column/{common.js → core.js} +2 -14
- package/es/column/date.js +1 -1
- package/es/column/number.js +1 -1
- package/es/column/option.js +145 -0
- package/es/common.js +23 -3
- package/es/constants/color.js +16 -0
- package/es/constants/column-permission.js +7 -0
- package/es/constants/column.js +127 -2
- package/es/constants/filter/index.js +5 -1
- package/es/constants/formula.js +2 -1
- package/es/constants/grid-header.js +6 -0
- package/es/constants/group.js +23 -0
- package/es/constants/limit.js +3 -0
- package/es/constants/reg.js +4 -0
- package/es/constants/row-color.js +11 -0
- package/es/constants/sort.js +11 -0
- package/es/date.js +1 -1
- package/es/filter/core.js +322 -0
- package/es/filter/filter-column/array.js +87 -0
- package/es/filter/filter-column/checkbox.js +14 -0
- package/es/filter/filter-column/collaborator.js +72 -0
- package/es/filter/filter-column/creator.js +59 -0
- package/es/filter/filter-column/date.js +102 -0
- package/es/filter/filter-column/digital-sign.js +29 -0
- package/es/filter/filter-column/file.js +27 -0
- package/es/filter/filter-column/formula.js +57 -0
- package/es/filter/filter-column/geolocation.js +58 -0
- package/es/filter/filter-column/link.js +20 -0
- package/es/filter/filter-column/long-text.js +28 -0
- package/es/filter/filter-column/multiple-select.js +64 -0
- package/es/filter/filter-column/number.js +97 -0
- package/es/filter/filter-column/single-select.js +45 -0
- package/es/filter/filter-column/text.js +60 -0
- package/es/filter/filter-row.js +233 -0
- package/es/group/core.js +116 -0
- package/es/group/group-row.js +402 -0
- package/es/index.js +63 -11
- package/es/link/core.js +78 -0
- package/es/number.js +21 -0
- package/es/row/core.js +180 -0
- package/es/sort/core.js +91 -0
- package/es/sort/sort-column/array.js +72 -0
- package/es/sort/sort-column/checkbox.js +22 -0
- package/es/sort/sort-column/collaborator.js +16 -0
- package/es/sort/sort-column/date.js +25 -0
- package/es/sort/sort-column/formula.js +49 -0
- package/es/sort/sort-column/link.js +32 -0
- package/es/sort/sort-column/multiple-select.js +45 -0
- package/es/sort/sort-column/number.js +25 -0
- package/es/sort/sort-column/single-select.js +30 -0
- package/es/sort/sort-column/text.js +61 -0
- package/es/sort/sort-row.js +110 -0
- package/es/table/column.js +27 -0
- package/es/table/core.js +14 -0
- package/es/table/row.js +25 -0
- package/es/validate/filter.js +1 -1
- package/es/validate/geolocation.js +5 -0
- package/es/view/core.js +134 -0
- package/es/view/formula.js +147 -0
- package/es/view/group.js +32 -0
- package/es/view/summaries.js +167 -0
- package/lib/cell-value-get/cell-value.js +254 -19
- package/lib/cell-value-get/collaborator.js +16 -2
- package/lib/cell-value-get/digital-sign.js +1 -1
- package/lib/cell-value-get/duration.js +3 -2
- package/lib/cell-value-get/geolocation.js +53 -30
- package/lib/cell-value-get/long-text.js +1 -1
- package/lib/cell-value-get/number.js +51 -18
- package/lib/cell-value-get/option.js +34 -8
- package/lib/cell-value-get/rate.js +15 -0
- package/lib/cell-value-set/date.js +30 -0
- package/lib/cell-value-set/number.js +53 -0
- package/lib/color/column-color.js +446 -0
- package/lib/color/gradient-color.js +110 -0
- package/lib/color/row-color.js +297 -0
- package/lib/column/{common.js → core.js} +1 -14
- package/lib/column/date.js +2 -2
- package/lib/column/number.js +3 -3
- package/lib/column/option.js +153 -0
- package/lib/common.js +27 -3
- package/lib/constants/color.js +20 -0
- package/lib/constants/column-permission.js +11 -0
- package/lib/constants/column.js +134 -1
- package/lib/constants/filter/index.js +5 -0
- package/lib/constants/formula.js +2 -0
- package/lib/constants/grid-header.js +10 -0
- package/lib/constants/group.js +36 -0
- package/lib/constants/limit.js +7 -0
- package/lib/constants/reg.js +9 -0
- package/lib/constants/row-color.js +17 -0
- package/lib/constants/sort.js +18 -0
- package/lib/filter/core.js +336 -0
- package/lib/filter/filter-column/array.js +91 -0
- package/lib/filter/filter-column/checkbox.js +18 -0
- package/lib/filter/filter-column/collaborator.js +80 -0
- package/lib/filter/filter-column/creator.js +63 -0
- package/lib/filter/filter-column/date.js +106 -0
- package/lib/filter/filter-column/digital-sign.js +33 -0
- package/lib/filter/filter-column/file.js +31 -0
- package/lib/filter/filter-column/formula.js +61 -0
- package/lib/filter/filter-column/geolocation.js +62 -0
- package/lib/filter/filter-column/link.js +24 -0
- package/lib/filter/filter-column/long-text.js +32 -0
- package/lib/filter/filter-column/multiple-select.js +72 -0
- package/lib/filter/filter-column/number.js +101 -0
- package/lib/filter/filter-column/single-select.js +49 -0
- package/lib/filter/filter-column/text.js +64 -0
- package/lib/filter/filter-row.js +239 -0
- package/lib/group/core.js +126 -0
- package/lib/group/group-row.js +413 -0
- package/lib/index.js +177 -7
- package/lib/link/core.js +90 -0
- package/lib/number.js +26 -0
- package/lib/row/core.js +189 -0
- package/lib/sort/core.js +102 -0
- package/lib/sort/sort-column/array.js +76 -0
- package/lib/sort/sort-column/checkbox.js +26 -0
- package/lib/sort/sort-column/collaborator.js +20 -0
- package/lib/sort/sort-column/date.js +29 -0
- package/lib/sort/sort-column/formula.js +53 -0
- package/lib/sort/sort-column/link.js +36 -0
- package/lib/sort/sort-column/multiple-select.js +49 -0
- package/lib/sort/sort-column/number.js +29 -0
- package/lib/sort/sort-column/single-select.js +34 -0
- package/lib/sort/sort-column/text.js +66 -0
- package/lib/sort/sort-row.js +115 -0
- package/lib/table/column.js +32 -0
- package/lib/table/core.js +18 -0
- package/lib/table/row.js +30 -0
- package/lib/validate/filter.js +3 -3
- package/lib/validate/geolocation.js +9 -0
- package/lib/view/core.js +143 -0
- package/lib/view/formula.js +154 -0
- package/lib/view/group.js +36 -0
- package/lib/view/summaries.js +173 -0
- package/package.json +5 -3
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
7
|
+
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
8
|
+
var color = require('../constants/color.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
13
|
+
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
14
|
+
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
15
|
+
|
|
16
|
+
var GradientColorUtils = /*#__PURE__*/function () {
|
|
17
|
+
function GradientColorUtils(_ref) {
|
|
18
|
+
var colorType = _ref.colorType,
|
|
19
|
+
max = _ref.max,
|
|
20
|
+
min = _ref.min;
|
|
21
|
+
_classCallCheck__default["default"](this, GradientColorUtils);
|
|
22
|
+
var newColorType = colorType || 'color_gradation_1';
|
|
23
|
+
var colors = color.COLOR_GRADATION_OPTIONS[newColorType];
|
|
24
|
+
this.startColor = this.hexToRgb(colors[0]);
|
|
25
|
+
this.endColor = this.hexToRgb(colors[4]);
|
|
26
|
+
this.min = min;
|
|
27
|
+
this.max = max;
|
|
28
|
+
this.computeMap = {};
|
|
29
|
+
}
|
|
30
|
+
_createClass__default["default"](GradientColorUtils, [{
|
|
31
|
+
key: "hexToRgb",
|
|
32
|
+
value: function hexToRgb(hexCode) {
|
|
33
|
+
var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
|
34
|
+
var nextHexCode = hexCode.toLowerCase();
|
|
35
|
+
if (nextHexCode && reg.test(nextHexCode)) {
|
|
36
|
+
if (nextHexCode.length === 4) {
|
|
37
|
+
var newHexCode = '#';
|
|
38
|
+
for (var i = 1; i < 4; i += 1) {
|
|
39
|
+
newHexCode += nextHexCode.slice(i, i + 1).concat(nextHexCode.slice(i, i + 1));
|
|
40
|
+
}
|
|
41
|
+
nextHexCode = newHexCode;
|
|
42
|
+
}
|
|
43
|
+
var hexCodeChange = [];
|
|
44
|
+
for (var _i = 1; _i < 7; _i += 2) {
|
|
45
|
+
hexCodeChange.push(parseInt("0x".concat(nextHexCode.slice(_i, _i + 2))));
|
|
46
|
+
}
|
|
47
|
+
return "RGB(".concat(hexCodeChange.join(','), ")");
|
|
48
|
+
}
|
|
49
|
+
return nextHexCode;
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
key: "getColorGradation",
|
|
53
|
+
value: function getColorGradation(color1, color2, value1, value2, value) {
|
|
54
|
+
var rgb1 = color1.split(',');
|
|
55
|
+
var r1 = parseInt(rgb1[0].split('(')[1]);
|
|
56
|
+
var g1 = parseInt(rgb1[1]);
|
|
57
|
+
var b1 = parseInt(rgb1[2].split(')')[0]);
|
|
58
|
+
var rgb2 = color2.split(',');
|
|
59
|
+
var r2 = parseInt(rgb2[0].split('(')[1]);
|
|
60
|
+
var g2 = parseInt(rgb2[1]);
|
|
61
|
+
var b2 = parseInt(rgb2[2].split(')')[0]);
|
|
62
|
+
var r = Math.round(r1 - (r1 - r2) / (value1 - value2) * (value1 - value));
|
|
63
|
+
var g = Math.round(g1 - (g1 - g2) / (value1 - value2) * (value1 - value));
|
|
64
|
+
var b = Math.round(b1 - (b1 - b2) / (value1 - value2) * (value1 - value));
|
|
65
|
+
return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")");
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "getCellColor",
|
|
69
|
+
value: function getCellColor(value) {
|
|
70
|
+
if (this.computeMap[value]) {
|
|
71
|
+
return this.computeMap[value];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// eslint-disable-next-line
|
|
75
|
+
if (value == this.min) {
|
|
76
|
+
if (this.computeMap[value]) {
|
|
77
|
+
this.computeMap[value] = this.startColor;
|
|
78
|
+
} else {
|
|
79
|
+
this.computeMap = _defineProperty__default["default"]({}, value, this.startColor);
|
|
80
|
+
}
|
|
81
|
+
return this.computeMap[value];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// eslint-disable-next-line
|
|
85
|
+
if (value == this.max) {
|
|
86
|
+
if (this.computeMap[value]) {
|
|
87
|
+
this.computeMap[value] = this.endColor;
|
|
88
|
+
} else {
|
|
89
|
+
this.computeMap = _defineProperty__default["default"]({}, value, this.endColor);
|
|
90
|
+
}
|
|
91
|
+
return this.computeMap[value];
|
|
92
|
+
}
|
|
93
|
+
if (value > this.min && value < this.max) {
|
|
94
|
+
var color1 = this.startColor,
|
|
95
|
+
color2 = this.endColor,
|
|
96
|
+
value1 = this.min,
|
|
97
|
+
value2 = this.max;
|
|
98
|
+
var color = this.getColorGradation(color1, color2, value1, value2, value);
|
|
99
|
+
this.computeMap[value] = color;
|
|
100
|
+
return this.computeMap[value];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// value < min || value > max
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}]);
|
|
107
|
+
return GradientColorUtils;
|
|
108
|
+
}();
|
|
109
|
+
|
|
110
|
+
exports["default"] = GradientColorUtils;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var column = require('../table/column.js');
|
|
7
|
+
var row = require('../table/row.js');
|
|
8
|
+
var core$1 = require('../row/core.js');
|
|
9
|
+
var option = require('../column/option.js');
|
|
10
|
+
var geolocation = require('../cell-value-get/geolocation.js');
|
|
11
|
+
var filter = require('../validate/filter.js');
|
|
12
|
+
var core = require('../filter/core.js');
|
|
13
|
+
var filterRow = require('../filter/filter-row.js');
|
|
14
|
+
var rowColor = require('../constants/row-color.js');
|
|
15
|
+
var cellType = require('../constants/cell-type.js');
|
|
16
|
+
|
|
17
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
|
+
|
|
19
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
20
|
+
|
|
21
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
+
var isValidRowColorRule = function isValidRowColorRule(rule, columns) {
|
|
24
|
+
var filters = rule.filters;
|
|
25
|
+
if (!filters || filters.length === 0) return false;
|
|
26
|
+
return filters.some(function (filter$1) {
|
|
27
|
+
return !filter.ValidateFilter.validate(filter$1, columns).error_message;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var getValidRowColorRules = function getValidRowColorRules(colorRules, columns) {
|
|
31
|
+
return colorRules.filter(function (colorRule) {
|
|
32
|
+
return isValidRowColorRule(colorRule, columns);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var getOptionIdMap = function getOptionIdMap(options) {
|
|
36
|
+
if (!Array.isArray(options) || options.length === 0) return {};
|
|
37
|
+
var optionsMap = {};
|
|
38
|
+
options.forEach(function (option) {
|
|
39
|
+
optionsMap[option.id] = true;
|
|
40
|
+
});
|
|
41
|
+
return optionsMap;
|
|
42
|
+
};
|
|
43
|
+
var getFormattedDuplicateColumns = function getFormattedDuplicateColumns(columns, duplicateColumnKeys, _ref) {
|
|
44
|
+
var collaborators = _ref.collaborators;
|
|
45
|
+
var formattedColumns = [];
|
|
46
|
+
var _loop = function _loop() {
|
|
47
|
+
var key = duplicateColumnKeys[i];
|
|
48
|
+
var currColumn = columns.find(function (column) {
|
|
49
|
+
return column.key === key;
|
|
50
|
+
});
|
|
51
|
+
if (!currColumn) return "continue";
|
|
52
|
+
var type = currColumn.type,
|
|
53
|
+
data = currColumn.data;
|
|
54
|
+
var formattedColumnData = data;
|
|
55
|
+
if (!rowColor.SUPPORT_CHECKING_DUPLICATE_COLUMNS_TYPES.includes(type)) return "continue";
|
|
56
|
+
if (type === cellType.CellType.SINGLE_SELECT || type === cellType.CellType.MULTIPLE_SELECT) {
|
|
57
|
+
var options = option.getColumnOptions(currColumn);
|
|
58
|
+
formattedColumnData = getOptionIdMap(options);
|
|
59
|
+
} else if (type === cellType.CellType.COLLABORATOR) {
|
|
60
|
+
var optionsMap = {};
|
|
61
|
+
if (Array.isArray(collaborators)) {
|
|
62
|
+
collaborators.forEach(function (collaborator) {
|
|
63
|
+
optionsMap[collaborator.email] = true;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
formattedColumnData = optionsMap;
|
|
67
|
+
}
|
|
68
|
+
formattedColumns.push({
|
|
69
|
+
key: key,
|
|
70
|
+
type: type,
|
|
71
|
+
data: formattedColumnData
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
for (var i = 0; i < duplicateColumnKeys.length; i++) {
|
|
75
|
+
var _ret = _loop();
|
|
76
|
+
if (_ret === "continue") continue;
|
|
77
|
+
}
|
|
78
|
+
return formattedColumns;
|
|
79
|
+
};
|
|
80
|
+
var getDuplicateRowValue = function getDuplicateRowValue(row, columns, formulaRow) {
|
|
81
|
+
if (!row) return '';
|
|
82
|
+
var rowValue = columns.map(function (column) {
|
|
83
|
+
var type = column.type,
|
|
84
|
+
data = column.data,
|
|
85
|
+
key = column.key;
|
|
86
|
+
var cellValue = row[key];
|
|
87
|
+
switch (type) {
|
|
88
|
+
case cellType.CellType.SINGLE_SELECT:
|
|
89
|
+
{
|
|
90
|
+
return data[cellValue] ? cellValue : '';
|
|
91
|
+
}
|
|
92
|
+
case cellType.CellType.MULTIPLE_SELECT:
|
|
93
|
+
case cellType.CellType.COLLABORATOR:
|
|
94
|
+
{
|
|
95
|
+
if (!Array.isArray(cellValue) || cellValue.length === 0) return '';
|
|
96
|
+
return cellValue.filter(function (item) {
|
|
97
|
+
return data[item];
|
|
98
|
+
}).sort().join('');
|
|
99
|
+
}
|
|
100
|
+
case cellType.CellType.GEOLOCATION:
|
|
101
|
+
{
|
|
102
|
+
if (!cellValue) return '';
|
|
103
|
+
return geolocation.getGeolocationDisplayString(cellValue, data) || '';
|
|
104
|
+
}
|
|
105
|
+
case cellType.CellType.NUMBER:
|
|
106
|
+
{
|
|
107
|
+
if (!cellValue && cellValue !== 0) return '';
|
|
108
|
+
return cellValue;
|
|
109
|
+
}
|
|
110
|
+
case cellType.CellType.FORMULA:
|
|
111
|
+
{
|
|
112
|
+
if (!formulaRow) return '';
|
|
113
|
+
cellValue = formulaRow[key];
|
|
114
|
+
return cellValue;
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
{
|
|
118
|
+
return cellValue || '';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}).join('_seatable_join_key_');
|
|
122
|
+
if (!rowValue) return '';
|
|
123
|
+
if (typeof ''.replaceAll !== 'function') {
|
|
124
|
+
// eslint-disable-next-line
|
|
125
|
+
String.prototype.replaceAll = function (s1, s2) {
|
|
126
|
+
return this.replace(new RegExp(s1, 'gm'), s2);
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (!rowValue.replaceAll('_seatable_join_key_', '')) return '';
|
|
130
|
+
return rowValue;
|
|
131
|
+
};
|
|
132
|
+
var getRowsColorBySingleSelectColumn = function getRowsColorBySingleSelectColumn(rows, columnKey, table) {
|
|
133
|
+
var colors = {};
|
|
134
|
+
var column$1 = column.getTableColumnByKey(table, columnKey);
|
|
135
|
+
var options = option.getColumnOptions(column$1);
|
|
136
|
+
if (!Array.isArray(options) || options.length === 0) return {};
|
|
137
|
+
var option_id_color_map = {};
|
|
138
|
+
options.forEach(function (option) {
|
|
139
|
+
option_id_color_map[option.id] = option.color;
|
|
140
|
+
});
|
|
141
|
+
rows.forEach(function (row) {
|
|
142
|
+
var optionId = row[columnKey];
|
|
143
|
+
var color = optionId ? option_id_color_map[optionId] : '';
|
|
144
|
+
if (color) {
|
|
145
|
+
colors[row._id] = color;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return colors;
|
|
149
|
+
};
|
|
150
|
+
var getRowsColorByRules = function getRowsColorByRules(rows, view, table) {
|
|
151
|
+
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
152
|
+
username = _ref2.username,
|
|
153
|
+
userId = _ref2.userId;
|
|
154
|
+
var formula_rows = view.formula_rows,
|
|
155
|
+
colorbys = view.colorbys;
|
|
156
|
+
var _ref3 = colorbys || {},
|
|
157
|
+
type = _ref3.type,
|
|
158
|
+
color_by_rules = _ref3.color_by_rules;
|
|
159
|
+
if (type !== rowColor.ROW_COLOR_TYPE.BY_RULES) return {};
|
|
160
|
+
var columns = table.columns;
|
|
161
|
+
var validColorRules = getValidRowColorRules(color_by_rules, columns);
|
|
162
|
+
var colorRulesLen = validColorRules.length;
|
|
163
|
+
var colors = {};
|
|
164
|
+
if (colorRulesLen === 0) return {};
|
|
165
|
+
validColorRules = validColorRules.map(function (colorRule) {
|
|
166
|
+
var filters = colorRule.filters;
|
|
167
|
+
var validFilters;
|
|
168
|
+
try {
|
|
169
|
+
validFilters = core.deleteInvalidFilter(filters, columns);
|
|
170
|
+
} catch (err) {
|
|
171
|
+
validFilters = [];
|
|
172
|
+
}
|
|
173
|
+
validFilters = core.getFormattedFilters(validFilters);
|
|
174
|
+
return _objectSpread(_objectSpread({}, colorRule), {}, {
|
|
175
|
+
filters: validFilters
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
rows.forEach(function (row) {
|
|
179
|
+
var rowId = row._id;
|
|
180
|
+
var formulaRow = formula_rows && formula_rows[rowId] || {};
|
|
181
|
+
for (var i = 0; i < colorRulesLen; i++) {
|
|
182
|
+
var colorRule = validColorRules[i];
|
|
183
|
+
var color = colorRule.color,
|
|
184
|
+
filter_conjunction = colorRule.filter_conjunction,
|
|
185
|
+
filters = colorRule.filters;
|
|
186
|
+
if (filterRow.filterRow(row, filter_conjunction, filters, {
|
|
187
|
+
formulaRow: formulaRow,
|
|
188
|
+
username: username,
|
|
189
|
+
userId: userId
|
|
190
|
+
})) {
|
|
191
|
+
colors[rowId] = color;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return colors;
|
|
197
|
+
};
|
|
198
|
+
var getRowsColorByDuplicateValues = function getRowsColorByDuplicateValues(rows, view, table, _ref4) {
|
|
199
|
+
var collaborators = _ref4.collaborators;
|
|
200
|
+
var colorbys = view.colorbys,
|
|
201
|
+
formula_rows = view.formula_rows;
|
|
202
|
+
var color_by_duplicate_column_keys = colorbys.color_by_duplicate_column_keys;
|
|
203
|
+
if (!Array.isArray(color_by_duplicate_column_keys) || color_by_duplicate_column_keys.length === 0) return {};
|
|
204
|
+
var columns = table.columns;
|
|
205
|
+
var formattedColumns = getFormattedDuplicateColumns(columns, color_by_duplicate_column_keys, {
|
|
206
|
+
collaborators: collaborators
|
|
207
|
+
});
|
|
208
|
+
if (formattedColumns.length === 0) return {};
|
|
209
|
+
var colors = {};
|
|
210
|
+
var duplicate_rows_ids_map = {}; // row value: [ row_id ]
|
|
211
|
+
for (var i = 0; i < rows.length; i++) {
|
|
212
|
+
var row = rows[i];
|
|
213
|
+
var rowId = row._id;
|
|
214
|
+
var formulaRow = formula_rows && formula_rows[rowId];
|
|
215
|
+
var rowValue = getDuplicateRowValue(row, formattedColumns, formulaRow);
|
|
216
|
+
if (!rowValue) continue;
|
|
217
|
+
var validRowIds = duplicate_rows_ids_map[rowValue];
|
|
218
|
+
if (validRowIds && validRowIds.length > 0) {
|
|
219
|
+
colors[rowId] = rowColor.ROW_COLOR_FOR_DUPLICATE_VALUES;
|
|
220
|
+
validRowIds.push(rowId);
|
|
221
|
+
var firstDuplicateRowId = validRowIds[0];
|
|
222
|
+
if (!colors[firstDuplicateRowId]) {
|
|
223
|
+
colors[firstDuplicateRowId] = rowColor.ROW_COLOR_FOR_DUPLICATE_VALUES;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
duplicate_rows_ids_map[rowValue] = [rowId];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
colors: colors,
|
|
231
|
+
duplicate_rows_ids_map: duplicate_rows_ids_map
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Calculate rows color.
|
|
237
|
+
* @param {array} rows
|
|
238
|
+
* @param {object} view
|
|
239
|
+
* @param {object} table e.g. { id_row_map, ... }
|
|
240
|
+
* @param {object} value e.g. { tables, collaborators, ... }
|
|
241
|
+
* @param {string} username
|
|
242
|
+
* @param {userId} username
|
|
243
|
+
* @returns rows color, object
|
|
244
|
+
*/
|
|
245
|
+
var getRowsColor = function getRowsColor(rows, view, table, value) {
|
|
246
|
+
var _ref5 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
247
|
+
username = _ref5.username,
|
|
248
|
+
userId = _ref5.userId;
|
|
249
|
+
var colorbys = view.colorbys;
|
|
250
|
+
if (!colorbys) return {};
|
|
251
|
+
var tableRows = core$1.isTableRows(rows) ? rows : row.getRowsByIds(table, rows);
|
|
252
|
+
if (tableRows.length === 0) return {};
|
|
253
|
+
var type = colorbys.type,
|
|
254
|
+
color_by_column = colorbys.color_by_column;
|
|
255
|
+
switch (type) {
|
|
256
|
+
case rowColor.ROW_COLOR_TYPE.BY_COLUMN:
|
|
257
|
+
{
|
|
258
|
+
return {
|
|
259
|
+
colors: getRowsColorBySingleSelectColumn(tableRows, color_by_column, table)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
case rowColor.ROW_COLOR_TYPE.BY_RULES:
|
|
263
|
+
{
|
|
264
|
+
return {
|
|
265
|
+
colors: getRowsColorByRules(tableRows, view, table, {
|
|
266
|
+
username: username,
|
|
267
|
+
userId: userId
|
|
268
|
+
})
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
case rowColor.ROW_COLOR_TYPE.BY_DUPLICATE_VALUES:
|
|
272
|
+
{
|
|
273
|
+
var _ref6 = value || {},
|
|
274
|
+
_ref6$collaborators = _ref6.collaborators,
|
|
275
|
+
collaborators = _ref6$collaborators === void 0 ? [] : _ref6$collaborators;
|
|
276
|
+
return getRowsColorByDuplicateValues(tableRows, view, table, {
|
|
277
|
+
collaborators: collaborators
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
default:
|
|
281
|
+
{
|
|
282
|
+
return {};
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
var RowColorUtils = {
|
|
287
|
+
isValidRowColorRule: isValidRowColorRule,
|
|
288
|
+
getValidRowColorRules: getValidRowColorRules,
|
|
289
|
+
getRowsColor: getRowsColor,
|
|
290
|
+
getFormattedDuplicateColumns: getFormattedDuplicateColumns,
|
|
291
|
+
getDuplicateRowValue: getDuplicateRowValue,
|
|
292
|
+
getRowsColorBySingleSelectColumn: getRowsColorBySingleSelectColumn,
|
|
293
|
+
getRowsColorByRules: getRowsColorByRules,
|
|
294
|
+
getRowsColorByDuplicateValues: getRowsColorByDuplicateValues
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
exports["default"] = RowColorUtils;
|
|
@@ -7,7 +7,7 @@ var formula = require('../constants/formula.js');
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Get column type.
|
|
10
|
-
* @param {object} column { type
|
|
10
|
+
* @param {object} column { type, ... }
|
|
11
11
|
* @returns column type
|
|
12
12
|
*/
|
|
13
13
|
var getColumnType = function getColumnType(column) {
|
|
@@ -30,17 +30,4 @@ var getColumnType = function getColumnType(column) {
|
|
|
30
30
|
return type;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
* Get options from single-select/multiple-select column.
|
|
35
|
-
* @param {object} column e.g. { type, data: { options: [] } }
|
|
36
|
-
* @returns options, array
|
|
37
|
-
*/
|
|
38
|
-
var getColumnOptions = function getColumnOptions(column) {
|
|
39
|
-
if (!column || !column.data || !Array.isArray(column.data.options)) {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
return column.data.options;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
exports.getColumnOptions = getColumnOptions;
|
|
46
33
|
exports.getColumnType = getColumnType;
|
package/lib/column/date.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var core = require('./core.js');
|
|
6
6
|
var column = require('../constants/column.js');
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -14,7 +14,7 @@ var column = require('../constants/column.js');
|
|
|
14
14
|
* @returns true/false, bool
|
|
15
15
|
*/
|
|
16
16
|
var isDateColumn = function isDateColumn(column$1) {
|
|
17
|
-
return column.DATE_COLUMN_OPTIONS.includes(
|
|
17
|
+
return column.DATE_COLUMN_OPTIONS.includes(core.getColumnType(column$1));
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
exports.isDateColumn = isDateColumn;
|
package/lib/column/number.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var core = require('./core.js');
|
|
6
6
|
var cellType = require('../constants/cell-type.js');
|
|
7
7
|
var column = require('../constants/column.js');
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ var column = require('../constants/column.js');
|
|
|
15
15
|
* @returns true/false, bool
|
|
16
16
|
*/
|
|
17
17
|
var isNumericColumn = function isNumericColumn(column$1) {
|
|
18
|
-
return column.NUMERIC_COLUMNS_TYPES.includes(
|
|
18
|
+
return column.NUMERIC_COLUMNS_TYPES.includes(core.getColumnType(column$1));
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -27,7 +27,7 @@ var isNumericColumn = function isNumericColumn(column$1) {
|
|
|
27
27
|
* @returns true/false, bool
|
|
28
28
|
*/
|
|
29
29
|
var isNumberColumn = function isNumberColumn(column) {
|
|
30
|
-
return
|
|
30
|
+
return core.getColumnType(column) === cellType.CellType.NUMBER;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
exports.isNumberColumn = isNumberColumn;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var selectOption = require('../constants/select-option.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get options from single-select/multiple-select column.
|
|
9
|
+
* @param {object} column e.g. { type, data: { options: [] } }
|
|
10
|
+
* @returns options, array
|
|
11
|
+
*/
|
|
12
|
+
var getColumnOptions = function getColumnOptions(column) {
|
|
13
|
+
if (!column || !column.data || !Array.isArray(column.data.options)) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return column.data.options;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* generate unique option id
|
|
21
|
+
* @param {array} options e.g. [{ id, ... }, ...]
|
|
22
|
+
* @returns generated option id, string
|
|
23
|
+
*/
|
|
24
|
+
var generateOptionID = function generateOptionID(options) {
|
|
25
|
+
if (options.length === 1) return String(Math.floor(Math.random() * Math.pow(10, 6)));
|
|
26
|
+
var optionID;
|
|
27
|
+
var isIDUnique = false;
|
|
28
|
+
while (!isIDUnique) {
|
|
29
|
+
optionID = String(Math.floor(Math.random() * Math.pow(10, 6)));
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line
|
|
32
|
+
isIDUnique = options.every(function (option) {
|
|
33
|
+
return option.id !== optionID;
|
|
34
|
+
});
|
|
35
|
+
if (isIDUnique) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return optionID;
|
|
40
|
+
};
|
|
41
|
+
var getRandomOptionColor = function getRandomOptionColor(options) {
|
|
42
|
+
var defaultOptions = selectOption.SELECT_OPTION_COLORS.slice(12, 24);
|
|
43
|
+
var colorIdx = Math.floor(Math.random() * defaultOptions.length);
|
|
44
|
+
if (!Array.isArray(options) || options.length === 0) {
|
|
45
|
+
return defaultOptions[colorIdx];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Avoid using the same color for adjacent labels
|
|
49
|
+
var adjacentOptions = options.slice(-(defaultOptions.length - 1));
|
|
50
|
+
var adjacentOptionsColorIdxArr = [];
|
|
51
|
+
var selectOptionColorObj = {};
|
|
52
|
+
defaultOptions.forEach(function (colorItem, index) {
|
|
53
|
+
selectOptionColorObj[colorItem.COLOR] = index;
|
|
54
|
+
});
|
|
55
|
+
adjacentOptions.forEach(function (option) {
|
|
56
|
+
var optionColorIdx = selectOptionColorObj[option.color];
|
|
57
|
+
adjacentOptionsColorIdxArr.push(optionColorIdx);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// eslint-disable-next-line
|
|
61
|
+
while (adjacentOptionsColorIdxArr.indexOf(colorIdx) != -1) {
|
|
62
|
+
colorIdx = Math.floor(Math.random() * defaultOptions.length);
|
|
63
|
+
}
|
|
64
|
+
return defaultOptions[colorIdx] || defaultOptions[0];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* generate option
|
|
69
|
+
* @param {array} options e.g. [{ id, ... }, ...]
|
|
70
|
+
* @param {string} optionName
|
|
71
|
+
* @param {string} optionColor used to find system support color options. The new color option will be generated if not found by "optionColor" or not supported
|
|
72
|
+
* @returns generated option, object
|
|
73
|
+
*/
|
|
74
|
+
var createOption = function createOption(options, optionName) {
|
|
75
|
+
var optionColor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
76
|
+
var id = generateOptionID(options);
|
|
77
|
+
var colors = optionColor && selectOption.SELECT_OPTION_COLORS.find(function (systemColor) {
|
|
78
|
+
return systemColor.COLOR === optionColor;
|
|
79
|
+
});
|
|
80
|
+
if (!colors) {
|
|
81
|
+
colors = getRandomOptionColor(options);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
id: id,
|
|
85
|
+
name: optionName,
|
|
86
|
+
color: colors.COLOR,
|
|
87
|
+
textColor: colors.TEXT_COLOR
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Generate cell option by name.
|
|
93
|
+
* Return the option id if exist, otherwise generate a new option
|
|
94
|
+
* @param {array} options e.g. [{ id, ... }, ...]
|
|
95
|
+
* @param {string} optionName used as the option name
|
|
96
|
+
* @returns option id and option, object
|
|
97
|
+
*/
|
|
98
|
+
var generatorCellOption = function generatorCellOption(options, optionName) {
|
|
99
|
+
var existOption = options.find(function (option) {
|
|
100
|
+
return option.name === optionName;
|
|
101
|
+
});
|
|
102
|
+
if (existOption) {
|
|
103
|
+
return {
|
|
104
|
+
selectedOptionId: existOption.id
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
var newOption = createOption(options, optionName) || {};
|
|
108
|
+
return {
|
|
109
|
+
cellOption: newOption,
|
|
110
|
+
selectedOptionId: newOption.id
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Generate cell options by names.
|
|
116
|
+
* Return the options ids if exist, otherwise generate new options
|
|
117
|
+
* @param {array} options e.g. [{ id, ... }, ...]
|
|
118
|
+
* @param {array} optionNames used as the options names
|
|
119
|
+
* @returns options ids and options, object
|
|
120
|
+
*/
|
|
121
|
+
var generatorCellOptions = function generatorCellOptions(options, optionNames) {
|
|
122
|
+
var cellOptions = [];
|
|
123
|
+
var selectedOptionIds = [];
|
|
124
|
+
optionNames.forEach(function (optionName) {
|
|
125
|
+
var existingOption = options.find(function (option) {
|
|
126
|
+
return option.name === optionName;
|
|
127
|
+
});
|
|
128
|
+
if (existingOption) {
|
|
129
|
+
selectedOptionIds.push(existingOption.id);
|
|
130
|
+
} else {
|
|
131
|
+
var cellOption = createOption(options, optionName);
|
|
132
|
+
if (cellOption) {
|
|
133
|
+
cellOptions.push(cellOption);
|
|
134
|
+
selectedOptionIds.push(cellOption.id);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (cellOptions.length === 0) {
|
|
139
|
+
return {
|
|
140
|
+
selectedOptionIds: selectedOptionIds
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
cellOptions: cellOptions,
|
|
145
|
+
selectedOptionIds: selectedOptionIds
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
exports.createOption = createOption;
|
|
150
|
+
exports.generateOptionID = generateOptionID;
|
|
151
|
+
exports.generatorCellOption = generatorCellOption;
|
|
152
|
+
exports.generatorCellOptions = generatorCellOptions;
|
|
153
|
+
exports.getColumnOptions = getColumnOptions;
|
package/lib/common.js
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
10
|
+
|
|
5
11
|
/**
|
|
6
12
|
* Generate a random string of specified length.
|
|
7
13
|
* @param {number} keyLength
|
|
@@ -16,11 +22,29 @@ var generatorBase64Code = function generatorBase64Code() {
|
|
|
16
22
|
}
|
|
17
23
|
return key;
|
|
18
24
|
};
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check whether the given value is empty
|
|
28
|
+
* @param {any} val
|
|
29
|
+
* @returns bool
|
|
30
|
+
*/
|
|
31
|
+
var isEmpty = function isEmpty(val) {
|
|
32
|
+
if (val === null || val === undefined) return true;
|
|
33
|
+
if (val.length !== undefined) return val.length === 0;
|
|
34
|
+
if (val instanceof Date) return false;
|
|
35
|
+
if (_typeof__default["default"](val) === 'object') return Object.keys(val).length === 0;
|
|
36
|
+
return false;
|
|
21
37
|
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Check whether the object is empty.
|
|
41
|
+
* The true will be returned if the "obj" is invalid.
|
|
42
|
+
* @param {object} obj
|
|
43
|
+
* @returns bool
|
|
44
|
+
*/
|
|
22
45
|
var isEmptyObject = function isEmptyObject(obj) {
|
|
23
46
|
var name;
|
|
47
|
+
// eslint-disable-next-line
|
|
24
48
|
for (name in obj) {
|
|
25
49
|
return false;
|
|
26
50
|
}
|
|
@@ -28,5 +52,5 @@ var isEmptyObject = function isEmptyObject(obj) {
|
|
|
28
52
|
};
|
|
29
53
|
|
|
30
54
|
exports.generatorBase64Code = generatorBase64Code;
|
|
55
|
+
exports.isEmpty = isEmpty;
|
|
31
56
|
exports.isEmptyObject = isEmptyObject;
|
|
32
|
-
exports.isNumber = isNumber;
|