@odoo/o-spreadsheet 17.0.16 → 17.0.17

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.16
6
- * @date 2024-03-25T09:42:01.717Z
7
- * @hash 9b128f8
5
+ * @version 17.0.17
6
+ * @date 2024-04-05T13:59:37.139Z
7
+ * @hash 33f09d7
8
8
  */
9
9
 
10
10
  import { Component, useRef, onMounted, useEffect, onWillPatch, useState, onWillUpdateProps, onPatched, useComponent, useExternalListener, onWillUnmount, onWillStart, xml, useChildSubEnv, useSubEnv, markRaw } from '@odoo/owl';
@@ -557,7 +557,7 @@ function getItemId(item, itemsDic) {
557
557
  }
558
558
  // Generate new Id if the item didn't exist in the dictionary
559
559
  const ids = Object.keys(itemsDic);
560
- const maxId = ids.length === 0 ? 0 : Math.max(...ids.map((id) => parseInt(id, 10)));
560
+ const maxId = ids.length === 0 ? 0 : largeMax(ids.map((id) => parseInt(id, 10)));
561
561
  itemsDic[maxId + 1] = item;
562
562
  return maxId + 1;
563
563
  }
@@ -774,6 +774,34 @@ function isNumberBetween(value, min, max) {
774
774
  }
775
775
  return value >= min && value <= max;
776
776
  }
777
+ /**
778
+ * Alternative to Math.max that works with large arrays.
779
+ * Typically useful for arrays bigger than 100k elements.
780
+ */
781
+ function largeMax(array) {
782
+ let len = array.length;
783
+ if (len < 100000)
784
+ return Math.max(...array);
785
+ let max = -Infinity;
786
+ while (len--) {
787
+ max = array[len] > max ? array[len] : max;
788
+ }
789
+ return max;
790
+ }
791
+ /**
792
+ * Alternative to Math.min that works with large arrays.
793
+ * Typically useful for arrays bigger than 100k elements.
794
+ */
795
+ function largeMin(array) {
796
+ let len = array.length;
797
+ if (len < 100000)
798
+ return Math.min(...array);
799
+ let min = +Infinity;
800
+ while (len--) {
801
+ min = array[len] < min ? array[len] : min;
802
+ }
803
+ return min;
804
+ }
777
805
 
778
806
  const RBA_REGEX = /rgba?\(|\s+|\)/gi;
779
807
  const HEX_MATCH = /^#([A-F\d]{2}){3,4}$/;
@@ -4420,8 +4448,9 @@ function computeTextLinesHeight(textLineHeight, numberOfLines = 1) {
4420
4448
  * Get the default height of the cell given its style.
4421
4449
  */
4422
4450
  function getDefaultCellHeight(ctx, cell, colSize) {
4423
- if (!cell || !cell.content)
4451
+ if (!cell || (!cell.isFormula && !cell.content)) {
4424
4452
  return DEFAULT_CELL_HEIGHT;
4453
+ }
4425
4454
  const maxWidth = cell.style?.wrapping === "wrap" ? colSize - 2 * MIN_CELL_TEXT_MARGIN : undefined;
4426
4455
  const numberOfLines = cell.isFormula
4427
4456
  ? 1
@@ -8324,10 +8353,10 @@ function aggregateDataForLabels(labels, datasets) {
8324
8353
  }
8325
8354
  }
8326
8355
  return {
8327
- labels: Object.keys(labelMap),
8356
+ labels: Array.from(labelSet),
8328
8357
  dataSetsValues: datasets.map((dataset, indexOfDataset) => ({
8329
8358
  ...dataset,
8330
- data: Object.values(labelMap).map((dataOfLabel) => dataOfLabel[indexOfDataset]),
8359
+ data: Array.from(labelSet).map((label) => labelMap[label][indexOfDataset]),
8331
8360
  })),
8332
8361
  };
8333
8362
  }
