@odoo/o-spreadsheet 15.0.19 → 15.0.21

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.
@@ -2972,7 +2972,7 @@
2972
2972
  if (typeof o1 !== typeof o2)
2973
2973
  return false;
2974
2974
  if (typeof o1 !== "object")
2975
- return o1 === o2;
2975
+ return false;
2976
2976
  // Objects can have different keys if the values are undefined
2977
2977
  const keys = new Set();
2978
2978
  Object.keys(o1).forEach((key) => keys.add(key));
@@ -2990,6 +2990,34 @@
2990
2990
  }
2991
2991
  }
2992
2992
  return true;
2993
+ }
2994
+ /**
2995
+ * Alternative to Math.max that works with large arrays.
2996
+ * Typically useful for arrays bigger than 100k elements.
2997
+ */
2998
+ function largeMax(array) {
2999
+ let len = array.length;
3000
+ if (len < 100000)
3001
+ return Math.max(...array);
3002
+ let max = -Infinity;
3003
+ while (len--) {
3004
+ max = array[len] > max ? array[len] : max;
3005
+ }
3006
+ return max;
3007
+ }
3008
+ /**
3009
+ * Alternative to Math.min that works with large arrays.
3010
+ * Typically useful for arrays bigger than 100k elements.
3011
+ */
3012
+ function largeMin(array) {
3013
+ let len = array.length;
3014
+ if (len < 100000)
3015
+ return Math.min(...array);
3016
+ let min = +Infinity;
3017
+ while (len--) {
3018
+ min = array[len] < min ? array[len] : min;
3019
+ }
3020
+ return min;
2993
3021
  }
2994
3022
 
2995
3023
  /**
@@ -3607,9 +3635,10 @@
3607
3635
  * https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
3608
3636
  * */
