Files
blockly/core/events/events_click.js
Rachel Fenichel 29fb7b7893 refactor: convert leaf event classes to es6 classes (#5870)
* chore(tests): update event assert functions to pass in types directly

* refactor: move event types from prototypes to constructors

* refactor: convert events/events_block_change.js to ES6 class

* refactor: convert events/events_block_create.js to ES6 class

* refactor: convert events/events_block_delete.js to ES6 class

* refactor: convert events/events_block_drag.js to ES6 class

* refactor: convert events/events_block_move.js to ES6 class

* refactor: convert events/events_click.js to ES6 class

* refactor: convert events/events_comment_change.js to ES6 class

* refactor: convert events/events_comment_create.js to ES6 class

* refactor: convert events/events_comment_delete.js to ES6 class

* refactor: convert events/events_comment_move.js to ES6 class

* refactor: convert events/events_marker_move.js to ES6 class

* refactor: convert events/events_selected.js to ES6 class

* refactor: convert events/events_theme_change.js to ES6 class

* refactor: convert events/events_toolbox_item_select.js to ES6 class

* refactor: convert events/events_trashcan_open.js to ES6 class

* refactor: convert events/events_ui.js to ES6 class

* refactor: convert events/events_var_create.js to ES6 class

* refactor: convert events/events_var_delete.js to ES6 class

* refactor: convert events/events_var_rename.js to ES6 class

* refactor: convert events/events_viewport.js to ES6 class

* chore: rebuild

* chore: run clang-format
2022-01-12 09:29:30 -08:00

88 lines
2.2 KiB
JavaScript

/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Events fired as a result of UI click in Blockly's editor.
*/
'use strict';
/**
* Events fired as a result of UI click in Blockly's editor.
* @class
*/
goog.module('Blockly.Events.Click');
const eventUtils = goog.require('Blockly.Events.utils');
const registry = goog.require('Blockly.registry');
/* eslint-disable-next-line no-unused-vars */
const {Block} = goog.requireType('Blockly.Block');
const {UiBase} = goog.require('Blockly.Events.UiBase');
/**
* Class for a click event.
* @extends {UiBase}
*/
class Click extends UiBase {
/**
* @param {?Block=} opt_block The affected block. Null for click events
* that do not have an associated block (i.e. workspace click). Undefined
* for a blank event.
* @param {?string=} opt_workspaceId The workspace identifier for this event.
* Not used if block is passed. Undefined for a blank event.
* @param {string=} opt_targetType The type of element targeted by this click
* event. Undefined for a blank event.
* @alias Blockly.Events.Click
*/
constructor(opt_block, opt_workspaceId, opt_targetType) {
let workspaceId = opt_block ? opt_block.workspace.id : opt_workspaceId;
if (workspaceId === null) {
workspaceId = undefined;
}
super(workspaceId);
this.blockId = opt_block ? opt_block.id : null;
/**
* The type of element targeted by this click event.
* @type {string|undefined}
*/
this.targetType = opt_targetType;
/**
* Type of this event.
* @type {string}
*/
this.type = eventUtils.CLICK;
}
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
toJson() {
const json = super.toJson();
json['targetType'] = this.targetType;
if (this.blockId) {
json['blockId'] = this.blockId;
}
return json;
}
/**
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
fromJson(json) {
super.fromJson(json);
this.targetType = json['targetType'];
this.blockId = json['blockId'];
}
}
registry.register(registry.Type.EVENT, eventUtils.CLICK, Click);
exports.Click = Click;