未验证 提交 a61109c5 编写于 作者: M Maribeth Bottorff 提交者: GitHub

Merge pull request #4735 from google/rc_2021_3

Rc 2021 3
Language: JavaScript
BasedOnStyle: Google
ColumnLimit: 80
......@@ -3,7 +3,7 @@
name: Node.js CI
on: push
on: [pull_request]
jobs:
build:
......
......@@ -2,14 +2,12 @@
.*
*.soy
*.komodoproject
/deploy
deploy
/static/appengine/
/static/closure/
/static/demos/plane/soy/*.jar
/static/demos/plane/xlf/
/static/externs/
/static/msg/json/
/static/node_modules/
/static/scripts/
/static/typings/
......
#!/bin/bash
# Script to deploy on GAE.
APP=./app.yaml
if ! [ -f $APP ] ; then
echo $APP not found 1>&2
exit 1
fi
PROJECT=blockly-demo
VERSION=37
echo 'Beginning deployment...'
gcloud app deploy --project $PROJECT --version $VERSION --no-promote
echo 'Deployment finished.'
此差异已折叠。
此差异已折叠。
此差异已折叠。
因为 它太大了无法显示 source diff 。您可以改为 查看blob
此差异已折叠。
......@@ -15,6 +15,8 @@ goog.provide('Blockly.blockAnimations');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.Svg');
goog.requireType('Blockly.BlockSvg');
/**
* PID of disconnect UI animation. There can only be one at a time.
......
......@@ -13,14 +13,20 @@
goog.provide('Blockly.BlockDragger');
goog.require('Blockly.blockAnimations');
/** @suppress {extraRequire} */
goog.require('Blockly.constants');
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockMove');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.BlockDrag');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.BlockMove');
goog.require('Blockly.InsertionMarkerManager');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.dom');
goog.requireType('Blockly.BlockSvg');
goog.requireType('Blockly.WorkspaceSvg');
/**
* Class for a block dragger. It moves blocks around the workspace when they
......@@ -184,8 +190,8 @@ Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY,
* @private
*/
Blockly.BlockDragger.prototype.fireDragStartEvent_ = function() {
var event = new Blockly.Events.BlockDrag(this.draggingBlock_, true,
this.draggingBlock_.getDescendants(false));
var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))(
this.draggingBlock_, true, this.draggingBlock_.getDescendants(false));
Blockly.Events.fire(event);
};
......@@ -261,8 +267,8 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) {
* @private
*/
Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() {
var event = new Blockly.Events.BlockDrag(this.draggingBlock_, false,
this.draggingBlock_.getDescendants(false));
var event = new (Blockly.Events.get(Blockly.Events.BLOCK_DRAG))(
this.draggingBlock_, false, this.draggingBlock_.getDescendants(false));
Blockly.Events.fire(event);
};
......@@ -271,7 +277,8 @@ Blockly.BlockDragger.prototype.fireDragEndEvent_ = function() {
* @private
*/
Blockly.BlockDragger.prototype.fireMoveEvent_ = function() {
var event = new Blockly.Events.BlockMove(this.draggingBlock_);
var event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(
this.draggingBlock_);
event.oldCoordinate = this.startXY_;
event.recordNew();
Blockly.Events.fire(event);
......
......@@ -16,29 +16,44 @@ goog.require('Blockly.ASTNode');
goog.require('Blockly.Block');
goog.require('Blockly.blockAnimations');
goog.require('Blockly.blockRendering.IPathObject');
goog.require('Blockly.browserEvents');
goog.require('Blockly.connectionTypes');
/** @suppress {extraRequire} */
goog.require('Blockly.constants');
goog.require('Blockly.ContextMenu');
goog.require('Blockly.ContextMenuRegistry');
goog.require('Blockly.Events');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.BlockMove');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.Selected');
goog.require('Blockly.Msg');
goog.require('Blockly.navigation');
goog.require('Blockly.RenderedConnection');
goog.require('Blockly.TabNavigateCursor');
goog.require('Blockly.Tooltip');
/** @suppress {extraRequire} */
goog.require('Blockly.Touch');
goog.require('Blockly.utils');
goog.require('Blockly.utils.deprecation');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.deprecation');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.object');
goog.require('Blockly.utils.Rect');
goog.require('Blockly.utils.userAgent');
goog.require('Blockly.Xml');
goog.requireType('Blockly.blockRendering.Debug');
goog.requireType('Blockly.Comment');
goog.requireType('Blockly.Connection');
goog.requireType('Blockly.Field');
goog.requireType('Blockly.IASTNodeLocationSvg');
goog.requireType('Blockly.IBoundedElement');
goog.requireType('Blockly.ICopyable');
goog.requireType('Blockly.Input');
goog.requireType('Blockly.Mutator');
goog.requireType('Blockly.Theme');
goog.requireType('Blockly.Warning');
goog.requireType('Blockly.WorkspaceSvg');
/**
......@@ -148,7 +163,7 @@ Blockly.BlockSvg.prototype.warningTextDb_ = null;
/**
* Constant for identifying rows that are to be rendered inline.
* Don't collide with Blockly.INPUT_VALUE and friends.
* Don't collide with Blockly.inputTypes.
* @const
*/
Blockly.BlockSvg.INLINE = -1;
......@@ -214,7 +229,7 @@ Blockly.BlockSvg.prototype.initSvg = function() {
this.pathObject.updateMovable(this.isMovable());
var svg = this.getSvgRoot();
if (!this.workspace.options.readOnly && !this.eventsInit_ && svg) {
Blockly.bindEventWithChecks_(
Blockly.browserEvents.conditionalBind(
svg, 'mousedown', this, this.onMouseDown_);
}
this.eventsInit_ = true;
......@@ -300,7 +315,8 @@ Blockly.BlockSvg.prototype.select = function() {
Blockly.Events.enable();
}
}
var event = new Blockly.Events.Selected(oldId, this.id, this.workspace.id);
var event = new (Blockly.Events.get(Blockly.Events.SELECTED))(oldId, this.id,
this.workspace.id);
Blockly.Events.fire(event);
Blockly.selected = this;
this.addSelect();
......@@ -313,7 +329,8 @@ Blockly.BlockSvg.prototype.unselect = function() {
if (Blockly.selected != this) {
return;
}
var event = new Blockly.Events.Selected(this.id, null, this.workspace.id);
var event = new (Blockly.Events.get(Blockly.Events.SELECTED))(this.id, null,
this.workspace.id);
event.workspaceId = this.workspace.id;
Blockly.Events.fire(event);
Blockly.selected = null;
......@@ -454,7 +471,7 @@ Blockly.BlockSvg.prototype.moveBy = function(dx, dy) {
}
var eventsEnabled = Blockly.Events.isEnabled();
if (eventsEnabled) {
var event = new Blockly.Events.BlockMove(this);
var event = new (Blockly.Events.get(Blockly.Events.BLOCK_MOVE))(this);
}
var xy = this.getRelativeToSurfaceXY();
this.translate(xy.x + dx, xy.y + dy);
......@@ -645,8 +662,8 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
*/
Blockly.BlockSvg.prototype.updateCollapsed_ = function() {
var collapsed = this.isCollapsed();
var collapsedInputName = Blockly.Block.COLLAPSED_INPUT_NAME;
var collapsedFieldName = Blockly.Block.COLLAPSED_FIELD_NAME;
var collapsedInputName = Blockly.constants.COLLAPSED_INPUT_NAME;
var collapsedFieldName = Blockly.constants.COLLAPSED_FIELD_NAME;
for (var i = 0, input; (input = this.inputList[i]); i++) {
if (input.name != collapsedInputName) {
......@@ -655,6 +672,7 @@ Blockly.BlockSvg.prototype.updateCollapsed_ = function() {
}
if (!collapsed) {
this.updateDisabled();
this.removeInput(collapsedInputName);
return;
}
......@@ -684,11 +702,12 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) {
var tabCursor = new Blockly.TabNavigateCursor();
tabCursor.setCurNode(Blockly.ASTNode.createFieldNode(start));
var currentNode = tabCursor.getCurNode();
var actionName = forward ?
Blockly.navigation.actionNames.NEXT : Blockly.navigation.actionNames.PREVIOUS;
tabCursor.onBlocklyAction(
/** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ ({name: actionName}));
if (forward) {
tabCursor.next();
} else {
tabCursor.prev();
}
var nextNode = tabCursor.getCurNode();
if (nextNode && nextNode !== currentNode) {
......@@ -899,10 +918,6 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
Blockly.ContextMenu.hide();
}
if (this.workspace.keyboardAccessibilityMode) {
Blockly.navigation.moveCursorOnBlockDelete(this);
}
if (animate && this.rendered) {
this.unplug(healStack);
Blockly.blockAnimations.disposeUiEffect(this);
......@@ -1361,8 +1376,7 @@ Blockly.BlockSvg.prototype.moveNumberedInputBefore = function(
/**
* Add a value input, statement input or local variable to this block.
* @param {number} type Either Blockly.INPUT_VALUE or Blockly.NEXT_STATEMENT or
* Blockly.DUMMY_INPUT.
* @param {number} type One of Blockly.inputTypes.
* @param {string} name Language-neutral identifier which may used to find this
* input again. Should be unique to this block.
* @return {!Blockly.Input} The input object created.
......@@ -1576,8 +1590,8 @@ Blockly.BlockSvg.prototype.positionNearConnection = function(sourceConnection,
targetConnection) {
// We only need to position the new block if it's before the existing one,
// otherwise its position is set by the previous block.
if (sourceConnection.type == Blockly.NEXT_STATEMENT ||
sourceConnection.type == Blockly.INPUT_VALUE) {
if (sourceConnection.type == Blockly.connectionTypes.NEXT_STATEMENT ||
sourceConnection.type == Blockly.connectionTypes.INPUT_VALUE) {
var dx = targetConnection.x - sourceConnection.x;
var dy = targetConnection.y - sourceConnection.y;
......@@ -1652,7 +1666,8 @@ Blockly.BlockSvg.prototype.updateMarkers_ = function() {
this.workspace.getCursor().draw();
}
if (this.workspace.keyboardAccessibilityMode && this.pathObject.markerSvg) {
this.workspace.getMarker(Blockly.navigation.MARKER_NAME).draw();
// TODO(#4592): Update all markers on the block.
this.workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw();
}
};
......
......@@ -16,23 +16,47 @@
*/
goog.provide('Blockly');
goog.require('Blockly.browserEvents');
/** @suppress {extraRequire} */
goog.require('Blockly.constants');
goog.require('Blockly.connectionTypes');
goog.require('Blockly.Events');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.BlockCreate');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.FinishedLoading');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.Ui');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.UiBase');
/** @suppress {extraRequire} */
goog.require('Blockly.Events.VarCreate');
/** @suppress {extraRequire} */
goog.require('Blockly.inject');
goog.require('Blockly.inputTypes');
/** @suppress {extraRequire} */
goog.require('Blockly.Procedures');
goog.require('Blockly.ShortcutRegistry');
goog.require('Blockly.Tooltip');
/** @suppress {extraRequire} */
goog.require('Blockly.Touch');
goog.require('Blockly.utils');
goog.require('Blockly.utils.colour');
goog.require('Blockly.utils.deprecation');
goog.require('Blockly.utils.Size');
goog.require('Blockly.utils.toolbox');
/** @suppress {extraRequire} */
goog.require('Blockly.Variables');
goog.require('Blockly.WidgetDiv');
goog.require('Blockly.WorkspaceSvg');
/** @suppress {extraRequire} */
goog.require('Blockly.Xml');
goog.requireType('Blockly.BlockSvg');
goog.requireType('Blockly.Connection');
goog.requireType('Blockly.ICopyable');
goog.requireType('Blockly.Workspace');
/**
* Blockly core version.
......@@ -99,19 +123,20 @@ Blockly.cache3dSupported_ = null;
*/
Blockly.parentContainer = null;
/**
* Blockly opaque event data used to unbind events when using
* `Blockly.bindEvent_` and `Blockly.bindEventWithChecks_`.
* @typedef {!Array.<!Array>}
*/
Blockly.EventData;
/**
* Returns the dimensions of the specified SVG image.
* @param {!SVGElement} svg SVG image.
* @return {!Blockly.utils.Size} Contains width and height properties.
* @deprecated Use workspace.setCachedParentSvgSize. (2021 March 5)
*/
Blockly.svgSize = function(svg) {
// When removing this function, remove svg.cachedWidth_ and svg.cachedHeight_
// from setCachedParentSvgSize.
Blockly.utils.deprecation.warn(
'Blockly.svgSize',
'March 2021',
'March 2022',
'workspace.getCachedParentSvgSize');
svg = /** @type {?} */ (svg);
return new Blockly.utils.Size(svg.cachedWidth_, svg.cachedHeight_);
};
......@@ -139,6 +164,7 @@ Blockly.svgResize = function(workspace) {
mainWorkspace = mainWorkspace.options.parentWorkspace;
}
var svg = mainWorkspace.getParentSvg();
var cachedSize = mainWorkspace.getCachedParentSvgSize();
var div = svg.parentNode;
if (!div) {
// Workspace deleted, or something.
......@@ -146,13 +172,13 @@ Blockly.svgResize = function(workspace) {
}
var width = div.offsetWidth;
var height = div.offsetHeight;
if (svg.cachedWidth_ != width) {
if (cachedSize.width != width) {
svg.setAttribute('width', width + 'px');
svg.cachedWidth_ = width;
mainWorkspace.setCachedParentSvgSize(width, null);
}
if (svg.cachedHeight_ != height) {
if (cachedSize.height != height) {
svg.setAttribute('height', height + 'px');
svg.cachedHeight_ = height;
mainWorkspace.setCachedParentSvgSize(null, height);
}
mainWorkspace.resize();
};
......@@ -383,149 +409,6 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) {
}
};
/**
* Bind an event to a function call. When calling the function, verifies that
* it belongs to the touch stream that is currently being processed, and splits
* multitouch events into multiple events as needed.
* @param {!EventTarget} node Node upon which to listen.
* @param {string} name Event name to listen to (e.g. 'mousedown').
* @param {Object} thisObject The value of 'this' in the function.
* @param {!Function} func Function to call when event is triggered.
* @param {boolean=} opt_noCaptureIdentifier True if triggering on this event
* should not block execution of other event handlers on this touch or
* other simultaneous touches. False by default.
* @param {boolean=} opt_noPreventDefault True if triggering on this event
* should prevent the default handler. False by default. If
* opt_noPreventDefault is provided, opt_noCaptureIdentifier must also be
* provided.
* @return {!Blockly.EventData} Opaque data that can be passed to unbindEvent_.
*/
Blockly.bindEventWithChecks_ = function(node, name, thisObject, func,
opt_noCaptureIdentifier, opt_noPreventDefault) {
var handled = false;
var wrapFunc = function(e) {
var captureIdentifier = !opt_noCaptureIdentifier;
// Handle each touch point separately. If the event was a mouse event, this
// will hand back an array with one element, which we're fine handling.
var events = Blockly.Touch.splitEventByTouches(e);
for (var i = 0, event; (event = events[i]); i++) {
if (captureIdentifier && !Blockly.Touch.shouldHandleEvent(event)) {
continue;
}
Blockly.Touch.setClientFromTouch(event);
if (thisObject) {
func.call(thisObject, event);
} else {
func(event);
}
handled = true;
}
};
var bindData = [];
if (Blockly.utils.global['PointerEvent'] &&
(name in Blockly.Touch.TOUCH_MAP)) {
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, wrapFunc, false);
bindData.push([node, type, wrapFunc]);
}
} else {
node.addEventListener(name, wrapFunc, false);
bindData.push([node, name, wrapFunc]);
// Add equivalent touch event.
if (name in Blockly.Touch.TOUCH_MAP) {
var touchWrapFunc = function(e) {
wrapFunc(e);
// Calling preventDefault stops the browser from scrolling/zooming the
// page.
var preventDef = !opt_noPreventDefault;
if (handled && preventDef) {
e.preventDefault();
}
};
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, touchWrapFunc, false);
bindData.push([node, type, touchWrapFunc]);
}
}
}
return bindData;
};
/**
* Bind an event to a function call. Handles multitouch events by using the
* coordinates of the first changed touch, and doesn't do any safety checks for
* simultaneous event processing. In most cases prefer is to use
* `Blockly.bindEventWithChecks_`.
* @param {!EventTarget} node Node upon which to listen.
* @param {string} name Event name to listen to (e.g. 'mousedown').
* @param {Object} thisObject The value of 'this' in the function.
* @param {!Function} func Function to call when event is triggered.
* @return {!Blockly.EventData} Opaque data that can be passed to unbindEvent_.
*/
Blockly.bindEvent_ = function(node, name, thisObject, func) {
var wrapFunc = function(e) {
if (thisObject) {
func.call(thisObject, e);
} else {
func(e);
}
};
var bindData = [];
if (Blockly.utils.global['PointerEvent'] &&
(name in Blockly.Touch.TOUCH_MAP)) {
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, wrapFunc, false);
bindData.push([node, type, wrapFunc]);
}
} else {
node.addEventListener(name, wrapFunc, false);
bindData.push([node, name, wrapFunc]);
// Add equivalent touch event.
if (name in Blockly.Touch.TOUCH_MAP) {
var touchWrapFunc = function(e) {
// Punt on multitouch events.
if (e.changedTouches && e.changedTouches.length == 1) {
// Map the touch event's properties to the event.
var touchPoint = e.changedTouches[0];
e.clientX = touchPoint.clientX;
e.clientY = touchPoint.clientY;
}
wrapFunc(e);
// Stop the browser from scrolling/zooming the page.
e.preventDefault();
};
for (var i = 0, type; (type = Blockly.Touch.TOUCH_MAP[name][i]); i++) {
node.addEventListener(type, touchWrapFunc, false);
bindData.push([node, type, touchWrapFunc]);
}
}
}
return bindData;
};
/**
* Unbind one or more events event from a function call.
* @param {!Array.<!Array>} bindData Opaque data from bindEvent_.
* This list is emptied during the course of calling this function.
* @return {!Function} The function call.
*/
Blockly.unbindEvent_ = function(bindData) {
while (bindData.length) {
var bindDatum = bindData.pop();
var node = bindDatum[0];
var name = bindDatum[1];
var func = bindDatum[2];
node.removeEventListener(name, func, false);
}
return func;
};
/**