"use client" import type { Editor } from "@tiptap/react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { buildGradientCss, DOCS_GRAPHIC_PLACEMENT_LABELS, DOCS_GRAPHIC_WRAP_LABELS, parseGraphicAttrs, type DocsGraphicPlacement, type DocsGraphicWrap, } from "@/lib/drive/docs-graphic-types" import { readGraphicToolbarActive } from "@/components/drive/richtext/docs-graphic-toolbar-menu" export function DocsGraphicOptionsPanel({ editor, disabled, open, onOpenChange, }: { editor: Editor | null disabled?: boolean open?: boolean onOpenChange?: (open: boolean) => void }) { if (!editor || !readGraphicToolbarActive(editor)) return null const name = editor.isActive("docsInlineGraphic") ? "docsInlineGraphic" : "docsGraphic" const attrs = parseGraphicAttrs(editor.getAttributes(name) as Record) const update = (patch: Record) => { editor.chain().focus().updateDocsGraphic(patch).run() } const numField = ( label: string, key: "width" | "height" | "x" | "y" | "rotationDeg", step = 1 ) => (
update({ [key]: Number(e.target.value) || 0 })} />
) return (

{attrs.graphicType === "image" ? "Options image" : attrs.graphicType === "draw" ? "Options dessin" : attrs.graphicType === "shape" ? "Options forme" : "Options dégradé"}

{numField("Largeur (px)", "width")} {numField("Hauteur (px)", "height")} {numField("X", "x")} {numField("Y", "y")} {numField("Rotation (°)", "rotationDeg")}
{attrs.graphicType === "shape" ? (
update({ fill: e.target.value })} />
update({ stroke: e.target.value })} />
update({ strokeWidth: Number(e.target.value) || 0 })} />
) : null} {attrs.graphicType === "gradient" ? (
{ const gradientColor1 = e.target.value update({ gradientColor1, gradientCss: buildGradientCss( attrs.gradientAngle, gradientColor1, attrs.gradientColor2, attrs.gradientType ), }) }} />
{ const gradientColor2 = e.target.value update({ gradientColor2, gradientCss: buildGradientCss( attrs.gradientAngle, attrs.gradientColor1, gradientColor2, attrs.gradientType ), }) }} />
{attrs.gradientType === "linear" ? (
{ const gradientAngle = Number(e.target.value) || 0 update({ gradientAngle, gradientCss: buildGradientCss( gradientAngle, attrs.gradientColor1, attrs.gradientColor2, attrs.gradientType ), }) }} />
) : null}
) : null} {attrs.graphicType === "image" ? ( ) : null} ) }