Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scratch-blocks

Package Overview
Dependencies
Maintainers
1
Versions
1420
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scratch-blocks - npm Package Compare versions

Comparing version 0.1.0-1c642 to 0.1.0-1da4d

core/touch.js

17

core/block_svg.js

@@ -31,2 +31,3 @@ /**

goog.require('Blockly.ContextMenu');
goog.require('Blockly.Touch');
goog.require('Blockly.RenderedConnection');

@@ -634,3 +635,3 @@ goog.require('goog.Timer');

* Handle a mouse-down on an SVG block.
* @param {!Event} e Mouse down event.
* @param {!Event} e Mouse down event or touch start event.
* @private

@@ -643,2 +644,13 @@ */

if (this.isInFlyout) {
// longStart's simulation of right-clicks for longpresses on touch devices
// calls the onMouseDown_ function defined on the prototype of the object
// the was longpressed (in this case, a Blockly.BlockSvg). In this case
// that behaviour is wrong, because Blockly.Flyout.prototype.blockMouseDown
// should be called for a mousedown on a block in the flyout, which blocks
// execution of the block's onMouseDown_ function.
if (e.type == 'touchstart' && Blockly.isRightButton(e)) {
Blockly.Flyout.blockRightClick_(e, this);
e.stopPropagation();
e.preventDefault();
}
return;

@@ -661,2 +673,4 @@ }

