| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
|
|
| 'use strict';
|
|
|
| goog.provide('Blockly.BlockSvg');
|
|
|
| goog.require('Blockly.Block');
|
| goog.require('Blockly.BlockAnimations');
|
| goog.require('Blockly.ContextMenu');
|
| goog.require('Blockly.Events.Ui');
|
| goog.require('Blockly.Events.BlockMove');
|
| goog.require('Blockly.Grid');
|
| goog.require('Blockly.RenderedConnection');
|
| goog.require('Blockly.scratchBlocksUtils');
|
| goog.require('Blockly.Tooltip');
|
| goog.require('Blockly.Touch');
|
| goog.require('Blockly.utils');
|
|
|
| goog.require('goog.Timer');
|
| goog.require('goog.asserts');
|
| goog.require('goog.dom');
|
| goog.require('goog.math.Coordinate');
|
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
|
|
|
| |
| |
| |
|
|
| this.svgGroup_ = Blockly.utils.createSvgElement('g', {}, null);
|
|
|
| this.svgPath_ = Blockly.utils.createSvgElement('path',
|
| {'class': 'blocklyPath blocklyBlockBackground'},
|
| this.svgGroup_);
|
| this.svgPath_.tooltip = this;
|
|
|
|
|
| this.rendered = false;
|
|
|
| |
| |
| |
| |
| |
|
|
| this.useDragSurface_ = Blockly.utils.is3dSupported() && !!workspace.blockDragSurface_;
|
|
|
| Blockly.Tooltip.bindMouseEvents(this.svgPath_);
|
| Blockly.BlockSvg.superClass_.constructor.call(this,
|
| workspace, prototypeName, opt_id);
|
|
|
|
|
| if (this.svgGroup_.dataset) {
|
| this.svgGroup_.dataset.id = this.id;
|
| }
|
| };
|
| goog.inherits(Blockly.BlockSvg, Blockly.Block);
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.height = 0;
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.width = 0;
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.insertionMarkerMinWidth_ = 0;
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.opacity_ = 1;
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.dragStartXY_ = null;
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.isGlowingBlock_ = false;
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.isGlowingStack_ = false;
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.INLINE = -1;
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.initSvg = function() {
|
| goog.asserts.assert(this.workspace.rendered, 'Workspace is headless.');
|
| if (!this.isInsertionMarker()) {
|
|
|
| for (var i = 0, input; input = this.inputList[i]; i++) {
|
| input.init();
|
| input.initOutlinePath(this.svgGroup_);
|
| }
|
| var icons = this.getIcons();
|
| for (i = 0; i < icons.length; i++) {
|
| icons[i].createIcon();
|
| }
|
| }
|
| this.updateColour();
|
| this.updateMovable();
|
| if (!this.workspace.options.readOnly && !this.eventsInit_) {
|
| Blockly.bindEventWithChecks_(
|
| this.getSvgRoot(), 'mousedown', this, this.onMouseDown_);
|
| }
|
| this.eventsInit_ = true;
|
|
|
| if (!this.getSvgRoot().parentNode) {
|
| this.workspace.getCanvas().appendChild(this.getSvgRoot());
|
| }
|
| };
|
|
|
| |
| |
|
|
| Blockly.BlockSvg.prototype.select = function() {
|
| if (this.isShadow() && this.getParent()) {
|
|
|
| this.getParent().select();
|
| return;
|
| }
|
| if (Blockly.selected == this) {
|
| return;
|
| }
|
| var oldId = null;
|
| if (Blockly.selected) {
|
| oldId = Blockly.selected.id;
|
|
|
| Blockly.Events.disable();
|
| try {
|
| Blockly.selected.unselect();
|
| } finally {
|
| Blockly.Events.enable();
|
| }
|
| }
|
| var event = new Blockly.Events.Ui(null, 'selected', oldId, this.id);
|
| event.workspaceId = this.workspace.id;
|
| Blockly.Events.fire(event);
|
| Blockly.selected = this;
|
| this.addSelect();
|
| };
|
|
|
| |
| |
|
|
| Blockly.BlockSvg.prototype.unselect = function() {
|
| if (Blockly.selected != this) {
|
| return;
|
| }
|
| var event = new Blockly.Events.Ui(null, 'selected', this.id, null);
|
| event.workspaceId = this.workspace.id;
|
| Blockly.Events.fire(event);
|
| Blockly.selected = null;
|
| this.removeSelect();
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setGlowBlock = function(isGlowingBlock) {
|
| this.isGlowingBlock_ = isGlowingBlock;
|
| this.updateColour();
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setGlowStack = function(isGlowingStack) {
|
| this.isGlowingStack_ = isGlowingStack;
|
|
|
| var svg = this.getSvgRoot();
|
| if (this.isGlowingStack_ && !svg.hasAttribute('filter')) {
|
| var stackGlowFilterId = this.workspace.options.stackGlowFilterId || 'blocklyStackGlowFilter';
|
| svg.setAttribute('filter', 'url(#' + stackGlowFilterId + ')');
|
| } else if (!this.isGlowingStack_ && svg.hasAttribute('filter')) {
|
| svg.removeAttribute('filter');
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setErrorStack = function(isGlowingStack) {
|
| this.isGlowingStack_ = isGlowingStack;
|
|
|
| var svg = this.getSvgRoot();
|
| if (this.isGlowingStack_ && !svg.hasAttribute('filter')) {
|
| var stackGlowFilterId = this.workspace.options.stackGlowFilterErrorId || 'blocklyStackGlowFilterError';
|
| svg.setAttribute('filter', 'url(#' + stackGlowFilterId + ')');
|
| } else if (!this.isGlowingStack_ && svg.hasAttribute('filter')) {
|
| svg.removeAttribute('filter');
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.mutator = null;
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.comment = null;
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.warning = null;
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.getIcons = function() {
|
| var icons = [];
|
| if (this.mutator) {
|
| icons.push(this.mutator);
|
| }
|
| if (this.comment) {
|
| icons.push(this.comment);
|
| }
|
| if (this.warning) {
|
| icons.push(this.warning);
|
| }
|
| return icons;
|
| };
|
|
|
| Blockly.BlockSvg.prototype.intersects_ = true;
|
|
|
| Blockly.BlockSvg.prototype.setIntersects = function(intersects) {
|
| if (intersects === this.intersects_) {
|
| return;
|
| }
|
| this.intersects_ = intersects;
|
| var root = this.getSvgRoot();
|
| if (!root) {
|
| return;
|
| }
|
| if (intersects) {
|
| root.style.display = '';
|
| } else {
|
| root.style.display = 'none';
|
| }
|
| };
|
|
|
| Blockly.BlockSvg.prototype.updateIntersectionObserver = function() {
|
| if (this.workspace.intersectionObserver) {
|
| if (this.getParent()) {
|
| this.workspace.intersectionObserver.unobserve(this);
|
| if (!this.intersects_) {
|
| this.setIntersects(true);
|
| }
|
| } else {
|
| this.workspace.intersectionObserver.observe(this);
|
| }
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setParent = function(newParent) {
|
| var oldParent = this.parentBlock_;
|
| if (newParent == oldParent) {
|
| return;
|
| }
|
| Blockly.Field.startCache();
|
| Blockly.BlockSvg.superClass_.setParent.call(this, newParent);
|
| Blockly.Field.stopCache();
|
|
|
| var svgRoot = this.getSvgRoot();
|
|
|
|
|
|
|
| if (this.workspace.isClearing || !svgRoot) {
|
| return;
|
| }
|
|
|
| this.updateIntersectionObserver();
|
|
|
| var oldXY = this.getRelativeToSurfaceXY();
|
| if (newParent) {
|
| newParent.getSvgRoot().appendChild(svgRoot);
|
| var newXY = this.getRelativeToSurfaceXY();
|
|
|
| this.moveConnections_(newXY.x - oldXY.x, newXY.y - oldXY.y);
|
|
|
| if (this.isShadow()) {
|
| this.setColour(this.getColour(), this.getColourSecondary(),
|
| newParent.getColourTertiary());
|
| }
|
| }
|
|
|
|
|
| else if (oldParent) {
|
| this.workspace.getCanvas().appendChild(svgRoot);
|
| this.translate(oldXY.x, oldXY.y);
|
| }
|
|
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() {
|
|
|
|
|
| var x = 0;
|
| var y = 0;
|
|
|
| var dragSurfaceGroup = this.useDragSurface_ ?
|
| this.workspace.blockDragSurface_.getGroup() : null;
|
|
|
| var element = this.getSvgRoot();
|
| if (element) {
|
| do {
|
|
|
| var xy = Blockly.utils.getRelativeXY(element);
|
| x += xy.x;
|
| y += xy.y;
|
|
|
|
|
| if (this.useDragSurface_ &&
|
| this.workspace.blockDragSurface_.getCurrentBlock() == element) {
|
| var surfaceTranslation = this.workspace.blockDragSurface_.getSurfaceTranslation();
|
| x += surfaceTranslation.x;
|
| y += surfaceTranslation.y;
|
| }
|
| element = element.parentNode;
|
| } while (element && element != this.workspace.getCanvas() &&
|
| element != dragSurfaceGroup);
|
| }
|
| return new goog.math.Coordinate(x, y);
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.moveBy = function(dx, dy) {
|
| goog.asserts.assert(!this.parentBlock_, 'Block has parent.');
|
| var eventsEnabled = Blockly.Events.isEnabled();
|
| if (eventsEnabled) {
|
| var event = new Blockly.Events.BlockMove(this);
|
| }
|
| var xy = this.getRelativeToSurfaceXY();
|
| this.translate(xy.x + dx, xy.y + dy);
|
| this.moveConnections_(dx, dy);
|
| if (eventsEnabled) {
|
| event.recordNew();
|
| Blockly.Events.fire(event);
|
| }
|
| this.workspace.resizeContents();
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.translate = function(x, y) {
|
| this.getSvgRoot().setAttribute('transform',
|
| 'translate(' + x + ',' + y + ')');
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.moveToDragSurface_ = function() {
|
| if (!this.useDragSurface_) {
|
| return;
|
| }
|
|
|
|
|
|
|
|
|
| var xy = this.getRelativeToSurfaceXY();
|
| this.clearTransformAttributes_();
|
| this.workspace.blockDragSurface_.translateSurface(xy.x, xy.y);
|
|
|
| this.workspace.blockDragSurface_.setBlocksAndShow(this.getSvgRoot());
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.moveOffDragSurface_ = function(newXY) {
|
| if (!this.useDragSurface_) {
|
| return;
|
| }
|
|
|
| this.translate(newXY.x, newXY.y);
|
| this.workspace.blockDragSurface_.clearAndHide(this.workspace.getCanvas());
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.moveDuringDrag = function(newLoc) {
|
| if (this.useDragSurface_) {
|
| this.workspace.blockDragSurface_.translateSurface(newLoc.x, newLoc.y);
|
| } else {
|
| this.svgGroup_.translate_ = 'translate(' + newLoc.x + ',' + newLoc.y + ')';
|
| this.svgGroup_.setAttribute('transform',
|
| this.svgGroup_.translate_ + this.svgGroup_.skew_);
|
| }
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.clearTransformAttributes_ = function() {
|
| Blockly.utils.removeAttribute(this.getSvgRoot(), 'transform');
|
| };
|
|
|
| |
| |
|
|
| Blockly.BlockSvg.prototype.snapToGrid = function() {
|
| if (!this.workspace) {
|
| return;
|
| }
|
| if (this.workspace.isDragging()) {
|
| return;
|
| }
|
| if (this.getParent()) {
|
| return;
|
| }
|
| if (this.isInFlyout) {
|
| return;
|
| }
|
| var grid = this.workspace.getGrid();
|
| if (!grid || !grid.shouldSnap()) {
|
| return;
|
| }
|
| var spacing = grid.getSpacing();
|
| var half = spacing / 2;
|
| var xy = this.getRelativeToSurfaceXY();
|
| var dx = Math.round((xy.x - half) / spacing) * spacing + half - xy.x;
|
| var dy = Math.round((xy.y - half) / spacing) * spacing + half - xy.y;
|
| dx = Math.round(dx);
|
| dy = Math.round(dy);
|
| if (dx != 0 || dy != 0) {
|
| this.moveBy(dx, dy);
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.getBoundingRectangle = function() {
|
| var blockXY = this.getRelativeToSurfaceXY(this);
|
| var blockBounds = this.getHeightWidth();
|
| var topLeft;
|
| var bottomRight;
|
| if (this.RTL) {
|
| topLeft = new goog.math.Coordinate(blockXY.x - blockBounds.width,
|
| blockXY.y);
|
| bottomRight = new goog.math.Coordinate(blockXY.x,
|
| blockXY.y + blockBounds.height);
|
| } else {
|
| topLeft = new goog.math.Coordinate(blockXY.x, blockXY.y);
|
| bottomRight = new goog.math.Coordinate(blockXY.x + blockBounds.width,
|
| blockXY.y + blockBounds.height);
|
| }
|
|
|
| return {topLeft: topLeft, bottomRight: bottomRight};
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setOpacity = function(opacity) {
|
| this.opacity_ = opacity;
|
| if (this.rendered) {
|
| this.updateColour();
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.getOpacity = function() {
|
| return this.opacity_;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
|
| if (this.collapsed_ == collapsed) {
|
| return;
|
| }
|
| var renderList = [];
|
|
|
| for (var i = 0, input; input = this.inputList[i]; i++) {
|
| renderList.push.apply(renderList, input.setVisible(!collapsed));
|
| }
|
|
|
| var COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT';
|
| if (collapsed) {
|
| var icons = this.getIcons();
|
| for (var i = 0; i < icons.length; i++) {
|
| icons[i].setVisible(false);
|
| }
|
| var text = this.toString(Blockly.COLLAPSE_CHARS);
|
| this.appendDummyInput(COLLAPSED_INPUT_NAME).appendField(text).init();
|
| } else {
|
| this.removeInput(COLLAPSED_INPUT_NAME);
|
|
|
| this.setWarningText(null);
|
| }
|
| Blockly.BlockSvg.superClass_.setCollapsed.call(this, collapsed);
|
|
|
| if (!renderList.length) {
|
|
|
| renderList[0] = this;
|
| }
|
| if (this.rendered) {
|
| for (var i = 0, block; block = renderList[i]; i++) {
|
| block.render();
|
| }
|
|
|
|
|
|
|
|
|
| }
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.tab = function(start, forward) {
|
| var list = this.createTabList_();
|
| var i = list.indexOf(start);
|
| if (i == -1) {
|
|
|
| i = forward ? -1 : list.length;
|
| }
|
| var target = list[forward ? i + 1 : i - 1];
|
| if (!target) {
|
|
|
|
|
| var outputBlock = this.outputConnection && this.outputConnection.targetBlock();
|
| if (outputBlock) {
|
| outputBlock.tab(this, forward);
|
| } else {
|
| var block = forward ? this.getNextBlock() : this.getPreviousBlock();
|
| if (block) {
|
| block.tab(this, forward);
|
| }
|
| }
|
| } else if (target instanceof Blockly.Field) {
|
| target.showEditor_();
|
| } else {
|
| target.tab(null, forward);
|
| }
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.createTabList_ = function() {
|
|
|
| var list = [];
|
| for (var i = 0, input; input = this.inputList[i]; i++) {
|
| for (var j = 0, field; field = input.fieldRow[j]; j++) {
|
| if (field instanceof Blockly.FieldTextInput) {
|
|
|
| list.push(field);
|
| }
|
| }
|
| if (input.connection) {
|
| var block = input.connection.targetBlock();
|
| if (block) {
|
| list.push(block);
|
| }
|
| }
|
| }
|
| return list;
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.onMouseDown_ = function(e) {
|
| if (this.workspace && this.workspace.isDragging()) {
|
| return;
|
| }
|
| var gesture = this.workspace && this.workspace.getGesture(e);
|
| if (gesture) {
|
| gesture.handleBlockStart(e, this);
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.showHelp_ = function() {
|
| var url = goog.isFunction(this.helpUrl) ? this.helpUrl() : this.helpUrl;
|
| if (url) {
|
|
|
| alert(url);
|
| }
|
| };
|
|
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
|
| if (this.workspace.options.readOnly || !this.contextMenu) {
|
| return;
|
| }
|
|
|
| var block = this;
|
| var menuOptions = [];
|
| if (this.isDeletable() && this.isMovable() && !block.isInFlyout) {
|
| menuOptions.push(Blockly.ContextMenu.blockDuplicateOption(block, e));
|
| if (this.isEditable() && this.workspace.options.comments) {
|
| menuOptions.push(Blockly.ContextMenu.blockCommentOption(block));
|
| }
|
|
|
| menuOptions.push(Blockly.ContextMenu.blockDeleteOption(block));
|
| } else if (this.parentBlock_ && this.isShadow_ && this.type !== 'polygon') {
|
| this.parentBlock_.showContextMenu_(e);
|
| return;
|
| }
|
|
|
|
|
| if (this.customContextMenu) {
|
| this.customContextMenu(menuOptions);
|
| }
|
| Blockly.ContextMenu.show(e, menuOptions, this.RTL);
|
| Blockly.ContextMenu.currentBlock = this;
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.moveConnections_ = function(dx, dy) {
|
| if (!this.rendered) {
|
|
|
|
|
| return;
|
| }
|
| var myConnections = this.getConnections_(false);
|
| for (var i = 0; i < myConnections.length; i++) {
|
| myConnections[i].moveBy(dx, dy);
|
| }
|
| var icons = this.getIcons();
|
| for (i = 0; i < icons.length; i++) {
|
| icons[i].computeIconLocation();
|
| }
|
|
|
|
|
| for (i = 0; i < this.childBlocks_.length; i++) {
|
| this.childBlocks_[i].moveConnections_(dx, dy);
|
| }
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setDragging = function(adding) {
|
| if (adding) {
|
| var group = this.getSvgRoot();
|
| group.translate_ = '';
|
| group.skew_ = '';
|
| Blockly.draggingConnections_ =
|
| Blockly.draggingConnections_.concat(this.getConnections_(true));
|
| Blockly.utils.addClass(
|
| (this.svgGroup_), 'blocklyDragging');
|
| } else {
|
| Blockly.draggingConnections_ = [];
|
| Blockly.utils.removeClass(
|
| (this.svgGroup_), 'blocklyDragging');
|
| }
|
|
|
| for (var i = 0; i < this.childBlocks_.length; i++) {
|
| this.childBlocks_[i].setDragging(adding);
|
| }
|
| };
|
|
|
| |
| |
|
|
| Blockly.BlockSvg.prototype.updateMovable = function() {
|
| if (this.isMovable()) {
|
| Blockly.utils.addClass(
|
| (this.svgGroup_), 'blocklyDraggable');
|
| } else {
|
| Blockly.utils.removeClass(
|
| (this.svgGroup_), 'blocklyDraggable');
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setMovable = function(movable) {
|
| Blockly.BlockSvg.superClass_.setMovable.call(this, movable);
|
| this.updateMovable();
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setEditable = function(editable) {
|
| Blockly.BlockSvg.superClass_.setEditable.call(this, editable);
|
| var icons = this.getIcons();
|
| for (var i = 0; i < icons.length; i++) {
|
| icons[i].updateEditable();
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setShadow = function(shadow) {
|
| Blockly.BlockSvg.superClass_.setShadow.call(this, shadow);
|
| this.updateColour();
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setInsertionMarker = function(insertionMarker, opt_minWidth) {
|
| Blockly.BlockSvg.superClass_.setInsertionMarker.call(this, insertionMarker);
|
| this.insertionMarkerMinWidth_ = opt_minWidth;
|
| this.updateColour();
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.getSvgRoot = function() {
|
| return this.svgGroup_;
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
|
| if (!this.workspace) {
|
|
|
| return;
|
| }
|
| Blockly.Tooltip.hide();
|
| Blockly.Field.startCache();
|
|
|
|
|
| var blockWorkspace = this.workspace;
|
|
|
| if (Blockly.selected == this) {
|
| this.unselect();
|
| this.workspace.cancelCurrentGesture();
|
| }
|
|
|
| if (Blockly.ContextMenu.currentBlock == this) {
|
| Blockly.ContextMenu.hide();
|
| }
|
|
|
| if (animate && this.rendered) {
|
| this.unplug(healStack);
|
| Blockly.BlockAnimations.disposeUiEffect(this);
|
| }
|
|
|
| this.rendered = false;
|
|
|
| Blockly.Events.disable();
|
| try {
|
| var icons = this.getIcons();
|
| for (var i = 0; i < icons.length; i++) {
|
| icons[i].dispose();
|
| }
|
| } finally {
|
| Blockly.Events.enable();
|
| }
|
| Blockly.BlockSvg.superClass_.dispose.call(this, healStack);
|
|
|
| if (blockWorkspace.intersectionObserver) {
|
| blockWorkspace.intersectionObserver.unobserve(this);
|
| }
|
| goog.dom.removeNode(this.svgGroup_);
|
| blockWorkspace.resizeContents();
|
|
|
| this.svgGroup_ = null;
|
| this.svgPath_ = null;
|
| Blockly.Field.stopCache();
|
| };
|
|
|
| |
| |
|
|
| Blockly.BlockSvg.prototype.updateDisabled = function() {
|
|
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.getCommentText = function() {
|
| if (this.comment) {
|
| var comment = this.comment.getText();
|
|
|
| return comment.replace(/\s+$/, '').replace(/ +\n/g, '\n');
|
| }
|
| return '';
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setCommentText = function(text, commentId,
|
| commentX, commentY, minimized) {
|
| var changedState = false;
|
| if (goog.isString(text)) {
|
| if (!this.comment) {
|
| this.comment = new Blockly.ScratchBlockComment(this, text, commentId,
|
| commentX, commentY, minimized);
|
| changedState = true;
|
| } else {
|
| this.comment.setText( (text));
|
| }
|
| } else {
|
| if (this.comment) {
|
| this.comment.dispose();
|
| changedState = true;
|
| }
|
| }
|
| if (changedState && this.rendered) {
|
| this.render();
|
| if (goog.isString(text)) {
|
| this.comment.setVisible(true);
|
| }
|
|
|
| this.bumpNeighbours_();
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
|
| if (!this.setWarningText.pid_) {
|
|
|
|
|
| this.setWarningText.pid_ = Object.create(null);
|
| }
|
| var id = opt_id || '';
|
| if (!id) {
|
|
|
| for (var n in this.setWarningText.pid_) {
|
| clearTimeout(this.setWarningText.pid_[n]);
|
| delete this.setWarningText.pid_[n];
|
| }
|
| } else if (this.setWarningText.pid_[id]) {
|
|
|
| clearTimeout(this.setWarningText.pid_[id]);
|
| delete this.setWarningText.pid_[id];
|
| }
|
| if (this.workspace.isDragging()) {
|
|
|
|
|
| var thisBlock = this;
|
| this.setWarningText.pid_[id] = setTimeout(function() {
|
| if (thisBlock.workspace) {
|
| delete thisBlock.setWarningText.pid_[id];
|
| thisBlock.setWarningText(text, id);
|
| }
|
| }, 100);
|
| return;
|
| }
|
| if (this.isInFlyout) {
|
| text = null;
|
| }
|
|
|
| var changedState = false;
|
| if (goog.isString(text)) {
|
| if (!this.warning) {
|
| this.warning = new Blockly.Warning(this);
|
| changedState = true;
|
| }
|
| this.warning.setText( (text), id);
|
| } else {
|
|
|
| if (this.warning && !id) {
|
| this.warning.dispose();
|
| changedState = true;
|
| } else if (this.warning) {
|
| var oldText = this.warning.getText();
|
| this.warning.setText('', id);
|
| var newText = this.warning.getText();
|
| if (!newText) {
|
| this.warning.dispose();
|
| }
|
| changedState = oldText != newText;
|
| }
|
| }
|
| if (changedState && this.rendered) {
|
| this.render();
|
|
|
| this.bumpNeighbours_();
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setMutator = function(mutator) {
|
| if (this.mutator && this.mutator !== mutator) {
|
| this.mutator.dispose();
|
| }
|
| if (mutator) {
|
| mutator.block_ = this;
|
| this.mutator = mutator;
|
| mutator.createIcon();
|
| }
|
| };
|
|
|
| |
| |
|
|
| Blockly.BlockSvg.prototype.addSelect = function() {
|
| Blockly.utils.addClass(
|
| (this.svgGroup_), 'blocklySelected');
|
| };
|
|
|
| |
| |
|
|
| Blockly.BlockSvg.prototype.removeSelect = function() {
|
| Blockly.utils.removeClass(
|
| (this.svgGroup_), 'blocklySelected');
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setMouseThroughStyle = function(letMouseThrough) {
|
| if (letMouseThrough) {
|
| Blockly.utils.addClass( (this.svgGroup_),
|
| 'blocklyDraggingMouseThrough');
|
| } else {
|
| Blockly.utils.removeClass( (this.svgGroup_),
|
| 'blocklyDraggingMouseThrough');
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setDeleteStyle = function(enable) {
|
| if (enable) {
|
| Blockly.utils.addClass( (this.svgGroup_),
|
| 'blocklyDraggingDelete');
|
| } else {
|
| Blockly.utils.removeClass( (this.svgGroup_),
|
| 'blocklyDraggingDelete');
|
| }
|
| };
|
|
|
|
|
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setColour = function(colour, colourSecondary,
|
| colourTertiary) {
|
| Blockly.BlockSvg.superClass_.setColour.call(this, colour, colourSecondary,
|
| colourTertiary);
|
|
|
| if (this.rendered) {
|
| this.updateColour();
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.bringToFront = function() {
|
| var block = this;
|
| do {
|
| var root = block.getSvgRoot();
|
| root.parentNode.appendChild(root);
|
| block = block.getParent();
|
| } while (block);
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setPreviousStatement = function(newBoolean,
|
| opt_check) {
|
| Blockly.BlockSvg.superClass_.setPreviousStatement.call(this, newBoolean,
|
| opt_check);
|
|
|
| if (this.rendered) {
|
| this.render();
|
| this.bumpNeighbours_();
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setNextStatement = function(newBoolean, opt_check) {
|
| Blockly.BlockSvg.superClass_.setNextStatement.call(this, newBoolean,
|
| opt_check);
|
|
|
| if (this.rendered) {
|
| this.render();
|
| this.bumpNeighbours_();
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setOutput = function(newBoolean, opt_check) {
|
| Blockly.BlockSvg.superClass_.setOutput.call(this, newBoolean, opt_check);
|
|
|
| if (this.rendered) {
|
| this.render();
|
| this.bumpNeighbours_();
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.setInputsInline = function(newBoolean) {
|
| Blockly.BlockSvg.superClass_.setInputsInline.call(this, newBoolean);
|
|
|
| if (this.rendered) {
|
| this.render();
|
| this.bumpNeighbours_();
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.removeInput = function(name, opt_quiet) {
|
| Blockly.BlockSvg.superClass_.removeInput.call(this, name, opt_quiet);
|
|
|
| if (this.rendered) {
|
| this.render();
|
|
|
| this.bumpNeighbours_();
|
| }
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.moveNumberedInputBefore = function(
|
| inputIndex, refIndex) {
|
| Blockly.BlockSvg.superClass_.moveNumberedInputBefore.call(this, inputIndex,
|
| refIndex);
|
|
|
| if (this.rendered) {
|
| this.render();
|
|
|
| this.bumpNeighbours_();
|
| }
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.appendInput_ = function(type, name) {
|
| var input = Blockly.BlockSvg.superClass_.appendInput_.call(this, type, name);
|
|
|
| if (this.rendered) {
|
| this.render();
|
|
|
| this.bumpNeighbours_();
|
| }
|
| return input;
|
| };
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.getConnections_ = function(all) {
|
| var myConnections = [];
|
| if (all || this.rendered) {
|
| if (this.outputConnection) {
|
| myConnections.push(this.outputConnection);
|
| }
|
| if (this.previousConnection) {
|
| myConnections.push(this.previousConnection);
|
| }
|
| if (this.nextConnection) {
|
| myConnections.push(this.nextConnection);
|
| }
|
| if (all || !this.collapsed_) {
|
| for (var i = 0, input; input = this.inputList[i]; i++) {
|
| if (input.connection) {
|
| myConnections.push(input.connection);
|
| }
|
| }
|
| }
|
| }
|
| return myConnections;
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.makeConnection_ = function(type) {
|
| return new Blockly.RenderedConnection(this, type);
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.bumpNeighbours_ = function() {
|
| if (!this.workspace) {
|
| return;
|
| }
|
| if (this.workspace.isDragging()) {
|
| return;
|
| }
|
| var rootBlock = this.getRootBlock();
|
| if (rootBlock.isInFlyout) {
|
| return;
|
| }
|
|
|
| var myConnections = this.getConnections_(false);
|
| for (var i = 0, connection; connection = myConnections[i]; i++) {
|
|
|
|
|
| if (connection.isConnected() && connection.isSuperior()) {
|
| connection.targetBlock().bumpNeighbours_();
|
| }
|
|
|
| var neighbours = connection.neighbours_(Blockly.SNAP_RADIUS);
|
| for (var j = 0, otherConnection; otherConnection = neighbours[j]; j++) {
|
|
|
|
|
|
|
| if (!connection.isConnected() || !otherConnection.isConnected()) {
|
|
|
| if (otherConnection.getSourceBlock().getRootBlock() != rootBlock) {
|
|
|
|
|
| if (connection.isSuperior()) {
|
| otherConnection.bumpAwayFrom_(connection);
|
| } else {
|
| connection.bumpAwayFrom_(otherConnection);
|
| }
|
| }
|
| }
|
| }
|
| }
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.BlockSvg.prototype.scheduleSnapAndBump = function() {
|
| var block = this;
|
|
|
| var group = Blockly.Events.getGroup();
|
|
|
| setTimeout(function() {
|
| Blockly.Events.setGroup(group);
|
| block.snapToGrid();
|
| Blockly.Events.setGroup(false);
|
| }, Blockly.BUMP_DELAY / 2);
|
|
|
| setTimeout(function() {
|
| Blockly.Events.setGroup(group);
|
| block.bumpNeighbours_();
|
| Blockly.Events.setGroup(false);
|
| }, Blockly.BUMP_DELAY);
|
| };
|
|
|