Skip to content

feat: Add a JSON Block definition interface#9613

Open
heliacer wants to merge 1 commit intoRaspberryPiFoundation:mainfrom
heliacer:main
Open

feat: Add a JSON Block definition interface#9613
heliacer wants to merge 1 commit intoRaspberryPiFoundation:mainfrom
heliacer:main

Conversation

@heliacer
Copy link

@heliacer heliacer commented Mar 5, 2026

This is a follow-up of #9402 :D (please read)

Changes:

  • Add custom field/input support as requested by @maribethb
  • Add tests in tests/typescript for field mitosis

The custom fields are done by augmenting, as shown in the jsdoc example.
Also I'm not too proud of the documentation strings in general but I'm leaving it as-is now.

lmk if I need to change something in order to merge :>

Copilot AI review requested due to automatic review settings March 5, 2026 18:59
@heliacer heliacer requested a review from a team as a code owner March 5, 2026 18:59
@heliacer heliacer requested a review from gonfunko March 5, 2026 18:59
@github-actions github-actions bot added the PR: feature Adds a feature label Mar 5, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@gonfunko gonfunko requested a review from maribethb March 12, 2026 15:32
@gonfunko gonfunko removed their request for review March 12, 2026 15:33
@gonfunko gonfunko removed their assignment Mar 12, 2026
@heliacer
Copy link
Author

hi, I noticed the review assignment changed,
@maribethb pinging in case you have time to review this.
thanks :D

@heliacer
Copy link
Author

bump again :D

Copy link
Contributor

@maribethb maribethb left a comment

Choose a reason for hiding this comment

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

Thank you so much for your patience while we reviewed this. This needed some consultation from our resident TS expert and after chatting with him I think we want to go in a different direction for custom fields for now. But the rest of this is mostly solid, thank you for your work on it.

{
'type': 'field_variable',
'name': 'VAR',
'variable': null,
Copy link
Contributor

Choose a reason for hiding this comment

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

The change to this file should not be made. You are changing the block definitions in unexpected ways.

'variable': '%{BKY_VARIABLES_DEFAULT_NAME}',
},
],
'output': null,
Copy link
Contributor

Choose a reason for hiding this comment

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

The change to this file should also be reverted. You've removed an output from one block and added it to a different one unexpectedly. This will change the function and shape of the blocks.

*
* @example
* ```typescript
* declare module 'blockly/core/interfaces/i_json_block_definition' {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an interesting idea, but I don't think it's a pattern we want to add here. Using declare module to augment the types might work, but we'd probably want to implement it in a different way so that developers don't have to use this specific filepath which is more of an implementation detail.

I think for now, it would be best to have custom fields/inputs/args use unknown type. While this isn't as helpful as having a fully typed interface, it would let developers create their own types for their own internal use but pass them to Blockly as unknown, which is an acceptable compromise at this point.

name?: string;
}

export type FieldsAlign = 'LEFT' | 'RIGHT' | 'CENTRE';
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to use Blockly.inputs.Align for this instead of redeclaring these strings.


import './different_user_input';

declare module 'blockly-test/core/interfaces/i_json_block_definition' {
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed above, if you have the internal Blockly types use unknown for custom fields, you should still be able to declare and use this type locally (so without the declare module bit).

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

Labels

PR: feature Adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants