@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.
@@ -1387,6 +1387,7 @@
1387
1387
  CommandResult[CommandResult["FigureDoesNotExist"] = 55] = "FigureDoesNotExist";
1388
1388
  CommandResult[CommandResult["DuplicatedFigureId"] = 56] = "DuplicatedFigureId";
1389
1389
  CommandResult[CommandResult["DuplicatedChartId"] = 57] = "DuplicatedChartId";
1390
+ CommandResult[CommandResult["ChartDoesNotExist"] = 58] = "ChartDoesNotExist";
1390
1391
  })(exports.CommandResult || (exports.CommandResult = {}));
1391
1392
 
1392
1393
  var ReturnFormatType;
@@ -8474,13 +8475,7 @@
8474
8475
  data = migrate(data);
8475
8476
  }
8476
8477
  }
8477
- // sanity check: try to fix missing fields/corrupted state by providing
8478
- // sensible default values
8479
- data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8480
- data.sheets = data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s));
8481
- if (data.sheets.length === 0) {
8482
- data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8483
- }
8478
+ data = repairData(data);
8484
8479
  return data;
8485
8480
  }
8486
8481
  function migrate(data) {
@@ -8689,6 +8684,48 @@
8689
8684
  },
8690
8685
  },
8691
8686
  ];
8687
+ /**
8688
+ * This function is used to repair faulty data independently of the migration.
8689
+ */
8690
+ function repairData(data) {
8691
+ data = forceUnicityOfFigure(data);
8692
+ data = setDefaults(data);
8693
+ return data;
8694
+ }
8695
+ /**
8696
+ * Force the unicity of figure ids accross sheets
8697
+ */
8698
+ function forceUnicityOfFigure(data) {
8699
+ if (data.uniqueFigureIds) {
8700
+ return data;
8701
+ }
8702
+ const figureIds = new Set();
8703
+ const uuidGenerator = new UuidGenerator();
8704
+ for (const sheet of data.sheets || []) {
8705
+ for (const figure of sheet.figures || []) {
8706
+ if (figureIds.has(figure.id)) {
8707
+ figure.id += uuidGenerator.uuidv4();
8708
+ }
8709
+ figureIds.add(figure.id);
8710
+ }
8711
+ }
8712
+ data.uniqueFigureIds = true;
8713
+ return data;
8714
+ }
8715
+ /**
8716
+ * sanity check: try to fix missing fields/corrupted state by providing
8717
+ * sensible default values
8718
+ */
8719
+ function setDefaults(data) {
8720
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8721
+ data.sheets = data.sheets
8722
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
8723
+ : [];
8724
+ if (data.sheets.length === 0) {
8725
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8726
+ }
8727
+ return data;
8728
+ }
8692
8729
  /**
8693
8730
  * The goal of this function is to repair corrupted/wrong initial messages caused by
8694
8731
  * a bug.
@@ -8775,6 +8812,7 @@
8775
8812
  styles: {},
8776
8813
  borders: {},
8777
8814
  revisionId: DEFAULT_REVISION_ID,
8815
+ uniqueFigureIds: true,
8778
8816
  };
8779
8817
  return data;
8780
8818
  }
@@ -9805,34 +9843,32 @@
9805
9843
  this.chartFigures = {};
9806
9844
  }
9807
9845
  adaptRanges(applyChange) {
9808
- for (const sheetId of Object.keys(this.chartFigures)) {
9809
- for (const [chartId, chart] of Object.entries(this.chartFigures[sheetId] || {})) {
9810
- if (chart) {
9811
- this.adaptDataSetRanges(sheetId, chart, chartId, applyChange);
9812
- this.adaptLabelRanges(sheetId, chart, chartId, applyChange);
9813
- }
9846
+ for (let [chartId, chart] of Object.entries(this.chartFigures)) {
9847
+ if (chart) {
9848
+ this.adaptDataSetRanges(chart, chartId, applyChange);
9849
+ this.adaptLabelRanges(chart, chartId, applyChange);
9814
9850
  }
9815
9851
  }
9816
9852
  }
9817
- adaptDataSetRanges(sheetId, chart, chartId, applyChange) {
9853
+ adaptDataSetRanges(chart, chartId, applyChange) {
9818
9854
  for (let ds of chart.dataSets) {
9819
9855
  if (ds.labelCell) {
9820
9856
  const labelCellChange = applyChange(ds.labelCell);
9821
9857
  switch (labelCellChange.changeType) {
9822
9858
  case "REMOVE":
9823
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9859
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9824
9860
  break;
9825
9861
  case "RESIZE":
9826
9862
  case "MOVE":
9827
9863
  case "CHANGE":
9828
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9864
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9829
9865
  }
9830
9866
  }
9831
9867
  const dataRangeChange = applyChange(ds.dataRange);
9832
9868
  switch (dataRangeChange.changeType) {
9833
9869
  case "REMOVE":
9834
9870
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9835
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9871
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9836
9872
  break;
9837
9873
  case "RESIZE":
9838
9874
  case "MOVE":
@@ -9840,27 +9876,27 @@
9840
9876
  // We have to remove the ranges that are #REF
9841
9877
  if (this.getters.getRangeString(dataRangeChange.range, dataRangeChange.range.sheetId) !==
9842
9878
  INCORRECT_RANGE_STRING) {
9843
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9879
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9844
9880
  }
9845
9881
  else {
9846
9882
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9847
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9883
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9848
9884
  }
9849
9885
  break;
9850
9886
  }
9851
9887
  }
9852
9888
  }
9853
- adaptLabelRanges(sheetId, chart, chartId, applyChange) {
9889
+ adaptLabelRanges(chart, chartId, applyChange) {
9854
9890
  if (chart.labelRange) {
9855
9891
  const labelRangeChange = applyChange(chart.labelRange);
9856
9892
  switch (labelRangeChange.changeType) {
9857
9893
  case "REMOVE":
9858
- this.history.update("chartFigures", sheetId, chartId, "labelRange", undefined);
9894
+ this.history.update("chartFigures", chartId, "labelRange", undefined);
9859
9895
  break;
9860
9896
  case "RESIZE":
9861
9897
  case "MOVE":
9862
9898
  case "CHANGE":
9863
- this.history.update("chartFigures", sheetId, chartId, "labelRange", labelRangeChange.range);
9899
+ this.history.update("chartFigures", chartId, "labelRange", labelRangeChange.range);
9864
9900
  break;
9865
9901
  }
9866
9902
  }
@@ -9871,16 +9907,16 @@
9871
9907
  allowDispatch(cmd) {
9872
9908
  const success = 0 /* Success */;
9873
9909
  switch (cmd.type) {
9874
- case "CREATE_CHART":
9875
- return this.checkValidations(cmd, this.chainValidations(this.checkChartDuplicate, this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9876
9910
  case "UPDATE_CHART":
9877
- return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9911
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartExists), this.checkLabelRange);
9912
+ case "CREATE_CHART":
9913
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartDuplicate), this.checkLabelRange);
9878
9914
  default:
9879
9915
  return success;
9880
9916
  }
9881
9917
  }
9882
9918
  handle(cmd) {
9883
- var _a;
9919
+ var _a, _b;
9884
9920
  switch (cmd.type) {
9885
9921
  case "CREATE_CHART":
9886
9922
  const x = cmd.position ? cmd.position.x : 0;
@@ -9895,7 +9931,7 @@
9895
9931
  });
9896
9932
  break;
9897
9933
  case "UPDATE_CHART": {
9898
- this.updateChartDefinition(cmd.sheetId, cmd.id, cmd.definition);
9934
+ this.updateChartDefinition(cmd.id, cmd.definition);
9899
9935
  break;
9900
9936
  }
9901
9937
  case "DUPLICATE_SHEET": {
@@ -9905,7 +9941,7 @@
9905
9941
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
9906
9942
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
9907
9943
  const chartDefinition = {
9908
- ...deepCopy(this.chartFigures[cmd.sheetId][fig.id]),
9944
+ ...deepCopy(this.chartFigures[fig.id]),
9909
9945
  id: duplicatedFigureId,
9910
9946
  };
9911
9947
  chartDefinition.sheetId = cmd.sheetIdTo;
@@ -9935,28 +9971,37 @@
9935
9971
  break;
9936
9972
  }
9937
9973
  case "DELETE_FIGURE":
