import { history, redo, undo } from 'prosemirror-history';
import { withLogAction } from "../../../utils/keymap.js";
var HistoryAction;
(function (HistoryAction) {
    HistoryAction["Undo"] = "undo";
    HistoryAction["Redo"] = "redo";
})(HistoryAction || (HistoryAction = {}));
export const History = (builder, opts) => {
    builder.addPlugin(() => history(opts?.config));
    builder.addKeymap(() => {
        const { undoKey, redoKey } = opts ?? {};
        const bindings = {};
        if (undoKey)
            bindings[undoKey] = withLogAction('undo', undo);
        if (redoKey)
            bindings[redoKey] = withLogAction('redo', redo);
        return bindings;
    });
    builder
        .addAction(HistoryAction.Undo, createHistoryAction(undo))
        .addAction(HistoryAction.Redo, createHistoryAction(redo));
};
function createHistoryAction(command) {
    return () => ({
        isEnable: command,
        run: command,
    });
}
//# sourceMappingURL=index.js.map
