@odoo/o-spreadsheet 15.2.0 → 15.2.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.
@@ -1392,6 +1392,7 @@ exports.CommandResult = void 0;
1392
1392
  CommandResult[CommandResult["FigureDoesNotExist"] = 55] = "FigureDoesNotExist";
1393
1393
  CommandResult[CommandResult["DuplicatedFigureId"] = 56] = "DuplicatedFigureId";
1394
1394
  CommandResult[CommandResult["DuplicatedChartId"] = 57] = "DuplicatedChartId";
1395
+ CommandResult[CommandResult["ChartDoesNotExist"] = 58] = "ChartDoesNotExist";
1395
1396
  })(exports.CommandResult || (exports.CommandResult = {}));
1396
1397
 
1397
1398
  var ReturnFormatType;
@@ -8439,13 +8440,7 @@ function load(data) {
8439
8440
  data = migrate(data);
8440
8441
  }
8441
8442
  }
8442
- // sanity check: try to fix missing fields/corrupted state by providing
8443
- // sensible default values
8444
- data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8445
- data.sheets = data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s));
8446
- if (data.sheets.length === 0) {
8447
- data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8448
- }
8443
+ data = repairData(data);
8449
8444
  return data;
8450
8445
  }
8451
8446
  function migrate(data) {
@@ -8672,6 +8667,48 @@ const MIGRATIONS = [
8672
8667
  },
8673
8668
  },
8674
8669
  ];
8670
+ /**
8671
+ * This function is used to repair faulty data independently of the migration.
8672
+ */
8673
+ function repairData(data) {
8674
+ data = forceUnicityOfFigure(data);
8675
+ data = setDefaults(data);
8676
+ return data;
8677
+ }
8678
+ /**
8679
+ * Force the unicity of figure ids accross sheets
8680
+ */
8681
+ function forceUnicityOfFigure(data) {
8682
+ if (data.uniqueFigureIds) {
8683
+ return data;
8684
+ }
8685
+ const figureIds = new Set();
8686
+ const uuidGenerator = new UuidGenerator();
8687
+ for (const sheet of data.sheets || []) {
8688
+ for (const figure of sheet.figures || []) {
8689
+ if (figureIds.has(figure.id)) {
8690
+ figure.id += uuidGenerator.uuidv4();
8691
+ }
8692
+ figureIds.add(figure.id);
8693
+ }
8694
+ }
8695
+ data.uniqueFigureIds = true;
8696
+ return data;
8697
+ }
8698
+ /**
8699
+ * sanity check: try to fix missing fields/corrupted state by providing
8700
+ * sensible default values
8701
+ */
8702
+ function setDefaults(data) {
8703
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8704
+ data.sheets = data.sheets
8705
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
8706
+ : [];
8707
+ if (data.sheets.length === 0) {
8708
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8709
+ }
8710
+ return data;
8711
+ }
8675
8712
  /**
8676
8713
  * The goal of this function is to repair corrupted/wrong initial messages caused by
8677
8714
  * a bug.
@@ -8759,6 +8796,7 @@ function createEmptyWorkbookData(sheetName = "Sheet1") {
8759
8796
  formats: {},
8760
8797
  borders: {},
8761
8798
  revisionId: DEFAULT_REVISION_ID,
8799
+ uniqueFigureIds: true,
8762
8800
  };
8763
8801
  return data;
8764
8802
  }
@@ -9799,34 +9837,32 @@ class ChartPlugin extends CorePlugin {
9799
9837
  this.chartFigures = {};
9800
9838
  }
9801
9839
  adaptRanges(applyChange) {
9802
- for (const sheetId of Object.keys(this.chartFigures)) {
9803
- for (const [chartId, chart] of Object.entries(this.chartFigures[sheetId] || {})) {
9804
- if (chart) {
9805
- this.adaptDataSetRanges(sheetId, chart, chartId, applyChange);
9806
- this.adaptLabelRanges(sheetId, chart, chartId, applyChange);
9807
- }
9840
+ for (let [chartId, chart] of Object.entries(this.chartFigures)) {
9841
+ if (chart) {
9842
+ this.adaptDataSetRanges(chart, chartId, applyChange);
9843
+ this.adaptLabelRanges(chart, chartId, applyChange);
9808
9844
  }
9809
9845
  }
9810
9846
  }
9811
- adaptDataSetRanges(sheetId, chart, chartId, applyChange) {
9847
+ adaptDataSetRanges(chart, chartId, applyChange) {
9812
9848
  for (let ds of chart.dataSets) {
9813
9849
  if (ds.labelCell) {
9814
9850
  const labelCellChange = applyChange(ds.labelCell);
9815
9851
  switch (labelCellChange.changeType) {
9816
9852
  case "REMOVE":
9817
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9853
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", undefined);
9818
9854
  break;
9819
9855
  case "RESIZE":
9820
9856
  case "MOVE":
9821
9857
  case "CHANGE":
9822
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9858
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "labelCell", labelCellChange.range);
9823
9859
  }
9824
9860
  }
9825
9861
  const dataRangeChange = applyChange(ds.dataRange);
9826
9862
  switch (dataRangeChange.changeType) {
9827
9863
  case "REMOVE":
9828
9864
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9829
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9865
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9830
9866
  break;
9831
9867
  case "RESIZE":
9832
9868
  case "MOVE":
@@ -9834,27 +9870,27 @@ class ChartPlugin extends CorePlugin {
9834
9870
  // We have to remove the ranges that are #REF
9835
9871
  if (this.getters.getRangeString(dataRangeChange.range, dataRangeChange.range.sheetId) !==
9836
9872
  INCORRECT_RANGE_STRING) {
9837
- this.history.update("chartFigures", sheetId, chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9873
+ this.history.update("chartFigures", chartId, "dataSets", chart.dataSets.indexOf(ds), "dataRange", dataRangeChange.range);
9838
9874
  }
9839
9875
  else {
9840
9876
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9841
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9877
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9842
9878
  }
9843
9879
  break;
9844
9880
  }
9845
9881
  }
9846
9882
  }
9847
- adaptLabelRanges(sheetId, chart, chartId, applyChange) {
9883
+ adaptLabelRanges(chart, chartId, applyChange) {
9848
9884
  if (chart.labelRange) {
9849
9885
  const labelRangeChange = applyChange(chart.labelRange);
9850
9886
  switch (labelRangeChange.changeType) {
9851
9887
  case "REMOVE":
9852
- this.history.update("chartFigures", sheetId, chartId, "labelRange", undefined);
9888
+ this.history.update("chartFigures", chartId, "labelRange", undefined);
9853
9889
  break;
9854
9890
  case "RESIZE":
9855
9891
  case "MOVE":
9856
9892
  case "CHANGE":
9857
- this.history.update("chartFigures", sheetId, chartId, "labelRange", labelRangeChange.range);
9893
+ this.history.update("chartFigures", chartId, "labelRange", labelRangeChange.range);
9858
9894
  break;
9859
9895
  }
9860
9896
  }
@@ -9865,16 +9901,16 @@ class ChartPlugin extends CorePlugin {
9865
9901
  allowDispatch(cmd) {
9866
9902
  const success = 0 /* Success */;
