@daoninc/opencode-file-explorer 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/dist/model.d.ts +36 -0
- package/dist/model.js +150 -0
- package/dist/preview.js +10 -0
- package/dist/prompt-focus.d.ts +15 -0
- package/dist/prompt-focus.js +31 -0
- package/dist/prompt.d.ts +9 -0
- package/dist/prompt.js +13 -0
- package/dist/tui.js +647 -0
- package/package.json +7 -7
- package/model.ts +0 -149
- package/preview.ts +0 -8
- package/prompt-focus.ts +0 -35
- package/prompt.ts +0 -24
- package/tui.tsx +0 -337
package/dist/tui.js
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
import { createTextNode as _$createTextNode } from "@opentui/solid";
|
|
2
|
+
import { use as _$use } from "@opentui/solid";
|
|
3
|
+
import { createComponent as _$createComponent } from "@opentui/solid";
|
|
4
|
+
import { effect as _$effect } from "@opentui/solid";
|
|
5
|
+
import { insertNode as _$insertNode } from "@opentui/solid";
|
|
6
|
+
import { insert as _$insert } from "@opentui/solid";
|
|
7
|
+
import { memo as _$memo } from "@opentui/solid";
|
|
8
|
+
import { setProp as _$setProp } from "@opentui/solid";
|
|
9
|
+
import { createElement as _$createElement } from "@opentui/solid";
|
|
10
|
+
import { Plugin, usePlugin } from "@opencode/plugin/tui";
|
|
11
|
+
import { createEffect, createMemo, createSignal, For, onCleanup, Show, untrack } from "solid-js";
|
|
12
|
+
import { createTree, readPreview, searchRows, visibleRows } from "./model.js";
|
|
13
|
+
import { insertFileReference } from "./prompt.js";
|
|
14
|
+
import { trackPromptFocus } from "./prompt-focus.js";
|
|
15
|
+
import { createPreviewRequest } from "./preview.js";
|
|
16
|
+
const PANEL = "daoninc.file-explorer";
|
|
17
|
+
function Explorer(props) {
|
|
18
|
+
const context = usePlugin();
|
|
19
|
+
const fallback = context.location ?? context.data.location.default();
|
|
20
|
+
const directory = () => context.data.session.get(props.panel.sessionID)?.location.directory ?? fallback.directory;
|
|
21
|
+
const [state, setState] = createSignal({
|
|
22
|
+
children: {},
|
|
23
|
+
expanded: new Set(),
|
|
24
|
+
loading: new Set(),
|
|
25
|
+
errors: {}
|
|
26
|
+
});
|
|
27
|
+
const [hidden, setHidden] = createSignal(false);
|
|
28
|
+
const [selected, setSelected] = createSignal("");
|
|
29
|
+
const [preview, setPreview] = createSignal();
|
|
30
|
+
const [content, setContent] = createSignal("");
|
|
31
|
+
const [reading, setReading] = createSignal(false);
|
|
32
|
+
const [query, setQuery] = createSignal("");
|
|
33
|
+
const [searchFocused, setSearchFocused] = createSignal(true);
|
|
34
|
+
const [matches, setMatches] = createSignal([]);
|
|
35
|
+
const [searching, setSearching] = createSignal(false);
|
|
36
|
+
const [searchError, setSearchError] = createSignal("");
|
|
37
|
+
const isSearch = () => Boolean(query().trim());
|
|
38
|
+
const rows = createMemo(() => isSearch() ? searchRows(matches(), hidden()) : visibleRows(state(), hidden()));
|
|
39
|
+
const current = () => rows().find(row => row.path === selected());
|
|
40
|
+
const promptFile = () => preview() ?? (current()?.type === "file" ? selected() : undefined);
|
|
41
|
+
let treeScroll;
|
|
42
|
+
let previewScroll;
|
|
43
|
+
let readRequest;
|
|
44
|
+
let debounce;
|
|
45
|
+
let disposed = false;
|
|
46
|
+
const tree = createTree(async (directory, path, signal) => {
|
|
47
|
+
const response = await context.client.file.list({
|
|
48
|
+
location: {
|
|
49
|
+
directory
|
|
50
|
+
},
|
|
51
|
+
path: path || "."
|
|
52
|
+
}, {
|
|
53
|
+
signal
|
|
54
|
+
});
|
|
55
|
+
return response.data;
|
|
56
|
+
}, setState);
|
|
57
|
+
const closePreview = () => {
|
|
58
|
+
readRequest?.abort();
|
|
59
|
+
setPreview(undefined);
|
|
60
|
+
setReading(false);
|
|
61
|
+
};
|
|
62
|
+
async function open(row = current()) {
|
|
63
|
+
if (!row) return;
|
|
64
|
+
if (row.type === "directory") {
|
|
65
|
+
await tree.toggle(row.path);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
await previewFile(row.path);
|
|
69
|
+
}
|
|
70
|
+
async function previewFile(path) {
|
|
71
|
+
readRequest?.abort();
|
|
72
|
+
const request = new AbortController();
|
|
73
|
+
readRequest = request;
|
|
74
|
+
setSearchFocused(false);
|
|
75
|
+
setPreview(path);
|
|
76
|
+
setContent("");
|
|
77
|
+
setReading(true);
|
|
78
|
+
try {
|
|
79
|
+
const text = await readPreview((input, options) => context.client.file.read(input, options), directory(), path, request.signal);
|
|
80
|
+
if (!disposed && !request.signal.aborted) setContent(text);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (!disposed && !request.signal.aborted) setContent(`Cannot preview file: ${error instanceof Error ? error.message : String(error)}`);
|
|
83
|
+
} finally {
|
|
84
|
+
if (!disposed && !request.signal.aborted) setReading(false);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function move(delta) {
|
|
88
|
+
if (preview()) {
|
|
89
|
+
previewScroll?.scrollBy(delta);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const index = rows().findIndex(row => row.path === selected());
|
|
93
|
+
const row = rows()[Math.max(0, Math.min(rows().length - 1, index + delta))];
|
|
94
|
+
if (row) setSelected(row.path);
|
|
95
|
+
}
|
|
96
|
+
function back() {
|
|
97
|
+
if (preview()) {
|
|
98
|
+
closePreview();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const row = current();
|
|
102
|
+
if (!row) return;
|
|
103
|
+
if (state().expanded.has(row.path)) {
|
|
104
|
+
void tree.toggle(row.path);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (row.parent) setSelected(row.parent);
|
|
108
|
+
}
|
|
109
|
+
const [searchRevision, setSearchRevision] = createSignal(0);
|
|
110
|
+
function refresh() {
|
|
111
|
+
if (isSearch()) setSearchRevision(value => value + 1);else void tree.refresh();
|
|
112
|
+
}
|
|
113
|
+
async function addToPrompt() {
|
|
114
|
+
const path = promptFile();
|
|
115
|
+
if (!path) return;
|
|
116
|
+
const sessionID = props.panel.sessionID;
|
|
117
|
+
const root = directory();
|
|
118
|
+
try {
|
|
119
|
+
await insertFileReference(path, {
|
|
120
|
+
close: () => props.panel.close(),
|
|
121
|
+
isCurrent: () => {
|
|
122
|
+
const route = context.ui.router.current();
|
|
123
|
+
return route.type === "session" && route.sessionID === sessionID && (context.data.session.get(sessionID)?.location.directory ?? fallback.directory) === root;
|
|
124
|
+
},
|
|
125
|
+
focus: props.focusPrompt,
|
|
126
|
+
paste: bytes => context.renderer.keyInput.processPaste(bytes)
|
|
127
|
+
});
|
|
128
|
+
} catch (error) {
|
|
129
|
+
context.ui.toast.show({
|
|
130
|
+
message: error instanceof Error ? error.message : String(error),
|
|
131
|
+
variant: "error"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
createEffect(() => {
|
|
136
|
+
const next = directory();
|
|
137
|
+
untrack(() => {
|
|
138
|
+
closePreview();
|
|
139
|
+
setSelected("");
|
|
140
|
+
setQuery("");
|
|
141
|
+
setSearchFocused(true);
|
|
142
|
+
void tree.setDirectory(next);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
createEffect(() => {
|
|
146
|
+
const request = props.request;
|
|
147
|
+
const root = directory();
|
|
148
|
+
if (!request || request.sessionID !== props.panel.sessionID || request.directory !== root) return;
|
|
149
|
+
untrack(() => {
|
|
150
|
+
setSelected(request.path);
|
|
151
|
+
void previewFile(request.path);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
createEffect(() => {
|
|
155
|
+
const root = directory();
|
|
156
|
+
const text = query().trim();
|
|
157
|
+
searchRevision();
|
|
158
|
+
setMatches([]);
|
|
159
|
+
setSearchError("");
|
|
160
|
+
setSearching(Boolean(text));
|
|
161
|
+
if (!text) return;
|
|
162
|
+
let active = true;
|
|
163
|
+
const request = new AbortController();
|
|
164
|
+
const timer = setTimeout(async () => {
|
|
165
|
+
try {
|
|
166
|
+
const response = await context.client.file.find({
|
|
167
|
+
location: {
|
|
168
|
+
directory: root
|
|
169
|
+
},
|
|
170
|
+
query: text,
|
|
171
|
+
type: "file",
|
|
172
|
+
limit: 200
|
|
173
|
+
}, {
|
|
174
|
+
signal: request.signal
|
|
175
|
+
});
|
|
176
|
+
if (active) setMatches(response.data);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (active && !request.signal.aborted) setSearchError(error instanceof Error ? error.message : String(error));
|
|
179
|
+
} finally {
|
|
180
|
+
if (active) setSearching(false);
|
|
181
|
+
}
|
|
182
|
+
}, 150);
|
|
183
|
+
onCleanup(() => {
|
|
184
|
+
active = false;
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
request.abort();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
createEffect(() => {
|
|
190
|
+
const list = rows();
|
|
191
|
+
const path = selected();
|
|
192
|
+
if (!list.some(row => row.path === path)) {
|
|
193
|
+
let parent = path;
|
|
194
|
+
while (parent.includes("/")) {
|
|
195
|
+
parent = parent.slice(0, parent.lastIndexOf("/"));
|
|
196
|
+
if (list.some(row => row.path === parent)) {
|
|
197
|
+
setSelected(parent);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
setSelected(list[0]?.path ?? "");
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
createEffect(() => {
|
|
205
|
+
const index = rows().findIndex(row => row.path === selected());
|
|
206
|
+
if (preview() || !treeScroll || index < 0) return;
|
|
207
|
+
const top = treeScroll.scrollTop;
|
|
208
|
+
const height = treeScroll.viewport.height;
|
|
209
|
+
if (index < top) treeScroll.scrollTo(index);else if (index >= top + height) treeScroll.scrollTo(index - height + 1);
|
|
210
|
+
});
|
|
211
|
+
context.keymap.layer(() => ({
|
|
212
|
+
enabled: () => props.panel.focused && !searchFocused(),
|
|
213
|
+
commands: [{
|
|
214
|
+
bind: "down,j",
|
|
215
|
+
run: () => move(1)
|
|
216
|
+
}, {
|
|
217
|
+
bind: "up,k",
|
|
218
|
+
run: () => move(-1)
|
|
219
|
+
}, {
|
|
220
|
+
bind: "pagedown,ctrl+f",
|
|
221
|
+
run: () => move(Math.max(1, (treeScroll?.viewport.height ?? 12) - 1))
|
|
222
|
+
}, {
|
|
223
|
+
bind: "pageup,ctrl+b",
|
|
224
|
+
run: () => move(-Math.max(1, (treeScroll?.viewport.height ?? 12) - 1))
|
|
225
|
+
}, {
|
|
226
|
+
bind: "home,g",
|
|
227
|
+
run: () => {
|
|
228
|
+
if (preview()) previewScroll?.scrollTo(0);else setSelected(rows()[0]?.path ?? "");
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
bind: "end,shift+g",
|
|
232
|
+
run: () => {
|
|
233
|
+
if (preview()) previewScroll?.scrollTo(previewScroll.scrollHeight);else setSelected(rows().at(-1)?.path ?? "");
|
|
234
|
+
}
|
|
235
|
+
}, {
|
|
236
|
+
bind: "return",
|
|
237
|
+
run: async () => {
|
|
238
|
+
if (!preview()) await open();
|
|
239
|
+
}
|
|
240
|
+
}, {
|
|
241
|
+
bind: "right,l",
|
|
242
|
+
run: async () => {
|
|
243
|
+
const row = current();
|
|
244
|
+
if (!preview() && row?.type === "directory" && !state().expanded.has(row.path)) await open(row);
|
|
245
|
+
}
|
|
246
|
+
}, {
|
|
247
|
+
bind: "left,h,backspace,b",
|
|
248
|
+
run: back
|
|
249
|
+
}, {
|
|
250
|
+
bind: ".",
|
|
251
|
+
run: () => {
|
|
252
|
+
setHidden(value => !value);
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
bind: "r",
|
|
256
|
+
run: refresh
|
|
257
|
+
}, {
|
|
258
|
+
bind: "/",
|
|
259
|
+
enabled: () => !preview(),
|
|
260
|
+
run: () => {
|
|
261
|
+
setSearchFocused(true);
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
id: "daoninc.file-explorer.add-to-prompt",
|
|
265
|
+
title: "Add file reference to prompt",
|
|
266
|
+
bind: "a",
|
|
267
|
+
enabled: () => Boolean(promptFile()),
|
|
268
|
+
run: addToPrompt
|
|
269
|
+
}, {
|
|
270
|
+
bind: "f",
|
|
271
|
+
run: () => props.panel.toggleFullscreen()
|
|
272
|
+
}, {
|
|
273
|
+
bind: "escape",
|
|
274
|
+
run: () => {
|
|
275
|
+
if (preview()) closePreview();else if (isSearch()) setQuery("");else props.panel.close();
|
|
276
|
+
}
|
|
277
|
+
}, {
|
|
278
|
+
bind: "q",
|
|
279
|
+
run: () => props.panel.close()
|
|
280
|
+
}]
|
|
281
|
+
}));
|
|
282
|
+
context.keymap.layer(() => ({
|
|
283
|
+
enabled: () => props.panel.focused && searchFocused() && !preview(),
|
|
284
|
+
priority: 2,
|
|
285
|
+
commands: [{
|
|
286
|
+
bind: "escape",
|
|
287
|
+
run: () => {
|
|
288
|
+
setQuery("");
|
|
289
|
+
setSearchFocused(false);
|
|
290
|
+
}
|
|
291
|
+
}, {
|
|
292
|
+
bind: "down,up,tab,return",
|
|
293
|
+
run: () => {
|
|
294
|
+
setSearchFocused(false);
|
|
295
|
+
}
|
|
296
|
+
}]
|
|
297
|
+
}));
|
|
298
|
+
const stop = context.data.listen(({
|
|
299
|
+
details
|
|
300
|
+
}) => {
|
|
301
|
+
if (details.location && details.location.directory !== directory()) return;
|
|
302
|
+
if (!["filesystem.changed", "session.execution.succeeded", "session.shell.ended", "shell.exited"].includes(details.type)) return;
|
|
303
|
+
clearTimeout(debounce);
|
|
304
|
+
debounce = setTimeout(refresh, 300);
|
|
305
|
+
});
|
|
306
|
+
const poll = setInterval(refresh, 10_000);
|
|
307
|
+
onCleanup(() => {
|
|
308
|
+
disposed = true;
|
|
309
|
+
tree.dispose();
|
|
310
|
+
readRequest?.abort();
|
|
311
|
+
stop();
|
|
312
|
+
clearTimeout(debounce);
|
|
313
|
+
clearInterval(poll);
|
|
314
|
+
});
|
|
315
|
+
return (() => {
|
|
316
|
+
var _el$ = _$createElement("box"),
|
|
317
|
+
_el$2 = _$createElement("box"),
|
|
318
|
+
_el$3 = _$createElement("text"),
|
|
319
|
+
_el$4 = _$createElement("b"),
|
|
320
|
+
_el$5 = _$createElement("text"),
|
|
321
|
+
_el$6 = _$createElement("text"),
|
|
322
|
+
_el$13 = _$createElement("text");
|
|
323
|
+
_$insertNode(_el$, _el$2);
|
|
324
|
+
_$insertNode(_el$, _el$6);
|
|
325
|
+
_$insertNode(_el$, _el$13);
|
|
326
|
+
_$setProp(_el$, "flexDirection", "column");
|
|
327
|
+
_$setProp(_el$, "flexGrow", 1);
|
|
328
|
+
_$setProp(_el$, "minHeight", 0);
|
|
329
|
+
_$setProp(_el$, "paddingLeft", 1);
|
|
330
|
+
_$setProp(_el$, "paddingRight", 1);
|
|
331
|
+
_$setProp(_el$, "onMouseDown", () => props.panel.focus());
|
|
332
|
+
_$insertNode(_el$2, _el$3);
|
|
333
|
+
_$insertNode(_el$2, _el$5);
|
|
334
|
+
_$setProp(_el$2, "flexDirection", "row");
|
|
335
|
+
_$setProp(_el$2, "justifyContent", "space-between");
|
|
336
|
+
_$setProp(_el$2, "flexShrink", 0);
|
|
337
|
+
_$insertNode(_el$3, _el$4);
|
|
338
|
+
_$insert(_el$4, () => preview() ? "File preview" : "Files");
|
|
339
|
+
_$insert(_el$5, (() => {
|
|
340
|
+
var _c$ = _$memo(() => !!isSearch());
|
|
341
|
+
return () => _c$() ? _$memo(() => !!searching())() ? "Searching…" : `${rows().length}${matches().length === 200 ? "+" : ""} results` : _$memo(() => !!state().loading.size)() ? "Loading…" : hidden() ? "incl. hidden" : "";
|
|
342
|
+
})());
|
|
343
|
+
_$setProp(_el$6, "flexShrink", 0);
|
|
344
|
+
_$setProp(_el$6, "wrapMode", "char");
|
|
345
|
+
_$insert(_el$6, () => context.ui.format.path(directory()));
|
|
346
|
+
_$insert(_el$, _$createComponent(Show, {
|
|
347
|
+
get when() {
|
|
348
|
+
return !preview();
|
|
349
|
+
},
|
|
350
|
+
get children() {
|
|
351
|
+
var _el$7 = _$createElement("box"),
|
|
352
|
+
_el$8 = _$createElement("input");
|
|
353
|
+
_$insertNode(_el$7, _el$8);
|
|
354
|
+
_$setProp(_el$7, "flexDirection", "row");
|
|
355
|
+
_$setProp(_el$7, "flexShrink", 0);
|
|
356
|
+
_$setProp(_el$7, "marginTop", 1);
|
|
357
|
+
_$setProp(_el$7, "gap", 1);
|
|
358
|
+
_$setProp(_el$8, "id", "file-explorer-search");
|
|
359
|
+
_$setProp(_el$8, "flexGrow", 1);
|
|
360
|
+
_$setProp(_el$8, "placeholder", "/ to search files…");
|
|
361
|
+
_$setProp(_el$8, "onInput", setQuery);
|
|
362
|
+
_$setProp(_el$8, "onMouseDown", () => {
|
|
363
|
+
props.panel.focus();
|
|
364
|
+
setSearchFocused(true);
|
|
365
|
+
});
|
|
366
|
+
_$effect(_p$ => {
|
|
367
|
+
var _v$ = query(),
|
|
368
|
+
_v$2 = props.panel.focused && searchFocused(),
|
|
369
|
+
_v$3 = context.theme.text.base,
|
|
370
|
+
_v$4 = context.theme.text.base,
|
|
371
|
+
_v$5 = context.theme.background.action.primary.hovered,
|
|
372
|
+
_v$6 = context.theme.background.action.primary.hovered;
|
|
373
|
+
_v$ !== _p$.e && (_p$.e = _$setProp(_el$8, "value", _v$, _p$.e));
|
|
374
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp(_el$8, "focused", _v$2, _p$.t));
|
|
375
|
+
_v$3 !== _p$.a && (_p$.a = _$setProp(_el$8, "textColor", _v$3, _p$.a));
|
|
376
|
+
_v$4 !== _p$.o && (_p$.o = _$setProp(_el$8, "focusedTextColor", _v$4, _p$.o));
|
|
377
|
+
_v$5 !== _p$.i && (_p$.i = _$setProp(_el$8, "backgroundColor", _v$5, _p$.i));
|
|
378
|
+
_v$6 !== _p$.n && (_p$.n = _$setProp(_el$8, "focusedBackgroundColor", _v$6, _p$.n));
|
|
379
|
+
return _p$;
|
|
380
|
+
}, {
|
|
381
|
+
e: undefined,
|
|
382
|
+
t: undefined,
|
|
383
|
+
a: undefined,
|
|
384
|
+
o: undefined,
|
|
385
|
+
i: undefined,
|
|
386
|
+
n: undefined
|
|
387
|
+
});
|
|
388
|
+
return _el$7;
|
|
389
|
+
}
|
|
390
|
+
}), _el$13);
|
|
391
|
+
_$insert(_el$, _$createComponent(Show, {
|
|
392
|
+
get when() {
|
|
393
|
+
return preview();
|
|
394
|
+
},
|
|
395
|
+
get fallback() {
|
|
396
|
+
return (() => {
|
|
397
|
+
var _el$14 = _$createElement("scrollbox");
|
|
398
|
+
var _ref$2 = treeScroll;
|
|
399
|
+
typeof _ref$2 === "function" ? _$use(_ref$2, _el$14) : treeScroll = _el$14;
|
|
400
|
+
_$setProp(_el$14, "flexGrow", 1);
|
|
401
|
+
_$setProp(_el$14, "minHeight", 0);
|
|
402
|
+
_$setProp(_el$14, "marginTop", 1);
|
|
403
|
+
_$insert(_el$14, _$createComponent(Show, {
|
|
404
|
+
get when() {
|
|
405
|
+
return _$memo(() => !!isSearch())() ? searchError() : state().errors[""];
|
|
406
|
+
},
|
|
407
|
+
get children() {
|
|
408
|
+
var _el$15 = _$createElement("text"),
|
|
409
|
+
_el$16 = _$createTextNode(` (r to retry)`);
|
|
410
|
+
_$insertNode(_el$15, _el$16);
|
|
411
|
+
_$insert(_el$15, (() => {
|
|
412
|
+
var _c$4 = _$memo(() => !!isSearch());
|
|
413
|
+
return () => _c$4() ? `Search failed: ${searchError()}` : `Cannot list folder: ${state().errors[""]}`;
|
|
414
|
+
})(), _el$16);
|
|
415
|
+
_$effect(_$p => _$setProp(_el$15, "fg", context.theme.text.muted, _$p));
|
|
416
|
+
return _el$15;
|
|
417
|
+
}
|
|
418
|
+
}), null);
|
|
419
|
+
_$insert(_el$14, _$createComponent(Show, {
|
|
420
|
+
get when() {
|
|
421
|
+
return _$memo(() => rows().length === 0)() && (isSearch() ? !searching() && !searchError() : !state().loading.has("") && !state().errors[""]);
|
|
422
|
+
},
|
|
423
|
+
get children() {
|
|
424
|
+
var _el$17 = _$createElement("text");
|
|
425
|
+
_$insert(_el$17, () => isSearch() ? "No matching files." : "No visible files. Press . to show hidden files.");
|
|
426
|
+
_$effect(_$p => _$setProp(_el$17, "fg", context.theme.text.muted, _$p));
|
|
427
|
+
return _el$17;
|
|
428
|
+
}
|
|
429
|
+
}), null);
|
|
430
|
+
_$insert(_el$14, _$createComponent(For, {
|
|
431
|
+
get each() {
|
|
432
|
+
return rows();
|
|
433
|
+
},
|
|
434
|
+
children: row => (() => {
|
|
435
|
+
var _el$18 = _$createElement("box"),
|
|
436
|
+
_el$19 = _$createElement("text"),
|
|
437
|
+
_el$20 = _$createElement("span");
|
|
438
|
+
_$insertNode(_el$18, _el$19);
|
|
439
|
+
_$setProp(_el$18, "height", 1);
|
|
440
|
+
_$setProp(_el$18, "flexShrink", 0);
|
|
441
|
+
_$setProp(_el$18, "onMouseUp", event => {
|
|
442
|
+
if (event.button !== 0 || context.renderer.getSelection()?.getSelectedText()) return;
|
|
443
|
+
event.stopPropagation();
|
|
444
|
+
props.panel.focus();
|
|
445
|
+
setSearchFocused(false);
|
|
446
|
+
setSelected(row.path);
|
|
447
|
+
void open(row);
|
|
448
|
+
});
|
|
449
|
+
_$insertNode(_el$19, _el$20);
|
|
450
|
+
_$setProp(_el$19, "wrapMode", "none");
|
|
451
|
+
_$insert(_el$19, () => " ".repeat(row.depth), _el$20);
|
|
452
|
+
_$insert(_el$20, (() => {
|
|
453
|
+
var _c$5 = _$memo(() => row.type === "directory");
|
|
454
|
+
return () => _c$5() ? _$memo(() => !!state().loading.has(row.path))() ? "◌ " : state().expanded.has(row.path) ? "▾ " : "▸ " : " ";
|
|
455
|
+
})());
|
|
456
|
+
_$insert(_el$19, _$createComponent(Show, {
|
|
457
|
+
get when() {
|
|
458
|
+
return selected() === row.path;
|
|
459
|
+
},
|
|
460
|
+
get fallback() {
|
|
461
|
+
return row.name;
|
|
462
|
+
},
|
|
463
|
+
get children() {
|
|
464
|
+
var _el$21 = _$createElement("b");
|
|
465
|
+
_$insert(_el$21, () => row.name);
|
|
466
|
+
return _el$21;
|
|
467
|
+
}
|
|
468
|
+
}), null);
|
|
469
|
+
_$insert(_el$19, () => row.type === "directory" ? "/" : "", null);
|
|
470
|
+
_$insert(_el$19, () => state().errors[row.path] ? " [unreadable; collapse/reopen to retry]" : "", null);
|
|
471
|
+
_$effect(_p$ => {
|
|
472
|
+
var _v$11 = selected() === row.path ? context.theme.background.action.primary.selected : undefined,
|
|
473
|
+
_v$12 = selected() === row.path ? context.theme.text.action.primary.selected : context.theme.text.base,
|
|
474
|
+
_v$13 = {
|
|
475
|
+
fg: context.theme.text.muted
|
|
476
|
+
};
|
|
477
|
+
_v$11 !== _p$.e && (_p$.e = _$setProp(_el$18, "backgroundColor", _v$11, _p$.e));
|
|
478
|
+
_v$12 !== _p$.t && (_p$.t = _$setProp(_el$19, "fg", _v$12, _p$.t));
|
|
479
|
+
_v$13 !== _p$.a && (_p$.a = _$setProp(_el$20, "style", _v$13, _p$.a));
|
|
480
|
+
return _p$;
|
|
481
|
+
}, {
|
|
482
|
+
e: undefined,
|
|
483
|
+
t: undefined,
|
|
484
|
+
a: undefined
|
|
485
|
+
});
|
|
486
|
+
return _el$18;
|
|
487
|
+
})()
|
|
488
|
+
}), null);
|
|
489
|
+
return _el$14;
|
|
490
|
+
})();
|
|
491
|
+
},
|
|
492
|
+
get children() {
|
|
493
|
+
return [(() => {
|
|
494
|
+
var _el$9 = _$createElement("text");
|
|
495
|
+
_$setProp(_el$9, "flexShrink", 0);
|
|
496
|
+
_$setProp(_el$9, "wrapMode", "char");
|
|
497
|
+
_$insert(_el$9, preview);
|
|
498
|
+
_$effect(_$p => _$setProp(_el$9, "fg", context.theme.text.muted, _$p));
|
|
499
|
+
return _el$9;
|
|
500
|
+
})(), (() => {
|
|
501
|
+
var _el$0 = _$createElement("scrollbox"),
|
|
502
|
+
_el$1 = _$createElement("text");
|
|
503
|
+
_$insertNode(_el$0, _el$1);
|
|
504
|
+
var _ref$ = previewScroll;
|
|
505
|
+
typeof _ref$ === "function" ? _$use(_ref$, _el$0) : previewScroll = _el$0;
|
|
506
|
+
_$setProp(_el$0, "flexGrow", 1);
|
|
507
|
+
_$setProp(_el$0, "minHeight", 0);
|
|
508
|
+
_$setProp(_el$0, "marginTop", 1);
|
|
509
|
+
_$setProp(_el$1, "wrapMode", "word");
|
|
510
|
+
_$insert(_el$1, (() => {
|
|
511
|
+
var _c$2 = _$memo(() => !!reading());
|
|
512
|
+
return () => _c$2() ? "Reading…" : content();
|
|
513
|
+
})());
|
|
514
|
+
_$effect(_$p => _$setProp(_el$1, "fg", context.theme.text.base, _$p));
|
|
515
|
+
return _el$0;
|
|
516
|
+
})()];
|
|
517
|
+
}
|
|
518
|
+
}), _el$13);
|
|
519
|
+
_$insert(_el$, _$createComponent(Show, {
|
|
520
|
+
get when() {
|
|
521
|
+
return promptFile();
|
|
522
|
+
},
|
|
523
|
+
get children() {
|
|
524
|
+
var _el$10 = _$createElement("box"),
|
|
525
|
+
_el$11 = _$createElement("text");
|
|
526
|
+
_$insertNode(_el$10, _el$11);
|
|
527
|
+
_$setProp(_el$10, "flexShrink", 0);
|
|
528
|
+
_$setProp(_el$10, "marginTop", 1);
|
|
529
|
+
_$setProp(_el$10, "onMouseUp", event => {
|
|
530
|
+
if (event.button !== 0 || context.renderer.getSelection()?.getSelectedText()) return;
|
|
531
|
+
event.stopPropagation();
|
|
532
|
+
void addToPrompt();
|
|
533
|
+
});
|
|
534
|
+
_$insertNode(_el$11, _$createTextNode(`[a] Add to prompt`));
|
|
535
|
+
_$effect(_p$ => {
|
|
536
|
+
var _v$7 = context.theme.background.action.primary.hovered,
|
|
537
|
+
_v$8 = context.theme.text.base;
|
|
538
|
+
_v$7 !== _p$.e && (_p$.e = _$setProp(_el$10, "backgroundColor", _v$7, _p$.e));
|
|
539
|
+
_v$8 !== _p$.t && (_p$.t = _$setProp(_el$11, "fg", _v$8, _p$.t));
|
|
540
|
+
return _p$;
|
|
541
|
+
}, {
|
|
542
|
+
e: undefined,
|
|
543
|
+
t: undefined
|
|
544
|
+
});
|
|
545
|
+
return _el$10;
|
|
546
|
+
}
|
|
547
|
+
}), _el$13);
|
|
548
|
+
_$setProp(_el$13, "flexShrink", 0);
|
|
549
|
+
_$setProp(_el$13, "marginTop", 1);
|
|
550
|
+
_$setProp(_el$13, "wrapMode", "word");
|
|
551
|
+
_$insert(_el$13, (() => {
|
|
552
|
+
var _c$3 = _$memo(() => !!preview());
|
|
553
|
+
return () => _c$3() ? "↑↓ scroll · a add to prompt · b back · f fullscreen · q close" : searchFocused() ? "↓ results · Esc clear search" : "/ search · ← collapse · . hidden · f fullscreen · q close";
|
|
554
|
+
})());
|
|
555
|
+
_$effect(_p$ => {
|
|
556
|
+
var _v$9 = context.theme.text.base,
|
|
557
|
+
_v$0 = context.theme.text.muted,
|
|
558
|
+
_v$1 = context.theme.text.muted,
|
|
559
|
+
_v$10 = context.theme.text.muted;
|
|
560
|
+
_v$9 !== _p$.e && (_p$.e = _$setProp(_el$3, "fg", _v$9, _p$.e));
|
|
561
|
+
_v$0 !== _p$.t && (_p$.t = _$setProp(_el$5, "fg", _v$0, _p$.t));
|
|
562
|
+
_v$1 !== _p$.a && (_p$.a = _$setProp(_el$6, "fg", _v$1, _p$.a));
|
|
563
|
+
_v$10 !== _p$.o && (_p$.o = _$setProp(_el$13, "fg", _v$10, _p$.o));
|
|
564
|
+
return _p$;
|
|
565
|
+
}, {
|
|
566
|
+
e: undefined,
|
|
567
|
+
t: undefined,
|
|
568
|
+
a: undefined,
|
|
569
|
+
o: undefined
|
|
570
|
+
});
|
|
571
|
+
return _el$;
|
|
572
|
+
})();
|
|
573
|
+
}
|
|
574
|
+
export default Plugin.define({
|
|
575
|
+
id: "daoninc.file-explorer",
|
|
576
|
+
setup(context) {
|
|
577
|
+
const [request, setRequest] = createSignal();
|
|
578
|
+
const activeSessionID = () => {
|
|
579
|
+
const route = context.ui.router.current();
|
|
580
|
+
return route.type === "session" ? route.sessionID : undefined;
|
|
581
|
+
};
|
|
582
|
+
const promptFocus = trackPromptFocus(context.renderer, () => activeSessionID() ?? "", activeSessionID, () => !context.ui.panel.current());
|
|
583
|
+
const unregister = context.ui.slot({
|
|
584
|
+
append: "session.panel",
|
|
585
|
+
render: panel => _$createComponent(Show, {
|
|
586
|
+
get when() {
|
|
587
|
+
return panel.name === PANEL;
|
|
588
|
+
},
|
|
589
|
+
get children() {
|
|
590
|
+
return _$createComponent(Explorer, {
|
|
591
|
+
panel: panel,
|
|
592
|
+
get request() {
|
|
593
|
+
return request();
|
|
594
|
+
},
|
|
595
|
+
focusPrompt: () => promptFocus.focus()
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
})
|
|
599
|
+
});
|
|
600
|
+
context.keymap.layer(() => ({
|
|
601
|
+
mode: "global",
|
|
602
|
+
commands: [{
|
|
603
|
+
id: "daoninc.file-explorer.open",
|
|
604
|
+
title: "Open file explorer",
|
|
605
|
+
group: "Files",
|
|
606
|
+
palette: true,
|
|
607
|
+
slash: {
|
|
608
|
+
name: "files"
|
|
609
|
+
},
|
|
610
|
+
run: () => {
|
|
611
|
+
setRequest(undefined);
|
|
612
|
+
if (!context.ui.panel.open(PANEL)) context.ui.toast.show({
|
|
613
|
+
message: "Open a session first to browse its files.",
|
|
614
|
+
variant: "info"
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}, {
|
|
618
|
+
id: "daoninc.file-explorer.preview",
|
|
619
|
+
title: "Preview a file from the sidebar",
|
|
620
|
+
run: path => {
|
|
621
|
+
const sessionID = activeSessionID();
|
|
622
|
+
if (!sessionID) return;
|
|
623
|
+
const directory = (context.data.session.get(sessionID)?.location ?? context.location ?? context.data.location.default()).directory;
|
|
624
|
+
try {
|
|
625
|
+
setRequest(createPreviewRequest(path, sessionID, directory));
|
|
626
|
+
if (!context.ui.panel.open(PANEL)) {
|
|
627
|
+
setRequest(undefined);
|
|
628
|
+
context.ui.toast.show({
|
|
629
|
+
message: "Open a session first to preview its files.",
|
|
630
|
+
variant: "info"
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
} catch (error) {
|
|
634
|
+
context.ui.toast.show({
|
|
635
|
+
message: error instanceof Error ? error.message : String(error),
|
|
636
|
+
variant: "error"
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}]
|
|
641
|
+
}));
|
|
642
|
+
return () => {
|
|
643
|
+
unregister();
|
|
644
|
+
promptFocus.dispose();
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
});
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daoninc/opencode-file-explorer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Searchable read-only file explorer and preview panel for OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"exports": {
|
|
8
|
-
"./tui": "./tui.
|
|
9
|
-
"./model": "./model.ts",
|
|
10
|
-
"./prompt": "./prompt.ts",
|
|
11
|
-
"./prompt-focus": "./prompt-focus.ts"
|
|
8
|
+
"./tui": "./dist/tui.js",
|
|
9
|
+
"./model": { "types": "./dist/model.d.ts", "default": "./dist/model.js" },
|
|
10
|
+
"./prompt": { "types": "./dist/prompt.d.ts", "default": "./dist/prompt.js" },
|
|
11
|
+
"./prompt-focus": { "types": "./dist/prompt-focus.d.ts", "default": "./dist/prompt-focus.js" }
|
|
12
12
|
},
|
|
13
|
-
"files": ["
|
|
14
|
-
"scripts": { "test": "bun test", "prepublishOnly": "bun run ../../scripts/check-release.ts ." },
|
|
13
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
14
|
+
"scripts": { "test": "bun test", "prepack": "bun run ../../scripts/build.ts .", "prepublishOnly": "bun run ../../scripts/build.ts . && bun run ../../scripts/check-release.ts ." },
|
|
15
15
|
"dependencies": { "@opencode/plugin": "^2.3.1" },
|
|
16
16
|
"peerDependencies": { "@opentui/core": ">=0.8.4 <0.9", "@opentui/solid": ">=0.8.4 <0.9", "solid-js": "^1.9.0" },
|
|
17
17
|
"publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
|