@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.
@@ -277,7 +277,6 @@ var ComponentsImportance;
277
277
  ComponentsImportance[ComponentsImportance["Dropdown"] = 16] = "Dropdown";
278
278
  ComponentsImportance[ComponentsImportance["GridComposer"] = 20] = "GridComposer";
279
279
  ComponentsImportance[ComponentsImportance["TopBarComposer"] = 21] = "TopBarComposer";
280
- ComponentsImportance[ComponentsImportance["ColorPicker"] = 25] = "ColorPicker";
281
280
  ComponentsImportance[ComponentsImportance["IconPicker"] = 25] = "IconPicker";
282
281
  ComponentsImportance[ComponentsImportance["Popover"] = 30] = "Popover";
283
282
  ComponentsImportance[ComponentsImportance["ChartAnchor"] = 1000] = "ChartAnchor";
@@ -2847,7 +2846,7 @@ class ChartJsComponent extends owl.Component {
2847
2846
  return `background-color: ${this.background}`;
2848
2847
  }
2849
2848
  get chartRuntime() {
2850
- const runtime = this.env.model.getters.getChartRuntime(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
2849
+ const runtime = this.env.model.getters.getChartRuntime(this.props.figure.id);
2851
2850
  if (!("chartJsConfig" in runtime)) {
2852
2851
  throw new Error("Unsupported chart runtime");
2853
2852
  }
@@ -3112,7 +3111,7 @@ class ScorecardChart$1 extends owl.Component {
3112
3111
  this.ctx = document.createElement("canvas").getContext("2d");
3113
3112
  }
3114
3113
  get runtime() {
3115
- return this.env.model.getters.getChartRuntime(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
3114
+ return this.env.model.getters.getChartRuntime(this.props.figure.id);
3116
3115
  }
3117
3116
  get title() {
3118
3117
  return this.runtime.title;
@@ -3501,7 +3500,7 @@ exports.CommandResult = void 0;
3501
3500
  CommandResult[CommandResult["InvalidRange"] = 25] = "InvalidRange";
3502
3501
  CommandResult[CommandResult["InvalidZones"] = 26] = "InvalidZones";
3503
3502
  CommandResult[CommandResult["InvalidSheetId"] = 27] = "InvalidSheetId";
3504
- CommandResult[CommandResult["DuplicatedImageId"] = 28] = "DuplicatedImageId";
3503
+ CommandResult[CommandResult["InvalidFigureId"] = 28] = "InvalidFigureId";
3505
3504
  CommandResult[CommandResult["InputAlreadyFocused"] = 29] = "InputAlreadyFocused";
3506
3505
  CommandResult[CommandResult["MaximumRangesReached"] = 30] = "MaximumRangesReached";
3507
3506
  CommandResult[CommandResult["InvalidChartDefinition"] = 31] = "InvalidChartDefinition";
@@ -3558,6 +3557,7 @@ exports.CommandResult = void 0;
3558
3557
  CommandResult[CommandResult["DuplicatedFigureId"] = 82] = "DuplicatedFigureId";
3559
3558
  CommandResult[CommandResult["InvalidSelectionStep"] = 83] = "InvalidSelectionStep";
3560
3559
  CommandResult[CommandResult["DuplicatedChartId"] = 84] = "DuplicatedChartId";
3560
+ CommandResult[CommandResult["ChartDoesNotExist"] = 85] = "ChartDoesNotExist";
3561
3561
  })(exports.CommandResult || (exports.CommandResult = {}));
3562
3562
 
3563
3563
  var DIRECTION;
@@ -6168,7 +6168,7 @@ class ChartFigure extends owl.Component {
6168
6168
  return registry;
6169
6169
  }
6170
6170
  get chartType() {
6171
- return this.env.model.getters.getChartType(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
6171
+ return this.env.model.getters.getChartType(this.props.figure.id);
6172
6172
  }
6173
6173
  onContextMenu(ev) {
6174
6174
  const position = {
@@ -17187,7 +17187,7 @@ class ImageFigure extends owl.Component {
17187
17187
  id: "reset_size",
17188
17188
  name: _lt("Reset size"),
17189
17189
  action: () => {
17190
- const size = this.env.model.getters.getImage(this.env.model.getters.getActiveSheetId(), this.figureId).size;
17190
+ const size = this.env.model.getters.getImageSize(this.figureId);
17191
17191
  const { height, width } = getMaxFigureSize(this.env.model.getters, size);
17192
17192
  this.env.model.dispatch("UPDATE_FIGURE", {
17193
17193
  sheetId: this.env.model.getters.getActiveSheetId(),
@@ -17236,8 +17236,7 @@ class ImageFigure extends owl.Component {
17236
17236
  return this.props.figure.id;
17237
17237
  }
17238
17238
  get getImagePath() {
17239
- return this.env.model.getters.getImage(this.env.model.getters.getActiveSheetId(), this.figureId)
17240
- .path;
17239
+ return this.env.model.getters.getImagePath(this.figureId);
17241
17240
  }
17242
17241
  }
17243
17242
  ImageFigure.template = "o-spreadsheet-ImageFigure";
@@ -18042,9 +18041,9 @@ class SelectionInput extends owl.Component {
18042
18041
  const ranges = existingSelectionRange.length
18043
18042
  ? existingSelectionRange
18044
18043
  : this.props.ranges
18045
- ? this.props.ranges.map((xc, i) => ({
18044
+ ? this.props.ranges.map((xc, id) => ({
18046
18045
  xc,
18047
- id: i.toString(),
18046
+ id,
18048
18047
  isFocused: false,
18049
18048
  }))
18050
18049
  : [];
@@ -18110,6 +18109,7 @@ class SelectionInput extends owl.Component {
18110
18109
  else if (ev.key === "Enter") {
18111
18110
  const target = ev.target;
18112
18111
  target.blur();
18112
+ this.confirm();
18113
18113
  }
18114
18114
  }
18115
18115
  focus(rangeId) {
@@ -18138,7 +18138,7 @@ class SelectionInput extends owl.Component {
18138
18138
  });
18139
18139
  this.triggerChange();
18140
18140
  }
18141
- disable() {
18141
+ confirm() {
18142
18142
  var _a, _b;
18143
18143
  this.env.model.dispatch("UNFOCUS_SELECTION_INPUT");
18144
18144
  const ranges = this.env.model.getters.getSelectionInputValue(this.id);
@@ -18233,7 +18233,6 @@ class LineBarPieConfigPanel extends owl.Component {
18233
18233
  LineBarPieConfigPanel.template = "o-spreadsheet-LineBarPieConfigPanel";
18234
18234
  LineBarPieConfigPanel.components = { SelectionInput };
18235
18235
  LineBarPieConfigPanel.props = {
18236
- sheetId: String,
18237
18236
  figureId: String,
18238
18237
  definition: Object,
18239
18238
  updateChart: Function,
@@ -18266,9 +18265,6 @@ const GRADIENT_WIDTH = PICKER_WIDTH - 2 * LINE_HORIZONTAL_PADDING - 2 * ITEM_BOR
18266
18265
  const GRADIENT_HEIGHT = PICKER_WIDTH - 50;
18267
18266
  css /* scss */ `
18268
18267
  .o-color-picker {
18269
- position: absolute;
18270
- top: calc(100% + 5px);
18271
- z-index: ${ComponentsImportance.ColorPicker};
18272
18268
  padding: ${PICKER_PADDING}px 0px;
18273
18269
  box-shadow: 1px 2px 5px 2px rgba(51, 51, 51, 0.15);
18274
18270
  background-color: white;
@@ -18383,15 +18379,6 @@ css /* scss */ `
18383
18379
  width: 100%;
18384
18380
  }
18385
18381
  }
18386
- &.right {
18387
- left: 0;
18388
- }
18389
- &.left {
18390
- right: 0;
18391
- }
18392
- &.center {
18393
- left: calc(50% - ${PICKER_WIDTH / 2}px);
18394
- }
18395
18382
  }
18396
18383
  .o-magnifier-glass {
18397
18384
  position: absolute;
@@ -18426,14 +18413,18 @@ class ColorPicker extends owl.Component {
18426
18413
  });
18427
18414
  }
18428
18415
  get colorPickerStyle() {
18429
- if (this.props.maxHeight === undefined)
18430
- return "";
18431
- if (this.props.maxHeight <= 0) {
18416
+ if (this.props.maxHeight !== undefined && this.props.maxHeight <= 0) {
18432
18417
  return cssPropertiesToCss({ display: "none" });
18433
18418
  }
18434
- return cssPropertiesToCss({
18435
- "max-height": `${this.props.maxHeight}px`,
18436
- });
18419
+ return "";
18420
+ }
18421
+ get popoverProps() {
18422
+ return {
18423
+ anchorRect: this.props.anchorRect,
18424
+ maxHeight: this.props.maxHeight,
18425
+ positioning: "BottomLeft",
18426
+ verticalOffset: 0,
18427
+ };
18437
18428
  }
18438
18429
  onColorClick(color) {
18439
18430
  if (color) {
@@ -18488,11 +18479,12 @@ ColorPicker.template = "o-spreadsheet-ColorPicker";
18488
18479
  ColorPicker.defaultProps = {
18489
18480
  currentColor: "", //TODO Change it to false instead of empty string
18490
18481
  };
18482
+ ColorPicker.components = { Popover };
18491
18483
  ColorPicker.props = {
18492
- dropdownDirection: { type: String, optional: true },
18493
18484
  onColorPicked: Function,
18494
18485
  currentColor: { type: String, optional: true },
18495
18486
  maxHeight: { type: Number, optional: true },
18487
+ anchorRect: Object,
18496
18488
  };
18497
18489
 
18498
18490
  css /* scss */ `
@@ -18528,11 +18520,25 @@ css /* scss */ `
18528
18520
  }
18529
18521
  `;
18530
18522
  class ColorPickerWidget extends owl.Component {
18523
+ constructor() {
18524
+ super(...arguments);
18525
+ this.colorPickerButtonRef = owl.useRef("colorPickerButton");
18526
+ }
18531
18527
  get iconStyle() {
18532
18528
  return this.props.currentColor
18533
18529
  ? `border-color: ${this.props.currentColor}`
18534
18530
  : "border-bottom-style: hidden";
18535
18531
  }
18532
+ get colorPickerAnchorRect() {
18533
+ const button = this.colorPickerButtonRef.el;
18534
+ const buttonRect = button.getBoundingClientRect();
18535
+ return {
18536
+ x: buttonRect.x,
18537
+ y: buttonRect.y,
18538
+ width: buttonRect.width,
18539
+ height: buttonRect.height,
18540
+ };
18541
+ }
18536
18542
  }
18537
18543
  ColorPickerWidget.template = "o-spreadsheet-ColorPickerWidget";
18538
18544
  ColorPickerWidget.components = { ColorPicker };
@@ -18542,7 +18548,6 @@ ColorPickerWidget.props = {
18542
18548
  showColorPicker: Boolean,
18543
18549
  onColorPicked: Function,
18544
18550
  icon: String,
18545
- dropdownDirection: { type: String, optional: true },
18546
18551
  title: { type: String, optional: true },
18547
18552
  disabled: { type: Boolean, optional: true },
18548
18553
  dropdownMaxHeight: { type: Number, optional: true },
@@ -18622,7 +18627,6 @@ class GaugeChartConfigPanel extends owl.Component {
18622
18627
  GaugeChartConfigPanel.template = "o-spreadsheet-GaugeChartConfigPanel";
18623
18628
  GaugeChartConfigPanel.components = { SelectionInput };
18624
18629
  GaugeChartConfigPanel.props = {
18625
- sheetId: String,
18626
18630
  figureId: String,
18627
18631
  definition: Object,
18628
18632
  updateChart: Function,
@@ -18769,7 +18773,7 @@ GaugeChartDesignPanel.props = {
18769
18773
 
18770
18774
  class LineConfigPanel extends LineBarPieConfigPanel {
18771
18775
  get canTreatLabelsAsText() {
18772
- const chart = this.env.model.getters.getChart(this.props.sheetId, this.props.figureId);
18776
+ const chart = this.env.model.getters.getChart(this.props.figureId);
18773
18777
  if (chart && chart instanceof LineChart) {
18774
18778
  return canChartParseLabels(chart.labelRange, this.env.model.getters);
18775
18779
  }
@@ -18846,7 +18850,6 @@ class ScorecardChartConfigPanel extends owl.Component {
18846
18850
  ScorecardChartConfigPanel.template = "o-spreadsheet-ScorecardChartConfigPanel";
18847
18851
  ScorecardChartConfigPanel.components = { SelectionInput };
18848
18852
  ScorecardChartConfigPanel.props = {
18849
- sheetId: String,
18850
18853
  figureId: String,
18851
18854
  definition: Object,
18852
18855
  updateChart: Function,
@@ -18982,7 +18985,7 @@ class ChartPanel extends owl.Component {
18982
18985
  else {
18983
18986
  this.shouldUpdateChart = true;
18984
18987
  }
18985
- if (!this.env.model.getters.isChartDefined(this.sheetId, this.figureId)) {
18988
+ if (!this.env.model.getters.isChartDefined(this.figureId)) {
18986
18989
  this.props.onCloseSidePanel();
18987
18990
  return;
18988
18991
  }
@@ -19003,7 +19006,7 @@ class ChartPanel extends owl.Component {
19003
19006
  });
19004
19007
  }
19005
19008
  onTypeChange(type) {
19006
- const context = this.env.model.getters.getContextCreationChart(this.sheetId, this.figureId);
19009
+ const context = this.env.model.getters.getContextCreationChart(this.figureId);
19007
19010
  if (!context) {
19008
19011
  throw new Error("Chart not defined.");
19009
19012
  }
@@ -19015,7 +19018,7 @@ class ChartPanel extends owl.Component {
19015
19018
  });
19016
19019
  }
19017
19020
  get chartPanel() {
19018
- const type = this.env.model.getters.getChartType(this.sheetId, this.figureId);
19021
+ const type = this.env.model.getters.getChartType(this.figureId);
19019
19022
  if (!type) {
19020
19023
  throw new Error("Chart not defined.");
19021
19024
  }
@@ -19025,8 +19028,8 @@ class ChartPanel extends owl.Component {
19025
19028
  }
19026
19029
  return chartPanel;
19027
19030
  }
19028
- getChartDefinition() {
19029
- return this.env.model.getters.getChartDefinition(this.sheetId, this.figureId);
19031
+ getChartDefinition(figureId = this.figureId) {
19032
+ return this.env.model.getters.getChartDefinition(figureId);
19030
19033
  }
19031
19034
  get chartTypes() {
19032
19035
  return getChartTypes();
@@ -25898,13 +25901,7 @@ function load(data, verboseImport) {
25898
25901
  data = migrate(data);
25899
25902
  }
25900
25903
  }
25901
- // sanity check: try to fix missing fields/corrupted state by providing
25902
- // sensible default values
25903
- data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
25904
- data.sheets = data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s));
25905
- if (data.sheets.length === 0) {
25906
- data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
25907
- }
25904
+ data = repairData(data);
25908
25905
  return data;
25909
25906
  }
25910
25907
  function migrate(data) {
@@ -26142,6 +26139,48 @@ const MIGRATIONS = [
26142
26139
  },
26143
26140
  },
26144
26141
  ];
26142
+ /**
26143
+ * This function is used to repair faulty data independently of the migration.
26144
+ */
26145
+ function repairData(data) {
26146
+ data = forceUnicityOfFigure(data);
26147
+ data = setDefaults(data);
26148
+ return data;
26149
+ }
26150
+ /**
26151
+ * Force the unicity of figure ids accross sheets
26152
+ */
26153
+ function forceUnicityOfFigure(data) {
26154
+ if (data.uniqueFigureIds) {
26155
+ return data;
26156
+ }
26157
+ const figureIds = new Set();
26158
+ const uuidGenerator = new UuidGenerator();
26159
+ for (const sheet of data.sheets || []) {
26160
+ for (const figure of sheet.figures || []) {
26161
+ if (figureIds.has(figure.id)) {
26162
+ figure.id += uuidGenerator.uuidv4();
26163
+ }
26164
+ figureIds.add(figure.id);
26165
+ }
26166
+ }
26167
+ data.uniqueFigureIds = true;
26168
+ return data;
26169
+ }
26170
+ /**
26171
+ * sanity check: try to fix missing fields/corrupted state by providing
26172
+ * sensible default values
26173
+ */
26174
+ function setDefaults(data) {
26175
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
26176
+ data.sheets = data.sheets
26177
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
26178
+ : [];
26179
+ if (data.sheets.length === 0) {
26180
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
26181
+ }
26182
+ return data;
26183
+ }
26145
26184
  /**
26146
26185
  * The goal of this function is to repair corrupted/wrong initial messages caused by
26147
26186
  * a bug.
@@ -26280,6 +26319,7 @@ function createEmptyWorkbookData(sheetName = "Sheet1") {
26280
26319
  formats: {},
26281
26320
  borders: {},
26282
26321
  revisionId: DEFAULT_REVISION_ID,
26322
+ uniqueFigureIds: true,
26283
26323
  };
26284
26324
  return data;
26285
26325
  }
@@ -28059,10 +28099,8 @@ class ChartPlugin extends CorePlugin {
28059
28099
  this.validateChartDefinition = (cmd) => validateChartDefinition(this, cmd.definition);
28060
28100
  }
28061
28101
  adaptRanges(applyChange) {
28062
- for (const sheetId of Object.keys(this.charts)) {
28063
- for (const [chartId, chart] of Object.entries(this.charts[sheetId] || {})) {
28064
- this.history.update("charts", sheetId, chartId, chart === null || chart === void 0 ? void 0 : chart.updateRanges(applyChange));
28065
- }
28102
+ for (const [chartId, chart] of Object.entries(this.charts)) {
28103
+ this.history.update("charts", chartId, chart === null || chart === void 0 ? void 0 : chart.updateRanges(applyChange));
28066
28104
  }
28067
28105
  }
28068
28106
  // ---------------------------------------------------------------------------
@@ -28073,20 +28111,20 @@ class ChartPlugin extends CorePlugin {
28073
28111
  case "CREATE_CHART":
28074
28112
  return this.checkValidations(cmd, this.chainValidations(this.validateChartDefinition, this.checkChartDuplicate));
28075
28113
  case "UPDATE_CHART":
28076
- return this.validateChartDefinition(cmd);
28114
+ return this.checkValidations(cmd, this.chainValidations(this.validateChartDefinition, this.checkChartExists));
28077
28115
  default:
28078
28116
  return 0 /* CommandResult.Success */;
28079
28117
  }
28080
28118
  }
28081
28119
  handle(cmd) {
28082
- var _a, _b;
28120
+ var _a;
28083
28121
  switch (cmd.type) {
28084
28122
  case "CREATE_CHART":
28085
28123
  this.addFigure(cmd.id, cmd.sheetId, cmd.position, cmd.size);
28086
- this.addChart(cmd.id, cmd.sheetId, cmd.definition);
28124
+ this.addChart(cmd.id, cmd.definition);
28087
28125
  break;
28088
28126
  case "UPDATE_CHART": {
28089
- this.addChart(cmd.id, cmd.sheetId, cmd.definition);
28127
+ this.addChart(cmd.id, cmd.definition);
28090
28128
  break;
28091
28129
  }
28092
28130
  case "DUPLICATE_SHEET": {
@@ -28095,7 +28133,7 @@ class ChartPlugin extends CorePlugin {
28095
28133
  if (fig.tag === "chart") {
28096
28134
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
28097
28135
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
28098
- 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);
28136
+ const chart = (_a = this.charts[fig.id]) === null || _a === void 0 ? void 0 : _a.copyForSheetId(cmd.sheetIdTo);
28099
28137
  if (chart) {
28100
28138
  this.dispatch("CREATE_CHART", {
28101
28139
  id: duplicatedFigureId,
@@ -28110,41 +28148,44 @@ class ChartPlugin extends CorePlugin {
28110
28148
  break;
28111
28149
  }
28112
28150
  case "DELETE_FIGURE":
28113
- this.history.update("charts", cmd.sheetId, cmd.id, undefined);
28151
+ this.history.update("charts", cmd.id, undefined);
28114
28152
  break;
28115
28153
  case "DELETE_SHEET":
28116
- this.history.update("charts", cmd.sheetId, undefined);
28154
+ for (let id of this.getChartIds(cmd.sheetId)) {
28155
+ this.history.update("charts", id, undefined);
28156
+ }
28117
28157
  break;
28118
28158
  }
28119
28159
  }
28120
28160
  // ---------------------------------------------------------------------------
28121
28161
  // Getters
28122
28162
  // ---------------------------------------------------------------------------
28123
- getContextCreationChart(sheetId, figureId) {
28124
- var _a, _b;
28125
- return (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.getContextCreation();
28126
- }
28127
- getChart(sheetId, figureId) {
28163
+ getContextCreationChart(figureId) {
28128
28164
  var _a;
28129
- return (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
28165
+ return (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.getContextCreation();
28130
28166
  }
28131
- getChartType(sheetId, figureId) {
28132
- var _a, _b;
28133
- const type = (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.type;
28167
+ getChart(figureId) {
28168
+ return this.charts[figureId];
28169
+ }
28170
+ getChartType(figureId) {
28171
+ var _a;
28172
+ const type = (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.type;
28134
28173
  if (!type) {
28135
28174
  throw new Error("Chart not defined.");
28136
28175
  }
28137
28176
  return type;
28138
28177
  }
28139
- isChartDefined(sheetId, figureId) {
28140
- return figureId in (this.charts[sheetId] || {});
28178
+ isChartDefined(figureId) {
28179
+ return figureId in this.charts && this.charts !== undefined;
28141
28180
  }
28142
28181
  getChartIds(sheetId) {
28143
- return Object.keys(this.charts[sheetId] || {});
28182
+ return Object.entries(this.charts)
28183
+ .filter(([, chart]) => (chart === null || chart === void 0 ? void 0 : chart.sheetId) === sheetId)
28184
+ .map(([id]) => id);
28144
28185
  }
28145
- getChartDefinition(sheetId, figureId) {
28146
- var _a, _b;
28147
- const definition = (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.getDefinition();
28186
+ getChartDefinition(figureId) {
28187
+ var _a;
28188
+ const definition = (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.getDefinition();
28148
28189
  if (!definition) {
28149
28190
  throw new Error(`There is no chart with the given figureId: ${figureId}`);
28150
28191
  }
@@ -28156,28 +28197,35 @@ class ChartPlugin extends CorePlugin {
28156
28197
  import(data) {
28157
28198
  for (let sheet of data.sheets) {
28158
28199
  if (sheet.figures) {
28159
- const charts = {};
28160
28200
  for (let figure of sheet.figures) {
28161
28201
  // TODO:
28162
28202
  // figure data should be external IMO => chart should be in sheet.chart
28163
28203
  // instead of in figure.data
28164
28204
  if (figure.tag === "chart") {
28165
- charts[figure.id] = this.createChart(figure.id, figure.data, sheet.id);
28205
+ this.charts[figure.id] = this.createChart(figure.id, figure.data, sheet.id);
28166
28206
  }
28167
28207
  }
28168
- this.charts[sheet.id] = charts;
28169
28208
  }
28170
28209
  }
28171
28210
  }
28172
28211
  export(data) {
28212
+ var _a;
28173
28213
  if (data.sheets) {
28174
28214
  for (let sheet of data.sheets) {
28175
28215
  // TODO This code is false, if two plugins want ot insert figures on the sheet, it will crash !
28176
28216
  const sheetFigures = this.getters.getFigures(sheet.id);
28177
- const figures = sheetFigures;
28178
- for (let figure of figures) {
28217
+ const figures = [];
28218
+ for (let sheetFigure of sheetFigures) {
28219
+ const figure = sheetFigure;
28179
28220
  if (figure && figure.tag === "chart") {
28180
- figure.data = this.getChartDefinition(sheet.id, figure.id);
28221
+ const data = (_a = this.charts[figure.id]) === null || _a === void 0 ? void 0 : _a.getDefinition();
28222
+ if (data) {
28223
+ figure.data = data;
28224
+ figures.push(figure);
28225
+ }
28226
+ }
28227
+ else {
28228
+ figures.push(figure);
28181
28229
  }
28182
28230
  }
28183
28231
  sheet.figures = figures;
@@ -28185,13 +28233,13 @@ class ChartPlugin extends CorePlugin {
28185
28233
  }
28186
28234
  }
28187
28235
  exportForExcel(data) {
28188
- var _a, _b;
28236
+ var _a;
28189
28237
  for (let sheet of data.sheets) {
28190
28238
  const sheetFigures = this.getters.getFigures(sheet.id);
28191
28239
  const figures = [];
28192
28240
  for (let figure of sheetFigures) {
28193
28241
  if (figure && figure.tag === "chart") {
28194
- 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();
28242
+ const figureData = (_a = this.charts[figure.id]) === null || _a === void 0 ? void 0 : _a.getDefinitionForExcel();
28195
28243
  if (figureData) {
28196
28244
  figures.push({
28197
28245
  ...figure,
@@ -28230,15 +28278,21 @@ class ChartPlugin extends CorePlugin {
28230
28278
  * Add a chart in the local state. If a chart already exists, this chart is
28231
28279
  * replaced
28232
28280
  */
28233
- addChart(id, sheetId, definition) {
28234
- this.history.update("charts", sheetId, id, this.createChart(id, definition, sheetId));
28281
+ addChart(id, definition) {
28282
+ const sheetId = this.getters.getFigureSheetId(id);
28283
+ if (sheetId) {
28284
+ this.history.update("charts", id, this.createChart(id, definition, sheetId));
28285
+ }
28235
28286
  }
28236
28287
  checkChartDuplicate(cmd) {
28237
- var _a;
28238
- if ((_a = this.charts[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[cmd.id]) {
28239
- return 84 /* CommandResult.DuplicatedChartId */;
28240
- }
28241
- return 0 /* CommandResult.Success */;
28288
+ return this.getters.getFigureSheetId(cmd.id)
28289
+ ? 84 /* CommandResult.DuplicatedChartId */
28290
+ : 0 /* CommandResult.Success */;
28291
+ }
28292
+ checkChartExists(cmd) {
28293
+ return this.getters.getFigureSheetId(cmd.id)
28294
+ ? 0 /* CommandResult.Success */
28295
+ : 85 /* CommandResult.ChartDoesNotExist */;
28242
28296
  }
28243
28297
  }
28244
28298
  ChartPlugin.getters = [
@@ -28619,7 +28673,7 @@ class FigurePlugin extends CorePlugin {
28619
28673
  allowDispatch(cmd) {
28620
28674
  switch (cmd.type) {
28621
28675
  case "CREATE_FIGURE":
28622
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
28676
+ return this.checkFigureDuplicate(cmd.figure.id);
28623
28677
  case "UPDATE_FIGURE":
28624
28678
  case "DELETE_FIGURE":
28625
28679
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -28685,9 +28739,8 @@ class FigurePlugin extends CorePlugin {
28685
28739
  }
28686
28740
  return 0 /* CommandResult.Success */;
28687
28741
  }
28688
- checkFigureDuplicate(sheetId, figureId) {
28689
- var _a;
28690
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
28742
+ checkFigureDuplicate(figureId) {
28743
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
28691
28744
  return 82 /* CommandResult.DuplicatedFigureId */;
28692
28745
  }
28693
28746
  return 0 /* CommandResult.Success */;
@@ -28702,6 +28755,9 @@ class FigurePlugin extends CorePlugin {
28702
28755
  var _a;
28703
28756
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
28704
28757
  }
28758
+ getFigureSheetId(figureId) {
28759
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
28760
+ }
28705
28761
  // ---------------------------------------------------------------------------
28706
28762
  // Import/Export
28707
28763
  // ---------------------------------------------------------------------------
@@ -28726,7 +28782,7 @@ class FigurePlugin extends CorePlugin {
28726
28782
  this.export(data);
28727
28783
  }
28728
28784
  }
28729
- FigurePlugin.getters = ["getFigures", "getFigure"];
28785
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
28730
28786
 
28731
28787
  class FilterTable {
28732
28788
  constructor(zone) {
@@ -29453,7 +29509,7 @@ class ImagePlugin extends CorePlugin {
29453
29509
  switch (cmd.type) {
29454
29510
  case "CREATE_IMAGE":
29455
29511
  if (this.getters.getFigure(cmd.sheetId, cmd.figureId)) {
29456
- return 28 /* CommandResult.DuplicatedImageId */;
29512
+ return 28 /* CommandResult.InvalidFigureId */;
29457
29513
  }
29458
29514
  return 0 /* CommandResult.Success */;
29459
29515
  default:
@@ -29473,7 +29529,7 @@ class ImagePlugin extends CorePlugin {
29473
29529
  if (fig.tag === "image") {
29474
29530
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
29475
29531
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
29476
- const image = this.getImage(cmd.sheetId, fig.id);
29532
+ const image = this.getImage(fig.id);
29477
29533
  if (image) {
29478
29534
  const size = { width: fig.width, height: fig.height };
29479
29535
  this.dispatch("CREATE_IMAGE", {
@@ -29511,13 +29567,19 @@ class ImagePlugin extends CorePlugin {
29511
29567
  // ---------------------------------------------------------------------------
29512
29568
  // Getters
29513
29569
  // ---------------------------------------------------------------------------
29514
- getImage(sheetId, figureId) {
29515
- var _a;
29516
- const image = (_a = this.images[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
29517
- if (!image) {
29518
- throw new Error(`There is no image with the given figureId: ${figureId}`);
29570
+ getImage(figureId) {
29571
+ for (const sheet of Object.values(this.images)) {
29572
+ if (sheet && sheet[figureId]) {
29573
+ return sheet[figureId];
29574
+ }
29519
29575
  }
29520
- return image;
29576
+ throw new Error(`There is no image with the given figureId: ${figureId}`);
29577
+ }
29578
+ getImagePath(figureId) {
29579
+ return this.getImage(figureId).path;
29580
+ }
29581
+ getImageSize(figureId) {
29582
+ return this.getImage(figureId).size;
29521
29583
  }
29522
29584
  // ---------------------------------------------------------------------------
29523
29585
  // Private
@@ -29559,7 +29621,7 @@ class ImagePlugin extends CorePlugin {
29559
29621
  return images;
29560
29622
  }
29561
29623
  }
29562
- ImagePlugin.getters = ["getImage"];
29624
+ ImagePlugin.getters = ["getImage", "getImagePath", "getImageSize"];
29563
29625
 
29564
29626
  class MergePlugin extends CorePlugin {
29565
29627
  constructor() {
@@ -31365,9 +31427,7 @@ class CustomColorsPlugin extends UIPlugin {
31365
31427
  return formatColors.filter(isDefined$1);
31366
31428
  }
31367
31429
  getChartColors(sheetId) {
31368
- const charts = this.getters
31369
- .getChartIds(sheetId)
31370
- .map((cid) => this.getters.getChart(sheetId, cid));
31430
+ const charts = this.getters.getChartIds(sheetId).map((cid) => this.getters.getChart(cid));
31371
31431
  let chartsColors = new Set();
31372
31432
  for (let chart of charts) {
31373
31433
  if (chart === undefined) {
@@ -31733,37 +31793,34 @@ class EvaluationChartPlugin extends UIPlugin {
31733
31793
  invalidateCFEvaluationCommands.has(cmd.type) ||
31734
31794
  cmd.type === "EVALUATE_CELLS" ||
31735
31795
  cmd.type === "UPDATE_CELL") {
31736
- for (const sheetId in this.charts) {
31737
- for (const chartId in this.charts[sheetId]) {
31738
- this.charts[sheetId][chartId] = undefined;
31739
- }
31796
+ for (const chartId in this.charts) {
31797
+ this.charts[chartId] = undefined;
31740
31798
  }
31741
31799
  }
31742
31800
  switch (cmd.type) {
31743
31801
  case "UPDATE_CHART":
31744
31802
  case "CREATE_CHART":
31745
31803
  case "DELETE_FIGURE":
31746
- if (this.charts[cmd.sheetId]) {
31747
- this.charts[cmd.sheetId][cmd.id] = undefined;
31748
- }
31804
+ this.charts[cmd.id] = undefined;
31749
31805
  break;
31750
31806
  case "DELETE_SHEET":
31751
- delete this.charts[cmd.sheetId];
31807
+ for (let chartId in this.charts) {
31808
+ if (!this.getters.isChartDefined(chartId)) {
31809
+ this.charts[chartId] = undefined;
31810
+ }
31811
+ }
31752
31812
  break;
31753
31813
  }
31754
31814
  }
31755
- getChartRuntime(sheetId, figureId) {
31756
- var _a;
31757
- if (!((_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId])) {
31758
- const chart = this.getters.getChart(sheetId, figureId);
31815
+ getChartRuntime(figureId) {
31816
+ if (!this.charts[figureId]) {
31817
+ const chart = this.getters.getChart(figureId);
31759
31818
  if (!chart) {
31760
31819
  throw new Error(`No chart for the given id: ${figureId}`);
31761
31820
  }
31762
- if (!this.charts[sheetId])
31763
- this.charts[sheetId] = {};
31764
- this.charts[sheetId][figureId] = this.createRuntimeChart(chart);
31821
+ this.charts[figureId] = this.createRuntimeChart(chart);
31765
31822
  }
31766
- return this.charts[sheetId][figureId];
31823
+ return this.charts[figureId];
31767
31824
  }
31768
31825
  /**
31769
31826
  * Get the background color of a chart based on the color of the first cell of the main range
@@ -35248,8 +35305,8 @@ class SelectionInputPlugin extends UIPlugin {
35248
35305
  const currentMaxId = Math.max(0, ...this.ranges.map((range) => Number(range.id)));
35249
35306
  this.ranges.splice(index, 0, ...values.map((xc, i) => ({
35250
35307
  xc,
35251
- id: (currentMaxId + i + 1).toString(),
35252
- color: colors$1[(currentMaxId + 1 + i) % colors$1.length],
35308
+ id: currentMaxId + i + 1,
35309
+ color: colors$1[(currentMaxId + i) % colors$1.length],
35253
35310
  })));
35254
35311
  }
35255
35312
  /**
@@ -37415,7 +37472,7 @@ class ClipboardFigureChart {
37415
37472
  constructor(dispatch, getters, sheetId, copiedFigureId) {
37416
37473
  this.dispatch = dispatch;
37417
37474
  this.sheetId = sheetId;
37418
- const chart = getters.getChart(sheetId, copiedFigureId);
37475
+ const chart = getters.getChart(copiedFigureId);
37419
37476
  if (!chart) {
37420
37477
  throw new Error(`No chart for the given id: ${copiedFigureId}`);
37421
37478
  }
@@ -37436,7 +37493,7 @@ class ClipboardFigureImage {
37436
37493
  constructor(dispatch, getters, sheetId, copiedFigureId) {
37437
37494
  this.dispatch = dispatch;
37438
37495
  this.sheetId = sheetId;
37439
- const image = getters.getImage(sheetId, copiedFigureId);
37496
+ const image = getters.getImage(copiedFigureId);
37440
37497
  this.copiedImage = deepCopy(image);
37441
37498
  }
37442
37499
  paste(sheetId, figureId, position, size) {
@@ -44846,6 +44903,6 @@ exports.setTranslationMethod = setTranslationMethod;
44846
44903
  exports.tokenize = tokenize;
44847
44904
 
44848
44905
 
44849
- __info__.version = '16.2.0-alpha.2';
44850
- __info__.date = '2023-03-01T14:43:49.348Z';
44851
- __info__.hash = 'eb626ad';
44906
+ __info__.version = '16.2.0-alpha.3';
44907
+ __info__.date = '2023-03-06T07:18:09.258Z';
44908
+ __info__.hash = 'ec749cf';