@odoo/o-spreadsheet 16.2.0-alpha.2 → 16.2.0-alpha.3

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.
@@ -274,7 +274,6 @@
274
274
  ComponentsImportance[ComponentsImportance["Dropdown"] = 16] = "Dropdown";
275
275
  ComponentsImportance[ComponentsImportance["GridComposer"] = 20] = "GridComposer";
276
276
  ComponentsImportance[ComponentsImportance["TopBarComposer"] = 21] = "TopBarComposer";
277
- ComponentsImportance[ComponentsImportance["ColorPicker"] = 25] = "ColorPicker";
278
277
  ComponentsImportance[ComponentsImportance["IconPicker"] = 25] = "IconPicker";
279
278
  ComponentsImportance[ComponentsImportance["Popover"] = 30] = "Popover";
280
279
  ComponentsImportance[ComponentsImportance["ChartAnchor"] = 1000] = "ChartAnchor";
@@ -2844,7 +2843,7 @@
2844
2843
  return `background-color: ${this.background}`;
2845
2844
  }
2846
2845
  get chartRuntime() {
2847
- const runtime = this.env.model.getters.getChartRuntime(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
2846
+ const runtime = this.env.model.getters.getChartRuntime(this.props.figure.id);
2848
2847
  if (!("chartJsConfig" in runtime)) {
2849
2848
  throw new Error("Unsupported chart runtime");
2850
2849
  }
@@ -3109,7 +3108,7 @@
3109
3108
  this.ctx = document.createElement("canvas").getContext("2d");
3110
3109
  }
3111
3110
  get runtime() {
3112
- return this.env.model.getters.getChartRuntime(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
3111
+ return this.env.model.getters.getChartRuntime(this.props.figure.id);
3113
3112
  }
3114
3113
  get title() {
3115
3114
  return this.runtime.title;
@@ -3498,7 +3497,7 @@
3498
3497
  CommandResult[CommandResult["InvalidRange"] = 25] = "InvalidRange";
3499
3498
  CommandResult[CommandResult["InvalidZones"] = 26] = "InvalidZones";
3500
3499
  CommandResult[CommandResult["InvalidSheetId"] = 27] = "InvalidSheetId";
3501
- CommandResult[CommandResult["DuplicatedImageId"] = 28] = "DuplicatedImageId";
3500
+ CommandResult[CommandResult["InvalidFigureId"] = 28] = "InvalidFigureId";
3502
3501
  CommandResult[CommandResult["InputAlreadyFocused"] = 29] = "InputAlreadyFocused";
3503
3502
  CommandResult[CommandResult["MaximumRangesReached"] = 30] = "MaximumRangesReached";
3504
3503
  CommandResult[CommandResult["InvalidChartDefinition"] = 31] = "InvalidChartDefinition";
@@ -3555,6 +3554,7 @@
3555
3554
  CommandResult[CommandResult["DuplicatedFigureId"] = 82] = "DuplicatedFigureId";
3556
3555
  CommandResult[CommandResult["InvalidSelectionStep"] = 83] = "InvalidSelectionStep";
3557
3556
  CommandResult[CommandResult["DuplicatedChartId"] = 84] = "DuplicatedChartId";
3557
+ CommandResult[CommandResult["ChartDoesNotExist"] = 85] = "ChartDoesNotExist";
3558
3558
  })(exports.CommandResult || (exports.CommandResult = {}));
3559
3559
 
3560
3560
  var DIRECTION;
@@ -6165,7 +6165,7 @@
6165
6165
  return registry;
6166
6166
  }
