@odoo/o-spreadsheet 17.2.4 → 17.2.5

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.
@@ -3,9 +3,9 @@
3
3
  /**
4
4
  * This file is generated by o-spreadsheet build tools. Do not edit it.
5
5
  * @see https://github.com/odoo/o-spreadsheet
6
- * @version 17.2.4
7
- * @date 2024-04-18T16:41:38.407Z
8
- * @hash 0c66038
6
+ * @version 17.2.5
7
+ * @date 2024-04-26T07:41:13.193Z
8
+ * @hash a730f5c
9
9
  */
10
10
 
11
11
  (function (exports, owl) {
@@ -32072,17 +32072,13 @@ stores.inject(MyMetaStore, storeInstance);
32072
32072
  this.DOMFocusableElementStore.setFocusableElement(el);
32073
32073
  }
32074
32074
  this.contentHelper.updateEl(el);
32075
- this.processTokenAtCursor();
32076
32075
  });
32077
32076
  owl.useEffect(() => {
32078
32077
  this.processContent();
32079
32078
  });
32080
- owl.onPatched(() => {
32081
- // Required because typing '=SUM' and double-clicking another cell leaves ShowProvider/ShowDescription true
32082
- if (this.composerStore.editionMode === "inactive") {
32083
- this.processTokenAtCursor();
32084
- }
32085
- });
32079
+ owl.useEffect(() => {
32080
+ this.processTokenAtCursor();
32081
+ }, () => [this.composerStore.editionMode !== "inactive"]);
32086
32082
  }
32087
32083
  // ---------------------------------------------------------------------------
32088
32084
  // Handlers
@@ -40379,7 +40375,7 @@ stores.inject(MyMetaStore, storeInstance);
40379
40375
  this.clearBorders(cmd.sheetId, cmd.target);
40380
40376
  break;
40381
40377
  case "REMOVE_COLUMNS_ROWS":
40382
- for (let el of cmd.elements) {
40378
+ for (let el of [...cmd.elements].sort((a, b) => b - a)) {
40383
40379
  if (cmd.dimension === "COL") {
40384
40380
  this.shiftBordersHorizontally(cmd.sheetId, el + 1, -1);
40385
40381
  }
@@ -45918,6 +45914,353 @@ stores.inject(MyMetaStore, storeInstance);
45918
45914
  }
45919
45915
  }
45920
45916
 
