@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.
@@ -1367,6 +1367,7 @@ var CommandResult;
1367
1367
  CommandResult[CommandResult["FigureDoesNotExist"] = 55] = "FigureDoesNotExist";
1368
1368
  CommandResult[CommandResult["DuplicatedFigureId"] = 56] = "DuplicatedFigureId";
1369
1369
  CommandResult[CommandResult["DuplicatedChartId"] = 57] = "DuplicatedChartId";
1370
+ CommandResult[CommandResult["ChartDoesNotExist"] = 58] = "ChartDoesNotExist";
1370
1371
  })(CommandResult || (CommandResult = {}));
1371
1372
 
1372
1373
  var ReturnFormatType;
@@ -2950,6 +2951,9 @@ function isZoneValid(zone) {
2950
2951
  if (isNaN(zone.bottom) || isNaN(zone.top) || isNaN(zone.left) || isNaN(zone.right)) {
2951
2952
  return false;
2952
2953
  }
2954
+ if (zone.top < 0 || zone.left < 0 || zone.right < 0 || zone.bottom < 0) {
2955
+ return false;
2956
+ }
2953
2957
  return zone.bottom >= zone.top && zone.right >= zone.left;
2954
2958
  }
2955
2959
  /**
@@ -8454,13 +8458,7 @@ function load(data) {
8454
8458
  data = migrate(data);
8455
8459
  }
8456
8460
  }
8457
- // sanity check: try to fix missing fields/corrupted state by providing
8458
- // sensible default values
8459
- data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8460
- data.sheets = data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s));
8461
- if (data.sheets.length === 0) {
8462
- data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8463
- }
8461
+ data = repairData(data);
8464
8462
  return data;
8465
8463
  }
8466
8464
  function migrate(data) {
@@ -8669,6 +8667,48 @@ const MIGRATIONS = [
8669
8667
  },
8670
8668
  },
8671
8669
  ];
8670
+ /**
8671
+ * This function is used to repair faulty data independently of the migration.
8672
+ */
8673
+ function repairData(data) {
8674
+ data = forceUnicityOfFigure(data);
8675
+ data = setDefaults(data);
8676
+ return data;
8677
+ }
8678
+ /**
8679
+ * Force the unicity of figure ids accross sheets
8680
+ */
8681
+ function forceUnicityOfFigure(data) {
8682
+ if (data.uniqueFigureIds) {
8683
+ return data;
8684
+ }
8685
+ const figureIds = new Set();
8686
+ const uuidGenerator = new UuidGenerator();
8687
+ for (const sheet of data.sheets || []) {
8688
+ for (const figure of sheet.figures || []) {
8689
+ if (figureIds.has(figure.id)) {
8690
+ figure.id += uuidGenerator.uuidv4();
8691
+ }
8692
+ figureIds.add(figure.id);
8693
+ }
8694
+ }
8695
+ data.uniqueFigureIds = true;
8696
+ return data;
8697
+ }
8698
+ /**
8699
+ * sanity check: try to fix missing fields/corrupted state by providing
8700
+ * sensible default values
8701
+ */
8702
+ function setDefaults(data) {
8703
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8704
+ data.sheets = data.sheets
8705
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
8706
+ : [];
8707
+ if (data.sheets.length === 0) {
8708
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8709
+ }
8710
+ return data;
8711
+ }
8672
8712
  /**
8673
8713
  * The goal of this function is to repair corrupted/wrong initial messages caused by
8674
8714
  * a bug.
@@ -8755,6 +8795,7 @@ function createEmptyWorkbookData(sheetName = "Sheet1") {
8755
8795
  styles: {},
8756
8796
  borders: {},
8757
8797
  revisionId: DEFAULT_REVISION_ID,
8798
+ uniqueFigureIds: true,
8758
8799
  };
8759
8800
  return data;
8760
8801
  }
@@ -9785,34 +9826,32 @@ class ChartPlugin extends CorePlugin {
9785
9826
  this.chartFigures = {};
9786
9827
  }
9787
9828
  adaptRanges(applyChange) {
9788
- for (const sheetId of Object.keys(this.chartFigures)) {
9789
- for (const [chartId, chart] of Object.entries(this.chartFigures[sheetId] || {})) {
9790
- if (chart) {
9791
- this.adaptDataSetRanges(sheetId, chart, chartId, applyChange);
9792
- this.adaptLabelRanges(sheetId, chart, chartId, applyChange);
9793
- }
9829
+ for (let [chartId, chart] of Object.entries(this.chartFigures)) {
9830
+ if (chart) {
9831
+ this.adaptDataSetRanges(chart, chartId, applyChange);
9832
+ this.adaptLabelRanges(chart, chartId, applyChange);
9794
9833
  }
9795
9834
  }
9796
9835
  }
9797
- adaptDataSetRanges(sheetId, chart, chartId, applyChange) {
9836
+ adaptDataSetRanges(chart, chartId, applyChange) {
9798
9837
  for (let ds of chart.dataSets) {
9799
9838
  if (ds.labelCell) {
9800
9839
  const labelCellChange = applyChange(ds.labelCell);
9801
9840
  switch (labelCellChange.changeType) {
9802
9841
  case "REMOVE":
9803
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9842
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9804
9843
  break;
9805
9844
  case "RESIZE":
9806
9845
  case "MOVE":
9807
9846
  case "CHANGE":
9808
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9847
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9809
9848
  }
9810
9849
  }
9811
9850
  const dataRangeChange = applyChange(ds.dataRange);
9812
9851
  switch (dataRangeChange.changeType) {
9813
9852
  case "REMOVE":
9814
9853
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9815
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9854
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9816
9855
  break;
9817
9856
  case "RESIZE":
9818
9857
  case "MOVE":
@@ -9820,27 +9859,27 @@ class ChartPlugin extends CorePlugin {
9820
9859
  // We have to remove the ranges that are #REF
9821
9860
  if (this.getters.getRangeString(dataRangeChange.range, dataRangeChange.range.sheetId) !==
9822
9861
  INCORRECT_RANGE_STRING) {
9823
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9862
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9824
9863
  }
9825
9864
  else {
9826
9865
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9827
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9866
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9828
9867
  }
9829
9868
  break;
9830
9869
  }
9831
9870
  }
9832
9871
  }
9833
- adaptLabelRanges(sheetId, chart, chartId, applyChange) {
9872
+ adaptLabelRanges(chart, chartId, applyChange) {
9834
9873
  if (chart.labelRange) {
9835
9874
  const labelRangeChange = applyChange(chart.labelRange);
9836
9875
  switch (labelRangeChange.changeType) {
9837
9876
  case "REMOVE":
9838
- this.history.update("chartFigures", sheetId, chartId, "labelRange", undefined);
9877
+ this.history.update("chartFigures", chartId, "labelRange", undefined);
9839
9878
  break;
9840
9879
  case "RESIZE":
9841
9880
  case "MOVE":
9842
9881
  case "CHANGE":
9843
- this.history.update("chartFigures", sheetId, chartId, "labelRange", labelRangeChange.range);
9882
+ this.history.update("chartFigures", chartId, "labelRange", labelRangeChange.range);
9844
9883
  break;
9845
9884
  }
9846
9885
  }
@@ -9851,16 +9890,16 @@ class ChartPlugin extends CorePlugin {
9851
9890
  allowDispatch(cmd) {
9852
9891
  const success = 0 /* Success */;
