import React, { CSSProperties } from 'react'; import { useEditor } from '@craftjs/core'; import { IMAGE_RADIUS_PRESETS, OBJECT_FIT, } from '../../../constants/presets'; import { StylePanelProps, SectionLabel, PresetButtonGrid, TextInputField, SizeControl, AspectRatioControl, FocalPointGrid, useNodeProp, } from './shared'; import { AssetPicker } from '../../../ui/AssetPicker'; import { PLACEHOLDER_SRC } from '../../../components/media/ImageBlock'; import { BoxModelSection, BorderEffectsSection, AnimVisSection } from './mediaBoxModel'; /* ---------- IMAGE (with upload/browse/drop) ---------- */ export const ImageStylePanel: React.FC = ({ selectedId, nodeProps }) => { const { actions } = useEditor(); const style: CSSProperties = nodeProps.style || {}; const { setProp, setPropStyle } = useNodeProp(selectedId); // Applying an aspect-ratio crop should FILL the frame by default (object-fit: // cover) rather than leave letterboxed empty bands, and width + ratio + cover // fully determine the box -- so a stale `height` can't linger and conflict // (kills the %-height no-op that made resize look like it wasn't working). // Clearing the ratio (back to 'Original') leaves objectFit as the user left it. const applyAspectRatio = (v: string) => { setPropStyle('aspectRatio', v); if (v) { if (!style.objectFit) setPropStyle('objectFit', 'cover'); setPropStyle('height', ''); } }; return ( <> {/* Image source */}
Image Source actions.setProp(selectedId, (props: any) => { props.src = url || PLACEHOLDER_SRC; })} variant="full" />
{/* Alt Text */} { actions.setProp(selectedId, (props: any) => { props.alt = v; }); }} /> {/* Size -- Width absorbs the historical maxWidth presets (25/50/75/100% are a subset of SizeControl's default preset row), Height is new. */} setPropStyle('maxWidth', v)} /> {/* Height is only meaningful when there's no aspect-ratio crop -- once a ratio is set, Width + ratio + cover fully determine the box, so a separate Height control would only conflict/mislead (see applyAspectRatio, which clears any stale height at that moment). */} {!style.aspectRatio && ( setPropStyle('height', v)} /> )} {/* Crop & Framing -- aspect-ratio + object-fit + object-position on the itself is a CSS framing crop (no server-side image processing needed). */}
Object Fit setPropStyle('objectFit', v)} />
setPropStyle('objectPosition', v)} /> {/* Border Radius */}
Border Radius setPropStyle('borderRadius', v)} />
{/* Box model + animation/visibility rollout */} ); };