scratch-blocks 2.0.1 → 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 (276) hide show
  1. package/AGENTS.md +140 -0
  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 +6 -9
  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 -31
  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 +5 -8
  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 -51
  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 +4 -5
  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 +7 -8
  110. package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
  111. package/dist/types/src/renderer/constants.d.ts +41 -0
  112. package/dist/types/src/renderer/constants.d.ts.map +1 -0
  113. package/dist/types/src/renderer/drawer.d.ts +7 -6
  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 +9 -16
  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 +3 -6
  126. package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
  127. package/dist/types/src/scratch_comment_icon.d.ts +3 -4
  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 +2 -11
  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 +2 -3
  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 +3 -3
  157. package/dist/types/tests/jsunit/connection_db_test.d.ts.map +1 -1
  158. package/dist/types/tests/jsunit/connection_test.d.ts.map +1 -1
  159. package/dist/types/tests/jsunit/event_test.d.ts.map +1 -1
  160. package/dist/types/tests/jsunit/extensions_test.d.ts.map +1 -1
  161. package/dist/types/tests/jsunit/field_number_test.d.ts.map +1 -1
  162. package/dist/types/tests/jsunit/field_test.d.ts.map +1 -1
  163. package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +1 -1
  164. package/dist/types/tests/jsunit/field_variable_test.d.ts.map +1 -1
  165. package/dist/types/tests/jsunit/gesture_test.d.ts.map +1 -1
  166. package/dist/types/tests/jsunit/input_test.d.ts +1 -0
  167. package/dist/types/tests/jsunit/input_test.d.ts.map +1 -1
  168. package/dist/types/tests/jsunit/json_test.d.ts.map +1 -1
  169. package/dist/types/tests/jsunit/names_test.d.ts.map +1 -1
  170. package/dist/types/tests/jsunit/procedure_test.d.ts.map +1 -1
  171. package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +1 -1
  172. package/dist/types/tests/jsunit/svg_test.d.ts.map +1 -1
  173. package/dist/types/tests/jsunit/test_utilities.d.ts.map +1 -1
  174. package/dist/types/tests/jsunit/utils_test.d.ts.map +1 -1
  175. package/dist/types/tests/jsunit/variable_map_test.d.ts.map +1 -1
  176. package/dist/types/tests/jsunit/variable_model_test.d.ts.map +1 -1
  177. package/dist/types/tests/jsunit/widget_div_test.d.ts.map +1 -1
  178. package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +1 -1
  179. package/dist/types/tests/jsunit/workspace_test.d.ts.map +1 -1
  180. package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +1 -1
  181. package/dist/types/tests/jsunit/xml_test.d.ts.map +1 -1
  182. package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +1 -1
  183. package/eslint.config.mjs +69 -0
  184. package/i18n/create_scratch_msgs.js +44 -45
  185. package/i18n/js_to_json.js +40 -32
  186. package/i18n/json_to_js.js +37 -37
  187. package/i18n/sync_tx_translations.js +64 -65
  188. package/i18n/test_scratch_msgs.js +66 -63
  189. package/msg/js/en.js +289 -287
  190. package/msg/json/en.json +284 -284
  191. package/msg/messages.js +289 -287
  192. package/msg/scratch_msgs.js +22959 -22970
  193. package/package.json +13 -10
  194. package/prettier.config.mjs +3 -0
  195. package/release.config.js +7 -7
  196. package/renovate.json5 +7 -9
  197. package/src/block_reporting.ts +16 -19
  198. package/src/blocks/colour.ts +12 -15
  199. package/src/blocks/control.ts +171 -174
  200. package/src/blocks/data.ts +233 -272
  201. package/src/blocks/event.ts +121 -123
  202. package/src/blocks/looks.ts +165 -167
  203. package/src/blocks/math.ts +44 -46
  204. package/src/blocks/matrix.ts +11 -13
  205. package/src/blocks/motion.ts +151 -153
  206. package/src/blocks/note.ts +11 -13
  207. package/src/blocks/operators.ts +158 -160
  208. package/src/blocks/procedures.ts +421 -511
  209. package/src/blocks/sensing.ts +163 -165
  210. package/src/blocks/sound.ts +58 -60
  211. package/src/blocks/text.ts +10 -12
  212. package/src/blocks/vertical_extensions.ts +86 -102
  213. package/src/checkable_continuous_flyout.ts +25 -42
  214. package/src/checkbox_bubble.ts +83 -100
  215. package/src/colours.ts +35 -37
  216. package/src/constants.ts +22 -29
  217. package/src/context_menu_items.ts +59 -84
  218. package/src/css.ts +3 -4
  219. package/src/data_category.ts +137 -251
  220. package/src/events/events_block_comment_base.ts +23 -30
  221. package/src/events/events_block_comment_change.ts +21 -42
  222. package/src/events/events_block_comment_collapse.ts +27 -36
  223. package/src/events/events_block_comment_create.ts +32 -46
  224. package/src/events/events_block_comment_delete.ts +12 -19
  225. package/src/events/events_block_comment_move.ts +27 -52
  226. package/src/events/events_block_comment_resize.ts +28 -55
  227. package/src/events/events_block_drag_end.ts +16 -26
  228. package/src/events/events_block_drag_outside.ts +12 -22
  229. package/src/events/events_scratch_variable_create.ts +37 -42
  230. package/src/fields/field_colour_slider.ts +186 -216
  231. package/src/fields/field_matrix.ts +202 -270
  232. package/src/fields/field_note.ts +277 -375
  233. package/src/fields/field_textinput_removable.ts +25 -40
  234. package/src/fields/field_variable_getter.ts +26 -31
  235. package/src/fields/field_vertical_separator.ts +19 -24
  236. package/src/fields/scratch_field_angle.ts +151 -187
  237. package/src/fields/scratch_field_dropdown.ts +15 -19
  238. package/src/fields/scratch_field_number.ts +125 -181
  239. package/src/fields/scratch_field_variable.ts +57 -75
  240. package/src/flyout_checkbox_icon.ts +18 -28
  241. package/src/glows.ts +52 -59
  242. package/src/index.ts +119 -133
  243. package/src/procedures.ts +150 -209
  244. package/src/recyclable_block_flyout_inflater.ts +14 -25
  245. package/src/renderer/bowler_hat.ts +6 -8
  246. package/src/renderer/cat/cat_face.ts +98 -99
  247. package/src/renderer/cat/constants.ts +67 -87
  248. package/src/renderer/cat/drawer.ts +21 -27
  249. package/src/renderer/cat/path_object.ts +3 -5
  250. package/src/renderer/cat/render_info.ts +5 -8
  251. package/src/renderer/cat/renderer.ts +12 -16
  252. package/src/renderer/constants.ts +34 -49
  253. package/src/renderer/drawer.ts +35 -51
  254. package/src/renderer/path_object.ts +4 -10
  255. package/src/renderer/render_info.ts +39 -56
  256. package/src/renderer/renderer.ts +17 -30
  257. package/src/scratch_block_paster.ts +12 -20
  258. package/src/scratch_blocks_utils.ts +4 -7
  259. package/src/scratch_comment_bubble.ts +76 -105
  260. package/src/scratch_comment_icon.ts +75 -124
  261. package/src/scratch_connection_checker.ts +7 -17
  262. package/src/scratch_continuous_category.ts +24 -28
  263. package/src/scratch_continuous_toolbox.ts +20 -27
  264. package/src/scratch_dragger.ts +42 -81
  265. package/src/scratch_insertion_marker_previewer.ts +6 -11
  266. package/src/scratch_variable_map.ts +5 -12
  267. package/src/scratch_variable_model.ts +6 -13
  268. package/src/scratch_zoom_controls.ts +101 -156
  269. package/src/shadows.ts +32 -37
  270. package/src/status_indicator_label.ts +54 -67
  271. package/src/status_indicator_label_flyout_inflater.ts +11 -21
  272. package/src/variables.ts +92 -141
  273. package/src/xml.ts +21 -35
  274. package/tsconfig.json +3 -7
  275. package/types/continuous-toolbox.d.ts +1 -1
  276. 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 2016 Massachusetts Institute of Technology
