| 1 | import { NodeApi, PathApi } from "platejs"; |
| 2 | import { SlateElement, type SlateElementProps } from "platejs/static"; |
| 3 | |
| 4 | import { cn } from "@/lib/utils"; |
| 5 | import { type TSequenceArrowGroupElement } from "../../plugins/sequence-arrow-plugin"; |
| 6 | import { getAlignmentClasses } from "../../utils"; |
| 7 | |
| 8 | export function SequenceArrowItemStatic(props: SlateElementProps) { |
| 9 | const path = props.editor.api.findPath(props.element) ?? [-1]; |
| 10 | const parentPath = PathApi.parent(path); |
| 11 | const parent = NodeApi.get( |
| 12 | props.editor, |
| 13 | parentPath, |
| 14 | ) as TSequenceArrowGroupElement; |
| 15 | const index = (path?.at(-1) as number) ?? 0; |
| 16 | const total = parent?.children?.length ?? 0; |
| 17 | const isLast = index === total - 1; |
| 18 | |
| 19 | const { orientation = "vertical" } = parent; |
| 20 | const triangleColor = |
| 21 | (parent.color as string) || |
| 22 | "var(--presentation-card-background, var(--presentation-primary))"; |
| 23 | |
| 24 | return ( |
| 25 | <div |
| 26 | className={cn( |
| 27 | "relative h-full w-full flex-1", |
| 28 | orientation === "horizontal" && "flex items-stretch", |
| 29 | )} |
| 30 | style={{ pointerEvents: "none" }} |
| 31 | > |
| 32 | <div |
| 33 | className={cn( |
| 34 | "rounded-xl p-6 shadow-lg", |
| 35 | orientation === "horizontal" && "flex-1", |
| 36 | )} |
| 37 | data-bg-export="true" |
| 38 | style={{ |
| 39 | backgroundColor: triangleColor, |
| 40 | color: "var(--presentation-background)", |
| 41 | }} |
| 42 | > |
| 43 | <SlateElement |
| 44 | {...props} |
| 45 | className={cn(getAlignmentClasses(parent.alignment))} |
| 46 | > |
| 47 | {props.children} |
| 48 | </SlateElement> |
| 49 | </div> |
| 50 | |
| 51 | {!isLast && orientation === "vertical" && ( |
| 52 | <div |
| 53 | data-decor="true" |
| 54 | className={cn("mx-auto h-0 w-0")} |
| 55 | style={{ |
| 56 | borderLeft: "13px solid transparent", |
| 57 | borderRight: "13px solid transparent", |
| 58 | borderTop: `19px solid ${triangleColor}`, |
| 59 | filter: "drop-shadow(0 6px 8px rgba(0,0,0,0.08))", |
| 60 | }} |
| 61 | /> |
| 62 | )} |
| 63 | |
| 64 | {!isLast && orientation === "horizontal" && ( |
| 65 | <div |
| 66 | data-decor="true" |
| 67 | className={cn("my-auto h-0 w-0")} |
| 68 | style={{ |
| 69 | borderTop: "13px solid transparent", |
| 70 | borderBottom: "13px solid transparent", |
| 71 | borderLeft: `19px solid ${triangleColor}`, |
| 72 | filter: "drop-shadow(6px 0 8px rgba(0,0,0,0.08))", |
| 73 | }} |
| 74 | /> |
| 75 | )} |
| 76 | </div> |
| 77 | ); |
| 78 | } |
| 79 |