UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

63 lines (61 loc) 2.2 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.EditorEventObserver = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _bindEventListener = require("bind-event-listener"); var _interactionEvents = require("./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. */ var EditorEventObserver = exports.EditorEventObserver = /*#__PURE__*/function () { function EditorEventObserver(onEvent) { (0, _classCallCheck2.default)(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 (0, _createClass2.default)(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 = (0, _bindEventListener.bindAll)(next, _interactionEvents.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; } }]); }();