MCPcopy Create free account
hub / github.com/composify-js/composify / BlockItem

Function BlockItem

packages/react/src/editor/BlockItem/BlockItem.tsx:14–55  ·  view source on GitHub ↗
({ block }: Props)

Source from the content-addressed store, hash-verified

12};
13
14export const BlockItem = ({ block }: Props) => {
15 const propertySpecs = block.props ?? {};
16
17 const defaultProps = Object.entries(propertySpecs).reduce(
18 (acc, [key, value]) => {
19 if (value?.hasDefault) {
20 acc[key] = propertySpecs[key].type === 'node' ? Parser.parse(toJsxString(value.default)) : value.default;
21 }
22
23 return acc;
24 },
25 {} as Record<string, unknown>,
26 );
27
28 const children = [defaultProps.children].flat().filter((child) => typeof child !== 'undefined') as ReactNode;
29
30 const node = {
31 __composify__: true,
32 type: block.name,
33 props: defaultProps,
34 children,
35 } as Node;
36
37 const jsxProps = Object.entries(defaultProps)
38 .map(([key, value]) => `${key}={${JSON.stringify(value)}}`)
39 .join(' ');
40
41 return (
42 <div className={styles.container}>
43 <Draggable type={TargetType.Library} item={node}>
44 <div className={styles.preview}>
45 <ContentScaler width={1024} height={1024}>
46 <Renderer source={`<${block.name} ${jsxProps} />`} />
47 </ContentScaler>
48 </div>
49 </Draggable>
50 <Text size="xs" color="on-surface" className={styles.name}>
51 {block.name}
52 </Text>
53 </div>
54 );
55};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected