@atlaskit/editor-plugin-interactivity
Version:
Interactivity plugin for @atlaskit/editor-core
52 lines (51 loc) • 1.96 kB
JavaScript
/**
* The events an interaction is made of, and the group they belong to. Both sides of the collector
* read this, so counting and grouping cannot disagree.
*
* These are the events Event Timing can report with a non-zero `interactionId`, so any of them can
* be the one an entry measured — and it is usually not the one the interaction is counted on: for a
* pointer press the slow part is normally the `click` handler.
*
* The counted event is at a different end of the interaction in each group, because what can go
* wrong differs. Typing is counted on `keydown`, since the browser opens a new interaction for
* every repeat of a held key, and nothing cancels a key press. Pointing is counted on `pointerup`,
* since a press cannot repeat but can be taken over by a scroll — which the browser does not count
* either, and in that case `pointerup` never arrives.
*
* Counting events is also why an editor group's `totalCount` is not comparable with `page`'s, which
* is told `performance.interactionCount`: when an event is counted the collector cannot know whether
* the browser will open an interaction for it.
*/
var INTERACTION_EVENTS = {
keydown: {
group: 'editorTyping',
counts: true
},
keyup: {
group: 'editorTyping'
},
// Only while an IME composes: the browser counts the text it commits in the interaction of the
// key that caused it.
input: {
group: 'editorTyping'
},
pointerdown: {
group: 'editorPointer'
},
pointerup: {
group: 'editorPointer',
counts: true
},
click: {
group: 'editorPointer'
},
// Ends a pointer press the way `pointerup` does, so the browser counts it as an interaction.
contextmenu: {
group: 'editorPointer'
}
};
/** Derived, so the types listened for cannot drift from the table. */
export var INTERACTION_EVENT_TYPES = Object.keys(INTERACTION_EVENTS);
export function interactionEventKind(type) {
return INTERACTION_EVENTS[type];
}