From ea823539ace3d34ac32bc3c3a8a6bf39bb612bf6 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Fri, 31 Jan 2025 18:30:25 -0800 Subject: [PATCH] Added support for disabled blocks, throw warning at runtime --- executor/index.ts | 8 +++++++- serializer/index.ts | 3 ++- serializer/types.ts | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/executor/index.ts b/executor/index.ts index 9475618bb0..a20fdda872 100644 --- a/executor/index.ts +++ b/executor/index.ts @@ -320,7 +320,7 @@ export class Executor { const path = match.slice(1, -1) // remove < and > const [blockRef, ...pathParts] = path.split('.') - // Try blockRef as ID, then as normalized name + // Try referencing as an ID, then as a normalized name. let sourceBlock = blockById.get(blockRef) if (!sourceBlock) { const normalized = blockRef.toLowerCase().replace(/\s+/g, '') @@ -332,6 +332,12 @@ export class Executor { continue } + // Check if the referenced block is disabled. + if (sourceBlock.enabled === false) { + console.warn(`Block "${sourceBlock.metadata?.title}" is disabled, and block "${block.metadata?.title}" depends on it.`) + continue + } + const sourceState = context.blockStates.get(sourceBlock.id) if (!sourceState) { console.warn(`No state found for block ID "${sourceBlock.id}".`) diff --git a/serializer/index.ts b/serializer/index.ts index db61c5dcb0..0869286e7b 100644 --- a/serializer/index.ts +++ b/serializer/index.ts @@ -53,7 +53,8 @@ export class Serializer { description: blockConfig.toolbar.description, category: blockConfig.toolbar.category, color: blockConfig.toolbar.bgColor - } + }, + enabled: block.enabled } } diff --git a/serializer/types.ts b/serializer/types.ts index efd2fd66bd..52aab8e4ec 100644 --- a/serializer/types.ts +++ b/serializer/types.ts @@ -30,4 +30,5 @@ export interface SerializedBlock { icon?: string color?: string } + enabled: boolean }