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
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { SORT_TYPE } from '../../constants/sort.js';
|
|
2
|
-
|
|
3
|
-
var getMultipleIndexesOrderbyOptions = function getMultipleIndexesOrderbyOptions(cellValue, option_id_index_map) {
|
|
4
|
-
var indexArr = [];
|
|
5
|
-
cellValue.forEach(function (optionId) {
|
|
6
|
-
var index = option_id_index_map[optionId];
|
|
7
|
-
if (index > -1) {
|
|
8
|
-
indexArr.push(index);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
return indexArr.sort();
|
|
12
|
-
};
|
|
13
|
-
var sortMultipleSelect = function sortMultipleSelect(currCellVal, nextCellVal, _ref) {
|
|
14
|
-
var sort_type = _ref.sort_type,
|
|
15
|
-
option_id_index_map = _ref.option_id_index_map;
|
|
16
|
-
var emptyCurrCellVal = !currCellVal || currCellVal.length === 0;
|
|
17
|
-
var emptyNextCellVal = !nextCellVal || nextCellVal.length === 0;
|
|
18
|
-
if (emptyCurrCellVal && emptyNextCellVal) return 0;
|
|
19
|
-
if (emptyCurrCellVal) return 1;
|
|
20
|
-
if (emptyNextCellVal) return -1;
|
|
21
|
-
var currCellValIndexes = getMultipleIndexesOrderbyOptions(currCellVal, option_id_index_map);
|
|
22
|
-
var nextCellValIndexes = getMultipleIndexesOrderbyOptions(nextCellVal, option_id_index_map);
|
|
23
|
-
var currLen = currCellValIndexes.length;
|
|
24
|
-
var nextLen = nextCellValIndexes.length;
|
|
25
|
-
|
|
26
|
-
// current multiple select equal to next multiple select.
|
|
27
|
-
if (currLen === nextLen && (currLen === 0 || currCellValIndexes.join('') === nextCellValIndexes.join(''))) {
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
var len = Math.min(currLen, nextLen);
|
|
31
|
-
for (var i = 0; i < len; i++) {
|
|
32
|
-
if (currCellValIndexes[i] > nextCellValIndexes[i]) {
|
|
33
|
-
return sort_type === SORT_TYPE.UP ? 1 : -1;
|
|
34
|
-
}
|
|
35
|
-
if (currCellValIndexes[i] < nextCellValIndexes[i]) {
|
|
36
|
-
return sort_type === SORT_TYPE.UP ? -1 : 1;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (currLen > nextLen) {
|
|
40
|
-
return sort_type === SORT_TYPE.UP ? 1 : -1;
|
|
41
|
-
}
|
|
42
|
-
return sort_type === SORT_TYPE.UP ? -1 : 1;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export { getMultipleIndexesOrderbyOptions, sortMultipleSelect };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SORT_TYPE } from '../../constants/sort.js';
|
|
2
|
-
|
|
3
|
-
var sortNumber = function sortNumber(currNum, nextNum, sortType) {
|
|
4
|
-
var emptyCurrNum = !currNum && currNum !== 0;
|
|
5
|
-
var emptyNextNum = !nextNum && nextNum !== 0;
|
|
6
|
-
if (emptyCurrNum && emptyNextNum) return 0;
|
|
7
|
-
if (emptyCurrNum) return 1;
|
|
8
|
-
if (emptyNextNum) return -1;
|
|
9
|
-
if (currNum > nextNum) {
|
|
10
|
-
return sortType === SORT_TYPE.UP ? 1 : -1;
|
|
11
|
-
}
|
|
12
|
-
if (currNum < nextNum) {
|
|
13
|
-
return sortType === SORT_TYPE.UP ? -1 : 1;
|
|
14
|
-
}
|
|
15
|
-
return 0;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { sortNumber };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { SORT_TYPE } from '../../constants/sort.js';
|
|
2
|
-
|
|
3
|
-
var sortSingleSelect = function sortSingleSelect(currCellVal, nextCellVal, _ref) {
|
|
4
|
-
var sort_type = _ref.sort_type,
|
|
5
|
-
option_id_index_map = _ref.option_id_index_map;
|
|
6
|
-
var currentOptionIdIndex = option_id_index_map[currCellVal];
|
|
7
|
-
var nextOptionIdIndex = option_id_index_map[nextCellVal];
|
|
8
|
-
var emptyCurrCellVal = !currentOptionIdIndex && currentOptionIdIndex !== 0;
|
|
9
|
-
var emptyNextCellVal = !nextOptionIdIndex && nextOptionIdIndex !== 0;
|
|
10
|
-
if (emptyCurrCellVal && emptyNextCellVal) return 0;
|
|
11
|
-
if (emptyCurrCellVal) return 1;
|
|
12
|
-
if (emptyNextCellVal) return -1;
|
|
13
|
-
if (currentOptionIdIndex > nextOptionIdIndex) {
|
|
14
|
-
return sort_type === SORT_TYPE.UP ? 1 : -1;
|
|
15
|
-
}
|
|
16
|
-
if (currentOptionIdIndex < nextOptionIdIndex) {
|
|
17
|
-
return sort_type === SORT_TYPE.UP ? -1 : 1;
|
|
18
|
-
}
|
|
19
|
-
return 0;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export { sortSingleSelect };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { REG_STRING_NUMBER_PARTS, REG_NUMBER_DIGIT } from '../../constants/reg.js';
|
|
2
|
-
import { SORT_TYPE } from '../../constants/sort.js';
|
|
3
|
-
|
|
4
|
-
var compareString = function compareString(leftString, rightString) {
|
|
5
|
-
if (!leftString && !rightString) return 0;
|
|
6
|
-
if (!leftString) return -1;
|
|
7
|
-
if (!rightString) return 1;
|
|
8
|
-
if (typeof leftString !== 'string' || typeof rightString !== 'string') return 0;
|
|
9
|
-
var leftStringParts = leftString.match(REG_STRING_NUMBER_PARTS);
|
|
10
|
-
var rightStringParts = rightString.match(REG_STRING_NUMBER_PARTS);
|
|
11
|
-
var len = Math.min(leftStringParts.length, rightStringParts.length);
|
|
12
|
-
var isDigitPart;
|
|
13
|
-
var leftStringPart;
|
|
14
|
-
var rightStringPart;
|
|
15
|
-
|
|
16
|
-
// Loop through each substring part to canCompare the overall strings.
|
|
17
|
-
for (var i = 0; i < len; i++) {
|
|
18
|
-
leftStringPart = leftStringParts[i];
|
|
19
|
-
rightStringPart = rightStringParts[i];
|
|
20
|
-
isDigitPart = REG_NUMBER_DIGIT.test(leftStringPart) && REG_NUMBER_DIGIT.test(rightStringPart);
|
|
21
|
-
if (isDigitPart) {
|
|
22
|
-
leftStringPart = parseInt(leftStringPart, 10);
|
|
23
|
-
rightStringPart = parseInt(rightStringPart, 10);
|
|
24
|
-
if (leftStringPart > rightStringPart) {
|
|
25
|
-
return 1;
|
|
26
|
-
}
|
|
27
|
-
if (leftStringPart < rightStringPart) {
|
|
28
|
-
return -1;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (leftStringPart !== rightStringPart) {
|
|
32
|
-
return leftString.localeCompare(rightString);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return leftString.localeCompare(rightString);
|
|
36
|
-
};
|
|
37
|
-
var sortText = function sortText(currCellVal, nextCellVal, sortType) {
|
|
38
|
-
var emptyCurrCellVal = !currCellVal;
|
|
39
|
-
var emptyNextCellVal = !nextCellVal;
|
|
40
|
-
if (emptyCurrCellVal && emptyNextCellVal) return 0;
|
|
41
|
-
if (emptyCurrCellVal) return 1;
|
|
42
|
-
if (emptyNextCellVal) return -1;
|
|
43
|
-
if (nextCellVal === currCellVal) return 0;
|
|
44
|
-
return sortType === SORT_TYPE.UP ? compareString(currCellVal, nextCellVal) : -1 * compareString(currCellVal, nextCellVal);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export { compareString, sortText };
|
package/es/sort/sort-row.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import { getValidSorts } from './core.js';
|
|
3
|
-
import { sortCheckbox } from './sort-column/checkbox.js';
|
|
4
|
-
import { sortCollaborator } from './sort-column/collaborator.js';
|
|
5
|
-
import { sortDate } from './sort-column/date.js';
|
|
6
|
-
import { getCollaboratorsNames } from '../cell-value-get/collaborator.js';
|
|
7
|
-
import '../cell-value-get/cell-value.js';
|
|
8
|
-
import { sortNumber } from './sort-column/number.js';
|
|
9
|
-
import { sortText } from './sort-column/text.js';
|
|
10
|
-
import { CellType } from '../constants/cell-type.js';
|
|
11
|
-
import { DATE_COLUMN_OPTIONS } from '../constants/column.js';
|
|
12
|
-
import { FORMULA_COLUMN_TYPES_MAP } from '../constants/formula.js';
|
|
13
|
-
import { sortFormula } from './sort-column/formula.js';
|
|
14
|
-
import { sortLink } from './sort-column/link.js';
|
|
15
|
-
import { sortMultipleSelect } from './sort-column/multiple-select.js';
|
|
16
|
-
import { sortSingleSelect } from './sort-column/single-select.js';
|
|
17
|
-
import { getColumnOptions } from '../column/option.js';
|
|
18
|
-
import { NUMBER_SORTER_COLUMN_TYPES } from '../constants/sort.js';
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
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; }
|
|
22
|
-
var deleteInvalidSort = function deleteInvalidSort(sorts, columns) {
|
|
23
|
-
var validSorts = getValidSorts(sorts, columns);
|
|
24
|
-
var cleanSorts = [];
|
|
25
|
-
validSorts.forEach(function (sort) {
|
|
26
|
-
var column_key = sort.column_key;
|
|
27
|
-
var sortColumn = columns.find(function (column) {
|
|
28
|
-
return column.key === column_key;
|
|
29
|
-
});
|
|
30
|
-
var columnType = sortColumn.type;
|
|
31
|
-
var newSort = _objectSpread(_objectSpread({}, sort), {}, {
|
|
32
|
-
column: sortColumn
|
|
33
|
-
});
|
|
34
|
-
switch (columnType) {
|
|
35
|
-
case CellType.SINGLE_SELECT:
|
|
36
|
-
case CellType.MULTIPLE_SELECT:
|
|
37
|
-
{
|
|
38
|
-
var options = getColumnOptions(sortColumn);
|
|
39
|
-
var option_id_index_map = {};
|
|
40
|
-
options.forEach(function (option, index) {
|
|
41
|
-
option_id_index_map[option.id] = index;
|
|
42
|
-
});
|
|
43
|
-
newSort.option_id_index_map = option_id_index_map;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
cleanSorts.push(newSort);
|
|
48
|
-
});
|
|
49
|
-
return cleanSorts;
|
|
50
|
-
};
|
|
51
|
-
var sortRowsWithMultiSorts = function sortRowsWithMultiSorts(sortRows, sorts, _ref) {
|
|
52
|
-
var _ref$formulaRows = _ref.formulaRows,
|
|
53
|
-
formulaRows = _ref$formulaRows === void 0 ? {} : _ref$formulaRows,
|
|
54
|
-
value = _ref.value;
|
|
55
|
-
sortRows.sort(function (currentRow, nextRow) {
|
|
56
|
-
var initValue = 0;
|
|
57
|
-
sorts.forEach(function (sort) {
|
|
58
|
-
var column_key = sort.column_key,
|
|
59
|
-
sort_type = sort.sort_type,
|
|
60
|
-
column = sort.column;
|
|
61
|
-
var columnType = column.type,
|
|
62
|
-
columnData = column.data;
|
|
63
|
-
var currCellVal = currentRow[column_key];
|
|
64
|
-
var nextCellVal = nextRow[column_key];
|
|
65
|
-
if (DATE_COLUMN_OPTIONS.includes(columnType)) {
|
|
66
|
-
initValue = initValue || sortDate(currCellVal, nextCellVal, sort_type);
|
|
67
|
-
} else if (columnType === CellType.SINGLE_SELECT) {
|
|
68
|
-
initValue = initValue || sortSingleSelect(currCellVal, nextCellVal, sort);
|
|
69
|
-
} else if (NUMBER_SORTER_COLUMN_TYPES.includes(columnType)) {
|
|
70
|
-
initValue = initValue || sortNumber(currCellVal, nextCellVal, sort_type);
|
|
71
|
-
} else if (FORMULA_COLUMN_TYPES_MAP[columnType]) {
|
|
72
|
-
var currentFormulaRow = formulaRows[currentRow._id] || {};
|
|
73
|
-
var nextFormulaRow = formulaRows[nextRow._id] || {};
|
|
74
|
-
currCellVal = currentFormulaRow[column_key];
|
|
75
|
-
nextCellVal = nextFormulaRow[column_key];
|
|
76
|
-
initValue = initValue || sortFormula(currCellVal, nextCellVal, sort_type, {
|
|
77
|
-
columnData: columnData,
|
|
78
|
-
value: value
|
|
79
|
-
});
|
|
80
|
-
} else if (columnType === CellType.COLLABORATOR) {
|
|
81
|
-
var collaborators = value.collaborators;
|
|
82
|
-
var currValidCollaborators = currCellVal;
|
|
83
|
-
var nextValidCollaborators = nextCellVal;
|
|
84
|
-
if (collaborators) {
|
|
85
|
-
currValidCollaborators = getCollaboratorsNames(currCellVal, collaborators);
|
|
86
|
-
nextValidCollaborators = getCollaboratorsNames(nextCellVal, collaborators);
|
|
87
|
-
}
|
|
88
|
-
initValue = initValue || sortCollaborator(currValidCollaborators, nextValidCollaborators, sort_type);
|
|
89
|
-
} else if (columnType === CellType.CHECKBOX) {
|
|
90
|
-
initValue = initValue || sortCheckbox(currCellVal, nextCellVal, sort_type);
|
|
91
|
-
} else if (columnType === CellType.MULTIPLE_SELECT) {
|
|
92
|
-
initValue = initValue || sortMultipleSelect(currCellVal, nextCellVal, sort);
|
|
93
|
-
} else if (columnType === CellType.LINK) {
|
|
94
|
-
var _currentFormulaRow = formulaRows[currentRow._id] || {};
|
|
95
|
-
var _nextFormulaRow = formulaRows[nextRow._id] || {};
|
|
96
|
-
currCellVal = _currentFormulaRow[column_key];
|
|
97
|
-
nextCellVal = _nextFormulaRow[column_key];
|
|
98
|
-
initValue = initValue || sortLink(currCellVal, nextCellVal, sort_type, {
|
|
99
|
-
columnData: columnData,
|
|
100
|
-
value: value
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
initValue = initValue || sortText(currCellVal, nextCellVal, sort_type);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
return initValue;
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
var sortTableRows = function sortTableRows(sorts, rows, columns) {
|
|
110
|
-
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
111
|
-
formulaRows = _ref2.formulaRows,
|
|
112
|
-
value = _ref2.value;
|
|
113
|
-
if (!Array.isArray(rows)) return [];
|
|
114
|
-
var sortRows = rows.slice(0);
|
|
115
|
-
var validSorts = deleteInvalidSort(sorts, columns);
|
|
116
|
-
var normalizedFormulaRows = formulaRows || {};
|
|
117
|
-
sortRowsWithMultiSorts(sortRows, validSorts, {
|
|
118
|
-
formulaRows: normalizedFormulaRows,
|
|
119
|
-
value: value
|
|
120
|
-
});
|
|
121
|
-
return sortRows.map(function (row) {
|
|
122
|
-
return row._id;
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export { deleteInvalidSort, sortRowsWithMultiSorts, sortTableRows };
|
package/es/table/column.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* get column by key from table
|
|
3
|
-
* @param {object} table
|
|
4
|
-
* @param {string} columnKey
|
|
5
|
-
* @returns column, object
|
|
6
|
-
*/
|
|
7
|
-
var getTableColumnByKey = function getTableColumnByKey(table, columnKey) {
|
|
8
|
-
if (!table || !Array.isArray(table.columns) || !columnKey) return null;
|
|
9
|
-
return table.columns.find(function (column) {
|
|
10
|
-
return column.key === columnKey;
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* get column by name from table
|
|
16
|
-
* @param {object} table
|
|
17
|
-
* @param {string} columnName
|
|
18
|
-
* @returns column, object
|
|
19
|
-
*/
|
|
20
|
-
var getTableColumnByName = function getTableColumnByName(table, columnName) {
|
|
21
|
-
if (!table || !Array.isArray(table.columns) || !columnName) return null;
|
|
22
|
-
return table.columns.find(function (column) {
|
|
23
|
-
return column.name === columnName;
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { getTableColumnByKey, getTableColumnByName };
|
package/es/table/core.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* get table by id
|
|
3
|
-
* @param {array} tables
|
|
4
|
-
* @param {string} tableId
|
|
5
|
-
* @returns object
|
|
6
|
-
*/
|
|
7
|
-
var getTableById = function getTableById(tables, tableId) {
|
|
8
|
-
if (!Array.isArray(tables) || !tableId) return null;
|
|
9
|
-
return tables.find(function (table) {
|
|
10
|
-
return table._id === tableId;
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { getTableById };
|
package/es/table/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* get table by id
|
|
3
|
-
* @param {array} tables
|
|
4
|
-
* @param {string} tableId
|
|
5
|
-
* @returns table, object
|
|
6
|
-
*/
|
|
7
|
-
var getTableById = function getTableById(tables, tableId) {
|
|
8
|
-
if (!Array.isArray(tables) || !tableId) return null;
|
|
9
|
-
return tables.find(function (table) {
|
|
10
|
-
return table._id === tableId;
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { getTableById };
|
package/es/table/row.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* get row by id from table
|
|
3
|
-
* @param {object} table
|
|
4
|
-
* @param {string} rowId the id of row
|
|
5
|
-
* @returns object
|
|
6
|
-
*/
|
|
7
|
-
var getRowById = function getRowById(table, rowId) {
|
|
8
|
-
if (!table || !table.id_row_map || !rowId) return null;
|
|
9
|
-
return table.id_row_map[rowId];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* get rows by ids from table
|
|
14
|
-
* @param {object} table { id_row_map, ... }
|
|
15
|
-
* @param {array} rowsIds [ row._id, ... ]
|
|
16
|
-
* @returns array, rows: [ row, ... ]
|
|
17
|
-
*/
|
|
18
|
-
var getRowsByIds = function getRowsByIds(table, rowsIds) {
|
|
19
|
-
if (!table || !table.id_row_map || !Array.isArray(rowsIds)) return [];
|
|
20
|
-
return rowsIds.map(function (rowId) {
|
|
21
|
-
return table.id_row_map[rowId];
|
|
22
|
-
}).filter(Boolean);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export { getRowById, getRowsByIds };
|
package/es/view/core.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { getValidFilters, getValidFiltersWithoutError } from '../filter/core.js';
|
|
2
|
-
import { getValidGroupbys } from '../group/core.js';
|
|
3
|
-
import { getValidSorts } from '../sort/core.js';
|
|
4
|
-
import { CellType } from '../constants/cell-type.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* get view by id
|
|
8
|
-
* @param {array} views { _id: '', ... }
|
|
9
|
-
* @param {string} viewId
|
|
10
|
-
* @returns object
|
|
11
|
-
*/
|
|
12
|
-
var getViewById = function getViewById(views, viewId) {
|
|
13
|
-
if (!Array.isArray(views) || !viewId) return null;
|
|
14
|
-
return views.find(function (view) {
|
|
15
|
-
return view._id === viewId;
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* check whether the view contains filters
|
|
21
|
-
* @param {object} view { filters: [], ... }
|
|
22
|
-
* @param {array} columns
|
|
23
|
-
* @returns boolean
|
|
24
|
-
*/
|
|
25
|
-
var isFilterView = function isFilterView(view, columns) {
|
|
26
|
-
var validFilters = getValidFilters(view.filters, columns);
|
|
27
|
-
return validFilters.length > 0;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* check whether the view contains groupbys
|
|
32
|
-
* @param {object} view { groupbys: [], ... }
|
|
33
|
-
* @param {array} columns
|
|
34
|
-
* @returns boolean
|
|
35
|
-
*/
|
|
36
|
-
var isGroupView = function isGroupView(view, columns) {
|
|
37
|
-
var validGroupbys = getValidGroupbys(view.groupbys, columns);
|
|
38
|
-
return validGroupbys.length > 0;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* check whether the view contains sorts
|
|
43
|
-
* @param {object} view { sorts: [], ... }
|
|
44
|
-
* @param {array} columns
|
|
45
|
-
* @returns boolean
|
|
46
|
-
*/
|
|
47
|
-
var isSortView = function isSortView(view, columns) {
|
|
48
|
-
var sorts = view.sorts;
|
|
49
|
-
var validSorts = getValidSorts(sorts, columns);
|
|
50
|
-
return validSorts.length > 0;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* check is default view which no contains filters, sorts, groupbys etc.
|
|
55
|
-
* @param {object} view { sorts: [], ... }
|
|
56
|
-
* @param {array} columns
|
|
57
|
-
* @returns boolean
|
|
58
|
-
*/
|
|
59
|
-
var isDefaultView = function isDefaultView(view, columns) {
|
|
60
|
-
return !isFilterView(view, columns) && !isSortView(view, columns) && !isGroupView(view, columns);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* get link columns which used either in filters, groupbys, sorts etc.
|
|
65
|
-
* @param {object} view { filters, groupbys, sorts, ... }
|
|
66
|
-
* @param {object} table
|
|
67
|
-
* @returns array, link columns
|
|
68
|
-
*/
|
|
69
|
-
var getLinkColumnsUsedInFilters = function getLinkColumnsUsedInFilters(view, table) {
|
|
70
|
-
var filters = view.filters,
|
|
71
|
-
sorts = view.sorts,
|
|
72
|
-
groupbys = view.groupbys;
|
|
73
|
-
var columns = table.columns;
|
|
74
|
-
if (!Array.isArray(columns)) return [];
|
|
75
|
-
var validFilters = getValidFiltersWithoutError(filters, columns);
|
|
76
|
-
var validSorts = getValidSorts(sorts, columns);
|
|
77
|
-
var validGroupbys = getValidGroupbys(groupbys, columns);
|
|
78
|
-
var hasFilters = validFilters && validFilters.length > 0;
|
|
79
|
-
var hasSorts = validSorts && validSorts.length > 0;
|
|
80
|
-
var hasGroupbys = validGroupbys && validGroupbys.length > 0;
|
|
81
|
-
if (!hasFilters && !hasSorts && !hasGroupbys) return [];
|
|
82
|
-
var keyLinkColumnMap = {};
|
|
83
|
-
var keyExistLinkColumnMap = {};
|
|
84
|
-
var linkColumns = [];
|
|
85
|
-
columns.forEach(function (column) {
|
|
86
|
-
var key = column.key,
|
|
87
|
-
name = column.name,
|
|
88
|
-
type = column.type,
|
|
89
|
-
data = column.data,
|
|
90
|
-
width = column.width;
|
|
91
|
-
if (type === CellType.LINK) {
|
|
92
|
-
keyLinkColumnMap[column.key] = {
|
|
93
|
-
key: key,
|
|
94
|
-
name: name,
|
|
95
|
-
type: type,
|
|
96
|
-
data: data,
|
|
97
|
-
width: width
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
if (Object.keys(keyLinkColumnMap).length === 0) return [];
|
|
102
|
-
if (hasFilters) {
|
|
103
|
-
validFilters.forEach(function (filter) {
|
|
104
|
-
var filterColumnKey = filter.column_key;
|
|
105
|
-
var filterLinkColumn = keyLinkColumnMap[filterColumnKey];
|
|
106
|
-
if (filterLinkColumn && !keyExistLinkColumnMap[filterColumnKey]) {
|
|
107
|
-
linkColumns.push(filterLinkColumn);
|
|
108
|
-
keyExistLinkColumnMap[filterColumnKey] = true;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (hasSorts) {
|
|
113
|
-
validSorts.forEach(function (sort) {
|
|
114
|
-
var sortColumnKey = sort.column_key;
|
|
115
|
-
var sortLinkColumn = keyLinkColumnMap[sortColumnKey];
|
|
116
|
-
if (sortLinkColumn && !keyExistLinkColumnMap[sortColumnKey]) {
|
|
117
|
-
linkColumns.push(sortLinkColumn);
|
|
118
|
-
keyExistLinkColumnMap[sortColumnKey] = true;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
if (hasGroupbys) {
|
|
123
|
-
validGroupbys.forEach(function (groupby) {
|
|
124
|
-
var groupbyColumnKey = groupby.column_key;
|
|
125
|
-
var groupbyLinkColumn = keyLinkColumnMap[groupbyColumnKey];
|
|
126
|
-
if (groupbyLinkColumn && !keyExistLinkColumnMap[groupbyColumnKey]) {
|
|
127
|
-
linkColumns.push(groupbyLinkColumn);
|
|
128
|
-
keyExistLinkColumnMap[groupbyColumnKey] = true;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
return linkColumns;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export { getLinkColumnsUsedInFilters, getViewById, isDefaultView, isFilterView, isGroupView, isSortView };
|
package/es/view/formula.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { CellType } from '../constants/cell-type.js';
|
|
2
|
-
import { FORMULA_COLUMN_TYPES_MAP } from '../constants/formula.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* transform the formats of link column to link-formula's
|
|
6
|
-
* @param {object} linkColumn { key, data: { display_column_key, ... }, ... }
|
|
7
|
-
* @returns object
|
|
8
|
-
*/
|
|
9
|
-
var transLink2LinkFormula = function transLink2LinkFormula(linkColumn) {
|
|
10
|
-
var key = linkColumn.key,
|
|
11
|
-
name = linkColumn.name,
|
|
12
|
-
data = linkColumn.data;
|
|
13
|
-
var display_column_key = data.display_column_key;
|
|
14
|
-
return {
|
|
15
|
-
key: key,
|
|
16
|
-
name: name,
|
|
17
|
-
type: CellType.LINK_FORMULA,
|
|
18
|
-
data: {
|
|
19
|
-
formula: 'lookup',
|
|
20
|
-
link_column_key: key,
|
|
21
|
-
level1_linked_table_column_key: display_column_key,
|
|
22
|
-
level2_linked_table_column_key: null,
|
|
23
|
-
operated_columns: []
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* get sorted formula columns
|
|
30
|
-
* @param {array} formulaColumns
|
|
31
|
-
* @param {object} table
|
|
32
|
-
* @returns array
|
|
33
|
-
*/
|
|
34
|
-
var getSortedFormulaColumns = function getSortedFormulaColumns(formulaColumns, table) {
|
|
35
|
-
if (!Array.isArray(formulaColumns) || !table || !Array.isArray(table.columns)) return [];
|
|
36
|
-
var keyColumnMap = {};
|
|
37
|
-
table.columns.forEach(function (column) {
|
|
38
|
-
var key = column.key,
|
|
39
|
-
type = column.type;
|
|
40
|
-
if (FORMULA_COLUMN_TYPES_MAP[type]) {
|
|
41
|
-
keyColumnMap[key] = column;
|
|
42
|
-
} else if (type === CellType.LINK && column.data) {
|
|
43
|
-
keyColumnMap[key] = transLink2LinkFormula(column);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// get none-repeating formulas
|
|
48
|
-
var key_sorting_formula_column = {};
|
|
49
|
-
var sorting_formula_column_keys = [];
|
|
50
|
-
formulaColumns.forEach(function (column) {
|
|
51
|
-
var columnKey = column.key;
|
|
52
|
-
if (!key_sorting_formula_column[columnKey]) {
|
|
53
|
-
key_sorting_formula_column[columnKey] = column;
|
|
54
|
-
sorting_formula_column_keys.push(columnKey);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* e.g. formula1 = formula2 + formula3
|
|
60
|
-
* e.g. formula2 = 1 + 2
|
|
61
|
-
* e.g. formula3 = formula2 + 3
|
|
62
|
-
* edges: formula2 --> formula1, formula2 --> formula3; formula3 --> formula1
|
|
63
|
-
* keyInDegreeMap, the total number of formula columns that depend on: { formula1_key: 2, formula2_key: 0, formula3_key: 1 }
|
|
64
|
-
* keyEdgesMap: { formula2_key: [formula1_key, formula3_key], formula3_kye: [formula1_key]}
|
|
65
|
-
*/
|
|
66
|
-
var keyInDegreeMap = {};
|
|
67
|
-
var keyEdgesMap = {};
|
|
68
|
-
sorting_formula_column_keys.forEach(function (formulaColumnKey) {
|
|
69
|
-
var formulaColumn = key_sorting_formula_column[formulaColumnKey];
|
|
70
|
-
var data = formulaColumn.data;
|
|
71
|
-
var operated_columns = data.operated_columns;
|
|
72
|
-
keyInDegreeMap[formulaColumnKey] = 0;
|
|
73
|
-
Array.isArray(operated_columns) && operated_columns.forEach(function (dependColumnKey) {
|
|
74
|
-
var dependColumn = keyColumnMap[dependColumnKey];
|
|
75
|
-
if (!dependColumn) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
keyInDegreeMap[formulaColumnKey]++;
|
|
79
|
-
if (keyEdgesMap[dependColumnKey]) {
|
|
80
|
-
keyEdgesMap[dependColumnKey].push(formulaColumnKey);
|
|
81
|
-
} else {
|
|
82
|
-
keyEdgesMap[dependColumnKey] = [formulaColumnKey];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
var sortedList = [];
|
|
87
|
-
var waitingQueue = [];
|
|
88
|
-
sorting_formula_column_keys.forEach(function (formulaColumnKey) {
|
|
89
|
-
if (keyInDegreeMap[formulaColumnKey] === 0) {
|
|
90
|
-
waitingQueue.push(formulaColumnKey);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
while (waitingQueue.length) {
|
|
94
|
-
var columnKey = waitingQueue.shift();
|
|
95
|
-
var edges = keyEdgesMap[columnKey];
|
|
96
|
-
sortedList.push(columnKey);
|
|
97
|
-
Array.isArray(edges) && edges.forEach(function (edge) {
|
|
98
|
-
keyInDegreeMap[edge]--;
|
|
99
|
-
if (keyInDegreeMap[edge] === 0) {
|
|
100
|
-
waitingQueue.push(edge);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return sortedList.map(function (columnKey) {
|
|
105
|
-
return keyColumnMap[columnKey];
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* get formula columns and link columns from table
|
|
111
|
-
* @param {object} table { columns: [], ... }
|
|
112
|
-
* @returns array
|
|
113
|
-
*/
|
|
114
|
-
var getFormulaColumnsContainLinks = function getFormulaColumnsContainLinks(table) {
|
|
115
|
-
var columns = table.columns;
|
|
116
|
-
var formulaColumns = columns.filter(function (column) {
|
|
117
|
-
var type = column.type,
|
|
118
|
-
data = column.data;
|
|
119
|
-
if (type === CellType.LINK) {
|
|
120
|
-
return !!data;
|
|
121
|
-
}
|
|
122
|
-
return FORMULA_COLUMN_TYPES_MAP[type] && data;
|
|
123
|
-
});
|
|
124
|
-
return formulaColumns.map(function (column) {
|
|
125
|
-
if (column.type === CellType.LINK) {
|
|
126
|
-
return transLink2LinkFormula(column);
|
|
127
|
-
}
|
|
128
|
-
return column;
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* get sorted formula columns and link columns from table
|
|
134
|
-
* @param {object} table { columns: [], ... }
|
|
135
|
-
* @returns array
|
|
136
|
-
*/
|
|
137
|
-
var getSortedFormulaColumnsContainLinks = function getSortedFormulaColumnsContainLinks(table) {
|
|
138
|
-
var formulaColumns = getFormulaColumnsContainLinks(table);
|
|
139
|
-
if (formulaColumns.length === 0) return [];
|
|
140
|
-
return getSortedFormulaColumns(formulaColumns, table);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export { getFormulaColumnsContainLinks, getSortedFormulaColumns, getSortedFormulaColumnsContainLinks, transLink2LinkFormula };
|
package/es/view/group.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* get group by paths.
|
|
3
|
-
* @param {array} paths e.g. [0, 1, 2]
|
|
4
|
-
* @param {array} groups
|
|
5
|
-
* @returns object
|
|
6
|
-
*/
|
|
7
|
-
var getGroupByPath = function getGroupByPath(paths, groups) {
|
|
8
|
-
if (!Array.isArray(paths) || !Array.isArray(groups)) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
var level0GroupIndex = paths[0];
|
|
12
|
-
if (level0GroupIndex < 0 || level0GroupIndex >= groups.length) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
var level = 1;
|
|
16
|
-
var foundGroup = groups[level0GroupIndex];
|
|
17
|
-
while (level < paths.length) {
|
|
18
|
-
if (!foundGroup) {
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
var subGroups = foundGroup.subgroups;
|
|
22
|
-
var currentLevelGroupIndex = paths[level];
|
|
23
|
-
if (!Array.isArray(subGroups) || currentLevelGroupIndex < 0 || currentLevelGroupIndex >= subGroups.length) {
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
foundGroup = subGroups[currentLevelGroupIndex];
|
|
27
|
-
level += 1;
|
|
28
|
-
}
|
|
29
|
-
return foundGroup;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { getGroupByPath };
|