@@ -17,92 +16,91 @@
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 5x5 matrix input field.
20
+ * @file 5x5 matrix input field.
23
21
  * Displays an editable 5x5 matrix for controlling LED arrays.
24
22
  * @author khanning@gmail.com (Kreg Hanning)
25
23
  */
26
- import * as Blockly from "blockly/core";
24
+ import * as Blockly from 'blockly/core'
27
25
 
28
26
  enum PaintStyle {
29
- FILL = "fill",
30
- CLEAR = "clear",
27
+ FILL = 'fill',
28
+ CLEAR = 'clear',
31
29
  }
32
30
 
33
31
  enum LEDState {
34
- ON = "1",
35
- OFF = "0",
32
+ ON = '1',
33
+ OFF = '0',
36
34
  }
37
35
 
38
36
  /**
39
37
  * Class for a matrix field.
40
38
  */
41
39
  class FieldMatrix extends Blockly.Field<string> {
42
- private originalStyle?: string;
40
+ private originalStyle = ''
43
41
 
44
42
  /**
45
43
  * Array of SVGElement<rect> for matrix thumbnail image on block field.
46
44
  */
47
- private ledThumbNodes_: SVGElement[] = [];
45
+ private ledThumbNodes_: SVGElement[] = []
48
46
  /**
49
47
  * Array of SVGElement<rect> for matrix editor in dropdown menu.
50
48
  */
51
- private ledButtons_: SVGElement[] = [];
49
+ private ledButtons_: SVGElement[] = []
52
50
 
53
51
  /**
54
52
  * SVGElement for LED matrix in editor.
55
53
  */
56
- private matrixStage_: SVGElement | null = null;
54
+ private matrixStage_: SVGElement | null = null
57
55
 
58
56
  /**
59
57
  * SVG image for dropdown arrow.
60
58
  */
61
- private arrow_: SVGElement | null = null;
59
+ private arrow_: SVGElement | null = null
62
60
 
63
61
  /**
64
62
  * String indicating matrix paint style.
65
63
  * value can be [null, 'fill', 'clear'].
66
64
  */
67
- private paintStyle_: PaintStyle | null = null;
65
+ private paintStyle_: PaintStyle | null = null
68
66
 
69
67
  /**
70
68
  * Touch event wrapper.
71
69
  * Runs when the field is selected.
72
70
  */
73
- private mouseDownWrapper_: Blockly.browserEvents.Data | null = null;
71
+ private mouseDownWrapper_: Blockly.browserEvents.Data | null = null
74
72
 
75
73
  /**
76
74
  * Touch event wrapper.
77
75
  * Runs when the clear button editor button is selected.
78
76
  */
79
- private clearButtonWrapper_: Blockly.browserEvents.Data | null = null;
77
+ private clearButtonWrapper_: Blockly.browserEvents.Data | null = null
80
78
 
81
79
  /**
82
80
  * Touch event wrapper.
83
81
  * Runs when the fill button editor button is selected.
84
82
  */
85
- private fillButtonWrapper_: Blockly.browserEvents.Data | null = null;
83
+ private fillButtonWrapper_: Blockly.browserEvents.Data | null = null
86
84
 
87
85
  /**
88
86
  * Touch event wrapper.
89
87
  * Runs when the matrix editor is touched.
90
88
  */
91
- private matrixTouchWrapper_: Blockly.browserEvents.Data | null = null;
89
+ private matrixTouchWrapper_: Blockly.browserEvents.Data | null = null
92
90
 
93
91
  /**
94
92
  * Touch event wrapper.
95
93
  * Runs when the matrix editor touch event moves.
96
94
  */
97
- private matrixMoveWrapper_: Blockly.browserEvents.Data | null = null;
95
+ private matrixMoveWrapper_: Blockly.browserEvents.Data | null = null
98
96
 
99
97
  /**
100
98
  * Touch event wrapper.
101
99
  * Runs when the matrix editor is released.
102
100
  */
103
- private matrixReleaseWrapper_: Blockly.browserEvents.Data | null = null;
101
+ private matrixReleaseWrapper_: Blockly.browserEvents.Data | null = null
104
102
 
105
- SERIALIZABLE = true;
103
+ SERIALIZABLE = true
106
104
 
107
105
  /**
108
106
  * Construct a FieldMatrix from a JSON arg object.
@@ -110,78 +108,77 @@ class FieldMatrix extends Blockly.Field<string> {
110
108
  * @returns The new field instance.
111
109
  */
112
110
  static fromJson(options: FieldMatrixConfig): FieldMatrix {
113
- return new FieldMatrix(options["matrix"]);
111
+ return new FieldMatrix(options.matrix)
114
112
  }
115
113
 
116
114
  /**
117
115
  * Fixed size of the matrix thumbnail in the input field, in px.
118
116
  */
119
- static readonly THUMBNAIL_SIZE = 26;
117
+ static readonly THUMBNAIL_SIZE = 26
120
118
 
121
119
  /**
122
120
  * Fixed size of each matrix thumbnail node, in px.
123
121
  */
124
- static readonly THUMBNAIL_NODE_SIZE = 4;
122
+ static readonly THUMBNAIL_NODE_SIZE = 4
125
123
 
126
124
  /**
127
125
  * Fixed size of each matrix thumbnail node, in px.
128
126
  */
129
- static readonly THUMBNAIL_NODE_PAD = 1;
127
+ static readonly THUMBNAIL_NODE_PAD = 1
130
128
 
131
129
  /**
132
130
  * Fixed size of arrow icon in drop down menu, in px.
133
131
  */
134
- static readonly ARROW_SIZE = 12;
132
+ static readonly ARROW_SIZE = 12
135
133
 
136
134
  /**
137
135
  * Fixed size of each button inside the 5x5 matrix, in px.
138
136
  */
139
- static readonly MATRIX_NODE_SIZE = 18;
137
+ static readonly MATRIX_NODE_SIZE = 18
140
138
 
141
139
  /**
142
140
  * Fixed corner radius for 5x5 matrix buttons, in px.
143
141
  */
144
- static readonly MATRIX_NODE_RADIUS = 4;
142
+ static readonly MATRIX_NODE_RADIUS = 4
145
143
 
146
144
  /**
147
145
  * Fixed padding for 5x5 matrix buttons, in px.
148
146
  */
149
- static readonly MATRIX_NODE_PAD = 5;
147
+ static readonly MATRIX_NODE_PAD = 5
150
148
 
151
149
  /**
152
150
  * String with 25 '0' chars.
153
151
  * Used for clearing a matrix or filling an LED node array.
154
152
  */
155
- static readonly ZEROS = "0000000000000000000000000";
153
+ static readonly ZEROS = '0000000000000000000000000'
156
154
 
157
155
  /**
158
156
  * String with 25 '1' chars.
159
157
  * Used for filling a matrix.
160
158
  */
161
- static readonly ONES = "1111111111111111111111111";
159
+ static readonly ONES = '1111111111111111111111111'
162
160
 
163
161
  /**
164
162
  * Called when the field is placed on a block.
165
163
  */
166
164
  initView() {
167
165
  // Build the DOM.
168
- this.updateSize_();
169
- const dropdownArrowPadding =
170
- (this.getConstants() as Blockly.zelos.ConstantProvider).GRID_UNIT * 2;
171
- const thumbX = dropdownArrowPadding / 2;
172
- const thumbY = (this.size_.height - FieldMatrix.THUMBNAIL_SIZE) / 2;
166
+ this.updateSize_()
167
+ const dropdownArrowPadding = (this.getConstants() as Blockly.zelos.ConstantProvider).GRID_UNIT * 2
168
+ const thumbX = dropdownArrowPadding / 2
169
+ const thumbY = (this.size_.height - FieldMatrix.THUMBNAIL_SIZE) / 2
173
170
  const thumbnail = Blockly.utils.dom.createSvgElement(
174
- "g",
171
+ 'g',
175
172
  {
176
- transform: "translate(" + thumbX + ", " + thumbY + ")",
177
- "pointer-events": "bounding-box",
178
- cursor: "pointer",
173
+ transform: 'translate(' + thumbX + ', ' + thumbY + ')',
174
+ 'pointer-events': 'bounding-box',
175
+ cursor: 'pointer',
179
176
  },
180
- this.fieldGroup_
181
- );
182
- this.ledThumbNodes_ = [];
183
- const nodeSize = FieldMatrix.THUMBNAIL_NODE_SIZE;
184
- const nodePad = FieldMatrix.THUMBNAIL_NODE_PAD;
177
+ this.fieldGroup_,
178
+ )
179
+ this.ledThumbNodes_ = []
180
+ const nodeSize = FieldMatrix.THUMBNAIL_NODE_SIZE
181
+ const nodePad = FieldMatrix.THUMBNAIL_NODE_PAD
185
182
  for (let i = 0; i < 5; i++) {
186
183
  for (let n = 0; n < 5; n++) {
187
184
  const attr = {
@@ -191,46 +188,42 @@ class FieldMatrix extends Blockly.Field<string> {
191
188
  height: nodeSize,
192
189
  rx: nodePad,
193
190
  ry: nodePad,
194
- };
195
- this.ledThumbNodes_.push(
196
- Blockly.utils.dom.createSvgElement("rect", attr, thumbnail)
197
- );
191
+ }
192
+ this.ledThumbNodes_.push(Blockly.utils.dom.createSvgElement('rect', attr, thumbnail))
198
193
  }
199
- thumbnail.style.cursor = "default";
200
- this.updateMatrix_();
194
+ thumbnail.style.cursor = 'default'
195
+ this.updateMatrix_()
201
196
  }
202
197
 
203
198
  if (!this.arrow_) {
204
- const arrowX = FieldMatrix.THUMBNAIL_SIZE + dropdownArrowPadding * 1.5;
205
- const arrowY = (this.size_.height - FieldMatrix.ARROW_SIZE) / 2;
199
+ const arrowX = FieldMatrix.THUMBNAIL_SIZE + dropdownArrowPadding * 1.5
200
+ const arrowY = (this.size_.height - FieldMatrix.ARROW_SIZE) / 2
206
201
  this.arrow_ = Blockly.utils.dom.createSvgElement(
207
- "image",
202
+ 'image',
208
203
  {
209
- height: FieldMatrix.ARROW_SIZE + "px",
210
- width: FieldMatrix.ARROW_SIZE + "px",
211
- transform: "translate(" + arrowX + ", " + arrowY + ")",
204
+ height: FieldMatrix.ARROW_SIZE + 'px',
205
+ width: FieldMatrix.ARROW_SIZE + 'px',
206
+ transform: 'translate(' + arrowX + ', ' + arrowY + ')',
212
207
  },
213
- this.fieldGroup_
214
- );
208
+ this.fieldGroup_,
209
+ )
215
210
  this.arrow_.setAttributeNS(
216
- "http://www.w3.org/1999/xlink",
217
- "xlink:href",
218
- this.getConstants().FIELD_DROPDOWN_SVG_ARROW_DATAURI
219
- );
220
- this.arrow_.style.cursor = "default";
211
+ 'http://www.w3.org/1999/xlink',
212
+ 'xlink:href',
213
+ this.getConstants()!.FIELD_DROPDOWN_SVG_ARROW_DATAURI,
214
+ )
215
+ this.arrow_.style.cursor = 'default'
221
216
  }
