Merge branch 'goog_module' into block_animations

This commit is contained in:
Aaron Dodson
2021-07-16 09:04:19 -07:00
committed by GitHub
4 changed files with 88 additions and 82 deletions

View File

@@ -15,11 +15,13 @@
'use strict';
goog.provide('Blockly.BlockDragSurfaceSvg');
goog.require('Blockly.utils');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.Svg');
goog.module('Blockly.BlockDragSurfaceSvg');
goog.module.declareLegacyNamespace();
const Coordinate = goog.require('Blockly.utils.Coordinate');
const {G, SVG} = goog.require('Blockly.utils.Svg');
const {getRelativeXY} = goog.require('Blockly.utils');
const {createSvgElement, HTML_NS, setCssTransform, SVG_NS, XLINK_NS} = goog.require('Blockly.utils.dom');
/**
@@ -28,7 +30,7 @@ goog.require('Blockly.utils.Svg');
* @param {!Element} container Containing element.
* @constructor
*/
Blockly.BlockDragSurfaceSvg = function(container) {
const BlockDragSurfaceSvg = function(container) {
/**
* @type {!Element}
* @private
@@ -38,11 +40,11 @@ Blockly.BlockDragSurfaceSvg = function(container) {
};
/**
* The SVG drag surface. Set once by Blockly.BlockDragSurfaceSvg.createDom.
* The SVG drag surface. Set once by BlockDragSurfaceSvg.createDom.
* @type {?SVGElement}
* @private
*/
Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null;
BlockDragSurfaceSvg.prototype.SVG_ = null;
/**
* This is where blocks live while they are being dragged if the drag surface
@@ -50,14 +52,14 @@ Blockly.BlockDragSurfaceSvg.prototype.SVG_ = null;
* @type {?SVGElement}
* @private
*/
Blockly.BlockDragSurfaceSvg.prototype.dragGroup_ = null;
BlockDragSurfaceSvg.prototype.dragGroup_ = null;
/**
* Containing HTML element; parent of the workspace and the drag surface.
* @type {?Element}
* @private
*/
Blockly.BlockDragSurfaceSvg.prototype.container_ = null;
BlockDragSurfaceSvg.prototype.container_ = null;
/**
* Cached value for the scale of the drag surface.
@@ -65,45 +67,43 @@ Blockly.BlockDragSurfaceSvg.prototype.container_ = null;
* @type {number}
* @private
*/
Blockly.BlockDragSurfaceSvg.prototype.scale_ = 1;
BlockDragSurfaceSvg.prototype.scale_ = 1;
/**
* Cached value for the translation of the drag surface.
* This translation is in pixel units, because the scale is applied to the
* drag group rather than the top-level SVG.
* @type {?Blockly.utils.Coordinate}
* @type {?Coordinate}
* @private
*/
Blockly.BlockDragSurfaceSvg.prototype.surfaceXY_ = null;
BlockDragSurfaceSvg.prototype.surfaceXY_ = null;
/**
* Cached value for the translation of the child drag surface in pixel units.
* Since the child drag surface tracks the translation of the workspace this is
* ultimately the translation of the workspace.
* @type {!Blockly.utils.Coordinate}
* @type {!Coordinate}
* @private
*/
Blockly.BlockDragSurfaceSvg.prototype.childSurfaceXY_ =
new Blockly.utils.Coordinate(0, 0);
BlockDragSurfaceSvg.prototype.childSurfaceXY_ = new Coordinate(0, 0);
/**
* Create the drag surface and inject it into the container.
*/
Blockly.BlockDragSurfaceSvg.prototype.createDom = function() {
BlockDragSurfaceSvg.prototype.createDom = function() {
if (this.SVG_) {
return; // Already created.
}
this.SVG_ = Blockly.utils.dom.createSvgElement(
Blockly.utils.Svg.SVG, {
'xmlns': Blockly.utils.dom.SVG_NS,
'xmlns:html': Blockly.utils.dom.HTML_NS,
'xmlns:xlink': Blockly.utils.dom.XLINK_NS,
this.SVG_ = createSvgElement(
SVG, {
'xmlns': SVG_NS,
'xmlns:html': HTML_NS,
'xmlns:xlink': XLINK_NS,
'version': '1.1',
'class': 'blocklyBlockDragSurface'
},
this.container_);
this.dragGroup_ =
Blockly.utils.dom.createSvgElement(Blockly.utils.Svg.G, {}, this.SVG_);
this.dragGroup_ = createSvgElement(G, {}, this.SVG_);
};
/**
@@ -112,14 +112,14 @@ Blockly.BlockDragSurfaceSvg.prototype.createDom = function() {
* @param {!SVGElement} blocks Block or group of blocks to place on the drag
* surface.
*/
Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) {
BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) {
if (this.dragGroup_.childNodes.length) {
throw Error('Already dragging a block.');
}
// appendChild removes the blocks from the previous parent
this.dragGroup_.appendChild(blocks);
this.SVG_.style.display = 'block';
this.surfaceXY_ = new Blockly.utils.Coordinate(0, 0);
this.surfaceXY_ = new Coordinate(0, 0);
};
/**
@@ -129,13 +129,12 @@ Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) {
* @param {number} y Y translation in pixel coordinates.
* @param {number} scale Scale of the group.
*/
Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function(
x, y, scale) {
BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function(x, y, scale) {
this.scale_ = scale;
// This is a work-around to prevent a the blocks from rendering
// fuzzy while they are being dragged on the drag surface.
var fixedX = x.toFixed(0);
var fixedY = y.toFixed(0);
const fixedX = x.toFixed(0);
const fixedY = y.toFixed(0);
this.childSurfaceXY_.x = parseInt(fixedX, 10);
this.childSurfaceXY_.y = parseInt(fixedY, 10);
@@ -149,17 +148,16 @@ Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function(
* Translate the drag surface's SVG based on its internal state.
* @private
*/
Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() {
var x = this.surfaceXY_.x;
var y = this.surfaceXY_.y;
BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() {
let x = this.surfaceXY_.x;
let y = this.surfaceXY_.y;
// This is a work-around to prevent a the blocks from rendering
// fuzzy while they are being dragged on the drag surface.
x = x.toFixed(0);
y = y.toFixed(0);
this.SVG_.style.display = 'block';
Blockly.utils.dom.setCssTransform(
this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)');
setCssTransform(this.SVG_, 'translate3d(' + x + 'px, ' + y + 'px, 0)');
};
/**
@@ -167,10 +165,10 @@ Blockly.BlockDragSurfaceSvg.prototype.translateSurfaceInternal_ = function() {
* @param {number} deltaX Horizontal offset in pixel units.
* @param {number} deltaY Vertical offset in pixel units.
*/
Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) {
var x = this.surfaceXY_.x + deltaX;
var y = this.surfaceXY_.y + deltaY;
this.surfaceXY_ = new Blockly.utils.Coordinate(x, y);
BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) {
const x = this.surfaceXY_.x + deltaX;
const y = this.surfaceXY_.y + deltaY;
this.surfaceXY_ = new Coordinate(x, y);
this.translateSurfaceInternal_();
};
@@ -182,20 +180,19 @@ Blockly.BlockDragSurfaceSvg.prototype.translateBy = function(deltaX, deltaY) {
* @param {number} x X translation for the entire surface.
* @param {number} y Y translation for the entire surface.
*/
Blockly.BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) {
this.surfaceXY_ =
new Blockly.utils.Coordinate(x * this.scale_, y * this.scale_);
BlockDragSurfaceSvg.prototype.translateSurface = function(x, y) {
this.surfaceXY_ = new Coordinate(x * this.scale_, y * this.scale_);
this.translateSurfaceInternal_();
};
/**
* Reports the surface translation in scaled workspace coordinates.
* Use this when finishing a drag to return blocks to the correct position.
* @return {!Blockly.utils.Coordinate} Current translation of the surface.
* @return {!Coordinate} Current translation of the surface.
*/
Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() {
var xy = Blockly.utils.getRelativeXY(/** @type {!SVGElement} */ (this.SVG_));
return new Blockly.utils.Coordinate(xy.x / this.scale_, xy.y / this.scale_);
BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() {
const xy = getRelativeXY(/** @type {!SVGElement} */ (this.SVG_));
return new Coordinate(xy.x / this.scale_, xy.y / this.scale_);
};
/**
@@ -203,7 +200,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getSurfaceTranslation = function() {
* BlockSvg.getRelativeToSurfaceXY).
* @return {?SVGElement} Drag surface group element.
*/
Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() {
BlockDragSurfaceSvg.prototype.getGroup = function() {
return this.dragGroup_;
};
@@ -211,16 +208,17 @@ Blockly.BlockDragSurfaceSvg.prototype.getGroup = function() {
* Returns the SVG drag surface.
* @returns {?SVGElement} The SVG drag surface.
*/
Blockly.BlockDragSurfaceSvg.prototype.getSvgRoot = function() {
BlockDragSurfaceSvg.prototype.getSvgRoot = function() {
return this.SVG_;
};
/**
* Get the current blocks on the drag surface, if any (primarily
* for BlockSvg.getRelativeToSurfaceXY).
* @return {?Element} Drag surface block DOM element, or null if no blocks exist.
* @return {?Element} Drag surface block DOM element, or null if no blocks
* exist.
*/
Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() {
BlockDragSurfaceSvg.prototype.getCurrentBlock = function() {
return /** @type {Element} */ (this.dragGroup_.firstChild);
};
@@ -228,9 +226,9 @@ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() {
* Gets the translation of the child block surface
* This surface is in charge of keeping track of how much the workspace has
* moved.
* @return {!Blockly.utils.Coordinate} The amount the workspace has been moved.
* @return {!Coordinate} The amount the workspace has been moved.
*/
Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() {
BlockDragSurfaceSvg.prototype.getWsTranslation = function() {
// Returning a copy so the coordinate can not be changed outside this class.
return this.childSurfaceXY_.clone();
};
@@ -244,7 +242,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getWsTranslation = function() {
* to, or null if the blocks should be removed from this surface without
* being moved to a different surface.
*/
Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) {
BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) {
if (opt_newSurface) {
// appendChild removes the node from this.dragGroup_
opt_newSurface.appendChild(this.getCurrentBlock());
@@ -257,3 +255,5 @@ Blockly.BlockDragSurfaceSvg.prototype.clearAndHide = function(opt_newSurface) {
}
this.surfaceXY_ = null;
};
exports = BlockDragSurfaceSvg;

View File

@@ -14,10 +14,13 @@
* A mapping of block type names to block prototype objects.
* @name Blockly.Blocks
*/
goog.provide('Blockly.Blocks');
goog.module('Blockly.Blocks');
goog.module.declareLegacyNamespace();
/**
* A mapping of block type names to block prototype objects.
* @type {!Object<string,Object>}
* @type {!Object<string,!Object>}
*/
Blockly.Blocks = Object.create(null);
const Blocks = Object.create(null);
exports = Blocks;

View File

@@ -14,139 +14,142 @@
* @name Blockly.utils.Metrics
* @namespace
*/
goog.provide('Blockly.utils.Metrics');
goog.module('Blockly.utils.Metrics');
goog.module.declareLegacyNamespace();
/**
* @record
*/
Blockly.utils.Metrics = function() {};
const Metrics = function() {};
/**
* Height of the visible portion of the workspace.
* @type {number}
*/
Blockly.utils.Metrics.prototype.viewHeight;
Metrics.prototype.viewHeight;
/**
* Width of the visible portion of the workspace.
* @type {number}
*/
Blockly.utils.Metrics.prototype.viewWidth;
Metrics.prototype.viewWidth;
/**
* Height of the content.
* @type {number}
*/
Blockly.utils.Metrics.prototype.contentHeight;
Metrics.prototype.contentHeight;
/**
* Width of the content.
* @type {number}
*/
Blockly.utils.Metrics.prototype.contentWidth;
Metrics.prototype.contentWidth;
/**
* Height of the scroll area.
* @type {number}
*/
Blockly.utils.Metrics.prototype.scrollHeight;
Metrics.prototype.scrollHeight;
/**
* Width of the scroll area.
* @type {number}
*/
Blockly.utils.Metrics.prototype.scrollWidth;
Metrics.prototype.scrollWidth;
/**
* Top-edge of the visible portion of the workspace, relative to the workspace
* origin.
* @type {number}
*/
Blockly.utils.Metrics.prototype.viewTop;
Metrics.prototype.viewTop;
/**
* Left-edge of the visible portion of the workspace, relative to the workspace
* origin.
* @type {number}
*/
Blockly.utils.Metrics.prototype.viewLeft;
Metrics.prototype.viewLeft;
/**
* Top-edge of the content, relative to the workspace origin.
* @type {number}
*/
Blockly.utils.Metrics.prototype.contentTop;
Metrics.prototype.contentTop;
/**
* Left-edge of the content relative to the workspace origin.
* @type {number}
*/
Blockly.utils.Metrics.prototype.contentLeft;
Metrics.prototype.contentLeft;
/**
* Top-edge of the scroll area, relative to the workspace origin.
* @type {number}
*/
Blockly.utils.Metrics.prototype.scrollTop;
Metrics.prototype.scrollTop;
/**
* Left-edge of the scroll area relative to the workspace origin.
* @type {number}
*/
Blockly.utils.Metrics.prototype.scrollLeft;
Metrics.prototype.scrollLeft;
/**
* Top-edge of the visible portion of the workspace, relative to the blocklyDiv.
* @type {number}
*/
Blockly.utils.Metrics.prototype.absoluteTop;
Metrics.prototype.absoluteTop;
/**
* Left-edge of the visible portion of the workspace, relative to the
* blocklyDiv.
* @type {number}
*/
Blockly.utils.Metrics.prototype.absoluteLeft;
Metrics.prototype.absoluteLeft;
/**
* Height of the Blockly div (the view + the toolbox, simple of otherwise).
* @type {number}
*/
Blockly.utils.Metrics.prototype.svgHeight;
Metrics.prototype.svgHeight;
/**
* Width of the Blockly div (the view + the toolbox, simple or otherwise).
* @type {number}
*/
Blockly.utils.Metrics.prototype.svgWidth;
Metrics.prototype.svgWidth;
/**
* Width of the toolbox, if it exists. Otherwise zero.
* @type {number}
*/
Blockly.utils.Metrics.prototype.toolboxWidth;
Metrics.prototype.toolboxWidth;
/**
* Height of the toolbox, if it exists. Otherwise zero.
* @type {number}
*/
Blockly.utils.Metrics.prototype.toolboxHeight;
Metrics.prototype.toolboxHeight;
/**
* Top, bottom, left or right. Use TOOLBOX_AT constants to compare.
* @type {number}
*/
Blockly.utils.Metrics.prototype.toolboxPosition;
Metrics.prototype.toolboxPosition;
/**
* Width of the flyout if it is always open. Otherwise zero.
* @type {number}
*/
Blockly.utils.Metrics.prototype.flyoutWidth;
Metrics.prototype.flyoutWidth;
/**
* Height of the flyout if it is always open. Otherwise zero.
* @type {number}
*/
Blockly.utils.Metrics.prototype.flyoutHeight;
Metrics.prototype.flyoutHeight;
exports = Metrics;

View File

@@ -9,11 +9,11 @@ goog.addDependency('../../blocks/variables.js', ['Blockly.Blocks.variables', 'Bl
goog.addDependency('../../blocks/variables_dynamic.js', ['Blockly.Constants.VariablesDynamic'], ['Blockly', 'Blockly.Blocks', 'Blockly.FieldLabel', 'Blockly.FieldVariable']);
goog.addDependency('../../core/block.js', ['Blockly.Block'], ['Blockly.ASTNode', 'Blockly.Blocks', 'Blockly.Connection', 'Blockly.Events', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.IASTNodeLocation', 'Blockly.IDeletable', 'Blockly.Input', 'Blockly.Tooltip', 'Blockly.Workspace', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.fieldRegistry', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.object'], {'lang': 'es5'});
goog.addDependency('../../core/block_animations.js', ['Blockly.blockAnimations'], ['Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom']);
goog.addDependency('../../core/block_drag_surface.js', ['Blockly.BlockDragSurfaceSvg'], ['Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Svg', 'Blockly.utils.dom'], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/block_dragger.js', ['Blockly.BlockDragger'], ['Blockly.Events', 'Blockly.Events.BlockDrag', 'Blockly.Events.BlockMove', 'Blockly.IBlockDragger', 'Blockly.InsertionMarkerManager', 'Blockly.blockAnimations', 'Blockly.constants', 'Blockly.registry', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']);
goog.addDependency('../../core/block_svg.js', ['Blockly.BlockSvg'], ['Blockly.ASTNode', 'Blockly.Block', 'Blockly.ContextMenu', 'Blockly.ContextMenuRegistry', 'Blockly.Events', 'Blockly.Events.BlockMove', 'Blockly.Events.Selected', 'Blockly.IASTNodeLocationSvg', 'Blockly.IBoundedElement', 'Blockly.ICopyable', 'Blockly.IDraggable', 'Blockly.Msg', 'Blockly.RenderedConnection', 'Blockly.TabNavigateCursor', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Xml', 'Blockly.blockAnimations', 'Blockly.blockRendering.IPathObject', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Rect', 'Blockly.utils.Svg', 'Blockly.utils.deprecation', 'Blockly.utils.dom', 'Blockly.utils.object', 'Blockly.utils.userAgent']);
goog.addDependency('../../core/blockly.js', ['Blockly'], ['Blockly.ComponentManager', 'Blockly.DropDownDiv', 'Blockly.Events', 'Blockly.Events.BlockCreate', 'Blockly.Events.FinishedLoading', 'Blockly.Events.Ui', 'Blockly.Events.UiBase', 'Blockly.Events.VarCreate', 'Blockly.Procedures', 'Blockly.ShortcutRegistry', 'Blockly.Tooltip', 'Blockly.Touch', 'Blockly.Variables', 'Blockly.WidgetDiv', 'Blockly.WorkspaceSvg', 'Blockly.Xml', 'Blockly.browserEvents', 'Blockly.connectionTypes', 'Blockly.constants', 'Blockly.inject', 'Blockly.inputTypes', 'Blockly.utils', 'Blockly.utils.Size', 'Blockly.utils.colour', 'Blockly.utils.deprecation', 'Blockly.utils.toolbox']);
goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], []);
goog.addDependency('../../core/blocks.js', ['Blockly.Blocks'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/browser_events.js', ['Blockly.browserEvents'], ['Blockly.Touch', 'Blockly.utils.global']);
goog.addDependency('../../core/bubble.js', ['Blockly.Bubble'], ['Blockly.IBubble', 'Blockly.Scrollbar', 'Blockly.Touch', 'Blockly.Workspace', 'Blockly.browserEvents', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.Size', 'Blockly.utils.Svg', 'Blockly.utils.dom', 'Blockly.utils.math', 'Blockly.utils.userAgent']);
goog.addDependency('../../core/bubble_dragger.js', ['Blockly.BubbleDragger'], ['Blockly.Bubble', 'Blockly.ComponentManager', 'Blockly.Events', 'Blockly.Events.CommentMove', 'Blockly.constants', 'Blockly.utils', 'Blockly.utils.Coordinate']);
@@ -178,7 +178,7 @@ goog.addDependency('../../core/utils/global.js', ['Blockly.utils.global'], []);
goog.addDependency('../../core/utils/idgenerator.js', ['Blockly.utils.IdGenerator'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/keycodes.js', ['Blockly.utils.KeyCodes'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/math.js', ['Blockly.utils.math'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], []);
goog.addDependency('../../core/utils/metrics.js', ['Blockly.utils.Metrics'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/object.js', ['Blockly.utils.object'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/rect.js', ['Blockly.utils.Rect'], [], {'lang': 'es6', 'module': 'goog'});
goog.addDependency('../../core/utils/size.js', ['Blockly.utils.Size'], []);