Skip to content

Commit b657b34

Browse files
Share isImageProperties between implementations
1 parent cf5ffcb commit b657b34

File tree

3 files changed

+23
-42
lines changed

3 files changed

+23
-42
lines changed

pxtblocks/fields/field_textdropdown.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference path="../../built/pxtlib.d.ts" />
22

33
import * as Blockly from "blockly";
4-
import { clearDropDownDiv, FieldCustom, FieldCustomOptions } from "./field_utils";
4+
import { clearDropDownDiv, FieldCustom, FieldCustomOptions, isImageProperties } from "./field_utils";
55

66
export interface FieldTextDropdownOptions extends FieldCustomOptions {
77
values?: string;
@@ -384,25 +384,4 @@ function isStringArray(arr: any[]): arr is string[] {
384384
}
385385
}
386386
return true;
387-
}
388-
389-
/**
390-
* Returns whether or not an object conforms to the ImageProperties interface.
391-
*
392-
* @param obj The object to test.
393-
* @returns True if the object conforms to ImageProperties, otherwise false.
394-
*/
395-
function isImageProperties(obj: any): obj is Blockly.ImageProperties {
396-
return (
397-
obj &&
398-
typeof obj === 'object' &&
399-
'src' in obj &&
400-
typeof obj.src === 'string' &&
401-
'alt' in obj &&
402-
typeof obj.alt === 'string' &&
403-
'width' in obj &&
404-
typeof obj.width === 'number' &&
405-
'height' in obj &&
406-
typeof obj.height === 'number'
407-
);
408387
}

pxtblocks/fields/field_utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,4 +699,25 @@ function inflateJRes(jres: pxt.Map<pxt.JRes | string>): pxt.Map<pxt.JRes> {
699699
export function clearDropDownDiv() {
700700
Blockly.DropDownDiv.clearContent();
701701
Blockly.DropDownDiv.getContentDiv().style.height = "";
702+
}
703+
704+
/**
705+
* Returns whether or not an object conforms to the ImageProperties interface.
706+
*
707+
* @param obj The object to test.
708+
* @returns True if the object conforms to ImageProperties, otherwise false.
709+
*/
710+
export function isImageProperties(obj: any): obj is Blockly.ImageProperties {
711+
return (
712+
obj &&
713+
typeof obj === 'object' &&
714+
'src' in obj &&
715+
typeof obj.src === 'string' &&
716+
'alt' in obj &&
717+
typeof obj.alt === 'string' &&
718+
'width' in obj &&
719+
typeof obj.width === 'number' &&
720+
'height' in obj &&
721+
typeof obj.height === 'number'
722+
);
702723
}

pxtblocks/plugins/newVariableField/fieldDropdownMixin.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Blockly from "blockly";
2+
import { isImageProperties } from "../../fields";
23

34
// This is the same as showEditor_ and dropdownCreate in field_dropdown
45
// except that it supports separators between dropdown menu items
@@ -85,26 +86,6 @@ export function showEditorMixin(this: Blockly.FieldDropdown, e?: MouseEvent) {
8586
this.applyColour();
8687
}
8788

88-
/**
89-
* Returns whether or not an object conforms to the ImageProperties interface.
90-
*
91-
* @param obj The object to test.
92-
* @returns True if the object conforms to ImageProperties, otherwise false.
93-
*/
94-
function isImageProperties(obj: any): obj is Blockly.ImageProperties {
95-
return (
96-
obj &&
97-
typeof obj === 'object' &&
98-
'src' in obj &&
99-
typeof obj.src === 'string' &&
100-
'alt' in obj &&
101-
typeof obj.alt === 'string' &&
102-
'width' in obj &&
103-
typeof obj.width === 'number' &&
104-
'height' in obj &&
105-
typeof obj.height === 'number'
106-
);
107-
}
10889

10990
class HorizontalRuleMenuItem extends Blockly.MenuItem {
11091
element_: Element;

0 commit comments

Comments
 (0)