feat: add extension point for overriding Grid functionality #8751
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The basics
The details
Resolves
Fixes #8614
Proposed Changes
Refactors the Grid class so that it can be overridden by a plugin. The static methods for parsing grid options and creating the SVG pattern element have also been moved onto a new GridProvider class which can be passed in as a plugin in the BlocklyOptions object. The implementations of these functions are unchanged; they just got moved around.
Originally, I just wanted these to be static methods on the IGrid interface, but the typings for the registry's
getClass
functions don't really allow for static properties and I didn't want to tear all that up in this PR.I would love some feedback on the typing of GridOptions here. My example use case for this is the MakeCode Minecraft editor which overrides the grid with a background image that scrolls with the workspace. A plugin that provided that functionality would likely need to extend the GridOptions type with extra fields like the URL of the image, width/height, opacity, etc. However, the
grid
property of the BlocklyOptions object passed to inject is pretty strongly typed; the only way around it right now is to do a lot of casting toany
.Reason for Changes
See the linked issue for reasoning!
Test Coverage
Tested manually in the playground and by creating a test plugin locally. Happy to add unit tests, but I didn't see any for other extension points at a click glance.
Documentation
Additional Information
I can also add a plugin to blockly-samples that utilizes this change should this PR be approved.