Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Google Blockly] v10 bump! #55770

Merged
merged 22 commits into from
Jan 18, 2024
Merged

[Google Blockly] v10 bump! #55770

merged 22 commits into from
Jan 18, 2024

Conversation

mikeharv
Copy link
Contributor

@mikeharv mikeharv commented Jan 16, 2024

This bump our version of Google Blockly to v10.3.1, which is the most recent version!

Major release notes: https://github.com/google/blockly/releases/tag/blockly-v10.0.0

Breaking changes addressed

Some thing were renamed:

Simplest to fix were some renamed variables, such as arrow_ to arrow.
See commits bf5d0fd, f7a08d4, 7c44082, 73555d1 for details.

New API for Generators

Code generators were refactored here: google/blockly#7150
Where previously, we might have said generator.sprite_parameter_get, for a generator function, now it would be generator.forBlock.sprite_parameter_get. In a couple of places we can just patch this. Additionally, we can also assign all the properties of our JS generator to forBlock. Even though this isn't technically a breaking change, it was causing a flood of deprecation warnings, so we needed to address it. See first commit: 51af955

Updated plugins

All Blockly plugins were updated to v10 compatible versions. These were tested manually. An exception exists for @blockly/renderer-inline-row-separators which was deprecated. See below.

Inline Row Separators -> End Row Inputs

A plugin that we have been relying on (for minitoolbox blocks) was deprecated with v10.2.
https://www.npmjs.com/package/@blockly/renderer-inline-row-separators
This changes our logic slightly. The plugin allowed us to arrange multiple inline value input connectors on separate rows by inserting dummy inputs between them (ie. we could put the dummy input with a flyout field below the other inputs, as long as the row also ended with a dummy input). Now the flyout field's input needs to follow an end row input (https://developers.google.com/blockly/guides/create-custom-blocks/define-blocks#block_inputs).
This means we need to convert the last input of a block from dummy to end row type. The only difference is that end row inputs always acts like a newline. This gets complicated as these custom blocks are made by our infamous block_utils flow. As far as I can tell we only use a dummy at the end of a block so it should be safe to just always use end row inputs now - for all blocks. Again, the only difference is that they will always mark the end of a row.
CDO Blockly has no concept of end row inputs so I added a monkey patch to its wrapper. I opted for this change over the opposite because once Sprite Lab is migrated, the only CDO Blockly still using block_utils will be Minecraft.

Included Improvements

Edit buttons can show in modal function editor

https://codedotorg.atlassian.net/browse/CT-124
The shareable procedures plugin has been updated so that we're now able to edit a function in the modal editor even when it's already open. This work was drafted #55155 back in November. I included it here because it's the single biggest feature that the v10 bump was blocking. Note that the buttons to create Functions/Behaviors are hidden from the modal editor's toolbox, but they would now work correctly if added.
image

Flyout fields cleaned up

The v10 update also includes a new render management system. Other than that it should improve rendering efficiency, we shouldn't have to interact with it much. However, Beka and I discovered that it had a couple of bugs that were causing issues when our mini-toolbox blocks would dynamically create their flyout fields. This was be patched in Blockly version 10.3.1, which is why we are using that version in this branch.
While pairing with Beka, we noticed that some of the code, originally sourced from outside our repo, seemed to be redundant or unnecessary for our implementation. Specifically, we had some leftover logic about showing and hide flyouts. This logic isn't needed because we were never hiding the flyouts; rather we just remove the field and flyout entirely when the user clicks the toggle. A few lines that were easy to remove have been deleted here.

Links

https://codedotorg.atlassian.net/browse/CT-1
https://codedotorg.atlassian.net/browse/CT-124
https://codedotorg.atlassian.net/browse/CT-130

Testing story

Some tests were failing initially. Our block utils test had to be updated to use appendEndRowInput. We also had some UI tests failures due to changes in how block ids were created.
Blockly had made a change here: google/blockly#7432
They've ended up reverting this for 10.3.1 for us which is another reason we need to use this specific version.

Deployment strategy

Follow-up work

Privacy

Security

Caching

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@mikeharv mikeharv requested a review from a team January 17, 2024 21:02
Copy link
Contributor

@molly-moen molly-moen left a comment

Choose a reason for hiding this comment

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

Looks good, some minor comments/questions

