@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
31 lines • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var schema_builder_1 = require("./schema-builder");
/**
* Replace the given range, or the selection if no range is given, with a text node containing the given string
*/
function insertText(view, text, from, to) {
var pos = from;
text.split('').forEach(function (character, index) {
if (!view.someProp('handleTextInput', function (f) { return f(view, pos + index, pos + index, character); })) {
view.dispatch(view.state.tr.insertText(character, pos + index, pos + index));
}
});
}
exports.insertText = insertText;
/**
* Replace the current selection with the given content, which may be a fragment, node, or array of nodes.
*
* @returns refs from the inserted nodes, made relative to the document
* insertion position
*/
function insert(view, content) {
var state = view.state;
var _a = state.selection, from = _a.from, to = _a.to;
var _b = schema_builder_1.coerce(content, state.schema), nodes = _b.nodes, refs = _b.refs;
var tr = state.tr.replaceWith(from, to, nodes);
view.dispatch(tr);
return schema_builder_1.offsetRefs(refs, from);
}
exports.insert = insert;
//# sourceMappingURL=transactions.js.map