mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
* Use goog.requireType when importing I* interfaces Interfaces have no code, so should never be referred to outside of (JSDoc) comments, and so the modules that define only interfaces never need to be goog.require'd - goog.requireType is always sufficient. This commit fixes imports of all modules whose name matches /(.*\.)?I[A-Z]*/ - i.e., the hungarian-notation named ones in core/interfaces/. * Use goog.requireType when only using import for type specifications Where a module is imported only to used in JSDoc comments it can (and should) be goog.requireType'd instead of goog.require'd. * Remove spurious eslint-disable no-unused-vars There were a few cases where modules were being imported with goog.require (because they are referred to in code, not just JSDoc comments) but were prefaced by a spurious eslint suppress. Remove these, restoring the invariant that an import gets an eslint if and only if it is a requireType. * Remove obsolete Closure Compiler error group stricterMissingRequire has been superceded by missingRequire, and now causes a Java null pointer exception if supplied.
155 lines
3.7 KiB
JavaScript
155 lines
3.7 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2020 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview An item in the toolbox.
|
|
* @author aschmiedt@google.com (Abby Schmiedt)
|
|
*/
|
|
'use strict';
|
|
|
|
goog.module('Blockly.ToolboxItem');
|
|
goog.module.declareLegacyNamespace();
|
|
|
|
/* eslint-disable-next-line no-unused-vars */
|
|
const ICollapsibleToolboxItem = goog.requireType('Blockly.ICollapsibleToolboxItem');
|
|
const IdGenerator = goog.require('Blockly.utils.IdGenerator');
|
|
/* eslint-disable-next-line no-unused-vars */
|
|
const IToolbox = goog.requireType('Blockly.IToolbox');
|
|
/* eslint-disable-next-line no-unused-vars */
|
|
const IToolboxItem = goog.requireType('Blockly.IToolboxItem');
|
|
/* eslint-disable-next-line no-unused-vars */
|
|
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
|
|
/* eslint-disable-next-line no-unused-vars */
|
|
const toolbox = goog.requireType('Blockly.utils.toolbox');
|
|
|
|
|
|
/**
|
|
* Class for an item in the toolbox.
|
|
* @param {!toolbox.ToolboxItemInfo} toolboxItemDef The JSON defining the
|
|
* toolbox item.
|
|
* @param {!IToolbox} toolbox The toolbox that holds the toolbox item.
|
|
* @param {ICollapsibleToolboxItem=} opt_parent The parent toolbox item
|
|
* or null if the category does not have a parent.
|
|
* @constructor
|
|
* @implements {IToolboxItem}
|
|
*/
|
|
const ToolboxItem = function(toolboxItemDef, toolbox, opt_parent) {
|
|
/**
|
|
* The id for the category.
|
|
* @type {string}
|
|
* @protected
|
|
*/
|
|
this.id_ = toolboxItemDef['toolboxitemid'] || IdGenerator.getNextUniqueId();
|
|
|
|
/**
|
|
* The parent of the category.
|
|
* @type {?ICollapsibleToolboxItem}
|
|
* @protected
|
|
*/
|
|
this.parent_ = opt_parent || null;
|
|
|
|
/**
|
|
* The level that the category is nested at.
|
|
* @type {number}
|
|
* @protected
|
|
*/
|
|
this.level_ = this.parent_ ? this.parent_.getLevel() + 1 : 0;
|
|
|
|
/**
|
|
* The JSON definition of the toolbox item.
|
|
* @type {!toolbox.ToolboxItemInfo}
|
|
* @protected
|
|
*/
|
|
this.toolboxItemDef_ = toolboxItemDef;
|
|
|
|
/**
|
|
* The toolbox this category belongs to.
|
|
* @type {!IToolbox}
|
|
* @protected
|
|
*/
|
|
this.parentToolbox_ = toolbox;
|
|
|
|
/**
|
|
* The workspace of the parent toolbox.
|
|
* @type {!WorkspaceSvg}
|
|
* @protected
|
|
*/
|
|
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.
|
|
* @public
|
|
*/
|
|
ToolboxItem.prototype.init = function() {
|
|
// No-op by default.
|
|
};
|
|
|
|
/**
|
|
* Gets the div for the toolbox item.
|
|
* @return {?Element} The div for the toolbox item.
|
|
* @public
|
|
*/
|
|
ToolboxItem.prototype.getDiv = function() {
|
|
return null;
|
|
};
|
|
|
|
/**
|
|
* Gets a unique identifier for this toolbox item.
|
|
* @return {string} The ID for the toolbox item.
|
|
* @public
|
|
*/
|
|
ToolboxItem.prototype.getId = function() {
|
|
return this.id_;
|
|
};
|
|
|
|
/**
|
|
* Gets the parent if the toolbox item is nested.
|
|
* @return {?IToolboxItem} The parent toolbox item, or null if
|
|
* this toolbox item is not nested.
|
|
* @public
|
|
*/
|
|
ToolboxItem.prototype.getParent = function() {
|
|
return null;
|
|
};
|
|
|
|
/**
|
|
* Gets the nested level of the category.
|
|
* @return {number} The nested level of the category.
|
|
* @package
|
|
*/
|
|
ToolboxItem.prototype.getLevel = function() {
|
|
return this.level_;
|
|
};
|
|
|
|
/**
|
|
* Whether the toolbox item is selectable.
|
|
* @return {boolean} True if the toolbox item can be selected.
|
|
* @public
|
|
*/
|
|
ToolboxItem.prototype.isSelectable = function() {
|
|
return false;
|
|
};
|
|
|
|
/**
|
|
* Whether the toolbox item is collapsible.
|
|
* @return {boolean} True if the toolbox item is collapsible.
|
|
* @public
|
|
*/
|
|
ToolboxItem.prototype.isCollapsible = function() {
|
|
return false;
|
|
};
|
|
|
|
/**
|
|
* Dispose of this toolbox item. No-op by default.
|
|
* @public
|
|
*/
|
|
ToolboxItem.prototype.dispose = function() {};
|
|
|
|
exports = ToolboxItem;
|