222
217
  }
223
218
 
224
219
  doClassValidation_(matrix: string) {
225
- return matrix
226
- ? matrix + FieldMatrix.ZEROS.substr(0, 25 - matrix.length)
227
- : matrix;
220
+ return matrix ? matrix + FieldMatrix.ZEROS.substr(0, 25 - matrix.length) : matrix
228
221
  }
229
222
 
230
223
  doValueUpdate_(newValue: string) {
231
- super.doValueUpdate_(newValue);
224
+ super.doValueUpdate_(newValue)
232
225
  if (newValue) {
233
- this.updateMatrix_();
226
+ this.updateMatrix_()
234
227
  }
235
228
  }
236
229
 
@@ -238,144 +231,110 @@ class FieldMatrix extends Blockly.Field<string> {
238
231
  * Show the drop-down menu for editing this field.
239
232
  */
240
233
  showEditor_() {
241
- const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg;
242
- Blockly.DropDownDiv.setColour(
243
- sourceBlock.getColour(),
244
- sourceBlock.getColourTertiary()
245
- );
234
+ const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
235
+ Blockly.DropDownDiv.setColour(sourceBlock.getColour(), sourceBlock.getColourTertiary())
246
236
 
247
- const style = sourceBlock.style;
237
+ const style = sourceBlock.style
248
238
  if (sourceBlock.isShadow()) {
249
- this.originalStyle = sourceBlock.getStyleName();
250
- sourceBlock.setStyle(`${this.originalStyle}_selected`);
239
+ this.originalStyle = sourceBlock.getStyleName()
240
+ sourceBlock.setStyle(`${this.originalStyle}_selected`)
251
241
  } else if (this.borderRect_) {
252
242
  this.borderRect_.setAttribute(
253
- "fill",
254
- "colourQuaternary" in style
255
- ? `${style.colourQuaternary}`
256
- : style.colourTertiary
257
- );
243
+ 'fill',
244
+ 'colourQuaternary' in style ? `${style.colourQuaternary}` : style.colourTertiary,
245
+ )
258
246
  }
259
247
 
260
- const div = Blockly.DropDownDiv.getContentDiv();
248
+ const div = Blockly.DropDownDiv.getContentDiv()
261
249
  // Build the SVG DOM.
262
- const matrixSize =
263
- FieldMatrix.MATRIX_NODE_SIZE * 5 + FieldMatrix.MATRIX_NODE_PAD * 6;
250
+ const matrixSize = FieldMatrix.MATRIX_NODE_SIZE * 5 + FieldMatrix.MATRIX_NODE_PAD * 6
264
251
  this.matrixStage_ = Blockly.utils.dom.createSvgElement(
265
- "svg",
252
+ 'svg',
266
253
  {
267
- xmlns: "http://www.w3.org/2000/svg",
268
- "xmlns:html": "http://www.w3.org/1999/xhtml",
269
- "xmlns:xlink": "http://www.w3.org/1999/xlink",
270
- version: "1.1",
271
- height: matrixSize + "px",
272
- width: matrixSize + "px",
254
+ xmlns: 'http://www.w3.org/2000/svg',
255
+ 'xmlns:html': 'http://www.w3.org/1999/xhtml',
256
+ 'xmlns:xlink': 'http://www.w3.org/1999/xlink',
257
+ version: '1.1',
258
+ height: matrixSize + 'px',
259
+ width: matrixSize + 'px',
273
260
  },
274
- div
275
- );
261
+ div,
262
+ )
276
263
  // Create the 5x5 matrix
