@odoo/o-spreadsheet 16.3.30 → 16.3.31

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.
@@ -1017,7 +1017,7 @@
1017
1017
  }
1018
1018
  // Generate new Id if the item didn't exist in the dictionary
1019
1019
  const ids = Object.keys(itemsDic);
1020
- const maxId = ids.length === 0 ? 0 : Math.max(...ids.map((id) => parseInt(id, 10)));
1020
+ const maxId = ids.length === 0 ? 0 : largeMax(ids.map((id) => parseInt(id, 10)));
1021
1021
  itemsDic[maxId + 1] = item;
1022
1022
  return maxId + 1;
1023
1023
  }
@@ -1209,6 +1209,34 @@
1209
1209
  }
1210
1210
  }
1211
1211
  return true;
1212
+ }
1213
+ /**
1214
+ * Alternative to Math.max that works with large arrays.
1215
+ * Typically useful for arrays bigger than 100k elements.
1216
+ */
1217
+ function largeMax(array) {
1218
+ let len = array.length;
1219
+ if (len < 100000)
1220
+ return Math.max(...array);
1221
+ let max = -Infinity;
1222
+ while (len--) {
1223
+ max = array[len] > max ? array[len] : max;
1224
+ }
1225
+ return max;
1226
+ }
1227
+ /**
1228
+ * Alternative to Math.min that works with large arrays.
1229
+ * Typically useful for arrays bigger than 100k elements.
1230
+ */
1231
+ function largeMin(array) {
1232
+ let len = array.length;
1233
+ if (len < 100000)
1234
+ return Math.min(...array);
1235
+ let min = +Infinity;
1236
+ while (len--) {
1237
+ min = array[len] < min ? array[len] : min;
1238
+ }
1239
+ return min;
1212
1240
  }
1213
1241
 
1214
1242
  const RBA_REGEX = /rgba?\(|\s+|\)/gi;
@@ -6820,10 +6848,10 @@
6820
6848
  }
6821
6849
  }
6822
6850
  return {
6823
- labels: Object.keys(labelMap),
6851
+ labels: Array.from(labelSet),
6824
6852
  dataSetsValues: datasets.map((dataset, indexOfDataset) => ({
6825
6853
  ...dataset,
6826
- data: Object.values(labelMap).map((dataOfLabel) => dataOfLabel[indexOfDataset]),
6854
+ data: Array.from(labelSet).map((label) => labelMap[label][indexOfDataset]),
6827
6855
  })),
6828
6856
  };
6829
6857
  }
@@ -7540,7 +7568,7 @@
7540
7568
  return undefined;
7541
7569
  }
7542
7570
  const labelsTimestamps = labelDates.map((date) => date.getTime());
7543
- const period = Math.max(...labelsTimestamps) - Math.min(...labelsTimestamps);
7571
+ const period = largeMax(labelsTimestamps) - largeMin(labelsTimestamps);
7544
7572
  const minUnit = getFormatMinDisplayUnit(format);
7545
7573
  if (UNIT_LENGTH.second >= UNIT_LENGTH[minUnit] && Milliseconds.inSeconds(period) < 180) {
7546
7574
  return "second";
@@ -7980,7 +8008,7 @@
7980
8008
  }
