@odoo/o-spreadsheet 15.0.0 → 15.0.2

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.
@@ -1390,6 +1390,7 @@ exports.CommandResult = void 0;
1390
1390
  CommandResult[CommandResult["FigureDoesNotExist"] = 55] = "FigureDoesNotExist";
1391
1391
  CommandResult[CommandResult["DuplicatedFigureId"] = 56] = "DuplicatedFigureId";
1392
1392
  CommandResult[CommandResult["DuplicatedChartId"] = 57] = "DuplicatedChartId";
1393
+ CommandResult[CommandResult["ChartDoesNotExist"] = 58] = "ChartDoesNotExist";
1393
1394
  })(exports.CommandResult || (exports.CommandResult = {}));
1394
1395
 
1395
1396
  var ReturnFormatType;
@@ -2973,6 +2974,9 @@ function isZoneValid(zone) {
2973
2974
  if (isNaN(zone.bottom) || isNaN(zone.top) || isNaN(zone.left) || isNaN(zone.right)) {
2974
2975
  return false;
2975
2976
  }
2977
+ if (zone.top < 0 || zone.left < 0 || zone.right < 0 || zone.bottom < 0) {
2978
+ return false;
2979
+ }
2976
2980
  return zone.bottom >= zone.top && zone.right >= zone.left;
2977
2981
  }
2978
2982
  /**
@@ -8477,13 +8481,7 @@ function load(data) {
8477
8481
  data = migrate(data);
8478
8482
  }
8479
8483
  }
8480
- // sanity check: try to fix missing fields/corrupted state by providing
8481
- // sensible default values
8482
- data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8483
- data.sheets = data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s));
8484
- if (data.sheets.length === 0) {
8485
- data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8486
- }
8484
+ data = repairData(data);
8487
8485
  return data;
8488
8486
  }
8489
8487
  function migrate(data) {
@@ -8692,6 +8690,48 @@ const MIGRATIONS = [
8692
8690
  },
8693
8691
  },
8694
8692
  ];
8693
+ /**
8694
+ * This function is used to repair faulty data independently of the migration.
8695
+ */
8696
+ function repairData(data) {
8697
+ data = forceUnicityOfFigure(data);
8698
+ data = setDefaults(data);
8699
+ return data;
8700
+ }
8701
+ /**
8702
+ * Force the unicity of figure ids accross sheets
8703
+ */
8704
+ function forceUnicityOfFigure(data) {
8705
+ if (data.uniqueFigureIds) {
8706
+ return data;
8707
+ }
8708
+ const figureIds = new Set();
8709
+ const uuidGenerator = new UuidGenerator();
8710
+ for (const sheet of data.sheets || []) {
8711
+ for (const figure of sheet.figures || []) {
8712
+ if (figureIds.has(figure.id)) {
8713
+ figure.id += uuidGenerator.uuidv4();
8714
+ }
8715
+ figureIds.add(figure.id);
8716
+ }
8717
+ }
8718
+ data.uniqueFigureIds = true;
8719
+ return data;
8720
+ }
8721
+ /**
8722
+ * sanity check: try to fix missing fields/corrupted state by providing
8723
+ * sensible default values
8724
+ */
8725
+ function setDefaults(data) {
8726
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8727
+ data.sheets = data.sheets
8728
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
8729
+ : [];
8730
+ if (data.sheets.length === 0) {
8731
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8732
+ }
8733
+ return data;
8734
+ }
8695
8735
  /**
8696
8736
  * The goal of this function is to repair corrupted/wrong initial messages caused by
8697
8737
  * a bug.
@@ -8778,6 +8818,7 @@ function createEmptyWorkbookData(sheetName = "Sheet1") {
8778
8818
  styles: {},
8779
8819
  borders: {},
8780
8820
  revisionId: DEFAULT_REVISION_ID,
8821
+ uniqueFigureIds: true,
8781
8822
  };
8782
8823
  return data;
8783
8824
  }
@@ -9808,34 +9849,32 @@ class ChartPlugin extends CorePlugin {
9808
9849
  this.chartFigures = {};
9809
9850
  }
9810
9851
  adaptRanges(applyChange) {
9811
- for (const sheetId of Object.keys(this.chartFigures)) {
9812
- for (const [chartId, chart] of Object.entries(this.chartFigures[sheetId] || {})) {
9813
- if (chart) {
9814
- this.adaptDataSetRanges(sheetId, chart, chartId, applyChange);
9815
- this.adaptLabelRanges(sheetId, chart, chartId, applyChange);
9816
- }
9852
+ for (let [chartId, chart] of Object.entries(this.chartFigures)) {
9853
+ if (chart) {
9854
+ this.adaptDataSetRanges(chart, chartId, applyChange);
9855
+ this.adaptLabelRanges(chart, chartId, applyChange);
9817
9856
  }
9818
9857
  }
9819
9858
  }
9820
- adaptDataSetRanges(sheetId, chart, chartId, applyChange) {
9859
+ adaptDataSetRanges(chart, chartId, applyChange) {
9821
9860
  for (let ds of chart.dataSets) {
9822
9861
  if (ds.labelCell) {
9823
9862
  const labelCellChange = applyChange(ds.labelCell);
9824
9863
  switch (labelCellChange.changeType) {
9825
9864
  case "REMOVE":
9826
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9865
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9827
9866
  break;
9828
9867
  case "RESIZE":
9829
9868
  case "MOVE":
9830
9869
  case "CHANGE":
9831
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9870
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9832
9871
  }
9833
9872
  }
9834
9873
  const dataRangeChange = applyChange(ds.dataRange);
9835
9874
  switch (dataRangeChange.changeType) {
9836
9875
  case "REMOVE":
9837
9876
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9838
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9877
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9839
9878
  break;
9840
9879
  case "RESIZE":
9841
9880
  case "MOVE":
@@ -9843,27 +9882,27 @@ class ChartPlugin extends CorePlugin {
9843
9882
  // We have to remove the ranges that are #REF
9844
9883
  if (this.getters.getRangeString(dataRangeChange.range, dataRangeChange.range.sheetId) !==
9845
9884
  INCORRECT_RANGE_STRING) {
9846
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9885
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9847
9886
  }
9848
9887
  else {
9849
9888
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9850
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9889
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9851
9890
  }
9852
9891
  break;
9853
9892
  }
9854
9893
  }
9855
9894
  }
9856
- adaptLabelRanges(sheetId, chart, chartId, applyChange) {
9895
+ adaptLabelRanges(chart, chartId, applyChange) {
9857
9896
  if (chart.labelRange) {
9858
9897
  const labelRangeChange = applyChange(chart.labelRange);
9859
9898
  switch (labelRangeChange.changeType) {
9860
9899
  case "REMOVE":
9861
- this.history.update("chartFigures", sheetId, chartId, "labelRange", undefined);
9900
+ this.history.update("chartFigures", chartId, "labelRange", undefined);
9862
9901
  break;
9863
9902
  case "RESIZE":
9864
9903
  case "MOVE":
9865
9904
  case "CHANGE":
9866
- this.history.update("chartFigures", sheetId, chartId, "labelRange", labelRangeChange.range);
9905
+ this.history.update("chartFigures", chartId, "labelRange", labelRangeChange.range);
9867
9906
  break;
9868
9907
  }
9869
9908
  }
@@ -9874,16 +9913,16 @@ class ChartPlugin extends CorePlugin {
9874
9913
  allowDispatch(cmd) {
9875
9914
  const success = 0 /* Success */;
