MCPcopy
hub / github.com/immutable-js/immutable-js / Editor

Function Editor

website/src/repl/Editor.tsx:15–60  ·  view source on GitHub ↗
({ value, onChange }: Props)

Source from the content-addressed store, hash-verified

13};
14
15export function Editor({ value, onChange }: Props): JSX.Element {
16 const editor = useRef<HTMLDivElement>(null);
17 const darkMode = useDarkMode();
18
19 const onUpdate = EditorView.updateListener.of((v) => {
20 if (onChange) {
21 onChange(v.state.doc.toString());
22 }
23 });
24
25 useEffect(() => {
26 if (!editor.current) {
27 return;
28 }
29
30 const readOnly = !onChange;
31
32 const startState = EditorState.create({
33 doc: value,
34 // readOnly: !onChange,
35 extensions: [
36 readOnly ? minimalSetup : basicSetup,
37 keymap.of([...defaultKeymap, indentWithTab]),
38 javascript(),
39 darkMode ? oneDark : undefined,
40 readOnly ? undefined : onUpdate,
41 EditorState.readOnly.of(readOnly),
42 readOnly ? gutter({}) : undefined,
43 ].filter(
44 (value: Extension | undefined): value is Extension =>
45 typeof value !== 'undefined'
46 ),
47 });
48
49 const view = new EditorView({
50 state: startState,
51 parent: editor.current,
52 });
53
54 return () => {
55 view.destroy();
56 };
57 }, [darkMode]);
58
59 return <div ref={editor}></div>;
60}

Callers

nothing calls this directly

Calls 4

useDarkModeFunction · 0.85
filterMethod · 0.65
ofMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected