scratch-blocks 2.0.2 → 2.0.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.
Files changed (275) hide show
  1. package/.nvmrc +1 -1
  2. package/commitlint.config.js +2 -2
  3. package/dist/main.mjs +1 -2
  4. package/dist/types/msg/scratch_msgs.d.ts.map +1 -1
  5. package/dist/types/src/block_reporting.d.ts.map +1 -1
  6. package/dist/types/src/blocks/colour.d.ts +0 -19
  7. package/dist/types/src/blocks/colour.d.ts.map +1 -1
  8. package/dist/types/src/blocks/control.d.ts +0 -19
  9. package/dist/types/src/blocks/control.d.ts.map +1 -1
  10. package/dist/types/src/blocks/data.d.ts +0 -19
  11. package/dist/types/src/blocks/data.d.ts.map +1 -1
  12. package/dist/types/src/blocks/event.d.ts +0 -19
  13. package/dist/types/src/blocks/event.d.ts.map +1 -1
  14. package/dist/types/src/blocks/looks.d.ts +0 -19
  15. package/dist/types/src/blocks/looks.d.ts.map +1 -1
  16. package/dist/types/src/blocks/math.d.ts +0 -19
  17. package/dist/types/src/blocks/math.d.ts.map +1 -1
  18. package/dist/types/src/blocks/matrix.d.ts +0 -19
  19. package/dist/types/src/blocks/matrix.d.ts.map +1 -1
  20. package/dist/types/src/blocks/motion.d.ts +0 -19
  21. package/dist/types/src/blocks/motion.d.ts.map +1 -1
  22. package/dist/types/src/blocks/note.d.ts +0 -19
  23. package/dist/types/src/blocks/note.d.ts.map +1 -1
  24. package/dist/types/src/blocks/operators.d.ts +0 -19
  25. package/dist/types/src/blocks/operators.d.ts.map +1 -1
  26. package/dist/types/src/blocks/procedures.d.ts +7 -10
  27. package/dist/types/src/blocks/procedures.d.ts.map +1 -1
  28. package/dist/types/src/blocks/sensing.d.ts +0 -19
  29. package/dist/types/src/blocks/sensing.d.ts.map +1 -1
  30. package/dist/types/src/blocks/sound.d.ts +0 -19
  31. package/dist/types/src/blocks/sound.d.ts.map +1 -1
  32. package/dist/types/src/blocks/text.d.ts +0 -19
  33. package/dist/types/src/blocks/text.d.ts.map +1 -1
  34. package/dist/types/src/blocks/vertical_extensions.d.ts +0 -19
  35. package/dist/types/src/blocks/vertical_extensions.d.ts.map +1 -1
  36. package/dist/types/src/checkable_continuous_flyout.d.ts +2 -7
  37. package/dist/types/src/checkable_continuous_flyout.d.ts.map +1 -1
  38. package/dist/types/src/checkbox_bubble.d.ts +13 -12
  39. package/dist/types/src/checkbox_bubble.d.ts.map +1 -1
  40. package/dist/types/src/colours.d.ts.map +1 -1
  41. package/dist/types/src/constants.d.ts +0 -7
  42. package/dist/types/src/constants.d.ts.map +1 -1
  43. package/dist/types/src/context_menu_items.d.ts +0 -5
  44. package/dist/types/src/context_menu_items.d.ts.map +1 -1
  45. package/dist/types/src/data_category.d.ts +2 -4
  46. package/dist/types/src/data_category.d.ts.map +1 -1
  47. package/dist/types/src/events/events_block_comment_base.d.ts +2 -3
  48. package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
  49. package/dist/types/src/events/events_block_comment_change.d.ts +0 -5
  50. package/dist/types/src/events/events_block_comment_change.d.ts.map +1 -1
  51. package/dist/types/src/events/events_block_comment_collapse.d.ts +0 -5
  52. package/dist/types/src/events/events_block_comment_collapse.d.ts.map +1 -1
  53. package/dist/types/src/events/events_block_comment_create.d.ts +0 -5
  54. package/dist/types/src/events/events_block_comment_create.d.ts.map +1 -1
  55. package/dist/types/src/events/events_block_comment_delete.d.ts +0 -5
  56. package/dist/types/src/events/events_block_comment_delete.d.ts.map +1 -1
  57. package/dist/types/src/events/events_block_comment_move.d.ts +0 -5
  58. package/dist/types/src/events/events_block_comment_move.d.ts.map +1 -1
  59. package/dist/types/src/events/events_block_comment_resize.d.ts +0 -5
  60. package/dist/types/src/events/events_block_comment_resize.d.ts.map +1 -1
  61. package/dist/types/src/events/events_block_drag_end.d.ts +1 -2
  62. package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
  63. package/dist/types/src/events/events_block_drag_outside.d.ts +1 -2
  64. package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
  65. package/dist/types/src/events/events_scratch_variable_create.d.ts +0 -5
  66. package/dist/types/src/events/events_scratch_variable_create.d.ts.map +1 -1
  67. package/dist/types/src/fields/field_colour_slider.d.ts +7 -9
  68. package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
  69. package/dist/types/src/fields/field_matrix.d.ts +0 -19
  70. package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
  71. package/dist/types/src/fields/field_note.d.ts +8 -23
  72. package/dist/types/src/fields/field_note.d.ts.map +1 -1
  73. package/dist/types/src/fields/field_textinput_removable.d.ts +2 -4
  74. package/dist/types/src/fields/field_textinput_removable.d.ts.map +1 -1
  75. package/dist/types/src/fields/field_variable_getter.d.ts +0 -19
  76. package/dist/types/src/fields/field_variable_getter.d.ts.map +1 -1
  77. package/dist/types/src/fields/field_vertical_separator.d.ts +0 -19
  78. package/dist/types/src/fields/field_vertical_separator.d.ts.map +1 -1
  79. package/dist/types/src/fields/scratch_field_angle.d.ts +0 -19
  80. package/dist/types/src/fields/scratch_field_angle.d.ts.map +1 -1
  81. package/dist/types/src/fields/scratch_field_dropdown.d.ts +0 -5
  82. package/dist/types/src/fields/scratch_field_dropdown.d.ts.map +1 -1
  83. package/dist/types/src/fields/scratch_field_number.d.ts +0 -19
  84. package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
  85. package/dist/types/src/fields/scratch_field_variable.d.ts +4 -7
  86. package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
  87. package/dist/types/src/flyout_checkbox_icon.d.ts +2 -3
  88. package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
  89. package/dist/types/src/glows.d.ts +1 -3
  90. package/dist/types/src/glows.d.ts.map +1 -1
  91. package/dist/types/src/index.d.ts +50 -55
  92. package/dist/types/src/index.d.ts.map +1 -1
  93. package/dist/types/src/procedures.d.ts +6 -8
  94. package/dist/types/src/procedures.d.ts.map +1 -1
  95. package/dist/types/src/recyclable_block_flyout_inflater.d.ts +3 -5
  96. package/dist/types/src/recyclable_block_flyout_inflater.d.ts.map +1 -1
  97. package/dist/types/src/renderer/bowler_hat.d.ts +2 -3
  98. package/dist/types/src/renderer/bowler_hat.d.ts.map +1 -1
  99. package/dist/types/src/renderer/cat/cat_face.d.ts +6 -5
  100. package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
  101. package/dist/types/src/renderer/cat/constants.d.ts +2 -2
  102. package/dist/types/src/renderer/cat/constants.d.ts.map +1 -1
  103. package/dist/types/src/renderer/cat/drawer.d.ts +3 -4
  104. package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
  105. package/dist/types/src/renderer/cat/path_object.d.ts +2 -3
  106. package/dist/types/src/renderer/cat/path_object.d.ts.map +1 -1
  107. package/dist/types/src/renderer/cat/render_info.d.ts +3 -4
  108. package/dist/types/src/renderer/cat/render_info.d.ts.map +1 -1
  109. package/dist/types/src/renderer/cat/renderer.d.ts +6 -7
  110. package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
  111. package/dist/types/src/renderer/constants.d.ts +4 -4
  112. package/dist/types/src/renderer/constants.d.ts.map +1 -1
  113. package/dist/types/src/renderer/drawer.d.ts +5 -4
  114. package/dist/types/src/renderer/drawer.d.ts.map +1 -1
  115. package/dist/types/src/renderer/path_object.d.ts +1 -3
  116. package/dist/types/src/renderer/path_object.d.ts.map +1 -1
  117. package/dist/types/src/renderer/render_info.d.ts +3 -4
  118. package/dist/types/src/renderer/render_info.d.ts.map +1 -1
  119. package/dist/types/src/renderer/renderer.d.ts +8 -15
  120. package/dist/types/src/renderer/renderer.d.ts.map +1 -1
  121. package/dist/types/src/scratch_block_paster.d.ts +0 -5
  122. package/dist/types/src/scratch_block_paster.d.ts.map +1 -1
  123. package/dist/types/src/scratch_blocks_utils.d.ts +0 -20
  124. package/dist/types/src/scratch_blocks_utils.d.ts.map +1 -1
  125. package/dist/types/src/scratch_comment_bubble.d.ts +1 -4
  126. package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
  127. package/dist/types/src/scratch_comment_icon.d.ts +2 -3
  128. package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
  129. package/dist/types/src/scratch_connection_checker.d.ts +0 -5
  130. package/dist/types/src/scratch_connection_checker.d.ts.map +1 -1
  131. package/dist/types/src/scratch_continuous_category.d.ts +5 -5
  132. package/dist/types/src/scratch_continuous_category.d.ts.map +1 -1
  133. package/dist/types/src/scratch_continuous_toolbox.d.ts +3 -6
  134. package/dist/types/src/scratch_continuous_toolbox.d.ts.map +1 -1
  135. package/dist/types/src/scratch_dragger.d.ts +3 -12
  136. package/dist/types/src/scratch_dragger.d.ts.map +1 -1
  137. package/dist/types/src/scratch_insertion_marker_previewer.d.ts +0 -5
  138. package/dist/types/src/scratch_insertion_marker_previewer.d.ts.map +1 -1
  139. package/dist/types/src/scratch_variable_map.d.ts +0 -5
  140. package/dist/types/src/scratch_variable_map.d.ts.map +1 -1
  141. package/dist/types/src/scratch_variable_model.d.ts +1 -2
  142. package/dist/types/src/scratch_variable_model.d.ts.map +1 -1
  143. package/dist/types/src/scratch_zoom_controls.d.ts +4 -6
  144. package/dist/types/src/scratch_zoom_controls.d.ts.map +1 -1
  145. package/dist/types/src/shadows.d.ts +2 -2
  146. package/dist/types/src/shadows.d.ts.map +1 -1
  147. package/dist/types/src/status_indicator_label.d.ts +4 -6
  148. package/dist/types/src/status_indicator_label.d.ts.map +1 -1
  149. package/dist/types/src/status_indicator_label_flyout_inflater.d.ts +1 -6
  150. package/dist/types/src/status_indicator_label_flyout_inflater.d.ts.map +1 -1
  151. package/dist/types/src/variables.d.ts +4 -8
  152. package/dist/types/src/variables.d.ts.map +1 -1
  153. package/dist/types/src/xml.d.ts +2 -3
  154. package/dist/types/src/xml.d.ts.map +1 -1
  155. package/dist/types/tests/jsunit/block_test.d.ts.map +1 -1
  156. package/dist/types/tests/jsunit/connection_db_test.d.ts.map +1 -1
  157. package/dist/types/tests/jsunit/connection_test.d.ts.map +1 -1
  158. package/dist/types/tests/jsunit/event_test.d.ts.map +1 -1
  159. package/dist/types/tests/jsunit/extensions_test.d.ts.map +1 -1
  160. package/dist/types/tests/jsunit/field_number_test.d.ts.map +1 -1
  161. package/dist/types/tests/jsunit/field_test.d.ts.map +1 -1
  162. package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +1 -1
  163. package/dist/types/tests/jsunit/field_variable_test.d.ts.map +1 -1
  164. package/dist/types/tests/jsunit/gesture_test.d.ts.map +1 -1
  165. package/dist/types/tests/jsunit/input_test.d.ts +1 -0
  166. package/dist/types/tests/jsunit/input_test.d.ts.map +1 -1
  167. package/dist/types/tests/jsunit/json_test.d.ts.map +1 -1
  168. package/dist/types/tests/jsunit/names_test.d.ts.map +1 -1
  169. package/dist/types/tests/jsunit/procedure_test.d.ts.map +1 -1
  170. package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +1 -1
  171. package/dist/types/tests/jsunit/svg_test.d.ts.map +1 -1
  172. package/dist/types/tests/jsunit/test_utilities.d.ts.map +1 -1
  173. package/dist/types/tests/jsunit/utils_test.d.ts.map +1 -1
  174. package/dist/types/tests/jsunit/variable_map_test.d.ts.map +1 -1
  175. package/dist/types/tests/jsunit/variable_model_test.d.ts.map +1 -1
  176. package/dist/types/tests/jsunit/widget_div_test.d.ts.map +1 -1
  177. package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +1 -1
  178. package/dist/types/tests/jsunit/workspace_test.d.ts.map +1 -1
  179. package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +1 -1
  180. package/dist/types/tests/jsunit/xml_test.d.ts.map +1 -1
  181. package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +1 -1
  182. package/eslint.config.mjs +69 -0
  183. package/i18n/create_scratch_msgs.js +44 -45
  184. package/i18n/js_to_json.js +40 -32
  185. package/i18n/json_to_js.js +37 -37
  186. package/i18n/sync_tx_translations.js +64 -65
  187. package/i18n/test_scratch_msgs.js +66 -63
  188. package/msg/js/en.js +289 -287
  189. package/msg/json/en.json +284 -284
  190. package/msg/messages.js +289 -287
  191. package/msg/scratch_msgs.js +22959 -22970
  192. package/package.json +13 -10
  193. package/prettier.config.mjs +3 -0
  194. package/release.config.js +7 -7
  195. package/renovate.json5 +7 -9
  196. package/src/block_reporting.ts +15 -18
  197. package/src/blocks/colour.ts +12 -15
  198. package/src/blocks/control.ts +167 -177
  199. package/src/blocks/data.ts +225 -292
  200. package/src/blocks/event.ts +121 -123
  201. package/src/blocks/looks.ts +165 -167
  202. package/src/blocks/math.ts +44 -46
  203. package/src/blocks/matrix.ts +11 -13
  204. package/src/blocks/motion.ts +151 -153
  205. package/src/blocks/note.ts +11 -13
  206. package/src/blocks/operators.ts +158 -160
  207. package/src/blocks/procedures.ts +488 -536
  208. package/src/blocks/sensing.ts +163 -165
  209. package/src/blocks/sound.ts +58 -60
  210. package/src/blocks/text.ts +10 -12
  211. package/src/blocks/vertical_extensions.ts +86 -102
  212. package/src/checkable_continuous_flyout.ts +25 -42
  213. package/src/checkbox_bubble.ts +83 -100
  214. package/src/colours.ts +35 -37
  215. package/src/constants.ts +22 -29
  216. package/src/context_menu_items.ts +56 -81
  217. package/src/css.ts +3 -4
  218. package/src/data_category.ts +136 -250
  219. package/src/events/events_block_comment_base.ts +21 -31
  220. package/src/events/events_block_comment_change.ts +21 -42
  221. package/src/events/events_block_comment_collapse.ts +22 -43
  222. package/src/events/events_block_comment_create.ts +29 -46
  223. package/src/events/events_block_comment_delete.ts +10 -19
  224. package/src/events/events_block_comment_move.ts +27 -52
  225. package/src/events/events_block_comment_resize.ts +28 -55
  226. package/src/events/events_block_drag_end.ts +16 -26
  227. package/src/events/events_block_drag_outside.ts +12 -22
  228. package/src/events/events_scratch_variable_create.ts +33 -56
  229. package/src/fields/field_colour_slider.ts +173 -228
  230. package/src/fields/field_matrix.ts +200 -269
  231. package/src/fields/field_note.ts +272 -377
  232. package/src/fields/field_textinput_removable.ts +25 -40
  233. package/src/fields/field_variable_getter.ts +26 -31
  234. package/src/fields/field_vertical_separator.ts +19 -24
  235. package/src/fields/scratch_field_angle.ts +150 -186
  236. package/src/fields/scratch_field_dropdown.ts +15 -19
  237. package/src/fields/scratch_field_number.ts +123 -180
  238. package/src/fields/scratch_field_variable.ts +52 -73
  239. package/src/flyout_checkbox_icon.ts +18 -28
  240. package/src/glows.ts +51 -58
  241. package/src/index.ts +119 -133
  242. package/src/procedures.ts +144 -211
  243. package/src/recyclable_block_flyout_inflater.ts +14 -25
  244. package/src/renderer/bowler_hat.ts +6 -8
  245. package/src/renderer/cat/cat_face.ts +98 -99
  246. package/src/renderer/cat/constants.ts +67 -87
  247. package/src/renderer/cat/drawer.ts +21 -27
  248. package/src/renderer/cat/path_object.ts +3 -5
  249. package/src/renderer/cat/render_info.ts +5 -8
  250. package/src/renderer/cat/renderer.ts +11 -15
  251. package/src/renderer/constants.ts +34 -49
  252. package/src/renderer/drawer.ts +35 -51
  253. package/src/renderer/path_object.ts +13 -15
  254. package/src/renderer/render_info.ts +36 -56
  255. package/src/renderer/renderer.ts +16 -29
  256. package/src/scratch_block_paster.ts +12 -20
  257. package/src/scratch_blocks_utils.ts +4 -7
  258. package/src/scratch_comment_bubble.ts +70 -101
  259. package/src/scratch_comment_icon.ts +74 -123
  260. package/src/scratch_connection_checker.ts +22 -17
  261. package/src/scratch_continuous_category.ts +24 -28
  262. package/src/scratch_continuous_toolbox.ts +20 -27
  263. package/src/scratch_dragger.ts +54 -86
  264. package/src/scratch_insertion_marker_previewer.ts +6 -11
  265. package/src/scratch_variable_map.ts +5 -12
  266. package/src/scratch_variable_model.ts +4 -11
  267. package/src/scratch_zoom_controls.ts +101 -156
  268. package/src/shadows.ts +32 -37
  269. package/src/status_indicator_label.ts +54 -67
  270. package/src/status_indicator_label_flyout_inflater.ts +11 -21
  271. package/src/variables.ts +89 -138
  272. package/src/xml.ts +21 -35
  273. package/tsconfig.json +2 -6
  274. package/types/continuous-toolbox.d.ts +1 -1
  275. package/dist/main.mjs.LICENSE.txt +0 -163
