@odoo/o-spreadsheet 16.0.41 → 16.0.43

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.
@@ -2298,8 +2298,11 @@
2298
2298
  /**
2299
2299
  * Create a range from a xc. If the xc is empty, this function returns undefined.
2300
2300
  */
2301
- function createRange(getters, sheetId, range) {
2302
- return range ? getters.getRangeFromSheetXC(sheetId, range) : undefined;
2301
+ function createValidRange(getters, sheetId, xc) {
2302
+ if (!xc)
2303
+ return;
2304
+ const range = getters.getRangeFromSheetXC(sheetId, xc);
2305
+ return !(range.invalidSheetName || range.invalidXc) ? range : undefined;
2303
2306
  }
2304
2307
 
2305
2308
  /** Methods from Odoo Web Utils */
@@ -4020,6 +4023,7 @@
4020
4023
  }
4021
4024
 
4022
4025
  const macRegex = /Mac/i;
4026
+ const MODIFIER_KEYS = ["Shift", "Control", "Alt", "Meta"];
4023
4027
  /**
4024
4028
  * Return true if the event was triggered from
4025
4029
  * a child element.
@@ -4038,6 +4042,31 @@
4038
4042
  function getOpenedMenus() {
4039
4043
  return Array.from(document.querySelectorAll(".o-spreadsheet .o-menu"));
4040
4044
  }
4045
+ const letterRegex = /^[a-zA-Z]$/;
4046
+ /**
4047
+ * Transform a keyboard event into a shortcut string that represent this event. The letters keys will be uppercased.
4048
+ *
4049
+ * @argument ev - The keyboard event to transform
4050
+ * @argument mode - Use either ev.key of ev.code to get the string shortcut
4051
+ *
4052
+ * @example
4053
+ * event : { ctrlKey: true, key: "a" } => "Ctrl+A"
4054
+ * event : { shift: true, alt: true, key: "Home" } => "Alt+Shift+Home"
4055
+ */
4056
+ function keyboardEventToShortcutString(ev, mode = "key") {
4057
+ let keyDownString = "";
4058
+ if (!MODIFIER_KEYS.includes(ev.key)) {
4059
+ if (isCtrlKey(ev))
4060
+ keyDownString += "Ctrl+";
4061
+ if (ev.altKey)
4062
+ keyDownString += "Alt+";
4063
+ if (ev.shiftKey)
4064
+ keyDownString += "Shift+";
4065
+ }
4066
+ const key = mode === "key" ? ev.key : ev.code;
4067
+ keyDownString += letterRegex.test(key) ? key.toUpperCase() : key;
4068
+ return keyDownString;
4069
+ }
4041
4070
  function isMacOS() {
4042
4071
  return Boolean(macRegex.test(navigator.userAgent));
4043
4072
  }
@@ -6972,8 +7001,8 @@
6972
7001
  const dataSets = [];
