scratch-blocks 1.1.206 → 2.0.0-beta.1

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 (1295) hide show
  1. package/.husky/commit-msg +0 -3
  2. package/CHANGELOG.md +111 -833
  3. package/TODO.md +16 -0
  4. package/blockly-rc/.eslintignore +28 -0
  5. package/blockly-rc/.eslintrc.js +187 -0
  6. package/blockly-rc/.gitattributes +1 -0
  7. package/blockly-rc/.github/CODEOWNERS +1 -0
  8. package/blockly-rc/.github/CONTRIBUTING.md +46 -0
  9. package/blockly-rc/.github/ISSUE_TEMPLATE/bug_report.yaml +58 -0
  10. package/blockly-rc/.github/ISSUE_TEMPLATE/config.yml +7 -0
  11. package/blockly-rc/.github/ISSUE_TEMPLATE/documentation.yaml +38 -0
  12. package/blockly-rc/.github/ISSUE_TEMPLATE/feature_request.yaml +39 -0
  13. package/blockly-rc/.github/PULL_REQUEST_TEMPLATE.md +42 -0
  14. package/blockly-rc/.github/dependabot.yml +27 -0
  15. package/blockly-rc/.github/release.yml +32 -0
  16. package/blockly-rc/.github/workflows/appengine_deploy.yml +54 -0
  17. package/blockly-rc/.github/workflows/assign_reviewers.yml +41 -0
  18. package/blockly-rc/.github/workflows/browser_test.yml +55 -0
  19. package/blockly-rc/.github/workflows/build.yml +86 -0
  20. package/blockly-rc/.github/workflows/conventional-label.yml +17 -0
  21. package/blockly-rc/.github/workflows/develop_freeze.yml +26 -0
  22. package/blockly-rc/.github/workflows/tag_module_cleanup.yml +37 -0
  23. package/blockly-rc/.github/workflows/welcome_new_contributors.yml +36 -0
  24. package/blockly-rc/.prettierignore +30 -0
  25. package/blockly-rc/.prettierrc.js +13 -0
  26. package/blockly-rc/CHANGELOG.md +77 -0
  27. package/blockly-rc/LICENSE +202 -0
  28. package/blockly-rc/README.md +80 -0
  29. package/blockly-rc/_config.yml +1 -0
  30. package/blockly-rc/api-extractor.json +385 -0
  31. package/blockly-rc/appengine/.gcloudignore +20 -0
  32. package/blockly-rc/appengine/README.txt +42 -0
  33. package/blockly-rc/appengine/add_timestamps.py +69 -0
  34. package/blockly-rc/appengine/app.yaml +104 -0
  35. package/blockly-rc/appengine/apple-touch-icon.png +0 -0
  36. package/blockly-rc/appengine/blockly_compressed.js +11 -0
  37. package/blockly-rc/appengine/expiration.py +52 -0
  38. package/blockly-rc/appengine/favicon.ico +0 -0
  39. package/blockly-rc/appengine/index.yaml +11 -0
  40. package/blockly-rc/appengine/main.py +39 -0
  41. package/blockly-rc/appengine/redirect.html +107 -0
  42. package/blockly-rc/appengine/requirements.txt +1 -0
  43. package/blockly-rc/appengine/robots.txt +2 -0
  44. package/blockly-rc/appengine/storage.js +190 -0
  45. package/blockly-rc/appengine/storage.py +125 -0
  46. package/blockly-rc/blocks/blocks.ts +44 -0
  47. package/blockly-rc/blocks/lists.ts +1085 -0
  48. package/blockly-rc/blocks/logic.ts +712 -0
  49. package/blockly-rc/blocks/loops.ts +408 -0
  50. package/blockly-rc/blocks/math.ts +591 -0
  51. package/blockly-rc/blocks/procedures.ts +1364 -0
  52. package/blockly-rc/blocks/text.ts +1007 -0
  53. package/blockly-rc/blocks/variables.ts +183 -0
  54. package/blockly-rc/blocks/variables_dynamic.ts +194 -0
  55. package/blockly-rc/core/any_aliases.ts +8 -0
  56. package/blockly-rc/core/block.ts +2523 -0
  57. package/blockly-rc/core/block_animations.ts +225 -0
  58. package/blockly-rc/core/block_flyout_inflater.ts +262 -0
  59. package/blockly-rc/core/block_svg.ts +1768 -0
  60. package/blockly-rc/core/blockly.ts +605 -0
  61. package/blockly-rc/core/blockly_options.ts +71 -0
  62. package/blockly-rc/core/blocks.ts +18 -0
  63. package/blockly-rc/core/browser_events.ts +244 -0
  64. package/blockly-rc/core/bubbles/bubble.ts +658 -0
  65. package/blockly-rc/core/bubbles/mini_workspace_bubble.ts +280 -0
  66. package/blockly-rc/core/bubbles/text_bubble.ts +103 -0
  67. package/blockly-rc/core/bubbles/textinput_bubble.ts +344 -0
  68. package/blockly-rc/core/bubbles.ts +12 -0
  69. package/blockly-rc/core/bump_objects.ts +192 -0
  70. package/blockly-rc/core/button_flyout_inflater.ts +63 -0
  71. package/blockly-rc/core/clipboard/block_paster.ts +142 -0
  72. package/blockly-rc/core/clipboard/registry.ts +31 -0
  73. package/blockly-rc/core/clipboard/workspace_comment_paster.ts +94 -0
  74. package/blockly-rc/core/clipboard.ts +113 -0
  75. package/blockly-rc/core/comments/comment_view.ts +899 -0
  76. package/blockly-rc/core/comments/rendered_workspace_comment.ts +297 -0
  77. package/blockly-rc/core/comments/workspace_comment.ts +237 -0
  78. package/blockly-rc/core/comments.ts +9 -0
  79. package/blockly-rc/core/common.ts +305 -0
  80. package/blockly-rc/core/component_manager.ts +235 -0
  81. package/blockly-rc/core/config.ts +65 -0
  82. package/blockly-rc/core/connection.ts +793 -0
  83. package/blockly-rc/core/connection_checker.ts +348 -0
  84. package/blockly-rc/core/connection_db.ts +297 -0
  85. package/blockly-rc/core/connection_type.ts +21 -0
  86. package/blockly-rc/core/constants.ts +23 -0
  87. package/blockly-rc/core/contextmenu.ts +268 -0
  88. package/blockly-rc/core/contextmenu_items.ts +700 -0
  89. package/blockly-rc/core/contextmenu_registry.ts +194 -0
  90. package/blockly-rc/core/css.ts +481 -0
  91. package/blockly-rc/core/delete_area.ts +77 -0
  92. package/blockly-rc/core/dialog.ts +121 -0
  93. package/blockly-rc/core/drag_target.ts +97 -0
  94. package/blockly-rc/core/dragging/block_drag_strategy.ts +454 -0
  95. package/blockly-rc/core/dragging/bubble_drag_strategy.ts +52 -0
  96. package/blockly-rc/core/dragging/comment_drag_strategy.ts +91 -0
  97. package/blockly-rc/core/dragging/dragger.ts +163 -0
  98. package/blockly-rc/core/dragging.ts +12 -0
  99. package/blockly-rc/core/dropdowndiv.ts +768 -0
  100. package/blockly-rc/core/events/events.ts +163 -0
  101. package/blockly-rc/core/events/events_abstract.ts +130 -0
  102. package/blockly-rc/core/events/events_block_base.ts +88 -0
  103. package/blockly-rc/core/events/events_block_change.ts +259 -0
  104. package/blockly-rc/core/events/events_block_create.ts +185 -0
  105. package/blockly-rc/core/events/events_block_delete.ts +182 -0
  106. package/blockly-rc/core/events/events_block_drag.ts +116 -0
  107. package/blockly-rc/core/events/events_block_field_intermediate_change.ts +167 -0
  108. package/blockly-rc/core/events/events_block_move.ts +307 -0
  109. package/blockly-rc/core/events/events_bubble_open.ts +120 -0
  110. package/blockly-rc/core/events/events_click.ts +110 -0
  111. package/blockly-rc/core/events/events_comment_base.ts +126 -0
  112. package/blockly-rc/core/events/events_comment_change.ts +161 -0
  113. package/blockly-rc/core/events/events_comment_collapse.ts +103 -0
  114. package/blockly-rc/core/events/events_comment_create.ts +118 -0
  115. package/blockly-rc/core/events/events_comment_delete.ts +117 -0
  116. package/blockly-rc/core/events/events_comment_drag.ts +99 -0
  117. package/blockly-rc/core/events/events_comment_move.ts +207 -0
  118. package/blockly-rc/core/events/events_comment_resize.ts +174 -0
  119. package/blockly-rc/core/events/events_marker_move.ts +134 -0
  120. package/blockly-rc/core/events/events_selected.ts +98 -0
  121. package/blockly-rc/core/events/events_theme_change.ts +84 -0
  122. package/blockly-rc/core/events/events_toolbox_item_select.ts +96 -0
  123. package/blockly-rc/core/events/events_trashcan_open.ts +88 -0
  124. package/blockly-rc/core/events/events_ui_base.ts +47 -0
  125. package/blockly-rc/core/events/events_var_base.ts +89 -0
  126. package/blockly-rc/core/events/events_var_create.ts +129 -0
  127. package/blockly-rc/core/events/events_var_delete.ts +124 -0
  128. package/blockly-rc/core/events/events_var_rename.ts +133 -0
  129. package/blockly-rc/core/events/events_var_type_change.ts +122 -0
  130. package/blockly-rc/core/events/events_viewport.ts +149 -0
  131. package/blockly-rc/core/events/utils.ts +595 -0
  132. package/blockly-rc/core/events/workspace_events.ts +46 -0
  133. package/blockly-rc/core/extensions.ts +491 -0
  134. package/blockly-rc/core/field.ts +1471 -0
  135. package/blockly-rc/core/field_checkbox.ts +271 -0
  136. package/blockly-rc/core/field_dropdown.ts +857 -0
  137. package/blockly-rc/core/field_image.ts +297 -0
  138. package/blockly-rc/core/field_input.ts +755 -0
  139. package/blockly-rc/core/field_label.ts +150 -0
  140. package/blockly-rc/core/field_label_serializable.ts +73 -0
  141. package/blockly-rc/core/field_number.ts +381 -0
  142. package/blockly-rc/core/field_registry.ts +115 -0
  143. package/blockly-rc/core/field_textinput.ts +117 -0
  144. package/blockly-rc/core/field_variable.ts +651 -0
  145. package/blockly-rc/core/flyout_base.ts +968 -0
  146. package/blockly-rc/core/flyout_button.ts +416 -0
  147. package/blockly-rc/core/flyout_horizontal.ts +374 -0
  148. package/blockly-rc/core/flyout_metrics_manager.ts +90 -0
  149. package/blockly-rc/core/flyout_separator.ts +61 -0
  150. package/blockly-rc/core/flyout_vertical.ts +353 -0
  151. package/blockly-rc/core/generator.ts +611 -0
  152. package/blockly-rc/core/gesture.ts +1191 -0
  153. package/blockly-rc/core/grid.ts +252 -0
  154. package/blockly-rc/core/icons/comment_icon.ts +435 -0
  155. package/blockly-rc/core/icons/exceptions.ts +23 -0
  156. package/blockly-rc/core/icons/icon.ts +147 -0
  157. package/blockly-rc/core/icons/icon_types.ts +32 -0
  158. package/blockly-rc/core/icons/mutator_icon.ts +354 -0
  159. package/blockly-rc/core/icons/registry.ts +33 -0
  160. package/blockly-rc/core/icons/warning_icon.ts +219 -0
  161. package/blockly-rc/core/icons.ts +24 -0
  162. package/blockly-rc/core/inject.ts +428 -0
  163. package/blockly-rc/core/inputs/align.ts +14 -0
  164. package/blockly-rc/core/inputs/dummy_input.ts +26 -0
  165. package/blockly-rc/core/inputs/end_row_input.ts +31 -0
  166. package/blockly-rc/core/inputs/input.ts +318 -0
  167. package/blockly-rc/core/inputs/input_types.ts +27 -0
  168. package/blockly-rc/core/inputs/statement_input.ts +34 -0
  169. package/blockly-rc/core/inputs/value_input.ts +30 -0
  170. package/blockly-rc/core/inputs.ts +23 -0
  171. package/blockly-rc/core/insertion_marker_manager.ts +742 -0
  172. package/blockly-rc/core/insertion_marker_previewer.ts +254 -0
  173. package/blockly-rc/core/interfaces/i_ast_node_location.ts +12 -0
  174. package/blockly-rc/core/interfaces/i_ast_node_location_svg.ts +28 -0
  175. package/blockly-rc/core/interfaces/i_ast_node_location_with_block.ts +22 -0
  176. package/blockly-rc/core/interfaces/i_autohideable.ts +22 -0
  177. package/blockly-rc/core/interfaces/i_bounded_element.ts +30 -0
  178. package/blockly-rc/core/interfaces/i_bubble.ts +63 -0
  179. package/blockly-rc/core/interfaces/i_collapsible_toolbox_item.ts +33 -0
  180. package/blockly-rc/core/interfaces/i_comment_icon.ts +47 -0
  181. package/blockly-rc/core/interfaces/i_component.ts +19 -0
  182. package/blockly-rc/core/interfaces/i_connection_checker.ts +100 -0
  183. package/blockly-rc/core/interfaces/i_connection_previewer.ts +50 -0
  184. package/blockly-rc/core/interfaces/i_contextmenu.ts +16 -0
  185. package/blockly-rc/core/interfaces/i_copyable.ts +31 -0
  186. package/blockly-rc/core/interfaces/i_deletable.ts +34 -0
  187. package/blockly-rc/core/interfaces/i_delete_area.ts +28 -0
  188. package/blockly-rc/core/interfaces/i_drag_target.ts +69 -0
  189. package/blockly-rc/core/interfaces/i_draggable.ts +72 -0
  190. package/blockly-rc/core/interfaces/i_dragger.ts +35 -0
  191. package/blockly-rc/core/interfaces/i_flyout.ts +189 -0
  192. package/blockly-rc/core/interfaces/i_flyout_inflater.ts +41 -0
  193. package/blockly-rc/core/interfaces/i_has_bubble.ts +20 -0
  194. package/blockly-rc/core/interfaces/i_icon.ts +114 -0
  195. package/blockly-rc/core/interfaces/i_keyboard_accessible.ts +21 -0
  196. package/blockly-rc/core/interfaces/i_legacy_procedure_blocks.ts +50 -0
  197. package/blockly-rc/core/interfaces/i_metrics_manager.ts +149 -0
  198. package/blockly-rc/core/interfaces/i_movable.ts +19 -0
  199. package/blockly-rc/core/interfaces/i_observable.ts +24 -0
  200. package/blockly-rc/core/interfaces/i_parameter_model.ts +51 -0
  201. package/blockly-rc/core/interfaces/i_paster.ts +25 -0
  202. package/blockly-rc/core/interfaces/i_positionable.ts +33 -0
  203. package/blockly-rc/core/interfaces/i_procedure_block.ts +27 -0
  204. package/blockly-rc/core/interfaces/i_procedure_map.ts +18 -0
  205. package/blockly-rc/core/interfaces/i_procedure_model.ts +71 -0
  206. package/blockly-rc/core/interfaces/i_registrable.ts +12 -0
  207. package/blockly-rc/core/interfaces/i_rendered_element.ts +22 -0
  208. package/blockly-rc/core/interfaces/i_selectable.ts +34 -0
  209. package/blockly-rc/core/interfaces/i_selectable_toolbox_item.ts +63 -0
  210. package/blockly-rc/core/interfaces/i_serializable.ts +28 -0
  211. package/blockly-rc/core/interfaces/i_serializer.ts +55 -0
  212. package/blockly-rc/core/interfaces/i_styleable.ts +26 -0
  213. package/blockly-rc/core/interfaces/i_toolbox.ts +112 -0
  214. package/blockly-rc/core/interfaces/i_toolbox_item.ts +81 -0
  215. package/blockly-rc/core/interfaces/i_variable_backed_parameter_model.ts +23 -0
  216. package/blockly-rc/core/interfaces/i_variable_map.ts +65 -0
  217. package/blockly-rc/core/interfaces/i_variable_model.ts +57 -0
  218. package/blockly-rc/core/internal_constants.ts +47 -0
  219. package/blockly-rc/core/keyboard_nav/ast_node.ts +884 -0
  220. package/blockly-rc/core/keyboard_nav/basic_cursor.ts +223 -0
  221. package/blockly-rc/core/keyboard_nav/cursor.ts +138 -0
  222. package/blockly-rc/core/keyboard_nav/marker.ts +113 -0
  223. package/blockly-rc/core/keyboard_nav/tab_navigate_cursor.ts +46 -0
  224. package/blockly-rc/core/label_flyout_inflater.ts +59 -0
  225. package/blockly-rc/core/layer_manager.ts +186 -0
  226. package/blockly-rc/core/layers.ts +17 -0
  227. package/blockly-rc/core/main.ts +31 -0
  228. package/blockly-rc/core/marker_manager.ts +189 -0
  229. package/blockly-rc/core/menu.ts +463 -0
  230. package/blockly-rc/core/menuitem.ts +221 -0
  231. package/blockly-rc/core/metrics_manager.ts +486 -0
  232. package/blockly-rc/core/msg.ts +27 -0
  233. package/blockly-rc/core/names.ts +275 -0
  234. package/blockly-rc/core/observable_procedure_map.ts +66 -0
  235. package/blockly-rc/core/options.ts +377 -0
  236. package/blockly-rc/core/positionable_helpers.ts +186 -0
  237. package/blockly-rc/core/procedures.ts +510 -0
  238. package/blockly-rc/core/registry.ts +400 -0
  239. package/blockly-rc/core/render_management.ts +193 -0
  240. package/blockly-rc/core/rendered_connection.ts +571 -0
  241. package/blockly-rc/core/renderers/common/block_rendering.ts +120 -0
  242. package/blockly-rc/core/renderers/common/constants.ts +1198 -0
  243. package/blockly-rc/core/renderers/common/drawer.ts +518 -0
  244. package/blockly-rc/core/renderers/common/i_path_object.ts +137 -0
  245. package/blockly-rc/core/renderers/common/info.ts +767 -0
  246. package/blockly-rc/core/renderers/common/marker_svg.ts +765 -0
  247. package/blockly-rc/core/renderers/common/path_object.ts +324 -0
  248. package/blockly-rc/core/renderers/common/renderer.ts +281 -0
  249. package/blockly-rc/core/renderers/geras/constants.ts +46 -0
  250. package/blockly-rc/core/renderers/geras/drawer.ts +167 -0
  251. package/blockly-rc/core/renderers/geras/geras.ts +31 -0
  252. package/blockly-rc/core/renderers/geras/highlight_constants.ts +342 -0
  253. package/blockly-rc/core/renderers/geras/highlighter.ts +313 -0
  254. package/blockly-rc/core/renderers/geras/info.ts +478 -0
  255. package/blockly-rc/core/renderers/geras/measurables/inline_input.ts +37 -0
  256. package/blockly-rc/core/renderers/geras/measurables/statement_input.ts +36 -0
  257. package/blockly-rc/core/renderers/geras/path_object.ts +135 -0
  258. package/blockly-rc/core/renderers/geras/renderer.ts +124 -0
  259. package/blockly-rc/core/renderers/measurables/base.ts +41 -0
  260. package/blockly-rc/core/renderers/measurables/bottom_row.ts +104 -0
  261. package/blockly-rc/core/renderers/measurables/connection.ts +43 -0
  262. package/blockly-rc/core/renderers/measurables/external_value_input.ts +53 -0
  263. package/blockly-rc/core/renderers/measurables/field.ts +50 -0
  264. package/blockly-rc/core/renderers/measurables/hat.ts +33 -0
  265. package/blockly-rc/core/renderers/measurables/icon.ts +42 -0
  266. package/blockly-rc/core/renderers/measurables/in_row_spacer.ts +29 -0
  267. package/blockly-rc/core/renderers/measurables/inline_input.ts +63 -0
  268. package/blockly-rc/core/renderers/measurables/input_connection.ts +57 -0
  269. package/blockly-rc/core/renderers/measurables/input_row.ts +67 -0
  270. package/blockly-rc/core/renderers/measurables/jagged_edge.ts +28 -0
  271. package/blockly-rc/core/renderers/measurables/next_connection.ts +34 -0
  272. package/blockly-rc/core/renderers/measurables/output_connection.ts +43 -0
  273. package/blockly-rc/core/renderers/measurables/previous_connection.ts +34 -0
  274. package/blockly-rc/core/renderers/measurables/round_corner.ts +34 -0
  275. package/blockly-rc/core/renderers/measurables/row.ts +191 -0
  276. package/blockly-rc/core/renderers/measurables/spacer_row.ts +44 -0
  277. package/blockly-rc/core/renderers/measurables/square_corner.ts +32 -0
  278. package/blockly-rc/core/renderers/measurables/statement_input.ts +41 -0
  279. package/blockly-rc/core/renderers/measurables/top_row.ts +110 -0
  280. package/blockly-rc/core/renderers/measurables/types.ts +319 -0
  281. package/blockly-rc/core/renderers/thrasos/info.ts +328 -0
  282. package/blockly-rc/core/renderers/thrasos/renderer.ts +40 -0
  283. package/blockly-rc/core/renderers/thrasos/thrasos.ts +14 -0
  284. package/blockly-rc/core/renderers/zelos/constants.ts +877 -0
  285. package/blockly-rc/core/renderers/zelos/drawer.ts +274 -0
  286. package/blockly-rc/core/renderers/zelos/info.ts +652 -0
  287. package/blockly-rc/core/renderers/zelos/marker_svg.ts +145 -0
  288. package/blockly-rc/core/renderers/zelos/measurables/bottom_row.ts +44 -0
  289. package/blockly-rc/core/renderers/zelos/measurables/inputs.ts +41 -0
  290. package/blockly-rc/core/renderers/zelos/measurables/row_elements.ts +29 -0
  291. package/blockly-rc/core/renderers/zelos/measurables/top_row.ts +50 -0
  292. package/blockly-rc/core/renderers/zelos/path_object.ts +209 -0
  293. package/blockly-rc/core/renderers/zelos/renderer.ts +143 -0
  294. package/blockly-rc/core/renderers/zelos/zelos.ts +33 -0
  295. package/blockly-rc/core/scrollbar.ts +898 -0
  296. package/blockly-rc/core/scrollbar_pair.ts +349 -0
  297. package/blockly-rc/core/separator_flyout_inflater.ts +69 -0
  298. package/blockly-rc/core/serialization/blocks.ts +868 -0
  299. package/blockly-rc/core/serialization/exceptions.ts +112 -0
  300. package/blockly-rc/core/serialization/priorities.ts +25 -0
  301. package/blockly-rc/core/serialization/procedures.ts +158 -0
  302. package/blockly-rc/core/serialization/registry.ts +30 -0
  303. package/blockly-rc/core/serialization/variables.ts +68 -0
  304. package/blockly-rc/core/serialization/workspace_comments.ts +143 -0
  305. package/blockly-rc/core/serialization/workspaces.ts +94 -0
  306. package/blockly-rc/core/serialization.ts +32 -0
  307. package/blockly-rc/core/shortcut_items.ts +338 -0
  308. package/blockly-rc/core/shortcut_registry.ts +368 -0
  309. package/blockly-rc/core/sprites.ts +15 -0
  310. package/blockly-rc/core/theme/classic.ts +40 -0
  311. package/blockly-rc/core/theme/themes.ts +12 -0
  312. package/blockly-rc/core/theme/zelos.ts +80 -0
  313. package/blockly-rc/core/theme.ts +232 -0
  314. package/blockly-rc/core/theme_manager.ts +192 -0
  315. package/blockly-rc/core/toolbox/category.ts +739 -0
  316. package/blockly-rc/core/toolbox/collapsible_category.ts +288 -0
  317. package/blockly-rc/core/toolbox/separator.ts +105 -0
  318. package/blockly-rc/core/toolbox/toolbox.ts +1134 -0
  319. package/blockly-rc/core/toolbox/toolbox_item.ts +152 -0
  320. package/blockly-rc/core/tooltip.ts +466 -0
  321. package/blockly-rc/core/touch.ts +155 -0
  322. package/blockly-rc/core/trashcan.ts +748 -0
  323. package/blockly-rc/core/utils/aria.ts +144 -0
  324. package/blockly-rc/core/utils/array.ts +24 -0
  325. package/blockly-rc/core/utils/colour.ts +265 -0
  326. package/blockly-rc/core/utils/coordinate.ts +129 -0
  327. package/blockly-rc/core/utils/deprecation.ts +47 -0
  328. package/blockly-rc/core/utils/dom.ts +356 -0
  329. package/blockly-rc/core/utils/idgenerator.ts +70 -0
  330. package/blockly-rc/core/utils/keycodes.ts +154 -0
  331. package/blockly-rc/core/utils/math.ts +50 -0
  332. package/blockly-rc/core/utils/metrics.ts +86 -0
  333. package/blockly-rc/core/utils/object.ts +28 -0
  334. package/blockly-rc/core/utils/parsing.ts +287 -0
  335. package/blockly-rc/core/utils/rect.ts +69 -0
  336. package/blockly-rc/core/utils/size.ts +62 -0
  337. package/blockly-rc/core/utils/string.ts +289 -0
  338. package/blockly-rc/core/utils/style.ts +219 -0
  339. package/blockly-rc/core/utils/svg.ts +84 -0
  340. package/blockly-rc/core/utils/svg_math.ts +208 -0
  341. package/blockly-rc/core/utils/svg_paths.ts +133 -0
  342. package/blockly-rc/core/utils/toolbox.ts +419 -0
  343. package/blockly-rc/core/utils/useragent.ts +86 -0
  344. package/blockly-rc/core/utils/xml.ts +165 -0
  345. package/blockly-rc/core/utils.ts +59 -0
  346. package/blockly-rc/core/variable_map.ts +437 -0
  347. package/blockly-rc/core/variable_model.ts +149 -0
  348. package/blockly-rc/core/variables.ts +773 -0
  349. package/blockly-rc/core/variables_dynamic.ts +142 -0
  350. package/blockly-rc/core/widgetdiv.ts +319 -0
  351. package/blockly-rc/core/workspace.ts +957 -0
  352. package/blockly-rc/core/workspace_audio.ts +171 -0
  353. package/blockly-rc/core/workspace_dragger.ts +97 -0
  354. package/blockly-rc/core/workspace_svg.ts +2519 -0
  355. package/blockly-rc/core/xml.ts +1133 -0
  356. package/blockly-rc/core/zoom_controls.ts +492 -0
  357. package/blockly-rc/demos/blockfactory/analytics.js +195 -0
  358. package/blockly-rc/demos/blockfactory/app_controller.js +726 -0
  359. package/blockly-rc/demos/blockfactory/block_definition_extractor.js +742 -0
  360. package/blockly-rc/demos/blockfactory/block_exporter_controller.js +311 -0
  361. package/blockly-rc/demos/blockfactory/block_exporter_tools.js +212 -0
  362. package/blockly-rc/demos/blockfactory/block_exporter_view.js +101 -0
  363. package/blockly-rc/demos/blockfactory/block_library_controller.js +325 -0
  364. package/blockly-rc/demos/blockfactory/block_library_storage.js +149 -0
  365. package/blockly-rc/demos/blockfactory/block_library_view.js +178 -0
  366. package/blockly-rc/demos/blockfactory/block_option.js +151 -0
  367. package/blockly-rc/demos/blockfactory/blocks.js +916 -0
  368. package/blockly-rc/demos/blockfactory/cp.css +46 -0
  369. package/blockly-rc/demos/blockfactory/cp.js +179 -0
  370. package/blockly-rc/demos/blockfactory/factory.css +586 -0
  371. package/blockly-rc/demos/blockfactory/factory.js +337 -0
  372. package/blockly-rc/demos/blockfactory/factory_utils.js +1036 -0
  373. package/blockly-rc/demos/blockfactory/icon.png +0 -0
  374. package/blockly-rc/demos/blockfactory/index.html +767 -0
  375. package/blockly-rc/demos/blockfactory/link.png +0 -0
  376. package/blockly-rc/demos/blockfactory/standard_categories.js +384 -0
  377. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_controller.js +1332 -0
  378. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_generator.js +224 -0
  379. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_init.js +541 -0
  380. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_model.js +548 -0
  381. package/blockly-rc/demos/blockfactory/workspacefactory/wfactory_view.js +424 -0
  382. package/blockly-rc/demos/code/code.js +626 -0
  383. package/blockly-rc/demos/code/icon.png +0 -0
  384. package/blockly-rc/demos/code/icons.png +0 -0
  385. package/blockly-rc/demos/code/index.html +359 -0
  386. package/blockly-rc/demos/code/msg/ar.js +24 -0
  387. package/blockly-rc/demos/code/msg/be-tarask.js +24 -0
  388. package/blockly-rc/demos/code/msg/br.js +24 -0
  389. package/blockly-rc/demos/code/msg/ca.js +24 -0
  390. package/blockly-rc/demos/code/msg/cs.js +24 -0
  391. package/blockly-rc/demos/code/msg/da.js +24 -0
  392. package/blockly-rc/demos/code/msg/de.js +24 -0
  393. package/blockly-rc/demos/code/msg/el.js +24 -0
  394. package/blockly-rc/demos/code/msg/en.js +24 -0
  395. package/blockly-rc/demos/code/msg/es.js +24 -0
  396. package/blockly-rc/demos/code/msg/et.js +24 -0
  397. package/blockly-rc/demos/code/msg/fa.js +24 -0
  398. package/blockly-rc/demos/code/msg/fr.js +24 -0
  399. package/blockly-rc/demos/code/msg/he.js +24 -0
  400. package/blockly-rc/demos/code/msg/hr.js +24 -0
  401. package/blockly-rc/demos/code/msg/hrx.js +24 -0
  402. package/blockly-rc/demos/code/msg/hu.js +24 -0
  403. package/blockly-rc/demos/code/msg/ia.js +24 -0
  404. package/blockly-rc/demos/code/msg/is.js +24 -0
  405. package/blockly-rc/demos/code/msg/it.js +24 -0
  406. package/blockly-rc/demos/code/msg/ja.js +24 -0
  407. package/blockly-rc/demos/code/msg/kab.js +24 -0
  408. package/blockly-rc/demos/code/msg/ko.js +24 -0
  409. package/blockly-rc/demos/code/msg/mk.js +24 -0
  410. package/blockly-rc/demos/code/msg/ms.js +24 -0
  411. package/blockly-rc/demos/code/msg/nb.js +24 -0
  412. package/blockly-rc/demos/code/msg/nl.js +24 -0
  413. package/blockly-rc/demos/code/msg/oc.js +24 -0
  414. package/blockly-rc/demos/code/msg/pl.js +24 -0
  415. package/blockly-rc/demos/code/msg/pms.js +24 -0
  416. package/blockly-rc/demos/code/msg/pt-br.js +24 -0
  417. package/blockly-rc/demos/code/msg/ro.js +24 -0
  418. package/blockly-rc/demos/code/msg/ru.js +24 -0
  419. package/blockly-rc/demos/code/msg/sc.js +24 -0
  420. package/blockly-rc/demos/code/msg/sk.js +24 -0
  421. package/blockly-rc/demos/code/msg/sr.js +24 -0
  422. package/blockly-rc/demos/code/msg/sv.js +24 -0
  423. package/blockly-rc/demos/code/msg/ta.js +24 -0
  424. package/blockly-rc/demos/code/msg/th.js +24 -0
  425. package/blockly-rc/demos/code/msg/tlh.js +24 -0
  426. package/blockly-rc/demos/code/msg/tr.js +24 -0
  427. package/blockly-rc/demos/code/msg/uk.js +24 -0
  428. package/blockly-rc/demos/code/msg/vi.js +24 -0
  429. package/blockly-rc/demos/code/msg/zh-hans.js +24 -0
  430. package/blockly-rc/demos/code/msg/zh-hant.js +24 -0
  431. package/blockly-rc/demos/code/style.css +184 -0
  432. package/blockly-rc/demos/index.html +68 -0
  433. package/blockly-rc/demos/minimap/icon.png +0 -0
  434. package/blockly-rc/demos/minimap/index.html +91 -0
  435. package/blockly-rc/demos/minimap/minimap.js +302 -0
  436. package/blockly-rc/demos/mobile/README.md +53 -0
  437. package/blockly-rc/demos/mobile/android/README.md +45 -0
  438. package/blockly-rc/demos/mobile/android/app/build.gradle +64 -0
  439. package/blockly-rc/demos/mobile/android/app/proguard-rules.pro +21 -0
  440. package/blockly-rc/demos/mobile/android/app/src/androidTest/java/com/example/blocklywebview/ExampleInstrumentedTest.java +26 -0
  441. package/blockly-rc/demos/mobile/android/app/src/main/AndroidManifest.xml +21 -0
  442. package/blockly-rc/demos/mobile/android/app/src/main/java/com/google/blockly/android/webview/BlocklyWebViewFragment.java +40 -0
  443. package/blockly-rc/demos/mobile/android/app/src/main/java/com/google/blockly/android/webview/JsDialogHelper.java +150 -0
  444. package/blockly-rc/demos/mobile/android/app/src/main/java/com/google/blockly/android/webview/WebChromeClient.java +32 -0
  445. package/blockly-rc/demos/mobile/android/app/src/main/java/com/google/blockly/android/webview/demo/MainActivity.java +18 -0
  446. package/blockly-rc/demos/mobile/android/app/src/main/res/drawable/ic_launcher_background.xml +74 -0
  447. package/blockly-rc/demos/mobile/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +34 -0
  448. package/blockly-rc/demos/mobile/android/app/src/main/res/layout/activity_main.xml +17 -0
  449. package/blockly-rc/demos/mobile/android/app/src/main/res/layout/js_prompt.xml +37 -0
  450. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +5 -0
  451. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +5 -0
  452. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  453. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  454. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  455. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  456. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  457. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  458. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  459. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  460. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  461. package/blockly-rc/demos/mobile/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  462. package/blockly-rc/demos/mobile/android/app/src/main/res/values/colors.xml +6 -0
  463. package/blockly-rc/demos/mobile/android/app/src/main/res/values/js_dialog_helper.xml +7 -0
  464. package/blockly-rc/demos/mobile/android/app/src/main/res/values/strings.xml +3 -0
  465. package/blockly-rc/demos/mobile/android/app/src/main/res/values/styles.xml +11 -0
  466. package/blockly-rc/demos/mobile/android/app/src/test/java/com/example/blocklywebview/ExampleUnitTest.java +17 -0
  467. package/blockly-rc/demos/mobile/android/build.gradle +27 -0
  468. package/blockly-rc/demos/mobile/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  469. package/blockly-rc/demos/mobile/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  470. package/blockly-rc/demos/mobile/android/gradle.properties +13 -0
  471. package/blockly-rc/demos/mobile/android/gradlew +172 -0
  472. package/blockly-rc/demos/mobile/android/gradlew.bat +84 -0
  473. package/blockly-rc/demos/mobile/android/settings.gradle +1 -0
  474. package/blockly-rc/demos/mobile/html/index.html +31 -0
  475. package/blockly-rc/demos/mobile/html/ln_resources.sh +22 -0
  476. package/blockly-rc/demos/mobile/html/toolbox_standard.js +333 -0
  477. package/blockly-rc/demos/mobile/ios/Blockly WebView/AppDelegate.swift +46 -0
  478. package/blockly-rc/demos/mobile/ios/Blockly WebView/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  479. package/blockly-rc/demos/mobile/ios/Blockly WebView/Assets.xcassets/Contents.json +6 -0
  480. package/blockly-rc/demos/mobile/ios/Blockly WebView/Base.lproj/LaunchScreen.storyboard +25 -0
  481. package/blockly-rc/demos/mobile/ios/Blockly WebView/Base.lproj/Main.storyboard +44 -0
  482. package/blockly-rc/demos/mobile/ios/Blockly WebView/Info.plist +45 -0
  483. package/blockly-rc/demos/mobile/ios/Blockly WebView/ViewController.swift +110 -0
  484. package/blockly-rc/demos/mobile/ios/Blockly WebView.xcodeproj/project.pbxproj +390 -0
  485. package/blockly-rc/demos/mobile/ios/Blockly WebView.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  486. package/blockly-rc/demos/mobile/ios/Blockly WebView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  487. package/blockly-rc/demos/mobile/ios/cp_resources.sh +21 -0
  488. package/blockly-rc/demos/storage/icon.png +0 -0
  489. package/blockly-rc/demos/storage/index.html +104 -0
  490. package/blockly-rc/generators/dart/dart_generator.ts +321 -0
  491. package/blockly-rc/generators/dart/lists.ts +525 -0
  492. package/blockly-rc/generators/dart/logic.ts +155 -0
  493. package/blockly-rc/generators/dart/loops.ts +217 -0
  494. package/blockly-rc/generators/dart/math.ts +559 -0
  495. package/blockly-rc/generators/dart/procedures.ts +138 -0
  496. package/blockly-rc/generators/dart/text.ts +405 -0
  497. package/blockly-rc/generators/dart/variables.ts +32 -0
  498. package/blockly-rc/generators/dart/variables_dynamic.ts +17 -0
  499. package/blockly-rc/generators/dart.ts +50 -0
  500. package/blockly-rc/generators/javascript/javascript_generator.ts +346 -0
  501. package/blockly-rc/generators/javascript/lists.ts +465 -0
  502. package/blockly-rc/generators/javascript/logic.ts +153 -0
  503. package/blockly-rc/generators/javascript/loops.ts +245 -0
  504. package/blockly-rc/generators/javascript/math.ts +450 -0
  505. package/blockly-rc/generators/javascript/procedures.ts +142 -0
  506. package/blockly-rc/generators/javascript/text.ts +418 -0
  507. package/blockly-rc/generators/javascript/variables.ts +32 -0
  508. package/blockly-rc/generators/javascript/variables_dynamic.ts +17 -0
  509. package/blockly-rc/generators/javascript.ts +46 -0
  510. package/blockly-rc/generators/lua/lists.ts +445 -0
  511. package/blockly-rc/generators/lua/logic.ts +142 -0
  512. package/blockly-rc/generators/lua/loops.ts +192 -0
  513. package/blockly-rc/generators/lua/lua_generator.ts +225 -0
  514. package/blockly-rc/generators/lua/math.ts +473 -0
  515. package/blockly-rc/generators/lua/procedures.ts +144 -0
  516. package/blockly-rc/generators/lua/text.ts +380 -0
  517. package/blockly-rc/generators/lua/variables.ts +31 -0
  518. package/blockly-rc/generators/lua/variables_dynamic.ts +17 -0
  519. package/blockly-rc/generators/lua.ts +44 -0
  520. package/blockly-rc/generators/php/lists.ts +585 -0
  521. package/blockly-rc/generators/php/logic.ts +155 -0
  522. package/blockly-rc/generators/php/loops.ts +218 -0
  523. package/blockly-rc/generators/php/math.ts +408 -0
  524. package/blockly-rc/generators/php/php_generator.ts +320 -0
  525. package/blockly-rc/generators/php/procedures.ts +159 -0
  526. package/blockly-rc/generators/php/text.ts +315 -0
  527. package/blockly-rc/generators/php/variables.ts +32 -0
  528. package/blockly-rc/generators/php/variables_dynamic.ts +17 -0
  529. package/blockly-rc/generators/php.ts +46 -0
  530. package/blockly-rc/generators/python/lists.ts +398 -0
  531. package/blockly-rc/generators/python/logic.ts +148 -0
  532. package/blockly-rc/generators/python/loops.ts +251 -0
  533. package/blockly-rc/generators/python/math.ts +434 -0
  534. package/blockly-rc/generators/python/procedures.ts +159 -0
  535. package/blockly-rc/generators/python/python_generator.ts +355 -0
  536. package/blockly-rc/generators/python/text.ts +338 -0
  537. package/blockly-rc/generators/python/variables.ts +31 -0
  538. package/blockly-rc/generators/python/variables_dynamic.ts +17 -0
  539. package/blockly-rc/generators/python.ts +51 -0
  540. package/blockly-rc/gulpfile.js +54 -0
  541. package/blockly-rc/jsconfig.json +7 -0
  542. package/blockly-rc/media/1x1.gif +0 -0
  543. package/blockly-rc/media/click.mp3 +0 -0
  544. package/blockly-rc/media/click.ogg +0 -0
  545. package/blockly-rc/media/click.wav +0 -0
  546. package/blockly-rc/media/delete-icon.svg +1 -0
  547. package/blockly-rc/media/delete.mp3 +0 -0
  548. package/blockly-rc/media/delete.ogg +0 -0
  549. package/blockly-rc/media/delete.wav +0 -0
  550. package/blockly-rc/media/disconnect.mp3 +0 -0
  551. package/blockly-rc/media/disconnect.ogg +0 -0
  552. package/blockly-rc/media/disconnect.wav +0 -0
  553. package/blockly-rc/media/dropdown-arrow.svg +1 -0
  554. package/blockly-rc/media/foldout-icon.svg +1 -0
  555. package/blockly-rc/media/handclosed.cur +0 -0
  556. package/blockly-rc/media/handdelete.cur +0 -0
  557. package/blockly-rc/media/handopen.cur +0 -0
  558. package/blockly-rc/media/pilcrow.png +0 -0
  559. package/blockly-rc/media/quote0.png +0 -0
  560. package/blockly-rc/media/quote1.png +0 -0
  561. package/blockly-rc/media/resize-handle.svg +3 -0
  562. package/blockly-rc/media/sprites.png +0 -0
  563. package/blockly-rc/media/sprites.svg +74 -0
  564. package/blockly-rc/msg/json/README.md +33 -0
  565. package/blockly-rc/msg/json/ab.json +222 -0
  566. package/blockly-rc/msg/json/ace.json +7 -0
  567. package/blockly-rc/msg/json/af.json +34 -0
  568. package/blockly-rc/msg/json/am.json +30 -0
  569. package/blockly-rc/msg/json/ar.json +355 -0
  570. package/blockly-rc/msg/json/ast.json +10 -0
  571. package/blockly-rc/msg/json/az.json +332 -0
  572. package/blockly-rc/msg/json/ba.json +211 -0
  573. package/blockly-rc/msg/json/bcc.json +290 -0
  574. package/blockly-rc/msg/json/be-tarask.json +334 -0
  575. package/blockly-rc/msg/json/be.json +324 -0
  576. package/blockly-rc/msg/json/bg.json +345 -0
  577. package/blockly-rc/msg/json/bn.json +189 -0
  578. package/blockly-rc/msg/json/br.json +334 -0
  579. package/blockly-rc/msg/json/bs.json +166 -0
  580. package/blockly-rc/msg/json/ca.json +341 -0
  581. package/blockly-rc/msg/json/cdo.json +6 -0
  582. package/blockly-rc/msg/json/ce.json +326 -0
  583. package/blockly-rc/msg/json/constants.json +12 -0
  584. package/blockly-rc/msg/json/cs.json +343 -0
  585. package/blockly-rc/msg/json/da.json +346 -0
  586. package/blockly-rc/msg/json/de.json +369 -0
  587. package/blockly-rc/msg/json/diq.json +258 -0
  588. package/blockly-rc/msg/json/dtp.json +198 -0
  589. package/blockly-rc/msg/json/dty.json +97 -0
  590. package/blockly-rc/msg/json/ee.json +160 -0
  591. package/blockly-rc/msg/json/el.json +356 -0
  592. package/blockly-rc/msg/json/en-gb.json +199 -0
  593. package/blockly-rc/msg/json/en.json +400 -0
  594. package/blockly-rc/msg/json/eo.json +337 -0
  595. package/blockly-rc/msg/json/es.json +358 -0
  596. package/blockly-rc/msg/json/et.json +326 -0
  597. package/blockly-rc/msg/json/eu.json +219 -0
  598. package/blockly-rc/msg/json/fa.json +341 -0
  599. package/blockly-rc/msg/json/fi.json +350 -0
  600. package/blockly-rc/msg/json/fo.json +46 -0
  601. package/blockly-rc/msg/json/fr.json +373 -0
  602. package/blockly-rc/msg/json/frr.json +6 -0
  603. package/blockly-rc/msg/json/gl.json +338 -0
  604. package/blockly-rc/msg/json/gn.json +54 -0
  605. package/blockly-rc/msg/json/gor.json +87 -0
  606. package/blockly-rc/msg/json/ha.json +313 -0
  607. package/blockly-rc/msg/json/hak.json +17 -0
  608. package/blockly-rc/msg/json/he.json +354 -0
  609. package/blockly-rc/msg/json/hi.json +318 -0
  610. package/blockly-rc/msg/json/hr.json +327 -0
  611. package/blockly-rc/msg/json/hrx.json +287 -0
  612. package/blockly-rc/msg/json/hsb.json +128 -0
  613. package/blockly-rc/msg/json/hu.json +349 -0
  614. package/blockly-rc/msg/json/hy.json +337 -0
  615. package/blockly-rc/msg/json/ia.json +337 -0
  616. package/blockly-rc/msg/json/id.json +335 -0
  617. package/blockly-rc/msg/json/ig.json +323 -0
  618. package/blockly-rc/msg/json/inh.json +80 -0
  619. package/blockly-rc/msg/json/is.json +331 -0
  620. package/blockly-rc/msg/json/it.json +346 -0
  621. package/blockly-rc/msg/json/ja.json +361 -0
  622. package/blockly-rc/msg/json/ka.json +14 -0
  623. package/blockly-rc/msg/json/kab.json +323 -0
  624. package/blockly-rc/msg/json/kbd-cyrl.json +84 -0
  625. package/blockly-rc/msg/json/km.json +29 -0
  626. package/blockly-rc/msg/json/kn.json +332 -0
  627. package/blockly-rc/msg/json/ko.json +372 -0
  628. package/blockly-rc/msg/json/ksh.json +43 -0
  629. package/blockly-rc/msg/json/ku-latn.json +41 -0
  630. package/blockly-rc/msg/json/ky.json +71 -0
  631. package/blockly-rc/msg/json/la.json +6 -0
  632. package/blockly-rc/msg/json/lb.json +156 -0
  633. package/blockly-rc/msg/json/lki.json +282 -0
  634. package/blockly-rc/msg/json/lo.json +92 -0
  635. package/blockly-rc/msg/json/lrc.json +123 -0
  636. package/blockly-rc/msg/json/lt.json +321 -0
  637. package/blockly-rc/msg/json/lv.json +324 -0
  638. package/blockly-rc/msg/json/mg.json +58 -0
  639. package/blockly-rc/msg/json/mk.json +178 -0
  640. package/blockly-rc/msg/json/ml.json +35 -0
  641. package/blockly-rc/msg/json/mnw.json +90 -0
  642. package/blockly-rc/msg/json/ms.json +300 -0
  643. package/blockly-rc/msg/json/my.json +57 -0
  644. package/blockly-rc/msg/json/mzn.json +6 -0
  645. package/blockly-rc/msg/json/nb.json +330 -0
  646. package/blockly-rc/msg/json/ne.json +247 -0
  647. package/blockly-rc/msg/json/nl.json +357 -0
  648. package/blockly-rc/msg/json/oc.json +194 -0
  649. package/blockly-rc/msg/json/olo.json +37 -0
  650. package/blockly-rc/msg/json/pa.json +69 -0
  651. package/blockly-rc/msg/json/pl.json +357 -0
  652. package/blockly-rc/msg/json/pms.json +324 -0
  653. package/blockly-rc/msg/json/ps.json +50 -0
  654. package/blockly-rc/msg/json/pt-br.json +369 -0
  655. package/blockly-rc/msg/json/pt.json +358 -0
  656. package/blockly-rc/msg/json/qqq.json +406 -0
  657. package/blockly-rc/msg/json/ro.json +333 -0
  658. package/blockly-rc/msg/json/ru.json +363 -0
  659. package/blockly-rc/msg/json/sc.json +283 -0
  660. package/blockly-rc/msg/json/sco.json +11 -0
  661. package/blockly-rc/msg/json/sd.json +158 -0
  662. package/blockly-rc/msg/json/shn.json +109 -0
  663. package/blockly-rc/msg/json/si.json +16 -0
  664. package/blockly-rc/msg/json/sk.json +332 -0
  665. package/blockly-rc/msg/json/skr-arab.json +117 -0
  666. package/blockly-rc/msg/json/sl.json +355 -0
  667. package/blockly-rc/msg/json/smn.json +133 -0
  668. package/blockly-rc/msg/json/sq.json +343 -0
  669. package/blockly-rc/msg/json/sr-latn.json +324 -0
  670. package/blockly-rc/msg/json/sr.json +348 -0
  671. package/blockly-rc/msg/json/sv.json +347 -0
  672. package/blockly-rc/msg/json/sw.json +12 -0
  673. package/blockly-rc/msg/json/synonyms.json +22 -0
  674. package/blockly-rc/msg/json/ta.json +306 -0
  675. package/blockly-rc/msg/json/tcy.json +316 -0
  676. package/blockly-rc/msg/json/tdd.json +109 -0
  677. package/blockly-rc/msg/json/te.json +101 -0
  678. package/blockly-rc/msg/json/th.json +333 -0
  679. package/blockly-rc/msg/json/ti.json +50 -0
  680. package/blockly-rc/msg/json/tl.json +129 -0
  681. package/blockly-rc/msg/json/tlh.json +179 -0
  682. package/blockly-rc/msg/json/tr.json +369 -0
  683. package/blockly-rc/msg/json/ug-arab.json +132 -0
  684. package/blockly-rc/msg/json/uk.json +345 -0
  685. package/blockly-rc/msg/json/ur.json +117 -0
  686. package/blockly-rc/msg/json/uz.json +36 -0
  687. package/blockly-rc/msg/json/vi.json +345 -0
  688. package/blockly-rc/msg/json/xmf.json +96 -0
  689. package/blockly-rc/msg/json/yo.json +316 -0
  690. package/blockly-rc/msg/json/zgh.json +83 -0
  691. package/blockly-rc/msg/json/zh-hans.json +372 -0
  692. package/blockly-rc/msg/json/zh-hant.json +362 -0
  693. package/blockly-rc/msg/messages.js +1616 -0
  694. package/blockly-rc/package-lock.json +12324 -0
  695. package/blockly-rc/package.json +149 -0
  696. package/blockly-rc/patches/@microsoft+api-documenter+7.22.4.patch +81 -0
  697. package/blockly-rc/scripts/goog_module/convert-file.sh +406 -0
  698. package/blockly-rc/scripts/gulpfiles/appengine_tasks.js +195 -0
  699. package/blockly-rc/scripts/gulpfiles/build_tasks.js +752 -0
  700. package/blockly-rc/scripts/gulpfiles/config.js +41 -0
  701. package/blockly-rc/scripts/gulpfiles/docs_tasks.js +147 -0
  702. package/blockly-rc/scripts/gulpfiles/git_tasks.js +181 -0
  703. package/blockly-rc/scripts/gulpfiles/helper_tasks.js +19 -0
  704. package/blockly-rc/scripts/gulpfiles/package_tasks.js +262 -0
  705. package/blockly-rc/scripts/gulpfiles/release_tasks.js +183 -0
  706. package/blockly-rc/scripts/gulpfiles/test_tasks.js +405 -0
  707. package/blockly-rc/scripts/helpers.js +74 -0
  708. package/blockly-rc/scripts/i18n/common.py +233 -0
  709. package/blockly-rc/scripts/i18n/create_messages.py +167 -0
  710. package/blockly-rc/scripts/i18n/dedup_json.py +72 -0
  711. package/blockly-rc/scripts/i18n/js_to_json.py +135 -0
  712. package/blockly-rc/scripts/i18n/tests.py +46 -0
  713. package/blockly-rc/scripts/migration/cjs2esm +162 -0
  714. package/blockly-rc/scripts/migration/js2ts +168 -0
  715. package/blockly-rc/scripts/migration/renamings.json5 +1599 -0
  716. package/blockly-rc/scripts/package/README.md +93 -0
  717. package/blockly-rc/scripts/package/core-node.js +31 -0
  718. package/blockly-rc/scripts/package/index.js +23 -0
  719. package/blockly-rc/scripts/package/templates/umd-msg.template +16 -0
  720. package/blockly-rc/scripts/package/templates/umd.template +13 -0
  721. package/blockly-rc/scripts/themes/blockStyles_example.json +11 -0
  722. package/blockly-rc/scripts/themes/create_blockStyles.py +181 -0
  723. package/blockly-rc/scripts/tsick.js +86 -0
  724. package/blockly-rc/tests/.eslintrc.json +10 -0
  725. package/blockly-rc/tests/browser/.eslintrc.json +29 -0
  726. package/blockly-rc/tests/browser/.mocharc.js +6 -0
  727. package/blockly-rc/tests/browser/test/basic_block_factory_test.mjs +44 -0
  728. package/blockly-rc/tests/browser/test/basic_block_test.mjs +39 -0
  729. package/blockly-rc/tests/browser/test/basic_playground_test.mjs +198 -0
  730. package/blockly-rc/tests/browser/test/block_undo_test.mjs +50 -0
  731. package/blockly-rc/tests/browser/test/delete_blocks_test.mjs +211 -0
  732. package/blockly-rc/tests/browser/test/extensive_test.mjs +195 -0
  733. package/blockly-rc/tests/browser/test/field_edits_test.mjs +61 -0
  734. package/blockly-rc/tests/browser/test/hooks.mjs +23 -0
  735. package/blockly-rc/tests/browser/test/mutator_test.mjs +88 -0
  736. package/blockly-rc/tests/browser/test/procedure_test.mjs +109 -0
  737. package/blockly-rc/tests/browser/test/test_setup.mjs +589 -0
  738. package/blockly-rc/tests/browser/test/toolbox_drag_test.mjs +207 -0
  739. package/blockly-rc/tests/browser/test/workspace_comment_test.mjs +224 -0
  740. package/blockly-rc/tests/compile/index.html +43 -0
  741. package/blockly-rc/tests/compile/main.js +53 -0
  742. package/blockly-rc/tests/compile/test_blocks.js +47 -0
  743. package/blockly-rc/tests/compile/webdriver.js +81 -0
  744. package/blockly-rc/tests/generators/functions.xml +561 -0
  745. package/blockly-rc/tests/generators/golden/generated.dart +1604 -0
  746. package/blockly-rc/tests/generators/golden/generated.js +1552 -0
  747. package/blockly-rc/tests/generators/golden/generated.lua +1828 -0
  748. package/blockly-rc/tests/generators/golden/generated.php +1611 -0
  749. package/blockly-rc/tests/generators/golden/generated.py +1407 -0
  750. package/blockly-rc/tests/generators/index.html +405 -0
  751. package/blockly-rc/tests/generators/lists.xml +8675 -0
  752. package/blockly-rc/tests/generators/logic.xml +1019 -0
  753. package/blockly-rc/tests/generators/loops1.xml +345 -0
  754. package/blockly-rc/tests/generators/loops2.xml +891 -0
  755. package/blockly-rc/tests/generators/loops3.xml +735 -0
  756. package/blockly-rc/tests/generators/math.xml +2077 -0
  757. package/blockly-rc/tests/generators/text.xml +4651 -0
  758. package/blockly-rc/tests/generators/unittest.js +103 -0
  759. package/blockly-rc/tests/generators/unittest_dart.js +163 -0
  760. package/blockly-rc/tests/generators/unittest_javascript.js +167 -0
  761. package/blockly-rc/tests/generators/unittest_lua.js +165 -0
  762. package/blockly-rc/tests/generators/unittest_php.js +154 -0
  763. package/blockly-rc/tests/generators/unittest_python.js +138 -0
  764. package/blockly-rc/tests/generators/variables.xml +68 -0
  765. package/blockly-rc/tests/generators/webdriver.js +123 -0
  766. package/blockly-rc/tests/media/200px.png +0 -0
  767. package/blockly-rc/tests/media/30px.png +0 -0
  768. package/blockly-rc/tests/media/50px.png +0 -0
  769. package/blockly-rc/tests/media/a.png +0 -0
  770. package/blockly-rc/tests/media/arrow.png +0 -0
  771. package/blockly-rc/tests/media/b.png +0 -0
  772. package/blockly-rc/tests/media/c.png +0 -0
  773. package/blockly-rc/tests/media/d.png +0 -0
  774. package/blockly-rc/tests/media/e.png +0 -0
  775. package/blockly-rc/tests/media/f.png +0 -0
  776. package/blockly-rc/tests/media/g.png +0 -0
  777. package/blockly-rc/tests/media/h.png +0 -0
  778. package/blockly-rc/tests/media/i.png +0 -0
  779. package/blockly-rc/tests/media/j.png +0 -0
  780. package/blockly-rc/tests/media/k.png +0 -0
  781. package/blockly-rc/tests/media/l.png +0 -0
  782. package/blockly-rc/tests/media/m.png +0 -0
  783. package/blockly-rc/tests/migration/renamings.schema.json +59 -0
  784. package/blockly-rc/tests/migration/validate-renamings.mjs +60 -0
  785. package/blockly-rc/tests/mocha/.eslintrc.json +21 -0
  786. package/blockly-rc/tests/mocha/.mocharc.js +6 -0
  787. package/blockly-rc/tests/mocha/astnode_test.js +850 -0
  788. package/blockly-rc/tests/mocha/block_json_test.js +777 -0
  789. package/blockly-rc/tests/mocha/block_test.js +2743 -0
  790. package/blockly-rc/tests/mocha/blocks/lists_test.js +196 -0
  791. package/blockly-rc/tests/mocha/blocks/logic_ternary_test.js +320 -0
  792. package/blockly-rc/tests/mocha/blocks/loops_test.js +56 -0
  793. package/blockly-rc/tests/mocha/blocks/procedures_test.js +2495 -0
  794. package/blockly-rc/tests/mocha/blocks/variables_test.js +311 -0
  795. package/blockly-rc/tests/mocha/clipboard_test.js +136 -0
  796. package/blockly-rc/tests/mocha/comment_deserialization_test.js +122 -0
  797. package/blockly-rc/tests/mocha/comment_test.js +170 -0
  798. package/blockly-rc/tests/mocha/comment_view_test.js +188 -0
  799. package/blockly-rc/tests/mocha/connection_checker_test.js +666 -0
  800. package/blockly-rc/tests/mocha/connection_db_test.js +362 -0
  801. package/blockly-rc/tests/mocha/connection_test.js +3738 -0
  802. package/blockly-rc/tests/mocha/contextmenu_items_test.js +488 -0
  803. package/blockly-rc/tests/mocha/contextmenu_test.js +71 -0
  804. package/blockly-rc/tests/mocha/cursor_test.js +134 -0
  805. package/blockly-rc/tests/mocha/dropdowndiv_test.js +116 -0
  806. package/blockly-rc/tests/mocha/event_block_change_test.js +126 -0
  807. package/blockly-rc/tests/mocha/event_block_create_test.js +109 -0
  808. package/blockly-rc/tests/mocha/event_block_delete_test.js +55 -0
  809. package/blockly-rc/tests/mocha/event_block_drag_test.js +36 -0
  810. package/blockly-rc/tests/mocha/event_block_field_intermediate_change_test.js +67 -0
  811. package/blockly-rc/tests/mocha/event_block_move_test.js +39 -0
  812. package/blockly-rc/tests/mocha/event_bubble_open_test.js +42 -0
  813. package/blockly-rc/tests/mocha/event_click_test.js +40 -0
  814. package/blockly-rc/tests/mocha/event_comment_change_test.js +39 -0
  815. package/blockly-rc/tests/mocha/event_comment_collapse_test.js +34 -0
  816. package/blockly-rc/tests/mocha/event_comment_create_test.js +38 -0
  817. package/blockly-rc/tests/mocha/event_comment_delete_test.js +38 -0
  818. package/blockly-rc/tests/mocha/event_comment_drag_test.js +35 -0
  819. package/blockly-rc/tests/mocha/event_comment_move_test.js +40 -0
  820. package/blockly-rc/tests/mocha/event_comment_resize_test.js +38 -0
  821. package/blockly-rc/tests/mocha/event_marker_move_test.js +44 -0
  822. package/blockly-rc/tests/mocha/event_selected_test.js +41 -0
  823. package/blockly-rc/tests/mocha/event_test.js +1578 -0
  824. package/blockly-rc/tests/mocha/event_theme_change_test.js +36 -0
  825. package/blockly-rc/tests/mocha/event_toolbox_item_select_test.js +64 -0
  826. package/blockly-rc/tests/mocha/event_trashcan_open_test.js +36 -0
  827. package/blockly-rc/tests/mocha/event_var_create_test.js +54 -0
  828. package/blockly-rc/tests/mocha/event_var_delete_test.js +54 -0
  829. package/blockly-rc/tests/mocha/event_var_rename_test.js +39 -0
  830. package/blockly-rc/tests/mocha/event_var_type_change_test.js +43 -0
  831. package/blockly-rc/tests/mocha/event_viewport_test.js +39 -0
  832. package/blockly-rc/tests/mocha/extensions_test.js +613 -0
  833. package/blockly-rc/tests/mocha/field_checkbox_test.js +299 -0
  834. package/blockly-rc/tests/mocha/field_colour_test.js +395 -0
  835. package/blockly-rc/tests/mocha/field_dropdown_test.js +282 -0
  836. package/blockly-rc/tests/mocha/field_image_test.js +241 -0
  837. package/blockly-rc/tests/mocha/field_label_serializable_test.js +252 -0
  838. package/blockly-rc/tests/mocha/field_label_test.js +226 -0
  839. package/blockly-rc/tests/mocha/field_number_test.js +505 -0
  840. package/blockly-rc/tests/mocha/field_registry_test.js +116 -0
  841. package/blockly-rc/tests/mocha/field_test.js +822 -0
  842. package/blockly-rc/tests/mocha/field_textinput_test.js +297 -0
  843. package/blockly-rc/tests/mocha/field_variable_test.js +611 -0
  844. package/blockly-rc/tests/mocha/flyout_test.js +638 -0
  845. package/blockly-rc/tests/mocha/generator_test.js +233 -0
  846. package/blockly-rc/tests/mocha/gesture_test.js +97 -0
  847. package/blockly-rc/tests/mocha/icon_test.js +369 -0
  848. package/blockly-rc/tests/mocha/index.html +229 -0
  849. package/blockly-rc/tests/mocha/input_test.js +296 -0
  850. package/blockly-rc/tests/mocha/insertion_marker_manager_test.js +443 -0
  851. package/blockly-rc/tests/mocha/insertion_marker_test.js +432 -0
  852. package/blockly-rc/tests/mocha/jso_deserialization_test.js +849 -0
  853. package/blockly-rc/tests/mocha/jso_serialization_test.js +1067 -0
  854. package/blockly-rc/tests/mocha/json_test.js +315 -0
  855. package/blockly-rc/tests/mocha/keydown_test.js +364 -0
  856. package/blockly-rc/tests/mocha/layering_test.js +95 -0
  857. package/blockly-rc/tests/mocha/metrics_test.js +671 -0
  858. package/blockly-rc/tests/mocha/mutator_test.js +87 -0
  859. package/blockly-rc/tests/mocha/names_test.js +97 -0
  860. package/blockly-rc/tests/mocha/old_workspace_comment_test.js +256 -0
  861. package/blockly-rc/tests/mocha/procedure_map_test.js +57 -0
  862. package/blockly-rc/tests/mocha/registry_test.js +281 -0
  863. package/blockly-rc/tests/mocha/render_management_test.js +127 -0
  864. package/blockly-rc/tests/mocha/serializer_test.js +2104 -0
  865. package/blockly-rc/tests/mocha/shortcut_registry_test.js +450 -0
  866. package/blockly-rc/tests/mocha/test_helpers/block_definitions.js +204 -0
  867. package/blockly-rc/tests/mocha/test_helpers/code_generation.js +115 -0
  868. package/blockly-rc/tests/mocha/test_helpers/common.js +106 -0
  869. package/blockly-rc/tests/mocha/test_helpers/events.js +290 -0
  870. package/blockly-rc/tests/mocha/test_helpers/fields.js +310 -0
  871. package/blockly-rc/tests/mocha/test_helpers/icon_mocks.js +81 -0
  872. package/blockly-rc/tests/mocha/test_helpers/procedures.js +302 -0
  873. package/blockly-rc/tests/mocha/test_helpers/serialization.js +124 -0
  874. package/blockly-rc/tests/mocha/test_helpers/setup_teardown.js +209 -0
  875. package/blockly-rc/tests/mocha/test_helpers/toolbox_definitions.js +271 -0
  876. package/blockly-rc/tests/mocha/test_helpers/user_input.js +62 -0
  877. package/blockly-rc/tests/mocha/test_helpers/variables.js +23 -0
  878. package/blockly-rc/tests/mocha/test_helpers/warnings.js +83 -0
  879. package/blockly-rc/tests/mocha/test_helpers/workspace.js +1691 -0
  880. package/blockly-rc/tests/mocha/theme_test.js +307 -0
  881. package/blockly-rc/tests/mocha/toolbox_test.js +761 -0
  882. package/blockly-rc/tests/mocha/tooltip_test.js +276 -0
  883. package/blockly-rc/tests/mocha/touch_test.js +109 -0
  884. package/blockly-rc/tests/mocha/trashcan_test.js +375 -0
  885. package/blockly-rc/tests/mocha/utils_test.js +536 -0
  886. package/blockly-rc/tests/mocha/variable_map_test.js +509 -0
  887. package/blockly-rc/tests/mocha/variable_model_test.js +85 -0
  888. package/blockly-rc/tests/mocha/webdriver.js +96 -0
  889. package/blockly-rc/tests/mocha/widget_div_test.js +272 -0
  890. package/blockly-rc/tests/mocha/workspace_comment_test.js +171 -0
  891. package/blockly-rc/tests/mocha/workspace_svg_test.js +414 -0
  892. package/blockly-rc/tests/mocha/workspace_test.js +27 -0
  893. package/blockly-rc/tests/mocha/xml_test.js +951 -0
  894. package/blockly-rc/tests/mocha/zoom_controls_test.js +81 -0
  895. package/blockly-rc/tests/multi_playground.html +482 -0
  896. package/blockly-rc/tests/node/.eslintrc.json +12 -0
  897. package/blockly-rc/tests/node/.mocharc.js +6 -0
  898. package/blockly-rc/tests/node/run_node_test.mjs +72 -0
  899. package/blockly-rc/tests/playground.html +1280 -0
  900. package/blockly-rc/tests/playgrounds/advanced_playground.html +158 -0
  901. package/blockly-rc/tests/playgrounds/iframe.html +40 -0
  902. package/blockly-rc/tests/playgrounds/screenshot.js +123 -0
  903. package/blockly-rc/tests/scripts/check_metadata.sh +166 -0
  904. package/blockly-rc/tests/scripts/compile_typings.sh +32 -0
  905. package/blockly-rc/tests/scripts/load.mjs +140 -0
  906. package/blockly-rc/tests/scripts/setup_linux_env.sh +7 -0
  907. package/blockly-rc/tests/scripts/update_metadata.sh +46 -0
  908. package/blockly-rc/tests/themes/test_themes.js +62 -0
  909. package/blockly-rc/tests/typescript/README.md +4 -0
  910. package/blockly-rc/tests/typescript/src/field/different_user_input.ts +81 -0
  911. package/blockly-rc/tests/typescript/src/generators/dart.ts +24 -0
  912. package/blockly-rc/tests/typescript/src/generators/javascript.ts +28 -0
  913. package/blockly-rc/tests/typescript/src/generators/lua.ts +24 -0
  914. package/blockly-rc/tests/typescript/src/generators/php.ts +24 -0
  915. package/blockly-rc/tests/typescript/src/generators/python.ts +24 -0
  916. package/blockly-rc/tests/typescript/src/generators.ts +31 -0
  917. package/blockly-rc/tests/typescript/src/msg.ts +20 -0
  918. package/blockly-rc/tests/typescript/tsconfig.json +20 -0
  919. package/blockly-rc/tests/xml/README.txt +11 -0
  920. package/blockly-rc/tests/xml/blockly.xsd +178 -0
  921. package/blockly-rc/tests/xml/invalid.xml +6 -0
  922. package/blockly-rc/tests/xml/toolbox.xml +311 -0
  923. package/blockly-rc/tests/xml/workspace.xml +114 -0
  924. package/blockly-rc/tsconfig.json +37 -0
  925. package/blockly-rc/tsdoc.json +35 -0
  926. package/blockly-rc/typings/README.md +5 -0
  927. package/blockly-rc/typings/blocks.d.ts +17 -0
  928. package/blockly-rc/typings/core.d.ts +7 -0
  929. package/blockly-rc/typings/dart.d.ts +7 -0
  930. package/blockly-rc/typings/index.d.ts +10 -0
  931. package/blockly-rc/typings/javascript.d.ts +7 -0
  932. package/blockly-rc/typings/lua.d.ts +7 -0
  933. package/blockly-rc/typings/msg/ab.d.ts +8 -0
  934. package/blockly-rc/typings/msg/ace.d.ts +8 -0
  935. package/blockly-rc/typings/msg/af.d.ts +8 -0
  936. package/blockly-rc/typings/msg/am.d.ts +8 -0
  937. package/blockly-rc/typings/msg/ar.d.ts +8 -0
  938. package/blockly-rc/typings/msg/ast.d.ts +8 -0
  939. package/blockly-rc/typings/msg/az.d.ts +8 -0
  940. package/blockly-rc/typings/msg/ba.d.ts +8 -0
  941. package/blockly-rc/typings/msg/bcc.d.ts +8 -0
  942. package/blockly-rc/typings/msg/be-tarask.d.ts +8 -0
  943. package/blockly-rc/typings/msg/be.d.ts +8 -0
  944. package/blockly-rc/typings/msg/bg.d.ts +8 -0
  945. package/blockly-rc/typings/msg/bn.d.ts +8 -0
  946. package/blockly-rc/typings/msg/br.d.ts +8 -0
  947. package/blockly-rc/typings/msg/bs.d.ts +8 -0
  948. package/blockly-rc/typings/msg/ca.d.ts +8 -0
  949. package/blockly-rc/typings/msg/cdo.d.ts +8 -0
  950. package/blockly-rc/typings/msg/ce.d.ts +8 -0
  951. package/blockly-rc/typings/msg/cs.d.ts +8 -0
  952. package/blockly-rc/typings/msg/da.d.ts +8 -0
  953. package/blockly-rc/typings/msg/de.d.ts +8 -0
  954. package/blockly-rc/typings/msg/diq.d.ts +8 -0
  955. package/blockly-rc/typings/msg/dtp.d.ts +8 -0
  956. package/blockly-rc/typings/msg/dty.d.ts +8 -0
  957. package/blockly-rc/typings/msg/ee.d.ts +8 -0
  958. package/blockly-rc/typings/msg/el.d.ts +8 -0
  959. package/blockly-rc/typings/msg/en-gb.d.ts +8 -0
  960. package/blockly-rc/typings/msg/en.d.ts +8 -0
  961. package/blockly-rc/typings/msg/eo.d.ts +8 -0
  962. package/blockly-rc/typings/msg/es.d.ts +8 -0
  963. package/blockly-rc/typings/msg/et.d.ts +8 -0
  964. package/blockly-rc/typings/msg/eu.d.ts +8 -0
  965. package/blockly-rc/typings/msg/fa.d.ts +8 -0
  966. package/blockly-rc/typings/msg/fi.d.ts +8 -0
  967. package/blockly-rc/typings/msg/fo.d.ts +8 -0
  968. package/blockly-rc/typings/msg/fr.d.ts +8 -0
  969. package/blockly-rc/typings/msg/frr.d.ts +8 -0
  970. package/blockly-rc/typings/msg/gl.d.ts +8 -0
  971. package/blockly-rc/typings/msg/gn.d.ts +8 -0
  972. package/blockly-rc/typings/msg/gor.d.ts +8 -0
  973. package/blockly-rc/typings/msg/ha.d.ts +8 -0
  974. package/blockly-rc/typings/msg/hak.d.ts +8 -0
  975. package/blockly-rc/typings/msg/he.d.ts +8 -0
  976. package/blockly-rc/typings/msg/hi.d.ts +8 -0
  977. package/blockly-rc/typings/msg/hr.d.ts +8 -0
  978. package/blockly-rc/typings/msg/hrx.d.ts +8 -0
  979. package/blockly-rc/typings/msg/hsb.d.ts +8 -0
  980. package/blockly-rc/typings/msg/hu.d.ts +8 -0
  981. package/blockly-rc/typings/msg/hy.d.ts +8 -0
  982. package/blockly-rc/typings/msg/ia.d.ts +8 -0
  983. package/blockly-rc/typings/msg/id.d.ts +8 -0
  984. package/blockly-rc/typings/msg/ig.d.ts +8 -0
  985. package/blockly-rc/typings/msg/inh.d.ts +8 -0
  986. package/blockly-rc/typings/msg/is.d.ts +8 -0
  987. package/blockly-rc/typings/msg/it.d.ts +8 -0
  988. package/blockly-rc/typings/msg/ja.d.ts +8 -0
  989. package/blockly-rc/typings/msg/ka.d.ts +8 -0
  990. package/blockly-rc/typings/msg/kab.d.ts +8 -0
  991. package/blockly-rc/typings/msg/kbd-cyrl.d.ts +8 -0
  992. package/blockly-rc/typings/msg/km.d.ts +8 -0
  993. package/blockly-rc/typings/msg/kn.d.ts +8 -0
  994. package/blockly-rc/typings/msg/ko.d.ts +8 -0
  995. package/blockly-rc/typings/msg/ksh.d.ts +8 -0
  996. package/blockly-rc/typings/msg/ku-latn.d.ts +8 -0
  997. package/blockly-rc/typings/msg/ky.d.ts +8 -0
  998. package/blockly-rc/typings/msg/la.d.ts +8 -0
  999. package/blockly-rc/typings/msg/lb.d.ts +8 -0
  1000. package/blockly-rc/typings/msg/lki.d.ts +8 -0
  1001. package/blockly-rc/typings/msg/lo.d.ts +8 -0
  1002. package/blockly-rc/typings/msg/lrc.d.ts +8 -0
  1003. package/blockly-rc/typings/msg/lt.d.ts +8 -0
  1004. package/blockly-rc/typings/msg/lv.d.ts +8 -0
  1005. package/blockly-rc/typings/msg/mg.d.ts +8 -0
  1006. package/blockly-rc/typings/msg/mk.d.ts +8 -0
  1007. package/blockly-rc/typings/msg/ml.d.ts +8 -0
  1008. package/blockly-rc/typings/msg/mnw.d.ts +8 -0
  1009. package/blockly-rc/typings/msg/ms.d.ts +8 -0
  1010. package/blockly-rc/typings/msg/msg.d.ts +440 -0
  1011. package/blockly-rc/typings/msg/my.d.ts +8 -0
  1012. package/blockly-rc/typings/msg/mzn.d.ts +8 -0
  1013. package/blockly-rc/typings/msg/nb.d.ts +8 -0
  1014. package/blockly-rc/typings/msg/ne.d.ts +8 -0
  1015. package/blockly-rc/typings/msg/nl.d.ts +8 -0
  1016. package/blockly-rc/typings/msg/oc.d.ts +8 -0
  1017. package/blockly-rc/typings/msg/olo.d.ts +8 -0
  1018. package/blockly-rc/typings/msg/pa.d.ts +8 -0
  1019. package/blockly-rc/typings/msg/pl.d.ts +8 -0
  1020. package/blockly-rc/typings/msg/pms.d.ts +8 -0
  1021. package/blockly-rc/typings/msg/ps.d.ts +8 -0
  1022. package/blockly-rc/typings/msg/pt-br.d.ts +8 -0
  1023. package/blockly-rc/typings/msg/pt.d.ts +8 -0
  1024. package/blockly-rc/typings/msg/ro.d.ts +8 -0
  1025. package/blockly-rc/typings/msg/ru.d.ts +8 -0
  1026. package/blockly-rc/typings/msg/sc.d.ts +8 -0
  1027. package/blockly-rc/typings/msg/sco.d.ts +8 -0
  1028. package/blockly-rc/typings/msg/sd.d.ts +8 -0
  1029. package/blockly-rc/typings/msg/shn.d.ts +8 -0
  1030. package/blockly-rc/typings/msg/si.d.ts +8 -0
  1031. package/blockly-rc/typings/msg/sk.d.ts +8 -0
  1032. package/blockly-rc/typings/msg/skr-arab.d.ts +8 -0
  1033. package/blockly-rc/typings/msg/sl.d.ts +8 -0
  1034. package/blockly-rc/typings/msg/smn.d.ts +8 -0
  1035. package/blockly-rc/typings/msg/sq.d.ts +8 -0
  1036. package/blockly-rc/typings/msg/sr-latn.d.ts +8 -0
  1037. package/blockly-rc/typings/msg/sr.d.ts +8 -0
  1038. package/blockly-rc/typings/msg/sv.d.ts +8 -0
  1039. package/blockly-rc/typings/msg/sw.d.ts +8 -0
  1040. package/blockly-rc/typings/msg/ta.d.ts +8 -0
  1041. package/blockly-rc/typings/msg/tcy.d.ts +8 -0
  1042. package/blockly-rc/typings/msg/tdd.d.ts +8 -0
  1043. package/blockly-rc/typings/msg/te.d.ts +8 -0
  1044. package/blockly-rc/typings/msg/th.d.ts +8 -0
  1045. package/blockly-rc/typings/msg/ti.d.ts +8 -0
  1046. package/blockly-rc/typings/msg/tl.d.ts +8 -0
  1047. package/blockly-rc/typings/msg/tlh.d.ts +8 -0
  1048. package/blockly-rc/typings/msg/tr.d.ts +8 -0
  1049. package/blockly-rc/typings/msg/ug-arab.d.ts +8 -0
  1050. package/blockly-rc/typings/msg/uk.d.ts +8 -0
  1051. package/blockly-rc/typings/msg/ur.d.ts +8 -0
  1052. package/blockly-rc/typings/msg/uz.d.ts +8 -0
  1053. package/blockly-rc/typings/msg/vi.d.ts +8 -0
  1054. package/blockly-rc/typings/msg/xmf.d.ts +8 -0
  1055. package/blockly-rc/typings/msg/yo.d.ts +8 -0
  1056. package/blockly-rc/typings/msg/zgh.d.ts +8 -0
  1057. package/blockly-rc/typings/msg/zh-hans.d.ts +8 -0
  1058. package/blockly-rc/typings/msg/zh-hant.d.ts +8 -0
  1059. package/blockly-rc/typings/php.d.ts +7 -0
  1060. package/blockly-rc/typings/python.d.ts +7 -0
  1061. package/blockly-rc/typings/templates/blockly-header.template +11 -0
  1062. package/blockly-rc/typings/templates/blockly-interfaces.template +83 -0
  1063. package/blockly-rc/typings/templates/msg.template +15 -0
  1064. package/blockly-rc/typings/tsconfig.json +23 -0
  1065. package/continuous-toolbox.d.ts +1 -0
  1066. package/dist/main.js +2 -0
  1067. package/dist/main.js.LICENSE.txt +163 -0
  1068. package/media/delete-icon.svg +10 -0
  1069. package/media/resize-handle.svg +3 -0
  1070. package/msg/scratch_msgs.js +184 -164
  1071. package/package.json +25 -40
  1072. package/release.config.js +8 -0
  1073. package/src/block_reporting.js +31 -0
  1074. package/src/blocks/colour.js +56 -0
  1075. package/src/blocks/control.js +492 -0
  1076. package/src/blocks/data.js +690 -0
  1077. package/src/blocks/event.js +305 -0
  1078. package/src/blocks/looks.js +537 -0
  1079. package/src/blocks/math.js +137 -0
  1080. package/src/blocks/matrix.js +47 -0
  1081. package/src/blocks/motion.js +513 -0
  1082. package/src/blocks/note.js +48 -0
  1083. package/src/blocks/operators.js +463 -0
  1084. package/src/blocks/procedures.js +1009 -0
  1085. package/src/blocks/sensing.js +441 -0
  1086. package/src/blocks/sound.js +205 -0
  1087. package/src/blocks/text.js +45 -0
  1088. package/src/blocks/vertical_extensions.js +309 -0
  1089. package/src/categories.js +15 -0
  1090. package/src/checkable_continuous_flyout.js +138 -0
  1091. package/src/checkbox_bubble.js +282 -0
  1092. package/src/colours.js +77 -0
  1093. package/src/constants.js +63 -0
  1094. package/src/context_menu_items.js +150 -0
  1095. package/src/css.js +1197 -0
  1096. package/src/data_category.js +556 -0
  1097. package/src/events/events_block_comment_base.js +35 -0
  1098. package/src/events/events_block_comment_change.js +43 -0
  1099. package/src/events/events_block_comment_collapse.js +43 -0
  1100. package/src/events/events_block_comment_create.js +52 -0
  1101. package/src/events/events_block_comment_delete.js +27 -0
  1102. package/src/events/events_block_comment_move.js +54 -0
  1103. package/src/events/events_block_comment_resize.js +52 -0
  1104. package/src/events/events_block_drag_end.js +33 -0
  1105. package/src/events/events_block_drag_outside.js +30 -0
  1106. package/src/events/events_scratch_variable_create.js +67 -0
  1107. package/src/fields/field_angle.js +433 -0
  1108. package/src/fields/field_colour_slider.js +388 -0
  1109. package/src/fields/field_dropdown.js +42 -0
  1110. package/src/fields/field_matrix.js +634 -0
  1111. package/src/fields/field_note.js +937 -0
  1112. package/src/fields/field_number.js +380 -0
  1113. package/src/fields/field_textinput_removable.js +107 -0
  1114. package/src/fields/field_variable.js +171 -0
  1115. package/src/fields/field_variable_getter.js +109 -0
  1116. package/src/fields/field_vertical_separator.js +139 -0
  1117. package/src/flyout_checkbox_icon.js +88 -0
  1118. package/src/glows.js +98 -0
  1119. package/src/index.ts +137 -0
  1120. package/src/procedures.js +425 -0
  1121. package/src/recyclable_block_flyout_inflater.js +194 -0
  1122. package/src/renderer/bowler_hat.js +17 -0
  1123. package/src/renderer/constants.js +45 -0
  1124. package/src/renderer/drawer.js +51 -0
  1125. package/src/renderer/path_object.js +35 -0
  1126. package/src/renderer/render_info.js +98 -0
  1127. package/src/renderer/renderer.js +74 -0
  1128. package/src/scratch_block_paster.js +46 -0
  1129. package/src/scratch_blocks_utils.js +148 -0
  1130. package/src/scratch_comment_bubble.js +169 -0
  1131. package/src/scratch_comment_icon.js +195 -0
  1132. package/src/scratch_connection_checker.js +29 -0
  1133. package/src/scratch_continuous_category.js +80 -0
  1134. package/src/scratch_continuous_toolbox.js +78 -0
  1135. package/src/scratch_dragger.js +142 -0
  1136. package/src/scratch_variable_map.js +25 -0
  1137. package/src/scratch_variable_model.js +24 -0
  1138. package/src/shadows.js +61 -0
  1139. package/src/status_indicator_label.js +186 -0
  1140. package/src/status_indicator_label_flyout_inflater.js +42 -0
  1141. package/src/variables.js +355 -0
  1142. package/temp-use-blockly-v12-rc.sh +26 -0
  1143. package/tsconfig.json +13 -0
  1144. package/blockly_compressed_horizontal.js +0 -2255
  1145. package/blockly_compressed_vertical.js +0 -2283
  1146. package/blockly_uncompressed_horizontal.js +0 -1210
  1147. package/blockly_uncompressed_vertical.js +0 -1210
  1148. package/blocks_common/colour.js +0 -61
  1149. package/blocks_common/math.js +0 -159
  1150. package/blocks_common/matrix.js +0 -54
  1151. package/blocks_common/note.js +0 -58
  1152. package/blocks_common/text.js +0 -57
  1153. package/blocks_compressed.js +0 -36
  1154. package/blocks_compressed_horizontal.js +0 -67
  1155. package/blocks_compressed_vertical.js +0 -208
  1156. package/blocks_horizontal/control.js +0 -212
  1157. package/blocks_horizontal/default_toolbox.js +0 -139
  1158. package/blocks_horizontal/event.js +0 -190
  1159. package/blocks_horizontal/wedo.js +0 -325
  1160. package/blocks_vertical/control.js +0 -532
  1161. package/blocks_vertical/data.js +0 -666
  1162. package/blocks_vertical/default_toolbox.js +0 -564
  1163. package/blocks_vertical/event.js +0 -329
  1164. package/blocks_vertical/extensions.js +0 -294
  1165. package/blocks_vertical/looks.js +0 -591
  1166. package/blocks_vertical/motion.js +0 -587
  1167. package/blocks_vertical/operators.js +0 -470
  1168. package/blocks_vertical/procedures.js +0 -973
  1169. package/blocks_vertical/sensing.js +0 -539
  1170. package/blocks_vertical/sound.js +0 -246
  1171. package/blocks_vertical/vertical_extensions.js +0 -266
  1172. package/build/gen_blocks.js +0 -1
  1173. package/build/test_expect.js +0 -1
  1174. package/build/test_input.js +0 -1
  1175. package/build.py +0 -636
  1176. package/cleanup.sh +0 -101
  1177. package/core/block.js +0 -1837
  1178. package/core/block_animations.js +0 -107
  1179. package/core/block_drag_surface.js +0 -299
  1180. package/core/block_dragger.js +0 -421
  1181. package/core/block_events.js +0 -531
  1182. package/core/block_render_svg_horizontal.js +0 -890
  1183. package/core/block_render_svg_vertical.js +0 -1732
  1184. package/core/block_svg.js +0 -1316
  1185. package/core/blockly.js +0 -622
  1186. package/core/blocks.js +0 -37
  1187. package/core/bubble.js +0 -664
  1188. package/core/bubble_dragger.js +0 -285
  1189. package/core/colours.js +0 -160
  1190. package/core/comment.js +0 -293
  1191. package/core/comment_events.js +0 -539
  1192. package/core/connection.js +0 -766
  1193. package/core/connection_db.js +0 -300
  1194. package/core/constants.js +0 -387
  1195. package/core/contextmenu.js +0 -519
  1196. package/core/css.js +0 -1351
  1197. package/core/data_category.js +0 -490
  1198. package/core/dragged_connection_manager.js +0 -260
  1199. package/core/dropdowndiv.js +0 -408
  1200. package/core/events.js +0 -429
  1201. package/core/events_abstract.js +0 -113
  1202. package/core/extensions.js +0 -450
  1203. package/core/field.js +0 -807
  1204. package/core/field_angle.js +0 -398
  1205. package/core/field_checkbox.js +0 -133
  1206. package/core/field_colour.js +0 -253
  1207. package/core/field_colour_slider.js +0 -387
  1208. package/core/field_date.js +0 -353
  1209. package/core/field_dropdown.js +0 -483
  1210. package/core/field_iconmenu.js +0 -309
  1211. package/core/field_image.js +0 -193
  1212. package/core/field_label.js +0 -136
  1213. package/core/field_label_serializable.js +0 -125
  1214. package/core/field_matrix.js +0 -566
  1215. package/core/field_note.js +0 -850
  1216. package/core/field_number.js +0 -366
  1217. package/core/field_numberdropdown.js +0 -77
  1218. package/core/field_textdropdown.js +0 -164
  1219. package/core/field_textinput.js +0 -675
  1220. package/core/field_textinput_removable.js +0 -105
  1221. package/core/field_variable.js +0 -385
  1222. package/core/field_variable_getter.js +0 -185
  1223. package/core/field_vertical_separator.js +0 -161
  1224. package/core/flyout_base.js +0 -923
  1225. package/core/flyout_button.js +0 -322
  1226. package/core/flyout_dragger.js +0 -83
  1227. package/core/flyout_extension_category_header.js +0 -159
  1228. package/core/flyout_horizontal.js +0 -475
  1229. package/core/flyout_vertical.js +0 -770
  1230. package/core/generator.js +0 -426
  1231. package/core/gesture.js +0 -1011
  1232. package/core/grid.js +0 -227
  1233. package/core/icon.js +0 -205
  1234. package/core/inject.js +0 -491
  1235. package/core/input.js +0 -285
  1236. package/core/insertion_marker_manager.js +0 -678
  1237. package/core/msg.js +0 -62
  1238. package/core/mutator.js +0 -426
  1239. package/core/names.js +0 -198
  1240. package/core/options.js +0 -244
  1241. package/core/procedures.js +0 -577
  1242. package/core/rendered_connection.js +0 -417
  1243. package/core/scratch_block_comment.js +0 -653
  1244. package/core/scratch_blocks_utils.js +0 -244
  1245. package/core/scratch_bubble.js +0 -696
  1246. package/core/scratch_events.js +0 -131
  1247. package/core/scratch_msgs.js +0 -85
  1248. package/core/scrollbar.js +0 -875
  1249. package/core/toolbox.js +0 -801
  1250. package/core/tooltip.js +0 -337
  1251. package/core/touch.js +0 -226
  1252. package/core/trashcan.js +0 -343
  1253. package/core/ui_events.js +0 -91
  1254. package/core/ui_menu_utils.js +0 -68
  1255. package/core/utils.js +0 -948
  1256. package/core/variable_events.js +0 -259
  1257. package/core/variable_map.js +0 -415
  1258. package/core/variable_model.js +0 -116
  1259. package/core/variables.js +0 -674
  1260. package/core/warning.js +0 -199
  1261. package/core/widgetdiv.js +0 -344
  1262. package/core/workspace.js +0 -673
  1263. package/core/workspace_audio.js +0 -170
  1264. package/core/workspace_comment.js +0 -432
  1265. package/core/workspace_comment_render_svg.js +0 -723
  1266. package/core/workspace_comment_svg.js +0 -611
  1267. package/core/workspace_drag_surface_svg.js +0 -195
  1268. package/core/workspace_dragger.js +0 -132
  1269. package/core/workspace_svg.js +0 -2267
  1270. package/core/xml.js +0 -919
  1271. package/core/zoom_controls.js +0 -301
  1272. package/dist/horizontal.js +0 -222
  1273. package/dist/vertical.js +0 -222
  1274. package/dist/web/horizontal.js +0 -232
  1275. package/dist/web/vertical.js +0 -232
  1276. package/local_build.sh +0 -70
  1277. package/pack/scratch-blocks-1.1.206.tgz +0 -0
  1278. package/pull_from_blockly.sh +0 -151
  1279. package/shim/blockly_compressed_horizontal-blocks_compressed.js +0 -1
  1280. package/shim/blockly_compressed_horizontal.Blockly.js +0 -1
  1281. package/shim/blockly_compressed_horizontal.goog.js +0 -1
  1282. package/shim/blockly_compressed_horizontal.js +0 -1
  1283. package/shim/blockly_compressed_vertical-blocks_compressed.js +0 -1
  1284. package/shim/blockly_compressed_vertical.Blockly.js +0 -1
  1285. package/shim/blockly_compressed_vertical.goog.js +0 -1
  1286. package/shim/blockly_compressed_vertical.js +0 -1
  1287. package/shim/blocks_compressed_horizontal-blockly_compressed_horizontal-messages.js +0 -1
  1288. package/shim/blocks_compressed_horizontal.js +0 -1
  1289. package/shim/blocks_compressed_vertical-blockly_compressed_vertical-messages.js +0 -1
  1290. package/shim/blocks_compressed_vertical.js +0 -1
  1291. package/shim/gh-pages.js +0 -1
  1292. package/shim/horizontal.js +0 -1
  1293. package/shim/index.js +0 -17
  1294. package/shim/vertical.js +0 -1
  1295. /package/media/{comment-arrow-down.svg → foldout-icon.svg} +0 -0
