@odoo/o-spreadsheet 17.0.19 → 17.0.20

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.
@@ -2,9 +2,9 @@
2
2
  /**
3
3
  * This file is generated by o-spreadsheet build tools. Do not edit it.
4
4
  * @see https://github.com/odoo/o-spreadsheet
5
- * @version 17.0.19
6
- * @date 2024-04-18T16:41:42.291Z
7
- * @hash 9f3317a
5
+ * @version 17.0.20
6
+ * @date 2024-04-26T07:37:04.503Z
7
+ * @hash 065ac98
8
8
  */
9
9
 
10
10
  (function (exports, owl) {
@@ -26667,17 +26667,13 @@
26667
26667
  this.env.focusableElement.setFocusableElement(el);
26668
26668
  }
26669
26669
  this.contentHelper.updateEl(el);
26670
- this.processTokenAtCursor();
26671
26670
  });
26672
26671
  owl.useEffect(() => {
26673
26672
  this.processContent();
26674
26673
  });
26675
- owl.onPatched(() => {
26676
- // Required because typing '=SUM' and double-clicking another cell leaves ShowProvider/ShowDescription true
26677
- if (this.env.model.getters.getEditionMode() === "inactive") {
26678
- this.processTokenAtCursor();
26679
- }
26680
- });
26674
+ owl.useEffect(() => {
26675
+ this.processTokenAtCursor();
26676
+ }, () => [this.env.model.getters.getEditionMode() !== "inactive"]);
26681
26677
  }
26682
26678
  // ---------------------------------------------------------------------------
26683
26679
  // Handlers
@@ -27108,6 +27104,7 @@
27108
27104
  const dataValidationAutocompleteValues = this.env.model.getters.getAutoCompleteDataValidationValues();
27109
27105
  if (!content.startsWith("=") && dataValidationAutocompleteValues.length) {
27110
27106
  this.showDataValidationAutocomplete(dataValidationAutocompleteValues);
27107
+ return;
27111
27108
  }
