import Select from "@/components/Select"; import Input from "@/components/Input"; import type { EditorObject } from "../../../store/editorStore"; import { useEditorStore } from "../../../store/editorStore"; import { ENTRANCE_ANIMATION_SELECT_ITEMS } from "../constants/entranceAnimationOptions"; import { DEFAULT_ENTRANCE_DURATION_MS, DEFAULT_ENTRANCE_DELAY_MS, MAX_ENTRANCE_DELAY_MS, } from "@/shared/entranceAnimation"; type Props = { selectedObject: EditorObject; onUpdate: (id: string, updates: Partial) => void; }; /** اعضای گروه (نه خود باکس group) برای تنظیم انیمیشن ورود */ function getAnimationTargets( selectedObject: EditorObject, objects: EditorObject[], ): EditorObject[] { if (selectedObject.type === "group") { return objects.filter( (o) => o.groupId === selectedObject.id && o.type !== "group", ); } return [selectedObject]; } const EntranceAnimationSettings = ({ selectedObject, onUpdate }: Props) => { const objects = useEditorStore((s) => s.objects); const targets = getAnimationTargets(selectedObject, objects); const primary = targets[0] ?? selectedObject; const anim = primary.entranceAnimation ?? "none"; const duration = primary.entranceDurationMs ?? DEFAULT_ENTRANCE_DURATION_MS; const delayMs = primary.entranceDelayMs ?? DEFAULT_ENTRANCE_DELAY_MS; const applyToTargets = (updates: Partial) => { const ids = targets.length > 0 ? targets.map((t) => t.id) : [selectedObject.id]; ids.forEach((id) => onUpdate(id, updates)); }; return (
{ const n = parseInt(e.target.value, 10); if (Number.isNaN(n)) return; applyToTargets({ entranceDurationMs: Math.min(4000, Math.max(100, n)), }); }} /> { const n = parseInt(e.target.value, 10); if (Number.isNaN(n)) return; const clamped = Math.min(MAX_ENTRANCE_DELAY_MS, Math.max(0, n)); applyToTargets({ entranceDelayMs: clamped === 0 ? undefined : clamped, }); }} /> )}
); }; export default EntranceAnimationSettings;