2
2
* @flow
3
3
*/
4
4
5
- import { dequal } from 'dequal/lite' ;
6
5
import iterationDecorator from "./util/iterationDecorator" ;
7
6
import rolesMap from './rolesMap' ;
8
7
@@ -24,25 +23,7 @@ for (let i = 0; i < keys.length; i++) {
24
23
if ( relation . module === 'HTML' ) {
25
24
const concept = relation . concept ;
26
25
if ( concept ) {
27
- const elementRoleRelation : ?ElementARIARoleRelationTuple = elementRoles . find ( relation => dequal ( relation , concept ) ) ;
28
- let roles : RoleSet ;
29
-
30
- if ( elementRoleRelation ) {
31
- roles = elementRoleRelation [ 1 ] ;
32
- } else {
33
- roles = [ ] ;
34
- }
35
- let isUnique = true ;
36
- for ( let i = 0 ; i < roles . length ; i ++ ) {
37
- if ( roles [ i ] === key ) {
38
- isUnique = false ;
39
- break ;
40
- }
41
- }
42
- if ( isUnique ) {
43
- roles . push ( key ) ;
44
- }
45
- elementRoles . push ( [ concept , roles ] ) ;
26
+ elementRoles . push ( [ concept , [ key ] ] ) ;
46
27
}
47
28
}
48
29
}
@@ -67,7 +48,7 @@ const elementRoleMap: TAriaQueryMap<
67
48
} ,
68
49
get : function ( key : ARIARoleRelationConcept ) : ?RoleSet {
69
50
const item = elementRoles . find ( tuple => (
70
- key . name === tuple [ 0 ] . name && dequal ( key . attributes , tuple [ 0 ] . attributes )
51
+ key . name === tuple [ 0 ] . name && ariaRoleRelationConceptAttributeEquals ( key . attributes , tuple [ 0 ] . attributes )
71
52
) ) ;
72
53
return item && item [ 1 ] ;
73
54
} ,
@@ -82,6 +63,54 @@ const elementRoleMap: TAriaQueryMap<
82
63
} ,
83
64
} ;
84
65
66
+ function ariaRoleRelationConceptAttributeEquals (
67
+ a ?: Array < ARIARoleRelationConceptAttribute > ,
68
+ b ?: Array < ARIARoleRelationConceptAttribute > ,
69
+ ) : boolean {
70
+
71
+ if ( a === undefined && b !== undefined ) {
72
+ return false ;
73
+ }
74
+
75
+ if ( a !== undefined && b === undefined ) {
76
+ return false ;
77
+ }
78
+
79
+ if ( a !== undefined && b !== undefined ) {
80
+ if ( a . length !== b . length ) {
81
+ return false ;
82
+ }
83
+
84
+ for ( let i = 0 ; i < a . length ; i ++ ) {
85
+ if ( a [ i ] . name !== b [ i ] . name || a [ i ] . value !== b [ i ] . value ) {
86
+ return false ;
87
+ }
88
+
89
+ if ( a [ i ] . constraints === undefined && b [ i ] . constraints !== undefined ) {
90
+ return false ;
91
+ }
92
+
93
+ if ( a [ i ] . constraints !== undefined && b [ i ] . constraints === undefined ) {
94
+ return false
95
+ }
96
+
97
+ if ( a [ i ] . constraints !== undefined && b [ i ] . constraints !== undefined ) {
98
+ if ( a [ i ] . constraints . length !== b [ i ] . constraints . length ) {
99
+ return false ;
100
+ }
101
+
102
+ for ( let j = 0 ; j < a [ i ] . constraints . length ; j ++ ) {
103
+ if ( a [ i ] . constraints [ j ] !== b [ i ] . constraints [ j ] ) {
104
+ return false ;
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+
111
+ return true ;
112
+ }
113
+
85
114
export default (
86
115
iterationDecorator (
87
116
elementRoleMap ,
0 commit comments