mirror of
https://github.com/google/blockly.git
synced 2026-01-08 01:20:12 +01:00
* fix(build): Restore erroneously-deleted filter function This was deleted in PR #7406 as it was mainly being used to filter core/ vs. test/mocha/ deps into separate deps files - but it turns out also to be used for filtering error messages too. Oops. * refactor(tests): Migrate advanced compilation test to ES Modules * refactor(build): Migrate main.js to TypeScript This turns out to be pretty straight forward, even if it would cause crashing if one actually tried to import this module instead of just feeding it to Closure Compiler. * chore(build): Remove goog.declareModuleId calls Replace goog.declareModuleId calls with a comment recording the former module ID for posterity (or at least until we decide how to reformat the renamings file. * chore(tests): Delete closure/goog/* For the moment we still need something to serve as base.js for the benefit of closure-make-deps, so we keep a vestigial base.js around, containing only the @provideGoog declaration. * refactor(build): Remove vestigial base.js By changing slightly the command line arguments to closure-make-deps and closure-calculate-chunks the need to have any base.js is eliminated. * chore: Typo fix for PR #7415
153 lines
3.8 KiB
TypeScript
153 lines
3.8 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* An item in the toolbox.
|
|
*
|
|
* @class
|
|
*/
|
|
// Former goog.module ID: Blockly.ToolboxItem
|
|
|
|
import type {ICollapsibleToolboxItem} from '../interfaces/i_collapsible_toolbox_item.js';
|
|
import type {IToolbox} from '../interfaces/i_toolbox.js';
|
|
import type {IToolboxItem} from '../interfaces/i_toolbox_item.js';
|
|
import * as idGenerator from '../utils/idgenerator.js';
|
|
import type * as toolbox from '../utils/toolbox.js';
|
|
import type {WorkspaceSvg} from '../workspace_svg.js';
|
|
|
|
/**
|
|
* Class for an item in the toolbox.
|
|
*/
|
|
export class ToolboxItem implements IToolboxItem {
|
|
protected id_: string;
|
|
protected parent_: ICollapsibleToolboxItem | null;
|
|
protected level_: number;
|
|
protected toolboxItemDef_: toolbox.ToolboxItemInfo | null;
|
|
protected workspace_: WorkspaceSvg;
|
|
/** The toolbox this category belongs to. */
|
|
protected readonly parentToolbox_: IToolbox;
|
|
|
|
/**
|
|
* @param toolboxItemDef The JSON defining the toolbox item.
|
|
* @param parentToolbox The toolbox that holds the toolbox item.
|
|
* @param opt_parent The parent toolbox item or null if the category does not
|
|
* have a parent.
|
|
*/
|
|
constructor(
|
|
toolboxItemDef: toolbox.ToolboxItemInfo,
|
|
parentToolbox: IToolbox,
|
|
opt_parent?: ICollapsibleToolboxItem,
|
|
) {
|
|
/** The ID for the category. */
|
|
this.id_ =
|
|
(toolboxItemDef as AnyDuringMigration)['toolboxitemid'] ||
|
|
idGenerator.getNextUniqueId();
|
|
|
|
/** The parent of the category. */
|
|
this.parent_ = opt_parent || null;
|
|
|
|
/** The level that the category is nested at. */
|
|
this.level_ = this.parent_ ? this.parent_.getLevel() + 1 : 0;
|
|
|
|
/** The JSON definition of the toolbox item. */
|
|
this.toolboxItemDef_ = toolboxItemDef;
|
|
|
|
this.parentToolbox_ = parentToolbox;
|
|
|
|
/** The workspace of the parent toolbox. */
|
|
this.workspace_ = this.parentToolbox_.getWorkspace();
|
|
}
|
|
|
|
/**
|
|
* Initializes the toolbox item.
|
|
* This includes creating the DOM and updating the state of any items based
|
|
* on the info object.
|
|
*/
|
|
init() {}
|
|
// No-op by default.
|
|
|
|
/**
|
|
* Gets the div for the toolbox item.
|
|
*
|
|
* @returns The div for the toolbox item.
|
|
*/
|
|
getDiv(): Element | null {
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Gets the HTML element that is clickable.
|
|
* The parent toolbox element receives clicks. The parent toolbox will add an
|
|
* ID to this element so it can pass the onClick event to the correct
|
|
* toolboxItem.
|
|
*
|
|
* @returns The HTML element that receives clicks, or null if this item should
|
|
* not receive clicks.
|
|
*/
|
|
getClickTarget(): Element | null {
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Gets a unique identifier for this toolbox item.
|
|
*
|
|
* @returns The ID for the toolbox item.
|
|
*/
|
|
getId(): string {
|
|
return this.id_;
|
|
}
|
|
|
|
/**
|
|
* Gets the parent if the toolbox item is nested.
|
|
*
|
|
* @returns The parent toolbox item, or null if this toolbox item is not
|
|
* nested.
|
|
*/
|
|
getParent(): ICollapsibleToolboxItem | null {
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Gets the nested level of the category.
|
|
*
|
|
* @returns The nested level of the category.
|
|
* @internal
|
|
*/
|
|
getLevel(): number {
|
|
return this.level_;
|
|
}
|
|
|
|
/**
|
|
* Whether the toolbox item is selectable.
|
|
*
|
|
* @returns True if the toolbox item can be selected.
|
|
*/
|
|
isSelectable(): boolean {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Whether the toolbox item is collapsible.
|
|
*
|
|
* @returns True if the toolbox item is collapsible.
|
|
*/
|
|
isCollapsible(): boolean {
|
|
return false;
|
|
}
|
|
|
|
/** Dispose of this toolbox item. No-op by default. */
|
|
dispose() {}
|
|
|
|
/**
|
|
* Sets whether the category is visible or not.
|
|
* For a category to be visible its parent category must also be expanded.
|
|
*
|
|
* @param _isVisible True if category should be visible.
|
|
*/
|
|
setVisible_(_isVisible: boolean) {}
|
|
}
|
|
// nop by default
|