@@ -1,68 +1,60 @@
1
1
  /**
2
- * @license
3
2
  * Copyright 2024 Google LLC
4
3
  * SPDX-License-Identifier: Apache-2.0
5
4
  */
6
-
7
- import * as Blockly from "blockly/core";
8
- import { ContinuousFlyout } from "@blockly/continuous-toolbox";
9
- import { CheckboxBubble } from "./checkbox_bubble";
10
- import { StatusIndicatorLabel } from "./status_indicator_label";
11
- import { STATUS_INDICATOR_LABEL_TYPE } from "./status_indicator_label_flyout_inflater";
5
+ import { ContinuousFlyout } from '@blockly/continuous-toolbox'
6
+ import * as Blockly from 'blockly/core'
7
+ import { CheckboxBubble } from './checkbox_bubble'
8
+ import { StatusIndicatorLabel } from './status_indicator_label'
9
+ import { STATUS_INDICATOR_LABEL_TYPE } from './status_indicator_label_flyout_inflater'
12
10
 
13
11
  export class CheckableContinuousFlyout extends ContinuousFlyout {
14
12
  /**
15
13
  * Creates a new CheckableContinuousFlyout.
16
- *
17
14
  * @param workspaceOptions Configuration options for the flyout workspace.
18
15
  */
19
16
  constructor(workspaceOptions: Blockly.Options) {
20
- workspaceOptions.modalInputs = false;
21
- super(workspaceOptions);
22
- this.tabWidth_ = 0;
23
- this.MARGIN = 12;
24
- this.GAP_Y = 12;
17
+ workspaceOptions.modalInputs = false
18
+ super(workspaceOptions)
19
+ this.tabWidth_ = 0
20
+ this.MARGIN = 12
21
+ this.GAP_Y = 12
25
22
  }
26
23
 
27
24
  /**
28
25
  * Serializes a block to JSON in order to copy it to the main workspace.
29
- *
30
26
  * @param block The block to serialize.
31
27
  * @returns A JSON representation of the block.
32
28
  */
33
29
  protected serializeBlock(block: Blockly.BlockSvg) {
34
- const json = super.serializeBlock(block);
30
+ const json = super.serializeBlock(block)
35
31
  // Delete the serialized block's ID so that a new one is generated when it is
36
32
  // placed on the workspace. Otherwise, the block on the workspace may be
37
33
  // indistinguishable from the one in the flyout, which can cause reporter blocks
38
34
  // to have their value dropdown shown in the wrong place.
39
- delete json.id;
40
- return json;
35
+ delete json.id
36
+ return json
41
37
  }
42
38
 
43
39
  /**
44
40
  * Set the state of a checkbox by block ID.
45
- *
46
41
  * @param blockId ID of the block whose checkbox should be set
47
42
  * @param value Value to set the checkbox to.
48
43
  */
49
44
  setCheckboxState(blockId: string, value: boolean) {
50
- this.getWorkspace()
51
- .getBlockById(blockId)
52
- ?.getIcon("checkbox")
53
- ?.setChecked(value);
45
+ this.getWorkspace().getBlockById(blockId)?.getIcon('checkbox')?.setChecked(value)
54
46
  }
55
47
 
56
48
  getFlyoutScale() {
57
- return 0.675;
49
+ return 0.675
58
50
  }
59
51
 
60
52
  getWidth() {
61
- return 250;
53
+ return 250
62
54
  }
63
55
 
64
56
  protected reflowInternal_() {
65
- super.reflowInternal_();
57
+ super.reflowInternal_()
66
58
 
67
59
  if (this.RTL) {
68
60
  // The parent implementation assumes that the flyout grows to fit its
@@ -70,33 +62,24 @@ export class CheckableContinuousFlyout extends ContinuousFlyout {
70
62
  // flyout width is fixed (and blocks may exceed it), so re-adjust blocks
71
63
  // accordingly based on the actual fixed width.
72
64
  for (const item of this.getContents()) {
73
- const oldX = item.getElement().getBoundingRectangle().left;
65
+ const oldX = item.getElement().getBoundingRectangle().left
74
66
  let newX =
75
- this.getWidth() / this.workspace_.scale -
76
- item.getElement().getBoundingRectangle().getWidth() -
77
- this.MARGIN;
78
- if (
79
- "checkboxInFlyout" in item.getElement() &&
80
- item.getElement().checkboxInFlyout
81
- ) {
82
- newX -= CheckboxBubble.CHECKBOX_SIZE + CheckboxBubble.CHECKBOX_MARGIN;
67
+ this.getWidth() / this.workspace_.scale - item.getElement().getBoundingRectangle().getWidth() - this.MARGIN
68
+ if ('checkboxInFlyout' in item.getElement() && item.getElement().checkboxInFlyout) {
69
+ newX -= CheckboxBubble.CHECKBOX_SIZE + CheckboxBubble.CHECKBOX_MARGIN
83
70
  }
84
- item.getElement().moveBy(newX - oldX, 0);
71
+ item.getElement().moveBy(newX - oldX, 0)
85
72
  }
86
73
  }
87
74
  }
88
75
 
89
76
  /**
90
77
  * Validates that the given toolbox item represents a label.
91
- *
92
78
  * @param item The toolbox item to check.
93
79
  * @returns True if the item represents a label in the flyout.
94
80
  */
95
81
  protected toolboxItemIsLabel(item: Blockly.FlyoutItem) {
96
- return (
97
- item.getType() === STATUS_INDICATOR_LABEL_TYPE ||
98
- super.toolboxItemIsLabel(item)
99
- );
82
+ return item.getType() === STATUS_INDICATOR_LABEL_TYPE || super.toolboxItemIsLabel(item)
100
83
  }
101
84
 
102
85
  /**
@@ -105,12 +88,12 @@ export class CheckableContinuousFlyout extends ContinuousFlyout {
105
88
  refreshStatusButtons() {
106
89
  for (const item of this.contents) {
107
90
  if (item.element instanceof StatusIndicatorLabel) {
108
- item.element.refreshStatus();
91
+ item.element.refreshStatus()
109
92
  }
110
93
  }
111
94
  }
112
95
 
113
96
  scrollTo(position: number) {
114
- super.scrollTo(Math.ceil(position));
97
+ super.scrollTo(Math.ceil(position))
115
98
  }
116
99
  }
@@ -1,256 +1,236 @@
1
1
  /**
2
- * @license
3
2
  * Copyright 2024 Google LLC
4
3
  * SPDX-License-Identifier: Apache-2.0
5
4
  */
6
-
7
- import * as Blockly from "blockly/core";
5
+ import * as Blockly from 'blockly/core'
8
6
 
9
7
  /**
10
8
  * A checkbox shown next to reporter blocks in the flyout.
11
9
  */
12
- export class CheckboxBubble
13
- implements Blockly.IBubble, Blockly.IRenderedElement
14
- {
10
+ export class CheckboxBubble implements Blockly.IBubble, Blockly.IRenderedElement {
15
11
  /**
16
12
  * Size of a checkbox next to a variable reporter.
17
13
  */
18
- static readonly CHECKBOX_SIZE = 25;
14
+ static readonly CHECKBOX_SIZE = 25
19
15
 
20
16
  /**
21
17
  * Amount of touchable padding around reporter checkboxes.
22
18
  */
23
- static readonly CHECKBOX_TOUCH_PADDING = 12;
19
+ static readonly CHECKBOX_TOUCH_PADDING = 12
24
20
 
25
21
  /**
26
22
  * SVG path data for checkmark in checkbox.
27
23
  */
28
24
  static readonly CHECKMARK_PATH =
29
- "M" +
25
+ 'M' +
30
26
  CheckboxBubble.CHECKBOX_SIZE / 4 +
31
- " " +
27
+ ' ' +
32
28
  CheckboxBubble.CHECKBOX_SIZE / 2 +
33
- "L" +
29
+ 'L' +
34
30
  (5 * CheckboxBubble.CHECKBOX_SIZE) / 12 +
35
- " " +
31
+ ' ' +
36
32
  (2 * CheckboxBubble.CHECKBOX_SIZE) / 3 +
37
- "L" +
33
+ 'L' +
38
34
  (3 * CheckboxBubble.CHECKBOX_SIZE) / 4 +
39
- " " +
40
- CheckboxBubble.CHECKBOX_SIZE / 3;
35
+ ' ' +
36
+ CheckboxBubble.CHECKBOX_SIZE / 3
41
37
 
42
38
  /**
43
39
  * Size of the checkbox corner radius.
44
40
  */
45
- static readonly CHECKBOX_CORNER_RADIUS = 5;
41
+ static readonly CHECKBOX_CORNER_RADIUS = 5
46
42
 
47
43
  /**
48
44
  * The margin around a checkbox.
49
45
  */
50
- static readonly CHECKBOX_MARGIN = 12;
46
+ static readonly CHECKBOX_MARGIN = 12
51
47
 
52
48
  /**
53
49
  * Total additional width of a row that contains a checkbox.
54
50
  */
55
- static readonly CHECKBOX_SPACE_X =
56
- CheckboxBubble.CHECKBOX_SIZE + 2 * CheckboxBubble.CHECKBOX_MARGIN;
51
+ static readonly CHECKBOX_SPACE_X = CheckboxBubble.CHECKBOX_SIZE + 2 * CheckboxBubble.CHECKBOX_MARGIN
57
52
 
58
53
  /**
59
54
  * Root SVG element for this bubble.
60
55
  */
61
- svgRoot: SVGGElement;
56
+ svgRoot: SVGGElement
62
57
 
63
58
  /**
64
59
  * Identifier for click handler, to allow unregistering during disposal.
65
60
  */
66
- clickListener: Blockly.browserEvents.Data;
61
+ clickListener: Blockly.browserEvents.Data
67
62
 
68
63
  /**
69
64
  * Whether or not this bubble is displayed as checked. Note that the source of
70
65
  * truth is the Scratch VM.
71
66
  */
72
- checked = false;
67
+ checked = false
73
68
 
74
69
  /**
75
70
  * The location of this bubble in workspace coordinates.
76
71
  */
77
- location = new Blockly.utils.Coordinate(0, 0);
72
+ location = new Blockly.utils.Coordinate(0, 0)
78
73
 
79
74
  /**
80
75
  * Creates a new flyout checkbox bubble.
81
- *
82
76
  * @param sourceBlock The block this bubble should be associated with.
83
77
  */
84
78
  constructor(private sourceBlock: Blockly.BlockSvg) {
85
79
  this.svgRoot = Blockly.utils.dom.createSvgElement(
86
80
  Blockly.utils.Svg.G,
87
81
  {},
88
- this.sourceBlock.workspace.getBubbleCanvas()
89
- );
82
+ this.sourceBlock.workspace.getBubbleCanvas(),
83
+ )
90
84
 
91
- const touchMargin = CheckboxBubble.CHECKBOX_TOUCH_PADDING;
85
+ const touchMargin = CheckboxBubble.CHECKBOX_TOUCH_PADDING
92
86
  const checkboxGroup = Blockly.utils.dom.createSvgElement(
93
- "g",
87
+ 'g',
94
88
  {
95
- fill: "transparent",
89
+ fill: 'transparent',
96
90
  },
97
- null
98
- );
91
+ null,
92
+ )
99
93
  Blockly.utils.dom.createSvgElement(
100
- "rect",
94
+ 'rect',
101
95
  {
102
- class: "blocklyFlyoutCheckbox",
96
+ class: 'blocklyFlyoutCheckbox',
103
97
  height: CheckboxBubble.CHECKBOX_SIZE,
104
98
  width: CheckboxBubble.CHECKBOX_SIZE,
105
99
  rx: CheckboxBubble.CHECKBOX_CORNER_RADIUS,
106
100
  ry: CheckboxBubble.CHECKBOX_CORNER_RADIUS,
107
101
  },
108
- checkboxGroup
109
- );
102
+ checkboxGroup,
103
+ )
110
104
  Blockly.utils.dom.createSvgElement(
111
- "path",
105
+ 'path',
112
106
  {
113
- class: "blocklyFlyoutCheckboxPath",
107
+ class: 'blocklyFlyoutCheckboxPath',
114
108
  d: CheckboxBubble.CHECKMARK_PATH,
115
109
  },
116
- checkboxGroup
117
- );
110
+ checkboxGroup,
111
+ )
118
112
  Blockly.utils.dom.createSvgElement(
119
- "rect",
113
+ 'rect',
120
114
  {
121
- class: "blocklyTouchTargetBackground",
122
- x: -touchMargin + "px",
123
- y: -touchMargin + "px",
115
+ class: 'blocklyTouchTargetBackground',
116
+ x: -touchMargin + 'px',
117
+ y: -touchMargin + 'px',
124
118
  height: CheckboxBubble.CHECKBOX_SIZE + 2 * touchMargin,
125
119
  width: CheckboxBubble.CHECKBOX_SIZE + 2 * touchMargin,
126
120
  },
127
- checkboxGroup
128
- );
129
- this.setChecked(this.isChecked(this.sourceBlock.id));
130
-
131
- this.svgRoot.prepend(checkboxGroup);
132
-
133
- this.clickListener = Blockly.browserEvents.bind(
134
- this.svgRoot,
135
- "pointerdown",
136
- null,
137
- (event: PointerEvent) => {
138
- this.setChecked(!this.checked);
139
- event.stopPropagation();
140
- event.preventDefault();
141
- }
142
- );
143
- this.updateLocation();
121
+ checkboxGroup,
122
+ )
123
+ this.setChecked(this.isChecked(this.sourceBlock.id))
124
+
125
+ this.svgRoot.prepend(checkboxGroup)
126
+
127
+ this.clickListener = Blockly.browserEvents.bind(this.svgRoot, 'pointerdown', null, (event: PointerEvent) => {
128
+ this.setChecked(!this.checked)
129
+ event.stopPropagation()
130
+ event.preventDefault()
131
+ })
132
+ this.updateLocation()
144
133
  }
