dtable-utils 0.0.2 → 0.0.3-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 +30 -2
- package/dist/index.js +1 -1
- package/es/cell-value-get/cell-value.js +227 -19
- package/es/cell-value-get/collaborator.js +9 -3
- package/es/cell-value-get/digital-sign.js +1 -1
- package/es/cell-value-get/geolocation.js +29 -5
- package/es/cell-value-get/long-text.js +1 -1
- package/es/cell-value-get/number.js +42 -18
- package/es/cell-value-get/option.js +17 -7
- package/es/cell-value-get/rate.js +6 -0
- package/es/cell-value-set/date.js +20 -0
- package/es/cell-value-set/number.js +53 -1
- package/es/color/gradient-color.js +100 -0
- package/es/column/color.js +415 -0
- package/es/column/{common.js → core.js} +3 -15
- package/es/column/date.js +2 -3
- package/es/column/number.js +3 -5
- package/es/column/option.js +115 -0
- package/es/common.js +10 -1
- 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/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 +287 -0
- package/es/filter/filter-column/array.js +82 -0
- package/es/filter/filter-column/checkbox.js +8 -0
- package/es/filter/filter-column/collaborator.js +67 -0
- package/es/filter/filter-column/creator.js +50 -0
- package/es/filter/filter-column/date.js +59 -0
- package/es/filter/filter-column/digital-sign.js +26 -0
- package/es/filter/filter-column/file.js +24 -0
- package/es/filter/filter-column/formula.js +49 -0
- package/es/filter/filter-column/geolocation.js +53 -0
- package/es/filter/filter-column/link.js +12 -0
- package/es/filter/filter-column/long-text.js +25 -0
- package/es/filter/filter-column/multiple-select.js +60 -0
- package/es/filter/filter-column/number.js +93 -0
- package/es/filter/filter-column/single-select.js +41 -0
- package/es/filter/filter-column/text.js +55 -0
- package/es/filter/filter-row.js +198 -0
- package/es/group/core.js +107 -0
- package/es/group/group-row.js +366 -0
- package/es/index.js +62 -10
- package/es/link/core.js +78 -0
- package/es/number.js +13 -0
- package/es/row/color.js +278 -0
- package/es/row/core.js +161 -0
- package/es/sort/core.js +32 -0
- package/es/sort/sort-column/array.js +63 -0
- package/es/sort/sort-column/checkbox.js +15 -0
- package/es/sort/sort-column/collaborator.js +9 -0
- package/es/sort/sort-column/date.js +25 -0
- package/es/sort/sort-column/formula.js +40 -0
- package/es/sort/sort-column/link.js +23 -0
- package/es/sort/sort-column/multiple-select.js +45 -0
- package/es/sort/sort-column/number.js +18 -0
- package/es/sort/sort-column/single-select.js +22 -0
- package/es/sort/sort-column/text.js +47 -0
- package/es/sort/sort-row.js +126 -0
- package/es/table/column.js +27 -0
- package/es/table/core.js +14 -0
- package/es/table/index.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 +135 -0
- package/es/view/formula.js +143 -0
- package/es/view/group.js +32 -0
- package/es/view/summaries.js +179 -0
- package/lib/cell-value-get/cell-value.js +231 -18
- package/lib/cell-value-get/collaborator.js +9 -2
- package/lib/cell-value-get/digital-sign.js +1 -1
- package/lib/cell-value-get/geolocation.js +30 -5
- package/lib/cell-value-get/long-text.js +1 -1
- package/lib/cell-value-get/number.js +42 -17
- package/lib/cell-value-get/option.js +18 -6
- package/lib/cell-value-get/rate.js +10 -0
- package/lib/cell-value-set/date.js +24 -0
- package/lib/cell-value-set/number.js +53 -0
- package/lib/color/gradient-color.js +110 -0
- package/lib/column/color.js +424 -0
- package/lib/column/{common.js → core.js} +3 -16
- package/lib/column/date.js +2 -3
- package/lib/column/number.js +3 -5
- package/lib/column/option.js +123 -0
- package/lib/common.js +14 -0
- 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/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 +301 -0
- package/lib/filter/filter-column/array.js +86 -0
- package/lib/filter/filter-column/checkbox.js +12 -0
- package/lib/filter/filter-column/collaborator.js +75 -0
- package/lib/filter/filter-column/creator.js +54 -0
- package/lib/filter/filter-column/date.js +63 -0
- package/lib/filter/filter-column/digital-sign.js +30 -0
- package/lib/filter/filter-column/file.js +28 -0
- package/lib/filter/filter-column/formula.js +53 -0
- package/lib/filter/filter-column/geolocation.js +57 -0
- package/lib/filter/filter-column/link.js +16 -0
- package/lib/filter/filter-column/long-text.js +29 -0
- package/lib/filter/filter-column/multiple-select.js +68 -0
- package/lib/filter/filter-column/number.js +97 -0
- package/lib/filter/filter-column/single-select.js +45 -0
- package/lib/filter/filter-column/text.js +59 -0
- package/lib/filter/filter-row.js +204 -0
- package/lib/group/core.js +117 -0
- package/lib/group/group-row.js +377 -0
- package/lib/index.js +176 -6
- package/lib/link/core.js +90 -0
- package/lib/number.js +18 -0
- package/lib/row/color.js +286 -0
- package/lib/row/core.js +170 -0
- package/lib/sort/core.js +37 -0
- package/lib/sort/sort-column/array.js +67 -0
- package/lib/sort/sort-column/checkbox.js +19 -0
- package/lib/sort/sort-column/collaborator.js +13 -0
- package/lib/sort/sort-column/date.js +29 -0
- package/lib/sort/sort-column/formula.js +44 -0
- package/lib/sort/sort-column/link.js +27 -0
- package/lib/sort/sort-column/multiple-select.js +50 -0
- package/lib/sort/sort-column/number.js +22 -0
- package/lib/sort/sort-column/single-select.js +26 -0
- package/lib/sort/sort-column/text.js +52 -0
- package/lib/sort/sort-row.js +136 -0
- package/lib/table/column.js +32 -0
- package/lib/table/core.js +18 -0
- package/lib/table/index.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 +144 -0
- package/lib/view/formula.js +150 -0
- package/lib/view/group.js +36 -0
- package/lib/view/summaries.js +185 -0
- package/package.json +4 -2
|
@@ -0,0 +1,63 @@
|
|
|
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 };
|
|
@@ -0,0 +1,15 @@
|
|
|
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 };
|
|
@@ -0,0 +1,9 @@
|
|
|
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 };
|
|
@@ -0,0 +1,25 @@
|
|
|
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 };
|
|
@@ -0,0 +1,40 @@
|
|
|
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 };
|
|
@@ -0,0 +1,23 @@
|
|
|
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 };
|
|
@@ -0,0 +1,45 @@
|
|
|
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 };
|
|
@@ -0,0 +1,18 @@
|
|
|
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 };
|
|
@@ -0,0 +1,22 @@
|
|
|
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 };
|
|
@@ -0,0 +1,47 @@
|
|
|
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 };
|
|
@@ -0,0 +1,126 @@
|
|
|
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 };
|
|
@@ -0,0 +1,27 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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 };
|
|
@@ -0,0 +1,14 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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/validate/filter.js
CHANGED
|
@@ -5,7 +5,7 @@ import { CellType } from '../constants/cell-type.js';
|
|
|
5
5
|
import { COLLABORATOR_COLUMN_TYPES } from '../constants/column.js';
|
|
6
6
|
import { FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE } from '../constants/formula.js';
|
|
7
7
|
import { FILTER_ERR_MSG } from '../constants/filter/index.js';
|
|
8
|
-
import { getColumnOptions } from '../column/
|
|
8
|
+
import { getColumnOptions } from '../column/option.js';
|
|
9
9
|
import { isDateColumn } from '../column/date.js';
|
|
10
10
|
import { FILTER_PREDICATE_TYPE } from '../constants/filter/filter-predicate.js';
|
|
11
11
|
import { FILTER_TERM_MODIFIER_TYPE } from '../constants/filter/filter-modifier.js';
|