dtable-utils 0.0.3-beta.1 → 0.0.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +12 -3
  2. package/dist/index.js +1 -1
  3. package/es/cell-value-get/cell-value.js +82 -60
  4. package/es/cell-value-get/collaborator.js +9 -2
  5. package/es/cell-value-get/duration.js +3 -3
  6. package/es/cell-value-get/geolocation.js +23 -25
  7. package/es/cell-value-get/number.js +19 -11
  8. package/es/cell-value-get/option.js +18 -4
  9. package/es/cell-value-get/rate.js +5 -0
  10. package/es/cell-value-set/date.js +9 -3
  11. package/es/{column/color.js → color/column-color.js} +25 -3
  12. package/es/{row/color.js → color/row-color.js} +12 -1
  13. package/es/column/option.js +37 -7
  14. package/es/common.js +23 -2
  15. package/es/constants/formula.js +2 -1
  16. package/es/filter/core.js +61 -26
  17. package/es/filter/filter-column/array.js +35 -30
  18. package/es/filter/filter-column/checkbox.js +9 -3
  19. package/es/filter/filter-column/collaborator.js +20 -15
  20. package/es/filter/filter-column/creator.js +22 -13
  21. package/es/filter/filter-column/date.js +57 -14
  22. package/es/filter/filter-column/digital-sign.js +11 -8
  23. package/es/filter/filter-column/file.js +9 -6
  24. package/es/filter/filter-column/formula.js +16 -8
  25. package/es/filter/filter-column/geolocation.js +12 -7
  26. package/es/filter/filter-column/link.js +10 -2
  27. package/es/filter/filter-column/long-text.js +10 -7
  28. package/es/filter/filter-column/multiple-select.js +17 -13
  29. package/es/filter/filter-column/number.js +25 -21
  30. package/es/filter/filter-column/single-select.js +14 -10
  31. package/es/filter/filter-column/text.js +18 -13
  32. package/es/filter/filter-row.js +35 -0
  33. package/es/group/core.js +15 -6
  34. package/es/group/group-row.js +39 -3
  35. package/es/index.js +10 -10
  36. package/es/link/core.js +14 -14
  37. package/es/number.js +11 -3
  38. package/es/row/core.js +20 -1
  39. package/es/sort/core.js +66 -7
  40. package/es/sort/sort-column/array.js +39 -30
  41. package/es/sort/sort-column/checkbox.js +12 -5
  42. package/es/sort/sort-column/collaborator.js +11 -4
  43. package/es/sort/sort-column/date.js +12 -12
  44. package/es/sort/sort-column/formula.js +21 -12
  45. package/es/sort/sort-column/link.js +18 -9
  46. package/es/sort/sort-column/multiple-select.js +26 -26
  47. package/es/sort/sort-column/number.js +15 -8
  48. package/es/sort/sort-column/single-select.js +16 -8
  49. package/es/sort/sort-column/text.js +24 -10
  50. package/es/sort/sort-row.js +22 -38
  51. package/es/table/column.js +2 -2
  52. package/es/table/core.js +2 -2
  53. package/es/table/row.js +4 -4
  54. package/es/view/core.js +20 -21
  55. package/es/view/formula.js +35 -31
  56. package/es/view/group.js +4 -4
  57. package/es/view/summaries.js +17 -29
  58. package/lib/cell-value-get/cell-value.js +82 -60
  59. package/lib/cell-value-get/collaborator.js +9 -2
  60. package/lib/cell-value-get/duration.js +4 -2
  61. package/lib/cell-value-get/geolocation.js +23 -25
  62. package/lib/cell-value-get/number.js +19 -11
  63. package/lib/cell-value-get/option.js +18 -4
  64. package/lib/cell-value-get/rate.js +5 -0
  65. package/lib/cell-value-set/date.js +9 -3
  66. package/lib/{column/color.js → color/column-color.js} +31 -9
  67. package/lib/{row/color.js → color/row-color.js} +12 -1
  68. package/lib/column/option.js +37 -7
  69. package/lib/common.js +23 -1
  70. package/lib/constants/formula.js +2 -0
  71. package/lib/filter/core.js +61 -26
  72. package/lib/filter/filter-column/array.js +35 -30
  73. package/lib/filter/filter-column/checkbox.js +9 -3
  74. package/lib/filter/filter-column/collaborator.js +20 -15
  75. package/lib/filter/filter-column/creator.js +22 -13
  76. package/lib/filter/filter-column/date.js +57 -14
  77. package/lib/filter/filter-column/digital-sign.js +11 -8
  78. package/lib/filter/filter-column/file.js +9 -6
  79. package/lib/filter/filter-column/formula.js +16 -8
  80. package/lib/filter/filter-column/geolocation.js +12 -7
  81. package/lib/filter/filter-column/link.js +10 -2
  82. package/lib/filter/filter-column/long-text.js +10 -7
  83. package/lib/filter/filter-column/multiple-select.js +17 -13
  84. package/lib/filter/filter-column/number.js +25 -21
  85. package/lib/filter/filter-column/single-select.js +14 -10
  86. package/lib/filter/filter-column/text.js +18 -13
  87. package/lib/filter/filter-row.js +35 -0
  88. package/lib/group/core.js +15 -6
  89. package/lib/group/group-row.js +39 -3
  90. package/lib/index.js +47 -45
  91. package/lib/link/core.js +14 -14
  92. package/lib/number.js +11 -3
  93. package/lib/row/core.js +20 -1
  94. package/lib/sort/core.js +71 -6
  95. package/lib/sort/sort-column/array.js +39 -30
  96. package/lib/sort/sort-column/checkbox.js +12 -5
  97. package/lib/sort/sort-column/collaborator.js +11 -4
  98. package/lib/sort/sort-column/date.js +12 -12
  99. package/lib/sort/sort-column/formula.js +21 -12
  100. package/lib/sort/sort-column/link.js +18 -9
  101. package/lib/sort/sort-column/multiple-select.js +25 -26
  102. package/lib/sort/sort-column/number.js +15 -8
  103. package/lib/sort/sort-column/single-select.js +16 -8
  104. package/lib/sort/sort-column/text.js +24 -10
  105. package/lib/sort/sort-row.js +21 -42
  106. package/lib/table/column.js +2 -2
  107. package/lib/table/core.js +2 -2
  108. package/lib/table/row.js +4 -4
  109. package/lib/view/core.js +20 -21
  110. package/lib/view/formula.js +35 -31
  111. package/lib/view/group.js +4 -4
  112. package/lib/view/summaries.js +17 -29
  113. package/package.json +1 -1
  114. package/es/table/index.js +0 -14
  115. package/lib/table/index.js +0 -18
