blockly 8.0.4-beta.0 → 8.0.5-beta.0
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.
- package/blockly.min.js +2421 -2688
- package/blockly_compressed.js +1499 -1994
- package/blockly_compressed.js.map +1 -1
- package/blocks/blocks.js +3 -2
- package/blocks/colour.js +3 -1
- package/blocks/lists.js +94 -22
- package/blocks/logic.js +14 -6
- package/blocks/loops.js +5 -3
- package/blocks/math.js +3 -1
- package/blocks/procedures.js +3 -1
- package/blocks/text.js +14 -6
- package/blocks/variables.js +3 -1
- package/blocks/variables_dynamic.js +3 -1
- package/blocks.d.ts +0 -2
- package/blocks_compressed.js +189 -171
- package/blocks_compressed.js.map +1 -1
- package/closure/goog/base.d.ts +1 -0
- package/closure/goog/base_minimal.d.ts +18 -0
- package/closure/goog/goog.d.ts +25 -0
- package/core/any_aliases.d.ts +1 -0
- package/core/any_aliases.ts +1 -0
- package/core/block.d.ts +779 -0
- package/core/{block.js → block.ts} +610 -719
- package/core/block_animations.d.ts +33 -0
- package/core/{block_animations.js → block_animations.ts} +75 -79
- package/core/block_drag_surface.d.ts +111 -0
- package/core/{block_drag_surface.js → block_drag_surface.ts} +85 -117
- package/core/block_dragger.d.ts +143 -0
- package/core/{block_dragger.js → block_dragger.ts} +139 -176
- package/core/block_svg.d.ts +588 -0
- package/core/{block_svg.js → block_svg.ts} +494 -630
- package/core/blockly.d.ts +562 -0
- package/core/blockly.js +1 -1
- package/core/blockly.ts +749 -0
- package/core/blockly_options.d.ts +69 -0
- package/core/blockly_options.ts +81 -0
- package/core/blocks.d.ts +17 -0
- package/core/{blocks.js → blocks.ts} +4 -8
- package/core/browser_events.d.ts +85 -0
- package/core/{browser_events.js → browser_events.ts} +98 -93
- package/core/bubble.d.ts +279 -0
- package/core/{bubble.js → bubble.ts} +277 -370
- package/core/bubble_dragger.d.ts +73 -0
- package/core/bubble_dragger.ts +229 -0
- package/core/bump_objects.d.ts +34 -0
- package/core/{bump_objects.js → bump_objects.ts} +54 -52
- package/core/clipboard.d.ts +42 -0
- package/core/clipboard.ts +91 -0
- package/core/comment.d.ts +113 -0
- package/core/{comment.js → comment.ts} +135 -185
- package/core/common.d.ts +129 -0
- package/core/{common.js → common.ts} +105 -82
- package/core/component_manager.d.ts +91 -0
- package/core/component_manager.ts +211 -0
- package/core/config.d.ts +23 -0
- package/core/{config.js → config.ts} +12 -19
- package/core/connection.d.ts +232 -0
- package/core/{connection.js → connection.ts} +187 -237
- package/core/connection_checker.d.ts +78 -0
- package/core/{connection_checker.js → connection_checker.ts} +66 -77
- package/core/connection_db.d.ts +91 -0
- package/core/{connection_db.js → connection_db.ts} +62 -87
- package/core/connection_type.d.ts +15 -0
- package/core/{connection_type.js → connection_type.ts} +8 -12
- package/core/constants.d.ts +15 -0
- package/core/{constants.js → constants.ts} +4 -8
- package/core/contextmenu.d.ts +80 -0
- package/core/{contextmenu.js → contextmenu.ts} +118 -153
- package/core/contextmenu_items.d.ts +77 -0
- package/core/contextmenu_items.ts +576 -0
- package/core/contextmenu_registry.d.ts +105 -0
- package/core/contextmenu_registry.ts +179 -0
- package/core/css.d.ts +24 -0
- package/core/{css.js → css.ts} +16 -24
- package/core/delete_area.d.ts +47 -0
- package/core/delete_area.ts +82 -0
- package/core/dialog.d.ts +61 -0
- package/core/dialog.ts +127 -0
- package/core/drag_target.d.ts +63 -0
- package/core/drag_target.ts +94 -0
- package/core/dropdowndiv.d.ts +155 -0
- package/core/{dropdowndiv.js → dropdowndiv.ts} +262 -333
- package/core/events/events.d.ts +102 -0
- package/core/events/events.ts +123 -0
- package/core/events/events_abstract.d.ts +51 -0
- package/core/events/events_abstract.ts +112 -0
- package/core/events/events_block_base.d.ts +31 -0
- package/core/events/events_block_base.ts +65 -0
- package/core/events/events_block_change.d.ts +55 -0
- package/core/events/{events_block_change.js → events_block_change.ts} +45 -48
- package/core/events/events_block_create.d.ts +35 -0
- package/core/events/{events_block_create.js → events_block_create.ts} +30 -35
- package/core/events/events_block_delete.d.ts +36 -0
- package/core/events/{events_block_delete.js → events_block_delete.ts} +34 -39
- package/core/events/events_block_drag.d.ts +36 -0
- package/core/events/events_block_drag.ts +82 -0
- package/core/events/events_block_move.d.ts +51 -0
- package/core/events/{events_block_move.js → events_block_move.ts} +54 -50
- package/core/events/events_bubble_open.d.ts +35 -0
- package/core/events/events_bubble_open.ts +82 -0
- package/core/events/events_click.d.ts +36 -0
- package/core/events/{events_click.js → events_click.ts} +27 -30
- package/core/events/events_comment_base.d.ts +39 -0
- package/core/events/events_comment_base.ts +107 -0
- package/core/events/events_comment_change.d.ts +43 -0
- package/core/events/{events_comment_change.js → events_comment_change.ts} +31 -28
- package/core/events/events_comment_create.d.ts +35 -0
- package/core/events/{events_comment_create.js → events_comment_create.ts} +24 -26
- package/core/events/events_comment_delete.d.ts +35 -0
- package/core/events/{events_comment_delete.js → events_comment_delete.ts} +20 -24
- package/core/events/events_comment_move.d.ts +55 -0
- package/core/events/{events_comment_move.js → events_comment_move.ts} +39 -42
- package/core/events/events_marker_move.d.ts +40 -0
- package/core/events/events_marker_move.ts +99 -0
- package/core/events/events_selected.d.ts +34 -0
- package/core/events/events_selected.ts +78 -0
- package/core/events/events_theme_change.d.ts +30 -0
- package/core/events/{events_theme_change.js → events_theme_change.ts} +19 -24
- package/core/events/events_toolbox_item_select.d.ts +34 -0
- package/core/events/events_toolbox_item_select.ts +79 -0
- package/core/events/events_trashcan_open.d.ts +31 -0
- package/core/events/events_trashcan_open.ts +68 -0
- package/core/events/events_ui.d.ts +37 -0
- package/core/events/{events_ui.js → events_ui.ts} +27 -26
- package/core/events/events_ui_base.d.ts +26 -0
- package/core/events/{events_ui_base.js → events_ui_base.ts} +17 -26
- package/core/events/events_var_base.d.ts +31 -0
- package/core/events/events_var_base.ts +65 -0
- package/core/events/events_var_create.d.ts +35 -0
- package/core/events/{events_var_create.js → events_var_create.ts} +24 -25
- package/core/events/events_var_delete.d.ts +35 -0
- package/core/events/{events_var_delete.js → events_var_delete.ts} +24 -25
- package/core/events/events_var_rename.d.ts +36 -0
- package/core/events/{events_var_rename.js → events_var_rename.ts} +25 -26
- package/core/events/events_viewport.d.ts +39 -0
- package/core/events/events_viewport.ts +100 -0
- package/core/events/utils.d.ts +272 -0
- package/core/events/{utils.js → utils.ts} +148 -219
- package/core/events/workspace_events.d.ts +36 -0
- package/core/events/workspace_events.ts +86 -0
- package/core/extensions.d.ts +107 -0
- package/core/{extensions.js → extensions.ts} +153 -172
- package/core/field.d.ts +534 -0
- package/core/{field.js → field.ts} +413 -489
- package/core/field_angle.d.ts +176 -0
- package/core/field_angle.ts +563 -0
- package/core/field_checkbox.d.ts +124 -0
- package/core/field_checkbox.ts +243 -0
- package/core/field_colour.d.ts +200 -0
- package/core/field_colour.ts +632 -0
- package/core/field_dropdown.d.ts +222 -0
- package/core/{field_dropdown.js → field_dropdown.ts} +277 -299
- package/core/field_image.d.ts +134 -0
- package/core/field_image.ts +282 -0
- package/core/field_label.d.ts +71 -0
- package/core/field_label.ts +152 -0
- package/core/field_label_serializable.d.ts +42 -0
- package/core/field_label_serializable.ts +76 -0
- package/core/field_multilineinput.d.ts +146 -0
- package/core/{field_multilineinput.js → field_multilineinput.ts} +166 -163
- package/core/field_number.d.ts +156 -0
- package/core/{field_number.js → field_number.ts} +110 -123
- package/core/field_registry.d.ts +45 -0
- package/core/{field_registry.js → field_registry.ts} +37 -30
- package/core/field_textinput.d.ts +219 -0
- package/core/field_textinput.ts +591 -0
- package/core/field_variable.d.ts +217 -0
- package/core/{field_variable.js → field_variable.ts} +174 -187
- package/core/flyout_base.d.ts +459 -0
- package/core/{flyout_base.js → flyout_base.ts} +429 -518
- package/core/flyout_button.d.ts +81 -0
- package/core/flyout_button.ts +292 -0
- package/core/flyout_horizontal.d.ts +82 -0
- package/core/{flyout_horizontal.js → flyout_horizontal.ts} +97 -107
- package/core/flyout_metrics_manager.d.ts +40 -0
- package/core/{flyout_metrics_manager.js → flyout_metrics_manager.ts} +22 -34
- package/core/flyout_vertical.d.ts +83 -0
- package/core/{flyout_vertical.js → flyout_vertical.ts} +106 -117
- package/core/generator.d.ts +205 -0
- package/core/{generator.js → generator.ts} +168 -193
- package/core/gesture.d.ts +357 -0
- package/core/{gesture.js → gesture.ts} +289 -369
- package/core/grid.d.ts +83 -0
- package/core/grid.ts +192 -0
- package/core/icon.d.ts +78 -0
- package/core/icon.ts +189 -0
- package/core/inject.d.ts +15 -0
- package/core/{inject.js → inject.ts} +101 -100
- package/core/input.d.ts +128 -0
- package/core/input.ts +309 -0
- package/core/input_types.d.ts +14 -0
- package/core/{input_types.js → input_types.ts} +8 -12
- package/core/insertion_marker_manager.d.ts +212 -0
- package/core/{insertion_marker_manager.js → insertion_marker_manager.ts} +234 -236
- package/core/interfaces/i_ast_node_location.d.ts +11 -0
- package/core/interfaces/{i_ast_node_location.js → i_ast_node_location.ts} +4 -7
- package/core/interfaces/i_ast_node_location_svg.d.ts +22 -0
- package/core/interfaces/i_ast_node_location_svg.ts +37 -0
- package/core/interfaces/i_ast_node_location_with_block.d.ts +18 -0
- package/core/interfaces/i_ast_node_location_with_block.ts +38 -0
- package/core/interfaces/i_autohideable.d.ts +18 -0
- package/core/interfaces/i_autohideable.ts +34 -0
- package/core/interfaces/i_block_dragger.d.ts +43 -0
- package/core/interfaces/i_block_dragger.ts +67 -0
- package/core/interfaces/i_bounded_element.d.ts +24 -0
- package/core/interfaces/i_bounded_element.ts +42 -0
- package/core/interfaces/i_bubble.d.ts +59 -0
- package/core/interfaces/i_bubble.ts +88 -0
- package/core/interfaces/i_collapsible_toolbox_item.d.ts +26 -0
- package/core/interfaces/i_collapsible_toolbox_item.ts +47 -0
- package/core/interfaces/i_component.d.ts +17 -0
- package/core/interfaces/{i_component.js → i_component.ts} +9 -14
- package/core/interfaces/i_connection_checker.d.ts +69 -0
- package/core/interfaces/i_connection_checker.ts +102 -0
- package/core/interfaces/i_contextmenu.d.ts +13 -0
- package/core/interfaces/i_contextmenu.ts +26 -0
- package/core/interfaces/i_copyable.d.ts +24 -0
- package/core/interfaces/i_copyable.ts +40 -0
- package/core/interfaces/i_deletable.d.ts +16 -0
- package/core/interfaces/{i_deletable.js → i_deletable.ts} +9 -13
- package/core/interfaces/i_delete_area.d.ts +25 -0
- package/core/interfaces/i_delete_area.ts +46 -0
- package/core/interfaces/i_drag_target.d.ts +53 -0
- package/core/interfaces/i_drag_target.ts +84 -0
- package/core/interfaces/i_draggable.d.ts +12 -0
- package/core/interfaces/{i_draggable.js → i_draggable.ts} +4 -10
- package/core/interfaces/i_flyout.d.ts +134 -0
- package/core/interfaces/i_flyout.ts +186 -0
- package/core/interfaces/i_keyboard_accessible.d.ts +18 -0
- package/core/interfaces/i_keyboard_accessible.ts +35 -0
- package/core/interfaces/i_metrics_manager.d.ts +117 -0
- package/core/interfaces/i_metrics_manager.ts +151 -0
- package/core/interfaces/i_movable.d.ts +16 -0
- package/core/interfaces/{i_movable.js → i_movable.ts} +9 -13
- package/core/interfaces/i_positionable.d.ts +27 -0
- package/core/interfaces/i_positionable.ts +50 -0
- package/core/interfaces/i_registrable.d.ts +11 -0
- package/core/interfaces/{i_registrable.js → i_registrable.ts} +3 -7
- package/core/interfaces/i_registrable_field.d.ts +17 -0
- package/core/interfaces/{i_registrable_field.js → i_registrable_field.ts} +8 -16
- package/core/interfaces/i_selectable.d.ts +18 -0
- package/core/interfaces/i_selectable.ts +34 -0
- package/core/interfaces/i_selectable_toolbox_item.d.ts +42 -0
- package/core/interfaces/i_selectable_toolbox_item.ts +64 -0
- package/core/interfaces/i_serializer.d.ts +42 -0
- package/core/interfaces/i_serializer.ts +65 -0
- package/core/interfaces/i_styleable.d.ts +21 -0
- package/core/interfaces/i_styleable.ts +35 -0
- package/core/interfaces/i_toolbox.d.ts +85 -0
- package/core/interfaces/i_toolbox.ts +127 -0
- package/core/interfaces/i_toolbox_item.d.ts +62 -0
- package/core/interfaces/i_toolbox_item.ts +84 -0
- package/core/internal_constants.d.ts +40 -0
- package/core/{internal_constants.js → internal_constants.ts} +13 -18
- package/core/keyboard_nav/ast_node.d.ts +239 -0
- package/core/keyboard_nav/{ast_node.js → ast_node.ts} +207 -231
- package/core/keyboard_nav/basic_cursor.d.ts +88 -0
- package/core/keyboard_nav/{basic_cursor.js → basic_cursor.ts} +55 -66
- package/core/keyboard_nav/cursor.d.ts +41 -0
- package/core/keyboard_nav/{cursor.js → cursor.ts} +25 -35
- package/core/keyboard_nav/marker.d.ts +58 -0
- package/core/keyboard_nav/{marker.js → marker.ts} +36 -55
- package/core/keyboard_nav/tab_navigate_cursor.d.ts +19 -0
- package/core/keyboard_nav/{tab_navigate_cursor.js → tab_navigate_cursor.ts} +11 -15
- package/core/main.d.ts +11 -0
- package/core/main.js +303 -0
- package/core/marker_manager.d.ts +85 -0
- package/core/marker_manager.ts +181 -0
- package/core/menu.d.ts +149 -0
- package/core/{menu.js → menu.ts} +141 -174
- package/core/menuitem.d.ts +118 -0
- package/core/menuitem.ts +240 -0
- package/core/metrics_manager.d.ts +201 -0
- package/core/{metrics_manager.js → metrics_manager.ts} +117 -156
- package/core/msg.d.ts +9 -0
- package/core/{msg.js → msg.ts} +4 -8
- package/core/mutator.d.ts +128 -0
- package/core/{mutator.js → mutator.ts} +196 -211
- package/core/names.d.ts +124 -0
- package/core/names.ts +267 -0
- package/core/options.d.ts +137 -0
- package/core/{options.js → options.ts} +147 -173
- package/core/positionable_helpers.d.ts +88 -0
- package/core/{positionable_helpers.js → positionable_helpers.ts} +63 -70
- package/core/procedures.d.ts +108 -0
- package/core/{procedures.js → procedures.ts} +143 -152
- package/core/registry.d.ts +137 -0
- package/core/registry.ts +339 -0
- package/core/rendered_connection.d.ts +191 -0
- package/core/{rendered_connection.js → rendered_connection.ts} +164 -184
- package/core/renderers/common/block_rendering.d.ts +114 -0
- package/core/renderers/common/block_rendering.ts +164 -0
- package/core/renderers/common/constants.d.ts +458 -0
- package/core/renderers/common/constants.ts +1124 -0
- package/core/renderers/common/debug.d.ts +28 -0
- package/core/renderers/common/{debug.js → debug.ts} +14 -20
- package/core/renderers/common/debugger.d.ts +120 -0
- package/core/renderers/common/{debugger.js → debugger.ts} +100 -124
- package/core/renderers/common/drawer.d.ts +132 -0
- package/core/renderers/common/{drawer.js → drawer.ts} +112 -137
- package/core/renderers/common/i_path_object.d.ts +117 -0
- package/core/renderers/common/i_path_object.ts +161 -0
- package/core/renderers/common/info.d.ts +194 -0
- package/core/renderers/common/{info.js → info.ts} +165 -222
- package/core/renderers/common/marker_svg.d.ts +220 -0
- package/core/renderers/common/marker_svg.ts +680 -0
- package/core/renderers/common/path_object.d.ts +146 -0
- package/core/renderers/common/path_object.ts +272 -0
- package/core/renderers/common/renderer.d.ts +157 -0
- package/core/renderers/common/renderer.ts +271 -0
- package/core/renderers/geras/constants.d.ts +23 -0
- package/core/renderers/geras/constants.ts +61 -0
- package/core/renderers/geras/drawer.d.ts +43 -0
- package/core/renderers/geras/{drawer.js → drawer.ts} +40 -84
- package/core/renderers/geras/geras.d.ts +11 -0
- package/core/renderers/geras/geras.ts +37 -0
- package/core/renderers/geras/highlight_constants.d.ts +108 -0
- package/core/renderers/geras/{highlight_constants.js → highlight_constants.ts} +107 -69
- package/core/renderers/geras/highlighter.d.ts +98 -0
- package/core/renderers/geras/{highlighter.js → highlighter.ts} +81 -86
- package/core/renderers/geras/info.d.ts +45 -0
- package/core/renderers/geras/{info.js → info.ts} +61 -99
- package/core/renderers/geras/measurables/inline_input.d.ts +23 -0
- package/core/renderers/geras/measurables/inline_input.ts +51 -0
- package/core/renderers/geras/measurables/statement_input.d.ts +23 -0
- package/core/renderers/geras/measurables/statement_input.ts +50 -0
- package/core/renderers/geras/path_object.d.ts +47 -0
- package/core/renderers/geras/{path_object.js → path_object.ts} +46 -74
- package/core/renderers/geras/renderer.d.ts +69 -0
- package/core/renderers/geras/renderer.ts +126 -0
- package/core/renderers/measurables/base.d.ts +27 -0
- package/core/renderers/measurables/base.ts +53 -0
- package/core/renderers/measurables/bottom_row.d.ts +61 -0
- package/core/renderers/measurables/bottom_row.ts +120 -0
- package/core/renderers/measurables/connection.d.ts +25 -0
- package/core/renderers/measurables/connection.ts +52 -0
- package/core/renderers/measurables/external_value_input.d.ts +27 -0
- package/core/renderers/measurables/external_value_input.ts +65 -0
- package/core/renderers/measurables/field.d.ts +30 -0
- package/core/renderers/measurables/field.ts +63 -0
- package/core/renderers/measurables/hat.d.ts +21 -0
- package/core/renderers/measurables/{hat.js → hat.ts} +12 -14
- package/core/renderers/measurables/icon.d.ts +26 -0
- package/core/renderers/measurables/{icon.js → icon.ts} +14 -18
- package/core/renderers/measurables/in_row_spacer.d.ts +21 -0
- package/core/renderers/measurables/in_row_spacer.ts +44 -0
- package/core/renderers/measurables/inline_input.d.ts +24 -0
- package/core/renderers/measurables/{inline_input.js → inline_input.ts} +22 -26
- package/core/renderers/measurables/input_connection.d.ts +29 -0
- package/core/renderers/measurables/input_connection.ts +66 -0
- package/core/renderers/measurables/input_row.d.ts +30 -0
- package/core/renderers/measurables/{input_row.js → input_row.ts} +24 -31
- package/core/renderers/measurables/jagged_edge.d.ts +20 -0
- package/core/renderers/measurables/{jagged_edge.js → jagged_edge.ts} +10 -13
- package/core/renderers/measurables/next_connection.d.ts +23 -0
- package/core/renderers/measurables/next_connection.ts +47 -0
- package/core/renderers/measurables/output_connection.d.ts +26 -0
- package/core/renderers/measurables/output_connection.ts +56 -0
- package/core/renderers/measurables/previous_connection.d.ts +23 -0
- package/core/renderers/measurables/previous_connection.ts +47 -0
- package/core/renderers/measurables/round_corner.d.ts +21 -0
- package/core/renderers/measurables/round_corner.ts +49 -0
- package/core/renderers/measurables/row.d.ts +141 -0
- package/core/renderers/measurables/row.ts +225 -0
- package/core/renderers/measurables/spacer_row.d.ts +29 -0
- package/core/renderers/measurables/spacer_row.ts +55 -0
- package/core/renderers/measurables/square_corner.d.ts +21 -0
- package/core/renderers/measurables/square_corner.ts +47 -0
- package/core/renderers/measurables/statement_input.d.ts +22 -0
- package/core/renderers/measurables/{statement_input.js → statement_input.ts} +14 -18
- package/core/renderers/measurables/top_row.d.ts +56 -0
- package/core/renderers/measurables/top_row.ts +122 -0
- package/core/renderers/measurables/types.d.ts +235 -0
- package/core/renderers/measurables/types.ts +332 -0
- package/core/renderers/minimalist/constants.d.ts +14 -0
- package/core/renderers/minimalist/{constants.js → constants.ts} +5 -10
- package/core/renderers/minimalist/drawer.d.ts +21 -0
- package/core/renderers/minimalist/drawer.ts +38 -0
- package/core/renderers/minimalist/info.d.ts +30 -0
- package/core/renderers/minimalist/info.ts +52 -0
- package/core/renderers/minimalist/minimalist.d.ts +6 -0
- package/core/renderers/minimalist/minimalist.ts +22 -0
- package/core/renderers/minimalist/renderer.d.ts +41 -0
- package/core/renderers/minimalist/renderer.ts +71 -0
- package/core/renderers/thrasos/info.d.ts +40 -0
- package/core/renderers/thrasos/{info.js → info.ts} +66 -67
- package/core/renderers/thrasos/renderer.d.ts +25 -0
- package/core/renderers/thrasos/renderer.ts +48 -0
- package/core/renderers/thrasos/thrasos.d.ts +4 -0
- package/core/renderers/thrasos/thrasos.ts +20 -0
- package/core/renderers/zelos/constants.d.ts +186 -0
- package/core/renderers/zelos/{constants.js → constants.ts} +294 -441
- package/core/renderers/zelos/drawer.d.ts +47 -0
- package/core/renderers/zelos/{drawer.js → drawer.ts} +73 -95
- package/core/renderers/zelos/info.d.ts +88 -0
- package/core/renderers/zelos/{info.js → info.ts} +111 -142
- package/core/renderers/zelos/marker_svg.d.ts +46 -0
- package/core/renderers/zelos/marker_svg.ts +151 -0
- package/core/renderers/zelos/measurables/bottom_row.d.ts +27 -0
- package/core/renderers/zelos/measurables/bottom_row.ts +53 -0
- package/core/renderers/zelos/measurables/inputs.d.ts +23 -0
- package/core/renderers/zelos/measurables/{inputs.js → inputs.ts} +14 -15
- package/core/renderers/zelos/measurables/row_elements.d.ts +21 -0
- package/core/renderers/zelos/measurables/row_elements.ts +45 -0
- package/core/renderers/zelos/measurables/top_row.d.ts +29 -0
- package/core/renderers/zelos/measurables/{top_row.js → top_row.ts} +14 -27
- package/core/renderers/zelos/path_object.d.ts +77 -0
- package/core/renderers/zelos/path_object.ts +215 -0
- package/core/renderers/zelos/renderer.d.ts +74 -0
- package/core/renderers/zelos/renderer.ts +142 -0
- package/core/renderers/zelos/zelos.d.ts +12 -0
- package/core/renderers/zelos/zelos.ts +39 -0
- package/core/scrollbar.d.ts +277 -0
- package/core/{scrollbar.js → scrollbar.ts} +307 -328
- package/core/scrollbar_pair.d.ts +105 -0
- package/core/{scrollbar_pair.js → scrollbar_pair.ts} +71 -79
- package/core/serialization/blocks.d.ts +98 -0
- package/core/serialization/{blocks.js → blocks.ts} +229 -228
- package/core/serialization/exceptions.d.ts +73 -0
- package/core/serialization/exceptions.ts +98 -0
- package/core/serialization/priorities.d.ts +15 -0
- package/core/serialization/{priorities.js → priorities.ts} +4 -10
- package/core/serialization/registry.d.ts +20 -0
- package/core/serialization/{registry.js → registry.ts} +11 -13
- package/core/serialization/variables.d.ts +14 -0
- package/core/serialization/{variables.js → variables.ts} +30 -32
- package/core/serialization/workspaces.d.ts +28 -0
- package/core/serialization/{workspaces.js → workspaces.ts} +30 -27
- package/core/shortcut_items.d.ts +61 -0
- package/core/{shortcut_items.js → shortcut_items.ts} +121 -157
- package/core/shortcut_registry.d.ts +151 -0
- package/core/shortcut_registry.ts +355 -0
- package/core/sprites.d.ts +19 -0
- package/core/{sprites.js → sprites.ts} +4 -6
- package/core/theme/classic.d.ts +12 -0
- package/core/theme/{classic.js → classic.ts} +5 -7
- package/core/theme/themes.d.ts +8 -0
- package/core/theme/themes.ts +22 -0
- package/core/theme/zelos.d.ts +11 -0
- package/core/theme/{zelos.js → zelos.ts} +4 -7
- package/core/theme.d.ts +142 -0
- package/core/theme.ts +221 -0
- package/core/theme_manager.d.ts +81 -0
- package/core/theme_manager.ts +186 -0
- package/core/toolbox/category.d.ts +239 -0
- package/core/toolbox/category.ts +679 -0
- package/core/toolbox/collapsible_category.d.ts +91 -0
- package/core/toolbox/collapsible_category.ts +273 -0
- package/core/toolbox/separator.d.ts +39 -0
- package/core/toolbox/separator.ts +105 -0
- package/core/toolbox/toolbox.d.ts +352 -0
- package/core/toolbox/{toolbox.js → toolbox.ts} +316 -432
- package/core/toolbox/toolbox_item.d.ts +85 -0
- package/core/toolbox/toolbox_item.ts +147 -0
- package/core/tooltip.d.ts +126 -0
- package/core/{tooltip.js → tooltip.ts} +136 -214
- package/core/touch.d.ts +121 -0
- package/core/touch.ts +306 -0
- package/core/touch_gesture.d.ts +115 -0
- package/core/{touch_gesture.js → touch_gesture.ts} +87 -125
- package/core/trashcan.d.ts +195 -0
- package/core/{trashcan.js → trashcan.ts} +226 -312
- package/core/utils/aria.d.ts +67 -0
- package/core/utils/{aria.js → aria.ts} +47 -61
- package/core/utils/array.d.ts +14 -0
- package/core/utils/{array.js → array.ts} +10 -12
- package/core/utils/colour.d.ts +103 -0
- package/core/utils/{colour.js → colour.ts} +60 -72
- package/core/utils/coordinate.d.ts +72 -0
- package/core/utils/coordinate.ts +124 -0
- package/core/utils/deprecation.d.ts +17 -0
- package/core/utils/{deprecation.js → deprecation.ts} +11 -11
- package/core/utils/dom.d.ts +165 -0
- package/core/utils/{dom.js → dom.ts} +125 -147
- package/core/utils/idgenerator.d.ts +25 -0
- package/core/utils/{idgenerator.js → idgenerator.ts} +15 -18
- package/core/utils/keycodes.d.ts +137 -0
- package/core/utils/keycodes.ts +169 -0
- package/core/utils/math.d.ts +30 -0
- package/core/utils/{math.js → math.ts} +17 -19
- package/core/utils/metrics.d.ts +64 -0
- package/core/utils/metrics.ts +97 -0
- package/core/utils/object.d.ts +35 -0
- package/core/utils/{object.js → object.ts} +30 -26
- package/core/utils/parsing.d.ts +50 -0
- package/core/utils/{parsing.js → parsing.ts} +50 -50
- package/core/utils/rect.d.ts +38 -0
- package/core/utils/{rect.js → rect.ts} +18 -31
- package/core/utils/sentinel.d.ts +11 -0
- package/core/utils/{sentinel.js → sentinel.ts} +3 -5
- package/core/utils/size.d.ts +27 -0
- package/core/utils/{size.js → size.ts} +12 -26
- package/core/utils/string.d.ts +55 -0
- package/core/utils/{string.js → string.ts} +64 -61
- package/core/utils/style.d.ts +127 -0
- package/core/utils/{style.js → style.ts} +102 -92
- package/core/utils/svg.d.ts +68 -0
- package/core/utils/svg.ts +88 -0
- package/core/utils/svg_math.d.ts +70 -0
- package/core/utils/{svg_math.js → svg_math.ts} +72 -71
- package/core/utils/svg_paths.d.ts +101 -0
- package/core/utils/{svg_paths.js → svg_paths.ts} +56 -65
- package/core/utils/toolbox.d.ts +193 -0
- package/core/utils/toolbox.ts +433 -0
- package/core/utils/useragent.d.ts +33 -0
- package/core/utils/useragent.ts +135 -0
- package/core/utils/xml.d.ts +52 -0
- package/core/utils/{xml.js → xml.ts} +26 -36
- package/core/utils.d.ts +217 -0
- package/core/utils.ts +428 -0
- package/core/variable_map.d.ts +141 -0
- package/core/{variable_map.js → variable_map.ts} +131 -149
- package/core/variable_model.d.ts +40 -0
- package/core/variable_model.ts +82 -0
- package/core/variables.d.ts +181 -0
- package/core/{variables.js → variables.ts} +206 -188
- package/core/variables_dynamic.d.ts +38 -0
- package/core/{variables_dynamic.js → variables_dynamic.ts} +47 -43
- package/core/warning.d.ts +50 -0
- package/core/{warning.js → warning.ts} +52 -66
- package/core/widgetdiv.d.ts +69 -0
- package/core/widgetdiv.ts +257 -0
- package/core/workspace.d.ts +386 -0
- package/core/workspace.ts +801 -0
- package/core/workspace_audio.d.ts +47 -0
- package/core/{workspace_audio.js → workspace_audio.ts} +47 -60
- package/core/workspace_comment.d.ts +170 -0
- package/core/workspace_comment.ts +398 -0
- package/core/workspace_comment_svg.d.ts +329 -0
- package/core/{workspace_comment_svg.js → workspace_comment_svg.ts} +347 -444
- package/core/workspace_drag_surface_svg.d.ts +68 -0
- package/core/{workspace_drag_surface_svg.js → workspace_drag_surface_svg.ts} +75 -82
- package/core/workspace_dragger.d.ts +48 -0
- package/core/workspace_dragger.ts +104 -0
- package/core/workspace_svg.d.ts +920 -0
- package/core/{workspace_svg.js → workspace_svg.ts} +855 -935
- package/core/xml.d.ts +117 -0
- package/core/{xml.js → xml.ts} +306 -326
- package/core/zoom_controls.d.ts +130 -0
- package/core/{zoom_controls.js → zoom_controls.ts} +185 -251
- package/core.d.ts +1 -3
- package/core.js +1 -2
- package/dart.d.ts +0 -3
- package/dart_compressed.js +387 -99
- package/dart_compressed.js.map +1 -1
- package/generators/dart/all.js +2 -0
- package/generators/dart/colour.js +1 -1
- package/generators/dart/lists.js +1 -1
- package/generators/dart/logic.js +1 -1
- package/generators/dart/loops.js +1 -1
- package/generators/dart/math.js +1 -1
- package/generators/dart/procedures.js +1 -1
- package/generators/dart/text.js +1 -1
- package/generators/dart/variables.js +1 -1
- package/generators/dart/variables_dynamic.js +1 -1
- package/generators/dart.js +1 -2
- package/generators/javascript/all.js +2 -0
- package/generators/javascript/colour.js +1 -1
- package/generators/javascript/lists.js +1 -1
- package/generators/javascript/logic.js +1 -1
- package/generators/javascript/loops.js +1 -1
- package/generators/javascript/math.js +4 -4
- package/generators/javascript/procedures.js +1 -1
- package/generators/javascript/text.js +2 -2
- package/generators/javascript/variables.js +1 -1
- package/generators/javascript/variables_dynamic.js +1 -1
- package/generators/javascript.js +1 -3
- package/generators/lua/all.js +2 -0
- package/generators/lua/colour.js +1 -1
- package/generators/lua/lists.js +1 -1
- package/generators/lua/logic.js +1 -1
- package/generators/lua/loops.js +1 -1
- package/generators/lua/math.js +1 -1
- package/generators/lua/procedures.js +1 -1
- package/generators/lua/text.js +1 -1
- package/generators/lua/variables.js +1 -1
- package/generators/lua/variables_dynamic.js +1 -1
- package/generators/lua.js +1 -2
- package/generators/php/all.js +2 -0
- package/generators/php/colour.js +1 -1
- package/generators/php/lists.js +1 -2
- package/generators/php/logic.js +1 -1
- package/generators/php/loops.js +1 -1
- package/generators/php/math.js +1 -1
- package/generators/php/procedures.js +1 -1
- package/generators/php/text.js +1 -1
- package/generators/php/variables.js +1 -1
- package/generators/php/variables_dynamic.js +1 -1
- package/generators/php.js +1 -2
- package/generators/python/all.js +2 -0
- package/generators/python/colour.js +3 -3
- package/generators/python/lists.js +1 -1
- package/generators/python/logic.js +1 -1
- package/generators/python/loops.js +4 -7
- package/generators/python/math.js +1 -1
- package/generators/python/procedures.js +1 -1
- package/generators/python/text.js +1 -1
- package/generators/python/variables.js +1 -1
- package/generators/python/variables_dynamic.js +1 -1
- package/generators/python.js +1 -2
- package/index.d.ts +2 -8
- package/javascript.d.ts +0 -3
- package/javascript_compressed.js +314 -104
- package/javascript_compressed.js.map +1 -1
- package/lua.d.ts +0 -3
- package/lua_compressed.js +399 -81
- package/lua_compressed.js.map +1 -1
- package/msg/ab.js +421 -421
- package/msg/ace.js +421 -421
- package/msg/af.js +421 -421
- package/msg/am.js +421 -421
- package/msg/ar.js +421 -421
- package/msg/ast.js +421 -421
- package/msg/az.js +421 -421
- package/msg/ba.js +421 -421
- package/msg/bcc.js +421 -421
- package/msg/be-tarask.js +421 -421
- package/msg/be.js +421 -421
- package/msg/bg.js +421 -421
- package/msg/bn.js +421 -421
- package/msg/br.js +421 -421
- package/msg/bs.js +421 -421
- package/msg/ca.js +421 -421
- package/msg/cdo.js +421 -421
- package/msg/cs.js +421 -421
- package/msg/da.js +421 -421
- package/msg/de.js +421 -421
- package/msg/diq.js +421 -421
- package/msg/dty.js +421 -421
- package/msg/ee.js +421 -421
- package/msg/el.js +421 -421
- package/msg/en-gb.js +421 -421
- package/msg/en.js +421 -421
- package/msg/eo.js +421 -421
- package/msg/es.js +421 -421
- package/msg/et.js +421 -421
- package/msg/eu.js +421 -421
- package/msg/fa.js +421 -421
- package/msg/fi.js +421 -421
- package/msg/fo.js +421 -421
- package/msg/fr.js +421 -421
- package/msg/frr.js +421 -421
- package/msg/gl.js +421 -421
- package/msg/gn.js +421 -421
- package/msg/gor.js +421 -421
- package/msg/ha.js +421 -421
- package/msg/hak.js +421 -421
- package/msg/he.js +421 -421
- package/msg/hi.js +421 -421
- package/msg/hr.js +421 -421
- package/msg/hrx.js +421 -421
- package/msg/hu.js +421 -421
- package/msg/hy.js +421 -421
- package/msg/ia.js +421 -421
- package/msg/id.js +421 -421
- package/msg/ig.js +421 -421
- package/msg/inh.js +421 -421
- package/msg/is.js +421 -421
- package/msg/it.js +421 -421
- package/msg/ja.js +421 -421
- package/msg/ka.js +421 -421
- package/msg/kab.js +421 -421
- package/msg/kbd-cyrl.js +421 -421
- package/msg/km.js +421 -421
- package/msg/kn.js +421 -421
- package/msg/ko.js +421 -421
- package/msg/ksh.js +421 -421
- package/msg/ku-latn.js +421 -421
- package/msg/ky.js +421 -421
- package/msg/la.js +421 -421
- package/msg/lb.js +421 -421
- package/msg/lki.js +421 -421
- package/msg/lo.js +421 -421
- package/msg/lrc.js +421 -421
- package/msg/lt.js +421 -421
- package/msg/lv.js +421 -421
- package/msg/mg.js +421 -421
- package/msg/mk.js +421 -421
- package/msg/ml.js +421 -421
- package/msg/mnw.js +421 -421
- package/msg/ms.js +421 -421
- package/msg/my.js +421 -421
- package/msg/mzn.js +421 -421
- package/msg/nb.js +421 -421
- package/msg/ne.js +421 -421
- package/msg/nl.js +421 -421
- package/msg/oc.js +421 -421
- package/msg/olo.js +421 -421
- package/msg/pa.js +421 -421
- package/msg/pl.js +421 -421
- package/msg/pms.js +421 -421
- package/msg/ps.js +421 -421
- package/msg/pt-br.js +421 -421
- package/msg/pt.js +421 -421
- package/msg/ro.js +421 -421
- package/msg/ru.js +421 -421
- package/msg/sc.js +421 -421
- package/msg/sco.js +421 -421
- package/msg/sd.js +421 -421
- package/msg/shn.js +421 -421
- package/msg/si.js +421 -421
- package/msg/sk.js +421 -421
- package/msg/skr-arab.js +421 -421
- package/msg/sl.js +421 -421
- package/msg/smn.js +421 -421
- package/msg/sq.js +421 -421
- package/msg/sr-latn.js +421 -421
- package/msg/sr.js +421 -421
- package/msg/sv.js +421 -421
- package/msg/sw.js +421 -421
- package/msg/ta.js +421 -421
- package/msg/tcy.js +421 -421
- package/msg/te.js +421 -421
- package/msg/th.js +421 -421
- package/msg/ti.js +421 -421
- package/msg/tl.js +421 -421
- package/msg/tlh.js +421 -421
- package/msg/tr.js +421 -421
- package/msg/ug-arab.js +421 -421
- package/msg/uk.js +421 -421
- package/msg/ur.js +421 -421
- package/msg/uz.js +421 -421
- package/msg/vi.js +421 -421
- package/msg/xmf.js +421 -421
- package/msg/yo.js +421 -421
- package/msg/yue.js +421 -421
- package/msg/zgh.js +421 -421
- package/msg/zh-hans.js +421 -421
- package/msg/zh-hant.js +421 -421
- package/package.json +5 -5
- package/php.d.ts +0 -3
- package/php_compressed.js +322 -93
- package/php_compressed.js.map +1 -1
- package/python.d.ts +0 -3
- package/python_compressed.js +237 -90
- package/python_compressed.js.map +1 -1
- package/blockly.d.ts +0 -26127
- package/core/blockly_options.js +0 -28
- package/core/bubble_dragger.js +0 -298
- package/core/clipboard.js +0 -80
- package/core/component_manager.js +0 -263
- package/core/contextmenu_items.js +0 -651
- package/core/contextmenu_registry.js +0 -178
- package/core/delete_area.js +0 -87
- package/core/dialog.js +0 -107
- package/core/drag_target.js +0 -98
- package/core/events/events.js +0 -147
- package/core/events/events_abstract.js +0 -133
- package/core/events/events_block_base.js +0 -70
- package/core/events/events_block_drag.js +0 -89
- package/core/events/events_bubble_open.js +0 -90
- package/core/events/events_comment_base.js +0 -121
- package/core/events/events_marker_move.js +0 -110
- package/core/events/events_selected.js +0 -83
- package/core/events/events_toolbox_item_select.js +0 -84
- package/core/events/events_trashcan_open.js +0 -73
- package/core/events/events_var_base.js +0 -70
- package/core/events/events_viewport.js +0 -107
- package/core/events/workspace_events.js +0 -93
- package/core/field_angle.js +0 -591
- package/core/field_checkbox.js +0 -255
- package/core/field_colour.js +0 -717
- package/core/field_image.js +0 -304
- package/core/field_label.js +0 -149
- package/core/field_label_serializable.js +0 -80
- package/core/field_textinput.js +0 -619
- package/core/flyout_button.js +0 -356
- package/core/grid.js +0 -226
- package/core/icon.js +0 -225
- package/core/input.js +0 -335
- package/core/interfaces/i_ast_node_location_svg.js +0 -45
- package/core/interfaces/i_ast_node_location_with_block.js +0 -41
- package/core/interfaces/i_autohideable.js +0 -40
- package/core/interfaces/i_block_dragger.js +0 -66
- package/core/interfaces/i_bounded_element.js +0 -45
- package/core/interfaces/i_bubble.js +0 -95
- package/core/interfaces/i_collapsible_toolbox_item.js +0 -53
- package/core/interfaces/i_connection_checker.js +0 -104
- package/core/interfaces/i_contextmenu.js +0 -32
- package/core/interfaces/i_copyable.js +0 -49
- package/core/interfaces/i_delete_area.js +0 -50
- package/core/interfaces/i_drag_target.js +0 -88
- package/core/interfaces/i_flyout.js +0 -201
- package/core/interfaces/i_keyboard_accessible.js +0 -38
- package/core/interfaces/i_metrics_manager.js +0 -154
- package/core/interfaces/i_positionable.js +0 -51
- package/core/interfaces/i_selectable.js +0 -51
- package/core/interfaces/i_selectable_toolbox_item.js +0 -73
- package/core/interfaces/i_serializer.js +0 -77
- package/core/interfaces/i_styleable.js +0 -39
- package/core/interfaces/i_toolbox.js +0 -142
- package/core/interfaces/i_toolbox_item.js +0 -85
- package/core/marker_manager.js +0 -213
- package/core/menuitem.js +0 -292
- package/core/names.js +0 -293
- package/core/registry.js +0 -384
- package/core/renderers/common/block_rendering.js +0 -170
- package/core/renderers/common/constants.js +0 -1250
- package/core/renderers/common/i_path_object.js +0 -162
- package/core/renderers/common/marker_svg.js +0 -721
- package/core/renderers/common/path_object.js +0 -283
- package/core/renderers/common/renderer.js +0 -305
- package/core/renderers/geras/constants.js +0 -73
- package/core/renderers/geras/geras.js +0 -36
- package/core/renderers/geras/measurables/inline_input.js +0 -58
- package/core/renderers/geras/measurables/statement_input.js +0 -57
- package/core/renderers/geras/renderer.js +0 -149
- package/core/renderers/measurables/base.js +0 -64
- package/core/renderers/measurables/bottom_row.js +0 -138
- package/core/renderers/measurables/connection.js +0 -56
- package/core/renderers/measurables/external_value_input.js +0 -70
- package/core/renderers/measurables/field.js +0 -71
- package/core/renderers/measurables/in_row_spacer.js +0 -47
- package/core/renderers/measurables/input_connection.js +0 -75
- package/core/renderers/measurables/next_connection.js +0 -50
- package/core/renderers/measurables/output_connection.js +0 -61
- package/core/renderers/measurables/previous_connection.js +0 -50
- package/core/renderers/measurables/round_corner.js +0 -52
- package/core/renderers/measurables/row.js +0 -247
- package/core/renderers/measurables/spacer_row.js +0 -69
- package/core/renderers/measurables/square_corner.js +0 -50
- package/core/renderers/measurables/top_row.js +0 -143
- package/core/renderers/measurables/types.js +0 -353
- package/core/renderers/minimalist/drawer.js +0 -42
- package/core/renderers/minimalist/info.js +0 -54
- package/core/renderers/minimalist/minimalist.js +0 -26
- package/core/renderers/minimalist/renderer.js +0 -80
- package/core/renderers/thrasos/renderer.js +0 -53
- package/core/renderers/thrasos/thrasos.js +0 -22
- package/core/renderers/zelos/marker_svg.js +0 -179
- package/core/renderers/zelos/measurables/bottom_row.js +0 -66
- package/core/renderers/zelos/measurables/row_elements.js +0 -46
- package/core/renderers/zelos/path_object.js +0 -247
- package/core/renderers/zelos/renderer.js +0 -147
- package/core/renderers/zelos/zelos.js +0 -38
- package/core/serialization/exceptions.js +0 -144
- package/core/shortcut_registry.js +0 -366
- package/core/theme/themes.js +0 -23
- package/core/theme.js +0 -228
- package/core/theme_manager.js +0 -211
- package/core/toolbox/category.js +0 -751
- package/core/toolbox/collapsible_category.js +0 -311
- package/core/toolbox/separator.js +0 -133
- package/core/toolbox/toolbox_item.js +0 -173
- package/core/touch.js +0 -285
- package/core/utils/coordinate.js +0 -138
- package/core/utils/global.js +0 -41
- package/core/utils/keycodes.js +0 -172
- package/core/utils/metrics.js +0 -154
- package/core/utils/svg.js +0 -186
- package/core/utils/toolbox.js +0 -459
- package/core/utils/useragent.js +0 -197
- package/core/utils.js +0 -383
- package/core/variable_model.js +0 -96
- package/core/widgetdiv.js +0 -290
- package/core/workspace.js +0 -836
- package/core/workspace_comment.js +0 -400
- package/core/workspace_dragger.js +0 -115
|
@@ -7,422 +7,393 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* @fileoverview Object representing a workspace rendered as SVG.
|
|
9
9
|
*/
|
|
10
|
-
'use strict';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Object representing a workspace rendered as SVG.
|
|
14
13
|
* @class
|
|
15
14
|
*/
|
|
16
|
-
goog
|
|
15
|
+
import * as goog from '../closure/goog/goog.js';
|
|
16
|
+
goog.declareModuleId('Blockly.WorkspaceSvg');
|
|
17
17
|
|
|
18
|
-
const ContextMenu = goog.require('Blockly.ContextMenu');
|
|
19
18
|
/* eslint-disable-next-line no-unused-vars */
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
20
|
+
// import './procedures.js';
|
|
22
21
|
/* eslint-disable-next-line no-unused-vars */
|
|
23
|
-
|
|
22
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
23
|
+
// import './variables.js';
|
|
24
24
|
/* eslint-disable-next-line no-unused-vars */
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const Xml = goog.require('Blockly.Xml');
|
|
28
|
-
const arrayUtils = goog.require('Blockly.utils.array');
|
|
29
|
-
const blockRendering = goog.require('Blockly.blockRendering');
|
|
30
|
-
const blocks = goog.require('Blockly.serialization.blocks');
|
|
31
|
-
const browserEvents = goog.require('Blockly.browserEvents');
|
|
32
|
-
const common = goog.require('Blockly.common');
|
|
33
|
-
const dom = goog.require('Blockly.utils.dom');
|
|
34
|
-
const dropDownDiv = goog.require('Blockly.dropDownDiv');
|
|
35
|
-
const eventUtils = goog.require('Blockly.Events.utils');
|
|
36
|
-
const registry = goog.require('Blockly.registry');
|
|
37
|
-
const svgMath = goog.require('Blockly.utils.svgMath');
|
|
38
|
-
const toolbox = goog.require('Blockly.utils.toolbox');
|
|
39
|
-
const userAgent = goog.require('Blockly.utils.userAgent');
|
|
40
|
-
const utils = goog.require('Blockly.utils');
|
|
25
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
26
|
+
// import './variables_dynamic.js';
|
|
41
27
|
/* eslint-disable-next-line no-unused-vars */
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
29
|
+
// import './rendered_connection.js';
|
|
44
30
|
/* eslint-disable-next-line no-unused-vars */
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
31
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
32
|
+
// import './zoom_controls.js';
|
|
33
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
34
|
+
import './events/events_block_create.js';
|
|
35
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
36
|
+
import './events/events_theme_change.js';
|
|
37
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
38
|
+
import './events/events_viewport.js';
|
|
39
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
40
|
+
// import './metrics_manager.js';
|
|
41
|
+
// Unused import preserved for side-effects. Remove if unneeded.
|
|
42
|
+
// import './msg.js';
|
|
43
|
+
|
|
44
|
+
import type {Block} from './block.js';
|
|
45
|
+
import type {BlockDragSurfaceSvg} from './block_drag_surface.js';
|
|
46
|
+
import type {BlockSvg} from './block_svg.js';
|
|
47
|
+
import type {BlocklyOptions} from './blockly_options.js';
|
|
48
|
+
import * as browserEvents from './browser_events.js';
|
|
49
|
+
import * as common from './common.js';
|
|
50
|
+
import {ComponentManager} from './component_manager.js';
|
|
51
|
+
import {config} from './config.js';
|
|
52
|
+
import {ConnectionDB} from './connection_db.js';
|
|
53
|
+
import * as ContextMenu from './contextmenu.js';
|
|
54
|
+
import {ContextMenuRegistry} from './contextmenu_registry.js';
|
|
55
|
+
import * as dropDownDiv from './dropdowndiv.js';
|
|
56
|
+
import * as eventUtils from './events/utils.js';
|
|
57
|
+
import type {FlyoutButton} from './flyout_button.js';
|
|
58
|
+
import {Gesture} from './gesture.js';
|
|
59
|
+
import {Grid} from './grid.js';
|
|
60
|
+
import type {IASTNodeLocationSvg} from './interfaces/i_ast_node_location_svg.js';
|
|
61
|
+
import type {IBoundedElement} from './interfaces/i_bounded_element.js';
|
|
62
|
+
import type {ICopyable} from './interfaces/i_copyable.js';
|
|
63
|
+
import type {IDragTarget} from './interfaces/i_drag_target.js';
|
|
64
|
+
import type {IFlyout} from './interfaces/i_flyout.js';
|
|
65
|
+
import type {IMetricsManager} from './interfaces/i_metrics_manager.js';
|
|
66
|
+
import type {IToolbox} from './interfaces/i_toolbox.js';
|
|
67
|
+
import type {Cursor} from './keyboard_nav/cursor.js';
|
|
68
|
+
import type {Marker} from './keyboard_nav/marker.js';
|
|
69
|
+
import {MarkerManager} from './marker_manager.js';
|
|
70
|
+
import {Options} from './options.js';
|
|
71
|
+
import * as Procedures from './procedures.js';
|
|
72
|
+
import * as registry from './registry.js';
|
|
73
|
+
import * as blockRendering from './renderers/common/block_rendering.js';
|
|
74
|
+
import type {Renderer} from './renderers/common/renderer.js';
|
|
75
|
+
import type {ScrollbarPair} from './scrollbar_pair.js';
|
|
76
|
+
import * as blocks from './serialization/blocks.js';
|
|
77
|
+
import type {Theme} from './theme.js';
|
|
78
|
+
import {Classic} from './theme/classic.js';
|
|
79
|
+
import {ThemeManager} from './theme_manager.js';
|
|
80
|
+
import * as Tooltip from './tooltip.js';
|
|
81
|
+
import {TouchGesture} from './touch_gesture.js';
|
|
82
|
+
import type {Trashcan} from './trashcan.js';
|
|
83
|
+
import * as utils from './utils.js';
|
|
84
|
+
import * as arrayUtils from './utils/array.js';
|
|
85
|
+
import {Coordinate} from './utils/coordinate.js';
|
|
86
|
+
import * as dom from './utils/dom.js';
|
|
87
|
+
import type {Metrics} from './utils/metrics.js';
|
|
88
|
+
import {Rect} from './utils/rect.js';
|
|
89
|
+
import {Size} from './utils/size.js';
|
|
90
|
+
import {Svg} from './utils/svg.js';
|
|
91
|
+
import * as svgMath from './utils/svg_math.js';
|
|
92
|
+
import * as toolbox from './utils/toolbox.js';
|
|
93
|
+
import * as userAgent from './utils/useragent.js';
|
|
94
|
+
import type {VariableModel} from './variable_model.js';
|
|
95
|
+
import * as Variables from './variables.js';
|
|
96
|
+
import * as VariablesDynamic from './variables_dynamic.js';
|
|
97
|
+
import * as WidgetDiv from './widgetdiv.js';
|
|
98
|
+
import {Workspace} from './workspace.js';
|
|
99
|
+
import {WorkspaceAudio} from './workspace_audio.js';
|
|
100
|
+
import {WorkspaceComment} from './workspace_comment.js';
|
|
101
|
+
import {WorkspaceCommentSvg} from './workspace_comment_svg.js';
|
|
102
|
+
import type {WorkspaceDragSurfaceSvg} from './workspace_drag_surface_svg.js';
|
|
103
|
+
import * as Xml from './xml.js';
|
|
104
|
+
import {ZoomControls} from './zoom_controls.js';
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
/** Margin around the top/bottom/left/right after a zoomToFit call. */
|
|
108
|
+
const ZOOM_TO_FIT_MARGIN = 20;
|
|
118
109
|
|
|
119
110
|
/**
|
|
120
111
|
* Class for a workspace. This is an onscreen area with optional trashcan,
|
|
121
112
|
* scrollbars, bubbles, and dragging.
|
|
122
|
-
* @extends {Workspace}
|
|
123
|
-
* @implements {IASTNodeLocationSvg}
|
|
124
113
|
* @alias Blockly.WorkspaceSvg
|
|
125
114
|
*/
|
|
126
|
-
class WorkspaceSvg extends Workspace {
|
|
115
|
+
export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
|
|
127
116
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* blocks.
|
|
131
|
-
* @param {WorkspaceDragSurfaceSvg=} opt_wsDragSurface Drag surface for
|
|
132
|
-
* the workspace.
|
|
117
|
+
* A wrapper function called when a resize event occurs.
|
|
118
|
+
* You can pass the result to `eventHandling.unbind`.
|
|
133
119
|
*/
|
|
134
|
-
|
|
135
|
-
super(options);
|
|
120
|
+
private resizeHandlerWrapper_: browserEvents.Data|null = null;
|
|
136
121
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.resizeHandlerWrapper_ = null;
|
|
122
|
+
/**
|
|
123
|
+
* The render status of an SVG workspace.
|
|
124
|
+
* Returns `false` for headless workspaces and true for instances of
|
|
125
|
+
* `WorkspaceSvg`.
|
|
126
|
+
*/
|
|
127
|
+
override rendered = true;
|
|
144
128
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
*/
|
|
151
|
-
this.rendered = true;
|
|
129
|
+
/**
|
|
130
|
+
* Whether the workspace is visible. False if the workspace has been hidden
|
|
131
|
+
* by calling `setVisible(false)`.
|
|
132
|
+
*/
|
|
133
|
+
private isVisible_ = true;
|
|
152
134
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*/
|
|
159
|
-
this.isVisible_ = true;
|
|
135
|
+
/**
|
|
136
|
+
* Whether this workspace has resizes enabled.
|
|
137
|
+
* Disable during batch operations for a performance improvement.
|
|
138
|
+
*/
|
|
139
|
+
private resizesEnabled_ = true;
|
|
160
140
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Current horizontal scrolling offset in pixel units, relative to the
|
|
143
|
+
* workspace origin.
|
|
144
|
+
*
|
|
145
|
+
* It is useful to think about a view, and a canvas moving beneath that
|
|
146
|
+
* view. As the canvas moves right, this value becomes more positive, and
|
|
147
|
+
* the view is now "seeing" the left side of the canvas. As the canvas moves
|
|
148
|
+
* left, this value becomes more negative, and the view is now "seeing" the
|
|
149
|
+
* right side of the canvas.
|
|
150
|
+
*
|
|
151
|
+
* The confusing thing about this value is that it does not, and must not
|
|
152
|
+
* include the absoluteLeft offset. This is because it is used to calculate
|
|
153
|
+
* the viewLeft value.
|
|
154
|
+
*
|
|
155
|
+
* The viewLeft is relative to the workspace origin (although in pixel
|
|
156
|
+
* units). The workspace origin is the top-left corner of the workspace (at
|
|
157
|
+
* least when it is enabled). It is shifted from the top-left of the
|
|
158
|
+
* blocklyDiv so as not to be beneath the toolbox.
|
|
159
|
+
*
|
|
160
|
+
* When the workspace is enabled the viewLeft and workspace origin are at
|
|
161
|
+
* the same X location. As the canvas slides towards the right beneath the
|
|
162
|
+
* view this value (scrollX) becomes more positive, and the viewLeft becomes
|
|
163
|
+
* more negative relative to the workspace origin (imagine the workspace
|
|
164
|
+
* origin as a dot on the canvas sliding to the right as the canvas moves).
|
|
165
|
+
*
|
|
166
|
+
* So if the scrollX were to include the absoluteLeft this would in a way
|
|
167
|
+
* "unshift" the workspace origin. This means that the viewLeft would be
|
|
168
|
+
* representing the left edge of the blocklyDiv, rather than the left edge
|
|
169
|
+
* of the workspace.
|
|
170
|
+
*/
|
|
171
|
+
scrollX = 0;
|
|
168
172
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
*/
|
|
201
|
-
this.scrollX = 0;
|
|
173
|
+
/**
|
|
174
|
+
* Current vertical scrolling offset in pixel units, relative to the
|
|
175
|
+
* workspace origin.
|
|
176
|
+
*
|
|
177
|
+
* It is useful to think about a view, and a canvas moving beneath that
|
|
178
|
+
* view. As the canvas moves down, this value becomes more positive, and the
|
|
179
|
+
* view is now "seeing" the upper part of the canvas. As the canvas moves
|
|
180
|
+
* up, this value becomes more negative, and the view is "seeing" the lower
|
|
181
|
+
* part of the canvas.
|
|
182
|
+
*
|
|
183
|
+
* This confusing thing about this value is that it does not, and must not
|
|
184
|
+
* include the absoluteTop offset. This is because it is used to calculate
|
|
185
|
+
* the viewTop value.
|
|
186
|
+
*
|
|
187
|
+
* The viewTop is relative to the workspace origin (although in pixel
|
|
188
|
+
* units). The workspace origin is the top-left corner of the workspace (at
|
|
189
|
+
* least when it is enabled). It is shifted from the top-left of the
|
|
190
|
+
* blocklyDiv so as not to be beneath the toolbox.
|
|
191
|
+
*
|
|
192
|
+
* When the workspace is enabled the viewTop and workspace origin are at the
|
|
193
|
+
* same Y location. As the canvas slides towards the bottom this value
|
|
194
|
+
* (scrollY) becomes more positive, and the viewTop becomes more negative
|
|
195
|
+
* relative to the workspace origin (image in the workspace origin as a dot
|
|
196
|
+
* on the canvas sliding downwards as the canvas moves).
|
|
197
|
+
*
|
|
198
|
+
* So if the scrollY were to include the absoluteTop this would in a way
|
|
199
|
+
* "unshift" the workspace origin. This means that the viewTop would be
|
|
200
|
+
* representing the top edge of the blocklyDiv, rather than the top edge of
|
|
201
|
+
* the workspace.
|
|
202
|
+
*/
|
|
203
|
+
scrollY = 0;
|
|
202
204
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
* workspace origin.
|
|
206
|
-
*
|
|
207
|
-
* It is useful to think about a view, and a canvas moving beneath that
|
|
208
|
-
* view. As the canvas moves down, this value becomes more positive, and the
|
|
209
|
-
* view is now "seeing" the upper part of the canvas. As the canvas moves
|
|
210
|
-
* up, this value becomes more negative, and the view is "seeing" the lower
|
|
211
|
-
* part of the canvas.
|
|
212
|
-
*
|
|
213
|
-
* This confusing thing about this value is that it does not, and must not
|
|
214
|
-
* include the absoluteTop offset. This is because it is used to calculate
|
|
215
|
-
* the viewTop value.
|
|
216
|
-
*
|
|
217
|
-
* The viewTop is relative to the workspace origin (although in pixel
|
|
218
|
-
* units). The workspace origin is the top-left corner of the workspace (at
|
|
219
|
-
* least when it is enabled). It is shifted from the top-left of the
|
|
220
|
-
* blocklyDiv so as not to be beneath the toolbox.
|
|
221
|
-
*
|
|
222
|
-
* When the workspace is enabled the viewTop and workspace origin are at the
|
|
223
|
-
* same Y location. As the canvas slides towards the bottom this value
|
|
224
|
-
* (scrollY) becomes more positive, and the viewTop becomes more negative
|
|
225
|
-
* relative to the workspace origin (image in the workspace origin as a dot
|
|
226
|
-
* on the canvas sliding downwards as the canvas moves).
|
|
227
|
-
*
|
|
228
|
-
* So if the scrollY were to include the absoluteTop this would in a way
|
|
229
|
-
* "unshift" the workspace origin. This means that the viewTop would be
|
|
230
|
-
* representing the top edge of the blocklyDiv, rather than the top edge of
|
|
231
|
-
* the workspace.
|
|
232
|
-
*
|
|
233
|
-
* @type {number}
|
|
234
|
-
*/
|
|
235
|
-
this.scrollY = 0;
|
|
205
|
+
/** Horizontal scroll value when scrolling started in pixel units. */
|
|
206
|
+
startScrollX = 0;
|
|
236
207
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
* @type {number}
|
|
240
|
-
*/
|
|
241
|
-
this.startScrollX = 0;
|
|
208
|
+
/** Vertical scroll value when scrolling started in pixel units. */
|
|
209
|
+
startScrollY = 0;
|
|
242
210
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.startScrollY = 0;
|
|
211
|
+
/** Distance from mouse to object being dragged. */
|
|
212
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
213
|
+
// 'Coordinate'.
|
|
214
|
+
private dragDeltaXY_: Coordinate = null as AnyDuringMigration;
|
|
248
215
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
* @type {Coordinate}
|
|
252
|
-
* @private
|
|
253
|
-
*/
|
|
254
|
-
this.dragDeltaXY_ = null;
|
|
216
|
+
/** Current scale. */
|
|
217
|
+
scale = 1;
|
|
255
218
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
* @type {number}
|
|
259
|
-
*/
|
|
260
|
-
this.scale = 1;
|
|
219
|
+
/** Cached scale value. Used to detect changes in viewport. */
|
|
220
|
+
private oldScale_ = 1;
|
|
261
221
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
* @type {number}
|
|
265
|
-
* @private
|
|
266
|
-
*/
|
|
267
|
-
this.oldScale_ = 1;
|
|
222
|
+
/** Cached viewport top value. Used to detect changes in viewport. */
|
|
223
|
+
private oldTop_ = 0;
|
|
268
224
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
* @type {number}
|
|
272
|
-
* @private
|
|
273
|
-
*/
|
|
274
|
-
this.oldTop_ = 0;
|
|
225
|
+
/** Cached viewport left value. Used to detect changes in viewport. */
|
|
226
|
+
private oldLeft_ = 0;
|
|
275
227
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
*/
|
|
281
|
-
this.oldLeft_ = 0;
|
|
228
|
+
/** The workspace's trashcan (if any). */
|
|
229
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
230
|
+
// 'Trashcan'.
|
|
231
|
+
trashcan: Trashcan = null as AnyDuringMigration;
|
|
282
232
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
this.trashcan = null;
|
|
233
|
+
/** This workspace's scrollbars, if they exist. */
|
|
234
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
235
|
+
// 'ScrollbarPair'.
|
|
236
|
+
scrollbar: ScrollbarPair = null as AnyDuringMigration;
|
|
288
237
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
238
|
+
/**
|
|
239
|
+
* Fixed flyout providing blocks which may be dragged into this workspace.
|
|
240
|
+
*/
|
|
241
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
242
|
+
// 'IFlyout'.
|
|
243
|
+
private flyout_: IFlyout = null as AnyDuringMigration;
|
|
294
244
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
245
|
+
/**
|
|
246
|
+
* Category-based toolbox providing blocks which may be dragged into this
|
|
247
|
+
* workspace.
|
|
248
|
+
*/
|
|
249
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
250
|
+
// 'IToolbox'.
|
|
251
|
+
private toolbox_: IToolbox = null as AnyDuringMigration;
|
|
301
252
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
253
|
+
/**
|
|
254
|
+
* The current gesture in progress on this workspace, if any.
|
|
255
|
+
* @internal
|
|
256
|
+
*/
|
|
257
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
258
|
+
// 'TouchGesture'.
|
|
259
|
+
currentGesture_: TouchGesture = null as AnyDuringMigration;
|
|
309
260
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
this.currentGesture_ = null;
|
|
261
|
+
/** This workspace's surface for dragging blocks, if it exists. */
|
|
262
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
263
|
+
// 'BlockDragSurfaceSvg'.
|
|
264
|
+
private readonly blockDragSurface_: BlockDragSurfaceSvg =
|
|
265
|
+
null as AnyDuringMigration;
|
|
316
266
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
this.blockDragSurface_ = null;
|
|
267
|
+
/** This workspace's drag surface, if it exists. */
|
|
268
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
269
|
+
// 'WorkspaceDragSurfaceSvg'.
|
|
270
|
+
private readonly workspaceDragSurface_: WorkspaceDragSurfaceSvg =
|
|
271
|
+
null as AnyDuringMigration;
|
|
323
272
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
this.workspaceDragSurface_ = null;
|
|
273
|
+
/**
|
|
274
|
+
* Whether to move workspace to the drag surface when it is dragged.
|
|
275
|
+
* True if it should move, false if it should be translated directly.
|
|
276
|
+
*/
|
|
277
|
+
private readonly useWorkspaceDragSurface_;
|
|
330
278
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Whether the drag surface is actively in use. When true, calls to
|
|
281
|
+
* translate will translate the drag surface instead of the translating the
|
|
282
|
+
* workspace directly.
|
|
283
|
+
* This is set to true in setupDragSurface and to false in resetDragSurface.
|
|
284
|
+
*/
|
|
285
|
+
private isDragSurfaceActive_ = false;
|
|
338
286
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
*/
|
|
347
|
-
this.isDragSurfaceActive_ = false;
|
|
287
|
+
/**
|
|
288
|
+
* The first parent div with 'injectionDiv' in the name, or null if not set.
|
|
289
|
+
* Access this with getInjectionDiv.
|
|
290
|
+
*/
|
|
291
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
292
|
+
// 'Element'.
|
|
293
|
+
private injectionDiv_: Element = null as AnyDuringMigration;
|
|
348
294
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Last known position of the page scroll.
|
|
297
|
+
* This is used to determine whether we have recalculated screen coordinate
|
|
298
|
+
* stuff since the page scrolled.
|
|
299
|
+
*/
|
|
300
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
301
|
+
// 'Coordinate'.
|
|
302
|
+
private lastRecordedPageScroll_: Coordinate = null as AnyDuringMigration;
|
|
356
303
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Developers may define this function to add custom menu options to the
|
|
306
|
+
* workspace's context menu or edit the workspace-created set of menu
|
|
307
|
+
* options.
|
|
308
|
+
* @param options List of menu options to add to.
|
|
309
|
+
* @param e The right-click event that triggered the context menu.
|
|
310
|
+
*/
|
|
311
|
+
configureContextMenu: AnyDuringMigration;
|
|
365
312
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
313
|
+
/**
|
|
314
|
+
* In a flyout, the target workspace where blocks should be placed after a
|
|
315
|
+
* drag. Otherwise null.
|
|
316
|
+
* @internal
|
|
317
|
+
*/
|
|
318
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
319
|
+
// 'WorkspaceSvg'.
|
|
320
|
+
targetWorkspace: WorkspaceSvg = null as AnyDuringMigration;
|
|
374
321
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
* drag. Otherwise null.
|
|
378
|
-
* @type {WorkspaceSvg}
|
|
379
|
-
* @package
|
|
380
|
-
*/
|
|
381
|
-
this.targetWorkspace = null;
|
|
322
|
+
/** Inverted screen CTM, for use in mouseToSvg. */
|
|
323
|
+
private inverseScreenCTM_: SVGMatrix|null = null;
|
|
382
324
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
325
|
+
/** Inverted screen CTM is dirty, recalculate it. */
|
|
326
|
+
private inverseScreenCTMDirty_ = true;
|
|
327
|
+
private metricsManager_: IMetricsManager;
|
|
328
|
+
/** @internal */
|
|
329
|
+
getMetrics: () => Metrics;
|
|
330
|
+
/** @internal */
|
|
331
|
+
setMetrics: (p1: {x: number, y: number}) => void;
|
|
332
|
+
private readonly componentManager_: ComponentManager;
|
|
389
333
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
334
|
+
/**
|
|
335
|
+
* List of currently highlighted blocks. Block highlighting is often used
|
|
336
|
+
* to visually mark blocks currently being executed.
|
|
337
|
+
*/
|
|
338
|
+
private readonly highlightedBlocks_: BlockSvg[] = [];
|
|
339
|
+
private audioManager_: WorkspaceAudio;
|
|
340
|
+
private grid_: Grid;
|
|
341
|
+
private markerManager_: MarkerManager;
|
|
342
|
+
private toolboxCategoryCallbacks_:
|
|
343
|
+
{[key: string]: ((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null};
|
|
344
|
+
private flyoutButtonCallbacks_:
|
|
345
|
+
{[key: string]: ((p1: FlyoutButton) => AnyDuringMigration)|null};
|
|
346
|
+
protected themeManager_: ThemeManager;
|
|
347
|
+
private readonly renderer_: Renderer;
|
|
348
|
+
|
|
349
|
+
/** Cached parent SVG. */
|
|
350
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
351
|
+
// 'SVGElement'.
|
|
352
|
+
private cachedParentSvg_: SVGElement = null as AnyDuringMigration;
|
|
353
|
+
|
|
354
|
+
/** True if keyboard accessibility mode is on, false otherwise. */
|
|
355
|
+
keyboardAccessibilityMode = false;
|
|
356
|
+
|
|
357
|
+
/** The list of top-level bounded elements on the workspace. */
|
|
358
|
+
private topBoundedElements_: IBoundedElement[] = [];
|
|
359
|
+
|
|
360
|
+
/** The recorded drag targets. */
|
|
361
|
+
private dragTargetAreas_: Array<{component: IDragTarget, clientRect: Rect}> =
|
|
362
|
+
[];
|
|
363
|
+
private readonly cachedParentSvgSize_: Size;
|
|
364
|
+
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
|
|
365
|
+
svgGroup_!: SVGElement;
|
|
366
|
+
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
|
|
367
|
+
svgBackground_!: SVGElement;
|
|
368
|
+
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
|
|
369
|
+
svgBlockCanvas_!: SVGElement;
|
|
370
|
+
// TODO(b/109816955): remove '!', see go/strict-prop-init-fix.
|
|
371
|
+
svgBubbleCanvas_!: SVGElement;
|
|
372
|
+
zoomControls_: AnyDuringMigration;
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* @param options Dictionary of options.
|
|
376
|
+
* @param opt_blockDragSurface Drag surface for blocks.
|
|
377
|
+
* @param opt_wsDragSurface Drag surface for the workspace.
|
|
378
|
+
*/
|
|
379
|
+
constructor(
|
|
380
|
+
options: Options, opt_blockDragSurface?: BlockDragSurfaceSvg,
|
|
381
|
+
opt_wsDragSurface?: WorkspaceDragSurfaceSvg) {
|
|
382
|
+
super(options);
|
|
396
383
|
|
|
397
384
|
const MetricsManagerClass = registry.getClassFromOptions(
|
|
398
385
|
registry.Type.METRICS_MANAGER, options, true);
|
|
399
|
-
/**
|
|
400
|
-
|
|
401
|
-
* @type {!IMetricsManager}
|
|
402
|
-
* @private
|
|
403
|
-
*/
|
|
404
|
-
this.metricsManager_ = new MetricsManagerClass(this);
|
|
386
|
+
/** Object in charge of calculating metrics for the workspace. */
|
|
387
|
+
this.metricsManager_ = new MetricsManagerClass!(this);
|
|
405
388
|
|
|
406
|
-
/**
|
|
407
|
-
* Method to get all the metrics that have to do with a workspace.
|
|
408
|
-
* @type {function():!Metrics}
|
|
409
|
-
* @package
|
|
410
|
-
*/
|
|
389
|
+
/** Method to get all the metrics that have to do with a workspace. */
|
|
411
390
|
this.getMetrics = options.getMetrics ||
|
|
412
391
|
this.metricsManager_.getMetrics.bind(this.metricsManager_);
|
|
413
392
|
|
|
414
|
-
/**
|
|
415
|
-
* Translates the workspace.
|
|
416
|
-
* @type {function(!{x:number, y:number}):void}
|
|
417
|
-
* @package
|
|
418
|
-
*/
|
|
393
|
+
/** Translates the workspace. */
|
|
419
394
|
this.setMetrics =
|
|
420
395
|
options.setMetrics || WorkspaceSvg.setTopLevelWorkspaceMetrics_;
|
|
421
396
|
|
|
422
|
-
/**
|
|
423
|
-
* @type {!ComponentManager}
|
|
424
|
-
* @private
|
|
425
|
-
*/
|
|
426
397
|
this.componentManager_ = new ComponentManager();
|
|
427
398
|
|
|
428
399
|
this.connectionDBList = ConnectionDB.init(this.connectionChecker);
|
|
@@ -438,156 +409,92 @@ class WorkspaceSvg extends Workspace {
|
|
|
438
409
|
this.useWorkspaceDragSurface_ =
|
|
439
410
|
!!this.workspaceDragSurface_ && svgMath.is3dSupported();
|
|
440
411
|
|
|
441
|
-
/**
|
|
442
|
-
* List of currently highlighted blocks. Block highlighting is often used
|
|
443
|
-
* to visually mark blocks currently being executed.
|
|
444
|
-
* @type {!Array<!BlockSvg>}
|
|
445
|
-
* @private
|
|
446
|
-
*/
|
|
447
|
-
this.highlightedBlocks_ = [];
|
|
448
|
-
|
|
449
412
|
/**
|
|
450
413
|
* Object in charge of loading, storing, and playing audio for a workspace.
|
|
451
|
-
* @type {!WorkspaceAudio}
|
|
452
|
-
* @private
|
|
453
414
|
*/
|
|
454
|
-
this.audioManager_ =
|
|
455
|
-
|
|
415
|
+
this.audioManager_ =
|
|
416
|
+
new WorkspaceAudio((options.parentWorkspace as WorkspaceSvg));
|
|
456
417
|
|
|
457
|
-
/**
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
new Grid(this.options.gridPattern, options.gridOptions) :
|
|
464
|
-
null;
|
|
418
|
+
/** This workspace's grid object or null. */
|
|
419
|
+
// AnyDuringMigration because: Type 'Grid | null' is not assignable to type
|
|
420
|
+
// 'Grid'.
|
|
421
|
+
this.grid_ = (this.options.gridPattern ?
|
|
422
|
+
new Grid(this.options.gridPattern, options.gridOptions) :
|
|
423
|
+
null) as AnyDuringMigration;
|
|
465
424
|
|
|
466
|
-
/**
|
|
467
|
-
* Manager in charge of markers and cursors.
|
|
468
|
-
* @type {!MarkerManager}
|
|
469
|
-
* @private
|
|
470
|
-
*/
|
|
425
|
+
/** Manager in charge of markers and cursors. */
|
|
471
426
|
this.markerManager_ = new MarkerManager(this);
|
|
472
427
|
|
|
473
428
|
/**
|
|
474
429
|
* Map from function names to callbacks, for deciding what to do when a
|
|
475
430
|
* custom toolbox category is opened.
|
|
476
|
-
* @type {!Object<string, ?function(!WorkspaceSvg):
|
|
477
|
-
* !toolbox.FlyoutDefinition>}
|
|
478
|
-
* @private
|
|
479
431
|
*/
|
|
480
432
|
this.toolboxCategoryCallbacks_ = Object.create(null);
|
|
481
433
|
|
|
482
434
|
/**
|
|
483
435
|
* Map from function names to callbacks, for deciding what to do when a
|
|
484
436
|
* button is clicked.
|
|
485
|
-
* @type {!Object<string, ?function(!FlyoutButton)>}
|
|
486
|
-
* @private
|
|
487
437
|
*/
|
|
488
438
|
this.flyoutButtonCallbacks_ = Object.create(null);
|
|
489
439
|
|
|
490
|
-
const Variables = goog.module.get('Blockly.Variables');
|
|
491
440
|
if (Variables && Variables.flyoutCategory) {
|
|
492
441
|
this.registerToolboxCategoryCallback(
|
|
493
442
|
Variables.CATEGORY_NAME, Variables.flyoutCategory);
|
|
494
443
|
}
|
|
495
444
|
|
|
496
|
-
const VariablesDynamic = goog.module.get('Blockly.VariablesDynamic');
|
|
497
445
|
if (VariablesDynamic && VariablesDynamic.flyoutCategory) {
|
|
498
446
|
this.registerToolboxCategoryCallback(
|
|
499
447
|
VariablesDynamic.CATEGORY_NAME, VariablesDynamic.flyoutCategory);
|
|
500
448
|
}
|
|
501
449
|
|
|
502
|
-
const Procedures = goog.module.get('Blockly.Procedures');
|
|
503
450
|
if (Procedures && Procedures.flyoutCategory) {
|
|
504
451
|
this.registerToolboxCategoryCallback(
|
|
505
452
|
Procedures.CATEGORY_NAME, Procedures.flyoutCategory);
|
|
506
453
|
this.addChangeListener(Procedures.mutatorOpenListener);
|
|
507
454
|
}
|
|
508
455
|
|
|
509
|
-
/**
|
|
510
|
-
* Object in charge of storing and updating the workspace theme.
|
|
511
|
-
* @type {!ThemeManager}
|
|
512
|
-
* @protected
|
|
513
|
-
*/
|
|
456
|
+
/** Object in charge of storing and updating the workspace theme. */
|
|
514
457
|
this.themeManager_ = this.options.parentWorkspace ?
|
|
515
458
|
this.options.parentWorkspace.getThemeManager() :
|
|
516
459
|
new ThemeManager(this, this.options.theme || Classic);
|
|
517
|
-
this
|
|
460
|
+
// AnyDuringMigration because: Argument of type 'this' is not assignable to
|
|
461
|
+
// parameter of type 'Workspace'.
|
|
462
|
+
this.themeManager_.subscribeWorkspace(this as AnyDuringMigration);
|
|
518
463
|
|
|
519
|
-
/**
|
|
520
|
-
* The block renderer used for rendering blocks on this workspace.
|
|
521
|
-
* @type {!Renderer}
|
|
522
|
-
* @private
|
|
523
|
-
*/
|
|
464
|
+
/** The block renderer used for rendering blocks on this workspace. */
|
|
524
465
|
this.renderer_ = blockRendering.init(
|
|
525
466
|
this.options.renderer || 'geras', this.getTheme(),
|
|
526
|
-
this.options.rendererOverrides);
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Cached parent SVG.
|
|
530
|
-
* @type {SVGElement}
|
|
531
|
-
* @private
|
|
532
|
-
*/
|
|
533
|
-
this.cachedParentSvg_ = null;
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* True if keyboard accessibility mode is on, false otherwise.
|
|
537
|
-
* @type {boolean}
|
|
538
|
-
*/
|
|
539
|
-
this.keyboardAccessibilityMode = false;
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* The list of top-level bounded elements on the workspace.
|
|
543
|
-
* @type {!Array<!IBoundedElement>}
|
|
544
|
-
* @private
|
|
545
|
-
*/
|
|
546
|
-
this.topBoundedElements_ = [];
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* The recorded drag targets.
|
|
550
|
-
* @type {!Array<
|
|
551
|
-
* {
|
|
552
|
-
* component: !IDragTarget,
|
|
553
|
-
* clientRect: !Rect
|
|
554
|
-
* }>}
|
|
555
|
-
* @private
|
|
556
|
-
*/
|
|
557
|
-
this.dragTargetAreas_ = [];
|
|
467
|
+
this.options.rendererOverrides ?? undefined);
|
|
558
468
|
|
|
559
469
|
/**
|
|
560
470
|
* The cached size of the parent svg element.
|
|
561
471
|
* Used to compute svg metrics.
|
|
562
|
-
* @type {!Size}
|
|
563
|
-
* @private
|
|
564
472
|
*/
|
|
565
473
|
this.cachedParentSvgSize_ = new Size(0, 0);
|
|
566
474
|
}
|
|
567
475
|
|
|
568
476
|
/**
|
|
569
477
|
* Get the marker manager for this workspace.
|
|
570
|
-
* @return
|
|
478
|
+
* @return The marker manager.
|
|
571
479
|
*/
|
|
572
|
-
getMarkerManager() {
|
|
480
|
+
getMarkerManager(): MarkerManager {
|
|
573
481
|
return this.markerManager_;
|
|
574
482
|
}
|
|
575
483
|
|
|
576
484
|
/**
|
|
577
485
|
* Gets the metrics manager for this workspace.
|
|
578
|
-
* @return
|
|
579
|
-
* @public
|
|
486
|
+
* @return The metrics manager.
|
|
580
487
|
*/
|
|
581
|
-
getMetricsManager() {
|
|
488
|
+
getMetricsManager(): IMetricsManager {
|
|
582
489
|
return this.metricsManager_;
|
|
583
490
|
}
|
|
584
491
|
|
|
585
492
|
/**
|
|
586
493
|
* Sets the metrics manager for the workspace.
|
|
587
|
-
* @param
|
|
588
|
-
* @
|
|
494
|
+
* @param metricsManager The metrics manager.
|
|
495
|
+
* @internal
|
|
589
496
|
*/
|
|
590
|
-
setMetricsManager(metricsManager) {
|
|
497
|
+
setMetricsManager(metricsManager: IMetricsManager) {
|
|
591
498
|
this.metricsManager_ = metricsManager;
|
|
592
499
|
this.getMetrics =
|
|
593
500
|
this.metricsManager_.getMetrics.bind(this.metricsManager_);
|
|
@@ -595,41 +502,40 @@ class WorkspaceSvg extends Workspace {
|
|
|
595
502
|
|
|
596
503
|
/**
|
|
597
504
|
* Gets the component manager for this workspace.
|
|
598
|
-
* @return
|
|
599
|
-
* @public
|
|
505
|
+
* @return The component manager.
|
|
600
506
|
*/
|
|
601
|
-
getComponentManager() {
|
|
507
|
+
getComponentManager(): ComponentManager {
|
|
602
508
|
return this.componentManager_;
|
|
603
509
|
}
|
|
604
510
|
|
|
605
511
|
/**
|
|
606
512
|
* Add the cursor SVG to this workspaces SVG group.
|
|
607
|
-
* @param
|
|
608
|
-
*
|
|
609
|
-
* @
|
|
513
|
+
* @param cursorSvg The SVG root of the cursor to be added to the workspace
|
|
514
|
+
* SVG group.
|
|
515
|
+
* @internal
|
|
610
516
|
*/
|
|
611
|
-
setCursorSvg(cursorSvg) {
|
|
517
|
+
setCursorSvg(cursorSvg: SVGElement) {
|
|
612
518
|
this.markerManager_.setCursorSvg(cursorSvg);
|
|
613
519
|
}
|
|
614
520
|
|
|
615
521
|
/**
|
|
616
522
|
* Add the marker SVG to this workspaces SVG group.
|
|
617
|
-
* @param
|
|
618
|
-
*
|
|
619
|
-
* @
|
|
523
|
+
* @param markerSvg The SVG root of the marker to be added to the workspace
|
|
524
|
+
* SVG group.
|
|
525
|
+
* @internal
|
|
620
526
|
*/
|
|
621
|
-
setMarkerSvg(markerSvg) {
|
|
527
|
+
setMarkerSvg(markerSvg: SVGElement) {
|
|
622
528
|
this.markerManager_.setMarkerSvg(markerSvg);
|
|
623
529
|
}
|
|
624
530
|
|
|
625
531
|
/**
|
|
626
532
|
* Get the marker with the given ID.
|
|
627
|
-
* @param
|
|
628
|
-
* @return
|
|
629
|
-
*
|
|
630
|
-
* @
|
|
533
|
+
* @param id The ID of the marker.
|
|
534
|
+
* @return The marker with the given ID or null if no marker with the given ID
|
|
535
|
+
* exists.
|
|
536
|
+
* @internal
|
|
631
537
|
*/
|
|
632
|
-
getMarker(id) {
|
|
538
|
+
getMarker(id: string): Marker|null {
|
|
633
539
|
if (this.markerManager_) {
|
|
634
540
|
return this.markerManager_.getMarker(id);
|
|
635
541
|
}
|
|
@@ -638,9 +544,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
638
544
|
|
|
639
545
|
/**
|
|
640
546
|
* The cursor for this workspace.
|
|
641
|
-
* @return
|
|
547
|
+
* @return The cursor for the workspace.
|
|
642
548
|
*/
|
|
643
|
-
getCursor() {
|
|
549
|
+
getCursor(): Cursor|null {
|
|
644
550
|
if (this.markerManager_) {
|
|
645
551
|
return this.markerManager_.getCursor();
|
|
646
552
|
}
|
|
@@ -649,45 +555,43 @@ class WorkspaceSvg extends Workspace {
|
|
|
649
555
|
|
|
650
556
|
/**
|
|
651
557
|
* Get the block renderer attached to this workspace.
|
|
652
|
-
* @return
|
|
653
|
-
* workspace.
|
|
558
|
+
* @return The renderer attached to this workspace.
|
|
654
559
|
*/
|
|
655
|
-
getRenderer() {
|
|
560
|
+
getRenderer(): Renderer {
|
|
656
561
|
return this.renderer_;
|
|
657
562
|
}
|
|
658
563
|
|
|
659
564
|
/**
|
|
660
565
|
* Get the theme manager for this workspace.
|
|
661
|
-
* @return
|
|
662
|
-
* @
|
|
566
|
+
* @return The theme manager for this workspace.
|
|
567
|
+
* @internal
|
|
663
568
|
*/
|
|
664
|
-
getThemeManager() {
|
|
569
|
+
getThemeManager(): ThemeManager {
|
|
665
570
|
return this.themeManager_;
|
|
666
571
|
}
|
|
667
572
|
|
|
668
573
|
/**
|
|
669
574
|
* Get the workspace theme object.
|
|
670
|
-
* @return
|
|
575
|
+
* @return The workspace theme object.
|
|
671
576
|
*/
|
|
672
|
-
getTheme() {
|
|
577
|
+
getTheme(): Theme {
|
|
673
578
|
return this.themeManager_.getTheme();
|
|
674
579
|
}
|
|
675
580
|
|
|
676
581
|
/**
|
|
677
582
|
* Set the workspace theme object.
|
|
678
583
|
* If no theme is passed, default to the `Classic` theme.
|
|
679
|
-
* @param
|
|
584
|
+
* @param theme The workspace theme object.
|
|
680
585
|
*/
|
|
681
|
-
setTheme(theme) {
|
|
586
|
+
setTheme(theme: Theme) {
|
|
682
587
|
if (!theme) {
|
|
683
|
-
theme =
|
|
588
|
+
theme = Classic as Theme;
|
|
684
589
|
}
|
|
685
590
|
this.themeManager_.setTheme(theme);
|
|
686
591
|
}
|
|
687
592
|
|
|
688
593
|
/**
|
|
689
594
|
* Refresh all blocks on the workspace after a theme update.
|
|
690
|
-
* @package
|
|
691
595
|
*/
|
|
692
596
|
refreshTheme() {
|
|
693
597
|
if (this.svgGroup_) {
|
|
@@ -695,9 +599,11 @@ class WorkspaceSvg extends Workspace {
|
|
|
695
599
|
}
|
|
696
600
|
|
|
697
601
|
// Update all blocks in workspace that have a style name.
|
|
602
|
+
// AnyDuringMigration because: Argument of type 'BlockSvg[]' is not
|
|
603
|
+
// assignable to parameter of type 'Block[]'.
|
|
698
604
|
this.updateBlockStyles_(this.getAllBlocks(false).filter(function(block) {
|
|
699
605
|
return !!block.getStyleName();
|
|
700
|
-
}));
|
|
606
|
+
}) as AnyDuringMigration);
|
|
701
607
|
|
|
702
608
|
// Update current toolbox selection.
|
|
703
609
|
this.refreshToolboxSelection();
|
|
@@ -710,24 +616,23 @@ class WorkspaceSvg extends Workspace {
|
|
|
710
616
|
this.setVisible(true);
|
|
711
617
|
}
|
|
712
618
|
|
|
713
|
-
const event = new (eventUtils.get(eventUtils.THEME_CHANGE))
|
|
714
|
-
this.getTheme().name, this.id);
|
|
619
|
+
const event = new (eventUtils.get(eventUtils.THEME_CHANGE))!
|
|
620
|
+
(this.getTheme().name, this.id);
|
|
715
621
|
eventUtils.fire(event);
|
|
716
622
|
}
|
|
717
623
|
|
|
718
624
|
/**
|
|
719
625
|
* Updates all the blocks with new style.
|
|
720
|
-
* @param
|
|
721
|
-
* on.
|
|
722
|
-
* @private
|
|
626
|
+
* @param blocks List of blocks to update the style on.
|
|
723
627
|
*/
|
|
724
|
-
updateBlockStyles_(blocks) {
|
|
725
|
-
for (let i = 0, block;
|
|
628
|
+
private updateBlockStyles_(blocks: Block[]) {
|
|
629
|
+
for (let i = 0, block; block = blocks[i]; i++) {
|
|
726
630
|
const blockStyleName = block.getStyleName();
|
|
727
631
|
if (blockStyleName) {
|
|
728
|
-
block
|
|
729
|
-
|
|
730
|
-
|
|
632
|
+
const blockSvg = block as BlockSvg;
|
|
633
|
+
blockSvg.setStyle(blockStyleName);
|
|
634
|
+
if (blockSvg.mutator) {
|
|
635
|
+
blockSvg.mutator.updateBlockStyle();
|
|
731
636
|
}
|
|
732
637
|
}
|
|
733
638
|
}
|
|
@@ -735,15 +640,15 @@ class WorkspaceSvg extends Workspace {
|
|
|
735
640
|
|
|
736
641
|
/**
|
|
737
642
|
* Getter for the inverted screen CTM.
|
|
738
|
-
* @return
|
|
643
|
+
* @return The matrix to use in mouseToSvg
|
|
739
644
|
*/
|
|
740
|
-
getInverseScreenCTM() {
|
|
645
|
+
getInverseScreenCTM(): SVGMatrix|null {
|
|
741
646
|
// Defer getting the screen CTM until we actually need it, this should
|
|
742
647
|
// avoid forced reflows from any calls to updateInverseScreenCTM.
|
|
743
648
|
if (this.inverseScreenCTMDirty_) {
|
|
744
649
|
const ctm = this.getParentSvg().getScreenCTM();
|
|
745
650
|
if (ctm) {
|
|
746
|
-
this.inverseScreenCTM_ = ctm.inverse();
|
|
651
|
+
this.inverseScreenCTM_ = (ctm).inverse();
|
|
747
652
|
this.inverseScreenCTMDirty_ = false;
|
|
748
653
|
}
|
|
749
654
|
}
|
|
@@ -751,19 +656,17 @@ class WorkspaceSvg extends Workspace {
|
|
|
751
656
|
return this.inverseScreenCTM_;
|
|
752
657
|
}
|
|
753
658
|
|
|
754
|
-
/**
|
|
755
|
-
* Mark the inverse screen CTM as dirty.
|
|
756
|
-
*/
|
|
659
|
+
/** Mark the inverse screen CTM as dirty. */
|
|
757
660
|
updateInverseScreenCTM() {
|
|
758
661
|
this.inverseScreenCTMDirty_ = true;
|
|
759
662
|
}
|
|
760
663
|
|
|
761
664
|
/**
|
|
762
665
|
* Getter for isVisible
|
|
763
|
-
* @return
|
|
666
|
+
* @return Whether the workspace is visible.
|
|
764
667
|
* False if the workspace has been hidden by calling `setVisible(false)`.
|
|
765
668
|
*/
|
|
766
|
-
isVisible() {
|
|
669
|
+
isVisible(): boolean {
|
|
767
670
|
return this.isVisible_;
|
|
768
671
|
}
|
|
769
672
|
|
|
@@ -771,11 +674,11 @@ class WorkspaceSvg extends Workspace {
|
|
|
771
674
|
* Return the absolute coordinates of the top-left corner of this element,
|
|
772
675
|
* scales that after canvas SVG element, if it's a descendant.
|
|
773
676
|
* The origin (0,0) is the top-left corner of the Blockly SVG.
|
|
774
|
-
* @param
|
|
775
|
-
* @return
|
|
776
|
-
* @
|
|
677
|
+
* @param element SVG element to find the coordinates of.
|
|
678
|
+
* @return Object with .x and .y properties.
|
|
679
|
+
* @internal
|
|
777
680
|
*/
|
|
778
|
-
getSvgXY(element) {
|
|
681
|
+
getSvgXY(element: SVGElement): Coordinate {
|
|
779
682
|
let x = 0;
|
|
780
683
|
let y = 0;
|
|
781
684
|
let scale = 1;
|
|
@@ -793,18 +696,17 @@ class WorkspaceSvg extends Workspace {
|
|
|
793
696
|
}
|
|
794
697
|
x += xy.x * scale;
|
|
795
698
|
y += xy.y * scale;
|
|
796
|
-
element =
|
|
699
|
+
element = element.parentNode as SVGElement;
|
|
797
700
|
} while (element && element !== this.getParentSvg());
|
|
798
701
|
return new Coordinate(x, y);
|
|
799
702
|
}
|
|
800
703
|
|
|
801
704
|
/**
|
|
802
705
|
* Gets the size of the workspace's parent SVG element.
|
|
803
|
-
* @return
|
|
804
|
-
*
|
|
805
|
-
* @package
|
|
706
|
+
* @return The cached width and height of the workspace's parent SVG element.
|
|
707
|
+
* @internal
|
|
806
708
|
*/
|
|
807
|
-
getCachedParentSvgSize() {
|
|
709
|
+
getCachedParentSvgSize(): Size {
|
|
808
710
|
const size = this.cachedParentSvgSize_;
|
|
809
711
|
return new Size(size.width, size.height);
|
|
810
712
|
}
|
|
@@ -814,10 +716,10 @@ class WorkspaceSvg extends Workspace {
|
|
|
814
716
|
* origin in pixels.
|
|
815
717
|
* The workspace origin is where a block would render at position (0, 0).
|
|
816
718
|
* It is not the upper left corner of the workspace SVG.
|
|
817
|
-
* @return
|
|
818
|
-
* @
|
|
719
|
+
* @return Offset in pixels.
|
|
720
|
+
* @internal
|
|
819
721
|
*/
|
|
820
|
-
getOriginOffsetInPixels() {
|
|
722
|
+
getOriginOffsetInPixels(): Coordinate {
|
|
821
723
|
return svgMath.getInjectionDivXY(this.getCanvas());
|
|
822
724
|
}
|
|
823
725
|
|
|
@@ -826,51 +728,50 @@ class WorkspaceSvg extends Workspace {
|
|
|
826
728
|
* Walks the DOM the first time it's called, then returns a cached value.
|
|
827
729
|
* Note: We assume this is only called after the workspace has been injected
|
|
828
730
|
* into the DOM.
|
|
829
|
-
* @return
|
|
830
|
-
* @
|
|
731
|
+
* @return The first parent div with 'injectionDiv' in the name.
|
|
732
|
+
* @internal
|
|
831
733
|
*/
|
|
832
|
-
getInjectionDiv() {
|
|
734
|
+
getInjectionDiv(): Element {
|
|
833
735
|
// NB: it would be better to pass this in at createDom, but is more likely
|
|
834
736
|
// to break existing uses of Blockly.
|
|
835
737
|
if (!this.injectionDiv_) {
|
|
836
|
-
let element = this.svgGroup_;
|
|
738
|
+
let element: Element = this.svgGroup_;
|
|
837
739
|
while (element) {
|
|
838
740
|
const classes = element.getAttribute('class') || '';
|
|
839
741
|
if ((' ' + classes + ' ').indexOf(' injectionDiv ') !== -1) {
|
|
840
742
|
this.injectionDiv_ = element;
|
|
841
743
|
break;
|
|
842
744
|
}
|
|
843
|
-
element =
|
|
745
|
+
element = element.parentNode as Element;
|
|
844
746
|
}
|
|
845
747
|
}
|
|
846
|
-
return
|
|
748
|
+
return this.injectionDiv_;
|
|
847
749
|
}
|
|
848
750
|
|
|
849
751
|
/**
|
|
850
752
|
* Get the SVG block canvas for the workspace.
|
|
851
|
-
* @return
|
|
852
|
-
* @
|
|
753
|
+
* @return The SVG group for the workspace.
|
|
754
|
+
* @internal
|
|
853
755
|
*/
|
|
854
|
-
getBlockCanvas() {
|
|
756
|
+
getBlockCanvas(): SVGElement|null {
|
|
855
757
|
return this.svgBlockCanvas_;
|
|
856
758
|
}
|
|
857
759
|
|
|
858
760
|
/**
|
|
859
761
|
* Save resize handler data so we can delete it later in dispose.
|
|
860
|
-
* @param
|
|
861
|
-
* eventHandling.unbind.
|
|
762
|
+
* @param handler Data that can be passed to eventHandling.unbind.
|
|
862
763
|
*/
|
|
863
|
-
setResizeHandlerWrapper(handler) {
|
|
764
|
+
setResizeHandlerWrapper(handler: browserEvents.Data) {
|
|
864
765
|
this.resizeHandlerWrapper_ = handler;
|
|
865
766
|
}
|
|
866
767
|
|
|
867
768
|
/**
|
|
868
769
|
* Create the workspace DOM elements.
|
|
869
|
-
* @param
|
|
770
|
+
* @param opt_backgroundClass Either 'blocklyMainBackground' or
|
|
870
771
|
* 'blocklyMutatorBackground'.
|
|
871
|
-
* @return
|
|
772
|
+
* @return The workspace's SVG group.
|
|
872
773
|
*/
|
|
873
|
-
createDom(opt_backgroundClass) {
|
|
774
|
+
createDom(opt_backgroundClass?: string): Element {
|
|
874
775
|
/**
|
|
875
776
|
* <g class="blocklyWorkspace">
|
|
876
777
|
* <rect class="blocklyMainBackground" height="100%" width="100%"></rect>
|
|
@@ -878,16 +779,13 @@ class WorkspaceSvg extends Workspace {
|
|
|
878
779
|
* <g class="blocklyBlockCanvas"></g>
|
|
879
780
|
* <g class="blocklyBubbleCanvas"></g>
|
|
880
781
|
* </g>
|
|
881
|
-
* @type {SVGElement}
|
|
882
782
|
*/
|
|
883
|
-
this.svgGroup_ =
|
|
884
|
-
dom.createSvgElement(Svg.G, {'class': 'blocklyWorkspace'}, null);
|
|
783
|
+
this.svgGroup_ = dom.createSvgElement(Svg.G, {'class': 'blocklyWorkspace'});
|
|
885
784
|
|
|
886
785
|
// Note that a <g> alone does not receive mouse events--it must have a
|
|
887
786
|
// valid target inside it. If no background class is specified, as in the
|
|
888
787
|
// flyout, the workspace will not receive mouse events.
|
|
889
788
|
if (opt_backgroundClass) {
|
|
890
|
-
/** @type {SVGElement} */
|
|
891
789
|
this.svgBackground_ = dom.createSvgElement(
|
|
892
790
|
Svg.RECT,
|
|
893
791
|
{'height': '100%', 'width': '100%', 'class': opt_backgroundClass},
|
|
@@ -901,10 +799,8 @@ class WorkspaceSvg extends Workspace {
|
|
|
901
799
|
this.svgBackground_, 'workspaceBackgroundColour', 'fill');
|
|
902
800
|
}
|
|
903
801
|
}
|
|
904
|
-
/** @type {SVGElement} */
|
|
905
802
|
this.svgBlockCanvas_ = dom.createSvgElement(
|
|
906
803
|
Svg.G, {'class': 'blocklyBlockCanvas'}, this.svgGroup_);
|
|
907
|
-
/** @type {SVGElement} */
|
|
908
804
|
this.svgBubbleCanvas_ = dom.createSvgElement(
|
|
909
805
|
Svg.G, {'class': 'blocklyBubbleCanvas'}, this.svgGroup_);
|
|
910
806
|
|
|
@@ -924,7 +820,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
924
820
|
if (this.options.hasCategories) {
|
|
925
821
|
const ToolboxClass = registry.getClassFromOptions(
|
|
926
822
|
registry.Type.TOOLBOX, this.options, true);
|
|
927
|
-
this.toolbox_ = new ToolboxClass(this);
|
|
823
|
+
this.toolbox_ = new ToolboxClass!(this);
|
|
928
824
|
}
|
|
929
825
|
if (this.grid_) {
|
|
930
826
|
this.grid_.update(this.scale);
|
|
@@ -944,7 +840,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
944
840
|
* Unlink from all DOM elements to prevent memory leaks.
|
|
945
841
|
* @suppress {checkTypes}
|
|
946
842
|
*/
|
|
947
|
-
dispose() {
|
|
843
|
+
override dispose() {
|
|
948
844
|
// Stop rerendering.
|
|
949
845
|
this.rendered = false;
|
|
950
846
|
if (this.currentGesture_) {
|
|
@@ -952,25 +848,39 @@ class WorkspaceSvg extends Workspace {
|
|
|
952
848
|
}
|
|
953
849
|
if (this.svgGroup_) {
|
|
954
850
|
dom.removeNode(this.svgGroup_);
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
851
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
852
|
+
// 'SVGElement'.
|
|
853
|
+
this.svgGroup_ = null as AnyDuringMigration;
|
|
854
|
+
}
|
|
855
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
856
|
+
// 'SVGElement'.
|
|
857
|
+
this.svgBlockCanvas_ = null as AnyDuringMigration;
|
|
858
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
859
|
+
// 'SVGElement'.
|
|
860
|
+
this.svgBubbleCanvas_ = null as AnyDuringMigration;
|
|
959
861
|
if (this.toolbox_) {
|
|
960
862
|
this.toolbox_.dispose();
|
|
961
|
-
|
|
863
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
864
|
+
// 'IToolbox'.
|
|
865
|
+
this.toolbox_ = null as AnyDuringMigration;
|
|
962
866
|
}
|
|
963
867
|
if (this.flyout_) {
|
|
964
868
|
this.flyout_.dispose();
|
|
965
|
-
|
|
869
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
870
|
+
// 'IFlyout'.
|
|
871
|
+
this.flyout_ = null as AnyDuringMigration;
|
|
966
872
|
}
|
|
967
873
|
if (this.trashcan) {
|
|
968
874
|
this.trashcan.dispose();
|
|
969
|
-
|
|
875
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
876
|
+
// 'Trashcan'.
|
|
877
|
+
this.trashcan = null as AnyDuringMigration;
|
|
970
878
|
}
|
|
971
879
|
if (this.scrollbar) {
|
|
972
880
|
this.scrollbar.dispose();
|
|
973
|
-
|
|
881
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
882
|
+
// 'ScrollbarPair'.
|
|
883
|
+
this.scrollbar = null as AnyDuringMigration;
|
|
974
884
|
}
|
|
975
885
|
if (this.zoomControls_) {
|
|
976
886
|
this.zoomControls_.dispose();
|
|
@@ -979,37 +889,50 @@ class WorkspaceSvg extends Workspace {
|
|
|
979
889
|
|
|
980
890
|
if (this.audioManager_) {
|
|
981
891
|
this.audioManager_.dispose();
|
|
982
|
-
|
|
892
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
893
|
+
// 'WorkspaceAudio'.
|
|
894
|
+
this.audioManager_ = null as AnyDuringMigration;
|
|
983
895
|
}
|
|
984
896
|
|
|
985
897
|
if (this.grid_) {
|
|
986
|
-
|
|
987
|
-
|
|
898
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
899
|
+
// 'Grid'.
|
|
900
|
+
this.grid_ = null as AnyDuringMigration;
|
|
988
901
|
}
|
|
989
902
|
|
|
990
903
|
this.renderer_.dispose();
|
|
991
904
|
|
|
992
905
|
if (this.markerManager_) {
|
|
993
906
|
this.markerManager_.dispose();
|
|
994
|
-
|
|
907
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
908
|
+
// 'MarkerManager'.
|
|
909
|
+
this.markerManager_ = null as AnyDuringMigration;
|
|
995
910
|
}
|
|
996
911
|
|
|
997
912
|
super.dispose();
|
|
998
913
|
|
|
999
914
|
// Dispose of theme manager after all blocks and mutators are disposed of.
|
|
1000
915
|
if (this.themeManager_) {
|
|
1001
|
-
this
|
|
916
|
+
// AnyDuringMigration because: Argument of type 'this' is not assignable
|
|
917
|
+
// to parameter of type 'Workspace'.
|
|
918
|
+
this.themeManager_.unsubscribeWorkspace(this as AnyDuringMigration);
|
|
1002
919
|
this.themeManager_.unsubscribe(this.svgBackground_);
|
|
1003
920
|
if (!this.options.parentWorkspace) {
|
|
1004
921
|
this.themeManager_.dispose();
|
|
1005
|
-
|
|
922
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
923
|
+
// 'ThemeManager'.
|
|
924
|
+
this.themeManager_ = null as AnyDuringMigration;
|
|
1006
925
|
}
|
|
1007
926
|
}
|
|
1008
927
|
|
|
1009
|
-
this.connectionDBList =
|
|
928
|
+
this.connectionDBList.length = 0;
|
|
1010
929
|
|
|
1011
|
-
|
|
1012
|
-
|
|
930
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type '{
|
|
931
|
+
// [key: string]: ((p1: WorkspaceSvg) => FlyoutDefinition) | null; }'.
|
|
932
|
+
this.toolboxCategoryCallbacks_ = null as AnyDuringMigration;
|
|
933
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type '{
|
|
934
|
+
// [key: string]: ((p1: FlyoutButton) => any) | null; }'.
|
|
935
|
+
this.flyoutButtonCallbacks_ = null as AnyDuringMigration;
|
|
1013
936
|
|
|
1014
937
|
if (!this.options.parentWorkspace) {
|
|
1015
938
|
// Top-most workspace. Dispose of the div that the
|
|
@@ -1025,48 +948,30 @@ class WorkspaceSvg extends Workspace {
|
|
|
1025
948
|
}
|
|
1026
949
|
}
|
|
1027
950
|
|
|
1028
|
-
/**
|
|
1029
|
-
* Obtain a newly created block.
|
|
1030
|
-
*
|
|
1031
|
-
* This block's SVG must still be initialized
|
|
1032
|
-
* ([initSvg]{@link BlockSvg#initSvg}) and it must be rendered
|
|
1033
|
-
* ([render]{@link BlockSvg#render}) before the block will be visible.
|
|
1034
|
-
* @param {!string} prototypeName Name of the language object containing
|
|
1035
|
-
* type-specific functions for this block.
|
|
1036
|
-
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
|
|
1037
|
-
* create a new ID.
|
|
1038
|
-
* @return {!BlockSvg} The created block.
|
|
1039
|
-
* @override
|
|
1040
|
-
*/
|
|
1041
|
-
newBlock(prototypeName, opt_id) {
|
|
1042
|
-
return new BlockSvg(this, prototypeName, opt_id);
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
951
|
/**
|
|
1046
952
|
* Add a trashcan.
|
|
1047
|
-
* @
|
|
953
|
+
* @internal
|
|
1048
954
|
*/
|
|
1049
955
|
addTrashcan() {
|
|
1050
|
-
|
|
1051
|
-
if (!Trashcan) {
|
|
1052
|
-
throw Error('Missing require for Blockly.Trashcan');
|
|
1053
|
-
}
|
|
1054
|
-
/** @type {Trashcan} */
|
|
1055
|
-
this.trashcan = new Trashcan(this);
|
|
956
|
+
this.trashcan = WorkspaceSvg.newTrashcan(this);
|
|
1056
957
|
const svgTrashcan = this.trashcan.createDom();
|
|
1057
958
|
this.svgGroup_.insertBefore(svgTrashcan, this.svgBlockCanvas_);
|
|
1058
959
|
}
|
|
1059
960
|
|
|
961
|
+
/**
|
|
962
|
+
* @internal
|
|
963
|
+
*/
|
|
964
|
+
static newTrashcan(workspace: WorkspaceSvg): Trashcan {
|
|
965
|
+
throw new Error(
|
|
966
|
+
'The implementation of newTrashcan should be ' +
|
|
967
|
+
'monkey-patched in by blockly.ts');
|
|
968
|
+
}
|
|
969
|
+
|
|
1060
970
|
/**
|
|
1061
971
|
* Add zoom controls.
|
|
1062
|
-
* @
|
|
972
|
+
* @internal
|
|
1063
973
|
*/
|
|
1064
974
|
addZoomControls() {
|
|
1065
|
-
const {ZoomControls} = goog.module.get('Blockly.ZoomControls');
|
|
1066
|
-
if (!ZoomControls) {
|
|
1067
|
-
throw Error('Missing require for Blockly.ZoomControls');
|
|
1068
|
-
}
|
|
1069
|
-
/** @type {ZoomControls} */
|
|
1070
975
|
this.zoomControls_ = new ZoomControls(this);
|
|
1071
976
|
const svgZoomControls = this.zoomControls_.createDom();
|
|
1072
977
|
this.svgGroup_.appendChild(svgZoomControls);
|
|
@@ -1074,36 +979,31 @@ class WorkspaceSvg extends Workspace {
|
|
|
1074
979
|
|
|
1075
980
|
/**
|
|
1076
981
|
* Add a flyout element in an element with the given tag name.
|
|
1077
|
-
* @param
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
'rendererOverrides': this.options.rendererOverrides,
|
|
1094
|
-
'move': {
|
|
1095
|
-
'scrollbars': true,
|
|
1096
|
-
},
|
|
1097
|
-
}));
|
|
982
|
+
* @param tagName What type of tag the flyout belongs in.
|
|
983
|
+
* @return The element containing the flyout DOM.
|
|
984
|
+
* @internal
|
|
985
|
+
*/
|
|
986
|
+
addFlyout(tagName: string|Svg<SVGSVGElement>|Svg<SVGGElement>): Element {
|
|
987
|
+
const workspaceOptions = new Options(({
|
|
988
|
+
'parentWorkspace': this,
|
|
989
|
+
'rtl': this.RTL,
|
|
990
|
+
'oneBasedIndex': this.options.oneBasedIndex,
|
|
991
|
+
'horizontalLayout': this.horizontalLayout,
|
|
992
|
+
'renderer': this.options.renderer,
|
|
993
|
+
'rendererOverrides': this.options.rendererOverrides,
|
|
994
|
+
'move': {
|
|
995
|
+
'scrollbars': true,
|
|
996
|
+
},
|
|
997
|
+
} as BlocklyOptions));
|
|
1098
998
|
workspaceOptions.toolboxPosition = this.options.toolboxPosition;
|
|
1099
999
|
if (this.horizontalLayout) {
|
|
1100
1000
|
const HorizontalFlyout = registry.getClassFromOptions(
|
|
1101
1001
|
registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX, this.options, true);
|
|
1102
|
-
this.flyout_ = new HorizontalFlyout(workspaceOptions);
|
|
1002
|
+
this.flyout_ = new HorizontalFlyout!(workspaceOptions);
|
|
1103
1003
|
} else {
|
|
1104
1004
|
const VerticalFlyout = registry.getClassFromOptions(
|
|
1105
1005
|
registry.Type.FLYOUTS_VERTICAL_TOOLBOX, this.options, true);
|
|
1106
|
-
this.flyout_ = new VerticalFlyout(workspaceOptions);
|
|
1006
|
+
this.flyout_ = new VerticalFlyout!(workspaceOptions);
|
|
1107
1007
|
}
|
|
1108
1008
|
this.flyout_.autoClose = false;
|
|
1109
1009
|
this.flyout_.getWorkspace().setVisible(true);
|
|
@@ -1118,12 +1018,11 @@ class WorkspaceSvg extends Workspace {
|
|
|
1118
1018
|
* Getter for the flyout associated with this workspace. This flyout may be
|
|
1119
1019
|
* owned by either the toolbox or the workspace, depending on toolbox
|
|
1120
1020
|
* configuration. It will be null if there is no flyout.
|
|
1121
|
-
* @param
|
|
1122
|
-
*
|
|
1123
|
-
* @
|
|
1124
|
-
* @package
|
|
1021
|
+
* @param opt_own Whether to only return the workspace's own flyout.
|
|
1022
|
+
* @return The flyout on this workspace.
|
|
1023
|
+
* @internal
|
|
1125
1024
|
*/
|
|
1126
|
-
getFlyout(opt_own) {
|
|
1025
|
+
getFlyout(opt_own?: boolean): IFlyout|null {
|
|
1127
1026
|
if (this.flyout_ || opt_own) {
|
|
1128
1027
|
return this.flyout_;
|
|
1129
1028
|
}
|
|
@@ -1135,19 +1034,18 @@ class WorkspaceSvg extends Workspace {
|
|
|
1135
1034
|
|
|
1136
1035
|
/**
|
|
1137
1036
|
* Getter for the toolbox associated with this workspace, if one exists.
|
|
1138
|
-
* @return
|
|
1139
|
-
* @
|
|
1037
|
+
* @return The toolbox on this workspace.
|
|
1038
|
+
* @internal
|
|
1140
1039
|
*/
|
|
1141
|
-
getToolbox() {
|
|
1040
|
+
getToolbox(): IToolbox|null {
|
|
1142
1041
|
return this.toolbox_;
|
|
1143
1042
|
}
|
|
1144
1043
|
|
|
1145
1044
|
/**
|
|
1146
1045
|
* Update items that use screen coordinate calculations
|
|
1147
1046
|
* because something has changed (e.g. scroll position, window size).
|
|
1148
|
-
* @private
|
|
1149
1047
|
*/
|
|
1150
|
-
updateScreenCalculations_() {
|
|
1048
|
+
private updateScreenCalculations_() {
|
|
1151
1049
|
this.updateInverseScreenCTM();
|
|
1152
1050
|
this.recordDragTargets();
|
|
1153
1051
|
}
|
|
@@ -1156,7 +1054,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1156
1054
|
* If enabled, resize the parts of the workspace that change when the
|
|
1157
1055
|
* workspace contents (e.g. block positions) change. This will also scroll
|
|
1158
1056
|
* the workspace contents if needed.
|
|
1159
|
-
* @
|
|
1057
|
+
* @internal
|
|
1160
1058
|
*/
|
|
1161
1059
|
resizeContents() {
|
|
1162
1060
|
if (!this.resizesEnabled_ || !this.rendered) {
|
|
@@ -1187,7 +1085,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1187
1085
|
ComponentManager.Capability.POSITIONABLE, true);
|
|
1188
1086
|
const metrics = this.getMetricsManager().getUiMetrics();
|
|
1189
1087
|
const savedPositions = [];
|
|
1190
|
-
for (let i = 0, positionable;
|
|
1088
|
+
for (let i = 0, positionable; positionable = positionables[i]; i++) {
|
|
1191
1089
|
positionable.position(metrics, savedPositions);
|
|
1192
1090
|
const boundingRect = positionable.getBoundingRectangle();
|
|
1193
1091
|
if (boundingRect) {
|
|
@@ -1204,7 +1102,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1204
1102
|
/**
|
|
1205
1103
|
* Resizes and repositions workspace chrome if the page has a new
|
|
1206
1104
|
* scroll position.
|
|
1207
|
-
* @
|
|
1105
|
+
* @internal
|
|
1208
1106
|
*/
|
|
1209
1107
|
updateScreenCalculationsIfScrolled() {
|
|
1210
1108
|
/* eslint-disable indent */
|
|
@@ -1218,50 +1116,54 @@ class WorkspaceSvg extends Workspace {
|
|
|
1218
1116
|
|
|
1219
1117
|
/**
|
|
1220
1118
|
* Get the SVG element that forms the drawing surface.
|
|
1221
|
-
* @return
|
|
1119
|
+
* @return SVG group element.
|
|
1222
1120
|
*/
|
|
1223
|
-
getCanvas() {
|
|
1224
|
-
return
|
|
1121
|
+
getCanvas(): SVGGElement {
|
|
1122
|
+
return this.svgBlockCanvas_ as SVGGElement;
|
|
1225
1123
|
}
|
|
1226
1124
|
|
|
1227
1125
|
/**
|
|
1228
1126
|
* Caches the width and height of the workspace's parent SVG element for use
|
|
1229
1127
|
* with getSvgMetrics.
|
|
1230
|
-
* @param
|
|
1231
|
-
* @param
|
|
1232
|
-
* @
|
|
1128
|
+
* @param width The width of the parent SVG element.
|
|
1129
|
+
* @param height The height of the parent SVG element
|
|
1130
|
+
* @internal
|
|
1233
1131
|
*/
|
|
1234
|
-
setCachedParentSvgSize(width, height) {
|
|
1132
|
+
setCachedParentSvgSize(width: number|null, height: number|null) {
|
|
1235
1133
|
const svg = this.getParentSvg();
|
|
1236
1134
|
if (width != null) {
|
|
1237
1135
|
this.cachedParentSvgSize_.width = width;
|
|
1238
1136
|
// This is set to support the public (but deprecated) Blockly.svgSize
|
|
1239
1137
|
// method.
|
|
1240
|
-
|
|
1138
|
+
// AnyDuringMigration because: Argument of type 'number' is not
|
|
1139
|
+
// assignable to parameter of type 'string'.
|
|
1140
|
+
svg.setAttribute('data-cached-width', width as AnyDuringMigration);
|
|
1241
1141
|
}
|
|
1242
1142
|
if (height != null) {
|
|
1243
1143
|
this.cachedParentSvgSize_.height = height;
|
|
1244
1144
|
// This is set to support the public (but deprecated) Blockly.svgSize
|
|
1245
1145
|
// method.
|
|
1246
|
-
|
|
1146
|
+
// AnyDuringMigration because: Argument of type 'number' is not
|
|
1147
|
+
// assignable to parameter of type 'string'.
|
|
1148
|
+
svg.setAttribute('data-cached-height', height as AnyDuringMigration);
|
|
1247
1149
|
}
|
|
1248
1150
|
}
|
|
1249
1151
|
|
|
1250
1152
|
/**
|
|
1251
1153
|
* Get the SVG element that forms the bubble surface.
|
|
1252
|
-
* @return
|
|
1154
|
+
* @return SVG group element.
|
|
1253
1155
|
*/
|
|
1254
|
-
getBubbleCanvas() {
|
|
1255
|
-
return
|
|
1156
|
+
getBubbleCanvas(): SVGGElement {
|
|
1157
|
+
return this.svgBubbleCanvas_ as SVGGElement;
|
|
1256
1158
|
}
|
|
1257
1159
|
|
|
1258
1160
|
/**
|
|
1259
1161
|
* Get the SVG element that contains this workspace.
|
|
1260
1162
|
* Note: We assume this is only called after the workspace has been injected
|
|
1261
1163
|
* into the DOM.
|
|
1262
|
-
* @return
|
|
1164
|
+
* @return SVG element.
|
|
1263
1165
|
*/
|
|
1264
|
-
getParentSvg() {
|
|
1166
|
+
getParentSvg(): SVGSVGElement {
|
|
1265
1167
|
if (!this.cachedParentSvg_) {
|
|
1266
1168
|
let element = this.svgGroup_;
|
|
1267
1169
|
while (element) {
|
|
@@ -1269,16 +1171,16 @@ class WorkspaceSvg extends Workspace {
|
|
|
1269
1171
|
this.cachedParentSvg_ = element;
|
|
1270
1172
|
break;
|
|
1271
1173
|
}
|
|
1272
|
-
element =
|
|
1174
|
+
element = element.parentNode as SVGSVGElement;
|
|
1273
1175
|
}
|
|
1274
1176
|
}
|
|
1275
|
-
return
|
|
1177
|
+
return this.cachedParentSvg_ as SVGSVGElement;
|
|
1276
1178
|
}
|
|
1277
1179
|
|
|
1278
1180
|
/**
|
|
1279
1181
|
* Fires a viewport event if events are enabled and there is a change in
|
|
1280
1182
|
* viewport values.
|
|
1281
|
-
* @
|
|
1183
|
+
* @internal
|
|
1282
1184
|
*/
|
|
1283
1185
|
maybeFireViewportChangeEvent() {
|
|
1284
1186
|
if (!eventUtils.isEnabled()) {
|
|
@@ -1293,8 +1195,8 @@ class WorkspaceSvg extends Workspace {
|
|
|
1293
1195
|
// of negligible changes in viewport top/left.
|
|
1294
1196
|
return;
|
|
1295
1197
|
}
|
|
1296
|
-
const event = new (eventUtils.get(eventUtils.VIEWPORT_CHANGE))
|
|
1297
|
-
top, left, scale, this.id, this.oldScale_);
|
|
1198
|
+
const event = new (eventUtils.get(eventUtils.VIEWPORT_CHANGE))!
|
|
1199
|
+
(top, left, scale, this.id, this.oldScale_);
|
|
1298
1200
|
this.oldScale_ = scale;
|
|
1299
1201
|
this.oldTop_ = top;
|
|
1300
1202
|
this.oldLeft_ = left;
|
|
@@ -1303,12 +1205,12 @@ class WorkspaceSvg extends Workspace {
|
|
|
1303
1205
|
|
|
1304
1206
|
/**
|
|
1305
1207
|
* Translate this workspace to new coordinates.
|
|
1306
|
-
* @param
|
|
1307
|
-
*
|
|
1308
|
-
* @param
|
|
1309
|
-
*
|
|
1208
|
+
* @param x Horizontal translation, in pixel units relative to the top left of
|
|
1209
|
+
* the Blockly div.
|
|
1210
|
+
* @param y Vertical translation, in pixel units relative to the top left of
|
|
1211
|
+
* the Blockly div.
|
|
1310
1212
|
*/
|
|
1311
|
-
translate(x, y) {
|
|
1213
|
+
translate(x: number, y: number) {
|
|
1312
1214
|
if (this.useWorkspaceDragSurface_ && this.isDragSurfaceActive_) {
|
|
1313
1215
|
this.workspaceDragSurface_.translateSurface(x, y);
|
|
1314
1216
|
} else {
|
|
@@ -1333,7 +1235,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1333
1235
|
* Called at the end of a workspace drag to take the contents
|
|
1334
1236
|
* out of the drag surface and put them back into the workspace SVG.
|
|
1335
1237
|
* Does nothing if the workspace drag surface is not enabled.
|
|
1336
|
-
* @
|
|
1238
|
+
* @internal
|
|
1337
1239
|
*/
|
|
1338
1240
|
resetDragSurface() {
|
|
1339
1241
|
// Don't do anything if we aren't using a drag surface.
|
|
@@ -1355,7 +1257,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1355
1257
|
* Called at the beginning of a workspace drag to move contents of
|
|
1356
1258
|
* the workspace to the drag surface.
|
|
1357
1259
|
* Does nothing if the drag surface is not enabled.
|
|
1358
|
-
* @
|
|
1260
|
+
* @internal
|
|
1359
1261
|
*/
|
|
1360
1262
|
setupDragSurface() {
|
|
1361
1263
|
// Don't do anything if we aren't using a drag surface.
|
|
@@ -1376,10 +1278,15 @@ class WorkspaceSvg extends Workspace {
|
|
|
1376
1278
|
|
|
1377
1279
|
// Figure out where we want to put the canvas back. The order
|
|
1378
1280
|
// in the is important because things are layered.
|
|
1379
|
-
const previousElement =
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
const
|
|
1281
|
+
const previousElement = this.svgBlockCanvas_.previousSibling as Element;
|
|
1282
|
+
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
1283
|
+
// assignable to parameter of type 'string'.
|
|
1284
|
+
const width = parseInt(
|
|
1285
|
+
this.getParentSvg().getAttribute('width') as AnyDuringMigration, 10);
|
|
1286
|
+
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
1287
|
+
// assignable to parameter of type 'string'.
|
|
1288
|
+
const height = parseInt(
|
|
1289
|
+
this.getParentSvg().getAttribute('height') as AnyDuringMigration, 10);
|
|
1383
1290
|
const coord = svgMath.getRelativeXY(this.getCanvas());
|
|
1384
1291
|
this.workspaceDragSurface_.setContentsAndShow(
|
|
1385
1292
|
this.getCanvas(), this.getBubbleCanvas(), previousElement, width,
|
|
@@ -1389,20 +1296,19 @@ class WorkspaceSvg extends Workspace {
|
|
|
1389
1296
|
|
|
1390
1297
|
/**
|
|
1391
1298
|
* Gets the drag surface blocks are moved to when a drag is started.
|
|
1392
|
-
* @return
|
|
1393
|
-
*
|
|
1394
|
-
* @package
|
|
1299
|
+
* @return This workspace's block drag surface, if one is in use.
|
|
1300
|
+
* @internal
|
|
1395
1301
|
*/
|
|
1396
|
-
getBlockDragSurface() {
|
|
1302
|
+
getBlockDragSurface(): BlockDragSurfaceSvg|null {
|
|
1397
1303
|
return this.blockDragSurface_;
|
|
1398
1304
|
}
|
|
1399
1305
|
|
|
1400
1306
|
/**
|
|
1401
1307
|
* Returns the horizontal offset of the workspace.
|
|
1402
1308
|
* Intended for LTR/RTL compatibility in XML.
|
|
1403
|
-
* @return
|
|
1309
|
+
* @return Width.
|
|
1404
1310
|
*/
|
|
1405
|
-
getWidth() {
|
|
1311
|
+
override getWidth(): number {
|
|
1406
1312
|
const metrics = this.getMetrics();
|
|
1407
1313
|
return metrics ? metrics.viewWidth / this.scale : 0;
|
|
1408
1314
|
}
|
|
@@ -1410,9 +1316,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
1410
1316
|
/**
|
|
1411
1317
|
* Toggles the visibility of the workspace.
|
|
1412
1318
|
* Currently only intended for main workspace.
|
|
1413
|
-
* @param
|
|
1319
|
+
* @param isVisible True if workspace should be visible.
|
|
1414
1320
|
*/
|
|
1415
|
-
setVisible(isVisible) {
|
|
1321
|
+
setVisible(isVisible: boolean) {
|
|
1416
1322
|
this.isVisible_ = isVisible;
|
|
1417
1323
|
if (!this.svgGroup_) {
|
|
1418
1324
|
return;
|
|
@@ -1427,7 +1333,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1427
1333
|
// Tell the flyout whether its container is visible so it can
|
|
1428
1334
|
// tell when to hide itself.
|
|
1429
1335
|
if (this.getFlyout()) {
|
|
1430
|
-
this.getFlyout()
|
|
1336
|
+
this.getFlyout()!.setContainerVisible(isVisible);
|
|
1431
1337
|
}
|
|
1432
1338
|
|
|
1433
1339
|
this.getParentSvg().style.display = isVisible ? 'block' : 'none';
|
|
@@ -1451,9 +1357,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1451
1357
|
}
|
|
1452
1358
|
}
|
|
1453
1359
|
|
|
1454
|
-
/**
|
|
1455
|
-
* Render all blocks in workspace.
|
|
1456
|
-
*/
|
|
1360
|
+
/** Render all blocks in workspace. */
|
|
1457
1361
|
render() {
|
|
1458
1362
|
// Generate list of all blocks.
|
|
1459
1363
|
const blocks = this.getAllBlocks(false);
|
|
@@ -1475,16 +1379,16 @@ class WorkspaceSvg extends Workspace {
|
|
|
1475
1379
|
/**
|
|
1476
1380
|
* Highlight or unhighlight a block in the workspace. Block highlighting is
|
|
1477
1381
|
* often used to visually mark blocks currently being executed.
|
|
1478
|
-
* @param
|
|
1479
|
-
*
|
|
1480
|
-
* @param
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1382
|
+
* @param id ID of block to highlight/unhighlight, or null for no block (used
|
|
1383
|
+
* to unhighlight all blocks).
|
|
1384
|
+
* @param opt_state If undefined, highlight specified block and automatically
|
|
1385
|
+
* unhighlight all others. If true or false, manually
|
|
1386
|
+
* highlight/unhighlight the specified block.
|
|
1483
1387
|
*/
|
|
1484
|
-
highlightBlock(id, opt_state) {
|
|
1388
|
+
highlightBlock(id: string|null, opt_state?: boolean) {
|
|
1485
1389
|
if (opt_state === undefined) {
|
|
1486
1390
|
// Unhighlight all blocks.
|
|
1487
|
-
for (let i = 0, block;
|
|
1391
|
+
for (let i = 0, block; block = this.highlightedBlocks_[i]; i++) {
|
|
1488
1392
|
block.setHighlighted(false);
|
|
1489
1393
|
}
|
|
1490
1394
|
this.highlightedBlocks_.length = 0;
|
|
@@ -1492,7 +1396,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1492
1396
|
// Highlight/unhighlight the specified block.
|
|
1493
1397
|
const block = id ? this.getBlockById(id) : null;
|
|
1494
1398
|
if (block) {
|
|
1495
|
-
const state =
|
|
1399
|
+
const state = opt_state === undefined || opt_state;
|
|
1496
1400
|
// Using Set here would be great, but at the cost of IE10 support.
|
|
1497
1401
|
if (!state) {
|
|
1498
1402
|
arrayUtils.removeElem(this.highlightedBlocks_, block);
|
|
@@ -1507,17 +1411,15 @@ class WorkspaceSvg extends Workspace {
|
|
|
1507
1411
|
* Pastes the provided block or workspace comment onto the workspace.
|
|
1508
1412
|
* Does not check whether there is remaining capacity for the object, that
|
|
1509
1413
|
* should be done before calling this method.
|
|
1510
|
-
* @param
|
|
1511
|
-
*
|
|
1512
|
-
* @return {!ICopyable|null} The pasted thing, or null if
|
|
1513
|
-
* the paste was not successful.
|
|
1414
|
+
* @param state The representation of the thing to paste.
|
|
1415
|
+
* @return The pasted thing, or null if the paste was not successful.
|
|
1514
1416
|
*/
|
|
1515
|
-
paste(state) {
|
|
1516
|
-
if (!this.rendered || !state['type'] && !state
|
|
1417
|
+
paste(state: AnyDuringMigration|Element|DocumentFragment): ICopyable|null {
|
|
1418
|
+
if (!this.rendered || !state['type'] && !state['tagName']) {
|
|
1517
1419
|
return null;
|
|
1518
1420
|
}
|
|
1519
|
-
if (this.currentGesture_) {
|
|
1520
|
-
this.currentGesture_.cancel();
|
|
1421
|
+
if (this.currentGesture_) { // Dragging while pasting? No.
|
|
1422
|
+
this.currentGesture_.cancel();
|
|
1521
1423
|
}
|
|
1522
1424
|
|
|
1523
1425
|
const existingGroup = eventUtils.getGroup();
|
|
@@ -1528,10 +1430,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
1528
1430
|
let pastedThing;
|
|
1529
1431
|
// Checks if this is JSON. JSON has a type property, while elements don't.
|
|
1530
1432
|
if (state['type']) {
|
|
1531
|
-
pastedThing =
|
|
1532
|
-
this.pasteBlock_(null, /** @type {!blocks.State} */ (state));
|
|
1433
|
+
pastedThing = this.pasteBlock_(null, state as blocks.State);
|
|
1533
1434
|
} else {
|
|
1534
|
-
const xmlBlock =
|
|
1435
|
+
const xmlBlock = state as Element;
|
|
1535
1436
|
if (xmlBlock.tagName.toLowerCase() === 'comment') {
|
|
1536
1437
|
pastedThing = this.pasteWorkspaceComment_(xmlBlock);
|
|
1537
1438
|
} else {
|
|
@@ -1545,27 +1446,36 @@ class WorkspaceSvg extends Workspace {
|
|
|
1545
1446
|
|
|
1546
1447
|
/**
|
|
1547
1448
|
* Paste the provided block onto the workspace.
|
|
1548
|
-
* @param
|
|
1549
|
-
* @param
|
|
1550
|
-
*
|
|
1551
|
-
* @return {!BlockSvg} The pasted block.
|
|
1552
|
-
* @private
|
|
1449
|
+
* @param xmlBlock XML block element.
|
|
1450
|
+
* @param jsonBlock JSON block representation.
|
|
1451
|
+
* @return The pasted block.
|
|
1553
1452
|
*/
|
|
1554
|
-
pasteBlock_(xmlBlock, jsonBlock)
|
|
1453
|
+
private pasteBlock_(xmlBlock: Element|null, jsonBlock: blocks.State|null):
|
|
1454
|
+
BlockSvg {
|
|
1555
1455
|
eventUtils.disable();
|
|
1556
|
-
let block;
|
|
1456
|
+
let block: BlockSvg;
|
|
1557
1457
|
try {
|
|
1558
1458
|
let blockX = 0;
|
|
1559
1459
|
let blockY = 0;
|
|
1560
1460
|
if (xmlBlock) {
|
|
1561
|
-
|
|
1562
|
-
|
|
1461
|
+
// AnyDuringMigration because: Argument of type 'this' is not
|
|
1462
|
+
// assignable to parameter of type 'Workspace'.
|
|
1463
|
+
block =
|
|
1464
|
+
Xml.domToBlock(xmlBlock, this as AnyDuringMigration) as BlockSvg;
|
|
1465
|
+
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
1466
|
+
// assignable to parameter of type 'string'.
|
|
1467
|
+
blockX = parseInt(xmlBlock.getAttribute('x') as AnyDuringMigration, 10);
|
|
1563
1468
|
if (this.RTL) {
|
|
1564
1469
|
blockX = -blockX;
|
|
1565
1470
|
}
|
|
1566
|
-
|
|
1471
|
+
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
1472
|
+
// assignable to parameter of type 'string'.
|
|
1473
|
+
blockY = parseInt(xmlBlock.getAttribute('y') as AnyDuringMigration, 10);
|
|
1567
1474
|
} else if (jsonBlock) {
|
|
1568
|
-
|
|
1475
|
+
// AnyDuringMigration because: Argument of type 'this' is not
|
|
1476
|
+
// assignable to parameter of type 'Workspace'.
|
|
1477
|
+
block =
|
|
1478
|
+
blocks.append(jsonBlock, this as AnyDuringMigration) as BlockSvg;
|
|
1569
1479
|
blockX = jsonBlock['x'] || 10;
|
|
1570
1480
|
if (this.RTL) {
|
|
1571
1481
|
blockX = this.getWidth() - blockX;
|
|
@@ -1581,7 +1491,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1581
1491
|
do {
|
|
1582
1492
|
collide = false;
|
|
1583
1493
|
const allBlocks = this.getAllBlocks(false);
|
|
1584
|
-
for (let i = 0, otherBlock;
|
|
1494
|
+
for (let i = 0, otherBlock; otherBlock = allBlocks[i]; i++) {
|
|
1585
1495
|
const otherXY = otherBlock.getRelativeToSurfaceXY();
|
|
1586
1496
|
if (Math.abs(blockX - otherXY.x) <= 1 &&
|
|
1587
1497
|
Math.abs(blockY - otherXY.y) <= 1) {
|
|
@@ -1591,10 +1501,10 @@ class WorkspaceSvg extends Workspace {
|
|
|
1591
1501
|
}
|
|
1592
1502
|
if (!collide) {
|
|
1593
1503
|
// Check for blocks in snap range to any of its connections.
|
|
1594
|
-
const connections = block
|
|
1595
|
-
for (let i = 0, connection;
|
|
1504
|
+
const connections = block!.getConnections_(false);
|
|
1505
|
+
for (let i = 0, connection; connection = connections[i]; i++) {
|
|
1596
1506
|
const neighbour =
|
|
1597
|
-
|
|
1507
|
+
(connection)
|
|
1598
1508
|
.closest(
|
|
1599
1509
|
config.snapRadius, new Coordinate(blockX, blockY));
|
|
1600
1510
|
if (neighbour.connection) {
|
|
@@ -1612,35 +1522,42 @@ class WorkspaceSvg extends Workspace {
|
|
|
1612
1522
|
blockY += config.snapRadius * 2;
|
|
1613
1523
|
}
|
|
1614
1524
|
} while (collide);
|
|
1615
|
-
block
|
|
1525
|
+
block!.moveTo(new Coordinate(blockX, blockY));
|
|
1616
1526
|
}
|
|
1617
1527
|
} finally {
|
|
1618
1528
|
eventUtils.enable();
|
|
1619
1529
|
}
|
|
1620
|
-
if (eventUtils.isEnabled() && !block
|
|
1621
|
-
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(block));
|
|
1530
|
+
if (eventUtils.isEnabled() && !block!.isShadow()) {
|
|
1531
|
+
eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))!(block!));
|
|
1622
1532
|
}
|
|
1623
|
-
block
|
|
1624
|
-
return block
|
|
1533
|
+
block!.select();
|
|
1534
|
+
return block!;
|
|
1625
1535
|
}
|
|
1626
1536
|
|
|
1627
1537
|
/**
|
|
1628
1538
|
* Paste the provided comment onto the workspace.
|
|
1629
|
-
* @param
|
|
1630
|
-
* @return
|
|
1631
|
-
* @private
|
|
1539
|
+
* @param xmlComment XML workspace comment element.
|
|
1540
|
+
* @return The pasted workspace comment.
|
|
1632
1541
|
* @suppress {checkTypes} Suppress checks while workspace comments are not
|
|
1633
|
-
*
|
|
1542
|
+
* bundled in.
|
|
1634
1543
|
*/
|
|
1635
|
-
pasteWorkspaceComment_(xmlComment) {
|
|
1544
|
+
private pasteWorkspaceComment_(xmlComment: Element): WorkspaceCommentSvg {
|
|
1636
1545
|
eventUtils.disable();
|
|
1637
|
-
let comment;
|
|
1546
|
+
let comment: WorkspaceCommentSvg;
|
|
1638
1547
|
try {
|
|
1639
|
-
|
|
1640
|
-
|
|
1548
|
+
// AnyDuringMigration because: Property 'get' does not exist on type
|
|
1549
|
+
// '(name: string) => void'.
|
|
1550
|
+
comment =
|
|
1551
|
+
WorkspaceCommentSvg.fromXml(xmlComment, this) as AnyDuringMigration;
|
|
1641
1552
|
// Move the duplicate to original position.
|
|
1642
|
-
|
|
1643
|
-
|
|
1553
|
+
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
1554
|
+
// assignable to parameter of type 'string'.
|
|
1555
|
+
let commentX =
|
|
1556
|
+
parseInt(xmlComment.getAttribute('x') as AnyDuringMigration, 10);
|
|
1557
|
+
// AnyDuringMigration because: Argument of type 'string | null' is not
|
|
1558
|
+
// assignable to parameter of type 'string'.
|
|
1559
|
+
let commentY =
|
|
1560
|
+
parseInt(xmlComment.getAttribute('y') as AnyDuringMigration, 10);
|
|
1644
1561
|
if (!isNaN(commentX) && !isNaN(commentY)) {
|
|
1645
1562
|
if (this.RTL) {
|
|
1646
1563
|
commentX = -commentX;
|
|
@@ -1656,7 +1573,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
1656
1573
|
eventUtils.enable();
|
|
1657
1574
|
}
|
|
1658
1575
|
if (eventUtils.isEnabled()) {
|
|
1659
|
-
|
|
1576
|
+
// AnyDuringMigration because: Property 'get' does not exist on type
|
|
1577
|
+
// '(name: string) => void'.
|
|
1578
|
+
WorkspaceComment.fireCreateEvent(comment);
|
|
1660
1579
|
}
|
|
1661
1580
|
comment.select();
|
|
1662
1581
|
return comment;
|
|
@@ -1664,7 +1583,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
1664
1583
|
|
|
1665
1584
|
/**
|
|
1666
1585
|
* Refresh the toolbox unless there's a drag in progress.
|
|
1667
|
-
* @
|
|
1586
|
+
* @internal
|
|
1668
1587
|
*/
|
|
1669
1588
|
refreshToolboxSelection() {
|
|
1670
1589
|
const ws = this.isFlyout ? this.targetWorkspace : this;
|
|
@@ -1676,10 +1595,10 @@ class WorkspaceSvg extends Workspace {
|
|
|
1676
1595
|
/**
|
|
1677
1596
|
* Rename a variable by updating its name in the variable map. Update the
|
|
1678
1597
|
* flyout to show the renamed variable immediately.
|
|
1679
|
-
* @param
|
|
1680
|
-
* @param
|
|
1598
|
+
* @param id ID of the variable to rename.
|
|
1599
|
+
* @param newName New variable name.
|
|
1681
1600
|
*/
|
|
1682
|
-
renameVariableById(id, newName) {
|
|
1601
|
+
override renameVariableById(id: string, newName: string) {
|
|
1683
1602
|
super.renameVariableById(id, newName);
|
|
1684
1603
|
this.refreshToolboxSelection();
|
|
1685
1604
|
}
|
|
@@ -1687,9 +1606,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
1687
1606
|
/**
|
|
1688
1607
|
* Delete a variable by the passed in ID. Update the flyout to show
|
|
1689
1608
|
* immediately that the variable is deleted.
|
|
1690
|
-
* @param
|
|
1609
|
+
* @param id ID of variable to delete.
|
|
1691
1610
|
*/
|
|
1692
|
-
deleteVariableById(id) {
|
|
1611
|
+
override deleteVariableById(id: string) {
|
|
1693
1612
|
super.deleteVariableById(id);
|
|
1694
1613
|
this.refreshToolboxSelection();
|
|
1695
1614
|
}
|
|
@@ -1697,15 +1616,16 @@ class WorkspaceSvg extends Workspace {
|
|
|
1697
1616
|
/**
|
|
1698
1617
|
* Create a new variable with the given name. Update the flyout to show the
|
|
1699
1618
|
* new variable immediately.
|
|
1700
|
-
* @param
|
|
1701
|
-
* @param
|
|
1619
|
+
* @param name The new variable's name.
|
|
1620
|
+
* @param opt_type The type of the variable like 'int' or 'string'.
|
|
1702
1621
|
* Does not need to be unique. Field_variable can filter variables based
|
|
1703
1622
|
* on their type. This will default to '' which is a specific type.
|
|
1704
|
-
* @param
|
|
1705
|
-
*
|
|
1706
|
-
* @return {!VariableModel} The newly created variable.
|
|
1623
|
+
* @param opt_id The unique ID of the variable. This will default to a UUID.
|
|
1624
|
+
* @return The newly created variable.
|
|
1707
1625
|
*/
|
|
1708
|
-
createVariable(
|
|
1626
|
+
override createVariable(
|
|
1627
|
+
name: string, opt_type?: string|null,
|
|
1628
|
+
opt_id?: string|null): VariableModel {
|
|
1709
1629
|
const newVar = super.createVariable(name, opt_type, opt_id);
|
|
1710
1630
|
this.refreshToolboxSelection();
|
|
1711
1631
|
return newVar;
|
|
@@ -1716,21 +1636,22 @@ class WorkspaceSvg extends Workspace {
|
|
|
1716
1636
|
* @deprecated Use workspace.recordDragTargets. (2021 June)
|
|
1717
1637
|
*/
|
|
1718
1638
|
recordDeleteAreas() {
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1639
|
+
// AnyDuringMigration because: Property 'warn' does not exist on type
|
|
1640
|
+
// 'void'.
|
|
1641
|
+
(utils.deprecation as AnyDuringMigration)
|
|
1642
|
+
.warn(
|
|
1643
|
+
'WorkspaceSvg.prototype.recordDeleteAreas', 'June 2021',
|
|
1644
|
+
'June 2022', 'WorkspaceSvg.prototype.recordDragTargets');
|
|
1722
1645
|
this.recordDragTargets();
|
|
1723
1646
|
}
|
|
1724
1647
|
|
|
1725
|
-
/**
|
|
1726
|
-
* Make a list of all the delete areas for this workspace.
|
|
1727
|
-
*/
|
|
1648
|
+
/** Make a list of all the delete areas for this workspace. */
|
|
1728
1649
|
recordDragTargets() {
|
|
1729
1650
|
const dragTargets = this.componentManager_.getComponents(
|
|
1730
1651
|
ComponentManager.Capability.DRAG_TARGET, true);
|
|
1731
1652
|
|
|
1732
1653
|
this.dragTargetAreas_ = [];
|
|
1733
|
-
for (let i = 0, targetArea;
|
|
1654
|
+
for (let i = 0, targetArea; targetArea = dragTargets[i]; i++) {
|
|
1734
1655
|
const rect = targetArea.getClientRect();
|
|
1735
1656
|
if (rect) {
|
|
1736
1657
|
this.dragTargetAreas_.push({
|
|
@@ -1742,14 +1663,33 @@ class WorkspaceSvg extends Workspace {
|
|
|
1742
1663
|
}
|
|
1743
1664
|
|
|
1744
1665
|
/**
|
|
1745
|
-
*
|
|
1746
|
-
* @param
|
|
1747
|
-
*
|
|
1748
|
-
*
|
|
1666
|
+
* Obtain a newly created block.
|
|
1667
|
+
* @param prototypeName Name of the language object containing type-specific
|
|
1668
|
+
* functions for this block.
|
|
1669
|
+
* @param opt_id Optional ID. Use this ID if provided, otherwise create a new
|
|
1670
|
+
* ID.
|
|
1671
|
+
* @return The created block.
|
|
1749
1672
|
*/
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1673
|
+
override newBlock(prototypeName: string, opt_id?: string): BlockSvg {
|
|
1674
|
+
throw new Error(
|
|
1675
|
+
'The implementation of newBlock should be ' +
|
|
1676
|
+
'monkey-patched in by blockly.ts');
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
/**
|
|
1680
|
+
* Returns the drag target the mouse event is over.
|
|
1681
|
+
* @param e Mouse move event.
|
|
1682
|
+
* @return Null if not over a drag target, or the drag target the event is
|
|
1683
|
+
* over.
|
|
1684
|
+
*/
|
|
1685
|
+
getDragTarget(e: Event): IDragTarget|null {
|
|
1686
|
+
for (let i = 0, targetArea; targetArea = this.dragTargetAreas_[i]; i++) {
|
|
1687
|
+
// AnyDuringMigration because: Property 'clientY' does not exist on
|
|
1688
|
+
// type 'Event'. AnyDuringMigration because: Property 'clientX' does
|
|
1689
|
+
// not exist on type 'Event'.
|
|
1690
|
+
if (targetArea.clientRect.contains(
|
|
1691
|
+
(e as AnyDuringMigration).clientX,
|
|
1692
|
+
(e as AnyDuringMigration).clientY)) {
|
|
1753
1693
|
return targetArea.component;
|
|
1754
1694
|
}
|
|
1755
1695
|
}
|
|
@@ -1758,10 +1698,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
1758
1698
|
|
|
1759
1699
|
/**
|
|
1760
1700
|
* Handle a mouse-down on SVG drawing surface.
|
|
1761
|
-
* @param
|
|
1762
|
-
* @private
|
|
1701
|
+
* @param e Mouse down event.
|
|
1763
1702
|
*/
|
|
1764
|
-
onMouseDown_(e) {
|
|
1703
|
+
private onMouseDown_(e: MouseEvent) {
|
|
1765
1704
|
const gesture = this.getGesture(e);
|
|
1766
1705
|
if (gesture) {
|
|
1767
1706
|
gesture.handleWsStart(e, this);
|
|
@@ -1770,10 +1709,10 @@ class WorkspaceSvg extends Workspace {
|
|
|
1770
1709
|
|
|
1771
1710
|
/**
|
|
1772
1711
|
* Start tracking a drag of an object on this workspace.
|
|
1773
|
-
* @param
|
|
1774
|
-
* @param
|
|
1712
|
+
* @param e Mouse down event.
|
|
1713
|
+
* @param xy Starting location of object.
|
|
1775
1714
|
*/
|
|
1776
|
-
startDrag(e, xy) {
|
|
1715
|
+
startDrag(e: MouseEvent, xy: Coordinate) {
|
|
1777
1716
|
// Record the starting offset between the bubble's location and the mouse.
|
|
1778
1717
|
const point = browserEvents.mouseToSvg(
|
|
1779
1718
|
e, this.getParentSvg(), this.getInverseScreenCTM());
|
|
@@ -1785,32 +1724,31 @@ class WorkspaceSvg extends Workspace {
|
|
|
1785
1724
|
|
|
1786
1725
|
/**
|
|
1787
1726
|
* Track a drag of an object on this workspace.
|
|
1788
|
-
* @param
|
|
1789
|
-
* @return
|
|
1727
|
+
* @param e Mouse move event.
|
|
1728
|
+
* @return New location of object.
|
|
1790
1729
|
*/
|
|
1791
|
-
moveDrag(e) {
|
|
1730
|
+
moveDrag(e: MouseEvent): Coordinate {
|
|
1792
1731
|
const point = browserEvents.mouseToSvg(
|
|
1793
1732
|
e, this.getParentSvg(), this.getInverseScreenCTM());
|
|
1794
1733
|
// Fix scale of mouse event.
|
|
1795
1734
|
point.x /= this.scale;
|
|
1796
1735
|
point.y /= this.scale;
|
|
1797
|
-
return Coordinate.sum(
|
|
1798
|
-
/** @type {!Coordinate} */ (this.dragDeltaXY_), point);
|
|
1736
|
+
return Coordinate.sum((this.dragDeltaXY_), point);
|
|
1799
1737
|
}
|
|
1800
1738
|
|
|
1801
1739
|
/**
|
|
1802
1740
|
* Is the user currently dragging a block or scrolling the flyout/workspace?
|
|
1803
|
-
* @return
|
|
1741
|
+
* @return True if currently dragging or scrolling.
|
|
1804
1742
|
*/
|
|
1805
|
-
isDragging() {
|
|
1743
|
+
isDragging(): boolean {
|
|
1806
1744
|
return this.currentGesture_ !== null && this.currentGesture_.isDragging();
|
|
1807
1745
|
}
|
|
1808
1746
|
|
|
1809
1747
|
/**
|
|
1810
1748
|
* Is this workspace draggable?
|
|
1811
|
-
* @return
|
|
1749
|
+
* @return True if this workspace may be dragged.
|
|
1812
1750
|
*/
|
|
1813
|
-
isDraggable() {
|
|
1751
|
+
isDraggable(): boolean {
|
|
1814
1752
|
return this.options.moveOptions && this.options.moveOptions.drag;
|
|
1815
1753
|
}
|
|
1816
1754
|
|
|
@@ -1822,47 +1760,43 @@ class WorkspaceSvg extends Workspace {
|
|
|
1822
1760
|
* through zooming with the scroll wheel or pinch (since the zoom is centered
|
|
1823
1761
|
* on the mouse position). This does not include zooming with the zoom
|
|
1824
1762
|
* controls since the X Y coordinates are decided programmatically.
|
|
1825
|
-
* @return
|
|
1763
|
+
* @return True if the workspace is movable, false otherwise.
|
|
1826
1764
|
*/
|
|
1827
|
-
isMovable() {
|
|
1828
|
-
return
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
(this.options.zoomOptions && this.options.zoomOptions.pinch);
|
|
1765
|
+
isMovable(): boolean {
|
|
1766
|
+
return this.options.moveOptions && !!this.options.moveOptions.scrollbars ||
|
|
1767
|
+
this.options.moveOptions && this.options.moveOptions.wheel ||
|
|
1768
|
+
this.options.moveOptions && this.options.moveOptions.drag ||
|
|
1769
|
+
this.options.zoomOptions && this.options.zoomOptions.wheel ||
|
|
1770
|
+
this.options.zoomOptions && this.options.zoomOptions.pinch;
|
|
1834
1771
|
}
|
|
1835
1772
|
|
|
1836
1773
|
/**
|
|
1837
1774
|
* Is this workspace movable horizontally?
|
|
1838
|
-
* @return
|
|
1839
|
-
* otherwise.
|
|
1775
|
+
* @return True if the workspace is movable horizontally, false otherwise.
|
|
1840
1776
|
*/
|
|
1841
|
-
isMovableHorizontally() {
|
|
1777
|
+
isMovableHorizontally(): boolean {
|
|
1842
1778
|
const hasScrollbars = !!this.scrollbar;
|
|
1843
1779
|
return this.isMovable() &&
|
|
1844
1780
|
(!hasScrollbars ||
|
|
1845
|
-
|
|
1781
|
+
hasScrollbars && this.scrollbar.canScrollHorizontally());
|
|
1846
1782
|
}
|
|
1847
1783
|
|
|
1848
1784
|
/**
|
|
1849
1785
|
* Is this workspace movable vertically?
|
|
1850
|
-
* @return
|
|
1851
|
-
* otherwise.
|
|
1786
|
+
* @return True if the workspace is movable vertically, false otherwise.
|
|
1852
1787
|
*/
|
|
1853
|
-
isMovableVertically() {
|
|
1788
|
+
isMovableVertically(): boolean {
|
|
1854
1789
|
const hasScrollbars = !!this.scrollbar;
|
|
1855
1790
|
return this.isMovable() &&
|
|
1856
1791
|
(!hasScrollbars ||
|
|
1857
|
-
|
|
1792
|
+
hasScrollbars && this.scrollbar.canScrollVertically());
|
|
1858
1793
|
}
|
|
1859
1794
|
|
|
1860
1795
|
/**
|
|
1861
1796
|
* Handle a mouse-wheel on SVG drawing surface.
|
|
1862
|
-
* @param
|
|
1863
|
-
* @private
|
|
1797
|
+
* @param e Mouse wheel event.
|
|
1864
1798
|
*/
|
|
1865
|
-
onMouseWheel_(e) {
|
|
1799
|
+
private onMouseWheel_(e: WheelEvent) {
|
|
1866
1800
|
// Don't scroll or zoom anything if drag is in progress.
|
|
1867
1801
|
if (Gesture.inProgress()) {
|
|
1868
1802
|
e.preventDefault();
|
|
@@ -1916,10 +1850,10 @@ class WorkspaceSvg extends Workspace {
|
|
|
1916
1850
|
* Calculate the bounding box for the blocks on the workspace.
|
|
1917
1851
|
* Coordinate system: workspace coordinates.
|
|
1918
1852
|
*
|
|
1919
|
-
* @return
|
|
1920
|
-
*
|
|
1853
|
+
* @return Contains the position and size of the bounding box containing the
|
|
1854
|
+
* blocks on the workspace.
|
|
1921
1855
|
*/
|
|
1922
|
-
getBlocksBoundingBox() {
|
|
1856
|
+
getBlocksBoundingBox(): Rect {
|
|
1923
1857
|
const topElements = this.getTopBoundedElements();
|
|
1924
1858
|
// There are no blocks, return empty rectangle.
|
|
1925
1859
|
if (!topElements.length) {
|
|
@@ -1932,7 +1866,8 @@ class WorkspaceSvg extends Workspace {
|
|
|
1932
1866
|
// Start at 1 since the 0th block was used for initialization.
|
|
1933
1867
|
for (let i = 1; i < topElements.length; i++) {
|
|
1934
1868
|
const topElement = topElements[i];
|
|
1935
|
-
if (topElement
|
|
1869
|
+
if ((topElement as AnyDuringMigration).isInsertionmarker &&
|
|
1870
|
+
(topElement as AnyDuringMigration).isInsertionMarker()) {
|
|
1936
1871
|
continue;
|
|
1937
1872
|
}
|
|
1938
1873
|
const blockBoundary = topElement.getBoundingRectangle();
|
|
@@ -1952,15 +1887,13 @@ class WorkspaceSvg extends Workspace {
|
|
|
1952
1887
|
return boundary;
|
|
1953
1888
|
}
|
|
1954
1889
|
|
|
1955
|
-
/**
|
|
1956
|
-
* Clean up the workspace by ordering all the blocks in a column.
|
|
1957
|
-
*/
|
|
1890
|
+
/** Clean up the workspace by ordering all the blocks in a column. */
|
|
1958
1891
|
cleanUp() {
|
|
1959
1892
|
this.setResizesEnabled(false);
|
|
1960
1893
|
eventUtils.setGroup(true);
|
|
1961
1894
|
const topBlocks = this.getTopBlocks(true);
|
|
1962
1895
|
let cursorY = 0;
|
|
1963
|
-
for (let i = 0, block;
|
|
1896
|
+
for (let i = 0, block; block = topBlocks[i]; i++) {
|
|
1964
1897
|
if (!block.isMovable()) {
|
|
1965
1898
|
continue;
|
|
1966
1899
|
}
|
|
@@ -1977,15 +1910,18 @@ class WorkspaceSvg extends Workspace {
|
|
|
1977
1910
|
|
|
1978
1911
|
/**
|
|
1979
1912
|
* Show the context menu for the workspace.
|
|
1980
|
-
* @param
|
|
1981
|
-
* @
|
|
1913
|
+
* @param e Mouse event.
|
|
1914
|
+
* @internal
|
|
1982
1915
|
*/
|
|
1983
|
-
showContextMenu(e) {
|
|
1916
|
+
showContextMenu(e: Event) {
|
|
1984
1917
|
if (this.options.readOnly || this.isFlyout) {
|
|
1985
1918
|
return;
|
|
1986
1919
|
}
|
|
1920
|
+
// AnyDuringMigration because: Argument of type '{ workspace: this; }' is
|
|
1921
|
+
// not assignable to parameter of type 'Scope'.
|
|
1987
1922
|
const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions(
|
|
1988
|
-
ContextMenuRegistry.ScopeType.WORKSPACE,
|
|
1923
|
+
ContextMenuRegistry.ScopeType.WORKSPACE,
|
|
1924
|
+
{workspace: this} as AnyDuringMigration);
|
|
1989
1925
|
|
|
1990
1926
|
// Allow the developer to add or modify menuOptions.
|
|
1991
1927
|
if (this.configureContextMenu) {
|
|
@@ -1997,11 +1933,10 @@ class WorkspaceSvg extends Workspace {
|
|
|
1997
1933
|
|
|
1998
1934
|
/**
|
|
1999
1935
|
* Modify the block tree on the existing toolbox.
|
|
2000
|
-
* @param
|
|
2001
|
-
*
|
|
2002
|
-
* representing toolbox definition.
|
|
1936
|
+
* @param toolboxDef DOM tree of toolbox contents, string of toolbox contents,
|
|
1937
|
+
* or JSON representing toolbox definition.
|
|
2003
1938
|
*/
|
|
2004
|
-
updateToolbox(toolboxDef) {
|
|
1939
|
+
updateToolbox(toolboxDef: toolbox.ToolboxDefinition|null) {
|
|
2005
1940
|
const parsedToolboxDef = toolbox.convertToolboxDefToJson(toolboxDef);
|
|
2006
1941
|
|
|
2007
1942
|
if (!parsedToolboxDef) {
|
|
@@ -2029,14 +1964,14 @@ class WorkspaceSvg extends Workspace {
|
|
|
2029
1964
|
}
|
|
2030
1965
|
}
|
|
2031
1966
|
|
|
2032
|
-
/**
|
|
2033
|
-
* Mark this workspace as the currently focused main workspace.
|
|
2034
|
-
*/
|
|
1967
|
+
/** Mark this workspace as the currently focused main workspace. */
|
|
2035
1968
|
markFocused() {
|
|
2036
1969
|
if (this.options.parentWorkspace) {
|
|
2037
1970
|
this.options.parentWorkspace.markFocused();
|
|
2038
1971
|
} else {
|
|
2039
|
-
|
|
1972
|
+
// AnyDuringMigration because: Argument of type 'this' is not assignable
|
|
1973
|
+
// to parameter of type 'Workspace'.
|
|
1974
|
+
common.setMainWorkspace(this as AnyDuringMigration);
|
|
2040
1975
|
// We call e.preventDefault in many event handlers which means we
|
|
2041
1976
|
// need to explicitly grab focus (e.g from a textarea) because
|
|
2042
1977
|
// the browser will not do it for us. How to do this is browser
|
|
@@ -2045,18 +1980,20 @@ class WorkspaceSvg extends Workspace {
|
|
|
2045
1980
|
}
|
|
2046
1981
|
}
|
|
2047
1982
|
|
|
2048
|
-
/**
|
|
2049
|
-
|
|
2050
|
-
* @private
|
|
2051
|
-
*/
|
|
2052
|
-
setBrowserFocus() {
|
|
1983
|
+
/** Set the workspace to have focus in the browser. */
|
|
1984
|
+
private setBrowserFocus() {
|
|
2053
1985
|
// Blur whatever was focused since explicitly grabbing focus below does not
|
|
2054
1986
|
// work in Edge.
|
|
2055
1987
|
// In IE, SVGs can't be blurred or focused. Check to make sure the current
|
|
2056
1988
|
// focus can be blurred before doing so.
|
|
2057
1989
|
// See https://github.com/google/blockly/issues/4440
|
|
2058
|
-
|
|
2059
|
-
|
|
1990
|
+
// AnyDuringMigration because: Property 'blur' does not exist on type
|
|
1991
|
+
// 'Element'.
|
|
1992
|
+
if (document.activeElement &&
|
|
1993
|
+
(document.activeElement as AnyDuringMigration).blur) {
|
|
1994
|
+
// AnyDuringMigration because: Property 'blur' does not exist on type
|
|
1995
|
+
// 'Element'.
|
|
1996
|
+
(document.activeElement as AnyDuringMigration).blur();
|
|
2060
1997
|
}
|
|
2061
1998
|
try {
|
|
2062
1999
|
// Focus the workspace SVG - this is for Chrome and Firefox.
|
|
@@ -2068,11 +2005,11 @@ class WorkspaceSvg extends Workspace {
|
|
|
2068
2005
|
try {
|
|
2069
2006
|
// In IE11, use setActive (which is IE only) so the page doesn't scroll
|
|
2070
2007
|
// to the workspace gaining focus.
|
|
2071
|
-
this.getParentSvg().
|
|
2008
|
+
(this.getParentSvg().parentElement as AnyDuringMigration).setActive();
|
|
2072
2009
|
} catch (e) {
|
|
2073
2010
|
// setActive support was discontinued in Edge so when that fails, call
|
|
2074
2011
|
// focus instead.
|
|
2075
|
-
this.getParentSvg().
|
|
2012
|
+
this.getParentSvg().parentElement!.focus({preventScroll: true});
|
|
2076
2013
|
}
|
|
2077
2014
|
}
|
|
2078
2015
|
}
|
|
@@ -2080,16 +2017,16 @@ class WorkspaceSvg extends Workspace {
|
|
|
2080
2017
|
/**
|
|
2081
2018
|
* Zooms the workspace in or out relative to/centered on the given (x, y)
|
|
2082
2019
|
* coordinate.
|
|
2083
|
-
* @param
|
|
2084
|
-
*
|
|
2085
|
-
* @param
|
|
2086
|
-
*
|
|
2087
|
-
* @param
|
|
2088
|
-
*
|
|
2089
|
-
*
|
|
2090
|
-
*
|
|
2091
|
-
*/
|
|
2092
|
-
zoom(x, y, amount) {
|
|
2020
|
+
* @param x X coordinate of center, in pixel units relative to the top-left
|
|
2021
|
+
* corner of the parentSVG.
|
|
2022
|
+
* @param y Y coordinate of center, in pixel units relative to the top-left
|
|
2023
|
+
* corner of the parentSVG.
|
|
2024
|
+
* @param amount Amount of zooming. The formula for the new scale is newScale
|
|
2025
|
+
* = currentScale * (scaleSpeed^amount). scaleSpeed is set in the
|
|
2026
|
+
* workspace options. Negative amount values zoom out, and positive amount
|
|
2027
|
+
* values zoom in.
|
|
2028
|
+
*/
|
|
2029
|
+
zoom(x: number, y: number, amount: number) {
|
|
2093
2030
|
// Scale factor.
|
|
2094
2031
|
const speed = this.options.zoomOptions.scaleSpeed;
|
|
2095
2032
|
let scaleChange = Math.pow(speed, amount);
|
|
@@ -2109,17 +2046,17 @@ class WorkspaceSvg extends Workspace {
|
|
|
2109
2046
|
// canvas' space, so that they are in workspace units relative to the top
|
|
2110
2047
|
// left of the visible portion of the workspace.
|
|
2111
2048
|
let matrix = this.getCanvas().getCTM();
|
|
2112
|
-
let center = this.getParentSvg().createSVGPoint();
|
|
2049
|
+
let center = (this.getParentSvg()).createSVGPoint();
|
|
2113
2050
|
center.x = x;
|
|
2114
2051
|
center.y = y;
|
|
2115
|
-
center = center.matrixTransform(matrix
|
|
2052
|
+
center = center.matrixTransform(matrix!.inverse());
|
|
2116
2053
|
x = center.x;
|
|
2117
2054
|
y = center.y;
|
|
2118
2055
|
|
|
2119
2056
|
// Find the new scrollX/scrollY so that the center remains in the same
|
|
2120
2057
|
// position (relative to the center) after we zoom.
|
|
2121
2058
|
// newScale and matrix.a should be identical (within a rounding error).
|
|
2122
|
-
matrix = matrix
|
|
2059
|
+
matrix = matrix!.translate(x * (1 - scaleChange), y * (1 - scaleChange))
|
|
2123
2060
|
.scale(scaleChange);
|
|
2124
2061
|
// scrollX and scrollY are in pixels.
|
|
2125
2062
|
// The scrollX and scrollY still need to have absoluteLeft and absoluteTop
|
|
@@ -2132,9 +2069,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
2132
2069
|
|
|
2133
2070
|
/**
|
|
2134
2071
|
* Zooming the blocks centered in the center of view with zooming in or out.
|
|
2135
|
-
* @param
|
|
2072
|
+
* @param type Type of zooming (-1 zooming out and 1 zooming in).
|
|
2136
2073
|
*/
|
|
2137
|
-
zoomCenter(type) {
|
|
2074
|
+
zoomCenter(type: number) {
|
|
2138
2075
|
const metrics = this.getMetrics();
|
|
2139
2076
|
let x;
|
|
2140
2077
|
let y;
|
|
@@ -2147,15 +2084,13 @@ class WorkspaceSvg extends Workspace {
|
|
|
2147
2084
|
x = metrics.svgWidth ? metrics.svgWidth / 2 : 0;
|
|
2148
2085
|
y = metrics.svgHeight ? metrics.svgHeight / 2 : 0;
|
|
2149
2086
|
} else {
|
|
2150
|
-
x =
|
|
2151
|
-
y =
|
|
2087
|
+
x = metrics.viewWidth / 2 + metrics.absoluteLeft;
|
|
2088
|
+
y = metrics.viewHeight / 2 + metrics.absoluteTop;
|
|
2152
2089
|
}
|
|
2153
2090
|
this.zoom(x, y, type);
|
|
2154
2091
|
}
|
|
2155
2092
|
|
|
2156
|
-
/**
|
|
2157
|
-
* Zoom the blocks to fit in the workspace if possible.
|
|
2158
|
-
*/
|
|
2093
|
+
/** Zoom the blocks to fit in the workspace if possible. */
|
|
2159
2094
|
zoomToFit() {
|
|
2160
2095
|
if (!this.isMovable()) {
|
|
2161
2096
|
console.warn(
|
|
@@ -2168,8 +2103,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
2168
2103
|
let workspaceWidth = metrics.viewWidth;
|
|
2169
2104
|
let workspaceHeight = metrics.viewHeight;
|
|
2170
2105
|
const blocksBox = this.getBlocksBoundingBox();
|
|
2171
|
-
|
|
2172
|
-
let
|
|
2106
|
+
const doubleMargin = ZOOM_TO_FIT_MARGIN * 2;
|
|
2107
|
+
let blocksWidth = blocksBox.right - blocksBox.left + doubleMargin;
|
|
2108
|
+
let blocksHeight = blocksBox.bottom - blocksBox.top + doubleMargin;
|
|
2173
2109
|
if (!blocksWidth) {
|
|
2174
2110
|
return; // Prevents zooming to infinity.
|
|
2175
2111
|
}
|
|
@@ -2205,33 +2141,23 @@ class WorkspaceSvg extends Workspace {
|
|
|
2205
2141
|
/**
|
|
2206
2142
|
* Add a transition class to the block and bubble canvas, to animate any
|
|
2207
2143
|
* transform changes.
|
|
2208
|
-
* @
|
|
2144
|
+
* @internal
|
|
2209
2145
|
*/
|
|
2210
2146
|
beginCanvasTransition() {
|
|
2211
|
-
dom.addClass(
|
|
2212
|
-
|
|
2213
|
-
'blocklyCanvasTransitioning');
|
|
2214
|
-
dom.addClass(
|
|
2215
|
-
/** @type {!SVGElement} */ (this.svgBubbleCanvas_),
|
|
2216
|
-
'blocklyCanvasTransitioning');
|
|
2147
|
+
dom.addClass((this.svgBlockCanvas_), 'blocklyCanvasTransitioning');
|
|
2148
|
+
dom.addClass((this.svgBubbleCanvas_), 'blocklyCanvasTransitioning');
|
|
2217
2149
|
}
|
|
2218
2150
|
|
|
2219
2151
|
/**
|
|
2220
2152
|
* Remove transition class from the block and bubble canvas.
|
|
2221
|
-
* @
|
|
2153
|
+
* @internal
|
|
2222
2154
|
*/
|
|
2223
2155
|
endCanvasTransition() {
|
|
2224
|
-
dom.removeClass(
|
|
2225
|
-
|
|
2226
|
-
'blocklyCanvasTransitioning');
|
|
2227
|
-
dom.removeClass(
|
|
2228
|
-
/** @type {!SVGElement} */ (this.svgBubbleCanvas_),
|
|
2229
|
-
'blocklyCanvasTransitioning');
|
|
2156
|
+
dom.removeClass((this.svgBlockCanvas_), 'blocklyCanvasTransitioning');
|
|
2157
|
+
dom.removeClass((this.svgBubbleCanvas_), 'blocklyCanvasTransitioning');
|
|
2230
2158
|
}
|
|
2231
2159
|
|
|
2232
|
-
/**
|
|
2233
|
-
* Center the workspace.
|
|
2234
|
-
*/
|
|
2160
|
+
/** Center the workspace. */
|
|
2235
2161
|
scrollCenter() {
|
|
2236
2162
|
if (!this.isMovable()) {
|
|
2237
2163
|
console.warn(
|
|
@@ -2253,10 +2179,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
2253
2179
|
/**
|
|
2254
2180
|
* Scroll the workspace to center on the given block. If the block has other
|
|
2255
2181
|
* blocks stacked below it, the workspace will be centered on the stack.
|
|
2256
|
-
* @param
|
|
2257
|
-
* @public
|
|
2182
|
+
* @param id ID of block center on.
|
|
2258
2183
|
*/
|
|
2259
|
-
centerOnBlock(id) {
|
|
2184
|
+
centerOnBlock(id: string|null) {
|
|
2260
2185
|
if (!this.isMovable()) {
|
|
2261
2186
|
console.warn(
|
|
2262
2187
|
'Tried to move a non-movable workspace. This could result' +
|
|
@@ -2279,7 +2204,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
2279
2204
|
|
|
2280
2205
|
// In RTL the block's position is the top right of the block, not top left.
|
|
2281
2206
|
const multiplier = this.RTL ? -1 : 1;
|
|
2282
|
-
const blockCenterX = xy.x +
|
|
2207
|
+
const blockCenterX = xy.x + multiplier * heightWidth.width / 2;
|
|
2283
2208
|
|
|
2284
2209
|
// Workspace scale, used to convert from workspace coordinates to pixels.
|
|
2285
2210
|
const scale = this.scale;
|
|
@@ -2309,9 +2234,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
2309
2234
|
|
|
2310
2235
|
/**
|
|
2311
2236
|
* Set the workspace's zoom factor.
|
|
2312
|
-
* @param
|
|
2237
|
+
* @param newScale Zoom factor. Units: (pixels / workspaceUnit).
|
|
2313
2238
|
*/
|
|
2314
|
-
setScale(newScale) {
|
|
2239
|
+
setScale(newScale: number) {
|
|
2315
2240
|
if (this.options.zoomOptions.maxScale &&
|
|
2316
2241
|
newScale > this.options.zoomOptions.maxScale) {
|
|
2317
2242
|
newScale = this.options.zoomOptions.maxScale;
|
|
@@ -2358,10 +2283,9 @@ class WorkspaceSvg extends Workspace {
|
|
|
2358
2283
|
/**
|
|
2359
2284
|
* Get the workspace's zoom factor. If the workspace has a parent, we call
|
|
2360
2285
|
* into the parent to get the workspace scale.
|
|
2361
|
-
* @return
|
|
2362
|
-
* workspaceUnit).
|
|
2286
|
+
* @return The workspace zoom factor. Units: (pixels / workspaceUnit).
|
|
2363
2287
|
*/
|
|
2364
|
-
getScale() {
|
|
2288
|
+
getScale(): number {
|
|
2365
2289
|
if (this.options.parentWorkspace) {
|
|
2366
2290
|
return this.options.parentWorkspace.getScale();
|
|
2367
2291
|
}
|
|
@@ -2372,12 +2296,13 @@ class WorkspaceSvg extends Workspace {
|
|
|
2372
2296
|
* Scroll the workspace to a specified offset (in pixels), keeping in the
|
|
2373
2297
|
* workspace bounds. See comment on workspaceSvg.scrollX for more detail on
|
|
2374
2298
|
* the meaning of these values.
|
|
2375
|
-
* @param
|
|
2376
|
-
* @param
|
|
2377
|
-
* @
|
|
2299
|
+
* @param x Target X to scroll to.
|
|
2300
|
+
* @param y Target Y to scroll to.
|
|
2301
|
+
* @internal
|
|
2378
2302
|
*/
|
|
2379
|
-
scroll(x, y) {
|
|
2380
|
-
this.hideChaff(/* opt_onlyClosePopups= */
|
|
2303
|
+
scroll(x: number, y: number) {
|
|
2304
|
+
this.hideChaff(/* opt_onlyClosePopups= */
|
|
2305
|
+
true);
|
|
2381
2306
|
|
|
2382
2307
|
// Keep scrolling within the bounds of the content.
|
|
2383
2308
|
const metrics = this.getMetrics();
|
|
@@ -2415,95 +2340,91 @@ class WorkspaceSvg extends Workspace {
|
|
|
2415
2340
|
|
|
2416
2341
|
/**
|
|
2417
2342
|
* Find the block on this workspace with the specified ID.
|
|
2418
|
-
* @param
|
|
2419
|
-
* @return
|
|
2420
|
-
* @override
|
|
2343
|
+
* @param id ID of block to find.
|
|
2344
|
+
* @return The sought after block, or null if not found.
|
|
2421
2345
|
*/
|
|
2422
|
-
getBlockById(id) {
|
|
2423
|
-
return
|
|
2346
|
+
override getBlockById(id: string): BlockSvg|null {
|
|
2347
|
+
return super.getBlockById(id) as BlockSvg;
|
|
2424
2348
|
}
|
|
2425
2349
|
|
|
2426
2350
|
/**
|
|
2427
2351
|
* Find all blocks in workspace. Blocks are optionally sorted
|
|
2428
2352
|
* by position; top to bottom (with slight LTR or RTL bias).
|
|
2429
|
-
* @param
|
|
2430
|
-
* @return
|
|
2353
|
+
* @param ordered Sort the list if true.
|
|
2354
|
+
* @return Array of blocks.
|
|
2431
2355
|
*/
|
|
2432
|
-
getAllBlocks(ordered) {
|
|
2433
|
-
return
|
|
2356
|
+
override getAllBlocks(ordered: boolean): BlockSvg[] {
|
|
2357
|
+
return super.getAllBlocks(ordered) as BlockSvg[];
|
|
2434
2358
|
}
|
|
2435
2359
|
|
|
2436
2360
|
/**
|
|
2437
2361
|
* Finds the top-level blocks and returns them. Blocks are optionally sorted
|
|
2438
2362
|
* by position; top to bottom (with slight LTR or RTL bias).
|
|
2439
|
-
* @param
|
|
2440
|
-
* @return
|
|
2441
|
-
* @override
|
|
2363
|
+
* @param ordered Sort the list if true.
|
|
2364
|
+
* @return The top-level block objects.
|
|
2442
2365
|
*/
|
|
2443
|
-
getTopBlocks(ordered) {
|
|
2444
|
-
return super.getTopBlocks(ordered);
|
|
2366
|
+
override getTopBlocks(ordered: boolean): BlockSvg[] {
|
|
2367
|
+
return super.getTopBlocks(ordered) as BlockSvg[];
|
|
2445
2368
|
}
|
|
2446
2369
|
|
|
2447
2370
|
/**
|
|
2448
2371
|
* Adds a block to the list of top blocks.
|
|
2449
|
-
* @param
|
|
2372
|
+
* @param block Block to add.
|
|
2450
2373
|
*/
|
|
2451
|
-
addTopBlock(block) {
|
|
2452
|
-
this.addTopBoundedElement(
|
|
2374
|
+
override addTopBlock(block: Block) {
|
|
2375
|
+
this.addTopBoundedElement(block as BlockSvg);
|
|
2453
2376
|
super.addTopBlock(block);
|
|
2454
2377
|
}
|
|
2455
2378
|
|
|
2456
2379
|
/**
|
|
2457
2380
|
* Removes a block from the list of top blocks.
|
|
2458
|
-
* @param
|
|
2381
|
+
* @param block Block to remove.
|
|
2459
2382
|
*/
|
|
2460
|
-
removeTopBlock(block) {
|
|
2461
|
-
this.removeTopBoundedElement(
|
|
2383
|
+
override removeTopBlock(block: Block) {
|
|
2384
|
+
this.removeTopBoundedElement(block as BlockSvg);
|
|
2462
2385
|
super.removeTopBlock(block);
|
|
2463
2386
|
}
|
|
2464
2387
|
|
|
2465
2388
|
/**
|
|
2466
2389
|
* Adds a comment to the list of top comments.
|
|
2467
|
-
* @param
|
|
2390
|
+
* @param comment comment to add.
|
|
2468
2391
|
*/
|
|
2469
|
-
addTopComment(comment) {
|
|
2470
|
-
this.addTopBoundedElement(
|
|
2471
|
-
/** @type {!WorkspaceCommentSvg} */ (comment));
|
|
2392
|
+
override addTopComment(comment: WorkspaceComment) {
|
|
2393
|
+
this.addTopBoundedElement(comment as WorkspaceCommentSvg);
|
|
2472
2394
|
super.addTopComment(comment);
|
|
2473
2395
|
}
|
|
2474
2396
|
|
|
2475
2397
|
/**
|
|
2476
2398
|
* Removes a comment from the list of top comments.
|
|
2477
|
-
* @param
|
|
2399
|
+
* @param comment comment to remove.
|
|
2478
2400
|
*/
|
|
2479
|
-
removeTopComment(comment) {
|
|
2480
|
-
this.removeTopBoundedElement(
|
|
2481
|
-
/** @type {!WorkspaceCommentSvg} */ (comment));
|
|
2401
|
+
override removeTopComment(comment: WorkspaceComment) {
|
|
2402
|
+
this.removeTopBoundedElement(comment as WorkspaceCommentSvg);
|
|
2482
2403
|
super.removeTopComment(comment);
|
|
2483
2404
|
}
|
|
2484
2405
|
|
|
2485
2406
|
/**
|
|
2486
2407
|
* Adds a bounded element to the list of top bounded elements.
|
|
2487
|
-
* @param
|
|
2408
|
+
* @param element Bounded element to add.
|
|
2488
2409
|
*/
|
|
2489
|
-
addTopBoundedElement(element) {
|
|
2410
|
+
addTopBoundedElement(element: IBoundedElement) {
|
|
2490
2411
|
this.topBoundedElements_.push(element);
|
|
2491
2412
|
}
|
|
2492
2413
|
|
|
2493
2414
|
/**
|
|
2494
2415
|
* Removes a bounded element from the list of top bounded elements.
|
|
2495
|
-
* @param
|
|
2416
|
+
* @param element Bounded element to remove.
|
|
2496
2417
|
*/
|
|
2497
|
-
removeTopBoundedElement(element) {
|
|
2418
|
+
removeTopBoundedElement(element: IBoundedElement) {
|
|
2498
2419
|
arrayUtils.removeElem(this.topBoundedElements_, element);
|
|
2499
2420
|
}
|
|
2500
2421
|
|
|
2501
2422
|
/**
|
|
2502
2423
|
* Finds the top-level bounded elements and returns them.
|
|
2503
|
-
* @return
|
|
2424
|
+
* @return The top-level bounded elements.
|
|
2504
2425
|
*/
|
|
2505
|
-
getTopBoundedElements() {
|
|
2506
|
-
return
|
|
2426
|
+
getTopBoundedElements(): IBoundedElement[] {
|
|
2427
|
+
return (new Array<IBoundedElement>()).concat(this.topBoundedElements_);
|
|
2507
2428
|
}
|
|
2508
2429
|
|
|
2509
2430
|
/**
|
|
@@ -2511,10 +2432,10 @@ class WorkspaceSvg extends Workspace {
|
|
|
2511
2432
|
* If enabled, workspace will resize when appropriate.
|
|
2512
2433
|
* If disabled, workspace will not resize until re-enabled.
|
|
2513
2434
|
* Use to avoid resizing during a batch operation, for performance.
|
|
2514
|
-
* @param
|
|
2435
|
+
* @param enabled Whether resizes should be enabled.
|
|
2515
2436
|
*/
|
|
2516
|
-
setResizesEnabled(enabled) {
|
|
2517
|
-
const reenabled =
|
|
2437
|
+
setResizesEnabled(enabled: boolean) {
|
|
2438
|
+
const reenabled = !this.resizesEnabled_ && enabled;
|
|
2518
2439
|
this.resizesEnabled_ = enabled;
|
|
2519
2440
|
if (reenabled) {
|
|
2520
2441
|
// Newly enabled. Trigger a resize.
|
|
@@ -2526,7 +2447,7 @@ class WorkspaceSvg extends Workspace {
|
|
|
2526
2447
|
* Dispose of all blocks in workspace, with an optimization to prevent
|
|
2527
2448
|
* resizes.
|
|
2528
2449
|
*/
|
|
2529
|
-
clear() {
|
|
2450
|
+
override clear() {
|
|
2530
2451
|
this.setResizesEnabled(false);
|
|
2531
2452
|
super.clear();
|
|
2532
2453
|
this.topBoundedElements_ = [];
|
|
@@ -2540,11 +2461,11 @@ class WorkspaceSvg extends Workspace {
|
|
|
2540
2461
|
* <button text="create variable" callbackKey="CREATE_VARIABLE"></button>
|
|
2541
2462
|
* should be matched by a call to
|
|
2542
2463
|
* registerButtonCallback("CREATE_VARIABLE", yourCallbackFunction).
|
|
2543
|
-
* @param
|
|
2544
|
-
* @param
|
|
2545
|
-
* given button is clicked.
|
|
2464
|
+
* @param key The name to use to look up this function.
|
|
2465
|
+
* @param func The function to call when the given button is clicked.
|
|
2546
2466
|
*/
|
|
2547
|
-
registerButtonCallback(
|
|
2467
|
+
registerButtonCallback(
|
|
2468
|
+
key: string, func: (p1: FlyoutButton) => AnyDuringMigration) {
|
|
2548
2469
|
if (typeof func !== 'function') {
|
|
2549
2470
|
throw TypeError('Button callbacks must be functions.');
|
|
2550
2471
|
}
|
|
@@ -2554,20 +2475,21 @@ class WorkspaceSvg extends Workspace {
|
|
|
2554
2475
|
/**
|
|
2555
2476
|
* Get the callback function associated with a given key, for clicks on
|
|
2556
2477
|
* buttons and labels in the flyout.
|
|
2557
|
-
* @param
|
|
2558
|
-
* @return
|
|
2559
|
-
*
|
|
2478
|
+
* @param key The name to use to look up the function.
|
|
2479
|
+
* @return The function corresponding to the given key for this workspace;
|
|
2480
|
+
* null if no callback is registered.
|
|
2560
2481
|
*/
|
|
2561
|
-
getButtonCallback(key)
|
|
2482
|
+
getButtonCallback(key: string):
|
|
2483
|
+
((p1: FlyoutButton) => AnyDuringMigration)|null {
|
|
2562
2484
|
const result = this.flyoutButtonCallbacks_[key];
|
|
2563
2485
|
return result ? result : null;
|
|
2564
2486
|
}
|
|
2565
2487
|
|
|
2566
2488
|
/**
|
|
2567
2489
|
* Remove a callback for a click on a button in the flyout.
|
|
2568
|
-
* @param
|
|
2490
|
+
* @param key The name associated with the callback function.
|
|
2569
2491
|
*/
|
|
2570
|
-
removeButtonCallback(key) {
|
|
2492
|
+
removeButtonCallback(key: string) {
|
|
2571
2493
|
this.flyoutButtonCallbacks_[key] = null;
|
|
2572
2494
|
}
|
|
2573
2495
|
|
|
@@ -2575,11 +2497,11 @@ class WorkspaceSvg extends Workspace {
|
|
|
2575
2497
|
* Register a callback function associated with a given key, for populating
|
|
2576
2498
|
* custom toolbox categories in this workspace. See the variable and
|
|
2577
2499
|
* procedure categories as an example.
|
|
2578
|
-
* @param
|
|
2579
|
-
* @param
|
|
2580
|
-
* function to call when the given toolbox category is opened.
|
|
2500
|
+
* @param key The name to use to look up this function.
|
|
2501
|
+
* @param func The function to call when the given toolbox category is opened.
|
|
2581
2502
|
*/
|
|
2582
|
-
registerToolboxCategoryCallback(
|
|
2503
|
+
registerToolboxCategoryCallback(
|
|
2504
|
+
key: string, func: (p1: WorkspaceSvg) => toolbox.FlyoutDefinition) {
|
|
2583
2505
|
if (typeof func !== 'function') {
|
|
2584
2506
|
throw TypeError('Toolbox category callbacks must be functions.');
|
|
2585
2507
|
}
|
|
@@ -2589,35 +2511,34 @@ class WorkspaceSvg extends Workspace {
|
|
|
2589
2511
|
/**
|
|
2590
2512
|
* Get the callback function associated with a given key, for populating
|
|
2591
2513
|
* custom toolbox categories in this workspace.
|
|
2592
|
-
* @param
|
|
2593
|
-
* @return
|
|
2594
|
-
*
|
|
2595
|
-
* function is registered.
|
|
2514
|
+
* @param key The name to use to look up the function.
|
|
2515
|
+
* @return The function corresponding to the given key for this workspace, or
|
|
2516
|
+
* null if no function is registered.
|
|
2596
2517
|
*/
|
|
2597
|
-
getToolboxCategoryCallback(key)
|
|
2518
|
+
getToolboxCategoryCallback(key: string):
|
|
2519
|
+
((p1: WorkspaceSvg) => toolbox.FlyoutDefinition)|null {
|
|
2598
2520
|
return this.toolboxCategoryCallbacks_[key] || null;
|
|
2599
2521
|
}
|
|
2600
2522
|
|
|
2601
2523
|
/**
|
|
2602
2524
|
* Remove a callback for a click on a custom category's name in the toolbox.
|
|
2603
|
-
* @param
|
|
2525
|
+
* @param key The name associated with the callback function.
|
|
2604
2526
|
*/
|
|
2605
|
-
removeToolboxCategoryCallback(key) {
|
|
2527
|
+
removeToolboxCategoryCallback(key: string) {
|
|
2606
2528
|
this.toolboxCategoryCallbacks_[key] = null;
|
|
2607
2529
|
}
|
|
2608
2530
|
|
|
2609
2531
|
/**
|
|
2610
2532
|
* Look up the gesture that is tracking this touch stream on this workspace.
|
|
2611
2533
|
* May create a new gesture.
|
|
2612
|
-
* @param
|
|
2613
|
-
* @return
|
|
2614
|
-
*
|
|
2615
|
-
* @
|
|
2534
|
+
* @param e Mouse event or touch event.
|
|
2535
|
+
* @return The gesture that is tracking this touch stream, or null if no valid
|
|
2536
|
+
* gesture exists.
|
|
2537
|
+
* @internal
|
|
2616
2538
|
*/
|
|
2617
|
-
getGesture(e) {
|
|
2618
|
-
const isStart =
|
|
2619
|
-
|
|
2620
|
-
e.type === 'pointerdown');
|
|
2539
|
+
getGesture(e: Event): TouchGesture|null {
|
|
2540
|
+
const isStart = e.type === 'mousedown' || e.type === 'touchstart' ||
|
|
2541
|
+
e.type === 'pointerdown';
|
|
2621
2542
|
|
|
2622
2543
|
const gesture = this.currentGesture_;
|
|
2623
2544
|
if (gesture) {
|
|
@@ -2643,15 +2564,17 @@ class WorkspaceSvg extends Workspace {
|
|
|
2643
2564
|
|
|
2644
2565
|
/**
|
|
2645
2566
|
* Clear the reference to the current gesture.
|
|
2646
|
-
* @
|
|
2567
|
+
* @internal
|
|
2647
2568
|
*/
|
|
2648
2569
|
clearGesture() {
|
|
2649
|
-
|
|
2570
|
+
// AnyDuringMigration because: Type 'null' is not assignable to type
|
|
2571
|
+
// 'TouchGesture'.
|
|
2572
|
+
this.currentGesture_ = null as AnyDuringMigration;
|
|
2650
2573
|
}
|
|
2651
2574
|
|
|
2652
2575
|
/**
|
|
2653
2576
|
* Cancel the current gesture, if one exists.
|
|
2654
|
-
* @
|
|
2577
|
+
* @internal
|
|
2655
2578
|
*/
|
|
2656
2579
|
cancelCurrentGesture() {
|
|
2657
2580
|
if (this.currentGesture_) {
|
|
@@ -2661,26 +2584,26 @@ class WorkspaceSvg extends Workspace {
|
|
|
2661
2584
|
|
|
2662
2585
|
/**
|
|
2663
2586
|
* Get the audio manager for this workspace.
|
|
2664
|
-
* @return
|
|
2587
|
+
* @return The audio manager for this workspace.
|
|
2665
2588
|
*/
|
|
2666
|
-
getAudioManager() {
|
|
2589
|
+
getAudioManager(): WorkspaceAudio {
|
|
2667
2590
|
return this.audioManager_;
|
|
2668
2591
|
}
|
|
2669
2592
|
|
|
2670
2593
|
/**
|
|
2671
2594
|
* Get the grid object for this workspace, or null if there is none.
|
|
2672
|
-
* @return
|
|
2673
|
-
* @
|
|
2595
|
+
* @return The grid object for this workspace.
|
|
2596
|
+
* @internal
|
|
2674
2597
|
*/
|
|
2675
|
-
getGrid() {
|
|
2598
|
+
getGrid(): Grid|null {
|
|
2676
2599
|
return this.grid_;
|
|
2677
2600
|
}
|
|
2678
2601
|
|
|
2679
2602
|
/**
|
|
2680
2603
|
* Close tooltips, context menus, dropdown selections, etc.
|
|
2681
|
-
* @param
|
|
2604
|
+
* @param opt_onlyClosePopups Whether only popups should be closed.
|
|
2682
2605
|
*/
|
|
2683
|
-
hideChaff(opt_onlyClosePopups) {
|
|
2606
|
+
hideChaff(opt_onlyClosePopups?: boolean) {
|
|
2684
2607
|
Tooltip.hide();
|
|
2685
2608
|
WidgetDiv.hide();
|
|
2686
2609
|
dropDownDiv.hideWithoutAnimation();
|
|
@@ -2694,12 +2617,11 @@ class WorkspaceSvg extends Workspace {
|
|
|
2694
2617
|
|
|
2695
2618
|
/**
|
|
2696
2619
|
* Sets the X/Y translations of a top level workspace.
|
|
2697
|
-
* @param
|
|
2698
|
-
*
|
|
2699
|
-
* @private
|
|
2700
|
-
* @this {WorkspaceSvg}
|
|
2620
|
+
* @param xyRatio Contains an x and/or y property which is a float between 0
|
|
2621
|
+
* and 1 specifying the degree of scrolling.
|
|
2701
2622
|
*/
|
|
2702
|
-
static setTopLevelWorkspaceMetrics_(
|
|
2623
|
+
private static setTopLevelWorkspaceMetrics_(
|
|
2624
|
+
this: WorkspaceSvg, xyRatio: AnyDuringMigration) {
|
|
2703
2625
|
const metrics = this.getMetrics();
|
|
2704
2626
|
|
|
2705
2627
|
if (typeof xyRatio.x === 'number') {
|
|
@@ -2724,12 +2646,10 @@ class WorkspaceSvg extends Workspace {
|
|
|
2724
2646
|
/**
|
|
2725
2647
|
* Size the workspace when the contents change. This also updates
|
|
2726
2648
|
* scrollbars accordingly.
|
|
2727
|
-
* @param
|
|
2649
|
+
* @param workspace The workspace to resize.
|
|
2728
2650
|
* @alias Blockly.WorkspaceSvg.resizeSvgContents
|
|
2651
|
+
* @internal
|
|
2729
2652
|
*/
|
|
2730
|
-
|
|
2653
|
+
export function resizeSvgContents(workspace: WorkspaceSvg) {
|
|
2731
2654
|
workspace.resizeContents();
|
|
2732
|
-
}
|
|
2733
|
-
exports.resizeSvgContents = resizeSvgContents;
|
|
2734
|
-
|
|
2735
|
-
exports.WorkspaceSvg = WorkspaceSvg;
|
|
2655
|
+
}
|