6167
6167
  get chartType() {
6168
- return this.env.model.getters.getChartType(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
6168
+ return this.env.model.getters.getChartType(this.props.figure.id);
6169
6169
  }
6170
6170
  onContextMenu(ev) {
6171
6171
  const position = {
@@ -17184,7 +17184,7 @@
17184
17184
  id: "reset_size",
17185
17185
  name: _lt("Reset size"),
17186
17186
  action: () => {
17187
- const size = this.env.model.getters.getImage(this.env.model.getters.getActiveSheetId(), this.figureId).size;
17187
+ const size = this.env.model.getters.getImageSize(this.figureId);
17188
17188
  const { height, width } = getMaxFigureSize(this.env.model.getters, size);
17189
17189
  this.env.model.dispatch("UPDATE_FIGURE", {
17190
17190
  sheetId: this.env.model.getters.getActiveSheetId(),
@@ -17233,8 +17233,7 @@
17233
17233
  return this.props.figure.id;
17234
17234
  }
17235
17235
  get getImagePath() {
17236
- return this.env.model.getters.getImage(this.env.model.getters.getActiveSheetId(), this.figureId)
17237
- .path;
17236
+ return this.env.model.getters.getImagePath(this.figureId);
17238
17237
  }
17239
17238
  }
17240
17239
  ImageFigure.template = "o-spreadsheet-ImageFigure";
@@ -18039,9 +18038,9 @@
18039
18038
  const ranges = existingSelectionRange.length
18040
18039
  ? existingSelectionRange
18041
18040
  : this.props.ranges
18042
- ? this.props.ranges.map((xc, i) => ({
18041
+ ? this.props.ranges.map((xc, id) => ({
18043
18042
  xc,
18044
- id: i.toString(),
18043
+ id,
18045
18044
  isFocused: false,
18046
18045
  }))
18047
18046
  : [];
@@ -18107,6 +18106,7 @@
18107
18106
  else if (ev.key === "Enter") {
18108
18107
  const target = ev.target;
18109
18108
  target.blur();
18109
+ this.confirm();
18110
18110
  }
18111
18111
  }
18112
18112
  focus(rangeId) {
@@ -18135,7 +18135,7 @@
18135
18135
  });
18136
18136
  this.triggerChange();
18137
18137
  }
18138
- disable() {
18138
+ confirm() {
18139
18139
  var _a, _b;
18140
18140
  this.env.model.dispatch("UNFOCUS_SELECTION_INPUT");
18141
18141
  const ranges = this.env.model.getters.getSelectionInputValue(this.id);
@@ -18230,7 +18230,6 @@
18230
18230
  LineBarPieConfigPanel.template = "o-spreadsheet-LineBarPieConfigPanel";
18231
18231
  LineBarPieConfigPanel.components = { SelectionInput };
18232
18232
  LineBarPieConfigPanel.props = {
18233
- sheetId: String,
18234
18233
  figureId: String,
18235
18234
  definition: Object,
18236
18235
  updateChart: Function,
@@ -18263,9 +18262,6 @@
18263
18262
  const GRADIENT_HEIGHT = PICKER_WIDTH - 50;
18264
18263
  css /* scss */ `
18265
18264
  .o-color-picker {
18266
- position: absolute;
18267
- top: calc(100% + 5px);
18268
- z-index: ${ComponentsImportance.ColorPicker};
18269
18265
  padding: ${PICKER_PADDING}px 0px;
18270
18266
  box-shadow: 1px 2px 5px 2px rgba(51, 51, 51, 0.15);
18271
18267
  background-color: white;
@@ -18380,15 +18376,6 @@
18380
18376
  width: 100%;
18381
18377
  }
18382
18378
  }
18383
- &.right {
18384
- left: 0;
18385
- }
18386
- &.left {
18387
- right: 0;
18388
- }
18389
- &.center {
18390
- left: calc(50% - ${PICKER_WIDTH / 2}px);
18391
- }
18392
18379
  }
18393
18380
  .o-magnifier-glass {
18394
18381
  position: absolute;
@@ -18423,14 +18410,18 @@
18423
18410
  });
18424
18411
  }
18425
18412
  get colorPickerStyle() {
18426
- if (this.props.maxHeight === undefined)
18427
- return "";
18428
- if (this.props.maxHeight <= 0) {
18413
+ if (this.props.maxHeight !== undefined && this.props.maxHeight <= 0) {
18429
18414
  return cssPropertiesToCss({ display: "none" });
18430
18415
  }
18431
- return cssPropertiesToCss({
18432
- "max-height": `${this.props.maxHeight}px`,
18433
- });
18416
+ return "";
18417
+ }
18418
+ get popoverProps() {
18419
+ return {
18420
+ anchorRect: this.props.anchorRect,
18421
+ maxHeight: this.props.maxHeight,
18422
+ positioning: "BottomLeft",
18423
+ verticalOffset: 0,
18424
+ };
18434
18425
  }
18435
18426
  onColorClick(color) {
18436
18427
  if (color) {
@@ -18485,11 +18476,12 @@
18485
18476
  ColorPicker.defaultProps = {
18486
18477
  currentColor: "", //TODO Change it to false instead of empty string
18487
18478
  };
18479
+ ColorPicker.components = { Popover };
18488
18480
  ColorPicker.props = {
18489
- dropdownDirection: { type: String, optional: true },
18490
18481
  onColorPicked: Function,
18491
18482
  currentColor: { type: String, optional: true },
18492
18483
  maxHeight: { type: Number, optional: true },
18484
+ anchorRect: Object,
18493
18485
  };
18494
18486
 
18495
18487
  css /* scss */ `
@@ -18525,11 +18517,25 @@
18525
18517
  }
18526
18518
  `;
18527
18519
  class ColorPickerWidget extends owl.Component {
18520
+ constructor() {
18521
+ super(...arguments);
18522
+ this.colorPickerButtonRef = owl.useRef("colorPickerButton");
18523
+ }
18528
18524
  get iconStyle() {
18529
18525
  return this.props.currentColor
18530
18526
  ? `border-color: ${this.props.currentColor}`
18531
18527
  : "border-bottom-style: hidden";
18532
18528
  }
18529
+ get colorPickerAnchorRect() {
18530
+ const button = this.colorPickerButtonRef.el;
18531
+ const buttonRect = button.getBoundingClientRect();
18532
+ return {
18533
+ x: buttonRect.x,
18534
+ y: buttonRect.y,
18535
+ width: buttonRect.width,
18536
+ height: buttonRect.height,
18537
+ };
18538
+ }
18533
18539
  }
18534
18540
  ColorPickerWidget.template = "o-spreadsheet-ColorPickerWidget";
18535
18541
  ColorPickerWidget.components = { ColorPicker };
@@ -18539,7 +18545,6 @@
18539
18545
  showColorPicker: Boolean,
18540
18546
  onColorPicked: Function,
18541
18547
  icon: String,
18542
- dropdownDirection: { type: String, optional: true },
18543
18548
  title: { type: String, optional: true },
18544
18549
  disabled: { type: Boolean, optional: true },
18545
18550
  dropdownMaxHeight: { type: Number, optional: true },
@@ -18619,7 +18624,6 @@
18619
18624
  GaugeChartConfigPanel.template = "o-spreadsheet-GaugeChartConfigPanel";
18620
18625
  GaugeChartConfigPanel.components = { SelectionInput };
18621
18626
  GaugeChartConfigPanel.props = {
18622
- sheetId: String,
18623
18627
  figureId: String,
18624
18628
  definition: Object,
18625
18629
  updateChart: Function,
@@ -18766,7 +18770,7 @@
18766
18770
 
18767
18771
  class LineConfigPanel extends LineBarPieConfigPanel {
18768
18772
  get canTreatLabelsAsText() {
18769
- const chart = this.env.model.getters.getChart(this.props.sheetId, this.props.figureId);
18773
+ const chart = this.env.model.getters.getChart(this.props.figureId);
18770
18774
  if (chart && chart instanceof LineChart) {
18771
18775
  return canChartParseLabels(chart.labelRange, this.env.model.getters);
18772
18776
  }
@@ -18843,7 +18847,6 @@
18843
18847
  ScorecardChartConfigPanel.template = "o-spreadsheet-ScorecardChartConfigPanel";
18844
18848
  ScorecardChartConfigPanel.components = { SelectionInput };
18845
18849
  ScorecardChartConfigPanel.props = {
18846
- sheetId: String,
18847
18850
  figureId: String,
18848
18851
  definition: Object,
18849
18852
  updateChart: Function,
@@ -18979,7 +18982,7 @@
18979
18982
  else {
18980
18983
  this.shouldUpdateChart = true;
18981
18984
  }
18982
- if (!this.env.model.getters.isChartDefined(this.sheetId, this.figureId)) {
18985
+ if (!this.env.model.getters.isChartDefined(this.figureId)) {
18983
18986
  this.props.onCloseSidePanel();
18984
18987
  return;
18985
18988
  }
@@ -19000,7 +19003,7 @@
19000
19003
  });
19001
19004
  }
19002
19005
  onTypeChange(type) {
19003
- const context = this.env.model.getters.getContextCreationChart(this.sheetId, this.figureId);
19006
+ const context = this.env.model.getters.getContextCreationChart(this.figureId);
19004
19007
  if (!context) {
19005
19008
  throw new Error("Chart not defined.");
19006
19009
  }
@@ -19012,7 +19015,7 @@
19012
19015
  });
19013
19016
  }
19014
19017
  get chartPanel() {
19015
- const type = this.env.model.getters.getChartType(this.sheetId, this.figureId);
19018
+ const type = this.env.model.getters.getChartType(this.figureId);
19016
19019
  if (!type) {
19017
19020
  throw new Error("Chart not defined.");
19018
19021
  }
@@ -19022,8 +19025,8 @@
19022
19025
  }
19023
19026
  return chartPanel;
19024
19027
  }
19025
- getChartDefinition() {
19026
- return this.env.model.getters.getChartDefinition(this.sheetId, this.figureId);
19028
+ getChartDefinition(figureId = this.figureId) {
19029
+ return this.env.model.getters.getChartDefinition(figureId);
19027
19030
  }
19028
19031
  get chartTypes() {
19029
19032
  return getChartTypes();
@@ -25895,13 +25898,7 @@
25895
25898
  data = migrate(data);
25896
25899
  }
25897
25900
  }
25898
- // sanity check: try to fix missing fields/corrupted state by providing
25899
- // sensible default values
25900
- data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
25901
- data.sheets = data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s));
25902
- if (data.sheets.length === 0) {
25903
- data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
25904
- }
25901
+ data = repairData(data);
25905
25902
  return data;
25906
25903
  }
25907
25904
  function migrate(data) {
@@ -26139,6 +26136,48 @@
26139
26136
  },
26140
26137
  },
26141
26138
  ];
26139
+ /**
26140
+ * This function is used to repair faulty data independently of the migration.
26141
+ */
26142
+ function repairData(data) {
26143
+ data = forceUnicityOfFigure(data);
26144
+ data = setDefaults(data);
26145
+ return data;
26146
+ }
26147
+ /**
26148
+ * Force the unicity of figure ids accross sheets
26149
+ */
26150
+ function forceUnicityOfFigure(data) {
26151
+ if (data.uniqueFigureIds) {
26152
+ return data;
26153
+ }
26154
+ const figureIds = new Set();
26155
+ const uuidGenerator = new UuidGenerator();
26156
+ for (const sheet of data.sheets || []) {
26157
+ for (const figure of sheet.figures || []) {
26158
+ if (figureIds.has(figure.id)) {
26159
+ figure.id += uuidGenerator.uuidv4();
26160
+ }
26161
+ figureIds.add(figure.id);
26162
+ }
26163
+ }
26164
+ data.uniqueFigureIds = true;
26165
+ return data;
26166
+ }
26167
+ /**
26168
+ * sanity check: try to fix missing fields/corrupted state by providing
26169
+ * sensible default values
26170
+ */
26171
+ function setDefaults(data) {
26172
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
26173
+ data.sheets = data.sheets
26174
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
26175
+ : [];
26176
+ if (data.sheets.length === 0) {
26177
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
26178
+ }
26179
+ return data;
26180
+ }
26142
26181
  /**
26143
26182
  * The goal of this function is to repair corrupted/wrong initial messages caused by
26144
26183
  * a bug.
@@ -26277,6 +26316,7 @@
26277
26316
  formats: {},
26278
26317
  borders: {},
26279
26318
  revisionId: DEFAULT_REVISION_ID,
26319
+ uniqueFigureIds: true,
26280
26320
  };
26281
26321
  return data;
26282
26322
  }
@@ -28056,10 +28096,8 @@
28056
28096
  this.validateChartDefinition = (cmd) => validateChartDefinition(this, cmd.definition);
28057
28097
  }
28058
28098
  adaptRanges(applyChange) {
28059
- for (const sheetId of Object.keys(this.charts)) {
28060
- for (const [chartId, chart] of Object.entries(this.charts[sheetId] || {})) {
28061
- this.history.update("charts", sheetId, chartId, chart === null || chart === void 0 ? void 0 : chart.updateRanges(applyChange));
28062
- }
28099
+ for (const [chartId, chart] of Object.entries(this.charts)) {
28100
+ this.history.update("charts", chartId, chart === null || chart === void 0 ? void 0 : chart.updateRanges(applyChange));
28063
28101
  }
28064
28102
  }
28065
28103
  // ---------------------------------------------------------------------------
@@ -28070,20 +28108,20 @@
28070
28108
  case "CREATE_CHART":
28071
28109
  return this.checkValidations(cmd, this.chainValidations(this.validateChartDefinition, this.checkChartDuplicate));
28072
28110
  case "UPDATE_CHART":
28073
- return this.validateChartDefinition(cmd);
28111
+ return this.checkValidations(cmd, this.chainValidations(this.validateChartDefinition, this.checkChartExists));
28074
28112
  default:
28075
28113
  return 0 /* CommandResult.Success */;
28076
28114
  }
28077
28115
  }
28078
28116
  handle(cmd) {
28079
- var _a, _b;
28117
+ var _a;
28080
28118
  switch (cmd.type) {
28081
28119
  case "CREATE_CHART":
28082
28120
  this.addFigure(cmd.id, cmd.sheetId, cmd.position, cmd.size);
28083
- this.addChart(cmd.id, cmd.sheetId, cmd.definition);
28121
+ this.addChart(cmd.id, cmd.definition);
28084
28122
  break;
28085
28123
  case "UPDATE_CHART": {
28086
- this.addChart(cmd.id, cmd.sheetId, cmd.definition);
28124
+ this.addChart(cmd.id, cmd.definition);
28087
28125
  break;
28088
28126
  }
28089
28127
  case "DUPLICATE_SHEET": {
@@ -28092,7 +28130,7 @@
28092
28130
  if (fig.tag === "chart") {
28093
28131
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
28094
28132
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
28095
- const chart = (_b = (_a = this.charts[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[fig.id]) === null || _b === void 0 ? void 0 : _b.copyForSheetId(cmd.sheetIdTo);
28133
+ const chart = (_a = this.charts[fig.id]) === null || _a === void 0 ? void 0 : _a.copyForSheetId(cmd.sheetIdTo);
28096
28134
  if (chart) {
28097
28135
  this.dispatch("CREATE_CHART", {
28098
28136
  id: duplicatedFigureId,
@@ -28107,41 +28145,44 @@
28107
28145
  break;
28108
28146
  }
28109
28147
  case "DELETE_FIGURE":
28110
- this.history.update("charts", cmd.sheetId, cmd.id, undefined);
28148
+ this.history.update("charts", cmd.id, undefined);
28111
28149
  break;
28112
28150
  case "DELETE_SHEET":
28113
- this.history.update("charts", cmd.sheetId, undefined);
28151
+ for (let id of this.getChartIds(cmd.sheetId)) {
28152
+ this.history.update("charts", id, undefined);
28153
+ }
28114
28154
  break;
28115
28155
  }
28116
28156
  }
28117
28157
  // ---------------------------------------------------------------------------
28118
28158
  // Getters
28119
28159
  // ---------------------------------------------------------------------------
28120
- getContextCreationChart(sheetId, figureId) {
28121
- var _a, _b;
28122
- return (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.getContextCreation();
28123
- }
28124
- getChart(sheetId, figureId) {
28160
+ getContextCreationChart(figureId) {
28125
28161
  var _a;
28126
- return (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
28162
+ return (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.getContextCreation();
28127
28163
  }
28128
- getChartType(sheetId, figureId) {
28129
- var _a, _b;
28130
- const type = (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.type;
28164
+ getChart(figureId) {
28165
+ return this.charts[figureId];
28166
+ }
28167
+ getChartType(figureId) {
28168
+ var _a;
28169
+ const type = (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.type;
28131
28170
  if (!type) {
28132
28171
  throw new Error("Chart not defined.");
28133
28172
  }
28134
28173
  return type;
28135
28174
  }
28136
- isChartDefined(sheetId, figureId) {
28137
- return figureId in (this.charts[sheetId] || {});
28175
+ isChartDefined(figureId) {
28176
+ return figureId in this.charts && this.charts !== undefined;
28138
28177
  }
28139
28178
  getChartIds(sheetId) {
28140
- return Object.keys(this.charts[sheetId] || {});
28179
+ return Object.entries(this.charts)
28180
+ .filter(([, chart]) => (chart === null || chart === void 0 ? void 0 : chart.sheetId) === sheetId)
28181
+ .map(([id]) => id);
28141
28182
  }
28142
- getChartDefinition(sheetId, figureId) {
28143
- var _a, _b;
28144
- const definition = (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.getDefinition();
28183
+ getChartDefinition(figureId) {
28184
+ var _a;
28185
+ const definition = (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.getDefinition();
28145
28186
  if (!definition) {
28146
28187
  throw new Error(`There is no chart with the given figureId: ${figureId}`);
28147
28188
  }
@@ -28153,28 +28194,35 @@
28153
28194
  import(data) {
28154
28195
  for (let sheet of data.sheets) {
28155
28196
  if (sheet.figures) {
28156
- const charts = {};
28157
28197
  for (let figure of sheet.figures) {
28158
28198
  // TODO:
28159
28199
  // figure data should be external IMO => chart should be in sheet.chart
28160
28200
  // instead of in figure.data
28161
28201
  if (figure.tag === "chart") {
28162
- charts[figure.id] = this.createChart(figure.id, figure.data, sheet.id);
28202
+ this.charts[figure.id] = this.createChart(figure.id, figure.data, sheet.id);
28163
28203
  }
28164
28204
  }
28165
- this.charts[sheet.id] = charts;
28166
28205
  }
28167
28206
  }
28168
28207
  }
28169
28208
  export(data) {
28209
+ var _a;
28170
28210
  if (data.sheets) {
28171
28211
  for (let sheet of data.sheets) {
28172
28212
  // TODO This code is false, if two plugins want ot insert figures on the sheet, it will crash !
28173
28213
  const sheetFigures = this.getters.getFigures(sheet.id);
28174
- const figures = sheetFigures;
28175
- for (let figure of figures) {
28214
+ const figures = [];
28215
+ for (let sheetFigure of sheetFigures) {
28216
+ const figure = sheetFigure;
28176
28217
  if (figure && figure.tag === "chart") {
28177
- figure.data = this.getChartDefinition(sheet.id, figure.id);
28218
+ const data = (_a = this.charts[figure.id]) === null || _a === void 0 ? void 0 : _a.getDefinition();
28219
+ if (data) {
28220
+ figure.data = data;
28221
+ figures.push(figure);
28222
+ }
28223
+ }
28224
+ else {
28225
+ figures.push(figure);
28178
28226
  }
28179
28227
  }
28180
28228
  sheet.figures = figures;
@@ -28182,13 +28230,13 @@
28182
28230
  }
28183
28231
  }
28184
28232
  exportForExcel(data) {
28185
- var _a, _b;
28233
+ var _a;
28186
28234
  for (let sheet of data.sheets) {
28187
28235
  const sheetFigures = this.getters.getFigures(sheet.id);
28188
28236
  const figures = [];
28189
28237
  for (let figure of sheetFigures) {
28190
28238
  if (figure && figure.tag === "chart") {
28191
- const figureData = (_b = (_a = this.charts[sheet.id]) === null || _a === void 0 ? void 0 : _a[figure.id]) === null || _b === void 0 ? void 0 : _b.getDefinitionForExcel();
28239
+ const figureData = (_a = this.charts[figure.id]) === null || _a === void 0 ? void 0 : _a.getDefinitionForExcel();
28192
28240
  if (figureData) {
28193
28241
  figures.push({
28194
28242
  ...figure,
@@ -28227,15 +28275,21 @@
28227
28275
  * Add a chart in the local state. If a chart already exists, this chart is
28228
28276
  * replaced
28229
28277
  */
28230
- addChart(id, sheetId, definition) {
28231
- this.history.update("charts", sheetId, id, this.createChart(id, definition, sheetId));
28278
+ addChart(id, definition) {
28279
+ const sheetId = this.getters.getFigureSheetId(id);
28280
+ if (sheetId) {
28281
+ this.history.update("charts", id, this.createChart(id, definition, sheetId));
28282
+ }
28232
28283
  }
28233
28284
  checkChartDuplicate(cmd) {
28234
- var _a;
28235
- if ((_a = this.charts[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[cmd.id]) {
28236
- return 84 /* CommandResult.DuplicatedChartId */;
28237
- }
28238
- return 0 /* CommandResult.Success */;
28285
+ return this.getters.getFigureSheetId(cmd.id)
28286
+ ? 84 /* CommandResult.DuplicatedChartId */
28287
+ : 0 /* CommandResult.Success */;
28288
+ }
28289
+ checkChartExists(cmd) {
28290
+ return this.getters.getFigureSheetId(cmd.id)
28291
+ ? 0 /* CommandResult.Success */
28292
+ : 85 /* CommandResult.ChartDoesNotExist */;
28239
28293
  }
28240
28294
  }
28241
28295
  ChartPlugin.getters = [
@@ -28616,7 +28670,7 @@
28616
28670
  allowDispatch(cmd) {
28617
28671
  switch (cmd.type) {
28618
28672
  case "CREATE_FIGURE":
28619
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
28673
+ return this.checkFigureDuplicate(cmd.figure.id);
28620
28674
  case "UPDATE_FIGURE":
28621
28675
  case "DELETE_FIGURE":
28622
28676
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -28682,9 +28736,8 @@
28682
28736
  }
28683
28737
  return 0 /* CommandResult.Success */;
28684
28738
  }
28685
- checkFigureDuplicate(sheetId, figureId) {
28686
- var _a;
28687
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
28739
+ checkFigureDuplicate(figureId) {
28740
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
28688
28741
  return 82 /* CommandResult.DuplicatedFigureId */;
28689
28742
  }
28690
28743
  return 0 /* CommandResult.Success */;
@@ -28699,6 +28752,9 @@
28699
28752
  var _a;
28700
28753
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
28701
28754
  }
28755
+ getFigureSheetId(figureId) {
28756
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
28757
+ }
28702
28758
  // ---------------------------------------------------------------------------
28703
28759
  // Import/Export
28704
28760
  // ---------------------------------------------------------------------------
@@ -28723,7 +28779,7 @@
28723
28779
  this.export(data);
28724
28780
  }
28725
28781
  }
28726
- FigurePlugin.getters = ["getFigures", "getFigure"];
28782
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
28727
28783
 
28728
28784
  class FilterTable {
28729
28785
  constructor(zone) {
@@ -29450,7 +29506,7 @@
29450
29506
  switch (cmd.type) {
29451
29507
  case "CREATE_IMAGE":
29452
29508
  if (this.getters.getFigure(cmd.sheetId, cmd.figureId)) {
29453
- return 28 /* CommandResult.DuplicatedImageId */;
29509
+ return 28 /* CommandResult.InvalidFigureId */;
29454
29510
  }
29455
29511
  return 0 /* CommandResult.Success */;
29456
29512
  default:
@@ -29470,7 +29526,7 @@
29470
29526
  if (fig.tag === "image") {
29471
29527
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
29472
29528
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
29473
- const image = this.getImage(cmd.sheetId, fig.id);
29529
+ const image = this.getImage(fig.id);
29474
29530
  if (image) {
29475
29531
  const size = { width: fig.width, height: fig.height };
29476
29532
  this.dispatch("CREATE_IMAGE", {
@@ -29508,13 +29564,19 @@
29508
29564
  // ---------------------------------------------------------------------------
29509
29565
  // Getters
29510
29566
  // ---------------------------------------------------------------------------
29511
- getImage(sheetId, figureId) {
29512
- var _a;
29513
- const image = (_a = this.images[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
29514
- if (!image) {
29515
- throw new Error(`There is no image with the given figureId: ${figureId}`);
29567
+ getImage(figureId) {
29568
+ for (const sheet of Object.values(this.images)) {
29569
+ if (sheet && sheet[figureId]) {
29570
+ return sheet[figureId];
29571
+ }
29516
29572
  }
29517
- return image;
29573
+ throw new Error(`There is no image with the given figureId: ${figureId}`);
29574
+ }
29575
+ getImagePath(figureId) {
29576
+ return this.getImage(figureId).path;
29577
+ }
29578
+ getImageSize(figureId) {
29579
+ return this.getImage(figureId).size;
29518
29580
  }
29519
29581
  // ---------------------------------------------------------------------------
29520
29582
  // Private
@@ -29556,7 +29618,7 @@
29556
29618
  return images;
29557
29619
  }
29558
29620
  }
29559
- ImagePlugin.getters = ["getImage"];
29621
+ ImagePlugin.getters = ["getImage", "getImagePath", "getImageSize"];
29560
29622
 
29561
29623
  class MergePlugin extends CorePlugin {
29562
29624
  constructor() {
@@ -31362,9 +31424,7 @@
31362
31424
  return formatColors.filter(isDefined$1);
31363
31425
  }
31364
31426
  getChartColors(sheetId) {
31365
- const charts = this.getters
31366
- .getChartIds(sheetId)
31367
- .map((cid) => this.getters.getChart(sheetId, cid));
31427
+ const charts = this.getters.getChartIds(sheetId).map((cid) => this.getters.getChart(cid));
31368
31428
  let chartsColors = new Set();
31369
31429
  for (let chart of charts) {
31370
31430
  if (chart === undefined) {
@@ -31730,37 +31790,34 @@
31730
31790
  invalidateCFEvaluationCommands.has(cmd.type) ||
31731
31791
  cmd.type === "EVALUATE_CELLS" ||
31732
31792
  cmd.type === "UPDATE_CELL") {
31733
- for (const sheetId in this.charts) {
31734
- for (const chartId in this.charts[sheetId]) {
31735
- this.charts[sheetId][chartId] = undefined;
31736
- }
31793
+ for (const chartId in this.charts) {
31794
+ this.charts[chartId] = undefined;
31737
31795
  }
31738
31796
  }
31739
31797
  switch (cmd.type) {
31740
31798
  case "UPDATE_CHART":
31741
31799
  case "CREATE_CHART":
31742
31800
  case "DELETE_FIGURE":
31743
- if (this.charts[cmd.sheetId]) {
31744
- this.charts[cmd.sheetId][cmd.id] = undefined;
31745
- }
31801
+ this.charts[cmd.id] = undefined;
31746
31802
  break;
31747
31803
  case "DELETE_SHEET":
31748
- delete this.charts[cmd.sheetId];
31804
+ for (let chartId in this.charts) {
31805
+ if (!this.getters.isChartDefined(chartId)) {
31806
+ this.charts[chartId] = undefined;
31807
+ }
31808
+ }
31749
31809
  break;
31750
31810
  }
31751
31811
  }
31752
- getChartRuntime(sheetId, figureId) {
31753
- var _a;
31754
- if (!((_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId])) {
31755
- const chart = this.getters.getChart(sheetId, figureId);
31812
+ getChartRuntime(figureId) {
31813
+ if (!this.charts[figureId]) {
31814
+ const chart = this.getters.getChart(figureId);
31756
31815
  if (!chart) {
31757
31816
  throw new Error(`No chart for the given id: ${figureId}`);
31758
31817
  }
31759
- if (!this.charts[sheetId])
31760
- this.charts[sheetId] = {};
31761
- this.charts[sheetId][figureId] = this.createRuntimeChart(chart);
31818
+ this.charts[figureId] = this.createRuntimeChart(chart);
31762
31819
  }
31763
- return this.charts[sheetId][figureId];
31820
+ return this.charts[figureId];
31764
31821
  }
31765
31822
  /**
31766
31823
  * Get the background color of a chart based on the color of the first cell of the main range
@@ -35245,8 +35302,8 @@
35245
35302
  const currentMaxId = Math.max(0, ...this.ranges.map((range) => Number(range.id)));
35246
35303
  this.ranges.splice(index, 0, ...values.map((xc, i) => ({
35247
35304
  xc,
35248
- id: (currentMaxId + i + 1).toString(),
35249
- color: colors$1[(currentMaxId + 1 + i) % colors$1.length],
35305
+ id: currentMaxId + i + 1,
35306
+ color: colors$1[(currentMaxId + i) % colors$1.length],
35250
35307
  })));
35251
35308
  }
35252
35309
  /**
@@ -37412,7 +37469,7 @@
37412
37469
  constructor(dispatch, getters, sheetId, copiedFigureId) {
37413
37470
  this.dispatch = dispatch;
37414
37471
  this.sheetId = sheetId;
37415
- const chart = getters.getChart(sheetId, copiedFigureId);
37472
+ const chart = getters.getChart(copiedFigureId);
37416
37473
  if (!chart) {
37417
37474
  throw new Error(`No chart for the given id: ${copiedFigureId}`);
37418
37475
  }
@@ -37433,7 +37490,7 @@
37433
37490
  constructor(dispatch, getters, sheetId, copiedFigureId) {
37434
37491
  this.dispatch = dispatch;
37435
37492
  this.sheetId = sheetId;
37436
- const image = getters.getImage(sheetId, copiedFigureId);
37493
+ const image = getters.getImage(copiedFigureId);
37437
37494
  this.copiedImage = deepCopy(image);
37438
37495
  }
37439
37496
  paste(sheetId, figureId, position, size) {
@@ -44845,9 +44902,9 @@
44845
44902
  Object.defineProperty(exports, '__esModule', { value: true });
44846
44903
 
44847
44904
 
44848
- __info__.version = '16.2.0-alpha.2';
44849
- __info__.date = '2023-03-01T14:43:49.348Z';
44850
- __info__.hash = 'eb626ad';
44905
+ __info__.version = '16.2.0-alpha.3';
44906
+ __info__.date = '2023-03-06T07:18:09.258Z';
44907
+ __info__.hash = 'ec749cf';
44851
44908
 
44852
44909
 
44853
44910
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);