Rename Blockly.Xml.utils to Blockly.utils.xml

This commit is contained in:
Neil Fraser
2019-07-01 13:54:22 -07:00
committed by Neil Fraser
parent 880dc4cbef
commit 74be35e23d
9 changed files with 603 additions and 597 deletions

File diff suppressed because one or more lines are too long

View File

@@ -37,7 +37,7 @@ goog.provide('Blockly.Events.Move'); // Deprecated.
goog.require('Blockly.Events');
goog.require('Blockly.Events.Abstract');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.Xml.utils');
goog.require('Blockly.utils.xml');
/**
@@ -271,7 +271,7 @@ Blockly.Events.Create.prototype.fromJson = function(json) {
Blockly.Events.Create.prototype.run = function(forward) {
var workspace = this.getEventWorkspace_();
if (forward) {
var xml = Blockly.Xml.utils.createElement('xml');
var xml = Blockly.utils.xml.createElement('xml');
xml.appendChild(this.xml);
Blockly.Xml.domToWorkspace(xml, workspace);
} else {
@@ -361,7 +361,7 @@ Blockly.Events.Delete.prototype.run = function(forward) {
}
}
} else {
var xml = Blockly.Xml.utils.createElement('xml');
var xml = Blockly.utils.xml.createElement('xml');
xml.appendChild(this.oldXml);
Blockly.Xml.domToWorkspace(xml, workspace);
}

View File

@@ -34,9 +34,9 @@ goog.require('Blockly.Events.Ui');
goog.require('Blockly.Icon');
goog.require('Blockly.utils');
goog.require('Blockly.utils.dom');
goog.require('Blockly.utils.xml');
goog.require('Blockly.WorkspaceSvg');
goog.require('Blockly.Xml');
goog.require('Blockly.Xml.utils');
/**
@@ -133,9 +133,9 @@ Blockly.Mutator.prototype.createEditor_ = function() {
null);
// Convert the list of names into a list of XML objects for the flyout.
if (this.quarkNames_.length) {
var quarkXml = Blockly.Xml.utils.createElement('xml');
var quarkXml = Blockly.utils.xml.createElement('xml');
for (var i = 0, quarkName; quarkName = this.quarkNames_[i]; i++) {
var element = Blockly.Xml.utils.createElement('block');
var element = Blockly.utils.xml.createElement('block');
element.setAttribute('type', quarkName);
quarkXml.appendChild(element);
}

View File

@@ -37,9 +37,9 @@ goog.require('Blockly.Events.BlockChange');
goog.require('Blockly.Field');
goog.require('Blockly.Msg');
goog.require('Blockly.Names');
goog.require('Blockly.utils.xml');
goog.require('Blockly.Workspace');
goog.require('Blockly.Xml');
goog.require('Blockly.Xml.utils');
/**
@@ -188,12 +188,12 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
// <block type="procedures_defnoreturn" gap="16">
// <field name="NAME">do something</field>
// </block>
var block = Blockly.Xml.utils.createElement('block');
var block = Blockly.utils.xml.createElement('block');
block.setAttribute('type', 'procedures_defnoreturn');
block.setAttribute('gap', 16);
var nameField = Blockly.Xml.utils.createElement('field');
var nameField = Blockly.utils.xml.createElement('field');
nameField.setAttribute('name', 'NAME');
nameField.appendChild(Blockly.Xml.utils.createTextNode(
nameField.appendChild(Blockly.utils.xml.createTextNode(
Blockly.Msg['PROCEDURES_DEFNORETURN_PROCEDURE']));
block.appendChild(nameField);
xmlList.push(block);
@@ -202,19 +202,19 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
// <block type="procedures_defreturn" gap="16">
// <field name="NAME">do something</field>
// </block>
var block = Blockly.Xml.utils.createElement('block');
var block = Blockly.utils.xml.createElement('block');
block.setAttribute('type', 'procedures_defreturn');
block.setAttribute('gap', 16);
var nameField = Blockly.Xml.utils.createElement('field');
var nameField = Blockly.utils.xml.createElement('field');
nameField.setAttribute('name', 'NAME');
nameField.appendChild(Blockly.Xml.utils.createTextNode(
nameField.appendChild(Blockly.utils.xml.createTextNode(
Blockly.Msg['PROCEDURES_DEFRETURN_PROCEDURE']));
block.appendChild(nameField);
xmlList.push(block);
}
if (Blockly.Blocks['procedures_ifreturn']) {
// <block type="procedures_ifreturn" gap="16"></block>
var block = Blockly.Xml.utils.createElement('block');
var block = Blockly.utils.xml.createElement('block');
block.setAttribute('type', 'procedures_ifreturn');
block.setAttribute('gap', 16);
xmlList.push(block);
@@ -233,14 +233,14 @@ Blockly.Procedures.flyoutCategory = function(workspace) {
// <arg name="x"></arg>
// </mutation>
// </block>
var block = Blockly.Xml.utils.createElement('block');
var block = Blockly.utils.xml.createElement('block');
block.setAttribute('type', templateName);
block.setAttribute('gap', 16);
var mutation = Blockly.Xml.utils.createElement('mutation');
var mutation = Blockly.utils.xml.createElement('mutation');
mutation.setAttribute('name', name);
block.appendChild(mutation);
for (var j = 0; j < args.length; j++) {
var arg = Blockly.Xml.utils.createElement('arg');
var arg = Blockly.utils.xml.createElement('arg');
arg.setAttribute('name', args[j]);
mutation.appendChild(arg);
}

View File

@@ -20,15 +20,17 @@
/**
* @fileoverview XML element manipulation.
* These methods are not specific to Blockly, and could be factored out into
* a JavaScript framework such as Closure.
* @author fraser@google.com (Neil Fraser)
*/
'use strict';
/**
* @name Blockly.Xml.utils
* @name Blockly.utils.xml
* @namespace
*/
goog.provide('Blockly.Xml.utils');
goog.provide('Blockly.utils.xml');
/**
@@ -37,7 +39,7 @@ goog.provide('Blockly.Xml.utils');
* @return {!Element} New DOM element.
* @package
*/
Blockly.Xml.utils.createElement = function(tagName) {
Blockly.utils.xml.createElement = function(tagName) {
// TODO (#1978): Namespace this element.
// TODO (#2082): Support node.js.
return document.createElement(tagName);
@@ -49,7 +51,7 @@ Blockly.Xml.utils.createElement = function(tagName) {
* @return {!Node} New DOM node.
* @package
*/
Blockly.Xml.utils.createTextNode = function(text) {
Blockly.utils.xml.createTextNode = function(text) {
// TODO (#2082): Support node.js.
return document.createTextNode(text);
};
@@ -62,7 +64,7 @@ Blockly.Xml.utils.createTextNode = function(text) {
* @throws if XML doesn't parse.
* @package
*/
Blockly.Xml.utils.textToDomDocument = function(text) {
Blockly.utils.xml.textToDomDocument = function(text) {
var oParser = new DOMParser();
return oParser.parseFromString(text, 'text/xml');
};
@@ -74,7 +76,7 @@ Blockly.Xml.utils.textToDomDocument = function(text) {
* @return {string} Text representation.
* @package
*/
Blockly.Xml.utils.domToText = function(dom) {
Blockly.utils.xml.domToText = function(dom) {
// TODO (#2082): Support node.js.
var oSerializer = new XMLSerializer();
return oSerializer.serializeToString(dom);

View File

@@ -33,7 +33,7 @@ goog.require('Blockly.Events.CommentDelete');
goog.require('Blockly.Events.CommentMove');
goog.require('Blockly.utils');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.Xml.utils');
goog.require('Blockly.utils.xml');
/**
@@ -278,7 +278,7 @@ Blockly.WorkspaceComment.prototype.toXmlWithXY = function(opt_noId) {
* @package
*/
Blockly.WorkspaceComment.prototype.toXml = function(opt_noId) {
var commentElement = Blockly.Xml.utils.createElement('comment');
var commentElement = Blockly.utils.xml.createElement('comment');
if (!opt_noId) {
commentElement.setAttribute('id', this.id);
}

View File

@@ -33,8 +33,8 @@ goog.provide('Blockly.Events.CommentMove');
goog.require('Blockly.Events');
goog.require('Blockly.Events.Abstract');
goog.require('Blockly.utils.Coordinate');
goog.require('Blockly.utils.xml');
goog.require('Blockly.Xml');
goog.require('Blockly.Xml.utils');
/**
@@ -227,7 +227,7 @@ Blockly.Events.CommentCreate.prototype.run = function(forward) {
Blockly.Events.CommentCreateDeleteHelper = function(event, create) {
var workspace = event.getEventWorkspace_();
if (create) {
var xml = Blockly.Xml.utils.createElement('xml');
var xml = Blockly.utils.xml.createElement('xml');
xml.appendChild(event.xml);
Blockly.Xml.domToWorkspace(xml, workspace);
} else {

View File

@@ -36,7 +36,7 @@ goog.require('Blockly.Events.FinishedLoading');
goog.require('Blockly.Events.VarCreate');
goog.require('Blockly.utils');
goog.require('Blockly.utils.dom');
goog.require('Blockly.Xml.utils');
goog.require('Blockly.utils.xml');
/**
@@ -46,7 +46,7 @@ goog.require('Blockly.Xml.utils');
* @return {!Element} XML document.
*/
Blockly.Xml.workspaceToDom = function(workspace, opt_noId) {
var xml = Blockly.Xml.utils.createElement('xml');
var xml = Blockly.utils.xml.createElement('xml');
var variablesElement = Blockly.Xml.variablesToDom(
Blockly.Variables.allUsedVarModels(workspace));
if (variablesElement.hasChildNodes()) {
@@ -70,10 +70,10 @@ Blockly.Xml.workspaceToDom = function(workspace, opt_noId) {
* @return {!Element} List of XML elements.
*/
Blockly.Xml.variablesToDom = function(variableList) {
var variables = Blockly.Xml.utils.createElement('variables');
var variables = Blockly.utils.xml.createElement('variables');
for (var i = 0, variable; variable = variableList[i]; i++) {
var element = Blockly.Xml.utils.createElement('variable');
element.appendChild(Blockly.Xml.utils.createTextNode(variable.name));
var element = Blockly.utils.xml.createElement('variable');
element.appendChild(Blockly.utils.xml.createTextNode(variable.name));
element.setAttribute('type', variable.type);
element.setAttribute('id', variable.getId());
variables.appendChild(element);
@@ -109,7 +109,7 @@ Blockly.Xml.blockToDomWithXY = function(block, opt_noId) {
*/
Blockly.Xml.fieldToDom_ = function(field) {
if (field.isSerializable()) {
var container = Blockly.Xml.utils.createElement('field');
var container = Blockly.utils.xml.createElement('field');
container.setAttribute('name', field.name);
return field.toXml(container);
}
@@ -143,7 +143,7 @@ Blockly.Xml.allFieldsToDom_ = function(block, element) {
*/
Blockly.Xml.blockToDom = function(block, opt_noId) {
var element =
Blockly.Xml.utils.createElement(block.isShadow() ? 'shadow' : 'block');
Blockly.utils.xml.createElement(block.isShadow() ? 'shadow' : 'block');
element.setAttribute('type', block.type);
if (!opt_noId) {
element.setAttribute('id', block.id);
@@ -160,8 +160,8 @@ Blockly.Xml.blockToDom = function(block, opt_noId) {
var commentText = block.getCommentText();
if (commentText) {
var commentElement = Blockly.Xml.utils.createElement('comment');
commentElement.appendChild(Blockly.Xml.utils.createTextNode(commentText));
var commentElement = Blockly.utils.xml.createElement('comment');
commentElement.appendChild(Blockly.utils.xml.createTextNode(commentText));
if (typeof block.comment == 'object') {
commentElement.setAttribute('pinned', block.comment.isVisible());
var hw = block.comment.getBubbleSize();
@@ -172,8 +172,8 @@ Blockly.Xml.blockToDom = function(block, opt_noId) {
}
if (block.data) {
var dataElement = Blockly.Xml.utils.createElement('data');
dataElement.appendChild(Blockly.Xml.utils.createTextNode(block.data));
var dataElement = Blockly.utils.xml.createElement('data');
dataElement.appendChild(Blockly.utils.xml.createTextNode(block.data));
element.appendChild(dataElement);
}
@@ -185,9 +185,9 @@ Blockly.Xml.blockToDom = function(block, opt_noId) {
} else {
var childBlock = input.connection.targetBlock();
if (input.type == Blockly.INPUT_VALUE) {
container = Blockly.Xml.utils.createElement('value');
container = Blockly.utils.xml.createElement('value');
} else if (input.type == Blockly.NEXT_STATEMENT) {
container = Blockly.Xml.utils.createElement('statement');
container = Blockly.utils.xml.createElement('statement');
}
var shadow = input.connection.getShadowDom();
if (shadow && (!childBlock || !childBlock.isShadow())) {
@@ -225,7 +225,7 @@ Blockly.Xml.blockToDom = function(block, opt_noId) {
var nextBlock = block.getNextBlock();
if (nextBlock) {
var container = Blockly.Xml.utils.createElement('next');
var container = Blockly.utils.xml.createElement('next');
container.appendChild(Blockly.Xml.blockToDom(nextBlock, opt_noId));
element.appendChild(container);
}
@@ -282,7 +282,7 @@ Blockly.Xml.cloneShadow_ = function(shadow) {
* @return {string} Text representation.
*/
Blockly.Xml.domToText = function(dom) {
return Blockly.Xml.utils.domToText(dom);
return Blockly.utils.xml.domToText(dom);
};
/**
@@ -324,7 +324,7 @@ Blockly.Xml.domToPrettyText = function(dom) {
* @throws if the text doesn't parse.
*/
Blockly.Xml.textToDom = function(text) {
var doc = Blockly.Xml.utils.textToDomDocument(text);
var doc = Blockly.utils.xml.textToDomDocument(text);
if (!doc || !doc.documentElement ||
doc.getElementsByTagName('parsererror').length) {
throw Error('textToDom was unable to parse: ' + text);

View File

@@ -62,7 +62,7 @@ gulp.task('blockly_javascript_en', function() {
.pipe(insert.append(`
if (typeof DOMParser !== 'function') {
var JSDOM = require('jsdom').JSDOM;
Blockly.Xml.utils.textToDomDocument = function(text) {
Blockly.utils.xml.textToDomDocument = function(text) {
var jsdom = new JSDOM(text, { contentType: 'text/xml' });
return jsdom.window.document;
};
@@ -95,7 +95,7 @@ function buildWatchTaskFn(concatTask) {
'msg/messages.js', 'msg/json/*.json' // Localization data
];
var options = {
debounceDelay: 2000 // Milliseconds to delay rebuild.
debounceDelay: 2000 // Milliseconds to delay rebuild.
};
gulp.watch(srcs, options, gulp.parallel(tasks));
};