Imported from josephbergevin/codebook-md (
src/webview/AGENTS.md). Install upstream withnpx skills add josephbergevin/codebook-md --skill webview. Copyright stays with the author.
AGENTS.md — src/webview/
Sidebar and modal UI. See webviews.md for detail and add-webview-view for the procedure.
Files
| File | View id | Template |
|---|---|---|
welcomeView.ts |
codebook-md-welcome-view |
templates/welcome.html |
notebooksView.ts |
codebook-md-notebooks-view |
templates/notebooks.html |
documentationView.ts |
codebook-md-documentation-view |
templates/documentation.html |
configModal.ts |
— (modal panel) | generated inline |
All three views live in the codebook-md-activitybar container declared in
package.json contributes.views.
The two-file pattern
- Provider —
<name>View.ts, implementingWebviewViewProviderandDisposable. Takes theExtensionContext, implementsresolveWebviewView(), reads its template, and handles messages. - Template —
templates/<name>.html, self-contained HTML + CSS + JS.
documentationView.ts is the smallest complete example. configModal.ts is the
exception to the pattern — it generates markup inline and is ~110k, so prefer
the template approach for anything new.
Rules for this directory
- Templates are read from
dist/templates/, notsrc/.webpack.config.jscopiessrc/webview/templates/*.htmltodist/templates/[name][ext]. Any new.htmlfile there is picked up automatically. - The provider
idinpackage.jsonmust matchstatic readonly viewTypeexactly. - Implement
dispose()and drain a_disposablesarray; push the provider itself ontocontext.subscriptions. - Use VS Code CSS theme variables —
var(--vscode-foreground),var(--vscode-editor-background),var(--vscode-button-background). Never hard-code colors; views must work in light, dark, and high-contrast themes. - Validate every inbound message. Dispatch on an explicit
message.commandfield and check the payload before acting. - Escape user-supplied content interpolated into HTML. Folder and file
display names come from
.vscode/codebook-md.json. groupIndexfrom the webview is 1-based. Convert to 0-based before indexing arrays.- Call
refreshNotebooksView()after any structural change to folders or files.
Documentation view
templates/documentation.html is the in-extension user documentation and has
its own index near the top. When adding a user-facing feature, add both the
section and its index entry — a section missing from the index is effectively
invisible.