mirror of
https://github.com/google/blockly.git
synced 2026-01-12 03:17:09 +01:00
Migrate core/component_manager.js to goog.module
This commit is contained in:
@@ -11,7 +11,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.ComponentManager');
|
||||
goog.module('Blockly.ComponentManager');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
goog.requireType('Blockly.IAutoHideable');
|
||||
goog.requireType('Blockly.IComponent');
|
||||
@@ -24,10 +25,10 @@ goog.requireType('Blockly.IPositionable');
|
||||
* Manager for all items registered with the workspace.
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.ComponentManager = function() {
|
||||
const ComponentManager = function() {
|
||||
/**
|
||||
* A map of the components registered with the workspace, mapped to id.
|
||||
* @type {!Object<string, !Blockly.ComponentManager.ComponentDatum>}
|
||||
* @type {!Object<string, !ComponentManager.ComponentDatum>}
|
||||
* @private
|
||||
*/
|
||||
this.componentData_ = Object.create(null);
|
||||
@@ -45,21 +46,21 @@ Blockly.ComponentManager = function() {
|
||||
* @typedef {{
|
||||
* component: !Blockly.IComponent,
|
||||
* capabilities: (
|
||||
* !Array<string|!Blockly.ComponentManager.Capability<!Blockly.IComponent>>
|
||||
* !Array<string|!ComponentManager.Capability<!Blockly.IComponent>>
|
||||
* ),
|
||||
* weight: number
|
||||
* }}
|
||||
*/
|
||||
Blockly.ComponentManager.ComponentDatum;
|
||||
ComponentManager.ComponentDatum;
|
||||
|
||||
/**
|
||||
* Adds a component.
|
||||
* @param {!Blockly.ComponentManager.ComponentDatum} componentInfo The data for
|
||||
* @param {!ComponentManager.ComponentDatum} componentInfo The data for
|
||||
* the component to register.
|
||||
* @param {boolean=} opt_allowOverrides True to prevent an error when overriding
|
||||
* an already registered item.
|
||||
*/
|
||||
Blockly.ComponentManager.prototype.addComponent = function(
|
||||
ComponentManager.prototype.addComponent = function(
|
||||
componentInfo, opt_allowOverrides) {
|
||||
// Don't throw an error if opt_allowOverrides is true.
|
||||
const id = componentInfo.component.id;
|
||||
@@ -86,7 +87,7 @@ Blockly.ComponentManager.prototype.addComponent = function(
|
||||
* Removes a component.
|
||||
* @param {string} id The ID of the component to remove.
|
||||
*/
|
||||
Blockly.ComponentManager.prototype.removeComponent = function(id) {
|
||||
ComponentManager.prototype.removeComponent = function(id) {
|
||||
const componentInfo = this.componentData_[id];
|
||||
if (!componentInfo) {
|
||||
return;
|
||||
@@ -102,11 +103,11 @@ Blockly.ComponentManager.prototype.removeComponent = function(id) {
|
||||
/**
|
||||
* Adds a capability to a existing registered component.
|
||||
* @param {string} id The ID of the component to add the capability to.
|
||||
* @param {string|!Blockly.ComponentManager.Capability<T>} capability The
|
||||
* @param {string|!ComponentManager.Capability<T>} capability The
|
||||
* capability to add.
|
||||
* @template T
|
||||
*/
|
||||
Blockly.ComponentManager.prototype.addCapability = function(id, capability) {
|
||||
ComponentManager.prototype.addCapability = function(id, capability) {
|
||||
if (!this.getComponent(id)) {
|
||||
throw Error('Cannot add capability, "' + capability + '". Plugin "' +
|
||||
id + '" has not been added to the ComponentManager');
|
||||
@@ -124,11 +125,11 @@ Blockly.ComponentManager.prototype.addCapability = function(id, capability) {
|
||||
/**
|
||||
* Removes a capability from an existing registered component.
|
||||
* @param {string} id The ID of the component to remove the capability from.
|
||||
* @param {string|!Blockly.ComponentManager.Capability<T>} capability The
|
||||
* @param {string|!ComponentManager.Capability<T>} capability The
|
||||
* capability to remove.
|
||||
* @template T
|
||||
*/
|
||||
Blockly.ComponentManager.prototype.removeCapability = function(id, capability) {
|
||||
ComponentManager.prototype.removeCapability = function(id, capability) {
|
||||
if (!this.getComponent(id)) {
|
||||
throw Error('Cannot remove capability, "' + capability + '". Plugin "' +
|
||||
id + '" has not been added to the ComponentManager');
|
||||
@@ -148,12 +149,12 @@ Blockly.ComponentManager.prototype.removeCapability = function(id, capability) {
|
||||
/**
|
||||
* Returns whether the component with this id has the specified capability.
|
||||
* @param {string} id The ID of the component to check.
|
||||
* @param {string|!Blockly.ComponentManager.Capability<T>} capability The
|
||||
* @param {string|!ComponentManager.Capability<T>} capability The
|
||||
* capability to check for.
|
||||
* @return {boolean} Whether the component has the capability.
|
||||
* @template T
|
||||
*/
|
||||
Blockly.ComponentManager.prototype.hasCapability = function(id, capability) {
|
||||
ComponentManager.prototype.hasCapability = function(id, capability) {
|
||||
capability = String(capability).toLowerCase();
|
||||
return this.componentData_[id].capabilities.indexOf(capability) !== -1;
|
||||
};
|
||||
@@ -164,19 +165,19 @@ Blockly.ComponentManager.prototype.hasCapability = function(id, capability) {
|
||||
* @return {!Blockly.IComponent|undefined} The component with the given name
|
||||
* or undefined if not found.
|
||||
*/
|
||||
Blockly.ComponentManager.prototype.getComponent = function(id) {
|
||||
ComponentManager.prototype.getComponent = function(id) {
|
||||
return this.componentData_[id] && this.componentData_[id].component;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets all the components with the specified capability.
|
||||
* @param {string|!Blockly.ComponentManager.Capability<T>
|
||||
* @param {string|!ComponentManager.Capability<T>
|
||||
* } capability The capability of the component.
|
||||
* @param {boolean} sorted Whether to return list ordered by weights.
|
||||
* @return {!Array<T>} The components that match the specified capability.
|
||||
* @template T
|
||||
*/
|
||||
Blockly.ComponentManager.prototype.getComponents = function(capability, sorted) {
|
||||
ComponentManager.prototype.getComponents = function(capability, sorted) {
|
||||
capability = String(capability).toLowerCase();
|
||||
const componentIds = this.capabilityToComponentIds_[capability];
|
||||
if (!componentIds) {
|
||||
@@ -210,7 +211,7 @@ Blockly.ComponentManager.prototype.getComponents = function(capability, sorted)
|
||||
* @constructor
|
||||
* @template T
|
||||
*/
|
||||
Blockly.ComponentManager.Capability = function(name) {
|
||||
ComponentManager.Capability = function(name) {
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
@@ -223,22 +224,24 @@ Blockly.ComponentManager.Capability = function(name) {
|
||||
* @return {string} The name.
|
||||
* @override
|
||||
*/
|
||||
Blockly.ComponentManager.Capability.prototype.toString = function() {
|
||||
ComponentManager.Capability.prototype.toString = function() {
|
||||
return this.name_;
|
||||
};
|
||||
|
||||
/** @type {!Blockly.ComponentManager.Capability<!Blockly.IPositionable>} */
|
||||
Blockly.ComponentManager.Capability.POSITIONABLE =
|
||||
new Blockly.ComponentManager.Capability('positionable');
|
||||
/** @type {!ComponentManager.Capability<!Blockly.IPositionable>} */
|
||||
ComponentManager.Capability.POSITIONABLE =
|
||||
new ComponentManager.Capability('positionable');
|
||||
|
||||
/** @type {!Blockly.ComponentManager.Capability<!Blockly.IDragTarget>} */
|
||||
Blockly.ComponentManager.Capability.DRAG_TARGET =
|
||||
new Blockly.ComponentManager.Capability('drag_target');
|
||||
/** @type {!ComponentManager.Capability<!Blockly.IDragTarget>} */
|
||||
ComponentManager.Capability.DRAG_TARGET =
|
||||
new ComponentManager.Capability('drag_target');
|
||||
|
||||
/** @type {!Blockly.ComponentManager.Capability<!Blockly.IDeleteArea>} */
|
||||
Blockly.ComponentManager.Capability.DELETE_AREA =
|
||||
new Blockly.ComponentManager.Capability('delete_area');
|
||||
/** @type {!ComponentManager.Capability<!Blockly.IDeleteArea>} */
|
||||
ComponentManager.Capability.DELETE_AREA =
|
||||
new ComponentManager.Capability('delete_area');
|
||||
|
||||
/** @type {!Blockly.ComponentManager.Capability<!Blockly.IAutoHideable>} */
|
||||
Blockly.ComponentManager.Capability.AUTOHIDEABLE =
|
||||
new Blockly.ComponentManager.Capability('autohideable');
|
||||
/** @type {!ComponentManager.Capability<!Blockly.IAutoHideable>} */
|
||||
ComponentManager.Capability.AUTOHIDEABLE =
|
||||
new ComponentManager.Capability('autohideable');
|
||||
|
||||
exports = ComponentManager;
|
||||
|
||||
@@ -18,7 +18,7 @@ goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['
|
||||
goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']);
|
||||
goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']);
|
||||
goog.addDependency('../../core/comment.js', ['Blockly.Comment'], ['Blockly.Bubble', 'Blockly.Css', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BubbleOpen', 'Blockly.Icon', 'Blockly.Warning', 'Blockly.browserEvents', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']);
|
||||
goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], []);
|
||||
goog.addDependency('../../core/component_manager.js', ['Blockly.ComponentManager'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../core/connection.js', ['Blockly.Connection'], ['Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.IASTNodeLocationWithBlock', 'Blockly.Xml', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils.deprecation']);
|
||||
goog.addDependency('../../core/connection_checker.js', ['Blockly.ConnectionChecker'], ['Blockly.Connection', 'Blockly.IConnectionChecker', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.registry']);
|
||||
goog.addDependency('../../core/connection_db.js', ['Blockly.ConnectionDB'], ['Blockly.RenderedConnection', 'Blockly.connectionTypes', 'Blockly.constants']);
|
||||
|
||||
Reference in New Issue
Block a user