()
| 57 | `; |
| 58 | |
| 59 | export default function Example() { |
| 60 | const [mode, setMode] = useState('js'); |
| 61 | const [placeholder, setPlaceholder] = useState('Please enter the code.'); |
| 62 | const [autofocus, setAutofocus] = useState(false); |
| 63 | const [editable, setEditable] = useState(true); |
| 64 | const { theme, setTheme } = useTheme(); |
| 65 | const [code, setCode] = useState(javascriptExample); |
| 66 | const [extensions, setExtensions] = useState<Extension[]>([color, langs.js()]); |
| 67 | const [height, setHeight] = useState('500px'); |
| 68 | const [basicSetup, setBasicSetup] = useState<BasicSetupOptions>({ |
| 69 | crosshairCursor: false, |
| 70 | }); |
| 71 | |
| 72 | function handleLangChange(lang: LanguageName) { |
| 73 | try { |
| 74 | import(`code-example/txt/sample.${lang.toLocaleLowerCase()}.txt`) |
| 75 | .then((data) => { |
| 76 | setCode(data.default); |
| 77 | let langFn = langs[lang]; |
| 78 | if (langFn && typeof langFn === 'function') { |
| 79 | setExtensions([color, langFn() as Extension]); |
| 80 | } |
| 81 | setMode(lang); |
| 82 | }) |
| 83 | .catch((err) => { |
| 84 | let langFn = langs[lang]; |
| 85 | if (langFn && typeof langFn === 'function') { |
| 86 | setExtensions([color, langFn() as Extension]); |
| 87 | } else { |
| 88 | setExtensions([color]); |
| 89 | } |
| 90 | setMode(lang); |
| 91 | setCode(''); |
| 92 | }); |
| 93 | if (lang === 'html') { |
| 94 | } |
| 95 | } catch (error) {} |
| 96 | } |
| 97 | |
| 98 | return ( |
| 99 | <Warpper className="wmde-markdown-var"> |
| 100 | <CodemirrorWarpper> |
| 101 | <CodeMirror |
| 102 | value={code} |
| 103 | height={`${height} !important`} |
| 104 | // @ts-ignore |
| 105 | theme={alls[theme as keyof typeof alls] || theme} |
| 106 | editable={editable} |
| 107 | extensions={extensions} |
| 108 | autoFocus={autofocus} |
| 109 | basicSetup={basicSetup} |
| 110 | placeholder={placeholder} |
| 111 | onChange={(val: string) => { |
| 112 | // https://github.com/uiwjs/react-codemirror/issues/449 |
| 113 | // setCode(val) |
| 114 | }} |
| 115 | style={{ |
| 116 | maxWidth: '995px', |
nothing calls this directly
no test coverage detected
searching dependent graphs…