2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2014-01-28 03:00:09 -08:00
|
|
|
* @license
|
2013-10-30 14:46:03 -07:00
|
|
|
* Visual Blocks Editor
|
|
|
|
*
|
|
|
|
* Copyright 2011 Google Inc.
|
2014-10-07 13:09:55 -07:00
|
|
|
* https://developers.google.com/blockly/
|
2013-10-30 14:46:03 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-06-22 10:38:20 -04:00
|
|
|
* @fileoverview Flyout tray containing blocks which may be created.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @author fraser@google.com (Neil Fraser)
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
goog.provide('Blockly.Flyout');
|
|
|
|
|
|
|
|
goog.require('Blockly.Block');
|
|
|
|
goog.require('Blockly.Comment');
|
2016-04-20 16:44:13 -07:00
|
|
|
goog.require('Blockly.Events');
|
2018-05-09 13:34:21 -07:00
|
|
|
goog.require('Blockly.Events.BlockCreate');
|
|
|
|
goog.require('Blockly.Events.VarCreate');
|
2016-06-21 13:42:03 -07:00
|
|
|
goog.require('Blockly.FlyoutButton');
|
2018-06-25 13:16:42 -04:00
|
|
|
goog.require('Blockly.FlyoutExtensionCategoryHeader');
|
2017-05-22 13:08:22 -07:00
|
|
|
goog.require('Blockly.Gesture');
|
2018-08-16 17:02:55 -07:00
|
|
|
goog.require('Blockly.scratchBlocksUtils');
|
2016-10-04 14:40:10 -07:00
|
|
|
goog.require('Blockly.Touch');
|
2014-12-23 11:22:02 -08:00
|
|
|
goog.require('Blockly.WorkspaceSvg');
|
2015-02-06 15:27:25 -08:00
|
|
|
goog.require('goog.dom');
|
|
|
|
goog.require('goog.events');
|
2014-11-28 21:43:39 -08:00
|
|
|
goog.require('goog.math.Rect');
|
2015-01-22 15:58:10 -08:00
|
|
|
goog.require('goog.userAgent');
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for a flyout.
|
2015-04-28 13:51:25 -07:00
|
|
|
* @param {!Object} workspaceOptions Dictionary of options for the workspace.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @constructor
|
|
|
|
*/
|
2015-04-28 13:51:25 -07:00
|
|
|
Blockly.Flyout = function(workspaceOptions) {
|
2016-01-08 13:03:22 -08:00
|
|
|
workspaceOptions.getMetrics = this.getMetrics_.bind(this);
|
|
|
|
workspaceOptions.setMetrics = this.setMetrics_.bind(this);
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {!Blockly.Workspace}
|
2018-04-30 15:42:02 -07:00
|
|
|
* @protected
|
2013-10-30 14:46:03 -07:00
|
|
|
*/
|
2015-04-28 13:51:25 -07:00
|
|
|
this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions);
|
2013-10-30 14:46:03 -07:00
|
|
|
this.workspace_.isFlyout = true;
|
|
|
|
|
2018-04-13 11:22:44 -04:00
|
|
|
// When we create blocks for this workspace, instead of using the "optional" id
|
|
|
|
// make the default `id` the same as the `type` for easier re-use.
|
|
|
|
var newBlock = this.workspace_.newBlock;
|
|
|
|
this.workspace_.newBlock = function(type, id) {
|
|
|
|
// Use `type` if `id` isn't passed. `this` will be workspace.
|
|
|
|
return newBlock.call(this, type, id || type);
|
|
|
|
};
|
|
|
|
|
2015-04-28 13:51:25 -07:00
|
|
|
/**
|
|
|
|
* Is RTL vs LTR.
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.RTL = !!workspaceOptions.RTL;
|
|
|
|
|
2016-02-08 13:56:57 -08:00
|
|
|
/**
|
|
|
|
* Flyout should be laid out horizontally vs vertically.
|
|
|
|
* @type {boolean}
|
2016-04-08 15:34:08 -07:00
|
|
|
* @private
|
2016-02-08 13:56:57 -08:00
|
|
|
*/
|
2016-02-11 14:46:51 -08:00
|
|
|
this.horizontalLayout_ = workspaceOptions.horizontalLayout;
|
2016-02-08 13:56:57 -08:00
|
|
|
|
2016-02-12 14:48:13 -08:00
|
|
|
/**
|
2016-02-17 16:19:40 -08:00
|
|
|
* Position of the toolbox and flyout relative to the workspace.
|
|
|
|
* @type {number}
|
2018-04-26 14:28:59 -07:00
|
|
|
* @protected
|
2016-02-12 14:48:13 -08:00
|
|
|
*/
|
2016-03-17 15:46:22 -07:00
|
|
|
this.toolboxPosition_ = workspaceOptions.toolboxPosition;
|
2016-02-12 10:57:33 -08:00
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2015-08-20 15:46:44 -07:00
|
|
|
* Opaque data that can be passed to Blockly.unbindEvent_.
|
2015-09-12 19:31:22 -07:00
|
|
|
* @type {!Array.<!Array>}
|
2013-10-30 14:46:03 -07:00
|
|
|
* @private
|
|
|
|
*/
|
2014-09-08 14:26:52 -07:00
|
|
|
this.eventWrappers_ = [];
|
2013-10-30 14:46:03 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of background buttons that lurk behind each block to catch clicks
|
|
|
|
* landing in the blocks' lakes and bays.
|
|
|
|
* @type {!Array.<!Element>}
|
|
|
|
* @private
|
|
|
|
*/
|
2016-06-21 13:42:03 -07:00
|
|
|
this.backgroundButtons_ = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of visible buttons.
|
2016-09-08 13:45:47 -07:00
|
|
|
* @type {!Array.<!Blockly.FlyoutButton>}
|
2018-04-26 14:28:59 -07:00
|
|
|
* @protected
|
2016-06-21 13:42:03 -07:00
|
|
|
*/
|
2013-10-30 14:46:03 -07:00
|
|
|
this.buttons_ = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of event listeners.
|
|
|
|
* @type {!Array.<!Array>}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.listeners_ = [];
|
2016-02-02 19:53:52 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List of blocks that should always be disabled.
|
|
|
|
* @type {!Array.<!Blockly.Block>}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.permanentlyDisabled_ = [];
|
2016-07-19 11:00:37 +02:00
|
|
|
|
2016-09-08 16:54:10 -07:00
|
|
|
/**
|
|
|
|
* The toolbox that this flyout belongs to, or none if tihs is a simple
|
|
|
|
* workspace.
|
2016-11-01 18:00:26 -07:00
|
|
|
* @type {Blockly.Toolbox}
|
|
|
|
* @private
|
2016-09-08 16:54:10 -07:00
|
|
|
*/
|
|
|
|
this.parentToolbox_ = null;
|
2017-09-21 11:54:42 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The target position for the flyout scroll animation in pixels.
|
|
|
|
* Is a number while animating, null otherwise.
|
|
|
|
* @type {?number}
|
|
|
|
* @package
|
|
|
|
*/
|
|
|
|
this.scrollTarget = null;
|
2018-04-13 11:22:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A recycle bin for blocks.
|
|
|
|
* @type {!Array.<!Blockly.Block>}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this.recycleBlocks_ = [];
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the flyout automatically close when a block is created?
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2017-09-01 16:18:16 -04:00
|
|
|
Blockly.Flyout.prototype.autoClose = false;
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2017-02-02 14:17:43 -05:00
|
|
|
/**
|
|
|
|
* Whether the flyout is visible.
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.isVisible_ = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the workspace containing this flyout is visible.
|
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.containerVisible_ = true;
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Corner radius of the flyout background.
|
|
|
|
* @type {number}
|
|
|
|
* @const
|
|
|
|
*/
|
2016-04-14 17:58:39 -04:00
|
|
|
Blockly.Flyout.prototype.CORNER_RADIUS = 0;
|
|
|
|
|
|
|
|
/**
|
2016-04-18 17:29:48 -07:00
|
|
|
* Margin around the edges of the blocks in the flyout.
|
2016-04-14 17:58:39 -04:00
|
|
|
* @type {number}
|
|
|
|
* @const
|
|
|
|
*/
|
2017-03-09 16:56:55 -05:00
|
|
|
Blockly.Flyout.prototype.MARGIN = 12;
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2017-08-03 12:05:17 -07:00
|
|
|
// TODO: Move GAP_X and GAP_Y to their appropriate files.
|
|
|
|
|
2016-09-08 13:45:47 -07:00
|
|
|
/**
|
|
|
|
* Gap between items in horizontal flyouts. Can be overridden with the "sep"
|
|
|
|
* element.
|
|
|
|
* @const {number}
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.GAP_X = Blockly.Flyout.prototype.MARGIN * 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gap between items in vertical flyouts. Can be overridden with the "sep"
|
|
|
|
* element.
|
|
|
|
* @const {number}
|
|
|
|
*/
|
2017-03-09 16:56:55 -05:00
|
|
|
Blockly.Flyout.prototype.GAP_Y = Blockly.Flyout.prototype.MARGIN;
|
2016-09-08 13:45:47 -07:00
|
|
|
|
2015-08-19 17:21:05 -07:00
|
|
|
/**
|
|
|
|
* Top/bottom padding between scrollbar and edge of flyout background.
|
|
|
|
* @type {number}
|
|
|
|
* @const
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.SCROLLBAR_PADDING = 2;
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2015-09-12 19:31:22 -07:00
|
|
|
/**
|
|
|
|
* Width of flyout.
|
|
|
|
* @type {number}
|
2018-04-26 14:28:59 -07:00
|
|
|
* @protected
|
2015-09-12 19:31:22 -07:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.width_ = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Height of flyout.
|
|
|
|
* @type {number}
|
2018-04-26 14:28:59 -07:00
|
|
|
* @protected
|
2015-09-12 19:31:22 -07:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.height_ = 0;
|
|
|
|
|
2016-04-12 15:50:07 +02:00
|
|
|
/**
|
|
|
|
* Width of flyout contents.
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.contentWidth_ = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Height of flyout contents.
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.contentHeight_ = 0;
|
|
|
|
|
2016-01-26 12:35:50 -08:00
|
|
|
/**
|
|
|
|
* Vertical offset of flyout.
|
|
|
|
* @type {number}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.verticalOffset_ = 0;
|
|
|
|
|
2016-04-11 14:21:55 -04:00
|
|
|
/**
|
2016-06-29 12:26:11 +02:00
|
|
|
* Range of a drag angle from a flyout considered "dragging toward workspace".
|
2016-04-11 14:21:55 -04:00
|
|
|
* Drags that are within the bounds of this many degrees from the orthogonal
|
2016-06-29 12:26:11 +02:00
|
|
|
* line to the flyout edge are considered to be "drags toward the workspace".
|
2016-04-11 14:21:55 -04:00
|
|
|
* Example:
|
|
|
|
* Flyout Edge Workspace
|
|
|
|
* [block] / <-within this angle, drags "toward workspace" |
|
|
|
|
* [block] ---- orthogonal to flyout boundary ---- |
|
|
|
|
* [block] \ |
|
|
|
|
* The angle is given in degrees from the orthogonal.
|
2016-06-29 12:26:11 +02:00
|
|
|
*
|
|
|
|
* This is used to know when to create a new block and when to scroll the
|
|
|
|
* flyout. Setting it to 360 means that all drags create a new block.
|
2016-04-11 14:21:55 -04:00
|
|
|
* @type {number}
|
2018-04-26 14:28:59 -07:00
|
|
|
* @protected
|
2016-04-11 14:21:55 -04:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.dragAngleRange_ = 70;
|
|
|
|
|
2017-09-18 15:21:41 -04:00
|
|
|
/**
|
|
|
|
* The fraction of the distance to the scroll target to move the flyout on
|
|
|
|
* each animation frame, when auto-scrolling. Values closer to 1.0 will make
|
|
|
|
* the scroll animation complete faster. Use 1.0 for no animation.
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.scrollAnimationFraction = 0.3;
|
|
|
|
|
2018-06-08 17:56:47 -04:00
|
|
|
/**
|
2018-06-12 12:36:04 -04:00
|
|
|
* Whether to recycle blocks when refreshing the flyout. When false, do not allow
|
|
|
|
* anything to be recycled. The default is to recycle.
|
2018-06-08 17:56:47 -04:00
|
|
|
* @type {boolean}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.recyclingEnabled_ = true;
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
2017-02-02 14:17:43 -05:00
|
|
|
* Creates the flyout's DOM. Only needs to be called once. The flyout can
|
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
|
|
|
* either exist as its own svg element or be a g element nested inside a
|
|
|
|
* separate svg element.
|
2017-02-02 14:17:43 -05:00
|
|
|
* @param {string} tagName The type of tag to put the flyout in. This
|
|
|
|
* should be <svg> or <g>.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @return {!Element} The flyout's SVG group.
|
|
|
|
*/
|
2017-02-02 14:17:43 -05:00
|
|
|
Blockly.Flyout.prototype.createDom = function(tagName) {
|
2013-10-30 14:46:03 -07:00
|
|
|
/*
|
2017-02-02 14:17:43 -05:00
|
|
|
<svg | g>
|
2013-10-30 14:46:03 -07:00
|
|
|
<path class="blocklyFlyoutBackground"/>
|
2015-07-14 23:13:09 -07:00
|
|
|
<g class="blocklyFlyout"></g>
|
2017-02-02 14:17:43 -05:00
|
|
|
</ svg | g>
|
2013-10-30 14:46:03 -07:00
|
|
|
*/
|
2017-02-02 14:17:43 -05:00
|
|
|
// Setting style to display:none to start. The toolbox and flyout
|
|
|
|
// hide/show code will set up proper visibility and size later.
|
|
|
|
this.svgGroup_ = Blockly.utils.createSvgElement(tagName,
|
2018-04-26 14:28:59 -07:00
|
|
|
{'class': 'blocklyFlyout', 'style': 'display: none'}, null);
|
2017-02-02 14:17:43 -05:00
|
|
|
this.svgBackground_ = Blockly.utils.createSvgElement('path',
|
2013-10-30 14:46:03 -07:00
|
|
|
{'class': 'blocklyFlyoutBackground'}, this.svgGroup_);
|
|
|
|
this.svgGroup_.appendChild(this.workspace_.createDom());
|
|
|
|
return this.svgGroup_;
|
|
|
|
};
|
|
|
|
|
2015-04-28 13:51:25 -07:00
|
|
|
/**
|
|
|
|
* Initializes the flyout.
|
2015-08-19 17:21:05 -07:00
|
|
|
* @param {!Blockly.Workspace} targetWorkspace The workspace in which to create
|
|
|
|
* new blocks.
|
2015-04-28 13:51:25 -07:00
|
|
|
*/
|
2015-08-19 17:21:05 -07:00
|
|
|
Blockly.Flyout.prototype.init = function(targetWorkspace) {
|
|
|
|
this.targetWorkspace_ = targetWorkspace;
|
|
|
|
this.workspace_.targetWorkspace = targetWorkspace;
|
2015-04-28 13:51:25 -07:00
|
|
|
// Add scrollbar.
|
2016-03-17 15:46:22 -07:00
|
|
|
this.scrollbar_ = new Blockly.Scrollbar(this.workspace_,
|
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.horizontalLayout_, false, 'blocklyFlyoutScrollbar');
|
2015-04-28 13:51:25 -07:00
|
|
|
|
2016-10-06 14:49:15 -07:00
|
|
|
this.position();
|
2015-04-28 13:51:25 -07:00
|
|
|
|
2015-08-20 15:46:44 -07:00
|
|
|
Array.prototype.push.apply(this.eventWrappers_,
|
2017-05-22 13:08:22 -07:00
|
|
|
Blockly.bindEventWithChecks_(this.svgGroup_, 'wheel', this, this.wheel_));
|
2016-02-08 13:56:57 -08:00
|
|
|
// Dragging the flyout up and down (or left and right).
|
2015-08-20 15:46:44 -07:00
|
|
|
Array.prototype.push.apply(this.eventWrappers_,
|
2018-04-26 14:28:59 -07:00
|
|
|
Blockly.bindEventWithChecks_(
|
2018-04-30 13:20:39 -07:00
|
|
|
this.svgGroup_, 'mousedown', this, this.onMouseDown_));
|
2017-05-22 13:08:22 -07:00
|
|
|
|
|
|
|
// A flyout connected to a workspace doesn't have its own current gesture.
|
|
|
|
this.workspace_.getGesture =
|
|
|
|
this.targetWorkspace_.getGesture.bind(this.targetWorkspace_);
|
2017-06-22 10:38:20 -04:00
|
|
|
|
|
|
|
// Get variables from the main workspace rather than the target workspace.
|
2017-12-19 14:46:53 -05:00
|
|
|
this.workspace_.variableMap_ = this.targetWorkspace_.getVariableMap();
|
2018-01-12 12:03:28 -08:00
|
|
|
|
|
|
|
this.workspace_.createPotentialVariableMap();
|
2015-04-28 13:51:25 -07:00
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Dispose of this flyout.
|
|
|
|
* Unlink from all DOM elements to prevent memory leaks.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.dispose = function() {
|
|
|
|
this.hide();
|
2014-09-08 14:26:52 -07:00
|
|
|
Blockly.unbindEvent_(this.eventWrappers_);
|
2013-10-30 14:46:03 -07:00
|
|
|
if (this.scrollbar_) {
|
|
|
|
this.scrollbar_.dispose();
|
|
|
|
this.scrollbar_ = null;
|
|
|
|
}
|
2015-08-20 15:46:44 -07:00
|
|
|
if (this.workspace_) {
|
|
|
|
this.workspace_.targetWorkspace = null;
|
|
|
|
this.workspace_.dispose();
|
|
|
|
this.workspace_ = null;
|
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
if (this.svgGroup_) {
|
|
|
|
goog.dom.removeNode(this.svgGroup_);
|
|
|
|
this.svgGroup_ = null;
|
|
|
|
}
|
2016-10-06 14:49:15 -07:00
|
|
|
this.parentToolbox_ = null;
|
2013-10-30 14:46:03 -07:00
|
|
|
this.svgBackground_ = null;
|
|
|
|
this.targetWorkspace_ = null;
|
|
|
|
};
|
|
|
|
|
2016-09-08 16:54:10 -07:00
|
|
|
/**
|
2016-10-07 10:15:41 -07:00
|
|
|
* Set the parent toolbox of this flyout.
|
|
|
|
* @param {!Blockly.Toolbox} toolbox The toolbox that owns this flyout.
|
2016-09-08 16:54:10 -07:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.setParentToolbox = function(toolbox) {
|
|
|
|
this.parentToolbox_ = toolbox;
|
|
|
|
};
|
|
|
|
|
2016-04-13 15:30:11 -07:00
|
|
|
/**
|
|
|
|
* Get the width of the flyout.
|
2016-05-13 15:30:47 -07:00
|
|
|
* @return {number} The width of the flyout.
|
2016-04-13 15:30:11 -07:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.getWidth = function() {
|
2017-07-11 10:50:08 -04:00
|
|
|
return this.DEFAULT_WIDTH;
|
2016-04-13 15:30:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the height of the flyout.
|
2016-05-13 15:30:47 -07:00
|
|
|
* @return {number} The width of the flyout.
|
2016-04-13 15:30:11 -07:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.getHeight = function() {
|
|
|
|
return this.height_;
|
|
|
|
};
|
|
|
|
|
2016-06-23 18:17:36 -04:00
|
|
|
/**
|
2018-04-30 15:42:02 -07:00
|
|
|
* Get the workspace inside the flyout.
|
2017-05-22 13:08:22 -07:00
|
|
|
* @return {!Blockly.WorkspaceSvg} The workspace inside the flyout.
|
|
|
|
* @package
|
2016-06-23 18:17:36 -04:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.getWorkspace = function() {
|
|
|
|
return this.workspace_;
|
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Is the flyout visible?
|
|
|
|
* @return {boolean} True if visible.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.isVisible = function() {
|
2017-02-02 14:17:43 -05:00
|
|
|
return this.isVisible_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether the flyout is visible. A value of true does not necessarily mean
|
|
|
|
* that the flyout is shown. It could be hidden because its container is hidden.
|
|
|
|
* @param {boolean} visible True if visible.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.setVisible = function(visible) {
|
|
|
|
var visibilityChanged = (visible != this.isVisible());
|
|
|
|
|
|
|
|
this.isVisible_ = visible;
|
|
|
|
if (visibilityChanged) {
|
|
|
|
this.updateDisplay_();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether this flyout's container is visible.
|
|
|
|
* @param {boolean} visible Whether the container is visible.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.setContainerVisible = function(visible) {
|
|
|
|
var visibilityChanged = (visible != this.containerVisible_);
|
|
|
|
this.containerVisible_ = visible;
|
|
|
|
if (visibilityChanged) {
|
|
|
|
this.updateDisplay_();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the display property of the flyout based whether it thinks it should
|
|
|
|
* be visible and whether its containing workspace is visible.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.updateDisplay_ = function() {
|
|
|
|
var show = true;
|
|
|
|
if (!this.containerVisible_) {
|
|
|
|
show = false;
|
|
|
|
} else {
|
|
|
|
show = this.isVisible();
|
|
|
|
}
|
|
|
|
this.svgGroup_.style.display = show ? 'block' : 'none';
|
|
|
|
// Update the scrollbar's visiblity too since it should mimic the
|
|
|
|
// flyout's visibility.
|
|
|
|
this.scrollbar_.setContainerVisible(show);
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide and empty the flyout.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.hide = function() {
|
|
|
|
if (!this.isVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-02 14:17:43 -05:00
|
|
|
this.setVisible(false);
|
2013-10-30 14:46:03 -07:00
|
|
|
// Delete all the event listeners.
|
|
|
|
for (var x = 0, listen; listen = this.listeners_[x]; x++) {
|
|
|
|
Blockly.unbindEvent_(listen);
|
|
|
|
}
|
2014-09-08 14:26:52 -07:00
|
|
|
this.listeners_.length = 0;
|
2013-10-30 14:46:03 -07:00
|
|
|
if (this.reflowWrapper_) {
|
2016-02-11 21:40:33 -08:00
|
|
|
this.workspace_.removeChangeListener(this.reflowWrapper_);
|
2013-10-30 14:46:03 -07:00
|
|
|
this.reflowWrapper_ = null;
|
|
|
|
}
|
2014-09-08 14:26:52 -07:00
|
|
|
// Do NOT delete the blocks here. Wait until Flyout.show.
|
|
|
|
// https://neil.fraser.name/news/2014/08/09/
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show and populate the flyout.
|
|
|
|
* @param {!Array|string} xmlList List of blocks to show.
|
|
|
|
* Variables and procedures have a custom set of blocks.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.show = function(xmlList) {
|
2017-10-20 17:53:14 -07:00
|
|
|
this.workspace_.setResizesEnabled(false);
|
2014-09-08 14:26:52 -07:00
|
|
|
this.hide();
|
2016-04-20 14:14:53 -07:00
|
|
|
this.clearOldBlocks_();
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2017-02-02 14:17:43 -05:00
|
|
|
this.setVisible(true);
|
2013-10-30 14:46:03 -07:00
|
|
|
// Create the blocks to be shown in this flyout.
|
2016-07-01 13:36:20 -07:00
|
|
|
var contents = [];
|
2013-10-30 14:46:03 -07:00
|
|
|
var gaps = [];
|
2016-02-02 19:53:52 -08:00
|
|
|
this.permanentlyDisabled_.length = 0;
|
2015-10-25 22:20:08 -04:00
|
|
|
for (var i = 0, xml; xml = xmlList[i]; i++) {
|
2017-09-13 13:46:34 -04:00
|
|
|
// Handle dynamic categories, represented by a name instead of a list of XML.
|
2017-08-23 18:30:28 -04:00
|
|
|
// Look up the correct category generation function and call that to get a
|
|
|
|
// valid XML list.
|
2017-09-21 11:54:42 -04:00
|
|
|
if (typeof xml === 'string') {
|
2017-08-23 18:30:28 -04:00
|
|
|
var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback(
|
|
|
|
xmlList[i]);
|
|
|
|
var newList = fnToApply(this.workspace_.targetWorkspace);
|
2017-09-13 13:46:34 -04:00
|
|
|
// Insert the new list of blocks in the middle of the list.
|
|
|
|
// We use splice to insert at index i, and remove a single element
|
2017-09-13 13:50:45 -04:00
|
|
|
// (the placeholder string). Because the spread operator (...) is not
|
|
|
|
// available, use apply and concat the array.
|
2017-08-23 18:30:28 -04:00
|
|
|
xmlList.splice.apply(xmlList, [i, 1].concat(newList));
|
|
|
|
xml = xmlList[i];
|
|
|
|
}
|
2016-06-21 13:42:03 -07:00
|
|
|
if (xml.tagName) {
|
|
|
|
var tagName = xml.tagName.toUpperCase();
|
2016-09-08 13:45:47 -07:00
|
|
|
var default_gap = this.horizontalLayout_ ? this.GAP_X : this.GAP_Y;
|
2016-06-21 13:42:03 -07:00
|
|
|
if (tagName == 'BLOCK') {
|
2018-04-13 11:22:44 -04:00
|
|
|
|
|
|
|
// We assume that in a flyout, the same block id (or type if missing id) means
|
|
|
|
// the same output BlockSVG.
|
|
|
|
|
|
|
|
// Look for a block that matches the id or type, our createBlock will assign
|
|
|
|
// id = type if none existed.
|
|
|
|
var id = xml.getAttribute('id') || xml.getAttribute('type');
|
|
|
|
var recycled = this.recycleBlocks_.findIndex(function(block) {
|
|
|
|
return block.id === id;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// If we found a recycled item, reuse the BlockSVG from last time.
|
|
|
|
// Otherwise, convert the XML block to a BlockSVG.
|
|
|
|
var curBlock;
|
|
|
|
if (recycled > -1) {
|
|
|
|
curBlock = this.recycleBlocks_.splice(recycled, 1)[0];
|
|
|
|
} else {
|
|
|
|
curBlock = Blockly.Xml.domToBlock(xml, this.workspace_);
|
|
|
|
}
|
|
|
|
|
2016-06-21 13:42:03 -07:00
|
|
|
if (curBlock.disabled) {
|
|
|
|
// Record blocks that were initially disabled.
|
|
|
|
// Do not enable these blocks as a result of capacity filtering.
|
|
|
|
this.permanentlyDisabled_.push(curBlock);
|
|
|
|
}
|
2016-07-01 13:36:20 -07:00
|
|
|
contents.push({type: 'block', block: curBlock});
|
2016-06-21 13:42:03 -07:00
|
|
|
var gap = parseInt(xml.getAttribute('gap'), 10);
|
2016-09-08 13:45:47 -07:00
|
|
|
gaps.push(isNaN(gap) ? default_gap : gap);
|
2016-08-09 16:34:59 -07:00
|
|
|
} else if (xml.tagName.toUpperCase() == 'SEP') {
|
|
|
|
// Change the gap between two blocks.
|
|
|
|
// <sep gap="36"></sep>
|
|
|
|
// The default gap is 24, can be set larger or smaller.
|
2016-08-09 17:51:50 -07:00
|
|
|
// This overwrites the gap attribute on the previous block.
|
2016-08-09 16:34:59 -07:00
|
|
|
// Note that a deprecated method is to add a gap to a block.
|
|
|
|
// <block type="math_arithmetic" gap="8"></block>
|
|
|
|
var newGap = parseInt(xml.getAttribute('gap'), 10);
|
|
|
|
// Ignore gaps before the first block.
|
2016-08-09 17:51:50 -07:00
|
|
|
if (!isNaN(newGap) && gaps.length > 0) {
|
|
|
|
gaps[gaps.length - 1] = newGap;
|
2016-08-09 16:34:59 -07:00
|
|
|
} else {
|
2016-09-08 13:45:47 -07:00
|
|
|
gaps.push(default_gap);
|
2016-08-09 16:34:59 -07:00
|
|
|
}
|
2018-06-25 13:16:42 -04:00
|
|
|
} else if ((tagName == 'LABEL') && (xml.getAttribute('showStatusButton') == 'true')) {
|
|
|
|
var curButton = new Blockly.FlyoutExtensionCategoryHeader(this.workspace_,
|
|
|
|
this.targetWorkspace_, xml);
|
|
|
|
contents.push({type: 'button', button: curButton});
|
2018-07-10 16:47:27 -04:00
|
|
|
gaps.push(default_gap);
|
2016-11-01 18:00:26 -07:00
|
|
|
} else if (tagName == 'BUTTON' || tagName == 'LABEL') {
|
|
|
|
// Labels behave the same as buttons, but are styled differently.
|
|
|
|
var isLabel = tagName == 'LABEL';
|
2016-07-01 15:51:59 -07:00
|
|
|
var curButton = new Blockly.FlyoutButton(this.workspace_,
|
2017-02-02 14:17:43 -05:00
|
|
|
this.targetWorkspace_, xml, isLabel);
|
2016-07-01 13:42:17 -07:00
|
|
|
contents.push({type: 'button', button: curButton});
|
2016-09-08 13:45:47 -07:00
|
|
|
gaps.push(default_gap);
|
2016-02-02 19:53:52 -08:00
|
|
|
}
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 11:22:44 -04:00
|
|
|
this.emptyRecycleBlocks_();
|
|
|
|
|
2016-07-01 13:36:20 -07:00
|
|
|
this.layout_(contents, gaps);
|
2016-04-20 14:14:53 -07:00
|
|
|
|
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
|
|
|
// IE 11 is an incompetent browser that fails to fire mouseout events.
|
2016-04-20 14:14:53 -07:00
|
|
|
// When the mouse is over the background, deselect all blocks.
|
2016-05-25 12:53:42 -07:00
|
|
|
var deselectAll = function() {
|
2016-05-14 03:50:35 -07:00
|
|
|
var topBlocks = this.workspace_.getTopBlocks(false);
|
|
|
|
for (var i = 0, block; block = topBlocks[i]; i++) {
|
2016-04-20 14:14:53 -07:00
|
|
|
block.removeSelect();
|
|
|
|
}
|
|
|
|
};
|
2016-05-25 12:53:42 -07:00
|
|
|
|
2016-04-20 14:14:53 -07:00
|
|
|
this.listeners_.push(Blockly.bindEvent_(this.svgBackground_, 'mouseover',
|
|
|
|
this, deselectAll));
|
2013-10-30 14:46:03 -07:00
|
|
|
|
2017-10-20 17:53:14 -07:00
|
|
|
this.workspace_.setResizesEnabled(true);
|
2016-04-20 14:14:53 -07:00
|
|
|
this.reflow();
|
|
|
|
|
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
|
|
|
// Correctly position the flyout's scrollbar when it opens.
|
|
|
|
this.position();
|
|
|
|
|
2016-04-20 14:14:53 -07:00
|
|
|
this.reflowWrapper_ = this.reflow.bind(this);
|
|
|
|
this.workspace_.addChangeListener(this.reflowWrapper_);
|
2017-08-23 17:15:27 -04:00
|
|
|
|
2017-09-13 15:19:50 -04:00
|
|
|
this.recordCategoryScrollPositions_();
|
|
|
|
};
|
|
|
|
|
2018-04-13 11:22:44 -04:00
|
|
|
/**
|
|
|
|
* Empty out the recycled blocks, properly destroying everything.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.emptyRecycleBlocks_ = function() {
|
|
|
|
// Clean out the old recycle bin.
|
|
|
|
var oldBlocks = this.recycleBlocks_;
|
|
|
|
this.recycleBlocks_ = [];
|
|
|
|
for (var i = 0; i < oldBlocks.length; i++) {
|
|
|
|
oldBlocks[i].dispose(false, false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-13 15:19:50 -04:00
|
|
|
/**
|
2018-05-10 15:15:44 -04:00
|
|
|
* Store an array of category names, ids, scrollbar positions, and category lengths.
|
2017-09-13 15:19:50 -04:00
|
|
|
* This is used when scrolling the flyout to cause a category to be selected.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.recordCategoryScrollPositions_ = function() {
|
2017-08-23 17:15:27 -04:00
|
|
|
this.categoryScrollPositions = [];
|
2018-05-10 15:15:44 -04:00
|
|
|
// Record category names and positions using the text label at the top of each one.
|
2017-09-13 15:28:38 -04:00
|
|
|
for (var i = 0; i < this.buttons_.length; i++) {
|
2017-09-21 10:25:21 -04:00
|
|
|
if (this.buttons_[i].getIsCategoryLabel()) {
|
2017-09-13 15:19:50 -04:00
|
|
|
var categoryLabel = this.buttons_[i];
|
2017-08-23 17:15:27 -04:00
|
|
|
this.categoryScrollPositions.push({
|
2017-09-21 10:25:21 -04:00
|
|
|
categoryName: categoryLabel.getText(),
|
2017-09-13 15:19:50 -04:00
|
|
|
position: this.horizontalLayout_ ?
|
2017-09-21 10:25:21 -04:00
|
|
|
categoryLabel.getPosition().x : categoryLabel.getPosition().y
|
2017-08-23 17:15:27 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-05-10 15:15:44 -04:00
|
|
|
// Record the length of each category, setting the final one to 0.
|
2018-04-27 09:53:38 -04:00
|
|
|
var numCategories = this.categoryScrollPositions.length;
|
2018-05-30 16:15:19 -04:00
|
|
|
if (numCategories > 0) {
|
|
|
|
for (var i = 0; i < numCategories - 1; i++) {
|
|
|
|
var currentPos = this.categoryScrollPositions[i].position;
|
2018-06-21 10:03:37 -04:00
|
|
|
var nextPos = this.categoryScrollPositions[i + 1].position;
|
2018-05-30 16:15:19 -04:00
|
|
|
var length = nextPos - currentPos;
|
|
|
|
this.categoryScrollPositions[i].length = length;
|
|
|
|
}
|
|
|
|
this.categoryScrollPositions[numCategories - 1].length = 0;
|
|
|
|
// Record the id of each category.
|
|
|
|
for (var i = 0; i < numCategories; i++) {
|
|
|
|
var category = this.parentToolbox_.getCategoryByIndex(i);
|
|
|
|
if (category && category.id_) {
|
|
|
|
this.categoryScrollPositions[i].categoryId = category.id_;
|
|
|
|
}
|
2018-05-10 15:15:44 -04:00
|
|
|
}
|
|
|
|
}
|
2016-04-20 14:14:53 -07:00
|
|
|
};
|
|
|
|
|
2017-09-18 16:40:55 -04:00
|
|
|
/**
|
|
|
|
* Select a category using the scroll position.
|
2017-09-21 11:54:42 -04:00
|
|
|
* @param {number} pos The scroll position in pixels.
|
2017-09-18 16:40:55 -04:00
|
|
|
* @package
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.selectCategoryByScrollPosition = function(pos) {
|
2017-10-04 13:59:00 -04:00
|
|
|
// If we are currently auto-scrolling, due to selecting a category by clicking on it,
|
|
|
|
// do not update the category selection.
|
|
|
|
if (this.scrollTarget) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-08 17:37:37 -05:00
|
|
|
var workspacePos = Math.round(pos / this.workspace_.scale);
|
2017-09-18 16:40:55 -04:00
|
|
|
// Traverse the array of scroll positions in reverse, so we can select the furthest
|
2017-09-21 11:54:42 -04:00
|
|
|
// category that the scroll position is beyond.
|
2017-09-18 16:40:55 -04:00
|
|
|
for (var i = this.categoryScrollPositions.length - 1; i >= 0; i--) {
|
2018-03-08 17:37:37 -05:00
|
|
|
if (workspacePos >= this.categoryScrollPositions[i].position) {
|
2018-05-10 15:15:44 -04:00
|
|
|
this.parentToolbox_.selectCategoryById(this.categoryScrollPositions[i].categoryId);
|
2017-09-18 16:40:55 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-18 14:55:40 -04:00
|
|
|
/**
|
|
|
|
* Step the scrolling animation by scrolling a fraction of the way to
|
|
|
|
* a scroll target, and request the next frame if necessary.
|
2017-09-18 15:07:59 -04:00
|
|
|
* @package
|
2017-09-18 14:55:40 -04:00
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.stepScrollAnimation = function() {
|
|
|
|
if (!this.scrollTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var scrollPos = this.horizontalLayout_ ?
|
|
|
|
-this.workspace_.scrollX : -this.workspace_.scrollY;
|
|
|
|
var diff = this.scrollTarget - scrollPos;
|
|
|
|
if (Math.abs(diff) < 1) {
|
|
|
|
this.scrollbar_.set(this.scrollTarget);
|
2017-10-04 13:59:00 -04:00
|
|
|
this.scrollTarget = null;
|
2017-09-18 14:55:40 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-09-18 15:21:41 -04:00
|
|
|
this.scrollbar_.set(scrollPos + diff * this.scrollAnimationFraction);
|
2017-09-18 14:55:40 -04:00
|
|
|
|
|
|
|
// Polyfilled by goog.dom.animationFrame.polyfill
|
|
|
|
requestAnimationFrame(this.stepScrollAnimation.bind(this));
|
|
|
|
};
|
|
|
|
|
2018-03-13 20:29:33 -04:00
|
|
|
/**
|
|
|
|
* Get the scaled scroll position.
|
|
|
|
* @return {number} The current scroll position.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.getScrollPos = function() {
|
2018-03-14 20:56:05 -04:00
|
|
|
var pos = this.horizontalLayout_ ?
|
|
|
|
-this.workspace_.scrollX : -this.workspace_.scrollY;
|
|
|
|
return pos / this.workspace_.scale;
|
2018-03-13 20:29:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scroll position, scaling it.
|
|
|
|
* @param {number} pos The scroll position to set.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.setScrollPos = function(pos) {
|
|
|
|
this.scrollbar_.set(pos * this.workspace_.scale);
|
|
|
|
};
|
|
|
|
|
2018-06-08 17:56:47 -04:00
|
|
|
/**
|
|
|
|
* Set whether the flyout can recycle blocks. A value of true allows blocks to be recycled.
|
|
|
|
* @param {boolean} recycle True if recycling is possible.
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.setRecyclingEnabled = function(recycle) {
|
|
|
|
this.recyclingEnabled_ = recycle;
|
|
|
|
};
|
|
|
|
|
2016-04-20 14:14:53 -07:00
|
|
|
/**
|
|
|
|
* Delete blocks and background buttons from a previous showing of the flyout.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.clearOldBlocks_ = function() {
|
|
|
|
// Delete any blocks from a previous showing.
|
2016-04-14 13:21:35 -07:00
|
|
|
var oldBlocks = this.workspace_.getTopBlocks(false);
|
|
|
|
for (var i = 0, block; block = oldBlocks[i]; i++) {
|
2016-04-20 14:14:53 -07:00
|
|
|
if (block.workspace == this.workspace_) {
|
2018-08-16 17:02:55 -07:00
|
|
|
if (this.recyclingEnabled_ &&
|
|
|
|
Blockly.scratchBlocksUtils.blockIsRecyclable(block)) {
|
2018-04-13 11:22:44 -04:00
|
|
|
this.recycleBlock_(block);
|
|
|
|
} else {
|
|
|
|
block.dispose(false, false);
|
|
|
|
}
|
2014-09-08 14:26:52 -07:00
|
|
|
}
|
2016-02-08 13:56:57 -08:00
|
|
|
}
|
2016-04-20 14:14:53 -07:00
|
|
|
// Delete any background buttons from a previous showing.
|
2017-09-05 10:26:58 -07:00
|
|
|
for (var j = 0; j < this.backgroundButtons_.length; j++) {
|
|
|
|
var rect = this.backgroundButtons_[j];
|
|
|
|
if (rect) goog.dom.removeNode(rect);
|
2016-04-20 14:14:53 -07:00
|
|
|
}
|
2016-06-21 13:42:03 -07:00
|
|
|
this.backgroundButtons_.length = 0;
|
|
|
|
|
|
|
|
for (var i = 0, button; button = this.buttons_[i]; i++) {
|
|
|
|
button.dispose();
|
|
|
|
}
|
2016-04-20 14:14:53 -07:00
|
|
|
this.buttons_.length = 0;
|
2017-12-19 14:46:53 -05:00
|
|
|
|
|
|
|
// Clear potential variables from the previous showing.
|
|
|
|
this.workspace_.getPotentialVariableMap().clear();
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-02-08 13:56:57 -08:00
|
|
|
* Add listeners to a block that has been added to the flyout.
|
2017-06-22 10:38:20 -04:00
|
|
|
* @param {!Element} root The root node of the SVG group the block is in.
|
2016-02-08 13:56:57 -08:00
|
|
|
* @param {!Blockly.Block} block The block to add listeners for.
|
|
|
|
* @param {!Element} rect The invisible rectangle under the block that acts as
|
|
|
|
* a button for that block.
|
|
|
|
* @private
|
2013-10-30 14:46:03 -07:00
|
|
|
*/
|
2016-02-08 13:56:57 -08:00
|
|
|
Blockly.Flyout.prototype.addBlockListeners_ = function(root, block, rect) {
|
2017-08-25 08:45:07 -04:00
|
|
|
this.listeners_.push(Blockly.bindEventWithChecks_(root, 'mousedown', null,
|
|
|
|
this.blockMouseDown_(block)));
|
|
|
|
this.listeners_.push(Blockly.bindEventWithChecks_(rect, 'mousedown', null,
|
|
|
|
this.blockMouseDown_(block)));
|
2016-04-20 14:14:53 -07:00
|
|
|
this.listeners_.push(Blockly.bindEvent_(root, 'mouseover', block,
|
|
|
|
block.addSelect));
|
|
|
|
this.listeners_.push(Blockly.bindEvent_(root, 'mouseout', block,
|
|
|
|
block.removeSelect));
|
|
|
|
this.listeners_.push(Blockly.bindEvent_(rect, 'mouseover', block,
|
|
|
|
block.addSelect));
|
|
|
|
this.listeners_.push(Blockly.bindEvent_(rect, 'mouseout', block,
|
|
|
|
block.removeSelect));
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a mouse-down on an SVG block in a non-closing flyout.
|
2014-09-08 14:26:52 -07:00
|
|
|
* @param {!Blockly.Block} block The flyout block to copy.
|
2013-10-30 14:46:03 -07:00
|
|
|
* @return {!Function} Function to call when block is clicked.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.blockMouseDown_ = function(block) {
|
|
|
|
var flyout = this;
|
|
|
|
return function(e) {
|
2017-05-22 13:08:22 -07:00
|
|
|
var gesture = flyout.targetWorkspace_.getGesture(e);
|
|
|
|
if (gesture) {
|
|
|
|
gesture.setStartBlock(block);
|
|
|
|
gesture.handleFlyoutStart(e, flyout);
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-09-08 14:26:52 -07:00
|
|
|
/**
|
2016-02-08 13:56:57 -08:00
|
|
|
* Mouse down on the flyout background. Start a scroll drag.
|
2014-09-08 14:26:52 -07:00
|
|
|
* @param {!Event} e Mouse down event.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.onMouseDown_ = function(e) {
|
2017-05-22 13:08:22 -07:00
|
|
|
var gesture = this.targetWorkspace_.getGesture(e);
|
|
|
|
if (gesture) {
|
|
|
|
gesture.handleFlyoutStart(e, this);
|
2016-04-23 12:59:38 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-30 14:46:03 -07:00
|
|
|
/**
|
|
|
|
* Create a copy of this block on the workspace.
|
2017-05-22 13:08:22 -07:00
|
|
|
* @param {!Blockly.BlockSvg} originalBlock The block to copy from the flyout.
|
|
|
|
* @return {Blockly.BlockSvg} The newly created block, or null if something
|
|
|
|
* went wrong with deserialization.
|
|
|
|
* @package
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.createBlock = function(originalBlock) {
|
|
|
|
var newBlock = null;
|
|
|
|
Blockly.Events.disable();
|
2017-11-22 12:56:31 -08:00
|
|
|
var variablesBeforeCreation = this.targetWorkspace_.getAllVariables();
|
2017-05-22 13:08:22 -07:00
|
|
|
this.targetWorkspace_.setResizesEnabled(false);
|
|
|
|
try {
|
|
|
|
newBlock = this.placeNewBlock_(originalBlock);
|
|
|
|
// Close the flyout.
|
|
|
|
Blockly.hideChaff();
|
|
|
|
} finally {
|
|
|
|
Blockly.Events.enable();
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
2017-05-22 13:08:22 -07:00
|
|
|
|
2017-12-19 14:46:53 -05:00
|
|
|
var newVariables = Blockly.Variables.getAddedVariables(this.targetWorkspace_,
|
|
|
|
variablesBeforeCreation);
|
2017-11-22 12:56:31 -08:00
|
|
|
|
2017-05-22 13:08:22 -07:00
|
|
|
if (Blockly.Events.isEnabled()) {
|
|
|
|
Blockly.Events.setGroup(true);
|
|
|
|
Blockly.Events.fire(new Blockly.Events.Create(newBlock));
|
2017-11-22 12:56:31 -08:00
|
|
|
// Fire a VarCreate event for each (if any) new variable created.
|
2018-04-30 15:42:02 -07:00
|
|
|
for (var i = 0; i < newVariables.length; i++) {
|
2017-11-22 12:56:31 -08:00
|
|
|
var thisVariable = newVariables[i];
|
|
|
|
Blockly.Events.fire(new Blockly.Events.VarCreate(thisVariable));
|
|
|
|
}
|
2014-09-08 14:26:52 -07:00
|
|
|
}
|
2017-05-22 13:08:22 -07:00
|
|
|
if (this.autoClose) {
|
|
|
|
this.hide();
|
2013-10-30 14:46:03 -07:00
|
|
|
}
|
2017-05-22 13:08:22 -07:00
|
|
|
return newBlock;
|
2013-10-30 14:46:03 -07:00
|
|
|
};
|
2016-02-08 13:56:57 -08:00
|
|
|
|
2016-04-18 17:29:48 -07:00
|
|
|
/**
|
|
|
|
* Reflow blocks and their buttons.
|
|
|
|
*/
|
2016-02-08 13:56:57 -08:00
|
|
|
Blockly.Flyout.prototype.reflow = function() {
|
2016-06-27 17:27:08 -07:00
|
|
|
if (this.reflowWrapper_) {
|
|
|
|
this.workspace_.removeChangeListener(this.reflowWrapper_);
|
|
|
|
}
|
2016-04-18 17:29:48 -07:00
|
|
|
var blocks = this.workspace_.getTopBlocks(false);
|
2016-09-08 16:54:10 -07:00
|
|
|
this.reflowInternal_(blocks);
|
2016-06-27 17:27:08 -07:00
|
|
|
if (this.reflowWrapper_) {
|
|
|
|
this.workspace_.addChangeListener(this.reflowWrapper_);
|
2016-02-08 13:56:57 -08:00
|
|
|
}
|
2016-04-27 11:33:09 -07:00
|
|
|
};
|
2017-05-22 13:08:22 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {boolean} True if this flyout may be scrolled with a scrollbar or by
|
|
|
|
* dragging.
|
|
|
|
* @package
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.isScrollable = function() {
|
|
|
|
return this.scrollbar_ ? this.scrollbar_.isVisible() : false;
|
|
|
|
};
|
2017-07-19 11:30:08 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy a block from the flyout to the workspace and position it correctly.
|
|
|
|
* @param {!Blockly.Block} oldBlock The flyout block to copy.
|
|
|
|
* @return {!Blockly.Block} The new block in the main workspace.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) {
|
|
|
|
var targetWorkspace = this.targetWorkspace_;
|
|
|
|
var svgRootOld = oldBlock.getSvgRoot();
|
|
|
|
if (!svgRootOld) {
|
2018-08-22 15:29:43 -04:00
|
|
|
throw 'oldBlock is not rendered.';
|
2017-07-19 11:30:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the new block by cloning the block in the flyout (via XML).
|
|
|
|
var xml = Blockly.Xml.blockToDom(oldBlock);
|
|
|
|
// The target workspace would normally resize during domToBlock, which will
|
|
|
|
// lead to weird jumps. Save it for terminateDrag.
|
|
|
|
targetWorkspace.setResizesEnabled(false);
|
|
|
|
|
|
|
|
// Using domToBlock instead of domToWorkspace means that the new block will be
|
|
|
|
// placed at position (0, 0) in main workspace units.
|
|
|
|
var block = Blockly.Xml.domToBlock(xml, targetWorkspace);
|
|
|
|
var svgRootNew = block.getSvgRoot();
|
|
|
|
if (!svgRootNew) {
|
2018-08-22 15:29:43 -04:00
|
|
|
throw 'block is not rendered.';
|
2017-07-19 11:30:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// The offset in pixels between the main workspace's origin and the upper left
|
|
|
|
// corner of the injection div.
|
|
|
|
var mainOffsetPixels = targetWorkspace.getOriginOffsetInPixels();
|
|
|
|
|
|
|
|
// The offset in pixels between the flyout workspace's origin and the upper
|
|
|
|
// left corner of the injection div.
|
|
|
|
var flyoutOffsetPixels = this.workspace_.getOriginOffsetInPixels();
|
|
|
|
|
|
|
|
// The position of the old block in flyout workspace coordinates.
|
|
|
|
var oldBlockPosWs = oldBlock.getRelativeToSurfaceXY();
|
|
|
|
|
|
|
|
// The position of the old block in pixels relative to the flyout
|
|
|
|
// workspace's origin.
|
|
|
|
var oldBlockPosPixels = oldBlockPosWs.scale(this.workspace_.scale);
|
|
|
|
|
|
|
|
// The position of the old block in pixels relative to the upper left corner
|
|
|
|
// of the injection div.
|
|
|
|
var oldBlockOffsetPixels = goog.math.Coordinate.sum(flyoutOffsetPixels,
|
|
|
|
oldBlockPosPixels);
|
|
|
|
|
|
|
|
// The position of the old block in pixels relative to the origin of the
|
|
|
|
// main workspace.
|
|
|
|
var finalOffsetPixels = goog.math.Coordinate.difference(oldBlockOffsetPixels,
|
|
|
|
mainOffsetPixels);
|
|
|
|
|
|
|
|
// The position of the old block in main workspace coordinates.
|
|
|
|
var finalOffsetMainWs = finalOffsetPixels.scale(1 / targetWorkspace.scale);
|
|
|
|
|
|
|
|
block.moveBy(finalOffsetMainWs.x, finalOffsetMainWs.y);
|
|
|
|
return block;
|
|
|
|
};
|
2018-04-13 11:22:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Put a previously created block into the recycle bin, used during large
|
|
|
|
* workspace swaps to limit the number of new dom elements we need to create
|
|
|
|
*
|
|
|
|
* @param {!Blockly.BlockSvg} block The block to recycle.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
Blockly.Flyout.prototype.recycleBlock_ = function(block) {
|
|
|
|
var xy = block.getRelativeToSurfaceXY();
|
|
|
|
block.moveBy(-xy.x, -xy.y);
|
|
|
|
this.recycleBlocks_.push(block);
|
|
|
|
};
|