@odoo/o-spreadsheet 16.1.26 → 16.1.28

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.
@@ -623,13 +623,6 @@
623
623
  }
624
624
 
625
625
  //------------------------------------------------------------------------------
626
- /**
627
- * Stringify an object, like JSON.stringify, except that the first level of keys
628
- * is ordered.
629
- */
630
- function stringify(obj) {
631
- return JSON.stringify(obj, Object.keys(obj).sort());
632
- }
633
626
  /**
634
627
  * Remove quotes from a quoted string
635
628
  * ```js
@@ -925,7 +918,7 @@
925
918
  */
926
919
  function getItemId(item, itemsDic) {
927
920
  for (let [key, value] of Object.entries(itemsDic)) {
928
- if (stringify(value) === stringify(item)) {
921
+ if (deepEquals(value, item)) {
929
922
  return parseInt(key, 10);
930
923
  }
931
924
  }
@@ -1061,6 +1054,22 @@
1061
1054
  if (!matrix.length)
1062
1055
  return matrix;
1063
1056
  return matrix[0].map((_, i) => matrix.map((row) => row[i]));
1057
+ }
1058
+ /**
1059
+ * Creates a version of the function that's memoized on the value of its first
1060
+ * argument, if any.
1061
+ */
1062
+ function memoize(func) {
1063
+ const cache = new Map();
1064
+ const funcName = func.name ? func.name + " (memoized)" : "memoized";
1065
+ return {
1066
+ [funcName](...args) {
1067
+ if (!cache.has(args[0])) {
1068
+ cache.set(args[0], func(...args));
1069
+ }
1070
+ return cache.get(args[0]);
1071
+ },
1072
+ }[funcName];
1064
1073
  }
1065
1074
 
1066
1075
  const RBA_REGEX = /rgba?\(|\s+|\)/gi;
@@ -3657,6 +3666,7 @@
3657
3666
  CommandResult[CommandResult["ChartDoesNotExist"] = 85] = "ChartDoesNotExist";
3658
3667
  CommandResult[CommandResult["InvalidHeaderIndex"] = 86] = "InvalidHeaderIndex";
3659
3668
  CommandResult[CommandResult["InvalidQuantity"] = 87] = "InvalidQuantity";
3669
+ CommandResult[CommandResult["NoChanges"] = 88] = "NoChanges";
3660
3670
  })(exports.CommandResult || (exports.CommandResult = {}));
3661
3671
 
3662
3672
  function isMatrix(x) {
@@ -8020,12 +8030,12 @@
8020
8030
  }
8021
8031
  }
8022
8032
  /** Normalize string by setting it to lowercase and replacing accent letters with plain letters */
8023
- function normalizeString(str) {
8033
+ const normalizeString = memoize(function normalizeString(str) {
8024
8034
  return str
8025
8035
  .toLowerCase()
8026
8036
  .normalize("NFD")
8027
8037
  .replace(/[\u0300-\u036f]/g, "");
8028
- }
8038
+ });
8029
8039
  /**
8030
8040
  * Normalize a value.
8031
8041
  * If the cell value is a string, this will set it to lowercase and replacing accent letters with plain letters
@@ -21758,7 +21768,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
21758
21768
  }
21759
21769
  .o-input-count {
21760
21770
  width: fit-content;
21761
- padding: 4 0 4 4;
21771
+ padding: 4px 0 4px 4px;
21762
21772
  }
21763
21773
  }
21764
21774
  }
@@ -27942,6 +27952,14 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
27942
27952
  // ---------------------------------------------------------------------------
27943
27953
  // Command Handling
27944
27954
  // ---------------------------------------------------------------------------
27955
+ allowDispatch(cmd) {
27956
+ switch (cmd.type) {
27957
+ case "SET_BORDER":
27958
+ return this.checkBordersUnchanged(cmd);
27959
+ default:
27960
+ return 0 /* CommandResult.Success */;
27961
+ }
27962
+ }
27945
27963
  handle(cmd) {
27946
27964
  switch (cmd.type) {
27947
27965
  case "ADD_MERGE":
@@ -28337,6 +28355,15 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
28337
28355
  this.setBorders(sheetId, [{ ...zone, left: right }], "right");
28338
28356
  }
28339
28357
  }
