mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
editor: allow download & preview of attachments in readonly mode (#2621)
Signed-off-by: Ramiro Pruis<ramapruis@gmail.com>
This commit is contained in:
@@ -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
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export function AttachmentComponent(
|
|||||||
const { editor, node, selected } = props;
|
const { editor, node, selected } = props;
|
||||||
const { filename, size, progress } = node.attrs;
|
const { filename, size, progress } = node.attrs;
|
||||||
const elementRef = useRef<HTMLSpanElement>();
|
const elementRef = useRef<HTMLSpanElement>();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box
|
<Box
|
||||||
@@ -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",
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -62,4 +62,5 @@ export type ReactNodeViewOptions<P> = {
|
|||||||
shouldUpdate?: ShouldUpdate;
|
shouldUpdate?: ShouldUpdate;
|
||||||
contentDOMFactory?: (() => ContentDOM) | boolean;
|
contentDOMFactory?: (() => ContentDOM) | boolean;
|
||||||
wrapperFactory?: () => HTMLElement;
|
wrapperFactory?: () => HTMLElement;
|
||||||
|
forceEnableSelection?: boolean;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user