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, { return createSelectionBasedNodeView(AttachmentComponent, {
shouldUpdate: ({ attrs: prev }, { attrs: next }) => { shouldUpdate: ({ attrs: prev }, { attrs: next }) => {
return prev.progress !== next.progress; return prev.progress !== next.progress;
} },
forceEnableSelection: true
}); });
}, },

View File

@@ -87,11 +87,15 @@ export function AttachmentComponent(
{selected && ( {selected && (
<ToolbarGroup <ToolbarGroup
editor={editor} editor={editor}
tools={[ tools={ editor.isEditable ? [
"removeAttachment", "removeAttachment",
"downloadAttachment", "downloadAttachment",
"previewAttachment" "previewAttachment"
]} ] : [
"downloadAttachment",
"previewAttachment"
]
}
sx={{ sx={{
boxShadow: "menu", boxShadow: "menu",
borderRadius: "default", borderRadius: "default",

View File

@@ -90,9 +90,7 @@ export class SelectionBasedNodeView<
forwardRef?: ForwardRef forwardRef?: ForwardRef
): React.ReactElement<unknown> | null { ): React.ReactElement<unknown> | null {
if (!this.options.component) return null; if (!this.options.component) return null;
const isSelected = const isSelected =(this.options.forceEnableSelection || this.editor.isEditable) && this.isSelectedNode(this.editor.view.state.selection);
this.editor.isEditable &&
this.isSelectedNode(this.editor.view.state.selection);
return ( return (
<ThemeProvider> <ThemeProvider>

View File

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