28358
+ checkBordersUnchanged(cmd) {
28359
+ var _a, _b, _c, _d;
28360
+ const currentBorder = this.getCellBorder(cmd);
28361
+ const areAllNewBordersUndefined = !((_a = cmd.border) === null || _a === void 0 ? void 0 : _a.bottom) && !((_b = cmd.border) === null || _b === void 0 ? void 0 : _b.left) && !((_c = cmd.border) === null || _c === void 0 ? void 0 : _c.right) && !((_d = cmd.border) === null || _d === void 0 ? void 0 : _d.top);
28362
+ if ((!currentBorder && areAllNewBordersUndefined) || deepEquals(currentBorder, cmd.border)) {
28363
+ return 88 /* CommandResult.NoChanges */;
28364
+ }
28365
+ return 0 /* CommandResult.Success */;
28366
+ }
28340
28367
  // ---------------------------------------------------------------------------
28341
28368
  // Import/Export
28342
28369
  // ---------------------------------------------------------------------------
@@ -28372,7 +28399,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
28372
28399
  */
28373
28400
  function getBorderId(border) {
28374
28401
  for (let [key, value] of Object.entries(borders)) {
28375
- if (stringify(value) === stringify(border)) {
28402
+ if (deepEquals(value, border)) {
28376
28403
  return parseInt(key, 10);
28377
28404
  }
28378
28405
  }
@@ -28440,8 +28467,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
28440
28467
  allowDispatch(cmd) {
28441
28468
  switch (cmd.type) {
28442
28469
  case "UPDATE_CELL":
28470
+ return this.checkCellOutOfSheet(cmd);
28443
28471
  case "CLEAR_CELL":
28444
- return this.checkCellOutOfSheet(cmd.sheetId, cmd.col, cmd.row);
28472
+ return this.checkValidations(cmd, this.chainValidations(this.checkCellOutOfSheet, this.checkUselessClearCell));
28445
28473
  default:
28446
28474
  return 0 /* CommandResult.Success */;
28447
28475
  }
@@ -28600,14 +28628,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
28600
28628
  */
28601
28629
  getCellById(cellId) {
28602
28630
  // this must be as fast as possible
28603
- for (const sheetId in this.cells) {
28604
- const sheet = this.cells[sheetId];
28605
- const cell = sheet[cellId];
28606
- if (cell) {
28607
- return cell;
28608
- }
28609
- }
28610
- return undefined;
28631
+ const position = this.getters.getCellPosition(cellId);
28632
+ const sheet = this.cells[position.sheetId];
28633
+ return sheet[cellId];
28611
28634
  }
28612
28635
  /*
28613
28636
  * Reconstructs the original formula string based on a normalized form and its dependencies
@@ -28848,13 +28871,23 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
28848
28871
  dependencies: [],
28849
28872
  };
28850
28873
  }
28851
- checkCellOutOfSheet(sheetId, col, row) {
28874
+ checkCellOutOfSheet(cmd) {
28875
+ const { sheetId, col, row } = cmd;
28852
28876
  const sheet = this.getters.tryGetSheet(sheetId);
28853
28877
  if (!sheet)
28854
28878
  return 27 /* CommandResult.InvalidSheetId */;
28855
28879
  const sheetZone = this.getters.getSheetZone(sheetId);
28856
28880
  return isInside(col, row, sheetZone) ? 0 /* CommandResult.Success */ : 18 /* CommandResult.TargetOutOfSheet */;
28857
28881
  }
28882
+ checkUselessClearCell(cmd) {
28883
+ const cell = this.getters.getCell(cmd);
28884
+ if (!cell)
28885
+ return 88 /* CommandResult.NoChanges */;
28886
+ if (!cell.content && !cell.style && !cell.format) {
28887
+ return 88 /* CommandResult.NoChanges */;
28888
+ }
28889
+ return 0 /* CommandResult.Success */;
28890
+ }
28858
28891
  }
28859
28892
  CellPlugin.getters = [
28860
28893
  "zoneToXC",
@@ -29757,6 +29790,13 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
29757
29790
  }
29758
29791
  onDeleteColumnsRows(cmd) {
29759
29792
  for (const table of this.getFilterTables(cmd.sheetId)) {
29793
+ // Remove the filter tables whose data filter headers are in the removed rows.
29794
+ if (cmd.dimension === "ROW" && cmd.elements.includes(table.zone.top)) {
29795
+ const tables = { ...this.tables[cmd.sheetId] };
29796
+ delete tables[table.id];
29797
+ this.history.update("tables", cmd.sheetId, tables);
29798
+ continue;
29799
+ }
29760
29800
  const zone = reduceZoneOnDeletion(table.zone, cmd.dimension === "COL" ? "left" : "top", cmd.elements);
29761
29801
  if (!zone) {
29762
29802
  const tables = { ...this.tables[cmd.sheetId] };
@@ -31908,10 +31948,13 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
31908
31948
  // begin with the end.
31909
31949
  rows.sort((a, b) => b - a);
31910
31950
  for (let group of groupConsecutive(rows)) {
31951
+ // indexes are sorted in the descending order
31952
+ const from = group[group.length - 1];
31953
+ const to = group[0];
31911
31954
  // Move the cells.
31912
- this.moveCellOnRowsDeletion(sheet, group[group.length - 1], group[0]);
31913
- // Effectively delete the element and recompute the left-right/top-bottom.
31914
- group.map((row) => this.updateRowsStructureOnDeletion(row, sheet));
31955
+ this.moveCellOnRowsDeletion(sheet, from, to);
31956
+ // Effectively delete the rows
31957
+ this.updateRowsStructureOnDeletion(sheet, from, to);
31915
31958
  }
31916
31959
  const count = rows.filter((row) => row < sheet.panes.ySplit).length;
31917
31960
  if (count) {
@@ -31933,8 +31976,6 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
31933
31976
  this.addEmptyRows(sheet, quantity);
31934
31977
  // Move the cells.
31935
31978
  this.moveCellsOnAddition(sheet, index, quantity, "rows");
31936
- // Recompute the left-right/top-bottom.
31937
- this.updateRowsStructureOnAddition(sheet, row, quantity);
31938
31979
  if (index < sheet.panes.ySplit) {
31939
31980
  this.setPaneDivisions(sheet.id, sheet.panes.ySplit + quantity, "ROW");
31940
31981
  }
@@ -32035,35 +32076,20 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
32035
32076
  }
32036
32077
  }
32037
32078
  }
32038
- updateRowsStructureOnDeletion(index, sheet) {
32079
+ updateRowsStructureOnDeletion(sheet, deleteFromRow, deleteToRow) {
32039
32080
  const rows = [];
32040
- const cellsQueue = sheet.rows.map((row) => row.cells);
32081
+ const cellsQueue = sheet.rows.map((row) => row.cells).reverse();
32041
32082
  for (let i in sheet.rows) {
32042
- if (Number(i) === index) {
32083
+ const row = Number(i);
32084
+ if (row >= deleteFromRow && row <= deleteToRow) {
32043
32085
  continue;
32044
32086
  }
32045
32087
  rows.push({
32046
- cells: cellsQueue.shift(),
32088
+ cells: cellsQueue.pop(),
32047
32089
  });
32048
32090
  }
32049
32091
  this.history.update("sheets", sheet.id, "rows", rows);
32050
32092
  }
32051
- /**
32052
- * Update the rows of the sheet after an addition:
32053
- * - Rename the rows
32054
- *
32055
- * @param sheet Sheet on which the deletion occurs
32056
- * @param addedRow Index of the added row
32057
- * @param rowsToAdd Number of the rows to add
32058
- */
32059
- updateRowsStructureOnAddition(sheet, addedRow, rowsToAdd) {
32060
- const rows = [];
32061
- const cellsQueue = sheet.rows.map((row) => row.cells);
32062
- sheet.rows.forEach(() => rows.push({
32063
- cells: cellsQueue.shift(),
32064
- }));
32065
- this.history.update("sheets", sheet.id, "rows", rows);
32066
- }
32067
32093
  /**
32068
32094
  * Add empty rows at the end of the rows
32069
32095
  *
@@ -32520,6 +32546,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
32520
32546
  }
32521
32547
  return evaluatedCell;
32522
32548
  };
32549
+ const rangeCache = {};
32523
32550
  /**
32524
32551
  * Return the values of the cell(s) used in reference, but always in the format of a range even
32525
32552
  * if a single cell is referenced. It is a list of col values. This is useful for the formulas that describe parameters as
@@ -32536,21 +32563,26 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
32536
32563
  // Performance issue: Avoid fetching data on positions that are out of the spreadsheet
32537
32564
  // e.g. A1:ZZZ9999 in a sheet with 10 cols and 10 rows should ignore everything past J10 and return a 10x10 array
32538
32565
  const sheetZone = getters.getSheetZone(sheetId);
32539
- const result = [];
32540
32566
  const zone = intersection(range.zone, sheetZone);
32541
32567
  if (!zone) {
32542
- result.push([]);
32543
- return result;
32568
+ return [[]];
32569
+ }
32570
+ const { top, left, bottom, right } = zone;
32571
+ const cacheKey = `${sheetId}-${top}-${left}-${bottom}-${right}`;
32572
+ if (cacheKey in rangeCache) {
32573
+ return rangeCache[cacheKey];
32544
32574
  }
32575
+ const result = new Array(right - left + 1);
32545
32576
  // Performance issue: nested loop is faster than a map here
32546
- for (let col = zone.left; col <= zone.right; col++) {
32547
- const rowValues = [];
32548
- for (let row = zone.top; row <= zone.bottom; row++) {
32577
+ for (let col = left; col <= right; col++) {
32578
+ const rowValues = new Array(bottom - top + 1);
32579
+ for (let row = top; row <= bottom; row++) {
32549
32580
  const cell = evalContext.getters.getCell({ sheetId: range.sheetId, col, row });
32550
- rowValues.push(cell ? getEvaluatedCell(cell) : undefined);
32581
+ rowValues[row - top] = cell ? getEvaluatedCell(cell) : undefined;
32551
32582
  }
32552
- result.push(rowValues);
32583
+ result[col - left] = rowValues;
32553
32584
  }
32585
+ rangeCache[cacheKey] = result;
32554
32586
  return result;
32555
32587
  }
32556
32588
  /**
@@ -33096,6 +33128,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
33096
33128
  case "EVALUATE_CELLS":
33097
33129
  case "ACTIVATE_SHEET":
33098
33130
  case "REMOVE_FILTER_TABLE":
33131
+ case "ADD_COLUMNS_ROWS":
33132
+ case "REMOVE_COLUMNS_ROWS":
33099
33133
  this.isEvaluationDirty = true;
33100
33134
  break;
33101
33135
  case "START":
@@ -41662,9 +41696,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
41662
41696
  * Apply the changes of the given HistoryChange to the state
41663
41697
  */
41664
41698
  function applyChange(change, target) {
41665
- let val = change.root;
41666
- let key = change.path[change.path.length - 1];
41667
- for (let pathIndex = 0; pathIndex < change.path.slice(0, -1).length; pathIndex++) {
41699
+ let val = change.path[0];
41700
+ const key = change.path[change.path.length - 1];
41701
+ for (let pathIndex = 1; pathIndex < change.path.slice(0, -1).length; pathIndex++) {
41668
41702
  const p = change.path[pathIndex];
41669
41703
  if (val[p] === undefined) {
41670
41704
  const nextPath = change.path[pathIndex + 1];
@@ -42419,13 +42453,14 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
42419
42453
  }
42420
42454
  addChange(...args) {
42421
42455
  const val = args.pop();
42422
- const [root, ...path] = args;
42456
+ const root = args[0];
42423
42457
  let value = root;
42424
- let key = path[path.length - 1];
42425
- for (let pathIndex = 0; pathIndex <= path.length - 2; pathIndex++) {
42426
- const p = path[pathIndex];
42458
+ let key = args[args.length - 1];
42459
+ const pathLength = args.length - 2;
42460
+ for (let pathIndex = 1; pathIndex <= pathLength; pathIndex++) {
42461
+ const p = args[pathIndex];
42427
42462
  if (value[p] === undefined) {
42428
- const nextPath = path[pathIndex + 1];
42463
+ const nextPath = args[pathIndex + 1];
42429
42464
  value[p] = createEmptyStructure(nextPath);
42430
42465
  }
42431
42466
  value = value[p];
@@ -42434,8 +42469,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
42434
42469
  return;
42435
42470
  }
42436
42471
  this.changes.push({
42437
- root,
42438
- path,
42472
+ path: args,
42439
42473
  before: value[key],
42440
42474
  after: val,
42441
42475
  });
@@ -44209,7 +44243,10 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
44209
44243
  */
44210
44244
  checkDispatchAllowed(command) {
44211
44245
  const results = this.handlers.map((handler) => handler.allowDispatch(command));
44212
- return new DispatchResult(results.flat());
44246
+ if (results.some((r) => r !== 0 /* CommandResult.Success */)) {
44247
+ return new DispatchResult(results.flat());
44248
+ }
44249
+ return DispatchResult.Success;
44213
44250
  }
44214
44251
  finalize() {
44215
44252
  this.status = 3 /* Status.Finalizing */;
@@ -44439,9 +44476,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
44439
44476
  Object.defineProperty(exports, '__esModule', { value: true });
44440
44477
 
44441
44478
 
44442
- __info__.version = '16.1.26';
44443
- __info__.date = '2023-11-02T09:31:23.420Z';
44444
- __info__.hash = '1ddd8d0';
44479
+ __info__.version = '16.1.28';
44480
+ __info__.date = '2023-11-24T13:11:01.992Z';
44481
+ __info__.hash = '257f369';
44445
44482
 
44446
44483
 
44447
44484
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);