Skip to content
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
6 changes: 2 additions & 4 deletions src/actions/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
getFocusManager,
} from 'blockly';
import * as Constants from '../constants';
import type {BlockSvg, WorkspaceSvg, INavigable} from 'blockly';
import type {BlockSvg, WorkspaceSvg} from 'blockly';
import {Navigation} from '../navigation';
import {getShortActionShortcut} from '../shortcut_formatting';
import * as Blockly from 'blockly';
Expand Down Expand Up @@ -366,9 +366,7 @@ export class Clipboard {
? workspace
: this.copyWorkspace;

const targetNode = FocusableTreeTraverser.findFocusedNode(
pasteWorkspace,
) as unknown as INavigable<any>;
const targetNode = FocusableTreeTraverser.findFocusedNode(pasteWorkspace);
// If we're pasting in the flyout it still targets the workspace. Focus
// first as to ensure correct selection handling.
getFocusManager().focusTree(workspace);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
LineCursor,
} from 'blockly';
import * as Constants from '../constants';
import type {BlockSvg, WorkspaceSvg} from 'blockly';
import type {WorkspaceSvg} from 'blockly';
import {Navigation} from '../navigation';

const KeyCodes = BlocklyUtils.KeyCodes;
Expand Down
4 changes: 2 additions & 2 deletions src/actions/disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
utils as BlocklyUtils,
} from 'blockly';
import * as Constants from '../constants';
import type {WorkspaceSvg, INavigable} from 'blockly';
import type {WorkspaceSvg, IFocusableNode} from 'blockly';
import {Navigation} from '../navigation';

