@uiw/react-codemirror
Version:
CodeMirror component for React.
80 lines (79 loc) • 2.06 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["className", "value", "selection", "extensions", "onChange", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable"];
import React, { useEffect, useRef, useImperativeHandle } from 'react';
import { useCodeMirror } from './useCodeMirror';
import { jsx as _jsx } from "react/jsx-runtime";
export * from '@codemirror/view';
export * from '@codemirror/basic-setup';
export * from '@codemirror/state';
export * from './useCodeMirror';
var ReactCodeMirror = /*#__PURE__*/React.forwardRef((props, ref) => {
var {
className,
value,
selection,
extensions = [],
onChange,
onUpdate,
autoFocus,
theme = 'light',
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
basicSetup,
placeholder,
indentWithTab,
editable
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
var editor = useRef(null);
var {
state,
view,
container,
setContainer
} = useCodeMirror({
container: editor.current,
value,
autoFocus,
theme,
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
basicSetup,
placeholder,
indentWithTab,
editable,
selection,
onChange,
onUpdate,
extensions
});
useImperativeHandle(ref, () => ({
editor: container,
state,
view
}));
useEffect(() => {
setContainer(editor.current);
return () => {
if (view) {
view.destroy();
}
}; // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return /*#__PURE__*/_jsx("div", _extends({
ref: editor,
className: "cm-theme-" + theme + (className ? " " + className : '')
}, other));
});
ReactCodeMirror.displayName = 'CodeMirror';
export default ReactCodeMirror;
//# sourceMappingURL=index.js.map