Skip to content

Commit c770cc8

Browse files
authored
refactor: Update to v12.0.0-beta.3 and use cursor from core. (#405)
* chore: Update dependency to Blockly v12 beta 3. * refactor: Use the built-in cursor in core. * chore: Fix imports.
1 parent e3897e0 commit c770cc8

File tree

12 files changed

+30
-812
lines changed

12 files changed

+30
-812
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@types/p5": "^1.7.6",
5656
"@typescript-eslint/eslint-plugin": "^6.7.2",
5757
"@typescript-eslint/parser": "^6.7.2",
58-
"blockly": "12.0.0-beta.2",
58+
"blockly": "12.0.0-beta.3",
5959
"chai": "^5.2.0",
6060
"eslint": "^8.49.0",
6161
"eslint-config-google": "^0.14.0",
@@ -71,11 +71,11 @@
7171
"webdriverio": "^9.12.1"
7272
},
7373
"peerDependencies": {
74-
"blockly": "^12.0.0-beta.2"
74+
"blockly": "^12.0.0-beta.3"
7575
},
7676
"overrides": {
7777
"@blockly/field-colour": {
78-
"blockly": "^12.0.0-beta.2"
78+
"blockly": "^12.0.0-beta.3"
7979
}
8080
},
8181
"publishConfig": {

src/actions/clipboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
utils as blocklyUtils,
1313
clipboard,
1414
ICopyData,
15+
LineCursor,
1516
} from 'blockly';
1617
import * as Constants from '../constants';
1718
import type {BlockSvg, WorkspaceSvg} from 'blockly';
18-
import {LineCursor} from '../line_cursor';
1919
import {Navigation} from '../navigation';
2020
import {ScopeWithConnection} from './action_menu';
2121

src/actions/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {
99
Gesture,
1010
ShortcutRegistry,
1111
utils as BlocklyUtils,
12+
LineCursor,
1213
} from 'blockly';
1314
import * as Constants from '../constants';
1415
import type {BlockSvg, WorkspaceSvg} from 'blockly';
15-
import {LineCursor} from '../line_cursor';
1616
import {Navigation} from '../navigation';
1717

1818
const KeyCodes = BlocklyUtils.KeyCodes;

src/actions/edit.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {ContextMenuRegistry} from 'blockly';
8-
import {LineCursor} from '../line_cursor';
7+
import {ContextMenuRegistry, LineCursor} from 'blockly';
98
import {Navigation} from 'src/navigation';
109

1110
/**

src/actions/enter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ export class EnterAction {
271271
if (block.isSimpleReporter()) {
272272
for (const input of block.inputList) {
273273
for (const field of input.fieldRow) {
274-
// @ts-expect-error isFullBlockField is a protected method.
275274
if (field.isClickable() && field.isFullBlockField()) {
276275
field.showEditor();
277276
return true;

src/actions/ws_movement.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ export class WorkspaceMovement {
109109
if (!curNode || curNode.getType() !== ASTNode.types.WORKSPACE) return false;
110110

111111
const wsCoord = curNode.getWsCoordinate();
112+
if (!wsCoord) return false;
113+
112114
const newX = xDirection * WS_MOVE_DISTANCE + wsCoord.x;
113115
const newY = yDirection * WS_MOVE_DISTANCE + wsCoord.y;
114116

src/flyout_cursor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import {scrollBoundsIntoView} from './workspace_utilities';
1717
* This controls how a user navigates blocks in the flyout.
1818
* This cursor only allows a user to go to the previous or next stack.
1919
*/
20-
export class FlyoutCursor extends Blockly.Cursor {
20+
export class FlyoutCursor extends Blockly.LineCursor {
2121
/**
2222
* The constructor for the FlyoutCursor.
2323
*
2424
* @param flyout The flyout this cursor is for.
2525
*/
2626
constructor(private readonly flyout: Blockly.IFlyout) {
27-
super();
27+
super(flyout.getWorkspace());
2828
}
2929

3030
/**

src/index.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
import * as Blockly from 'blockly/core';
88
import {NavigationController} from './navigation_controller';
9-
import {CursorOptions, LineCursor} from './line_cursor';
109
import {getFlyoutElement, getToolboxElement} from './workspace_utilities';
1110

1211
/** Options object for KeyboardNavigation instances. */
1312
export interface NavigationOptions {
14-
cursor: Partial<CursorOptions>;
13+
cursor: Partial<Blockly.CursorOptions>;
1514
}
1615

1716
/** Default options for LineCursor instances. */
@@ -49,7 +48,7 @@ export class KeyboardNavigation {
4948
private navigationController: NavigationController;
5049

5150
/** Cursor for the main workspace. */
52-
private cursor: LineCursor;
51+
private cursor: Blockly.LineCursor;
5352

5453
/**
5554
* These fields are used to preserve the workspace's initial state to restore
@@ -92,8 +91,7 @@ export class KeyboardNavigation {
9291
this.originalTheme = workspace.getTheme();
9392
this.setGlowTheme();
9493

95-
this.cursor = new LineCursor(workspace, options.cursor);
96-
this.cursor.install();
94+
this.cursor = new Blockly.LineCursor(workspace, options.cursor);
9795

9896
// Ensure that only the root SVG G (group) has a tab index.
9997
this.injectionDivTabIndex = workspace
@@ -276,8 +274,6 @@ export class KeyboardNavigation {
276274
this.workspace.getInjectionDiv().removeAttribute('tabindex');
277275
}
278276

279-
this.cursor.uninstall();
280-
281277
this.workspace.setTheme(this.originalTheme);
282278

283279
this.navigationController.dispose();

src/keyboard_drag_strategy.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {ASTNode, BlockSvg, RenderedConnection, dragging, utils} from 'blockly';
7+
import {
8+
ASTNode,
9+
BlockSvg,
10+
RenderedConnection,
11+
LineCursor,
12+
dragging,
13+
utils,
14+
} from 'blockly';
815
import {Direction, getDirectionFromXY} from './drag_direction';
9-
import {LineCursor} from './line_cursor';
1016

1117
// Copied in from core because it is not exported.
1218
interface ConnectionCandidate {

0 commit comments

Comments
 (0)