scratch-blocks/core/scrollbar.js

876 lines
29 KiB
JavaScript
Raw Permalink Normal View History

/**
* @license
* Visual Blocks Editor
*
* Copyright 2011 Google Inc.
2014-10-07 13:09:55 -07:00
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Library for creating scrollbars.
* @author fraser@google.com (Neil Fraser)
*/
'use strict';
goog.provide('Blockly.Scrollbar');
goog.provide('Blockly.ScrollbarPair');
goog.require('goog.dom');
goog.require('goog.events');
/**
* A note on units: most of the numbers that are in CSS pixels are scaled if the
* scrollbar is in a mutator.
*/
/**
* Class for a pair of scrollbars. Horizontal and vertical.
* @param {!Blockly.Workspace} workspace Workspace to bind the scrollbars to.
* @constructor
*/
Blockly.ScrollbarPair = function(workspace) {
this.workspace_ = workspace;
this.hScroll = new Blockly.Scrollbar(
workspace, true, true, 'blocklyMainWorkspaceScrollbar');
this.vScroll = new Blockly.Scrollbar(
workspace, false, true, 'blocklyMainWorkspaceScrollbar');
this.corner_ = Blockly.utils.createSvgElement(
'rect',
{
'height': Blockly.Scrollbar.scrollbarThickness,
'width': Blockly.Scrollbar.scrollbarThickness,
'class': 'blocklyScrollbarBackground'
},
null);
2018-08-16 16:46:19 -07:00
Blockly.utils.insertAfter(this.corner_, workspace.getBubbleCanvas());
};
/**
* Previously recorded metrics from the workspace.
* @type {Object}
* @private
*/
Blockly.ScrollbarPair.prototype.oldHostMetrics_ = null;
/**
* Dispose of this pair of scrollbars.
* Unlink from all DOM elements to prevent memory leaks.
*/
Blockly.ScrollbarPair.prototype.dispose = function() {
goog.dom.removeNode(this.corner_);
this.corner_ = null;
this.workspace_ = null;
this.oldHostMetrics_ = null;
this.hScroll.dispose();
this.hScroll = null;
this.vScroll.dispose();
this.vScroll = null;
};
/**
* Recalculate both of the scrollbars' locations and lengths.
* Also reposition the corner rectangle.
*/
Blockly.ScrollbarPair.prototype.resize = function() {
// Look up the host metrics once, and use for both scrollbars.
var hostMetrics = this.workspace_.getMetrics();
if (!hostMetrics) {
// Host element is likely not visible.
return;
}
// Only change the scrollbars if there has been a change in metrics.
var resizeH = false;
var resizeV = false;
if (!this.oldHostMetrics_ ||
this.oldHostMetrics_.viewWidth != hostMetrics.viewWidth ||
this.oldHostMetrics_.viewHeight != hostMetrics.viewHeight ||
this.oldHostMetrics_.absoluteTop != hostMetrics.absoluteTop ||
this.oldHostMetrics_.absoluteLeft != hostMetrics.absoluteLeft) {
// The window has been resized or repositioned.
resizeH = true;
resizeV = true;
} else {
// Has the content been resized or moved?
if (!this.oldHostMetrics_ ||
this.oldHostMetrics_.contentWidth != hostMetrics.contentWidth ||
this.oldHostMetrics_.viewLeft != hostMetrics.viewLeft ||
this.oldHostMetrics_.contentLeft != hostMetrics.contentLeft) {
resizeH = true;
}
if (!this.oldHostMetrics_ ||
this.oldHostMetrics_.contentHeight != hostMetrics.contentHeight ||
this.oldHostMetrics_.viewTop != hostMetrics.viewTop ||
this.oldHostMetrics_.contentTop != hostMetrics.contentTop) {
resizeV = true;
}
}
if (resizeH) {
this.hScroll.resize(hostMetrics);
}
if (resizeV) {
this.vScroll.resize(hostMetrics);
}
// Reposition the corner square.
if (!this.oldHostMetrics_ ||
this.oldHostMetrics_.viewWidth != hostMetrics.viewWidth ||
this.oldHostMetrics_.absoluteLeft != hostMetrics.absoluteLeft) {
this.corner_.setAttribute('x', this.vScroll.position_.x);
}
if (!this.oldHostMetrics_ ||
this.oldHostMetrics_.viewHeight != hostMetrics.viewHeight ||
this.oldHostMetrics_.absoluteTop != hostMetrics.absoluteTop) {
this.corner_.setAttribute('y', this.hScroll.position_.y);
}
// Cache the current metrics to potentially short-cut the next resize event.
this.oldHostMetrics_ = hostMetrics;
};
/**
* Set the handles of both scrollbars to be at a certain position in CSS pixels
* relative to their parents.
* @param {number} x Horizontal scroll value.
* @param {number} y Vertical scroll value.
*/
Blockly.ScrollbarPair.prototype.set = function(x, y) {
2016-02-01 16:13:05 -08:00
// This function is equivalent to:
// this.hScroll.set(x);
// this.vScroll.set(y);
// However, that calls setMetrics twice which causes a chain of
// getAttribute->setAttribute->getAttribute resulting in an extra layout pass.
// Combining them speeds up rendering.
2016-02-01 16:13:05 -08:00
var xyRatio = {};
var hHandlePosition = x * this.hScroll.ratio_;
var vHandlePosition = y * this.vScroll.ratio_;
2016-02-01 16:13:05 -08:00
var hBarLength = this.hScroll.scrollViewSize_;
var vBarLength = this.vScroll.scrollViewSize_;
xyRatio.x = this.getRatio_(hHandlePosition, hBarLength);
xyRatio.y = this.getRatio_(vHandlePosition, vBarLength);
this.workspace_.setMetrics(xyRatio);
this.hScroll.setHandlePosition(hHandlePosition);
this.vScroll.setHandlePosition(vHandlePosition);
};
/**
* Helper to calculate the ratio of handle position to scrollbar view size.
2016-05-27 10:25:19 -07:00
* @param {number} handlePosition The value of the handle.
* @param {number} viewSize The total size of the scrollbar's view.
2016-03-18 15:19:26 -07:00
* @return {number} Ratio.
* @private
*/
Blockly.ScrollbarPair.prototype.getRatio_ = function(handlePosition, viewSize) {
var ratio = handlePosition / viewSize;
2016-02-01 16:13:05 -08:00
if (isNaN(ratio)) {
return 0;
2016-02-01 16:13:05 -08:00
}
return ratio;
};
// --------------------------------------------------------------------
/**
* Class for a pure SVG scrollbar.
* This technique offers a scrollbar that is guaranteed to work, but may not
* look or behave like the system's scrollbars.
* @param {!Blockly.Workspace} workspace Workspace to bind the scrollbar to.
* @param {boolean} horizontal True if horizontal, false if vertical.
2016-03-18 15:19:26 -07:00
* @param {boolean=} opt_pair True if scrollbar is part of a horiz/vert pair.
* @param {string=} opt_class A class to be applied to this scrollbar.
* @constructor
*/
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
Blockly.Scrollbar = function(workspace, horizontal, opt_pair, opt_class) {
this.workspace_ = workspace;
this.pair_ = opt_pair || false;
this.horizontal_ = horizontal;
this.oldHostMetrics_ = null;
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
this.createDom_(opt_class);
/**
* The upper left corner of the scrollbar's SVG group in CSS pixels relative
* to the scrollbar's origin. This is usually relative to the injection div
* origin.
* @type {goog.math.Coordinate}
* @private
*/
this.position_ = new goog.math.Coordinate(0, 0);
// Store the thickness in a temp variable for readability.
var scrollbarThickness = Blockly.Scrollbar.scrollbarThickness;
if (horizontal) {
this.svgBackground_.setAttribute('height', scrollbarThickness);
this.outerSvg_.setAttribute('height', scrollbarThickness);
this.svgHandle_.setAttribute('height', scrollbarThickness - 5);
2016-05-27 10:25:19 -07:00
this.svgHandle_.setAttribute('y', 2.5);
this.lengthAttribute_ = 'width';
this.positionAttribute_ = 'x';
} else {
this.svgBackground_.setAttribute('width', scrollbarThickness);
this.outerSvg_.setAttribute('width', scrollbarThickness);
this.svgHandle_.setAttribute('width', scrollbarThickness - 5);
2016-05-27 10:25:19 -07:00
this.svgHandle_.setAttribute('x', 2.5);
this.lengthAttribute_ = 'height';
this.positionAttribute_ = 'y';
}
var scrollbar = this;
this.onMouseDownBarWrapper_ = Blockly.bindEventWithChecks_(
this.svgBackground_, 'mousedown', scrollbar, scrollbar.onMouseDownBar_);
this.onMouseDownHandleWrapper_ = Blockly.bindEventWithChecks_(this.svgHandle_,
2016-05-27 10:25:19 -07:00
'mousedown', scrollbar, scrollbar.onMouseDownHandle_);
};
/**
* The location of the origin of the workspace that the scrollbar is in,
* measured in CSS pixels relative to the injection div origin. This is usually
* (0, 0). When the scrollbar is in a flyout it may have a different origin.
* @type {goog.math.Coordinate}
* @private
*/
Blockly.Scrollbar.prototype.origin_ = new goog.math.Coordinate(0, 0);
/**
* Whether or not the origin of the scrollbar has changed. Used
* to help decide whether or not the reflow/resize calls need to happen.
* @type {boolean}
* @private
*/
Blockly.Scrollbar.prototype.originHasChanged_ = true;
/**
* The size of the area within which the scrollbar handle can move, in CSS
* pixels.
* @type {number}
* @private
*/
Blockly.Scrollbar.prototype.scrollViewSize_ = 0;
/**
* The length of the scrollbar handle in CSS pixels.
* @type {number}
* @private
*/
Blockly.Scrollbar.prototype.handleLength_ = 0;
/**
* The offset of the start of the handle from the scrollbar position, in CSS
* pixels.
* @type {number}
* @private
*/
Blockly.Scrollbar.prototype.handlePosition_ = 0;
/**
* Whether the scrollbar handle is visible.
* @type {boolean}
* @private
*/
Blockly.Scrollbar.prototype.isVisible_ = true;
/**
* Whether the workspace containing this scrollbar is visible.
* @type {boolean}
* @private
*/
Blockly.Scrollbar.prototype.containerVisible_ = true;
2014-09-08 14:26:52 -07:00
/**
* Width of vertical scrollbar or height of horizontal scrollbar in CSS pixels.
* Scrollbars should be larger on touch devices.
2014-09-08 14:26:52 -07:00
*/
2016-10-03 08:32:07 -04:00
Blockly.Scrollbar.scrollbarThickness = 11;
if (goog.events.BrowserFeature.TOUCH_ENABLED) {
Blockly.Scrollbar.scrollbarThickness = 14;
2014-12-23 11:22:02 -08:00
}
2014-09-08 14:26:52 -07:00
/**
* @param {!Object} first An object containing computed measurements of a
* workspace.
* @param {!Object} second Another object containing computed measurements of a
* workspace.
* @return {boolean} Whether the two sets of metrics are equivalent.
* @private
*/
Blockly.Scrollbar.metricsAreEquivalent_ = function(first, second) {
if (!(first && second)) {
return false;
}
if (first.viewWidth != second.viewWidth ||
first.viewHeight != second.viewHeight ||
first.viewLeft != second.viewLeft ||
first.viewTop != second.viewTop ||
first.absoluteTop != second.absoluteTop ||
first.absoluteLeft != second.absoluteLeft ||
first.contentWidth != second.contentWidth ||
first.contentHeight != second.contentHeight ||
first.contentLeft != second.contentLeft ||
first.contentTop != second.contentTop) {
return false;
}
return true;
};
/**
* Dispose of this scrollbar.
* Unlink from all DOM elements to prevent memory leaks.
*/
2014-09-08 14:26:52 -07:00
Blockly.Scrollbar.prototype.dispose = function() {
this.cleanUp_();
Blockly.unbindEvent_(this.onMouseDownBarWrapper_);
this.onMouseDownBarWrapper_ = null;
2016-05-27 10:25:19 -07:00
Blockly.unbindEvent_(this.onMouseDownHandleWrapper_);
this.onMouseDownHandleWrapper_ = null;
goog.dom.removeNode(this.outerSvg_);
this.outerSvg_ = null;
this.svgGroup_ = null;
this.svgBackground_ = null;
2016-05-27 10:25:19 -07:00
this.svgHandle_ = null;
this.workspace_ = null;
};
/**
* Set the length of the scrollbar's handle and change the SVG attribute
* accordingly.
* @param {number} newLength The new scrollbar handle length in CSS pixels.
*/
Blockly.Scrollbar.prototype.setHandleLength_ = function(newLength) {
this.handleLength_ = newLength;
2016-05-27 10:25:19 -07:00
this.svgHandle_.setAttribute(this.lengthAttribute_, this.handleLength_);
};
/**
* Set the offset of the scrollbar's handle from the scrollbar's position, and
* change the SVG attribute accordingly.
* @param {number} newPosition The new scrollbar handle offset in CSS pixels.
*/
Blockly.Scrollbar.prototype.setHandlePosition = function(newPosition) {
this.handlePosition_ = newPosition;
2016-05-27 10:25:19 -07:00
this.svgHandle_.setAttribute(this.positionAttribute_, this.handlePosition_);
};
/**
* Set the size of the scrollbar's background and change the SVG attribute
* accordingly.
* @param {number} newSize The new scrollbar background length in CSS pixels.
* @private
*/
Blockly.Scrollbar.prototype.setScrollViewSize_ = function(newSize) {
this.scrollViewSize_ = newSize;
this.outerSvg_.setAttribute(this.lengthAttribute_, this.scrollViewSize_);
this.svgBackground_.setAttribute(this.lengthAttribute_, this.scrollViewSize_);
};
/**
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
* Set whether this scrollbar's container is visible.
* @param {boolean} visible Whether the container is visible.
*/
Blockly.ScrollbarPair.prototype.setContainerVisible = function(visible) {
this.hScroll.setContainerVisible(visible);
this.vScroll.setContainerVisible(visible);
};
/**
* Set the position of the scrollbar's SVG group in CSS pixels relative to the
* scrollbar's origin. This sets the scrollbar's location within the workspace.
* @param {number} x The new x coordinate.
* @param {number} y The new y coordinate.
* @private
*/
Blockly.Scrollbar.prototype.setPosition_ = function(x, y) {
this.position_.x = x;
this.position_.y = y;
var tempX = this.position_.x + this.origin_.x;
var tempY = this.position_.y + this.origin_.y;
var transform = 'translate(' + tempX + 'px,' + tempY + 'px)';
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
Blockly.utils.setCssTransform(this.outerSvg_, transform);
};
/**
* Recalculate the scrollbar's location and its length.
* @param {Object=} opt_metrics A data structure of from the describing all the
* required dimensions. If not provided, it will be fetched from the host
* object.
*/
2014-09-08 14:26:52 -07:00
Blockly.Scrollbar.prototype.resize = function(opt_metrics) {
// Determine the location, height and width of the host element.
var hostMetrics = opt_metrics;
if (!hostMetrics) {
hostMetrics = this.workspace_.getMetrics();
if (!hostMetrics) {
// Host element is likely not visible.
return;
}
}
// If the origin has changed (e.g. the toolbox is moving from start to end)
// we want to continue with the resize even if workspace metrics haven't.
if (this.originHasChanged_) {
this.originHasChanged_ = false;
} else if (Blockly.Scrollbar.metricsAreEquivalent_(hostMetrics,
this.oldHostMetrics_)) {
return;
}
this.oldHostMetrics_ = hostMetrics;
/* hostMetrics is an object with the following properties.
* .viewHeight: Height of the visible rectangle,
* .viewWidth: Width of the visible rectangle,
* .contentHeight: Height of the contents,
* .contentWidth: Width of the content,
* .viewTop: Offset of top edge of visible rectangle from parent,
* .viewLeft: Offset of left edge of visible rectangle from parent,
* .contentTop: Offset of the top-most content from the y=0 coordinate,
* .contentLeft: Offset of the left-most content from the x=0 coordinate,
* .absoluteTop: Top-edge of view.
* .absoluteLeft: Left-edge of view.
*/
if (this.horizontal_) {
this.resizeHorizontal_(hostMetrics);
} else {
this.resizeVertical_(hostMetrics);
}
// Resizing may have caused some scrolling.
this.onScroll_();
};
/**
* Recalculate a horizontal scrollbar's location and length.
* @param {!Object} hostMetrics A data structure describing all the
2016-04-21 06:05:25 -07:00
* required dimensions, possibly fetched from the host object.
* @private
*/
Blockly.Scrollbar.prototype.resizeHorizontal_ = function(hostMetrics) {
// TODO: Inspect metrics to determine if we can get away with just a content
// resize.
this.resizeViewHorizontal(hostMetrics);
};
/**
* Recalculate a horizontal scrollbar's location on the screen and path length.
* This should be called when the layout or size of the window has changed.
* @param {!Object} hostMetrics A data structure describing all the
* required dimensions, possibly fetched from the host object.
*/
Blockly.Scrollbar.prototype.resizeViewHorizontal = function(hostMetrics) {
var viewSize = hostMetrics.viewWidth - 1;
if (this.pair_) {
// Shorten the scrollbar to make room for the corner square.
viewSize -= Blockly.Scrollbar.scrollbarThickness;
}
this.setScrollViewSize_(Math.max(0, viewSize));
var xCoordinate = hostMetrics.absoluteLeft + 0.5;
if (this.pair_ && this.workspace_.RTL) {
xCoordinate += Blockly.Scrollbar.scrollbarThickness;
}
// Horizontal toolbar should always be just above the bottom of the workspace.
var yCoordinate = hostMetrics.absoluteTop + hostMetrics.viewHeight -
Blockly.Scrollbar.scrollbarThickness - 0.5;
this.setPosition_(xCoordinate, yCoordinate);
// If the view has been resized, a content resize will also be necessary. The
// reverse is not true.
this.resizeContentHorizontal(hostMetrics);
};
/**
* Recalculate a horizontal scrollbar's location within its path and length.
* This should be called when the contents of the workspace have changed.
* @param {!Object} hostMetrics A data structure describing all the
* required dimensions, possibly fetched from the host object.
*/
Blockly.Scrollbar.prototype.resizeContentHorizontal = function(hostMetrics) {
if (!this.pair_) {
// Only show the scrollbar if needed.
// Ideally this would also apply to scrollbar pairs, but that's a bigger
// headache (due to interactions with the corner square).
this.setVisible(this.scrollViewSize_ < hostMetrics.contentWidth);
}
this.ratio_ = this.scrollViewSize_ / hostMetrics.contentWidth;
if (this.ratio_ == -Infinity || this.ratio_ == Infinity ||
isNaN(this.ratio_)) {
this.ratio_ = 0;
}
var handleLength = hostMetrics.viewWidth * this.ratio_;
this.setHandleLength_(Math.max(0, handleLength));
var handlePosition = (hostMetrics.viewLeft - hostMetrics.contentLeft) *
this.ratio_;
this.setHandlePosition(this.constrainHandle_(handlePosition));
};
/**
* Recalculate a vertical scrollbar's location and length.
* @param {!Object} hostMetrics A data structure describing all the
2016-04-21 06:05:25 -07:00
* required dimensions, possibly fetched from the host object.
* @private
*/
Blockly.Scrollbar.prototype.resizeVertical_ = function(hostMetrics) {
// TODO: Inspect metrics to determine if we can get away with just a content
// resize.
this.resizeViewVertical(hostMetrics);
};
/**
* Recalculate a vertical scrollbar's location on the screen and path length.
* This should be called when the layout or size of the window has changed.
* @param {!Object} hostMetrics A data structure describing all the
* required dimensions, possibly fetched from the host object.
*/
Blockly.Scrollbar.prototype.resizeViewVertical = function(hostMetrics) {
var viewSize = hostMetrics.viewHeight - 1;
if (this.pair_) {
// Shorten the scrollbar to make room for the corner square.
viewSize -= Blockly.Scrollbar.scrollbarThickness;
}
this.setScrollViewSize_(Math.max(0, viewSize));
var xCoordinate = hostMetrics.absoluteLeft + 0.5;
if (!this.workspace_.RTL) {
xCoordinate += hostMetrics.viewWidth -
Blockly.Scrollbar.scrollbarThickness - 1;
}
var yCoordinate = hostMetrics.absoluteTop + 0.5;
this.setPosition_(xCoordinate, yCoordinate);
// If the view has been resized, a content resize will also be necessary. The
// reverse is not true.
this.resizeContentVertical(hostMetrics);
};
/**
* Recalculate a vertical scrollbar's location within its path and length.
* This should be called when the contents of the workspace have changed.
* @param {!Object} hostMetrics A data structure describing all the
* required dimensions, possibly fetched from the host object.
*/
Blockly.Scrollbar.prototype.resizeContentVertical = function(hostMetrics) {
if (!this.pair_) {
// Only show the scrollbar if needed.
this.setVisible(this.scrollViewSize_ < hostMetrics.contentHeight);
}
this.ratio_ = this.scrollViewSize_ / hostMetrics.contentHeight;
if (this.ratio_ == -Infinity || this.ratio_ == Infinity ||
isNaN(this.ratio_)) {
this.ratio_ = 0;
}
var handleLength = hostMetrics.viewHeight * this.ratio_;
this.setHandleLength_(Math.max(0, handleLength));
var handlePosition = (hostMetrics.viewTop - hostMetrics.contentTop) *
this.ratio_;
this.setHandlePosition(this.constrainHandle_(handlePosition));
};
/**
* Create all the DOM elements required for a scrollbar.
* The resulting widget is not sized.
* @param {string=} opt_class A class to be applied to this scrollbar.
* @private
*/
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
Blockly.Scrollbar.prototype.createDom_ = function(opt_class) {
/* Create the following DOM:
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
<svg class="blocklyScrollbarHorizontal optionalClass">
<g>
<rect class="blocklyScrollbarBackground" />
<rect class="blocklyScrollbarHandle" rx="8" ry="8" />
</g>
</svg>
*/
2015-07-14 23:13:09 -07:00
var className = 'blocklyScrollbar' +
(this.horizontal_ ? 'Horizontal' : 'Vertical');
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
if (opt_class) {
className += ' ' + opt_class;
}
this.outerSvg_ = Blockly.utils.createSvgElement(
'svg', {'class': className}, null);
this.svgGroup_ = Blockly.utils.createSvgElement('g', {}, this.outerSvg_);
this.svgBackground_ = Blockly.utils.createSvgElement(
'rect', {'class': 'blocklyScrollbarBackground'}, this.svgGroup_);
var radius = Math.floor((Blockly.Scrollbar.scrollbarThickness - 5) / 2);
this.svgHandle_ = Blockly.utils.createSvgElement(
'rect',
{
'class': 'blocklyScrollbarHandle',
'rx': radius,
'ry': radius
},
this.svgGroup_);
2018-08-16 16:46:19 -07:00
Blockly.utils.insertAfter(this.outerSvg_, this.workspace_.getParentSvg());
};
/**
* Is the scrollbar visible. Non-paired scrollbars disappear when they aren't
* needed.
* @return {boolean} True if visible.
*/
2014-09-08 14:26:52 -07:00
Blockly.Scrollbar.prototype.isVisible = function() {
return this.isVisible_;
};
/**
* Set whether the scrollbar's container is visible and update
* display accordingly if visibility has changed.
* @param {boolean} visible Whether the container is visible
*/
Blockly.Scrollbar.prototype.setContainerVisible = function(visible) {
var visibilityChanged = (visible != this.containerVisible_);
this.containerVisible_ = visible;
if (visibilityChanged) {
this.updateDisplay_();
}
};
/**
* Set whether the scrollbar is visible.
* Only applies to non-paired scrollbars.
* @param {boolean} visible True if visible.
*/
2014-09-08 14:26:52 -07:00
Blockly.Scrollbar.prototype.setVisible = function(visible) {
var visibilityChanged = (visible != this.isVisible());
// Ideally this would also apply to scrollbar pairs, but that's a bigger
// headache (due to interactions with the corner square).
if (this.pair_) {
throw 'Unable to toggle visibility of paired scrollbars.';
}
this.isVisible_ = visible;
if (visibilityChanged) {
this.updateDisplay_();
}
};
/**
* Update visibility of scrollbar based on whether it thinks it should
* be visible and whether its containing workspace is visible.
* We cannot rely on the containing workspace being hidden to hide us
* because it is not necessarily our parent in the DOM.
*/
Blockly.Scrollbar.prototype.updateDisplay_ = function() {
var show = true;
// Check whether our parent/container is visible.
if (!this.containerVisible_) {
show = false;
} else {
show = this.isVisible();
}
if (show) {
this.outerSvg_.setAttribute('display', 'block');
} else {
this.outerSvg_.setAttribute('display', 'none');
}
};
/**
* Scroll by one pageful.
* Called when scrollbar background is clicked.
* @param {!Event} e Mouse down event.
* @private
*/
2014-09-08 14:26:52 -07:00
Blockly.Scrollbar.prototype.onMouseDownBar_ = function(e) {
this.workspace_.markFocused();
Blockly.Touch.clearTouchIdentifier(); // This is really a click.
this.cleanUp_();
if (Blockly.utils.isRightButton(e)) {
// Right-click.
// Scrollbars have no context menu.
e.stopPropagation();
return;
}
var mouseXY = Blockly.utils.mouseToSvg(e, this.workspace_.getParentSvg(),
Merge google/develop June 22 (#441) * Localisation updates from https://translatewiki.net. * test page that creates random blocks and randomly drags them around the page * Localisation updates from https://translatewiki.net. * add missing return in fake drag * get rid of drag_tests file: * Generated JS helper functions should be camelCase. Complying with Google style guide. * Localisation updates from https://translatewiki.net. * Fix extra category error. Clean up code, rename variables, reduce line lengths, fix lint issues. * Remove claim that good.string.quote should be used. * Change the blockly workspace resizing strategy. (#386) * Add a new method to be called when the contents of the workspace change and the scrollbars need to be adjusted but the the chrome (trash, toolbox, etc) are expected to stay in the same place. Change a bunch of calls to svgResize to either be removed or call the new method instead. This is a nice performance win since the offsetHeight/Width call in svgResize can be expensive, especially when called as often as we do - there was some layout thrashing. This also paves the way for moving calls to recordDeleteAreas (which is also expensive) to a more cacheable spot than on every mouse down/touch event. of things (namely the scrollbars) * Fix size of graph demo when it first loads by calling svgResize. The graph starts with fixed width and was relying on a resize event to fire (which I believe was removed in commit 217c681b86b0f2df76c479c9efae62e6e). * Fix the resizing of the code demo. The demo's tab min-width used to match the toolbox's width was only being set on a resize event, but commit 217c681b86b0f2df76c479c9efae62e6e changed how that worked. * Fix up some comments. * Use specific workspaces rather than Blockly.getMainWorkspace(). * Make workspace required for resizeSvgContents and update some calls to send real workspaces rather than ones that are null. Remove the private tag on terminateDrag_ because it is only actually called from outside the BlockSvg object. * Remove a rogue period. * Recategorize BlockSvg.terminateDrag_ to @package instead of @private so that other developers don't use it, but it still can be used by other Blockly classes. * Add a TODO to fix issue #307. * Add @package to workspace resizeContents. * Routine recompile * Fix unit tests. * Fix inheritance on rendered connection. Closure compiler on maximum compression breaks badly due to lack of @extends attribute. * Add toolbox location and toolbox mode options to playground. * Increase commonality between playgrounds. * Properly deal with shadow statement blocks in stacks. * Localisation updates from https://translatewiki.net. * Use a comment block for function comments in generated JS, Python and Dart. * Fix typo in flyout.js (#403) * Fix typo in flyout.js (#402) * Line wrap comments in generated code. * Remove reference to undefined variable (#413) REASON_MUST_DISCONNECT was removed by a refactor in 2a1ffa1. * Fix airstrike by grabbing the correct toolbox element. (#411) Probably broken in 266e2ffa9a017d21d7ca2f151730d6ecfcecf173. * Localisation updates from https://translatewiki.net. * Fix issue #406 by calling resize from the keypress handler on text inputs. (#408) * Remove shadow blocks from Accessible Blockly demo. Update README. * Generate for loops on one line. * Introduce a common translation pipe; remove local stringMap attributes. Fix variable name error in paste functions. Minor linting. * Fix precedence on isIndex blocks. * Add indexing setting for JavaScript Generation (#419) Adding setting to allow for switching between zero and one based indexing for Blockly Blocks such that the generated code will use this flag to determine whether one based or zero based indexing should be used. One based indexing is enabled by default. * Remove unused functions and dependencies. * Remove the unnecessary construction of new services. * Fix sort block in JS to satisfy tests. * Trigger a contents resize in block's moveBy. (#422) This fixes #420 but and it also fixes some other similar problems with copy/paste and other users of moveBy. * Consolidate the usages of the 'blockly-disabled' label. * Fix error when undoing a shadow block replacement. Issue #415. * Unify setActiveDesc() and updateSelectedNode() in the TreeService. Move function calls made directly within the template to the correct hooks. * Standardize naming of components. * Prevent collisions between user functions and helper functions. * Localisation updates from https://translatewiki.net. * Fix #425. Attash the resize handler to the workspace so it can be removed (#429) when workspace.dispose() is called. * Change the TreeService to a singleton. * Remove unneeded generated parens around function calls in indexOf blocks. * Fix #423 by calling workspace's resize when the flyout reflows. (#430) * Updating URLs to reflect new docs. (#418) * Updating URLs to reflect new docs. Removing -blockly in URLs. * Rebuilt. * Routine recompile * Prevent selected block from ending up underneath a bumped block. * Fix undo on fields with validators with side effects. * Don't fire change event on fields that haven't been named yet. * Localisation updates from https://translatewiki.net. * Fix tree focus issues. * Fix remaining focus issues on block deletion. * cache delete areas instead of recalculating them onMouseDown * Cache screen CTM for performance improvement. * Call svgResizeContents from block_svg's dipose so that deleting blocks (#434) from the context menu (or anywhere really) causes the workspace to recalculate its size. Remove the call to svgResizeContents from onMouseUp's logic for determining whether the block is being dropped in the trash since it calls dispose. One side effect of this is that when you delete multiple blocks resize gets called for each of them and the scrollbars move during the operation. This is most obviously seen by doing an airstrike in the playground and then deleting all the blocks at once. * Allow terminal blocks to replace other terminal blocks (#433) * Allow terminal blocks to replace other terminal blocks * Updated test to allow replacing terminal blocks * Refactor how activeDescendant is set. Introduce helper functions to ensure that calls like pasteAbove() preserve the focus. * Localisation updates from https://translatewiki.net. * Remove unnecessary logging. * Reduce unneeded parentheses in JS and Python. * Start using field_number. * Make it easy to disable unconnected blocks. * Routine recompile. * Check if matrix is null in mouseToSvg * Remove js/ localizations pre-merge * Fix change to block_render_svg * Fix error in xml.js * Playground merge * Add simple toolboxes to playgrounds * Fix flyout reference in events listener * Move tokenizeIntepolation into Blockly.utils namespace. * Use simpler message interpolation in Code demo. * Create console stub for IE 9. * Don't output blockId if not set (e.g., toolbox category event). (#443) * Fix block in multi-playground * Increase commonality between playgrounds. # Conflicts: # tests/multi_playground.html # tests/playground.html * Remove "show flyouts" button * Recompile for merge June 22
2016-06-22 17:50:16 -04:00
this.workspace_.getInverseScreenCTM());
var mouseLocation = this.horizontal_ ? mouseXY.x : mouseXY.y;
var handleXY = Blockly.utils.getInjectionDivXY_(this.svgHandle_);
var handleStart = this.horizontal_ ? handleXY.x : handleXY.y;
var handlePosition = this.handlePosition_;
var pageLength = this.handleLength_ * 0.95;
if (mouseLocation <= handleStart) {
// Decrease the scrollbar's value by a page.
handlePosition -= pageLength;
} else if (mouseLocation >= handleStart + this.handleLength_) {
// Increase the scrollbar's value by a page.
handlePosition += pageLength;
}
// When the scrollbars are clicked, hide the WidgetDiv/DropDownDiv without
// animation in anticipation of a workspace move.
Blockly.WidgetDiv.hide(true);
Implement drop-down menus and icon picker field (#233) * Icon menu and drop-down stubs * Recompile 4/15 * Fix stubs to draw shadow block for drop-down * Fix rendering of shadow for icon menu * Add arrow to dropdown button * Add drop-down buttons to rest of examples * Implementation of drop-down div including positioning * Drop-downs take colours from the blocks * Fix scaled secondary position of drop-downs * Fix arrow positioning for RTL * Use SVG parentNode for sizing dropdown * Use transform for drop-down positioning * Add basic DropDownDiv hide * Add animation-in to dropdown * More subtle drop-down animation and shadow * Add icon menu example * Use options style of Blockly FieldImage for drop-down * Add default value for iconmenu * Add example hover, active states for iconmenu buttons * Update dropdown_icon example * Implement icon-menu value handling and default value * Add updating the parent block image field to dropdown * Drop-down animates out; add hooks to hide for various Blockly happenings * Add pointer cursor for drop-down icons * Improve documentation for drop-downs and minor refactor * Factor out getSrcForValue in iconmenu * Blocks take on the icon of their icon-menu * Add basic accessibility properties, similar to closure * Remove extra drop-down example; update playgrounds * Remove unnecessary colour overrides * Add onHide, colour changing, fix references in dropdowndiv * Flip arrow when the drop-down is rendered above * Hide the icon menu drop-down on second tap of button * Add preventDefault to button ontouchstart * Updates to drop-down from Carl * Add icon-menu placeholders and a crazy demo * Fix naming to normalize (drop-down, DropDown) * Add license header
2016-04-21 15:33:28 -04:00
Blockly.DropDownDiv.hideWithoutAnimation();
this.setHandlePosition(this.constrainHandle_(handlePosition));
this.onScroll_();
e.stopPropagation();
e.preventDefault();
};
/**
* Start a dragging operation.
2016-05-27 10:25:19 -07:00
* Called when scrollbar handle is clicked.
* @param {!Event} e Mouse down event.
* @private
*/
2016-05-27 10:25:19 -07:00
Blockly.Scrollbar.prototype.onMouseDownHandle_ = function(e) {
this.workspace_.markFocused();
this.cleanUp_();
if (Blockly.utils.isRightButton(e)) {
// Right-click.
// Scrollbars have no context menu.
e.stopPropagation();
return;
}
// Look up the current translation and record it.
2016-05-27 10:25:19 -07:00
this.startDragHandle = this.handlePosition_;
// Tell the workspace to setup its drag surface since it is about to move.
// onMouseMoveHandle will call onScroll which actually tells the workspace
// to move.
this.workspace_.setupDragSurface();
// Record the current mouse position.
this.startDragMouse_ = this.horizontal_ ? e.clientX : e.clientY;
Blockly.Scrollbar.onMouseUpWrapper_ = Blockly.bindEventWithChecks_(document,
2016-05-27 10:25:19 -07:00
'mouseup', this, this.onMouseUpHandle_);
Blockly.Scrollbar.onMouseMoveWrapper_ = Blockly.bindEventWithChecks_(document,
2016-05-27 10:25:19 -07:00
'mousemove', this, this.onMouseMoveHandle_);
// When the scrollbars are clicked, hide the WidgetDiv/DropDownDiv without
// animation in anticipation of a workspace move.
Blockly.WidgetDiv.hide(true);
Implement drop-down menus and icon picker field (#233) * Icon menu and drop-down stubs * Recompile 4/15 * Fix stubs to draw shadow block for drop-down * Fix rendering of shadow for icon menu * Add arrow to dropdown button * Add drop-down buttons to rest of examples * Implementation of drop-down div including positioning * Drop-downs take colours from the blocks * Fix scaled secondary position of drop-downs * Fix arrow positioning for RTL * Use SVG parentNode for sizing dropdown * Use transform for drop-down positioning * Add basic DropDownDiv hide * Add animation-in to dropdown * More subtle drop-down animation and shadow * Add icon menu example * Use options style of Blockly FieldImage for drop-down * Add default value for iconmenu * Add example hover, active states for iconmenu buttons * Update dropdown_icon example * Implement icon-menu value handling and default value * Add updating the parent block image field to dropdown * Drop-down animates out; add hooks to hide for various Blockly happenings * Add pointer cursor for drop-down icons * Improve documentation for drop-downs and minor refactor * Factor out getSrcForValue in iconmenu * Blocks take on the icon of their icon-menu * Add basic accessibility properties, similar to closure * Remove extra drop-down example; update playgrounds * Remove unnecessary colour overrides * Add onHide, colour changing, fix references in dropdowndiv * Flip arrow when the drop-down is rendered above * Hide the icon menu drop-down on second tap of button * Add preventDefault to button ontouchstart * Updates to drop-down from Carl * Add icon-menu placeholders and a crazy demo * Fix naming to normalize (drop-down, DropDown) * Add license header
2016-04-21 15:33:28 -04:00
Blockly.DropDownDiv.hideWithoutAnimation();
e.stopPropagation();
e.preventDefault();
};
/**
2016-05-27 10:25:19 -07:00
* Drag the scrollbar's handle.
* @param {!Event} e Mouse up event.
* @private
*/
2016-05-27 10:25:19 -07:00
Blockly.Scrollbar.prototype.onMouseMoveHandle_ = function(e) {
var currentMouse = this.horizontal_ ? e.clientX : e.clientY;
var mouseDelta = currentMouse - this.startDragMouse_;
2016-05-27 10:25:19 -07:00
var handlePosition = this.startDragHandle + mouseDelta;
// Position the bar.
2016-05-27 10:25:19 -07:00
this.setHandlePosition(this.constrainHandle_(handlePosition));
this.onScroll_();
};
/**
* Release the scrollbar handle and reset state accordingly.
* @private
*/
2016-05-27 10:25:19 -07:00
Blockly.Scrollbar.prototype.onMouseUpHandle_ = function() {
// Tell the workspace to clean up now that the workspace is done moving.
this.workspace_.resetDragSurface();
2016-09-07 17:42:09 -07:00
Blockly.Touch.clearTouchIdentifier();
this.cleanUp_();
};
/**
* Hide chaff and stop binding to mouseup and mousemove events. Call this to
* wrap up lose ends associated with the scrollbar.
* @private
*/
Blockly.Scrollbar.prototype.cleanUp_ = function() {
2014-09-08 14:26:52 -07:00
Blockly.hideChaff(true);
if (Blockly.Scrollbar.onMouseUpWrapper_) {
Blockly.unbindEvent_(Blockly.Scrollbar.onMouseUpWrapper_);
Blockly.Scrollbar.onMouseUpWrapper_ = null;
}
2014-09-08 14:26:52 -07:00
if (Blockly.Scrollbar.onMouseMoveWrapper_) {
Blockly.unbindEvent_(Blockly.Scrollbar.onMouseMoveWrapper_);
Blockly.Scrollbar.onMouseMoveWrapper_ = null;
}
};
/**
* Constrain the handle's position within the minimum (0) and maximum
* (length of scrollbar) values allowed for the scrollbar.
* @param {number} value Value that is potentially out of bounds, in CSS pixels.
* @return {number} Constrained value, in CSS pixels.
* @private
*/
Blockly.Scrollbar.prototype.constrainHandle_ = function(value) {
if (value <= 0 || isNaN(value) || this.scrollViewSize_ < this.handleLength_) {
value = 0;
} else {
value = Math.min(value, this.scrollViewSize_ - this.handleLength_);
}
return value;
};
/**
* Called when scrollbar is moved.
* @private
*/
2014-09-08 14:26:52 -07:00
Blockly.Scrollbar.prototype.onScroll_ = function() {
var ratio = this.handlePosition_ / this.scrollViewSize_;
if (isNaN(ratio)) {
ratio = 0;
}
var xyRatio = {};
if (this.horizontal_) {
xyRatio.x = ratio;
} else {
xyRatio.y = ratio;
}
this.workspace_.setMetrics(xyRatio);
};
/**
* Set the scrollbar handle's position.
* @param {number} value The distance from the top/left end of the bar, in CSS
* pixels. It may be larger than the maximum allowable position of the
* scrollbar handle.
*/
2014-09-08 14:26:52 -07:00
Blockly.Scrollbar.prototype.set = function(value) {
this.setHandlePosition(this.constrainHandle_(value * this.ratio_));
2014-09-08 14:26:52 -07:00
this.onScroll_();
};
/**
* Record the origin of the workspace that the scrollbar is in, in pixels
* relative to the injection div origin. This is for times when the scrollbar is
* used in an object whose origin isn't the same as the main workspace
* (e.g. in a flyout.)
* @param {number} x The x coordinate of the scrollbar's origin, in CSS pixels.
* @param {number} y The y coordinate of the scrollbar's origin, in CSS pixels.
*/
Blockly.Scrollbar.prototype.setOrigin = function(x, y) {
if (x != this.origin_.x || y != this.origin_.y) {
this.origin_ = new goog.math.Coordinate(x, y);
this.originHasChanged_ = true;
}
};