145
134
 
146
135
  /**
147
136
  * Sets whether or not this bubble should be displayed in the checked state.
148
- *
149
137
  * @param checked True if this bubble should be checked.
150
138
  */
151
139
  setChecked(checked: boolean) {
152
- if (checked === this.checked) return;
140
+ if (checked === this.checked) return
153
141
 
154
- this.checked = checked;
142
+ this.checked = checked
155
143
  if (this.checked) {
156
- Blockly.utils.dom.addClass(this.svgRoot, "checked");
144
+ Blockly.utils.dom.addClass(this.svgRoot, 'checked')
157
145
  } else {
158
- Blockly.utils.dom.removeClass(this.svgRoot, "checked");
146
+ Blockly.utils.dom.removeClass(this.svgRoot, 'checked')
159
147
  }
160
148
 
161
149
  Blockly.Events.fire(
162
- new Blockly.Events.BlockChange(
163
- this.sourceBlock,
164
- "checkbox",
165
- null,
166
- !this.checked,
167
- this.checked
168
- )
169
- );
150
+ new Blockly.Events.BlockChange(this.sourceBlock, 'checkbox', null, !this.checked, this.checked),
151
+ )
170
152
  }
171
153
 
172
154
  /**
173
155
  * Returns whether or not the specified block has its checkbox checked.
174
156
  *
175
157
  * This method is patched by scratch-gui to query the VM state.
176
- *
177
158
  * @param blockId The ID of the block in question.
178
159
  * @returns True if the block's checkbox should be checked.
179
160
  */