@@ -0,0 +1,2523 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2011 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ /**
8
+ * The class representing one block.
9
+ *
10
+ * @class
11
+ */
12
+ // Former goog.module ID: Blockly.Block
13
+
14
+ // Unused import preserved for side-effects. Remove if unneeded.
15
+ import './events/events_block_change.js';
16
+ // Unused import preserved for side-effects. Remove if unneeded.
17
+ import './events/events_block_create.js';
18
+ // Unused import preserved for side-effects. Remove if unneeded.
19
+ import './events/events_block_delete.js';
20
+
21
+ import {Blocks} from './blocks.js';
22
+ import * as common from './common.js';
23
+ import {Connection} from './connection.js';
24
+ import {ConnectionType} from './connection_type.js';
25
+ import * as constants from './constants.js';
26
+ import {DuplicateIconType} from './icons/exceptions.js';
27
+ import type {Abstract} from './events/events_abstract.js';
28
+ import type {BlockChange} from './events/events_block_change.js';
29
+ import type {BlockMove} from './events/events_block_move.js';
30
+ import * as deprecation from './utils/deprecation.js';
31
+ import * as eventUtils from './events/utils.js';
32
+ import * as Extensions from './extensions.js';
33
+ import type {Field} from './field.js';
34
+ import * as fieldRegistry from './field_registry.js';
35
+ import {Input} from './inputs/input.js';
36
+ import {Align} from './inputs/align.js';
37
+ import type {IASTNodeLocation} from './interfaces/i_ast_node_location.js';
38
+ import {type IIcon} from './interfaces/i_icon.js';
39
+ import {isCommentIcon} from './interfaces/i_comment_icon.js';
40
+ import type {MutatorIcon} from './icons/mutator_icon.js';
41
+ import * as Tooltip from './tooltip.js';
42
+ import * as arrayUtils from './utils/array.js';
43
+ import {Coordinate} from './utils/coordinate.js';
44
+ import * as idGenerator from './utils/idgenerator.js';
45
+ import * as parsing from './utils/parsing.js';
46
+ import * as registry from './registry.js';
47
+ import {Size} from './utils/size.js';
48
+ import type {
49
+ IVariableModel,
50
+ IVariableState,
51
+ } from './interfaces/i_variable_model.js';
52
+ import type {Workspace} from './workspace.js';
53
+ import {DummyInput} from './inputs/dummy_input.js';
54
+ import {EndRowInput} from './inputs/end_row_input.js';
55
+ import {ValueInput} from './inputs/value_input.js';
56
+ import {StatementInput} from './inputs/statement_input.js';
57
+ import {IconType} from './icons/icon_types.js';
58
+
59
+ /**
60
+ * Class for one block.
61
+ * Not normally called directly, workspace.newBlock() is preferred.
62
+ */
63
+ export class Block implements IASTNodeLocation {
64
+ /**
65
+ * An optional callback method to use whenever the block's parent workspace
66
+ * changes. This is usually only called from the constructor, the block type
67
+ * initializer function, or an extension initializer function.
68
+ */
69
+ onchange?: ((p1: Abstract) => void) | null;
70
+
71
+ /** The language-neutral ID given to the collapsed input. */
72
+ static readonly COLLAPSED_INPUT_NAME: string = constants.COLLAPSED_INPUT_NAME;
73
+
74
+ /** The language-neutral ID given to the collapsed field. */
75
+ static readonly COLLAPSED_FIELD_NAME: string = constants.COLLAPSED_FIELD_NAME;
76
+
77
+ /**
78
+ * Optional text data that round-trips between blocks and XML.
79
+ * Has no effect. May be used by 3rd parties for meta information.
80
+ */
81
+ data: string | null = null;
82
+
83
+ /**
84
+ * Has this block been disposed of?
85
+ *
86
+ * @internal
87
+ */
88
+ disposed = false;
89
+
90
+ /**
91
+ * Colour of the block as HSV hue value (0-360)
92
+ * This may be null if the block colour was not set via a hue number.
93
+ */
94
+ private hue_: number | null = null;
95
+
96
+ /** Colour of the block in '#RRGGBB' format. */
97
+ protected colour_ = '#000000';
98
+
99
+ /** Name of the block style. */
100
+ protected styleName_ = '';
101
+
102
+ /** An optional method called during initialization. */
103
+ init?: () => void;
104
+
105
+ /** An optional method called during disposal. */
106
+ destroy?: () => void;
107
+
108
+ /**
109
+ * An optional serialization method for defining how to serialize the
110
+ * mutation state to XML. This must be coupled with defining
111
+ * `domToMutation`.
112
+ */
113
+ mutationToDom?: (...p1: AnyDuringMigration[]) => Element;
114
+
115
+ /**
116
+ * An optional deserialization method for defining how to deserialize the
117
+ * mutation state from XML. This must be coupled with defining
118
+ * `mutationToDom`.
119
+ */
120
+ domToMutation?: (p1: Element) => void;
121
+
122
+ /**
123
+ * An optional serialization method for defining how to serialize the
124
+ * block's extra state (eg mutation state) to something JSON compatible.
125
+ * This must be coupled with defining `loadExtraState`.
126
+ *
127
+ * @param doFullSerialization Whether or not to serialize the full state of
128
+ * the extra state (rather than possibly saving a reference to some
129
+ * state). This is used during copy-paste. See the
130
+ * {@link https://developers.devsite.google.com/blockly/guides/create-custom-blocks/extensions#full_serialization_and_backing_data | block serialization docs}
131
+ * for more information.
132
+ */
133
+ saveExtraState?: (doFullSerialization?: boolean) => AnyDuringMigration;
134
+
135
+ /**
136
+ * An optional serialization method for defining how to deserialize the
137
+ * block's extra state (eg mutation state) from something JSON compatible.
138
+ * This must be coupled with defining `saveExtraState`.
139
+ */
140
+ loadExtraState?: (p1: AnyDuringMigration) => void;
141
+
142
+ /**
143
+ * An optional property for suppressing adding STATEMENT_PREFIX and
144
+ * STATEMENT_SUFFIX to generated code.
145
+ */
146
+ suppressPrefixSuffix: boolean | null = false;
147
+
148
+ /**
149
+ * An optional property for declaring developer variables. Return a list of
150
+ * variable names for use by generators. Developer variables are never
151
+ * shown to the user, but are declared as global variables in the generated
152
+ * code.
153
+ */
154
+ getDeveloperVariables?: () => string[];
155
+
156
+ /**
157
+ * An optional function that reconfigures the block based on the contents of
158
+ * the mutator dialog.
159
+ */
160
+ compose?: (p1: Block) => void;
161
+
162
+ /**
163
+ * An optional function that populates the mutator's dialog with
164
+ * this block's components.
165
+ */
166
+ decompose?: (p1: Workspace) => Block;
167
+ id: string;
168
+ outputConnection: Connection | null = null;
169
+ nextConnection: Connection | null = null;
170
+ previousConnection: Connection | null = null;
171
+ inputList: Input[] = [];
172
+ inputsInline?: boolean;
173
+ icons: IIcon[] = [];
174
+ private disabledReasons = new Set<string>();
175
+ tooltip: Tooltip.TipInfo = '';
176
+ contextMenu = true;
177
+
178
+ protected parentBlock_: this | null = null;
179
+
180
+ protected childBlocks_: this[] = [];
181
+
182
+ private deletable_ = true;
183
+
184
+ private movable_ = true;
185
+
186
+ private editable_ = true;
187
+
188
+ private isShadow_ = false;
189
+
190
+ protected collapsed_ = false;
191
+ protected outputShape_: number | null = null;
192
+
193
+ /**
194
+ * Is the current block currently in the process of being disposed?
195
+ */
196
+ protected disposing = false;
197
+
198
+ /**
199
+ * Has this block been fully initialized? E.g. all fields initailized.
200
+ *
201
+ * @internal
202
+ */
203
+ initialized = false;
204
+
205
+ private readonly xy_: Coordinate;
206
+ isInFlyout: boolean;
207
+ isInMutator: boolean;
208
+ RTL: boolean;
209
+
210
+ /** True if this block is an insertion marker. */
211
+ protected isInsertionMarker_ = false;
212
+
213
+ /** Name of the type of hat. */
214
+ hat?: string;
215
+
216
+ /** Is this block a BlockSVG? */
217
+ readonly rendered: boolean = false;
218
+
219
+ /**
220
+ * String for block help, or function that returns a URL. Null for no help.
221
+ */
222
+ helpUrl: string | Function | null = null;
223
+
224
+ /** A bound callback function to use when the parent workspace changes. */
225
+ private onchangeWrapper_: ((p1: Abstract) => void) | null = null;
226
+
227
+ /**
228
+ * A count of statement inputs on the block.
229
+ *
230
+ * @internal
231
+ */
232
+ statementInputCount = 0;
233
+ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
234
+ type!: string;
235
+ // Record initial inline state.
236
+ inputsInlineDefault?: boolean;
237
+ workspace: Workspace;
238
+
239
+ /**
240
+ * @param workspace The block's workspace.
241
+ * @param prototypeName Name of the language object containing type-specific
242
+ * functions for this block.
243
+ * @param opt_id Optional ID. Use this ID if provided, otherwise create a new
244
+ * ID.
245
+ * @throws When the prototypeName is not valid or not allowed.
246
+ */
247
+ constructor(workspace: Workspace, prototypeName: string, opt_id?: string) {
248
+ this.workspace = workspace;
249
+
250
+ this.id =
251
+ opt_id && !workspace.getBlockById(opt_id) ? opt_id : idGenerator.genUid();
252
+ workspace.setBlockById(this.id, this);
253
+
254
+ /**
255
+ * The block's position in workspace units. (0, 0) is at the workspace's
256
+ * origin; scale does not change this value.
257
+ */
258
+ this.xy_ = new Coordinate(0, 0);
259
+ this.isInFlyout = workspace.isFlyout;
260
+ this.isInMutator = workspace.isMutator;
261
+
262
+ this.RTL = workspace.RTL;
263
+
264
+ // Copy the type-specific functions and data from the prototype.
265
+ if (prototypeName) {
266
+ this.type = prototypeName;
267
+ const prototype = Blocks[prototypeName];
268
+ if (!prototype || typeof prototype !== 'object') {
269
+ throw TypeError('Invalid block definition for type: ' + prototypeName);
270
+ }
271
+ Object.assign(this, prototype);
272
+ }
273
+
274
+ workspace.addTopBlock(this);
275
+ workspace.addTypedBlock(this);
276
+
277
+ if (new.target === Block) {
278
+ this.doInit_();
279
+ }
280
+ }
281
+
282
+ /** Calls the init() function and handles associated event firing, etc. */
283
+ protected doInit_() {
284
+ // All events fired should be part of the same group.
285
+ // Any events fired during init should not be undoable,
286
+ // so that block creation is atomic.
287
+ const existingGroup = eventUtils.getGroup();
288
+ if (!existingGroup) {
289
+ eventUtils.setGroup(true);
290
+ }
291
+ const initialUndoFlag = eventUtils.getRecordUndo();
292
+
293
+ try {
294
+ // Call an initialization function, if it exists.
295
+ if (typeof this.init === 'function') {
296
+ eventUtils.setRecordUndo(false);
297
+ this.init();
298
+ eventUtils.setRecordUndo(initialUndoFlag);
299
+ }
300
+
301
+ // Fire a create event.
302
+ if (eventUtils.isEnabled()) {
303
+ eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(this));
304
+ }
305
+ } finally {
306
+ eventUtils.setGroup(existingGroup);
307
+ // In case init threw, recordUndo flag should still be reset.
308
+ eventUtils.setRecordUndo(initialUndoFlag);
309
+ }
310
+ this.inputsInlineDefault = this.inputsInline;
311
+
312
+ // Bind an onchange function, if it exists.
313
+ if (typeof this.onchange === 'function') {
314
+ this.setOnChange(this.onchange);
315
+ }
316
+ }
317
+
318
+ /**
319
+ * Dispose of this block.
320
+ *
321
+ * @param healStack If true, then try to heal any gap by connecting the next
322
+ * statement with the previous statement. Otherwise, dispose of all
323
+ * children of this block.
324
+ */
325
+ dispose(healStack = false) {
326
+ this.disposing = true;
327
+
328
+ // Dispose of this change listener before unplugging.
329
+ // Technically not necessary due to the event firing delay.
330
+ // But future-proofing.
331
+ if (this.onchangeWrapper_) {
332
+ this.workspace.removeChangeListener(this.onchangeWrapper_);
333
+ }
334
+
335
+ this.unplug(healStack);
336
+ if (eventUtils.isEnabled()) {
337
+ // Constructing the delete event is costly. Only perform if necessary.
338
+ eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_DELETE))(this));
339
+ }
340
+ this.workspace.removeTopBlock(this);
341
+ this.disposeInternal();
342
+ }
343
+
344
+ /**
345
+ * Disposes of this block without doing things required by the top block.
346
+ * E.g. does not fire events, unplug the block, etc.
347
+ */
348
+ protected disposeInternal() {
349
+ this.disposing = true;
350
+ if (this.onchangeWrapper_) {
351
+ this.workspace.removeChangeListener(this.onchangeWrapper_);
352
+ }
353
+
354
+ this.workspace.removeTypedBlock(this);
355
+ this.workspace.removeBlockById(this.id);
356
+
357
+ if (typeof this.destroy === 'function') this.destroy();
358
+
359
+ this.childBlocks_.forEach((c) => c.disposeInternal());
360
+ this.inputList.forEach((i) => i.dispose());
361
+ this.inputList.length = 0;
362
+ this.getConnections_(true).forEach((c) => c.dispose());
363
+ this.disposed = true;
364
+ }
365
+
366
+ /**
367
+ * Returns true if the block is either in the process of being disposed, or
368
+ * is disposed.
369
+ *
370
+ * @internal
371
+ */
372
+ isDeadOrDying(): boolean {
373
+ return this.disposing || this.disposed;
374
+ }
375
+
376
+ /**
377
+ * Call initModel on all fields on the block.
378
+ * May be called more than once.
379
+ * Either initModel or initSvg must be called after creating a block and
380
+ * before the first interaction with it. Interactions include UI actions
381
+ * (e.g. clicking and dragging) and firing events (e.g. create, delete, and
382
+ * change).
383
+ */
384
+ initModel() {
385
+ if (this.initialized) return;
386
+ for (const input of this.inputList) {
387
+ input.initModel();
388
+ }
389
+ this.initialized = true;
390
+ }
391
+
392
+ /**
393
+ * Unplug this block from its superior block. If this block is a statement,
394
+ * optionally reconnect the block underneath with the block on top.
395
+ *
396
+ * @param opt_healStack Disconnect child statement and reconnect stack.
397
+ * Defaults to false.
398
+ */
399
+ unplug(opt_healStack?: boolean) {
400
+ if (this.outputConnection) {
401
+ this.unplugFromRow_(opt_healStack);
402
+ }
403
+ if (this.previousConnection) {
404
+ this.unplugFromStack_(opt_healStack);
405
+ }
406
+ }
407
+
408
+ /**
409
+ * Unplug this block's output from an input on another block. Optionally
410
+ * reconnect the block's parent to the only child block, if possible.
411
+ *
412
+ * @param opt_healStack Disconnect right-side block and connect to left-side
413
+ * block. Defaults to false.
414
+ */
415
+ private unplugFromRow_(opt_healStack?: boolean) {
416
+ let parentConnection = null;
417
+ if (this.outputConnection?.isConnected()) {
418
+ parentConnection = this.outputConnection.targetConnection;
419
+ // Disconnect from any superior block.
420
+ this.outputConnection.disconnect();
421
+ }
422
+
423
+ // Return early in obvious cases.
424
+ if (!parentConnection || !opt_healStack) {
425
+ return;
426
+ }
427
+
428
+ const thisConnection = this.getOnlyValueConnection_();
429
+ if (
430
+ !thisConnection ||
431
+ !thisConnection.isConnected() ||
432
+ thisConnection.targetBlock()!.isShadow()
433
+ ) {
434
+ // Too many or too few possible connections on this block, or there's
435
+ // nothing on the other side of this connection.
436
+ return;
437
+ }
438
+
439
+ const childConnection = thisConnection.targetConnection;
440
+ // Disconnect the child block.
441
+ childConnection?.disconnect();
442
+ // Connect child to the parent if possible, otherwise bump away.
443
+ if (
444
+ this.workspace.connectionChecker.canConnect(
445
+ childConnection,
446
+ parentConnection,
447
+ false,
448
+ )
449
+ ) {
450
+ parentConnection.connect(childConnection!);
451
+ } else {
452
+ childConnection?.onFailedConnect(parentConnection);
453
+ }
454
+ }
455
+
456
+ /**
457
+ * Returns the connection on the value input that is connected to another
458
+ * block. When an insertion marker is connected to a connection with a block
459
+ * already attached, the connected block is attached to the insertion marker.
460
+ * Since only one block can be displaced and attached to the insertion marker
461
+ * this should only ever return one connection.
462
+ *
463
+ * @returns The connection on the value input, or null.
464
+ */
465
+ private getOnlyValueConnection_(): Connection | null {
466
+ let connection = null;
467
+ for (let i = 0; i < this.inputList.length; i++) {
468
+ const thisConnection = this.inputList[i].connection;
469
+ if (
470
+ thisConnection &&
471
+ thisConnection.type === ConnectionType.INPUT_VALUE &&
472
+ thisConnection.targetConnection
473
+ ) {
474
+ if (connection) {
475
+ return null; // More than one value input found.
476
+ }
477
+ connection = thisConnection;
478
+ }
479
+ }
480
+ return connection;
481
+ }
482
+
483
+ /**
484
+ * Unplug this statement block from its superior block. Optionally reconnect
485
+ * the block underneath with the block on top.
486
+ *
487
+ * @param opt_healStack Disconnect child statement and reconnect stack.
488
+ * Defaults to false.
489
+ */
490
+ private unplugFromStack_(opt_healStack?: boolean) {
491
+ let previousTarget = null;
492
+ if (this.previousConnection?.isConnected()) {
493
+ // Remember the connection that any next statements need to connect to.
494
+ previousTarget = this.previousConnection.targetConnection;
495
+ // Detach this block from the parent's tree.
496
+ this.previousConnection.disconnect();
497
+ }
498
+ const nextBlock = this.getNextBlock();
499
+ if (opt_healStack && nextBlock && !nextBlock.isShadow()) {
500
+ // Disconnect the next statement.
501
+ const nextTarget = this.nextConnection?.targetConnection ?? null;
502
+ nextTarget?.disconnect();
503
+ if (
504
+ previousTarget &&
505
+ this.workspace.connectionChecker.canConnect(
506
+ previousTarget,
507
+ nextTarget,
508
+ false,
509
+ )
510
+ ) {
511
+ // Attach the next statement to the previous statement.
512
+ previousTarget.connect(nextTarget!);
513
+ }
514
+ }
515
+ }
516
+
517
+ /**
518
+ * Returns all connections originating from this block.
519
+ *
520
+ * @param _all If true, return all connections even hidden ones.
521
+ * @returns Array of connections.
522
+ * @internal
523
+ */
524
+ getConnections_(_all: boolean): Connection[] {
525
+ const myConnections = [];
526
+ if (this.outputConnection) {
527
+ myConnections.push(this.outputConnection);
528
+ }
529
+ if (this.previousConnection) {
530
+ myConnections.push(this.previousConnection);
531
+ }
532
+ if (this.nextConnection) {
533
+ myConnections.push(this.nextConnection);
534
+ }
535
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
536
+ if (input.connection) {
537
+ myConnections.push(input.connection);
538
+ }
539
+ }
540
+ return myConnections;
541
+ }
542
+
543
+ /**
544
+ * Walks down a stack of blocks and finds the last next connection on the
545
+ * stack.
546
+ *
547
+ * @param ignoreShadows If true,the last connection on a non-shadow block will
548
+ * be returned. If false, this will follow shadows to find the last
549
+ * connection.
550
+ * @returns The last next connection on the stack, or null.
551
+ * @internal
552
+ */
553
+ lastConnectionInStack(ignoreShadows: boolean): Connection | null {
554
+ let nextConnection = this.nextConnection;
555
+ while (nextConnection) {
556
+ const nextBlock = nextConnection.targetBlock();
557
+ if (!nextBlock || (ignoreShadows && nextBlock.isShadow())) {
558
+ return nextConnection;
559
+ }
560
+ nextConnection = nextBlock.nextConnection;
561
+ }
562
+ return null;
563
+ }
564
+
565
+ /**
566
+ * Bump unconnected blocks out of alignment. Two blocks which aren't actually
567
+ * connected should not coincidentally line up on screen.
568
+ */
569
+ bumpNeighbours() {}
570
+
571
+ /**
572
+ * Return the parent block or null if this block is at the top level. The
573
+ * parent block is either the block connected to the previous connection (for
574
+ * a statement block) or the block connected to the output connection (for a
575
+ * value block).
576
+ *
577
+ * @returns The block (if any) that holds the current block.
578
+ */
579
+ getParent(): this | null {
580
+ return this.parentBlock_;
581
+ }
582
+
583
+ /**
584
+ * Return the input that connects to the specified block.
585
+ *
586
+ * @param block A block connected to an input on this block.
587
+ * @returns The input (if any) that connects to the specified block.
588
+ */
589
+ getInputWithBlock(block: Block): Input | null {
590
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
591
+ if (input.connection && input.connection.targetBlock() === block) {
592
+ return input;
593
+ }
594
+ }
595
+ return null;
596
+ }
597
+
598
+ /**
599
+ * Return the parent block that surrounds the current block, or null if this
600
+ * block has no surrounding block. A parent block might just be the previous
601
+ * statement, whereas the surrounding block is an if statement, while loop,
602
+ * etc.
603
+ *
604
+ * @returns The block (if any) that surrounds the current block.
605
+ */
606
+ getSurroundParent(): this | null {
607
+ /* eslint-disable-next-line @typescript-eslint/no-this-alias */
608
+ let block: this | null = this;
609
+ let prevBlock;
610
+ do {
611
+ prevBlock = block;
612
+ block = block.getParent();
613
+ if (!block) {
614
+ // Ran off the top.
615
+ return null;
616
+ }
617
+ } while (block.getNextBlock() === prevBlock);
618
+ // This block is an enclosing parent, not just a statement in a stack.
619
+ return block;
620
+ }
621
+
622
+ /**
623
+ * Return the next statement block directly connected to this block.
624
+ *
625
+ * @returns The next statement block or null.
626
+ */
627
+ getNextBlock(): Block | null {
628
+ return this.nextConnection && this.nextConnection.targetBlock();
629
+ }
630
+
631
+ /**
632
+ * Returns the block connected to the previous connection.
633
+ *
634
+ * @returns The previous statement block or null.
635
+ */
636
+ getPreviousBlock(): Block | null {
637
+ return this.previousConnection && this.previousConnection.targetBlock();
638
+ }
639
+
640
+ /**
641
+ * Return the top-most block in this block's tree.
642
+ * This will return itself if this block is at the top level.
643
+ *
644
+ * @returns The root block.
645
+ */
646
+ getRootBlock(): this {
647
+ let rootBlock: this;
648
+ /* eslint-disable-next-line @typescript-eslint/no-this-alias */
649
+ let block: this | null = this;
650
+ do {
651
+ rootBlock = block;
652
+ block = rootBlock.parentBlock_;
653
+ } while (block);
654
+ return rootBlock;
655
+ }
656
+
657
+ /**
658
+ * Walk up from the given block up through the stack of blocks to find
659
+ * the top block of the sub stack. If we are nested in a statement input only
660
+ * find the top-most nested block. Do not go all the way to the root block.
661
+ *
662
+ * @returns The top block in a stack.
663
+ * @internal
664
+ */
665
+ getTopStackBlock(): this {
666
+ /* eslint-disable-next-line @typescript-eslint/no-this-alias */
667
+ let block = this;
668
+ let previous;
669
+ do {
670
+ previous = block.getPreviousBlock();
671
+ // AnyDuringMigration because: Type 'Block' is not assignable to type
672
+ // 'this'.
673
+ } while (
674
+ previous &&
675
+ previous.getNextBlock() === block &&
676
+ (block = previous as AnyDuringMigration)
677
+ );
678
+ return block;
679
+ }
680
+
681
+ /**
682
+ * Find all the blocks that are directly nested inside this one.
683
+ * Includes value and statement inputs, as well as any following statement.
684
+ * Excludes any connection on an output tab or any preceding statement.
685
+ * Blocks are optionally sorted by position; top to bottom.
686
+ *
687
+ * @param ordered Sort the list if true.
688
+ * @returns Array of blocks.
689
+ */
690
+ getChildren(ordered: boolean): Block[] {
691
+ if (!ordered) {
692
+ return this.childBlocks_;
693
+ }
694
+ const blocks = [];
695
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
696
+ if (input.connection) {
697
+ const child = input.connection.targetBlock();
698
+ if (child) {
699
+ blocks.push(child);
700
+ }
701
+ }
702
+ }
703
+ const next = this.getNextBlock();
704
+ if (next) {
705
+ blocks.push(next);
706
+ }
707
+ return blocks;
708
+ }
709
+
710
+ /**
711
+ * Set parent of this block to be a new block or null.
712
+ *
713
+ * @param newParent New parent block.
714
+ * @internal
715
+ */
716
+ setParent(newParent: this | null) {
717
+ if (newParent === this.parentBlock_) {
718
+ return;
719
+ }
720
+
721
+ // Check that block is connected to new parent if new parent is not null and
722
+ // that block is not connected to superior one if new parent is null.
723
+ const targetBlock =
724
+ (this.previousConnection && this.previousConnection.targetBlock()) ||
725
+ (this.outputConnection && this.outputConnection.targetBlock());
726
+ const isConnected = !!targetBlock;
727
+
728
+ if (isConnected && newParent && targetBlock !== newParent) {
729
+ throw Error('Block connected to superior one that is not new parent.');
730
+ } else if (!isConnected && newParent) {
731
+ throw Error('Block not connected to new parent.');
732
+ } else if (isConnected && !newParent) {
733
+ throw Error(
734
+ 'Cannot set parent to null while block is still connected to' +
735
+ ' superior block.',
736
+ );
737
+ }
738
+
739
+ // This block hasn't actually moved on-screen, so there's no need to
740
+ // update
741
+ // its connection locations.
742
+ if (this.parentBlock_) {
743
+ // Remove this block from the old parent's child list.
744
+ arrayUtils.removeElem(this.parentBlock_.childBlocks_, this);
745
+ } else {
746
+ // New parent must be non-null so remove this block from the workspace's
747
+ // list of top-most blocks.
748
+ this.workspace.removeTopBlock(this);
749
+ }
750
+
751
+ this.parentBlock_ = newParent;
752
+ if (newParent) {
753
+ // Add this block to the new parent's child list.
754
+ newParent.childBlocks_.push(this);
755
+ } else {
756
+ this.workspace.addTopBlock(this);
757
+ }
758
+ }
759
+
760
+ /**
761
+ * Find all the blocks that are directly or indirectly nested inside this one.
762
+ * Includes this block in the list.
763
+ * Includes value and statement inputs, as well as any following statements.
764
+ * Excludes any connection on an output tab or any preceding statements.
765
+ * Blocks are optionally sorted by position; top to bottom.
766
+ *
767
+ * @param ordered Sort the list if true.
768
+ * @returns Flattened array of blocks.
769
+ */
770
+ getDescendants(ordered: boolean): this[] {
771
+ const blocks = [this];
772
+ const childBlocks = this.getChildren(ordered);
773
+ for (let child, i = 0; (child = childBlocks[i]); i++) {
774
+ // AnyDuringMigration because: Argument of type 'Block[]' is not
775
+ // assignable to parameter of type 'this[]'.
776
+ blocks.push(...(child.getDescendants(ordered) as AnyDuringMigration));
777
+ }
778
+ return blocks;
779
+ }
780
+
781
+ /**
782
+ * Get whether this block is deletable or not.
783
+ *
784
+ * @returns True if deletable.
785
+ */
786
+ isDeletable(): boolean {
787
+ return (
788
+ this.deletable_ &&
789
+ !this.isShadow_ &&
790
+ !this.isDeadOrDying() &&
791
+ !this.workspace.options.readOnly
792
+ );
793
+ }
794
+
795
+ /**
796
+ * Return whether this block's own deletable property is true or false.
797
+ *
798
+ * @returns True if the block's deletable property is true, false otherwise.
799
+ */
800
+ isOwnDeletable(): boolean {
801
+ return this.deletable_;
802
+ }
803
+
804
+ /**
805
+ * Set whether this block is deletable or not.
806
+ *
807
+ * @param deletable True if deletable.
808
+ */
809
+ setDeletable(deletable: boolean) {
810
+ this.deletable_ = deletable;
811
+ }
812
+
813
+ /**
814
+ * Get whether this block is movable or not.
815
+ *
816
+ * @returns True if movable.
817
+ * @internal
818
+ */
819
+ isMovable(): boolean {
820
+ return (
821
+ this.movable_ &&
822
+ !this.isShadow_ &&
823
+ !this.isDeadOrDying() &&
824
+ !this.workspace.options.readOnly
825
+ );
826
+ }
827
+
828
+ /**
829
+ * Return whether this block's own movable property is true or false.
830
+ *
831
+ * @returns True if the block's movable property is true, false otherwise.
832
+ * @internal
833
+ */
834
+ isOwnMovable(): boolean {
835
+ return this.movable_;
836
+ }
837
+
838
+ /**
839
+ * Set whether this block is movable or not.
840
+ *
841
+ * @param movable True if movable.
842
+ */
843
+ setMovable(movable: boolean) {
844
+ this.movable_ = movable;
845
+ }
846
+
847
+ /**
848
+ * Get whether is block is duplicatable or not. If duplicating this block and
849
+ * descendants will put this block over the workspace's capacity this block is
850
+ * not duplicatable. If duplicating this block and descendants will put any
851
+ * type over their maxInstances this block is not duplicatable.
852
+ *
853
+ * @returns True if duplicatable.
854
+ */
855
+ isDuplicatable(): boolean {
856
+ if (!this.workspace.hasBlockLimits()) {
857
+ return true;
858
+ }
859
+ return this.workspace.isCapacityAvailable(
860
+ common.getBlockTypeCounts(this, true),
861
+ );
862
+ }
863
+
864
+ /**
865
+ * Get whether this block is a shadow block or not.
866
+ *
867
+ * @returns True if a shadow.
868
+ */
869
+ isShadow(): boolean {
870
+ return this.isShadow_;
871
+ }
872
+
873
+ /**
874
+ * Set whether this block is a shadow block or not.
875
+ * This method is internal and should not be called by users of Blockly. To
876
+ * create shadow blocks programmatically call connection.setShadowState
877
+ *
878
+ * @param shadow True if a shadow.
879
+ * @internal
880
+ */
881
+ setShadow(shadow: boolean) {
882
+ this.isShadow_ = shadow;
883
+ }
884
+
885
+ /**
886
+ * Get whether this block is an insertion marker block or not.
887
+ *
888
+ * @returns True if an insertion marker.
889
+ */
890
+ isInsertionMarker(): boolean {
891
+ return this.isInsertionMarker_;
892
+ }
893
+
894
+ /**
895
+ * Set whether this block is an insertion marker block or not.
896
+ * Once set this cannot be unset.
897
+ *
898
+ * @param insertionMarker True if an insertion marker.
899
+ * @internal
900
+ */
901
+ setInsertionMarker(insertionMarker: boolean) {
902
+ this.isInsertionMarker_ = insertionMarker;
903
+ }
904
+
905
+ /**
906
+ * Get whether this block is editable or not.
907
+ *
908
+ * @returns True if editable.
909
+ * @internal
910
+ */
911
+ isEditable(): boolean {
912
+ return (
913
+ this.editable_ &&
914
+ !this.isDeadOrDying() &&
915
+ !this.workspace.options.readOnly
916
+ );
917
+ }
918
+
919
+ /**
920
+ * Return whether this block's own editable property is true or false.
921
+ *
922
+ * @returns True if the block's editable property is true, false otherwise.
923
+ */
924
+ isOwnEditable(): boolean {
925
+ return this.editable_;
926
+ }
927
+
928
+ /**
929
+ * Set whether this block is editable or not.
930
+ *
931
+ * @param editable True if editable.
932
+ */
933
+ setEditable(editable: boolean) {
934
+ this.editable_ = editable;
935
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
936
+ for (let j = 0, field; (field = input.fieldRow[j]); j++) {
937
+ field.updateEditable();
938
+ }
939
+ }
940
+ }
941
+
942
+ /**
943
+ * Returns if this block has been disposed of / deleted.
944
+ *
945
+ * @returns True if this block has been disposed of / deleted.
946
+ */
947
+ isDisposed(): boolean {
948
+ return this.disposed;
949
+ }
950
+
951
+ /**
952
+ * @returns True if this block is a value block with a single editable field.
953
+ * @internal
954
+ */
955
+ isSimpleReporter(): boolean {
956
+ if (!this.outputConnection) return false;
957
+
958
+ for (const input of this.inputList) {
959
+ if (input.connection || input.fieldRow.length > 1) return false;
960
+ }
961
+ return true;
962
+ }
963
+
964
+ /**
965
+ * Find the connection on this block that corresponds to the given connection
966
+ * on the other block.
967
+ * Used to match connections between a block and its insertion marker.
968
+ *
969
+ * @param otherBlock The other block to match against.
970
+ * @param conn The other connection to match.
971
+ * @returns The matching connection on this block, or null.
972
+ * @internal
973
+ */
974
+ getMatchingConnection(
975
+ otherBlock: Block,
976
+ conn: Connection,
977
+ ): Connection | null {
978
+ const connections = this.getConnections_(true);
979
+ const otherConnections = otherBlock.getConnections_(true);
980
+ if (connections.length !== otherConnections.length) {
981
+ throw Error('Connection lists did not match in length.');
982
+ }
983
+ for (let i = 0; i < otherConnections.length; i++) {
984
+ if (otherConnections[i] === conn) {
985
+ return connections[i];
986
+ }
987
+ }
988
+ return null;
989
+ }
990
+
991
+ /**
992
+ * Set the URL of this block's help page.
993
+ *
994
+ * @param url URL string for block help, or function that returns a URL. Null
995
+ * for no help.
996
+ */
997
+ setHelpUrl(url: string | Function) {
998
+ this.helpUrl = url;
999
+ }
1000
+
1001
+ /**
1002
+ * Sets the tooltip for this block.
1003
+ *
1004
+ * @param newTip The text for the tooltip, a function that returns the text
1005
+ * for the tooltip, or a parent object whose tooltip will be used. To not
1006
+ * display a tooltip pass the empty string.
1007
+ */
1008
+ setTooltip(newTip: Tooltip.TipInfo) {
1009
+ this.tooltip = newTip;
1010
+ }
1011
+
1012
+ /**
1013
+ * Returns the tooltip text for this block.
1014
+ *
1015
+ * @returns The tooltip text for this block.
1016
+ */
1017
+ getTooltip(): string {
1018
+ return Tooltip.getTooltipOfObject(this);
1019
+ }
1020
+
1021
+ /**
1022
+ * Get the colour of a block.
1023
+ *
1024
+ * @returns #RRGGBB string.
1025
+ */
1026
+ getColour(): string {
1027
+ return this.colour_;
1028
+ }
1029
+
1030
+ /**
1031
+ * Get the name of the block style.
1032
+ *
1033
+ * @returns Name of the block style.
1034
+ */
1035
+ getStyleName(): string {
1036
+ return this.styleName_;
1037
+ }
1038
+
1039
+ /**
1040
+ * Get the HSV hue value of a block. Null if hue not set.
1041
+ *
1042
+ * @returns Hue value (0-360).
1043
+ */
1044
+ getHue(): number | null {
1045
+ return this.hue_;
1046
+ }
1047
+
1048
+ /**
1049
+ * Change the colour of a block.
1050
+ *
1051
+ * @param colour HSV hue value (0 to 360), #RRGGBB string, or a message
1052
+ * reference string pointing to one of those two values.
1053
+ */
1054
+ setColour(colour: number | string) {
1055
+ const parsed = parsing.parseBlockColour(colour);
1056
+ this.hue_ = parsed.hue;
1057
+ this.colour_ = parsed.hex;
1058
+ }
1059
+
1060
+ /**
1061
+ * Set the style and colour values of a block.
1062
+ *
1063
+ * @param blockStyleName Name of the block style.
1064
+ */
1065
+ setStyle(blockStyleName: string) {
1066
+ this.styleName_ = blockStyleName;
1067
+ }
1068
+
1069
+ /**
1070
+ * Sets a callback function to use whenever the block's parent workspace
1071
+ * changes, replacing any prior onchange handler. This is usually only called
1072
+ * from the constructor, the block type initializer function, or an extension
1073
+ * initializer function.
1074
+ *
1075
+ * @param onchangeFn The callback to call when the block's workspace changes.
1076
+ * @throws {Error} if onchangeFn is not falsey and not a function.
1077
+ */
1078
+ setOnChange(onchangeFn: (p1: Abstract) => void) {
1079
+ if (onchangeFn && typeof onchangeFn !== 'function') {
1080
+ throw Error('onchange must be a function.');
1081
+ }
1082
+ if (this.onchangeWrapper_) {
1083
+ this.workspace.removeChangeListener(this.onchangeWrapper_);
1084
+ }
1085
+ this.onchange = onchangeFn;
1086
+ this.onchangeWrapper_ = onchangeFn.bind(this);
1087
+ this.workspace.addChangeListener(this.onchangeWrapper_);
1088
+ }
1089
+
1090
+ /**
1091
+ * Returns the named field from a block.
1092
+ *
1093
+ * @param name The name of the field.
1094
+ * @returns Named field, or null if field does not exist.
1095
+ */
1096
+ getField(name: string): Field | null {
1097
+ if (typeof name !== 'string') {
1098
+ throw TypeError(
1099
+ 'Block.prototype.getField expects a string ' +
1100
+ 'with the field name but received ' +
1101
+ (name === undefined ? 'nothing' : name + ' of type ' + typeof name) +
1102
+ ' instead',
1103
+ );
1104
+ }
1105
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
1106
+ for (let j = 0, field; (field = input.fieldRow[j]); j++) {
1107
+ if (field.name === name) {
1108
+ return field;
1109
+ }
1110
+ }
1111
+ }
1112
+ return null;
1113
+ }
1114
+
1115
+ /**
1116
+ * Return all variables referenced by this block.
1117
+ *
1118
+ * @returns List of variable ids.
1119
+ */
1120
+ getVars(): string[] {
1121
+ const vars: string[] = [];
1122
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
1123
+ for (let j = 0, field; (field = input.fieldRow[j]); j++) {
1124
+ if (field.referencesVariables()) {
1125
+ // NOTE: This only applies to `FieldVariable`, a `Field<string>`
1126
+ vars.push(field.getValue() as string);
1127
+ }
1128
+ }
1129
+ }
1130
+ return vars;
1131
+ }
1132
+
1133
+ /**
1134
+ * Return all variables referenced by this block.
1135
+ *
1136
+ * @returns List of variable models.
1137
+ * @internal
1138
+ */
1139
+ getVarModels(): IVariableModel<IVariableState>[] {
1140
+ const vars = [];
1141
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
1142
+ for (let j = 0, field; (field = input.fieldRow[j]); j++) {
1143
+ if (field.referencesVariables()) {
1144
+ const model = this.workspace.getVariableById(
1145
+ field.getValue() as string,
1146
+ );
1147
+ // Check if the variable actually exists (and isn't just a potential
1148
+ // variable).
1149
+ if (model) {
1150
+ vars.push(model);
1151
+ }
1152
+ }
1153
+ }
1154
+ }
1155
+ return vars;
1156
+ }
1157
+
1158
+ /**
1159
+ * Notification that a variable is renaming but keeping the same ID. If the
1160
+ * variable is in use on this block, rerender to show the new name.
1161
+ *
1162
+ * @param variable The variable being renamed.
1163
+ * @internal
1164
+ */
1165
+ updateVarName(variable: IVariableModel<IVariableState>) {
1166
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
1167
+ for (let j = 0, field; (field = input.fieldRow[j]); j++) {
1168
+ if (
1169
+ field.referencesVariables() &&
1170
+ variable.getId() === field.getValue()
1171
+ ) {
1172
+ field.refreshVariableName();
1173
+ }
1174
+ }
1175
+ }
1176
+ }
1177
+
1178
+ /**
1179
+ * Notification that a variable is renaming.
1180
+ * If the ID matches one of this block's variables, rename it.
1181
+ *
1182
+ * @param oldId ID of variable to rename.
1183
+ * @param newId ID of new variable. May be the same as oldId, but with an
1184
+ * updated name.
1185
+ */
1186
+ renameVarById(oldId: string, newId: string) {
1187
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
1188
+ for (let j = 0, field; (field = input.fieldRow[j]); j++) {
1189
+ if (field.referencesVariables() && oldId === field.getValue()) {
1190
+ field.setValue(newId);
1191
+ }
1192
+ }
1193
+ }
1194
+ }
1195
+
1196
+ /**
1197
+ * Returns the language-neutral value of the given field.
1198
+ *
1199
+ * @param name The name of the field.
1200
+ * @returns Value of the field or null if field does not exist.
1201
+ */
1202
+ getFieldValue(name: string): AnyDuringMigration {
1203
+ const field = this.getField(name);
1204
+ if (field) {
1205
+ return field.getValue();
1206
+ }
1207
+ return null;
1208
+ }
1209
+
1210
+ /**
1211
+ * Sets the value of the given field for this block.
1212
+ *
1213
+ * @param newValue The value to set.
1214
+ * @param name The name of the field to set the value of.
1215
+ */
1216
+ setFieldValue(newValue: AnyDuringMigration, name: string) {
1217
+ const field = this.getField(name);
1218
+ if (!field) {
1219
+ throw Error('Field "' + name + '" not found.');
1220
+ }
1221
+ field.setValue(newValue);
1222
+ }
1223
+
1224
+ /**
1225
+ * Set whether this block can chain onto the bottom of another block.
1226
+ *
1227
+ * @param newBoolean True if there can be a previous statement.
1228
+ * @param opt_check Statement type or list of statement types. Null/undefined
1229
+ * if any type could be connected.
1230
+ */
1231
+ setPreviousStatement(
1232
+ newBoolean: boolean,
1233
+ opt_check?: string | string[] | null,
1234
+ ) {
1235
+ if (newBoolean) {
1236
+ if (opt_check === undefined) {
1237
+ opt_check = null;
1238
+ }
1239
+ if (!this.previousConnection) {
1240
+ this.previousConnection = this.makeConnection_(
1241
+ ConnectionType.PREVIOUS_STATEMENT,
1242
+ );
1243
+ }
1244
+ this.previousConnection.setCheck(opt_check);
1245
+ } else {
1246
+ if (this.previousConnection) {
1247
+ if (this.previousConnection.isConnected()) {
1248
+ throw Error(
1249
+ 'Must disconnect previous statement before removing ' +
1250
+ 'connection.',
1251
+ );
1252
+ }
1253
+ this.previousConnection.dispose();
1254
+ this.previousConnection = null;
1255
+ }
1256
+ }
1257
+ }
1258
+
1259
+ /**
1260
+ * Set whether another block can chain onto the bottom of this block.
1261
+ *
1262
+ * @param newBoolean True if there can be a next statement.
1263
+ * @param opt_check Statement type or list of statement types. Null/undefined
1264
+ * if any type could be connected.
1265
+ */
1266
+ setNextStatement(newBoolean: boolean, opt_check?: string | string[] | null) {
1267
+ if (newBoolean) {
1268
+ if (opt_check === undefined) {
1269
+ opt_check = null;
1270
+ }
1271
+ if (!this.nextConnection) {
1272
+ this.nextConnection = this.makeConnection_(
1273
+ ConnectionType.NEXT_STATEMENT,
1274
+ );
1275
+ }
1276
+ this.nextConnection.setCheck(opt_check);
1277
+ } else {
1278
+ if (this.nextConnection) {
1279
+ if (this.nextConnection.isConnected()) {
1280
+ throw Error(
1281
+ 'Must disconnect next statement before removing ' + 'connection.',
1282
+ );
1283
+ }
1284
+ this.nextConnection.dispose();
1285
+ this.nextConnection = null;
1286
+ }
1287
+ }
1288
+ }
1289
+
1290
+ /**
1291
+ * Set whether this block returns a value.
1292
+ *
1293
+ * @param newBoolean True if there is an output.
1294
+ * @param opt_check Returned type or list of returned types. Null or
1295
+ * undefined if any type could be returned (e.g. variable get).
1296
+ */
1297
+ setOutput(newBoolean: boolean, opt_check?: string | string[] | null) {
1298
+ if (newBoolean) {
1299
+ if (opt_check === undefined) {
1300
+ opt_check = null;
1301
+ }
1302
+ if (!this.outputConnection) {
1303
+ this.outputConnection = this.makeConnection_(
1304
+ ConnectionType.OUTPUT_VALUE,
1305
+ );
1306
+ }
1307
+ this.outputConnection.setCheck(opt_check);
1308
+ } else {
1309
+ if (this.outputConnection) {
1310
+ if (this.outputConnection.isConnected()) {
1311
+ throw Error(
1312
+ 'Must disconnect output value before removing connection.',
1313
+ );
1314
+ }
1315
+ this.outputConnection.dispose();
1316
+ this.outputConnection = null;
1317
+ }
1318
+ }
1319
+ }
1320
+
1321
+ /**
1322
+ * Set whether value inputs are arranged horizontally or vertically.
1323
+ *
1324
+ * @param newBoolean True if inputs are horizontal.
1325
+ */
1326
+ setInputsInline(newBoolean: boolean) {
1327
+ if (this.inputsInline !== newBoolean) {
1328
+ eventUtils.fire(
1329
+ new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
1330
+ this,
1331
+ 'inline',
1332
+ null,
1333
+ this.inputsInline,
1334
+ newBoolean,
1335
+ ),
1336
+ );
1337
+ this.inputsInline = newBoolean;
1338
+ }
1339
+ }
1340
+
1341
+ /**
1342
+ * Get whether value inputs are arranged horizontally or vertically.
1343
+ *
1344
+ * @returns True if inputs are horizontal.
1345
+ */
1346
+ getInputsInline(): boolean {
1347
+ if (this.inputsInline !== undefined) {
1348
+ // Set explicitly.
1349
+ return this.inputsInline;
1350
+ }
1351
+ // Not defined explicitly. Figure out what would look best.
1352
+ for (let i = 1; i < this.inputList.length; i++) {
1353
+ if (
1354
+ this.inputList[i - 1] instanceof DummyInput &&
1355
+ this.inputList[i] instanceof DummyInput
1356
+ ) {
1357
+ // Two dummy inputs in a row. Don't inline them.
1358
+ return false;
1359
+ }
1360
+ }
1361
+ for (let i = 1; i < this.inputList.length; i++) {
1362
+ if (
1363
+ this.inputList[i - 1] instanceof ValueInput &&
1364
+ this.inputList[i] instanceof DummyInput
1365
+ ) {
1366
+ // Dummy input after a value input. Inline them.
1367
+ return true;
1368
+ }
1369
+ }
1370
+ for (let i = 0; i < this.inputList.length; i++) {
1371
+ if (this.inputList[i] instanceof EndRowInput) {
1372
+ // A row-end input is present. Inline value inputs.
1373
+ return true;
1374
+ }
1375
+ }
1376
+ return false;
1377
+ }
1378
+
1379
+ /**
1380
+ * Set the block's output shape.
1381
+ *
1382
+ * @param outputShape Value representing an output shape.
1383
+ */
1384
+ setOutputShape(outputShape: number | null) {
1385
+ this.outputShape_ = outputShape;
1386
+ }
1387
+
1388
+ /**
1389
+ * Get the block's output shape.
1390
+ *
1391
+ * @returns Value representing output shape if one exists.
1392
+ */
1393
+ getOutputShape(): number | null {
1394
+ return this.outputShape_;
1395
+ }
1396
+
1397
+ /**
1398
+ * Get whether this block is enabled or not. A block is considered enabled
1399
+ * if there aren't any reasons why it would be disabled. A block may still
1400
+ * be disabled for other reasons even if the user attempts to manually
1401
+ * enable it, such as when the block is in an invalid location.
1402
+ *
1403
+ * @returns True if enabled.
1404
+ */
1405
+ isEnabled(): boolean {
1406
+ return this.disabledReasons.size === 0;
1407
+ }
1408
+
1409
+ /** @deprecated v11 - Get whether the block is manually disabled. */
1410
+ private get disabled(): boolean {
1411
+ deprecation.warn(
1412
+ 'disabled',
1413
+ 'v11',
1414
+ 'v12',
1415
+ 'the isEnabled or hasDisabledReason methods of Block',
1416
+ );
1417
+ return this.hasDisabledReason(constants.MANUALLY_DISABLED);
1418
+ }
1419
+
1420
+ /** @deprecated v11 - Set whether the block is manually disabled. */
1421
+ private set disabled(value: boolean) {
1422
+ deprecation.warn(
1423
+ 'disabled',
1424
+ 'v11',
1425
+ 'v12',
1426
+ 'the setDisabledReason method of Block',
1427
+ );
1428
+ this.setDisabledReason(value, constants.MANUALLY_DISABLED);
1429
+ }
1430
+
1431
+ /**
1432
+ * @deprecated v11 - Set whether the block is manually enabled or disabled.
1433
+ * The user can toggle whether a block is disabled from a context menu
1434
+ * option. A block may still be disabled for other reasons even if the user
1435
+ * attempts to manually enable it, such as when the block is in an invalid
1436
+ * location. This method is deprecated and setDisabledReason should be used
1437
+ * instead.
1438
+ *
1439
+ * @param enabled True if enabled.
1440
+ */
1441
+ setEnabled(enabled: boolean) {
1442
+ deprecation.warn(
1443
+ 'setEnabled',
1444
+ 'v11',
1445
+ 'v12',
1446
+ 'the setDisabledReason method of Block',
1447
+ );
1448
+ this.setDisabledReason(!enabled, constants.MANUALLY_DISABLED);
1449
+ }
1450
+
1451
+ /**
1452
+ * Add or remove a reason why the block might be disabled. If a block has
1453
+ * any reasons to be disabled, then the block itself will be considered
1454
+ * disabled. A block could be disabled for multiple independent reasons
1455
+ * simultaneously, such as when the user manually disables it, or the block
1456
+ * is invalid.
1457
+ *
1458
+ * @param disabled If true, then the block should be considered disabled for
1459
+ * at least the provided reason, otherwise the block is no longer disabled
1460
+ * for that reason.
1461
+ * @param reason A language-neutral identifier for a reason why the block
1462
+ * could be disabled. Call this method again with the same identifier to
1463
+ * update whether the block is currently disabled for this reason.
1464
+ */
1465
+ setDisabledReason(disabled: boolean, reason: string): void {
1466
+ if (this.disabledReasons.has(reason) !== disabled) {
1467
+ if (disabled) {
1468
+ this.disabledReasons.add(reason);
1469
+ } else {
1470
+ this.disabledReasons.delete(reason);
1471
+ }
1472
+ const blockChangeEvent = new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
1473
+ this,
1474
+ 'disabled',
1475
+ /* name= */ null,
1476
+ /* oldValue= */ !disabled,
1477
+ /* newValue= */ disabled,
1478
+ ) as BlockChange;
1479
+ blockChangeEvent.setDisabledReason(reason);
1480
+ eventUtils.fire(blockChangeEvent);
1481
+ }
1482
+ }
1483
+
1484
+ /**
1485
+ * Get whether the block is disabled or not due to parents.
1486
+ * The block's own disabled property is not considered.
1487
+ *
1488
+ * @returns True if disabled.
1489
+ */
1490
+ getInheritedDisabled(): boolean {
1491
+ let ancestor = this.getSurroundParent();
1492
+ while (ancestor) {
1493
+ if (!ancestor.isEnabled()) {
1494
+ return true;
1495
+ }
1496
+ ancestor = ancestor.getSurroundParent();
1497
+ }
1498
+ // Ran off the top.
1499
+ return false;
1500
+ }
1501
+
1502
+ /**
1503
+ * Get whether the block is currently disabled for the provided reason.
1504
+ *
1505
+ * @param reason A language-neutral identifier for a reason why the block
1506
+ * could be disabled.
1507
+ * @returns Whether the block is disabled for the provided reason.
1508
+ */
1509
+ hasDisabledReason(reason: string): boolean {
1510
+ return this.disabledReasons.has(reason);
1511
+ }
1512
+
1513
+ /**
1514
+ * Get a set of reasons why the block is currently disabled, if any. If the
1515
+ * block is enabled, this set will be empty.
1516
+ *
1517
+ * @returns The set of reasons why the block is disabled, if any.
1518
+ */
1519
+ getDisabledReasons(): ReadonlySet<string> {
1520
+ return this.disabledReasons;
1521
+ }
1522
+
1523
+ /**
1524
+ * Get whether the block is collapsed or not.
1525
+ *
1526
+ * @returns True if collapsed.
1527
+ */
1528
+ isCollapsed(): boolean {
1529
+ return this.collapsed_;
1530
+ }
1531
+
1532
+ /**
1533
+ * Set whether the block is collapsed or not.
1534
+ *
1535
+ * @param collapsed True if collapsed.
1536
+ */
1537
+ setCollapsed(collapsed: boolean) {
1538
+ if (this.collapsed_ !== collapsed) {
1539
+ eventUtils.fire(
1540
+ new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
1541
+ this,
1542
+ 'collapsed',
1543
+ null,
1544
+ this.collapsed_,
1545
+ collapsed,
1546
+ ),
1547
+ );
1548
+ this.collapsed_ = collapsed;
1549
+ }
1550
+ }
1551
+
1552
+ /**
1553
+ * Create a human-readable text representation of this block and any children.
1554
+ *
1555
+ * @param opt_maxLength Truncate the string to this length.
1556
+ * @param opt_emptyToken The placeholder string used to denote an empty input.
1557
+ * If not specified, '?' is used.
1558
+ * @returns Text of block.
1559
+ */
1560
+ toString(opt_maxLength?: number, opt_emptyToken?: string): string {
1561
+ const tokens = this.toTokens(opt_emptyToken);
1562
+
1563
+ // Run through our tokens array and simplify expression to remove
1564
+ // parentheses around single field blocks.
1565
+ // E.g. ['repeat', '(', '10', ')', 'times', 'do', '?']
1566
+ for (let i = 2; i < tokens.length; i++) {
1567
+ if (tokens[i - 2] === '(' && tokens[i] === ')') {
1568
+ tokens[i - 2] = tokens[i - 1];
1569
+ tokens.splice(i - 1, 2);
1570
+ }
1571
+ }
1572
+
1573
+ // Join the text array, removing the spaces around added parentheses.
1574
+ let prev = '';
1575
+ let text: string = tokens.reduce((acc, curr) => {
1576
+ const val = acc + (prev === '(' || curr === ')' ? '' : ' ') + curr;
1577
+ prev = curr[curr.length - 1];
1578
+ return val;
1579
+ }, '');
1580
+
1581
+ text = text.trim() || '???';
1582
+ if (opt_maxLength) {
1583
+ // TODO: Improve truncation so that text from this block is given
1584
+ // priority. E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not
1585
+ // "1+2+3+4+5...". E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...".
1586
+ if (text.length > opt_maxLength) {
1587
+ text = text.substring(0, opt_maxLength - 3) + '...';
1588
+ }
1589
+ }
1590
+ return text;
1591
+ }
1592
+
1593
+ /**
1594
+ * Converts this block into string tokens.
1595
+ *
1596
+ * @param emptyToken The token to use in place of an empty input.
1597
+ * Defaults to '?'.
1598
+ * @returns The array of string tokens representing this block.
1599
+ */
1600
+ private toTokens(emptyToken = '?'): string[] {
1601
+ const tokens = [];
1602
+ /**
1603
+ * Whether or not to add parentheses around an input.
1604
+ *
1605
+ * @param connection The connection.
1606
+ * @returns True if we should add parentheses around the input.
1607
+ */
1608
+ function shouldAddParentheses(connection: Connection): boolean {
1609
+ let checks = connection.getCheck();
1610
+ if (!checks && connection.targetConnection) {
1611
+ checks = connection.targetConnection.getCheck();
1612
+ }
1613
+ return (
1614
+ !!checks && (checks.includes('Boolean') || checks.includes('Number'))
1615
+ );
1616
+ }
1617
+
1618
+ for (const input of this.inputList) {
1619
+ if (input.name == constants.COLLAPSED_INPUT_NAME) {
1620
+ continue;
1621
+ }
1622
+ for (const field of input.fieldRow) {
1623
+ tokens.push(field.getText());
1624
+ }
1625
+ if (input.connection) {
1626
+ const child = input.connection.targetBlock();
1627
+ if (child) {
1628
+ const shouldAddParens = shouldAddParentheses(input.connection);
1629
+ if (shouldAddParens) tokens.push('(');
1630
+ tokens.push(...child.toTokens(emptyToken));
1631
+ if (shouldAddParens) tokens.push(')');
1632
+ } else {
1633
+ tokens.push(emptyToken);
1634
+ }
1635
+ }
1636
+ }
1637
+ return tokens;
1638
+ }
1639
+
1640
+ /**
1641
+ * Appends a value input row.
1642
+ *
1643
+ * @param name Language-neutral identifier which may used to find this input
1644
+ * again. Should be unique to this block.
1645
+ * @returns The input object created.
1646
+ */
1647
+ appendValueInput(name: string): Input {
1648
+ return this.appendInput(new ValueInput(name, this));
1649
+ }
1650
+
1651
+ /**
1652
+ * Appends a statement input row.
1653
+ *
1654
+ * @param name Language-neutral identifier which may used to find this input
1655
+ * again. Should be unique to this block.
1656
+ * @returns The input object created.
1657
+ */
1658
+ appendStatementInput(name: string): Input {
1659
+ this.statementInputCount++;
1660
+ return this.appendInput(new StatementInput(name, this));
1661
+ }
1662
+
1663
+ /**
1664
+ * Appends a dummy input row.
1665
+ *
1666
+ * @param name Optional language-neutral identifier which may used to find
1667
+ * this input again. Should be unique to this block.
1668
+ * @returns The input object created.
1669
+ */
1670
+ appendDummyInput(name = ''): Input {
1671
+ return this.appendInput(new DummyInput(name, this));
1672
+ }
1673
+
1674
+ /**
1675
+ * Appends an input that ends the row.
1676
+ *
1677
+ * @param name Optional language-neutral identifier which may used to find
1678
+ * this input again. Should be unique to this block.
1679
+ * @returns The input object created.
1680
+ */
1681
+ appendEndRowInput(name = ''): Input {
1682
+ return this.appendInput(new EndRowInput(name, this));
1683
+ }
1684
+
1685
+ /**
1686
+ * Appends the given input row.
1687
+ *
1688
+ * Allows for custom inputs to be appended to the block.
1689
+ */
1690
+ appendInput(input: Input): Input {
1691
+ this.inputList.push(input);
1692
+ return input;
1693
+ }
1694
+
1695
+ /**
1696
+ * Appends an input with the given input type and name to the block after
1697
+ * constructing it from the registry.
1698
+ *
1699
+ * @param type The name the input is registered under in the registry.
1700
+ * @param name The name the input will have within the block.
1701
+ * @returns The constucted input, or null if there was no constructor
1702
+ * associated with the type.
1703
+ */
1704
+ private appendInputFromRegistry(type: string, name: string): Input | null {
1705
+ const inputConstructor = registry.getClass(
1706
+ registry.Type.INPUT,
1707
+ type,
1708
+ false,
1709
+ );
1710
+ if (!inputConstructor) return null;
1711
+ return this.appendInput(new inputConstructor(name, this));
1712
+ }
1713
+
1714
+ /**
1715
+ * Initialize this block using a cross-platform, internationalization-friendly
1716
+ * JSON description.
1717
+ *
1718
+ * @param json Structured data describing the block.
1719
+ */
1720
+ jsonInit(json: AnyDuringMigration) {
1721
+ const warningPrefix = json['type'] ? 'Block "' + json['type'] + '": ' : '';
1722
+
1723
+ // Validate inputs.
1724
+ if (json['output'] && json['previousStatement']) {
1725
+ throw Error(
1726
+ warningPrefix + 'Must not have both an output and a previousStatement.',
1727
+ );
1728
+ }
1729
+
1730
+ // Validate that each arg has a corresponding message
1731
+ let n = 0;
1732
+ while (json['args' + n]) {
1733
+ if (json['message' + n] === undefined) {
1734
+ throw Error(
1735
+ warningPrefix +
1736
+ `args${n} must have a corresponding message (message${n}).`,
1737
+ );
1738
+ }
1739
+ n++;
1740
+ }
1741
+
1742
+ // Set basic properties of block.
1743
+ // Makes styles backward compatible with old way of defining hat style.
1744
+ if (json['style'] && json['style'].hat) {
1745
+ this.hat = json['style'].hat;
1746
+ // Must set to null so it doesn't error when checking for style and
1747
+ // colour.
1748
+ json['style'] = null;
1749
+ }
1750
+
1751
+ if (json['style'] && json['colour']) {
1752
+ throw Error(warningPrefix + 'Must not have both a colour and a style.');
1753
+ } else if (json['style']) {
1754
+ this.jsonInitStyle_(json, warningPrefix);
1755
+ } else {
1756
+ this.jsonInitColour_(json, warningPrefix);
1757
+ }
1758
+
1759
+ // Interpolate the message blocks.
1760
+ let i = 0;
1761
+ while (json['message' + i] !== undefined) {
1762
+ this.interpolate_(
1763
+ json['message' + i],
1764
+ json['args' + i] || [],
1765
+ // Backwards compatibility: lastDummyAlign aliases implicitAlign.
1766
+ json['implicitAlign' + i] || json['lastDummyAlign' + i],
1767
+ warningPrefix,
1768
+ );
1769
+ i++;
1770
+ }
1771
+
1772
+ if (json['inputsInline'] !== undefined) {
1773
+ eventUtils.disable();
1774
+ this.setInputsInline(json['inputsInline']);
1775
+ eventUtils.enable();
1776
+ }
1777
+
1778
+ // Set output and previous/next connections.
1779
+ if (json['output'] !== undefined) {
1780
+ this.setOutput(true, json['output']);
1781
+ }
1782
+ if (json['outputShape'] !== undefined) {
1783
+ this.setOutputShape(json['outputShape']);
1784
+ }
1785
+ if (json['previousStatement'] !== undefined) {
1786
+ this.setPreviousStatement(true, json['previousStatement']);
1787
+ }
1788
+ if (json['nextStatement'] !== undefined) {
1789
+ this.setNextStatement(true, json['nextStatement']);
1790
+ }
1791
+ if (json['tooltip'] !== undefined) {
1792
+ const rawValue = json['tooltip'];
1793
+ const localizedText = parsing.replaceMessageReferences(rawValue);
1794
+ this.setTooltip(localizedText);
1795
+ }
1796
+ if (json['enableContextMenu'] !== undefined) {
1797
+ this.contextMenu = !!json['enableContextMenu'];
1798
+ }
1799
+ if (json['suppressPrefixSuffix'] !== undefined) {
1800
+ this.suppressPrefixSuffix = !!json['suppressPrefixSuffix'];
1801
+ }
1802
+ if (json['helpUrl'] !== undefined) {
1803
+ const rawValue = json['helpUrl'];
1804
+ const localizedValue = parsing.replaceMessageReferences(rawValue);
1805
+ this.setHelpUrl(localizedValue);
1806
+ }
1807
+ if (typeof json['extensions'] === 'string') {
1808
+ console.warn(
1809
+ warningPrefix +
1810
+ "JSON attribute 'extensions' should be an array of" +
1811
+ " strings. Found raw string in JSON for '" +
1812
+ json['type'] +
1813
+ "' block.",
1814
+ );
1815
+ json['extensions'] = [json['extensions']]; // Correct and continue.
1816
+ }
1817
+
1818
+ // Add the mutator to the block.
1819
+ if (json['mutator'] !== undefined) {
1820
+ Extensions.apply(json['mutator'], this, true);
1821
+ }
1822
+
1823
+ const extensionNames = json['extensions'];
1824
+ if (Array.isArray(extensionNames)) {
1825
+ for (let j = 0; j < extensionNames.length; j++) {
1826
+ Extensions.apply(extensionNames[j], this, false);
1827
+ }
1828
+ }
1829
+ }
1830
+
1831
+ /**
1832
+ * Initialize the colour of this block from the JSON description.
1833
+ *
1834
+ * @param json Structured data describing the block.
1835
+ * @param warningPrefix Warning prefix string identifying block.
1836
+ */
1837
+ private jsonInitColour_(json: AnyDuringMigration, warningPrefix: string) {
1838
+ if ('colour' in json) {
1839
+ if (json['colour'] === undefined) {
1840
+ console.warn(warningPrefix + 'Undefined colour value.');
1841
+ } else {
1842
+ const rawValue = json['colour'];
1843
+ try {
1844
+ this.setColour(rawValue);
1845
+ } catch (e) {
1846
+ console.warn(warningPrefix + 'Illegal colour value: ', rawValue);
1847
+ }
1848
+ }
1849
+ }
1850
+ }
1851
+
1852
+ /**
1853
+ * Initialize the style of this block from the JSON description.
1854
+ *
1855
+ * @param json Structured data describing the block.
1856
+ * @param warningPrefix Warning prefix string identifying block.
1857
+ */
1858
+ private jsonInitStyle_(json: AnyDuringMigration, warningPrefix: string) {
1859
+ const blockStyleName = json['style'];
1860
+ try {
1861
+ this.setStyle(blockStyleName);
1862
+ } catch (styleError) {
1863
+ console.warn(warningPrefix + 'Style does not exist: ', blockStyleName);
1864
+ }
1865
+ }
1866
+
1867
+ /**
1868
+ * Add key/values from mixinObj to this block object. By default, this method
1869
+ * will check that the keys in mixinObj will not overwrite existing values in
1870
+ * the block, including prototype values. This provides some insurance against
1871
+ * mixin / extension incompatibilities with future block features. This check
1872
+ * can be disabled by passing true as the second argument.
1873
+ *
1874
+ * @param mixinObj The key/values pairs to add to this block object.
1875
+ * @param opt_disableCheck Option flag to disable overwrite checks.
1876
+ */
1877
+ mixin(mixinObj: AnyDuringMigration, opt_disableCheck?: boolean) {
1878
+ if (
1879
+ opt_disableCheck !== undefined &&
1880
+ typeof opt_disableCheck !== 'boolean'
1881
+ ) {
1882
+ throw Error('opt_disableCheck must be a boolean if provided');
1883
+ }
1884
+ if (!opt_disableCheck) {
1885
+ const overwrites = [];
1886
+ for (const key in mixinObj) {
1887
+ if ((this as AnyDuringMigration)[key] !== undefined) {
1888
+ overwrites.push(key);
1889
+ }
1890
+ }
1891
+ if (overwrites.length) {
1892
+ throw Error(
1893
+ 'Mixin will overwrite block members: ' + JSON.stringify(overwrites),
1894
+ );
1895
+ }
1896
+ }
1897
+ Object.assign(this, mixinObj);
1898
+ }
1899
+
1900
+ /**
1901
+ * Interpolate a message description onto the block.
1902
+ *
1903
+ * @param message Text contains interpolation tokens (%1, %2, ...) that match
1904
+ * with fields or inputs defined in the args array.
1905
+ * @param args Array of arguments to be interpolated.
1906
+ * @param implicitAlign If an implicit input is added at the end or in place
1907
+ * of newline tokens, how should it be aligned?
1908
+ * @param warningPrefix Warning prefix string identifying block.
1909
+ */
1910
+ private interpolate_(
1911
+ message: string,
1912
+ args: AnyDuringMigration[],
1913
+ implicitAlign: string | undefined,
1914
+ warningPrefix: string,
1915
+ ) {
1916
+ const tokens = parsing.tokenizeInterpolation(message);
1917
+ this.validateTokens_(tokens, args.length);
1918
+ const elements = this.interpolateArguments_(tokens, args, implicitAlign);
1919
+
1920
+ // An array of [field, fieldName] tuples.
1921
+ const fieldStack = [];
1922
+ for (let i = 0, element; (element = elements[i]); i++) {
1923
+ if (this.isInputKeyword_(element['type'])) {
1924
+ const input = this.inputFromJson_(element, warningPrefix);
1925
+ // Should never be null, but just in case.
1926
+ if (input) {
1927
+ for (let j = 0, tuple; (tuple = fieldStack[j]); j++) {
1928
+ input.appendField(tuple[0], tuple[1]);
1929
+ }
1930
+ fieldStack.length = 0;
1931
+ }
1932
+ } else {
1933
+ // All other types, including ones starting with 'input_' get routed
1934
+ // here.
1935
+ const field = this.fieldFromJson_(element);
1936
+ if (field) {
1937
+ fieldStack.push([field, element['name']]);
1938
+ }
1939
+ }
1940
+ }
1941
+ }
1942
+
1943
+ /**
1944
+ * Validates that the tokens are within the correct bounds, with no
1945
+ * duplicates, and that all of the arguments are referred to. Throws errors if
1946
+ * any of these things are not true.
1947
+ *
1948
+ * @param tokens An array of tokens to validate
1949
+ * @param argsCount The number of args that need to be referred to.
1950
+ */
1951
+ private validateTokens_(tokens: Array<string | number>, argsCount: number) {
1952
+ const visitedArgsHash = [];
1953
+ let visitedArgsCount = 0;
1954
+ for (let i = 0; i < tokens.length; i++) {
1955
+ const token = tokens[i];
1956
+ if (typeof token !== 'number') {
1957
+ continue;
1958
+ }
1959
+ if (token < 1 || token > argsCount) {
1960
+ throw Error(
1961
+ 'Block "' +
1962
+ this.type +
1963
+ '": ' +
1964
+ 'Message index %' +
1965
+ token +
1966
+ ' out of range.',
1967
+ );
1968
+ }
1969
+ if (visitedArgsHash[token]) {
1970
+ throw Error(
1971
+ 'Block "' +
1972
+ this.type +
1973
+ '": ' +
1974
+ 'Message index %' +
1975
+ token +
1976
+ ' duplicated.',
1977
+ );
1978
+ }
1979
+ visitedArgsHash[token] = true;
1980
+ visitedArgsCount++;
1981
+ }
1982
+ if (visitedArgsCount !== argsCount) {
1983
+ throw Error(
1984
+ 'Block "' +
1985
+ this.type +
1986
+ '": ' +
1987
+ 'Message does not reference all ' +
1988
+ argsCount +
1989
+ ' arg(s).',
1990
+ );
1991
+ }
1992
+ }
1993
+
1994
+ /**
1995
+ * Inserts args in place of numerical tokens. String args are converted to
1996
+ * JSON that defines a label field. Newline characters are converted to
1997
+ * end-row inputs, and if necessary an extra dummy input is added to the end
1998
+ * of the elements.
1999
+ *
2000
+ * @param tokens The tokens to interpolate
2001
+ * @param args The arguments to insert.
2002
+ * @param implicitAlign The alignment to use for any implicitly added end-row
2003
+ * or dummy inputs, if necessary.
2004
+ * @returns The JSON definitions of field and inputs to add to the block.
2005
+ */
2006
+ private interpolateArguments_(
2007
+ tokens: Array<string | number>,
2008
+ args: Array<AnyDuringMigration | string>,
2009
+ implicitAlign: string | undefined,
2010
+ ): AnyDuringMigration[] {
2011
+ const elements = [];
2012
+ for (let i = 0; i < tokens.length; i++) {
2013
+ let element = tokens[i];
2014
+ if (typeof element === 'number') {
2015
+ element = args[element - 1];
2016
+ }
2017
+ // Args can be strings, which is why this isn't elseif.
2018
+ if (typeof element === 'string') {
2019
+ if (element === '\n') {
2020
+ // Convert newline tokens to end-row inputs.
2021
+ const newlineInput = {'type': 'input_end_row'};
2022
+ if (implicitAlign) {
2023
+ (newlineInput as AnyDuringMigration)['align'] = implicitAlign;
2024
+ }
2025
+ element = newlineInput as AnyDuringMigration;
2026
+ } else {
2027
+ // AnyDuringMigration because: Type '{ text: string; type: string; }
2028
+ // | null' is not assignable to type 'string | number'.
2029
+ element = this.stringToFieldJson_(element) as AnyDuringMigration;
2030
+ if (!element) {
2031
+ continue;
2032
+ }
2033
+ }
2034
+ }
2035
+ elements.push(element);
2036
+ }
2037
+
2038
+ const length = elements.length;
2039
+ if (
2040
+ length &&
2041
+ !this.isInputKeyword_(
2042
+ (elements as AnyDuringMigration)[length - 1]['type'],
2043
+ )
2044
+ ) {
2045
+ const dummyInput = {'type': 'input_dummy'};
2046
+ if (implicitAlign) {
2047
+ (dummyInput as AnyDuringMigration)['align'] = implicitAlign;
2048
+ }
2049
+ elements.push(dummyInput);
2050
+ }
2051
+
2052
+ return elements;
2053
+ }
2054
+
2055
+ /**
2056
+ * Creates a field from the JSON definition of a field. If a field with the
2057
+ * given type cannot be found, this attempts to create a different field using
2058
+ * the 'alt' property of the JSON definition (if it exists).
2059
+ *
2060
+ * @param element The element to try to turn into a field.
2061
+ * @returns The field defined by the JSON, or null if one couldn't be created.
2062
+ */
2063
+ private fieldFromJson_(element: {
2064
+ alt?: string;
2065
+ type: string;
2066
+ text?: string;
2067
+ }): Field | null {
2068
+ const field = fieldRegistry.fromJson(element);
2069
+ if (!field && element['alt']) {
2070
+ if (typeof element['alt'] === 'string') {
2071
+ const json = this.stringToFieldJson_(element['alt']);
2072
+ return json ? this.fieldFromJson_(json) : null;
2073
+ }
2074
+ return this.fieldFromJson_(element['alt']);
2075
+ }
2076
+ return field;
2077
+ }
2078
+
2079
+ /**
2080
+ * Creates an input from the JSON definition of an input. Sets the input's
2081
+ * check and alignment if they are provided.
2082
+ *
2083
+ * @param element The JSON to turn into an input.
2084
+ * @param warningPrefix The prefix to add to warnings to help the developer
2085
+ * debug.
2086
+ * @returns The input that has been created, or null if one could not be
2087
+ * created for some reason (should never happen).
2088
+ */
2089
+ private inputFromJson_(
2090
+ element: AnyDuringMigration,
2091
+ warningPrefix: string,
2092
+ ): Input | null {
2093
+ const alignmentLookup = {
2094
+ 'LEFT': Align.LEFT,
2095
+ 'RIGHT': Align.RIGHT,
2096
+ 'CENTRE': Align.CENTRE,
2097
+ 'CENTER': Align.CENTRE,
2098
+ };
2099
+
2100
+ let input = null;
2101
+ switch (element['type']) {
2102
+ case 'input_value':
2103
+ input = this.appendValueInput(element['name']);
2104
+ break;
2105
+ case 'input_statement':
2106
+ input = this.appendStatementInput(element['name']);
2107
+ break;
2108
+ case 'input_dummy':
2109
+ input = this.appendDummyInput(element['name']);
2110
+ break;
2111
+ case 'input_end_row':
2112
+ input = this.appendEndRowInput(element['name']);
2113
+ break;
2114
+ default: {
2115
+ input = this.appendInputFromRegistry(element['type'], element['name']);
2116
+ break;
2117
+ }
2118
+ }
2119
+ // Should never be hit because of interpolate_'s checks, but just in case.
2120
+ if (!input) {
2121
+ return null;
2122
+ }
2123
+
2124
+ if (element['check']) {
2125
+ input.setCheck(element['check']);
2126
+ }
2127
+ if (element['align']) {
2128
+ const alignment = (alignmentLookup as AnyDuringMigration)[
2129
+ element['align'].toUpperCase()
2130
+ ];
2131
+ if (alignment === undefined) {
2132
+ console.warn(warningPrefix + 'Illegal align value: ', element['align']);
2133
+ } else {
2134
+ input.setAlign(alignment);
2135
+ }
2136
+ }
2137
+ return input;
2138
+ }
2139
+
2140
+ /**
2141
+ * Returns true if the given string matches one of the input keywords.
2142
+ *
2143
+ * @param str The string to check.
2144
+ * @returns True if the given string matches one of the input keywords, false
2145
+ * otherwise.
2146
+ */
2147
+ private isInputKeyword_(str: string): boolean {
2148
+ return (
2149
+ str === 'input_value' ||
2150
+ str === 'input_statement' ||
2151
+ str === 'input_dummy' ||
2152
+ str === 'input_end_row' ||
2153
+ registry.hasItem(registry.Type.INPUT, str)
2154
+ );
2155
+ }
2156
+
2157
+ /**
2158
+ * Turns a string into the JSON definition of a label field. If the string
2159
+ * becomes an empty string when trimmed, this returns null.
2160
+ *
2161
+ * @param str String to turn into the JSON definition of a label field.
2162
+ * @returns The JSON definition or null.
2163
+ */
2164
+ private stringToFieldJson_(str: string): {text: string; type: string} | null {
2165
+ str = str.trim();
2166
+ if (str) {
2167
+ return {
2168
+ 'type': 'field_label',
2169
+ 'text': str,
2170
+ };
2171
+ }
2172
+ return null;
2173
+ }
2174
+
2175
+ /**
2176
+ * Move a named input to a different location on this block.
2177
+ *
2178
+ * @param name The name of the input to move.
2179
+ * @param refName Name of input that should be after the moved input, or null
2180
+ * to be the input at the end.
2181
+ */
2182
+ moveInputBefore(name: string, refName: string | null) {
2183
+ if (name === refName) {
2184
+ return;
2185
+ }
2186
+ // Find both inputs.
2187
+ let inputIndex = -1;
2188
+ let refIndex = refName ? -1 : this.inputList.length;
2189
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
2190
+ if (input.name === name) {
2191
+ inputIndex = i;
2192
+ if (refIndex !== -1) {
2193
+ break;
2194
+ }
2195
+ } else if (refName && input.name === refName) {
2196
+ refIndex = i;
2197
+ if (inputIndex !== -1) {
2198
+ break;
2199
+ }
2200
+ }
2201
+ }
2202
+ if (inputIndex === -1) {
2203
+ throw Error('Named input "' + name + '" not found.');
2204
+ }
2205
+ if (refIndex === -1) {
2206
+ throw Error('Reference input "' + refName + '" not found.');
2207
+ }
2208
+ this.moveNumberedInputBefore(inputIndex, refIndex);
2209
+ }
2210
+
2211
+ /**
2212
+ * Move a numbered input to a different location on this block.
2213
+ *
2214
+ * @param inputIndex Index of the input to move.
2215
+ * @param refIndex Index of input that should be after the moved input.
2216
+ */
2217
+ moveNumberedInputBefore(inputIndex: number, refIndex: number) {
2218
+ // Validate arguments.
2219
+ if (inputIndex === refIndex) {
2220
+ throw Error("Can't move input to itself.");
2221
+ }
2222
+ if (inputIndex >= this.inputList.length) {
2223
+ throw RangeError('Input index ' + inputIndex + ' out of bounds.');
2224
+ }
2225
+ if (refIndex > this.inputList.length) {
2226
+ throw RangeError('Reference input ' + refIndex + ' out of bounds.');
2227
+ }
2228
+ // Remove input.
2229
+ const input = this.inputList[inputIndex];
2230
+ this.inputList.splice(inputIndex, 1);
2231
+ if (inputIndex < refIndex) {
2232
+ refIndex--;
2233
+ }
2234
+ // Reinsert input.
2235
+ this.inputList.splice(refIndex, 0, input);
2236
+ }
2237
+
2238
+ /**
2239
+ * Remove an input from this block.
2240
+ *
2241
+ * @param name The name of the input.
2242
+ * @param opt_quiet True to prevent an error if input is not present.
2243
+ * @returns True if operation succeeds, false if input is not present and
2244
+ * opt_quiet is true.
2245
+ * @throws {Error} if the input is not present and opt_quiet is not true.
2246
+ */
2247
+ removeInput(name: string, opt_quiet?: boolean): boolean {
2248
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
2249
+ if (input.name === name) {
2250
+ if (input instanceof StatementInput) this.statementInputCount--;
2251
+ input.dispose();
2252
+ this.inputList.splice(i, 1);
2253
+ return true;
2254
+ }
2255
+ }
2256
+ if (opt_quiet) {
2257
+ return false;
2258
+ }
2259
+ throw Error('Input not found: ' + name);
2260
+ }
2261
+
2262
+ /**
2263
+ * Fetches the named input object.
2264
+ *
2265
+ * @param name The name of the input.
2266
+ * @returns The input object, or null if input does not exist.
2267
+ */
2268
+ getInput(name: string): Input | null {
2269
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
2270
+ if (input.name === name) {
2271
+ return input;
2272
+ }
2273
+ }
2274
+ // This input does not exist.
2275
+ return null;
2276
+ }
2277
+
2278
+ /**
2279
+ * Fetches the block attached to the named input.
2280
+ *
2281
+ * @param name The name of the input.
2282
+ * @returns The attached value block, or null if the input is either
2283
+ * disconnected or if the input does not exist.
2284
+ */
2285
+ getInputTargetBlock(name: string): Block | null {
2286
+ const input = this.getInput(name);
2287
+ return input && input.connection && input.connection.targetBlock();
2288
+ }
2289
+
2290
+ /**
2291
+ * Returns the comment on this block (or null if there is no comment).
2292
+ *
2293
+ * @returns Block's comment.
2294
+ */
2295
+ getCommentText(): string | null {
2296
+ const comment = this.getIcon(IconType.COMMENT);
2297
+ return comment?.getText() ?? null;
2298
+ }
2299
+
2300
+ /**
2301
+ * Set this block's comment text.
2302
+ *
2303
+ * @param text The text, or null to delete.
2304
+ */
2305
+ setCommentText(text: string | null) {
2306
+ const comment = this.getIcon(IconType.COMMENT);
2307
+ const oldText = comment?.getText() ?? null;
2308
+ if (oldText === text) return;
2309
+ if (text !== null) {
2310
+ let comment = this.getIcon(IconType.COMMENT);
2311
+ if (!comment) {
2312
+ const commentConstructor = registry.getClass(
2313
+ registry.Type.ICON,
2314
+ IconType.COMMENT.toString(),
2315
+ false,
2316
+ );
2317
+ if (!commentConstructor) {
2318
+ throw new Error(
2319
+ 'No comment icon class is registered, so a comment cannot be set',
2320
+ );
2321
+ }
2322
+ const icon = new commentConstructor(this);
2323
+ if (!isCommentIcon(icon)) {
2324
+ throw new Error(
2325
+ 'The class registered as a comment icon does not conform to the ' +
2326
+ 'ICommentIcon interface',
2327
+ );
2328
+ }
2329
+ comment = this.addIcon(icon);
2330
+ }
2331
+ eventUtils.disable();
2332
+ comment.setText(text);
2333
+ eventUtils.enable();
2334
+ } else {
2335
+ this.removeIcon(IconType.COMMENT);
2336
+ }
2337
+
2338
+ eventUtils.fire(
2339
+ new (eventUtils.get(eventUtils.BLOCK_CHANGE))(
2340
+ this,
2341
+ 'comment',
2342
+ null,
2343
+ oldText,
2344
+ text,
2345
+ ),
2346
+ );
2347
+ }
2348
+
2349
+ /**
2350
+ * Set this block's warning text.
2351
+ *
2352
+ * @param _text The text, or null to delete.
2353
+ * @param _opt_id An optional ID for the warning text to be able to maintain
2354
+ * multiple warnings.
2355
+ */
2356
+ setWarningText(_text: string | null, _opt_id?: string) {
2357
+ // NOOP.
2358
+ }
2359
+
2360
+ /**
2361
+ * Give this block a mutator dialog.
2362
+ *
2363
+ * @param _mutator A mutator dialog instance or null to remove.
2364
+ */
2365
+ setMutator(_mutator: MutatorIcon) {
2366
+ // NOOP.
2367
+ }
2368
+
2369
+ /** Adds the given icon to the block. */
2370
+ addIcon<T extends IIcon>(icon: T): T {
2371
+ if (this.hasIcon(icon.getType())) throw new DuplicateIconType(icon);
2372
+ this.icons.push(icon);
2373
+ this.icons.sort((a, b) => a.getWeight() - b.getWeight());
2374
+ return icon;
2375
+ }
2376
+
2377
+ /**
2378
+ * Removes the icon whose getType matches the given type iconType from the
2379
+ * block.
2380
+ *
2381
+ * @param type The type of the icon to remove from the block.
2382
+ * @returns True if an icon with the given type was found, false otherwise.
2383
+ */
2384
+ removeIcon(type: IconType<IIcon>): boolean {
2385
+ if (!this.hasIcon(type)) return false;
2386
+ this.getIcon(type)?.dispose();
2387
+ this.icons = this.icons.filter((icon) => !icon.getType().equals(type));
2388
+ return true;
2389
+ }
2390
+
2391
+ /**
2392
+ * @returns True if an icon with the given type exists on the block,
2393
+ * false otherwise.
2394
+ */
2395
+ hasIcon(type: IconType<IIcon>): boolean {
2396
+ return this.icons.some((icon) => icon.getType().equals(type));
2397
+ }
2398
+
2399
+ /**
2400
+ * @param type The type of the icon to retrieve. Prefer passing an `IconType`
2401
+ * for proper type checking when using typescript.
2402
+ * @returns The icon with the given type if it exists on the block, undefined
2403
+ * otherwise.
2404
+ */
2405
+ getIcon<T extends IIcon>(type: IconType<T> | string): T | undefined {
2406
+ if (type instanceof IconType) {
2407
+ return this.icons.find((icon) => icon.getType().equals(type)) as T;
2408
+ } else {
2409
+ return this.icons.find((icon) => icon.getType().toString() === type) as T;
2410
+ }
2411
+ }
2412
+
2413
+ /** @returns An array of the icons attached to this block. */
2414
+ getIcons(): IIcon[] {
2415
+ return [...this.icons];
2416
+ }
2417
+
2418
+ /**
2419
+ * Return the coordinates of the top-left corner of this block relative to the
2420
+ * drawing surface's origin (0,0), in workspace units.
2421
+ *
2422
+ * @returns Object with .x and .y properties.
2423
+ */
2424
+ getRelativeToSurfaceXY(): Coordinate {
2425
+ return this.xy_;
2426
+ }
2427
+
2428
+ /**
2429
+ * Move a block by a relative offset.
2430
+ *
2431
+ * @param dx Horizontal offset, in workspace units.
2432
+ * @param dy Vertical offset, in workspace units.
2433
+ * @param reason Why is this move happening? 'drag', 'bump', 'snap', ...
2434
+ */
2435
+ moveBy(dx: number, dy: number, reason?: string[]) {
2436
+ if (this.parentBlock_) {
2437
+ throw Error('Block has parent');
2438
+ }
2439
+ const event = new (eventUtils.get(eventUtils.BLOCK_MOVE))(
2440
+ this,
2441
+ ) as BlockMove;
2442
+ reason && event.setReason(reason);
2443
+ this.xy_.translate(dx, dy);
2444
+ event.recordNew();
2445
+ eventUtils.fire(event);
2446
+ }
2447
+
2448
+ /**
2449
+ * Create a connection of the specified type.
2450
+ *
2451
+ * @param type The type of the connection to create.
2452
+ * @returns A new connection of the specified type.
2453
+ * @internal
2454
+ */
2455
+ makeConnection_(type: ConnectionType): Connection {
2456
+ return new Connection(this, type);
2457
+ }
2458
+
2459
+ /**
2460
+ * Recursively checks whether all statement and value inputs are filled with
2461
+ * blocks. Also checks all following statement blocks in this stack.
2462
+ *
2463
+ * @param opt_shadowBlocksAreFilled An optional argument controlling whether
2464
+ * shadow blocks are counted as filled. Defaults to true.
2465
+ * @returns True if all inputs are filled, false otherwise.
2466
+ */
2467
+ allInputsFilled(opt_shadowBlocksAreFilled?: boolean): boolean {
2468
+ // Account for the shadow block filledness toggle.
2469
+ if (opt_shadowBlocksAreFilled === undefined) {
2470
+ opt_shadowBlocksAreFilled = true;
2471
+ }
2472
+ if (!opt_shadowBlocksAreFilled && this.isShadow()) {
2473
+ return false;
2474
+ }
2475
+
2476
+ // Recursively check each input block of the current block.
2477
+ for (let i = 0, input; (input = this.inputList[i]); i++) {
2478
+ if (!input.connection) {
2479
+ continue;
2480
+ }
2481
+ const target = input.connection.targetBlock();
2482
+ if (!target || !target.allInputsFilled(opt_shadowBlocksAreFilled)) {
2483
+ return false;
2484
+ }
2485
+ }
2486
+
2487
+ // Recursively check the next block after the current block.
2488
+ const next = this.getNextBlock();
2489
+ if (next) {
2490
+ return next.allInputsFilled(opt_shadowBlocksAreFilled);
2491
+ }
2492
+
2493
+ return true;
2494
+ }
2495
+
2496
+ /**
2497
+ * This method returns a string describing this Block in developer terms (type
2498
+ * name and ID; English only).
2499
+ *
2500
+ * Intended to on be used in console logs and errors. If you need a string
2501
+ * that uses the user's native language (including block text, field values,
2502
+ * and child blocks), use [toString()]{@link Block#toString}.
2503
+ *
2504
+ * @returns The description.
2505
+ */
2506
+ toDevString(): string {
2507
+ let msg = this.type ? '"' + this.type + '" block' : 'Block';
2508
+ if (this.id) {
2509
+ msg += ' (id="' + this.id + '")';
2510
+ }
2511
+ return msg;
2512
+ }
2513
+ }
2514
+
2515
+ export namespace Block {
2516
+ export interface CommentModel {
2517
+ text: string | null;
2518
+ pinned: boolean;
2519
+ size: Size;
2520
+ }
2521
+ }
2522
+
2523
+ export type CommentModel = Block.CommentModel;