fix(sections): inserting from the section library closes the mobile Blocks sheet

The section library now calls closeSheet() after inserting a section (or a
global section). It mounts in CanvasOverlays, beside EditorShell, so it could
not reach the MobileChromeProvider inside the shell; the provider moves up to
App around the shell and the overlays so both share one sheet state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-10-07 13:41:22 -07:00
1 parent 472e5e4d81
commit eb401cd979
5 files changed
+85 -12

No files matched your search

@@ -7,6 +7,7 @@ import { SiteDesignProvider } from '../../state/SiteDesignContext';
import { __resetCommandsForTests, getCommand } from '../../editor/commands';
import { SectionLibraryModal, openSectionLibrary, closeSectionLibrary } from './SectionLibraryModal';
import { BlocksPanel } from '../left/BlocksPanel';
import { MobileChromeProvider, useMobileChrome } from '../../state/MobileChromeContext';
let h: EditorHarness;
let extrasApi: ReturnType<typeof useProjectExtras>;
@@ -117,3 +118,28 @@ describe('SectionLibraryModal', () => {
expect($$('.section-lib-card').map((c) => c.dataset.sectionId)).toContain('custom-loaded');
});
});
describe('SectionLibraryModal on mobile', () => {
let chrome: ReturnType<typeof useMobileChrome>;
const Chrome: React.FC = () => { chrome = useMobileChrome(); return null; };
function mountMobile() {
h = renderEditorHarness({
wrap: (tree) => (
<SaveGuardProvider><ProjectExtrasProvider><SiteDesignProvider><MobileChromeProvider>
{tree}<Grab /><Chrome />
</MobileChromeProvider></SiteDesignProvider></ProjectExtrasProvider></SaveGuardProvider>
),
});
h.mountChild(<SectionLibraryModal />);
}
test('inserting a section closes the Blocks sheet so the canvas is visible', () => {
mountMobile();
h.act(() => chrome.openSheet('blocks'));
expect(chrome.activeSheet).toBe('blocks');
h.act(() => openSectionLibrary());
h.act(() => { ($('[data-section-id="hero-centered"] .section-lib-pick') as HTMLElement).click(); });
expect(rootKids()).toHaveLength(1);
expect(chrome.activeSheet).toBeNull();
});
});
@@ -14,6 +14,7 @@ import { exportToHtml } from '../../utils/html-export';
import { masterZoneState, type GlobalMaster } from '../../utils/global-sections';
import { useGlobalSections } from '../../state/GlobalSectionsContext';
import { usePages } from '../../state/PageContext';
import { useMobileChrome } from '../../state/MobileChromeContext';
// ---- open state: module-level so the command, the empty-state button and the
// Blocks panel button can open the modal without a provider ----
@@ -79,6 +80,8 @@ export const SectionLibraryModal: React.FC = () => {
const [globalTab, setGlobalTab] = useState(false);
const globals = useGlobalSections();
const { isEditingGlobal } = usePages();
// Mobile: an insert also closes the Blocks sheet so the new section is visible.
const { closeSheet } = useMobileChrome();
const [q, setQ] = useState('');
const [saveName, setSaveName] = useState('');
@@ -118,6 +121,7 @@ export const SectionLibraryModal: React.FC = () => {
return;
}
closeSectionLibrary();
closeSheet();
notify({ kind: 'success', message: `Added global section "${name}"` });
};
const onDeleteGlobal = (libraryId: string, name: string) => {
@@ -132,6 +136,7 @@ export const SectionLibraryModal: React.FC = () => {
try {
const id = insertSection(query, actions, def, { afterSelection: true, select: true });
closeSectionLibrary();
closeSheet();
notify({ kind: 'success', message: `Added "${def.name}"` });
requestAnimationFrame(() => requestAnimationFrame(() => {
try { query.node(id).get()?.dom?.scrollIntoView({ behavior: 'smooth', block: 'center' }); } catch { /* best effort */ }
@@ -140,7 +145,7 @@ export const SectionLibraryModal: React.FC = () => {
console.error('Failed to insert section:', e);
notify({ kind: 'error', message: 'Could not add that section.' });
}
}, [query, actions, notify]);
}, [query, actions, notify, closeSheet]);
const onSave = () => {
const name = saveName.trim();