@odoo/o-spreadsheet 15.2.0 → 15.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1389,6 +1389,7 @@
1389
1389
  CommandResult[CommandResult["FigureDoesNotExist"] = 55] = "FigureDoesNotExist";
1390
1390
  CommandResult[CommandResult["DuplicatedFigureId"] = 56] = "DuplicatedFigureId";
1391
1391
  CommandResult[CommandResult["DuplicatedChartId"] = 57] = "DuplicatedChartId";
1392
+ CommandResult[CommandResult["ChartDoesNotExist"] = 58] = "ChartDoesNotExist";
1392
1393
  })(exports.CommandResult || (exports.CommandResult = {}));
1393
1394
 
1394
1395
  var ReturnFormatType;
@@ -3179,6 +3180,9 @@
3179
3180
  if (isNaN(zone.bottom) || isNaN(zone.top) || isNaN(zone.left) || isNaN(zone.right)) {
3180
3181
  return false;
3181
3182
  }
3183
+ if (zone.top < 0 || zone.left < 0 || zone.right < 0 || zone.bottom < 0) {
3184
+ return false;
3185
+ }
3182
3186
  return zone.bottom >= zone.top && zone.right >= zone.left;
3183
3187
  }
3184
3188
  /**
@@ -8436,13 +8440,7 @@
8436
8440
  data = migrate(data);
8437
8441
  }
8438
8442
  }
8439
- // sanity check: try to fix missing fields/corrupted state by providing
8440
- // sensible default values
8441
- data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8442
- data.sheets = data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s));
8443
- if (data.sheets.length === 0) {
8444
- data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8445
- }
8443
+ data = repairData(data);
8446
8444
  return data;
8447
8445
  }
8448
8446
  function migrate(data) {
@@ -8669,6 +8667,48 @@
8669
8667
  },
8670
8668
  },
8671
8669
  ];
8670
+ /**
8671
+ * This function is used to repair faulty data independently of the migration.
8672
+ */
8673
+ function repairData(data) {
8674
+ data = forceUnicityOfFigure(data);
8675
+ data = setDefaults(data);
8676
+ return data;
8677
+ }
8678
+ /**
8679
+ * Force the unicity of figure ids accross sheets
8680
+ */
8681
+ function forceUnicityOfFigure(data) {
8682
+ if (data.uniqueFigureIds) {
8683
+ return data;
8684
+ }
8685
+ const figureIds = new Set();
8686
+ const uuidGenerator = new UuidGenerator();
8687
+ for (const sheet of data.sheets || []) {
8688
+ for (const figure of sheet.figures || []) {
8689
+ if (figureIds.has(figure.id)) {
8690
+ figure.id += uuidGenerator.uuidv4();
8691
+ }
8692
+ figureIds.add(figure.id);
8693
+ }
8694
+ }
8695
+ data.uniqueFigureIds = true;
8696
+ return data;
8697
+ }
8698
+ /**
8699
+ * sanity check: try to fix missing fields/corrupted state by providing
8700
+ * sensible default values
8701
+ */
8702
+ function setDefaults(data) {
8703
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
8704
+ data.sheets = data.sheets
8705
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
8706
+ : [];
8707
+ if (data.sheets.length === 0) {
8708
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
8709
+ }
8710
+ return data;
8711
+ }
8672
8712
  /**
8673
8713
  * The goal of this function is to repair corrupted/wrong initial messages caused by
8674
8714
  * a bug.
@@ -8756,6 +8796,7 @@
8756
8796
  formats: {},
8757
8797
  borders: {},
8758
8798
  revisionId: DEFAULT_REVISION_ID,
8799
+ uniqueFigureIds: true,
8759
8800
  };
8760
8801
  return data;
8761
8802
  }
@@ -9796,34 +9837,32 @@
9796
9837
  this.chartFigures = {};
9797
9838
  }
9798
9839
  adaptRanges(applyChange) {
9799
- for (const sheetId of Object.keys(this.chartFigures)) {
9800
- for (const [chartId, chart] of Object.entries(this.chartFigures[sheetId] || {})) {
9801
- if (chart) {
9802
- this.adaptDataSetRanges(sheetId, chart, chartId, applyChange);
9803
- this.adaptLabelRanges(sheetId, chart, chartId, applyChange);
9804
- }
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);
9805
9844
  }
9806
9845
  }
9807
9846
  }
9808
- adaptDataSetRanges(sheetId, chart, chartId, applyChange) {
9847
+ adaptDataSetRanges(chart, chartId, applyChange) {
9809
9848
  for (let ds of chart.dataSets) {
9810
9849
  if (ds.labelCell) {
9811
9850
  const labelCellChange = applyChange(ds.labelCell);
9812
9851
  switch (labelCellChange.changeType) {
9813
9852
  case "REMOVE":
9814
- 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);
9815
9854
  break;
9816
9855
  case "RESIZE":
9817
9856
  case "MOVE":
9818
9857
  case "CHANGE":
9819
- 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);
9820
9859
  }
9821
9860
  }
9822
9861
  const dataRangeChange = applyChange(ds.dataRange);
9823
9862
  switch (dataRangeChange.changeType) {
9824
9863
  case "REMOVE":
9825
9864
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9826
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9865
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9827
9866
  break;
9828
9867
  case "RESIZE":
9829
9868
  case "MOVE":
@@ -9831,27 +9870,27 @@
9831
9870
  // We have to remove the ranges that are #REF
9832
9871
  if (this.getters.getRangeString(dataRangeChange.range, dataRangeChange.range.sheetId) !==
9833
9872
  INCORRECT_RANGE_STRING) {
9834
- 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);
9835
9874
  }
9836
9875
  else {
9837
9876
  const newDataSets = chart.dataSets.filter((dataset) => dataset !== ds);
9838
- this.history.update("chartFigures", sheetId, chartId, "dataSets", newDataSets);
9877
+ this.history.update("chartFigures", chartId, "dataSets", newDataSets);
9839
9878
  }
9840
9879
  break;
9841
9880
  }
9842
9881
  }
9843
9882
  }
9844
- adaptLabelRanges(sheetId, chart, chartId, applyChange) {
9883
+ adaptLabelRanges(chart, chartId, applyChange) {
9845
9884
  if (chart.labelRange) {
9846
9885
  const labelRangeChange = applyChange(chart.labelRange);
9847
9886
  switch (labelRangeChange.changeType) {
9848
9887
  case "REMOVE":
9849
- this.history.update("chartFigures", sheetId, chartId, "labelRange", undefined);
9888
+ this.history.update("chartFigures", chartId, "labelRange", undefined);
9850
9889
  break;
9851
9890
  case "RESIZE":
9852
9891
  case "MOVE":
9853
9892
  case "CHANGE":
9854
- this.history.update("chartFigures", sheetId, chartId, "labelRange", labelRangeChange.range);
9893
+ this.history.update("chartFigures", chartId, "labelRange", labelRangeChange.range);
9855
9894
  break;
9856
9895
  }
9857
9896
  }
@@ -9862,16 +9901,16 @@
9862
9901
  allowDispatch(cmd) {
9863
9902
  const success = 0 /* Success */;
