scratch-blocks 2.0.2 → 2.0.3

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 (274) hide show
  1. package/commitlint.config.js +2 -2
  2. package/dist/main.mjs +1 -2
  3. package/dist/types/msg/scratch_msgs.d.ts.map +1 -1
  4. package/dist/types/src/block_reporting.d.ts.map +1 -1
  5. package/dist/types/src/blocks/colour.d.ts +0 -19
  6. package/dist/types/src/blocks/colour.d.ts.map +1 -1
  7. package/dist/types/src/blocks/control.d.ts +0 -19
  8. package/dist/types/src/blocks/control.d.ts.map +1 -1
  9. package/dist/types/src/blocks/data.d.ts +0 -19
  10. package/dist/types/src/blocks/data.d.ts.map +1 -1
  11. package/dist/types/src/blocks/event.d.ts +0 -19
  12. package/dist/types/src/blocks/event.d.ts.map +1 -1
  13. package/dist/types/src/blocks/looks.d.ts +0 -19
  14. package/dist/types/src/blocks/looks.d.ts.map +1 -1
  15. package/dist/types/src/blocks/math.d.ts +0 -19
  16. package/dist/types/src/blocks/math.d.ts.map +1 -1
  17. package/dist/types/src/blocks/matrix.d.ts +0 -19
  18. package/dist/types/src/blocks/matrix.d.ts.map +1 -1
  19. package/dist/types/src/blocks/motion.d.ts +0 -19
  20. package/dist/types/src/blocks/motion.d.ts.map +1 -1
  21. package/dist/types/src/blocks/note.d.ts +0 -19
  22. package/dist/types/src/blocks/note.d.ts.map +1 -1
  23. package/dist/types/src/blocks/operators.d.ts +0 -19
  24. package/dist/types/src/blocks/operators.d.ts.map +1 -1
  25. package/dist/types/src/blocks/procedures.d.ts +6 -9
  26. package/dist/types/src/blocks/procedures.d.ts.map +1 -1
  27. package/dist/types/src/blocks/sensing.d.ts +0 -19
  28. package/dist/types/src/blocks/sensing.d.ts.map +1 -1
  29. package/dist/types/src/blocks/sound.d.ts +0 -19
  30. package/dist/types/src/blocks/sound.d.ts.map +1 -1
  31. package/dist/types/src/blocks/text.d.ts +0 -19
  32. package/dist/types/src/blocks/text.d.ts.map +1 -1
  33. package/dist/types/src/blocks/vertical_extensions.d.ts +0 -19
  34. package/dist/types/src/blocks/vertical_extensions.d.ts.map +1 -1
  35. package/dist/types/src/checkable_continuous_flyout.d.ts +2 -7
  36. package/dist/types/src/checkable_continuous_flyout.d.ts.map +1 -1
  37. package/dist/types/src/checkbox_bubble.d.ts +13 -12
  38. package/dist/types/src/checkbox_bubble.d.ts.map +1 -1
  39. package/dist/types/src/colours.d.ts.map +1 -1
  40. package/dist/types/src/constants.d.ts +0 -7
  41. package/dist/types/src/constants.d.ts.map +1 -1
  42. package/dist/types/src/context_menu_items.d.ts +0 -5
  43. package/dist/types/src/context_menu_items.d.ts.map +1 -1
  44. package/dist/types/src/data_category.d.ts +2 -4
  45. package/dist/types/src/data_category.d.ts.map +1 -1
  46. package/dist/types/src/events/events_block_comment_base.d.ts +2 -3
  47. package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
  48. package/dist/types/src/events/events_block_comment_change.d.ts +0 -5
  49. package/dist/types/src/events/events_block_comment_change.d.ts.map +1 -1
  50. package/dist/types/src/events/events_block_comment_collapse.d.ts +0 -5
  51. package/dist/types/src/events/events_block_comment_collapse.d.ts.map +1 -1
  52. package/dist/types/src/events/events_block_comment_create.d.ts +0 -5
  53. package/dist/types/src/events/events_block_comment_create.d.ts.map +1 -1
  54. package/dist/types/src/events/events_block_comment_delete.d.ts +0 -5
  55. package/dist/types/src/events/events_block_comment_delete.d.ts.map +1 -1
  56. package/dist/types/src/events/events_block_comment_move.d.ts +0 -5
  57. package/dist/types/src/events/events_block_comment_move.d.ts.map +1 -1
  58. package/dist/types/src/events/events_block_comment_resize.d.ts +0 -5
  59. package/dist/types/src/events/events_block_comment_resize.d.ts.map +1 -1
  60. package/dist/types/src/events/events_block_drag_end.d.ts +1 -2
  61. package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
  62. package/dist/types/src/events/events_block_drag_outside.d.ts +1 -2
  63. package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
  64. package/dist/types/src/events/events_scratch_variable_create.d.ts +0 -5
  65. package/dist/types/src/events/events_scratch_variable_create.d.ts.map +1 -1
  66. package/dist/types/src/fields/field_colour_slider.d.ts +3 -27
  67. package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
  68. package/dist/types/src/fields/field_matrix.d.ts +0 -19
  69. package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
  70. package/dist/types/src/fields/field_note.d.ts +8 -23
  71. package/dist/types/src/fields/field_note.d.ts.map +1 -1
  72. package/dist/types/src/fields/field_textinput_removable.d.ts +2 -4
  73. package/dist/types/src/fields/field_textinput_removable.d.ts.map +1 -1
  74. package/dist/types/src/fields/field_variable_getter.d.ts +0 -19
  75. package/dist/types/src/fields/field_variable_getter.d.ts.map +1 -1
  76. package/dist/types/src/fields/field_vertical_separator.d.ts +0 -19
  77. package/dist/types/src/fields/field_vertical_separator.d.ts.map +1 -1
  78. package/dist/types/src/fields/scratch_field_angle.d.ts +0 -19
  79. package/dist/types/src/fields/scratch_field_angle.d.ts.map +1 -1
  80. package/dist/types/src/fields/scratch_field_dropdown.d.ts +0 -5
  81. package/dist/types/src/fields/scratch_field_dropdown.d.ts.map +1 -1
  82. package/dist/types/src/fields/scratch_field_number.d.ts +0 -19
  83. package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
  84. package/dist/types/src/fields/scratch_field_variable.d.ts +4 -7
  85. package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
  86. package/dist/types/src/flyout_checkbox_icon.d.ts +2 -3
  87. package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
  88. package/dist/types/src/glows.d.ts +1 -3
  89. package/dist/types/src/glows.d.ts.map +1 -1
  90. package/dist/types/src/index.d.ts +50 -51
  91. package/dist/types/src/index.d.ts.map +1 -1
  92. package/dist/types/src/procedures.d.ts +6 -8
  93. package/dist/types/src/procedures.d.ts.map +1 -1
  94. package/dist/types/src/recyclable_block_flyout_inflater.d.ts +3 -5
  95. package/dist/types/src/recyclable_block_flyout_inflater.d.ts.map +1 -1
  96. package/dist/types/src/renderer/bowler_hat.d.ts +2 -3
  97. package/dist/types/src/renderer/bowler_hat.d.ts.map +1 -1
  98. package/dist/types/src/renderer/cat/cat_face.d.ts +6 -5
  99. package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
  100. package/dist/types/src/renderer/cat/constants.d.ts +2 -2
  101. package/dist/types/src/renderer/cat/constants.d.ts.map +1 -1
  102. package/dist/types/src/renderer/cat/drawer.d.ts +3 -4
  103. package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
  104. package/dist/types/src/renderer/cat/path_object.d.ts +2 -3
  105. package/dist/types/src/renderer/cat/path_object.d.ts.map +1 -1
  106. package/dist/types/src/renderer/cat/render_info.d.ts +3 -4
  107. package/dist/types/src/renderer/cat/render_info.d.ts.map +1 -1
  108. package/dist/types/src/renderer/cat/renderer.d.ts +6 -7
  109. package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
  110. package/dist/types/src/renderer/constants.d.ts +4 -4
  111. package/dist/types/src/renderer/constants.d.ts.map +1 -1
  112. package/dist/types/src/renderer/drawer.d.ts +5 -4
  113. package/dist/types/src/renderer/drawer.d.ts.map +1 -1
  114. package/dist/types/src/renderer/path_object.d.ts +1 -3
  115. package/dist/types/src/renderer/path_object.d.ts.map +1 -1
  116. package/dist/types/src/renderer/render_info.d.ts +3 -4
  117. package/dist/types/src/renderer/render_info.d.ts.map +1 -1
  118. package/dist/types/src/renderer/renderer.d.ts +8 -15
  119. package/dist/types/src/renderer/renderer.d.ts.map +1 -1
  120. package/dist/types/src/scratch_block_paster.d.ts +0 -5
  121. package/dist/types/src/scratch_block_paster.d.ts.map +1 -1
  122. package/dist/types/src/scratch_blocks_utils.d.ts +0 -20
  123. package/dist/types/src/scratch_blocks_utils.d.ts.map +1 -1
  124. package/dist/types/src/scratch_comment_bubble.d.ts +1 -4
  125. package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
  126. package/dist/types/src/scratch_comment_icon.d.ts +2 -3
  127. package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
  128. package/dist/types/src/scratch_connection_checker.d.ts +0 -5
  129. package/dist/types/src/scratch_connection_checker.d.ts.map +1 -1
  130. package/dist/types/src/scratch_continuous_category.d.ts +5 -5
  131. package/dist/types/src/scratch_continuous_category.d.ts.map +1 -1
  132. package/dist/types/src/scratch_continuous_toolbox.d.ts +3 -6
  133. package/dist/types/src/scratch_continuous_toolbox.d.ts.map +1 -1
  134. package/dist/types/src/scratch_dragger.d.ts +1 -10
  135. package/dist/types/src/scratch_dragger.d.ts.map +1 -1
  136. package/dist/types/src/scratch_insertion_marker_previewer.d.ts +0 -5
  137. package/dist/types/src/scratch_insertion_marker_previewer.d.ts.map +1 -1
  138. package/dist/types/src/scratch_variable_map.d.ts +0 -5
  139. package/dist/types/src/scratch_variable_map.d.ts.map +1 -1
  140. package/dist/types/src/scratch_variable_model.d.ts +1 -2
  141. package/dist/types/src/scratch_variable_model.d.ts.map +1 -1
  142. package/dist/types/src/scratch_zoom_controls.d.ts +4 -6
  143. package/dist/types/src/scratch_zoom_controls.d.ts.map +1 -1
  144. package/dist/types/src/shadows.d.ts +2 -2
  145. package/dist/types/src/shadows.d.ts.map +1 -1
  146. package/dist/types/src/status_indicator_label.d.ts +4 -6
  147. package/dist/types/src/status_indicator_label.d.ts.map +1 -1
  148. package/dist/types/src/status_indicator_label_flyout_inflater.d.ts +1 -6
  149. package/dist/types/src/status_indicator_label_flyout_inflater.d.ts.map +1 -1
  150. package/dist/types/src/variables.d.ts +4 -8
  151. package/dist/types/src/variables.d.ts.map +1 -1
  152. package/dist/types/src/xml.d.ts +2 -3
  153. package/dist/types/src/xml.d.ts.map +1 -1
  154. package/dist/types/tests/jsunit/block_test.d.ts.map +1 -1
  155. package/dist/types/tests/jsunit/connection_db_test.d.ts.map +1 -1
  156. package/dist/types/tests/jsunit/connection_test.d.ts.map +1 -1
  157. package/dist/types/tests/jsunit/event_test.d.ts.map +1 -1
  158. package/dist/types/tests/jsunit/extensions_test.d.ts.map +1 -1
  159. package/dist/types/tests/jsunit/field_number_test.d.ts.map +1 -1
  160. package/dist/types/tests/jsunit/field_test.d.ts.map +1 -1
  161. package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +1 -1
  162. package/dist/types/tests/jsunit/field_variable_test.d.ts.map +1 -1
  163. package/dist/types/tests/jsunit/gesture_test.d.ts.map +1 -1
  164. package/dist/types/tests/jsunit/input_test.d.ts +1 -0
  165. package/dist/types/tests/jsunit/input_test.d.ts.map +1 -1
  166. package/dist/types/tests/jsunit/json_test.d.ts.map +1 -1
  167. package/dist/types/tests/jsunit/names_test.d.ts.map +1 -1
  168. package/dist/types/tests/jsunit/procedure_test.d.ts.map +1 -1
  169. package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +1 -1
  170. package/dist/types/tests/jsunit/svg_test.d.ts.map +1 -1
  171. package/dist/types/tests/jsunit/test_utilities.d.ts.map +1 -1
  172. package/dist/types/tests/jsunit/utils_test.d.ts.map +1 -1
  173. package/dist/types/tests/jsunit/variable_map_test.d.ts.map +1 -1
  174. package/dist/types/tests/jsunit/variable_model_test.d.ts.map +1 -1
  175. package/dist/types/tests/jsunit/widget_div_test.d.ts.map +1 -1
  176. package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +1 -1
  177. package/dist/types/tests/jsunit/workspace_test.d.ts.map +1 -1
  178. package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +1 -1
  179. package/dist/types/tests/jsunit/xml_test.d.ts.map +1 -1
  180. package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +1 -1
  181. package/eslint.config.mjs +69 -0
  182. package/i18n/create_scratch_msgs.js +44 -45
  183. package/i18n/js_to_json.js +40 -32
  184. package/i18n/json_to_js.js +37 -37
  185. package/i18n/sync_tx_translations.js +64 -65
  186. package/i18n/test_scratch_msgs.js +66 -63
  187. package/msg/js/en.js +289 -287
  188. package/msg/json/en.json +284 -284
  189. package/msg/messages.js +289 -287
  190. package/msg/scratch_msgs.js +22959 -22970
  191. package/package.json +6 -3
  192. package/prettier.config.mjs +3 -0
  193. package/release.config.js +7 -7
  194. package/renovate.json5 +7 -9
  195. package/src/block_reporting.ts +15 -18
  196. package/src/blocks/colour.ts +12 -15
  197. package/src/blocks/control.ts +167 -177
  198. package/src/blocks/data.ts +225 -292
  199. package/src/blocks/event.ts +121 -123
  200. package/src/blocks/looks.ts +165 -167
  201. package/src/blocks/math.ts +44 -46
  202. package/src/blocks/matrix.ts +11 -13
  203. package/src/blocks/motion.ts +151 -153
  204. package/src/blocks/note.ts +11 -13
  205. package/src/blocks/operators.ts +158 -160
  206. package/src/blocks/procedures.ts +415 -523
  207. package/src/blocks/sensing.ts +163 -165
  208. package/src/blocks/sound.ts +58 -60
  209. package/src/blocks/text.ts +10 -12
  210. package/src/blocks/vertical_extensions.ts +86 -102
  211. package/src/checkable_continuous_flyout.ts +25 -42
  212. package/src/checkbox_bubble.ts +83 -100
  213. package/src/colours.ts +35 -37
  214. package/src/constants.ts +22 -29
  215. package/src/context_menu_items.ts +56 -81
  216. package/src/css.ts +3 -4
  217. package/src/data_category.ts +137 -251
  218. package/src/events/events_block_comment_base.ts +21 -31
  219. package/src/events/events_block_comment_change.ts +21 -42
  220. package/src/events/events_block_comment_collapse.ts +22 -43
  221. package/src/events/events_block_comment_create.ts +29 -46
  222. package/src/events/events_block_comment_delete.ts +10 -19
  223. package/src/events/events_block_comment_move.ts +27 -52
  224. package/src/events/events_block_comment_resize.ts +28 -55
  225. package/src/events/events_block_drag_end.ts +16 -26
  226. package/src/events/events_block_drag_outside.ts +12 -22
  227. package/src/events/events_scratch_variable_create.ts +33 -56
  228. package/src/fields/field_colour_slider.ts +173 -228
  229. package/src/fields/field_matrix.ts +200 -269
  230. package/src/fields/field_note.ts +272 -377
  231. package/src/fields/field_textinput_removable.ts +25 -40
  232. package/src/fields/field_variable_getter.ts +26 -31
  233. package/src/fields/field_vertical_separator.ts +19 -24
  234. package/src/fields/scratch_field_angle.ts +150 -186
  235. package/src/fields/scratch_field_dropdown.ts +15 -19
  236. package/src/fields/scratch_field_number.ts +123 -180
  237. package/src/fields/scratch_field_variable.ts +54 -75
  238. package/src/flyout_checkbox_icon.ts +18 -28
  239. package/src/glows.ts +51 -58
  240. package/src/index.ts +119 -133
  241. package/src/procedures.ts +146 -213
  242. package/src/recyclable_block_flyout_inflater.ts +14 -25
  243. package/src/renderer/bowler_hat.ts +6 -8
  244. package/src/renderer/cat/cat_face.ts +98 -99
  245. package/src/renderer/cat/constants.ts +67 -87
  246. package/src/renderer/cat/drawer.ts +21 -27
  247. package/src/renderer/cat/path_object.ts +3 -5
  248. package/src/renderer/cat/render_info.ts +5 -8
  249. package/src/renderer/cat/renderer.ts +11 -15
  250. package/src/renderer/constants.ts +34 -49
  251. package/src/renderer/drawer.ts +35 -51
  252. package/src/renderer/path_object.ts +4 -10
  253. package/src/renderer/render_info.ts +36 -56
  254. package/src/renderer/renderer.ts +16 -29
  255. package/src/scratch_block_paster.ts +12 -20
  256. package/src/scratch_blocks_utils.ts +4 -7
  257. package/src/scratch_comment_bubble.ts +70 -101
  258. package/src/scratch_comment_icon.ts +74 -123
  259. package/src/scratch_connection_checker.ts +7 -17
  260. package/src/scratch_continuous_category.ts +24 -28
  261. package/src/scratch_continuous_toolbox.ts +20 -27
  262. package/src/scratch_dragger.ts +42 -81
  263. package/src/scratch_insertion_marker_previewer.ts +6 -11
  264. package/src/scratch_variable_map.ts +5 -12
  265. package/src/scratch_variable_model.ts +4 -11
  266. package/src/scratch_zoom_controls.ts +101 -156
  267. package/src/shadows.ts +32 -37
  268. package/src/status_indicator_label.ts +54 -67
  269. package/src/status_indicator_label_flyout_inflater.ts +11 -21
  270. package/src/variables.ts +89 -138
  271. package/src/xml.ts +21 -35
  272. package/tsconfig.json +2 -6
  273. package/types/continuous-toolbox.d.ts +1 -1
  274. package/dist/main.mjs.LICENSE.txt +0 -163
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license
3
2
  * Visual Blocks Editor
