Skip to content

Commit 1fba9c5

Browse files
authored
refactor!: Update and modernize plugins for Blockly v12. (#2468)
* refactor: Update ContinuousFlyout for compatibility with new flyout API. * chore: Rename ContinuousFlyout.js to ContinuousFlyout.ts. * chore: Rename ContinuousToolbox.js to ContinuousToolbox.ts. * chore: Rename ContinuousMetricsFlyout.js to ContinuousMetricsFlyout.ts. * chore: Rename ContinuousCategory.js to ContinuousCategory.ts. * chore: Rename ContinuousMetrics.js to ContinuousMetrics.ts. * chore: Rename index.js to index.ts. * refactor: Convert ContinuousToolbox to Typescript * chore: Name RecyclableBlockFlyoutInflater.ts consistently with other files. * refactor: Add and use a function for registering the continuous toolbox. * chore: Improve docs. * feat: Add support for autoclosing continuous toolboxes. * fix: Fix bug when making configuration changes in the playground. * refactor: Update visibility on RecyclableBlockFlyoutInflater. * fix: Use the recycleEligibilityChecker callback if set. * refactor: Make converting toolbox items to flyout items more extensible. * chore: Remove debugging. * fix: Debounce flyout refreshes. * chore: Remove unused import. * chore: Fix TSDoc args. * chore: Add TSDoc for registration function. * refactor: Clean up implementation of recordScrollPositions. * chore: Fix TSDoc. * chore: Remove unneeded underscores in symbol names. * chore: Suppress unavoidable lint errors. * fix: Fix alignment when jumping to a category. * fix: Fix injection options and documentation. * chore: Fix typo. * refactor: Make the ContinuousFlyoutMetrics class and file name consistent. * fix: Update flyout contents in response to procedure mutations. * refactor: Make the RecyclableBlockFlyoutInflater inert for non-continuous flyouts. * fix: Fix alignment of toolbox labels. * chore: Update to use Blockly v12 beta. * chore: Update plugins for compatibility with Blockly v12. * fix: Fix tests for v12 compatibility. * fix: Fix bug that could cause scroll jank when interrupting an animated scroll. * chore: Revert errant test change. * refactor: Update continuous-toolbox for latest flyout API changes. * chore: Update Blockly dependency to 12.0.0-beta.1. * chore: Clarify comments. * chore: Make guard clauses single-line. * refactor: Improve typings for getViewMetrics(). * fix: Fix missing return. * chore: Add comment clarifying FlyoutButton weirdness. * chore: Improve formatting. * refactor: Use direct field access instead of pass-through setters. * fix: Check for modern mutations when determining block recyclability. * chore: Add comment clarifying flyout positioning checks. * fix: Remove explicit public visibility annotations. * fix: Don't recycle blocks with any mutation-related methods. * chore: Add some information about block recycling to the README. * chore: Improve continuous toolbox README.
1 parent 27d9fc9 commit 1fba9c5

30 files changed

Lines changed: 2181 additions & 1244 deletions

package-lock.json

Lines changed: 140 additions & 220 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@eslint/js": "^8.49.0",
3737
"@typescript-eslint/eslint-plugin": "^6.7.2",
3838
"@typescript-eslint/parser": "^6.7.2",
39-
"blockly": "^11.0.0",
39+
"blockly": "^12.0.0-beta.1",
4040
"conventional-changelog-conventionalcommits": "^5.0.0",
4141
"eslint": "^8.49.0",
4242
"eslint-config-google": "^0.14.0",

plugins/block-shareable-procedures/src/observable_parameter_model.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class ObservableParameterModel
1313
implements Blockly.procedures.IParameterModel
1414
{
1515
private id: string;
16-
private variable: Blockly.VariableModel;
16+
private variable: Blockly.IVariableModel<Blockly.IVariableState>;
1717
private shouldFireEvents = false;
1818
private procedureModel: Blockly.procedures.IProcedureModel | null = null;
1919

@@ -44,8 +44,8 @@ export class ObservableParameterModel
4444
* @returns This parameter model.
4545
*/
4646
setName(name: string, id?: string): this {
47-
if (name === this.variable.name) return this;
48-
const oldName = this.variable.name;
47+
if (name === this.variable.getName()) return this;
48+
const oldName = this.variable.getName();
4949
this.variable =
5050
this.workspace.getVariable(name) ??
5151
this.workspace.createVariable(name, '', id);
@@ -73,7 +73,7 @@ export class ObservableParameterModel
7373
protected createBackingVariable(
7474
name: string,
7575
varId?: string,
76-
): Blockly.VariableModel {
76+
): Blockly.IVariableModel<Blockly.IVariableState> {
7777
this.variable =
7878
this.workspace.getVariable(name) ??
7979
this.workspace.createVariable(name, '', varId);
@@ -100,7 +100,7 @@ export class ObservableParameterModel
100100
* @returns the name of this parameter.
101101
*/
102102
getName(): string {
103-
return this.variable.name;
103+
return this.variable.getName();
104104
}
105105

106106
/**
@@ -123,7 +123,7 @@ export class ObservableParameterModel
123123
/**
124124
* @returns the variable model associated with the parameter model.
125125
*/
126-
getVariableModel(): Blockly.VariableModel {
126+
getVariableModel(): Blockly.IVariableModel<Blockly.IVariableState> {
127127
return this.variable;
128128
}
129129

plugins/block-shareable-procedures/test/procedure_blocks.mocha.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,7 @@ suite('Procedures', function () {
12371237
'if a procedure caller block was already disabled before ' +
12381238
'its definition was disabled, it is not reenabled',
12391239
function () {
1240+
this.workspace.options.disable = true;
12401241
const defBlock = createProcDefBlock(this.workspace);
12411242
const callBlock = createProcCallBlock(this.workspace);
12421243
globalThis.clock.runAll();

plugins/content-highlight/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as Blockly from 'blockly/core';
1313
/**
1414
* List of events that cause a change in content area size.
1515
*/
16-
const contentChangeEvents = [
16+
const contentChangeEvents: string[] = [
1717
Blockly.Events.VIEWPORT_CHANGE,
1818
Blockly.Events.BLOCK_MOVE,
1919
Blockly.Events.BLOCK_DELETE,

plugins/continuous-toolbox/README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,50 @@ npm install @blockly/continuous-toolbox --save
2121

2222
## Usage
2323

24-
Include the toolbox, flyout, and metrics manager classes from the plugin in the options struct used when injecting Blockly. This style of flyout works best with a toolbox definition that does not use collapsible categories.
24+
Import and call the `registerContinuousToolbox()` function before injecting
25+
Blockly. This style of flyout works best with a toolbox definition that does
26+
not use collapsible categories.
2527

26-
Note that this plugin uses APIs introduced in the `3.20200924.3` release of Blockly, so you will need to use at least this version or higher.
28+
Note that this plugin uses APIs introduced in the `v12` release of Blockly, so
29+
you will need to use at least this version or higher.
2730

2831
```js
2932
import * as Blockly from 'blockly';
30-
import {
31-
ContinuousToolbox,
32-
ContinuousFlyout,
33-
ContinuousMetrics,
34-
} from '@blockly/continuous-toolbox';
33+
import {registerContinuousToolbox} from '@blockly/continuous-toolbox';
3534

3635
// Inject Blockly.
36+
registerContinuousToolbox();
3737
const workspace = Blockly.inject('blocklyDiv', {
38+
toolbox: toolboxCategories,
3839
plugins: {
39-
toolbox: ContinuousToolbox,
40-
flyoutsVerticalToolbox: ContinuousFlyout,
41-
metricsManager: ContinuousMetrics,
40+
flyoutsVerticalToolbox: 'ContinuousFlyout',
41+
metricsManager: 'ContinuousMetrics',
42+
toolbox: 'ContinuousToolbox',
4243
},
43-
toolbox: toolboxCategories,
4444
// ... your other options here ...
4545
});
4646
```
4747

48+
## Block Recycling
49+
50+
As a performance optimization, by default the continuous toolbox "recycles"
51+
blocks to avoid having to create DOM elements for potentially hundreds of blocks
52+
every time the flyout is shown. With the default set of blocks, this drops the
53+
time to show the flyout from roughly 35ms to 25ms; the effect is naturally
54+
larger with larger block sets.
55+
56+
Recycling is unrelated to Blockly's Trash feature; instead, it entails moving
57+
the blocks offscreen when the flyout is hidden, and then simply repositioning
58+
them when the flyout is shown again. Not all block types are amenable to this;
59+
in particular, blocks with dynamic behavior (e.g. those that reference
60+
variables, support mutations, or have dynamic dropdown fields) are excluded by
61+
default.
62+
63+
This feature can be toggled by calling `setRecyclingEnabled()` on an instance of
64+
`ContinuousFlyout`, and the default ruleset for determining which blocks are
65+
safe for recycling can be replaced with a custom callback by passing that
66+
function to `setBlockIsRecyclable()`.
67+
4868
## License
4969

5070
Apache 2.0

0 commit comments

Comments
 (0)