9864
9903
  switch (cmd.type) {
9865
- case "CREATE_CHART":
9866
- return this.checkValidations(cmd, this.chainValidations(this.checkChartDuplicate, this.checkEmptyDataset, this.checkDataset), this.checkLabelRange);
9867
9904
  case "UPDATE_CHART":
9868
- 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);
9869
9908
  default:
9870
9909
  return success;
9871
9910
  }
9872
9911
  }
9873
9912
  handle(cmd) {
9874
- var _a;
9913
+ var _a, _b;
9875
9914
  switch (cmd.type) {
9876
9915
  case "CREATE_CHART":
9877
9916
  const x = cmd.position ? cmd.position.x : 0;
@@ -9886,7 +9925,7 @@
9886
9925
  });
9887
9926
  break;
9888
9927
  case "UPDATE_CHART": {
9889
- this.updateChartDefinition(cmd.sheetId, cmd.id, cmd.definition);
9928
+ this.updateChartDefinition(cmd.id, cmd.definition);
9890
9929
  break;
9891
9930
  }
9892
9931
  case "DUPLICATE_SHEET": {
@@ -9896,7 +9935,7 @@
9896
9935
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
9897
9936
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
9898
9937
  const chartDefinition = {
9899
- ...deepCopy(this.chartFigures[cmd.sheetId][fig.id]),
9938
+ ...deepCopy(this.chartFigures[fig.id]),
9900
9939
  id: duplicatedFigureId,
9901
9940
  };
9902
9941
  chartDefinition.sheetId = cmd.sheetIdTo;
@@ -9926,28 +9965,37 @@
9926
9965
  break;
9927
9966
  }
