diff --git a/src/components/ui/image-node.tsx b/src/components/ui/image-node.tsx index 229df96..201a7de 100644 --- a/src/components/ui/image-node.tsx +++ b/src/components/ui/image-node.tsx @@ -1,10 +1,15 @@ 'use client'; -import * as React from 'react'; import type { PlateElementProps } from 'platejs/react'; -import { PlateElement, useEditorRef, useFocused, useReadOnly, useSelected, useElement } from 'platejs/react'; +import Image from 'next/image'; +import { + PlateElement, + useEditorRef, + useElement, + useReadOnly +} from 'platejs/react'; import { cn } from '@/lib/utils'; @@ -18,26 +23,25 @@ type ImageElementData = { export function ImageElement(props: PlateElementProps) { const editor = useEditorRef(); - const element = useElement(); + const element = useElement(); const readOnly = useReadOnly(); - const selected = useSelected(); - const focused = useFocused(); - const data = element ?? (props.element as ImageElementData); + const data = (element ?? props.element) as ImageElementData; const src = data.url ?? data.src; const captionText = data.caption?.map((c) => c.text).join('') ?? data.alt ?? data.altText ?? ''; const showCaptionEditor = !readOnly; - const path = showCaptionEditor ? editor.api.findPath(element) : null; + const path = showCaptionEditor ? editor.api.findPath(element ?? props.element) : null; return (
- {src ? ( - {captionText} ) : ( @@ -54,10 +58,7 @@ export function ImageElement(props: PlateElementProps) { value={captionText} onChange={(e) => { if (!path) return; - editor.tf.setNodes( - { caption: [{ text: e.target.value }] }, - { at: path } - ); + editor.tf.setNodes({ caption: [{ text: e.target.value }] }, { at: path }); }} placeholder="Add caption / alt text" className="w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground"