1
1
import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
- import { aceResizeKey , offerCrateAutocompleteOnUse } from './selectors' ;
3
+ import { aceResizeKey , offerCrateAutocompleteOnUse } from '.. /selectors' ;
4
4
5
- import State from './state' ;
6
- import { AceResizeKey , CommonEditorProps , Crate , PairCharacters , Position , Selection } from './types' ;
5
+ import State from '.. /state' ;
6
+ import { AceResizeKey , CommonEditorProps , Crate , PairCharacters , Position , Selection } from '.. /types' ;
7
7
8
8
import styles from './Editor.module.css' ;
9
9
10
10
type Ace = typeof import ( 'ace-builds' ) ;
11
- type AceEditor = import ( 'ace-builds' ) . Ace . Editor ;
11
+ type AceModule = import ( 'ace-builds' ) . Ace . Editor ;
12
12
type AceCompleter = import ( 'ace-builds' ) . Ace . Completer ;
13
13
14
- const displayExternCrateAutocomplete = ( editor : AceEditor , autocompleteOnUse : boolean ) => {
14
+ const displayExternCrateAutocomplete = ( editor : AceModule , autocompleteOnUse : boolean ) => {
15
15
const { session } = editor ;
16
16
const pos = editor . getCursorPosition ( ) ;
17
17
const line = session . getLine ( pos . row ) ;
@@ -55,11 +55,11 @@ function useRafDebouncedFunction<A extends any[]>(fn: (...args: A) => void, onCa
55
55
} , [ fn , onCall , timeout ] ) ;
56
56
}
57
57
58
- interface AdvancedEditorProps extends AdvancedEditorAsyncProps {
58
+ interface AceEditorProps extends AceEditorAsyncProps {
59
59
ace : Ace ;
60
60
}
61
61
62
- interface AdvancedEditorProps {
62
+ interface AceEditorProps {
63
63
ace : Ace ;
64
64
autocompleteOnUse : boolean ;
65
65
code : string ;
@@ -75,16 +75,16 @@ interface AdvancedEditorProps {
75
75
}
76
76
77
77
// Run an effect when the editor or prop changes
78
- function useEditorProp < T > ( editor : AceEditor , prop : T , whenPresent : ( editor : AceEditor , prop : T ) => void ) {
78
+ function useEditorProp < T > ( editor : AceModule , prop : T , whenPresent : ( editor : AceModule , prop : T ) => void ) {
79
79
useEffect ( ( ) => {
80
80
if ( editor ) {
81
81
return whenPresent ( editor , prop ) ;
82
82
}
83
83
} , [ editor , prop , whenPresent ] ) ;
84
84
}
85
85
86
- const AdvancedEditor : React . SFC < AdvancedEditorProps > = props => {
87
- const [ editor , setEditor ] = useState < AceEditor > ( null ) ;
86
+ const AceEditor : React . SFC < AceEditorProps > = props => {
87
+ const [ editor , setEditor ] = useState < AceModule > ( null ) ;
88
88
const child = useRef < HTMLDivElement > ( null ) ;
89
89
90
90
useEffect ( ( ) => {
@@ -292,7 +292,7 @@ const AdvancedEditor: React.SFC<AdvancedEditorProps> = props => {
292
292
} , [ ] ) ) ;
293
293
294
294
return (
295
- < div className = { styles . advanced } ref = { child } />
295
+ < div className = { styles . ace } ref = { child } />
296
296
) ;
297
297
} ;
298
298
@@ -315,7 +315,7 @@ enum LoadState {
315
315
//
316
316
// Themes and keybindings can be changed at runtime.
317
317
318
- interface AdvancedEditorAsyncProps {
318
+ interface AceEditorAsyncProps {
319
319
autocompleteOnUse : boolean ;
320
320
code : string ;
321
321
execute : ( ) => any ;
@@ -329,7 +329,7 @@ interface AdvancedEditorAsyncProps {
329
329
pairCharacters : PairCharacters ;
330
330
}
331
331
332
- class AdvancedEditorAsync extends React . Component < AdvancedEditorAsyncProps , AdvancedEditorAsyncState > {
332
+ class AceEditorAsync extends React . Component < AceEditorAsyncProps , AceEditorAsyncState > {
333
333
public constructor ( props ) {
334
334
super ( props ) ;
335
335
this . state = {
@@ -342,7 +342,7 @@ class AdvancedEditorAsync extends React.Component<AdvancedEditorAsyncProps, Adva
342
342
public render ( ) {
343
343
if ( this . isLoaded ( ) ) {
344
344
const { ace, theme, keybinding } = this . state ;
345
- return < AdvancedEditor { ...this . props } ace = { ace } theme = { theme } keybinding = { keybinding } /> ;
345
+ return < AceEditor { ...this . props } ace = { ace } theme = { theme } keybinding = { keybinding } /> ;
346
346
} else {
347
347
return < div > Loading the ACE editor...</ div > ;
348
348
}
@@ -447,13 +447,13 @@ class AdvancedEditorAsync extends React.Component<AdvancedEditorAsyncProps, Adva
447
447
448
448
private async requireLibraries ( ) {
449
449
return import (
450
- /* webpackChunkName: "advanced -editor" */
451
- './advanced -editor'
450
+ /* webpackChunkName: "ace -editor" */
451
+ './ace -editor'
452
452
) ;
453
453
}
454
454
}
455
455
456
- interface AdvancedEditorAsyncState {
456
+ interface AceEditorAsyncState {
457
457
theme ?: string ;
458
458
keybinding ?: string ;
459
459
themeState : LoadState ;
@@ -472,7 +472,7 @@ interface PropsFromState {
472
472
}
473
473
474
474
const mapStateToProps = ( state : State ) => {
475
- const { configuration : { theme, keybinding, pairCharacters } } = state ;
475
+ const { configuration : { ace : { theme, keybinding, pairCharacters } } } = state ;
476
476
477
477
return {
478
478
theme,
@@ -483,4 +483,4 @@ const mapStateToProps = (state: State) => {
483
483
} ;
484
484
} ;
485
485
486
- export default connect < PropsFromState , undefined , CommonEditorProps > ( mapStateToProps ) ( AdvancedEditorAsync ) ;
486
+ export default connect < PropsFromState , undefined , CommonEditorProps > ( mapStateToProps ) ( AceEditorAsync ) ;
0 commit comments