9938
- this.history.update("chartFigures", cmd.sheetId, cmd.id, undefined);
9974
+ this.history.update("chartFigures", cmd.id, undefined);
9939
9975
  break;
9940
9976
  case "DELETE_SHEET":
9941
- this.history.update("chartFigures", cmd.sheetId, undefined);
9977
+ for (let id of Object.keys(this.chartFigures)) {
9978
+ if (((_b = this.chartFigures[id]) === null || _b === void 0 ? void 0 : _b.sheetId) === cmd.sheetId) {
9979
+ this.history.update("chartFigures", id, undefined);
9980
+ }
9981
+ }
9942
9982
  break;
9943
9983
  }
9944
9984
  }
9945
9985
  // ---------------------------------------------------------------------------
9946
9986
  // Getters
9947
9987
  // ---------------------------------------------------------------------------
9948
- getChartDefinition(sheetId, figureId) {
9949
- var _a;
9950
- return (_a = this.chartFigures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
9988
+ getChartDefinition(figureId) {
9989
+ return this.chartFigures[figureId];
9951
9990
  }
9952
- getChartDefinitionsBySheet(sheetId) {
9953
- return Object.values(this.chartFigures[sheetId] || {}).filter(isDefined);
9991
+ getChartsIdBySheet(sheetId) {
9992
+ return Object.entries(this.chartFigures)
9993
+ .filter((chart) => {
9994
+ return chart[1].sheetId === sheetId;
9995
+ })
9996
+ .map((chart) => chart[0]);
9954
9997
  }
9955
- getChartDefinitionUI(sheetId, figureId, forceSheetName = false) {
9956
- const data = this.chartFigures[sheetId][figureId];
9957
- const rangeSheetId = forceSheetName ? "forceSheetReference" : sheetId;
9998
+ getChartDefinitionUI(sheetId, figureId) {
9999
+ const data = this.chartFigures[figureId];
10000
+ if (!data) {
10001
+ return undefined;
10002
+ }
9958
10003
  const dataSets = data.dataSets
9959
- .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, rangeSheetId) : ""))
10004
+ .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, sheetId) : ""))
9960
10005
  .filter((ds) => {
9961
10006
  return ds !== ""; // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9962
10007
  });
@@ -9964,7 +10009,7 @@
9964
10009
  title: data && data.title ? data.title : "",
9965
10010
  dataSets,
9966
10011
  labelRange: data.labelRange
9967
- ? this.getters.getRangeString(data.labelRange, rangeSheetId)
10012
+ ? this.getters.getRangeString(data.labelRange, sheetId)
9968
10013
  : undefined,
9969
10014
  type: data ? data.type : "bar",
9970
10015
  dataSetsHaveTitle: data && dataSets.length !== 0 ? Boolean(data.dataSets[0].labelCell) : false,
@@ -9975,12 +10020,16 @@
9975
10020
  };
9976
10021
  }