this.showContextMenu_(e);
// Click, not drag, so stop waiting for other touches from this identifier.
Blockly.Touch.clearTouchIdentifier();
} else if (!this.isMovable()) {

@@ -708,2 +722,3 @@ // Allow immovable blocks to be selected and context menued, but not

var fieldEditing = Blockly.WidgetDiv.isVisible() || Blockly.DropDownDiv.isVisible();
Blockly.Touch.clearTouchIdentifier();
if (Blockly.dragMode_ != Blockly.DRAG_FREE && !fieldEditing) {

@@ -710,0 +725,0 @@ Blockly.Events.fire(

91

core/blockly.js

@@ -49,2 +49,3 @@ /**

goog.require('Blockly.Toolbox');
goog.require('Blockly.Touch');
goog.require('Blockly.WidgetDiv');

@@ -154,9 +155,2 @@ goog.require('Blockly.WorkspaceSvg');

/**
* Wrapper function called when a touch mouseUp occurs during a drag operation.
* @type {Array.<!Array>}
* @private
*/
Blockly.onTouchUpWrapper_ = null;
/**
* Convert a hue (HSV model) into an RGB hex triplet.

@@ -223,48 +217,2 @@ * @param {number} hue Hue on a colour wheel (0-360).

/**
* Handle a mouse-up anywhere on the page.
* @param {!Event} e Mouse up event.
* @private
*/
Blockly.onMouseUp_ = function(/*e*/) {
var workspace = Blockly.getMainWorkspace();
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
workspace.dragMode_ = Blockly.DRAG_NONE;
// Unbind the touch event if it exists.
if (Blockly.onTouchUpWrapper_) {
Blockly.unbindEvent_(Blockly.onTouchUpWrapper_);
Blockly.onTouchUpWrapper_ = null;
}
if (Blockly.onMouseMoveWrapper_) {
Blockly.unbindEvent_(Blockly.onMouseMoveWrapper_);
Blockly.onMouseMoveWrapper_ = null;
}
};
/**
* Handle a mouse-move on SVG drawing surface.
* @param {!Event} e Mouse move event.
* @private
*/
Blockly.onMouseMove_ = function(e) {
if (e.touches && e.touches.length >= 2) {
return; // Multi-touch gestures won't have e.clientX.
}
var workspace = Blockly.getMainWorkspace();
if (workspace.dragMode_ != Blockly.DRAG_NONE) {
var dx = e.clientX - workspace.startDragMouseX;
var dy = e.clientY - workspace.startDragMouseY;
var x = workspace.startScrollX + dx;
var y = workspace.startScrollY + dy;
workspace.scroll(x, y);
// Cancel the long-press if the drag has moved too far.
if (Math.sqrt(dx * dx + dy * dy) > Blockly.DRAG_RADIUS) {
Blockly.longStop_();
workspace.dragMode_ = Blockly.DRAG_FREE;
}
e.stopPropagation();
e.preventDefault();
}
};
/**
* Handle a key-down on SVG drawing surface.

@@ -332,39 +280,2 @@ * @param {!Event} e Key down event.

/**
* PID of queued long-press task.
* @private
*/
Blockly.longPid_ = 0;
/**
* Context menus on touch devices are activated using a long-press.
* Unfortunately the contextmenu touch event is currently (2015) only suported
* by Chrome. This function is fired on any touchstart event, queues a task,
* which after about a second opens the context menu. The tasks is killed
* if the touch event terminates early.
* @param {!Event} e Touch start event.
* @param {!Blockly.Block|!Blockly.WorkspaceSvg} uiObject The block or workspace
* under the touchstart event.
* @private
*/
Blockly.longStart_ = function(e, uiObject) {
Blockly.longStop_();
Blockly.longPid_ = setTimeout(function() {
e.button = 2; // Simulate a right button click.
uiObject.onMouseDown_(e);
}, Blockly.LONGPRESS);
};
/**
* Nope, that's not a long-press. Either touchend or touchcancel was fired,
* or a drag hath begun. Kill the queued long-press task.
* @private
*/
Blockly.longStop_ = function() {
if (Blockly.longPid_) {
clearTimeout(Blockly.longPid_);
Blockly.longPid_ = 0;
}
};
/**
* Copy a block onto the local clipboard.

@@ -371,0 +282,0 @@ * @param {!Blockly.Block} block Block to be copied.

@@ -29,2 +29,3 @@ /**

goog.require('Blockly.Touch');
goog.require('Blockly.Workspace');

@@ -148,2 +149,13 @@ goog.require('goog.dom');

/*
* Handle a mouse-up event while dragging a bubble's border or resize handle.
* @param {!Event} e Mouse up event.
* @private
*/
Blockly.Bubble.bubbleMouseUp_ = function(/*e*/) {
Blockly.Touch.clearTouchIdentifier();
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
Blockly.Bubble.unbindDragEvents_();
};
/**

@@ -280,3 +292,3 @@ * Flag to stop incremental rendering during construction.

Blockly.Bubble.onMouseUpWrapper_ = Blockly.bindEvent_(document,
'mouseup', this, Blockly.Bubble.unbindDragEvents_);
'mouseup', this, Blockly.Bubble.bubbleMouseUp_);
Blockly.Bubble.onMouseMoveWrapper_ = Blockly.bindEvent_(document,

@@ -323,3 +335,3 @@ 'mousemove', this, this.bubbleMouseMove_);

Blockly.Bubble.onMouseUpWrapper_ = Blockly.bindEvent_(document,
'mouseup', this, Blockly.Bubble.unbindDragEvents_);
'mouseup', this, Blockly.Bubble.bubbleMouseUp_);
Blockly.Bubble.onMouseMoveWrapper_ = Blockly.bindEvent_(document,

@@ -326,0 +338,0 @@ 'mousemove', this, this.resizeMouseMove_);

@@ -513,2 +513,5 @@ /**

this.showEditor_();
// The field is handling the touch, but we also want the blockSvg onMouseUp
// handler to fire, so we will leave the touch identifier as it is.
// The next onMouseUp is responsible for nulling it out.
}

@@ -515,0 +518,0 @@ };

@@ -33,2 +33,3 @@ /**

goog.require('Blockly.FlyoutButton');
goog.require('Blockly.Touch');
goog.require('Blockly.WorkspaceSvg');

@@ -1000,2 +1001,16 @@ goog.require('goog.dom');

/**
* Actions to take when a block in the flyout is right-clicked.
* @param {!Event} e Event that triggered the right-click. Could originate from
* a long-press in a touch environment.
* @param {Blockly.BlockSvg} block The block that was clicked.
*/
Blockly.Flyout.blockRightClick_ = function(e, block) {
Blockly.terminateDrag_();
Blockly.hideChaff(true);
block.showContextMenu_(e);
// This was a right-click, so end the gesture immediately.
Blockly.Touch.clearTouchIdentifier();
};
/**
* Handle a mouse-down on an SVG block in a non-closing flyout.

@@ -1015,5 +1030,6 @@ * @param {!Blockly.Block} block The flyout block to copy.

if (Blockly.isRightButton(e)) {
// Right-click.
block.showContextMenu_(e);
Blockly.Flyout.blockRightClick_(e, block);
} else {
Blockly.terminateDrag_();
Blockly.hideChaff(true);
// Left-click (or middle click)

@@ -1046,2 +1062,4 @@ Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);

if (Blockly.isRightButton(e)) {
// Don't start drags with right clicks.
Blockly.Touch.clearTouchIdentifier();
return;

@@ -1074,2 +1092,4 @@ }

if (!this.workspace_.isDragging()) {
// This was a click, not a drag. End the gesture.
Blockly.Touch.clearTouchIdentifier();
if (this.autoClose) {

@@ -1140,2 +1160,3 @@ this.createBlockFunc_(Blockly.Flyout.startBlock_)(

} else if (this.dragMode_ == Blockly.DRAG_FREE) {
Blockly.longStop_();
// Do a scroll.

@@ -1237,2 +1258,4 @@ this.onMouseMove_(e);

}
// It wasn't a right-click. Get rid of the pending longPress handler.
Blockly.longStop_();
if (originBlock.disabled) {

@@ -1244,3 +1267,9 @@ // Beyond capacity.

try {
// If creating the block creates a variable, we need startFlyout_ set so
// we don't try to refresh the flyout immediately. That would be a
// problem because it would change the DOM on the path the touch events
// were on. See google/blockly #613.
Blockly.Flyout.startFlyout_ = flyout;
var block = flyout.placeNewBlock_(originBlock);
Blockly.Flyout.startFlyout_ = null;
} finally {

@@ -1377,5 +1406,9 @@ Blockly.Events.enable();

Blockly.Flyout.terminateDrag_ = function() {
this.dragMode_ = Blockly.DRAG_NONE;
if (Blockly.Flyout.startFlyout_) {
// User was dragging the flyout background, and has stopped.
if (Blockly.Flyout.startFlyout_.dragMode_ == Blockly.DRAG_FREE) {
Blockly.Touch.clearTouchIdentifier();
}
Blockly.Flyout.startFlyout_.dragMode_ = Blockly.DRAG_NONE;
Blockly.Flyout.startFlyout_ = null;
}

@@ -1396,3 +1429,2 @@ if (Blockly.Flyout.onMouseUpWrapper_) {

Blockly.Flyout.startBlock_ = null;
Blockly.Flyout.startFlyout_ = null;
};

@@ -1399,0 +1431,0 @@

@@ -314,20 +314,3 @@ /**

if (options.hasSounds) {
mainWorkspace.loadAudio_(
[options.pathToMedia + 'click.wav'], 'click');
mainWorkspace.loadAudio_(
[options.pathToMedia + 'delete.wav'], 'delete');
// Bind temporary hooks that preload the sounds.
var soundBinds = [];
var unbindSounds = function() {
while (soundBinds.length) {
Blockly.unbindEvent_(soundBinds.pop());
}
mainWorkspace.preloadAudio_();
};
// Android ignores any sound not loaded as a result of a user action.
soundBinds.push(
Blockly.bindEvent_(document, 'mousemove', null, unbindSounds));
soundBinds.push(
Blockly.bindEvent_(document, 'touchstart', null, unbindSounds));
Blockly.inject.loadSounds_(options.pathToMedia, mainWorkspace);
}

@@ -368,2 +351,29 @@ };

/**
* Load sounds for the given workspace.
* @param {string} pathToMedia The path to the media directory.
* @param {!Blockly.Workspace} workspace The workspace to load sounds for.
* @private
*/
Blockly.inject.loadSounds_ = function(pathToMedia, workspace) {
workspace.loadAudio_(
[pathToMedia + 'click.wav'], 'click');
workspace.loadAudio_(
[pathToMedia + 'delete.wav'], 'delete');
// Bind temporary hooks that preload the sounds.
var soundBinds = [];
var unbindSounds = function() {
while (soundBinds.length) {
Blockly.unbindEvent_(soundBinds.pop());
}
workspace.preloadAudio_();
};
// Android ignores any sound not loaded as a result of a user action.
soundBinds.push(
Blockly.bindEvent_(document, 'mousemove', null, unbindSounds, true));
soundBinds.push(
Blockly.bindEvent_(document, 'touchstart', null, unbindSounds, true));
};
/**
* Modify the block tree on the existing toolbox.

@@ -370,0 +380,0 @@ * @param {Node|string} tree DOM tree of blocks, or text representation of same.

@@ -300,3 +300,3 @@ /**

Blockly.Scrollbar.prototype.dispose = function() {
this.onMouseUpHandle_();
this.cleanUp_();
Blockly.unbindEvent_(this.onMouseDownBarWrapper_);

@@ -603,3 +603,4 @@ this.onMouseDownBarWrapper_ = null;

Blockly.Scrollbar.prototype.onMouseDownBar_ = function(e) {
this.onMouseUpHandle_();
Blockly.Touch.clearTouchIdentifier(); // This is really a click.
this.cleanUp_();
if (Blockly.isRightButton(e)) {

@@ -645,3 +646,3 @@ // Right-click.

Blockly.Scrollbar.prototype.onMouseDownHandle_ = function(e) {
this.onMouseUpHandle_();
this.cleanUp_();
if (Blockly.isRightButton(e)) {

@@ -685,6 +686,16 @@ // Right-click.

/**
* Stop binding to the global mouseup and mousemove events.
* Release the scrollbar handle and reset state accordingly.
* @private
*/
Blockly.Scrollbar.prototype.onMouseUpHandle_ = function() {
Blockly.Touch.clearTouchIdentifier();
this.cleanUp_();
};
/**
* Hide chaff and stop binding to mouseup and mousemove events. Call this to
* wrap up lose ends associated with the scrollbar.
* @private
*/
Blockly.Scrollbar.prototype.cleanUp_ = function() {
Blockly.hideChaff(true);

@@ -691,0 +702,0 @@ if (Blockly.Scrollbar.onMouseUpWrapper_) {

@@ -30,2 +30,3 @@ /**

goog.require('Blockly.Flyout');
goog.require('Blockly.Touch');
goog.require('goog.dom');

@@ -175,2 +176,3 @@ goog.require('goog.dom.TagName');

}
Blockly.Touch.clearTouchIdentifier(); // Don't block future drags.
});

@@ -492,5 +494,5 @@ var workspaceOptions = {

var el = this.getElement();
// Add touch handler.
if (goog.events.BrowserFeature.TOUCH_ENABLED) {
var el = this.getElement();
Blockly.bindEvent_(el, goog.events.EventType.TOUCHSTART, this,

@@ -497,0 +499,0 @@ this.handleTouchEvent_);

@@ -136,3 +136,7 @@ /**

Blockly.bindEvent_(element, 'mouseout', null, Blockly.Tooltip.onMouseOut_);
Blockly.bindEvent_(element, 'mousemove', null, Blockly.Tooltip.onMouseMove_);
// Don't use bindEvent_ for mousemove since that would create a
// corresponding touch handler, even though this only makes sense in the
// context of a mouseover/mouseout.
element.addEventListener('mousemove', Blockly.Tooltip.onMouseMove_, false);
};

@@ -139,0 +143,0 @@

@@ -31,2 +31,3 @@ /**

goog.require('Blockly.Touch');
goog.require('goog.dom');

@@ -106,33 +107,46 @@ goog.require('goog.events.BrowserFeature');

* @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.
* @return {!Array.<!Array>} Opaque data that can be passed to unbindEvent_.
* @private
*/
Blockly.bindEvent_ = function(node, name, thisObject, func) {
if (thisObject) {
var wrapFunc = function(e) {
func.call(thisObject, e);
};
} else {
var wrapFunc = func;
}
Blockly.bindEvent_ = function(node, name, thisObject, func,
opt_noCaptureIdentifier) {
var handled = false;
var wrapFunc = function(e) {
var captureIdentifier = !opt_noCaptureIdentifier;
// Handle each touch point separately. If the event was a mouse event, this
// will hand back an array with one element, which we're fine handling.
var events = Blockly.Touch.splitEventByTouches(e);
for (var i = 0, event; event = events[i]; i++) {
if (captureIdentifier && !Blockly.Touch.shouldHandleEvent(event)) {
continue;
}
Blockly.Touch.setClientFromTouch(event);
if (thisObject) {
func.call(thisObject, event);
} else {
func(event);
}
handled = true;
}
};
node.addEventListener(name, wrapFunc, false);
var bindData = [[node, name, wrapFunc]];
// Add equivalent touch event.
if (name in Blockly.bindEvent_.TOUCH_MAP) {
wrapFunc = function(e) {
// Punt on multitouch events.
if (e.changedTouches.length == 1) {
// Map the touch event's properties to the event.
var touchPoint = e.changedTouches[0];
e.clientX = touchPoint.clientX;
e.clientY = touchPoint.clientY;
if (name in Blockly.Touch.TOUCH_MAP) {
var touchWrapFunc = function(e) {
wrapFunc(e);
// Stop the browser from scrolling/zooming the page.
if (handled) {
e.preventDefault();
}
func.call(thisObject, e);
// Stop the browser from scrolling/zooming the page.
e.preventDefault();
};
for (var i = 0, eventName;
eventName = Blockly.bindEvent_.TOUCH_MAP[name][i]; i++) {
node.addEventListener(eventName, wrapFunc, false);
bindData.push([node, eventName, wrapFunc]);
eventName = Blockly.Touch.TOUCH_MAP[name][i]; i++) {
node.addEventListener(eventName, touchWrapFunc, false);
bindData.push([node, eventName, touchWrapFunc]);
}

@@ -144,16 +158,2 @@ }

/**
* The TOUCH_MAP lookup dictionary specifies additional touch events to fire,
* in conjunction with mouse events.
* @type {Object}
*/
Blockly.bindEvent_.TOUCH_MAP = {};
if (goog.events.BrowserFeature.TOUCH_ENABLED) {
Blockly.bindEvent_.TOUCH_MAP = {
'mousedown': ['touchstart'],
'mousemove': ['touchmove'],
'mouseup': ['touchend', 'touchcancel']
};
}
/**
* Unbind one or more events event from a function call.

@@ -160,0 +160,0 @@ * @param {!Array.<!Array>} bindData Opaque data from bindEvent_. This list is

@@ -38,2 +38,3 @@ /**

goog.require('Blockly.ScrollbarPair');
goog.require('Blockly.Touch');
goog.require('Blockly.Trashcan');

@@ -765,3 +766,4 @@ goog.require('Blockly.Workspace');

Blockly.WorkspaceSvg.superClass_.createVariable.call(this, name);
if (this.toolbox_ && this.toolbox_.flyout_) {
// Don't refresh the toolbox if there's a drag in progress.
if (this.toolbox_ && this.toolbox_.flyout_ && !Blockly.Flyout.startFlyout_) {
this.toolbox_.refreshSelection();

@@ -823,2 +825,3 @@ }

if (Blockly.isTargetInput_(e)) {
Blockly.Touch.clearTouchIdentifier();
return;

@@ -839,2 +842,4 @@ }

this.showContextMenu_(e);
// Since this was a click, not a drag, end the gesture immediately.
Blockly.Touch.clearTouchIdentifier();
} else if (this.scrollbar) {

@@ -853,5 +858,5 @@ this.dragMode_ = Blockly.DRAG_BEGIN;

// bound to the document instead of the SVG's surface.
if ('mouseup' in Blockly.bindEvent_.TOUCH_MAP) {
Blockly.onTouchUpWrapper_ = Blockly.onTouchUpWrapper_ || [];
Blockly.onTouchUpWrapper_ = Blockly.onTouchUpWrapper_.concat(
if ('mouseup' in Blockly.Touch.TOUCH_MAP) {
Blockly.Touch.onTouchUpWrapper_ = Blockly.Touch.onTouchUpWrapper_ || [];
Blockly.Touch.onTouchUpWrapper_ = Blockly.Touch.onTouchUpWrapper_.concat(
Blockly.bindEvent_(document, 'mouseup', null, Blockly.onMouseUp_));

@@ -858,0 +863,0 @@ }

@@ -29,2 +29,3 @@ /**

goog.require('Blockly.Touch');
goog.require('goog.dom');

@@ -169,2 +170,3 @@

workspace.scrollCenter();
Blockly.Touch.clearTouchIdentifier(); // Don't block future drags.
e.stopPropagation(); // Don't start a workspace scroll.

@@ -175,2 +177,3 @@ e.preventDefault(); // Stop double-clicking from selecting text.

workspace.zoomCenter(1);
Blockly.Touch.clearTouchIdentifier(); // Don't block future drags.
e.stopPropagation(); // Don't start a workspace scroll.

@@ -181,2 +184,3 @@ e.preventDefault(); // Stop double-clicking from selecting text.

workspace.zoomCenter(-1);
Blockly.Touch.clearTouchIdentifier(); // Don't block future drags.
e.stopPropagation(); // Don't start a workspace scroll.

@@ -183,0 +187,0 @@ e.preventDefault(); // Stop double-clicking from selecting text.

{
"@metadata": {
"author": "Ellen Spertus <ellen.spertus@gmail.com>",
"lastupdated": "2016-09-22 15:25:43.285238",
"lastupdated": "2016-09-27 02:37:33.769445",
"locale": "en",

@@ -6,0 +6,0 @@ "messagedocumentation" : "qqq"

{
"name": "scratch-blocks",
"version": "0.1.0-1c642",
"version": "0.1.0-1da4d",
"description": "Scratch Blocks is a library for building creative computing interfaces.",

@@ -14,9 +14,9 @@ "author": "Massachusetts Institute of Technology",

"scripts": {
"prepublish": "./node_modules/.bin/webpack",
"prepublish": "python ./build.py && ./node_modules/.bin/webpack",
"test": "./node_modules/.bin/eslint ."
},
"dependencies": {},
"devDependencies": {
"eslint": "2.9.0",
"exports-loader": "0.6.3",
"google-closure-library": "20160911.0.0",
"imports-loader": "0.6.5",

@@ -23,0 +23,0 @@ "travis-after-all": "1.4.4",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc