@odoo/o-spreadsheet 16.3.29 → 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.
@@ -1016,7 +1016,7 @@ function getItemId(item, itemsDic) {
1016
1016
  }
1017
1017
  // Generate new Id if the item didn't exist in the dictionary
1018
1018
  const ids = Object.keys(itemsDic);
1019
- const maxId = ids.length === 0 ? 0 : Math.max(...ids.map((id) => parseInt(id, 10)));
1019
+ const maxId = ids.length === 0 ? 0 : largeMax(ids.map((id) => parseInt(id, 10)));
1020
1020
  itemsDic[maxId + 1] = item;
1021
1021
  return maxId + 1;
1022
1022
  }
@@ -1208,6 +1208,34 @@ function isConsecutive(iterable) {
1208
1208
  }
1209
1209
  }
1210
1210
  return true;
1211
+ }
1212
+ /**
1213
+ * Alternative to Math.max that works with large arrays.
1214
+ * Typically useful for arrays bigger than 100k elements.
1215
+ */
1216
+ function largeMax(array) {
1217
+ let len = array.length;
1218
+ if (len < 100000)
1219
+ return Math.max(...array);
1220
+ let max = -Infinity;
1221
+ while (len--) {
1222
+ max = array[len] > max ? array[len] : max;
1223
+ }
1224
+ return max;
1225
+ }
1226
+ /**
1227
+ * Alternative to Math.min that works with large arrays.
1228
+ * Typically useful for arrays bigger than 100k elements.
1229
+ */
1230
+ function largeMin(array) {
1231
+ let len = array.length;
1232
+ if (len < 100000)
1233
+ return Math.min(...array);
1234
+ let min = +Infinity;
1235
+ while (len--) {
1236
+ min = array[len] < min ? array[len] : min;
1237
+ }
1238
+ return min;
1211
1239
  }
1212
1240
 
1213
1241
  const RBA_REGEX = /rgba?\(|\s+|\)/gi;
@@ -6819,10 +6847,10 @@ function aggregateDataForLabels(labels, datasets) {
6819
6847
  }
6820
6848
  }
6821
6849
  return {
6822
- labels: Object.keys(labelMap),
6850
+ labels: Array.from(labelSet),
6823
6851
  dataSetsValues: datasets.map((dataset, indexOfDataset) => ({
6824
6852
  ...dataset,
6825
- data: Object.values(labelMap).map((dataOfLabel) => dataOfLabel[indexOfDataset]),
6853
+ data: Array.from(labelSet).map((label) => labelMap[label][indexOfDataset]),
6826
6854
  })),
6827
6855
  };
6828
6856
  }
@@ -7539,7 +7567,7 @@ function getBestTimeUnitForScale(labels, format) {
7539
7567
  return undefined;
7540
7568
  }
7541
7569
  const labelsTimestamps = labelDates.map((date) => date.getTime());
7542
- const period = Math.max(...labelsTimestamps) - Math.min(...labelsTimestamps);
7570
+ const period = largeMax(labelsTimestamps) - largeMin(labelsTimestamps);
7543
7571
  const minUnit = getFormatMinDisplayUnit(format);
