UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

28 lines (27 loc) 868 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findChangedNodesFromTransaction = void 0; /** * Finds all top level nodes affected by the transaction * Uses from/to positions in transaction's steps to work out which nodes will * be changed by the transaction */ var findChangedNodesFromTransaction = exports.findChangedNodesFromTransaction = function findChangedNodesFromTransaction(tr) { var nodes = []; var steps = tr.steps || []; steps.forEach(function (step) { step.getMap().forEach(function (_oldStart, _oldEnd, newStart, newEnd) { tr.doc.nodesBetween(newStart, Math.min(newEnd, tr.doc.content.size), function (node) { if (!nodes.find(function (n) { return n === node; })) { nodes.push(node); } return false; }); }); }); return nodes; };