UNPKG

@blockly/continuous-toolbox

Version:

A Blockly plugin that adds a continous-scrolling style toolbox and flyout

139 lines 4.84 kB
/** * @license * Copyright 2020 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * @fileoverview Flyout that supports always-open continuous scrolling. */ import * as Blockly from 'blockly/core'; import { RecyclableBlockFlyoutInflater } from './RecyclableBlockFlyoutInflater'; export interface LabelFlyoutItem extends Blockly.FlyoutItem { getElement(): Blockly.FlyoutButton; } /** * Class for continuous flyout. */ export declare class ContinuousFlyout extends Blockly.VerticalFlyout { /** * Target scroll position, used to smoothly scroll to a given category * location when selected. */ private scrollTarget?; /** * Map from category name to its position in the flyout. */ private scrollPositions; /** * The percentage of the distance to the scrollTarget that should be * scrolled at a time. Lower values will produce a smoother, slower scroll. */ protected scrollAnimationFraction: number; /** * Prevents the flyout from closing automatically when a block is dragged out. */ autoClose: boolean; /** * Creates a new ContinuousFlyout. * * @param workspaceOptions The injection options for the flyout's workspace. */ constructor(workspaceOptions: Blockly.Options); /** * Gets parent toolbox. * Since we registered the ContinuousToolbox, we know that's its type. * * @returns Toolbox that owns this flyout. */ private getParentToolbox; /** * Records scroll position for each category in the toolbox. * The scroll position is determined by the coordinates of each category's * label after the entire flyout has been rendered. */ private recordScrollPositions; /** * Validates and typechecks that the given toolbox item represents a label. * * @param item The toolbox item to check. * @returns True if the item represents a label in the flyout, and is a * Blockly.FlyoutButton. */ protected toolboxItemIsLabel(item: Blockly.FlyoutItem): item is LabelFlyoutItem; /** * Returns the scroll position for the given category name. * * @param name Category name. * @returns Scroll position for given category in workspace units, or null if * not found. */ getCategoryScrollPosition(name: string): number | null; /** * Selects an item in the toolbox based on the scroll position of the flyout. * * @param position Current scroll position of the workspace. */ private selectCategoryByScrollPosition; /** * Scrolls the flyout to given position. * * @param position The Y coordinate to scroll to. */ scrollTo(position: number): void; /** * Scrolls the flyout to display the given category at the top. * * @param category The toolbox category to scroll to in the flyout. */ scrollToCategory(category: Blockly.ISelectableToolboxItem): void; /** * Step the scrolling animation by scrolling a fraction of the way to * a scroll target, and request the next frame if necessary. */ private stepScrollAnimation; /** * Handles mouse wheel events. * * @param e The mouse wheel event to handle. */ protected wheel_(e: WheelEvent): void; /** * Calculates the additional padding needed at the bottom of the flyout in * order to make it possible to scroll to the top of the last category. * * @param contentMetrics Content metrics for the flyout. * @param viewMetrics View metrics for the flyout. * @returns The additional bottom padding needed. */ calculateBottomPadding(contentMetrics: Blockly.MetricsManager.ContainerRegion, viewMetrics: Blockly.MetricsManager.ContainerRegion): number; /** * Returns the X coordinate for the flyout's position. */ getX(): number; /** * Displays the given contents in the flyout. * * @param flyoutDef A string or JSON object specifying the contents of the * flyout. */ show(flyoutDef: Blockly.utils.toolbox.FlyoutDefinition | string): void; /** * Sets the function used to determine whether a block is recyclable. * * @param func The function used to determine if a block is recyclable. */ setBlockIsRecyclable(func: (block: Blockly.Block) => boolean): void; /** * Set whether the flyout can recycle blocks. * * @param isEnabled True to allow blocks to be recycled, false otherwise. */ setRecyclingEnabled(isEnabled: boolean): void; /** * Returns the recyclable block flyout inflater. * * @returns The recyclable inflater. */ protected getRecyclableInflater(): RecyclableBlockFlyoutInflater; } //# sourceMappingURL=ContinuousFlyout.d.ts.map