@@ -230,11 +230,10 @@ function processInlineTag(
230230 currentStyle : DraftInlineStyle ,
231231) : DraftInlineStyle {
232232 var styleToCheck = inlineTags [ tag ] ;
233- var win = node . ownerDocument . defaultView || window ;
234233 if ( styleToCheck ) {
235234 currentStyle = currentStyle . add ( styleToCheck ) . toOrderedSet ( ) ;
236- } else if ( node instanceof win . HTMLElement ) {
237- const htmlElement = node ;
235+ } else if ( node . nodeType === 1 ) {
236+ const htmlElement : HTMLElement = ( node : any ) ;
238237 currentStyle = currentStyle . withMutations ( style => {
239238 const fontWeight = htmlElement . style . fontWeight ;
240239 const fontStyle = htmlElement . style . fontStyle ;
@@ -317,16 +316,16 @@ function containsSemanticBlockMarkup(
317316}
318317
319318function hasValidLinkText ( link : Node ) : boolean {
320- const win = link . ownerDocument . defaultView || window ;
321319 invariant (
322- link instanceof win . HTMLAnchorElement ,
320+ link . nodeName === 'A' ,
323321 'Link must be an HTMLAnchorElement.' ,
324322 ) ;
325- var protocol = link . protocol ;
323+
324+ const element : HTMLAnchorElement = ( link : any ) ;
326325 return (
327- protocol === 'http:' ||
328- protocol === 'https:' ||
329- protocol === 'mailto:'
326+ element . protocol === 'http:' ||
327+ element . protocol === 'https:' ||
328+ element . protocol === 'mailto:'
330329 ) ;
331330}
332331
@@ -389,37 +388,35 @@ function genFragment(
389388 return { chunk : getSoftNewlineChunk ( ) , entityMap } ;
390389 }
391390
392- const win = node . ownerDocument . defaultView || window ;
393-
394391 // IMG tags
395- if (
396- nodeName === 'img' &&
397- node instanceof win . HTMLImageElement &&
398- node . attributes . getNamedItem ( 'src' ) &&
399- node . attributes . getNamedItem ( 'src' ) . value
400- ) {
401- const image : HTMLImageElement = node ;
402- const entityConfig = { } ;
392+ if ( nodeName === 'img' ) {
393+ const image : HTMLImageElement = ( node : any ) ;
394+ if (
395+ image . attributes . getNamedItem ( 'src' ) &&
396+ image . attributes . getNamedItem ( 'src' ) . value
397+ ) {
398+ const entityConfig = { } ;
403399
404- imgAttr . forEach ( ( attr ) => {
405- const imageAttribute = image . getAttribute ( attr ) ;
406- if ( imageAttribute ) {
407- entityConfig [ attr ] = imageAttribute ;
408- }
409- } ) ;
410- // Forcing this node to have children because otherwise no entity will be
411- // created for this node.
412- // The child text node cannot just have a space or return as content -
413- // we strip those out.
414- // See https://github.com/facebook/draft-js/issues/231 for some context.
415- node . textContent = '\ud83d\udcf7' ;
416-
417- // TODO: update this when we remove DraftEntity entirely
418- inEntity = DraftEntity . __create (
419- 'IMAGE' ,
420- 'MUTABLE' ,
421- entityConfig || { } ,
422- ) ;
400+ imgAttr . forEach ( ( attr ) => {
401+ const imageAttribute = image . getAttribute ( attr ) ;
402+ if ( imageAttribute ) {
403+ entityConfig [ attr ] = imageAttribute ;
404+ }
405+ } ) ;
406+ // Forcing this node to have children because otherwise no entity will be
407+ // created for this node.
408+ // The child text node cannot just have a space or return as content -
409+ // we strip those out.
410+ // See https://github.com/facebook/draft-js/issues/231 for some context.
411+ node . textContent = '\ud83d\udcf7' ;
412+
413+ // TODO: update this when we remove DraftEntity entirely
414+ inEntity = DraftEntity . __create (
415+ 'IMAGE' ,
416+ 'MUTABLE' ,
417+ entityConfig || { } ,
418+ ) ;
419+ }
423420 }
424421
425422 var chunk = getEmptyChunk ( ) ;
@@ -465,30 +462,30 @@ function genFragment(
465462 var entityId : ?string = null ;
466463
467464 while ( child ) {
468- if (
469- child instanceof win . HTMLAnchorElement &&
470- child . href &&
471- hasValidLinkText ( child )
472- ) {
473- const anchor : HTMLAnchorElement = child ;
474- const entityConfig = { } ;
475-
476- anchorAttr . forEach ( ( attr ) => {
477- const anchorAttribute = anchor . getAttribute ( attr ) ;
478- if ( anchorAttribute ) {
479- entityConfig [ attr ] = anchorAttribute ;
480- }
481- } ) ;
465+ entityId = null ;
466+ if ( nodeName === 'a' ) {
467+ const anchor : HTMLAnchorElement = ( child : any ) ;
468+ if (
469+ anchor . href &&
470+ hasValidLinkText ( anchor )
471+ ) {
472+ const entityConfig = { } ;
473+
474+ anchorAttr . forEach ( ( attr ) => {
475+ const anchorAttribute = anchor . getAttribute ( attr ) ;
476+ if ( anchorAttribute ) {
477+ entityConfig [ attr ] = anchorAttribute ;
478+ }
479+ } ) ;
482480
483- entityConfig . url = new URI ( anchor . href ) . toString ( ) ;
484- // TODO: update this when we remove DraftEntity completely
485- entityId = DraftEntity . __create (
486- 'LINK' ,
487- 'MUTABLE' ,
488- entityConfig || { } ,
489- ) ;
490- } else {
491- entityId = undefined ;
481+ entityConfig . url = new URI ( anchor . href ) . toString ( ) ;
482+ // TODO: update this when we remove DraftEntity completely
483+ entityId = DraftEntity . __create (
484+ 'LINK' ,
485+ 'MUTABLE' ,
486+ entityConfig || { } ,
487+ ) ;
488+ }
492489 }
493490
494491 const {
0 commit comments