scratch_events.js
5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* @license
* Visual Blocks Editor
*
* Copyright 2018 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Events fired as a result of UI actions in a Scratch-Blocks
* editor that are not fired in Blockly.
* @author fenichel@google.com (Rachel Fenichel)
*/
'use strict';
goog.provide('Blockly.Events.UpdateToolboxFinish');
goog.provide('Blockly.Events.DragBlockOutside');
goog.provide('Blockly.Events.EndBlockDrag');
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockBase');
goog.require('Blockly.Events.Abstract');
goog.require('goog.array');
goog.require('goog.math.Coordinate');
/**
* Class for toolbox update finish event.
* @param {!Object} workspace that finsh update toolbox.
* @extends {Blockly.Events.Abstract}
* @constructor
*/
Blockly.Events.UpdateToolboxFinish = function(workspace) {
Blockly.Events.UpdateToolboxFinish.superClass_.constructor.call(this, workspace);
/**
* Set a fask block id, prevent listener ignore the event.
*/
this.blockId = 'fakeId';
this.workspaceId = workspace.id;
};
goog.inherits(Blockly.Events.UpdateToolboxFinish, Blockly.Events.Abstract);
/**
* Type of this event.
* @type {string}
*/
Blockly.Events.UpdateToolboxFinish.prototype.type = Blockly.Events.UPDATE_TOOLBOX_FINISH;
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.UpdateToolboxFinish.prototype.toJson = function() {
var json = Blockly.Events.UpdateToolboxFinish.superClass_.toJson.call(this);
json['blockId'] = this.blockId;
return json;
};
/**
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
Blockly.Events.UpdateToolboxFinish.prototype.fromJson = function(json) {
Blockly.Events.UpdateToolboxFinish.superClass_.fromJson.call(this, json);
this.blockId = json['blockId'];
};
/**
* Class for a block drag event. Fired when block dragged into or out of
* the blocks UI.
* @param {Blockly.Block} block The moved block. Null for a blank event.
* @extends {Blockly.Events.BlockBase}
* @constructor
*/
Blockly.Events.DragBlockOutside = function(block) {
if (!block) {
return; // Blank event to be populated by fromJson.
}
Blockly.Events.DragBlockOutside.superClass_.constructor.call(this, block);
this.recordUndo = false;
};
goog.inherits(Blockly.Events.DragBlockOutside, Blockly.Events.BlockBase);
/**
* Type of this event.
* @type {string}
*/
Blockly.Events.DragBlockOutside.prototype.type = Blockly.Events.DRAG_OUTSIDE;
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.DragBlockOutside.prototype.toJson = function() {
var json = Blockly.Events.DragBlockOutside.superClass_.toJson.call(this);
if (this.isOutside) {
json['isOutside'] = this.isOutside;
}
return json;
};
/**
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
Blockly.Events.DragBlockOutside.prototype.fromJson = function(json) {
Blockly.Events.DragBlockOutside.superClass_.fromJson.call(this, json);
this.isOutside = json['isOutside'];
};
/**
* Class for a block end drag event.
* @param {Blockly.Block} block The moved block. Null for a blank event.
* @param {boolean} isOutside True if the moved block is outside of the
* blocks workspace.
* @extends {Blockly.Events.BlockBase}
* @constructor
*/
Blockly.Events.EndBlockDrag = function(block, isOutside) {
if (!block) {
return; // Blank event to be populated by fromJson.
}
Blockly.Events.EndBlockDrag.superClass_.constructor.call(this, block);
this.isOutside = isOutside;
// If drag ends outside the blocks workspace, send the block XML
if (isOutside) {
this.xml = Blockly.Xml.blockToDom(block, true /* opt_noId */);
}
this.recordUndo = false;
};
goog.inherits(Blockly.Events.EndBlockDrag, Blockly.Events.BlockBase);
/**
* Type of this event.
* @type {string}
*/
Blockly.Events.EndBlockDrag.prototype.type = Blockly.Events.END_DRAG;
/**
* Encode the event as JSON.
* @return {!Object} JSON representation.
*/
Blockly.Events.EndBlockDrag.prototype.toJson = function() {
var json = Blockly.Events.EndBlockDrag.superClass_.toJson.call(this);
if (this.isOutside) {
json['isOutside'] = this.isOutside;
}
if (this.xml) {
json['xml'] = this.xml;
}
return json;
};
/**
* Decode the JSON event.
* @param {!Object} json JSON representation.
*/
Blockly.Events.EndBlockDrag.prototype.fromJson = function(json) {
Blockly.Events.EndBlockDrag.superClass_.fromJson.call(this, json);
this.isOutside = json['isOutside'];
this.xml = json['xml'];
};