9928
9967
  case "DELETE_FIGURE":
9929
- this.history.update("chartFigures", cmd.sheetId, cmd.id, undefined);
9968
+ this.history.update("chartFigures", cmd.id, undefined);
9930
9969
  break;
9931
9970
  case "DELETE_SHEET":
9932
- 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
+ }
9933
9976
  break;
9934
9977
  }
9935
9978
  }
9936
9979
  // ---------------------------------------------------------------------------
9937
9980
  // Getters
9938
9981
  // ---------------------------------------------------------------------------
9939
- getChartDefinition(sheetId, figureId) {
9940
- var _a;
9941
- return (_a = this.chartFigures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
9982
+ getChartDefinition(figureId) {
9983
+ return this.chartFigures[figureId];
9942
9984
  }
9943
- getChartDefinitionsBySheet(sheetId) {
9944
- 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]);
9945
9991
  }
9946
- getChartDefinitionUI(sheetId, figureId, forceSheetName = false) {
9947
- const data = this.chartFigures[sheetId][figureId];
9948
- const rangeSheetId = forceSheetName ? "forceSheetReference" : sheetId;
9992
+ getChartDefinitionUI(sheetId, figureId) {
9993
+ const data = this.chartFigures[figureId];
9994
+ if (!data) {
9995
+ return undefined;
9996
+ }
9949
9997
  const dataSets = data.dataSets
9950
- .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, rangeSheetId) : ""))
9998
+ .map((ds) => (ds ? this.getters.getRangeString(ds.dataRange, sheetId) : ""))
9951
9999
  .filter((ds) => {
9952
10000
  return ds !== ""; // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9953
10001
  });
@@ -9955,7 +10003,7 @@
9955
10003
  title: data && data.title ? data.title : "",
9956
10004
  dataSets,
9957
10005
  labelRange: data.labelRange
9958
- ? this.getters.getRangeString(data.labelRange, rangeSheetId)
10006
+ ? this.getters.getRangeString(data.labelRange, sheetId)
9959
10007
  : undefined,
9960
10008
  type: data ? data.type : "bar",
9961
10009
  dataSetsHaveTitle: data && dataSets.length !== 0 ? Boolean(data.dataSets[0].labelCell) : false,
@@ -9966,12 +10014,16 @@
9966
10014
  };
9967
10015
  }
9968
10016
  getChartDefinitionExcel(sheetId, figureId) {
9969
- 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
+ }
9970
10022
  const dataSets = data.dataSets
9971
10023
  .map((ds) => this.toExcelDataset(ds))
9972
10024
  .filter((ds) => ds.range !== ""); // && range !== INCORRECT_RANGE_STRING ? show incorrect #ref ?
9973
10025
  return {
9974
- ...this.getChartDefinitionUI(sheetId, figureId, true),
10026
+ ...dataUI,
9975
10027
  backgroundColor: data.background,
9976
10028
  dataSets,
9977
10029
  };
@@ -10006,17 +10058,15 @@
10006
10058
  import(data) {
10007
10059
  for (let sheet of data.sheets) {
10008
10060
  if (sheet.figures) {
10009
- const charts = {};
10010
10061
  for (let figure of sheet.figures) {
10011
10062
  if (figure.tag === "chart") {
10012
10063
  const figureData = {
10013
10064
  ...figure.data,
10014
10065
  };
10015
- charts[figure.id] = this.createChartDefinition(figureData, sheet.id);
10066
+ this.chartFigures[figure.id] = this.createChartDefinition(figureData, sheet.id);
10016
10067
  delete figure.data;
10017
10068
  }
10018
10069
  }
10019
- this.chartFigures[sheet.id] = charts;
10020
10070
  }
10021
10071
  }
10022
10072
  }
