| 1 | "use client"; |
| 2 | |
| 3 | import { cn } from "@/lib/utils"; |
| 4 | import { NodeApi, PathApi } from "platejs"; |
| 5 | import { PlateElement, type PlateElementProps } from "platejs/react"; |
| 6 | import { |
| 7 | type TColumnGroupElement, |
| 8 | type TColumnItemElement, |
| 9 | } from "../plugins/column-plugin"; |
| 10 | import { getAlignmentClasses } from "../utils"; |
| 11 | |
| 12 | export const ColumnItem = (props: PlateElementProps<TColumnItemElement>) => { |
| 13 | // Get parent element for alignment information |
| 14 | const parentPath = PathApi.parent(props.path); |
| 15 | const parentElement = NodeApi.get( |
| 16 | props.editor, |
| 17 | parentPath, |
| 18 | ) as TColumnGroupElement; |
| 19 | |
| 20 | // Get alignment - use item alignment if set, otherwise inherit from parent |
| 21 | const itemAlignment = props.element.alignment; |
| 22 | const parentAlignment = parentElement?.alignment; |
| 23 | const alignment = itemAlignment ?? parentAlignment ?? "center"; |
| 24 | return ( |
| 25 | <PlateElement {...props}> |
| 26 | <div |
| 27 | className={cn( |
| 28 | "flex h-full flex-col gap-2 p-3", |
| 29 | getAlignmentClasses(alignment), |
| 30 | "[&_:is(.presentation-heading)]:[-webkit-background-clip:unset!important;]", |
| 31 | "[&_:is(.presentation-heading)]:[-webkit-text-fill-color:unset!important;]", |
| 32 | "[&_:is(.presentation-heading)]:[background-clip:unset!important;]", |
| 33 | "[&_:is(.presentation-heading)]:[background:none!important;]", |
| 34 | "[&_:is(.presentation-heading)]:text-primary!", |
| 35 | )} |
| 36 | > |
| 37 | {props.children} |
| 38 | </div> |
| 39 | </PlateElement> |
| 40 | ); |
| 41 | }; |
| 42 |