4
3
  *
5
4
  * Copyright 2012 Google Inc.
@@ -17,32 +16,31 @@
17
16
  * See the License for the specific language governing permissions and
18
17
  * limitations under the License.
19
18
  */
20
-
21
19
  /**
22
- * @fileoverview Procedure blocks for Scratch.
20
+ * @file Procedure blocks for Scratch.
23
21
  */
24
-
25
- import * as Blockly from "blockly/core";
26
- import { FieldTextInputRemovable } from "../fields/field_textinput_removable";
27
- import type { ScratchDragger } from "../scratch_dragger";
22
+ import * as Blockly from 'blockly/core'
23
+ import { FieldTextInputRemovable } from '../fields/field_textinput_removable'
24
+ import type { ScratchDragger } from '../scratch_dragger'
28
25
 
29
26
  /**
30
27
  * An object mapping argument IDs to blocks and shadow DOMs.
31
28
  */
32
- type ConnectionMap = {
33
- [key: string]: {
34
- shadow: Element;
35
- block: Blockly.BlockSvg;
36
- } | null;
37
- };
29
+ type ConnectionMap = Record<
30
+ string,
31
+ {
32
+ shadow: Element
33
+ block: Blockly.BlockSvg
34
+ } | null
35
+ >
38
36
 
39
37
  /**
40
38
  * Possible types for procedure arguments.
41
39
  */
42
40
  enum ArgumentType {
43
- STRING = "s",
44
- NUMBER = "n",
45
- BOOLEAN = "b",
41
+ STRING = 's',
42
+ NUMBER = 'n',
43
+ BOOLEAN = 'b',
46
44
  }
47
45
 
48
46
  /**
@@ -52,66 +50,59 @@ class DuplicateOnDragDraggable implements Blockly.IDraggable {
52
50
  /**
53
51
  * The newly-created duplicate block.
54
52
  */
55
- private copy?: Blockly.BlockSvg;
53
+ private copy?: Blockly.BlockSvg
56
54
  constructor(private block: Blockly.BlockSvg) {}
57
55
 
58
56
  /**
59
- * Returns whether or not this draggable is movable. */
57
+ * Returns whether or not this draggable is movable.
58
+ * @returns Always true.
59
+ */
60
60
  isMovable(): boolean {
61
- return true;
61
+ return true
62
62
  }
63
63
 
64
64
  /**
65
65
  * Handles the start of a drag.
66
- *
67
66
  * @param e The event that triggered the drag.
68
67
  */
69
68
  startDrag(e: PointerEvent) {
70
- const data = this.block.toCopyData();
69
+ const data = this.block.toCopyData()
71
70
  if (!data) {
72
71
  console.warn(
73
- "DuplicateOnDragDraggable.startDrag: failed to serialize block for copy",
72
+ 'DuplicateOnDragDraggable.startDrag: failed to serialize block for copy',
74
73
  this.block.type,
75
- this.block.id
76
- );
77
- return;
74
+ this.block.id,
75
+ )
76
+ return
78
77
  }
