返回 presentation-ai
slope-static.tsx
1 "use client";
2
3 import { SlateElement, type SlateElementProps } from "platejs/static";
4
5 import { cn } from "@/lib/utils";
6 import { getDiagramFitFrameStyle, useDiagramFitScale } from "../diagram-fit";
7 import {
8 getStaticDiagramJustifyClass,
9 type StaticDiagramElement,
10 } from "./diagram-static-utils";
11
12 const SLOPE_LAYOUT_WIDTH_PX = 1024;
13 const SLOPE_MIN_LAYOUT_HEIGHT_PX = 455;
14
15 export default function SlopeStatic(props: SlateElementProps) {
16 const element = props.element as StaticDiagramElement;
17 const { containerRef, fitStyle, frameStyle, layoutRef } =
18 useDiagramFitScale<HTMLDivElement>(
19 SLOPE_LAYOUT_WIDTH_PX,
20 SLOPE_MIN_LAYOUT_HEIGHT_PX,
21 );
22
23 return (
24 <SlateElement {...props} className="my-4">
25 <div
26 ref={containerRef}
27 className={cn(
28 "w-full overflow-visible",
29 getStaticDiagramJustifyClass(element.alignment),
30 )}
31 >
32 <div
33 style={{
34 ...frameStyle,
35 ...getDiagramFitFrameStyle(element.alignment),
36 }}
37 >
38 <div
39 ref={layoutRef}
40 className={cn(
41 "flex items-stretch gap-3 overflow-visible py-6",
42 getStaticDiagramJustifyClass(element.alignment),
43 )}
44 style={fitStyle}
45 >
46 {props.children}
47 </div>
48 </div>
49 </div>
50 </SlateElement>
51 );
52 }
53
53 lines Plain Text