@sisense/sdk-pivot-query-client 2.17.0

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 (189) hide show
  1. package/LICENSE.md +35 -0
  2. package/README.md +2 -0
  3. package/dist/__test-helpers__/testUtils.d.ts +30 -0
  4. package/dist/__test-helpers__/testUtils.js +89 -0
  5. package/dist/builders/index.d.ts +2 -0
  6. package/dist/builders/index.js +2 -0
  7. package/dist/builders/pivot-data-builder.d.ts +34 -0
  8. package/dist/builders/pivot-data-builder.js +182 -0
  9. package/dist/builders/socket-builder.d.ts +18 -0
  10. package/dist/builders/socket-builder.js +72 -0
  11. package/dist/cjs/__test-helpers__/testUtils.d.ts +30 -0
  12. package/dist/cjs/__test-helpers__/testUtils.js +104 -0
  13. package/dist/cjs/builders/index.d.ts +2 -0
  14. package/dist/cjs/builders/index.js +7 -0
  15. package/dist/cjs/builders/pivot-data-builder.d.ts +34 -0
  16. package/dist/cjs/builders/pivot-data-builder.js +186 -0
  17. package/dist/cjs/builders/socket-builder.d.ts +18 -0
  18. package/dist/cjs/builders/socket-builder.js +79 -0
  19. package/dist/cjs/data-handling/DataService.d.ts +672 -0
  20. package/dist/cjs/data-handling/DataService.js +1364 -0
  21. package/dist/cjs/data-handling/DivergenceComparator.d.ts +7 -0
  22. package/dist/cjs/data-handling/DivergenceComparator.js +20 -0
  23. package/dist/cjs/data-handling/constants.d.ts +44 -0
  24. package/dist/cjs/data-handling/constants.js +43 -0
  25. package/dist/cjs/data-handling/index.d.ts +3 -0
  26. package/dist/cjs/data-handling/index.js +23 -0
  27. package/dist/cjs/data-handling/types.d.ts +104 -0
  28. package/dist/cjs/data-handling/types.js +2 -0
  29. package/dist/cjs/data-handling/utils/createPivotTreeNode.d.ts +13 -0
  30. package/dist/cjs/data-handling/utils/createPivotTreeNode.js +21 -0
  31. package/dist/cjs/data-handling/utils/index.d.ts +4 -0
  32. package/dist/cjs/data-handling/utils/index.js +14 -0
  33. package/dist/cjs/data-handling/utils/jaqlProcessor.d.ts +122 -0
  34. package/dist/cjs/data-handling/utils/jaqlProcessor.js +661 -0
  35. package/dist/cjs/data-handling/utils/pivotTransforms.d.ts +74 -0
  36. package/dist/cjs/data-handling/utils/pivotTransforms.js +373 -0
  37. package/dist/cjs/data-handling/utils/plugins/PluginService.d.ts +135 -0
  38. package/dist/cjs/data-handling/utils/plugins/PluginService.js +383 -0
  39. package/dist/cjs/data-handling/utils/plugins/getters.d.ts +23 -0
  40. package/dist/cjs/data-handling/utils/plugins/getters.js +70 -0
  41. package/dist/cjs/data-handling/utils/plugins/types.d.ts +75 -0
  42. package/dist/cjs/data-handling/utils/plugins/types.js +2 -0
  43. package/dist/cjs/data-handling/utils/plugins/validator.d.ts +13 -0
  44. package/dist/cjs/data-handling/utils/plugins/validator.js +169 -0
  45. package/dist/cjs/data-load/AbstractDataLoadService.d.ts +256 -0
  46. package/dist/cjs/data-load/AbstractDataLoadService.js +473 -0
  47. package/dist/cjs/data-load/DataLoadService.d.ts +63 -0
  48. package/dist/cjs/data-load/DataLoadService.js +152 -0
  49. package/dist/cjs/data-load/SisenseDataLoadService.d.ts +44 -0
  50. package/dist/cjs/data-load/SisenseDataLoadService.js +87 -0
  51. package/dist/cjs/data-load/TestDataLoadService.d.ts +27 -0
  52. package/dist/cjs/data-load/TestDataLoadService.js +76 -0
  53. package/dist/cjs/data-load/constants.d.ts +13 -0
  54. package/dist/cjs/data-load/constants.js +28 -0
  55. package/dist/cjs/data-load/index.d.ts +6 -0
  56. package/dist/cjs/data-load/index.js +14 -0
  57. package/dist/cjs/data-load/sockets/SisenseSocket.d.ts +81 -0
  58. package/dist/cjs/data-load/sockets/SisenseSocket.js +162 -0
  59. package/dist/cjs/data-load/sockets/TestSocket.d.ts +61 -0
  60. package/dist/cjs/data-load/sockets/TestSocket.js +90 -0
  61. package/dist/cjs/data-load/sockets/helpers.d.ts +4 -0
  62. package/dist/cjs/data-load/sockets/helpers.js +27 -0
  63. package/dist/cjs/data-load/sockets/index.d.ts +2 -0
  64. package/dist/cjs/data-load/sockets/index.js +8 -0
  65. package/dist/cjs/data-load/types.d.ts +90 -0
  66. package/dist/cjs/data-load/types.js +2 -0
  67. package/dist/cjs/errors/LoadingCanceledError.d.ts +7 -0
  68. package/dist/cjs/errors/LoadingCanceledError.js +24 -0
  69. package/dist/cjs/errors/index.d.ts +1 -0
  70. package/dist/cjs/errors/index.js +6 -0
  71. package/dist/cjs/index.d.ts +17 -0
  72. package/dist/cjs/index.js +32 -0
  73. package/dist/cjs/package.json +12 -0
  74. package/dist/cjs/pivot-query-client.d.ts +13 -0
  75. package/dist/cjs/pivot-query-client.js +26 -0
  76. package/dist/cjs/tree-structure/AbstractTreeService.d.ts +308 -0
  77. package/dist/cjs/tree-structure/AbstractTreeService.js +716 -0
  78. package/dist/cjs/tree-structure/HeaderTreeService.d.ts +180 -0
  79. package/dist/cjs/tree-structure/HeaderTreeService.js +280 -0
  80. package/dist/cjs/tree-structure/TreeCellMap.d.ts +104 -0
  81. package/dist/cjs/tree-structure/TreeCellMap.js +145 -0
  82. package/dist/cjs/tree-structure/TreeService.d.ts +8 -0
  83. package/dist/cjs/tree-structure/TreeService.js +12 -0
  84. package/dist/cjs/tree-structure/constants.d.ts +6 -0
  85. package/dist/cjs/tree-structure/constants.js +10 -0
  86. package/dist/cjs/tree-structure/index.d.ts +5 -0
  87. package/dist/cjs/tree-structure/index.js +10 -0
  88. package/dist/cjs/tree-structure/types.d.ts +93 -0
  89. package/dist/cjs/tree-structure/types.js +2 -0
  90. package/dist/cjs/tree-structure/utils/index.d.ts +1 -0
  91. package/dist/cjs/tree-structure/utils/index.js +9 -0
  92. package/dist/cjs/tree-structure/utils/treeNode.d.ts +147 -0
  93. package/dist/cjs/tree-structure/utils/treeNode.js +534 -0
  94. package/dist/cjs/utils/array.d.ts +13 -0
  95. package/dist/cjs/utils/array.js +25 -0
  96. package/dist/cjs/utils/cloneObject.d.ts +30 -0
  97. package/dist/cjs/utils/cloneObject.js +225 -0
  98. package/dist/cjs/utils/index.d.ts +3 -0
  99. package/dist/cjs/utils/index.js +9 -0
  100. package/dist/cjs/utils/throttle.d.ts +12 -0
  101. package/dist/cjs/utils/throttle.js +39 -0
  102. package/dist/cjs/utils/types.d.ts +12 -0
  103. package/dist/cjs/utils/types.js +2 -0
  104. package/dist/data-handling/DataService.d.ts +672 -0
  105. package/dist/data-handling/DataService.js +1357 -0
  106. package/dist/data-handling/DivergenceComparator.d.ts +7 -0
  107. package/dist/data-handling/DivergenceComparator.js +16 -0
  108. package/dist/data-handling/constants.d.ts +44 -0
  109. package/dist/data-handling/constants.js +40 -0
  110. package/dist/data-handling/index.d.ts +3 -0
  111. package/dist/data-handling/index.js +4 -0
  112. package/dist/data-handling/types.d.ts +104 -0
  113. package/dist/data-handling/types.js +1 -0
  114. package/dist/data-handling/utils/createPivotTreeNode.d.ts +13 -0
  115. package/dist/data-handling/utils/createPivotTreeNode.js +17 -0
  116. package/dist/data-handling/utils/index.d.ts +4 -0
  117. package/dist/data-handling/utils/index.js +4 -0
  118. package/dist/data-handling/utils/jaqlProcessor.d.ts +122 -0
  119. package/dist/data-handling/utils/jaqlProcessor.js +621 -0
  120. package/dist/data-handling/utils/pivotTransforms.d.ts +74 -0
  121. package/dist/data-handling/utils/pivotTransforms.js +335 -0
  122. package/dist/data-handling/utils/plugins/PluginService.d.ts +135 -0
  123. package/dist/data-handling/utils/plugins/PluginService.js +379 -0
  124. package/dist/data-handling/utils/plugins/getters.d.ts +23 -0
  125. package/dist/data-handling/utils/plugins/getters.js +65 -0
  126. package/dist/data-handling/utils/plugins/types.d.ts +75 -0
  127. package/dist/data-handling/utils/plugins/types.js +1 -0
  128. package/dist/data-handling/utils/plugins/validator.d.ts +13 -0
  129. package/dist/data-handling/utils/plugins/validator.js +165 -0
  130. package/dist/data-load/AbstractDataLoadService.d.ts +256 -0
  131. package/dist/data-load/AbstractDataLoadService.js +466 -0
  132. package/dist/data-load/DataLoadService.d.ts +63 -0
  133. package/dist/data-load/DataLoadService.js +148 -0
  134. package/dist/data-load/SisenseDataLoadService.d.ts +44 -0
  135. package/dist/data-load/SisenseDataLoadService.js +83 -0
  136. package/dist/data-load/TestDataLoadService.d.ts +27 -0
  137. package/dist/data-load/TestDataLoadService.js +69 -0
  138. package/dist/data-load/constants.d.ts +13 -0
  139. package/dist/data-load/constants.js +25 -0
  140. package/dist/data-load/index.d.ts +6 -0
  141. package/dist/data-load/index.js +6 -0
  142. package/dist/data-load/sockets/SisenseSocket.d.ts +81 -0
  143. package/dist/data-load/sockets/SisenseSocket.js +155 -0
  144. package/dist/data-load/sockets/TestSocket.d.ts +61 -0
  145. package/dist/data-load/sockets/TestSocket.js +83 -0
  146. package/dist/data-load/sockets/helpers.d.ts +4 -0
  147. package/dist/data-load/sockets/helpers.js +23 -0
  148. package/dist/data-load/sockets/index.d.ts +2 -0
  149. package/dist/data-load/sockets/index.js +3 -0
  150. package/dist/data-load/types.d.ts +90 -0
  151. package/dist/data-load/types.js +1 -0
  152. package/dist/errors/LoadingCanceledError.d.ts +7 -0
  153. package/dist/errors/LoadingCanceledError.js +20 -0
  154. package/dist/errors/index.d.ts +1 -0
  155. package/dist/errors/index.js +2 -0
  156. package/dist/index.d.ts +17 -0
  157. package/dist/index.js +9 -0
  158. package/dist/pivot-query-client.d.ts +13 -0
  159. package/dist/pivot-query-client.js +22 -0
  160. package/dist/tree-structure/AbstractTreeService.d.ts +308 -0
  161. package/dist/tree-structure/AbstractTreeService.js +712 -0
  162. package/dist/tree-structure/HeaderTreeService.d.ts +180 -0
  163. package/dist/tree-structure/HeaderTreeService.js +276 -0
  164. package/dist/tree-structure/TreeCellMap.d.ts +104 -0
  165. package/dist/tree-structure/TreeCellMap.js +141 -0
  166. package/dist/tree-structure/TreeService.d.ts +8 -0
  167. package/dist/tree-structure/TreeService.js +8 -0
  168. package/dist/tree-structure/constants.d.ts +6 -0
  169. package/dist/tree-structure/constants.js +7 -0
  170. package/dist/tree-structure/index.d.ts +5 -0
  171. package/dist/tree-structure/index.js +4 -0
  172. package/dist/tree-structure/types.d.ts +93 -0
  173. package/dist/tree-structure/types.js +1 -0
  174. package/dist/tree-structure/utils/index.d.ts +1 -0
  175. package/dist/tree-structure/utils/index.js +1 -0
  176. package/dist/tree-structure/utils/treeNode.d.ts +147 -0
  177. package/dist/tree-structure/utils/treeNode.js +515 -0
  178. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  179. package/dist/utils/array.d.ts +13 -0
  180. package/dist/utils/array.js +21 -0
  181. package/dist/utils/cloneObject.d.ts +30 -0
  182. package/dist/utils/cloneObject.js +221 -0
  183. package/dist/utils/index.d.ts +3 -0
  184. package/dist/utils/index.js +3 -0
  185. package/dist/utils/throttle.d.ts +12 -0
  186. package/dist/utils/throttle.js +35 -0
  187. package/dist/utils/types.d.ts +12 -0
  188. package/dist/utils/types.js +1 -0
  189. package/package.json +61 -0
