Skip to content

Commit 5cef465

Browse files
committed
chore(deps): Update dependency codemirror to v6 (#327) (#88)
1 parent 8e90032 commit 5cef465

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

.kktrc.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LoaderConfOptions } from 'kkt';
44
import lessModules from '@kkt/less-modules';
55
import rawModules from '@kkt/raw-modules';
66
import scopePluginOptions from '@kkt/scope-plugin-options';
7+
import { mdCodeModulesLoader } from 'markdown-react-code-preview-loader';
78
import pkg from './package.json';
89

910
export default (conf: Configuration, env: 'development' | 'production', options: LoaderConfOptions) => {
@@ -74,9 +75,10 @@ export default (conf: Configuration, env: 'development' | 'production', options:
7475
} else {
7576
conf = rawModules(conf, env, {
7677
...options,
77-
test: /\.(txt|md)$/i,
78+
test: /\.(txt)$/i,
7879
esModule: true,
7980
});
81+
conf = mdCodeModulesLoader(conf);
8082
conf = scopePluginOptions(conf, env, {
8183
...options,
8284
allowedFiles: [path.resolve(process.cwd(), 'src'), path.resolve(process.cwd(), 'README.md')],

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,24 @@ npm install @uiw/react-codemirror --save
3737

3838
[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/embed/react-codemirror-example-codemirror-6-slvju?fontsize=14&hidenavigation=1&theme=dark)
3939

40-
```jsx
40+
```jsx mdx:preview
41+
import React from 'react';
4142
import CodeMirror from '@uiw/react-codemirror';
42-
import { javascript } from '@codemirror/lang-javascript';
43+
import * as lang from '@codemirror/lang-javascript';
4344

44-
export default function App() {
45+
function App() {
4546
return (
4647
<CodeMirror
4748
value="console.log('hello world!');"
4849
height="200px"
49-
extensions={[javascript({ jsx: true })]}
50+
// extensions={[lang.javascript({ jsx: true })]}
5051
onChange={(value, viewUpdate) => {
5152
console.log('value:', value);
5253
}}
5354
/>
5455
);
5556
}
57+
export default App;
5658
```
5759

5860
## Support Language

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@
6262
},
6363
"dependencies": {
6464
"@babel/runtime": ">=7.11.0",
65-
"@codemirror/basic-setup": "^0.20.0",
66-
"@codemirror/state": "^6.0.0",
6765
"@codemirror/theme-one-dark": "^6.0.0",
68-
"@codemirror/view": "^6.0.0"
66+
"codemirror": "^6.0.0"
6967
},
7068
"devDependencies": {
7169
"@codemirror/lang-cpp": "~6.0.0",
@@ -80,7 +78,6 @@
8078
"@codemirror/lang-rust": "~6.0.0",
8179
"@codemirror/lang-sql": "~6.0.0",
8280
"@codemirror/lang-xml": "~6.0.0",
83-
"@codemirror/language": "6.0.0",
8481
"@codemirror/legacy-modes": "~6.0.0",
8582
"@kkt/less-modules": "~7.1.1",
8683
"@kkt/ncc": "~1.0.8",
@@ -99,8 +96,10 @@
9996
"husky": "~8.0.0",
10097
"kkt": "~7.1.5",
10198
"lint-staged": "~13.0.0",
99+
"markdown-react-code-preview-loader": "^2.1.2",
102100
"prettier": "~2.6.0",
103101
"react": "~18.1.0",
102+
"react-code-preview-layout": "^2.0.2",
104103
"react-dom": "~18.1.0",
105104
"react-test-renderer": "~18.1.0",
106105
"tsbb": "~3.7.0"

src/index.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { EditorState, EditorStateConfig, Extension } from '@codemirror/state';
33
import { EditorView, ViewUpdate } from '@codemirror/view';
44
import { useCodeMirror } from './useCodeMirror';
55

6-
export * from '@codemirror/view';
7-
export * from '@codemirror/basic-setup';
8-
export * from '@codemirror/state';
96
export * from './useCodeMirror';
107

118
export interface ReactCodeMirrorProps

src/useCodeMirror.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from 'react';
2-
import { basicSetup } from '@codemirror/basic-setup';
2+
import { basicSetup } from 'codemirror';
33
import { EditorState, StateEffect } from '@codemirror/state';
44
import { indentWithTab } from '@codemirror/commands';
55
import { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';

website/App.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import { r } from '@codemirror/legacy-modes/mode/r';
4646
import logo from './logo.png';
4747
import styles from './App.module.less';
4848
import DocumentStr from '../README.md';
49-
import CodeMirror, { ReactCodeMirrorProps, Extension } from '..';
49+
import { Extension } from '@codemirror/state';
50+
import CodeMirror, { ReactCodeMirrorProps } from '..';
5051
import { Select } from './Select';
5152

5253
const langs: Record<string, any> = {
@@ -166,7 +167,7 @@ export default function App() {
166167
setTheme(e.detail.colorScheme as ReactCodeMirrorProps['theme']);
167168
});
168169
}, []);
169-
170+
console.log('DocumentStr:', DocumentStr);
170171
// @ts-ignore
171172
const version = VERSION;
172173
return (
@@ -250,7 +251,7 @@ export default function App() {
250251
<input type="text" value={placeholder} onChange={(evn) => setPlaceholder(evn.target.value)} />
251252
</label>
252253
</div>
253-
<MarkdownPreview className={styles.markdown} source={DocumentStr.replace(/([\s\S]*)<!--dividing-->/, '')} />
254+
<MarkdownPreview className={styles.markdown} source={DocumentStr.source} />
254255
<div className={styles.footer}>
255256
<Github user="uiwjs" repo="react-codemirror">
256257
<Github.Social type="forks" href="https://github.com/uiwjs/react-codemirror" />

website/react-app-env.d.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ declare module '*.module.less' {
55
export default classes;
66
}
77

8-
declare module '*.md' {
8+
declare module '*.txt' {
99
const src: string;
1010
export default src;
1111
}
1212

13-
declare module '*.txt' {
14-
const src: string;
13+
declare module '*.md' {
14+
import { CodeBlockData } from 'markdown-react-code-preview-loader';
15+
const src: CodeBlockData;
1516
export default src;
1617
}

0 commit comments

Comments
 (0)