"use client"; import { FileText } from "lucide-react"; import { BaseBoxShapeUtil, HTMLContainer, T, type TLBaseShape, toDomPrecision, } from "tldraw"; import { cn } from "@/lib/utils"; export type DocumentCardShape = TLBaseShape< "document-card", { w: number; h: number; objectId: string; title: string; preview: string; } >; function truncatePreview(text: string, max = 100): string { const t = text.trim(); if (t.length <= max) return t; return `${t.slice(0, max - 1)}…`; } function DocumentCardBody({ shape }: { shape: DocumentCardShape }) { const { title, preview } = shape.props; const body = truncatePreview(preview); return ( {title || "Untitled document"} {body || "No preview yet."} Document ); } export class DocumentCardShapeUtil extends BaseBoxShapeUtil { static override type = "document-card"; static override props = { w: T.number, h: T.number, objectId: T.string, title: T.string, preview: T.string, }; override getDefaultProps(): DocumentCardShape["props"] { return { w: 220, h: 140, objectId: "", title: "Document", preview: "", }; } override getAriaDescriptor(shape: DocumentCardShape) { return shape.props.title; } override component(shape: DocumentCardShape) { return ; } override indicator(shape: DocumentCardShape) { return ( ); } override useLegacyIndicator() { return false; } override getIndicatorPath(shape: DocumentCardShape) { const p = new Path2D(); p.roundRect(0, 0, shape.props.w, shape.props.h, 10); return p; } }
{body || "No preview yet."}