blob: 823adecd42631a51dd432308051a8d6533203b4e [file] [log] [blame] [view]
Sean McCullough848572d2025-05-13 22:27:42 +00001# Component Architecture: sketch-tool-card and Related Components
2
3This document explains the relationship between LitElement subclasses in webui/src/web-components/ and the sketch-tool-card custom element, focusing on their containment relationship and CSS styling effects.
4
5## Containment Relationship
6
7The component hierarchy and containment relationship is structured as follows:
8
91. **sketch-app-shell** (the main application container)
10 - Contains **sketch-timeline** (for displaying conversation history)
11 - Contains **sketch-timeline-message** (for individual messages)
12 - Contains **sketch-tool-calls** (collection of tool calls)
13 - Contains specific tool card components like:
14 - **sketch-tool-card-bash**
15 - **sketch-tool-card-think**
16 - **sketch-tool-card-codereview**
17 - **sketch-tool-card-done**
18 - **sketch-tool-card-patch**
19 - **sketch-tool-card-take-screenshot**
Josh Bleecher Snyder19969a92025-06-05 14:34:02 -070020 - **sketch-tool-card-set-slug**
21 - **sketch-tool-card-commit-message-style**
Sean McCullough848572d2025-05-13 22:27:42 +000022 - **sketch-tool-card-multiple-choice**
23 - **sketch-tool-card-generic** (fallback for unknown tools)
24 - All of these specialized components **contain** or **compose with** the base **sketch-tool-card**
25
26The key aspect is that the specialized tool card components do not inherit from `SketchToolCard` in a class hierarchy sense. Instead, they **use composition** by embedding a `<sketch-tool-card>` element within their render method and passing data to it.
27
28For example, from `sketch-tool-card-bash.ts`:
29
30```typescript
31render() {
32 return html` <sketch-tool-card
33 .open=${this.open}
34 .toolCall=${this.toolCall}
35 >
36 <span slot="summary" class="summary-text">...</span>
37 <div slot="input" class="input">...</div>
38 <div slot="result" class="result">...</div>
39 </sketch-tool-card>`;
40}
41```
42
43## CSS Styling and Effects
44
45Regarding how CSS rules defined in sketch-tool-card affect elements that contain it:
46
471. **Shadow DOM Encapsulation**:
Sean McCullough848572d2025-05-13 22:27:42 +000048 - Each Web Component has its own Shadow DOM, which encapsulates its styles
49 - Styles defined in `sketch-tool-card` apply only within its shadow DOM, not to parent components
50
512. **Slot Content Styling**:
Sean McCullough848572d2025-05-13 22:27:42 +000052 - The base `sketch-tool-card` defines three slots: "summary", "input", and "result"
53 - Specialized tool cards provide content for these slots
54 - The base component can style the slot containers, but cannot directly style the slotted content
55
563. **Style Inheritance and Sharing**:
Sean McCullough848572d2025-05-13 22:27:42 +000057 - The code uses a `commonStyles` constant that is shared across some components
58 - These common styles ensure consistent styling for elements like pre, code blocks
59 - Each specialized component adds its own unique styles as needed
60
614. **Parent CSS Targeting**:
Sean McCullough848572d2025-05-13 22:27:42 +000062 - In `sketch-timeline-message.ts`, there are styles that target the tool components using the `::slotted()` pseudo-element:
63
64 ```css
65 ::slotted(sketch-tool-calls) {
66 max-width: 100%;
67 width: 100%;
68 overflow-wrap: break-word;
69 word-break: break-word;
70 }
71 ```
Philip Zeyligerb01b1502025-06-26 21:20:12 -070072
Sean McCullough848572d2025-05-13 22:27:42 +000073 - This allows parent components to influence the layout of slotted components while preserving Shadow DOM encapsulation
74
755. **Host Element Styling**:
76 - The `:host` selector is used in sketch-tool-card for styling the component itself:
banksean9aa141a2025-06-27 05:02:24 +000077
Sean McCullough848572d2025-05-13 22:27:42 +000078 ```css
79 :host {
80 display: block;
81 max-width: 100%;
82 width: 100%;
83 box-sizing: border-box;
84 overflow: hidden;
85 }
86 ```
Philip Zeyligerb01b1502025-06-26 21:20:12 -070087
Sean McCullough848572d2025-05-13 22:27:42 +000088 - This affects how the component is displayed in its parent context
89
90In summary, the architecture uses composition rather than inheritance, with specialized tool cards wrapping the base sketch-tool-card component and filling its slots with custom content. The CSS styling is carefully managed through Shadow DOM, with some targeted styling using ::slotted selectors to ensure proper layout and appearance throughout the component hierarchy.
Philip Zeyliger33219392025-05-14 20:43:24 -070091
92# API URLs Must Be Relative
93
94When 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:
95
96```javascript
97// CORRECT - use relative paths without leading slash
98const response = await fetch(`git/rawdiff?commit=${commit}`);
99const data = await fetch(`git/show?hash=${hash}`);
100
101// INCORRECT - do not use absolute paths with leading slash
102const response = await fetch(`/git/rawdiff?commit=${commit}`); // WRONG!
103const data = await fetch(`/git/show?hash=${hash}`); // WRONG!
104```
105
106The reason for this requirement is that Sketch may be deployed:
107
1081. At the root path of a domain
1092. In a subdirectory
1103. Behind a proxy with a path prefix
1114. In different environments (dev, production)
112
113Using 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.