Official
files
Built-in files UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/files@0.2.3
Permissions in 0.2.3
Files
views.ts3 KB
// Files rail and panel trees. Rendering only reads state; handlers run effects.
// HTM whitespace is significant; keep these templates out of Prettier's HTML formatter.
import { html as htm } from "divergence";
import type { EffectViewContext } from "divergence/effect";
import type { Files } from "./controller.ts";
import { isOpen, isPending, selectedPath, treeItems } from "./panel.ts";
// Layout for the templates below: a flex column, a row that centres its
// children across (the old `ui.row`), and a child that takes the free
// space and may shrink below its content.
const column = { display: "flex", flexDirection: "column" };
const row = { display: "flex", flexDirection: "row", alignItems: "center" };
const fill = { flexGrow: 1, flexShrink: 1, flexBasis: "0%", minWidth: 0, minHeight: 0 };
const full = { width: "100%", height: "100%" };
export function renderRail(ctx: EffectViewContext<object>, actions: Files["Service"]) {
return htm`
<button id="rail-files" icon="files" variant="ghost" active=${ctx.app.shared?.rightPanel === "files"} tooltip="Files"
onClick=${() => ctx.run(actions.toggle(ctx.app))} />`;
}
export function renderPanel(ctx: EffectViewContext<object>, actions: Files["Service"]) {
const { state } = actions;
if (!isOpen(ctx.app)) return null;
const workspaceId = ctx.app.workspaceId;
if (!workspaceId) {
return htm`<div ...${column} gap="small" padding="medium"><text style="muted">Select a workspace to browse files.</text></div>`;
}
const flat = state.query.trim() ? state.results : state.all;
const source = flat ? { files: flat.map((path) => ({ path })) } : { items: treeItems(state.listing) };
// One 0.5rem inset and one gap: the title, the field's mark and the
// tree's icons start on the same line, and the close button ends where
// the field does.
return htm`
<div ...${column} ...${fill} ...${full} padding="medium" gap="small">
<div ...${row} gap="small">
<div ...${row} ...${fill} paddingX=${9}>
<text style="body" size=${13.125} weight=${600} truncate>Files</text>
</div>
<button id="files-refresh" icon="rotate-cw" variant="ghost" small tooltip="Refresh" onClick=${() => ctx.run(actions.refresh(workspaceId))} />
<button id="files-close" icon="x" variant="ghost" small tooltip="Close" onClick=${() => ctx.run(actions.close)} />
</div>
<input id="files-search" value=${state.query} placeholder="Search files..." icon="search"
onChange=${(e: { value: string }) => {
state.query = e.value;
ctx.update();
ctx.run(actions.search(workspaceId, e.value));
}} />
<div ...${column} ...${fill}>
<tree id=${`files-${workspaceId}`}
...${source}
selected=${selectedPath(state.activePath)}
onSelect=${(e: { id: string; folder: boolean }) => {
if (e.folder) ctx.run(actions.expand(workspaceId, e.id));
else if (!isPending(e.id)) ctx.run(actions.openFile(workspaceId, e.id));
}} />
</div>
</div>`;
}
No comments yet.