@@ -62,9 +62,6 @@ type Props<T1 = any, T2 = any, T3 = any> = Value &
62
62
/** default: true */
63
63
readonly ?: boolean
64
64
65
- /** Callback when content changes */
66
- onContentChange ?: ( content : string ) => void
67
-
68
65
/** A Block identifier, to enable cross-referencing with check lists, etc. */
69
66
blockId ?: string
70
67
@@ -107,6 +104,9 @@ type State = Value &
107
104
108
105
/** Millis timestamp of the last Run completion */
109
106
endTime ?: number
107
+
108
+ /** Any updates flowing *up* from the included CodeSnippet component */
109
+ codeSnippetValue ?: string
110
110
}
111
111
112
112
export default class Input < T1 , T2 , T3 > extends StreamingConsumer < Props < T1 , T2 , T3 > , State > {
@@ -167,12 +167,18 @@ export default class Input<T1, T2, T3> extends StreamingConsumer<Props<T1, T2, T
167
167
}
168
168
169
169
public static getDerivedStateFromProps ( props : Props , state ?: State ) {
170
- if ( ! state || state . value !== props . value || state . language !== props . language ) {
170
+ const usePropsValue = ! state || ! state . codeSnippetValue
171
+
172
+ if ( ! usePropsValue && state && state . codeSnippetValue ) {
173
+ return Object . assign ( state , {
174
+ value : state . codeSnippetValue
175
+ } )
176
+ } else if ( ! state || state . value !== props . value || state . language !== props . language ) {
171
177
const execUUID = uuid ( )
172
178
return Object . assign (
173
179
{
174
180
execution : props . status || 'not-yet' ,
175
- value : props . value ,
181
+ value : usePropsValue ? props . value : state . codeSnippetValue || state . value ,
176
182
language : props . language ,
177
183
validated : false
178
184
} ,
@@ -222,6 +228,11 @@ export default class Input<T1, T2, T3> extends StreamingConsumer<Props<T1, T2, T
222
228
}
223
229
}
224
230
231
+ /** Updates coming from the CodeSnippet component */
232
+ private readonly onContentChange = ( codeSnippetValue : string ) => {
233
+ this . setState ( { codeSnippetValue } )
234
+ }
235
+
225
236
private input ( ) {
226
237
return (
227
238
< div className = "repl-input-element-wrapper flex-layout flex-fill kui--inverted-color-context kui--relative-positioning" >
@@ -230,10 +241,11 @@ export default class Input<T1, T2, T3> extends StreamingConsumer<Props<T1, T2, T
230
241
< div className = "flex-fill" >
231
242
< CodeSnippet
232
243
wordWrap = "on"
233
- tabUUID = { this . props . tab ? this . props . tab . uuid : undefined }
234
244
value = { this . state . value }
235
245
language = { this . state . language }
236
- onContentChange = { this . props . onContentChange }
246
+ onContentChange = { this . onContentChange }
247
+ readonly = { this . props . readonly !== false }
248
+ tabUUID = { this . props . tab ? this . props . tab . uuid : undefined }
237
249
/>
238
250
</ div >
239
251
{ this . actions ( ) }
0 commit comments