diff --git a/src/pages/editor/components/EditorSidebar.tsx b/src/pages/editor/components/EditorSidebar.tsx index c297fcb..8a80c79 100644 --- a/src/pages/editor/components/EditorSidebar.tsx +++ b/src/pages/editor/components/EditorSidebar.tsx @@ -15,30 +15,6 @@ const EditorSidebar = () => { setTool(selectedTool); }; - const handleImageUpload = (e: React.ChangeEvent) => { - const file = e.target.files?.[0]; - if (!file) return; - - const reader = new FileReader(); - reader.onload = (event) => { - const imageUrl = event.target?.result as string; - const img = new Image(); - img.onload = () => { - const newImage = { - id: `image-${Date.now()}`, - type: "image" as ToolType, - x: 100, - y: 100, - width: img.width, - height: img.height, - imageUrl, - }; - useEditorStore.getState().addObject(newImage); - }; - img.src = imageUrl; - }; - reader.readAsDataURL(file); - }; return ( <> @@ -72,7 +48,7 @@ const EditorSidebar = () => { onDelete={deleteObject} /> ) : ( - + )} diff --git a/src/pages/editor/components/sidebar/ObjectSettings.tsx b/src/pages/editor/components/sidebar/ObjectSettings.tsx index 8f2e6fe..03ad92e 100644 --- a/src/pages/editor/components/sidebar/ObjectSettings.tsx +++ b/src/pages/editor/components/sidebar/ObjectSettings.tsx @@ -8,6 +8,7 @@ import { LinkSettings, VideoSettings, TransformSettings, + GridSettings, } from "./settings"; type ObjectSettingsProps = { @@ -60,6 +61,10 @@ const ObjectSettings = ({ selectedObject, onUpdate, onDelete }: ObjectSettingsPr /> )} + {selectedObject.type === "grid" && ( + + )} + ); diff --git a/src/pages/editor/components/sidebar/ToolInstructions.tsx b/src/pages/editor/components/sidebar/ToolInstructions.tsx index e189f94..8b7203e 100644 --- a/src/pages/editor/components/sidebar/ToolInstructions.tsx +++ b/src/pages/editor/components/sidebar/ToolInstructions.tsx @@ -1,14 +1,53 @@ -import type { ToolType } from "../../store/editorStore"; -import { ImageUpload, DocumentUpload, VideoInput, LinkInput, SimpleInstruction } from "./instructions"; +import { useEditorStore, type ToolType } from "../../store/editorStore"; +import { + ImageUpload, + DocumentUpload, + VideoInput, + LinkInput, + SelectInstruction, + RectangleInstruction, + CircleInstruction, + TextInstruction, + LineInstruction, + ArrowInstruction, + StickerInstruction, + GridInstruction, +} from "./instructions"; type ToolInstructionsProps = { tool: ToolType; - onImageUpload: (e: React.ChangeEvent) => void; }; -const ToolInstructions = ({ tool, onImageUpload }: ToolInstructionsProps) => { +const ToolInstructions = ({ tool }: ToolInstructionsProps) => { + const { addObject } = useEditorStore(); + + const handleImageUpload = (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + if (file) { + const reader = new FileReader(); + reader.onload = (event) => { + const imageUrl = event.target?.result as string; + const img = new Image(); + img.onload = () => { + const newImage = { + id: `image-${Date.now()}`, + type: "image" as ToolType, + x: 100, + y: 100, + width: img.width, + height: img.height, + imageUrl, + }; + addObject(newImage); + }; + img.src = imageUrl; + }; + reader.readAsDataURL(file); + } + }; + if (tool === "image") { - return ; + return ; } if (tool === "document") { @@ -23,7 +62,18 @@ const ToolInstructions = ({ tool, onImageUpload }: ToolInstructionsProps) => { return ; } - return ; + const simpleInstructions: Partial> = { + select: , + rectangle: , + circle: , + text: , + line: , + arrow: , + sticker: , + grid: , + }; + + return simpleInstructions[tool] ?? null; }; export default ToolInstructions; diff --git a/src/pages/editor/components/sidebar/instructions/ArrowInstruction.tsx b/src/pages/editor/components/sidebar/instructions/ArrowInstruction.tsx new file mode 100644 index 0000000..0fc6188 --- /dev/null +++ b/src/pages/editor/components/sidebar/instructions/ArrowInstruction.tsx @@ -0,0 +1,9 @@ +const ArrowInstruction = () => ( +
+

برای رسم پیکان، روی کانوس کلیک کرده و بکشید

+
+); + +export default ArrowInstruction; + + diff --git a/src/pages/editor/components/sidebar/instructions/CircleInstruction.tsx b/src/pages/editor/components/sidebar/instructions/CircleInstruction.tsx new file mode 100644 index 0000000..53defc3 --- /dev/null +++ b/src/pages/editor/components/sidebar/instructions/CircleInstruction.tsx @@ -0,0 +1,9 @@ +const CircleInstruction = () => ( +
+

برای رسم دایره، روی کانوس کلیک کرده و بکشید

+
+); + +export default CircleInstruction; + + diff --git a/src/pages/editor/components/sidebar/instructions/GridInstruction.tsx b/src/pages/editor/components/sidebar/instructions/GridInstruction.tsx new file mode 100644 index 0000000..cde23d4 --- /dev/null +++ b/src/pages/editor/components/sidebar/instructions/GridInstruction.tsx @@ -0,0 +1,9 @@ +const GridInstruction = () => ( +
+

برای افزودن گرید، روی کانوس کلیک کنید

+
+); + +export default GridInstruction; + + diff --git a/src/pages/editor/components/sidebar/instructions/LineInstruction.tsx b/src/pages/editor/components/sidebar/instructions/LineInstruction.tsx new file mode 100644 index 0000000..efb1467 --- /dev/null +++ b/src/pages/editor/components/sidebar/instructions/LineInstruction.tsx @@ -0,0 +1,9 @@ +const LineInstruction = () => ( +
+

برای رسم خط، روی کانوس کلیک کرده و بکشید

+
+); + +export default LineInstruction; + + diff --git a/src/pages/editor/components/sidebar/instructions/RectangleInstruction.tsx b/src/pages/editor/components/sidebar/instructions/RectangleInstruction.tsx new file mode 100644 index 0000000..c0c908d --- /dev/null +++ b/src/pages/editor/components/sidebar/instructions/RectangleInstruction.tsx @@ -0,0 +1,9 @@ +const RectangleInstruction = () => ( +
+

برای رسم مستطیل، روی کانوس کلیک کرده و بکشید

+
+); + +export default RectangleInstruction; + + diff --git a/src/pages/editor/components/sidebar/instructions/SelectInstruction.tsx b/src/pages/editor/components/sidebar/instructions/SelectInstruction.tsx new file mode 100644 index 0000000..cd9b677 --- /dev/null +++ b/src/pages/editor/components/sidebar/instructions/SelectInstruction.tsx @@ -0,0 +1,9 @@ +const SelectInstruction = () => ( +
+

برای انتخاب و جابجایی اشیاء، روی آن‌ها کلیک کنید

+
+); + +export default SelectInstruction; + + diff --git a/src/pages/editor/components/sidebar/instructions/SimpleInstruction.tsx b/src/pages/editor/components/sidebar/instructions/SimpleInstruction.tsx deleted file mode 100644 index 77f9412..0000000 --- a/src/pages/editor/components/sidebar/instructions/SimpleInstruction.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import type { ToolType } from "../../../store/editorStore"; - -type SimpleInstructionProps = { - tool: ToolType; -}; - -const SimpleInstruction = ({ tool }: SimpleInstructionProps) => { - const instructions: Record = { - select: "برای انتخاب و جابجایی اشیاء، روی آن‌ها کلیک کنید", - rectangle: "برای رسم مستطیل، روی کانوس کلیک کرده و بکشید", - circle: "برای رسم دایره، روی کانوس کلیک کرده و بکشید", - text: "برای افزودن متن، روی کانوس کلیک کنید", - line: "برای رسم خط، روی کانوس کلیک کرده و بکشید", - arrow: "برای رسم پیکان، روی کانوس کلیک کرده و بکشید", - sticker: "برای افزودن استیکر، روی کانوس کلیک کنید", - grid: "برای افزودن گرید، روی کانوس کلیک کنید", - image: "", - document: "", - video: "", - link: "", - }; - - return ( -
-

{instructions[tool]}

-
- ); -}; - -export default SimpleInstruction; - diff --git a/src/pages/editor/components/sidebar/instructions/StickerInstruction.tsx b/src/pages/editor/components/sidebar/instructions/StickerInstruction.tsx new file mode 100644 index 0000000..cb82d74 --- /dev/null +++ b/src/pages/editor/components/sidebar/instructions/StickerInstruction.tsx @@ -0,0 +1,9 @@ +const StickerInstruction = () => ( +
+

برای افزودن استیکر، روی کانوس کلیک کنید

+
+); + +export default StickerInstruction; + + diff --git a/src/pages/editor/components/sidebar/instructions/TextInstruction.tsx b/src/pages/editor/components/sidebar/instructions/TextInstruction.tsx new file mode 100644 index 0000000..deb2e64 --- /dev/null +++ b/src/pages/editor/components/sidebar/instructions/TextInstruction.tsx @@ -0,0 +1,9 @@ +const TextInstruction = () => ( +
+

برای افزودن متن، روی کانوس کلیک کنید

+
+); + +export default TextInstruction; + + diff --git a/src/pages/editor/components/sidebar/instructions/index.ts b/src/pages/editor/components/sidebar/instructions/index.ts index 1f8814d..45f19db 100644 --- a/src/pages/editor/components/sidebar/instructions/index.ts +++ b/src/pages/editor/components/sidebar/instructions/index.ts @@ -2,5 +2,12 @@ export { default as ImageUpload } from "./ImageUpload"; export { default as DocumentUpload } from "./DocumentUpload"; export { default as VideoInput } from "./VideoInput"; export { default as LinkInput } from "./LinkInput"; -export { default as SimpleInstruction } from "./SimpleInstruction"; +export { default as SelectInstruction } from "./SelectInstruction"; +export { default as RectangleInstruction } from "./RectangleInstruction"; +export { default as CircleInstruction } from "./CircleInstruction"; +export { default as TextInstruction } from "./TextInstruction"; +export { default as LineInstruction } from "./LineInstruction"; +export { default as ArrowInstruction } from "./ArrowInstruction"; +export { default as StickerInstruction } from "./StickerInstruction"; +export { default as GridInstruction } from "./GridInstruction"; diff --git a/src/pages/editor/components/sidebar/settings/GridSettings.tsx b/src/pages/editor/components/sidebar/settings/GridSettings.tsx new file mode 100644 index 0000000..ca1f212 --- /dev/null +++ b/src/pages/editor/components/sidebar/settings/GridSettings.tsx @@ -0,0 +1,37 @@ +import type { EditorObject } from "../../../store/editorStore"; +import Input from "@/components/Input"; + +type GridSettingsProps = { + selectedObject: EditorObject; + onUpdate: (id: string, updates: Partial) => void; +}; + +const GridSettings = ({ selectedObject, onUpdate }: GridSettingsProps) => { + return ( + <> + + onUpdate(selectedObject.id, { + width: parseInt(e.target.value) || 200, + }) + } + /> + + onUpdate(selectedObject.id, { + height: parseInt(e.target.value) || 200, + }) + } + /> + + ); +}; + +export default GridSettings; + diff --git a/src/pages/editor/components/sidebar/settings/index.ts b/src/pages/editor/components/sidebar/settings/index.ts index 96f7f21..f578aab 100644 --- a/src/pages/editor/components/sidebar/settings/index.ts +++ b/src/pages/editor/components/sidebar/settings/index.ts @@ -5,4 +5,5 @@ export { default as SizeSettings } from "./SizeSettings"; export { default as LinkSettings } from "./LinkSettings"; export { default as VideoSettings } from "./VideoSettings"; export { default as TransformSettings } from "./TransformSettings"; +export { default as GridSettings } from "./GridSettings"; diff --git a/src/pages/editor/components/tools/types.ts b/src/pages/editor/components/tools/types.ts index 4701c09..05d1379 100644 --- a/src/pages/editor/components/tools/types.ts +++ b/src/pages/editor/components/tools/types.ts @@ -1,5 +1,5 @@ import Konva from "konva"; -import { EditorObject } from "../../store/editorStore"; +import type { EditorObject } from "../../store/editorStore"; export type ShapeProps = { obj: EditorObject;