@@ -26,8 +26,8 @@ const KEY_ALIASES = new Set(keyAliases)
26
26
/**
27
27
* Finds and returns all keys for event directives
28
28
*
29
- * @param {Array } attributes Element attributes
30
- * @returns {Array }
29
+ * @param {array } attributes Element attributes
30
+ * @returns {array[object] } [{ name, node, modifiers }]
31
31
*/
32
32
function getEventDirectives ( attributes ) {
33
33
return attributes
@@ -42,6 +42,12 @@ function getEventDirectives (attributes) {
42
42
} ) )
43
43
}
44
44
45
+ /**
46
+ * Checks whether given modifier is KEY
47
+ *
48
+ * @param {string } modifier
49
+ * @returns {boolean }
50
+ */
45
51
function isKeyModifier ( modifier ) {
46
52
return (
47
53
KEY_MODIFIERS . has ( modifier ) ||
@@ -54,10 +60,24 @@ function isKeyModifier (modifier) {
54
60
)
55
61
}
56
62
63
+ /**
64
+ * Checks whether given any of provided modifiers
65
+ * has KEY modifier
66
+ *
67
+ * @param {array } modifiers
68
+ * @returns {boolean }
69
+ */
57
70
function hasKeyModifier ( modifiers ) {
58
71
return modifiers . some ( isKeyModifier )
59
72
}
60
73
74
+ /**
75
+ * Groups all events in object,
76
+ * with keys represinting each event name
77
+ *
78
+ * @param {array } events
79
+ * @returns {object } { click: [], keypress: [] }
80
+ */
61
81
function groupEvents ( events ) {
62
82
return events . reduce ( ( acc , event ) => {
63
83
if ( acc [ event . name ] ) {
@@ -70,10 +90,24 @@ function groupEvents (events) {
70
90
} , { } )
71
91
}
72
92
93
+ /**
94
+ * Creates alphabetically sorted string with key modifiers
95
+ *
96
+ * @param {array[string] } modifiers
97
+ * @returns {string } e.g. "alt,ctrl,del,shift"
98
+ */
73
99
function getKeyModifiersString ( modifiers ) {
74
100
return modifiers . filter ( isKeyModifier ) . sort ( ) . join ( ',' )
75
101
}
76
102
103
+ /**
104
+ * Compares two events based on their modifiers
105
+ * to detect possible event leakeage
106
+ *
107
+ * @param {object } baseEvent
108
+ * @param {object } event
109
+ * @returns {boolean }
110
+ */
77
111
function hasConflictedModifiers ( baseEvent , event ) {
78
112
if (
79
113
event . node === baseEvent . node ||
@@ -90,6 +124,12 @@ function hasConflictedModifiers (baseEvent, event) {
90
124
)
91
125
}
92
126
127
+ /**
128
+ * Searches for events that might conflict with each other
129
+ *
130
+ * @param {array } events
131
+ * @returns {array } conflicted events, without duplicates
132
+ */
93
133
function findConflictedEvents ( events ) {
94
134
return events . reduce ( ( acc , event ) => {
95
135
return [
0 commit comments