/** * One row of the docked header builder: a drag handle + name on the left * (the name opens the row's settings), its columns as drop zones of element * chips, and a trailing "+" to add an element or a column. * * A row with nothing in it collapses to a single dashed "Add element" strip — * its columns are still there underneath as drop targets, they just aren't * worth drawing until something is dragged over them. */ import { forwardRef, useState } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { Button } from '@wordpress/components'; import { CSS, SortableContext, horizontalListSortingStrategy, useDroppable, useSortable, } from '../../dnd'; import { EyeOff, GripVertical, PanelRight, Plus, SlidersHorizontal, X, } from '../../icons'; import ColumnToolbar from './column-toolbar'; import RowSettings from './row-settings'; import AddElementMenu from './add-element-menu'; import { iconFor, hasEditAffordance } from './element-registry'; import type { HeaderRow, HeaderColumn } from './canvas-model'; import type { Containers } from './use-canvas-dnd'; import type { RowOps } from './use-row-ops'; import type { ElementDef } from './element-groups'; interface ChipProps { id: string; label: string; onEdit: () => void; onRemove?: () => void; overlay?: boolean; /** Toggle only: highlighted together with the drawer card it opens. */ hot?: boolean; onHover?: ( hot: boolean ) => void; } const chipTitle = ( label: string, editable: boolean, linked: boolean ): string => { if ( linked ) { return sprintf( /* translators: %s: element name. */ __( '%s — opens the off-canvas panel', 'aureon' ), label ); } if ( editable ) { /* translators: %s: element name. */ return sprintf( __( 'Edit %s', 'aureon' ), label ); } return label; }; /** Presentational chip — also rendered in the DragOverlay. */ export const DockChip = forwardRef< HTMLDivElement, ChipProps & Omit< React.HTMLAttributes< HTMLDivElement >, 'id' > >( function DockChip( { id, label, onEdit, onRemove, overlay, hot, onHover, ...rest }, ref ) { const Icon = iconFor( id ); const editable = hasEditAffordance( id ); const linked = 'toggle' === id; return (
onHover( true ) : undefined } onMouseLeave={ onHover ? () => onHover( false ) : undefined } { ...rest } > { onRemove && ( ) }
); } ); export function SortableDockChip( { sortId, ...props }: ChipProps & { /** Sortable id when it differs from the element id (drawer items). */ sortId?: string; } ) { const { attributes, listeners, setNodeRef, transform, transition, isDragging, } = useSortable( { id: sortId ?? props.id } ); return (