diff --git a/core/block.ts b/core/block.ts index 8ab73232ccc..499cdaef0e2 100644 --- a/core/block.ts +++ b/core/block.ts @@ -2102,8 +2102,13 @@ export class Block implements IASTNodeLocation, IDeletable { return msg; } } -export interface CommentModel { - text: string|null; - pinned: boolean; - size: Size; + +export namespace Block { + export interface CommentModel { + text: string|null; + pinned: boolean; + size: Size; + } } + +export type CommentModel = Block.CommentModel; diff --git a/core/component_manager.ts b/core/component_manager.ts index 8e048494ae9..a39130a4790 100644 --- a/core/component_manager.ts +++ b/core/component_manager.ts @@ -211,8 +211,14 @@ export class ComponentManager { return components; } } -export interface ComponentDatum { - component: IComponent; - capabilities: Array>; - weight: number; -} \ No newline at end of file + +export namespace ComponentManager { + /** An object storing component information. */ + export interface ComponentDatum { + component: IComponent; + capabilities: Array>; + weight: number; + } +} + +export type ComponentDatum = ComponentManager.ComponentDatum; \ No newline at end of file diff --git a/core/interfaces/i_copyable.ts b/core/interfaces/i_copyable.ts index a5a82028d36..20fec55c0bd 100644 --- a/core/interfaces/i_copyable.ts +++ b/core/interfaces/i_copyable.ts @@ -31,8 +31,13 @@ export interface ICopyable extends ISelectable { */ toCopyData: AnyDuringMigration; } -export interface CopyData { - saveInfo: AnyDuringMigration|Element; - source: WorkspaceSvg; - typeCounts: AnyDuringMigration|null; + +export namespace ICopyable { + export interface CopyData { + saveInfo: AnyDuringMigration|Element; + source: WorkspaceSvg; + typeCounts: AnyDuringMigration|null; + } } + +export type CopyData = ICopyable.CopyData; diff --git a/core/keyboard_nav/ast_node.ts b/core/keyboard_nav/ast_node.ts index dfc49dcc485..626290c4f01 100644 --- a/core/keyboard_nav/ast_node.ts +++ b/core/keyboard_nav/ast_node.ts @@ -42,18 +42,6 @@ import {Workspace} from '../workspace.js'; * @alias Blockly.ASTNode */ export class ASTNode { - /** Object holding different types for an AST node. */ - static types = { - FIELD: 'field', - BLOCK: 'block', - INPUT: 'input', - OUTPUT: 'output', - NEXT: 'next', - PREVIOUS: 'previous', - STACK: 'stack', - WORKSPACE: 'workspace', - }; - /** * True to navigate to all fields. False to only navigate to clickable fields. */ @@ -694,10 +682,30 @@ export class ASTNode { return astNode; } } -export interface Params { - wsCoordinate: Coordinate; + +export namespace ASTNode { + export interface Params { + wsCoordinate: Coordinate; + } + + export enum types { + FIELD = 'field', + BLOCK = 'block', + INPUT = 'input', + OUTPUT = 'output', + NEXT = 'next', + PREVIOUS = 'previous', + STACK = 'stack', + WORKSPACE = 'workspace', + } } +export type Params = ASTNode.Params; +// No need to export ASTNode.types from the module at this time because (1) it +// wasn't automatically converted by the automatic migration script, (2) the +// name doesn't follow the styleguide. + + /** * Gets the parent connection on a block. * This is either an output connection, previous connection or undefined. diff --git a/core/metrics_manager.ts b/core/metrics_manager.ts index 69551e36839..dacb86d7f37 100644 --- a/core/metrics_manager.ts +++ b/core/metrics_manager.ts @@ -401,32 +401,56 @@ export class MetricsManager implements IMetricsManager { }; } } -export interface ToolboxMetrics { - width: number; - height: number; - position: toolboxUtils.Position; -} -export interface AbsoluteMetrics { - left: number; - top: number; -} -export interface ContainerRegion { - height: number; - width: number; - top: number; - left: number; -} -export interface FixedEdges { - top?: number; - bottom?: number; - left?: number; - right?: number; -} -export interface UiMetrics { - viewMetrics: ContainerRegion; - absoluteMetrics: AbsoluteMetrics; - toolboxMetrics: ToolboxMetrics; + +export namespace MetricsManager { + /** + * Describes the width, height and location of the toolbox on the main + * workspace. + */ + export interface ToolboxMetrics { + width: number; + height: number; + position: toolboxUtils.Position; + } + + /** Describes where the viewport starts in relation to the workspace SVG. */ + export interface AbsoluteMetrics { + left: number; + top: number; + } + + /** + * All the measurements needed to describe the size and location of a + * container. + */ + export interface ContainerRegion { + height: number; + width: number; + top: number; + left: number; + } + + /** Describes fixed edges of the workspace. */ + export interface FixedEdges { + top?: number; + bottom?: number; + left?: number; + right?: number; + } + + /** Common metrics used for UI elements. */ + export interface UiMetrics { + viewMetrics: ContainerRegion; + absoluteMetrics: AbsoluteMetrics; + toolboxMetrics: ToolboxMetrics; + } } +export type ToolboxMetrics = MetricsManager.ToolboxMetrics; +export type AbsoluteMetrics = MetricsManager.AbsoluteMetrics; +export type ContainerRegion = MetricsManager.ContainerRegion; +export type FixedEdges = MetricsManager.FixedEdges; +export type UiMetrics = MetricsManager.UiMetrics; + registry.register( registry.Type.METRICS_MANAGER, registry.DEFAULT, MetricsManager); diff --git a/core/options.ts b/core/options.ts index a03757fd76a..dd4c9024a47 100644 --- a/core/options.ts +++ b/core/options.ts @@ -429,27 +429,38 @@ export class Options { theme.name || 'builtin' + idGenerator.getNextUniqueId(), theme); } } -export interface GridOptions { - colour: string; - length: number; - snap: boolean; - spacing: number; -} -export interface MoveOptions { - drag: boolean; - scrollbars: boolean|ScrollbarOptions; - wheel: boolean; -} -export interface ScrollbarOptions { - horizontal: boolean; - vertical: boolean; -} -export interface ZoomOptions { - controls: boolean; - maxScale: number; - minScale: number; - pinch: boolean; - scaleSpeed: number; - startScale: number; - wheel: boolean; + +export namespace Options { + export interface GridOptions { + colour: string; + length: number; + snap: boolean; + spacing: number; + } + + export interface MoveOptions { + drag: boolean; + scrollbars: boolean|ScrollbarOptions; + wheel: boolean; + } + + export interface ScrollbarOptions { + horizontal: boolean; + vertical: boolean; + } + + export interface ZoomOptions { + controls: boolean; + maxScale: number; + minScale: number; + pinch: boolean; + scaleSpeed: number; + startScale: number; + wheel: boolean; + } } + +export type GridOptions = Options.GridOptions; +export type MoveOptions = Options.MoveOptions; +export type ScrollbarOptions = Options.ScrollbarOptions; +export type ZoomOptions = Options.ZoomOptions; diff --git a/core/renderers/common/constants.ts b/core/renderers/common/constants.ts index fcde186d09c..e359a01271d 100644 --- a/core/renderers/common/constants.ts +++ b/core/renderers/common/constants.ts @@ -399,8 +399,7 @@ export class ConstantProvider { */ INSERTION_MARKER_OPACITY = 0.2; - /** Enum for connection shapes. */ - SHAPES = {PUZZLE: 1, NOTCH: 2}; + SHAPES: {[key: string]: number} = {PUZZLE: 1, NOTCH: 2}; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. JAGGED_TEETH!: JaggedTeeth; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. diff --git a/core/shortcut_registry.ts b/core/shortcut_registry.ts index c8c73249a23..5091f6c721c 100644 --- a/core/shortcut_registry.ts +++ b/core/shortcut_registry.ts @@ -30,13 +30,6 @@ import {Workspace} from './workspace.js'; * @alias Blockly.ShortcutRegistry */ export class ShortcutRegistry { - /** Enum of valid modifiers. */ - static modifierKeys = { - 'Shift': KeyCodes.SHIFT, - 'Control': KeyCodes.CTRL, - 'Alt': KeyCodes.ALT, - 'Meta': KeyCodes.META, - }; static registry: AnyDuringMigration; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. private registry_!: {[key: string]: KeyboardShortcut}; @@ -326,15 +319,30 @@ export class ShortcutRegistry { } } -export interface KeyboardShortcut { - callback?: ((p1: Workspace, p2: Event, p3: KeyboardShortcut) => boolean); - name: string; - preconditionFn?: ((p1: Workspace) => boolean); - metadata?: object; - keyCodes?: (number|string)[]; - allowCollision?: boolean; +export namespace ShortcutRegistry { + export interface KeyboardShortcut { + callback?: ((p1: Workspace, p2: Event, p3: KeyboardShortcut) => boolean); + name: string; + preconditionFn?: ((p1: Workspace) => boolean); + metadata?: object; + keyCodes?: (number|string)[]; + allowCollision?: boolean; + } + + /** Supported modifiers. */ + export enum modifierKeys { + Shift = KeyCodes.SHIFT, + Control = KeyCodes.CTRL, + Alt = KeyCodes.ALT, + Meta = KeyCodes.META, + } } +export type KeyboardShortcut = ShortcutRegistry.KeyboardShortcut; +// No need to export ShorcutRegistry.modifierKeys from the module at this time +// because (1) it wasn't automatically converted by the automatic migration +// script, (2) the name doesn't follow the styleguide. + // Creates and assigns the singleton instance. const registry = new ShortcutRegistry(); ShortcutRegistry.registry = registry; diff --git a/core/theme.ts b/core/theme.ts index 38d8e5fb5de..d8355e054b8 100644 --- a/core/theme.ts +++ b/core/theme.ts @@ -166,35 +166,46 @@ export class Theme { return theme; } } -export interface BlockStyle { - colourPrimary: string; - colourSecondary: string; - colourTertiary: string; - hat?: string; -} -export interface CategoryStyle { - colour: string; -} -export interface ComponentStyle { - workspaceBackgroundColour: string|null; - toolboxBackgroundColour: string|null; - toolboxForegroundColour: string|null; - flyoutBackgroundColour: string|null; - flyoutForegroundColour: string|null; - flyoutOpacity: number|null; - scrollbarColour: string|null; - scrollbarOpacity: number|null; - insertionMarkerColour: string|null; - insertionMarkerOpacity: number|null; - markerColour: string|null; - cursorColour: string|null; - selectedGlowColour: string|null; - selectedGlowOpacity: number|null; - replacementGlowColour: string|null; - replacementGlowOpacity: number|null; -} -export interface FontStyle { - family: string|null; - weight: string|null; - size: number|null; + +export namespace Theme { + export interface BlockStyle { + colourPrimary: string; + colourSecondary: string; + colourTertiary: string; + hat?: string; + } + + export interface CategoryStyle { + colour: string; + } + + export interface ComponentStyle { + workspaceBackgroundColour: string|null; + toolboxBackgroundColour: string|null; + toolboxForegroundColour: string|null; + flyoutBackgroundColour: string|null; + flyoutForegroundColour: string|null; + flyoutOpacity: number|null; + scrollbarColour: string|null; + scrollbarOpacity: number|null; + insertionMarkerColour: string|null; + insertionMarkerOpacity: number|null; + markerColour: string|null; + cursorColour: string|null; + selectedGlowColour: string|null; + selectedGlowOpacity: number|null; + replacementGlowColour: string|null; + replacementGlowOpacity: number|null; + } + + export interface FontStyle { + family: string|null; + weight: string|null; + size: number|null; + } } + +export type BlockStyle = Theme.BlockStyle; +export type CategoryStyle = Theme.CategoryStyle; +export type ComponentStyle = Theme.ComponentStyle; +export type FontStyle = Theme.FontStyle; \ No newline at end of file diff --git a/core/theme_manager.ts b/core/theme_manager.ts index 48aea7e7660..2d3aa8caac0 100644 --- a/core/theme_manager.ts +++ b/core/theme_manager.ts @@ -185,7 +185,13 @@ export class ThemeManager { this.componentDB_ = null as AnyDuringMigration; } } -export interface Component { - element: Element; - propertyName: string; + +export namespace ThemeManager { + /** The type for a Blockly UI Component. */ + export interface Component { + element: Element; + propertyName: string; + } } + +export type Component = ThemeManager.Component; diff --git a/core/toolbox/category.ts b/core/toolbox/category.ts index e7c01ba0d4e..7ce582fc80e 100644 --- a/core/toolbox/category.ts +++ b/core/toolbox/category.ts @@ -585,17 +585,23 @@ export class ToolboxCategory extends ToolboxItem implements dom.removeNode(this.htmlDiv_); } } -export interface CssConfig { - container: string|undefined; - row: string|undefined; - rowcontentcontainer: string|undefined; - icon: string|undefined; - label: string|undefined; - selected: string|undefined; - openicon: string|undefined; - closedicon: string|undefined; + +export namespace ToolboxCategory { + /** All the CSS class names that are used to create a category. */ + export interface CssConfig { + container: string|undefined; + row: string|undefined; + rowcontentcontainer: string|undefined; + icon: string|undefined; + label: string|undefined; + selected: string|undefined; + openicon: string|undefined; + closedicon: string|undefined; + } } +export type CssConfig = ToolboxCategory.CssConfig; + /** CSS for Toolbox. See css.js for use. */ Css.register(` .blocklyTreeRow:not(.blocklyTreeSelected):hover { diff --git a/core/toolbox/collapsible_category.ts b/core/toolbox/collapsible_category.ts index 32e39e66fbb..f8a5adb205a 100644 --- a/core/toolbox/collapsible_category.ts +++ b/core/toolbox/collapsible_category.ts @@ -249,18 +249,28 @@ export class CollapsibleToolboxCategory extends ToolboxCategory implements return this.toolboxItems_; } } -export interface CssConfig { - container: string|null; - row: string|null; - rowcontentcontainer: string|null; - icon: string|null; - label: string|null; - selected: string|null; - openicon: string|null; - closedicon: string|null; - contents: string|null; + +export namespace CollapsibleToolboxCategory { + /** + * All the CSS class names that are used to create a collapsible + * category. This is all the properties from the regular category plus + * contents. + */ + export interface CssConfig { + container: string|null; + row: string|null; + rowcontentcontainer: string|null; + icon: string|null; + label: string|null; + selected: string|null; + openicon: string|null; + closedicon: string|null; + contents: string|null; + } } +export type CssConfig = CollapsibleToolboxCategory.CssConfig; + registry.register( registry.Type.TOOLBOX_ITEM, CollapsibleToolboxCategory.registrationName, CollapsibleToolboxCategory); diff --git a/core/toolbox/separator.ts b/core/toolbox/separator.ts index 14e73fe2bc8..43b2a1fb5fc 100644 --- a/core/toolbox/separator.ts +++ b/core/toolbox/separator.ts @@ -75,10 +75,15 @@ export class ToolboxSeparator extends ToolboxItem { dom.removeNode(this.htmlDiv_ as HTMLDivElement); } } -export interface CssConfig { - container: string|undefined; + +export namespace ToolboxSeparator { + export interface CssConfig { + container: string|undefined; + } } +export type CssConfig = ToolboxSeparator.CssConfig; + /** CSS for Toolbox. See css.js for use. */ Css.register(` .blocklyTreeSeparator {