2022-01-25 11:22:09 +01:00
|
|
|
import Path from '../path'
|
|
|
|
import Point from '../point'
|
|
|
|
import Snippet from '../snippet'
|
|
|
|
import { getProps } from '../utils'
|
|
|
|
|
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
|
2022-02-20 19:02:25 +01:00
|
|
|
const i = props.gist._state?.xray?.reveal
|
|
|
|
? 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 (
|
2022-01-28 19:55:32 +01:00
|
|
|
<g {...getProps(part)} id={`part-${partName}`}>
|
2022-01-25 11:22:09 +01:00
|
|
|
{grid}
|
2022-02-20 19:02:25 +01:00
|
|
|
{
|
|
|
|
props.gist?._state?.xray?.enabled &&
|
|
|
|
props.gist?._state?.xray?.reveal?.[partName]
|
|
|
|
&& <XrayPart {...props} />
|
|
|
|
}
|
2022-01-28 19:55:32 +01:00
|
|
|
{Object.keys(part.paths).map((pathName) => (
|
2022-01-25 11:22:09 +01:00
|
|
|
<Path
|
2022-01-30 15:14:44 +01:00
|
|
|
key={pathName}
|
2022-01-28 19:55:32 +01:00
|
|
|
pathName={pathName}
|
|
|
|
path={part.paths[pathName]}
|
2022-01-25 11:22:09 +01:00
|
|
|
topLeft={props.part.topLeft}
|
|
|
|
bottomRight={props.part.bottomRight}
|
2022-01-28 19:55:32 +01:00
|
|
|
{...props}
|
2022-01-25 11:22:09 +01:00
|
|
|
/>
|
|
|
|
))}
|
2022-01-30 15:14:44 +01:00
|
|
|
{Object.keys(props.part.points).map((pointName) => (
|
2022-01-25 11:22:09 +01:00
|
|
|
<Point
|
2022-01-30 15:14:44 +01:00
|
|
|
key={pointName}
|
|
|
|
pointName={pointName}
|
|
|
|
point={props.part.points[pointName]}
|
2022-01-25 11:22:09 +01:00
|
|
|
topLeft={props.part.topLeft}
|
|
|
|
bottomRight={props.part.bottomRight}
|
2022-01-28 19:55:32 +01:00
|
|
|
{...props}
|
2022-01-25 11:22:09 +01:00
|
|
|
/>
|
|
|
|
))}
|
2022-01-28 19:55:32 +01:00
|
|
|
{Object.keys(props.part.snippets).map((snippetName) => (
|
|
|
|
<Snippet
|
2022-01-30 15:14:44 +01:00
|
|
|
key={snippetName}
|
2022-01-28 19:55:32 +01:00
|
|
|
snippetName={snippetName}
|
|
|
|
snippet={props.part.snippets[snippetName]}
|
|
|
|
{...props}
|
|
|
|
/>
|
2022-01-25 11:22:09 +01:00
|
|
|
))}
|
|
|
|
{focus}
|
|
|
|
</g>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Part
|