@odoo/o-spreadsheet 15.0.0 → 15.0.1

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;
@@ -8477,13 +8478,7 @@ function load(data) {
8477
8478
  data = migrate(data);
8478
8479
  }
8479
8480
  }
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
- }
8481
+ data = repairData(data);
8487
8482
  return data;
8488
8483
  }
8489
8484
  function migrate(data) {
@@ -8692,6 +8687,48 @@ const MIGRATIONS = [
8692
8687
  },
8693
8688
  },
8694
8689
  ];
8690
+ /**
8691
+ * This function is used to repair faulty data independently of the migration.
8692
+ */
8693
+ function repairData(data) {
8694
+ data = forceUnicityOfFigure(data);
8695
+ data = setDefaults(data);
8696
+ return data;
8697
+ }
8698
+ /**
8699
+ * Force the unicity of figure ids accross sheets
8700
+ */
8701
+ function forceUnicityOfFigure(data) {
8702
+ if (data.uniqueFigureIds) {
8703
+ return data;
8704
+ }
8705
+ const figureIds = new Set();
8706
+ const uuidGenerator = new UuidGenerator();
8707
+ for (const sheet of data.sheets || []) {
8708
+ for (const figure of sheet.figures || []) {
8709
+ if (figureIds.has(figure.id)) {
8710
+ figure.id += uuidGenerator.uuidv4();
8711
+ }
8712
+ figureIds.add(figure.id);
8713
+ }
8714
+ }
8715
+ data.uniqueFigureIds = true;
8716
+ return data;
8717
+ }
8718
+ /**
8719
+ * sanity check: try to fix missing fields/corrupted state by providing
8720
+ * sensible default values
8721
+ */
8722
+ function setDefaults(data) {
8723
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8724
+ data.sheets = data.sheets
8725
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
8726
+ : [];
8727
+ if (data.sheets.length === 0) {
8728
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8729
+ }
8730
+ return data;
8731
+ }
8695
8732
  /**
8696
8733
  * The goal of this function is to repair corrupted/wrong initial messages caused by
8697
8734
  * a bug.
@@ -8778,6 +8815,7 @@ function createEmptyWorkbookData(sheetName = "Sheet1") {
8778
8815
  styles: {},
8779
8816
  borders: {},
8780
8817
  revisionId: DEFAULT_REVISION_ID,
8818
+ uniqueFigureIds: true,
8781
8819
  };
8782
8820
  return data;
8783
8821
  }
@@ -9808,34 +9846,32 @@ class ChartPlugin extends CorePlugin {
9808
9846
  this.chartFigures = {};
9809
9847
  }
9810
9848
  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
- }
9849
+ for (let [chartId, chart] of Object.entries(this.chartFigures)) {
9850
+ if (chart) {
9851
+ this.adaptDataSetRanges(chart, chartId, applyChange);
9852
+ this.adaptLabelRanges(chart, chartId, applyChange);
9817
9853
  }
9818
9854
  }
9819
9855
  }
9820
- adaptDataSetRanges(sheetId, chart, chartId, applyChange) {
9856
+ adaptDataSetRanges(chart, chartId, applyChange) {
9821
9857
  for (let ds of chart.dataSets) {
9822
9858
  if (ds.labelCell) {
9823
9859
  const labelCellChange = applyChange(ds.labelCell);
9824
9860
  switch (labelCellChange.changeType) {
9825
9861
  case "REMOVE":
9826
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9862
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9827
9863
  break;
9828
9864
  case "RESIZE":
9829
9865
  case "MOVE":
9830
9866
  case "CHANGE":
9831
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9867
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9832
9868
  }
9833
9869
  }
9834
9870
  const dataRangeChange = applyChange(ds.dataRange);
9835
9871
  switch (dataRangeChange.changeType) {
9836
9872
  case "REMOVE":
9837
9873
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9838
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9874
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9839
9875
  break;
9840
9876
  case "RESIZE":
9841
9877
  case "MOVE":
@@ -9843,27 +9879,27 @@ class ChartPlugin extends CorePlugin {
9843
9879
  // We have to remove the ranges that are #REF
9844
9880
  if (this.getters.getRangeString(dataRangeChange.range, dataRangeChange.range.sheetId) !==
9845
9881
  INCORRECT_RANGE_STRING) {
9846
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9882
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9847
9883
  }
9848
9884
  else {
9849
9885
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9850
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9886
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9851
9887
  }
9852
9888
  break;
9853
9889
  }
9854
9890
  }
9855
9891
  }
9856
- adaptLabelRanges(sheetId, chart, chartId, applyChange) {
9892
+ adaptLabelRanges(chart, chartId, applyChange) {
9857
9893
  if (chart.labelRange) {
9858
9894
  const labelRangeChange = applyChange(chart.labelRange);
9859
9895
  switch (labelRangeChange.changeType) {
9860
9896
  case "REMOVE":
9861
- this.history.update("chartFigures", sheetId, chartId, "labelRange", undefined);
9897
+ this.history.update("chartFigures", chartId, "labelRange", undefined);
9862
9898
  break;
9863
9899
  case "RESIZE":
9864
9900
  case "MOVE":
9865
9901
  case "CHANGE":
9866
- this.history.update("chartFigures", sheetId, chartId, "labelRange", labelRangeChange.range);
9902
+ this.history.update("chartFigures", chartId, "labelRange", labelRangeChange.range);
9867
9903
  break;
9868
9904
  }
9869
9905
  }
@@ -9874,16 +9910,16 @@ class ChartPlugin extends CorePlugin {
9874
9910
  allowDispatch(cmd) {
9875
9911
  const success = 0 /* Success */;