79
- this.copy = Blockly.clipboard.paste(
80
- data,
81
- this.block.workspace
82
- ) as Blockly.BlockSvg;
83
- this.copy.startDrag(e);
78
+ this.copy = Blockly.clipboard.paste(data, this.block.workspace) as Blockly.BlockSvg
79
+ this.copy.startDrag(e)
84
80
  }
85
81
 
86
82
  drag(newLoc: Blockly.utils.Coordinate, e?: PointerEvent) {
87
- const gesture = this.block.workspace.getGesture(e);
83
+ const gesture = this.block.workspace.getGesture(e)
88
84
  if (!gesture || !this.copy) {
89
- console.warn(
90
- "DuplicateOnDragDraggable.drag: missing gesture or copied block",
91
- {
92
- hasGesture: Boolean(gesture),
93
- hasCopy: Boolean(this.copy),
94
- blockId: this.block.id,
95
- }
96
- );
97
- return;
85
+ console.warn('DuplicateOnDragDraggable.drag: missing gesture or copied block', {
86
+ hasGesture: Boolean(gesture),
87
+ hasCopy: Boolean(this.copy),
88
+ blockId: this.block.id,
89
+ })
90
+ return
98
91
  }
99
- (gesture.getCurrentDragger() as ScratchDragger).setDraggable(this.copy);
100
- this.copy.drag(newLoc, e);
92
+ ;(gesture.getCurrentDragger() as ScratchDragger).setDraggable(this.copy)
93
+ this.copy.drag(newLoc, e)
101
94
  }
102
95
 
103
96
  endDrag(e: PointerEvent) {
104
- this.copy?.endDrag(e);
97
+ this.copy?.endDrag(e)
105
98
  }
106
99
 
107
100
  revertDrag() {
108
- this.copy?.dispose();
101
+ this.copy?.dispose()
109
102
  }
110
103
 
111
104
  getRelativeToSurfaceXY() {
112
- return this.copy
113
- ? this.copy.getRelativeToSurfaceXY()
114
- : this.block.getRelativeToSurfaceXY();
105
+ return this.copy ? this.copy.getRelativeToSurfaceXY() : this.block.getRelativeToSurfaceXY()
115
106
  }
116
107
  }
117
108
 
