blockly 7.20211209.2 → 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.
Files changed (262) hide show
  1. package/blockly.d.ts +18963 -18432
  2. package/blockly.min.js +852 -844
  3. package/blockly_compressed.js +669 -664
  4. package/blockly_compressed.js.map +1 -1
  5. package/blocks/blocks.js +47 -0
  6. package/blocks/colour.js +13 -3
  7. package/blocks/lists.js +22 -13
  8. package/blocks/logic.js +13 -3
  9. package/blocks/loops.js +24 -11
  10. package/blocks/math.js +12 -3
  11. package/blocks/procedures.js +41 -27
  12. package/blocks/text.js +22 -13
  13. package/blocks/variables.js +14 -3
  14. package/blocks/variables_dynamic.js +13 -3
  15. package/blocks_compressed.js +146 -141
  16. package/blocks_compressed.js.map +1 -1
  17. package/core/block.js +1869 -1814
  18. package/core/block_drag_surface.js +201 -200
  19. package/core/block_dragger.js +377 -373
  20. package/core/block_svg.js +1593 -1479
  21. package/core/blockly.js +8 -22
  22. package/core/blocks.js +9 -2
  23. package/core/browser_events.js +22 -5
  24. package/core/bubble.js +841 -797
  25. package/core/bubble_dragger.js +213 -206
  26. package/core/bump_objects.js +2 -2
  27. package/core/clipboard.js +9 -9
  28. package/core/comment.js +353 -332
  29. package/core/common.js +46 -17
  30. package/core/component_manager.js +181 -174
  31. package/core/config.js +87 -0
  32. package/core/connection.js +595 -584
  33. package/core/connection_checker.js +242 -244
  34. package/core/connection_db.js +235 -230
  35. package/core/contextmenu.js +9 -6
  36. package/core/contextmenu_items.js +1 -2
  37. package/core/contextmenu_registry.js +93 -89
  38. package/core/css.js +474 -474
  39. package/core/delete_area.js +45 -42
  40. package/core/drag_target.js +57 -56
  41. package/core/dropdowndiv.js +153 -163
  42. package/core/events/events.js +2 -2
  43. package/core/events/events_abstract.js +89 -77
  44. package/core/events/events_block_base.js +37 -36
  45. package/core/events/events_block_change.js +130 -124
  46. package/core/events/events_block_create.js +73 -71
  47. package/core/events/events_block_delete.js +84 -82
  48. package/core/events/events_block_drag.js +50 -49
  49. package/core/events/events_block_move.js +147 -140
  50. package/core/events/events_bubble_open.js +51 -50
  51. package/core/events/events_click.js +48 -44
  52. package/core/events/events_comment_base.js +72 -69
  53. package/core/events/events_comment_change.js +63 -61
  54. package/core/events/events_comment_create.js +44 -42
  55. package/core/events/events_comment_delete.js +42 -40
  56. package/core/events/events_comment_move.js +106 -104
  57. package/core/events/events_marker_move.js +65 -64
  58. package/core/events/events_selected.js +46 -45
  59. package/core/events/events_theme_change.js +36 -35
  60. package/core/events/events_toolbox_item_select.js +46 -45
  61. package/core/events/events_trashcan_open.js +37 -36
  62. package/core/events/events_ui.js +47 -46
  63. package/core/events/events_ui_base.js +30 -29
  64. package/core/events/events_var_base.js +37 -36
  65. package/core/events/events_var_create.js +50 -48
  66. package/core/events/events_var_delete.js +50 -48
  67. package/core/events/events_var_rename.js +51 -49
  68. package/core/events/events_viewport.js +66 -65
  69. package/core/events/utils.js +29 -14
  70. package/core/events/workspace_events.js +49 -55
  71. package/core/extensions.js +4 -3
  72. package/core/field.js +1061 -997
  73. package/core/field_angle.js +462 -442
  74. package/core/field_checkbox.js +194 -182
  75. package/core/field_colour.js +519 -505
  76. package/core/field_dropdown.js +617 -598
  77. package/core/field_image.js +229 -220
  78. package/core/field_label.js +102 -91
  79. package/core/field_label_serializable.js +42 -41
  80. package/core/field_multilineinput.js +372 -358
  81. package/core/field_number.js +272 -253
  82. package/core/field_textinput.js +499 -467
  83. package/core/field_variable.js +458 -420
  84. package/core/flyout_base.js +1005 -952
  85. package/core/flyout_button.js +277 -260
  86. package/core/flyout_horizontal.js +304 -302
  87. package/core/flyout_metrics_manager.js +64 -64
  88. package/core/flyout_vertical.js +306 -300
  89. package/core/generator.js +459 -446
  90. package/core/gesture.js +829 -813
  91. package/core/grid.js +166 -163
  92. package/core/icon.js +168 -159
  93. package/core/inject.js +7 -5
  94. package/core/input.js +257 -248
  95. package/core/insertion_marker_manager.js +655 -624
  96. package/core/internal_constants.js +0 -129
  97. package/core/keyboard_nav/ast_node.js +605 -596
  98. package/core/keyboard_nav/basic_cursor.js +166 -165
  99. package/core/keyboard_nav/cursor.js +99 -97
  100. package/core/keyboard_nav/marker.js +83 -79
  101. package/core/keyboard_nav/tab_navigate_cursor.js +18 -23
  102. package/core/marker_manager.js +153 -141
  103. package/core/menu.js +377 -372
  104. package/core/menuitem.js +223 -217
  105. package/core/metrics_manager.js +403 -390
  106. package/core/mutator.js +468 -437
  107. package/core/names.js +229 -188
  108. package/core/options.js +290 -284
  109. package/core/procedures.js +29 -17
  110. package/core/registry.js +19 -16
  111. package/core/rendered_connection.js +482 -463
  112. package/core/renderers/common/block_rendering.js +9 -3
  113. package/core/renderers/common/constants.js +1119 -1112
  114. package/core/renderers/common/debug.js +14 -0
  115. package/core/renderers/common/debugger.js +338 -316
  116. package/core/renderers/common/drawer.js +380 -370
  117. package/core/renderers/common/i_path_object.js +2 -2
  118. package/core/renderers/common/info.js +626 -618
  119. package/core/renderers/common/marker_svg.js +579 -541
  120. package/core/renderers/common/path_object.js +203 -200
  121. package/core/renderers/common/renderer.js +220 -218
  122. package/core/renderers/geras/constants.js +36 -36
  123. package/core/renderers/geras/drawer.js +155 -147
  124. package/core/renderers/geras/highlight_constants.js +244 -238
  125. package/core/renderers/geras/highlighter.js +231 -179
  126. package/core/renderers/geras/info.js +392 -369
  127. package/core/renderers/geras/measurables/inline_input.js +25 -19
  128. package/core/renderers/geras/measurables/statement_input.js +23 -17
  129. package/core/renderers/geras/path_object.js +106 -121
  130. package/core/renderers/geras/renderer.js +96 -98
  131. package/core/renderers/measurables/base.js +30 -18
  132. package/core/renderers/measurables/bottom_row.js +83 -80
  133. package/core/renderers/measurables/connection.js +22 -15
  134. package/core/renderers/measurables/external_value_input.js +35 -22
  135. package/core/renderers/measurables/field.js +35 -20
  136. package/core/renderers/measurables/hat.js +18 -13
  137. package/core/renderers/measurables/icon.js +24 -17
  138. package/core/renderers/measurables/in_row_spacer.js +15 -13
  139. package/core/renderers/measurables/inline_input.js +43 -33
  140. package/core/renderers/measurables/input_connection.js +41 -28
  141. package/core/renderers/measurables/input_row.js +50 -44
  142. package/core/renderers/measurables/jagged_edge.js +14 -12
  143. package/core/renderers/measurables/next_connection.js +16 -14
  144. package/core/renderers/measurables/output_connection.js +26 -20
  145. package/core/renderers/measurables/previous_connection.js +16 -15
  146. package/core/renderers/measurables/round_corner.js +20 -18
  147. package/core/renderers/measurables/row.js +184 -168
  148. package/core/renderers/measurables/spacer_row.js +38 -23
  149. package/core/renderers/measurables/square_corner.js +18 -16
  150. package/core/renderers/measurables/statement_input.js +23 -20
  151. package/core/renderers/measurables/top_row.js +88 -85
  152. package/core/renderers/minimalist/constants.js +8 -7
  153. package/core/renderers/minimalist/drawer.js +11 -10
  154. package/core/renderers/minimalist/info.js +18 -18
  155. package/core/renderers/minimalist/renderer.js +40 -39
  156. package/core/renderers/thrasos/info.js +258 -248
  157. package/core/renderers/thrasos/renderer.js +20 -20
  158. package/core/renderers/zelos/constants.js +898 -873
  159. package/core/renderers/zelos/drawer.js +186 -169
  160. package/core/renderers/zelos/info.js +502 -479
  161. package/core/renderers/zelos/marker_svg.js +129 -115
  162. package/core/renderers/zelos/measurables/bottom_row.js +31 -30
  163. package/core/renderers/zelos/measurables/inputs.js +22 -21
  164. package/core/renderers/zelos/measurables/row_elements.js +14 -13
  165. package/core/renderers/zelos/measurables/top_row.js +34 -33
  166. package/core/renderers/zelos/path_object.js +181 -180
  167. package/core/renderers/zelos/renderer.js +91 -92
  168. package/core/scrollbar.js +759 -713
  169. package/core/scrollbar_pair.js +250 -245
  170. package/core/serialization/blocks.js +19 -9
  171. package/core/serialization/workspaces.js +3 -2
  172. package/core/shortcut_registry.js +286 -277
  173. package/core/sprites.js +31 -0
  174. package/core/theme.js +135 -141
  175. package/core/theme_manager.js +147 -143
  176. package/core/toolbox/category.js +602 -576
  177. package/core/toolbox/collapsible_category.js +226 -227
  178. package/core/toolbox/separator.js +70 -61
  179. package/core/toolbox/toolbox.js +934 -927
  180. package/core/toolbox/toolbox_item.js +115 -99
  181. package/core/tooltip.js +108 -35
  182. package/core/touch.js +8 -3
  183. package/core/touch_gesture.js +254 -251
  184. package/core/trashcan.js +606 -595
  185. package/core/utils/coordinate.js +97 -95
  186. package/core/utils/dom.js +2 -2
  187. package/core/utils/global.js +2 -0
  188. package/core/utils/rect.js +41 -37
  189. package/core/utils/sentinel.js +25 -0
  190. package/core/utils/size.js +30 -27
  191. package/core/utils/svg.js +18 -16
  192. package/core/variable_map.js +325 -341
  193. package/core/variable_model.js +55 -54
  194. package/core/variables.js +9 -2
  195. package/core/variables_dynamic.js +3 -1
  196. package/core/warning.js +126 -120
  197. package/core/widgetdiv.js +4 -4
  198. package/core/workspace.js +685 -664
  199. package/core/workspace_audio.js +124 -118
  200. package/core/workspace_comment.js +308 -298
  201. package/core/workspace_comment_svg.js +1029 -951
  202. package/core/workspace_drag_surface_svg.js +147 -140
  203. package/core/workspace_dragger.js +70 -71
  204. package/core/workspace_svg.js +2322 -2297
  205. package/core/xml.js +30 -20
  206. package/core/zoom_controls.js +431 -439
  207. package/dart_compressed.js +40 -43
  208. package/dart_compressed.js.map +1 -1
  209. package/generators/dart/colour.js +56 -64
  210. package/generators/dart/lists.js +61 -50
  211. package/generators/dart/math.js +160 -148
  212. package/generators/dart/text.js +83 -61
  213. package/generators/javascript/colour.js +37 -34
  214. package/generators/javascript/lists.js +50 -43
  215. package/generators/javascript/math.js +123 -139
  216. package/generators/javascript/text.js +67 -81
  217. package/generators/lua/colour.js +25 -23
  218. package/generators/lua/lists.js +97 -69
  219. package/generators/lua/logic.js +1 -2
  220. package/generators/lua/math.js +182 -144
  221. package/generators/lua/text.js +116 -99
  222. package/generators/php/colour.js +38 -32
  223. package/generators/php/lists.js +109 -89
  224. package/generators/php/math.js +90 -81
  225. package/generators/php/text.js +63 -61
  226. package/generators/python/colour.js +18 -18
  227. package/generators/python/lists.js +38 -30
  228. package/generators/python/loops.js +12 -8
  229. package/generators/python/math.js +104 -106
  230. package/generators/python/text.js +34 -30
  231. package/javascript_compressed.js +37 -39
  232. package/javascript_compressed.js.map +1 -1
  233. package/lua_compressed.js +39 -42
  234. package/lua_compressed.js.map +1 -1
  235. package/msg/az.js +2 -2
  236. package/msg/be.js +4 -4
  237. package/msg/cs.js +15 -15
  238. package/msg/de.js +1 -1
  239. package/msg/diq.js +1 -1
  240. package/msg/eo.js +1 -1
  241. package/msg/es.js +1 -1
  242. package/msg/fa.js +1 -1
  243. package/msg/fr.js +4 -4
  244. package/msg/he.js +1 -1
  245. package/msg/hr.js +2 -2
  246. package/msg/hy.js +2 -2
  247. package/msg/id.js +12 -12
  248. package/msg/inh.js +14 -14
  249. package/msg/ja.js +7 -7
  250. package/msg/lv.js +29 -29
  251. package/msg/pa.js +3 -3
  252. package/msg/smn.js +436 -0
  253. package/msg/te.js +1 -1
  254. package/msg/yue.js +1 -1
  255. package/msg/zh-hans.js +3 -3
  256. package/msg/zh-hant.js +3 -3
  257. package/package.json +7 -6
  258. package/php_compressed.js +38 -42
  259. package/php_compressed.js.map +1 -1
  260. package/python_compressed.js +26 -25
  261. package/python_compressed.js.map +1 -1
  262. 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
