mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
* chore(deps): Bump prettier from 2.8.8 to 3.0.0 Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0) --- updated-dependencies: - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore: Reformat using Prettier v3.0 defaults The main change is to add trailing commas to the last line of block-formatted function calls. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Christopher Allen <cpcallen+git@google.com>
90 lines
2.0 KiB
TypeScript
90 lines
2.0 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2018 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* Base class for all types of block events.
|
|
*
|
|
* @class
|
|
*/
|
|
import * as goog from '../../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.Events.BlockBase');
|
|
|
|
import type {Block} from '../block.js';
|
|
import type {Workspace} from '../workspace.js';
|
|
|
|
import {
|
|
Abstract as AbstractEvent,
|
|
AbstractEventJson,
|
|
} from './events_abstract.js';
|
|
|
|
/**
|
|
* Abstract class for any event related to blocks.
|
|
*/
|
|
export class BlockBase extends AbstractEvent {
|
|
override isBlank = true;
|
|
|
|
/** The ID of the block associated with this event. */
|
|
blockId?: string;
|
|
|
|
/**
|
|
* @param opt_block The block this event corresponds to.
|
|
* Undefined for a blank event.
|
|
*/
|
|
constructor(opt_block?: Block) {
|
|
super();
|
|
this.isBlank = !opt_block;
|
|
|
|
if (!opt_block) return;
|
|
|
|
this.blockId = opt_block.id;
|
|
this.workspaceId = opt_block.workspace.id;
|
|
}
|
|
|
|
/**
|
|
* Encode the event as JSON.
|
|
*
|
|
* @returns JSON representation.
|
|
*/
|
|
override toJson(): BlockBaseJson {
|
|
const json = super.toJson() as BlockBaseJson;
|
|
if (!this.blockId) {
|
|
throw new Error(
|
|
'The block ID is undefined. Either pass a block to ' +
|
|
'the constructor, or call fromJson',
|
|
);
|
|
}
|
|
json['blockId'] = this.blockId;
|
|
return json;
|
|
}
|
|
|
|
/**
|
|
* Deserializes the JSON event.
|
|
*
|
|
* @param event The event to append new properties to. Should be a subclass
|
|
* of BlockBase, 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: BlockBaseJson,
|
|
workspace: Workspace,
|
|
event?: any,
|
|
): BlockBase {
|
|
const newEvent = super.fromJson(
|
|
json,
|
|
workspace,
|
|
event ?? new BlockBase(),
|
|
) as BlockBase;
|
|
newEvent.blockId = json['blockId'];
|
|
return newEvent;
|
|
}
|
|
}
|
|
|
|
export interface BlockBaseJson extends AbstractEventJson {
|
|
blockId: string;
|
|
}
|