@odoo/o-spreadsheet 17.0.0 → 17.1.0-alpha.0

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.
@@ -2,9 +2,9 @@
2
2
  /**
3
3
  * This file is generated by o-spreadsheet build tools. Do not edit it.
4
4
  * @see https://github.com/odoo/o-spreadsheet
5
- * @version 17.0.0
6
- * @date 2023-10-27T06:53:09.229Z
7
- * @hash c0a34c2
5
+ * @version 17.1.0-alpha.0
6
+ * @date 2023-10-28T08:12:20.922Z
7
+ * @hash a6a33b5
8
8
  */
9
9
 
10
10
  'use strict';
@@ -6630,6 +6630,31 @@ function* iterateChildren(el) {
6630
6630
  function getOpenedMenus() {
6631
6631
  return Array.from(document.querySelectorAll(".o-spreadsheet .o-menu"));
6632
6632
  }
6633
+ const letterRegex = /^[a-zA-Z]$/;
6634
+ /**
6635
+ * Transform a keyboard event into a shortcut string that represent this event. The letters keys will be uppercased.
6636
+ *
6637
+ * @argument ev - The keyboard event to transform
6638
+ * @argument mode - Use either ev.key of ev.code to get the string shortcut
6639
+ *
6640
+ * @example
6641
+ * event : { ctrlKey: true, key: "a" } => "Ctrl+A"
6642
+ * event : { shift: true, alt: true, key: "Home" } => "Alt+Shift+Home"
6643
+ */
6644
+ function keyboardEventToShortcutString(ev, mode = "key") {
6645
+ let keyDownString = "";
6646
+ if (ev.ctrlKey && ev.key !== "Ctrl")
6647
+ keyDownString += "Ctrl+";
6648
+ if (ev.metaKey)
6649
+ keyDownString += "Ctrl+";
6650
+ if (ev.altKey && ev.key !== "Alt")
6651
+ keyDownString += "Alt+";
6652
+ if (ev.shiftKey && ev.key !== "Shift")
6653
+ keyDownString += "Shift+";
6654
+ const key = mode === "key" ? ev.key : ev.code;
6655
+ keyDownString += letterRegex.test(key) ? key.toUpperCase() : key;
6656
+ return keyDownString;
6657
+ }
6633
6658
 
6634
6659
  /**
6635
6660
  * Return the o-spreadsheet element position relative
@@ -27352,16 +27377,16 @@ class Composer extends owl.Component {
27352
27377
  shouldProcessInputEvents = false;
27353
27378
  tokens = [];
27354
27379
  keyMapping = {
27355
- ArrowUp: this.processArrowKeys,
27356
- ArrowDown: this.processArrowKeys,
27357
- ArrowLeft: this.processArrowKeys,
27358
- ArrowRight: this.processArrowKeys,
27359
- Enter: this.processEnterKey,
27380
+ Enter: (ev) => this.processEnterKey(ev, "down"),
27381
+ "Shift+Enter": (ev) => this.processEnterKey(ev, "up"),
27382
+ "Alt+Enter": this.processNewLineEvent,
27383
+ "Ctrl+Enter": this.processNewLineEvent,
27360
27384
  Escape: this.processEscapeKey,
27361
27385
  F2: () => console.warn("Not implemented"),
27362
27386
  F4: this.processF4Key,
27363
- Tab: (ev) => this.processTabKey(ev),
27364
- " ": (ev) => this.processSpaceKey(ev),
27387
+ Tab: (ev) => this.processTabKey(ev, "right"),
27388
+ "Shift+Tab": (ev) => this.processTabKey(ev, "left"),
27389
+ "Ctrl+ ": this.processSpaceKey,
27365
27390
  };
27366
27391
  keyCodeMapping = {
27367
27392
  NumpadDecimal: this.processNumpadDecimal,
@@ -27423,7 +27448,7 @@ class Composer extends owl.Component {
27423
27448
  }
27424
27449
  }
27425
27450
  }
27426
- processTabKey(ev) {
27451
+ processTabKey(ev, direction) {
27427
27452
  ev.preventDefault();
27428
27453
  ev.stopPropagation();
27429
27454
  const state = this.autoCompleteState;
@@ -27434,25 +27459,18 @@ class Composer extends owl.Component {
27434
27459
  return;
27435
27460
  }
27436
27461
  }
27437
- const direction = ev.shiftKey ? "left" : "right";
27438
27462
  interactiveStopEdition(this.env);
27439
27463
  this.env.model.selection.moveAnchorCell(direction, 1);
27440
27464
  }
27441
27465
  processSpaceKey(ev) {
27442
- if (ev.ctrlKey) {
27443
- ev.preventDefault();
27444
- ev.stopPropagation();
27445
- this.showFunctionAutocomplete("");
27446
- this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
27447
- }
27466
+ ev.preventDefault();
27467
+ ev.stopPropagation();
27468
+ this.showFunctionAutocomplete("");
27469
+ this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
27448
27470
  }
27449
- processEnterKey(ev) {
27471
+ processEnterKey(ev, direction) {
27450
27472
  ev.preventDefault();
27451
27473
  ev.stopPropagation();
27452
- if (ev.altKey || ev.ctrlKey) {
27453
- this.composerRef.el?.dispatchEvent(new InputEvent("input", { inputType: "insertParagraph", bubbles: true, isComposing: false }));
27454
- return;
27455
- }
27456
27474
  const state = this.autoCompleteState;
27457
27475
  if (state.showProvider && state.selectedIndex !== undefined) {
27458
27476
  const autoCompleteValue = this.autoCompleteState.values[state.selectedIndex]?.text;
@@ -27462,9 +27480,22 @@ class Composer extends owl.Component {
27462
27480
  }
27463
27481
  }
27464
27482
  interactiveStopEdition(this.env);
27465
- const direction = ev.shiftKey ? "up" : "down";
27466
27483
  this.env.model.selection.moveAnchorCell(direction, 1);
27467
27484
  }
27485
+ processNewLineEvent(ev) {
27486
+ ev.preventDefault();
27487
+ ev.stopPropagation();
27488
+ const content = this.contentHelper.getText();
27489
+ const selection = this.contentHelper.getCurrentSelection();
27490
+ const start = Math.min(selection.start, selection.end);
27491
+ const end = Math.max(selection.start, selection.end);
27492
+ this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
27493
+ this.env.model.dispatch("SET_CURRENT_CONTENT", {
27494
+ content: content.slice(0, start) + NEWLINE + content.slice(end),
27495
+ selection: { start: start + 1, end: start + 1 },
27496
+ });
27497
+ this.processContent();
27498
+ }
27468
27499
  processEscapeKey() {
27469
27500
  this.env.model.dispatch("CANCEL_EDITION");
27470
27501
  }
@@ -27498,7 +27529,12 @@ class Composer extends owl.Component {
27498
27529
  this.compositionActive = false;
27499
27530
  }
27500
27531
  onKeydown(ev) {
27501
- let handler = this.keyMapping[ev.key] || this.keyCodeMapping[ev.code];
27532
+ if (ev.key.startsWith("Arrow")) {
27533
+ this.processArrowKeys(ev);
27534
+ return;
27535
+ }
27536
+ let handler = this.keyMapping[keyboardEventToShortcutString(ev)] ||
27537
+ this.keyCodeMapping[keyboardEventToShortcutString(ev, "code")];
27502
27538
  if (handler) {
27503
27539
  handler.call(this, ev);
27504
27540
  }
@@ -27515,12 +27551,6 @@ class Composer extends owl.Component {
27515
27551
  }
27516
27552
  let content = this.contentHelper.getText();
27517
27553
  let selection = this.contentHelper.getCurrentSelection();
27518
- if (ev.inputType === "insertParagraph") {
27519
- const start = Math.min(selection.start, selection.end);
27520
- const end = Math.max(selection.start, selection.end);
27521
- content = content.slice(0, start) + NEWLINE + content.slice(end);
27522
- selection = { start: start + 1, end: start + 1 };
27523
- }
27524
27554
  this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
27525
27555
  this.env.model.dispatch("SET_CURRENT_CONTENT", {
27526
27556
  content,
@@ -30217,33 +30247,33 @@ class Grid extends owl.Component {
30217
30247
  // this map will handle most of the actions that should happen on key down. The arrow keys are managed in the key
30218
30248
  // down itself
30219
30249
  keyDownMapping = {
30220
- ENTER: () => {
30250
+ Enter: () => {
30221
30251
  const cell = this.env.model.getters.getActiveCell();
30222
30252
  cell.type === CellValueType.empty
30223
30253
  ? this.props.onGridComposerCellFocused()
30224
30254
  : this.props.onComposerContentFocused();
30225
30255
  },
30226
- TAB: () => this.env.model.selection.moveAnchorCell("right", 1),
30227
- "SHIFT+TAB": () => this.env.model.selection.moveAnchorCell("left", 1),
30256
+ Tab: () => this.env.model.selection.moveAnchorCell("right", 1),
30257
+ "Shift+Tab": () => this.env.model.selection.moveAnchorCell("left", 1),
30228
30258
  F2: () => {
30229
30259
  const cell = this.env.model.getters.getActiveCell();
30230
30260
  cell.type === CellValueType.empty
30231
30261
  ? this.props.onGridComposerCellFocused()
30232
30262
  : this.props.onComposerContentFocused();
30233
30263
  },
30234
- DELETE: () => {
30264
+ Delete: () => {
30235
30265
  this.env.model.dispatch("DELETE_CONTENT", {
30236
30266
  sheetId: this.env.model.getters.getActiveSheetId(),
30237
30267
  target: this.env.model.getters.getSelectedZones(),
30238
30268
  });
30239
30269
  },
30240
- BACKSPACE: () => {
30270
+ Backspace: () => {
30241
30271
  this.env.model.dispatch("DELETE_CONTENT", {
30242
30272
  sheetId: this.env.model.getters.getActiveSheetId(),
30243
30273
  target: this.env.model.getters.getSelectedZones(),
30244
30274
  });
30245
30275
  },
30246
- ESCAPE: () => {
30276
+ Escape: () => {
30247
30277
  /** TODO: Clean once we introduce proper focus on sub components. Grid should not have to handle all this logic */
30248
30278
  if (this.env.model.getters.hasOpenedPopover()) {
30249
30279
  this.closeOpenedPopover();
@@ -30258,27 +30288,27 @@ class Grid extends owl.Component {
30258
30288
  this.env.model.dispatch("CLEAN_CLIPBOARD_HIGHLIGHT");
30259
30289
  }
30260
30290
  },
30261
- "CTRL+A": () => this.env.model.selection.loopSelection(),
30262
- "CTRL+Z": () => this.env.model.dispatch("REQUEST_UNDO"),
30263
- "CTRL+Y": () => this.env.model.dispatch("REQUEST_REDO"),
30291
+ "Ctrl+A": () => this.env.model.selection.loopSelection(),
30292
+ "Ctrl+Z": () => this.env.model.dispatch("REQUEST_UNDO"),
30293
+ "Ctrl+Y": () => this.env.model.dispatch("REQUEST_REDO"),
30264
30294
  F4: () => this.env.model.dispatch("REQUEST_REDO"),
30265
- "CTRL+B": () => this.env.model.dispatch("SET_FORMATTING", {
30295
+ "Ctrl+B": () => this.env.model.dispatch("SET_FORMATTING", {
30266
30296
  sheetId: this.env.model.getters.getActiveSheetId(),
30267
30297
  target: this.env.model.getters.getSelectedZones(),
30268
30298
  style: { bold: !this.env.model.getters.getCurrentStyle().bold },
30269
30299
  }),
30270
- "CTRL+I": () => this.env.model.dispatch("SET_FORMATTING", {
30300
+ "Ctrl+I": () => this.env.model.dispatch("SET_FORMATTING", {
30271
30301
  sheetId: this.env.model.getters.getActiveSheetId(),
30272
30302
  target: this.env.model.getters.getSelectedZones(),
30273
30303
  style: { italic: !this.env.model.getters.getCurrentStyle().italic },
30274
30304
  }),
30275
- "CTRL+U": () => this.env.model.dispatch("SET_FORMATTING", {
30305
+ "Ctrl+U": () => this.env.model.dispatch("SET_FORMATTING", {
30276
30306
  sheetId: this.env.model.getters.getActiveSheetId(),
30277
30307
  target: this.env.model.getters.getSelectedZones(),
30278
30308
  style: { underline: !this.env.model.getters.getCurrentStyle().underline },
30279
30309
  }),
30280
- "CTRL+O": () => CREATE_IMAGE(this.env),
30281
- "ALT+=": () => {
30310
+ "Ctrl+O": () => CREATE_IMAGE(this.env),
30311
+ "Alt+=": () => {
30282
30312
  const sheetId = this.env.model.getters.getActiveSheetId();
30283
30313
  const mainSelectedZone = this.env.model.getters.getSelectedZone();
30284
30314
  const { anchor } = this.env.model.getters.getSelection();
@@ -30294,13 +30324,13 @@ class Grid extends owl.Component {
30294
30324
  this.env.model.dispatch("SUM_SELECTION");
30295
30325
  }
30296
30326
  },
30297
- "ALT+ENTER": () => {
30327
+ "Alt+Enter": () => {
30298
30328
  const cell = this.env.model.getters.getActiveCell();
30299
30329
  if (cell.link) {
30300
30330
  openLink(cell.link, this.env);
30301
30331
  }
30302
30332
  },
30303
- "CTRL+HOME": () => {
30333
+ "Ctrl+Home": () => {
30304
30334
  const sheetId = this.env.model.getters.getActiveSheetId();
30305
30335
  const { col, row } = this.env.model.getters.getNextVisibleCellPosition({
30306
30336
  sheetId,
@@ -30309,13 +30339,13 @@ class Grid extends owl.Component {
30309
30339
  });
30310
30340
  this.env.model.selection.selectCell(col, row);
30311
30341
  },
30312
- "CTRL+END": () => {
30342
+ "Ctrl+End": () => {
30313
30343
  const sheetId = this.env.model.getters.getActiveSheetId();
30314
30344
  const col = this.env.model.getters.findVisibleHeader(sheetId, "COL", this.env.model.getters.getNumberCols(sheetId) - 1, 0);
30315
30345
  const row = this.env.model.getters.findVisibleHeader(sheetId, "ROW", this.env.model.getters.getNumberRows(sheetId) - 1, 0);
30316
30346
  this.env.model.selection.selectCell(col, row);
30317
30347
  },
30318
- "SHIFT+ ": () => {
30348
+ "Shift+ ": () => {
30319
30349
  const sheetId = this.env.model.getters.getActiveSheetId();
30320
30350
  const newZone = {
30321
30351
  ...this.env.model.getters.getSelectedZone(),
@@ -30325,7 +30355,7 @@ class Grid extends owl.Component {
30325
30355
  const position = this.env.model.getters.getActivePosition();
30326
30356
  this.env.model.selection.selectZone({ cell: position, zone: newZone });
30327
30357
  },
30328
- "CTRL+ ": () => {
30358
+ "Ctrl+ ": () => {
30329
30359
  const sheetId = this.env.model.getters.getActiveSheetId();
30330
30360
  const newZone = {
30331
30361
  ...this.env.model.getters.getSelectedZone(),
@@ -30335,18 +30365,18 @@ class Grid extends owl.Component {
30335
30365
  const position = this.env.model.getters.getActivePosition();
30336
30366
  this.env.model.selection.selectZone({ cell: position, zone: newZone });
30337
30367
  },
30338
- "CTRL+D": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ABOVE"),
30339
- "CTRL+R": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ON_LEFT"),
30340
- "CTRL+SHIFT+E": () => this.setHorizontalAlign("center"),
30341
- "CTRL+SHIFT+L": () => this.setHorizontalAlign("left"),
30342
- "CTRL+SHIFT+R": () => this.setHorizontalAlign("right"),
30343
- "CTRL+SHIFT+V": () => PASTE_VALUE_ACTION(this.env),
30344
- "CTRL+SHIFT+<": () => this.clearFormatting(),
30345
- "CTRL+<": () => this.clearFormatting(),
30346
- "CTRL+SHIFT+ ": () => {
30368
+ "Ctrl+D": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ABOVE"),
30369
+ "Ctrl+R": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ON_LEFT"),
30370
+ "Ctrl+Shift+E": () => this.setHorizontalAlign("center"),
30371
+ "Ctrl+Shift+L": () => this.setHorizontalAlign("left"),
30372
+ "Ctrl+Shift+R": () => this.setHorizontalAlign("right"),
30373
+ "Ctrl+Shift+V": () => PASTE_VALUE_ACTION(this.env),
30374
+ "Ctrl+Shift+<": () => this.clearFormatting(),
30375
+ "Ctrl+<": () => this.clearFormatting(),
30376
+ "Ctrl+Shift+ ": () => {
30347
30377
  this.env.model.selection.selectAll();
30348
30378
  },
30349
- "CTRL+ALT+=": () => {
30379
+ "Ctrl+Alt+=": () => {
30350
30380
  const activeCols = this.env.model.getters.getActiveCols();
30351
30381
  const activeRows = this.env.model.getters.getActiveRows();
30352
30382
  const isSingleSelection = this.env.model.getters.getSelectedZones().length === 1;
@@ -30359,7 +30389,7 @@ class Grid extends owl.Component {
30359
30389
  INSERT_ROWS_BEFORE_ACTION(this.env);
30360
30390
  }
30361
30391
  },
30362
- "CTRL+ALT+-": () => {
30392
+ "Ctrl+Alt+-": () => {
30363
30393
  const columns = [...this.env.model.getters.getActiveCols()];
30364
30394
  const rows = [...this.env.model.getters.getActiveRows()];
30365
30395
  if (columns.length > 0 && rows.length === 0) {
@@ -30377,19 +30407,19 @@ class Grid extends owl.Component {
30377
30407
  });
30378
30408
  }
30379
30409
  },
30380
- "SHIFT+PAGEDOWN": () => {
30410
+ "Shift+PageDown": () => {
30381
30411
  this.env.model.dispatch("ACTIVATE_NEXT_SHEET");
30382
30412
  },
30383
- "SHIFT+PAGEUP": () => {
30413
+ "Shift+PageUp": () => {
30384
30414
  this.env.model.dispatch("ACTIVATE_PREVIOUS_SHEET");
30385
30415
  },
30386
- PAGEDOWN: () => this.env.model.dispatch("SHIFT_VIEWPORT_DOWN"),
30387
- PAGEUP: () => this.env.model.dispatch("SHIFT_VIEWPORT_UP"),
30388
- "CTRL+K": () => INSERT_LINK(this.env),
30389
- "ALT+SHIFT+ARROWRIGHT": () => this.processHeaderGroupingKey("right"),
30390
- "ALT+SHIFT+ARROWLEFT": () => this.processHeaderGroupingKey("left"),
30391
- "ALT+SHIFT+ARROWUP": () => this.processHeaderGroupingKey("up"),
30392
- "ALT+SHIFT+ARROWDOWN": () => this.processHeaderGroupingKey("down"),
30416
+ PageDown: () => this.env.model.dispatch("SHIFT_VIEWPORT_DOWN"),
30417
+ PageUp: () => this.env.model.dispatch("SHIFT_VIEWPORT_UP"),
30418
+ "Ctrl+K": () => INSERT_LINK(this.env),
30419
+ "Alt+Shift+ArrowRight": () => this.processHeaderGroupingKey("right"),
30420
+ "Alt+Shift+ArrowLeft": () => this.processHeaderGroupingKey("left"),
30421
+ "Alt+Shift+ArrowUp": () => this.processHeaderGroupingKey("up"),
30422
+ "Alt+Shift+ArrowDown": () => this.processHeaderGroupingKey("down"),
30393
30423
  };
30394
30424
  focus() {
30395
30425
  if (!this.env.model.getters.getSelectedFigureId() &&
@@ -30517,18 +30547,8 @@ class Grid extends owl.Component {
30517
30547
  }
30518
30548
  }
30519
30549
  onKeydown(ev) {
30520
- const eventKey = ev.key.toUpperCase();
30521
- let keyDownString = "";
30522
- if (ev.ctrlKey && eventKey !== "CTRL")
30523
- keyDownString += "CTRL+";
30524
- if (ev.metaKey)
30525
- keyDownString += "CTRL+";
30526
- if (ev.altKey && eventKey !== "ALT")
30527
- keyDownString += "ALT+";
30528
- if (ev.shiftKey && eventKey !== "SHIFT")
30529
- keyDownString += "SHIFT+";
30530
- keyDownString += ev.key.toUpperCase();
30531
- let handler = this.keyDownMapping[keyDownString];
30550
+ const keyDownString = keyboardEventToShortcutString(ev);
30551
+ const handler = this.keyDownMapping[keyDownString];
30532
30552
  if (handler) {
30533
30553
  ev.preventDefault();
30534
30554
  ev.stopPropagation();
@@ -55814,6 +55834,6 @@ exports.setTranslationMethod = setTranslationMethod;
55814
55834
  exports.tokenize = tokenize;
55815
55835
 
55816
55836
 
55817
- __info__.version = "17.0.0";
55818
- __info__.date = "2023-10-27T06:53:09.229Z";
55819
- __info__.hash = "c0a34c2";
55837
+ __info__.version = "17.1.0-alpha.0";
55838
+ __info__.date = "2023-10-28T08:12:20.922Z";
55839
+ __info__.hash = "a6a33b5";
@@ -7204,6 +7204,7 @@ declare class Composer extends Component<ComposerProps, SpreadsheetChildEnv> {
7204
7204
  private processTabKey;
7205
7205
  processSpaceKey(ev: KeyboardEvent): void;
7206
7206
  private processEnterKey;
7207
+ private processNewLineEvent;
7207
7208
  private processEscapeKey;
7208
7209
  private processF4Key;
7209
7210
  private processNumpadDecimal;