@odoo/o-spreadsheet 17.1.12 → 17.1.13

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.1.12
6
- * @date 2024-04-18T16:45:30.109Z
7
- * @hash 3e90776
5
+ * @version 17.1.13
6
+ * @date 2024-04-26T07:39:54.100Z
7
+ * @hash f2ea8c7
8
8
  */
9
9
 
10
10
  (function (exports, owl) {
@@ -27179,17 +27179,13 @@
27179
27179
  this.env.focusableElement.setFocusableElement(el);
27180
27180
  }
27181
27181
  this.contentHelper.updateEl(el);
27182
- this.processTokenAtCursor();
27183
27182
  });
27184
27183
  owl.useEffect(() => {
27185
27184
  this.processContent();
27186
27185
  });
27187
- owl.onPatched(() => {
27188
- // Required because typing '=SUM' and double-clicking another cell leaves ShowProvider/ShowDescription true
27189
- if (this.env.model.getters.getEditionMode() === "inactive") {
27190
- this.processTokenAtCursor();
27191
- }
27192
- });
27186
+ owl.useEffect(() => {
27187
+ this.processTokenAtCursor();
27188
+ }, () => [this.env.model.getters.getEditionMode() !== "inactive"]);
27193
27189
  }
27194
27190
  // ---------------------------------------------------------------------------
27195
27191
  // Handlers
@@ -27627,6 +27623,7 @@
27627
27623
  const dataValidationAutocompleteValues = this.env.model.getters.getAutoCompleteDataValidationValues();
27628
27624
  if (!content.startsWith("=") && dataValidationAutocompleteValues.length) {
27629
27625
  this.showDataValidationAutocomplete(dataValidationAutocompleteValues);
27626
+ return;
27630
27627
  }
