blockly 9.0.0-beta.0 → 9.0.0-beta.2

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 (736) hide show
  1. package/blockly.min.js +830 -810
  2. package/blockly_compressed.js +821 -801
  3. package/blockly_compressed.js.map +1 -1
  4. package/blocks.d.ts +0 -5
  5. package/blocks_compressed.js +9 -9
  6. package/blocks_compressed.js.map +1 -1
  7. package/closure/goog/base.d.ts +1 -0
  8. package/closure/goog/base_minimal.d.ts +1 -0
  9. package/closure/goog/goog.d.ts +1 -0
  10. package/core/any_aliases.d.ts +1 -0
  11. package/core/block.d.ts +156 -53
  12. package/core/block_animations.d.ts +5 -0
  13. package/core/block_drag_surface.d.ts +18 -5
  14. package/core/block_dragger.d.ts +20 -5
  15. package/core/block_svg.d.ts +92 -24
  16. package/core/blockly.d.ts +31 -10
  17. package/core/blockly_options.d.ts +2 -0
  18. package/core/blocks.d.ts +2 -0
  19. package/core/browser_events.d.ts +16 -7
  20. package/core/bubble.d.ts +42 -12
  21. package/core/bubble_dragger.d.ts +9 -2
  22. package/core/bump_objects.d.ts +6 -2
  23. package/core/clipboard.d.ts +6 -2
  24. package/core/comment.d.ts +13 -3
  25. package/core/common.d.ts +35 -9
  26. package/core/component_manager.d.ts +16 -6
  27. package/core/config.d.ts +1 -0
  28. package/core/connection.d.ts +48 -18
  29. package/core/connection_checker.d.ts +16 -7
  30. package/core/connection_db.d.ts +17 -6
  31. package/core/connection_type.d.ts +2 -0
  32. package/core/constants.d.ts +3 -0
  33. package/core/contextmenu.d.ts +15 -5
  34. package/core/contextmenu_items.d.ts +15 -0
  35. package/core/contextmenu_registry.d.ts +12 -7
  36. package/core/css.d.ts +3 -0
  37. package/core/delete_area.d.ts +5 -1
  38. package/core/dialog.d.ts +14 -7
  39. package/core/drag_target.d.ts +10 -2
  40. package/core/dropdowndiv.d.ts +42 -10
  41. package/core/events/events.d.ts +51 -24
  42. package/core/events/events_abstract.d.ts +18 -7
  43. package/core/events/events_block_base.d.ts +13 -7
  44. package/core/events/events_block_change.d.ts +24 -11
  45. package/core/events/events_block_create.d.ts +18 -7
  46. package/core/events/events_block_delete.d.ts +20 -8
  47. package/core/events/events_block_drag.d.ts +14 -4
  48. package/core/events/events_block_move.d.ts +25 -12
  49. package/core/events/events_bubble_open.d.ts +21 -6
  50. package/core/events/events_click.d.ts +20 -6
  51. package/core/events/events_comment_base.d.ts +13 -6
  52. package/core/events/events_comment_change.d.ts +17 -7
  53. package/core/events/events_comment_create.d.ts +13 -5
  54. package/core/events/events_comment_delete.d.ts +4 -11
  55. package/core/events/events_comment_move.d.ts +19 -8
  56. package/core/events/events_marker_move.d.ts +16 -5
  57. package/core/events/events_selected.d.ts +14 -5
  58. package/core/events/events_theme_change.d.ts +11 -3
  59. package/core/events/events_toolbox_item_select.d.ts +14 -5
  60. package/core/events/events_trashcan_open.d.ts +11 -3
  61. package/core/events/events_ui.d.ts +5 -1
  62. package/core/events/events_ui_base.d.ts +2 -0
  63. package/core/events/events_var_base.d.ts +13 -7
  64. package/core/events/events_var_create.d.ts +15 -6
  65. package/core/events/events_var_delete.d.ts +15 -6
  66. package/core/events/events_var_rename.d.ts +15 -6
  67. package/core/events/events_viewport.d.ts +14 -3
  68. package/core/events/utils.d.ts +50 -7
  69. package/core/events/workspace_events.d.ts +11 -6
  70. package/core/extensions.d.ts +14 -4
  71. package/core/field.d.ts +93 -36
  72. package/core/field_angle.d.ts +14 -3
  73. package/core/field_checkbox.d.ts +20 -7
  74. package/core/field_colour.d.ts +22 -6
  75. package/core/field_dropdown.d.ts +28 -8
  76. package/core/field_image.d.ts +15 -4
  77. package/core/field_label.d.ts +8 -2
  78. package/core/field_label_serializable.d.ts +4 -1
  79. package/core/field_multilineinput.d.ts +21 -6
  80. package/core/field_number.d.ts +22 -6
  81. package/core/field_registry.d.ts +8 -2
  82. package/core/field_textinput.d.ts +28 -8
  83. package/core/field_variable.d.ts +36 -13
  84. package/core/flyout_base.d.ts +70 -24
  85. package/core/flyout_button.d.ts +12 -5
  86. package/core/flyout_horizontal.d.ts +14 -6
  87. package/core/flyout_metrics_manager.d.ts +6 -3
  88. package/core/flyout_vertical.d.ts +14 -6
  89. package/core/generator.d.ts +39 -20
  90. package/core/gesture.d.ts +56 -22
  91. package/core/grid.d.ts +20 -16
  92. package/core/icon.d.ts +18 -5
  93. package/core/inject.d.ts +3 -1
  94. package/core/input.d.ts +25 -10
  95. package/core/input_types.d.ts +2 -0
  96. package/core/insertion_marker_manager.d.ts +27 -9
  97. package/core/interfaces/i_ast_node_location.d.ts +2 -0
  98. package/core/interfaces/i_ast_node_location_svg.d.ts +4 -0
  99. package/core/interfaces/i_ast_node_location_with_block.d.ts +4 -1
  100. package/core/interfaces/i_autohideable.d.ts +3 -0
  101. package/core/interfaces/i_block_dragger.d.ts +7 -1
  102. package/core/interfaces/i_bounded_element.d.ts +5 -1
  103. package/core/interfaces/i_bubble.d.ts +11 -2
  104. package/core/interfaces/i_collapsible_toolbox_item.d.ts +6 -2
  105. package/core/interfaces/i_component.d.ts +3 -1
  106. package/core/interfaces/i_connection_checker.d.ts +14 -6
  107. package/core/interfaces/i_contextmenu.d.ts +2 -0
  108. package/core/interfaces/i_copyable.d.ts +3 -1
  109. package/core/interfaces/i_deletable.d.ts +4 -1
  110. package/core/interfaces/i_delete_area.d.ts +4 -1
  111. package/core/interfaces/i_drag_target.d.ts +10 -2
  112. package/core/interfaces/i_draggable.d.ts +2 -0
  113. package/core/interfaces/i_flyout.d.ts +27 -11
  114. package/core/interfaces/i_keyboard_accessible.d.ts +4 -1
  115. package/core/interfaces/i_metrics_manager.d.ts +24 -12
  116. package/core/interfaces/i_movable.d.ts +4 -1
  117. package/core/interfaces/i_positionable.d.ts +5 -1
  118. package/core/interfaces/i_registrable.d.ts +2 -0
  119. package/core/interfaces/i_registrable_field.d.ts +2 -0
  120. package/core/interfaces/i_selectable.d.ts +2 -0
  121. package/core/interfaces/i_selectable_toolbox_item.d.ts +10 -3
  122. package/core/interfaces/i_serializer.d.ts +6 -1
  123. package/core/interfaces/i_styleable.d.ts +4 -0
  124. package/core/interfaces/i_toolbox.d.ts +17 -6
  125. package/core/interfaces/i_toolbox_item.d.ts +17 -7
  126. package/core/internal_constants.d.ts +6 -0
  127. package/core/keyboard_nav/ast_node.d.ts +55 -28
  128. package/core/keyboard_nav/basic_cursor.d.ts +20 -9
  129. package/core/keyboard_nav/cursor.d.ts +11 -5
  130. package/core/keyboard_nav/marker.d.ts +9 -2
  131. package/core/keyboard_nav/tab_navigate_cursor.d.ts +4 -1
  132. package/core/main.d.ts +1 -0
  133. package/core/marker_manager.d.ts +13 -2
  134. package/core/menu.d.ts +25 -6
  135. package/core/menuitem.d.ts +22 -7
  136. package/core/metrics_manager.d.ts +30 -15
  137. package/core/msg.d.ts +15 -0
  138. package/core/mutator.d.ts +20 -8
  139. package/core/names.d.ts +20 -8
  140. package/core/options.d.ts +12 -6
  141. package/core/positionable_helpers.d.ts +11 -3
  142. package/core/procedures.d.ts +27 -10
  143. package/core/registry.d.ts +19 -8
  144. package/core/rendered_connection.d.ts +29 -7
  145. package/core/renderers/common/block_rendering.d.ts +9 -2
  146. package/core/renderers/common/constants.d.ts +57 -18
  147. package/core/renderers/common/debug.d.ts +5 -1
  148. package/core/renderers/common/debugger.d.ts +12 -1
  149. package/core/renderers/common/drawer.d.ts +16 -3
  150. package/core/renderers/common/i_path_object.d.ts +37 -16
  151. package/core/renderers/common/info.d.ts +28 -11
  152. package/core/renderers/common/marker_svg.d.ts +42 -11
  153. package/core/renderers/common/path_object.d.ts +23 -3
  154. package/core/renderers/common/renderer.d.ts +33 -12
  155. package/core/renderers/geras/constants.d.ts +6 -2
  156. package/core/renderers/geras/drawer.d.ts +4 -1
  157. package/core/renderers/geras/geras.d.ts +3 -2
  158. package/core/renderers/geras/highlight_constants.d.ts +9 -6
  159. package/core/renderers/geras/highlighter.d.ts +12 -1
  160. package/core/renderers/geras/info.d.ts +4 -1
  161. package/core/renderers/geras/measurables/inline_input.d.ts +2 -0
  162. package/core/renderers/geras/measurables/statement_input.d.ts +2 -0
  163. package/core/renderers/geras/path_object.d.ts +4 -1
  164. package/core/renderers/geras/renderer.d.ts +16 -6
  165. package/core/renderers/measurables/base.d.ts +2 -0
  166. package/core/renderers/measurables/bottom_row.d.ts +9 -3
  167. package/core/renderers/measurables/connection.d.ts +2 -0
  168. package/core/renderers/measurables/external_value_input.d.ts +2 -1
  169. package/core/renderers/measurables/field.d.ts +2 -1
  170. package/core/renderers/measurables/hat.d.ts +2 -1
  171. package/core/renderers/measurables/icon.d.ts +4 -1
  172. package/core/renderers/measurables/in_row_spacer.d.ts +2 -1
  173. package/core/renderers/measurables/inline_input.d.ts +2 -1
  174. package/core/renderers/measurables/input_connection.d.ts +2 -0
  175. package/core/renderers/measurables/input_row.d.ts +4 -1
  176. package/core/renderers/measurables/jagged_edge.d.ts +2 -1
  177. package/core/renderers/measurables/next_connection.d.ts +2 -1
  178. package/core/renderers/measurables/output_connection.d.ts +2 -1
  179. package/core/renderers/measurables/previous_connection.d.ts +2 -1
  180. package/core/renderers/measurables/round_corner.d.ts +2 -1
  181. package/core/renderers/measurables/row.d.ts +30 -8
  182. package/core/renderers/measurables/spacer_row.d.ts +2 -1
  183. package/core/renderers/measurables/square_corner.d.ts +2 -1
  184. package/core/renderers/measurables/statement_input.d.ts +2 -1
  185. package/core/renderers/measurables/top_row.d.ts +7 -4
  186. package/core/renderers/measurables/types.d.ts +54 -25
  187. package/core/renderers/minimalist/constants.d.ts +2 -0
  188. package/core/renderers/minimalist/drawer.d.ts +2 -0
  189. package/core/renderers/minimalist/info.d.ts +5 -1
  190. package/core/renderers/minimalist/minimalist.d.ts +2 -1
  191. package/core/renderers/minimalist/renderer.d.ts +8 -3
  192. package/core/renderers/thrasos/info.d.ts +5 -4
  193. package/core/renderers/thrasos/renderer.d.ts +4 -1
  194. package/core/renderers/thrasos/thrasos.d.ts +2 -1
  195. package/core/renderers/zelos/constants.d.ts +31 -44
  196. package/core/renderers/zelos/drawer.d.ts +3 -0
  197. package/core/renderers/zelos/info.d.ts +10 -5
  198. package/core/renderers/zelos/marker_svg.d.ts +5 -0
  199. package/core/renderers/zelos/measurables/bottom_row.d.ts +2 -0
  200. package/core/renderers/zelos/measurables/inputs.d.ts +2 -1
  201. package/core/renderers/zelos/measurables/row_elements.d.ts +2 -0
  202. package/core/renderers/zelos/measurables/top_row.d.ts +2 -0
  203. package/core/renderers/zelos/path_object.d.ts +9 -2
  204. package/core/renderers/zelos/renderer.d.ts +14 -6
  205. package/core/renderers/zelos/zelos.d.ts +3 -2
  206. package/core/scrollbar.d.ts +41 -9
  207. package/core/scrollbar_pair.d.ts +20 -6
  208. package/core/serialization/blocks.d.ts +10 -4
  209. package/core/serialization/exceptions.d.ts +5 -0
  210. package/core/serialization/priorities.d.ts +3 -0
  211. package/core/serialization/registry.d.ts +3 -0
  212. package/core/serialization/variables.d.ts +2 -0
  213. package/core/serialization/workspaces.d.ts +4 -1
  214. package/core/shortcut_items.d.ts +10 -0
  215. package/core/shortcut_registry.d.ts +25 -9
  216. package/core/sprites.d.ts +2 -4
  217. package/core/theme/classic.d.ts +2 -0
  218. package/core/theme/themes.d.ts +1 -0
  219. package/core/theme/zelos.d.ts +2 -0
  220. package/core/theme.d.ts +41 -30
  221. package/core/theme_manager.d.ts +10 -1
  222. package/core/toolbox/category.d.ts +60 -32
  223. package/core/toolbox/collapsible_category.d.ts +10 -3
  224. package/core/toolbox/separator.d.ts +4 -1
  225. package/core/toolbox/toolbox.d.ts +71 -23
  226. package/core/toolbox/toolbox_item.d.ts +17 -7
  227. package/core/tooltip.d.ts +22 -1
  228. package/core/touch.d.ts +18 -6
  229. package/core/touch_gesture.d.ts +19 -4
  230. package/core/trashcan.d.ts +27 -6
  231. package/core/utils/aria.d.ts +4 -0
  232. package/core/utils/array.d.ts +4 -2
  233. package/core/utils/colour.d.ts +24 -13
  234. package/core/utils/coordinate.d.ts +19 -9
  235. package/core/utils/deprecation.d.ts +6 -4
  236. package/core/utils/dom.d.ts +37 -18
  237. package/core/utils/idgenerator.d.ts +14 -4
  238. package/core/utils/keycodes.d.ts +1 -0
  239. package/core/utils/math.d.ts +7 -3
  240. package/core/utils/metrics.d.ts +1 -0
  241. package/core/utils/object.d.ts +7 -2
  242. package/core/utils/parsing.d.ts +9 -4
  243. package/core/utils/rect.d.ts +5 -3
  244. package/core/utils/sentinel.d.ts +2 -0
  245. package/core/utils/size.d.ts +4 -2
  246. package/core/utils/string.d.ts +13 -6
  247. package/core/utils/style.d.ts +14 -33
  248. package/core/utils/svg.d.ts +5 -2
  249. package/core/utils/svg_math.d.ts +15 -7
  250. package/core/utils/svg_paths.d.ts +20 -10
  251. package/core/utils/toolbox.d.ts +26 -5
  252. package/core/utils/useragent.d.ts +1 -12
  253. package/core/utils/xml.d.ts +13 -5
  254. package/core/utils.d.ts +43 -21
  255. package/core/variable_map.d.ts +26 -9
  256. package/core/variable_model.d.ts +5 -2
  257. package/core/variables.d.ts +33 -18
  258. package/core/variables_dynamic.d.ts +25 -5
  259. package/core/warning.d.ts +8 -3
  260. package/core/widgetdiv.d.ts +15 -6
  261. package/core/workspace.d.ts +80 -30
  262. package/core/workspace_audio.d.ts +6 -0
  263. package/core/workspace_comment.d.ts +33 -11
  264. package/core/workspace_comment_svg.d.ts +52 -9
  265. package/core/workspace_drag_surface_svg.d.ts +20 -14
  266. package/core/workspace_dragger.d.ts +6 -0
  267. package/core/workspace_svg.d.ts +174 -62
  268. package/core/xml.d.ts +26 -11
  269. package/core/zoom_controls.d.ts +17 -7
  270. package/core-browser.js +0 -6
  271. package/core.d.ts +0 -5
  272. package/core.js +0 -6
  273. package/dart.d.ts +1 -7
  274. package/dart_compressed.js.map +1 -1
  275. package/index.d.ts +2 -6
  276. package/javascript.d.ts +1 -7
  277. package/javascript_compressed.js.map +1 -1
  278. package/lua.d.ts +1 -7
  279. package/lua_compressed.js.map +1 -1
  280. package/msg/ab.d.ts +8 -0
  281. package/msg/ace.d.ts +8 -0
  282. package/msg/af.d.ts +8 -0
  283. package/msg/am.d.ts +8 -0
  284. package/msg/ar.d.ts +8 -0
  285. package/msg/ast.d.ts +8 -0
  286. package/msg/az.d.ts +8 -0
  287. package/msg/ba.d.ts +8 -0
  288. package/msg/bcc.d.ts +8 -0
  289. package/msg/be-tarask.d.ts +8 -0
  290. package/msg/be.d.ts +8 -0
  291. package/msg/bg.d.ts +8 -0
  292. package/msg/bn.d.ts +8 -0
  293. package/msg/br.d.ts +8 -0
  294. package/msg/bs.d.ts +8 -0
  295. package/msg/ca.d.ts +8 -0
  296. package/msg/cdo.d.ts +8 -0
  297. package/msg/constants.d.ts +16 -0
  298. package/msg/cs.d.ts +8 -0
  299. package/msg/da.d.ts +8 -0
  300. package/msg/de.d.ts +8 -0
  301. package/msg/diq.d.ts +8 -0
  302. package/msg/dty.d.ts +8 -0
  303. package/msg/ee.d.ts +8 -0
  304. package/msg/el.d.ts +8 -0
  305. package/msg/en-gb.d.ts +8 -0
  306. package/msg/en.d.ts +8 -0
  307. package/msg/eo.d.ts +8 -0
  308. package/msg/es.d.ts +8 -0
  309. package/msg/et.d.ts +8 -0
  310. package/msg/eu.d.ts +8 -0
  311. package/msg/fa.d.ts +8 -0
  312. package/msg/fi.d.ts +8 -0
  313. package/msg/fo.d.ts +8 -0
  314. package/msg/fr.d.ts +8 -0
  315. package/msg/frr.d.ts +8 -0
  316. package/msg/gl.d.ts +8 -0
  317. package/msg/gn.d.ts +8 -0
  318. package/msg/gor.d.ts +8 -0
  319. package/msg/ha.d.ts +8 -0
  320. package/msg/hak.d.ts +8 -0
  321. package/msg/he.d.ts +8 -0
  322. package/msg/hi.d.ts +8 -0
  323. package/msg/hr.d.ts +8 -0
  324. package/msg/hrx.d.ts +8 -0
  325. package/msg/hu.d.ts +8 -0
  326. package/msg/hy.d.ts +8 -0
  327. package/msg/ia.d.ts +8 -0
  328. package/msg/id.d.ts +8 -0
  329. package/msg/ig.d.ts +8 -0
  330. package/msg/inh.d.ts +8 -0
  331. package/msg/is.d.ts +8 -0
  332. package/msg/it.d.ts +8 -0
  333. package/msg/ja.d.ts +8 -0
  334. package/msg/ka.d.ts +8 -0
  335. package/msg/kab.d.ts +8 -0
  336. package/msg/kbd-cyrl.d.ts +8 -0
  337. package/msg/km.d.ts +8 -0
  338. package/msg/kn.d.ts +8 -0
  339. package/msg/ko.d.ts +8 -0
  340. package/msg/ksh.d.ts +8 -0
  341. package/msg/ku-latn.d.ts +8 -0
  342. package/msg/ky.d.ts +8 -0
  343. package/msg/la.d.ts +8 -0
  344. package/msg/lb.d.ts +8 -0
  345. package/msg/lki.d.ts +8 -0
  346. package/msg/lo.d.ts +8 -0
  347. package/msg/lrc.d.ts +8 -0
  348. package/msg/lt.d.ts +8 -0
  349. package/msg/lv.d.ts +8 -0
  350. package/msg/mg.d.ts +8 -0
  351. package/msg/mk.d.ts +8 -0
  352. package/msg/ml.d.ts +8 -0
  353. package/msg/mnw.d.ts +8 -0
  354. package/msg/ms.d.ts +8 -0
  355. package/msg/msg.d.ts +429 -432
  356. package/msg/my.d.ts +8 -0
  357. package/msg/mzn.d.ts +8 -0
  358. package/msg/nb.d.ts +8 -0
  359. package/msg/ne.d.ts +8 -0
  360. package/msg/nl.d.ts +8 -0
  361. package/msg/oc.d.ts +8 -0
  362. package/msg/olo.d.ts +8 -0
  363. package/msg/pa.d.ts +8 -0
  364. package/msg/pl.d.ts +8 -0
  365. package/msg/pms.d.ts +8 -0
  366. package/msg/ps.d.ts +8 -0
  367. package/msg/pt-br.d.ts +8 -0
  368. package/msg/pt.d.ts +8 -0
  369. package/msg/qqq.d.ts +16 -0
  370. package/msg/ro.d.ts +8 -0
  371. package/msg/ru.d.ts +8 -0
  372. package/msg/sc.d.ts +8 -0
  373. package/msg/sco.d.ts +8 -0
  374. package/msg/sd.d.ts +8 -0
  375. package/msg/shn.d.ts +8 -0
  376. package/msg/si.d.ts +8 -0
  377. package/msg/sk.d.ts +8 -0
  378. package/msg/skr-arab.d.ts +8 -0
  379. package/msg/sl.d.ts +8 -0
  380. package/msg/smn.d.ts +8 -0
  381. package/msg/sq.d.ts +8 -0
  382. package/msg/sr-latn.d.ts +8 -0
  383. package/msg/sr.d.ts +8 -0
  384. package/msg/sv.d.ts +8 -0
  385. package/msg/sw.d.ts +8 -0
  386. package/msg/synonyms.d.ts +16 -0
  387. package/msg/ta.d.ts +8 -0
  388. package/msg/tcy.d.ts +8 -0
  389. package/msg/te.d.ts +8 -0
  390. package/msg/th.d.ts +8 -0
  391. package/msg/ti.d.ts +8 -0
  392. package/msg/tl.d.ts +8 -0
  393. package/msg/tlh.d.ts +8 -0
  394. package/msg/tr.d.ts +8 -0
  395. package/msg/ug-arab.d.ts +8 -0
  396. package/msg/uk.d.ts +8 -0
  397. package/msg/ur.d.ts +8 -0
  398. package/msg/uz.d.ts +8 -0
  399. package/msg/vi.d.ts +8 -0
  400. package/msg/xmf.d.ts +8 -0
  401. package/msg/yo.d.ts +8 -0
  402. package/msg/yue.d.ts +8 -0
  403. package/msg/zgh.d.ts +8 -0
  404. package/msg/zh-hans.d.ts +8 -0
  405. package/msg/zh-hant.d.ts +8 -0
  406. package/package.json +6 -3
  407. package/php.d.ts +1 -7
  408. package/php_compressed.js.map +1 -1
  409. package/python.d.ts +1 -7
  410. package/python_compressed.js.map +1 -1
  411. package/blocks/blocks.js +0 -48
  412. package/blocks/colour.js +0 -121
  413. package/blocks/lists.js +0 -996
  414. package/blocks/logic.js +0 -665
  415. package/blocks/loops.js +0 -375
  416. package/blocks/math.js +0 -594
  417. package/blocks/procedures.js +0 -1196
  418. package/blocks/text.js +0 -1000
  419. package/blocks/variables.js +0 -176
  420. package/blocks/variables_dynamic.js +0 -192
  421. package/core/any_aliases.ts +0 -1
  422. package/core/block.ts +0 -2102
  423. package/core/block_animations.ts +0 -202
  424. package/core/block_drag_surface.ts +0 -237
  425. package/core/block_dragger.ts +0 -447
  426. package/core/block_svg.ts +0 -1758
  427. package/core/blockly.js +0 -890
  428. package/core/blockly.ts +0 -749
  429. package/core/blockly_options.ts +0 -81
  430. package/core/blocks.ts +0 -29
  431. package/core/browser_events.ts +0 -289
  432. package/core/bubble.ts +0 -892
  433. package/core/bubble_dragger.ts +0 -229
  434. package/core/bump_objects.ts +0 -182
  435. package/core/clipboard.ts +0 -91
  436. package/core/comment.ts +0 -398
  437. package/core/common.ts +0 -288
  438. package/core/component_manager.ts +0 -211
  439. package/core/config.ts +0 -80
  440. package/core/connection.ts +0 -692
  441. package/core/connection_checker.ts +0 -301
  442. package/core/connection_db.ts +0 -289
  443. package/core/connection_type.ts +0 -32
  444. package/core/constants.ts +0 -29
  445. package/core/contextmenu.ts +0 -363
  446. package/core/contextmenu_items.ts +0 -576
  447. package/core/contextmenu_registry.ts +0 -179
  448. package/core/css.ts +0 -560
  449. package/core/delete_area.ts +0 -82
  450. package/core/dialog.ts +0 -127
  451. package/core/drag_target.ts +0 -94
  452. package/core/dropdowndiv.ts +0 -683
  453. package/core/events/events.ts +0 -123
  454. package/core/events/events_abstract.ts +0 -112
  455. package/core/events/events_block_base.ts +0 -65
  456. package/core/events/events_block_change.ts +0 -176
  457. package/core/events/events_block_create.ts +0 -114
  458. package/core/events/events_block_delete.ts +0 -126
  459. package/core/events/events_block_drag.ts +0 -82
  460. package/core/events/events_block_move.ts +0 -206
  461. package/core/events/events_bubble_open.ts +0 -82
  462. package/core/events/events_click.ts +0 -84
  463. package/core/events/events_comment_base.ts +0 -107
  464. package/core/events/events_comment_change.ts +0 -108
  465. package/core/events/events_comment_create.ts +0 -82
  466. package/core/events/events_comment_delete.ts +0 -77
  467. package/core/events/events_comment_move.ts +0 -154
  468. package/core/events/events_marker_move.ts +0 -99
  469. package/core/events/events_selected.ts +0 -78
  470. package/core/events/events_theme_change.ts +0 -67
  471. package/core/events/events_toolbox_item_select.ts +0 -79
  472. package/core/events/events_trashcan_open.ts +0 -68
  473. package/core/events/events_ui.ts +0 -89
  474. package/core/events/events_ui_base.ts +0 -54
  475. package/core/events/events_var_base.ts +0 -65
  476. package/core/events/events_var_create.ts +0 -88
  477. package/core/events/events_var_delete.ts +0 -88
  478. package/core/events/events_var_rename.ts +0 -89
  479. package/core/events/events_viewport.ts +0 -100
  480. package/core/events/utils.ts +0 -529
  481. package/core/events/workspace_events.ts +0 -86
  482. package/core/extensions.ts +0 -504
  483. package/core/field.ts +0 -1206
  484. package/core/field_angle.ts +0 -563
  485. package/core/field_checkbox.ts +0 -243
  486. package/core/field_colour.ts +0 -632
  487. package/core/field_dropdown.ts +0 -773
  488. package/core/field_image.ts +0 -282
  489. package/core/field_label.ts +0 -152
  490. package/core/field_label_serializable.ts +0 -76
  491. package/core/field_multilineinput.ts +0 -466
  492. package/core/field_number.ts +0 -327
  493. package/core/field_registry.ts +0 -87
  494. package/core/field_textinput.ts +0 -591
  495. package/core/field_variable.ts +0 -545
  496. package/core/flyout_base.ts +0 -1165
  497. package/core/flyout_button.ts +0 -292
  498. package/core/flyout_horizontal.ts +0 -381
  499. package/core/flyout_metrics_manager.ts +0 -94
  500. package/core/flyout_vertical.ts +0 -384
  501. package/core/generator.ts +0 -539
  502. package/core/gesture.ts +0 -946
  503. package/core/grid.ts +0 -192
  504. package/core/icon.ts +0 -189
  505. package/core/inject.ts +0 -390
  506. package/core/input.ts +0 -309
  507. package/core/input_types.ts +0 -32
  508. package/core/insertion_marker_manager.ts +0 -788
  509. package/core/interfaces/i_ast_node_location.ts +0 -23
  510. package/core/interfaces/i_ast_node_location_svg.ts +0 -37
  511. package/core/interfaces/i_ast_node_location_with_block.ts +0 -38
  512. package/core/interfaces/i_autohideable.ts +0 -34
  513. package/core/interfaces/i_block_dragger.ts +0 -67
  514. package/core/interfaces/i_bounded_element.ts +0 -42
  515. package/core/interfaces/i_bubble.ts +0 -88
  516. package/core/interfaces/i_collapsible_toolbox_item.ts +0 -47
  517. package/core/interfaces/i_component.ts +0 -32
  518. package/core/interfaces/i_connection_checker.ts +0 -102
  519. package/core/interfaces/i_contextmenu.ts +0 -26
  520. package/core/interfaces/i_copyable.ts +0 -40
  521. package/core/interfaces/i_deletable.ts +0 -29
  522. package/core/interfaces/i_delete_area.ts +0 -46
  523. package/core/interfaces/i_drag_target.ts +0 -84
  524. package/core/interfaces/i_draggable.ts +0 -25
  525. package/core/interfaces/i_flyout.ts +0 -186
  526. package/core/interfaces/i_keyboard_accessible.ts +0 -35
  527. package/core/interfaces/i_metrics_manager.ts +0 -151
  528. package/core/interfaces/i_movable.ts +0 -29
  529. package/core/interfaces/i_positionable.ts +0 -50
  530. package/core/interfaces/i_registrable.ts +0 -25
  531. package/core/interfaces/i_registrable_field.ts +0 -31
  532. package/core/interfaces/i_selectable.ts +0 -34
  533. package/core/interfaces/i_selectable_toolbox_item.ts +0 -64
  534. package/core/interfaces/i_serializer.ts +0 -65
  535. package/core/interfaces/i_styleable.ts +0 -35
  536. package/core/interfaces/i_toolbox.ts +0 -127
  537. package/core/interfaces/i_toolbox_item.ts +0 -84
  538. package/core/internal_constants.ts +0 -67
  539. package/core/keyboard_nav/ast_node.ts +0 -717
  540. package/core/keyboard_nav/basic_cursor.ts +0 -214
  541. package/core/keyboard_nav/cursor.ts +0 -134
  542. package/core/keyboard_nav/marker.ts +0 -115
  543. package/core/keyboard_nav/tab_navigate_cursor.ts +0 -48
  544. package/core/main.js +0 -303
  545. package/core/marker_manager.ts +0 -181
  546. package/core/menu.ts +0 -449
  547. package/core/menuitem.ts +0 -240
  548. package/core/metrics_manager.ts +0 -456
  549. package/core/msg.ts +0 -20
  550. package/core/mutator.ts +0 -560
  551. package/core/names.ts +0 -267
  552. package/core/options.ts +0 -365
  553. package/core/positionable_helpers.ts +0 -181
  554. package/core/procedures.ts +0 -443
  555. package/core/registry.ts +0 -339
  556. package/core/rendered_connection.ts +0 -568
  557. package/core/renderers/common/block_rendering.ts +0 -164
  558. package/core/renderers/common/constants.ts +0 -1124
  559. package/core/renderers/common/debug.ts +0 -61
  560. package/core/renderers/common/debugger.ts +0 -433
  561. package/core/renderers/common/drawer.ts +0 -450
  562. package/core/renderers/common/i_path_object.ts +0 -161
  563. package/core/renderers/common/info.ts +0 -718
  564. package/core/renderers/common/marker_svg.ts +0 -680
  565. package/core/renderers/common/path_object.ts +0 -272
  566. package/core/renderers/common/renderer.ts +0 -271
  567. package/core/renderers/geras/constants.ts +0 -61
  568. package/core/renderers/geras/drawer.ts +0 -176
  569. package/core/renderers/geras/geras.ts +0 -37
  570. package/core/renderers/geras/highlight_constants.ts +0 -337
  571. package/core/renderers/geras/highlighter.ts +0 -306
  572. package/core/renderers/geras/info.ts +0 -450
  573. package/core/renderers/geras/measurables/inline_input.ts +0 -51
  574. package/core/renderers/geras/measurables/statement_input.ts +0 -50
  575. package/core/renderers/geras/path_object.ts +0 -138
  576. package/core/renderers/geras/renderer.ts +0 -126
  577. package/core/renderers/measurables/base.ts +0 -53
  578. package/core/renderers/measurables/bottom_row.ts +0 -120
  579. package/core/renderers/measurables/connection.ts +0 -52
  580. package/core/renderers/measurables/external_value_input.ts +0 -65
  581. package/core/renderers/measurables/field.ts +0 -63
  582. package/core/renderers/measurables/hat.ts +0 -48
  583. package/core/renderers/measurables/icon.ts +0 -54
  584. package/core/renderers/measurables/in_row_spacer.ts +0 -44
  585. package/core/renderers/measurables/inline_input.ts +0 -76
  586. package/core/renderers/measurables/input_connection.ts +0 -66
  587. package/core/renderers/measurables/input_row.ts +0 -82
  588. package/core/renderers/measurables/jagged_edge.ts +0 -43
  589. package/core/renderers/measurables/next_connection.ts +0 -47
  590. package/core/renderers/measurables/output_connection.ts +0 -56
  591. package/core/renderers/measurables/previous_connection.ts +0 -47
  592. package/core/renderers/measurables/round_corner.ts +0 -49
  593. package/core/renderers/measurables/row.ts +0 -225
  594. package/core/renderers/measurables/spacer_row.ts +0 -55
  595. package/core/renderers/measurables/square_corner.ts +0 -47
  596. package/core/renderers/measurables/statement_input.ts +0 -55
  597. package/core/renderers/measurables/top_row.ts +0 -122
  598. package/core/renderers/measurables/types.ts +0 -332
  599. package/core/renderers/minimalist/constants.ts +0 -32
  600. package/core/renderers/minimalist/drawer.ts +0 -38
  601. package/core/renderers/minimalist/info.ts +0 -52
  602. package/core/renderers/minimalist/minimalist.ts +0 -22
  603. package/core/renderers/minimalist/renderer.ts +0 -71
  604. package/core/renderers/thrasos/info.ts +0 -338
  605. package/core/renderers/thrasos/renderer.ts +0 -48
  606. package/core/renderers/thrasos/thrasos.ts +0 -20
  607. package/core/renderers/zelos/constants.ts +0 -858
  608. package/core/renderers/zelos/drawer.ts +0 -228
  609. package/core/renderers/zelos/info.ts +0 -593
  610. package/core/renderers/zelos/marker_svg.ts +0 -151
  611. package/core/renderers/zelos/measurables/bottom_row.ts +0 -53
  612. package/core/renderers/zelos/measurables/inputs.ts +0 -56
  613. package/core/renderers/zelos/measurables/row_elements.ts +0 -45
  614. package/core/renderers/zelos/measurables/top_row.ts +0 -58
  615. package/core/renderers/zelos/path_object.ts +0 -215
  616. package/core/renderers/zelos/renderer.ts +0 -142
  617. package/core/renderers/zelos/zelos.ts +0 -39
  618. package/core/scrollbar.ts +0 -870
  619. package/core/scrollbar_pair.ts +0 -321
  620. package/core/serialization/blocks.ts +0 -706
  621. package/core/serialization/exceptions.ts +0 -98
  622. package/core/serialization/priorities.ts +0 -32
  623. package/core/serialization/registry.ts +0 -43
  624. package/core/serialization/variables.ts +0 -96
  625. package/core/serialization/workspaces.ts +0 -106
  626. package/core/shortcut_items.ts +0 -266
  627. package/core/shortcut_registry.ts +0 -355
  628. package/core/sprites.ts +0 -29
  629. package/core/theme/classic.ts +0 -54
  630. package/core/theme/themes.ts +0 -22
  631. package/core/theme/zelos.ts +0 -91
  632. package/core/theme.ts +0 -221
  633. package/core/theme_manager.ts +0 -186
  634. package/core/toolbox/category.ts +0 -679
  635. package/core/toolbox/collapsible_category.ts +0 -273
  636. package/core/toolbox/separator.ts +0 -105
  637. package/core/toolbox/toolbox.ts +0 -1044
  638. package/core/toolbox/toolbox_item.ts +0 -147
  639. package/core/tooltip.ts +0 -463
  640. package/core/touch.ts +0 -306
  641. package/core/touch_gesture.ts +0 -295
  642. package/core/trashcan.ts +0 -671
  643. package/core/utils/aria.ts +0 -160
  644. package/core/utils/array.ts +0 -32
  645. package/core/utils/colour.ts +0 -276
  646. package/core/utils/coordinate.ts +0 -124
  647. package/core/utils/deprecation.ts +0 -41
  648. package/core/utils/dom.ts +0 -408
  649. package/core/utils/idgenerator.ts +0 -80
  650. package/core/utils/keycodes.ts +0 -169
  651. package/core/utils/math.ts +0 -61
  652. package/core/utils/metrics.ts +0 -97
  653. package/core/utils/object.ts +0 -95
  654. package/core/utils/parsing.ts +0 -261
  655. package/core/utils/rect.ts +0 -62
  656. package/core/utils/sentinel.ts +0 -23
  657. package/core/utils/size.ts +0 -51
  658. package/core/utils/string.ts +0 -308
  659. package/core/utils/style.ts +0 -306
  660. package/core/utils/svg.ts +0 -88
  661. package/core/utils/svg_math.ts +0 -269
  662. package/core/utils/svg_paths.ts +0 -140
  663. package/core/utils/toolbox.ts +0 -433
  664. package/core/utils/useragent.ts +0 -135
  665. package/core/utils/xml.ts +0 -97
  666. package/core/utils.ts +0 -428
  667. package/core/variable_map.ts +0 -392
  668. package/core/variable_model.ts +0 -82
  669. package/core/variables.ts +0 -596
  670. package/core/variables_dynamic.ts +0 -133
  671. package/core/warning.ts +0 -161
  672. package/core/widgetdiv.ts +0 -257
  673. package/core/workspace.ts +0 -801
  674. package/core/workspace_audio.ts +0 -156
  675. package/core/workspace_comment.ts +0 -398
  676. package/core/workspace_comment_svg.ts +0 -1127
  677. package/core/workspace_drag_surface_svg.ts +0 -187
  678. package/core/workspace_dragger.ts +0 -104
  679. package/core/workspace_svg.ts +0 -2655
  680. package/core/xml.ts +0 -1023
  681. package/core/zoom_controls.ts +0 -441
  682. package/generators/dart/all.js +0 -27
  683. package/generators/dart/colour.js +0 -105
  684. package/generators/dart/lists.js +0 -431
  685. package/generators/dart/logic.js +0 -123
  686. package/generators/dart/loops.js +0 -161
  687. package/generators/dart/math.js +0 -446
  688. package/generators/dart/procedures.js +0 -105
  689. package/generators/dart/text.js +0 -338
  690. package/generators/dart/variables.js +0 -32
  691. package/generators/dart/variables_dynamic.js +0 -21
  692. package/generators/dart.js +0 -303
  693. package/generators/javascript/all.js +0 -27
  694. package/generators/javascript/colour.js +0 -85
  695. package/generators/javascript/lists.js +0 -405
  696. package/generators/javascript/logic.js +0 -127
  697. package/generators/javascript/loops.js +0 -180
  698. package/generators/javascript/math.js +0 -401
  699. package/generators/javascript/procedures.js +0 -110
  700. package/generators/javascript/text.js +0 -371
  701. package/generators/javascript/variables.js +0 -32
  702. package/generators/javascript/variables_dynamic.js +0 -21
  703. package/generators/javascript.js +0 -322
  704. package/generators/lua/all.js +0 -27
  705. package/generators/lua/colour.js +0 -71
  706. package/generators/lua/lists.js +0 -348
  707. package/generators/lua/logic.js +0 -112
  708. package/generators/lua/loops.js +0 -168
  709. package/generators/lua/math.js +0 -406
  710. package/generators/lua/procedures.js +0 -106
  711. package/generators/lua/text.js +0 -327
  712. package/generators/lua/variables.js +0 -31
  713. package/generators/lua/variables_dynamic.js +0 -21
  714. package/generators/lua.js +0 -206
  715. package/generators/php/all.js +0 -27
  716. package/generators/php/colour.js +0 -81
  717. package/generators/php/lists.js +0 -481
  718. package/generators/php/logic.js +0 -119
  719. package/generators/php/loops.js +0 -161
  720. package/generators/php/math.js +0 -349
  721. package/generators/php/procedures.js +0 -125
  722. package/generators/php/text.js +0 -255
  723. package/generators/php/variables.js +0 -32
  724. package/generators/php/variables_dynamic.js +0 -21
  725. package/generators/php.js +0 -303
  726. package/generators/python/all.js +0 -27
  727. package/generators/python/colour.js +0 -67
  728. package/generators/python/lists.js +0 -346
  729. package/generators/python/logic.js +0 -120
  730. package/generators/python/loops.js +0 -206
  731. package/generators/python/math.js +0 -373
  732. package/generators/python/procedures.js +0 -129
  733. package/generators/python/text.js +0 -291
  734. package/generators/python/variables.js +0 -32
  735. package/generators/python/variables_dynamic.js +0 -21
  736. package/generators/python.js +0 -333