277
- this.ledButtons_ = [];
264
+ this.ledButtons_ = []
278
265
  for (let i = 0; i < 5; i++) {
279
266
  for (let n = 0; n < 5; n++) {
280
- const x =
281
- FieldMatrix.MATRIX_NODE_SIZE * n +
282
- FieldMatrix.MATRIX_NODE_PAD * (n + 1);
283
- const y =
284
- FieldMatrix.MATRIX_NODE_SIZE * i +
285
- FieldMatrix.MATRIX_NODE_PAD * (i + 1);
267
+ const x = FieldMatrix.MATRIX_NODE_SIZE * n + FieldMatrix.MATRIX_NODE_PAD * (n + 1)
268
+ const y = FieldMatrix.MATRIX_NODE_SIZE * i + FieldMatrix.MATRIX_NODE_PAD * (i + 1)
286
269
  const attr = {
287
- x: x + "px",
288
- y: y + "px",
270
+ x: x + 'px',
271
+ y: y + 'px',
289
272
  width: FieldMatrix.MATRIX_NODE_SIZE,
290
273
  height: FieldMatrix.MATRIX_NODE_SIZE,
291
274
  rx: FieldMatrix.MATRIX_NODE_RADIUS,
292
275
  ry: FieldMatrix.MATRIX_NODE_RADIUS,
293
- };
294
- const led = Blockly.utils.dom.createSvgElement(
295
- "rect",
296
- attr,
297
- this.matrixStage_
298
- );
299
- this.matrixStage_.appendChild(led);
300
- this.ledButtons_.push(led);
276
+ }
277
+ const led = Blockly.utils.dom.createSvgElement('rect', attr, this.matrixStage_)
278
+ this.matrixStage_.appendChild(led)
279
+ this.ledButtons_.push(led)
301
280
  }
