UNPKG

@atlaskit/editor-plugin-synced-block

Version:

SyncedBlock plugin for @atlaskit/editor-core

19 lines 719 B
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import { Mapping } from '@atlaskit/editor-prosemirror/transform'; export var rebaseTransaction = function rebaseTransaction(currentTr, incomingTr, state) { if (!incomingTr.docChanged) { return currentTr; } var currentMapping = new Mapping(_toConsumableArray(currentTr.mapping.maps).reverse().map(function (map) { return map.invert(); })); var rebasedTransaction = state.tr; currentTr.steps.forEach(function (step) { var mappedStep = step.map(currentMapping); if (mappedStep) { rebasedTransaction.step(mappedStep); currentMapping.appendMap(mappedStep.getMap()); } }); return rebasedTransaction; };