From 93abc0b34bc6dd209308304539ca97a86ff0a86e Mon Sep 17 00:00:00 2001 From: Liz Looney Date: Sun, 9 Nov 2025 21:43:57 -0800 Subject: [PATCH] Fixed code in ComponentBlock.updateBlock_ where it needs the module type. --- src/blocks/mrc_component.ts | 12 +++++++++--- src/blocks/utils/workspaces.ts | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/blocks/mrc_component.ts b/src/blocks/mrc_component.ts index 0b2b80e3..4a1bb1a5 100644 --- a/src/blocks/mrc_component.ts +++ b/src/blocks/mrc_component.ts @@ -59,6 +59,11 @@ type ComponentExtraState = { // If staticFunctionName is not present, generate the constructor. staticFunctionName?: string, params?: ConstructorArg[], + /** + * The module type. Note that this is only present when blocks are created for the toolbox. It is not + * saved to the blocks file. + */ + moduleType? : storageModule.ModuleType, } export type ComponentBlock = Blockly.Block & ComponentMixin; @@ -137,13 +142,13 @@ const COMPONENT = { }); }); } - this.updateBlock_(); + this.updateBlock_(extraState); }, /** * Update the block to reflect the newly loaded extra state. */ - updateBlock_: function (this: ComponentBlock): void { - const moduleType = getModuleTypeForWorkspace(this.workspace); + updateBlock_: function (this: ComponentBlock, extraState: ComponentExtraState): void { + const moduleType = extraState.moduleType ? extraState.moduleType : getModuleTypeForWorkspace(this.workspace); if (moduleType === storageModule.ModuleType.ROBOT) { // Add input sockets for the arguments. for (let i = 0; i < this.mrcArgs.length; i++) { @@ -297,6 +302,7 @@ function createComponentBlock( //TODO(ags): Remove this because we know what the constructor name is staticFunctionName: constructorData.functionName, params: [], + moduleType: moduleType, }; const fields: {[key: string]: any} = {}; fields[FIELD_NAME] = componentName; diff --git a/src/blocks/utils/workspaces.ts b/src/blocks/utils/workspaces.ts index 30cd0d03..02326df9 100644 --- a/src/blocks/utils/workspaces.ts +++ b/src/blocks/utils/workspaces.ts @@ -38,6 +38,14 @@ export function getModuleTypeForWorkspace(workspace: Blockly.Workspace): storage if (workspace.id in workspaceIdToModuleType) { return workspaceIdToModuleType[workspace.id]; } + // If the workspace id was not found, it might be because the workspace is associated with a + // block mutator's flyout. Try this workspaces's root workspace. + const rootWorkspace = workspace.getRootWorkspace(); + if (rootWorkspace && + rootWorkspace.id in workspaceIdToModuleType) { + return workspaceIdToModuleType[rootWorkspace.id]; + } + throw new Error('getModuleTypeForWorkspace: workspaceId not found: ' + workspace.id); }