scratch-blocks 2.1.12 → 2.1.13
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scratch_field_dropdown.d.ts","sourceRoot":"","sources":["../../../../src/fields/scratch_field_dropdown.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scratch_field_dropdown.d.ts","sourceRoot":"","sources":["../../../../src/fields/scratch_field_dropdown.ts"],"names":[],"mappings":"AAiFA;;GAEG;AACH,wBAAgB,4BAA4B,SAG3C"}
|
package/package.json
CHANGED
|
@@ -7,6 +7,50 @@ import * as Blockly from 'blockly/core'
|
|
|
7
7
|
class ScratchFieldDropdown extends Blockly.FieldDropdown {
|
|
8
8
|
private originalStyle!: string
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Accept string values even when they are not in the current options list.
|
|
12
|
+
* Scratch populates some dropdowns from dynamic data (e.g. the sprite list
|
|
13
|
+
* for motion_goto_menu, motion_pointtowards_menu, sensing_touchingobject_menu)
|
|
14
|
+
* and deliberately excludes the currently-editing sprite. A block moved into
|
|
15
|
+
* the sprite it now targets carries a stored value that is therefore absent
|
|
16
|
+
* from the option list for this editing context, but is still valid — the
|
|
17
|
+
* runtime reads the stored value directly. Preserve that value so the UI
|
|
18
|
+
* shows what the block actually does, rather than silently reverting to the
|
|
19
|
+
* first option.
|
|
20
|
+
* @param newValue The value to validate.
|
|
21
|
+
* @returns The value unchanged if it is a string; otherwise null to reject
|
|
22
|
+
* the update.
|
|
23
|
+
*/
|
|
24
|
+
protected override doClassValidation_(newValue?: string): string | null {
|
|
25
|
+
if (typeof newValue !== 'string') {
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
return newValue
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* When the stored value is not in the current options list, display the raw
|
|
33
|
+
* value. Blockly's base implementation reads from the last-matched option,
|
|
34
|
+
* which stays stale when the incoming value does not appear in the list, so
|
|
35
|
+
* the default would otherwise render as the first option's text.
|
|
36
|
+
* @returns Text to display for the currently-selected value.
|
|
37
|
+
*/
|
|
38
|
+
protected override getText_(): string | null {
|
|
39
|
+
const value = this.getValue()
|
|
40
|
+
if (value === null) {
|
|
41
|
+
return super.getText_()
|
|
42
|
+
}
|
|
43
|
+
for (const option of this.getOptions(true)) {
|
|
44
|
+
if (option === 'separator') continue
|
|
45
|
+
if (option[1] === value) {
|
|
46
|
+
// Delegate to the base for the matched case so image/HTMLElement
|
|
47
|
+
// option types render correctly.
|
|
48
|
+
return super.getText_()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return value
|
|
52
|
+
}
|
|
53
|
+
|
|
10
54
|
showEditor_(event: PointerEvent) {
|
|
11
55
|
super.showEditor_(event)
|
|
12
56
|
const sourceBlock = this.getSourceBlock() as Blockly.BlockSvg
|