@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.
@@ -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;
@@ -8454,13 +8455,7 @@ function load(data) {
8454
8455
  data = migrate(data);
8455
8456
  }
8456
8457
  }
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
- }
8458
+ data = repairData(data);
8464
8459
  return data;
8465
8460
  }
8466
8461
  function migrate(data) {
@@ -8669,6 +8664,48 @@ const MIGRATIONS = [
8669
8664
  },
8670
8665
  },
8671
8666
  ];
8667
+ /**
8668
+ * This function is used to repair faulty data independently of the migration.
8669
+ */
8670
+ function repairData(data) {
8671
+ data = forceUnicityOfFigure(data);
8672
+ data = setDefaults(data);
8673
+ return data;
8674
+ }
8675
+ /**
8676
+ * Force the unicity of figure ids accross sheets
8677
+ */
8678
+ function forceUnicityOfFigure(data) {
8679
+ if (data.uniqueFigureIds) {
8680
+ return data;
8681
+ }
8682
+ const figureIds = new Set();
8683
+ const uuidGenerator = new UuidGenerator();
8684
+ for (const sheet of data.sheets || []) {
8685
+ for (const figure of sheet.figures || []) {
8686
+ if (figureIds.has(figure.id)) {
8687
+ figure.id += uuidGenerator.uuidv4();
8688
+ }
8689
+ figureIds.add(figure.id);
8690
+ }
8691
+ }
8692
+ data.uniqueFigureIds = true;
8693
+ return data;
8694
+ }
8695
+ /**
8696
+ * sanity check: try to fix missing fields/corrupted state by providing
8697
+ * sensible default values
8698
+ */
8699
+ function setDefaults(data) {
8700
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8701
+ data.sheets = data.sheets
8702
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
8703
+ : [];
8704
+ if (data.sheets.length === 0) {
8705
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8706
+ }
8707
+ return data;
8708
+ }
8672
8709
  /**
8673
8710
  * The goal of this function is to repair corrupted/wrong initial messages caused by
8674
8711
  * a bug.
@@ -8755,6 +8792,7 @@ function createEmptyWorkbookData(sheetName = "Sheet1") {
8755
8792
  styles: {},
8756
8793
  borders: {},
8757
8794
  revisionId: DEFAULT_REVISION_ID,
8795
+ uniqueFigureIds: true,
8758
8796
  };
8759
8797
  return data;
8760
8798
  }
@@ -9785,34 +9823,32 @@ class ChartPlugin extends CorePlugin {
9785
9823
  this.chartFigures = {};
9786
9824
  }
9787
9825
  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
- }
9826
+ for (let [chartId, chart] of Object.entries(this.chartFigures)) {
9827
+ if (chart) {
9828
+ this.adaptDataSetRanges(chart, chartId, applyChange);
9829
+ this.adaptLabelRanges(chart, chartId, applyChange);
9794
9830
  }
9795
9831
  }
9796
9832
  }
9797
- adaptDataSetRanges(sheetId, chart, chartId, applyChange) {
9833
+ adaptDataSetRanges(chart, chartId, applyChange) {
9798
9834
  for (let ds of chart.dataSets) {
9799
9835
  if (ds.labelCell) {
9800
9836
  const labelCellChange = applyChange(ds.labelCell);
9801
9837
  switch (labelCellChange.changeType) {
9802
9838
  case "REMOVE":
9803
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9839
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9804
9840
  break;
9805
9841
  case "RESIZE":
9806
9842
  case "MOVE":
9807
9843
  case "CHANGE":
9808
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9844
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9809
9845
  }
9810
9846
  }
9811
9847
  const dataRangeChange = applyChange(ds.dataRange);
9812
9848
  switch (dataRangeChange.changeType) {
9813
9849
  case "REMOVE":
9814
9850
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9815
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9851
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9816
9852
  break;
9817
9853
  case "RESIZE":
9818
9854
  case "MOVE":
@@ -9820,27 +9856,27 @@ class ChartPlugin extends CorePlugin {
9820
9856
  // We have to remove the ranges that are #REF
9821
9857
  if (this.getters.getRangeString(dataRangeChange.range, dataRangeChange.range.sheetId) !==
9822
9858
  INCORRECT_RANGE_STRING) {
9823
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9859
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9824
9860
  }
9825
9861
  else {
9826
9862
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9827
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9863
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9828
9864
  }
9829
9865
  break;
9830
9866
  }
9831
9867
  }
9832
9868
  }
9833
- adaptLabelRanges(sheetId, chart, chartId, applyChange) {
9869
+ adaptLabelRanges(chart, chartId, applyChange) {
9834
9870
  if (chart.labelRange) {
9835
9871
  const labelRangeChange = applyChange(chart.labelRange);
9836
9872
  switch (labelRangeChange.changeType) {
9837
9873
  case "REMOVE":
9838
- this.history.update("chartFigures", sheetId, chartId, "labelRange", undefined);
9874
+ this.history.update("chartFigures", chartId, "labelRange", undefined);
9839
9875
  break;
9840
9876
  case "RESIZE":
9841
9877
  case "MOVE":
9842
9878
  case "CHANGE":
9843
- this.history.update("chartFigures", sheetId, chartId, "labelRange", labelRangeChange.range);
9879
+ this.history.update("chartFigures", chartId, "labelRange", labelRangeChange.range);
9844
9880
  break;
9845
9881
  }
9846
9882
  }
@@ -9851,16 +9887,16 @@ class ChartPlugin extends CorePlugin {
9851
9887
  allowDispatch(cmd) {
9852
9888
  const success = 0 /* Success */;
