diff --git a/src/dom_components/model/ComponentLink.js b/src/dom_components/model/ComponentLink.js deleted file mode 100644 index ba0bb0735..000000000 --- a/src/dom_components/model/ComponentLink.js +++ /dev/null @@ -1,43 +0,0 @@ -import { forEach } from 'underscore'; -import { toLowerCase } from 'utils/mixins'; -import ComponentText from './ComponentText'; - -const type = 'link'; - -export default class ComponentLink extends ComponentText { - get defaults() { - return { - ...super.defaults, - type, - tagName: 'a', - traits: ['title', 'href', 'target'], - }; - } -} - -ComponentLink.isComponent = (el, opts = {}) => { - let result; - - if (toLowerCase(el.tagName) === 'a') { - const textTags = opts.textTags || []; - result = { type, editable: false }; - - // The link is editable only if, at least, one of its - // children is a text node (not empty one) - const children = el.childNodes; - const len = children.length; - if (!len) delete result.editable; - - forEach(children, child => { - const { tagName } = child; - if ( - (child.nodeType == 3 && child.textContent.trim() !== '') || - (tagName && textTags.indexOf(toLowerCase(tagName)) >= 0) - ) { - delete result.editable; - } - }); - } - - return result; -}; diff --git a/src/dom_components/model/ComponentLink.ts b/src/dom_components/model/ComponentLink.ts new file mode 100644 index 000000000..82a1115d5 --- /dev/null +++ b/src/dom_components/model/ComponentLink.ts @@ -0,0 +1,44 @@ +import { forEach } from 'underscore'; +import { toLowerCase } from '../../utils/mixins'; +import ComponentText from './ComponentText'; + +const type = 'link'; + +export default class ComponentLink extends ComponentText { + get defaults() { + return { + // @ts-ignore + ...super.defaults, + type, + tagName: 'a', + traits: ['title', 'href', 'target'], + }; + } + + static isComponent(el: HTMLElement, opts: any = {}) { + let result: any; + + if (toLowerCase(el.tagName) === 'a') { + const textTags = opts.textTags || []; + result = { type, editable: false }; + + // The link is editable only if, at least, one of its + // children is a text node (not empty one) + const children = el.childNodes; + const len = children.length; + if (!len) delete result.editable; + + forEach(children, child => { + const { tagName } = child as HTMLElement; + if ( + (child.nodeType == 3 && (child as any).textContent.trim() !== '') || + (tagName && textTags.indexOf(toLowerCase(tagName)) >= 0) + ) { + delete result.editable; + } + }); + } + + return result; + } +}