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