mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-07-05 08:30:25 -04:00
* JSON definitions for colour blocks (#838)
Replaces old colour block definitions with a Blockly.defineBlocksWithJsonArray(..) call. Generator unit tests continue to load and pass, signifying compatibility with prior block definitions.
Replaces extension 'math_number_tooltip' with the reusable 'parent_tooltip_when_inline' extension, also used by colour_picker. Includes tests.
* Rewrite tree.service.js.
- Remove unnecessary code and functions.
- Add documentation where needed.
- Fix a bug arising when a block on the workspace is attached to an existing link.
* Use setValue in fieldTextInput so that procedure renaming works
* Further cleanup and removal of unnecessary functions. Pull some strings out for i18n.
* Use bindEvent_ instead of bindEventWithChecks_ for longStop
* Clean up workspace.component.js. When moving a block from one place to another, move all blocks after it too, and adjust the active descs accordingly.
* Unit tests for JSON block definitions (just the start) (#850)
* Beginnings of a JSON block definition unit test set.
* Dispose of unit test workspaces and blocks in finally blocks.
* Clarify JSON error message by echoing arg notation.
* New blocks text_count, text_replace, and text_reverse (#830)
Includes generators for all languages and units tests on those generators.
* Fixing combo boxes getting out-of-sync with NVDA.
Combo boxes need to be special cased like text input. Also, Escape is
a reserved button in NVDA, so I added Enter as a way to "submit and
move up a level" in addition to escape, so these boxes can be edited
while NVDA is on.
* Temporary fix for broken text field validation.
* rebuild
* Add a block to reverse a list (#844)
* Localisation updates from https://translatewiki.net.
* Porting math.js blocks to JSON (#846)
Moving all `math.js` definitions into a single JSON array, complete with i18n syntax for all messages, dropdowns, and tooltips.
Adding Blockly.Extensions.buildTooltipForDropdown(..) to facilitate the creation and error-checking of tooltips that update based on the value of a dropdown.
Now warn on raw string in JSON 'extensions'.
* Fixing JSON support for images in dropdowns. Adding tests. (#851)
Fixes #848.
* Update README.md
Add a link to our forum.
* Correcting math_change color
* Enable custom flyout categories.
* Add some safety
* Update the set of reserved words in Python to reflect the current state of Python (2.7 and 3.6). (#861)
* Localisation updates from https://translatewiki.net.
* .getOptions_() to .getOptions() (#869)
Fixes #867.
* Blockly.Extensions.buildTooltipForDropdown(..): Deferred validation. (#870)
Defer tooltip message string check until after load, when all Blockly.Msg should be loaded.
Avoids validation in headless mode, due to lack of document.readyState.
* annotation updates
* annotation updates
* jsdoc corrections (#874)
* Remove use of Array.prototype.includes which is not implemented in IE or Edge < 14. Fixes google/blockly#876.
* Attempt to work around the IE/Edge bug where `getComputedTextLength()` throws an exception when the SVG node is not visible. This workaround forces a re-render, which in turn, forces a re-calculation of the node width once a block is inserted into the workspace SVG. This workaround is only executed on IE and Edge. See https://groups.google.com/forum/#!topic/blockly/T8IR4t4xAIY for the initial discussion of this issue.
* Change CSS transforms to work with older browsers (#879)
* Change the setting of the CSS transform properties on SVG nodes to set both the unprefixed version and the `-webkit-` prefixed version so that Blockly correctly renders in order browsers, such as Safari < 9 and iOS Safari < 9.2. For discussion of this issue, see https://groups.google.com/forum/#!topic/blockly/o3pERaRQhSg
* Correct the separation between the CSS transform property and the rest of the CSS that was in the variable misleadingly called "transform".
* Don't try to get block position in a headless workspace
* Stop bumping neighbours in headless blockly
* Place context menu correctly on touch
* Clear all active desc ids when the 'Erase Workspace' button is pressed.
* Fix a bug where splicing a block between two linked blocks disconnects the group and messes up the focus.
* Deleting a top-level block does not cause blocks after it to be deleted. Properly handle the active desc for this case.
* Localisation updates from https://translatewiki.net.
* Use the empty field placeholder for dropdowns that do not have a value selected.
* Bugfix for #892. I incorrectly converted one CSS transform setting to use the cross-browser setting function in 40a063763c74b3f712c3057565966c25d5cfdb10. (#895)
* Adding @namespace annotations for JSDoc. (#900)
* Fix typo causing TypeError (#901)
* Pinning the angular2 dependency, and including licenses. (#893)
* Add skeleton for tests on rendered workspaces
* Fix some lint errors
* Localisation updates from https://translatewiki.net.
* Correct changedState in setWarningText() (#908)
When clearing warnings on blocks with IDs, the changedState variable should be true if the text changed. This will trigger the block being reshaped and remove the space for the notification icon (this.bumpNeighbours_).
* Adds Block.prototype.mixin() and Blockly.Extensions.registerMixin(). (#907)
Adds Block.prototype.mixin() and Blockly.Extensions.registerMixin().
This adds support for a common use pattern in extensions, and adds
error checking to avoid future incompatibilities.
* Porting Logic blocks to JSON (#913)
Extensions, mixins, mutators and constants now grouped under the new namespace Blockly.Constants.Logic.
* Improving errors/warnings with Block.toDevString() and Connection.toString(). (#911)
* Add isEditable to field, and add tests
* Separate tests
* Blockly.Constants.Math and Blockly.Constants.Colour extension constants (#916)
Also, correcting quotes in logic.js.
* Correction to logic_ternary type check (#920)
* Porting Loop blocks to JSON (#919)
* Improved documentation on `Blockly.Extensions.buildTooltipForDropdown`
* Replaced incorrect uses of `@mixes` JSDoc annotation (on mixin extensions) with `@augments Blockly.Block`.
* Added Blockly.Extensions.buildTooltipWithFieldValue() extension helper.
* Workspace isDraggable
* JSONify simple list blocks
* JSONify variable blocks
* Initial text block, with a mixin to generate quote image fields. (#923)
Text block now uses the extension "text_quotes", supported by Blockly.Constants.Text.QUOTE_IMAGE_MIXIN.quoteField_(fieldName), so that each platform can use the best platform appropriate image (size, density, etc.) for the quotes.
* Add no-op stub .neighbors() for headless Connection.
* Adding tests for logic_ternary block in a new jsunit test framework.
* Correcting output of the logic_null block.
* Potential bug fix for issue #661
* extension controls_if => controls_if_mutator.
* Renamed extension function constant, and moved variables into the mixin.
* Dereference string table references when loading variable fields from JSON.
* Moving FieldImage string dereferencing back into Block.interpolate_() (part of jsonInit()). This sets a clear boundary of where dereferencing should happen.
Towards this, I've added message dereferencing for other field types here, as well. I've used a pattern of field-type specific helper functions.
* Addressing comments.
* .utils.replaceMessageReferences(..) now gracefully returns non-string arguments.
* Clarification update.
Unraveling nested ternaries in Blockly.utils.tokenizeInterpolation_()
* Code correction from previous commit. Moved style to css.js and set ROUNDING=15;
* Fixing Enter so it properly propogates to dropdown selection. (#934)
Fixing FieldSegment so it updates dropdowns when the underlying dropdown changes.
* Localisation updates from https://translatewiki.net.
* Make variable add set/get block in context menu obey block limits
* Localisation updates from https://translatewiki.net.
* Use mutator extension for controls_if block
* Fix #946. Don't check for presence of constants.js
* Fix #945 (annotations) and an eslint issue (constant condition)
* Localisation updates from https://translatewiki.net.
* Fix #950: BlockFactory typo and copypasta
* Add safety checks for mutators and non-mutator extensions
* Handle mutations with both mixins and functions
* Adding warning on duplicate JSON block definition.
* period
* Make some functions private and add tests
* Localisation updates from https://translatewiki.net.
* Update help URL per #937.
Replace URL usages of %28 and %29 with normal parenthesis characters. (They aren't replaced by JavaScript's encodeURIComponent() function, and seem to work just fine without them.)
Added missing semicolon in build.py.
* Typo in comment.
* Make it easier to read the code that creates the variable category in the tolbox
* Adding Blockly.Xml.appendDomToWorkspace() (#962)
This is a copy (with additional comments) of PR #822 (and also #961) by @qnoirhomme with unrelated files removed. See #822 for full review.
* Annotation fixes
* Fix bug #904 by explicitly grabbing focus on the workspace svg element. (#964)
* Potential fix for #888. Stops checking whether we are mid workspace drag since we do not always get mosue up events when blockly is in an iframe. (#899)
* Adding new minimap demo
* Basic code style changes. Adding a few more comments. Return early if disableScrollChange in onScrollChange listener.
* `unction` to `function` corrects #962 (#970)
* Cross browser friendly fix for #904. This calls blur and focus from … (#972)
* Cross browser friendly fix for #904. This calls blur and focus from workspace.markFocused and removes the event listener on focus events. markFocused is called from all of our mouse down handlers, which triggers the focus event leading to an infinite loop of focus. As far as I can tell, there are no uses of the focus handler that actually did anything for us.
* Localisation updates from https://translatewiki.net.
* Another attempt to fix #904 to keep the page from jumping to the focused workspace in IE 11 (#974)
* Adding horizontal scrolling. Changed scroll change callbacks from onScroll_ to setHandlePosition. onScroll_ is not challed when workspace is dragged.
* set background color to lilac if opening the playground from file:
* Registering mousemove and mouseup listener in mousedown event. Mousemove and Mouseup events are now listening over document.
* Localisation updates from https://translatewiki.net.
* Fix #967 by overriding the updateWidth method in FieldImage blocks to be a no-op. FieldImage fields should not change size after the width is set in init. The updateWidth and, therefore, getCachedWidth is now being called by BlockSvg renderFields_ (see commit d55d9cbd9f
). IIUC, updateWidth/getCachedWidth was only called from render before which is overridden in FieldImage to be a no-op already. (#979)
* Fix #969
* Localisation updates from https://translatewiki.net.
* Fix #986. Looks like the original PR just forgot this block. (#992)
* rebuild develop (#996)
* Added the variable modal and component and implemented basic renaming functionality. (#991)
* Fixing commenting from the last commit. (#1000)
* Localisation updates from https://translatewiki.net.
* RemoveAttribute doesn't work on SVG elements in IE 10. Use setAttribute to null instead.
* Adding the remove variable modal and functionality to accessible Blockly. (#1011)
* Minimap position bug fix for browsers other than chrome. Added touch support.
* Adding an add variable modal to accessible Blockly. (#1015)
* Adding the remove variable modal and functionality to accessible Blockly.
* Adding the add variable modal for accessible Blockly.
* Block browser context menu in the toolbox and flyout
* Add links to the dev registration form and contributor guidelines
* Miscellaneous comment cleanup
* Adding the common modal class. (#1017)
Centralizes accessible modal behavior.
* - Changed error message referencing 'procedure' instead of 'function' (#1019)
- Added iOS specific UI messages
- Fixed bug with js_to_json.py script where it didn't recognize ' character
* - Allows use of Blockly's messaging format for category name, colour,… (#1028)
...in toolbox XML.
- Updated code editor demo to use this message format
- Re-built blockly_compressed.js
* Making text_count use a text color (like text_length, which also returns a number). (#1027)
* Enable google/blockly with continuous build on travis ci (#1023) (#1035)
* create .travis for ci job
* initial checkin for blocky-web travis ci job
* rename file to .travis.yaml for typo
* remove after_script
* added cache
* rename .travis.yaml to .travis.yml
* Update .travis.yml
* include build script
* fix yaml file format issue
* debug install part
* debug build issue
* Update .travis.yml
* remove cache for now
* Update .travis.yml
* Update .travis.yml
* Update .travis.yml
* more debug info
* Update .travis.yml
* Update .travis.yml
* fix typo
* installing chrome browser
* remove chrome setting config
* run build.py as part of npm install
* Update .travis.yml
* update karma dependency
* use karma as test runner
* fix typo
* remove karma test for now
* Update .travis.yml
* Update package.json
* add npm test target
* add browserstack-runner depdendency
* update browser support
* fix typo for test target
* fix chrome typo
* added closure dependency
* add google-closure-library
* include blockly_uncompressed.js and core.js dependency
* uncomment out core/*.js files
* add kama job as part of install
* remove browserstack add on for now
* fix karma config typo
* add karma-closure
* add os support
* remove typo config
* include more closure files
* change os back to linux
* use closure-library from node_modules
* change log level back to INFO
* change npm test target to use open browser command instead of karma
* change travis test target to use open command instead of karma
* list current directory
* find what's in current dir
* typo command
* Update .travis.yml
* typo again
* open right index.html
* use right path for index.html
* xdg-open to open default browser on travis
* exit browser after 5s wait
* change timeout to 1 min
* exit after opening up browser
* use browser only
* use karma
* remove un-needed dependency
* clean up script section
* fix typo
* update build status on readme
* initial commit for selenium integration tests
* update selenium jar path
* fix test_runner.js typo
* add more debug info
* check java version
* add && instead of 9288
* fix java path
* add logic to check if selenium is running or not
* add some deugging info
* initial commit to get chromedriver
* add chromedriver flag
* add get_chromedriver.sh to package.json and .travel
* change browser to chrome for now
* fix path issue
* update chromdriver path
* fix path issue again
* more debugging
* add debug msg
* fix typo
* minor fix for getting chromedriver
* install latest chrome browser
* clean up pakcage.json
* use npm target for test run
* remove removing trailing comma
* fix another trailing comma
* updated travis test target
* clean up scripts
* not sure nmp run preinstall
* redirect selenium log to tmp file
* revert writing console log to file
* update test summary
* more clean up
* minor clean up before pull request
* resolved closure-library conflict
1. add closure-library to dependencies instead of devDependencies.
2. add lint back in scripts block
* fix typo (adding comma) in script section
* Renames Blockly.workspaceDragSurface to Blockly.WorkspaceDragSurface.
Fixes #880.
* Ensure useDragSurface is a boolean.
Fixed #988
* use pretest instead of preinstall in package.json (#1043)
* cherry pick for pretest fix
* put pretest target to test_setup.sh
* fix conflict
* cherry pick for get_chromedriver.sh
* add some sleep to wait download to finish
* use node.js stable
* use npm test target
* field_angle renders degree symbol consistently.
Fixes #973
* bumpNeighbours_ function moved to block_svg.
Fixed #1009
* Update RegEx in js-to-json to match windowi eol (#1050)
The current regex only works with the "\n" line endings as it expects no characters after the optional ";" at the end of the line. In windows, if it adds the "\r" it counts as a characters and is not part of the line terminator so it doesn't match.
* Fix French translation of "colour with rgb" block (#1053)
"colorier", which is currently used, is a verb and proposed "couleur" is
a noun: the block in question does not change colour of anything, it
creates new colour instead, thus noun is more applicable.
Also, noun is used in French translation of "random colour" block:
"couleur aléatoire".
* Enforcing non-empty names on value inputs and statement inputs. (#1054)
* Correcting #1054 (#1056)
single quotes. better logic.
* Created a variable model with name, id, and type.
Created a jsunit test file for variable model.
* Change how blockly handles cursors. The old way was quite slow becau… (#1057)
* Change how blockly handles cursors. The old way was quite slow because it changed the stylesheet directly. See issue #981 for more details on implementation and tradeoffs. This changes makes the following high level changes: deprecate Blockly.Css.setCursor, use built in open and closed hand cursor instead of custom .cur files, add css to draggable objects to set the open and closed hand cursors.
* Rebuild blockly_uncompressed to pick up a testing change to make travis happy. Fix a build warning from a multi-line string in the process. (#1059)
* Merge master into develop (#1063)
- pick up translation changes
- clean up trailing spaces
* use goog.string.startswith instead of string.startswith (#1065)
* New jsinterpreter demo includes wait block. Both demos have improved UI for clarity. (#1001)
Refactor of interpreter demo
* Renamed demos/interpreter/index.html as demos/interpreter/step-execution.html (including redirect), and added demos/interpreter/async-execution.html.
* Refactored code to automatically generate/parse the blocks, eliminating the need for a "Parse JavaScript" button. Code is still shown in alert upon stepping to the first statement. Print statements now write to output <textarea> instead of modal dialogs.
* VariableMap and functions added.
* Create separate file for VariableMap and its functions.
* Fix #1069 (#1073)
* VariableMap and functions added.
* Fix #1051 (#1084)
* Improve errors when validating JSON block definitions. (#1086)
goog.asserts to not run from blockly_compressed.js. User data validation should always run.
* Dragging changes, rebased on develop (#1078)
* Add block drag surface translateSurfaceBy
* Add dragged connection manager
* Add gesture.js
* Add GestureHandler
* Implemented gesture skeleton
* Most basic workspace dragging
* Add dragged connection manager
* cleanup
* doc
* more cleanup
* Add gesture handler
* Add translateSurfaceInternal
* core/block_dragger.js
* cleanup
* Pull in changes to dragged connection manager
* Pull in changes to dragged connection manager
* comments
* more annotations
* Add workspace dragger
* Add coordinate annotations
* Start on block dragging
* Limit number of concurrent gestures
* Add some TODOs
* start using dragged connection manager
* Set origin correctly for dragging blocks
* Connect or delete at the end of a block drag.
* cleanup
* handle field clicks and block + workspace right-clicks
* move code into BlockDragger class, but still reach into Gesture internals a lot
* Clean up block dragger
* Call blockDragger constructor with correct arguments
* Enable block dragging in a mutator workspace
* Add workspace dragger
* click todos
* Drag flyout with background
* more dragging from flyout
* nit
* fix dragging from flyouts
* Remove unused code and rename gestureHandler to gestureDB
* Rename gesture handler
* Added some jsdoc in gesture.js
* Update some docs
* Move some code to block_svg and clean up code
* Lots of coordinate annotations
* Fix block dragging when zoomed.
* Remove built files from branch
* More dragging work (#1026)
-- Drag bubbles while dragging blocks
-- Use bindEventWithChecks to work in touch on Android. Not tested anywhere else yet.
-- Handle dragging blocks while zoomed
-- Handle dragging blocks in mutators
-- Handle right-clicks (I hope)
-- Removed lots of unused code
* More dragging work (#1048)
- Removed gestureDB
- Removing uses of terminateDrag
- Cleaned up disposal code
* Dragging bugfixes (#1058)
- Get rid of flyout.dragMode_ and blockly.dragMode_
- Make drags from the flyout start from the top block in the group
- Block tooltips from being scheduled or shown during gestures
- Don't resize mutator bubbles mid-drag
* Fix events in new dragging (#1060)
* rebuild for testing
* unbuild
* Fix events
* rebuild
* Fix up cursors
* Use language files from develop
* Remove handled TODOS
* attempt to fix IE rerendering bug, and recalculate workspace positions on scroll
* Rebuild all the things
* Comment cleanup; annotations; delete unused variables.
* Tidy up context menu code. (#1081)
* add osx travis test run job (#1074)
* Names are correctly fetched from VariableModels!
* add more wait time for test setup (#1091)
* Work around timing issue with travis osx issue (#1092)
* add more wait time for test setup
* increase selenium wait time
* add more wait
* Fix #1077 by adding a rule to cover the toolbox labels too. (#1099)
* Assign variable UUID to field_variable dropdown.
* Change registration link to a static one (#1106)
This lets us redirect to a different form if we change it in the future.
* Edit generators to read in Variable Models.
* Add VariableMap requirement to workspace.
* Changed parameter name in workspace for clarity.
* Add type, id, and info to the generated xml.
Add xml tests for fieldToDom.
Update workspace tests to pass with new changes.
* Fix apostrophe in tooltips and helpurls (#1111)
* Click events on shadow blocks have the correct id (#1089)
* Add image_onclick option (#1080)
* Cleanup: semicolons, spacing, etc. (#1116)
* Spelling. Spelling is hard.
* Add variable info to xml generated in variables.js
* Add missing CLAs info to the contributing file (#1119)
* Add missing CLAs info to the contributing file
* Added larger changes paragraph
* Replacing latest prettifier hosted in repo with latest version at rawgit CDN. (#1120)
* Forgot update code demo (#1121)
* Move audio code to a new file (#1122)
* move audio code to a new file
* dispose
* null check
* Make flyout get variables from target workspace's variableMap.
* Require VariableModel in field_variable.js.
* Update contributing.md (#1126)
* Include variables at top of serialization.
* Move blockSvg.getHeightWidth to block_render_svg.js (#1118)
* Deserialization variables at top.
* Create grid object (#1131)
* Create grid object
* Doc
* Units! Thanks @RoboErikG
* Add our sound files in other formats
* Remove duplicate merged code
* Remove translation files
* Cleanup duplicate functions
* Add back scrollbar code
* Fix variable related issues
* Revert workspace variable creation change
* Delete language files
* Appease linter
* Remove duplication
* Add spaces to jsdoc line
1857 lines
58 KiB
JavaScript
1857 lines
58 KiB
JavaScript
/**
|
|
* @license
|
|
* Visual Blocks Editor
|
|
*
|
|
* Copyright 2014 Google Inc.
|
|
* https://developers.google.com/blockly/
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Object representing a workspace rendered as SVG.
|
|
* @author fraser@google.com (Neil Fraser)
|
|
*/
|
|
'use strict';
|
|
|
|
goog.provide('Blockly.WorkspaceSvg');
|
|
|
|
// TODO(scr): Fix circular dependencies
|
|
//goog.require('Blockly.BlockSvg');
|
|
goog.require('Blockly.Colours');
|
|
goog.require('Blockly.ConnectionDB');
|
|
goog.require('Blockly.constants');
|
|
goog.require('Blockly.DropDownDiv');
|
|
goog.require('Blockly.Events');
|
|
goog.require('Blockly.Gesture');
|
|
goog.require('Blockly.Grid');
|
|
goog.require('Blockly.Options');
|
|
goog.require('Blockly.ScrollbarPair');
|
|
goog.require('Blockly.Touch');
|
|
goog.require('Blockly.Trashcan');
|
|
//goog.require('Blockly.VerticalFlyout');
|
|
goog.require('Blockly.Workspace');
|
|
goog.require('Blockly.WorkspaceAudio');
|
|
goog.require('Blockly.WorkspaceDragSurfaceSvg');
|
|
goog.require('Blockly.Xml');
|
|
goog.require('Blockly.ZoomControls');
|
|
|
|
goog.require('goog.array');
|
|
goog.require('goog.dom');
|
|
goog.require('goog.math.Coordinate');
|
|
goog.require('goog.userAgent');
|
|
|
|
|
|
/**
|
|
* Class for a workspace. This is an onscreen area with optional trashcan,
|
|
* scrollbars, bubbles, and dragging.
|
|
* @param {!Blockly.Options} options Dictionary of options.
|
|
* @param {Blockly.BlockDragSurfaceSvg=} opt_blockDragSurface Drag surface for
|
|
* blocks.
|
|
* @param {Blockly.WorkspaceDragSurfaceSvg=} opt_wsDragSurface Drag surface for
|
|
* the workspace.
|
|
* @extends {Blockly.Workspace}
|
|
* @constructor
|
|
*/
|
|
Blockly.WorkspaceSvg = function(options, opt_blockDragSurface, opt_wsDragSurface) {
|
|
Blockly.WorkspaceSvg.superClass_.constructor.call(this, options);
|
|
this.getMetrics =
|
|
options.getMetrics || Blockly.WorkspaceSvg.getTopLevelWorkspaceMetrics_;
|
|
this.setMetrics =
|
|
options.setMetrics || Blockly.WorkspaceSvg.setTopLevelWorkspaceMetrics_;
|
|
|
|
Blockly.ConnectionDB.init(this);
|
|
|
|
if (opt_blockDragSurface) {
|
|
this.blockDragSurface_ = opt_blockDragSurface;
|
|
}
|
|
|
|
if (opt_wsDragSurface) {
|
|
this.workspaceDragSurface_ = opt_wsDragSurface;
|
|
}
|
|
|
|
this.useWorkspaceDragSurface_ =
|
|
this.workspaceDragSurface_ && Blockly.utils.is3dSupported();
|
|
|
|
/**
|
|
* List of currently highlighted blocks. Block highlighting is often used to
|
|
* visually mark blocks currently being executed.
|
|
* @type !Array.<!Blockly.BlockSvg>
|
|
* @private
|
|
*/
|
|
this.highlightedBlocks_ = [];
|
|
|
|
/**
|
|
* Object in charge of loading, storing, and playing audio for a workspace.
|
|
* @type {Blockly.WorkspaceAudio}
|
|
* @private
|
|
*/
|
|
this.audioManager_ = new Blockly.WorkspaceAudio(options.parentWorkspace);
|
|
|
|
/**
|
|
* This workspace's grid object or null.
|
|
* @type {Blockly.Grid}
|
|
* @private
|
|
*/
|
|
this.grid_ = this.options.gridPattern ?
|
|
new Blockly.Grid(options.gridPattern, options.gridOptions) : null;
|
|
|
|
this.registerToolboxCategoryCallback(Blockly.VARIABLE_CATEGORY_NAME,
|
|
Blockly.Variables.flyoutCategory);
|
|
this.registerToolboxCategoryCallback(Blockly.PROCEDURE_CATEGORY_NAME,
|
|
Blockly.Procedures.flyoutCategory);
|
|
};
|
|
goog.inherits(Blockly.WorkspaceSvg, Blockly.Workspace);
|
|
|
|
/**
|
|
* A wrapper function called when a resize event occurs.
|
|
* You can pass the result to `unbindEvent_`.
|
|
* @type {Array.<!Array>}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_ = null;
|
|
|
|
/**
|
|
* The render status of an SVG workspace.
|
|
* Returns `true` for visible workspaces and `false` for non-visible,
|
|
* or headless, workspaces.
|
|
* @type {boolean}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.rendered = true;
|
|
|
|
/**
|
|
* Is this workspace the surface for a flyout?
|
|
* @type {boolean}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.isFlyout = false;
|
|
|
|
/**
|
|
* Is this workspace the surface for a mutator?
|
|
* @type {boolean}
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.isMutator = false;
|
|
|
|
/**
|
|
* Whether this workspace has resizes enabled.
|
|
* Disable during batch operations for a performance improvement.
|
|
* @type {boolean}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.resizesEnabled_ = true;
|
|
|
|
/**
|
|
* Current horizontal scrolling offset in pixel units.
|
|
* @type {number}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.scrollX = 0;
|
|
|
|
/**
|
|
* Current vertical scrolling offset in pixel units.
|
|
* @type {number}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.scrollY = 0;
|
|
|
|
/**
|
|
* Horizontal scroll value when scrolling started in pixel units.
|
|
* @type {number}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.startScrollX = 0;
|
|
|
|
/**
|
|
* Vertical scroll value when scrolling started in pixel units.
|
|
* @type {number}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.startScrollY = 0;
|
|
|
|
/**
|
|
* Distance from mouse to object being dragged.
|
|
* @type {goog.math.Coordinate}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.dragDeltaXY_ = null;
|
|
|
|
/**
|
|
* Current scale.
|
|
* @type {number}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.scale = 1;
|
|
|
|
/**
|
|
* The workspace's trashcan (if any).
|
|
* @type {Blockly.Trashcan}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.trashcan = null;
|
|
|
|
/**
|
|
* This workspace's scrollbars, if they exist.
|
|
* @type {Blockly.ScrollbarPair}
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.scrollbar = null;
|
|
|
|
/**
|
|
* The current gesture in progress on this workspace, if any.
|
|
* @type {Blockly.Gesture}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.currentGesture_ = null;
|
|
|
|
/**
|
|
* This workspace's surface for dragging blocks, if it exists.
|
|
* @type {Blockly.BlockDragSurfaceSvg}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.blockDragSurface_ = null;
|
|
|
|
/**
|
|
* This workspace's drag surface, if it exists.
|
|
* @type {Blockly.WorkspaceDragSurfaceSvg}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.workspaceDragSurface_ = null;
|
|
|
|
/**
|
|
* Whether to move workspace to the drag surface when it is dragged.
|
|
* True if it should move, false if it should be translated directly.
|
|
* @type {boolean}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.useWorkspaceDragSurface_ = false;
|
|
|
|
/**
|
|
* Whether the drag surface is actively in use. When true, calls to
|
|
* translate will translate the drag surface instead of the translating the
|
|
* workspace directly.
|
|
* This is set to true in setupDragSurface and to false in resetDragSurface.
|
|
* @type {boolean}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.isDragSurfaceActive_ = false;
|
|
|
|
/**
|
|
* Last known position of the page scroll.
|
|
* This is used to determine whether we have recalculated screen coordinate
|
|
* stuff since the page scrolled.
|
|
* @type {!goog.math.Coordinate}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.lastRecordedPageScroll_ = null;
|
|
|
|
/**
|
|
* Map from function names to callbacks, for deciding what to do when a button
|
|
* is clicked.
|
|
* @type {!Object<string, function(!Blockly.FlyoutButton)>}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_ = {};
|
|
|
|
/**
|
|
* Map from function names to callbacks, for deciding what to do when a custom
|
|
* toolbox category is opened.
|
|
* @type {!Object<string, function(!Blockly.Workspace):!Array<!Element>>}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_ = {};
|
|
|
|
/**
|
|
* Inverted screen CTM, for use in mouseToSvg.
|
|
* @type {SVGMatrix}
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.inverseScreenCTM_ = null;
|
|
|
|
/**
|
|
* Getter for the inverted screen CTM.
|
|
* @return {SVGMatrix} The matrix to use in mouseToSvg
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getInverseScreenCTM = function() {
|
|
return this.inverseScreenCTM_;
|
|
};
|
|
|
|
/**
|
|
* Update the inverted screen CTM.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM = function() {
|
|
var ctm = this.getParentSvg().getScreenCTM();
|
|
if (ctm) {
|
|
this.inverseScreenCTM_ = ctm.inverse();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Return the absolute coordinates of the top-left corner of this element,
|
|
* scales that after canvas SVG element, if it's a descendant.
|
|
* The origin (0,0) is the top-left corner of the Blockly SVG.
|
|
* @param {!Element} element Element to find the coordinates of.
|
|
* @return {!goog.math.Coordinate} Object with .x and .y properties.
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getSvgXY = function(element) {
|
|
var x = 0;
|
|
var y = 0;
|
|
var scale = 1;
|
|
if (goog.dom.contains(this.getCanvas(), element) ||
|
|
goog.dom.contains(this.getBubbleCanvas(), element)) {
|
|
// Before the SVG canvas, scale the coordinates.
|
|
scale = this.scale;
|
|
}
|
|
do {
|
|
// Loop through this block and every parent.
|
|
var xy = Blockly.utils.getRelativeXY(element);
|
|
if (element == this.getCanvas() ||
|
|
element == this.getBubbleCanvas()) {
|
|
// After the SVG canvas, don't scale the coordinates.
|
|
scale = 1;
|
|
}
|
|
x += xy.x * scale;
|
|
y += xy.y * scale;
|
|
element = element.parentNode;
|
|
} while (element && element != this.getParentSvg());
|
|
return new goog.math.Coordinate(x, y);
|
|
};
|
|
|
|
/**
|
|
* Save resize handler data so we can delete it later in dispose.
|
|
* @param {!Array.<!Array>} handler Data that can be passed to unbindEvent_.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.setResizeHandlerWrapper = function(handler) {
|
|
this.resizeHandlerWrapper_ = handler;
|
|
};
|
|
|
|
/**
|
|
* Create the workspace DOM elements.
|
|
* @param {string=} opt_backgroundClass Either 'blocklyMainBackground' or
|
|
* 'blocklyMutatorBackground'.
|
|
* @return {!Element} The workspace's SVG group.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
|
|
/**
|
|
* <g class="blocklyWorkspace">
|
|
* <rect class="blocklyMainBackground" height="100%" width="100%"></rect>
|
|
* [Trashcan and/or flyout may go here]
|
|
* <g class="blocklyBlockCanvas"></g>
|
|
* <g class="blocklyBubbleCanvas"></g>
|
|
* </g>
|
|
* @type {SVGElement}
|
|
*/
|
|
this.svgGroup_ = Blockly.utils.createSvgElement('g',
|
|
{'class': 'blocklyWorkspace'}, null);
|
|
|
|
// Note that a <g> alone does not receive mouse events--it must have a
|
|
// valid target inside it. If no background class is specified, as in the
|
|
// flyout, the workspace will not receive mouse events.
|
|
if (opt_backgroundClass) {
|
|
/** @type {SVGElement} */
|
|
this.svgBackground_ = Blockly.utils.createSvgElement('rect',
|
|
{'height': '100%', 'width': '100%', 'class': opt_backgroundClass},
|
|
this.svgGroup_);
|
|
|
|
if (opt_backgroundClass == 'blocklyMainBackground' && this.grid_) {
|
|
this.svgBackground_.style.fill =
|
|
'url(#' + this.grid_.getPatternId() + ')';
|
|
}
|
|
}
|
|
/** @type {SVGElement} */
|
|
this.svgBlockCanvas_ = Blockly.utils.createSvgElement('g',
|
|
{'class': 'blocklyBlockCanvas'}, this.svgGroup_, this);
|
|
/** @type {SVGElement} */
|
|
this.svgBubbleCanvas_ = Blockly.utils.createSvgElement('g',
|
|
{'class': 'blocklyBubbleCanvas'}, this.svgGroup_, this);
|
|
var bottom = Blockly.Scrollbar.scrollbarThickness;
|
|
if (this.options.hasTrashcan) {
|
|
bottom = this.addTrashcan_(bottom);
|
|
}
|
|
if (this.options.zoomOptions && this.options.zoomOptions.controls) {
|
|
bottom = this.addZoomControls_(bottom);
|
|
}
|
|
|
|
if (!this.isFlyout) {
|
|
Blockly.bindEventWithChecks_(this.svgGroup_, 'mousedown', this,
|
|
this.onMouseDown_);
|
|
if (this.options.zoomOptions && this.options.zoomOptions.wheel) {
|
|
// Mouse-wheel.
|
|
Blockly.bindEventWithChecks_(this.svgGroup_, 'wheel', this,
|
|
this.onMouseWheel_);
|
|
}
|
|
}
|
|
|
|
// Determine if there needs to be a category tree, or a simple list of
|
|
// blocks. This cannot be changed later, since the UI is very different.
|
|
if (this.options.hasCategories) {
|
|
/**
|
|
* @type {Blockly.Toolbox}
|
|
* @private
|
|
*/
|
|
this.toolbox_ = new Blockly.Toolbox(this);
|
|
}
|
|
if (this.grid_) {
|
|
this.grid_.update(this.scale);
|
|
}
|
|
this.recordDeleteAreas();
|
|
return this.svgGroup_;
|
|
};
|
|
|
|
/**
|
|
* Dispose of this workspace.
|
|
* Unlink from all DOM elements to prevent memory leaks.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.dispose = function() {
|
|
// Stop rerendering.
|
|
this.rendered = false;
|
|
if (this.currentGesture_) {
|
|
this.currentGesture_.cancel();
|
|
}
|
|
Blockly.WorkspaceSvg.superClass_.dispose.call(this);
|
|
if (this.svgGroup_) {
|
|
goog.dom.removeNode(this.svgGroup_);
|
|
this.svgGroup_ = null;
|
|
}
|
|
this.svgBlockCanvas_ = null;
|
|
this.svgBubbleCanvas_ = null;
|
|
if (this.toolbox_) {
|
|
this.toolbox_.dispose();
|
|
this.toolbox_ = null;
|
|
}
|
|
if (this.flyout_) {
|
|
this.flyout_.dispose();
|
|
this.flyout_ = null;
|
|
}
|
|
if (this.trashcan) {
|
|
this.trashcan.dispose();
|
|
this.trashcan = null;
|
|
}
|
|
if (this.scrollbar) {
|
|
this.scrollbar.dispose();
|
|
this.scrollbar = null;
|
|
}
|
|
if (this.zoomControls_) {
|
|
this.zoomControls_.dispose();
|
|
this.zoomControls_ = null;
|
|
}
|
|
|
|
if (this.audioManager_) {
|
|
this.audioManager_.dispose();
|
|
this.audioManager_ = null;
|
|
}
|
|
|
|
if (this.grid_) {
|
|
this.grid_.dispose();
|
|
this.grid_ = null;
|
|
}
|
|
|
|
if (this.toolboxCategoryCallbacks_) {
|
|
this.toolboxCategoryCallbacks_ = null;
|
|
}
|
|
if (this.flyoutButtonCallbacks_) {
|
|
this.flyoutButtonCallbacks_ = null;
|
|
}
|
|
if (!this.options.parentWorkspace) {
|
|
// Top-most workspace. Dispose of the div that the
|
|
// svg is injected into (i.e. injectionDiv).
|
|
goog.dom.removeNode(this.getParentSvg().parentNode);
|
|
}
|
|
if (this.resizeHandlerWrapper_) {
|
|
Blockly.unbindEvent_(this.resizeHandlerWrapper_);
|
|
this.resizeHandlerWrapper_ = null;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Obtain a newly created block.
|
|
* @param {?string} prototypeName Name of the language object containing
|
|
* type-specific functions for this block.
|
|
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
|
|
* create a new ID.
|
|
* @return {!Blockly.BlockSvg} The created block.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.newBlock = function(prototypeName, opt_id) {
|
|
return new Blockly.BlockSvg(this, prototypeName, opt_id);
|
|
};
|
|
|
|
/**
|
|
* Add a trashcan.
|
|
* @param {number} bottom Distance from workspace bottom to bottom of trashcan.
|
|
* @return {number} Distance from workspace bottom to the top of trashcan.
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.addTrashcan_ = function(bottom) {
|
|
/** @type {Blockly.Trashcan} */
|
|
this.trashcan = new Blockly.Trashcan(this);
|
|
var svgTrashcan = this.trashcan.createDom();
|
|
this.svgGroup_.insertBefore(svgTrashcan, this.svgBlockCanvas_);
|
|
return this.trashcan.init(bottom);
|
|
};
|
|
|
|
/**
|
|
* Add zoom controls.
|
|
* @param {number} bottom Distance from workspace bottom to bottom of controls.
|
|
* @return {number} Distance from workspace bottom to the top of controls.
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.addZoomControls_ = function(bottom) {
|
|
/** @type {Blockly.ZoomControls} */
|
|
this.zoomControls_ = new Blockly.ZoomControls(this);
|
|
var svgZoomControls = this.zoomControls_.createDom();
|
|
this.svgGroup_.appendChild(svgZoomControls);
|
|
return this.zoomControls_.init(bottom);
|
|
};
|
|
|
|
/**
|
|
* Add a flyout element in an element with the given tag name.
|
|
* @param {string} tagName What type of tag the flyout belongs in.
|
|
* @return {!Element} The element containing the flyout dom.
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.addFlyout_ = function(tagName) {
|
|
var workspaceOptions = {
|
|
disabledPatternId: this.options.disabledPatternId,
|
|
parentWorkspace: this,
|
|
RTL: this.RTL,
|
|
oneBasedIndex: this.options.oneBasedIndex,
|
|
horizontalLayout: this.horizontalLayout,
|
|
toolboxPosition: this.options.toolboxPosition
|
|
};
|
|
if (this.horizontalLayout) {
|
|
this.flyout_ = new Blockly.HorizontalFlyout(workspaceOptions);
|
|
} else {
|
|
this.flyout_ = new Blockly.VerticalFlyout(workspaceOptions);
|
|
}
|
|
this.flyout_.autoClose = false;
|
|
|
|
// Return the element so that callers can place it in their desired
|
|
// spot in the dom. For exmaple, mutator flyouts do not go in the same place
|
|
// as main workspace flyouts.
|
|
return this.flyout_.createDom(tagName);
|
|
};
|
|
|
|
/**
|
|
* Getter for the flyout associated with this workspace. This flyout may be
|
|
* owned by either the toolbox or the workspace, depending on toolbox
|
|
* configuration. It will be null if there is no flyout.
|
|
* @return {Blockly.Flyout} The flyout on this workspace.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getFlyout = function() {
|
|
if (this.flyout_) {
|
|
return this.flyout_;
|
|
}
|
|
if (this.toolbox_) {
|
|
return this.toolbox_.flyout_;
|
|
}
|
|
return null;
|
|
};
|
|
|
|
/**
|
|
* Update items that use screen coordinate calculations
|
|
* because something has changed (e.g. scroll position, window size).
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.updateScreenCalculations_ = function() {
|
|
this.updateInverseScreenCTM();
|
|
this.recordDeleteAreas();
|
|
};
|
|
|
|
/**
|
|
* If enabled, resize the parts of the workspace that change when the workspace
|
|
* contents (e.g. block positions) change. This will also scroll the
|
|
* workspace contents if needed.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.resizeContents = function() {
|
|
if (!this.resizesEnabled_ || !this.rendered) {
|
|
return;
|
|
}
|
|
if (this.scrollbar) {
|
|
// TODO(picklesrus): Once rachel-fenichel's scrollbar refactoring
|
|
// is complete, call the method that only resizes scrollbar
|
|
// based on contents.
|
|
this.scrollbar.resize();
|
|
}
|
|
this.updateInverseScreenCTM();
|
|
};
|
|
|
|
/**
|
|
* Resize and reposition all of the workspace chrome (toolbox,
|
|
* trash, scrollbars etc.)
|
|
* This should be called when something changes that
|
|
* requires recalculating dimensions and positions of the
|
|
* trash, zoom, toolbox, etc. (e.g. window resize).
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.resize = function() {
|
|
if (this.toolbox_) {
|
|
this.toolbox_.position();
|
|
}
|
|
if (this.flyout_) {
|
|
this.flyout_.position();
|
|
}
|
|
if (this.trashcan) {
|
|
this.trashcan.position();
|
|
}
|
|
if (this.zoomControls_) {
|
|
this.zoomControls_.position();
|
|
}
|
|
if (this.scrollbar) {
|
|
this.scrollbar.resize();
|
|
}
|
|
this.updateScreenCalculations_();
|
|
};
|
|
|
|
/**
|
|
* Resizes and repositions workspace chrome if the page has a new
|
|
* scroll position.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.updateScreenCalculationsIfScrolled
|
|
= function() {
|
|
/* eslint-disable indent */
|
|
var currScroll = goog.dom.getDocumentScroll();
|
|
if (!goog.math.Coordinate.equals(this.lastRecordedPageScroll_,
|
|
currScroll)) {
|
|
this.lastRecordedPageScroll_ = currScroll;
|
|
this.updateScreenCalculations_();
|
|
}
|
|
}; /* eslint-enable indent */
|
|
|
|
/**
|
|
* Get the SVG element that forms the drawing surface.
|
|
* @return {!Element} SVG element.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getCanvas = function() {
|
|
return this.svgBlockCanvas_;
|
|
};
|
|
|
|
/**
|
|
* Get the SVG element that forms the bubble surface.
|
|
* @return {!SVGGElement} SVG element.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getBubbleCanvas = function() {
|
|
return this.svgBubbleCanvas_;
|
|
};
|
|
|
|
/**
|
|
* Get the SVG element that contains this workspace.
|
|
* @return {!Element} SVG element.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getParentSvg = function() {
|
|
if (this.cachedParentSvg_) {
|
|
return this.cachedParentSvg_;
|
|
}
|
|
var element = this.svgGroup_;
|
|
while (element) {
|
|
if (element.tagName == 'svg') {
|
|
this.cachedParentSvg_ = element;
|
|
return element;
|
|
}
|
|
element = element.parentNode;
|
|
}
|
|
return null;
|
|
};
|
|
|
|
/**
|
|
* Translate this workspace to new coordinates.
|
|
* @param {number} x Horizontal translation.
|
|
* @param {number} y Vertical translation.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.translate = function(x, y) {
|
|
if (this.useWorkspaceDragSurface_ && this.isDragSurfaceActive_) {
|
|
this.workspaceDragSurface_.translateSurface(x,y);
|
|
} else {
|
|
var translation = 'translate(' + x + ',' + y + ') ' +
|
|
'scale(' + this.scale + ')';
|
|
this.svgBlockCanvas_.setAttribute('transform', translation);
|
|
this.svgBubbleCanvas_.setAttribute('transform', translation);
|
|
}
|
|
// Now update the block drag surface if we're using one.
|
|
if (this.blockDragSurface_) {
|
|
this.blockDragSurface_.translateAndScaleGroup(x, y, this.scale);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Called at the end of a workspace drag to take the contents
|
|
* out of the drag surface and put them back into the workspace svg.
|
|
* Does nothing if the workspace drag surface is not enabled.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.resetDragSurface = function() {
|
|
// Don't do anything if we aren't using a drag surface.
|
|
if (!this.useWorkspaceDragSurface_) {
|
|
return;
|
|
}
|
|
|
|
this.isDragSurfaceActive_ = false;
|
|
|
|
var trans = this.workspaceDragSurface_.getSurfaceTranslation();
|
|
this.workspaceDragSurface_.clearAndHide(this.svgGroup_);
|
|
var translation = 'translate(' + trans.x + ',' + trans.y + ') ' +
|
|
'scale(' + this.scale + ')';
|
|
this.svgBlockCanvas_.setAttribute('transform', translation);
|
|
this.svgBubbleCanvas_.setAttribute('transform', translation);
|
|
};
|
|
|
|
/**
|
|
* Called at the beginning of a workspace drag to move contents of
|
|
* the workspace to the drag surface.
|
|
* Does nothing if the drag surface is not enabled.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.setupDragSurface = function() {
|
|
// Don't do anything if we aren't using a drag surface.
|
|
if (!this.useWorkspaceDragSurface_) {
|
|
return;
|
|
}
|
|
|
|
// This can happen if the user starts a drag, mouses up outside of the
|
|
// document where the mouseup listener is registered (e.g. outside of an
|
|
// iframe) and then moves the mouse back in the workspace. On mobile and ff,
|
|
// we get the mouseup outside the frame. On chrome and safari desktop we do
|
|
// not.
|
|
if (this.isDragSurfaceActive_) {
|
|
return;
|
|
}
|
|
|
|
this.isDragSurfaceActive_ = true;
|
|
|
|
// Figure out where we want to put the canvas back. The order
|
|
// in the is important because things are layered.
|
|
var previousElement = this.svgBlockCanvas_.previousSibling;
|
|
var width = this.getParentSvg().getAttribute("width");
|
|
var height = this.getParentSvg().getAttribute("height");
|
|
var coord = Blockly.utils.getRelativeXY(this.svgBlockCanvas_);
|
|
this.workspaceDragSurface_.setContentsAndShow(this.svgBlockCanvas_,
|
|
this.svgBubbleCanvas_, previousElement, width, height, this.scale);
|
|
this.workspaceDragSurface_.translateSurface(coord.x, coord.y);
|
|
};
|
|
|
|
/**
|
|
* Returns the horizontal offset of the workspace.
|
|
* Intended for LTR/RTL compatibility in XML.
|
|
* @return {number} Width.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getWidth = function() {
|
|
var metrics = this.getMetrics();
|
|
return metrics ? metrics.viewWidth / this.scale : 0;
|
|
};
|
|
|
|
/**
|
|
* Toggles the visibility of the workspace.
|
|
* Currently only intended for main workspace.
|
|
* @param {boolean} isVisible True if workspace should be visible.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.setVisible = function(isVisible) {
|
|
|
|
// Tell the scrollbar whether its container is visible so it can
|
|
// tell when to hide itself.
|
|
if (this.scrollbar) {
|
|
this.scrollbar.setContainerVisible(isVisible);
|
|
}
|
|
|
|
// Tell the flyout whether its container is visible so it can
|
|
// tell when to hide itself.
|
|
if (this.getFlyout()) {
|
|
this.getFlyout().setContainerVisible(isVisible);
|
|
}
|
|
|
|
this.getParentSvg().style.display = isVisible ? 'block' : 'none';
|
|
if (this.toolbox_) {
|
|
// Currently does not support toolboxes in mutators.
|
|
this.toolbox_.HtmlDiv.style.display = isVisible ? 'block' : 'none';
|
|
}
|
|
if (isVisible) {
|
|
this.render();
|
|
if (this.toolbox_) {
|
|
this.toolbox_.position();
|
|
}
|
|
} else {
|
|
Blockly.hideChaff(true);
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Render all blocks in workspace.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.render = function() {
|
|
// Generate list of all blocks.
|
|
var blocks = this.getAllBlocks();
|
|
// Render each block.
|
|
for (var i = blocks.length - 1; i >= 0; i--) {
|
|
blocks[i].render(false);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Was used back when block highlighting (for execution) and block selection
|
|
* (for editing) were the same thing.
|
|
* Any calls of this function can be deleted.
|
|
* @deprecated October 2016
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.traceOn = function() {
|
|
console.warn('Deprecated call to traceOn, delete this.');
|
|
};
|
|
|
|
/**
|
|
* Highlight or unhighlight a block in the workspace. Block highlighting is
|
|
* often used to visually mark blocks currently being executed.
|
|
* @param {?string} id ID of block to highlight/unhighlight,
|
|
* or null for no block (used to unhighlight all blocks).
|
|
* @param {boolean=} opt_state If undefined, highlight specified block and
|
|
* automatically unhighlight all others. If true or false, manually
|
|
* highlight/unhighlight the specified block.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.highlightBlock = function(id, opt_state) {
|
|
if (opt_state === undefined) {
|
|
// Unhighlight all blocks.
|
|
for (var i = 0, block; block = this.highlightedBlocks_[i]; i++) {
|
|
block.setHighlighted(false);
|
|
}
|
|
this.highlightedBlocks_.length = 0;
|
|
}
|
|
// Highlight/unhighlight the specified block.
|
|
var block = id ? this.getBlockById(id) : null;
|
|
if (block) {
|
|
var state = (opt_state === undefined) || opt_state;
|
|
// Using Set here would be great, but at the cost of IE10 support.
|
|
if (!state) {
|
|
goog.array.remove(this.highlightedBlocks_, block);
|
|
} else if (this.highlightedBlocks_.indexOf(block) == -1) {
|
|
this.highlightedBlocks_.push(block);
|
|
}
|
|
block.setHighlighted(state);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Glow/unglow a block in the workspace.
|
|
* @param {?string} id ID of block to find.
|
|
* @param {boolean} isGlowingBlock Whether to glow the block.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.glowBlock = function(id, isGlowingBlock) {
|
|
var block = null;
|
|
if (id) {
|
|
block = this.getBlockById(id);
|
|
if (!block) {
|
|
throw 'Tried to glow block that does not exist.';
|
|
}
|
|
}
|
|
block.setGlowBlock(isGlowingBlock);
|
|
};
|
|
|
|
/**
|
|
* Glow/unglow a stack in the workspace.
|
|
* @param {?string} id ID of block which starts the stack.
|
|
* @param {boolean} isGlowingStack Whether to glow the stack.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.glowStack = function(id, isGlowingStack) {
|
|
var block = null;
|
|
if (id) {
|
|
block = this.getBlockById(id);
|
|
if (!block) {
|
|
throw 'Tried to glow stack on block that does not exist.';
|
|
}
|
|
}
|
|
block.setGlowStack(isGlowingStack);
|
|
};
|
|
|
|
/**
|
|
* Visually report a value associated with a block.
|
|
* In Scratch, appears as a pop-up next to the block when a reporter block is clicked.
|
|
* @param {?string} id ID of block to report associated value.
|
|
* @param {?string} value String value to visually report.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.reportValue = function(id, value) {
|
|
var block = this.getBlockById(id);
|
|
if (!block) {
|
|
throw 'Tried to report value on block that does not exist.';
|
|
}
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
Blockly.DropDownDiv.clearContent();
|
|
var contentDiv = Blockly.DropDownDiv.getContentDiv();
|
|
var valueReportBox = goog.dom.createElement('div');
|
|
valueReportBox.setAttribute('class', 'valueReportBox');
|
|
valueReportBox.innerHTML = Blockly.utils.encodeEntities(value);
|
|
contentDiv.appendChild(valueReportBox);
|
|
Blockly.DropDownDiv.setColour(
|
|
Blockly.Colours.valueReportBackground,
|
|
Blockly.Colours.valueReportBorder
|
|
);
|
|
Blockly.DropDownDiv.showPositionedByBlock(this, block);
|
|
};
|
|
|
|
/**
|
|
* Paste the provided block onto the workspace.
|
|
* @param {!Element} xmlBlock XML block element.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
|
|
if (!this.rendered) {
|
|
return;
|
|
}
|
|
if (this.currentGesture_) {
|
|
this.currentGesture_.cancel(); // Dragging while pasting? No.
|
|
}
|
|
Blockly.Events.disable();
|
|
try {
|
|
var block = Blockly.Xml.domToBlock(xmlBlock, this);
|
|
// Rerender to get around problem with IE and Edge not measuring text
|
|
// correctly when it is hidden.
|
|
if (goog.userAgent.IE || goog.userAgent.EDGE) {
|
|
var blocks = block.getDescendants();
|
|
for (var i = blocks.length - 1; i >= 0; i--) {
|
|
blocks[i].render(false);
|
|
}
|
|
}
|
|
// Move the duplicate to original position.
|
|
var blockX = parseInt(xmlBlock.getAttribute('x'), 10);
|
|
var blockY = parseInt(xmlBlock.getAttribute('y'), 10);
|
|
if (!isNaN(blockX) && !isNaN(blockY)) {
|
|
if (this.RTL) {
|
|
blockX = -blockX;
|
|
}
|
|
// Offset block until not clobbering another block and not in connection
|
|
// distance with neighbouring blocks.
|
|
do {
|
|
var collide = false;
|
|
var allBlocks = this.getAllBlocks();
|
|
for (var i = 0, otherBlock; otherBlock = allBlocks[i]; i++) {
|
|
var otherXY = otherBlock.getRelativeToSurfaceXY();
|
|
if (Math.abs(blockX - otherXY.x) <= 1 &&
|
|
Math.abs(blockY - otherXY.y) <= 1) {
|
|
collide = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!collide) {
|
|
// Check for blocks in snap range to any of its connections.
|
|
var connections = block.getConnections_(false);
|
|
for (var i = 0, connection; connection = connections[i]; i++) {
|
|
var neighbour = connection.closest(Blockly.SNAP_RADIUS,
|
|
new goog.math.Coordinate(blockX, blockY));
|
|
if (neighbour.connection) {
|
|
collide = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (collide) {
|
|
if (this.RTL) {
|
|
blockX -= Blockly.SNAP_RADIUS;
|
|
} else {
|
|
blockX += Blockly.SNAP_RADIUS;
|
|
}
|
|
blockY += Blockly.SNAP_RADIUS * 2;
|
|
}
|
|
} while (collide);
|
|
block.moveBy(blockX, blockY);
|
|
}
|
|
} finally {
|
|
Blockly.Events.enable();
|
|
}
|
|
if (Blockly.Events.isEnabled() && !block.isShadow()) {
|
|
Blockly.Events.fire(new Blockly.Events.Create(block));
|
|
}
|
|
block.select();
|
|
};
|
|
|
|
/**
|
|
* Rename a variable by updating its name in the variable list.
|
|
* TODO: google/blockly:#468
|
|
* @param {string} oldName Variable to rename.
|
|
* @param {string} newName New variable name.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.renameVariable = function(oldName, newName) {
|
|
Blockly.WorkspaceSvg.superClass_.renameVariable.call(this, oldName, newName);
|
|
// Refresh the toolbox unless there's a drag in progress.
|
|
if (this.toolbox_ && this.toolbox_.flyout_ && !Blockly.Flyout.startFlyout_) {
|
|
this.toolbox_.refreshSelection();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Create a new variable with the given name. Update the flyout to show the new
|
|
* variable immediately.
|
|
* TODO: #468
|
|
* @param {string} name The new variable's name.
|
|
* @return {?Blockly.VariableModel} The newly created variable.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.createVariable = function(name) {
|
|
var newVar = Blockly.WorkspaceSvg.superClass_.createVariable.call(this, name);
|
|
// Don't refresh the toolbox if there's a drag in progress.
|
|
if (this.toolbox_ && this.toolbox_.flyout_ && !this.currentGesture_) {
|
|
this.toolbox_.refreshSelection();
|
|
}
|
|
return newVar;
|
|
};
|
|
|
|
/**
|
|
* Make a list of all the delete areas for this workspace.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.recordDeleteAreas = function() {
|
|
if (this.trashcan) {
|
|
this.deleteAreaTrash_ = this.trashcan.getClientRect();
|
|
} else {
|
|
this.deleteAreaTrash_ = null;
|
|
}
|
|
if (this.flyout_) {
|
|
this.deleteAreaToolbox_ = this.flyout_.getClientRect();
|
|
} else if (this.toolbox_) {
|
|
this.deleteAreaToolbox_ = this.toolbox_.getClientRect();
|
|
} else {
|
|
this.deleteAreaToolbox_ = null;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Is the mouse event over a delete area (toolbox or non-closing flyout)?
|
|
* @param {!Event} e Mouse move event.
|
|
* @return {?number} Null if not over a delete area, or an enum representing
|
|
* which delete area the event is over.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.isDeleteArea = function(e) {
|
|
var xy = new goog.math.Coordinate(e.clientX, e.clientY);
|
|
if (this.deleteAreaTrash_ && this.deleteAreaTrash_.contains(xy)) {
|
|
return Blockly.DELETE_AREA_TRASH;
|
|
}
|
|
if (this.deleteAreaToolbox_ && this.deleteAreaToolbox_.contains(xy)) {
|
|
return Blockly.DELETE_AREA_TOOLBOX;
|
|
}
|
|
return Blockly.DELETE_AREA_NONE;
|
|
};
|
|
|
|
/**
|
|
* Handle a mouse-down on SVG drawing surface.
|
|
* @param {!Event} e Mouse down event.
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.onMouseDown_ = function(e) {
|
|
var gesture = this.getGesture(e);
|
|
if (gesture) {
|
|
gesture.handleWsStart(e, this);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Start tracking a drag of an object on this workspace.
|
|
* @param {!Event} e Mouse down event.
|
|
* @param {!goog.math.Coordinate} xy Starting location of object.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.startDrag = function(e, xy) {
|
|
// Record the starting offset between the bubble's location and the mouse.
|
|
var point = Blockly.utils.mouseToSvg(e, this.getParentSvg(),
|
|
this.getInverseScreenCTM());
|
|
// Fix scale of mouse event.
|
|
point.x /= this.scale;
|
|
point.y /= this.scale;
|
|
this.dragDeltaXY_ = goog.math.Coordinate.difference(xy, point);
|
|
};
|
|
|
|
/**
|
|
* Track a drag of an object on this workspace.
|
|
* @param {!Event} e Mouse move event.
|
|
* @return {!goog.math.Coordinate} New location of object.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.moveDrag = function(e) {
|
|
var point = Blockly.utils.mouseToSvg(e, this.getParentSvg(),
|
|
this.getInverseScreenCTM());
|
|
// Fix scale of mouse event.
|
|
point.x /= this.scale;
|
|
point.y /= this.scale;
|
|
return goog.math.Coordinate.sum(this.dragDeltaXY_, point);
|
|
};
|
|
|
|
/**
|
|
* Is the user currently dragging a block or scrolling the flyout/workspace?
|
|
* @return {boolean} True if currently dragging or scrolling.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.isDragging = function() {
|
|
return this.currentGesture_ && this.currentGesture_.isDragging();
|
|
};
|
|
|
|
/**
|
|
* Is this workspace draggable and scrollable?
|
|
* @return {boolean} True if this workspace may be dragged.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.isDraggable = function() {
|
|
return !!this.scrollbar;
|
|
};
|
|
|
|
/**
|
|
* Handle a mouse-wheel on SVG drawing surface.
|
|
* @param {!Event} e Mouse wheel event.
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.onMouseWheel_ = function(e) {
|
|
// TODO: Remove gesture cancellation and compensate for coordinate skew during
|
|
// zoom.
|
|
if (this.currentGesture_) {
|
|
this.currentGesture_.cancel();
|
|
}
|
|
if (e.ctrlKey) {
|
|
// The vertical scroll distance that corresponds to a click of a zoom button.
|
|
var PIXELS_PER_ZOOM_STEP = 50;
|
|
var delta = -e.deltaY / PIXELS_PER_ZOOM_STEP;
|
|
var position = Blockly.utils.mouseToSvg(e, this.getParentSvg(),
|
|
this.getInverseScreenCTM());
|
|
this.zoom(position.x, position.y, delta);
|
|
} else {
|
|
// This is a regular mouse wheel event - scroll the workspace
|
|
// First hide the WidgetDiv without animation
|
|
// (mouse scroll makes field out of place with div)
|
|
Blockly.WidgetDiv.hide(true);
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
var x = this.scrollX - e.deltaX;
|
|
var y = this.scrollY - e.deltaY;
|
|
this.startDragMetrics = this.getMetrics();
|
|
this.scroll(x, y);
|
|
}
|
|
e.preventDefault();
|
|
};
|
|
|
|
/**
|
|
* Calculate the bounding box for the blocks on the workspace.
|
|
* Coordinate system: workspace coordinates.
|
|
*
|
|
* @return {Object} Contains the position and size of the bounding box
|
|
* containing the blocks on the workspace.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getBlocksBoundingBox = function() {
|
|
var topBlocks = this.getTopBlocks(false);
|
|
// There are no blocks, return empty rectangle.
|
|
if (!topBlocks.length) {
|
|
return {x: 0, y: 0, width: 0, height: 0};
|
|
}
|
|
|
|
// Initialize boundary using the first block.
|
|
var boundary = topBlocks[0].getBoundingRectangle();
|
|
|
|
// Start at 1 since the 0th block was used for initialization
|
|
for (var i = 1; i < topBlocks.length; i++) {
|
|
var blockBoundary = topBlocks[i].getBoundingRectangle();
|
|
if (blockBoundary.topLeft.x < boundary.topLeft.x) {
|
|
boundary.topLeft.x = blockBoundary.topLeft.x;
|
|
}
|
|
if (blockBoundary.bottomRight.x > boundary.bottomRight.x) {
|
|
boundary.bottomRight.x = blockBoundary.bottomRight.x;
|
|
}
|
|
if (blockBoundary.topLeft.y < boundary.topLeft.y) {
|
|
boundary.topLeft.y = blockBoundary.topLeft.y;
|
|
}
|
|
if (blockBoundary.bottomRight.y > boundary.bottomRight.y) {
|
|
boundary.bottomRight.y = blockBoundary.bottomRight.y;
|
|
}
|
|
}
|
|
return {
|
|
x: boundary.topLeft.x,
|
|
y: boundary.topLeft.y,
|
|
width: boundary.bottomRight.x - boundary.topLeft.x,
|
|
height: boundary.bottomRight.y - boundary.topLeft.y
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Clean up the workspace by ordering all the blocks in a column.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.cleanUp = function() {
|
|
Blockly.Events.setGroup(true);
|
|
var topBlocks = this.getTopBlocks(true);
|
|
var cursorY = 0;
|
|
for (var i = 0, block; block = topBlocks[i]; i++) {
|
|
var xy = block.getRelativeToSurfaceXY();
|
|
block.moveBy(-xy.x, cursorY - xy.y);
|
|
block.snapToGrid();
|
|
cursorY = block.getRelativeToSurfaceXY().y +
|
|
block.getHeightWidth().height + Blockly.BlockSvg.MIN_BLOCK_Y;
|
|
}
|
|
Blockly.Events.setGroup(false);
|
|
// Fire an event to allow scrollbars to resize.
|
|
this.resizeContents();
|
|
};
|
|
|
|
/**
|
|
* Show the context menu for the workspace.
|
|
* @param {!Event} e Mouse event.
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
|
|
if (this.options.readOnly || this.isFlyout) {
|
|
return;
|
|
}
|
|
var menuOptions = [];
|
|
var topBlocks = this.getTopBlocks(true);
|
|
var eventGroup = Blockly.utils.genUid();
|
|
var ws = this;
|
|
|
|
// Options to undo/redo previous action.
|
|
var undoOption = {};
|
|
undoOption.text = Blockly.Msg.UNDO;
|
|
undoOption.enabled = this.undoStack_.length > 0;
|
|
undoOption.callback = this.undo.bind(this, false);
|
|
menuOptions.push(undoOption);
|
|
var redoOption = {};
|
|
redoOption.text = Blockly.Msg.REDO;
|
|
redoOption.enabled = this.redoStack_.length > 0;
|
|
redoOption.callback = this.undo.bind(this, true);
|
|
menuOptions.push(redoOption);
|
|
|
|
// Option to clean up blocks.
|
|
if (this.scrollbar) {
|
|
var cleanOption = {};
|
|
cleanOption.text = Blockly.Msg.CLEAN_UP;
|
|
cleanOption.enabled = topBlocks.length > 1;
|
|
cleanOption.callback = this.cleanUp.bind(this);
|
|
menuOptions.push(cleanOption);
|
|
}
|
|
|
|
// Add a little animation to collapsing and expanding.
|
|
var DELAY = 10;
|
|
if (this.options.collapse) {
|
|
var hasCollapsedBlocks = false;
|
|
var hasExpandedBlocks = false;
|
|
for (var i = 0; i < topBlocks.length; i++) {
|
|
var block = topBlocks[i];
|
|
while (block) {
|
|
if (block.isCollapsed()) {
|
|
hasCollapsedBlocks = true;
|
|
} else {
|
|
hasExpandedBlocks = true;
|
|
}
|
|
block = block.getNextBlock();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Option to collapse or expand top blocks.
|
|
* @param {boolean} shouldCollapse Whether a block should collapse.
|
|
* @private
|
|
*/
|
|
var toggleOption = function(shouldCollapse) {
|
|
var ms = 0;
|
|
for (var i = 0; i < topBlocks.length; i++) {
|
|
var block = topBlocks[i];
|
|
while (block) {
|
|
setTimeout(block.setCollapsed.bind(block, shouldCollapse), ms);
|
|
block = block.getNextBlock();
|
|
ms += DELAY;
|
|
}
|
|
}
|
|
};
|
|
|
|
// Option to collapse top blocks.
|
|
var collapseOption = {enabled: hasExpandedBlocks};
|
|
collapseOption.text = Blockly.Msg.COLLAPSE_ALL;
|
|
collapseOption.callback = function() {
|
|
toggleOption(true);
|
|
};
|
|
menuOptions.push(collapseOption);
|
|
|
|
// Option to expand top blocks.
|
|
var expandOption = {enabled: hasCollapsedBlocks};
|
|
expandOption.text = Blockly.Msg.EXPAND_ALL;
|
|
expandOption.callback = function() {
|
|
toggleOption(false);
|
|
};
|
|
menuOptions.push(expandOption);
|
|
}
|
|
|
|
// Option to delete all blocks.
|
|
// Count the number of blocks that are deletable.
|
|
var deleteList = [];
|
|
function addDeletableBlocks(block) {
|
|
if (block.isDeletable()) {
|
|
deleteList = deleteList.concat(block.getDescendants());
|
|
} else {
|
|
var children = block.getChildren();
|
|
for (var i = 0; i < children.length; i++) {
|
|
addDeletableBlocks(children[i]);
|
|
}
|
|
}
|
|
}
|
|
for (var i = 0; i < topBlocks.length; i++) {
|
|
addDeletableBlocks(topBlocks[i]);
|
|
}
|
|
// Scratch-specific: don't count shadow blocks in delete count
|
|
var deleteCount = 0;
|
|
for (var i = 0; i < deleteList.length; i++) {
|
|
if (!deleteList[i].isShadow()) {
|
|
deleteCount++;
|
|
}
|
|
}
|
|
function deleteNext() {
|
|
Blockly.Events.setGroup(eventGroup);
|
|
var block = deleteList.shift();
|
|
if (block) {
|
|
if (block.workspace) {
|
|
block.dispose(false, true);
|
|
setTimeout(deleteNext, DELAY);
|
|
} else {
|
|
deleteNext();
|
|
}
|
|
}
|
|
Blockly.Events.setGroup(false);
|
|
}
|
|
|
|
var deleteOption = {
|
|
text: deleteCount == 1 ? Blockly.Msg.DELETE_BLOCK :
|
|
Blockly.Msg.DELETE_X_BLOCKS.replace('%1', String(deleteCount)),
|
|
enabled: deleteCount > 0,
|
|
callback: function() {
|
|
if (ws.currentGesture_) {
|
|
ws.currentGesture_.cancel();
|
|
}
|
|
if (deleteList.length < 2 ) {
|
|
deleteNext();
|
|
} else {
|
|
Blockly.confirm(Blockly.Msg.DELETE_ALL_BLOCKS.
|
|
replace('%1', deleteList.length),
|
|
function(ok) {
|
|
if (ok) {
|
|
deleteNext();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
menuOptions.push(deleteOption);
|
|
|
|
Blockly.ContextMenu.show(e, menuOptions, this.RTL);
|
|
};
|
|
|
|
/**
|
|
* Modify the block tree on the existing toolbox.
|
|
* @param {Node|string} tree DOM tree of blocks, or text representation of same.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.updateToolbox = function(tree) {
|
|
tree = Blockly.Options.parseToolboxTree(tree);
|
|
if (!tree) {
|
|
if (this.options.languageTree) {
|
|
throw 'Can\'t nullify an existing toolbox.';
|
|
}
|
|
return; // No change (null to null).
|
|
}
|
|
if (!this.options.languageTree) {
|
|
throw 'Existing toolbox is null. Can\'t create new toolbox.';
|
|
}
|
|
if (tree.getElementsByTagName('category').length) {
|
|
if (!this.toolbox_) {
|
|
throw 'Existing toolbox has no categories. Can\'t change mode.';
|
|
}
|
|
this.options.languageTree = tree;
|
|
this.toolbox_.populate_(tree);
|
|
this.toolbox_.position();
|
|
} else {
|
|
if (!this.flyout_) {
|
|
throw 'Existing toolbox has categories. Can\'t change mode.';
|
|
}
|
|
this.options.languageTree = tree;
|
|
this.flyout_.show(tree.childNodes);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Mark this workspace as the currently focused main workspace.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.markFocused = function() {
|
|
if (this.options.parentWorkspace) {
|
|
this.options.parentWorkspace.markFocused();
|
|
} else {
|
|
Blockly.mainWorkspace = this;
|
|
// We call e.preventDefault in many event handlers which means we
|
|
// need to explicitly grab focus (e.g from a textarea) because
|
|
// the browser will not do it for us. How to do this is browser dependant.
|
|
this.setBrowserFocus();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Set the workspace to have focus in the browser.
|
|
* @private
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.setBrowserFocus = function() {
|
|
// Blur whatever was focused since explcitly grabbing focus below does not
|
|
// work in Edge.
|
|
if (document.activeElement) {
|
|
document.activeElement.blur();
|
|
}
|
|
try {
|
|
// Focus the workspace SVG - this is for Chrome and Firefox.
|
|
this.getParentSvg().focus();
|
|
} catch (e) {
|
|
// IE and Edge do not support focus on SVG elements. When that fails
|
|
// above, get the injectionDiv (the workspace's parent) and focus that
|
|
// instead. This doesn't work in Chrome.
|
|
try {
|
|
// In IE11, use setActive (which is IE only) so the page doesn't scroll
|
|
// to the workspace gaining focus.
|
|
this.getParentSvg().parentNode.setActive();
|
|
} catch (e) {
|
|
// setActive support was discontinued in Edge so when that fails, call
|
|
// focus instead.
|
|
this.getParentSvg().parentNode.focus();
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Zooming the blocks centered in (x, y) coordinate with zooming in or out.
|
|
* @param {number} x X coordinate of center.
|
|
* @param {number} y Y coordinate of center.
|
|
* @param {number} amount Amount of zooming
|
|
* (negative zooms out and positive zooms in).
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.zoom = function(x, y, amount) {
|
|
var speed = this.options.zoomOptions.scaleSpeed;
|
|
var metrics = this.getMetrics();
|
|
var center = this.getParentSvg().createSVGPoint();
|
|
center.x = x;
|
|
center.y = y;
|
|
center = center.matrixTransform(this.getCanvas().getCTM().inverse());
|
|
x = center.x;
|
|
y = center.y;
|
|
var canvas = this.getCanvas();
|
|
// Scale factor.
|
|
var scaleChange = Math.pow(speed, amount);
|
|
// Clamp scale within valid range.
|
|
var newScale = this.scale * scaleChange;
|
|
if (newScale > this.options.zoomOptions.maxScale) {
|
|
scaleChange = this.options.zoomOptions.maxScale / this.scale;
|
|
} else if (newScale < this.options.zoomOptions.minScale) {
|
|
scaleChange = this.options.zoomOptions.minScale / this.scale;
|
|
}
|
|
if (this.scale == newScale) {
|
|
return; // No change in zoom.
|
|
}
|
|
if (this.scrollbar) {
|
|
var matrix = canvas.getCTM()
|
|
.translate(x * (1 - scaleChange), y * (1 - scaleChange))
|
|
.scale(scaleChange);
|
|
// newScale and matrix.a should be identical (within a rounding error).
|
|
this.scrollX = matrix.e - metrics.absoluteLeft;
|
|
this.scrollY = matrix.f - metrics.absoluteTop;
|
|
}
|
|
this.setScale(newScale);
|
|
// Hide the WidgetDiv without animation (zoom makes field out of place with div)
|
|
Blockly.WidgetDiv.hide(true);
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
};
|
|
|
|
/**
|
|
* Zooming the blocks centered in the center of view with zooming in or out.
|
|
* @param {number} type Type of zooming (-1 zooming out and 1 zooming in).
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.zoomCenter = function(type) {
|
|
var metrics = this.getMetrics();
|
|
var x = metrics.viewWidth / 2;
|
|
var y = metrics.viewHeight / 2;
|
|
this.zoom(x, y, type);
|
|
};
|
|
|
|
/**
|
|
* Zoom the blocks to fit in the workspace if possible.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.zoomToFit = function() {
|
|
var metrics = this.getMetrics();
|
|
var blocksBox = this.getBlocksBoundingBox();
|
|
var blocksWidth = blocksBox.width;
|
|
var blocksHeight = blocksBox.height;
|
|
if (!blocksWidth) {
|
|
return; // Prevents zooming to infinity.
|
|
}
|
|
var workspaceWidth = metrics.viewWidth;
|
|
var workspaceHeight = metrics.viewHeight;
|
|
if (this.flyout_) {
|
|
workspaceWidth -= this.flyout_.width_;
|
|
}
|
|
if (!this.scrollbar) {
|
|
// Origin point of 0,0 is fixed, blocks will not scroll to center.
|
|
blocksWidth += metrics.contentLeft;
|
|
blocksHeight += metrics.contentTop;
|
|
}
|
|
var ratioX = workspaceWidth / blocksWidth;
|
|
var ratioY = workspaceHeight / blocksHeight;
|
|
this.setScale(Math.min(ratioX, ratioY));
|
|
this.scrollCenter();
|
|
};
|
|
|
|
/**
|
|
* Center the workspace.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.scrollCenter = function() {
|
|
if (!this.scrollbar) {
|
|
// Can't center a non-scrolling workspace.
|
|
return;
|
|
}
|
|
// Hide the WidgetDiv without animation (zoom makes field out of place with div)
|
|
Blockly.WidgetDiv.hide(true);
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
Blockly.hideChaff(false);
|
|
var metrics = this.getMetrics();
|
|
var x = (metrics.contentWidth - metrics.viewWidth) / 2;
|
|
if (this.flyout_) {
|
|
x -= this.flyout_.width_ / 2;
|
|
}
|
|
var y = (metrics.contentHeight - metrics.viewHeight) / 2;
|
|
this.scrollbar.set(x, y);
|
|
};
|
|
|
|
/**
|
|
* Set the workspace's zoom factor.
|
|
* @param {number} newScale Zoom factor.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.setScale = function(newScale) {
|
|
if (this.options.zoomOptions.maxScale &&
|
|
newScale > this.options.zoomOptions.maxScale) {
|
|
newScale = this.options.zoomOptions.maxScale;
|
|
} else if (this.options.zoomOptions.minScale &&
|
|
newScale < this.options.zoomOptions.minScale) {
|
|
newScale = this.options.zoomOptions.minScale;
|
|
}
|
|
this.scale = newScale;
|
|
if (this.grid_) {
|
|
this.grid_.update(this.scale);
|
|
}
|
|
if (this.scrollbar) {
|
|
this.scrollbar.resize();
|
|
} else {
|
|
this.translate(this.scrollX, this.scrollY);
|
|
}
|
|
Blockly.hideChaff(false);
|
|
if (this.flyout_) {
|
|
// No toolbox, resize flyout.
|
|
this.flyout_.reflow();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Scroll the workspace by a specified amount, keeping in the bounds.
|
|
* Be sure to set this.startDragMetrics with cached metrics before calling.
|
|
* @param {number} x Target X to scroll to
|
|
* @param {number} y Target Y to scroll to
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.scroll = function(x, y) {
|
|
var metrics = this.startDragMetrics; // Cached values
|
|
x = Math.min(x, -metrics.contentLeft);
|
|
y = Math.min(y, -metrics.contentTop);
|
|
x = Math.max(x, metrics.viewWidth - metrics.contentLeft -
|
|
metrics.contentWidth);
|
|
y = Math.max(y, metrics.viewHeight - metrics.contentTop -
|
|
metrics.contentHeight);
|
|
// When the workspace starts scrolling, hide the WidgetDiv without animation.
|
|
// This is to prevent a dispoal animation from happening in the wrong location.
|
|
Blockly.WidgetDiv.hide(true);
|
|
Blockly.DropDownDiv.hideWithoutAnimation();
|
|
// Move the scrollbars and the page will scroll automatically.
|
|
this.scrollbar.set(-x - metrics.contentLeft,
|
|
-y - metrics.contentTop);
|
|
};
|
|
|
|
/**
|
|
* Update the workspace's stack glow radius to be proportional to scale.
|
|
* Ensures that stack glows always appear to be a fixed size.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.updateStackGlowScale_ = function() {
|
|
// No such def in the flyout workspace.
|
|
if (this.options.stackGlowBlur) {
|
|
this.options.stackGlowBlur.setAttribute('stdDeviation',
|
|
Blockly.STACK_GLOW_RADIUS / this.scale
|
|
);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Return an object with all the metrics required to size scrollbars for a
|
|
* top level workspace. The following properties are computed:
|
|
* Coordinate system: pixel coordinates.
|
|
* .viewHeight: Height of the visible rectangle,
|
|
* .viewWidth: Width of the visible rectangle,
|
|
* .contentHeight: Height of the contents,
|
|
* .contentWidth: Width of the content,
|
|
* .viewTop: Offset of top edge of visible rectangle from parent,
|
|
* .viewLeft: Offset of left edge of visible rectangle from parent,
|
|
* .contentTop: Offset of the top-most content from the y=0 coordinate,
|
|
* .contentLeft: Offset of the left-most content from the x=0 coordinate.
|
|
* .absoluteTop: Top-edge of view.
|
|
* .absoluteLeft: Left-edge of view.
|
|
* .toolboxWidth: Width of toolbox, if it exists. Otherwise zero.
|
|
* .toolboxHeight: Height of toolbox, if it exists. Otherwise zero.
|
|
* .flyoutWidth: Width of the flyout if it is always open. Otherwise zero.
|
|
* .flyoutHeight: Height of flyout if it is always open. Otherwise zero.
|
|
* .toolboxPosition: Top, bottom, left or right.
|
|
* @return {!Object} Contains size and position metrics of a top level
|
|
* workspace.
|
|
* @private
|
|
* @this Blockly.WorkspaceSvg
|
|
*/
|
|
Blockly.WorkspaceSvg.getTopLevelWorkspaceMetrics_ = function() {
|
|
var svgSize = Blockly.svgSize(this.getParentSvg());
|
|
if (this.toolbox_) {
|
|
if (this.toolboxPosition == Blockly.TOOLBOX_AT_TOP ||
|
|
this.toolboxPosition == Blockly.TOOLBOX_AT_BOTTOM) {
|
|
svgSize.height -= this.toolbox_.getHeight();
|
|
} else if (this.toolboxPosition == Blockly.TOOLBOX_AT_LEFT ||
|
|
this.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) {
|
|
svgSize.width -= this.toolbox_.getWidth();
|
|
}
|
|
}
|
|
// Set the margin to match the flyout's margin so that the workspace does
|
|
// not jump as blocks are added.
|
|
var MARGIN = Blockly.Flyout.prototype.CORNER_RADIUS - 1;
|
|
var viewWidth = svgSize.width - MARGIN;
|
|
var viewHeight = svgSize.height - MARGIN;
|
|
|
|
var blockBox = this.getBlocksBoundingBox();
|
|
|
|
// Fix scale.
|
|
var contentWidth = blockBox.width * this.scale;
|
|
var contentHeight = blockBox.height * this.scale;
|
|
var contentX = blockBox.x * this.scale;
|
|
var contentY = blockBox.y * this.scale;
|
|
if (this.scrollbar) {
|
|
// Add a border around the content that is at least half a screenful wide.
|
|
// Ensure border is wide enough that blocks can scroll over entire screen.
|
|
var leftEdge = Math.min(contentX - viewWidth / 2,
|
|
contentX + contentWidth - viewWidth);
|
|
var rightEdge = Math.max(contentX + contentWidth + viewWidth / 2,
|
|
contentX + viewWidth);
|
|
var topEdge = Math.min(contentY - viewHeight / 2,
|
|
contentY + contentHeight - viewHeight);
|
|
var bottomEdge = Math.max(contentY + contentHeight + viewHeight / 2,
|
|
contentY + viewHeight);
|
|
} else {
|
|
var leftEdge = blockBox.x;
|
|
var rightEdge = leftEdge + blockBox.width;
|
|
var topEdge = blockBox.y;
|
|
var bottomEdge = topEdge + blockBox.height;
|
|
}
|
|
var absoluteLeft = 0;
|
|
if (this.toolbox_ && this.toolboxPosition == Blockly.TOOLBOX_AT_LEFT) {
|
|
absoluteLeft = this.toolbox_.getWidth();
|
|
}
|
|
var absoluteTop = 0;
|
|
if (this.toolbox_ && this.toolboxPosition == Blockly.TOOLBOX_AT_TOP) {
|
|
absoluteTop = this.toolbox_.getHeight();
|
|
}
|
|
|
|
var metrics = {
|
|
viewHeight: svgSize.height,
|
|
viewWidth: svgSize.width,
|
|
contentHeight: bottomEdge - topEdge,
|
|
contentWidth: rightEdge - leftEdge,
|
|
viewTop: -this.scrollY,
|
|
viewLeft: -this.scrollX,
|
|
contentTop: topEdge,
|
|
contentLeft: leftEdge,
|
|
absoluteTop: absoluteTop,
|
|
absoluteLeft: absoluteLeft,
|
|
toolboxWidth: this.toolbox_ ? this.toolbox_.getWidth() : 0,
|
|
toolboxHeight: this.toolbox_ ? this.toolbox_.getHeight() : 0,
|
|
flyoutWidth: this.flyout_ ? this.flyout_.getWidth() : 0,
|
|
flyoutHeight: this.flyout_ ? this.flyout_.getHeight() : 0,
|
|
toolboxPosition: this.toolboxPosition
|
|
};
|
|
return metrics;
|
|
};
|
|
|
|
/**
|
|
* Sets the X/Y translations of a top level workspace to match the scrollbars.
|
|
* @param {!Object} xyRatio Contains an x and/or y property which is a float
|
|
* between 0 and 1 specifying the degree of scrolling.
|
|
* @private
|
|
* @this Blockly.WorkspaceSvg
|
|
*/
|
|
Blockly.WorkspaceSvg.setTopLevelWorkspaceMetrics_ = function(xyRatio) {
|
|
if (!this.scrollbar) {
|
|
throw 'Attempt to set top level workspace scroll without scrollbars.';
|
|
}
|
|
var metrics = this.getMetrics();
|
|
if (goog.isNumber(xyRatio.x)) {
|
|
this.scrollX = -metrics.contentWidth * xyRatio.x - metrics.contentLeft;
|
|
}
|
|
if (goog.isNumber(xyRatio.y)) {
|
|
this.scrollY = -metrics.contentHeight * xyRatio.y - metrics.contentTop;
|
|
}
|
|
var x = this.scrollX + metrics.absoluteLeft;
|
|
var y = this.scrollY + metrics.absoluteTop;
|
|
this.translate(x, y);
|
|
if (this.grid_) {
|
|
this.grid_.moveTo(x, y);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Update whether this workspace has resizes enabled.
|
|
* If enabled, workspace will resize when appropriate.
|
|
* If disabled, workspace will not resize until re-enabled.
|
|
* Use to avoid resizing during a batch operation, for performance.
|
|
* @param {boolean} enabled Whether resizes should be enabled.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.setResizesEnabled = function(enabled) {
|
|
var reenabled = (!this.resizesEnabled_ && enabled);
|
|
this.resizesEnabled_ = enabled;
|
|
if (reenabled) {
|
|
// Newly enabled. Trigger a resize.
|
|
this.resizeContents();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Dispose of all blocks in workspace, with an optimization to prevent resizes.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.clear = function() {
|
|
this.setResizesEnabled(false);
|
|
Blockly.WorkspaceSvg.superClass_.clear.call(this);
|
|
this.setResizesEnabled(true);
|
|
};
|
|
|
|
/**
|
|
* Register a callback function associated with a given key, for clicks on
|
|
* buttons and labels in the flyout.
|
|
* For instance, a button specified by the XML
|
|
* <button text="create variable" callbackKey="CREATE_VARIABLE"></button>
|
|
* should be matched by a call to
|
|
* registerButtonCallback("CREATE_VARIABLE", yourCallbackFunction).
|
|
* @param {string} key The name to use to look up this function.
|
|
* @param {function(!Blockly.FlyoutButton)} func The function to call when the
|
|
* given button is clicked.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.registerButtonCallback = function(key, func) {
|
|
goog.asserts.assert(goog.isFunction(func),
|
|
'Button callbacks must be functions.');
|
|
this.flyoutButtonCallbacks_[key] = func;
|
|
};
|
|
|
|
/**
|
|
* Get the callback function associated with a given key, for clicks on buttons
|
|
* and labels in the flyout.
|
|
* @param {string} key The name to use to look up the function.
|
|
* @return {?function(!Blockly.FlyoutButton)} The function corresponding to the
|
|
* given key for this workspace; null if no callback is registered.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getButtonCallback = function(key) {
|
|
var result = this.flyoutButtonCallbacks_[key];
|
|
return result ? result : null;
|
|
};
|
|
|
|
/**
|
|
* Remove a callback for a click on a button in the flyout.
|
|
* @param {string} key The name associated with the callback function.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.removeButtonCallback = function(key) {
|
|
this.flyoutButtonCallbacks_[key] = null;
|
|
};
|
|
|
|
/**
|
|
* Register a callback function associated with a given key, for populating
|
|
* custom toolbox categories in this workspace. See the variable and procedure
|
|
* categories as an example.
|
|
* @param {string} key The name to use to look up this function.
|
|
* @param {function(!Blockly.Workspace):!Array<!Element>} func The function to
|
|
* call when the given toolbox category is opened.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.registerToolboxCategoryCallback = function(key,
|
|
func) {
|
|
goog.asserts.assert(goog.isFunction(func),
|
|
'Toolbox category callbacks must be functions.');
|
|
this.toolboxCategoryCallbacks_[key] = func;
|
|
};
|
|
|
|
/**
|
|
* Get the callback function associated with a given key, for populating
|
|
* custom toolbox categories in this workspace.
|
|
* @param {string} key The name to use to look up the function.
|
|
* @return {?function(!Blockly.Workspace):!Array<!Element>} The function
|
|
* corresponding to the given key for this workspace, or null if no function
|
|
* is registered.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getToolboxCategoryCallback = function(key) {
|
|
var result = this.toolboxCategoryCallbacks_[key];
|
|
return result ? result : null;
|
|
};
|
|
|
|
/**
|
|
* Remove a callback for a click on a custom category's name in the toolbox.
|
|
* @param {string} key The name associated with the callback function.
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.removeToolboxCategoryCallback = function(key) {
|
|
this.toolboxCategoryCallbacks_[key] = null;
|
|
};
|
|
|
|
/**
|
|
* Look up the gesture that is tracking this touch stream on this workspace.
|
|
* May create a new gesture.
|
|
* @param {!Event} e Mouse event or touch event
|
|
* @return {Blockly.Gesture} The gesture that is tracking this touch stream,
|
|
* or null if no valid gesture exists.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getGesture = function(e) {
|
|
var isStart = (e.type == 'mousedown' || e.type == 'touchstart');
|
|
|
|
var gesture = this.currentGesture_;
|
|
if (gesture) {
|
|
if (isStart && gesture.hasStarted()) {
|
|
console.warn('tried to start the same gesture twice');
|
|
// That's funny. We must have missed a mouse up.
|
|
// Cancel it, rather than try to retrieve all of the state we need.
|
|
gesture.cancel();
|
|
return null;
|
|
}
|
|
return gesture;
|
|
}
|
|
|
|
// No gesture existed on this workspace, but this looks like the start of a
|
|
// new gesture.
|
|
if (isStart) {
|
|
this.currentGesture_ = new Blockly.Gesture(e, this);
|
|
return this.currentGesture_;
|
|
}
|
|
// No gesture existed and this event couldn't be the start of a new gesture.
|
|
return null;
|
|
};
|
|
|
|
/**
|
|
* Clear the reference to the current gesture.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.clearGesture = function() {
|
|
this.currentGesture_ = null;
|
|
};
|
|
|
|
/**
|
|
* Cancel the current gesture, if one exists.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.cancelCurrentGesture = function() {
|
|
if (this.currentGesture_) {
|
|
this.currentGesture_.cancel();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Get the audio manager for this workspace.
|
|
* @return {Blockly.WorkspaceAudio} The audio manager for this workspace.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getAudioManager = function() {
|
|
return this.audioManager_;
|
|
};
|
|
|
|
/**
|
|
* Get the grid object for this workspace, or null if there is none.
|
|
* @return {Blockly.Grid} The grid object for this workspace.
|
|
* @package
|
|
*/
|
|
Blockly.WorkspaceSvg.prototype.getGrid = function() {
|
|
return this.grid_;
|
|
};
|
|
|
|
// Export symbols that would otherwise be renamed by Closure compiler.
|
|
Blockly.WorkspaceSvg.prototype['setVisible'] =
|
|
Blockly.WorkspaceSvg.prototype.setVisible;
|