- const WorkspaceComment = function(workspace, content, height, width, opt_id) {
46
- /** @type {string} */
47
- this.id = (opt_id && !workspace.getCommentById(opt_id)) ?
48
- opt_id :
49
- idGenerator.genUid();
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
- workspace.addTopComment(this);
121
+ /**
122
+ * @package
123
+ * @type {boolean}
124
+ */
125
+ this.isComment = true;
126
+
127
+ WorkspaceComment.fireCreateEvent(this);
128
+ }
52
129
 
53
130
  /**
54
- * The comment's position in workspace units. (0, 0) is at the workspace's
55
- * origin; scale does not change this value.
56
- * @type {!Coordinate}
57
- * @protected
131
+ * Dispose of this comment.
132
+ * @package
58
133
  */
59
- this.xy_ = new Coordinate(0, 0);
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
- * The comment's height in workspace units. Scale does not change this value.
63
- * @type {number}
64
- * @protected
152
+ * Get comment height.
153
+ * @return {number} Comment height.
154
+ * @package
65
155
  */
66
- this.height_ = height;
156
+ getHeight() {
157
+ return this.height_;
158
+ }
67
159
 
68
160
  /**
69
- * The comment's width in workspace units. Scale does not change this value.
70
- * @type {number}
71
- * @protected
161
+ * Set comment height.
162
+ * @param {number} height Comment height.
163
+ * @package
72
164
  */
73
- this.width_ = width;
165
+ setHeight(height) {
166
+ this.height_ = height;
167
+ }
74
168
 
75
169
  /**
76
- * @type {!Workspace}
170
+ * Get comment width.
171
+ * @return {number} Comment width.
172
+ * @package
77
173
  */
78
- this.workspace = workspace;
174
+ getWidth() {
175
+ return this.width_;
176
+ }
79
177
 
80
178
  /**
81
- * @protected
82
- * @type {boolean}
179
+ * Set comment width.
180
+ * @param {number} width comment width.
181
+ * @package
83
182
  */
84
- this.RTL = workspace.RTL;
183
+ setWidth(width) {
184
+ this.width_ = width;
185
+ }
85
186
 
86
187
  /**
87
- * @type {boolean}
88
- * @private
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
- this.deletable_ = true;
193
+ getXY() {
194
+ return new Coordinate(this.xy_.x, this.xy_.y);
195
+ }
91
196
 
92
197
  /**
93
- * @type {boolean}
94
- * @private
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
- this.movable_ = true;
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
- * @type {boolean}
100
- * @private
212
+ * Get whether this comment is deletable or not.
213
+ * @return {boolean} True if deletable.
214
+ * @package
101
215
  */
102
- this.editable_ = true;
216
+ isDeletable() {
217
+ return this.deletable_ &&
218
+ !(this.workspace && this.workspace.options.readOnly);
219
+ }
103
220
 
