mirror of
https://github.com/google/blockly.git
synced 2026-03-12 00:00:12 +01:00
Line wrap at 80.
This commit is contained in:
@@ -854,7 +854,7 @@ Blockly.Block.prototype.setColour = function(colour) {
|
||||
*/
|
||||
Blockly.Block.prototype.setOnChange = function(onchangeFn) {
|
||||
if (onchangeFn && typeof onchangeFn != 'function') {
|
||||
throw new Error('onchange must be a function.');
|
||||
throw Error('onchange must be a function.');
|
||||
}
|
||||
if (this.onchangeWrapper_) {
|
||||
this.workspace.removeChangeListener(this.onchangeWrapper_);
|
||||
@@ -1339,7 +1339,7 @@ Blockly.Block.prototype.jsonInitColour_ = function(json, warningPrefix) {
|
||||
*/
|
||||
Blockly.Block.prototype.mixin = function(mixinObj, opt_disableCheck) {
|
||||
if (opt_disableCheck !== undefined && typeof opt_disableCheck != 'boolean') {
|
||||
throw new Error('opt_disableCheck must be a boolean if provided');
|
||||
throw Error('opt_disableCheck must be a boolean if provided');
|
||||
}
|
||||
if (!opt_disableCheck) {
|
||||
var overwrites = [];
|
||||
@@ -1349,7 +1349,7 @@ Blockly.Block.prototype.mixin = function(mixinObj, opt_disableCheck) {
|
||||
}
|
||||
}
|
||||
if (overwrites.length) {
|
||||
throw new Error('Mixin will overwrite block members: ' +
|
||||
throw Error('Mixin will overwrite block members: ' +
|
||||
JSON.stringify(overwrites));
|
||||
}
|
||||
}
|
||||
@@ -1375,11 +1375,11 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
|
||||
var token = tokens[i];
|
||||
if (typeof token == 'number') {
|
||||
if (token <= 0 || token > args.length) {
|
||||
throw new Error('Block "' + this.type + '": ' +
|
||||
throw Error('Block "' + this.type + '": ' +
|
||||
'Message index %' + token + ' out of range.');
|
||||
}
|
||||
if (indexDup[token]) {
|
||||
throw new Error('Block "' + this.type + '": ' +
|
||||
throw Error('Block "' + this.type + '": ' +
|
||||
'Message index %' + token + ' duplicated.');
|
||||
}
|
||||
indexDup[token] = true;
|
||||
@@ -1393,7 +1393,7 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
|
||||
}
|
||||
}
|
||||
if (indexCount != args.length) {
|
||||
throw new Error('Block "' + this.type + '": ' +
|
||||
throw Error('Block "' + this.type + '": ' +
|
||||
'Message does not reference all ' + args.length + ' arg(s).');
|
||||
}
|
||||
// Add last dummy input if needed.
|
||||
|
||||
@@ -128,7 +128,8 @@ Blockly.BlockDragSurfaceSvg.prototype.setBlocksAndShow = function(blocks) {
|
||||
* @param {number} y Y translation in workspace coordinates.
|
||||
* @param {number} scale Scale of the group.
|
||||
*/
|
||||
Blockly.BlockDragSurfaceSvg.prototype.translateAndScaleGroup = function(x, y, scale) {
|
||||
Blockly.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.
|
||||
|
||||
@@ -144,17 +144,20 @@ Blockly.BlockDragger.initIconData_ = function(block) {
|
||||
* Start dragging a block. This includes moving it to the drag surface.
|
||||
* @param {!goog.math.Coordinate} currentDragDeltaXY How far the pointer has
|
||||
* moved from the position at mouse down, in pixel units.
|
||||
* @param {boolean} healStack whether or not to heal the stack after disconnecting
|
||||
* @param {boolean} healStack Whether or not to heal the stack after
|
||||
* disconnecting.
|
||||
* @package
|
||||
*/
|
||||
Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY, healStack) {
|
||||
Blockly.BlockDragger.prototype.startBlockDrag = function(currentDragDeltaXY,
|
||||
healStack) {
|
||||
if (!Blockly.Events.getGroup()) {
|
||||
Blockly.Events.setGroup(true);
|
||||
}
|
||||
|
||||
// Mutators don't have the same type of z-ordering as the normal workspace during a drag.
|
||||
// They have to rely on the order of the blocks in the svg. For performance reasons that
|
||||
// usually happens at the end of a drag, but do it at the beginning for mutators.
|
||||
// Mutators don't have the same type of z-ordering as the normal workspace
|
||||
// during a drag. They have to rely on the order of the blocks in the SVG.
|
||||
// For performance reasons that usually happens at the end of a drag,
|
||||
// but do it at the beginning for mutators.
|
||||
if (this.workspace_.isMutator) {
|
||||
this.draggingBlock_.bringToFront();
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
|
||||
* @type {SVGElement}
|
||||
* @private
|
||||
*/
|
||||
this.svgPath_ = Blockly.utils.createSvgElement('path', {'class': 'blocklyPath'},
|
||||
this.svgGroup_);
|
||||
this.svgPath_ = Blockly.utils.createSvgElement('path',
|
||||
{'class': 'blocklyPath'}, this.svgGroup_);
|
||||
|
||||
/**
|
||||
* @type {SVGElement}
|
||||
@@ -93,7 +93,8 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.useDragSurface_ = Blockly.utils.is3dSupported() && !!workspace.blockDragSurface_;
|
||||
this.useDragSurface_ =
|
||||
Blockly.utils.is3dSupported() && !!workspace.blockDragSurface_;
|
||||
|
||||
Blockly.Tooltip.bindMouseEvents(this.svgPath_);
|
||||
Blockly.BlockSvg.superClass_.constructor.call(this,
|
||||
@@ -311,7 +312,8 @@ Blockly.BlockSvg.prototype.getRelativeToSurfaceXY = function() {
|
||||
// the translation of the drag surface itself.
|
||||
if (this.useDragSurface_ &&
|
||||
this.workspace.blockDragSurface_.getCurrentBlock() == element) {
|
||||
var surfaceTranslation = this.workspace.blockDragSurface_.getSurfaceTranslation();
|
||||
var surfaceTranslation =
|
||||
this.workspace.blockDragSurface_.getSurfaceTranslation();
|
||||
x += surfaceTranslation.x;
|
||||
y += surfaceTranslation.y;
|
||||
}
|
||||
|
||||
@@ -168,15 +168,17 @@ Blockly.svgResize = function(workspace) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle a key-down on SVG drawing surface. Does nothing if the main workspace is not visible.
|
||||
* Handle a key-down on SVG drawing surface. Does nothing if the main workspace
|
||||
* is not visible.
|
||||
* @param {!Event} e Key down event.
|
||||
* @private
|
||||
*/
|
||||
// TODO (https://github.com/google/blockly/issues/1998) handle cases where there are
|
||||
// multiple workspaces and non-main workspaces are able to accept input.
|
||||
// TODO (https://github.com/google/blockly/issues/1998) handle cases where there
|
||||
// are multiple workspaces and non-main workspaces are able to accept input.
|
||||
Blockly.onKeyDown_ = function(e) {
|
||||
if (Blockly.mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e)
|
||||
|| (Blockly.mainWorkspace.rendered && !Blockly.mainWorkspace.isVisible())) {
|
||||
var workspace = Blockly.mainWorkspace;
|
||||
if (workspace.options.readOnly || Blockly.utils.isTargetInput(e)
|
||||
|| (workspace.rendered && !workspace.isVisible())) {
|
||||
// No key actions on readonly workspaces.
|
||||
// When focused on an HTML text input widget, don't trap any keys.
|
||||
// Ignore keypresses on rendered workspaces that have been explicitly
|
||||
@@ -194,7 +196,7 @@ Blockly.onKeyDown_ = function(e) {
|
||||
// data loss.
|
||||
e.preventDefault();
|
||||
// Don't delete while dragging. Jeez.
|
||||
if (Blockly.mainWorkspace.isDragging()) {
|
||||
if (workspace.isDragging()) {
|
||||
return;
|
||||
}
|
||||
if (Blockly.selected && Blockly.selected.isDeletable()) {
|
||||
@@ -202,7 +204,7 @@ Blockly.onKeyDown_ = function(e) {
|
||||
}
|
||||
} else if (e.altKey || e.ctrlKey || e.metaKey) {
|
||||
// Don't use meta keys during drags.
|
||||
if (Blockly.mainWorkspace.isDragging()) {
|
||||
if (workspace.isDragging()) {
|
||||
return;
|
||||
}
|
||||
if (Blockly.selected &&
|
||||
@@ -225,8 +227,8 @@ Blockly.onKeyDown_ = function(e) {
|
||||
// 'v' for paste.
|
||||
if (Blockly.clipboardXml_) {
|
||||
Blockly.Events.setGroup(true);
|
||||
// Pasting always pastes to the main workspace, even if the copy started
|
||||
// in a flyout workspace.
|
||||
// Pasting always pastes to the main workspace, even if the copy
|
||||
// started in a flyout workspace.
|
||||
var workspace = Blockly.clipboardSource_;
|
||||
if (workspace.isFlyout) {
|
||||
workspace = workspace.targetWorkspace;
|
||||
@@ -237,7 +239,7 @@ Blockly.onKeyDown_ = function(e) {
|
||||
} else if (e.keyCode == 90) {
|
||||
// 'z' for undo 'Z' is for redo.
|
||||
Blockly.hideChaff();
|
||||
Blockly.mainWorkspace.undo(e.shiftKey);
|
||||
workspace.undo(e.shiftKey);
|
||||
}
|
||||
}
|
||||
// Common code for delete and cut.
|
||||
@@ -252,8 +254,8 @@ Blockly.onKeyDown_ = function(e) {
|
||||
|
||||
/**
|
||||
* Copy a block or workspace comment onto the local clipboard.
|
||||
* @param {!Blockly.Block | !Blockly.WorkspaceComment} toCopy Block or Workspace Comment
|
||||
* to be copied.
|
||||
* @param {!Blockly.Block | !Blockly.WorkspaceComment} toCopy Block or
|
||||
* Workspace Comment to be copied.
|
||||
* @private
|
||||
*/
|
||||
Blockly.copy_ = function(toCopy) {
|
||||
@@ -437,8 +439,8 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) {
|
||||
* @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.
|
||||
* should not block execution of other event handlers on this touch or
|
||||
* other simultaneous touches.
|
||||
* @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
|
||||
|
||||
@@ -124,7 +124,8 @@ Blockly.Comment.prototype.createEditor_ = function() {
|
||||
body.appendChild(textarea);
|
||||
this.textarea_ = textarea;
|
||||
this.foreignObject_.appendChild(body);
|
||||
Blockly.bindEventWithChecks_(textarea, 'mouseup', this, this.textareaFocus_, true, true);
|
||||
Blockly.bindEventWithChecks_(textarea, 'mouseup', this, this.textareaFocus_,
|
||||
true, true);
|
||||
// Don't zoom with mousewheel.
|
||||
Blockly.bindEventWithChecks_(textarea, 'wheel', this, function(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
23
core/css.js
23
core/css.js
@@ -769,14 +769,14 @@ Blockly.Css.CONTENT = [
|
||||
* NOTE(mleibman,chrishenry):
|
||||
* The RTL support in Closure is provided via two mechanisms -- "rtl" CSS
|
||||
* classes and BiDi flipping done by the CSS compiler. Closure supports RTL
|
||||
* with or without the use of the CSS compiler. In order for them not
|
||||
* to conflict with each other, the "rtl" CSS classes need to have the #noflip
|
||||
* annotation. The non-rtl counterparts should ideally have them as well, but,
|
||||
* since .goog-menuitem existed without .goog-menuitem-rtl for so long before
|
||||
* being added, there is a risk of people having templates where they are not
|
||||
* rendering the .goog-menuitem-rtl class when in RTL and instead rely solely
|
||||
* on the BiDi flipping by the CSS compiler. That's why we're not adding the
|
||||
* #noflip to .goog-menuitem.
|
||||
* with or without the use of the CSS compiler. In order for them not to
|
||||
* conflict with each other, the "rtl" CSS classes need to have the #noflip
|
||||
* annotation. The non-rtl counterparts should ideally have them as well,
|
||||
* but, since .goog-menuitem existed without .goog-menuitem-rtl for so long
|
||||
* before being added, there is a risk of people having templates where they
|
||||
* are not rendering the .goog-menuitem-rtl class when in RTL and instead
|
||||
* rely solely on the BiDi flipping by the CSS compiler. That's why we're
|
||||
* not adding the #noflip to .goog-menuitem.
|
||||
*/
|
||||
'.blocklyWidgetDiv .goog-menuitem {',
|
||||
'color: #000;',
|
||||
@@ -796,14 +796,15 @@ Blockly.Css.CONTENT = [
|
||||
'padding-right: 28px;',
|
||||
'}',
|
||||
|
||||
/* If a menu doesn't have checkable items or items with icons, remove padding. */
|
||||
/* If a menu doesn't have checkable items or items with icons,
|
||||
* remove padding.
|
||||
*/
|
||||
'.blocklyWidgetDiv .goog-menu-nocheckbox .goog-menuitem,',
|
||||
'.blocklyWidgetDiv .goog-menu-noicon .goog-menuitem {',
|
||||
'padding-left: 12px;',
|
||||
'}',
|
||||
|
||||
/*
|
||||
* If a menu doesn't have items with shortcuts, leave just enough room for
|
||||
/* If a menu doesn't have items with shortcuts, leave just enough room for
|
||||
* submenu arrows, if they are rendered.
|
||||
*/
|
||||
'.blocklyWidgetDiv .goog-menu-noaccel .goog-menuitem {',
|
||||
|
||||
@@ -60,8 +60,8 @@ Blockly.DraggedConnectionManager = function(block) {
|
||||
|
||||
/**
|
||||
* The connections on the dragging blocks that are available to connect to
|
||||
* other blocks. This includes all open connections on the top block, as well
|
||||
* as the last connection on the block stack.
|
||||
* other blocks. This includes all open connections on the top block,
|
||||
* as well as the last connection on the block stack.
|
||||
* Does not change during a drag.
|
||||
* @type {!Array.<!Blockly.RenderedConnection>}
|
||||
* @private
|
||||
@@ -128,7 +128,8 @@ Blockly.DraggedConnectionManager.prototype.wouldDeleteBlock = function() {
|
||||
/**
|
||||
* Return whether the block would be connected if dropped immediately, based on
|
||||
* information from the most recent move event.
|
||||
* @return {boolean} true if the block would be connected if dropped immediately.
|
||||
* @return {boolean} true if the block would be connected if dropped
|
||||
* immediately.
|
||||
* @package
|
||||
*/
|
||||
Blockly.DraggedConnectionManager.prototype.wouldConnectBlock = function() {
|
||||
|
||||
@@ -232,7 +232,8 @@ Blockly.Events.filter = function(queueIn, forward) {
|
||||
// Merge click events.
|
||||
lastEvent.newValue = event.newValue;
|
||||
} else {
|
||||
// Collision: newer events should merge into this event to maintain order
|
||||
// Collision: newer events should merge into this event to maintain
|
||||
// order.
|
||||
hash[key] = { event: event, index: 1};
|
||||
mergedQueue.push(event);
|
||||
}
|
||||
|
||||
@@ -54,13 +54,13 @@ Blockly.Extensions.ALL_ = {};
|
||||
*/
|
||||
Blockly.Extensions.register = function(name, initFn) {
|
||||
if ((typeof name != 'string') || (name.trim() == '')) {
|
||||
throw new Error('Error: Invalid extension name "' + name + '"');
|
||||
throw Error('Error: Invalid extension name "' + name + '"');
|
||||
}
|
||||
if (Blockly.Extensions.ALL_[name]) {
|
||||
throw new Error('Error: Extension "' + name + '" is already registered.');
|
||||
throw Error('Error: Extension "' + name + '" is already registered.');
|
||||
}
|
||||
if (typeof initFn != 'function') {
|
||||
throw new Error('Error: Extension "' + name + '" must be a function');
|
||||
throw Error('Error: Extension "' + name + '" must be a function');
|
||||
}
|
||||
Blockly.Extensions.ALL_[name] = initFn;
|
||||
};
|
||||
@@ -74,7 +74,7 @@ Blockly.Extensions.register = function(name, initFn) {
|
||||
*/
|
||||
Blockly.Extensions.registerMixin = function(name, mixinObj) {
|
||||
if (!mixinObj || typeof mixinObj != 'object'){
|
||||
throw new Error('Error: Mixin "' + name + '" must be a object');
|
||||
throw Error('Error: Mixin "' + name + '" must be a object');
|
||||
}
|
||||
Blockly.Extensions.register(name, function() {
|
||||
this.mixin(mixinObj);
|
||||
@@ -108,7 +108,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn,
|
||||
Blockly.Extensions.checkMutatorDialog_(mixinObj, errorPrefix);
|
||||
|
||||
if (opt_helperFn && (typeof opt_helperFn != 'function')) {
|
||||
throw new Error('Extension "' + name + '" is not a function');
|
||||
throw Error('Extension "' + name + '" is not a function');
|
||||
}
|
||||
|
||||
// Sanity checks passed.
|
||||
@@ -136,7 +136,7 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn,
|
||||
Blockly.Extensions.apply = function(name, block, isMutator) {
|
||||
var extensionFn = Blockly.Extensions.ALL_[name];
|
||||
if (typeof extensionFn != 'function') {
|
||||
throw new Error('Error: Extension "' + name + '" not found.');
|
||||
throw Error('Error: Extension "' + name + '" not found.');
|
||||
}
|
||||
if (isMutator) {
|
||||
// Fail early if the block already has mutation properties.
|
||||
@@ -153,7 +153,7 @@ Blockly.Extensions.apply = function(name, block, isMutator) {
|
||||
Blockly.Extensions.checkBlockHasMutatorProperties_(errorPrefix, block);
|
||||
} else {
|
||||
if (!Blockly.Extensions.mutatorPropertiesMatch_(mutatorProperties, block)) {
|
||||
throw new Error('Error when applying extension "' + name + '": ' +
|
||||
throw Error('Error when applying extension "' + name + '": ' +
|
||||
'mutation properties changed when applying a non-mutator extension.');
|
||||
}
|
||||
}
|
||||
@@ -170,10 +170,10 @@ Blockly.Extensions.apply = function(name, block, isMutator) {
|
||||
Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func,
|
||||
propertyName) {
|
||||
if (!func) {
|
||||
throw new Error(errorPrefix +
|
||||
throw Error(errorPrefix +
|
||||
'missing required property "' + propertyName + '"');
|
||||
} else if (typeof func != 'function') {
|
||||
throw new Error(errorPrefix +
|
||||
throw Error(errorPrefix +
|
||||
'" required property "' + propertyName + '" must be a function');
|
||||
}
|
||||
};
|
||||
@@ -191,7 +191,7 @@ Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func,
|
||||
Blockly.Extensions.checkNoMutatorProperties_ = function(mutationName, block) {
|
||||
var properties = Blockly.Extensions.getMutatorProperties_(block);
|
||||
if (properties.length) {
|
||||
throw new Error('Error: tried to apply mutation "' + mutationName +
|
||||
throw Error('Error: tried to apply mutation "' + mutationName +
|
||||
'" to a block that already has mutator functions.' +
|
||||
' Block id: ' + block.id);
|
||||
}
|
||||
@@ -215,15 +215,15 @@ Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) {
|
||||
|
||||
if (hasCompose && hasDecompose) {
|
||||
if (typeof object.compose != 'function') {
|
||||
throw new Error(errorPrefix + 'compose must be a function.');
|
||||
throw Error(errorPrefix + 'compose must be a function.');
|
||||
} else if (typeof object.decompose != 'function') {
|
||||
throw new Error(errorPrefix + 'decompose must be a function.');
|
||||
throw Error(errorPrefix + 'decompose must be a function.');
|
||||
}
|
||||
return true;
|
||||
} else if (!hasCompose && !hasDecompose) {
|
||||
return false;
|
||||
} else {
|
||||
throw new Error(errorPrefix +
|
||||
throw Error(errorPrefix +
|
||||
'Must have both or neither of "compose" and "decompose"');
|
||||
}
|
||||
};
|
||||
@@ -238,12 +238,10 @@ Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) {
|
||||
Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix,
|
||||
block) {
|
||||
if (typeof block.domToMutation != 'function') {
|
||||
throw new Error(errorPrefix +
|
||||
'Applying a mutator didn\'t add "domToMutation"');
|
||||
throw Error(errorPrefix + 'Applying a mutator didn\'t add "domToMutation"');
|
||||
}
|
||||
if (typeof block.mutationToDom != 'function') {
|
||||
throw new Error(errorPrefix +
|
||||
'Applying a mutator didn\'t add "mutationToDom"');
|
||||
throw Error(errorPrefix + 'Applying a mutator didn\'t add "mutationToDom"');
|
||||
}
|
||||
|
||||
// A block with a mutator isn't required to have a mutation dialog, but
|
||||
|
||||
@@ -69,11 +69,10 @@ Blockly.Field.TYPE_MAP_ = {};
|
||||
*/
|
||||
Blockly.Field.register = function(type, fieldClass) {
|
||||
if ((typeof type != 'string') || (type.trim() == '')) {
|
||||
throw new Error('Invalid field type "' + type + '"');
|
||||
throw Error('Invalid field type "' + type + '"');
|
||||
}
|
||||
if (!fieldClass || (typeof fieldClass.fromJson != 'function')) {
|
||||
throw new Error('Field "' + fieldClass +
|
||||
'" must have a fromJson function');
|
||||
throw Error('Field "' + fieldClass + '" must have a fromJson function');
|
||||
}
|
||||
Blockly.Field.TYPE_MAP_[type] = fieldClass;
|
||||
};
|
||||
|
||||
@@ -343,7 +343,8 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() {
|
||||
* @param {number} suffixLength The length of the common suffix
|
||||
* @return {!Array.<!Array>} A new array with all of the option text trimmed.
|
||||
*/
|
||||
Blockly.FieldDropdown.applyTrim_ = function(options, prefixLength, suffixLength) {
|
||||
Blockly.FieldDropdown.applyTrim_ = function(options,
|
||||
prefixLength, suffixLength) {
|
||||
var newOptions = [];
|
||||
// Remove the prefix and suffix from the options.
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
@@ -515,7 +516,8 @@ Blockly.FieldDropdown.prototype.updateWidth = function() {
|
||||
if (this.imageJson_ && (goog.userAgent.IE || goog.userAgent.EDGE)) {
|
||||
// Recalculate the full width.
|
||||
var arrowWidth = Blockly.Field.getCachedWidth(this.arrow_);
|
||||
var width = Number(this.imageJson_.width) + arrowWidth + Blockly.BlockSvg.SEP_SPACE_X;
|
||||
var width = Number(this.imageJson_.width) + arrowWidth +
|
||||
Blockly.BlockSvg.SEP_SPACE_X;
|
||||
if (this.borderRect_) {
|
||||
this.borderRect_.setAttribute('width', width);
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ goog.require('Blockly.FieldTextInput');
|
||||
|
||||
/**
|
||||
* Class for an editable number field.
|
||||
* @param {(string|number)=} opt_value The initial content of the field. The value
|
||||
* should cast to a number, and if it does not, '0' will be used.
|
||||
* @param {(string|number)=} opt_value The initial content of the field.
|
||||
* The value should cast to a number, and if it does not, '0' will be used.
|
||||
* @param {(string|number)=} opt_min Minimum value.
|
||||
* @param {(string|number)=} opt_max Maximum value.
|
||||
* @param {(string|number)=} opt_precision Precision for value.
|
||||
|
||||
@@ -178,14 +178,12 @@ Blockly.FieldVariable.prototype.setValue = function(id) {
|
||||
var variable = Blockly.Variables.getVariable(workspace, id);
|
||||
|
||||
if (!variable) {
|
||||
throw new Error('Variable id doesn\'t point to a real variable! ID was ' +
|
||||
id);
|
||||
throw Error('Variable id doesn\'t point to a real variable! ID was ' + id);
|
||||
}
|
||||
// Type checks!
|
||||
var type = variable.type;
|
||||
if (!this.typeIsAllowed_(type)) {
|
||||
throw new Error('Variable type doesn\'t match this field! Type was ' +
|
||||
type);
|
||||
throw Error('Variable type doesn\'t match this field! Type was ' + type);
|
||||
}
|
||||
if (this.sourceBlock_ && Blockly.Events.isEnabled()) {
|
||||
var oldValue = this.variable_ ? this.variable_.getId() : null;
|
||||
@@ -236,7 +234,7 @@ Blockly.FieldVariable.prototype.getVariableTypes_ = function() {
|
||||
if (variableTypes.length == 0) {
|
||||
// Throw an error if variableTypes is an empty list.
|
||||
var name = this.getText();
|
||||
throw new Error('\'variableTypes\' of field variable ' +
|
||||
throw Error('\'variableTypes\' of field variable ' +
|
||||
name + ' was an empty list');
|
||||
}
|
||||
return variableTypes;
|
||||
@@ -270,11 +268,11 @@ Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes,
|
||||
}
|
||||
}
|
||||
if (!isInArray) {
|
||||
throw new Error('Invalid default type \'' + defaultType + '\' in ' +
|
||||
throw Error('Invalid default type \'' + defaultType + '\' in ' +
|
||||
'the definition of a FieldVariable');
|
||||
}
|
||||
} else {
|
||||
throw new Error('\'variableTypes\' was not an array in the definition of ' +
|
||||
throw Error('\'variableTypes\' was not an array in the definition of ' +
|
||||
'a FieldVariable');
|
||||
}
|
||||
// Only update the field once all checks pass.
|
||||
@@ -290,7 +288,7 @@ Blockly.FieldVariable.prototype.setTypes_ = function(opt_variableTypes,
|
||||
*/
|
||||
Blockly.FieldVariable.dropdownCreate = function() {
|
||||
if (!this.variable_) {
|
||||
throw new Error('Tried to call dropdownCreate on a variable field with no' +
|
||||
throw Error('Tried to call dropdownCreate on a variable field with no' +
|
||||
' variable selected.');
|
||||
}
|
||||
var name = this.getText();
|
||||
|
||||
@@ -427,7 +427,8 @@ Blockly.Flyout.prototype.show = function(xmlList) {
|
||||
var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback(
|
||||
xmlList);
|
||||
if (typeof fnToApply != 'function') {
|
||||
throw TypeError('Couldn\'t find a callback function when opening a toolbox category.');
|
||||
throw TypeError('Couldn\'t find a callback function when opening' +
|
||||
' a toolbox category.');
|
||||
}
|
||||
xmlList = fnToApply(this.workspace_.targetWorkspace);
|
||||
if (!Array.isArray(xmlList)) {
|
||||
|
||||
@@ -385,8 +385,8 @@ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() {
|
||||
// With the flyoutWidth known, right-align the buttons.
|
||||
for (var i = 0, button; button = this.buttons_[i]; i++) {
|
||||
var y = button.getPosition().y;
|
||||
var x = flyoutWidth / this.workspace_.scale - button.width - this.MARGIN -
|
||||
Blockly.BlockSvg.TAB_WIDTH;
|
||||
var x = flyoutWidth / this.workspace_.scale - button.width -
|
||||
this.MARGIN - Blockly.BlockSvg.TAB_WIDTH;
|
||||
button.moveTo(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ Blockly.Gesture = function(e, creatorWorkspace) {
|
||||
|
||||
/**
|
||||
* Whether the pointer has at any point moved out of the drag radius.
|
||||
* A gesture that exceeds the drag radius is a drag even if it ends exactly at
|
||||
* its start point.
|
||||
* A gesture that exceeds the drag radius is a drag even if it ends exactly
|
||||
* at its start point.
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
@@ -493,7 +493,8 @@ Blockly.Gesture.prototype.doStart = function(e) {
|
||||
this.startWorkspace_.markFocused();
|
||||
this.mostRecentEvent_ = e;
|
||||
|
||||
// Hide chaff also hides the flyout, so don't do it if the click is in a flyout.
|
||||
// Hide chaff also hides the flyout, so don't do it if the click is in a
|
||||
// flyout.
|
||||
Blockly.hideChaff(!!this.flyout_);
|
||||
Blockly.Tooltip.block();
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ goog.require('goog.userAgent');
|
||||
|
||||
/**
|
||||
* Class for a workspace's grid.
|
||||
* @param {!SVGElement} pattern The grid's SVG pattern, created during injection.
|
||||
* @param {!SVGElement} pattern The grid's SVG pattern, created during
|
||||
* injection.
|
||||
* @param {!Object} options A dictionary of normalized options for the grid.
|
||||
* See grid documentation:
|
||||
* https://developers.google.com/blockly/guides/configure/web/grid
|
||||
@@ -164,7 +165,8 @@ Blockly.Grid.prototype.update = function(scale) {
|
||||
* @param {number} y2 The new y end position of the line (in px).
|
||||
* @private
|
||||
*/
|
||||
Blockly.Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2) {
|
||||
Blockly.Grid.prototype.setLineAttributes_ = function(line, width,
|
||||
x1, x2, y1, y2) {
|
||||
if (line) {
|
||||
line.setAttribute('stroke-width', width);
|
||||
line.setAttribute('x1', x1);
|
||||
@@ -175,7 +177,8 @@ Blockly.Grid.prototype.setLineAttributes_ = function(line, width, x1, x2, y1, y2
|
||||
};
|
||||
|
||||
/**
|
||||
* Move the grid to a new x and y position, and make sure that change is visible.
|
||||
* Move the grid to a new x and y position, and make sure that change is
|
||||
* visible.
|
||||
* @param {number} x The new x position of the grid (in px).
|
||||
* @param {number} y The new y position ofthe grid (in px).
|
||||
* @package
|
||||
|
||||
@@ -205,9 +205,11 @@ Blockly.createDom_ = function(container, options) {
|
||||
* @return {!Blockly.Workspace} Newly created main workspace.
|
||||
* @private
|
||||
*/
|
||||
Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, workspaceDragSurface) {
|
||||
Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface,
|
||||
workspaceDragSurface) {
|
||||
options.parentWorkspace = null;
|
||||
var mainWorkspace = new Blockly.WorkspaceSvg(options, blockDragSurface, workspaceDragSurface);
|
||||
var mainWorkspace =
|
||||
new Blockly.WorkspaceSvg(options, blockDragSurface, workspaceDragSurface);
|
||||
mainWorkspace.scale = options.zoomOptions.startScale;
|
||||
svg.appendChild(mainWorkspace.createDom('blocklyMainBackground'));
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ Blockly.Input.prototype.appendField = function(field, opt_name) {
|
||||
*/
|
||||
Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) {
|
||||
if (index < 0 || index > this.fieldRow.length) {
|
||||
throw new Error('index ' + index + ' out of bounds.');
|
||||
throw Error('index ' + index + ' out of bounds.');
|
||||
}
|
||||
|
||||
// Empty string, Null or undefined generates no field, unless field is named.
|
||||
|
||||
@@ -342,13 +342,14 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) {
|
||||
} else if (/^#[0-9a-fA-F]{6}$/.test(colour)) {
|
||||
childOut.hexColour = colour;
|
||||
this.hasColours_ = true;
|
||||
} else if (typeof colour === 'number'
|
||||
|| (typeof colour === 'string' && !isNaN(Number(colour)))) {
|
||||
} else if (typeof colour === 'number' ||
|
||||
(typeof colour === 'string' && !isNaN(Number(colour)))) {
|
||||
childOut.hexColour = Blockly.hueToRgb(Number(colour));
|
||||
this.hasColours_ = true;
|
||||
} else {
|
||||
childOut.hexColour = '';
|
||||
console.warn('Toolbox category "' + categoryName + '" has unrecognized colour attribute: ' + colour);
|
||||
console.warn('Toolbox category "' + categoryName +
|
||||
'" has unrecognized colour attribute: ' + colour);
|
||||
}
|
||||
if (childIn.getAttribute('expanded') == 'true') {
|
||||
if (childOut.blocks.length) {
|
||||
|
||||
@@ -180,7 +180,8 @@ Blockly.Touch.checkTouchIdentifier = function(e) {
|
||||
// source?
|
||||
return Blockly.Touch.touchIdentifier_ == identifier;
|
||||
}
|
||||
if (e.type == 'mousedown' || e.type == 'touchstart' || e.type == 'pointerdown') {
|
||||
if (e.type == 'mousedown' || e.type == 'touchstart' ||
|
||||
e.type == 'pointerdown') {
|
||||
// No identifier set yet, and this is the start of a drag. Set it and
|
||||
// return.
|
||||
Blockly.Touch.touchIdentifier_ = identifier;
|
||||
|
||||
@@ -82,7 +82,8 @@ Blockly.TouchGesture = function(e, creatorWorkspace) {
|
||||
|
||||
/**
|
||||
* A handle to use to unbind the second touch start or pointer down listener
|
||||
* at the end of a drag. Opaque data returned from Blockly.bindEventWithChecks_.
|
||||
* at the end of a drag.
|
||||
* Opaque data returned from Blockly.bindEventWithChecks_.
|
||||
* @type {Array.<!Array>}
|
||||
* @private
|
||||
*/
|
||||
@@ -118,7 +119,8 @@ Blockly.TouchGesture.prototype.doStart = function(e) {
|
||||
/**
|
||||
* Bind gesture events.
|
||||
* Overriding the gesture definition of this function, binding the same
|
||||
* functions for onMoveWrapper_ and onUpWrapper_ but passing opt_noCaptureIdentifier.
|
||||
* functions for onMoveWrapper_ and onUpWrapper_ but passing
|
||||
* opt_noCaptureIdentifier.
|
||||
* In addition, binding a second mouse down event to detect multi-touch events.
|
||||
* @param {!Event} e A mouse down or touch start event.
|
||||
* @package
|
||||
@@ -224,7 +226,8 @@ Blockly.TouchGesture.prototype.dispose = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle a touch start or pointer down event and keep track of current pointers.
|
||||
* Handle a touch start or pointer down event and keep track of current
|
||||
* pointers.
|
||||
* @param {!Event} e A touch start, or pointer down event.
|
||||
* @package
|
||||
*/
|
||||
@@ -244,7 +247,8 @@ Blockly.TouchGesture.prototype.handleTouchStart = function(e) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle a touch move or pointer move event and zoom in/out if two pointers are on the screen.
|
||||
* Handle a touch move or pointer move event and zoom in/out if two pointers
|
||||
* are on the screen.
|
||||
* @param {!Event} e A touch move, or pointer move event.
|
||||
* @package
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Utility methods for working with the closure menu (goog.ui.menu).
|
||||
* @fileoverview Utility methods for working with the closure menu
|
||||
* (goog.ui.menu).
|
||||
* @author fenichel@google.com (Rachel Fenichel)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
@@ -439,7 +439,8 @@ Blockly.utils.checkMessageReferences = function(message) {
|
||||
var msgKey = match[1];
|
||||
msgKey = msgKey.toUpperCase();
|
||||
if (msgKey.substr(0, 4) != 'BKY_') {
|
||||
console.log('WARNING: Unsupported message table prefix in %{' + match[1] + '}.');
|
||||
console.log('WARNING: Unsupported message table prefix in %{' +
|
||||
match[1] + '}.');
|
||||
validSoFar = false; // Continue to report other errors.
|
||||
} else if (msgTable[msgKey.substr(4)] == undefined) {
|
||||
console.log('WARNING: No message string for %{' + match[1] + '}.');
|
||||
@@ -531,8 +532,8 @@ Blockly.utils.tokenizeInterpolation_ = function(message,
|
||||
var keyUpper = rawKey.toUpperCase();
|
||||
|
||||
// BKY_ is the prefix used to namespace the strings used in Blockly
|
||||
// core files and the predefined blocks in ../blocks/. These strings
|
||||
// are defined in ../msgs/ files.
|
||||
// core files and the predefined blocks in ../blocks/.
|
||||
// These strings are defined in ../msgs/ files.
|
||||
var bklyKey = Blockly.utils.startsWith(keyUpper, 'BKY_') ?
|
||||
keyUpper.substring(4) : null;
|
||||
if (bklyKey && bklyKey in Blockly.Msg) {
|
||||
@@ -863,14 +864,14 @@ Blockly.utils.insertAfter = function(newNode, refNode) {
|
||||
*/
|
||||
Blockly.utils.runAfterPageLoad = function(fn) {
|
||||
if (typeof document != 'object') {
|
||||
throw new Error('Blockly.utils.runAfterPageLoad() requires browser document.');
|
||||
throw Error('Blockly.utils.runAfterPageLoad() requires browser document.');
|
||||
}
|
||||
if (document.readyState === 'complete') {
|
||||
if (document.readyState == 'complete') {
|
||||
fn(); // Page has already loaded. Call immediately.
|
||||
} else {
|
||||
// Poll readyState.
|
||||
var readyStateCheckInterval = setInterval(function() {
|
||||
if (document.readyState === 'complete') {
|
||||
if (document.readyState == 'complete') {
|
||||
clearInterval(readyStateCheckInterval);
|
||||
fn();
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) {
|
||||
Blockly.VariableMap.prototype.renameVariableById = function(id, newName) {
|
||||
var variable = this.getVariableById(id);
|
||||
if (!variable) {
|
||||
throw new Error('Tried to rename a variable that didn\'t exist. ID: ' + id);
|
||||
throw Error('Tried to rename a variable that didn\'t exist. ID: ' + id);
|
||||
}
|
||||
|
||||
this.renameVariable(variable, newName);
|
||||
|
||||
@@ -298,7 +298,8 @@ Blockly.Variables.createVariableButtonHandler = function(
|
||||
var msg = Blockly.Msg['VARIABLE_ALREADY_EXISTS'].replace(
|
||||
'%1', lowerCase);
|
||||
} else {
|
||||
var msg = Blockly.Msg['VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE'];
|
||||
var msg =
|
||||
Blockly.Msg['VARIABLE_ALREADY_EXISTS_FOR_ANOTHER_TYPE'];
|
||||
msg = msg.replace('%1', lowerCase).replace('%2', existing.type);
|
||||
}
|
||||
Blockly.alert(msg,
|
||||
@@ -438,8 +439,8 @@ Blockly.Variables.nameUsedWithOtherType_ = function(name, type, workspace) {
|
||||
* @param {string} name The name to search for.
|
||||
* @param {!Blockly.Workspace} workspace The workspace to search for the
|
||||
* variable.
|
||||
* @return {?Blockly.VariableModel} The variable with the given name, or null if
|
||||
* none was found.
|
||||
* @return {?Blockly.VariableModel} The variable with the given name,
|
||||
* or null if none was found.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Variables.nameUsedWithAnyType_ = function(name, workspace) {
|
||||
@@ -462,8 +463,8 @@ Blockly.Variables.nameUsedWithAnyType_ = function(name, workspace) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.Variables.generateVariableFieldXmlString = function(variableModel) {
|
||||
// The variable name may be user input, so it may contain characters that need
|
||||
// to be escaped to create valid XML.
|
||||
// The variable name may be user input, so it may contain characters that
|
||||
// need to be escaped to create valid XML.
|
||||
var typeString = variableModel.type;
|
||||
if (typeString == '') {
|
||||
typeString = '\'\'';
|
||||
@@ -520,10 +521,10 @@ Blockly.Variables.getOrCreateVariablePackage = function(workspace, id, opt_name,
|
||||
* @param {!Blockly.Workspace} workspace The workspace to search for the
|
||||
* variable. It may be a flyout workspace or main workspace.
|
||||
* @param {string} id The ID to use to look up the variable, or null.
|
||||
* @param {string=} opt_name The string to use to look up the variable. Only
|
||||
* used if lookup by ID fails.
|
||||
* @param {string=} opt_type The type to use to look up the variable. Only used
|
||||
* if lookup by ID fails.
|
||||
* @param {string=} opt_name The string to use to look up the variable.
|
||||
* Only used if lookup by ID fails.
|
||||
* @param {string=} opt_type The type to use to look up the variable.
|
||||
* Only used if lookup by ID fails.
|
||||
* @return {?Blockly.VariableModel} The variable corresponding to the given ID
|
||||
* or name + type combination, or null if not found.
|
||||
* @package
|
||||
@@ -539,7 +540,7 @@ Blockly.Variables.getVariable = function(workspace, id, opt_name, opt_type) {
|
||||
}
|
||||
} else if (opt_name) {
|
||||
if (opt_type == undefined) {
|
||||
throw new Error('Tried to look up a variable by name without a type');
|
||||
throw Error('Tried to look up a variable by name without a type');
|
||||
}
|
||||
// Otherwise look up by name and type.
|
||||
var variable = workspace.getVariable(opt_name, opt_type);
|
||||
@@ -586,9 +587,9 @@ Blockly.Variables.createVariable_ = function(workspace, id, opt_name,
|
||||
* @param {!Blockly.Workspace} workspace The workspace to inspect.
|
||||
* @param {!Array.<!Blockly.VariableModel>} originalVariables The array of
|
||||
* variables that existed in the workspace before adding the new block.
|
||||
* @return {!Array.<!Blockly.VariableModel>} The new array of variables that were
|
||||
* freshly added to the workspace after creating the new block, or [] if no
|
||||
* new variables were added to the workspace.
|
||||
* @return {!Array.<!Blockly.VariableModel>} The new array of variables that
|
||||
* were freshly added to the workspace after creating the new block,
|
||||
* or [] if no new variables were added to the workspace.
|
||||
* @package
|
||||
*/
|
||||
Blockly.Variables.getAddedVariables = function(workspace, originalVariables) {
|
||||
|
||||
@@ -36,13 +36,16 @@ goog.require('Blockly.VariableModel');
|
||||
|
||||
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) {
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null, 'String');
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(),
|
||||
null, 'String');
|
||||
};
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_Number = function(button) {
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null, 'Number');
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(),
|
||||
null, 'Number');
|
||||
};
|
||||
Blockly.VariablesDynamic.onCreateVariableButtonClick_Colour = function(button) {
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(), null, 'Colour');
|
||||
Blockly.Variables.createVariableButtonHandler(button.getTargetWorkspace(),
|
||||
null, 'Colour');
|
||||
};
|
||||
/**
|
||||
* Construct the elements (blocks and button) required by the flyout for the
|
||||
|
||||
@@ -73,8 +73,8 @@ Blockly.WidgetDiv.createDom = function() {
|
||||
* Initialize and display the widget div. Close the old one if needed.
|
||||
* @param {!Object} newOwner The object that will be using this container.
|
||||
* @param {boolean} rtl Right-to-left (true) or left-to-right (false).
|
||||
* @param {Function} dispose Optional cleanup function to be run when the widget
|
||||
* is closed.
|
||||
* @param {Function} dispose Optional cleanup function to be run when the
|
||||
* widget is closed.
|
||||
*/
|
||||
Blockly.WidgetDiv.show = function(newOwner, rtl, dispose) {
|
||||
Blockly.WidgetDiv.hide();
|
||||
@@ -113,7 +113,7 @@ Blockly.WidgetDiv.isVisible = function() {
|
||||
|
||||
/**
|
||||
* Destroy the widget and hide the div if it is being used by the specified
|
||||
* object.
|
||||
* object.
|
||||
* @param {!Object} oldOwner The object that was using this container.
|
||||
*/
|
||||
Blockly.WidgetDiv.hideIfOwner = function(oldOwner) {
|
||||
@@ -169,7 +169,7 @@ Blockly.WidgetDiv.positionInternal_ = function(x, y, height) {
|
||||
* Position the widget div based on an anchor rectangle.
|
||||
* The widget should be placed adjacent to but not overlapping the anchor
|
||||
* rectangle. The preferred position is directly below and aligned to the left
|
||||
* (ltr) or right (rtl) side of the anchor.
|
||||
* (LTR) or right (RTL) side of the anchor.
|
||||
* @param {!Object} viewportBBox The bounding rectangle of the current viewport,
|
||||
* in window coordinates.
|
||||
* @param {!Object} anchorBBox The bounding rectangle of the anchor, in window
|
||||
@@ -206,14 +206,14 @@ Blockly.WidgetDiv.positionWithAnchor = function(viewportBBox, anchorBBox,
|
||||
Blockly.WidgetDiv.calculateX_ = function(viewportBBox, anchorBBox, widgetSize,
|
||||
rtl) {
|
||||
if (rtl) {
|
||||
// Try to align the right side of the field and the right side of the widget.
|
||||
// Try to align the right side of the field and the right side of widget.
|
||||
var widgetLeft = anchorBBox.right - widgetSize.width;
|
||||
// Don't go offscreen left.
|
||||
var x = Math.max(widgetLeft, viewportBBox.left);
|
||||
// But really don't go offscreen right:
|
||||
return Math.min(x, viewportBBox.right - widgetSize.width);
|
||||
} else {
|
||||
// Try to align the left side of the field and the left side of the widget.
|
||||
// Try to align the left side of the field and the left side of widget.
|
||||
// Don't go offscreen right.
|
||||
var x = Math.min(anchorBBox.left,
|
||||
viewportBBox.right - widgetSize.width);
|
||||
|
||||
@@ -122,7 +122,8 @@ Blockly.Workspace.prototype.rendered = false;
|
||||
Blockly.Workspace.prototype.isClearing = false;
|
||||
|
||||
/**
|
||||
* Maximum number of undo events in stack. `0` turns off undo, `Infinity` sets it to unlimited.
|
||||
* Maximum number of undo events in stack. `0` turns off undo, `Infinity` sets
|
||||
* it to unlimited.
|
||||
* @type {number}
|
||||
*/
|
||||
Blockly.Workspace.prototype.MAX_UNDO = 1024;
|
||||
@@ -221,8 +222,8 @@ Blockly.Workspace.prototype.removeTopComment = function(comment) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds the top-level comments and returns them. Comments are optionally sorted
|
||||
* by position; top to bottom (with slight LTR or RTL bias).
|
||||
* Finds the top-level comments and returns them. Comments are optionally
|
||||
* sorted by position; top to bottom (with slight LTR or RTL bias).
|
||||
* @param {boolean} ordered Sort the list if true.
|
||||
* @return {!Array.<!Blockly.WorkspaceComment>} The top-level comment objects.
|
||||
* @package
|
||||
@@ -342,8 +343,8 @@ Blockly.Workspace.prototype.deleteVariableById = function(id) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a variable and all of its uses from this workspace without asking the
|
||||
* user for confirmation.
|
||||
* Deletes a variable and all of its uses from this workspace without asking
|
||||
* the user for confirmation.
|
||||
* @param {!Blockly.VariableModel} variable Variable to delete.
|
||||
* @param {!Array.<!Blockly.Block>} uses An array of uses of the variable.
|
||||
* @private
|
||||
@@ -559,7 +560,8 @@ Blockly.Workspace.prototype.getCommentById = function(id) {
|
||||
* whether shadow blocks are counted as filled. Defaults to true.
|
||||
* @return {boolean} True if all inputs are filled, false otherwise.
|
||||
*/
|
||||
Blockly.Workspace.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled) {
|
||||
Blockly.Workspace.prototype.allInputsFilled = function(
|
||||
opt_shadowBlocksAreFilled) {
|
||||
var blocks = this.getTopBlocks(false);
|
||||
for (var i = 0, block; block = blocks[i]; i++) {
|
||||
if (!block.allInputsFilled(opt_shadowBlocksAreFilled)) {
|
||||
@@ -570,8 +572,8 @@ Blockly.Workspace.prototype.allInputsFilled = function(opt_shadowBlocksAreFilled
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the variable map that contains "potential" variables. These exist in
|
||||
* the flyout but not in the workspace.
|
||||
* Return the variable map that contains "potential" variables.
|
||||
* These exist in the flyout but not in the workspace.
|
||||
* @return {?Blockly.VariableMap} The potential variable map.
|
||||
* @package
|
||||
*/
|
||||
|
||||
@@ -67,7 +67,7 @@ Blockly.WorkspaceCommentSvg.TOP_OFFSET = 10;
|
||||
/**
|
||||
* Returns a bounding box describing the dimensions of this comment.
|
||||
* @return {!{height: number, width: number}} Object with height and width
|
||||
* properties in workspace units.
|
||||
* properties in workspace units.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceCommentSvg.prototype.getHeightWidth = function() {
|
||||
@@ -283,9 +283,10 @@ Blockly.WorkspaceCommentSvg.prototype.resizeMouseDown_ = function(e) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_ = function(e) {
|
||||
// highlight the delete icon
|
||||
// Highlight the delete icon.
|
||||
Blockly.utils.addClass(
|
||||
/** @type {!Element} */ (this.deleteIconBorder_), 'blocklyDeleteIconHighlighted');
|
||||
/** @type {!Element} */ (this.deleteIconBorder_),
|
||||
'blocklyDeleteIconHighlighted');
|
||||
// This event has been handled. No need to bubble up to the document.
|
||||
e.stopPropagation();
|
||||
};
|
||||
@@ -296,9 +297,10 @@ Blockly.WorkspaceCommentSvg.prototype.deleteMouseDown_ = function(e) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_ = function(/*e*/) {
|
||||
// restore highlight on the delete icon
|
||||
// Restore highlight on the delete icon.
|
||||
Blockly.utils.removeClass(
|
||||
/** @type {!Element} */ (this.deleteIconBorder_), 'blocklyDeleteIconHighlighted');
|
||||
/** @type {!Element} */ (this.deleteIconBorder_),
|
||||
'blocklyDeleteIconHighlighted');
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -307,7 +309,7 @@ Blockly.WorkspaceCommentSvg.prototype.deleteMouseOut_ = function(/*e*/) {
|
||||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceCommentSvg.prototype.deleteMouseUp_ = function(e) {
|
||||
// Delete this comment
|
||||
// Delete this comment.
|
||||
this.dispose(true, true);
|
||||
// This event has been handled. No need to bubble up to the document.
|
||||
e.stopPropagation();
|
||||
@@ -359,18 +361,13 @@ Blockly.WorkspaceCommentSvg.prototype.resizeComment_ = function() {
|
||||
var topOffset = Blockly.WorkspaceCommentSvg.TOP_OFFSET;
|
||||
var textOffset = Blockly.WorkspaceCommentSvg.TEXTAREA_OFFSET * 2;
|
||||
|
||||
this.foreignObject_.setAttribute('width',
|
||||
size.width);
|
||||
this.foreignObject_.setAttribute('height',
|
||||
size.height - topOffset);
|
||||
this.foreignObject_.setAttribute('width', size.width);
|
||||
this.foreignObject_.setAttribute('height', size.height - topOffset);
|
||||
if (this.RTL) {
|
||||
this.foreignObject_.setAttribute('x',
|
||||
-size.width);
|
||||
this.foreignObject_.setAttribute('x', -size.width);
|
||||
}
|
||||
this.textarea_.style.width =
|
||||
(size.width - textOffset) + 'px';
|
||||
this.textarea_.style.height =
|
||||
(size.height - textOffset - topOffset) + 'px';
|
||||
this.textarea_.style.width = (size.width - textOffset) + 'px';
|
||||
this.textarea_.style.height = (size.height - textOffset - topOffset) + 'px';
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -390,7 +387,8 @@ Blockly.WorkspaceCommentSvg.prototype.setSize_ = function(width, height) {
|
||||
this.svgRectTarget_.setAttribute('width', width);
|
||||
this.svgRectTarget_.setAttribute('height', height);
|
||||
this.svgHandleTarget_.setAttribute('width', width);
|
||||
this.svgHandleTarget_.setAttribute('height', Blockly.WorkspaceCommentSvg.TOP_OFFSET);
|
||||
this.svgHandleTarget_.setAttribute('height',
|
||||
Blockly.WorkspaceCommentSvg.TOP_OFFSET);
|
||||
if (this.RTL) {
|
||||
this.svgRect_.setAttribute('transform', 'scale(-1 1)');
|
||||
this.svgRectTarget_.setAttribute('transform', 'scale(-1 1)');
|
||||
|
||||
@@ -266,8 +266,8 @@ Blockly.WorkspaceCommentSvg.prototype.removeFocus = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the coordinates of the top-left corner of this comment relative to the
|
||||
* drawing surface's origin (0,0), in workspace units.
|
||||
* Return the coordinates of the top-left corner of this comment relative to
|
||||
* the drawing surface's origin (0,0), in workspace units.
|
||||
* If the comment is on the workspace, (0, 0) is the origin of the workspace
|
||||
* coordinate system.
|
||||
* This does not change with workspace scale.
|
||||
@@ -337,9 +337,9 @@ Blockly.WorkspaceCommentSvg.prototype.translate = function(x, y) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Move this comment to its workspace's drag surface, accounting for positioning.
|
||||
* Generally should be called at the same time as setDragging(true).
|
||||
* Does nothing if useDragSurface_ is false.
|
||||
* Move this comment to its workspace's drag surface, accounting for
|
||||
* positioning. Generally should be called at the same time as
|
||||
* setDragging(true). Does nothing if useDragSurface_ is false.
|
||||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceCommentSvg.prototype.moveToDragSurface_ = function() {
|
||||
@@ -383,7 +383,8 @@ Blockly.WorkspaceCommentSvg.prototype.moveOffDragSurface_ = function(newXY) {
|
||||
* workspace coordinates.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceCommentSvg.prototype.moveDuringDrag = function(dragSurface, newLoc) {
|
||||
Blockly.WorkspaceCommentSvg.prototype.moveDuringDrag = function(dragSurface,
|
||||
newLoc) {
|
||||
if (dragSurface) {
|
||||
dragSurface.translateSurface(newLoc.x, newLoc.y);
|
||||
} else {
|
||||
|
||||
@@ -169,7 +169,8 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
||||
/**
|
||||
* Set the SVG to have the block canvas and bubble canvas in it and then
|
||||
* show the surface.
|
||||
* @param {!Element} blockCanvas The block canvas <g> element from the workspace.
|
||||
* @param {!Element} blockCanvas The block canvas <g> element from the
|
||||
* workspace.
|
||||
* @param {!Element} bubbleCanvas The <g> element that contains the bubbles.
|
||||
* @param {?Element} previousSibling The element to insert the block canvas &
|
||||
bubble canvas after when it goes back in the DOM at the end of a drag.
|
||||
|
||||
@@ -64,7 +64,8 @@ goog.require('goog.math.Coordinate');
|
||||
* @extends {Blockly.Workspace}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.WorkspaceSvg = function(options, opt_blockDragSurface, opt_wsDragSurface) {
|
||||
Blockly.WorkspaceSvg = function(options,
|
||||
opt_blockDragSurface, opt_wsDragSurface) {
|
||||
Blockly.WorkspaceSvg.superClass_.constructor.call(this, options);
|
||||
this.getMetrics =
|
||||
options.getMetrics || Blockly.WorkspaceSvg.getTopLevelWorkspaceMetrics_;
|
||||
@@ -344,8 +345,8 @@ Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM = function() {
|
||||
|
||||
/**
|
||||
* Getter for isVisible
|
||||
* @return {boolean} Whether the workspace is visible. False if the workspace has been hidden
|
||||
* by calling `setVisible(false)`.
|
||||
* @return {boolean} Whether the workspace is visible.
|
||||
* False if the workspace has been hidden by calling `setVisible(false)`.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.isVisible = function() {
|
||||
return this.isVisible_;
|
||||
@@ -1051,7 +1052,8 @@ Blockly.WorkspaceSvg.prototype.pasteWorkspaceComment_ = function(xmlComment) {
|
||||
commentX = -commentX;
|
||||
}
|
||||
// Offset workspace comment.
|
||||
// TODO: #1719 properly offset comment such that it's not interfereing with any blocks
|
||||
// TODO: #1719 properly offset comment such that it's not interfereing
|
||||
// with any blocks.
|
||||
commentX += 50;
|
||||
commentY += 50;
|
||||
comment.moveBy(commentX, commentY);
|
||||
@@ -1060,7 +1062,7 @@ Blockly.WorkspaceSvg.prototype.pasteWorkspaceComment_ = function(xmlComment) {
|
||||
Blockly.Events.enable();
|
||||
}
|
||||
if (Blockly.Events.isEnabled()) {
|
||||
// TODO: Fire a Workspace Comment Create event
|
||||
// TODO: Fire a Workspace Comment Create event.
|
||||
}
|
||||
comment.select();
|
||||
};
|
||||
@@ -1100,8 +1102,8 @@ Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new variable with the given name. Update the flyout to show the new
|
||||
* variable immediately.
|
||||
* Create a new variable with the given name. Update the flyout to show the
|
||||
* new variable immediately.
|
||||
* @param {string} name The new variable's name.
|
||||
* @param {string=} opt_type The type of the variable like 'int' or 'string'.
|
||||
* Does not need to be unique. Field_variable can filter variables based on
|
||||
|
||||
@@ -330,7 +330,7 @@ goog.inherits(Blockly.Events.CommentMove, Blockly.Events.CommentBase);
|
||||
*/
|
||||
Blockly.Events.CommentMove.prototype.recordNew = function() {
|
||||
if (!this.comment_) {
|
||||
throw new Error('Tried to record the new position of a comment on the ' +
|
||||
throw Error('Tried to record the new position of a comment on the ' +
|
||||
'same event twice.');
|
||||
}
|
||||
this.newCoordinate_ = this.comment_.getXY();
|
||||
|
||||
13
core/xml.js
13
core/xml.js
@@ -116,8 +116,8 @@ Blockly.Xml.fieldToDomVariable_ = function(field) {
|
||||
}
|
||||
// Get the variable directly from the field, instead of doing a lookup. This
|
||||
// will work even if the variable has already been deleted. This can happen
|
||||
// because the flyout defers deleting blocks until the next time the flyout is
|
||||
// opened.
|
||||
// because the flyout defers deleting blocks until the next time the flyout
|
||||
// is opened.
|
||||
var variable = field.getVariable();
|
||||
|
||||
if (!variable) {
|
||||
@@ -178,7 +178,8 @@ Blockly.Xml.allFieldsToDom_ = function(block, element) {
|
||||
* @return {!Element} Tree of XML elements.
|
||||
*/
|
||||
Blockly.Xml.blockToDom = function(block, opt_noId) {
|
||||
var element = Blockly.Xml.utils.createElement(block.isShadow() ? 'shadow' : 'block');
|
||||
var element =
|
||||
Blockly.Xml.utils.createElement(block.isShadow() ? 'shadow' : 'block');
|
||||
element.setAttribute('type', block.type);
|
||||
if (!opt_noId) {
|
||||
element.setAttribute('id', block.id);
|
||||
@@ -354,7 +355,8 @@ Blockly.Xml.domToPrettyText = function(dom) {
|
||||
* Converts an XML string into a DOM structure. It requires the XML to have a
|
||||
* root element of <xml>. Other XML string will result in throwing an error.
|
||||
* @param {string} text An XML string.
|
||||
* @return {!Element} A DOM object representing the singular child of the document element.
|
||||
* @return {!Element} A DOM object representing the singular child of the
|
||||
* document element.
|
||||
* @throws if XML doesn't parse or is not the expected structure.
|
||||
*/
|
||||
Blockly.Xml.textToDom = function(text) {
|
||||
@@ -500,7 +502,8 @@ Blockly.Xml.appendDomToWorkspace = function(xml, workspace) {
|
||||
var newX = Infinity; // x of top corner
|
||||
var newY = Infinity; // y of top corner
|
||||
for (var i = 0; i < newBlockIds.length; i++) {
|
||||
var blockXY = workspace.getBlockById(newBlockIds[i]).getRelativeToSurfaceXY();
|
||||
var blockXY =
|
||||
workspace.getBlockById(newBlockIds[i]).getRelativeToSurfaceXY();
|
||||
if (blockXY.y < newY) {
|
||||
newY = blockXY.y;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user