@uiw/react-codemirror 4.8.0 → 4.9.1
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 +73 -5
- 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 -1
- package/cjs/index.js +21 -8
- package/cjs/index.js.map +2 -2
- package/cjs/useCodeMirror.d.ts +1 -2
- package/cjs/useCodeMirror.js +19 -9
- package/cjs/useCodeMirror.js.map +6 -4
- package/dist/{codemirror.js → mdeditor.js} +66 -91
- 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 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +2 -2
- package/esm/useCodeMirror.d.ts +1 -2
- package/esm/useCodeMirror.js +13 -3
- package/esm/useCodeMirror.js.map +6 -4
- package/package.json +23 -87
- package/src/basicSetup.ts +136 -0
- package/src/index.tsx +7 -1
- 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
|
@@ -47,7 +47,7 @@ function App() {
|
|
|
47
47
|
<CodeMirror
|
|
48
48
|
value="console.log('hello world!');"
|
|
49
49
|
height="200px"
|
|
50
|
-
extensions={[
|
|
50
|
+
extensions={[javascript({ jsx: true })]}
|
|
51
51
|
onChange={(value, viewUpdate) => {
|
|
52
52
|
console.log('value:', value);
|
|
53
53
|
}}
|
|
@@ -173,16 +173,46 @@ export default function App() {
|
|
|
173
173
|
## Using custom theme
|
|
174
174
|
|
|
175
175
|
```jsx
|
|
176
|
-
import { oneDark } from '@codemirror/theme-one-dark';
|
|
177
176
|
import CodeMirror from '@uiw/react-codemirror';
|
|
177
|
+
import { createTheme } from '@uiw/codemirror-themes';
|
|
178
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
|
+
});
|
|
179
209
|
|
|
180
210
|
export default function App() {
|
|
181
211
|
return (
|
|
182
212
|
<CodeMirror
|
|
183
213
|
value="console.log('hello world!');"
|
|
184
|
-
height="
|
|
185
|
-
theme={
|
|
214
|
+
height="200px"
|
|
215
|
+
theme={myTheme}
|
|
186
216
|
extensions={[javascript({ jsx: true })]}
|
|
187
217
|
onChange={(value, viewUpdate) => {
|
|
188
218
|
console.log('value:', value);
|
|
@@ -243,7 +273,7 @@ export interface ReactCodeMirrorProps
|
|
|
243
273
|
* Whether to optional basicSetup by default
|
|
244
274
|
* @default true
|
|
245
275
|
*/
|
|
246
|
-
basicSetup?: boolean;
|
|
276
|
+
basicSetup?: boolean | BasicSetupOptions;
|
|
247
277
|
/**
|
|
248
278
|
* This disables editing of the editor content by the user.
|
|
249
279
|
* @default true
|
|
@@ -285,8 +315,46 @@ declare const ReactCodeMirror: React.ForwardRefExoticComponent<
|
|
|
285
315
|
ReactCodeMirrorProps & React.RefAttributes<ReactCodeMirrorRef>
|
|
286
316
|
>;
|
|
287
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
|
+
}
|
|
288
344
|
```
|
|
289
345
|
|
|
346
|
+
## Packages
|
|
347
|
+
|
|
348
|
+
| Name | NPM Version | Website |
|
|
349
|
+
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
350
|
+
| `@uiw/react-codemirror` | [](https://www.npmjs.com/package/@uiw/react-codemirror) | [Preview Website](https://uiwjs.github.io/react-codemirror/) |
|
|
351
|
+
| `@uiw/codemirror-themes` | [](https://www.npmjs.com/package/@uiw/codemirror-themes) | [Preview Website](https://uiwjs.github.io/react-codemirror/#/theme/doc) |
|
|
352
|
+
| `@uiw/codemirror-theme-okaidia` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-okaidia) | [Preview Website](https://uiwjs.github.io/react-codemirror/#/theme/data/okaidia) |
|
|
353
|
+
| `@uiw/codemirror-theme-duotone` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-duotone) | [Preview Website](https://uiwjs.github.io/react-codemirror/#/theme/data/duotoneDark) |
|
|
354
|
+
| `@uiw/codemirror-theme-dracula` | [](https://www.npmjs.com/package/@uiw/codemirror-theme-dracula) | [Preview Website](https://uiwjs.github.io/react-codemirror/#/theme/data/dracula) |
|
|
355
|
+
|
|
356
|
+
<!--rehype:style=width: 100%; display: inline-table;-->
|
|
357
|
+
|
|
290
358
|
### Related
|
|
291
359
|
|
|
292
360
|
- [@uiw/react-textarea-code-editor](https://github.com/uiwjs/react-textarea-code-editor): A simple code editor with syntax highlighting.
|
|
@@ -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,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,OAAO,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,6 +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
|
+
import { BasicSetupOptions } from './basicSetup';
|
|
5
|
+
export * from './basicSetup';
|
|
4
6
|
export * from './useCodeMirror';
|
|
5
7
|
export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'extensions'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
|
|
6
8
|
/** value of the auto created model in the editor. */
|
|
@@ -24,12 +26,16 @@ export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'e
|
|
|
24
26
|
* Whether to optional basicSetup by default
|
|
25
27
|
* @default true
|
|
26
28
|
*/
|
|
27
|
-
basicSetup?: boolean;
|
|
29
|
+
basicSetup?: boolean | BasicSetupOptions;
|
|
28
30
|
/**
|
|
29
31
|
* This disables editing of the editor content by the user.
|
|
30
32
|
* @default true
|
|
31
33
|
*/
|
|
32
34
|
editable?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* This disables editing of the editor content by the user.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
33
39
|
readOnly?: boolean;
|
|
34
40
|
/**
|
|
35
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,9 +34,22 @@ Object.keys(_useCodeMirror2).forEach(function (key) {
|
|
|
34
34
|
|
|
35
35
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
36
36
|
|
|
37
|
+
var _basicSetup = require("./basicSetup");
|
|
38
|
+
|
|
39
|
+
Object.keys(_basicSetup).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] === _basicSetup[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _basicSetup[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
37
50
|
var _excluded = ["className", "value", "selection", "extensions", "onChange", "onUpdate", "autoFocus", "theme", "height", "minHeight", "maxHeight", "width", "minWidth", "maxWidth", "basicSetup", "placeholder", "indentWithTab", "editable", "readOnly", "root"];
|
|
38
51
|
|
|
39
|
-
var ReactCodeMirror = /*#__PURE__*/_react
|
|
52
|
+
var ReactCodeMirror = /*#__PURE__*/_react["default"].forwardRef(function (props, ref) {
|
|
40
53
|
var className = props.className,
|
|
41
54
|
_props$value = props.value,
|
|
42
55
|
value = _props$value === void 0 ? '' : _props$value,
|
|
@@ -60,7 +73,7 @@ var ReactCodeMirror = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
60
73
|
editable = props.editable,
|
|
61
74
|
readOnly = props.readOnly,
|
|
62
75
|
root = props.root,
|
|
63
|
-
other = (0, _objectWithoutProperties2
|
|
76
|
+
other = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
|
64
77
|
var editor = (0, _react.useRef)(null);
|
|
65
78
|
|
|
66
79
|
var _useCodeMirror = (0, _useCodeMirror2.useCodeMirror)({
|
|
@@ -102,11 +115,11 @@ var ReactCodeMirror = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
102
115
|
}, []); // check type of value
|
|
103
116
|
|
|
104
117
|
if (typeof value !== 'string') {
|
|
105
|
-
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)));
|
|
106
119
|
}
|
|
107
120
|
|
|
108
121
|
var defaultClassNames = typeof theme === 'string' ? "cm-theme-".concat(theme) : 'cm-theme';
|
|
109
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2
|
|
122
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({
|
|
110
123
|
ref: editor,
|
|
111
124
|
className: "".concat(defaultClassNames).concat(className ? " ".concat(className) : '')
|
|
112
125
|
}, other));
|
|
@@ -114,5 +127,5 @@ var ReactCodeMirror = /*#__PURE__*/_react.default.forwardRef(function (props, re
|
|
|
114
127
|
|
|
115
128
|
ReactCodeMirror.displayName = 'CodeMirror';
|
|
116
129
|
var _default = ReactCodeMirror;
|
|
117
|
-
exports
|
|
130
|
+
exports["default"] = _default;
|
|
118
131
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"../src/index.tsx"
|
|
46
46
|
],
|
|
47
47
|
"sourcesContent": [
|
|
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';\n\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;\n /**\n * This disables editing of the editor content by the user.\n * @default true\n */\n editable?: boolean;\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"
|
|
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
49
|
],
|
|
50
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;;AAGA;;
|
|
50
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;;AAGA;;AAIA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;;;AADA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;;AAmEA,IAAMA,eAAe,gBAAGC,iBAAA,CAAMC,UAAN,CAA2D,UAACC,KAAD,EAAQC,GAAR,EAAgB;EACjG,IACEC,SADF,GAsBIF,KAtBJ,CACEE,SADF;EAAA,mBAsBIF,KAtBJ,CAEEG,KAFF;EAAA,IAEEA,KAFF,6BAEU,EAFV;EAAA,IAGEC,SAHF,GAsBIJ,KAtBJ,CAGEI,SAHF;EAAA,wBAsBIJ,KAtBJ,CAIEK,UAJF;EAAA,IAI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B,GAA8B,YAA9B;eAEetC,e"
|
|
51
51
|
}
|
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
|
}
|
package/cjs/useCodeMirror.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -11,8 +11,6 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
11
11
|
|
|
12
12
|
var _react = require("react");
|
|
13
13
|
|
|
14
|
-
var _codemirror = require("codemirror");
|
|
15
|
-
|
|
16
14
|
var _state = require("@codemirror/state");
|
|
17
15
|
|
|
18
16
|
var _commands = require("@codemirror/commands");
|
|
@@ -21,7 +19,7 @@ var _view = require("@codemirror/view");
|
|
|
21
19
|
|
|
22
20
|
var _themeOneDark = require("@codemirror/theme-one-dark");
|
|
23
21
|
|
|
24
|
-
var
|
|
22
|
+
var _basicSetup = require("./basicSetup");
|
|
25
23
|
|
|
26
24
|
function useCodeMirror(props) {
|
|
27
25
|
var value = props.value,
|
|
@@ -58,20 +56,28 @@ function useCodeMirror(props) {
|
|
|
58
56
|
root = props.root;
|
|
59
57
|
|
|
60
58
|
var _useState = (0, _react.useState)(props.container),
|
|
61
|
-
_useState2 = (0, _slicedToArray2
|
|
59
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
62
60
|
container = _useState2[0],
|
|
63
61
|
setContainer = _useState2[1];
|
|
64
62
|
|
|
65
63
|
var _useState3 = (0, _react.useState)(),
|
|
66
|
-
_useState4 = (0, _slicedToArray2
|
|
64
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
|
67
65
|
view = _useState4[0],
|
|
68
66
|
setView = _useState4[1];
|
|
69
67
|
|
|
70
68
|
var _useState5 = (0, _react.useState)(),
|
|
71
|
-
_useState6 = (0, _slicedToArray2
|
|
69
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
|
72
70
|
state = _useState6[0],
|
|
73
71
|
setState = _useState6[1];
|
|
74
72
|
|
|
73
|
+
var defaultLightThemeOption = _view.EditorView.theme({
|
|
74
|
+
'&': {
|
|
75
|
+
backgroundColor: '#fff'
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
dark: false
|
|
79
|
+
});
|
|
80
|
+
|
|
75
81
|
var defaultThemeOption = _view.EditorView.theme({
|
|
76
82
|
'&': {
|
|
77
83
|
height: height,
|
|
@@ -100,7 +106,11 @@ function useCodeMirror(props) {
|
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
if (defaultBasicSetup) {
|
|
103
|
-
|
|
109
|
+
if (typeof defaultBasicSetup === 'boolean') {
|
|
110
|
+
getExtensions.unshift((0, _basicSetup.basicSetup)());
|
|
111
|
+
} else {
|
|
112
|
+
getExtensions.unshift((0, _basicSetup.basicSetup)(defaultBasicSetup));
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
if (placeholderStr) {
|
|
@@ -109,7 +119,7 @@ function useCodeMirror(props) {
|
|
|
109
119
|
|
|
110
120
|
switch (theme) {
|
|
111
121
|
case 'light':
|
|
112
|
-
getExtensions.push(
|
|
122
|
+
getExtensions.push(defaultLightThemeOption);
|
|
113
123
|
break;
|
|
114
124
|
|
|
115
125
|
case 'dark':
|