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