@atlaskit/editor-plugin-interactivity
Version:
Interactivity plugin for @atlaskit/editor-core
58 lines (57 loc) • 3.33 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.InteractivitySession = void 0;
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
var _interactionObserver = require("./interaction-observer");
var _interactionTracker = require("./interaction-tracker");
var _interactionGroup = require("./interaction-group");
var _slowInteractionList = require("./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.
*/
var InteractivitySession = exports.InteractivitySession = /*#__PURE__*/(0, _createClass2.default)(function InteractivitySession(start) {
(0, _classCallCheck2.default)(this, InteractivitySession);
(0, _defineProperty2.default)(this, "id", createSessionId());
(0, _defineProperty2.default)(this, "startedAt", performance.now());
/** Page interaction count when the session opened, subtracted to get its own total. */
(0, _defineProperty2.default)(this, "interactionCountAtStart", _interactionObserver.InteractionObserver.readPageInteractionCount());
(0, _defineProperty2.default)(this, "page", new _interactionGroup.InteractionGroup());
(0, _defineProperty2.default)(this, "editorTyping", new _interactionGroup.InteractionGroup());
(0, _defineProperty2.default)(this, "editorPointer", new _interactionGroup.InteractionGroup());
(0, _defineProperty2.default)(this, "editorOther", new _interactionGroup.InteractionGroup());
(0, _defineProperty2.default)(this, "slowest", (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_editor_interactivity_slowest') ? new _slowInteractionList.SlowInteractionList() : undefined);
/** Increments per snapshot; a query takes the highest one per session. */
(0, _defineProperty2.default)(this, "seq", 0);
(0, _defineProperty2.default)(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.
*/
(0, _defineProperty2.default)(this, "revision", 0);
(0, _defineProperty2.default)(this, "emittedRevision", 0);
/** One lifecycle snapshot per hidden episode; cleared when the page comes back. */
(0, _defineProperty2.default)(this, "lifecycleSnapshotEmitted", false);
this.objectId = start.objectId;
this.mode = start.mode;
this.hiddenSince = start.hidden ? this.startedAt : undefined;
this.tracker = new _interactionTracker.InteractionTracker(start.startsAfterInteractionId);
});