2023-06-01 18:28:22 +02:00
|
|
|
import React, { forwardRef } from 'react'
|
|
|
|
import { getId, getProps } from './utils.mjs'
|
|
|
|
|
2025-05-25 16:29:57 +02:00
|
|
|
/**
|
|
|
|
* A component to render an inner FreeSewing Part in a pattern (no group)
|
|
|
|
*
|
|
|
|
* @component
|
|
|
|
* @param {object} props - All component props
|
|
|
|
* @param {string} props.stackName - The name of the stack the part belongs to
|
|
|
|
* @param {string} props.partName - The name of the part
|
|
|
|
* @param {object} props.part - The part object itself
|
|
|
|
* @param {object} props.settings - The pattern settings object
|
|
|
|
* @param {object} props.components - An object holding the pattern compnents to use
|
|
|
|
* @param {object} props.strings - An object holding translations
|
|
|
|
* @param {object} props.drillProps - An object holding extra props to pass down (used in Xray mode)
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
*/
|
2023-06-01 18:28:22 +02:00
|
|
|
export const PartInner = forwardRef(
|
2025-04-18 06:22:16 +00:00
|
|
|
({ stackName, partName, part, settings, components, strings, drillProps }, ref) => {
|
2023-06-04 17:28:02 +02:00
|
|
|
const { Group, Path, Point, Snippet } = components
|
2023-06-01 18:28:22 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Group ref={ref} id={getId({ settings, stackName, partName, name: 'inner' })}>
|
|
|
|
{Object.keys(part.paths).map((pathName) => (
|
|
|
|
<Path
|
|
|
|
key={pathName}
|
|
|
|
path={part.paths[pathName]}
|
|
|
|
topLeft={part.topLeft}
|
|
|
|
bottomRight={part.bottomRight}
|
2023-06-06 11:17:14 -05:00
|
|
|
units={settings[0].units}
|
2025-04-18 06:22:16 +00:00
|
|
|
{...{ stackName, partName, pathName, part, settings, components, strings, drillProps }}
|
2023-06-01 18:28:22 +02:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{Object.keys(part.points).map((pointName) => (
|
|
|
|
<Point
|
|
|
|
key={pointName}
|
|
|
|
point={part.points[pointName]}
|
|
|
|
topLeft={part.topLeft}
|
|
|
|
bottomRight={part.bottomRight}
|
2025-04-18 06:22:16 +00:00
|
|
|
{...{ stackName, partName, pointName, part, settings, components, strings, drillProps }}
|
2023-06-01 18:28:22 +02:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
{Object.keys(part.snippets).map((snippetName) => (
|
|
|
|
<Snippet
|
|
|
|
key={snippetName}
|
|
|
|
snippet={part.snippets[snippetName]}
|
2025-04-18 06:22:16 +00:00
|
|
|
{...{
|
|
|
|
stackName,
|
|
|
|
partName,
|
|
|
|
snippetName,
|
|
|
|
part,
|
|
|
|
settings,
|
|
|
|
components,
|
|
|
|
strings,
|
|
|
|
drillProps,
|
|
|
|
}}
|
2023-06-01 18:28:22 +02:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Group>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-06-07 10:06:30 -05:00
|
|
|
PartInner.displayName = 'PartInner'
|
|
|
|
|
2025-05-25 16:29:57 +02:00
|
|
|
/**
|
|
|
|
* A component to render a FreeSewing Part (group) in a pattern
|
|
|
|
*
|
|
|
|
* @component
|
|
|
|
* @param {object} props - All component props
|
|
|
|
* @param {string} props.stackName - The name of the stack the part belongs to
|
|
|
|
* @param {string} props.partName - The name of the part
|
|
|
|
* @param {object} props.part - The part object itself
|
|
|
|
* @param {object} props.settings - The pattern settings object
|
|
|
|
* @param {object} props.components - An object holding the pattern compnents to use
|
|
|
|
* @param {object} props.strings - An object holding translations
|
|
|
|
* @param {object} props.drillProps - An object holding extra props to pass down (used in Xray mode)
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
*/
|
2025-04-18 06:22:16 +00:00
|
|
|
export const Part = ({ stackName, partName, part, settings, components, strings, drillProps }) => {
|
2023-06-01 18:28:22 +02:00
|
|
|
const { Group } = components
|
|
|
|
|
|
|
|
return (
|
2025-04-18 13:00:40 +00:00
|
|
|
<Group
|
|
|
|
{...getProps(part)}
|
|
|
|
id={getId({ settings, stackName, partName })}
|
|
|
|
transform={`translate(${-part.anchor.x}, ${-part.anchor.y})`}
|
|
|
|
>
|
2025-04-18 06:22:16 +00:00
|
|
|
<PartInner {...{ stackName, partName, part, settings, components, strings, drillProps }} />
|
2023-06-01 18:28:22 +02:00
|
|
|
</Group>
|
|
|
|
)
|
|
|
|
}
|