UNPKG

@atlaskit/editor-plugin-track-changes

Version:

ShowDiff plugin for @atlaskit/editor-core

32 lines (30 loc) 877 B
import { MAX_STEPS_FROM_BASELINE } from './maxSteps'; /** * Returns the filtered steps to ensure we don't track an entire document worth of changes */ export function filterSteps(steps, allocations) { if (allocations.size <= MAX_STEPS_FROM_BASELINE) { return { steps, allocations }; } // Create a new allocation, retaining only the most recent values const elements = Array.from(allocations); const newAllocation = new Set(elements.slice(-MAX_STEPS_FROM_BASELINE)); const finalSteps = []; let cutoffFound = false; for (const step of steps) { if (newAllocation.has(step.allocation)) { cutoffFound = true; } // Accept everything after this point otherwise we could have mis-ordered steps if (cutoffFound) { finalSteps.push(step); } } return { steps: finalSteps, allocations: newAllocation }; }