Official
sidebar
Built-in sidebar 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/sidebar@0.2.4
Permissions in 0.2.4
Files
search-field.test.ts2 KB
// The sidebar's search field heads the rows under it: an outlined field
// with a search icon, its outline level with the top of the chat pane
// beside it.
import assert from "node:assert/strict";
import { test } from "node:test";
import type { EffectViewContext } from "divergence/effect";
import type { Sidebar } from "./controller.ts";
import { initialState } from "./sections.ts";
import { renderSidebar } from "./views.tsx";
type Node = Record<string, unknown> & { type?: string; id?: string; children?: Node[] };
function sidebarTree() {
const state = initialState();
state.loaded = true;
const ctx = { app: { route: "chat" }, state: {}, plugin: "sidebar", update() {}, run() {} } as unknown as EffectViewContext<{ cmd?: boolean }>;
return { state, tree: renderSidebar(ctx, { state } as unknown as Sidebar["Service"]) as unknown as Node };
}
// The chain of nodes from the root down to the one with `id`.
function pathTo(node: Node, id: string): Node[] | null {
if (node.id === id) return [node];
for (const child of node.children ?? []) {
const path = child && typeof child === "object" ? pathTo(child, id) : null;
if (path) return [node, ...path];
}
return null;
}
test("the search field is an outlined field whose outline starts level with the top of the chat pane", () => {
const { state, tree } = sidebarTree();
const path = pathTo(tree, "chat-search");
assert.ok(path, "the sidebar draws the search field");
const [sidebar, top, input] = path.slice(-3);
assert.equal(input!.ghost, undefined, "the field keeps its outline");
assert.equal(input!.icon, "search");
assert.equal(input!.placeholder, "Search chats...");
assert.equal(sidebar!.id, "sidebar");
assert.equal(sidebar!.paddingTop, 0);
// The kernel draws the outline half a point outside the field's box, so
// the box starts half a point down and the outline at the very top.
assert.equal(top!.paddingTop, 0.5);
(input!.onChange as (event: { value: string }) => void)({ value: "plan" });
assert.equal(state.query, "plan", "typing narrows the list");
});
No comments yet.