@@ -10024,10 +10074,18 @@
10024
10074
  if (data.sheets) {
10025
10075
  for (let sheet of data.sheets) {
10026
10076
  const sheetFigures = this.getters.getFigures(sheet.id);
10027
- const figures = sheetFigures;
10028
- for (let figure of figures) {
10077
+ const figures = [];
10078
+ for (let sheetFigure of sheetFigures) {
10079
+ const figure = sheetFigure;
10029
10080
  if (figure && figure.tag === "chart") {
10030
- 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);
10031
10089
  }
10032
10090
  }
10033
10091
  sheet.figures = figures;
@@ -10037,10 +10095,18 @@
10037
10095
  exportForExcel(data) {
10038
10096
  for (let sheet of data.sheets) {
10039
10097
  const sheetFigures = this.getters.getFigures(sheet.id);
10040
- const figures = sheetFigures;
10041
- for (let figure of figures) {
10098
+ const figures = [];
10099
+ for (let sheetFigure of sheetFigures) {
10100
+ const figure = sheetFigure;
10042
10101
  if (figure && figure.tag === "chart") {
10043
- 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);
10044
10110
  }
10045
10111
  }
10046
10112
  sheet.charts = figures;
@@ -10066,39 +10132,39 @@
10066
10132
  * Update the chart definition linked to the given id with the attributes
10067
10133
  * given in the partial UI definition
10068
10134
  */
10069
- updateChartDefinition(sheetId, id, definition) {
10070
- const chart = this.chartFigures[sheetId][id];
10135
+ updateChartDefinition(id, definition) {
10136
+ const chart = this.chartFigures[id];
10071
10137
  if (!chart) {
10072
10138
  throw new Error(`There is no chart with the given id: ${id}`);
10073
10139
  }
10074
10140
  if (definition.title !== undefined) {
10075
- this.history.update("chartFigures", sheetId, id, "title", definition.title);
10141
+ this.history.update("chartFigures", id, "title", definition.title);
10076
10142
  }
10077
10143
  if (definition.type) {
10078
- this.history.update("chartFigures", sheetId, id, "type", definition.type);
10144
+ this.history.update("chartFigures", id, "type", definition.type);
10079
10145
  }
10080
10146
  if (definition.dataSets) {
10081
10147
  const dataSetsHaveTitle = !!definition.dataSetsHaveTitle;
10082
10148
  const dataSets = this.createDataSets(definition.dataSets, chart.sheetId, dataSetsHaveTitle);
10083
- this.history.update("chartFigures", sheetId, id, "dataSets", dataSets);
10149
+ this.history.update("chartFigures", id, "dataSets", dataSets);
10084
10150
  }
10085
10151
  if (definition.labelRange !== undefined) {
10086
10152
  const labelRange = definition.labelRange
10087
10153
  ? this.getters.getRangeFromSheetXC(chart.sheetId, definition.labelRange)
10088
10154
  : undefined;
10089
- this.history.update("chartFigures", sheetId, id, "labelRange", labelRange);
10155
+ this.history.update("chartFigures", id, "labelRange", labelRange);
10090
10156
  }
10091
10157
  if (definition.background) {
10092
- this.history.update("chartFigures", sheetId, id, "background", definition.background);
10158
+ this.history.update("chartFigures", id, "background", definition.background);
10093
10159
  }
10094
10160
  if (definition.verticalAxisPosition) {
10095
- this.history.update("chartFigures", sheetId, id, "verticalAxisPosition", definition.verticalAxisPosition);
10161
+ this.history.update("chartFigures", id, "verticalAxisPosition", definition.verticalAxisPosition);
10096
10162
  }
10097
10163
  if (definition.legendPosition) {
10098
- this.history.update("chartFigures", sheetId, id, "legendPosition", definition.legendPosition);
10164
+ this.history.update("chartFigures", id, "legendPosition", definition.legendPosition);
10099
10165
  }
10100
10166
  if (definition.stackedBar !== undefined) {
10101
- this.history.update("chartFigures", sheetId, id, "stackedBar", definition.stackedBar);
10167
+ this.history.update("chartFigures", id, "stackedBar", definition.stackedBar);
10102
10168
  }
10103
10169
  }
10104
10170
  createDataSets(dataSetsString, sheetId, dataSetsHaveTitle) {
@@ -10153,7 +10219,7 @@
10153
10219
  sheetId,
10154
10220
  figure,
10155
10221
  });
10156
- this.history.update("chartFigures", sheetId, figure.id, data);
10222
+ this.history.update("chartFigures", figure.id, data);
10157
10223
  }
10158
10224
  createDataSet(sheetId, fullZone, titleZone) {
10159
10225
  if (fullZone.left !== fullZone.right && fullZone.top !== fullZone.bottom) {
@@ -10194,18 +10260,20 @@
10194
10260
  return invalidLabels ? 29 /* InvalidLabelRange */ : 0 /* Success */;
10195
10261
  }
10196
10262
  checkChartDuplicate(cmd) {
10197
- var _a;
10198
- if ((_a = this.chartFigures[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[cmd.id]) {
10199
- 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
+ }
10200
10267
  }
10201
10268
  return 0 /* Success */;
10202
10269
  }
10270
+ checkChartExists(cmd) {
10271
+ return this.getters.getFigure(cmd.sheetId, cmd.id)
10272
+ ? 0 /* Success */
10273
+ : 58 /* ChartDoesNotExist */;
10274
+ }
10203
10275
  }
10204
- ChartPlugin.getters = [
10205
- "getChartDefinition",
10206
- "getChartDefinitionUI",
10207
- "getChartDefinitionsBySheet",
10208
- ];
10276
+ ChartPlugin.getters = ["getChartDefinition", "getChartDefinitionUI", "getChartsIdBySheet"];
10209
10277
 
10210
10278
  // -----------------------------------------------------------------------------
10211
10279
  // Constants
@@ -10544,7 +10612,7 @@
10544
10612
  allowDispatch(cmd) {
10545
10613
  switch (cmd.type) {
10546
10614
  case "CREATE_FIGURE":
10547
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
10615
+ return this.checkFigureDuplicate(cmd.figure.id);
10548
10616
  case "UPDATE_FIGURE":
10549
10617
  case "DELETE_FIGURE":
10550
10618
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -10610,9 +10678,8 @@
10610
10678
  }
10611
10679
  return 0 /* Success */;
10612
10680
  }
10613
- checkFigureDuplicate(sheetId, figureId) {
10614
- var _a;
10615
- 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])) {
10616
10683
  return 56 /* DuplicatedFigureId */;
10617
10684
  }
10618
10685
  return 0 /* Success */;
@@ -10627,6 +10694,9 @@
10627
10694
  var _a;
10628
10695
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
10629
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
+ }
10630
10700
  // ---------------------------------------------------------------------------
10631
10701
  // Import/Export
10632
10702
  // ---------------------------------------------------------------------------
@@ -10651,7 +10721,7 @@
10651
10721
  this.export(data);
10652
10722
  }
