@uiw/react-codemirror 4.7.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -8
- package/cjs/basicSetup.d.ts +65 -0
- package/cjs/basicSetup.js +119 -0
- package/cjs/basicSetup.js.map +49 -0
- package/cjs/index.d.ts +7 -4
- package/cjs/index.js +9 -37
- package/cjs/index.js.map +10 -6
- package/cjs/theme/light.js.map +5 -5
- package/cjs/useCodeMirror.d.ts +1 -2
- package/cjs/useCodeMirror.js +19 -9
- package/cjs/useCodeMirror.js.map +12 -8
- package/dist/{codemirror.js → mdeditor.js} +4019 -359
- package/dist/mdeditor.min.js +2 -0
- package/dist/{codemirror.min.js.LICENSE.txt → mdeditor.min.js.LICENSE.txt} +0 -0
- package/esm/basicSetup.d.ts +65 -0
- package/esm/basicSetup.js +103 -0
- package/esm/basicSetup.js.map +49 -0
- package/esm/index.d.ts +7 -4
- package/esm/index.js +1 -3
- package/esm/index.js.map +6 -6
- package/esm/theme/light.js.map +5 -5
- package/esm/useCodeMirror.d.ts +1 -2
- package/esm/useCodeMirror.js +13 -3
- package/esm/useCodeMirror.js.map +10 -8
- package/package.json +25 -90
- package/src/basicSetup.ts +136 -0
- package/src/index.tsx +7 -4
- package/src/useCodeMirror.ts +18 -4
- package/LICENSE +0 -21
- package/cjs/theme/light.d.ts +0 -1
- package/dist/codemirror.min.js +0 -2
- package/esm/theme/light.d.ts +0 -1
- package/src/tsconfig.json +0 -7
package/README.md
CHANGED
|
@@ -27,8 +27,9 @@ CodeMirror component for React. Demo Preview: [@uiwjs.github.io/react-codemirror
|
|
|
27
27
|
|
|
28
28
|
## Install
|
|
29
29
|
|
|
30
|
+
**Not dependent on uiw.**
|
|
31
|
+
|
|
30
32
|
```bash
|
|
31
|
-
# Not dependent on uiw.
|
|
32
33
|
npm install @uiw/react-codemirror --save
|
|
33
34
|
```
|
|
34
35
|
|
|
@@ -36,11 +37,12 @@ npm install @uiw/react-codemirror --save
|
|
|
36
37
|
|
|
37
38
|
[](https://codesandbox.io/embed/react-codemirror-example-codemirror-6-slvju?fontsize=14&hidenavigation=1&theme=dark)
|
|
38
39
|
|
|
39
|
-
```jsx
|
|
40
|
+
```jsx mdx:preview
|
|
41
|
+
import React from 'react';
|
|
40
42
|
import CodeMirror from '@uiw/react-codemirror';
|
|
41
43
|
import { javascript } from '@codemirror/lang-javascript';
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
function App() {
|
|
44
46
|
return (
|
|
45
47
|
<CodeMirror
|
|
46
48
|
value="console.log('hello world!');"
|
|
@@ -52,6 +54,7 @@ export default function App() {
|
|
|
52
54
|
/>
|
|
53
55
|
);
|
|
54
56
|
}
|
|
57
|
+
export default App;
|
|
55
58
|
```
|
|
56
59
|
|
|
57
60
|
## Support Language
|
|
@@ -60,7 +63,7 @@ export default function App() {
|
|
|
60
63
|
|
|
61
64
|
```jsx
|
|
62
65
|
import CodeMirror from '@uiw/react-codemirror';
|
|
63
|
-
import { StreamLanguage } from '@codemirror/
|
|
66
|
+
import { StreamLanguage } from '@codemirror/language';
|
|
64
67
|
import { go } from '@codemirror/legacy-modes/mode/go';
|
|
65
68
|
|
|
66
69
|
const goLang = `package main
|
|
@@ -170,16 +173,46 @@ export default function App() {
|
|
|
170
173
|
## Using custom theme
|
|
171
174
|
|
|
172
175
|
```jsx
|
|
173
|
-
import { oneDark } from '@codemirror/theme-one-dark';
|
|
174
176
|
import CodeMirror from '@uiw/react-codemirror';
|
|
177
|
+
import { createTheme } from '@uiw/codemirror-themes';
|
|
175
178
|
import { javascript } from '@codemirror/lang-javascript';
|
|
179
|
+
import { tags as t } from '@lezer/highlight';
|
|
180
|
+
|
|
181
|
+
const myTheme = createTheme({
|
|
182
|
+
variant: 'light',
|
|
183
|
+
settings: {
|
|
184
|
+
background: '#ffffff',
|
|
185
|
+
foreground: '#75baff',
|
|
186
|
+
caret: '#5d00ff',
|
|
187
|
+
selection: '#036dd626',
|
|
188
|
+
lineHighlight: '#8a91991a',
|
|
189
|
+
gutterBackground: '#fff',
|
|
190
|
+
gutterForeground: '#8a919966',
|
|
191
|
+
},
|
|
192
|
+
styles: [
|
|
193
|
+
{ tag: t.comment, color: '#787b8099' },
|
|
194
|
+
{ tag: t.variableName, color: '#0080ff' },
|
|
195
|
+
{ tag: [t.string, t.special(t.brace)], color: '#5c6166' },
|
|
196
|
+
{ tag: t.number, color: '#5c6166' },
|
|
197
|
+
{ tag: t.bool, color: '#5c6166' },
|
|
198
|
+
{ tag: t.null, color: '#5c6166' },
|
|
199
|
+
{ tag: t.keyword, color: '#5c6166' },
|
|
200
|
+
{ tag: t.operator, color: '#5c6166' },
|
|
201
|
+
{ tag: t.className, color: '#5c6166' },
|
|
202
|
+
{ tag: t.definition(t.typeName), color: '#5c6166' },
|
|
203
|
+
{ tag: t.typeName, color: '#5c6166' },
|
|
204
|
+
{ tag: t.angleBracket, color: '#5c6166' },
|
|
205
|
+
{ tag: t.tagName, color: '#5c6166' },
|
|
206
|
+
{ tag: t.attributeName, color: '#5c6166' },
|
|
207
|
+
],
|
|
208
|
+
});
|
|
176
209
|
|
|
177
210
|
export default function App() {
|
|
178
211
|
return (
|
|
179
212
|
<CodeMirror
|
|
180
213
|
value="console.log('hello world!');"
|
|
181
|
-
height="
|
|
182
|
-
theme={
|
|
214
|
+
height="200px"
|
|
215
|
+
theme={myTheme}
|
|
183
216
|
extensions={[javascript({ jsx: true })]}
|
|
184
217
|
onChange={(value, viewUpdate) => {
|
|
185
218
|
console.log('value:', value);
|
|
@@ -240,7 +273,7 @@ export interface ReactCodeMirrorProps
|
|
|
240
273
|
* Whether to optional basicSetup by default
|
|
241
274
|
* @default true
|
|
242
275
|
*/
|
|
243
|
-
basicSetup?: boolean;
|
|
276
|
+
basicSetup?: boolean | BasicSetupOptions;
|
|
244
277
|
/**
|
|
245
278
|
* This disables editing of the editor content by the user.
|
|
246
279
|
* @default true
|
|
@@ -282,6 +315,32 @@ declare const ReactCodeMirror: React.ForwardRefExoticComponent<
|
|
|
282
315
|
ReactCodeMirrorProps & React.RefAttributes<ReactCodeMirrorRef>
|
|
283
316
|
>;
|
|
284
317
|
export default ReactCodeMirror;
|
|
318
|
+
export interface BasicSetupOptions {
|
|
319
|
+
lineNumbers?: boolean;
|
|
320
|
+
highlightActiveLineGutter?: boolean;
|
|
321
|
+
highlightSpecialChars?: boolean;
|
|
322
|
+
history?: boolean;
|
|
323
|
+
foldGutter?: boolean;
|
|
324
|
+
drawSelection?: boolean;
|
|
325
|
+
dropCursor?: boolean;
|
|
326
|
+
allowMultipleSelections?: boolean;
|
|
327
|
+
indentOnInput?: boolean;
|
|
328
|
+
syntaxHighlighting?: boolean;
|
|
329
|
+
bracketMatching?: boolean;
|
|
330
|
+
closeBrackets?: boolean;
|
|
331
|
+
autocompletion?: boolean;
|
|
332
|
+
rectangularSelection?: boolean;
|
|
333
|
+
crosshairCursor?: boolean;
|
|
334
|
+
highlightActiveLine?: boolean;
|
|
335
|
+
highlightSelectionMatches?: boolean;
|
|
336
|
+
closeBracketsKeymap?: boolean;
|
|
337
|
+
defaultKeymap?: boolean;
|
|
338
|
+
searchKeymap?: boolean;
|
|
339
|
+
historyKeymap?: boolean;
|
|
340
|
+
foldKeymap?: boolean;
|
|
341
|
+
completionKeymap?: boolean;
|
|
342
|
+
lintKeymap?: boolean;
|
|
343
|
+
}
|
|
285
344
|
```
|
|
286
345
|
|
|
287
346
|
### Related
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
export interface BasicSetupOptions {
|
|
3
|
+
lineNumbers?: boolean;
|
|
4
|
+
highlightActiveLineGutter?: boolean;
|
|
5
|
+
highlightSpecialChars?: boolean;
|
|
6
|
+
history?: boolean;
|
|
7
|
+
foldGutter?: boolean;
|
|
8
|
+
drawSelection?: boolean;
|
|
9
|
+
dropCursor?: boolean;
|
|
10
|
+
allowMultipleSelections?: boolean;
|
|
11
|
+
indentOnInput?: boolean;
|
|
12
|
+
syntaxHighlighting?: boolean;
|
|
13
|
+
bracketMatching?: boolean;
|
|
14
|
+
closeBrackets?: boolean;
|
|
15
|
+
autocompletion?: boolean;
|
|
16
|
+
rectangularSelection?: boolean;
|
|
17
|
+
crosshairCursor?: boolean;
|
|
18
|
+
highlightActiveLine?: boolean;
|
|
19
|
+
highlightSelectionMatches?: boolean;
|
|
20
|
+
closeBracketsKeymap?: boolean;
|
|
21
|
+
defaultKeymap?: boolean;
|
|
22
|
+
searchKeymap?: boolean;
|
|
23
|
+
historyKeymap?: boolean;
|
|
24
|
+
foldKeymap?: boolean;
|
|
25
|
+
completionKeymap?: boolean;
|
|
26
|
+
lintKeymap?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
This is an extension value that just pulls together a number of
|
|
30
|
+
extensions that you might want in a basic editor. It is meant as a
|
|
31
|
+
convenient helper to quickly set up CodeMirror without installing
|
|
32
|
+
and importing a lot of separate packages.
|
|
33
|
+
|
|
34
|
+
Specifically, it includes...
|
|
35
|
+
|
|
36
|
+
- [the default command bindings](https://codemirror.net/6/docs/ref/#commands.defaultKeymap)
|
|
37
|
+
- [line numbers](https://codemirror.net/6/docs/ref/#view.lineNumbers)
|
|
38
|
+
- [special character highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars)
|
|
39
|
+
- [the undo history](https://codemirror.net/6/docs/ref/#commands.history)
|
|
40
|
+
- [a fold gutter](https://codemirror.net/6/docs/ref/#language.foldGutter)
|
|
41
|
+
- [custom selection drawing](https://codemirror.net/6/docs/ref/#view.drawSelection)
|
|
42
|
+
- [drop cursor](https://codemirror.net/6/docs/ref/#view.dropCursor)
|
|
43
|
+
- [multiple selections](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
|
|
44
|
+
- [reindentation on input](https://codemirror.net/6/docs/ref/#language.indentOnInput)
|
|
45
|
+
- [the default highlight style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle) (as fallback)
|
|
46
|
+
- [bracket matching](https://codemirror.net/6/docs/ref/#language.bracketMatching)
|
|
47
|
+
- [bracket closing](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets)
|
|
48
|
+
- [autocompletion](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion)
|
|
49
|
+
- [rectangular selection](https://codemirror.net/6/docs/ref/#view.rectangularSelection) and [crosshair cursor](https://codemirror.net/6/docs/ref/#view.crosshairCursor)
|
|
50
|
+
- [active line highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLine)
|
|
51
|
+
- [active line gutter highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLineGutter)
|
|
52
|
+
- [selection match highlighting](https://codemirror.net/6/docs/ref/#search.highlightSelectionMatches)
|
|
53
|
+
- [search](https://codemirror.net/6/docs/ref/#search.searchKeymap)
|
|
54
|
+
- [linting](https://codemirror.net/6/docs/ref/#lint.lintKeymap)
|
|
55
|
+
|
|
56
|
+
(You'll probably want to add some language package to your setup
|
|
57
|
+
too.)
|
|
58
|
+
|
|
59
|
+
This extension does not allow customization. The idea is that,
|
|
60
|
+
once you decide you want to configure your editor more precisely,
|
|
61
|
+
you take this package's source (which is just a bunch of imports
|
|
62
|
+
and an array literal), copy it into your own code, and adjust it
|
|
63
|
+
as desired.
|
|
64
|
+
*/
|
|
65
|
+
export declare const basicSetup: (options?: BasicSetupOptions) => Extension[];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.basicSetup = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _view = require("@codemirror/view");
|
|
13
|
+
|
|
14
|
+
var _state = require("@codemirror/state");
|
|
15
|
+
|
|
16
|
+
var _commands = require("@codemirror/commands");
|
|
17
|
+
|
|
18
|
+
var _search = require("@codemirror/search");
|
|
19
|
+
|
|
20
|
+
var _autocomplete = require("@codemirror/autocomplete");
|
|
21
|
+
|
|
22
|
+
var _language = require("@codemirror/language");
|
|
23
|
+
|
|
24
|
+
var _lint = require("@codemirror/lint");
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
This is an extension value that just pulls together a number of
|
|
28
|
+
extensions that you might want in a basic editor. It is meant as a
|
|
29
|
+
convenient helper to quickly set up CodeMirror without installing
|
|
30
|
+
and importing a lot of separate packages.
|
|
31
|
+
|
|
32
|
+
Specifically, it includes...
|
|
33
|
+
|
|
34
|
+
- [the default command bindings](https://codemirror.net/6/docs/ref/#commands.defaultKeymap)
|
|
35
|
+
- [line numbers](https://codemirror.net/6/docs/ref/#view.lineNumbers)
|
|
36
|
+
- [special character highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars)
|
|
37
|
+
- [the undo history](https://codemirror.net/6/docs/ref/#commands.history)
|
|
38
|
+
- [a fold gutter](https://codemirror.net/6/docs/ref/#language.foldGutter)
|
|
39
|
+
- [custom selection drawing](https://codemirror.net/6/docs/ref/#view.drawSelection)
|
|
40
|
+
- [drop cursor](https://codemirror.net/6/docs/ref/#view.dropCursor)
|
|
41
|
+
- [multiple selections](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)
|
|
42
|
+
- [reindentation on input](https://codemirror.net/6/docs/ref/#language.indentOnInput)
|
|
43
|
+
- [the default highlight style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle) (as fallback)
|
|
44
|
+
- [bracket matching](https://codemirror.net/6/docs/ref/#language.bracketMatching)
|
|
45
|
+
- [bracket closing](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets)
|
|
46
|
+
- [autocompletion](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion)
|
|
47
|
+
- [rectangular selection](https://codemirror.net/6/docs/ref/#view.rectangularSelection) and [crosshair cursor](https://codemirror.net/6/docs/ref/#view.crosshairCursor)
|
|
48
|
+
- [active line highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLine)
|
|
49
|
+
- [active line gutter highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLineGutter)
|
|
50
|
+
- [selection match highlighting](https://codemirror.net/6/docs/ref/#search.highlightSelectionMatches)
|
|
51
|
+
- [search](https://codemirror.net/6/docs/ref/#search.searchKeymap)
|
|
52
|
+
- [linting](https://codemirror.net/6/docs/ref/#lint.lintKeymap)
|
|
53
|
+
|
|
54
|
+
(You'll probably want to add some language package to your setup
|
|
55
|
+
too.)
|
|
56
|
+
|
|
57
|
+
This extension does not allow customization. The idea is that,
|
|
58
|
+
once you decide you want to configure your editor more precisely,
|
|
59
|
+
you take this package's source (which is just a bunch of imports
|
|
60
|
+
and an array literal), copy it into your own code, and adjust it
|
|
61
|
+
as desired.
|
|
62
|
+
*/
|
|
63
|
+
var basicSetup = function basicSetup() {
|
|
64
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
65
|
+
var keymaps = [];
|
|
66
|
+
|
|
67
|
+
if (options.closeBracketsKeymap !== false) {
|
|
68
|
+
keymaps.push((0, _toConsumableArray2["default"])(_autocomplete.closeBracketsKeymap));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (options.defaultKeymap !== false) {
|
|
72
|
+
keymaps.push((0, _toConsumableArray2["default"])(_commands.defaultKeymap));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (options.searchKeymap !== false) {
|
|
76
|
+
keymaps.push((0, _toConsumableArray2["default"])(_search.searchKeymap));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (options.historyKeymap !== false) {
|
|
80
|
+
keymaps.push((0, _toConsumableArray2["default"])(_commands.historyKeymap));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (options.foldKeymap !== false) {
|
|
84
|
+
keymaps.push((0, _toConsumableArray2["default"])(_language.foldKeymap));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (options.completionKeymap !== false) {
|
|
88
|
+
keymaps.push((0, _toConsumableArray2["default"])(_autocomplete.completionKeymap));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (options.lintKeymap !== false) {
|
|
92
|
+
keymaps.push((0, _toConsumableArray2["default"])(_lint.lintKeymap));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var extensions = [];
|
|
96
|
+
if (options.lineNumbers !== false) extensions.push((0, _view.lineNumbers)());
|
|
97
|
+
if (options.highlightActiveLineGutter !== false) extensions.push((0, _view.highlightActiveLineGutter)());
|
|
98
|
+
if (options.highlightSpecialChars !== false) extensions.push((0, _view.highlightSpecialChars)());
|
|
99
|
+
if (options.history !== false) extensions.push((0, _commands.history)());
|
|
100
|
+
if (options.foldGutter !== false) extensions.push((0, _language.foldGutter)());
|
|
101
|
+
if (options.drawSelection !== false) extensions.push((0, _view.drawSelection)());
|
|
102
|
+
if (options.dropCursor !== false) extensions.push((0, _view.dropCursor)());
|
|
103
|
+
if (options.allowMultipleSelections !== false) extensions.push(_state.EditorState.allowMultipleSelections.of(true));
|
|
104
|
+
if (options.indentOnInput !== false) extensions.push((0, _language.indentOnInput)());
|
|
105
|
+
if (options.syntaxHighlighting !== false) extensions.push((0, _language.syntaxHighlighting)(_language.defaultHighlightStyle, {
|
|
106
|
+
fallback: true
|
|
107
|
+
}));
|
|
108
|
+
if (options.bracketMatching !== false) extensions.push((0, _language.bracketMatching)());
|
|
109
|
+
if (options.closeBrackets !== false) extensions.push((0, _autocomplete.closeBrackets)());
|
|
110
|
+
if (options.autocompletion !== false) extensions.push((0, _autocomplete.autocompletion)());
|
|
111
|
+
if (options.rectangularSelection !== false) extensions.push((0, _view.rectangularSelection)());
|
|
112
|
+
if (options.crosshairCursor !== false) extensions.push((0, _view.crosshairCursor)());
|
|
113
|
+
if (options.highlightActiveLine !== false) extensions.push((0, _view.highlightActiveLine)());
|
|
114
|
+
if (options.highlightSelectionMatches !== false) extensions.push((0, _search.highlightSelectionMatches)());
|
|
115
|
+
return [].concat(extensions, [_view.keymap.of(keymaps.flat())]).filter(Boolean);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
exports.basicSetup = basicSetup;
|
|
119
|
+
//# sourceMappingURL=basicSetup.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"names": [
|
|
4
|
+
"basicSetup",
|
|
5
|
+
"options",
|
|
6
|
+
"keymaps",
|
|
7
|
+
"closeBracketsKeymap",
|
|
8
|
+
"push",
|
|
9
|
+
"defaultKeymap",
|
|
10
|
+
"searchKeymap",
|
|
11
|
+
"historyKeymap",
|
|
12
|
+
"foldKeymap",
|
|
13
|
+
"completionKeymap",
|
|
14
|
+
"lintKeymap",
|
|
15
|
+
"extensions",
|
|
16
|
+
"lineNumbers",
|
|
17
|
+
"highlightActiveLineGutter",
|
|
18
|
+
"highlightSpecialChars",
|
|
19
|
+
"history",
|
|
20
|
+
"foldGutter",
|
|
21
|
+
"drawSelection",
|
|
22
|
+
"dropCursor",
|
|
23
|
+
"allowMultipleSelections",
|
|
24
|
+
"EditorState",
|
|
25
|
+
"of",
|
|
26
|
+
"indentOnInput",
|
|
27
|
+
"syntaxHighlighting",
|
|
28
|
+
"defaultHighlightStyle",
|
|
29
|
+
"fallback",
|
|
30
|
+
"bracketMatching",
|
|
31
|
+
"closeBrackets",
|
|
32
|
+
"autocompletion",
|
|
33
|
+
"rectangularSelection",
|
|
34
|
+
"crosshairCursor",
|
|
35
|
+
"highlightActiveLine",
|
|
36
|
+
"highlightSelectionMatches",
|
|
37
|
+
"keymap",
|
|
38
|
+
"flat",
|
|
39
|
+
"filter",
|
|
40
|
+
"Boolean"
|
|
41
|
+
],
|
|
42
|
+
"sources": [
|
|
43
|
+
"../src/basicSetup.ts"
|
|
44
|
+
],
|
|
45
|
+
"sourcesContent": [
|
|
46
|
+
"import {\n KeyBinding,\n lineNumbers,\n highlightActiveLineGutter,\n highlightSpecialChars,\n drawSelection,\n dropCursor,\n rectangularSelection,\n crosshairCursor,\n highlightActiveLine,\n keymap,\n} from '@codemirror/view';\nimport { EditorState, Extension } from '@codemirror/state';\nimport { history, defaultKeymap, historyKeymap } from '@codemirror/commands';\nimport { highlightSelectionMatches, searchKeymap } from '@codemirror/search';\nimport { closeBrackets, autocompletion, closeBracketsKeymap, completionKeymap } from '@codemirror/autocomplete';\nimport {\n foldGutter,\n indentOnInput,\n syntaxHighlighting,\n defaultHighlightStyle,\n bracketMatching,\n foldKeymap,\n} from '@codemirror/language';\nimport { lintKeymap } from '@codemirror/lint';\n\nexport interface BasicSetupOptions {\n lineNumbers?: boolean;\n highlightActiveLineGutter?: boolean;\n highlightSpecialChars?: boolean;\n history?: boolean;\n foldGutter?: boolean;\n drawSelection?: boolean;\n dropCursor?: boolean;\n allowMultipleSelections?: boolean;\n indentOnInput?: boolean;\n syntaxHighlighting?: boolean;\n bracketMatching?: boolean;\n closeBrackets?: boolean;\n autocompletion?: boolean;\n rectangularSelection?: boolean;\n crosshairCursor?: boolean;\n highlightActiveLine?: boolean;\n highlightSelectionMatches?: boolean;\n\n closeBracketsKeymap?: boolean;\n defaultKeymap?: boolean;\n searchKeymap?: boolean;\n historyKeymap?: boolean;\n foldKeymap?: boolean;\n completionKeymap?: boolean;\n lintKeymap?: boolean;\n}\n\n/**\nThis is an extension value that just pulls together a number of\nextensions that you might want in a basic editor. It is meant as a\nconvenient helper to quickly set up CodeMirror without installing\nand importing a lot of separate packages.\n\nSpecifically, it includes...\n\n - [the default command bindings](https://codemirror.net/6/docs/ref/#commands.defaultKeymap)\n - [line numbers](https://codemirror.net/6/docs/ref/#view.lineNumbers)\n - [special character highlighting](https://codemirror.net/6/docs/ref/#view.highlightSpecialChars)\n - [the undo history](https://codemirror.net/6/docs/ref/#commands.history)\n - [a fold gutter](https://codemirror.net/6/docs/ref/#language.foldGutter)\n - [custom selection drawing](https://codemirror.net/6/docs/ref/#view.drawSelection)\n - [drop cursor](https://codemirror.net/6/docs/ref/#view.dropCursor)\n - [multiple selections](https://codemirror.net/6/docs/ref/#state.EditorState^allowMultipleSelections)\n - [reindentation on input](https://codemirror.net/6/docs/ref/#language.indentOnInput)\n - [the default highlight style](https://codemirror.net/6/docs/ref/#language.defaultHighlightStyle) (as fallback)\n - [bracket matching](https://codemirror.net/6/docs/ref/#language.bracketMatching)\n - [bracket closing](https://codemirror.net/6/docs/ref/#autocomplete.closeBrackets)\n - [autocompletion](https://codemirror.net/6/docs/ref/#autocomplete.autocompletion)\n - [rectangular selection](https://codemirror.net/6/docs/ref/#view.rectangularSelection) and [crosshair cursor](https://codemirror.net/6/docs/ref/#view.crosshairCursor)\n - [active line highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLine)\n - [active line gutter highlighting](https://codemirror.net/6/docs/ref/#view.highlightActiveLineGutter)\n - [selection match highlighting](https://codemirror.net/6/docs/ref/#search.highlightSelectionMatches)\n - [search](https://codemirror.net/6/docs/ref/#search.searchKeymap)\n - [linting](https://codemirror.net/6/docs/ref/#lint.lintKeymap)\n\n(You'll probably want to add some language package to your setup\ntoo.)\n\nThis extension does not allow customization. The idea is that,\nonce you decide you want to configure your editor more precisely,\nyou take this package's source (which is just a bunch of imports\nand an array literal), copy it into your own code, and adjust it\nas desired.\n*/\nexport const basicSetup = (options: BasicSetupOptions = {}): Extension[] => {\n const keymaps: KeyBinding[][] = [];\n if (options.closeBracketsKeymap !== false) {\n keymaps.push([...closeBracketsKeymap]);\n }\n if (options.defaultKeymap !== false) {\n keymaps.push([...defaultKeymap]);\n }\n if (options.searchKeymap !== false) {\n keymaps.push([...searchKeymap]);\n }\n if (options.historyKeymap !== false) {\n keymaps.push([...historyKeymap]);\n }\n if (options.foldKeymap !== false) {\n keymaps.push([...foldKeymap]);\n }\n if (options.completionKeymap !== false) {\n keymaps.push([...completionKeymap]);\n }\n if (options.lintKeymap !== false) {\n keymaps.push([...lintKeymap]);\n }\n const extensions: Extension[] = [];\n if (options.lineNumbers !== false) extensions.push(lineNumbers());\n if (options.highlightActiveLineGutter !== false) extensions.push(highlightActiveLineGutter());\n if (options.highlightSpecialChars !== false) extensions.push(highlightSpecialChars());\n if (options.history !== false) extensions.push(history());\n if (options.foldGutter !== false) extensions.push(foldGutter());\n if (options.drawSelection !== false) extensions.push(drawSelection());\n if (options.dropCursor !== false) extensions.push(dropCursor());\n if (options.allowMultipleSelections !== false) extensions.push(EditorState.allowMultipleSelections.of(true));\n if (options.indentOnInput !== false) extensions.push(indentOnInput());\n if (options.syntaxHighlighting !== false)\n extensions.push(syntaxHighlighting(defaultHighlightStyle, { fallback: true }));\n if (options.bracketMatching !== false) extensions.push(bracketMatching());\n if (options.closeBrackets !== false) extensions.push(closeBrackets());\n if (options.autocompletion !== false) extensions.push(autocompletion());\n if (options.rectangularSelection !== false) extensions.push(rectangularSelection());\n if (options.crosshairCursor !== false) extensions.push(crosshairCursor());\n if (options.highlightActiveLine !== false) extensions.push(highlightActiveLine());\n if (options.highlightSelectionMatches !== false) extensions.push(highlightSelectionMatches());\n\n return [...extensions, keymap.of(keymaps.flat())].filter(Boolean);\n};\n"
|
|
47
|
+
],
|
|
48
|
+
"mappings": ";;;;;;;;;;;AAAA;;AAYA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AA8BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,UAAU,GAAG,SAAbA,UAAa,GAAkD;EAAA,IAAjDC,OAAiD,uEAApB,EAAoB;EAC1E,IAAMC,OAAuB,GAAG,EAAhC;;EACA,IAAID,OAAO,CAACE,mBAAR,KAAgC,KAApC,EAA2C;IACzCD,OAAO,CAAC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AO,CAAC+B,yBAAR,KAAsC,KAA1C,EAAiDrB,UAAU,CAACP,IAAX,CAAgB,IAAA4B,iCAAA,GAAhB;EAEjD,OAAO,UAAIrB,UAAJ,GAAgBsB,YAAA,CAAOZ,EAAP,CAAUnB,OAAO,CAACgC,IAAR,EAAV,CAAhB,GAA2CC,MAA3C,CAAkDC,OAAlD,CAAP;AACD,CA5CM"
|
|
49
|
+
}
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { EditorState, EditorStateConfig, Extension } from '@codemirror/state';
|
|
3
3
|
import { EditorView, ViewUpdate } from '@codemirror/view';
|
|
4
|
-
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '@codemirror/state';
|
|
4
|
+
import { BasicSetupOptions } from './basicSetup';
|
|
5
|
+
export * from './basicSetup';
|
|
7
6
|
export * from './useCodeMirror';
|
|
8
7
|
export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'extensions'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
|
|
9
8
|
/** value of the auto created model in the editor. */
|
|
@@ -27,12 +26,16 @@ export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'e
|
|
|
27
26
|
* Whether to optional basicSetup by default
|
|
28
27
|
* @default true
|
|
29
28
|
*/
|
|
30
|
-
basicSetup?: boolean;
|
|
29
|
+
basicSetup?: boolean | BasicSetupOptions;
|
|
31
30
|
/**
|
|
32
31
|
* This disables editing of the editor content by the user.
|
|
33
32
|
* @default true
|
|
34
33
|
*/
|
|
35
34
|
editable?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* This disables editing of the editor content by the user.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
36
39
|
readOnly?: boolean;
|
|
37
40
|
/**
|
|
38
41
|
* Whether to optional basicSetup by default
|
package/cjs/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
4
|
|
|
5
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
10
|
var _exportNames = {};
|
|
11
|
-
exports
|
|
11
|
+
exports["default"] = void 0;
|
|
12
12
|
|
|
13
13
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
14
14
|
|
|
@@ -34,21 +34,7 @@ Object.keys(_useCodeMirror2).forEach(function (key) {
|
|
|
34
34
|
|
|
35
35
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
36
36
|
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
Object.keys(_view).forEach(function (key) {
|
|
40
|
-
if (key === "default" || key === "__esModule") return;
|
|
41
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
42
|
-
if (key in exports && exports[key] === _view[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function get() {
|
|
46
|
-
return _view[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
var _basicSetup = require("@codemirror/basic-setup");
|
|
37
|
+
var _basicSetup = require("./basicSetup");
|
|
52
38
|
|
|
53
39
|
Object.keys(_basicSetup).forEach(function (key) {
|
|
54
40
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -61,23 +47,9 @@ Object.keys(_basicSetup).forEach(function (key) {
|
|
|
61
47
|
}
|
|
62
48
|
});
|
|
63
49
|
});
|
|
64
|
-
|
|
65
|
-
var _state = require("@codemirror/state");
|
|
66
|
-
|
|
67
|
-
Object.keys(_state).forEach(function (key) {
|
|
68
|
-
if (key === "default" || key === "__esModule") return;
|
|
69
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
70
|
-
if (key in exports && exports[key] === _state[key]) return;
|
|
71
|
-
Object.defineProperty(exports, key, {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function get() {
|
|
74
|
-
return _state[key];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
50
|
var _excluded = ["className", "value", "selection", "extensions", "onChange", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable", "readOnly", "root"];
|
|
79
51
|
|
|
80
|
-
var ReactCodeMirror = /*#__PURE__*/_react
|
|
52
|
+
var ReactCodeMirror = /*#__PURE__*/_react["default"].forwardRef(function (props, ref) {
|
|
81
53
|
var className = props.className,
|
|
82
54
|
_props$value = props.value,
|
|
83
55
|
value = _props$value === void 0 ? '' : _props$value,
|
|
@@ -101,7 +73,7 @@ var ReactCodeMirror = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
101
73
|
editable = props.editable,
|
|
102
74
|
readOnly = props.readOnly,
|
|
103
75
|
root = props.root,
|
|
104
|
-
other = (0, _objectWithoutProperties2
|
|
76
|
+
other = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
105
77
|
var editor = (0, _react.useRef)(null);
|
|
106
78
|
|
|
107
79
|
var _useCodeMirror = (0, _useCodeMirror2.useCodeMirror)({
|
|
@@ -143,11 +115,11 @@ var ReactCodeMirror = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
143
115
|
}, []); // check type of value
|
|
144
116
|
|
|
145
117
|
if (typeof value !== 'string') {
|
|
146
|
-
throw new Error("value must be typeof string but got ".concat((0, _typeof2
|
|
118
|
+
throw new Error("value must be typeof string but got ".concat((0, _typeof2["default"])(value)));
|
|
147
119
|
}
|
|
148
120
|
|
|
149
121
|
var defaultClassNames = typeof theme === 'string' ? "cm-theme-".concat(theme) : 'cm-theme';
|
|
150
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2
|
|
122
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({
|
|
151
123
|
ref: editor,
|
|
152
124
|
className: "".concat(defaultClassNames).concat(className ? " ".concat(className) : '')
|
|
153
125
|
}, other));
|
|
@@ -155,5 +127,5 @@ var ReactCodeMirror = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
155
127
|
|
|
156
128
|
ReactCodeMirror.displayName = 'CodeMirror';
|
|
157
129
|
var _default = ReactCodeMirror;
|
|
158
|
-
exports
|
|
130
|
+
exports["default"] = _default;
|
|
159
131
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../src/index.tsx"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"ReactCodeMirror",
|
|
8
5
|
"React",
|
|
@@ -31,17 +28,24 @@
|
|
|
31
28
|
"root",
|
|
32
29
|
"other",
|
|
33
30
|
"editor",
|
|
31
|
+
"useRef",
|
|
32
|
+
"useCodeMirror",
|
|
34
33
|
"container",
|
|
35
34
|
"current",
|
|
36
35
|
"state",
|
|
37
36
|
"view",
|
|
38
37
|
"setContainer",
|
|
38
|
+
"useImperativeHandle",
|
|
39
|
+
"useEffect",
|
|
39
40
|
"Error",
|
|
40
41
|
"defaultClassNames",
|
|
41
42
|
"displayName"
|
|
42
43
|
],
|
|
43
|
-
"
|
|
44
|
+
"sources": [
|
|
45
|
+
"../src/index.tsx"
|
|
46
|
+
],
|
|
44
47
|
"sourcesContent": [
|
|
45
|
-
"import React, { useEffect, useRef, useImperativeHandle } from 'react';\nimport { EditorState, EditorStateConfig, Extension } from '@codemirror/state';\nimport { EditorView, ViewUpdate } from '@codemirror/view';\nimport { useCodeMirror } from './useCodeMirror';\
|
|
46
|
-
]
|
|
48
|
+
"import React, { useEffect, useRef, useImperativeHandle } from 'react';\nimport { EditorState, EditorStateConfig, Extension } from '@codemirror/state';\nimport { EditorView, ViewUpdate } from '@codemirror/view';\nimport { useCodeMirror } from './useCodeMirror';\nimport { BasicSetupOptions } from './basicSetup';\n\nexport * from './basicSetup';\nexport * from './useCodeMirror';\n\nexport interface ReactCodeMirrorProps\n extends Omit<EditorStateConfig, 'doc' | 'extensions'>,\n Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {\n /** value of the auto created model in the editor. */\n value?: string;\n height?: string;\n minHeight?: string;\n maxHeight?: string;\n width?: string;\n minWidth?: string;\n maxWidth?: string;\n /** focus on the editor. */\n autoFocus?: boolean;\n /** Enables a placeholder—a piece of example content to show when the editor is empty. */\n placeholder?: string | HTMLElement;\n /**\n * `light` / `dark` / `Extension` Defaults to `light`.\n * @default light\n */\n theme?: 'light' | 'dark' | Extension;\n /**\n * Whether to optional basicSetup by default\n * @default true\n */\n basicSetup?: boolean | BasicSetupOptions;\n /**\n * This disables editing of the editor content by the user.\n * @default true\n */\n editable?: boolean;\n /**\n * This disables editing of the editor content by the user.\n * @default false\n */\n readOnly?: boolean;\n /**\n * Whether to optional basicSetup by default\n * @default true\n */\n indentWithTab?: boolean;\n /** Fired whenever a change occurs to the document. */\n onChange?(value: string, viewUpdate: ViewUpdate): void;\n /** Fired whenever a change occurs to the document. There is a certain difference with `onChange`. */\n onUpdate?(viewUpdate: ViewUpdate): void;\n /**\n * Extension values can be [provided](https://codemirror.net/6/docs/ref/#state.EditorStateConfig.extensions) when creating a state to attach various kinds of configuration and behavior information.\n * They can either be built-in extension-providing objects,\n * such as [state fields](https://codemirror.net/6/docs/ref/#state.StateField) or [facet providers](https://codemirror.net/6/docs/ref/#state.Facet.of),\n * or objects with an extension in its `extension` property. Extensions can be nested in arrays arbitrarily deep—they will be flattened when processed.\n */\n extensions?: Extension[];\n /**\n * If the view is going to be mounted in a shadow root or document other than the one held by the global variable document (the default), you should pass it here.\n * Originally from the [config of EditorView](https://codemirror.net/6/docs/ref/#view.EditorView.constructor%5Econfig.root)\n */\n root?: ShadowRoot | Document;\n}\n\nexport interface ReactCodeMirrorRef {\n editor?: HTMLDivElement | null;\n state?: EditorState;\n view?: EditorView;\n}\n\nconst ReactCodeMirror = React.forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((props, ref) => {\n const {\n className,\n value = '',\n selection,\n extensions = [],\n onChange,\n onUpdate,\n autoFocus,\n theme = 'light',\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n basicSetup,\n placeholder,\n indentWithTab,\n editable,\n readOnly,\n root,\n ...other\n } = props;\n const editor = useRef<HTMLDivElement>(null);\n const { state, view, container, setContainer } = useCodeMirror({\n container: editor.current,\n root,\n value,\n autoFocus,\n theme,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n basicSetup,\n placeholder,\n indentWithTab,\n editable,\n readOnly,\n selection,\n onChange,\n onUpdate,\n extensions,\n });\n useImperativeHandle(ref, () => ({ editor: container, state, view }), [container, state, view]);\n useEffect(() => {\n setContainer(editor.current);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // check type of value\n if (typeof value !== 'string') {\n throw new Error(`value must be typeof string but got ${typeof value}`);\n }\n\n const defaultClassNames = typeof theme === 'string' ? `cm-theme-${theme}` : 'cm-theme';\n return <div ref={editor} className={`${defaultClassNames}${className ? ` ${className}` : ''}`} {...other}></div>;\n});\n\nReactCodeMirror.displayName = 'CodeMirror';\n\nexport default ReactCodeMirror;\n"
|
|
49
|
+
],
|
|
50
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;;AAGA;;AAIA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;;;AADA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AI,OAAOxB,KAAP,KAAiB,QAArB,EAA+B;IAC7B,MAAM,IAAI8B,KAAJ,wEAAwD9B,KAAxD,GAAN;EACD;;EAED,IAAM+B,iBAAiB,GAAG,OAAOzB,KAAP,KAAiB,QAAjB,sBAAwCA,KAAxC,IAAkD,UAA5E;EACA,oBAAO;IAAK,GAAG,EAAEc,MAAV;IAAkB,SAAS,YAAKW,iBAAL,SAAyBhC,SAAS,cAAOA,SAAP,IAAqB,EAAvD;EAA3B,GAA4FoB,KAA5F,EAAP;AACD,CA5DuB,CAAxB;;AA8DAzB,eAAe,CAACsC,WAAhB,GAA8B,YAA9B;eAEetC,e"
|
|
47
51
|
}
|
package/cjs/theme/light.js.map
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"../../src/theme/light.ts"
|
|
5
|
-
],
|
|
6
3
|
"names": [
|
|
7
4
|
"defaultLightThemeOption",
|
|
8
5
|
"EditorView",
|
|
@@ -10,8 +7,11 @@
|
|
|
10
7
|
"backgroundColor",
|
|
11
8
|
"dark"
|
|
12
9
|
],
|
|
13
|
-
"
|
|
10
|
+
"sources": [
|
|
11
|
+
"../../src/theme/light.ts"
|
|
12
|
+
],
|
|
14
13
|
"sourcesContent": [
|
|
15
14
|
"import { EditorView } from '@codemirror/view';\n\nexport const defaultLightThemeOption = EditorView.theme(\n {\n '&': {\n backgroundColor: '#fff',\n },\n },\n {\n dark: false,\n },\n);\n"
|
|
16
|
-
]
|
|
15
|
+
],
|
|
16
|
+
"mappings": ";;;;;;;AAAA;;AAEO,IAAMA,uBAAuB,GAAGC,gBAAA,CAAWC,KAAX,CACrC;EACE,KAAK;IACHC,eAAe,EAAE;EADd;AADP,CADqC,EAMrC;EACEC,IAAI,EAAE;AADR,CANqC,CAAhC"
|
|
17
17
|
}
|
package/cjs/useCodeMirror.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { EditorState } from '@codemirror/state';
|
|
3
2
|
import { EditorView } from '@codemirror/view';
|
|
4
|
-
import { ReactCodeMirrorProps } from '
|
|
3
|
+
import { ReactCodeMirrorProps } from '.';
|
|
5
4
|
export interface UseCodeMirror extends ReactCodeMirrorProps {
|
|
6
5
|
container?: HTMLDivElement | null;
|
|
7
6
|
}
|