@odoo/o-spreadsheet 17.2.1 → 17.2.2

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.1
7
- * @date 2024-03-25T09:41:58.737Z
8
- * @hash f97284c
6
+ * @version 17.2.2
7
+ * @date 2024-04-05T14:01:19.824Z
8
+ * @hash c15836d
9
9
  */
10
10
 
11
11
  'use strict';
@@ -466,7 +466,7 @@ function getItemId(item, itemsDic) {
466
466
  }
467
467
  // Generate new Id if the item didn't exist in the dictionary
468
468
  const ids = Object.keys(itemsDic);
469
- const maxId = ids.length === 0 ? 0 : Math.max(...ids.map((id) => parseInt(id, 10)));
469
+ const maxId = ids.length === 0 ? 0 : largeMax(ids.map((id) => parseInt(id, 10)));
470
470
  itemsDic[maxId + 1] = item;
471
471
  return maxId + 1;
472
472
  }
@@ -686,6 +686,34 @@ function getSearchRegex(searchStr, searchOptions) {
686
686
  }
687
687
  return RegExp(searchValue, flags);
688
688
  }
689
+ /**
690
+ * Alternative to Math.max that works with large arrays.
691
+ * Typically useful for arrays bigger than 100k elements.
692
+ */
693
+ function largeMax(array) {
694
+ let len = array.length;
695
+ if (len < 100000)
696
+ return Math.max(...array);
697
+ let max = -Infinity;
698
+ while (len--) {
699
+ max = array[len] > max ? array[len] : max;
700
+ }
701
+ return max;
702
+ }
703
+ /**
704
+ * Alternative to Math.min that works with large arrays.
705
+ * Typically useful for arrays bigger than 100k elements.
706
+ */
707
+ function largeMin(array) {
708
+ let len = array.length;
709
+ if (len < 100000)
710
+ return Math.min(...array);
711
+ let min = +Infinity;
712
+ while (len--) {
713
+ min = array[len] < min ? array[len] : min;
714
+ }
715
+ return min;
716
+ }
689
717
 
690
718
  const RBA_REGEX = /rgba?\(|\s+|\)/gi;
691
719
  const HEX_MATCH = /^#([A-F\d]{2}){3,4}$/;
@@ -4545,8 +4573,9 @@ function computeTextLinesHeight(textLineHeight, numberOfLines = 1) {
4545
4573
  * Get the default height of the cell given its style.
4546
4574
  */
4547
4575
  function getDefaultCellHeight(ctx, cell, colSize) {
4548
- if (!cell || !cell.content)
4576
+ if (!cell || (!cell.isFormula && !cell.content)) {
4549
4577
  return DEFAULT_CELL_HEIGHT;
4578
+ }
4550
4579
  const maxWidth = cell.style?.wrapping === "wrap" ? colSize - 2 * MIN_CELL_TEXT_MARGIN : undefined;
4551
4580
  const numberOfLines = cell.isFormula
4552
4581
  ? 1
@@ -9940,11 +9969,11 @@ autoCompleteProviders.add("dataValidation", {
9940
9969
  }
9941
9970
  else {
9942
9971
  const range = this.getters.getRangeFromSheetXC(position.sheetId, rule.criterion.values[0]);
9943
- values = this.getters
9972
+ values = Array.from(new Set(this.getters
9944
9973
  .getRangeValues(range)
9945
9974
  .filter(isNotNull)
9946
9975
  .map((value) => value.toString())
9947
- .filter((val) => val !== "");
9976
+ .filter((val) => val !== "")));
9948
9977
  }
9949
9978
  return values.map((value) => ({ text: value }));
9950
9979
  },
@@ -19391,10 +19420,10 @@ function aggregateDataForLabels(labels, datasets) {
19391
19420
  }
19392
19421
  }
19393
19422
  return {
19394
- labels: Object.keys(labelMap),
19423
+ labels: Array.from(labelSet),
19395
19424
  dataSetsValues: datasets.map((dataset, indexOfDataset) => ({
19396
19425
  ...dataset,
19397
- data: Object.values(labelMap).map((dataOfLabel) => dataOfLabel[indexOfDataset]),
19426
+ data: Array.from(labelSet).map((label) => labelMap[label][indexOfDataset]),
19398
19427
  })),
19399
19428
  };
19400
19429
  }
@@ -20126,7 +20155,7 @@ function getBestTimeUnitForScale(labels, format, locale) {
20126
20155
  return undefined;
20127
20156
  }
20128
20157
  const labelsTimestamps = labelDates.map((date) => date.getTime());
