@atlaskit/editor-plugin-interactivity
Version:
Interactivity plugin for @atlaskit/editor-core
51 lines • 2.64 kB
JavaScript
import _createClass from "@babel/runtime/helpers/createClass";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
import { InteractionObserver } from './interaction-observer';
import { InteractionTracker } from './interaction-tracker';
import { InteractionGroup } from './interaction-group';
import { SlowInteractionList } from './slow-interaction-list';
function createSessionId() {
if (typeof crypto.randomUUID === 'function') {
return crypto.randomUUID();
}
var bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
return Array.from(bytes, function (byte) {
return byte.toString(16).padStart(2, '0');
}).join('');
}
/**
* Everything that belongs to one session.
*
* Nothing here is reset — the next session is a new instance — so a field added here cannot
* be left carrying the previous session's value.
*/
export var InteractivitySession = /*#__PURE__*/_createClass(function InteractivitySession(start) {
_classCallCheck(this, InteractivitySession);
_defineProperty(this, "id", createSessionId());
_defineProperty(this, "startedAt", performance.now());
/** Page interaction count when the session opened, subtracted to get its own total. */
_defineProperty(this, "interactionCountAtStart", InteractionObserver.readPageInteractionCount());
_defineProperty(this, "page", new InteractionGroup());
_defineProperty(this, "editorTyping", new InteractionGroup());
_defineProperty(this, "editorPointer", new InteractionGroup());
_defineProperty(this, "editorOther", new InteractionGroup());
_defineProperty(this, "slowest", isExperimentEnabled('platform_editor_editor_interactivity_slowest') ? new SlowInteractionList() : undefined);
/** Increments per snapshot; a query takes the highest one per session. */
_defineProperty(this, "seq", 0);
_defineProperty(this, "hiddenMs", 0);
/**
* Bumped on every change to the accumulated data. A snapshot is emitted only when this
* has moved past `emittedRevision`, so identical snapshots are never sent twice.
*/
_defineProperty(this, "revision", 0);
_defineProperty(this, "emittedRevision", 0);
/** One lifecycle snapshot per hidden episode; cleared when the page comes back. */
_defineProperty(this, "lifecycleSnapshotEmitted", false);
this.objectId = start.objectId;
this.mode = start.mode;
this.hiddenSince = start.hidden ? this.startedAt : undefined;
this.tracker = new InteractionTracker(start.startsAfterInteractionId);
});