180
161
  isChecked(blockId: string): boolean {
181
- return false;
162
+ return false
182
163
  }
183
164
 
184
165
  /**
185
166
  * Returns whether this bubble is movable by the user.
186
- *
187
167
  * @returns Always returns false.
188
168
  */
189
169
  isMovable(): boolean {
190
- return false;
170
+ return false
191
171
  }
192
172
 
193
173
  /**
194
174
  * Returns the root SVG element for this bubble.
195
- *
196
175
  * @returns The root SVG element.
197
176
  */
198
177
  getSvgRoot(): SVGGElement {
199
- return this.svgRoot;
178
+ return this.svgRoot
200
179
  }
201
180
 
202
181
  /**
203
182
  * Recalculates this bubble's location, keeping it adjacent to its block.
204
183
  */
205
184
  updateLocation() {
206
- const bounds = this.sourceBlock.getBoundingRectangle();
185
+ const bounds = this.sourceBlock.getBoundingRectangle()
207
186
  const x = this.sourceBlock.workspace.RTL
208
187
  ? bounds.right + CheckboxBubble.CHECKBOX_MARGIN
209
- : bounds.left -
210
- CheckboxBubble.CHECKBOX_MARGIN -
211
- CheckboxBubble.CHECKBOX_SIZE;
212
- const y =
213
- bounds.top + (bounds.getHeight() - CheckboxBubble.CHECKBOX_SIZE) / 2;
214
- this.moveTo(x, y);
188
+ : bounds.left - CheckboxBubble.CHECKBOX_MARGIN - CheckboxBubble.CHECKBOX_SIZE
189
+ const y = bounds.top + (bounds.getHeight() - CheckboxBubble.CHECKBOX_SIZE) / 2
190
+ this.moveTo(x, y)
215
191
  }
