UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

34 lines (32 loc) • 1.27 kB
import { encodeCharacterWithMarks } from './encodeCharacterWithMarks'; /** Mirrors the library's private (unexported) `typeID` so node-end tokens match. */ var typeID = function typeID(type) { var cache = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null)); var id = cache[type.name]; if (id == null) { cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1; } return id; }; /** * The library default encoder plus mark folding on text characters. * * Deliberately narrower than `attrAwareTokenEncoder`: node-start tokens keep the library default * and do not fold in diffable attributes, which `getAttrChangeRanges` already reports for every * diff type. The NCS version-history path also uses `attrAwareTokenEncoder` so main diff calculation * detects attribute-only node replacements. */ export var markAwareTokenEncoder = { encodeCharacter: function encodeCharacter(char, marks) { return encodeCharacterWithMarks(char, marks); }, encodeNodeStart: function encodeNodeStart(node) { return node.type.name; }, encodeNodeEnd: function encodeNodeEnd(node) { return -typeID(node.type); }, compareTokens: function compareTokens(a, b) { return a === b; } };