Skip to content

Conversation

@heliacer
Copy link

@heliacer heliacer commented Oct 3, 2025

The basics

The details

Resolves

Implements JSON Block Definition interface proposed in #9387

Proposed Changes

Introduces a new JsonBlockDefinition in core/interfaces/

  • Added core/interfaces/i_json_block_definition.ts with JsonBlockDefinition and BlockArg definitions
  • Migrated Block.jsonInit, jsonInitFactory, defineBlocksWithJsonArray and createBlockDefinitionsFromJsonArray to use the new interface
  • Migrated interpolate to use the new BlockArg type
  • Updated all built-in block JSON definitions in blocks/ to explicitly set 'output': null to match the default behaviour in the block factory
  • Removed legacy AnyDuringMigration usage for JSON block definitions

Reason for Changes

Makes it easier to write valid JSON Block definitions without having to always rely on the block factory

Test Coverage

I ran the unit test suite and manually loaded the playground with the updated blocks to ensure they still render and connect correctly

Documentation

Not needed

Additional Information

I found another issue while testing (unrelated to this) in the default Playground, when Categories: (typed variables) is selected, the colour category errors out because of an invalid colour_picker definition

@heliacer heliacer requested a review from a team as a code owner October 3, 2025 21:23
@heliacer heliacer requested a review from gonfunko October 3, 2025 21:23
@heliacer heliacer marked this pull request as draft October 3, 2025 21:23
@heliacer heliacer marked this pull request as ready for review October 3, 2025 21:54
@heliacer
Copy link
Author

heliacer commented Nov 3, 2025

@gonfunko bump, will this be considered? 👀

@gonfunko
Copy link
Contributor

gonfunko commented Nov 3, 2025

Yes, sorry for the delay on this! Will try to get you an initial review this week, thank you for the ping on it.

Copy link
Contributor

@gonfunko gonfunko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks promising; added a couple notes. I'd like to run this by my colleagues before merging, but as you may have seen we're transitioning from Google to the Raspberry Pi Foundation so it may be a couple weeks until things are settled.

Comment on lines +41 to +95
interface CommonArg {
name?: string;
}

/** Input Args */
interface InputValueArg extends CommonArg {
type: 'input_value';
check?: string | string[];
align?: FieldsAlign
}
interface InputStatementArg extends CommonArg {
type: 'input_statement';
check?: string | string[];
}
interface InputDummyArg extends CommonArg {
type: 'input_dummy';
}

/** Field Args */
interface FieldInputArg extends CommonArg{
type: 'field_input'
text: string
}

interface FieldNumberArg extends CommonArg {
type: 'field_number';
value?: number;
min?: number;
max?: number;
precision?: number;
}

interface FieldDropdownArg extends CommonArg {
type: 'field_dropdown';
options: [string, string][];
}

interface FieldCheckboxArg extends CommonArg {
type: 'field_checkbox';
checked?: boolean | 'TRUE' | 'FALSE';
}

interface FieldImageArg {
type: 'field_image';
src: string;
width: number;
height: number;
alt?: string;
flipRtl?: boolean | 'TRUE' | 'FALSE';
}

interface FieldVariableArg extends CommonArg {
type: 'field_variable'
variable: string | null
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each of the Field classes defines and exports a FieldXYZFromJsonConfig interface, which I think should be used in place of these to avoid duplication/skew.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh, didn't know these configs existed 👀

interface FieldInputArg extends FieldTextInputFromJsonConfig {
  name: string
  type: 'field_input'
}

interface FieldNumberArg extends FieldNumberFromJsonConfig {
  name: string
  type: 'field_number'
}
// ...

wdyt 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gonfunko bump again, hope this finds you well since there was all the migration from google to rpf and stuff 👀
I would definitely want to include your suggested changes, but before I do, can you run this and lmk if it works?
Thanks 😃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the bump, and yes, we're all moved over and all is well. The approach to the interfaces you proposed in your prior comment makes sense to me, so updating it along those lines sounds good.

@heliacer heliacer marked this pull request as draft November 8, 2025 17:33
@heliacer
Copy link
Author

heliacer commented Nov 8, 2025

converted this to draft, will implement @gonfunko's review feedback sooner or later :>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants