import { identityFunction } from "@contember/react-utils";
import { defaultEditorPluginPreset } from "./presets.js";
import { createEditorWithEssentials } from "../baseEditor/createEditorWithEssentials.js";
import { withAnchors } from "../plugins/element/anchors/withAnchors.js";
import { withParagraphs } from "../plugins/element/paragraphs/withParagraphs.js";
import { withHeadings } from "../plugins/element/headings/withHeadings.js";
import { withLists } from "../plugins/element/lists/withLists.js";
import { withHorizontalRules } from "../plugins/element/horizonalRules/withHorizontalRules.js";
import { withScrollTargets } from "../plugins/element/scrollTargets/withScrollTargets.js";
import { withTables } from "../plugins/element/tables/withTables.js";
import { withBold } from "../plugins/text/bold/withBold.js";
import { withCode } from "../plugins/text/code/withCode.js";
import { withHighlight } from "../plugins/text/highlight/withHighlight.js";
import { withItalic } from "../plugins/text/italic/withItalic.js";
import { withNewline } from "../plugins/text/newline/withNewline.js";
import { withStrikeThrough } from "../plugins/text/strikeThrough/withStrikeThrough.js";
import { withUnderline } from "../plugins/text/underline/withUnderline.js";
const pluginAugmenters = {
  anchor: withAnchors,
  paragraph: withParagraphs,
  heading: withHeadings,
  list: withLists,
  horizontalRule: withHorizontalRules,
  scrollTarget: withScrollTargets,
  table: withTables,
  bold: withBold,
  code: withCode,
  highlight: withHighlight,
  italic: withItalic,
  newline: withNewline,
  strikeThrough: withStrikeThrough,
  underline: withUnderline
};
const createEditor = ({
  plugins = defaultEditorPluginPreset,
  defaultElementType,
  augmentEditorBuiltins = identityFunction,
  addEditorBuiltins,
  augmentEditor = identityFunction
}) => {
  const editor = createEditorWithEssentials(defaultElementType);
  return initializeEditor({ editor, plugins, augmentEditor, addEditorBuiltins, augmentEditorBuiltins });
};
const initializeEditor = ({
  editor,
  plugins = defaultEditorPluginPreset,
  augmentEditorBuiltins = identityFunction,
  addEditorBuiltins,
  augmentEditor = identityFunction
}) => {
  for (const plugin of new Set(plugins)) {
    editor = pluginAugmenters[plugin](editor);
  }
  const withAugmentedBase = augmentEditor(editor) ?? editor;
  const withBuiltins = addEditorBuiltins(withAugmentedBase) ?? withAugmentedBase;
  return augmentEditorBuiltins(withBuiltins) ?? withBuiltins;
};
export { createEditor, initializeEditor };
//# sourceMappingURL=createEditor.js.map