27112
27109
  if (content.startsWith("=")) {
27113
27110
  const token = this.env.model.getters.getTokenAtCursor();
@@ -34367,7 +34364,7 @@
34367
34364
  this.clearBorders(cmd.sheetId, cmd.target);
34368
34365
  break;
34369
34366
  case "REMOVE_COLUMNS_ROWS":
34370
- for (let el of cmd.elements) {
34367
+ for (let el of [...cmd.elements].sort((a, b) => b - a)) {
34371
34368
  if (cmd.dimension === "COL") {
34372
34369
  this.shiftBordersHorizontally(cmd.sheetId, el + 1, -1);
34373
34370
  }
@@ -40147,6 +40144,353 @@
40147
40144
  }
40148
40145
  }
40149
40146
 
40147
+ /**
40148
+ * ####################################################
40149
+ * # INTRODUCTION
40150
+ * ####################################################
40151
+ *
40152
+ * This file contain the function recomputeZones.
40153
+ * This function try to recompute in a performant way
40154
+ * an ensemble of zones possibly overlapping to avoid
40155
+ * overlapping and to reduce the number of zones.
40156
+ *
40157
+ * It also allows to remove some zones from the ensemble.
40158
+ *
40159
+ * In the following example, 2 zones are overlapping.
40160
+ * Applying recomputeZones will return zones without
40161
+ * overlapping:
40162
+ *
40163
+ * ["B3:D4", "D2:E3"] ["B3:C4", "D2:D4", "E2:E3"]
40164
+ *
40165
+ * A B C D E A B C D E
40166
+ * 1 ___ 1 ___
40167
+ * 2 ___|_ | 2 ___| | |
40168
+ * 3 | |_|_| ---> 3 | | |_|
40169
+ * 4 |_____| 4 |___|_|
40170
+ * 6 6
40171
+ * 7 7
40172
+ *
40173
+ *
40174
+ * In the following example, 2 zones are contiguous.
40175
+ * Applying recomputeZones will return only one zone:
40176
+ *
40177
+ * ["B2:B3", "C2:D3"] ["B2:D3"]
40178
+ *
40179
+ * A B C D E A B C D E
40180
+ * 1 _ ___ 1 _____
40181
+ * 2 | | | ---> 2 | |
40182
+ * 3 |_|___| 3 |_____|
40183
+ * 4 4
40184
+ *
40185
+ *
40186
+ * In the following example, we want to remove a zone
40187
+ * from the ensemble. Applying recomputeZones will
40188
+ * return the ensemble without the zone to remove:
40189
+ *
40190
+ * remove ["C3:D3"] ["B2:B4", "C2:D2",
40191
+ * "C4:D4", "E2:E4"]
40192
+ *
40193
+ * A B C D E F A B C D E F
40194
+ * 1 _______ 1 _______
40195
+ * 2 | | ---> 2 | |___| |
40196
+ * 3 | xxx | 3 | |___| |
40197
+ * 4 |_______| 4 |_|___|_|
40198
+ * 5 5
40199
+ *
40200
+ *
40201
+ * The exercise seems simple when we have only 2 zones.
40202
+ * But with n zones and in a performant way, we want to
40203
+ * avoid comparing each zone with all the others.
40204
+ *
40205
+ *
40206
+ * ####################################################
40207
+ * # Methodological approach
40208
+ * ####################################################
40209
+ *
40210
+ * The methodological approach to avoid comparing each
40211
+ * zone with all the others is to use a data structure
40212
+ * that allow to quickly find which zones are
40213
+ * overlapping with any other given zone.
40214
+ *
40215
+ * Here the idea is to profile the zones at the columns level.
40216
+ *
40217
+ * To do that, we propose to use a data structure
40218
+ * composed of 2 parts:
40219
+ * - profilesStartingPosition: a sorted number array
40220
+ * indicating on which columns a new profile begins.
40221
+ * - profiles: a map where the key is a column
40222
+ * position (from profilesStartingPosition) and the
40223
+ * value is a sorted number array representing a
40224
+ * profile.
40225
+ *
40226
+ *
40227
+ * See the following example: here profileStartingPosition
40228
+ * corresponds to [A,C,E,G,K]
40229
+ * A B C D E F G H I J K so with number [0,2,4,6,10]
40230
+ * 1 ' ' ' '
40231
+ * 2 ' ' '_______' here profile correspond
40232
+ * 3 '___' |_______| for A to []
40233
+ * 4 | | for C to [3, 5]
40234
+ * 5 |___| for E to []
40235
+ * 6 for G to [2, 3]
40236
+ * 7 for K to []
40237
+ *
40238
+ *
40239
+ * Now we can easily find which zones are overlapping
40240
+ * with a given zone. Suppose we want to add a new zone
40241
+ * D5:H6 to the ensemble:
40242
+ *
40243
+ * With a binary search of left and right
40244
+ * A B C D E F G H I J K on profilesStartingPosition, we can
40245
+ * 1 ' ' ' ' find the indexes of the profiles on which
40246
+ * 2 ' ' '_______' to apply a modification.
40247
+ * 3 '___' |_______|
40248
+ * 4 | _|_______ Here we will:
40249
+ * 5 |_|_| | - add a new profile in D --> become [3, 6]
40250
+ * 6 |_________| - modify the profile in E --> become [4, 6]
40251
+ * 7 - modify the profile in G --> become [2, 3, 4, 6]
40252
+ * - add a new profile in I --> become [8, 10]
40253
+ *
40254
+ * See below the result:
40255
+ *
40256
+ * Note the particularity of the profile
40257
+ * A B C D E F G H I J K for G: it will correspond to [2, 3, 4, 6]
40258
+ * 1 ' ' ' ' ' '
40259
+ * 2 ' ' ' '___'___' To know how to modify the profile (add a
40260
+ * 3 '_'_' |___|___| zone or remove it) we do a binary
40261
+ * 4 | | |___ ___ search of the top and bottom value on the
40262
+ * 5 |_| | | | profile array. Depending on the result index
40263
+ * 6 |_|___|___| parity (odd or even), because zone boundaries
40264
+ * 7 go by pairs, we know if we are in a zone or
40265
+ * not and how operate.
40266
+ */
40267
+ /**
40268
+ * Recompute the zone without the cells in toRemoveZones and avoid overlapping.
40269
+ * This compute is particularly useful because after this function:
40270
+ * - you will find coordinate of a cell only once among all the zones
40271
+ * - the number of zones will be reduced to the minimum
40272
+ */
40273
+ function futureRecomputeZones(zones, zonesToRemove = []) {
40274
+ const profilesStartingPosition = [0];
40275
+ const profiles = new Map([[0, []]]);
40276
+ modifyProfiles(profilesStartingPosition, profiles, zones, false);
40277
+ modifyProfiles(profilesStartingPosition, profiles, zonesToRemove, true);
40278
+ return constructZonesFromProfiles(profilesStartingPosition, profiles);
40279
+ }
40280
+ function modifyProfiles(// export for testing only
40281
+ profilesStartingPosition, profiles, zones, toRemove = false) {
40282
+ for (const zone of zones) {
40283
+ const leftValue = zone.left;
40284
+ const rightValue = zone.right === undefined ? undefined : zone.right + 1;
40285
+ const leftIndex = findIndexAndCreateProfile(profilesStartingPosition, profiles, leftValue, true, 0);
40286
+ const rightIndex = findIndexAndCreateProfile(profilesStartingPosition, profiles, rightValue, false, leftIndex);
40287
+ for (let i = leftIndex; i <= rightIndex; i++) {
40288
+ const profile = profiles.get(profilesStartingPosition[i]);
40289
+ modifyProfile(profile, zone, toRemove);
40290
+ }
40291
+ // maybe this part cost in performance, and maybe it's not necessary (depending on the use case). To be checked
40292
+ removeContiguousProfiles(profilesStartingPosition, profiles, leftIndex, rightIndex);
40293
+ }
40294
+ }
40295
+ function findIndexAndCreateProfile(profilesStartingPosition, profiles, value, searchLeft, startIndex) {
40296
+ if (value === undefined) {
40297
+ // this is only the case when the value correspond to a bottom value that could be undefined
40298
+ return profilesStartingPosition.length - 1;
40299
+ }
40300
+ const predecessorIndex = binaryPredecessorSearch(profilesStartingPosition, value, startIndex);
40301
+ if (value != profilesStartingPosition[predecessorIndex]) {
40302
+ // mean that the value is not ending/starting at the same position as the previous/next profile
40303
+ // --> it's a new profile
40304
+ // --> we need to add it
40305
+ profilesStartingPosition.splice(predecessorIndex + 1, 0, value);
40306
+ // suppose the we want to add the for the left value
40307
+ // following profile following zone: 'C', the predecessor index
40308
+ // for B: [1, 3] "C3:D4" correspond to 'B'.
40309
+ // The next line code will
40310
+ // A B C D A B C D copy the profile of 'B'
40311
+ // 1 '___' 1 '___' to 'C'. In the rest of the
40312
+ // 2 | | ---> 2 | _|_ process the 'modifyProfile'
40313
+ // 3 |___| 3 |_|_| | function will adapt the waiting
40314
+ // 4 4 |___| 'C' profile [1, 3] to the
40315
+ // correct 'C' profile [1, 4]
40316
+ profiles.set(value, [...profiles.get(profilesStartingPosition[predecessorIndex])]);
40317
+ return searchLeft ? predecessorIndex + 1 : predecessorIndex;
40318
+ }
40319
+ return searchLeft ? predecessorIndex : predecessorIndex - 1;
40320
+ }
40321
+ /**
40322
+ * Suppose the following Suppose we want to add We want to have the
40323
+ * profile: the following zone: following profile:
40324
+ *
40325
+ * A B C D E F A B C D E F A B C D E F
40326
+ * 1 '___' 1 ' ' 1 '___'
40327
+ * 2 |___| 2 '___' 2 | |
40328
+ * 3 ' ' 3 | | 3 | |
40329
+ * 4 '___' --> 4 | | --> 4 | |
40330
+ * 6 | | 6 |___| 6 | |
40331
+ * 7 |___| 7 7 |___|
40332
+ * 8 8 8
40333
+ *
40334
+ * the profile for 'C' the top zone correspond Here [2, 3, 5, 8] with [3, 7]
40335
+ * corresponds to: to 3 and the bottom zone would be merged into [2, 8]
40336
+ * ____ ____ correspond to 6
40337
+ * [2, 3, 5, 8] would be the profile: The difficulty of modify profile
40338
+ * ____ is to know what must be deleted
40339
+ * Note that the 'filled [3, 7] and what must be added to the
40340
+ * zone' are always between existing profile.
40341
+ * an even index and its
40342
+ * next index
40343
+ *
40344
+ */
40345
+ function modifyProfile(profile, zone, toRemove = false) {
40346
+ const topValue = zone.top;
40347
+ const bottomValue = zone.bottom === undefined ? undefined : zone.bottom + 1;
40348
+ const newPoints = [];
40349
+ // Case we want to add a zone to the profile:
40350
+ // - If the top predecessor index `topPredIndex` is even, it means the top of the zone is already positioned on a filled zone
40351
+ // so we don't need to add it to the profile. we can keep in reference the index of the predecessor.
40352
+ // - If it is odd, it means the top of the zone must be the beginning of a filled zone.
40353
+ // so we can keep the index of the top position
40354
+ // Case we want to remove a zone from the profile: it's the opposite of the previous case
40355
+ const topPredIndex = binaryPredecessorSearch(profile, topValue, 0, false);
40356
+ if ((topPredIndex % 2 !== 0 && !toRemove) || (topPredIndex % 2 === 0 && toRemove)) {
40357
+ newPoints.push(topValue);
40358
+ }
40359
+ if (bottomValue === undefined) {
40360
+ // The following two code lines will not impact the final result,
40361
+ // but they will impact the intermediate profile.
40362
+ // We keep them for performance reason
40363
+ profile.splice(topPredIndex + 1);
40364
+ profile.push(...newPoints);
40365
+ return;
40366
+ }
40367
+ // Case we want to add a zone to the profile:
40368
+ // - If the bottom successor index `bottomSuccIndex` is even, it means the bottom of the zone must be the ending of a filled zone
40369
+ // so we can keep the index of the bottom position.
40370
+ // - If it is odd, it means the bottom of the zone is already positioned on a filled zone
40371
+ // so we don't need to add it to the profile. we can keep in reference the index of the successor
40372
+ // Case we want to remove a zone from the profile: it's the opposite of the previous case
40373
+ const bottomSuccIndex = binarySuccessorSearch(profile, bottomValue, 0, false);
40374
+ if ((bottomSuccIndex % 2 === 0 && !toRemove) || (bottomSuccIndex % 2 !== 0 && toRemove)) {
40375
+ newPoints.push(bottomValue);
40376
+ }
40377
+ // add the top and bottom value to the profile and
40378
+ // remove all information between the top and bottom index
40379
+ profile.splice(topPredIndex + 1, bottomSuccIndex - topPredIndex - 1, ...newPoints);
40380
+ }
40381
+ function removeContiguousProfiles(profilesStartingPosition, profiles, leftIndex, rightIndex) {
40382
+ const start = leftIndex - 1 === -1 ? 0 : leftIndex - 1;
40383
+ const end = rightIndex === profilesStartingPosition.length - 1 ? rightIndex : rightIndex + 1;
40384
+ for (let i = end; i > start; i--) {
40385
+ if (deepEqualsArray(profiles.get(profilesStartingPosition[i]), profiles.get(profilesStartingPosition[i - 1]))) {
40386
+ profiles.delete(profilesStartingPosition[i]);
40387
+ profilesStartingPosition.splice(i, 1);
40388
+ }
40389
+ }
40390
+ }
40391
+ function constructZonesFromProfiles(profilesStartingPosition, profiles) {
40392
+ const mergedZone = [];
40393
+ let pendingZones = [];
40394
+ for (let colIndex = 0; colIndex < profilesStartingPosition.length; colIndex++) {
40395
+ const left = profilesStartingPosition[colIndex];
40396
+ const profile = profiles.get(left);
40397
+ if (!profile || profile.length === 0) {
40398
+ mergedZone.push(...pendingZones);
40399
+ pendingZones = [];
40400
+ continue;
40401
+ }
40402
+ let right = profilesStartingPosition[colIndex + 1];
40403
+ if (right !== undefined) {
40404
+ right--;
40405
+ }
40406
+ const nextPendingZones = [];
40407
+ for (let i = 0; i < profile.length; i += 2) {
40408
+ const top = profile[i];
40409
+ let bottom = profile[i + 1];
40410
+ if (bottom !== undefined) {
40411
+ bottom--;
40412
+ }
40413
+ const profileZone = {
40414
+ top,
40415
+ left,
40416
+ bottom,
40417
+ right,
40418
+ hasHeader: (bottom === undefined && top !== 0) || (right === undefined && left !== 0),
40419
+ };
40420
+ let findCorrespondingZone = false;
40421
+ for (let j = pendingZones.length - 1; j >= 0; j--) {
40422
+ const pendingZone = pendingZones[j];
40423
+ if (pendingZone.top === profileZone.top && pendingZone.bottom === profileZone.bottom) {
40424
+ pendingZone.right = profileZone.right;
40425
+ pendingZones.splice(j, 1);
40426
+ nextPendingZones.push(pendingZone);
40427
+ findCorrespondingZone = true;
40428
+ break;
40429
+ }
40430
+ }
40431
+ if (!findCorrespondingZone) {
40432
+ nextPendingZones.push(profileZone);
40433
+ }
40434
+ }
40435
+ mergedZone.push(...pendingZones);
40436
+ pendingZones = nextPendingZones;
40437
+ }
40438
+ mergedZone.push(...pendingZones);
40439
+ return mergedZone;
40440
+ }
40441
+ function binaryPredecessorSearch(arr, val, start = 0, matchEqual = true) {
40442
+ let end = arr.length - 1;
40443
+ let result = -1;
40444
+ while (start <= end) {
40445
+ const mid = Math.floor((start + end) / 2);
40446
+ if (arr[mid] === val && matchEqual) {
40447
+ return mid;
40448
+ }
40449
+ else if (arr[mid] < val) {
40450
+ result = mid;
40451
+ start = mid + 1;
40452
+ }
40453
+ else {
40454
+ end = mid - 1;
40455
+ }
40456
+ }
40457
+ return result;
40458
+ }
40459
+ function binarySuccessorSearch(arr, val, start = 0, matchEqual = true) {
40460
+ let end = arr.length - 1;
40461
+ let result = arr.length;
40462
+ while (start <= end) {
40463
+ const mid = Math.floor((start + end) / 2);
40464
+ if (arr[mid] === val && matchEqual) {
40465
+ return mid;
40466
+ }
40467
+ else if (arr[mid] > val) {
40468
+ result = mid;
40469
+ end = mid - 1;
40470
+ }
40471
+ else {
40472
+ start = mid + 1;
40473
+ }
40474
+ }
40475
+ return result;
40476
+ }
40477
+ /**
40478
+ * Compares two arrays.
40479
+ * For performance reasons, this function is to be preferred
40480
+ * to 'deepEquals' in the case we know that the inputs are arrays.
40481
+ */
40482
+ function deepEqualsArray(arr1, arr2) {
40483
+ if (arr1.length !== arr2.length) {
40484
+ return false;
40485
+ }
40486
+ for (let i = 0; i < arr1.length; i++) {
40487
+ if (!deepEquals(arr1[i], arr2[i])) {
40488
+ return false;
40489
+ }
40490
+ }
40491
+ return true;
40492
+ }
40493
+
40150
40494
  function quickselect(arr, k, left, right, compare) {
40151
40495
  quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
40152
40496
  }
@@ -40910,7 +41254,7 @@
40910
41254
  }
