@odoo/o-spreadsheet 18.2.17 → 18.2.19

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.
@@ -2,9 +2,9 @@
2
2
  /**
3
3
  * This file is generated by o-spreadsheet build tools. Do not edit it.
4
4
  * @see https://github.com/odoo/o-spreadsheet
5
- * @version 18.2.17
6
- * @date 2025-06-12T09:52:15.050Z
7
- * @hash ea64209
5
+ * @version 18.2.19
6
+ * @date 2025-06-23T15:07:13.023Z
7
+ * @hash 430d931
8
8
  */
9
9
 
10
10
  (function (exports, owl) {
@@ -6826,6 +6826,63 @@
6826
6826
  data: spreadsheetContent,
6827
6827
  };
6828
6828
  }
6829
+ /**
6830
+ * Applies each clipboard handler to paste its corresponding data into the target.
6831
+ */
6832
+ const applyClipboardHandlersPaste = (handlers, copiedData, target, options) => {
6833
+ handlers.forEach(({ handlerName, handler }) => {
6834
+ const data = copiedData[handlerName];
6835
+ if (data) {
6836
+ handler.paste(target, data, options);
6837
+ }
6838
+ });
6839
+ };
6840
+ /**
6841
+ * Returns the paste target based on clipboard handlers.
6842
+ * Also includes the full affected zone and the list of pasted zones for selection.
6843
+ */
6844
+ function getPasteTargetFromHandlers(sheetId, zones, copiedData, handlers, options) {
6845
+ let zone = undefined;
6846
+ let selectedZones = [];
6847
+ let target = {
6848
+ sheetId,
6849
+ zones,
6850
+ };
6851
+ for (const { handlerName, handler } of handlers) {
6852
+ const handlerData = copiedData[handlerName];
6853
+ if (!handlerData) {
6854
+ continue;
6855
+ }
6856
+ const currentTarget = handler.getPasteTarget(sheetId, zones, handlerData, options);
6857
+ if (currentTarget.figureId) {
6858
+ target.figureId = currentTarget.figureId;
6859
+ }
6860
+ for (const targetZone of currentTarget.zones) {
6861
+ selectedZones.push(targetZone);
6862
+ if (zone === undefined) {
6863
+ zone = targetZone;
6864
+ continue;
6865
+ }
6866
+ zone = union(zone, targetZone);
6867
+ }
6868
+ }
6869
+ return {
6870
+ target,
6871
+ zone,
6872
+ selectedZones,
6873
+ };
6874
+ }
6875
+ /**
6876
+ * Updates the selection after a paste operation.
6877
+ */
6878
+ const selectPastedZone = (selection, sourceZones, pastedZones) => {
6879
+ const anchorCell = {
6880
+ col: sourceZones[0].left,
6881
+ row: sourceZones[0].top,
6882
+ };
6883
+ selection.getBackToDefault();
6884
+ selection.selectZone({ cell: anchorCell, zone: union(...pastedZones) }, { scrollIntoView: false });
6885
+ };
6829
6886
 
