Compare commits
3 Commits
f2a083f022
...
26047df3c8
| Author | SHA1 | Date | |
|---|---|---|---|
| 26047df3c8 | |||
|
|
12936ec1f9 | ||
|
|
1bb92a975e |
@ -6,29 +6,19 @@ import { contextMenuListState, contextMenuState } from '@/store/contextMenu'
|
|||||||
import { useTempGrid } from '@/hooks/useTempGrid'
|
import { useTempGrid } from '@/hooks/useTempGrid'
|
||||||
import { useContextMenu } from '@/hooks/useContextMenu'
|
import { useContextMenu } from '@/hooks/useContextMenu'
|
||||||
import { useEvent } from '@/hooks/useEvent'
|
import { useEvent } from '@/hooks/useEvent'
|
||||||
import { canvasState } from '@/store/canvasAtom'
|
import { canvasState, currentObjectState } from '@/store/canvasAtom'
|
||||||
|
|
||||||
export default function QContextMenu(props) {
|
export default function QContextMenu(props) {
|
||||||
const canvas = useRecoilValue(canvasState)
|
const canvas = useRecoilValue(canvasState)
|
||||||
const { contextRef, canvasProps } = props
|
const { contextRef, canvasProps } = props
|
||||||
const [contextMenu, setContextMenu] = useRecoilState(contextMenuState)
|
const [contextMenu, setContextMenu] = useRecoilState(contextMenuState)
|
||||||
const contextMenuList = useRecoilValue(contextMenuListState)
|
const contextMenuList = useRecoilValue(contextMenuListState)
|
||||||
const activeObject = canvasProps?.getActiveObject() //액티브된 객체를 가져옴
|
const currentObject = useRecoilValue(currentObjectState)
|
||||||
const { tempGridMode, setTempGridMode } = useTempGrid()
|
const { tempGridMode, setTempGridMode } = useTempGrid()
|
||||||
const { handleKeyup } = useContextMenu()
|
const { handleKeyup } = useContextMenu()
|
||||||
const { addDocumentEventListener, removeDocumentEvent } = useEvent()
|
const { addDocumentEventListener, removeDocumentEvent } = useEvent()
|
||||||
// const { addDocumentEventListener, removeDocumentEvent } = useContext(EventContext)
|
// const { addDocumentEventListener, removeDocumentEvent } = useContext(EventContext)
|
||||||
|
|
||||||
let contextType = ''
|
|
||||||
|
|
||||||
if (activeObject) {
|
|
||||||
if (activeObject.initOptions && activeObject.initOptions.name) {
|
|
||||||
//이건 바뀔 가능성이 있음
|
|
||||||
if (activeObject.initOptions?.name?.indexOf('guide') > -1) {
|
|
||||||
contextType = 'surface' //면형상
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const getYPosition = (e) => {
|
const getYPosition = (e) => {
|
||||||
const contextLength = contextMenuList.reduce((acc, cur, index) => {
|
const contextLength = contextMenuList.reduce((acc, cur, index) => {
|
||||||
return acc + cur.length
|
return acc + cur.length
|
||||||
@ -36,11 +26,13 @@ export default function QContextMenu(props) {
|
|||||||
return e?.clientY - (contextLength * 25 + contextMenuList.length * 2 * 17)
|
return e?.clientY - (contextLength * 25 + contextMenuList.length * 2 * 17)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
const handleContextMenu = (e) => {
|
||||||
if (!contextRef.current) return
|
// e.preventDefault() //기존 contextmenu 막고
|
||||||
|
|
||||||
|
if (currentObject) {
|
||||||
|
const isArray = currentObject.hasOwnProperty('arrayData')
|
||||||
|
if (isArray && currentObject.arrayData.length === 0) return
|
||||||
|
|
||||||
const handleContextMenu = (e) => {
|
|
||||||
e.preventDefault() //기존 contextmenu 막고
|
|
||||||
if (tempGridMode) return
|
if (tempGridMode) return
|
||||||
const position = {
|
const position = {
|
||||||
x: window.innerWidth / 2 < e.pageX ? e.pageX - 240 : e.pageX,
|
x: window.innerWidth / 2 < e.pageX ? e.pageX - 240 : e.pageX,
|
||||||
@ -48,21 +40,24 @@ export default function QContextMenu(props) {
|
|||||||
}
|
}
|
||||||
setContextMenu({ visible: true, ...position, currentMousePos: canvasProps.getPointer(e) })
|
setContextMenu({ visible: true, ...position, currentMousePos: canvasProps.getPointer(e) })
|
||||||
addDocumentEventListener('keyup', document, handleKeyup)
|
addDocumentEventListener('keyup', document, handleKeyup)
|
||||||
canvasProps?.upperCanvasEl.removeEventListener('contextmenu', handleContextMenu) //한번 노출 후 이벤트 삭제
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleClick = (e) => {
|
const handleClick = (e) => {
|
||||||
// e.preventDefault()
|
// e.preventDefault()
|
||||||
|
setContextMenu({ ...contextMenu, visible: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOutsideClick = (e) => {
|
||||||
|
// e.preventDefault()
|
||||||
|
if (contextMenu.visible) {
|
||||||
setContextMenu({ ...contextMenu, visible: false })
|
setContextMenu({ ...contextMenu, visible: false })
|
||||||
|
removeDocumentEvent('keyup')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleOutsideClick = (e) => {
|
useEffect(() => {
|
||||||
// e.preventDefault()
|
if (!contextRef.current) return
|
||||||
if (contextMenu.visible) {
|
|
||||||
setContextMenu({ ...contextMenu, visible: false })
|
|
||||||
removeDocumentEvent('keyup')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
canvasProps?.upperCanvasEl.addEventListener('contextmenu', handleContextMenu)
|
canvasProps?.upperCanvasEl.addEventListener('contextmenu', handleContextMenu)
|
||||||
document.addEventListener('click', handleClick)
|
document.addEventListener('click', handleClick)
|
||||||
@ -72,43 +67,9 @@ export default function QContextMenu(props) {
|
|||||||
removeDocumentEvent('keyup')
|
removeDocumentEvent('keyup')
|
||||||
document.removeEventListener('click', handleClick)
|
document.removeEventListener('click', handleClick)
|
||||||
document.removeEventListener('click', handleOutsideClick)
|
document.removeEventListener('click', handleOutsideClick)
|
||||||
|
canvasProps?.upperCanvasEl.removeEventListener('contextmenu', handleContextMenu) //한번 노출 후 이벤트 삭제
|
||||||
}
|
}
|
||||||
}, [contextRef, contextMenuList])
|
}, [contextRef, contextMenuList, currentObject])
|
||||||
|
|
||||||
const handleObjectMove = () => {
|
|
||||||
activeObject.set({
|
|
||||||
lockMovementX: false, // X 축 이동 잠금
|
|
||||||
lockMovementY: false, // Y 축 이동 잠금
|
|
||||||
})
|
|
||||||
|
|
||||||
canvasProps?.on('object:modified', function (e) {
|
|
||||||
activeObject.set({
|
|
||||||
lockMovementX: true, // X 축 이동 잠금
|
|
||||||
lockMovementY: true, // Y 축 이동 잠금
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleObjectDelete = () => {
|
|
||||||
if (confirm('삭제하실거?')) {
|
|
||||||
canvasProps.remove(activeObject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleObjectCopy = () => {
|
|
||||||
activeObject.clone((cloned) => {
|
|
||||||
cloned.set({
|
|
||||||
left: activeObject.left + activeObject.width + 20,
|
|
||||||
initOptions: { ...activeObject.initOptions },
|
|
||||||
lockMovementX: true, // X 축 이동 잠금
|
|
||||||
lockMovementY: true, // Y 축 이동 잠금
|
|
||||||
lockRotation: true, // 회전 잠금
|
|
||||||
lockScalingX: true, // X 축 크기 조정 잠금
|
|
||||||
lockScalingY: true, // Y 축 크기 조정 잠금
|
|
||||||
})
|
|
||||||
canvasProps?.add(cloned)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import { useCanvasSetting } from '@/hooks/option/useCanvasSetting'
|
|||||||
import { useCanvasMenu } from '@/hooks/common/useCanvasMenu'
|
import { useCanvasMenu } from '@/hooks/common/useCanvasMenu'
|
||||||
import { useEvent } from '@/hooks/useEvent'
|
import { useEvent } from '@/hooks/useEvent'
|
||||||
import { compasDegAtom } from '@/store/orientationAtom'
|
import { compasDegAtom } from '@/store/orientationAtom'
|
||||||
|
import { hotkeyStore } from '@/store/hotkeyAtom'
|
||||||
|
|
||||||
export default function CanvasFrame() {
|
export default function CanvasFrame() {
|
||||||
const canvasRef = useRef(null)
|
const canvasRef = useRef(null)
|
||||||
@ -110,6 +111,38 @@ export default function CanvasFrame() {
|
|||||||
resetPcsCheckState()
|
resetPcsCheckState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 캔버스가 있을 경우 핫키 이벤트 처리
|
||||||
|
* hotkeyStore에 핫키 이벤트 리스너 추가
|
||||||
|
*
|
||||||
|
* const hotkeys = [
|
||||||
|
{ key: 'c', fn: () => asdf() },
|
||||||
|
{ key: 'v', fn: () => qwer() },
|
||||||
|
]
|
||||||
|
setHotkeyStore(hotkeys)
|
||||||
|
*/
|
||||||
|
const [hotkeyState, setHotkeyState] = useRecoilState(hotkeyStore)
|
||||||
|
const hotkeyHandlerRef = useRef(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
hotkeyHandlerRef.current = (e) => {
|
||||||
|
hotkeyState.forEach((hotkey) => {
|
||||||
|
if (e.key === hotkey.key) {
|
||||||
|
hotkey.fn()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('keyup', hotkeyHandlerRef.current)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (hotkeyHandlerRef.current) {
|
||||||
|
document.removeEventListener('keyup', hotkeyHandlerRef.current)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [hotkeyState])
|
||||||
|
/** 핫키 이벤트 처리 끝 */
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="canvas-frame">
|
<div className="canvas-frame">
|
||||||
<canvas ref={canvasRef} id="canvas" style={{ position: 'relative' }}></canvas>
|
<canvas ref={canvasRef} id="canvas" style={{ position: 'relative' }}></canvas>
|
||||||
|
|||||||
@ -1,35 +0,0 @@
|
|||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { useRecoilValue, useSetRecoilState } from 'recoil'
|
|
||||||
import { moduleSelectionDataState, selectedModuleState } from '@/store/selectedModuleOptions'
|
|
||||||
import { useMasterController } from '@/hooks/common/useMasterController'
|
|
||||||
import { canvasSettingState, canvasState, currentCanvasPlanState, moduleSetupSurfaceState } from '@/store/canvasAtom'
|
|
||||||
import { POLYGON_TYPE, BATCH_TYPE } from '@/common/common'
|
|
||||||
import { useRoofFn } from '@/hooks/common/useRoofFn'
|
|
||||||
import { roofDisplaySelector } from '@/store/settingAtom'
|
|
||||||
import offsetPolygon from '@/util/qpolygon-utils'
|
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
|
||||||
import { QPolygon } from '@/components/fabric/QPolygon'
|
|
||||||
import { useEvent } from '@/hooks/useEvent'
|
|
||||||
import { useSwal } from '@/hooks/useSwal'
|
|
||||||
import { useMessage } from '@/hooks/useMessage'
|
|
||||||
|
|
||||||
export function useModulePlace() {
|
|
||||||
const canvas = useRecoilValue(canvasState)
|
|
||||||
const moduleSelectionData = useRecoilValue(moduleSelectionDataState)
|
|
||||||
const [trestleDetailParams, setTrestleDetailParams] = useState([])
|
|
||||||
const [trestleDetailList, setTrestleDetailList] = useState([])
|
|
||||||
const selectedModules = useRecoilValue(selectedModuleState)
|
|
||||||
const { getTrestleDetailList } = useMasterController()
|
|
||||||
const canvasSetting = useRecoilValue(canvasSettingState)
|
|
||||||
const { setSurfaceShapePattern } = useRoofFn()
|
|
||||||
const roofDisplay = useRecoilValue(roofDisplaySelector)
|
|
||||||
const { addTargetMouseEventListener } = useEvent()
|
|
||||||
const setModuleSetupSurface = useSetRecoilState(moduleSetupSurfaceState)
|
|
||||||
const [saleStoreNorthFlg, setSaleStoreNorthFlg] = useState(false)
|
|
||||||
const { swalFire } = useSwal()
|
|
||||||
const { getMessage } = useMessage()
|
|
||||||
|
|
||||||
return {
|
|
||||||
selectedModules,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -81,9 +81,9 @@ export function useContextMenu() {
|
|||||||
switch (selectedMenu) {
|
switch (selectedMenu) {
|
||||||
case 'outline':
|
case 'outline':
|
||||||
break
|
break
|
||||||
default:
|
// default:
|
||||||
setContextMenu([])
|
// setContextMenu([])
|
||||||
break
|
// break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
src/store/hotkeyAtom.js
Normal file
6
src/store/hotkeyAtom.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { atom } from 'recoil'
|
||||||
|
|
||||||
|
export const hotkeyStore = atom({
|
||||||
|
key: 'hotkeyState',
|
||||||
|
default: [],
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user