216
192
 
217
193
  /**
218
194
  * Moves this bubble to the specified location.
219
- *
220
195
  * @param x The location on the X axis to move to.
221
196
  * @param y The location on the Y axis to move to.
222
197
  */
223
198
  moveTo(x: number, y: number) {
224
- this.location.x = x;
225
- this.location.y = y;
226
- this.svgRoot.setAttribute("transform", `translate(${x}, ${y})`);
199
+ this.location.x = x
200
+ this.location.y = y
201
+ this.svgRoot.setAttribute('transform', `translate(${x}, ${y})`)
227
202
  }
228
203
 
229
204
  /**
230
205
  * Returns this bubble's location in workspace coordinates.
231
- *
232
206
  * @returns The bubble's location.
233
207
  */
234
208
  getRelativeToSurfaceXY(): Blockly.utils.Coordinate {
235
- return this.location;
209
+ return this.location
236
210
  }
237
211
 
238
212
  /**
239
213
  * Disposes of this checkbox bubble.
240
214
  */
241
215
  dispose() {
242
- Blockly.utils.dom.removeNode(this.svgRoot);
243
- Blockly.browserEvents.unbind(this.clickListener);
216
+ Blockly.utils.dom.removeNode(this.svgRoot)
217
+ Blockly.browserEvents.unbind(this.clickListener)
244
218
  }