9867
9903
  switch (cmd.type) {
9868
- case "CREATE_CHART":
9869
- return this.checkValidations(cmd, this.chainValidations(this.checkChartDuplicate, this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9870
9904
  case "UPDATE_CHART":
9871
- return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9905
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartExists), this.checkLabelRange);
9906
+ case "CREATE_CHART":
9907
+ return this.checkValidations(cmd, this.chainValidations(this.checkEmptyDataset, this.checkDataset, this.checkChartDuplicate), this.checkLabelRange);
9872
9908
  default:
9873
9909
  return success;
9874
9910
  }
9875
9911
  }
9876
9912
  handle(cmd) {
9877
- var _a;
9913
+ var _a, _b;
9878
9914
  switch (cmd.type) {
9879
9915
  case "CREATE_CHART":
9880
9916
  const x = cmd.position ? cmd.position.x : 0;
@@ -9889,7 +9925,7 @@ class ChartPlugin extends CorePlugin {
9889
9925
  });
9890
9926
  break;
9891
9927
  case "UPDATE_CHART": {
9892
- this.updateChartDefinition(cmd.sheetId, cmd.id, cmd.definition);
9928
+ this.updateChartDefinition(cmd.id, cmd.definition);
9893
9929
  break;
9894
9930
  }
9895
9931
  case "DUPLICATE_SHEET": {
@@ -9899,7 +9935,7 @@ class ChartPlugin extends CorePlugin {
9899
9935
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
9900
9936
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
9901
9937
  const chartDefinition = {
9902
- ...deepCopy(this.chartFigures[cmd.sheetId][fig.id]),
9938
+ ...deepCopy(this.chartFigures[fig.id]),
9903
9939
  id: duplicatedFigureId,
9904
9940
  };
9905
9941
  chartDefinition.sheetId = cmd.sheetIdTo;
@@ -9929,28 +9965,37 @@ class ChartPlugin extends CorePlugin {
9929
9965
  break;
9930
9966
  }
9931
9967
  case "DELETE_FIGURE":
9932
- this.history.update("chartFigures", cmd.sheetId, cmd.id, undefined);
9968
+ this.history.update("chartFigures", cmd.id, undefined);
9933
9969
  break;
9934
9970
  case "DELETE_SHEET":
9935
- this.history.update("chartFigures", cmd.sheetId, undefined);
9971
+ for (let id of Object.keys(this.chartFigures)) {
9972
+ if (((_b = this.chartFigures[id]) === null || _b === void 0 ? void 0 : _b.sheetId) === cmd.sheetId) {
9973
+ this.history.update("chartFigures", id, undefined);
9974
+ }
9975
+ }
9936
9976
  break;
9937
9977
  }
9938
9978
  }
9939
9979
  // ---------------------------------------------------------------------------
9940
9980
  // Getters
9941
9981
  // ---------------------------------------------------------------------------
9942
- getChartDefinition(sheetId, figureId) {
9943
- var _a;
9944
- return (_a = this.chartFigures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
9982
+ getChartDefinition(figureId) {
9983
+ return this.chartFigures[figureId];
9945
9984
  }
9946
- getChartDefinitionsBySheet(sheetId) {
9947
- return Object.values(this.chartFigures[sheetId] || {}).filter(isDefined);
9985
+ getChartsIdBySheet(sheetId) {
9986
+ return Object.entries(this.chartFigures)
9987
+ .filter((chart) => {
9988
+ return chart[1].sheetId === sheetId;
9989
+ })
9990
+ .map((chart) => chart[0]);
9948
9991
  }
9949
- getChartDefinitionUI(sheetId, figureId, forceSheetName = false) {
9950
- const data = this.chartFigures[sheetId][figureId];
9951
- const rangeSheetId = forceSheetName ? "forceSheetReference" : sheetId;
9992
+ getChartDefinitionUI(sheetId, figureId) {
9993
+ const data = this.chartFigures[figureId];
9994
+ if (!data) {
9995
+ return undefined;
9996
+ }
9952
9997
  const dataSets = data.dataSets
9953
- .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, rangeSheetId) : ""))
9998
+ .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, sheetId) : ""))
9954
9999
  .filter((ds) => {
9955
10000
  return ds !== ""; // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9956
10001
  });