9876
9915
  switch (cmd.type) {
9877
- case "CREATE_CHART":
9878
- return this.checkValidations(cmd, this.chainValidations(this.checkChartDuplicate, this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9879
9916
  case "UPDATE_CHART":
9880
- return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9917
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartExists), this.checkLabelRange);
9918
+ case "CREATE_CHART":
9919
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartDuplicate), this.checkLabelRange);
9881
9920
  default:
9882
9921
  return success;
9883
9922
  }
9884
9923
  }
9885
9924
  handle(cmd) {
9886
- var _a;
9925
+ var _a, _b;
9887
9926
  switch (cmd.type) {
9888
9927
  case "CREATE_CHART":
9889
9928
  const x = cmd.position ? cmd.position.x : 0;
@@ -9898,7 +9937,7 @@ class ChartPlugin extends CorePlugin {
9898
9937
  });
9899
9938
  break;
9900
9939
  case "UPDATE_CHART": {
9901
- this.updateChartDefinition(cmd.sheetId, cmd.id, cmd.definition);
9940
+ this.updateChartDefinition(cmd.id, cmd.definition);
9902
9941
  break;
9903
9942
  }
9904
9943
  case "DUPLICATE_SHEET": {
@@ -9908,7 +9947,7 @@ class ChartPlugin extends CorePlugin {
9908
9947
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
9909
9948
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
9910
9949
  const chartDefinition = {
9911
- ...deepCopy(this.chartFigures[cmd.sheetId][fig.id]),
9950
+ ...deepCopy(this.chartFigures[fig.id]),
9912
9951
  id: duplicatedFigureId,
9913
9952
  };
9914
9953
  chartDefinition.sheetId = cmd.sheetIdTo;
@@ -9938,28 +9977,37 @@ class ChartPlugin extends CorePlugin {
9938
9977
  break;
9939
9978
  }
9940
9979
  case "DELETE_FIGURE":
9941
- this.history.update("chartFigures", cmd.sheetId, cmd.id, undefined);
9980
+ this.history.update("chartFigures", cmd.id, undefined);
9942
9981
  break;
9943
9982
  case "DELETE_SHEET":
9944
- this.history.update("chartFigures", cmd.sheetId, undefined);
9983
+ for (let id of Object.keys(this.chartFigures)) {
9984
+ if (((_b = this.chartFigures[id]) === null || _b === void 0 ? void 0 : _b.sheetId) === cmd.sheetId) {
9985
+ this.history.update("chartFigures", id, undefined);
9986
+ }
9987
+ }
9945
9988
  break;
9946
9989
  }
9947
9990
  }
9948
9991
  // ---------------------------------------------------------------------------
9949
9992
  // Getters
9950
9993
  // ---------------------------------------------------------------------------
9951
- getChartDefinition(sheetId, figureId) {
9952
- var _a;
9953
- return (_a = this.chartFigures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
9994
+ getChartDefinition(figureId) {
9995
+ return this.chartFigures[figureId];
9954
9996
  }
9955
- getChartDefinitionsBySheet(sheetId) {
9956
- return Object.values(this.chartFigures[sheetId] || {}).filter(isDefined);
9997
+ getChartsIdBySheet(sheetId) {
9998
+ return Object.entries(this.chartFigures)
9999
+ .filter((chart) => {
10000
+ return chart[1].sheetId === sheetId;
10001
+ })
10002
+ .map((chart) => chart[0]);
9957
10003
  }
9958
- getChartDefinitionUI(sheetId, figureId, forceSheetName = false) {
9959
- const data = this.chartFigures[sheetId][figureId];
9960
- const rangeSheetId = forceSheetName ? "forceSheetReference" : sheetId;
10004
+ getChartDefinitionUI(sheetId, figureId) {
10005
+ const data = this.chartFigures[figureId];
10006
+ if (!data) {
10007
+ return undefined;
10008
+ }
9961
10009
  const dataSets = data.dataSets
9962
- .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, rangeSheetId) : ""))
10010
+ .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, sheetId) : ""))
9963
10011
  .filter((ds) => {
9964
10012
  return ds !== ""; // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9965
10013
  });
