"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.History = void 0;
const prosemirror_history_1 = require("prosemirror-history");
const keymap_1 = require("../../../utils/keymap.js");
var HistoryAction;
(function (HistoryAction) {
    HistoryAction["Undo"] = "undo";
    HistoryAction["Redo"] = "redo";
})(HistoryAction || (HistoryAction = {}));
const History = (builder, opts) => {
    builder.addPlugin(() => (0, prosemirror_history_1.history)(opts?.config));
    builder.addKeymap(() => {
        const { undoKey, redoKey } = opts ?? {};
        const bindings = {};
        if (undoKey)
            bindings[undoKey] = (0, keymap_1.withLogAction)('undo', prosemirror_history_1.undo);
        if (redoKey)
            bindings[redoKey] = (0, keymap_1.withLogAction)('redo', prosemirror_history_1.redo);
        return bindings;
    });
    builder
        .addAction(HistoryAction.Undo, createHistoryAction(prosemirror_history_1.undo))
        .addAction(HistoryAction.Redo, createHistoryAction(prosemirror_history_1.redo));
};
exports.History = History;
function createHistoryAction(command) {
    return () => ({
        isEnable: command,
        run: command,
    });
}
//# sourceMappingURL=index.js.map
