| 1 | "use client"; |
| 2 | |
| 3 | import { PlateElement, type StyledPlateElementProps } from "platejs/react"; |
| 4 | |
| 5 | import { ARROW_LIST, PYRAMID_GROUP, TIMELINE_GROUP } from "../../lib"; |
| 6 | import { type TArrowListElement } from "../../plugins/arrow-plugin"; |
| 7 | import { type TVisualizationListElement } from "../../plugins/legacy/visualization-list-plugin"; |
| 8 | import { type TPyramidGroupElement } from "../../plugins/pyramid-plugin"; |
| 9 | import { type TTimelineGroupElement } from "../../plugins/timeline-plugin"; |
| 10 | import ArrowList from "../arrow-list"; |
| 11 | import Pyramid from "../pyramid"; |
| 12 | import Timeline from "../timeline"; |
| 13 | |
| 14 | // Main visualization list component with withRef pattern |
| 15 | export const VisualizationListElement = ({ |
| 16 | element, |
| 17 | className, |
| 18 | ref, |
| 19 | ...props |
| 20 | }: StyledPlateElementProps<TVisualizationListElement>) => { |
| 21 | const { visualizationType, children } = element as TVisualizationListElement; |
| 22 | const renderer = () => { |
| 23 | switch (visualizationType) { |
| 24 | case "pyramid": |
| 25 | const pyramidElement = { |
| 26 | ...element, |
| 27 | children: element.children, |
| 28 | type: PYRAMID_GROUP, |
| 29 | }; |
| 30 | |
| 31 | return ( |
| 32 | <Pyramid |
| 33 | element={pyramidElement as unknown as TPyramidGroupElement} |
| 34 | className={className} |
| 35 | ref={ref} |
| 36 | {...props} |
| 37 | > |
| 38 | {props.children} |
| 39 | </Pyramid> |
| 40 | ); |
| 41 | case "arrow": |
| 42 | const arrowElement = { |
| 43 | ...element, |
| 44 | children: element.children, |
| 45 | type: ARROW_LIST, |
| 46 | }; |
| 47 | return ( |
| 48 | <ArrowList |
| 49 | element={arrowElement as unknown as TArrowListElement} |
| 50 | className={className} |
| 51 | ref={ref} |
| 52 | {...props} |
| 53 | > |
| 54 | {props.children} |
| 55 | </ArrowList> |
| 56 | ); |
| 57 | case "timeline": |
| 58 | const timelineElement = { |
| 59 | ...element, |
| 60 | children: element.children, |
| 61 | type: TIMELINE_GROUP, |
| 62 | orientation: "vertical", |
| 63 | sidedness: "single", |
| 64 | }; |
| 65 | |
| 66 | return ( |
| 67 | <Timeline |
| 68 | element={timelineElement as unknown as TTimelineGroupElement} |
| 69 | className={className} |
| 70 | ref={ref} |
| 71 | {...props} |
| 72 | > |
| 73 | {children} |
| 74 | </Timeline> |
| 75 | ); |
| 76 | default: |
| 77 | return <div>{props.children}</div>; |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | return ( |
| 82 | <PlateElement element={element} className={className} ref={ref} {...props}> |
| 83 | {renderer()} |
| 84 | </PlateElement> |
| 85 | ); |
| 86 | }; |
| 87 |