9876
9912
  switch (cmd.type) {
9877
- case "CREATE_CHART":
9878
- return this.checkValidations(cmd, this.chainValidations(this.checkChartDuplicate, this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9879
9913
  case "UPDATE_CHART":
9880
- return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9914
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartExists), this.checkLabelRange);
9915
+ case "CREATE_CHART":
9916
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartDuplicate), this.checkLabelRange);
9881
9917
  default:
9882
9918
  return success;
9883
9919
  }
9884
9920
  }
9885
9921
  handle(cmd) {
9886
- var _a;
9922
+ var _a, _b;
9887
9923
  switch (cmd.type) {
9888
9924
  case "CREATE_CHART":
9889
9925
  const x = cmd.position ? cmd.position.x : 0;
@@ -9898,7 +9934,7 @@ class ChartPlugin extends CorePlugin {
9898
9934
  });
9899
9935
  break;
9900
9936
  case "UPDATE_CHART": {
9901
- this.updateChartDefinition(cmd.sheetId, cmd.id, cmd.definition);
9937
+ this.updateChartDefinition(cmd.id, cmd.definition);
9902
9938
  break;
9903
9939
  }
9904
9940
  case "DUPLICATE_SHEET": {
@@ -9908,7 +9944,7 @@ class ChartPlugin extends CorePlugin {
9908
9944
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
9909
9945
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
9910
9946
  const chartDefinition = {
9911
- ...deepCopy(this.chartFigures[cmd.sheetId][fig.id]),
9947
+ ...deepCopy(this.chartFigures[fig.id]),
9912
9948
  id: duplicatedFigureId,
9913
9949
  };
9914
9950
  chartDefinition.sheetId = cmd.sheetIdTo;
@@ -9938,28 +9974,37 @@ class ChartPlugin extends CorePlugin {
9938
9974
  break;
9939
9975
  }
9940
9976
  case "DELETE_FIGURE":
9941
- this.history.update("chartFigures", cmd.sheetId, cmd.id, undefined);
9977
+ this.history.update("chartFigures", cmd.id, undefined);
9942
9978
  break;
9943
9979
  case "DELETE_SHEET":
9944
- this.history.update("chartFigures", cmd.sheetId, undefined);
9980
+ for (let id of Object.keys(this.chartFigures)) {
9981
+ if (((_b = this.chartFigures[id]) === null || _b === void 0 ? void 0 : _b.sheetId) === cmd.sheetId) {
9982
+ this.history.update("chartFigures", id, undefined);
9983
+ }
9984
+ }
9945
9985
  break;
9946
9986
  }
9947
9987
  }
9948
9988
  // ---------------------------------------------------------------------------
9949
9989
  // Getters
9950
9990
  // ---------------------------------------------------------------------------
9951
- getChartDefinition(sheetId, figureId) {
9952
- var _a;
9953
- return (_a = this.chartFigures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
9991
+ getChartDefinition(figureId) {
9992
+ return this.chartFigures[figureId];
9954
9993
  }
9955
- getChartDefinitionsBySheet(sheetId) {
9956
- return Object.values(this.chartFigures[sheetId] || {}).filter(isDefined);
9994
+ getChartsIdBySheet(sheetId) {
9995
+ return Object.entries(this.chartFigures)
9996
+ .filter((chart) => {
9997
+ return chart[1].sheetId === sheetId;
9998
+ })
9999
+ .map((chart) => chart[0]);
9957
10000
  }
9958
- getChartDefinitionUI(sheetId, figureId, forceSheetName = false) {
9959
- const data = this.chartFigures[sheetId][figureId];
9960
- const rangeSheetId = forceSheetName ? "forceSheetReference" : sheetId;
10001
+ getChartDefinitionUI(sheetId, figureId) {
10002
+ const data = this.chartFigures[figureId];
10003
+ if (!data) {
10004
+ return undefined;
10005
+ }
9961
10006
  const dataSets = data.dataSets
9962
- .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, rangeSheetId) : ""))
10007
+ .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, sheetId) : ""))
9963
10008
  .filter((ds) => {
9964
10009
  return ds !== ""; // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9965
10010
  });
