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.
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
@@ -17,108 +17,272 @@ goog.module('Blockly.FieldImage');
17
17
 
18
18
  const dom = goog.require('Blockly.utils.dom');
19
19
  const fieldRegistry = goog.require('Blockly.fieldRegistry');
20
- const object = goog.require('Blockly.utils.object');
21
20
  const parsing = goog.require('Blockly.utils.parsing');
22
21
  const {Field} = goog.require('Blockly.Field');
22
+ /* eslint-disable-next-line no-unused-vars */
23
+ const {Sentinel} = goog.requireType('Blockly.utils.Sentinel');
23
24
  const {Size} = goog.require('Blockly.utils.Size');
24
25
  const {Svg} = goog.require('Blockly.utils.Svg');
25
26
 
26
27
 
27
28
  /**
28
29
  * Class for an image on a block.
29
- * @param {string} src The URL of the image.
30
- * @param {!(string|number)} width Width of the image.
31
- * @param {!(string|number)} height Height of the image.
32
- * @param {string=} opt_alt Optional alt text for when block is collapsed.
33
- * @param {function(!FieldImage)=} opt_onClick Optional function to be
34
- * called when the image is clicked. If opt_onClick is defined, opt_alt must
35
- * also be defined.
36
- * @param {boolean=} opt_flipRtl Whether to flip the icon in RTL.
37
- * @param {Object=} opt_config A map of options used to configure the field.
38
- * See the [field creation documentation]{@link
39
- * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation}
40
- * for a list of properties this parameter supports.
41
30
  * @extends {Field}
42
- * @constructor
43
31
  * @alias Blockly.FieldImage
44
32
  */