104
221
  /**
105
- * @protected
106
- * @type {string}
222
+ * Set whether this comment is deletable or not.
223
+ * @param {boolean} deletable True if deletable.
224
+ * @package
107
225
  */
108
- this.content_ = content;
226
+ setDeletable(deletable) {
227
+ this.deletable_ = deletable;
228
+ }
109
229
 
110
230
  /**
111
- * Whether this comment has been disposed.
112
- * @protected
113
- * @type {boolean}
231
+ * Get whether this comment is movable or not.
232
+ * @return {boolean} True if movable.
233
+ * @package
114
234
  */
115
- this.disposed_ = false;
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
- this.isComment = true;
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
- if (eventUtils.isEnabled()) {
136
- eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_DELETE))(this));
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
- // Remove from the list of top comments and the comment database.
140
- this.workspace.removeTopComment(this);
141
- this.disposed_ = true;
142
- };
143
-
144
- // Height, width, x, and y are all stored on even non-rendered comments, to
145
- // preserve state if you pass the contents through a headless workspace.
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
- * Set this comment's content.
270
- * @param {string} content Comment content.
271
- * @package
272
- */
273
- WorkspaceComment.prototype.setContent = function(content) {
274
- if (this.content_ !== content) {
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
- * Encode a comment subtree as XML with XY coordinates.
283
- * @param {boolean=} opt_noId True if the encoder should skip the comment ID.
284
- * @return {!Element} Tree of XML elements.
285
- * @package
286
- */
287
- WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) {
288
- const element = this.toXml(opt_noId);
289
- element.setAttribute('x', Math.round(this.xy_.x));
290
- element.setAttribute('y', Math.round(this.xy_.y));
291
- element.setAttribute('h', this.height_);
292
- element.setAttribute('w', this.width_);
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
- * Encode a comment subtree as XML, but don't serialize the XY coordinates.
298
- * This method avoids some expensive metrics-related calls that are made in
299
- * toXmlWithXY().
300
- * @param {boolean=} opt_noId True if the encoder should skip the comment ID.
301
- * @return {!Element} Tree of XML elements.
302
- * @package
303
- */
304
- WorkspaceComment.prototype.toXml = function(opt_noId) {
305
- const commentElement = xml.createElement('comment');
306
- if (!opt_noId) {
307
- commentElement.id = this.id;
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
- * Fire a create event for the given workspace comment, if comments are enabled.
315
- * @param {!WorkspaceComment} comment The comment that was just created.
316
- * @package
317
- */
318
- WorkspaceComment.fireCreateEvent = function(comment) {
319
- if (eventUtils.isEnabled()) {
320
- const existingGroup = eventUtils.getGroup();
321
- if (!existingGroup) {
322
- eventUtils.setGroup(true);
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
- try {
325
- eventUtils.fire(new (eventUtils.get(eventUtils.COMMENT_CREATE))(comment));
326
- } finally {
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(false);
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
- * Decode an XML comment tag and create a comment on the workspace.
336
- * @param {!Element} xmlComment XML comment element.
337
- * @param {!Workspace} workspace The workspace.
338
- * @return {!WorkspaceComment} The created workspace comment.
339
- * @package
340
- */
341
- WorkspaceComment.fromXml = function(xmlComment, workspace) {
342
- const info = WorkspaceComment.parseAttributes(xmlComment);
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
- const comment =
345
- new WorkspaceComment(workspace, info.content, info.h, info.w, info.id);
353
+ const comment =
354
+ new WorkspaceComment(workspace, info.content, info.h, info.w, info.id);
346
355
 
347
- const commentX = parseInt(xmlComment.getAttribute('x'), 10);
348
- const commentY = parseInt(xmlComment.getAttribute('y'), 10);
349
- if (!isNaN(commentX) && !isNaN(commentY)) {
350
- comment.moveBy(commentX, commentY);
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
- WorkspaceComment.fireCreateEvent(comment);
354
- return comment;
355
- };
362
+ WorkspaceComment.fireCreateEvent(comment);
363
+ return comment;
364
+ }
356
365
 
357
- /**
358
- * Decode an XML comment tag and return the results in an object.
359
- * @param {!Element} xml XML comment element.
360
- * @return {{w: number, h: number, x: number, y: number, content: string}} An
361
- * object containing the id, size, position, and comment string.
362
- * @package
363
- */
364
- WorkspaceComment.parseAttributes = function(xml) {
365
- const xmlH = xml.getAttribute('h');
366
- const xmlW = xml.getAttribute('w');
367
-
368
- return {
369
- // @type {string}
370
- id: xml.getAttribute('id'),
371
- // The height of the comment in workspace units, or 100 if not specified.
372
- // @type {number}
373
- h: xmlH ? parseInt(xmlH, 10) : 100,
374
- // The width of the comment in workspace units, or 100 if not specified.
375
- // @type {number}
376
- w: xmlW ? parseInt(xmlW, 10) : 100,
377
- // The x position of the comment in workspace coordinates, or NaN if not
378
- // specified in the XML.
379
- // @type {number}
380
- x: parseInt(xml.getAttribute('x'), 10),
381
- // The y position of the comment in workspace coordinates, or NaN if not
382
- // specified in the XML.
383
- // @type {number}
384
- y: parseInt(xml.getAttribute('y'), 10),
385
- // @type {string}
386
- content: xml.textContent,
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;