kopia lustrzana https://github.com/backface/turtlestitch
Merge branch 'master' into scenes
commit
d6b33e29bb
|
@ -100,6 +100,12 @@
|
|||
* **Notable Fixes:**
|
||||
* fixed occasional invisible error messages
|
||||
|
||||
### 2021-06-24
|
||||
* extensions: tweaked loading unlisted script-extensions
|
||||
* byob, threads, store: removed unused code
|
||||
* extensions: added documentation for adding external JS modules
|
||||
* updated bignumbers library
|
||||
|
||||
### 2021-06-23
|
||||
* updated bignums library
|
||||
* pushed dev version to 6.10
|
||||
|
|
|
@ -1 +1 @@
|
|||
<blocks app="Snap! 6, https://snap.berkeley.edu" version="1"><block-definition s="USE BIGNUMS %'bool'" type="command" category="operators"><comment x="0" y="0" w="303.3333333333333" collapsed="false">call with True to turn on the entire Scheme numeric tower, including infinite-precision integers, exact rationals, and complex numbers; call with False to restore native JavaScript arithmetic.</comment><header></header><code></code><translations>pt:altera utilização de aritmética do Scheme para _
</translations><inputs><input type="%b"></input></inputs><script><block s="doApplyExtension"><l>scr_load(url)</l><list><l>libraries/biginteger.js</l></list></block><block s="doApplyExtension"><l>scr_load(url)</l><list><l>libraries/schemeNumber.js</l></list></block><block s="doApplyExtension"><l>scr_load(url)</l><list><l>libraries/bignums.js</l></list></block><block s="doApplyExtension"><l>big_switch(bool)</l><list><block var="bool"/></list></block></script></block-definition><block-definition s="%'n' !" type="reporter" category="operators"><comment x="0" y="0" w="190.66666666666666" collapsed="false">The factorial function, to make very large numbers, to demo bignums.</comment><header></header><code></code><translations></translations><inputs><input type="%n"></input></inputs><script><block s="doReport"><block s="reportIfElse"><block s="reportEquals"><block var="n"/><l>0</l></block><l>1</l><block s="reportProduct"><block var="n"/><custom-block s="%n !"><block s="reportDifference"><block var="n"/><l>1</l></block></custom-block></block></block></block></script></block-definition><block-definition s="%'x'" type="reporter" category="operators"><comment x="0" y="0" w="234.66666666666666" collapsed="false">The identity function: reports its input.
It's useful to get things like 3/4 or 5-2i into
numeric input slots.</comment><header></header><code></code><translations></translations><inputs><input type="%s"></input></inputs><script><block s="doReport"><block var="x"/></block></script></block-definition><block-definition s="Scheme number %'function' of %'number'" type="reporter" category="operators"><comment x="0" y="0" w="300" collapsed="true">Provides Scheme arithmetic functions not in JavaScript</comment><header></header><code></code><translations>pt:_ de _
</translations><inputs><input type="%s" readonly="true"><options>number?
complex?
real?
rational?
integer?
exact?
inexact?
exact
inexact
finite?
infinite?
nan?
numerator
denominator
real-part
imag-part
magnitude
angle</options></input><input type="%s"></input></inputs><script><block s="doReport"><block s="reportApplyExtension"><l>big_scheme(fn, num)</l><list><block var="function"/><block var="number"/></list></block></block></script></block-definition></blocks>
|
||||
<blocks app="Snap! 6, https://snap.berkeley.edu" version="1"><block-definition s="USE BIGNUMS %'bool'" type="command" category="operators"><comment w="303.3333333333333" collapsed="false">call with True to turn on the entire Scheme numeric tower, including infinite-precision integers, exact rationals, and complex numbers; call with False to restore native JavaScript arithmetic.</comment><header></header><code></code><translations>pt:altera utilização de aritmética do Scheme para _
</translations><inputs><input type="%b"></input></inputs><script><block s="doApplyExtension"><l>src_load(url)</l><list><l>libraries/biginteger.js</l></list></block><block s="doApplyExtension"><l>src_load(url)</l><list><l>libraries/schemeNumber.js</l></list></block><block s="doApplyExtension"><l>src_load(url)</l><list><l>libraries/bignums.js</l></list></block><block s="doApplyExtension"><l>big_switch(bool)</l><list><block var="bool"/></list></block></script></block-definition><block-definition s="%'n' !" type="reporter" category="operators"><comment x="0" y="0" w="190.66666666666666" collapsed="false">The factorial function, to make very large numbers, to demo bignums.</comment><header></header><code></code><translations></translations><inputs><input type="%n"></input></inputs><script><block s="doReport"><block s="reportIfElse"><block s="reportEquals"><block var="n"/><l>0</l></block><l>1</l><block s="reportProduct"><block var="n"/><custom-block s="%n !"><block s="reportDifference"><block var="n"/><l>1</l></block></custom-block></block></block></block></script></block-definition><block-definition s="%'x'" type="reporter" category="operators"><comment x="0" y="0" w="234.66666666666666" collapsed="false">The identity function: reports its input.
It's useful to get things like 3/4 or 5-2i into
numeric input slots.</comment><header></header><code></code><translations></translations><inputs><input type="%s"></input></inputs><script><block s="doReport"><block var="x"/></block></script></block-definition><block-definition s="Scheme number %'function' of %'number'" type="reporter" category="operators"><comment x="0" y="0" w="300" collapsed="true">Provides Scheme arithmetic functions not in JavaScript</comment><header></header><code></code><translations>pt:_ de _
</translations><inputs><input type="%s" readonly="true"><options>number?
complex?
real?
rational?
integer?
exact?
inexact?
exact
inexact
finite?
infinite?
nan?
numerator
denominator
real-part
imag-part
magnitude
angle</options></input><input type="%s"></input></inputs><script><block s="doReport"><block s="reportApplyExtension"><l>big_scheme(fn, num)</l><list><block var="function"/><block var="number"/></list></block></block></script></block-definition></blocks>
|
|
@ -9,20 +9,20 @@
|
|||
<script src="src/symbols.js?version=2021-03-03"></script>
|
||||
<script src="src/widgets.js?version=2021-01-05"></script>
|
||||
<script src="src/blocks.js?version=2021-06-18"></script>
|
||||
<script src="src/threads.js?version=2021-06-18"></script>
|
||||
<script src="src/threads.js?version=2021-06-24"></script>
|
||||
<script src="src/objects.js?version=2021-06-14"></script>
|
||||
<script src="src/scenes.js?version=2021-05-21"></script>
|
||||
<script src="src/gui.js?version=2021-06-23"></script>
|
||||
<script src="src/paint.js?version=2020-05-17"></script>
|
||||
<script src="src/lists.js?version=2021-03-15"></script>
|
||||
<script src="src/byob.js?version=2021-06-19"></script>
|
||||
<script src="src/byob.js?version=2021-06-24"></script>
|
||||
<script src="src/tables.js?version=2021-03-05"></script>
|
||||
<script src="src/sketch.js?version=2021-03-17"></script>
|
||||
<script src="src/video.js?version=2019-06-27"></script>
|
||||
<script src="src/maps.js?version=2021-06-15"></script>
|
||||
<script src="src/extensions.js?version=2021-06-23"></script>
|
||||
<script src="src/extensions.js?version=2021-06-24"></script>
|
||||
<script src="src/xml.js?version=2020-04-27"></script>
|
||||
<script src="src/store.js?version=2021-06-10"></script>
|
||||
<script src="src/store.js?version=2021-06-24"></script>
|
||||
<script src="src/locale.js?version=2021-06-11"></script>
|
||||
<script src="src/cloud.js?version=2021-02-04"></script>
|
||||
<script src="src/api.js?version=2021-01-25"></script>
|
||||
|
|
|
@ -106,7 +106,7 @@ WatcherMorph, XML_Serializer, SnapTranslator, SnapExtensions*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.byob = '2021-June-19';
|
||||
modules.byob = '2021-June-24';
|
||||
|
||||
// Declarations
|
||||
|
||||
|
@ -347,11 +347,6 @@ CustomBlockDefinition.prototype.parseChoices = function (string) {
|
|||
if (string.match(/^function\s*\(.*\)\s*{.*\n/)) {
|
||||
// It's a JS function definition.
|
||||
// Let's extract its params and body, and return a Function out of them.
|
||||
/*
|
||||
if (!Process.prototype.enableJS) {
|
||||
throw new Error('JavaScript is not enabled');
|
||||
}
|
||||
*/
|
||||
params = string.match(/^function\s*\((.*)\)/)[1].split(',');
|
||||
body = string.split('\n').slice(1,-1).join('\n');
|
||||
return Function.apply(null, params.concat([body]));
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
|
||||
/*global modules, List, StageMorph, Costume, SpeechSynthesisUtterance, Sound,
|
||||
IDE_Morph, CamSnapshotDialogMorph, SoundRecorderDialogMorph, isSnapObject, nop,
|
||||
Color, contains*/
|
||||
Color, Process, contains*/
|
||||
|
||||
modules.extensions = '2021-June-23';
|
||||
modules.extensions = '2021-June-24';
|
||||
|
||||
// Global stuff
|
||||
|
||||
|
@ -50,6 +50,11 @@ var SnapExtensions = {
|
|||
extensions are stored in the "primitives" dictionary of SnapExtensions,
|
||||
dynamic dropdown menus in the "menus" section.
|
||||
|
||||
You can also extend Snap! with your own externally hosted JavaScript file(s)
|
||||
and have them add your own extension primitives and menus to the global
|
||||
SnapExtensions dictionaries. This lets you provide libraries to support
|
||||
special APIs and custom hardware.
|
||||
|
||||
|
||||
1. Primitives (additional blocks)
|
||||
=================================
|
||||
|
@ -109,6 +114,37 @@ var SnapExtensions = {
|
|||
"block.inputs()". This will give you an array of all input slots.
|
||||
You can access the contents of an input slot by calling "slot.evaluate()"
|
||||
|
||||
|
||||
3. External JavaScript files
|
||||
============================
|
||||
You can provide extensions for your custom hardware or for arbitrary APIs
|
||||
or extend Snap! with JavaScript libraries from other parties. You can
|
||||
load additional JavaScript files using the "src_load(url)" extension
|
||||
primitive inside Snap, which you can find using Snap's search bar in the
|
||||
IDE. The loading primitive will wait until the source file has fully loaded
|
||||
and its defined functions are ready to be called.
|
||||
|
||||
adding primitives to SnapExtensions
|
||||
-----------------------------------
|
||||
It is the suggested best practice to expose your own extension primitives
|
||||
by adding them to the global SnapExtensions libraries (for primitives and
|
||||
menus) using the very same conventions described herein, and then to offer
|
||||
a library of custom blocks that make calls to your additional operations.
|
||||
|
||||
publishing an extension
|
||||
-----------------------
|
||||
Running the "src_load(url)" primitive will throw an error unless you first
|
||||
check the "Enable JavaScript extensions" setting in Snap's preferences menu,
|
||||
or if your JavaScript extension comes from a list of trusted hosts.
|
||||
While you develop your JavaScript extension it's recommended to turn the
|
||||
"Enable JavaScript extensions" setting on to load the extension once, and
|
||||
then to turn it off again, so you can make sure your custom blocks are not
|
||||
using any "JS Function" blocks (because those will be caught if the
|
||||
preference is turned off).
|
||||
When you're ready to publish your extension you can contact us to allow-list
|
||||
the url hosting your JS file, or you can send me a Github pull-request to
|
||||
include it in the main Snap branch.
|
||||
|
||||
Whatever you do, please use these extension capabilities sensibly.
|
||||
*/
|
||||
|
||||
|
@ -680,10 +716,10 @@ SnapExtensions.primitives.set(
|
|||
}
|
||||
);
|
||||
|
||||
// loading external scripts (scr_)
|
||||
// loading external scripts (src_)
|
||||
|
||||
SnapExtensions.primitives.set(
|
||||
'scr_load(url)',
|
||||
'src_load(url)',
|
||||
function (url, proc) {
|
||||
var scriptElement;
|
||||
if (!proc.context.accumulator) {
|
||||
|
@ -691,23 +727,28 @@ SnapExtensions.primitives.set(
|
|||
if (contains(SnapExtensions.scripts, url)) {
|
||||
return;
|
||||
}
|
||||
if (!(SnapExtensions.urls.some(any => url.indexOf(any) === 0))) {
|
||||
throw new Error('unlisted extension url:\n"' + url + '"');
|
||||
if (Process.prototype.enableJS || SnapExtensions.urls.some(
|
||||
any => url.indexOf(any) === 0)
|
||||
) {
|
||||
scriptElement = document.createElement('script');
|
||||
scriptElement.onload = () => {
|
||||
SnapExtensions.scripts.push(url);
|
||||
proc.context.accumulator.done = true;
|
||||
};
|
||||
document.head.appendChild(scriptElement);
|
||||
scriptElement.src = url;
|
||||
} else {
|
||||
throw new Error(
|
||||
'unlisted extension url:\n"' + url + '"\n' +
|
||||
'JavaScript extensions for Snap!\nare turned off'
|
||||
);
|
||||
}
|
||||
scriptElement = document.createElement('script');
|
||||
scriptElement.onload = () => {
|
||||
SnapExtensions.scripts.push(url);
|
||||
proc.context.accumulator.done = true;
|
||||
};
|
||||
document.head.appendChild(scriptElement);
|
||||
scriptElement.src = url;
|
||||
} else if (proc.context.accumulator.done) {
|
||||
return;
|
||||
}
|
||||
proc.pushContext('doYield');
|
||||
proc.pushContext();
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
// Menus
|
||||
|
|
13
src/store.js
13
src/store.js
|
@ -61,7 +61,7 @@ Project*/
|
|||
|
||||
// Global stuff ////////////////////////////////////////////////////////
|
||||
|
||||
modules.store = '2021-June-10';
|
||||
modules.store = '2021-June-24';
|
||||
|
||||
// XML_Serializer ///////////////////////////////////////////////////////
|
||||
/*
|
||||
|
@ -1174,17 +1174,6 @@ SnapSerializer.prototype.loadBlock = function (model, isReporter, object) {
|
|||
model.attributes['var']
|
||||
);
|
||||
} else {
|
||||
// disable loading JavaScript functions
|
||||
/*
|
||||
if (model.attributes.s === 'reportJSFunction' &&
|
||||
!Process.prototype.enableJS) {
|
||||
if (window.confirm('enable JavaScript?')) {
|
||||
Process.prototype.enableJS = true;
|
||||
} else {
|
||||
throw new Error('JavaScript is not enabled');
|
||||
}
|
||||
}
|
||||
*/
|
||||
block = SpriteMorph.prototype.blockForSelector(model.attributes.s);
|
||||
migration = SpriteMorph.prototype.blockMigrations[
|
||||
model.attributes.s
|
||||
|
|
|
@ -62,7 +62,7 @@ isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, BLACK,
|
|||
TableFrameMorph, ColorSlotMorph, isSnapObject, newCanvas, Symbol, SVG_Costume,
|
||||
SnapExtensions*/
|
||||
|
||||
modules.threads = '2021-June-18';
|
||||
modules.threads = '2021-June-24';
|
||||
|
||||
var ThreadManager;
|
||||
var Process;
|
||||
|
@ -1254,11 +1254,6 @@ Process.prototype.evaluate = function (
|
|||
return this.returnValueToParentContext(null);
|
||||
}
|
||||
if (context instanceof Function) {
|
||||
/*
|
||||
if (!this.enableJS) {
|
||||
throw new Error('JavaScript extensions for Snap!\nare turned off');
|
||||
}
|
||||
*/
|
||||
return context.apply(
|
||||
this.blockReceiver(),
|
||||
args.itemsArray().concat([this])
|
||||
|
|
Ładowanie…
Reference in New Issue