302
281
  }
303
282
  // Div for lower button menu
304
- const buttonDiv = document.createElement("div");
283
+ const buttonDiv = document.createElement('div')
305
284
  // Button to clear matrix
306
- const clearButtonDiv = document.createElement("div");
307
- clearButtonDiv.className = "scratchMatrixButtonDiv";
285
+ const clearButtonDiv = document.createElement('div')
286
+ clearButtonDiv.className = 'scratchMatrixButtonDiv'
308
287
 
309
- const clearButton = this.createButton_(sourceBlock.getColourSecondary());
310
- clearButtonDiv.appendChild(clearButton);
288
+ const clearButton = this.createButton_(sourceBlock.getColourSecondary())
289
+ clearButtonDiv.appendChild(clearButton)
311
290
  // Button to fill matrix
312
- const fillButtonDiv = document.createElement("div");
313
- fillButtonDiv.className = "scratchMatrixButtonDiv";
314
- const fillButton = this.createButton_("var(--colour-text)");
315
- fillButtonDiv.appendChild(fillButton);
316
-
317
- buttonDiv.appendChild(clearButtonDiv);
318
- buttonDiv.appendChild(fillButtonDiv);
319
- div.appendChild(buttonDiv);
320
-
321
- Blockly.DropDownDiv.showPositionedByBlock(
322
- this,
323
- sourceBlock,
324
- this.dropdownDispose_.bind(this)
325
- );
326
-
327
- this.matrixTouchWrapper_ = Blockly.browserEvents.bind(
328
- this.matrixStage_,
329
- "mousedown",
330
- this,
331
- this.onMouseDown
332
- );
333
- this.clearButtonWrapper_ = Blockly.browserEvents.bind(
334
- clearButton,
335
- "click",
336
- this,
337
- this.clearMatrix_
338
- );
339
- this.fillButtonWrapper_ = Blockly.browserEvents.bind(
340
- fillButton,
341
- "click",
342
- this,
343
- this.fillMatrix_
344
- );
291
+ const fillButtonDiv = document.createElement('div')
292
+ fillButtonDiv.className = 'scratchMatrixButtonDiv'
293
+ const fillButton = this.createButton_('var(--colour-text)')
294
+ fillButtonDiv.appendChild(fillButton)
295
+
296
+ buttonDiv.appendChild(clearButtonDiv)
297
+ buttonDiv.appendChild(fillButtonDiv)
298
+ div.appendChild(buttonDiv)
299
+
300
+ Blockly.DropDownDiv.showPositionedByBlock(this, sourceBlock, this.dropdownDispose_.bind(this))
301
+
302
+ this.matrixTouchWrapper_ = Blockly.browserEvents.bind(this.matrixStage_, 'mousedown', this, this.onMouseDown)
303
+ this.clearButtonWrapper_ = Blockly.browserEvents.bind(clearButton, 'click', this, this.clearMatrix_)
304
+ this.fillButtonWrapper_ = Blockly.browserEvents.bind(fillButton, 'click', this, this.fillMatrix_)
345
305
 
346
306
  // Update the matrix for the current value