@@ -120,85 +111,71 @@ class DuplicateOnDragDraggable implements Blockly.IDraggable {
120
111
  /**
121
112
  * Create XML to represent the (non-editable) name and arguments of a procedure
122
113
  * call block.
123
- *
124
114
  * @returns XML storage element.
125
115
  */
126
116
  function callerMutationToDom(this: ProcedureCallBlock): Element {
127
- const container = document.createElement("mutation");
128
- container.setAttribute("proccode", this.procCode_);
129
- container.setAttribute("argumentids", JSON.stringify(this.argumentIds_));
130
- container.setAttribute("warp", JSON.stringify(this.warp_));
131
- return container;
117
+ const container = document.createElement('mutation')
118
+ container.setAttribute('proccode', this.procCode_)
119
+ container.setAttribute('argumentids', JSON.stringify(this.argumentIds_))
120
+ container.setAttribute('warp', JSON.stringify(this.warp_))
121
+ return container
132
122
  }
133
123
 
134
124
  /**
135
125
  * Parse XML to restore the (non-editable) name and arguments of a procedure
136
126
  * call block.
137
- *
138
127
  * @param xmlElement XML storage element.
139
128
  */
140
129
  function callerDomToMutation(this: ProcedureCallBlock, xmlElement: Element) {
141
- this.procCode_ = xmlElement.getAttribute("proccode")!;
142
- this.generateShadows_ = JSON.parse(
143
- xmlElement.getAttribute("generateshadows")!
144
- );
145
- this.argumentIds_ = JSON.parse(xmlElement.getAttribute("argumentids")!);
146
- this.warp_ = JSON.parse(xmlElement.getAttribute("warp")!);
147
- this.updateDisplay_();
130
+ this.procCode_ = xmlElement.getAttribute('proccode')!
131
+ this.generateShadows_ = JSON.parse(xmlElement.getAttribute('generateshadows')!)
132
+ this.argumentIds_ = JSON.parse(xmlElement.getAttribute('argumentids')!)
133
+ this.warp_ = JSON.parse(xmlElement.getAttribute('warp')!)
134
+ this.updateDisplay_()
148
135
  }
149
136
 
150
137
  /**
151
138
  * Create XML to represent the (non-editable) name and arguments of a
152
139
  * procedures_prototype block or a procedures_declaration block.
153
- *
154
140
  * @param opt_generateShadows Whether to include the generateshadows flag in the
155
141
  * generated XML. False if not provided.
156
142
  * @returns XML storage element.
157
143
  */
158
144
  function definitionMutationToDom(
159
145
  this: ProcedurePrototypeBlock | ProcedureDeclarationBlock,
160
- opt_generateShadows?: boolean
146
+ opt_generateShadows?: boolean,
161
147
  ): Element {
162
- const container = document.createElement("mutation");
148
+ const container = document.createElement('mutation')
163
149
 
164
150
  if (opt_generateShadows) {
165
- container.setAttribute("generateshadows", "true");
151
+ container.setAttribute('generateshadows', 'true')
166
152
  }
167
- container.setAttribute("proccode", this.procCode_);
168
- container.setAttribute("argumentids", JSON.stringify(this.argumentIds_));
169
- container.setAttribute("argumentnames", JSON.stringify(this.displayNames_));
170
- container.setAttribute(
171
- "argumentdefaults",
172
- JSON.stringify(this.argumentDefaults_)
173
- );
174
- container.setAttribute("warp", JSON.stringify(this.warp_));
175
- return container;
153
+ container.setAttribute('proccode', this.procCode_)
154
+ container.setAttribute('argumentids', JSON.stringify(this.argumentIds_))
155
+ container.setAttribute('argumentnames', JSON.stringify(this.displayNames_))
156
+ container.setAttribute('argumentdefaults', JSON.stringify(this.argumentDefaults_))
157
+ container.setAttribute('warp', JSON.stringify(this.warp_))
158
+ return container
176
159
  }
177
160
 
178
161
  /**
179
162
  * Parse XML to restore the (non-editable) name and arguments of a
180
163
  * procedures_prototype block or a procedures_declaration block.
181
- *
182
164
  * @param xmlElement XML storage element.
183
165
  */
184
- function definitionDomToMutation(
185
- this: ProcedurePrototypeBlock | ProcedureDeclarationBlock,
186
- xmlElement: Element
187
- ) {
188
- this.procCode_ = xmlElement.getAttribute("proccode")!;
189
- this.warp_ = JSON.parse(xmlElement.getAttribute("warp")!);
190
-
191
- const prevArgIds = this.argumentIds_;
192
- const prevDisplayNames = this.displayNames_;
193
-
194
- this.argumentIds_ = JSON.parse(xmlElement.getAttribute("argumentids")!);
195
- this.displayNames_ = JSON.parse(xmlElement.getAttribute("argumentnames")!);
196
- this.argumentDefaults_ = JSON.parse(
197
- xmlElement.getAttribute("argumentdefaults")!
198
- );
199
- this.updateDisplay_();
200
- if ("updateArgumentReporterNames_" in this) {
201
- this.updateArgumentReporterNames_(prevArgIds, prevDisplayNames);
166
+ function definitionDomToMutation(this: ProcedurePrototypeBlock | ProcedureDeclarationBlock, xmlElement: Element) {
167
+ this.procCode_ = xmlElement.getAttribute('proccode')!
168
+ this.warp_ = JSON.parse(xmlElement.getAttribute('warp')!)
169
+
170
+ const prevArgIds = this.argumentIds_
171
+ const prevDisplayNames = this.displayNames_
172
+
173
+ this.argumentIds_ = JSON.parse(xmlElement.getAttribute('argumentids')!)
174
+ this.displayNames_ = JSON.parse(xmlElement.getAttribute('argumentnames')!)
175
+ this.argumentDefaults_ = JSON.parse(xmlElement.getAttribute('argumentdefaults')!)
176
+ this.updateDisplay_()
177
+ if ('updateArgumentReporterNames_' in this) {
178
+ this.updateArgumentReporterNames_(prevArgIds, prevDisplayNames)
202
179
  }
203
180
  }
204
181
 
@@ -209,11 +186,10 @@ function definitionDomToMutation(
209
186
  /**
210
187
  * Returns the name of the procedure this block calls, or the empty string if
211
188
  * it has not yet been set.
212
- *
213
189
  * @returns Procedure name.
214
190
  */
215
191
  function getProcCode(this: ProcedureBlock): string {
216
- return this.procCode_;
192
+ return this.procCode_
217
193
  }
218
194
 
219
195
  /**
@@ -221,10 +197,10 @@ function getProcCode(this: ProcedureBlock): string {
221
197
  * mutation.
222
198
  */
223
199
  function updateDisplay_(this: ProcedureBlock) {
224
- const connectionMap = this.disconnectOldBlocks_();
225
- this.removeAllInputs_();
226
- this.createAllInputs_(connectionMap);
227
- this.deleteShadows_(connectionMap);
200
+ const connectionMap = this.disconnectOldBlocks_()
201
+ this.removeAllInputs_()
202
+ this.createAllInputs_(connectionMap)
203
+ this.deleteShadows_(connectionMap)
228
204
  }
229
205
 
230
206
  /**
@@ -232,27 +208,26 @@ function updateDisplay_(this: ProcedureBlock) {
232
208
  * in case they can be reattached later. Also save the shadow DOM if it exists.
233
209
  * The result is a map from argument ID to information that was associated with
234
210
  * that argument at the beginning of the mutation.
235
- *
236
211
  * @returns An object mapping argument IDs to blocks and shadow DOMs.
237
212
  */
238
213
  function disconnectOldBlocks_(this: ProcedureBlock): ConnectionMap {
239
214
  // Remove old stuff
240
- const connectionMap: ConnectionMap = {};
215
+ const connectionMap: ConnectionMap = {}
241
216
  for (const input of this.inputList) {
242
217
  if (input.connection) {
243
- const target = input.connection.targetBlock() as Blockly.BlockSvg;
218
+ const target = input.connection.targetBlock() as Blockly.BlockSvg
244
219
  const saveInfo = {
245
- shadow: input.connection.getShadowDom(true) as Element,
220
+ shadow: input.connection.getShadowDom(true)!,
246
221
  block: target,
247
- };
248
- connectionMap[input.name] = saveInfo;
222
+ }
223
+ connectionMap[input.name] = saveInfo
249
224
 
250
225
  if (target) {
251
- input.connection.disconnect();
226
+ input.connection.disconnect()
252
227
  }
253
228
  }
254
229
  }
255
- return connectionMap;
230
+ return connectionMap
256
231
  }
257
232
 
258
233
  /**
@@ -262,29 +237,26 @@ function disconnectOldBlocks_(this: ProcedureBlock): ConnectionMap {
262
237
  function removeAllInputs_(this: ProcedureBlock) {
263
238
  // Delete inputs directly instead of with block.removeInput to avoid splicing
264
239
  // out of the input list at every index.
265
- this.inputList.forEach((input: Blockly.Input) => input.dispose());
266
- this.inputList = [];
240
+ this.inputList.forEach((input: Blockly.Input) => input.dispose())
241
+ this.inputList = []
267
242
  }
268
243
 
269
244
  /**
270
245
  * Create all inputs specified by the new procCode, and populate them with
271
246
  * shadow blocks or reconnected old blocks as appropriate.
272
- *
273
247
  * @param connectionMap An object mapping argument IDs to blocks and shadow DOMs.
274
248
  */
275
249
  function createAllInputs_(this: ProcedureBlock, connectionMap: ConnectionMap) {
276
250
  // Split the proc into components, by %n, %b, and %s (ignoring escaped).
277
- const procComponents = this.procCode_
278
- .split(/(?=[^\\]%[nbs])/)
279
- .map(function (c: string) {
280
- return c.trim(); // Strip whitespace.
281
- });
251
+ const procComponents = this.procCode_.split(/(?=[^\\]%[nbs])/).map(
252
+ (c: string) => c.trim(), // Strip whitespace.
253
+ )
282
254
  // Create arguments and labels as appropriate.
283
- let argumentCount = 0;
255
+ let argumentCount = 0
284
256
  for (const component of procComponents) {
285
- let labelText;
286
- if (component.substring(0, 1) === "%") {
287
- const argumentType = component.substring(1, 2);
257
+ let labelText
258
+ if (component.startsWith('%')) {
259
+ const argumentType = component.substring(1, 2)
288
260
  if (
289
261
  !(
290
262
  argumentType === ArgumentType.NUMBER ||
@@ -292,36 +264,27 @@ function createAllInputs_(this: ProcedureBlock, connectionMap: ConnectionMap) {
292
264
  argumentType === ArgumentType.STRING
293
265
  )
294
266
  ) {
295
- throw new Error(
296
- "Found an custom procedure with an invalid type: " + argumentType
297
- );
267
+ throw new Error('Found an custom procedure with an invalid type: ' + argumentType)
298
268
  }
299
- labelText = component.substring(2).trim();
269
+ labelText = component.substring(2).trim()
300
270
 
301
- const id = this.argumentIds_[argumentCount];
271
+ const id = this.argumentIds_[argumentCount]
302
272
 
303
- const input = this.appendValueInput(id);
273
+ const input = this.appendValueInput(id)
304
274
  if (argumentType === ArgumentType.BOOLEAN) {
305
- input.setCheck("Boolean");
275
+ input.setCheck('Boolean')
306
276
  }
307
- this.populateArgument_(
308
- argumentType,
309
- argumentCount,
310
- connectionMap,
311
- id,
312
- input
313
- );
314
- argumentCount++;
277
+ this.populateArgument_(argumentType, argumentCount, connectionMap, id, input)
278
+ argumentCount++
315
279
  } else {
316
- labelText = component.trim();
280
+ labelText = component.trim()
317
281
  }
318
- this.addProcedureLabel_(labelText.replace(/\\%/, "%"));
282
+ this.addProcedureLabel_(labelText.replace(/\\%/, '%'))
319
283
  }
320
284
  }
321
285
 
322
286
  /**
323
287
  * Delete all shadow blocks in the given map.
324
- *
325
288
  * @param connectionMap An object mapping argument IDs to the blocks that were
326
289
  * connected to those IDs at the beginning of the mutation.
327
290
  */
@@ -329,12 +292,12 @@ function deleteShadows_(this: ProcedureBlock, connectionMap: ConnectionMap) {
329
292
  // Get rid of all of the old shadow blocks if they aren't connected.
330
293
  if (connectionMap) {
331
294
  for (const id in connectionMap) {
332
- const saveInfo = connectionMap[id];
295
+ const saveInfo = connectionMap[id]
333
296
  if (saveInfo) {
334
- const block = saveInfo["block"];
297
+ const block = saveInfo.block
335
298
  if (block && block.isShadow()) {
336
- block.dispose();
337
- connectionMap[id] = null;
299
+ block.dispose()
300
+ connectionMap[id] = null
338
301
  // At this point we know which shadow DOMs are about to be orphaned in
339
302
  // the VM. What do we do with that information?
340
303
  }
@@ -347,104 +310,84 @@ function deleteShadows_(this: ProcedureBlock, connectionMap: ConnectionMap) {
347
310
  /**
348
311
  * Add a label field with the given text to a procedures_call or
349
312
  * procedures_prototype block.
350
- *
351
- * @param text The label text.
313
+ * @param text The string to display in the block's label field.
352
314
  */
353
- function addLabelField_(
354
- this: ProcedureCallBlock | ProcedurePrototypeBlock,
355
- text: string
356
- ) {
357
- this.appendDummyInput().appendField(text);
315
+ function addLabelField_(this: ProcedureCallBlock | ProcedurePrototypeBlock, text: string) {
316
+ this.appendDummyInput().appendField(text)
358
317
  }
359
318
 
360
319
  /**
361
320
  * Add a label editor with the given text to a procedures_declaration
362
321
  * block. Editing the text in the label editor updates the text of the
363
322
  * corresponding label fields on function calls.
364
- *
365
- * @param text The label text.
323
+ * @param text The initial string to show in the label editor.
366
324
  */
367
325
  function addLabelEditor_(this: ProcedureDeclarationBlock, text: string) {
368
326
  if (text) {
369
- this.appendDummyInput(Blockly.utils.idGenerator.genUid()).appendField(
370
- new FieldTextInputRemovable(text)
371
- );
327
+ this.appendDummyInput(Blockly.utils.idGenerator.genUid()).appendField(new FieldTextInputRemovable(text))
372
328
  }
373
329
  }
374
330
 
375
331
  /**
376
332
  * Build a DOM node representing a shadow block of the given type.
377
- *
378
333
  * @param type One of 's' (string) or 'n' (number).
379
334
  * @returns The DOM node representing the new shadow block.
380
335
  */
381
336
  function buildShadowDom_(type: ArgumentType): Element {
382
- const shadowDom = document.createElement("shadow");
383
- let shadowType, fieldName, fieldValue;
337
+ const shadowDom = document.createElement('shadow')
338
+ let shadowType, fieldName, fieldValue
384
339
  if (type === ArgumentType.NUMBER) {
385
- shadowType = "math_number";
386
- fieldName = "NUM";
387
- fieldValue = "1";
340
+ shadowType = 'math_number'
341
+ fieldName = 'NUM'
342
+ fieldValue = '1'
388
343
  } else {
389
- shadowType = "text";
390
- fieldName = "TEXT";
391
- fieldValue = "";
344
+ shadowType = 'text'
345
+ fieldName = 'TEXT'
346
+ fieldValue = ''
392
347
  }
393
- shadowDom.setAttribute("type", shadowType);
394
- const fieldDom = document.createElement("field");
395
- fieldDom.textContent = fieldValue;
396
- fieldDom.setAttribute("name", fieldName);
397
- shadowDom.appendChild(fieldDom);
398
- return shadowDom;
348
+ shadowDom.setAttribute('type', shadowType)
349
+ const fieldDom = document.createElement('field')
350
+ fieldDom.textContent = fieldValue
351
+ fieldDom.setAttribute('name', fieldName)
352
+ shadowDom.appendChild(fieldDom)
353
+ return shadowDom
399
354
  }
400
355
 
401
356
  /**
402
357
  * Create a new shadow block and attach it to the given input.
403
- *
404
358
  * @param input The value input to attach a block to.
405
359
  * @param argumentType One of 'b' (boolean), 's' (string) or
406
360
  * 'n' (number).
407
361
  */
408
- function attachShadow_(
409
- this: ProcedureCallBlock,
410
- input: Blockly.Input,
411
- argumentType: ArgumentType
412
- ) {
413
- if (
414
- argumentType === ArgumentType.NUMBER ||
415
- argumentType === ArgumentType.STRING
416
- ) {
417
- const blockType =
418
- argumentType === ArgumentType.NUMBER ? "math_number" : "text";
419
- Blockly.Events.disable();
420
- let newBlock;
362
+ function attachShadow_(this: ProcedureCallBlock, input: Blockly.Input, argumentType: ArgumentType) {
363
+ if (argumentType === ArgumentType.NUMBER || argumentType === ArgumentType.STRING) {
364
+ const blockType = argumentType === ArgumentType.NUMBER ? 'math_number' : 'text'
365
+ Blockly.Events.disable()
366
+ let newBlock
421
367
  try {
422
- newBlock = this.workspace.newBlock(blockType);
368
+ newBlock = this.workspace.newBlock(blockType)
423
369
  if (argumentType === ArgumentType.NUMBER) {
424
- newBlock.setFieldValue("1", "NUM");
370
+ newBlock.setFieldValue('1', 'NUM')
425
371
  } else {
426
- newBlock.setFieldValue("", "TEXT");
372
+ newBlock.setFieldValue('', 'TEXT')
427
373
  }
428
- newBlock.setShadow(true);
374
+ newBlock.setShadow(true)
429
375
  if (!this.isInsertionMarker()) {
430
- newBlock.initSvg();
431
- newBlock.render();
376
+ newBlock.initSvg()
377
+ newBlock.render()
432
378
  }
433
379
  } finally {
434
- Blockly.Events.enable();
380
+ Blockly.Events.enable()
435
381
  }
436
382
  if (Blockly.Events.isEnabled()) {
437
- Blockly.Events.fire(
438
- new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock)
439
- );
383
+ Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock))
440
384
  }
441
- newBlock.outputConnection!.connect(input.connection!);
385
+ newBlock.outputConnection.connect(input.connection!)
442
386
  }
443
387
  }
444
388
 
445
389
  /**
446
390
  * Create a new argument reporter block.
447
- *
448
391
  * @param argumentType One of 'b' (boolean), 's' (string) or
449
392
  * 'n' (number).
450
393
  * @param displayName The name of the argument as provided by the
@@ -454,42 +397,36 @@ function attachShadow_(
454
397
  function createArgumentReporter_(
455
398
  this: ProcedurePrototypeBlock,
456
399
  argumentType: ArgumentType,
457
- displayName: string
400
+ displayName: string,
458
401
  ): Blockly.BlockSvg {
459
- let blockType;
460
- if (
461
- argumentType === ArgumentType.NUMBER ||
462
- argumentType === ArgumentType.STRING
463
- ) {
464
- blockType = "argument_reporter_string_number";
402
+ let blockType
403
+ if (argumentType === ArgumentType.NUMBER || argumentType === ArgumentType.STRING) {
404
+ blockType = 'argument_reporter_string_number'
465
405
  } else {
466
- blockType = "argument_reporter_boolean";
406
+ blockType = 'argument_reporter_boolean'
467
407
  }
468
- Blockly.Events.disable();
469
- let newBlock;
408
+ Blockly.Events.disable()
409
+ let newBlock
470
410
  try {
471
- newBlock = this.workspace.newBlock(blockType);
472
- newBlock.setShadow(true);
473
- newBlock.setFieldValue(displayName, "VALUE");
411
+ newBlock = this.workspace.newBlock(blockType)
412
+ newBlock.setShadow(true)
413
+ newBlock.setFieldValue(displayName, 'VALUE')
474
414
  if (!this.isInsertionMarker()) {
475
- newBlock.initSvg();
476
- newBlock.render();
415
+ newBlock.initSvg()
416
+ newBlock.render()
477
417
  }
478
418
  } finally {
479
- Blockly.Events.enable();
419
+ Blockly.Events.enable()
480
420
  }
481
421
  if (Blockly.Events.isEnabled()) {
482
- Blockly.Events.fire(
483
- new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock)
484
- );
422
+ Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock))
485
423
  }
486
- return newBlock;
424
+ return newBlock
487
425
  }
488
426
 
489
427
  /**
490
428
  * Populate the argument by attaching the correct child block or shadow to the
491
429
  * given input.
492
- *
493
430
  * @param type One of 'b' (boolean), 's' (string) or 'n' (number).
494
431
  * @param index The index of this argument into the argument id array.
495
432
  * @param connectionMap An object mapping argument IDs to blocks and shadow DOMs.
@@ -502,33 +439,32 @@ function populateArgumentOnCaller_(
502
439
  index: number,
503
440
  connectionMap: ConnectionMap,
504
441
  id: string,
505
- input: Blockly.Input
442
+ input: Blockly.Input,
506
443
  ) {
507
- let oldBlock: Blockly.BlockSvg | undefined;
508
- let oldShadow: Element | undefined;
444
+ let oldBlock: Blockly.BlockSvg | undefined
445
+ let oldShadow: Element | undefined
509
446
  if (connectionMap && id in connectionMap) {
510
- const saveInfo = connectionMap[id];
511
- oldBlock = saveInfo?.["block"];
512
- oldShadow = saveInfo?.["shadow"];
447
+ const saveInfo = connectionMap[id]
448
+ oldBlock = saveInfo?.block
449
+ oldShadow = saveInfo?.shadow
513
450
  }
514
451
 
515
452
  if (connectionMap && oldBlock) {
516
453
  // Reattach the old block and shadow DOM.
517
- connectionMap[input.name] = null;
518
- oldBlock.outputConnection!.connect(input.connection!);
454
+ connectionMap[input.name] = null
455
+ oldBlock.outputConnection.connect(input.connection!)
519
456
  if (type !== ArgumentType.BOOLEAN && this.generateShadows_) {
520
- const shadowDom = oldShadow || this.buildShadowDom_(type);
521
- input.connection!.setShadowDom(shadowDom);
457
+ const shadowDom = oldShadow || this.buildShadowDom_(type)
458
+ input.connection!.setShadowDom(shadowDom)
522
459
  }
523
460
  } else if (this.generateShadows_) {
524
- this.attachShadow_(input, type);
461
+ this.attachShadow_(input, type)
525
462
  }
526
463
  }
527
464
 
528
465
  /**
529
466
  * Populate the argument by attaching the correct argument reporter to the given
530
467
  * input.
531
- *
532
468
  * @param type One of 'b' (boolean), 's' (string) or 'n' (number).
533
469
  * @param index The index of this argument into the argument ID and
534
470
  * argument display name arrays.
@@ -542,37 +478,36 @@ function populateArgumentOnPrototype_(
542
478
  index: number,
543
479
  connectionMap: ConnectionMap,
544
480
  id: string,
545
- input: Blockly.Input
481
+ input: Blockly.Input,
546
482
  ) {
547
- let oldBlock: Blockly.BlockSvg | null = null;
483
+ let oldBlock: Blockly.BlockSvg | null = null
548
484
  if (connectionMap && id in connectionMap) {
549
- const saveInfo = connectionMap[id];
550
- oldBlock = saveInfo?.["block"] ?? null;
485
+ const saveInfo = connectionMap[id]
486
+ oldBlock = saveInfo?.block ?? null
551
487
  }
552
488
 
553
- const oldTypeMatches = checkOldTypeMatches_(oldBlock, type);
554
- const displayName = this.displayNames_[index];
489
+ const oldTypeMatches = checkOldTypeMatches_(oldBlock, type)
490
+ const displayName = this.displayNames_[index]
555
491
 
556
492
  // Decide which block to attach.
557
- let argumentReporter: Blockly.BlockSvg;
493
+ let argumentReporter: Blockly.BlockSvg
558
494
  if (connectionMap && oldBlock && oldTypeMatches) {
559
495
  // Update the text if needed. The old argument reporter is the same type,
560
496
  // and on the same input, but the argument's display name may have changed.
561
- argumentReporter = oldBlock;
562
- argumentReporter.setFieldValue(displayName, "VALUE");
563
- connectionMap[input.name] = null;
497
+ argumentReporter = oldBlock
498
+ argumentReporter.setFieldValue(displayName, 'VALUE')
499
+ connectionMap[input.name] = null
564
500
  } else {
565
- argumentReporter = this.createArgumentReporter_(type, displayName);
501
+ argumentReporter = this.createArgumentReporter_(type, displayName)
566
502
  }
567
503
 
568
504
  // Attach the block.
569
- input.connection!.connect(argumentReporter.outputConnection!);
505
+ input.connection!.connect(argumentReporter.outputConnection)
570
506
  }
571
507
 
572
508
  /**
573
509
  * Populate the argument by attaching the correct argument editor to the given
574
510
  * input.
575
- *
576
511
  * @param type One of 'b' (boolean), 's' (string) or 'n' (number).
577
512
  * @param index The index of this argument into the argument id and argument
578
513
  * display name arrays.
@@ -586,69 +521,61 @@ function populateArgumentOnDeclaration_(
586
521
  index: number,
587
522
  connectionMap: ConnectionMap,
588
523
  id: string,
589
- input: Blockly.Input
524
+ input: Blockly.Input,
590
525
  ) {
591
- let oldBlock: Blockly.BlockSvg | null = null;
526
+ let oldBlock: Blockly.BlockSvg | null = null
592
527
  if (connectionMap && id in connectionMap) {
593
- const saveInfo = connectionMap[id];
594
- oldBlock = saveInfo?.["block"] ?? null;
528
+ const saveInfo = connectionMap[id]
529
+ oldBlock = saveInfo?.block ?? null
595
530
  }
596
531
 
597
532
  // TODO: This always returns false, because it checks for argument reporter
598
533
  // blocks instead of argument editor blocks. Create a new version for argument
599
534
  // editors.
600
- const oldTypeMatches = checkOldTypeMatches_(oldBlock, type);
601
- const displayName = this.displayNames_[index];
535
+ const oldTypeMatches = checkOldTypeMatches_(oldBlock, type)
536
+ const displayName = this.displayNames_[index]
602
537
 
603
538
  // Decide which block to attach.
604
- let argumentEditor: Blockly.BlockSvg;
539
+ let argumentEditor: Blockly.BlockSvg
605
540
  if (oldBlock && oldTypeMatches) {
606
- argumentEditor = oldBlock;
607
- oldBlock.setFieldValue(displayName, "TEXT");
608
- connectionMap[input.name] = null;
541
+ argumentEditor = oldBlock
542
+ oldBlock.setFieldValue(displayName, 'TEXT')
543
+ connectionMap[input.name] = null
609
544
  } else {
610
- argumentEditor = this.createArgumentEditor_(type, displayName);
545
+ argumentEditor = this.createArgumentEditor_(type, displayName)
611
546
  }
612
547
 
613
548
  // Attach the block.
614
- input.connection!.connect(argumentEditor.outputConnection!);
549
+ input.connection!.connect(argumentEditor.outputConnection)
615
550
  }
616
551
 
617
552
  /**
618
553
  * Check whether the type of the old block corresponds to the given argument
619
554
  * type.
620
- *
621
555
  * @param oldBlock The old block to check.
622
556
  * @param type The argument type. One of 'n', 'n', or 's'.
623
557
  * @returns True if the type matches, false otherwise.
624
558
  */
625
- function checkOldTypeMatches_(
626
- oldBlock: Blockly.BlockSvg | null,
627
- type: string
628
- ): boolean {
559
+ function checkOldTypeMatches_(oldBlock: Blockly.BlockSvg | null, type: string): boolean {
629
560
  if (!oldBlock) {
630
- return false;
561
+ return false
631
562
  }
632
563
  if (
633
564
  (type === ArgumentType.NUMBER || type === ArgumentType.STRING) &&
634
- oldBlock.type === "argument_reporter_string_number"
565
+ oldBlock.type === 'argument_reporter_string_number'
635
566
  ) {
636
- return true;
567
+ return true
637
568
  }
638
- if (
639
- type === ArgumentType.BOOLEAN &&
640
- oldBlock.type === "argument_reporter_boolean"
641
- ) {
642
- return true;
569
+ if (type === ArgumentType.BOOLEAN && oldBlock.type === 'argument_reporter_boolean') {
570
+ return true
643
571
  }
644
- return false;
572
+ return false
645
573
  }
646
574
 
647
575
  /**
648
576
  * Create an argument editor.
649
577
  * An argument editor is a shadow block with a single text field, which is used
650
578
  * to set the display name of the argument.
651
- *
652
579
  * @param argumentType One of 'b' (boolean), 's' (string) or 'n' (number).
653
580
  * @param displayName The display name of this argument, which is the text of
654
581
  * the field on the shadow block.
@@ -657,34 +584,29 @@ function checkOldTypeMatches_(
657
584
  function createArgumentEditor_(
658
585
  this: ProcedureDeclarationBlock,
659
586
  argumentType: ArgumentType,
660
- displayName: string
587
+ displayName: string,
661
588
  ): Blockly.BlockSvg {
662
- Blockly.Events.disable();
663
- let newBlock;
589
+ Blockly.Events.disable()
590
+ let newBlock
664
591
  try {
665
- if (
666
- argumentType === ArgumentType.NUMBER ||
667
- argumentType === ArgumentType.STRING
668
- ) {
669
- newBlock = this.workspace.newBlock("argument_editor_string_number");
592
+ if (argumentType === ArgumentType.NUMBER || argumentType === ArgumentType.STRING) {
593
+ newBlock = this.workspace.newBlock('argument_editor_string_number')
670
594
  } else {
671
- newBlock = this.workspace.newBlock("argument_editor_boolean");
595
+ newBlock = this.workspace.newBlock('argument_editor_boolean')
672
596
  }
673
- newBlock.setFieldValue(displayName, "TEXT");
674
- newBlock.setShadow(true);
597
+ newBlock.setFieldValue(displayName, 'TEXT')
598
+ newBlock.setShadow(true)
675
599
  if (!this.isInsertionMarker()) {
676
- newBlock.initSvg();
677
- newBlock.queueRender();
600
+ newBlock.initSvg()
601
+ newBlock.queueRender()
678
602
  }
679
603
  } finally {
680
- Blockly.Events.enable();
604
+ Blockly.Events.enable()
681
605
  }
682
606
  if (Blockly.Events.isEnabled()) {
683
- Blockly.Events.fire(
684
- new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock)
685
- );
607
+ Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.BLOCK_CREATE))(newBlock))
686
608
  }
687
- return newBlock;
609
+ return newBlock
688
610
  }
689
611
 
690
612
  /**
@@ -692,30 +614,28 @@ function createArgumentEditor_(
692
614
  * and their text.
693
615
  */
694
616
  function updateDeclarationProcCode_(this: ProcedureDeclarationBlock) {
695
- this.procCode_ = "";
696
- this.displayNames_ = [];
697
- this.argumentIds_ = [];
617
+ this.procCode_ = ''
618
+ this.displayNames_ = []
619
+ this.argumentIds_ = []
698
620
  for (let i = 0; i < this.inputList.length; i++) {
699
621
  if (i !== 0) {
700
- this.procCode_ += " ";
622
+ this.procCode_ += ' '
701
623
  }
702
- const input = this.inputList[i];
624
+ const input = this.inputList[i]
703
625
  if (input.type === Blockly.inputs.inputTypes.DUMMY) {
704
- this.procCode_ += input.fieldRow[0].getValue();
626
+ this.procCode_ += input.fieldRow[0].getValue()
705
627
  } else if (input.type === Blockly.inputs.inputTypes.VALUE) {
706
628
  // Inspect the argument editor.
707
- const target = input.connection!.targetBlock()!;
708
- this.displayNames_.push(target.getFieldValue("TEXT"));
709
- this.argumentIds_.push(input.name);
710
- if (target.type === "argument_editor_boolean") {
711
- this.procCode_ += "%b";
629
+ const target = input.connection!.targetBlock()!
630
+ this.displayNames_.push(target.getFieldValue('TEXT'))
631
+ this.argumentIds_.push(input.name)
632
+ if (target.type === 'argument_editor_boolean') {
633
+ this.procCode_ += '%b'
712
634
  } else {
713
- this.procCode_ += "%s";
635
+ this.procCode_ += '%s'
714
636
  }
715
637
  } else {
716
- throw new Error(
717
- "Unexpected input type on a procedure mutator root: " + input.type
718
- );
638
+ throw new Error('Unexpected input type on a procedure mutator root: ' + input.type)
719
639
  }
720
640
  }
721
641
  }
@@ -725,13 +645,13 @@ function updateDeclarationProcCode_(this: ProcedureDeclarationBlock) {
725
645
  */
726
646
  function focusLastEditor_(this: ProcedureDeclarationBlock) {
727
647
  if (this.inputList.length > 0) {
728
- const newInput = this.inputList[this.inputList.length - 1];
648
+ const newInput = this.inputList[this.inputList.length - 1]
729
649
  if (newInput.type === Blockly.inputs.inputTypes.DUMMY) {
730
- newInput.fieldRow[0].showEditor();
650
+ newInput.fieldRow[0].showEditor()
731
651
  } else if (newInput.type === Blockly.inputs.inputTypes.VALUE) {
732
652
  // Inspect the argument editor.
733
- const target = newInput.connection!.targetBlock()!;
734
- target.getField("TEXT")!.showEditor();
653
+ const target = newInput.connection!.targetBlock()!
654
+ target.getField('TEXT')!.showEditor()
735
655
  }
736
656
  }
737
657
  }
@@ -740,10 +660,10 @@ function focusLastEditor_(this: ProcedureDeclarationBlock) {
740
660
  * Externally-visible function to add a label to the procedure declaration.
741
661
  */
742
662
  function addLabelExternal(this: ProcedureDeclarationBlock) {
743
- Blockly.WidgetDiv.hide();
744
- this.procCode_ = this.procCode_ + " label text";
745
- this.updateDisplay_();
746
- this.focusLastEditor_();
663
+ Blockly.WidgetDiv.hide()
664
+ this.procCode_ = this.procCode_ + ' label text'
665
+ this.updateDisplay_()
666
+ this.focusLastEditor_()
747
667
  }
748
668
 
749
669
  /**
@@ -751,13 +671,13 @@ function addLabelExternal(this: ProcedureDeclarationBlock) {
751
671
  * declaration.
752
672
  */
753
673
  function addBooleanExternal(this: ProcedureDeclarationBlock) {
754
- Blockly.WidgetDiv.hide();
755
- this.procCode_ = this.procCode_ + " %b";
756
- this.displayNames_.push("boolean");
757
- this.argumentIds_.push(Blockly.utils.idGenerator.genUid());
758
- this.argumentDefaults_.push("false");
759
- this.updateDisplay_();
760
- this.focusLastEditor_();
674
+ Blockly.WidgetDiv.hide()
675
+ this.procCode_ = this.procCode_ + ' %b'
676
+ this.displayNames_.push('boolean')
677
+ this.argumentIds_.push(Blockly.utils.idGenerator.genUid())
678
+ this.argumentDefaults_.push('false')
679
+ this.updateDisplay_()
680
+ this.focusLastEditor_()
761
681
  }
762
682
 
763
683
  /**
@@ -765,82 +685,75 @@ function addBooleanExternal(this: ProcedureDeclarationBlock) {
765
685
  * declaration.
766
686
  */
767
687
  function addStringNumberExternal(this: ProcedureDeclarationBlock) {
768
- Blockly.WidgetDiv.hide();
769
- this.procCode_ = this.procCode_ + " %s";
770
- this.displayNames_.push("number or text");
771
- this.argumentIds_.push(Blockly.utils.idGenerator.genUid());
772
- this.argumentDefaults_.push("");
773
- this.updateDisplay_();
774
- this.focusLastEditor_();
688
+ Blockly.WidgetDiv.hide()
689
+ this.procCode_ = this.procCode_ + ' %s'
690
+ this.displayNames_.push('number or text')
691
+ this.argumentIds_.push(Blockly.utils.idGenerator.genUid())
692
+ this.argumentDefaults_.push('')
693
+ this.updateDisplay_()
694
+ this.focusLastEditor_()
775
695
  }
776
696
 
777
697
  /**
778
698
  * Externally-visible function to get the warp on procedure declaration.
779
- *
780
699
  * @returns The value of the warp_ property.
781
700
  */
782
701
  function getWarp(this: ProcedureDeclarationBlock): boolean {
783
- return this.warp_;
702
+ return this.warp_
784
703
  }
785
704
 
786
705
  /**
787
706
  * Externally-visible function to set the warp on procedure declaration.
788
- *
789
707
  * @param warp The value of the warp_ property.
790
708
  */
791
709
  function setWarp(this: ProcedureDeclarationBlock, warp: boolean) {
792
- this.warp_ = warp;
710
+ this.warp_ = warp
793
711
  }
794
712
 
795
713
  /**
796
714
  * Callback to remove a field, only for the declaration block.
797
- *
798
715
  * @param field The field being removed.
799
716
  */
800
- function removeFieldCallback(
801
- this: ProcedureDeclarationBlock,
802
- field: Blockly.Field
803
- ) {
717
+ function removeFieldCallback(this: ProcedureDeclarationBlock, field: Blockly.Field) {
804
718
  // Do not delete if there is only one input
805
719
  if (this.inputList.length === 1) {
806
- return;
720
+ return
807
721
  }
808
- var inputNameToRemove = null;
809
- for (var n = 0; n < this.inputList.length; n++) {
810
- var input = this.inputList[n];
722
+ let inputNameToRemove = null
723
+ for (let n = 0; n < this.inputList.length; n++) {
724
+ const input = this.inputList[n]
811
725
  if (input.connection) {
812
- var target = input.connection!.targetBlock()!;
726
+ const target = input.connection.targetBlock()!
813
727
  if (field.name && target.getField(field.name) === field) {
814
- inputNameToRemove = input.name;
728
+ inputNameToRemove = input.name
815
729
  }
816
730
  } else {
817
- for (var j = 0; j < input.fieldRow.length; j++) {
731
+ for (let j = 0; j < input.fieldRow.length; j++) {
818
732
  if (input.fieldRow[j] === field) {
819
- inputNameToRemove = input.name;
733
+ inputNameToRemove = input.name
820
734
  }
821
735
  }
822
736
  }
823
737
  }
824
738
  if (inputNameToRemove) {
825
- Blockly.WidgetDiv.hide();
826
- this.removeInput(inputNameToRemove);
827
- this.onChangeFn();
828
- this.updateDisplay_();
739
+ Blockly.WidgetDiv.hide()
740
+ this.removeInput(inputNameToRemove)
741
+ this.onChangeFn()
742
+ this.updateDisplay_()
829
743
  }
830
744
  }
831
745
 
832
746
  /**
833
747
  * Callback to pass removeField up to the declaration block from arguments.
834
- *
835
748
  * @param field The field being removed.
836
749
  */
837
750
  function removeArgumentCallback_(
838
751
  this: ProcedureDeclarationBlock | ProcedureArgumentEditorBlock,
839
- field: Blockly.Field
752
+ field: Blockly.Field,
840
753
  ) {
841
- const parent = this.getParent();
754
+ const parent = this.getParent()
842
755
  if (parent && parent.removeFieldCallback) {
843
- parent.removeFieldCallback(field);
756
+ parent.removeFieldCallback(field)
844
757
  }
845
758
  }
846
759
 
@@ -853,46 +766,42 @@ function removeArgumentCallback_(
853
766
  * Until there is a more explicit way of identifying argument reporter blocks using ids,
854
767
  * be conservative and only update argument reporters that are used in the
855
768
  * stack below the prototype, ie the definition.
856
- *
857
769
  * @param prevArgIds The previous ordering of argument ids.
858
770
  * @param prevDisplayNames The previous argument names.
859
771
  */
860
772
  function updateArgumentReporterNames_(
861
773
  this: ProcedurePrototypeBlock,
862
774
  prevArgIds: string[],
863
- prevDisplayNames: string[]
775
+ prevDisplayNames: string[],
864
776
  ) {
865
- const nameChanges: { newName: string; blocks: Blockly.BlockSvg[] }[] = [];
866
- const argReporters: Blockly.BlockSvg[] = [];
867
- const definitionBlock = this.getParent();
868
- if (!definitionBlock) return;
777
+ const nameChanges: { newName: string; blocks: Blockly.BlockSvg[] }[] = []
778
+ const argReporters: Blockly.BlockSvg[] = []
779
+ const definitionBlock = this.getParent()
780
+ if (!definitionBlock) return
869
781
 
870
782
  // Create a list of argument reporters that are descendants of the definition stack (see above comment)
871
783
  definitionBlock.getDescendants(false).forEach((block: Blockly.BlockSvg) => {
872
784
  if (
873
- (block.type === "argument_reporter_string_number" ||
874
- block.type === "argument_reporter_boolean") &&
785
+ (block.type === 'argument_reporter_string_number' || block.type === 'argument_reporter_boolean') &&
875
786
  !block.isShadow()
876
787
  ) {
877
788
  // Exclude arg reporters in the prototype block, which are shadows.
878
- argReporters.push(block);
789
+ argReporters.push(block)
879
790
  }
880
- });
791
+ })
881
792
 
882
793
  // Create a list of "name changes", including the new name and blocks matching the old name
883
794
  // Only search over the current set of argument ids, ignore args that have been removed
884
795
  for (let i = 0, id; (id = this.argumentIds_[i]); i++) {
885
796
  // Find the previous index of this argument id. Could be -1 if it is newly added.
886
- const prevIndex = prevArgIds.indexOf(id);
887
- if (prevIndex === -1) continue; // Newly added argument, no corresponding previous argument to update.
888
- const prevName = prevDisplayNames[prevIndex];
797
+ const prevIndex = prevArgIds.indexOf(id)
798
+ if (prevIndex === -1) continue // Newly added argument, no corresponding previous argument to update.
799
+ const prevName = prevDisplayNames[prevIndex]
889
800
  if (prevName !== this.displayNames_[i]) {
890
801
  nameChanges.push({
891
802
  newName: this.displayNames_[i],
892
- blocks: argReporters.filter((block) => {
893
- return block.getFieldValue("VALUE") === prevName;
894
- }),
895
- });
803
+ blocks: argReporters.filter(block => block.getFieldValue('VALUE') === prevName),
804
+ })
896
805
  }
897
806
  }
898
807
 
@@ -900,12 +809,12 @@ function updateArgumentReporterNames_(
900
809
  // Do this after creating the lists to avoid cycles of renaming.
901
810
  for (const nameChange of nameChanges) {
902
811
  for (const block of nameChange.blocks) {
903
- block.setFieldValue(nameChange.newName, "VALUE");
812
+ block.setFieldValue(nameChange.newName, 'VALUE')
904
813
  }
905
814
  }
906
815
  }
907
816
 
908
- Blockly.Blocks["procedures_definition"] = {
817
+ Blockly.Blocks.procedures_definition = {
909
818
  /**
910
819
  * Block for defining a procedure with no return value.
911
820
  */
@@ -914,263 +823,246 @@ Blockly.Blocks["procedures_definition"] = {
914
823
  message0: Blockly.Msg.PROCEDURES_DEFINITION,
915
824
  args0: [
916
825
  {
917
- type: "input_statement",
918
- name: "custom_block",
826
+ type: 'input_statement',
827
+ name: 'custom_block',
919
828
  },
920
829
  ],
921
- extensions: [
922
- "colours_more",
923
- "shape_bowler_hat",
924
- "procedure_def_contextmenu",
925
- ],
926
- });
830
+ extensions: ['colours_more', 'shape_bowler_hat', 'procedure_def_contextmenu'],
831
+ })
927
832
  },
928
- };
833
+ }
929
834
 
930
- Blockly.Blocks["procedures_call"] = {
835
+ Blockly.Blocks.procedures_call = {
931
836
  /**
932
837
  * Block for calling a procedure with no return value.
933
838
  */
934
839
  init: function (this: ProcedureCallBlock) {
935
840
  this.jsonInit({
936
- extensions: [
937
- "colours_more",
938
- "shape_statement",
939
- "procedure_call_contextmenu",
940
- ],
941
- });
942
- this.procCode_ = "";
943
- this.argumentIds_ = [];
944
- this.warp_ = false;
841
+ extensions: ['colours_more', 'shape_statement', 'procedure_call_contextmenu'],
842
+ })
843
+ this.procCode_ = ''
844
+ this.argumentIds_ = []
845
+ this.warp_ = false
945
846
 
946
847
  // Shared.
947
- this.getProcCode = getProcCode.bind(this);
948
- this.removeAllInputs_ = removeAllInputs_.bind(this);
949
- this.disconnectOldBlocks_ = disconnectOldBlocks_.bind(this);
950
- this.deleteShadows_ = deleteShadows_.bind(this);
951
- this.createAllInputs_ = createAllInputs_.bind(this);
952
- this.updateDisplay_ = updateDisplay_.bind(this);
848
+ this.getProcCode = getProcCode.bind(this)
849
+ this.removeAllInputs_ = removeAllInputs_.bind(this)
850
+ this.disconnectOldBlocks_ = disconnectOldBlocks_.bind(this)
851
+ this.deleteShadows_ = deleteShadows_.bind(this)
852
+ this.createAllInputs_ = createAllInputs_.bind(this)
853
+ this.updateDisplay_ = updateDisplay_.bind(this)
953
854
 
954
855
  // Exist on all three blocks, but have different implementations.
955
- this.mutationToDom = callerMutationToDom.bind(this);
956
- this.domToMutation = callerDomToMutation.bind(this);
957
- this.populateArgument_ = populateArgumentOnCaller_.bind(this);
958
- this.addProcedureLabel_ = addLabelField_.bind(this);
856
+ this.mutationToDom = callerMutationToDom.bind(this)
857
+ this.domToMutation = callerDomToMutation.bind(this)
858
+ this.populateArgument_ = populateArgumentOnCaller_.bind(this)
859
+ this.addProcedureLabel_ = addLabelField_.bind(this)
959
860
 
960
861
  // Only exists on the external caller.
961
- this.attachShadow_ = attachShadow_.bind(this);
962
- this.buildShadowDom_ = buildShadowDom_.bind(this);
862
+ this.attachShadow_ = attachShadow_.bind(this)
863
+ this.buildShadowDom_ = buildShadowDom_.bind(this)
963
864
  },
964
- };
865
+ }
965
866
 
966
- Blockly.Blocks["procedures_prototype"] = {
867
+ Blockly.Blocks.procedures_prototype = {
967
868
  /**
968
869
  * Block for calling a procedure with no return value, for rendering inside
969
870
  * define block.
970
871
  */
971
872
  init: function (this: ProcedurePrototypeBlock) {
972
873
  this.jsonInit({
973
- extensions: ["colours_more", "shape_statement"],
974
- });
874
+ extensions: ['colours_more', 'shape_statement'],
875
+ })
975
876
 
976
877
  /* Data known about the procedure. */
977
- this.procCode_ = "";
978
- this.displayNames_ = [];
979
- this.argumentIds_ = [];
980
- this.argumentDefaults_ = [];
981
- this.warp_ = false;
878
+ this.procCode_ = ''
879
+ this.displayNames_ = []
880
+ this.argumentIds_ = []
881
+ this.argumentDefaults_ = []
882
+ this.warp_ = false
982
883
 
983
884
  // Shared.
984
- this.getProcCode = getProcCode.bind(this);
985
- this.removeAllInputs_ = removeAllInputs_.bind(this);
986
- this.disconnectOldBlocks_ = disconnectOldBlocks_.bind(this);
987
- this.deleteShadows_ = deleteShadows_.bind(this);
988
- this.createAllInputs_ = createAllInputs_.bind(this);
989
- this.updateDisplay_ = updateDisplay_.bind(this);
885
+ this.getProcCode = getProcCode.bind(this)
886
+ this.removeAllInputs_ = removeAllInputs_.bind(this)
887
+ this.disconnectOldBlocks_ = disconnectOldBlocks_.bind(this)
888
+ this.deleteShadows_ = deleteShadows_.bind(this)
889
+ this.createAllInputs_ = createAllInputs_.bind(this)
890
+ this.updateDisplay_ = updateDisplay_.bind(this)
990
891
  // Exist on all three blocks, but have different implementations.
991
- this.mutationToDom = definitionMutationToDom.bind(this);
992
- this.domToMutation = definitionDomToMutation.bind(this);
993
- this.populateArgument_ = populateArgumentOnPrototype_.bind(this);
994
- this.addProcedureLabel_ = addLabelField_.bind(this);
892
+ this.mutationToDom = definitionMutationToDom.bind(this)
893
+ this.domToMutation = definitionDomToMutation.bind(this)
894
+ this.populateArgument_ = populateArgumentOnPrototype_.bind(this)
895
+ this.addProcedureLabel_ = addLabelField_.bind(this)
995
896
 
996
897
  // Only exists on procedures_prototype.
997
- this.createArgumentReporter_ = createArgumentReporter_.bind(this);
998
- this.updateArgumentReporterNames_ = updateArgumentReporterNames_.bind(this);
898
+ this.createArgumentReporter_ = createArgumentReporter_.bind(this)
899
+ this.updateArgumentReporterNames_ = updateArgumentReporterNames_.bind(this)
999
900
  },
1000
- };
901
+ }
1001
902
 
1002
- Blockly.Blocks["procedures_declaration"] = {
903
+ Blockly.Blocks.procedures_declaration = {
1003
904
  /**
1004
905
  * The root block in the procedure declaration editor.
1005
906
  */
1006
907
  init: function (this: ProcedureDeclarationBlock) {
1007
908
  this.jsonInit({
1008
- extensions: ["colours_more", "shape_statement"],
1009
- });
909
+ extensions: ['colours_more', 'shape_statement'],
910
+ })
1010
911
  /* Data known about the procedure. */
1011
- this.procCode_ = "";
1012
- this.displayNames_ = [];
1013
- this.argumentIds_ = [];
1014
- this.argumentDefaults_ = [];
1015
- this.warp_ = false;
912
+ this.procCode_ = ''
913
+ this.displayNames_ = []
914
+ this.argumentIds_ = []
915
+ this.argumentDefaults_ = []
916
+ this.warp_ = false
1016
917
 
1017
918
  // Shared.
1018
- this.getProcCode = getProcCode.bind(this);
1019
- this.removeAllInputs_ = removeAllInputs_.bind(this);
1020
- this.disconnectOldBlocks_ = disconnectOldBlocks_.bind(this);
1021
- this.deleteShadows_ = deleteShadows_.bind(this);
1022
- this.createAllInputs_ = createAllInputs_.bind(this);
1023
- this.updateDisplay_ = updateDisplay_.bind(this);
919
+ this.getProcCode = getProcCode.bind(this)
920
+ this.removeAllInputs_ = removeAllInputs_.bind(this)
921
+ this.disconnectOldBlocks_ = disconnectOldBlocks_.bind(this)
922
+ this.deleteShadows_ = deleteShadows_.bind(this)
923
+ this.createAllInputs_ = createAllInputs_.bind(this)
924
+ this.updateDisplay_ = updateDisplay_.bind(this)
1024
925
 
1025
926
  // Exist on all three blocks, but have different implementations.
1026
- this.mutationToDom = definitionMutationToDom.bind(this);
1027
- this.domToMutation = definitionDomToMutation.bind(this);
1028
- this.populateArgument_ = populateArgumentOnDeclaration_.bind(this);
1029
- this.addProcedureLabel_ = addLabelEditor_.bind(this);
927
+ this.mutationToDom = definitionMutationToDom.bind(this)
928
+ this.domToMutation = definitionDomToMutation.bind(this)
929
+ this.populateArgument_ = populateArgumentOnDeclaration_.bind(this)
930
+ this.addProcedureLabel_ = addLabelEditor_.bind(this)
1030
931
 
1031
932
  // Exist on declaration and arguments editors, with different implementations.
1032
- this.removeFieldCallback = removeFieldCallback.bind(this);
933
+ this.removeFieldCallback = removeFieldCallback.bind(this)
1033
934
 
1034
935
  // Only exist on procedures_declaration.
1035
- this.createArgumentEditor_ = createArgumentEditor_.bind(this);
1036
- this.focusLastEditor_ = focusLastEditor_.bind(this);
1037
- this.getWarp = getWarp.bind(this);
1038
- this.setWarp = setWarp.bind(this);
1039
- this.addLabelExternal = addLabelExternal.bind(this);
1040
- this.addBooleanExternal = addBooleanExternal.bind(this);
1041
- this.addStringNumberExternal = addStringNumberExternal.bind(this);
1042
- this.onChangeFn = updateDeclarationProcCode_.bind(this);
936
+ this.createArgumentEditor_ = createArgumentEditor_.bind(this)
937
+ this.focusLastEditor_ = focusLastEditor_.bind(this)
938
+ this.getWarp = getWarp.bind(this)
939
+ this.setWarp = setWarp.bind(this)
940
+ this.addLabelExternal = addLabelExternal.bind(this)
941
+ this.addBooleanExternal = addBooleanExternal.bind(this)
942
+ this.addStringNumberExternal = addStringNumberExternal.bind(this)
943
+ this.onChangeFn = updateDeclarationProcCode_.bind(this)
1043
944
  },
1044
- };
945
+ }
1045
946
 
1046
- Blockly.Blocks["argument_reporter_boolean"] = {
947
+ Blockly.Blocks.argument_reporter_boolean = {
1047
948
  init: function (this: Blockly.BlockSvg) {
1048
949
  this.jsonInit({
1049
- message0: " %1",
950
+ message0: ' %1',
1050
951
  args0: [
1051
952
  {
1052
- type: "field_label_serializable",
1053
- name: "VALUE",
1054
- text: "",
953
+ type: 'field_label_serializable',
954
+ name: 'VALUE',
955
+ text: '',
1055
956
  },
1056
957
  ],
1057
- extensions: ["colours_more", "output_boolean"],
1058
- });
1059
- this.setDragStrategy(new DuplicateOnDragDraggable(this));
958
+ extensions: ['colours_more', 'output_boolean'],
959
+ })
960
+ this.setDragStrategy(new DuplicateOnDragDraggable(this))
1060
961
  },
1061
- };
962
+ }
1062
963
 
1063
- Blockly.Blocks["argument_reporter_string_number"] = {
964
+ Blockly.Blocks.argument_reporter_string_number = {
1064
965
  init: function (this: Blockly.BlockSvg) {
1065
966
  this.jsonInit({
1066
- message0: " %1",
967
+ message0: ' %1',
1067
968
  args0: [
1068
969
  {
1069
- type: "field_label_serializable",
1070
- name: "VALUE",
1071
- text: "",
970
+ type: 'field_label_serializable',
971
+ name: 'VALUE',
972
+ text: '',
1072
973
  },
1073
974
  ],
1074
- extensions: ["colours_more", "output_number", "output_string"],
1075
- });
1076
- this.setDragStrategy(new DuplicateOnDragDraggable(this));
975
+ extensions: ['colours_more', 'output_number', 'output_string'],
976
+ })
977
+ this.setDragStrategy(new DuplicateOnDragDraggable(this))
1077
978
  },
1078
- };
979
+ }
1079
980
 
1080
- Blockly.Blocks["argument_editor_boolean"] = {
981
+ Blockly.Blocks.argument_editor_boolean = {
1081
982
  init: function (this: ProcedureArgumentEditorBlock) {
1082
983
  this.jsonInit({
1083
- message0: " %1",
984
+ message0: ' %1',
1084
985
  args0: [
1085
986
  {
1086
- type: "field_input_removable",
1087
- name: "TEXT",
1088
- text: "foo",
987
+ type: 'field_input_removable',
988
+ name: 'TEXT',
989
+ text: 'foo',
1089
990
  },
1090
991
  ],
1091
- extensions: ["colours_textfield", "output_boolean"],
1092
- });
992
+ extensions: ['colours_textfield', 'output_boolean'],
993
+ })
1093
994
 
1094
995
  // Exist on declaration and arguments editors, with different implementations.
1095
- this.removeFieldCallback = removeArgumentCallback_.bind(this);
996
+ this.removeFieldCallback = removeArgumentCallback_.bind(this)
1096
997
  },
1097
- };
998
+ }
1098
999
 
