scratch-blocks 2.0.0-spork.3 → 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 +7 -0
- package/dist/main.js +1 -1
- package/dist/main.js.LICENSE.txt +0 -12
- package/package.json +4 -4
- package/src/checkable_continuous_flyout.ts +112 -0
- package/src/checkbox_bubble.ts +4 -5
- package/src/css.ts +13 -7
- package/src/index.ts +3 -3
- package/src/recyclable_block_flyout_inflater.ts +8 -151
- package/src/scratch_continuous_toolbox.ts +20 -30
- package/src/status_indicator_label_flyout_inflater.ts +5 -3
- package/src/variables.ts +1 -1
- package/src/checkable_continuous_flyout.js +0 -138
|
@@ -1,138 +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 { ContinuousFlyout } from "@blockly/continuous-toolbox";
|
|
9
|
-
import { RecyclableBlockFlyoutInflater } from "./recyclable_block_flyout_inflater";
|
|
10
|
-
import { StatusIndicatorLabel } from "./status_indicator_label";
|
|
11
|
-
|
|
12
|
-
export class CheckableContinuousFlyout extends ContinuousFlyout {
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new CheckableContinuousFlyout.
|
|
15
|
-
*
|
|
16
|
-
* @param {!Blockly.Options} workspaceOptions Configuration options for the
|
|
17
|
-
* flyout workspace.
|
|
18
|
-
*/
|
|
19
|
-
constructor(workspaceOptions) {
|
|
20
|
-
workspaceOptions.modalInputs = false;
|
|
21
|
-
super(workspaceOptions);
|
|
22
|
-
this.tabWidth_ = -2;
|
|
23
|
-
this.MARGIN = 12;
|
|
24
|
-
this.GAP_Y = 12;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Displays the given contents in the flyout.
|
|
29
|
-
*
|
|
30
|
-
* @param {!Object} flyoutDef The new contents to show in the flyout.
|
|
31
|
-
*/
|
|
32
|
-
show(flyoutDef) {
|
|
33
|
-
super.show(flyoutDef);
|
|
34
|
-
const inflater = this.getInflaterForType("block");
|
|
35
|
-
if (inflater instanceof RecyclableBlockFlyoutInflater) {
|
|
36
|
-
inflater.emptyRecycledBlocks();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Serializes a block to JSON in order to copy it to the main workspace.
|
|
42
|
-
*
|
|
43
|
-
* @param {!Blockly.BlockSvg} block The block to serialize.
|
|
44
|
-
* @returns {!Object} A JSON representation of the block.
|
|
45
|
-
*/
|
|
46
|
-
serializeBlock(block) {
|
|
47
|
-
const json = super.serializeBlock(block);
|
|
48
|
-
// Delete the serialized block's ID so that a new one is generated when it is
|
|
49
|
-
// placed on the workspace. Otherwise, the block on the workspace may be
|
|
50
|
-
// indistinguishable from the one in the flyout, which can cause reporter blocks
|
|
51
|
-
// to have their value dropdown shown in the wrong place.
|
|
52
|
-
delete json.id;
|
|
53
|
-
return json;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Set the state of a checkbox by block ID.
|
|
58
|
-
* @param {string} blockId ID of the block whose checkbox should be set
|
|
59
|
-
* @param {boolean} value Value to set the checkbox to.
|
|
60
|
-
* @public
|
|
61
|
-
*/
|
|
62
|
-
setCheckboxState(blockId, value) {
|
|
63
|
-
this.getWorkspace()
|
|
64
|
-
.getBlockById(blockId)
|
|
65
|
-
?.getIcon("checkbox")
|
|
66
|
-
?.setChecked(value);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
getFlyoutScale() {
|
|
70
|
-
return 0.675;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getWidth() {
|
|
74
|
-
return 250;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Sets whether or not block recycling is enabled in the flyout.
|
|
79
|
-
*
|
|
80
|
-
* @param {boolean} enabled True if recycling should be enabled.
|
|
81
|
-
*/
|
|
82
|
-
setRecyclingEnabled(enabled) {
|
|
83
|
-
const inflater = this.getInflaterForType("block");
|
|
84
|
-
if (inflater instanceof RecyclableBlockFlyoutInflater) {
|
|
85
|
-
inflater.setRecyclingEnabled(enabled);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Records scroll position for each category in the toolbox.
|
|
91
|
-
* The scroll position is determined by the coordinates of each category's
|
|
92
|
-
* label after the entire flyout has been rendered.
|
|
93
|
-
* @package
|
|
94
|
-
*/
|
|
95
|
-
recordScrollPositions() {
|
|
96
|
-
// TODO(#211) Remove this once the continuous toolbox has been updated.
|
|
97
|
-
this.scrollPositions = [];
|
|
98
|
-
const categoryLabels = this.getContents()
|
|
99
|
-
.filter(
|
|
100
|
-
(item) =>
|
|
101
|
-
(item.type === "label" || item.type === "status_indicator_label") &&
|
|
102
|
-
item.element.isLabel() &&
|
|
103
|
-
this.getParentToolbox_().getCategoryByName(
|
|
104
|
-
item.element.getButtonText()
|
|
105
|
-
)
|
|
106
|
-
)
|
|
107
|
-
.map((item) => item.element);
|
|
108
|
-
for (const [index, label] of categoryLabels.entries()) {
|
|
109
|
-
this.scrollPositions.push({
|
|
110
|
-
name: label.getButtonText(),
|
|
111
|
-
position: label.getPosition(),
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Positions the contents of the flyout.
|
|
118
|
-
*
|
|
119
|
-
* @param {!Blockly.FlyoutItem[]} The flyout items to position.
|
|
120
|
-
*/
|
|
121
|
-
layout_(contents) {
|
|
122
|
-
// TODO(#211) Remove this once the continuous toolbox has been updated.
|
|
123
|
-
// Bypass the continuous flyout's layout method until the plugin is
|
|
124
|
-
// updated for the new flyout API.
|
|
125
|
-
Blockly.VerticalFlyout.prototype.layout_.call(this, contents);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Updates the state of status indicators for hardware-based extensions.
|
|
130
|
-
*/
|
|
131
|
-
refreshStatusButtons() {
|
|
132
|
-
for (const item of this.contents) {
|
|
133
|
-
if (item.element instanceof StatusIndicatorLabel) {
|
|
134
|
-
item.element.refreshStatus();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|