1
0
Fork 0
freesewing/sites/shared/components/workbench/draft/part/index.js

115 lines
2.8 KiB
JavaScript
Raw Normal View History

import React from 'react'
2022-01-25 11:22:09 +01:00
import Path from '../path'
import Point from '../point'
import Snippet from '../snippet'
import { getProps } from '../utils'
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error) {
console.log(error)
return { hasError: true }
}
componentDidCatch(error, errorInfo) {
console.log(error, errorInfo)
}
render() {
if (this.state.hasError) {
console.log('in error boundary', props)
return <text>Something went wrong.</text>
}
return this.props.children
}
}
2022-01-30 12:21:08 +01:00
const XrayPart = props => {
// Don't bother if this is the only part on display
if (props.gist.only && props.gist.only.length === 1) return null
const i = props.gist._state?.xray?.reveal
2022-03-13 08:48:21 +01:00
? Object.keys(props.gist._state.xray.reveal).indexOf(props.partName)%10
2022-02-12 15:23:37 +01:00
: 0
2022-01-30 12:21:08 +01:00
const { topLeft, bottomRight } = props.part
return (
<g>
<path d={`
M ${topLeft.x} ${topLeft.y}
L ${topLeft.x} ${bottomRight.y}
L ${bottomRight.x} ${bottomRight.y}
L ${bottomRight.x} ${topLeft.y}
z`} className={`fill-color-${i} opacity-10`} />
</g>
)
}
2022-01-28 19:55:32 +01:00
const Part = props => {
const { partName, part, app, gist, updateGist } = props
2022-01-30 12:21:08 +01:00
const grid = gist.paperless ? (
2022-01-25 11:22:09 +01:00
<rect
2022-01-28 19:55:32 +01:00
x={part.topLeft.x}
y={part.topLeft.y}
width={part.width}
height={part.height}
2022-01-25 11:22:09 +01:00
className="grid"
2022-01-28 19:55:32 +01:00
fill={'url(#grid-' + partName + ')'}
2022-01-25 11:22:09 +01:00
/>
) : null
return (
<g {...getProps(part)} id={`part-${partName}`}>
{grid}
{
props.gist?._state?.xray?.enabled &&
props.gist?._state?.xray?.reveal?.[partName]
&& <XrayPart {...props} />
}
{Object.keys(part.paths).map((pathName) => (
<Path
key={pathName}
pathName={pathName}
path={part.paths[pathName]}
topLeft={props.part.topLeft}
bottomRight={props.part.bottomRight}
{...props}
/>
))}
{Object.keys(props.part.points).map((pointName) => (
<Point
key={pointName}
pointName={pointName}
point={props.part.points[pointName]}
topLeft={props.part.topLeft}
bottomRight={props.part.bottomRight}
{...props}
/>
))}
{Object.keys(props.part.snippets).map((snippetName) => (
<Snippet
key={snippetName}
snippetName={snippetName}
snippet={props.part.snippets[snippetName]}
{...props}
/>
))}
{focus}
</g>
2022-01-25 11:22:09 +01:00
)
}
/*
<ErrorBoundary
x={part.topLeft.x}
y={part.topLeft.y}
width={part.width}
height={part.height}
>
</ErrorBoundary>
*/
2022-01-25 11:22:09 +01:00
export default Part