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

fix: reenable reporting block values #55

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/block_reporting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as Blockly from 'blockly/core';
import {Colours} from '../core/colours.js';

export function reportValue(id, value) {
const block = Blockly.getMainWorkspace().getBlockById(id) ||
Blockly.getMainWorkspace().getFlyout().getWorkspace().getBlockById(id);
gonfunko marked this conversation as resolved.
Show resolved Hide resolved
if (!block) {
throw 'Tried to report value on block that does not exist.';
}
const field = block.inputList[0].fieldRow[0];
const contentDiv = Blockly.DropDownDiv.getContentDiv();
const valueReportBox = document.createElement('div');
valueReportBox.setAttribute('class', 'valueReportBox');
valueReportBox.innerText = value;
contentDiv.appendChild(valueReportBox);
Blockly.DropDownDiv.setColour(
Colours.valueReportBackground,
Colours.valueReportBorder
);
Blockly.DropDownDiv.showPositionedByBlock(field, block);
}
10 changes: 10 additions & 0 deletions src/checkable_continuous_flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ export class CheckableContinuousFlyout extends ContinuousFlyout {
super.show(flyoutDef);
}

serializeBlock(block) {
const json = super.serializeBlock(block);
// Delete the serialized block's ID so that a new one is generated when it is
// placed on the workspace. Otherwise, the block on the workspace may be
// indistinguishable from the one in the flyout, which can cause reporter blocks
// to have their value dropdown shown in the wrong place.
delete json.id;
return json;
}

clearOldCheckboxes() {
for (const checkbox of this.checkboxes_.values()) {
checkbox.svgRoot.remove();
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {CheckableContinuousFlyout} from './checkable_continuous_flyout.js';
import './scratch_continuous_category.js';

export * from 'blockly';
export * from './block_reporting.js';
export * from './categories.js';
export * from './procedures.js';
export * from '../core/colours.js';
Expand Down