import { isRicosFunctionalExtension } from "./../../ricos-types/index.js";
import { Extension, mergeAttributes } from "./../../tiptap/core/index.js";
import { DEFAULT_PRIORITY } from "./constants.js";
class FunctionalExtension {
  constructor(extension, services, config) {
    this.type = "extension";
    if (!isRicosFunctionalExtension(extension)) {
      throw new TypeError("invalid argument");
    }
    const { addKeyboardShortcuts, ...rest } = config || extension.createExtensionConfig({ mergeAttributes, services });
    this.config = {
      ...rest,
      ...extension.groups.includes("shortcuts-enabled") ? { addKeyboardShortcuts } : {},
      type: "extension"
    };
    this.priority = this.config.priority || DEFAULT_PRIORITY;
    this.name = this.config.name;
    this.groups = extension.groups || [];
    this.settings = extension.settings || {};
    this.ricosExtension = extension;
    this.reconfigure = extension.reconfigure || (() => this.config);
  }
  getRicosExtension() {
    return this.ricosExtension;
  }
  toTiptapExtension(extensions, ricosProps, services) {
    const config = this.reconfigure(this.config, extensions, ricosProps, this.settings, services);
    return Extension.create(config);
  }
  getNodeHocDescriptor(extensions, ricosProps, services) {
    const config = this.reconfigure(this.config, extensions, ricosProps, this.settings, services);
    return config.addNodeHoc?.();
  }
}
export {
  FunctionalExtension
};
//# sourceMappingURL=functional-extension.js.map