6830
6887
  class ClipboardHandler {
6831
6888
  getters;
@@ -10367,6 +10424,7 @@ stores.inject(MyMetaStore, storeInstance);
10367
10424
  if (isTrendLineAxis(dataset.xAxisID) || dataset.hidden) {
10368
10425
  continue;
10369
10426
  }
10427
+ const yAxisScale = chart.scales[dataset.yAxisID];
10370
10428
  for (let i = 0; i < dataset._parsed.length; i++) {
10371
10429
  const parsedValue = dataset._parsed[i];
10372
10430
  const value = Number(chart.config.type === "radar" ? parsedValue.r : parsedValue.y);
@@ -10377,10 +10435,18 @@ stores.inject(MyMetaStore, storeInstance);
10377
10435
  const xPosition = point.x;
10378
10436
  let yPosition = 0;
10379
10437
  if (chart.config.type === "line" || chart.config.type === "radar") {
10380
- yPosition = point.y - 10;
10438
+ yPosition = value < 0 ? point.y + 10 : point.y - 10;
10381
10439
  }
10382
10440
  else {
10383
- yPosition = value < 0 ? point.y - point.height / 2 : point.y + point.height / 2;
10441
+ const yZeroLine = yAxisScale.getPixelForValue(0);
10442
+ const distanceFromAxisOrigin = Math.abs(yZeroLine - point.y);
10443
+ const textHeight = 12; // ChartJS default text height
10444
+ if (distanceFromAxisOrigin < textHeight) {
10445
+ yPosition = value < 0 ? yZeroLine + textHeight / 2 : yZeroLine - textHeight / 2;
10446
+ }
10447
+ else {
10448
+ yPosition = value < 0 ? point.y - point.height / 2 : point.y + point.height / 2;
10449
+ }
10384
10450
  }
10385
10451
  yPosition = Math.min(yPosition, yMax);
10386
10452
  yPosition = Math.max(yPosition, yMin);
@@ -10390,7 +10456,7 @@ stores.inject(MyMetaStore, storeInstance);
10390
10456
  }
10391
10457
  for (const otherPosition of textsPositions[xPosition] || []) {
10392
10458
  if (Math.abs(otherPosition - yPosition) < 13) {
10393
- yPosition = otherPosition - 13;
10459
+ yPosition = value < 0 ? otherPosition + 13 : otherPosition - 13;
10394
10460
  }
10395
10461
  }
10396
10462
  textsPositions[xPosition].push(yPosition);
@@ -10409,6 +10475,8 @@ stores.inject(MyMetaStore, storeInstance);
10409
10475
  if (isTrendLineAxis(dataset.xAxisID)) {
10410
10476
  return; // ignore trend lines
10411
10477
  }
10478
+ const xAxisScale = chart.scales[dataset.xAxisID];
10479
+ const xZeroLine = xAxisScale.getPixelForValue(0);
10412
10480
  for (let i = 0; i < dataset._parsed.length; i++) {
10413
10481
  const value = Number(dataset._parsed[i].x);
10414
10482
  if (isNaN(value)) {
@@ -10417,17 +10485,27 @@ stores.inject(MyMetaStore, storeInstance);
10417
10485
  const displayValue = options.callback(value, dataset, i);
10418
10486
  const point = dataset.data[i];
10419
10487
  const yPosition = point.y;
10420
- let xPosition = value < 0 ? point.x + point.width / 2 : point.x - point.width / 2;
10421
- xPosition = Math.min(xPosition, xMax);
10422
- xPosition = Math.max(xPosition, xMin);
10488
+ const textWidth = computeTextWidth(ctx, displayValue, { fontSize: 12 }, "px");
10489
+ const distanceFromAxisOrigin = Math.abs(point.x - xZeroLine);
10490
+ const PADDING = 3;
10491
+ let xPosition;
10492
+ if (distanceFromAxisOrigin < textWidth) {
10493
+ xPosition =
10494
+ value < 0 ? xZeroLine - textWidth / 2 - PADDING : xZeroLine + textWidth / 2 + PADDING;
10495
+ }
10496
+ else {
10497
+ xPosition = value < 0 ? point.x + point.width / 2 : point.x - point.width / 2;
10498
+ xPosition = Math.min(xPosition, xMax);
10499
+ xPosition = Math.max(xPosition, xMin);
10500
+ }
10423
10501
  // Avoid overlapping texts with same Y
10424
10502
  if (!textsPositions[yPosition]) {
10425
10503
  textsPositions[yPosition] = [];
10426
10504
  }
10427
- const textWidth = computeTextWidth(ctx, displayValue, { fontSize: 12 }, "px");
10428
10505
  for (const otherPosition of textsPositions[yPosition]) {
10429
10506
  if (Math.abs(otherPosition - xPosition) < textWidth) {
10430
- xPosition = otherPosition + textWidth + 3;
10507
+ xPosition =
10508
+ value < 0 ? otherPosition - textWidth - PADDING : otherPosition + textWidth + PADDING;
10431
10509
  }
10432
10510
  }
10433
10511
  textsPositions[yPosition].push(xPosition);
@@ -30111,7 +30189,9 @@ stores.inject(MyMetaStore, storeInstance);
30111
30189
  background: definition.background,
30112
30190
  callback: (value, dataset) => {
30113
30191
  value = Math.abs(Number(value));
30114
- return formatChartDatasetValue(axisFormats, locale)(value, dataset.xAxisID || "x");
30192
+ return value === 0
30193
+ ? ""
30194
+ : formatChartDatasetValue(axisFormats, locale)(value, dataset.xAxisID || "x");
30115
30195
  },
30116
30196
  };
30117
30197
  }
@@ -34780,6 +34860,10 @@ stores.inject(MyMetaStore, storeInstance);
34780
34860
  });
