1- import { defaultHighlightStyle , StreamLanguage , StreamParser , LanguageSupport } from "@codemirror/language" ;
2-
3- //modes imports
4- import { markdown } from "@codemirror/lang-markdown" ;
1+ //adapted v6 modes imports
2+ import { javascript } from "@codemirror/lang-javascript" ;
53import { json } from "@codemirror/lang-json" ;
4+ import { markdown } from "@codemirror/lang-markdown" ;
5+ import { sql } from "@codemirror/lang-sql" ;
66import { xml } from "@codemirror/lang-xml" ;
7- import { javascript } from "@codemirror/legacy-modes/mode/javascript" ;
7+ import { yaml } from "@codemirror/lang-yaml" ;
8+ import { defaultHighlightStyle , LanguageSupport , StreamLanguage , StreamParser } from "@codemirror/language" ;
9+ //legacy mode imports
10+ import { jinja2 } from "@codemirror/legacy-modes/mode/jinja2" ;
11+ import { mathematica } from "@codemirror/legacy-modes/mode/mathematica" ;
12+ import { ntriples } from "@codemirror/legacy-modes/mode/ntriples" ;
813import { python } from "@codemirror/legacy-modes/mode/python" ;
914import { sparql } from "@codemirror/legacy-modes/mode/sparql" ;
10- import { sql } from "@codemirror/legacy-modes/mode/sql" ;
1115import { turtle } from "@codemirror/legacy-modes/mode/turtle" ;
12- import { jinja2 } from "@codemirror/legacy-modes/mode/jinja2" ;
13- import { yaml } from "@codemirror/legacy-modes/mode/yaml" ;
14- import { ntriples } from "@codemirror/legacy-modes/mode/ntriples" ;
15- import { mathematica } from "@codemirror/legacy-modes/mode/mathematica" ;
1616
1717//adaptations
1818import { adaptedSyntaxHighlighting } from "../tests/codemirrorTestHelper" ;
@@ -35,10 +35,19 @@ const supportedModes = {
3535export const supportedCodeEditorModes = Object . keys ( supportedModes ) as Array < keyof typeof supportedModes > ;
3636export type SupportedCodeEditorModes = ( typeof supportedCodeEditorModes ) [ number ] ;
3737
38+ const v6AdaptedModes : ReadonlyMap < SupportedCodeEditorModes , boolean > = new Map ( [
39+ [ "json" , true ] ,
40+ [ "markdown" , true ] ,
41+ [ "xml" , true ] ,
42+ [ "sql" , true ] ,
43+ [ "yaml" , true ] ,
44+ [ "javascript" , true ] ,
45+ ] ) ;
46+
3847export const useCodeMirrorModeExtension = ( mode ?: SupportedCodeEditorModes ) => {
3948 return ! mode
4049 ? adaptedSyntaxHighlighting ( defaultHighlightStyle )
41- : [ "json" , "markdown" , "xml" ] . includes ( mode )
50+ : v6AdaptedModes . has ( mode )
4251 ? ( ( typeof supportedModes [ mode ] === "function" ? supportedModes [ mode ] : ( ) => { } ) as ( ) => LanguageSupport ) ( )
4352 : StreamLanguage ?. define ( supportedModes [ mode ] as StreamParser < unknown > ) ;
4453} ;
0 commit comments