40911
41255
  }
40912
41256
  /**
40913
- * Return the cell and all cells that depend on it,
41257
+ * Return all the cells that depend on the provided ranges,
40914
41258
  * in the correct order they should be evaluated.
40915
41259
  * This is called a topological ordering (excluding cycles)
40916
41260
  */
@@ -40921,11 +41265,20 @@
40921
41265
  const range = queue.pop();
40922
41266
  visited.addMany(this.encoder.encodeBoundingBox(range));
40923
41267
  const impactedPositionIds = this.rTree.search(range).map((dep) => dep.data);
41268
+ const nextInQueue = {};
40924
41269
  for (const positionId of impactedPositionIds) {
40925
41270
  if (!visited.has(positionId)) {
40926
- queue.push(this.encoder.decodeToBoundingBox(positionId));
41271
+ const { sheetId, zone } = this.encoder.decodeToBoundingBox(positionId);
41272
+ if (!nextInQueue[sheetId]) {
41273
+ nextInQueue[sheetId] = [];
41274
+ }
41275
+ nextInQueue[sheetId].push(zone);
40927
41276
  }
40928
41277
  }
41278
+ for (const sheetId in nextInQueue) {
41279
+ const zones = futureRecomputeZones(nextInQueue[sheetId]);
41280
+ queue.push(...zones.map((zone) => ({ sheetId, zone })));
41281
+ }
40929
41282
  }