3609
3637
  class UuidGenerator {
3610
- constructor() {
3638
+ constructor(isFast = false) {
3611
3639
  this.isFastIdStrategy = false;
3612
3640
  this.fastIdStart = 0;
3641
+ this.setIsFastStrategy(isFast);
3613
3642
  }
3614
3643
  setIsFastStrategy(isFast) {
3615
3644
  this.isFastIdStrategy = isFast;
@@ -9520,6 +9549,7 @@
9520
9549
  constructor() {
9521
9550
  super(...arguments);
9522
9551
  this.cells = {};
9552
+ this.cellUuidGenerator = new UuidGenerator(true);
9523
9553
  this.createCell = cellFactory(this.getters);
9524
9554
  }
9525
9555
  adaptRanges(applyChange, sheetId) {
@@ -9699,7 +9729,7 @@
9699
9729
  }
9700
9730
  importCell(sheet, cellData, normalizedStyles) {
9701
9731
  const style = (cellData.style && normalizedStyles[cellData.style]) || undefined;
9702
- const cellId = this.uuidGenerator.uuidv4();
9732
+ const cellId = this.cellUuidGenerator.uuidv4();
9703
9733
  const properties = { format: cellData === null || cellData === void 0 ? void 0 : cellData.format, style };
9704
9734
  return this.createCell(cellId, (cellData === null || cellData === void 0 ? void 0 : cellData.content) || "", properties, sheet.id);
9705
9735
  }
@@ -9882,7 +9912,7 @@
9882
9912
  }
9883
9913
  return;
9884
9914
  }
9885
- const cellId = (before === null || before === void 0 ? void 0 : before.id) || this.uuidGenerator.uuidv4();
9915
+ const cellId = (before === null || before === void 0 ? void 0 : before.id) || this.cellUuidGenerator.uuidv4();
9886
9916
  const didContentChange = hasContent;
9887
9917
  const properties = { format, style };
9888
9918
  const cell = this.createCell(cellId, afterContent, properties, sheet.id);
@@ -12029,8 +12059,8 @@
12029
12059
  getImportedSheetSize(data) {
12030
12060
  const positions = Object.keys(data.cells).map(toCartesian);
12031
12061
  return {
12032
- rowNumber: Math.max(data.rowNumber, ...new Set(positions.map(([col, row]) => row + 1))),
12033
- colNumber: Math.max(data.colNumber, ...new Set(positions.map(([col, row]) => col + 1))),
12062
+ rowNumber: Math.max(data.rowNumber, largeMax(positions.map(([col, row]) => row + 1))),
12063
+ colNumber: Math.max(data.colNumber, largeMax(positions.map(([col, row]) => col + 1))),
12034
12064
  };
12035
12065
  }
12036
12066
  // ----------------------------------------------------
@@ -12567,8 +12597,8 @@
12567
12597
  let last;
12568
12598
  const activesRows = env.getters.getActiveRows();
12569
12599
  if (activesRows.size !== 0) {
12570
- first = Math.min(...activesRows);
12571
- last = Math.max(...activesRows);
12600
+ first = largeMin([...activesRows]);
12601
+ last = largeMax([...activesRows]);
12572
12602
  }
12573
12603
  else {
12574
12604
  const zone = env.getters.getSelectedZones()[0];
@@ -12593,8 +12623,8 @@
12593
12623
  let last;
12594
12624
  const activeCols = env.getters.getActiveCols();
12595
12625
  if (activeCols.size !== 0) {
12596
- first = Math.min(...activeCols);
12597
- last = Math.max(...activeCols);
12626
+ first = largeMin([...activeCols]);
12627
+ last = largeMax([...activeCols]);
12598
12628
  }
12599
12629
  else {
12600
12630
  const zone = env.getters.getSelectedZones()[0];
@@ -12619,8 +12649,8 @@
12619
12649
  let last;
12620
12650
  const activesRows = env.getters.getActiveRows();
12621
12651
  if (activesRows.size !== 0) {
12622
- first = Math.min(...activesRows);
12623
- last = Math.max(...activesRows);
12652
+ first = largeMin([...activesRows]);
12653
+ last = largeMax([...activesRows]);
12624
12654
  }
12625
12655
  else {
12626
12656
  const zone = env.getters.getSelectedZones()[0];
@@ -12651,8 +12681,8 @@
12651
12681
  let last;
12652
12682
  const activeCols = env.getters.getActiveCols();
12653
12683
  if (activeCols.size !== 0) {
12654
- first = Math.min(...activeCols);
12655
- last = Math.max(...activeCols);
12684
+ first = largeMin([...activeCols]);
12685
+ last = largeMax([...activeCols]);
12656
12686
  }
12657
12687
  else {
12658
12688
  const zone = env.getters.getSelectedZones()[0];
@@ -12717,7 +12747,7 @@
12717
12747
  let row;
12718
12748
  let quantity;
12719
12749
  if (activeRows.size) {
12720
- row = Math.min(...activeRows);
12750
+ row = largeMin([...activeRows]);
12721
12751
  quantity = activeRows.size;
12722
12752
  }
12723
12753
  else {
@@ -12749,7 +12779,7 @@
12749
12779
  let row;
12750
12780
  let quantity;
12751
12781
  if (activeRows.size) {
12752
- row = Math.max(...activeRows);
12782
+ row = largeMax([...activeRows]);
12753
12783
  quantity = activeRows.size;
12754
12784
  }
12755
12785
  else {
@@ -12790,7 +12820,7 @@
12790
12820
  let column;
12791
12821
  let quantity;
12792
12822
  if (activeCols.size) {
12793
- column = Math.min(...activeCols);
12823
+ column = largeMin([...activeCols]);
12794
12824
  quantity = activeCols.size;
12795
12825
  }
12796
12826
  else {
@@ -12824,7 +12854,7 @@
12824
12854
  let column;
12825
12855
  let quantity;
12826
12856
  if (activeCols.size) {
12827
- column = Math.max(...activeCols);
12857
+ column = largeMax([...activeCols]);
12828
12858
  quantity = activeCols.size;
12829
12859
  }
12830
12860
  else {
@@ -16566,13 +16596,13 @@
16566
16596
  const cells = mapCellsInZone(zone, sheet, (cell) => cell, undefined).flat();
16567
16597
  const cellPositions = range(end, -1, -1);
16568
16598
  const invalidCells = cellPositions.filter((position) => { var _a; return cells[position] && !((_a = cells[position]) === null || _a === void 0 ? void 0 : _a.isAutoSummable); });
16569
- const maxValidPosition = Math.max(...invalidCells);
16599
+ const maxValidPosition = largeMax(invalidCells);
16570
16600
  const numberSequences = groupConsecutive(cellPositions.filter((position) => this.isNumber(cells[position])));
16571
16601
  const firstSequence = numberSequences[0] || [];
16572
- if (Math.max(...firstSequence) < maxValidPosition) {
16602
+ if (largeMax(firstSequence) < maxValidPosition) {
16573
16603
  return Infinity;
16574
16604
  }
16575
- return Math.min(...firstSequence);
16605
+ return largeMin(firstSequence);
16576
16606
  }
16577
16607
  shouldFindData(sheetId, zone) {
16578
16608
  return this.getters.isEmpty(sheetId, zone) || this.getters.isSingleCellOrMerge(sheetId, zone);
@@ -22263,13 +22293,13 @@
22263
22293
  getColMaxWidth(sheetId, index) {
22264
22294
  const cells = this.getters.getColCells(sheetId, index);
22265
22295
  const sizes = cells.map((cell) => this.getCellWidth(cell));
22266
- return Math.max(0, ...sizes);
22296
+ return Math.max(0, largeMax(sizes));
22267
22297
  }
22268
22298
  getRowMaxHeight(sheetId, index) {
22269
22299
  const sheet = this.getters.getSheet(sheetId);
22270
22300
  const cells = Object.values(sheet.rows[index].cells);
22271
22301
  const sizes = cells.map((cell) => this.getCellHeight(cell));
22272
- return Math.max(0, ...sizes);
22302
+ return Math.max(0, largeMax(sizes));
22273
22303
  }
22274
22304
  interactiveRenameSheet(sheetId, title) {
22275
22305
  const placeholder = this.getters.getSheetName(sheetId);
@@ -23688,8 +23718,8 @@
23688
23718
  let newRange = range;
23689
23719
  let changeType = "NONE";
23690
23720
  for (let group of groups) {
23691
- const min = Math.min(...group);
23692
- const max = Math.max(...group);
23721
+ const min = largeMin(group);
23722
+ const max = largeMax(group);
23693
23723
  if (range.zone[start] <= min && min <= range.zone[end]) {
23694
23724
  const toRemove = Math.min(range.zone[end], max) - min + 1;
23695
23725
  changeType = "RESIZE";
@@ -24274,10 +24304,6 @@
24274
24304
  if (cell.style) {
24275
24305
  style = data.styles[cell.style];
24276
24306
  }
24277
- let border = {};
24278
- if (cell.border) {
24279
- border = data.borders[cell.border];
24280
- }
24281
24307
  const styles = {
24282
24308
  font: {
24283
24309
  size: (style === null || style === void 0 ? void 0 : style.fontSize) || DEFAULT_FONT_SIZE,
@@ -24291,7 +24317,7 @@
24291
24317
  }
24292
24318
  : { reservedAttribute: "none" },
24293
24319
  numFmt: cell.format,
24294
- border: border || {},
24320
+ border: cell.border || 0,
24295
24321
  verticalAlignment: "center",
24296
24322
  horizontalAlignment: style === null || style === void 0 ? void 0 : style.align,
24297
24323
  };
@@ -24302,21 +24328,17 @@
24302
24328
  return styles;
24303
24329
  }
24304
24330
  function normalizeStyle(construct, styles) {
24305
- const { id: fontId } = pushElement(styles["font"], construct.fonts);
24306
- const { id: fillId } = pushElement(styles["fill"], construct.fills);
24307
- const { id: borderId } = pushElement(styles["border"], construct.borders);
24308
24331
  // Normalize this
24309
24332
  const numFmtId = convertFormat(styles["numFmt"], construct.numFmts);
24310
24333
  const style = {
24311
- fontId,
24312
- fillId,
24313
- borderId,
24334
+ fontId: pushElement(styles.font, construct.fonts),
24335
+ fillId: pushElement(styles.fill, construct.fills),
24336
+ borderId: styles.border,
24314
24337
  numFmtId,
24315
24338
  verticalAlignment: styles["verticalAlignment"],
24316
24339
  horizontalAlignment: styles["horizontalAlignment"],
24317
24340
  };
24318
- const { id } = pushElement(style, construct.styles);
24319
- return id;
24341
+ return pushElement(style, construct.styles);
24320
24342
  }
24321
24343
  function convertFormat(format, numFmtStructure) {
24322
24344
  if (!format) {
@@ -24324,8 +24346,7 @@
24324
24346
  }
24325
24347
  let formatId = XLSX_FORMAT_MAP[format];
24326
24348
  if (!formatId) {
24327
- const { id } = pushElement(format, numFmtStructure);
24328
- formatId = id + FIRST_NUMFMT_ID;
24349
+ formatId = pushElement(format, numFmtStructure) + FIRST_NUMFMT_ID;
24329
24350
  }
24330
24351
  return formatId;
24331
24352
  }
@@ -24350,20 +24371,15 @@
24350
24371
  return id;
24351
24372
  }
24352
24373
  function pushElement(property, propertyList) {
24353
- for (let [key, value] of Object.entries(propertyList)) {
24354
- if (JSON.stringify(value) === JSON.stringify(property)) {
24355
- return { id: parseInt(key, 10), list: propertyList };
24374
+ let len = propertyList.length;
24375
+ const operator = typeof property === "object" ? deepEquals : (a, b) => a === b;
24376
+ for (let i = 0; i < len; i++) {
24377
+ if (operator(property, propertyList[i])) {
24378
+ return i;
24356
24379
  }
24357
24380
  }
24358
- let elemId = propertyList.findIndex((elem) => JSON.stringify(elem) === JSON.stringify(property));
24359
- if (elemId === -1) {
24360
- propertyList.push(property);
24361
- elemId = propertyList.length - 1;
24362
- }
24363
- return {
24364
- id: elemId,
24365
- list: propertyList,
24366
- };
24381
+ propertyList[propertyList.length] = property;
24382
+ return propertyList.length - 1;
24367
24383
  }
24368
24384
  const chartIds = [];
24369
24385
  /**
@@ -24444,7 +24460,8 @@
24444
24460
  }
24445
24461
  return document;
24446
24462
  }
24447
- function getDefaultXLSXStructure() {
24463
+ function getDefaultXLSXStructure(data) {
24464
+ const borders = [{}, ...Object.values(data.borders)];
24448
24465
  return {
24449
24466
  relsFiles: [],
24450
24467
  sharedStrings: [],
@@ -24467,7 +24484,7 @@
24467
24484
  },
24468
24485
  ],
24469
24486
  fills: [{ reservedAttribute: "none" }, { reservedAttribute: "gray125" }],
24470
- borders: [{}],
24487
+ borders,
24471
24488
  numFmts: [],
24472
24489
  dxfs: [],
24473
24490
  };
@@ -24894,8 +24911,7 @@
24894
24911
  attrs.push(["t", "b"]);
24895
24912
  }
24896
24913
  else if (!isNumber(value)) {
24897
- const { id } = pushElement(content, sharedStrings);
24898
- value = id.toString();
24914
+ value = pushElement(content, sharedStrings);
24899
24915
  attrs.push(["t", "s"]);
24900
24916
  }
24901
24917
  return { attrs, node: escapeXml /*xml*/ `<v>${value}</v>` };
@@ -25020,8 +25036,7 @@
25020
25036
  if (rule.style.fillColor) {
25021
25037
  dxf.fill = { fgColor: rule.style.fillColor };
25022
25038
  }
25023
- const { id } = pushElement(dxf, dxfs);
25024
- ruleAttributes.push(["dxfId", id]);
25039
+ ruleAttributes.push(["dxfId", pushElement(dxf, dxfs)]);
25025
25040
  return escapeXml /*xml*/ `
25026
25041
  <conditionalFormatting sqref="${cf.ranges.join(" ")}">
25027
25042
  <cfRule ${formatAttributes(ruleAttributes)}>
@@ -25630,7 +25645,7 @@
25630
25645
  */
25631
25646
  function getXLSX(data) {
25632
25647
  const files = [];
25633
- const construct = getDefaultXLSXStructure();
25648
+ const construct = getDefaultXLSXStructure(data);
25634
25649
  files.push(createWorkbook(data, construct));
25635
25650
  files.push(...createWorksheets(data, construct));
25636
25651
  files.push(createStylesSheet(construct));
@@ -31507,9 +31522,9 @@
31507
31522
  Object.defineProperty(exports, '__esModule', { value: true });
31508
31523
 
31509
31524
 
31510
- __info__.version = '15.0.19';
31511
- __info__.date = '2024-03-15T10:55:52.497Z';
31512
- __info__.hash = '277ed99';
31525
+ __info__.version = '15.0.21';
31526
+ __info__.date = '2024-04-10T12:08:56.252Z';
31527
+ __info__.hash = '4d672af';
31513
31528
 
31514
31529
 
31515
31530
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);