mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
* fix: convert files to typescript * fix: add alias for AnyDuringMigration so that tsc will run * chore: format * chore: enable ts for the clang-format workflow (#6233) * chore: Restore @fileoverview comment locations (#6237) * chore: add declareModuleId (#6238) * fix: Revert comment change to app_controller.js (#6241) * fix: Add missing import goog statements (#6240) I've added the import statement immediately before the goog.declareModuleId calls that depend on it. There is an argument to be made that we should put the import statement in their normal place amongst any other imports, and move the declareModuleId statement to below the double blank line below the imports, but as these are so tightly coupled, replace the previous goog.module calls, and will both be deleted at the same time once the transition to TypeScript is fully complete I think it's fine (and certainly much easier) to do it this way. * chore: Fix whitespace (#6243) * fix: Remove spurious blank lines Remove extraneous blank lines introduced by deletion of 'use strict'; pragmas. Also fix the location of the goog.declareModuleId call in core/utils/array.ts. * fix: Add missing double-blank-line before body of modules Our convention is to have two blank lines between the imports (or module ID, if there are no imports) and the beginning of the body of the module. Enforce this. * fix: one addition format error for PR #6243 * fix(build): Skip npm prepare when running in CI (#6244) Have npm prepare do nothing when running in CI. We don't need to do any building, because npm test will build everything needed in the workflows in which it is run, and we don't want to build anything in other workflows because a tsc error would prevent those workflows from completing. * fix: re-add `@package` annotations as `@internal` annotations (#6232) * fix: add ~70% of internal attributes * fix: work on manually adding more @internal annotations * fix: add more manual internal annotations * fix: rename package typos to internal * fix: final manual fixes for internal annotations * chore: format * chore: make unnecessary multiline jsdoc a single line * fix: fix internal tags in serialization exceptions * fix: tsc errors picked up from develop (#6224) * fix: relative path for deprecation utils * fix: checking if properties exist in svg_math * fix: set all timeout PIDs to AnyDuringMigration * fix: make nullability errors explicity in block drag surface * fix: make null check in events_block_change explicit * fix: make getEventWorkspace_ internal so we can access it from CommentCreateDeleteHelper * fix: rename DIV -> containerDiv in tooltip * fix: ignore backwards compat check in category * fix: set block styles to AnyDuringMigration * fix: type typo in KeyboardShortcut * fix: constants name in row measurables * fix: typecast in mutator * fix: populateProcedures type of flattened array * fix: ignore errors related to workspace comment deserialization * chore: format files * fix: renaming imports missing file extensions * fix: remove check for sound.play * fix: temporarily remove bad requireType. All `export type` statements are stripped when tsc is run. This means that when we attempt to require BlockDefinition from the block files, we get an error because it does not exist. We decided to temporarily remove the require, because this will no longer be a problem when we conver the blocks to typescript, and everything gets compiled together. * fix: bad jsdoc in array * fix: silence missing property errors Closure was complaining about inexistant properties, but they actually do exist, they're just not being transpiled by tsc in a way that closure understands. I.E. if things are initialized in a function called by the constructor, rather than in a class field or in the custructor itself, closure would error. It would also error on enums, because they are transpiled to a weird IIFE. * fix: context menu action handler not knowing the type of this. this: TypeX information gets stripped when tsc is run, so closure could not know that this was not global. Fixed this by reorganizing to use the option object directly instead of passing it to onAction to be bound to this. * fix: readd getDeveloperVars checks (should not be part of migration) This was found because ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE was no longer being accessed. * fix: silence closure errors about overriding supertype props We propertly define the overrides in typescript, but these get removed from the compiled output, so closure doesn't know they exist. * fix: silence globalThis errors this: TypeX annotations get stripped from the compiled output, so closure can't know that we're accessing the correct things. However, typescript makes sure that this always has the correct properties, so silencing this should be fine. * fix: bad jsdoc name * chore: attempt compiling with blockly.js * fix: attempt moving the import statement above the namespace line * chore: add todo comments to block def files * chore: remove todo from context menu * chore: add comments abotu disabled errors * chore: move comments back to their correct positions (#6249) * fix: work on fixing comments * chore: finish moving all comments * chore: format * chore: move some other messed up comments * chore: format * fix: Correct enum formatting, use merged `namespace`s for types that are class static members (#6246) * fix: formatting of enum KeyCodes * fix: Use merged namespace for ContextMenuRegistry static types - Create a namespace to be merged with the ContextMenuRegistry class containing the types that were formerly declared as static properties on that class. - Use type aliases to export them individually as well, for compatibility with the changes made by MigranTS (and/or @gonfunko) to how other modules in core/ now import these types. - Update renamings.json5 to reflect the availability of the direct exports for modules that import this module directly (though they are not available to, and will not be used by, code that imports only via blockly.js/blockly.ts.) * fix: Use merged namespace for Input.Align - Create a merged namespace for the Input.Align enum. - Use type/const aliases to export it as Input too. - Update renamings.json5 to reflect the availability of the direct export. * fix: Use merged namespace for Names.NameType - Create a merged namespace for the Names.NameType enum. - Use type/const aliases to export it as NameType too. - Update renamings.json5 to reflect the availability of the direct export. (This ought to have happened in an earlier version as it was already available by both routes.) * chore: Fix minor issues for PR #6246 - Use `Align` instead of `Input.Align` where possible. * fix(build): Suppress irrelevant JSC_UNUSED_LOCAL_ASSIGNMENT errors tsc generates code for merged namespaces that looks like: (function (ClassName) { let EnumName; (function (EnumName) { EnumName[EnumNameAlign["v1"] = 0] = "v1"; // etc. })(EnumName = ClassName.EnumName || (ClassName.EnumName = {})); })(ClassName || (ClassName = {})); and Closure Compiler complains about the fact that the EnumName let binding is initialised but never used. (It exists so that any other code that was in the namespace could see the enum.) Suppress this message, since it is not actionable and lint and/or tsc should tell us if we have actual unused variables in our .ts files. * chore(build): Suppress spurious warnings from closure-make-deps (#6253) A little bit of an ugly hack, but it works: pipe stderr through grep -v to suppress error output starting with "WARNING in". * fix: remaining enums that weren't properly exported (#6251) * fix: remaining enums that weren't properly exported * chore: format * fix: add enum value exports * chore: format * fix: properly export interfaces that were typedefs (#6250) * fix: properly export interfaces that were typedefs * fix: allowCollsion -> allowCollision * fix: convert unconverted enums * fix: enums that were/are instance properties * fix: revert changes to property enums * fix: renamed protected parameter properties (#6252) * fix: bad protected parameter properties * chore:format * fix: gesture constructor * fix: overridden properties that were renamed * refactor: Migrate `blockly.js` to TypeScript (#6261) * chore: Apply changes to blockly.js to blockly.ts * fix: Build using core/blockly.ts instead of .js Compiles and runs in compressed mode correctly! * fix(build): Don't depend on execSync running bash (#6262) For some reason on Github CI servers execSync uses /bin/sh, which is (on Ubuntu) dash rather than bash, and does not understand the pipefail option. So remove the grep pipe on stderr and just discard all error output at all. This is not ideal as errors in test deps will go unreported AND not even cause test failure, but it's not clear that it's worth investing more time to fix this at the moment. * chore: use `import type` where possible (#6279) * chore: automatically change imports to import types * chore: revert changes that actually need to be imports * chore: format * chore: add more import type statements based on importsNotUsedAsValues * chore: fix tsconfig * chore: add link to compiler issue * fix: add type information to blockly options (#6283) * fix: add type information to blockly options * chore: format * chore: remove erroneous comment * fix: bugs revealed by getting the built output working (#6282) * fix: types of compose and decompose in block * fix: workspace naming in toolbox * chore: add jsdoc * chore: restore registry comments to better positions * chore: pr comments' * fix(variables): Revert inadvertent change to allDeveloperVariables (#6290) It appears that a function call got modified incorrectly (probably in an effort to fix a typing issue). This fix trivially reverts the line in question to match the original JS version from develop. This causes the generator tests to pass. * fix: circular dependencies (#6281) * chore: fix circular dependencies w/ static workspace funcs * remove preserved imports that aren't currently necessary (probably) * fix circular dependency with workspaces and block using stub * fix dependency between variables and xml by moving function to utils * add stub for trashcan as well * fix line endings from rebase * fix goog/base order * add trashcan patch * fix: types of compose and decompose in block * fix: workspace naming in toolbox * chore: add jsdoc * chore: restore registry comments to better positions * chore: remove implementations in goog.js * chore: fix types of stubs * chore: remove added AnyDuringMigration casts * chore: remove modifications to xml and variables * chore: format * chore: remove event requirements in workspace comments * chore: fix circular dependency with xml and workspace comments * fixup remove ContextMenu import * chore: fix dependency between mutator and workspace * chore: break circular dependency between names and procedures * chore: get tests to run? * chore: pr comments' * chore: fix stubbing field registry fromJson * chore: fix spying on fire * chore: fix stubbing parts of connection checker * chore: fix stubbing dialog * chore: fix stubbing style * chore: fix spying on duplicate * chore: fix stubbing variables * chore: fix stubbing copy * chore: fix stubbing in workspace * chore: remove unnecessary stubs * chore: fix formatting * chore: fix other formatting * chore: add backwards compatible static properties to workspace * chore: move static type properties * chore: move and comment stubs * chore: add newlines at EOF * chore: improve errors for monkey patched functions * chore: update comment with a pointer to the doc * chore: update comment with a pointer to the doc * chore: format * chore: revert changes to playground used for testing (#6292) * chore: get mocha tests to pass. (#6291) * chore: fix undo and empty code blocks * chore: skip IE test * chore: fix gesture test * chore: fix replace message references test * chore: fix string table interpolation * chore: skip getById tests * chore: fix field tests * chore: fix console errors by making workspace nullable * chore: format * chore: fix definition overwrite warning * chore: update metadata * chore: temporarily modify the the advanced compile test * chore: fix gestures by fixing test instead Co-authored-by: Neil Fraser <fraser@google.com> Co-authored-by: Christopher Allen <cpcallen+git@google.com>
450 lines
13 KiB
TypeScript
450 lines
13 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Blockly menu similar to Closure's goog.ui.Menu
|
|
*/
|
|
|
|
/**
|
|
* Blockly menu similar to Closure's goog.ui.Menu
|
|
* @class
|
|
*/
|
|
import * as goog from '../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.Menu');
|
|
|
|
import * as browserEvents from './browser_events.js';
|
|
import type {MenuItem} from './menuitem.js';
|
|
import * as aria from './utils/aria.js';
|
|
import {Coordinate} from './utils/coordinate.js';
|
|
import * as dom from './utils/dom.js';
|
|
import {KeyCodes} from './utils/keycodes.js';
|
|
import type {Size} from './utils/size.js';
|
|
import * as style from './utils/style.js';
|
|
|
|
|
|
/**
|
|
* A basic menu class.
|
|
* @alias Blockly.Menu
|
|
*/
|
|
export class Menu {
|
|
/**
|
|
* Array of menu items.
|
|
* (Nulls are never in the array, but typing the array as nullable prevents
|
|
* the compiler from objecting to .indexOf(null))
|
|
*/
|
|
private readonly menuItems_: MenuItem[] = [];
|
|
|
|
/**
|
|
* Coordinates of the mousedown event that caused this menu to open. Used to
|
|
* prevent the consequent mouseup event due to a simple click from
|
|
* activating a menu item immediately.
|
|
*/
|
|
openingCoords: Coordinate|null = null;
|
|
|
|
/**
|
|
* This is the element that we will listen to the real focus events on.
|
|
* A value of null means no menu item is highlighted.
|
|
*/
|
|
private highlightedItem_: MenuItem|null = null;
|
|
|
|
/** Mouse over event data. */
|
|
private mouseOverHandler_: browserEvents.Data|null = null;
|
|
|
|
/** Click event data. */
|
|
private clickHandler_: browserEvents.Data|null = null;
|
|
|
|
/** Mouse enter event data. */
|
|
private mouseEnterHandler_: browserEvents.Data|null = null;
|
|
|
|
/** Mouse leave event data. */
|
|
private mouseLeaveHandler_: browserEvents.Data|null = null;
|
|
|
|
/** Key down event data. */
|
|
private onKeyDownHandler_: browserEvents.Data|null = null;
|
|
|
|
/** The menu's root DOM element. */
|
|
private element_: HTMLDivElement|null = null;
|
|
|
|
/** ARIA name for this menu. */
|
|
private roleName_: aria.Role|null = null;
|
|
|
|
/** Constructs a new Menu instance. */
|
|
constructor() {}
|
|
|
|
/**
|
|
* Add a new menu item to the bottom of this menu.
|
|
* @param menuItem Menu item to append.
|
|
* @internal
|
|
*/
|
|
addChild(menuItem: MenuItem) {
|
|
this.menuItems_.push(menuItem);
|
|
}
|
|
|
|
/**
|
|
* Creates the menu DOM.
|
|
* @param container Element upon which to append this menu.
|
|
*/
|
|
render(container: Element) {
|
|
const element = (document.createElement('div'));
|
|
// goog-menu is deprecated, use blocklyMenu. May 2020.
|
|
element.className = 'blocklyMenu goog-menu blocklyNonSelectable';
|
|
element.tabIndex = 0;
|
|
if (this.roleName_) {
|
|
aria.setRole(element, this.roleName_);
|
|
}
|
|
this.element_ = element;
|
|
|
|
// Add menu items.
|
|
for (let i = 0, menuItem; menuItem = this.menuItems_[i]; i++) {
|
|
element.appendChild(menuItem.createDom());
|
|
}
|
|
|
|
// Add event handlers.
|
|
this.mouseOverHandler_ = browserEvents.conditionalBind(
|
|
element, 'mouseover', this, this.handleMouseOver_, true);
|
|
this.clickHandler_ = browserEvents.conditionalBind(
|
|
element, 'click', this, this.handleClick_, true);
|
|
this.mouseEnterHandler_ = browserEvents.conditionalBind(
|
|
element, 'mouseenter', this, this.handleMouseEnter_, true);
|
|
this.mouseLeaveHandler_ = browserEvents.conditionalBind(
|
|
element, 'mouseleave', this, this.handleMouseLeave_, true);
|
|
this.onKeyDownHandler_ = browserEvents.conditionalBind(
|
|
element, 'keydown', this, this.handleKeyEvent_);
|
|
|
|
container.appendChild(element);
|
|
}
|
|
|
|
/**
|
|
* Gets the menu's element.
|
|
* @return The DOM element.
|
|
* @internal
|
|
*/
|
|
getElement(): Element|null {
|
|
return this.element_;
|
|
}
|
|
|
|
/**
|
|
* Focus the menu element.
|
|
* @internal
|
|
*/
|
|
focus() {
|
|
const el = this.getElement();
|
|
if (el) {
|
|
// AnyDuringMigration because: Property 'focus' does not exist on type
|
|
// 'Element'.
|
|
(el as AnyDuringMigration).focus({preventScroll: true});
|
|
dom.addClass(el, 'blocklyFocused');
|
|
}
|
|
}
|
|
|
|
/** Blur the menu element. */
|
|
private blur_() {
|
|
const el = this.getElement();
|
|
if (el) {
|
|
// AnyDuringMigration because: Property 'blur' does not exist on type
|
|
// 'Element'.
|
|
(el as AnyDuringMigration).blur();
|
|
dom.removeClass(el, 'blocklyFocused');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Set the menu accessibility role.
|
|
* @param roleName role name.
|
|
* @internal
|
|
*/
|
|
setRole(roleName: aria.Role) {
|
|
this.roleName_ = roleName;
|
|
}
|
|
|
|
/** Dispose of this menu. */
|
|
dispose() {
|
|
// Remove event handlers.
|
|
if (this.mouseOverHandler_) {
|
|
browserEvents.unbind(this.mouseOverHandler_);
|
|
this.mouseOverHandler_ = null;
|
|
}
|
|
if (this.clickHandler_) {
|
|
browserEvents.unbind(this.clickHandler_);
|
|
this.clickHandler_ = null;
|
|
}
|
|
if (this.mouseEnterHandler_) {
|
|
browserEvents.unbind(this.mouseEnterHandler_);
|
|
this.mouseEnterHandler_ = null;
|
|
}
|
|
if (this.mouseLeaveHandler_) {
|
|
browserEvents.unbind(this.mouseLeaveHandler_);
|
|
this.mouseLeaveHandler_ = null;
|
|
}
|
|
if (this.onKeyDownHandler_) {
|
|
browserEvents.unbind(this.onKeyDownHandler_);
|
|
this.onKeyDownHandler_ = null;
|
|
}
|
|
|
|
// Remove menu items.
|
|
for (let i = 0, menuItem; menuItem = this.menuItems_[i]; i++) {
|
|
menuItem.dispose();
|
|
}
|
|
this.element_ = null;
|
|
}
|
|
|
|
// Child component management.
|
|
|
|
/**
|
|
* Returns the child menu item that owns the given DOM element,
|
|
* or null if no such menu item is found.
|
|
* @param elem DOM element whose owner is to be returned.
|
|
* @return Menu item for which the DOM element belongs to.
|
|
*/
|
|
private getMenuItem_(elem: Element): MenuItem|null {
|
|
const menuElem = this.getElement();
|
|
// Node might be the menu border (resulting in no associated menu item), or
|
|
// a menu item's div, or some element within the menu item.
|
|
// Walk up parents until one meets either the menu's root element, or
|
|
// a menu item's div.
|
|
while (elem && elem !== menuElem) {
|
|
if (dom.hasClass(elem, 'blocklyMenuItem')) {
|
|
// Having found a menu item's div, locate that menu item in this menu.
|
|
for (let i = 0, menuItem; menuItem = this.menuItems_[i]; i++) {
|
|
if (menuItem.getElement() === elem) {
|
|
return menuItem;
|
|
}
|
|
}
|
|
}
|
|
// AnyDuringMigration because: Type 'HTMLElement | null' is not
|
|
// assignable to type 'Element'.
|
|
elem = elem.parentElement as AnyDuringMigration;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Highlight management.
|
|
|
|
/**
|
|
* Highlights the given menu item, or clears highlighting if null.
|
|
* @param item Item to highlight, or null.
|
|
* @internal
|
|
*/
|
|
setHighlighted(item: MenuItem|null) {
|
|
const currentHighlighted = this.highlightedItem_;
|
|
if (currentHighlighted) {
|
|
currentHighlighted.setHighlighted(false);
|
|
this.highlightedItem_ = null;
|
|
}
|
|
if (item) {
|
|
item.setHighlighted(true);
|
|
this.highlightedItem_ = item;
|
|
// Bring the highlighted item into view. This has no effect if the menu is
|
|
// not scrollable.
|
|
const el = this.getElement() as Element;
|
|
style.scrollIntoContainerView(item.getElement() as Element, el);
|
|
|
|
aria.setState(el, aria.State.ACTIVEDESCENDANT, item.getId());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Highlights the next highlightable item (or the first if nothing is
|
|
* currently highlighted).
|
|
* @internal
|
|
*/
|
|
highlightNext() {
|
|
// AnyDuringMigration because: Argument of type 'MenuItem | null' is not
|
|
// assignable to parameter of type 'MenuItem'.
|
|
const index =
|
|
this.menuItems_.indexOf(this.highlightedItem_ as AnyDuringMigration);
|
|
this.highlightHelper_(index, 1);
|
|
}
|
|
|
|
/**
|
|
* Highlights the previous highlightable item (or the last if nothing is
|
|
* currently highlighted).
|
|
* @internal
|
|
*/
|
|
highlightPrevious() {
|
|
// AnyDuringMigration because: Argument of type 'MenuItem | null' is not
|
|
// assignable to parameter of type 'MenuItem'.
|
|
const index =
|
|
this.menuItems_.indexOf(this.highlightedItem_ as AnyDuringMigration);
|
|
this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1);
|
|
}
|
|
|
|
/** Highlights the first highlightable item. */
|
|
private highlightFirst_() {
|
|
this.highlightHelper_(-1, 1);
|
|
}
|
|
|
|
/** Highlights the last highlightable item. */
|
|
private highlightLast_() {
|
|
this.highlightHelper_(this.menuItems_.length, -1);
|
|
}
|
|
|
|
/**
|
|
* Helper function that manages the details of moving the highlight among
|
|
* child menuitems in response to keyboard events.
|
|
* @param startIndex Start index.
|
|
* @param delta Step direction: 1 to go down, -1 to go up.
|
|
*/
|
|
private highlightHelper_(startIndex: number, delta: number) {
|
|
let index = startIndex + delta;
|
|
let menuItem;
|
|
while (menuItem = this.menuItems_[index]) {
|
|
if (menuItem.isEnabled()) {
|
|
this.setHighlighted(menuItem);
|
|
break;
|
|
}
|
|
index += delta;
|
|
}
|
|
}
|
|
|
|
// Mouse events.
|
|
|
|
/**
|
|
* Handles mouseover events. Highlight menuitems as the user hovers over them.
|
|
* @param e Mouse event to handle.
|
|
*/
|
|
private handleMouseOver_(e: Event) {
|
|
const menuItem = this.getMenuItem_(e.target as Element);
|
|
|
|
if (menuItem) {
|
|
if (menuItem.isEnabled()) {
|
|
if (this.highlightedItem_ !== menuItem) {
|
|
this.setHighlighted(menuItem);
|
|
}
|
|
} else {
|
|
this.setHighlighted(null);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles click events. Pass the event onto the child menuitem to handle.
|
|
* @param e Click event to handle.
|
|
*/
|
|
private handleClick_(e: Event) {
|
|
const oldCoords = this.openingCoords;
|
|
// Clear out the saved opening coords immediately so they're not used twice.
|
|
this.openingCoords = null;
|
|
// AnyDuringMigration because: Property 'clientX' does not exist on type
|
|
// 'Event'.
|
|
if (oldCoords && typeof (e as AnyDuringMigration).clientX === 'number') {
|
|
// AnyDuringMigration because: Property 'clientY' does not exist on type
|
|
// 'Event'. AnyDuringMigration because: Property 'clientX' does not exist
|
|
// on type 'Event'.
|
|
const newCoords = new Coordinate(
|
|
(e as AnyDuringMigration).clientX, (e as AnyDuringMigration).clientY);
|
|
if (Coordinate.distance(oldCoords, newCoords) < 1) {
|
|
// This menu was opened by a mousedown and we're handling the consequent
|
|
// click event. The coords haven't changed, meaning this was the same
|
|
// opening event. Don't do the usual behavior because the menu just
|
|
// popped up under the mouse and the user didn't mean to activate this
|
|
// item.
|
|
return;
|
|
}
|
|
}
|
|
|
|
const menuItem = this.getMenuItem_(e.target as Element);
|
|
if (menuItem) {
|
|
menuItem.performAction();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles mouse enter events. Focus the element.
|
|
* @param _e Mouse event to handle.
|
|
*/
|
|
private handleMouseEnter_(_e: Event) {
|
|
this.focus();
|
|
}
|
|
|
|
/**
|
|
* Handles mouse leave events. Blur and clear highlight.
|
|
* @param _e Mouse event to handle.
|
|
*/
|
|
private handleMouseLeave_(_e: Event) {
|
|
if (this.getElement()) {
|
|
this.blur_();
|
|
this.setHighlighted(null);
|
|
}
|
|
}
|
|
|
|
// Keyboard events.
|
|
|
|
/**
|
|
* Attempts to handle a keyboard event, if the menu item is enabled, by
|
|
* calling
|
|
* {@link handleKeyEventInternal_}.
|
|
* @param e Key event to handle.
|
|
*/
|
|
private handleKeyEvent_(e: Event) {
|
|
if (!this.menuItems_.length) {
|
|
// Empty menu.
|
|
return;
|
|
}
|
|
// AnyDuringMigration because: Property 'altKey' does not exist on type
|
|
// 'Event'. AnyDuringMigration because: Property 'metaKey' does not exist
|
|
// on type 'Event'. AnyDuringMigration because: Property 'ctrlKey' does not
|
|
// exist on type 'Event'. AnyDuringMigration because: Property 'shiftKey'
|
|
// does not exist on type 'Event'.
|
|
if ((e as AnyDuringMigration).shiftKey ||
|
|
(e as AnyDuringMigration).ctrlKey ||
|
|
(e as AnyDuringMigration).metaKey || (e as AnyDuringMigration).altKey) {
|
|
// Do not handle the key event if any modifier key is pressed.
|
|
return;
|
|
}
|
|
|
|
const highlighted = this.highlightedItem_;
|
|
// AnyDuringMigration because: Property 'keyCode' does not exist on type
|
|
// 'Event'.
|
|
switch ((e as AnyDuringMigration).keyCode) {
|
|
case KeyCodes.ENTER:
|
|
case KeyCodes.SPACE:
|
|
if (highlighted) {
|
|
highlighted.performAction();
|
|
}
|
|
break;
|
|
|
|
case KeyCodes.UP:
|
|
this.highlightPrevious();
|
|
break;
|
|
|
|
case KeyCodes.DOWN:
|
|
this.highlightNext();
|
|
break;
|
|
|
|
case KeyCodes.PAGE_UP:
|
|
case KeyCodes.HOME:
|
|
this.highlightFirst_();
|
|
break;
|
|
|
|
case KeyCodes.PAGE_DOWN:
|
|
case KeyCodes.END:
|
|
this.highlightLast_();
|
|
break;
|
|
|
|
default:
|
|
// Not a key the menu is interested in.
|
|
return;
|
|
}
|
|
// The menu used this key, don't let it have secondary effects.
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
}
|
|
|
|
/**
|
|
* Get the size of a rendered menu.
|
|
* @return Object with width and height properties.
|
|
* @internal
|
|
*/
|
|
getSize(): Size {
|
|
const menuDom = this.getElement();
|
|
const menuSize = style.getSize(menuDom as Element);
|
|
// Recalculate height for the total content, not only box height.
|
|
menuSize.height = menuDom!.scrollHeight;
|
|
return menuSize;
|
|
}
|
|
}
|