10653
10723
  }
10654
- FigurePlugin.getters = ["getFigures", "getFigure"];
10724
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
10655
10725
 
10656
10726
  class MergePlugin extends CorePlugin {
10657
10727
  constructor() {
@@ -12954,7 +13024,7 @@
12954
13024
  },
12955
13025
  });
12956
13026
  const figure = env.getters.getFigure(sheetId, id);
12957
- env.openSidePanel("ChartPanel", { sheetId, figure });
13027
+ env.openSidePanel("ChartPanel", { figure });
12958
13028
  };
12959
13029
  //------------------------------------------------------------------------------
12960
13030
  // Style/Format
@@ -14467,15 +14537,17 @@
14467
14537
  constructor() {
14468
14538
  super(...arguments);
14469
14539
  this.getters = this.env.getters;
14540
+ this.chartSheetId = this.findSheetId(this.props.figure.id);
14470
14541
  this.state = owl.useState(this.initialState(this.props.figure));
14471
14542
  }
14472
14543
  setup() {
14473
14544
  onWillUpdateProps$6((nextProps) => {
14474
- if (!this.getters.getChartDefinition(nextProps.sheetId, nextProps.figure.id)) {
14545
+ if (!this.getters.getChartDefinition(nextProps.figure.id)) {
14475
14546
  this.props.onCloseSidePanel();
14476
14547
  return;
14477
14548
  }
14478
14549
  if (nextProps.figure.id !== this.props.figure.id) {
14550
+ this.chartSheetId = this.findSheetId(nextProps.figure.id);
14479
14551
  this.state.panel = "configuration";
14480
14552
  this.state.fillColorTool = false;
14481
14553
  this.state.datasetDispatchResult = undefined;
@@ -14528,7 +14600,7 @@
14528
14600
  updateChart(definition) {
14529
14601
  return this.env.dispatch("UPDATE_CHART", {
14530
14602
  id: this.props.figure.id,
14531
- sheetId: this.props.sheetId,
14603
+ sheetId: this.chartSheetId,
14532
14604
  definition,
14533
14605
  });
14534
14606
  }
@@ -14550,12 +14622,16 @@
14550
14622
  this.state.panel = panel;
14551
14623
  }
14552
14624
  initialState(figure) {
14625
+ const sheetId = this.findSheetId(figure.id);
14553
14626
  return {
14554
- chart: this.env.getters.getChartDefinitionUI(this.env.getters.getActiveSheetId(), figure.id),
14627
+ chart: this.env.getters.getChartDefinitionUI(sheetId, figure.id),
14555
14628
  panel: "configuration",
14556
14629
  fillColorTool: false,
14557
14630
  };
14558
14631
  }
14632
+ findSheetId(figureId) {
14633
+ return this.env.getters.getFigureSheetId(figureId) || "";
14634
+ }
14559
14635
  }
14560
14636
  ChartPanel.template = TEMPLATE$m;
14561
14637
  ChartPanel.style = STYLE;
@@ -18871,60 +18947,51 @@
18871
18947
  this.outOfDate = new Set();
18872
18948
  }
18873
18949
  handle(cmd) {
18874
- var _a;
18875
18950
  if (invalidateEvaluationCommands.has(cmd.type) ||
18876
18951
  cmd.type === "EVALUATE_CELLS" ||
18877
18952
  (cmd.type === "UPDATE_CELL" && "content" in cmd)) {
18878
- for (const sheetId of Object.keys(this.chartRuntime)) {
18879
- for (const chartId of Object.keys(this.chartRuntime[sheetId] || {})) {
18880
- this.outOfDate.add(chartId);
18881
- }
18953
+ for (let chartId of Object.keys(this.chartRuntime)) {
18954
+ this.outOfDate.add(chartId);
18882
18955
  }
18883
18956
  }
18884
18957
  switch (cmd.type) {
18885
18958
  case "UPDATE_CHART":
18886
- case "CREATE_CHART": {
18887
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18888
- if (!this.chartRuntime[cmd.sheetId])
18889
- this.chartRuntime[cmd.sheetId] = {};
18890
- 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);
18891
18962
  break;
18892
- }
18893
18963
  case "DELETE_FIGURE":
18894
- (_a = this.chartRuntime[cmd.sheetId]) === null || _a === void 0 ? true : delete _a[cmd.id];
18964
+ delete this.chartRuntime[cmd.id];
18895
18965
  break;
18896
- case "REFRESH_CHART": {
18897
- const chartDefinition = this.getters.getChartDefinition(cmd.sheetId, cmd.id);
18898
- this.evaluateUsedSheets([chartDefinition]);
18966
+ case "REFRESH_CHART":
18967
+ this.evaluateUsedSheets([cmd.id]);
18899
18968
  this.outOfDate.add(cmd.id);
18900
18969
  break;
18901
- }
18902
- case "ACTIVATE_SHEET": {
18903
- const chartsDefinitions = this.getters.getChartDefinitionsBySheet(cmd.sheetIdTo);
18904
- this.evaluateUsedSheets(chartsDefinitions);
18970
+ case "ACTIVATE_SHEET":
18971
+ const chartsIds = this.getters.getChartsIdBySheet(cmd.sheetIdTo);
18972
+ this.evaluateUsedSheets(chartsIds);
18905
18973
  break;
18906
- }
18907
18974
  case "DELETE_SHEET":
18908
- 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
+ }
18909
18980
  break;
18910
18981
  }
18911
18982
  }
18912
18983
  // ---------------------------------------------------------------------------
18913
18984
  // Getters
18914
18985
  // ---------------------------------------------------------------------------
18915
- getChartRuntime(sheetId, figureId) {
18916
- if (this.outOfDate.has(figureId) ||
18917
- !(sheetId in this.chartRuntime) ||
18918
- !(figureId in this.chartRuntime[sheetId])) {
18919
- 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);
18920
18989
  if (chartDefinition === undefined)
18921
18990
  return;
18922
- if (!this.chartRuntime[sheetId])
18923
- this.chartRuntime[sheetId] = {};
18924
- this.chartRuntime[sheetId][figureId] = this.mapDefinitionToRuntime(chartDefinition);
18991
+ this.chartRuntime[figureId] = this.mapDefinitionToRuntime(chartDefinition);
18925
18992
  this.outOfDate.delete(figureId);
18926
18993
  }
18927
- return this.chartRuntime[sheetId][figureId];
18994
+ return this.chartRuntime[figureId];
18928
18995
  }