27631
27628
  if (content.startsWith("=")) {
27632
27629
  const token = this.env.model.getters.getTokenAtCursor();
@@ -34869,7 +34866,7 @@
34869
34866
  this.clearBorders(cmd.sheetId, cmd.target);
34870
34867
  break;
34871
34868
  case "REMOVE_COLUMNS_ROWS":
34872
- for (let el of cmd.elements) {
34869
+ for (let el of [...cmd.elements].sort((a, b) => b - a)) {
34873
34870
  if (cmd.dimension === "COL") {
34874
34871
  this.shiftBordersHorizontally(cmd.sheetId, el + 1, -1);
34875
34872
  }
@@ -40625,6 +40622,353 @@
40625
40622
  }
40626
40623
  }
40627
40624
 
40625
+ /**
40626
+ * ####################################################
40627
+ * # INTRODUCTION
40628
+ * ####################################################
40629
+ *
40630
+ * This file contain the function recomputeZones.
40631
+ * This function try to recompute in a performant way
40632
+ * an ensemble of zones possibly overlapping to avoid
40633
+ * overlapping and to reduce the number of zones.
40634
+ *
40635
+ * It also allows to remove some zones from the ensemble.
40636
+ *
40637
+ * In the following example, 2 zones are overlapping.
40638
+ * Applying recomputeZones will return zones without
40639
+ * overlapping:
40640
+ *
40641
+ * ["B3:D4", "D2:E3"] ["B3:C4", "D2:D4", "E2:E3"]
40642
+ *
40643
+ * A B C D E A B C D E
40644
+ * 1 ___ 1 ___
40645
+ * 2 ___|_ | 2 ___| | |
40646
+ * 3 | |_|_| ---> 3 | | |_|
40647
+ * 4 |_____| 4 |___|_|
40648
+ * 6 6
40649
+ * 7 7
40650
+ *
40651
+ *
40652
+ * In the following example, 2 zones are contiguous.
40653
+ * Applying recomputeZones will return only one zone:
40654
+ *
40655
+ * ["B2:B3", "C2:D3"] ["B2:D3"]
40656
+ *
40657
+ * A B C D E A B C D E
40658
+ * 1 _ ___ 1 _____
40659
+ * 2 | | | ---> 2 | |
40660
+ * 3 |_|___| 3 |_____|
40661
+ * 4 4
40662
+ *
40663
+ *
40664
+ * In the following example, we want to remove a zone
40665
+ * from the ensemble. Applying recomputeZones will
40666
+ * return the ensemble without the zone to remove:
40667
+ *
40668
+ * remove ["C3:D3"] ["B2:B4", "C2:D2",
40669
+ * "C4:D4", "E2:E4"]
40670
+ *
40671
+ * A B C D E F A B C D E F
40672
+ * 1 _______ 1 _______
40673
+ * 2 | | ---> 2 | |___| |
40674
+ * 3 | xxx | 3 | |___| |
40675
+ * 4 |_______| 4 |_|___|_|
40676
+ * 5 5
40677
+ *
40678
+ *
40679
+ * The exercise seems simple when we have only 2 zones.
40680
+ * But with n zones and in a performant way, we want to
40681
+ * avoid comparing each zone with all the others.
40682
+ *
40683
+ *
40684
+ * ####################################################
40685
+ * # Methodological approach
40686
+ * ####################################################
40687
+ *
40688
+ * The methodological approach to avoid comparing each
40689
+ * zone with all the others is to use a data structure
40690
+ * that allow to quickly find which zones are
40691
+ * overlapping with any other given zone.
40692
+ *
40693
+ * Here the idea is to profile the zones at the columns level.
40694
+ *
40695
+ * To do that, we propose to use a data structure
40696
+ * composed of 2 parts:
40697
+ * - profilesStartingPosition: a sorted number array
40698
+ * indicating on which columns a new profile begins.
40699
+ * - profiles: a map where the key is a column
40700
+ * position (from profilesStartingPosition) and the
40701
+ * value is a sorted number array representing a
40702
+ * profile.
40703
+ *
40704
+ *
40705
+ * See the following example: here profileStartingPosition
40706
+ * corresponds to [A,C,E,G,K]
40707
+ * A B C D E F G H I J K so with number [0,2,4,6,10]
40708
+ * 1 ' ' ' '
40709
+ * 2 ' ' '_______' here profile correspond
40710
+ * 3 '___' |_______| for A to []
40711
+ * 4 | | for C to [3, 5]
40712
+ * 5 |___| for E to []
40713
+ * 6 for G to [2, 3]
40714
+ * 7 for K to []
40715
+ *
40716
+ *
40717
+ * Now we can easily find which zones are overlapping
40718
+ * with a given zone. Suppose we want to add a new zone
40719
+ * D5:H6 to the ensemble:
40720
+ *
40721
+ * With a binary search of left and right
40722
+ * A B C D E F G H I J K on profilesStartingPosition, we can
40723
+ * 1 ' ' ' ' find the indexes of the profiles on which
40724
+ * 2 ' ' '_______' to apply a modification.
40725
+ * 3 '___' |_______|
40726
+ * 4 | _|_______ Here we will:
40727
+ * 5 |_|_| | - add a new profile in D --> become [3, 6]
40728
+ * 6 |_________| - modify the profile in E --> become [4, 6]
40729
+ * 7 - modify the profile in G --> become [2, 3, 4, 6]
40730
+ * - add a new profile in I --> become [8, 10]
40731
+ *
40732
+ * See below the result:
40733
+ *
40734
+ * Note the particularity of the profile
40735
+ * A B C D E F G H I J K for G: it will correspond to [2, 3, 4, 6]
40736
+ * 1 ' ' ' ' ' '
40737
+ * 2 ' ' ' '___'___' To know how to modify the profile (add a
40738
+ * 3 '_'_' |___|___| zone or remove it) we do a binary
40739
+ * 4 | | |___ ___ search of the top and bottom value on the
40740
+ * 5 |_| | | | profile array. Depending on the result index
40741
+ * 6 |_|___|___| parity (odd or even), because zone boundaries
40742
+ * 7 go by pairs, we know if we are in a zone or
40743
+ * not and how operate.
40744
+ */
40745
+ /**
40746
+ * Recompute the zone without the cells in toRemoveZones and avoid overlapping.
40747
+ * This compute is particularly useful because after this function:
40748
+ * - you will find coordinate of a cell only once among all the zones
40749
+ * - the number of zones will be reduced to the minimum
40750
+ */
40751
+ function futureRecomputeZones(zones, zonesToRemove = []) {
40752
+ const profilesStartingPosition = [0];
40753
+ const profiles = new Map([[0, []]]);
40754
+ modifyProfiles(profilesStartingPosition, profiles, zones, false);
40755
+ modifyProfiles(profilesStartingPosition, profiles, zonesToRemove, true);
40756
+ return constructZonesFromProfiles(profilesStartingPosition, profiles);
40757
+ }
40758
+ function modifyProfiles(// export for testing only
40759
+ profilesStartingPosition, profiles, zones, toRemove = false) {
40760
+ for (const zone of zones) {
40761
+ const leftValue = zone.left;
40762
+ const rightValue = zone.right === undefined ? undefined : zone.right + 1;
40763
+ const leftIndex = findIndexAndCreateProfile(profilesStartingPosition, profiles, leftValue, true, 0);
40764
+ const rightIndex = findIndexAndCreateProfile(profilesStartingPosition, profiles, rightValue, false, leftIndex);
40765
+ for (let i = leftIndex; i <= rightIndex; i++) {
40766
+ const profile = profiles.get(profilesStartingPosition[i]);
40767
+ modifyProfile(profile, zone, toRemove);
40768
+ }
40769
+ // maybe this part cost in performance, and maybe it's not necessary (depending on the use case). To be checked
40770
+ removeContiguousProfiles(profilesStartingPosition, profiles, leftIndex, rightIndex);
40771
+ }
40772
+ }
40773
+ function findIndexAndCreateProfile(profilesStartingPosition, profiles, value, searchLeft, startIndex) {
40774
+ if (value === undefined) {
40775
+ // this is only the case when the value correspond to a bottom value that could be undefined
40776
+ return profilesStartingPosition.length - 1;
40777
+ }
40778
+ const predecessorIndex = binaryPredecessorSearch(profilesStartingPosition, value, startIndex);
40779
+ if (value != profilesStartingPosition[predecessorIndex]) {
40780
+ // mean that the value is not ending/starting at the same position as the previous/next profile
40781
+ // --> it's a new profile
40782
+ // --> we need to add it
40783
+ profilesStartingPosition.splice(predecessorIndex + 1, 0, value);
40784
+ // suppose the we want to add the for the left value
40785
+ // following profile following zone: 'C', the predecessor index
40786
+ // for B: [1, 3] "C3:D4" correspond to 'B'.
40787
+ // The next line code will
40788
+ // A B C D A B C D copy the profile of 'B'
40789
+ // 1 '___' 1 '___' to 'C'. In the rest of the
40790
+ // 2 | | ---> 2 | _|_ process the 'modifyProfile'
40791
+ // 3 |___| 3 |_|_| | function will adapt the waiting
40792
+ // 4 4 |___| 'C' profile [1, 3] to the
40793
+ // correct 'C' profile [1, 4]
40794
+ profiles.set(value, [...profiles.get(profilesStartingPosition[predecessorIndex])]);
40795
+ return searchLeft ? predecessorIndex + 1 : predecessorIndex;
40796
+ }
40797
+ return searchLeft ? predecessorIndex : predecessorIndex - 1;
40798
+ }
40799
+ /**
40800
+ * Suppose the following Suppose we want to add We want to have the
40801
+ * profile: the following zone: following profile:
40802
+ *
40803
+ * A B C D E F A B C D E F A B C D E F
40804
+ * 1 '___' 1 ' ' 1 '___'
40805
+ * 2 |___| 2 '___' 2 | |
40806
+ * 3 ' ' 3 | | 3 | |
40807
+ * 4 '___' --> 4 | | --> 4 | |
40808
+ * 6 | | 6 |___| 6 | |
40809
+ * 7 |___| 7 7 |___|
40810
+ * 8 8 8
40811
+ *
40812
+ * the profile for 'C' the top zone correspond Here [2, 3, 5, 8] with [3, 7]
40813
+ * corresponds to: to 3 and the bottom zone would be merged into [2, 8]
40814
+ * ____ ____ correspond to 6
40815
+ * [2, 3, 5, 8] would be the profile: The difficulty of modify profile
40816
+ * ____ is to know what must be deleted
40817
+ * Note that the 'filled [3, 7] and what must be added to the
40818
+ * zone' are always between existing profile.
40819
+ * an even index and its
40820
+ * next index
40821
+ *
40822
+ */
40823
+ function modifyProfile(profile, zone, toRemove = false) {
40824
+ const topValue = zone.top;
40825
+ const bottomValue = zone.bottom === undefined ? undefined : zone.bottom + 1;
40826
+ const newPoints = [];
40827
+ // Case we want to add a zone to the profile:
40828
+ // - If the top predecessor index `topPredIndex` is even, it means the top of the zone is already positioned on a filled zone
40829
+ // so we don't need to add it to the profile. we can keep in reference the index of the predecessor.
40830
+ // - If it is odd, it means the top of the zone must be the beginning of a filled zone.
40831
+ // so we can keep the index of the top position
40832
+ // Case we want to remove a zone from the profile: it's the opposite of the previous case
40833
+ const topPredIndex = binaryPredecessorSearch(profile, topValue, 0, false);
40834
+ if ((topPredIndex % 2 !== 0 && !toRemove) || (topPredIndex % 2 === 0 && toRemove)) {
40835
+ newPoints.push(topValue);
40836
+ }
40837
+ if (bottomValue === undefined) {
40838
+ // The following two code lines will not impact the final result,
40839
+ // but they will impact the intermediate profile.
40840
+ // We keep them for performance reason
40841
+ profile.splice(topPredIndex + 1);
40842
+ profile.push(...newPoints);
40843
+ return;
40844
+ }
40845
+ // Case we want to add a zone to the profile:
40846
+ // - If the bottom successor index `bottomSuccIndex` is even, it means the bottom of the zone must be the ending of a filled zone
40847
+ // so we can keep the index of the bottom position.
40848
+ // - If it is odd, it means the bottom of the zone is already positioned on a filled zone
40849
+ // so we don't need to add it to the profile. we can keep in reference the index of the successor
40850
+ // Case we want to remove a zone from the profile: it's the opposite of the previous case
40851
+ const bottomSuccIndex = binarySuccessorSearch(profile, bottomValue, 0, false);
40852
+ if ((bottomSuccIndex % 2 === 0 && !toRemove) || (bottomSuccIndex % 2 !== 0 && toRemove)) {
40853
+ newPoints.push(bottomValue);
40854
+ }
40855
+ // add the top and bottom value to the profile and
40856
+ // remove all information between the top and bottom index
40857
+ profile.splice(topPredIndex + 1, bottomSuccIndex - topPredIndex - 1, ...newPoints);
40858
+ }
40859
+ function removeContiguousProfiles(profilesStartingPosition, profiles, leftIndex, rightIndex) {
40860
+ const start = leftIndex - 1 === -1 ? 0 : leftIndex - 1;
40861
+ const end = rightIndex === profilesStartingPosition.length - 1 ? rightIndex : rightIndex + 1;
40862
+ for (let i = end; i > start; i--) {
40863
+ if (deepEqualsArray(profiles.get(profilesStartingPosition[i]), profiles.get(profilesStartingPosition[i - 1]))) {
40864
+ profiles.delete(profilesStartingPosition[i]);
40865
+ profilesStartingPosition.splice(i, 1);
40866
+ }
40867
+ }
40868
+ }
40869
+ function constructZonesFromProfiles(profilesStartingPosition, profiles) {
40870
+ const mergedZone = [];
40871
+ let pendingZones = [];
40872
+ for (let colIndex = 0; colIndex < profilesStartingPosition.length; colIndex++) {
40873
+ const left = profilesStartingPosition[colIndex];
40874
+ const profile = profiles.get(left);
40875
+ if (!profile || profile.length === 0) {
40876
+ mergedZone.push(...pendingZones);
40877
+ pendingZones = [];
40878
+ continue;
40879
+ }
40880
+ let right = profilesStartingPosition[colIndex + 1];
40881
+ if (right !== undefined) {
40882
+ right--;
40883
+ }
40884
+ const nextPendingZones = [];
40885
+ for (let i = 0; i < profile.length; i += 2) {
40886
+ const top = profile[i];
40887
+ let bottom = profile[i + 1];
40888
+ if (bottom !== undefined) {
40889
+ bottom--;
40890
+ }
40891
+ const profileZone = {
40892
+ top,
40893
+ left,
40894
+ bottom,
40895
+ right,
40896
+ hasHeader: (bottom === undefined && top !== 0) || (right === undefined && left !== 0),
40897
+ };
40898
+ let findCorrespondingZone = false;
40899
+ for (let j = pendingZones.length - 1; j >= 0; j--) {
40900
+ const pendingZone = pendingZones[j];
40901
+ if (pendingZone.top === profileZone.top && pendingZone.bottom === profileZone.bottom) {
40902
+ pendingZone.right = profileZone.right;
40903
+ pendingZones.splice(j, 1);
40904
+ nextPendingZones.push(pendingZone);
40905
+ findCorrespondingZone = true;
40906
+ break;
40907
+ }
40908
+ }
40909
+ if (!findCorrespondingZone) {
40910
+ nextPendingZones.push(profileZone);
40911
+ }
40912
+ }
40913
+ mergedZone.push(...pendingZones);
40914
+ pendingZones = nextPendingZones;
40915
+ }
40916
+ mergedZone.push(...pendingZones);
40917
+ return mergedZone;
40918
+ }
40919
+ function binaryPredecessorSearch(arr, val, start = 0, matchEqual = true) {
40920
+ let end = arr.length - 1;
40921
+ let result = -1;
40922
+ while (start <= end) {
40923
+ const mid = Math.floor((start + end) / 2);
40924
+ if (arr[mid] === val && matchEqual) {
40925
+ return mid;
40926
+ }
40927
+ else if (arr[mid] < val) {
40928
+ result = mid;
40929
+ start = mid + 1;
40930
+ }
40931
+ else {
40932
+ end = mid - 1;
40933
+ }
40934
+ }
40935
+ return result;
40936
+ }
40937
+ function binarySuccessorSearch(arr, val, start = 0, matchEqual = true) {
40938
+ let end = arr.length - 1;
40939
+ let result = arr.length;
40940
+ while (start <= end) {
40941
+ const mid = Math.floor((start + end) / 2);
40942
+ if (arr[mid] === val && matchEqual) {
40943
+ return mid;
40944
+ }
40945
+ else if (arr[mid] > val) {
40946
+ result = mid;
40947
+ end = mid - 1;
40948
+ }
40949
+ else {
40950
+ start = mid + 1;
40951
+ }
40952
+ }
40953
+ return result;
40954
+ }
40955
+ /**
40956
+ * Compares two arrays.
40957
+ * For performance reasons, this function is to be preferred
40958
+ * to 'deepEquals' in the case we know that the inputs are arrays.
40959
+ */
40960
+ function deepEqualsArray(arr1, arr2) {
40961
+ if (arr1.length !== arr2.length) {
40962
+ return false;
40963
+ }
40964
+ for (let i = 0; i < arr1.length; i++) {
40965
+ if (!deepEquals(arr1[i], arr2[i])) {
40966
+ return false;
40967
+ }
40968
+ }
40969
+ return true;
40970
+ }
40971
+
40628
40972
  function quickselect(arr, k, left, right, compare) {
40629
40973
  quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare);
40630
40974
  }
