dtable-utils 0.0.3-beta.1 → 0.0.3
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 +2 -30
- package/dist/index.js +1 -1
- package/es/cell-value-get/cell-value.js +19 -227
- package/es/cell-value-get/collaborator.js +3 -9
- package/es/cell-value-get/digital-sign.js +1 -1
- package/es/cell-value-get/duration.js +1 -1
- package/es/cell-value-get/geolocation.js +5 -29
- package/es/cell-value-get/long-text.js +1 -1
- package/es/cell-value-get/number.js +18 -42
- package/es/cell-value-get/option.js +7 -17
- package/es/cell-value-set/number.js +1 -53
- package/es/column/{core.js → common.js} +14 -2
- package/es/column/date.js +1 -1
- package/es/column/number.js +1 -1
- package/es/common.js +10 -9
- package/es/constants/column.js +2 -127
- package/es/constants/filter/index.js +1 -5
- package/es/date.js +1 -1
- package/es/index.js +10 -62
- package/es/validate/filter.js +1 -1
- package/lib/cell-value-get/cell-value.js +18 -231
- package/lib/cell-value-get/collaborator.js +2 -9
- package/lib/cell-value-get/digital-sign.js +1 -1
- package/lib/cell-value-get/duration.js +1 -0
- package/lib/cell-value-get/geolocation.js +5 -30
- package/lib/cell-value-get/long-text.js +1 -1
- package/lib/cell-value-get/number.js +17 -42
- package/lib/cell-value-get/option.js +6 -18
- package/lib/cell-value-set/number.js +0 -53
- package/lib/column/{core.js → common.js} +14 -1
- package/lib/column/date.js +2 -2
- package/lib/column/number.js +3 -3
- package/lib/common.js +11 -13
- package/lib/constants/column.js +1 -134
- package/lib/constants/filter/index.js +0 -5
- package/lib/index.js +8 -176
- package/lib/validate/filter.js +3 -3
- package/package.json +3 -5
- package/es/cell-value-get/rate.js +0 -6
- package/es/cell-value-set/date.js +0 -20
- package/es/color/gradient-color.js +0 -100
- package/es/column/color.js +0 -415
- package/es/column/option.js +0 -115
- package/es/constants/color.js +0 -16
- package/es/constants/column-permission.js +0 -7
- package/es/constants/grid-header.js +0 -6
- package/es/constants/group.js +0 -23
- package/es/constants/limit.js +0 -3
- package/es/constants/reg.js +0 -4
- package/es/constants/row-color.js +0 -11
- package/es/constants/sort.js +0 -11
- package/es/filter/core.js +0 -287
- package/es/filter/filter-column/array.js +0 -82
- package/es/filter/filter-column/checkbox.js +0 -8
- package/es/filter/filter-column/collaborator.js +0 -67
- package/es/filter/filter-column/creator.js +0 -50
- package/es/filter/filter-column/date.js +0 -59
- package/es/filter/filter-column/digital-sign.js +0 -26
- package/es/filter/filter-column/file.js +0 -24
- package/es/filter/filter-column/formula.js +0 -49
- package/es/filter/filter-column/geolocation.js +0 -53
- package/es/filter/filter-column/link.js +0 -12
- package/es/filter/filter-column/long-text.js +0 -25
- package/es/filter/filter-column/multiple-select.js +0 -60
- package/es/filter/filter-column/number.js +0 -93
- package/es/filter/filter-column/single-select.js +0 -41
- package/es/filter/filter-column/text.js +0 -55
- package/es/filter/filter-row.js +0 -198
- package/es/group/core.js +0 -107
- package/es/group/group-row.js +0 -366
- package/es/link/core.js +0 -78
- package/es/number.js +0 -13
- package/es/row/color.js +0 -278
- package/es/row/core.js +0 -161
- package/es/sort/core.js +0 -32
- package/es/sort/sort-column/array.js +0 -63
- package/es/sort/sort-column/checkbox.js +0 -15
- package/es/sort/sort-column/collaborator.js +0 -9
- package/es/sort/sort-column/date.js +0 -25
- package/es/sort/sort-column/formula.js +0 -40
- package/es/sort/sort-column/link.js +0 -23
- package/es/sort/sort-column/multiple-select.js +0 -45
- package/es/sort/sort-column/number.js +0 -18
- package/es/sort/sort-column/single-select.js +0 -22
- package/es/sort/sort-column/text.js +0 -47
- package/es/sort/sort-row.js +0 -126
- package/es/table/column.js +0 -27
- package/es/table/core.js +0 -14
- package/es/table/index.js +0 -14
- package/es/table/row.js +0 -25
- package/es/validate/geolocation.js +0 -5
- package/es/view/core.js +0 -135
- package/es/view/formula.js +0 -143
- package/es/view/group.js +0 -32
- package/es/view/summaries.js +0 -179
- package/lib/cell-value-get/rate.js +0 -10
- package/lib/cell-value-set/date.js +0 -24
- package/lib/color/gradient-color.js +0 -110
- package/lib/column/color.js +0 -424
- package/lib/column/option.js +0 -123
- package/lib/constants/color.js +0 -20
- package/lib/constants/column-permission.js +0 -11
- package/lib/constants/grid-header.js +0 -10
- package/lib/constants/group.js +0 -36
- package/lib/constants/limit.js +0 -7
- package/lib/constants/reg.js +0 -9
- package/lib/constants/row-color.js +0 -17
- package/lib/constants/sort.js +0 -18
- package/lib/filter/core.js +0 -301
- package/lib/filter/filter-column/array.js +0 -86
- package/lib/filter/filter-column/checkbox.js +0 -12
- package/lib/filter/filter-column/collaborator.js +0 -75
- package/lib/filter/filter-column/creator.js +0 -54
- package/lib/filter/filter-column/date.js +0 -63
- package/lib/filter/filter-column/digital-sign.js +0 -30
- package/lib/filter/filter-column/file.js +0 -28
- package/lib/filter/filter-column/formula.js +0 -53
- package/lib/filter/filter-column/geolocation.js +0 -57
- package/lib/filter/filter-column/link.js +0 -16
- package/lib/filter/filter-column/long-text.js +0 -29
- package/lib/filter/filter-column/multiple-select.js +0 -68
- package/lib/filter/filter-column/number.js +0 -97
- package/lib/filter/filter-column/single-select.js +0 -45
- package/lib/filter/filter-column/text.js +0 -59
- package/lib/filter/filter-row.js +0 -204
- package/lib/group/core.js +0 -117
- package/lib/group/group-row.js +0 -377
- package/lib/link/core.js +0 -90
- package/lib/number.js +0 -18
- package/lib/row/color.js +0 -286
- package/lib/row/core.js +0 -170
- package/lib/sort/core.js +0 -37
- package/lib/sort/sort-column/array.js +0 -67
- package/lib/sort/sort-column/checkbox.js +0 -19
- package/lib/sort/sort-column/collaborator.js +0 -13
- package/lib/sort/sort-column/date.js +0 -29
- package/lib/sort/sort-column/formula.js +0 -44
- package/lib/sort/sort-column/link.js +0 -27
- package/lib/sort/sort-column/multiple-select.js +0 -50
- package/lib/sort/sort-column/number.js +0 -22
- package/lib/sort/sort-column/single-select.js +0 -26
- package/lib/sort/sort-column/text.js +0 -52
- package/lib/sort/sort-row.js +0 -136
- package/lib/table/column.js +0 -32
- package/lib/table/core.js +0 -18
- package/lib/table/index.js +0 -18
- package/lib/table/row.js +0 -30
- package/lib/validate/geolocation.js +0 -9
- package/lib/view/core.js +0 -144
- package/lib/view/formula.js +0 -150
- package/lib/view/group.js +0 -36
- package/lib/view/summaries.js +0 -185
package/es/row/color.js
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import { getTableColumnByKey } from '../table/column.js';
|
|
3
|
-
import { getRowsByIds } from '../table/row.js';
|
|
4
|
-
import { isTableRows } from './core.js';
|
|
5
|
-
import { getColumnOptions } from '../column/option.js';
|
|
6
|
-
import { getGeolocationDisplayString } from '../cell-value-get/geolocation.js';
|
|
7
|
-
import { ValidateFilter } from '../validate/filter.js';
|
|
8
|
-
import { deleteInvalidFilter, getFormattedFilters } from '../filter/core.js';
|
|
9
|
-
import { filterRow } from '../filter/filter-row.js';
|
|
10
|
-
import { ROW_COLOR_TYPE, ROW_COLOR_FOR_DUPLICATE_VALUES, SUPPORT_CHECKING_DUPLICATE_COLUMNS_TYPES } from '../constants/row-color.js';
|
|
11
|
-
import { CellType } from '../constants/cell-type.js';
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
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(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; }
|
|
15
|
-
var isValidRowColorRule = function isValidRowColorRule(rule, columns) {
|
|
16
|
-
var filters = rule.filters;
|
|
17
|
-
if (!filters || filters.length === 0) return false;
|
|
18
|
-
return filters.some(function (filter) {
|
|
19
|
-
return !ValidateFilter.validate(filter, columns).error_message;
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var getValidRowColorRules = function getValidRowColorRules(colorRules, columns) {
|
|
23
|
-
return colorRules.filter(function (colorRule) {
|
|
24
|
-
return isValidRowColorRule(colorRule, columns);
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
var getOptionIdMap = function getOptionIdMap(options) {
|
|
28
|
-
if (!Array.isArray(options) || options.length === 0) return {};
|
|
29
|
-
var optionsMap = {};
|
|
30
|
-
options.forEach(function (option) {
|
|
31
|
-
optionsMap[option.id] = true;
|
|
32
|
-
});
|
|
33
|
-
return optionsMap;
|
|
34
|
-
};
|
|
35
|
-
var getFormattedDuplicateColumns = function getFormattedDuplicateColumns(columns, duplicateColumnKeys, _ref) {
|
|
36
|
-
var collaborators = _ref.collaborators;
|
|
37
|
-
var formattedColumns = [];
|
|
38
|
-
var _loop = function _loop() {
|
|
39
|
-
var key = duplicateColumnKeys[i];
|
|
40
|
-
var currColumn = columns.find(function (column) {
|
|
41
|
-
return column.key === key;
|
|
42
|
-
});
|
|
43
|
-
if (!currColumn) return "continue";
|
|
44
|
-
var type = currColumn.type,
|
|
45
|
-
data = currColumn.data;
|
|
46
|
-
var formattedColumnData = data;
|
|
47
|
-
if (!SUPPORT_CHECKING_DUPLICATE_COLUMNS_TYPES.includes(type)) return "continue";
|
|
48
|
-
if (type === CellType.SINGLE_SELECT || type === CellType.MULTIPLE_SELECT) {
|
|
49
|
-
var options = getColumnOptions(currColumn);
|
|
50
|
-
formattedColumnData = getOptionIdMap(options);
|
|
51
|
-
} else if (type === CellType.COLLABORATOR) {
|
|
52
|
-
var optionsMap = {};
|
|
53
|
-
if (Array.isArray(collaborators)) {
|
|
54
|
-
collaborators.forEach(function (collaborator) {
|
|
55
|
-
optionsMap[collaborator.email] = true;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
formattedColumnData = optionsMap;
|
|
59
|
-
}
|
|
60
|
-
formattedColumns.push({
|
|
61
|
-
key: key,
|
|
62
|
-
type: type,
|
|
63
|
-
data: formattedColumnData
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
for (var i = 0; i < duplicateColumnKeys.length; i++) {
|
|
67
|
-
var _ret = _loop();
|
|
68
|
-
if (_ret === "continue") continue;
|
|
69
|
-
}
|
|
70
|
-
return formattedColumns;
|
|
71
|
-
};
|
|
72
|
-
var getDuplicateRowValue = function getDuplicateRowValue(row, columns, formulaRow) {
|
|
73
|
-
if (!row) return '';
|
|
74
|
-
var rowValue = columns.map(function (column) {
|
|
75
|
-
var type = column.type,
|
|
76
|
-
data = column.data,
|
|
77
|
-
key = column.key;
|
|
78
|
-
var cellValue = row[key];
|
|
79
|
-
switch (type) {
|
|
80
|
-
case CellType.SINGLE_SELECT:
|
|
81
|
-
{
|
|
82
|
-
return data[cellValue] ? cellValue : '';
|
|
83
|
-
}
|
|
84
|
-
case CellType.MULTIPLE_SELECT:
|
|
85
|
-
case CellType.COLLABORATOR:
|
|
86
|
-
{
|
|
87
|
-
if (!Array.isArray(cellValue) || cellValue.length === 0) return '';
|
|
88
|
-
return cellValue.filter(function (item) {
|
|
89
|
-
return data[item];
|
|
90
|
-
}).sort().join('');
|
|
91
|
-
}
|
|
92
|
-
case CellType.GEOLOCATION:
|
|
93
|
-
{
|
|
94
|
-
if (!cellValue) return '';
|
|
95
|
-
return getGeolocationDisplayString(cellValue, data) || '';
|
|
96
|
-
}
|
|
97
|
-
case CellType.NUMBER:
|
|
98
|
-
{
|
|
99
|
-
if (!cellValue && cellValue !== 0) return '';
|
|
100
|
-
return cellValue;
|
|
101
|
-
}
|
|
102
|
-
case CellType.FORMULA:
|
|
103
|
-
{
|
|
104
|
-
if (!formulaRow) return '';
|
|
105
|
-
cellValue = formulaRow[key];
|
|
106
|
-
return cellValue;
|
|
107
|
-
}
|
|
108
|
-
default:
|
|
109
|
-
{
|
|
110
|
-
return cellValue || '';
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}).join('_seatable_join_key_');
|
|
114
|
-
if (!rowValue) return '';
|
|
115
|
-
if (typeof ''.replaceAll !== 'function') {
|
|
116
|
-
// eslint-disable-next-line
|
|
117
|
-
String.prototype.replaceAll = function (s1, s2) {
|
|
118
|
-
return this.replace(new RegExp(s1, 'gm'), s2);
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
if (!rowValue.replaceAll('_seatable_join_key_', '')) return '';
|
|
122
|
-
return rowValue;
|
|
123
|
-
};
|
|
124
|
-
var getRowsColorBySingleSelectColumn = function getRowsColorBySingleSelectColumn(rows, columnKey, table) {
|
|
125
|
-
var colors = {};
|
|
126
|
-
var column = getTableColumnByKey(table, columnKey);
|
|
127
|
-
var options = getColumnOptions(column);
|
|
128
|
-
if (!Array.isArray(options) || options.length === 0) return {};
|
|
129
|
-
var option_id_color_map = {};
|
|
130
|
-
options.forEach(function (option) {
|
|
131
|
-
option_id_color_map[option.id] = option.color;
|
|
132
|
-
});
|
|
133
|
-
rows.forEach(function (row) {
|
|
134
|
-
var optionId = row[columnKey];
|
|
135
|
-
var color = optionId ? option_id_color_map[optionId] : '';
|
|
136
|
-
if (color) {
|
|
137
|
-
colors[row._id] = color;
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
return colors;
|
|
141
|
-
};
|
|
142
|
-
var getRowsColorByRules = function getRowsColorByRules(rows, view, table) {
|
|
143
|
-
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
144
|
-
username = _ref2.username,
|
|
145
|
-
userId = _ref2.userId;
|
|
146
|
-
var formula_rows = view.formula_rows,
|
|
147
|
-
colorbys = view.colorbys;
|
|
148
|
-
var _ref3 = colorbys || {},
|
|
149
|
-
type = _ref3.type,
|
|
150
|
-
color_by_rules = _ref3.color_by_rules;
|
|
151
|
-
if (type !== ROW_COLOR_TYPE.BY_RULES) return {};
|
|
152
|
-
var columns = table.columns;
|
|
153
|
-
var validColorRules = getValidRowColorRules(color_by_rules, columns);
|
|
154
|
-
var colorRulesLen = validColorRules.length;
|
|
155
|
-
var colors = {};
|
|
156
|
-
if (colorRulesLen === 0) return {};
|
|
157
|
-
validColorRules = validColorRules.map(function (colorRule) {
|
|
158
|
-
var filters = colorRule.filters;
|
|
159
|
-
var validFilters;
|
|
160
|
-
try {
|
|
161
|
-
validFilters = deleteInvalidFilter(filters, columns);
|
|
162
|
-
} catch (err) {
|
|
163
|
-
validFilters = [];
|
|
164
|
-
}
|
|
165
|
-
validFilters = getFormattedFilters(validFilters);
|
|
166
|
-
return _objectSpread(_objectSpread({}, colorRule), {}, {
|
|
167
|
-
filters: validFilters
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
rows.forEach(function (row) {
|
|
171
|
-
var rowId = row._id;
|
|
172
|
-
var formulaRow = formula_rows && formula_rows[rowId] || {};
|
|
173
|
-
for (var i = 0; i < colorRulesLen; i++) {
|
|
174
|
-
var colorRule = validColorRules[i];
|
|
175
|
-
var color = colorRule.color,
|
|
176
|
-
filter_conjunction = colorRule.filter_conjunction,
|
|
177
|
-
filters = colorRule.filters;
|
|
178
|
-
if (filterRow(row, filter_conjunction, filters, {
|
|
179
|
-
formulaRow: formulaRow,
|
|
180
|
-
username: username,
|
|
181
|
-
userId: userId
|
|
182
|
-
})) {
|
|
183
|
-
colors[rowId] = color;
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
return colors;
|
|
189
|
-
};
|
|
190
|
-
var getRowsColorByDuplicateValues = function getRowsColorByDuplicateValues(rows, view, table, _ref4) {
|
|
191
|
-
var collaborators = _ref4.collaborators;
|
|
192
|
-
var colorbys = view.colorbys,
|
|
193
|
-
formula_rows = view.formula_rows;
|
|
194
|
-
var color_by_duplicate_column_keys = colorbys.color_by_duplicate_column_keys;
|
|
195
|
-
if (!Array.isArray(color_by_duplicate_column_keys) || color_by_duplicate_column_keys.length === 0) return {};
|
|
196
|
-
var columns = table.columns;
|
|
197
|
-
var formattedColumns = getFormattedDuplicateColumns(columns, color_by_duplicate_column_keys, {
|
|
198
|
-
collaborators: collaborators
|
|
199
|
-
});
|
|
200
|
-
if (formattedColumns.length === 0) return {};
|
|
201
|
-
var colors = {};
|
|
202
|
-
var duplicate_rows_ids_map = {}; // row value: [ row_id ]
|
|
203
|
-
for (var i = 0; i < rows.length; i++) {
|
|
204
|
-
var row = rows[i];
|
|
205
|
-
var rowId = row._id;
|
|
206
|
-
var formulaRow = formula_rows && formula_rows[rowId];
|
|
207
|
-
var rowValue = getDuplicateRowValue(row, formattedColumns, formulaRow);
|
|
208
|
-
if (!rowValue) continue;
|
|
209
|
-
var validRowIds = duplicate_rows_ids_map[rowValue];
|
|
210
|
-
if (validRowIds && validRowIds.length > 0) {
|
|
211
|
-
colors[rowId] = ROW_COLOR_FOR_DUPLICATE_VALUES;
|
|
212
|
-
validRowIds.push(rowId);
|
|
213
|
-
var firstDuplicateRowId = validRowIds[0];
|
|
214
|
-
if (!colors[firstDuplicateRowId]) {
|
|
215
|
-
colors[firstDuplicateRowId] = ROW_COLOR_FOR_DUPLICATE_VALUES;
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
218
|
-
duplicate_rows_ids_map[rowValue] = [rowId];
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return {
|
|
222
|
-
colors: colors,
|
|
223
|
-
duplicate_rows_ids_map: duplicate_rows_ids_map
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
var getRowsColor = function getRowsColor(rows, view, table, value) {
|
|
227
|
-
var _ref5 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
228
|
-
username = _ref5.username,
|
|
229
|
-
userId = _ref5.userId;
|
|
230
|
-
var colorbys = view.colorbys;
|
|
231
|
-
if (!colorbys) return {};
|
|
232
|
-
var tableRows = isTableRows(rows) ? rows : getRowsByIds(table, rows);
|
|
233
|
-
if (tableRows.length === 0) return {};
|
|
234
|
-
var type = colorbys.type,
|
|
235
|
-
color_by_column = colorbys.color_by_column;
|
|
236
|
-
switch (type) {
|
|
237
|
-
case ROW_COLOR_TYPE.BY_COLUMN:
|
|
238
|
-
{
|
|
239
|
-
return {
|
|
240
|
-
colors: getRowsColorBySingleSelectColumn(tableRows, color_by_column, table)
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
case ROW_COLOR_TYPE.BY_RULES:
|
|
244
|
-
{
|
|
245
|
-
return {
|
|
246
|
-
colors: getRowsColorByRules(tableRows, view, table, {
|
|
247
|
-
username: username,
|
|
248
|
-
userId: userId
|
|
249
|
-
})
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
case ROW_COLOR_TYPE.BY_DUPLICATE_VALUES:
|
|
253
|
-
{
|
|
254
|
-
var _ref6 = value || {},
|
|
255
|
-
_ref6$collaborators = _ref6.collaborators,
|
|
256
|
-
collaborators = _ref6$collaborators === void 0 ? [] : _ref6$collaborators;
|
|
257
|
-
return getRowsColorByDuplicateValues(tableRows, view, table, {
|
|
258
|
-
collaborators: collaborators
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
default:
|
|
262
|
-
{
|
|
263
|
-
return {};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
var RowColorUtils = {
|
|
268
|
-
isValidRowColorRule: isValidRowColorRule,
|
|
269
|
-
getValidRowColorRules: getValidRowColorRules,
|
|
270
|
-
getRowsColor: getRowsColor,
|
|
271
|
-
getFormattedDuplicateColumns: getFormattedDuplicateColumns,
|
|
272
|
-
getDuplicateRowValue: getDuplicateRowValue,
|
|
273
|
-
getRowsColorBySingleSelectColumn: getRowsColorBySingleSelectColumn,
|
|
274
|
-
getRowsColorByRules: getRowsColorByRules,
|
|
275
|
-
getRowsColorByDuplicateValues: getRowsColorByDuplicateValues
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
export { RowColorUtils as default };
|
package/es/row/core.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
-
import { getFormulaDisplayString } from '../cell-value-get/cell-value.js';
|
|
3
|
-
import 'dayjs';
|
|
4
|
-
import '../constants/column.js';
|
|
5
|
-
import { getColumnOptionNameById } from '../cell-value-get/option.js';
|
|
6
|
-
import '../constants/group.js';
|
|
7
|
-
import { getLinkCellValue } from '../link/core.js';
|
|
8
|
-
import { isEmpty } from '../common.js';
|
|
9
|
-
import { CellType } from '../constants/cell-type.js';
|
|
10
|
-
import { CONVERT_ROW_COLUMNS_LIMIT } from '../constants/limit.js';
|
|
11
|
-
|
|
12
|
-
var isTableRows = function isTableRows(rows) {
|
|
13
|
-
return Array.isArray(rows) && _typeof(rows[0]) === 'object';
|
|
14
|
-
};
|
|
15
|
-
var convertRow = function convertRow(row, value, table, view, formulaResults, convertLinkID) {
|
|
16
|
-
var _ref = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {},
|
|
17
|
-
debug = _ref.debug;
|
|
18
|
-
var result = {};
|
|
19
|
-
// eslint-disable-next-line
|
|
20
|
-
if (row.hasOwnProperty('_id')) {
|
|
21
|
-
result._id = row._id;
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line
|
|
24
|
-
if (row.hasOwnProperty('_mtime')) {
|
|
25
|
-
result._mtime = row._mtime;
|
|
26
|
-
}
|
|
27
|
-
// eslint-disable-next-line
|
|
28
|
-
if (row.hasOwnProperty('_ctime')) {
|
|
29
|
-
result._ctime = row._ctime;
|
|
30
|
-
}
|
|
31
|
-
var columns = table.columns;
|
|
32
|
-
if (columns.length > CONVERT_ROW_COLUMNS_LIMIT) {
|
|
33
|
-
columns = columns.slice(0, CONVERT_ROW_COLUMNS_LIMIT);
|
|
34
|
-
}
|
|
35
|
-
var hiddenColumns = view ? view.hidden_columns : null;
|
|
36
|
-
for (var i = 0; i < columns.length; i++) {
|
|
37
|
-
var column = columns[i];
|
|
38
|
-
var key = column.key,
|
|
39
|
-
type = column.type,
|
|
40
|
-
columnName = column.name;
|
|
41
|
-
if (hiddenColumns && hiddenColumns.includes(key)) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
var cellValue = row[key];
|
|
45
|
-
switch (type) {
|
|
46
|
-
case CellType.SINGLE_SELECT:
|
|
47
|
-
{
|
|
48
|
-
if (!column.data) {
|
|
49
|
-
if (debug) {
|
|
50
|
-
debug('No options found');
|
|
51
|
-
}
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
result[columnName] = getColumnOptionNameById(column, cellValue);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
case CellType.MULTIPLE_SELECT:
|
|
58
|
-
{
|
|
59
|
-
if (!column.data) {
|
|
60
|
-
if (debug) {
|
|
61
|
-
debug('No options found');
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
if (!Array.isArray(cellValue)) {
|
|
66
|
-
result[columnName] = '';
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
var optionNames = [];
|
|
70
|
-
for (var optionIndex = 0; optionIndex < cellValue.length; optionIndex++) {
|
|
71
|
-
var optionName = getColumnOptionNameById(column, cellValue[optionIndex]);
|
|
72
|
-
if (optionName) {
|
|
73
|
-
optionNames.push(optionName);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
result[columnName] = optionNames;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case CellType.LONG_TEXT:
|
|
80
|
-
{
|
|
81
|
-
result[columnName] = cellValue ? cellValue.text : '';
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
case CellType.LINK:
|
|
85
|
-
{
|
|
86
|
-
if (!column.data) {
|
|
87
|
-
if (debug) {
|
|
88
|
-
debug('No links found');
|
|
89
|
-
}
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
// convertLinkID to display value
|
|
93
|
-
if (convertLinkID) {
|
|
94
|
-
// get values form formulaResults
|
|
95
|
-
var formulaRow = formulaResults && formulaResults[row._id];
|
|
96
|
-
var cellResult = formulaRow && formulaRow[key];
|
|
97
|
-
if (!cellResult || !Array.isArray(cellResult) || cellResult.length === 0) {
|
|
98
|
-
result[columnName] = null;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
// linked with common column:
|
|
102
|
-
// cellResult
|
|
103
|
-
// [
|
|
104
|
-
// {row_id: '', displayValue: ''},
|
|
105
|
-
// {row_id: '', displayValue: ''},
|
|
106
|
-
// ]
|
|
107
|
-
|
|
108
|
-
// linked with formula column and formula result is array
|
|
109
|
-
// cellResult
|
|
110
|
-
// [
|
|
111
|
-
// {row_id: '', display_value: []},
|
|
112
|
-
// {row_id: '', display_value: []},
|
|
113
|
-
// ]
|
|
114
|
-
result[columnName] = cellResult;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
var tableID = table._id;
|
|
118
|
-
var _column$data = column.data,
|
|
119
|
-
link_id = _column$data.link_id,
|
|
120
|
-
table_id = _column$data.table_id,
|
|
121
|
-
other_table_id = _column$data.other_table_id;
|
|
122
|
-
var otherTableID = tableID === table_id ? other_table_id : table_id;
|
|
123
|
-
var links = value.links;
|
|
124
|
-
result[columnName] = getLinkCellValue(links, link_id, tableID, otherTableID, row._id);
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
case CellType.FORMULA:
|
|
128
|
-
case CellType.LINK_FORMULA:
|
|
129
|
-
{
|
|
130
|
-
if (!column.data || !formulaResults) {
|
|
131
|
-
if (debug) {
|
|
132
|
-
debug('No formula found');
|
|
133
|
-
}
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
var _formulaRow = formulaResults[row._id] || {};
|
|
137
|
-
result[columnName] = getFormulaDisplayString(_formulaRow[key], column.data);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
default:
|
|
141
|
-
{
|
|
142
|
-
// text/email/url/auto-number/
|
|
143
|
-
// check/
|
|
144
|
-
// rate/duration/
|
|
145
|
-
// file/image/button/
|
|
146
|
-
// translate in dtable-events
|
|
147
|
-
// number/
|
|
148
|
-
// date/ctime/mtime/
|
|
149
|
-
// geolocation/
|
|
150
|
-
// collaborator/creator/last-modifier/
|
|
151
|
-
result[columnName] = cellValue;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (isEmpty(result[columnName])) {
|
|
155
|
-
delete result[columnName];
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return result;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export { convertRow, isTableRows };
|
package/es/sort/core.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SORT_COLUMN_OPTIONS } from '../constants/sort.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* check is valid sort
|
|
5
|
-
* @param {object} sort e.g. { column_key: '', sort_type: '' }
|
|
6
|
-
* @param {array} columns
|
|
7
|
-
* @returns boolean
|
|
8
|
-
*/
|
|
9
|
-
var isValidSort = function isValidSort(sort, columns) {
|
|
10
|
-
var sortByColumn = sort && columns.find(function (column) {
|
|
11
|
-
return column.key === sort.column_key;
|
|
12
|
-
});
|
|
13
|
-
if (!sortByColumn) return false;
|
|
14
|
-
return SORT_COLUMN_OPTIONS.includes(sortByColumn.type);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* get valid sorts
|
|
19
|
-
* 1. sort column is exist or not
|
|
20
|
-
* 2. valid sort type
|
|
21
|
-
* @param {array} sorts
|
|
22
|
-
* @param {array} columns
|
|
23
|
-
* @returns array
|
|
24
|
-
*/
|
|
25
|
-
var getValidSorts = function getValidSorts(sorts, columns) {
|
|
26
|
-
if (!Array.isArray(sorts) || !Array.isArray(columns)) return [];
|
|
27
|
-
return sorts.filter(function (sort) {
|
|
28
|
-
return isValidSort(sort, columns);
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { getValidSorts, isValidSort };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { getCollaboratorsNames } from '../../cell-value-get/collaborator.js';
|
|
2
|
-
import { getFormulaDisplayString } from '../../cell-value-get/cell-value.js';
|
|
3
|
-
import { sortCheckbox } from './checkbox.js';
|
|
4
|
-
import { sortCollaborator } from './collaborator.js';
|
|
5
|
-
import { sortDate } from './date.js';
|
|
6
|
-
import { sortNumber } from './number.js';
|
|
7
|
-
import { sortText } from './text.js';
|
|
8
|
-
import { CellType } from '../../constants/cell-type.js';
|
|
9
|
-
import { NUMERIC_COLUMNS_TYPES, DATE_COLUMN_OPTIONS } from '../../constants/column.js';
|
|
10
|
-
import { FORMULA_RESULT_TYPE } from '../../constants/formula.js';
|
|
11
|
-
|
|
12
|
-
var sortByArrayType = function sortByArrayType(currCellVal, nextCellVal, sortType, _ref) {
|
|
13
|
-
var columnData = _ref.columnData,
|
|
14
|
-
value = _ref.value;
|
|
15
|
-
var _ref2 = columnData || {},
|
|
16
|
-
array_type = _ref2.array_type;
|
|
17
|
-
if (NUMERIC_COLUMNS_TYPES.includes(array_type)) {
|
|
18
|
-
var currNumber = currCellVal;
|
|
19
|
-
var nextNumber = nextCellVal;
|
|
20
|
-
if (Array.isArray(currCellVal)) {
|
|
21
|
-
currNumber = currCellVal[0];
|
|
22
|
-
}
|
|
23
|
-
if (Array.isArray(nextCellVal)) {
|
|
24
|
-
nextNumber = nextCellVal[0];
|
|
25
|
-
}
|
|
26
|
-
currNumber = currNumber || currNumber === 0 ? currNumber : null;
|
|
27
|
-
nextNumber = nextNumber || nextNumber === 0 ? nextNumber : null;
|
|
28
|
-
return sortNumber(currNumber, nextNumber, sortType);
|
|
29
|
-
}
|
|
30
|
-
if (DATE_COLUMN_OPTIONS.includes(array_type)) {
|
|
31
|
-
var currDate = Array.isArray(currCellVal) ? currCellVal[0] : currCellVal;
|
|
32
|
-
var nextDate = Array.isArray(nextCellVal) ? nextCellVal[0] : nextCellVal;
|
|
33
|
-
return sortDate(currDate, nextDate, sortType);
|
|
34
|
-
}
|
|
35
|
-
if (array_type === CellType.CHECKBOX || array_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
36
|
-
var currBoolean = currCellVal;
|
|
37
|
-
var nextBoolean = nextCellVal;
|
|
38
|
-
if (Array.isArray(currCellVal)) {
|
|
39
|
-
currBoolean = currCellVal[0];
|
|
40
|
-
}
|
|
41
|
-
if (Array.isArray(nextCellVal)) {
|
|
42
|
-
nextBoolean = nextCellVal[0];
|
|
43
|
-
}
|
|
44
|
-
currBoolean = currBoolean || false;
|
|
45
|
-
nextBoolean = nextBoolean || false;
|
|
46
|
-
return sortCheckbox(currBoolean, nextBoolean, sortType);
|
|
47
|
-
}
|
|
48
|
-
if (array_type === CellType.COLLABORATOR) {
|
|
49
|
-
var collaborators = value.collaborators;
|
|
50
|
-
var currCollaborators = Array.isArray(currCellVal) ? currCellVal : [currCellVal];
|
|
51
|
-
var nextCollaborators = Array.isArray(nextCellVal) ? nextCellVal : [nextCellVal];
|
|
52
|
-
if (collaborators) {
|
|
53
|
-
currCollaborators = getCollaboratorsNames(currCollaborators, collaborators);
|
|
54
|
-
nextCollaborators = getCollaboratorsNames(nextCollaborators, collaborators);
|
|
55
|
-
}
|
|
56
|
-
return sortCollaborator(currCollaborators, nextCollaborators, sortType);
|
|
57
|
-
}
|
|
58
|
-
var currText = getFormulaDisplayString(currCellVal, columnData);
|
|
59
|
-
var nextText = getFormulaDisplayString(nextCellVal, columnData);
|
|
60
|
-
return sortText(currText, nextText, sortType);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export { sortByArrayType };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SORT_TYPE } from '../../constants/sort.js';
|
|
2
|
-
|
|
3
|
-
var sortCheckbox = function sortCheckbox(currCellVal, nextCellVal, sortType) {
|
|
4
|
-
var currCellValPart = currCellVal ? 1 : -1;
|
|
5
|
-
var nextCellValPart = nextCellVal ? 1 : -1;
|
|
6
|
-
if (currCellValPart > nextCellValPart) {
|
|
7
|
-
return sortType === SORT_TYPE.UP ? 1 : -1;
|
|
8
|
-
}
|
|
9
|
-
if (currCellValPart < nextCellValPart) {
|
|
10
|
-
return sortType === SORT_TYPE.UP ? -1 : 1;
|
|
11
|
-
}
|
|
12
|
-
return 0;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { sortCheckbox };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { sortText } from './text.js';
|
|
2
|
-
|
|
3
|
-
var sortCollaborator = function sortCollaborator(currCellVal, nextCellVal, sortType) {
|
|
4
|
-
var currCellValString = Array.isArray(currCellVal) && currCellVal.length ? currCellVal.join('') : null;
|
|
5
|
-
var nextCellValString = Array.isArray(currCellVal) && currCellVal.length ? nextCellVal.join('') : null;
|
|
6
|
-
return sortText(currCellValString, nextCellValString, sortType);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export { sortCollaborator };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { SORT_TYPE } from '../../constants/sort.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* compare date
|
|
5
|
-
* @param {string} currDate date string, e.g. '2023-07-31'
|
|
6
|
-
* @param {string} nextDate date string
|
|
7
|
-
* @param {string} sortType e.g. 'up' | 'down'
|
|
8
|
-
* @returns number, e.g. 1 | -1 | 0
|
|
9
|
-
*/
|
|
10
|
-
var sortDate = function sortDate(currDate, nextDate, sortType) {
|
|
11
|
-
var emptyCurrDate = !currDate;
|
|
12
|
-
var emptyNextDate = !nextDate;
|
|
13
|
-
if (emptyCurrDate && emptyNextDate) return 0;
|
|
14
|
-
if (emptyCurrDate) return 1;
|
|
15
|
-
if (emptyNextDate) return -1;
|
|
16
|
-
if (currDate > nextDate) {
|
|
17
|
-
return sortType === SORT_TYPE.UP ? 1 : -1;
|
|
18
|
-
}
|
|
19
|
-
if (currDate < nextDate) {
|
|
20
|
-
return sortType === SORT_TYPE.UP ? -1 : 1;
|
|
21
|
-
}
|
|
22
|
-
return 0;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export { sortDate };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { getFormulaDisplayString } from '../../cell-value-get/cell-value.js';
|
|
2
|
-
import { sortByArrayType } from './array.js';
|
|
3
|
-
import { sortCheckbox } from './checkbox.js';
|
|
4
|
-
import { sortDate } from './date.js';
|
|
5
|
-
import { sortNumber } from './number.js';
|
|
6
|
-
import { sortText } from './text.js';
|
|
7
|
-
import { DATE_COLUMN_OPTIONS } from '../../constants/column.js';
|
|
8
|
-
import { FORMULA_RESULT_TYPE } from '../../constants/formula.js';
|
|
9
|
-
import { NUMBER_SORTER_COLUMN_TYPES } from '../../constants/sort.js';
|
|
10
|
-
|
|
11
|
-
var sortFormula = function sortFormula(currCellVal, nextCellVal, sortType, _ref) {
|
|
12
|
-
var columnData = _ref.columnData,
|
|
13
|
-
value = _ref.value;
|
|
14
|
-
var _ref2 = columnData || {},
|
|
15
|
-
result_type = _ref2.result_type;
|
|
16
|
-
if (NUMBER_SORTER_COLUMN_TYPES.includes(result_type)) {
|
|
17
|
-
var currNumber = currCellVal || currCellVal === 0 ? currCellVal - 0 : null;
|
|
18
|
-
var nextNumber = nextCellVal || nextCellVal === 0 ? nextCellVal - 0 : null;
|
|
19
|
-
return sortNumber(currNumber, nextNumber, sortType);
|
|
20
|
-
}
|
|
21
|
-
if (DATE_COLUMN_OPTIONS.includes(result_type)) {
|
|
22
|
-
return sortDate(currCellVal, nextCellVal, sortType);
|
|
23
|
-
}
|
|
24
|
-
if (result_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
25
|
-
var currBoolean = currCellVal || false;
|
|
26
|
-
var nextBoolean = nextCellVal || false;
|
|
27
|
-
return sortCheckbox(currBoolean, nextBoolean);
|
|
28
|
-
}
|
|
29
|
-
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
30
|
-
return sortByArrayType(currCellVal, nextCellVal, sortType, {
|
|
31
|
-
columnData: columnData,
|
|
32
|
-
value: value
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
var currText = getFormulaDisplayString(currCellVal, columnData);
|
|
36
|
-
var nextText = getFormulaDisplayString(nextCellVal, columnData);
|
|
37
|
-
return sortText(currText, nextText, sortType);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export { sortFormula };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { sortByArrayType } from './array.js';
|
|
2
|
-
|
|
3
|
-
var sortLink = function sortLink(currCellVal, nextCellVal, sortType, _ref) {
|
|
4
|
-
var columnData = _ref.columnData,
|
|
5
|
-
value = _ref.value;
|
|
6
|
-
var emptyCurrCellVal = !Array.isArray(currCellVal) || currCellVal.length === 0;
|
|
7
|
-
var emptyNextCellVal = !Array.isArray(nextCellVal) || nextCellVal.length === 0;
|
|
8
|
-
if (emptyCurrCellVal && emptyNextCellVal) return 0;
|
|
9
|
-
if (emptyCurrCellVal) return 1;
|
|
10
|
-
if (emptyNextCellVal) return -1;
|
|
11
|
-
var currDisplayValues = currCellVal.map(function (linked) {
|
|
12
|
-
return linked.display_value;
|
|
13
|
-
});
|
|
14
|
-
var nextDisplayValues = nextCellVal.map(function (linked) {
|
|
15
|
-
return linked.display_value;
|
|
16
|
-
});
|
|
17
|
-
return sortByArrayType(currDisplayValues, nextDisplayValues, sortType, {
|
|
18
|
-
columnData: columnData,
|
|
19
|
-
value: value
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export { sortLink };
|