1099
- Blockly.Blocks["argument_editor_string_number"] = {
1000
+ Blockly.Blocks.argument_editor_string_number = {
1100
1001
  init: function (this: ProcedureArgumentEditorBlock) {
1101
1002
  this.jsonInit({
1102
- message0: " %1",
1003
+ message0: ' %1',
1103
1004
  args0: [
1104
1005
  {
1105
- type: "field_input_removable",
1106
- name: "TEXT",
1107
- text: "foo",
1006
+ type: 'field_input_removable',
1007
+ name: 'TEXT',
1008
+ text: 'foo',
1108
1009
  },
1109
1010
  ],
1110
- extensions: ["colours_textfield", "output_number", "output_string"],
1111
- });
1011
+ extensions: ['colours_textfield', 'output_number', 'output_string'],
1012
+ })
1112
1013
 
1113
1014
  // Exist on declaration and arguments editors, with different implementations.
1114
- this.removeFieldCallback = removeArgumentCallback_.bind(this);
1015
+ this.removeFieldCallback = removeArgumentCallback_.bind(this)
1115
1016
  },
1116
- };
1017
+ }
1117
1018
 
1118
1019
  interface ProcedureBlock extends Blockly.BlockSvg {
1119
- procCode_: string;
1120
- argumentIds_: string[];
1121
- warp_: boolean;
1122
- getProcCode: () => string;
1123
- removeAllInputs_: () => void;
1124
- disconnectOldBlocks_: () => ConnectionMap;
1125
- deleteShadows_: (connectionMap: ConnectionMap) => void;
1126
- createAllInputs_: (connectionMap: ConnectionMap) => void;
1127
- updateDisplay_: () => void;
1020
+ procCode_: string
1021
+ argumentIds_: string[]
1022
+ warp_: boolean
1023
+ getProcCode: () => string
1024
+ removeAllInputs_: () => void
1025
+ disconnectOldBlocks_: () => ConnectionMap
1026
+ deleteShadows_: (connectionMap: ConnectionMap) => void
1027
+ createAllInputs_: (connectionMap: ConnectionMap) => void
1028
+ updateDisplay_: () => void
1128
1029
  populateArgument_: (
1129
1030
  type: ArgumentType,
1130
1031
  index: number,
1131
1032
  connectionMap: ConnectionMap,
1132
1033
  id: string,
1133
- input: Blockly.Input
1134
- ) => void;
1135
- addProcedureLabel_: (text: string) => void;
1034
+ input: Blockly.Input,
1035
+ ) => void
1036
+ addProcedureLabel_: (text: string) => void
1136
1037
  }
