Use generics to derive SVG element type (#4036)

* Encapsulate type in a generic to automatically derive type of SVG element when using createSvgElement
This commit is contained in:
Sam El-Husseini
2020-07-13 10:40:31 -07:00
committed by GitHub
parent e4bbd451a3
commit 0f3db47fa5
39 changed files with 564 additions and 278 deletions

View File

@@ -113,20 +113,22 @@ Blockly.createDom_ = function(container, options) {
...
</svg>
*/
var svg = Blockly.utils.dom.createSvgElement('svg', {
'xmlns': Blockly.utils.dom.SVG_NS,
'xmlns:html': Blockly.utils.dom.HTML_NS,
'xmlns:xlink': Blockly.utils.dom.XLINK_NS,
'version': '1.1',
'class': 'blocklySvg',
'tabindex': '0'
}, container);
var svg = Blockly.utils.dom.createSvgElement(
Blockly.utils.dom.SvgElementType.SVG, {
'xmlns': Blockly.utils.dom.SVG_NS,
'xmlns:html': Blockly.utils.dom.HTML_NS,
'xmlns:xlink': Blockly.utils.dom.XLINK_NS,
'version': '1.1',
'class': 'blocklySvg',
'tabindex': '0'
}, container);
/*
<defs>
... filters go here ...
</defs>
*/
var defs = Blockly.utils.dom.createSvgElement('defs', {}, svg);
var defs = Blockly.utils.dom.createSvgElement(
Blockly.utils.dom.SvgElementType.DEFS, {}, svg);
// Each filter/pattern needs a unique ID for the case of multiple Blockly
// instances on a page. Browser behaviour becomes undefined otherwise.
// https://neil.fraser.name/news/2015/11/01/
@@ -164,7 +166,7 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface,
if (!wsOptions.hasCategories && wsOptions.languageTree) {
// Add flyout as an <svg> that is a sibling of the workspace svg.
var flyout = mainWorkspace.addFlyout('svg');
var flyout = mainWorkspace.addFlyout(Blockly.utils.dom.SvgElementType.SVG);
Blockly.utils.dom.insertAfter(flyout, svg);
}
if (wsOptions.hasTrashcan) {