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