@uiw/react-codemirror 4.25.10 → 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 +0 -2
- 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 +94 -46
- package/dist/codemirror.min.js +1 -1
- package/esm/theme/dimensionTheme.d.ts +3 -0
- package/esm/theme/dimensionTheme.js +36 -0
- package/esm/useCodeMirror.js +3 -14
- package/package.json +2 -2
- package/src/theme/dimensionTheme.ts +42 -0
- package/src/useCodeMirror.ts +8 -14
|
@@ -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,6 +4,7 @@ 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
|
|
|
@@ -59,19 +60,7 @@ export function useCodeMirror(props) {
|
|
|
59
60
|
var pendingUpdate = useState(() => ({
|
|
60
61
|
current: null
|
|
61
62
|
}))[0];
|
|
62
|
-
var defaultThemeOption =
|
|
63
|
-
'&': {
|
|
64
|
-
height,
|
|
65
|
-
minHeight,
|
|
66
|
-
maxHeight,
|
|
67
|
-
width,
|
|
68
|
-
minWidth,
|
|
69
|
-
maxWidth
|
|
70
|
-
},
|
|
71
|
-
'& .cm-scroller': {
|
|
72
|
-
height: '100% !important'
|
|
73
|
-
}
|
|
74
|
-
});
|
|
63
|
+
var defaultThemeOption = getDimensionTheme(height, minHeight, maxHeight, width, minWidth, maxWidth);
|
|
75
64
|
var updateListener = EditorView.updateListener.of(vu => {
|
|
76
65
|
if (vu.docChanged && typeof onChange === 'function' &&
|
|
77
66
|
// Fix echoing of the remote changes:
|
|
@@ -104,7 +93,7 @@ export function useCodeMirror(props) {
|
|
|
104
93
|
indentWithTab: defaultIndentWithTab,
|
|
105
94
|
basicSetup: defaultBasicSetup
|
|
106
95
|
});
|
|
107
|
-
var getExtensions = [updateListener, defaultThemeOption, ...defaultExtensions];
|
|
96
|
+
var getExtensions = [updateListener, ...(defaultThemeOption ? [defaultThemeOption] : []), scrollerTheme, ...defaultExtensions];
|
|
108
97
|
if (onUpdate && typeof onUpdate === 'function') {
|
|
109
98
|
getExtensions.push(EditorView.updateListener.of(onUpdate));
|
|
110
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));
|