Commit de6c5e1
authored
Toggle DatoCMS block labels on preview mode (#309)
# Changes
Adds visual block labels in preview mode that allow users to quickly
identify and edit blocks in DatoCMS.
<img width="1125" height="839" alt="SCR-20260205-knbe"
src="https://github.com/user-attachments/assets/cddd827d-8f1c-490f-9706-3c735dfb09a2"
/>
## What changed
- **Block labels**: Block names appear as overlays in preview mode
(toggleable via "show blocks" button)
- **Clickable labels**: Clicking a block label opens the block's focus
field in DatoCMS editor
- **Field path detection**: Automatically detects the primary editable
field for each block type
- **Nested block support**: Correctly handles nested blocks (e.g.,
blocks inside GroupingBlock items)
## Technical details
- Added `block-debug-utils.ts` for field path building and API key
conversion
- Enhanced `download-item-types.ts` to detect focus fields (rich text,
media, JSON, links, etc.)
- Updated `Blocks.astro` to render debug labels with correct field paths
- Updated `PreviewMode.client.ts` to handle label positioning, hover
effects, and edit link generation
- Added `hideDebugLabels` prop to skip labels in specific contexts
(PagePartialBlock, TextBlock inline blocks)
## Usage
Block labels appear automatically in preview mode when:
1. Preview mode is active
2. `PreviewModeSubscription` receives a `record` prop
3. "show blocks" button is toggled on
Labels are hidden for:
- PagePartialBlock children (wrong record context)
- TextBlock inline blocks (embedded in rich text)
## Documentation
Updated `docs/preview-mode.md`
https://github.com/voorhoede/head-start/blob/feat/show-blocks/docs/preview-mode.md#block-field-path-detection
# How to test
- Click "show blocks" button in preview bar
- Verify block labels appear as overlays
- Hover over blocks to see highlight effect
- Click a block label to verify it opens the correct field in DatoCMS
- Test nested blocks (e.g., blocks inside GroupingBlock)
- Verify labels are hidden for PagePartialBlock children and TextBlock
inline blocks
Test in other head-start based projects:
<img width="1825" height="1216" alt="Screenshot 2026-02-05 at 11 38 35"
src="https://github.com/user-attachments/assets/298589c1-3852-4bcb-8e71-3d669aa96838"
/>
# Checklist
- [x] I have performed a self-review of my own code
- [x] I have made sure that my PR is easy to review (not too big,
includes comments)
- [x] I have made updated relevant documentation files (in project
README, docs/, etc)
- ~~ I have added a decision log entry if the change affects the
architecture or changes a significant technology~~
- [x] I have notified a reviewer
<!-- Please strike through and check off all items that do not apply
(rather than removing them) -->1 parent aa18c42 commit de6c5e1
13 files changed
Lines changed: 646 additions & 123 deletions
File tree
- config
- docs
- scripts
- src
- blocks
- GroupingBlock
- PagePartialBlock
- TableBlock
- TextBlock/nodes
- components/PreviewMode
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| |||
0 commit comments