45917
+ /**
45918
+ * ####################################################
45919
+ * # INTRODUCTION
45920
+ * ####################################################
45921
+ *
45922
+ * This file contain the function recomputeZones.
45923
+ * This function try to recompute in a performant way
45924
+ * an ensemble of zones possibly overlapping to avoid
45925
+ * overlapping and to reduce the number of zones.
45926
+ *
45927
+ * It also allows to remove some zones from the ensemble.
45928
+ *
45929
+ * In the following example, 2 zones are overlapping.
45930
+ * Applying recomputeZones will return zones without
45931
+ * overlapping:
45932
+ *
45933
+ * ["B3:D4", "D2:E3"] ["B3:C4", "D2:D4", "E2:E3"]
45934
+ *
45935
+ * A B C D E A B C D E
45936
+ * 1 ___ 1 ___
45937
+ * 2 ___|_ | 2 ___| | |
45938
+ * 3 | |_|_| ---> 3 | | |_|
45939
+ * 4 |_____| 4 |___|_|
45940
+ * 6 6
45941
+ * 7 7
45942
+ *
45943
+ *
45944
+ * In the following example, 2 zones are contiguous.
45945
+ * Applying recomputeZones will return only one zone:
45946
+ *
45947
+ * ["B2:B3", "C2:D3"] ["B2:D3"]
45948
+ *
45949
+ * A B C D E A B C D E
45950
+ * 1 _ ___ 1 _____
45951
+ * 2 | | | ---> 2 | |
45952
+ * 3 |_|___| 3 |_____|
45953
+ * 4 4
45954
+ *
45955
+ *
45956
+ * In the following example, we want to remove a zone
45957
+ * from the ensemble. Applying recomputeZones will
45958
+ * return the ensemble without the zone to remove:
45959
+ *
45960
+ * remove ["C3:D3"] ["B2:B4", "C2:D2",
45961
+ * "C4:D4", "E2:E4"]
45962
+ *
45963
+ * A B C D E F A B C D E F
45964
+ * 1 _______ 1 _______
45965
+ * 2 | | ---> 2 | |___| |
45966
+ * 3 | xxx | 3 | |___| |
45967
+ * 4 |_______| 4 |_|___|_|
45968
+ * 5 5
45969
+ *
45970
+ *
45971
+ * The exercise seems simple when we have only 2 zones.
45972
+ * But with n zones and in a performant way, we want to
45973
+ * avoid comparing each zone with all the others.
45974
+ *
45975
+ *
45976
+ * ####################################################
45977
+ * # Methodological approach
45978
+ * ####################################################
45979
+ *
45980
+ * The methodological approach to avoid comparing each
45981
+ * zone with all the others is to use a data structure
45982
+ * that allow to quickly find which zones are
45983
+ * overlapping with any other given zone.
45984
+ *
45985
+ * Here the idea is to profile the zones at the columns level.
45986
+ *
45987
+ * To do that, we propose to use a data structure
45988
+ * composed of 2 parts:
45989
+ * - profilesStartingPosition: a sorted number array
45990
+ * indicating on which columns a new profile begins.
45991
+ * - profiles: a map where the key is a column
45992
+ * position (from profilesStartingPosition) and the
45993
+ * value is a sorted number array representing a
45994
+ * profile.
45995
+ *
45996
+ *
45997
+ * See the following example: here profileStartingPosition
45998
+ * corresponds to [A,C,E,G,K]
45999
+ * A B C D E F G H I J K so with number [0,2,4,6,10]
46000
+ * 1 ' ' ' '
46001
+ * 2 ' ' '_______' here profile correspond
46002
+ * 3 '___' |_______| for A to []
46003
+ * 4 | | for C to [3, 5]
46004
+ * 5 |___| for E to []
46005
+ * 6 for G to [2, 3]
46006
+ * 7 for K to []
46007
+ *
46008
+ *
46009
+ * Now we can easily find which zones are overlapping
46010
+ * with a given zone. Suppose we want to add a new zone
46011
+ * D5:H6 to the ensemble:
46012
+ *
46013
+ * With a binary search of left and right
46014
+ * A B C D E F G H I J K on profilesStartingPosition, we can
46015
+ * 1 ' ' ' ' find the indexes of the profiles on which
46016
+ * 2 ' ' '_______' to apply a modification.
46017
+ * 3 '___' |_______|
46018
+ * 4 | _|_______ Here we will:
46019
+ * 5 |_|_| | - add a new profile in D --> become [3, 6]
46020
+ * 6 |_________| - modify the profile in E --> become [4, 6]
46021
+ * 7 - modify the profile in G --> become [2, 3, 4, 6]
46022
+ * - add a new profile in I --> become [8, 10]
46023
+ *
46024
+ * See below the result:
46025
+ *
46026
+ * Note the particularity of the profile
46027
+ * A B C D E F G H I J K for G: it will correspond to [2, 3, 4, 6]
46028
+ * 1 ' ' ' ' ' '
46029
+ * 2 ' ' ' '___'___' To know how to modify the profile (add a
46030
+ * 3 '_'_' |___|___| zone or remove it) we do a binary
46031
+ * 4 | | |___ ___ search of the top and bottom value on the
46032
+ * 5 |_| | | | profile array. Depending on the result index
46033
+ * 6 |_|___|___| parity (odd or even), because zone boundaries
46034
+ * 7 go by pairs, we know if we are in a zone or
46035
+ * not and how operate.
46036
+ */
46037
+ /**
46038
+ * Recompute the zone without the cells in toRemoveZones and avoid overlapping.
46039
+ * This compute is particularly useful because after this function:
46040
+ * - you will find coordinate of a cell only once among all the zones
46041
+ * - the number of zones will be reduced to the minimum
46042
+ */
46043
+ function futureRecomputeZones(zones, zonesToRemove = []) {
46044
+ const profilesStartingPosition = [0];
46045
+ const profiles = new Map([[0, []]]);
46046
+ modifyProfiles(profilesStartingPosition, profiles, zones, false);
46047
+ modifyProfiles(profilesStartingPosition, profiles, zonesToRemove, true);
46048
+ return constructZonesFromProfiles(profilesStartingPosition, profiles);
46049
+ }
46050
+ function modifyProfiles(// export for testing only
46051
+ profilesStartingPosition, profiles, zones, toRemove = false) {
46052
+ for (const zone of zones) {
46053
+ const leftValue = zone.left;
46054
+ const rightValue = zone.right === undefined ? undefined : zone.right + 1;
46055
+ const leftIndex = findIndexAndCreateProfile(profilesStartingPosition, profiles, leftValue, true, 0);
46056
+ const rightIndex = findIndexAndCreateProfile(profilesStartingPosition, profiles, rightValue, false, leftIndex);
46057
+ for (let i = leftIndex; i <= rightIndex; i++) {
46058
+ const profile = profiles.get(profilesStartingPosition[i]);
46059
+ modifyProfile(profile, zone, toRemove);
46060
+ }
46061
+ // maybe this part cost in performance, and maybe it's not necessary (depending on the use case). To be checked
46062
+ removeContiguousProfiles(profilesStartingPosition, profiles, leftIndex, rightIndex);
46063
+ }
46064
+ }
46065
+ function findIndexAndCreateProfile(profilesStartingPosition, profiles, value, searchLeft, startIndex) {
46066
+ if (value === undefined) {
46067
+ // this is only the case when the value correspond to a bottom value that could be undefined
46068
+ return profilesStartingPosition.length - 1;
46069
+ }
46070
+ const predecessorIndex = binaryPredecessorSearch(profilesStartingPosition, value, startIndex);
46071
+ if (value != profilesStartingPosition[predecessorIndex]) {
46072
+ // mean that the value is not ending/starting at the same position as the previous/next profile
46073
+ // --> it's a new profile
46074
+ // --> we need to add it
46075
+ profilesStartingPosition.splice(predecessorIndex + 1, 0, value);
46076
+ // suppose the we want to add the for the left value
46077
+ // following profile following zone: 'C', the predecessor index
46078
+ // for B: [1, 3] "C3:D4" correspond to 'B'.
46079
+ // The next line code will
46080
+ // A B C D A B C D copy the profile of 'B'
46081
+ // 1 '___' 1 '___' to 'C'. In the rest of the
46082
+ // 2 | | ---> 2 | _|_ process the 'modifyProfile'
46083
+ // 3 |___| 3 |_|_| | function will adapt the waiting
46084
+ // 4 4 |___| 'C' profile [1, 3] to the
46085
+ // correct 'C' profile [1, 4]
46086
+ profiles.set(value, [...profiles.get(profilesStartingPosition[predecessorIndex])]);
46087
+ return searchLeft ? predecessorIndex + 1 : predecessorIndex;
46088
+ }
46089
+ return searchLeft ? predecessorIndex : predecessorIndex - 1;
46090
+ }
46091
+ /**
46092
+ * Suppose the following Suppose we want to add We want to have the
46093
+ * profile: the following zone: following profile:
46094
+ *
46095
+ * A B C D E F A B C D E F A B C D E F
46096
+ * 1 '___' 1 ' ' 1 '___'
46097
+ * 2 |___| 2 '___' 2 | |
46098
+ * 3 ' ' 3 | | 3 | |
46099
+ * 4 '___' --> 4 | | --> 4 | |
46100
+ * 6 | | 6 |___| 6 | |
46101
+ * 7 |___| 7 7 |___|
46102
+ * 8 8 8
46103
+ *
46104
+ * the profile for 'C' the top zone correspond Here [2, 3, 5, 8] with [3, 7]
46105
+ * corresponds to: to 3 and the bottom zone would be merged into [2, 8]
46106
+ * ____ ____ correspond to 6
46107
+ * [2, 3, 5, 8] would be the profile: The difficulty of modify profile
46108
+ * ____ is to know what must be deleted
46109
+ * Note that the 'filled [3, 7] and what must be added to the
46110
+ * zone' are always between existing profile.
46111
+ * an even index and its
46112
+ * next index
46113
+ *
46114
+ */
46115
+ function modifyProfile(profile, zone, toRemove = false) {
46116
+ const topValue = zone.top;
46117
+ const bottomValue = zone.bottom === undefined ? undefined : zone.bottom + 1;
46118
+ const newPoints = [];
46119
+ // Case we want to add a zone to the profile:
46120
+ // - If the top predecessor index `topPredIndex` is even, it means the top of the zone is already positioned on a filled zone
46121
+ // so we don't need to add it to the profile. we can keep in reference the index of the predecessor.
46122
+ // - If it is odd, it means the top of the zone must be the beginning of a filled zone.
46123
+ // so we can keep the index of the top position
46124
+ // Case we want to remove a zone from the profile: it's the opposite of the previous case
46125
+ const topPredIndex = binaryPredecessorSearch(profile, topValue, 0, false);
46126
+ if ((topPredIndex % 2 !== 0 && !toRemove) || (topPredIndex % 2 === 0 && toRemove)) {
46127
+ newPoints.push(topValue);
46128
+ }
46129
+ if (bottomValue === undefined) {
46130
+ // The following two code lines will not impact the final result,
46131
+ // but they will impact the intermediate profile.
46132
+ // We keep them for performance reason
46133
+ profile.splice(topPredIndex + 1);
46134
+ profile.push(...newPoints);
46135
+ return;
46136
+ }
46137
+ // Case we want to add a zone to the profile:
46138
+ // - If the bottom successor index `bottomSuccIndex` is even, it means the bottom of the zone must be the ending of a filled zone
46139
+ // so we can keep the index of the bottom position.
46140
+ // - If it is odd, it means the bottom of the zone is already positioned on a filled zone
46141
+ // so we don't need to add it to the profile. we can keep in reference the index of the successor
46142
+ // Case we want to remove a zone from the profile: it's the opposite of the previous case
46143
+ const bottomSuccIndex = binarySuccessorSearch(profile, bottomValue, 0, false);
46144
+ if ((bottomSuccIndex % 2 === 0 && !toRemove) || (bottomSuccIndex % 2 !== 0 && toRemove)) {
46145
+ newPoints.push(bottomValue);
46146
+ }
46147
+ // add the top and bottom value to the profile and
46148
+ // remove all information between the top and bottom index
46149
+ profile.splice(topPredIndex + 1, bottomSuccIndex - topPredIndex - 1, ...newPoints);
46150
+ }
46151
+ function removeContiguousProfiles(profilesStartingPosition, profiles, leftIndex, rightIndex) {
46152
+ const start = leftIndex - 1 === -1 ? 0 : leftIndex - 1;
46153
+ const end = rightIndex === profilesStartingPosition.length - 1 ? rightIndex : rightIndex + 1;
46154
+ for (let i = end; i > start; i--) {
46155
+ if (deepEqualsArray(profiles.get(profilesStartingPosition[i]), profiles.get(profilesStartingPosition[i - 1]))) {
46156
+ profiles.delete(profilesStartingPosition[i]);
46157
+ profilesStartingPosition.splice(i, 1);
46158
+ }
46159
+ }
46160
+ }
46161
+ function constructZonesFromProfiles(profilesStartingPosition, profiles) {
46162
+ const mergedZone = [];
46163
+ let pendingZones = [];
46164
+ for (let colIndex = 0; colIndex < profilesStartingPosition.length; colIndex++) {
46165
+ const left = profilesStartingPosition[colIndex];
46166
+ const profile = profiles.get(left);
46167
+ if (!profile || profile.length === 0) {
46168
+ mergedZone.push(...pendingZones);
46169
+ pendingZones = [];
46170
+ continue;
46171
+ }
46172
+ let right = profilesStartingPosition[colIndex + 1];
46173
+ if (right !== undefined) {
46174
+ right--;
46175
+ }
46176
+ const nextPendingZones = [];
46177
+ for (let i = 0; i < profile.length; i += 2) {
46178
+ const top = profile[i];
46179
+ let bottom = profile[i + 1];
46180
+ if (bottom !== undefined) {
46181
+ bottom--;
46182
+ }
46183
+ const profileZone = {
46184
+ top,
46185
+ left,
46186
+ bottom,
46187
+ right,
46188
+ hasHeader: (bottom === undefined && top !== 0) || (right === undefined && left !== 0),
46189
+ };
46190
+ let findCorrespondingZone = false;
46191
+ for (let j = pendingZones.length - 1; j >= 0; j--) {
46192
+ const pendingZone = pendingZones[j];
46193
+ if (pendingZone.top === profileZone.top && pendingZone.bottom === profileZone.bottom) {
46194
+ pendingZone.right = profileZone.right;
46195
+ pendingZones.splice(j, 1);
46196
+ nextPendingZones.push(pendingZone);
46197
+ findCorrespondingZone = true;
46198
+ break;
46199
+ }
46200
+ }
46201
+ if (!findCorrespondingZone) {
46202
+ nextPendingZones.push(profileZone);
46203
+ }
46204
+ }
46205
+ mergedZone.push(...pendingZones);
46206
+ pendingZones = nextPendingZones;
46207
+ }
46208
+ mergedZone.push(...pendingZones);
46209
+ return mergedZone;
46210
+ }
46211
+ function binaryPredecessorSearch(arr, val, start = 0, matchEqual = true) {
46212
+ let end = arr.length - 1;
46213
+ let result = -1;
46214
+ while (start <= end) {
46215
+ const mid = Math.floor((start + end) / 2);
46216
+ if (arr[mid] === val && matchEqual) {
46217
+ return mid;
46218
+ }
46219
+ else if (arr[mid] < val) {
46220
+ result = mid;
46221
+ start = mid + 1;
46222
+ }
46223
+ else {
46224
+ end = mid - 1;
46225
+ }
46226
+ }
46227
+ return result;
46228
+ }
46229
+ function binarySuccessorSearch(arr, val, start = 0, matchEqual = true) {
46230
+ let end = arr.length - 1;
46231
+ let result = arr.length;
46232
+ while (start <= end) {
46233
+ const mid = Math.floor((start + end) / 2);
46234
+ if (arr[mid] === val && matchEqual) {
46235
+ return mid;
46236
+ }
46237
+ else if (arr[mid] > val) {
46238
+ result = mid;
46239
+ end = mid - 1;
46240
+ }
46241
+ else {
46242
+ start = mid + 1;
46243
+ }
46244
+ }
46245
+ return result;
46246
+ }
46247
+ /**
46248
+ * Compares two arrays.
46249
+ * For performance reasons, this function is to be preferred
46250
+ * to 'deepEquals' in the case we know that the inputs are arrays.
46251
+ */
46252
+ function deepEqualsArray(arr1, arr2) {
46253
+ if (arr1.length !== arr2.length) {
46254
+ return false;
46255
+ }
46256
+ for (let i = 0; i < arr1.length; i++) {
46257
+ if (!deepEquals(arr1[i], arr2[i])) {
46258
+ return false;
46259
+ }
46260
+ }
46261
+ return true;
46262
+ }
46263
+
45921
46264
  class PositionMap {
45922
46265
  map = {};
45923
46266
  set({ sheetId, col, row }, value) {
@@ -46716,7 +47059,7 @@ stores.inject(MyMetaStore, storeInstance);
46716
47059
  }
46717
47060
  }
