mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
Move constants to internal_constants.js and add aliases
This commit is contained in:
@@ -35,6 +35,7 @@ goog.require('Blockly.Events.VarCreate');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.inject');
|
||||
goog.require('Blockly.inputTypes');
|
||||
goog.require('Blockly.internalConstants');
|
||||
/** @suppress {extraRequire} */
|
||||
goog.require('Blockly.Procedures');
|
||||
goog.require('Blockly.ShortcutRegistry');
|
||||
@@ -596,3 +597,38 @@ Blockly.TOOLBOX_AT_LEFT = Blockly.utils.toolbox.Position.LEFT;
|
||||
* @see Blockly.utils.toolbox.Position.RIGHT
|
||||
*/
|
||||
Blockly.TOOLBOX_AT_RIGHT = Blockly.utils.toolbox.Position.RIGHT;
|
||||
|
||||
// Aliases to allow external code to access these values for legacy reasons.
|
||||
Blockly.LINE_MODE_MULTIPLIER = Blockly.internalConstants.LINE_MODE_MULTIPLIER;
|
||||
Blockly.PAGE_MODE_MULTIPLIER = Blockly.internalConstants.PAGE_MODE_MULTIPLIER;
|
||||
Blockly.DRAG_RADIUS = Blockly.internalConstants.DRAG_RADIUS;
|
||||
Blockly.FLYOUT_DRAG_RADIUS = Blockly.internalConstants.FLYOUT_DRAG_RADIUS;
|
||||
Blockly.SNAP_RADIUS = Blockly.internalConstants.SNAP_RADIUS;
|
||||
Blockly.CONNECTING_SNAP_RADIUS =
|
||||
Blockly.internalConstants.CONNECTING_SNAP_RADIUS;
|
||||
Blockly.CURRENT_CONNECTION_PREFERENCE =
|
||||
Blockly.internalConstants.CURRENT_CONNECTION_PREFERENCE;
|
||||
Blockly.BUMP_DELAY = Blockly.internalConstants.BUMP_DELAY;
|
||||
Blockly.BUMP_RANDOMNESS = Blockly.internalConstants.BUMP_RANDOMNESS;
|
||||
Blockly.COLLAPSE_CHARS = Blockly.internalConstants.COLLAPSE_CHARS;
|
||||
Blockly.LONGPRESS = Blockly.internalConstants.LONGPRESS;
|
||||
Blockly.SOUND_LIMIT = Blockly.internalConstants.SOUND_LIMIT;
|
||||
Blockly.DRAG_STACK = Blockly.internalConstants.DRAG_STACK;
|
||||
Blockly.HSV_SATURATION = Blockly.internalConstants.HSV_SATURATION;
|
||||
Blockly.HSV_VALUE = Blockly.internalConstants.HSV_VALUE;
|
||||
Blockly.SPRITE = Blockly.internalConstants.SPRITE;
|
||||
Blockly.DRAG_NONE = Blockly.internalConstants.DRAG_NONE;
|
||||
Blockly.DRAG_STICKY = Blockly.internalConstants.DRAG_STICKY;
|
||||
Blockly.DRAG_BEGIN = Blockly.internalConstants.DRAG_BEGIN;
|
||||
Blockly.DRAG_FREE = Blockly.internalConstants.DRAG_FREE;
|
||||
Blockly.OPPOSITE_TYPE = Blockly.internalConstants.OPPOSITE_TYPE;
|
||||
Blockly.VARIABLE_CATEGORY_NAME =
|
||||
Blockly.internalConstants.VARIABLE_CATEGORY_NAME;
|
||||
Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME =
|
||||
Blockly.internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME;
|
||||
Blockly.PROCEDURE_CATEGORY_NAME =
|
||||
Blockly.internalConstants.PROCEDURE_CATEGORY_NAME;
|
||||
Blockly.RENAME_VARIABLE_ID = Blockly.internalConstants.RENAME_VARIABLE_ID;
|
||||
Blockly.DELETE_VARIABLE_ID = Blockly.internalConstants.DELETE_VARIABLE_ID;
|
||||
Blockly.COLLAPSED_INPUT_NAME = Blockly.constants.COLLAPSED_INPUT_NAME;
|
||||
Blockly.COLLAPSED_FIELD_NAME = Blockly.constants.COLLAPSED_FIELD_NAME;
|
||||
|
||||
@@ -10,204 +10,31 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.constants');
|
||||
goog.module('Blockly.constants');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
goog.require('Blockly.connectionTypes');
|
||||
|
||||
|
||||
/**
|
||||
* The multiplier for scroll wheel deltas using the line delta mode.
|
||||
* @type {number}
|
||||
*/
|
||||
Blockly.LINE_MODE_MULTIPLIER = 40;
|
||||
|
||||
/**
|
||||
* The multiplier for scroll wheel deltas using the page delta mode.
|
||||
* @type {number}
|
||||
*/
|
||||
Blockly.PAGE_MODE_MULTIPLIER = 125;
|
||||
|
||||
/**
|
||||
* Number of pixels the mouse must move before a drag starts.
|
||||
*/
|
||||
Blockly.DRAG_RADIUS = 5;
|
||||
|
||||
/**
|
||||
* Number of pixels the mouse must move before a drag/scroll starts from the
|
||||
* flyout. Because the drag-intention is determined when this is reached, it is
|
||||
* larger than Blockly.DRAG_RADIUS so that the drag-direction is clearer.
|
||||
*/
|
||||
Blockly.FLYOUT_DRAG_RADIUS = 10;
|
||||
|
||||
/**
|
||||
* Maximum misalignment between connections for them to snap together.
|
||||
*/
|
||||
Blockly.SNAP_RADIUS = 28;
|
||||
|
||||
/**
|
||||
* Maximum misalignment between connections for them to snap together,
|
||||
* when a connection is already highlighted.
|
||||
*/
|
||||
Blockly.CONNECTING_SNAP_RADIUS = Blockly.SNAP_RADIUS;
|
||||
|
||||
/**
|
||||
* How much to prefer staying connected to the current connection over moving to
|
||||
* a new connection. The current previewed connection is considered to be this
|
||||
* much closer to the matching connection on the block than it actually is.
|
||||
*/
|
||||
Blockly.CURRENT_CONNECTION_PREFERENCE = 8;
|
||||
|
||||
/**
|
||||
* Delay in ms between trigger and bumping unconnected block out of alignment.
|
||||
*/
|
||||
Blockly.BUMP_DELAY = 250;
|
||||
|
||||
/**
|
||||
* Maximum randomness in workspace units for bumping a block.
|
||||
*/
|
||||
Blockly.BUMP_RANDOMNESS = 10;
|
||||
|
||||
/**
|
||||
* Number of characters to truncate a collapsed block to.
|
||||
*/
|
||||
Blockly.COLLAPSE_CHARS = 30;
|
||||
|
||||
/**
|
||||
* Length in ms for a touch to become a long press.
|
||||
*/
|
||||
Blockly.LONGPRESS = 750;
|
||||
|
||||
/**
|
||||
* Prevent a sound from playing if another sound preceded it within this many
|
||||
* milliseconds.
|
||||
*/
|
||||
Blockly.SOUND_LIMIT = 100;
|
||||
|
||||
/**
|
||||
* When dragging a block out of a stack, split the stack in two (true), or drag
|
||||
* out the block healing the stack (false).
|
||||
*/
|
||||
Blockly.DRAG_STACK = true;
|
||||
|
||||
/**
|
||||
* The richness of block colours, regardless of the hue.
|
||||
* Must be in the range of 0 (inclusive) to 1 (exclusive).
|
||||
*/
|
||||
Blockly.HSV_SATURATION = 0.45;
|
||||
|
||||
/**
|
||||
* The intensity of block colours, regardless of the hue.
|
||||
* Must be in the range of 0 (inclusive) to 1 (exclusive).
|
||||
*/
|
||||
Blockly.HSV_VALUE = 0.65;
|
||||
|
||||
/**
|
||||
* Sprited icons and images.
|
||||
*/
|
||||
Blockly.SPRITE = {
|
||||
width: 96,
|
||||
height: 124,
|
||||
url: 'sprites.png'
|
||||
};
|
||||
|
||||
// Constants below this point are not intended to be changed.
|
||||
|
||||
/**
|
||||
* Enum for alignment of inputs.
|
||||
* @enum {number}
|
||||
*/
|
||||
Blockly.constants.ALIGN = {
|
||||
const ALIGN = {
|
||||
LEFT: -1,
|
||||
CENTRE: 0,
|
||||
RIGHT: 1
|
||||
};
|
||||
|
||||
/**
|
||||
* ENUM for no drag operation.
|
||||
* @const
|
||||
*/
|
||||
Blockly.DRAG_NONE = 0;
|
||||
|
||||
/**
|
||||
* ENUM for inside the sticky DRAG_RADIUS.
|
||||
* @const
|
||||
*/
|
||||
Blockly.DRAG_STICKY = 1;
|
||||
|
||||
/**
|
||||
* ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between
|
||||
* clicks and drags.
|
||||
* @const
|
||||
*/
|
||||
Blockly.DRAG_BEGIN = 1;
|
||||
|
||||
/**
|
||||
* ENUM for freely draggable (outside the DRAG_RADIUS, if one applies).
|
||||
* @const
|
||||
*/
|
||||
Blockly.DRAG_FREE = 2;
|
||||
|
||||
/**
|
||||
* Lookup table for determining the opposite type of a connection.
|
||||
* @const
|
||||
*/
|
||||
Blockly.OPPOSITE_TYPE = [];
|
||||
Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.INPUT_VALUE] =
|
||||
Blockly.connectionTypes.OUTPUT_VALUE;
|
||||
Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.OUTPUT_VALUE] =
|
||||
Blockly.connectionTypes.INPUT_VALUE;
|
||||
Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.NEXT_STATEMENT] =
|
||||
Blockly.connectionTypes.PREVIOUS_STATEMENT;
|
||||
Blockly.OPPOSITE_TYPE[Blockly.connectionTypes.PREVIOUS_STATEMENT] =
|
||||
Blockly.connectionTypes.NEXT_STATEMENT;
|
||||
|
||||
/**
|
||||
* String for use in the "custom" attribute of a category in toolbox XML.
|
||||
* This string indicates that the category should be dynamically populated with
|
||||
* variable blocks.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.VARIABLE_CATEGORY_NAME = 'VARIABLE';
|
||||
/**
|
||||
* String for use in the "custom" attribute of a category in toolbox XML.
|
||||
* This string indicates that the category should be dynamically populated with
|
||||
* variable blocks.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.VARIABLE_DYNAMIC_CATEGORY_NAME = 'VARIABLE_DYNAMIC';
|
||||
|
||||
/**
|
||||
* String for use in the "custom" attribute of a category in toolbox XML.
|
||||
* This string indicates that the category should be dynamically populated with
|
||||
* procedure blocks.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.PROCEDURE_CATEGORY_NAME = 'PROCEDURE';
|
||||
|
||||
/**
|
||||
* String for use in the dropdown created in field_variable.
|
||||
* This string indicates that this option in the dropdown is 'Rename
|
||||
* variable...' and if selected, should trigger the prompt to rename a variable.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID';
|
||||
|
||||
/**
|
||||
* String for use in the dropdown created in field_variable.
|
||||
* This string indicates that this option in the dropdown is 'Delete the "%1"
|
||||
* variable' and if selected, should trigger the prompt to delete a variable.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID';
|
||||
exports.ALIGN = ALIGN;
|
||||
|
||||
/**
|
||||
* The language-neutral ID given to the collapsed input.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.constants.COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT';
|
||||
const COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT';
|
||||
exports.COLLAPSED_INPUT_NAME = COLLAPSED_INPUT_NAME;
|
||||
|
||||
/**
|
||||
* The language-neutral ID given to the collapsed field.
|
||||
* @const {string}
|
||||
*/
|
||||
Blockly.constants.COLLAPSED_FIELD_NAME = '_TEMP_COLLAPSED_FIELD';
|
||||
const COLLAPSED_FIELD_NAME = '_TEMP_COLLAPSED_FIELD';
|
||||
exports.COLLAPSED_FIELD_NAME = COLLAPSED_FIELD_NAME;
|
||||
|
||||
217
core/internal_constants.js
Normal file
217
core/internal_constants.js
Normal file
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2021 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Module that provides constants for use inside Blockly. Do not
|
||||
* use these constants outside of the core library.
|
||||
* @author fenichel@google.com (Rachel Fenichel)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.module('Blockly.internalConstants');
|
||||
goog.module.declareLegacyNamespace();
|
||||
|
||||
const connectionTypes = goog.require('Blockly.connectionTypes');
|
||||
|
||||
|
||||
/**
|
||||
* The multiplier for scroll wheel deltas using the line delta mode.
|
||||
* @type {number}
|
||||
*/
|
||||
const LINE_MODE_MULTIPLIER = 40;
|
||||
exports.LINE_MODE_MULTIPLIER = LINE_MODE_MULTIPLIER;
|
||||
|
||||
/**
|
||||
* The multiplier for scroll wheel deltas using the page delta mode.
|
||||
* @type {number}
|
||||
*/
|
||||
const PAGE_MODE_MULTIPLIER = 125;
|
||||
exports.PAGE_MODE_MULTIPLIER = PAGE_MODE_MULTIPLIER;
|
||||
|
||||
/**
|
||||
* Number of pixels the mouse must move before a drag starts.
|
||||
*/
|
||||
const DRAG_RADIUS = 5;
|
||||
exports.DRAG_RADIUS = DRAG_RADIUS;
|
||||
|
||||
/**
|
||||
* Number of pixels the mouse must move before a drag/scroll starts from the
|
||||
* flyout. Because the drag-intention is determined when this is reached, it is
|
||||
* larger than DRAG_RADIUS so that the drag-direction is clearer.
|
||||
*/
|
||||
const FLYOUT_DRAG_RADIUS = 10;
|
||||
exports.FLYOUT_DRAG_RADIUS = FLYOUT_DRAG_RADIUS;
|
||||
|
||||
/**
|
||||
* Maximum misalignment between connections for them to snap together.
|
||||
*/
|
||||
const SNAP_RADIUS = 28;
|
||||
exports.SNAP_RADIUS = SNAP_RADIUS;
|
||||
|
||||
/**
|
||||
* Maximum misalignment between connections for them to snap together,
|
||||
* when a connection is already highlighted.
|
||||
*/
|
||||
const CONNECTING_SNAP_RADIUS = SNAP_RADIUS;
|
||||
exports.CONNECTING_SNAP_RADIUS = CONNECTING_SNAP_RADIUS;
|
||||
|
||||
/**
|
||||
* How much to prefer staying connected to the current connection over moving to
|
||||
* a new connection. The current previewed connection is considered to be this
|
||||
* much closer to the matching connection on the block than it actually is.
|
||||
*/
|
||||
const CURRENT_CONNECTION_PREFERENCE = 8;
|
||||
exports.CURRENT_CONNECTION_PREFERENCE = CURRENT_CONNECTION_PREFERENCE;
|
||||
|
||||
/**
|
||||
* Delay in ms between trigger and bumping unconnected block out of alignment.
|
||||
*/
|
||||
const BUMP_DELAY = 250;
|
||||
exports.BUMP_DELAY = BUMP_DELAY;
|
||||
|
||||
/**
|
||||
* Maximum randomness in workspace units for bumping a block.
|
||||
*/
|
||||
const BUMP_RANDOMNESS = 10;
|
||||
exports.BUMP_RANDOMNESS = BUMP_RANDOMNESS;
|
||||
|
||||
/**
|
||||
* Number of characters to truncate a collapsed block to.
|
||||
*/
|
||||
const COLLAPSE_CHARS = 30;
|
||||
exports.COLLAPSE_CHARS = COLLAPSE_CHARS;
|
||||
|
||||
/**
|
||||
* Length in ms for a touch to become a long press.
|
||||
*/
|
||||
const LONGPRESS = 750;
|
||||
exports.LONGPRESS = LONGPRESS;
|
||||
|
||||
/**
|
||||
* Prevent a sound from playing if another sound preceded it within this many
|
||||
* milliseconds.
|
||||
*/
|
||||
const SOUND_LIMIT = 100;
|
||||
exports.SOUND_LIMIT = SOUND_LIMIT;
|
||||
|
||||
/**
|
||||
* When dragging a block out of a stack, split the stack in two (true), or drag
|
||||
* out the block healing the stack (false).
|
||||
*/
|
||||
const DRAG_STACK = true;
|
||||
exports.DRAG_STACK = DRAG_STACK;
|
||||
|
||||
/**
|
||||
* The richness of block colours, regardless of the hue.
|
||||
* Must be in the range of 0 (inclusive) to 1 (exclusive).
|
||||
*/
|
||||
const HSV_SATURATION = 0.45;
|
||||
exports.HSV_SATURATION = HSV_SATURATION;
|
||||
|
||||
/**
|
||||
* The intensity of block colours, regardless of the hue.
|
||||
* Must be in the range of 0 (inclusive) to 1 (exclusive).
|
||||
*/
|
||||
const HSV_VALUE = 0.65;
|
||||
exports.HSV_VALUE = HSV_VALUE;
|
||||
|
||||
/**
|
||||
* Sprited icons and images.
|
||||
*/
|
||||
const SPRITE = {
|
||||
width: 96,
|
||||
height: 124,
|
||||
url: 'sprites.png'
|
||||
};
|
||||
exports.SPRITE = SPRITE;
|
||||
|
||||
/**
|
||||
* ENUM for no drag operation.
|
||||
* @const
|
||||
*/
|
||||
const DRAG_NONE = 0;
|
||||
exports.DRAG_NONE = DRAG_NONE;
|
||||
|
||||
/**
|
||||
* ENUM for inside the sticky DRAG_RADIUS.
|
||||
* @const
|
||||
*/
|
||||
const DRAG_STICKY = 1;
|
||||
exports.DRAG_STICKY = DRAG_STICKY;
|
||||
|
||||
/**
|
||||
* ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between
|
||||
* clicks and drags.
|
||||
* @const
|
||||
*/
|
||||
const DRAG_BEGIN = 1;
|
||||
exports.DRAG_BEGIN = DRAG_BEGIN;
|
||||
|
||||
/**
|
||||
* ENUM for freely draggable (outside the DRAG_RADIUS, if one applies).
|
||||
* @const
|
||||
*/
|
||||
const DRAG_FREE = 2;
|
||||
exports.DRAG_FREE = DRAG_FREE;
|
||||
|
||||
/**
|
||||
* Lookup table for determining the opposite type of a connection.
|
||||
* @const
|
||||
*/
|
||||
const OPPOSITE_TYPE = [];
|
||||
OPPOSITE_TYPE[connectionTypes.INPUT_VALUE] = connectionTypes.OUTPUT_VALUE;
|
||||
OPPOSITE_TYPE[connectionTypes.OUTPUT_VALUE] = connectionTypes.INPUT_VALUE;
|
||||
OPPOSITE_TYPE[connectionTypes.NEXT_STATEMENT] =
|
||||
connectionTypes.PREVIOUS_STATEMENT;
|
||||
OPPOSITE_TYPE[connectionTypes.PREVIOUS_STATEMENT] =
|
||||
connectionTypes.NEXT_STATEMENT;
|
||||
|
||||
exports.OPPOSITE_TYPE = OPPOSITE_TYPE;
|
||||
|
||||
/**
|
||||
* String for use in the "custom" attribute of a category in toolbox XML.
|
||||
* This string indicates that the category should be dynamically populated with
|
||||
* variable blocks.
|
||||
* @const {string}
|
||||
*/
|
||||
const VARIABLE_CATEGORY_NAME = 'VARIABLE';
|
||||
exports.VARIABLE_CATEGORY_NAME = VARIABLE_CATEGORY_NAME;
|
||||
|
||||
/**
|
||||
* String for use in the "custom" attribute of a category in toolbox XML.
|
||||
* This string indicates that the category should be dynamically populated with
|
||||
* variable blocks.
|
||||
* @const {string}
|
||||
*/
|
||||
const VARIABLE_DYNAMIC_CATEGORY_NAME = 'VARIABLE_DYNAMIC';
|
||||
exports.VARIABLE_DYNAMIC_CATEGORY_NAME = VARIABLE_DYNAMIC_CATEGORY_NAME;
|
||||
|
||||
/**
|
||||
* String for use in the "custom" attribute of a category in toolbox XML.
|
||||
* This string indicates that the category should be dynamically populated with
|
||||
* procedure blocks.
|
||||
* @const {string}
|
||||
*/
|
||||
const PROCEDURE_CATEGORY_NAME = 'PROCEDURE';
|
||||
exports.PROCEDURE_CATEGORY_NAME = PROCEDURE_CATEGORY_NAME;
|
||||
|
||||
/**
|
||||
* String for use in the dropdown created in field_variable.
|
||||
* This string indicates that this option in the dropdown is 'Rename
|
||||
* variable...' and if selected, should trigger the prompt to rename a variable.
|
||||
* @const {string}
|
||||
*/
|
||||
const RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID';
|
||||
exports.RENAME_VARIABLE_ID = RENAME_VARIABLE_ID;
|
||||
|
||||
/**
|
||||
* String for use in the dropdown created in field_variable.
|
||||
* This string indicates that this option in the dropdown is 'Delete the "%1"
|
||||
* variable' and if selected, should trigger the prompt to delete a variable.
|
||||
* @const {string}
|
||||
*/
|
||||
const DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID';
|
||||
exports.DELETE_VARIABLE_ID = DELETE_VARIABLE_ID;
|
||||
Reference in New Issue
Block a user