@@ -9958,7 +10003,7 @@ class ChartPlugin extends CorePlugin {
9958
10003
  title: data && data.title ? data.title : "",
9959
10004
  dataSets,
9960
10005
  labelRange: data.labelRange
9961
- ? this.getters.getRangeString(data.labelRange, rangeSheetId)
10006
+ ? this.getters.getRangeString(data.labelRange, sheetId)
9962
10007
  : undefined,
9963
10008
  type: data ? data.type : "bar",
9964
10009
  dataSetsHaveTitle: data && dataSets.length !== 0 ? Boolean(data.dataSets[0].labelCell) : false,
@@ -9969,12 +10014,16 @@ class ChartPlugin extends CorePlugin {
9969
10014
  };
9970
10015
  }
9971
10016
  getChartDefinitionExcel(sheetId, figureId) {
9972
- const data = this.chartFigures[sheetId][figureId];
10017
+ const data = this.chartFigures[figureId];
10018
+ const dataUI = this.getChartDefinitionUI("forceSheetReference", figureId);
10019
+ if (!data || !dataUI) {
10020
+ return undefined;
10021
+ }
9973
10022
  const dataSets = data.dataSets
9974
10023
  .map((ds) => this.toExcelDataset(ds))
9975
10024
  .filter((ds) => ds.range !== ""); // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9976
10025
  return {
9977
- ...this.getChartDefinitionUI(sheetId, figureId, true),
10026
+ ...dataUI,
9978
10027
  backgroundColor: data.background,
9979
10028
  dataSets,
9980
10029
  };
@@ -10009,17 +10058,15 @@ class ChartPlugin extends CorePlugin {
10009
10058
  import(data) {
10010
10059
  for (let sheet of data.sheets) {
10011
10060
  if (sheet.figures) {
10012
- const charts = {};
10013
10061
  for (let figure of sheet.figures) {
10014
10062
  if (figure.tag === "chart") {
10015
10063
  const figureData = {
10016
10064
  ...figure.data,
10017
10065
  };
10018
- charts[figure.id] = this.createChartDefinition(figureData, sheet.id);
10066
+ this.chartFigures[figure.id] = this.createChartDefinition(figureData, sheet.id);
10019
10067
  delete figure.data;
10020
10068
  }
10021
10069
  }
10022
- this.chartFigures[sheet.id] = charts;
10023
10070
  }
10024
10071
  }
10025
10072
  }
@@ -10027,10 +10074,18 @@ class ChartPlugin extends CorePlugin {
10027
10074
  if (data.sheets) {
10028
10075
  for (let sheet of data.sheets) {
10029
10076
  const sheetFigures = this.getters.getFigures(sheet.id);
10030
- const figures = sheetFigures;
10031
- for (let figure of figures) {
10077
+ const figures = [];
10078
+ for (let sheetFigure of sheetFigures) {
10079
+ const figure = sheetFigure;
10032
10080
  if (figure && figure.tag === "chart") {
10033
- figure.data = this.getChartDefinitionUI(sheet.id, figure.id);
10081
+ const data = this.getChartDefinitionUI(sheet.id, figure.id);
10082
+ if (data) {
10083
+ figure.data = data;
10084
+ figures.push(figure);
10085
+ }
10086
+ }
10087
+ else {
10088
+ figures.push(figure);
10034
10089
  }
10035
10090
  }
10036
10091
  sheet.figures = figures;
@@ -10040,10 +10095,18 @@ class ChartPlugin extends CorePlugin {
10040
10095
  exportForExcel(data) {
10041
10096
  for (let sheet of data.sheets) {
10042
10097
  const sheetFigures = this.getters.getFigures(sheet.id);
10043
- const figures = sheetFigures;
10044
- for (let figure of figures) {
10098
+ const figures = [];
10099
+ for (let sheetFigure of sheetFigures) {
10100
+ const figure = sheetFigure;
10045
10101
  if (figure && figure.tag === "chart") {
10046
- figure.data = this.getChartDefinitionExcel(sheet.id, figure.id);
10102
+ const data = this.getChartDefinitionExcel(sheet.id, figure.id);
10103
+ if (data) {
10104
+ figure.data = data;
10105
+ figures.push(figure);
10106
+ }
10107
+ }
10108
+ else {
10109
+ figures.push(figure);
10047
10110
  }
10048
10111
  }
10049
10112
  sheet.charts = figures;
@@ -10069,39 +10132,39 @@ class ChartPlugin extends CorePlugin {
10069
10132
  * Update the chart definition linked to the given id with the attributes
10070
10133
  * given in the partial UI definition
10071
10134
  */
10072
- updateChartDefinition(sheetId, id, definition) {
10073
- const chart = this.chartFigures[sheetId][id];
10135
+ updateChartDefinition(id, definition) {
10136
+ const chart = this.chartFigures[id];
10074
10137
  if (!chart) {
10075
10138
  throw new Error(`There is no chart with the given id: ${id}`);
10076
10139
  }
10077
10140
  if (definition.title !== undefined) {
10078
- this.history.update("chartFigures", sheetId, id, "title", definition.title);
10141
+ this.history.update("chartFigures", id, "title", definition.title);
10079
10142
  }
10080
10143
  if (definition.type) {
10081
- this.history.update("chartFigures", sheetId, id, "type", definition.type);
10144
+ this.history.update("chartFigures", id, "type", definition.type);
10082
10145
  }
10083
10146
  if (definition.dataSets) {
10084
10147
  const dataSetsHaveTitle = !!definition.dataSetsHaveTitle;
10085
10148
  const dataSets = this.createDataSets(definition.dataSets, chart.sheetId, dataSetsHaveTitle);
10086
- this.history.update("chartFigures", sheetId, id, "dataSets", dataSets);
10149
+ this.history.update("chartFigures", id, "dataSets", dataSets);
10087
10150
  }
10088
10151
  if (definition.labelRange !== undefined) {
10089
10152
  const labelRange = definition.labelRange
10090
10153
  ? this.getters.getRangeFromSheetXC(chart.sheetId, definition.labelRange)
10091
10154
  : undefined;
10092
- this.history.update("chartFigures", sheetId, id, "labelRange", labelRange);
10155
+ this.history.update("chartFigures", id, "labelRange", labelRange);
10093
10156
  }
10094
10157
  if (definition.background) {
10095
- this.history.update("chartFigures", sheetId, id, "background", definition.background);
10158
+ this.history.update("chartFigures", id, "background", definition.background);
10096
10159
  }
10097
10160
  if (definition.verticalAxisPosition) {
10098
- this.history.update("chartFigures", sheetId, id, "verticalAxisPosition", definition.verticalAxisPosition);
10161
+ this.history.update("chartFigures", id, "verticalAxisPosition", definition.verticalAxisPosition);
10099
10162
  }
10100
10163
  if (definition.legendPosition) {
10101
- this.history.update("chartFigures", sheetId, id, "legendPosition", definition.legendPosition);
10164
+ this.history.update("chartFigures", id, "legendPosition", definition.legendPosition);
10102
10165
  }
10103
10166
  if (definition.stackedBar !== undefined) {
10104
- this.history.update("chartFigures", sheetId, id, "stackedBar", definition.stackedBar);
10167
+ this.history.update("chartFigures", id, "stackedBar", definition.stackedBar);
10105
10168
  }
10106
10169
  }
10107
10170
  createDataSets(dataSetsString, sheetId, dataSetsHaveTitle) {
@@ -10156,7 +10219,7 @@ class ChartPlugin extends CorePlugin {
10156
10219
  sheetId,
10157
10220
  figure,
10158
10221
  });
10159
- this.history.update("chartFigures", sheetId, figure.id, data);
10222
+ this.history.update("chartFigures", figure.id, data);
10160
10223
  }
10161
10224
  createDataSet(sheetId, fullZone, titleZone) {
10162
10225
  if (fullZone.left !== fullZone.right && fullZone.top !== fullZone.bottom) {
@@ -10197,18 +10260,20 @@ class ChartPlugin extends CorePlugin {
10197
10260
  return invalidLabels ? 29 /* InvalidLabelRange */ : 0 /* Success */;
10198
10261
  }
10199
10262
  checkChartDuplicate(cmd) {
10200
- var _a;
10201
- if ((_a = this.chartFigures[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[cmd.id]) {
10202
- return 57 /* DuplicatedChartId */;
10263
+ for (const sheet of this.getters.getSheets()) {
10264
+ if (this.getters.getFigure(sheet.id, cmd.id)) {
10265
+ return 57 /* DuplicatedChartId */;
10266
+ }
10203
10267
  }
10204
10268
  return 0 /* Success */;
10205
10269
  }
10270
+ checkChartExists(cmd) {
10271
+ return this.getters.getFigure(cmd.sheetId, cmd.id)
10272
+ ? 0 /* Success */
10273
+ : 58 /* ChartDoesNotExist */;
10274
+ }
10206
10275
  }
10207
- ChartPlugin.getters = [
10208
- "getChartDefinition",
10209
- "getChartDefinitionUI",
10210
- "getChartDefinitionsBySheet",
10211
- ];
10276
+ ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartsIdBySheet"];
10212
10277
 
10213
10278
  // -----------------------------------------------------------------------------
10214
10279
  // Constants
@@ -10547,7 +10612,7 @@ class FigurePlugin extends CorePlugin {
10547
10612
  allowDispatch(cmd) {
10548
10613
  switch (cmd.type) {
10549
10614
  case "CREATE_FIGURE":
10550
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
10615
+ return this.checkFigureDuplicate(cmd.figure.id);
10551
10616
  case "UPDATE_FIGURE":
10552
10617
  case "DELETE_FIGURE":
10553
10618
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -10613,9 +10678,8 @@ class FigurePlugin extends CorePlugin {
10613
10678
  }
10614
10679
  return 0 /* Success */;
10615
10680
  }
10616
- checkFigureDuplicate(sheetId, figureId) {
10617
- var _a;
10618
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
10681
+ checkFigureDuplicate(figureId) {
10682
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
10619
10683
  return 56 /* DuplicatedFigureId */;
10620
10684
  }
10621
10685
  return 0 /* Success */;
@@ -10630,6 +10694,9 @@ class FigurePlugin extends CorePlugin {
10630
10694
  var _a;
10631
10695
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
10632
10696
  }
10697
+ getFigureSheetId(figureId) {
10698
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
10699
+ }
10633
10700
  // ---------------------------------------------------------------------------
10634
10701
  // Import/Export
10635
10702
  // ---------------------------------------------------------------------------
@@ -10654,7 +10721,7 @@ class FigurePlugin extends CorePlugin {
10654
10721
  this.export(data);
10655
10722
  }
10656
10723
  }
10657
- FigurePlugin.getters = ["getFigures", "getFigure"];
10724
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
10658
10725
 
10659
10726
  class MergePlugin extends CorePlugin {
10660
10727
  constructor() {
@@ -12957,7 +13024,7 @@ const CREATE_CHART = (env) => {
12957
13024
  },
12958
13025
  });
12959
13026
  const figure = env.getters.getFigure(sheetId, id);
12960
- env.openSidePanel("ChartPanel", { sheetId, figure });
13027
+ env.openSidePanel("ChartPanel", { figure });
12961
13028
  };
12962
13029
  //------------------------------------------------------------------------------
12963
13030
  // Style/Format
@@ -14470,15 +14537,17 @@ class ChartPanel extends owl.Component {
14470
14537
  constructor() {
14471
14538
  super(...arguments);
14472
14539
  this.getters = this.env.getters;
14540
+ this.chartSheetId = this.findSheetId(this.props.figure.id);
14473
14541
  this.state = owl.useState(this.initialState(this.props.figure));
14474
14542
  }
14475
14543
  setup() {
14476
14544
  onWillUpdateProps$6((nextProps) => {
14477
- if (!this.getters.getChartDefinition(nextProps.sheetId, nextProps.figure.id)) {
14545
+ if (!this.getters.getChartDefinition(nextProps.figure.id)) {
14478
14546
  this.props.onCloseSidePanel();
14479
14547
  return;
14480
14548
  }
14481
14549
  if (nextProps.figure.id !== this.props.figure.id) {
14550
+ this.chartSheetId = this.findSheetId(nextProps.figure.id);
14482
14551
  this.state.panel = "configuration";
14483
14552
  this.state.fillColorTool = false;
14484
14553
  this.state.datasetDispatchResult = undefined;
@@ -14531,7 +14600,7 @@ class ChartPanel extends owl.Component {
14531
14600
  updateChart(definition) {
14532
14601
  return this.env.dispatch("UPDATE_CHART", {
14533
14602
  id: this.props.figure.id,
14534
- sheetId: this.props.sheetId,
14603
+ sheetId: this.chartSheetId,
14535
14604
  definition,
14536
14605
  });
14537
14606
  }
@@ -14553,12 +14622,16 @@ class ChartPanel extends owl.Component {
14553
14622
  this.state.panel = panel;
14554
14623
  }
14555
14624
  initialState(figure) {
14625
+ const sheetId = this.findSheetId(figure.id);
14556
14626
  return {
14557
- chart: this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), figure.id),
14627
+ chart: this.env.getters.getChartDefinitionUI(sheetId, figure.id),
14558
14628
  panel: "configuration",
14559
14629
  fillColorTool: false,
14560
14630
  };
14561
14631
  }
14632
+ findSheetId(figureId) {
14633
+ return this.env.getters.getFigureSheetId(figureId) || "";
14634
+ }
14562
14635
  }
14563
14636
  ChartPanel.template = TEMPLATE$m;
14564
14637
  ChartPanel.style = STYLE;
@@ -18874,60 +18947,51 @@ class EvaluationChartPlugin extends UIPlugin {
18874
18947
  this.outOfDate = new Set();
18875
18948
  }
18876
18949
  handle(cmd) {
18877
- var _a;
18878
18950
  if (invalidateEvaluationCommands.has(cmd.type) ||
18879
18951
  cmd.type === "EVALUATE_CELLS" ||
18880
18952
  (cmd.type === "UPDATE_CELL" && "content" in cmd)) {
18881
- for (const sheetId of Object.keys(this.chartRuntime)) {
18882
- for (const chartId of Object.keys(this.chartRuntime[sheetId] || {})) {
18883
- this.outOfDate.add(chartId);
18884
- }
18953
+ for (let chartId of Object.keys(this.chartRuntime)) {
18954
+ this.outOfDate.add(chartId);
18885
18955
  }
18886
18956
  }
18887
18957
  switch (cmd.type) {
18888
18958
  case "UPDATE_CHART":
18889
- case "CREATE_CHART": {
18890
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18891
- if (!this.chartRuntime[cmd.sheetId])
18892
- this.chartRuntime[cmd.sheetId] = {};
18893
- this.chartRuntime[cmd.sheetId][cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18959
+ case "CREATE_CHART":
18960
+ const chartDefinition = this.getters.getChartDefinition(cmd.id);
18961
+ this.chartRuntime[cmd.id] = this.mapDefinitionToRuntime(chartDefinition);
18894
18962
  break;
18895
- }
18896
18963
  case "DELETE_FIGURE":
18897
- (_a = this.chartRuntime[cmd.sheetId]) === null || _a === void 0 ? true : delete _a[cmd.id];
18964
+ delete this.chartRuntime[cmd.id];
18898
18965
  break;
18899
- case "REFRESH_CHART": {
18900
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18901
- this.evaluateUsedSheets([chartDefinition]);
18966
+ case "REFRESH_CHART":
18967
+ this.evaluateUsedSheets([cmd.id]);
18902
18968
  this.outOfDate.add(cmd.id);
18903
18969
  break;
18904
- }
18905
- case "ACTIVATE_SHEET": {
18906
- const chartsDefinitions = this.getters.getChartDefinitionsBySheet(cmd.sheetIdTo);
18907
- this.evaluateUsedSheets(chartsDefinitions);
18970
+ case "ACTIVATE_SHEET":
18971
+ const chartsIds = this.getters.getChartsIdBySheet(cmd.sheetIdTo);
18972
+ this.evaluateUsedSheets(chartsIds);
18908
18973
  break;
18909
- }
18910
18974
  case "DELETE_SHEET":
18911
- delete this.chartRuntime[cmd.sheetId];
18975
+ for (let chartId of Object.keys(this.chartRuntime)) {
18976
+ if (!this.getters.getChartDefinition(chartId)) {
18977
+ delete this.chartRuntime[chartId];
18978
+ }
18979
+ }
18912
18980
  break;
18913
18981
  }
18914
18982
  }
18915
18983
  // ---------------------------------------------------------------------------
18916
18984
  // Getters
18917
18985
  // ---------------------------------------------------------------------------
18918
- getChartRuntime(sheetId, figureId) {
18919
- if (this.outOfDate.has(figureId) ||
18920
- !(sheetId in this.chartRuntime) ||
18921
- !(figureId in this.chartRuntime[sheetId])) {
18922
- const chartDefinition = this.getters.getChartDefinition(sheetId, figureId);
18986
+ getChartRuntime(figureId) {
18987
+ if (this.outOfDate.has(figureId) || !(figureId in this.chartRuntime)) {
18988
+ const chartDefinition = this.getters.getChartDefinition(figureId);
18923
18989
  if (chartDefinition === undefined)
18924
18990
  return;
18925
- if (!this.chartRuntime[sheetId])
18926
- this.chartRuntime[sheetId] = {};
18927
- this.chartRuntime[sheetId][figureId] = this.mapDefinitionToRuntime(chartDefinition);
18991
+ this.chartRuntime[figureId] = this.mapDefinitionToRuntime(chartDefinition);
18928
18992
  this.outOfDate.delete(figureId);
18929
18993
  }
18930
- return this.chartRuntime[sheetId][figureId];
18994
+ return this.chartRuntime[figureId];
18931
18995
  }
18932
18996
  truncateLabel(label) {
18933
18997
  if (!label) {
@@ -19032,9 +19096,10 @@ class EvaluationChartPlugin extends UIPlugin {
19032
19096
  }
19033
19097
  return sheetIds;
19034
19098
  }
19035
- evaluateUsedSheets(chartsDefinitions) {
19099
+ evaluateUsedSheets(chartsIds) {
19036
19100
  const usedSheetsId = new Set();
19037
- for (const chartDefinition of chartsDefinitions) {
19101
+ for (let chartId of chartsIds) {
19102
+ const chartDefinition = this.getters.getChartDefinition(chartId);
19038
19103
  const sheetsIds = chartDefinition !== undefined ? this.getSheetIdsUsedInChart(chartDefinition) : [];
19039
19104
  sheetsIds.forEach((sheetId) => {
19040
19105
  if (sheetId !== this.getters.getActiveSheetId()) {
@@ -27821,7 +27886,7 @@ class ChartFigure extends owl.Component {
27821
27886
  setup() {
27822
27887
  onMounted$4(() => {
27823
27888
  const figure = this.props.figure;
27824
- const chartData = this.env.getters.getChartRuntime(this.env.getters.getActiveSheetId(), figure.id);
27889
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27825
27890
  if (chartData) {
27826
27891
  this.createChart(chartData);
27827
27892
  }
@@ -27829,8 +27894,7 @@ class ChartFigure extends owl.Component {
27829
27894
  onPatched$1(() => {
27830
27895
  var _a, _b, _c;
27831
27896
  const figure = this.props.figure;
27832
- const sheetId = this.env.getters.getActiveSheetId();
27833
- const chartData = this.env.getters.getChartRuntime(sheetId, figure.id);
27897
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27834
27898
  if (chartData) {
27835
27899
  if (chartData.type !== this.chart.config.type) {
27836
27900
  // Updating a chart type requires to update its options accordingly, if feasible at all.
@@ -27856,7 +27920,7 @@ class ChartFigure extends owl.Component {
27856
27920
  else {
27857
27921
  this.chart && this.chart.destroy();
27858
27922
  }
27859
- const def = this.env.getters.getChartDefinition(sheetId, figure.id);
27923
+ const def = this.env.getters.getChartDefinition(figure.id);
27860
27924
  if (def) {
27861
27925
  this.state.background = def.background;
27862
27926
  }
@@ -27866,7 +27930,7 @@ class ChartFigure extends owl.Component {
27866
27930
  const canvas = this.canvas.el;
27867
27931
  const ctx = canvas.getContext("2d");
27868
27932
  this.chart = new window.Chart(ctx, chartData);
27869
- const def = this.env.getters.getChartDefinition(this.env.getters.getActiveSheetId(), this.props.figure.id);
27933
+ const def = this.env.getters.getChartDefinition(this.props.figure.id);
27870
27934
  if (def) {
27871
27935
  this.state.background = def.background;
27872
27936
  }
@@ -27876,10 +27940,8 @@ class ChartFigure extends owl.Component {
27876
27940
  registry.add("edit", {
27877
27941
  name: _lt("Edit"),
27878
27942
  sequence: 1,
27879
- action: () => this.env.openSidePanel("ChartPanel", {
27880
- sheetId: this.env.getters.getActiveSheetId(),
27881
- figure: this.props.figure,
27882
- }),
27943
+ action: () => this.env.openSidePanel("ChartPanel", { figure: this.props.figure }),
27944
+ isVisible: () => !!this.env.getters.getChartDefinition(this.props.figure.id),
27883
27945
  });
27884
27946
  registry.add("delete", {
27885
27947
  name: _lt("Delete"),
@@ -27890,10 +27952,7 @@ class ChartFigure extends owl.Component {
27890
27952
  id: this.props.figure.id,
27891
27953
  });
27892
27954
  if (this.props.sidePanelIsOpen) {
27893
- this.env.toggleSidePanel("ChartPanel", {
27894
- sheetId: this.env.getters.getActiveSheetId(),
27895
- figure: this.props.figure,
27896
- });
27955
+ this.env.toggleSidePanel("ChartPanel", { figure: this.props.figure });
27897
27956
  }
27898
27957
  this.props.onFigureDeleted();
27899
27958
  },
@@ -27903,7 +27962,6 @@ class ChartFigure extends owl.Component {
27903
27962
  sequence: 11,
27904
27963
  action: () => {
27905
27964
  this.env.dispatch("REFRESH_CHART", {
27906
- sheetId: this.env.getters.getActiveSheetId(),
27907
27965
  id: this.props.figure.id,
27908
27966
  });
27909
27967
  },
@@ -28151,10 +28209,7 @@ class FiguresContainer extends owl.Component {
28151
28209
  return;
28152
28210
  }
28153
28211
  if (this.props.sidePanelIsOpen) {
28154
- this.env.openSidePanel("ChartPanel", {
28155
- sheetId: this.env.getters.getActiveSheetId(),
28156
- figure,
28157
- });
28212
+ this.env.openSidePanel("ChartPanel", { figure });
28158
28213
  }
28159
28214
  const initialX = ev.clientX;
28160
28215
  const initialY = ev.clientY;
@@ -31234,6 +31289,6 @@ exports.registries = registries;
31234
31289
  exports.setTranslationMethod = setTranslationMethod;
31235
31290
 
31236
31291
 
31237
- __info__.version = '15.2.0';
31238
- __info__.date = '2023-02-27T14:23:03.128Z';
31239
- __info__.hash = 'd07958f';
31292
+ __info__.version = '15.2.1';
31293
+ __info__.date = '2023-03-06T07:16:45.196Z';
31294
+ __info__.hash = 'baeea23';