const KeyCodes = BlocklyUtils.KeyCodes;
Expand Down Expand Up @@ -79,7 +79,7 @@ export class DisconnectAction {
if (!cursor) {
return;
}
let curNode: INavigable<any> | null = cursor.getCurNode();
let curNode: IFocusableNode | null = cursor.getCurNode();
let wasVisitingConnection = true;
while (
curNode &&
Expand Down
7 changes: 2 additions & 5 deletions src/actions/enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
FocusableTreeTraverser,
} from 'blockly/core';

import type {Block, INavigable} from 'blockly/core';
import type {Block} from 'blockly/core';

import * as Constants from '../constants';
import type {Navigation} from '../navigation';
Expand Down Expand Up @@ -59,7 +59,6 @@ export class EnterAction {

let flyoutCursor;
let curNode;
let nodeType;

switch (this.navigation.getState(workspace)) {
case Constants.STATE.WORKSPACE:
Expand Down Expand Up @@ -128,9 +127,7 @@ export class EnterAction {
Events.setGroup(true);
}

const stationaryNode = FocusableTreeTraverser.findFocusedNode(
workspace,
) as unknown as INavigable<any>;
const stationaryNode = FocusableTreeTraverser.findFocusedNode(workspace);
const newBlock = this.createNewBlock(workspace);
if (!newBlock) return;
const insertStartPoint = stationaryNode
Expand Down
24 changes: 3 additions & 21 deletions src/flyout_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class FlyoutCursor extends Blockly.LineCursor {
* @returns The next element, or null if the current node is
* not set or there is no next value.
*/
override next(): Blockly.INavigable<any> | null {
override next(): Blockly.IFocusableNode | null {
const curNode = this.getCurNode();
if (!curNode) {
return null;
Expand All @@ -46,22 +46,13 @@ export class FlyoutCursor extends Blockly.LineCursor {
return newNode;
}

/**
* This is a no-op since a flyout cursor can not go in.
*
* @returns Always null.
*/
override in(): null {
return null;
}

/**
* Moves the cursor to the previous stack of blocks in the flyout.
*
* @returns The previous element, or null if the current
* node is not set or there is no previous value.
*/
override prev(): Blockly.INavigable<any> | null {
override prev(): Blockly.IFocusableNode | null {
const curNode = this.getCurNode();
if (!curNode) {
return null;
Expand All @@ -74,16 +65,7 @@ export class FlyoutCursor extends Blockly.LineCursor {
return newNode;
}

/**
* This is a no-op since a flyout cursor can not go out.
*
* @returns Always null.
*/
override out(): null {
return null;
}

override setCurNode(node: Blockly.INavigable<any> | null) {
override setCurNode(node: Blockly.IFocusableNode | null) {
super.setCurNode(node);

let bounds: Blockly.utils.Rect | undefined;
Expand Down
24 changes: 3 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ import * as Blockly from 'blockly/core';
import {NavigationController} from './navigation_controller';
import {enableBlocksOnDrag} from './disabled_blocks';

/** Options object for KeyboardNavigation instances. */
export interface NavigationOptions {
cursor: Partial<Blockly.CursorOptions>;
}

/** Default options for LineCursor instances. */
const defaultOptions: NavigationOptions = {
cursor: {},
};

/** Plugin for keyboard navigation. */
export class KeyboardNavigation {
/** The workspace. */
Expand All @@ -38,19 +28,11 @@ export class KeyboardNavigation {
/**
* Constructs the keyboard navigation.
*
* @param workspace The workspace that the plugin will
* be added to.
* @param options Options.
* @param workspace The workspace that the plugin will be added to.
*/
constructor(
workspace: Blockly.WorkspaceSvg,
options: Partial<NavigationOptions>,
) {
constructor(workspace: Blockly.WorkspaceSvg) {
this.workspace = workspace;

// Regularise options and apply defaults.
options = {...defaultOptions, ...options};

this.navigationController = new NavigationController();
this.navigationController.init();
this.navigationController.addWorkspace(workspace);
Expand All @@ -59,7 +41,7 @@ export class KeyboardNavigation {
this.originalTheme = workspace.getTheme();
this.setGlowTheme();

this.cursor = new Blockly.LineCursor(workspace, options.cursor);
this.cursor = new Blockly.LineCursor(workspace);

// Add the event listener to enable disabled blocks on drag.
workspace.addChangeListener(enableBlocksOnDrag);
Expand Down
1 change: 0 additions & 1 deletion src/keyboard_drag_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
RenderedConnection,
dragging,
utils,
INavigable,
} from 'blockly';
import {Direction, getDirectionFromXY} from './drag_direction';
import {showUnconstrainedMoveHint} from './hints';
Expand Down
17 changes: 7 additions & 10 deletions src/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import {
registrationName as cursorRegistrationName,
registrationType as cursorRegistrationType,
FlyoutCursor,
} from './flyout_cursor';

/**
Expand All @@ -31,7 +30,7 @@
* after a block has been deleted. In pixel coordinates, but will be
* converted to workspace coordinates when used to position the cursor.
*/
const WS_COORDINATE_ON_DELETE: Blockly.utils.Coordinate =

Check warning on line 33 in src/navigation.ts

View workflow job for this annotation

GitHub Actions / Eslint check

'WS_COORDINATE_ON_DELETE' is assigned a value but never used
new Blockly.utils.Coordinate(100, 100);

/**
Expand Down Expand Up @@ -151,7 +150,7 @@
if (FlyoutCursorClass) {
flyoutWorkspace
.getMarkerManager()
.setCursor(new Blockly.LineCursor(flyout.getWorkspace()));
.setCursor(new FlyoutCursorClass(flyout));
}
}

Expand Down Expand Up @@ -258,7 +257,7 @@
}

private isFlyoutItemDisposed(
node: Blockly.INavigable<any>,
node: Blockly.IFocusableNode,
sourceBlock: Blockly.BlockSvg | null,
) {
if (sourceBlock?.disposed) {
Expand Down Expand Up @@ -368,9 +367,7 @@
: flyoutContents[flyoutContents.length - 1];
if (!defaultFlyoutItem) return false;
const defaultFlyoutItemElement = defaultFlyoutItem.getElement();
flyoutCursor.setCurNode(
defaultFlyoutItemElement as unknown as Blockly.INavigable<any>,
);
flyoutCursor.setCurNode(defaultFlyoutItemElement);
return true;
}

Expand Down Expand Up @@ -400,7 +397,7 @@
// disposed (which can happen when blocks are reloaded).
return false;
}
const wsCoordinates = new Blockly.utils.Coordinate(

Check warning on line 400 in src/navigation.ts

View workflow job for this annotation

GitHub Actions / Eslint check

'wsCoordinates' is assigned a value but never used
DEFAULT_WS_COORDINATE.x / workspace.scale,
DEFAULT_WS_COORDINATE.y / workspace.scale,
);
Expand All @@ -420,11 +417,11 @@
* @param workspace The main workspace the flyout is on.
* @returns The flyout's cursor or null if no flyout exists.
*/
getFlyoutCursor(workspace: Blockly.WorkspaceSvg): FlyoutCursor | null {
getFlyoutCursor(workspace: Blockly.WorkspaceSvg): Blockly.LineCursor | null {
const flyout = workspace.getFlyout();
const cursor = flyout ? flyout.getWorkspace().getCursor() : null;

return cursor as FlyoutCursor;
return cursor;
}

/**
Expand All @@ -437,7 +434,7 @@
* wrong.
*/
findInsertStartPoint(
stationaryNode: Blockly.INavigable<any>,
stationaryNode: Blockly.IFocusableNode,
movingBlock: Blockly.BlockSvg,
): Blockly.RenderedConnection | null {
const movingHasOutput = !!movingBlock.outputConnection;
Expand Down Expand Up @@ -517,7 +514,7 @@
* @returns True if the connection was successful, false otherwise.
*/
tryToConnectBlock(
stationaryNode: Blockly.INavigable<any>,
stationaryNode: Blockly.IFocusableNode,
movingBlock: Blockly.BlockSvg,
): boolean {
const destConnection = this.findInsertStartPoint(
Expand Down
8 changes: 0 additions & 8 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,6 @@
<option value="zelos">Zelos</option>
</select>
</div>
<div>
<label for="stackConnections">Disable stack connections:</label>
<input
type="checkbox"
name="noStack"
id="noStack"
onChange="document.forms.options.submit()" />
</div>
</form>
</div>
</div>
Expand Down
13 changes: 2 additions & 11 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import {load} from './loadTestBlocks';
import {runCode, registerRunCodeShortcut} from './runCode';

(window as any).Blockly = Blockly;

Check warning on line 26 in test/index.ts

View workflow job for this annotation

GitHub Actions / Eslint check

Unexpected any. Specify a different type

/**
* Parse query params for inject and navigation options and update
Expand All @@ -49,9 +49,6 @@
renderer = 'thrasos';
}

const noStackParam = params.get('noStack');
const stackConnections = !noStackParam;

const toolboxParam = params.get('toolbox');
const toolbox = toolboxParam ?? 'toolbox';
const toolboxObject =
Expand All @@ -66,13 +63,10 @@
(document.getElementById('toolbox') as HTMLSelectElement).value = toolbox;
(document.getElementById('renderer') as HTMLSelectElement).value = renderer;
(document.getElementById('scenario') as HTMLSelectElement).value = scenario;
(document.getElementById('noStack') as HTMLInputElement).checked =
!stackConnections;
});

return {
scenario,
stackConnections,
renderer,
toolbox: toolboxObject,
};
Expand All @@ -85,7 +79,7 @@
* @returns The created workspace.
*/
function createWorkspace(): Blockly.WorkspaceSvg {
const {scenario, stackConnections, renderer, toolbox} = getOptions();
const {scenario, renderer, toolbox} = getOptions();

const injectOptions = {
toolbox,
Expand All @@ -97,10 +91,7 @@
}
const workspace = Blockly.inject(blocklyDiv, injectOptions);

const navigationOptions = {
cursor: {stackConnections},
};
new KeyboardNavigation(workspace, navigationOptions);
new KeyboardNavigation(workspace);
registerRunCodeShortcut();

// Disable blocks that aren't inside the setup or draw loops.
Expand Down
11 changes: 2 additions & 9 deletions test/webdriverio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ function getOptions() {
renderer = 'thrasos';
}

const noStackParam = params.get('noStack');
const stackConnections = !noStackParam;

const toolboxParam = params.get('toolbox');
const toolbox = toolboxParam ?? 'toolbox';
const toolboxObject =
Expand All @@ -57,7 +54,6 @@ function getOptions() {

return {
scenario,
stackConnections,
renderer,
toolbox: toolboxObject,
rtl,
Expand All @@ -71,7 +67,7 @@ function getOptions() {
* @returns The created workspace.
*/
function createWorkspace(): Blockly.WorkspaceSvg {
const {scenario, stackConnections, renderer, toolbox, rtl} = getOptions();
const {scenario, renderer, toolbox, rtl} = getOptions();

const injectOptions = {
toolbox,
Expand All @@ -84,10 +80,7 @@ function createWorkspace(): Blockly.WorkspaceSvg {
}
const workspace = Blockly.inject(blocklyDiv, injectOptions);

const navigationOptions = {
cursor: {stackConnections},
};
new KeyboardNavigation(workspace, navigationOptions);
new KeyboardNavigation(workspace);

// Disable blocks that aren't inside the setup or draw loops.
workspace.addChangeListener(Blockly.Events.disableOrphans);
Expand Down
Loading
Loading