返回 presentation-ai
visualization-list-static.tsx
根目录 / src / components / notebook / presentation / editor / custom-elements / legacy / visualization-list-static.tsx
1 import { type TElement } from "platejs";
2 import { SlateElement, type SlateElementProps } from "platejs/static";
3
4 import { ARROW_LIST, PYRAMID_GROUP, TIMELINE_GROUP } from "../../lib";
5 import { type TArrowListElement } from "../../plugins/arrow-plugin";
6 import { type TTimelineGroupElement } from "../../plugins/timeline-plugin";
7 import ArrowListStatic from "../static/arrow-list-static";
8 import PyramidStatic from "../static/pyramid-static";
9 import TimelineStatic from "../static/timeline-static";
10
11 export default function VisualizationListElementStatic(
12 props: SlateElementProps,
13 ) {
14 const { element, className, children, ...rest } = props;
15 const visualizationType = element.visualizationType as
16 | "arrow"
17 | "pyramid"
18 | "timeline";
19
20 const renderer = () => {
21 switch (visualizationType) {
22 case "pyramid": {
23 const pyramidElement = {
24 ...element,
25 children: element.children,
26 type: PYRAMID_GROUP,
27 };
28
29 return (
30 <PyramidStatic
31 element={pyramidElement as TElement}
32 className={className}
33 {...rest}
34 >
35 {children}
36 </PyramidStatic>
37 );
38 }
39 case "arrow": {
40 const arrowElement = {
41 ...element,
42 children: element.children,
43 type: ARROW_LIST,
44 };
45 return (
46 <ArrowListStatic
47 element={arrowElement as TArrowListElement}
48 className={className}
49 {...rest}
50 >
51 {children}
52 </ArrowListStatic>
53 );
54 }
55 case "timeline": {
56 const timelineElement = {
57 ...element,
58 children: element.children,
59 type: TIMELINE_GROUP,
60 orientation: "vertical",
61 sidedness: "single",
62 };
63
64 return (
65 <TimelineStatic
66 element={timelineElement as TTimelineGroupElement}
67 className={className}
68 {...rest}
69 >
70 {children}
71 </TimelineStatic>
72 );
73 }
74 default:
75 return <div>{children}</div>;
76 }
77 };
78
79 return (
80 <SlateElement element={element} className={className} {...rest}>
81 {renderer()}
82 </SlateElement>
83 );
84 }
85
85 lines Plain Text