apps/src/blockly/addons/cdoFieldImage.js Outdated Show resolved Hide resolved
apps/src/blockly/addons/cdoFieldFlyout.js Outdated Show resolved Hide resolved
@@ -101,10 +101,10 @@ export default class FunctionEditor {
// we have to pass the main ws so that the correct procedures are populated
// false to not show the new function button inside the modal editor
this.editorWorkspace.registerToolboxCategoryCallback('PROCEDURE', () =>
functionsFlyoutCategory(Blockly.mainBlockSpace, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 It looks like passing the main workspace here vs. the editor workspace was intentional: we have to pass the main ws so that the correct procedures are populated. But we did move away from the mainBlockSpace language?

Copy link
Contributor Author

@mikeharv mikeharv Jan 18, 2024

Choose a reason for hiding this comment

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

We need to register this category using the editor workspace so that when we getNewFunctionButtonWithCallback, it register a button callback for the editor workspace. Otherwise, the button doesn't do anything if it's in the flyout for the modal editor. Note that we also register these category callbacks on the main workspace in the wrapper. We no longer have to look at the main workspace to find the procedures, so I'll removed that comment the Emily is quoting above.

Copy link
Contributor

Choose a reason for hiding this comment

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

So we don't care if the "new function"/"new behavior" button is rendered inside the editor toolbox? I see it in your screenshots and I don't think that's how it worked before (and I imagine, if we could avoid that, we'd want to?).

Copy link
Contributor

@ebeastlake ebeastlake Jan 18, 2024

Choose a reason for hiding this comment

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

Screenshot 2024-01-17 at 4 25 37 PM
Screenshot 2024-01-17 at 4 25 58 PM

We need to register this category using the editor workspace so that when we getNewFunctionButtonWithCallback, it register a button callback for the editor workspace. Otherwise, the button doesn't do anything if it's in the flyout for the modal editor.

But you're saying we want this button? I thought we a) didn't want it and b) didn't want it to do anything. (Sorry for two comments, my 4:30 PM brain is dragging.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you recall a reason why we wouldn't to be able to create a function/behavior from within the editor? I don't think there's a technical reason we can't, so maybe it's worth checking with Amy?

On CDO Blockly, you are right that you can't create a new function if the function editor is open (same for behaviors). Strangely, you can create a function if just the behavior editor is open (and vice versa). If you try this, things get gross, because CDO makes two modals which it isn't really meant to. :(

I'm not saying I know for sure, but I wonder if the decision to hide these buttons in the original modal editor was a technical one or a design decision.

Copy link
Contributor

@molly-moen molly-moen Jan 18, 2024

Choose a reason for hiding this comment

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

We no longer have to look at the main workspace to find the procedures

Why is this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mikeharv I think it was a design decision, but I'm not sure it's one I disagree with?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@molly-moen More detailed answer in Slack, but we always populate the flyout by looking for procedure blocks on both the main and hidden workspaces. I think the comment has long been out of date.

@ebeastlake I've made a partial revert so that we again only add the "Create" buttons to the flyout if we're on the main workspace. I've left in the change that would make these buttons work correctly if we did want to use them in the modal editor's toolbox at any point.

const blockList = [];

const behaviorDefinitionBlock = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify why this was removed? I see it's not currently used, but I don't remember when we stopped needing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was used to define an empty c-shaped behavior definition block that was placed in the toolbox when the modal editor was disabled. We do this for functions, but not behaviors because behaviors are always hidden from the main workspace. I originally added this back in the summer as a way of testing our earliest behavior blocks.

blockList.push(newFunctionButton);
} else {
// Note: Blockly.Msg was undefined when this code was extracted into global scope
const functionDefinitionBlock = {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit that doesn't need to be addressed: Since this is a block "constant"/"template" that I would have extracted into a constants file if I could have, it could also have continued to live above where it's used, but this also makes sense and no need to revert!

@@ -55,7 +53,6 @@ export const blocks = {
if (!block.getInput(INPUTS.FLYOUT)) {
const flyoutField = createFlyoutField(block);
flyoutField.showEditor();
flyoutField.render_();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this part of the flyout fields clean-up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! It was actually just redundant. Normally render_ should only be called by getSize.

Copy link
Contributor

@molly-moen molly-moen left a comment

Choose a reason for hiding this comment

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

yay v10! 🎉

@mikeharv mikeharv merged commit e5fdf34 into staging Jan 18, 2024
2 checks passed
@mikeharv mikeharv deleted the mike/blockly-v10 branch January 18, 2024 21:36
dju90 pushed a commit that referenced this pull request Feb 5, 2024
* bump blockly and plugins to v10.3

* connection check was renamed

* fix generator for sprite getter

* imageElement was renamed

* imageElement was renamed

* more renames

* allow procedure editing from within modal editor

* deprecate inline row separate; add end row inputs

* support end row input calls with cdo blockly

* rename appendDummyInput

* use multiline text input fields for descriptions

* bump to 10.3.1

* account for taller description field

* update comments

* partial revert: once again hide create buttons in modal

* Update functionEditor.js

* update block placement in eyes test

* revert multiline description fields
@bencodeorg bencodeorg restored the mike/blockly-v10 branch February 27, 2024 22:04
@bencodeorg bencodeorg deleted the mike/blockly-v10 branch February 27, 2024 22:06
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.

3 participants