@@ -58,7 +58,6 @@ export type CustomBlockFn = (
58
58
element : DOMElement ,
59
59
) => ?PartialBlock ;
60
60
61
- type EntityData = { [ key : string ] : mixed } ;
62
61
type EntityMutability = 'IMMUTABLE' | 'MUTABLE' | 'SEGMENTED' ;
63
62
64
63
type CustomStyle = {
@@ -75,7 +74,7 @@ export type CustomInlineFn = (
75
74
element : DOMElement ,
76
75
creators : {
77
76
Style : ( style : string ) => CustomStyle ;
78
- Entity: ( type : string , data : EntityData , mutability ? : EntityMutability ) => CustomEntity ;
77
+ Entity: ( type : string , data : DataMap < mixed > , mutability ? : EntityMutability ) => CustomEntity ;
79
78
}
80
79
) => ?( CustomStyle | CustomEntity ) ;
81
80
@@ -85,6 +84,7 @@ type Options = {
85
84
customBlockFn ?: CustomBlockFn ;
86
85
customInlineFn ? : CustomInlineFn ;
87
86
} ;
87
+ type DataMap < T > = { [ key : string ] : T } ;
88
88
89
89
const NO_STYLE = OrderedSet ( ) ;
90
90
const NO_ENTITY = null ;
@@ -112,17 +112,18 @@ const ELEM_ATTR_MAP = {
112
112
} ;
113
113
114
114
const getEntityData = ( tagName : string , element : DOMElement ) => {
115
- const data = { } ;
115
+ const data : DataMap < string > = { } ;
116
116
if (ELEM_ATTR_MAP.hasOwnProperty(tagName)) {
117
117
const attrMap = ELEM_ATTR_MAP [ tagName ] ;
118
118
for ( let i = 0 ; i < element . attributes . length ; i ++ ) {
119
119
const { name, value} = element . attributes [ i ] ;
120
- if ( value != null ) {
120
+ if ( typeof value === 'string' ) {
121
+ let strVal = value ;
121
122
if ( attrMap . hasOwnProperty ( name ) ) {
122
123
const newName = attrMap [ name ] ;
123
- data [ newName ] = value ;
124
+ data [ newName ] = strVal ;
124
125
} else if ( DATA_ATTRIBUTE . test ( name ) ) {
125
- data [ name ] = value ;
126
+ data [ name ] = strVal ;
126
127
}
127
128
}
128
129
}
@@ -166,9 +167,9 @@ class ContentGenerator {
166
167
// to return a Style() or Entity().
167
168
inlineCreators = {
168
169
Style : ( style : Style ) => ( { type : 'STYLE' , style} ) ,
169
- Entity : ( type : string , data : EntityData , mutability : EntityMutability = 'MUTABLE' ) => ( {
170
+ Entity : ( type : string , data : DataMap < mixed > , mutability : EntityMutability = 'MUTABLE' ) => ( {
170
171
type : 'ENTITY' ,
171
- entityKey : this . createEntity ( type , data , mutability ) ,
172
+ entityKey : this . createEntity ( type , toStringMap ( data ) , mutability ) ,
172
173
} ) ,
173
174
} ;
174
175
@@ -408,7 +409,7 @@ class ContentGenerator {
408
409
}
409
410
}
410
411
411
- createEntity ( type : string , data : EntityData , mutability : EntityMutability = 'MUTABLE' ) {
412
+ createEntity ( type : string , data : DataMap < string > , mutability: EntityMutability = 'MUTABLE') {
412
413
this . contentStateForEntities = this . contentStateForEntities . createEntity (
413
414
type ,
414
415
mutability ,
@@ -543,6 +544,20 @@ function hasSemanticMeaning(blockType: string) {
543
544
return blockType !== BLOCK_TYPE . UNSTYLED ;
544
545
}
545
546
547
+ function toStringMap ( input : mixed ) {
548
+ let result : DataMap < string > = { } ;
549
+ if ( input !== null && typeof input === 'object' && ! Array . isArray ( input ) ) {
550
+ let obj = input ;
551
+ for ( let key of Object . keys ( obj ) ) {
552
+ let value = obj [ key ] ;
553
+ if ( typeof value === 'string' ) {
554
+ result [ key ] = value ;
555
+ }
556
+ }
557
+ }
558
+ return result;
559
+ }
560
+
546
561
export function stateFromElement (
547
562
element : DOMElement ,
548
563
options ?: Options ,
0 commit comments