mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Merge pull request #934 from picklesrus/extensions-dynamic-menu
Extensions dynamic menu
This commit is contained in:
commit
219f083a29
3 changed files with 64 additions and 16 deletions
|
@ -569,22 +569,21 @@ class Runtime extends EventEmitter {
|
|||
*/
|
||||
_buildMenuForScratchBlocks (menuName, menuItems, categoryInfo) {
|
||||
const menuId = this._makeExtensionMenuId(menuName, categoryInfo.id);
|
||||
|
||||
/** @TODO: support dynamic menus when 'menuItems' is a method name string (see extension spec) */
|
||||
if (typeof menuItems === 'string') {
|
||||
throw new Error(`Dynamic extension menus are not yet supported. Menu name: ${menuName}`);
|
||||
let options = null;
|
||||
if (typeof menuItems === 'function') {
|
||||
options = menuItems;
|
||||
} else {
|
||||
options = menuItems.map(item => {
|
||||
switch (typeof item) {
|
||||
case 'string':
|
||||
return [item, item];
|
||||
case 'object':
|
||||
return [item.text, item.value];
|
||||
default:
|
||||
throw new Error(`Can't interpret menu item: ${item}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
const options = menuItems.map(item => {
|
||||
switch (typeof item) {
|
||||
case 'string':
|
||||
return [item, item];
|
||||
case 'object':
|
||||
return [item.text, item.value];
|
||||
default:
|
||||
throw new Error(`Can't interpret menu item: ${item}`);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
json: {
|
||||
message0: '%1',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue