Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 98 additions & 9 deletions src/app/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3699,17 +3699,31 @@ body > .embed-editor_provenance {
font-size: 12px;
}

/* Structure tree — flat Framer-style layer rows */
/* Structure tree — dense layer rows.
Every density knob of the navigator lives here: tune these, not the rules
below. StructureTree.tsx and TreeDragDrop.tsx read the indent. */
.navigator {
--navigator-row-height: 32px;
--navigator-row-padding: 6px;
--navigator-row-gap: 4px;
--navigator-row-radius: 4px;
--navigator-indent: 12px;
--navigator-font-size: 12px;
--navigator-font-weight: 400;
--navigator-label-color: var(--text);
--navigator-icon-color: var(--text-dim);
}
.structure-node {
display: flex;
align-items: center;
gap: 6px;
height: 28px;
padding: 0 6px;
border-radius: 6px;
gap: var(--navigator-row-gap, 6px);
height: var(--navigator-row-height, 28px);
padding: 0 var(--navigator-row-padding, 6px);
font-size: var(--navigator-font-size, 12px);
border-radius: var(--navigator-row-radius, 6px);
border: 1px solid transparent;
cursor: pointer;
color: var(--text-dim);
color: var(--navigator-label-color, var(--text-dim));
/* Rows are at least panel-width but grow with deep indentation + long
labels, so horizontal scrolling reveals the full text. */
width: fit-content;
Expand All @@ -3724,19 +3738,47 @@ body > .embed-editor_provenance {
background: var(--accent-soft);
color: var(--text);
}
/* The selected row is a capsule. With an open subtree it becomes the head of a
block: its bottom corners square off and the subtree below rounds them. */
.structure-node.selected:has(+ .structure-subtree) {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
/* Tint strength of the subtree block: raise the percentage for a stronger
background, lower it for a more transparent one. */
.structure-subtree {
--subtree-tint: 8%;
/* flow-root keeps the overlay drop gaps' negative margins inside the block;
without it the first gap pulls the block up over the selected row and the
two tints add up in a visible band. */
display: flow-root;
/* Clip the square hover of the last row to the block's rounded corners. */
overflow: clip;
background: color-mix(in srgb, var(--accent) var(--subtree-tint), transparent);
border-radius: 0 0 var(--navigator-row-radius, 6px) var(--navigator-row-radius, 6px);
margin-bottom: 2px;
}
/* Inside the open block the hover is square: it fills the block edge to edge
instead of floating as a capsule. Rows elsewhere keep their radius. */
.structure-subtree .structure-node:hover {
border-radius: 0;
}
.structure-subtree.is-component {
background: color-mix(in srgb, var(--component-green) var(--subtree-tint), transparent);
}
/* Hovering must not repaint the selected row's icon — the :hover rule below
has the same specificity and would otherwise win on source order. */
.structure-node.selected .icon,
.structure-node.selected:hover .icon {
color: var(--accent);
}
.structure-node.layout-node {
color: var(--text-dim);
color: var(--navigator-label-color, var(--text-dim));
}
.structure-node .icon {
display: flex;
align-items: center;
color: var(--text-faint);
color: var(--navigator-icon-color, var(--text-faint));
}
.structure-node:hover .icon {
color: var(--text-dim);
Expand All @@ -3757,14 +3799,42 @@ body > .embed-editor_provenance {
color: var(--text-faint);
opacity: 0.6;
}
/* A leaf's empty slot: it holds the width, never the pointer. */
.structure-node .drag-handle.is-empty {
display: flex;
flex-shrink: 0;
width: 18px;
align-self: stretch;
margin: 0 -2px 0 -4px;
pointer-events: none;
}
/* Hierarchy guides, as in Webflow: a thin line from each open parent's
chevron down past its last child, shown while the pointer is over the tree. */
.structure-children {
position: relative;
}
.structure-guide {
position: absolute;
top: 0;
bottom: 0;
width: 1px;
background: var(--border-strong, var(--border));
opacity: 0;
pointer-events: none;
transition: opacity 120ms ease;
z-index: 1;
}
.navigator .panel-body:hover .structure-guide {
opacity: 0.4;
}
.tree-drag-row .drag-handle:hover {
opacity: 1;
color: var(--text);
}
.structure-node .label {
flex: 1;
white-space: nowrap;
font-weight: 500;
font-weight: var(--navigator-font-weight, 500);
}
.structure-node .prop-preview {
font-size: 10.5px;
Expand Down Expand Up @@ -3846,6 +3916,25 @@ body > .embed-editor_provenance {
margin-bottom: -3.5px;
z-index: 1;
}
/* Navigator gaps take no room; they catch the pointer only during a drag
over the panel (StructurePanel.tsx sets .is-drag-over). */
.navigator .nav-gap.nav-gap-overlay {
/* Zero height, not 7px with -3.5px margins: adjacent negative margins merge,
so each level of a subtree ending together left 3.5px of blank strip at
the bottom of the block. The 7px hit area lives in the ::before. */
height: 0;
margin-top: 0;
margin-bottom: 0;
pointer-events: none;
}
.navigator .nav-gap.nav-gap-overlay::before {
content: '';
position: absolute;
inset: -3.5px 0;
}
.navigator .panel-body.is-drag-over .nav-gap.nav-gap-overlay {
pointer-events: auto;
}
.drop-indicator {
/* The marker must not move the gap or become a new drag target. */
position: absolute;
Expand Down
19 changes: 13 additions & 6 deletions src/features/structure/StructurePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { PseudoKind, PseudoNodeIds, StructureTreeContext } from './Structur
import type { ContextPosition } from './StructureContextMenu';
import { ElementContextMenu } from './ElementContextMenu';
import type { WrapperTag } from '../../editor/wrapRules';
import { CollapseVerticalIcon, CodeIcon, DragIcon, ExpandVerticalIcon } from '../../ui/Icons';
import { CollapseVerticalIcon, CodeIcon, ExpandVerticalIcon } from '../../ui/Icons';
import { hidesChildRows } from '../../editor/treeSelection';
import { navigatorArrowTarget } from './navigatorArrows';
import {
Expand Down Expand Up @@ -150,7 +150,7 @@ function EditableStructurePanel(props: EditableProps) {
const state = useTreeState(props);
const treeContext = treeContextOf(props, state);
return (
<div className="panel-section grow">
<div className="panel-section grow navigator">
<NavigatorHeader state={state} nodes={props.pageState.model.nodes} />
<NavigatorBody props={props} state={state} treeContext={treeContext} />
{state.contextMenu && (
Expand Down Expand Up @@ -497,19 +497,27 @@ function NavigatorBody({
readonly treeContext: StructureTreeContext;
}) {
const nodes = props.pageState.model.nodes;
// Drop gaps overlap the row edges instead of taking room between rows, so
// they catch the pointer only while a drag is over the navigator. Otherwise
// a click on a row's edge would land on a gap and select nothing.
const [bodyDrag, setBodyDrag] = useState<BodyDrag>('idle');
return (
<div
className="panel-body"
className={bodyDrag === 'dragging' ? 'panel-body is-drag-over' : 'panel-body'}
ref={state.bodyRef}
onDragEnter={() => setBodyDrag('dragging')}
onDragOver={() => state.setDropTarget(undefined)}
onDragLeave={(event) => {
if (event.relatedTarget instanceof Node) {
if (event.currentTarget.contains(event.relatedTarget)) {
return;
}
}
setBodyDrag('idle');
state.setDropTarget(undefined);
}}
onDropCapture={() => setBodyDrag('idle')}
onDragEnd={() => setBodyDrag('idle')}
>
{!props.clientMode && !props.editRootId && <FrontmatterRow props={props} />}
<NodeList nodes={nodes} parentId={undefined} depth={0} {...treeContext} />
Expand All @@ -518,6 +526,8 @@ function NavigatorBody({
);
}

type BodyDrag = 'idle' | 'dragging';

function FrontmatterRow({ props }: { readonly props: EditableProps }) {
const importCount = props.pageState.model.imports.length;
const selectedClass = props.selectedId === 'frontmatter' ? 'selected' : '';
Expand All @@ -528,9 +538,6 @@ function FrontmatterRow({ props }: { readonly props: EditableProps }) {
onClick={() => props.onSelect('frontmatter')}
onDoubleClick={() => props.onOpenCode?.('frontmatter')}
>
<span className="drag-handle" style={{ visibility: 'hidden' }}>
<DragIcon size={11} />
</span>
<span className="icon">
<CodeIcon size={12} />
</span>
Expand Down
40 changes: 34 additions & 6 deletions src/features/structure/StructureTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function Gap(props: GapProps) {
}
return (
<TreeDropGap
layout="overlay"
depth={depth}
parent={parentId}
index={index}
Expand Down Expand Up @@ -170,15 +171,20 @@ function TreeNode(props: TreeNodeProps) {
onSelect={props.onSelectPseudo ?? ((id) => props.onSelect(id))}
/>
) : undefined;
const rowSelected = selected && props.selectedPseudo === undefined;
return (
<>
<TreeRow {...props} {...view} selected={selected && props.selectedPseudo === undefined} rowRef={rowRef} />
<TreeRow {...props} {...view} selected={rowSelected} rowRef={rowRef} />
{showChildren && !view.collapsed && (
<>
// The selected row's subtree sits in a tinted block under the row, so the
// selection reads as one container. The tint follows the row's own colour.
<div className={subtreeClassName({ rowSelected, component: view.component })}>
{/* The guide drops from the parent's chevron; CSS shows it while the pointer is over the tree. */}
<span className="structure-guide" aria-hidden="true" style={{ left: navigatorGuideLeft(depth) }} />
{pseudoRow('before')}
{listsChildren && <NodeList {...context} nodes={children} parentId={host.id} depth={depth + 1} />}
{pseudoRow('after')}
</>
</div>
)}
</>
);
Expand Down Expand Up @@ -214,15 +220,16 @@ function PseudoRow(props: {
className={`structure-node is-pseudo${props.selected ? ' selected' : ''}`}
data-pseudo-of={props.nodeId}
data-pseudo={props.pseudo}
style={{ paddingLeft: 6 + props.depth * 16 }}
data-depth={props.depth}
style={{ paddingLeft: navigatorIndent(props.depth) }}
onMouseEnter={() => props.onHover(props.nodeId, props.pseudo)}
onMouseLeave={props.onLeave}
onClick={(event) => {
event.stopPropagation();
props.onSelect(props.nodeId, props.pseudo);
}}
>
<span className="drag-handle" />
<span className="drag-handle is-empty" aria-hidden="true" />
<span className="icon">
<PseudoElementIcon size={12} />
</span>
Expand Down Expand Up @@ -319,7 +326,8 @@ function TreeRow(props: TreeRowProps) {
aria-disabled={!props.canEdit(node.id)}
title={props.fragment ? fragmentTitle : undefined}
className={rowClassName(props)}
style={{ paddingLeft: 6 + props.depth * 16 }}
data-depth={props.depth}
style={{ paddingLeft: navigatorIndent(props.depth) }}
dropBehavior={treeRowDropBehavior(props)}
draggable={
props.canEdit(node.id) &&
Expand Down Expand Up @@ -491,3 +499,23 @@ function nodeIsDataBound(node: NavigatorNode): boolean {
const fragmentTitle = 'Inline group in this file. Expand it to edit its children; there is no separate file to open.';

export { defaultCollapsed };

// Only the selected row's subtree is tinted; a component's block takes the component colour.
function subtreeClassName(row: { readonly rowSelected: boolean; readonly component: boolean }): string {
if (row.rowSelected) {
return row.component ? 'structure-children structure-subtree is-component' : 'structure-children structure-subtree';
}
return 'structure-children';
}

// The indent step lives in CSS (`--navigator-indent` in styles.css), so the
// navigator's density is tuned in one stylesheet, not in TSX.
function navigatorIndent(depth: number): string {
return `calc(var(--navigator-row-padding) + ${depth} * var(--navigator-indent))`;
}

// The guide runs under the centre of the parent row's chevron: the row's left
// padding, its 1px border, then half the 18px handle less its -4px margin.
function navigatorGuideLeft(depth: number): string {
return `calc(${navigatorIndent(depth)} + 6px)`;
}
31 changes: 19 additions & 12 deletions src/ui/TreeDragDrop.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { forwardRef, useEffect, useRef } from 'react';
import { ChevronDownIcon, ChevronRightIcon, DragIcon } from './Icons';
import { ChevronDownIcon, ChevronRightIcon } from './Icons';
import { DropLine } from './DropLine';

export interface TreeDropBehavior {
Expand Down Expand Up @@ -49,29 +49,36 @@ export function TreeDropGap({
className={`nav-gap ${layout === 'overlay' ? 'nav-gap-overlay' : ''}`}
data-drop-parent={parent ?? ''}
data-drop-index={index}
style={{ marginLeft: depth * 16, pointerEvents: interactive ? undefined : 'none' }}
style={{
marginLeft: `calc(${depth} * var(--navigator-indent, 16px))`,
// Where subtrees end, overlay gaps of several levels share one edge: the
// deeper one sits on top, so the pointer's x position picks the level.
...(layout === 'overlay' ? { zIndex: 1 + depth } : {}),
pointerEvents: interactive ? undefined : 'none',
}}
{...treeDropHandlers(behavior)}
>
{behavior.active && <DropLine />}
</div>
);
}

// Only a node with children carries a collapse chevron. A leaf keeps the empty
// slot so its icon lines up with its siblings' icons; the whole row is draggable.
export function TreeDragHandle({ expansion }: { readonly expansion?: { readonly collapsed: boolean; readonly toggle: () => void } }) {
if (expansion === undefined) {
return <span className="drag-handle is-empty" aria-hidden="true" />;
}
return (
<span
className="drag-handle"
style={expansion ? { cursor: 'pointer', opacity: 1 } : undefined}
onClick={
expansion
? (event) => {
event.stopPropagation();
expansion.toggle();
}
: undefined
}
style={{ cursor: 'pointer', opacity: 1 }}
onClick={(event) => {
event.stopPropagation();
expansion.toggle();
}}
>
{expansion ? expansion.collapsed ? <ChevronRightIcon size={10} /> : <ChevronDownIcon size={10} /> : <DragIcon size={11} />}
{expansion.collapsed ? <ChevronRightIcon size={12} /> : <ChevronDownIcon size={12} />}
</span>
);
}
Expand Down
Loading
Loading