UNPKG

@atlaskit/editor-plugin-interactivity

Version:

Interactivity plugin for @atlaskit/editor-core

48 lines 2.45 kB
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(); } const bytes = new Uint8Array(16); crypto.getRandomValues(bytes); return Array.from(bytes, byte => 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 class InteractivitySession { constructor(start) { _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); } }