9977
10022
  getChartDefinitionExcel(sheetId, figureId) {
9978
- const data = this.chartFigures[sheetId][figureId];
10023
+ const data = this.chartFigures[figureId];
10024
+ const dataUI = this.getChartDefinitionUI("forceSheetReference", figureId);
10025
+ if (!data || !dataUI) {
10026
+ return undefined;
10027
+ }
9979
10028
  const dataSets = data.dataSets
9980
10029
  .map((ds) => this.toExcelDataset(ds))
9981
10030
  .filter((ds) => ds.range !== ""); // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9982
10031
  return {
9983
- ...this.getChartDefinitionUI(sheetId, figureId, true),
10032
+ ...dataUI,
9984
10033
  backgroundColor: data.background,
9985
10034
  dataSets,
9986
10035
  };
@@ -10015,17 +10064,15 @@
10015
10064
  import(data) {
10016
10065
  for (let sheet of data.sheets) {
10017
10066
  if (sheet.figures) {
10018
- const charts = {};
10019
10067
  for (let figure of sheet.figures) {
10020
10068
  if (figure.tag === "chart") {
10021
10069
  const figureData = {
10022
10070
  ...figure.data,
10023
10071
  };
10024
- charts[figure.id] = this.createChartDefinition(figureData, sheet.id);
10072
+ this.chartFigures[figure.id] = this.createChartDefinition(figureData, sheet.id);
10025
10073
  delete figure.data;
10026
10074
  }
10027
10075
  }
10028
- this.chartFigures[sheet.id] = charts;
10029
10076
  }
10030
10077
  }
10031
10078
  }
@@ -10033,10 +10080,18 @@
10033
10080
  if (data.sheets) {
10034
10081
  for (let sheet of data.sheets) {
10035
10082
  const sheetFigures = this.getters.getFigures(sheet.id);
10036
- const figures = sheetFigures;
10037
- for (let figure of figures) {
10083
+ const figures = [];
10084
+ for (let sheetFigure of sheetFigures) {
10085
+ const figure = sheetFigure;
10038
10086
  if (figure && figure.tag === "chart") {
10039
- figure.data = this.getChartDefinitionUI(sheet.id, figure.id);
10087
+ const data = this.getChartDefinitionUI(sheet.id, figure.id);
10088
+ if (data) {
10089
+ figure.data = data;
10090
+ figures.push(figure);
10091
+ }
10092
+ }
10093
+ else {
10094
+ figures.push(figure);
10040
10095
  }
10041
10096
  }
10042
10097
  sheet.figures = figures;
@@ -10046,10 +10101,18 @@
10046
10101
  exportForExcel(data) {
10047
10102
  for (let sheet of data.sheets) {
10048
10103
  const sheetFigures = this.getters.getFigures(sheet.id);
10049
- const figures = sheetFigures;
10050
- for (let figure of figures) {
10104
+ const figures = [];
10105
+ for (let sheetFigure of sheetFigures) {
10106
+ const figure = sheetFigure;
10051
10107
  if (figure && figure.tag === "chart") {
10052
- figure.data = this.getChartDefinitionExcel(sheet.id, figure.id);
10108
+ const data = this.getChartDefinitionExcel(sheet.id, figure.id);
10109
+ if (data) {
10110
+ figure.data = data;
10111
+ figures.push(figure);
10112
+ }
10113
+ }
10114
+ else {
10115
+ figures.push(figure);
10053
10116
  }
10054
10117
  }
10055
10118
  sheet.charts = figures;
@@ -10075,39 +10138,39 @@
10075
10138
  * Update the chart definition linked to the given id with the attributes
10076
10139
  * given in the partial UI definition
10077
10140
  */
10078
- updateChartDefinition(sheetId, id, definition) {
10079
- const chart = this.chartFigures[sheetId][id];
10141
+ updateChartDefinition(id, definition) {
10142
+ const chart = this.chartFigures[id];
10080
10143
  if (!chart) {
10081
10144
  throw new Error(`There is no chart with the given id: ${id}`);
10082
10145
  }
10083
10146
  if (definition.title !== undefined) {
10084
- this.history.update("chartFigures", sheetId, id, "title", definition.title);
10147
+ this.history.update("chartFigures", id, "title", definition.title);
10085
10148
  }
10086
10149
  if (definition.type) {
10087
- this.history.update("chartFigures", sheetId, id, "type", definition.type);
10150
+ this.history.update("chartFigures", id, "type", definition.type);
10088
10151
  }
10089
10152
  if (definition.dataSets) {
10090
10153
  const dataSetsHaveTitle = !!definition.dataSetsHaveTitle;
10091
10154
  const dataSets = this.createDataSets(definition.dataSets, chart.sheetId, dataSetsHaveTitle);
10092
- this.history.update("chartFigures", sheetId, id, "dataSets", dataSets);
10155
+ this.history.update("chartFigures", id, "dataSets", dataSets);
10093
10156
  }
10094
10157
  if (definition.labelRange !== undefined) {
10095
10158
  const labelRange = definition.labelRange
10096
10159
  ? this.getters.getRangeFromSheetXC(chart.sheetId, definition.labelRange)
10097
10160
  : undefined;
10098
- this.history.update("chartFigures", sheetId, id, "labelRange", labelRange);
10161
+ this.history.update("chartFigures", id, "labelRange", labelRange);
10099
10162
  }
10100
10163
  if (definition.background) {
10101
- this.history.update("chartFigures", sheetId, id, "background", definition.background);
10164
+ this.history.update("chartFigures", id, "background", definition.background);
10102
10165
  }
10103
10166
  if (definition.verticalAxisPosition) {
10104
- this.history.update("chartFigures", sheetId, id, "verticalAxisPosition", definition.verticalAxisPosition);
10167
+ this.history.update("chartFigures", id, "verticalAxisPosition", definition.verticalAxisPosition);
10105
10168
  }
10106
10169
  if (definition.legendPosition) {
10107
- this.history.update("chartFigures", sheetId, id, "legendPosition", definition.legendPosition);
10170
+ this.history.update("chartFigures", id, "legendPosition", definition.legendPosition);
10108
10171
  }
10109
10172
  if (definition.stackedBar !== undefined) {
10110
- this.history.update("chartFigures", sheetId, id, "stackedBar", definition.stackedBar);
10173
+ this.history.update("chartFigures", id, "stackedBar", definition.stackedBar);
10111
10174
  }
10112
10175
  }
10113
10176
  createDataSets(dataSetsString, sheetId, dataSetsHaveTitle) {
@@ -10162,7 +10225,7 @@
10162
10225
  sheetId,
10163
10226
  figure,
10164
10227
  });
10165
- this.history.update("chartFigures", sheetId, figure.id, data);
10228
+ this.history.update("chartFigures", figure.id, data);
10166
10229
  }
10167
10230
  createDataSet(sheetId, fullZone, titleZone) {
10168
10231
  if (fullZone.left !== fullZone.right && fullZone.top !== fullZone.bottom) {
@@ -10203,14 +10266,20 @@
10203
10266
  return invalidLabels ? 29 /* InvalidLabelRange */ : 0 /* Success */;
10204
10267
  }
10205
10268
  checkChartDuplicate(cmd) {
10206
- var _a;
10207
- if ((_a = this.chartFigures[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[cmd.id]) {
10208
- return 57 /* DuplicatedChartId */;
10269
+ for (const sheet of this.getters.getSheets()) {
10270
+ if (this.getters.getFigure(sheet.id, cmd.id)) {
10271
+ return 57 /* DuplicatedChartId */;
10272
+ }
10209
10273
  }
10210
10274
  return 0 /* Success */;
10211
10275
  }
10276
+ checkChartExists(cmd) {
10277
+ return this.getters.getFigure(cmd.sheetId, cmd.id)
10278
+ ? 0 /* Success */
10279
+ : 58 /* ChartDoesNotExist */;
10280
+ }
10212
10281
  }
10213
- ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartDefinitionsBySheet"];
10282
+ ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartsIdBySheet"];
10214
10283
 
10215
10284
  // -----------------------------------------------------------------------------
10216
10285
  // Constants
@@ -10549,7 +10618,7 @@
10549
10618
  allowDispatch(cmd) {
10550
10619
  switch (cmd.type) {
10551
10620
  case "CREATE_FIGURE":
10552
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
10621
+ return this.checkFigureDuplicate(cmd.figure.id);
10553
10622
  case "UPDATE_FIGURE":
10554
10623
  case "DELETE_FIGURE":
10555
10624
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -10615,9 +10684,8 @@
10615
10684
  }
10616
10685
  return 0 /* Success */;
10617
10686
  }
10618
- checkFigureDuplicate(sheetId, figureId) {
10619
- var _a;
10620
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
10687
+ checkFigureDuplicate(figureId) {
10688
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
10621
10689
  return 56 /* DuplicatedFigureId */;
10622
10690
  }
10623
10691
  return 0 /* Success */;
@@ -10632,6 +10700,9 @@
10632
10700
  var _a;
10633
10701
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
10634
10702
  }
10703
+ getFigureSheetId(figureId) {
10704
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
10705
+ }
10635
10706
  // ---------------------------------------------------------------------------
10636
10707
  // Import/Export
10637
10708
  // ---------------------------------------------------------------------------
@@ -10656,7 +10727,7 @@
10656
10727
  this.export(data);
10657
10728
  }
10658
10729
  }
10659
- FigurePlugin.getters = ["getFigures", "getFigure"];
10730
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
10660
10731
 
10661
10732
  class MergePlugin extends CorePlugin {
10662
10733
  constructor() {
@@ -12818,7 +12889,7 @@
12818
12889
  },
12819
12890
  });
12820
12891
  const figure = env.getters.getFigure(sheetId, id);
12821
- env.openSidePanel("ChartPanel", { sheetId, figure });
12892
+ env.openSidePanel("ChartPanel", { figure });
12822
12893
  };
12823
12894
  //------------------------------------------------------------------------------
12824
12895
  // Style/Format
@@ -14315,19 +14386,21 @@
14315
14386
  constructor() {
14316
14387
  super(...arguments);
14317
14388
  this.getters = this.env.getters;
14389
+ this.chartSheetId = this.findSheetId(this.props.figure.id);
14318
14390
  this.state = owl.useState(this.initialState(this.props.figure));
14319
14391
  }
14320
14392
  async willUpdateProps(nextProps) {
14321
- if (!this.getters.getChartDefinition(nextProps.sheetId, nextProps.figure.id)) {
14393
+ if (!this.getters.getChartDefinition(nextProps.figure.id)) {
14322
14394
  this.trigger("close-side-panel");
14323
14395
  return;
14324
14396
  }
14325
14397
  if (nextProps.figure.id !== this.props.figure.id) {
14398
+ this.chartSheetId = this.findSheetId(nextProps.figure.id);
14326
14399
  this.state.panel = "configuration";
14327
14400
  this.state.fillColorTool = false;
14328
14401
  this.state.datasetDispatchResult = undefined;
14329
14402
  this.state.labelsDispatchResult = undefined;
14330
- this.state.chart = this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), nextProps.figure.id);
14403
+ this.state.chart = this.env.getters.getChartDefinitionUI(this.chartSheetId, nextProps.figure.id);
14331
14404
  }
14332
14405
  }
14333
14406
  get errorMessages() {
@@ -14374,7 +14447,7 @@
14374
14447
  updateChart(definition) {
14375
14448
  return this.env.dispatch("UPDATE_CHART", {
14376
14449
  id: this.props.figure.id,
14377
- sheetId: this.props.sheetId,
14450
+ sheetId: this.chartSheetId,
14378
14451
  definition,
14379
14452
  });
14380
14453
  }
@@ -14396,12 +14469,16 @@
14396
14469
  this.state.panel = panel;
14397
14470
  }
14398
14471
  initialState(figure) {
14472
+ const sheetId = this.findSheetId(figure.id);
14399
14473
  return {
14400
- chart: this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), figure.id),
14474
+ chart: this.env.getters.getChartDefinitionUI(sheetId, figure.id),
14401
14475
  panel: "configuration",
14402
14476
  fillColorTool: false,
14403
14477
  };
14404
14478
  }
14479
+ findSheetId(figureId) {
14480
+ return this.env.getters.getFigureSheetId(figureId) || "";
14481
+ }
14405
14482
  }
14406
14483
  ChartPanel.template = TEMPLATE$p;
14407
14484
  ChartPanel.style = STYLE;
@@ -18815,60 +18892,51 @@
18815
18892
  this.outOfDate = new Set();
18816
18893
  }
