-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
모바일 환경에서 더보기 버튼을 통한 노드.간선 편집 #199
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
53b02c9
feat: 터치디바이스 여부 확인 로직
CatyJazzy e5c540e
feat: 모바일환경에서 더보기 버튼 클릭 시 context-menu 표시
CatyJazzy a5a50d7
feat: 더보기 버튼 클릭 시 clientX, clientY값 정의하여 전달
CatyJazzy d252475
Merge branch 'dev' into feat/mobile-spaceEdit
CatyJazzy b0f53ec
feat: 간선 삭제 버튼 스타일 수정
CatyJazzy 7e47a0a
feat: 삭제 버튼 터치 핸들러 연결
CatyJazzy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,15 @@ import { Circle, Group, KonvaNodeEvents, Text } from "react-konva"; | |
import { useNavigate } from "react-router-dom"; | ||
|
||
import Konva from "konva"; | ||
import { | ||
KonvaEventObject, | ||
Node as KonvaNode, | ||
NodeConfig, | ||
} from "konva/lib/Node"; | ||
import { Vector2d } from "konva/lib/types"; | ||
|
||
const RADIUS = 64; | ||
const MORE_BUTTON_RADIUS = 12; | ||
|
||
type NodeProps = { | ||
id: string; | ||
|
@@ -72,6 +78,7 @@ Node.Text = function NodeText({ | |
fontSize, | ||
fontStyle, | ||
width, | ||
...rest | ||
}: NodeTextProps) { | ||
const ref = useRef<Konva.Text>(null); | ||
const [offset, setOffset] = useState<Konva.Vector2d | undefined>(undefined); | ||
|
@@ -95,10 +102,76 @@ Node.Text = function NodeText({ | |
align="center" | ||
wrap="none" | ||
ellipsis | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
type NodeMoreButtonProps = { | ||
onTap?: | ||
| ((evt: KonvaEventObject<PointerEvent, KonvaNode<NodeConfig>>) => void) | ||
| undefined; | ||
content: string; | ||
}; | ||
|
||
Node.MoreButton = function NodeMoreButton({ content }: NodeMoreButtonProps) { | ||
const [isTouch, setIsTouch] = useState(false); | ||
|
||
useEffect(() => { | ||
setIsTouch("ontouchstart" in window || navigator.maxTouchPoints > 0); | ||
}, []); | ||
|
||
if (!isTouch) return null; | ||
|
||
const handleTap = (e: KonvaEventObject<Event>) => { | ||
e.cancelBubble = true; | ||
|
||
const parentNode = e.target.findAncestor("Group").findAncestor("Group"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 Konva event에는 findAncestor로 부모 노드를 찾을 수 있군요 ㅎㅎ |
||
|
||
if (!parentNode) return; | ||
|
||
const absolutePosition = parentNode.getAbsolutePosition(); | ||
|
||
const contextMenuEvent = new MouseEvent("contextmenu", { | ||
button: 2, | ||
buttons: 2, | ||
clientX: absolutePosition.x, | ||
clientY: absolutePosition.y, | ||
bubbles: true, | ||
}); | ||
|
||
parentNode.fire("contextmenu", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fire를 활용하셨군요..! 가장 깔끔한 방법인 것 같아요 |
||
evt: contextMenuEvent, | ||
target: parentNode, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Group x={RADIUS - 20} y={-RADIUS + 20} onTap={handleTap}> | ||
<Circle | ||
x={0} | ||
y={0} | ||
radius={MORE_BUTTON_RADIUS} | ||
fill="#FFFFFF" | ||
stroke="#DED8D3" | ||
strokeWidth={1.5} | ||
/> | ||
<Text | ||
x={0} | ||
y={1} | ||
fontSize={16} | ||
text={content} | ||
align="center" | ||
verticalAlign="middle" | ||
width={MORE_BUTTON_RADIUS * 2} | ||
height={MORE_BUTTON_RADIUS * 2} | ||
offsetX={MORE_BUTTON_RADIUS} | ||
offsetY={MORE_BUTTON_RADIUS} | ||
/> | ||
</Group> | ||
); | ||
}; | ||
|
||
export type HeadNodeProps = { | ||
id: string; | ||
name: string; | ||
|
@@ -126,7 +199,15 @@ export type NoteNodeProps = { | |
name: string; | ||
} & NodeHandlers; | ||
|
||
export function NoteNode({ id, x, y, name, src, ...rest }: NoteNodeProps) { | ||
export function NoteNode({ | ||
id, | ||
x, | ||
y, | ||
name, | ||
src, | ||
onContextMenu, | ||
...rest | ||
}: NoteNodeProps) { | ||
// TODO: src 적용 필요 | ||
const navigate = useNavigate(); | ||
return ( | ||
|
@@ -139,10 +220,12 @@ export function NoteNode({ id, x, y, name, src, ...rest }: NoteNodeProps) { | |
navigate(`/note/${src}`); | ||
} | ||
}} | ||
onContextMenu={onContextMenu} | ||
{...rest} | ||
> | ||
<Node.Circle radius={RADIUS} fill="#FAF9F7" stroke="#DED8D3" /> | ||
<Node.Text width={RADIUS * 2} fontSize={16} content={name} /> | ||
<Node.MoreButton onTap={onContextMenu} content="⋮" /> | ||
</Node> | ||
); | ||
} | ||
|
@@ -161,6 +244,7 @@ export function SubspaceNode({ | |
y, | ||
name, | ||
src, | ||
onContextMenu, | ||
...rest | ||
}: SubspaceNodeProps) { | ||
const navigate = useNavigate(); | ||
|
@@ -171,10 +255,17 @@ export function SubspaceNode({ | |
x={x} | ||
y={y} | ||
onClick={() => navigate(`/space/${src}`)} | ||
onContextMenu={onContextMenu} | ||
{...rest} | ||
> | ||
<Node.Circle radius={RADIUS} fill="#FFF4BB" stroke="#F9D46B" /> | ||
<Node.Text width={RADIUS * 2} fontSize={16} fontStyle="700" content={name} /> | ||
<Node.Text | ||
width={RADIUS * 2} | ||
fontSize={16} | ||
fontStyle="700" | ||
content={name} | ||
/> | ||
<Node.MoreButton onTap={onContextMenu} content="⋮" /> | ||
</Node> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Touch screen인지 확인할 수 있는 방법이군요! 좋은 것 알아갑니다 👍