mirror of
https://github.com/google/blockly.git
synced 2026-01-06 00:20:37 +01:00
* chore(build): Add "all" modules for blocks & generators
These modules (Blockly.blocks.all and Blockly.<Generator>.all) will
be the entry points for the corresponding chunks.
They also make it easier to pull in all the modules in each package
(e.g. for playground and tests).
It is necessary to set the Closure Compiler dependency_mode to
SORT_ONLY as otherwise it tries to compile the "all" modules before
their dependencies, which fails.
The only impact on the _compressed.js files is the addition of a short
string to the very end of each file, e.g.:
var module$exports$Blockly$JavaScript$all={};
* chore(deps): Add devDependency on closure-calculate-chunks
* feat(build): First pass at chunked complation
Add a new buildCompiled gulp target (npm run build:compiled) that
uses closure-calculate-chunks to do chunked compliation of core/,
blocks/ and generators/ all in a single pass.
This work is incomplete: the resulting *_compressed.js files don't
(yet) have UMD wrappers.
* chore(build): Generate chunk wrappers
A first pass; this does not have support for a namespace object yet.
* refactor(build): Use chunked compilation by default
Remove old "compressed" gulp tasks in favour of new "compiled" task.
* chore(build): Remove cruft from buildCompiled
Remove unneeded `done` parameter and commented-out options that had
been cargo-culted from the old build pipeline.
* fix(build): Fix test failures caused by new build pipeline
- Exclude closure/goog/base.js from compiler input; use
externs/goog-externs.js instead.
- Have the build:debug and build:strict targets only build the first
chunk (blockly_compressed.js).
- Fix namespace entries for blocks and generators.
* fix(build): Fix build failures on node v12
closure-calculate-chunks requires node.js v14 or later.
When running on node.js v14 or later have getChunkOptions save
the output of closure-calculate-chunks to
scripts/gulpfiles/chunks.json. When running on older versions of
node.js have it use this checked-in, cached output instead of
attempting to run closure-calculate-chunks.
* chore(build): enable --rename_prefix_namespace
This will allow modules in blocks/ and generators/ to use
goog.require to obtain the exports object of goog.modules from
core/.
* fix(build): Always build all chunks
The previous commit enabled --rename_prefix_namespace option to
Closure Compiler, and this causes the buildCompressed target to
work fine when run without --debug or --strict, but adding either
of those flags (as for example when `npm test` runs
`npm run build:debug`) causes an issue:
- Because of many compiler errors in blocks/ and generators/,
a previous commit added a hack to only build the first chunk
when doing debug/strict builds.
- When asked to build only one chunk, Closure Compiler ignores the
--rename_prefix_namespace flag, because it 'correctly' infers
that there are no later chunks that will need to access global
variables from the first chunk.
- This causes a test failure, because `npm test` first runs
`npm run build`, which generates a valid blockly_compressed.js,
but this is then overrwritten by an invalid one when it next runs
`npm run build:debug`.
(The invalid one is missing all `$.` prefixes on 'global' variables,
including on Blockly, so the wrapper's last two lines -
"$.Blockly.internal_ = $;" and "return $.Blockly" - fail.)
The fix is to add appropriate @suppress annotations to blocks/*.js and
generators/**/*.js and then remove the first-chunk-only hack.
* refactor(build): Just build once
Since the previous commit caused `npm run build:debug` to do
everything that `... build:compressed` does - and to produce
byte-for-byte identical output - it doesn't make sense to run
both when testing. To that end:
- Replace the build:debug and build:strict package scripts that
did `gulp buildCompressed --...` with new scripts build-debug
and build-strict that do `gulp build --...` instead.
(The target names are changed so as to extend our existing naming
convention as follows: a target named "foo:bar" does some sub-part
of the job done by target "foo", but a target named "foo-bar" does
all the work of the target "foo" with some extra options.)
- build:debug:log and build:strict:log are similarly replaced with
build-debug-log and build-strict-log.
- Modify run_all_tests.js to just do `npm run build-debug` instead of
doing both `npm run build` and `npm run build:debug`.
- Also remove the 'build:blocks' script that should have been removed
when the buildBlocks gulp task was deleted previously.
* refactor(build): Compile with base_minimal.js instead of base.js
Introduce a (very!) cut-down version of closure/goog/base.js named
base_minimal.js that is used as input to the compiler as an
alternative to using externs/goog-externs.js (which will be deleted
once the buildAdvancedCompilationTest target has been updated).
This will allow use of goog.setTestOnly since it will now exist in
compiled mode, and allows the changes made in 5b112db to filter
base.js out of the files for the first chunk to be reverted.
(It also obliges a change to the compiled-mode check in blockly.js.)
* fix(build): Fix buildAdvanceCompilationTest
- In build_tasks.js:
- Replace the old compile() function with a new one factored out of
buildCompiled().
- Update buildAdvancedCompilationTest to use the new compile()
and other helpers created in the meantime.
- Remove no-longer-used maybeAddClosureLibrary().
- Remove externs/{block,generator,goog}-externs.js, which are no longer
used by any compile pipeline.
- Update core/blockly.js to fix issue with detection of compiled mode
when using ADVANCED_OPTIMISATIONS.
- Update only other use of globalThis, in core/utils/xml.js, to
consistently treat it as a dictionary object.
- Update instructions in tests/compile/index.html.
This commit is sort-of-a-prerequisite to #5602; test:compile:advanced
was previously working but the generated `main_compresed.js` would
throw errors upon loading.
727 lines
27 KiB
JavaScript
727 lines
27 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2011 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview The top level namespace used to access the Blockly library.
|
|
*/
|
|
'use strict';
|
|
|
|
/**
|
|
* The top level namespace used to access the Blockly library.
|
|
* @namespace Blockly
|
|
*/
|
|
goog.module('Blockly');
|
|
goog.module.declareLegacyNamespace();
|
|
|
|
const ContextMenu = goog.require('Blockly.ContextMenu');
|
|
const ContextMenuItems = goog.require('Blockly.ContextMenuItems');
|
|
const Css = goog.require('Blockly.Css');
|
|
const Events = goog.require('Blockly.Events');
|
|
const Extensions = goog.require('Blockly.Extensions');
|
|
const Procedures = goog.require('Blockly.Procedures');
|
|
const ShortcutItems = goog.require('Blockly.ShortcutItems');
|
|
const Themes = goog.require('Blockly.Themes');
|
|
const Tooltip = goog.require('Blockly.Tooltip');
|
|
const Touch = goog.require('Blockly.Touch');
|
|
const Variables = goog.require('Blockly.Variables');
|
|
const VariablesDynamic = goog.require('Blockly.VariablesDynamic');
|
|
const WidgetDiv = goog.require('Blockly.WidgetDiv');
|
|
const Xml = goog.require('Blockly.Xml');
|
|
const blockAnimations = goog.require('Blockly.blockAnimations');
|
|
const blockRendering = goog.require('Blockly.blockRendering');
|
|
const browserEvents = goog.require('Blockly.browserEvents');
|
|
const bumpObjects = goog.require('Blockly.bumpObjects');
|
|
const clipboard = goog.require('Blockly.clipboard');
|
|
const colour = goog.require('Blockly.utils.colour');
|
|
const common = goog.require('Blockly.common');
|
|
const constants = goog.require('Blockly.constants');
|
|
const deprecation = goog.require('Blockly.utils.deprecation');
|
|
const dialog = goog.require('Blockly.dialog');
|
|
const fieldRegistry = goog.require('Blockly.fieldRegistry');
|
|
const geras = goog.require('Blockly.geras');
|
|
const internalConstants = goog.require('Blockly.internalConstants');
|
|
const loopMixin = goog.require('Blockly.loopMixin');
|
|
const minimalist = goog.require('Blockly.minimalist');
|
|
const registry = goog.require('Blockly.registry');
|
|
const svgMath = goog.require('Blockly.utils.svgMath');
|
|
const thrasos = goog.require('Blockly.thrasos');
|
|
const toolbox = goog.require('Blockly.utils.toolbox');
|
|
const uiPosition = goog.require('Blockly.uiPosition');
|
|
const utils = goog.require('Blockly.utils');
|
|
const zelos = goog.require('Blockly.zelos');
|
|
const {ASTNode} = goog.require('Blockly.ASTNode');
|
|
const {BasicCursor} = goog.require('Blockly.BasicCursor');
|
|
const {BlockDragSurfaceSvg} = goog.require('Blockly.BlockDragSurfaceSvg');
|
|
const {BlockDragger} = goog.require('Blockly.BlockDragger');
|
|
const {BlockSvg} = goog.require('Blockly.BlockSvg');
|
|
const {BlocklyOptions} = goog.require('Blockly.BlocklyOptions');
|
|
const {Blocks} = goog.require('Blockly.blocks');
|
|
const {Block} = goog.require('Blockly.Block');
|
|
const {BubbleDragger} = goog.require('Blockly.BubbleDragger');
|
|
const {Bubble} = goog.require('Blockly.Bubble');
|
|
const {CollapsibleToolboxCategory} = goog.require('Blockly.CollapsibleToolboxCategory');
|
|
const {Comment} = goog.require('Blockly.Comment');
|
|
const {ComponentManager} = goog.require('Blockly.ComponentManager');
|
|
const {ConnectionChecker} = goog.require('Blockly.ConnectionChecker');
|
|
const {ConnectionDB} = goog.require('Blockly.ConnectionDB');
|
|
const {ConnectionType} = goog.require('Blockly.ConnectionType');
|
|
const {Connection} = goog.require('Blockly.Connection');
|
|
const {ContextMenuRegistry} = goog.require('Blockly.ContextMenuRegistry');
|
|
const {Cursor} = goog.require('Blockly.Cursor');
|
|
const {DeleteArea} = goog.require('Blockly.DeleteArea');
|
|
const {DragTarget} = goog.require('Blockly.DragTarget');
|
|
const {DropDownDiv} = goog.require('Blockly.DropDownDiv');
|
|
const {FieldAngle} = goog.require('Blockly.FieldAngle');
|
|
const {FieldCheckbox} = goog.require('Blockly.FieldCheckbox');
|
|
const {FieldColour} = goog.require('Blockly.FieldColour');
|
|
const {FieldDropdown} = goog.require('Blockly.FieldDropdown');
|
|
const {FieldImage} = goog.require('Blockly.FieldImage');
|
|
const {FieldLabelSerializable} = goog.require('Blockly.FieldLabelSerializable');
|
|
const {FieldLabel} = goog.require('Blockly.FieldLabel');
|
|
const {FieldMultilineInput} = goog.require('Blockly.FieldMultilineInput');
|
|
const {FieldNumber} = goog.require('Blockly.FieldNumber');
|
|
const {FieldTextInput} = goog.require('Blockly.FieldTextInput');
|
|
const {FieldVariable} = goog.require('Blockly.FieldVariable');
|
|
const {Field} = goog.require('Blockly.Field');
|
|
const {FlyoutButton} = goog.require('Blockly.FlyoutButton');
|
|
const {FlyoutMetricsManager} = goog.require('Blockly.FlyoutMetricsManager');
|
|
const {Flyout} = goog.require('Blockly.Flyout');
|
|
const {Generator} = goog.require('Blockly.Generator');
|
|
const {Gesture} = goog.require('Blockly.Gesture');
|
|
const {Grid} = goog.require('Blockly.Grid');
|
|
const {HorizontalFlyout} = goog.require('Blockly.HorizontalFlyout');
|
|
const {IASTNodeLocationSvg} = goog.require('Blockly.IASTNodeLocationSvg');
|
|
const {IASTNodeLocationWithBlock} = goog.require('Blockly.IASTNodeLocationWithBlock');
|
|
const {IASTNodeLocation} = goog.require('Blockly.IASTNodeLocation');
|
|
const {IAutoHideable} = goog.require('Blockly.IAutoHideable');
|
|
const {IBlockDragger} = goog.require('Blockly.IBlockDragger');
|
|
const {IBoundedElement} = goog.require('Blockly.IBoundedElement');
|
|
const {IBubble} = goog.require('Blockly.IBubble');
|
|
const {ICollapsibleToolboxItem} = goog.require('Blockly.ICollapsibleToolboxItem');
|
|
const {IComponent} = goog.require('Blockly.IComponent');
|
|
const {IConnectionChecker} = goog.require('Blockly.IConnectionChecker');
|
|
const {IContextMenu} = goog.require('Blockly.IContextMenu');
|
|
const {ICopyable} = goog.require('Blockly.ICopyable');
|
|
const {IDeletable} = goog.require('Blockly.IDeletable');
|
|
const {IDeleteArea} = goog.require('Blockly.IDeleteArea');
|
|
const {IDragTarget} = goog.require('Blockly.IDragTarget');
|
|
const {IDraggable} = goog.require('Blockly.IDraggable');
|
|
const {IFlyout} = goog.require('Blockly.IFlyout');
|
|
const {IKeyboardAccessible} = goog.require('Blockly.IKeyboardAccessible');
|
|
const {IMetricsManager} = goog.require('Blockly.IMetricsManager');
|
|
const {IMovable} = goog.require('Blockly.IMovable');
|
|
const {IPositionable} = goog.require('Blockly.IPositionable');
|
|
const {IRegistrableField} = goog.require('Blockly.IRegistrableField');
|
|
const {IRegistrable} = goog.require('Blockly.IRegistrable');
|
|
const {ISelectableToolboxItem} = goog.require('Blockly.ISelectableToolboxItem');
|
|
const {ISelectable} = goog.require('Blockly.ISelectable');
|
|
const {IStyleable} = goog.require('Blockly.IStyleable');
|
|
const {IToolboxItem} = goog.require('Blockly.IToolboxItem');
|
|
const {IToolbox} = goog.require('Blockly.IToolbox');
|
|
const {Icon} = goog.require('Blockly.Icon');
|
|
const {Input} = goog.require('Blockly.Input');
|
|
const {InsertionMarkerManager} = goog.require('Blockly.InsertionMarkerManager');
|
|
const {Marker} = goog.require('Blockly.Marker');
|
|
const {MarkerManager} = goog.require('Blockly.MarkerManager');
|
|
const {MenuItem} = goog.require('Blockly.MenuItem');
|
|
const {Menu} = goog.require('Blockly.Menu');
|
|
const {MetricsManager} = goog.require('Blockly.MetricsManager');
|
|
const {Mutator} = goog.require('Blockly.Mutator');
|
|
const {Names} = goog.require('Blockly.Names');
|
|
const {Options} = goog.require('Blockly.Options');
|
|
const {RenderedConnection} = goog.require('Blockly.RenderedConnection');
|
|
const {ScrollbarPair} = goog.require('Blockly.ScrollbarPair');
|
|
const {Scrollbar} = goog.require('Blockly.Scrollbar');
|
|
const {ShortcutRegistry} = goog.require('Blockly.ShortcutRegistry');
|
|
const {TabNavigateCursor} = goog.require('Blockly.TabNavigateCursor');
|
|
const {ThemeManager} = goog.require('Blockly.ThemeManager');
|
|
const {Theme} = goog.require('Blockly.Theme');
|
|
const {ToolboxCategory} = goog.require('Blockly.ToolboxCategory');
|
|
const {ToolboxItem} = goog.require('Blockly.ToolboxItem');
|
|
const {ToolboxSeparator} = goog.require('Blockly.ToolboxSeparator');
|
|
const {Toolbox} = goog.require('Blockly.Toolbox');
|
|
const {TouchGesture} = goog.require('Blockly.TouchGesture');
|
|
const {Trashcan} = goog.require('Blockly.Trashcan');
|
|
const {VariableMap} = goog.require('Blockly.VariableMap');
|
|
const {VariableModel} = goog.require('Blockly.VariableModel');
|
|
const {VerticalFlyout} = goog.require('Blockly.VerticalFlyout');
|
|
const {Warning} = goog.require('Blockly.Warning');
|
|
const {WorkspaceAudio} = goog.require('Blockly.WorkspaceAudio');
|
|
const {WorkspaceCommentSvg} = goog.require('Blockly.WorkspaceCommentSvg');
|
|
const {WorkspaceComment} = goog.require('Blockly.WorkspaceComment');
|
|
const {WorkspaceDragSurfaceSvg} = goog.require('Blockly.WorkspaceDragSurfaceSvg');
|
|
const {WorkspaceDragger} = goog.require('Blockly.WorkspaceDragger');
|
|
const {WorkspaceSvg, resizeSvgContents} = goog.require('Blockly.WorkspaceSvg');
|
|
const {Workspace} = goog.require('Blockly.Workspace');
|
|
const {ZoomControls} = goog.require('Blockly.ZoomControls');
|
|
const {globalThis} = goog.require('Blockly.utils.global');
|
|
const {inject} = goog.require('Blockly.inject');
|
|
const {inputTypes} = goog.require('Blockly.inputTypes');
|
|
/** @suppress {extraRequire} */
|
|
goog.require('Blockly.Events.BlockCreate');
|
|
/** @suppress {extraRequire} */
|
|
goog.require('Blockly.Events.FinishedLoading');
|
|
/** @suppress {extraRequire} */
|
|
goog.require('Blockly.Events.Ui');
|
|
/** @suppress {extraRequire} */
|
|
goog.require('Blockly.Events.UiBase');
|
|
/** @suppress {extraRequire} */
|
|
goog.require('Blockly.Events.VarCreate');
|
|
|
|
|
|
/**
|
|
* Blockly core version.
|
|
* This constant is overridden by the build script (npm run build) to the value
|
|
* of the version in package.json. This is done by the Closure Compiler in the
|
|
* buildCompressed gulp task.
|
|
* For local builds, you can pass --define='Blockly.VERSION=X.Y.Z' to the
|
|
* compiler to override this constant.
|
|
* @define {string}
|
|
* @alias Blockly.VERSION
|
|
*/
|
|
exports.VERSION = 'uncompiled';
|
|
|
|
/**
|
|
* @define {boolean} Overridden to true by the compiler.
|
|
*/
|
|
const COMPILED = false;
|
|
|
|
// Add a getter and setter pair for Blockly.alert, Blockly.confirm,
|
|
// Blockly.mainWorkspace, Blockly.prompt and Blockly.selected for backwards
|
|
// compatibility.
|
|
Object.defineProperties(exports, {
|
|
/**
|
|
* Wrapper to window.alert() that app developers may override to
|
|
* provide alternatives to the modal browser window.
|
|
* @name Blockly.alert
|
|
* @type {!function(string, function()=)}
|
|
* @deprecated Use Blockly.dialog.alert / .setAlert() instead.
|
|
* (September 2021)
|
|
* @suppress {checkTypes}
|
|
*/
|
|
alert: {
|
|
set: function(newAlert) {
|
|
deprecation.warn('Blockly.alert', 'September 2021', 'September 2022');
|
|
dialog.setAlert(newAlert);
|
|
},
|
|
get: function() {
|
|
deprecation.warn(
|
|
'Blockly.alert', 'September 2021', 'September 2022',
|
|
'Blockly.dialog.alert()');
|
|
return dialog.alert;
|
|
},
|
|
},
|
|
/**
|
|
* Wrapper to window.confirm() that app developers may override to
|
|
* provide alternatives to the modal browser window.
|
|
* @name Blockly.confirm
|
|
* @type {!function(string, function()=)}
|
|
* @deprecated Use Blockly.dialog.confirm / .setConfirm() instead.
|
|
* (September 2021)
|
|
* @suppress {checkTypes}
|
|
*/
|
|
confirm: {
|
|
set: function(newConfirm) {
|
|
deprecation.warn('Blockly.confirm', 'September 2021', 'September 2022');
|
|
dialog.setConfirm(newConfirm);
|
|
},
|
|
get: function() {
|
|
deprecation.warn(
|
|
'Blockly.confirm', 'September 2021', 'September 2022',
|
|
'Blockly.dialog.confirm()');
|
|
return dialog.confirm;
|
|
},
|
|
},
|
|
/**
|
|
* The main workspace most recently used.
|
|
* Set by Blockly.WorkspaceSvg.prototype.markFocused
|
|
* @name Blockly.mainWorkspace
|
|
* @type {Workspace}
|
|
* @deprecated Use Blockly.common.getMainWorkspace() /
|
|
* .setMainWorkspace instead. (September 2021)
|
|
* @suppress {checkTypes}
|
|
*/
|
|
mainWorkspace: {
|
|
set: function(x) {
|
|
deprecation.warn(
|
|
'Blockly.mainWorkspace', 'September 2021', 'September 2022');
|
|
common.setMainWorkspace(x);
|
|
},
|
|
get: function() {
|
|
deprecation.warn(
|
|
'Blockly.mainWorkspace', 'September 2021', 'September 2022',
|
|
'Blockly.getMainWorkspace()');
|
|
return common.getMainWorkspace();
|
|
},
|
|
},
|
|
/**
|
|
* Wrapper to window.prompt() that app developers may override to
|
|
* provide alternatives to the modal browser window. Built-in
|
|
* browser prompts are often used for better text input experience
|
|
* on mobile device. We strongly recommend testing mobile when
|
|
* overriding this.
|
|
* @name Blockly.prompt
|
|
* @type {!function(string, string, function()=)}
|
|
* @deprecated Use Blockly.dialog.prompt / .setPrompt() instead.
|
|
* (September 2021)
|
|
* @suppress {checkTypes}
|
|
*/
|
|
prompt: {
|
|
set: function(newPrompt) {
|
|
deprecation.warn('Blockly.prompt', 'September 2021', 'September 2022');
|
|
dialog.setPrompt(newPrompt);
|
|
},
|
|
get: function() {
|
|
deprecation.warn(
|
|
'Blockly.prompt', 'September 2021', 'September 2022',
|
|
'Blockly.dialog.prompt()');
|
|
return dialog.prompt;
|
|
},
|
|
},
|
|
/**
|
|
* Currently selected block.
|
|
* @name Blockly.selected
|
|
* @type {?ICopyable}
|
|
* @deprecated Use Blockly.common.getSelected() / .setSelected
|
|
* instead. (September 2021)
|
|
* @suppress {checkTypes}
|
|
*/
|
|
selected: {
|
|
get: function() {
|
|
deprecation.warn(
|
|
'Blockly.selected', 'September 2021', 'September 2022',
|
|
'Blockly.common.getSelected()');
|
|
return common.getSelected();
|
|
},
|
|
set: function(newSelection) {
|
|
deprecation.warn(
|
|
'Blockly.selected', 'September 2021', 'September 2022',
|
|
'Blockly.common.setSelected()');
|
|
common.setSelected(newSelection);
|
|
},
|
|
},
|
|
});
|
|
|
|
/**
|
|
* Returns the dimensions of the specified SVG image.
|
|
* @param {!SVGElement} svg SVG image.
|
|
* @return {!Size} Contains width and height properties.
|
|
* @deprecated Use workspace.setCachedParentSvgSize. (2021 March 5)
|
|
* @alias Blockly.svgSize
|
|
*/
|
|
exports.svgSize = svgMath.svgSize;
|
|
|
|
/**
|
|
* Size the workspace when the contents change. This also updates
|
|
* scrollbars accordingly.
|
|
* @param {!WorkspaceSvg} workspace The workspace to resize.
|
|
* @deprecated
|
|
* @alias Blockly.resizeSvgContents
|
|
*/
|
|
const resizeSvgContentsLocal = function(workspace) {
|
|
deprecation.warn(
|
|
'Blockly.resizeSvgContents', 'December 2021', 'December 2022',
|
|
'Blockly.WorkspaceSvg.resizeSvgContents');
|
|
resizeSvgContents(workspace);
|
|
};
|
|
exports.resizeSvgContents = resizeSvgContentsLocal;
|
|
|
|
/**
|
|
* Copy a block or workspace comment onto the local clipboard.
|
|
* @param {!ICopyable} toCopy Block or Workspace Comment to be copied.
|
|
* @package
|
|
* @alias Blockly.copy
|
|
*/
|
|
exports.copy = clipboard.copy;
|
|
|
|
/**
|
|
* Paste a block or workspace comment on to the main workspace.
|
|
* @return {boolean} True if the paste was successful, false otherwise.
|
|
* @package
|
|
* @alias Blockly.paste
|
|
*/
|
|
exports.paste = clipboard.paste;
|
|
|
|
/**
|
|
* Duplicate this block and its children, or a workspace comment.
|
|
* @param {!ICopyable} toDuplicate Block or Workspace Comment to be
|
|
* copied.
|
|
* @package
|
|
* @alias Blockly.duplicate
|
|
*/
|
|
exports.duplicate = clipboard.duplicate;
|
|
|
|
/**
|
|
* Close tooltips, context menus, dropdown selections, etc.
|
|
* @deprecated Use Blockly.common.getMainWorkspace().hideChaff()
|
|
* @param {boolean=} opt_onlyClosePopups Whether only popups should be closed.
|
|
* @alias Blockly.hideChaff
|
|
*/
|
|
const hideChaff = function(opt_onlyClosePopups) {
|
|
deprecation.warn(
|
|
'Blockly.hideChaff', 'September 2021', 'September 2022',
|
|
'workspace.hideChaff');
|
|
common.getMainWorkspace().hideChaff(opt_onlyClosePopups);
|
|
};
|
|
exports.hideChaff = hideChaff;
|
|
|
|
/**
|
|
* Returns the main workspace. Returns the last used main workspace (based on
|
|
* focus). Try not to use this function, particularly if there are multiple
|
|
* Blockly instances on a page.
|
|
* @return {!Workspace} The main workspace.
|
|
* @alias Blockly.getMainWorkspace
|
|
*/
|
|
exports.getMainWorkspace = common.getMainWorkspace;
|
|
|
|
/**
|
|
* Define blocks from an array of JSON block definitions, as might be generated
|
|
* by the Blockly Developer Tools.
|
|
* @param {!Array<!Object>} jsonArray An array of JSON block definitions.
|
|
* @alias Blockly.defineBlocksWithJsonArray
|
|
*/
|
|
exports.defineBlocksWithJsonArray = common.defineBlocksWithJsonArray;
|
|
|
|
/**
|
|
* Is the given string a number (includes negative and decimals).
|
|
* @param {string} str Input string.
|
|
* @return {boolean} True if number, false otherwise.
|
|
* @deprecated
|
|
* @alias Blockly.isNumber
|
|
*/
|
|
const isNumber = function(str) {
|
|
deprecation.warn(
|
|
'Blockly.isNumber', 'December 2021', 'December 2022',
|
|
'Blockly.utils.string.isNumber');
|
|
return utils.string.isNumber(str);
|
|
};
|
|
exports.isNumber = isNumber;
|
|
|
|
/**
|
|
* Set the parent container. This is the container element that the WidgetDiv,
|
|
* DropDownDiv, and Tooltip are rendered into the first time `Blockly.inject`
|
|
* is called.
|
|
* This method is a NOP if called after the first ``Blockly.inject``.
|
|
* @param {!Element} container The container element.
|
|
* @alias Blockly.setParentContainer
|
|
*/
|
|
exports.setParentContainer = common.setParentContainer;
|
|
|
|
/** Aliases. */
|
|
|
|
/**
|
|
* @see colour.hueToHex
|
|
* @deprecated Use Blockly.utils.colour.hueToHex (September 2021).
|
|
* @alias Blockly.hueToHex
|
|
*/
|
|
exports.hueToHex = colour.hueToHex;
|
|
|
|
/**
|
|
* @see browserEvents.bind
|
|
* @alias Blockly.bindEvent_
|
|
*/
|
|
exports.bindEvent_ = browserEvents.bind;
|
|
|
|
/**
|
|
* @see browserEvents.unbind
|
|
* @alias Blockly.unbindEvent_
|
|
*/
|
|
exports.unbindEvent_ = browserEvents.unbind;
|
|
|
|
/**
|
|
* @see browserEvents.conditionalBind
|
|
* @alias Blockly.bindEventWithChecks_
|
|
*/
|
|
exports.bindEventWithChecks_ = browserEvents.conditionalBind;
|
|
|
|
/**
|
|
* @see constants.ALIGN.LEFT
|
|
* @alias Blockly.ALIGN_LEFT
|
|
*/
|
|
exports.ALIGN_LEFT = constants.ALIGN.LEFT;
|
|
|
|
/**
|
|
* @see constants.ALIGN.CENTRE
|
|
* @alias Blockly.ALIGN_CENTRE
|
|
*/
|
|
exports.ALIGN_CENTRE = constants.ALIGN.CENTRE;
|
|
|
|
/**
|
|
* @see constants.ALIGN.RIGHT
|
|
* @alias Blockly.ALIGN_RIGHT
|
|
*/
|
|
exports.ALIGN_RIGHT = constants.ALIGN.RIGHT;
|
|
|
|
/**
|
|
* @see common.svgResize
|
|
*/
|
|
exports.svgResize = common.svgResize;
|
|
|
|
/**
|
|
* Aliases for constants used for connection and input types.
|
|
*/
|
|
|
|
/**
|
|
* @see ConnectionType.INPUT_VALUE
|
|
* @alias Blockly.INPUT_VALUE
|
|
*/
|
|
exports.INPUT_VALUE = ConnectionType.INPUT_VALUE;
|
|
|
|
/**
|
|
* @see ConnectionType.OUTPUT_VALUE
|
|
* @alias Blockly.OUTPUT_VALUE
|
|
*/
|
|
exports.OUTPUT_VALUE = ConnectionType.OUTPUT_VALUE;
|
|
|
|
/**
|
|
* @see ConnectionType.NEXT_STATEMENT
|
|
* @alias Blockly.NEXT_STATEMENT
|
|
*/
|
|
exports.NEXT_STATEMENT = ConnectionType.NEXT_STATEMENT;
|
|
|
|
/**
|
|
* @see ConnectionType.PREVIOUS_STATEMENT
|
|
* @alias Blockly.PREVIOUS_STATEMENT
|
|
*/
|
|
exports.PREVIOUS_STATEMENT = ConnectionType.PREVIOUS_STATEMENT;
|
|
|
|
/**
|
|
* @see inputTypes.DUMMY_INPUT
|
|
* @alias Blockly.DUMMY_INPUT
|
|
*/
|
|
exports.DUMMY_INPUT = inputTypes.DUMMY;
|
|
|
|
/**
|
|
* Aliases for toolbox positions.
|
|
*/
|
|
|
|
/**
|
|
* @see toolbox.Position.TOP
|
|
* @alias Blockly.TOOLBOX_AT_TOP
|
|
*/
|
|
exports.TOOLBOX_AT_TOP = toolbox.Position.TOP;
|
|
|
|
/**
|
|
* @see toolbox.Position.BOTTOM
|
|
* @alias Blockly.TOOLBOX_AT_BOTTOM
|
|
*/
|
|
exports.TOOLBOX_AT_BOTTOM = toolbox.Position.BOTTOM;
|
|
|
|
/**
|
|
* @see toolbox.Position.LEFT
|
|
* @alias Blockly.TOOLBOX_AT_LEFT
|
|
*/
|
|
exports.TOOLBOX_AT_LEFT = toolbox.Position.LEFT;
|
|
|
|
/**
|
|
* @see toolbox.Position.RIGHT
|
|
* @alias Blockly.TOOLBOX_AT_RIGHT
|
|
*/
|
|
exports.TOOLBOX_AT_RIGHT = toolbox.Position.RIGHT;
|
|
|
|
// Aliases to allow external code to access these values for legacy reasons.
|
|
exports.LINE_MODE_MULTIPLIER = internalConstants.LINE_MODE_MULTIPLIER;
|
|
exports.PAGE_MODE_MULTIPLIER = internalConstants.PAGE_MODE_MULTIPLIER;
|
|
exports.DRAG_RADIUS = internalConstants.DRAG_RADIUS;
|
|
exports.FLYOUT_DRAG_RADIUS = internalConstants.FLYOUT_DRAG_RADIUS;
|
|
exports.SNAP_RADIUS = internalConstants.SNAP_RADIUS;
|
|
exports.CONNECTING_SNAP_RADIUS = internalConstants.CONNECTING_SNAP_RADIUS;
|
|
exports.CURRENT_CONNECTION_PREFERENCE =
|
|
internalConstants.CURRENT_CONNECTION_PREFERENCE;
|
|
exports.BUMP_DELAY = internalConstants.BUMP_DELAY;
|
|
exports.BUMP_RANDOMNESS = internalConstants.BUMP_RANDOMNESS;
|
|
exports.COLLAPSE_CHARS = internalConstants.COLLAPSE_CHARS;
|
|
exports.LONGPRESS = internalConstants.LONGPRESS;
|
|
exports.SOUND_LIMIT = internalConstants.SOUND_LIMIT;
|
|
exports.DRAG_STACK = internalConstants.DRAG_STACK;
|
|
exports.HSV_SATURATION = internalConstants.HSV_SATURATION;
|
|
exports.HSV_VALUE = internalConstants.HSV_VALUE;
|
|
exports.SPRITE = internalConstants.SPRITE;
|
|
exports.DRAG_NONE = internalConstants.DRAG_NONE;
|
|
exports.DRAG_STICKY = internalConstants.DRAG_STICKY;
|
|
exports.DRAG_BEGIN = internalConstants.DRAG_BEGIN;
|
|
exports.DRAG_FREE = internalConstants.DRAG_FREE;
|
|
exports.OPPOSITE_TYPE = internalConstants.OPPOSITE_TYPE;
|
|
exports.VARIABLE_CATEGORY_NAME = internalConstants.VARIABLE_CATEGORY_NAME;
|
|
exports.VARIABLE_DYNAMIC_CATEGORY_NAME =
|
|
internalConstants.VARIABLE_DYNAMIC_CATEGORY_NAME;
|
|
exports.PROCEDURE_CATEGORY_NAME = internalConstants.PROCEDURE_CATEGORY_NAME;
|
|
exports.RENAME_VARIABLE_ID = internalConstants.RENAME_VARIABLE_ID;
|
|
exports.DELETE_VARIABLE_ID = internalConstants.DELETE_VARIABLE_ID;
|
|
exports.COLLAPSED_INPUT_NAME = constants.COLLAPSED_INPUT_NAME;
|
|
exports.COLLAPSED_FIELD_NAME = constants.COLLAPSED_FIELD_NAME;
|
|
|
|
// Re-export submodules that no longer declareLegacyNamespace.
|
|
exports.ASTNode = ASTNode;
|
|
exports.BasicCursor = BasicCursor;
|
|
exports.Block = Block;
|
|
exports.BlocklyOptions = BlocklyOptions;
|
|
exports.BlockDragger = BlockDragger;
|
|
exports.BlockDragSurfaceSvg = BlockDragSurfaceSvg;
|
|
exports.BlockSvg = BlockSvg;
|
|
exports.Blocks = Blocks;
|
|
exports.Bubble = Bubble;
|
|
exports.BubbleDragger = BubbleDragger;
|
|
exports.CollapsibleToolboxCategory = CollapsibleToolboxCategory;
|
|
exports.Comment = Comment;
|
|
exports.ComponentManager = ComponentManager;
|
|
exports.Connection = Connection;
|
|
exports.ConnectionType = ConnectionType;
|
|
exports.ConnectionChecker = ConnectionChecker;
|
|
exports.ConnectionDB = ConnectionDB;
|
|
exports.ContextMenu = ContextMenu;
|
|
exports.ContextMenuItems = ContextMenuItems;
|
|
exports.ContextMenuRegistry = ContextMenuRegistry;
|
|
exports.Css = Css;
|
|
exports.Cursor = Cursor;
|
|
exports.DeleteArea = DeleteArea;
|
|
exports.DragTarget = DragTarget;
|
|
exports.DropDownDiv = DropDownDiv;
|
|
exports.Events = Events;
|
|
exports.Extensions = Extensions;
|
|
exports.Field = Field;
|
|
exports.FieldAngle = FieldAngle;
|
|
exports.FieldCheckbox = FieldCheckbox;
|
|
exports.FieldColour = FieldColour;
|
|
exports.FieldDropdown = FieldDropdown;
|
|
exports.FieldImage = FieldImage;
|
|
exports.FieldLabel = FieldLabel;
|
|
exports.FieldLabelSerializable = FieldLabelSerializable;
|
|
exports.FieldMultilineInput = FieldMultilineInput;
|
|
exports.FieldNumber = FieldNumber;
|
|
exports.FieldTextInput = FieldTextInput;
|
|
exports.FieldVariable = FieldVariable;
|
|
exports.Flyout = Flyout;
|
|
exports.FlyoutButton = FlyoutButton;
|
|
exports.FlyoutMetricsManager = FlyoutMetricsManager;
|
|
exports.Generator = Generator;
|
|
exports.Gesture = Gesture;
|
|
exports.Grid = Grid;
|
|
exports.HorizontalFlyout = HorizontalFlyout;
|
|
exports.IASTNodeLocation = IASTNodeLocation;
|
|
exports.IASTNodeLocationSvg = IASTNodeLocationSvg;
|
|
exports.IASTNodeLocationWithBlock = IASTNodeLocationWithBlock;
|
|
exports.IAutoHideable = IAutoHideable;
|
|
exports.IBlockDragger = IBlockDragger;
|
|
exports.IBoundedElement = IBoundedElement;
|
|
exports.IBubble = IBubble;
|
|
exports.ICollapsibleToolboxItem = ICollapsibleToolboxItem;
|
|
exports.IComponent = IComponent;
|
|
exports.IConnectionChecker = IConnectionChecker;
|
|
exports.IContextMenu = IContextMenu;
|
|
exports.Icon = Icon;
|
|
exports.ICopyable = ICopyable;
|
|
exports.IDeletable = IDeletable;
|
|
exports.IDeleteArea = IDeleteArea;
|
|
exports.IDragTarget = IDragTarget;
|
|
exports.IDraggable = IDraggable;
|
|
exports.IFlyout = IFlyout;
|
|
exports.IKeyboardAccessible = IKeyboardAccessible;
|
|
exports.IMetricsManager = IMetricsManager;
|
|
exports.IMovable = IMovable;
|
|
exports.Input = Input;
|
|
exports.InsertionMarkerManager = InsertionMarkerManager;
|
|
exports.IPositionable = IPositionable;
|
|
exports.IRegistrable = IRegistrable;
|
|
exports.IRegistrableField = IRegistrableField;
|
|
exports.ISelectable = ISelectable;
|
|
exports.ISelectableToolboxItem = ISelectableToolboxItem;
|
|
exports.IStyleable = IStyleable;
|
|
exports.IToolbox = IToolbox;
|
|
exports.IToolboxItem = IToolboxItem;
|
|
exports.Marker = Marker;
|
|
exports.MarkerManager = MarkerManager;
|
|
exports.Menu = Menu;
|
|
exports.MenuItem = MenuItem;
|
|
exports.MetricsManager = MetricsManager;
|
|
exports.Mutator = Mutator;
|
|
exports.Names = Names;
|
|
exports.Options = Options;
|
|
exports.Procedures = Procedures;
|
|
exports.RenderedConnection = RenderedConnection;
|
|
exports.Scrollbar = Scrollbar;
|
|
exports.ScrollbarPair = ScrollbarPair;
|
|
exports.ShortcutItems = ShortcutItems;
|
|
exports.ShortcutRegistry = ShortcutRegistry;
|
|
exports.TabNavigateCursor = TabNavigateCursor;
|
|
exports.Theme = Theme;
|
|
exports.Themes = Themes;
|
|
exports.ThemeManager = ThemeManager;
|
|
exports.Toolbox = Toolbox;
|
|
exports.ToolboxCategory = ToolboxCategory;
|
|
exports.ToolboxItem = ToolboxItem;
|
|
exports.ToolboxSeparator = ToolboxSeparator;
|
|
exports.Tooltip = Tooltip;
|
|
exports.Touch = Touch;
|
|
exports.TouchGesture = TouchGesture;
|
|
exports.Trashcan = Trashcan;
|
|
exports.VariableMap = VariableMap;
|
|
exports.VariableModel = VariableModel;
|
|
exports.Variables = Variables;
|
|
exports.VariablesDynamic = VariablesDynamic;
|
|
exports.VerticalFlyout = VerticalFlyout;
|
|
exports.Warning = Warning;
|
|
exports.WidgetDiv = WidgetDiv;
|
|
exports.Workspace = Workspace;
|
|
exports.WorkspaceAudio = WorkspaceAudio;
|
|
exports.WorkspaceComment = WorkspaceComment;
|
|
exports.WorkspaceCommentSvg = WorkspaceCommentSvg;
|
|
exports.WorkspaceDragSurfaceSvg = WorkspaceDragSurfaceSvg;
|
|
exports.WorkspaceDragger = WorkspaceDragger;
|
|
exports.WorkspaceSvg = WorkspaceSvg;
|
|
exports.Xml = Xml;
|
|
exports.ZoomControls = ZoomControls;
|
|
exports.blockAnimations = blockAnimations;
|
|
exports.blockRendering = blockRendering;
|
|
exports.browserEvents = browserEvents;
|
|
exports.bumpObjects = bumpObjects;
|
|
exports.clipboard = clipboard;
|
|
exports.common = common;
|
|
/** @deprecated Use Blockly.ConnectionType instead. */
|
|
exports.connectionTypes = ConnectionType;
|
|
exports.constants = constants;
|
|
exports.dialog = dialog;
|
|
exports.fieldRegistry = fieldRegistry;
|
|
exports.geras = geras;
|
|
exports.inject = inject;
|
|
exports.inputTypes = inputTypes;
|
|
exports.loopMixin = loopMixin;
|
|
exports.minimalist = minimalist;
|
|
exports.registry = registry;
|
|
exports.thrasos = thrasos;
|
|
exports.uiPosition = uiPosition;
|
|
exports.utils = utils;
|
|
exports.zelos = zelos;
|
|
|
|
// Temporary hack to copy accessor properties from exports to the
|
|
// global Blockly object as the routine to copy exports in
|
|
// goog.exportPath_ (see closure/goog/base.js) invoked by
|
|
// declareLegacyNamespace only copies normal data properties, not
|
|
// accessors. This can be removed once all remaining calls to
|
|
// declareLegacyNamspace have been removed.
|
|
//
|
|
// This is only needed in uncompiled mode (see
|
|
// google/blockly-samples#902); in compiled mode the exports object is
|
|
// already the value of globalThis['Blockly'].
|
|
//
|
|
// Note that this code will still attempt to redefine accessors on a
|
|
// previously-imported copy of the Blockly library if both are
|
|
// imported in uncompiled mode. This will fail with TypeError as the
|
|
// accessors are nonconfigurable (which is good, as otherwise one
|
|
// accessors on one copy would call get/set functions on the other
|
|
// copy!)
|
|
if (!COMPILED && typeof globalThis['Blockly'] === 'object' &&
|
|
globalThis['Blockly'] !== exports) {
|
|
const descriptors = Object.getOwnPropertyDescriptors(exports);
|
|
const accessors = {};
|
|
for (const key in descriptors) {
|
|
if (descriptors[key].get || descriptors[key].set) {
|
|
accessors[key] = descriptors[key];
|
|
}
|
|
}
|
|
Object.defineProperties(globalThis['Blockly'], accessors);
|
|
}
|