返回 presentation-ai
slope.tsx
1 "use client";
2
3 import { PlateElement, type PlateElementProps } from "platejs/react";
4
5 import { useForceUpdateChildrenOnLengthChange } from "@/hooks/presentation/useForceUpdateChildrenOnLengthChange";
6 import { cn } from "@/lib/utils";
7 import { type TSlopeGroupElement } from "../plugins/diagram-components-plugin";
8 import { getDiagramFitFrameStyle, useDiagramFitScale } from "./diagram-fit";
9
10 const SLOPE_LAYOUT_WIDTH_PX = 1024;
11 const SLOPE_MIN_LAYOUT_HEIGHT_PX = 455;
12
13 function getSlopeJustifyClass(alignment: TSlopeGroupElement["alignment"]) {
14 if (alignment === "left") return "justify-start";
15 if (alignment === "right") return "justify-end";
16 return "justify-center";
17 }
18
19 export default function Slope(props: PlateElementProps<TSlopeGroupElement>) {
20 const { alignment = "center" } = props.element;
21 const { containerRef, fitStyle, frameStyle, layoutRef } =
22 useDiagramFitScale<HTMLDivElement>(
23 SLOPE_LAYOUT_WIDTH_PX,
24 SLOPE_MIN_LAYOUT_HEIGHT_PX,
25 );
26
27 useForceUpdateChildrenOnLengthChange(props.editor, props.element);
28
29 return (
30 <PlateElement {...props} className="relative my-4">
31 <div ref={containerRef} className="w-full overflow-visible">
32 <div
33 style={{
34 ...frameStyle,
35 ...getDiagramFitFrameStyle(alignment),
36 }}
37 >
38 <div
39 ref={layoutRef}
40 className={cn(
41 "flex items-stretch gap-3 overflow-visible py-6",
42 "[&>div]:flex [&>div]:flex-col [&>div]:items-stretch",
43 getSlopeJustifyClass(alignment),
44 )}
45 style={fitStyle}
46 >
47 {props.children}
48 </div>
49 </div>
50 </div>
51 </PlateElement>
52 );
53 }
54
54 lines Plain Text