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