blockly 8.20220331.0-beta.0 → 9.0.0-beta.1

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