import { NodeViewProps, NodeViewWrapper } from "@tiptap/react"; import { Group, Image, Loader, Text } from "@mantine/core"; import { useMemo } from "react"; import { getFileUrl } from "@/lib/config.ts"; import clsx from "clsx"; import classes from "./image-view.module.css"; import { useTranslation } from "react-i18next"; export default function ImageView(props: NodeViewProps) { const { t } = useTranslation(); const { editor, node, selected } = props; const { src, width, align, title, aspectRatio, placeholder } = node.attrs; const alignClass = useMemo(() => { if (align === "left") return "alignLeft"; if (align === "right") return "alignRight"; if (align === "center") return "alignCenter"; return "alignCenter"; }, [align]); const previewSrc = useMemo(() => { editor.storage.shared.imagePreviews = editor.storage.shared.imagePreviews || {}; if (placeholder?.id) { return editor.storage.shared.imagePreviews[placeholder.id]; } return null; }, [placeholder, editor]); return (
{src && ( {title} )} {!src && previewSrc && ( {placeholder?.name} )} {!src && !previewSrc && ( {placeholder?.name ? t("Uploading {{name}}", { name: placeholder.name }) : t("Uploading file")} )}
); }