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