@odoo/o-spreadsheet 16.0.56 → 16.0.58

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.
@@ -11568,15 +11568,18 @@ function dichotomicSearch(data, target, mode, sortOrder, rangeLength, getValueIn
11568
11568
  let currentIndex;
11569
11569
  let currentVal;
11570
11570
  let currentType;
11571
+ const getValue = sortOrder === "desc"
11572
+ ? (i) => getValueInData(data, rangeLength - i - 1)
11573
+ : (i) => getValueInData(data, i);
11571
11574
  while (indexRight - indexLeft >= 0) {
11572
11575
  indexMedian = Math.floor((indexLeft + indexRight) / 2);
11573
11576
  currentIndex = indexMedian;
11574
- currentVal = getValueInData(data, currentIndex);
11577
+ currentVal = getValue(currentIndex);
11575
11578
  currentType = typeof currentVal;
11576
11579
  // 1 - linear search to find value with the same type
11577
11580
  while (indexLeft < currentIndex && targetType !== currentType) {
11578
11581
  currentIndex--;
11579
- currentVal = getValueInData(data, currentIndex);
11582
+ currentVal = getValue(currentIndex);
11580
11583
  currentType = typeof currentVal;
11581
11584
  }
11582
11585
  if (currentType !== targetType || currentVal === undefined) {
@@ -11591,8 +11594,7 @@ function dichotomicSearch(data, target, mode, sortOrder, rangeLength, getValueIn
11591
11594
  else if (mode === "nextSmaller" && currentVal <= target) {
11592
11595
  if (matchVal === undefined ||
11593
11596
  matchVal < currentVal ||
11594
- (matchVal === currentVal && sortOrder === "asc" && matchValIndex < currentIndex) ||
11595
- (matchVal === currentVal && sortOrder === "desc" && matchValIndex > currentIndex)) {
11597
+ (matchVal === currentVal && matchValIndex < currentIndex)) {
11596
11598
  matchVal = currentVal;
11597
11599
  matchValIndex = currentIndex;
11598
11600
  }
@@ -11600,15 +11602,13 @@ function dichotomicSearch(data, target, mode, sortOrder, rangeLength, getValueIn
11600
11602
  else if (mode === "nextGreater" && currentVal >= target) {
11601
11603
  if (matchVal === undefined ||
11602
11604
  matchVal > currentVal ||
11603
- (matchVal === currentVal && sortOrder === "asc" && matchValIndex < currentIndex) ||
11604
- (matchVal === currentVal && sortOrder === "desc" && matchValIndex > currentIndex)) {
11605
+ (matchVal === currentVal && matchValIndex < currentIndex)) {
11605
11606
  matchVal = currentVal;
11606
11607
  matchValIndex = currentIndex;
11607
11608
  }
11608
11609
  }
11609
11610
  // 3 - give new indexes for the Binary search
11610
- if ((sortOrder === "asc" && currentVal > target) ||
11611
- (sortOrder === "desc" && currentVal <= target)) {
11611
+ if (currentVal > target || (mode === "strict" && currentVal === target)) {
11612
11612
  indexRight = currentIndex - 1;
11613
11613
  }
11614
11614
  else {
@@ -11616,7 +11616,10 @@ function dichotomicSearch(data, target, mode, sortOrder, rangeLength, getValueIn
11616
11616
  }
11617
11617
  }
11618
11618
  // note that valMinIndex could be 0
11619
- return matchValIndex !== undefined ? matchValIndex : -1;
11619
+ if (matchValIndex === undefined) {
11620
+ return -1;
11621
+ }
11622
+ return sortOrder === "desc" ? rangeLength - matchValIndex - 1 : matchValIndex;
11620
11623
  }
11621
11624
  /**
11622
11625
  * Perform a linear search and return the index of the match.
@@ -25039,6 +25042,9 @@ function convertFigure(figure, id, sheetData) {
25039
25042
  }
25040
25043
  function convertChartData(chartData) {
25041
25044
  var _a;
25045
+ if (chartData.dataSets.length === 0) {
25046
+ return undefined;
25047
+ }
25042
25048
  const labelRange = (_a = chartData.dataSets[0].label) === null || _a === void 0 ? void 0 : _a.replace(/\$/g, "");
25043
25049
  let dataSets = chartData.dataSets.map((data) => data.range.replace(/\$/g, ""));
25044
25050
  // For doughnut charts, in chartJS first dataset = outer dataset, in excel first dataset = inner dataset
@@ -27510,10 +27516,34 @@ class BordersPlugin extends CorePlugin {
27510
27516
  const elements = [...cmd.elements].sort((a, b) => b - a);
27511
27517
  for (const group of groupConsecutive(elements)) {
27512
27518
  if (cmd.dimension === "COL") {
27513
- this.shiftBordersHorizontally(cmd.sheetId, group[group.length - 1] + 1, -group.length);
27519
+ if (group[0] >= this.getters.getNumberCols(cmd.sheetId)) {
27520
+ for (let row = 0; row < this.getters.getNumberRows(cmd.sheetId); row++) {
27521
+ this.history.update("borders", cmd.sheetId, group[0] + 1, row, "vertical", undefined);
27522
+ }
27523
+ }
27524
+ if (group[group.length - 1] === 0) {
27525
+ for (let row = 0; row < this.getters.getNumberRows(cmd.sheetId); row++) {
27526
+ this.history.update("borders", cmd.sheetId, 0, row, "vertical", undefined);
27527
+ }
27528
+ }
27529
+ const zone = this.getters.getColsZone(cmd.sheetId, group[group.length - 1] + 1, group[0]);
27530
+ this.clearInsideBorders(cmd.sheetId, [zone]);
27531
+ this.shiftBordersHorizontally(cmd.sheetId, group[0] + 1, -group.length);
27514
27532
  }
27515
27533
  else {
27516
- this.shiftBordersVertically(cmd.sheetId, group[group.length - 1] + 1, -group.length);
27534
+ if (group[0] >= this.getters.getNumberRows(cmd.sheetId)) {
27535
+ for (let col = 0; col < this.getters.getNumberCols(cmd.sheetId); col++) {
27536
+ this.history.update("borders", cmd.sheetId, col, group[0] + 1, "horizontal", undefined);
27537
+ }
27538
+ }
27539
+ if (group[group.length - 1] === 0) {
27540
+ for (let col = 0; col < this.getters.getNumberCols(cmd.sheetId); col++) {
27541
+ this.history.update("borders", cmd.sheetId, col, 0, "horizontal", undefined);
27542
+ }
27543
+ }
27544
+ const zone = this.getters.getRowsZone(cmd.sheetId, group[group.length - 1] + 1, group[0]);
27545
+ this.clearInsideBorders(cmd.sheetId, [zone]);
27546
+ this.shiftBordersVertically(cmd.sheetId, group[0] + 1, -group.length);
27517
27547
  }
27518
27548
  }
27519
27549
  break;
@@ -27808,6 +27838,18 @@ class BordersPlugin extends CorePlugin {
27808
27838
  }
27809
27839
  }
27810
27840
  }
27841
+ /**
27842
+ * Remove the borders inside of a zone
27843
+ */
27844
+ clearInsideBorders(sheetId, zones) {
27845
+ for (let zone of zones) {
27846
+ for (let row = zone.top; row <= zone.bottom; row++) {
27847
+ for (let col = zone.left; col <= zone.right; col++) {
27848
+ this.history.update("borders", sheetId, col, row, undefined);
27849
+ }
27850
+ }
27851
+ }
27852
+ }
27811
27853
  /**
27812
27854
  * Add a border to the existing one to a cell
27813
27855
  */
@@ -34380,12 +34422,21 @@ class RendererPlugin extends UIPlugin {
34380
34422
  drawGrid(renderingContext, layer) {
34381
34423
  switch (layer) {
34382
34424
  case 0 /* LAYERS.Background */:
34383
- this.boxes = this.getGridBoxes();
34384
34425
  this.drawBackground(renderingContext);
34385
- this.drawCellBackground(renderingContext);
34386
- this.drawBorders(renderingContext);
34387
- this.drawTexts(renderingContext);
34388
- this.drawIcon(renderingContext);
34426
+ for (const zone of this.getters.getAllActiveViewportsZones()) {
34427
+ const { ctx } = renderingContext;
34428
+ ctx.save();
34429
+ ctx.beginPath();
34430
+ const rect = this.getters.getVisibleRect(zone);
34431
+ ctx.rect(rect.x, rect.y, rect.width, rect.height);
34432
+ ctx.clip();
34433
+ this.boxes = this.getGridBoxes(zone);
34434
+ this.drawCellBackground(renderingContext);
34435
+ this.drawBorders(renderingContext);
34436
+ this.drawTexts(renderingContext);
34437
+ this.drawIcon(renderingContext);
34438
+ ctx.restore();
34439
+ }
34389
34440
  this.drawFrozenPanes(renderingContext);
34390
34441
  break;
34391
34442
  case 7 /* LAYERS.Headers */:
@@ -34750,7 +34801,7 @@ class RendererPlugin extends UIPlugin {
34750
34801
  const row = zone.top;
34751
34802
  const cell = this.getters.getCell(sheetId, col, row);
34752
34803
  const showFormula = this.getters.shouldShowFormulas();
34753
- const { x, y, width, height } = this.getters.getVisibleRect(zone);
34804
+ const { x, y, width, height } = this.getters.getRect(zone);
34754
34805
  const box = {
34755
34806
  x,
34756
34807
  y,
@@ -34862,12 +34913,16 @@ class RendererPlugin extends UIPlugin {
34862
34913
  }
34863
34914
  return box;
34864
34915
  }
34865
- getGridBoxes() {
34916
+ getGridBoxes(zone) {
34866
34917
  const boxes = [];
34867
- const visibleCols = this.getters.getSheetViewVisibleCols();
34918
+ const visibleCols = this.getters
34919
+ .getSheetViewVisibleCols()
34920
+ .filter((col) => col >= zone.left && col <= zone.right);
34868
34921
  const left = visibleCols[0];
34869
34922
  const right = visibleCols[visibleCols.length - 1];
34870
- const visibleRows = this.getters.getSheetViewVisibleRows();
34923
+ const visibleRows = this.getters
34924
+ .getSheetViewVisibleRows()
34925
+ .filter((row) => row >= zone.top && row <= zone.bottom);
34871
34926
  const top = visibleRows[0];
34872
34927
  const bottom = visibleRows[visibleRows.length - 1];
34873
34928
  const viewport = { left, right, top, bottom };
@@ -35397,7 +35452,7 @@ class GridSelectionPlugin extends UIPlugin {
35397
35452
  ];
35398
35453
  state.paste(pasteTarget, { selectTarget: true });
35399
35454
  const toRemove = isBasedBefore ? cmd.elements.map((el) => el + thickness) : cmd.elements;
35400
- let currentIndex = cmd.base;
35455
+ let currentIndex = isBasedBefore ? cmd.base : cmd.base + 1;
35401
35456
  for (const element of toRemove) {
35402
35457
  const size = cmd.dimension === "COL"
35403
35458
  ? this.getters.getColSize(cmd.sheetId, element)
@@ -36904,7 +36959,7 @@ class InternalViewport {
36904
36959
  * @param zone
36905
36960
  * @returns Computes the absolute coordinate of a given zone inside the viewport
36906
36961
  */
36907
- getRect(zone) {
36962
+ getVisibleRect(zone) {
36908
36963
  const targetZone = intersection(zone, this.zone);
36909
36964
  if (targetZone) {
36910
36965
  const x = this.getters.getColRowOffset("COL", this.zone.left, targetZone.left) +
@@ -36912,12 +36967,20 @@ class InternalViewport {
36912
36967
  const y = this.getters.getColRowOffset("ROW", this.zone.top, targetZone.top) + this.offsetCorrectionY;
36913
36968
  const width = Math.min(this.getters.getColRowOffset("COL", targetZone.left, targetZone.right + 1), this.viewportWidth);
36914
36969
  const height = Math.min(this.getters.getColRowOffset("ROW", targetZone.top, targetZone.bottom + 1), this.viewportHeight);
36915
- return {
36916
- x,
36917
- y,
36918
- width,
36919
- height,
36920
- };
36970
+ return { x, y, width, height };
36971
+ }
36972
+ else {
36973
+ return undefined;
36974
+ }
36975
+ }
36976
+ getFullRect(zone) {
36977
+ const targetZone = intersection(zone, this.zone);
36978
+ if (targetZone) {
36979
+ const x = this.getters.getColRowOffset("COL", this.zone.left, zone.left) + this.offsetCorrectionX;
36980
+ const y = this.getters.getColRowOffset("ROW", this.zone.top, zone.top) + this.offsetCorrectionY;
36981
+ const width = this.getters.getColRowOffset("COL", zone.left, zone.right + 1);
36982
+ const height = this.getters.getColRowOffset("ROW", zone.top, zone.bottom + 1);
36983
+ return { x, y, width, height };
36921
36984
  }
36922
36985
  else {
36923
36986
  return undefined;
@@ -37411,21 +37474,26 @@ class SheetViewPlugin extends UIPlugin {
37411
37474
  getVisibleRect(zone) {
37412
37475
  const sheetId = this.getters.getActiveSheetId();
37413
37476
  const viewportRects = this.getSubViewports(sheetId)
37414
- .map((viewport) => viewport.getRect(zone))
37477
+ .map((viewport) => viewport.getVisibleRect(zone))
37415
37478
  .filter(isDefined$1);
37416
37479
  if (viewportRects.length === 0) {
37417
37480
  return { x: 0, y: 0, width: 0, height: 0 };
37418
37481
  }
37419
- const x = Math.min(...viewportRects.map((rect) => rect.x));
37420
- const y = Math.min(...viewportRects.map((rect) => rect.y));
37421
- const width = Math.max(...viewportRects.map((rect) => rect.x + rect.width)) - x;
37422
- const height = Math.max(...viewportRects.map((rect) => rect.y + rect.height)) - y;
37423
- return {
37424
- x: x + this.gridOffsetX,
37425
- y: y + this.gridOffsetY,
37426
- width,
37427
- height,
37428
- };
37482
+ return this.recomposeRect(viewportRects);
37483
+ }
37484
+ /**
37485
+ * Computes the actual size and position (:Rect) of the zone on the canvas
37486
+ * regardless of the viewport dimensions.
37487
+ */
37488
+ getRect(zone) {
37489
+ const sheetId = this.getters.getActiveSheetId();
37490
+ const viewportRects = this.getSubViewports(sheetId)
37491
+ .map((viewport) => viewport.getFullRect(zone))
37492
+ .filter(isDefined$1);
37493
+ if (viewportRects.length === 0) {
37494
+ return { x: 0, y: 0, width: 0, height: 0 };
37495
+ }
37496
+ return this.recomposeRect(viewportRects);
37429
37497
  }
37430
37498
  /**
37431
37499
  * Returns the position of the MainViewport relatively to the start of the grid (without headers)
@@ -37439,6 +37507,10 @@ class SheetViewPlugin extends UIPlugin {
37439
37507
  const y = this.getters.getRowDimensions(sheetId, ySplit).start;
37440
37508
  return { x, y };
37441
37509
  }
37510
+ getAllActiveViewportsZones() {
37511
+ const sheetId = this.getters.getActiveSheetId();
37512
+ return this.getSubViewports(sheetId);
37513
+ }
37442
37514
  // ---------------------------------------------------------------------------
37443
37515
  // Private
37444
37516
  // ---------------------------------------------------------------------------
@@ -37621,6 +37693,18 @@ class SheetViewPlugin extends UIPlugin {
37621
37693
  const height = this.sheetViewHeight + this.gridOffsetY;
37622
37694
  return { xRatio: offsetCorrectionX / width, yRatio: offsetCorrectionY / height };
37623
37695
  }
37696
+ recomposeRect(viewportRects) {
37697
+ const x = Math.min(...viewportRects.map((rect) => rect.x));
37698
+ const y = Math.min(...viewportRects.map((rect) => rect.y));
37699
+ const width = Math.max(...viewportRects.map((rect) => rect.x + rect.width)) - x;
37700
+ const height = Math.max(...viewportRects.map((rect) => rect.y + rect.height)) - y;
37701
+ return {
37702
+ x: x + this.gridOffsetX,
37703
+ y: y + this.gridOffsetY,
37704
+ width,
37705
+ height,
37706
+ };
37707
+ }
37624
37708
  }
37625
37709
  SheetViewPlugin.getters = [
37626
37710
  "getColIndex",
@@ -37641,6 +37725,8 @@ SheetViewPlugin.getters = [
37641
37725
  "getSheetViewVisibleCols",
37642
37726
  "getSheetViewVisibleRows",
37643
37727
  "getFrozenSheetViewRatio",
37728
+ "getAllActiveViewportsZones",
37729
+ "getRect",
37644
37730
  ];
37645
37731
 
37646
37732
  class SortPlugin extends UIPlugin {
@@ -43484,6 +43570,6 @@ exports.setTranslationMethod = setTranslationMethod;
43484
43570
  exports.tokenize = tokenize;
43485
43571
 
43486
43572
 
43487
- __info__.version = '16.0.56';
43488
- __info__.date = '2024-12-19T07:45:47.250Z';
43489
- __info__.hash = '9d0e335';
43573
+ __info__.version = '16.0.58';
43574
+ __info__.date = '2025-01-27T10:00:05.196Z';
43575
+ __info__.hash = '4886b0b';
@@ -3081,6 +3081,10 @@ declare class BordersPlugin extends CorePlugin<BordersPluginState> implements Bo
3081
3081
  * Remove the borders of a zone
3082
3082
  */
3083
3083
  private clearBorders;
3084
+ /**
3085
+ * Remove the borders inside of a zone
3086
+ */
3087
+ private clearInsideBorders;
3084
3088
  /**
3085
3089
  * Add a border to the existing one to a cell
3086
3090
  */
@@ -4342,7 +4346,8 @@ declare class InternalViewport {
4342
4346
  * @param zone
4343
4347
  * @returns Computes the absolute coordinate of a given zone inside the viewport
4344
4348
  */
4345
- getRect(zone: Zone): Rect | undefined;
4349
+ getVisibleRect(zone: Zone): Rect | undefined;
4350
+ getFullRect(zone: Zone): Rect | undefined;
4346
4351
  isVisible(col: HeaderIndex, row: HeaderIndex): boolean;
4347
4352
  private searchHeaderIndex;
4348
4353
  private get zone();
@@ -4412,7 +4417,7 @@ type SheetViewports = {
4412
4417
  *
4413
4418
  */
4414
4419
  declare class SheetViewPlugin extends UIPlugin {
4415
- static getters: readonly ["getColIndex", "getRowIndex", "getActiveMainViewport", "getSheetViewDimension", "getSheetViewDimensionWithHeaders", "getMainViewportRect", "isVisibleInViewport", "getEdgeScrollCol", "getEdgeScrollRow", "getVisibleFigures", "getVisibleRect", "getColRowOffsetInViewport", "getMainViewportCoordinates", "getActiveSheetScrollInfo", "getActiveSheetDOMScrollInfo", "getSheetViewVisibleCols", "getSheetViewVisibleRows", "getFrozenSheetViewRatio"];
4420
+ static getters: readonly ["getColIndex", "getRowIndex", "getActiveMainViewport", "getSheetViewDimension", "getSheetViewDimensionWithHeaders", "getMainViewportRect", "isVisibleInViewport", "getEdgeScrollCol", "getEdgeScrollRow", "getVisibleFigures", "getVisibleRect", "getColRowOffsetInViewport", "getMainViewportCoordinates", "getActiveSheetScrollInfo", "getActiveSheetDOMScrollInfo", "getSheetViewVisibleCols", "getSheetViewVisibleRows", "getFrozenSheetViewRatio", "getAllActiveViewportsZones", "getRect"];
4416
4421
  readonly viewports: Record<UID, SheetViewports | undefined>;
4417
4422
  /**
4418
4423
  * The viewport dimensions are usually set by one of the components
@@ -4474,12 +4479,18 @@ declare class SheetViewPlugin extends UIPlugin {
4474
4479
  * Computes the coordinates and size to draw the zone on the canvas
4475
4480
  */
4476
4481
  getVisibleRect(zone: Zone): Rect;
4482
+ /**
4483
+ * Computes the actual size and position (:Rect) of the zone on the canvas
4484
+ * regardless of the viewport dimensions.
4485
+ */
4486
+ getRect(zone: Zone): Rect;
4477
4487
  /**
4478
4488
  * Returns the position of the MainViewport relatively to the start of the grid (without headers)
4479
4489
  * It corresponds to the summed dimensions of the visible cols/rows (in x/y respectively)
4480
4490
  * situated before the pane divisions.
4481
4491
  */
4482
4492
  getMainViewportCoordinates(): DOMCoordinates;
4493
+ getAllActiveViewportsZones(): Zone[];
4483
4494
  private ensureMainViewportExist;
4484
4495
  private getSubViewports;
4485
4496
  private checkPositiveDimension;
@@ -4510,6 +4521,7 @@ declare class SheetViewPlugin extends UIPlugin {
4510
4521
  xRatio: number;
4511
4522
  yRatio: number;
4512
4523
  };
4524
+ private recomposeRect;
4513
4525
  }
4514
4526
 
4515
4527
  declare class SortPlugin extends UIPlugin {