@@ -6,24 +6,26 @@ type Options = {
6
6
preview ?: HTMLDivElement | null | undefined ;
7
7
container ?: HTMLDivElement | null | undefined ;
8
8
editor ?: CodeMirror . Editor ;
9
- }
9
+ } ;
10
10
11
- const Fullscreen : React . FC < { command : ICommand , editorProps : IMarkdownEditor & Options } > = ( props ) => {
12
- const { editorProps : { container, preview, editor } } = props ;
11
+ const Fullscreen : React . FC < { command : ICommand ; editorProps : IMarkdownEditor & Options } > = ( props ) => {
12
+ const {
13
+ editorProps : { container, preview, editor } ,
14
+ } = props ;
13
15
const [ full , setFull ] = useState ( false ) ;
14
16
const initEditorHeight = useRef ( 0 ) ;
15
17
const containerRef = useRef < HTMLDivElement | null > ( ) ;
16
18
const editorRef = useRef < CodeMirror . Editor > ( ) ;
17
19
function handleResize ( ) {
18
- if ( containerRef . current && editorRef . current ) {
20
+ if ( containerRef . current && editorRef . current && editorRef . current . setSize ) {
19
21
editorRef . current . setSize ( 'initial' , containerRef . current . clientHeight - 35 ) ;
20
22
}
21
23
}
22
24
useEffect ( ( ) => {
23
25
window && window . addEventListener ( 'resize' , handleResize , true ) ;
24
26
return ( ) => {
25
27
window && window . removeEventListener ( 'resize' , handleResize , true ) ;
26
- }
28
+ } ;
27
29
} , [ ] ) ;
28
30
useEffect ( ( ) => {
29
31
if ( editor ) {
@@ -34,7 +36,7 @@ const Fullscreen: React.FC<{ command: ICommand, editorProps: IMarkdownEditor & O
34
36
} , [ editor ] ) ;
35
37
useEffect ( ( ) => {
36
38
if ( ! document ) return ;
37
- containerRef . current = container
39
+ containerRef . current = container ;
38
40
document . body . style . overflow = full ? 'hidden' : 'initial' ;
39
41
if ( container && full ) {
40
42
container . style . zIndex = '999' ;
@@ -43,35 +45,41 @@ const Fullscreen: React.FC<{ command: ICommand, editorProps: IMarkdownEditor & O
43
45
container . style . bottom = '0px' ;
44
46
container . style . left = '0px' ;
45
47
container . style . right = '0px' ;
46
- editor ! . setSize ( 'initial' , container . clientHeight - 35 ) ;
48
+ if ( editor ) {
49
+ editor . setSize ( 'initial' , container . clientHeight - 35 ) ;
50
+ }
47
51
} else if ( container ) {
48
52
container . style . position = 'initial' ;
49
53
container . style . top = 'initial' ;
50
54
container . style . bottom = 'initial' ;
51
55
container . style . left = 'initial' ;
52
56
container . style . right = 'initial' ;
53
- editor ! . setSize ( 'initial' , initEditorHeight . current ) ;
57
+ if ( editor ) {
58
+ editor . setSize ( 'initial' , initEditorHeight . current ) ;
59
+ }
54
60
}
55
- } , [ full , container , preview ] ) ;
61
+ } , [ full , container , preview , editor ] ) ;
56
62
return (
57
- < button
58
- onClick = { ( ) => setFull ( ! full ) }
59
- type = "button"
60
- className = { full ? 'active' : '' }
61
- >
63
+ < button onClick = { ( ) => setFull ( ! full ) } type = "button" className = { full ? 'active' : '' } >
62
64
{ props . command . icon }
63
65
</ button >
64
66
) ;
65
- }
67
+ } ;
66
68
67
69
export const fullscreen : ICommand = {
68
70
name : 'fullscreen' ,
69
71
keyCommand : 'fullscreen' ,
70
72
button : ( command , props , opts ) => < Fullscreen command = { command } editorProps = { { ...props , ...opts } } /> ,
71
73
icon : (
72
74
< svg width = "16" height = "16" viewBox = "0 0 1024 1024" >
73
- < path fill = "currentColor" d = "M189.75 428.89a36.87 36.87 0 0 0 36.84-36.85V228.12h164a36.85 36.85 0 1 0 0-73.7H189.75a36.82 36.82 0 0 0-36.8 36.85v200.8a36.83 36.83 0 0 0 36.8 36.82zM834.26 595.06a36.82 36.82 0 0 0-36.8 36.84v164H633.41a36.85 36.85 0 0 0 0 73.7h200.85a36.87 36.87 0 0 0 36.84-36.85V631.9a36.86 36.86 0 0 0-36.84-36.84zM797.46 228.12v179.31a36.82 36.82 0 1 0 73.64 0V191.24a36.86 36.86 0 0 0-36.84-36.85H602.33a36.85 36.85 0 0 0 0 73.7zM421.62 795.9H226.54V616.56a36.82 36.82 0 1 0-73.64 0v216.19a36.83 36.83 0 0 0 36.85 36.85h231.87a36.85 36.85 0 0 0 0-73.7z" />
74
- < path fill = "currentColor" d = "M306.5 307.94m32.95 0l345.1 0q32.95 0 32.95 32.95l0 342.22q0 32.95-32.95 32.95l-345.1 0q-32.95 0-32.95-32.95l0-342.22q0-32.95 32.95-32.95Z" />
75
+ < path
76
+ fill = "currentColor"
77
+ d = "M189.75 428.89a36.87 36.87 0 0 0 36.84-36.85V228.12h164a36.85 36.85 0 1 0 0-73.7H189.75a36.82 36.82 0 0 0-36.8 36.85v200.8a36.83 36.83 0 0 0 36.8 36.82zM834.26 595.06a36.82 36.82 0 0 0-36.8 36.84v164H633.41a36.85 36.85 0 0 0 0 73.7h200.85a36.87 36.87 0 0 0 36.84-36.85V631.9a36.86 36.86 0 0 0-36.84-36.84zM797.46 228.12v179.31a36.82 36.82 0 1 0 73.64 0V191.24a36.86 36.86 0 0 0-36.84-36.85H602.33a36.85 36.85 0 0 0 0 73.7zM421.62 795.9H226.54V616.56a36.82 36.82 0 1 0-73.64 0v216.19a36.83 36.83 0 0 0 36.85 36.85h231.87a36.85 36.85 0 0 0 0-73.7z"
78
+ />
79
+ < path
80
+ fill = "currentColor"
81
+ d = "M306.5 307.94m32.95 0l345.1 0q32.95 0 32.95 32.95l0 342.22q0 32.95-32.95 32.95l-345.1 0q-32.95 0-32.95-32.95l0-342.22q0-32.95 32.95-32.95Z"
82
+ />
75
83
</ svg >
76
84
) ,
77
- } ;
85
+ } ;
0 commit comments