UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

39 lines (37 loc) • 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.markAwareTokenEncoder = void 0; var _encodeCharacterWithMarks = require("./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. */ var markAwareTokenEncoder = exports.markAwareTokenEncoder = { encodeCharacter: function encodeCharacter(char, marks) { return (0, _encodeCharacterWithMarks.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; } };