6973
7002
  for (const sheetXC of dataSetsString) {
6974
7003
  const dataRange = getters.getRangeFromSheetXC(sheetId, sheetXC);
6975
- const { unboundedZone: zone, sheetId: dataSetSheetId, invalidSheetName } = dataRange;
6976
- if (invalidSheetName) {
7004
+ const { unboundedZone: zone, sheetId: dataSetSheetId, invalidSheetName, invalidXc } = dataRange;
7005
+ if (invalidSheetName || invalidXc) {
6977
7006
  continue;
6978
7007
  }
6979
7008
  // It's a rectangle. We treat all columns (arbitrary) as different data series.
@@ -7366,7 +7395,7 @@
7366
7395
  super(definition, sheetId, getters);
7367
7396
  this.type = "bar";
7368
7397
  this.dataSets = createDataSets(getters, definition.dataSets, sheetId, definition.dataSetsHaveTitle);
7369
- this.labelRange = createRange(getters, sheetId, definition.labelRange);
7398
+ this.labelRange = createValidRange(getters, sheetId, definition.labelRange);
7370
7399
  this.background = definition.background;
7371
7400
  this.verticalAxisPosition = definition.verticalAxisPosition;
7372
7401
  this.legendPosition = definition.legendPosition;
@@ -7662,7 +7691,7 @@
7662
7691
  constructor(definition, sheetId, getters) {
7663
7692
  super(definition, sheetId, getters);
7664
7693
  this.type = "gauge";
7665
- this.dataRange = createRange(this.getters, this.sheetId, definition.dataRange);
7694
+ this.dataRange = createValidRange(this.getters, this.sheetId, definition.dataRange);
7666
7695
  this.sectionRule = definition.sectionRule;
7667
7696
  this.background = definition.background;
7668
7697
  }
@@ -7993,7 +8022,7 @@
7993
8022
  super(definition, sheetId, getters);
7994
8023
  this.type = "line";
7995
8024
  this.dataSets = createDataSets(this.getters, definition.dataSets, sheetId, definition.dataSetsHaveTitle);
7996
- this.labelRange = createRange(this.getters, sheetId, definition.labelRange);
8025
+ this.labelRange = createValidRange(this.getters, sheetId, definition.labelRange);
7997
8026
  this.background = definition.background;
7998
8027
  this.verticalAxisPosition = definition.verticalAxisPosition;
7999
8028
  this.legendPosition = definition.legendPosition;
@@ -8267,7 +8296,7 @@
8267
8296
  super(definition, sheetId, getters);
8268
8297
  this.type = "pie";
8269
8298
  this.dataSets = createDataSets(getters, definition.dataSets, sheetId, definition.dataSetsHaveTitle);
8270
- this.labelRange = createRange(getters, sheetId, definition.labelRange);
8299
+ this.labelRange = createValidRange(getters, sheetId, definition.labelRange);
8271
8300
  this.background = definition.background;
8272
8301
  this.legendPosition = definition.legendPosition;
8273
8302
  }
@@ -8425,8 +8454,8 @@
8425
8454
  constructor(definition, sheetId, getters) {
8426
8455
  super(definition, sheetId, getters);
8427
8456
  this.type = "scorecard";
8428
- this.keyValue = createRange(getters, sheetId, definition.keyValue);
8429
- this.baseline = createRange(getters, sheetId, definition.baseline);
8457
+ this.keyValue = createValidRange(getters, sheetId, definition.keyValue);
8458
+ this.baseline = createValidRange(getters, sheetId, definition.baseline);
8430
8459
  this.baselineMode = definition.baselineMode;
8431
8460
  this.baselineDescr = definition.baselineDescr;
8432
8461
  this.background = definition.background;
@@ -21199,7 +21228,8 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
21199
21228
  }
21200
21229
  onKeyDown(ev) {
21201
21230
  const figure = this.props.figure;
21202
- switch (ev.key) {
21231
+ const keyDownShortcut = keyboardEventToShortcutString(ev);
21232
+ switch (keyDownShortcut) {
21203
21233
  case "Delete":
21204
21234
  this.env.model.dispatch("DELETE_FIGURE", {
21205
21235
  sheetId: this.env.model.getters.getActiveSheetId(),
@@ -21229,6 +21259,22 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
21229
21259
  ev.preventDefault();
21230
21260
  ev.stopPropagation();
21231
21261
  break;
21262
+ case "Ctrl+A":
21263
+ // Maybe in the future we will implement a way to select all figures
21264
+ ev.preventDefault();
21265
+ ev.stopPropagation();
21266
+ break;
21267
+ case "Ctrl+Y":
21268
+ case "Ctrl+Z":
21269
+ if (keyDownShortcut === "Ctrl+Y") {
21270
+ this.env.model.dispatch("REQUEST_REDO");
21271
+ }
21272
+ else if (keyDownShortcut === "Ctrl+Z") {
21273
+ this.env.model.dispatch("REQUEST_UNDO");
21274
+ }
21275
+ ev.preventDefault();
21276
+ ev.stopPropagation();
21277
+ break;
21232
21278
  }
21233
21279
  }
21234
21280
  }
@@ -23251,15 +23297,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
23251
23297
  }
23252
23298
  class LinkCell extends AbstractCell {
23253
23299
  constructor(id, content, properties = {}) {
23254
- var _a;
23255
23300
  const link = parseMarkdownLink(content);
23256
- properties = {
23257
- ...properties,
23258
- style: {
23259
- ...properties.style,
23260
- textColor: ((_a = properties.style) === null || _a === void 0 ? void 0 : _a.textColor) || LINK_COLOR,
23261
- },
23262
- };
23263
23301
  link.label = _t(link.label);
23264
23302
  super(id, lazy({ value: link.label, type: CellValueType.text }), properties);
23265
23303
  this.link = link;
@@ -27825,6 +27863,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
27825
27863
  BordersPlugin.getters = ["getCellBorder"];
27826
27864
 
27827
27865
  const nbspRegexp = new RegExp(String.fromCharCode(160), "g");
27866
+ const LINK_STYLE = { textColor: LINK_COLOR };
27828
27867
  /**
27829
27868
  * Core Plugin
27830
27869
  *
@@ -28059,7 +28098,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
28059
28098
  return this.buildFormulaContent(sheetId, cell);
28060
28099
  }
28061
28100
  getCellStyle(cell) {
28062
- return (cell && cell.style) || {};
28101
+ if (!cell) {
28102
+ return {};
28103
+ }
28104
+ const linkStyle = cell.isLink() ? LINK_STYLE : {};
28105
+ return { ...linkStyle, ...cell.style };
28063
28106
  }
28064
28107
  /**
28065
28108
  * Converts a zone to a XC coordinate system
@@ -32468,7 +32511,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
32468
32511
  return 0 /* CommandResult.Success */;
32469
32512
  }
32470
32513
  handle(cmd) {
32471
- var _a, _b;
32514
+ var _a, _b, _c, _d;
32472
32515
  switch (cmd.type) {
32473
32516
  case "COPY":
32474
32517
  case "CUT":
@@ -32509,7 +32552,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
32509
32552
  case "ADD_COLUMNS_ROWS": {
32510
32553
  this.status = "invisible";
32511
32554
  // If we add a col/row inside or before the cut area, we invalidate the clipboard
32512
- if (((_a = this.state) === null || _a === void 0 ? void 0 : _a.operation) !== "CUT") {
32555
+ if (((_a = this.state) === null || _a === void 0 ? void 0 : _a.operation) !== "CUT" || cmd.sheetId !== ((_b = this.state) === null || _b === void 0 ? void 0 : _b.sheetId)) {
32513
32556
  return;
32514
32557
  }
32515
32558
  const isClipboardDirty = this.state.isColRowDirtyingClipboard(cmd.position === "before" ? cmd.base : cmd.base + 1, cmd.dimension);
@@ -32521,7 +32564,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
32521
32564
  case "REMOVE_COLUMNS_ROWS": {
32522
32565
  this.status = "invisible";
32523
32566
  // If we remove a col/row inside or before the cut area, we invalidate the clipboard
32524
- if (((_b = this.state) === null || _b === void 0 ? void 0 : _b.operation) !== "CUT") {
32567
+ if (((_c = this.state) === null || _c === void 0 ? void 0 : _c.operation) !== "CUT" || cmd.sheetId !== ((_d = this.state) === null || _d === void 0 ? void 0 : _d.sheetId)) {
32525
32568
  return;
32526
32569
  }
32527
32570
  for (let el of cmd.elements) {
@@ -39299,6 +39342,10 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
39299
39342
  });
39300
39343
  owl.useExternalListener(window, "resize", () => this.render(true));
39301
39344
  owl.useExternalListener(window, "beforeunload", this.unbindModelEvents.bind(this));
39345
+ // For some reason, the wheel event is not properly registered inside templates
39346
+ // in Chromium-based browsers based on chromium 125
39347
+ // This hack ensures the event declared in the template is properly registered/working
39348
+ owl.useExternalListener(document.body, "wheel", () => { });
39302
39349
  this.bindModelEvents();
39303
39350
  owl.onMounted(() => {
39304
39351
  this.checkViewportSize();
@@ -40624,6 +40671,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
40624
40671
  if (range.invalidXc) {
40625
40672
  return range.invalidXc;
40626
40673
  }
40674
+ if (!this.getters.tryGetSheet(range.sheetId)) {
40675
+ return INCORRECT_RANGE_STRING;
40676
+ }
40627
40677
  if (range.zone.bottom - range.zone.top < 0 || range.zone.right - range.zone.left < 0) {
40628
40678
  return INCORRECT_RANGE_STRING;
40629
40679
  }
@@ -41762,6 +41812,12 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
41762
41812
  else {
41763
41813
  // Shouldn't we always output the value then ?
41764
41814
  const value = cell.value;
41815
+ // If the cell contains a non-exported formula and that is evaluates to
41816
+ // nothing* ,we don't export it.
41817
+ // * non-falsy value are relevant and so are 0 and FALSE, which only leaves
41818
+ // the empty string.
41819
+ if (value === "")
41820
+ return undefined;
41765
41821
  const type = getCellType(value);
41766
41822
  attrs.push(["t", type]);
41767
41823
  node = escapeXml /*xml*/ `<v>${value}</v>`;
@@ -42484,7 +42540,11 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
42484
42540
  let cellNode = escapeXml ``;
42485
42541
  // Either formula or static value inside the cell
42486
42542
  if (cell.isFormula) {
42487
- ({ attrs: additionalAttrs, node: cellNode } = addFormula(cell));
42543
+ const res = addFormula(cell);
42544
+ if (!res) {
42545
+ continue;
42546
+ }
42547
+ ({ attrs: additionalAttrs, node: cellNode } = res);
42488
42548
  }
42489
42549
  else if (cell.content && isMarkdownLink(cell.content)) {
42490
42550
  const { label } = parseMarkdownLink(cell.content);
@@ -43322,9 +43382,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
43322
43382
  Object.defineProperty(exports, '__esModule', { value: true });
43323
43383
 
43324
43384
 
43325
- __info__.version = '16.0.41';
43326
- __info__.date = '2024-05-15T09:15:13.021Z';
43327
- __info__.hash = '3b3f648';
43385
+ __info__.version = '16.0.43';
43386
+ __info__.date = '2024-06-03T14:49:29.032Z';
43387
+ __info__.hash = '7bff796';
43328
43388
 
43329
43389
 
43330
43390
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);