mirror of
https://github.com/google/blockly.git
synced 2026-03-09 14:50:09 +01:00
@@ -16,15 +16,16 @@ goog.provide('Blockly.fieldRegistry');
|
||||
|
||||
goog.require('Blockly.registry');
|
||||
|
||||
goog.requireType('Blockly.IRegistrableField');
|
||||
|
||||
|
||||
/**
|
||||
* Registers a field type.
|
||||
* Blockly.fieldRegistry.fromJson uses this registry to
|
||||
* find the appropriate field type.
|
||||
* @param {string} type The field type name as used in the JSON definition.
|
||||
* @param {?function(new:Blockly.Field, ...?)} fieldClass The field class
|
||||
* containing a fromJson function that can construct an instance of the
|
||||
* field.
|
||||
* @param {!Blockly.IRegistrableField} fieldClass The field class containing a
|
||||
* fromJson function that can construct an instance of the field.
|
||||
* @throws {Error} if the type name is empty, the field is already
|
||||
* registered, or the fieldClass is not an object containing a fromJson
|
||||
* function.
|
||||
@@ -52,14 +53,14 @@ Blockly.fieldRegistry.unregister = function(type) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.fieldRegistry.fromJson = function(options) {
|
||||
var fieldClass = /** @type {{fromJson:function(!Object):!Blockly.Field}} */ (
|
||||
Blockly.registry.getClass(Blockly.registry.Type.FIELD, options['type']));
|
||||
if (!fieldClass) {
|
||||
var fieldObject = /** @type {?Blockly.IRegistrableField} */ (
|
||||
Blockly.registry.getObject(Blockly.registry.Type.FIELD, options['type']));
|
||||
if (!fieldObject) {
|
||||
console.warn('Blockly could not create a field of type ' + options['type'] +
|
||||
'. The field is probably not being registered. This could be because' +
|
||||
' the file is not loaded, the field does not register itself (Issue' +
|
||||
' #1584), or the registration is not being reached.');
|
||||
return null;
|
||||
}
|
||||
return fieldClass.fromJson(options);
|
||||
return fieldObject.fromJson(options);
|
||||
};
|
||||
|
||||
15
core/icon.js
15
core/icon.js
@@ -31,6 +31,12 @@ Blockly.Icon = function(block) {
|
||||
* @protected
|
||||
*/
|
||||
this.block_ = block;
|
||||
|
||||
/**
|
||||
* The icon SVG group.
|
||||
* @type {?SVGGElement}
|
||||
*/
|
||||
this.iconGroup_ = null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -154,7 +160,8 @@ Blockly.Icon.prototype.setIconLocation = function(xy) {
|
||||
Blockly.Icon.prototype.computeIconLocation = function() {
|
||||
// Find coordinates for the centre of the icon and update the arrow.
|
||||
var blockXY = this.block_.getRelativeToSurfaceXY();
|
||||
var iconXY = Blockly.utils.getRelativeXY(this.iconGroup_);
|
||||
var iconXY = Blockly.utils.getRelativeXY(
|
||||
/** @type {!SVGElement} */ (this.iconGroup_));
|
||||
var newXY = new Blockly.utils.Coordinate(
|
||||
blockXY.x + iconXY.x + this.SIZE / 2,
|
||||
blockXY.y + iconXY.y + this.SIZE / 2);
|
||||
@@ -190,3 +197,9 @@ Blockly.Icon.prototype.getCorrectedSize = function() {
|
||||
* @protected
|
||||
*/
|
||||
Blockly.Icon.prototype.drawIcon_;
|
||||
|
||||
/**
|
||||
* Show or hide the icon.
|
||||
* @param {boolean} visible True if the icon should be visible.
|
||||
*/
|
||||
Blockly.Icon.prototype.setVisible;
|
||||
|
||||
@@ -18,5 +18,5 @@ goog.provide('Blockly.IRegistrable');
|
||||
/**
|
||||
* The interface for a Blockly component that can be registered.
|
||||
* @interface
|
||||
* */
|
||||
*/
|
||||
Blockly.IRegistrable = function() {};
|
||||
|
||||
31
core/interfaces/i_registrable_field.js
Normal file
31
core/interfaces/i_registrable_field.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview The interface for a Blockly field that can be registered.
|
||||
* @author samelh@google.com (Sam El-Husseini)
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.IRegistrableField');
|
||||
|
||||
goog.requireType('Blockly.Field');
|
||||
|
||||
/**
|
||||
* A registrable field.
|
||||
* Note: We are not using an interface here as we are interested in defining the
|
||||
* static methods of a field rather than the instance methods.
|
||||
* @typedef {{
|
||||
* fromJson:Blockly.IRegistrableField.fromJson
|
||||
* }}
|
||||
*/
|
||||
Blockly.IRegistrableField;
|
||||
|
||||
/**
|
||||
* @typedef {function(!Object): Blockly.Field}
|
||||
*/
|
||||
Blockly.IRegistrableField.fromJson;
|
||||
@@ -22,6 +22,8 @@ goog.require('Blockly.utils.toolbox');
|
||||
goog.require('Blockly.utils.userAgent');
|
||||
goog.require('Blockly.Xml');
|
||||
|
||||
goog.requireType('Blockly.WorkspaceSvg');
|
||||
|
||||
|
||||
/**
|
||||
* Parse the user-specified options, using reasonable defaults where behaviour
|
||||
@@ -170,8 +172,9 @@ Blockly.Options = function(options) {
|
||||
|
||||
/**
|
||||
* The parent of the current workspace, or null if there is no parent
|
||||
* workspace.
|
||||
* @type {Blockly.Workspace}
|
||||
* workspace. We can assert that this is of type WorkspaceSvg as opposed to
|
||||
* Workspace as this is only used in a rendered workspace.
|
||||
* @type {Blockly.WorkspaceSvg}
|
||||
*/
|
||||
this.parentWorkspace = options['parentWorkspace'];
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ declare module Blockly {
|
||||
};
|
||||
renderer?: string;
|
||||
keyMap?: {[type: string]: Blockly.Action;};
|
||||
parentWorkspace?: Blockly.WorkspaceSvg;
|
||||
}
|
||||
|
||||
interface BlocklyThemeOptions {
|
||||
|
||||
Reference in New Issue
Block a user