UNPKG

@atlaskit/editor-plugin-ufo

Version:

Ufo plugin for @atlaskit/editor-core

26 lines 1.13 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 var traceUFOInteractionOnFirstInteraction = function traceUFOInteractionOnFirstInteraction() { return new SafePlugin({ view: function view() { var aborted = false; return { update: function 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)) { var activeInteraction = getActiveInteraction(); if (activeInteraction && ['edit-page', 'live-edit'].includes(activeInteraction.ufoName)) { abortAll('new_interaction', "selection-changed-on-editor-element"); } aborted = true; } } }; } }); };