@@ -8378,7 +8407,7 @@ function getDefaultChartJsRuntime(chart, labels, fontColor, { format, locale })
8378
8407
  const xLabel = tooltipItem.dataset?.label || tooltipItem.label;
8379
8408
  // tooltipItem.parsed.y can be an object or a number for pie charts
8380
8409
  const yLabel = tooltipItem.parsed.y ?? tooltipItem.parsed;
8381
- const toolTipFormat = !format && yLabel > 1000 ? "#,##" : format;
8410
+ const toolTipFormat = !format && Math.abs(yLabel) >= 1000 ? "#,##" : format;
8382
8411
  const yLabelStr = formatValue(yLabel, { format: toolTipFormat, locale });
8383
8412
  return xLabel ? `${xLabel}: ${yLabelStr}` : yLabelStr;
8384
8413
  },
@@ -8664,7 +8693,10 @@ function getBarConfiguration(chart, labels, localeFormat) {
8664
8693
  if (isNaN(value))
8665
8694
  return value;
8666
8695
  const { locale, format } = localeFormat;
8667
- return formatValue(value, { locale, format: !format && value > 1000 ? "#,##" : format });
8696
+ return formatValue(value, {
8697
+ locale,
8698
+ format: !format && Math.abs(value) >= 1000 ? "#,##" : format,
8699
+ });
8668
8700
  },
8669
8701
  },
8670
8702
  },
@@ -9078,7 +9110,7 @@ function getBestTimeUnitForScale(labels, format, locale) {
9078
9110
  return undefined;
9079
9111
  }
9080
9112
  const labelsTimestamps = labelDates.map((date) => date.getTime());
9081
- const period = Math.max(...labelsTimestamps) - Math.min(...labelsTimestamps);
9113
+ const period = largeMax(labelsTimestamps) - largeMin(labelsTimestamps);
9082
9114
  const minUnit = getFormatMinDisplayUnit(format);
9083
9115
  if (UNIT_LENGTH.second >= UNIT_LENGTH[minUnit] && Milliseconds.inSeconds(period) < 180) {
9084
9116
  return "second";
@@ -9315,7 +9347,10 @@ function getLineConfiguration(chart, labels, localeFormat) {
9315
9347
  if (isNaN(value))
9316
9348
  return value;
9317
9349
  const { locale, format } = localeFormat;
9318
- return formatValue(value, { locale, format: !format && value > 1000 ? "#,##" : format });
9350
+ return formatValue(value, {
9351
+ locale,
9352
+ format: !format && Math.abs(value) >= 1000 ? "#,##" : format,
9353
+ });
9319
9354
  },
9320
9355
  },
9321
9356
  },
@@ -9542,7 +9577,7 @@ function getPieConfiguration(chart, labels, localeFormat) {
9542
9577
  const percentage = calculatePercentage(data, dataIndex);
9543
9578
  const xLabel = tooltipItem.label || tooltipItem.dataset.label;
9544
9579
  const yLabel = tooltipItem.parsed.y ?? tooltipItem.parsed;
9545
- const toolTipFormat = !format && yLabel > 1000 ? "#,##" : format;
9580
+ const toolTipFormat = !format && Math.abs(yLabel) >= 1000 ? "#,##" : format;
9546
9581
  const yLabelStr = formatValue(yLabel, { format: toolTipFormat, locale });
9547
9582
  return xLabel ? `${xLabel}: ${yLabelStr} (${percentage}%)` : `${yLabelStr} (${percentage}%)`;
9548
9583
  };
@@ -9550,7 +9585,7 @@ function getPieConfiguration(chart, labels, localeFormat) {
9550
9585
  }
