mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
7981ef462e
* use local resizable * feat: aduio * support audio imports * feat: use confluence real file names * cleanup * error handling * hide notice * add audio * fix pulse * Fix import and export * unify pulse * hide in readonly mode * keywords * keyword * translations * better sort * feat: PDF embed * cleanup * remove audio menu * open active * hide focus on readonly mode * increase iframe default dimension
72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
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 (
|
|
<NodeViewWrapper data-drag-handle>
|
|
<div
|
|
className={clsx(
|
|
selected && "ProseMirror-selectednode",
|
|
classes.imageWrapper,
|
|
!src && classes.skeleton,
|
|
alignClass,
|
|
)}
|
|
style={{
|
|
aspectRatio: aspectRatio ? aspectRatio : src ? undefined : "16 / 9",
|
|
width,
|
|
}}
|
|
>
|
|
{src && (
|
|
<Image radius="md" fit="contain" src={getFileUrl(src)} alt={title} />
|
|
)}
|
|
{!src && previewSrc && (
|
|
<Group pos="relative" h="100%" w="100%">
|
|
<Image
|
|
radius="md"
|
|
fit="contain"
|
|
src={previewSrc}
|
|
alt={placeholder?.name}
|
|
/>
|
|
<Loader size={20} pos="absolute" bottom={6} right={6} />
|
|
</Group>
|
|
)}
|
|
{!src && !previewSrc && (
|
|
<Group justify="center" wrap="nowrap" gap="xs" maw="100%" px="md">
|
|
<Loader size={20} style={{ flexShrink: 0 }} />
|
|
<Text component="span" size="sm" truncate="end">
|
|
{placeholder?.name
|
|
? t("Uploading {{name}}", { name: placeholder.name })
|
|
: t("Uploading file")}
|
|
</Text>
|
|
</Group>
|
|
)}
|
|
</div>
|
|
</NodeViewWrapper>
|
|
);
|
|
}
|