@@ -12,6 +12,7 @@ import {
12
12
elementAXObjects ,
13
13
} from 'axobject-query' ;
14
14
import includes from 'array-includes' ;
15
+ import flatMap from 'array.prototype.flatmap' ;
15
16
import attributesComparator from './attributesComparator' ;
16
17
17
18
const domKeys = [ ...dom . keys ( ) ] ;
@@ -39,8 +40,8 @@ const interactiveRoles = new Set(roleKeys
39
40
const role = roles . get ( name ) ;
40
41
return (
41
42
! role . abstract
42
- // The `progressbar` is descended from `widget`, but in practice, its
43
- // value is always `readonly`, so we treat it as a non-interactive role.
43
+ // The `progressbar` is descended from `widget`, but in practice, its
44
+ // value is always `readonly`, so we treat it as a non-interactive role.
44
45
&& name !== 'progressbar'
45
46
&& role . superClass . some ( ( classes ) => includes ( classes , 'widget' ) )
46
47
) ;
@@ -50,50 +51,23 @@ const interactiveRoles = new Set(roleKeys
50
51
'toolbar' ,
51
52
) ) ;
52
53
53
- const nonInteractiveElementRoleSchemas = elementRoleEntries
54
- . reduce ( (
55
- accumulator ,
56
- [
57
- elementSchema ,
58
- roleSet ,
59
- ] ,
60
- ) => {
61
- if ( [ ...roleSet ] . every ( ( role ) : boolean => nonInteractiveRoles . has ( role ) ) ) {
62
- accumulator . push ( elementSchema ) ;
63
- }
64
- return accumulator ;
65
- } , [ ] ) ;
54
+ const nonInteractiveElementRoleSchemas = flatMap (
55
+ elementRoleEntries ,
56
+ ( [ elementSchema , roleSet ] ) => ( [ ...roleSet ] . every ( ( role ) : boolean => nonInteractiveRoles . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
57
+ ) ;
66
58
67
- const interactiveElementRoleSchemas = elementRoleEntries
68
- . reduce ( (
69
- accumulator ,
70
- [
71
- elementSchema ,
72
- roleSet ,
73
- ] ,
74
- ) => {
75
- if ( [ ...roleSet ] . some ( ( role ) : boolean => interactiveRoles . has ( role ) ) ) {
76
- accumulator . push ( elementSchema ) ;
77
- }
78
- return accumulator ;
79
- } , [ ] ) ;
59
+ const interactiveElementRoleSchemas = flatMap (
60
+ elementRoleEntries ,
61
+ ( [ elementSchema , roleSet ] ) => ( [ ...roleSet ] . some ( ( role ) : boolean => interactiveRoles . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
62
+ ) ;
80
63
81
64
const interactiveAXObjects = new Set ( [ ...AXObjects . keys ( ) ]
82
65
. filter ( ( name ) => AXObjects . get ( name ) . type === 'widget' ) ) ;
83
66
84
- const interactiveElementAXObjectSchemas = [ ...elementAXObjects ]
85
- . reduce ( (
86
- accumulator ,
87
- [
88
- elementSchema ,
89
- AXObjectSet ,
90
- ] ,
91
- ) => {
92
- if ( [ ...AXObjectSet ] . every ( ( role ) : boolean => interactiveAXObjects . has ( role ) ) ) {
93
- accumulator . push ( elementSchema ) ;
94
- }
95
- return accumulator ;
96
- } , [ ] ) ;
67
+ const interactiveElementAXObjectSchemas = flatMap (
68
+ [ ...elementAXObjects ] ,
69
+ ( [ elementSchema , AXObjectSet ] ) => ( [ ...AXObjectSet ] . every ( ( role ) : boolean => interactiveAXObjects . has ( role ) ) ? [ elementSchema ] : [ ] ) ,
70
+ ) ;
97
71
98
72
function checkIsInteractiveElement ( tagName , attributes ) : boolean {
99
73
function elementSchemaMatcher ( elementSchema ) {
@@ -104,21 +78,18 @@ function checkIsInteractiveElement(tagName, attributes): boolean {
104
78
}
105
79
// Check in elementRoles for inherent interactive role associations for
106
80
// this element.
107
- const isInherentInteractiveElement = interactiveElementRoleSchemas
108
- . some ( elementSchemaMatcher ) ;
81
+ const isInherentInteractiveElement = interactiveElementRoleSchemas . some ( elementSchemaMatcher ) ;
109
82
if ( isInherentInteractiveElement ) {
110
83
return true ;
111
84
}
112
85
// Check in elementRoles for inherent non-interactive role associations for
113
86
// this element.
114
- const isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas
115
- . some ( elementSchemaMatcher ) ;
87
+ const isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas . some ( elementSchemaMatcher ) ;
116
88
if ( isInherentNonInteractiveElement ) {
117
89
return false ;
118
90
}
119
91
// Check in elementAXObjects for AX Tree associations for this element.
120
- const isInteractiveAXElement = interactiveElementAXObjectSchemas
121
- . some ( elementSchemaMatcher ) ;
92
+ const isInteractiveAXElement = interactiveElementAXObjectSchemas . some ( elementSchemaMatcher ) ;
122
93
if ( isInteractiveAXElement ) {
123
94
return true ;
124
95
}
0 commit comments