canvas => recoil로 수정
This commit is contained in:
parent
353aa4be9b
commit
4fe2de627d
@ -4,7 +4,7 @@ import { fabric } from 'fabric'
|
|||||||
import { actionHandler, anchorWrapper, polygonPositionHandler } from '@/util/canvas-util'
|
import { actionHandler, anchorWrapper, polygonPositionHandler } from '@/util/canvas-util'
|
||||||
|
|
||||||
import { useRecoilState } from 'recoil'
|
import { useRecoilState } from 'recoil'
|
||||||
import { canvasSizeState, fontSizeState } from '@/store/canvasAtom'
|
import { canvasSizeState, canvasState, fontSizeState } from '@/store/canvasAtom'
|
||||||
import { QLine } from '@/components/fabric/QLine'
|
import { QLine } from '@/components/fabric/QLine'
|
||||||
import { QPolygon } from '@/components/fabric/QPolygon'
|
import { QPolygon } from '@/components/fabric/QPolygon'
|
||||||
import { defineQLine } from '@/util/qline-utils'
|
import { defineQLine } from '@/util/qline-utils'
|
||||||
@ -14,7 +14,7 @@ import { useCanvasEvent } from '@/hooks/useCanvasEvent'
|
|||||||
import { post } from '@/lib/Axios'
|
import { post } from '@/lib/Axios'
|
||||||
|
|
||||||
export function useCanvas(id) {
|
export function useCanvas(id) {
|
||||||
const [canvas, setCanvas] = useState()
|
const [canvas, setCanvas] = useRecoilState(canvasState)
|
||||||
const [isLocked, setIsLocked] = useState(false)
|
const [isLocked, setIsLocked] = useState(false)
|
||||||
const [history, setHistory] = useState([])
|
const [history, setHistory] = useState([])
|
||||||
const [backImg, setBackImg] = useState()
|
const [backImg, setBackImg] = useState()
|
||||||
|
|||||||
@ -14,25 +14,26 @@ import { useRecoilState, useRecoilValue } from 'recoil'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
canvasSizeState,
|
canvasSizeState,
|
||||||
|
canvasState,
|
||||||
compassState,
|
compassState,
|
||||||
drewRoofCellsState,
|
drewRoofCellsState,
|
||||||
fontSizeState,
|
fontSizeState,
|
||||||
|
guideLineState,
|
||||||
|
horiGuideLinesState,
|
||||||
modeState,
|
modeState,
|
||||||
|
objectPlacementModeState,
|
||||||
roofPolygonArrayState,
|
roofPolygonArrayState,
|
||||||
roofPolygonPatternArrayState,
|
roofPolygonPatternArrayState,
|
||||||
roofState,
|
roofState,
|
||||||
sortedPolygonArray,
|
sortedPolygonArray,
|
||||||
templateTypeState,
|
templateTypeState,
|
||||||
wallState,
|
|
||||||
guideLineState,
|
|
||||||
horiGuideLinesState,
|
|
||||||
vertGuideLinesState,
|
vertGuideLinesState,
|
||||||
objectPlacementModeState,
|
wallState,
|
||||||
} from '@/store/canvasAtom'
|
} from '@/store/canvasAtom'
|
||||||
import { QLine } from '@/components/fabric/QLine'
|
import { QLine } from '@/components/fabric/QLine'
|
||||||
import { fabric } from 'fabric'
|
import { fabric } from 'fabric'
|
||||||
import { QPolygon } from '@/components/fabric/QPolygon'
|
import { QPolygon } from '@/components/fabric/QPolygon'
|
||||||
import offsetPolygon, { inPolygon } from '@/util/qpolygon-utils'
|
import offsetPolygon from '@/util/qpolygon-utils'
|
||||||
import { isObjectNotEmpty } from '@/util/common-utils'
|
import { isObjectNotEmpty } from '@/util/common-utils'
|
||||||
import * as turf from '@turf/turf'
|
import * as turf from '@turf/turf'
|
||||||
import { INPUT_TYPE, Mode } from '@/common/common'
|
import { INPUT_TYPE, Mode } from '@/common/common'
|
||||||
@ -43,7 +44,7 @@ export function useMode() {
|
|||||||
const historyPoints = useRef([])
|
const historyPoints = useRef([])
|
||||||
const historyLines = useRef([])
|
const historyLines = useRef([])
|
||||||
const startPoint = useRef()
|
const startPoint = useRef()
|
||||||
const [canvas, setCanvas] = useState(null)
|
const [canvas, setCanvas] = useRecoilState(canvasState)
|
||||||
const [zoom, setZoom] = useState(100)
|
const [zoom, setZoom] = useState(100)
|
||||||
const [fontSize] = useRecoilState(fontSizeState)
|
const [fontSize] = useRecoilState(fontSizeState)
|
||||||
const [sortedArray, setSortedArray] = useRecoilState(sortedPolygonArray)
|
const [sortedArray, setSortedArray] = useRecoilState(sortedPolygonArray)
|
||||||
@ -83,7 +84,6 @@ export function useMode() {
|
|||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
if (!canvas) return
|
if (!canvas) return
|
||||||
setCanvas(canvas)
|
|
||||||
canvas?.off('mouse:out', removeMouseLines)
|
canvas?.off('mouse:out', removeMouseLines)
|
||||||
canvas?.on('mouse:out', removeMouseLines)
|
canvas?.on('mouse:out', removeMouseLines)
|
||||||
canvas?.off('mouse:move')
|
canvas?.off('mouse:move')
|
||||||
@ -685,7 +685,6 @@ export function useMode() {
|
|||||||
mouseAndkeyboardEventClear()
|
mouseAndkeyboardEventClear()
|
||||||
addCommonMouseEvent()
|
addCommonMouseEvent()
|
||||||
setMode(mode)
|
setMode(mode)
|
||||||
setCanvas(canvas)
|
|
||||||
|
|
||||||
// mode별 이벤트 변경
|
// mode별 이벤트 변경
|
||||||
|
|
||||||
@ -5119,7 +5118,6 @@ export function useMode() {
|
|||||||
mode,
|
mode,
|
||||||
setMode,
|
setMode,
|
||||||
changeMode,
|
changeMode,
|
||||||
setCanvas,
|
|
||||||
handleClear,
|
handleClear,
|
||||||
zoomIn,
|
zoomIn,
|
||||||
zoomOut,
|
zoomOut,
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
import { atom } from 'recoil'
|
import { atom } from 'recoil'
|
||||||
|
|
||||||
|
export const canvasState = atom({
|
||||||
|
key: 'canvasState',
|
||||||
|
default: null,
|
||||||
|
dangerouslyAllowMutability: true,
|
||||||
|
})
|
||||||
|
|
||||||
export const textState = atom({
|
export const textState = atom({
|
||||||
key: 'textState',
|
key: 'textState',
|
||||||
default: 'test text',
|
default: 'test text',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user