245
219
 
246
- /** See IFocusableNode.getFocusableElement. */
220
+ /**
221
+ * See IFocusableNode.getFocusableElement.
222
+ * @returns The SVG root element of this bubble.
223
+ */
247
224
  getFocusableElement(): HTMLElement | SVGElement {
248
- return this.svgRoot;
225
+ return this.svgRoot
249
226
  }
250
227
 
251
- /** See IFocusableNode.getFocusableTree. */
228
+ /**
229
+ * See IFocusableNode.getFocusableTree.
230
+ * @returns The workspace containing this bubble's source block.
231
+ */
252
232
  getFocusableTree(): Blockly.IFocusableTree {
253
- return this.sourceBlock.workspace;
233
+ return this.sourceBlock.workspace
254
234
  }
255
235
 
256
236
  /** See IFocusableNode.onNodeFocus. */
@@ -259,9 +239,12 @@ export class CheckboxBubble
259
239
  /** See IFocusableNode.onNodeBlur. */
260
240
  onNodeBlur(): void {}
261
241
 
262
- /** See IFocusableNode.canBeFocused. */
242
+ /**
243
+ * See IFocusableNode.canBeFocused.
244
+ * @returns Always true; this bubble can always receive focus.
245
+ */
263
246
  canBeFocused(): boolean {
264
- return true;
247
+ return true
265
248
  }