@@ -9967,7 +10012,7 @@ class ChartPlugin extends CorePlugin {
9967
10012
  title: data && data.title ? data.title : "",
9968
10013
  dataSets,
9969
10014
  labelRange: data.labelRange
9970
- ? this.getters.getRangeString(data.labelRange, rangeSheetId)
10015
+ ? this.getters.getRangeString(data.labelRange, sheetId)
9971
10016
  : undefined,
9972
10017
  type: data ? data.type : "bar",
9973
10018
  dataSetsHaveTitle: data && dataSets.length !== 0 ? Boolean(data.dataSets[0].labelCell) : false,
@@ -9978,12 +10023,16 @@ class ChartPlugin extends CorePlugin {
9978
10023
  };
9979
10024
  }
9980
10025
  getChartDefinitionExcel(sheetId, figureId) {
9981
- const data = this.chartFigures[sheetId][figureId];
10026
+ const data = this.chartFigures[figureId];
10027
+ const dataUI = this.getChartDefinitionUI("forceSheetReference", figureId);
10028
+ if (!data || !dataUI) {
10029
+ return undefined;
10030
+ }
9982
10031
  const dataSets = data.dataSets
9983
10032
  .map((ds) => this.toExcelDataset(ds))
9984
10033
  .filter((ds) => ds.range !== ""); // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9985
10034
  return {
9986
- ...this.getChartDefinitionUI(sheetId, figureId, true),
10035
+ ...dataUI,
9987
10036
  backgroundColor: data.background,
9988
10037
  dataSets,
9989
10038
  };
@@ -10018,17 +10067,15 @@ class ChartPlugin extends CorePlugin {
10018
10067
  import(data) {
10019
10068
  for (let sheet of data.sheets) {
10020
10069
  if (sheet.figures) {
10021
- const charts = {};
10022
10070
  for (let figure of sheet.figures) {
10023
10071
  if (figure.tag === "chart") {
10024
10072
  const figureData = {
10025
10073
  ...figure.data,
10026
10074
  };
10027
- charts[figure.id] = this.createChartDefinition(figureData, sheet.id);
10075
+ this.chartFigures[figure.id] = this.createChartDefinition(figureData, sheet.id);
10028
10076
  delete figure.data;
10029
10077
  }
10030
10078
  }
10031
- this.chartFigures[sheet.id] = charts;
10032
10079
  }
10033
10080
  }
10034
10081
  }
@@ -10036,10 +10083,18 @@ class ChartPlugin extends CorePlugin {
10036
10083
  if (data.sheets) {
10037
10084
  for (let sheet of data.sheets) {
10038
10085
  const sheetFigures = this.getters.getFigures(sheet.id);
10039
- const figures = sheetFigures;
10040
- for (let figure of figures) {
10086
+ const figures = [];
10087
+ for (let sheetFigure of sheetFigures) {
10088
+ const figure = sheetFigure;
10041
10089
  if (figure && figure.tag === "chart") {
10042
- figure.data = this.getChartDefinitionUI(sheet.id, figure.id);
10090
+ const data = this.getChartDefinitionUI(sheet.id, figure.id);
10091
+ if (data) {
10092
+ figure.data = data;
10093
+ figures.push(figure);
10094
+ }
10095
+ }
10096
+ else {
10097
+ figures.push(figure);
10043
10098
  }
10044
10099
  }
10045
10100
  sheet.figures = figures;
@@ -10049,10 +10104,18 @@ class ChartPlugin extends CorePlugin {
10049
10104
  exportForExcel(data) {
10050
10105
  for (let sheet of data.sheets) {
10051
10106
  const sheetFigures = this.getters.getFigures(sheet.id);
10052
- const figures = sheetFigures;
10053
- for (let figure of figures) {
10107
+ const figures = [];
10108
+ for (let sheetFigure of sheetFigures) {
10109
+ const figure = sheetFigure;
10054
10110
  if (figure && figure.tag === "chart") {
10055
- figure.data = this.getChartDefinitionExcel(sheet.id, figure.id);
10111
+ const data = this.getChartDefinitionExcel(sheet.id, figure.id);
10112
+ if (data) {
10113
+ figure.data = data;
10114
+ figures.push(figure);
10115
+ }
10116
+ }
10117
+ else {
10118
+ figures.push(figure);
10056
10119
  }
10057
10120
  }
10058
10121
  sheet.charts = figures;
@@ -10078,39 +10141,39 @@ class ChartPlugin extends CorePlugin {
10078
10141
  * Update the chart definition linked to the given id with the attributes
10079
10142
  * given in the partial UI definition
10080
10143
  */
10081
- updateChartDefinition(sheetId, id, definition) {
10082
- const chart = this.chartFigures[sheetId][id];
10144
+ updateChartDefinition(id, definition) {
10145
+ const chart = this.chartFigures[id];
10083
10146
  if (!chart) {
10084
10147
  throw new Error(`There is no chart with the given id: ${id}`);
10085
10148
  }
10086
10149
  if (definition.title !== undefined) {
10087
- this.history.update("chartFigures", sheetId, id, "title", definition.title);
10150
+ this.history.update("chartFigures", id, "title", definition.title);
10088
10151
  }
10089
10152
  if (definition.type) {
10090
- this.history.update("chartFigures", sheetId, id, "type", definition.type);
10153
+ this.history.update("chartFigures", id, "type", definition.type);
10091
10154
  }
10092
10155
  if (definition.dataSets) {
10093
10156
  const dataSetsHaveTitle = !!definition.dataSetsHaveTitle;
10094
10157
  const dataSets = this.createDataSets(definition.dataSets, chart.sheetId, dataSetsHaveTitle);
10095
- this.history.update("chartFigures", sheetId, id, "dataSets", dataSets);
10158
+ this.history.update("chartFigures", id, "dataSets", dataSets);
10096
10159
  }
10097
10160
  if (definition.labelRange !== undefined) {
10098
10161
  const labelRange = definition.labelRange
10099
10162
  ? this.getters.getRangeFromSheetXC(chart.sheetId, definition.labelRange)
10100
10163
  : undefined;
10101
- this.history.update("chartFigures", sheetId, id, "labelRange", labelRange);
10164
+ this.history.update("chartFigures", id, "labelRange", labelRange);
10102
10165
  }
10103
10166
  if (definition.background) {
10104
- this.history.update("chartFigures", sheetId, id, "background", definition.background);
10167
+ this.history.update("chartFigures", id, "background", definition.background);
10105
10168
  }
10106
10169
  if (definition.verticalAxisPosition) {
10107
- this.history.update("chartFigures", sheetId, id, "verticalAxisPosition", definition.verticalAxisPosition);
10170
+ this.history.update("chartFigures", id, "verticalAxisPosition", definition.verticalAxisPosition);
10108
10171
  }
10109
10172
  if (definition.legendPosition) {
10110
- this.history.update("chartFigures", sheetId, id, "legendPosition", definition.legendPosition);
10173
+ this.history.update("chartFigures", id, "legendPosition", definition.legendPosition);
10111
10174
  }
10112
10175
  if (definition.stackedBar !== undefined) {
10113
- this.history.update("chartFigures", sheetId, id, "stackedBar", definition.stackedBar);
10176
+ this.history.update("chartFigures", id, "stackedBar", definition.stackedBar);
10114
10177
  }
10115
10178
  }
10116
10179
  createDataSets(dataSetsString, sheetId, dataSetsHaveTitle) {
@@ -10165,7 +10228,7 @@ class ChartPlugin extends CorePlugin {
10165
10228
  sheetId,
10166
10229
  figure,
10167
10230
  });
10168
- this.history.update("chartFigures", sheetId, figure.id, data);
10231
+ this.history.update("chartFigures", figure.id, data);
10169
10232
  }
10170
10233
  createDataSet(sheetId, fullZone, titleZone) {
10171
10234
  if (fullZone.left !== fullZone.right && fullZone.top !== fullZone.bottom) {
@@ -10206,14 +10269,20 @@ class ChartPlugin extends CorePlugin {
10206
10269
  return invalidLabels ? 29 /* InvalidLabelRange */ : 0 /* Success */;
10207
10270
  }
10208
10271
  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 */;
10272
+ for (const sheet of this.getters.getSheets()) {
10273
+ if (this.getters.getFigure(sheet.id, cmd.id)) {
10274
+ return 57 /* DuplicatedChartId */;
10275
+ }
10212
10276
  }
10213
10277
  return 0 /* Success */;
10214
10278
  }
10279
+ checkChartExists(cmd) {
10280
+ return this.getters.getFigure(cmd.sheetId, cmd.id)
10281
+ ? 0 /* Success */
10282
+ : 58 /* ChartDoesNotExist */;
10283
+ }
10215
10284
  }
10216
- ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartDefinitionsBySheet"];
10285
+ ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartsIdBySheet"];
10217
10286
 
10218
10287
  // -----------------------------------------------------------------------------
10219
10288
  // Constants
@@ -10552,7 +10621,7 @@ class FigurePlugin extends CorePlugin {
10552
10621
  allowDispatch(cmd) {
10553
10622
  switch (cmd.type) {
10554
10623
  case "CREATE_FIGURE":
10555
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
10624
+ return this.checkFigureDuplicate(cmd.figure.id);
10556
10625
  case "UPDATE_FIGURE":
10557
10626
  case "DELETE_FIGURE":
10558
10627
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -10618,9 +10687,8 @@ class FigurePlugin extends CorePlugin {
10618
10687
  }
10619
10688
  return 0 /* Success */;
10620
10689
  }
10621
- checkFigureDuplicate(sheetId, figureId) {
10622
- var _a;
10623
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
10690
+ checkFigureDuplicate(figureId) {
10691
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
10624
10692
  return 56 /* DuplicatedFigureId */;
10625
10693
  }
10626
10694
  return 0 /* Success */;
@@ -10635,6 +10703,9 @@ class FigurePlugin extends CorePlugin {
10635
10703
  var _a;
10636
10704
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
10637
10705
  }
10706
+ getFigureSheetId(figureId) {
10707
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
10708
+ }
10638
10709
  // ---------------------------------------------------------------------------
10639
10710
  // Import/Export
10640
10711
  // ---------------------------------------------------------------------------
@@ -10659,7 +10730,7 @@ class FigurePlugin extends CorePlugin {
10659
10730
  this.export(data);
10660
10731
  }
10661
10732
  }
10662
- FigurePlugin.getters = ["getFigures", "getFigure"];
10733
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
10663
10734
 
10664
10735
  class MergePlugin extends CorePlugin {
10665
10736
  constructor() {
@@ -12821,7 +12892,7 @@ const CREATE_CHART = (env) => {
12821
12892
  },
12822
12893
  });
12823
12894
  const figure = env.getters.getFigure(sheetId, id);
12824
- env.openSidePanel("ChartPanel", { sheetId, figure });
12895
+ env.openSidePanel("ChartPanel", { figure });
12825
12896
  };
12826
12897
  //------------------------------------------------------------------------------
12827
12898
  // Style/Format
@@ -14318,19 +14389,21 @@ class ChartPanel extends owl.Component {
14318
14389
  constructor() {
14319
14390
  super(...arguments);
14320
14391
  this.getters = this.env.getters;
14392
+ this.chartSheetId = this.findSheetId(this.props.figure.id);
14321
14393
  this.state = owl.useState(this.initialState(this.props.figure));
14322
14394
  }
14323
14395
  async willUpdateProps(nextProps) {
14324
- if (!this.getters.getChartDefinition(nextProps.sheetId, nextProps.figure.id)) {
14396
+ if (!this.getters.getChartDefinition(nextProps.figure.id)) {
14325
14397
  this.trigger("close-side-panel");
14326
14398
  return;
14327
14399
  }
14328
14400
  if (nextProps.figure.id !== this.props.figure.id) {
14401
+ this.chartSheetId = this.findSheetId(nextProps.figure.id);
14329
14402
  this.state.panel = "configuration";
14330
14403
  this.state.fillColorTool = false;
14331
14404
  this.state.datasetDispatchResult = undefined;
14332
14405
  this.state.labelsDispatchResult = undefined;
14333
- this.state.chart = this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), nextProps.figure.id);
14406
+ this.state.chart = this.env.getters.getChartDefinitionUI(this.chartSheetId, nextProps.figure.id);
14334
14407
  }
14335
14408
  }
14336
14409
  get errorMessages() {
@@ -14377,7 +14450,7 @@ class ChartPanel extends owl.Component {
14377
14450
  updateChart(definition) {
14378
14451
  return this.env.dispatch("UPDATE_CHART", {
14379
14452
  id: this.props.figure.id,
14380
- sheetId: this.props.sheetId,
14453
+ sheetId: this.chartSheetId,
14381
14454
  definition,
14382
14455
  });
14383
14456
  }
@@ -14399,12 +14472,16 @@ class ChartPanel extends owl.Component {
14399
14472
  this.state.panel = panel;
14400
14473
  }
14401
14474
  initialState(figure) {
14475
+ const sheetId = this.findSheetId(figure.id);
14402
14476
  return {
14403
- chart: this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), figure.id),
14477
+ chart: this.env.getters.getChartDefinitionUI(sheetId, figure.id),
14404
14478
  panel: "configuration",
14405
14479
  fillColorTool: false,
14406
14480
  };
14407
14481
  }
14482
+ findSheetId(figureId) {
14483
+ return this.env.getters.getFigureSheetId(figureId) || "";
14484
+ }
14408
14485
  }
14409
14486
  ChartPanel.template = TEMPLATE$p;
14410
14487
  ChartPanel.style = STYLE;
@@ -18818,60 +18895,51 @@ class EvaluationChartPlugin extends UIPlugin {
18818
18895
  this.outOfDate = new Set();
18819
18896
  }
18820
18897
  handle(cmd) {
18821
- var _a;
18822
18898
  if (invalidateEvaluationCommands.has(cmd.type) ||
18823
18899
  cmd.type === "EVALUATE_CELLS" ||
18824
18900
  (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
- }
18901
+ for (let chartId of Object.keys(this.chartRuntime)) {
18902
+ this.outOfDate.add(chartId);
18829
18903
  }
18830
18904
  }
18831
18905
  switch (cmd.type) {
18832
18906
  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);
18907
+ case "CREATE_CHART":
18908
+ const chartDefinition = this.getters.getChartDefinition(cmd.id);
18909
+ this.chartRuntime[cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18838
18910
  break;
18839
- }
18840
18911
  case "DELETE_FIGURE":
18841
- (_a = this.chartRuntime[cmd.sheetId]) === null || _a === void 0 ? true : delete _a[cmd.id];
18912
+ delete this.chartRuntime[cmd.id];
18842
18913
  break;
18843
- case "REFRESH_CHART": {
18844
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18845
- this.evaluateUsedSheets([chartDefinition]);
18914
+ case "REFRESH_CHART":
18915
+ this.evaluateUsedSheets([cmd.id]);
18846
18916
  this.outOfDate.add(cmd.id);
18847
18917
  break;
18848
- }
18849
- case "ACTIVATE_SHEET": {
18850
- const chartsDefinitions = this.getters.getChartDefinitionsBySheet(cmd.sheetIdTo);
18851
- this.evaluateUsedSheets(chartsDefinitions);
18918
+ case "ACTIVATE_SHEET":
18919
+ const chartsIds = this.getters.getChartsIdBySheet(cmd.sheetIdTo);
18920
+ this.evaluateUsedSheets(chartsIds);
18852
18921
  break;
18853
- }
18854
18922
  case "DELETE_SHEET":
18855
- delete this.chartRuntime[cmd.sheetId];
18923
+ for (let chartId of Object.keys(this.chartRuntime)) {
18924
+ if (!this.getters.getChartDefinition(chartId)) {
18925
+ delete this.chartRuntime[chartId];
18926
+ }
18927
+ }
18856
18928
  break;
18857
18929
  }
18858
18930
  }
18859
18931
  // ---------------------------------------------------------------------------
18860
18932
  // Getters
18861
18933
  // ---------------------------------------------------------------------------
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);
18934
+ getChartRuntime(figureId) {
18935
+ if (this.outOfDate.has(figureId) || !(figureId in this.chartRuntime)) {
18936
+ const chartDefinition = this.getters.getChartDefinition(figureId);
18867
18937
  if (chartDefinition === undefined)
18868
18938
  return;
18869
- if (!this.chartRuntime[sheetId])
18870
- this.chartRuntime[sheetId] = {};
18871
- this.chartRuntime[sheetId][figureId] = this.mapDefinitionToRuntime(chartDefinition);
18939
+ this.chartRuntime[figureId] = this.mapDefinitionToRuntime(chartDefinition);
18872
18940
  this.outOfDate.delete(figureId);
18873
18941
  }
18874
- return this.chartRuntime[sheetId][figureId];
18942
+ return this.chartRuntime[figureId];
18875
18943
  }
18876
18944
  truncateLabel(label) {
18877
18945
  if (!label) {
@@ -18976,9 +19044,10 @@ class EvaluationChartPlugin extends UIPlugin {
18976
19044
  }
18977
19045
  return sheetIds;
18978
19046
  }
18979
- evaluateUsedSheets(chartsDefinitions) {
19047
+ evaluateUsedSheets(chartsIds) {
18980
19048
  const usedSheetsId = new Set();
18981
- for (const chartDefinition of chartsDefinitions) {
19049
+ for (let chartId of chartsIds) {
19050
+ const chartDefinition = this.getters.getChartDefinition(chartId);
18982
19051
  const sheetsIds = chartDefinition !== undefined ? this.getSheetIdsUsedInChart(chartDefinition) : [];
18983
19052
  sheetsIds.forEach((sheetId) => {
18984
19053
  if (sheetId !== this.getters.getActiveSheetId()) {
@@ -27875,7 +27944,7 @@ class ChartFigure extends owl.Component {
27875
27944
  }
27876
27945
  mounted() {
27877
27946
  const figure = this.props.figure;
27878
- const chartData = this.env.getters.getChartRuntime(this.env.getters.getActiveSheetId(), figure.id);
27947
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27879
27948
  if (chartData) {
27880
27949
  this.createChart(chartData);
27881
27950
  }
@@ -27883,8 +27952,7 @@ class ChartFigure extends owl.Component {
27883
27952
  patched() {
27884
27953
  var _a, _b, _c;
27885
27954
  const figure = this.props.figure;
27886
- const sheetId = this.env.getters.getActiveSheetId();
27887
- const chartData = this.env.getters.getChartRuntime(sheetId, figure.id);
27955
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27888
27956
  if (chartData) {
27889
27957
  if (chartData.type !== this.chart.config.type) {
27890
27958
  // Updating a chart type requires to update its options accordingly, if feasible at all.
@@ -27910,7 +27978,7 @@ class ChartFigure extends owl.Component {
27910
27978
  else {
27911
27979
  this.chart && this.chart.destroy();
27912
27980
  }
27913
- const def = this.env.getters.getChartDefinition(sheetId, figure.id);
27981
+ const def = this.env.getters.getChartDefinition(figure.id);
27914
27982
  if (def) {
27915
27983
  this.state.background = def.background;
27916
27984
  }
@@ -27919,7 +27987,7 @@ class ChartFigure extends owl.Component {
27919
27987
  const canvas = this.canvas.el;
27920
27988
  const ctx = canvas.getContext("2d");
27921
27989
  this.chart = new window.Chart(ctx, chartData);
27922
- const def = this.env.getters.getChartDefinition(this.env.getters.getActiveSheetId(), this.props.figure.id);
27990
+ const def = this.env.getters.getChartDefinition(this.props.figure.id);
27923
27991
  if (def) {
27924
27992
  this.state.background = def.background;
27925
27993
  }
@@ -27929,10 +27997,8 @@ class ChartFigure extends owl.Component {
27929
27997
  registry.add("edit", {
27930
27998
  name: _lt("Edit"),
27931
27999
  sequence: 1,
27932
- action: () => this.env.openSidePanel("ChartPanel", {
27933
- sheetId: this.env.getters.getActiveSheetId(),
27934
- figure: this.props.figure,
27935
- }),
28000
+ action: () => this.env.openSidePanel("ChartPanel", { figure: this.props.figure }),
28001
+ isVisible: () => !!this.env.getters.getChartDefinition(this.props.figure.id),
27936
28002
  });
27937
28003
  registry.add("delete", {
27938
28004
  name: _lt("Delete"),
@@ -27943,10 +28009,7 @@ class ChartFigure extends owl.Component {
27943
28009
  id: this.props.figure.id,
27944
28010
  });
27945
28011
  if (this.props.sidePanelIsOpen) {
27946
- this.env.toggleSidePanel("ChartPanel", {
27947
- sheetId: this.env.getters.getActiveSheetId(),
27948
- figure: this.props.figure,
27949
- });
28012
+ this.env.toggleSidePanel("ChartPanel", { figure: this.props.figure });
27950
28013
  }
27951
28014
  this.trigger("figure-deleted");
27952
28015
  },
@@ -27956,7 +28019,6 @@ class ChartFigure extends owl.Component {
27956
28019
  sequence: 11,
27957
28020
  action: () => {
27958
28021
  this.env.dispatch("REFRESH_CHART", {
27959
- sheetId: this.env.getters.getActiveSheetId(),
27960
28022
  id: this.props.figure.id,
27961
28023
  });
27962
28024
  },
@@ -28200,10 +28262,7 @@ class FiguresContainer extends owl.Component {
28200
28262
  return;
28201
28263
  }
28202
28264
  if (this.props.sidePanelIsOpen) {
28203
- this.env.openSidePanel("ChartPanel", {
28204
- sheetId: this.env.getters.getActiveSheetId(),
28205
- figure,
28206
- });
28265
+ this.env.openSidePanel("ChartPanel", { figure });
28207
28266
  }
28208
28267
  const initialX = ev.clientX;
28209
28268
  const initialY = ev.clientY;
@@ -31297,6 +31356,6 @@ exports.registries = registries;
31297
31356
  exports.setTranslationMethod = setTranslationMethod;
31298
31357
 
31299
31358
 
31300
- __info__.version = '15.0.0';
31301
- __info__.date = '2023-02-27T14:03:17.561Z';
31302
- __info__.hash = '2d1cea1';
31359
+ __info__.version = '15.0.1';
31360
+ __info__.date = '2023-03-06T07:16:47.732Z';
31361
+ __info__.hash = 'de03e1c';