@@ -41388,7 +41732,7 @@
41388
41732
  }
41389
41733
  }
41390
41734
  /**
41391
- * Return the cell and all cells that depend on it,
41735
+ * Return all the cells that depend on the provided ranges,
41392
41736
  * in the correct order they should be evaluated.
41393
41737
  * This is called a topological ordering (excluding cycles)
41394
41738
  */
@@ -41399,11 +41743,20 @@
41399
41743
  const range = queue.pop();
41400
41744
  visited.addMany(this.encoder.encodeBoundingBox(range));
41401
41745
  const impactedPositionIds = this.rTree.search(range).map((dep) => dep.data);
41746
+ const nextInQueue = {};
41402
41747
  for (const positionId of impactedPositionIds) {
41403
41748
  if (!visited.has(positionId)) {
41404
- queue.push(this.encoder.decodeToBoundingBox(positionId));
41749
+ const { sheetId, zone } = this.encoder.decodeToBoundingBox(positionId);
41750
+ if (!nextInQueue[sheetId]) {
41751
+ nextInQueue[sheetId] = [];
41752
+ }
41753
+ nextInQueue[sheetId].push(zone);
41405
41754
  }
41406
41755
  }
41756
+ for (const sheetId in nextInQueue) {
41757
+ const zones = futureRecomputeZones(nextInQueue[sheetId]);
41758
+ queue.push(...zones.map((zone) => ({ sheetId, zone })));
41759
+ }
41407
41760
  }
