diff --git a/core/shortcut_items.js b/core/shortcut_items.js index 6f80f5648..0a99e1259 100644 --- a/core/shortcut_items.js +++ b/core/shortcut_items.js @@ -10,12 +10,10 @@ */ 'use strict'; -/** - * @name Blockly.ShortcutItems - * @namespace - */ -goog.provide('Blockly.ShortcutItems'); +goog.module('Blockly.ShortcutItems'); +goog.module.declareLegacyNamespace(); +goog.require('Blockly'); goog.require('Blockly.clipboard'); goog.require('Blockly.Gesture'); goog.require('Blockly.ShortcutRegistry'); @@ -29,7 +27,7 @@ goog.requireType('Blockly.ICopyable'); * Object holding the names of the default shortcut items. * @enum {string} */ -Blockly.ShortcutItems.names = { +const names = { ESCAPE: 'escape', DELETE: 'delete', COPY: 'copy', @@ -38,12 +36,13 @@ Blockly.ShortcutItems.names = { UNDO: 'undo', REDO: 'redo' }; +exports.names = names; /** Keyboard shortcut to hide chaff on escape. */ -Blockly.ShortcutItems.registerEscape = function() { +const registerEscape = function() { /** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ const escapeAction = { - name: Blockly.ShortcutItems.names.ESCAPE, + name: names.ESCAPE, preconditionFn: function (workspace) { return !workspace.options.readOnly; }, @@ -56,12 +55,13 @@ Blockly.ShortcutItems.registerEscape = function() { Blockly.ShortcutRegistry.registry.addKeyMapping( Blockly.utils.KeyCodes.ESC, escapeAction.name); }; +exports.registerEscape = registerEscape; /** Keyboard shortcut to delete a block on delete or backspace */ -Blockly.ShortcutItems.registerDelete = function() { +const registerDelete = function() { /** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ const deleteShortcut = { - name: Blockly.ShortcutItems.names.DELETE, + name: names.DELETE, preconditionFn: function (workspace) { return !workspace.options.readOnly && Blockly.selected && @@ -87,12 +87,13 @@ Blockly.ShortcutItems.registerDelete = function() { Blockly.ShortcutRegistry.registry.addKeyMapping( Blockly.utils.KeyCodes.BACKSPACE, deleteShortcut.name); }; +exports.registerDelete = registerDelete; /** Keyboard shortcut to copy a block on ctrl+c, cmd+c, or alt+c. */ -Blockly.ShortcutItems.registerCopy = function() { +const registerCopy = function() { /** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ const copyShortcut = { - name: Blockly.ShortcutItems.names.COPY, + name: names.COPY, preconditionFn: function (workspace) { return !workspace.options.readOnly && !Blockly.Gesture.inProgress() && @@ -123,12 +124,13 @@ Blockly.ShortcutItems.registerCopy = function() { Blockly.utils.KeyCodes.C, [Blockly.utils.KeyCodes.META]); Blockly.ShortcutRegistry.registry.addKeyMapping(metaC, copyShortcut.name); }; +exports.registerCopy = registerCopy; /** Keyboard shortcut to copy and delete a block on ctrl+x, cmd+x, or alt+x. */ -Blockly.ShortcutItems.registerCut = function() { +const registerCut = function() { /** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ const cutShortcut = { - name: Blockly.ShortcutItems.names.CUT, + name: names.CUT, preconditionFn: function (workspace) { return !workspace.options.readOnly && !Blockly.Gesture.inProgress() && @@ -158,12 +160,13 @@ Blockly.ShortcutItems.registerCut = function() { Blockly.utils.KeyCodes.X, [Blockly.utils.KeyCodes.META]); Blockly.ShortcutRegistry.registry.addKeyMapping(metaX, cutShortcut.name); }; +exports.registerCut = registerCut; /** Keyboard shortcut to paste a block on ctrl+v, cmd+v, or alt+v. */ -Blockly.ShortcutItems.registerPaste = function() { +const registerPaste = function() { /** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ const pasteShortcut = { - name: Blockly.ShortcutItems.names.PASTE, + name: names.PASTE, preconditionFn: function (workspace) { return !workspace.options.readOnly && !Blockly.Gesture.inProgress(); }, @@ -186,12 +189,13 @@ Blockly.ShortcutItems.registerPaste = function() { Blockly.utils.KeyCodes.V, [Blockly.utils.KeyCodes.META]); Blockly.ShortcutRegistry.registry.addKeyMapping(metaV, pasteShortcut.name); }; +exports.registerPaste = registerPaste; /** Keyboard shortcut to undo the previous action on ctrl+z, cmd+z, or alt+z. */ -Blockly.ShortcutItems.registerUndo = function() { +const registerUndo = function() { /** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ const undoShortcut = { - name: Blockly.ShortcutItems.names.UNDO, + name: names.UNDO, preconditionFn: function (workspace) { return !workspace.options.readOnly && !Blockly.Gesture.inProgress(); @@ -217,12 +221,13 @@ Blockly.ShortcutItems.registerUndo = function() { Blockly.utils.KeyCodes.Z, [Blockly.utils.KeyCodes.META]); Blockly.ShortcutRegistry.registry.addKeyMapping(metaZ, undoShortcut.name); }; +exports.registerUndo = registerUndo; /** Keyboard shortcut to redo the previous action on ctrl+shift+z, cmd+shift+z, or alt+shift+z. */ -Blockly.ShortcutItems.registerRedo = function() { +const registerRedo = function() { /** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ const redoShortcut = { - name: Blockly.ShortcutItems.names.REDO, + name: names.REDO, preconditionFn: function (workspace) { return !Blockly.Gesture.inProgress() && !workspace.options.readOnly; }, @@ -257,20 +262,22 @@ Blockly.ShortcutItems.registerRedo = function() { Blockly.utils.KeyCodes.Y, [Blockly.utils.KeyCodes.CTRL]); Blockly.ShortcutRegistry.registry.addKeyMapping(ctrlY, redoShortcut.name); }; +exports.registerRedo = registerRedo; /** * Registers all default keyboard shortcut item. This should be called once per instance of * KeyboardShortcutRegistry. - * @package */ -Blockly.ShortcutItems.registerDefaultShortcuts = function() { - Blockly.ShortcutItems.registerEscape(); - Blockly.ShortcutItems.registerDelete(); - Blockly.ShortcutItems.registerCopy(); - Blockly.ShortcutItems.registerCut(); - Blockly.ShortcutItems.registerPaste(); - Blockly.ShortcutItems.registerUndo(); - Blockly.ShortcutItems.registerRedo(); +const registerDefaultShortcuts = function() { + registerEscape(); + registerDelete(); + registerCopy(); + registerCut(); + registerPaste(); + registerUndo(); + registerRedo(); }; +/** @package */ +exports.registerDefaultShortcuts = registerDefaultShortcuts; -Blockly.ShortcutItems.registerDefaultShortcuts(); +registerDefaultShortcuts(); diff --git a/tests/deps.js b/tests/deps.js index e250dc441..0b2e55f2c 100644 --- a/tests/deps.js +++ b/tests/deps.js @@ -162,7 +162,7 @@ goog.addDependency('../../core/renderers/zelos/renderer.js', ['Blockly.zelos.Ren goog.addDependency('../../core/requires.js', ['Blockly.requires'], ['Blockly', 'Blockly.Comment', 'Blockly.ContextMenuItems', 'Blockly.FieldAngle', 'Blockly.FieldCheckbox', 'Blockly.FieldColour', 'Blockly.FieldDropdown', 'Blockly.FieldImage', 'Blockly.FieldLabelSerializable', 'Blockly.FieldMultilineInput', 'Blockly.FieldNumber', 'Blockly.FieldTextInput', 'Blockly.FieldVariable', 'Blockly.FlyoutButton', 'Blockly.Generator', 'Blockly.HorizontalFlyout', 'Blockly.Mutator', 'Blockly.ShortcutItems', 'Blockly.Themes.Classic', 'Blockly.Toolbox', 'Blockly.Trashcan', 'Blockly.VariablesDynamic', 'Blockly.VerticalFlyout', 'Blockly.Warning', 'Blockly.ZoomControls', 'Blockly.geras.Renderer', 'Blockly.thrasos.Renderer', 'Blockly.zelos.Renderer']); goog.addDependency('../../core/scrollbar.js', ['Blockly.Scrollbar'], ['Blockly.Touch', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/scrollbar_pair.js', ['Blockly.ScrollbarPair'], ['Blockly.Events', 'Blockly.Scrollbar', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.clipboard', 'Blockly.utils.KeyCodes']); +goog.addDependency('../../core/shortcut_items.js', ['Blockly.ShortcutItems'], ['Blockly', 'Blockly.Gesture', 'Blockly.ShortcutRegistry', 'Blockly.clipboard', 'Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/shortcut_registry.js', ['Blockly.ShortcutRegistry'], ['Blockly.utils.KeyCodes', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme.js', ['Blockly.Theme'], ['Blockly.registry', 'Blockly.utils.object'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../core/theme/classic.js', ['Blockly.Themes.Classic'], ['Blockly.Theme']);