@@ -9967,7 +10015,7 @@ class ChartPlugin extends CorePlugin {
9967
10015
  title: data && data.title ? data.title : "",
9968
10016
  dataSets,
9969
10017
  labelRange: data.labelRange
9970
- ? this.getters.getRangeString(data.labelRange, rangeSheetId)
10018
+ ? this.getters.getRangeString(data.labelRange, sheetId)
9971
10019
  : undefined,
9972
10020
  type: data ? data.type : "bar",
9973
10021
  dataSetsHaveTitle: data && dataSets.length !== 0 ? Boolean(data.dataSets[0].labelCell) : false,
@@ -9978,12 +10026,16 @@ class ChartPlugin extends CorePlugin {
9978
10026
  };
9979
10027
  }
9980
10028
  getChartDefinitionExcel(sheetId, figureId) {
9981
- const data = this.chartFigures[sheetId][figureId];
10029
+ const data = this.chartFigures[figureId];
10030
+ const dataUI = this.getChartDefinitionUI("forceSheetReference", figureId);
10031
+ if (!data || !dataUI) {
10032
+ return undefined;
10033
+ }
9982
10034
  const dataSets = data.dataSets
9983
10035
  .map((ds) => this.toExcelDataset(ds))
9984
10036
  .filter((ds) => ds.range !== ""); // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9985
10037
  return {
9986
- ...this.getChartDefinitionUI(sheetId, figureId, true),
10038
+ ...dataUI,
9987
10039
  backgroundColor: data.background,
9988
10040
  dataSets,
9989
10041
  };
@@ -10018,17 +10070,15 @@ class ChartPlugin extends CorePlugin {
10018
10070
  import(data) {
10019
10071
  for (let sheet of data.sheets) {
10020
10072
  if (sheet.figures) {
10021
- const charts = {};
10022
10073
  for (let figure of sheet.figures) {
10023
10074
  if (figure.tag === "chart") {
10024
10075
  const figureData = {
10025
10076
  ...figure.data,
10026
10077
  };
10027
- charts[figure.id] = this.createChartDefinition(figureData, sheet.id);
10078
+ this.chartFigures[figure.id] = this.createChartDefinition(figureData, sheet.id);
10028
10079
  delete figure.data;
10029
10080
  }
10030
10081
  }
10031
- this.chartFigures[sheet.id] = charts;
10032
10082
  }
10033
10083
  }
10034
10084
  }
@@ -10036,10 +10086,18 @@ class ChartPlugin extends CorePlugin {
10036
10086
  if (data.sheets) {
10037
10087
  for (let sheet of data.sheets) {
10038
10088
  const sheetFigures = this.getters.getFigures(sheet.id);
10039
- const figures = sheetFigures;
10040
- for (let figure of figures) {
10089
+ const figures = [];
10090
+ for (let sheetFigure of sheetFigures) {
10091
+ const figure = sheetFigure;
10041
10092
  if (figure && figure.tag === "chart") {
10042
- figure.data = this.getChartDefinitionUI(sheet.id, figure.id);
10093
+ const data = this.getChartDefinitionUI(sheet.id, figure.id);
10094
+ if (data) {
10095
+ figure.data = data;
10096
+ figures.push(figure);
10097
+ }
10098
+ }
10099
+ else {
10100
+ figures.push(figure);
10043
10101
  }
10044
10102
  }
10045
10103
  sheet.figures = figures;
@@ -10049,10 +10107,18 @@ class ChartPlugin extends CorePlugin {
10049
10107
  exportForExcel(data) {
10050
10108
  for (let sheet of data.sheets) {
10051
10109
  const sheetFigures = this.getters.getFigures(sheet.id);
10052
- const figures = sheetFigures;
10053
- for (let figure of figures) {
10110
+ const figures = [];
10111
+ for (let sheetFigure of sheetFigures) {
10112
+ const figure = sheetFigure;
10054
10113
  if (figure && figure.tag === "chart") {
10055
- figure.data = this.getChartDefinitionExcel(sheet.id, figure.id);
10114
+ const data = this.getChartDefinitionExcel(sheet.id, figure.id);
10115
+ if (data) {
10116
+ figure.data = data;
10117
+ figures.push(figure);
10118
+ }
10119
+ }
10120
+ else {
10121
+ figures.push(figure);
10056
10122
  }
10057
10123
  }
10058
10124
  sheet.charts = figures;
@@ -10078,39 +10144,39 @@ class ChartPlugin extends CorePlugin {
10078
10144
  * Update the chart definition linked to the given id with the attributes
10079
10145
  * given in the partial UI definition
10080
10146
  */
10081
- updateChartDefinition(sheetId, id, definition) {
10082
- const chart = this.chartFigures[sheetId][id];
10147
+ updateChartDefinition(id, definition) {
10148
+ const chart = this.chartFigures[id];
10083
10149
  if (!chart) {
10084
10150
  throw new Error(`There is no chart with the given id: ${id}`);
10085
10151
  }
10086
10152
  if (definition.title !== undefined) {
10087
- this.history.update("chartFigures", sheetId, id, "title", definition.title);
10153
+ this.history.update("chartFigures", id, "title", definition.title);
10088
10154
  }
10089
10155
  if (definition.type) {
10090
- this.history.update("chartFigures", sheetId, id, "type", definition.type);
10156
+ this.history.update("chartFigures", id, "type", definition.type);
10091
10157
  }
10092
10158
  if (definition.dataSets) {
10093
10159
  const dataSetsHaveTitle = !!definition.dataSetsHaveTitle;
10094
10160
  const dataSets = this.createDataSets(definition.dataSets, chart.sheetId, dataSetsHaveTitle);
10095
- this.history.update("chartFigures", sheetId, id, "dataSets", dataSets);
10161
+ this.history.update("chartFigures", id, "dataSets", dataSets);
10096
10162
  }
10097
10163
  if (definition.labelRange !== undefined) {
10098
10164
  const labelRange = definition.labelRange
10099
10165
  ? this.getters.getRangeFromSheetXC(chart.sheetId, definition.labelRange)
10100
10166
  : undefined;
10101
- this.history.update("chartFigures", sheetId, id, "labelRange", labelRange);
10167
+ this.history.update("chartFigures", id, "labelRange", labelRange);
10102
10168
  }
10103
10169
  if (definition.background) {
10104
- this.history.update("chartFigures", sheetId, id, "background", definition.background);
10170
+ this.history.update("chartFigures", id, "background", definition.background);
10105
10171
  }
10106
10172
  if (definition.verticalAxisPosition) {
10107
- this.history.update("chartFigures", sheetId, id, "verticalAxisPosition", definition.verticalAxisPosition);
10173
+ this.history.update("chartFigures", id, "verticalAxisPosition", definition.verticalAxisPosition);
10108
10174
  }
10109
10175
  if (definition.legendPosition) {
10110
- this.history.update("chartFigures", sheetId, id, "legendPosition", definition.legendPosition);
10176
+ this.history.update("chartFigures", id, "legendPosition", definition.legendPosition);
10111
10177
  }
10112
10178
  if (definition.stackedBar !== undefined) {
10113
- this.history.update("chartFigures", sheetId, id, "stackedBar", definition.stackedBar);
10179
+ this.history.update("chartFigures", id, "stackedBar", definition.stackedBar);
10114
10180
  }
10115
10181
  }
10116
10182
  createDataSets(dataSetsString, sheetId, dataSetsHaveTitle) {
@@ -10165,7 +10231,7 @@ class ChartPlugin extends CorePlugin {
10165
10231
  sheetId,
10166
10232
  figure,
10167
10233
  });
10168
- this.history.update("chartFigures", sheetId, figure.id, data);
10234
+ this.history.update("chartFigures", figure.id, data);
10169
10235
  }
10170
10236
  createDataSet(sheetId, fullZone, titleZone) {
10171
10237
  if (fullZone.left !== fullZone.right && fullZone.top !== fullZone.bottom) {
@@ -10206,14 +10272,20 @@ class ChartPlugin extends CorePlugin {
10206
10272
  return invalidLabels ? 29 /* InvalidLabelRange */ : 0 /* Success */;
10207
10273
  }
10208
10274
  checkChartDuplicate(cmd) {
10209
- var _a;
10210
- if ((_a = this.chartFigures[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[cmd.id]) {
10211
- return 57 /* DuplicatedChartId */;
10275
+ for (const sheet of this.getters.getSheets()) {
10276
+ if (this.getters.getFigure(sheet.id, cmd.id)) {
10277
+ return 57 /* DuplicatedChartId */;
10278
+ }
10212
10279
  }
10213
10280
  return 0 /* Success */;
10214
10281
  }
10282
+ checkChartExists(cmd) {
10283
+ return this.getters.getFigure(cmd.sheetId, cmd.id)
10284
+ ? 0 /* Success */
10285
+ : 58 /* ChartDoesNotExist */;
10286
+ }
10215
10287
  }
10216
- ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartDefinitionsBySheet"];
10288
+ ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartsIdBySheet"];
10217
10289
 
10218
10290
  // -----------------------------------------------------------------------------
10219
10291
  // Constants
@@ -10552,7 +10624,7 @@ class FigurePlugin extends CorePlugin {
10552
10624
  allowDispatch(cmd) {
10553
10625
  switch (cmd.type) {
10554
10626
  case "CREATE_FIGURE":
10555
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
10627
+ return this.checkFigureDuplicate(cmd.figure.id);
10556
10628
  case "UPDATE_FIGURE":
10557
10629
  case "DELETE_FIGURE":
10558
10630
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -10618,9 +10690,8 @@ class FigurePlugin extends CorePlugin {
10618
10690
  }
10619
10691
  return 0 /* Success */;
10620
10692
  }
10621
- checkFigureDuplicate(sheetId, figureId) {
10622
- var _a;
10623
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
10693
+ checkFigureDuplicate(figureId) {
10694
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
10624
10695
  return 56 /* DuplicatedFigureId */;
10625
10696
  }
10626
10697
  return 0 /* Success */;
@@ -10635,6 +10706,9 @@ class FigurePlugin extends CorePlugin {
10635
10706
  var _a;
10636
10707
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
10637
10708
  }
10709
+ getFigureSheetId(figureId) {
10710
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
10711
+ }
10638
10712
  // ---------------------------------------------------------------------------
10639
10713
  // Import/Export
10640
10714
  // ---------------------------------------------------------------------------
@@ -10659,7 +10733,7 @@ class FigurePlugin extends CorePlugin {
10659
10733
  this.export(data);
10660
10734
  }
10661
10735
  }
10662
- FigurePlugin.getters = ["getFigures", "getFigure"];
10736
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
10663
10737
 
10664
10738
  class MergePlugin extends CorePlugin {
10665
10739
  constructor() {
@@ -12821,7 +12895,7 @@ const CREATE_CHART = (env) => {
12821
12895
  },
12822
12896
  });
12823
12897
  const figure = env.getters.getFigure(sheetId, id);
12824
- env.openSidePanel("ChartPanel", { sheetId, figure });
12898
+ env.openSidePanel("ChartPanel", { figure });
12825
12899
  };
12826
12900
  //------------------------------------------------------------------------------
12827
12901
  // Style/Format
@@ -14318,19 +14392,21 @@ class ChartPanel extends owl.Component {
14318
14392
  constructor() {
14319
14393
  super(...arguments);
14320
14394
  this.getters = this.env.getters;
14395
+ this.chartSheetId = this.findSheetId(this.props.figure.id);
14321
14396
  this.state = owl.useState(this.initialState(this.props.figure));
14322
14397
  }
14323
14398
  async willUpdateProps(nextProps) {
14324
- if (!this.getters.getChartDefinition(nextProps.sheetId, nextProps.figure.id)) {
14399
+ if (!this.getters.getChartDefinition(nextProps.figure.id)) {
14325
14400
  this.trigger("close-side-panel");
14326
14401
  return;
14327
14402
  }
14328
14403
  if (nextProps.figure.id !== this.props.figure.id) {
14404
+ this.chartSheetId = this.findSheetId(nextProps.figure.id);
14329
14405
  this.state.panel = "configuration";
14330
14406
  this.state.fillColorTool = false;
14331
14407
  this.state.datasetDispatchResult = undefined;
14332
14408
  this.state.labelsDispatchResult = undefined;
14333
- this.state.chart = this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), nextProps.figure.id);
14409
+ this.state.chart = this.env.getters.getChartDefinitionUI(this.chartSheetId, nextProps.figure.id);
14334
14410
  }
14335
14411
  }
14336
14412
  get errorMessages() {
@@ -14377,7 +14453,7 @@ class ChartPanel extends owl.Component {
14377
14453
  updateChart(definition) {
14378
14454
  return this.env.dispatch("UPDATE_CHART", {
14379
14455
  id: this.props.figure.id,
14380
- sheetId: this.props.sheetId,
14456
+ sheetId: this.chartSheetId,
14381
14457
  definition,
14382
14458
  });
14383
14459
  }
@@ -14399,12 +14475,16 @@ class ChartPanel extends owl.Component {
14399
14475
  this.state.panel = panel;
14400
14476
  }
14401
14477
  initialState(figure) {
14478
+ const sheetId = this.findSheetId(figure.id);
14402
14479
  return {
14403
- chart: this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), figure.id),
14480
+ chart: this.env.getters.getChartDefinitionUI(sheetId, figure.id),
14404
14481
  panel: "configuration",
14405
14482
  fillColorTool: false,
14406
14483
  };
14407
14484
  }
14485
+ findSheetId(figureId) {
14486
+ return this.env.getters.getFigureSheetId(figureId) || "";
14487
+ }
14408
14488
  }
14409
14489
  ChartPanel.template = TEMPLATE$p;
14410
14490
  ChartPanel.style = STYLE;
@@ -18818,60 +18898,51 @@ class EvaluationChartPlugin extends UIPlugin {
18818
18898
  this.outOfDate = new Set();
18819
18899
  }
18820
18900
  handle(cmd) {
18821
- var _a;
18822
18901
  if (invalidateEvaluationCommands.has(cmd.type) ||
18823
18902
  cmd.type === "EVALUATE_CELLS" ||
18824
18903
  (cmd.type === "UPDATE_CELL" && "content" in cmd)) {
18825
- for (const sheetId of Object.keys(this.chartRuntime)) {
18826
- for (const chartId of Object.keys(this.chartRuntime[sheetId] || {})) {
18827
- this.outOfDate.add(chartId);
18828
- }
18904
+ for (let chartId of Object.keys(this.chartRuntime)) {
18905
+ this.outOfDate.add(chartId);
18829
18906
  }
18830
18907
  }
18831
18908
  switch (cmd.type) {
18832
18909
  case "UPDATE_CHART":
18833
- case "CREATE_CHART": {
18834
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18835
- if (!this.chartRuntime[cmd.sheetId])
18836
- this.chartRuntime[cmd.sheetId] = {};
18837
- this.chartRuntime[cmd.sheetId][cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18910
+ case "CREATE_CHART":
18911
+ const chartDefinition = this.getters.getChartDefinition(cmd.id);
18912
+ this.chartRuntime[cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18838
18913
  break;
18839
- }
18840
18914
  case "DELETE_FIGURE":
18841
- (_a = this.chartRuntime[cmd.sheetId]) === null || _a === void 0 ? true : delete _a[cmd.id];
18915
+ delete this.chartRuntime[cmd.id];
18842
18916
  break;
18843
- case "REFRESH_CHART": {
18844
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18845
- this.evaluateUsedSheets([chartDefinition]);
18917
+ case "REFRESH_CHART":
18918
+ this.evaluateUsedSheets([cmd.id]);
18846
18919
  this.outOfDate.add(cmd.id);
18847
18920
  break;
18848
- }
18849
- case "ACTIVATE_SHEET": {
18850
- const chartsDefinitions = this.getters.getChartDefinitionsBySheet(cmd.sheetIdTo);
18851
- this.evaluateUsedSheets(chartsDefinitions);
18921
+ case "ACTIVATE_SHEET":
18922
+ const chartsIds = this.getters.getChartsIdBySheet(cmd.sheetIdTo);
18923
+ this.evaluateUsedSheets(chartsIds);
18852
18924
  break;
18853
- }
18854
18925
  case "DELETE_SHEET":
18855
- delete this.chartRuntime[cmd.sheetId];
18926
+ for (let chartId of Object.keys(this.chartRuntime)) {
18927
+ if (!this.getters.getChartDefinition(chartId)) {
18928
+ delete this.chartRuntime[chartId];
18929
+ }
18930
+ }
18856
18931
  break;
18857
18932
  }
18858
18933
  }
18859
18934
  // ---------------------------------------------------------------------------
18860
18935
  // Getters
18861
18936
  // ---------------------------------------------------------------------------
18862
- getChartRuntime(sheetId, figureId) {
18863
- if (this.outOfDate.has(figureId) ||
18864
- !(sheetId in this.chartRuntime) ||
18865
- !(figureId in this.chartRuntime[sheetId])) {
18866
- const chartDefinition = this.getters.getChartDefinition(sheetId, figureId);
18937
+ getChartRuntime(figureId) {
18938
+ if (this.outOfDate.has(figureId) || !(figureId in this.chartRuntime)) {
18939
+ const chartDefinition = this.getters.getChartDefinition(figureId);
18867
18940
  if (chartDefinition === undefined)
18868
18941
  return;
18869
- if (!this.chartRuntime[sheetId])
18870
- this.chartRuntime[sheetId] = {};
18871
- this.chartRuntime[sheetId][figureId] = this.mapDefinitionToRuntime(chartDefinition);
18942
+ this.chartRuntime[figureId] = this.mapDefinitionToRuntime(chartDefinition);
18872
18943
  this.outOfDate.delete(figureId);
18873
18944
  }
18874
- return this.chartRuntime[sheetId][figureId];
18945
+ return this.chartRuntime[figureId];
18875
18946
  }
18876
18947
  truncateLabel(label) {
18877
18948
  if (!label) {
@@ -18976,9 +19047,10 @@ class EvaluationChartPlugin extends UIPlugin {
18976
19047
  }
18977
19048
  return sheetIds;
18978
19049
  }
18979
- evaluateUsedSheets(chartsDefinitions) {
19050
+ evaluateUsedSheets(chartsIds) {
18980
19051
  const usedSheetsId = new Set();
18981
- for (const chartDefinition of chartsDefinitions) {
19052
+ for (let chartId of chartsIds) {
19053
+ const chartDefinition = this.getters.getChartDefinition(chartId);
18982
19054
  const sheetsIds = chartDefinition !== undefined ? this.getSheetIdsUsedInChart(chartDefinition) : [];
18983
19055
  sheetsIds.forEach((sheetId) => {
18984
19056
  if (sheetId !== this.getters.getActiveSheetId()) {
@@ -23529,6 +23601,7 @@ class RangeAdapter {
23529
23601
  }
23530
23602
  else if (range.zone[start] >= min && range.zone[end] <= max) {
23531
23603
  changeType = "REMOVE";
23604
+ newRange = this.buildInvalidRange(INCORRECT_RANGE_STRING);
23532
23605
  }
23533
23606
  else if (range.zone[start] <= max && range.zone[end] >= max) {
23534
23607
  const toRemove = max - range.zone[start] + 1;
@@ -23594,10 +23667,8 @@ class RangeAdapter {
23594
23667
  return { changeType: "NONE" };
23595
23668
  }
23596
23669
  range = {
23597
- ...range,
23598
- zone: { ...range.zone },
23670
+ ...this.buildInvalidRange(INCORRECT_RANGE_STRING),
23599
23671
  invalidSheetName: this.getters.getSheetName(cmd.sheetId),
23600
- sheetId: "",
23601
23672
  };
23602
23673
  return { changeType: "REMOVE", range };
23603
23674
  }, cmd.sheetId);
@@ -26066,7 +26137,7 @@ const { Portal } = owl.misc;
26066
26137
  const { xml: xml$l } = owl.tags;
26067
26138
  const TEMPLATE$j = xml$l /* xml */ `
26068
26139
  <Portal target="'.o-spreadsheet'">
26069
- <div t-att-style="style">
26140
+ <div class="o-popover" t-att-style="style">
26070
26141
  <t t-slot="default"/>
26071
26142
  </div>
26072
26143
  </Portal>
@@ -27248,7 +27319,7 @@ const CSS$b = css$d /* scss */ `
27248
27319
  padding: 0;
27249
27320
  margin: 0;
27250
27321
  border: 0;
27251
- z-index: 5;
27322
+ z-index: 6;
27252
27323
  flex-grow: 1;
27253
27324
  max-height: inherit;
27254
27325
  .o-composer {
@@ -27819,6 +27890,10 @@ const CSS$9 = css$b /* scss */ `
27819
27890
  border-left: 3px solid red;
27820
27891
  padding: 10px;
27821
27892
  }
27893
+
27894
+ .o-popover:has(.o-error-tooltip) {
27895
+ z-index: 4 !important;
27896
+ }
27822
27897
  `;
27823
27898
  class ErrorToolTip extends owl.Component {
27824
27899
  }
@@ -27875,7 +27950,7 @@ class ChartFigure extends owl.Component {
27875
27950
  }
27876
27951
  mounted() {
27877
27952
  const figure = this.props.figure;
27878
- const chartData = this.env.getters.getChartRuntime(this.env.getters.getActiveSheetId(), figure.id);
27953
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27879
27954
  if (chartData) {
27880
27955
  this.createChart(chartData);
27881
27956
  }
@@ -27883,8 +27958,7 @@ class ChartFigure extends owl.Component {
27883
27958
  patched() {
27884
27959
  var _a, _b, _c;
27885
27960
  const figure = this.props.figure;
27886
- const sheetId = this.env.getters.getActiveSheetId();
27887
- const chartData = this.env.getters.getChartRuntime(sheetId, figure.id);
27961
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27888
27962
  if (chartData) {
27889
27963
  if (chartData.type !== this.chart.config.type) {
27890
27964
  // Updating a chart type requires to update its options accordingly, if feasible at all.
@@ -27910,7 +27984,7 @@ class ChartFigure extends owl.Component {
27910
27984
  else {
27911
27985
  this.chart && this.chart.destroy();
27912
27986
  }
27913
- const def = this.env.getters.getChartDefinition(sheetId, figure.id);
27987
+ const def = this.env.getters.getChartDefinition(figure.id);
27914
27988
  if (def) {
27915
27989
  this.state.background = def.background;
27916
27990
  }
@@ -27919,7 +27993,7 @@ class ChartFigure extends owl.Component {
27919
27993
  const canvas = this.canvas.el;
27920
27994
  const ctx = canvas.getContext("2d");
27921
27995
  this.chart = new window.Chart(ctx, chartData);
27922
- const def = this.env.getters.getChartDefinition(this.env.getters.getActiveSheetId(), this.props.figure.id);
27996
+ const def = this.env.getters.getChartDefinition(this.props.figure.id);
27923
27997
  if (def) {
27924
27998
  this.state.background = def.background;
27925
27999
  }
@@ -27929,10 +28003,8 @@ class ChartFigure extends owl.Component {
27929
28003
  registry.add("edit", {
27930
28004
  name: _lt("Edit"),
27931
28005
  sequence: 1,
27932
- action: () => this.env.openSidePanel("ChartPanel", {
27933
- sheetId: this.env.getters.getActiveSheetId(),
27934
- figure: this.props.figure,
27935
- }),
28006
+ action: () => this.env.openSidePanel("ChartPanel", { figure: this.props.figure }),
28007
+ isVisible: () => !!this.env.getters.getChartDefinition(this.props.figure.id),
27936
28008
  });
27937
28009
  registry.add("delete", {
27938
28010
  name: _lt("Delete"),
@@ -27943,10 +28015,7 @@ class ChartFigure extends owl.Component {
27943
28015
  id: this.props.figure.id,
27944
28016
  });
27945
28017
  if (this.props.sidePanelIsOpen) {
27946
- this.env.toggleSidePanel("ChartPanel", {
27947
- sheetId: this.env.getters.getActiveSheetId(),
27948
- figure: this.props.figure,
27949
- });
28018
+ this.env.toggleSidePanel("ChartPanel", { figure: this.props.figure });
27950
28019
  }
27951
28020
  this.trigger("figure-deleted");
27952
28021
  },
@@ -27956,7 +28025,6 @@ class ChartFigure extends owl.Component {
27956
28025
  sequence: 11,
27957
28026
  action: () => {
27958
28027
  this.env.dispatch("REFRESH_CHART", {
27959
- sheetId: this.env.getters.getActiveSheetId(),
27960
28028
  id: this.props.figure.id,
27961
28029
  });
27962
28030
  },
@@ -28200,10 +28268,7 @@ class FiguresContainer extends owl.Component {
28200
28268
  return;
28201
28269
  }
28202
28270
  if (this.props.sidePanelIsOpen) {
28203
- this.env.openSidePanel("ChartPanel", {
28204
- sheetId: this.env.getters.getActiveSheetId(),
28205
- figure,
28206
- });
28271
+ this.env.openSidePanel("ChartPanel", { figure });
28207
28272
  }
28208
28273
  const initialX = ev.clientX;
28209
28274
  const initialY = ev.clientY;
@@ -31297,6 +31362,6 @@ exports.registries = registries;
31297
31362
  exports.setTranslationMethod = setTranslationMethod;
31298
31363
 
31299
31364
 
31300
- __info__.version = '15.0.0';
31301
- __info__.date = '2023-02-27T14:03:17.561Z';
31302
- __info__.hash = '2d1cea1';
31365
+ __info__.version = '15.0.2';
31366
+ __info__.date = '2023-03-14T09:19:34.555Z';
31367
+ __info__.hash = 'c0a25a0';