1137
1038
 
1138
1039
  export interface ProcedureDeclarationBlock extends ProcedureBlock {
1139
- displayNames_: string[];
1140
- argumentDefaults_: string[];
1141
- removeFieldCallback: (field: Blockly.Field) => void;
1142
- createArgumentEditor_: (
1143
- argumentType: ArgumentType,
1144
- displayName: string
1145
- ) => Blockly.BlockSvg;
1146
- focusLastEditor_: () => void;
1147
- getWarp: () => boolean;
1148
- setWarp: (warp: boolean) => void;
1149
- addLabelExternal: () => void;
1150
- addBooleanExternal: () => void;
1151
- addStringNumberExternal: () => void;
1152
- onChangeFn: () => void;
1040
+ displayNames_: string[]
1041
+ argumentDefaults_: string[]
1042
+ removeFieldCallback: (field: Blockly.Field) => void
1043
+ createArgumentEditor_: (argumentType: ArgumentType, displayName: string) => Blockly.BlockSvg
1044
+ focusLastEditor_: () => void
1045
+ getWarp: () => boolean
1046
+ setWarp: (warp: boolean) => void
1047
+ addLabelExternal: () => void
1048
+ addBooleanExternal: () => void
1049
+ addStringNumberExternal: () => void
1050
+ onChangeFn: () => void
1153
1051
  }
