File tree Expand file tree Collapse file tree 3 files changed +24
-10
lines changed Expand file tree Collapse file tree 3 files changed +24
-10
lines changed Original file line number Diff line number Diff line change 1- import { type ReadableBoxedValues , type WritableBoxedValues } from "svelte-toolbelt" ;
1+ import { box , type ReadableBoxedValues , type WritableBoxedValues } from "svelte-toolbelt" ;
22import { getExtensionForLanguage , lazyPromise } from "$lib/util" ;
33import type { BundledLanguage , SpecialLanguage } from "shiki" ;
44import type { Snippet } from "svelte" ;
@@ -236,6 +236,23 @@ export class MultimodalFileInputState {
236236 } ) ;
237237 dragActive = $state ( false ) ;
238238
239+ /**
240+ * For creating a state instance before the component is mounted.
241+ *
242+ * @returns new state instance
243+ */
244+ static createInstance ( ) {
245+ return new MultimodalFileInputState ( {
246+ state : undefined ,
247+
248+ // These will be overridden by the component itself. Only the actual input state is inherited.
249+ label : box . with ( ( ) => "" ) ,
250+ required : box . with ( ( ) => false ) ,
251+ fileTypeOverride : box . with ( ( ) => false ) ,
252+ defaultMode : box . with ( ( ) => "file" ) ,
253+ } ) ;
254+ }
255+
239256 constructor ( opts : MultimodalFileInputStateProps ) {
240257 this . opts = opts ;
241258 if ( this . opts . state ) {
@@ -317,5 +334,6 @@ export class MultimodalFileInputState {
317334 this . text = "" ;
318335 this . file = undefined ;
319336 this . url = "" ;
337+ this . mode = this . opts . defaultMode . current ;
320338 }
321339}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export class OpenDiffDialogState {
2929
3030 githubUrl = $state ( "https://github.com/" ) ;
3131
32- patchFile = $state < MultimodalFileInputState | undefined > ( ) ;
32+ patchFile = $state ( MultimodalFileInputState . createInstance ( ) ) ;
3333
3434 fileOne = $state < MultimodalFileInputState | undefined > ( ) ;
3535 fileTwo = $state < MultimodalFileInputState | undefined > ( ) ;
Original file line number Diff line number Diff line change 2727 instance .githubUrl = githubUrlParam ;
2828 await instance .handleGithubUrl ();
2929 } else if (patchUrlParam !== null ) {
30- open = true ;
31- await tick ();
32- if (instance .patchFile ) {
33- instance .patchFile .reset ();
34- instance .patchFile .mode = " url" ;
35- instance .patchFile .url = patchUrlParam ;
36- await instance .handlePatchFile ();
37- }
30+ instance .patchFile .reset ();
31+ instance .patchFile .mode = " url" ;
32+ instance .patchFile .url = patchUrlParam ;
33+ await instance .handlePatchFile ();
3834 } else {
3935 open = true ;
4036 }
You can’t perform that action at this time.
0 commit comments