46718
47061
  /**
46719
- * Return the cell and all cells that depend on it,
47062
+ * Return all the cells that depend on the provided ranges,
46720
47063
  * in the correct order they should be evaluated.
46721
47064
  * This is called a topological ordering (excluding cycles)
46722
47065
  */
@@ -46727,11 +47070,19 @@ stores.inject(MyMetaStore, storeInstance);
46727
47070
  const range = queue.pop();
46728
47071
  visited.addMany(positions(range.zone).map((position) => ({ sheetId: range.sheetId, ...position })));
46729
47072
  const impactedPositions = this.rTree.search(range).map((dep) => dep.data);
47073
+ const nextInQueue = {};
46730
47074
  for (const position of impactedPositions) {
46731
47075
  if (!visited.has(position)) {
46732
- queue.push({ sheetId: position.sheetId, zone: positionToZone(position) });
47076
+ if (!nextInQueue[position.sheetId]) {
47077
+ nextInQueue[position.sheetId] = [];
47078
+ }
47079
+ nextInQueue[position.sheetId].push(positionToZone(position));
46733
47080
  }
46734
47081
  }
47082
+ for (const sheetId in nextInQueue) {
47083
+ const zones = futureRecomputeZones(nextInQueue[sheetId]);
47084
+ queue.push(...zones.map((zone) => ({ sheetId, zone })));
47085
+ }
46735
47086
  }
