scratch-blocks 2.0.0-spork.2 → 2.0.0-spork.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/main.js +1 -1
- package/dist/main.js.LICENSE.txt +0 -12
- package/package.json +4 -4
- package/src/{block_reporting.js → block_reporting.ts} +7 -5
- package/src/blocks/{colour.js → colour.ts} +6 -6
- package/src/blocks/{control.js → control.ts} +21 -54
- package/src/blocks/{data.js → data.ts} +134 -142
- package/src/blocks/{event.js → event.ts} +12 -33
- package/src/blocks/{looks.js → looks.ts} +24 -73
- package/src/blocks/{math.js → math.ts} +6 -11
- package/src/blocks/{matrix.js → matrix.ts} +2 -3
- package/src/blocks/{motion.js → motion.ts} +23 -70
- package/src/blocks/{note.js → note.ts} +2 -3
- package/src/blocks/{operators.js → operators.ts} +18 -55
- package/src/blocks/{procedures.js → procedures.ts} +418 -269
- package/src/blocks/{sensing.js → sensing.ts} +21 -61
- package/src/blocks/{sound.js → sound.ts} +9 -28
- package/src/blocks/{text.js → text.ts} +1 -2
- package/src/blocks/{vertical_extensions.js → vertical_extensions.ts} +63 -100
- package/src/checkable_continuous_flyout.ts +112 -0
- package/src/{checkbox_bubble.js → checkbox_bubble.ts} +40 -58
- package/src/{colours.js → colours.ts} +11 -4
- package/src/{constants.js → constants.ts} +13 -0
- package/src/{context_menu_items.js → context_menu_items.ts} +18 -12
- package/src/{css.js → css.ts} +13 -7
- package/src/{data_category.js → data_category.ts} +216 -150
- package/src/events/{events_block_comment_base.js → events_block_comment_base.ts} +23 -4
- package/src/events/{events_block_comment_change.js → events_block_comment_change.ts} +29 -5
- package/src/events/{events_block_comment_collapse.js → events_block_comment_collapse.ts} +24 -6
- package/src/events/{events_block_comment_create.js → events_block_comment_create.ts} +36 -10
- package/src/events/{events_block_comment_delete.js → events_block_comment_delete.ts} +6 -2
- package/src/events/{events_block_comment_move.js → events_block_comment_move.ts} +36 -6
- package/src/events/events_block_comment_resize.ts +88 -0
- package/src/events/events_block_drag_end.ts +49 -0
- package/src/events/events_block_drag_outside.ts +44 -0
- package/src/events/{events_scratch_variable_create.js → events_scratch_variable_create.ts} +28 -15
- package/src/fields/{field_colour_slider.js → field_colour_slider.ts} +117 -106
- package/src/fields/{field_matrix.js → field_matrix.ts} +189 -215
- package/src/fields/{field_note.js → field_note.ts} +227 -286
- package/src/fields/{field_textinput_removable.js → field_textinput_removable.ts} +17 -20
- package/src/fields/{field_variable_getter.js → field_variable_getter.ts} +28 -17
- package/src/fields/{field_vertical_separator.js → field_vertical_separator.ts} +14 -30
- package/src/fields/{field_angle.js → scratch_field_angle.ts} +124 -80
- package/src/fields/{field_dropdown.js → scratch_field_dropdown.ts} +9 -7
- package/src/fields/{field_number.js → scratch_field_number.ts} +60 -55
- package/src/fields/{field_variable.js → scratch_field_variable.ts} +46 -27
- package/src/{flyout_checkbox_icon.js → flyout_checkbox_icon.ts} +15 -19
- package/src/{glows.js → glows.ts} +29 -18
- package/src/index.ts +62 -63
- package/src/procedures.ts +462 -0
- package/src/recyclable_block_flyout_inflater.ts +51 -0
- package/src/renderer/{bowler_hat.js → bowler_hat.ts} +1 -1
- package/src/renderer/{constants.js → constants.ts} +26 -12
- package/src/renderer/{drawer.js → drawer.ts} +8 -3
- package/src/renderer/{path_object.js → path_object.ts} +2 -2
- package/src/renderer/{render_info.js → render_info.ts} +19 -7
- package/src/renderer/renderer.ts +76 -0
- package/src/{scratch_block_paster.js → scratch_block_paster.ts} +9 -7
- package/src/scratch_blocks_utils.ts +39 -0
- package/src/{scratch_comment_icon.js → scratch_comment_icon.ts} +43 -26
- package/src/scratch_connection_checker.ts +44 -0
- package/src/{scratch_continuous_category.js → scratch_continuous_category.ts} +20 -13
- package/src/scratch_continuous_toolbox.ts +70 -0
- package/src/{scratch_dragger.js → scratch_dragger.ts} +97 -28
- package/src/{scratch_variable_map.js → scratch_variable_map.ts} +4 -1
- package/src/scratch_variable_model.ts +30 -0
- package/src/{shadows.js → shadows.ts} +8 -4
- package/src/{status_indicator_label.js → status_indicator_label.ts} +24 -36
- package/src/{status_indicator_label_flyout_inflater.js → status_indicator_label_flyout_inflater.ts} +13 -9
- package/src/{variables.js → variables.ts} +153 -123
- package/tsconfig.json +5 -0
- package/src/categories.js +0 -15
- package/src/checkable_continuous_flyout.js +0 -138
- package/src/events/events_block_comment_resize.js +0 -52
- package/src/events/events_block_drag_end.js +0 -33
- package/src/events/events_block_drag_outside.js +0 -30
- package/src/procedures.js +0 -425
- package/src/recyclable_block_flyout_inflater.js +0 -194
- package/src/renderer/renderer.js +0 -74
- package/src/scratch_blocks_utils.js +0 -148
- package/src/scratch_connection_checker.js +0 -29
- package/src/scratch_continuous_toolbox.js +0 -78
- package/src/scratch_variable_model.js +0 -24
- /package/{continuous-toolbox.d.ts → types/continuous-toolbox.d.ts} +0 -0
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Visual Blocks Editor
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2018 Google Inc.
|
|
6
|
-
* https://developers.google.com/blockly/
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
-
* you may not use this file except in compliance with the License.
|
|
10
|
-
* You may obtain a copy of the License at
|
|
11
|
-
*
|
|
12
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @fileoverview Utility methods for Scratch Blocks but not Blockly.
|
|
23
|
-
* @author fenichel@google.com (Rachel Fenichel)
|
|
24
|
-
*/
|
|
25
|
-
import * as Blockly from "blockly/core";
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Re-assign obscured shadow blocks new IDs to prevent collisions
|
|
29
|
-
* Scratch specific to help the VM handle deleting obscured shadows.
|
|
30
|
-
* @param {Blockly.Block} block the root block to be processed.
|
|
31
|
-
* @package
|
|
32
|
-
*/
|
|
33
|
-
export function changeObscuredShadowIds(block) {
|
|
34
|
-
var blocks = block.getDescendants(false);
|
|
35
|
-
for (var i = blocks.length - 1; i >= 0; i--) {
|
|
36
|
-
var descendant = blocks[i];
|
|
37
|
-
for (var j = 0; j < descendant.inputList.length; j++) {
|
|
38
|
-
var connection = descendant.inputList[j].connection;
|
|
39
|
-
if (connection) {
|
|
40
|
-
var shadowDom = connection.getShadowDom();
|
|
41
|
-
if (shadowDom) {
|
|
42
|
-
shadowDom.setAttribute("id", Blockly.utils.genUid());
|
|
43
|
-
connection.setShadowDom(shadowDom);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Compare strings with natural number sorting.
|
|
52
|
-
* @param {string} str1 First input.
|
|
53
|
-
* @param {string} str2 Second input.
|
|
54
|
-
* @return {number} -1, 0, or 1 to signify greater than, equality, or less than.
|
|
55
|
-
*/
|
|
56
|
-
export function compareStrings(str1, str2) {
|
|
57
|
-
return str1.localeCompare(str2, [], {
|
|
58
|
-
sensitivity: "base",
|
|
59
|
-
numeric: true,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates a callback function for a click on the "duplicate" context menu
|
|
65
|
-
* option in Scratch Blocks. The block is duplicated and attached to the mouse,
|
|
66
|
-
* which acts as though it were pressed and mid-drag. Clicking the mouse
|
|
67
|
-
* releases the new dragging block.
|
|
68
|
-
* @param {!Blockly.BlockSvg} oldBlock The block that will be duplicated.
|
|
69
|
-
* @param {!Event} event Event that caused the context menu to open.
|
|
70
|
-
* @return {Function} A callback function that duplicates the block and starts a
|
|
71
|
-
* drag.
|
|
72
|
-
* @package
|
|
73
|
-
*/
|
|
74
|
-
export function duplicateAndDragCallback(oldBlock, event) {
|
|
75
|
-
var isMouseEvent =
|
|
76
|
-
Blockly.Touch.getTouchIdentifierFromEvent(event) === "mouse";
|
|
77
|
-
return function (e) {
|
|
78
|
-
// Give the context menu a chance to close.
|
|
79
|
-
setTimeout(function () {
|
|
80
|
-
var ws = oldBlock.workspace;
|
|
81
|
-
var svgRootOld = oldBlock.getSvgRoot();
|
|
82
|
-
if (!svgRootOld) {
|
|
83
|
-
throw new Error("oldBlock is not rendered.");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Create the new block by cloning the block in the flyout (via XML).
|
|
87
|
-
var xml = Blockly.Xml.blockToDom(oldBlock);
|
|
88
|
-
// The target workspace would normally resize during domToBlock, which
|
|
89
|
-
// will lead to weird jumps.
|
|
90
|
-
// Resizing will be enabled when the drag ends.
|
|
91
|
-
ws.setResizesEnabled(false);
|
|
92
|
-
|
|
93
|
-
// Disable events and manually emit events after the block has been
|
|
94
|
-
// positioned and has had its shadow IDs fixed (Scratch-specific).
|
|
95
|
-
Blockly.Events.disable();
|
|
96
|
-
try {
|
|
97
|
-
// Using domToBlock instead of domToWorkspace means that the new block
|
|
98
|
-
// will be placed at position (0, 0) in main workspace units.
|
|
99
|
-
var newBlock = Blockly.Xml.domToBlock(xml, ws);
|
|
100
|
-
|
|
101
|
-
// Scratch-specific: Give shadow dom new IDs to prevent duplicating on paste
|
|
102
|
-
changeObscuredShadowIds(newBlock);
|
|
103
|
-
|
|
104
|
-
var svgRootNew = newBlock.getSvgRoot();
|
|
105
|
-
if (!svgRootNew) {
|
|
106
|
-
throw new Error("newBlock is not rendered.");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// The position of the old block in workspace coordinates.
|
|
110
|
-
var oldBlockPosWs = oldBlock.getRelativeToSurfaceXY();
|
|
111
|
-
|
|
112
|
-
// Place the new block as the same position as the old block.
|
|
113
|
-
// TODO: Offset by the difference between the mouse position and the upper
|
|
114
|
-
// left corner of the block.
|
|
115
|
-
newBlock.moveBy(oldBlockPosWs.x, oldBlockPosWs.y);
|
|
116
|
-
if (!isMouseEvent) {
|
|
117
|
-
var offsetX = ws.RTL ? -100 : 100;
|
|
118
|
-
var offsetY = 100;
|
|
119
|
-
newBlock.moveBy(offsetX, offsetY); // Just offset the block for touch.
|
|
120
|
-
}
|
|
121
|
-
} finally {
|
|
122
|
-
Blockly.Events.enable();
|
|
123
|
-
}
|
|
124
|
-
if (Blockly.Events.isEnabled()) {
|
|
125
|
-
Blockly.Events.fire(new Blockly.Events.BlockCreate(newBlock));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (isMouseEvent) {
|
|
129
|
-
// e is not a real mouseEvent/touchEvent/pointerEvent. It's an event
|
|
130
|
-
// created by the context menu and has the coordinates of the mouse
|
|
131
|
-
// click that opened the context menu.
|
|
132
|
-
var fakeEvent = {
|
|
133
|
-
clientX: event.clientX,
|
|
134
|
-
clientY: event.clientY,
|
|
135
|
-
type: "mousedown",
|
|
136
|
-
preventDefault: function () {
|
|
137
|
-
e.preventDefault();
|
|
138
|
-
},
|
|
139
|
-
stopPropagation: function () {
|
|
140
|
-
e.stopPropagation();
|
|
141
|
-
},
|
|
142
|
-
target: e.target,
|
|
143
|
-
};
|
|
144
|
-
ws.startDragWithFakeEvent(fakeEvent, newBlock);
|
|
145
|
-
}
|
|
146
|
-
}, 0);
|
|
147
|
-
};
|
|
148
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2024 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as Blockly from "blockly/core";
|
|
8
|
-
|
|
9
|
-
class ScratchConnectionChecker extends Blockly.ConnectionChecker {
|
|
10
|
-
// This check prevents dragging a block into the slot occupied by the
|
|
11
|
-
// procedure caller example block in a procedure definition block.
|
|
12
|
-
doDragChecks(a, b, distance) {
|
|
13
|
-
if (
|
|
14
|
-
b.getSourceBlock().type === "procedures_definition" &&
|
|
15
|
-
b.getParentInput()?.name === "custom_block"
|
|
16
|
-
) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return super.doDragChecks(a, b, distance);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
Blockly.registry.register(
|
|
25
|
-
Blockly.registry.Type.CONNECTION_CHECKER,
|
|
26
|
-
Blockly.registry.DEFAULT,
|
|
27
|
-
ScratchConnectionChecker,
|
|
28
|
-
true
|
|
29
|
-
);
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2024 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as Blockly from "blockly/core";
|
|
8
|
-
import { ContinuousToolbox } from "@blockly/continuous-toolbox";
|
|
9
|
-
import { ScratchContinuousCategory } from "./scratch_continuous_category.js";
|
|
10
|
-
|
|
11
|
-
export class ScratchContinuousToolbox extends ContinuousToolbox {
|
|
12
|
-
postRenderCallbacks = [];
|
|
13
|
-
|
|
14
|
-
refreshSelection() {
|
|
15
|
-
// Intentionally a no-op, Scratch manually manages refreshing the toolbox via forceRerender().
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Gets the contents that should be shown in the flyout.
|
|
20
|
-
* @returns {!Blockly.utils.toolbox.FlyoutItemInfoArray} Flyout contents.
|
|
21
|
-
*/
|
|
22
|
-
getInitialFlyoutContents_() {
|
|
23
|
-
// TODO(#211) Clean this up when the continuous toolbox plugin is updated.
|
|
24
|
-
/** @type {!Blockly.utils.toolbox.FlyoutItemInfoArray} */
|
|
25
|
-
let contents = [];
|
|
26
|
-
for (const toolboxItem of this.getToolboxItems()) {
|
|
27
|
-
if (toolboxItem instanceof ScratchContinuousCategory) {
|
|
28
|
-
if (toolboxItem.shouldShowStatusButton()) {
|
|
29
|
-
contents.push({
|
|
30
|
-
kind: "STATUS_INDICATOR_LABEL",
|
|
31
|
-
id: toolboxItem.getId(),
|
|
32
|
-
text: toolboxItem.getName(),
|
|
33
|
-
});
|
|
34
|
-
} else {
|
|
35
|
-
// Create a label node to go at the top of the category
|
|
36
|
-
contents.push({ kind: "LABEL", text: toolboxItem.getName() });
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @type {string|Blockly.utils.toolbox.FlyoutItemInfoArray|
|
|
40
|
-
* Blockly.utils.toolbox.FlyoutItemInfo}
|
|
41
|
-
*/
|
|
42
|
-
let itemContents = toolboxItem.getContents();
|
|
43
|
-
|
|
44
|
-
// Handle custom categories (e.g. variables and functions)
|
|
45
|
-
if (typeof itemContents === "string") {
|
|
46
|
-
itemContents =
|
|
47
|
-
/** @type {!Blockly.utils.toolbox.DynamicCategoryInfo} */ ({
|
|
48
|
-
custom: itemContents,
|
|
49
|
-
kind: "CATEGORY",
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
contents = contents.concat(itemContents);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return contents;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Forcibly rerenders the toolbox, preserving selection when possible.
|
|
60
|
-
*/
|
|
61
|
-
forceRerender() {
|
|
62
|
-
const selectedCategoryName = this.selectedItem_?.getName();
|
|
63
|
-
super.refreshSelection();
|
|
64
|
-
let callback;
|
|
65
|
-
while ((callback = this.postRenderCallbacks.shift())) {
|
|
66
|
-
callback();
|
|
67
|
-
}
|
|
68
|
-
this.selectCategoryByName(selectedCategoryName);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Runs the specified callback after the next rerender.
|
|
73
|
-
* @param {!Function} A callback to run whenever the toolbox next rerenders.
|
|
74
|
-
*/
|
|
75
|
-
runAfterRerender(callback) {
|
|
76
|
-
this.postRenderCallbacks.push(callback);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2024 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as Blockly from "blockly/core";
|
|
8
|
-
|
|
9
|
-
class ScratchVariableModel extends Blockly.VariableModel {
|
|
10
|
-
constructor(workspace, name, type, id, isLocal, isCloud) {
|
|
11
|
-
super(workspace, name, type, id);
|
|
12
|
-
// isLocal and isCloud may not be passed when creating broadcast message
|
|
13
|
-
// variables, which conveniently are neither local nor cloud.
|
|
14
|
-
this.isLocal = !!isLocal;
|
|
15
|
-
this.isCloud = !!isCloud;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
Blockly.registry.register(
|
|
20
|
-
Blockly.registry.Type.VARIABLE_MODEL,
|
|
21
|
-
Blockly.registry.DEFAULT,
|
|
22
|
-
ScratchVariableModel,
|
|
23
|
-
true
|
|
24
|
-
);
|
|
File without changes
|