9853
9892
  switch (cmd.type) {
9854
- case "CREATE_CHART":
9855
- return this.checkValidations(cmd, this.chainValidations(this.checkChartDuplicate, this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9856
9893
  case "UPDATE_CHART":
9857
- return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9894
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartExists), this.checkLabelRange);
9895
+ case "CREATE_CHART":
9896
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartDuplicate), this.checkLabelRange);
9858
9897
  default:
9859
9898
  return success;
9860
9899
  }
9861
9900
  }
9862
9901
  handle(cmd) {
9863
- var _a;
9902
+ var _a, _b;
9864
9903
  switch (cmd.type) {
9865
9904
  case "CREATE_CHART":
9866
9905
  const x = cmd.position ? cmd.position.x : 0;
@@ -9875,7 +9914,7 @@ class ChartPlugin extends CorePlugin {
9875
9914
  });
9876
9915
  break;
9877
9916
  case "UPDATE_CHART": {
9878
- this.updateChartDefinition(cmd.sheetId, cmd.id, cmd.definition);
9917
+ this.updateChartDefinition(cmd.id, cmd.definition);
9879
9918
  break;
9880
9919
  }
9881
9920
  case "DUPLICATE_SHEET": {
@@ -9885,7 +9924,7 @@ class ChartPlugin extends CorePlugin {
9885
9924
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
9886
9925
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
9887
9926
  const chartDefinition = {
9888
- ...deepCopy(this.chartFigures[cmd.sheetId][fig.id]),
9927
+ ...deepCopy(this.chartFigures[fig.id]),
9889
9928
  id: duplicatedFigureId,
9890
9929
  };
9891
9930
  chartDefinition.sheetId = cmd.sheetIdTo;
@@ -9915,28 +9954,37 @@ class ChartPlugin extends CorePlugin {
9915
9954
  break;
9916
9955
  }
9917
9956
  case "DELETE_FIGURE":
9918
- this.history.update("chartFigures", cmd.sheetId, cmd.id, undefined);
9957
+ this.history.update("chartFigures", cmd.id, undefined);
9919
9958
  break;
9920
9959
  case "DELETE_SHEET":
9921
- this.history.update("chartFigures", cmd.sheetId, undefined);
9960
+ for (let id of Object.keys(this.chartFigures)) {
9961
+ if (((_b = this.chartFigures[id]) === null || _b === void 0 ? void 0 : _b.sheetId) === cmd.sheetId) {
9962
+ this.history.update("chartFigures", id, undefined);
9963
+ }
9964
+ }
9922
9965
  break;
9923
9966
  }
9924
9967
  }
9925
9968
  // ---------------------------------------------------------------------------
9926
9969
  // Getters
9927
9970
  // ---------------------------------------------------------------------------
9928
- getChartDefinition(sheetId, figureId) {
9929
- var _a;
9930
- return (_a = this.chartFigures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
9971
+ getChartDefinition(figureId) {
9972
+ return this.chartFigures[figureId];
9931
9973
  }
9932
- getChartDefinitionsBySheet(sheetId) {
9933
- return Object.values(this.chartFigures[sheetId] || {}).filter(isDefined);
9974
+ getChartsIdBySheet(sheetId) {
9975
+ return Object.entries(this.chartFigures)
9976
+ .filter((chart) => {
9977
+ return chart[1].sheetId === sheetId;
9978
+ })
9979
+ .map((chart) => chart[0]);
9934
9980
  }
9935
- getChartDefinitionUI(sheetId, figureId, forceSheetName = false) {
9936
- const data = this.chartFigures[sheetId][figureId];
9937
- const rangeSheetId = forceSheetName ? "forceSheetReference" : sheetId;
9981
+ getChartDefinitionUI(sheetId, figureId) {
9982
+ const data = this.chartFigures[figureId];
9983
+ if (!data) {
9984
+ return undefined;
9985
+ }
9938
9986
  const dataSets = data.dataSets
9939
- .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, rangeSheetId) : ""))
9987
+ .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, sheetId) : ""))
9940
9988
  .filter((ds) => {
9941
9989
  return ds !== ""; // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9942
9990
  });