34781
34861
  };
34782
34862
  const CAN_REMOVE_COLUMNS_ROWS = (dimension, env) => {
34863
+ if ((dimension === "COL" && env.model.getters.getActiveRows().size > 0) ||
34864
+ (dimension === "ROW" && env.model.getters.getActiveCols().size > 0)) {
34865
+ return false;
34866
+ }
34783
34867
  const sheetId = env.model.getters.getActiveSheetId();
34784
34868
  const selectedElements = env.model.getters.getElementsFromSelection(dimension);
34785
34869
  const includesAllVisibleHeaders = env.model.getters.checkElementsIncludeAllVisibleHeaders(sheetId, dimension, selectedElements);
@@ -37759,11 +37843,11 @@ stores.inject(MyMetaStore, storeInstance);
37759
37843
  * transformation function given
37760
37844
  */
37761
37845
  addTransformation(executed, toTransforms, fn) {
37762
- for (let toTransform of toTransforms) {
37763
- if (!this.content[toTransform]) {
37764
- this.content[toTransform] = new Map();
37765
- }
37766
- this.content[toTransform].set(executed, fn);
37846
+ if (!this.content[executed]) {
37847
+ this.content[executed] = new Map();
37848
+ }
37849
+ for (const toTransform of toTransforms) {
37850
+ this.content[executed].set(toTransform, fn);
37767
37851
  }
37768
37852
  return this;
37769
37853
  }
@@ -37772,7 +37856,7 @@ stores.inject(MyMetaStore, storeInstance);
37772
37856
  * that the executed command happened.
37773
37857
  */
37774
37858
  getTransformation(toTransform, executed) {
37775
- return this.content[toTransform] && this.content[toTransform].get(executed);
37859
+ return this.content[executed] && this.content[executed].get(toTransform);
37776
37860
  }
37777
37861
  }
37778
37862
  const otRegistry = new OTRegistry();
@@ -47079,7 +47163,7 @@ stores.inject(MyMetaStore, storeInstance);
47079
47163
  }
47080
47164
  getTypeFromZone(sheetId, zone) {
47081
47165
  const cells = this.getters.getEvaluatedCellsInZone(sheetId, zone);
47082
- const nonEmptyCells = cells.filter((cell) => cell.type !== CellValueType.empty);
47166
+ const nonEmptyCells = cells.filter((cell) => !(cell.type === CellValueType.empty || cell.value === ""));
47083
47167
  if (nonEmptyCells.length === 0) {
47084
47168
  return "integer";
47085
47169
  }
@@ -50629,15 +50713,16 @@ stores.inject(MyMetaStore, storeInstance);
50629
50713
  }
50630
50714
  }
50631
50715
 