266
249
 
267
250
  // These methods are required by the interfaces, but intentionally have no
package/src/colours.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license
3
2
  * Visual Blocks Editor
4
3
  *
5
4
  * Copyright 2016 Massachusetts Institute of Technology
@@ -17,69 +16,68 @@
17
16
  * See the License for the specific language governing permissions and
18
17
  * limitations under the License.
19
18
  */
20
- import * as Blockly from "blockly/core";
19
+ import * as Blockly from 'blockly/core'
21
20
 
22
21
  const Colours = {
23
22
  // SVG colours: these must be specified in #RRGGBB style
24
23
  // To add an opacity, this must be specified as a separate property (for SVG fill-opacity)
25
- text: "#FFFFFF",
26
- workspace: "#F9F9F9",
27
- toolboxHover: "#4C97FF",
28
- toolboxSelected: "#e9eef2",
29
- toolboxText: "#575E75",
30
- toolbox: "#FFFFFF",
31
- flyout: "#F9F9F9",
32
- scrollbar: "#CECDCE",
33
- scrollbarHover: "#CECDCE",
34
- textField: "#FFFFFF",
35
- textFieldText: "#575E75",
36
- insertionMarker: "#000000",
24
+ text: '#FFFFFF',
25
+ workspace: '#F9F9F9',
26
+ toolboxHover: '#4C97FF',
27
+ toolboxSelected: '#e9eef2',
28
+ toolboxText: '#575E75',
29
+ toolbox: '#FFFFFF',
30
+ flyout: '#F9F9F9',
31
+ scrollbar: '#CECDCE',
32
+ scrollbarHover: '#CECDCE',
33
+ textField: '#FFFFFF',
34
+ textFieldText: '#575E75',
35
+ insertionMarker: '#000000',
37
36
  insertionMarkerOpacity: 0.2,
38
37
  dragShadowOpacity: 0.6,
39
- stackGlow: "#FFF200",
38
+ stackGlow: '#FFF200',
40
39
  stackGlowSize: 4,
41
40
  stackGlowOpacity: 1,
42
- replacementGlow: "#FFFFFF",
41
+ replacementGlow: '#FFFFFF',
43
42
  replacementGlowSize: 2,
44
43
  replacementGlowOpacity: 1,
45
- colourPickerStroke: "#FFFFFF",
44
+ colourPickerStroke: '#FFFFFF',
46
45
  // CSS colours: support RGBA
47
- fieldShadow: "rgba(0,0,0,0.1)",
48
- dropDownShadow: "rgba(0, 0, 0, .3)",
49
- numPadBackground: "#547AB2",
50
- numPadBorder: "#435F91",
51
- numPadActiveBackground: "#435F91",
52
- numPadText: "white", // Do not use hex here, it cannot be inlined with data-uri SVG
53
- valueReportBackground: "#FFFFFF",
54
- valueReportBorder: "#AAAAAA",
55
- contextualMenuHover: "rgba(77, 151, 255, .25)",
56
- menuHover: "rgba(0, 0, 0, .2)",
57
- };
46
+ fieldShadow: 'rgba(0,0,0,0.1)',
47
+ dropDownShadow: 'rgba(0, 0, 0, .3)',
48
+ numPadBackground: '#547AB2',
49
+ numPadBorder: '#435F91',
50
+ numPadActiveBackground: '#435F91',
51
+ numPadText: 'white', // Do not use hex here, it cannot be inlined with data-uri SVG
52
+ valueReportBackground: '#FFFFFF',
53
+ valueReportBorder: '#AAAAAA',
54
+ contextualMenuHover: 'rgba(77, 151, 255, .25)',
55
+ menuHover: 'rgba(0, 0, 0, .2)',
56
+ }
58
57
 
