UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

57 lines (55 loc) 1.84 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import { bindAll } from 'bind-event-listener'; import { INTERACTION_EVENT_TYPES } from './interaction-events'; /** * Reports the events the interactions with the editor are made of, as the browser dispatched * them. What they mean is the tracker's business. * * Event Timing cannot answer which interactions were with the editor, because it observes the * whole document, nor how many there were, because it reports none below 16 ms. */ export var EditorEventObserver = /*#__PURE__*/function () { function EditorEventObserver(onEvent) { _classCallCheck(this, EditorEventObserver); this.onEvent = onEvent; } /** * Called as the element the editor renders itself into changes: the editor only knows it after * its first render, and can replace it. */ return _createClass(EditorEventObserver, [{ key: "observe", value: function observe(root) { var _this = this; var next = root !== null && root !== void 0 ? root : undefined; if (next === this.root) { return; } this.stop(); this.root = next; if (!next) { return; } this.unbind = bindAll(next, INTERACTION_EVENT_TYPES.map(function (type) { return { type: type, listener: _this.onEvent }; }), // Capture, so a handler in the editor cannot stop an interaction from being reported. { capture: true, passive: true }); } }, { key: "stop", value: function stop() { var _this$unbind; (_this$unbind = this.unbind) === null || _this$unbind === void 0 || _this$unbind.call(this); this.unbind = undefined; this.root = undefined; } }]); }();