mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
fix!: delete marker move event and tests (#9013)
This commit is contained in:
@@ -33,7 +33,6 @@ export {CommentDelete} from './events_comment_delete.js';
|
||||
export {CommentDrag, CommentDragJson} from './events_comment_drag.js';
|
||||
export {CommentMove, CommentMoveJson} from './events_comment_move.js';
|
||||
export {CommentResize, CommentResizeJson} from './events_comment_resize.js';
|
||||
export {MarkerMove, MarkerMoveJson} from './events_marker_move.js';
|
||||
export {Selected, SelectedJson} from './events_selected.js';
|
||||
export {ThemeChange, ThemeChangeJson} from './events_theme_change.js';
|
||||
export {
|
||||
@@ -77,7 +76,6 @@ export const CREATE = EventType.BLOCK_CREATE;
|
||||
/** @deprecated Use BLOCK_DELETE instead */
|
||||
export const DELETE = EventType.BLOCK_DELETE;
|
||||
export const FINISHED_LOADING = EventType.FINISHED_LOADING;
|
||||
export const MARKER_MOVE = EventType.MARKER_MOVE;
|
||||
/** @deprecated Use BLOCK_MOVE instead */
|
||||
export const MOVE = EventType.BLOCK_MOVE;
|
||||
export const SELECTED = EventType.SELECTED;
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Events fired as a result of a marker move.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
// Former goog.module ID: Blockly.Events.MarkerMove
|
||||
|
||||
import type {Block} from '../block.js';
|
||||
import {ASTNode} from '../keyboard_nav/ast_node.js';
|
||||
import * as registry from '../registry.js';
|
||||
import type {Workspace} from '../workspace.js';
|
||||
import {AbstractEventJson} from './events_abstract.js';
|
||||
import {UiBase} from './events_ui_base.js';
|
||||
import {EventType} from './type.js';
|
||||
|
||||
/**
|
||||
* Notifies listeners that a marker (used for keyboard navigation) has
|
||||
* moved.
|
||||
*/
|
||||
export class MarkerMove extends UiBase {
|
||||
/** The ID of the block the marker is now on, if any. */
|
||||
blockId?: string;
|
||||
|
||||
/** The old node the marker used to be on, if any. */
|
||||
oldNode?: ASTNode;
|
||||
|
||||
/** The new node the marker is now on. */
|
||||
newNode?: ASTNode;
|
||||
|
||||
/**
|
||||
* True if this is a cursor event, false otherwise.
|
||||
* For information about cursors vs markers see {@link
|
||||
* https://blocklycodelabs.dev/codelabs/keyboard-navigation/index.html?index=..%2F..index#1}.
|
||||
*/
|
||||
isCursor?: boolean;
|
||||
|
||||
override type = EventType.MARKER_MOVE;
|
||||
|
||||
/**
|
||||
* @param opt_block The affected block. Null if current node is of type
|
||||
* workspace. Undefined for a blank event.
|
||||
* @param isCursor Whether this is a cursor event. Undefined for a blank
|
||||
* event.
|
||||
* @param opt_oldNode The old node the marker used to be on.
|
||||
* Undefined for a blank event.
|
||||
* @param opt_newNode The new node the marker is now on.
|
||||
* Undefined for a blank event.
|
||||
*/
|
||||
constructor(
|
||||
opt_block?: Block | null,
|
||||
isCursor?: boolean,
|
||||
opt_oldNode?: ASTNode | null,
|
||||
opt_newNode?: ASTNode,
|
||||
) {
|
||||
let workspaceId = opt_block ? opt_block.workspace.id : undefined;
|
||||
if (opt_newNode && opt_newNode.getType() === ASTNode.types.WORKSPACE) {
|
||||
workspaceId = (opt_newNode.getLocation() as Workspace).id;
|
||||
}
|
||||
super(workspaceId);
|
||||
|
||||
this.blockId = opt_block?.id;
|
||||
this.oldNode = opt_oldNode || undefined;
|
||||
this.newNode = opt_newNode;
|
||||
this.isCursor = isCursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the event as JSON.
|
||||
*
|
||||
* @returns JSON representation.
|
||||
*/
|
||||
override toJson(): MarkerMoveJson {
|
||||
const json = super.toJson() as MarkerMoveJson;
|
||||
if (this.isCursor === undefined) {
|
||||
throw new Error(
|
||||
'Whether this is a cursor event or not is undefined. Either pass ' +
|
||||
'a value to the constructor, or call fromJson',
|
||||
);
|
||||
}
|
||||
if (!this.newNode) {
|
||||
throw new Error(
|
||||
'The new node is undefined. Either pass a node to ' +
|
||||
'the constructor, or call fromJson',
|
||||
);
|
||||
}
|
||||
json['isCursor'] = this.isCursor;
|
||||
json['blockId'] = this.blockId;
|
||||
json['oldNode'] = this.oldNode;
|
||||
json['newNode'] = this.newNode;
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the JSON event.
|
||||
*
|
||||
* @param event The event to append new properties to. Should be a subclass
|
||||
* of MarkerMove, but we can't specify that due to the fact that
|
||||
* parameters to static methods in subclasses must be supertypes of
|
||||
* parameters to static methods in superclasses.
|
||||
* @internal
|
||||
*/
|
||||
static fromJson(
|
||||
json: MarkerMoveJson,
|
||||
workspace: Workspace,
|
||||
event?: any,
|
||||
): MarkerMove {
|
||||
const newEvent = super.fromJson(
|
||||
json,
|
||||
workspace,
|
||||
event ?? new MarkerMove(),
|
||||
) as MarkerMove;
|
||||
newEvent.isCursor = json['isCursor'];
|
||||
newEvent.blockId = json['blockId'];
|
||||
newEvent.oldNode = json['oldNode'];
|
||||
newEvent.newNode = json['newNode'];
|
||||
return newEvent;
|
||||
}
|
||||
}
|
||||
|
||||
export interface MarkerMoveJson extends AbstractEventJson {
|
||||
isCursor: boolean;
|
||||
blockId?: string;
|
||||
oldNode?: ASTNode;
|
||||
newNode: ASTNode;
|
||||
}
|
||||
|
||||
registry.register(registry.Type.EVENT, EventType.MARKER_MOVE, MarkerMove);
|
||||
@@ -29,7 +29,6 @@ import type {CommentDelete} from './events_comment_delete.js';
|
||||
import type {CommentDrag} from './events_comment_drag.js';
|
||||
import type {CommentMove} from './events_comment_move.js';
|
||||
import type {CommentResize} from './events_comment_resize.js';
|
||||
import type {MarkerMove} from './events_marker_move.js';
|
||||
import type {Selected} from './events_selected.js';
|
||||
import type {ThemeChange} from './events_theme_change.js';
|
||||
import type {ToolboxItemSelect} from './events_toolbox_item_select.js';
|
||||
@@ -99,11 +98,6 @@ export function isClick(event: Abstract): event is Click {
|
||||
return event.type === EventType.CLICK;
|
||||
}
|
||||
|
||||
/** @returns true iff event.type is EventType.MARKER_MOVE */
|
||||
export function isMarkerMove(event: Abstract): event is MarkerMove {
|
||||
return event.type === EventType.MARKER_MOVE;
|
||||
}
|
||||
|
||||
/** @returns true iff event.type is EventType.BUBBLE_OPEN */
|
||||
export function isBubbleOpen(event: Abstract): event is BubbleOpen {
|
||||
return event.type === EventType.BUBBLE_OPEN;
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2022 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {defineRowBlock} from './test_helpers/block_definitions.js';
|
||||
import {
|
||||
sharedTestSetup,
|
||||
sharedTestTeardown,
|
||||
} from './test_helpers/setup_teardown.js';
|
||||
|
||||
suite('Marker Move Event', function () {
|
||||
setup(function () {
|
||||
sharedTestSetup.call(this);
|
||||
defineRowBlock();
|
||||
this.workspace = new Blockly.Workspace();
|
||||
});
|
||||
|
||||
teardown(function () {
|
||||
sharedTestTeardown.call(this);
|
||||
});
|
||||
|
||||
suite('Serialization', function () {
|
||||
test('events round-trip through JSON', function () {
|
||||
const block1 = this.workspace.newBlock('row_block', 'test_id1');
|
||||
const block2 = this.workspace.newBlock('row_block', 'test_id2');
|
||||
const node1 = new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, block1);
|
||||
const node2 = new Blockly.ASTNode(Blockly.ASTNode.types.BLOCK, block2);
|
||||
const origEvent = new Blockly.Events.MarkerMove(
|
||||
block2,
|
||||
false,
|
||||
node1,
|
||||
node2,
|
||||
);
|
||||
|
||||
const json = origEvent.toJson();
|
||||
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
|
||||
|
||||
assert.deepEqual(newEvent, origEvent);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
import * as Blockly from '../../build/src/core/blockly.js';
|
||||
import * as eventUtils from '../../build/src/core/events/utils.js';
|
||||
import {ASTNode} from '../../build/src/core/keyboard_nav/ast_node.js';
|
||||
import {assert} from '../../node_modules/chai/chai.js';
|
||||
import {
|
||||
assertEventEquals,
|
||||
@@ -519,85 +518,6 @@ suite('Events', function () {
|
||||
newValue: 'new value',
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: 'null to Block Marker move',
|
||||
class: Blockly.Events.MarkerMove,
|
||||
getArgs: (thisObj) => [
|
||||
thisObj.block,
|
||||
true,
|
||||
null,
|
||||
new ASTNode(ASTNode.types.BLOCK, thisObj.block),
|
||||
],
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'marker_move',
|
||||
group: '',
|
||||
isCursor: true,
|
||||
blockId: thisObj.block.id,
|
||||
oldNode: undefined,
|
||||
newNode: new ASTNode(ASTNode.types.BLOCK, thisObj.block),
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: 'null to Workspace Marker move',
|
||||
class: Blockly.Events.MarkerMove,
|
||||
getArgs: (thisObj) => [
|
||||
null,
|
||||
true,
|
||||
null,
|
||||
ASTNode.createWorkspaceNode(
|
||||
thisObj.workspace,
|
||||
new Blockly.utils.Coordinate(0, 0),
|
||||
),
|
||||
],
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'marker_move',
|
||||
group: '',
|
||||
isCursor: true,
|
||||
blockId: undefined,
|
||||
oldNode: undefined,
|
||||
newNode: ASTNode.createWorkspaceNode(
|
||||
thisObj.workspace,
|
||||
new Blockly.utils.Coordinate(0, 0),
|
||||
),
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: 'Workspace to Block Marker move',
|
||||
class: Blockly.Events.MarkerMove,
|
||||
getArgs: (thisObj) => [
|
||||
thisObj.block,
|
||||
true,
|
||||
ASTNode.createWorkspaceNode(
|
||||
thisObj.workspace,
|
||||
new Blockly.utils.Coordinate(0, 0),
|
||||
),
|
||||
new ASTNode(ASTNode.types.BLOCK, thisObj.block),
|
||||
],
|
||||
getExpectedJson: (thisObj) => ({
|
||||
type: 'marker_move',
|
||||
group: '',
|
||||
isCursor: true,
|
||||
blockId: thisObj.block.id,
|
||||
oldNode: ASTNode.createWorkspaceNode(
|
||||
thisObj.workspace,
|
||||
new Blockly.utils.Coordinate(0, 0),
|
||||
),
|
||||
newNode: new ASTNode(ASTNode.types.BLOCK, thisObj.block),
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: 'Block to Workspace Marker move',
|
||||
class: Blockly.Events.MarkerMove,
|
||||
getArgs: (thisObj) => [
|
||||
null,
|
||||
true,
|
||||
new ASTNode(ASTNode.types.BLOCK, thisObj.block),
|
||||
ASTNode.createWorkspaceNode(
|
||||
thisObj.workspace,
|
||||
new Blockly.utils.Coordinate(0, 0),
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Selected',
|
||||
class: Blockly.Events.Selected,
|
||||
|
||||
@@ -209,7 +209,6 @@
|
||||
import './event_comment_move_test.js';
|
||||
import './event_comment_drag_test.js';
|
||||
import './event_comment_resize_test.js';
|
||||
import './event_marker_move_test.js';
|
||||
import './event_selected_test.js';
|
||||
import './event_theme_change_test.js';
|
||||
import './event_toolbox_item_select_test.js';
|
||||
|
||||
Reference in New Issue
Block a user