@@ -9944,7 +9992,7 @@ class ChartPlugin extends CorePlugin {
9944
9992
  title: data && data.title ? data.title : "",
9945
9993
  dataSets,
9946
9994
  labelRange: data.labelRange
9947
- ? this.getters.getRangeString(data.labelRange, rangeSheetId)
9995
+ ? this.getters.getRangeString(data.labelRange, sheetId)
9948
9996
  : undefined,
9949
9997
  type: data ? data.type : "bar",
9950
9998
  dataSetsHaveTitle: data && dataSets.length !== 0 ? Boolean(data.dataSets[0].labelCell) : false,
@@ -9955,12 +10003,16 @@ class ChartPlugin extends CorePlugin {
9955
10003
  };
9956
10004
  }
9957
10005
  getChartDefinitionExcel(sheetId, figureId) {
9958
- const data = this.chartFigures[sheetId][figureId];
10006
+ const data = this.chartFigures[figureId];
10007
+ const dataUI = this.getChartDefinitionUI("forceSheetReference", figureId);
10008
+ if (!data || !dataUI) {
10009
+ return undefined;
10010
+ }
9959
10011
  const dataSets = data.dataSets
9960
10012
  .map((ds) => this.toExcelDataset(ds))
9961
10013
  .filter((ds) => ds.range !== ""); // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9962
10014
  return {
9963
- ...this.getChartDefinitionUI(sheetId, figureId, true),
10015
+ ...dataUI,
9964
10016
  backgroundColor: data.background,
9965
10017
  dataSets,
9966
10018
  };
@@ -9995,17 +10047,15 @@ class ChartPlugin extends CorePlugin {
9995
10047
  import(data) {
9996
10048
  for (let sheet of data.sheets) {
9997
10049
  if (sheet.figures) {
9998
- const charts = {};
9999
10050
  for (let figure of sheet.figures) {
10000
10051
  if (figure.tag === "chart") {
10001
10052
  const figureData = {
10002
10053
  ...figure.data,
10003
10054
  };
10004
- charts[figure.id] = this.createChartDefinition(figureData, sheet.id);
10055
+ this.chartFigures[figure.id] = this.createChartDefinition(figureData, sheet.id);
10005
10056
  delete figure.data;
10006
10057
  }
10007
10058
  }
10008
- this.chartFigures[sheet.id] = charts;
10009
10059
  }
10010
10060
  }
10011
10061
  }
@@ -10013,10 +10063,18 @@ class ChartPlugin extends CorePlugin {
10013
10063
  if (data.sheets) {
10014
10064
  for (let sheet of data.sheets) {
10015
10065
  const sheetFigures = this.getters.getFigures(sheet.id);
10016
- const figures = sheetFigures;
10017
- for (let figure of figures) {
10066
+ const figures = [];
10067
+ for (let sheetFigure of sheetFigures) {
10068
+ const figure = sheetFigure;
10018
10069
  if (figure && figure.tag === "chart") {
10019
- figure.data = this.getChartDefinitionUI(sheet.id, figure.id);
10070
+ const data = this.getChartDefinitionUI(sheet.id, figure.id);
10071
+ if (data) {
10072
+ figure.data = data;
10073
+ figures.push(figure);
10074
+ }
10075
+ }
10076
+ else {
10077
+ figures.push(figure);
10020
10078
  }
10021
10079
  }
10022
10080
  sheet.figures = figures;
@@ -10026,10 +10084,18 @@ class ChartPlugin extends CorePlugin {
10026
10084
  exportForExcel(data) {
10027
10085
  for (let sheet of data.sheets) {
10028
10086
  const sheetFigures = this.getters.getFigures(sheet.id);
10029
- const figures = sheetFigures;
10030
- for (let figure of figures) {
10087
+ const figures = [];
10088
+ for (let sheetFigure of sheetFigures) {
10089
+ const figure = sheetFigure;
10031
10090
  if (figure && figure.tag === "chart") {
10032
- figure.data = this.getChartDefinitionExcel(sheet.id, figure.id);
10091
+ const data = this.getChartDefinitionExcel(sheet.id, figure.id);
10092
+ if (data) {
10093
+ figure.data = data;
10094
+ figures.push(figure);
10095
+ }
10096
+ }
10097
+ else {
10098
+ figures.push(figure);
10033
10099
  }
10034
10100
  }
10035
10101
  sheet.charts = figures;
@@ -10055,39 +10121,39 @@ class ChartPlugin extends CorePlugin {
10055
10121
  * Update the chart definition linked to the given id with the attributes
10056
10122
  * given in the partial UI definition
10057
10123
  */
10058
- updateChartDefinition(sheetId, id, definition) {
10059
- const chart = this.chartFigures[sheetId][id];
10124
+ updateChartDefinition(id, definition) {
10125
+ const chart = this.chartFigures[id];
10060
10126
  if (!chart) {
10061
10127
  throw new Error(`There is no chart with the given id: ${id}`);
10062
10128
  }
10063
10129
  if (definition.title !== undefined) {
10064
- this.history.update("chartFigures", sheetId, id, "title", definition.title);
10130
+ this.history.update("chartFigures", id, "title", definition.title);
10065
10131
  }
10066
10132
  if (definition.type) {
10067
- this.history.update("chartFigures", sheetId, id, "type", definition.type);
10133
+ this.history.update("chartFigures", id, "type", definition.type);
10068
10134
  }
10069
10135
  if (definition.dataSets) {
10070
10136
  const dataSetsHaveTitle = !!definition.dataSetsHaveTitle;
10071
10137
  const dataSets = this.createDataSets(definition.dataSets, chart.sheetId, dataSetsHaveTitle);
10072
- this.history.update("chartFigures", sheetId, id, "dataSets", dataSets);
10138
+ this.history.update("chartFigures", id, "dataSets", dataSets);
10073
10139
  }
10074
10140
  if (definition.labelRange !== undefined) {
10075
10141
  const labelRange = definition.labelRange
10076
10142
  ? this.getters.getRangeFromSheetXC(chart.sheetId, definition.labelRange)
10077
10143
  : undefined;
10078
- this.history.update("chartFigures", sheetId, id, "labelRange", labelRange);
10144
+ this.history.update("chartFigures", id, "labelRange", labelRange);
10079
10145
  }
10080
10146
  if (definition.background) {
10081
- this.history.update("chartFigures", sheetId, id, "background", definition.background);
10147
+ this.history.update("chartFigures", id, "background", definition.background);
10082
10148
  }
10083
10149
  if (definition.verticalAxisPosition) {
10084
- this.history.update("chartFigures", sheetId, id, "verticalAxisPosition", definition.verticalAxisPosition);
10150
+ this.history.update("chartFigures", id, "verticalAxisPosition", definition.verticalAxisPosition);
10085
10151
  }
10086
10152
  if (definition.legendPosition) {
10087
- this.history.update("chartFigures", sheetId, id, "legendPosition", definition.legendPosition);
10153
+ this.history.update("chartFigures", id, "legendPosition", definition.legendPosition);
10088
10154
  }
10089
10155
  if (definition.stackedBar !== undefined) {
10090
- this.history.update("chartFigures", sheetId, id, "stackedBar", definition.stackedBar);
10156
+ this.history.update("chartFigures", id, "stackedBar", definition.stackedBar);
10091
10157
  }
10092
10158
  }
10093
10159
  createDataSets(dataSetsString, sheetId, dataSetsHaveTitle) {
@@ -10142,7 +10208,7 @@ class ChartPlugin extends CorePlugin {
10142
10208
  sheetId,
10143
10209
  figure,
10144
10210
  });
10145
- this.history.update("chartFigures", sheetId, figure.id, data);
10211
+ this.history.update("chartFigures", figure.id, data);
10146
10212
  }
10147
10213
  createDataSet(sheetId, fullZone, titleZone) {
10148
10214
  if (fullZone.left !== fullZone.right && fullZone.top !== fullZone.bottom) {
@@ -10183,14 +10249,20 @@ class ChartPlugin extends CorePlugin {
10183
10249
  return invalidLabels ? 29 /* InvalidLabelRange */ : 0 /* Success */;
10184
10250
  }
10185
10251
  checkChartDuplicate(cmd) {
10186
- var _a;
10187
- if ((_a = this.chartFigures[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[cmd.id]) {
10188
- return 57 /* DuplicatedChartId */;
10252
+ for (const sheet of this.getters.getSheets()) {
10253
+ if (this.getters.getFigure(sheet.id, cmd.id)) {
10254
+ return 57 /* DuplicatedChartId */;
10255
+ }
10189
10256
  }
10190
10257
  return 0 /* Success */;
10191
10258
  }
10259
+ checkChartExists(cmd) {
10260
+ return this.getters.getFigure(cmd.sheetId, cmd.id)
10261
+ ? 0 /* Success */
10262
+ : 58 /* ChartDoesNotExist */;
10263
+ }
10192
10264
  }
10193
- ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartDefinitionsBySheet"];
10265
+ ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartsIdBySheet"];
10194
10266
 
10195
10267
  // -----------------------------------------------------------------------------
10196
10268
  // Constants
@@ -10529,7 +10601,7 @@ class FigurePlugin extends CorePlugin {
10529
10601
  allowDispatch(cmd) {
10530
10602
  switch (cmd.type) {
10531
10603
  case "CREATE_FIGURE":
10532
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
10604
+ return this.checkFigureDuplicate(cmd.figure.id);
10533
10605
  case "UPDATE_FIGURE":
10534
10606
  case "DELETE_FIGURE":
10535
10607
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -10595,9 +10667,8 @@ class FigurePlugin extends CorePlugin {
10595
10667
  }
10596
10668
  return 0 /* Success */;
10597
10669
  }
10598
- checkFigureDuplicate(sheetId, figureId) {
10599
- var _a;
10600
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
10670
+ checkFigureDuplicate(figureId) {
10671
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
10601
10672
  return 56 /* DuplicatedFigureId */;
10602
10673
  }
10603
10674
  return 0 /* Success */;
@@ -10612,6 +10683,9 @@ class FigurePlugin extends CorePlugin {
10612
10683
  var _a;
10613
10684
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
10614
10685
  }
10686
+ getFigureSheetId(figureId) {
10687
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
10688
+ }
10615
10689
  // ---------------------------------------------------------------------------
10616
10690
  // Import/Export
10617
10691
  // ---------------------------------------------------------------------------
@@ -10636,7 +10710,7 @@ class FigurePlugin extends CorePlugin {
10636
10710
  this.export(data);
10637
10711
  }
10638
10712
  }
10639
- FigurePlugin.getters = ["getFigures", "getFigure"];
10713
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
10640
10714
 
10641
10715
  class MergePlugin extends CorePlugin {
10642
10716
  constructor() {
@@ -12798,7 +12872,7 @@ const CREATE_CHART = (env) => {
12798
12872
  },
12799
12873
  });
12800
12874
  const figure = env.getters.getFigure(sheetId, id);
12801
- env.openSidePanel("ChartPanel", { sheetId, figure });
12875
+ env.openSidePanel("ChartPanel", { figure });
12802
12876
  };
12803
12877
  //------------------------------------------------------------------------------
12804
12878
  // Style/Format
@@ -14295,19 +14369,21 @@ class ChartPanel extends Component {
14295
14369
  constructor() {
14296
14370
  super(...arguments);
14297
14371
  this.getters = this.env.getters;
14372
+ this.chartSheetId = this.findSheetId(this.props.figure.id);
14298
14373
  this.state = useState$b(this.initialState(this.props.figure));
14299
14374
  }
14300
14375
  async willUpdateProps(nextProps) {
14301
- if (!this.getters.getChartDefinition(nextProps.sheetId, nextProps.figure.id)) {
14376
+ if (!this.getters.getChartDefinition(nextProps.figure.id)) {
14302
14377
  this.trigger("close-side-panel");
14303
14378
  return;
14304
14379
  }
14305
14380
  if (nextProps.figure.id !== this.props.figure.id) {
14381
+ this.chartSheetId = this.findSheetId(nextProps.figure.id);
14306
14382
  this.state.panel = "configuration";
14307
14383
  this.state.fillColorTool = false;
14308
14384
  this.state.datasetDispatchResult = undefined;
14309
14385
  this.state.labelsDispatchResult = undefined;
14310
- this.state.chart = this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), nextProps.figure.id);
14386
+ this.state.chart = this.env.getters.getChartDefinitionUI(this.chartSheetId, nextProps.figure.id);
14311
14387
  }
14312
14388
  }
14313
14389
  get errorMessages() {
@@ -14354,7 +14430,7 @@ class ChartPanel extends Component {
14354
14430
  updateChart(definition) {
14355
14431
  return this.env.dispatch("UPDATE_CHART", {
14356
14432
  id: this.props.figure.id,
14357
- sheetId: this.props.sheetId,
14433
+ sheetId: this.chartSheetId,
14358
14434
  definition,
14359
14435
  });
14360
14436
  }
@@ -14376,12 +14452,16 @@ class ChartPanel extends Component {
14376
14452
  this.state.panel = panel;
14377
14453
  }
14378
14454
  initialState(figure) {
14455
+ const sheetId = this.findSheetId(figure.id);
14379
14456
  return {
14380
- chart: this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), figure.id),
14457
+ chart: this.env.getters.getChartDefinitionUI(sheetId, figure.id),
14381
14458
  panel: "configuration",
14382
14459
  fillColorTool: false,
14383
14460
  };
14384
14461
  }
14462
+ findSheetId(figureId) {
14463
+ return this.env.getters.getFigureSheetId(figureId) || "";
14464
+ }
14385
14465
  }
14386
14466
  ChartPanel.template = TEMPLATE$p;
14387
14467
  ChartPanel.style = STYLE;
@@ -18795,60 +18875,51 @@ class EvaluationChartPlugin extends UIPlugin {
18795
18875
  this.outOfDate = new Set();
18796
18876
  }
18797
18877
  handle(cmd) {
18798
- var _a;
18799
18878
  if (invalidateEvaluationCommands.has(cmd.type) ||
18800
18879
  cmd.type === "EVALUATE_CELLS" ||
18801
18880
  (cmd.type === "UPDATE_CELL" && "content" in cmd)) {
18802
- for (const sheetId of Object.keys(this.chartRuntime)) {
18803
- for (const chartId of Object.keys(this.chartRuntime[sheetId] || {})) {
18804
- this.outOfDate.add(chartId);
18805
- }
18881
+ for (let chartId of Object.keys(this.chartRuntime)) {
18882
+ this.outOfDate.add(chartId);
18806
18883
  }
18807
18884
  }
18808
18885
  switch (cmd.type) {
18809
18886
  case "UPDATE_CHART":
18810
- case "CREATE_CHART": {
18811
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18812
- if (!this.chartRuntime[cmd.sheetId])
18813
- this.chartRuntime[cmd.sheetId] = {};
18814
- this.chartRuntime[cmd.sheetId][cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18887
+ case "CREATE_CHART":
18888
+ const chartDefinition = this.getters.getChartDefinition(cmd.id);
18889
+ this.chartRuntime[cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18815
18890
  break;
18816
- }
18817
18891
  case "DELETE_FIGURE":
18818
- (_a = this.chartRuntime[cmd.sheetId]) === null || _a === void 0 ? true : delete _a[cmd.id];
18892
+ delete this.chartRuntime[cmd.id];
18819
18893
  break;
18820
- case "REFRESH_CHART": {
18821
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18822
- this.evaluateUsedSheets([chartDefinition]);
18894
+ case "REFRESH_CHART":
18895
+ this.evaluateUsedSheets([cmd.id]);
18823
18896
  this.outOfDate.add(cmd.id);
18824
18897
  break;
18825
- }
18826
- case "ACTIVATE_SHEET": {
18827
- const chartsDefinitions = this.getters.getChartDefinitionsBySheet(cmd.sheetIdTo);
18828
- this.evaluateUsedSheets(chartsDefinitions);
18898
+ case "ACTIVATE_SHEET":
18899
+ const chartsIds = this.getters.getChartsIdBySheet(cmd.sheetIdTo);
18900
+ this.evaluateUsedSheets(chartsIds);
18829
18901
  break;
18830
- }
18831
18902
  case "DELETE_SHEET":
18832
- delete this.chartRuntime[cmd.sheetId];
18903
+ for (let chartId of Object.keys(this.chartRuntime)) {
18904
+ if (!this.getters.getChartDefinition(chartId)) {
18905
+ delete this.chartRuntime[chartId];
18906
+ }
18907
+ }
18833
18908
  break;
18834
18909
  }
18835
18910
  }
18836
18911
  // ---------------------------------------------------------------------------
18837
18912
  // Getters
18838
18913
  // ---------------------------------------------------------------------------
18839
- getChartRuntime(sheetId, figureId) {
18840
- if (this.outOfDate.has(figureId) ||
18841
- !(sheetId in this.chartRuntime) ||
18842
- !(figureId in this.chartRuntime[sheetId])) {
18843
- const chartDefinition = this.getters.getChartDefinition(sheetId, figureId);
18914
+ getChartRuntime(figureId) {
18915
+ if (this.outOfDate.has(figureId) || !(figureId in this.chartRuntime)) {
18916
+ const chartDefinition = this.getters.getChartDefinition(figureId);
18844
18917
  if (chartDefinition === undefined)
18845
18918
  return;
18846
- if (!this.chartRuntime[sheetId])
18847
- this.chartRuntime[sheetId] = {};
18848
- this.chartRuntime[sheetId][figureId] = this.mapDefinitionToRuntime(chartDefinition);
18919
+ this.chartRuntime[figureId] = this.mapDefinitionToRuntime(chartDefinition);
18849
18920
  this.outOfDate.delete(figureId);
18850
18921
  }
18851
- return this.chartRuntime[sheetId][figureId];
18922
+ return this.chartRuntime[figureId];
18852
18923
  }
18853
18924
  truncateLabel(label) {
18854
18925
  if (!label) {
@@ -18953,9 +19024,10 @@ class EvaluationChartPlugin extends UIPlugin {
18953
19024
  }
18954
19025
  return sheetIds;
18955
19026
  }
18956
- evaluateUsedSheets(chartsDefinitions) {
19027
+ evaluateUsedSheets(chartsIds) {
18957
19028
  const usedSheetsId = new Set();
18958
- for (const chartDefinition of chartsDefinitions) {
19029
+ for (let chartId of chartsIds) {
19030
+ const chartDefinition = this.getters.getChartDefinition(chartId);
18959
19031
  const sheetsIds = chartDefinition !== undefined ? this.getSheetIdsUsedInChart(chartDefinition) : [];
18960
19032
  sheetsIds.forEach((sheetId) => {
18961
19033
  if (sheetId !== this.getters.getActiveSheetId()) {
@@ -23506,6 +23578,7 @@ class RangeAdapter {
23506
23578
  }
23507
23579
  else if (range.zone[start] >= min && range.zone[end] <= max) {
23508
23580
  changeType = "REMOVE";
23581
+ newRange = this.buildInvalidRange(INCORRECT_RANGE_STRING);
23509
23582
  }
23510
23583
  else if (range.zone[start] <= max && range.zone[end] >= max) {
23511
23584
  const toRemove = max - range.zone[start] + 1;
@@ -23571,10 +23644,8 @@ class RangeAdapter {
23571
23644
  return { changeType: "NONE" };
23572
23645
  }
23573
23646
  range = {
23574
- ...range,
23575
- zone: { ...range.zone },
23647
+ ...this.buildInvalidRange(INCORRECT_RANGE_STRING),
23576
23648
  invalidSheetName: this.getters.getSheetName(cmd.sheetId),
23577
- sheetId: "",
23578
23649
  };
23579
23650
  return { changeType: "REMOVE", range };
23580
23651
  }, cmd.sheetId);
@@ -26043,7 +26114,7 @@ const { Portal } = misc$1;
26043
26114
  const { xml: xml$l } = tags;
26044
26115
  const TEMPLATE$j = xml$l /* xml */ `
26045
26116
  <Portal target="'.o-spreadsheet'">
26046
- <div t-att-style="style">
26117
+ <div class="o-popover" t-att-style="style">
26047
26118
  <t t-slot="default"/>
26048
26119
  </div>
26049
26120
  </Portal>
@@ -27225,7 +27296,7 @@ const CSS$b = css$d /* scss */ `
27225
27296
  padding: 0;
27226
27297
  margin: 0;
27227
27298
  border: 0;
27228
- z-index: 5;
27299
+ z-index: 6;
27229
27300
  flex-grow: 1;
27230
27301
  max-height: inherit;
27231
27302
  .o-composer {
@@ -27796,6 +27867,10 @@ const CSS$9 = css$b /* scss */ `
27796
27867
  border-left: 3px solid red;
27797
27868
  padding: 10px;
27798
27869
  }
27870
+
27871
+ .o-popover:has(.o-error-tooltip) {
27872
+ z-index: 4 !important;
27873
+ }
27799
27874
  `;
27800
27875
  class ErrorToolTip extends Component {
27801
27876
  }
@@ -27852,7 +27927,7 @@ class ChartFigure extends Component {
27852
27927
  }
27853
27928
  mounted() {
27854
27929
  const figure = this.props.figure;
27855
- const chartData = this.env.getters.getChartRuntime(this.env.getters.getActiveSheetId(), figure.id);
27930
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27856
27931
  if (chartData) {
27857
27932
  this.createChart(chartData);
27858
27933
  }
@@ -27860,8 +27935,7 @@ class ChartFigure extends Component {
27860
27935
  patched() {
27861
27936
  var _a, _b, _c;
27862
27937
  const figure = this.props.figure;
27863
- const sheetId = this.env.getters.getActiveSheetId();
27864
- const chartData = this.env.getters.getChartRuntime(sheetId, figure.id);
27938
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27865
27939
  if (chartData) {
27866
27940
  if (chartData.type !== this.chart.config.type) {
27867
27941
  // Updating a chart type requires to update its options accordingly, if feasible at all.
@@ -27887,7 +27961,7 @@ class ChartFigure extends Component {
27887
27961
  else {
27888
27962
  this.chart && this.chart.destroy();
27889
27963
  }
27890
- const def = this.env.getters.getChartDefinition(sheetId, figure.id);
27964
+ const def = this.env.getters.getChartDefinition(figure.id);
27891
27965
  if (def) {
27892
27966
  this.state.background = def.background;
27893
27967
  }
@@ -27896,7 +27970,7 @@ class ChartFigure extends Component {
27896
27970
  const canvas = this.canvas.el;
27897
27971
  const ctx = canvas.getContext("2d");
27898
27972
  this.chart = new window.Chart(ctx, chartData);
27899
- const def = this.env.getters.getChartDefinition(this.env.getters.getActiveSheetId(), this.props.figure.id);
27973
+ const def = this.env.getters.getChartDefinition(this.props.figure.id);
27900
27974
  if (def) {
27901
27975
  this.state.background = def.background;
27902
27976
  }
@@ -27906,10 +27980,8 @@ class ChartFigure extends Component {
27906
27980
  registry.add("edit", {
27907
27981
  name: _lt("Edit"),
27908
27982
  sequence: 1,
27909
- action: () => this.env.openSidePanel("ChartPanel", {
27910
- sheetId: this.env.getters.getActiveSheetId(),
27911
- figure: this.props.figure,
27912
- }),
27983
+ action: () => this.env.openSidePanel("ChartPanel", { figure: this.props.figure }),
27984
+ isVisible: () => !!this.env.getters.getChartDefinition(this.props.figure.id),
27913
27985
  });
27914
27986
  registry.add("delete", {
27915
27987
  name: _lt("Delete"),
@@ -27920,10 +27992,7 @@ class ChartFigure extends Component {
27920
27992
  id: this.props.figure.id,
27921
27993
  });
27922
27994
  if (this.props.sidePanelIsOpen) {
27923
- this.env.toggleSidePanel("ChartPanel", {
27924
- sheetId: this.env.getters.getActiveSheetId(),
27925
- figure: this.props.figure,
27926
- });
27995
+ this.env.toggleSidePanel("ChartPanel", { figure: this.props.figure });
27927
27996
  }
27928
27997
  this.trigger("figure-deleted");
27929
27998
  },
@@ -27933,7 +28002,6 @@ class ChartFigure extends Component {
27933
28002
  sequence: 11,
27934
28003
  action: () => {
27935
28004
  this.env.dispatch("REFRESH_CHART", {
27936
- sheetId: this.env.getters.getActiveSheetId(),
27937
28005
  id: this.props.figure.id,
27938
28006
  });
27939
28007
  },
@@ -28177,10 +28245,7 @@ class FiguresContainer extends Component {
28177
28245
  return;
28178
28246
  }
28179
28247
  if (this.props.sidePanelIsOpen) {
28180
- this.env.openSidePanel("ChartPanel", {
28181
- sheetId: this.env.getters.getActiveSheetId(),
28182
- figure,
28183
- });
28248
+ this.env.openSidePanel("ChartPanel", { figure });
28184
28249
  }
28185
28250
  const initialX = ev.clientX;
28186
28251
  const initialY = ev.clientY;
@@ -31252,6 +31317,6 @@ const helpers = {
31252
31317
  export { CommandResult, CorePlugin, DATETIME_FORMAT, DataSource, DispatchResult, Model, Revision, SPREADSHEET_DIMENSIONS, Spreadsheet, UIPlugin, DEBUG as __DEBUG__, __info__, astToFormula, cellTypes, convertAstNodes, coreTypes, functionCache, helpers, invalidateEvaluationCommands, normalize, parse, readonlyAllowedCommands, registries, setTranslationMethod };
31253
31318
 
31254
31319
 
31255
- __info__.version = '15.0.0';
31256
- __info__.date = '2023-02-27T14:03:17.561Z';
31257
- __info__.hash = '2d1cea1';
31320
+ __info__.version = '15.0.2';
31321
+ __info__.date = '2023-03-14T09:19:34.555Z';
31322
+ __info__.hash = 'c0a25a0';