返回 presentation-ai
bullet-item-static.tsx
根目录 / src / components / notebook / presentation / editor / custom-elements / static / bullet-item-static.tsx
1 import { NodeApi, PathApi } from "platejs";
2 import { SlateElement, type SlateElementProps } from "platejs/static";
3
4 import { cn } from "@/lib/utils";
5 import {
6 type TBulletGroupElement,
7 type TBulletItemElement,
8 } from "../../plugins/bullet-plugin";
9 import { getAlignmentClasses } from "../../utils";
10 import { ArrowMarker } from "../bullet-item";
11 import {
12 bulletItemVariants,
13 bulletMarkerVariants,
14 } from "../bullet-item";
15 import { PresentationIcon } from "../presentation-icon";
16
17 export function BulletItemStatic(props: SlateElementProps<TBulletItemElement>) {
18 const path = props.editor.api.findPath(props.element) ?? [-1];
19 const parentPath = PathApi.parent(path);
20 const parentElement = NodeApi.get(
21 props.editor,
22 parentPath,
23 ) as TBulletGroupElement;
24
25 const bulletType = parentElement?.bulletType ?? "numbered";
26 const index = path.at(-1) as number;
27
28 // Get alignment - use item alignment if set, otherwise inherit from parent
29 const itemAlignment = props.element.alignment;
30 const parentAlignment = parentElement?.alignment;
31 const alignment = itemAlignment ?? parentAlignment ?? "left";
32 const { icon } = props.element;
33 const markerColor =
34 (parentElement?.color as string) || "var(--presentation-primary)";
35
36 return (
37 <SlateElement {...props}>
38 <div className={cn("group/bullet-item relative")}>
39 {/* The bullet item layout with numbered block and content */}
40 <div
41 className={cn(
42 bulletItemVariants({ bulletType }),
43 "gap-3",
44 alignment === "right" && "flex-row-reverse",
45 )}
46 >
47 {/* Bullet marker - numbered, basic dot, or arrow */}
48 <div
49 data-decor="true"
50 className={bulletMarkerVariants({ bulletType })}
51 style={{
52 backgroundColor:
53 bulletType === "numbered" ? markerColor : "transparent",
54 borderColor: "transparent",
55 color:
56 bulletType === "numbered"
57 ? "var(--presentation-background)"
58 : markerColor,
59 }}
60 >
61 {icon ? (
62 <PresentationIcon icon={icon} size={20} />
63 ) : bulletType === "numbered" ? (
64 index + 1
65 ) : bulletType === "arrow" ? (
66 <ArrowMarker color={markerColor} />
67 ) : (
68 <span
69 className="size-2 rounded-full"
70 style={{ backgroundColor: markerColor }}
71 />
72 )}
73 </div>
74
75 <div className={cn("flex-1", getAlignmentClasses(alignment))}>
76 {props.children}
77 </div>
78 </div>
79 </div>
80 </SlateElement>
81 );
82 }
83
83 lines Plain Text