2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2014-01-28 03:00:09 -08:00
|
|
|
* @license
|
2013-10-30 14:46:03 -07:00
|
|
|
* Visual Blocks Editor
|
|
|
|
*
|
|
|
|
* Copyright 2012 Google Inc.
|
2014-10-07 13:09:55 -07:00
|
|
|
* https://developers.google.com/blockly/
|
2013-10-30 14:46:03 -07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-12-18 17:26:08 -08:00
|
|
|
* @fileoverview Utility functions for handling variables.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @author fraser@google.com (Neil Fraser)
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
Feature/merge feb 2017 (#791)
* Revert "Rebuild nov 3 16"
* Move injected css to start of head
* simplification
* lint
* Remove copy/paste buttons.
* Localisation updates from https://translatewiki.net.
* Don't split dropdown text if there is an image.
* Unblock push to master.
* Revert "Revert "Rebuild nov 3 16""
This reverts commit c8ca24a0007b70e137417e843459c87185141a55.
* rebuild
* Remove ifelse block and messages'
* Remove obsolete Gecko image hack. Apparently this has been fixed in Gecko.
* Add correct focus behavior for the modal. Update boundary sounds.
* Disallow clicks on disabled buttons.
* add back metadata tag to qqq
* revert qqq.json
* Improve performance of block dragging. This is a backport of the blo… (#732)
Improve performance of block dragging. This is a backport of the block drag surface from scratch-blocks. At the beginning of a block drag, blocks get moved to a drag surface which then translates using translate3d to avoid repainting the entire svg on every mouse move. At the end of the drag, the blocks are dropped back in the svg in their new position.
* API-breaking cleanup. But doubtful anyone will be affected. (#748)
* Make add/removeClass return whether they did anything.
* Move more functions onto utils.
* Move bind functions to Blockly.
* Routine recompile.
* String reference in JSON string messages (#741)
* Adds message references to message string interpolation, in the form of %{BKY_STRING}.
* Re-adding CONTROLS_IFELSE block using the new syntax, referencing to CONTROL_IF equivalents.
* Fix compiler errors.
* Break the sidebar out into its own individual component.
* Hide notification messages after a short time interval.
* Fix selection border on blocks that have been highlighted.
* controls_ifelse: Remove right-align. Remove Boolean check on statements. (#749)
* Move away from using a common modal service, since the block options and the toolbox modals are going to end up behaving fairly differently.
* Fix conflict between 'utils' and 'image dropdown' merges.
* Add a contextual modal for the toolbox.
* Fix some bugs arising in the toolbox modal for the no-categories case.
* Allow attaching blocks to a marked spot from the toolbox modal. This is the last prerequisite for removal of the existing on-screen toolbox.
* Delete the on-screen toolbox.
* Add warning sounds when the user reaches a boundary of the workspace.
* Stop some blocks from throwing errors in headless workspaces.
* Lint
* Fix speling.
* Fix broken highlighting when highlighted block is deleted. Issue 752.
* When the workspace is empty, make it easy for the user to add a new group of blocks to it.
* Handle the finer points for setting focus correctly after deleting blocks from the workspace.
* When user edits text in a field, set text, not value.
Existing text-editable fields don’t care (dropdown care, but are not
text-editable). But a note picker needs to set its value to 60 if text
is set to ‘C4’.
* Set the text not the value when closing a text editor.
Also rename variables for clarity.
* Localisation updates from https://translatewiki.net.
* Streamline the logic for block selection callbacks in the toolbox modal.
* Do not show disabled actions in the block options modal.
* Set focus correctly when toolbox modal is dismissed.
* Add information regarding target screen reader and browser.
* Rebuild Blockly.
* Remove unavailable blocks from toolbox modal. Hide unnecessary category name in a toolbox without categories.
* Do some refactoring and tidy-up. Pull some hardcoded strings out for i18n purposes; remove unused strings.
* Update config options for sidebar buttons.
* Minor refactoring. Remove unused dependencies.
* Improve styling of sidebar buttons.
* Remove clipboard functionality.
* Refactor and simplify marked spot logic.
* Change dropdowns to select fields instead of lists of buttons.
* Add ability to specify a css class for labels and buttons
* Don't make labels clickable
* console.log -> console.warn
* change 'class' to 'web-style'
* createSvgElement is now in utils. fix two calls.
* Improve comments.
* lint
* fix missing semicolon
* When adding a new block group from the toolbox modal, only show blocks with no output connections.
* Clean up the sidebar file and remove unneeded code.
* Remove some functions from utilsService and consolidate code in workspace-tree.component.js.
* Standardize indentation.
* Remove premature focus on buttons in modal dialogs, since this prevents readout of the dialog text.
* Localisation updates from https://translatewiki.net.
* Don't get Toolbox element unless needed.
* Associate flyout button callbacks directly with workspaces
* Add colour block to the block factory base block initial state
* Start getting helpurl and tooltip in
* Generate helpURL and tooltip for Javascript block definition
* Use Tab keys instead of arrow keys for dialog boxes. Set role=alertdialog and read out the header/text automatically. Ensure that Esc key actually closes dialogs and that all keystrokes are captured.
* Add an aria-describedby to the 'create new block group...' button in the workspace to give more context.
* Fix issue with aria-liveregion not speaking. Allow sufficient time for alert noise to play before speaking the notification.
* Make zoom speed independent of event granularity
Before, touchpads would give "smoother" scrolling by delivering lots of
mousewheel events with small distance changes. Because the code only
looked at the sign of deltaY, ten 5px scrolls would zoom 10x more than
one 50px scroll.
This change makes zooming with a touchpad more like zooming with a
mousewheel. On my laptop, a full-scale zoom (fully out to fully in) was
about a 5mm finger movement before, and is now about 3cm.
Fixes #758.
* Split the scrollbar and flyout out into their own SVG elements. They (#771)
* Split the scrollbar and flyout out into their own SVG elements. They
are siblings of the workpsace SVG. This paves the way to make performance
improvements to workspace dragging.
* remove overflow-y on the block exporter labels so scroll bars do not show upin firefox. Also fix up the styles on the labels so that they display better in firefox. (#699)
* Fix #698 by adjusting the regex to not have \. Still not 100% sure w… (#700)
* Fix #698 by adjusting the regex to not have \. Still not 100% sure why that was there.
Also replaces bad names on input. There are probably more invalid names but this is
a start.
* update generator comments
* Move the call to disable resize before placeNewBlock so that it is of… (#777)
* Move the call to disable resize before placeNewBlock so that it is off when workspace resizeContents
gets triggered by placeNewBlock. This fixes a bug in rtl mode where the workspace was being resized
between when the block was added to the workspace and when it was moved to the proper location.
* Disable workspace resizing while loading the flyout from XML
* Localisation updates from https://translatewiki.net.
* Add a workspace drag surface that blocks and bubble get moved to duri… (#778)
* Add a workspace drag surface that blocks and bubble get moved to during a workspace drag.
The surface is translated using translate3d instead of svg's translate attribute so that
the browser does not have to repaint the entire workspace on every mouse move.
This is very similar to the block drag surface.
* Address code review comments
* add back hasClass_ utility removed in #748 and stop using contains since it is not supported in IE
* Fixes #786 by checking if getComputedStyle is null in is3dSupported. We do not cache the value in this case and try again later. is3dSupported is only called while users are interacting with blockly which they cannot do while hidden so the performance implications of running the check again are minimal. (#787)
* Localisation updates from https://translatewiki.net.
* Change the Python codegen for string quoting to match the behaviour of `repr` on a string in CPython.
* Localisation updates from https://translatewiki.net.
* Add an `allInputsConnected` method to `Block` and `Workspace` to test whether all trees in the block forest have their inputs filled. An optional argument controls whether or not shadow blocks are counted as being filled. Recommitting changes off `develop` instead of `master` as per discussion in PR #791.
* Localisation updates from https://translatewiki.net.
* Localisation updates from https://translatewiki.net.
* Use the drag surface when scrolling using the scrollbars. #783 (#789)
* End event groups when you finish editing a field
* Fix #794 and make the workspace grid drag along with the workspace. (#801)
There was some IE specific code that also applies to Edge so just updated
a conditional to include Edge.
* Now that text input's setText skips setValue, it needs to explicitly create a change event
* Check if the text has changed before firing an event
* Init procedure blocks with empty name, and set default name in xml in Blockly.Procedures.flyoutCategory
* Routine rebuild
* Move createDom call into the constructor of block drag surface. (#790)
* Make cursor stay as a closed hand when dragging blocks around in the drag surface. Do this by applying the same style to text elements in the drag surface that we do in the main svg. (#805)
* Don't connect to blocks under the flyout.
* recompile again. (#806)
* Fix german translation
* Fix german translation of 'delete x blocks'
* Adding unit tests for ifelse block.
* Improvements to the generator test framework.
* <field>, <value> reorder due to load/save.
* Use the npm closure library instead of the same library installed at a parallel directory
* Fix undo/redo for FieldCheckbox
Thanks to PR #813 by ademenev
* PR #818: Adding support for string table lookups in dropdown field labels
Adding support for string table lookups in dropdown field labels specified in JSON.
Adds Blockly.utils.replaceMessageReferences() method to handle string replacement without interpolation tokens. Effectively uses the same old code, now moved into tokenizeInterpolation_(), which takes a parseInterpolationTokens option.
Replaces the direct JavaScript references (not pure JSON, and thus not portable).
Demonstrating this behavior in the logic_boolean dropdown.
* Integrating qqq.json changes into messages.json. (#820)
From commits b77f8cbebc5cef247116d3df6a428df8addbe53d and 4ecdedec9f8a69f78abf246e7a5db1e1a0be6b85
* Naming changes in mirror demo
* Adding support for untranslated messages. (#819)
This will be used to define constants accessible in JSON block definitions. Messages with descriptions that include `{{Notranslate}}` will not be included in the translation files sent to TranslateWiki. Instead, they are written to `msg/json/constants.json`, and later merged back into the `.js` files, similar to synonyms.
Template details: https://translatewiki.net/wiki/Template:Notranslate
* JSON support for message lookup in colour, tooltip, and help URL. (#825)
String replacement for the colour, tooltip text and help URL attributes of JSON defined blocks.
Demonstrated in logic_boolean.
* Fixes as per code review on PR.
* Reduce number of Closure files in App Engine upload.
* Python false is False. Issue #828.
* Replace 'const' with 'var'.
This unbreaks IE10 and advanced compiled apps such as Blockly Games.
* Fix bug in audioService where attached event callbacks were not being cleared properly.
* Rename workspace-tree to workspace-block.
* Minor refactoring of the modal code (add comments, guard against invalid keystrokes, etc.).
* FieldNumber & FieldAngle: Default value "0" (#832)
FieldNumber and FieldAngle previously accepted "undefined" as values, if not defined in JSON. This catches these and uses "0" for any NaN value. The constructor value parameter is now optional. Includes tests.
* Remove unnecessary check when attaching a new block to a marked connection.
* Remove debug info.
* Refactor and simplify field-segment.component.js.
* Replace single quotes with double. (#836)
Fixes commits in #832.
* Adding extensions for JSON support of dynamic blocks. (#834)
Adding support for extensions, functions that can assist with loading blocks, much like init functions, but that can be referenced from JSON definitions. This allows JSON definitions to define dynamic blocks such as onchange handlers and mutators.
Rewrote math_number as an example pure JSON block.
* Add ability to add a class to a scrollbar so that different types of … (#837)
* Add ability to add a class to a scrollbar so that different types of scrollbars can
be distinguished from each other. You used to be able to do this by looking at the parent
element but now all the scrollbars are siblings in the dom.
Also, use this new class to fix #816 so that layering of the flyout and workspace scrollbars
are done correctly.
* 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.
* Add a block to reverse a list (#844)
* 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)
* .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
* 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.
* 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
* 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.
* 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.
* Fix a few small errors and rebuild
* Call dynamic toolbox generators correctly
* cleanup
* Fix unit tests, and delete a few that relied on completely undefined behaviour
* Fix RTL text inputs
* eslintignore more tests
* Fix insertion marker highlighting, I think
* Make getFlyout public
2017-02-21 12:09:23 -08:00
|
|
|
/**
|
|
|
|
* @name Blockly.Variables
|
|
|
|
* @namespace
|
|
|
|
**/
|
2013-10-30 14:46:03 -07:00
|
|
|
goog.provide('Blockly.Variables');
|
|
|
|
|
2016-06-03 16:12:59 -07:00
|
|
|
goog.require('Blockly.Blocks');
|
Feature/merge feb 2017 (#791)
* Revert "Rebuild nov 3 16"
* Move injected css to start of head
* simplification
* lint
* Remove copy/paste buttons.
* Localisation updates from https://translatewiki.net.
* Don't split dropdown text if there is an image.
* Unblock push to master.
* Revert "Revert "Rebuild nov 3 16""
This reverts commit c8ca24a0007b70e137417e843459c87185141a55.
* rebuild
* Remove ifelse block and messages'
* Remove obsolete Gecko image hack. Apparently this has been fixed in Gecko.
* Add correct focus behavior for the modal. Update boundary sounds.
* Disallow clicks on disabled buttons.
* add back metadata tag to qqq
* revert qqq.json
* Improve performance of block dragging. This is a backport of the blo… (#732)
Improve performance of block dragging. This is a backport of the block drag surface from scratch-blocks. At the beginning of a block drag, blocks get moved to a drag surface which then translates using translate3d to avoid repainting the entire svg on every mouse move. At the end of the drag, the blocks are dropped back in the svg in their new position.
* API-breaking cleanup. But doubtful anyone will be affected. (#748)
* Make add/removeClass return whether they did anything.
* Move more functions onto utils.
* Move bind functions to Blockly.
* Routine recompile.
* String reference in JSON string messages (#741)
* Adds message references to message string interpolation, in the form of %{BKY_STRING}.
* Re-adding CONTROLS_IFELSE block using the new syntax, referencing to CONTROL_IF equivalents.
* Fix compiler errors.
* Break the sidebar out into its own individual component.
* Hide notification messages after a short time interval.
* Fix selection border on blocks that have been highlighted.
* controls_ifelse: Remove right-align. Remove Boolean check on statements. (#749)
* Move away from using a common modal service, since the block options and the toolbox modals are going to end up behaving fairly differently.
* Fix conflict between 'utils' and 'image dropdown' merges.
* Add a contextual modal for the toolbox.
* Fix some bugs arising in the toolbox modal for the no-categories case.
* Allow attaching blocks to a marked spot from the toolbox modal. This is the last prerequisite for removal of the existing on-screen toolbox.
* Delete the on-screen toolbox.
* Add warning sounds when the user reaches a boundary of the workspace.
* Stop some blocks from throwing errors in headless workspaces.
* Lint
* Fix speling.
* Fix broken highlighting when highlighted block is deleted. Issue 752.
* When the workspace is empty, make it easy for the user to add a new group of blocks to it.
* Handle the finer points for setting focus correctly after deleting blocks from the workspace.
* When user edits text in a field, set text, not value.
Existing text-editable fields don’t care (dropdown care, but are not
text-editable). But a note picker needs to set its value to 60 if text
is set to ‘C4’.
* Set the text not the value when closing a text editor.
Also rename variables for clarity.
* Localisation updates from https://translatewiki.net.
* Streamline the logic for block selection callbacks in the toolbox modal.
* Do not show disabled actions in the block options modal.
* Set focus correctly when toolbox modal is dismissed.
* Add information regarding target screen reader and browser.
* Rebuild Blockly.
* Remove unavailable blocks from toolbox modal. Hide unnecessary category name in a toolbox without categories.
* Do some refactoring and tidy-up. Pull some hardcoded strings out for i18n purposes; remove unused strings.
* Update config options for sidebar buttons.
* Minor refactoring. Remove unused dependencies.
* Improve styling of sidebar buttons.
* Remove clipboard functionality.
* Refactor and simplify marked spot logic.
* Change dropdowns to select fields instead of lists of buttons.
* Add ability to specify a css class for labels and buttons
* Don't make labels clickable
* console.log -> console.warn
* change 'class' to 'web-style'
* createSvgElement is now in utils. fix two calls.
* Improve comments.
* lint
* fix missing semicolon
* When adding a new block group from the toolbox modal, only show blocks with no output connections.
* Clean up the sidebar file and remove unneeded code.
* Remove some functions from utilsService and consolidate code in workspace-tree.component.js.
* Standardize indentation.
* Remove premature focus on buttons in modal dialogs, since this prevents readout of the dialog text.
* Localisation updates from https://translatewiki.net.
* Don't get Toolbox element unless needed.
* Associate flyout button callbacks directly with workspaces
* Add colour block to the block factory base block initial state
* Start getting helpurl and tooltip in
* Generate helpURL and tooltip for Javascript block definition
* Use Tab keys instead of arrow keys for dialog boxes. Set role=alertdialog and read out the header/text automatically. Ensure that Esc key actually closes dialogs and that all keystrokes are captured.
* Add an aria-describedby to the 'create new block group...' button in the workspace to give more context.
* Fix issue with aria-liveregion not speaking. Allow sufficient time for alert noise to play before speaking the notification.
* Make zoom speed independent of event granularity
Before, touchpads would give "smoother" scrolling by delivering lots of
mousewheel events with small distance changes. Because the code only
looked at the sign of deltaY, ten 5px scrolls would zoom 10x more than
one 50px scroll.
This change makes zooming with a touchpad more like zooming with a
mousewheel. On my laptop, a full-scale zoom (fully out to fully in) was
about a 5mm finger movement before, and is now about 3cm.
Fixes #758.
* Split the scrollbar and flyout out into their own SVG elements. They (#771)
* Split the scrollbar and flyout out into their own SVG elements. They
are siblings of the workpsace SVG. This paves the way to make performance
improvements to workspace dragging.
* remove overflow-y on the block exporter labels so scroll bars do not show upin firefox. Also fix up the styles on the labels so that they display better in firefox. (#699)
* Fix #698 by adjusting the regex to not have \. Still not 100% sure w… (#700)
* Fix #698 by adjusting the regex to not have \. Still not 100% sure why that was there.
Also replaces bad names on input. There are probably more invalid names but this is
a start.
* update generator comments
* Move the call to disable resize before placeNewBlock so that it is of… (#777)
* Move the call to disable resize before placeNewBlock so that it is off when workspace resizeContents
gets triggered by placeNewBlock. This fixes a bug in rtl mode where the workspace was being resized
between when the block was added to the workspace and when it was moved to the proper location.
* Disable workspace resizing while loading the flyout from XML
* Localisation updates from https://translatewiki.net.
* Add a workspace drag surface that blocks and bubble get moved to duri… (#778)
* Add a workspace drag surface that blocks and bubble get moved to during a workspace drag.
The surface is translated using translate3d instead of svg's translate attribute so that
the browser does not have to repaint the entire workspace on every mouse move.
This is very similar to the block drag surface.
* Address code review comments
* add back hasClass_ utility removed in #748 and stop using contains since it is not supported in IE
* Fixes #786 by checking if getComputedStyle is null in is3dSupported. We do not cache the value in this case and try again later. is3dSupported is only called while users are interacting with blockly which they cannot do while hidden so the performance implications of running the check again are minimal. (#787)
* Localisation updates from https://translatewiki.net.
* Change the Python codegen for string quoting to match the behaviour of `repr` on a string in CPython.
* Localisation updates from https://translatewiki.net.
* Add an `allInputsConnected` method to `Block` and `Workspace` to test whether all trees in the block forest have their inputs filled. An optional argument controls whether or not shadow blocks are counted as being filled. Recommitting changes off `develop` instead of `master` as per discussion in PR #791.
* Localisation updates from https://translatewiki.net.
* Localisation updates from https://translatewiki.net.
* Use the drag surface when scrolling using the scrollbars. #783 (#789)
* End event groups when you finish editing a field
* Fix #794 and make the workspace grid drag along with the workspace. (#801)
There was some IE specific code that also applies to Edge so just updated
a conditional to include Edge.
* Now that text input's setText skips setValue, it needs to explicitly create a change event
* Check if the text has changed before firing an event
* Init procedure blocks with empty name, and set default name in xml in Blockly.Procedures.flyoutCategory
* Routine rebuild
* Move createDom call into the constructor of block drag surface. (#790)
* Make cursor stay as a closed hand when dragging blocks around in the drag surface. Do this by applying the same style to text elements in the drag surface that we do in the main svg. (#805)
* Don't connect to blocks under the flyout.
* recompile again. (#806)
* Fix german translation
* Fix german translation of 'delete x blocks'
* Adding unit tests for ifelse block.
* Improvements to the generator test framework.
* <field>, <value> reorder due to load/save.
* Use the npm closure library instead of the same library installed at a parallel directory
* Fix undo/redo for FieldCheckbox
Thanks to PR #813 by ademenev
* PR #818: Adding support for string table lookups in dropdown field labels
Adding support for string table lookups in dropdown field labels specified in JSON.
Adds Blockly.utils.replaceMessageReferences() method to handle string replacement without interpolation tokens. Effectively uses the same old code, now moved into tokenizeInterpolation_(), which takes a parseInterpolationTokens option.
Replaces the direct JavaScript references (not pure JSON, and thus not portable).
Demonstrating this behavior in the logic_boolean dropdown.
* Integrating qqq.json changes into messages.json. (#820)
From commits b77f8cbebc5cef247116d3df6a428df8addbe53d and 4ecdedec9f8a69f78abf246e7a5db1e1a0be6b85
* Naming changes in mirror demo
* Adding support for untranslated messages. (#819)
This will be used to define constants accessible in JSON block definitions. Messages with descriptions that include `{{Notranslate}}` will not be included in the translation files sent to TranslateWiki. Instead, they are written to `msg/json/constants.json`, and later merged back into the `.js` files, similar to synonyms.
Template details: https://translatewiki.net/wiki/Template:Notranslate
* JSON support for message lookup in colour, tooltip, and help URL. (#825)
String replacement for the colour, tooltip text and help URL attributes of JSON defined blocks.
Demonstrated in logic_boolean.
* Fixes as per code review on PR.
* Reduce number of Closure files in App Engine upload.
* Python false is False. Issue #828.
* Replace 'const' with 'var'.
This unbreaks IE10 and advanced compiled apps such as Blockly Games.
* Fix bug in audioService where attached event callbacks were not being cleared properly.
* Rename workspace-tree to workspace-block.
* Minor refactoring of the modal code (add comments, guard against invalid keystrokes, etc.).
* FieldNumber & FieldAngle: Default value "0" (#832)
FieldNumber and FieldAngle previously accepted "undefined" as values, if not defined in JSON. This catches these and uses "0" for any NaN value. The constructor value parameter is now optional. Includes tests.
* Remove unnecessary check when attaching a new block to a marked connection.
* Remove debug info.
* Refactor and simplify field-segment.component.js.
* Replace single quotes with double. (#836)
Fixes commits in #832.
* Adding extensions for JSON support of dynamic blocks. (#834)
Adding support for extensions, functions that can assist with loading blocks, much like init functions, but that can be referenced from JSON definitions. This allows JSON definitions to define dynamic blocks such as onchange handlers and mutators.
Rewrote math_number as an example pure JSON block.
* Add ability to add a class to a scrollbar so that different types of … (#837)
* Add ability to add a class to a scrollbar so that different types of scrollbars can
be distinguished from each other. You used to be able to do this by looking at the parent
element but now all the scrollbars are siblings in the dom.
Also, use this new class to fix #816 so that layering of the flyout and workspace scrollbars
are done correctly.
* 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.
* Add a block to reverse a list (#844)
* 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)
* .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
* 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.
* 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
* 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.
* 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.
* Fix a few small errors and rebuild
* Call dynamic toolbox generators correctly
* cleanup
* Fix unit tests, and delete a few that relied on completely undefined behaviour
* Fix RTL text inputs
* eslintignore more tests
* Fix insertion marker highlighting, I think
* Make getFlyout public
2017-02-21 12:09:23 -08:00
|
|
|
goog.require('Blockly.constants');
|
Merge/05 24 (#903)
* 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 d55d9cbd9ff308ff5e361cf77acabb61a4bf4695). 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
2017-05-30 09:26:06 -04:00
|
|
|
goog.require('Blockly.VariableModel');
|
2013-10-30 14:46:03 -07:00
|
|
|
goog.require('Blockly.Workspace');
|
2015-02-06 15:27:25 -08:00
|
|
|
goog.require('goog.string');
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
|
Merge google/blockly, May 2017 (#881)
* Move createDom call into the constructor of block drag surface. (#790)
* Make cursor stay as a closed hand when dragging blocks around in the drag surface. Do this by applying the same style to text elements in the drag surface that we do in the main svg. (#805)
* Don't connect to blocks under the flyout.
* recompile again. (#806)
* Fix german translation
* Option for moving one block from stack.
See thread in support group before merging.
* Fix german translation of 'delete x blocks'
* Adding unit tests for ifelse block.
* Improvements to the generator test framework.
* <field>, <value> reorder due to load/save.
* Expand stack-drag modifier key to include alt and ctrl.
* Use the npm closure library instead of the same library installed at a parallel directory
* Fix undo/redo for FieldCheckbox
Thanks to PR #813 by ademenev
* Localisation updates from https://translatewiki.net.
* PR #818: Adding support for string table lookups in dropdown field labels
Adding support for string table lookups in dropdown field labels specified in JSON.
Adds Blockly.utils.replaceMessageReferences() method to handle string replacement without interpolation tokens. Effectively uses the same old code, now moved into tokenizeInterpolation_(), which takes a parseInterpolationTokens option.
Replaces the direct JavaScript references (not pure JSON, and thus not portable).
Demonstrating this behavior in the logic_boolean dropdown.
* Integrating qqq.json changes into messages.json. (#820)
From commits b77f8cbebc5cef247116d3df6a428df8addbe53d and 4ecdedec9f8a69f78abf246e7a5db1e1a0be6b85
* Naming changes in mirror demo
* Adding support for untranslated messages. (#819)
This will be used to define constants accessible in JSON block definitions. Messages with descriptions that include `{{Notranslate}}` will not be included in the translation files sent to TranslateWiki. Instead, they are written to `msg/json/constants.json`, and later merged back into the `.js` files, similar to synonyms.
Template details: https://translatewiki.net/wiki/Template:Notranslate
* JSON support for message lookup in colour, tooltip, and help URL. (#825)
String replacement for the colour, tooltip text and help URL attributes of JSON defined blocks.
Demonstrated in logic_boolean.
* Fixes as per code review on PR.
* Localisation updates from https://translatewiki.net.
* Reduce number of Closure files in App Engine upload.
* Python false is False. Issue #828.
* Replace 'const' with 'var'.
This unbreaks IE10 and advanced compiled apps such as Blockly Games.
* Fix bug in audioService where attached event callbacks were not being cleared properly.
* Rename workspace-tree to workspace-block.
* Minor refactoring of the modal code (add comments, guard against invalid keystrokes, etc.).
* FieldNumber & FieldAngle: Default value "0" (#832)
FieldNumber and FieldAngle previously accepted "undefined" as values, if not defined in JSON. This catches these and uses "0" for any NaN value. The constructor value parameter is now optional. Includes tests.
* Remove unnecessary check when attaching a new block to a marked connection.
* Remove debug info.
* Refactor and simplify field-segment.component.js.
* Replace single quotes with double. (#836)
Fixes commits in #832.
* Adding extensions for JSON support of dynamic blocks. (#834)
Adding support for extensions, functions that can assist with loading blocks, much like init functions, but that can be referenced from JSON definitions. This allows JSON definitions to define dynamic blocks such as onchange handlers and mutators.
Rewrote math_number as an example pure JSON block.
* Add ability to add a class to a scrollbar so that different types of … (#837)
* Add ability to add a class to a scrollbar so that different types of scrollbars can
be distinguished from each other. You used to be able to do this by looking at the parent
element but now all the scrollbars are siblings in the dom.
Also, use this new class to fix #816 so that layering of the flyout and workspace scrollbars
are done correctly.
* 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 d55d9cbd9ff308ff5e361cf77acabb61a4bf4695). 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.
* Fix #1069 (#1073)
* Fix cursor and mistaken css from merge
* Comment out broken field angle merge
* Fix broken merge with borders
* Add back original package json (woops)
* Remove render function for field angle, may not be the right way but it was broken...
* Revert merge blocking variable shadow blocks
* Add changes from built lang files
* Add back travis and readme
* Revert broken cleanup additions
* Add notes for scratch-block specific functions
* Revert change to css so blocks stay under the toolbox
* Add back accidentally removed files
* Use getFlyout_ instead of getFlyout everywhere
* Satisfy the linter
* Re-remove deprecated function
* Remove duplicated code in block_svg
* Add back flip_rtl option for images
* Remove more duplicated functions from past merges
* Fix flip_rtl code
* Revert renaming of getFlyout
2017-05-11 15:58:18 -04:00
|
|
|
/**
|
|
|
|
* Constant to separate variable names from procedures and generated functions
|
|
|
|
* when running generators.
|
|
|
|
* @deprecated Use Blockly.VARIABLE_CATEGORY_NAME
|
|
|
|
*/
|
|
|
|
Blockly.Variables.NAME_TYPE = Blockly.VARIABLE_CATEGORY_NAME;
|
|
|
|
|
2018-11-13 16:42:28 -05:00
|
|
|
/**
|
|
|
|
* Constant prefix to differentiate cloud variable names from other types
|
|
|
|
* of variables.
|
|
|
|
* This is the \u2601 cloud unicode character followed by a space.
|
|
|
|
* @type {string}
|
|
|
|
* @package
|
|
|
|
*/
|
|
|
|
Blockly.Variables.CLOUD_PREFIX = '☁ ';
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2016-07-07 15:23:20 -07:00
|
|
|
* Find all user-created variables that are in use in the workspace.
|
|
|
|
* For use by generators.
|
2015-01-12 14:57:00 -08:00
|
|
|
* @param {!Blockly.Block|!Blockly.Workspace} root Root block or workspace.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @return {!Array.<string>} Array of variable names.
|
|
|
|
*/
|
2016-07-07 15:23:20 -07:00
|
|
|
Blockly.Variables.allUsedVariables = function(root) {
|
2013-10-30 14:46:03 -07:00
|
|
|
var blocks;
|
2016-07-13 12:50:44 -07:00
|
|
|
if (root instanceof Blockly.Block) {
|
2014-12-23 11:22:02 -08:00
|
|
|
// Root is Block.
|
2018-05-16 12:51:41 -07:00
|
|
|
blocks = root.getDescendants(false);
|
2016-07-13 14:36:35 -07:00
|
|
|
} else if (root instanceof Blockly.Workspace ||
|
|
|
|
root instanceof Blockly.WorkspaceSvg) {
|
2014-12-23 11:22:02 -08:00
|
|
|
// Root is Workspace.
|
|
|
|
blocks = root.getAllBlocks();
|
2013-10-30 14:46:03 -07:00
|
|
|
} else {
|
2014-12-23 11:22:02 -08:00
|
|
|
throw 'Not Block or Workspace: ' + root;
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
2017-02-22 13:49:39 -08:00
|
|
|
|
|
|
|
var ignorableName = Blockly.Variables.noVariableText();
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
var variableHash = Object.create(null);
|
|
|
|
// Iterate through every block and add each variable to the hash.
|
|
|
|
for (var x = 0; x < blocks.length; x++) {
|
2017-12-19 14:46:53 -05:00
|
|
|
var blockVariables = blocks[x].getVarModels();
|
2016-06-22 16:16:31 -07:00
|
|
|
if (blockVariables) {
|
|
|
|
for (var y = 0; y < blockVariables.length; y++) {
|
2017-12-19 14:46:53 -05:00
|
|
|
var variable = blockVariables[y];
|
|
|
|
// Variable ID may be null if the block is only half-built.
|
2017-12-19 17:14:04 -05:00
|
|
|
if (variable.getId() && variable.name.toLowerCase() != ignorableName) {
|
2017-12-19 14:46:53 -05:00
|
|
|
variableHash[variable.name.toLowerCase()] = variable.name;
|
2016-06-22 16:16:31 -07:00
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Flatten the hash into a list.
|
|
|
|
var variableList = [];
|
|
|
|
for (var name in variableHash) {
|
|
|
|
variableList.push(variableHash[name]);
|
|
|
|
}
|
|
|
|
return variableList;
|
|
|
|
};
|
|
|
|
|
2016-07-07 15:23:20 -07:00
|
|
|
/**
|
|
|
|
* Find all variables that the user has created through the workspace or
|
|
|
|
* toolbox. For use by generators.
|
|
|
|
* @param {!Blockly.Workspace} root The workspace to inspect.
|
2017-05-22 13:08:22 -07:00
|
|
|
* @return {!Array.<Blockly.VariableModel>} Array of variable models.
|
2016-07-07 15:23:20 -07:00
|
|
|
*/
|
|
|
|
Blockly.Variables.allVariables = function(root) {
|
2016-07-13 12:50:44 -07:00
|
|
|
if (root instanceof Blockly.Block) {
|
2016-07-07 15:23:20 -07:00
|
|
|
// Root is Block.
|
|
|
|
console.warn('Deprecated call to Blockly.Variables.allVariables ' +
|
|
|
|
'with a block instead of a workspace. You may want ' +
|
|
|
|
'Blockly.Variables.allUsedVariables');
|
2017-05-22 13:08:22 -07:00
|
|
|
return {};
|
2016-07-07 15:23:20 -07:00
|
|
|
}
|
2017-05-22 13:08:22 -07:00
|
|
|
return root.getAllVariables();
|
2016-07-07 15:23:20 -07:00
|
|
|
};
|
|
|
|
|
2017-02-22 13:49:39 -08:00
|
|
|
/**
|
2017-12-19 11:28:23 -08:00
|
|
|
* Find all developer variables used by blocks in the workspace.
|
|
|
|
* Developer variables are never shown to the user, but are declared as global
|
|
|
|
* variables in the generated code.
|
|
|
|
* To declare developer variables, define the getDeveloperVariables function on
|
|
|
|
* your block and return a list of variable names.
|
|
|
|
* For use by generators.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace to search.
|
|
|
|
* @return {!Array.<string>} A list of non-duplicated variable names.
|
|
|
|
* @package
|
|
|
|
*/
|
|
|
|
Blockly.Variables.allDeveloperVariables = function(workspace) {
|
|
|
|
var blocks = workspace.getAllBlocks();
|
|
|
|
var hash = {};
|
|
|
|
for (var i = 0; i < blocks.length; i++) {
|
|
|
|
var block = blocks[i];
|
|
|
|
if (block.getDeveloperVars) {
|
|
|
|
var devVars = block.getDeveloperVars();
|
|
|
|
for (var j = 0; j < devVars.length; j++) {
|
|
|
|
hash[devVars[j]] = devVars[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flatten the hash into a list.
|
|
|
|
var list = [];
|
|
|
|
for (var name in hash) {
|
|
|
|
list.push(hash[name]);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the text that should be used in a field_variable or
|
|
|
|
* field_variable_getter when no variable exists.
|
|
|
|
* TODO: #572
|
|
|
|
* @return {string} The text to display.
|
2017-02-22 13:49:39 -08:00
|
|
|
*/
|
|
|
|
Blockly.Variables.noVariableText = function() {
|
|
|
|
return "No variable selected";
|
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Return a new variable name that is not yet being used. This will try to
|
|
|
|
* generate single letter variable names in the range 'i' to 'z' to start with.
|
2015-01-12 14:57:00 -08:00
|
|
|
* If no unique name is located it will try 'i' to 'z', 'a' to 'h',
|
|
|
|
* then 'i2' to 'z2' etc. Skip 'l'.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace to be unique in.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @return {string} New variable name.
|
|
|
|
*/
|
2015-01-12 14:57:00 -08:00
|
|
|
Blockly.Variables.generateUniqueName = function(workspace) {
|
2017-05-22 13:08:22 -07:00
|
|
|
var variableList = workspace.getAllVariables();
|
2013-10-30 14:46:03 -07:00
|
|
|
var newName = '';
|
|
|
|
if (variableList.length) {
|
2015-01-12 14:57:00 -08:00
|
|
|
var nameSuffix = 1;
|
|
|
|
var letters = 'ijkmnopqrstuvwxyzabcdefgh'; // No 'l'.
|
|
|
|
var letterIndex = 0;
|
|
|
|
var potName = letters.charAt(letterIndex);
|
2013-10-30 14:46:03 -07:00
|
|
|
while (!newName) {
|
2015-01-12 14:57:00 -08:00
|
|
|
var inUse = false;
|
|
|
|
for (var i = 0; i < variableList.length; i++) {
|
2017-05-22 13:08:22 -07:00
|
|
|
if (variableList[i].name.toLowerCase() == potName) {
|
2013-10-30 14:46:03 -07:00
|
|
|
// This potential name is already used.
|
|
|
|
inUse = true;
|
2015-01-12 14:57:00 -08:00
|
|
|
break;
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (inUse) {
|
|
|
|
// Try the next potential name.
|
2015-01-12 14:57:00 -08:00
|
|
|
letterIndex++;
|
|
|
|
if (letterIndex == letters.length) {
|
|
|
|
// Reached the end of the character sequence so back to 'i'.
|
2013-10-30 14:46:03 -07:00
|
|
|
// a new suffix.
|
2015-01-12 14:57:00 -08:00
|
|
|
letterIndex = 0;
|
2013-10-30 14:46:03 -07:00
|
|
|
nameSuffix++;
|
|
|
|
}
|
2015-01-12 14:57:00 -08:00
|
|
|
potName = letters.charAt(letterIndex);
|
|
|
|
if (nameSuffix > 1) {
|
2013-10-30 14:46:03 -07:00
|
|
|
potName += nameSuffix;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We can use the current potential name.
|
|
|
|
newName = potName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newName = 'i';
|
|
|
|
}
|
|
|
|
return newName;
|
|
|
|
};
|
2016-06-22 17:19:49 -07:00
|
|
|
|
2018-01-16 11:42:00 -05:00
|
|
|
/**
|
2018-01-16 11:43:37 -05:00
|
|
|
* Remove any possiblity of conflict/duplication between a real and potential variable.
|
2018-01-22 10:53:15 -05:00
|
|
|
* When creating a new variable, checks whether the desired name and type already exists
|
2018-01-16 11:42:00 -05:00
|
|
|
* as a real or potential variable.
|
2018-01-22 10:53:15 -05:00
|
|
|
* If 'checkReal' is true, checks whether a real variable with the given
|
|
|
|
* name and type already exists.
|
|
|
|
* Checks whether a potential variable (using the given 'potentialVarWs') exists.
|
2018-01-16 11:42:00 -05:00
|
|
|
* If a potential var exists and a real var also exists, discards the potential var
|
|
|
|
* and returns the real var.
|
2018-01-22 10:53:15 -05:00
|
|
|
* If a potential var exists and a real var does not exist (or 'checkReal'
|
|
|
|
* was false), creates the potential var as a real var,
|
2018-01-16 11:42:00 -05:00
|
|
|
* discards the potential var, and returns the newly created real var.
|
|
|
|
* If a potential var does not exist, returns null.
|
|
|
|
*
|
|
|
|
* @param {string} varName The name of the variable to check for.
|
|
|
|
* @param {string} varType The type of the variable to check for.
|
2018-01-22 10:53:15 -05:00
|
|
|
* @param {!Blockly.Workspace} potentialVarWs The workspace containing the
|
|
|
|
* potential variable map we want to check against.
|
|
|
|
* @param {boolean} checkReal Whether or not to check if a variable of the given
|
|
|
|
* name and type exists as a real variable.
|
2018-01-16 11:42:00 -05:00
|
|
|
* @return {?Blockly.VariableModel} The matching variable, if one already existed
|
2018-01-22 10:53:15 -05:00
|
|
|
* in the real workspace; the newly transformed variable, if one already
|
|
|
|
* existed as a potential variable. Null, if no matching variable, real or
|
|
|
|
* potential, was found.
|
2018-01-16 11:42:00 -05:00
|
|
|
*/
|
2018-01-22 10:53:15 -05:00
|
|
|
Blockly.Variables.realizePotentialVar = function(varName, varType, potentialVarWs,
|
|
|
|
checkReal) {
|
|
|
|
var potentialVarMap = potentialVarWs.getPotentialVariableMap();
|
|
|
|
var realWs = potentialVarWs.targetWorkspace;
|
|
|
|
if (!potentialVarMap) {
|
2018-01-10 17:01:02 -05:00
|
|
|
console.warn('Called Blockly.Variables.realizePotentialVar with incorrect ' +
|
2018-01-22 10:53:15 -05:00
|
|
|
'workspace. The provided workspace does not have a potential variable map.');
|
2018-01-10 17:01:02 -05:00
|
|
|
return;
|
|
|
|
}
|
2018-01-16 10:54:16 -05:00
|
|
|
// First check if a variable with the same name and type already exists as a
|
|
|
|
// real variable.
|
|
|
|
var realVar;
|
2018-01-22 10:53:15 -05:00
|
|
|
if (checkReal) {
|
|
|
|
realVar = Blockly.Variables.getVariable(realWs, null, varName, varType);
|
2018-01-16 10:54:16 -05:00
|
|
|
}
|
2018-01-22 10:53:15 -05:00
|
|
|
|
|
|
|
// Check if variable with same name and type exists as a potential var
|
|
|
|
var potentialVar = potentialVarMap.getVariable(varName, varType);
|
|
|
|
if (!potentialVar) {
|
|
|
|
return null;
|
2018-01-10 17:01:02 -05:00
|
|
|
}
|
2018-01-22 10:53:15 -05:00
|
|
|
|
|
|
|
// The potential var exists, so save its id and delete it from the potential
|
|
|
|
// variable map.
|
|
|
|
var id = potentialVar.getId();
|
|
|
|
potentialVarMap.deleteVariable(potentialVar);
|
|
|
|
|
|
|
|
// Depending on whether a real var already exists or not, either return the
|
|
|
|
// existing real var or turn the potential var into a new one using its id.
|
|
|
|
if (realVar) {
|
|
|
|
return realVar;
|
2018-01-10 17:01:02 -05:00
|
|
|
}
|
2018-01-22 10:53:15 -05:00
|
|
|
return realWs.createVariable(varName, varType, id);
|
2018-01-10 17:01:02 -05:00
|
|
|
};
|
|
|
|
|
2016-07-01 15:51:59 -07:00
|
|
|
/**
|
|
|
|
* Create a new variable on the given workspace.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace on which to create the
|
|
|
|
* variable.
|
2018-01-24 17:45:39 -05:00
|
|
|
* @param {function(?string=)=} opt_callback An optional callback function to act
|
|
|
|
* on the id of the variable that is created from the user's input, or null
|
|
|
|
* if the change is to be aborted (cancel button or an invalid name was provided).
|
|
|
|
* @param {string} opt_type Optional type of the variable to be created,
|
|
|
|
* like 'string' or 'list'.
|
2016-07-01 15:51:59 -07:00
|
|
|
*/
|
2017-07-06 18:00:33 -07:00
|
|
|
Blockly.Variables.createVariable = function(workspace, opt_callback, opt_type) {
|
2017-11-20 14:09:17 -05:00
|
|
|
// Decide on a modal message based on the opt_type. If opt_type was not
|
|
|
|
// provided, default to the original message for scalar variables.
|
2018-01-24 17:45:39 -05:00
|
|
|
var newMsg, modalTitle;
|
2018-01-29 10:40:07 -05:00
|
|
|
if (opt_type == Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE) {
|
2017-11-20 14:09:17 -05:00
|
|
|
newMsg = Blockly.Msg.NEW_BROADCAST_MESSAGE_TITLE;
|
2017-12-22 13:47:35 -05:00
|
|
|
modalTitle = Blockly.Msg.BROADCAST_MODAL_TITLE;
|
2018-01-29 10:40:07 -05:00
|
|
|
} else if (opt_type == Blockly.LIST_VARIABLE_TYPE) {
|
2018-01-24 17:45:39 -05:00
|
|
|
newMsg = Blockly.Msg.NEW_LIST_TITLE;
|
|
|
|
modalTitle = Blockly.Msg.LIST_MODAL_TITLE;
|
2018-01-29 10:40:07 -05:00
|
|
|
} else {
|
|
|
|
// Note: this case covers 1) scalar variables, 2) any new type of
|
|
|
|
// variable not explicitly checked for above, and 3) a null or undefined
|
|
|
|
// opt_type -- turns a falsey opt_type into ''
|
|
|
|
// TODO (#1251) Warn developers that they didn't provide an opt_type/provided
|
|
|
|
// a falsey opt_type
|
|
|
|
opt_type = opt_type ? opt_type : '';
|
2017-11-20 14:09:17 -05:00
|
|
|
newMsg = Blockly.Msg.NEW_VARIABLE_TITLE;
|
2017-12-22 13:47:35 -05:00
|
|
|
modalTitle = Blockly.Msg.VARIABLE_MODAL_TITLE;
|
2017-11-20 14:09:17 -05:00
|
|
|
}
|
2018-01-24 17:45:39 -05:00
|
|
|
var validate = Blockly.Variables.nameValidator_.bind(null, opt_type);
|
2018-01-26 09:33:22 -05:00
|
|
|
|
2018-01-25 10:42:30 -05:00
|
|
|
// Prompt the user to enter a name for the variable
|
|
|
|
Blockly.prompt(newMsg, '',
|
2018-11-13 16:42:28 -05:00
|
|
|
function(text, additionalVars, variableOptions) {
|
2018-12-04 15:54:06 -05:00
|
|
|
variableOptions = variableOptions || {};
|
2018-11-13 16:42:28 -05:00
|
|
|
var scope = variableOptions.scope;
|
2018-07-03 14:01:49 -04:00
|
|
|
var isLocal = (scope === 'local') || false;
|
2018-11-13 16:42:28 -05:00
|
|
|
var isCloud = variableOptions.isCloud || false;
|
2018-07-12 19:15:49 -04:00
|
|
|
// Default to [] if additionalVars is not provided
|
2018-07-06 13:03:36 -04:00
|
|
|
additionalVars = additionalVars || [];
|
2018-07-12 19:15:49 -04:00
|
|
|
// Only use additionalVars for global variable creation.
|
|
|
|
var additionalVarNames = isLocal ? [] : additionalVars;
|
|
|
|
|
2018-11-13 16:42:28 -05:00
|
|
|
var validatedText = validate(text, workspace, additionalVarNames, isCloud, opt_callback);
|
2018-01-24 17:45:39 -05:00
|
|
|
if (validatedText) {
|
|
|
|
// The name is valid according to the type, create the variable
|
|
|
|
var potentialVarMap = workspace.getPotentialVariableMap();
|
|
|
|
var variable;
|
|
|
|
// This check ensures that if a new variable is being created from a
|
|
|
|
// workspace that already has a variable of the same name and type as
|
|
|
|
// a potential variable, that potential variable gets turned into a
|
|
|
|
// real variable and thus there aren't duplicate options in the field_variable
|
|
|
|
// dropdown.
|
|
|
|
if (potentialVarMap && opt_type) {
|
2018-01-25 10:42:30 -05:00
|
|
|
variable = Blockly.Variables.realizePotentialVar(validatedText,
|
|
|
|
opt_type, workspace, false);
|
2018-01-24 17:45:39 -05:00
|
|
|
}
|
|
|
|
if (!variable) {
|
2018-11-13 16:42:28 -05:00
|
|
|
variable = workspace.createVariable(validatedText, opt_type, null, isLocal, isCloud);
|
2018-01-24 17:45:39 -05:00
|
|
|
}
|
2017-06-02 11:30:45 -04:00
|
|
|
|
2018-01-24 17:45:39 -05:00
|
|
|
var flyout = workspace.isFlyout ? workspace : workspace.getFlyout();
|
|
|
|
var variableBlockId = variable.getId();
|
|
|
|
if (flyout.setCheckboxState) {
|
|
|
|
flyout.setCheckboxState(variableBlockId, true);
|
|
|
|
}
|
2017-06-02 11:30:45 -04:00
|
|
|
|
2018-01-24 17:45:39 -05:00
|
|
|
if (opt_callback) {
|
|
|
|
opt_callback(variableBlockId);
|
2016-10-20 09:30:45 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// User canceled prompt without a value.
|
2017-07-18 22:47:52 -07:00
|
|
|
if (opt_callback) {
|
|
|
|
opt_callback(null);
|
|
|
|
}
|
|
|
|
}
|
2018-01-29 15:40:49 -05:00
|
|
|
}, modalTitle, opt_type);
|
2017-07-18 22:47:52 -07:00
|
|
|
};
|
|
|
|
|
2018-01-24 17:45:39 -05:00
|
|
|
/**
|
|
|
|
* This function provides a common interface for variable name validation agnostic
|
|
|
|
* of type. This is so that functions like Blockly.Variables.createVariable and
|
2018-01-26 09:33:22 -05:00
|
|
|
* Blockly.Variables.renameVariable can call a single function (with a single
|
2018-01-25 10:42:30 -05:00
|
|
|
* type signature) to validate the user-provided name for a variable.
|
2018-01-24 17:45:39 -05:00
|
|
|
* @param {string} type The type of the variable for which the provided name
|
|
|
|
* should be validated.
|
|
|
|
* @param {string} text The user-provided text that should be validated as a
|
|
|
|
* variable name.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace on which to validate the
|
|
|
|
* variable name. This is the workspace used to check whether the variable
|
|
|
|
* already exists.
|
2018-07-03 14:01:49 -04:00
|
|
|
* @param {Array<string>} additionalVars A list of additional var names to check
|
|
|
|
* for conflicts against.
|
2018-11-13 16:42:28 -05:00
|
|
|
* @param {boolean} isCloud Whether the variable is a cloud variable.
|
2018-01-24 17:45:39 -05:00
|
|
|
* @param {function(?string=)=} opt_callback An optional function to be called on
|
2018-01-25 10:42:30 -05:00
|
|
|
* a pre-existing variable of the user-provided name. This function is currently
|
|
|
|
* only used for broadcast messages.
|
|
|
|
* @return {string} The validated name according to the parameters given, if
|
|
|
|
* the name is determined to be valid, or null if the name
|
2018-01-24 17:45:39 -05:00
|
|
|
* is determined to be invalid/in-use, and the calling function should not
|
|
|
|
* proceed with creating or renaming the variable.
|
2018-01-25 10:42:30 -05:00
|
|
|
* @private
|
2018-01-24 17:45:39 -05:00
|
|
|
*/
|
2018-11-13 16:42:28 -05:00
|
|
|
Blockly.Variables.nameValidator_ = function(type, text, workspace, additionalVars,
|
|
|
|
isCloud, opt_callback) {
|
2018-01-24 17:45:39 -05:00
|
|
|
// The validators for the different variable types require slightly different arguments.
|
|
|
|
// For broadcast messages, if a broadcast message of the provided name already exists,
|
|
|
|
// the validator needs to call a function that updates the selected
|
|
|
|
// field option of the dropdown menu of the block that was used to create the new message.
|
2018-01-26 09:33:22 -05:00
|
|
|
// For scalar variables and lists, the validator has the same validation behavior, but needs
|
|
|
|
// to know which type of variable to check for and needs a type-specific error message
|
|
|
|
// that is displayed when a variable of the given name and type already exists.
|
2018-01-24 17:45:39 -05:00
|
|
|
|
|
|
|
if (type == Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE) {
|
|
|
|
return Blockly.Variables.validateBroadcastMessageName_(text, workspace, opt_callback);
|
|
|
|
} else if (type == Blockly.LIST_VARIABLE_TYPE) {
|
2018-11-13 16:42:28 -05:00
|
|
|
return Blockly.Variables.validateScalarVarOrListName_(text, workspace, additionalVars, false, type,
|
2018-01-25 10:42:30 -05:00
|
|
|
Blockly.Msg.LIST_ALREADY_EXISTS);
|
2018-01-29 10:40:07 -05:00
|
|
|
} else {
|
2018-11-13 16:42:28 -05:00
|
|
|
return Blockly.Variables.validateScalarVarOrListName_(text, workspace, additionalVars, isCloud, type,
|
2018-01-25 10:42:30 -05:00
|
|
|
Blockly.Msg.VARIABLE_ALREADY_EXISTS);
|
2018-01-24 17:45:39 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the given name as a broadcast message type.
|
|
|
|
* @param {string} name The name to validate
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace the name should be validated
|
|
|
|
* against.
|
|
|
|
* @param {function(?string=)=} opt_callback An optional function to call if a broadcast
|
|
|
|
* message already exists with the given name. This function will be called on the id
|
|
|
|
* of the existing variable.
|
|
|
|
* @return {string} The validated name, or null if invalid.
|
2018-01-25 10:42:30 -05:00
|
|
|
* @private
|
2018-01-24 17:45:39 -05:00
|
|
|
*/
|
|
|
|
Blockly.Variables.validateBroadcastMessageName_ = function(name, workspace, opt_callback) {
|
2018-01-25 10:42:30 -05:00
|
|
|
if (!name) { // no name was provided or the user cancelled the prompt
|
2018-01-24 17:45:39 -05:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var variable = workspace.getVariable(name, Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE);
|
|
|
|
if (variable) {
|
|
|
|
// If the user provided a name for a broadcast message that already exists,
|
2018-01-25 10:42:30 -05:00
|
|
|
// use the provided callback function to update the selected option in
|
|
|
|
// the field of the block that was used to create
|
2018-01-24 17:45:39 -05:00
|
|
|
// this message.
|
|
|
|
if (opt_callback) {
|
|
|
|
opt_callback(variable.getId());
|
|
|
|
}
|
|
|
|
// Return null to signal to the calling function that we do not want to create
|
2018-01-25 10:42:30 -05:00
|
|
|
// a new variable since one already exists.
|
2018-01-24 17:45:39 -05:00
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
// The name provided is actually a new name, so the calling
|
|
|
|
// function should go ahead and create it as a new variable.
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2018-01-25 10:42:30 -05:00
|
|
|
* Validate the given name as a scalar variable or list type.
|
|
|
|
* This function is also responsible for any user facing error-handling.
|
2018-01-24 17:45:39 -05:00
|
|
|
* @param {string} name The name to validate
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace the name should be validated
|
|
|
|
* against.
|
2018-07-03 14:01:49 -04:00
|
|
|
* @param {Array<string>} additionalVars A list of additional variable names to check
|
|
|
|
* for conflicts against.
|
2018-11-13 16:42:28 -05:00
|
|
|
* @param {boolean} isCloud Whether the variable is a cloud variable.
|
2018-01-25 10:42:30 -05:00
|
|
|
* @param {string} type The type to validate the variable as. This should be one of
|
|
|
|
* Blockly.SCALAR_VARIABLE_TYPE or Blockly.LIST_VARIABLE_TYPE.
|
|
|
|
* @param {string} errorMsg The type-specific error message the user should see
|
|
|
|
* if a variable of the validated, given name and type already exists.
|
2018-01-24 17:45:39 -05:00
|
|
|
* @return {string} The validated name, or null if invalid.
|
2018-01-25 10:42:30 -05:00
|
|
|
* @private
|
2018-01-24 17:45:39 -05:00
|
|
|
*/
|
2018-07-03 14:01:49 -04:00
|
|
|
Blockly.Variables.validateScalarVarOrListName_ = function(name, workspace, additionalVars,
|
2018-11-13 16:42:28 -05:00
|
|
|
isCloud, type, errorMsg) {
|
2018-01-25 10:42:30 -05:00
|
|
|
// For scalar variables, we don't want leading or trailing white space
|
2018-01-24 17:45:39 -05:00
|
|
|
name = Blockly.Variables.trimName_(name);
|
|
|
|
if (!name) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-11-13 16:42:28 -05:00
|
|
|
if (isCloud) {
|
|
|
|
name = Blockly.Variables.CLOUD_PREFIX + name;
|
|
|
|
}
|
2018-07-03 14:01:49 -04:00
|
|
|
if (workspace.getVariable(name, type) || additionalVars.indexOf(name) >= 0) {
|
2018-01-25 10:42:30 -05:00
|
|
|
// error
|
|
|
|
Blockly.alert(errorMsg.replace('%1', name));
|
|
|
|
return null;
|
|
|
|
} else { // trimmed name is valid
|
2018-01-24 17:45:39 -05:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-18 22:47:52 -07:00
|
|
|
/**
|
|
|
|
* Rename a variable with the given workspace, variableType, and oldName.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace on which to rename the
|
|
|
|
* variable.
|
2017-12-19 14:46:53 -05:00
|
|
|
* @param {Blockly.VariableModel} variable Variable to rename.
|
2017-07-18 22:47:52 -07:00
|
|
|
* @param {function(?string=)=} opt_callback A callback. It will
|
|
|
|
* be passed an acceptable new variable name, or null if change is to be
|
|
|
|
* aborted (cancel button), or undefined if an existing variable was chosen.
|
|
|
|
*/
|
|
|
|
Blockly.Variables.renameVariable = function(workspace, variable,
|
2018-01-24 17:45:39 -05:00
|
|
|
opt_callback) {
|
|
|
|
// Validation and modal message/title depends on the variable type
|
2018-01-26 09:33:22 -05:00
|
|
|
var promptMsg, modalTitle;
|
2018-01-24 17:45:39 -05:00
|
|
|
var varType = variable.type;
|
2018-01-29 10:40:07 -05:00
|
|
|
if (varType == Blockly.BROADCAST_MESSAGE_VARIABLE_TYPE) {
|
|
|
|
console.warn('Unexpected attempt to rename a broadcast message with ' +
|
|
|
|
'id: ' + variable.getId() + ' and name: ' + variable.name);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-24 17:45:39 -05:00
|
|
|
if (varType == Blockly.LIST_VARIABLE_TYPE) {
|
|
|
|
promptMsg = Blockly.Msg.RENAME_LIST_TITLE;
|
|
|
|
modalTitle = Blockly.Msg.RENAME_LIST_MODAL_TITLE;
|
2018-01-29 10:40:07 -05:00
|
|
|
} else {
|
|
|
|
// Default for all other types of variables
|
2018-01-24 17:45:39 -05:00
|
|
|
promptMsg = Blockly.Msg.RENAME_VARIABLE_TITLE;
|
|
|
|
modalTitle = Blockly.Msg.RENAME_VARIABLE_MODAL_TITLE;
|
|
|
|
}
|
2018-01-26 09:33:22 -05:00
|
|
|
var validate = Blockly.Variables.nameValidator_.bind(null, varType);
|
2018-01-24 17:45:39 -05:00
|
|
|
|
2018-01-25 10:42:30 -05:00
|
|
|
var promptText = promptMsg.replace('%1', variable.name);
|
2018-12-12 15:30:05 -04:00
|
|
|
var promptDefaultText = variable.name;
|
|
|
|
if (variable.isCloud && variable.name.indexOf(Blockly.Variables.CLOUD_PREFIX) == 0) {
|
|
|
|
promptDefaultText = promptDefaultText.substring(Blockly.Variables.CLOUD_PREFIX.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
Blockly.prompt(promptText, promptDefaultText,
|
2018-07-12 19:15:49 -04:00
|
|
|
function(newName, additionalVars) {
|
2018-11-13 16:42:28 -05:00
|
|
|
if (variable.isCloud &&
|
2018-12-12 15:33:01 -04:00
|
|
|
newName.length > 0 && newName.indexOf(Blockly.Variables.CLOUD_PREFIX) == 0) {
|
2018-12-13 12:38:00 -04:00
|
|
|
newName = newName.substring(Blockly.Variables.CLOUD_PREFIX.length);
|
|
|
|
// The name validator will add the prefix back
|
2018-11-13 16:42:28 -05:00
|
|
|
}
|
2018-07-12 19:15:49 -04:00
|
|
|
additionalVars = additionalVars || [];
|
|
|
|
var additionalVarNames = variable.isLocal ? [] : additionalVars;
|
2018-11-13 16:42:28 -05:00
|
|
|
var validatedText = validate(newName, workspace, additionalVarNames, variable.isCloud);
|
2018-01-25 10:42:30 -05:00
|
|
|
if (validatedText) {
|
|
|
|
workspace.renameVariableById(variable.getId(), validatedText);
|
|
|
|
if (opt_callback) {
|
|
|
|
opt_callback(newName);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// User canceled prompt without a value.
|
|
|
|
if (opt_callback) {
|
|
|
|
opt_callback(null);
|
2017-07-18 22:47:52 -07:00
|
|
|
}
|
2018-01-25 10:42:30 -05:00
|
|
|
}
|
2018-01-29 15:40:49 -05:00
|
|
|
}, modalTitle, varType);
|
2016-07-01 15:51:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2018-01-24 17:45:39 -05:00
|
|
|
* Strip leading and trailing whitespace from the given name, for use with
|
|
|
|
* user provided name for scalar variables and lists.
|
2017-12-21 15:12:11 -05:00
|
|
|
* @param {string} name The user-provided name of the variable.
|
2018-01-24 17:45:39 -05:00
|
|
|
* @return {string} The trimmed name, or whatever falsey value was originally provided.
|
2017-12-21 15:12:11 -05:00
|
|
|
*/
|
2018-01-24 17:45:39 -05:00
|
|
|
Blockly.Variables.trimName_ = function(name) {
|
|
|
|
if (name) {
|
|
|
|
return goog.string.trim(name);
|
|
|
|
} else {
|
|
|
|
// Return whatever was provided
|
|
|
|
return name;
|
2017-12-15 17:33:38 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-06 18:00:33 -07:00
|
|
|
/**
|
|
|
|
* Generate XML string for variable field.
|
|
|
|
* @param {!Blockly.VariableModel} variableModel The variable model to generate
|
|
|
|
* an XML string from.
|
|
|
|
* @param {?string} opt_name The optional name of the field, such as "VARIABLE"
|
|
|
|
* or "LIST". Defaults to "VARIABLE".
|
|
|
|
* @return {string} The generated XML.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Variables.generateVariableFieldXml_ = function(variableModel, opt_name) {
|
2017-08-18 11:18:49 -07:00
|
|
|
// The variable name may be user input, so it may contain characters that need
|
|
|
|
// to be escaped to create valid XML.
|
2017-12-19 14:46:53 -05:00
|
|
|
var typeString = variableModel.type;
|
|
|
|
if (typeString == '') {
|
|
|
|
typeString = '\'\'';
|
|
|
|
}
|
|
|
|
var fieldName = opt_name || 'VARIABLE';
|
|
|
|
var text = '<field name="' + fieldName + '" id="' + variableModel.getId() +
|
2018-01-12 12:03:28 -08:00
|
|
|
'" variabletype="' + goog.string.htmlEscape(typeString) +
|
2017-12-19 14:46:53 -05:00
|
|
|
'">' + goog.string.htmlEscape(variableModel.name) + '</field>';
|
|
|
|
return text;
|
|
|
|
};
|
2017-08-18 11:18:49 -07:00
|
|
|
|
2017-12-19 14:46:53 -05:00
|
|
|
/**
|
|
|
|
* Helper function to look up or create a variable on the given workspace.
|
|
|
|
* If no variable exists, creates and returns it.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace to search for the
|
|
|
|
* variable. It may be a flyout workspace or main workspace.
|
|
|
|
* @param {string} id The ID to use to look up or create the variable, or null.
|
2017-12-19 11:28:23 -08:00
|
|
|
* @param {string=} opt_name The string to use to look up or create the
|
|
|
|
* variable.
|
|
|
|
* @param {string=} opt_type The type to use to look up or create the variable.
|
2017-12-19 14:46:53 -05:00
|
|
|
* @return {!Blockly.VariableModel} The variable corresponding to the given ID
|
|
|
|
* or name + type combination.
|
|
|
|
* @package
|
|
|
|
*/
|
2018-01-12 12:03:28 -08:00
|
|
|
Blockly.Variables.getOrCreateVariablePackage = function(workspace, id, opt_name,
|
2017-12-19 11:28:23 -08:00
|
|
|
opt_type) {
|
|
|
|
var variable = Blockly.Variables.getVariable(workspace, id, opt_name,
|
|
|
|
opt_type);
|
2017-12-19 14:46:53 -05:00
|
|
|
if (!variable) {
|
2017-12-19 11:28:23 -08:00
|
|
|
variable = Blockly.Variables.createVariable_(workspace, id, opt_name,
|
|
|
|
opt_type);
|
2017-12-19 14:46:53 -05:00
|
|
|
}
|
|
|
|
return variable;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up a variable on the given workspace.
|
|
|
|
* Always looks in the main workspace before looking in the flyout workspace.
|
|
|
|
* Always prefers lookup by ID to lookup by name + type.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace to search for the
|
|
|
|
* variable. It may be a flyout workspace or main workspace.
|
|
|
|
* @param {string} id The ID to use to look up the variable, or null.
|
|
|
|
* @param {string=} opt_name The string to use to look up the variable. Only
|
|
|
|
* used if lookup by ID fails.
|
|
|
|
* @param {string=} opt_type The type to use to look up the variable. Only used
|
|
|
|
* if lookup by ID fails.
|
|
|
|
* @return {?Blockly.VariableModel} The variable corresponding to the given ID
|
|
|
|
* or name + type combination, or null if not found.
|
2017-12-19 11:28:23 -08:00
|
|
|
* @package
|
2017-12-19 14:46:53 -05:00
|
|
|
*/
|
|
|
|
Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) {
|
|
|
|
var potentialVariableMap = workspace.getPotentialVariableMap();
|
|
|
|
// Try to just get the variable, by ID if possible.
|
|
|
|
if (id) {
|
|
|
|
// Look in the real variable map before checking the potential variable map.
|
|
|
|
var variable = workspace.getVariableById(id);
|
|
|
|
if (!variable && potentialVariableMap) {
|
|
|
|
variable = potentialVariableMap.getVariableById(id);
|
|
|
|
}
|
2018-01-12 12:03:28 -08:00
|
|
|
} else if (opt_name) {
|
|
|
|
if (opt_type == undefined) {
|
|
|
|
throw new Error('Tried to look up a variable by name without a type');
|
|
|
|
}
|
2017-12-19 14:46:53 -05:00
|
|
|
// Otherwise look up by name and type.
|
|
|
|
var variable = workspace.getVariable(opt_name, opt_type);
|
|
|
|
if (!variable && potentialVariableMap) {
|
|
|
|
variable = potentialVariableMap.getVariable(opt_name, opt_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return variable;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to create a variable on the given workspace.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace in which to create the
|
|
|
|
* variable. It may be a flyout workspace or main workspace.
|
|
|
|
* @param {string} id The ID to use to create the variable, or null.
|
2017-12-19 11:28:23 -08:00
|
|
|
* @param {string=} opt_name The string to use to create the variable.
|
|
|
|
* @param {string=} opt_type The type to use to create the variable.
|
2017-12-19 14:46:53 -05:00
|
|
|
* @return {!Blockly.VariableModel} The variable corresponding to the given ID
|
|
|
|
* or name + type combination.
|
|
|
|
* @private
|
|
|
|
*/
|
2017-12-19 11:28:23 -08:00
|
|
|
Blockly.Variables.createVariable_ = function(workspace, id, opt_name,
|
|
|
|
opt_type) {
|
2017-12-19 14:46:53 -05:00
|
|
|
var potentialVariableMap = workspace.getPotentialVariableMap();
|
|
|
|
// Variables without names get uniquely named for this workspace.
|
2017-12-19 11:28:23 -08:00
|
|
|
if (!opt_name) {
|
2017-12-19 14:46:53 -05:00
|
|
|
var ws = workspace.isFlyout ? workspace.targetWorkspace : workspace;
|
2017-12-19 11:28:23 -08:00
|
|
|
opt_name = Blockly.Variables.generateUniqueName(ws);
|
2017-12-19 14:46:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a potential variable if in the flyout.
|
|
|
|
if (potentialVariableMap) {
|
2017-12-19 11:28:23 -08:00
|
|
|
var variable = potentialVariableMap.createVariable(opt_name, opt_type, id);
|
2017-12-19 14:46:53 -05:00
|
|
|
} else { // In the main workspace, create a real variable.
|
2017-12-19 11:28:23 -08:00
|
|
|
var variable = workspace.createVariable(opt_name, opt_type, id);
|
2017-12-19 14:46:53 -05:00
|
|
|
}
|
|
|
|
return variable;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get the list of variables that have been added to the
|
|
|
|
* workspace after adding a new block, using the given list of variables that
|
|
|
|
* were in the workspace before the new block was added.
|
|
|
|
* @param {!Blockly.Workspace} workspace The workspace to inspect.
|
|
|
|
* @param {!Array.<!Blockly.VariableModel>} originalVariables The array of
|
|
|
|
* variables that existed in the workspace before adding the new block.
|
|
|
|
* @return {!Array.<!Blockly.VariableModel>} The new array of variables that were
|
|
|
|
* freshly added to the workspace after creating the new block, or [] if no
|
|
|
|
* new variables were added to the workspace.
|
|
|
|
* @package
|
|
|
|
*/
|
|
|
|
Blockly.Variables.getAddedVariables = function(workspace, originalVariables) {
|
|
|
|
var allCurrentVariables = workspace.getAllVariables();
|
|
|
|
var addedVariables = [];
|
|
|
|
if (originalVariables.length != allCurrentVariables.length) {
|
|
|
|
for (var i = 0; i < allCurrentVariables.length; i++) {
|
|
|
|
var variable = allCurrentVariables[i];
|
|
|
|
// For any variable that is present in allCurrentVariables but not
|
|
|
|
// present in originalVariables, add the variable to addedVariables.
|
|
|
|
if (!originalVariables.includes(variable)) {
|
|
|
|
addedVariables.push(variable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return addedVariables;
|
2017-07-06 18:00:33 -07:00
|
|
|
};
|