347
- this.updateMatrix_();
307
+ this.updateMatrix_()
348
308
  }
349
309
 
350
310
  dropdownDispose_() {
351
- const sourceBlock = this.getSourceBlock();
311
+ const sourceBlock = this.getSourceBlock()!
352
312
  if (sourceBlock.isShadow()) {
353
- sourceBlock.setStyle(this.originalStyle);
313
+ sourceBlock.setStyle(this.originalStyle)
354
314
  }
355
- this.updateMatrix_();
315
+ this.updateMatrix_()
356
316
  }
357
317
 
358
318
  /**
359
319
  * Make an svg object that resembles a 3x3 matrix to be used as a button.
360
- *
361
320
  * @param fill The color to fill the matrix nodes.
362
321
  * @returns The button svg element.
363
322
  */
364
323
  createButton_(fill: string): SVGElement {
365
- const button = Blockly.utils.dom.createSvgElement("svg", {
366
- xmlns: "http://www.w3.org/2000/svg",
367
- "xmlns:html": "http://www.w3.org/1999/xhtml",
368
- "xmlns:xlink": "http://www.w3.org/1999/xlink",
369
- version: "1.1",
370
- height: FieldMatrix.MATRIX_NODE_SIZE + "px",
371
- width: FieldMatrix.MATRIX_NODE_SIZE + "px",
372
- });
373
- const nodeSize = FieldMatrix.MATRIX_NODE_SIZE / 4;
374
- const nodePad = FieldMatrix.MATRIX_NODE_SIZE / 16;
324
+ const button = Blockly.utils.dom.createSvgElement('svg', {
325
+ xmlns: 'http://www.w3.org/2000/svg',
326
+ 'xmlns:html': 'http://www.w3.org/1999/xhtml',
327
+ 'xmlns:xlink': 'http://www.w3.org/1999/xlink',
328
+ version: '1.1',
329
+ height: FieldMatrix.MATRIX_NODE_SIZE + 'px',
330
+ width: FieldMatrix.MATRIX_NODE_SIZE + 'px',
331
+ })
332
+ const nodeSize = FieldMatrix.MATRIX_NODE_SIZE / 4
333
+ const nodePad = FieldMatrix.MATRIX_NODE_SIZE / 16
375
334
  for (let i = 0; i < 3; i++) {
376
335
  for (let n = 0; n < 3; n++) {
377
336
  Blockly.utils.dom.createSvgElement(
378
- "rect",
337
+ 'rect',
379
338
  {
380
339
  x: (nodeSize + nodePad) * n + nodePad,
381
340
  y: (nodeSize + nodePad) * i + nodePad,
@@ -385,126 +344,103 @@ class FieldMatrix extends Blockly.Field<string> {
385
344
  ry: nodePad,
386
345
  fill: fill,
387
346
  },
388
- button
389
- );
347
+ button,
348
+ )
390
349
  }
391
350
  }
392
- return button;
351
+ return button
393
352
  }
394
353
 
395
354
  /**
396
355
  * Redraw the matrix with the current value.
397
356
  */
398
357
  private updateMatrix_() {
399
- const matrix = this.getValue();
400
- const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg;
358
+ const matrix = this.getValue()!
359
+ const sourceBlock = this.getSourceBlock()! as Blockly.BlockSvg
401
360
  for (let i = 0; i < matrix.length; i++) {
402
361
  if (matrix[i] === LEDState.OFF) {
403
- this.fillMatrixNode_(
404
- this.ledButtons_,
405
- i,
406
- sourceBlock.getColourTertiary()
407
- );
408
- this.fillMatrixNode_(
409
- this.ledThumbNodes_,
410
- i,
411
- sourceBlock.getColourSecondary()
412
- );
362
+ this.fillMatrixNode_(this.ledButtons_, i, sourceBlock.getColourTertiary())
363
+ this.fillMatrixNode_(this.ledThumbNodes_, i, sourceBlock.getColourSecondary())
413
364
  } else {
414
- this.fillMatrixNode_(this.ledButtons_, i, "var(--colour-text)");
415
- this.fillMatrixNode_(this.ledThumbNodes_, i, "var(--colour-text)");
365
+ this.fillMatrixNode_(this.ledButtons_, i, 'var(--colour-text)')
366
+ this.fillMatrixNode_(this.ledThumbNodes_, i, 'var(--colour-text)')
416
367
  }
417
368
  }
418
369
  }
419
370
 
420
371
  /**
421
- * Clear the matrix.
422
- *
423
- * @param e Mouse event.
372
+ * Resets all LED values to zero.
373
+ * @param e Checked to allow only left-button clicks (button 0).
424
374
  */
425
375
  clearMatrix_(e: PointerEvent) {
426
- if (e.button != 0) return;
427
- this.setValue(FieldMatrix.ZEROS);
376
+ if (e.button != 0) return
377
+ this.setValue(FieldMatrix.ZEROS)
428
378
  }
429
379
 
430
380
  /**
431
- * Fill the matrix.
432
- *
433
- * @param e Mouse event.
381
+ * Sets all LED values to one.
382
+ * @param e Checked to allow only left-button clicks (button 0).
434
383
  */
435
384
  fillMatrix_(e: PointerEvent) {
436
- if (e.button != 0) return;
437
- this.setValue(FieldMatrix.ONES);
385
+ if (e.button != 0) return
386
+ this.setValue(FieldMatrix.ONES)
438
387
  }
439
388
 
440
389
  /**
441
390
  * Fill matrix node with specified colour.
442
- *
443
391
  * @param node The array of matrix nodes.
444
392
  * @param index The index of the matrix node.
445
393
  * @param fill The fill colour in '#rrggbb' format.
446
394
  */