9853
9889
  switch (cmd.type) {
9854
- case "CREATE_CHART":
9855
- return this.checkValidations(cmd, this.chainValidations(this.checkChartDuplicate, this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9856
9890
  case "UPDATE_CHART":
9857
- return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9891
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartExists), this.checkLabelRange);
9892
+ case "CREATE_CHART":
9893
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartDuplicate), this.checkLabelRange);
9858
9894
  default:
9859
9895
  return success;
9860
9896
  }
9861
9897
  }
9862
9898
  handle(cmd) {
9863
- var _a;
9899
+ var _a, _b;
9864
9900
  switch (cmd.type) {
9865
9901
  case "CREATE_CHART":
9866
9902
  const x = cmd.position ? cmd.position.x : 0;
@@ -9875,7 +9911,7 @@ class ChartPlugin extends CorePlugin {
9875
9911
  });
9876
9912
  break;
9877
9913
  case "UPDATE_CHART": {
9878
- this.updateChartDefinition(cmd.sheetId, cmd.id, cmd.definition);
9914
+ this.updateChartDefinition(cmd.id, cmd.definition);
9879
9915
  break;
9880
9916
  }
9881
9917
  case "DUPLICATE_SHEET": {
@@ -9885,7 +9921,7 @@ class ChartPlugin extends CorePlugin {
9885
9921
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
9886
9922
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
9887
9923
  const chartDefinition = {
9888
- ...deepCopy(this.chartFigures[cmd.sheetId][fig.id]),
9924
+ ...deepCopy(this.chartFigures[fig.id]),
9889
9925
  id: duplicatedFigureId,
9890
9926
  };
9891
9927
  chartDefinition.sheetId = cmd.sheetIdTo;
@@ -9915,28 +9951,37 @@ class ChartPlugin extends CorePlugin {
9915
9951
  break;
9916
9952
  }
9917
9953
  case "DELETE_FIGURE":
9918
- this.history.update("chartFigures", cmd.sheetId, cmd.id, undefined);
9954
+ this.history.update("chartFigures", cmd.id, undefined);
9919
9955
  break;
9920
9956
  case "DELETE_SHEET":
9921
- this.history.update("chartFigures", cmd.sheetId, undefined);
9957
+ for (let id of Object.keys(this.chartFigures)) {
9958
+ if (((_b = this.chartFigures[id]) === null || _b === void 0 ? void 0 : _b.sheetId) === cmd.sheetId) {
9959
+ this.history.update("chartFigures", id, undefined);
9960
+ }
9961
+ }
9922
9962
  break;
9923
9963
  }
9924
9964
  }
9925
9965
  // ---------------------------------------------------------------------------
9926
9966
  // Getters
9927
9967
  // ---------------------------------------------------------------------------
9928
- getChartDefinition(sheetId, figureId) {
9929
- var _a;
9930
- return (_a = this.chartFigures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
9968
+ getChartDefinition(figureId) {
9969
+ return this.chartFigures[figureId];
9931
9970
  }
9932
- getChartDefinitionsBySheet(sheetId) {
9933
- return Object.values(this.chartFigures[sheetId] || {}).filter(isDefined);
9971
+ getChartsIdBySheet(sheetId) {
9972
+ return Object.entries(this.chartFigures)
9973
+ .filter((chart) => {
9974
+ return chart[1].sheetId === sheetId;
9975
+ })
9976
+ .map((chart) => chart[0]);
9934
9977
  }
9935
- getChartDefinitionUI(sheetId, figureId, forceSheetName = false) {
9936
- const data = this.chartFigures[sheetId][figureId];
9937
- const rangeSheetId = forceSheetName ? "forceSheetReference" : sheetId;
9978
+ getChartDefinitionUI(sheetId, figureId) {
9979
+ const data = this.chartFigures[figureId];
9980
+ if (!data) {
9981
+ return undefined;
9982
+ }
9938
9983
  const dataSets = data.dataSets
9939
- .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, rangeSheetId) : ""))
9984
+ .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, sheetId) : ""))
9940
9985
  .filter((ds) => {
9941
9986
  return ds !== ""; // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9942
9987
  });