41408
41761
  visited.deleteMany(ranges.flatMap((r) => this.encoder.encodeBoundingBox(r)));
41409
41762
  return visited;
@@ -41561,7 +41914,7 @@
41561
41914
  }
41562
41915
  if (!content) {
41563
41916
  // The previous content could have blocked some array formulas
41564
- impactedPositionIds.addMany(this.getArrayFormulasBlockedByOrSpreadingOn(positionId));
41917
+ impactedPositionIds.addMany(this.getArrayFormulasBlockedBy(positionId));
41565
41918
  }
41566
41919
  }
41567
41920
  return impactedPositionIds;
@@ -41609,13 +41962,22 @@
41609
41962
  }
41610
41963
  return positionIds;
41611
41964
  }
41612
- getArrayFormulasBlockedByOrSpreadingOn(positionId) {
41965
+ /**
41966
+ * Return the position of formulas blocked by the given position
41967
+ * as well as all their dependencies.
41968
+ */
41969
+ getArrayFormulasBlockedBy(positionId) {
41613
41970
  if (!this.spreadingRelations.hasArrayFormulaResult(positionId)) {
41614
41971
  return [];
41615
41972
  }
41616
41973
  const arrayFormulas = this.spreadingRelations.getFormulaPositionsSpreadingOn(positionId);
41617
41974
  const cells = new JetSet(arrayFormulas);
41618
- cells.addMany(this.getCellsDependingOn(arrayFormulas));
41975
+ const arrayFormulaPositionId = this.getArrayFormulaSpreadingOnId(positionId);
41976
+ if (arrayFormulaPositionId) {
41977
+ // ignore the formula spreading on the position. Keep only the blocked ones
41978
+ cells.delete(arrayFormulaPositionId);
41979
+ }
41980
+ cells.addMany(this.getCellsDependingOn(cells));
41619
41981
  return cells;
41620
41982
  }
41621
41983
  nextPositionsToUpdate = new JetSet();
@@ -41769,7 +42131,7 @@
41769
42131
  }
41770
42132
  this.evaluatedCells.delete(child);
41771
42133
  this.nextPositionsToUpdate.addMany(this.getCellsDependingOn([child]));
41772
- this.nextPositionsToUpdate.addMany(this.getArrayFormulasBlockedByOrSpreadingOn(child));
42134
+ this.nextPositionsToUpdate.addMany(this.getArrayFormulasBlockedBy(child));
41773
42135
  }
41774
42136
  this.spreadingRelations.removeNode(positionId);
41775
42137
  }
@@ -57355,9 +57717,9 @@
57355
57717
  exports.tokenize = tokenize;
57356
57718
 
57357
57719
 
57358
- __info__.version = "17.1.12";
57359
- __info__.date = "2024-04-18T16:45:30.109Z";
57360
- __info__.hash = "3e90776";
57720
+ __info__.version = "17.1.13";
57721
+ __info__.date = "2024-04-26T07:39:54.100Z";
57722
+ __info__.hash = "f2ea8c7";
57361
57723
 
57362
57724
 
57363
57725
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);