9
import {PluginOptions} from 'babel-plugin-react-compiler';
10
import type {editor} from 'monaco-editor';
11
import * as monaco from 'monaco-editor';
12
-import React, {useState, useRef} from 'react';
12
+import React, {
13
+ useState,
14
+ useRef,
15
+ unstable_ViewTransition as ViewTransition,
16
+ unstable_addTransitionType as addTransitionType,
17
+ startTransition,
18
+} from 'react';
19
import {Resizable} from 're-resizable';
20
import {useStore, useStoreDispatch} from '../StoreContext';
21
import {monacoOptions} from './monacoOptions';
22
import {IconChevron} from '../Icons/IconChevron';
23
import prettyFormat from 'pretty-format';
24
+import {CONFIG_PANEL_TRANSITION} from '../../lib/transitionTypes';
25
26
// @ts-expect-error - webpack asset/source loader handles .d.ts files as strings
27
import compilerTypeDefs from 'babel-plugin-react-compiler/dist/index.d.ts';
43
display: isExpanded ? 'block' : 'none',
44
}}>
45
<ExpandedEditor
39
- onToggle={setIsExpanded}
46
+ onToggle={() => {
47
+ startTransition(() => {
48
+ addTransitionType(CONFIG_PANEL_TRANSITION);
49
+ setIsExpanded(false);
50
+ });
51
+ }}
52
appliedOptions={appliedOptions}
53
/>
54
</div>
56
style={{
57
display: !isExpanded ? 'block' : 'none',
58
}}>
47
- <CollapsedEditor onToggle={setIsExpanded} />
59
+ <CollapsedEditor
60
+ onToggle={() => {
61
+ startTransition(() => {
62
+ addTransitionType(CONFIG_PANEL_TRANSITION);
63
+ setIsExpanded(true);
64
+ });
65
+ }}
66
+ />
67
</div>
68
</>
69
);
73
onToggle,
74
appliedOptions,
75
}: {
57
- onToggle: (expanded: boolean) => void;
76
+ onToggle: () => void;
77
appliedOptions: PluginOptions | null;
78
}): React.ReactElement {
79
const store = useStore();
130
: 'Invalid configs';
131
132
return (
114
- <Resizable
115
- minWidth={300}
116
- maxWidth={600}
117
- defaultSize={{width: 350}}
118
- enable={{right: true, bottom: false}}>
119
- <div className="bg-blue-10 relative h-full flex flex-col !h-[calc(100vh_-_3.5rem)] border border-gray-300">
120
- <div
121
- className="absolute w-8 h-16 bg-blue-10 rounded-r-full flex items-center justify-center z-[2] cursor-pointer border border-l-0 border-gray-300"
122
- title="Minimize config editor"
123
- onClick={() => onToggle(false)}
124
- style={{
125
- top: '50%',
126
- marginTop: '-32px',
127
- right: '-32px',
128
- borderTopLeftRadius: 0,
129
- borderBottomLeftRadius: 0,
130
- }}>
131
- <IconChevron displayDirection="left" className="text-blue-50" />
132
- </div>
133
-
134
- <div className="flex-1 flex flex-col m-2 mb-2">
135
- <div className="pb-2">
136
- <h2 className="inline-block text-blue-50 py-1.5 px-1.5 xs:px-3 sm:px-4 text-sm">
137
- Config Overrides
138
- </h2>
139
- </div>
140
- <div className="flex-1 rounded-lg overflow-hidden border border-gray-300">
141
- <MonacoEditor
142
- path={'config.ts'}
143
- language={'typescript'}
144
- value={store.config}
145
- onMount={handleMount}
146
- onChange={handleChange}
147
- loading={''}
148
- className="monaco-editor-config"
149
- options={{
150
- ...monacoOptions,
151
- lineNumbers: 'off',
152
- renderLineHighlight: 'none',
153
- overviewRulerBorder: false,
154
- overviewRulerLanes: 0,
155
- fontSize: 12,
156
- scrollBeyondLastLine: false,
157
- glyphMargin: false,
158
- }}
159
- />
133
+ <ViewTransition
134
+ update={{[CONFIG_PANEL_TRANSITION]: 'slide-in', default: 'none'}}>
135
+ <Resizable
136
+ minWidth={300}
137
+ maxWidth={600}
138
+ defaultSize={{width: 350}}
139
+ enable={{right: true, bottom: false}}>
140
+ <div className="bg-blue-10 relative h-full flex flex-col !h-[calc(100vh_-_3.5rem)] border border-gray-300">
141
+ <div
142
+ className="absolute w-8 h-16 bg-blue-10 rounded-r-full flex items-center justify-center z-[2] cursor-pointer border border-l-0 border-gray-300"
143
+ title="Minimize config editor"
144
+ onClick={onToggle}
145
+ style={{
146
+ top: '50%',
147
+ marginTop: '-32px',
148
+ right: '-32px',
149
+ borderTopLeftRadius: 0,
150
+ borderBottomLeftRadius: 0,
151
+ }}>
152
+ <IconChevron displayDirection="left" className="text-blue-50" />
153
</div>
161
- </div>
162
- <div className="flex-1 flex flex-col m-2">
163
- <div className="pb-2">
164
- <h2 className="inline-block text-blue-50 py-1.5 px-1.5 xs:px-3 sm:px-4 text-sm">
165
- Applied Configs
166
- </h2>
154
+
155
+ <div className="flex-1 flex flex-col m-2 mb-2">
156
+ <div className="pb-2">
157
+ <h2 className="inline-block text-blue-50 py-1.5 px-1.5 xs:px-3 sm:px-4 text-sm">
158
+ Config Overrides
159
+ </h2>
160
+ </div>
161
+ <div className="flex-1 rounded-lg overflow-hidden border border-gray-300">
162
+ <MonacoEditor
163
+ path={'config.ts'}
164
+ language={'typescript'}
165
+ value={store.config}
166
+ onMount={handleMount}
167
+ onChange={handleChange}
168
+ loading={''}
169
+ className="monaco-editor-config"
170
+ options={{
171
+ ...monacoOptions,
172
+ lineNumbers: 'off',
173
+ renderLineHighlight: 'none',
174
+ overviewRulerBorder: false,
175
+ overviewRulerLanes: 0,
176
+ fontSize: 12,
177
+ scrollBeyondLastLine: false,
178
+ glyphMargin: false,
179
+ }}
180
+ />
181
+ </div>
182
</div>
168
- <div className="flex-1 rounded-lg overflow-hidden border border-gray-300">
169
- <MonacoEditor
170
- path={'applied-config.js'}
171
- language={'javascript'}
172
- value={formattedAppliedOptions}
173
- loading={''}
174
- className="monaco-editor-applied-config"
175
- options={{
176
- ...monacoOptions,
177
- lineNumbers: 'off',
178
- renderLineHighlight: 'none',
179
- overviewRulerBorder: false,
180
- overviewRulerLanes: 0,
181
- fontSize: 12,
182
- scrollBeyondLastLine: false,
183
- readOnly: true,
184
- glyphMargin: false,
185
- }}
186
- />
183
+ <div className="flex-1 flex flex-col m-2">
184
+ <div className="pb-2">
185
+ <h2 className="inline-block text-blue-50 py-1.5 px-1.5 xs:px-3 sm:px-4 text-sm">
186
+ Applied Configs
187
+ </h2>
188
+ </div>
189
+ <div className="flex-1 rounded-lg overflow-hidden border border-gray-300">
190
+ <MonacoEditor
191
+ path={'applied-config.js'}
192
+ language={'javascript'}
193
+ value={formattedAppliedOptions}
194
+ loading={''}
195
+ className="monaco-editor-applied-config"
196
+ options={{
197
+ ...monacoOptions,
198
+ lineNumbers: 'off',
199
+ renderLineHighlight: 'none',
200
+ overviewRulerBorder: false,
201
+ overviewRulerLanes: 0,
202
+ fontSize: 12,
203
+ scrollBeyondLastLine: false,
204
+ readOnly: true,
205
+ glyphMargin: false,
206
+ }}
207
+ />
208
+ </div>
209
</div>
210
</div>
189
- </div>
190
- </Resizable>
211
+ </Resizable>
212
+ </ViewTransition>
213
);
214
}
215
216
function CollapsedEditor({
217
onToggle,
218
}: {
197
- onToggle: (expanded: boolean) => void;
219
+ onToggle: () => void;
220
}): React.ReactElement {
221
return (
222
<div
225
<div
226
className="absolute w-10 h-16 bg-blue-10 hover:translate-x-2 transition-transform rounded-r-full flex items-center justify-center z-[2] cursor-pointer border border-gray-300"
227
title="Expand config editor"
206
- onClick={() => onToggle(true)}
228
+ onClick={onToggle}
229
style={{
230
top: '50%',
231
marginTop: '-32px',