40930
41283
  visited.deleteMany(ranges.flatMap((r) => this.encoder.encodeBoundingBox(r)));
40931
41284
  return visited;
@@ -41081,7 +41434,7 @@
41081
41434
  }
41082
41435
  if (!content) {
41083
41436
  // The previous content could have blocked some array formulas
41084
- impactedPositionIds.addMany(this.getArrayFormulasBlockedByOrSpreadingOn(positionId));
41437
+ impactedPositionIds.addMany(this.getArrayFormulasBlockedBy(positionId));
41085
41438
  }
41086
41439
  }
41087
41440
  return impactedPositionIds;
@@ -41126,13 +41479,22 @@
41126
41479
  }
41127
41480
  return positionIds;
41128
41481
  }
41129
- getArrayFormulasBlockedByOrSpreadingOn(positionId) {
41482
+ /**
41483
+ * Return the position of formulas blocked by the given position
41484
+ * as well as all their dependencies.
41485
+ */
41486
+ getArrayFormulasBlockedBy(positionId) {
41130
41487
  if (!this.spreadingRelations.hasArrayFormulaResult(positionId)) {
41131
41488
  return [];
41132
41489
  }
41133
41490
  const arrayFormulas = this.spreadingRelations.getFormulaPositionsSpreadingOn(positionId);
41134
41491
  const cells = new JetSet(arrayFormulas);
41135
- cells.addMany(this.getCellsDependingOn(arrayFormulas));
41492
+ const arrayFormulaPositionId = this.getArrayFormulaSpreadingOnId(positionId);
41493
+ if (arrayFormulaPositionId) {
41494
+ // ignore the formula spreading on the position. Keep only the blocked ones
41495
+ cells.delete(arrayFormulaPositionId);
41496
+ }
41497
+ cells.addMany(this.getCellsDependingOn(cells));
41136
41498
  return cells;
41137
41499
  }
41138
41500
  nextPositionsToUpdate = new JetSet();
@@ -41297,7 +41659,7 @@
41297
41659
  }
41298
41660
  this.evaluatedCells.delete(child);
41299
41661
  this.nextPositionsToUpdate.addMany(this.getCellsDependingOn([child]));
41300
- this.nextPositionsToUpdate.addMany(this.getArrayFormulasBlockedByOrSpreadingOn(child));
41662
+ this.nextPositionsToUpdate.addMany(this.getArrayFormulasBlockedBy(child));
41301
41663
  }
41302
41664
  this.spreadingRelations.removeNode(positionId);
41303
41665
  }
@@ -57029,9 +57391,9 @@
57029
57391
  exports.tokenize = tokenize;
57030
57392
 
57031
57393
 
57032
- __info__.version = "17.0.19";
57033
- __info__.date = "2024-04-18T16:41:42.291Z";
57034
- __info__.hash = "9f3317a";
57394
+ __info__.version = "17.0.20";
57395
+ __info__.date = "2024-04-26T07:37:04.503Z";
57396
+ __info__.hash = "065ac98";
57035
57397
 
57036
57398
 
57037
57399
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);