@uiw/react-codemirror 4.19.11 → 4.19.13
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 +30 -1
- package/cjs/getDefaultExtensions.d.ts +11 -0
- package/cjs/getDefaultExtensions.js +68 -0
- package/cjs/index.d.ts +3 -1
- package/cjs/index.js +13 -2
- package/cjs/theme/light.d.ts +1 -0
- package/cjs/theme/light.js +1 -2
- package/cjs/useCodeMirror.js +12 -45
- package/cjs/utils.js +1 -2
- package/dist/mdeditor.js +42 -19
- package/dist/mdeditor.min.js +1 -1
- package/esm/getDefaultExtensions.d.ts +11 -0
- package/esm/getDefaultExtensions.js +59 -0
- package/esm/index.d.ts +3 -1
- package/esm/index.js +2 -2
- package/esm/theme/light.d.ts +1 -0
- package/esm/theme/light.js +1 -2
- package/esm/useCodeMirror.js +12 -46
- package/esm/utils.js +1 -2
- package/package.json +4 -4
- package/src/getDefaultExtensions.ts +71 -0
- package/src/index.tsx +3 -1
- package/src/useCodeMirror.ts +11 -49
- package/cjs/index.js.map +0 -81
- package/cjs/theme/light.js.map +0 -20
- package/cjs/useCodeMirror.js.map +0 -123
- package/cjs/utils.js.map +0 -40
- package/esm/index.js.map +0 -57
- package/esm/theme/light.js.map +0 -17
- package/esm/useCodeMirror.js.map +0 -95
- package/esm/utils.js.map +0 -39
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
3
|
+
export type DefaultExtensionsOptions = {
|
|
4
|
+
indentWithTab?: boolean;
|
|
5
|
+
basicSetup?: boolean | BasicSetupOptions;
|
|
6
|
+
placeholder?: string | HTMLElement;
|
|
7
|
+
theme?: 'light' | 'dark' | 'none' | Extension;
|
|
8
|
+
readOnly?: boolean;
|
|
9
|
+
editable?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const getDefaultExtensions: (optios?: DefaultExtensionsOptions) => Extension[];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { indentWithTab } from '@codemirror/commands';
|
|
2
|
+
import { basicSetup } from '@uiw/codemirror-extensions-basic-setup';
|
|
3
|
+
import { EditorView, keymap, placeholder } from '@codemirror/view';
|
|
4
|
+
import { oneDark } from '@codemirror/theme-one-dark';
|
|
5
|
+
import { EditorState } from '@codemirror/state';
|
|
6
|
+
export var getDefaultExtensions = function getDefaultExtensions(optios) {
|
|
7
|
+
if (optios === void 0) {
|
|
8
|
+
optios = {};
|
|
9
|
+
}
|
|
10
|
+
var {
|
|
11
|
+
indentWithTab: defaultIndentWithTab = true,
|
|
12
|
+
editable = true,
|
|
13
|
+
readOnly = false,
|
|
14
|
+
theme = 'light',
|
|
15
|
+
placeholder: placeholderStr = '',
|
|
16
|
+
basicSetup: defaultBasicSetup = true
|
|
17
|
+
} = optios;
|
|
18
|
+
var getExtensions = [];
|
|
19
|
+
var defaultLightThemeOption = EditorView.theme({
|
|
20
|
+
'&': {
|
|
21
|
+
backgroundColor: '#fff'
|
|
22
|
+
}
|
|
23
|
+
}, {
|
|
24
|
+
dark: false
|
|
25
|
+
});
|
|
26
|
+
if (defaultIndentWithTab) {
|
|
27
|
+
getExtensions.unshift(keymap.of([indentWithTab]));
|
|
28
|
+
}
|
|
29
|
+
if (defaultBasicSetup) {
|
|
30
|
+
if (typeof defaultBasicSetup === 'boolean') {
|
|
31
|
+
getExtensions.unshift(basicSetup());
|
|
32
|
+
} else {
|
|
33
|
+
getExtensions.unshift(basicSetup(defaultBasicSetup));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (placeholderStr) {
|
|
37
|
+
getExtensions.unshift(placeholder(placeholderStr));
|
|
38
|
+
}
|
|
39
|
+
switch (theme) {
|
|
40
|
+
case 'light':
|
|
41
|
+
getExtensions.push(defaultLightThemeOption);
|
|
42
|
+
break;
|
|
43
|
+
case 'dark':
|
|
44
|
+
getExtensions.push(oneDark);
|
|
45
|
+
break;
|
|
46
|
+
case 'none':
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
getExtensions.push(theme);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
if (editable === false) {
|
|
53
|
+
getExtensions.push(EditorView.editable.of(false));
|
|
54
|
+
}
|
|
55
|
+
if (readOnly) {
|
|
56
|
+
getExtensions.push(EditorState.readOnly.of(true));
|
|
57
|
+
}
|
|
58
|
+
return [...getExtensions];
|
|
59
|
+
};
|
package/esm/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
|
5
5
|
import { Statistics } from './utils';
|
|
6
6
|
export * from '@uiw/codemirror-extensions-basic-setup';
|
|
7
7
|
export * from './useCodeMirror';
|
|
8
|
+
export * from './getDefaultExtensions';
|
|
8
9
|
export * from './utils';
|
|
9
10
|
export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'extensions'>, Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'placeholder'> {
|
|
10
11
|
/** value of the auto created model in the editor. */
|
|
@@ -40,7 +41,8 @@ export interface ReactCodeMirrorProps extends Omit<EditorStateConfig, 'doc' | 'e
|
|
|
40
41
|
*/
|
|
41
42
|
readOnly?: boolean;
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
+
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
|
|
45
|
+
* or behaves according to the browser's default behavior (`false`).
|
|
44
46
|
* @default true
|
|
45
47
|
*/
|
|
46
48
|
indentWithTab?: boolean;
|
package/esm/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { useCodeMirror } from './useCodeMirror';
|
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
export * from '@uiw/codemirror-extensions-basic-setup';
|
|
8
8
|
export * from './useCodeMirror';
|
|
9
|
+
export * from './getDefaultExtensions';
|
|
9
10
|
export * from './utils';
|
|
10
11
|
var ReactCodeMirror = /*#__PURE__*/forwardRef((props, ref) => {
|
|
11
12
|
var {
|
|
@@ -81,5 +82,4 @@ var ReactCodeMirror = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
81
82
|
}, other));
|
|
82
83
|
});
|
|
83
84
|
ReactCodeMirror.displayName = 'CodeMirror';
|
|
84
|
-
export default ReactCodeMirror;
|
|
85
|
-
//# sourceMappingURL=index.js.map
|
|
85
|
+
export default ReactCodeMirror;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const defaultLightThemeOption: import("@codemirror/state").Extension;
|
package/esm/theme/light.js
CHANGED
package/esm/useCodeMirror.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { Annotation, EditorState, StateEffect } from '@codemirror/state';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { basicSetup } from '@uiw/codemirror-extensions-basic-setup';
|
|
6
|
-
import { oneDark } from '@codemirror/theme-one-dark';
|
|
3
|
+
import { EditorView } from '@codemirror/view';
|
|
4
|
+
import { getDefaultExtensions } from './getDefaultExtensions';
|
|
7
5
|
import { getStatistics } from './utils';
|
|
8
6
|
var External = Annotation.define();
|
|
9
7
|
export function useCodeMirror(props) {
|
|
@@ -34,13 +32,6 @@ export function useCodeMirror(props) {
|
|
|
34
32
|
var [container, setContainer] = useState();
|
|
35
33
|
var [view, setView] = useState();
|
|
36
34
|
var [state, setState] = useState();
|
|
37
|
-
var defaultLightThemeOption = EditorView.theme({
|
|
38
|
-
'&': {
|
|
39
|
-
backgroundColor: '#fff'
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
dark: false
|
|
43
|
-
});
|
|
44
35
|
var defaultThemeOption = EditorView.theme({
|
|
45
36
|
'&': {
|
|
46
37
|
height,
|
|
@@ -62,39 +53,15 @@ export function useCodeMirror(props) {
|
|
|
62
53
|
}
|
|
63
54
|
onStatistics && onStatistics(getStatistics(vu));
|
|
64
55
|
});
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (placeholderStr) {
|
|
77
|
-
getExtensions.unshift(placeholder(placeholderStr));
|
|
78
|
-
}
|
|
79
|
-
switch (theme) {
|
|
80
|
-
case 'light':
|
|
81
|
-
getExtensions.push(defaultLightThemeOption);
|
|
82
|
-
break;
|
|
83
|
-
case 'dark':
|
|
84
|
-
getExtensions.push(oneDark);
|
|
85
|
-
break;
|
|
86
|
-
case 'none':
|
|
87
|
-
break;
|
|
88
|
-
default:
|
|
89
|
-
getExtensions.push(theme);
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
if (editable === false) {
|
|
93
|
-
getExtensions.push(EditorView.editable.of(false));
|
|
94
|
-
}
|
|
95
|
-
if (readOnly) {
|
|
96
|
-
getExtensions.push(EditorState.readOnly.of(true));
|
|
97
|
-
}
|
|
56
|
+
var defaultExtensions = getDefaultExtensions({
|
|
57
|
+
theme,
|
|
58
|
+
editable: true,
|
|
59
|
+
readOnly: false,
|
|
60
|
+
placeholder: placeholderStr,
|
|
61
|
+
indentWithTab: defaultIndentWithTab,
|
|
62
|
+
basicSetup: defaultBasicSetup
|
|
63
|
+
});
|
|
64
|
+
var getExtensions = [updateListener, defaultThemeOption, ...defaultExtensions];
|
|
98
65
|
if (onUpdate && typeof onUpdate === 'function') {
|
|
99
66
|
getExtensions.push(EditorView.updateListener.of(onUpdate));
|
|
100
67
|
}
|
|
@@ -169,5 +136,4 @@ export function useCodeMirror(props) {
|
|
|
169
136
|
container,
|
|
170
137
|
setContainer
|
|
171
138
|
};
|
|
172
|
-
}
|
|
173
|
-
//# sourceMappingURL=useCodeMirror.js.map
|
|
139
|
+
}
|
package/esm/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-codemirror",
|
|
3
|
-
"version": "4.19.
|
|
3
|
+
"version": "4.19.13",
|
|
4
4
|
"description": "CodeMirror component for React.",
|
|
5
5
|
"homepage": "https://uiwjs.github.io/react-codemirror",
|
|
6
6
|
"author": "kenny wong <wowohoo@qq.com>",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"bundle": "ncc build src/index.tsx --target web --filename mdeditor && npm run bundle:min",
|
|
12
12
|
"bundle:watch": "ncc watch src/index.tsx --target web --filename mdeditor",
|
|
13
13
|
"bundle:min": "ncc build src/index.tsx --target web --filename mdeditor --minify",
|
|
14
|
-
"watch": "tsbb watch",
|
|
15
|
-
"build": "tsbb build",
|
|
14
|
+
"watch": "tsbb watch src/*.tsx --use-babel",
|
|
15
|
+
"build": "tsbb build src/*.tsx --use-babel",
|
|
16
16
|
"test": "tsbb test --env=jsdom",
|
|
17
17
|
"coverage": "tsbb test --env=jsdom --coverage --bail"
|
|
18
18
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@codemirror/commands": "^6.1.0",
|
|
41
41
|
"@codemirror/state": "^6.1.1",
|
|
42
42
|
"@codemirror/theme-one-dark": "^6.0.0",
|
|
43
|
-
"@uiw/codemirror-extensions-basic-setup": "4.19.
|
|
43
|
+
"@uiw/codemirror-extensions-basic-setup": "4.19.13",
|
|
44
44
|
"codemirror": "^6.0.0"
|
|
45
45
|
},
|
|
46
46
|
"keywords": [
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { indentWithTab } from '@codemirror/commands';
|
|
3
|
+
import { basicSetup, BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';
|
|
4
|
+
import { EditorView, keymap, placeholder } from '@codemirror/view';
|
|
5
|
+
import { oneDark } from '@codemirror/theme-one-dark';
|
|
6
|
+
import { EditorState } from '@codemirror/state';
|
|
7
|
+
|
|
8
|
+
export type DefaultExtensionsOptions = {
|
|
9
|
+
indentWithTab?: boolean;
|
|
10
|
+
basicSetup?: boolean | BasicSetupOptions;
|
|
11
|
+
placeholder?: string | HTMLElement;
|
|
12
|
+
theme?: 'light' | 'dark' | 'none' | Extension;
|
|
13
|
+
readOnly?: boolean;
|
|
14
|
+
editable?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getDefaultExtensions = (optios: DefaultExtensionsOptions = {}): Extension[] => {
|
|
18
|
+
const {
|
|
19
|
+
indentWithTab: defaultIndentWithTab = true,
|
|
20
|
+
editable = true,
|
|
21
|
+
readOnly = false,
|
|
22
|
+
theme = 'light',
|
|
23
|
+
placeholder: placeholderStr = '',
|
|
24
|
+
basicSetup: defaultBasicSetup = true,
|
|
25
|
+
} = optios;
|
|
26
|
+
const getExtensions: Extension[] = [];
|
|
27
|
+
const defaultLightThemeOption = EditorView.theme(
|
|
28
|
+
{
|
|
29
|
+
'&': {
|
|
30
|
+
backgroundColor: '#fff',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
dark: false,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
if (defaultIndentWithTab) {
|
|
38
|
+
getExtensions.unshift(keymap.of([indentWithTab]));
|
|
39
|
+
}
|
|
40
|
+
if (defaultBasicSetup) {
|
|
41
|
+
if (typeof defaultBasicSetup === 'boolean') {
|
|
42
|
+
getExtensions.unshift(basicSetup());
|
|
43
|
+
} else {
|
|
44
|
+
getExtensions.unshift(basicSetup(defaultBasicSetup));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (placeholderStr) {
|
|
48
|
+
getExtensions.unshift(placeholder(placeholderStr));
|
|
49
|
+
}
|
|
50
|
+
switch (theme) {
|
|
51
|
+
case 'light':
|
|
52
|
+
getExtensions.push(defaultLightThemeOption);
|
|
53
|
+
break;
|
|
54
|
+
case 'dark':
|
|
55
|
+
getExtensions.push(oneDark);
|
|
56
|
+
break;
|
|
57
|
+
case 'none':
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
getExtensions.push(theme);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
if (editable === false) {
|
|
64
|
+
getExtensions.push(EditorView.editable.of(false));
|
|
65
|
+
}
|
|
66
|
+
if (readOnly) {
|
|
67
|
+
getExtensions.push(EditorState.readOnly.of(true));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return [...getExtensions];
|
|
71
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import { Statistics } from './utils';
|
|
|
7
7
|
|
|
8
8
|
export * from '@uiw/codemirror-extensions-basic-setup';
|
|
9
9
|
export * from './useCodeMirror';
|
|
10
|
+
export * from './getDefaultExtensions';
|
|
10
11
|
export * from './utils';
|
|
11
12
|
|
|
12
13
|
export interface ReactCodeMirrorProps
|
|
@@ -45,7 +46,8 @@ export interface ReactCodeMirrorProps
|
|
|
45
46
|
*/
|
|
46
47
|
readOnly?: boolean;
|
|
47
48
|
/**
|
|
48
|
-
*
|
|
49
|
+
* Controls whether pressing the `Tab` key inserts a tab character and indents the text (`true`)
|
|
50
|
+
* or behaves according to the browser's default behavior (`false`).
|
|
49
51
|
* @default true
|
|
50
52
|
*/
|
|
51
53
|
indentWithTab?: boolean;
|
package/src/useCodeMirror.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { Annotation, EditorState, StateEffect } from '@codemirror/state';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { basicSetup } from '@uiw/codemirror-extensions-basic-setup';
|
|
6
|
-
import { oneDark } from '@codemirror/theme-one-dark';
|
|
3
|
+
import { EditorView, ViewUpdate } from '@codemirror/view';
|
|
4
|
+
import { getDefaultExtensions } from './getDefaultExtensions';
|
|
7
5
|
import { getStatistics } from './utils';
|
|
8
6
|
import { ReactCodeMirrorProps } from '.';
|
|
9
7
|
|
|
@@ -41,16 +39,6 @@ export function useCodeMirror(props: UseCodeMirror) {
|
|
|
41
39
|
const [container, setContainer] = useState<HTMLDivElement>();
|
|
42
40
|
const [view, setView] = useState<EditorView>();
|
|
43
41
|
const [state, setState] = useState<EditorState>();
|
|
44
|
-
const defaultLightThemeOption = EditorView.theme(
|
|
45
|
-
{
|
|
46
|
-
'&': {
|
|
47
|
-
backgroundColor: '#fff',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
dark: false,
|
|
52
|
-
},
|
|
53
|
-
);
|
|
54
42
|
const defaultThemeOption = EditorView.theme({
|
|
55
43
|
'&': {
|
|
56
44
|
height,
|
|
@@ -76,42 +64,16 @@ export function useCodeMirror(props: UseCodeMirror) {
|
|
|
76
64
|
onStatistics && onStatistics(getStatistics(vu));
|
|
77
65
|
});
|
|
78
66
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
getExtensions.unshift(basicSetup(defaultBasicSetup));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (placeholderStr) {
|
|
92
|
-
getExtensions.unshift(placeholder(placeholderStr));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
switch (theme) {
|
|
96
|
-
case 'light':
|
|
97
|
-
getExtensions.push(defaultLightThemeOption);
|
|
98
|
-
break;
|
|
99
|
-
case 'dark':
|
|
100
|
-
getExtensions.push(oneDark);
|
|
101
|
-
break;
|
|
102
|
-
case 'none':
|
|
103
|
-
break;
|
|
104
|
-
default:
|
|
105
|
-
getExtensions.push(theme);
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
67
|
+
const defaultExtensions = getDefaultExtensions({
|
|
68
|
+
theme,
|
|
69
|
+
editable: true,
|
|
70
|
+
readOnly: false,
|
|
71
|
+
placeholder: placeholderStr,
|
|
72
|
+
indentWithTab: defaultIndentWithTab,
|
|
73
|
+
basicSetup: defaultBasicSetup,
|
|
74
|
+
});
|
|
108
75
|
|
|
109
|
-
|
|
110
|
-
getExtensions.push(EditorView.editable.of(false));
|
|
111
|
-
}
|
|
112
|
-
if (readOnly) {
|
|
113
|
-
getExtensions.push(EditorState.readOnly.of(true));
|
|
114
|
-
}
|
|
76
|
+
let getExtensions = [updateListener, defaultThemeOption, ...defaultExtensions];
|
|
115
77
|
|
|
116
78
|
if (onUpdate && typeof onUpdate === 'function') {
|
|
117
79
|
getExtensions.push(EditorView.updateListener.of(onUpdate));
|
package/cjs/index.js.map
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"_react",
|
|
5
|
-
"_interopRequireWildcard",
|
|
6
|
-
"require",
|
|
7
|
-
"_useCodeMirror2",
|
|
8
|
-
"Object",
|
|
9
|
-
"keys",
|
|
10
|
-
"forEach",
|
|
11
|
-
"key",
|
|
12
|
-
"prototype",
|
|
13
|
-
"hasOwnProperty",
|
|
14
|
-
"call",
|
|
15
|
-
"_exportNames",
|
|
16
|
-
"exports",
|
|
17
|
-
"defineProperty",
|
|
18
|
-
"enumerable",
|
|
19
|
-
"get",
|
|
20
|
-
"_jsxRuntime",
|
|
21
|
-
"_codemirrorExtensionsBasicSetup",
|
|
22
|
-
"_utils",
|
|
23
|
-
"_excluded",
|
|
24
|
-
"ReactCodeMirror",
|
|
25
|
-
"forwardRef",
|
|
26
|
-
"props",
|
|
27
|
-
"ref",
|
|
28
|
-
"className",
|
|
29
|
-
"_props$value",
|
|
30
|
-
"value",
|
|
31
|
-
"selection",
|
|
32
|
-
"_props$extensions",
|
|
33
|
-
"extensions",
|
|
34
|
-
"onChange",
|
|
35
|
-
"onStatistics",
|
|
36
|
-
"onCreateEditor",
|
|
37
|
-
"onUpdate",
|
|
38
|
-
"autoFocus",
|
|
39
|
-
"_props$theme",
|
|
40
|
-
"theme",
|
|
41
|
-
"height",
|
|
42
|
-
"minHeight",
|
|
43
|
-
"maxHeight",
|
|
44
|
-
"width",
|
|
45
|
-
"minWidth",
|
|
46
|
-
"maxWidth",
|
|
47
|
-
"basicSetup",
|
|
48
|
-
"placeholder",
|
|
49
|
-
"indentWithTab",
|
|
50
|
-
"editable",
|
|
51
|
-
"readOnly",
|
|
52
|
-
"root",
|
|
53
|
-
"initialState",
|
|
54
|
-
"other",
|
|
55
|
-
"_objectWithoutProperties2",
|
|
56
|
-
"editor",
|
|
57
|
-
"useRef",
|
|
58
|
-
"_useCodeMirror",
|
|
59
|
-
"useCodeMirror",
|
|
60
|
-
"container",
|
|
61
|
-
"current",
|
|
62
|
-
"state",
|
|
63
|
-
"view",
|
|
64
|
-
"useImperativeHandle",
|
|
65
|
-
"Error",
|
|
66
|
-
"concat",
|
|
67
|
-
"_typeof2",
|
|
68
|
-
"defaultClassNames",
|
|
69
|
-
"jsx",
|
|
70
|
-
"_objectSpread2",
|
|
71
|
-
"displayName",
|
|
72
|
-
"_default"
|
|
73
|
-
],
|
|
74
|
-
"sources": [
|
|
75
|
-
"../src/index.tsx"
|
|
76
|
-
],
|
|
77
|
-
"sourcesContent": [
|
|
78
|
-
"import React, { useRef, forwardRef, useImperativeHandle } from 'react';\nimport { EditorState, EditorStateConfig, Extension, StateField } from '@codemirror/state';\nimport { EditorView, ViewUpdate } from '@codemirror/view';\nimport { BasicSetupOptions } from '@uiw/codemirror-extensions-basic-setup';\nimport { useCodeMirror } from './useCodeMirror';\nimport { Statistics } from './utils';\n\nexport * from '@uiw/codemirror-extensions-basic-setup';\nexport * from './useCodeMirror';\nexport * from './utils';\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' | 'none' | 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 /** Some data on the statistics editor. */\n onStatistics?(data: Statistics): void;\n /** Fired whenever any state change occurs within the editor, including non-document changes like lint results. */\n onUpdate?(viewUpdate: ViewUpdate): void;\n /** The first time the editor executes the event. */\n onCreateEditor?(view: EditorView, state: EditorState): 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 * Create a state from its JSON representation serialized with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function\n */\n initialState?: {\n json: any;\n fields?: Record<string, StateField<any>>;\n };\n}\n\nexport interface ReactCodeMirrorRef {\n editor?: HTMLDivElement | null;\n state?: EditorState;\n view?: EditorView;\n}\n\nconst ReactCodeMirror = forwardRef<ReactCodeMirrorRef, ReactCodeMirrorProps>((props, ref) => {\n const {\n className,\n value = '',\n selection,\n extensions = [],\n onChange,\n onStatistics,\n onCreateEditor,\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 initialState,\n ...other\n } = props;\n const editor = useRef<HTMLDivElement>(null);\n const { state, view, container } = 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 onStatistics,\n onCreateEditor,\n onUpdate,\n extensions,\n initialState,\n });\n\n useImperativeHandle(ref, () => ({ editor: editor.current, state: state, view: view }), [\n editor,\n container,\n state,\n view,\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"
|
|
79
|
-
],
|
|
80
|
-
"mappings": ";;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,eAAA,GAAAD,OAAA;AAIAE,MAAA,CAAAC,IAAA,CAAAF,eAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,eAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAA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F,MAAA,CAAGtC,SAAS,OAAAsC,MAAA,CAAOtC,SAAS,IAAK,EAAE;EAAG,GAAK0B,KAAK,EAAQ;AAClH,CAAC,CAAC;AAEF9B,eAAe,CAAC+C,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAE5BhD,eAAe;AAAAR,OAAA,cAAAwD,QAAA"
|
|
81
|
-
}
|
package/cjs/theme/light.js.map
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"_view",
|
|
5
|
-
"require",
|
|
6
|
-
"defaultLightThemeOption",
|
|
7
|
-
"EditorView",
|
|
8
|
-
"theme",
|
|
9
|
-
"backgroundColor",
|
|
10
|
-
"dark",
|
|
11
|
-
"exports"
|
|
12
|
-
],
|
|
13
|
-
"sources": [
|
|
14
|
-
"../../src/theme/light.ts"
|
|
15
|
-
],
|
|
16
|
-
"sourcesContent": [
|
|
17
|
-
"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"
|
|
18
|
-
],
|
|
19
|
-
"mappings": ";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEO,IAAMC,uBAAuB,GAAGC,gBAAU,CAACC,KAAK,CACrD;EACE,GAAG,EAAE;IACHC,eAAe,EAAE;EACnB;AACF,CAAC,EACD;EACEC,IAAI,EAAE;AACR,CAAC,CACF;AAACC,OAAA,CAAAL,uBAAA,GAAAA,uBAAA"
|
|
20
|
-
}
|
package/cjs/useCodeMirror.js.map
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"names": [
|
|
4
|
-
"_react",
|
|
5
|
-
"require",
|
|
6
|
-
"_state",
|
|
7
|
-
"_commands",
|
|
8
|
-
"_view",
|
|
9
|
-
"_codemirrorExtensionsBasicSetup",
|
|
10
|
-
"_themeOneDark",
|
|
11
|
-
"_utils",
|
|
12
|
-
"External",
|
|
13
|
-
"Annotation",
|
|
14
|
-
"define",
|
|
15
|
-
"useCodeMirror",
|
|
16
|
-
"props",
|
|
17
|
-
"value",
|
|
18
|
-
"selection",
|
|
19
|
-
"onChange",
|
|
20
|
-
"onStatistics",
|
|
21
|
-
"onCreateEditor",
|
|
22
|
-
"onUpdate",
|
|
23
|
-
"_props$extensions",
|
|
24
|
-
"extensions",
|
|
25
|
-
"autoFocus",
|
|
26
|
-
"_props$theme",
|
|
27
|
-
"theme",
|
|
28
|
-
"_props$height",
|
|
29
|
-
"height",
|
|
30
|
-
"_props$minHeight",
|
|
31
|
-
"minHeight",
|
|
32
|
-
"_props$maxHeight",
|
|
33
|
-
"maxHeight",
|
|
34
|
-
"_props$placeholder",
|
|
35
|
-
"placeholder",
|
|
36
|
-
"placeholderStr",
|
|
37
|
-
"_props$width",
|
|
38
|
-
"width",
|
|
39
|
-
"_props$minWidth",
|
|
40
|
-
"minWidth",
|
|
41
|
-
"_props$maxWidth",
|
|
42
|
-
"maxWidth",
|
|
43
|
-
"_props$editable",
|
|
44
|
-
"editable",
|
|
45
|
-
"_props$readOnly",
|
|
46
|
-
"readOnly",
|
|
47
|
-
"_props$indentWithTab",
|
|
48
|
-
"indentWithTab",
|
|
49
|
-
"defaultIndentWithTab",
|
|
50
|
-
"_props$basicSetup",
|
|
51
|
-
"basicSetup",
|
|
52
|
-
"defaultBasicSetup",
|
|
53
|
-
"root",
|
|
54
|
-
"initialState",
|
|
55
|
-
"_useState",
|
|
56
|
-
"useState",
|
|
57
|
-
"_useState2",
|
|
58
|
-
"_slicedToArray2",
|
|
59
|
-
"container",
|
|
60
|
-
"setContainer",
|
|
61
|
-
"_useState3",
|
|
62
|
-
"_useState4",
|
|
63
|
-
"view",
|
|
64
|
-
"setView",
|
|
65
|
-
"_useState5",
|
|
66
|
-
"_useState6",
|
|
67
|
-
"state",
|
|
68
|
-
"setState",
|
|
69
|
-
"defaultLightThemeOption",
|
|
70
|
-
"EditorView",
|
|
71
|
-
"backgroundColor",
|
|
72
|
-
"dark",
|
|
73
|
-
"defaultThemeOption",
|
|
74
|
-
"updateListener",
|
|
75
|
-
"of",
|
|
76
|
-
"vu",
|
|
77
|
-
"docChanged",
|
|
78
|
-
"transactions",
|
|
79
|
-
"some",
|
|
80
|
-
"tr",
|
|
81
|
-
"annotation",
|
|
82
|
-
"doc",
|
|
83
|
-
"toString",
|
|
84
|
-
"getStatistics",
|
|
85
|
-
"getExtensions",
|
|
86
|
-
"unshift",
|
|
87
|
-
"keymap",
|
|
88
|
-
"push",
|
|
89
|
-
"oneDark",
|
|
90
|
-
"EditorState",
|
|
91
|
-
"concat",
|
|
92
|
-
"useEffect",
|
|
93
|
-
"config",
|
|
94
|
-
"stateCurrent",
|
|
95
|
-
"fromJSON",
|
|
96
|
-
"json",
|
|
97
|
-
"fields",
|
|
98
|
-
"create",
|
|
99
|
-
"viewCurrent",
|
|
100
|
-
"parent",
|
|
101
|
-
"undefined",
|
|
102
|
-
"destroy",
|
|
103
|
-
"focus",
|
|
104
|
-
"dispatch",
|
|
105
|
-
"effects",
|
|
106
|
-
"StateEffect",
|
|
107
|
-
"reconfigure",
|
|
108
|
-
"currentValue",
|
|
109
|
-
"changes",
|
|
110
|
-
"from",
|
|
111
|
-
"to",
|
|
112
|
-
"length",
|
|
113
|
-
"insert",
|
|
114
|
-
"annotations"
|
|
115
|
-
],
|
|
116
|
-
"sources": [
|
|
117
|
-
"../src/useCodeMirror.ts"
|
|
118
|
-
],
|
|
119
|
-
"sourcesContent": [
|
|
120
|
-
"import { useEffect, useState } from 'react';\nimport { Annotation, EditorState, StateEffect } from '@codemirror/state';\nimport { indentWithTab } from '@codemirror/commands';\nimport { EditorView, keymap, ViewUpdate, placeholder } from '@codemirror/view';\nimport { basicSetup } from '@uiw/codemirror-extensions-basic-setup';\nimport { oneDark } from '@codemirror/theme-one-dark';\nimport { getStatistics } from './utils';\nimport { ReactCodeMirrorProps } from '.';\n\nconst External = Annotation.define<boolean>();\n\nexport interface UseCodeMirror extends ReactCodeMirrorProps {\n container?: HTMLDivElement | null;\n}\n\nexport function useCodeMirror(props: UseCodeMirror) {\n const {\n value,\n selection,\n onChange,\n onStatistics,\n onCreateEditor,\n onUpdate,\n extensions = [],\n autoFocus,\n theme = 'light',\n height = '',\n minHeight = '',\n maxHeight = '',\n placeholder: placeholderStr = '',\n width = '',\n minWidth = '',\n maxWidth = '',\n editable = true,\n readOnly = false,\n indentWithTab: defaultIndentWithTab = true,\n basicSetup: defaultBasicSetup = true,\n root,\n initialState,\n } = props;\n const [container, setContainer] = useState<HTMLDivElement>();\n const [view, setView] = useState<EditorView>();\n const [state, setState] = useState<EditorState>();\n const defaultLightThemeOption = EditorView.theme(\n {\n '&': {\n backgroundColor: '#fff',\n },\n },\n {\n dark: false,\n },\n );\n const defaultThemeOption = EditorView.theme({\n '&': {\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n },\n });\n const updateListener = EditorView.updateListener.of((vu: ViewUpdate) => {\n if (\n vu.docChanged &&\n typeof onChange === 'function' &&\n // Fix echoing of the remote changes:\n // If transaction is market as remote we don't have to call `onChange` handler again\n !vu.transactions.some((tr) => tr.annotation(External))\n ) {\n const doc = vu.state.doc;\n const value = doc.toString();\n onChange(value, vu);\n }\n onStatistics && onStatistics(getStatistics(vu));\n });\n\n let getExtensions = [updateListener, defaultThemeOption];\n if (defaultIndentWithTab) {\n getExtensions.unshift(keymap.of([indentWithTab]));\n }\n if (defaultBasicSetup) {\n if (typeof defaultBasicSetup === 'boolean') {\n getExtensions.unshift(basicSetup());\n } else {\n getExtensions.unshift(basicSetup(defaultBasicSetup));\n }\n }\n\n if (placeholderStr) {\n getExtensions.unshift(placeholder(placeholderStr));\n }\n\n switch (theme) {\n case 'light':\n getExtensions.push(defaultLightThemeOption);\n break;\n case 'dark':\n getExtensions.push(oneDark);\n break;\n case 'none':\n break;\n default:\n getExtensions.push(theme);\n break;\n }\n\n if (editable === false) {\n getExtensions.push(EditorView.editable.of(false));\n }\n if (readOnly) {\n getExtensions.push(EditorState.readOnly.of(true));\n }\n\n if (onUpdate && typeof onUpdate === 'function') {\n getExtensions.push(EditorView.updateListener.of(onUpdate));\n }\n getExtensions = getExtensions.concat(extensions);\n\n useEffect(() => {\n if (container && !state) {\n const config = {\n doc: value,\n selection,\n extensions: getExtensions,\n };\n const stateCurrent = initialState\n ? EditorState.fromJSON(initialState.json, config, initialState.fields)\n : EditorState.create(config);\n setState(stateCurrent);\n if (!view) {\n const viewCurrent = new EditorView({\n state: stateCurrent,\n parent: container,\n root,\n });\n setView(viewCurrent);\n onCreateEditor && onCreateEditor(viewCurrent, stateCurrent);\n }\n }\n return () => {\n if (view) {\n setState(undefined);\n setView(undefined);\n }\n };\n }, [container, state]);\n\n useEffect(() => setContainer(props.container!), [props.container]);\n\n useEffect(\n () => () => {\n if (view) {\n view.destroy();\n setView(undefined);\n }\n },\n [view],\n );\n\n useEffect(() => {\n if (autoFocus && view) {\n view.focus();\n }\n }, [autoFocus, view]);\n\n useEffect(() => {\n if (view) {\n view.dispatch({ effects: StateEffect.reconfigure.of(getExtensions) });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n theme,\n extensions,\n height,\n minHeight,\n maxHeight,\n width,\n minWidth,\n maxWidth,\n placeholderStr,\n editable,\n readOnly,\n defaultIndentWithTab,\n defaultBasicSetup,\n onChange,\n onUpdate,\n ]);\n\n useEffect(() => {\n if (value === undefined) {\n return;\n }\n const currentValue = view ? view.state.doc.toString() : '';\n if (view && value !== currentValue) {\n view.dispatch({\n changes: { from: 0, to: currentValue.length, insert: value || '' },\n annotations: [External.of(true)],\n });\n }\n }, [value, view]);\n\n return { state, setState, view, setView, container, setContainer };\n}\n"
|
|
121
|
-
],
|
|
122
|
-
"mappings": ";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAA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