refactor: Remove last remaining circular import in core/ (#6818)

* refactor(xml): Move textToDom to core/utils/xml.ts

  This function being in core/xml.ts was the cause for the last
  remaining circular import in core/ (between variables.ts and
  xml.ts).

  Moving it to utils/xml.ts makes sense anyway, since there is
  nothing Blockly-specific about this function.

  Fixes #6817.

* fix(closure): Reenable goog.declareModuleId multiple-call check

  Reenable an assertion which check to make sure that
  goog.declareModuleId is not called more than once in a module
  (and which also catches circular imports amongst ES modules, which
  are not detected by closure-make-deps).

* chore(tests,demos): Augo-migrate use of textToDom

  Testing the migration file entry by auto-migrating all uses of
  Blockly.Xml.textToDom to Blockly.utils.xml.textToDom.

* chore(blocks): Manually migrate remaining use of textToDom

  Update the one remaining call to textToDom (in blocks/lists.ts)
  to the function's new location - also removing the last use of
  the Blockly.Xml / core/xml.ts) module from this file.

* docs(xml): Remove unneeded @alias per comments on PR #6818

* fix(imports): Remove unused import
This commit is contained in:
Christopher Allen
2023-02-07 12:11:11 +00:00
committed by GitHub
parent d808c068d2
commit 167e26521c
48 changed files with 292 additions and 261 deletions

View File

