@odoo/o-spreadsheet 16.2.0-alpha.1 → 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.
@@ -273,7 +273,6 @@ var ComponentsImportance;
273
273
  ComponentsImportance[ComponentsImportance["Dropdown"] = 16] = "Dropdown";
274
274
  ComponentsImportance[ComponentsImportance["GridComposer"] = 20] = "GridComposer";
275
275
  ComponentsImportance[ComponentsImportance["TopBarComposer"] = 21] = "TopBarComposer";
276
- ComponentsImportance[ComponentsImportance["ColorPicker"] = 25] = "ColorPicker";
277
276
  ComponentsImportance[ComponentsImportance["IconPicker"] = 25] = "IconPicker";
278
277
  ComponentsImportance[ComponentsImportance["Popover"] = 30] = "Popover";
279
278
  ComponentsImportance[ComponentsImportance["ChartAnchor"] = 1000] = "ChartAnchor";
@@ -2843,7 +2842,7 @@ class ChartJsComponent extends Component {
2843
2842
  return `background-color: ${this.background}`;
2844
2843
  }
2845
2844
  get chartRuntime() {
2846
- const runtime = this.env.model.getters.getChartRuntime(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
2845
+ const runtime = this.env.model.getters.getChartRuntime(this.props.figure.id);
2847
2846
  if (!("chartJsConfig" in runtime)) {
2848
2847
  throw new Error("Unsupported chart runtime");
2849
2848
  }
@@ -3108,7 +3107,7 @@ class ScorecardChart$1 extends Component {
3108
3107
  this.ctx = document.createElement("canvas").getContext("2d");
3109
3108
  }
3110
3109
  get runtime() {
3111
- return this.env.model.getters.getChartRuntime(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
3110
+ return this.env.model.getters.getChartRuntime(this.props.figure.id);
3112
3111
  }
3113
3112
  get title() {
3114
3113
  return this.runtime.title;
@@ -3497,7 +3496,7 @@ var CommandResult;
3497
3496
  CommandResult[CommandResult["InvalidRange"] = 25] = "InvalidRange";
3498
3497
  CommandResult[CommandResult["InvalidZones"] = 26] = "InvalidZones";
3499
3498
  CommandResult[CommandResult["InvalidSheetId"] = 27] = "InvalidSheetId";
3500
- CommandResult[CommandResult["DuplicatedImageId"] = 28] = "DuplicatedImageId";
3499
+ CommandResult[CommandResult["InvalidFigureId"] = 28] = "InvalidFigureId";
3501
3500
  CommandResult[CommandResult["InputAlreadyFocused"] = 29] = "InputAlreadyFocused";
3502
3501
  CommandResult[CommandResult["MaximumRangesReached"] = 30] = "MaximumRangesReached";
3503
3502
  CommandResult[CommandResult["InvalidChartDefinition"] = 31] = "InvalidChartDefinition";
@@ -3554,6 +3553,7 @@ var CommandResult;
3554
3553
  CommandResult[CommandResult["DuplicatedFigureId"] = 82] = "DuplicatedFigureId";
3555
3554
  CommandResult[CommandResult["InvalidSelectionStep"] = 83] = "InvalidSelectionStep";
3556
3555
  CommandResult[CommandResult["DuplicatedChartId"] = 84] = "DuplicatedChartId";
3556
+ CommandResult[CommandResult["ChartDoesNotExist"] = 85] = "ChartDoesNotExist";
3557
3557
  })(CommandResult || (CommandResult = {}));
3558
3558
 
3559
3559
  var DIRECTION;
@@ -6164,7 +6164,7 @@ class ChartFigure extends Component {
6164
6164
  return registry;
6165
6165
  }
6166
6166
  get chartType() {
6167
- return this.env.model.getters.getChartType(this.env.model.getters.getActiveSheetId(), this.props.figure.id);
6167
+ return this.env.model.getters.getChartType(this.props.figure.id);
6168
6168
  }
6169
6169
  onContextMenu(ev) {
6170
6170
  const position = {
@@ -17183,7 +17183,7 @@ class ImageFigure extends Component {
17183
17183
  id: "reset_size",
17184
17184
  name: _lt("Reset size"),
17185
17185
  action: () => {
17186
- const size = this.env.model.getters.getImage(this.env.model.getters.getActiveSheetId(), this.figureId).size;
17186
+ const size = this.env.model.getters.getImageSize(this.figureId);
17187
17187
  const { height, width } = getMaxFigureSize(this.env.model.getters, size);
17188
17188
  this.env.model.dispatch("UPDATE_FIGURE", {
17189
17189
  sheetId: this.env.model.getters.getActiveSheetId(),
@@ -17232,8 +17232,7 @@ class ImageFigure extends Component {
17232
17232
  return this.props.figure.id;
17233
17233
  }
17234
17234
  get getImagePath() {
17235
- return this.env.model.getters.getImage(this.env.model.getters.getActiveSheetId(), this.figureId)
17236
- .path;
17235
+ return this.env.model.getters.getImagePath(this.figureId);
17237
17236
  }
17238
17237
  }
17239
17238
  ImageFigure.template = "o-spreadsheet-ImageFigure";
@@ -18038,9 +18037,9 @@ class SelectionInput extends Component {
18038
18037
  const ranges = existingSelectionRange.length
18039
18038
  ? existingSelectionRange
18040
18039
  : this.props.ranges
18041
- ? this.props.ranges.map((xc, i) => ({
18040
+ ? this.props.ranges.map((xc, id) => ({
18042
18041
  xc,
18043
- id: i.toString(),
18042
+ id,
18044
18043
  isFocused: false,
18045
18044
  }))
18046
18045
  : [];
@@ -18106,6 +18105,7 @@ class SelectionInput extends Component {
18106
18105
  else if (ev.key === "Enter") {
18107
18106
  const target = ev.target;
18108
18107
  target.blur();
18108
+ this.confirm();
18109
18109
  }
18110
18110
  }
18111
18111
  focus(rangeId) {
@@ -18134,7 +18134,7 @@ class SelectionInput extends Component {
18134
18134
  });
18135
18135
  this.triggerChange();
18136
18136
  }
18137
- disable() {
18137
+ confirm() {
18138
18138
  var _a, _b;
18139
18139
  this.env.model.dispatch("UNFOCUS_SELECTION_INPUT");
18140
18140
  const ranges = this.env.model.getters.getSelectionInputValue(this.id);
@@ -18229,7 +18229,6 @@ class LineBarPieConfigPanel extends Component {
18229
18229
  LineBarPieConfigPanel.template = "o-spreadsheet-LineBarPieConfigPanel";
18230
18230
  LineBarPieConfigPanel.components = { SelectionInput };
18231
18231
  LineBarPieConfigPanel.props = {
18232
- sheetId: String,
18233
18232
  figureId: String,
18234
18233
  definition: Object,
18235
18234
  updateChart: Function,
@@ -18262,9 +18261,6 @@ const GRADIENT_WIDTH = PICKER_WIDTH - 2 * LINE_HORIZONTAL_PADDING - 2 * ITEM_BOR
18262
18261
  const GRADIENT_HEIGHT = PICKER_WIDTH - 50;
18263
18262
  css /* scss */ `
18264
18263
  .o-color-picker {
18265
- position: absolute;
18266
- top: calc(100% + 5px);
18267
- z-index: ${ComponentsImportance.ColorPicker};
18268
18264
  padding: ${PICKER_PADDING}px 0px;
18269
18265
  box-shadow: 1px 2px 5px 2px rgba(51, 51, 51, 0.15);
18270
18266
  background-color: white;
@@ -18379,15 +18375,6 @@ css /* scss */ `
18379
18375
  width: 100%;
18380
18376
  }
18381
18377
  }
18382
- &.right {
18383
- left: 0;
18384
- }
18385
- &.left {
18386
- right: 0;
18387
- }
18388
- &.center {
18389
- left: calc(50% - ${PICKER_WIDTH / 2}px);
18390
- }
18391
18378
  }
18392
18379
  .o-magnifier-glass {
18393
18380
  position: absolute;
@@ -18422,14 +18409,18 @@ class ColorPicker extends Component {
18422
18409
  });
18423
18410
  }
18424
18411
  get colorPickerStyle() {
18425
- if (this.props.maxHeight === undefined)
18426
- return "";
18427
- if (this.props.maxHeight <= 0) {
18412
+ if (this.props.maxHeight !== undefined && this.props.maxHeight <= 0) {
18428
18413
  return cssPropertiesToCss({ display: "none" });
18429
18414
  }
18430
- return cssPropertiesToCss({
18431
- "max-height": `${this.props.maxHeight}px`,
18432
- });
18415
+ return "";
18416
+ }
18417
+ get popoverProps() {
18418
+ return {
18419
+ anchorRect: this.props.anchorRect,
18420
+ maxHeight: this.props.maxHeight,
18421
+ positioning: "BottomLeft",
18422
+ verticalOffset: 0,
18423
+ };
18433
18424
  }
18434
18425
  onColorClick(color) {
18435
18426
  if (color) {
@@ -18484,11 +18475,12 @@ ColorPicker.template = "o-spreadsheet-ColorPicker";
18484
18475
  ColorPicker.defaultProps = {
18485
18476
  currentColor: "", //TODO Change it to false instead of empty string
18486
18477
  };
18478
+ ColorPicker.components = { Popover };
18487
18479
  ColorPicker.props = {
18488
- dropdownDirection: { type: String, optional: true },
18489
18480
  onColorPicked: Function,
18490
18481
  currentColor: { type: String, optional: true },
18491
18482
  maxHeight: { type: Number, optional: true },
18483
+ anchorRect: Object,
18492
18484
  };
18493
18485
 
18494
18486
  css /* scss */ `
@@ -18524,11 +18516,25 @@ css /* scss */ `
18524
18516
  }
18525
18517
  `;
18526
18518
  class ColorPickerWidget extends Component {
18519
+ constructor() {
18520
+ super(...arguments);
18521
+ this.colorPickerButtonRef = useRef("colorPickerButton");
18522
+ }
18527
18523
  get iconStyle() {
18528
18524
  return this.props.currentColor
18529
18525
  ? `border-color: ${this.props.currentColor}`
18530
18526
  : "border-bottom-style: hidden";
18531
18527
  }
18528
+ get colorPickerAnchorRect() {
18529
+ const button = this.colorPickerButtonRef.el;
18530
+ const buttonRect = button.getBoundingClientRect();
18531
+ return {
18532
+ x: buttonRect.x,
18533
+ y: buttonRect.y,
18534
+ width: buttonRect.width,
18535
+ height: buttonRect.height,
18536
+ };
18537
+ }
18532
18538
  }
18533
18539
  ColorPickerWidget.template = "o-spreadsheet-ColorPickerWidget";
18534
18540
  ColorPickerWidget.components = { ColorPicker };
@@ -18538,7 +18544,6 @@ ColorPickerWidget.props = {
18538
18544
  showColorPicker: Boolean,
18539
18545
  onColorPicked: Function,
18540
18546
  icon: String,
18541
- dropdownDirection: { type: String, optional: true },
18542
18547
  title: { type: String, optional: true },
18543
18548
  disabled: { type: Boolean, optional: true },
18544
18549
  dropdownMaxHeight: { type: Number, optional: true },
@@ -18618,7 +18623,6 @@ class GaugeChartConfigPanel extends Component {
18618
18623
  GaugeChartConfigPanel.template = "o-spreadsheet-GaugeChartConfigPanel";
18619
18624
  GaugeChartConfigPanel.components = { SelectionInput };
18620
18625
  GaugeChartConfigPanel.props = {
18621
- sheetId: String,
18622
18626
  figureId: String,
18623
18627
  definition: Object,
18624
18628
  updateChart: Function,
@@ -18765,7 +18769,7 @@ GaugeChartDesignPanel.props = {
18765
18769
 
18766
18770
  class LineConfigPanel extends LineBarPieConfigPanel {
18767
18771
  get canTreatLabelsAsText() {
18768
- const chart = this.env.model.getters.getChart(this.props.sheetId, this.props.figureId);
18772
+ const chart = this.env.model.getters.getChart(this.props.figureId);
18769
18773
  if (chart && chart instanceof LineChart) {
18770
18774
  return canChartParseLabels(chart.labelRange, this.env.model.getters);
18771
18775
  }
@@ -18842,7 +18846,6 @@ class ScorecardChartConfigPanel extends Component {
18842
18846
  ScorecardChartConfigPanel.template = "o-spreadsheet-ScorecardChartConfigPanel";
18843
18847
  ScorecardChartConfigPanel.components = { SelectionInput };
18844
18848
  ScorecardChartConfigPanel.props = {
18845
- sheetId: String,
18846
18849
  figureId: String,
18847
18850
  definition: Object,
18848
18851
  updateChart: Function,
@@ -18978,7 +18981,7 @@ class ChartPanel extends Component {
18978
18981
  else {
18979
18982
  this.shouldUpdateChart = true;
18980
18983
  }
18981
- if (!this.env.model.getters.isChartDefined(this.sheetId, this.figureId)) {
18984
+ if (!this.env.model.getters.isChartDefined(this.figureId)) {
18982
18985
  this.props.onCloseSidePanel();
18983
18986
  return;
18984
18987
  }
@@ -18992,7 +18995,6 @@ class ChartPanel extends Component {
18992
18995
  ...this.getChartDefinition(),
18993
18996
  ...updateDefinition,
18994
18997
  };
18995
- // TODORAR add a putain de test - c'est faux de nouveau ...
18996
18998
  return this.env.model.dispatch("UPDATE_CHART", {
18997
18999
  definition,
18998
19000
  id: this.figureId,
@@ -19000,12 +19002,11 @@ class ChartPanel extends Component {
19000
19002
  });
19001
19003
  }
19002
19004
  onTypeChange(type) {
19003
- const context = this.env.model.getters.getContextCreationChart(this.sheetId, this.figureId);
19005
+ const context = this.env.model.getters.getContextCreationChart(this.figureId);
19004
19006
  if (!context) {
19005
19007
  throw new Error("Chart not defined.");
19006
19008
  }
19007
19009
  const definition = getChartDefinitionFromContextCreation(context, type);
19008
- // TODORAR add a putain de test - c'est faux de nouveau ...
19009
19010
  this.env.model.dispatch("UPDATE_CHART", {
19010
19011
  definition,
19011
19012
  id: this.figureId,
@@ -19013,7 +19014,7 @@ class ChartPanel extends Component {
19013
19014
  });
19014
19015
  }
19015
19016
  get chartPanel() {
19016
- const type = this.env.model.getters.getChartType(this.sheetId, this.figureId);
19017
+ const type = this.env.model.getters.getChartType(this.figureId);
19017
19018
  if (!type) {
19018
19019
  throw new Error("Chart not defined.");
19019
19020
  }
@@ -19023,8 +19024,8 @@ class ChartPanel extends Component {
19023
19024
  }
19024
19025
  return chartPanel;
19025
19026
  }
19026
- getChartDefinition() {
19027
- return this.env.model.getters.getChartDefinition(this.sheetId, this.figureId);
19027
+ getChartDefinition(figureId = this.figureId) {
19028
+ return this.env.model.getters.getChartDefinition(figureId);
19028
19029
  }
19029
19030
  get chartTypes() {
19030
19031
  return getChartTypes();
@@ -25896,13 +25897,7 @@ function load(data, verboseImport) {
25896
25897
  data = migrate(data);
25897
25898
  }
25898
25899
  }
25899
- // sanity check: try to fix missing fields/corrupted state by providing
25900
- // sensible default values
25901
- data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
25902
- data.sheets = data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s));
25903
- if (data.sheets.length === 0) {
25904
- data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
25905
- }
25900
+ data = repairData(data);
25906
25901
  return data;
25907
25902
  }
25908
25903
  function migrate(data) {
@@ -26140,6 +26135,48 @@ const MIGRATIONS = [
26140
26135
  },
26141
26136
  },
26142
26137
  ];
26138
+ /**
26139
+ * This function is used to repair faulty data independently of the migration.
26140
+ */
26141
+ function repairData(data) {
26142
+ data = forceUnicityOfFigure(data);
26143
+ data = setDefaults(data);
26144
+ return data;
26145
+ }
26146
+ /**
26147
+ * Force the unicity of figure ids accross sheets
26148
+ */
26149
+ function forceUnicityOfFigure(data) {
26150
+ if (data.uniqueFigureIds) {
26151
+ return data;
26152
+ }
26153
+ const figureIds = new Set();
26154
+ const uuidGenerator = new UuidGenerator();
26155
+ for (const sheet of data.sheets || []) {
26156
+ for (const figure of sheet.figures || []) {
26157
+ if (figureIds.has(figure.id)) {
26158
+ figure.id += uuidGenerator.uuidv4();
26159
+ }
26160
+ figureIds.add(figure.id);
26161
+ }
26162
+ }
26163
+ data.uniqueFigureIds = true;
26164
+ return data;
26165
+ }
26166
+ /**
26167
+ * sanity check: try to fix missing fields/corrupted state by providing
26168
+ * sensible default values
26169
+ */
26170
+ function setDefaults(data) {
26171
+ data = Object.assign(createEmptyWorkbookData(), data, { version: CURRENT_VERSION });
26172
+ data.sheets = data.sheets
26173
+ ? data.sheets.map((s, i) => Object.assign(createEmptySheet(`Sheet${i + 1}`, `Sheet${i + 1}`), s))
26174
+ : [];
26175
+ if (data.sheets.length === 0) {
26176
+ data.sheets.push(createEmptySheet(INITIAL_SHEET_ID, "Sheet1"));
26177
+ }
26178
+ return data;
26179
+ }
26143
26180
  /**
26144
26181
  * The goal of this function is to repair corrupted/wrong initial messages caused by
26145
26182
  * a bug.
@@ -26278,6 +26315,7 @@ function createEmptyWorkbookData(sheetName = "Sheet1") {
26278
26315
  formats: {},
26279
26316
  borders: {},
26280
26317
  revisionId: DEFAULT_REVISION_ID,
26318
+ uniqueFigureIds: true,
26281
26319
  };
26282
26320
  return data;
26283
26321
  }
@@ -28057,10 +28095,8 @@ class ChartPlugin extends CorePlugin {
28057
28095
  this.validateChartDefinition = (cmd) => validateChartDefinition(this, cmd.definition);
28058
28096
  }
28059
28097
  adaptRanges(applyChange) {
28060
- for (const sheetId of Object.keys(this.charts)) {
28061
- for (const [chartId, chart] of Object.entries(this.charts[sheetId] || {})) {
28062
- this.history.update("charts", sheetId, chartId, chart === null || chart === void 0 ? void 0 : chart.updateRanges(applyChange));
28063
- }
28098
+ for (const [chartId, chart] of Object.entries(this.charts)) {
28099
+ this.history.update("charts", chartId, chart === null || chart === void 0 ? void 0 : chart.updateRanges(applyChange));
28064
28100
  }
28065
28101
  }
28066
28102
  // ---------------------------------------------------------------------------
@@ -28071,20 +28107,20 @@ class ChartPlugin extends CorePlugin {
28071
28107
  case "CREATE_CHART":
28072
28108
  return this.checkValidations(cmd, this.chainValidations(this.validateChartDefinition, this.checkChartDuplicate));
28073
28109
  case "UPDATE_CHART":
28074
- return this.validateChartDefinition(cmd);
28110
+ return this.checkValidations(cmd, this.chainValidations(this.validateChartDefinition, this.checkChartExists));
28075
28111
  default:
28076
28112
  return 0 /* CommandResult.Success */;
28077
28113
  }
28078
28114
  }
28079
28115
  handle(cmd) {
28080
- var _a, _b;
28116
+ var _a;
28081
28117
  switch (cmd.type) {
28082
28118
  case "CREATE_CHART":
28083
28119
  this.addFigure(cmd.id, cmd.sheetId, cmd.position, cmd.size);
28084
- this.addChart(cmd.id, cmd.sheetId, cmd.definition);
28120
+ this.addChart(cmd.id, cmd.definition);
28085
28121
  break;
28086
28122
  case "UPDATE_CHART": {
28087
- this.addChart(cmd.id, cmd.sheetId, cmd.definition);
28123
+ this.addChart(cmd.id, cmd.definition);
28088
28124
  break;
28089
28125
  }
28090
28126
  case "DUPLICATE_SHEET": {
@@ -28093,7 +28129,7 @@ class ChartPlugin extends CorePlugin {
28093
28129
  if (fig.tag === "chart") {
28094
28130
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
28095
28131
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
28096
- 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);
28132
+ const chart = (_a = this.charts[fig.id]) === null || _a === void 0 ? void 0 : _a.copyForSheetId(cmd.sheetIdTo);
28097
28133
  if (chart) {
28098
28134
  this.dispatch("CREATE_CHART", {
28099
28135
  id: duplicatedFigureId,
@@ -28108,44 +28144,44 @@ class ChartPlugin extends CorePlugin {
28108
28144
  break;
28109
28145
  }
28110
28146
  case "DELETE_FIGURE":
28111
- this.history.update("charts", cmd.sheetId, cmd.id, undefined);
28147
+ this.history.update("charts", cmd.id, undefined);
28112
28148
  break;
28113
28149
  case "DELETE_SHEET":
28114
- this.history.update("charts", cmd.sheetId, undefined);
28150
+ for (let id of this.getChartIds(cmd.sheetId)) {
28151
+ this.history.update("charts", id, undefined);
28152
+ }
28115
28153
  break;
28116
28154
  }
28117
28155
  }
28118
28156
  // ---------------------------------------------------------------------------
28119
28157
  // Getters
28120
28158
  // ---------------------------------------------------------------------------
28121
- getContextCreationChart(sheetId, figureId) {
28122
- var _a, _b;
28123
- return (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.getContextCreation();
28124
- }
28125
- getChart(sheetId, figureId) {
28159
+ getContextCreationChart(figureId) {
28126
28160
  var _a;
28127
- return (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
28161
+ return (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.getContextCreation();
28128
28162
  }
28129
- getChartType(sheetId, figureId) {
28130
- var _a, _b;
28131
- const type = (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.type;
28163
+ getChart(figureId) {
28164
+ return this.charts[figureId];
28165
+ }
28166
+ getChartType(figureId) {
28167
+ var _a;
28168
+ const type = (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.type;
28132
28169
  if (!type) {
28133
28170
  throw new Error("Chart not defined.");
28134
28171
  }
28135
28172
  return type;
28136
28173
  }
28137
- isChartDefined(sheetId, figureId) {
28138
- return figureId in (this.charts[sheetId] || {});
28174
+ isChartDefined(figureId) {
28175
+ return figureId in this.charts && this.charts !== undefined;
28139
28176
  }
28140
28177
  getChartIds(sheetId) {
28141
- // TODORAR refaire ce shit truc
28142
- // on veut un truc du genre Object.keys(this.charts[sheetId] || {} a mon avis
28143
- // return (Object.values(this.charts[sheetId] || {}).filter(isDefined) as AbstractChart[]).map((chart) => chart.id);
28144
- return Object.keys(this.charts[sheetId] || {});
28178
+ return Object.entries(this.charts)
28179
+ .filter(([, chart]) => (chart === null || chart === void 0 ? void 0 : chart.sheetId) === sheetId)
28180
+ .map(([id]) => id);
28145
28181
  }
28146
- getChartDefinition(sheetId, figureId) {
28147
- var _a, _b;
28148
- const definition = (_b = (_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) === null || _b === void 0 ? void 0 : _b.getDefinition();
28182
+ getChartDefinition(figureId) {
28183
+ var _a;
28184
+ const definition = (_a = this.charts[figureId]) === null || _a === void 0 ? void 0 : _a.getDefinition();
28149
28185
  if (!definition) {
28150
28186
  throw new Error(`There is no chart with the given figureId: ${figureId}`);
28151
28187
  }
@@ -28157,28 +28193,35 @@ class ChartPlugin extends CorePlugin {
28157
28193
  import(data) {
28158
28194
  for (let sheet of data.sheets) {
28159
28195
  if (sheet.figures) {
28160
- const charts = {};
28161
28196
  for (let figure of sheet.figures) {
28162
28197
  // TODO:
28163
28198
  // figure data should be external IMO => chart should be in sheet.chart
28164
28199
  // instead of in figure.data
28165
28200
  if (figure.tag === "chart") {
28166
- charts[figure.id] = this.createChart(figure.id, figure.data, sheet.id);
28201
+ this.charts[figure.id] = this.createChart(figure.id, figure.data, sheet.id);
28167
28202
  }
28168
28203
  }
28169
- this.charts[sheet.id] = charts;
28170
28204
  }
28171
28205
  }
28172
28206
  }
28173
28207
  export(data) {
28208
+ var _a;
28174
28209
  if (data.sheets) {
28175
28210
  for (let sheet of data.sheets) {
28176
28211
  // TODO This code is false, if two plugins want ot insert figures on the sheet, it will crash !
28177
28212
  const sheetFigures = this.getters.getFigures(sheet.id);
28178
- const figures = sheetFigures;
28179
- for (let figure of figures) {
28213
+ const figures = [];
28214
+ for (let sheetFigure of sheetFigures) {
28215
+ const figure = sheetFigure;
28180
28216
  if (figure && figure.tag === "chart") {
28181
- figure.data = this.getChartDefinition(sheet.id, figure.id);
28217
+ const data = (_a = this.charts[figure.id]) === null || _a === void 0 ? void 0 : _a.getDefinition();
28218
+ if (data) {
28219
+ figure.data = data;
28220
+ figures.push(figure);
28221
+ }
28222
+ }
28223
+ else {
28224
+ figures.push(figure);
28182
28225
  }
28183
28226
  }
28184
28227
  sheet.figures = figures;
@@ -28186,13 +28229,13 @@ class ChartPlugin extends CorePlugin {
28186
28229
  }
28187
28230
  }
28188
28231
  exportForExcel(data) {
28189
- var _a, _b;
28232
+ var _a;
28190
28233
  for (let sheet of data.sheets) {
28191
28234
  const sheetFigures = this.getters.getFigures(sheet.id);
28192
28235
  const figures = [];
28193
28236
  for (let figure of sheetFigures) {
28194
28237
  if (figure && figure.tag === "chart") {
28195
- 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();
28238
+ const figureData = (_a = this.charts[figure.id]) === null || _a === void 0 ? void 0 : _a.getDefinitionForExcel();
28196
28239
  if (figureData) {
28197
28240
  figures.push({
28198
28241
  ...figure,
@@ -28231,15 +28274,21 @@ class ChartPlugin extends CorePlugin {
28231
28274
  * Add a chart in the local state. If a chart already exists, this chart is
28232
28275
  * replaced
28233
28276
  */
28234
- addChart(id, sheetId, definition) {
28235
- this.history.update("charts", sheetId, id, this.createChart(id, definition, sheetId));
28277
+ addChart(id, definition) {
28278
+ const sheetId = this.getters.getFigureSheetId(id);
28279
+ if (sheetId) {
28280
+ this.history.update("charts", id, this.createChart(id, definition, sheetId));
28281
+ }
28236
28282
  }
28237
28283
  checkChartDuplicate(cmd) {
28238
- var _a;
28239
- if ((_a = this.charts[cmd.sheetId]) === null || _a === void 0 ? void 0 : _a[cmd.id]) {
28240
- return 84 /* CommandResult.DuplicatedChartId */;
28241
- }
28242
- return 0 /* CommandResult.Success */;
28284
+ return this.getters.getFigureSheetId(cmd.id)
28285
+ ? 84 /* CommandResult.DuplicatedChartId */
28286
+ : 0 /* CommandResult.Success */;
28287
+ }
28288
+ checkChartExists(cmd) {
28289
+ return this.getters.getFigureSheetId(cmd.id)
28290
+ ? 0 /* CommandResult.Success */
28291
+ : 85 /* CommandResult.ChartDoesNotExist */;
28243
28292
  }
28244
28293
  }
28245
28294
  ChartPlugin.getters = [
@@ -28620,7 +28669,7 @@ class FigurePlugin extends CorePlugin {
28620
28669
  allowDispatch(cmd) {
28621
28670
  switch (cmd.type) {
28622
28671
  case "CREATE_FIGURE":
28623
- return this.checkFigureDuplicate(cmd.sheetId, cmd.figure.id);
28672
+ return this.checkFigureDuplicate(cmd.figure.id);
28624
28673
  case "UPDATE_FIGURE":
28625
28674
  case "DELETE_FIGURE":
28626
28675
  return this.checkFigureExists(cmd.sheetId, cmd.id);
@@ -28686,9 +28735,8 @@ class FigurePlugin extends CorePlugin {
28686
28735
  }
28687
28736
  return 0 /* CommandResult.Success */;
28688
28737
  }
28689
- checkFigureDuplicate(sheetId, figureId) {
28690
- var _a;
28691
- if ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) {
28738
+ checkFigureDuplicate(figureId) {
28739
+ if (Object.values(this.figures).find((sheet) => sheet === null || sheet === void 0 ? void 0 : sheet[figureId])) {
28692
28740
  return 82 /* CommandResult.DuplicatedFigureId */;
28693
28741
  }
28694
28742
  return 0 /* CommandResult.Success */;
@@ -28703,6 +28751,9 @@ class FigurePlugin extends CorePlugin {
28703
28751
  var _a;
28704
28752
  return (_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
28705
28753
  }
28754
+ getFigureSheetId(figureId) {
28755
+ return Object.keys(this.figures).find((sheetId) => { var _a; return ((_a = this.figures[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId]) !== undefined; });
28756
+ }
28706
28757
  // ---------------------------------------------------------------------------
28707
28758
  // Import/Export
28708
28759
  // ---------------------------------------------------------------------------
@@ -28727,7 +28778,7 @@ class FigurePlugin extends CorePlugin {
28727
28778
  this.export(data);
28728
28779
  }
28729
28780
  }
28730
- FigurePlugin.getters = ["getFigures", "getFigure"];
28781
+ FigurePlugin.getters = ["getFigures", "getFigure", "getFigureSheetId"];
28731
28782
 
28732
28783
  class FilterTable {
28733
28784
  constructor(zone) {
@@ -29454,7 +29505,7 @@ class ImagePlugin extends CorePlugin {
29454
29505
  switch (cmd.type) {
29455
29506
  case "CREATE_IMAGE":
29456
29507
  if (this.getters.getFigure(cmd.sheetId, cmd.figureId)) {
29457
- return 28 /* CommandResult.DuplicatedImageId */;
29508
+ return 28 /* CommandResult.InvalidFigureId */;
29458
29509
  }
29459
29510
  return 0 /* CommandResult.Success */;
29460
29511
  default:
@@ -29474,7 +29525,7 @@ class ImagePlugin extends CorePlugin {
29474
29525
  if (fig.tag === "image") {
29475
29526
  const figureIdBase = fig.id.split(FIGURE_ID_SPLITTER).pop();
29476
29527
  const duplicatedFigureId = `${cmd.sheetIdTo}${FIGURE_ID_SPLITTER}${figureIdBase}`;
29477
- const image = this.getImage(cmd.sheetId, fig.id);
29528
+ const image = this.getImage(fig.id);
29478
29529
  if (image) {
29479
29530
  const size = { width: fig.width, height: fig.height };
29480
29531
  this.dispatch("CREATE_IMAGE", {
@@ -29512,13 +29563,19 @@ class ImagePlugin extends CorePlugin {
29512
29563
  // ---------------------------------------------------------------------------
29513
29564
  // Getters
29514
29565
  // ---------------------------------------------------------------------------
29515
- getImage(sheetId, figureId) {
29516
- var _a;
29517
- const image = (_a = this.images[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId];
29518
- if (!image) {
29519
- throw new Error(`There is no image with the given figureId: ${figureId}`);
29566
+ getImage(figureId) {
29567
+ for (const sheet of Object.values(this.images)) {
29568
+ if (sheet && sheet[figureId]) {
29569
+ return sheet[figureId];
29570
+ }
29520
29571
  }
29521
- return image;
29572
+ throw new Error(`There is no image with the given figureId: ${figureId}`);
29573
+ }
29574
+ getImagePath(figureId) {
29575
+ return this.getImage(figureId).path;
29576
+ }
29577
+ getImageSize(figureId) {
29578
+ return this.getImage(figureId).size;
29522
29579
  }
29523
29580
  // ---------------------------------------------------------------------------
29524
29581
  // Private
@@ -29560,7 +29617,7 @@ class ImagePlugin extends CorePlugin {
29560
29617
  return images;
29561
29618
  }
29562
29619
  }
29563
- ImagePlugin.getters = ["getImage"];
29620
+ ImagePlugin.getters = ["getImage", "getImagePath", "getImageSize"];
29564
29621
 
29565
29622
  class MergePlugin extends CorePlugin {
29566
29623
  constructor() {
@@ -31366,9 +31423,7 @@ class CustomColorsPlugin extends UIPlugin {
31366
31423
  return formatColors.filter(isDefined$1);
31367
31424
  }
31368
31425
  getChartColors(sheetId) {
31369
- const charts = this.getters
31370
- .getChartIds(sheetId)
31371
- .map((cid) => this.getters.getChart(sheetId, cid));
31426
+ const charts = this.getters.getChartIds(sheetId).map((cid) => this.getters.getChart(cid));
31372
31427
  let chartsColors = new Set();
31373
31428
  for (let chart of charts) {
31374
31429
  if (chart === undefined) {
@@ -31734,37 +31789,34 @@ class EvaluationChartPlugin extends UIPlugin {
31734
31789
  invalidateCFEvaluationCommands.has(cmd.type) ||
31735
31790
  cmd.type === "EVALUATE_CELLS" ||
31736
31791
  cmd.type === "UPDATE_CELL") {
31737
- for (const sheetId in this.charts) {
31738
- for (const chartId in this.charts[sheetId]) {
31739
- this.charts[sheetId][chartId] = undefined;
31740
- }
31792
+ for (const chartId in this.charts) {
31793
+ this.charts[chartId] = undefined;
31741
31794
  }
31742
31795
  }
31743
31796
  switch (cmd.type) {
31744
31797
  case "UPDATE_CHART":
31745
31798
  case "CREATE_CHART":
31746
31799
  case "DELETE_FIGURE":
31747
- if (this.charts[cmd.sheetId]) {
31748
- this.charts[cmd.sheetId][cmd.id] = undefined;
31749
- }
31800
+ this.charts[cmd.id] = undefined;
31750
31801
  break;
31751
31802
  case "DELETE_SHEET":
31752
- delete this.charts[cmd.sheetId];
31803
+ for (let chartId in this.charts) {
31804
+ if (!this.getters.isChartDefined(chartId)) {
31805
+ this.charts[chartId] = undefined;
31806
+ }
31807
+ }
31753
31808
  break;
31754
31809
  }
31755
31810
  }
31756
- getChartRuntime(sheetId, figureId) {
31757
- var _a;
31758
- if (!((_a = this.charts[sheetId]) === null || _a === void 0 ? void 0 : _a[figureId])) {
31759
- const chart = this.getters.getChart(sheetId, figureId);
31811
+ getChartRuntime(figureId) {
31812
+ if (!this.charts[figureId]) {
31813
+ const chart = this.getters.getChart(figureId);
31760
31814
  if (!chart) {
31761
31815
  throw new Error(`No chart for the given id: ${figureId}`);
31762
31816
  }
31763
- if (!this.charts[sheetId])
31764
- this.charts[sheetId] = {};
31765
- this.charts[sheetId][figureId] = this.createRuntimeChart(chart);
31817
+ this.charts[figureId] = this.createRuntimeChart(chart);
31766
31818
  }
31767
- return this.charts[sheetId][figureId];
31819
+ return this.charts[figureId];
31768
31820
  }
31769
31821
  /**
31770
31822
  * Get the background color of a chart based on the color of the first cell of the main range
@@ -35249,8 +35301,8 @@ class SelectionInputPlugin extends UIPlugin {
35249
35301
  const currentMaxId = Math.max(0, ...this.ranges.map((range) => Number(range.id)));
35250
35302
  this.ranges.splice(index, 0, ...values.map((xc, i) => ({
35251
35303
  xc,
35252
- id: (currentMaxId + i + 1).toString(),
35253
- color: colors$1[(currentMaxId + 1 + i) % colors$1.length],
35304
+ id: currentMaxId + i + 1,
35305
+ color: colors$1[(currentMaxId + i) % colors$1.length],
35254
35306
  })));
35255
35307
  }
35256
35308
  /**
@@ -37416,7 +37468,7 @@ class ClipboardFigureChart {
37416
37468
  constructor(dispatch, getters, sheetId, copiedFigureId) {
37417
37469
  this.dispatch = dispatch;
37418
37470
  this.sheetId = sheetId;
37419
- const chart = getters.getChart(sheetId, copiedFigureId);
37471
+ const chart = getters.getChart(copiedFigureId);
37420
37472
  if (!chart) {
37421
37473
  throw new Error(`No chart for the given id: ${copiedFigureId}`);
37422
37474
  }
@@ -37437,7 +37489,7 @@ class ClipboardFigureImage {
37437
37489
  constructor(dispatch, getters, sheetId, copiedFigureId) {
37438
37490
  this.dispatch = dispatch;
37439
37491
  this.sheetId = sheetId;
37440
- const image = getters.getImage(sheetId, copiedFigureId);
37492
+ const image = getters.getImage(copiedFigureId);
37441
37493
  this.copiedImage = deepCopy(image);
37442
37494
  }
37443
37495
  paste(sheetId, figureId, position, size) {
@@ -44819,6 +44871,6 @@ function addFunction(functionName, functionDescription) {
44819
44871
  export { AbstractChart, CommandResult, CorePlugin, DATETIME_FORMAT, DispatchResult, EvaluationError, Model, Registry, Revision, SPREADSHEET_DIMENSIONS, Spreadsheet, UIPlugin, __info__, addFunction, astToFormula, compile, components, convertAstNodes, coreTypes, findCellInNewZone, functionCache, helpers, invalidateEvaluationCommands, links, load, parse, readonlyAllowedCommands, registries, setTranslationMethod, tokenize };
44820
44872
 
44821
44873
 
44822
- __info__.version = '16.2.0-alpha.1';
44823
- __info__.date = '2023-03-01T07:42:43.501Z';
44824
- __info__.hash = '162451a';
44874
+ __info__.version = '16.2.0-alpha.3';
44875
+ __info__.date = '2023-03-06T07:18:09.258Z';
44876
+ __info__.hash = 'ec749cf';