feat(site-builder): section library catalog, modal and insertion

Catalog skeleton with per-family files (one seed each for hero, services,
contact), live token-styled thumbnails, insert-after-selection, and
save-as-section into project extras.

Refs #52

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-10-07 11:52:25 -07:00
1 parent 8860349c9b
commit 6e819f1ef2
23 files changed
+903 -10

No files matched your search

+4 -3
View File
@@ -9,6 +9,7 @@ import { useIsMobile } from '../hooks/useIsMobile';
import { useMobileChrome } from '../state/MobileChromeContext';
import { useSitesmithModal } from '../state/SitesmithContext';
import { insertBlock } from '../panels/left/blocks-registry';
import { openSectionLibrary } from '../panels/sections/SectionLibraryModal';
interface CanvasProps {
/** Item 10: when false, applies `.guides-off` to hide the dashed drop-target guides. */
@@ -109,8 +110,8 @@ const ZonePreview: React.FC<{ craftState: string | null; zone: 'header' | 'foote
* opt back in.
*/
/** "Add a section" action. Kept as one named function so #52 can point it at
* the section library with a one-line swap. */
/** Blank-section insert (no longer wired to the empty-state button, which
* opens the section library). */
export function addSectionToRoot(query: any, actions: any): string | null {
return insertBlock(query, actions, 'section', { parentId: 'ROOT', select: true });
}
@@ -141,7 +142,7 @@ export const EmptyCanvasHint: React.FC = () => {
<button type="button" className="empty-canvas-btn" onClick={() => setTemplateModalOpen(true)}>
<i className="fa fa-th-large" aria-hidden /> Choose a template
</button>
<button type="button" className="empty-canvas-btn" onClick={() => addSectionToRoot(query, actions)}>
<button type="button" className="empty-canvas-btn" onClick={() => openSectionLibrary()}>
<i className="fa fa-plus" aria-hidden /> Add a section
</button>
<button type="button" className="empty-canvas-btn" onClick={() => openSitesmith()}>
+2
View File
@@ -3,6 +3,7 @@ import { NoticeHost } from './NoticeHost';
import { EmptyContainerAdd } from './EmptyContainerAdd';
import { DropIndicator } from './DropIndicator';
import { RichTextToolbar } from './RichTextToolbar';
import { SectionLibraryModal } from '../panels/sections/SectionLibraryModal';
/**
* Single mount point for editor-wide overlays rendered next to the shell.
@@ -15,5 +16,6 @@ export const CanvasOverlays: React.FC = () => (
<EmptyContainerAdd />
<DropIndicator />
<RichTextToolbar />
<SectionLibraryModal />
</>
);
+9 -7
View File
@@ -3,6 +3,7 @@ import React from 'react';
import { renderEditorHarness, EditorHarness } from '../test-utils/editorHarness';
import { EmptyCanvasHint, addSectionToRoot } from './Canvas';
import { SitesmithProvider, useSitesmithModal } from '../state/SitesmithContext';
import { closeSectionLibrary, useSectionLibraryState } from '../panels/sections/SectionLibraryModal';
import { MobileChromeProvider, useMobileChrome } from '../state/MobileChromeContext';
const forceDragging = vi.hoisted(() => ({ on: false }));
@@ -21,9 +22,11 @@ vi.mock('@craftjs/core', async (orig) => {
/* Real @craftjs/core editor (no mocks); providers wrap the whole <Editor>. */
let h: EditorHarness;
let libState = { open: false, saving: false };
let seen: { sitesmithOpen: boolean; templateOpen: boolean };
const Probe: React.FC = () => {
libState = useSectionLibraryState();
seen = { sitesmithOpen: useSitesmithModal().isOpen, templateOpen: useMobileChrome().templateModalOpen };
return null;
};
@@ -54,14 +57,13 @@ describe('EmptyCanvasHint', () => {
expect(btn('Generate with Sitesmith')).toBeTruthy();
});
test('"Add a section" adds a Section under ROOT, selects it, and hides the hint', () => {
test('"Add a section" opens the section library and leaves the canvas empty', () => {
mount();
expect(libState.open).toBe(false);
h.act(() => { btn('Add a section').click(); });
const rootNodes: string[] = h.query.node('ROOT').get().data.nodes;
expect(rootNodes).toHaveLength(1);
expect(h.query.node(rootNodes[0]).get().data.displayName).toBe('Section');
expect(h.query.getEvent('selected').all()).toEqual([rootNodes[0]]);
expect(h.container.querySelector('.empty-canvas-hint')).toBeNull();
expect(libState.open).toBe(true);
expect(h.query.node('ROOT').get().data.nodes).toHaveLength(0);
closeSectionLibrary();
});
test('Sitesmith button opens the Sitesmith modal', () => {
@@ -80,7 +82,7 @@ describe('EmptyCanvasHint', () => {
test('hides once the page has content', () => {
mount();
h.act(() => { btn('Add a section').click(); });
h.act(() => { addSectionToRoot(h.query, h.actions); });
expect(nodeTypes()).toContain('Section');
expect(h.container.querySelector('.empty-canvas-hint')).toBeNull();
});