package/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { CellType } from './constants/cell-type.js';
2
2
  export { COLLABORATOR_COLUMN_TYPES, COLUMNS_ICON_CONFIG, COLUMN_OPTIONS, DATE_COLUMN_OPTIONS, DATE_DEFAULT_TYPES, DATE_FORMAT_MAP, DATE_UNIT, DEFAULT_DATE_FORMAT, DEFAULT_NUMBER_FORMAT, DURATION_DECIMAL_DIGITS, DURATION_FORMATS, DURATION_FORMATS_MAP, DURATION_ZERO_DISPLAY, FILL_DEFAULT_VALUE_COLUMNS_TYPE, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, NOT_SUPPORT_EDIT_COLUMN_TYPE_MAP, NUMERIC_COLUMNS_TYPES, SINGLE_CELL_VALUE_COLUMN_TYPE_MAP, UTC_FORMAT_DEFAULT } from './constants/column.js';
3
3
  export { FILTER_CONJUNCTION_TYPE, FILTER_ERR_MSG } from './constants/filter/index.js';
4
- export { FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE } from './constants/formula.js';
4
+ export { DISPLAY_INTERNAL_ERRORS, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE } from './constants/formula.js';
5
5
  export { HIGHLIGHT_COLORS, SELECT_OPTION_COLORS } from './constants/select-option.js';
6
6
  export { NUMBER_SORTER_COLUMN_TYPES, SORT_COLUMN_OPTIONS, SORT_TYPE, TEXT_SORTER_COLUMN_TYPES } from './constants/sort.js';
7
7
  export { DISPLAY_GROUP_DATE_GRANULARITY, DISPLAY_GROUP_GEOLOCATION_GRANULARITY, GROUP_DATE_GRANULARITY, GROUP_GEOLOCATION_GRANULARITY, MAX_GROUP_LEVEL, SUPPORT_GROUP_COLUMN_TYPES } from './constants/group.js';
@@ -9,10 +9,11 @@ export { COLUMN_PERMISSION_TYPE } from './constants/column-permission.js';
9
9
  export { REG_NUMBER_DIGIT, REG_STRING_NUMBER_PARTS } from './constants/reg.js';
10
10
  export { COLOR_GRADATION_OPTIONS } from './constants/color.js';
11
11
  export { HEADER_HEIGHT_TYPE } from './constants/grid-header.js';
12
- export { generatorBase64Code, isEmpty } from './common.js';
13
- export { getTableById } from './table/index.js';
12
+ export { generatorBase64Code, isEmpty, isEmptyObject } from './common.js';
13
+ export { getTableById } from './table/core.js';
14
+ export { getTableColumnByKey, getTableColumnByName } from './table/column.js';
15
+ export { getRowById, getRowsByIds } from './table/row.js';
14
16
  export { convertRow, isTableRows } from './row/core.js';
15
- export { default as RowColorUtils } from './row/color.js';
16
17
  export { getLinkColumnsUsedInFilters, getViewById, isDefaultView, isFilterView, isGroupView, isSortView } from './view/core.js';
17
18
  export { getSummaries, getSummariesWithSubgroups, updateGroupSummaries } from './view/summaries.js';
18
19
  export { getFormulaColumnsContainLinks, getSortedFormulaColumns, getSortedFormulaColumnsContainLinks, transLink2LinkFormula } from './view/formula.js';
@@ -33,7 +34,6 @@ export { formatTextToDate } from './cell-value-set/date.js';
33
34
  export { createOption, generateOptionID, generatorCellOption, generatorCellOptions, getColumnOptions } from './column/option.js';
34
35
  export { isDateColumn } from './column/date.js';
35
36
  export { isNumberColumn, isNumericColumn } from './column/number.js';
36
- export { default as ColumnColorUtils } from './column/color.js';
37
37
  export { DateUtils } from './date.js';
38
38
  export { isNumber, isNumberEqual } from './number.js';
39
39
  export { ValidateFilter } from './validate/filter.js';
@@ -55,24 +55,24 @@ export { numberFilter } from './filter/filter-column/number.js';
55
55
  export { singleSelectFilter } from './filter/filter-column/single-select.js';
56
56
  export { linkFilter } from './filter/filter-column/link.js';
57
57
  export { filterRow, filterRows, getFilteredRowsWithoutFormulaCalculation } from './filter/filter-row.js';
58
- export { getValidSorts, isValidSort } from './sort/core.js';
58
+ export { deleteInvalidSort, getMultipleIndexesOrderbyOptions, getValidSorts, isValidSort } from './sort/core.js';
59
59
  export { sortCheckbox } from './sort/sort-column/checkbox.js';
60
60
  export { sortCollaborator } from './sort/sort-column/collaborator.js';
61
61
  export { sortDate } from './sort/sort-column/date.js';
62
62
  export { sortByArrayType } from './sort/sort-column/array.js';
63
63
  export { sortFormula } from './sort/sort-column/formula.js';
64
64
  export { sortLink } from './sort/sort-column/link.js';
65
- export { getMultipleIndexesOrderbyOptions, sortMultipleSelect } from './sort/sort-column/multiple-select.js';
65
+ export { sortMultipleSelect } from './sort/sort-column/multiple-select.js';
66
66
  export { sortNumber } from './sort/sort-column/number.js';
67
67
  export { sortSingleSelect } from './sort/sort-column/single-select.js';
68
68
  export { compareString, sortText } from './sort/sort-column/text.js';
69
- export { deleteInvalidSort, sortRowsWithMultiSorts, sortTableRows } from './sort/sort-row.js';
69
+ export { sortRowsWithMultiSorts, sortTableRows } from './sort/sort-row.js';
70
70
  export { deleteInvalidGroupby, getValidGroupbys, isValidGroupby } from './group/core.js';
71
71
  export { getGroupedRowsWithoutFormulaCalculation, groupTableRows, groupViewRows } from './group/group-row.js';
72
72
  export { default as GradientColorUtils } from './color/gradient-color.js';
73
+ export { default as ColumnColorUtils } from './color/column-color.js';
74
+ export { default as RowColorUtils } from './color/row-color.js';
73
75
  export { FILTER_COLUMN_OPTIONS } from './constants/filter/filter-column-options.js';
74
76
  export { FILTER_TERM_MODIFIER_SHOW, FILTER_TERM_MODIFIER_TYPE } from './constants/filter/filter-modifier.js';
75
77
  export { FILTER_PREDICATE_SHOW, FILTER_PREDICATE_TYPE } from './constants/filter/filter-predicate.js';
76
78
  export { filterTermModifierIsWithin, filterTermModifierNotWithin } from './constants/filter/filter-is-within.js';
77
- export { getTableColumnByKey, getTableColumnByName } from './table/column.js';
78
- export { getRowById, getRowsByIds } from './table/row.js';
package/es/link/core.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
2
 
3
3
  /**
4
- * get link by id
5
- * @param {array} links [{ _id, ... }]
4
+ * Get link by id
5
+ * @param {array} links e.g. [{ _id, ... }, ...]
6
6
  * @param {string} linkId
7
- * @returns object
7
+ * @returns link, object
8
8
  */
