blockly 7.20211209.4 → 8.0.1
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 +5 -4
- package/blockly_compressed.js +4 -3
- 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 +45 -32
- package/blocks/text.js +22 -13
- package/blocks/variables.js +14 -3
- package/blocks/variables_dynamic.js +13 -3
- package/blocks_compressed.js +1 -1
- 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 +26 -10
- 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/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/msg/smn.js +436 -0
- package/package.json +7 -6
- package/blocks/all.js +0 -23
package/core/field_image.js
CHANGED
|
@@ -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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
*
|
|
68
|
-
* @
|
|
69
|
-
* @
|
|
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
|
-
|
|
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
|
-
*
|
|
75
|
-
* @
|
|
76
|
-
* @private
|
|
160
|
+
* Create the block UI for this image.
|
|
161
|
+
* @package
|
|
77
162
|
*/
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
*
|
|
90
|
-
* @
|
|
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
|
-
|
|
218
|
+
getFlipRtl() {
|
|
219
|
+
return this.flipRtl_;
|
|
220
|
+
}
|
|
95
221
|
|
|
96
222
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @
|
|
99
|
-
* @
|
|
223
|
+
* Set the alt text of this image.
|
|
224
|
+
* @param {?string} alt New alt text.
|
|
225
|
+
* @public
|
|
100
226
|
*/
|
|
101
|
-
|
|
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
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* @
|
|
238
|
+
* If field click is called, and click handler defined,
|
|
239
|
+
* call the handler.
|
|
240
|
+
* @protected
|
|
107
241
|
*/
|
|
108
|
-
|
|
242
|
+
showEditor_() {
|
|
243
|
+
if (this.clickHandler_) {
|
|
244
|
+
this.clickHandler_(this);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
109
247
|
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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;
|