import { keymap } from "../_vendor/@codemirror/view/dist-index.js";
import { useMemo } from "react";
import { indentationMarkers } from "../_vendor/@replit/codemirror-indentation-markers/dist-index.js";
import { createFormatExtension } from "../extensions/format.js";
import { useBaseExtensions } from "./use-base-extensions.js";
import { codeEditorTheme } from "../extensions/theme.js";
import { tooltipToBody } from "../extensions/tooltip-config.js";
import { clipboardHandler } from "../extensions/clipboard-handler.js";
import { editorKeymap } from "../extensions/keymap.js";
function useExtensions(props) {
  const { readonly, lineWrapping = true, customExtensions = [], rows, onChange, onEditorUpdate, onFormat, onCursorChange, onSelectionChange } = props;
  const baseExtensions = useBaseExtensions({
    readonly,
    lineWrapping,
    onChange,
    onCursorChange,
    onSelectionChange,
    onEditorUpdate,
    theme: codeEditorTheme({
      isReadOnly: readonly,
      maxHeight: "100%",
      minHeight: "20vh",
      rows
    }),
    includeKeymap: true
  });
  const extensions = useMemo(() => {
    const allExtensions = [
      ...baseExtensions,
      tooltipToBody,
      clipboardHandler
    ];
    if (!readonly) {
      allExtensions.push(
        // 缩进标记
        indentationMarkers({
          highlightActiveBlock: true,
          markerType: "fullScope",
          colors: {
            activeDark: "var(--color-code-indentation-marker-active)",
            activeLight: "var(--color-code-indentation-marker-active)",
            dark: "var(--color-code-indentation-marker)",
            light: "var(--color-code-indentation-marker)"
          }
        }),
        // 编辑器键盘映射
        keymap.of(editorKeymap)
      );
    }
    const formatExtension = onFormat ? createFormatExtension(onFormat) : [];
    return [...allExtensions, formatExtension, ...customExtensions];
  }, [baseExtensions, customExtensions, onFormat, readonly]);
  return extensions;
}
export {
  useExtensions
};
//# sourceMappingURL=use-extensions.js.map