1154
1052
 
1155
1053
  interface ProcedureCallBlock extends ProcedureBlock {
1156
- generateShadows_: boolean;
1157
- attachShadow_: (input: Blockly.Input, argumentType: ArgumentType) => void;
1158
- buildShadowDom_: (type: ArgumentType) => Element;
1054
+ generateShadows_: boolean
1055
+ attachShadow_: (input: Blockly.Input, argumentType: ArgumentType) => void
1056
+ buildShadowDom_: (type: ArgumentType) => Element
1159
1057
  }
1160
1058
 
1161
1059
  interface ProcedurePrototypeBlock extends ProcedureBlock {
1162
- displayNames_: string[];
1163
- argumentDefaults_: string[];
1164
- createArgumentReporter_: (
1165
- argumentType: ArgumentType,
1166
- displayName: string
1167
- ) => Blockly.BlockSvg;
1168
- updateArgumentReporterNames_: (
1169
- prevArgIds: string[],
1170
- prevDisplayNames: string[]
1171
- ) => void;
1060
+ displayNames_: string[]
1061
+ argumentDefaults_: string[]
1062
+ createArgumentReporter_: (argumentType: ArgumentType, displayName: string) => Blockly.BlockSvg
1063
+ updateArgumentReporterNames_: (prevArgIds: string[], prevDisplayNames: string[]) => void
1172
1064
  }
1173
1065
 
1174
1066
  interface ProcedureArgumentEditorBlock extends Blockly.BlockSvg {
1175
- removeFieldCallback: (field: Blockly.Field) => void;
1067
+ removeFieldCallback: (field: Blockly.Field) => void
1176
1068
  }