Skip to content

Commit

Permalink
update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
SebCanet committed Oct 7, 2020
1 parent b5d9e6e commit 17ef8d6
Show file tree
Hide file tree
Showing 41 changed files with 1,218 additions and 893 deletions.
2 changes: 1 addition & 1 deletion @blockly/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Want to contribute? Great! First, read [our guidelines for contributors](https:/

## Releases

The next major release will be **June 26th, 2020**.
The next major release will be **September 25th, 2020**.

We release by pushing the latest code to the master branch, followed by updating our [docs](https://developers.google.com/blockly) and [demo pages](https://blockly-demo.appspot.com). We typically release a new version of Blockly once a quarter (every 3 months). If there are breaking bugs, such as a crash when performing a standard action or a rendering issue that makes Blockly unusable, we will cherry-pick fixes to master between releases to fix them. The [releases page](https://github.com/google/blockly/releases) has a list of all releases.

Expand Down
789 changes: 418 additions & 371 deletions @blockly/blockly_compressed.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion @blockly/blockly_compressed.js.map

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions @blockly/blocks_compressed.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion @blockly/blocks_compressed.js.map

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions @blockly/core/workspace_audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Object in charge of loading, storing, and playing audio for a
* workspace.
* @author [email protected] (Rachel Fenichel)
*/
'use strict';

goog.provide('Blockly.WorkspaceAudio');

goog.require('Blockly.utils');
goog.require('Blockly.utils.global');
goog.require('Blockly.utils.userAgent');


/**
* Class for loading, storing, and playing audio for a workspace.
* @param {Blockly.WorkspaceSvg} parentWorkspace The parent of the workspace
* this audio object belongs to, or null.
* @constructor
*/
Blockly.WorkspaceAudio = function(parentWorkspace) {

/**
* The parent of the workspace this object belongs to, or null. May be
* checked for sounds that this object can't find.
* @type {Blockly.WorkspaceSvg}
* @private
*/
this.parentWorkspace_ = parentWorkspace;

/**
* Database of pre-loaded sounds.
* @private
*/
this.SOUNDS_ = Object.create(null);
};

/**
* Time that the last sound was played.
* @type {Date}
* @private
*/
Blockly.WorkspaceAudio.prototype.lastSound_ = null;

/**
* Dispose of this audio manager.
* @package
*/
Blockly.WorkspaceAudio.prototype.dispose = function() {
this.parentWorkspace_ = null;
this.SOUNDS_ = null;
};

/**
* Load an audio file. Cache it, ready for instantaneous playing.
* @param {!Array.<string>} filenames List of file types in decreasing order of
* preference (i.e. increasing size). E.g. ['media/go.mp3', 'media/go.wav']
* Filenames include path from Blockly's root. File extensions matter.
* @param {string} name Name of sound.
*/
Blockly.WorkspaceAudio.prototype.load = function(filenames, name) {
if (!filenames.length) {
return;
}
try {
var audioTest = new Blockly.utils.global['Audio']();
} catch (e) {
// No browser support for Audio.
// IE can throw an error even if the Audio object exists.
return;
}
var sound;
for (var i = 0; i < filenames.length; i++) {
var filename = filenames[i];
var ext = filename.match(/\.(\w+)$/);
if (ext && audioTest.canPlayType('audio/' + ext[1])) {
// Found an audio format we can play.
sound = new Blockly.utils.global['Audio'](filename);
break;
}
}
if (sound && sound.play) {
this.SOUNDS_[name] = sound;
}
};

/**
* Preload all the audio files so that they play quickly when asked for.
* @package
*/
Blockly.WorkspaceAudio.prototype.preload = function() {
for (var name in this.SOUNDS_) {
var sound = this.SOUNDS_[name];
sound.volume = 0.01;
var playPromise = sound.play();
// Edge does not return a promise, so we need to check.
if (playPromise !== undefined) {
// If we don't wait for the play request to complete before calling pause()
// we will get an exception: (DOMException: The play() request was interrupted)
// See more: https://developers.google.com/web/updates/2017/06/play-request-was-interrupted
playPromise.then(sound.pause).catch(function() {
// Play without user interaction was prevented.
});
} else {
sound.pause();
}

// iOS can only process one sound at a time. Trying to load more than one
// corrupts the earlier ones. Just load one and leave the others uncached.
if (Blockly.utils.userAgent.IPAD || Blockly.utils.userAgent.IPHONE) {
break;
}
}
};

/**
* Play a named sound at specified volume. If volume is not specified,
* use full volume (1).
* @param {string} name Name of sound.
* @param {number=} opt_volume Volume of sound (0-1).
*/
Blockly.WorkspaceAudio.prototype.play = function(name, opt_volume) {
var sound = this.SOUNDS_[name];
if (sound) {
// Don't play one sound on top of another.
var now = new Date;
if (this.lastSound_ != null &&
now - this.lastSound_ < Blockly.SOUND_LIMIT) {
return;
}
this.lastSound_ = now;
var mySound;
if (Blockly.utils.userAgent.IPAD || Blockly.utils.userAgent.ANDROID) {
// Creating a new audio node causes lag in Android and iPad. Android
// refetches the file from the server, iPad uses a singleton audio
// node which must be deleted and recreated for each new audio tag.
mySound = sound;
} else {
mySound = sound.cloneNode();
}
mySound.volume = (opt_volume === undefined ? 1 : opt_volume);
mySound.play();
} else if (this.parentWorkspace_) {
// Maybe a workspace on a lower level knows about this sound.
this.parentWorkspace_.getAudioManager().play(name, opt_volume);
}
};
26 changes: 15 additions & 11 deletions @blockly/core/workspace_comment_render_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ goog.provide('Blockly.WorkspaceCommentSvg.render');
goog.require('Blockly.utils');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.Svg');


/**
Expand Down Expand Up @@ -74,14 +75,16 @@ Blockly.WorkspaceCommentSvg.prototype.render = function() {
this.createEditor_();
this.svgGroup_.appendChild(this.foreignObject_);

this.svgHandleTarget_ = Blockly.utils.dom.createSvgElement('rect',
this.svgHandleTarget_ = Blockly.utils.dom.createSvgElement(
Blockly.utils.Svg.RECT,
{
'class': 'blocklyCommentHandleTarget',
'x': 0,
'y': 0
});
this.svgGroup_.appendChild(this.svgHandleTarget_);
this.svgRectTarget_ = Blockly.utils.dom.createSvgElement('rect',
this.svgRectTarget_ = Blockly.utils.dom.createSvgElement(
Blockly.utils.Svg.RECT,
{
'class': 'blocklyCommentTarget',
'x': 0,
Expand Down Expand Up @@ -136,7 +139,7 @@ Blockly.WorkspaceCommentSvg.prototype.createEditor_ = function() {
</foreignObject>
*/
this.foreignObject_ = Blockly.utils.dom.createSvgElement(
'foreignObject',
Blockly.utils.Svg.FOREIGNOBJECT,
{
'x': 0,
'y': Blockly.WorkspaceCommentSvg.TOP_OFFSET,
Expand Down Expand Up @@ -171,25 +174,25 @@ Blockly.WorkspaceCommentSvg.prototype.createEditor_ = function() {
*/
Blockly.WorkspaceCommentSvg.prototype.addResizeDom_ = function() {
this.resizeGroup_ = Blockly.utils.dom.createSvgElement(
'g',
Blockly.utils.Svg.G,
{
'class': this.RTL ? 'blocklyResizeSW' : 'blocklyResizeSE'
},
this.svgGroup_);
var resizeSize = Blockly.WorkspaceCommentSvg.RESIZE_SIZE;
Blockly.utils.dom.createSvgElement(
'polygon',
Blockly.utils.Svg.POLYGON,
{'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())},
this.resizeGroup_);
Blockly.utils.dom.createSvgElement(
'line',
Blockly.utils.Svg.LINE,
{
'class': 'blocklyResizeLine',
'x1': resizeSize / 3, 'y1': resizeSize - 1,
'x2': resizeSize - 1, 'y2': resizeSize / 3
}, this.resizeGroup_);
Blockly.utils.dom.createSvgElement(
'line',
Blockly.utils.Svg.LINE,
{
'class': 'blocklyResizeLine',
'x1': resizeSize * 2 / 3, 'y1': resizeSize - 1,
Expand All @@ -203,12 +206,13 @@ Blockly.WorkspaceCommentSvg.prototype.addResizeDom_ = function() {
*/
Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_ = function() {
this.deleteGroup_ = Blockly.utils.dom.createSvgElement(
'g',
Blockly.utils.Svg.G,
{
'class': 'blocklyCommentDeleteIcon'
},
this.svgGroup_);
this.deleteIconBorder_ = Blockly.utils.dom.createSvgElement('circle',
this.deleteIconBorder_ = Blockly.utils.dom.createSvgElement(
Blockly.utils.Svg.CIRCLE,
{
'class': 'blocklyDeleteIconShape',
'r': '7',
Expand All @@ -218,7 +222,7 @@ Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_ = function() {
this.deleteGroup_);
// x icon.
Blockly.utils.dom.createSvgElement(
'line',
Blockly.utils.Svg.LINE,
{
'x1': '5', 'y1': '10',
'x2': '10', 'y2': '5',
Expand All @@ -227,7 +231,7 @@ Blockly.WorkspaceCommentSvg.prototype.addDeleteDom_ = function() {
},
this.deleteGroup_);
Blockly.utils.dom.createSvgElement(
'line',
Blockly.utils.Svg.LINE,
{
'x1': '5', 'y1': '5',
'x2': '10', 'y2': '10',
Expand Down
Loading

0 comments on commit 17ef8d6

Please sign in to comment.