@@ -13,9 +13,13 @@ import {
13
13
} from 'axobject-query' ;
14
14
import includes from 'array-includes' ;
15
15
import flatMap from 'array.prototype.flatmap' ;
16
+ import iterFrom from 'es-iterator-helpers/Iterator.from' ;
17
+ // import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
18
+ import filter from 'es-iterator-helpers/Iterator.prototype.filter' ;
19
+ import some from 'es-iterator-helpers/Iterator.prototype.some' ;
20
+
16
21
import attributesComparator from './attributesComparator' ;
17
22
18
- const domKeys = [ ...dom . keys ( ) ] ;
19
23
const roleKeys = [ ...roles . keys ( ) ] ;
20
24
const elementRoleEntries = [ ...elementRoles ] ;
21
25
@@ -51,22 +55,24 @@ const interactiveRoles = new Set(roleKeys
51
55
'toolbar' ,
52
56
) ) ;
53
57
54
- const nonInteractiveElementRoleSchemas = flatMap (
58
+ // TODO: convert to use iterFlatMap and iterFrom
59
+ const interactiveElementRoleSchemas = flatMap (
55
60
elementRoleEntries ,
56
- ( [ elementSchema , roleSet ] ) => ( [ ... roleSet ] . every ( ( role ) : boolean => nonInteractiveRoles . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
61
+ ( [ elementSchema , rolesArr ] ) => ( rolesArr . some ( ( role ) : boolean => interactiveRoles . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
57
62
) ;
58
63
59
- const interactiveElementRoleSchemas = flatMap (
64
+ // TODO: convert to use iterFlatMap and iterFrom
65
+ const nonInteractiveElementRoleSchemas = flatMap (
60
66
elementRoleEntries ,
61
- ( [ elementSchema , roleSet ] ) => ( [ ... roleSet ] . some ( ( role ) : boolean => interactiveRoles . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
67
+ ( [ elementSchema , rolesArr ] ) => ( rolesArr . every ( ( role ) : boolean => nonInteractiveRoles . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
62
68
) ;
63
69
64
- const interactiveAXObjects = new Set ( [ ...AXObjects . keys ( ) ]
65
- . filter ( ( name ) => AXObjects . get ( name ) . type === 'widget' ) ) ;
70
+ const interactiveAXObjects = new Set ( filter ( iterFrom ( AXObjects . keys ( ) ) , ( name ) => AXObjects . get ( name ) . type === 'widget' ) ) ;
66
71
72
+ // TODO: convert to use iterFlatMap and iterFrom
67
73
const interactiveElementAXObjectSchemas = flatMap (
68
74
[ ...elementAXObjects ] ,
69
- ( [ elementSchema , AXObjectSet ] ) => ( [ ... AXObjectSet ] . every ( ( role ) : boolean => interactiveAXObjects . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
75
+ ( [ elementSchema , AXObjectsArr ] ) => ( AXObjectsArr . every ( ( role ) : boolean => interactiveAXObjects . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
70
76
) ;
71
77
72
78
function checkIsInteractiveElement ( tagName , attributes ) : boolean {
@@ -78,18 +84,18 @@ function checkIsInteractiveElement(tagName, attributes): boolean {
78
84
}
79
85
// Check in elementRoles for inherent interactive role associations for
80
86
// this element.
81
- const isInherentInteractiveElement = interactiveElementRoleSchemas . some ( elementSchemaMatcher ) ;
87
+ const isInherentInteractiveElement = some ( iterFrom ( interactiveElementRoleSchemas ) , elementSchemaMatcher ) ;
82
88
if ( isInherentInteractiveElement ) {
83
89
return true ;
84
90
}
85
91
// Check in elementRoles for inherent non-interactive role associations for
86
92
// this element.
87
- const isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas . some ( elementSchemaMatcher ) ;
93
+ const isInherentNonInteractiveElement = some ( iterFrom ( nonInteractiveElementRoleSchemas ) , elementSchemaMatcher ) ;
88
94
if ( isInherentNonInteractiveElement ) {
89
95
return false ;
90
96
}
91
97
// Check in elementAXObjects for AX Tree associations for this element.
92
- const isInteractiveAXElement = interactiveElementAXObjectSchemas . some ( elementSchemaMatcher ) ;
98
+ const isInteractiveAXElement = some ( iterFrom ( interactiveElementAXObjectSchemas ) , elementSchemaMatcher ) ;
93
99
if ( isInteractiveAXElement ) {
94
100
return true ;
95
101
}
@@ -109,7 +115,7 @@ const isInteractiveElement = (
109
115
) : boolean => {
110
116
// Do not test higher level JSX components, as we do not know what
111
117
// low-level DOM element this maps to.
112
- if ( ! includes ( domKeys , tagName ) ) {
118
+ if ( ! dom . has ( tagName ) ) {
113
119
return false ;
114
120
}
115
121
0 commit comments