50716
+ const PAINT_FORMAT_HANDLER_KEYS = [
50717
+ "cell",
50718
+ "border",
50719
+ "table",
50720
+ "conditionalFormat",
50721
+ "merge",
50722
+ ];
50632
50723
  class PaintFormatStore extends SpreadsheetStore {
50633
50724
  mutators = ["activate", "cancel", "pasteFormat"];
50634
50725
  highlightStore = this.get(HighlightStore);
50635
- clipboardHandlers = [
50636
- new CellClipboardHandler(this.getters, this.model.dispatch),
50637
- new BorderClipboardHandler(this.getters, this.model.dispatch),
50638
- new TableClipboardHandler(this.getters, this.model.dispatch),
50639
- new ConditionalFormatClipboardHandler(this.getters, this.model.dispatch),
50640
- ];
50641
50726
  status = "inactive";
50642
50727
  copiedData;
50643
50728
  constructor(get) {
@@ -50668,24 +50753,38 @@ stores.inject(MyMetaStore, storeInstance);
50668
50753
  get isActive() {
50669
50754
  return this.status !== "inactive";
50670
50755
  }
50756
+ get clipboardHandlers() {
50757
+ return PAINT_FORMAT_HANDLER_KEYS.map((handlerName) => {
50758
+ const HandlerClass = clipboardHandlersRegistries.cellHandlers.get(handlerName);
50759
+ return {
50760
+ handlerName,
50761
+ handler: new HandlerClass(this.getters, this.model.dispatch),
50762
+ };
50763
+ });
50764
+ }
50671
50765
  copyFormats() {
50672
50766
  const sheetId = this.getters.getActiveSheetId();
50673
50767
  const zones = this.getters.getSelectedZones();
50674
- const copiedData = {};
50675
- for (const handler of this.clipboardHandlers) {
50676
- Object.assign(copiedData, handler.copy(getClipboardDataPositions(sheetId, zones)));
50768
+ const copiedData = { zones, sheetId };
50769
+ for (const { handlerName, handler } of this.clipboardHandlers) {
50770
+ const handlerResult = handler.copy(getClipboardDataPositions(sheetId, zones));
50771
+ if (handlerResult !== undefined) {
50772
+ copiedData[handlerName] = handlerResult;
50773
+ }
50677
50774
  }
50678
50775
  return copiedData;
50679
50776
  }
50680
50777
  paintFormat(sheetId, target) {
50681
- if (this.copiedData) {
50682
- for (const handler of this.clipboardHandlers) {
50683
- handler.paste({ zones: target, sheetId }, this.copiedData, {
50684
- isCutOperation: false,
50685
- pasteOption: "onlyFormat",
50686
- });
50687
- }
50778
+ if (!this.copiedData) {
50779
+ return;
50688
50780
  }
50781
+ const options = {
50782
+ isCutOperation: false,
50783
+ pasteOption: "onlyFormat",
50784
+ };
50785
+ const { target: pasteTarget, selectedZones } = getPasteTargetFromHandlers(sheetId, target, this.copiedData, this.clipboardHandlers, options);
50786
+ applyClipboardHandlersPaste(this.clipboardHandlers, this.copiedData, pasteTarget, options);
50787
+ selectPastedZone(this.model.selection, target, selectedZones);
50689
50788
  if (this.status === "oneOff") {
50690
50789
  this.cancel();
50691
50790
  }
@@ -55986,7 +56085,7 @@ stores.inject(MyMetaStore, storeInstance);
55986
56085
  else if (newRule.criterion.type === "isValueInList") {
55987
56086
  newRule.criterion.values = Array.from(new Set(newRule.criterion.values));
55988
56087
  }
55989
- const adaptedRules = this.removeRangesFromRules(sheetId, newRule.ranges, rules);
56088
+ const adaptedRules = this.removeRangesFromRules(sheetId, newRule.ranges, rules, newRule.id);
55990
56089
  const ruleIndex = adaptedRules.findIndex((rule) => rule.id === newRule.id);
55991
56090
  if (ruleIndex !== -1) {
55992
56091
  adaptedRules[ruleIndex] = newRule;
@@ -55996,9 +56095,12 @@ stores.inject(MyMetaStore, storeInstance);
55996
56095
  this.history.update("rules", sheetId, [...adaptedRules, newRule]);
55997
56096
  }
55998
56097
  }
55999
- removeRangesFromRules(sheetId, ranges, rules) {
56098
+ removeRangesFromRules(sheetId, ranges, rules, editingRuleId) {
56000
56099
  rules = deepCopy(rules);
56001
56100
  for (const rule of rules) {
56101
+ if (rule.id === editingRuleId) {
56102
+ continue; // Skip the rule being edited to preserve its place in the list
56103
+ }
56002
56104
  rule.ranges = this.getters.recomputeRanges(rule.ranges, ranges);
56003
56105
  }
56004
56106
  return rules.filter((rule) => rule.ranges.length > 0);
@@ -64766,10 +64868,20 @@ stores.inject(MyMetaStore, storeInstance);
64766
64868
  */
64767
64869
  function transformAll(toTransform, executed) {
64768
64870
  let transformedCommands = [...toTransform];
64871
+ const possibleTransformations = new Set(otRegistry.getKeys());
64769
64872
  for (const executedCommand of executed) {
64770
- transformedCommands = transformedCommands
64771
- .map((cmd) => transform(cmd, executedCommand))
64772
- .filter(isDefined);
64873
+ // If the executed command is not in the registry, we skip it
64874
+ // because we know there won't be any transformation impacting the
64875
+ // commands to transform.
64876
+ if (possibleTransformations.has(executedCommand.type)) {
64877
+ transformedCommands = transformedCommands.reduce((acc, cmd) => {
64878
+ const transformed = transform(cmd, executedCommand);
64879
+ if (transformed) {
64880
+ acc.push(transformed);
64881
+ }
64882
+ return acc;
64883
+ }, []);
64884
+ }
64773
64885
  }
64774
64886
  return transformedCommands;
64775
64887
  }
@@ -66458,7 +66570,7 @@ stores.inject(MyMetaStore, storeInstance);
66458
66570
  }
66459
66571
  const position = this.getters.getCellPosition(cell.id);
66460
66572
  const colSize = this.getters.getColSize(sheetId, position.col);
66461
- if (cell.isFormula) {
66573
+ if (cell.isFormula || this.getters.getArrayFormulaSpreadingOn(position)) {
66462
66574
  const content = this.getters.getEvaluatedCell(position).formattedValue;
66463
66575
  const evaluatedSize = getCellContentHeight(this.ctx, content, cell?.style, colSize);
66464
66576
  if (evaluatedSize > evaluatedRowSize && evaluatedSize > DEFAULT_CELL_HEIGHT) {
@@ -67746,49 +67858,17 @@ stores.inject(MyMetaStore, storeInstance);
67746
67858
  if (!copiedData) {
67747
67859
  return;
67748
67860
  }
67749
- let zone = undefined;
67750
- let selectedZones = [];
67751
67861
  const sheetId = this.getters.getActiveSheetId();
67752
- let target = {
67753
- sheetId,
67754
- zones,
67755
- };
67756
67862
  const handlers = this.selectClipboardHandlers(copiedData);
67757
- for (const { handlerName, handler } of handlers) {
67758
- const handlerData = copiedData[handlerName];
67759
- if (!handlerData) {
67760
- continue;
67761
- }
67762
- const currentTarget = handler.getPasteTarget(sheetId, zones, handlerData, options);
67763
- if (currentTarget.figureId) {
67764
- target.figureId = currentTarget.figureId;
67765
- }
67766
- for (const targetZone of currentTarget.zones) {
67767
- selectedZones.push(targetZone);
67768
- if (zone === undefined) {
67769
- zone = targetZone;
67770
- continue;
67771
- }
67772
- zone = union(zone, targetZone);
67773
- }
67774
- }
67863
+ const { target, zone, selectedZones } = getPasteTargetFromHandlers(sheetId, zones, copiedData, handlers, options);
67775
67864
  if (zone !== undefined) {
67776
- this.addMissingDimensions(this.getters.getActiveSheetId(), zone.right - zone.left + 1, zone.bottom - zone.top + 1, zone.left, zone.top);
67865
+ this.addMissingDimensions(sheetId, zone.right - zone.left + 1, zone.bottom - zone.top + 1, zone.left, zone.top);
67777
67866
  }
67778
- handlers.forEach(({ handlerName, handler }) => {
67779
- const handlerData = copiedData[handlerName];
67780
- if (handlerData) {
67781
- handler.paste(target, handlerData, options);
67782
- }
67783
- });
67867
+ applyClipboardHandlersPaste(handlers, copiedData, target, options);
67784
67868
  if (!options?.selectTarget) {
67785
67869
  return;
67786
67870
  }
67787
- const selection = zones[0];
67788
- const col = selection.left;
67789
- const row = selection.top;
67790
- this.selection.getBackToDefault();
67791
- this.selection.selectZone({ cell: { col, row }, zone: union(...selectedZones) }, { scrollIntoView: false });
67871
+ selectPastedZone(this.selection, zones, selectedZones);
67792
67872
  }
67793
67873
  /**
67794
67874
  * Add columns and/or rows to ensure that col + width and row + height are still
@@ -77014,9 +77094,9 @@ stores.inject(MyMetaStore, storeInstance);
77014
77094
  exports.tokenize = tokenize;
77015
77095
 
77016
77096
 
77017
- __info__.version = "18.2.17";
77018
- __info__.date = "2025-06-12T09:52:15.050Z";
77019
- __info__.hash = "ea64209";
77097
+ __info__.version = "18.2.19";
77098
+ __info__.date = "2025-06-23T15:07:13.023Z";
77099
+ __info__.hash = "430d931";
77020
77100
 
77021
77101
 
77022
77102
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);