447
395
  fillMatrixNode_(node: SVGElement[], index: number, fill: string) {
448
- if (!node || !node[index] || !fill) return;
449
- node[index].setAttribute("fill", fill);
396
+ if (!node?.[index] || !fill) return
397
+ node[index].setAttribute('fill', fill)
450
398
  }
451
399
 
452
400
  setLEDNode_(led: number, state: LEDState) {
453
- if (led < 0 || led > 24) return;
454
- const oldMatrix = this.getValue();
455
- const newMatrix =
456
- oldMatrix.substr(0, led) + state + oldMatrix.substr(led + 1);
457
- this.setValue(newMatrix);
401
+ if (led < 0 || led > 24) return
402
+ const oldMatrix = this.getValue()!
403
+ const newMatrix = oldMatrix.substr(0, led) + state + oldMatrix.substr(led + 1)
404
+ this.setValue(newMatrix)
458
405
  }
459
406
 
460
407
  fillLEDNode_(led: number) {
461
- if (led < 0 || led > 24) return;
462
- this.setLEDNode_(led, LEDState.ON);
408
+ if (led < 0 || led > 24) return
409
+ this.setLEDNode_(led, LEDState.ON)
463
410
  }
464
411
 
465
412
  clearLEDNode_(led: number) {
466
- if (led < 0 || led > 24) return;
467
- this.setLEDNode_(led, LEDState.OFF);
413
+ if (led < 0 || led > 24) return
414
+ this.setLEDNode_(led, LEDState.OFF)
468
415
  }
469
416
 
