UNPKG

@atlaskit/editor-plugin-ufo

Version:

Ufo plugin for @atlaskit/editor-core

26 lines 1.06 kB
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { atTheBeginningOfDoc } from '@atlaskit/editor-common/selection'; import { isEmptyDocument } from '@atlaskit/editor-common/utils'; import { abortAll, getActiveInteraction } from '@atlaskit/react-ufo/interaction-metrics'; export const traceUFOInteractionOnFirstInteraction = () => { return new SafePlugin({ view() { let aborted = false; return { update(view, prevState) { if (aborted) { // opt out of additional logic if already aborted return; } if (!view.state.selection.eq(prevState.selection) && !atTheBeginningOfDoc(view.state) && !isEmptyDocument(view.state.doc)) { const activeInteraction = getActiveInteraction(); if (activeInteraction && ['edit-page', 'live-edit'].includes(activeInteraction.ufoName)) { abortAll('new_interaction', `selection-changed-on-editor-element`); } aborted = true; } } }; } }); };