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 command to start the demo server. It will render your component changes, populated with fake example data.All Sketch web components have been successfully migrated to the modern SketchTailwindElement architecture:
SketchTailwindElementLitElement directlyAll components now follow the modern architecture patterns described above. The migration from legacy LitElement patterns is complete.
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.