@gridsuite/commons-ui 0.29.1 → 0.30.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.
@@ -0,0 +1,667 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.noOpHelper = exports.getHelper = exports.forTesting = exports.collectibleHelper = exports.KeyedColumnsRowIndexer = exports.CHANGE_WAYS = void 0;
5
+
6
+ var _algos = require("../../utils/algos");
7
+
8
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13
+
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
+
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
20
+ var CHANGE_WAYS = {
21
+ SIMPLE: 'Simple',
22
+ TAIL: 'Tail',
23
+ AMEND: 'Amend',
24
+ REMOVE: 'Remove'
25
+ };
26
+ /*
27
+ const someTypicalColumns = [
28
+ { label: 'strings column', dataKey: 'key1' },
29
+ {
30
+ label: 'integers column',
31
+ dataKey: 'key2',
32
+ numeric: true,
33
+ fractionDigits: 0,
34
+ },
35
+ {
36
+ label: 'column to ignore',
37
+ dataKey: 'key3',
38
+ nostat: true,
39
+ },
40
+ ];
41
+ */
42
+
43
+ exports.CHANGE_WAYS = CHANGE_WAYS;
44
+ var noOpHelper = Object.freeze({
45
+ debugName: 'noOp',
46
+ maintainsStats: false,
47
+ initStat: function initStat() {
48
+ return undefined;
49
+ },
50
+ updateStat: function updateStat(colStat, value) {},
51
+ accepts: function accepts(value, userParams, outerParams) {
52
+ return true;
53
+ }
54
+ });
55
+ exports.noOpHelper = noOpHelper;
56
+ var numericHelper = Object.freeze({
57
+ debugName: 'num',
58
+ maintainsStats: true,
59
+ initStat: function initStat() {
60
+ return {
61
+ imin: null,
62
+ imax: null
63
+ };
64
+ },
65
+ updateStat: function updateStat(colStat, value) {
66
+ if (colStat.imin === null || colStat.imin > value) {
67
+ colStat.imin = value;
68
+ }
69
+
70
+ if (colStat.imax === null || colStat.imax < value) {
71
+ colStat.imax = value;
72
+ }
73
+ },
74
+ accepts: function accepts(value, userParams, outerParams) {
75
+ return true;
76
+ }
77
+ });
78
+ var collectibleHelper = Object.freeze({
79
+ debugName: 'collectible',
80
+ maintainsStats: true,
81
+ initStat: function initStat() {
82
+ return {
83
+ seen: {},
84
+ kept: {}
85
+ };
86
+ },
87
+ updateStat: function updateStat(colStat, cellValue, isForKeep) {
88
+ var m = isForKeep ? colStat.kept : colStat.seen;
89
+ if (!m[cellValue]) m[cellValue] = 1;else m[cellValue] += 1;
90
+ },
91
+ accepts: function accepts(value, userParams, outerParams) {
92
+ return !userParams || userParams.some(function (v) {
93
+ return v === value;
94
+ });
95
+ }
96
+ });
97
+ exports.collectibleHelper = collectibleHelper;
98
+
99
+ var getHelper = function getHelper(column) {
100
+ if (column === null || column === void 0 ? void 0 : column.numeric) {
101
+ return numericHelper;
102
+ } else if (!(column === null || column === void 0 ? void 0 : column.nostat)) {
103
+ return collectibleHelper;
104
+ } else {
105
+ return noOpHelper;
106
+ }
107
+ };
108
+ /**
109
+ * A rows indexer for MuiVirtualizedTable to delegate to an instance of it
110
+ * for filtering, grouping and multi-column sorting via
111
+ * a view index to model index array.
112
+ */
113
+
114
+
115
+ exports.getHelper = getHelper;
116
+
117
+ var KeyedColumnsRowIndexer = /*#__PURE__*/function () {
118
+ function KeyedColumnsRowIndexer(isThreeState, singleColumnByDefault, delegatorCallback, versionSetter) {
119
+ var _this = this;
120
+
121
+ if (isThreeState === void 0) {
122
+ isThreeState = true;
123
+ }
124
+
125
+ if (singleColumnByDefault === void 0) {
126
+ singleColumnByDefault = false;
127
+ }
128
+
129
+ if (delegatorCallback === void 0) {
130
+ delegatorCallback = null;
131
+ }
132
+
133
+ if (versionSetter === void 0) {
134
+ versionSetter = null;
135
+ }
136
+
137
+ _defineProperty(this, "hasVersionSetter", function () {
138
+ return !!_this._versionSetter;
139
+ });
140
+
141
+ _defineProperty(this, "getVersion", function () {
142
+ return _this.version;
143
+ });
144
+
145
+ _defineProperty(this, "_bumpVersion", function (isFilter) {
146
+ if (isFilter === void 0) {
147
+ isFilter = false;
148
+ }
149
+
150
+ _this.version += 1;
151
+
152
+ if (isFilter) {
153
+ _this.filterVersion = _this.version;
154
+ }
155
+
156
+ if (_this.delegatorCallback) {
157
+ _this.indirectionStatus = 'to sort';
158
+
159
+ _this.delegatorCallback(_this, function (updated_ok) {
160
+ _this.indirectionStatus = updated_ok ? 'done' : 'no_luck';
161
+ });
162
+ }
163
+
164
+ if (_this._versionSetter) {
165
+ _this._versionSetter(_this.version);
166
+ }
167
+ });
168
+
169
+ _defineProperty(this, "updatePreferences", function (preferences) {
170
+ if (preferences.isThreeState === _this.isThreeState && preferences.singleColumnByDefault === _this.singleColumnByDefault) {
171
+ return false;
172
+ }
173
+
174
+ if (preferences.isThreeState !== _this.isThreeState) {
175
+ _this.isThreeState = preferences.isThreeState;
176
+ }
177
+
178
+ if (preferences.singleColumnByDefault !== _this.singleColumnByDefault) {
179
+ _this.singleColumnByDefault = preferences.singleColumnByDefault;
180
+ }
181
+
182
+ _this._bumpVersion();
183
+ });
184
+
185
+ _defineProperty(this, "preFilterRowMapping", function (columns, rows) {
186
+ if (!(rows === null || rows === void 0 ? void 0 : rows.length) || !(columns === null || columns === void 0 ? void 0 : columns.length)) return null;
187
+ var ri = [];
188
+ var cs = {};
189
+
190
+ for (var colIdx = 0; colIdx < columns.length; colIdx++) {
191
+ var col = columns[colIdx];
192
+ var helper = getHelper(col);
193
+ var colStat = helper.initStat();
194
+
195
+ if (colStat) {
196
+ cs[col.dataKey] = colStat;
197
+ }
198
+ }
199
+
200
+ for (var rowIdx = 0; rowIdx < rows.length; rowIdx++) {
201
+ var row = rows[rowIdx];
202
+ var acceptsRow = true;
203
+ var acceptedOnRow = {};
204
+
205
+ for (var _colIdx = 0; _colIdx < columns.length; _colIdx++) {
206
+ var _this$byColFilter;
207
+
208
+ var _col = columns[_colIdx];
209
+
210
+ var _helper = getHelper(_col);
211
+
212
+ var colKey = _col.dataKey;
213
+ var cellValue = row[colKey];
214
+
215
+ _helper.updateStat(cs[colKey], cellValue, false);
216
+
217
+ var colFilterParams = (_this$byColFilter = _this.byColFilter) === null || _this$byColFilter === void 0 ? void 0 : _this$byColFilter[colKey];
218
+ var acceptsCell = true;
219
+
220
+ if (colFilterParams) {
221
+ var up = colFilterParams.userParams;
222
+ var op = colFilterParams.outerParams;
223
+
224
+ if (!_helper.accepts(cellValue, up, op)) {
225
+ acceptsCell = false;
226
+ }
227
+ }
228
+
229
+ if (_helper.maintainsStats && acceptsCell) {
230
+ acceptedOnRow[_colIdx] = cellValue;
231
+ }
232
+
233
+ acceptsRow &= acceptsCell;
234
+ }
235
+
236
+ if (acceptsRow && _this.byRowFilter) {
237
+ acceptsRow = _this.byRowFilter(row);
238
+ }
239
+
240
+ if (acceptsRow) {
241
+ for (var _i = 0, _Object$entries = Object.entries(acceptedOnRow); _i < _Object$entries.length; _i++) {
242
+ var _Object$entries$_i = _Object$entries[_i],
243
+ idx = _Object$entries$_i[0],
244
+ value = _Object$entries$_i[1];
245
+ var _col2 = columns[idx];
246
+
247
+ var _helper2 = getHelper(_col2);
248
+
249
+ _helper2.updateStat(cs[_col2.dataKey], value, true);
250
+ }
251
+
252
+ ri.push([row, rowIdx]);
253
+ }
254
+ }
255
+
256
+ return {
257
+ rowAndOrigIndex: ri,
258
+ colsStats: cs,
259
+ rowsCount: rows.length
260
+ };
261
+ });
262
+
263
+ _defineProperty(this, "makeGroupAndSortIndirector", function (preFilteredRowPairs, columns) {
264
+ if (!preFilteredRowPairs) return null;
265
+ var codedColumns = !_this.sortingState ? null : codedColumnsFromKeyAndDirection(_this.sortingState, columns);
266
+ var groupingColumnsCount = _this.groupingCount;
267
+ var indexedArray = groupAndSort(preFilteredRowPairs, codedColumns, groupingColumnsCount, columns);
268
+ return !indexedArray ? null : indexedArray.map(function (k) {
269
+ return k[1];
270
+ });
271
+ });
272
+
273
+ _defineProperty(this, "getSortingAsKeyAndCodedRank", function () {
274
+ if (!_this.sortingState) return [];
275
+ return _this.sortingState.map(function (kd, i) {
276
+ var sign = giveDirSignFor(kd[1]);
277
+ var codedRank = sign * (i + 1);
278
+ return [kd[0], codedRank];
279
+ });
280
+ });
281
+
282
+ _defineProperty(this, "updateSortingFromUser", function (colKey, change_way) {
283
+ var keyAndDirections = _this.sortingState;
284
+
285
+ if (change_way === CHANGE_WAYS.REMOVE) {
286
+ if (!keyAndDirections) {
287
+ return false;
288
+ }
289
+
290
+ var would = keyAndDirections.filter(function (p) {
291
+ return p[0] !== colKey;
292
+ });
293
+
294
+ if (would.length === keyAndDirections.length) {
295
+ return false;
296
+ }
297
+
298
+ _this.sortingState = would.length ? would : null;
299
+ } else if (!keyAndDirections) {
300
+ _this.sortingState = [[colKey, canonicalForSign(1)]];
301
+ _this.lastUsedRank = 1;
302
+ } else {
303
+ var wasAtIdx = keyAndDirections.findIndex(function (p) {
304
+ return p[0] === colKey;
305
+ });
306
+ var wasFuzzyDir = wasAtIdx < 0 ? 0 : keyAndDirections[wasAtIdx][1];
307
+ var wasSignDir = giveDirSignFor(wasFuzzyDir);
308
+
309
+ if (change_way === CHANGE_WAYS.SIMPLE) {
310
+ if (wasSignDir < 0 && _this.isThreeState) {
311
+ if (_this.sortingState.length === 1) {
312
+ _this.sortingState = null;
313
+ } else {
314
+ _this.sortingState.splice(wasAtIdx, 1);
315
+ }
316
+ } else {
317
+ if (_this.singleColumnByDefault || wasAtIdx < 0) {
318
+ _this.sortingState = [];
319
+ } else {
320
+ _this.sortingState.splice(wasAtIdx, 1);
321
+ }
322
+
323
+ var nextSign = wasSignDir ? -wasSignDir : 1;
324
+ var nextKD = [colKey, canonicalForSign(nextSign)];
325
+
326
+ _this.sortingState.unshift(nextKD);
327
+ }
328
+ } else if (change_way === CHANGE_WAYS.TAIL) {
329
+ if (wasAtIdx < 0) {
330
+ _this.sortingState.push([colKey, canonicalForSign(1)]);
331
+ } else if (wasAtIdx !== keyAndDirections.length - 1) {
332
+ return false;
333
+ } else if (!(_this.isThreeState && wasSignDir === -1)) {
334
+ _this.sortingState[wasAtIdx][1] = canonicalForSign(-wasSignDir);
335
+ } else {
336
+ _this.sortingState.splice(wasAtIdx, 1);
337
+ }
338
+ } else {
339
+ // AMEND
340
+ if (wasAtIdx < 0) {
341
+ if (_this.lastUsedRank - 1 > _this.sortingState.length) {
342
+ return false;
343
+ } else {
344
+ _this.sortingState.splice(_this.lastUsedRank - 1, 0, [colKey, canonicalForSign(1)]);
345
+ }
346
+ } else if (!(_this.isThreeState && wasSignDir === -1)) {
347
+ _this.sortingState[wasAtIdx][1] = canonicalForSign(-wasSignDir);
348
+ } else {
349
+ _this.lastUsedRank = wasAtIdx + 1;
350
+
351
+ _this.sortingState.splice(wasAtIdx, 1);
352
+ }
353
+ }
354
+ }
355
+
356
+ _this._bumpVersion();
357
+
358
+ return true;
359
+ });
360
+
361
+ _defineProperty(this, "codedRankByColumnIndex", function (columns) {
362
+ return codedColumnsFromKeyAndDirection(_this.sortingState, columns);
363
+ });
364
+
365
+ _defineProperty(this, "columnSortingSignedRank", function (colKey) {
366
+ var _this$sortingState;
367
+
368
+ if (!(_this === null || _this === void 0 ? void 0 : (_this$sortingState = _this.sortingState) === null || _this$sortingState === void 0 ? void 0 : _this$sortingState.length)) return 0;
369
+
370
+ var idx = _this.sortingState.findIndex(function (kd) {
371
+ return kd[0] === colKey;
372
+ });
373
+
374
+ if (idx < 0) return 0;
375
+ var colSorting = _this.sortingState[idx];
376
+ return giveDirSignFor(colSorting[1]) * (idx + 1);
377
+ });
378
+
379
+ _defineProperty(this, "highestCodedColumn", function (columns) {
380
+ var _this$sortingState2;
381
+
382
+ if (!(_this === null || _this === void 0 ? void 0 : (_this$sortingState2 = _this.sortingState) === null || _this$sortingState2 === void 0 ? void 0 : _this$sortingState2.length)) return 0;
383
+ var colSorting = _this.sortingState[0];
384
+ var colKey = colSorting[0];
385
+ var idx = columns.findIndex(function (col) {
386
+ return col.dataKey === colKey;
387
+ });
388
+ if (idx < 0) return 0;
389
+ return giveDirSignFor(colSorting[1]) * (idx + 1);
390
+ });
391
+
392
+ _defineProperty(this, "_getColFilterParams", function (colKey, isForUser) {
393
+ if (!colKey || !_this.byColFilter) {
394
+ return undefined;
395
+ }
396
+
397
+ var colFilter = _this.byColFilter[colKey];
398
+
399
+ if (!colFilter) {
400
+ return undefined;
401
+ }
402
+
403
+ return colFilter[isForUser ? 'userParams' : 'outerParams'];
404
+ });
405
+
406
+ _defineProperty(this, "_setColFilterParams", function (colKey, params, isForUser) {
407
+ if (!colKey) {
408
+ if (params) {
409
+ throw new Error('column key has to be defined');
410
+ }
411
+
412
+ return false;
413
+ }
414
+
415
+ var fieldName = isForUser ? 'userParams' : 'outerParams';
416
+
417
+ if (params) {
418
+ if (!_this.byColFilter) {
419
+ _this.byColFilter = {};
420
+ }
421
+
422
+ var colFilter = _this.byColFilter[colKey];
423
+
424
+ if (!colFilter) {
425
+ colFilter = {};
426
+ _this.byColFilter[colKey] = colFilter;
427
+ } else if (colFilter[fieldName] === params) {
428
+ return false;
429
+ }
430
+
431
+ colFilter[fieldName] = params;
432
+ } else {
433
+ var _this$byColFilter$col;
434
+
435
+ if (!_this.byColFilter) {
436
+ return false;
437
+ }
438
+
439
+ var otherFieldName = !isForUser ? 'userParams' : 'outerParams';
440
+
441
+ if ((_this$byColFilter$col = _this.byColFilter[colKey]) === null || _this$byColFilter$col === void 0 ? void 0 : _this$byColFilter$col[otherFieldName]) {
442
+ delete _this.byColFilter[colKey][fieldName];
443
+ } else {
444
+ delete _this.byColFilter[colKey];
445
+ }
446
+ }
447
+
448
+ if (isForUser) {
449
+ _this._bumpVersion(true);
450
+ }
451
+
452
+ return true;
453
+ });
454
+
455
+ _defineProperty(this, "getColFilterOuterParams", function (colKey) {
456
+ return _this._getColFilterParams(colKey, false);
457
+ });
458
+
459
+ _defineProperty(this, "setColFilterOuterParams", function (colKey, outerParams) {
460
+ return _this._setColFilterParams(colKey, outerParams, false);
461
+ });
462
+
463
+ _defineProperty(this, "getColFilterUserParams", function (colKey) {
464
+ return _this._getColFilterParams(colKey, true);
465
+ });
466
+
467
+ _defineProperty(this, "setColFilterUserParams", function (colKey, params) {
468
+ return _this._setColFilterParams(colKey, params, true);
469
+ });
470
+
471
+ _defineProperty(this, "getUserFiltering", function () {
472
+ var ret = {};
473
+
474
+ if (_this.byColFilter) {
475
+ Object.entries(_this.byColFilter).forEach(function (_ref) {
476
+ var k = _ref[0],
477
+ v = _ref[1];
478
+ if (!v.userParams) return;
479
+ ret[k] = [].concat(v.userParams);
480
+ });
481
+ }
482
+
483
+ return ret;
484
+ });
485
+
486
+ _defineProperty(this, "updateRowFiltering", function (rowFilterFunc) {
487
+ if (typeof rowFilterFunc !== 'function') {
488
+ throw new Error('row filter should be a function');
489
+ }
490
+
491
+ _this.byRowFilter = rowFilterFunc;
492
+
493
+ _this._bumpVersion();
494
+ });
495
+
496
+ console.debug('KeyedColumnsRowIndexer');
497
+ this._versionSetter = versionSetter;
498
+ this.version = 0;
499
+ this.filterVersion = 0;
500
+ this.delegatorCallback = delegatorCallback;
501
+ this.indirectionStatus = null;
502
+ this.isThreeState = isThreeState;
503
+ this.singleColumnByDefault = singleColumnByDefault;
504
+ this.lastUsedRank = 1;
505
+ this.sortingState = null;
506
+ this.groupingCount = 0;
507
+ this.byColFilter = null; // common
508
+
509
+ this.byRowFilter = null;
510
+ }
511
+
512
+ _createClass(KeyedColumnsRowIndexer, null, [{
513
+ key: "CHANGE_WAYS",
514
+ get: function get() {
515
+ return CHANGE_WAYS;
516
+ }
517
+ }]);
518
+
519
+ return KeyedColumnsRowIndexer;
520
+ }();
521
+
522
+ exports.KeyedColumnsRowIndexer = KeyedColumnsRowIndexer;
523
+
524
+ var giveDirSignFor = function giveDirSignFor(fuzzySign) {
525
+ if (fuzzySign < 0) return -1;
526
+ if (fuzzySign > 0) return 1;
527
+ if (fuzzySign === 'asc') return 1;
528
+ if (fuzzySign === 'desc') return -1;
529
+ return 0;
530
+ };
531
+
532
+ var canonicalForSign = function canonicalForSign(dirSign) {
533
+ if (dirSign > 0) return 'asc';
534
+ if (dirSign < 0) return 'desc';
535
+ return undefined;
536
+ };
537
+
538
+ var codedColumnsFromKeyAndDirection = function codedColumnsFromKeyAndDirection(keyAndDirections, columns) {
539
+ if (!keyAndDirections) return null;
540
+ var ret = [];
541
+ var columIndexByKey = {};
542
+
543
+ for (var colIdx = 0; colIdx < columns.length; colIdx++) {
544
+ var col = columns[colIdx];
545
+ var colKey = col.dataKey;
546
+ columIndexByKey[colKey] = colIdx;
547
+ }
548
+
549
+ for (var i = 0; i < keyAndDirections.length; i++) {
550
+ var knd = keyAndDirections[i];
551
+ var _colKey = knd[0];
552
+ var dir = knd[1];
553
+ var _colIdx2 = columIndexByKey[_colKey];
554
+ if (_colIdx2 === undefined) continue;
555
+ var sign = giveDirSignFor(dir);
556
+ ret.push((_colIdx2 + 1) * sign);
557
+ }
558
+
559
+ return ret;
560
+ };
561
+
562
+ var compareValue = function compareValue(a, b, isNumeric, undefSign) {
563
+ if (undefSign === void 0) {
564
+ undefSign = -1;
565
+ }
566
+
567
+ if (a === undefined && b === undefined) return 0;else if (a === undefined) return undefSign;else if (b === undefined) return -undefSign;
568
+ return isNumeric ? Math.sign(Number(a) - Number(b)) : ('' + a).localeCompare(b);
569
+ };
570
+
571
+ var makeCompositeComparatorFromCodedColumns = function makeCompositeComparatorFromCodedColumns(codedColumns, columns, rowExtractor) {
572
+ return function (row_a_i, row_b_i) {
573
+ var row_a = rowExtractor(row_a_i);
574
+ var row_b = rowExtractor(row_b_i);
575
+
576
+ for (var _iterator = _createForOfIteratorHelperLoose(codedColumns), _step; !(_step = _iterator()).done;) {
577
+ var cc = _step.value;
578
+ var i = Math.abs(cc) - 1;
579
+ var mul = Math.sign(cc);
580
+ var col = columns[i];
581
+ var key = col.dataKey;
582
+ var sgn = compareValue(row_a[key], row_b[key], col.numeric);
583
+
584
+ if (sgn) {
585
+ return mul * sgn;
586
+ }
587
+ }
588
+
589
+ return 0;
590
+ };
591
+ };
592
+
593
+ var groupRows = function groupRows(groupingColumnsCount, columns, indexedArray) {
594
+ var groupingComparator = makeCompositeComparatorFromCodedColumns(Array(groupingColumnsCount).map(function (x, i) {
595
+ return i + 1;
596
+ }), columns, function (ar) {
597
+ return ar[0];
598
+ });
599
+ indexedArray.sort(groupingComparator);
600
+ var groups = [];
601
+ var prevSlice = null;
602
+ var inBuildGroup = [];
603
+ groups.push(inBuildGroup);
604
+
605
+ for (var _iterator2 = _createForOfIteratorHelperLoose(indexedArray), _step2; !(_step2 = _iterator2()).done;) {
606
+ var p = _step2.value;
607
+ var nextSlice = p[0].slice(0, groupingColumnsCount);
608
+
609
+ if (prevSlice === null || !(0, _algos.equalsArray)(prevSlice, nextSlice)) {
610
+ inBuildGroup = [];
611
+ groups.push(inBuildGroup);
612
+ }
613
+
614
+ inBuildGroup.push(p);
615
+ prevSlice = nextSlice;
616
+ }
617
+
618
+ return groups;
619
+ };
620
+
621
+ var groupAndSort = function groupAndSort(preFilteredRowPairs, codedColumns, groupingColumnsCount, columns) {
622
+ var nothingToDo = !codedColumns && !groupingColumnsCount;
623
+ var indexedArray = preFilteredRowPairs.rowAndOrigIndex;
624
+ var noOutFiltered = preFilteredRowPairs.rowsCount === indexedArray.length;
625
+
626
+ if (nothingToDo && noOutFiltered) {
627
+ return null;
628
+ } else if (!nothingToDo) {
629
+ // make a copy for not losing base order
630
+ indexedArray = [].concat(indexedArray);
631
+ }
632
+
633
+ if (nothingToDo) {// just nothing
634
+ } else if (!groupingColumnsCount) {
635
+ var sortingComparator = makeCompositeComparatorFromCodedColumns(codedColumns, columns, function (ar) {
636
+ return ar[0];
637
+ });
638
+ indexedArray.sort(sortingComparator);
639
+ } else {
640
+ var groups = groupRows(groupingColumnsCount, columns, indexedArray);
641
+ var interGroupSortingComparator = makeCompositeComparatorFromCodedColumns(codedColumns, columns, function (ar) {
642
+ return ar[0][0];
643
+ });
644
+ groups.sort(interGroupSortingComparator);
645
+ var intraGroupSortingComparator = makeCompositeComparatorFromCodedColumns(codedColumns, columns, function (ar) {
646
+ return ar[0];
647
+ });
648
+ indexedArray = [];
649
+
650
+ for (var _iterator3 = _createForOfIteratorHelperLoose(groups), _step3; !(_step3 = _iterator3()).done;) {
651
+ var _indexedArray;
652
+
653
+ var group = _step3.value;
654
+ group.sort(intraGroupSortingComparator);
655
+
656
+ (_indexedArray = indexedArray).push.apply(_indexedArray, group);
657
+ }
658
+ }
659
+
660
+ return indexedArray;
661
+ };
662
+
663
+ var forTesting = {
664
+ codedColumnsFromKeyAndDirection: codedColumnsFromKeyAndDirection,
665
+ makeCompositeComparatorFromCodedColumns: makeCompositeComparatorFromCodedColumns
666
+ };
667
+ exports.forTesting = forTesting;