fix: resolve type errors in selection/crop/transform tools

This commit is contained in:
SnapOtter
2026-05-06 23:37:31 +08:00
parent 0f42ceca83
commit f0941e4aec
11 changed files with 65 additions and 45 deletions
@@ -30,9 +30,9 @@ export function CanvasResizeDialog({ open, onClose }: { open: boolean; onClose:
const [fill, setFill] = useState("#ffffff");
const handleApply = useCallback(() => {
resizeCanvas(width, height, anchor, fill);
resizeCanvas(width, height, anchor);
onClose();
}, [width, height, anchor, fill, resizeCanvas, onClose]);
}, [width, height, anchor, resizeCanvas, onClose]);
if (!open) return null;
@@ -73,7 +73,8 @@ export function ContextMenu({
const cutObjects = useEditorStore((s) => s.cutObjects);
const pasteObjects = useEditorStore((s) => s.pasteObjects);
const removeObjects = useEditorStore((s) => s.removeObjects);
const duplicateObjects = useEditorStore((s) => s.duplicateObjects);
const copyObjectsFn = useEditorStore((s) => s.copyObjects);
const pasteObjectsFn = useEditorStore((s) => s.pasteObjects);
const bringToFront = useEditorStore((s) => s.bringToFront);
const bringForward = useEditorStore((s) => s.bringForward);
const sendBackward = useEditorStore((s) => s.sendBackward);
@@ -106,7 +107,7 @@ export function ContextMenu({
icon: Scissors,
shortcut: "Ctrl+X",
action: () => {
cutObjects(selectedObjectIds);
cutObjects();
onClose();
},
},
@@ -115,7 +116,7 @@ export function ContextMenu({
icon: Copy,
shortcut: "Ctrl+C",
action: () => {
copyObjects(selectedObjectIds);
copyObjects();
onClose();
},
},
@@ -127,14 +128,15 @@ export function ContextMenu({
pasteObjects();
onClose();
},
disabled: clipboard.length === 0,
disabled: !clipboard || clipboard.length === 0,
},
{
label: "Duplicate",
icon: CopyPlus,
shortcut: "Ctrl+D",
action: () => {
duplicateObjects(selectedObjectIds);
copyObjectsFn();
pasteObjectsFn();
onClose();
},
dividerAfter: true,
@@ -192,7 +194,7 @@ export function ContextMenu({
pasteObjects();
onClose();
},
disabled: clipboard.length === 0,
disabled: !clipboard || clipboard.length === 0,
},
{
label: "Select All",
@@ -12,7 +12,7 @@ const GUIDE_WIDTH = 1;
export function GuideLines() {
const guides = useEditorStore((s) => s.guides);
const showGuides = useEditorStore((s) => s.showGuides);
const showGuides = useEditorStore((s) => s.guidesVisible);
const canvasSize = useEditorStore((s) => s.canvasSize);
const updateGuide = useEditorStore((s) => s.updateGuide);
const removeGuide = useEditorStore((s) => s.removeGuide);
@@ -2,7 +2,8 @@ import { Lock, Unlock, X } from "lucide-react";
import { useCallback, useEffect, useState } from "react";
import { cn } from "@/lib/utils";
import { useEditorStore } from "@/stores/editor-store";
import type { ResampleMethod } from "@/types/editor";
type ResampleMethod = "nearest" | "bilinear" | "bicubic" | "lanczos";
// ---------------------------------------------------------------------------
// ImageResizeDialog -- modal with W/H, aspect lock, resampling method
@@ -34,7 +34,7 @@ export function HorizontalRuler() {
const zoom = useEditorStore((s) => s.zoom);
const panOffset = useEditorStore((s) => s.panOffset);
const canvasSize = useEditorStore((s) => s.canvasSize);
const showRulers = useEditorStore((s) => s.showRulers);
const showRulers = useEditorStore((s) => s.rulersVisible);
const addGuide = useEditorStore((s) => s.addGuide);
const draw = useCallback(() => {
@@ -146,7 +146,7 @@ export function VerticalRuler() {
const zoom = useEditorStore((s) => s.zoom);
const panOffset = useEditorStore((s) => s.panOffset);
const canvasSize = useEditorStore((s) => s.canvasSize);
const showRulers = useEditorStore((s) => s.showRulers);
const showRulers = useEditorStore((s) => s.rulersVisible);
const addGuide = useEditorStore((s) => s.addGuide);
const draw = useCallback(() => {
@@ -1,6 +1,10 @@
import { Group, Line } from "react-konva";
import { useEditorStore } from "@/stores/editor-store";
import type { SmartGuide } from "@/types/editor";
export interface SmartGuide {
orientation: "horizontal" | "vertical";
position: number;
type: "edge" | "center" | "canvas";
}
// ---------------------------------------------------------------------------
// Smart guide calculation utilities (exported for testing)
@@ -156,7 +160,7 @@ export function snapToGuides(
// SmartGuidesOverlay -- renders temporary guide lines during drag
// ---------------------------------------------------------------------------
const GUIDE_COLORS = {
const GUIDE_COLORS: Record<SmartGuide["type"], string> = {
edge: "#f43f5e",
center: "#8b5cf6",
canvas: "#22c55e",