Skip to content

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

editor: allow download & preview of attachments in readonly mode (#2621)

Ramiro Pruis9cc9660b48a3
diff --git a/packages/editor/src/extensions/attachment/attachment.ts b/packages/editor/src/extensions/attachment/attachment.ts
index 05312aaf4..dca9028e2 100644
--- a/packages/editor/src/extensions/attachment/attachment.ts
+++ b/packages/editor/src/extensions/attachment/attachment.ts
@@ -112,7 +112,8 @@ export const AttachmentNode = Node.create<AttachmentOptions>({
return createSelectionBasedNodeView(AttachmentComponent, {
shouldUpdate: ({ attrs: prev }, { attrs: next }) => {
return prev.progress !== next.progress;
- }
+ },
+ forceEnableSelection: true
});
},
diff --git a/packages/editor/src/extensions/attachment/component.tsx b/packages/editor/src/extensions/attachment/component.tsx
index 75c28189f..9243f3759 100644
--- a/packages/editor/src/extensions/attachment/component.tsx
+++ b/packages/editor/src/extensions/attachment/component.tsx
@@ -32,7 +32,7 @@ export function AttachmentComponent(
const { editor, node, selected } = props;
const { filename, size, progress } = node.attrs;
const elementRef = useRef<HTMLSpanElement>();
-
+
return (
<>
<Box
@@ -87,11 +87,15 @@ export function AttachmentComponent(
{selected && (
<ToolbarGroup
editor={editor}
- tools={[
+ tools={ editor.isEditable ? [
"removeAttachment",
"downloadAttachment",
"previewAttachment"
- ]}
+ ] : [
+ "downloadAttachment",
+ "previewAttachment"
+ ]
+ }
sx={{
boxShadow: "menu",
borderRadius: "default",
diff --git a/packages/editor/src/extensions/react/selection-based-react-node-view.tsx b/packages/editor/src/extensions/react/selection-based-react-node-view.tsx
index 0f537af67..89877198c 100644
--- a/packages/editor/src/extensions/react/selection-based-react-node-view.tsx
+++ b/packages/editor/src/extensions/react/selection-based-react-node-view.tsx
@@ -90,9 +90,7 @@ export class SelectionBasedNodeView<
forwardRef?: ForwardRef
): React.ReactElement<unknown> | null {
if (!this.options.component) return null;
- const isSelected =
- this.editor.isEditable &&
- this.isSelectedNode(this.editor.view.state.selection);
+ const isSelected =(this.options.forceEnableSelection || this.editor.isEditable) && this.isSelectedNode(this.editor.view.state.selection);
return (
<ThemeProvider>
diff --git a/packages/editor/src/extensions/react/types.ts b/packages/editor/src/extensions/react/types.ts
index 0b10734ff..12ad04e23 100644
--- a/packages/editor/src/extensions/react/types.ts
+++ b/packages/editor/src/extensions/react/types.ts
@@ -62,4 +62,5 @@ export type ReactNodeViewOptions<P> = {
shouldUpdate?: ShouldUpdate;
contentDOMFactory?: (() => ContentDOM) | boolean;
wrapperFactory?: () => HTMLElement;
+ forceEnableSelection?: boolean;
};