20129
- const period = Math.max(...labelsTimestamps) - Math.min(...labelsTimestamps);
20158
+ const period = largeMax(labelsTimestamps) - largeMin(labelsTimestamps);
20130
20159
  const minUnit = getFormatMinDisplayUnit(format);
20131
20160
  if (UNIT_LENGTH.second >= UNIT_LENGTH[minUnit] && Milliseconds.inSeconds(period) < 180) {
20132
20161
  return "second";
@@ -20614,7 +20643,7 @@ function getPieConfiguration(chart, labels, localeFormat) {
20614
20643
  }
20615
20644
  function getPieColors(colors, dataSetsValues) {
20616
20645
  const pieColors = [];
20617
- const maxLength = Math.max(...dataSetsValues.map((ds) => ds.data.length));
20646
+ const maxLength = largeMax(dataSetsValues.map((ds) => ds.data.length));
20618
20647
  for (let i = 0; i <= maxLength; i++) {
20619
20648
  pieColors.push(colors.next());
20620
20649
  }
@@ -23419,8 +23448,8 @@ const DELETE_CONTENT_ROWS_NAME = (env) => {
23419
23448
  let last;
23420
23449
  const activesRows = env.model.getters.getActiveRows();
23421
23450
  if (activesRows.size !== 0) {
23422
- first = Math.min(...activesRows);
23423
- last = Math.max(...activesRows);
23451
+ first = largeMin([...activesRows]);
23452
+ last = largeMax([...activesRows]);
23424
23453
  }
23425
23454
  else {
23426
23455
  const zone = env.model.getters.getSelectedZones()[0];
@@ -23448,8 +23477,8 @@ const DELETE_CONTENT_COLUMNS_NAME = (env) => {
23448
23477
  let last;
23449
23478
  const activeCols = env.model.getters.getActiveCols();
23450
23479
  if (activeCols.size !== 0) {
23451
- first = Math.min(...activeCols);
23452
- last = Math.max(...activeCols);
23480
+ first = largeMin([...activeCols]);
23481
+ last = largeMax([...activeCols]);
23453
23482
  }
23454
23483
  else {
23455
23484
  const zone = env.model.getters.getSelectedZones()[0];
@@ -23477,8 +23506,8 @@ const REMOVE_ROWS_NAME = (env) => {
23477
23506
  let last;
23478
23507
  const activesRows = env.model.getters.getActiveRows();
23479
23508
  if (activesRows.size !== 0) {
23480
- first = Math.min(...activesRows);
23481
- last = Math.max(...activesRows);
23509
+ first = largeMin([...activesRows]);
23510
+ last = largeMax([...activesRows]);
23482
23511
  }
23483
23512
  else {
23484
23513
  const zone = env.model.getters.getSelectedZones()[0];
@@ -23519,8 +23548,8 @@ const REMOVE_COLUMNS_NAME = (env) => {
23519
23548
  let last;
23520
23549
  const activeCols = env.model.getters.getActiveCols();
23521
23550
  if (activeCols.size !== 0) {
23522
- first = Math.min(...activeCols);
23523
- last = Math.max(...activeCols);
23551
+ first = largeMin([...activeCols]);
23552
+ last = largeMax([...activeCols]);
23524
23553
  }
23525
23554
  else {
23526
23555
  const zone = env.model.getters.getSelectedZones()[0];
@@ -23561,7 +23590,7 @@ const INSERT_ROWS_BEFORE_ACTION = (env) => {
23561
23590
  let row;
23562
23591
  let quantity;
23563
23592
  if (activeRows.size) {
23564
- row = Math.min(...activeRows);
23593
+ row = largeMin([...activeRows]);
23565
23594
  quantity = activeRows.size;
23566
23595
  }
23567
23596
  else {
@@ -23582,7 +23611,7 @@ const INSERT_ROWS_AFTER_ACTION = (env) => {
23582
23611
  let row;
23583
23612
  let quantity;
23584
23613
  if (activeRows.size) {
23585
- row = Math.max(...activeRows);
23614
+ row = largeMax([...activeRows]);
23586
23615
  quantity = activeRows.size;
23587
23616
  }
23588
23617
  else {
@@ -23603,7 +23632,7 @@ const INSERT_COLUMNS_BEFORE_ACTION = (env) => {
23603
23632
  let column;
23604
23633
  let quantity;
23605
23634
  if (activeCols.size) {
23606
- column = Math.min(...activeCols);
23635
+ column = largeMin([...activeCols]);
23607
23636
  quantity = activeCols.size;
23608
23637
  }
23609
23638
  else {
@@ -23624,7 +23653,7 @@ const INSERT_COLUMNS_AFTER_ACTION = (env) => {
23624
23653
  let column;
23625
23654
  let quantity;
23626
23655
  if (activeCols.size) {
23627
- column = Math.max(...activeCols);
23656
+ column = largeMax([...activeCols]);
23628
23657
  quantity = activeCols.size;
23629
23658
  }
23630
23659
  else {
@@ -30223,7 +30252,11 @@ class SplitIntoColumnsPanel extends owl.Component {
30223
30252
  const composerStore = useStore(ComposerStore);
30224
30253
  // The feature makes no sense if we are editing a cell, because then the selection isn't active
30225
30254
  // Stop the edition when the panel is mounted, and close the panel if the user start editing a cell
30226
- owl.useEffect(this.props.onCloseSidePanel, () => [composerStore.editionMode]);
30255
+ owl.useEffect((editionMode) => {
30256
+ if (editionMode !== "inactive") {
30257
+ this.props.onCloseSidePanel();
30258
+ }
30259
+ }, () => [composerStore.editionMode]);
30227
30260
  owl.onMounted(() => {
30228
30261
  composerStore.stopEdition();
30229
30262
  });
@@ -32019,6 +32052,12 @@ class Composer extends owl.Component {
32019
32052
  owl.useEffect(() => {
32020
32053
  this.processContent();
32021
32054
  });
32055
+ owl.onPatched(() => {
32056
+ // Required because typing '=SUM' and double-clicking another cell leaves ShowProvider/ShowDescription true
32057
+ if (this.composerStore.editionMode === "inactive") {
32058
+ this.processTokenAtCursor();
32059
+ }
32060
+ });
32022
32061
  }
32023
32062
  // ---------------------------------------------------------------------------
32024
32063
  // Handlers
@@ -33999,11 +34038,6 @@ css /* scss */ `
33999
34038
  height: 10000px;
34000
34039
  background-color: ${SELECTION_BORDER_COLOR};
34001
34040
  }
34002
- .o-unhide-buttons {
34003
- width: fit-content;
34004
- gap: 5px;
34005
- transform: translate(-50%, 0);
34006
- }
34007
34041
  .o-unhide:hover {
34008
34042
  z-index: ${ComponentsImportance.Grid + 1};
34009
34043
  background-color: lightgrey;
@@ -34165,10 +34199,6 @@ css /* scss */ `
34165
34199
  height: 1px;
34166
34200
  background-color: ${SELECTION_BORDER_COLOR};
34167
34201
  }
34168
- .o-unhide-buttons {
34169
- height: fit-content;
34170
- transform: translate(0, -50%);
34171
- }
34172
34202
  .o-unhide:hover {
34173
34203
  z-index: ${ComponentsImportance.Grid + 1};
34174
34204
  background-color: lightgrey;
@@ -37862,7 +37892,7 @@ function convertHyperlink(link, cellValue, warningManager) {
37862
37892
  function getSheetDims(sheet) {
37863
37893
  const dims = [0, 0];
37864
37894
  for (let row of sheet.rows) {
37865
- dims[0] = Math.max(dims[0], ...row.cells.map((cell) => toCartesian(cell.xc).col));
37895
+ dims[0] = Math.max(dims[0], largeMax(row.cells.map((cell) => toCartesian(cell.xc).col)));
37866
37896
  dims[1] = Math.max(dims[1], row.index);
37867
37897
  }
37868
37898
  dims[0] = Math.max(dims[0], EXCEL_IMPORT_DEFAULT_NUMBER_OF_COLS);
@@ -42369,6 +42399,9 @@ class DataValidationPlugin extends CorePlugin {
42369
42399
  if (newRule.criterion.type === "isBoolean") {
42370
42400
  this.setCenterStyleToBooleanCells(newRule);
42371
42401
  }
42402
+ else if (newRule.criterion.type === "isValueInList") {
42403
+ newRule.criterion.values = Array.from(new Set(newRule.criterion.values));
42404
+ }
42372
42405
  const adaptedRules = this.removeRangesFromRules(sheetId, newRule.ranges, rules);
42373
42406
  const ruleIndex = adaptedRules.findIndex((rule) => rule.id === newRule.id);
42374
42407
  if (ruleIndex !== -1) {
@@ -42765,7 +42798,7 @@ class HeaderVisibilityPlugin extends CorePlugin {
42765
42798
  if (hiddenElements.size >= elements) {
42766
42799
  return "TooManyHiddenElements" /* CommandResult.TooManyHiddenElements */;
42767
42800
  }
42768
- else if (Math.min(...cmd.elements) < 0 || Math.max(...cmd.elements) > elements) {
42801
+ else if (largeMin(cmd.elements) < 0 || largeMax(cmd.elements) > elements) {
42769
42802
  return "InvalidHeaderIndex" /* CommandResult.InvalidHeaderIndex */;
42770
42803
  }
42771
42804
  else {
@@ -43583,8 +43616,8 @@ class RangeAdapter {
43583
43616
  let newRange = range;
43584
43617
  let changeType = "NONE";
43585
43618
  for (let group of groups) {
43586
- const min = Math.min(...group);
43587
- const max = Math.max(...group);
43619
+ const min = largeMin(group);
43620
+ const max = largeMax(group);
43588
43621
  if (range.zone[start] <= min && min <= range.zone[end]) {
43589
43622
  const toRemove = Math.min(range.zone[end], max) - min + 1;
43590
43623
  changeType = "RESIZE";
@@ -44033,8 +44066,8 @@ class SheetPlugin extends CorePlugin {
44033
44066
  }
44034
44067
  return "Success" /* CommandResult.Success */;
44035
44068
  case "REMOVE_COLUMNS_ROWS": {
44036
- const min = Math.min(...cmd.elements);
44037
- const max = Math.max(...cmd.elements);
44069
+ const min = largeMin(cmd.elements);
44070
+ const max = largeMax(cmd.elements);
44038
44071
  if (min < 0 || !this.doesHeaderExist(cmd.sheetId, cmd.dimension, max)) {
44039
44072
  return "InvalidHeaderIndex" /* CommandResult.InvalidHeaderIndex */;
44040
44073
  }
@@ -47498,7 +47531,7 @@ class EvaluationPlugin extends UIPlugin {
47498
47531
  ? getItemId(newFormat, data.formats)
47499
47532
  : exportedCellData.format;
47500
47533
  let content;
47501
- if (formulaCell instanceof FormulaCellWithDependencies) {
47534
+ if (isFormula && formulaCell instanceof FormulaCellWithDependencies) {
47502
47535
  content = formulaCell.contentWithFixedReferences;
47503
47536
  }
47504
47537
  else {
@@ -47947,13 +47980,13 @@ class EvaluationConditionalFormatPlugin extends UIPlugin {
47947
47980
  .map((cell) => cell.value);
47948
47981
  switch (threshold.type) {
47949
47982
  case "value":
47950
- const result = functionName === "max" ? Math.max(...rangeValues) : Math.min(...rangeValues);
47983
+ const result = functionName === "max" ? largeMax(rangeValues) : largeMin(rangeValues);
47951
47984
  return result;
47952
47985
  case "number":
47953
47986
  return Number(threshold.value);
47954
47987
  case "percentage":
47955
- const min = Math.min(...rangeValues);
47956
- const max = Math.max(...rangeValues);
47988
+ const min = largeMin(rangeValues);
47989
+ const max = largeMax(rangeValues);
47957
47990
  const delta = max - min;
47958
47991
  return min + (delta * Number(threshold.value)) / 100;
47959
47992
  case "percentile":
@@ -49026,13 +49059,13 @@ class AutomaticSumPlugin extends UIPlugin {
49026
49059
  const cells = this.getters.getEvaluatedCellsInZone(sheet.id, zone);
49027
49060
  const cellPositions = range(end, -1, -1);
49028
49061
  const invalidCells = cellPositions.filter((position) => cells[position] && !cells[position].isAutoSummable);
49029
- const maxValidPosition = Math.max(...invalidCells);
49062
+ const maxValidPosition = largeMax(invalidCells);
49030
49063
  const numberSequences = groupConsecutive(cellPositions.filter((position) => this.isNumber(cells[position])));
49031
49064
  const firstSequence = numberSequences[0] || [];
49032
- if (Math.max(...firstSequence) < maxValidPosition) {
49065
+ if (largeMax(firstSequence) < maxValidPosition) {
49033
49066
  return Infinity;
49034
49067
  }
49035
- return Math.min(...firstSequence);
49068
+ return largeMin(firstSequence);
49036
49069
  }
49037
49070
  shouldFindData(sheetId, zone) {
49038
49071
  return this.getters.isEmpty(sheetId, zone) || this.getters.isSingleCellOrMerge(sheetId, zone);
@@ -50773,7 +50806,7 @@ class SheetUIPlugin extends UIPlugin {
50773
50806
  getColMaxWidth(sheetId, index) {
50774
50807
  const cellsPositions = positions(this.getters.getColsZone(sheetId, index, index));
50775
50808
  const sizes = cellsPositions.map((position) => this.getCellWidth({ sheetId, ...position }));
50776
- return Math.max(0, ...sizes);
50809
+ return Math.max(0, largeMax(sizes));
50777
50810
  }
50778
50811
  /**
50779
50812
  * Check that any "sheetId" in the command matches an existing
@@ -53669,7 +53702,7 @@ class SheetViewPlugin extends UIPlugin {
53669
53702
  * column of the current viewport
53670
53703
  */
53671
53704
  getColDimensionsInViewport(sheetId, col) {
53672
- const left = Math.min(...this.getters.getSheetViewVisibleCols());
53705
+ const left = largeMin(this.getters.getSheetViewVisibleCols());
53673
53706
  const start = this.getters.getColRowOffsetInViewport("COL", left, col);
53674
53707
  const size = this.getters.getColSize(sheetId, col);
53675
53708
  const isColHidden = this.getters.isColHidden(sheetId, col);
@@ -53684,7 +53717,7 @@ class SheetViewPlugin extends UIPlugin {
53684
53717
  * of the current viewport
53685
53718
  */
53686
53719
  getRowDimensionsInViewport(sheetId, row) {
53687
- const top = Math.min(...this.getters.getSheetViewVisibleRows());
53720
+ const top = largeMin(this.getters.getSheetViewVisibleRows());
53688
53721
  const start = this.getters.getColRowOffsetInViewport("ROW", top, row);
53689
53722
  const size = this.getters.getRowSize(sheetId, row);
53690
53723
  const isRowHidden = this.getters.isRowHidden(sheetId, row);
@@ -54397,12 +54430,14 @@ class BottomBarSheet extends owl.Component {
54397
54430
  this.editionState = "initializing";
54398
54431
  }
54399
54432
  stopEdition() {
54400
- if (!this.state.isEditing)
54433
+ const input = this.sheetNameRef.el;
54434
+ if (!this.state.isEditing || !input)
54401
54435
  return;
54402
54436
  this.state.isEditing = false;
54403
54437
  this.editionState = "initializing";
54404
- this.sheetNameRef.el?.blur();
54438
+ input.blur();
54405
54439
  const inputValue = this.getInputContent() || "";
54440
+ input.innerText = inputValue;
54406
54441
  interactiveRenameSheet(this.env, this.props.sheetId, inputValue, () => this.startEdition());
54407
54442
  }
54408
54443
  cancelEdition() {
@@ -54693,7 +54728,7 @@ class BottomBar extends owl.Component {
54693
54728
  this.sheetListRef.el.scrollTo({ top: 0, left: scroll, behavior: "smooth" });
54694
54729
  }
54695
54730
  onSheetMouseDown(sheetId, event) {
54696
- if (event.button !== 0)
54731
+ if (event.button !== 0 || this.env.model.getters.isReadonly())
54697
54732
  return;
54698
54733
  this.closeMenu();
54699
54734
  const visibleSheets = this.getVisibleSheets();
@@ -58147,7 +58182,7 @@ function addLineChart(chart) {
58147
58182
  }
58148
58183
  function addDoughnutChart(chart, chartSheetIndex, data, { holeSize } = { holeSize: 50 }) {
58149
58184
  const colors = new ChartColors();
58150
- const maxLength = Math.max(...chart.dataSets.map((ds) => getRangeSize(ds.range, chartSheetIndex, data)));
58185
+ const maxLength = largeMax(chart.dataSets.map((ds) => getRangeSize(ds.range, chartSheetIndex, data)));
58151
58186
  const doughnutColors = range(0, maxLength).map(() => toXlsxHexColor(colors.next()));
58152
58187
  const dataSetsNodes = [];
58153
58188
  for (const [dsIndex, dataset] of Object.entries(chart.dataSets).reverse()) {
@@ -60177,6 +60212,6 @@ exports.tokenColors = tokenColors;
60177
60212
  exports.tokenize = tokenize;
60178
60213
 
60179
60214
 
60180
- __info__.version = "17.2.1";
60181
- __info__.date = "2024-03-25T09:41:58.737Z";
60182
- __info__.hash = "f97284c";
60215
+ __info__.version = "17.2.2";
60216
+ __info__.date = "2024-04-05T14:01:19.824Z";
60217
+ __info__.hash = "c15836d";