45
- const FieldImage = function(
46
- src, width, height, opt_alt, opt_onClick, opt_flipRtl, opt_config) {
47
- // Return early.
48
- if (!src) {
49
- throw Error('Src value of an image field is required');
50
- }
51
- src = parsing.replaceMessageReferences(src);
52
- const imageHeight = Number(parsing.replaceMessageReferences(height));
53
- const imageWidth = Number(parsing.replaceMessageReferences(width));
54
- if (isNaN(imageHeight) || isNaN(imageWidth)) {
55
- throw Error(
56
- 'Height and width values of an image field must cast to' +
57
- ' numbers.');
58
- }
59
- if (imageHeight <= 0 || imageWidth <= 0) {
60
- throw Error(
61
- 'Height and width values of an image field must be greater' +
62
- ' than 0.');
33
+ class FieldImage extends Field {
34
+ /**
35
+ * @param {string|!Sentinel} src The URL of the image.
36
+ * Also accepts Field.SKIP_SETUP if you wish to skip setup (only used by
37
+ * subclasses that want to handle configuration and setting the field
38
+ * value after their own constructors have run).
39
+ * @param {!(string|number)} width Width of the image.
40
+ * @param {!(string|number)} height Height of the image.
41
+ * @param {string=} opt_alt Optional alt text for when block is collapsed.
42
+ * @param {function(!FieldImage)=} opt_onClick Optional function to be
43
+ * called when the image is clicked. If opt_onClick is defined, opt_alt
44
+ * must also be defined.
45
+ * @param {boolean=} opt_flipRtl Whether to flip the icon in RTL.
46
+ * @param {Object=} opt_config A map of options used to configure the field.
47
+ * See the [field creation documentation]{@link
48
+ * https://developers.google.com/blockly/guides/create-custom-blocks/fields/built-in-fields/image#creation}
49
+ * for a list of properties this parameter supports.
50
+ */
51
+ constructor(
52
+ src, width, height, opt_alt, opt_onClick, opt_flipRtl, opt_config) {
53
+ super(Field.SKIP_SETUP);
54
+
55
+ // Return early.
56
+ if (!src) {
57
+ throw Error('Src value of an image field is required');
58
+ }
59
+ const imageHeight = Number(parsing.replaceMessageReferences(height));
60
+ const imageWidth = Number(parsing.replaceMessageReferences(width));
61
+ if (isNaN(imageHeight) || isNaN(imageWidth)) {
62
+ throw Error(
63
+ 'Height and width values of an image field must cast to' +
64
+ ' numbers.');
65
+ }
66
+ if (imageHeight <= 0 || imageWidth <= 0) {
67
+ throw Error(
68
+ 'Height and width values of an image field must be greater' +
69
+ ' than 0.');
70
+ }
71
+
72
+ /**
73
+ * The size of the area rendered by the field.
74
+ * @type {Size}
75
+ * @protected
76
+ * @override
77
+ */
78
+ this.size_ = new Size(imageWidth, imageHeight + FieldImage.Y_PADDING);
79
+
80
+ /**
81
+ * Store the image height, since it is different from the field height.
82
+ * @type {number}
83
+ * @private
84
+ */
85
+ this.imageHeight_ = imageHeight;
86
+
87
+ /**
88
+ * The function to be called when this field is clicked.
89
+ * @type {?function(!FieldImage)}
90
+ * @private
91
+ */
92
+ this.clickHandler_ = null;
93
+
94
+ if (typeof opt_onClick === 'function') {
95
+ this.clickHandler_ = opt_onClick;
96
+ }
97
+
98
+ /**
99
+ * The rendered field's image element.
100
+ * @type {SVGImageElement}
101
+ * @private
102
+ */
103
+ this.imageElement_ = null;
104
+
105
+ /**
106
+ * Editable fields usually show some sort of UI indicating they are
107
+ * editable. This field should not.
108
+ * @type {boolean}
109
+ * @const
110
+ */
111
+ this.EDITABLE = false;
112
+
113
+ /**
114
+ * Used to tell if the field needs to be rendered the next time the block is
115
+ * rendered. Image fields are statically sized, and only need to be
116
+ * rendered at initialization.
117
+ * @type {boolean}
118
+ * @protected
119
+ */
120
+ this.isDirty_ = false;
121
+
122
+ /**
123
+ * Whether to flip this image in RTL.
124
+ * @type {boolean}
125
+ * @private
126
+ */
127
+ this.flipRtl_ = false;
128
+
129
+ /**
130
+ * Alt text of this image.
131
+ * @type {string}
132
+ * @private
133
+ */
134
+ this.altText_ = '';
135
+
136
+ if (src === Field.SKIP_SETUP) return;
137
+
138
+ if (opt_config) {
139
+ this.configure_(opt_config);
140
+ } else {
141
+ this.flipRtl_ = !!opt_flipRtl;
142
+ this.altText_ = parsing.replaceMessageReferences(opt_alt) || '';
143
+ }
144
+ this.setValue(parsing.replaceMessageReferences(src));
63
145
  }
64
146
 
65
- // Initialize configurable properties.
66
147
  /**
67
- * Whether to flip this image in RTL.
68
- * @type {boolean}
69
- * @private
148
+ * Configure the field based on the given map of options.
149
+ * @param {!Object} config A map of options to configure the field based on.
150
+ * @protected
151
+ * @override
70
152
  */
71
- this.flipRtl_ = false;
153
+ configure_(config) {
154
+ super.configure_(config);
155
+ this.flipRtl_ = !!config['flipRtl'];
156
+ this.altText_ = parsing.replaceMessageReferences(config['alt']) || '';
157
+ }
72
158
 
73
159
  /**
74
- * Alt text of this image.
75
- * @type {string}
76
- * @private
160
+ * Create the block UI for this image.
161
+ * @package
77
162
  */
78
- this.altText_ = '';
163
+ initView() {
164
+ this.imageElement_ = dom.createSvgElement(
165
+ Svg.IMAGE, {
166
+ 'height': this.imageHeight_ + 'px',
167
+ 'width': this.size_.width + 'px',
168
+ 'alt': this.altText_,
169
+ },
170
+ this.fieldGroup_);
171
+ this.imageElement_.setAttributeNS(
172
+ dom.XLINK_NS, 'xlink:href', /** @type {string} */ (this.value_));
79
173
 
80
- FieldImage.superClass_.constructor.call(this, src, null, opt_config);
174
+ if (this.clickHandler_) {
175
+ this.imageElement_.style.cursor = 'pointer';
176
+ }
177
+ }
178
+
179
+ /**
180
+ * @override
181
+ */
182
+ updateSize_() {
183
+ // NOP
184
+ }
81
185
 
82
- if (!opt_config) { // If the config wasn't passed, do old configuration.
83
- this.flipRtl_ = !!opt_flipRtl;
84
- this.altText_ = parsing.replaceMessageReferences(opt_alt) || '';
186
+ /**
187
+ * Ensure that the input value (the source URL) is a string.
188
+ * @param {*=} opt_newValue The input value.
189
+ * @return {?string} A string, or null if invalid.
190
+ * @protected
191
+ */
192
+ doClassValidation_(opt_newValue) {
193
+ if (typeof opt_newValue !== 'string') {
194
+ return null;
195
+ }
196
+ return opt_newValue;
85
197
  }
86
198
 
87
- // Initialize other properties.
88
199
  /**
89
- * The size of the area rendered by the field.
90
- * @type {Size}
200
+ * Update the value of this image field, and update the displayed image.
201
+ * @param {*} newValue The value to be saved. The default validator guarantees
202
+ * that this is a string.
91
203
  * @protected
204
+ */
205
+ doValueUpdate_(newValue) {
206
+ this.value_ = newValue;
207
+ if (this.imageElement_) {
208
+ this.imageElement_.setAttributeNS(
209
+ dom.XLINK_NS, 'xlink:href', String(this.value_));
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Get whether to flip this image in RTL
215
+ * @return {boolean} True if we should flip in RTL.
92
216
  * @override
93
217
  */
94
- this.size_ = new Size(imageWidth, imageHeight + FieldImage.Y_PADDING);
218
+ getFlipRtl() {
219
+ return this.flipRtl_;
220
+ }
95
221
 
96
222
  /**
97
- * Store the image height, since it is different from the field height.
98
- * @type {number}
99
- * @private
223
+ * Set the alt text of this image.
224
+ * @param {?string} alt New alt text.
225
+ * @public
100
226
  */
101
- this.imageHeight_ = imageHeight;
227
+ setAlt(alt) {
228
+ if (alt === this.altText_) {
229
+ return;
230
+ }
231
+ this.altText_ = alt || '';
232
+ if (this.imageElement_) {
233
+ this.imageElement_.setAttribute('alt', this.altText_);
234
+ }
235
+ }
102
236
 
103
237
  /**
104
- * The function to be called when this field is clicked.
105
- * @type {?function(!FieldImage)}
106
- * @private
238
+ * If field click is called, and click handler defined,
239
+ * call the handler.
240
+ * @protected
107
241
  */
108
- this.clickHandler_ = null;
242
+ showEditor_() {
243
+ if (this.clickHandler_) {
244
+ this.clickHandler_(this);
245
+ }
246
+ }
109
247
 
110
- if (typeof opt_onClick === 'function') {
111
- this.clickHandler_ = opt_onClick;
248
+ /**
249
+ * Set the function that is called when this image is clicked.
250
+ * @param {?function(!FieldImage)} func The function that is called
251
+ * when the image is clicked, or null to remove.
252
+ */
253
+ setOnClickHandler(func) {
254
+ this.clickHandler_ = func;
112
255
  }
113
256
 
114
257
  /**
115
- * The rendered field's image element.
116
- * @type {SVGImageElement}
117
- * @private
258
+ * Use the `getText_` developer hook to override the field's text
259
+ * representation.
260
+ * Return the image alt text instead.
261
+ * @return {?string} The image alt text.
262
+ * @protected
263
+ * @override
118
264
  */
119
- this.imageElement_ = null;
120
- };
121
- object.inherits(FieldImage, Field);
265
+ getText_() {
266
+ return this.altText_;
267
+ }
268
+
269
+ /**
270
+ * Construct a FieldImage from a JSON arg object,
271
+ * dereferencing any string table references.
272
+ * @param {!Object} options A JSON object with options (src, width, height,
273
+ * alt, and flipRtl).
274
+ * @return {!FieldImage} The new field instance.
275
+ * @package
276
+ * @nocollapse
277
+ */
278
+ static fromJson(options) {
279
+ // `this` might be a subclass of FieldImage if that class doesn't override
280
+ // the static fromJson method.
281
+ return new this(
282
+ options['src'], options['width'], options['height'], undefined,
283
+ undefined, undefined, options);
284
+ }
285
+ }
122
286
 
123
287
  /**
124
288
  * The default value for this field.
@@ -127,23 +291,6 @@ object.inherits(FieldImage, Field);
127
291
  */
128
292
  FieldImage.prototype.DEFAULT_VALUE = '';
129
293
 
130
- /**
131
- * Construct a FieldImage from a JSON arg object,
132
- * dereferencing any string table references.
133
- * @param {!Object} options A JSON object with options (src, width, height,
134
- * alt, and flipRtl).
135
- * @return {!FieldImage} The new field instance.
136
- * @package
137
- * @nocollapse
138
- */
139
- FieldImage.fromJson = function(options) {
140
- // `this` might be a subclass of FieldImage if that class doesn't override
141
- // the static fromJson method.
142
- return new this(
143
- options['src'], options['width'], options['height'], undefined, undefined,
144
- undefined, options);
145
- };
146
-
147
294
  /**
148
295
  * Vertical padding below the image, which is included in the reported height of
149
296
  * the field.
@@ -152,144 +299,6 @@ FieldImage.fromJson = function(options) {
152
299
  */
153
300
  FieldImage.Y_PADDING = 1;
154
301
 
155
- /**
156
- * Editable fields usually show some sort of UI indicating they are
157
- * editable. This field should not.
158
- * @type {boolean}
159
- */
160
- FieldImage.prototype.EDITABLE = false;
161
-
162
- /**
163
- * Used to tell if the field needs to be rendered the next time the block is
164
- * rendered. Image fields are statically sized, and only need to be
165
- * rendered at initialization.
166
- * @type {boolean}
167
- * @protected
168
- */
169
- FieldImage.prototype.isDirty_ = false;
170
-
171
- /**
172
- * Configure the field based on the given map of options.
173
- * @param {!Object} config A map of options to configure the field based on.
174
- * @protected
175
- * @override
176
- */
177
- FieldImage.prototype.configure_ = function(config) {
178
- FieldImage.superClass_.configure_.call(this, config);
179
- this.flipRtl_ = !!config['flipRtl'];
180
- this.altText_ = parsing.replaceMessageReferences(config['alt']) || '';
181
- };
182
-
183
- /**
184
- * Create the block UI for this image.
185
- * @package
186
- */
187
- FieldImage.prototype.initView = function() {
188
- this.imageElement_ = dom.createSvgElement(
189
- Svg.IMAGE, {
190
- 'height': this.imageHeight_ + 'px',
191
- 'width': this.size_.width + 'px',
192
- 'alt': this.altText_,
193
- },
194
- this.fieldGroup_);
195
- this.imageElement_.setAttributeNS(
196
- dom.XLINK_NS, 'xlink:href', /** @type {string} */ (this.value_));
197
-
198
- if (this.clickHandler_) {
199
- this.imageElement_.style.cursor = 'pointer';
200
- }
201
- };
202
-
203
- /**
204
- * @override
205
- */
206
- FieldImage.prototype.updateSize_ = function() {
207
- // NOP
208
- };
209
-
210
- /**
211
- * Ensure that the input value (the source URL) is a string.
212
- * @param {*=} opt_newValue The input value.
213
- * @return {?string} A string, or null if invalid.
214
- * @protected
215
- */
216
- FieldImage.prototype.doClassValidation_ = function(opt_newValue) {
217
- if (typeof opt_newValue !== 'string') {
218
- return null;
219
- }
220
- return opt_newValue;
221
- };
222
-
223
- /**
224
- * Update the value of this image field, and update the displayed image.
225
- * @param {*} newValue The value to be saved. The default validator guarantees
226
- * that this is a string.
227
- * @protected
228
- */
229
- FieldImage.prototype.doValueUpdate_ = function(newValue) {
230
- this.value_ = newValue;
231
- if (this.imageElement_) {
232
- this.imageElement_.setAttributeNS(
233
- dom.XLINK_NS, 'xlink:href', String(this.value_));
234
- }
235
- };
236
-
237
- /**
238
- * Get whether to flip this image in RTL
239
- * @return {boolean} True if we should flip in RTL.
240
- * @override
241
- */
242
- FieldImage.prototype.getFlipRtl = function() {
243
- return this.flipRtl_;
244
- };
245
-
246
- /**
247
- * Set the alt text of this image.
248
- * @param {?string} alt New alt text.
249
- * @public
250
- */
251
- FieldImage.prototype.setAlt = function(alt) {
252
- if (alt === this.altText_) {
253
- return;
254
- }
255
- this.altText_ = alt || '';
256
- if (this.imageElement_) {
257
- this.imageElement_.setAttribute('alt', this.altText_);
258
- }
259
- };
260
-
261
- /**
262
- * If field click is called, and click handler defined,
263
- * call the handler.
264
- * @protected
265
- */
266
- FieldImage.prototype.showEditor_ = function() {
267
- if (this.clickHandler_) {
268
- this.clickHandler_(this);
269
- }
270
- };
271
-
272
- /**
273
- * Set the function that is called when this image is clicked.
274
- * @param {?function(!FieldImage)} func The function that is called
275
- * when the image is clicked, or null to remove.
276
- */
277
- FieldImage.prototype.setOnClickHandler = function(func) {
278
- this.clickHandler_ = func;
279
- };
280
-
281
- /**
282
- * Use the `getText_` developer hook to override the field's text
283
- * representation.
284
- * Return the image alt text instead.
285
- * @return {?string} The image alt text.
286
- * @protected
287
- * @override
288
- */
289
- FieldImage.prototype.getText_ = function() {
290
- return this.altText_;
291
- };
292
-
293
302
  fieldRegistry.register('field_image', FieldImage);
294
303
 
295
304
  exports.FieldImage = FieldImage;