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

Signed-off-by: Ramiro Pruis<ramapruis@gmail.com>
This commit is contained in:
Ramiro Pruis
2023-06-01 12:39:10 -03:00
committed by GitHub
parent e6162b2580
commit 9cc9660b48
4 changed files with 11 additions and 7 deletions

View File

@@ -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
});
},

View File

@@ -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",

View File

@@ -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>

View File

@@ -62,4 +62,5 @@ export type ReactNodeViewOptions<P> = {
shouldUpdate?: ShouldUpdate;
contentDOMFactory?: (() => ContentDOM) | boolean;
wrapperFactory?: () => HTMLElement;
forceEnableSelection?: boolean;
};