@@ -9,31 +9,29 @@ export function createNameConflictDialogState() {
9
9
let description = $state . raw ( "" ) ;
10
10
let onClose : ( ( result : NameConflictResolution ) => void ) | undefined ;
11
11
12
- function show ( args : {
12
+ type ShowArgs = {
13
13
title : string ;
14
14
description : string ;
15
15
onClose : ( result : NameConflictResolution ) => void ;
16
- } ) : void {
17
- open = true ;
18
- title = args . title ;
19
- description = args . description ;
20
- onClose = args . onClose ;
21
- }
22
-
23
- function close ( result : NameConflictResolution ) : void {
24
- open = false ;
25
- title = "" ;
26
- description = "" ;
27
- onClose ! ( result ) ;
28
- onClose = undefined ;
29
- }
16
+ } ;
30
17
31
18
return {
32
19
open : ( ) => open ,
33
20
title : ( ) => title ,
34
21
description : ( ) => description ,
35
- show,
36
- close,
22
+ show : ( args : ShowArgs ) => {
23
+ open = true ;
24
+ title = args . title ;
25
+ description = args . description ;
26
+ onClose = args . onClose ;
27
+ } ,
28
+ close : ( result : NameConflictResolution ) => {
29
+ open = false ;
30
+ title = "" ;
31
+ description = "" ;
32
+ onClose ! ( result ) ;
33
+ onClose = undefined ;
34
+ } ,
37
35
} ;
38
36
}
39
37
@@ -43,36 +41,32 @@ export function createNameFormDialogState() {
43
41
let title = $state . raw ( "" ) ;
44
42
let onSubmit : ( ( name : string ) => void ) | undefined ;
45
43
46
- function setName ( value : string ) : void {
47
- name = value ;
48
- }
49
-
50
- function show ( args : { title : string ; onSubmit : ( name : string ) => void ; name ?: string } ) : void {
51
- name = args . name ?? "" ;
52
- open = true ;
53
- title = args . title ;
54
- onSubmit = args . onSubmit ;
55
- }
56
-
57
- function submit ( ) : void {
58
- onSubmit ! ( name ) ;
59
- }
60
-
61
- function close ( ) : void {
62
- name = "" ;
63
- open = false ;
64
- title = "" ;
65
- onSubmit = undefined ;
66
- }
44
+ type ShowArgs = {
45
+ title : string ;
46
+ onSubmit : ( name : string ) => void ;
47
+ name ?: string ;
48
+ } ;
67
49
68
50
return {
69
51
name : ( ) => name ,
70
- setName,
52
+ setName : ( value : string ) => {
53
+ name = value ;
54
+ } ,
71
55
open : ( ) => open ,
72
56
title : ( ) => title ,
73
- show,
74
- submit,
75
- close,
57
+ show : ( args : ShowArgs ) => {
58
+ name = args . name ?? "" ;
59
+ open = true ;
60
+ title = args . title ;
61
+ onSubmit = args . onSubmit ;
62
+ } ,
63
+ submit : ( ) => onSubmit ! ( name ) ,
64
+ close : ( ) => {
65
+ name = "" ;
66
+ open = false ;
67
+ title = "" ;
68
+ onSubmit = undefined ;
69
+ } ,
76
70
} ;
77
71
}
78
72
@@ -105,11 +99,7 @@ export function createContextMenuState({
105
99
} ) {
106
100
let target : TreeContextMenuTarget | undefined = $state . raw ( ) ;
107
101
108
- function setTarget ( value : TreeContextMenuTarget ) : void {
109
- target = value ;
110
- }
111
-
112
- function item ( ) : TreeItemState {
102
+ function item ( ) {
113
103
switch ( target ! . type ) {
114
104
case "tree" : {
115
105
throw new Error ( "Expected an item" ) ;
@@ -120,7 +110,7 @@ export function createContextMenuState({
120
110
}
121
111
}
122
112
123
- function folderOrTree ( ) : FolderNode | FileTree {
113
+ function folderOrTree ( ) {
124
114
switch ( target ! . type ) {
125
115
case "tree" : {
126
116
return target ! . tree ( ) ;
@@ -135,61 +125,32 @@ export function createContextMenuState({
135
125
}
136
126
}
137
127
138
- function rename ( ) : void {
139
- onRename ( item ( ) ) ;
140
- }
141
-
142
- function copy ( ) : void {
143
- onCopy ( item ( ) ) ;
144
- }
145
-
146
- function cut ( ) : void {
147
- onCut ( item ( ) ) ;
148
- }
149
-
150
- function paste ( ) : void {
151
- onPaste ( item ( ) ) ;
152
- }
153
-
154
- function remove ( ) : void {
155
- onRemove ( item ( ) ) ;
156
- }
157
-
158
- function createFolder ( ) : void {
159
- onCreateFolder ( folderOrTree ( ) ) ;
160
- }
161
-
162
- function uploadFiles ( ) : void {
163
- onUploadFiles ( folderOrTree ( ) ) ;
164
- }
165
-
166
- function close ( ) : void {
167
- target = undefined ;
168
- }
169
-
170
128
return {
171
129
target : ( ) => target ,
172
- setTarget,
173
- rename,
174
- copy,
175
- cut,
176
- paste,
177
- remove,
178
- createFolder,
179
- uploadFiles,
180
- close,
130
+ setTarget : ( value : TreeContextMenuTarget ) => {
131
+ target = value ;
132
+ } ,
133
+ rename : ( ) => onRename ( item ( ) ) ,
134
+ copy : ( ) => onCopy ( item ( ) ) ,
135
+ cut : ( ) => onCut ( item ( ) ) ,
136
+ paste : ( ) => onPaste ( item ( ) ) ,
137
+ remove : ( ) => onRemove ( item ( ) ) ,
138
+ createFolder : ( ) => onCreateFolder ( folderOrTree ( ) ) ,
139
+ uploadFiles : ( ) => onUploadFiles ( folderOrTree ( ) ) ,
140
+ close : ( ) => {
141
+ target = undefined ;
142
+ } ,
181
143
} ;
182
144
}
183
145
184
146
export function createFileInputState ( { ref } : { ref : ( ) => HTMLInputElement | null } ) {
185
147
let onPick : ( ( files : FileList ) => void ) | undefined ;
186
148
187
- function showPicker ( args : { onPick : ( files : FileList ) => void } ) : void {
188
- onPick = args . onPick ;
189
- ref ( ) ! . click ( ) ;
190
- }
149
+ type ShowPickerArgs = {
150
+ onPick : ( files : FileList ) => void ;
151
+ } ;
191
152
192
- const onChange : EventHandler < Event , HTMLInputElement > = ( event ) => {
153
+ const onchange : EventHandler < Event , HTMLInputElement > = ( event ) => {
193
154
const { files } = event . currentTarget ;
194
155
if ( files !== null && files . length !== 0 ) {
195
156
onPick ! ( files ) ;
@@ -199,13 +160,16 @@ export function createFileInputState({ ref }: { ref: () => HTMLInputElement | nu
199
160
event . currentTarget . value = "" ;
200
161
} ;
201
162
202
- const onCancel : EventHandler < Event , HTMLInputElement > = ( ) => {
163
+ const oncancel : EventHandler < Event , HTMLInputElement > = ( ) => {
203
164
onPick = undefined ;
204
165
} ;
205
166
206
167
return {
207
- showPicker,
208
- onChange,
209
- onCancel,
168
+ showPicker : ( args : ShowPickerArgs ) => {
169
+ onPick = args . onPick ;
170
+ ref ( ) ! . click ( ) ;
171
+ } ,
172
+ onchange,
173
+ oncancel,
210
174
} ;
211
175
}
0 commit comments