Skip to content

Commit ba329e4

Browse files
authored
fix!: Remove event dependencies on XML (#9536)
1 parent 1a25a95 commit ba329e4

File tree

6 files changed

+2
-95
lines changed

6 files changed

+2
-95
lines changed

core/events/events_block_create.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import type {Block} from '../block.js';
1515
import * as registry from '../registry.js';
1616
import * as blocks from '../serialization/blocks.js';
17-
import * as utilsXml from '../utils/xml.js';
1817
import {Workspace} from '../workspace.js';
19-
import * as Xml from '../xml.js';
2018
import {BlockBase, BlockBaseJson} from './events_block_base.js';
2119
import {EventType} from './type.js';
2220
import * as eventUtils from './utils.js';
@@ -28,9 +26,6 @@ import * as eventUtils from './utils.js';
2826
export class BlockCreate extends BlockBase {
2927
override type = EventType.BLOCK_CREATE;
3028

31-
/** The XML representation of the created block(s). */
32-
xml?: Element | DocumentFragment;
33-
3429
/** The JSON respresentation of the created block(s). */
3530
json?: blocks.State;
3631

@@ -50,7 +45,6 @@ export class BlockCreate extends BlockBase {
5045
this.recordUndo = false;
5146
}
5247

53-
this.xml = Xml.blockToDomWithXY(opt_block);
5448
this.ids = eventUtils.getDescendantIds(opt_block);
5549

5650
this.json = blocks.save(opt_block, {addCoordinates: true}) as blocks.State;
@@ -63,12 +57,6 @@ export class BlockCreate extends BlockBase {
6357
*/
6458
override toJson(): BlockCreateJson {
6559
const json = super.toJson() as BlockCreateJson;
66-
if (!this.xml) {
67-
throw new Error(
68-
'The block XML is undefined. Either pass a block to ' +
69-
'the constructor, or call fromJson',
70-
);
71-
}
7260
if (!this.ids) {
7361
throw new Error(
7462
'The block IDs are undefined. Either pass a block to ' +
@@ -81,7 +69,6 @@ export class BlockCreate extends BlockBase {
8169
'the constructor, or call fromJson',
8270
);
8371
}
84-
json['xml'] = Xml.domToText(this.xml);
8572
json['ids'] = this.ids;
8673
json['json'] = this.json;
8774
if (!this.recordUndo) {
@@ -109,7 +96,6 @@ export class BlockCreate extends BlockBase {
10996
workspace,
11097
event ?? new BlockCreate(),
11198
) as BlockCreate;
112-
newEvent.xml = utilsXml.textToDom(json['xml']);
11399
newEvent.ids = json['ids'];
114100
newEvent.json = json['json'] as blocks.State;
115101
if (json['recordUndo'] !== undefined) {
@@ -176,7 +162,6 @@ const allShadowBlocks = function (
176162
};
177163

178164
export interface BlockCreateJson extends BlockBaseJson {
179-
xml: string;
180165
ids: string[];
181166
json: object;
182167
recordUndo?: boolean;

core/events/events_block_delete.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import type {Block} from '../block.js';
1515
import * as registry from '../registry.js';
1616
import * as blocks from '../serialization/blocks.js';
17-
import * as utilsXml from '../utils/xml.js';
1817
import {Workspace} from '../workspace.js';
19-
import * as Xml from '../xml.js';
2018
import {BlockBase, BlockBaseJson} from './events_block_base.js';
2119
import {EventType} from './type.js';
2220
import * as eventUtils from './utils.js';
@@ -26,9 +24,6 @@ import * as eventUtils from './utils.js';
2624
* deleted.
2725
*/
2826
export class BlockDelete extends BlockBase {
29-
/** The XML representation of the deleted block(s). */
30-
oldXml?: Element | DocumentFragment;
31-
3227
/** The JSON respresentation of the deleted block(s). */
3328
oldJson?: blocks.State;
3429

@@ -56,7 +51,6 @@ export class BlockDelete extends BlockBase {
5651
this.recordUndo = false;
5752
}
5853

59-
this.oldXml = Xml.blockToDomWithXY(opt_block);
6054
this.ids = eventUtils.getDescendantIds(opt_block);
6155
this.wasShadow = opt_block.isShadow();
6256
this.oldJson = blocks.save(opt_block, {
@@ -71,12 +65,6 @@ export class BlockDelete extends BlockBase {
7165
*/
7266
override toJson(): BlockDeleteJson {
7367
const json = super.toJson() as BlockDeleteJson;
74-
if (!this.oldXml) {
75-
throw new Error(
76-
'The old block XML is undefined. Either pass a block ' +
77-
'to the constructor, or call fromJson',
78-
);
79-
}
8068
if (!this.ids) {
8169
throw new Error(
8270
'The block IDs are undefined. Either pass a block to ' +
@@ -95,7 +83,6 @@ export class BlockDelete extends BlockBase {
9583
'to the constructor, or call fromJson',
9684
);
9785
}
98-
json['oldXml'] = Xml.domToText(this.oldXml);
9986
json['ids'] = this.ids;
10087
json['wasShadow'] = this.wasShadow;
10188
json['oldJson'] = this.oldJson;
@@ -124,10 +111,8 @@ export class BlockDelete extends BlockBase {
124111
workspace,
125112
event ?? new BlockDelete(),
126113
) as BlockDelete;
127-
newEvent.oldXml = utilsXml.textToDom(json['oldXml']);
128114
newEvent.ids = json['ids'];
129-
newEvent.wasShadow =
130-
json['wasShadow'] || newEvent.oldXml.tagName.toLowerCase() === 'shadow';
115+
newEvent.wasShadow = json['wasShadow'];
131116
newEvent.oldJson = json['oldJson'];
132117
if (json['recordUndo'] !== undefined) {
133118
newEvent.recordUndo = json['recordUndo'];
@@ -172,7 +157,6 @@ export class BlockDelete extends BlockBase {
172157
}
173158

174159
export interface BlockDeleteJson extends BlockBaseJson {
175-
oldXml: string;
176160
ids: string[];
177161
wasShadow: boolean;
178162
oldJson: blocks.State;

core/events/events_comment_create.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import type {WorkspaceComment} from '../comments/workspace_comment.js';
1515
import * as registry from '../registry.js';
1616
import * as comments from '../serialization/workspace_comments.js';
17-
import * as utilsXml from '../utils/xml.js';
1817
import type {Workspace} from '../workspace.js';
19-
import * as Xml from '../xml.js';
2018
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
2119
import {EventType} from './type.js';
2220

@@ -26,9 +24,6 @@ import {EventType} from './type.js';
2624
export class CommentCreate extends CommentBase {
2725
override type = EventType.COMMENT_CREATE;
2826

29-
/** The XML representation of the created workspace comment. */
30-
xml?: Element | DocumentFragment;
31-
3227
/** The JSON representation of the created workspace comment. */
3328
json?: comments.State;
3429

@@ -43,7 +38,6 @@ export class CommentCreate extends CommentBase {
4338
return; // Blank event to be populated by fromJson.
4439
}
4540

46-
this.xml = Xml.saveWorkspaceComment(opt_comment);
4741
this.json = comments.save(opt_comment, {addCoordinates: true});
4842
}
4943

@@ -55,19 +49,12 @@ export class CommentCreate extends CommentBase {
5549
*/
5650
override toJson(): CommentCreateJson {
5751
const json = super.toJson() as CommentCreateJson;
58-
if (!this.xml) {
59-
throw new Error(
60-
'The comment XML is undefined. Either pass a comment to ' +
61-
'the constructor, or call fromJson',
62-
);
63-
}
6452
if (!this.json) {
6553
throw new Error(
6654
'The comment JSON is undefined. Either pass a block to ' +
6755
'the constructor, or call fromJson',
6856
);
6957
}
70-
json['xml'] = Xml.domToText(this.xml);
7158
json['json'] = this.json;
7259
return json;
7360
}
@@ -91,7 +78,6 @@ export class CommentCreate extends CommentBase {
9178
workspace,
9279
event ?? new CommentCreate(),
9380
) as CommentCreate;
94-
newEvent.xml = utilsXml.textToDom(json['xml']);
9581
newEvent.json = json['json'];
9682
return newEvent;
9783
}
@@ -107,7 +93,6 @@ export class CommentCreate extends CommentBase {
10793
}
10894

10995
export interface CommentCreateJson extends CommentBaseJson {
110-
xml: string;
11196
json: object;
11297
}
11398

core/events/events_comment_delete.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import type {WorkspaceComment} from '../comments/workspace_comment.js';
1515
import * as registry from '../registry.js';
1616
import * as comments from '../serialization/workspace_comments.js';
17-
import * as utilsXml from '../utils/xml.js';
1817
import type {Workspace} from '../workspace.js';
19-
import * as Xml from '../xml.js';
2018
import {CommentBase, CommentBaseJson} from './events_comment_base.js';
2119
import {EventType} from './type.js';
2220

@@ -26,9 +24,6 @@ import {EventType} from './type.js';
2624
export class CommentDelete extends CommentBase {
2725
override type = EventType.COMMENT_DELETE;
2826

29-
/** The XML representation of the deleted workspace comment. */
30-
xml?: Element;
31-
3227
/** The JSON representation of the created workspace comment. */
3328
json?: comments.State;
3429

@@ -43,7 +38,6 @@ export class CommentDelete extends CommentBase {
4338
return; // Blank event to be populated by fromJson.
4439
}
4540

46-
this.xml = Xml.saveWorkspaceComment(opt_comment);
4741
this.json = comments.save(opt_comment, {addCoordinates: true});
4842
}
4943

@@ -63,19 +57,12 @@ export class CommentDelete extends CommentBase {
6357
*/
6458
override toJson(): CommentDeleteJson {
6559
const json = super.toJson() as CommentDeleteJson;
66-
if (!this.xml) {
67-
throw new Error(
68-
'The comment XML is undefined. Either pass a comment to ' +
69-
'the constructor, or call fromJson',
70-
);
71-
}
7260
if (!this.json) {
7361
throw new Error(
7462
'The comment JSON is undefined. Either pass a block to ' +
7563
'the constructor, or call fromJson',
7664
);
7765
}
78-
json['xml'] = Xml.domToText(this.xml);
7966
json['json'] = this.json;
8067
return json;
8168
}
@@ -99,14 +86,12 @@ export class CommentDelete extends CommentBase {
9986
workspace,
10087
event ?? new CommentDelete(),
10188
) as CommentDelete;
102-
newEvent.xml = utilsXml.textToDom(json['xml']);
10389
newEvent.json = json['json'];
10490
return newEvent;
10591
}
10692
}
10793

10894
export interface CommentDeleteJson extends CommentBaseJson {
109-
xml: string;
11095
json: object;
11196
}
11297

tests/mocha/event_block_create_test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ suite('Block Create Event', function () {
5252
this.workspace.id,
5353
'shadowId',
5454
);
55-
const calls = this.eventsFireStub.getCalls();
56-
const event = calls[calls.length - 1].args[0];
57-
assert.equal(event.xml.tagName, 'shadow');
5855
});
5956

6057
test('Does not create extra shadow blocks', function () {
@@ -100,8 +97,6 @@ suite('Block Create Event', function () {
10097

10198
const json = origEvent.toJson();
10299
const newEvent = new Blockly.Events.fromJson(json, this.workspace);
103-
delete origEvent.xml; // xml fails deep equals for some reason.
104-
delete newEvent.xml; // xml fails deep equals for some reason.
105100

106101
assert.deepEqual(newEvent, origEvent);
107102
});

tests/mocha/event_test.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,6 @@ suite('Events', function () {
639639
type: 'create',
640640
group: '',
641641
blockId: thisObj.block.id,
642-
xml:
643-
'<block xmlns="https://developers.google.com/blockly/xml"' +
644-
' type="simple_test_block" id="testBlockId1" x="0" y="0">' +
645-
'</block>',
646642
ids: [thisObj.block.id],
647643
json: {
648644
'type': 'simple_test_block',
@@ -660,10 +656,6 @@ suite('Events', function () {
660656
type: 'create',
661657
group: '',
662658
blockId: thisObj.shadowBlock.id,
663-
xml:
664-
'<shadow xmlns="https://developers.google.com/blockly/xml"' +
665-
' type="simple_test_block" id="testBlockId2" x="0" y="0">' +
666-
'</shadow>',
667659
ids: [thisObj.shadowBlock.id],
668660
json: {
669661
'type': 'simple_test_block',
@@ -682,10 +674,6 @@ suite('Events', function () {
682674
type: 'delete',
683675
group: '',
684676
blockId: thisObj.block.id,
685-
oldXml:
686-
'<block xmlns="https://developers.google.com/blockly/xml"' +
687-
' type="simple_test_block" id="testBlockId1" x="0" y="0">' +
688-
'</block>',
689677
ids: [thisObj.block.id],
690678
wasShadow: false,
691679
oldJson: {
@@ -704,10 +692,6 @@ suite('Events', function () {
704692
type: 'delete',
705693
group: '',
706694
blockId: thisObj.shadowBlock.id,
707-
oldXml:
708-
'<shadow xmlns="https://developers.google.com/blockly/xml"' +
709-
' type="simple_test_block" id="testBlockId2" x="0" y="0">' +
710-
'</shadow>',
711695
ids: [thisObj.shadowBlock.id],
712696
wasShadow: true,
713697
oldJson: {
@@ -765,11 +749,6 @@ suite('Events', function () {
765749
type: 'comment_create',
766750
group: '',
767751
commentId: thisObj.comment.id,
768-
// TODO: Before merging, is this a dumb change detector?
769-
xml: Blockly.Xml.domToText(
770-
Blockly.Xml.saveWorkspaceComment(thisObj.comment),
771-
{addCoordinates: true},
772-
),
773752
json: {
774753
height: 100,
775754
width: 120,
@@ -788,11 +767,6 @@ suite('Events', function () {
788767
type: 'comment_delete',
789768
group: '',
790769
commentId: thisObj.comment.id,
791-
// TODO: Before merging, is this a dumb change detector?
792-
xml: Blockly.Xml.domToText(
793-
Blockly.Xml.saveWorkspaceComment(thisObj.comment),
794-
{addCoordinates: true},
795-
),
796770
json: {
797771
height: 100,
798772
width: 120,
@@ -1405,7 +1379,6 @@ suite('Events', function () {
14051379
const block = workspaceSvg.newBlock('');
14061380
block.initSvg();
14071381
block.setCommentText('test comment');
1408-
const expectedOldXml = Blockly.Xml.blockToDomWithXY(block);
14091382
const expectedId = block.id;
14101383

14111384
// Run all queued events.
@@ -1426,7 +1399,7 @@ suite('Events', function () {
14261399
this.eventsFireSpy,
14271400
0,
14281401
Blockly.Events.BlockDelete,
1429-
{oldXml: expectedOldXml, group: ''},
1402+
{group: ''},
14301403
workspaceSvg.id,
14311404
expectedId,
14321405
);

0 commit comments

Comments
 (0)