9551
9586
  function getPieColors(colors, dataSetsValues) {
9552
9587
  const pieColors = [];
9553
- const maxLength = Math.max(...dataSetsValues.map((ds) => ds.data.length));
9588
+ const maxLength = largeMax(dataSetsValues.map((ds) => ds.data.length));
9554
9589
  for (let i = 0; i <= maxLength; i++) {
9555
9590
  pieColors.push(colors.next());
9556
9591
  }
@@ -10452,8 +10487,8 @@ const DELETE_CONTENT_ROWS_NAME = (env) => {
10452
10487
  let last;
10453
10488
  const activesRows = env.model.getters.getActiveRows();
10454
10489
  if (activesRows.size !== 0) {
10455
- first = Math.min(...activesRows);
10456
- last = Math.max(...activesRows);
10490
+ first = largeMin([...activesRows]);
10491
+ last = largeMax([...activesRows]);
10457
10492
  }
10458
10493
  else {
10459
10494
  const zone = env.model.getters.getSelectedZones()[0];
@@ -10481,8 +10516,8 @@ const DELETE_CONTENT_COLUMNS_NAME = (env) => {
10481
10516
  let last;
10482
10517
  const activeCols = env.model.getters.getActiveCols();
10483
10518
  if (activeCols.size !== 0) {
10484
- first = Math.min(...activeCols);
10485
- last = Math.max(...activeCols);
10519
+ first = largeMin([...activeCols]);
10520
+ last = largeMax([...activeCols]);
10486
10521
  }
10487
10522
  else {
10488
10523
  const zone = env.model.getters.getSelectedZones()[0];
@@ -10510,8 +10545,8 @@ const REMOVE_ROWS_NAME = (env) => {
10510
10545
  let last;
10511
10546
  const activesRows = env.model.getters.getActiveRows();
10512
10547
  if (activesRows.size !== 0) {
10513
- first = Math.min(...activesRows);
10514
- last = Math.max(...activesRows);
10548
+ first = largeMin([...activesRows]);
10549
+ last = largeMax([...activesRows]);
10515
10550
  }
10516
10551
  else {
10517
10552
  const zone = env.model.getters.getSelectedZones()[0];
@@ -10552,8 +10587,8 @@ const REMOVE_COLUMNS_NAME = (env) => {
10552
10587
  let last;
10553
10588
  const activeCols = env.model.getters.getActiveCols();
10554
10589
  if (activeCols.size !== 0) {
10555
- first = Math.min(...activeCols);
10556
- last = Math.max(...activeCols);
10590
+ first = largeMin([...activeCols]);
10591
+ last = largeMax([...activeCols]);
10557
10592
  }
10558
10593
  else {
10559
10594
  const zone = env.model.getters.getSelectedZones()[0];
@@ -10594,7 +10629,7 @@ const INSERT_ROWS_BEFORE_ACTION = (env) => {
10594
10629
  let row;
10595
10630
  let quantity;
10596
10631
  if (activeRows.size) {
10597
- row = Math.min(...activeRows);
10632
+ row = largeMin([...activeRows]);
10598
10633
  quantity = activeRows.size;
10599
10634
  }
10600
10635
  else {
@@ -10615,7 +10650,7 @@ const INSERT_ROWS_AFTER_ACTION = (env) => {
10615
10650
  let row;
10616
10651
  let quantity;
10617
10652
  if (activeRows.size) {
10618
- row = Math.max(...activeRows);
10653
+ row = largeMax([...activeRows]);
10619
10654
  quantity = activeRows.size;
10620
10655
  }
10621
10656
  else {
@@ -10636,7 +10671,7 @@ const INSERT_COLUMNS_BEFORE_ACTION = (env) => {
10636
10671
  let column;
10637
10672
  let quantity;
10638
10673
  if (activeCols.size) {
10639
- column = Math.min(...activeCols);
10674
+ column = largeMin([...activeCols]);
10640
10675
  quantity = activeCols.size;
10641
10676
  }
10642
10677
  else {
@@ -10657,7 +10692,7 @@ const INSERT_COLUMNS_AFTER_ACTION = (env) => {
10657
10692
  let column;
10658
10693
  let quantity;
10659
10694
  if (activeCols.size) {
10660
- column = Math.max(...activeCols);
10695
+ column = largeMax([...activeCols]);
10661
10696
  quantity = activeCols.size;
10662
10697
  }
10663
10698
  else {
@@ -31854,7 +31889,7 @@ function convertHyperlink(link, cellValue, warningManager) {
31854
31889
  function getSheetDims(sheet) {
31855
31890
  const dims = [0, 0];
31856
31891
  for (let row of sheet.rows) {
31857
- dims[0] = Math.max(dims[0], ...row.cells.map((cell) => toCartesian(cell.xc).col));
31892
+ dims[0] = Math.max(dims[0], largeMax(row.cells.map((cell) => toCartesian(cell.xc).col)));
31858
31893
  dims[1] = Math.max(dims[1], row.index);
31859
31894
  }
31860
31895
  dims[0] = Math.max(dims[0], EXCEL_IMPORT_DEFAULT_NUMBER_OF_COLS);
@@ -36744,6 +36779,9 @@ class DataValidationPlugin extends CorePlugin {
36744
36779
  if (newRule.criterion.type === "isBoolean") {
36745
36780
  this.setCenterStyleToBooleanCells(newRule);
36746
36781
  }
36782
+ else if (newRule.criterion.type === "isValueInList") {
36783
+ newRule.criterion.values = Array.from(new Set(newRule.criterion.values));
36784
+ }
36747
36785
  const adaptedRules = this.removeRangesFromRules(sheetId, newRule.ranges, rules);
36748
36786
  const ruleIndex = adaptedRules.findIndex((rule) => rule.id === newRule.id);
36749
36787
  if (ruleIndex !== -1) {
@@ -37470,7 +37508,7 @@ class HeaderVisibilityPlugin extends CorePlugin {
37470
37508
  if (hiddenElements.size >= elements) {
37471
37509
  return "TooManyHiddenElements" /* CommandResult.TooManyHiddenElements */;
37472
37510
  }
37473
- else if (Math.min(...cmd.elements) < 0 || Math.max(...cmd.elements) > elements) {
37511
+ else if (largeMin(cmd.elements) < 0 || largeMax(cmd.elements) > elements) {
37474
37512
  return "InvalidHeaderIndex" /* CommandResult.InvalidHeaderIndex */;
37475
37513
  }
37476
37514
  else {
@@ -38285,8 +38323,8 @@ class RangeAdapter {
38285
38323
  let newRange = range;
38286
38324
  let changeType = "NONE";
38287
38325
  for (let group of groups) {
38288
- const min = Math.min(...group);
38289
- const max = Math.max(...group);
38326
+ const min = largeMin(group);
38327
+ const max = largeMax(group);
38290
38328
  if (range.zone[start] <= min && min <= range.zone[end]) {
38291
38329
  const toRemove = Math.min(range.zone[end], max) - min + 1;
38292
38330
  changeType = "RESIZE";
@@ -38709,8 +38747,8 @@ class SheetPlugin extends CorePlugin {
38709
38747
  }
38710
38748
  return "Success" /* CommandResult.Success */;
38711
38749
  case "REMOVE_COLUMNS_ROWS": {
38712
- const min = Math.min(...cmd.elements);
38713
- const max = Math.max(...cmd.elements);
38750
+ const min = largeMin(cmd.elements);
38751
+ const max = largeMax(cmd.elements);
38714
38752
  if (min < 0 || !this.doesHeaderExist(cmd.sheetId, cmd.dimension, max)) {
38715
38753
  return "InvalidHeaderIndex" /* CommandResult.InvalidHeaderIndex */;
38716
38754
  }
@@ -42042,13 +42080,13 @@ class EvaluationConditionalFormatPlugin extends UIPlugin {
42042
42080
  .map((cell) => cell.value);
42043
42081
  switch (threshold.type) {
42044
42082
  case "value":
42045
- const result = functionName === "max" ? Math.max(...rangeValues) : Math.min(...rangeValues);
42083
+ const result = functionName === "max" ? largeMax(rangeValues) : largeMin(rangeValues);
42046
42084
  return result;
42047
42085
  case "number":
42048
42086
  return Number(threshold.value);
42049
42087
  case "percentage":
42050
- const min = Math.min(...rangeValues);
42051
- const max = Math.max(...rangeValues);
42088
+ const min = largeMin(rangeValues);
42089
+ const max = largeMax(rangeValues);
42052
42090
  const delta = max - min;
42053
42091
  return min + (delta * Number(threshold.value)) / 100;
42054
42092
  case "percentile":
@@ -43100,13 +43138,13 @@ class AutomaticSumPlugin extends UIPlugin {
43100
43138
  const cells = this.getters.getEvaluatedCellsInZone(sheet.id, zone);
43101
43139
  const cellPositions = range(end, -1, -1);
43102
43140
  const invalidCells = cellPositions.filter((position) => cells[position] && !cells[position].isAutoSummable);
43103
- const maxValidPosition = Math.max(...invalidCells);
43141
+ const maxValidPosition = largeMax(invalidCells);
43104
43142
  const numberSequences = groupConsecutive(cellPositions.filter((position) => this.isNumber(cells[position])));
43105
43143
  const firstSequence = numberSequences[0] || [];
43106
- if (Math.max(...firstSequence) < maxValidPosition) {
43144
+ if (largeMax(firstSequence) < maxValidPosition) {
43107
43145
  return Infinity;
43108
43146
  }
43109
- return Math.min(...firstSequence);
43147
+ return largeMin(firstSequence);
43110
43148
  }
43111
43149
  shouldFindData(sheetId, zone) {
43112
43150
  return this.getters.isEmpty(sheetId, zone) || this.getters.isSingleCellOrMerge(sheetId, zone);
@@ -45510,7 +45548,7 @@ class RendererPlugin extends UIPlugin {
45510
45548
  * column of the current viewport
45511
45549
  */
45512
45550
  getColDimensionsInViewport(sheetId, col) {
45513
- const left = Math.min(...this.getters.getSheetViewVisibleCols());
45551
+ const left = largeMin(this.getters.getSheetViewVisibleCols());
45514
45552
  const start = this.getters.getColRowOffsetInViewport("COL", left, col);
45515
45553
  const size = this.getters.getColSize(sheetId, col);
45516
45554
  const isColHidden = this.getters.isColHidden(sheetId, col);
@@ -45525,7 +45563,7 @@ class RendererPlugin extends UIPlugin {
45525
45563
  * of the current viewport
45526
45564
  */
45527
45565
  getRowDimensionsInViewport(sheetId, row) {
45528
- const top = Math.min(...this.getters.getSheetViewVisibleRows());
45566
+ const top = largeMin(this.getters.getSheetViewVisibleRows());
45529
45567
  const start = this.getters.getColRowOffsetInViewport("ROW", top, row);
45530
45568
  const size = this.getters.getRowSize(sheetId, row);
45531
45569
  const isRowHidden = this.getters.isRowHidden(sheetId, row);
@@ -46989,7 +47027,7 @@ class SheetUIPlugin extends UIPlugin {
46989
47027
  getColMaxWidth(sheetId, index) {
46990
47028
  const cellsPositions = positions(this.getters.getColsZone(sheetId, index, index));
46991
47029
  const sizes = cellsPositions.map((position) => this.getCellWidth({ sheetId, ...position }));
46992
- return Math.max(0, ...sizes);
47030
+ return Math.max(0, largeMax(sizes));
46993
47031
  }
46994
47032
  /**
46995
47033
  * Check that any "sheetId" in the command matches an existing
@@ -47754,7 +47792,7 @@ class ClipboardOsState extends ClipboardCellsAbstractState {
47754
47792
  }
47755
47793
  getPasteZone(target) {
47756
47794
  const height = this.values.length;
47757
- const width = Math.max(...this.values.map((a) => a.length));
47795
+ const width = largeMax(this.values.map((a) => a.length));
47758
47796
  const { left: activeCol, top: activeRow } = target[0];
47759
47797
  return {
47760
47798
  top: activeRow,
@@ -48791,11 +48829,11 @@ class EditionPlugin extends UIPlugin {
48791
48829
  }
48792
48830
  else {
48793
48831
  const range = this.getters.getRangeFromSheetXC(this.sheetId, rule.criterion.values[0]);
48794
- values = this.getters
48832
+ values = Array.from(new Set(this.getters
48795
48833
  .getRangeValues(range)
48796
48834
  .filter(isNotNull)
48797
48835
  .map((value) => value.toString())
48798
- .filter((val) => val !== "");
48836
+ .filter((val) => val !== "")));
48799
48837
  }
48800
48838
  const composerContent = this.getCurrentContent();
48801
48839
  if (composerContent && composerContent !== this.getInitialComposerContent()) {
@@ -51252,12 +51290,14 @@ class BottomBarSheet extends Component {
51252
51290
  this.editionState = "initializing";
51253
51291
  }
51254
51292
  stopEdition() {
51255
- if (!this.state.isEditing)
51293
+ const input = this.sheetNameRef.el;
51294
+ if (!this.state.isEditing || !input)
51256
51295
  return;
51257
51296
  this.state.isEditing = false;
51258
51297
  this.editionState = "initializing";
51259
- this.sheetNameRef.el?.blur();
51298
+ input.blur();
51260
51299
  const inputValue = this.getInputContent() || "";
51300
+ input.innerText = inputValue;
51261
51301
  interactiveRenameSheet(this.env, this.props.sheetId, inputValue, () => this.startEdition());
51262
51302
  }
51263
51303
  cancelEdition() {
@@ -51551,7 +51591,7 @@ class BottomBar extends Component {
51551
51591
  this.sheetListRef.el.scrollTo({ top: 0, left: scroll, behavior: "smooth" });
51552
51592
  }
51553
51593
  onSheetMouseDown(sheetId, event) {
51554
- if (event.button !== 0)
51594
+ if (event.button !== 0 || this.env.model.getters.isReadonly())
51555
51595
  return;
51556
51596
  this.closeMenu();
51557
51597
  const visibleSheets = this.getVisibleSheets();
@@ -55056,7 +55096,7 @@ function addLineChart(chart) {
55056
55096
  }
55057
55097
  function addDoughnutChart(chart, chartSheetIndex, data, { holeSize } = { holeSize: 50 }) {
55058
55098
  const colors = new ChartColors();
55059
- const maxLength = Math.max(...chart.dataSets.map((ds) => getRangeSize(ds.range, chartSheetIndex, data)));
55099
+ const maxLength = largeMax(chart.dataSets.map((ds) => getRangeSize(ds.range, chartSheetIndex, data)));
55060
55100
  const doughnutColors = range(0, maxLength).map(() => toXlsxHexColor(colors.next()));
55061
55101
  const dataSetsNodes = [];
55062
55102
  for (const [dsIndex, dataset] of Object.entries(chart.dataSets).reverse()) {
@@ -56975,6 +57015,6 @@ const constants = {
56975
57015
  export { AbstractChart, CommandResult, CorePlugin, DispatchResult, EvaluationError, Model, Registry, Revision, SPREADSHEET_DIMENSIONS, Spreadsheet, UIPlugin, __info__, addFunction, astToFormula, compile, compileTokens, components, constants, convertAstNodes, coreTypes, findCellInNewZone, functionCache, helpers, hooks, invalidateCFEvaluationCommands, invalidateDependenciesCommands, invalidateEvaluationCommands, iterateAstNodes, links, load, parse, parseTokens, readonlyAllowedCommands, registries, setDefaultSheetViewSize, setTranslationMethod, tokenize };
56976
57016
 
56977
57017
 
56978
- __info__.version = "17.0.16";
56979
- __info__.date = "2024-03-25T09:42:01.717Z";
56980
- __info__.hash = "9b128f8";
57018
+ __info__.version = "17.0.17";
57019
+ __info__.date = "2024-04-05T13:59:37.139Z";
57020
+ __info__.hash = "33f09d7";