@@ -0,0 +1,180 @@
1
+ import { CloneFn } from '../utils/types.js';
2
+ import { TreeNode, TreeNodeMetadata, TreeServiceI } from './types.js';
3
+ export declare class HeaderTreeService implements TreeServiceI {
4
+ hasGrandTotals: boolean;
5
+ /**
6
+ * columns TreeService
7
+ *
8
+ *
9
+ * @private
10
+ */
11
+ columnsTreeService?: TreeServiceI;
12
+ /**
13
+ * corner TreeService
14
+ *
15
+ *
16
+ * @private
17
+ */
18
+ cornerTreeService?: TreeServiceI;
19
+ /**
20
+ * Final 2D array
21
+ *
22
+ *
23
+ * @private
24
+ */
25
+ grid?: Array<Array<any>>;
26
+ /**
27
+ * columns grid offset base on corner size
28
+ *
29
+ *
30
+ * @private
31
+ */
32
+ cornerOffset: number;
33
+ constructor(cornerTreeService?: TreeServiceI, columnsTreeService?: TreeServiceI);
34
+ /**
35
+ * Returns grid (2d list) of tree structure
36
+ *
37
+ * @returns {Array<Array<TreeNode | string>>} - 2d list
38
+ */
39
+ getGrid(): Array<Array<TreeNode | string>>;
40
+ /**
41
+ * Returns TreeNode item if exist for appropriate coordinates (rowIndex, columnIndex)
42
+ *
43
+ * @param {number} rowIndex - row index
44
+ * @param {number} columnIndex - column index
45
+ * @returns {TreeNode|undefined} - TreeNode item
46
+ */
47
+ getTreeNode(rowIndex: number, columnIndex: number): TreeNode | undefined;
48
+ /**
49
+ * Defines if cell with (rowIndex, columnIndex) coordinate is children cell or main one
50
+ *
51
+ * @param {number} rowIndex - row index of the cell
52
+ * @param {number} columnIndex - column index of the cell
53
+ * @returns {boolean} - true - if children, false if main one
54
+ */
55
+ isChildren(rowIndex: number, columnIndex: number): boolean;
56
+ /**
57
+ * Defines if cell with (rowIndex, columnIndex) coordinate has children column/row cells or not
58
+ *
59
+ * @param {number} rowIndex - row index of the cell
60
+ * @param {number} columnIndex - column index of the cell
61
+ * @returns {boolean} - true - has children column/row cells, false - does not have
62
+ */
63
+ hasChildren(rowIndex: number, columnIndex: number): boolean;
64
+ getMainCellWidth(rowIndex: number, columnIndex: number, columnWidth: Function, borderWidth: number, options?: {
65
+ offsetTop?: number;
66
+ columnsOffset?: number;
67
+ }): number;
68
+ /**
69
+ * Updates merge object for the cell if it has children cells
70
+ *
71
+ * @param {number} rowIndex - cell row index
72
+ * @param {number} columnIndex - cell column index
73
+ * @returns {object} - new merge object
74
+ */
75
+ getMainCellSpans(rowIndex: number, columnIndex: number): {
76
+ colSpan?: number;
77
+ rowSpan?: number;
78
+ };
79
+ /**
80
+ * Align start index in case of long merged cell
81
+ *
82
+ * @param {number} startIndex - initial start index
83
+ * @param {boolean} isVertical - defines if it is vertical grid or not
84
+ * @returns {number} - new start index
85
+ */
86
+ alignStartIndex(startIndex: number, isVertical?: boolean): number;
87
+ /**
88
+ * Align stop index in case of long merged cell
89
+ *
90
+ * @param {number} stopIndex - initial stop index
91
+ * @param {boolean} isVertical - defines if it is vertical grid or not
92
+ * @returns {number} - new stop index
93
+ */
94
+ alignStopIndex(stopIndex: number, isVertical?: boolean): number;
95
+ /**
96
+ * Returns number of last children for the tree
97
+ *
98
+ * @param {Array<TreeNode> | TreeNode} item - tree node or list of nodes
99
+ * @returns {number} - count of last children
100
+ */
101
+ getTreeChildLength(item?: Array<TreeNode> | TreeNode): number;
102
+ /**
103
+ * Returns deep level of the tree
104
+ *
105
+ * @param {Array<TreeNode> | TreeNode} item - tree node or list of nodes
106
+ * @returns {number} - count of last children
107
+ */
108
+ getTreeDeepsLength(item?: Array<TreeNode> | TreeNode): number;
109
+ /**
110
+ * Sets value node when it's single
111
+ *
112
+ * @param {TreeNode} valueNode - values measure node
113
+ * @returns {void}
114
+ */
115
+ setValueNode(valueNode: TreeNode): void;
116
+ /**
117
+ * Returns cell meta information
118
+ *
119
+ * @param {number} rowIndex - cell row index
120
+ * @param {number} columnIndex - cell column index
121
+ * @param {{ to: number }} [options] - additional configuration options
122
+ * @returns {{levels: Array<string>, siblings: Array<string>}} - meta information
123
+ */
124
+ getMetadata(rowIndex: number, columnIndex: number, options?: {
125
+ from: number;
126
+ to: number;
127
+ }): TreeNodeMetadata | undefined;
128
+ destroy(): void;
129
+ /**
130
+ * Returns array of last tree nodes
131
+ * Should not be called for header
132
+ *
133
+ * @returns {Array<TreeNode>} - list of tree nodes
134
+ * @deprecated
135
+ */
136
+ getLastLevelNodes(): Array<TreeNode>;
137
+ /**
138
+ * Extract 2D array of data base on columnsTreeService
139
+ * Should not be called for header
140
+ *
141
+ * @param {TreeServiceI} columnsTreeService - tree service according to which align the data
142
+ * @returns {Array<Array<any>>} - 2D array of data
143
+ * @deprecated
144
+ */
145
+ extractData(columnsTreeService?: TreeServiceI): Array<Array<any>>;
146
+ /**
147
+ * Adds additional tree node to current state
148
+ * Should not be called for header
149
+ *
150
+ * @param {TreeNode} tree - new treeNode
151
+ * @returns {void}
152
+ * @deprecated
153
+ */
154
+ extend(tree?: TreeNode): void;
155
+ /**
156
+ * Returns part of current tree with possible cut nodes according to "from" - "to" position
157
+ * Should not be called for header
158
+ *
159
+ * @param {number} from - start rows index for partial grid
160
+ * @param {number} [to] - stop rows index for partial grid
161
+ * @param {object} [options] - additional options
162
+ * @param {Function} [options.cloneFn] - replace default clone function with specific one
163
+ * @returns {Array<TreeNode>} - partial tree
164
+ * @deprecated
165
+ */
166
+ getPartialTree(from: number, to?: number, options?: {
167
+ cloneFn?: CloneFn;
168
+ }): Array<TreeNode>;
169
+ /**
170
+ * Returns part of current grid according to "from" - "to" position
171
+ * Should not be called for header
172
+ *
173
+ * @param {number} from - start rows index for partial grid
174
+ * @param {number} to - stop rows index for partial grid
175
+ * @returns {Array<Array<TreeNode | string>>} - partial grid
176
+ * @deprecated
177
+ */
178
+ getPartialGrid(from: number, to: number): Array<Array<TreeNode | string>>;
179
+ }
180
+ export default HeaderTreeService;
@@ -0,0 +1,276 @@
1
+ export class HeaderTreeService {
2
+ constructor(cornerTreeService, columnsTreeService) {
3
+ this.hasGrandTotals = false;
4
+ /**
5
+ * columns grid offset base on corner size
6
+ *
7
+ *
8
+ * @private
9
+ */
10
+ this.cornerOffset = 0;
11
+ this.cornerTreeService = cornerTreeService;
12
+ this.columnsTreeService = columnsTreeService;
13
+ this.cornerOffset = this.cornerTreeService ? this.cornerTreeService.getTreeChildLength() : 0;
14
+ }
15
+ /**
16
+ * Returns grid (2d list) of tree structure
17
+ *
18
+ * @returns {Array<Array<TreeNode | string>>} - 2d list
19
+ */
20
+ getGrid() {
21
+ if (this.grid) {
22
+ return this.grid;
23
+ }
24
+ const cornerGrid = this.cornerTreeService ? this.cornerTreeService.getGrid() : [];
25
+ const columnsGrid = this.columnsTreeService ? this.columnsTreeService.getGrid() : [];
26
+ this.grid = cornerGrid.map((cornerRow = [], index) => {
27
+ const columnsRow = columnsGrid[index] || [];
28
+ return cornerRow.concat(columnsRow);
29
+ });
30
+ return this.grid;
31
+ }
32
+ /**
33
+ * Returns TreeNode item if exist for appropriate coordinates (rowIndex, columnIndex)
34
+ *
35
+ * @param {number} rowIndex - row index
36
+ * @param {number} columnIndex - column index
37
+ * @returns {TreeNode|undefined} - TreeNode item
38
+ */
39
+ getTreeNode(rowIndex, columnIndex) {
40
+ if (columnIndex >= this.cornerOffset && this.columnsTreeService) {
41
+ return this.columnsTreeService.getTreeNode(rowIndex, columnIndex - this.cornerOffset);
42
+ }
43
+ return this.cornerTreeService
44
+ ? this.cornerTreeService.getTreeNode(rowIndex, columnIndex)
45
+ : undefined;
46
+ }
47
+ /**
48
+ * Defines if cell with (rowIndex, columnIndex) coordinate is children cell or main one
49
+ *
50
+ * @param {number} rowIndex - row index of the cell
51
+ * @param {number} columnIndex - column index of the cell
52
+ * @returns {boolean} - true - if children, false if main one
53
+ */
54
+ isChildren(rowIndex, columnIndex) {
55
+ if (columnIndex >= this.cornerOffset && this.columnsTreeService) {
56
+ return this.columnsTreeService.isChildren(rowIndex, columnIndex - this.cornerOffset);
57
+ }
58
+ return this.cornerTreeService
59
+ ? this.cornerTreeService.isChildren(rowIndex, columnIndex)
60
+ : false;
61
+ }
62
+ /**
63
+ * Defines if cell with (rowIndex, columnIndex) coordinate has children column/row cells or not
64
+ *
65
+ * @param {number} rowIndex - row index of the cell
66
+ * @param {number} columnIndex - column index of the cell
67
+ * @returns {boolean} - true - has children column/row cells, false - does not have
68
+ */
69
+ hasChildren(rowIndex, columnIndex) {
70
+ if (columnIndex >= this.cornerOffset && this.columnsTreeService) {
71
+ return this.columnsTreeService.hasChildren(rowIndex, columnIndex - this.cornerOffset);
72
+ }
73
+ return this.cornerTreeService
74
+ ? this.cornerTreeService.hasChildren(rowIndex, columnIndex)
75
+ : false;
76
+ }
77
+ getMainCellWidth(rowIndex, columnIndex, columnWidth, borderWidth, options = { offsetTop: -1, columnsOffset: 0 }) {
78
+ const columnsOffset = options.columnsOffset || this.cornerOffset;
79
+ if (columnIndex >= columnsOffset && this.columnsTreeService) {
80
+ return this.columnsTreeService.getMainCellWidth(rowIndex, columnIndex - columnsOffset, columnWidth, borderWidth, Object.assign(Object.assign({}, options), { columnsOffset }));
81
+ }
82
+ return this.cornerTreeService
83
+ ? this.cornerTreeService.getMainCellWidth(rowIndex, columnIndex, columnWidth, borderWidth, options)
84
+ : Number.NaN;
85
+ }
86
+ /**
87
+ * Updates merge object for the cell if it has children cells
88
+ *
89
+ * @param {number} rowIndex - cell row index
90
+ * @param {number} columnIndex - cell column index
91
+ * @returns {object} - new merge object
92
+ */
93
+ getMainCellSpans(rowIndex, columnIndex) {
94
+ if (columnIndex >= this.cornerOffset && this.columnsTreeService) {
95
+ return this.columnsTreeService.getMainCellSpans(rowIndex, columnIndex - this.cornerOffset);
96
+ }
97
+ return this.cornerTreeService
98
+ ? this.cornerTreeService.getMainCellSpans(rowIndex, columnIndex)
99
+ : {};
100
+ }
101
+ /**
102
+ * Align start index in case of long merged cell
103
+ *
104
+ * @param {number} startIndex - initial start index
105
+ * @param {boolean} isVertical - defines if it is vertical grid or not
106
+ * @returns {number} - new start index
107
+ */
108
+ alignStartIndex(startIndex, isVertical) {
109
+ if (startIndex >= this.cornerOffset && this.columnsTreeService) {
110
+ return (this.cornerOffset +
111
+ this.columnsTreeService.alignStartIndex(startIndex - this.cornerOffset, isVertical));
112
+ }
113
+ return this.cornerTreeService
114
+ ? this.cornerTreeService.alignStartIndex(startIndex, isVertical)
115
+ : startIndex;
116
+ }
117
+ /**
118
+ * Align stop index in case of long merged cell
119
+ *
120
+ * @param {number} stopIndex - initial stop index
121
+ * @param {boolean} isVertical - defines if it is vertical grid or not
122
+ * @returns {number} - new stop index
123
+ */
124
+ alignStopIndex(stopIndex, isVertical) {
125
+ if (stopIndex >= this.cornerOffset && this.columnsTreeService) {
126
+ return (this.cornerOffset +
127
+ this.columnsTreeService.alignStopIndex(stopIndex - this.cornerOffset, isVertical));
128
+ }
129
+ return this.cornerTreeService
130
+ ? this.cornerTreeService.alignStopIndex(stopIndex, isVertical)
131
+ : stopIndex;
132
+ }
133
+ /**
134
+ * Returns number of last children for the tree
135
+ *
136
+ * @param {Array<TreeNode> | TreeNode} item - tree node or list of nodes
137
+ * @returns {number} - count of last children
138
+ */
139
+ getTreeChildLength(item) {
140
+ if (item) {
141
+ if (this.columnsTreeService) {
142
+ return this.columnsTreeService.getTreeChildLength(item);
143
+ }
144
+ return this.cornerTreeService ? this.cornerTreeService.getTreeChildLength(item) : 0;
145
+ }
146
+ const cornerLength = this.cornerTreeService ? this.cornerTreeService.getTreeChildLength() : 0;
147
+ const columnsLength = this.columnsTreeService
148
+ ? this.columnsTreeService.getTreeChildLength()
149
+ : 0;
150
+ return cornerLength + columnsLength;
151
+ }
152
+ /**
153
+ * Returns deep level of the tree
154
+ *
155
+ * @param {Array<TreeNode> | TreeNode} item - tree node or list of nodes
156
+ * @returns {number} - count of last children
157
+ */
158
+ getTreeDeepsLength(item) {
159
+ if (this.columnsTreeService) {
160
+ return this.columnsTreeService.getTreeDeepsLength(item);
161
+ }
162
+ return this.cornerTreeService ? this.cornerTreeService.getTreeDeepsLength(item) : 0;
163
+ }
164
+ /**
165
+ * Sets value node when it's single
166
+ *
167
+ * @param {TreeNode} valueNode - values measure node
168
+ * @returns {void}
169
+ */
170
+ setValueNode(valueNode) {
171
+ if (this.columnsTreeService) {
172
+ this.columnsTreeService.setValueNode(valueNode);
173
+ }
174
+ }
175
+ /**
176
+ * Returns cell meta information
177
+ *
178
+ * @param {number} rowIndex - cell row index
179
+ * @param {number} columnIndex - cell column index
180
+ * @param {{ to: number }} [options] - additional configuration options
181
+ * @returns {{levels: Array<string>, siblings: Array<string>}} - meta information
182
+ */
183
+ getMetadata(rowIndex, columnIndex, options) {
184
+ if (columnIndex >= this.cornerOffset && this.columnsTreeService) {
185
+ return this.columnsTreeService.getMetadata(rowIndex, columnIndex - this.cornerOffset, options);
186
+ // eslint-disable-next-line max-lines
187
+ }
188
+ return this.cornerTreeService
189
+ ? this.cornerTreeService.getMetadata(rowIndex, columnIndex, options)
190
+ : undefined;
191
+ }
192
+ destroy() {
193
+ if (this.cornerTreeService) {
194
+ this.cornerTreeService.destroy();
195
+ }
196
+ if (this.columnsTreeService) {
197
+ this.columnsTreeService.destroy();
198
+ }
199
+ this.cornerTreeService = undefined;
200
+ this.columnsTreeService = undefined;
201
+ }
202
+ /**
203
+ * Returns array of last tree nodes
204
+ * Should not be called for header
205
+ *
206
+ * @returns {Array<TreeNode>} - list of tree nodes
207
+ * @deprecated
208
+ */
209
+ getLastLevelNodes() {
210
+ throw new Error(`"${this.constructor.name}.getLastLevelNodes" should not be called`);
211
+ // TODO review this
212
+ return this; // eslint-disable-line no-unreachable
213
+ }
214
+ /**
215
+ * Extract 2D array of data base on columnsTreeService
216
+ * Should not be called for header
217
+ *
218
+ * @param {TreeServiceI} columnsTreeService - tree service according to which align the data
219
+ * @returns {Array<Array<any>>} - 2D array of data
220
+ * @deprecated
221
+ */
222
+ extractData(columnsTreeService) {
223
+ throw new Error(`"${this.constructor.name}.extractData" should not be called`);
224
+ // TODO review this
225
+ return this || columnsTreeService; // eslint-disable-line no-unreachable
226
+ }
227
+ /**
228
+ * Adds additional tree node to current state
229
+ * Should not be called for header
230
+ *
231
+ * @param {TreeNode} tree - new treeNode
232
+ * @returns {void}
233
+ * @deprecated
234
+ */
235
+ extend(tree) {
236
+ throw new Error(`"${this.constructor.name}.extend" should not be called`);
237
+ // TODO review this
238
+ // return (this as unknown as void) || (tree as unknown as void); // eslint-disable-line no-unreachable
239
+ }
240
+ /**
241
+ * Returns part of current tree with possible cut nodes according to "from" - "to" position
242
+ * Should not be called for header
243
+ *
244
+ * @param {number} from - start rows index for partial grid
245
+ * @param {number} [to] - stop rows index for partial grid
246
+ * @param {object} [options] - additional options
247
+ * @param {Function} [options.cloneFn] - replace default clone function with specific one
248
+ * @returns {Array<TreeNode>} - partial tree
249
+ * @deprecated
250
+ */
251
+ getPartialTree(from, to, options) {
252
+ throw new Error(`"${this.constructor.name}.getPartialTree" should not be called`);
253
+ // TODO review this
254
+ return (this ||
255
+ from ||
256
+ to ||
257
+ options); // eslint-disable-line no-unreachable
258
+ }
259
+ /**
260
+ * Returns part of current grid according to "from" - "to" position
261
+ * Should not be called for header
262
+ *
263
+ * @param {number} from - start rows index for partial grid
264
+ * @param {number} to - stop rows index for partial grid
265
+ * @returns {Array<Array<TreeNode | string>>} - partial grid
266
+ * @deprecated
267
+ */
268
+ getPartialGrid(from, to) {
269
+ throw new Error(`"${this.constructor.name}.getPartialGrid" should not be called`);
270
+ // TODO review this
271
+ return (this ||
272
+ from ||
273
+ to); // eslint-disable-line no-unreachable
274
+ }
275
+ }
276
+ export default HeaderTreeService;
@@ -0,0 +1,104 @@
1
+ import { TreeCellMapI, TreeNode } from './types.js';
2
+ /**
3
+ * TreeCellMap keep mapping between grid cells and tree nodes
4
+ */
5
+ export declare class TreeCellMap implements TreeCellMapI {
6
+ rowIndex: number;
7
+ colIndex: number;
8
+ node?: TreeNode;
9
+ parent?: string;
10
+ /**
11
+ @private */
12
+ childColCells: Array<TreeCellMapI>;
13
+ /**
14
+ @private */
15
+ childRowCells: Array<TreeCellMapI>;
16
+ /**
17
+ @private */
18
+ indexInParent: number;
19
+ /**
20
+ @private */
21
+ siblingCount: number;
22
+ constructor(rowIndex: number, colIndex: number, node?: TreeNode, parent?: string);
23
+ /**
24
+ * Defines if grid cell is child or main one
25
+ *
26
+ * @returns {boolean} - true - is children, false - main one
27
+ */
28
+ isChild(): boolean;
29
+ /**
30
+ * Defines if node has child row or column nodes or not
31
+ *
32
+ * @returns {boolean} - true - has children, false - does not have
33
+ */
34
+ hasChildren(): boolean;
35
+ /**
36
+ * Defines if node has child column nodes or not
37
+ *
38
+ * @returns {boolean} - true - has column children, false - does not have
39
+ */
40
+ hasColCell(): boolean;
41
+ /**
42
+ * Adds column children cell
43
+ *
44
+ * @param {TreeCellMapI} cell - column children
45
+ * @returns {void}
46
+ */
47
+ addColCell(cell: TreeCellMapI): void;
48
+ /**
49
+ * Returns list of column children
50
+ *
51
+ * @returns {Array<TreeCellMapI>} - list of column children
52
+ */
53
+ getColCell(): Array<TreeCellMapI>;
54
+ /**
55
+ * Defines if node has child row nodes or not
56
+ *
57
+ * @returns {boolean} - true - has row children, false - does not have
58
+ */
59
+ hasRowCell(): boolean;
60
+ /**
61
+ * Adds row children cell
62
+ *
63
+ * @param {TreeCellMapI} cell - row children
64
+ * @returns {void}
65
+ */
66
+ addRowCell(cell: TreeCellMapI): void;
67
+ /**
68
+ * Returns list of row children
69
+ *
70
+ * @returns {Array<TreeCellMapI>} - list of row children
71
+ */
72
+ getRowCell(): Array<TreeCellMapI>;
73
+ /**
74
+ * Returns row index of last merged cell
75
+ *
76
+ * @returns {number} - row index
77
+ */
78
+ getStopRowIndex(): number;
79
+ /**
80
+ * Returns column index of last merged cell
81
+ *
82
+ * @returns {number} - column index
83
+ */
84
+ getStopColIndex(): number;
85
+ /**
86
+ * Save index of node in parent child and total parent child count
87
+ *
88
+ * @param {number} indexInParent - index
89
+ * @param {number} siblingCount - child count
90
+ * @returns {void}
91
+ */
92
+ setIndexInParent(indexInParent: number, siblingCount: number): void;
93
+ /**
94
+ * Returns node index in parent and total parent child count
95
+ *
96
+ * @returns {{ indexInParent: number, siblingCount: number }} - index & count
97
+ */
98
+ getIndexInParent(): {
99
+ indexInParent: number;
100
+ siblingCount: number;
101
+ };
102
+ getParenPosition(): Array<number> | undefined;
103
+ }
104
+ export default TreeCellMap;
@@ -0,0 +1,141 @@
1
+ /**
2
+ * TreeCellMap keep mapping between grid cells and tree nodes
3
+ */
4
+ export class TreeCellMap {
5
+ constructor(rowIndex, colIndex, node, parent) {
6
+ /**
7
+ @private */
8
+ this.childColCells = [];
9
+ /**
10
+ @private */
11
+ this.childRowCells = [];
12
+ /**
13
+ @private */
14
+ this.indexInParent = -1;
15
+ /**
16
+ @private */
17
+ this.siblingCount = 0;
18
+ this.rowIndex = rowIndex;
19
+ this.colIndex = colIndex;
20
+ this.node = node;
21
+ this.parent = parent;
22
+ }
23
+ /**
24
+ * Defines if grid cell is child or main one
25
+ *
26
+ * @returns {boolean} - true - is children, false - main one
27
+ */
28
+ isChild() {
29
+ return !this.node;
30
+ }
31
+ /**
32
+ * Defines if node has child row or column nodes or not
33
+ *
34
+ * @returns {boolean} - true - has children, false - does not have
35
+ */
36
+ hasChildren() {
37
+ return !!(this.childColCells.length || this.childRowCells.length);
38
+ }
39
+ /**
40
+ * Defines if node has child column nodes or not
41
+ *
42
+ * @returns {boolean} - true - has column children, false - does not have
43
+ */
44
+ hasColCell() {
45
+ return this.childColCells.length > 0;
46
+ }
47
+ /**
48
+ * Adds column children cell
49
+ *
50
+ * @param {TreeCellMapI} cell - column children
51
+ * @returns {void}
52
+ */
53
+ addColCell(cell) {
54
+ this.childColCells.push(cell);
55
+ }
56
+ /**
57
+ * Returns list of column children
58
+ *
59
+ * @returns {Array<TreeCellMapI>} - list of column children
60
+ */
61
+ getColCell() {
62
+ return this.childColCells || [];
63
+ }
64
+ /**
65
+ * Defines if node has child row nodes or not
66
+ *
67
+ * @returns {boolean} - true - has row children, false - does not have
68
+ */
69
+ hasRowCell() {
70
+ return this.childRowCells.length > 0;
71
+ }
72
+ /**
73
+ * Adds row children cell
74
+ *
75
+ * @param {TreeCellMapI} cell - row children
76
+ * @returns {void}
77
+ */
78
+ addRowCell(cell) {
79
+ this.childRowCells.push(cell);
80
+ }
81
+ /**
82
+ * Returns list of row children
83
+ *
84
+ * @returns {Array<TreeCellMapI>} - list of row children
85
+ */
86
+ getRowCell() {
87
+ return this.childRowCells || [];
88
+ }
89
+ /**
90
+ * Returns row index of last merged cell
91
+ *
92
+ * @returns {number} - row index
93
+ */
94
+ getStopRowIndex() {
95
+ if (!this.hasRowCell()) {
96
+ return this.rowIndex;
97
+ }
98
+ return this.rowIndex + this.getRowCell().length;
99
+ }
100
+ /**
101
+ * Returns column index of last merged cell
102
+ *
103
+ * @returns {number} - column index
104
+ */
105
+ getStopColIndex() {
106
+ if (!this.hasColCell()) {
107
+ return this.colIndex;
108
+ }
109
+ return this.colIndex + this.getColCell().length;
110
+ }
111
+ /**
112
+ * Save index of node in parent child and total parent child count
113
+ *
114
+ * @param {number} indexInParent - index
115
+ * @param {number} siblingCount - child count
116
+ * @returns {void}
117
+ */
118
+ setIndexInParent(indexInParent, siblingCount) {
119
+ this.indexInParent = indexInParent;
120
+ this.siblingCount = siblingCount;
121
+ }
122
+ /**
123
+ * Returns node index in parent and total parent child count
124
+ *
125
+ * @returns {{ indexInParent: number, siblingCount: number }} - index & count
126
+ */
127
+ getIndexInParent() {
128
+ return {
129
+ indexInParent: this.indexInParent,
130
+ siblingCount: this.siblingCount,
131
+ };
132
+ }
133
+ getParenPosition() {
134
+ if (!this.parent) {
135
+ return undefined;
136
+ }
137
+ const res = (this.parent || '').match(/\d+/g) || [];
138
+ return [Number(res[0]), Number(res[1])];
139
+ }
140
+ }
141
+ export default TreeCellMap;