7981
8009
  function getPieColors(colors, dataSetsValues) {
7982
8010
  const pieColors = [];
7983
- const maxLength = Math.max(...dataSetsValues.map((ds) => ds.data.length));
8011
+ const maxLength = largeMax(dataSetsValues.map((ds) => ds.data.length));
7984
8012
  for (let i = 0; i <= maxLength; i++) {
7985
8013
  pieColors.push(colors.next());
7986
8014
  }
@@ -8943,8 +8971,8 @@
8943
8971
  let last;
8944
8972
  const activesRows = env.model.getters.getActiveRows();
8945
8973
  if (activesRows.size !== 0) {
8946
- first = Math.min(...activesRows);
8947
- last = Math.max(...activesRows);
8974
+ first = largeMin([...activesRows]);
8975
+ last = largeMax([...activesRows]);
8948
8976
  }
8949
8977
  else {
8950
8978
  const zone = env.model.getters.getSelectedZones()[0];
@@ -8972,8 +9000,8 @@
8972
9000
  let last;
8973
9001
  const activeCols = env.model.getters.getActiveCols();
8974
9002
  if (activeCols.size !== 0) {
8975
- first = Math.min(...activeCols);
8976
- last = Math.max(...activeCols);
9003
+ first = largeMin([...activeCols]);
9004
+ last = largeMax([...activeCols]);
8977
9005
  }
8978
9006
  else {
8979
9007
  const zone = env.model.getters.getSelectedZones()[0];
@@ -9001,8 +9029,8 @@
9001
9029
  let last;
9002
9030
  const activesRows = env.model.getters.getActiveRows();
9003
9031
  if (activesRows.size !== 0) {
9004
- first = Math.min(...activesRows);
9005
- last = Math.max(...activesRows);
9032
+ first = largeMin([...activesRows]);
9033
+ last = largeMax([...activesRows]);
9006
9034
  }
9007
9035
  else {
9008
9036
  const zone = env.model.getters.getSelectedZones()[0];
@@ -9043,8 +9071,8 @@
9043
9071
  let last;
9044
9072
  const activeCols = env.model.getters.getActiveCols();
9045
9073
  if (activeCols.size !== 0) {
9046
- first = Math.min(...activeCols);
9047
- last = Math.max(...activeCols);
9074
+ first = largeMin([...activeCols]);
9075
+ last = largeMax([...activeCols]);
9048
9076
  }
9049
9077
  else {
9050
9078
  const zone = env.model.getters.getSelectedZones()[0];
@@ -9127,7 +9155,7 @@
9127
9155
  let row;
9128
9156
  let quantity;
9129
9157
  if (activeRows.size) {
9130
- row = Math.min(...activeRows);
9158
+ row = largeMin([...activeRows]);
9131
9159
  quantity = activeRows.size;
9132
9160
  }
9133
9161
  else {
@@ -9159,7 +9187,7 @@
9159
9187
  let row;
9160
9188
  let quantity;
9161
9189
  if (activeRows.size) {
9162
- row = Math.max(...activeRows);
9190
+ row = largeMax([...activeRows]);
9163
9191
  quantity = activeRows.size;
9164
9192
  }
9165
9193
  else {
@@ -9204,7 +9232,7 @@
9204
9232
  let column;
9205
9233
  let quantity;
9206
9234
  if (activeCols.size) {
9207
- column = Math.min(...activeCols);
9235
+ column = largeMin([...activeCols]);
9208
9236
  quantity = activeCols.size;
9209
9237
  }
9210
9238
  else {
@@ -9238,7 +9266,7 @@
9238
9266
  let column;
9239
9267
  let quantity;
9240
9268
  if (activeCols.size) {
9241
- column = Math.max(...activeCols);
9269
+ column = largeMax([...activeCols]);
9242
9270
  quantity = activeCols.size;
9243
9271
  }
9244
9272
  else {
@@ -26926,7 +26954,7 @@
26926
26954
  function getSheetDims(sheet) {
26927
26955
  const dims = [0, 0];
26928
26956
  for (let row of sheet.rows) {
26929
- dims[0] = Math.max(dims[0], ...row.cells.map((cell) => toCartesian(cell.xc).col));
26957
+ dims[0] = Math.max(dims[0], largeMax(row.cells.map((cell) => toCartesian(cell.xc).col)));
26930
26958
  dims[1] = Math.max(dims[1], row.index);
26931
26959
  }
26932
26960
  dims[0] = Math.max(dims[0], EXCEL_IMPORT_DEFAULT_NUMBER_OF_COLS);
@@ -31213,7 +31241,7 @@
31213
31241
  for (let headerIndex of [...cmd.elements].sort((a, b) => b - a)) {
31214
31242
  sizes.splice(headerIndex, 1);
31215
31243
  }
31216
- const min = Math.min(...cmd.elements);
31244
+ const min = largeMin(cmd.elements);
31217
31245
  sizes = sizes.map((size, row) => {
31218
31246
  if (cmd.dimension === "ROW" && row >= min) {
31219
31247
  // invalidate sizes
@@ -31440,7 +31468,7 @@
31440
31468
  if (hiddenElements.size >= elements) {
31441
31469
  return 67 /* CommandResult.TooManyHiddenElements */;
31442
31470
  }
31443
- else if (Math.min(...cmd.elements) < 0 || Math.max(...cmd.elements) > elements) {
31471
+ else if (largeMin(cmd.elements) < 0 || largeMax(cmd.elements) > elements) {
31444
31472
  return 87 /* CommandResult.InvalidHeaderIndex */;
31445
31473
  }
31446
31474
  else {
@@ -32213,8 +32241,8 @@
32213
32241
  let newRange = range;
32214
32242
  let changeType = "NONE";
32215
32243
  for (let group of groups) {
32216
- const min = Math.min(...group);
32217
- const max = Math.max(...group);
32244
+ const min = largeMin(group);
32245
+ const max = largeMax(group);
32218
32246
  if (range.zone[start] <= min && min <= range.zone[end]) {
32219
32247
  const toRemove = Math.min(range.zone[end], max) - min + 1;
32220
32248
  changeType = "RESIZE";
@@ -32645,7 +32673,7 @@
32645
32673
  const elements = cmd.dimension === "COL"
32646
32674
  ? this.getNumberCols(cmd.sheetId)
32647
32675
  : this.getNumberRows(cmd.sheetId);
32648
- if (Math.min(...cmd.elements) < 0 || Math.max(...cmd.elements) > elements) {
32676
+ if (largeMin(cmd.elements) < 0 || largeMax(cmd.elements) > elements) {
32649
32677
  return 87 /* CommandResult.InvalidHeaderIndex */;
32650
32678
  }
32651
32679
  else if (this.checkElementsIncludeAllNonFrozenHeaders(cmd.sheetId, cmd.dimension, cmd.elements)) {
@@ -34147,13 +34175,13 @@
34147
34175
  .map((cell) => cell.value);
34148
34176
  switch (threshold.type) {
34149
34177
  case "value":
34150
- const result = functionName === "max" ? Math.max(...rangeValues) : Math.min(...rangeValues);
34178
+ const result = functionName === "max" ? largeMax(rangeValues) : largeMin(rangeValues);
34151
34179
  return result;
34152
34180
  case "number":
34153
34181
  return Number(threshold.value);
34154
34182
  case "percentage":
34155
- const min = Math.min(...rangeValues);
34156
- const max = Math.max(...rangeValues);
34183
+ const min = largeMin(rangeValues);
34184
+ const max = largeMax(rangeValues);
34157
34185
  const delta = max - min;
34158
34186
  return min + (delta * Number(threshold.value)) / 100;
34159
34187
  case "percentile":
@@ -36103,13 +36131,13 @@
36103
36131
  const cells = this.getters.getEvaluatedCellsInZone(sheet.id, zone);
36104
36132
  const cellPositions = range(end, -1, -1);
36105
36133
  const invalidCells = cellPositions.filter((position) => cells[position] && !cells[position].isAutoSummable);
36106
- const maxValidPosition = Math.max(...invalidCells);
36134
+ const maxValidPosition = largeMax(invalidCells);
36107
36135
  const numberSequences = groupConsecutive(cellPositions.filter((position) => this.isNumber(cells[position])));
36108
36136
  const firstSequence = numberSequences[0] || [];
36109
- if (Math.max(...firstSequence) < maxValidPosition) {
36137
+ if (largeMax(firstSequence) < maxValidPosition) {
36110
36138
  return Infinity;
36111
36139
  }
36112
- return Math.min(...firstSequence);
36140
+ return largeMin(firstSequence);
36113
36141
  }
36114
36142
  shouldFindData(sheetId, zone) {
36115
36143
  return this.getters.isEmpty(sheetId, zone) || this.getters.isSingleCellOrMerge(sheetId, zone);
@@ -37694,7 +37722,7 @@
37694
37722
  * column of the current viewport
37695
37723
  */
37696
37724
  getColDimensionsInViewport(sheetId, col) {
37697
- const left = Math.min(...this.getters.getSheetViewVisibleCols());
37725
+ const left = largeMin(this.getters.getSheetViewVisibleCols());
37698
37726
  const start = this.getters.getColRowOffsetInViewport("COL", left, col);
37699
37727
  const size = this.getters.getColSize(sheetId, col);
37700
37728
  const isColHidden = this.getters.isColHidden(sheetId, col);
@@ -37709,7 +37737,7 @@
37709
37737
  * of the current viewport
37710
37738
  */
37711
37739
  getRowDimensionsInViewport(sheetId, row) {
37712
- const top = Math.min(...this.getters.getSheetViewVisibleRows());
37740
+ const top = largeMin(this.getters.getSheetViewVisibleRows());
37713
37741
  const start = this.getters.getColRowOffsetInViewport("ROW", top, row);
37714
37742
  const size = this.getters.getRowSize(sheetId, row);
37715
37743
  const isRowHidden = this.getters.isRowHidden(sheetId, row);
@@ -39237,7 +39265,7 @@
39237
39265
  getColMaxWidth(sheetId, index) {
39238
39266
  const cellsPositions = positions(this.getters.getColsZone(sheetId, index, index));
39239
39267
  const sizes = cellsPositions.map((position) => this.getCellWidth({ sheetId, ...position }));
39240
- return Math.max(0, ...sizes);
39268
+ return Math.max(0, largeMax(sizes));
39241
39269
  }
39242
39270
  splitWordToSpecificWidth(ctx, word, width, style) {
39243
39271
  const wordWidth = computeTextWidth(ctx, word, style);
@@ -42500,12 +42528,14 @@
42500
42528
  this.editionState = "initializing";
42501
42529
  }
42502
42530
  stopEdition() {
42503
- if (!this.state.isEditing)
42531
+ const input = this.sheetNameRef.el;
42532
+ if (!this.state.isEditing || !input)
42504
42533
  return;
42505
42534
  this.state.isEditing = false;
42506
42535
  this.editionState = "initializing";
42507
- this.sheetNameRef.el?.blur();
42536
+ input.blur();
42508
42537
  const inputValue = this.getInputContent() || "";
42538
+ input.innerText = inputValue;
42509
42539
  interactiveRenameSheet(this.env, this.props.sheetId, inputValue, () => this.startEdition());
42510
42540
  }
42511
42541
  cancelEdition() {
@@ -42966,7 +42996,7 @@
42966
42996
  this.sheetListRef.el.scrollTo({ top: 0, left: scroll, behavior: "smooth" });
42967
42997
  }
42968
42998
  onSheetMouseDown(sheetId, event) {
42969
- if (event.button !== 0)
42999
+ if (event.button !== 0 || this.env.model.getters.isReadonly())
42970
43000
  return;
42971
43001
  this.closeMenu();
42972
43002
  const mouseX = event.clientX;
@@ -46140,7 +46170,7 @@
46140
46170
  }
46141
46171
  function addDoughnutChart(chart, chartSheetIndex, data, { holeSize } = { holeSize: 50 }) {
46142
46172
  const colors = new ChartColors();
46143
- const maxLength = Math.max(...chart.dataSets.map((ds) => getRangeSize(ds.range, chartSheetIndex, data)));
46173
+ const maxLength = largeMax(chart.dataSets.map((ds) => getRangeSize(ds.range, chartSheetIndex, data)));
46144
46174
  const doughnutColors = range(0, maxLength).map(() => toXlsxHexColor(colors.next()));
46145
46175
  const dataSetsNodes = [];
46146
46176
  for (const [dsIndex, dataset] of Object.entries(chart.dataSets).reverse()) {
@@ -48063,9 +48093,9 @@
48063
48093
  Object.defineProperty(exports, '__esModule', { value: true });
48064
48094
 
48065
48095
 
48066
- __info__.version = '16.3.30';
48067
- __info__.date = '2024-03-25T09:36:48.685Z';
48068
- __info__.hash = '0d2ee33';
48096
+ __info__.version = '16.3.31';
48097
+ __info__.date = '2024-04-05T13:57:05.657Z';
48098
+ __info__.hash = '052efd4';
48069
48099
 
48070
48100
 
48071
48101
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);