UNPKG

@atlaskit/editor-plugin-metrics

Version:

Metrics plugin for @atlaskit/editor-core

52 lines (51 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shouldSkipTr = void 0; var _steps = require("@atlaskit/adf-schema/steps"); var _transform = require("@atlaskit/editor-prosemirror/transform"); var isResolvingLink = function isResolvingLink(tr) { var _linkStep$getMetadata; // When links are added, there are two transactions that are fired and we want to ignore the last one where the link is resolved var linkStep = tr.steps.find(function (step) { return step instanceof _steps.LinkMetaStep; }); var hasReplaceStep = tr.steps.some(function (step) { return step instanceof _transform.ReplaceStep; }); return Boolean(hasReplaceStep && linkStep instanceof _steps.LinkMetaStep && ((_linkStep$getMetadata = linkStep.getMetadata()) === null || _linkStep$getMetadata === void 0 ? void 0 : _linkStep$getMetadata.cardAction) === 'RESOLVE'); }; var checkTypeAheadStepStage = function checkTypeAheadStepStage(tr) { var _tr$getMeta; // When nodes are inserted from typeahead, there are multiple transactions that are fired that changes the document // We want to ignore all but the last transaction where the node is inserted if (((_tr$getMeta = tr.getMeta('typeAheadPlugin$')) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.action) === 'INSERT_RAW_QUERY') { return 'INSERT_RAW_QUERY'; } if (!tr.getMeta('appendedTransaction')) { return false; } var insertTypeAheadStep = tr.steps.find(function (step) { return step instanceof _steps.InsertTypeAheadStep; }); var replaceStep = tr.steps.find(function (step) { return step instanceof _transform.ReplaceStep; }); if (!insertTypeAheadStep || !replaceStep) { return false; } return insertTypeAheadStep instanceof _steps.InsertTypeAheadStep && insertTypeAheadStep.stage; }; var shouldSkipTr = exports.shouldSkipTr = function shouldSkipTr(tr) { if (isResolvingLink(tr)) { return true; } var typeAheadStepStage = checkTypeAheadStepStage(tr); if (typeAheadStepStage) { return typeAheadStepStage !== 'INSERTING_ITEM'; } else { // Ignore all appended transactions apart from when typeahead is inserting an item return tr.getMeta('appendedTransaction'); } };