@uiw/react-codemirror 4.25.9 → 4.25.11
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 +50 -34
- package/cjs/theme/dimensionTheme.d.ts +3 -0
- package/cjs/theme/dimensionTheme.js +43 -0
- package/cjs/useCodeMirror.js +3 -14
- package/dist/codemirror.js +230 -132
- package/dist/codemirror.min.js +1 -1
- package/esm/getDefaultExtensions.js +13 -8
- package/esm/index.js +43 -43
- package/esm/theme/dimensionTheme.d.ts +3 -0
- package/esm/theme/dimensionTheme.js +36 -0
- package/esm/useCodeMirror.js +47 -41
- package/package.json +2 -2
- package/src/theme/dimensionTheme.ts +42 -0
- package/src/useCodeMirror.ts +8 -14
|
@@ -10,14 +10,19 @@ export var getDefaultExtensions = function getDefaultExtensions(optios) {
|
|
|
10
10
|
if (optios === void 0) {
|
|
11
11
|
optios = {};
|
|
12
12
|
}
|
|
13
|
-
var
|
|
14
|
-
indentWithTab
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
var _optios = optios,
|
|
14
|
+
_optios$indentWithTab = _optios.indentWithTab,
|
|
15
|
+
defaultIndentWithTab = _optios$indentWithTab === void 0 ? true : _optios$indentWithTab,
|
|
16
|
+
_optios$editable = _optios.editable,
|
|
17
|
+
editable = _optios$editable === void 0 ? true : _optios$editable,
|
|
18
|
+
_optios$readOnly = _optios.readOnly,
|
|
19
|
+
readOnly = _optios$readOnly === void 0 ? false : _optios$readOnly,
|
|
20
|
+
_optios$theme = _optios.theme,
|
|
21
|
+
theme = _optios$theme === void 0 ? 'light' : _optios$theme,
|
|
22
|
+
_optios$placeholder = _optios.placeholder,
|
|
23
|
+
placeholderStr = _optios$placeholder === void 0 ? '' : _optios$placeholder,
|
|
24
|
+
_optios$basicSetup = _optios.basicSetup,
|
|
25
|
+
defaultBasicSetup = _optios$basicSetup === void 0 ? true : _optios$basicSetup;
|
|
21
26
|
var getExtensions = [];
|
|
22
27
|
if (defaultIndentWithTab) {
|
|
23
28
|
getExtensions.unshift(keymap.of([indentWithTab]));
|
package/esm/index.js
CHANGED
|
@@ -11,17 +11,39 @@ export * from "./useCodeMirror.js";
|
|
|
11
11
|
export * from "./getDefaultExtensions.js";
|
|
12
12
|
export * from "./utils.js";
|
|
13
13
|
var ReactCodeMirror = /*#__PURE__*/forwardRef((props, ref) => {
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
var className = props.className,
|
|
15
|
+
_props$value = props.value,
|
|
16
|
+
value = _props$value === void 0 ? '' : _props$value,
|
|
17
|
+
selection = props.selection,
|
|
18
|
+
_props$extensions = props.extensions,
|
|
19
|
+
extensions = _props$extensions === void 0 ? [] : _props$extensions,
|
|
20
|
+
onChange = props.onChange,
|
|
21
|
+
onStatistics = props.onStatistics,
|
|
22
|
+
onCreateEditor = props.onCreateEditor,
|
|
23
|
+
onUpdate = props.onUpdate,
|
|
24
|
+
autoFocus = props.autoFocus,
|
|
25
|
+
_props$theme = props.theme,
|
|
26
|
+
theme = _props$theme === void 0 ? 'light' : _props$theme,
|
|
27
|
+
height = props.height,
|
|
28
|
+
minHeight = props.minHeight,
|
|
29
|
+
maxHeight = props.maxHeight,
|
|
30
|
+
width = props.width,
|
|
31
|
+
minWidth = props.minWidth,
|
|
32
|
+
maxWidth = props.maxWidth,
|
|
33
|
+
basicSetup = props.basicSetup,
|
|
34
|
+
placeholder = props.placeholder,
|
|
35
|
+
indentWithTab = props.indentWithTab,
|
|
36
|
+
editable = props.editable,
|
|
37
|
+
readOnly = props.readOnly,
|
|
38
|
+
root = props.root,
|
|
39
|
+
initialState = props.initialState,
|
|
40
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
41
|
+
var editor = useRef(null);
|
|
42
|
+
var _useCodeMirror = useCodeMirror({
|
|
43
|
+
root,
|
|
44
|
+
value,
|
|
23
45
|
autoFocus,
|
|
24
|
-
theme
|
|
46
|
+
theme,
|
|
25
47
|
height,
|
|
26
48
|
minHeight,
|
|
27
49
|
maxHeight,
|
|
@@ -33,40 +55,18 @@ var ReactCodeMirror = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
33
55
|
indentWithTab,
|
|
34
56
|
editable,
|
|
35
57
|
readOnly,
|
|
36
|
-
|
|
58
|
+
selection,
|
|
59
|
+
onChange,
|
|
60
|
+
onStatistics,
|
|
61
|
+
onCreateEditor,
|
|
62
|
+
onUpdate,
|
|
63
|
+
extensions,
|
|
37
64
|
initialState
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
view,
|
|
44
|
-
container,
|
|
45
|
-
setContainer
|
|
46
|
-
} = useCodeMirror({
|
|
47
|
-
root,
|
|
48
|
-
value,
|
|
49
|
-
autoFocus,
|
|
50
|
-
theme,
|
|
51
|
-
height,
|
|
52
|
-
minHeight,
|
|
53
|
-
maxHeight,
|
|
54
|
-
width,
|
|
55
|
-
minWidth,
|
|
56
|
-
maxWidth,
|
|
57
|
-
basicSetup,
|
|
58
|
-
placeholder,
|
|
59
|
-
indentWithTab,
|
|
60
|
-
editable,
|
|
61
|
-
readOnly,
|
|
62
|
-
selection,
|
|
63
|
-
onChange,
|
|
64
|
-
onStatistics,
|
|
65
|
-
onCreateEditor,
|
|
66
|
-
onUpdate,
|
|
67
|
-
extensions,
|
|
68
|
-
initialState
|
|
69
|
-
});
|
|
65
|
+
}),
|
|
66
|
+
state = _useCodeMirror.state,
|
|
67
|
+
view = _useCodeMirror.view,
|
|
68
|
+
container = _useCodeMirror.container,
|
|
69
|
+
setContainer = _useCodeMirror.setContainer;
|
|
70
70
|
useImperativeHandle(ref, () => ({
|
|
71
71
|
editor: editor.current,
|
|
72
72
|
state: state,
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Extension } from '@codemirror/state';
|
|
2
|
+
export declare const scrollerTheme: Extension;
|
|
3
|
+
export declare function getDimensionTheme(height: string | null, minHeight: string | null, maxHeight: string | null, width: string | null, minWidth: string | null, maxWidth: string | null): Extension | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
export var scrollerTheme = EditorView.theme({
|
|
3
|
+
'& .cm-scroller': {
|
|
4
|
+
height: '100% !important'
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
var lastDimensionKey = null;
|
|
8
|
+
var lastDimensionTheme = null;
|
|
9
|
+
export function getDimensionTheme(height, minHeight, maxHeight, width, minWidth, maxWidth) {
|
|
10
|
+
if (!height && !minHeight && !maxHeight && !width && !minWidth && !maxWidth) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
var cacheKey = JSON.stringify({
|
|
14
|
+
height,
|
|
15
|
+
minHeight,
|
|
16
|
+
maxHeight,
|
|
17
|
+
width,
|
|
18
|
+
minWidth,
|
|
19
|
+
maxWidth
|
|
20
|
+
});
|
|
21
|
+
if (cacheKey === lastDimensionKey) {
|
|
22
|
+
return lastDimensionTheme;
|
|
23
|
+
}
|
|
24
|
+
lastDimensionKey = cacheKey;
|
|
25
|
+
lastDimensionTheme = EditorView.theme({
|
|
26
|
+
'&': {
|
|
27
|
+
height,
|
|
28
|
+
minHeight,
|
|
29
|
+
maxHeight,
|
|
30
|
+
width,
|
|
31
|
+
minWidth,
|
|
32
|
+
maxWidth
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return lastDimensionTheme;
|
|
36
|
+
}
|
package/esm/useCodeMirror.js
CHANGED
|
@@ -4,57 +4,63 @@ import { EditorView } from '@codemirror/view';
|
|
|
4
4
|
import { getDefaultExtensions } from "./getDefaultExtensions.js";
|
|
5
5
|
import { getStatistics } from "./utils.js";
|
|
6
6
|
import { TimeoutLatch, getScheduler } from "./timeoutLatch.js";
|
|
7
|
+
import { scrollerTheme, getDimensionTheme } from "./theme/dimensionTheme.js";
|
|
7
8
|
export var ExternalChange = Annotation.define();
|
|
8
9
|
var TYPING_TIMOUT = 200; // ms
|
|
9
10
|
|
|
10
11
|
var emptyExtensions = [];
|
|
11
12
|
export function useCodeMirror(props) {
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
extensions = emptyExtensions,
|
|
20
|
-
autoFocus,
|
|
21
|
-
theme =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
13
|
+
var value = props.value,
|
|
14
|
+
selection = props.selection,
|
|
15
|
+
onChange = props.onChange,
|
|
16
|
+
onStatistics = props.onStatistics,
|
|
17
|
+
onCreateEditor = props.onCreateEditor,
|
|
18
|
+
onUpdate = props.onUpdate,
|
|
19
|
+
_props$extensions = props.extensions,
|
|
20
|
+
extensions = _props$extensions === void 0 ? emptyExtensions : _props$extensions,
|
|
21
|
+
autoFocus = props.autoFocus,
|
|
22
|
+
_props$theme = props.theme,
|
|
23
|
+
theme = _props$theme === void 0 ? 'light' : _props$theme,
|
|
24
|
+
_props$height = props.height,
|
|
25
|
+
height = _props$height === void 0 ? null : _props$height,
|
|
26
|
+
_props$minHeight = props.minHeight,
|
|
27
|
+
minHeight = _props$minHeight === void 0 ? null : _props$minHeight,
|
|
28
|
+
_props$maxHeight = props.maxHeight,
|
|
29
|
+
maxHeight = _props$maxHeight === void 0 ? null : _props$maxHeight,
|
|
30
|
+
_props$width = props.width,
|
|
31
|
+
width = _props$width === void 0 ? null : _props$width,
|
|
32
|
+
_props$minWidth = props.minWidth,
|
|
33
|
+
minWidth = _props$minWidth === void 0 ? null : _props$minWidth,
|
|
34
|
+
_props$maxWidth = props.maxWidth,
|
|
35
|
+
maxWidth = _props$maxWidth === void 0 ? null : _props$maxWidth,
|
|
36
|
+
_props$placeholder = props.placeholder,
|
|
37
|
+
placeholderStr = _props$placeholder === void 0 ? '' : _props$placeholder,
|
|
38
|
+
_props$editable = props.editable,
|
|
39
|
+
editable = _props$editable === void 0 ? true : _props$editable,
|
|
40
|
+
_props$readOnly = props.readOnly,
|
|
41
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
42
|
+
_props$indentWithTab = props.indentWithTab,
|
|
43
|
+
defaultIndentWithTab = _props$indentWithTab === void 0 ? true : _props$indentWithTab,
|
|
44
|
+
_props$basicSetup = props.basicSetup,
|
|
45
|
+
defaultBasicSetup = _props$basicSetup === void 0 ? true : _props$basicSetup,
|
|
46
|
+
root = props.root,
|
|
47
|
+
initialState = props.initialState;
|
|
48
|
+
var _useState = useState(),
|
|
49
|
+
container = _useState[0],
|
|
50
|
+
setContainer = _useState[1];
|
|
51
|
+
var _useState2 = useState(),
|
|
52
|
+
view = _useState2[0],
|
|
53
|
+
setView = _useState2[1];
|
|
54
|
+
var _useState3 = useState(),
|
|
55
|
+
state = _useState3[0],
|
|
56
|
+
setState = _useState3[1];
|
|
39
57
|
var typingLatch = useState(() => ({
|
|
40
58
|
current: null
|
|
41
59
|
}))[0];
|
|
42
60
|
var pendingUpdate = useState(() => ({
|
|
43
61
|
current: null
|
|
44
62
|
}))[0];
|
|
45
|
-
var defaultThemeOption =
|
|
46
|
-
'&': {
|
|
47
|
-
height,
|
|
48
|
-
minHeight,
|
|
49
|
-
maxHeight,
|
|
50
|
-
width,
|
|
51
|
-
minWidth,
|
|
52
|
-
maxWidth
|
|
53
|
-
},
|
|
54
|
-
'& .cm-scroller': {
|
|
55
|
-
height: '100% !important'
|
|
56
|
-
}
|
|
57
|
-
});
|
|
63
|
+
var defaultThemeOption = getDimensionTheme(height, minHeight, maxHeight, width, minWidth, maxWidth);
|
|
58
64
|
var updateListener = EditorView.updateListener.of(vu => {
|
|
59
65
|
if (vu.docChanged && typeof onChange === 'function' &&
|
|
60
66
|
// Fix echoing of the remote changes:
|
|
@@ -87,7 +93,7 @@ export function useCodeMirror(props) {
|
|
|
87
93
|
indentWithTab: defaultIndentWithTab,
|
|
88
94
|
basicSetup: defaultBasicSetup
|
|
89
95
|
});
|
|
90
|
-
var getExtensions = [updateListener, defaultThemeOption, ...defaultExtensions];
|
|
96
|
+
var getExtensions = [updateListener, ...(defaultThemeOption ? [defaultThemeOption] : []), scrollerTheme, ...defaultExtensions];
|
|
91
97
|
if (onUpdate && typeof onUpdate === 'function') {
|
|
92
98
|
getExtensions.push(EditorView.updateListener.of(onUpdate));
|
|
93
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/react-codemirror",
|
|
3
|
-
"version": "4.25.
|
|
3
|
+
"version": "4.25.11",
|
|
4
4
|
"description": "CodeMirror component for React.",
|
|
5
5
|
"homepage": "https://uiwjs.github.io/react-codemirror",
|
|
6
6
|
"funding": "https://jaywcjlove.github.io/#/sponsor",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@codemirror/commands": "^6.1.0",
|
|
48
48
|
"@codemirror/state": "^6.1.1",
|
|
49
49
|
"@codemirror/theme-one-dark": "^6.0.0",
|
|
50
|
-
"@uiw/codemirror-extensions-basic-setup": "4.25.
|
|
50
|
+
"@uiw/codemirror-extensions-basic-setup": "4.25.11",
|
|
51
51
|
"codemirror": "^6.0.0"
|
|
52
52
|
},
|
|
53
53
|
"keywords": [
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
import type { Extension } from '@codemirror/state';
|
|
3
|
+
|
|
4
|
+
export const scrollerTheme = EditorView.theme({
|
|
5
|
+
'& .cm-scroller': {
|
|
6
|
+
height: '100% !important',
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
let lastDimensionKey: string | null = null;
|
|
11
|
+
let lastDimensionTheme: Extension | null = null;
|
|
12
|
+
|
|
13
|
+
export function getDimensionTheme(
|
|
14
|
+
height: string | null,
|
|
15
|
+
minHeight: string | null,
|
|
16
|
+
maxHeight: string | null,
|
|
17
|
+
width: string | null,
|
|
18
|
+
minWidth: string | null,
|
|
19
|
+
maxWidth: string | null,
|
|
20
|
+
): Extension | null {
|
|
21
|
+
if (!height && !minHeight && !maxHeight && !width && !minWidth && !maxWidth) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const cacheKey = JSON.stringify({ height, minHeight, maxHeight, width, minWidth, maxWidth });
|
|
26
|
+
if (cacheKey === lastDimensionKey) {
|
|
27
|
+
return lastDimensionTheme;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
lastDimensionKey = cacheKey;
|
|
31
|
+
lastDimensionTheme = EditorView.theme({
|
|
32
|
+
'&': {
|
|
33
|
+
height,
|
|
34
|
+
minHeight,
|
|
35
|
+
maxHeight,
|
|
36
|
+
width,
|
|
37
|
+
minWidth,
|
|
38
|
+
maxWidth,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
return lastDimensionTheme;
|
|
42
|
+
}
|
package/src/useCodeMirror.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { getDefaultExtensions } from './getDefaultExtensions';
|
|
|
5
5
|
import { getStatistics } from './utils';
|
|
6
6
|
import { type ReactCodeMirrorProps } from '.';
|
|
7
7
|
import { TimeoutLatch, getScheduler } from './timeoutLatch';
|
|
8
|
+
import { scrollerTheme, getDimensionTheme } from './theme/dimensionTheme';
|
|
8
9
|
|
|
9
10
|
export const ExternalChange = Annotation.define<boolean>();
|
|
10
11
|
const TYPING_TIMOUT = 200; // ms
|
|
@@ -45,19 +46,7 @@ export function useCodeMirror(props: UseCodeMirror) {
|
|
|
45
46
|
const [state, setState] = useState<EditorState>();
|
|
46
47
|
const typingLatch = useState<{ current: TimeoutLatch | null }>(() => ({ current: null }))[0];
|
|
47
48
|
const pendingUpdate = useState<{ current: (() => void) | null }>(() => ({ current: null }))[0];
|
|
48
|
-
const defaultThemeOption =
|
|
49
|
-
'&': {
|
|
50
|
-
height,
|
|
51
|
-
minHeight,
|
|
52
|
-
maxHeight,
|
|
53
|
-
width,
|
|
54
|
-
minWidth,
|
|
55
|
-
maxWidth,
|
|
56
|
-
},
|
|
57
|
-
'& .cm-scroller': {
|
|
58
|
-
height: '100% !important',
|
|
59
|
-
},
|
|
60
|
-
});
|
|
49
|
+
const defaultThemeOption = getDimensionTheme(height, minHeight, maxHeight, width, minWidth, maxWidth);
|
|
61
50
|
const updateListener = EditorView.updateListener.of((vu: ViewUpdate) => {
|
|
62
51
|
if (
|
|
63
52
|
vu.docChanged &&
|
|
@@ -96,7 +85,12 @@ export function useCodeMirror(props: UseCodeMirror) {
|
|
|
96
85
|
basicSetup: defaultBasicSetup,
|
|
97
86
|
});
|
|
98
87
|
|
|
99
|
-
let getExtensions = [
|
|
88
|
+
let getExtensions = [
|
|
89
|
+
updateListener,
|
|
90
|
+
...(defaultThemeOption ? [defaultThemeOption] : []),
|
|
91
|
+
scrollerTheme,
|
|
92
|
+
...defaultExtensions,
|
|
93
|
+
];
|
|
100
94
|
|
|
101
95
|
if (onUpdate && typeof onUpdate === 'function') {
|
|
102
96
|
getExtensions.push(EditorView.updateListener.of(onUpdate));
|