"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var history_exports = {};
__export(history_exports, {
  undoRedo: () => undoRedo
});
module.exports = __toCommonJS(history_exports);
var import_plugin_commons = require("./../../plugin-commons/index.js");
var import_history_infra = require("./history-infra.js");
const undoRedo = (0, import_plugin_commons.createRicosFunctionalExtension)({
  type: "extension",
  groups: ["shortcuts-enabled"],
  name: "ricosHistory",
  createExtensionConfig({ services }) {
    const historySettings = services.editorProps.historySettings;
    const keyboardShortcuts = historySettings?.keyboardShortcuts;
    return {
      name: this.name,
      priority: 1e3,
      addOptions: () => ({
        depth: 100,
        newGroupDelay: 500,
        onHistoryChange: historySettings?.onHistoryChange
      }),
      addCommands() {
        return {
          rebase: (count) => ({ tr }) => {
            tr.setMeta("rebased", count);
            return true;
          },
          silent: () => ({ tr }) => {
            tr.setMeta("skip", true);
            return true;
          },
          closeHistory: () => ({ tr }) => {
            (0, import_history_infra.closeHistory)(tr);
            return true;
          },
          undo: () => ({ state, dispatch }) => {
            return (0, import_history_infra.undo)(state, dispatch);
          },
          redo: () => ({ state, dispatch }) => {
            return (0, import_history_infra.redo)(state, dispatch);
          },
          pushActionItem: (callback) => ({ state, dispatch }) => {
            if (!dispatch) {
              return false;
            }
            return (0, import_history_infra.pushActionItem)(state, dispatch, callback);
          }
        };
      },
      addProseMirrorPlugins() {
        return [(0, import_history_infra.history)(this.options)];
      },
      addKeyboardShortcuts() {
        if (keyboardShortcuts === false) {
          return {};
        }
        const undoHandler = keyboardShortcuts?.undo ? () => keyboardShortcuts.undo() : () => this.editor.commands.undo();
        const redoHandler = keyboardShortcuts?.redo ? () => keyboardShortcuts.redo() : () => this.editor.commands.redo();
        return {
          "Mod-z": undoHandler,
          "Mod-y": redoHandler,
          "Shift-Mod-z": redoHandler
        };
      }
    };
  }
});
//# sourceMappingURL=history.js.map
