1
- import type { RefObject } from 'react' ;
2
- import { Component , createRef } from 'react' ;
1
+ import { Component } from 'react' ;
3
2
import Panel from './Panel' ;
4
3
import OptionPanel , { Language } from './OptionPanel' ;
5
4
import type { Config } from 'react-docgen' ;
6
- import { parse } from 'react-docgen' ;
5
+ import { parse , builtinResolvers } from 'react-docgen' ;
7
6
8
7
const defaultPlugins = [
9
8
'jsx' ,
10
- 'asyncGenerators' ,
11
- 'bigInt' ,
12
- 'classProperties' ,
13
- 'classPrivateProperties' ,
14
- 'classPrivateMethods' ,
15
- [ 'decorators' , { decoratorsBeforeExport : false } ] ,
9
+ 'asyncDoExpressions' ,
10
+ 'decimal' ,
11
+ 'decorators' ,
12
+ 'decoratorAutoAccessors' ,
13
+ 'destructuringPrivate' ,
16
14
'doExpressions' ,
17
- 'dynamicImport ' ,
15
+ 'explicitResourceManagement ' ,
18
16
'exportDefaultFrom' ,
19
- 'exportNamespaceFrom' ,
20
17
'functionBind' ,
21
18
'functionSent' ,
22
- 'importMeta' ,
23
- 'logicalAssignment' ,
24
- 'nullishCoalescingOperator' ,
25
- 'numericSeparator' ,
26
- 'objectRestSpread' ,
27
- 'optionalCatchBinding' ,
28
- 'optionalChaining' ,
19
+ 'importAssertions' ,
20
+ 'importReflection' ,
21
+ 'moduleBlocks' ,
22
+ 'partialApplication' ,
29
23
[ 'pipelineOperator' , { proposal : 'minimal' } ] ,
24
+ 'recordAndTuple' ,
25
+ 'regexpUnicodeSets' ,
30
26
'throwExpressions' ,
31
- 'topLevelAwait' ,
32
27
] ;
33
28
34
29
interface PlaygroundProps {
35
30
initialContent : string ;
31
+ initialLanguage : Language ;
36
32
}
37
33
38
34
export type EditorMode = 'application/json' | 'text/jsx' | 'text/plain' ;
39
35
40
36
interface PlaygroundState {
41
37
value : string ;
42
- mode : EditorMode ;
43
38
content : string ;
44
39
language : Language ;
45
40
options : Config ;
46
41
}
47
42
48
- export default class App extends Component < PlaygroundProps , PlaygroundState > {
49
- private _jsonRef : RefObject < unknown > ;
43
+ const {
44
+ ChainResolver,
45
+ FindAllDefinitionsResolver,
46
+ FindAnnotatedDefinitionsResolver,
47
+ } = builtinResolvers ;
48
+
49
+ const resolver = new ChainResolver (
50
+ [ new FindAnnotatedDefinitionsResolver ( ) , new FindAllDefinitionsResolver ( ) ] ,
51
+ { chainingLogic : ChainResolver . Logic . ALL } ,
52
+ ) ;
50
53
54
+ export default class App extends Component < PlaygroundProps , PlaygroundState > {
51
55
constructor ( props : PlaygroundProps ) {
52
56
super ( props ) ;
53
- this . _jsonRef = createRef ( ) ;
54
57
55
- const initialLanguage = Language . TYPESCRIPT ;
56
-
57
- const options = this . buildOptions ( initialLanguage ) ;
58
+ const options = this . buildOptions ( props . initialLanguage ) ;
58
59
59
60
this . state = {
60
61
value : this . compile ( props . initialContent , options ) ,
61
- mode : 'application/json' ,
62
62
content : props . initialContent ,
63
- language : initialLanguage ,
63
+ language : props . initialLanguage ,
64
64
options,
65
65
} ;
66
66
}
@@ -71,19 +71,18 @@ export default class App extends Component<PlaygroundProps, PlaygroundState> {
71
71
72
72
handleChange = ( value : string ) => {
73
73
let result ;
74
- let mode : EditorMode = 'text/plain' ;
75
74
76
75
try {
77
76
result = this . compile ( value , this . state . options ) ;
78
- mode = 'application/json' ;
79
77
} catch ( err ) {
80
78
result = String ( err ) ;
81
79
}
82
- this . setState ( { value : result , mode , content : value } ) ;
80
+ this . setState ( { value : result , content : value } ) ;
83
81
} ;
84
82
85
83
buildOptions ( language : Language ) : Config {
86
84
const options : Config = {
85
+ resolver,
87
86
babelOptions : {
88
87
babelrc : false ,
89
88
babelrcRoots : false ,
@@ -132,12 +131,7 @@ export default class App extends Component<PlaygroundProps, PlaygroundState> {
132
131
/>
133
132
</ div >
134
133
< div className = "h-full w-1/2 flex-auto self-auto overflow-hidden" >
135
- < Panel
136
- readOnly = { true }
137
- ref = { this . _jsonRef }
138
- value = { this . state . value }
139
- mode = { this . state . mode }
140
- />
134
+ < Panel readOnly = { true } value = { this . state . value } />
141
135
</ div >
142
136
</ div >
143
137
</ >
0 commit comments