返回 presentation-ai
visualization-item.tsx
根目录 / src / components / notebook / presentation / editor / custom-elements / legacy / visualization-item.tsx
1 // Main visualization item component with withRef pattern
2 "use client";
3
4 import { NodeApi, PathApi } from "platejs";
5 import { type StyledPlateElementProps } from "platejs/react";
6
7 import { cn } from "@/lib/utils";
8 import { ARROW_LIST_ITEM, PYRAMID_ITEM, TIMELINE_ITEM } from "../../lib";
9 import { type TArrowListItemElement } from "../../plugins/arrow-plugin";
10 import { type TVisualizationListElement } from "../../plugins/legacy/visualization-list-plugin";
11 import { type TPyramidItemElement } from "../../plugins/pyramid-plugin";
12 import { ArrowItem } from "../arrow-item";
13 import { PyramidItem } from "../pyramid-item";
14 import { TimelineItem } from "../timeline-item";
15
16 export const VisualizationItemElement = ({
17 element,
18 children,
19 className,
20 ref,
21 ...props
22 }: StyledPlateElementProps<TVisualizationListElement>) => {
23 const parentPath = PathApi.parent(props.path);
24 const parentElement = NodeApi.get(
25 props.editor,
26 parentPath,
27 ) as TVisualizationListElement;
28
29 const visualizationType = parentElement.visualizationType as
30 | "arrow"
31 | "pyramid"
32 | "timeline";
33
34 switch (visualizationType) {
35 case "pyramid":
36 const pyramidItemElement = {
37 ...element,
38 children: element.children,
39 type: PYRAMID_ITEM,
40 };
41
42 return (
43 <PyramidItem
44 ref={ref}
45 element={pyramidItemElement as TPyramidItemElement}
46 className={cn(className)}
47 {...props}
48 >
49 {children}
50 </PyramidItem>
51 );
52
53 case "arrow":
54 const arrowItemElement = {
55 ...element,
56 children: element.children,
57 type: ARROW_LIST_ITEM,
58 };
59
60 return (
61 <ArrowItem
62 ref={ref}
63 element={arrowItemElement as TArrowListItemElement}
64 {...props}
65 >
66 {children}
67 </ArrowItem>
68 );
69
70 case "timeline":
71 const timelineItemElement = {
72 ...element,
73 children: element.children,
74 type: TIMELINE_ITEM,
75 };
76
77 return (
78 <TimelineItem ref={ref} element={timelineItemElement} {...props}>
79 {children}
80 </TimelineItem>
81 );
82 }
83 };
84
84 lines Plain Text