Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/crutchcorn/codewrapper. A modular, framework-agnostic library for building interactive code editors codewrapper.vercel.app
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940import { EditorView, PluginValue, ViewPlugin, ViewUpdate,} from "@codemirror/view";import { Compartment, EditorState } from "@codemirror/state";
export const extensions = new Compartment();
export const getCodeEditorState = () => { return EditorState.create({ extensions: extensions.of([]), });};
export const setCodeEditorElement = ( el: HTMLElement, state: ReturnType<typeof getCodeEditorState>,) => { const view = new EditorView({ state, parent: el, });
return view;};
export const docUpdaterPlugin = (updateFn: (state: string) => void) => ViewPlugin.fromClass( class DocUpdater implements PluginValue { constructor(val: EditorView) { updateFn(val.state.doc.toString()); } update(update: ViewUpdate) { if (update.docChanged) updateFn(update.state.doc.toString()); } }, );