@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
38 lines (37 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDeletedWidgets = void 0;
var _decorationKeys = require("./decorations/decorationKeys");
var _getWidgetElement = require("./decorations/utils/getWidgetElement");
var _main = require("./main");
/**
* The rendered deleted-content widgets in `editorState`, optionally restricted to `[from, to]`,
* ordered by position. Deleted content is rendered as widget decorations rather than document
* nodes, so this is how the element and the position it is anchored at are recovered.
*
* Kept internal and surfaced only through the `getDeletedWidgets` plugin action, so consumers never
* receive the plugin key or the decoration set (which would let them mutate plugin behaviour).
*/
var getDeletedWidgets = exports.getDeletedWidgets = function getDeletedWidgets(editorState, range) {
var _showDiffPluginKey$ge;
var decorations = (_showDiffPluginKey$ge = _main.showDiffPluginKey.getState(editorState)) === null || _showDiffPluginKey$ge === void 0 ? void 0 : _showDiffPluginKey$ge.decorations;
if (!decorations) {
return [];
}
return decorations.find(range === null || range === void 0 ? void 0 : range.from, range === null || range === void 0 ? void 0 : range.to, function (spec) {
return (0, _decorationKeys.isDiffDecorationSpec)(spec) && spec.decorationType === 'widget';
}).reduce(function (widgets, decoration) {
var element = (0, _getWidgetElement.getWidgetElement)(decoration);
if (element) {
widgets.push({
element: element,
position: decoration.from
});
}
return widgets;
}, []).sort(function (a, b) {
return a.position - b.position;
});
};