IMPORTANT: New component architecture standards for all Sketch web components
All new Sketch web components should:
SketchTailwindElement instead of LitElementimport { html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { SketchTailwindElement } from "./sketch-tailwind-element"; import "./sketch-tool-card-base"; @customElement("sketch-tool-card-example") export class SketchToolCardExample extends SketchTailwindElement { @property() toolCall: ToolCall; @property() open: boolean; render() { const summaryContent = html`<span class="font-mono text-sm text-gray-700"> ${this.toolCall?.name} </span>`; const inputContent = html`<div class="p-2 bg-gray-100 rounded"> <pre class="whitespace-pre-wrap break-words">${this.toolCall?.input}</pre> </div>`; return html`<sketch-tool-card-base .open=${this.open} .toolCall=${this.toolCall} .summaryContent=${summaryContent} .inputContent=${inputContent} ></sketch-tool-card-base>`; } }
font-mono text-sm text-gray-700 (not CSS-in-JS).summaryContent=${html\...`}`)cd ./sketch/webuinpm installrm -rf node_modules package-lock.json npm install
npm run demo:runner command to start the demo server. It will render your component changes, populated with fake example data.Some existing components still use the old architecture and will be migrated:
LitElement directlystatic styles = css\...``<slot name="summary"></slot>)Do not use these legacy patterns for new components. They are being phased out.
When making fetch requests to backend APIs in Sketch, all URLs must be relative without leading slashes. The base URL for Sketch varies depending on how it is deployed and run:
// CORRECT - use relative paths without leading slash const response = await fetch(`git/rawdiff?commit=${commit}`); const data = await fetch(`git/show?hash=${hash}`); // INCORRECT - do not use absolute paths with leading slash const response = await fetch(`/git/rawdiff?commit=${commit}`); // WRONG! const data = await fetch(`/git/show?hash=${hash}`); // WRONG!
The reason for this requirement is that Sketch may be deployed:
Using relative paths ensures that requests are correctly routed regardless of the deployment configuration. The browser will resolve the URLs relative to the current page location.