18817
18894
  handle(cmd) {
18818
- var _a;
18819
18895
  if (invalidateEvaluationCommands.has(cmd.type) ||
18820
18896
  cmd.type === "EVALUATE_CELLS" ||
18821
18897
  (cmd.type === "UPDATE_CELL" && "content" in cmd)) {
18822
- for (const sheetId of Object.keys(this.chartRuntime)) {
18823
- for (const chartId of Object.keys(this.chartRuntime[sheetId] || {})) {
18824
- this.outOfDate.add(chartId);
18825
- }
18898
+ for (let chartId of Object.keys(this.chartRuntime)) {
18899
+ this.outOfDate.add(chartId);
18826
18900
  }
18827
18901
  }
18828
18902
  switch (cmd.type) {
18829
18903
  case "UPDATE_CHART":
18830
- case "CREATE_CHART": {
18831
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18832
- if (!this.chartRuntime[cmd.sheetId])
18833
- this.chartRuntime[cmd.sheetId] = {};
18834
- this.chartRuntime[cmd.sheetId][cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18904
+ case "CREATE_CHART":
18905
+ const chartDefinition = this.getters.getChartDefinition(cmd.id);
18906
+ this.chartRuntime[cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18835
18907
  break;
18836
- }
18837
18908
  case "DELETE_FIGURE":
18838
- (_a = this.chartRuntime[cmd.sheetId]) === null || _a === void 0 ? true : delete _a[cmd.id];
18909
+ delete this.chartRuntime[cmd.id];
18839
18910
  break;
18840
- case "REFRESH_CHART": {
18841
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18842
- this.evaluateUsedSheets([chartDefinition]);
18911
+ case "REFRESH_CHART":
18912
+ this.evaluateUsedSheets([cmd.id]);
18843
18913
  this.outOfDate.add(cmd.id);
18844
18914
  break;
18845
- }
18846
- case "ACTIVATE_SHEET": {
18847
- const chartsDefinitions = this.getters.getChartDefinitionsBySheet(cmd.sheetIdTo);
18848
- this.evaluateUsedSheets(chartsDefinitions);
18915
+ case "ACTIVATE_SHEET":
18916
+ const chartsIds = this.getters.getChartsIdBySheet(cmd.sheetIdTo);
18917
+ this.evaluateUsedSheets(chartsIds);
18849
18918
  break;
18850
- }
18851
18919
  case "DELETE_SHEET":
18852
- delete this.chartRuntime[cmd.sheetId];
18920
+ for (let chartId of Object.keys(this.chartRuntime)) {
18921
+ if (!this.getters.getChartDefinition(chartId)) {
18922
+ delete this.chartRuntime[chartId];
18923
+ }
18924
+ }
18853
18925
  break;
18854
18926
  }
18855
18927
  }
18856
18928
  // ---------------------------------------------------------------------------
18857
18929
  // Getters
18858
18930
  // ---------------------------------------------------------------------------
18859
- getChartRuntime(sheetId, figureId) {
18860
- if (this.outOfDate.has(figureId) ||
18861
- !(sheetId in this.chartRuntime) ||
18862
- !(figureId in this.chartRuntime[sheetId])) {
18863
- const chartDefinition = this.getters.getChartDefinition(sheetId, figureId);
18931
+ getChartRuntime(figureId) {
18932
+ if (this.outOfDate.has(figureId) || !(figureId in this.chartRuntime)) {
18933
+ const chartDefinition = this.getters.getChartDefinition(figureId);
18864
18934
  if (chartDefinition === undefined)
18865
18935
  return;
18866
- if (!this.chartRuntime[sheetId])
18867
- this.chartRuntime[sheetId] = {};
18868
- this.chartRuntime[sheetId][figureId] = this.mapDefinitionToRuntime(chartDefinition);
18936
+ this.chartRuntime[figureId] = this.mapDefinitionToRuntime(chartDefinition);
18869
18937
  this.outOfDate.delete(figureId);
18870
18938
  }
18871
- return this.chartRuntime[sheetId][figureId];
18939
+ return this.chartRuntime[figureId];
18872
18940
  }
18873
18941
  truncateLabel(label) {
18874
18942
  if (!label) {
@@ -18973,9 +19041,10 @@
18973
19041
  }
18974
19042
  return sheetIds;
18975
19043
  }
18976
- evaluateUsedSheets(chartsDefinitions) {
19044
+ evaluateUsedSheets(chartsIds) {
18977
19045
  const usedSheetsId = new Set();
18978
- for (const chartDefinition of chartsDefinitions) {
19046
+ for (let chartId of chartsIds) {
19047
+ const chartDefinition = this.getters.getChartDefinition(chartId);
18979
19048
  const sheetsIds = chartDefinition !== undefined ? this.getSheetIdsUsedInChart(chartDefinition) : [];
18980
19049
  sheetsIds.forEach((sheetId) => {
18981
19050
  if (sheetId !== this.getters.getActiveSheetId()) {
@@ -27872,7 +27941,7 @@
27872
27941
  }
27873
27942
  mounted() {
27874
27943
  const figure = this.props.figure;
27875
- const chartData = this.env.getters.getChartRuntime(this.env.getters.getActiveSheetId(), figure.id);
27944
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27876
27945
  if (chartData) {
27877
27946
  this.createChart(chartData);
27878
27947
  }
@@ -27880,8 +27949,7 @@
27880
27949
  patched() {
27881
27950
  var _a, _b, _c;
27882
27951
  const figure = this.props.figure;
27883
- const sheetId = this.env.getters.getActiveSheetId();
27884
- const chartData = this.env.getters.getChartRuntime(sheetId, figure.id);
27952
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27885
27953
  if (chartData) {
27886
27954
  if (chartData.type !== this.chart.config.type) {
27887
27955
  // Updating a chart type requires to update its options accordingly, if feasible at all.
@@ -27907,7 +27975,7 @@
27907
27975
  else {
27908
27976
  this.chart && this.chart.destroy();
27909
27977
  }
27910
- const def = this.env.getters.getChartDefinition(sheetId, figure.id);
27978
+ const def = this.env.getters.getChartDefinition(figure.id);
27911
27979
  if (def) {
27912
27980
  this.state.background = def.background;
27913
27981
  }
@@ -27916,7 +27984,7 @@
27916
27984
  const canvas = this.canvas.el;
27917
27985
  const ctx = canvas.getContext("2d");
27918
27986
  this.chart = new window.Chart(ctx, chartData);
27919
- const def = this.env.getters.getChartDefinition(this.env.getters.getActiveSheetId(), this.props.figure.id);
27987
+ const def = this.env.getters.getChartDefinition(this.props.figure.id);
27920
27988
  if (def) {
27921
27989
  this.state.background = def.background;
27922
27990
  }
@@ -27926,10 +27994,8 @@
27926
27994
  registry.add("edit", {
27927
27995
  name: _lt("Edit"),
27928
27996
  sequence: 1,
27929
- action: () => this.env.openSidePanel("ChartPanel", {
27930
- sheetId: this.env.getters.getActiveSheetId(),
27931
- figure: this.props.figure,
27932
- }),
27997
+ action: () => this.env.openSidePanel("ChartPanel", { figure: this.props.figure }),
27998
+ isVisible: () => !!this.env.getters.getChartDefinition(this.props.figure.id),
27933
27999
  });
27934
28000
  registry.add("delete", {
27935
28001
  name: _lt("Delete"),
@@ -27940,10 +28006,7 @@
27940
28006
  id: this.props.figure.id,
27941
28007
  });
27942
28008
  if (this.props.sidePanelIsOpen) {
27943
- this.env.toggleSidePanel("ChartPanel", {
27944
- sheetId: this.env.getters.getActiveSheetId(),
27945
- figure: this.props.figure,
27946
- });
28009
+ this.env.toggleSidePanel("ChartPanel", { figure: this.props.figure });
27947
28010
  }
27948
28011
  this.trigger("figure-deleted");
27949
28012
  },
@@ -27953,7 +28016,6 @@
27953
28016
  sequence: 11,
27954
28017
  action: () => {
27955
28018
  this.env.dispatch("REFRESH_CHART", {
27956
- sheetId: this.env.getters.getActiveSheetId(),
27957
28019
  id: this.props.figure.id,
27958
28020
  });
27959
28021
  },
@@ -28197,10 +28259,7 @@
28197
28259
  return;
28198
28260
  }
28199
28261
  if (this.props.sidePanelIsOpen) {
28200
- this.env.openSidePanel("ChartPanel", {
28201
- sheetId: this.env.getters.getActiveSheetId(),
28202
- figure,
28203
- });
28262
+ this.env.openSidePanel("ChartPanel", { figure });
28204
28263
  }
28205
28264
  const initialX = ev.clientX;
28206
28265
  const initialY = ev.clientY;
@@ -31296,9 +31355,9 @@
31296
31355
  Object.defineProperty(exports, '__esModule', { value: true });
31297
31356
 
31298
31357
 
31299
- __info__.version = '15.0.0';
31300
- __info__.date = '2023-02-27T14:03:17.561Z';
31301
- __info__.hash = '2d1cea1';
31358
+ __info__.version = '15.0.1';
31359
+ __info__.date = '2023-03-06T07:16:47.732Z';
31360
+ __info__.hash = 'de03e1c';
31302
31361
 
31303
31362
 
31304
31363
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);