feat(builder): items 10+12+13 — scope canvas guides, Show Guides toggle, Layers panel hover/icons, topbar unification
Item 10: dashed canvas "guide" outlines were applied via blanket tag
selectors (div/section/header/...), so a finished section showed 3-4
nested dashed boxes. RenderNode.tsx (the <Editor onRender> override) now
tags each Craft.js droppable container's real DOM node with a
`data-craft-node` attribute (node.data.isCanvas, excluding ROOT), and
editor.css's guide rules target that attribute instead — a component's own
internal wrapper markup is no longer mistaken for a drop target. Added a
"Show guides" topbar toggle (default ON, persisted to localStorage),
state lifted in EditorShell.tsx (mirrors how `device` is already lifted),
flips `.guides-off` on Canvas.tsx's `.canvas-device-frame`.
Item 12: Layers panel rows get per-type FA icons (keyed off the same
craft.displayName used for the row label, seeded from BlocksPanel's
choices), indent-guide lines connecting nested rows, and row hover
highlights the matching canvas element (`data-layer-hovered`, written
directly to the node's DOM via `query.node(id).get().dom` — NOT via
`actions.setNodeEvent`, which is stripped from useEditor()'s public
`actions` at runtime, not just in its TS type, and threw when called).
Along the way, Craft.js's own connect() was found to already wire mouse
hover to the same `hovered` node event internally (previously invisible
because the matching CSS was dead) — RenderNode now also mirrors that
onto `data-craft-hovered` for a real-mouse-hover canvas highlight, and
both hover attributes plus the guide attribute are suppressed under
`.guides-off` so the toggle stays airtight.
Item 13: unified the topbar to one button radius (`.topbar-btn` 20px pill
-> var(--radius-md)), demoted Code/Preview to icon-only with
`data-tooltip`. Fixed a latent bug the new tooltips exposed: `[data-tooltip]`
tooltips render above their trigger, but the topbar has no room above it
(`body { overflow: hidden }`) — added a `.topbar` override to render
those below instead.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,74 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import React, { useCallback, useEffect, useRef } from 'react';
|
||||
import { useEditor } from '@craftjs/core';
|
||||
import { clickableProps } from '../../utils/a11y';
|
||||
|
||||
/**
|
||||
* Per-type icon lookup keyed by the component's `craft.displayName` (the
|
||||
* same human label `LayerNode` already resolves and shows as the row text).
|
||||
* Mirrors the icon choices in `BlocksPanel.tsx` where a block exists for the
|
||||
* type; the remaining entries (Navbar, Container, Section, Columns,
|
||||
* Background Section, Map, Video, Image, form fields, and the richer
|
||||
* section blocks not draggable from the Basic/Sections categories) get a
|
||||
* sensible FA4 icon of their own. Unknown/future types fall back to
|
||||
* `DEFAULT_ICON`.
|
||||
*/
|
||||
const TYPE_ICONS: Record<string, string> = {
|
||||
// Layout
|
||||
Container: 'fa-square-o',
|
||||
Section: 'fa-window-maximize',
|
||||
Columns: 'fa-th-large',
|
||||
'Background Section': 'fa-picture-o',
|
||||
// Basic
|
||||
Heading: 'fa-header',
|
||||
Text: 'fa-paragraph',
|
||||
Button: 'fa-square',
|
||||
Logo: 'fa-bookmark',
|
||||
Menu: 'fa-bars',
|
||||
Navbar: 'fa-bars',
|
||||
Footer: 'fa-window-minimize',
|
||||
Divider: 'fa-minus',
|
||||
Spacer: 'fa-arrows-v',
|
||||
Icon: 'fa-star',
|
||||
'Star Rating': 'fa-star-half-o',
|
||||
'Social Links': 'fa-share-alt',
|
||||
'Search Bar': 'fa-search',
|
||||
HTML: 'fa-code',
|
||||
// Media
|
||||
Image: 'fa-image',
|
||||
Video: 'fa-play-circle',
|
||||
Map: 'fa-map-marker',
|
||||
// Sections
|
||||
Hero: 'fa-star-o',
|
||||
'Features Grid': 'fa-th-large',
|
||||
'CTA Section': 'fa-bullhorn',
|
||||
'Call to Action': 'fa-bullhorn',
|
||||
Countdown: 'fa-clock-o',
|
||||
Testimonials: 'fa-quote-left',
|
||||
'Content Slider': 'fa-sliders',
|
||||
'Number Counter': 'fa-sort-numeric-asc',
|
||||
Accordion: 'fa-list',
|
||||
Tabs: 'fa-folder-o',
|
||||
'Pricing Table': 'fa-usd',
|
||||
Gallery: 'fa-th',
|
||||
// Forms
|
||||
Form: 'fa-wpforms',
|
||||
Input: 'fa-i-cursor',
|
||||
Textarea: 'fa-align-left',
|
||||
'Submit Button': 'fa-paper-plane',
|
||||
'Contact Form': 'fa-envelope',
|
||||
'Subscribe Form': 'fa-paper-plane',
|
||||
};
|
||||
|
||||
const DEFAULT_ICON = 'fa-cube';
|
||||
const ROOT_ICON = 'fa-desktop';
|
||||
|
||||
interface LayerNodeProps {
|
||||
nodeId: string;
|
||||
depth: number;
|
||||
}
|
||||
|
||||
const LayerNode: React.FC<LayerNodeProps> = ({ nodeId, depth }) => {
|
||||
const { node, selectedId, actions } = useEditor((state) => {
|
||||
const { node, selectedId, actions, query } = useEditor((state) => {
|
||||
const n = state.nodes[nodeId];
|
||||
const selectedIds = state.events.selected;
|
||||
const selId = selectedIds ? Array.from(selectedIds)[0] : null;
|
||||
@@ -18,28 +78,76 @@ const LayerNode: React.FC<LayerNodeProps> = ({ nodeId, depth }) => {
|
||||
};
|
||||
});
|
||||
|
||||
const isSelected = selectedId === nodeId;
|
||||
|
||||
const handleActivate = useCallback(() => {
|
||||
actions.selectNode(nodeId);
|
||||
}, [actions, nodeId]);
|
||||
|
||||
// Layers-panel <-> canvas hover sync (Item 12): tags the target node's own
|
||||
// DOM element (found via `query`) with `data-layer-hovered` directly.
|
||||
// `RenderNode.tsx` mirrors Craft's *own* `hovered` node event onto
|
||||
// `data-craft-hovered` for the (separate, mouse-driven) canvas hover
|
||||
// outline -- editor.css's rule matches both attributes. This panel can't
|
||||
// reuse that path: `setNodeEvent` is a private action that `useEditor()`
|
||||
// strips from its `actions` return at runtime (see
|
||||
// @craftjs/core/dist/esm's `xe()` action stripper, not just its TypeScript
|
||||
// type), so calling it here throws. Writing our own attribute directly is
|
||||
// a supported, version-stable way to get the same highlight.
|
||||
const hoveredDomRef = useRef<HTMLElement | null>(null);
|
||||
|
||||
const handleMouseEnter = useCallback(
|
||||
(e: React.MouseEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {
|
||||
const dom = query.node(nodeId).get()?.dom;
|
||||
if (dom) {
|
||||
dom.setAttribute('data-layer-hovered', '');
|
||||
hoveredDomRef.current = dom;
|
||||
}
|
||||
if (!isSelected) {
|
||||
(e.currentTarget as HTMLElement).style.background = 'var(--color-bg-hover)';
|
||||
}
|
||||
},
|
||||
[query, nodeId, isSelected],
|
||||
);
|
||||
|
||||
const handleMouseLeave = useCallback(
|
||||
(e: React.MouseEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {
|
||||
hoveredDomRef.current?.removeAttribute('data-layer-hovered');
|
||||
hoveredDomRef.current = null;
|
||||
if (!isSelected) {
|
||||
(e.currentTarget as HTMLElement).style.background = 'transparent';
|
||||
}
|
||||
},
|
||||
[isSelected],
|
||||
);
|
||||
|
||||
// Safety net: if this row unmounts (e.g. the user switches away from the
|
||||
// Layers tab, or the tree re-shuffles) while still hovered, clear the
|
||||
// attribute so it doesn't get stuck highlighted on the canvas forever.
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
hoveredDomRef.current?.removeAttribute('data-layer-hovered');
|
||||
hoveredDomRef.current = null;
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!node) return null;
|
||||
|
||||
const isSelected = selectedId === nodeId;
|
||||
const nodeType = node.data.type;
|
||||
const resolvedName = typeof nodeType === 'object' && nodeType !== null && 'resolvedName' in nodeType
|
||||
? (nodeType as any).resolvedName
|
||||
: typeof nodeType === 'string' ? nodeType : undefined;
|
||||
const displayName = (node.data.props?.aiName as string) || node.data.displayName || (node.data.type as any)?.resolvedName || 'Node';
|
||||
const childNodeIds: string[] = node.data.nodes || [];
|
||||
const linkedNodeIds: string[] = Object.values(node.data.linkedNodes || {}) as string[];
|
||||
const allChildren = [...childNodeIds, ...linkedNodeIds];
|
||||
const isRoot = nodeId === 'ROOT';
|
||||
const icon = isRoot ? ROOT_ICON : TYPE_ICONS[displayName] || DEFAULT_ICON;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
{...clickableProps(handleActivate)}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
style={{
|
||||
position: 'relative',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
padding: '5px 8px',
|
||||
@@ -56,30 +164,53 @@ const LayerNode: React.FC<LayerNodeProps> = ({ nodeId, depth }) => {
|
||||
textOverflow: 'ellipsis',
|
||||
userSelect: 'none',
|
||||
}}
|
||||
onMouseEnter={(e) => {
|
||||
if (!isSelected) {
|
||||
(e.currentTarget as HTMLElement).style.background = 'var(--color-bg-hover)';
|
||||
}
|
||||
}}
|
||||
onMouseLeave={(e) => {
|
||||
if (!isSelected) {
|
||||
(e.currentTarget as HTMLElement).style.background = 'transparent';
|
||||
}
|
||||
}}
|
||||
onFocus={handleMouseEnter}
|
||||
onBlur={handleMouseLeave}
|
||||
>
|
||||
{/* Indentation indicator */}
|
||||
{allChildren.length > 0 && (
|
||||
<span style={{ marginRight: 4, fontSize: 8, color: 'var(--color-text-dim)' }}>
|
||||
{/* Indent guides: one vertical line per ancestor depth level,
|
||||
aligned under each ancestor's disclosure/icon column so nested
|
||||
rows read as a tree instead of a flat, ever-further-indented list. */}
|
||||
{Array.from({ length: depth }).map((_, level) => (
|
||||
<span
|
||||
key={level}
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
position: 'absolute',
|
||||
left: `${8 + level * 16 + 4}px`,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
width: 1,
|
||||
background: 'var(--color-border)',
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
||||
{/* Indentation/disclosure indicator */}
|
||||
{allChildren.length > 0 ? (
|
||||
<span style={{ marginRight: 4, fontSize: 8, color: 'var(--color-text-dim)', flexShrink: 0 }}>
|
||||
▼
|
||||
</span>
|
||||
)}
|
||||
{allChildren.length === 0 && (
|
||||
<span style={{ marginRight: 4, fontSize: 8, color: 'transparent' }}>
|
||||
) : (
|
||||
<span style={{ marginRight: 4, fontSize: 8, color: 'transparent', flexShrink: 0 }}>
|
||||
▼
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Component type icon and name */}
|
||||
{/* Component type icon */}
|
||||
<i
|
||||
className={`fa ${icon}`}
|
||||
aria-hidden="true"
|
||||
style={{
|
||||
marginRight: 6,
|
||||
fontSize: 11,
|
||||
width: 12,
|
||||
textAlign: 'center',
|
||||
flexShrink: 0,
|
||||
color: isSelected ? 'var(--color-accent)' : 'var(--color-text-dim)',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Name */}
|
||||
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
{isRoot ? 'Canvas (Root)' : displayName}
|
||||
</span>
|
||||
|
||||
@@ -13,9 +13,12 @@ import { useSitesmithModal } from '../../state/SitesmithContext';
|
||||
interface TopBarProps {
|
||||
device: DeviceMode;
|
||||
onDeviceChange: (device: DeviceMode) => void;
|
||||
/** Item 10: canvas dashed guide outlines, default ON. */
|
||||
showGuides: boolean;
|
||||
onToggleGuides: () => void;
|
||||
}
|
||||
|
||||
export const TopBar: React.FC<TopBarProps> = ({ device, onDeviceChange }) => {
|
||||
export const TopBar: React.FC<TopBarProps> = ({ device, onDeviceChange, showGuides, onToggleGuides }) => {
|
||||
const { whpConfig, isWHP } = useEditorConfig();
|
||||
const { actions, query, canUndo, canRedo } = useEditor((_state, query) => ({
|
||||
canUndo: query.history.canUndo(),
|
||||
@@ -148,6 +151,16 @@ export const TopBar: React.FC<TopBarProps> = ({ device, onDeviceChange }) => {
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className={`topbar-btn guides-toggle icon-only${showGuides ? ' active' : ''}`}
|
||||
onClick={onToggleGuides}
|
||||
aria-pressed={showGuides}
|
||||
aria-label={showGuides ? 'Hide canvas guides' : 'Show canvas guides'}
|
||||
data-tooltip={showGuides ? 'Hide guides' : 'Show guides'}
|
||||
>
|
||||
<i className={`fa ${showGuides ? 'fa-th' : 'fa-th-large'}`} aria-hidden />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="topbar-right">
|
||||
@@ -161,10 +174,15 @@ export const TopBar: React.FC<TopBarProps> = ({ device, onDeviceChange }) => {
|
||||
<button className="topbar-btn" title="Templates" aria-label="Templates" onClick={() => setTemplateModalOpen(true)}>
|
||||
<i className="fa fa-th-large" /> Templates
|
||||
</button>
|
||||
<button className="topbar-btn" title="Custom Head Code" aria-label="Custom Head Code" onClick={() => setHeadCodeModalOpen(true)}>
|
||||
<i className="fa fa-code" /> Code
|
||||
<button
|
||||
className="topbar-btn icon-only"
|
||||
aria-label="Custom Head Code"
|
||||
data-tooltip="Code"
|
||||
onClick={() => setHeadCodeModalOpen(true)}
|
||||
>
|
||||
<i className="fa fa-code" />
|
||||
</button>
|
||||
<button className="topbar-btn" title="Preview" aria-label="Preview" onClick={() => {
|
||||
<button className="topbar-btn icon-only" aria-label="Preview" data-tooltip="Preview" onClick={() => {
|
||||
try {
|
||||
const serialized = query.serialize();
|
||||
import('../../utils/html-export').then(({ exportToHtml, exportBodyHtml }) => {
|
||||
@@ -218,7 +236,7 @@ export const TopBar: React.FC<TopBarProps> = ({ device, onDeviceChange }) => {
|
||||
console.error('Preview failed:', e);
|
||||
}
|
||||
}}>
|
||||
<i className="fa fa-eye" /> Preview
|
||||
<i className="fa fa-eye" />
|
||||
</button>
|
||||
|
||||
{/* Draft/Published status badge */}
|
||||
|
||||
Reference in New Issue
Block a user