File tree 6 files changed +54
-47
lines changed
routes/tutorial/[slug]/filetree
6 files changed +54
-47
lines changed Original file line number Diff line number Diff line change @@ -89,3 +89,9 @@ export interface Warning {
89
89
frame : string ;
90
90
message : string ;
91
91
}
92
+
93
+ export interface MenuItem {
94
+ icon : string ;
95
+ label : string ;
96
+ fn : ( ) => void ;
97
+ }
Original file line number Diff line number Diff line change 5
5
import { writable } from ' svelte/store' ;
6
6
7
7
/**
8
- * @typedef {{ icon: string; label: string; fn: () => void }} MenuItem
9
- */
10
-
11
- /**
12
- * @type {import("svelte/store").Writable<{x: number; y: number; items: MenuItem[]} | null>}
8
+ * @type {import("svelte/store").Writable<{x: number; y: number; items: import('$lib/types').MenuItem[]} | null>}
13
9
*/
14
10
let menu_items = writable (null );
15
11
16
12
/**
17
13
* @param {number} x
18
14
* @param {number} y
19
- * @param {MenuItem[]} items
15
+ * @param {import('$lib/types'). MenuItem[]} items
20
16
*/
21
17
export function open (x , y , items ) {
22
18
if (items .length > 0 ) {
Original file line number Diff line number Diff line change 16
16
17
17
$: can_remove = ! $solution[file .name ];
18
18
19
- /** @type {import('./ContextMenu.svelte ').MenuItems } */
19
+ /** @type {import('$lib/types ').MenuItem[] } */
20
20
$: actions = can_remove
21
21
? [
22
22
{
Original file line number Diff line number Diff line change 146
146
if (e .key === ' ArrowUp' || e .key === ' ArrowDown' ) {
147
147
e .preventDefault ();
148
148
const lis = Array .from (e .currentTarget .querySelectorAll (' li' ));
149
- const focused = lis .findIndex ((li ) => li .contains (e .target ));
149
+ const focused = lis .findIndex ((li ) => li .contains (/** @type {HTMLElement} */ ( e .target ) ));
150
150
151
151
const d = e .key === ' ArrowUp' ? - 1 : + 1 ;
152
152
Original file line number Diff line number Diff line change 33
33
(child ) => get_depth (child .name ) === segments && child .type === ' directory'
34
34
);
35
35
36
- $: child_files = /** @type {import('$lib/types').FileStub[]} */ (
37
- children .filter ((child ) => get_depth (child .name ) === segments && child .type === ' file' )
36
+ // prettier-ignore
37
+ $: child_files = (
38
+ /** @type {import('$lib/types').FileStub[]} */ (
39
+ children .filter ((child ) => get_depth (child .name ) === segments && child .type === ' file' )
40
+ )
38
41
);
39
42
40
43
const can_create = { file: false , directory: false };
71
74
// fake root directory has no name
72
75
$: can_remove = directory .name ? ! $solution[directory .name ] : false ;
73
76
74
- /** @type {import('./ContextMenu.svelte').MenuItem[]} */
75
- $: actions = [
76
- can_create .file && {
77
- icon: ' file-new' ,
78
- label: ' New file' ,
79
- fn : () => {
80
- creating .set ({
81
- parent: directory .name ,
82
- type: ' file'
83
- });
77
+ // prettier-ignore
78
+ $: actions = (
79
+ /** @type {import('$lib/types').MenuItem[]} */ ([
80
+ can_create .file && {
81
+ icon: ' file-new' ,
82
+ label: ' New file' ,
83
+ fn : () => {
84
+ creating .set ({
85
+ parent: directory .name ,
86
+ type: ' file'
87
+ });
88
+ }
89
+ },
90
+ can_create .directory && {
91
+ icon: ' folder-new' ,
92
+ label: ' New folder' ,
93
+ fn : () => {
94
+ creating .set ({
95
+ parent: directory .name ,
96
+ type: ' directory'
97
+ });
98
+ }
99
+ },
100
+ can_remove && {
101
+ icon: ' rename' ,
102
+ label: ' Rename' ,
103
+ fn : () => {
104
+ renaming = true ;
105
+ }
106
+ },
107
+ can_remove && {
108
+ icon: ' delete' ,
109
+ label: ' Delete' ,
110
+ fn : () => {
111
+ remove (directory);
112
+ }
84
113
}
85
- },
86
- can_create .directory && {
87
- icon: ' folder-new' ,
88
- label: ' New folder' ,
89
- fn : () => {
90
- creating .set ({
91
- parent: directory .name ,
92
- type: ' directory'
93
- });
94
- }
95
- },
96
- can_remove && {
97
- icon: ' rename' ,
98
- label: ' Rename' ,
99
- fn : () => {
100
- renaming = true ;
101
- }
102
- },
103
- can_remove && {
104
- icon: ' delete' ,
105
- label: ' Delete' ,
106
- fn : () => {
107
- remove (directory);
108
- }
109
- }
110
- ].filter (Boolean );
114
+ ].filter (Boolean ))
115
+ );
111
116
</script >
112
117
113
118
<Item
Original file line number Diff line number Diff line change 14
14
/** @type {boolean} */
15
15
export let renaming;
16
16
17
- /** @type {import('./ContextMenu.svelte ').MenuItem[]} */
17
+ /** @type {import('$lib/types ').MenuItem[]} */
18
18
export let actions = [];
19
19
20
20
const dispatch = createEventDispatcher ();
You can’t perform that action at this time.
0 commit comments