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
|
@@ -20,6 +20,8 @@ const idGenerator = goog.require('Blockly.utils.idGenerator');
|
|
|
20
20
|
const xml = goog.require('Blockly.utils.xml');
|
|
21
21
|
const {Coordinate} = goog.require('Blockly.utils.Coordinate');
|
|
22
22
|
/* eslint-disable-next-line no-unused-vars */
|
|
23
|
+
const {CommentMove} = goog.require('Blockly.Events.CommentMove');
|
|
24
|
+
/* eslint-disable-next-line no-unused-vars */
|
|
23
25
|
const {Workspace} = goog.requireType('Blockly.Workspace');
|
|
24
26
|
/** @suppress {extraRequire} */
|
|
25
27
|
goog.require('Blockly.Events.CommentChange');
|
|
@@ -27,364 +29,372 @@ goog.require('Blockly.Events.CommentChange');
|
|
|
27
29
|
goog.require('Blockly.Events.CommentCreate');
|
|
28
30
|
/** @suppress {extraRequire} */
|
|
29
31
|
goog.require('Blockly.Events.CommentDelete');
|
|
30
|
-
/** @suppress {extraRequire} */
|
|
31
|
-
goog.require('Blockly.Events.CommentMove');
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Class for a workspace comment.
|
|
36
|
-
* @param {!Workspace} workspace The block's workspace.
|
|
37
|
-
* @param {string} content The content of this workspace comment.
|
|
38
|
-
* @param {number} height Height of the comment.
|
|
39
|
-
* @param {number} width Width of the comment.
|
|
40
|
-
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
|
|
41
|
-
* create a new ID.
|
|
42
|
-
* @constructor
|
|
43
36
|
* @alias Blockly.WorkspaceComment
|
|
44
37
|
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
class WorkspaceComment {
|
|
39
|
+
/**
|
|
40
|
+
* @param {!Workspace} workspace The block's workspace.
|
|
41
|
+
* @param {string} content The content of this workspace comment.
|
|
42
|
+
* @param {number} height Height of the comment.
|
|
43
|
+
* @param {number} width Width of the comment.
|
|
44
|
+
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
|
|
45
|
+
* create a new ID.
|
|
46
|
+
*/
|
|
47
|
+
constructor(workspace, content, height, width, opt_id) {
|
|
48
|
+
/** @type {string} */
|
|
49
|
+
this.id = (opt_id && !workspace.getCommentById(opt_id)) ?
|
|
50
|
+
opt_id :
|
|
51
|
+
idGenerator.genUid();
|
|
52
|
+
|
|
53
|
+
workspace.addTopComment(this);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The comment's position in workspace units. (0, 0) is at the workspace's
|
|
57
|
+
* origin; scale does not change this value.
|
|
58
|
+
* @type {!Coordinate}
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
this.xy_ = new Coordinate(0, 0);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The comment's height in workspace units. Scale does not change this
|
|
65
|
+
* value.
|
|
66
|
+
* @type {number}
|
|
67
|
+
* @protected
|
|
68
|
+
*/
|
|
69
|
+
this.height_ = height;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The comment's width in workspace units. Scale does not change this
|
|
73
|
+
* value.
|
|
74
|
+
* @type {number}
|
|
75
|
+
* @protected
|
|
76
|
+
*/
|
|
77
|
+
this.width_ = width;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @type {!Workspace}
|
|
81
|
+
*/
|
|
82
|
+
this.workspace = workspace;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @protected
|
|
86
|
+
* @type {boolean}
|
|
87
|
+
*/
|
|
88
|
+
this.RTL = workspace.RTL;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @type {boolean}
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
this.deletable_ = true;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @type {boolean}
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
this.movable_ = true;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @type {boolean}
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
this.editable_ = true;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @protected
|
|
110
|
+
* @type {string}
|
|
111
|
+
*/
|
|
112
|
+
this.content_ = content;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Whether this comment has been disposed.
|
|
116
|
+
* @protected
|
|
117
|
+
* @type {boolean}
|
|
118
|
+
*/
|
|
119
|
+
this.disposed_ = false;
|
|
50
120
|
|
|
51
|
-
|
|
121
|
+
/**
|
|
122
|
+
* @package
|
|
123
|
+
* @type {boolean}
|
|
124
|
+
*/
|
|
125
|
+
this.isComment = true;
|
|
126
|
+
|
|
127
|
+
WorkspaceComment.fireCreateEvent(this);
|
|
128
|
+
}
|
|
52
129
|
|
|
53
130
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @type {!Coordinate}
|
|
57
|
-
* @protected
|
|
131
|
+
* Dispose of this comment.
|
|
132
|
+
* @package
|
|
58
133
|
*/
|
|
59
|
-
|
|
134
|
+
dispose() {
|
|
135
|
+
if (this.disposed_) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (eventUtils.isEnabled()) {
|
|
140
|
+
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_DELETE))(this));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Remove from the list of top comments and the comment database.
|
|
144
|
+
this.workspace.removeTopComment(this);
|
|
145
|
+
this.disposed_ = true;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Height, width, x, and y are all stored on even non-rendered comments, to
|
|
149
|
+
// preserve state if you pass the contents through a headless workspace.
|
|
60
150
|
|
|
61
151
|
/**
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
* @
|
|
152
|
+
* Get comment height.
|
|
153
|
+
* @return {number} Comment height.
|
|
154
|
+
* @package
|
|
65
155
|
*/
|
|
66
|
-
|
|
156
|
+
getHeight() {
|
|
157
|
+
return this.height_;
|
|
158
|
+
}
|
|
67
159
|
|
|
68
160
|
/**
|
|
69
|
-
*
|
|
70
|
-
* @
|
|
71
|
-
* @
|
|
161
|
+
* Set comment height.
|
|
162
|
+
* @param {number} height Comment height.
|
|
163
|
+
* @package
|
|
72
164
|
*/
|
|
73
|
-
|
|
165
|
+
setHeight(height) {
|
|
166
|
+
this.height_ = height;
|
|
167
|
+
}
|
|
74
168
|
|
|
75
169
|
/**
|
|
76
|
-
*
|
|
170
|
+
* Get comment width.
|
|
171
|
+
* @return {number} Comment width.
|
|
172
|
+
* @package
|
|
77
173
|
*/
|
|
78
|
-
|
|
174
|
+
getWidth() {
|
|
175
|
+
return this.width_;
|
|
176
|
+
}
|
|
79
177
|
|
|
80
178
|
/**
|
|
81
|
-
*
|
|
82
|
-
* @
|
|
179
|
+
* Set comment width.
|
|
180
|
+
* @param {number} width comment width.
|
|
181
|
+
* @package
|
|
83
182
|
*/
|
|
84
|
-
|
|
183
|
+
setWidth(width) {
|
|
184
|
+
this.width_ = width;
|
|
185
|
+
}
|
|
85
186
|
|
|
86
187
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @
|
|
188
|
+
* Get stored location.
|
|
189
|
+
* @return {!Coordinate} The comment's stored location.
|
|
190
|
+
* This is not valid if the comment is currently being dragged.
|
|
191
|
+
* @package
|
|
89
192
|
*/
|
|
90
|
-
|
|
193
|
+
getXY() {
|
|
194
|
+
return new Coordinate(this.xy_.x, this.xy_.y);
|
|
195
|
+
}
|
|
91
196
|
|
|
92
197
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @
|
|
198
|
+
* Move a comment by a relative offset.
|
|
199
|
+
* @param {number} dx Horizontal offset, in workspace units.
|
|
200
|
+
* @param {number} dy Vertical offset, in workspace units.
|
|
201
|
+
* @package
|
|
95
202
|
*/
|
|
96
|
-
|
|
203
|
+
moveBy(dx, dy) {
|
|
204
|
+
const event = /** @type {!CommentMove} */ (
|
|
205
|
+
new (eventUtils.get(eventUtils.COMMENT_MOVE))(this));
|
|
206
|
+
this.xy_.translate(dx, dy);
|
|
207
|
+
event.recordNew();
|
|
208
|
+
eventUtils.fire(event);
|
|
209
|
+
}
|
|
97
210
|
|
|
98
211
|
/**
|
|
99
|
-
*
|
|
100
|
-
* @
|
|
212
|
+
* Get whether this comment is deletable or not.
|
|
213
|
+
* @return {boolean} True if deletable.
|
|
214
|
+
* @package
|
|
101
215
|
*/
|
|
102
|
-
|
|
216
|
+
isDeletable() {
|
|
217
|
+
return this.deletable_ &&
|
|
218
|
+
!(this.workspace && this.workspace.options.readOnly);
|
|
219
|
+
}
|
|
103
220
|
|
|
104
221
|
/**
|
|
105
|
-
*
|
|
106
|
-
* @
|
|
222
|
+
* Set whether this comment is deletable or not.
|
|
223
|
+
* @param {boolean} deletable True if deletable.
|
|
224
|
+
* @package
|
|
107
225
|
*/
|
|
108
|
-
|
|
226
|
+
setDeletable(deletable) {
|
|
227
|
+
this.deletable_ = deletable;
|
|
228
|
+
}
|
|
109
229
|
|
|
110
230
|
/**
|
|
111
|
-
*
|
|
112
|
-
* @
|
|
113
|
-
* @
|
|
231
|
+
* Get whether this comment is movable or not.
|
|
232
|
+
* @return {boolean} True if movable.
|
|
233
|
+
* @package
|
|
114
234
|
*/
|
|
115
|
-
|
|
235
|
+
isMovable() {
|
|
236
|
+
return this.movable_ &&
|
|
237
|
+
!(this.workspace && this.workspace.options.readOnly);
|
|
238
|
+
}
|
|
116
239
|
|
|
117
240
|
/**
|
|
241
|
+
* Set whether this comment is movable or not.
|
|
242
|
+
* @param {boolean} movable True if movable.
|
|
118
243
|
* @package
|
|
119
|
-
* @type {boolean}
|
|
120
244
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
WorkspaceComment.fireCreateEvent(this);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Dispose of this comment.
|
|
128
|
-
* @package
|
|
129
|
-
*/
|
|
130
|
-
WorkspaceComment.prototype.dispose = function() {
|
|
131
|
-
if (this.disposed_) {
|
|
132
|
-
return;
|
|
245
|
+
setMovable(movable) {
|
|
246
|
+
this.movable_ = movable;
|
|
133
247
|
}
|
|
134
248
|
|
|
135
|
-
|
|
136
|
-
|
|
249
|
+
/**
|
|
250
|
+
* Get whether this comment is editable or not.
|
|
251
|
+
* @return {boolean} True if editable.
|
|
252
|
+
*/
|
|
253
|
+
isEditable() {
|
|
254
|
+
return this.editable_ &&
|
|
255
|
+
!(this.workspace && this.workspace.options.readOnly);
|
|
137
256
|
}
|
|
138
257
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Get comment height.
|
|
149
|
-
* @return {number} Comment height.
|
|
150
|
-
* @package
|
|
151
|
-
*/
|
|
152
|
-
WorkspaceComment.prototype.getHeight = function() {
|
|
153
|
-
return this.height_;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Set comment height.
|
|
158
|
-
* @param {number} height Comment height.
|
|
159
|
-
* @package
|
|
160
|
-
*/
|
|
161
|
-
WorkspaceComment.prototype.setHeight = function(height) {
|
|
162
|
-
this.height_ = height;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Get comment width.
|
|
167
|
-
* @return {number} Comment width.
|
|
168
|
-
* @package
|
|
169
|
-
*/
|
|
170
|
-
WorkspaceComment.prototype.getWidth = function() {
|
|
171
|
-
return this.width_;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Set comment width.
|
|
176
|
-
* @param {number} width comment width.
|
|
177
|
-
* @package
|
|
178
|
-
*/
|
|
179
|
-
WorkspaceComment.prototype.setWidth = function(width) {
|
|
180
|
-
this.width_ = width;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Get stored location.
|
|
185
|
-
* @return {!Coordinate} The comment's stored location.
|
|
186
|
-
* This is not valid if the comment is currently being dragged.
|
|
187
|
-
* @package
|
|
188
|
-
*/
|
|
189
|
-
WorkspaceComment.prototype.getXY = function() {
|
|
190
|
-
return new Coordinate(this.xy_.x, this.xy_.y);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Move a comment by a relative offset.
|
|
195
|
-
* @param {number} dx Horizontal offset, in workspace units.
|
|
196
|
-
* @param {number} dy Vertical offset, in workspace units.
|
|
197
|
-
* @package
|
|
198
|
-
*/
|
|
199
|
-
WorkspaceComment.prototype.moveBy = function(dx, dy) {
|
|
200
|
-
const event = new (eventUtils.get(eventUtils.COMMENT_MOVE))(this);
|
|
201
|
-
this.xy_.translate(dx, dy);
|
|
202
|
-
event.recordNew();
|
|
203
|
-
eventUtils.fire(event);
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Get whether this comment is deletable or not.
|
|
208
|
-
* @return {boolean} True if deletable.
|
|
209
|
-
* @package
|
|
210
|
-
*/
|
|
211
|
-
WorkspaceComment.prototype.isDeletable = function() {
|
|
212
|
-
return this.deletable_ &&
|
|
213
|
-
!(this.workspace && this.workspace.options.readOnly);
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Set whether this comment is deletable or not.
|
|
218
|
-
* @param {boolean} deletable True if deletable.
|
|
219
|
-
* @package
|
|
220
|
-
*/
|
|
221
|
-
WorkspaceComment.prototype.setDeletable = function(deletable) {
|
|
222
|
-
this.deletable_ = deletable;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Get whether this comment is movable or not.
|
|
227
|
-
* @return {boolean} True if movable.
|
|
228
|
-
* @package
|
|
229
|
-
*/
|
|
230
|
-
WorkspaceComment.prototype.isMovable = function() {
|
|
231
|
-
return this.movable_ && !(this.workspace && this.workspace.options.readOnly);
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Set whether this comment is movable or not.
|
|
236
|
-
* @param {boolean} movable True if movable.
|
|
237
|
-
* @package
|
|
238
|
-
*/
|
|
239
|
-
WorkspaceComment.prototype.setMovable = function(movable) {
|
|
240
|
-
this.movable_ = movable;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Get whether this comment is editable or not.
|
|
245
|
-
* @return {boolean} True if editable.
|
|
246
|
-
*/
|
|
247
|
-
WorkspaceComment.prototype.isEditable = function() {
|
|
248
|
-
return this.editable_ && !(this.workspace && this.workspace.options.readOnly);
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Set whether this comment is editable or not.
|
|
253
|
-
* @param {boolean} editable True if editable.
|
|
254
|
-
*/
|
|
255
|
-
WorkspaceComment.prototype.setEditable = function(editable) {
|
|
256
|
-
this.editable_ = editable;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Returns this comment's text.
|
|
261
|
-
* @return {string} Comment text.
|
|
262
|
-
* @package
|
|
263
|
-
*/
|
|
264
|
-
WorkspaceComment.prototype.getContent = function() {
|
|
265
|
-
return this.content_;
|
|
266
|
-
};
|
|
258
|
+
/**
|
|
259
|
+
* Set whether this comment is editable or not.
|
|
260
|
+
* @param {boolean} editable True if editable.
|
|
261
|
+
*/
|
|
262
|
+
setEditable(editable) {
|
|
263
|
+
this.editable_ = editable;
|
|
264
|
+
}
|
|
267
265
|
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_CHANGE))(
|
|
276
|
-
this, this.content_, content));
|
|
277
|
-
this.content_ = content;
|
|
266
|
+
/**
|
|
267
|
+
* Returns this comment's text.
|
|
268
|
+
* @return {string} Comment text.
|
|
269
|
+
* @package
|
|
270
|
+
*/
|
|
271
|
+
getContent() {
|
|
272
|
+
return this.content_;
|
|
278
273
|
}
|
|
279
|
-
};
|
|
280
274
|
|
|
281
|
-
/**
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return element;
|
|
294
|
-
};
|
|
275
|
+
/**
|
|
276
|
+
* Set this comment's content.
|
|
277
|
+
* @param {string} content Comment content.
|
|
278
|
+
* @package
|
|
279
|
+
*/
|
|
280
|
+
setContent(content) {
|
|
281
|
+
if (this.content_ !== content) {
|
|
282
|
+
eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_CHANGE))(
|
|
283
|
+
this, this.content_, content));
|
|
284
|
+
this.content_ = content;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
295
287
|
|
|
296
|
-
/**
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Encode a comment subtree as XML with XY coordinates.
|
|
290
|
+
* @param {boolean=} opt_noId True if the encoder should skip the comment ID.
|
|
291
|
+
* @return {!Element} Tree of XML elements.
|
|
292
|
+
* @package
|
|
293
|
+
*/
|
|
294
|
+
toXmlWithXY(opt_noId) {
|
|
295
|
+
const element = this.toXml(opt_noId);
|
|
296
|
+
element.setAttribute('x', Math.round(this.xy_.x));
|
|
297
|
+
element.setAttribute('y', Math.round(this.xy_.y));
|
|
298
|
+
element.setAttribute('h', this.height_);
|
|
299
|
+
element.setAttribute('w', this.width_);
|
|
300
|
+
return element;
|
|
308
301
|
}
|
|
309
|
-
commentElement.textContent = this.getContent();
|
|
310
|
-
return commentElement;
|
|
311
|
-
};
|
|
312
302
|
|
|
313
|
-
/**
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Encode a comment subtree as XML, but don't serialize the XY coordinates.
|
|
305
|
+
* This method avoids some expensive metrics-related calls that are made in
|
|
306
|
+
* toXmlWithXY().
|
|
307
|
+
* @param {boolean=} opt_noId True if the encoder should skip the comment ID.
|
|
308
|
+
* @return {!Element} Tree of XML elements.
|
|
309
|
+
* @package
|
|
310
|
+
*/
|
|
311
|
+
toXml(opt_noId) {
|
|
312
|
+
const commentElement = xml.createElement('comment');
|
|
313
|
+
if (!opt_noId) {
|
|
314
|
+
commentElement.id = this.id;
|
|
323
315
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
316
|
+
commentElement.textContent = this.getContent();
|
|
317
|
+
return commentElement;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Fire a create event for the given workspace comment, if comments are
|
|
322
|
+
* enabled.
|
|
323
|
+
* @param {!WorkspaceComment} comment The comment that was just created.
|
|
324
|
+
* @package
|
|
325
|
+
*/
|
|
326
|
+
static fireCreateEvent(comment) {
|
|
327
|
+
if (eventUtils.isEnabled()) {
|
|
328
|
+
const existingGroup = eventUtils.getGroup();
|
|
327
329
|
if (!existingGroup) {
|
|
328
|
-
eventUtils.setGroup(
|
|
330
|
+
eventUtils.setGroup(true);
|
|
331
|
+
}
|
|
332
|
+
try {
|
|
333
|
+
eventUtils.fire(
|
|
334
|
+
new (eventUtils.get(eventUtils.COMMENT_CREATE))(comment));
|
|
335
|
+
} finally {
|
|
336
|
+
if (!existingGroup) {
|
|
337
|
+
eventUtils.setGroup(false);
|
|
338
|
+
}
|
|
329
339
|
}
|
|
330
340
|
}
|
|
331
341
|
}
|
|
332
|
-
};
|
|
333
342
|
|
|
334
|
-
/**
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
+
/**
|
|
344
|
+
* Decode an XML comment tag and create a comment on the workspace.
|
|
345
|
+
* @param {!Element} xmlComment XML comment element.
|
|
346
|
+
* @param {!Workspace} workspace The workspace.
|
|
347
|
+
* @return {!WorkspaceComment} The created workspace comment.
|
|
348
|
+
* @package
|
|
349
|
+
*/
|
|
350
|
+
static fromXml(xmlComment, workspace) {
|
|
351
|
+
const info = WorkspaceComment.parseAttributes(xmlComment);
|
|
343
352
|
|
|
344
|
-
|
|
345
|
-
|
|
353
|
+
const comment =
|
|
354
|
+
new WorkspaceComment(workspace, info.content, info.h, info.w, info.id);
|
|
346
355
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
356
|
+
const commentX = parseInt(xmlComment.getAttribute('x'), 10);
|
|
357
|
+
const commentY = parseInt(xmlComment.getAttribute('y'), 10);
|
|
358
|
+
if (!isNaN(commentX) && !isNaN(commentY)) {
|
|
359
|
+
comment.moveBy(commentX, commentY);
|
|
360
|
+
}
|
|
352
361
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
362
|
+
WorkspaceComment.fireCreateEvent(comment);
|
|
363
|
+
return comment;
|
|
364
|
+
}
|
|
356
365
|
|
|
357
|
-
/**
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
366
|
+
/**
|
|
367
|
+
* Decode an XML comment tag and return the results in an object.
|
|
368
|
+
* @param {!Element} xml XML comment element.
|
|
369
|
+
* @return {{w: number, h: number, x: number, y: number, content: string}} An
|
|
370
|
+
* object containing the id, size, position, and comment string.
|
|
371
|
+
* @package
|
|
372
|
+
*/
|
|
373
|
+
static parseAttributes(xml) {
|
|
374
|
+
const xmlH = xml.getAttribute('h');
|
|
375
|
+
const xmlW = xml.getAttribute('w');
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
// @type {string}
|
|
379
|
+
id: xml.getAttribute('id'),
|
|
380
|
+
// The height of the comment in workspace units, or 100 if not specified.
|
|
381
|
+
// @type {number}
|
|
382
|
+
h: xmlH ? parseInt(xmlH, 10) : 100,
|
|
383
|
+
// The width of the comment in workspace units, or 100 if not specified.
|
|
384
|
+
// @type {number}
|
|
385
|
+
w: xmlW ? parseInt(xmlW, 10) : 100,
|
|
386
|
+
// The x position of the comment in workspace coordinates, or NaN if not
|
|
387
|
+
// specified in the XML.
|
|
388
|
+
// @type {number}
|
|
389
|
+
x: parseInt(xml.getAttribute('x'), 10),
|
|
390
|
+
// The y position of the comment in workspace coordinates, or NaN if not
|
|
391
|
+
// specified in the XML.
|
|
392
|
+
// @type {number}
|
|
393
|
+
y: parseInt(xml.getAttribute('y'), 10),
|
|
394
|
+
// @type {string}
|
|
395
|
+
content: xml.textContent,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
389
399
|
|
|
390
400
|
exports.WorkspaceComment = WorkspaceComment;
|