mirror of
https://github.com/r2r90/canvas-label.git
synced 2025-12-18 12:35:49 +00:00
wip: editable text working
This commit is contained in:
@@ -5,14 +5,12 @@ import { useAppDispatch, useAppSelector } from "@/hooks";
|
|||||||
import {
|
import {
|
||||||
appSlice,
|
appSlice,
|
||||||
deselectItem,
|
deselectItem,
|
||||||
setStageScale,
|
|
||||||
StageItemType,
|
StageItemType,
|
||||||
updateImage,
|
updateImage,
|
||||||
updateText,
|
updateText,
|
||||||
} from "@/store/app.slice";
|
} from "@/store/app.slice";
|
||||||
import { useEffect, useState, type MouseEvent } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Toolbar } from "@/components/toolbar";
|
import { Toolbar } from "@/components/toolbar";
|
||||||
import type Konva from "konva";
|
|
||||||
import TransformableText from "@/components/transformable-text";
|
import TransformableText from "@/components/transformable-text";
|
||||||
|
|
||||||
const Canvas = () => {
|
const Canvas = () => {
|
||||||
@@ -56,41 +54,41 @@ const Canvas = () => {
|
|||||||
setSelected(!isEditing);
|
setSelected(!isEditing);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleTransforming() {
|
// function toggleTransforming() {
|
||||||
setIsTransforming(!isTransforming);
|
// setIsTransforming(!isTransforming);
|
||||||
setSelected(!isTransforming);
|
// setSelected(!isTransforming);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
const handleWheel = (e: Konva.KonvaEventObject<WheelEvent>) => {
|
// const handleWheel = (e: Konva.KonvaEventObject<WheelEvent>) => {
|
||||||
e.evt.preventDefault();
|
// e.evt.preventDefault();
|
||||||
|
//
|
||||||
const scaleBy = 1.02;
|
// const scaleBy = 1.02;
|
||||||
const targetStage = e.target.getStage()!;
|
// const targetStage = e.target.getStage()!;
|
||||||
const oldScale = targetStage.scaleX();
|
// const oldScale = targetStage.scaleX();
|
||||||
|
//
|
||||||
const mousePointTo = {
|
// const mousePointTo = {
|
||||||
x:
|
// x:
|
||||||
targetStage.getPointerPosition().x / oldScale -
|
// targetStage.getPointerPosition().x / oldScale -
|
||||||
targetStage.x() / oldScale,
|
// targetStage.x() / oldScale,
|
||||||
y:
|
// y:
|
||||||
targetStage.getPointerPosition().y / oldScale -
|
// targetStage.getPointerPosition().y / oldScale -
|
||||||
targetStage.y() / oldScale,
|
// targetStage.y() / oldScale,
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
const newScale = e.evt.deltaY < 0 ? oldScale * scaleBy : oldScale / scaleBy;
|
// const newScale = e.evt.deltaY < 0 ? oldScale * scaleBy : oldScale / scaleBy;
|
||||||
|
//
|
||||||
dispatch(
|
// dispatch(
|
||||||
setStageScale({
|
// setStageScale({
|
||||||
scale: newScale,
|
// scale: newScale,
|
||||||
x:
|
// x:
|
||||||
(targetStage.getPointerPosition().x / newScale - mousePointTo.x) *
|
// (targetStage.getPointerPosition().x / newScale - mousePointTo.x) *
|
||||||
newScale,
|
// newScale,
|
||||||
y:
|
// y:
|
||||||
(targetStage.getPointerPosition().y / newScale - mousePointTo.y) *
|
// (targetStage.getPointerPosition().y / newScale - mousePointTo.y) *
|
||||||
newScale,
|
// newScale,
|
||||||
}),
|
// }),
|
||||||
);
|
// );
|
||||||
};
|
// };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative flex h-full w-full flex-col items-center">
|
<div className="relative flex h-full w-full flex-col items-center">
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export function EditableTextInput({
|
|||||||
textAreaRef.current.scrollHeight + 3 + "px";
|
textAreaRef.current.scrollHeight + 3 + "px";
|
||||||
textAreaRef.current.focus();
|
textAreaRef.current.focus();
|
||||||
}
|
}
|
||||||
}, []);
|
}, [height]);
|
||||||
const style: CSSProperties = {
|
const style: CSSProperties = {
|
||||||
textAlign: align,
|
textAlign: align,
|
||||||
width: `${width}px`,
|
width: `${width}px`,
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export const TransformableImage = ({
|
|||||||
y: e.target.y(),
|
y: e.target.y(),
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onTransformEnd={(e) => {
|
onTransformEnd={() => {
|
||||||
const node = imageRef.current;
|
const node = imageRef.current;
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user