Skip to content

Commit 2512f4c

Browse files
authored
Add documentation for ct-cell-context usage (commontoolsinc#2184)
1 parent 5a37790 commit 2512f4c

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

docs/common/CELL_CONTEXT.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
`<ct-cell-context>` designates a region of the page as pertaining to a particular cell. This creates a tree of cells annotating the entire interaction—like an accessibility tree, but for data. Currently used for debugging and inspection; future features will build on this structure.
2+
3+
# Automatic Injection
4+
5+
Every `[UI]` render is automatically wrapped in `ct-cell-context`. You get top-level charm debugging for free without any code changes.
6+
7+
# When to Use Manually
8+
9+
Add `ct-cell-context` sparingly—typically 1-2 per pattern at most. Use it for values that are:
10+
11+
- Important but otherwise difficult to access
12+
- Intermediate calculations or API responses
13+
- Values you'd otherwise debug with `console.log`
14+
15+
This is better than adding a `derive` with `console.log` because inspection is conditional—users can watch and unwatch values on demand rather than flooding the console.
16+
17+
```tsx
18+
<ct-cell-context $cell={result} label="Calculation Result">
19+
<div>{result.value}</div>
20+
</ct-cell-context>
21+
```
22+
23+
# API
24+
25+
- `$cell` - The Cell to associate with this region
26+
- `label` - Human-readable name shown in the toolbar (optional)
27+
- `inline` - Display as inline-block instead of block (optional)
28+
29+
# Debugging
30+
31+
Hold **Alt** and hover over a cell context region to see the debugging toolbar:
32+
33+
- **val** - Log the cell value to console and set `globalThis.$cell` to the cell, making it accessible via the console for inspection (similar to Chrome's `$0` for elements)
34+
- **id** - Log the cell's full address
35+
- **watch/unwatch** - Subscribe to value changes; updates appear in the debugger's Watch List
36+
37+
# When NOT to Use
38+
39+
- Don't wrap every cell—reserve for important values
40+
- Don't use for trivial or obviously-accessible values
41+
- If a value is already easy to inspect via the UI, you probably don't need this

packages/ui/src/v2/components/ct-cell-context/ct-cell-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class CTCellContext extends BaseElement {
3131
}
3232
3333
:host([inline]) {
34-
display: inline;
34+
display: inline-block;
3535
}
3636
3737
.container {

0 commit comments

Comments
 (0)