470
417
  toggleLEDNode_(led: number) {
471
- if (led < 0 || led > 24) return;
472
- if (this.getValue().charAt(led) === LEDState.OFF) {
473
- this.setLEDNode_(led, LEDState.ON);
418
+ if (led < 0 || led > 24) return
419
+ if (this.getValue()!.charAt(led) === LEDState.OFF) {
420
+ this.setLEDNode_(led, LEDState.ON)
474
421
  } else {
475
- this.setLEDNode_(led, LEDState.OFF);
422
+ this.setLEDNode_(led, LEDState.OFF)
476
423
  }
477
424
  }
478
425
 
479
426
  /**
480
427
  * Toggle matrix nodes on and off.
481
- *
482
428
  * @param e Mouse event.
483
429
  */
484
430
  onMouseDown(e: PointerEvent) {
485
- this.matrixMoveWrapper_ = Blockly.browserEvents.bind(
486
- document.body,
487
- "mousemove",
488
- this,
489
- this.onMouseMove
490
- );
491
- this.matrixReleaseWrapper_ = Blockly.browserEvents.bind(
492
- document.body,
493
- "mouseup",
494
- this,
495
- this.onMouseUp
496
- );
497
- const ledHit = this.checkForLED_(e);
431
+ this.matrixMoveWrapper_ = Blockly.browserEvents.bind(document.body, 'mousemove', this, this.onMouseMove)
432
+ this.matrixReleaseWrapper_ = Blockly.browserEvents.bind(document.body, 'mouseup', this, this.onMouseUp)
433
+ const ledHit = this.checkForLED_(e)
498
434
  if (ledHit > -1) {
499
- if (this.getValue().charAt(ledHit) === LEDState.OFF) {
500
- this.paintStyle_ = PaintStyle.FILL;
435
+ if (this.getValue()!.charAt(ledHit) === LEDState.OFF) {
436
+ this.paintStyle_ = PaintStyle.FILL
501
437
  } else {
502
- this.paintStyle_ = PaintStyle.CLEAR;
438
+ this.paintStyle_ = PaintStyle.CLEAR
503
439
  }
504
- this.toggleLEDNode_(ledHit);
505
- this.updateMatrix_();
440
+ this.toggleLEDNode_(ledHit)
441
+ this.updateMatrix_()
506
442
  } else {
507
- this.paintStyle_ = null;
443
+ this.paintStyle_ = null
508
444
  }
509
445
  }
510
446
 
@@ -513,107 +449,103 @@ class FieldMatrix extends Blockly.Field<string> {
513
449
  */
514
450
  onMouseUp() {
515
451
  if (this.matrixMoveWrapper_) {
516
- Blockly.browserEvents.unbind(this.matrixMoveWrapper_);
517
- this.matrixMoveWrapper_ = null;
452
+ Blockly.browserEvents.unbind(this.matrixMoveWrapper_)
453
+ this.matrixMoveWrapper_ = null
518
454
  }
519
455
  if (this.matrixReleaseWrapper_) {
520
- Blockly.browserEvents.unbind(this.matrixReleaseWrapper_);
521
- this.matrixReleaseWrapper_ = null;
456
+ Blockly.browserEvents.unbind(this.matrixReleaseWrapper_)
457
+ this.matrixReleaseWrapper_ = null
522
458
  }
523
- this.paintStyle_ = null;
459
+ this.paintStyle_ = null
524
460
  }
525
461
 
526
462
  /**
527
463
  * Toggle matrix nodes on and off by dragging mouse.
528
- *
529
464
  * @param e Mouse move event.
530
465
  */
531
466
  onMouseMove(e: PointerEvent) {
532
- e.preventDefault();
467
+ e.preventDefault()
533
468
  if (this.paintStyle_) {
534
- const led = this.checkForLED_(e);
535
- if (led < 0) return;
469
+ const led = this.checkForLED_(e)
470
+ if (led < 0) return
536
471
  if (this.paintStyle_ === PaintStyle.CLEAR) {
537
- this.clearLEDNode_(led);
472
+ this.clearLEDNode_(led)
538
473
  } else if (this.paintStyle_ === PaintStyle.FILL) {
539
- this.fillLEDNode_(led);
474
+ this.fillLEDNode_(led)
540
475
  }
541
476
  }
542
477
  }
543
478
 
544
479
  /**
545
480
  * Check if mouse coordinates collide with a matrix node.
546
- *
547
481
  * @param e Mouse move event.
548
482
  * @returns The matching matrix node or -1 for none.
549
483
  */
550
484
  checkForLED_(e: PointerEvent): number {
551
- const bBox = this.matrixStage_.getBoundingClientRect();
552
- const nodeSize = FieldMatrix.MATRIX_NODE_SIZE;
553
- const nodePad = FieldMatrix.MATRIX_NODE_PAD;
554
- const dx = e.clientX - bBox.left;
555
- const dy = e.clientY - bBox.top;
556
- const min = nodePad / 2;
557
- const max = bBox.width - nodePad / 2;
485
+ if (!this.matrixStage_) return -1
486
+ const bBox = this.matrixStage_.getBoundingClientRect()
487
+ const nodeSize = FieldMatrix.MATRIX_NODE_SIZE
488
+ const nodePad = FieldMatrix.MATRIX_NODE_PAD
489
+ const dx = e.clientX - bBox.left
490
+ const dy = e.clientY - bBox.top
491
+ const min = nodePad / 2
492
+ const max = bBox.width - nodePad / 2
558
493
  if (dx < min || dx > max || dy < min || dy > max) {
559
- return -1;
494
+ return -1
560
495
  }
561
- const xDiv = Math.trunc((dx - nodePad / 2) / (nodeSize + nodePad));
562
- const yDiv = Math.trunc((dy - nodePad / 2) / (nodeSize + nodePad));
563
- return xDiv + yDiv * nodePad;
496
+ const xDiv = Math.trunc((dx - nodePad / 2) / (nodeSize + nodePad))
497
+ const yDiv = Math.trunc((dy - nodePad / 2) / (nodeSize + nodePad))
498
+ return xDiv + yDiv * nodePad
564
499
  }
565
500
 
566
501
  /**
567
502
  * Clean up this FieldMatrix, as well as the inherited Field.
568
503
  */
569
504
  dispose() {
570
- super.dispose();
571
- this.matrixStage_ = null;
505
+ super.dispose()
506
+ this.matrixStage_ = null
572
507
  if (this.mouseDownWrapper_) {
573
- Blockly.browserEvents.unbind(this.mouseDownWrapper_);
508
+ Blockly.browserEvents.unbind(this.mouseDownWrapper_)
574
509
  }
575
510
  if (this.matrixTouchWrapper_) {
576
- Blockly.browserEvents.unbind(this.matrixTouchWrapper_);
511
+ Blockly.browserEvents.unbind(this.matrixTouchWrapper_)
577
512
  }
578
513
  if (this.matrixReleaseWrapper_) {
579
- Blockly.browserEvents.unbind(this.matrixReleaseWrapper_);
514
+ Blockly.browserEvents.unbind(this.matrixReleaseWrapper_)
580
515
  }
581
516
  if (this.matrixMoveWrapper_) {
582
- Blockly.browserEvents.unbind(this.matrixMoveWrapper_);
517
+ Blockly.browserEvents.unbind(this.matrixMoveWrapper_)
583
518
  }
584
519
  if (this.clearButtonWrapper_) {
585
- Blockly.browserEvents.unbind(this.clearButtonWrapper_);
520
+ Blockly.browserEvents.unbind(this.clearButtonWrapper_)
586
521
  }
587
522
  if (this.fillButtonWrapper_) {
588
- Blockly.browserEvents.unbind(this.fillButtonWrapper_);
523
+ Blockly.browserEvents.unbind(this.fillButtonWrapper_)
589
524
  }
590
525
  }
591
526
 
592
527
  updateSize_() {
593
- const constants = this.getConstants() as Blockly.zelos.ConstantProvider;
594
- let totalHeight = constants.FIELD_TEXT_HEIGHT;
528
+ const constants = this.getConstants() as Blockly.zelos.ConstantProvider
529
+ const totalHeight = constants.FIELD_TEXT_HEIGHT
595
530
 
596
- this.size_.height = totalHeight;
597
- this.size_.width =
598
- FieldMatrix.THUMBNAIL_SIZE +
599
- FieldMatrix.ARROW_SIZE +
600
- constants.GRID_UNIT * 2 * 1.5;
531
+ this.size_.height = totalHeight
532
+ this.size_.width = FieldMatrix.THUMBNAIL_SIZE + FieldMatrix.ARROW_SIZE + constants.GRID_UNIT * 2 * 1.5
601
533
 
602
- this.positionBorderRect_();
534
+ this.positionBorderRect_()
603
535
  }
604
536
 
605
537
  getClickTarget_() {
606
- return (this.getSourceBlock() as Blockly.BlockSvg).getSvgRoot();
538
+ return (this.getSourceBlock() as Blockly.BlockSvg).getSvgRoot()
607
539
  }
608
540
  }
609
541
 
610
542
  interface FieldMatrixConfig extends Blockly.FieldConfig {
611
- matrix: string;
543
+ matrix: string
612
544
  }
613
545
 
614
546
  /**
615
547
  * Register the field and any dependencies.
616
548
  */
617
549
  export function registerFieldMatrix() {
618
- Blockly.fieldRegistry.register("field_matrix", FieldMatrix);
550
+ Blockly.fieldRegistry.register('field_matrix', FieldMatrix)
619
551
  }