fix big on transform

This commit is contained in:
Steve Ruiz 2021-06-29 17:04:45 +01:00
parent 84949fffe6
commit a6b8c23fce
3 changed files with 18 additions and 25 deletions

View file

@ -1,4 +1,4 @@
import React, { useRef, memo, useEffect, useState } from 'react' import React, { useRef, memo, useEffect } from 'react'
import state, { useSelector } from 'state' import state, { useSelector } from 'state'
import styled from 'styles' import styled from 'styles'
import { getShapeUtils } from 'state/shape-utils' import { getShapeUtils } from 'state/shape-utils'
@ -14,12 +14,6 @@ interface ShapeProps {
isSelecting: boolean isSelecting: boolean
} }
function ShapeGuard(props: ShapeProps): JSX.Element {
const hasShape = useMissingShapeTest(props.id)
if (!hasShape) return null
return <Shape {...props} />
}
function Shape({ id, isSelecting }: ShapeProps): JSX.Element { function Shape({ id, isSelecting }: ShapeProps): JSX.Element {
const rGroup = useRef<SVGGElement>(null) const rGroup = useRef<SVGGElement>(null)
@ -97,6 +91,21 @@ function Shape({ id, isSelecting }: ShapeProps): JSX.Element {
) )
} }
function ShapeGuard(props: ShapeProps): JSX.Element {
const hasShape = useSelector(
(s) => tld.getShape(s.data, props.id) !== undefined
)
if (!hasShape) {
console.warn('missing shape!')
return null
}
return <Shape {...props} />
}
export default memo(ShapeGuard)
interface RealShapeProps { interface RealShapeProps {
id: string id: string
isParent: boolean isParent: boolean
@ -197,19 +206,3 @@ const EventSoak = styled('use', {
const StyledGroup = styled('g', { const StyledGroup = styled('g', {
outline: 'none', outline: 'none',
}) })
export default memo(ShapeGuard)
function useMissingShapeTest(id: string) {
const [isShape, setIsShape] = useState(true)
useEffect(() => {
return state.onUpdate((s) => {
if (isShape && !tld.getShape(s.data, id)) {
setIsShape(false)
}
})
}, [isShape, id])
return isShape
}

View file

@ -69,7 +69,7 @@ export default class TransformSession extends BaseSession {
transformOrigin, transformOrigin,
}) })
shapes[id] = { ...shape } shapes[id] = deepClone(shape)
} }
tld.updateParents(data, Object.keys(shapeBounds)) tld.updateParents(data, Object.keys(shapeBounds))

View file

@ -53,7 +53,7 @@ export default class TransformSingleSession extends BaseSession {
transformOrigin: [0.5, 0.5], transformOrigin: [0.5, 0.5],
}) })
data.document.pages[data.currentPageId].shapes[shape.id] = { ...shape } data.document.pages[data.currentPageId].shapes[shape.id] = deepClone(shape)
tld.updateParents(data, [id]) tld.updateParents(data, [id])
} }