@vericus/slate-kit-align
Version:
Plugins to provide a way to align blocks on slate
30 lines • 1.28 kB
JavaScript
import * as tslib_1 from "tslib";
import { Text } from "slate";
export default function createSchema(opts) {
var floatBlocks = opts.floatBlocks, textBlocks = opts.textBlocks, dataField = opts.dataField, alignments = opts.alignments;
var alignBlocks = tslib_1.__spread(floatBlocks, textBlocks);
return {
blocks: alignBlocks.reduce(function (acc, block) {
var _a, _b;
return (tslib_1.__assign({}, acc, (_a = {}, _a[block] = {
data: (_b = {},
_b[dataField] = function (align) {
return !align || (align && alignments.includes(align));
},
_b),
normalize: function (editor, error) {
if (error.code === "node_data_invalid") {
editor.withoutNormalizing(function () {
if (!Text.isText(error.node)) {
editor.setNodeByKey(error.node.key, {
data: error.node.data.delete(dataField),
});
}
});
}
},
}, _a)));
}, {}),
};
}
//# sourceMappingURL=index.js.map