返回 presentation-ai
sequence-arrow-item.tsx
根目录 / src / components / notebook / presentation / editor / custom-elements / sequence-arrow-item.tsx
1 "use client";
2
3 import { NodeApi, PathApi } from "platejs";
4 import { PlateElement, type PlateElementProps } from "platejs/react";
5
6 import { cn } from "@/lib/utils";
7 import { type TSequenceArrowGroupElement } from "../plugins/sequence-arrow-plugin";
8 import { getAlignmentClasses } from "../utils";
9 import { getPresentationAccentColor } from "./color-utils";
10 import { getSiblingIndexContext } from "./sibling-index";
11
12 export const SequenceArrowItem = (props: PlateElementProps) => {
13 const { index, parentElement } =
14 getSiblingIndexContext<TSequenceArrowGroupElement>(
15 props.editor,
16 props.element,
17 props.path,
18 );
19 const fallbackParentPath = PathApi.parent(props.path);
20 const fallbackParentElement = NodeApi.get(
21 props.editor,
22 fallbackParentPath,
23 ) as TSequenceArrowGroupElement | undefined;
24 const resolvedParentElement = parentElement ?? fallbackParentElement;
25 const total = resolvedParentElement?.children?.length ?? 0;
26 const isLast = index === total - 1;
27
28 const { orientation = "vertical" } = resolvedParentElement ?? {};
29 const triangleColor = getPresentationAccentColor(
30 props.element,
31 resolvedParentElement,
32 "var(--presentation-card-background, var(--presentation-primary))",
33 );
34 return (
35 <PlateElement
36 {...props}
37 className={cn(
38 "relative h-full w-full flex-1",
39 orientation === "horizontal" && "flex items-stretch",
40 )}
41 style={{ pointerEvents: "none" }}
42 >
43 <div
44 className={cn(
45 "grid w-full rounded-xl p-6 shadow-lg",
46 orientation === "horizontal" && "flex-1",
47 )}
48 data-bg-export="true"
49 style={{
50 backgroundColor: triangleColor,
51 color: "var(--presentation-background)",
52 }}
53 >
54 <div
55 className={cn(getAlignmentClasses(resolvedParentElement?.alignment))}
56 >
57 {props.children}
58 </div>
59 </div>
60
61 {!isLast && orientation === "vertical" && (
62 <div
63 data-decor="true"
64 className={cn("mx-auto h-0 w-0")}
65 style={{
66 borderLeft: "13px solid transparent",
67 borderRight: "13px solid transparent",
68 borderTop: `19px solid ${triangleColor}`,
69 filter: "drop-shadow(0 6px 8px rgba(0,0,0,0.08))",
70 }}
71 />
72 )}
73
74 {!isLast && orientation === "horizontal" && (
75 <div
76 data-decor="true"
77 className={cn("my-auto h-0 w-0")}
78 style={{
79 borderTop: "13px solid transparent",
80 borderBottom: "13px solid transparent",
81 borderLeft: `19px solid ${triangleColor}`,
82 filter: "drop-shadow(6px 0 8px rgba(0,0,0,0.08))",
83 }}
84 />
85 )}
86 </PlateElement>
87 );
88 };
89
89 lines Plain Text