Skip to content

Commit 96ed9b0

Browse files
committed
Gutenberg editor capture: no admin seam, sticky boxes unscrolled, pending blocks awaited (from c6928b1)
1 parent 4610f3c commit 96ed9b0

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

‎skills/html2wp/assets/scripts/block-schema.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"schema": "h2wp-block-schema/1",
3-
"generator": "0.2.2",
3+
"generator": "0.2.3",
44
"compiler": "gutenberg/2",
55
"nodeFields": [
66
"name",

‎skills/html2wp/assets/scripts/gutenberg-editor-visual.py‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"""Capture the real editor canvas, keeping CSS viewport units and responsive width.
33
44
Overlapping scroll captures retain native layout. Only already captured upper
5-
pixels (including repeated sticky overlays) are omitted from subsequent tiles;
6-
no content nodes/styles are hidden or replaced with frontend markup.
5+
pixels are omitted from subsequent tiles; sticky boxes are laid out where they
6+
stand unscrolled on both sides, as a full-page screenshot lays them out; no
7+
content nodes/styles are hidden or replaced with frontend markup.
78
"""
89
import io
910
import json, re
@@ -47,10 +48,20 @@ def ready(frame):
4748
for(let y=0;y<document.documentElement.scrollHeight;y+=700){scrollTo(0,y);await new Promise(r=>setTimeout(r,80));}
4849
scrollTo(0,0);
4950
await new Promise(r=>setTimeout(r,400));
51+
// A block still asking the server what to draw (an article's prev/next
52+
// side waiting for its post) marks itself data-h2wp-pending.
53+
for(let i=0;i<100&&document.querySelector('[data-h2wp-pending]');i++)await new Promise(r=>setTimeout(r,100));
5054
await document.fonts.ready;
5155
await Promise.all([...document.images].map(i=>i.decode().catch(()=>{})));
5256
}''')
5357
frame.add_style_tag(content='*,*::before,*::after{animation:none!important;transition:none!important;caret-color:transparent!important}')
58+
# A sticky box sticks to the viewport as the tiles scroll, and a region
59+
# sits at another height in the canvas than on the page (a page's content
60+
# has no header above it in its editor): stuck at another place on each
61+
# side (claire's sticky case-study photos). Both sides lay it out where it
62+
# stands unscrolled, as the frontend gate's full-page screenshot does.
63+
frame.evaluate('''()=>{for(const e of document.querySelectorAll('*')){if(getComputedStyle(e).position!=='sticky')continue;
64+
e.style.setProperty('position','relative','important');for(const side of ['top','right','bottom','left'])e.style.setProperty(side,'auto','important');}}''')
5465

5566

5667
def canvas_image(page, frame, selector, iframe=False, children=False):
@@ -129,7 +140,12 @@ def size_frame(page,width):
129140
frame.locator(ROOT).wait_for(state='attached',timeout=60000)
130141
page.wait_for_timeout(250)
131142
actual=frame.evaluate('({width:innerWidth,height:innerHeight})')
132-
if actual=={'width':width,'height':900}: return frame
143+
if actual=={'width':width,'height':900}:
144+
# Every row of the canvas viewport must reach the screenshot.
145+
clip=element.evaluate(CLIP)
146+
if clip['visibleTop']>clip['top']+.5 or clip['visibleBottom']<clip['bottom']-.5:
147+
raise RuntimeError(f'Editor canvas is clipped by the administration layout: {clip}')
148+
return frame
133149
raise RuntimeError(f'Editor iframe viewport differs: {actual}, expected {width}x900')
134150

135151

@@ -150,6 +166,20 @@ def size_frame(page,width):
150166
}"""
151167

152168

169+
# The administration chrome around the canvas keeps its layout space but is
170+
# not painted: the admin toolbar's shadow extends one pixel over a mobile
171+
# iframe's edge. The post editor's meta box pane takes none: with it, the
172+
# region holding the canvas was 899px tall and clipped the 900px iframe's
173+
# last row, which every scroll tile ended on (the pane's border, then the
174+
# admin's white: a seam every 450px down a tall capture).
175+
ADMIN_CHROME='.interface-interface-skeleton__header,.interface-interface-skeleton__footer{visibility:hidden!important}.edit-post-meta-boxes-main{display:none!important}'
176+
# The canvas iframe's box against everything that clips it (the admin
177+
# window and every ancestor with overflow): what a tile can capture.
178+
CLIP='''e=>{const r=e.getBoundingClientRect();let top=Math.max(0,r.top),bottom=Math.min(innerHeight,r.bottom);
179+
for(let n=e.parentElement;n;n=n.parentElement){const s=getComputedStyle(n);if(s.overflowX!=='visible'||s.overflowY!=='visible'){const b=n.getBoundingClientRect();top=Math.max(top,b.top);bottom=Math.min(bottom,b.bottom);}}
180+
return {top:r.top,bottom:r.bottom,visibleTop:top,visibleBottom:bottom}}'''
181+
182+
153183
def open_editor(browser,args,item,widths):
154184
"""One editor load for every width of a surface: the admin window stays at
155185
the widest width's size throughout (only the canvas iframe is resized)."""
@@ -158,6 +188,7 @@ def open_editor(browser,args,item,widths):
158188
page=context.new_page()
159189
page.goto(args.site+item['editorUrl'],wait_until='domcontentloaded')
160190
page.wait_for_function('window.wp && wp.data && wp.blocks',timeout=60000)
191+
page.add_style_tag(content=ADMIN_CHROME)
161192
page.wait_for_timeout(1200)
162193
# Native view mode: show the real assigned template around the
163194
# content. This action changes no post/template data or preference.
@@ -173,9 +204,6 @@ def open_editor(browser,args,item,widths):
173204
if button.nth(index).is_visible(): button.nth(index).click()
174205
close_settings=page.get_by_role('button',name='Close Settings',exact=True)
175206
if close_settings.count() and close_settings.first.is_visible():close_settings.first.click()
176-
# Admin toolbar shadow extends one pixel over mobile iframe edge.
177-
# Keep its layout space but exclude this non-content chrome.
178-
page.add_style_tag(content='.interface-interface-skeleton__header{visibility:hidden!important}')
179207
if item['kind']=='templates':
180208
resolved=page.evaluate("wp.data.select('core/edit-site').getEditedPostId()")
181209
if str(resolved)!=str(item['id']):

0 commit comments

Comments
 (0)