blockly 7.20211209.4 → 8.0.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.d.ts +18963 -18432
- package/blockly.min.js +852 -844
- package/blockly_compressed.js +669 -664
- package/blockly_compressed.js.map +1 -1
- package/blocks/blocks.js +47 -0
- package/blocks/colour.js +13 -3
- package/blocks/lists.js +22 -13
- package/blocks/logic.js +13 -3
- package/blocks/loops.js +24 -11
- package/blocks/math.js +12 -3
- package/blocks/procedures.js +41 -27
- package/blocks/text.js +22 -13
- package/blocks/variables.js +14 -3
- package/blocks/variables_dynamic.js +13 -3
- package/blocks_compressed.js +146 -141
- package/blocks_compressed.js.map +1 -1
- package/core/block.js +1869 -1814
- package/core/block_drag_surface.js +201 -200
- package/core/block_dragger.js +377 -373
- package/core/block_svg.js +1593 -1479
- package/core/blockly.js +8 -22
- package/core/blocks.js +9 -2
- package/core/browser_events.js +22 -5
- package/core/bubble.js +841 -797
- package/core/bubble_dragger.js +213 -206
- package/core/bump_objects.js +2 -2
- package/core/clipboard.js +9 -9
- package/core/comment.js +353 -332
- package/core/common.js +46 -17
- package/core/component_manager.js +181 -174
- package/core/config.js +87 -0
- package/core/connection.js +595 -584
- package/core/connection_checker.js +242 -244
- package/core/connection_db.js +235 -230
- package/core/contextmenu.js +9 -6
- package/core/contextmenu_items.js +1 -2
- package/core/contextmenu_registry.js +93 -89
- package/core/css.js +474 -474
- package/core/delete_area.js +45 -42
- package/core/drag_target.js +57 -56
- package/core/dropdowndiv.js +153 -163
- package/core/events/events.js +2 -2
- package/core/events/events_abstract.js +89 -77
- package/core/events/events_block_base.js +37 -36
- package/core/events/events_block_change.js +130 -124
- package/core/events/events_block_create.js +73 -71
- package/core/events/events_block_delete.js +84 -82
- package/core/events/events_block_drag.js +50 -49
- package/core/events/events_block_move.js +147 -140
- package/core/events/events_bubble_open.js +51 -50
- package/core/events/events_click.js +48 -44
- package/core/events/events_comment_base.js +72 -69
- package/core/events/events_comment_change.js +63 -61
- package/core/events/events_comment_create.js +44 -42
- package/core/events/events_comment_delete.js +42 -40
- package/core/events/events_comment_move.js +106 -104
- package/core/events/events_marker_move.js +65 -64
- package/core/events/events_selected.js +46 -45
- package/core/events/events_theme_change.js +36 -35
- package/core/events/events_toolbox_item_select.js +46 -45
- package/core/events/events_trashcan_open.js +37 -36
- package/core/events/events_ui.js +47 -46
- package/core/events/events_ui_base.js +30 -29
- package/core/events/events_var_base.js +37 -36
- package/core/events/events_var_create.js +50 -48
- package/core/events/events_var_delete.js +50 -48
- package/core/events/events_var_rename.js +51 -49
- package/core/events/events_viewport.js +66 -65
- package/core/events/utils.js +29 -14
- package/core/events/workspace_events.js +49 -55
- package/core/extensions.js +4 -3
- package/core/field.js +1061 -997
- package/core/field_angle.js +462 -442
- package/core/field_checkbox.js +194 -182
- package/core/field_colour.js +519 -505
- package/core/field_dropdown.js +617 -598
- package/core/field_image.js +229 -220
- package/core/field_label.js +102 -91
- package/core/field_label_serializable.js +42 -41
- package/core/field_multilineinput.js +372 -358
- package/core/field_number.js +272 -253
- package/core/field_textinput.js +499 -467
- package/core/field_variable.js +458 -420
- package/core/flyout_base.js +1005 -952
- package/core/flyout_button.js +277 -260
- package/core/flyout_horizontal.js +304 -302
- package/core/flyout_metrics_manager.js +64 -64
- package/core/flyout_vertical.js +306 -300
- package/core/generator.js +459 -446
- package/core/gesture.js +829 -813
- package/core/grid.js +166 -163
- package/core/icon.js +168 -159
- package/core/inject.js +7 -5
- package/core/input.js +257 -248
- package/core/insertion_marker_manager.js +655 -624
- package/core/internal_constants.js +0 -129
- package/core/keyboard_nav/ast_node.js +605 -596
- package/core/keyboard_nav/basic_cursor.js +166 -165
- package/core/keyboard_nav/cursor.js +99 -97
- package/core/keyboard_nav/marker.js +83 -79
- package/core/keyboard_nav/tab_navigate_cursor.js +18 -23
- package/core/marker_manager.js +153 -141
- package/core/menu.js +377 -372
- package/core/menuitem.js +223 -217
- package/core/metrics_manager.js +403 -390
- package/core/mutator.js +468 -437
- package/core/names.js +229 -188
- package/core/options.js +290 -284
- package/core/procedures.js +29 -17
- package/core/registry.js +19 -16
- package/core/rendered_connection.js +482 -463
- package/core/renderers/common/block_rendering.js +9 -3
- package/core/renderers/common/constants.js +1119 -1112
- package/core/renderers/common/debug.js +14 -0
- package/core/renderers/common/debugger.js +338 -316
- package/core/renderers/common/drawer.js +380 -370
- package/core/renderers/common/i_path_object.js +2 -2
- package/core/renderers/common/info.js +626 -618
- package/core/renderers/common/marker_svg.js +579 -541
- package/core/renderers/common/path_object.js +203 -200
- package/core/renderers/common/renderer.js +220 -218
- package/core/renderers/geras/constants.js +36 -36
- package/core/renderers/geras/drawer.js +155 -147
- package/core/renderers/geras/highlight_constants.js +244 -238
- package/core/renderers/geras/highlighter.js +231 -179
- package/core/renderers/geras/info.js +392 -369
- package/core/renderers/geras/measurables/inline_input.js +25 -19
- package/core/renderers/geras/measurables/statement_input.js +23 -17
- package/core/renderers/geras/path_object.js +106 -121
- package/core/renderers/geras/renderer.js +96 -98
- package/core/renderers/measurables/base.js +30 -18
- package/core/renderers/measurables/bottom_row.js +83 -80
- package/core/renderers/measurables/connection.js +22 -15
- package/core/renderers/measurables/external_value_input.js +35 -22
- package/core/renderers/measurables/field.js +35 -20
- package/core/renderers/measurables/hat.js +18 -13
- package/core/renderers/measurables/icon.js +24 -17
- package/core/renderers/measurables/in_row_spacer.js +15 -13
- package/core/renderers/measurables/inline_input.js +43 -33
- package/core/renderers/measurables/input_connection.js +41 -28
- package/core/renderers/measurables/input_row.js +50 -44
- package/core/renderers/measurables/jagged_edge.js +14 -12
- package/core/renderers/measurables/next_connection.js +16 -14
- package/core/renderers/measurables/output_connection.js +26 -20
- package/core/renderers/measurables/previous_connection.js +16 -15
- package/core/renderers/measurables/round_corner.js +20 -18
- package/core/renderers/measurables/row.js +184 -168
- package/core/renderers/measurables/spacer_row.js +38 -23
- package/core/renderers/measurables/square_corner.js +18 -16
- package/core/renderers/measurables/statement_input.js +23 -20
- package/core/renderers/measurables/top_row.js +88 -85
- package/core/renderers/minimalist/constants.js +8 -7
- package/core/renderers/minimalist/drawer.js +11 -10
- package/core/renderers/minimalist/info.js +18 -18
- package/core/renderers/minimalist/renderer.js +40 -39
- package/core/renderers/thrasos/info.js +258 -248
- package/core/renderers/thrasos/renderer.js +20 -20
- package/core/renderers/zelos/constants.js +898 -873
- package/core/renderers/zelos/drawer.js +186 -169
- package/core/renderers/zelos/info.js +502 -479
- package/core/renderers/zelos/marker_svg.js +129 -115
- package/core/renderers/zelos/measurables/bottom_row.js +31 -30
- package/core/renderers/zelos/measurables/inputs.js +22 -21
- package/core/renderers/zelos/measurables/row_elements.js +14 -13
- package/core/renderers/zelos/measurables/top_row.js +34 -33
- package/core/renderers/zelos/path_object.js +181 -180
- package/core/renderers/zelos/renderer.js +91 -92
- package/core/scrollbar.js +759 -713
- package/core/scrollbar_pair.js +250 -245
- package/core/serialization/blocks.js +19 -9
- package/core/serialization/workspaces.js +3 -2
- package/core/shortcut_registry.js +286 -277
- package/core/sprites.js +31 -0
- package/core/theme.js +135 -141
- package/core/theme_manager.js +147 -143
- package/core/toolbox/category.js +602 -576
- package/core/toolbox/collapsible_category.js +226 -227
- package/core/toolbox/separator.js +70 -61
- package/core/toolbox/toolbox.js +934 -927
- package/core/toolbox/toolbox_item.js +115 -99
- package/core/tooltip.js +108 -35
- package/core/touch.js +8 -3
- package/core/touch_gesture.js +254 -251
- package/core/trashcan.js +606 -595
- package/core/utils/coordinate.js +97 -95
- package/core/utils/dom.js +2 -2
- package/core/utils/global.js +2 -0
- package/core/utils/rect.js +41 -37
- package/core/utils/sentinel.js +25 -0
- package/core/utils/size.js +30 -27
- package/core/utils/svg.js +18 -16
- package/core/variable_map.js +325 -341
- package/core/variable_model.js +55 -54
- package/core/variables.js +9 -2
- package/core/variables_dynamic.js +3 -1
- package/core/warning.js +126 -120
- package/core/widgetdiv.js +4 -4
- package/core/workspace.js +685 -664
- package/core/workspace_audio.js +124 -118
- package/core/workspace_comment.js +308 -298
- package/core/workspace_comment_svg.js +1029 -951
- package/core/workspace_drag_surface_svg.js +147 -140
- package/core/workspace_dragger.js +70 -71
- package/core/workspace_svg.js +2322 -2297
- package/core/xml.js +30 -20
- package/core/zoom_controls.js +431 -439
- package/dart_compressed.js +40 -43
- package/dart_compressed.js.map +1 -1
- package/generators/dart/colour.js +56 -64
- package/generators/dart/lists.js +61 -50
- package/generators/dart/math.js +160 -148
- package/generators/dart/text.js +83 -61
- package/generators/javascript/colour.js +37 -34
- package/generators/javascript/lists.js +50 -43
- package/generators/javascript/math.js +123 -139
- package/generators/javascript/text.js +67 -81
- package/generators/lua/colour.js +25 -23
- package/generators/lua/lists.js +97 -69
- package/generators/lua/logic.js +1 -2
- package/generators/lua/math.js +182 -144
- package/generators/lua/text.js +116 -99
- package/generators/php/colour.js +38 -32
- package/generators/php/lists.js +109 -89
- package/generators/php/math.js +90 -81
- package/generators/php/text.js +63 -61
- package/generators/python/colour.js +18 -18
- package/generators/python/lists.js +38 -30
- package/generators/python/loops.js +12 -8
- package/generators/python/math.js +104 -106
- package/generators/python/text.js +34 -30
- package/javascript_compressed.js +37 -39
- package/javascript_compressed.js.map +1 -1
- package/lua_compressed.js +39 -42
- package/lua_compressed.js.map +1 -1
- package/msg/az.js +2 -2
- package/msg/be.js +4 -4
- package/msg/cs.js +15 -15
- package/msg/de.js +1 -1
- package/msg/diq.js +1 -1
- package/msg/eo.js +1 -1
- package/msg/es.js +1 -1
- package/msg/fa.js +1 -1
- package/msg/fr.js +4 -4
- package/msg/he.js +1 -1
- package/msg/hr.js +2 -2
- package/msg/hy.js +2 -2
- package/msg/id.js +12 -12
- package/msg/inh.js +14 -14
- package/msg/ja.js +7 -7
- package/msg/lv.js +29 -29
- package/msg/pa.js +3 -3
- package/msg/smn.js +436 -0
- package/msg/te.js +1 -1
- package/msg/yue.js +1 -1
- package/msg/zh-hans.js +3 -3
- package/msg/zh-hant.js +3 -3
- package/package.json +7 -6
- package/php_compressed.js +38 -42
- package/php_compressed.js.map +1 -1
- package/python_compressed.js +26 -25
- package/python_compressed.js.map +1 -1
- package/blocks/all.js +0 -23
|
@@ -19,10 +19,10 @@ const blockAnimations = goog.require('Blockly.blockAnimations');
|
|
|
19
19
|
const common = goog.require('Blockly.common');
|
|
20
20
|
const constants = goog.require('Blockly.constants');
|
|
21
21
|
const eventUtils = goog.require('Blockly.Events.utils');
|
|
22
|
-
const internalConstants = goog.require('Blockly.internalConstants');
|
|
23
22
|
/* eslint-disable-next-line no-unused-vars */
|
|
24
23
|
const {BlockSvg} = goog.requireType('Blockly.BlockSvg');
|
|
25
24
|
const {ComponentManager} = goog.require('Blockly.ComponentManager');
|
|
25
|
+
const {config} = goog.require('Blockly.config');
|
|
26
26
|
const {ConnectionType} = goog.require('Blockly.ConnectionType');
|
|
27
27
|
/* eslint-disable-next-line no-unused-vars */
|
|
28
28
|
const {Coordinate} = goog.requireType('Blockly.utils.Coordinate');
|
|
@@ -36,724 +36,755 @@ const {RenderedConnection} = goog.requireType('Blockly.RenderedConnection');
|
|
|
36
36
|
const {WorkspaceSvg} = goog.requireType('Blockly.WorkspaceSvg');
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* An error message to throw if the block created by createMarkerBlock_ is
|
|
41
|
+
* missing any components.
|
|
42
|
+
* @type {string}
|
|
43
|
+
* @const
|
|
44
|
+
*/
|
|
45
|
+
const DUPLICATE_BLOCK_ERROR = 'The insertion marker ' +
|
|
46
|
+
'manager tried to create a marker but the result is missing %1. If ' +
|
|
47
|
+
'you are using a mutator, make sure your domToMutation method is ' +
|
|
48
|
+
'properly defined.';
|
|
49
|
+
|
|
50
|
+
|
|
39
51
|
/**
|
|
40
52
|
* Class that controls updates to connections during drags. It is primarily
|
|
41
53
|
* responsible for finding the closest eligible connection and highlighting or
|
|
42
54
|
* unhighlighting it as needed during a drag.
|
|
43
|
-
* @param {!BlockSvg} block The top block in the stack being dragged.
|
|
44
|
-
* @constructor
|
|
45
55
|
* @alias Blockly.InsertionMarkerManager
|
|
46
56
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
class InsertionMarkerManager {
|
|
58
|
+
/**
|
|
59
|
+
* @param {!BlockSvg} block The top block in the stack being dragged.
|
|
60
|
+
*/
|
|
61
|
+
constructor(block) {
|
|
62
|
+
common.setSelected(block);
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The top block in the stack being dragged.
|
|
66
|
+
* Does not change during a drag.
|
|
67
|
+
* @type {!BlockSvg}
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
this.topBlock_ = block;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The workspace on which these connections are being dragged.
|
|
74
|
+
* Does not change during a drag.
|
|
75
|
+
* @type {!WorkspaceSvg}
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
this.workspace_ = block.workspace;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The last connection on the stack, if it's not the last connection on the
|
|
82
|
+
* first block.
|
|
83
|
+
* Set in initAvailableConnections, if at all.
|
|
84
|
+
* @type {RenderedConnection}
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
this.lastOnStack_ = null;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The insertion marker corresponding to the last block in the stack, if
|
|
91
|
+
* that's not the same as the first block in the stack.
|
|
92
|
+
* Set in initAvailableConnections, if at all
|
|
93
|
+
* @type {BlockSvg}
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
this.lastMarker_ = null;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The insertion marker that shows up between blocks to show where a block
|
|
100
|
+
* would go if dropped immediately.
|
|
101
|
+
* @type {BlockSvg}
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
this.firstMarker_ = this.createMarkerBlock_(this.topBlock_);
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The connection that this block would connect to if released immediately.
|
|
108
|
+
* Updated on every mouse move.
|
|
109
|
+
* This is not on any of the blocks that are being dragged.
|
|
110
|
+
* @type {RenderedConnection}
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
this.closestConnection_ = null;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The connection that would connect to this.closestConnection_ if this
|
|
117
|
+
* block were released immediately. Updated on every mouse move. This is on
|
|
118
|
+
* the top block that is being dragged or the last block in the dragging
|
|
119
|
+
* stack.
|
|
120
|
+
* @type {RenderedConnection}
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
this.localConnection_ = null;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Whether the block would be deleted if it were dropped immediately.
|
|
127
|
+
* Updated on every mouse move.
|
|
128
|
+
* @type {boolean}
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
this.wouldDeleteBlock_ = false;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Connection on the insertion marker block that corresponds to
|
|
135
|
+
* this.localConnection_ on the currently dragged block.
|
|
136
|
+
* @type {RenderedConnection}
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
this.markerConnection_ = null;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The block that currently has an input being highlighted, or null.
|
|
143
|
+
* @type {BlockSvg}
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
this.highlightedBlock_ = null;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The block being faded to indicate replacement, or null.
|
|
150
|
+
* @type {BlockSvg}
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
this.fadedBlock_ = null;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The connections on the dragging blocks that are available to connect to
|
|
157
|
+
* other blocks. This includes all open connections on the top block, as
|
|
158
|
+
* well as the last connection on the block stack. Does not change during a
|
|
159
|
+
* drag.
|
|
160
|
+
* @type {!Array<!RenderedConnection>}
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
this.availableConnections_ = this.initAvailableConnections_();
|
|
164
|
+
}
|
|
49
165
|
|
|
50
166
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @type {!BlockSvg}
|
|
54
|
-
* @private
|
|
167
|
+
* Sever all links from this object.
|
|
168
|
+
* @package
|
|
55
169
|
*/
|
|
56
|
-
|
|
170
|
+
dispose() {
|
|
171
|
+
this.availableConnections_.length = 0;
|
|
172
|
+
|
|
173
|
+
eventUtils.disable();
|
|
174
|
+
try {
|
|
175
|
+
if (this.firstMarker_) {
|
|
176
|
+
this.firstMarker_.dispose();
|
|
177
|
+
}
|
|
178
|
+
if (this.lastMarker_) {
|
|
179
|
+
this.lastMarker_.dispose();
|
|
180
|
+
}
|
|
181
|
+
} finally {
|
|
182
|
+
eventUtils.enable();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
57
185
|
|
|
58
186
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @
|
|
62
|
-
* @private
|
|
187
|
+
* Update the available connections for the top block. These connections can
|
|
188
|
+
* change if a block is unplugged and the stack is healed.
|
|
189
|
+
* @package
|
|
63
190
|
*/
|
|
64
|
-
|
|
191
|
+
updateAvailableConnections() {
|
|
192
|
+
this.availableConnections_ = this.initAvailableConnections_();
|
|
193
|
+
}
|
|
65
194
|
|
|
66
195
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @
|
|
196
|
+
* Return whether the block would be deleted if dropped immediately, based on
|
|
197
|
+
* information from the most recent move event.
|
|
198
|
+
* @return {boolean} True if the block would be deleted if dropped
|
|
199
|
+
* immediately.
|
|
200
|
+
* @package
|
|
72
201
|
*/
|
|
73
|
-
|
|
202
|
+
wouldDeleteBlock() {
|
|
203
|
+
return this.wouldDeleteBlock_;
|
|
204
|
+
}
|
|
74
205
|
|
|
75
206
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
207
|
+
* Return whether the block would be connected if dropped immediately, based
|
|
208
|
+
* on information from the most recent move event.
|
|
209
|
+
* @return {boolean} True if the block would be connected if dropped
|
|
210
|
+
* immediately.
|
|
211
|
+
* @package
|
|
81
212
|
*/
|
|
82
|
-
|
|
213
|
+
wouldConnectBlock() {
|
|
214
|
+
return !!this.closestConnection_;
|
|
215
|
+
}
|
|
83
216
|
|
|
84
217
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
88
|
-
* @private
|
|
218
|
+
* Connect to the closest connection and render the results.
|
|
219
|
+
* This should be called at the end of a drag.
|
|
220
|
+
* @package
|
|
89
221
|
*/
|
|
90
|
-
|
|
222
|
+
applyConnections() {
|
|
223
|
+
if (this.closestConnection_) {
|
|
224
|
+
// Don't fire events for insertion markers.
|
|
225
|
+
eventUtils.disable();
|
|
226
|
+
this.hidePreview_();
|
|
227
|
+
eventUtils.enable();
|
|
228
|
+
// Connect two blocks together.
|
|
229
|
+
this.localConnection_.connect(this.closestConnection_);
|
|
230
|
+
if (this.topBlock_.rendered) {
|
|
231
|
+
// Trigger a connection animation.
|
|
232
|
+
// Determine which connection is inferior (lower in the source stack).
|
|
233
|
+
const inferiorConnection = this.localConnection_.isSuperior() ?
|
|
234
|
+
this.closestConnection_ :
|
|
235
|
+
this.localConnection_;
|
|
236
|
+
blockAnimations.connectionUiEffect(inferiorConnection.getSourceBlock());
|
|
237
|
+
// Bring the just-edited stack to the front.
|
|
238
|
+
const rootBlock = this.topBlock_.getRootBlock();
|
|
239
|
+
rootBlock.bringToFront();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
91
243
|
|
|
92
244
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* @
|
|
97
|
-
*
|
|
245
|
+
* Update connections based on the most recent move location.
|
|
246
|
+
* @param {!Coordinate} dxy Position relative to drag start,
|
|
247
|
+
* in workspace units.
|
|
248
|
+
* @param {?IDragTarget} dragTarget The drag target that the block is
|
|
249
|
+
* currently over.
|
|
250
|
+
* @package
|
|
98
251
|
*/
|
|
99
|
-
|
|
252
|
+
update(dxy, dragTarget) {
|
|
253
|
+
const candidate = this.getCandidate_(dxy);
|
|
254
|
+
|
|
255
|
+
this.wouldDeleteBlock_ = this.shouldDelete_(candidate, dragTarget);
|
|
256
|
+
|
|
257
|
+
const shouldUpdate =
|
|
258
|
+
this.wouldDeleteBlock_ || this.shouldUpdatePreviews_(candidate, dxy);
|
|
259
|
+
|
|
260
|
+
if (shouldUpdate) {
|
|
261
|
+
// Don't fire events for insertion marker creation or movement.
|
|
262
|
+
eventUtils.disable();
|
|
263
|
+
this.maybeHidePreview_(candidate);
|
|
264
|
+
this.maybeShowPreview_(candidate);
|
|
265
|
+
eventUtils.enable();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
100
268
|
|
|
101
269
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @type {RenderedConnection}
|
|
270
|
+
* Create an insertion marker that represents the given block.
|
|
271
|
+
* @param {!BlockSvg} sourceBlock The block that the insertion marker
|
|
272
|
+
* will represent.
|
|
273
|
+
* @return {!BlockSvg} The insertion marker that represents the given
|
|
274
|
+
* block.
|
|
108
275
|
* @private
|
|
109
276
|
*/
|
|
110
|
-
|
|
277
|
+
createMarkerBlock_(sourceBlock) {
|
|
278
|
+
const imType = sourceBlock.type;
|
|
279
|
+
|
|
280
|
+
eventUtils.disable();
|
|
281
|
+
let result;
|
|
282
|
+
try {
|
|
283
|
+
result = this.workspace_.newBlock(imType);
|
|
284
|
+
result.setInsertionMarker(true);
|
|
285
|
+
if (sourceBlock.saveExtraState) {
|
|
286
|
+
const state = sourceBlock.saveExtraState();
|
|
287
|
+
if (state) {
|
|
288
|
+
result.loadExtraState(state);
|
|
289
|
+
}
|
|
290
|
+
} else if (sourceBlock.mutationToDom) {
|
|
291
|
+
const oldMutationDom = sourceBlock.mutationToDom();
|
|
292
|
+
if (oldMutationDom) {
|
|
293
|
+
result.domToMutation(oldMutationDom);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// Copy field values from the other block. These values may impact the
|
|
297
|
+
// rendered size of the insertion marker. Note that we do not care about
|
|
298
|
+
// child blocks here.
|
|
299
|
+
for (let i = 0; i < sourceBlock.inputList.length; i++) {
|
|
300
|
+
const sourceInput = sourceBlock.inputList[i];
|
|
301
|
+
if (sourceInput.name === constants.COLLAPSED_INPUT_NAME) {
|
|
302
|
+
continue; // Ignore the collapsed input.
|
|
303
|
+
}
|
|
304
|
+
const resultInput = result.inputList[i];
|
|
305
|
+
if (!resultInput) {
|
|
306
|
+
throw new Error(DUPLICATE_BLOCK_ERROR.replace('%1', 'an input'));
|
|
307
|
+
}
|
|
308
|
+
for (let j = 0; j < sourceInput.fieldRow.length; j++) {
|
|
309
|
+
const sourceField = sourceInput.fieldRow[j];
|
|
310
|
+
const resultField = resultInput.fieldRow[j];
|
|
311
|
+
if (!resultField) {
|
|
312
|
+
throw new Error(DUPLICATE_BLOCK_ERROR.replace('%1', 'a field'));
|
|
313
|
+
}
|
|
314
|
+
resultField.setValue(sourceField.getValue());
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
result.setCollapsed(sourceBlock.isCollapsed());
|
|
319
|
+
result.setInputsInline(sourceBlock.getInputsInline());
|
|
320
|
+
|
|
321
|
+
result.initSvg();
|
|
322
|
+
result.getSvgRoot().setAttribute('visibility', 'hidden');
|
|
323
|
+
} finally {
|
|
324
|
+
eventUtils.enable();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
111
329
|
|
|
112
330
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
331
|
+
* Populate the list of available connections on this block stack. This
|
|
332
|
+
* should only be called once, at the beginning of a drag. If the stack has
|
|
333
|
+
* more than one block, this function will populate lastOnStack_ and create
|
|
334
|
+
* the corresponding insertion marker.
|
|
335
|
+
* @return {!Array<!RenderedConnection>} A list of available
|
|
336
|
+
* connections.
|
|
116
337
|
* @private
|
|
117
338
|
*/
|
|
118
|
-
|
|
339
|
+
initAvailableConnections_() {
|
|
340
|
+
const available = this.topBlock_.getConnections_(false);
|
|
341
|
+
// Also check the last connection on this stack
|
|
342
|
+
const lastOnStack = this.topBlock_.lastConnectionInStack(true);
|
|
343
|
+
if (lastOnStack && lastOnStack !== this.topBlock_.nextConnection) {
|
|
344
|
+
available.push(lastOnStack);
|
|
345
|
+
this.lastOnStack_ = lastOnStack;
|
|
346
|
+
if (this.lastMarker_) {
|
|
347
|
+
eventUtils.disable();
|
|
348
|
+
try {
|
|
349
|
+
this.lastMarker_.dispose();
|
|
350
|
+
} finally {
|
|
351
|
+
eventUtils.enable();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
this.lastMarker_ = this.createMarkerBlock_(lastOnStack.getSourceBlock());
|
|
355
|
+
}
|
|
356
|
+
return available;
|
|
357
|
+
}
|
|
119
358
|
|
|
120
359
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* @
|
|
360
|
+
* Whether the previews (insertion marker and replacement marker) should be
|
|
361
|
+
* updated based on the closest candidate and the current drag distance.
|
|
362
|
+
* @param {!Object} candidate An object containing a local connection, a
|
|
363
|
+
* closest connection, and a radius. Returned by getCandidate_.
|
|
364
|
+
* @param {!Coordinate} dxy Position relative to drag start,
|
|
365
|
+
* in workspace units.
|
|
366
|
+
* @return {boolean} Whether the preview should be updated.
|
|
124
367
|
* @private
|
|
125
368
|
*/
|
|
126
|
-
|
|
369
|
+
shouldUpdatePreviews_(candidate, dxy) {
|
|
370
|
+
const candidateLocal = candidate.local;
|
|
371
|
+
const candidateClosest = candidate.closest;
|
|
372
|
+
const radius = candidate.radius;
|
|
373
|
+
|
|
374
|
+
// Found a connection!
|
|
375
|
+
if (candidateLocal && candidateClosest) {
|
|
376
|
+
// We're already showing an insertion marker.
|
|
377
|
+
// Decide whether the new connection has higher priority.
|
|
378
|
+
if (this.localConnection_ && this.closestConnection_) {
|
|
379
|
+
// The connection was the same as the current connection.
|
|
380
|
+
if (this.closestConnection_ === candidateClosest &&
|
|
381
|
+
this.localConnection_ === candidateLocal) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
const xDiff =
|
|
385
|
+
this.localConnection_.x + dxy.x - this.closestConnection_.x;
|
|
386
|
+
const yDiff =
|
|
387
|
+
this.localConnection_.y + dxy.y - this.closestConnection_.y;
|
|
388
|
+
const curDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
|
389
|
+
// Slightly prefer the existing preview over a new preview.
|
|
390
|
+
return !(
|
|
391
|
+
candidateClosest &&
|
|
392
|
+
radius > curDistance - config.currentConnectionPreference);
|
|
393
|
+
} else if (!this.localConnection_ && !this.closestConnection_) {
|
|
394
|
+
// We weren't showing a preview before, but we should now.
|
|
395
|
+
return true;
|
|
396
|
+
} else {
|
|
397
|
+
console.error(
|
|
398
|
+
'Only one of localConnection_ and closestConnection_ was set.');
|
|
399
|
+
}
|
|
400
|
+
} else { // No connection found.
|
|
401
|
+
// Only need to update if we were showing a preview before.
|
|
402
|
+
return !!(this.localConnection_ && this.closestConnection_);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
console.error(
|
|
406
|
+
'Returning true from shouldUpdatePreviews, but it\'s not clear why.');
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
127
409
|
|
|
128
410
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
411
|
+
* Find the nearest valid connection, which may be the same as the current
|
|
412
|
+
* closest connection.
|
|
413
|
+
* @param {!Coordinate} dxy Position relative to drag start,
|
|
414
|
+
* in workspace units.
|
|
415
|
+
* @return {!Object} An object containing a local connection, a closest
|
|
416
|
+
* connection, and a radius.
|
|
131
417
|
* @private
|
|
132
418
|
*/
|
|
133
|
-
|
|
419
|
+
getCandidate_(dxy) {
|
|
420
|
+
let radius = this.getStartRadius_();
|
|
421
|
+
let candidateClosest = null;
|
|
422
|
+
let candidateLocal = null;
|
|
423
|
+
|
|
424
|
+
// It's possible that a block has added or removed connections during a
|
|
425
|
+
// drag, (e.g. in a drag/move event handler), so let's update the available
|
|
426
|
+
// connections. Note that this will be called on every move while dragging,
|
|
427
|
+
// so it might cause slowness, especially if the block stack is large. If
|
|
428
|
+
// so, maybe it could be made more efficient. Also note that we won't update
|
|
429
|
+
// the connections if we've already connected the insertion marker to a
|
|
430
|
+
// block.
|
|
431
|
+
if (!this.markerConnection_ || !this.markerConnection_.isConnected()) {
|
|
432
|
+
this.updateAvailableConnections();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
for (let i = 0; i < this.availableConnections_.length; i++) {
|
|
436
|
+
const myConnection = this.availableConnections_[i];
|
|
437
|
+
const neighbour = myConnection.closest(radius, dxy);
|
|
438
|
+
if (neighbour.connection) {
|
|
439
|
+
candidateClosest = neighbour.connection;
|
|
440
|
+
candidateLocal = myConnection;
|
|
441
|
+
radius = neighbour.radius;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return {closest: candidateClosest, local: candidateLocal, radius: radius};
|
|
445
|
+
}
|
|
134
446
|
|
|
135
447
|
/**
|
|
136
|
-
*
|
|
137
|
-
* @
|
|
448
|
+
* Decide the radius at which to start searching for the closest connection.
|
|
449
|
+
* @return {number} The radius at which to start the search for the closest
|
|
450
|
+
* connection.
|
|
138
451
|
* @private
|
|
139
452
|
*/
|
|
140
|
-
|
|
453
|
+
getStartRadius_() {
|
|
454
|
+
// If there is already a connection highlighted,
|
|
455
|
+
// increase the radius we check for making new connections.
|
|
456
|
+
// Why? When a connection is highlighted, blocks move around when the
|
|
457
|
+
// insertion marker is created, which could cause the connection became out
|
|
458
|
+
// of range. By increasing radiusConnection when a connection already
|
|
459
|
+
// exists, we never "lose" the connection from the offset.
|
|
460
|
+
if (this.closestConnection_ && this.localConnection_) {
|
|
461
|
+
return config.connectingSnapRadius;
|
|
462
|
+
}
|
|
463
|
+
return config.snapRadius;
|
|
464
|
+
}
|
|
141
465
|
|
|
142
466
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* @
|
|
467
|
+
* Whether ending the drag would delete the block.
|
|
468
|
+
* @param {!Object} candidate An object containing a local connection, a
|
|
469
|
+
* closest
|
|
470
|
+
* connection, and a radius.
|
|
471
|
+
* @param {?IDragTarget} dragTarget The drag target that the block is
|
|
472
|
+
* currently over.
|
|
473
|
+
* @return {boolean} Whether dropping the block immediately would delete the
|
|
474
|
+
* block.
|
|
148
475
|
* @private
|
|
149
476
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
INPUT_OUTLINE: 1,
|
|
161
|
-
REPLACEMENT_FADE: 2,
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* An error message to throw if the block created by createMarkerBlock_ is
|
|
166
|
-
* missing any components.
|
|
167
|
-
* @type {string}
|
|
168
|
-
* @const
|
|
169
|
-
*/
|
|
170
|
-
InsertionMarkerManager.DUPLICATE_BLOCK_ERROR = 'The insertion marker ' +
|
|
171
|
-
'manager tried to create a marker but the result is missing %1. If ' +
|
|
172
|
-
'you are using a mutator, make sure your domToMutation method is ' +
|
|
173
|
-
'properly defined.';
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Sever all links from this object.
|
|
177
|
-
* @package
|
|
178
|
-
*/
|
|
179
|
-
InsertionMarkerManager.prototype.dispose = function() {
|
|
180
|
-
this.availableConnections_.length = 0;
|
|
181
|
-
|
|
182
|
-
eventUtils.disable();
|
|
183
|
-
try {
|
|
184
|
-
if (this.firstMarker_) {
|
|
185
|
-
this.firstMarker_.dispose();
|
|
186
|
-
}
|
|
187
|
-
if (this.lastMarker_) {
|
|
188
|
-
this.lastMarker_.dispose();
|
|
477
|
+
shouldDelete_(candidate, dragTarget) {
|
|
478
|
+
if (dragTarget) {
|
|
479
|
+
const componentManager = this.workspace_.getComponentManager();
|
|
480
|
+
const isDeleteArea = componentManager.hasCapability(
|
|
481
|
+
dragTarget.id, ComponentManager.Capability.DELETE_AREA);
|
|
482
|
+
if (isDeleteArea) {
|
|
483
|
+
return (
|
|
484
|
+
/** @type {!IDeleteArea} */ (dragTarget))
|
|
485
|
+
.wouldDelete(this.topBlock_, candidate && !!candidate.closest);
|
|
486
|
+
}
|
|
189
487
|
}
|
|
190
|
-
|
|
191
|
-
eventUtils.enable();
|
|
488
|
+
return false;
|
|
192
489
|
}
|
|
193
|
-
};
|
|
194
490
|
|
|
195
|
-
/**
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return this.wouldDeleteBlock_;
|
|
212
|
-
};
|
|
491
|
+
/**
|
|
492
|
+
* Show an insertion marker or replacement highlighting during a drag, if
|
|
493
|
+
* needed.
|
|
494
|
+
* At the beginning of this function, this.localConnection_ and
|
|
495
|
+
* this.closestConnection_ should both be null.
|
|
496
|
+
* @param {!Object} candidate An object containing a local connection, a
|
|
497
|
+
* closest connection, and a radius.
|
|
498
|
+
* @private
|
|
499
|
+
*/
|
|
500
|
+
maybeShowPreview_(candidate) {
|
|
501
|
+
// Nope, don't add a marker.
|
|
502
|
+
if (this.wouldDeleteBlock_) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const closest = candidate.closest;
|
|
506
|
+
const local = candidate.local;
|
|
213
507
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
* immediately.
|
|
219
|
-
* @package
|
|
220
|
-
*/
|
|
221
|
-
InsertionMarkerManager.prototype.wouldConnectBlock = function() {
|
|
222
|
-
return !!this.closestConnection_;
|
|
223
|
-
};
|
|
508
|
+
// Nothing to connect to.
|
|
509
|
+
if (!closest) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
224
512
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (this.closestConnection_) {
|
|
232
|
-
// Don't fire events for insertion markers.
|
|
233
|
-
eventUtils.disable();
|
|
234
|
-
this.hidePreview_();
|
|
235
|
-
eventUtils.enable();
|
|
236
|
-
// Connect two blocks together.
|
|
237
|
-
this.localConnection_.connect(this.closestConnection_);
|
|
238
|
-
if (this.topBlock_.rendered) {
|
|
239
|
-
// Trigger a connection animation.
|
|
240
|
-
// Determine which connection is inferior (lower in the source stack).
|
|
241
|
-
const inferiorConnection = this.localConnection_.isSuperior() ?
|
|
242
|
-
this.closestConnection_ :
|
|
243
|
-
this.localConnection_;
|
|
244
|
-
blockAnimations.connectionUiEffect(inferiorConnection.getSourceBlock());
|
|
245
|
-
// Bring the just-edited stack to the front.
|
|
246
|
-
const rootBlock = this.topBlock_.getRootBlock();
|
|
247
|
-
rootBlock.bringToFront();
|
|
513
|
+
// Something went wrong and we're trying to connect to an invalid
|
|
514
|
+
// connection.
|
|
515
|
+
if (closest === this.closestConnection_ ||
|
|
516
|
+
closest.getSourceBlock().isInsertionMarker()) {
|
|
517
|
+
console.log('Trying to connect to an insertion marker');
|
|
518
|
+
return;
|
|
248
519
|
}
|
|
520
|
+
// Add an insertion marker or replacement marker.
|
|
521
|
+
this.closestConnection_ = closest;
|
|
522
|
+
this.localConnection_ = local;
|
|
523
|
+
this.showPreview_();
|
|
249
524
|
}
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Update connections based on the most recent move location.
|
|
254
|
-
* @param {!Coordinate} dxy Position relative to drag start,
|
|
255
|
-
* in workspace units.
|
|
256
|
-
* @param {?IDragTarget} dragTarget The drag target that the block is
|
|
257
|
-
* currently over.
|
|
258
|
-
* @package
|
|
259
|
-
*/
|
|
260
|
-
InsertionMarkerManager.prototype.update = function(dxy, dragTarget) {
|
|
261
|
-
const candidate = this.getCandidate_(dxy);
|
|
262
|
-
|
|
263
|
-
this.wouldDeleteBlock_ = this.shouldDelete_(candidate, dragTarget);
|
|
264
525
|
|
|
265
|
-
|
|
266
|
-
|
|
526
|
+
/**
|
|
527
|
+
* A preview should be shown. This function figures out if it should be a
|
|
528
|
+
* block highlight or an insertion marker, and shows the appropriate one.
|
|
529
|
+
* @private
|
|
530
|
+
*/
|
|
531
|
+
showPreview_() {
|
|
532
|
+
const closest = this.closestConnection_;
|
|
533
|
+
const renderer = this.workspace_.getRenderer();
|
|
534
|
+
const method = renderer.getConnectionPreviewMethod(
|
|
535
|
+
/** @type {!RenderedConnection} */ (closest),
|
|
536
|
+
/** @type {!RenderedConnection} */ (this.localConnection_),
|
|
537
|
+
this.topBlock_);
|
|
538
|
+
|
|
539
|
+
switch (method) {
|
|
540
|
+
case InsertionMarkerManager.PREVIEW_TYPE.INPUT_OUTLINE:
|
|
541
|
+
this.showInsertionInputOutline_();
|
|
542
|
+
break;
|
|
543
|
+
case InsertionMarkerManager.PREVIEW_TYPE.INSERTION_MARKER:
|
|
544
|
+
this.showInsertionMarker_();
|
|
545
|
+
break;
|
|
546
|
+
case InsertionMarkerManager.PREVIEW_TYPE.REPLACEMENT_FADE:
|
|
547
|
+
this.showReplacementFade_();
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
267
550
|
|
|
268
|
-
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
eventUtils.enable();
|
|
551
|
+
// Optionally highlight the actual connection, as a nod to previous
|
|
552
|
+
// behaviour.
|
|
553
|
+
if (closest && renderer.shouldHighlightConnection(closest)) {
|
|
554
|
+
closest.highlight();
|
|
555
|
+
}
|
|
274
556
|
}
|
|
275
|
-
};
|
|
276
557
|
|
|
277
|
-
/**
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
// Copy field values from the other block. These values may impact the
|
|
305
|
-
// rendered size of the insertion marker. Note that we do not care about
|
|
306
|
-
// child blocks here.
|
|
307
|
-
for (let i = 0; i < sourceBlock.inputList.length; i++) {
|
|
308
|
-
const sourceInput = sourceBlock.inputList[i];
|
|
309
|
-
if (sourceInput.name === constants.COLLAPSED_INPUT_NAME) {
|
|
310
|
-
continue; // Ignore the collapsed input.
|
|
311
|
-
}
|
|
312
|
-
const resultInput = result.inputList[i];
|
|
313
|
-
if (!resultInput) {
|
|
314
|
-
throw new Error(InsertionMarkerManager.DUPLICATE_BLOCK_ERROR.replace(
|
|
315
|
-
'%1', 'an input'));
|
|
316
|
-
}
|
|
317
|
-
for (let j = 0; j < sourceInput.fieldRow.length; j++) {
|
|
318
|
-
const sourceField = sourceInput.fieldRow[j];
|
|
319
|
-
const resultField = resultInput.fieldRow[j];
|
|
320
|
-
if (!resultField) {
|
|
321
|
-
throw new Error(InsertionMarkerManager.DUPLICATE_BLOCK_ERROR.replace(
|
|
322
|
-
'%1', 'a field'));
|
|
323
|
-
}
|
|
324
|
-
resultField.setValue(sourceField.getValue());
|
|
558
|
+
/**
|
|
559
|
+
* Show an insertion marker or replacement highlighting during a drag, if
|
|
560
|
+
* needed.
|
|
561
|
+
* At the end of this function, this.localConnection_ and
|
|
562
|
+
* this.closestConnection_ should both be null.
|
|
563
|
+
* @param {!Object} candidate An object containing a local connection, a
|
|
564
|
+
* closest connection, and a radius.
|
|
565
|
+
* @private
|
|
566
|
+
*/
|
|
567
|
+
maybeHidePreview_(candidate) {
|
|
568
|
+
// If there's no new preview, remove the old one but don't bother deleting
|
|
569
|
+
// it. We might need it later, and this saves disposing of it and recreating
|
|
570
|
+
// it.
|
|
571
|
+
if (!candidate.closest) {
|
|
572
|
+
this.hidePreview_();
|
|
573
|
+
} else {
|
|
574
|
+
// If there's a new preview and there was an preview before, and either
|
|
575
|
+
// connection has changed, remove the old preview.
|
|
576
|
+
const hadPreview = this.closestConnection_ && this.localConnection_;
|
|
577
|
+
const closestChanged = this.closestConnection_ !== candidate.closest;
|
|
578
|
+
const localChanged = this.localConnection_ !== candidate.local;
|
|
579
|
+
|
|
580
|
+
// Also hide if we had a preview before but now we're going to delete
|
|
581
|
+
// instead.
|
|
582
|
+
if (hadPreview &&
|
|
583
|
+
(closestChanged || localChanged || this.wouldDeleteBlock_)) {
|
|
584
|
+
this.hidePreview_();
|
|
325
585
|
}
|
|
326
586
|
}
|
|
327
587
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
result.getSvgRoot().setAttribute('visibility', 'hidden');
|
|
333
|
-
} finally {
|
|
334
|
-
eventUtils.enable();
|
|
588
|
+
// Either way, clear out old state.
|
|
589
|
+
this.markerConnection_ = null;
|
|
590
|
+
this.closestConnection_ = null;
|
|
591
|
+
this.localConnection_ = null;
|
|
335
592
|
}
|
|
336
593
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
* @private
|
|
348
|
-
*/
|
|
349
|
-
InsertionMarkerManager.prototype.initAvailableConnections_ = function() {
|
|
350
|
-
const available = this.topBlock_.getConnections_(false);
|
|
351
|
-
// Also check the last connection on this stack
|
|
352
|
-
const lastOnStack = this.topBlock_.lastConnectionInStack(true);
|
|
353
|
-
if (lastOnStack && lastOnStack !== this.topBlock_.nextConnection) {
|
|
354
|
-
available.push(lastOnStack);
|
|
355
|
-
this.lastOnStack_ = lastOnStack;
|
|
356
|
-
if (this.lastMarker_) {
|
|
357
|
-
eventUtils.disable();
|
|
358
|
-
try {
|
|
359
|
-
this.lastMarker_.dispose();
|
|
360
|
-
} finally {
|
|
361
|
-
eventUtils.enable();
|
|
362
|
-
}
|
|
594
|
+
/**
|
|
595
|
+
* A preview should be hidden. This function figures out if it is a block
|
|
596
|
+
* highlight or an insertion marker, and hides the appropriate one.
|
|
597
|
+
* @private
|
|
598
|
+
*/
|
|
599
|
+
hidePreview_() {
|
|
600
|
+
if (this.closestConnection_ && this.closestConnection_.targetBlock() &&
|
|
601
|
+
this.workspace_.getRenderer().shouldHighlightConnection(
|
|
602
|
+
this.closestConnection_)) {
|
|
603
|
+
this.closestConnection_.unhighlight();
|
|
363
604
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
* Whether the previews (insertion marker and replacement marker) should be
|
|
371
|
-
* updated based on the closest candidate and the current drag distance.
|
|
372
|
-
* @param {!Object} candidate An object containing a local connection, a closest
|
|
373
|
-
* connection, and a radius. Returned by getCandidate_.
|
|
374
|
-
* @param {!Coordinate} dxy Position relative to drag start,
|
|
375
|
-
* in workspace units.
|
|
376
|
-
* @return {boolean} Whether the preview should be updated.
|
|
377
|
-
* @private
|
|
378
|
-
*/
|
|
379
|
-
InsertionMarkerManager.prototype.shouldUpdatePreviews_ = function(
|
|
380
|
-
candidate, dxy) {
|
|
381
|
-
const candidateLocal = candidate.local;
|
|
382
|
-
const candidateClosest = candidate.closest;
|
|
383
|
-
const radius = candidate.radius;
|
|
384
|
-
|
|
385
|
-
// Found a connection!
|
|
386
|
-
if (candidateLocal && candidateClosest) {
|
|
387
|
-
// We're already showing an insertion marker.
|
|
388
|
-
// Decide whether the new connection has higher priority.
|
|
389
|
-
if (this.localConnection_ && this.closestConnection_) {
|
|
390
|
-
// The connection was the same as the current connection.
|
|
391
|
-
if (this.closestConnection_ === candidateClosest &&
|
|
392
|
-
this.localConnection_ === candidateLocal) {
|
|
393
|
-
return false;
|
|
394
|
-
}
|
|
395
|
-
const xDiff = this.localConnection_.x + dxy.x - this.closestConnection_.x;
|
|
396
|
-
const yDiff = this.localConnection_.y + dxy.y - this.closestConnection_.y;
|
|
397
|
-
const curDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
|
398
|
-
// Slightly prefer the existing preview over a new preview.
|
|
399
|
-
return !(
|
|
400
|
-
candidateClosest &&
|
|
401
|
-
radius >
|
|
402
|
-
curDistance - internalConstants.CURRENT_CONNECTION_PREFERENCE);
|
|
403
|
-
} else if (!this.localConnection_ && !this.closestConnection_) {
|
|
404
|
-
// We weren't showing a preview before, but we should now.
|
|
405
|
-
return true;
|
|
406
|
-
} else {
|
|
407
|
-
console.error(
|
|
408
|
-
'Only one of localConnection_ and closestConnection_ was set.');
|
|
605
|
+
if (this.fadedBlock_) {
|
|
606
|
+
this.hideReplacementFade_();
|
|
607
|
+
} else if (this.highlightedBlock_) {
|
|
608
|
+
this.hideInsertionInputOutline_();
|
|
609
|
+
} else if (this.markerConnection_) {
|
|
610
|
+
this.hideInsertionMarker_();
|
|
409
611
|
}
|
|
410
|
-
} else { // No connection found.
|
|
411
|
-
// Only need to update if we were showing a preview before.
|
|
412
|
-
return !!(this.localConnection_ && this.closestConnection_);
|
|
413
612
|
}
|
|
414
613
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
614
|
+
/**
|
|
615
|
+
* Shows an insertion marker connected to the appropriate blocks (based on
|
|
616
|
+
* manager state).
|
|
617
|
+
* @private
|
|
618
|
+
*/
|
|
619
|
+
showInsertionMarker_() {
|
|
620
|
+
const local = this.localConnection_;
|
|
621
|
+
const closest = this.closestConnection_;
|
|
622
|
+
|
|
623
|
+
const isLastInStack = this.lastOnStack_ && local === this.lastOnStack_;
|
|
624
|
+
let imBlock = isLastInStack ? this.lastMarker_ : this.firstMarker_;
|
|
625
|
+
let imConn;
|
|
626
|
+
try {
|
|
627
|
+
imConn = imBlock.getMatchingConnection(local.getSourceBlock(), local);
|
|
628
|
+
} catch (e) {
|
|
629
|
+
// It's possible that the number of connections on the local block has
|
|
630
|
+
// changed since the insertion marker was originally created. Let's
|
|
631
|
+
// recreate the insertion marker and try again. In theory we could
|
|
632
|
+
// probably recreate the marker block (e.g. in getCandidate_), which is
|
|
633
|
+
// called more often during the drag, but creating a block that often
|
|
634
|
+
// might be too slow, so we only do it if necessary.
|
|
635
|
+
this.firstMarker_ = this.createMarkerBlock_(this.topBlock_);
|
|
636
|
+
imBlock = isLastInStack ? this.lastMarker_ : this.firstMarker_;
|
|
637
|
+
imConn = imBlock.getMatchingConnection(local.getSourceBlock(), local);
|
|
638
|
+
}
|
|
419
639
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
* in workspace units.
|
|
425
|
-
* @return {!Object} An object containing a local connection, a closest
|
|
426
|
-
* connection, and a radius.
|
|
427
|
-
* @private
|
|
428
|
-
*/
|
|
429
|
-
InsertionMarkerManager.prototype.getCandidate_ = function(dxy) {
|
|
430
|
-
let radius = this.getStartRadius_();
|
|
431
|
-
let candidateClosest = null;
|
|
432
|
-
let candidateLocal = null;
|
|
433
|
-
|
|
434
|
-
for (let i = 0; i < this.availableConnections_.length; i++) {
|
|
435
|
-
const myConnection = this.availableConnections_[i];
|
|
436
|
-
const neighbour = myConnection.closest(radius, dxy);
|
|
437
|
-
if (neighbour.connection) {
|
|
438
|
-
candidateClosest = neighbour.connection;
|
|
439
|
-
candidateLocal = myConnection;
|
|
440
|
-
radius = neighbour.radius;
|
|
640
|
+
if (imConn === this.markerConnection_) {
|
|
641
|
+
throw Error(
|
|
642
|
+
'Made it to showInsertionMarker_ even though the marker isn\'t ' +
|
|
643
|
+
'changing');
|
|
441
644
|
}
|
|
442
|
-
}
|
|
443
|
-
return {closest: candidateClosest, local: candidateLocal, radius: radius};
|
|
444
|
-
};
|
|
445
645
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
*/
|
|
452
|
-
InsertionMarkerManager.prototype.getStartRadius_ = function() {
|
|
453
|
-
// If there is already a connection highlighted,
|
|
454
|
-
// increase the radius we check for making new connections.
|
|
455
|
-
// Why? When a connection is highlighted, blocks move around when the
|
|
456
|
-
// insertion marker is created, which could cause the connection became out of
|
|
457
|
-
// range. By increasing radiusConnection when a connection already exists, we
|
|
458
|
-
// never "lose" the connection from the offset.
|
|
459
|
-
if (this.closestConnection_ && this.localConnection_) {
|
|
460
|
-
return internalConstants.CONNECTING_SNAP_RADIUS;
|
|
461
|
-
}
|
|
462
|
-
return internalConstants.SNAP_RADIUS;
|
|
463
|
-
};
|
|
646
|
+
// Render disconnected from everything else so that we have a valid
|
|
647
|
+
// connection location.
|
|
648
|
+
imBlock.render();
|
|
649
|
+
imBlock.rendered = true;
|
|
650
|
+
imBlock.getSvgRoot().setAttribute('visibility', 'visible');
|
|
464
651
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
* block.
|
|
473
|
-
* @private
|
|
474
|
-
*/
|
|
475
|
-
InsertionMarkerManager.prototype.shouldDelete_ = function(
|
|
476
|
-
candidate, dragTarget) {
|
|
477
|
-
if (dragTarget) {
|
|
478
|
-
const componentManager = this.workspace_.getComponentManager();
|
|
479
|
-
const isDeleteArea = componentManager.hasCapability(
|
|
480
|
-
dragTarget.id, ComponentManager.Capability.DELETE_AREA);
|
|
481
|
-
if (isDeleteArea) {
|
|
482
|
-
return (
|
|
483
|
-
/** @type {!IDeleteArea} */ (dragTarget))
|
|
484
|
-
.wouldDelete(this.topBlock_, candidate && !!candidate.closest);
|
|
652
|
+
if (imConn && closest) {
|
|
653
|
+
// Position so that the existing block doesn't move.
|
|
654
|
+
imBlock.positionNearConnection(imConn, closest);
|
|
655
|
+
}
|
|
656
|
+
if (closest) {
|
|
657
|
+
// Connect() also renders the insertion marker.
|
|
658
|
+
imConn.connect(closest);
|
|
485
659
|
}
|
|
486
|
-
}
|
|
487
|
-
return false;
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Show an insertion marker or replacement highlighting during a drag, if
|
|
492
|
-
* needed.
|
|
493
|
-
* At the beginning of this function, this.localConnection_ and
|
|
494
|
-
* this.closestConnection_ should both be null.
|
|
495
|
-
* @param {!Object} candidate An object containing a local connection, a closest
|
|
496
|
-
* connection, and a radius.
|
|
497
|
-
* @private
|
|
498
|
-
*/
|
|
499
|
-
InsertionMarkerManager.prototype.maybeShowPreview_ = function(candidate) {
|
|
500
|
-
// Nope, don't add a marker.
|
|
501
|
-
if (this.wouldDeleteBlock_) {
|
|
502
|
-
return;
|
|
503
|
-
}
|
|
504
|
-
const closest = candidate.closest;
|
|
505
|
-
const local = candidate.local;
|
|
506
660
|
|
|
507
|
-
|
|
508
|
-
if (!closest) {
|
|
509
|
-
return;
|
|
661
|
+
this.markerConnection_ = imConn;
|
|
510
662
|
}
|
|
511
663
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
};
|
|
664
|
+
/**
|
|
665
|
+
* Disconnects and hides the current insertion marker. Should return the
|
|
666
|
+
* blocks to their original state.
|
|
667
|
+
* @private
|
|
668
|
+
*/
|
|
669
|
+
hideInsertionMarker_() {
|
|
670
|
+
if (!this.markerConnection_) {
|
|
671
|
+
console.log('No insertion marker connection to disconnect');
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
523
674
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
675
|
+
const imConn = this.markerConnection_;
|
|
676
|
+
const imBlock = imConn.getSourceBlock();
|
|
677
|
+
const markerNext = imBlock.nextConnection;
|
|
678
|
+
const markerPrev = imBlock.previousConnection;
|
|
679
|
+
const markerOutput = imBlock.outputConnection;
|
|
680
|
+
|
|
681
|
+
const isFirstInStatementStack =
|
|
682
|
+
(imConn === markerNext && !(markerPrev && markerPrev.targetConnection));
|
|
683
|
+
|
|
684
|
+
const isFirstInOutputStack = imConn.type === ConnectionType.INPUT_VALUE &&
|
|
685
|
+
!(markerOutput && markerOutput.targetConnection);
|
|
686
|
+
// The insertion marker is the first block in a stack. Unplug won't do
|
|
687
|
+
// anything in that case. Instead, unplug the following block.
|
|
688
|
+
if (isFirstInStatementStack || isFirstInOutputStack) {
|
|
689
|
+
imConn.targetBlock().unplug(false);
|
|
690
|
+
} else if (
|
|
691
|
+
imConn.type === ConnectionType.NEXT_STATEMENT &&
|
|
692
|
+
imConn !== markerNext) {
|
|
693
|
+
// Inside of a C-block, first statement connection.
|
|
694
|
+
const innerConnection = imConn.targetConnection;
|
|
695
|
+
innerConnection.getSourceBlock().unplug(false);
|
|
696
|
+
|
|
697
|
+
const previousBlockNextConnection =
|
|
698
|
+
markerPrev ? markerPrev.targetConnection : null;
|
|
699
|
+
|
|
700
|
+
imBlock.unplug(true);
|
|
701
|
+
if (previousBlockNextConnection) {
|
|
702
|
+
previousBlockNextConnection.connect(innerConnection);
|
|
703
|
+
}
|
|
704
|
+
} else {
|
|
705
|
+
imBlock.unplug(true /* healStack */);
|
|
706
|
+
}
|
|
548
707
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
708
|
+
if (imConn.targetConnection) {
|
|
709
|
+
throw Error(
|
|
710
|
+
'markerConnection_ still connected at the end of ' +
|
|
711
|
+
'disconnectInsertionMarker');
|
|
712
|
+
}
|
|
554
713
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
* this.closestConnection_ should both be null.
|
|
560
|
-
* @param {!Object} candidate An object containing a local connection, a closest
|
|
561
|
-
* connection, and a radius.
|
|
562
|
-
* @private
|
|
563
|
-
*/
|
|
564
|
-
InsertionMarkerManager.prototype.maybeHidePreview_ = function(candidate) {
|
|
565
|
-
// If there's no new preview, remove the old one but don't bother deleting it.
|
|
566
|
-
// We might need it later, and this saves disposing of it and recreating it.
|
|
567
|
-
if (!candidate.closest) {
|
|
568
|
-
this.hidePreview_();
|
|
569
|
-
} else {
|
|
570
|
-
// If there's a new preview and there was an preview before, and either
|
|
571
|
-
// connection has changed, remove the old preview.
|
|
572
|
-
const hadPreview = this.closestConnection_ && this.localConnection_;
|
|
573
|
-
const closestChanged = this.closestConnection_ !== candidate.closest;
|
|
574
|
-
const localChanged = this.localConnection_ !== candidate.local;
|
|
575
|
-
|
|
576
|
-
// Also hide if we had a preview before but now we're going to delete
|
|
577
|
-
// instead.
|
|
578
|
-
if (hadPreview &&
|
|
579
|
-
(closestChanged || localChanged || this.wouldDeleteBlock_)) {
|
|
580
|
-
this.hidePreview_();
|
|
714
|
+
this.markerConnection_ = null;
|
|
715
|
+
const svg = imBlock.getSvgRoot();
|
|
716
|
+
if (svg) {
|
|
717
|
+
svg.setAttribute('visibility', 'hidden');
|
|
581
718
|
}
|
|
582
719
|
}
|
|
583
720
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
* highlight or an insertion marker, and hides the appropriate one.
|
|
593
|
-
* @private
|
|
594
|
-
*/
|
|
595
|
-
InsertionMarkerManager.prototype.hidePreview_ = function() {
|
|
596
|
-
if (this.closestConnection_ && this.closestConnection_.targetBlock() &&
|
|
597
|
-
this.workspace_.getRenderer().shouldHighlightConnection(
|
|
598
|
-
this.closestConnection_)) {
|
|
599
|
-
this.closestConnection_.unhighlight();
|
|
600
|
-
}
|
|
601
|
-
if (this.fadedBlock_) {
|
|
602
|
-
this.hideReplacementFade_();
|
|
603
|
-
} else if (this.highlightedBlock_) {
|
|
604
|
-
this.hideInsertionInputOutline_();
|
|
605
|
-
} else if (this.markerConnection_) {
|
|
606
|
-
this.hideInsertionMarker_();
|
|
721
|
+
/**
|
|
722
|
+
* Shows an outline around the input the closest connection belongs to.
|
|
723
|
+
* @private
|
|
724
|
+
*/
|
|
725
|
+
showInsertionInputOutline_() {
|
|
726
|
+
const closest = this.closestConnection_;
|
|
727
|
+
this.highlightedBlock_ = closest.getSourceBlock();
|
|
728
|
+
this.highlightedBlock_.highlightShapeForInput(closest, true);
|
|
607
729
|
}
|
|
608
|
-
};
|
|
609
730
|
|
|
610
|
-
/**
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
const isLastInStack = this.lastOnStack_ && local === this.lastOnStack_;
|
|
620
|
-
const imBlock = isLastInStack ? this.lastMarker_ : this.firstMarker_;
|
|
621
|
-
const imConn = imBlock.getMatchingConnection(local.getSourceBlock(), local);
|
|
622
|
-
|
|
623
|
-
if (imConn === this.markerConnection_) {
|
|
624
|
-
throw Error(
|
|
625
|
-
'Made it to showInsertionMarker_ even though the marker isn\'t ' +
|
|
626
|
-
'changing');
|
|
731
|
+
/**
|
|
732
|
+
* Hides any visible input outlines.
|
|
733
|
+
* @private
|
|
734
|
+
*/
|
|
735
|
+
hideInsertionInputOutline_() {
|
|
736
|
+
this.highlightedBlock_.highlightShapeForInput(
|
|
737
|
+
this.closestConnection_, false);
|
|
738
|
+
this.highlightedBlock_ = null;
|
|
627
739
|
}
|
|
628
740
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
imBlock.positionNearConnection(imConn, closest);
|
|
638
|
-
}
|
|
639
|
-
if (closest) {
|
|
640
|
-
// Connect() also renders the insertion marker.
|
|
641
|
-
imConn.connect(closest);
|
|
741
|
+
/**
|
|
742
|
+
* Shows a replacement fade affect on the closest connection's target block
|
|
743
|
+
* (the block that is currently connected to it).
|
|
744
|
+
* @private
|
|
745
|
+
*/
|
|
746
|
+
showReplacementFade_() {
|
|
747
|
+
this.fadedBlock_ = this.closestConnection_.targetBlock();
|
|
748
|
+
this.fadedBlock_.fadeForReplacement(true);
|
|
642
749
|
}
|
|
643
750
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
*/
|
|
652
|
-
InsertionMarkerManager.prototype.hideInsertionMarker_ = function() {
|
|
653
|
-
if (!this.markerConnection_) {
|
|
654
|
-
console.log('No insertion marker connection to disconnect');
|
|
655
|
-
return;
|
|
751
|
+
/**
|
|
752
|
+
* Hides/Removes any visible fade affects.
|
|
753
|
+
* @private
|
|
754
|
+
*/
|
|
755
|
+
hideReplacementFade_() {
|
|
756
|
+
this.fadedBlock_.fadeForReplacement(false);
|
|
757
|
+
this.fadedBlock_ = null;
|
|
656
758
|
}
|
|
657
759
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
// The insertion marker is the first block in a stack. Unplug won't do
|
|
670
|
-
// anything in that case. Instead, unplug the following block.
|
|
671
|
-
if (isFirstInStatementStack || isFirstInOutputStack) {
|
|
672
|
-
imConn.targetBlock().unplug(false);
|
|
673
|
-
} else if (
|
|
674
|
-
imConn.type === ConnectionType.NEXT_STATEMENT && imConn !== markerNext) {
|
|
675
|
-
// Inside of a C-block, first statement connection.
|
|
676
|
-
const innerConnection = imConn.targetConnection;
|
|
677
|
-
innerConnection.getSourceBlock().unplug(false);
|
|
678
|
-
|
|
679
|
-
const previousBlockNextConnection =
|
|
680
|
-
markerPrev ? markerPrev.targetConnection : null;
|
|
681
|
-
|
|
682
|
-
imBlock.unplug(true);
|
|
683
|
-
if (previousBlockNextConnection) {
|
|
684
|
-
previousBlockNextConnection.connect(innerConnection);
|
|
760
|
+
/**
|
|
761
|
+
* Get a list of the insertion markers that currently exist. Drags have 0, 1,
|
|
762
|
+
* or 2 insertion markers.
|
|
763
|
+
* @return {!Array<!BlockSvg>} A possibly empty list of insertion
|
|
764
|
+
* marker blocks.
|
|
765
|
+
* @package
|
|
766
|
+
*/
|
|
767
|
+
getInsertionMarkers() {
|
|
768
|
+
const result = [];
|
|
769
|
+
if (this.firstMarker_) {
|
|
770
|
+
result.push(this.firstMarker_);
|
|
685
771
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
if (imConn.targetConnection) {
|
|
691
|
-
throw Error(
|
|
692
|
-
'markerConnection_ still connected at the end of ' +
|
|
693
|
-
'disconnectInsertionMarker');
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
this.markerConnection_ = null;
|
|
697
|
-
const svg = imBlock.getSvgRoot();
|
|
698
|
-
if (svg) {
|
|
699
|
-
svg.setAttribute('visibility', 'hidden');
|
|
772
|
+
if (this.lastMarker_) {
|
|
773
|
+
result.push(this.lastMarker_);
|
|
774
|
+
}
|
|
775
|
+
return result;
|
|
700
776
|
}
|
|
701
|
-
}
|
|
777
|
+
}
|
|
702
778
|
|
|
703
779
|
/**
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
|
|
707
|
-
InsertionMarkerManager.prototype.showInsertionInputOutline_ = function() {
|
|
708
|
-
const closest = this.closestConnection_;
|
|
709
|
-
this.highlightedBlock_ = closest.getSourceBlock();
|
|
710
|
-
this.highlightedBlock_.highlightShapeForInput(closest, true);
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Hides any visible input outlines.
|
|
715
|
-
* @private
|
|
716
|
-
*/
|
|
717
|
-
InsertionMarkerManager.prototype.hideInsertionInputOutline_ = function() {
|
|
718
|
-
this.highlightedBlock_.highlightShapeForInput(this.closestConnection_, false);
|
|
719
|
-
this.highlightedBlock_ = null;
|
|
720
|
-
};
|
|
721
|
-
|
|
722
|
-
/**
|
|
723
|
-
* Shows a replacement fade affect on the closest connection's target block
|
|
724
|
-
* (the block that is currently connected to it).
|
|
725
|
-
* @private
|
|
726
|
-
*/
|
|
727
|
-
InsertionMarkerManager.prototype.showReplacementFade_ = function() {
|
|
728
|
-
this.fadedBlock_ = this.closestConnection_.targetBlock();
|
|
729
|
-
this.fadedBlock_.fadeForReplacement(true);
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
/**
|
|
733
|
-
* Hides/Removes any visible fade affects.
|
|
734
|
-
* @private
|
|
735
|
-
*/
|
|
736
|
-
InsertionMarkerManager.prototype.hideReplacementFade_ = function() {
|
|
737
|
-
this.fadedBlock_.fadeForReplacement(false);
|
|
738
|
-
this.fadedBlock_ = null;
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
/**
|
|
742
|
-
* Get a list of the insertion markers that currently exist. Drags have 0, 1,
|
|
743
|
-
* or 2 insertion markers.
|
|
744
|
-
* @return {!Array<!BlockSvg>} A possibly empty list of insertion
|
|
745
|
-
* marker blocks.
|
|
746
|
-
* @package
|
|
780
|
+
* An enum describing different kinds of previews the InsertionMarkerManager
|
|
781
|
+
* could display.
|
|
782
|
+
* @enum {number}
|
|
747
783
|
*/
|
|
748
|
-
InsertionMarkerManager.
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
if (this.lastMarker_) {
|
|
754
|
-
result.push(this.lastMarker_);
|
|
755
|
-
}
|
|
756
|
-
return result;
|
|
784
|
+
InsertionMarkerManager.PREVIEW_TYPE = {
|
|
785
|
+
INSERTION_MARKER: 0,
|
|
786
|
+
INPUT_OUTLINE: 1,
|
|
787
|
+
REPLACEMENT_FADE: 2,
|
|
757
788
|
};
|
|
758
789
|
|
|
759
790
|
exports.InsertionMarkerManager = InsertionMarkerManager;
|