Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: enable previewing attachments on desktop/web

Abdullah Atta09098410a545
diff --git a/packages/editor/src/extensions/attachment/attachment.ts b/packages/editor/src/extensions/attachment/attachment.ts
index fc50d3541..36aa1dcd0 100644
--- a/packages/editor/src/extensions/attachment/attachment.ts
+++ b/packages/editor/src/extensions/attachment/attachment.ts
@@ -166,6 +166,7 @@ export const AttachmentNode = Node.create<AttachmentOptions>({
previewAttachment:
(attachment) =>
({ editor }) => {
+ if (!this.options.onPreviewAttachment) return false;
return this.options.onPreviewAttachment(editor, attachment);
}
};
diff --git a/packages/editor/src/extensions/image/component.tsx b/packages/editor/src/extensions/image/component.tsx
index edc394ba6..03e149fff 100644
--- a/packages/editor/src/extensions/image/component.tsx
+++ b/packages/editor/src/extensions/image/component.tsx
@@ -206,6 +206,7 @@ export function ImageComponent(
<ToolbarGroup
editor={editor}
tools={[
+ hash ? "previewAttachment" : "none",
hash ? "downloadAttachment" : "none",
"imageAlignLeft",
float ? "none" : "imageAlignCenter",
diff --git a/packages/editor/src/toolbar/tools/attachment.tsx b/packages/editor/src/toolbar/tools/attachment.tsx
index 0d4abb437..cb1599df3 100644
--- a/packages/editor/src/toolbar/tools/attachment.tsx
+++ b/packages/editor/src/toolbar/tools/attachment.tsx
@@ -64,9 +64,7 @@ export function DownloadAttachment(props: ToolProps) {
export function PreviewAttachment(props: ToolProps) {
const { editor } = props;
- const isBottom = useToolbarLocation() === "bottom";
-
- if (!editor.isActive("image") || !isBottom) return null;
+ if (!editor.isActive("image")) return null;
return (
<ToolButton
@@ -78,7 +76,7 @@ export function PreviewAttachment(props: ToolProps) {
findSelectedNode(editor, "image");
const attachment = (attachmentNode?.attrs || {}) as Attachment;
- editor.current?.chain().focus().previewAttachment(attachment).run();
+ editor.current?.commands.previewAttachment(attachment);
}}
/>
);