diff --git a/src/dom_components/model/ComponentSvg.js b/src/dom_components/model/ComponentSvg.js index 6f1bdd988..1d7714c2b 100644 --- a/src/dom_components/model/ComponentSvg.js +++ b/src/dom_components/model/ComponentSvg.js @@ -1,11 +1,16 @@ import Component from './Component'; +import { toLowerCase } from 'utils/mixins'; + +const type = 'svg'; export default Component.extend( { defaults: { ...Component.prototype.defaults, - resizable: { ratioDefault: 1 }, - highlightable: 0 + type, + tagName: type, + highlightable: 0, + resizable: { ratioDefault: 1 } }, getName() { @@ -16,13 +21,6 @@ export default Component.extend( } }, { - isComponent(el) { - if (SVGElement && el instanceof SVGElement) { - return { - tagName: el.tagName, - type: 'svg' - }; - } - } + isComponent: el => toLowerCase(el.tagName) === type } ); diff --git a/src/dom_components/model/ComponentSvgIn.js b/src/dom_components/model/ComponentSvgIn.js index dad3385f8..f10a40bd7 100644 --- a/src/dom_components/model/ComponentSvgIn.js +++ b/src/dom_components/model/ComponentSvgIn.js @@ -13,13 +13,6 @@ export default Component.extend( } }, { - isComponent(el) { - if (Component.isComponent(el) && el.tagName.toLowerCase() !== 'svg') { - return { - tagName: el.tagName, - type: 'svg-in' - }; - } - } + isComponent: (el, opts = {}) => !!opts.inSvg } ); diff --git a/src/parser/model/ParserHtml.js b/src/parser/model/ParserHtml.js index f0674c2f2..ee9e21ee4 100644 --- a/src/parser/model/ParserHtml.js +++ b/src/parser/model/ParserHtml.js @@ -103,7 +103,7 @@ export default config => { * @param {HTMLElement} el DOM element to traverse * @return {Array} */ - parseNode(el) { + parseNode(el, opts = {}) { const result = []; const nodes = el.childNodes; @@ -130,7 +130,7 @@ export default config => { // the first with a valid result will be that component for (let it = 0; it < ct.length; it++) { const compType = ct[it]; - obj = compType.model.isComponent(node); + obj = compType.model.isComponent(node, opts); if (obj) { if (typeof obj !== 'object') { @@ -209,7 +209,10 @@ export default config => { content: firstChild.nodeValue }; } else { - model.components = this.parseNode(node); + model.components = this.parseNode(node, { + inSvg: model.type === 'svg', + ...opts + }); } } diff --git a/test/specs/dom_components/model/ComponentTypes.js b/test/specs/dom_components/model/ComponentTypes.js index e8075e670..1f6b9b0d5 100644 --- a/test/specs/dom_components/model/ComponentTypes.js +++ b/test/specs/dom_components/model/ComponentTypes.js @@ -82,11 +82,17 @@ describe('Component Types', () => { ); }); - test.skip(' is correctly recognized', () => { + test(' is correctly recognized', () => { const cmp = wrapper.append(` `)[0]; expect(wrapper.components().length).toBe(1); expect(cmp.is('svg')).toBe(true); + expect( + cmp + .components() + .at(0) + .is('svg-in') + ).toBe(true); }); });