mirror of
https://github.com/google/blockly.git
synced 2026-01-09 01:50:11 +01:00
* 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
85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2018 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview Class for comment creation event.
|
|
*/
|
|
'use strict';
|
|
|
|
/**
|
|
* Class for comment creation event.
|
|
* @class
|
|
*/
|
|
goog.module('Blockly.Events.CommentCreate');
|
|
|
|
const Xml = goog.require('Blockly.Xml');
|
|
const eventUtils = goog.require('Blockly.Events.utils');
|
|
const registry = goog.require('Blockly.registry');
|
|
const {CommentBase} = goog.require('Blockly.Events.CommentBase');
|
|
/* eslint-disable-next-line no-unused-vars */
|
|
const {WorkspaceComment} = goog.requireType('Blockly.WorkspaceComment');
|
|
|
|
|
|
/**
|
|
* Class for a comment creation event.
|
|
* @extends {CommentBase}
|
|
*/
|
|
class CommentCreate extends CommentBase {
|
|
/**
|
|
* @param {!WorkspaceComment=} opt_comment The created comment.
|
|
* Undefined for a blank event.
|
|
* @alias Blockly.Events.CommentCreate
|
|
*/
|
|
constructor(opt_comment) {
|
|
super(opt_comment);
|
|
|
|
/**
|
|
* Type of this event.
|
|
* @type {string}
|
|
*/
|
|
this.type = eventUtils.COMMENT_CREATE;
|
|
|
|
if (!opt_comment) {
|
|
return; // Blank event to be populated by fromJson.
|
|
}
|
|
|
|
this.xml = opt_comment.toXmlWithXY();
|
|
}
|
|
|
|
// TODO (#1266): "Full" and "minimal" serialization.
|
|
/**
|
|
* Encode the event as JSON.
|
|
* @return {!Object} JSON representation.
|
|
*/
|
|
toJson() {
|
|
const json = super.toJson();
|
|
json['xml'] = Xml.domToText(this.xml);
|
|
return json;
|
|
}
|
|
|
|
/**
|
|
* Decode the JSON event.
|
|
* @param {!Object} json JSON representation.
|
|
*/
|
|
fromJson(json) {
|
|
super.fromJson(json);
|
|
this.xml = Xml.textToDom(json['xml']);
|
|
}
|
|
|
|
/**
|
|
* Run a creation event.
|
|
* @param {boolean} forward True if run forward, false if run backward (undo).
|
|
*/
|
|
run(forward) {
|
|
CommentBase.CommentCreateDeleteHelper(this, forward);
|
|
}
|
|
}
|
|
|
|
registry.register(
|
|
registry.Type.EVENT, eventUtils.COMMENT_CREATE, CommentCreate);
|
|
|
|
exports.CommentCreate = CommentCreate;
|