9
9
  var getLinkById = function getLinkById(links, linkId) {
10
10
  if (!Array.isArray(links) || !linkId) return null;
@@ -14,9 +14,9 @@ var getLinkById = function getLinkById(links, linkId) {
14
14
  };
15
15
 
16
16
  /**
17
- * check is valid link by link column's data
18
- * @param {object} columnData
19
- * @returns boolean
17
+ * Check is valid link
18
+ * @param {object} columnData
19
+ * @returns bool
20
20
  */
21
21
  var isValidLink = function isValidLink(linkColumnData) {
22
22
  if (!linkColumnData) return false;
@@ -28,35 +28,35 @@ var isValidLink = function isValidLink(linkColumnData) {
28
28
  };
29
29
 
30
30
  /**
31
- * get current table's id
31
+ * Get current table id by link relationship
32
32
  * @param {string} currentTableID
33
33
  * @param {string} tableID
34
34
  * @param {string} otherTableID
35
- * @returns string
35
+ * @returns current table id, string
36
36
  */
37
37
  var getLinkTableID = function getLinkTableID(currentTableID, tableID, otherTableID) {
38
38
  return currentTableID === tableID ? tableID : otherTableID;
39
39
  };
40
40
 
41
41
  /**
42
- * get linked table's id
42
+ * Get linked table id by link relationship
43
43
  * @param {string} currentTableID
44
44
  * @param {string} tableID
45
45
  * @param {string} otherTableID
46
- * @returns string
46
+ * @returns linked table id, string
47
47
  */
48
48
  var getLinkedTableID = function getLinkedTableID(currentTableID, tableID, otherTableID) {
49
49
  return currentTableID === tableID ? otherTableID : tableID;
50
50
  };
51
51
 
52
52
  /**
53
- * get linked rows ids of the row id
54
- * @param {array} links [ { _id: '', table1_id, table2_id: '', table1_table2_map: {}, table2_table1_map: {} }, ... ]
55
- * @param {string} link_id
53
+ * Get linked rows ids by the given row id
54
+ * @param {array} links e.g. [ { _id, table1_id, table2_id, table1_table2_map, table2_table1_map, ... }, ... ]
55
+ * @param {string} linkId
56
56
  * @param {string} table1Id
57
57
  * @param {string} table2Id
58
58
  * @param {string} rowId
59
- * @returns array, linked rows ids
59
+ * @returns linked rows ids, array
60
60
  */
61
61
  var getLinkCellValue = function getLinkCellValue(links, linkId, table1Id, table2Id, rowId) {
62
62
  if (!Array.isArray(links) || links.length === 0 || !table1Id || !table2Id || !rowId) return [];
package/es/number.js CHANGED
@@ -1,13 +1,21 @@
1
1
  /**
2
- * check whether is number
2
+ * Check whether is number
3
3
  * @param {number} number
4
4
  * @returns boolean
5
5
  */
6
6
  var isNumber = function isNumber(number) {
7
7
  return (number || number === 0) && Object.prototype.toString.call(number) === '[object Number]';
8
8
  };
9
- var isNumberEqual = function isNumberEqual(number1, number2) {
10
- return number1 === number2 || Math.abs(number1 - number2) < 0.00001;
9
+
10
+ /**
11
+ * Check whether the numbers is equal
12
+ * Two numbers are considered equal if the absolute value of their difference is less than 0.00001
13
+ * @param {number} leftNumber
14
+ * @param {number} rightNumber
15
+ * @returns bool
16
+ */
17
+ var isNumberEqual = function isNumberEqual(leftNumber, rightNumber) {
18
+ return leftNumber === rightNumber || Math.abs(leftNumber - rightNumber) < 0.00001;
11
19
  };
12
20
 
13
21
  export { isNumber, isNumberEqual };
package/es/row/core.js CHANGED
@@ -2,6 +2,7 @@ import _typeof from '@babel/runtime/helpers/typeof';
2
2
  import { getFormulaDisplayString } from '../cell-value-get/cell-value.js';
3
3
  import 'dayjs';
4
4
  import '../constants/column.js';
5
+ import '../constants/formula.js';
5
6
  import { getColumnOptionNameById } from '../cell-value-get/option.js';
6
7
  import '../constants/group.js';
7
8
  import { getLinkCellValue } from '../link/core.js';
@@ -9,9 +10,27 @@ import { isEmpty } from '../common.js';
9
10
  import { CellType } from '../constants/cell-type.js';
10
11
  import { CONVERT_ROW_COLUMNS_LIMIT } from '../constants/limit.js';
11
12
 
13
+ /**
14
+ * Check is table rows
15
+ * @param {array} rows e.g. table rows: [{ _id, xxx }, ...] | view rows: [ row._id, ... ]
16
+ * @returns bool
17
+ */
12
18
  var isTableRows = function isTableRows(rows) {
13
19
  return Array.isArray(rows) && _typeof(rows[0]) === 'object';
14
20
  };
21
+
22
+ /**
23
+ * Convert row
24
+ * e.g. { '0000': 'a' } to { 'Name': 'a' }
25
+ * @param {object} row
26
+ * @param {object} value e.g. { links, ... }
27
+ * @param {object} table e.g. { _id, columns, ... }
28
+ * @param {object} view e.g. { hidden_columns, ... }
29
+ * @param {object} formulaResults computed value of formula, link-formula, link etc.
30
+ * @param {bool} convertLinkID use to convert link: get linked from formulaResults if true, otherwise get linked from links
31
+ * @param {func} debug use to debug if supplied
32
+ * @returns converted row, object
33
+ */
15
34
  var convertRow = function convertRow(row, value, table, view, formulaResults, convertLinkID) {
16
35
  var _ref = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {},
17
36
  debug = _ref.debug;
@@ -94,7 +113,7 @@ var convertRow = function convertRow(row, value, table, view, formulaResults, co
94
113
  // get values form formulaResults
95
114
  var formulaRow = formulaResults && formulaResults[row._id];
96
115
  var cellResult = formulaRow && formulaRow[key];
97
- if (!cellResult || !Array.isArray(cellResult) || cellResult.length === 0) {
116
+ if (!Array.isArray(cellResult) || cellResult.length === 0) {
98
117
  result[columnName] = null;
99
118
  break;
100
119
  }
package/es/sort/core.js CHANGED
@@ -1,10 +1,16 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import { getColumnOptions } from '../column/option.js';
3
+ import { CellType } from '../constants/cell-type.js';
1
4
  import { SORT_COLUMN_OPTIONS } from '../constants/sort.js';
2
5
 
6
+ 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; }
7
+ 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; }
8
+
3
9
  /**
4
- * check is valid sort
5
- * @param {object} sort e.g. { column_key: '', sort_type: '' }
10
+ * Check is valid sort
11
+ * @param {object} sort e.g. { column_key, sort_type, ... }
6
12
  * @param {array} columns
7
- * @returns boolean
13
+ * @returns bool
8
14
  */
9
15
  var isValidSort = function isValidSort(sort, columns) {
10
16
  var sortByColumn = sort && columns.find(function (column) {
@@ -15,12 +21,12 @@ var isValidSort = function isValidSort(sort, columns) {
15
21
  };
16
22
 
17
23
  /**
18
- * get valid sorts
24
+ * Get valid sorts
19
25
  * 1. sort column is exist or not
20
26
  * 2. valid sort type
21
- * @param {array} sorts
27
+ * @param {array} sorts e.g. [{ column_key, sort_type, ... }, ...]
22
28
  * @param {array} columns
23
- * @returns array
29
+ * @returns valid sorts, array
24
30
  */
25
31
  var getValidSorts = function getValidSorts(sorts, columns) {
26
32
  if (!Array.isArray(sorts) || !Array.isArray(columns)) return [];
@@ -29,4 +35,57 @@ var getValidSorts = function getValidSorts(sorts, columns) {
29
35
  });
30
36
  };
31
37
 
32
- export { getValidSorts, isValidSort };
38
+ /**
39
+ * Get sorted option index of the "optionIds"
40
+ * @param {array} optionIds
41
+ * @param {object} option_id_index_map e.g. {[option.id]: 0, ...}
42
+ * @returns sorted options index, array
43
+ */
44
+ var getMultipleIndexesOrderbyOptions = function getMultipleIndexesOrderbyOptions(optionIds, option_id_index_map) {
45
+ var indexArr = [];
46
+ optionIds.forEach(function (optionId) {
47
+ var index = option_id_index_map[optionId];
48
+ if (index > -1) {
49
+ indexArr.push(index);
50
+ }
51
+ });
52
+ return indexArr.sort();
53
+ };
54
+
55
+ /**
56
+ * Get valid and formatted sorts
57
+ * @param {array} sorts e.g. [{ column_key, sort_type, ... }, ...]
58
+ * @param {array} columns
59
+ * @returns valid and formatted sorts, array
60
+ */
61
+ var deleteInvalidSort = function deleteInvalidSort(sorts, columns) {
62
+ var validSorts = getValidSorts(sorts, columns);
63
+ var cleanSorts = [];
64
+ validSorts.forEach(function (sort) {
65
+ var column_key = sort.column_key;
66
+ var sortColumn = columns.find(function (column) {
67
+ return column.key === column_key;
68
+ });
69
+ var columnType = sortColumn.type;
70
+ var newSort = _objectSpread(_objectSpread({}, sort), {}, {
71
+ column: sortColumn
72
+ });
73
+ switch (columnType) {
74
+ case CellType.SINGLE_SELECT:
75
+ case CellType.MULTIPLE_SELECT:
76
+ {
77
+ var options = getColumnOptions(sortColumn);
78
+ var option_id_index_map = {};
79
+ options.forEach(function (option, index) {
80
+ option_id_index_map[option.id] = index;
81
+ });
82
+ newSort.option_id_index_map = option_id_index_map;
83
+ break;
84
+ }
85
+ }
86
+ cleanSorts.push(newSort);
87
+ });
88
+ return cleanSorts;
89
+ };
90
+
91
+ export { deleteInvalidSort, getMultipleIndexesOrderbyOptions, getValidSorts, isValidSort };
@@ -9,55 +9,64 @@ import { CellType } from '../../constants/cell-type.js';
9
9
  import { NUMERIC_COLUMNS_TYPES, DATE_COLUMN_OPTIONS } from '../../constants/column.js';
10
10
  import { FORMULA_RESULT_TYPE } from '../../constants/formula.js';
11
11
 
12
- var sortByArrayType = function sortByArrayType(currCellVal, nextCellVal, sortType, _ref) {
12
+ /**
13
+ * Sort by array type
14
+ * @param {array} leftArray
15
+ * @param {array} rightArray
16
+ * @param {string} sortType e.g. 'up' | 'down
17
+ * @param {object} columnData e.g. { result_type, array_type, array_data, ... }
18
+ * @param {object} value e.g. { collaborators, ... }
19
+ * @returns number
20
+ */
21
+ var sortByArrayType = function sortByArrayType(leftArray, rightArray, sortType, _ref) {
13
22
  var columnData = _ref.columnData,
14
23
  value = _ref.value;
15
24
  var _ref2 = columnData || {},
16
25
  array_type = _ref2.array_type;
17
26
  if (NUMERIC_COLUMNS_TYPES.includes(array_type)) {
18
- var currNumber = currCellVal;
19
- var nextNumber = nextCellVal;
20
- if (Array.isArray(currCellVal)) {
21
- currNumber = currCellVal[0];
27
+ var leftNumber = leftArray;
28
+ var rightNumber = rightArray;
29
+ if (Array.isArray(leftArray)) {
30
+ leftNumber = leftArray[0];
22
31
  }
23
- if (Array.isArray(nextCellVal)) {
24
- nextNumber = nextCellVal[0];
32
+ if (Array.isArray(rightArray)) {
33
+ rightNumber = rightArray[0];
25
34
  }
26
- currNumber = currNumber || currNumber === 0 ? currNumber : null;
27
- nextNumber = nextNumber || nextNumber === 0 ? nextNumber : null;
28
- return sortNumber(currNumber, nextNumber, sortType);
35
+ leftNumber = leftNumber || leftNumber === 0 ? leftNumber : null;
36
+ rightNumber = rightNumber || rightNumber === 0 ? rightNumber : null;
37
+ return sortNumber(leftNumber, rightNumber, sortType);
29
38
  }
30
39
  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);
40
+ var leftDate = Array.isArray(leftArray) ? leftArray[0] : leftArray;
41
+ var rightDate = Array.isArray(rightArray) ? rightArray[0] : rightArray;
42
+ return sortDate(leftDate, rightDate, sortType);
34
43
  }
35
44
  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];
45
+ var leftBool = leftArray;
46
+ var rightBool = rightArray;
47
+ if (Array.isArray(leftArray)) {
48
+ leftBool = leftArray[0];
40
49
  }
41
- if (Array.isArray(nextCellVal)) {
42
- nextBoolean = nextCellVal[0];
50
+ if (Array.isArray(rightArray)) {
51
+ rightBool = rightArray[0];
43
52
  }
44
- currBoolean = currBoolean || false;
45
- nextBoolean = nextBoolean || false;
46
- return sortCheckbox(currBoolean, nextBoolean, sortType);
53
+ leftBool = leftBool || false;
54
+ rightBool = rightBool || false;
55
+ return sortCheckbox(leftBool, rightBool, sortType);
47
56
  }
48
57
  if (array_type === CellType.COLLABORATOR) {
49
58
  var collaborators = value.collaborators;
50
- var currCollaborators = Array.isArray(currCellVal) ? currCellVal : [currCellVal];
51
- var nextCollaborators = Array.isArray(nextCellVal) ? nextCellVal : [nextCellVal];
59
+ var leftCollaborators = Array.isArray(leftArray) ? leftArray : [leftArray];
60
+ var rightCollaborators = Array.isArray(rightArray) ? rightArray : [rightArray];
52
61
  if (collaborators) {
53
- currCollaborators = getCollaboratorsNames(currCollaborators, collaborators);
54
- nextCollaborators = getCollaboratorsNames(nextCollaborators, collaborators);
62
+ leftCollaborators = getCollaboratorsNames(leftCollaborators, collaborators);
63
+ rightCollaborators = getCollaboratorsNames(rightCollaborators, collaborators);
55
64
  }
56
- return sortCollaborator(currCollaborators, nextCollaborators, sortType);
65
+ return sortCollaborator(leftCollaborators, rightCollaborators, sortType);
57
66
  }
58
- var currText = getFormulaDisplayString(currCellVal, columnData);
59
- var nextText = getFormulaDisplayString(nextCellVal, columnData);
60
- return sortText(currText, nextText, sortType);
67
+ var leftText = getFormulaDisplayString(leftArray, columnData);
68
+ var rightText = getFormulaDisplayString(rightArray, columnData);
69
+ return sortText(leftText, rightText, sortType);
61
70
  };
62
71
 
63
72
  export { sortByArrayType };
@@ -1,12 +1,19 @@
1
1
  import { SORT_TYPE } from '../../constants/sort.js';
2
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) {
3
+ /**
4
+ * Sort checkbox
5
+ * @param {bool} leftChecked
6
+ * @param {bool} rightChecked
7
+ * @param {string} sortType e.g. 'up' | 'down
8
+ * @returns number
9
+ */
10
+ var sortCheckbox = function sortCheckbox(leftChecked, rightChecked, sortType) {
11
+ var normalizedCurrChecked = leftChecked ? 1 : -1;
12
+ var normalizedNextChecked = rightChecked ? 1 : -1;
13
+ if (normalizedCurrChecked > normalizedNextChecked) {
7
14
  return sortType === SORT_TYPE.UP ? 1 : -1;
8
15
  }
9
- if (currCellValPart < nextCellValPart) {
16
+ if (normalizedCurrChecked < normalizedNextChecked) {
10
17
  return sortType === SORT_TYPE.UP ? -1 : 1;
11
18
  }
12
19
  return 0;
@@ -1,9 +1,16 @@
1
1
  import { sortText } from './text.js';
2
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);
3
+ /**
4
+ * Sort collaborator with email or name
5
+ * @param {array} leftCollaborators e.g. [ collaborator.email, ... ] | [ collaborator.name, ... ]
6
+ * @param {array} rightCollaborators
7
+ * @param {string} sortType e.g. 'up' | 'down
8
+ * @returns number
9
+ */
10
+ var sortCollaborator = function sortCollaborator(leftCollaborators, rightCollaborators, sortType) {
11
+ var sLeftCollaborators = Array.isArray(leftCollaborators) && leftCollaborators.length ? leftCollaborators.join('') : null;
12
+ var sRightCollaborators = Array.isArray(rightCollaborators) && rightCollaborators.length ? rightCollaborators.join('') : null;
13
+ return sortText(sLeftCollaborators, sRightCollaborators, sortType);
7
14
  };
8
15
 
9
16
  export { sortCollaborator };
@@ -1,22 +1,22 @@
1
1
  import { SORT_TYPE } from '../../constants/sort.js';
2
2
 
3
3
  /**
4
- * compare date
5
- * @param {string} currDate date string, e.g. '2023-07-31'
6
- * @param {string} nextDate date string
4
+ * Sort date
5
+ * @param {string} leftDate e.g. '2023-07-31'
6
+ * @param {string} nextDate
7
7
  * @param {string} sortType e.g. 'up' | 'down'
8
- * @returns number, e.g. 1 | -1 | 0
8
+ * @returns number
9
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) {
10
+ var sortDate = function sortDate(leftDate, rightDate, sortType) {
11
+ var emptyLeftDate = !leftDate;
12
+ var emptyRightDate = !rightDate;
13
+ if (emptyLeftDate && emptyRightDate) return 0;
14
+ if (emptyLeftDate) return 1;
15
+ if (emptyRightDate) return -1;
16
+ if (leftDate > rightDate) {
17
17
  return sortType === SORT_TYPE.UP ? 1 : -1;
18
18
  }
19
- if (currDate < nextDate) {
19
+ if (leftDate < rightDate) {
20
20
  return sortType === SORT_TYPE.UP ? -1 : 1;
21
21
  }
22
22
  return 0;
@@ -8,33 +8,42 @@ import { DATE_COLUMN_OPTIONS } from '../../constants/column.js';
8
8
  import { FORMULA_RESULT_TYPE } from '../../constants/formula.js';
9
9
  import { NUMBER_SORTER_COLUMN_TYPES } from '../../constants/sort.js';
10
10
 
11
- var sortFormula = function sortFormula(currCellVal, nextCellVal, sortType, _ref) {
11
+ /**
12
+ * Sort formula
13
+ * @param {any} leftComputedValue compute value from formula row
14
+ * @param {any} rightComputedValue
15
+ * @param {string} sortType e.g. 'up' | 'down
16
+ * @param {object} columnData e.g. { result_type, array_type, array_data, ... }
17
+ * @param {object} value e.g. { collaborators, ... }
18
+ * @returns number
19
+ */
20
+ var sortFormula = function sortFormula(leftComputedValue, rightComputedValue, sortType, _ref) {
12
21
  var columnData = _ref.columnData,
13
22
  value = _ref.value;
14
23
  var _ref2 = columnData || {},
15
24
  result_type = _ref2.result_type;
16
25
  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);
26
+ var leftNumber = leftComputedValue || leftComputedValue === 0 ? leftComputedValue - 0 : null;
27
+ var rightNumber = rightComputedValue || rightComputedValue === 0 ? rightComputedValue - 0 : null;
28
+ return sortNumber(leftNumber, rightNumber, sortType);
20
29
  }
21
30
  if (DATE_COLUMN_OPTIONS.includes(result_type)) {
22
- return sortDate(currCellVal, nextCellVal, sortType);
31
+ return sortDate(leftComputedValue, rightComputedValue, sortType);
23
32
  }
24
33
  if (result_type === FORMULA_RESULT_TYPE.BOOL) {
25
- var currBoolean = currCellVal || false;
26
- var nextBoolean = nextCellVal || false;
27
- return sortCheckbox(currBoolean, nextBoolean);
34
+ var leftBoolean = leftComputedValue || false;
35
+ var rightBoolean = rightComputedValue || false;
36
+ return sortCheckbox(leftBoolean, rightBoolean, sortType);
28
37
  }
29
38
  if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
30
- return sortByArrayType(currCellVal, nextCellVal, sortType, {
39
+ return sortByArrayType(leftComputedValue, rightComputedValue, sortType, {
31
40
  columnData: columnData,
32
41
  value: value
33
42
  });
34
43
  }
35
- var currText = getFormulaDisplayString(currCellVal, columnData);
36
- var nextText = getFormulaDisplayString(nextCellVal, columnData);
37
- return sortText(currText, nextText, sortType);
44
+ var leftText = getFormulaDisplayString(leftComputedValue, columnData);
45
+ var rightText = getFormulaDisplayString(rightComputedValue, columnData);
46
+ return sortText(leftText, rightText, sortType);
38
47
  };
39
48
 
40
49
  export { sortFormula };
@@ -1,20 +1,29 @@
1
1
  import { sortByArrayType } from './array.js';
2
2
 
3
- var sortLink = function sortLink(currCellVal, nextCellVal, sortType, _ref) {
3
+ /**
4
+ * Sort link
5
+ * @param {array} leftLinkedCellValues e.g. [{ row_id, display_value }]
6
+ * @param {array} rightLinkedCellValues
7
+ * @param {string} sortType e.g. 'up' | 'down
8
+ * @param {object} columnData e.g. { result_type, array_type, array_data, ... }
9
+ * @param {object} value e.g. { collaborators, ... }
10
+ * @returns number
11
+ */
12
+ var sortLink = function sortLink(leftLinkedCellValues, rightLinkedCellValues, sortType, _ref) {
4
13
  var columnData = _ref.columnData,
5
14
  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) {
15
+ var emptyLeftLinkedCellValues = !Array.isArray(leftLinkedCellValues) || leftLinkedCellValues.length === 0;
16
+ var emptyRightLinkedCellValues = !Array.isArray(rightLinkedCellValues) || rightLinkedCellValues.length === 0;
17
+ if (emptyLeftLinkedCellValues && emptyRightLinkedCellValues) return 0;
18
+ if (emptyLeftLinkedCellValues) return 1;
19
+ if (emptyRightLinkedCellValues) return -1;
20
+ var leftDisplayValues = leftLinkedCellValues.map(function (linked) {
12
21
  return linked.display_value;
13
22
  });
14
- var nextDisplayValues = nextCellVal.map(function (linked) {
23
+ var rightDisplayValues = rightLinkedCellValues.map(function (linked) {
15
24
  return linked.display_value;
16
25
  });
17
- return sortByArrayType(currDisplayValues, nextDisplayValues, sortType, {
26
+ return sortByArrayType(leftDisplayValues, rightDisplayValues, sortType, {
18
27
  columnData: columnData,
19
28
  value: value
20
29
  });
@@ -1,45 +1,45 @@
1
+ import { getMultipleIndexesOrderbyOptions } from '../core.js';
2
+ export { getMultipleIndexesOrderbyOptions } from '../core.js';
1
3
  import { SORT_TYPE } from '../../constants/sort.js';
2
4
 
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) {
5
+ /**
6
+ * Sort multiple-select
7
+ * @param {array} leftOptionIds the ids of options
8
+ * @param {array} rightOptionIds
9
+ * @param {string} sort_type e.g. 'up' | 'down'
10
+ * @param {object} option_id_index_map e.g. { [option.id]: 0, ... }
11
+ * @returns number
12
+ */
13
+ var sortMultipleSelect = function sortMultipleSelect(leftOptionIds, rightOptionIds, _ref) {
14
14
  var sort_type = _ref.sort_type,
15
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;
16
+ var emptyLeftOptionIds = !leftOptionIds || leftOptionIds.length === 0;
17
+ var emptyRightOptionIds = !rightOptionIds || rightOptionIds.length === 0;
18
+ if (emptyLeftOptionIds && emptyRightOptionIds) return 0;
19
+ if (emptyLeftOptionIds) return 1;
20
+ if (emptyRightOptionIds) return -1;
21
+ var leftOptionIndexes = getMultipleIndexesOrderbyOptions(leftOptionIds, option_id_index_map);
22
+ var rightOptionIndexes = getMultipleIndexesOrderbyOptions(rightOptionIds, option_id_index_map);
23
+ var leftOptionsLen = leftOptionIndexes.length;
24
+ var rightOptionsLen = rightOptionIndexes.length;
25
25
 
26
26
  // current multiple select equal to next multiple select.
27
- if (currLen === nextLen && (currLen === 0 || currCellValIndexes.join('') === nextCellValIndexes.join(''))) {
27
+ if (leftOptionsLen === rightOptionsLen && (leftOptionsLen === 0 || leftOptionIndexes.join('') === rightOptionIndexes.join(''))) {
28
28
  return 0;
29
29
  }
30
- var len = Math.min(currLen, nextLen);
30
+ var len = Math.min(leftOptionsLen, rightOptionsLen);
31
31
  for (var i = 0; i < len; i++) {
32
- if (currCellValIndexes[i] > nextCellValIndexes[i]) {
32
+ if (leftOptionIndexes[i] > rightOptionIndexes[i]) {
33
33
  return sort_type === SORT_TYPE.UP ? 1 : -1;
34
34
  }
35
- if (currCellValIndexes[i] < nextCellValIndexes[i]) {
35
+ if (leftOptionIndexes[i] < rightOptionIndexes[i]) {
36
36
  return sort_type === SORT_TYPE.UP ? -1 : 1;
37
37
  }
38
38
  }
39
- if (currLen > nextLen) {
39
+ if (leftOptionsLen > rightOptionsLen) {
40
40
  return sort_type === SORT_TYPE.UP ? 1 : -1;
41
41
  }
42
42
  return sort_type === SORT_TYPE.UP ? -1 : 1;
43
43
  };
44
44
 
45
- export { getMultipleIndexesOrderbyOptions, sortMultipleSelect };
45
+ export { sortMultipleSelect };