package/core/block.ts DELETED
@@ -1,2102 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2011 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- /**
8
- * @fileoverview The class representing one block.
9
- */
10
-
11
- /**
12
- * The class representing one block.
13
- * @class
14
- */
15
- import * as goog from '../closure/goog/goog.js';
16
- goog.declareModuleId('Blockly.Block');
17
-
18
- // Unused import preserved for side-effects. Remove if unneeded.
19
- import './events/events_block_change.js';
20
- // Unused import preserved for side-effects. Remove if unneeded.
21
- import './events/events_block_create.js';
22
- // Unused import preserved for side-effects. Remove if unneeded.
23
- import './events/events_block_delete.js';
24
-
25
- import {Blocks} from './blocks.js';
26
- import type {Comment} from './comment.js';
27
- import * as common from './common.js';
28
- import {Connection} from './connection.js';
29
- import {ConnectionType} from './connection_type.js';
30
- import * as constants from './constants.js';
31
- import type {Abstract} from './events/events_abstract.js';
32
- import type {BlockMove} from './events/events_block_move.js';
33
- import * as eventUtils from './events/utils.js';
34
- import * as Extensions from './extensions.js';
35
- import type {Field} from './field.js';
36
- import * as fieldRegistry from './field_registry.js';
37
- import {Align, Input} from './input.js';
38
- import {inputTypes} from './input_types.js';
39
- import type {IASTNodeLocation} from './interfaces/i_ast_node_location.js';
40
- import type {IDeletable} from './interfaces/i_deletable.js';
41
- import {ASTNode} from './keyboard_nav/ast_node.js';
42
- import type {Mutator} from './mutator.js';
43
- import * as Tooltip from './tooltip.js';
44
- import * as arrayUtils from './utils/array.js';
45
- import {Coordinate} from './utils/coordinate.js';
46
- import * as idGenerator from './utils/idgenerator.js';
47
- import * as parsing from './utils/parsing.js';
48
- import {Size} from './utils/size.js';
49
- import type {VariableModel} from './variable_model.js';
50
- import type {Workspace} from './workspace.js';
51
-
52
-
53
- /**
54
- * Class for one block.
55
- * Not normally called directly, workspace.newBlock() is preferred.
56
- * @unrestricted
57
- * @alias Blockly.Block
58
- */
59
- export class Block implements IASTNodeLocation, IDeletable {
60
- /**
61
- * An optional callback method to use whenever the block's parent workspace
62
- * changes. This is usually only called from the constructor, the block type
63
- * initializer function, or an extension initializer function.
64
- */
65
- onchange?: ((p1: Abstract) => AnyDuringMigration)|null;
66
-
67
- /** The language-neutral ID given to the collapsed input. */
68
- static readonly COLLAPSED_INPUT_NAME: string = constants.COLLAPSED_INPUT_NAME;
69
-
70
- /** The language-neutral ID given to the collapsed field. */
71
- static readonly COLLAPSED_FIELD_NAME: string = constants.COLLAPSED_FIELD_NAME;
72
-
73
- /**
74
- * Optional text data that round-trips between blocks and XML.
75
- * Has no effect. May be used by 3rd parties for meta information.
76
- */
77
- data: string|null = null;
78
-
79
- /**
80
- * Has this block been disposed of?
81
- * @internal
82
- */
83
- disposed = false;
84
-
85
- /**
86
- * Colour of the block as HSV hue value (0-360)
87
- * This may be null if the block colour was not set via a hue number.
88
- */
89
- private hue_: number|null = null;
90
-
91
- /** Colour of the block in '#RRGGBB' format. */
92
- protected colour_ = '#000000';
93
-
94
- /** Name of the block style. */
95
- protected styleName_ = '';
96
-
97
- /** An optional method called during initialization. */
98
- init?: (() => AnyDuringMigration)|null = undefined;
99
-
100
- /**
101
- * An optional serialization method for defining how to serialize the
102
- * mutation state to XML. This must be coupled with defining
103
- * `domToMutation`.
104
- */
105
- mutationToDom?: ((...p1: AnyDuringMigration[]) => Element)|null = undefined;
106
-
107
- /**
108
- * An optional deserialization method for defining how to deserialize the
109
- * mutation state from XML. This must be coupled with defining
110
- * `mutationToDom`.
111
- */
112
- domToMutation?: ((p1: Element) => AnyDuringMigration)|null = undefined;
113
-
114
- /**
115
- * An optional serialization method for defining how to serialize the
116
- * block's extra state (eg mutation state) to something JSON compatible.
117
- * This must be coupled with defining `loadExtraState`.
118
- */
119
- saveExtraState?: (() => AnyDuringMigration)|null = undefined;
120
-
121
- /**
122
- * An optional serialization method for defining how to deserialize the
123
- * block's extra state (eg mutation state) from something JSON compatible.
124
- * This must be coupled with defining `saveExtraState`.
125
- */
126
- loadExtraState?:
127
- ((p1: AnyDuringMigration) => AnyDuringMigration)|null = undefined;
128
-
129
- /**
130
- * An optional property for suppressing adding STATEMENT_PREFIX and
131
- * STATEMENT_SUFFIX to generated code.
132
- */
133
- suppressPrefixSuffix: boolean|null = false;
134
-
135
- /**
136
- * An optional property for declaring developer variables. Return a list of
137
- * variable names for use by generators. Developer variables are never
138
- * shown to the user, but are declared as global variables in the generated
139
- * code.
140
- */
141
- getDeveloperVariables?: (() => string[]) = undefined;
142
-
143
- /**
144
- * An optional function that reconfigures the block based on the contents of
145
- * the mutator dialog.
146
- */
147
- compose?: ((p1: Block) => void) = undefined;
148
-
149
- /**
150
- * An optional function that populates the mutator's dialog with
151
- * this block's components.
152
- */
153
- decompose?: ((p1: Workspace) => Block) = undefined;
154
- id: string;
155
- // AnyDuringMigration because: Type 'null' is not assignable to type
156
- // 'Connection'.
157
- outputConnection: Connection = null as AnyDuringMigration;
158
- // AnyDuringMigration because: Type 'null' is not assignable to type
159
- // 'Connection'.
160
- nextConnection: Connection = null as AnyDuringMigration;
161
- // AnyDuringMigration because: Type 'null' is not assignable to type
162
- // 'Connection'.
163
- previousConnection: Connection = null as AnyDuringMigration;
164
- inputList: Input[] = [];
165
- inputsInline?: boolean = undefined;
166
- private disabled = false;
167
- tooltip: Tooltip.TipInfo = '';
168
- contextMenu = true;
169
-
170
- protected parentBlock_: this|null = null;
171
-
172
- protected childBlocks_: this[] = [];
173
-
174
- private deletable_ = true;
175
-
176
- private movable_ = true;
177
-
178
- private editable_ = true;
179
-
180
- private isShadow_ = false;
181
-
182
- protected collapsed_ = false;
183
- protected outputShape_: number|null = null;
184
-
185
- /**
186
- * A string representing the comment attached to this block.
187
- * @deprecated August 2019. Use getCommentText instead.
188
- */
189
- comment: string|Comment|null = null;
190
- /** @internal */
191
- commentModel: CommentModel;
192
- private readonly xy_: Coordinate;
193
- isInFlyout: boolean;
194
- isInMutator: boolean;
195
- RTL: boolean;
196
-
197
- /** True if this block is an insertion marker. */
198
- protected isInsertionMarker_ = false;
199
-
200
- /** Name of the type of hat. */
201
- hat?: string = undefined;
202
-
203
- rendered: boolean|null = null;
204
-
205
- /**
206
- * String for block help, or function that returns a URL. Null for no help.
207
- */
208
- // AnyDuringMigration because: Type 'null' is not assignable to type 'string
209
- // | Function'.
210
- helpUrl: string|Function = null as AnyDuringMigration;
211
-
212
- /** A bound callback function to use when the parent workspace changes. */
213
- private onchangeWrapper_: ((p1: Abstract) => AnyDuringMigration)|null = null;
214
-
215
- /**
216
- * A count of statement inputs on the block.
217
- * @internal
218
- */
219
- statementInputCount = 0;
220
- // TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
221
- type!: string;
222
- // Record initial inline state.
223
- inputsInlineDefault?: boolean;
224
- workspace: Workspace;
225
-
226
- /**
227
- * @param workspace The block's workspace.
228
- * @param prototypeName Name of the language object containing type-specific
229
- * functions for this block.
230
- * @param opt_id Optional ID. Use this ID if provided, otherwise create a new
231
- * ID.
232
- * @throws When the prototypeName is not valid or not allowed.
233
- */
234
- constructor(workspace: Workspace, prototypeName: string, opt_id?: string) {
235
- this.workspace = workspace;
236
-
237
- this.id = opt_id && !workspace.getBlockById(opt_id) ? opt_id :
238
- idGenerator.genUid();
239
- workspace.setBlockById(this.id, this);
240
-
241
- /** A model of the comment attached to this block. */
242
- this.commentModel = {text: null, pinned: false, size: new Size(160, 80)};
243
-
244
- /**
245
- * The block's position in workspace units. (0, 0) is at the workspace's
246
- * origin; scale does not change this value.
247
- */
248
- this.xy_ = new Coordinate(0, 0);
249
- this.isInFlyout = workspace.isFlyout;
250
- this.isInMutator = workspace.isMutator;
251
-
252
- this.RTL = workspace.RTL;
253
-
254
- // Copy the type-specific functions and data from the prototype.
255
- if (prototypeName) {
256
- this.type = prototypeName;
257
- const prototype = Blocks[prototypeName];
258
- if (!prototype || typeof prototype !== 'object') {
259
- throw TypeError('Invalid block definition for type: ' + prototypeName);
260
- }
261
- Object.assign(this, prototype);
262
- }
263
-
264
- workspace.addTopBlock(this);
265
- workspace.addTypedBlock(this);
266
-
267
- if (new.target === Block) {
268
- this.doInit_();
269
- }
270
- }
271
-
272
- /** Calls the init() function and handles associated event firing, etc. */
273
- protected doInit_() {
274
- // All events fired should be part of the same group.
275
- // Any events fired during init should not be undoable,
276
- // so that block creation is atomic.
277
- const existingGroup = eventUtils.getGroup();
278
- if (!existingGroup) {
279
- eventUtils.setGroup(true);
280
- }
281
- const initialUndoFlag = eventUtils.getRecordUndo();
282
-
283
- try {
284
- // Call an initialization function, if it exists.
285
- if (typeof this.init === 'function') {
286
- eventUtils.setRecordUndo(false);
287
- this.init();
288
- eventUtils.setRecordUndo(initialUndoFlag);
289
- }
290
-
291
- // Fire a create event.
292
- if (eventUtils.isEnabled()) {
293
- eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(this));
294
- }
295
- } finally {
296
- if (!existingGroup) {
297
- eventUtils.setGroup(false);
298
- }
299
- // In case init threw, recordUndo flag should still be reset.
300
- eventUtils.setRecordUndo(initialUndoFlag);
301
- }
302
- this.inputsInlineDefault = this.inputsInline;
303
-
304
- // Bind an onchange function, if it exists.
305
- if (typeof this.onchange === 'function') {
306
- this.setOnChange(this.onchange);
307
- }
308
- }
309
-
310
- /**
311
- * Dispose of this block.
312
- * @param healStack If true, then try to heal any gap by connecting the next
313
- * statement with the previous statement. Otherwise, dispose of all
314
- * children of this block.
315
- * @suppress {checkTypes}
316
- */
317
- dispose(healStack: boolean) {
318
- if (this.disposed) {
319
- // Already deleted.
320
- return;
321
- }
322
- // Terminate onchange event calls.
323
- if (this.onchangeWrapper_) {
324
- this.workspace.removeChangeListener(this.onchangeWrapper_);
325
- }
326
-
327
- this.unplug(healStack);
328
- if (eventUtils.isEnabled()) {
329
- eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_DELETE))!(this));
330
- }
331
- eventUtils.disable();
332
-
333
- try {
334
- // This block is now at the top of the workspace.
335
- // Remove this block from the workspace's list of top-most blocks.
336
- this.workspace.removeTopBlock(this);
337
- this.workspace.removeTypedBlock(this);
338
- // Remove from block database.
339
- this.workspace.removeBlockById(this.id);
340
-
341
- // First, dispose of all my children.
342
- for (let i = this.childBlocks_.length - 1; i >= 0; i--) {
343
- this.childBlocks_[i].dispose(false);
344
- }
345
- // Then dispose of myself.
346
- // Dispose of all inputs and their fields.
347
- for (let i = 0, input; input = this.inputList[i]; i++) {
348
- input.dispose();
349
- }
350
- this.inputList.length = 0;
351
- // Dispose of any remaining connections (next/previous/output).
352
- const connections = this.getConnections_(true);
353
- for (let i = 0, connection; connection = connections[i]; i++) {
354
- connection.dispose();
355
- }
356
- } finally {
357
- eventUtils.enable();
358
- this.disposed = true;
359
- }
360
- }
361
-
362
- /**
363
- * Call initModel on all fields on the block.
364
- * May be called more than once.
365
- * Either initModel or initSvg must be called after creating a block and
366
- * before the first interaction with it. Interactions include UI actions
367
- * (e.g. clicking and dragging) and firing events (e.g. create, delete, and
368
- * change).
369
- */
370
- initModel() {
371
- for (let i = 0, input; input = this.inputList[i]; i++) {
372
- for (let j = 0, field; field = input.fieldRow[j]; j++) {
373
- if (field.initModel) {
374
- field.initModel();
375
- }
376
- }
377
- }
378
- }
379
-
380
- /**
381
- * Unplug this block from its superior block. If this block is a statement,
382
- * optionally reconnect the block underneath with the block on top.
383
- * @param opt_healStack Disconnect child statement and reconnect stack.
384
- * Defaults to false.
385
- */
386
- unplug(opt_healStack?: boolean) {
387
- if (this.outputConnection) {
388
- this.unplugFromRow_(opt_healStack);
389
- }
390
- if (this.previousConnection) {
391
- this.unplugFromStack_(opt_healStack);
392
- }
393
- }
394
-
395
- /**
396
- * Unplug this block's output from an input on another block. Optionally
397
- * reconnect the block's parent to the only child block, if possible.
398
- * @param opt_healStack Disconnect right-side block and connect to left-side
399
- * block. Defaults to false.
400
- */
401
- private unplugFromRow_(opt_healStack?: boolean) {
402
- let parentConnection = null;
403
- if (this.outputConnection.isConnected()) {
404
- parentConnection = this.outputConnection.targetConnection;
405
- // Disconnect from any superior block.
406
- this.outputConnection.disconnect();
407
- }
408
-
409
- // Return early in obvious cases.
410
- if (!parentConnection || !opt_healStack) {
411
- return;
412
- }
413
-
414
- const thisConnection = this.getOnlyValueConnection_();
415
- if (!thisConnection || !thisConnection.isConnected() ||
416
- thisConnection.targetBlock()!.isShadow()) {
417
- // Too many or too few possible connections on this block, or there's
418
- // nothing on the other side of this connection.
419
- return;
420
- }
421
-
422
- const childConnection = thisConnection.targetConnection;
423
- // Disconnect the child block.
424
- childConnection?.disconnect();
425
- // Connect child to the parent if possible, otherwise bump away.
426
- if (this.workspace.connectionChecker.canConnect(
427
- childConnection, parentConnection, false)) {
428
- parentConnection.connect(childConnection!);
429
- } else {
430
- childConnection?.onFailedConnect(parentConnection);
431
- }
432
- }
433
-
434
- /**
435
- * Returns the connection on the value input that is connected to another
436
- * block. When an insertion marker is connected to a connection with a block
437
- * already attached, the connected block is attached to the insertion marker.
438
- * Since only one block can be displaced and attached to the insertion marker
439
- * this should only ever return one connection.
440
- *
441
- * @return The connection on the value input, or null.
442
- */
443
- private getOnlyValueConnection_(): Connection|null {
444
- let connection = null;
445
- for (let i = 0; i < this.inputList.length; i++) {
446
- const thisConnection = this.inputList[i].connection;
447
- if (thisConnection &&
448
- thisConnection.type === ConnectionType.INPUT_VALUE &&
449
- thisConnection.targetConnection) {
450
- if (connection) {
451
- return null; // More than one value input found.
452
- }
453
- connection = thisConnection;
454
- }
455
- }
456
- return connection;
457
- }
458
-
459
- /**
460
- * Unplug this statement block from its superior block. Optionally reconnect
461
- * the block underneath with the block on top.
462
- * @param opt_healStack Disconnect child statement and reconnect stack.
463
- * Defaults to false.
464
- */
465
- private unplugFromStack_(opt_healStack?: boolean) {
466
- let previousTarget = null;
467
- if (this.previousConnection.isConnected()) {
468
- // Remember the connection that any next statements need to connect to.
469
- previousTarget = this.previousConnection.targetConnection;
470
- // Detach this block from the parent's tree.
471
- this.previousConnection.disconnect();
472
- }
473
- const nextBlock = this.getNextBlock();
474
- if (opt_healStack && nextBlock && !nextBlock.isShadow()) {
475
- // Disconnect the next statement.
476
- const nextTarget = this.nextConnection.targetConnection;
477
- nextTarget?.disconnect();
478
- if (previousTarget &&
479
- this.workspace.connectionChecker.canConnect(
480
- previousTarget, nextTarget, false)) {
481
- // Attach the next statement to the previous statement.
482
- previousTarget.connect(nextTarget!);
483
- }
484
- }
485
- }
486
-
487
- /**
488
- * Returns all connections originating from this block.
489
- * @param _all If true, return all connections even hidden ones.
490
- * @return Array of connections.
491
- * @internal
492
- */
493
- getConnections_(_all: boolean): Connection[] {
494
- const myConnections = [];
495
- if (this.outputConnection) {
496
- myConnections.push(this.outputConnection);
497
- }
498
- if (this.previousConnection) {
499
- myConnections.push(this.previousConnection);
500
- }
501
- if (this.nextConnection) {
502
- myConnections.push(this.nextConnection);
503
- }
504
- for (let i = 0, input; input = this.inputList[i]; i++) {
505
- if (input.connection) {
506
- myConnections.push(input.connection);
507
- }
508
- }
509
- return myConnections;
510
- }
511
-
512
- /**
513
- * Walks down a stack of blocks and finds the last next connection on the
514
- * stack.
515
- * @param ignoreShadows If true,the last connection on a non-shadow block will
516
- * be returned. If false, this will follow shadows to find the last
517
- * connection.
518
- * @return The last next connection on the stack, or null.
519
- * @internal
520
- */
521
- lastConnectionInStack(ignoreShadows: boolean): Connection|null {
522
- let nextConnection = this.nextConnection;
523
- while (nextConnection) {
524
- const nextBlock = nextConnection.targetBlock();
525
- if (!nextBlock || ignoreShadows && nextBlock.isShadow()) {
526
- return nextConnection;
527
- }
528
- nextConnection = nextBlock.nextConnection;
529
- }
530
- return null;
531
- }
532
-
533
- /**
534
- * Bump unconnected blocks out of alignment. Two blocks which aren't actually
535
- * connected should not coincidentally line up on screen.
536
- */
537
- bumpNeighbours() {}
538
- // noop.
539
-
540
- /**
541
- * Return the parent block or null if this block is at the top level. The
542
- * parent block is either the block connected to the previous connection (for
543
- * a statement block) or the block connected to the output connection (for a
544
- * value block).
545
- * @return The block (if any) that holds the current block.
546
- */
547
- getParent(): this|null {
548
- return this.parentBlock_;
549
- }
550
-
551
- /**
552
- * Return the input that connects to the specified block.
553
- * @param block A block connected to an input on this block.
554
- * @return The input (if any) that connects to the specified block.
555
- */
556
- getInputWithBlock(block: Block): Input|null {
557
- for (let i = 0, input; input = this.inputList[i]; i++) {
558
- if (input.connection && input.connection.targetBlock() === block) {
559
- return input;
560
- }
561
- }
562
- return null;
563
- }
564
-
565
- /**
566
- * Return the parent block that surrounds the current block, or null if this
567
- * block has no surrounding block. A parent block might just be the previous
568
- * statement, whereas the surrounding block is an if statement, while loop,
569
- * etc.
570
- * @return The block (if any) that surrounds the current block.
571
- */
572
- getSurroundParent(): this|null {
573
- let block = this;
574
- let prevBlock;
575
- do {
576
- prevBlock = block;
577
- // AnyDuringMigration because: Type 'Block | null' is not assignable to
578
- // type 'this'.
579
- block = block.getParent() as AnyDuringMigration;
580
- if (!block) {
581
- // Ran off the top.
582
- return null;
583
- }
584
- } while (block.getNextBlock() === prevBlock);
585
- // This block is an enclosing parent, not just a statement in a stack.
586
- return block;
587
- }
588
-
589
- /**
590
- * Return the next statement block directly connected to this block.
591
- * @return The next statement block or null.
592
- */
593
- getNextBlock(): Block|null {
594
- return this.nextConnection && this.nextConnection.targetBlock();
595
- }
596
-
597
- /**
598
- * Returns the block connected to the previous connection.
599
- * @return The previous statement block or null.
600
- */
601
- getPreviousBlock(): Block|null {
602
- return this.previousConnection && this.previousConnection.targetBlock();
603
- }
604
-
605
- /**
606
- * Return the connection on the first statement input on this block, or null
607
- * if there are none.
608
- * @return The first statement connection or null.
609
- * @internal
610
- */
611
- getFirstStatementConnection(): Connection|null {
612
- for (let i = 0, input; input = this.inputList[i]; i++) {
613
- if (input.connection &&
614
- input.connection.type === ConnectionType.NEXT_STATEMENT) {
615
- return input.connection;
616
- }
617
- }
618
- return null;
619
- }
620
-
621
- /**
622
- * Return the top-most block in this block's tree.
623
- * This will return itself if this block is at the top level.
624
- * @return The root block.
625
- */
626
- getRootBlock(): this {
627
- let rootBlock: this;
628
- let block: this|null = this;
629
- do {
630
- rootBlock = block;
631
- block = rootBlock.parentBlock_;
632
- } while (block);
633
- return rootBlock;
634
- }
635
-
636
- /**
637
- * Walk up from the given block up through the stack of blocks to find
638
- * the top block of the sub stack. If we are nested in a statement input only
639
- * find the top-most nested block. Do not go all the way to the root block.
640
- * @return The top block in a stack.
641
- * @internal
642
- */
643
- getTopStackBlock(): this {
644
- let block = this;
645
- let previous;
646
- do {
647
- previous = block.getPreviousBlock();
648
- // AnyDuringMigration because: Type 'Block' is not assignable to type
649
- // 'this'.
650
- } while (previous && previous.getNextBlock() === block &&
651
- (block = previous as AnyDuringMigration));
652
- return block;
653
- }
654
-
655
- /**
656
- * Find all the blocks that are directly nested inside this one.
657
- * Includes value and statement inputs, as well as any following statement.
658
- * Excludes any connection on an output tab or any preceding statement.
659
- * Blocks are optionally sorted by position; top to bottom.
660
- * @param ordered Sort the list if true.
661
- * @return Array of blocks.
662
- */
663
- getChildren(ordered: boolean): Block[] {
664
- if (!ordered) {
665
- return this.childBlocks_;
666
- }
667
- const blocks = [];
668
- for (let i = 0, input; input = this.inputList[i]; i++) {
669
- if (input.connection) {
670
- const child = input.connection.targetBlock();
671
- if (child) {
672
- blocks.push(child);
673
- }
674
- }
675
- }
676
- const next = this.getNextBlock();
677
- if (next) {
678
- blocks.push(next);
679
- }
680
- return blocks;
681
- }
682
-
683
- /**
684
- * Set parent of this block to be a new block or null.
685
- * @param newParent New parent block.
686
- * @internal
687
- */
688
- setParent(newParent: this|null) {
689
- if (newParent === this.parentBlock_) {
690
- return;
691
- }
692
-
693
- // Check that block is connected to new parent if new parent is not null and
694
- // that block is not connected to superior one if new parent is null.
695
- const targetBlock =
696
- this.previousConnection && this.previousConnection.targetBlock() ||
697
- this.outputConnection && this.outputConnection.targetBlock();
698
- const isConnected = !!targetBlock;
699
-
700
- if (isConnected && newParent && targetBlock !== newParent) {
701
- throw Error('Block connected to superior one that is not new parent.');
702
- } else if (!isConnected && newParent) {
703
- throw Error('Block not connected to new parent.');
704
- } else if (isConnected && !newParent) {
705
- throw Error(
706
- 'Cannot set parent to null while block is still connected to' +
707
- ' superior block.');
708
- }
709
-
710
- // This block hasn't actually moved on-screen, so there's no need to
711
- // update
712
- // its connection locations.
713
- if (this.parentBlock_) {
714
- // Remove this block from the old parent's child list.
715
- arrayUtils.removeElem(this.parentBlock_.childBlocks_, this);
716
- } else {
717
- // New parent must be non-null so remove this block from the workspace's
718
- // list of top-most blocks.
719
- this.workspace.removeTopBlock(this);
720
- }
721
-
722
- this.parentBlock_ = newParent;
723
- if (newParent) {
724
- // Add this block to the new parent's child list.
725
- newParent.childBlocks_.push(this);
726
- } else {
727
- this.workspace.addTopBlock(this);
728
- }
729
- }
730
-
731
- /**
732
- * Find all the blocks that are directly or indirectly nested inside this one.
733
- * Includes this block in the list.
734
- * Includes value and statement inputs, as well as any following statements.
735
- * Excludes any connection on an output tab or any preceding statements.
736
- * Blocks are optionally sorted by position; top to bottom.
737
- * @param ordered Sort the list if true.
738
- * @return Flattened array of blocks.
739
- */
740
- getDescendants(ordered: boolean): this[] {
741
- const blocks = [this];
742
- const childBlocks = this.getChildren(ordered);
743
- for (let child, i = 0; child = childBlocks[i]; i++) {
744
- // AnyDuringMigration because: Argument of type 'Block[]' is not
745
- // assignable to parameter of type 'this[]'.
746
- blocks.push.apply(
747
- blocks, child.getDescendants(ordered) as AnyDuringMigration);
748
- }
749
- return blocks;
750
- }
751
-
752
- /**
753
- * Get whether this block is deletable or not.
754
- * @return True if deletable.
755
- */
756
- isDeletable(): boolean {
757
- return this.deletable_ && !this.isShadow_ && !this.disposed &&
758
- !this.workspace.options.readOnly;
759
- }
760
-
761
- /**
762
- * Set whether this block is deletable or not.
763
- * @param deletable True if deletable.
764
- */
765
- setDeletable(deletable: boolean) {
766
- this.deletable_ = deletable;
767
- }
768
-
769
- /**
770
- * Get whether this block is movable or not.
771
- * @return True if movable.
772
- */
773
- isMovable(): boolean {
774
- return this.movable_ && !this.isShadow_ && !this.disposed &&
775
- !this.workspace.options.readOnly;
776
- }
777
-
778
- /**
779
- * Set whether this block is movable or not.
780
- * @param movable True if movable.
781
- */
782
- setMovable(movable: boolean) {
783
- this.movable_ = movable;
784
- }
785
-
786
- /**
787
- * Get whether is block is duplicatable or not. If duplicating this block and
788
- * descendants will put this block over the workspace's capacity this block is
789
- * not duplicatable. If duplicating this block and descendants will put any
790
- * type over their maxInstances this block is not duplicatable.
791
- * @return True if duplicatable.
792
- */
793
- isDuplicatable(): boolean {
794
- if (!this.workspace.hasBlockLimits()) {
795
- return true;
796
- }
797
- return this.workspace.isCapacityAvailable(
798
- common.getBlockTypeCounts(this, true));
799
- }
800
-
801
- /**
802
- * Get whether this block is a shadow block or not.
803
- * @return True if a shadow.
804
- */
805
- isShadow(): boolean {
806
- return this.isShadow_;
807
- }
808
-
809
- /**
810
- * Set whether this block is a shadow block or not.
811
- * @param shadow True if a shadow.
812
- * @internal
813
- */
814
- setShadow(shadow: boolean) {
815
- this.isShadow_ = shadow;
816
- }
817
-
818
- /**
819
- * Get whether this block is an insertion marker block or not.
820
- * @return True if an insertion marker.
821
- */
822
- isInsertionMarker(): boolean {
823
- return this.isInsertionMarker_;
824
- }
825
-
826
- /**
827
- * Set whether this block is an insertion marker block or not.
828
- * Once set this cannot be unset.
829
- * @param insertionMarker True if an insertion marker.
830
- * @internal
831
- */
832
- setInsertionMarker(insertionMarker: boolean) {
833
- this.isInsertionMarker_ = insertionMarker;
834
- }
835
-
836
- /**
837
- * Get whether this block is editable or not.
838
- * @return True if editable.
839
- */
840
- isEditable(): boolean {
841
- return this.editable_ && !this.disposed && !this.workspace.options.readOnly;
842
- }
843
-
844
- /**
845
- * Set whether this block is editable or not.
846
- * @param editable True if editable.
847
- */
848
- setEditable(editable: boolean) {
849
- this.editable_ = editable;
850
- for (let i = 0, input; input = this.inputList[i]; i++) {
851
- for (let j = 0, field; field = input.fieldRow[j]; j++) {
852
- field.updateEditable();
853
- }
854
- }
855
- }
856
-
857
- /**
858
- * Returns if this block has been disposed of / deleted.
859
- * @return True if this block has been disposed of / deleted.
860
- */
861
- isDisposed(): boolean {
862
- return this.disposed;
863
- }
864
-
865
- /**
866
- * Find the connection on this block that corresponds to the given connection
867
- * on the other block.
868
- * Used to match connections between a block and its insertion marker.
869
- * @param otherBlock The other block to match against.
870
- * @param conn The other connection to match.
871
- * @return The matching connection on this block, or null.
872
- * @internal
873
- */
874
- getMatchingConnection(otherBlock: Block, conn: Connection): Connection|null {
875
- const connections = this.getConnections_(true);
876
- const otherConnections = otherBlock.getConnections_(true);
877
- if (connections.length !== otherConnections.length) {
878
- throw Error('Connection lists did not match in length.');
879
- }
880
- for (let i = 0; i < otherConnections.length; i++) {
881
- if (otherConnections[i] === conn) {
882
- return connections[i];
883
- }
884
- }
885
- return null;
886
- }
887
-
888
- /**
889
- * Set the URL of this block's help page.
890
- * @param url URL string for block help, or function that returns a URL. Null
891
- * for no help.
892
- */
893
- setHelpUrl(url: string|Function) {
894
- this.helpUrl = url;
895
- }
896
-
897
- /**
898
- * Sets the tooltip for this block.
899
- * @param newTip The text for the tooltip, a function that returns the text
900
- * for the tooltip, or a parent object whose tooltip will be used. To not
901
- * display a tooltip pass the empty string.
902
- */
903
- setTooltip(newTip: Tooltip.TipInfo) {
904
- this.tooltip = newTip;
905
- }
906
-
907
- /**
908
- * Returns the tooltip text for this block.
909
- * @return The tooltip text for this block.
910
- */
911
- getTooltip(): string {
912
- return Tooltip.getTooltipOfObject(this);
913
- }
914
-
915
- /**
916
- * Get the colour of a block.
917
- * @return #RRGGBB string.
918
- */
919
- getColour(): string {
920
- return this.colour_;
921
- }
922
-
923
- /**
924
- * Get the name of the block style.
925
- * @return Name of the block style.
926
- */
927
- getStyleName(): string {
928
- return this.styleName_;
929
- }
930
-
931
- /**
932
- * Get the HSV hue value of a block. Null if hue not set.
933
- * @return Hue value (0-360).
934
- */
935
- getHue(): number|null {
936
- return this.hue_;
937
- }
938
-
939
- /**
940
- * Change the colour of a block.
941
- * @param colour HSV hue value (0 to 360), #RRGGBB string, or a message
942
- * reference string pointing to one of those two values.
943
- */
944
- setColour(colour: number|string) {
945
- const parsed = parsing.parseBlockColour(colour);
946
- this.hue_ = parsed.hue;
947
- this.colour_ = parsed.hex;
948
- }
949
-
950
- /**
951
- * Set the style and colour values of a block.
952
- * @param blockStyleName Name of the block style.
953
- */
954
- setStyle(blockStyleName: string) {
955
- this.styleName_ = blockStyleName;
956
- }
957
-
958
- /**
959
- * Sets a callback function to use whenever the block's parent workspace
960
- * changes, replacing any prior onchange handler. This is usually only called
961
- * from the constructor, the block type initializer function, or an extension
962
- * initializer function.
963
- * @param onchangeFn The callback to call when the block's workspace changes.
964
- * @throws {Error} if onchangeFn is not falsey and not a function.
965
- */
966
- setOnChange(onchangeFn: (p1: Abstract) => AnyDuringMigration) {
967
- if (onchangeFn && typeof onchangeFn !== 'function') {
968
- throw Error('onchange must be a function.');
969
- }
970
- if (this.onchangeWrapper_) {
971
- this.workspace.removeChangeListener(this.onchangeWrapper_);
972
- }
973
- this.onchange = onchangeFn;
974
- this.onchangeWrapper_ = onchangeFn.bind(this);
975
- this.workspace.addChangeListener(this.onchangeWrapper_);
976
- }
977
-
978
- /**
979
- * Returns the named field from a block.
980
- * @param name The name of the field.
981
- * @return Named field, or null if field does not exist.
982
- */
983
- getField(name: string): Field|null {
984
- if (typeof name !== 'string') {
985
- throw TypeError(
986
- 'Block.prototype.getField expects a string ' +
987
- 'with the field name but received ' +
988
- (name === undefined ? 'nothing' : name + ' of type ' + typeof name) +
989
- ' instead');
990
- }
991
- for (let i = 0, input; input = this.inputList[i]; i++) {
992
- for (let j = 0, field; field = input.fieldRow[j]; j++) {
993
- if (field.name === name) {
994
- return field;
995
- }
996
- }
997
- }
998
- return null;
999
- }
1000
-
1001
- /**
1002
- * Return all variables referenced by this block.
1003
- * @return List of variable ids.
1004
- */
1005
- getVars(): string[] {
1006
- const vars = [];
1007
- for (let i = 0, input; input = this.inputList[i]; i++) {
1008
- for (let j = 0, field; field = input.fieldRow[j]; j++) {
1009
- if (field.referencesVariables()) {
1010
- vars.push(field.getValue());
1011
- }
1012
- }
1013
- }
1014
- return vars;
1015
- }
1016
-
1017
- /**
1018
- * Return all variables referenced by this block.
1019
- * @return List of variable models.
1020
- * @internal
1021
- */
1022
- getVarModels(): VariableModel[] {
1023
- const vars = [];
1024
- for (let i = 0, input; input = this.inputList[i]; i++) {
1025
- for (let j = 0, field; field = input.fieldRow[j]; j++) {
1026
- if (field.referencesVariables()) {
1027
- const model =
1028
- this.workspace.getVariableById(field.getValue() as string);
1029
- // Check if the variable actually exists (and isn't just a potential
1030
- // variable).
1031
- if (model) {
1032
- vars.push(model);
1033
- }
1034
- }
1035
- }
1036
- }
1037
- return vars;
1038
- }
1039
-
1040
- /**
1041
- * Notification that a variable is renaming but keeping the same ID. If the
1042
- * variable is in use on this block, rerender to show the new name.
1043
- * @param variable The variable being renamed.
1044
- * @internal
1045
- */
1046
- updateVarName(variable: VariableModel) {
1047
- for (let i = 0, input; input = this.inputList[i]; i++) {
1048
- for (let j = 0, field; field = input.fieldRow[j]; j++) {
1049
- if (field.referencesVariables() &&
1050
- variable.getId() === field.getValue()) {
1051
- field.refreshVariableName();
1052
- }
1053
- }
1054
- }
1055
- }
1056
-
1057
- /**
1058
- * Notification that a variable is renaming.
1059
- * If the ID matches one of this block's variables, rename it.
1060
- * @param oldId ID of variable to rename.
1061
- * @param newId ID of new variable. May be the same as oldId, but with an
1062
- * updated name.
1063
- */
1064
- renameVarById(oldId: string, newId: string) {
1065
- for (let i = 0, input; input = this.inputList[i]; i++) {
1066
- for (let j = 0, field; field = input.fieldRow[j]; j++) {
1067
- if (field.referencesVariables() && oldId === field.getValue()) {
1068
- field.setValue(newId);
1069
- }
1070
- }
1071
- }
1072
- }
1073
-
1074
- /**
1075
- * Returns the language-neutral value of the given field.
1076
- * @param name The name of the field.
1077
- * @return Value of the field or null if field does not exist.
1078
- */
1079
- getFieldValue(name: string): AnyDuringMigration {
1080
- const field = this.getField(name);
1081
- if (field) {
1082
- return field.getValue();
1083
- }
1084
- return null;
1085
- }
1086
-
1087
- /**
1088
- * Sets the value of the given field for this block.
1089
- * @param newValue The value to set.
1090
- * @param name The name of the field to set the value of.
1091
- */
1092
- setFieldValue(newValue: AnyDuringMigration, name: string) {
1093
- const field = this.getField(name);
1094
- if (!field) {
1095
- throw Error('Field "' + name + '" not found.');
1096
- }
1097
- field.setValue(newValue);
1098
- }
1099
-
1100
- /**
1101
- * Set whether this block can chain onto the bottom of another block.
1102
- * @param newBoolean True if there can be a previous statement.
1103
- * @param opt_check Statement type or list of statement types. Null/undefined
1104
- * if any type could be connected.
1105
- */
1106
- setPreviousStatement(newBoolean: boolean, opt_check?: string|string[]|null) {
1107
- if (newBoolean) {
1108
- if (opt_check === undefined) {
1109
- opt_check = null;
1110
- }
1111
- if (!this.previousConnection) {
1112
- this.previousConnection =
1113
- this.makeConnection_(ConnectionType.PREVIOUS_STATEMENT);
1114
- }
1115
- this.previousConnection.setCheck(opt_check);
1116
- } else {
1117
- if (this.previousConnection) {
1118
- if (this.previousConnection.isConnected()) {
1119
- throw Error(
1120
- 'Must disconnect previous statement before removing ' +
1121
- 'connection.');
1122
- }
1123
- this.previousConnection.dispose();
1124
- // AnyDuringMigration because: Type 'null' is not assignable to type
1125
- // 'Connection'.
1126
- this.previousConnection = null as AnyDuringMigration;
1127
- }
1128
- }
1129
- }
1130
-
1131
- /**
1132
- * Set whether another block can chain onto the bottom of this block.
1133
- * @param newBoolean True if there can be a next statement.
1134
- * @param opt_check Statement type or list of statement types. Null/undefined
1135
- * if any type could be connected.
1136
- */
1137
- setNextStatement(newBoolean: boolean, opt_check?: string|string[]|null) {
1138
- if (newBoolean) {
1139
- if (opt_check === undefined) {
1140
- opt_check = null;
1141
- }
1142
- if (!this.nextConnection) {
1143
- this.nextConnection =
1144
- this.makeConnection_(ConnectionType.NEXT_STATEMENT);
1145
- }
1146
- this.nextConnection.setCheck(opt_check);
1147
- } else {
1148
- if (this.nextConnection) {
1149
- if (this.nextConnection.isConnected()) {
1150
- throw Error(
1151
- 'Must disconnect next statement before removing ' +
1152
- 'connection.');
1153
- }
1154
- this.nextConnection.dispose();
1155
- // AnyDuringMigration because: Type 'null' is not assignable to type
1156
- // 'Connection'.
1157
- this.nextConnection = null as AnyDuringMigration;
1158
- }
1159
- }
1160
- }
1161
-
1162
- /**
1163
- * Set whether this block returns a value.
1164
- * @param newBoolean True if there is an output.
1165
- * @param opt_check Returned type or list of returned types. Null or
1166
- * undefined if any type could be returned (e.g. variable get).
1167
- */
1168
- setOutput(newBoolean: boolean, opt_check?: string|string[]|null) {
1169
- if (newBoolean) {
1170
- if (opt_check === undefined) {
1171
- opt_check = null;
1172
- }
1173
- if (!this.outputConnection) {
1174
- this.outputConnection =
1175
- this.makeConnection_(ConnectionType.OUTPUT_VALUE);
1176
- }
1177
- this.outputConnection.setCheck(opt_check);
1178
- } else {
1179
- if (this.outputConnection) {
1180
- if (this.outputConnection.isConnected()) {
1181
- throw Error(
1182
- 'Must disconnect output value before removing connection.');
1183
- }
1184
- this.outputConnection.dispose();
1185
- // AnyDuringMigration because: Type 'null' is not assignable to type
1186
- // 'Connection'.
1187
- this.outputConnection = null as AnyDuringMigration;
1188
- }
1189
- }
1190
- }
1191
-
1192
- /**
1193
- * Set whether value inputs are arranged horizontally or vertically.
1194
- * @param newBoolean True if inputs are horizontal.
1195
- */
1196
- setInputsInline(newBoolean: boolean) {
1197
- if (this.inputsInline !== newBoolean) {
1198
- eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
1199
- (this, 'inline', null, this.inputsInline, newBoolean));
1200
- this.inputsInline = newBoolean;
1201
- }
1202
- }
1203
-
1204
- /**
1205
- * Get whether value inputs are arranged horizontally or vertically.
1206
- * @return True if inputs are horizontal.
1207
- */
1208
- getInputsInline(): boolean {
1209
- if (this.inputsInline !== undefined) {
1210
- // Set explicitly.
1211
- return this.inputsInline;
1212
- }
1213
- // Not defined explicitly. Figure out what would look best.
1214
- for (let i = 1; i < this.inputList.length; i++) {
1215
- if (this.inputList[i - 1].type === inputTypes.DUMMY &&
1216
- this.inputList[i].type === inputTypes.DUMMY) {
1217
- // Two dummy inputs in a row. Don't inline them.
1218
- return false;
1219
- }
1220
- }
1221
- for (let i = 1; i < this.inputList.length; i++) {
1222
- if (this.inputList[i - 1].type === inputTypes.VALUE &&
1223
- this.inputList[i].type === inputTypes.DUMMY) {
1224
- // Dummy input after a value input. Inline them.
1225
- return true;
1226
- }
1227
- }
1228
- return false;
1229
- }
1230
-
1231
- /**
1232
- * Set the block's output shape.
1233
- * @param outputShape Value representing an output shape.
1234
- */
1235
- setOutputShape(outputShape: number|null) {
1236
- this.outputShape_ = outputShape;
1237
- }
1238
-
1239
- /**
1240
- * Get the block's output shape.
1241
- * @return Value representing output shape if one exists.
1242
- */
1243
- getOutputShape(): number|null {
1244
- return this.outputShape_;
1245
- }
1246
-
1247
- /**
1248
- * Get whether this block is enabled or not.
1249
- * @return True if enabled.
1250
- */
1251
- isEnabled(): boolean {
1252
- return !this.disabled;
1253
- }
1254
-
1255
- /**
1256
- * Set whether the block is enabled or not.
1257
- * @param enabled True if enabled.
1258
- */
1259
- setEnabled(enabled: boolean) {
1260
- if (this.isEnabled() !== enabled) {
1261
- const oldValue = this.disabled;
1262
- this.disabled = !enabled;
1263
- eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
1264
- (this, 'disabled', null, oldValue, !enabled));
1265
- }
1266
- }
1267
-
1268
- /**
1269
- * Get whether the block is disabled or not due to parents.
1270
- * The block's own disabled property is not considered.
1271
- * @return True if disabled.
1272
- */
1273
- getInheritedDisabled(): boolean {
1274
- let ancestor = this.getSurroundParent();
1275
- while (ancestor) {
1276
- if (ancestor.disabled) {
1277
- return true;
1278
- }
1279
- ancestor = ancestor.getSurroundParent();
1280
- }
1281
- // Ran off the top.
1282
- return false;
1283
- }
1284
-
1285
- /**
1286
- * Get whether the block is collapsed or not.
1287
- * @return True if collapsed.
1288
- */
1289
- isCollapsed(): boolean {
1290
- return this.collapsed_;
1291
- }
1292
-
1293
- /**
1294
- * Set whether the block is collapsed or not.
1295
- * @param collapsed True if collapsed.
1296
- */
1297
- setCollapsed(collapsed: boolean) {
1298
- if (this.collapsed_ !== collapsed) {
1299
- eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
1300
- (this, 'collapsed', null, this.collapsed_, collapsed));
1301
- this.collapsed_ = collapsed;
1302
- }
1303
- }
1304
-
1305
- /**
1306
- * Create a human-readable text representation of this block and any children.
1307
- * @param opt_maxLength Truncate the string to this length.
1308
- * @param opt_emptyToken The placeholder string used to denote an empty field.
1309
- * If not specified, '?' is used.
1310
- * @return Text of block.
1311
- */
1312
- toString(opt_maxLength?: number, opt_emptyToken?: string): string {
1313
- let text = [];
1314
- const emptyFieldPlaceholder = opt_emptyToken || '?';
1315
-
1316
- // Temporarily set flag to navigate to all fields.
1317
- const prevNavigateFields = ASTNode.NAVIGATE_ALL_FIELDS;
1318
- ASTNode.NAVIGATE_ALL_FIELDS = true;
1319
-
1320
- let node = ASTNode.createBlockNode(this);
1321
- const rootNode = node;
1322
-
1323
- /**
1324
- * Whether or not to add parentheses around an input.
1325
- * @param connection The connection.
1326
- * @return True if we should add parentheses around the input.
1327
- */
1328
- function shouldAddParentheses(connection: Connection): boolean {
1329
- let checks = connection.getCheck();
1330
- if (!checks && connection.targetConnection) {
1331
- checks = connection.targetConnection.getCheck();
1332
- }
1333
- return !!checks &&
1334
- (checks.indexOf('Boolean') !== -1 || checks.indexOf('Number') !== -1);
1335
- }
1336
-
1337
- /** Check that we haven't circled back to the original root node. */
1338
- function checkRoot() {
1339
- if (node && node.getType() === rootNode?.getType() &&
1340
- node.getLocation() === rootNode?.getLocation()) {
1341
- node = null;
1342
- }
1343
- }
1344
-
1345
- // Traverse the AST building up our text string.
1346
- while (node) {
1347
- switch (node.getType()) {
1348
- case ASTNode.types.INPUT: {
1349
- const connection = node.getLocation() as Connection;
1350
- if (!node.in()) {
1351
- text.push(emptyFieldPlaceholder);
1352
- } else if (shouldAddParentheses(connection)) {
1353
- text.push('(');
1354
- }
1355
- break;
1356
- }
1357
- case ASTNode.types.FIELD: {
1358
- const field = node.getLocation() as Field;
1359
- if (field.name !== constants.COLLAPSED_FIELD_NAME) {
1360
- text.push(field.getText());
1361
- }
1362
- break;
1363
- }
1364
- }
1365
-
1366
- const current = node;
1367
- node = current.in() || current.next();
1368
- if (!node) {
1369
- // Can't go in or next, keep going out until we can go next.
1370
- node = current.out();
1371
- checkRoot();
1372
- while (node && !node.next()) {
1373
- node = node.out();
1374
- checkRoot();
1375
- // If we hit an input on the way up, possibly close out parentheses.
1376
- if (node && node.getType() === ASTNode.types.INPUT &&
1377
- shouldAddParentheses(node.getLocation() as Connection)) {
1378
- text.push(')');
1379
- }
1380
- }
1381
- if (node) {
1382
- node = node.next();
1383
- }
1384
- }
1385
- }
1386
-
1387
- // Restore state of NAVIGATE_ALL_FIELDS.
1388
- ASTNode.NAVIGATE_ALL_FIELDS = prevNavigateFields;
1389
-
1390
- // Run through our text array and simplify expression to remove parentheses
1391
- // around single field blocks.
1392
- // E.g. ['repeat', '(', '10', ')', 'times', 'do', '?']
1393
- for (let i = 2; i < text.length; i++) {
1394
- if (text[i - 2] === '(' && text[i] === ')') {
1395
- text[i - 2] = text[i - 1];
1396
- text.splice(i - 1, 2);
1397
- }
1398
- }
1399
-
1400
- // Join the text array, removing spaces around added parentheses.
1401
- // AnyDuringMigration because: Type 'string' is not assignable to type
1402
- // 'any[]'.
1403
- text = text.reduce(function(acc, value) {
1404
- return acc + (acc.substr(-1) === '(' || value === ')' ? '' : ' ') + value;
1405
- }, '') as AnyDuringMigration;
1406
- // AnyDuringMigration because: Property 'trim' does not exist on type
1407
- // 'any[]'.
1408
- text = (text as AnyDuringMigration).trim() || '???';
1409
- if (opt_maxLength) {
1410
- // TODO: Improve truncation so that text from this block is given
1411
- // priority. E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not
1412
- // "1+2+3+4+5...". E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...".
1413
- if (text.length > opt_maxLength) {
1414
- // AnyDuringMigration because: Type 'string' is not assignable to type
1415
- // 'any[]'.
1416
- text = (text.substring(0, opt_maxLength - 3) + '...') as
1417
- AnyDuringMigration;
1418
- }
1419
- }
1420
- return text;
1421
- }
1422
-
1423
- /**
1424
- * Shortcut for appending a value input row.
1425
- * @param name Language-neutral identifier which may used to find this input
1426
- * again. Should be unique to this block.
1427
- * @return The input object created.
1428
- */
1429
- appendValueInput(name: string): Input {
1430
- return this.appendInput_(inputTypes.VALUE, name);
1431
- }
1432
-
1433
- /**
1434
- * Shortcut for appending a statement input row.
1435
- * @param name Language-neutral identifier which may used to find this input
1436
- * again. Should be unique to this block.
1437
- * @return The input object created.
1438
- */
1439
- appendStatementInput(name: string): Input {
1440
- return this.appendInput_(inputTypes.STATEMENT, name);
1441
- }
1442
-
1443
- /**
1444
- * Shortcut for appending a dummy input row.
1445
- * @param opt_name Language-neutral identifier which may used to find this
1446
- * input again. Should be unique to this block.
1447
- * @return The input object created.
1448
- */
1449
- appendDummyInput(opt_name?: string): Input {
1450
- return this.appendInput_(inputTypes.DUMMY, opt_name || '');
1451
- }
1452
-
1453
- /**
1454
- * Initialize this block using a cross-platform, internationalization-friendly
1455
- * JSON description.
1456
- * @param json Structured data describing the block.
1457
- */
1458
- jsonInit(json: AnyDuringMigration) {
1459
- const warningPrefix = json['type'] ? 'Block "' + json['type'] + '": ' : '';
1460
-
1461
- // Validate inputs.
1462
- if (json['output'] && json['previousStatement']) {
1463
- throw Error(
1464
- warningPrefix +
1465
- 'Must not have both an output and a previousStatement.');
1466
- }
1467
-
1468
- // Set basic properties of block.
1469
- // Makes styles backward compatible with old way of defining hat style.
1470
- if (json['style'] && json['style'].hat) {
1471
- this.hat = json['style'].hat;
1472
- // Must set to null so it doesn't error when checking for style and
1473
- // colour.
1474
- json['style'] = null;
1475
- }
1476
-
1477
- if (json['style'] && json['colour']) {
1478
- throw Error(warningPrefix + 'Must not have both a colour and a style.');
1479
- } else if (json['style']) {
1480
- this.jsonInitStyle_(json, warningPrefix);
1481
- } else {
1482
- this.jsonInitColour_(json, warningPrefix);
1483
- }
1484
-
1485
- // Interpolate the message blocks.
1486
- let i = 0;
1487
- while (json['message' + i] !== undefined) {
1488
- this.interpolate_(
1489
- json['message' + i], json['args' + i] || [],
1490
- json['lastDummyAlign' + i], warningPrefix);
1491
- i++;
1492
- }
1493
-
1494
- if (json['inputsInline'] !== undefined) {
1495
- this.setInputsInline(json['inputsInline']);
1496
- }
1497
- // Set output and previous/next connections.
1498
- if (json['output'] !== undefined) {
1499
- this.setOutput(true, json['output']);
1500
- }
1501
- if (json['outputShape'] !== undefined) {
1502
- this.setOutputShape(json['outputShape']);
1503
- }
1504
- if (json['previousStatement'] !== undefined) {
1505
- this.setPreviousStatement(true, json['previousStatement']);
1506
- }
1507
- if (json['nextStatement'] !== undefined) {
1508
- this.setNextStatement(true, json['nextStatement']);
1509
- }
1510
- if (json['tooltip'] !== undefined) {
1511
- const rawValue = json['tooltip'];
1512
- const localizedText = parsing.replaceMessageReferences(rawValue);
1513
- this.setTooltip(localizedText);
1514
- }
1515
- if (json['enableContextMenu'] !== undefined) {
1516
- this.contextMenu = !!json['enableContextMenu'];
1517
- }
1518
- if (json['suppressPrefixSuffix'] !== undefined) {
1519
- this.suppressPrefixSuffix = !!json['suppressPrefixSuffix'];
1520
- }
1521
- if (json['helpUrl'] !== undefined) {
1522
- const rawValue = json['helpUrl'];
1523
- const localizedValue = parsing.replaceMessageReferences(rawValue);
1524
- this.setHelpUrl(localizedValue);
1525
- }
1526
- if (typeof json['extensions'] === 'string') {
1527
- console.warn(
1528
- warningPrefix +
1529
- 'JSON attribute \'extensions\' should be an array of' +
1530
- ' strings. Found raw string in JSON for \'' + json['type'] +
1531
- '\' block.');
1532
- json['extensions'] = [json['extensions']]; // Correct and continue.
1533
- }
1534
-
1535
- // Add the mutator to the block.
1536
- if (json['mutator'] !== undefined) {
1537
- Extensions.apply(json['mutator'], this, true);
1538
- }
1539
-
1540
- const extensionNames = json['extensions'];
1541
- if (Array.isArray(extensionNames)) {
1542
- for (let j = 0; j < extensionNames.length; j++) {
1543
- Extensions.apply(extensionNames[j], this, false);
1544
- }
1545
- }
1546
- }
1547
-
1548
- /**
1549
- * Initialize the colour of this block from the JSON description.
1550
- * @param json Structured data describing the block.
1551
- * @param warningPrefix Warning prefix string identifying block.
1552
- */
1553
- private jsonInitColour_(json: AnyDuringMigration, warningPrefix: string) {
1554
- if ('colour' in json) {
1555
- if (json['colour'] === undefined) {
1556
- console.warn(warningPrefix + 'Undefined colour value.');
1557
- } else {
1558
- const rawValue = json['colour'];
1559
- try {
1560
- this.setColour(rawValue);
1561
- } catch (e) {
1562
- console.warn(warningPrefix + 'Illegal colour value: ', rawValue);
1563
- }
1564
- }
1565
- }
1566
- }
1567
-
1568
- /**
1569
- * Initialize the style of this block from the JSON description.
1570
- * @param json Structured data describing the block.
1571
- * @param warningPrefix Warning prefix string identifying block.
1572
- */
1573
- private jsonInitStyle_(json: AnyDuringMigration, warningPrefix: string) {
1574
- const blockStyleName = json['style'];
1575
- try {
1576
- this.setStyle(blockStyleName);
1577
- } catch (styleError) {
1578
- console.warn(warningPrefix + 'Style does not exist: ', blockStyleName);
1579
- }
1580
- }
1581
-
1582
- /**
1583
- * Add key/values from mixinObj to this block object. By default, this method
1584
- * will check that the keys in mixinObj will not overwrite existing values in
1585
- * the block, including prototype values. This provides some insurance against
1586
- * mixin / extension incompatibilities with future block features. This check
1587
- * can be disabled by passing true as the second argument.
1588
- * @param mixinObj The key/values pairs to add to this block object.
1589
- * @param opt_disableCheck Option flag to disable overwrite checks.
1590
- */
1591
- mixin(mixinObj: AnyDuringMigration, opt_disableCheck?: boolean) {
1592
- if (opt_disableCheck !== undefined &&
1593
- typeof opt_disableCheck !== 'boolean') {
1594
- throw Error('opt_disableCheck must be a boolean if provided');
1595
- }
1596
- if (!opt_disableCheck) {
1597
- const overwrites = [];
1598
- for (const key in mixinObj) {
1599
- if ((this as AnyDuringMigration)[key] !== undefined) {
1600
- overwrites.push(key);
1601
- }
1602
- }
1603
- if (overwrites.length) {
1604
- throw Error(
1605
- 'Mixin will overwrite block members: ' +
1606
- JSON.stringify(overwrites));
1607
- }
1608
- }
1609
- Object.assign(this, mixinObj);
1610
- }
1611
-
1612
- /**
1613
- * Interpolate a message description onto the block.
1614
- * @param message Text contains interpolation tokens (%1, %2, ...) that match
1615
- * with fields or inputs defined in the args array.
1616
- * @param args Array of arguments to be interpolated.
1617
- * @param lastDummyAlign If a dummy input is added at the end, how should it
1618
- * be aligned?
1619
- * @param warningPrefix Warning prefix string identifying block.
1620
- */
1621
- private interpolate_(
1622
- message: string, args: AnyDuringMigration[],
1623
- lastDummyAlign: string|undefined, warningPrefix: string) {
1624
- const tokens = parsing.tokenizeInterpolation(message);
1625
- this.validateTokens_(tokens, args.length);
1626
- const elements = this.interpolateArguments_(tokens, args, lastDummyAlign);
1627
-
1628
- // An array of [field, fieldName] tuples.
1629
- const fieldStack = [];
1630
- for (let i = 0, element; element = elements[i]; i++) {
1631
- if (this.isInputKeyword_(element['type'])) {
1632
- const input = this.inputFromJson_(element, warningPrefix);
1633
- // Should never be null, but just in case.
1634
- if (input) {
1635
- for (let j = 0, tuple; tuple = fieldStack[j]; j++) {
1636
- input.appendField(tuple[0], tuple[1]);
1637
- }
1638
- fieldStack.length = 0;
1639
- }
1640
- } else {
1641
- // All other types, including ones starting with 'input_' get routed
1642
- // here.
1643
- const field = this.fieldFromJson_(element);
1644
- if (field) {
1645
- fieldStack.push([field, element['name']]);
1646
- }
1647
- }
1648
- }
1649
- }
1650
-
1651
- /**
1652
- * Validates that the tokens are within the correct bounds, with no
1653
- * duplicates, and that all of the arguments are referred to. Throws errors if
1654
- * any of these things are not true.
1655
- * @param tokens An array of tokens to validate
1656
- * @param argsCount The number of args that need to be referred to.
1657
- */
1658
- private validateTokens_(tokens: Array<string|number>, argsCount: number) {
1659
- const visitedArgsHash = [];
1660
- let visitedArgsCount = 0;
1661
- for (let i = 0; i < tokens.length; i++) {
1662
- const token = tokens[i];
1663
- if (typeof token !== 'number') {
1664
- continue;
1665
- }
1666
- if (token < 1 || token > argsCount) {
1667
- throw Error(
1668
- 'Block "' + this.type + '": ' +
1669
- 'Message index %' + token + ' out of range.');
1670
- }
1671
- if (visitedArgsHash[token]) {
1672
- throw Error(
1673
- 'Block "' + this.type + '": ' +
1674
- 'Message index %' + token + ' duplicated.');
1675
- }
1676
- visitedArgsHash[token] = true;
1677
- visitedArgsCount++;
1678
- }
1679
- if (visitedArgsCount !== argsCount) {
1680
- throw Error(
1681
- 'Block "' + this.type + '": ' +
1682
- 'Message does not reference all ' + argsCount + ' arg(s).');
1683
- }
1684
- }
1685
-
1686
- /**
1687
- * Inserts args in place of numerical tokens. String args are converted to
1688
- * JSON that defines a label field. If necessary an extra dummy input is added
1689
- * to the end of the elements.
1690
- * @param tokens The tokens to interpolate
1691
- * @param args The arguments to insert.
1692
- * @param lastDummyAlign The alignment the added dummy input should have, if
1693
- * we are required to add one.
1694
- * @return The JSON definitions of field and inputs to add to the block.
1695
- */
1696
- private interpolateArguments_(
1697
- tokens: Array<string|number>, args: Array<AnyDuringMigration|string>,
1698
- lastDummyAlign: string|undefined): AnyDuringMigration[] {
1699
- const elements = [];
1700
- for (let i = 0; i < tokens.length; i++) {
1701
- let element = tokens[i];
1702
- if (typeof element === 'number') {
1703
- element = args[element - 1];
1704
- }
1705
- // Args can be strings, which is why this isn't elseif.
1706
- if (typeof element === 'string') {
1707
- // AnyDuringMigration because: Type '{ text: string; type: string; } |
1708
- // null' is not assignable to type 'string | number'.
1709
- element = this.stringToFieldJson_(element) as AnyDuringMigration;
1710
- if (!element) {
1711
- continue;
1712
- }
1713
- }
1714
- elements.push(element);
1715
- }
1716
-
1717
- const length = elements.length;
1718
- if (length &&
1719
- !this.isInputKeyword_(
1720
- (elements as AnyDuringMigration)[length - 1]['type'])) {
1721
- const dummyInput = {'type': 'input_dummy'};
1722
- if (lastDummyAlign) {
1723
- (dummyInput as AnyDuringMigration)['align'] = lastDummyAlign;
1724
- }
1725
- elements.push(dummyInput);
1726
- }
1727
-
1728
- return elements;
1729
- }
1730
-
1731
- /**
1732
- * Creates a field from the JSON definition of a field. If a field with the
1733
- * given type cannot be found, this attempts to create a different field using
1734
- * the 'alt' property of the JSON definition (if it exists).
1735
- * @param element The element to try to turn into a field.
1736
- * @return The field defined by the JSON, or null if one couldn't be created.
1737
- */
1738
- private fieldFromJson_(element: {alt?: string, type?: string, text?: string}):
1739
- Field|null {
1740
- const field = fieldRegistry.fromJson(element);
1741
- if (!field && element['alt']) {
1742
- if (typeof element['alt'] === 'string') {
1743
- const json = this.stringToFieldJson_(element['alt']);
1744
- return json ? this.fieldFromJson_(json) : null;
1745
- }
1746
- return this.fieldFromJson_(element['alt']);
1747
- }
1748
- return field;
1749
- }
1750
-
1751
- /**
1752
- * Creates an input from the JSON definition of an input. Sets the input's
1753
- * check and alignment if they are provided.
1754
- * @param element The JSON to turn into an input.
1755
- * @param warningPrefix The prefix to add to warnings to help the developer
1756
- * debug.
1757
- * @return The input that has been created, or null if one could not be
1758
- * created for some reason (should never happen).
1759
- */
1760
- private inputFromJson_(element: AnyDuringMigration, warningPrefix: string):
1761
- Input|null {
1762
- const alignmentLookup = {
1763
- 'LEFT': Align.LEFT,
1764
- 'RIGHT': Align.RIGHT,
1765
- 'CENTRE': Align.CENTRE,
1766
- 'CENTER': Align.CENTRE,
1767
- };
1768
-
1769
- let input = null;
1770
- switch (element['type']) {
1771
- case 'input_value':
1772
- input = this.appendValueInput(element['name']);
1773
- break;
1774
- case 'input_statement':
1775
- input = this.appendStatementInput(element['name']);
1776
- break;
1777
- case 'input_dummy':
1778
- input = this.appendDummyInput(element['name']);
1779
- break;
1780
- }
1781
- // Should never be hit because of interpolate_'s checks, but just in case.
1782
- if (!input) {
1783
- return null;
1784
- }
1785
-
1786
- if (element['check']) {
1787
- input.setCheck(element['check']);
1788
- }
1789
- if (element['align']) {
1790
- const alignment =
1791
- (alignmentLookup as
1792
- AnyDuringMigration)[element['align'].toUpperCase()];
1793
- if (alignment === undefined) {
1794
- console.warn(warningPrefix + 'Illegal align value: ', element['align']);
1795
- } else {
1796
- input.setAlign(alignment);
1797
- }
1798
- }
1799
- return input;
1800
- }
1801
-
1802
- /**
1803
- * Returns true if the given string matches one of the input keywords.
1804
- * @param str The string to check.
1805
- * @return True if the given string matches one of the input keywords, false
1806
- * otherwise.
1807
- */
1808
- private isInputKeyword_(str: string): boolean {
1809
- return str === 'input_value' || str === 'input_statement' ||
1810
- str === 'input_dummy';
1811
- }
1812
-
1813
- /**
1814
- * Turns a string into the JSON definition of a label field. If the string
1815
- * becomes an empty string when trimmed, this returns null.
1816
- * @param str String to turn into the JSON definition of a label field.
1817
- * @return The JSON definition or null.
1818
- */
1819
- private stringToFieldJson_(str: string): {text: string, type: string}|null {
1820
- str = str.trim();
1821
- if (str) {
1822
- return {
1823
- 'type': 'field_label',
1824
- 'text': str,
1825
- };
1826
- }
1827
- return null;
1828
- }
1829
-
1830
- /**
1831
- * Add a value input, statement input or local variable to this block.
1832
- * @param type One of Blockly.inputTypes.
1833
- * @param name Language-neutral identifier which may used to find this input
1834
- * again. Should be unique to this block.
1835
- * @return The input object created.
1836
- */
1837
- protected appendInput_(type: number, name: string): Input {
1838
- let connection = null;
1839
- if (type === inputTypes.VALUE || type === inputTypes.STATEMENT) {
1840
- connection = this.makeConnection_(type);
1841
- }
1842
- if (type === inputTypes.STATEMENT) {
1843
- this.statementInputCount++;
1844
- }
1845
- // AnyDuringMigration because: Argument of type 'Connection | null' is not
1846
- // assignable to parameter of type 'Connection'.
1847
- const input =
1848
- new Input(type, name, this, (connection as AnyDuringMigration));
1849
- // Append input to list.
1850
- this.inputList.push(input);
1851
- return input;
1852
- }
1853
-
1854
- /**
1855
- * Move a named input to a different location on this block.
1856
- * @param name The name of the input to move.
1857
- * @param refName Name of input that should be after the moved input, or null
1858
- * to be the input at the end.
1859
- */
1860
- moveInputBefore(name: string, refName: string|null) {
1861
- if (name === refName) {
1862
- return;
1863
- }
1864
- // Find both inputs.
1865
- let inputIndex = -1;
1866
- let refIndex = refName ? -1 : this.inputList.length;
1867
- for (let i = 0, input; input = this.inputList[i]; i++) {
1868
- if (input.name === name) {
1869
- inputIndex = i;
1870
- if (refIndex !== -1) {
1871
- break;
1872
- }
1873
- } else if (refName && input.name === refName) {
1874
- refIndex = i;
1875
- if (inputIndex !== -1) {
1876
- break;
1877
- }
1878
- }
1879
- }
1880
- if (inputIndex === -1) {
1881
- throw Error('Named input "' + name + '" not found.');
1882
- }
1883
- if (refIndex === -1) {
1884
- throw Error('Reference input "' + refName + '" not found.');
1885
- }
1886
- this.moveNumberedInputBefore(inputIndex, refIndex);
1887
- }
1888
-
1889
- /**
1890
- * Move a numbered input to a different location on this block.
1891
- * @param inputIndex Index of the input to move.
1892
- * @param refIndex Index of input that should be after the moved input.
1893
- */
1894
- moveNumberedInputBefore(inputIndex: number, refIndex: number) {
1895
- // Validate arguments.
1896
- if (inputIndex === refIndex) {
1897
- throw Error('Can\'t move input to itself.');
1898
- }
1899
- if (inputIndex >= this.inputList.length) {
1900
- throw RangeError('Input index ' + inputIndex + ' out of bounds.');
1901
- }
1902
- if (refIndex > this.inputList.length) {
1903
- throw RangeError('Reference input ' + refIndex + ' out of bounds.');
1904
- }
1905
- // Remove input.
1906
- const input = this.inputList[inputIndex];
1907
- this.inputList.splice(inputIndex, 1);
1908
- if (inputIndex < refIndex) {
1909
- refIndex--;
1910
- }
1911
- // Reinsert input.
1912
- this.inputList.splice(refIndex, 0, input);
1913
- }
1914
-
1915
- /**
1916
- * Remove an input from this block.
1917
- * @param name The name of the input.
1918
- * @param opt_quiet True to prevent an error if input is not present.
1919
- * @return True if operation succeeds, false if input is not present and
1920
- * opt_quiet is true.
1921
- * @throws {Error} if the input is not present and opt_quiet is not true.
1922
- */
1923
- removeInput(name: string, opt_quiet?: boolean): boolean {
1924
- for (let i = 0, input; input = this.inputList[i]; i++) {
1925
- if (input.name === name) {
1926
- if (input.type === inputTypes.STATEMENT) {
1927
- this.statementInputCount--;
1928
- }
1929
- input.dispose();
1930
- this.inputList.splice(i, 1);
1931
- return true;
1932
- }
1933
- }
1934
- if (opt_quiet) {
1935
- return false;
1936
- }
1937
- throw Error('Input not found: ' + name);
1938
- }
1939
-
1940
- /**
1941
- * Fetches the named input object.
1942
- * @param name The name of the input.
1943
- * @return The input object, or null if input does not exist.
1944
- */
1945
- getInput(name: string): Input|null {
1946
- for (let i = 0, input; input = this.inputList[i]; i++) {
1947
- if (input.name === name) {
1948
- return input;
1949
- }
1950
- }
1951
- // This input does not exist.
1952
- return null;
1953
- }
1954
-
1955
- /**
1956
- * Fetches the block attached to the named input.
1957
- * @param name The name of the input.
1958
- * @return The attached value block, or null if the input is either
1959
- * disconnected or if the input does not exist.
1960
- */
1961
- getInputTargetBlock(name: string): Block|null {
1962
- const input = this.getInput(name);
1963
- return input && input.connection && input.connection.targetBlock();
1964
- }
1965
-
1966
- /**
1967
- * Returns the comment on this block (or null if there is no comment).
1968
- * @return Block's comment.
1969
- */
1970
- getCommentText(): string|null {
1971
- return this.commentModel.text;
1972
- }
1973
-
1974
- /**
1975
- * Set this block's comment text.
1976
- * @param text The text, or null to delete.
1977
- */
1978
- setCommentText(text: string|null) {
1979
- if (this.commentModel.text === text) {
1980
- return;
1981
- }
1982
- eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CHANGE))!
1983
- (this, 'comment', null, this.commentModel.text, text));
1984
- this.commentModel.text = text;
1985
- // AnyDuringMigration because: Type 'string | null' is not assignable to
1986
- // type 'string | Comment'.
1987
- this.comment = text as AnyDuringMigration; // For backwards compatibility.
1988
- }
1989
-
1990
- /**
1991
- * Set this block's warning text.
1992
- * @param _text The text, or null to delete.
1993
- * @param _opt_id An optional ID for the warning text to be able to maintain
1994
- * multiple warnings.
1995
- */
1996
- setWarningText(_text: string|null, _opt_id?: string) {}
1997
- // NOP.
1998
-
1999
- /**
2000
- * Give this block a mutator dialog.
2001
- * @param _mutator A mutator dialog instance or null to remove.
2002
- */
2003
- setMutator(_mutator: Mutator) {}
2004
- // NOP.
2005
-
2006
- /**
2007
- * Return the coordinates of the top-left corner of this block relative to the
2008
- * drawing surface's origin (0,0), in workspace units.
2009
- * @return Object with .x and .y properties.
2010
- */
2011
- getRelativeToSurfaceXY(): Coordinate {
2012
- return this.xy_;
2013
- }
2014
-
2015
- /**
2016
- * Move a block by a relative offset.
2017
- * @param dx Horizontal offset, in workspace units.
2018
- * @param dy Vertical offset, in workspace units.
2019
- */
2020
- moveBy(dx: number, dy: number) {
2021
- if (this.parentBlock_) {
2022
- throw Error('Block has parent.');
2023
- }
2024
- const event =
2025
- new (eventUtils.get(eventUtils.BLOCK_MOVE))!(this) as BlockMove;
2026
- this.xy_.translate(dx, dy);
2027
- event.recordNew();
2028
- eventUtils.fire(event);
2029
- }
2030
-
2031
- /**
2032
- * Create a connection of the specified type.
2033
- * @param type The type of the connection to create.
2034
- * @return A new connection of the specified type.
2035
- */
2036
- protected makeConnection_(type: number): Connection {
2037
- return new Connection(this, type);
2038
- }
2039
-
2040
- /**
2041
- * Recursively checks whether all statement and value inputs are filled with
2042
- * blocks. Also checks all following statement blocks in this stack.
2043
- * @param opt_shadowBlocksAreFilled An optional argument controlling whether
2044
- * shadow blocks are counted as filled. Defaults to true.
2045
- * @return True if all inputs are filled, false otherwise.
2046
- */
2047
- allInputsFilled(opt_shadowBlocksAreFilled?: boolean): boolean {
2048
- // Account for the shadow block filledness toggle.
2049
- if (opt_shadowBlocksAreFilled === undefined) {
2050
- opt_shadowBlocksAreFilled = true;
2051
- }
2052
- if (!opt_shadowBlocksAreFilled && this.isShadow()) {
2053
- return false;
2054
- }
2055
-
2056
- // Recursively check each input block of the current block.
2057
- for (let i = 0, input; input = this.inputList[i]; i++) {
2058
- if (!input.connection) {
2059
- continue;
2060
- }
2061
- const target = input.connection.targetBlock();
2062
- if (!target || !target.allInputsFilled(opt_shadowBlocksAreFilled)) {
2063
- return false;
2064
- }
2065
- }
2066
-
2067
- // Recursively check the next block after the current block.
2068
- const next = this.getNextBlock();
2069
- if (next) {
2070
- return next.allInputsFilled(opt_shadowBlocksAreFilled);
2071
- }
2072
-
2073
- return true;
2074
- }
2075
-
2076
- /**
2077
- * This method returns a string describing this Block in developer terms (type
2078
- * name and ID; English only).
2079
- *
2080
- * Intended to on be used in console logs and errors. If you need a string
2081
- * that uses the user's native language (including block text, field values,
2082
- * and child blocks), use [toString()]{@link Block#toString}.
2083
- * @return The description.
2084
- */
2085
- toDevString(): string {
2086
- let msg = this.type ? '"' + this.type + '" block' : 'Block';
2087
- if (this.id) {
2088
- msg += ' (id="' + this.id + '")';
2089
- }
2090
- return msg;
2091
- }
2092
- }
2093
-
2094
- export namespace Block {
2095
- export interface CommentModel {
2096
- text: string|null;
2097
- pinned: boolean;
2098
- size: Size;
2099
- }
2100
- }
2101
-
2102
- export type CommentModel = Block.CommentModel;