@@ -44,7 +44,7 @@ BlocklyStorage.restoreBlocks = function(opt_workspace) {
var url = window.location.href.split('#')[0]; var url = window.location.href.split('#')[0];
if ('localStorage' in window && window.localStorage[url]) { if ('localStorage' in window && window.localStorage[url]) {
var workspace = opt_workspace || Blockly.getMainWorkspace(); var workspace = opt_workspace || Blockly.getMainWorkspace();
var xml = Blockly.Xml.textToDom(window.localStorage[url]); var xml = Blockly.utils.xml.textToDom(window.localStorage[url]);
Blockly.Xml.domToWorkspace(xml, workspace); Blockly.Xml.domToWorkspace(xml, workspace);
} }
}; };
@@ -168,7 +168,7 @@ BlocklyStorage.monitorChanges_ = function(workspace) {
*/ */
BlocklyStorage.loadXml_ = function(xml, workspace) { BlocklyStorage.loadXml_ = function(xml, workspace) {
try { try {
xml = Blockly.Xml.textToDom(xml); xml = Blockly.utils.xml.textToDom(xml);
} catch (e) { } catch (e) {
BlocklyStorage.alert(BlocklyStorage.XML_ERROR + '\nXML: ' + xml); BlocklyStorage.alert(BlocklyStorage.XML_ERROR + '\nXML: ' + xml);
return; return;

View File

@@ -13,7 +13,6 @@
goog.module('Blockly.libraryBlocks.lists'); goog.module('Blockly.libraryBlocks.lists');
const xmlUtils = goog.require('Blockly.utils.xml'); const xmlUtils = goog.require('Blockly.utils.xml');
const Xml = goog.require('Blockly.Xml');
const {Align} = goog.require('Blockly.Input'); const {Align} = goog.require('Blockly.Input');
/* eslint-disable-next-line no-unused-vars */ /* eslint-disable-next-line no-unused-vars */
const {Block} = goog.requireType('Blockly.Block'); const {Block} = goog.requireType('Blockly.Block');
@@ -480,7 +479,7 @@ blocks['lists_getIndex'] = {
this.updateStatement_(true); this.updateStatement_(true);
} else if (typeof state === 'string') { } else if (typeof state === 'string') {
// backward compatible for json serialised mutations // backward compatible for json serialised mutations
this.domToMutation(Xml.textToDom(state)); this.domToMutation(xmlUtils.textToDom(state));
} }
}, },

View File

@@ -617,8 +617,10 @@ goog.declareModuleId = function(namespace) {
'within an ES6 module'); 'within an ES6 module');
} }
if (goog.moduleLoaderState_ && goog.moduleLoaderState_.moduleName) { if (goog.moduleLoaderState_ && goog.moduleLoaderState_.moduleName) {
// throw new Error( throw new Error(
// 'goog.declareModuleId may only be called once per module.'); 'goog.declareModuleId may only be called once per module.' +
'This error can also be caused by circular imports, which ' +
'are not supported by debug module loader.');
} }
if (namespace in goog.loadedModules_) { if (namespace in goog.loadedModules_) {
throw new Error( throw new Error(

View File

@@ -16,6 +16,7 @@ import type {Block} from '../block.js';
import type {BlockSvg} from '../block_svg.js'; import type {BlockSvg} from '../block_svg.js';
import * as deprecation from '../utils/deprecation.js'; import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js'; import * as registry from '../registry.js';
import * as utilsXml from '../utils/xml.js';
import {Workspace} from '../workspace.js'; import {Workspace} from '../workspace.js';
import * as Xml from '../xml.js'; import * as Xml from '../xml.js';
@@ -182,7 +183,8 @@ export class BlockChange extends BlockBase {
if (block.loadExtraState) { if (block.loadExtraState) {
block.loadExtraState(JSON.parse(value as string || '{}')); block.loadExtraState(JSON.parse(value as string || '{}'));
} else if (block.domToMutation) { } else if (block.domToMutation) {
block.domToMutation(Xml.textToDom(value as string || '<mutation/>')); block.domToMutation(
utilsXml.textToDom(value as string || '<mutation/>'));
} }
eventUtils.fire( eventUtils.fire(
new BlockChange(block, 'mutation', null, oldState, value)); new BlockChange(block, 'mutation', null, oldState, value));

View File

@@ -16,6 +16,7 @@ import type {Block} from '../block.js';
import * as deprecation from '../utils/deprecation.js'; import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js'; import * as registry from '../registry.js';
import * as blocks from '../serialization/blocks.js'; import * as blocks from '../serialization/blocks.js';
import * as utilsXml from '../utils/xml.js';
import * as Xml from '../xml.js'; import * as Xml from '../xml.js';
import {BlockBase, BlockBaseJson} from './events_block_base.js'; import {BlockBase, BlockBaseJson} from './events_block_base.js';
@@ -99,7 +100,7 @@ export class BlockCreate extends BlockBase {
'Blockly.Events.BlockCreate.prototype.fromJson', 'version 9', 'Blockly.Events.BlockCreate.prototype.fromJson', 'version 9',
'version 10', 'Blockly.Events.fromJson'); 'version 10', 'Blockly.Events.fromJson');
super.fromJson(json); super.fromJson(json);
this.xml = Xml.textToDom(json['xml']); this.xml = utilsXml.textToDom(json['xml']);
this.ids = json['ids']; this.ids = json['ids'];
this.json = json['json'] as blocks.State; this.json = json['json'] as blocks.State;
if (json['recordUndo'] !== undefined) { if (json['recordUndo'] !== undefined) {
@@ -121,7 +122,7 @@ export class BlockCreate extends BlockBase {
const newEvent = const newEvent =
super.fromJson(json, workspace, event ?? new BlockCreate()) as super.fromJson(json, workspace, event ?? new BlockCreate()) as
BlockCreate; BlockCreate;
newEvent.xml = Xml.textToDom(json['xml']); newEvent.xml = utilsXml.textToDom(json['xml']);
newEvent.ids = json['ids']; newEvent.ids = json['ids'];
newEvent.json = json['json'] as blocks.State; newEvent.json = json['json'] as blocks.State;
if (json['recordUndo'] !== undefined) { if (json['recordUndo'] !== undefined) {

View File

@@ -16,6 +16,7 @@ import type {Block} from '../block.js';
import * as deprecation from '../utils/deprecation.js'; import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js'; import * as registry from '../registry.js';
import * as blocks from '../serialization/blocks.js'; import * as blocks from '../serialization/blocks.js';
import * as utilsXml from '../utils/xml.js';
import * as Xml from '../xml.js'; import * as Xml from '../xml.js';
import {BlockBase, BlockBaseJson} from './events_block_base.js'; import {BlockBase, BlockBaseJson} from './events_block_base.js';
@@ -112,7 +113,7 @@ export class BlockDelete extends BlockBase {
'Blockly.Events.BlockDelete.prototype.fromJson', 'version 9', 'Blockly.Events.BlockDelete.prototype.fromJson', 'version 9',
'version 10', 'Blockly.Events.fromJson'); 'version 10', 'Blockly.Events.fromJson');
super.fromJson(json); super.fromJson(json);
this.oldXml = Xml.textToDom(json['oldXml']); this.oldXml = utilsXml.textToDom(json['oldXml']);
this.ids = json['ids']; this.ids = json['ids'];
this.wasShadow = this.wasShadow =
json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow'; json['wasShadow'] || this.oldXml.tagName.toLowerCase() === 'shadow';
@@ -136,7 +137,7 @@ export class BlockDelete extends BlockBase {
const newEvent = const newEvent =
super.fromJson(json, workspace, event ?? new BlockDelete()) as super.fromJson(json, workspace, event ?? new BlockDelete()) as
BlockDelete; BlockDelete;
newEvent.oldXml = Xml.textToDom(json['oldXml']); newEvent.oldXml = utilsXml.textToDom(json['oldXml']);
newEvent.ids = json['ids']; newEvent.ids = json['ids'];
newEvent.wasShadow = newEvent.wasShadow =
json['wasShadow'] || newEvent.oldXml.tagName.toLowerCase() === 'shadow'; json['wasShadow'] || newEvent.oldXml.tagName.toLowerCase() === 'shadow';

View File

@@ -15,6 +15,7 @@ goog.declareModuleId('Blockly.Events.CommentCreate');
import * as deprecation from '../utils/deprecation.js'; import * as deprecation from '../utils/deprecation.js';
import * as registry from '../registry.js'; import * as registry from '../registry.js';
import type {WorkspaceComment} from '../workspace_comment.js'; import type {WorkspaceComment} from '../workspace_comment.js';
import * as utilsXml from '../utils/xml.js';
import * as Xml from '../xml.js'; import * as Xml from '../xml.js';
import {CommentBase, CommentBaseJson} from './events_comment_base.js'; import {CommentBase, CommentBaseJson} from './events_comment_base.js';
@@ -72,7 +73,7 @@ export class CommentCreate extends CommentBase {
'Blockly.Events.CommentCreate.prototype.fromJson', 'version 9', 'Blockly.Events.CommentCreate.prototype.fromJson', 'version 9',
'version 10', 'Blockly.Events.fromJson'); 'version 10', 'Blockly.Events.fromJson');
super.fromJson(json); super.fromJson(json);
this.xml = Xml.textToDom(json['xml']); this.xml = utilsXml.textToDom(json['xml']);
} }
/** /**
@@ -89,7 +90,7 @@ export class CommentCreate extends CommentBase {
const newEvent = const newEvent =
super.fromJson(json, workspace, event ?? new CommentCreate()) as super.fromJson(json, workspace, event ?? new CommentCreate()) as
CommentCreate; CommentCreate;
newEvent.xml = Xml.textToDom(json['xml']); newEvent.xml = utilsXml.textToDom(json['xml']);
return newEvent; return newEvent;
} }

View File

@@ -17,6 +17,7 @@ import type {WorkspaceComment} from '../workspace_comment.js';
import {CommentBase, CommentBaseJson} from './events_comment_base.js'; import {CommentBase, CommentBaseJson} from './events_comment_base.js';
import * as eventUtils from './utils.js'; import * as eventUtils from './utils.js';
import * as utilsXml from '../utils/xml.js';
import * as Xml from '../xml.js'; import * as Xml from '../xml.js';
import type {Workspace} from '../workspace.js'; import type {Workspace} from '../workspace.js';
@@ -83,7 +84,7 @@ export class CommentDelete extends CommentBase {
const newEvent = const newEvent =
super.fromJson(json, workspace, event ?? new CommentDelete()) as super.fromJson(json, workspace, event ?? new CommentDelete()) as
CommentDelete; CommentDelete;
newEvent.xml = Xml.textToDom(json['xml']); newEvent.xml = utilsXml.textToDom(json['xml']);
return newEvent; return newEvent;
} }
} }

View File

@@ -43,7 +43,6 @@ import * as userAgent from './utils/useragent.js';
import * as utilsXml from './utils/xml.js'; import * as utilsXml from './utils/xml.js';
import * as WidgetDiv from './widgetdiv.js'; import * as WidgetDiv from './widgetdiv.js';
import type {WorkspaceSvg} from './workspace_svg.js'; import type {WorkspaceSvg} from './workspace_svg.js';
import * as Xml from './xml.js';
/** /**
* A function that is called to validate changes to the field's value before * A function that is called to validate changes to the field's value before
@@ -454,7 +453,7 @@ export abstract class Field<T = any> implements IASTNodeLocationSvg,
callingClass.prototype.toXml !== this.toXml) { callingClass.prototype.toXml !== this.toXml) {
const elem = utilsXml.createElement('field'); const elem = utilsXml.createElement('field');
elem.setAttribute('name', this.name || ''); elem.setAttribute('name', this.name || '');
const text = Xml.domToText(this.toXml(elem)); const text = utilsXml.domToText(this.toXml(elem));
return text.replace( return text.replace(
' xmlns="https://developers.google.com/blockly/xml"', ''); ' xmlns="https://developers.google.com/blockly/xml"', '');
} }
@@ -476,7 +475,7 @@ export abstract class Field<T = any> implements IASTNodeLocationSvg,
boolean { boolean {
if (callingClass.prototype.loadState === this.loadState && if (callingClass.prototype.loadState === this.loadState &&
callingClass.prototype.fromXml !== this.fromXml) { callingClass.prototype.fromXml !== this.fromXml) {
this.fromXml(Xml.textToDom(state as string)); this.fromXml(utilsXml.textToDom(state as string));
return true; return true;
} }
// Either they called this on purpose from their loadState, or they have // Either they called this on purpose from their loadState, or they have

View File

@@ -33,6 +33,7 @@ import {Svg} from './utils/svg.js';
import * as toolbox from './utils/toolbox.js'; import * as toolbox from './utils/toolbox.js';
import * as Variables from './variables.js'; import * as Variables from './variables.js';
import {WorkspaceSvg} from './workspace_svg.js'; import {WorkspaceSvg} from './workspace_svg.js';
import * as utilsXml from './utils/xml.js';
import * as Xml from './xml.js'; import * as Xml from './xml.js';
@@ -742,7 +743,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
let block; let block;
if (blockInfo['blockxml']) { if (blockInfo['blockxml']) {
const xml = (typeof blockInfo['blockxml'] === 'string' ? const xml = (typeof blockInfo['blockxml'] === 'string' ?
Xml.textToDom(blockInfo['blockxml']) : utilsXml.textToDom(blockInfo['blockxml']) :
blockInfo['blockxml']) as Element; blockInfo['blockxml']) as Element;
block = this.getRecycledBlock_(xml.getAttribute('type')!); block = this.getRecycledBlock_(xml.getAttribute('type')!);
if (!block) { if (!block) {
@@ -801,7 +802,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout {
gap = parseInt(blockInfo['gap'].toString()); gap = parseInt(blockInfo['gap'].toString());
} else if (blockInfo['blockxml']) { } else if (blockInfo['blockxml']) {
const xml = (typeof blockInfo['blockxml'] === 'string' ? const xml = (typeof blockInfo['blockxml'] === 'string' ?
Xml.textToDom(blockInfo['blockxml']) : utilsXml.textToDom(blockInfo['blockxml']) :
blockInfo['blockxml']) as Element; blockInfo['blockxml']) as Element;
gap = parseInt(xml.getAttribute('gap')!); gap = parseInt(xml.getAttribute('gap')!);
} }

View File

@@ -34,7 +34,6 @@ import * as utilsXml from './utils/xml.js';
import * as Variables from './variables.js'; import * as Variables from './variables.js';
import type {Workspace} from './workspace.js'; import type {Workspace} from './workspace.js';
import type {WorkspaceSvg} from './workspace_svg.js'; import type {WorkspaceSvg} from './workspace_svg.js';
import * as Xml from './xml.js';
/** /**
@@ -440,12 +439,12 @@ export function mutateCallers(defBlock: Block) {
const callers = getCallers(name, defBlock.workspace); const callers = getCallers(name, defBlock.workspace);
for (let i = 0, caller; caller = callers[i]; i++) { for (let i = 0, caller; caller = callers[i]; i++) {
const oldMutationDom = caller.mutationToDom!(); const oldMutationDom = caller.mutationToDom!();
const oldMutation = oldMutationDom && Xml.domToText(oldMutationDom); const oldMutation = oldMutationDom && utilsXml.domToText(oldMutationDom);
if (caller.domToMutation) { if (caller.domToMutation) {
caller.domToMutation(xmlElement); caller.domToMutation(xmlElement);
} }
const newMutationDom = caller.mutationToDom!(); const newMutationDom = caller.mutationToDom!();
const newMutation = newMutationDom && Xml.domToText(newMutationDom); const newMutation = newMutationDom && utilsXml.domToText(newMutationDom);
if (oldMutation !== newMutation) { if (oldMutation !== newMutation) {
// Fire a mutation on every caller block. But don't record this as an // Fire a mutation on every caller block. But don't record this as an
// undo action since it is deterministically tied to the procedure's // undo action since it is deterministically tied to the procedure's

View File

@@ -19,6 +19,7 @@ import * as eventUtils from '../events/utils.js';
import {inputTypes} from '../input_types.js'; import {inputTypes} from '../input_types.js';
import type {ISerializer} from '../interfaces/i_serializer.js'; import type {ISerializer} from '../interfaces/i_serializer.js';
import {Size} from '../utils/size.js'; import {Size} from '../utils/size.js';
import * as utilsXml from '../utils/xml.js';
import type {Workspace} from '../workspace.js'; import type {Workspace} from '../workspace.js';
import * as Xml from '../xml.js'; import * as Xml from '../xml.js';
@@ -461,7 +462,7 @@ function loadExtraState(block: Block, state: State) {
if (block.loadExtraState) { if (block.loadExtraState) {
block.loadExtraState(state['extraState']); block.loadExtraState(state['extraState']);
} else if (block.domToMutation) { } else if (block.domToMutation) {
block.domToMutation(Xml.textToDom(state['extraState'])); block.domToMutation(utilsXml.textToDom(state['extraState']));
} }
} }

View File

@@ -15,7 +15,7 @@ goog.declareModuleId('Blockly.utils.toolbox');
import type {ConnectionState} from '../serialization/blocks.js'; import type {ConnectionState} from '../serialization/blocks.js';
import type {CssConfig as CategoryCssConfig} from '../toolbox/category.js'; import type {CssConfig as CategoryCssConfig} from '../toolbox/category.js';
import type {CssConfig as SeparatorCssConfig} from '../toolbox/separator.js'; import type {CssConfig as SeparatorCssConfig} from '../toolbox/separator.js';
import * as Xml from '../xml.js'; import * as utilsXml from './xml.js';
/** /**
@@ -387,7 +387,7 @@ export function parseToolboxTree(toolboxDef: Element|null|string): Element|
let parsedToolboxDef: Element|null = null; let parsedToolboxDef: Element|null = null;
if (toolboxDef) { if (toolboxDef) {
if (typeof toolboxDef === 'string') { if (typeof toolboxDef === 'string') {
parsedToolboxDef = Xml.textToDom(toolboxDef); parsedToolboxDef = utilsXml.textToDom(toolboxDef);
if (parsedToolboxDef.nodeName.toLowerCase() !== 'xml') { if (parsedToolboxDef.nodeName.toLowerCase() !== 'xml') {
throw TypeError('Toolbox should be an <xml> document.'); throw TypeError('Toolbox should be an <xml> document.');
} }

View File

@@ -106,6 +106,23 @@ export function createTextNode(text: string): Text {
return document.createTextNode(text); return document.createTextNode(text);
} }
/**
* Converts an XML string into a DOM structure.
*
* @param text An XML string.
* @returns A DOM object representing the singular child of the document
* element.
* @throws if the text doesn't parse.
*/
export function textToDom(text: string): Element {
const doc = textToDomDocument(text);
if (!doc || !doc.documentElement ||
doc.getElementsByTagName('parsererror').length) {
throw Error('textToDom was unable to parse: ' + text);
}
return doc.documentElement;
}
/** /**
* Converts an XML string into a DOM tree. * Converts an XML string into a DOM tree.
* *

View File

@@ -19,7 +19,6 @@ import * as utilsXml from './utils/xml.js';
import {VariableModel} from './variable_model.js'; import {VariableModel} from './variable_model.js';
import type {Workspace} from './workspace.js'; import type {Workspace} from './workspace.js';
import type {WorkspaceSvg} from './workspace_svg.js'; import type {WorkspaceSvg} from './workspace_svg.js';
import * as Xml from './xml.js';
/** /**
@@ -136,7 +135,7 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] {
block.setAttribute('type', 'math_change'); block.setAttribute('type', 'math_change');
block.setAttribute('gap', Blocks['variables_get'] ? '20' : '8'); block.setAttribute('gap', Blocks['variables_get'] ? '20' : '8');
block.appendChild(generateVariableFieldDom(mostRecentVariable)); block.appendChild(generateVariableFieldDom(mostRecentVariable));
const value = Xml.textToDom( const value = utilsXml.textToDom(
'<value name="DELTA">' + '<value name="DELTA">' +
'<shadow type="math_number">' + '<shadow type="math_number">' +
'<field name="NUM">1</field>' + '<field name="NUM">1</field>' +

View File

@@ -15,6 +15,7 @@ goog.declareModuleId('Blockly.Xml');
import type {Block} from './block.js'; import type {Block} from './block.js';
import type {BlockSvg} from './block_svg.js'; import type {BlockSvg} from './block_svg.js';
import type {Connection} from './connection.js'; import type {Connection} from './connection.js';
import * as deprecation from './utils/deprecation.js';
import * as eventUtils from './events/utils.js'; import * as eventUtils from './events/utils.js';
import type {Field} from './field.js'; import type {Field} from './field.js';
import {inputTypes} from './input_types.js'; import {inputTypes} from './input_types.js';
@@ -380,14 +381,13 @@ export function domToPrettyText(dom: Node): string {
* @returns A DOM object representing the singular child of the document * @returns A DOM object representing the singular child of the document
* element. * element.
* @throws if the text doesn't parse. * @throws if the text doesn't parse.
* @deprecated Moved to core/utils/xml.js.
*/ */
export function textToDom(text: string): Element { export function textToDom(text: string): Element {
const doc = utilsXml.textToDomDocument(text); deprecation.warn(
if (!doc || !doc.documentElement || 'Blockly.Xml.textToDom', 'version 9', 'version 10',
doc.getElementsByTagName('parsererror').length) { 'Use Blockly.utils.xml.textToDom instead');
throw Error('textToDom was unable to parse: ' + text); return utilsXml.textToDom(text);
}
return doc.documentElement;
} }
/** /**

View File

@@ -138,7 +138,7 @@ AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
// Append each block node to XML DOM. // Append each block node to XML DOM.
for (var blockType in blockXmlMap) { for (var blockType in blockXmlMap) {
var blockXmlDom = Blockly.Xml.textToDom(blockXmlMap[blockType]); var blockXmlDom = Blockly.utils.xml.textToDom(blockXmlMap[blockType]);
var blockNode = blockXmlDom.firstElementChild; var blockNode = blockXmlDom.firstElementChild;
xmlDom.appendChild(blockNode); xmlDom.appendChild(blockNode);
} }
@@ -155,7 +155,7 @@ AppController.prototype.formatBlockLibraryForExport_ = function(blockXmlMap) {
* @private * @private
*/ */
AppController.prototype.formatBlockLibraryForImport_ = function(xmlText) { AppController.prototype.formatBlockLibraryForImport_ = function(xmlText) {
var inputXml = Blockly.Xml.textToDom(xmlText); var inputXml = Blockly.utils.xml.textToDom(xmlText);
// Convert the live HTMLCollection of child Elements into a static array, // Convert the live HTMLCollection of child Elements into a static array,
// since the addition to editorWorkspaceXml below removes it from inputXml. // since the addition to editorWorkspaceXml below removes it from inputXml.
var inputChildren = Array.from(inputXml.children); var inputChildren = Array.from(inputXml.children);
@@ -192,7 +192,7 @@ AppController.prototype.formatBlockLibraryForImport_ = function(xmlText) {
* @private * @private
*/ */
AppController.prototype.getBlockTypeFromXml_ = function(xmlText) { AppController.prototype.getBlockTypeFromXml_ = function(xmlText) {
var xmlDom = Blockly.Xml.textToDom(xmlText); var xmlDom = Blockly.utils.xml.textToDom(xmlText);
// Find factory base block. // Find factory base block.
var factoryBaseBlockXml = xmlDom.getElementsByTagName('block')[0]; var factoryBaseBlockXml = xmlDom.getElementsByTagName('block')[0];
// Get field elements from factory base. // Get field elements from factory base.

View File

@@ -89,7 +89,7 @@ BlockLibraryStorage.prototype.removeBlock = function(blockType) {
BlockLibraryStorage.prototype.getBlockXml = function(blockType) { BlockLibraryStorage.prototype.getBlockXml = function(blockType) {
var xml = this.blocks[blockType] || null; var xml = this.blocks[blockType] || null;
if (xml) { if (xml) {
var xml = Blockly.Xml.textToDom(xml); var xml = Blockly.utils.xml.textToDom(xml);
} }
return xml; return xml;
}; };

View File

@@ -304,7 +304,7 @@ BlockFactory.disableEnableLink = function() {
*/ */
BlockFactory.showStarterBlock = function() { BlockFactory.showStarterBlock = function() {
BlockFactory.mainWorkspace.clear(); BlockFactory.mainWorkspace.clear();
var xml = Blockly.Xml.textToDom(BlockFactory.STARTER_BLOCK_XML_TEXT); var xml = Blockly.utils.xml.textToDom(BlockFactory.STARTER_BLOCK_XML_TEXT);
Blockly.Xml.domToWorkspace(xml, BlockFactory.mainWorkspace); Blockly.Xml.domToWorkspace(xml, BlockFactory.mainWorkspace);
}; };

View File

@@ -26,7 +26,7 @@ StandardCategories.categoryMap = Object.create(null);
StandardCategories.categoryMap['logic'] = StandardCategories.categoryMap['logic'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Logic'); new ListElement(ListElement.TYPE_CATEGORY, 'Logic');
StandardCategories.categoryMap['logic'].xml = StandardCategories.categoryMap['logic'].xml =
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="controls_if"></block>' + '<block type="controls_if"></block>' +
'<block type="logic_compare"></block>' + '<block type="logic_compare"></block>' +
@@ -41,7 +41,7 @@ StandardCategories.categoryMap['logic'].hue = 210;
StandardCategories.categoryMap['loops'] = StandardCategories.categoryMap['loops'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Loops'); new ListElement(ListElement.TYPE_CATEGORY, 'Loops');
StandardCategories.categoryMap['loops'].xml = StandardCategories.categoryMap['loops'].xml =
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="controls_repeat_ext">' + '<block type="controls_repeat_ext">' +
'<value name="TIMES">' + '<value name="TIMES">' +
@@ -76,7 +76,7 @@ StandardCategories.categoryMap['loops'].hue = 120;
StandardCategories.categoryMap['math'] = StandardCategories.categoryMap['math'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Math'); new ListElement(ListElement.TYPE_CATEGORY, 'Math');
StandardCategories.categoryMap['math'].xml = StandardCategories.categoryMap['math'].xml =
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="math_number"></block>' + '<block type="math_number"></block>' +
'<block type="math_arithmetic">' + '<block type="math_arithmetic">' +
@@ -169,7 +169,7 @@ StandardCategories.categoryMap['math'].hue = 230;
StandardCategories.categoryMap['text'] = StandardCategories.categoryMap['text'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Text'); new ListElement(ListElement.TYPE_CATEGORY, 'Text');
StandardCategories.categoryMap['text'].xml = StandardCategories.categoryMap['text'].xml =
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="text"></block>' + '<block type="text"></block>' +
'<block type="text_join"></block>' + '<block type="text_join"></block>' +
@@ -252,7 +252,7 @@ StandardCategories.categoryMap['text'].hue = 160;
StandardCategories.categoryMap['lists'] = StandardCategories.categoryMap['lists'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Lists'); new ListElement(ListElement.TYPE_CATEGORY, 'Lists');
StandardCategories.categoryMap['lists'].xml = StandardCategories.categoryMap['lists'].xml =
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="lists_create_with">' + '<block type="lists_create_with">' +
'<mutation items="0"></mutation>' + '<mutation items="0"></mutation>' +
@@ -309,7 +309,7 @@ StandardCategories.categoryMap['lists'].hue = 260;
StandardCategories.categoryMap['colour'] = StandardCategories.categoryMap['colour'] =
new ListElement(ListElement.TYPE_CATEGORY, 'Colour'); new ListElement(ListElement.TYPE_CATEGORY, 'Colour');
StandardCategories.categoryMap['colour'].xml = StandardCategories.categoryMap['colour'].xml =
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="colour_picker"></block>' + '<block type="colour_picker"></block>' +
'<block type="colour_random"></block>' + '<block type="colour_random"></block>' +

View File

@@ -701,7 +701,7 @@ WorkspaceFactoryController.prototype.importFile = function(file, importMode) {
// Try to parse XML from file and load it into toolbox editing area. // Try to parse XML from file and load it into toolbox editing area.
// Print error message if fail. // Print error message if fail.
try { try {
var tree = Blockly.Xml.textToDom(reader.result); var tree = Blockly.utils.xml.textToDom(reader.result);
if (importMode === WorkspaceFactoryController.MODE_TOOLBOX) { if (importMode === WorkspaceFactoryController.MODE_TOOLBOX) {
// Switch mode. // Switch mode.
controller.setMode(WorkspaceFactoryController.MODE_TOOLBOX); controller.setMode(WorkspaceFactoryController.MODE_TOOLBOX);

View File

@@ -799,7 +799,7 @@ function init() {
mainWorkspace); mainWorkspace);
} else { } else {
var xml = '<xml xmlns="https://developers.google.com/blockly/xml"><block type="factory_base" deletable="false" movable="false"></block></xml>'; var xml = '<xml xmlns="https://developers.google.com/blockly/xml"><block type="factory_base" deletable="false" movable="false"></block></xml>';
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), mainWorkspace); Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(xml), mainWorkspace);
} }
mainWorkspace.clearUndo(); mainWorkspace.clearUndo();

View File

@@ -127,11 +127,11 @@ Code.loadBlocks = function(defaultXml) {
} else if (loadOnce) { } else if (loadOnce) {
// Language switching stores the blocks during the reload. // Language switching stores the blocks during the reload.
delete window.sessionStorage.loadOnceBlocks; delete window.sessionStorage.loadOnceBlocks;
var xml = Blockly.Xml.textToDom(loadOnce); var xml = Blockly.utils.xml.textToDom(loadOnce);
Blockly.Xml.domToWorkspace(xml, Code.workspace); Blockly.Xml.domToWorkspace(xml, Code.workspace);
} else if (defaultXml) { } else if (defaultXml) {
// Load the editor with default starting blocks. // Load the editor with default starting blocks.
var xml = Blockly.Xml.textToDom(defaultXml); var xml = Blockly.utils.xml.textToDom(defaultXml);
Blockly.Xml.domToWorkspace(xml, Code.workspace); Blockly.Xml.domToWorkspace(xml, Code.workspace);
} else if ('BlocklyStorage' in window) { } else if ('BlocklyStorage' in window) {
// Restore saved blocks in a separate thread so that subsequent // Restore saved blocks in a separate thread so that subsequent
@@ -264,7 +264,7 @@ Code.tabClick = function(clickedName) {
var xmlText = xmlTextarea.value; var xmlText = xmlTextarea.value;
var xmlDom = null; var xmlDom = null;
try { try {
xmlDom = Blockly.Xml.textToDom(xmlText); xmlDom = Blockly.utils.xml.textToDom(xmlText);
} catch (e) { } catch (e) {
var q = window.confirm( var q = window.confirm(
MSG['parseError'].replace(/%1/g, 'XML').replace('%2', e)); MSG['parseError'].replace(/%1/g, 'XML').replace('%2', e));
@@ -459,7 +459,7 @@ Code.init = function() {
var toolboxText = document.getElementById('toolbox').outerHTML; var toolboxText = document.getElementById('toolbox').outerHTML;
toolboxText = toolboxText.replace(/(^|[^%]){(\w+)}/g, toolboxText = toolboxText.replace(/(^|[^%]){(\w+)}/g,
function(m, p1, p2) {return p1 + MSG[p2];}); function(m, p1, p2) {return p1 + MSG[p2];});
var toolboxXml = Blockly.Xml.textToDom(toolboxText); var toolboxXml = Blockly.utils.xml.textToDom(toolboxText);
Code.workspace = Blockly.inject('content_blocks', Code.workspace = Blockly.inject('content_blocks',
{grid: {grid:

View File

@@ -1427,6 +1427,14 @@
{ {
oldName: 'Blockly.TouchGesture', oldName: 'Blockly.TouchGesture',
newName: 'Blockly.Gesture', newName: 'Blockly.Gesture',
}, },
] {
oldName: 'Blockly.Xml',
exports: {
textToDom: {
newModule: 'Blockly.utils.xml',
},
},
}
],
} }

View File

@@ -121,7 +121,7 @@ function fromXml(filename, xmlText, opt_append) {
demoWorkspace.clear(); demoWorkspace.clear();
} }
try { try {
var xmlDoc = Blockly.Xml.textToDom(xmlText); var xmlDoc = Blockly.utils.xml.textToDom(xmlText);
if (opt_append) { if (opt_append) {
Blockly.Xml.appendDomToWorkspace(xmlDoc, demoWorkspace); Blockly.Xml.appendDomToWorkspace(xmlDoc, demoWorkspace);
} else { } else {

View File

@@ -506,7 +506,7 @@ suite('Blocks', function() {
suite('Deserialization', function() { suite('Deserialization', function() {
setup(function() { setup(function() {
this.deserializationHelper = function(text) { this.deserializationHelper = function(text) {
const dom = Blockly.Xml.textToDom(text); const dom = Blockly.utils.xml.textToDom(text);
Blockly.Xml.appendDomToWorkspace(dom, this.workspace); Blockly.Xml.appendDomToWorkspace(dom, this.workspace);
this.assertConnectionsEmpty(); this.assertConnectionsEmpty();
this.clock.runAll(); this.clock.runAll();
@@ -616,7 +616,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getInputs().length, 0); chai.assert.equal(this.getInputs().length, 0);
}); });
test('Collapsed Multi-Row Middle', function() { test('Collapsed Multi-Row Middle', function() {
Blockly.Xml.appendDomToWorkspace(Blockly.Xml.textToDom( Blockly.Xml.appendDomToWorkspace(Blockly.utils.xml.textToDom(
'<xml>' + '<xml>' +
' <block type="row_block">' + ' <block type="row_block">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
@@ -735,7 +735,7 @@ suite('Blocks', function() {
}); });
suite('setCollapsed', function() { suite('setCollapsed', function() {
test('Stack', function() { test('Stack', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="stack_block"/>' '<block type="stack_block"/>'
), this.workspace); ), this.workspace);
this.clock.runAll(); this.clock.runAll();
@@ -751,7 +751,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getNext().length, 1); chai.assert.equal(this.getNext().length, 1);
}); });
test('Multi-Stack', function() { test('Multi-Stack', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="stack_block">' + '<block type="stack_block">' +
' <next>' + ' <next>' +
' <block type="stack_block">' + ' <block type="stack_block">' +
@@ -776,7 +776,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getNext().length, 3); chai.assert.equal(this.getNext().length, 3);
}); });
test('Row', function() { test('Row', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block"/>' '<block type="row_block"/>'
), this.workspace); ), this.workspace);
this.clock.runAll(); this.clock.runAll();
@@ -792,7 +792,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getInputs().length, 1); chai.assert.equal(this.getInputs().length, 1);
}); });
test('Multi-Row', function() { test('Multi-Row', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block">' + '<block type="row_block">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <block type="row_block">' + ' <block type="row_block">' +
@@ -816,7 +816,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getInputs().length, 3); chai.assert.equal(this.getInputs().length, 3);
}); });
test('Multi-Row Middle', function() { test('Multi-Row Middle', function() {
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( let block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block">' + '<block type="row_block">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <block type="row_block">' + ' <block type="row_block">' +
@@ -843,7 +843,7 @@ suite('Blocks', function() {
test('Multi-Row Double Collapse', function() { test('Multi-Row Double Collapse', function() {
// Collapse middle -> Collapse top -> // Collapse middle -> Collapse top ->
// Uncollapse top -> Uncollapse middle // Uncollapse top -> Uncollapse middle
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block">' + '<block type="row_block">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <block type="row_block">' + ' <block type="row_block">' +
@@ -876,7 +876,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getInputs().length, 3); chai.assert.equal(this.getInputs().length, 3);
}); });
test('Statement', function() { test('Statement', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block"/>' '<block type="statement_block"/>'
), this.workspace); ), this.workspace);
this.clock.runAll(); this.clock.runAll();
@@ -892,7 +892,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getNext().length, 2); chai.assert.equal(this.getNext().length, 2);
}); });
test('Multi-Statement', function() { test('Multi-Statement', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block">' + '<block type="statement_block">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
' <block type="statement_block">' + ' <block type="statement_block">' +
@@ -917,7 +917,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getNext().length, 6); chai.assert.equal(this.getNext().length, 6);
}); });
test('Multi-Statement Middle', function() { test('Multi-Statement Middle', function() {
let block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( let block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block">' + '<block type="statement_block">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
' <block type="statement_block">' + ' <block type="statement_block">' +
@@ -943,7 +943,7 @@ suite('Blocks', function() {
chai.assert.equal(this.getNext().length, 6); chai.assert.equal(this.getNext().length, 6);
}); });
test('Multi-Statement Double Collapse', function() { test('Multi-Statement Double Collapse', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block">' + '<block type="statement_block">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
' <block type="statement_block">' + ' <block type="statement_block">' +
@@ -979,7 +979,7 @@ suite('Blocks', function() {
}); });
suite('Setting Parent Block', function() { suite('Setting Parent Block', function() {
setup(function() { setup(function() {
this.printBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.printBlock = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="text_print">' + '<block type="text_print">' +
' <value name="TEXT">' + ' <value name="TEXT">' +
' <block type="text_join">' + ' <block type="text_join">' +
@@ -1181,7 +1181,7 @@ suite('Blocks', function() {
}); });
suite('Headless', function() { suite('Headless', function() {
setup(function() { setup(function() {
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.workspace); ), this.workspace);
}); });
@@ -1214,7 +1214,7 @@ suite('Blocks', function() {
comments: true, comments: true,
scrollbars: true, scrollbars: true,
}); });
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.workspace); ), this.workspace);
}); });
@@ -1281,7 +1281,7 @@ suite('Blocks', function() {
suite('Getting/Setting Field (Values)', function() { suite('Getting/Setting Field (Values)', function() {
setup(function() { setup(function() {
this.workspace = Blockly.inject('blocklyDiv'); this.workspace = Blockly.inject('blocklyDiv');
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="text"><field name = "TEXT">test</field></block>' '<block type="text"><field name = "TEXT">test</field></block>'
), this.workspace); ), this.workspace);
}); });
@@ -1349,7 +1349,7 @@ suite('Blocks', function() {
}); });
test('Has Icon', function() { test('Has Icon', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block"/>' '<block type="statement_block"/>'
), this.workspace); ), this.workspace);
block.setCommentText('test text'); block.setCommentText('test text');
@@ -1359,7 +1359,7 @@ suite('Blocks', function() {
chai.assert.isFalse(block.comment.isVisible()); chai.assert.isFalse(block.comment.isVisible());
}); });
test('Child Has Icon', function() { test('Child Has Icon', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block">' + '<block type="statement_block">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
' <block type="statement_block"/>' + ' <block type="statement_block"/>' +
@@ -1374,7 +1374,7 @@ suite('Blocks', function() {
chai.assert.isFalse(childBlock.comment.isVisible()); chai.assert.isFalse(childBlock.comment.isVisible());
}); });
test('Next Block Has Icon', function() { test('Next Block Has Icon', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block">' + '<block type="statement_block">' +
' <next>' + ' <next>' +
' <block type="statement_block"/>' + ' <block type="statement_block"/>' +
@@ -1873,7 +1873,7 @@ suite('Blocks', function() {
suite('Style', function() { suite('Style', function() {
suite('Headless', function() { suite('Headless', function() {
setup(function() { setup(function() {
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.workspace); ), this.workspace);
}); });
@@ -1894,7 +1894,7 @@ suite('Blocks', function() {
suite('Rendered', function() { suite('Rendered', function() {
setup(function() { setup(function() {
this.workspace = Blockly.inject('blocklyDiv', {}); this.workspace = Blockly.inject('blocklyDiv', {});
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.workspace); ), this.workspace);
this.workspace.setTheme(new Blockly.Theme('test', { this.workspace.setTheme(new Blockly.Theme('test', {
@@ -2046,7 +2046,7 @@ suite('Blocks', function() {
// Create mocha test cases for each toString test. // Create mocha test cases for each toString test.
toStringTests.forEach(function(t) { toStringTests.forEach(function(t) {
test(t.name, function() { test(t.name, function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(t.xml), const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(t.xml),
this.workspace); this.workspace);
chai.assert.equal(block.toString(), t.toString); chai.assert.equal(block.toString(), t.toString);
}); });

View File

@@ -771,7 +771,7 @@ suite('Procedures', function() {
suite('xml', function() { suite('xml', function() {
test('callers without defs create new defs', function() { test('callers without defs create new defs', function() {
const callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(` const callBlock = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(`
<block type="procedures_callreturn"> <block type="procedures_callreturn">
<mutation name="do something"/> <mutation name="do something"/>
</block>` </block>`
@@ -783,7 +783,7 @@ suite('Procedures', function() {
}); });
test('callers without mutations create unnamed defs', function() { test('callers without mutations create unnamed defs', function() {
const callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const callBlock = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="procedures_callreturn"></block>' '<block type="procedures_callreturn"></block>'
), this.workspace); ), this.workspace);
this.clock.runAll(); this.clock.runAll();
@@ -793,7 +793,7 @@ suite('Procedures', function() {
}); });
test('callers with missing args create new defs', function() { test('callers with missing args create new defs', function() {
const defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(` const defBlock = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(`
<block type="procedures_defreturn"> <block type="procedures_defreturn">
<field name="NAME">do something</field> <field name="NAME">do something</field>
<mutation> <mutation>
@@ -801,7 +801,7 @@ suite('Procedures', function() {
</mutation> </mutation>
</block> </block>
`), this.workspace); `), this.workspace);
const callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const callBlock = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="procedures_callreturn">' + '<block type="procedures_callreturn">' +
' <mutation name="do something"/>' + ' <mutation name="do something"/>' +
'</block>' '</block>'
@@ -812,7 +812,7 @@ suite('Procedures', function() {
}); });
test('callers with mismatched args create new defs', function() { test('callers with mismatched args create new defs', function() {
const defBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(` const defBlock = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(`
<block type="procedures_defreturn"> <block type="procedures_defreturn">
<field name="NAME">do something</field> <field name="NAME">do something</field>
<mutation> <mutation>
@@ -820,7 +820,7 @@ suite('Procedures', function() {
</mutation> </mutation>
</block> </block>
`), this.workspace); `), this.workspace);
const callBlock = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(` const callBlock = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(`
<block type="procedures_callreturn"> <block type="procedures_callreturn">
<mutation name="do something"> <mutation name="do something">
<arg name="y"></arg> <arg name="y"></arg>
@@ -836,7 +836,7 @@ suite('Procedures', function() {
test.skip( test.skip(
'callers whose defs are deserialized later do not create defs', 'callers whose defs are deserialized later do not create defs',
function() { function() {
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(` Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(`
<xml> <xml>
<block type="procedures_callreturn"> <block type="procedures_callreturn">
<mutation name="do something"> <mutation name="do something">
@@ -1139,7 +1139,7 @@ suite('Procedures', function() {
suite('no name renamed to unnamed', function() { suite('no name renamed to unnamed', function() {
test('defnoreturn and defreturn', function() { test('defnoreturn and defreturn', function() {
const xml = Blockly.Xml.textToDom(` const xml = Blockly.utils.xml.textToDom(`
<xml xmlns="https://developers.google.com/blockly/xml"> <xml xmlns="https://developers.google.com/blockly/xml">
<block type="procedures_defnoreturn"/> <block type="procedures_defnoreturn"/>
<block type="procedures_defreturn"/> <block type="procedures_defreturn"/>
@@ -1152,7 +1152,7 @@ suite('Procedures', function() {
}); });
test('defreturn and defnoreturn', function() { test('defreturn and defnoreturn', function() {
const xml = Blockly.Xml.textToDom(` const xml = Blockly.utils.xml.textToDom(`
<xml xmlns="https://developers.google.com/blockly/xml"> <xml xmlns="https://developers.google.com/blockly/xml">
<block type="procedures_defreturn"/> <block type="procedures_defreturn"/>
<block type="procedures_defnoreturn"/> <block type="procedures_defnoreturn"/>
@@ -1165,7 +1165,7 @@ suite('Procedures', function() {
}); });
test('callreturn (no def in xml)', function() { test('callreturn (no def in xml)', function() {
const xml = Blockly.Xml.textToDom(` const xml = Blockly.utils.xml.textToDom(`
<xml xmlns="https://developers.google.com/blockly/xml"> <xml xmlns="https://developers.google.com/blockly/xml">
<block type="procedures_callreturn"/> <block type="procedures_callreturn"/>
</xml>`); </xml>`);
@@ -1176,7 +1176,7 @@ suite('Procedures', function() {
}); });
test('callnoreturn and callreturn (no def in xml)', function() { test('callnoreturn and callreturn (no def in xml)', function() {
const xml = Blockly.Xml.textToDom(` const xml = Blockly.utils.xml.textToDom(`
<xml xmlns="https://developers.google.com/blockly/xml"> <xml xmlns="https://developers.google.com/blockly/xml">
<block type="procedures_callnoreturn" id="first"/> <block type="procedures_callnoreturn" id="first"/>
<block type="procedures_callreturn" id="second"/> <block type="procedures_callreturn" id="second"/>
@@ -1188,7 +1188,7 @@ suite('Procedures', function() {
}); });
test('callreturn and callnoreturn (no def in xml)', function() { test('callreturn and callnoreturn (no def in xml)', function() {
const xml = Blockly.Xml.textToDom(` const xml = Blockly.utils.xml.textToDom(`
<xml xmlns="https://developers.google.com/blockly/xml"> <xml xmlns="https://developers.google.com/blockly/xml">
<block type="procedures_callreturn"/> <block type="procedures_callreturn"/>
<block type="procedures_callnoreturn"/> <block type="procedures_callnoreturn"/>
@@ -1579,7 +1579,7 @@ suite('Procedures', function() {
chai.assert.isFalse(this.defBlock.hasStatements_); chai.assert.isFalse(this.defBlock.hasStatements_);
}); });
test('Saving Statements', function() { test('Saving Statements', function() {
const blockXml = Blockly.Xml.textToDom( const blockXml = Blockly.utils.xml.textToDom(
'<block type="procedures_defreturn">' + '<block type="procedures_defreturn">' +
' <statement name="STACK">' + ' <statement name="STACK">' +
' <block type="procedures_ifreturn" id="test"></block>' + ' <block type="procedures_ifreturn" id="test"></block>' +

View File

@@ -34,7 +34,7 @@ suite('Comment Deserialization', function() {
scrollbars: true, scrollbars: true,
trashcan: true, trashcan: true,
maxTrashcanContents: Infinity, maxTrashcanContents: Infinity,
toolbox: Blockly.Xml.textToDom(toolboxXml), toolbox: Blockly.utils.xml.textToDom(toolboxXml),
}); });
}); });
teardown(function() { teardown(function() {
@@ -46,7 +46,7 @@ suite('Comment Deserialization', function() {
this.workspace.clear(); this.workspace.clear();
}); });
function createBlock(workspace) { function createBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), workspace); ), workspace);
block.setCommentText('test text'); block.setCommentText('test text');

View File

@@ -25,7 +25,7 @@ suite('Comments', function() {
comments: true, comments: true,
scrollbars: true, scrollbars: true,
}); });
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.workspace); ), this.workspace);
this.comment = new Blockly.Comment(this.block); this.comment = new Blockly.Comment(this.block);

View File

@@ -346,7 +346,7 @@ suite('Connection checker', function() {
setup(function() { setup(function() {
this.workspace = Blockly.inject('blocklyDiv'); this.workspace = Blockly.inject('blocklyDiv');
// Load in three blocks: A and B are connected (next/prev); B is unmovable. // Load in three blocks: A and B are connected (next/prev); B is unmovable.
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(`<xml xmlns="https://developers.google.com/blockly/xml"> Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(`<xml xmlns="https://developers.google.com/blockly/xml">
<block type="text_print" id="A" x="-76" y="-112"> <block type="text_print" id="A" x="-76" y="-112">
<next> <next>
<block type="text_print" id="B" movable="false"> <block type="text_print" id="B" movable="false">
@@ -402,7 +402,7 @@ suite('Connection checker', function() {
setup(function() { setup(function() {
this.workspace = Blockly.inject('blocklyDiv'); this.workspace = Blockly.inject('blocklyDiv');
// Load 3 blocks: A and B are connected (input/output); B is unmovable. // Load 3 blocks: A and B are connected (input/output); B is unmovable.
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(`<xml xmlns="https://developers.google.com/blockly/xml"> Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(`<xml xmlns="https://developers.google.com/blockly/xml">
<block type="test_basic_row" id="A" x="38" y="37"> <block type="test_basic_row" id="A" x="38" y="37">
<value name="INPUT"> <value name="INPUT">
<block type="test_basic_row" id="B" movable="false"></block> <block type="test_basic_row" id="B" movable="false"></block>

View File

@@ -109,21 +109,21 @@ suite('Connection', function() {
suite('Add - No Block Connected', function() { suite('Add - No Block Connected', function() {
// These are defined separately in each suite. // These are defined separately in each suite.
function createRowBlock(workspace) { function createRowBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block" id="id0"/>' '<block type="row_block" id="id0"/>'
), workspace); ), workspace);
return block; return block;
} }
function createStatementBlock(workspace) { function createStatementBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block" id="id0"/>' '<block type="statement_block" id="id0"/>'
), workspace); ), workspace);
return block; return block;
} }
function createStackBlock(workspace) { function createStackBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="stack_block" id="id0"/>' '<block type="stack_block" id="id0"/>'
), workspace); ), workspace);
return block; return block;
@@ -131,7 +131,7 @@ suite('Connection', function() {
test('Value', function() { test('Value', function() {
const parent = createRowBlock(this.workspace); const parent = createRowBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="row_block" id="id1"/>' '<shadow type="row_block" id="id1"/>'
); );
parent.getInput('INPUT').connection.setShadowDom(xml); parent.getInput('INPUT').connection.setShadowDom(xml);
@@ -161,7 +161,7 @@ suite('Connection', function() {
test('Multiple Value', function() { test('Multiple Value', function() {
const parent = createRowBlock(this.workspace); const parent = createRowBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="row_block" id="id1">' + '<shadow type="row_block" id="id1">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <shadow type="row_block" id="id2"/>' + ' <shadow type="row_block" id="id2"/>' +
@@ -209,7 +209,7 @@ suite('Connection', function() {
test('Statement', function() { test('Statement', function() {
const parent = createStatementBlock(this.workspace); const parent = createStatementBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="statement_block" id="id1"/>' '<shadow type="statement_block" id="id1"/>'
); );
parent.getInput('NAME').connection.setShadowDom(xml); parent.getInput('NAME').connection.setShadowDom(xml);
@@ -239,7 +239,7 @@ suite('Connection', function() {
test('Multiple Statement', function() { test('Multiple Statement', function() {
const parent = createStatementBlock(this.workspace); const parent = createStatementBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="statement_block" id="id1">' + '<shadow type="statement_block" id="id1">' +
' <statement name="NAME">' + ' <statement name="NAME">' +
' <shadow type="statement_block" id="id2"/>' + ' <shadow type="statement_block" id="id2"/>' +
@@ -287,7 +287,7 @@ suite('Connection', function() {
test('Next', function() { test('Next', function() {
const parent = createStackBlock(this.workspace); const parent = createStackBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="id1"/>' '<shadow type="stack_block" id="id1"/>'
); );
parent.nextConnection.setShadowDom(xml); parent.nextConnection.setShadowDom(xml);
@@ -315,7 +315,7 @@ suite('Connection', function() {
test('Multiple Next', function() { test('Multiple Next', function() {
const parent = createStackBlock(this.workspace); const parent = createStackBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="id1">' + '<shadow type="stack_block" id="id1">' +
' <next>' + ' <next>' +
' <shadow type="stack_block" id="id2"/>' + ' <shadow type="stack_block" id="id2"/>' +
@@ -360,7 +360,7 @@ suite('Connection', function() {
suite('Add - With Block Connected', function() { suite('Add - With Block Connected', function() {
// These are defined separately in each suite. // These are defined separately in each suite.
function createRowBlocks(workspace) { function createRowBlocks(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block" id="id0">' + '<block type="row_block" id="id0">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <block type="row_block" id="idA"/>' + ' <block type="row_block" id="idA"/>' +
@@ -371,7 +371,7 @@ suite('Connection', function() {
} }
function createStatementBlocks(workspace) { function createStatementBlocks(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block" id="id0">' + '<block type="statement_block" id="id0">' +
' <statement name="NAME">' + ' <statement name="NAME">' +
' <block type="statement_block" id="idA"/>' + ' <block type="statement_block" id="idA"/>' +
@@ -382,7 +382,7 @@ suite('Connection', function() {
} }
function createStackBlocks(workspace) { function createStackBlocks(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="stack_block" id="id0">' + '<block type="stack_block" id="id0">' +
' <next>' + ' <next>' +
' <block type="stack_block" id="idA"/>' + ' <block type="stack_block" id="idA"/>' +
@@ -394,7 +394,7 @@ suite('Connection', function() {
test('Value', function() { test('Value', function() {
const parent = createRowBlocks(this.workspace); const parent = createRowBlocks(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="row_block" id="id1"/>' '<shadow type="row_block" id="id1"/>'
); );
parent.getInput('INPUT').connection.setShadowDom(xml); parent.getInput('INPUT').connection.setShadowDom(xml);
@@ -426,7 +426,7 @@ suite('Connection', function() {
test('Multiple Value', function() { test('Multiple Value', function() {
const parent = createRowBlocks(this.workspace); const parent = createRowBlocks(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="row_block" id="id1">' + '<shadow type="row_block" id="id1">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <shadow type="row_block" id="id2"/>' + ' <shadow type="row_block" id="id2"/>' +
@@ -477,7 +477,7 @@ suite('Connection', function() {
test('Statement', function() { test('Statement', function() {
const parent = createStatementBlocks(this.workspace); const parent = createStatementBlocks(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="statement_block" id="id1"/>' '<shadow type="statement_block" id="id1"/>'
); );
parent.getInput('NAME').connection.setShadowDom(xml); parent.getInput('NAME').connection.setShadowDom(xml);
@@ -509,7 +509,7 @@ suite('Connection', function() {
test('Multiple Statement', function() { test('Multiple Statement', function() {
const parent = createStatementBlocks(this.workspace); const parent = createStatementBlocks(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="statement_block" id="id1">' + '<shadow type="statement_block" id="id1">' +
' <statement name="NAME">' + ' <statement name="NAME">' +
' <shadow type="statement_block" id="id2"/>' + ' <shadow type="statement_block" id="id2"/>' +
@@ -561,7 +561,7 @@ suite('Connection', function() {
test('Next', function() { test('Next', function() {
const parent = createStackBlocks(this.workspace); const parent = createStackBlocks(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="id1"/>' '<shadow type="stack_block" id="id1"/>'
); );
parent.nextConnection.setShadowDom(xml); parent.nextConnection.setShadowDom(xml);
@@ -591,7 +591,7 @@ suite('Connection', function() {
test('Multiple Next', function() { test('Multiple Next', function() {
const parent = createStackBlocks(this.workspace); const parent = createStackBlocks(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="id1">' + '<shadow type="stack_block" id="id1">' +
' <next>' + ' <next>' +
' <shadow type="stack_block" id="id2"/>' + ' <shadow type="stack_block" id="id2"/>' +
@@ -639,21 +639,21 @@ suite('Connection', function() {
suite('Add - With Shadow Connected', function() { suite('Add - With Shadow Connected', function() {
// These are defined separately in each suite. // These are defined separately in each suite.
function createRowBlock(workspace) { function createRowBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block" id="id0"/>' '<block type="row_block" id="id0"/>'
), workspace); ), workspace);
return block; return block;
} }
function createStatementBlock(workspace) { function createStatementBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block" id="id0"/>' '<block type="statement_block" id="id0"/>'
), workspace); ), workspace);
return block; return block;
} }
function createStackBlock(workspace) { function createStackBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="stack_block" id="id0"/>' '<block type="stack_block" id="id0"/>'
), workspace); ), workspace);
return block; return block;
@@ -661,13 +661,13 @@ suite('Connection', function() {
test('Value', function() { test('Value', function() {
const parent = createRowBlock(this.workspace); const parent = createRowBlock(this.workspace);
const xml1 = Blockly.Xml.textToDom( const xml1 = Blockly.utils.xml.textToDom(
'<shadow type="row_block" id="1"/>' '<shadow type="row_block" id="1"/>'
); );
parent.getInput('INPUT').connection.setShadowDom(xml1); parent.getInput('INPUT').connection.setShadowDom(xml1);
assertInputHasBlock(parent, 'INPUT', true, '1'); assertInputHasBlock(parent, 'INPUT', true, '1');
const xml2 = const xml2 =
Blockly.Xml.textToDom('<shadow type="row_block" id="2"/>'); Blockly.utils.xml.textToDom('<shadow type="row_block" id="2"/>');
parent.getInput('INPUT').connection.setShadowDom(xml2); parent.getInput('INPUT').connection.setShadowDom(xml2);
assertInputHasBlock(parent, 'INPUT', true, '2'); assertInputHasBlock(parent, 'INPUT', true, '2');
assertSerialization( assertSerialization(
@@ -695,7 +695,7 @@ suite('Connection', function() {
test('Multiple Value', function() { test('Multiple Value', function() {
const parent = createRowBlock(this.workspace); const parent = createRowBlock(this.workspace);
const xml1 = Blockly.Xml.textToDom( const xml1 = Blockly.utils.xml.textToDom(
'<shadow type="row_block" id="1">' + '<shadow type="row_block" id="1">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <shadow type="row_block" id="a"/>' + ' <shadow type="row_block" id="a"/>' +
@@ -705,7 +705,7 @@ suite('Connection', function() {
assertInputHasBlock(parent, 'INPUT', true, '1'); assertInputHasBlock(parent, 'INPUT', true, '1');
assertInputHasBlock( assertInputHasBlock(
parent.getInputTargetBlock('INPUT'), 'INPUT', true, 'a'); parent.getInputTargetBlock('INPUT'), 'INPUT', true, 'a');
const xml2 = Blockly.Xml.textToDom( const xml2 = Blockly.utils.xml.textToDom(
'<shadow type="row_block" id="2">' + '<shadow type="row_block" id="2">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <shadow type="row_block" id="b"/>' + ' <shadow type="row_block" id="b"/>' +
@@ -752,11 +752,11 @@ suite('Connection', function() {
test('Statement', function() { test('Statement', function() {
const parent = createStatementBlock(this.workspace); const parent = createStatementBlock(this.workspace);
const xml1 = Blockly.Xml.textToDom( const xml1 = Blockly.utils.xml.textToDom(
'<shadow type="statement_block" id="1"/>'); '<shadow type="statement_block" id="1"/>');
parent.getInput('NAME').connection.setShadowDom(xml1); parent.getInput('NAME').connection.setShadowDom(xml1);
assertInputHasBlock(parent, 'NAME', true, '1'); assertInputHasBlock(parent, 'NAME', true, '1');
const xml2 = Blockly.Xml.textToDom( const xml2 = Blockly.utils.xml.textToDom(
'<shadow type="statement_block" id="2"/>'); '<shadow type="statement_block" id="2"/>');
parent.getInput('NAME').connection.setShadowDom(xml2); parent.getInput('NAME').connection.setShadowDom(xml2);
assertInputHasBlock(parent, 'NAME', true, '2'); assertInputHasBlock(parent, 'NAME', true, '2');
@@ -785,7 +785,7 @@ suite('Connection', function() {
test('Multiple Statement', function() { test('Multiple Statement', function() {
const parent = createStatementBlock(this.workspace); const parent = createStatementBlock(this.workspace);
const xml1 = Blockly.Xml.textToDom( const xml1 = Blockly.utils.xml.textToDom(
'<shadow type="statement_block" id="1">' + '<shadow type="statement_block" id="1">' +
' <statement name="NAME">' + ' <statement name="NAME">' +
' <shadow type="statement_block" id="a"/>' + ' <shadow type="statement_block" id="a"/>' +
@@ -795,7 +795,7 @@ suite('Connection', function() {
assertInputHasBlock(parent, 'NAME', true, '1'); assertInputHasBlock(parent, 'NAME', true, '1');
assertInputHasBlock( assertInputHasBlock(
parent.getInputTargetBlock('NAME'), 'NAME', true, 'a'); parent.getInputTargetBlock('NAME'), 'NAME', true, 'a');
const xml2 = Blockly.Xml.textToDom( const xml2 = Blockly.utils.xml.textToDom(
'<shadow type="statement_block" id="2">' + '<shadow type="statement_block" id="2">' +
' <statement name="NAME">' + ' <statement name="NAME">' +
' <shadow type="statement_block" id="b"/>' + ' <shadow type="statement_block" id="b"/>' +
@@ -843,11 +843,11 @@ suite('Connection', function() {
test('Next', function() { test('Next', function() {
const parent = createStackBlock(this.workspace); const parent = createStackBlock(this.workspace);
const xml1 = const xml1 =
Blockly.Xml.textToDom('<shadow type="stack_block" id="1"/>'); Blockly.utils.xml.textToDom('<shadow type="stack_block" id="1"/>');
parent.nextConnection.setShadowDom(xml1); parent.nextConnection.setShadowDom(xml1);
assertNextHasBlock(parent, true, '1'); assertNextHasBlock(parent, true, '1');
const xml2 = const xml2 =
Blockly.Xml.textToDom('<shadow type="stack_block" id="2"/>'); Blockly.utils.xml.textToDom('<shadow type="stack_block" id="2"/>');
parent.nextConnection.setShadowDom(xml2); parent.nextConnection.setShadowDom(xml2);
assertNextHasBlock(parent, true, '2'); assertNextHasBlock(parent, true, '2');
assertSerialization( assertSerialization(
@@ -873,7 +873,7 @@ suite('Connection', function() {
test('Multiple Next', function() { test('Multiple Next', function() {
const parent = createStackBlock(this.workspace); const parent = createStackBlock(this.workspace);
const xml1 = Blockly.Xml.textToDom( const xml1 = Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="1">' + '<shadow type="stack_block" id="1">' +
' <next>' + ' <next>' +
' <shadow type="stack_block" id="a"/>' + ' <shadow type="stack_block" id="a"/>' +
@@ -882,7 +882,7 @@ suite('Connection', function() {
parent.nextConnection.setShadowDom(xml1); parent.nextConnection.setShadowDom(xml1);
assertNextHasBlock(parent, true, '1'); assertNextHasBlock(parent, true, '1');
assertNextHasBlock(parent.getNextBlock(), true, 'a'); assertNextHasBlock(parent.getNextBlock(), true, 'a');
const xml2 = Blockly.Xml.textToDom( const xml2 = Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="2">' + '<shadow type="stack_block" id="2">' +
' <next>' + ' <next>' +
' <shadow type="stack_block" id="b"/>' + ' <shadow type="stack_block" id="b"/>' +
@@ -926,7 +926,7 @@ suite('Connection', function() {
suite('Remove - No Block Connected', function() { suite('Remove - No Block Connected', function() {
// These are defined separately in each suite. // These are defined separately in each suite.
function createRowBlock(workspace) { function createRowBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block" id="id0">' + '<block type="row_block" id="id0">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <shadow type="row_block" id="idA"/>' + ' <shadow type="row_block" id="idA"/>' +
@@ -937,7 +937,7 @@ suite('Connection', function() {
} }
function createStatementBlock(workspace) { function createStatementBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block" id="id0">' + '<block type="statement_block" id="id0">' +
' <statement name="NAME">' + ' <statement name="NAME">' +
' <shadow type="statement_block" id="idA"/>' + ' <shadow type="statement_block" id="idA"/>' +
@@ -948,7 +948,7 @@ suite('Connection', function() {
} }
function createStackBlock(workspace) { function createStackBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="stack_block" id="id0">' + '<block type="stack_block" id="id0">' +
' <next>' + ' <next>' +
' <shadow type="stack_block" id="idA"/>' + ' <shadow type="stack_block" id="idA"/>' +
@@ -1010,7 +1010,7 @@ suite('Connection', function() {
suite('Remove - Block Connected', function() { suite('Remove - Block Connected', function() {
// These are defined separately in each suite. // These are defined separately in each suite.
function createRowBlock(workspace) { function createRowBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block" id="id0">' + '<block type="row_block" id="id0">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <shadow type="row_block" id="idA"/>' + ' <shadow type="row_block" id="idA"/>' +
@@ -1022,7 +1022,7 @@ suite('Connection', function() {
} }
function createStatementBlock(workspace) { function createStatementBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block" id="id0">' + '<block type="statement_block" id="id0">' +
' <statement name="NAME">' + ' <statement name="NAME">' +
' <shadow type="statement_block" id="idA"/>' + ' <shadow type="statement_block" id="idA"/>' +
@@ -1034,7 +1034,7 @@ suite('Connection', function() {
} }
function createStackBlock(workspace) { function createStackBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="stack_block" id="id0">' + '<block type="stack_block" id="id0">' +
' <next>' + ' <next>' +
' <shadow type="stack_block" id="idA"/>' + ' <shadow type="stack_block" id="idA"/>' +
@@ -1103,21 +1103,21 @@ suite('Connection', function() {
suite('Add - Connect & Disconnect - Remove', function() { suite('Add - Connect & Disconnect - Remove', function() {
// These are defined separately in each suite. // These are defined separately in each suite.
function createRowBlock(workspace) { function createRowBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="row_block"/>' '<block type="row_block"/>'
), workspace); ), workspace);
return block; return block;
} }
function createStatementBlock(workspace) { function createStatementBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="statement_block"/>' '<block type="statement_block"/>'
), workspace); ), workspace);
return block; return block;
} }
function createStackBlock(workspace) { function createStackBlock(workspace) {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="stack_block"/>' '<block type="stack_block"/>'
), workspace); ), workspace);
return block; return block;
@@ -1125,7 +1125,7 @@ suite('Connection', function() {
test('Value', function() { test('Value', function() {
const parent = createRowBlock(this.workspace); const parent = createRowBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="row_block"/>' '<shadow type="row_block"/>'
); );
parent.getInput('INPUT').connection.setShadowDom(xml); parent.getInput('INPUT').connection.setShadowDom(xml);
@@ -1141,7 +1141,7 @@ suite('Connection', function() {
test('Multiple Value', function() { test('Multiple Value', function() {
const parent = createRowBlock(this.workspace); const parent = createRowBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="row_block">' + '<shadow type="row_block">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
' <shadow type="row_block"/>' + ' <shadow type="row_block"/>' +
@@ -1165,7 +1165,7 @@ suite('Connection', function() {
test('Statement', function() { test('Statement', function() {
const parent = createStatementBlock(this.workspace); const parent = createStatementBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="statement_block"/>' '<shadow type="statement_block"/>'
); );
parent.getInput('NAME').connection.setShadowDom(xml); parent.getInput('NAME').connection.setShadowDom(xml);
@@ -1182,7 +1182,7 @@ suite('Connection', function() {
test('Multiple Statement', function() { test('Multiple Statement', function() {
const parent = createStatementBlock(this.workspace); const parent = createStatementBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="statement_block">' + '<shadow type="statement_block">' +
' <statement name="NAME">' + ' <statement name="NAME">' +
' <shadow type="statement_block"/>' + ' <shadow type="statement_block"/>' +
@@ -1207,7 +1207,7 @@ suite('Connection', function() {
test('Next', function() { test('Next', function() {
const parent = createStackBlock(this.workspace); const parent = createStackBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
parent.nextConnection.setShadowDom(xml); parent.nextConnection.setShadowDom(xml);
@@ -1223,7 +1223,7 @@ suite('Connection', function() {
test('Multiple Next', function() { test('Multiple Next', function() {
const parent = createStackBlock(this.workspace); const parent = createStackBlock(this.workspace);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="parent">' + '<shadow type="stack_block" id="parent">' +
' <next>' + ' <next>' +
' <shadow type="stack_block" id="child"/>' + ' <shadow type="stack_block" id="child"/>' +
@@ -1248,28 +1248,28 @@ suite('Connection', function() {
test('Attach to output', function() { test('Attach to output', function() {
const block = this.workspace.newBlock('row_block'); const block = this.workspace.newBlock('row_block');
chai.assert.throws(() => chai.assert.throws(() =>
block.outputConnection.setShadowDom(Blockly.Xml.textToDom( block.outputConnection.setShadowDom(Blockly.utils.xml.textToDom(
'<block type="row_block">'))); '<block type="row_block">')));
}); });
test('Attach to previous', function() { test('Attach to previous', function() {
const block = this.workspace.newBlock('stack_block'); const block = this.workspace.newBlock('stack_block');
chai.assert.throws(() => chai.assert.throws(() =>
block.previousConnection.setShadowDom(Blockly.Xml.textToDom( block.previousConnection.setShadowDom(Blockly.utils.xml.textToDom(
'<block type="stack_block">'))); '<block type="stack_block">')));
}); });
test('Missing output', function() { test('Missing output', function() {
const block = this.workspace.newBlock('row_block'); const block = this.workspace.newBlock('row_block');
chai.assert.throws(() => chai.assert.throws(() =>
block.outputConnection.setShadowDom(Blockly.Xml.textToDom( block.outputConnection.setShadowDom(Blockly.utils.xml.textToDom(
'<block type="stack_block">'))); '<block type="stack_block">')));
}); });
test('Missing previous', function() { test('Missing previous', function() {
const block = this.workspace.newBlock('stack_block'); const block = this.workspace.newBlock('stack_block');
chai.assert.throws(() => chai.assert.throws(() =>
block.previousConnection.setShadowDom(Blockly.Xml.textToDom( block.previousConnection.setShadowDom(Blockly.utils.xml.textToDom(
'<block type="row_block">'))); '<block type="row_block">')));
}); });
@@ -1277,7 +1277,7 @@ suite('Connection', function() {
const block = this.workspace.newBlock('logic_operation'); const block = this.workspace.newBlock('logic_operation');
chai.assert.throws(() => chai.assert.throws(() =>
block.getInput('A').connection.setShadowDom( block.getInput('A').connection.setShadowDom(
Blockly.Xml.textToDom('<block type="stack_block">'))); Blockly.utils.xml.textToDom('<block type="stack_block">')));
}); });
test('Invalid connection checks, previous', function() { test('Invalid connection checks, previous', function() {
@@ -1289,7 +1289,7 @@ suite('Connection', function() {
}]); }]);
const block = this.workspace.newBlock('stack_checks_block'); const block = this.workspace.newBlock('stack_checks_block');
chai.assert.throws(() => chai.assert.throws(() =>
block.nextConnection.setShadowDom(Blockly.Xml.textToDom( block.nextConnection.setShadowDom(Blockly.utils.xml.textToDom(
'<block type="stack_checks_block">'))); '<block type="stack_checks_block">')));
}); });
}); });
@@ -2788,7 +2788,7 @@ suite('Connection', function() {
test('Value', function() { test('Value', function() {
const newParent = this.workspace.newBlock('row_block'); const newParent = this.workspace.newBlock('row_block');
const child = this.workspace.newBlock('row_block'); const child = this.workspace.newBlock('row_block');
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="row_block"/>' '<shadow type="row_block"/>'
); );
newParent.getInput('INPUT').connection.setShadowDom(xml); newParent.getInput('INPUT').connection.setShadowDom(xml);
@@ -2803,7 +2803,7 @@ suite('Connection', function() {
test('Statement', function() { test('Statement', function() {
const newParent = this.workspace.newBlock('statement_block'); const newParent = this.workspace.newBlock('statement_block');
const child = this.workspace.newBlock('stack_block'); const child = this.workspace.newBlock('stack_block');
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
newParent.getInput('NAME').connection.setShadowDom(xml); newParent.getInput('NAME').connection.setShadowDom(xml);
@@ -2821,7 +2821,7 @@ suite('Connection', function() {
test('Next', function() { test('Next', function() {
const newParent = this.workspace.newBlock('stack_block'); const newParent = this.workspace.newBlock('stack_block');
const child = this.workspace.newBlock('stack_block'); const child = this.workspace.newBlock('stack_block');
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
newParent.nextConnection.setShadowDom(xml); newParent.nextConnection.setShadowDom(xml);
@@ -2838,7 +2838,7 @@ suite('Connection', function() {
test('Value', function() { test('Value', function() {
const newParent = this.workspace.newBlock('row_block'); const newParent = this.workspace.newBlock('row_block');
const child = this.workspace.newBlock('row_block'); const child = this.workspace.newBlock('row_block');
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="row_block"/>' '<shadow type="row_block"/>'
); );
newParent.getInput('INPUT').connection.setShadowDom(xml); newParent.getInput('INPUT').connection.setShadowDom(xml);
@@ -2856,7 +2856,7 @@ suite('Connection', function() {
test('Statement', function() { test('Statement', function() {
const newParent = this.workspace.newBlock('statement_block'); const newParent = this.workspace.newBlock('statement_block');
const child = this.workspace.newBlock('stack_block'); const child = this.workspace.newBlock('stack_block');
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
newParent.getInput('NAME').connection.setShadowDom(xml); newParent.getInput('NAME').connection.setShadowDom(xml);
@@ -2876,7 +2876,7 @@ suite('Connection', function() {
test('Next', function() { test('Next', function() {
const newParent = this.workspace.newBlock('stack_block'); const newParent = this.workspace.newBlock('stack_block');
const child = this.workspace.newBlock('stack_block'); const child = this.workspace.newBlock('stack_block');
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
newParent.nextConnection.setShadowDom(xml); newParent.nextConnection.setShadowDom(xml);
@@ -3054,10 +3054,10 @@ suite('Connection', function() {
parent.getInput('INPUT').connection parent.getInput('INPUT').connection
.connect(oldChild.outputConnection); .connect(oldChild.outputConnection);
newChild.getInput('INPUT').connection.setShadowDom( newChild.getInput('INPUT').connection.setShadowDom(
Blockly.Xml.textToDom('<xml><shadow type="row_block"/></xml>') Blockly.utils.xml.textToDom('<xml><shadow type="row_block"/></xml>')
.firstChild); .firstChild);
newChild.getInput('INPUT2').connection.setShadowDom( newChild.getInput('INPUT2').connection.setShadowDom(
Blockly.Xml.textToDom('<xml><shadow type="row_block"/></xml>') Blockly.utils.xml.textToDom('<xml><shadow type="row_block"/></xml>')
.firstChild); .firstChild);
parent.getInput('INPUT').connection parent.getInput('INPUT').connection
@@ -3086,10 +3086,10 @@ suite('Connection', function() {
newChild.getInput('INPUT2').connection newChild.getInput('INPUT2').connection
.connect(childY.outputConnection); .connect(childY.outputConnection);
childX.getInput('INPUT').connection.setShadowDom( childX.getInput('INPUT').connection.setShadowDom(
Blockly.Xml.textToDom('<xml><shadow type="row_block"/></xml>') Blockly.utils.xml.textToDom('<xml><shadow type="row_block"/></xml>')
.firstChild); .firstChild);
childY.getInput('INPUT').connection.setShadowDom( childY.getInput('INPUT').connection.setShadowDom(
Blockly.Xml.textToDom('<xml><shadow type="row_block"/></xml>') Blockly.utils.xml.textToDom('<xml><shadow type="row_block"/></xml>')
.firstChild); .firstChild);
parent.getInput('INPUT').connection parent.getInput('INPUT').connection
@@ -3115,7 +3115,7 @@ suite('Connection', function() {
newChild.getInput('INPUT').connection newChild.getInput('INPUT').connection
.connect(otherChild.outputConnection); .connect(otherChild.outputConnection);
newChild.getInput('INPUT2').connection.setShadowDom( newChild.getInput('INPUT2').connection.setShadowDom(
Blockly.Xml.textToDom('<xml><shadow type="row_block"/></xml>') Blockly.utils.xml.textToDom('<xml><shadow type="row_block"/></xml>')
.firstChild); .firstChild);
parent.getInput('INPUT').connection parent.getInput('INPUT').connection
@@ -3161,7 +3161,7 @@ suite('Connection', function() {
parent.getInput('INPUT').connection parent.getInput('INPUT').connection
.connect(oldChild.outputConnection); .connect(oldChild.outputConnection);
newChild.getInput('INPUT').connection.setShadowDom( newChild.getInput('INPUT').connection.setShadowDom(
Blockly.Xml.textToDom('<xml><shadow type="row_block"/></xml>') Blockly.utils.xml.textToDom('<xml><shadow type="row_block"/></xml>')
.firstChild); .firstChild);
parent.getInput('INPUT').connection parent.getInput('INPUT').connection
@@ -3268,7 +3268,7 @@ suite('Connection', function() {
const newChild = this.workspace.newBlock('stack_block'); const newChild = this.workspace.newBlock('stack_block');
parent.getInput('NAME').connection parent.getInput('NAME').connection
.connect(oldChild.previousConnection); .connect(oldChild.previousConnection);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
newChild.nextConnection.setShadowDom(xml); newChild.nextConnection.setShadowDom(xml);
@@ -3293,7 +3293,7 @@ suite('Connection', function() {
parent.getInput('NAME').connection parent.getInput('NAME').connection
.connect(oldChild.previousConnection); .connect(oldChild.previousConnection);
newChild1.nextConnection.connect(newChild2.previousConnection); newChild1.nextConnection.connect(newChild2.previousConnection);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
newChild2.nextConnection.setShadowDom(xml); newChild2.nextConnection.setShadowDom(xml);
@@ -3316,7 +3316,7 @@ suite('Connection', function() {
const newChild = this.workspace.newBlock('stack_block_1to2'); const newChild = this.workspace.newBlock('stack_block_1to2');
parent.getInput('NAME').connection parent.getInput('NAME').connection
.connect(oldChild.previousConnection); .connect(oldChild.previousConnection);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block_2to1"/>' '<shadow type="stack_block_2to1"/>'
); );
newChild.nextConnection.setShadowDom(xml); newChild.nextConnection.setShadowDom(xml);
@@ -3409,7 +3409,7 @@ suite('Connection', function() {
const oldChild = this.workspace.newBlock('stack_block'); const oldChild = this.workspace.newBlock('stack_block');
const newChild = this.workspace.newBlock('stack_block'); const newChild = this.workspace.newBlock('stack_block');
parent.nextConnection.connect(oldChild.previousConnection); parent.nextConnection.connect(oldChild.previousConnection);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
newChild.nextConnection.setShadowDom(xml); newChild.nextConnection.setShadowDom(xml);
@@ -3430,7 +3430,7 @@ suite('Connection', function() {
const newChild2 = this.workspace.newBlock('stack_block_2to1'); const newChild2 = this.workspace.newBlock('stack_block_2to1');
parent.nextConnection.connect(oldChild.previousConnection); parent.nextConnection.connect(oldChild.previousConnection);
newChild1.nextConnection.connect(newChild2.previousConnection); newChild1.nextConnection.connect(newChild2.previousConnection);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block"/>' '<shadow type="stack_block"/>'
); );
newChild2.nextConnection.setShadowDom(xml); newChild2.nextConnection.setShadowDom(xml);
@@ -3449,7 +3449,7 @@ suite('Connection', function() {
const oldChild = this.workspace.newBlock('stack_block'); const oldChild = this.workspace.newBlock('stack_block');
const newChild = this.workspace.newBlock('stack_block_1to2'); const newChild = this.workspace.newBlock('stack_block_1to2');
parent.nextConnection.connect(oldChild.previousConnection); parent.nextConnection.connect(oldChild.previousConnection);
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<shadow type="stack_block_2to1"/>' '<shadow type="stack_block_2to1"/>'
); );
newChild.nextConnection.setShadowDom(xml); newChild.nextConnection.setShadowDom(xml);

View File

@@ -35,7 +35,7 @@ suite('Block Change Event', function() {
test('Undo', function() { test('Undo', function() {
const block = this.workspace.newBlock('xml_block', 'block_id'); const block = this.workspace.newBlock('xml_block', 'block_id');
block.domToMutation( block.domToMutation(
Blockly.Xml.textToDom('<mutation hasInput="true"/>')); Blockly.utils.xml.textToDom('<mutation hasInput="true"/>'));
const blockChange = new Blockly.Events.BlockChange( const blockChange = new Blockly.Events.BlockChange(
block, 'mutation', null, '', '<mutation hasInput="true"/>'); block, 'mutation', null, '', '<mutation hasInput="true"/>');
blockChange.run(false); blockChange.run(false);
@@ -85,7 +85,7 @@ suite('Block Change Event', function() {
test('events round-trip through JSON', function() { test('events round-trip through JSON', function() {
const block = this.workspace.newBlock('xml_block', 'block_id'); const block = this.workspace.newBlock('xml_block', 'block_id');
block.domToMutation( block.domToMutation(
Blockly.Xml.textToDom('<mutation hasInput="true"/>')); Blockly.utils.xml.textToDom('<mutation hasInput="true"/>'));
const origEvent = new Blockly.Events.BlockChange( const origEvent = new Blockly.Events.BlockChange(
block, 'mutation', null, '', '<mutation hasInput="true"/>'); block, 'mutation', null, '', '<mutation hasInput="true"/>');

View File

@@ -1047,7 +1047,7 @@ suite('Events', function() {
test('New block new var xml', function() { test('New block new var xml', function() {
const TEST_GROUP_ID = 'test_group_id'; const TEST_GROUP_ID = 'test_group_id';
const genUidStub = createGenUidStubWithReturns(TEST_GROUP_ID); const genUidStub = createGenUidStubWithReturns(TEST_GROUP_ID);
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="field_variable_test_block" id="test_block_id">' + ' <block type="field_variable_test_block" id="test_block_id">' +
' <field name="VAR" id="test_var_id">name1</field>' + ' <field name="VAR" id="test_var_id">name1</field>' +

View File

@@ -315,21 +315,21 @@ suite('Abstract Fields', function() {
test('No implementations', function() { test('No implementations', function() {
const field = new DefaultSerializationField(''); const field = new DefaultSerializationField('');
field.fromXml( field.fromXml(
Blockly.Xml.textToDom('<field name="">test value</field>')); Blockly.utils.xml.textToDom('<field name="">test value</field>'));
chai.assert.equal(field.getValue(), 'test value'); chai.assert.equal(field.getValue(), 'test value');
}); });
test('Xml implementations', function() { test('Xml implementations', function() {
const field = new CustomXmlField(''); const field = new CustomXmlField('');
field.fromXml( field.fromXml(
Blockly.Xml.textToDom('<field name="">custom value</field>')); Blockly.utils.xml.textToDom('<field name="">custom value</field>'));
chai.assert.equal(field.someProperty, 'custom value'); chai.assert.equal(field.someProperty, 'custom value');
}); });
test('Xml super implementation', function() { test('Xml super implementation', function() {
const field = new CustomXmlCallSuperField(''); const field = new CustomXmlCallSuperField('');
field.fromXml( field.fromXml(
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<field attribute="custom value" name="">test value</field>' '<field attribute="custom value" name="">test value</field>'
) )
); );
@@ -340,7 +340,7 @@ suite('Abstract Fields', function() {
test('XML andd JSO implementations', function() { test('XML andd JSO implementations', function() {
const field = new CustomXmlAndJsoField(''); const field = new CustomXmlAndJsoField('');
field.fromXml( field.fromXml(
Blockly.Xml.textToDom('<field name="">custom value</field>')); Blockly.utils.xml.textToDom('<field name="">custom value</field>'));
chai.assert.equal(field.someProperty, 'custom value'); chai.assert.equal(field.someProperty, 'custom value');
}); });
}); });
@@ -666,7 +666,7 @@ suite('Abstract Fields', function() {
.appendField(field, 'TOOLTIP'); .appendField(field, 'TOOLTIP');
}, },
}; };
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="tooltip"></block>' + ' <block type="tooltip"></block>' +
'</xml>' '</xml>'
@@ -684,7 +684,7 @@ suite('Abstract Fields', function() {
field.setTooltip('tooltip'); field.setTooltip('tooltip');
}, },
}; };
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="tooltip"></block>' + ' <block type="tooltip"></block>' +
'</xml>' '</xml>'
@@ -701,7 +701,7 @@ suite('Abstract Fields', function() {
.appendField(field, 'TOOLTIP'); .appendField(field, 'TOOLTIP');
}, },
}; };
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="tooltip"></block>' + ' <block type="tooltip"></block>' +
'</xml>' '</xml>'
@@ -724,7 +724,7 @@ suite('Abstract Fields', function() {
return this.getFieldValue('TOOLTIP'); return this.getFieldValue('TOOLTIP');
}, },
}; };
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="tooltip"></block>' + ' <block type="tooltip"></block>' +
'</xml>' '</xml>'
@@ -745,7 +745,7 @@ suite('Abstract Fields', function() {
tooltip: 'tooltip', tooltip: 'tooltip',
}, },
}; };
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="tooltip"></block>' + ' <block type="tooltip"></block>' +
'</xml>' '</xml>'
@@ -763,7 +763,7 @@ suite('Abstract Fields', function() {
.appendField(field, 'TOOLTIP'); .appendField(field, 'TOOLTIP');
}, },
}; };
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="tooltip"></block>' + ' <block type="tooltip"></block>' +
'</xml>' '</xml>'
@@ -780,7 +780,7 @@ suite('Abstract Fields', function() {
.appendField(field, 'TOOLTIP'); .appendField(field, 'TOOLTIP');
}, },
}; };
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="tooltip"></block>' + ' <block type="tooltip"></block>' +
'</xml>' '</xml>'

View File

@@ -360,7 +360,7 @@ suite('Flyout', function() {
suite('XML', function() { suite('XML', function() {
test('True string', function() { test('True string', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml>' + '<xml>' +
'<block type="text_print" disabled="true"></block>' + '<block type="text_print" disabled="true"></block>' +
'</xml>' '</xml>'
@@ -370,7 +370,7 @@ suite('Flyout', function() {
}); });
test('False string', function() { test('False string', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml>' + '<xml>' +
'<block type="text_print" disabled="false"></block>' + '<block type="text_print" disabled="false"></block>' +
'</xml>' '</xml>'
@@ -381,7 +381,7 @@ suite('Flyout', function() {
test('Disabled string', function() { test('Disabled string', function() {
// The XML system supports this for some reason!? // The XML system supports this for some reason!?
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml>' + '<xml>' +
'<block type="text_print" disabled="disabled"></block>' + '<block type="text_print" disabled="disabled"></block>' +
'</xml>' '</xml>'
@@ -391,7 +391,7 @@ suite('Flyout', function() {
}); });
test('Different string', function() { test('Different string', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml>' + '<xml>' +
'<block type="text_print" disabled="random"></block>' + '<block type="text_print" disabled="random"></block>' +
'</xml>' '</xml>'

View File

@@ -19,7 +19,7 @@ suite('Inputs', function() {
}]); }]);
this.workspace = Blockly.inject('blocklyDiv'); this.workspace = Blockly.inject('blocklyDiv');
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.workspace); ), this.workspace);

View File

@@ -77,7 +77,7 @@ suite('InsertionMarkers', function() {
delete javascriptGenerator['statement_block']; delete javascriptGenerator['statement_block'];
}); });
test('Marker Surrounds', function() { test('Marker Surrounds', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="statement_block" id="insertion">' + ' <block type="statement_block" id="insertion">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
@@ -88,7 +88,7 @@ suite('InsertionMarkers', function() {
this.assertGen(xml, 'statement[a]{\n};\n'); this.assertGen(xml, 'statement[a]{\n};\n');
}); });
test('Marker Enclosed', function() { test('Marker Enclosed', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="statement_block" id="a">' + ' <block type="statement_block" id="a">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
@@ -99,7 +99,7 @@ suite('InsertionMarkers', function() {
this.assertGen(xml, 'statement[a]{\n};\n'); this.assertGen(xml, 'statement[a]{\n};\n');
}); });
test('Marker Enclosed and Surrounds', function() { test('Marker Enclosed and Surrounds', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="statement_block" id="a">' + ' <block type="statement_block" id="a">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
@@ -118,7 +118,7 @@ suite('InsertionMarkers', function() {
'};\n'); '};\n');
}); });
test('Marker Prev', function() { test('Marker Prev', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="stack_block" id="insertion">' + ' <block type="stack_block" id="insertion">' +
' <next>' + ' <next>' +
@@ -129,7 +129,7 @@ suite('InsertionMarkers', function() {
this.assertGen(xml, 'stack[a];\n'); this.assertGen(xml, 'stack[a];\n');
}); });
test('Marker Next', function() { test('Marker Next', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="stack_block" id="a">' + ' <block type="stack_block" id="a">' +
' <next>' + ' <next>' +
@@ -140,7 +140,7 @@ suite('InsertionMarkers', function() {
this.assertGen(xml, 'stack[a];\n'); this.assertGen(xml, 'stack[a];\n');
}); });
test('Marker Middle of Stack', function() { test('Marker Middle of Stack', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="stack_block" id="a">' + ' <block type="stack_block" id="a">' +
' <next>' + ' <next>' +
@@ -157,7 +157,7 @@ suite('InsertionMarkers', function() {
'stack[b];\n'); 'stack[b];\n');
}); });
test('Marker On Output', function() { test('Marker On Output', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="row_block" id="insertion">' + ' <block type="row_block" id="insertion">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
@@ -168,7 +168,7 @@ suite('InsertionMarkers', function() {
this.assertGen(xml, 'row[a]();\n'); this.assertGen(xml, 'row[a]();\n');
}); });
test('Marker On Input', function() { test('Marker On Input', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="row_block" id="a">' + ' <block type="row_block" id="a">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
@@ -179,7 +179,7 @@ suite('InsertionMarkers', function() {
this.assertGen(xml, 'row[a]();\n'); this.assertGen(xml, 'row[a]();\n');
}); });
test('Marker Middle of Row', function() { test('Marker Middle of Row', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="row_block" id="a">' + ' <block type="row_block" id="a">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
@@ -194,7 +194,7 @@ suite('InsertionMarkers', function() {
this.assertGen(xml, 'row[a](row[b]());\n'); this.assertGen(xml, 'row[a](row[b]());\n');
}); });
test('Marker Detatched', function() { test('Marker Detatched', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="stack_block" id="insertion"/>' + ' <block type="stack_block" id="insertion"/>' +
' <block type="stack_block" id="a"/>' + ' <block type="stack_block" id="a"/>' +
@@ -215,7 +215,7 @@ suite('InsertionMarkers', function() {
}; };
}); });
test('Marker Surrounds', function() { test('Marker Surrounds', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="statement_block" id="insertion" x="20" y="20">' + ' <block type="statement_block" id="insertion" x="20" y="20">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
@@ -231,7 +231,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker Enclosed', function() { test('Marker Enclosed', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="statement_block" id="a" x="20" y="20">' + ' <block type="statement_block" id="a" x="20" y="20">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
@@ -245,7 +245,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker Enclosed and Surrounds', function() { test('Marker Enclosed and Surrounds', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="statement_block" id="a" x="20" y="20">' + ' <block type="statement_block" id="a" x="20" y="20">' +
' <statement name="STATEMENT">' + ' <statement name="STATEMENT">' +
@@ -267,7 +267,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker Prev', function() { test('Marker Prev', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="stack_block" id="insertion" x="20" y="20">' + ' <block type="stack_block" id="insertion" x="20" y="20">' +
' <next>' + ' <next>' +
@@ -283,7 +283,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker Next', function() { test('Marker Next', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="stack_block" id="a" x="20" y="20">' + ' <block type="stack_block" id="a" x="20" y="20">' +
' <next>' + ' <next>' +
@@ -297,7 +297,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker Middle of Stack', function() { test('Marker Middle of Stack', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="stack_block" id="a" x="20" y="20">' + ' <block type="stack_block" id="a" x="20" y="20">' +
' <next>' + ' <next>' +
@@ -319,7 +319,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker On Output', function() { test('Marker On Output', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="row_block" id="insertion" x="20" y="20">' + ' <block type="row_block" id="insertion" x="20" y="20">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
@@ -335,7 +335,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker On Input', function() { test('Marker On Input', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="row_block" id="a" x="20" y="20">' + ' <block type="row_block" id="a" x="20" y="20">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
@@ -349,7 +349,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker Middle of Row', function() { test('Marker Middle of Row', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="row_block" id="a" x="20" y="20">' + ' <block type="row_block" id="a" x="20" y="20">' +
' <value name="INPUT">' + ' <value name="INPUT">' +
@@ -371,7 +371,7 @@ suite('InsertionMarkers', function() {
'</xml>'); '</xml>');
}); });
test('Marker Detatched', function() { test('Marker Detatched', function() {
const xml = Blockly.Xml.textToDom( const xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="stack_block" id="insertion"/>' + ' <block type="stack_block" id="insertion"/>' +
' <block type="stack_block" id="a" x="20" y="20"/>' + ' <block type="stack_block" id="a" x="20" y="20"/>' +

View File

@@ -374,7 +374,7 @@ suite('JSO Serialization', function() {
this.createBlockWithShadow = function(blockType, inputName) { this.createBlockWithShadow = function(blockType, inputName) {
const block = this.workspace.newBlock(blockType); const block = this.workspace.newBlock(blockType);
block.getInput(inputName).connection.setShadowDom( block.getInput(inputName).connection.setShadowDom(
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<shadow type="' + blockType + '" id="test"></shadow>')); '<shadow type="' + blockType + '" id="test"></shadow>'));
return block; return block;
}; };
@@ -385,7 +385,7 @@ suite('JSO Serialization', function() {
block.getInput(inputName).connection.connect( block.getInput(inputName).connection.connect(
childBlock.outputConnection || childBlock.previousConnection); childBlock.outputConnection || childBlock.previousConnection);
block.getInput(inputName).connection.setShadowDom( block.getInput(inputName).connection.setShadowDom(
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<shadow type="' + blockType + '" id="test"></shadow>')); '<shadow type="' + blockType + '" id="test"></shadow>'));
return block; return block;
}; };
@@ -601,7 +601,7 @@ suite('JSO Serialization', function() {
this.createNextWithShadow = function() { this.createNextWithShadow = function() {
const block = this.workspace.newBlock('stack_block'); const block = this.workspace.newBlock('stack_block');
block.nextConnection.setShadowDom( block.nextConnection.setShadowDom(
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="test"></shadow>')); '<shadow type="stack_block" id="test"></shadow>'));
return block; return block;
}; };
@@ -611,7 +611,7 @@ suite('JSO Serialization', function() {
const childBlock = this.workspace.newBlock('stack_block'); const childBlock = this.workspace.newBlock('stack_block');
block.nextConnection.connect(childBlock.previousConnection); block.nextConnection.connect(childBlock.previousConnection);
block.nextConnection.setShadowDom( block.nextConnection.setShadowDom(
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<shadow type="stack_block" id="test"></shadow>')); '<shadow type="stack_block" id="test"></shadow>'));
return block; return block;
}; };

View File

@@ -1830,7 +1830,7 @@ const runSerializerTestSuite = (serializer, deserializer, testSuite) => {
const createTestFunction = function(test) { const createTestFunction = function(test) {
return function() { return function() {
Blockly.Xml.domToWorkspace( Blockly.Xml.domToWorkspace(
Blockly.Xml.textToDom(test.xml), this.workspace); Blockly.utils.xml.textToDom(test.xml), this.workspace);
if (serializer && deserializer) { if (serializer && deserializer) {
const save = serializer(workspaces.save(this.workspace)); const save = serializer(workspaces.save(this.workspace));
this.workspace.clear(); this.workspace.clear();

View File

@@ -127,7 +127,7 @@ export function createProcDefBlock(
xml += xml +=
` <field name="NAME">${name}</field>` + ` <field name="NAME">${name}</field>` +
'</block>'; '</block>';
return Blockly.Xml.domToBlock(Blockly.Xml.textToDom(xml), workspace); return Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(xml), workspace);
} }
/** /**
@@ -142,7 +142,7 @@ export function createProcCallBlock(
workspace, hasReturn = false, name = 'proc name') { workspace, hasReturn = false, name = 'proc name') {
const type = hasReturn ? const type = hasReturn ?
'procedures_callreturn' : 'procedures_callnoreturn'; 'procedures_callreturn' : 'procedures_callnoreturn';
return Blockly.Xml.domToBlock(Blockly.Xml.textToDom( return Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
`<block type="${type}">` + `<block type="${type}">` +
` <mutation name="${name}"/>` + ` <mutation name="${name}"/>` +
`</block>` `</block>`

View File

@@ -63,7 +63,7 @@ export const runSerializationTestSuite = (testCases) => {
block = Blockly.serialization.blocks.append( block = Blockly.serialization.blocks.append(
testCase.json, this.workspace, {recordUndo: true}); testCase.json, this.workspace, {recordUndo: true});
} else { } else {
block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
testCase.xml), this.workspace); testCase.xml), this.workspace);
} }
this.clock.runAll(); this.clock.runAll();
@@ -85,7 +85,7 @@ export const runSerializationTestSuite = (testCases) => {
const expectedJson = testCase.expectedJson || testCase.json; const expectedJson = testCase.expectedJson || testCase.json;
chai.assert.deepEqual(generatedJson, expectedJson); chai.assert.deepEqual(generatedJson, expectedJson);
} else { } else {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
testCase.xml), this.workspace); testCase.xml), this.workspace);
this.clock.runAll(); this.clock.runAll();
const generatedXml = const generatedXml =

View File

@@ -176,7 +176,7 @@ export function getDeeplyNestedJSON() {
* @return {Array<Node>} Array holding xml elements for a toolbox. * @return {Array<Node>} Array holding xml elements for a toolbox.
*/ */
export function getXmlArray() { export function getXmlArray() {
const block = Blockly.Xml.textToDom( const block = Blockly.utils.xml.textToDom(
`<block type="logic_compare"> `<block type="logic_compare">
<field name="OP">NEQ</field> <field name="OP">NEQ</field>
<value name="A"> <value name="A">
@@ -190,9 +190,9 @@ export function getXmlArray() {
</block> </block>
</value> </value>
</block>`); </block>`);
const separator = Blockly.Xml.textToDom('<sep gap="20"></sep>'); const separator = Blockly.utils.xml.textToDom('<sep gap="20"></sep>');
const button = Blockly.Xml.textToDom('<button text="insert" callbackkey="insertConnectionRows"></button>'); const button = Blockly.utils.xml.textToDom('<button text="insert" callbackkey="insertConnectionRows"></button>');
const label = Blockly.Xml.textToDom('<label text="tooltips"></label>'); const label = Blockly.utils.xml.textToDom('<label text="tooltips"></label>');
return [block, separator, button, label]; return [block, separator, button, label];
} }

View File

@@ -697,7 +697,7 @@ export function testAWorkspace() {
}); });
function testUndoDelete(xmlText) { function testUndoDelete(xmlText) {
const xml = Blockly.Xml.textToDom(xmlText); const xml = Blockly.utils.xml.textToDom(xmlText);
Blockly.Xml.domToBlock(xml, this.workspace); Blockly.Xml.domToBlock(xml, this.workspace);
this.workspace.getTopBlocks()[0].dispose(false); this.workspace.getTopBlocks()[0].dispose(false);
this.workspace.undo(); this.workspace.undo();
@@ -819,7 +819,7 @@ export function testAWorkspace() {
}); });
function testUndoConnect(xmlText, parentId, childId, func) { function testUndoConnect(xmlText, parentId, childId, func) {
const xml = Blockly.Xml.textToDom(xmlText); const xml = Blockly.utils.xml.textToDom(xmlText);
Blockly.Xml.domToWorkspace(xml, this.workspace); Blockly.Xml.domToWorkspace(xml, this.workspace);
const parent = this.workspace.getBlockById(parentId); const parent = this.workspace.getBlockById(parentId);
@@ -1008,7 +1008,7 @@ export function testAWorkspace() {
}); });
function testUndoDisconnect(xmlText, childId) { function testUndoDisconnect(xmlText, childId) {
const xml = Blockly.Xml.textToDom(xmlText); const xml = Blockly.utils.xml.textToDom(xmlText);
Blockly.Xml.domToWorkspace(xml, this.workspace); Blockly.Xml.domToWorkspace(xml, this.workspace);
const child = this.workspace.getBlockById(childId); const child = this.workspace.getBlockById(childId);

View File

@@ -15,7 +15,7 @@ import {simulateClick} from './test_helpers/user_input.js';
suite("Trashcan", function() { suite("Trashcan", function() {
function fireDeleteEvent(workspace, xmlString) { function fireDeleteEvent(workspace, xmlString) {
let xml = Blockly.Xml.textToDom( let xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
xmlString + '</xml>'); xmlString + '</xml>');
xml = xml.children[0]; xml = xml.children[0];
@@ -63,7 +63,7 @@ suite("Trashcan", function() {
chai.assert.equal(this.trashcan.contents_.length, 0); chai.assert.equal(this.trashcan.contents_.length, 0);
}); });
test("Non-Delete w/ oldXml", function() { test("Non-Delete w/ oldXml", function() {
let xml = Blockly.Xml.textToDom( let xml = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="test_field_block"/>' + ' <block type="test_field_block"/>' +
'</xml>' '</xml>'

View File

@@ -46,7 +46,7 @@ suite('WorkspaceSvg', function() {
}); });
test('appendDomToWorkspace alignment', function() { test('appendDomToWorkspace alignment', function() {
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="math_random_float" inline="true" x="21" y="23">' + ' <block type="math_random_float" inline="true" x="21" y="23">' +
' </block>' + ' </block>' +
@@ -71,7 +71,7 @@ suite('WorkspaceSvg', function() {
}); });
test('Replacing shadow disposes svg', function() { test('Replacing shadow disposes svg', function() {
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="test_val_in">' + '<block type="test_val_in">' +
'<value name="NAME">' + '<value name="NAME">' +
@@ -240,7 +240,7 @@ suite('WorkspaceSvg', function() {
test('domToWorkspace that doesn\'t trigger scroll', function() { test('domToWorkspace that doesn\'t trigger scroll', function() {
// 4 blocks with space in center. // 4 blocks with space in center.
Blockly.Xml.domToWorkspace( Blockly.Xml.domToWorkspace(
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="controls_if" x="88" y="88"></block>' + '<block type="controls_if" x="88" y="88"></block>' +
'<block type="controls_if" x="288" y="88"></block>' + '<block type="controls_if" x="288" y="88"></block>' +
@@ -248,12 +248,12 @@ suite('WorkspaceSvg', function() {
'<block type="controls_if" x="288" y="238"></block>' + '<block type="controls_if" x="288" y="238"></block>' +
'</xml>'), '</xml>'),
this.workspace); this.workspace);
const xmlDom = Blockly.Xml.textToDom( const xmlDom = Blockly.utils.xml.textToDom(
'<block type="controls_if" x="188" y="163"></block>'); '<block type="controls_if" x="188" y="163"></block>');
this.clock.runAll(); this.clock.runAll();
resetEventHistory(this.eventsFireStub, this.changeListenerSpy); resetEventHistory(this.eventsFireStub, this.changeListenerSpy);
// Add block in center of other blocks, not triggering scroll. // Add block in center of other blocks, not triggering scroll.
Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom( Blockly.Xml.domToWorkspace(Blockly.utils.xml.textToDom(
'<block type="controls_if" x="188" y="163"></block>'), this.workspace); '<block type="controls_if" x="188" y="163"></block>'), this.workspace);
this.clock.runAll(); this.clock.runAll();
assertEventNotFired( assertEventNotFired(
@@ -265,7 +265,7 @@ suite('WorkspaceSvg', function() {
test('domToWorkspace at 0,0 that doesn\'t trigger scroll', function() { test('domToWorkspace at 0,0 that doesn\'t trigger scroll', function() {
// 4 blocks with space in center. // 4 blocks with space in center.
Blockly.Xml.domToWorkspace( Blockly.Xml.domToWorkspace(
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="controls_if" x="-75" y="-72"></block>' + '<block type="controls_if" x="-75" y="-72"></block>' +
'<block type="controls_if" x="75" y="-72"></block>' + '<block type="controls_if" x="75" y="-72"></block>' +
@@ -273,7 +273,7 @@ suite('WorkspaceSvg', function() {
'<block type="controls_if" x="75" y="75"></block>' + '<block type="controls_if" x="75" y="75"></block>' +
'</xml>'), '</xml>'),
this.workspace); this.workspace);
const xmlDom = Blockly.Xml.textToDom( const xmlDom = Blockly.utils.xml.textToDom(
'<block type="controls_if" x="0" y="0"></block>'); '<block type="controls_if" x="0" y="0"></block>');
this.clock.runAll(); this.clock.runAll();
resetEventHistory(this.eventsFireStub, this.changeListenerSpy); resetEventHistory(this.eventsFireStub, this.changeListenerSpy);
@@ -291,7 +291,7 @@ suite('WorkspaceSvg', function() {
// TODO: Un-skip after adding filtering for consecutive viewport events. // TODO: Un-skip after adding filtering for consecutive viewport events.
const addingMultipleBlocks = () => { const addingMultipleBlocks = () => {
Blockly.Xml.domToWorkspace( Blockly.Xml.domToWorkspace(
Blockly.Xml.textToDom( Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
'<block type="controls_if" x="88" y="88"></block>' + '<block type="controls_if" x="88" y="88"></block>' +
'<block type="controls_if" x="288" y="88"></block>' + '<block type="controls_if" x="288" y="88"></block>' +

View File

@@ -75,7 +75,7 @@ suite('XML', function() {
}); });
suite('textToDom', function() { suite('textToDom', function() {
test('Basic', function() { test('Basic', function() {
const dom = Blockly.Xml.textToDom(this.complexXmlText); const dom = Blockly.utils.xml.textToDom(this.complexXmlText);
chai.assert.equal(dom.nodeName, 'xml', 'XML tag'); chai.assert.equal(dom.nodeName, 'xml', 'XML tag');
chai.assert.equal(dom.getElementsByTagName('block').length, 6, 'Block tags'); chai.assert.equal(dom.getElementsByTagName('block').length, 6, 'Block tags');
}); });
@@ -306,7 +306,7 @@ suite('XML', function() {
suite('Comments', function() { suite('Comments', function() {
suite('Headless', function() { suite('Headless', function() {
setup(function() { setup(function() {
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.workspace); ), this.workspace);
}); });
@@ -331,7 +331,7 @@ suite('XML', function() {
setup(function() { setup(function() {
// Let the parent teardown dispose of it. // Let the parent teardown dispose of it.
this.workspace = Blockly.inject('blocklyDiv', {comments: true}); this.workspace = Blockly.inject('blocklyDiv', {comments: true});
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( this.block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.workspace); ), this.workspace);
}); });
@@ -435,7 +435,7 @@ suite('XML', function() {
}); });
suite('domToText', function() { suite('domToText', function() {
test('Round tripping', function() { test('Round tripping', function() {
const dom = Blockly.Xml.textToDom(this.complexXmlText); const dom = Blockly.utils.xml.textToDom(this.complexXmlText);
const text = Blockly.Xml.domToText(dom); const text = Blockly.Xml.domToText(dom);
chai.assert.equal(text.replace(/\s+/g, ''), chai.assert.equal(text.replace(/\s+/g, ''),
this.complexXmlText.replace(/\s+/g, ''), 'Round trip'); this.complexXmlText.replace(/\s+/g, ''), 'Round trip');
@@ -443,7 +443,7 @@ suite('XML', function() {
}); });
suite('domToPrettyText', function() { suite('domToPrettyText', function() {
test('Round tripping', function() { test('Round tripping', function() {
const dom = Blockly.Xml.textToDom(this.complexXmlText); const dom = Blockly.utils.xml.textToDom(this.complexXmlText);
const text = Blockly.Xml.domToPrettyText(dom); const text = Blockly.Xml.domToPrettyText(dom);
chai.assert.equal(text.replace(/\s+/g, ''), chai.assert.equal(text.replace(/\s+/g, ''),
this.complexXmlText.replace(/\s+/g, ''), 'Round trip'); this.complexXmlText.replace(/\s+/g, ''), 'Round trip');
@@ -479,7 +479,7 @@ suite('XML', function() {
suite('Comments', function() { suite('Comments', function() {
suite('Headless', function() { suite('Headless', function() {
test('Text', function() { test('Text', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment>test text</comment>' + ' <comment>test text</comment>' +
'</block>' '</block>'
@@ -487,7 +487,7 @@ suite('XML', function() {
chai.assert.equal(block.getCommentText(), 'test text'); chai.assert.equal(block.getCommentText(), 'test text');
}); });
test('No Text', function() { test('No Text', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment></comment>' + ' <comment></comment>' +
'</block>' '</block>'
@@ -495,7 +495,7 @@ suite('XML', function() {
chai.assert.equal(block.getCommentText(), ''); chai.assert.equal(block.getCommentText(), '');
}); });
test('Size', function() { test('Size', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment w="100" h="200">test text</comment>' + ' <comment w="100" h="200">test text</comment>' +
'</block>' '</block>'
@@ -504,7 +504,7 @@ suite('XML', function() {
{width: 100, height: 200}); {width: 100, height: 200});
}); });
test('Pinned True', function() { test('Pinned True', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment pinned="true">test text</comment>' + ' <comment pinned="true">test text</comment>' +
'</block>' '</block>'
@@ -512,7 +512,7 @@ suite('XML', function() {
chai.assert.isTrue(block.commentModel.pinned); chai.assert.isTrue(block.commentModel.pinned);
}); });
test('Pinned False', function() { test('Pinned False', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment pinned="false">test text</comment>' + ' <comment pinned="false">test text</comment>' +
'</block>' '</block>'
@@ -520,7 +520,7 @@ suite('XML', function() {
chai.assert.isFalse(block.commentModel.pinned); chai.assert.isFalse(block.commentModel.pinned);
}); });
test('Pinned Undefined', function() { test('Pinned Undefined', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment>test text</comment>' + ' <comment>test text</comment>' +
'</block>' '</block>'
@@ -537,7 +537,7 @@ suite('XML', function() {
}); });
test('Text', function() { test('Text', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment>test text</comment>' + ' <comment>test text</comment>' +
'</block>' '</block>'
@@ -546,7 +546,7 @@ suite('XML', function() {
chai.assert.isNotNull(block.getCommentIcon()); chai.assert.isNotNull(block.getCommentIcon());
}); });
test('No Text', function() { test('No Text', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment></comment>' + ' <comment></comment>' +
'</block>' '</block>'
@@ -555,7 +555,7 @@ suite('XML', function() {
chai.assert.isNotNull(block.getCommentIcon()); chai.assert.isNotNull(block.getCommentIcon());
}); });
test('Size', function() { test('Size', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment w="100" h="200">test text</comment>' + ' <comment w="100" h="200">test text</comment>' +
'</block>' '</block>'
@@ -568,7 +568,7 @@ suite('XML', function() {
}); });
suite('Pinned', function() { suite('Pinned', function() {
test('Pinned True', function() { test('Pinned True', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment pinned="true">test text</comment>' + ' <comment pinned="true">test text</comment>' +
'</block>' '</block>'
@@ -579,7 +579,7 @@ suite('XML', function() {
chai.assert.isTrue(block.getCommentIcon().isVisible()); chai.assert.isTrue(block.getCommentIcon().isVisible());
}); });
test('Pinned False', function() { test('Pinned False', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment pinned="false">test text</comment>' + ' <comment pinned="false">test text</comment>' +
'</block>' '</block>'
@@ -590,7 +590,7 @@ suite('XML', function() {
chai.assert.isFalse(block.getCommentIcon().isVisible()); chai.assert.isFalse(block.getCommentIcon().isVisible());
}); });
test('Pinned Undefined', function() { test('Pinned Undefined', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block">' + '<block type="empty_block">' +
' <comment>test text</comment>' + ' <comment>test text</comment>' +
'</block>' '</block>'
@@ -624,7 +624,7 @@ suite('XML', function() {
}); });
test('Backwards compatibility', function() { test('Backwards compatibility', function() {
createGenUidStubWithReturns('1'); createGenUidStubWithReturns('1');
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="field_variable_test_block" id="block_id">' + ' <block type="field_variable_test_block" id="block_id">' +
' <field name="VAR">name1</field>' + ' <field name="VAR">name1</field>' +
@@ -635,7 +635,7 @@ suite('XML', function() {
assertVariableValues(this.workspace, 'name1', '', '1'); assertVariableValues(this.workspace, 'name1', '', '1');
}); });
test('Variables at top', function() { test('Variables at top', function() {
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <variables>' + ' <variables>' +
' <variable type="type1" id="id1">name1</variable>' + ' <variable type="type1" id="id1">name1</variable>' +
@@ -653,7 +653,7 @@ suite('XML', function() {
assertVariableValues(this.workspace, 'name3', '', 'id3'); assertVariableValues(this.workspace, 'name3', '', 'id3');
}); });
test('Variables at top duplicated variables tag', function() { test('Variables at top duplicated variables tag', function() {
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <variables>' + ' <variables>' +
' </variables>' + ' </variables>' +
@@ -665,7 +665,7 @@ suite('XML', function() {
}); });
}); });
test('Variables at top missing type', function() { test('Variables at top missing type', function() {
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <variables>' + ' <variables>' +
' <variable id="id1">name1</variable>' + ' <variable id="id1">name1</variable>' +
@@ -679,7 +679,7 @@ suite('XML', function() {
}); });
}); });
test('Variables at top mismatch block type', function() { test('Variables at top mismatch block type', function() {
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <variables>' + ' <variables>' +
' <variable type="type1" id="id1">name1</variable>' + ' <variable type="type1" id="id1">name1</variable>' +
@@ -709,7 +709,7 @@ suite('XML', function() {
workspaceTeardown.call(this, this.workspace); workspaceTeardown.call(this, this.workspace);
}); });
test('Headless', function() { test('Headless', function() {
const dom = Blockly.Xml.textToDom( const dom = Blockly.utils.xml.textToDom(
'<xml xmlns="https://developers.google.com/blockly/xml">' + '<xml xmlns="https://developers.google.com/blockly/xml">' +
' <block type="test_block" inline="true" x="21" y="23">' + ' <block type="test_block" inline="true" x="21" y="23">' +
' </block>' + ' </block>' +
@@ -746,7 +746,7 @@ suite('XML', function() {
}; };
suite('Rendered -> XML -> Headless -> XML', function() { suite('Rendered -> XML -> Headless -> XML', function() {
test('Comment', function() { test('Comment', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.renderedWorkspace); ), this.renderedWorkspace);
block.setCommentText('test text'); block.setCommentText('test text');
@@ -757,7 +757,7 @@ suite('XML', function() {
}); });
suite('Headless -> XML -> Rendered -> XML', function() { suite('Headless -> XML -> Rendered -> XML', function() {
test('Comment', function() { test('Comment', function() {
const block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom( const block = Blockly.Xml.domToBlock(Blockly.utils.xml.textToDom(
'<block type="empty_block"/>' '<block type="empty_block"/>'
), this.headlessWorkspace); ), this.headlessWorkspace);
block.setCommentText('test text'); block.setCommentText('test text');

View File

@@ -24,14 +24,14 @@ const xmlText = '<xml xmlns="https://developers.google.com/blockly/xml">\n' +
suite('Test Node.js', function() { suite('Test Node.js', function() {
test('Import XML', function() { test('Import XML', function() {
const xml = Blockly.Xml.textToDom(xmlText); const xml = Blockly.utils.xml.textToDom(xmlText);
// Create workspace and import the XML // Create workspace and import the XML
const workspace = new Blockly.Workspace(); const workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace); Blockly.Xml.domToWorkspace(xml, workspace);
}); });
test('Roundtrip XML', function() { test('Roundtrip XML', function() {
const xml = Blockly.Xml.textToDom(xmlText); const xml = Blockly.utils.xml.textToDom(xmlText);
const workspace = new Blockly.Workspace(); const workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace); Blockly.Xml.domToWorkspace(xml, workspace);
@@ -42,7 +42,7 @@ suite('Test Node.js', function() {
assert.equal(headlessText, xmlText, 'equal'); assert.equal(headlessText, xmlText, 'equal');
}); });
test('Generate Code', function() { test('Generate Code', function() {
const xml = Blockly.Xml.textToDom(xmlText); const xml = Blockly.utils.xml.textToDom(xmlText);
// Create workspace and import the XML // Create workspace and import the XML
const workspace = new Blockly.Workspace(); const workspace = new Blockly.Workspace();

View File

@@ -177,7 +177,7 @@ function load() {
var state = JSON.parse(input.value); var state = JSON.parse(input.value);
Blockly.serialization.workspaces.load(state, workspace); Blockly.serialization.workspaces.load(state, workspace);
} else if (valid.xml) { } else if (valid.xml) {
var xml = Blockly.Xml.textToDom(input.value); var xml = Blockly.utils.xml.textToDom(input.value);
Blockly.Xml.domToWorkspace(xml, workspace); Blockly.Xml.domToWorkspace(xml, workspace);
} }
taChange(); taChange();
@@ -216,7 +216,7 @@ function saveIsValid(save) {
} }
var validXml = true var validXml = true
try { try {
Blockly.Xml.textToDom(save); Blockly.utils.xml.textToDom(save);
} catch (e) { } catch (e) {
validXml = false; validXml = false;
} }
@@ -296,7 +296,7 @@ function spaghetti(n) {
'$1' + spaghettiXml + '</'); '$1' + spaghettiXml + '</');
} }
xml = '<xml xmlns="https://developers.google.com/blockly/xml">' + xml + '</xml>'; xml = '<xml xmlns="https://developers.google.com/blockly/xml">' + xml + '</xml>';
var dom = Blockly.Xml.textToDom(xml); var dom = Blockly.utils.xml.textToDom(xml);
console.time('Spaghetti domToWorkspace'); console.time('Spaghetti domToWorkspace');
Blockly.Xml.domToWorkspace(dom, workspace); Blockly.Xml.domToWorkspace(dom, workspace);
console.timeEnd('Spaghetti domToWorkspace'); console.timeEnd('Spaghetti domToWorkspace');