59
58
  /**
60
59
  * Converts the given colours to CSS variables.
61
- *
62
60
  * @param coloursObj A (potentially nested) object whose keys are colour names
63
61
  * and values are CSS colours.
64
62
  * @param prefix A prefix to prepend to the CSS variables.
65
63
  * @returns A string containing CSS variable definitions for the colours.
66
64
  */
67
- function varify(coloursObj: Object, prefix = "--colour"): string {
65
+ function varify(coloursObj: object, prefix = '--colour'): string {
68
66
  return Object.entries(coloursObj)
69
67
  .map(([key, colour]) => {
70
- if (typeof colour === "string") {
71
- return `${prefix}-${key}: ${colour};`;
68
+ if (typeof colour === 'string') {
69
+ return `${prefix}-${key}: ${colour};`
72
70
  } else {
73
- return varify(colour, `${prefix}-${key}`);
71
+ return varify(colour, `${prefix}-${key}`)
74
72
  }
75
73
  })
76
- .join("\n");
74
+ .join('\n')
77
75
  }
78
76
 
79
77
  const cssVariables = `:root {
80
78
  ${varify(Colours)}
81
- }`;
79
+ }`
82
80
 
83
- Blockly.Css.register(cssVariables);
81
+ Blockly.Css.register(cssVariables)
84
82
 
85
- export { Colours };
83
+ export { Colours }