@odoo/o-spreadsheet 17.0.1 → 17.1.0-alpha.1

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.1
6
- * @date 2023-11-02T09:35:50.522Z
7
- * @hash 0887d5b
5
+ * @version 17.1.0-alpha.1
6
+ * @date 2023-11-02T09:35:10.532Z
7
+ * @hash 3b1fe3b
8
8
  */
9
9
 
10
10
  'use strict';
@@ -6638,6 +6638,31 @@ function* iterateChildren(el) {
6638
6638
  function getOpenedMenus() {
6639
6639
  return Array.from(document.querySelectorAll(".o-spreadsheet .o-menu"));
6640
6640
  }
6641
+ const letterRegex = /^[a-zA-Z]$/;
6642
+ /**
6643
+ * Transform a keyboard event into a shortcut string that represent this event. The letters keys will be uppercased.
6644
+ *
6645
+ * @argument ev - The keyboard event to transform
6646
+ * @argument mode - Use either ev.key of ev.code to get the string shortcut
6647
+ *
6648
+ * @example
6649
+ * event : { ctrlKey: true, key: "a" } => "Ctrl+A"
6650
+ * event : { shift: true, alt: true, key: "Home" } => "Alt+Shift+Home"
6651
+ */
6652
+ function keyboardEventToShortcutString(ev, mode = "key") {
6653
+ let keyDownString = "";
6654
+ if (ev.ctrlKey && ev.key !== "Ctrl")
6655
+ keyDownString += "Ctrl+";
6656
+ if (ev.metaKey)
6657
+ keyDownString += "Ctrl+";
6658
+ if (ev.altKey && ev.key !== "Alt")
6659
+ keyDownString += "Alt+";
6660
+ if (ev.shiftKey && ev.key !== "Shift")
6661
+ keyDownString += "Shift+";
6662
+ const key = mode === "key" ? ev.key : ev.code;
6663
+ keyDownString += letterRegex.test(key) ? key.toUpperCase() : key;
6664
+ return keyDownString;
6665
+ }
6641
6666
 
6642
6667
  /**
6643
6668
  * Return the o-spreadsheet element position relative
@@ -26476,16 +26501,16 @@ class Composer extends owl.Component {
26476
26501
  shouldProcessInputEvents = false;
26477
26502
  tokens = [];
26478
26503
  keyMapping = {
26479
- ArrowUp: this.processArrowKeys,
26480
- ArrowDown: this.processArrowKeys,
26481
- ArrowLeft: this.processArrowKeys,
26482
- ArrowRight: this.processArrowKeys,
26483
- Enter: this.processEnterKey,
26504
+ Enter: (ev) => this.processEnterKey(ev, "down"),
26505
+ "Shift+Enter": (ev) => this.processEnterKey(ev, "up"),
26506
+ "Alt+Enter": this.processNewLineEvent,
26507
+ "Ctrl+Enter": this.processNewLineEvent,
26484
26508
  Escape: this.processEscapeKey,
26485
26509
  F2: () => console.warn("Not implemented"),
26486
26510
  F4: this.processF4Key,
26487
- Tab: (ev) => this.processTabKey(ev),
26488
- " ": (ev) => this.processSpaceKey(ev),
26511
+ Tab: (ev) => this.processTabKey(ev, "right"),
26512
+ "Shift+Tab": (ev) => this.processTabKey(ev, "left"),
26513
+ "Ctrl+ ": this.processSpaceKey,
26489
26514
  };
26490
26515
  keyCodeMapping = {
26491
26516
  NumpadDecimal: this.processNumpadDecimal,
@@ -26547,7 +26572,7 @@ class Composer extends owl.Component {
26547
26572
  }
26548
26573
  }
26549
26574
  }
26550
- processTabKey(ev) {
26575
+ processTabKey(ev, direction) {
26551
26576
  ev.preventDefault();
26552
26577
  ev.stopPropagation();
26553
26578
  const state = this.autoCompleteState;
@@ -26558,25 +26583,18 @@ class Composer extends owl.Component {
26558
26583
  return;
26559
26584
  }
26560
26585
  }
26561
- const direction = ev.shiftKey ? "left" : "right";
26562
26586
  interactiveStopEdition(this.env);
26563
26587
  this.env.model.selection.moveAnchorCell(direction, 1);
26564
26588
  }
26565
26589
  processSpaceKey(ev) {
26566
- if (ev.ctrlKey) {
26567
- ev.preventDefault();
26568
- ev.stopPropagation();
26569
- this.showFunctionAutocomplete("");
26570
- this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
26571
- }
26590
+ ev.preventDefault();
26591
+ ev.stopPropagation();
26592
+ this.showFunctionAutocomplete("");
26593
+ this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
26572
26594
  }
26573
- processEnterKey(ev) {
26595
+ processEnterKey(ev, direction) {
26574
26596
  ev.preventDefault();
26575
26597
  ev.stopPropagation();
26576
- if (ev.altKey || ev.ctrlKey) {
26577
- this.composerRef.el?.dispatchEvent(new InputEvent("input", { inputType: "insertParagraph", bubbles: true, isComposing: false }));
26578
- return;
26579
- }
26580
26598
  const state = this.autoCompleteState;
26581
26599
  if (state.showProvider && state.selectedIndex !== undefined) {
26582
26600
  const autoCompleteValue = this.autoCompleteState.values[state.selectedIndex]?.text;
@@ -26586,9 +26604,22 @@ class Composer extends owl.Component {
26586
26604
  }
26587
26605
  }
26588
26606
  interactiveStopEdition(this.env);
26589
- const direction = ev.shiftKey ? "up" : "down";
26590
26607
  this.env.model.selection.moveAnchorCell(direction, 1);
26591
26608
  }
26609
+ processNewLineEvent(ev) {
26610
+ ev.preventDefault();
26611
+ ev.stopPropagation();
26612
+ const content = this.contentHelper.getText();
26613
+ const selection = this.contentHelper.getCurrentSelection();
26614
+ const start = Math.min(selection.start, selection.end);
26615
+ const end = Math.max(selection.start, selection.end);
26616
+ this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
26617
+ this.env.model.dispatch("SET_CURRENT_CONTENT", {
26618
+ content: content.slice(0, start) + NEWLINE + content.slice(end),
26619
+ selection: { start: start + 1, end: start + 1 },
26620
+ });
26621
+ this.processContent();
26622
+ }
26592
26623
  processEscapeKey() {
26593
26624
  this.env.model.dispatch("CANCEL_EDITION");
26594
26625
  }
@@ -26622,7 +26653,12 @@ class Composer extends owl.Component {
26622
26653
  this.compositionActive = false;
26623
26654
  }
26624
26655
  onKeydown(ev) {
26625
- let handler = this.keyMapping[ev.key] || this.keyCodeMapping[ev.code];
26656
+ if (ev.key.startsWith("Arrow")) {
26657
+ this.processArrowKeys(ev);
26658
+ return;
26659
+ }
26660
+ let handler = this.keyMapping[keyboardEventToShortcutString(ev)] ||
26661
+ this.keyCodeMapping[keyboardEventToShortcutString(ev, "code")];
26626
26662
  if (handler) {
26627
26663
  handler.call(this, ev);
26628
26664
  }
@@ -26639,12 +26675,6 @@ class Composer extends owl.Component {
26639
26675
  }
26640
26676
  let content = this.contentHelper.getText();
26641
26677
  let selection = this.contentHelper.getCurrentSelection();
26642
- if (ev.inputType === "insertParagraph") {
26643
- const start = Math.min(selection.start, selection.end);
26644
- const end = Math.max(selection.start, selection.end);
26645
- content = content.slice(0, start) + NEWLINE + content.slice(end);
26646
- selection = { start: start + 1, end: start + 1 };
26647
- }
26648
26678
  this.env.model.dispatch("STOP_COMPOSER_RANGE_SELECTION");
26649
26679
  this.env.model.dispatch("SET_CURRENT_CONTENT", {
26650
26680
  content,
@@ -29341,33 +29371,33 @@ class Grid extends owl.Component {
29341
29371
  // this map will handle most of the actions that should happen on key down. The arrow keys are managed in the key
29342
29372
  // down itself
29343
29373
  keyDownMapping = {
29344
- ENTER: () => {
29374
+ Enter: () => {
29345
29375
  const cell = this.env.model.getters.getActiveCell();
29346
29376
  cell.type === CellValueType.empty
29347
29377
  ? this.props.onGridComposerCellFocused()
29348
29378
  : this.props.onComposerContentFocused();
29349
29379
  },
29350
- TAB: () => this.env.model.selection.moveAnchorCell("right", 1),
29351
- "SHIFT+TAB": () => this.env.model.selection.moveAnchorCell("left", 1),
29380
+ Tab: () => this.env.model.selection.moveAnchorCell("right", 1),
29381
+ "Shift+Tab": () => this.env.model.selection.moveAnchorCell("left", 1),
29352
29382
  F2: () => {
29353
29383
  const cell = this.env.model.getters.getActiveCell();
29354
29384
  cell.type === CellValueType.empty
29355
29385
  ? this.props.onGridComposerCellFocused()
29356
29386
  : this.props.onComposerContentFocused();
29357
29387
  },
29358
- DELETE: () => {
29388
+ Delete: () => {
29359
29389
  this.env.model.dispatch("DELETE_CONTENT", {
29360
29390
  sheetId: this.env.model.getters.getActiveSheetId(),
29361
29391
  target: this.env.model.getters.getSelectedZones(),
29362
29392
  });
29363
29393
  },
29364
- BACKSPACE: () => {
29394
+ Backspace: () => {
29365
29395
  this.env.model.dispatch("DELETE_CONTENT", {
29366
29396
  sheetId: this.env.model.getters.getActiveSheetId(),
29367
29397
  target: this.env.model.getters.getSelectedZones(),
29368
29398
  });
29369
29399
  },
29370
- ESCAPE: () => {
29400
+ Escape: () => {
29371
29401
  /** TODO: Clean once we introduce proper focus on sub components. Grid should not have to handle all this logic */
29372
29402
  if (this.env.model.getters.hasOpenedPopover()) {
29373
29403
  this.closeOpenedPopover();
@@ -29382,27 +29412,27 @@ class Grid extends owl.Component {
29382
29412
  this.env.model.dispatch("CLEAN_CLIPBOARD_HIGHLIGHT");
29383
29413
  }
29384
29414
  },
29385
- "CTRL+A": () => this.env.model.selection.loopSelection(),
29386
- "CTRL+Z": () => this.env.model.dispatch("REQUEST_UNDO"),
29387
- "CTRL+Y": () => this.env.model.dispatch("REQUEST_REDO"),
29415
+ "Ctrl+A": () => this.env.model.selection.loopSelection(),
29416
+ "Ctrl+Z": () => this.env.model.dispatch("REQUEST_UNDO"),
29417
+ "Ctrl+Y": () => this.env.model.dispatch("REQUEST_REDO"),
29388
29418
  F4: () => this.env.model.dispatch("REQUEST_REDO"),
29389
- "CTRL+B": () => this.env.model.dispatch("SET_FORMATTING", {
29419
+ "Ctrl+B": () => this.env.model.dispatch("SET_FORMATTING", {
29390
29420
  sheetId: this.env.model.getters.getActiveSheetId(),
29391
29421
  target: this.env.model.getters.getSelectedZones(),
29392
29422
  style: { bold: !this.env.model.getters.getCurrentStyle().bold },
29393
29423
  }),
29394
- "CTRL+I": () => this.env.model.dispatch("SET_FORMATTING", {
29424
+ "Ctrl+I": () => this.env.model.dispatch("SET_FORMATTING", {
29395
29425
  sheetId: this.env.model.getters.getActiveSheetId(),
29396
29426
  target: this.env.model.getters.getSelectedZones(),
29397
29427
  style: { italic: !this.env.model.getters.getCurrentStyle().italic },
29398
29428
  }),
29399
- "CTRL+U": () => this.env.model.dispatch("SET_FORMATTING", {
29429
+ "Ctrl+U": () => this.env.model.dispatch("SET_FORMATTING", {
29400
29430
  sheetId: this.env.model.getters.getActiveSheetId(),
29401
29431
  target: this.env.model.getters.getSelectedZones(),
29402
29432
  style: { underline: !this.env.model.getters.getCurrentStyle().underline },
29403
29433
  }),
29404
- "CTRL+O": () => CREATE_IMAGE(this.env),
29405
- "ALT+=": () => {
29434
+ "Ctrl+O": () => CREATE_IMAGE(this.env),
29435
+ "Alt+=": () => {
29406
29436
  const sheetId = this.env.model.getters.getActiveSheetId();
29407
29437
  const mainSelectedZone = this.env.model.getters.getSelectedZone();
29408
29438
  const { anchor } = this.env.model.getters.getSelection();
@@ -29418,13 +29448,13 @@ class Grid extends owl.Component {
29418
29448
  this.env.model.dispatch("SUM_SELECTION");
29419
29449
  }
29420
29450
  },
29421
- "ALT+ENTER": () => {
29451
+ "Alt+Enter": () => {
29422
29452
  const cell = this.env.model.getters.getActiveCell();
29423
29453
  if (cell.link) {
29424
29454
  openLink(cell.link, this.env);
29425
29455
  }
29426
29456
  },
29427
- "CTRL+HOME": () => {
29457
+ "Ctrl+Home": () => {
29428
29458
  const sheetId = this.env.model.getters.getActiveSheetId();
29429
29459
  const { col, row } = this.env.model.getters.getNextVisibleCellPosition({
29430
29460
  sheetId,
@@ -29433,13 +29463,13 @@ class Grid extends owl.Component {
29433
29463
  });
29434
29464
  this.env.model.selection.selectCell(col, row);
29435
29465
  },
29436
- "CTRL+END": () => {
29466
+ "Ctrl+End": () => {
29437
29467
  const sheetId = this.env.model.getters.getActiveSheetId();
29438
29468
  const col = this.env.model.getters.findVisibleHeader(sheetId, "COL", this.env.model.getters.getNumberCols(sheetId) - 1, 0);
29439
29469
  const row = this.env.model.getters.findVisibleHeader(sheetId, "ROW", this.env.model.getters.getNumberRows(sheetId) - 1, 0);
29440
29470
  this.env.model.selection.selectCell(col, row);
29441
29471
  },
29442
- "SHIFT+ ": () => {
29472
+ "Shift+ ": () => {
29443
29473
  const sheetId = this.env.model.getters.getActiveSheetId();
29444
29474
  const newZone = {
29445
29475
  ...this.env.model.getters.getSelectedZone(),
@@ -29449,7 +29479,7 @@ class Grid extends owl.Component {
29449
29479
  const position = this.env.model.getters.getActivePosition();
29450
29480
  this.env.model.selection.selectZone({ cell: position, zone: newZone });
29451
29481
  },
29452
- "CTRL+ ": () => {
29482
+ "Ctrl+ ": () => {
29453
29483
  const sheetId = this.env.model.getters.getActiveSheetId();
29454
29484
  const newZone = {
29455
29485
  ...this.env.model.getters.getSelectedZone(),
@@ -29459,18 +29489,18 @@ class Grid extends owl.Component {
29459
29489
  const position = this.env.model.getters.getActivePosition();
29460
29490
  this.env.model.selection.selectZone({ cell: position, zone: newZone });
29461
29491
  },
29462
- "CTRL+D": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ABOVE"),
29463
- "CTRL+R": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ON_LEFT"),
29464
- "CTRL+SHIFT+E": () => this.setHorizontalAlign("center"),
29465
- "CTRL+SHIFT+L": () => this.setHorizontalAlign("left"),
29466
- "CTRL+SHIFT+R": () => this.setHorizontalAlign("right"),
29467
- "CTRL+SHIFT+V": () => PASTE_VALUE_ACTION(this.env),
29468
- "CTRL+SHIFT+<": () => this.clearFormatting(),
29469
- "CTRL+<": () => this.clearFormatting(),
29470
- "CTRL+SHIFT+ ": () => {
29492
+ "Ctrl+D": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ABOVE"),
29493
+ "Ctrl+R": async () => this.env.model.dispatch("COPY_PASTE_CELLS_ON_LEFT"),
29494
+ "Ctrl+Shift+E": () => this.setHorizontalAlign("center"),
29495
+ "Ctrl+Shift+L": () => this.setHorizontalAlign("left"),
29496
+ "Ctrl+Shift+R": () => this.setHorizontalAlign("right"),
29497
+ "Ctrl+Shift+V": () => PASTE_VALUE_ACTION(this.env),
29498
+ "Ctrl+Shift+<": () => this.clearFormatting(),
29499
+ "Ctrl+<": () => this.clearFormatting(),
29500
+ "Ctrl+Shift+ ": () => {
29471
29501
  this.env.model.selection.selectAll();
29472
29502
  },
29473
- "CTRL+ALT+=": () => {
29503
+ "Ctrl+Alt+=": () => {
29474
29504
  const activeCols = this.env.model.getters.getActiveCols();
29475
29505
  const activeRows = this.env.model.getters.getActiveRows();
29476
29506
  const isSingleSelection = this.env.model.getters.getSelectedZones().length === 1;
@@ -29483,7 +29513,7 @@ class Grid extends owl.Component {
29483
29513
  INSERT_ROWS_BEFORE_ACTION(this.env);
29484
29514
  }
29485
29515
  },
29486
- "CTRL+ALT+-": () => {
29516
+ "Ctrl+Alt+-": () => {
29487
29517
  const columns = [...this.env.model.getters.getActiveCols()];
29488
29518
  const rows = [...this.env.model.getters.getActiveRows()];
29489
29519
  if (columns.length > 0 && rows.length === 0) {
@@ -29501,19 +29531,19 @@ class Grid extends owl.Component {
29501
29531
  });
29502
29532
  }
29503
29533
  },
29504
- "SHIFT+PAGEDOWN": () => {
29534
+ "Shift+PageDown": () => {
29505
29535
  this.env.model.dispatch("ACTIVATE_NEXT_SHEET");
29506
29536
  },
29507
- "SHIFT+PAGEUP": () => {
29537
+ "Shift+PageUp": () => {
29508
29538
  this.env.model.dispatch("ACTIVATE_PREVIOUS_SHEET");
29509
29539
  },
29510
- PAGEDOWN: () => this.env.model.dispatch("SHIFT_VIEWPORT_DOWN"),
29511
- PAGEUP: () => this.env.model.dispatch("SHIFT_VIEWPORT_UP"),
29512
- "CTRL+K": () => INSERT_LINK(this.env),
29513
- "ALT+SHIFT+ARROWRIGHT": () => this.processHeaderGroupingKey("right"),
29514
- "ALT+SHIFT+ARROWLEFT": () => this.processHeaderGroupingKey("left"),
29515
- "ALT+SHIFT+ARROWUP": () => this.processHeaderGroupingKey("up"),
29516
- "ALT+SHIFT+ARROWDOWN": () => this.processHeaderGroupingKey("down"),
29540
+ PageDown: () => this.env.model.dispatch("SHIFT_VIEWPORT_DOWN"),
29541
+ PageUp: () => this.env.model.dispatch("SHIFT_VIEWPORT_UP"),
29542
+ "Ctrl+K": () => INSERT_LINK(this.env),
29543
+ "Alt+Shift+ArrowRight": () => this.processHeaderGroupingKey("right"),
29544
+ "Alt+Shift+ArrowLeft": () => this.processHeaderGroupingKey("left"),
29545
+ "Alt+Shift+ArrowUp": () => this.processHeaderGroupingKey("up"),
29546
+ "Alt+Shift+ArrowDown": () => this.processHeaderGroupingKey("down"),
29517
29547
  };
29518
29548
  focus() {
29519
29549
  if (!this.env.model.getters.getSelectedFigureId() &&
@@ -29641,18 +29671,8 @@ class Grid extends owl.Component {
29641
29671
  }
29642
29672
  }
29643
29673
  onKeydown(ev) {
29644
- const eventKey = ev.key.toUpperCase();
29645
- let keyDownString = "";
29646
- if (ev.ctrlKey && eventKey !== "CTRL")
29647
- keyDownString += "CTRL+";
29648
- if (ev.metaKey)
29649
- keyDownString += "CTRL+";
29650
- if (ev.altKey && eventKey !== "ALT")
29651
- keyDownString += "ALT+";
29652
- if (ev.shiftKey && eventKey !== "SHIFT")
29653
- keyDownString += "SHIFT+";
29654
- keyDownString += ev.key.toUpperCase();
29655
- let handler = this.keyDownMapping[keyDownString];
29674
+ const keyDownString = keyboardEventToShortcutString(ev);
29675
+ const handler = this.keyDownMapping[keyDownString];
29656
29676
  if (handler) {
29657
29677
  ev.preventDefault();
29658
29678
  ev.stopPropagation();
@@ -43487,6 +43507,8 @@ class ClipboardCellsState extends ClipboardCellsAbstractState {
43487
43507
  if (height > 1 || width > 1 || isCutOperation) {
43488
43508
  const zones = this.pastedZones(target, width, height);
43489
43509
  const newZone = isCutOperation ? zones[0] : union(...zones);
43510
+ // we want grid selection to capture the selection stream
43511
+ this.selection.getBackToDefault();
43490
43512
  this.selection.selectZone({ cell: { col, row }, zone: newZone }, { scrollIntoView: false });
43491
43513
  }
43492
43514
  }
@@ -44153,6 +44175,8 @@ class FindAndReplacePlugin extends UIPlugin {
44153
44175
  //modulo of negative value to be able to cycle in both directions with previous and next
44154
44176
  nextIndex = ((nextIndex % matches.length) + matches.length) % matches.length;
44155
44177
  this.selectedMatchIndex = nextIndex;
44178
+ // we want grid selection to capture the selection stream
44179
+ this.selection.getBackToDefault();
44156
44180
  this.selection.selectCell(matches[nextIndex].col, matches[nextIndex].row);
44157
44181
  for (let index = 0; index < this.searchMatches.length; index++) {
44158
44182
  this.searchMatches[index].selected = index === this.selectedMatchIndex;
@@ -45500,7 +45524,10 @@ class SelectionInputsManagerPlugin extends UIPlugin {
45500
45524
  };
45501
45525
  this.selection.capture(input, anchor, {
45502
45526
  handleEvent: input.handleEvent.bind(input),
45503
- release: () => (this.focusedInputId = null),
45527
+ release: () => {
45528
+ this.focusedInputId = null;
45529
+ input.focusedRangeIndex = null;
45530
+ },
45504
45531
  });
45505
45532
  this.focusedInputId = id;
45506
45533
  }
@@ -46681,6 +46708,8 @@ class ClipboardOsState extends ClipboardCellsAbstractState {
46681
46708
  right: activeCol + numberOfCols - 1,
46682
46709
  bottom: activeRow + numberOfRows - 1,
46683
46710
  };
46711
+ // we want grid selection to capture the selection stream
46712
+ this.selection.getBackToDefault();
46684
46713
  this.selection.selectZone({ cell: { col: activeCol, row: activeRow }, zone }, { scrollIntoView: false });
46685
46714
  }
46686
46715
  getClipboardContent() {
@@ -55869,6 +55898,6 @@ exports.setTranslationMethod = setTranslationMethod;
55869
55898
  exports.tokenize = tokenize;
55870
55899
 
55871
55900
 
55872
- __info__.version = "17.0.1";
55873
- __info__.date = "2023-11-02T09:35:50.522Z";
55874
- __info__.hash = "0887d5b";
55901
+ __info__.version = "17.1.0-alpha.1";
55902
+ __info__.date = "2023-11-02T09:35:10.532Z";
55903
+ __info__.hash = "3b1fe3b";
@@ -7205,6 +7205,7 @@ declare class Composer extends Component<ComposerProps, SpreadsheetChildEnv> {
7205
7205
  private processTabKey;
7206
7206
  processSpaceKey(ev: KeyboardEvent): void;
7207
7207
  private processEnterKey;
7208
+ private processNewLineEvent;
7208
7209
  private processEscapeKey;
7209
7210
  private processF4Key;
7210
7211
  private processNumpadDecimal;