7544
7572
  if (UNIT_LENGTH.second >= UNIT_LENGTH[minUnit] && Milliseconds.inSeconds(period) < 180) {
7545
7573
  return "second";
@@ -7979,7 +8007,7 @@ function getPieConfiguration(chart, labels, dataSetFormat) {
7979
8007
  }
7980
8008
  function getPieColors(colors, dataSetsValues) {
7981
8009
  const pieColors = [];
7982
- const maxLength = Math.max(...dataSetsValues.map((ds) => ds.data.length));
8010
+ const maxLength = largeMax(dataSetsValues.map((ds) => ds.data.length));
7983
8011
  for (let i = 0; i <= maxLength; i++) {
7984
8012
  pieColors.push(colors.next());
7985
8013
  }
@@ -8942,8 +8970,8 @@ const DELETE_CONTENT_ROWS_NAME = (env) => {
8942
8970
  let last;
8943
8971
  const activesRows = env.model.getters.getActiveRows();
8944
8972
  if (activesRows.size !== 0) {
8945
- first = Math.min(...activesRows);
8946
- last = Math.max(...activesRows);
8973
+ first = largeMin([...activesRows]);
8974
+ last = largeMax([...activesRows]);
8947
8975
  }
8948
8976
  else {
8949
8977
  const zone = env.model.getters.getSelectedZones()[0];
@@ -8971,8 +8999,8 @@ const DELETE_CONTENT_COLUMNS_NAME = (env) => {
8971
8999
  let last;
8972
9000
  const activeCols = env.model.getters.getActiveCols();
8973
9001
  if (activeCols.size !== 0) {
8974
- first = Math.min(...activeCols);
8975
- last = Math.max(...activeCols);
9002
+ first = largeMin([...activeCols]);
9003
+ last = largeMax([...activeCols]);
8976
9004
  }
8977
9005
  else {
8978
9006
  const zone = env.model.getters.getSelectedZones()[0];
@@ -9000,8 +9028,8 @@ const REMOVE_ROWS_NAME = (env) => {
9000
9028
  let last;
9001
9029
  const activesRows = env.model.getters.getActiveRows();
9002
9030
  if (activesRows.size !== 0) {
9003
- first = Math.min(...activesRows);
9004
- last = Math.max(...activesRows);
9031
+ first = largeMin([...activesRows]);
9032
+ last = largeMax([...activesRows]);
9005
9033
  }
9006
9034
  else {
9007
9035
  const zone = env.model.getters.getSelectedZones()[0];
@@ -9042,8 +9070,8 @@ const REMOVE_COLUMNS_NAME = (env) => {
9042
9070
  let last;
9043
9071
  const activeCols = env.model.getters.getActiveCols();
9044
9072
  if (activeCols.size !== 0) {
9045
- first = Math.min(...activeCols);
9046
- last = Math.max(...activeCols);
9073
+ first = largeMin([...activeCols]);
9074
+ last = largeMax([...activeCols]);
9047
9075
  }
9048
9076
  else {
9049
9077
  const zone = env.model.getters.getSelectedZones()[0];
@@ -9126,7 +9154,7 @@ const INSERT_ROWS_BEFORE_ACTION = (env) => {
9126
9154
  let row;
9127
9155
  let quantity;
9128
9156
  if (activeRows.size) {
9129
- row = Math.min(...activeRows);
9157
+ row = largeMin([...activeRows]);
9130
9158
  quantity = activeRows.size;
9131
9159
  }
9132
9160
  else {
@@ -9158,7 +9186,7 @@ const INSERT_ROWS_AFTER_ACTION = (env) => {
9158
9186
  let row;
9159
9187
  let quantity;
9160
9188
  if (activeRows.size) {
9161
- row = Math.max(...activeRows);
9189
+ row = largeMax([...activeRows]);
9162
9190
  quantity = activeRows.size;
9163
9191
  }
9164
9192
  else {
@@ -9203,7 +9231,7 @@ const INSERT_COLUMNS_BEFORE_ACTION = (env) => {
9203
9231
  let column;
9204
9232
  let quantity;
9205
9233
  if (activeCols.size) {
9206
- column = Math.min(...activeCols);
9234
+ column = largeMin([...activeCols]);
9207
9235
  quantity = activeCols.size;
9208
9236
  }
9209
9237
  else {
@@ -9237,7 +9265,7 @@ const INSERT_COLUMNS_AFTER_ACTION = (env) => {
9237
9265
  let column;
9238
9266
  let quantity;
9239
9267
  if (activeCols.size) {
9240
- column = Math.max(...activeCols);
9268
+ column = largeMax([...activeCols]);
9241
9269
  quantity = activeCols.size;
9242
9270
  }
9243
9271
  else {
@@ -16545,14 +16573,19 @@ const categorieFunctionAll = {
16545
16573
  children: [allFunctionListMenuBuilder],
16546
16574
  };
16547
16575
  function allFunctionListMenuBuilder() {
16548
- const fnNames = functionRegistry.getKeys();
16576
+ const fnNames = functionRegistry.getKeys().filter((key) => !functionRegistry.get(key).hidden);
16549
16577
  return createFormulaFunctions(fnNames);
16550
16578
  }
16551
16579
  const categoriesFunctionListMenuBuilder = () => {
16552
16580
  const functions = functionRegistry.content;
16553
- const categories = [...new Set(functionRegistry.getAll().map((fn) => fn.category))].filter(isDefined$1);
16581
+ const categories = [
16582
+ ...new Set(functionRegistry
16583
+ .getAll()
16584
+ .filter((fn) => !fn.hidden)
16585
+ .map((fn) => fn.category)),
16586
+ ].filter(isDefined$1);
16554
16587
  return categories.sort().map((category, i) => {
16555
- const functionsInCategory = Object.keys(functions).filter((key) => functions[key].category === category);
16588
+ const functionsInCategory = Object.keys(functions).filter((key) => functions[key].category === category && !functions[key].hidden);
16556
16589
  return {
16557
16590
  name: category,
16558
16591
  children: createFormulaFunctions(functionsInCategory),
@@ -20212,6 +20245,9 @@ class FigureComponent extends Component {
20212
20245
  el?.focus({ preventScroll: true });
20213
20246
  }
20214
20247
  }, () => [this.env.model.getters.getSelectedFigureId(), this.props.figure.id, this.figureRef.el]);
20248
+ onWillUnmount(() => {
20249
+ this.props.onFigureDeleted();
20250
+ });
20215
20251
  }
20216
20252
  clickAnchor(dirX, dirY, ev) {
20217
20253
  this.props.onClickAnchor(dirX, dirY, ev);
@@ -20230,6 +20266,7 @@ class FigureComponent extends Component {
20230
20266
  this.props.onFigureDeleted();
20231
20267
  ev.stopPropagation();
20232
20268
  ev.preventDefault();
20269
+ ev.stopPropagation();
20233
20270
  break;
20234
20271
  case "ArrowDown":
20235
20272
  case "ArrowLeft":
@@ -20250,6 +20287,7 @@ class FigureComponent extends Component {
20250
20287
  });
20251
20288
  ev.stopPropagation();
20252
20289
  ev.preventDefault();
20290
+ ev.stopPropagation();
20253
20291
  break;
20254
20292
  }
20255
20293
  }
@@ -21058,6 +21096,10 @@ class Composer extends Component {
21058
21096
  if (!this.isKeyStillDown) {
21059
21097
  this.processContent();
21060
21098
  }
21099
+ // Required because typing '=SUM' and double-clicking another cell leaves ShowProvider and ShowDescription true
21100
+ if (this.env.model.getters.getEditionMode() === "inactive") {
21101
+ this.processTokenAtCursor();
21102
+ }
21061
21103
  });
21062
21104
  }
21063
21105
  // ---------------------------------------------------------------------------
@@ -26911,7 +26953,7 @@ function convertHyperlink(link, cellValue, warningManager) {
26911
26953
  function getSheetDims(sheet) {
26912
26954
  const dims = [0, 0];
26913
26955
  for (let row of sheet.rows) {
26914
- dims[0] = Math.max(dims[0], ...row.cells.map((cell) => toCartesian(cell.xc).col));
26956
+ dims[0] = Math.max(dims[0], largeMax(row.cells.map((cell) => toCartesian(cell.xc).col)));
26915
26957
  dims[1] = Math.max(dims[1], row.index);
26916
26958
  }
26917
26959
  dims[0] = Math.max(dims[0], EXCEL_IMPORT_DEFAULT_NUMBER_OF_COLS);
@@ -31198,7 +31240,7 @@ class HeaderSizePlugin extends CorePlugin {
31198
31240
  for (let headerIndex of [...cmd.elements].sort((a, b) => b - a)) {
31199
31241
  sizes.splice(headerIndex, 1);
31200
31242
  }
31201
- const min = Math.min(...cmd.elements);
31243
+ const min = largeMin(cmd.elements);
31202
31244
  sizes = sizes.map((size, row) => {
31203
31245
  if (cmd.dimension === "ROW" && row >= min) {
31204
31246
  // invalidate sizes
@@ -31425,7 +31467,7 @@ class HeaderVisibilityPlugin extends CorePlugin {
31425
31467
  if (hiddenElements.size >= elements) {
31426
31468
  return 67 /* CommandResult.TooManyHiddenElements */;
31427
31469
  }
31428
- else if (Math.min(...cmd.elements) < 0 || Math.max(...cmd.elements) > elements) {
31470
+ else if (largeMin(cmd.elements) < 0 || largeMax(cmd.elements) > elements) {
31429
31471
  return 87 /* CommandResult.InvalidHeaderIndex */;
31430
31472
  }
31431
31473
  else {
@@ -32198,8 +32240,8 @@ class RangeAdapter {
32198
32240
  let newRange = range;
32199
32241
  let changeType = "NONE";
32200
32242
  for (let group of groups) {
32201
- const min = Math.min(...group);
32202
- const max = Math.max(...group);
32243
+ const min = largeMin(group);
32244
+ const max = largeMax(group);
32203
32245
  if (range.zone[start] <= min && min <= range.zone[end]) {
32204
32246
  const toRemove = Math.min(range.zone[end], max) - min + 1;
32205
32247
  changeType = "RESIZE";
@@ -32630,7 +32672,7 @@ class SheetPlugin extends CorePlugin {
32630
32672
  const elements = cmd.dimension === "COL"
32631
32673
  ? this.getNumberCols(cmd.sheetId)
32632
32674
  : this.getNumberRows(cmd.sheetId);
32633
- if (Math.min(...cmd.elements) < 0 || Math.max(...cmd.elements) > elements) {
32675
+ if (largeMin(cmd.elements) < 0 || largeMax(cmd.elements) > elements) {
32634
32676
  return 87 /* CommandResult.InvalidHeaderIndex */;
32635
32677
  }
32636
32678
  else if (this.checkElementsIncludeAllNonFrozenHeaders(cmd.sheetId, cmd.dimension, cmd.elements)) {
@@ -34132,13 +34174,13 @@ class EvaluationConditionalFormatPlugin extends UIPlugin {
34132
34174
  .map((cell) => cell.value);
34133
34175
  switch (threshold.type) {
34134
34176
  case "value":
34135
- const result = functionName === "max" ? Math.max(...rangeValues) : Math.min(...rangeValues);
34177
+ const result = functionName === "max" ? largeMax(rangeValues) : largeMin(rangeValues);
34136
34178
  return result;
34137
34179
  case "number":
34138
34180
  return Number(threshold.value);
34139
34181
  case "percentage":
34140
- const min = Math.min(...rangeValues);
34141
- const max = Math.max(...rangeValues);
34182
+ const min = largeMin(rangeValues);
34183
+ const max = largeMax(rangeValues);
34142
34184
  const delta = max - min;
34143
34185
  return min + (delta * Number(threshold.value)) / 100;
34144
34186
  case "percentile":
@@ -36088,13 +36130,13 @@ class AutomaticSumPlugin extends UIPlugin {
36088
36130
  const cells = this.getters.getEvaluatedCellsInZone(sheet.id, zone);
36089
36131
  const cellPositions = range(end, -1, -1);
36090
36132
  const invalidCells = cellPositions.filter((position) => cells[position] && !cells[position].isAutoSummable);
36091
- const maxValidPosition = Math.max(...invalidCells);
36133
+ const maxValidPosition = largeMax(invalidCells);
36092
36134
  const numberSequences = groupConsecutive(cellPositions.filter((position) => this.isNumber(cells[position])));
36093
36135
  const firstSequence = numberSequences[0] || [];
36094
- if (Math.max(...firstSequence) < maxValidPosition) {
36136
+ if (largeMax(firstSequence) < maxValidPosition) {
36095
36137
  return Infinity;
36096
36138
  }
36097
- return Math.min(...firstSequence);
36139
+ return largeMin(firstSequence);
36098
36140
  }
36099
36141
  shouldFindData(sheetId, zone) {
36100
36142
  return this.getters.isEmpty(sheetId, zone) || this.getters.isSingleCellOrMerge(sheetId, zone);
@@ -37679,7 +37721,7 @@ class RendererPlugin extends UIPlugin {
37679
37721
  * column of the current viewport
37680
37722
  */
37681
37723
  getColDimensionsInViewport(sheetId, col) {
37682
- const left = Math.min(...this.getters.getSheetViewVisibleCols());
37724
+ const left = largeMin(this.getters.getSheetViewVisibleCols());
37683
37725
  const start = this.getters.getColRowOffsetInViewport("COL", left, col);
37684
37726
  const size = this.getters.getColSize(sheetId, col);
37685
37727
  const isColHidden = this.getters.isColHidden(sheetId, col);
@@ -37694,7 +37736,7 @@ class RendererPlugin extends UIPlugin {
37694
37736
  * of the current viewport
37695
37737
  */
37696
37738
  getRowDimensionsInViewport(sheetId, row) {
37697
- const top = Math.min(...this.getters.getSheetViewVisibleRows());
37739
+ const top = largeMin(this.getters.getSheetViewVisibleRows());
37698
37740
  const start = this.getters.getColRowOffsetInViewport("ROW", top, row);
37699
37741
  const size = this.getters.getRowSize(sheetId, row);
37700
37742
  const isRowHidden = this.getters.isRowHidden(sheetId, row);
@@ -39222,7 +39264,7 @@ class SheetUIPlugin extends UIPlugin {
39222
39264
  getColMaxWidth(sheetId, index) {
39223
39265
  const cellsPositions = positions(this.getters.getColsZone(sheetId, index, index));
39224
39266
  const sizes = cellsPositions.map((position) => this.getCellWidth({ sheetId, ...position }));
39225
- return Math.max(0, ...sizes);
39267
+ return Math.max(0, largeMax(sizes));
39226
39268
  }
39227
39269
  splitWordToSpecificWidth(ctx, word, width, style) {
39228
39270
  const wordWidth = computeTextWidth(ctx, word, style);
@@ -41679,6 +41721,7 @@ class GridSelectionPlugin extends UIPlugin {
41679
41721
  this.gridSelection.zones = this.gridSelection.zones.map((z) => this.getters.expandZone(sheetId, z));
41680
41722
  this.gridSelection.anchor.zone = this.getters.expandZone(sheetId, this.gridSelection.anchor.zone);
41681
41723
  this.setSelectionMixin(this.gridSelection.anchor, this.gridSelection.zones);
41724
+ this.selectedFigureId = null;
41682
41725
  break;
41683
41726
  }
41684
41727
  /** Any change to the selection has to be reflected in the selection processor. */
@@ -42484,12 +42527,14 @@ class BottomBarSheet extends Component {
42484
42527
  this.editionState = "initializing";
42485
42528
  }
42486
42529
  stopEdition() {
42487
- if (!this.state.isEditing)
42530
+ const input = this.sheetNameRef.el;
42531
+ if (!this.state.isEditing || !input)
42488
42532
  return;
42489
42533
  this.state.isEditing = false;
42490
42534
  this.editionState = "initializing";
42491
- this.sheetNameRef.el?.blur();
42535
+ input.blur();
42492
42536
  const inputValue = this.getInputContent() || "";
42537
+ input.innerText = inputValue;
42493
42538
  interactiveRenameSheet(this.env, this.props.sheetId, inputValue, () => this.startEdition());
42494
42539
  }
42495
42540
  cancelEdition() {
@@ -42950,7 +42995,7 @@ class BottomBar extends Component {
42950
42995
  this.sheetListRef.el.scrollTo({ top: 0, left: scroll, behavior: "smooth" });
42951
42996
  }
42952
42997
  onSheetMouseDown(sheetId, event) {
42953
- if (event.button !== 0)
42998
+ if (event.button !== 0 || this.env.model.getters.isReadonly())
42954
42999
  return;
42955
43000
  this.closeMenu();
42956
43001
  const mouseX = event.clientX;
@@ -46124,7 +46169,7 @@ function addLineChart(chart) {
46124
46169
  }
46125
46170
  function addDoughnutChart(chart, chartSheetIndex, data, { holeSize } = { holeSize: 50 }) {
46126
46171
  const colors = new ChartColors();
46127
- const maxLength = Math.max(...chart.dataSets.map((ds) => getRangeSize(ds.range, chartSheetIndex, data)));
46172
+ const maxLength = largeMax(chart.dataSets.map((ds) => getRangeSize(ds.range, chartSheetIndex, data)));
46128
46173
  const doughnutColors = range(0, maxLength).map(() => toXlsxHexColor(colors.next()));
46129
46174
  const dataSetsNodes = [];
46130
46175
  for (const [dsIndex, dataset] of Object.entries(chart.dataSets).reverse()) {
@@ -48017,6 +48062,6 @@ function addFunction(functionName, functionDescription) {
48017
48062
  export { AbstractChart, CommandResult, CorePlugin, DispatchResult, EvaluationError, Model, Registry, Revision, SPREADSHEET_DIMENSIONS, Spreadsheet, UIPlugin, __info__, addFunction, astToFormula, compile, components, convertAstNodes, coreTypes, findCellInNewZone, functionCache, helpers, invalidateEvaluationCommands, links, load, parse, readonlyAllowedCommands, registries, setDefaultSheetViewSize, setTranslationMethod, tokenize };
48018
48063
 
48019
48064
 
48020
- __info__.version = '16.3.29';
48021
- __info__.date = '2024-03-15T10:57:27.142Z';
48022
- __info__.hash = 'd86234a';
48065
+ __info__.version = '16.3.31';
48066
+ __info__.date = '2024-04-05T13:57:05.657Z';
48067
+ __info__.hash = '052efd4';