@@ -9944,7 +9989,7 @@ class ChartPlugin extends CorePlugin {
9944
9989
  title: data && data.title ? data.title : "",
9945
9990
  dataSets,
9946
9991
  labelRange: data.labelRange
9947
- ? this.getters.getRangeString(data.labelRange, rangeSheetId)
9992
+ ? this.getters.getRangeString(data.labelRange, sheetId)
9948
9993
  : undefined,
9949
9994
  type: data ? data.type : "bar",
9950
9995
  dataSetsHaveTitle: data && dataSets.length !== 0 ? Boolean(data.dataSets[0].labelCell) : false,
@@ -9955,12 +10000,16 @@ class ChartPlugin extends CorePlugin {
9955
10000
  };
9956
10001
  }
9957
10002
  getChartDefinitionExcel(sheetId, figureId) {
9958
- const data = this.chartFigures[sheetId][figureId];
10003
+ const data = this.chartFigures[figureId];
10004
+ const dataUI = this.getChartDefinitionUI("forceSheetReference", figureId);
10005
+ if (!data || !dataUI) {
10006
+ return undefined;
10007
+ }
9959
10008
  const dataSets = data.dataSets
9960
10009
  .map((ds) => this.toExcelDataset(ds))
9961
10010
  .filter((ds) => ds.range !== ""); // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9962
10011
  return {
9963
- ...this.getChartDefinitionUI(sheetId, figureId, true),
10012
+ ...dataUI,
9964
10013
  backgroundColor: data.background,
9965
10014
  dataSets,
9966
10015
  };
@@ -9995,17 +10044,15 @@ class ChartPlugin extends CorePlugin {
9995
10044
  import(data) {
9996
10045
  for (let sheet of data.sheets) {
9997
10046
  if (sheet.figures) {
9998
- const charts = {};
9999
10047
  for (let figure of sheet.figures) {
10000
10048
  if (figure.tag === "chart") {
10001
10049
  const figureData = {
10002
10050
  ...figure.data,
10003
10051
  };
10004
- charts[figure.id] = this.createChartDefinition(figureData, sheet.id);
10052
+ this.chartFigures[figure.id] = this.createChartDefinition(figureData, sheet.id);
10005
10053
  delete figure.data;
10006
10054
  }
10007
10055
  }
10008
- this.chartFigures[sheet.id] = charts;
10009
10056
  }
10010
10057
  }
10011
10058
  }
@@ -10013,10 +10060,18 @@ class ChartPlugin extends CorePlugin {
10013
10060
  if (data.sheets) {
10014
10061
  for (let sheet of data.sheets) {
10015
10062
  const sheetFigures = this.getters.getFigures(sheet.id);
10016
- const figures = sheetFigures;
10017
- for (let figure of figures) {
10063
+ const figures = [];
10064
+ for (let sheetFigure of sheetFigures) {
10065
+ const figure = sheetFigure;
10018
10066
  if (figure && figure.tag === "chart") {
10019
- figure.data = this.getChartDefinitionUI(sheet.id, figure.id);
10067
+ const data = this.getChartDefinitionUI(sheet.id, figure.id);
10068
+ if (data) {
10069
+ figure.data = data;
10070
+ figures.push(figure);
10071
+ }
10072
+ }
10073
+ else {
10074
+ figures.push(figure);
10020
10075
  }
10021
10076
  }
10022
10077
  sheet.figures = figures;
@@ -10026,10 +10081,18 @@ class ChartPlugin extends CorePlugin {
10026
10081
  exportForExcel(data) {
10027
10082
  for (let sheet of data.sheets) {
10028
10083
  const sheetFigures = this.getters.getFigures(sheet.id);
10029
- const figures = sheetFigures;
10030
- for (let figure of figures) {
10084
+ const figures = [];
10085
+ for (let sheetFigure of sheetFigures) {
10086
+ const figure = sheetFigure;
10031
10087
  if (figure && figure.tag === "chart") {
10032
- figure.data = this.getChartDefinitionExcel(sheet.id, figure.id);
10088
+ const data = this.getChartDefinitionExcel(sheet.id, figure.id);
10089
+ if (data) {
10090
+ figure.data = data;
10091
+ figures.push(figure);
10092
+ }
10093
+ }
10094
+ else {
10095
+ figures.push(figure);
10033
10096
  }
10034
10097
  }
10035
10098
  sheet.charts = figures;
@@ -10055,39 +10118,39 @@ class ChartPlugin extends CorePlugin {
10055
10118
  * Update the chart definition linked to the given id with the attributes
10056
10119
  * given in the partial UI definition
10057
10120
  */
10058
- updateChartDefinition(sheetId, id, definition) {
10059
- const chart = this.chartFigures[sheetId][id];
10121
+ updateChartDefinition(id, definition) {
10122
+ const chart = this.chartFigures[id];
10060
10123
  if (!chart) {
10061
10124
  throw new Error(`There is no chart with the given id: ${id}`);
10062
10125
  }
10063
10126
  if (definition.title !== undefined) {
10064
- this.history.update("chartFigures", sheetId, id, "title", definition.title);
10127
+ this.history.update("chartFigures", id, "title", definition.title);
10065
10128
  }
10066
10129
  if (definition.type) {
10067
- this.history.update("chartFigures", sheetId, id, "type", definition.type);
10130
+ this.history.update("chartFigures", id, "type", definition.type);
10068
10131
  }
10069
10132
  if (definition.dataSets) {
10070
10133
  const dataSetsHaveTitle = !!definition.dataSetsHaveTitle;
10071
10134
  const dataSets = this.createDataSets(definition.dataSets, chart.sheetId, dataSetsHaveTitle);
10072
- this.history.update("chartFigures", sheetId, id, "dataSets", dataSets);
10135
+ this.history.update("chartFigures", id, "dataSets", dataSets);
10073
10136
  }
10074
10137
  if (definition.labelRange !== undefined) {
10075
10138
  const labelRange = definition.labelRange
10076
10139
  ? this.getters.getRangeFromSheetXC(chart.sheetId, definition.labelRange)
10077
10140
  : undefined;
10078
- this.history.update("chartFigures", sheetId, id, "labelRange", labelRange);
10141
+ this.history.update("chartFigures", id, "labelRange", labelRange);
10079
10142
  }
10080
10143
  if (definition.background) {
10081
- this.history.update("chartFigures", sheetId, id, "background", definition.background);
10144
+ this.history.update("chartFigures", id, "background", definition.background);
10082
10145
  }
10083
10146
  if (definition.verticalAxisPosition) {
10084
- this.history.update("chartFigures", sheetId, id, "verticalAxisPosition", definition.verticalAxisPosition);
10147
+ this.history.update("chartFigures", id, "verticalAxisPosition", definition.verticalAxisPosition);
10085
10148
  }
10086
10149
  if (definition.legendPosition) {
10087
- this.history.update("chartFigures", sheetId, id, "legendPosition", definition.legendPosition);
10150
+ this.history.update("chartFigures", id, "legendPosition", definition.legendPosition);
10088
10151
  }
10089
10152
  if (definition.stackedBar !== undefined) {
10090
- this.history.update("chartFigures", sheetId, id, "stackedBar", definition.stackedBar);
10153
+ this.history.update("chartFigures", id, "stackedBar", definition.stackedBar);
10091
10154
  }
10092
10155
  }
10093
10156
  createDataSets(dataSetsString, sheetId, dataSetsHaveTitle) {
@@ -10142,7 +10205,7 @@ class ChartPlugin extends CorePlugin {
10142
10205
  sheetId,
10143
10206
  figure,
10144
10207
  });
10145
- this.history.update("chartFigures", sheetId, figure.id, data);
10208
+ this.history.update("chartFigures", figure.id, data);
10146
10209
  }
10147
10210
  createDataSet(sheetId, fullZone, titleZone) {
10148
10211
  if (fullZone.left !== fullZone.right && fullZone.top !== fullZone.bottom) {
@@ -10183,14 +10246,20 @@ class ChartPlugin extends CorePlugin {
10183
10246
  return invalidLabels ? 29 /* InvalidLabelRange */ : 0 /* Success */;
10184
10247
  }
10185
10248
  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 */;
10249
+ for (const sheet of this.getters.getSheets()) {
10250
+ if (this.getters.getFigure(sheet.id, cmd.id)) {
10251
+ return 57 /* DuplicatedChartId */;
10252
+ }
10189
10253
  }
10190
10254
  return 0 /* Success */;
10191
10255
  }
10256
+ checkChartExists(cmd) {
10257
+ return this.getters.getFigure(cmd.sheetId, cmd.id)
10258
+ ? 0 /* Success */
10259
+ : 58 /* ChartDoesNotExist */;
10260
+ }
10192
10261
  }
10193
- ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartDefinitionsBySheet"];
10262
+ ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartsIdBySheet"];
10194
10263
 
10195
10264
  // -----------------------------------------------------------------------------
10196
10265
  // Constants
@@ -10529,7 +10598,7 @@ class FigurePlugin extends CorePlugin {
10529
10598
  allowDispatch(cmd) {
10530
10599
  switch (cmd.type) {
10531
10600
  case "CREATE_FIGURE":
10532
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
10601
+ return this.checkFigureDuplicate(cmd.figure.id);
10533
10602
  case "UPDATE_FIGURE":
10534
10603
  case "DELETE_FIGURE":
10535
10604
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -10595,9 +10664,8 @@ class FigurePlugin extends CorePlugin {
10595
10664
  }
10596
10665
  return 0 /* Success */;
10597
10666
  }
10598
- checkFigureDuplicate(sheetId, figureId) {
10599
- var _a;
10600
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
10667
+ checkFigureDuplicate(figureId) {
10668
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
10601
10669
  return 56 /* DuplicatedFigureId */;
10602
10670
  }
10603
10671
  return 0 /* Success */;
@@ -10612,6 +10680,9 @@ class FigurePlugin extends CorePlugin {
10612
10680
  var _a;
10613
10681
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
10614
10682
  }
10683
+ getFigureSheetId(figureId) {
10684
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
10685
+ }
10615
10686
  // ---------------------------------------------------------------------------
10616
10687
  // Import/Export
10617
10688
  // ---------------------------------------------------------------------------
@@ -10636,7 +10707,7 @@ class FigurePlugin extends CorePlugin {
10636
10707
  this.export(data);
10637
10708
  }
10638
10709
  }
10639
- FigurePlugin.getters = ["getFigures", "getFigure"];
10710
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
10640
10711
 
10641
10712
  class MergePlugin extends CorePlugin {
10642
10713
  constructor() {
@@ -12798,7 +12869,7 @@ const CREATE_CHART = (env) => {
12798
12869
  },
12799
12870
  });
12800
12871
  const figure = env.getters.getFigure(sheetId, id);
12801
- env.openSidePanel("ChartPanel", { sheetId, figure });
12872
+ env.openSidePanel("ChartPanel", { figure });
12802
12873
  };
12803
12874
  //------------------------------------------------------------------------------
12804
12875
  // Style/Format
@@ -14295,19 +14366,21 @@ class ChartPanel extends Component {
14295
14366
  constructor() {
14296
14367
  super(...arguments);
14297
14368
  this.getters = this.env.getters;
14369
+ this.chartSheetId = this.findSheetId(this.props.figure.id);
14298
14370
  this.state = useState$b(this.initialState(this.props.figure));
14299
14371
  }
14300
14372
  async willUpdateProps(nextProps) {
14301
- if (!this.getters.getChartDefinition(nextProps.sheetId, nextProps.figure.id)) {
14373
+ if (!this.getters.getChartDefinition(nextProps.figure.id)) {
14302
14374
  this.trigger("close-side-panel");
14303
14375
  return;
14304
14376
  }
14305
14377
  if (nextProps.figure.id !== this.props.figure.id) {
14378
+ this.chartSheetId = this.findSheetId(nextProps.figure.id);
14306
14379
  this.state.panel = "configuration";
14307
14380
  this.state.fillColorTool = false;
14308
14381
  this.state.datasetDispatchResult = undefined;
14309
14382
  this.state.labelsDispatchResult = undefined;
14310
- this.state.chart = this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), nextProps.figure.id);
14383
+ this.state.chart = this.env.getters.getChartDefinitionUI(this.chartSheetId, nextProps.figure.id);
14311
14384
  }
14312
14385
  }
14313
14386
  get errorMessages() {
@@ -14354,7 +14427,7 @@ class ChartPanel extends Component {
14354
14427
  updateChart(definition) {
14355
14428
  return this.env.dispatch("UPDATE_CHART", {
14356
14429
  id: this.props.figure.id,
14357
- sheetId: this.props.sheetId,
14430
+ sheetId: this.chartSheetId,
14358
14431
  definition,
14359
14432
  });
14360
14433
  }
@@ -14376,12 +14449,16 @@ class ChartPanel extends Component {
14376
14449
  this.state.panel = panel;
14377
14450
  }
14378
14451
  initialState(figure) {
14452
+ const sheetId = this.findSheetId(figure.id);
14379
14453
  return {
14380
- chart: this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), figure.id),
14454
+ chart: this.env.getters.getChartDefinitionUI(sheetId, figure.id),
14381
14455
  panel: "configuration",
14382
14456
  fillColorTool: false,
14383
14457
  };
14384
14458
  }
14459
+ findSheetId(figureId) {
14460
+ return this.env.getters.getFigureSheetId(figureId) || "";
14461
+ }
14385
14462
  }
14386
14463
  ChartPanel.template = TEMPLATE$p;
14387
14464
  ChartPanel.style = STYLE;
@@ -18795,60 +18872,51 @@ class EvaluationChartPlugin extends UIPlugin {
18795
18872
  this.outOfDate = new Set();
18796
18873
  }
18797
18874
  handle(cmd) {
18798
- var _a;
18799
18875
  if (invalidateEvaluationCommands.has(cmd.type) ||
18800
18876
  cmd.type === "EVALUATE_CELLS" ||
18801
18877
  (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
- }
18878
+ for (let chartId of Object.keys(this.chartRuntime)) {
18879
+ this.outOfDate.add(chartId);
18806
18880
  }
18807
18881
  }
18808
18882
  switch (cmd.type) {
18809
18883
  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);
18884
+ case "CREATE_CHART":
18885
+ const chartDefinition = this.getters.getChartDefinition(cmd.id);
18886
+ this.chartRuntime[cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18815
18887
  break;
18816
- }
18817
18888
  case "DELETE_FIGURE":
18818
- (_a = this.chartRuntime[cmd.sheetId]) === null || _a === void 0 ? true : delete _a[cmd.id];
18889
+ delete this.chartRuntime[cmd.id];
18819
18890
  break;
18820
- case "REFRESH_CHART": {
18821
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18822
- this.evaluateUsedSheets([chartDefinition]);
18891
+ case "REFRESH_CHART":
18892
+ this.evaluateUsedSheets([cmd.id]);
18823
18893
  this.outOfDate.add(cmd.id);
18824
18894
  break;
18825
- }
18826
- case "ACTIVATE_SHEET": {
18827
- const chartsDefinitions = this.getters.getChartDefinitionsBySheet(cmd.sheetIdTo);
18828
- this.evaluateUsedSheets(chartsDefinitions);
18895
+ case "ACTIVATE_SHEET":
18896
+ const chartsIds = this.getters.getChartsIdBySheet(cmd.sheetIdTo);
18897
+ this.evaluateUsedSheets(chartsIds);
18829
18898
  break;
18830
- }
18831
18899
  case "DELETE_SHEET":
18832
- delete this.chartRuntime[cmd.sheetId];
18900
+ for (let chartId of Object.keys(this.chartRuntime)) {
18901
+ if (!this.getters.getChartDefinition(chartId)) {
18902
+ delete this.chartRuntime[chartId];
18903
+ }
18904
+ }
18833
18905
  break;
18834
18906
  }
18835
18907
  }
18836
18908
  // ---------------------------------------------------------------------------
18837
18909
  // Getters
18838
18910
  // ---------------------------------------------------------------------------
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);
18911
+ getChartRuntime(figureId) {
18912
+ if (this.outOfDate.has(figureId) || !(figureId in this.chartRuntime)) {
18913
+ const chartDefinition = this.getters.getChartDefinition(figureId);
18844
18914
  if (chartDefinition === undefined)
18845
18915
  return;
18846
- if (!this.chartRuntime[sheetId])
18847
- this.chartRuntime[sheetId] = {};
18848
- this.chartRuntime[sheetId][figureId] = this.mapDefinitionToRuntime(chartDefinition);
18916
+ this.chartRuntime[figureId] = this.mapDefinitionToRuntime(chartDefinition);
18849
18917
  this.outOfDate.delete(figureId);
18850
18918
  }
18851
- return this.chartRuntime[sheetId][figureId];
18919
+ return this.chartRuntime[figureId];
18852
18920
  }
18853
18921
  truncateLabel(label) {
18854
18922
  if (!label) {
@@ -18953,9 +19021,10 @@ class EvaluationChartPlugin extends UIPlugin {
18953
19021
  }
18954
19022
  return sheetIds;
18955
19023
  }
18956
- evaluateUsedSheets(chartsDefinitions) {
19024
+ evaluateUsedSheets(chartsIds) {
18957
19025
  const usedSheetsId = new Set();
18958
- for (const chartDefinition of chartsDefinitions) {
19026
+ for (let chartId of chartsIds) {
19027
+ const chartDefinition = this.getters.getChartDefinition(chartId);
18959
19028
  const sheetsIds = chartDefinition !== undefined ? this.getSheetIdsUsedInChart(chartDefinition) : [];
18960
19029
  sheetsIds.forEach((sheetId) => {
18961
19030
  if (sheetId !== this.getters.getActiveSheetId()) {
@@ -27852,7 +27921,7 @@ class ChartFigure extends Component {
27852
27921
  }
27853
27922
  mounted() {
27854
27923
  const figure = this.props.figure;
27855
- const chartData = this.env.getters.getChartRuntime(this.env.getters.getActiveSheetId(), figure.id);
27924
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27856
27925
  if (chartData) {
27857
27926
  this.createChart(chartData);
27858
27927
  }
@@ -27860,8 +27929,7 @@ class ChartFigure extends Component {
27860
27929
  patched() {
27861
27930
  var _a, _b, _c;
27862
27931
  const figure = this.props.figure;
27863
- const sheetId = this.env.getters.getActiveSheetId();
27864
- const chartData = this.env.getters.getChartRuntime(sheetId, figure.id);
27932
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27865
27933
  if (chartData) {
27866
27934
  if (chartData.type !== this.chart.config.type) {
27867
27935
  // Updating a chart type requires to update its options accordingly, if feasible at all.
@@ -27887,7 +27955,7 @@ class ChartFigure extends Component {
27887
27955
  else {
27888
27956
  this.chart && this.chart.destroy();
27889
27957
  }
27890
- const def = this.env.getters.getChartDefinition(sheetId, figure.id);
27958
+ const def = this.env.getters.getChartDefinition(figure.id);
27891
27959
  if (def) {
27892
27960
  this.state.background = def.background;
27893
27961
  }
@@ -27896,7 +27964,7 @@ class ChartFigure extends Component {
27896
27964
  const canvas = this.canvas.el;
27897
27965
  const ctx = canvas.getContext("2d");
27898
27966
  this.chart = new window.Chart(ctx, chartData);
27899
- const def = this.env.getters.getChartDefinition(this.env.getters.getActiveSheetId(), this.props.figure.id);
27967
+ const def = this.env.getters.getChartDefinition(this.props.figure.id);
27900
27968
  if (def) {
27901
27969
  this.state.background = def.background;
27902
27970
  }
@@ -27906,10 +27974,8 @@ class ChartFigure extends Component {
27906
27974
  registry.add("edit", {
27907
27975
  name: _lt("Edit"),
27908
27976
  sequence: 1,
27909
- action: () => this.env.openSidePanel("ChartPanel", {
27910
- sheetId: this.env.getters.getActiveSheetId(),
27911
- figure: this.props.figure,
27912
- }),
27977
+ action: () => this.env.openSidePanel("ChartPanel", { figure: this.props.figure }),
27978
+ isVisible: () => !!this.env.getters.getChartDefinition(this.props.figure.id),
27913
27979
  });
27914
27980
  registry.add("delete", {
27915
27981
  name: _lt("Delete"),
@@ -27920,10 +27986,7 @@ class ChartFigure extends Component {
27920
27986
  id: this.props.figure.id,
27921
27987
  });
27922
27988
  if (this.props.sidePanelIsOpen) {
27923
- this.env.toggleSidePanel("ChartPanel", {
27924
- sheetId: this.env.getters.getActiveSheetId(),
27925
- figure: this.props.figure,
27926
- });
27989
+ this.env.toggleSidePanel("ChartPanel", { figure: this.props.figure });
27927
27990
  }
27928
27991
  this.trigger("figure-deleted");
27929
27992
  },
@@ -27933,7 +27996,6 @@ class ChartFigure extends Component {
27933
27996
  sequence: 11,
27934
27997
  action: () => {
27935
27998
  this.env.dispatch("REFRESH_CHART", {
27936
- sheetId: this.env.getters.getActiveSheetId(),
27937
27999
  id: this.props.figure.id,
27938
28000
  });
27939
28001
  },
@@ -28177,10 +28239,7 @@ class FiguresContainer extends Component {
28177
28239
  return;
28178
28240
  }
28179
28241
  if (this.props.sidePanelIsOpen) {
28180
- this.env.openSidePanel("ChartPanel", {
28181
- sheetId: this.env.getters.getActiveSheetId(),
28182
- figure,
28183
- });
28242
+ this.env.openSidePanel("ChartPanel", { figure });
28184
28243
  }
28185
28244
  const initialX = ev.clientX;
28186
28245
  const initialY = ev.clientY;
@@ -31252,6 +31311,6 @@ const helpers = {
31252
31311
  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
31312
 
31254
31313
 
31255
- __info__.version = '15.0.0';
31256
- __info__.date = '2023-02-27T14:03:17.561Z';
31257
- __info__.hash = '2d1cea1';
31314
+ __info__.version = '15.0.1';
31315
+ __info__.date = '2023-03-06T07:16:47.732Z';
31316
+ __info__.hash = 'de03e1c';