Files
blockly/core/events/events_block_drag.ts
Aaron Dodson 83a3e74ec9 fix: Made workspace non-nullable. (#6300)
* Made workspace non-nullable.

* chore: clang-format files.

* fix: Fixed incorrect block disposal check in connection.ts
2022-08-02 13:36:15 -07:00

83 lines
2.0 KiB
TypeScript

/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Events fired as a block drag.
*/
/**
* Events fired as a block drag.
* @class
*/
import * as goog from '../../closure/goog/goog.js';
goog.declareModuleId('Blockly.Events.BlockDrag');
import type {Block} from '../block.js';
import * as registry from '../registry.js';
import {UiBase} from './events_ui_base.js';
import * as eventUtils from './utils.js';
/**
* Class for a block drag event.
* @alias Blockly.Events.BlockDrag
*/
export class BlockDrag extends UiBase {
blockId: AnyDuringMigration;
isStart?: boolean;
blocks?: Block[];
override type: string;
/**
* @param opt_block The top block in the stack that is being dragged.
* Undefined for a blank event.
* @param opt_isStart Whether this is the start of a block drag.
* Undefined for a blank event.
* @param opt_blocks The blocks affected by this drag. Undefined for a blank
* event.
*/
constructor(opt_block?: Block, opt_isStart?: boolean, opt_blocks?: Block[]) {
const workspaceId = opt_block ? opt_block.workspace.id : undefined;
super(workspaceId);
this.blockId = opt_block ? opt_block.id : null;
/** Whether this is the start of a block drag. */
this.isStart = opt_isStart;
/** The blocks affected by this drag event. */
this.blocks = opt_blocks;
/** Type of this event. */
this.type = eventUtils.BLOCK_DRAG;
}
/**
* Encode the event as JSON.
* @return JSON representation.
*/
override toJson(): AnyDuringMigration {
const json = super.toJson();
json['isStart'] = this.isStart;
json['blockId'] = this.blockId;
json['blocks'] = this.blocks;
return json;
}
/**
* Decode the JSON event.
* @param json JSON representation.
*/
override fromJson(json: AnyDuringMigration) {
super.fromJson(json);
this.isStart = json['isStart'];
this.blockId = json['blockId'];
this.blocks = json['blocks'];
}
}
registry.register(registry.Type.EVENT, eventUtils.BLOCK_DRAG, BlockDrag);