18929
18996
  truncateLabel(label) {
18930
18997
  if (!label) {
@@ -19029,9 +19096,10 @@
19029
19096
  }
19030
19097
  return sheetIds;
19031
19098
  }
19032
- evaluateUsedSheets(chartsDefinitions) {
19099
+ evaluateUsedSheets(chartsIds) {
19033
19100
  const usedSheetsId = new Set();
19034
- for (const chartDefinition of chartsDefinitions) {
19101
+ for (let chartId of chartsIds) {
19102
+ const chartDefinition = this.getters.getChartDefinition(chartId);
19035
19103
  const sheetsIds = chartDefinition !== undefined ? this.getSheetIdsUsedInChart(chartDefinition) : [];
19036
19104
  sheetsIds.forEach((sheetId) => {
19037
19105
  if (sheetId !== this.getters.getActiveSheetId()) {
@@ -23441,6 +23509,7 @@
23441
23509
  }
23442
23510
  else if (range.zone[start] >= min && range.zone[end] <= max) {
23443
23511
  changeType = "REMOVE";
23512
+ newRange = this.buildInvalidRange(INCORRECT_RANGE_STRING);
23444
23513
  }
23445
23514
  else if (range.zone[start] <= max && range.zone[end] >= max) {
23446
23515
  const toRemove = max - range.zone[start] + 1;
@@ -23506,10 +23575,8 @@
23506
23575
  return { changeType: "NONE" };
23507
23576
  }
23508
23577
  range = {
23509
- ...range,
23510
- zone: { ...range.zone },
23578
+ ...this.buildInvalidRange(INCORRECT_RANGE_STRING),
23511
23579
  invalidSheetName: this.getters.getSheetName(cmd.sheetId),
23512
- sheetId: "",
23513
23580
  };
23514
23581
  return { changeType: "REMOVE", range };
23515
23582
  }, cmd.sheetId);
@@ -27818,7 +27885,7 @@
27818
27885
  setup() {
27819
27886
  onMounted$4(() => {
27820
27887
  const figure = this.props.figure;
27821
- const chartData = this.env.getters.getChartRuntime(this.env.getters.getActiveSheetId(), figure.id);
27888
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27822
27889
  if (chartData) {
27823
27890
  this.createChart(chartData);
27824
27891
  }
@@ -27826,8 +27893,7 @@
27826
27893
  onPatched$1(() => {
27827
27894
  var _a, _b, _c;
27828
27895
  const figure = this.props.figure;
27829
- const sheetId = this.env.getters.getActiveSheetId();
27830
- const chartData = this.env.getters.getChartRuntime(sheetId, figure.id);
27896
+ const chartData = this.env.getters.getChartRuntime(figure.id);
27831
27897
  if (chartData) {
27832
27898
  if (chartData.type !== this.chart.config.type) {
27833
27899
  // Updating a chart type requires to update its options accordingly, if feasible at all.
@@ -27853,7 +27919,7 @@
27853
27919
  else {
27854
27920
  this.chart && this.chart.destroy();
27855
27921
  }
27856
- const def = this.env.getters.getChartDefinition(sheetId, figure.id);
27922
+ const def = this.env.getters.getChartDefinition(figure.id);
27857
27923
  if (def) {
27858
27924
  this.state.background = def.background;
27859
27925
  }
@@ -27863,7 +27929,7 @@
27863
27929
  const canvas = this.canvas.el;
27864
27930
  const ctx = canvas.getContext("2d");
27865
27931
  this.chart = new window.Chart(ctx, chartData);
27866
- const def = this.env.getters.getChartDefinition(this.env.getters.getActiveSheetId(), this.props.figure.id);
27932
+ const def = this.env.getters.getChartDefinition(this.props.figure.id);
27867
27933
  if (def) {
27868
27934
  this.state.background = def.background;
27869
27935
  }
@@ -27873,10 +27939,8 @@
27873
27939
  registry.add("edit", {
27874
27940
  name: _lt("Edit"),
27875
27941
  sequence: 1,
27876
- action: () => this.env.openSidePanel("ChartPanel", {
27877
- sheetId: this.env.getters.getActiveSheetId(),
27878
- figure: this.props.figure,
27879
- }),
27942
+ action: () => this.env.openSidePanel("ChartPanel", { figure: this.props.figure }),
27943
+ isVisible: () => !!this.env.getters.getChartDefinition(this.props.figure.id),
27880
27944
  });
27881
27945
  registry.add("delete", {
27882
27946
  name: _lt("Delete"),
@@ -27887,10 +27951,7 @@
27887
27951
  id: this.props.figure.id,
27888
27952
  });
27889
27953
  if (this.props.sidePanelIsOpen) {
27890
- this.env.toggleSidePanel("ChartPanel", {
27891
- sheetId: this.env.getters.getActiveSheetId(),
27892
- figure: this.props.figure,
27893
- });
27954
+ this.env.toggleSidePanel("ChartPanel", { figure: this.props.figure });
27894
27955
  }
27895
27956
  this.props.onFigureDeleted();
27896
27957
  },
@@ -27900,7 +27961,6 @@
27900
27961
  sequence: 11,
27901
27962
  action: () => {
27902
27963
  this.env.dispatch("REFRESH_CHART", {
27903
- sheetId: this.env.getters.getActiveSheetId(),
27904
27964
  id: this.props.figure.id,
27905
27965
  });
27906
27966
  },
@@ -28148,10 +28208,7 @@
28148
28208
  return;
28149
28209
  }
28150
28210
  if (this.props.sidePanelIsOpen) {
28151
- this.env.openSidePanel("ChartPanel", {
28152
- sheetId: this.env.getters.getActiveSheetId(),
28153
- figure,
28154
- });
28211
+ this.env.openSidePanel("ChartPanel", { figure });
28155
28212
  }
28156
28213
  const initialX = ev.clientX;
28157
28214
  const initialY = ev.clientY;
@@ -31233,9 +31290,9 @@
31233
31290
  Object.defineProperty(exports, '__esModule', { value: true });
31234
31291
 
31235
31292
 
31236
- __info__.version = '15.2.0';
31237
- __info__.date = '2023-02-27T14:23:03.128Z';
31238
- __info__.hash = 'd07958f';
31293
+ __info__.version = '15.2.2';
31294
+ __info__.date = '2023-03-14T09:19:31.079Z';
31295
+ __info__.hash = 'a3fcdb7';
31239
31296
 
31240
31297
 
31241
31298
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);