This commit is contained in:
@@ -97,7 +97,7 @@ const LayersList = () => {
|
|||||||
case 'video':
|
case 'video':
|
||||||
return 'ویدیو'
|
return 'ویدیو'
|
||||||
case 'audio':
|
case 'audio':
|
||||||
return 'صدا'
|
return obj.audioName || 'صدا'
|
||||||
case 'document':
|
case 'document':
|
||||||
return 'سند'
|
return 'سند'
|
||||||
case 'arrow':
|
case 'arrow':
|
||||||
|
|||||||
@@ -224,7 +224,12 @@ const ObjectRenderer = ({
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "audio":
|
case "audio":
|
||||||
shapeElement = <AudioShape key={obj.id} {...commonProps} />;
|
shapeElement = (
|
||||||
|
<AudioShape
|
||||||
|
key={`${obj.id}-${obj.audioName ?? ""}`}
|
||||||
|
{...commonProps}
|
||||||
|
/>
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "document":
|
case "document":
|
||||||
shapeElement = <ImageObject key={obj.id} {...commonProps} />;
|
shapeElement = <ImageObject key={obj.id} {...commonProps} />;
|
||||||
|
|||||||
@@ -4,16 +4,21 @@ import { useSingleUpload } from "@/pages/uploader/hooks/useUploaderData";
|
|||||||
import { CloseCircle, Music } from "iconsax-react";
|
import { CloseCircle, Music } from "iconsax-react";
|
||||||
import { useDropzone } from "react-dropzone";
|
import { useDropzone } from "react-dropzone";
|
||||||
import AudioUploadZone from "@/components/AudioUploadZone";
|
import AudioUploadZone from "@/components/AudioUploadZone";
|
||||||
|
import Input from "@/components/Input";
|
||||||
|
|
||||||
|
const getAudioNameFromFile = (file: File) =>
|
||||||
|
file.name.replace(/\.[^/.]+$/, "");
|
||||||
|
|
||||||
export const AUDIO_ACCEPT = {
|
export const AUDIO_ACCEPT = {
|
||||||
"audio/*": [".mp3", ".wav", ".ogg", ".m4a", ".aac", ".flac", ".webm"],
|
"audio/*": [".mp3", ".wav", ".ogg", ".m4a", ".aac", ".flac", ".webm"],
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const AudioInput: FC = () => {
|
const AudioInput: FC = () => {
|
||||||
const { objects, addObject, setSelectedObjectId, setTool, deleteObject } =
|
const { objects, addObject, setSelectedObjectId, setTool, deleteObject, updateObject } =
|
||||||
useEditorStore();
|
useEditorStore();
|
||||||
const { mutateAsync: uploadFile } = useSingleUpload();
|
const { mutateAsync: uploadFile } = useSingleUpload();
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
const [isUploading, setIsUploading] = useState(false);
|
||||||
|
const [audioName, setAudioName] = useState("");
|
||||||
|
|
||||||
const onDrop = useCallback(
|
const onDrop = useCallback(
|
||||||
async (acceptedFiles: File[]) => {
|
async (acceptedFiles: File[]) => {
|
||||||
@@ -35,6 +40,7 @@ const AudioInput: FC = () => {
|
|||||||
width: 320,
|
width: 320,
|
||||||
height: 56,
|
height: 56,
|
||||||
audioUrl,
|
audioUrl,
|
||||||
|
audioName: audioName.trim() || getAudioNameFromFile(file),
|
||||||
};
|
};
|
||||||
addObject(newAudio);
|
addObject(newAudio);
|
||||||
setSelectedObjectId(newAudio.id);
|
setSelectedObjectId(newAudio.id);
|
||||||
@@ -43,11 +49,12 @@ const AudioInput: FC = () => {
|
|||||||
// TODO: show error toast
|
// TODO: show error toast
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setAudioName("");
|
||||||
} finally {
|
} finally {
|
||||||
setIsUploading(false);
|
setIsUploading(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[addObject, setSelectedObjectId, setTool, uploadFile]
|
[addObject, audioName, setSelectedObjectId, setTool, uploadFile]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { getRootProps, getInputProps } = useDropzone({
|
const { getRootProps, getInputProps } = useDropzone({
|
||||||
@@ -69,6 +76,13 @@ const AudioInput: FC = () => {
|
|||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="text-base font-bold">صدا</div>
|
<div className="text-base font-bold">صدا</div>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
label="نام فایل صوتی"
|
||||||
|
value={audioName}
|
||||||
|
onChange={(e) => setAudioName(e.target.value)}
|
||||||
|
placeholder="مثلاً موسیقی پسزمینه"
|
||||||
|
/>
|
||||||
|
|
||||||
<AudioUploadZone
|
<AudioUploadZone
|
||||||
getRootProps={getRootProps}
|
getRootProps={getRootProps}
|
||||||
getInputProps={getInputProps}
|
getInputProps={getInputProps}
|
||||||
@@ -85,9 +99,16 @@ const AudioInput: FC = () => {
|
|||||||
className="relative flex items-center gap-2 rounded-lg border border-border bg-gray-50 px-3 py-2"
|
className="relative flex items-center gap-2 rounded-lg border border-border bg-gray-50 px-3 py-2"
|
||||||
>
|
>
|
||||||
<Music size={20} color="#8C90A3" variant="Bold" />
|
<Music size={20} color="#8C90A3" variant="Bold" />
|
||||||
<span className="flex-1 truncate text-xs text-description">
|
<input
|
||||||
فایل صوتی
|
className="flex-1 h-7 rounded-lg border border-border bg-white px-2 text-xs text-black outline-none"
|
||||||
</span>
|
value={audioObject.audioName || ""}
|
||||||
|
onChange={(e) =>
|
||||||
|
updateObject(audioObject.id, {
|
||||||
|
audioName: e.target.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
placeholder="نام فایل صوتی"
|
||||||
|
/>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleDeleteAudio(audioObject.id)}
|
onClick={() => handleDeleteAudio(audioObject.id)}
|
||||||
className="absolute -right-1 -top-2 shadow-md bg-white size-5 rounded-full flex justify-center items-center hover:bg-gray-100 transition-colors"
|
className="absolute -right-1 -top-2 shadow-md bg-white size-5 rounded-full flex justify-center items-center hover:bg-gray-100 transition-colors"
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ type AudioSettingsProps = {
|
|||||||
const AudioSettings = ({ selectedObject, onUpdate }: AudioSettingsProps) => {
|
const AudioSettings = ({ selectedObject, onUpdate }: AudioSettingsProps) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<Input
|
||||||
|
label="نام فایل صوتی"
|
||||||
|
value={selectedObject.audioName || ""}
|
||||||
|
onChange={(e) => onUpdate(selectedObject.id, { audioName: e.target.value })}
|
||||||
|
placeholder="مثلاً موسیقی پسزمینه"
|
||||||
|
/>
|
||||||
<Input
|
<Input
|
||||||
label="آدرس فایل صوتی"
|
label="آدرس فایل صوتی"
|
||||||
value={selectedObject.audioUrl || ""}
|
value={selectedObject.audioUrl || ""}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useRef } from "react";
|
import { useEffect, useMemo, useRef } from "react";
|
||||||
import { Rect, Group, Circle, Text as KonvaText } from "react-konva";
|
import { Rect, Group, Circle, Text as KonvaText } from "react-konva";
|
||||||
import Konva from "konva";
|
import Konva from "konva";
|
||||||
import type { ShapeProps } from "./types";
|
import type { ShapeProps } from "./types";
|
||||||
@@ -11,12 +11,25 @@ const AudioShape = ({
|
|||||||
draggable,
|
draggable,
|
||||||
}: ShapeProps) => {
|
}: ShapeProps) => {
|
||||||
const groupRef = useRef<Konva.Group>(null);
|
const groupRef = useRef<Konva.Group>(null);
|
||||||
|
const labelRef = useRef<Konva.Text>(null);
|
||||||
|
|
||||||
const containerWidth = obj.width || 320;
|
const containerWidth = obj.width || 320;
|
||||||
const containerHeight = obj.height || 56;
|
const containerHeight = obj.height || 56;
|
||||||
const barY = containerHeight * 0.55;
|
const barY = containerHeight * 0.55;
|
||||||
const barHeight = Math.max(4, containerHeight * 0.12);
|
const barHeight = Math.max(4, containerHeight * 0.12);
|
||||||
const playRadius = Math.min(18, containerHeight * 0.35);
|
const playRadius = Math.min(18, containerHeight * 0.35);
|
||||||
|
const labelWidth = Math.max(0, containerWidth - playRadius * 2 - 44);
|
||||||
|
const displayName = useMemo(
|
||||||
|
() => obj.audioName?.trim() || "فایل صوتی",
|
||||||
|
[obj.audioName],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const labelNode = labelRef.current;
|
||||||
|
if (!labelNode) return;
|
||||||
|
labelNode.text(displayName);
|
||||||
|
labelNode.getLayer()?.batchDraw();
|
||||||
|
}, [displayName]);
|
||||||
|
|
||||||
const handleGroupClick = (e?: Konva.KonvaEventObject<MouseEvent>) => {
|
const handleGroupClick = (e?: Konva.KonvaEventObject<MouseEvent>) => {
|
||||||
if (e) {
|
if (e) {
|
||||||
@@ -103,13 +116,17 @@ const AudioShape = ({
|
|||||||
listening={false}
|
listening={false}
|
||||||
/>
|
/>
|
||||||
<KonvaText
|
<KonvaText
|
||||||
|
ref={labelRef}
|
||||||
|
key={displayName}
|
||||||
x={playRadius * 2 + 28}
|
x={playRadius * 2 + 28}
|
||||||
y={containerHeight * 0.18}
|
y={containerHeight * 0.18}
|
||||||
text="فایل صوتی (پیشنمایش)"
|
text={displayName}
|
||||||
fontSize={11}
|
fontSize={11}
|
||||||
fill="#6b7280"
|
fill="#6b7280"
|
||||||
fontFamily="Arial"
|
fontFamily="Arial"
|
||||||
listening={false}
|
listening={false}
|
||||||
|
width={labelWidth}
|
||||||
|
ellipsis={true}
|
||||||
/>
|
/>
|
||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ export type EditorObject = {
|
|||||||
imageUrl?: string;
|
imageUrl?: string;
|
||||||
videoUrl?: string;
|
videoUrl?: string;
|
||||||
audioUrl?: string;
|
audioUrl?: string;
|
||||||
|
/** نام نمایشی فایل صوتی؛ فقط در ادیتور استفاده میشود */
|
||||||
|
audioName?: string;
|
||||||
linkUrl?: string;
|
linkUrl?: string;
|
||||||
rotation?: number;
|
rotation?: number;
|
||||||
scaleX?: number;
|
scaleX?: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user