46736
47087
  visited.deleteMany(ranges.flatMap((r) => positions(r.zone).map((position) => ({ sheetId: r.sheetId, ...position }))));
46737
47088
  return visited;
@@ -47070,7 +47421,7 @@ stores.inject(MyMetaStore, storeInstance);
47070
47421
  }
47071
47422
  if (!content) {
47072
47423
  // The previous content could have blocked some array formulas
47073
- impactedPositions.addMany(this.getArrayFormulasBlockedByOrSpreadingOn(position));
47424
+ impactedPositions.addMany(this.getArrayFormulasBlockedBy(position));
47074
47425
  }
47075
47426
  }
47076
47427
  return impactedPositions;
@@ -47113,14 +47464,23 @@ stores.inject(MyMetaStore, storeInstance);
47113
47464
  positions.fillAllPositions();
47114
47465
  return positions;
47115
47466
  }
47116
- getArrayFormulasBlockedByOrSpreadingOn(position) {
47467
+ /**
47468
+ * Return the position of formulas blocked by the given position
47469
+ * as well as all their dependencies.
47470
+ */
47471
+ getArrayFormulasBlockedBy(position) {
47117
47472
  if (!this.spreadingRelations.hasArrayFormulaResult(position)) {
47118
47473
  return [];
47119
47474
  }
47120
47475
  const arrayFormulas = this.spreadingRelations.getFormulaPositionsSpreadingOn(position);
47121
47476
  const positions = this.createEmptyPositionSet();
47122
47477
  positions.addMany(arrayFormulas);
47123
- positions.addMany(this.getCellsDependingOn(arrayFormulas));
47478
+ const arrayFormulaPosition = this.getArrayFormulaSpreadingOn(position);
47479
+ if (arrayFormulaPosition) {
47480
+ // ignore the formula spreading on the position. Keep only the blocked ones
47481
+ positions.delete(arrayFormulaPosition);
47482
+ }
47483
+ positions.addMany(this.getCellsDependingOn(positions));
47124
47484
  return positions;
47125
47485
  }
47126
47486
  nextPositionsToUpdate = new PositionSet({});
@@ -47260,7 +47620,7 @@ stores.inject(MyMetaStore, storeInstance);
47260
47620
  }
47261
47621
  this.evaluatedCells.delete(child);
47262
47622
  this.nextPositionsToUpdate.addMany(this.getCellsDependingOn([child]));
47263
- this.nextPositionsToUpdate.addMany(this.getArrayFormulasBlockedByOrSpreadingOn(child));
47623
+ this.nextPositionsToUpdate.addMany(this.getArrayFormulasBlockedBy(child));
47264
47624
  }
47265
47625
  this.spreadingRelations.removeNode(position);
47266
47626
  }
@@ -60239,9 +60599,9 @@ stores.inject(MyMetaStore, storeInstance);
60239
60599
  exports.tokenize = tokenize;
60240
60600
 
60241
60601
 
60242
- __info__.version = "17.2.4";
60243
- __info__.date = "2024-04-18T16:41:38.407Z";
60244
- __info__.hash = "0c66038";
60602
+ __info__.version = "17.2.5";
60603
+ __info__.date = "2024-04-26T07:41:13.193Z";
60604
+ __info__.hash = "a730f5c";
60245
60605
 
60246
60606
 
60247
60607
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);