-
Notifications
You must be signed in to change notification settings - Fork 391
✨(frontend) add pdf block to the editor #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Changed content disposition as inline so that pdf is not downloaded automatically. Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
Added pdf block in the editor. Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
Moved drag handler logic to a hook to make component dumb. Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
Made docx and pdf export mapper for the newly added pdf block Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
Hey team, This is a duplicate of PR-795, since I couldn’t reopen the original after losing the fork. I’d appreciate the maintainers’ input on a few points where the implementation could be improved:
Looking forward to your feedback and happy to adjust the implementation accordingly. |
Added pr number in changelog Signed-off-by: dakshesh14 <65905942+dakshesh14@users.noreply.github.com>
Hey @dakshesh14 ! |
Hey @virgile-dev, happy to be back! No problem at all - I’ll wait for @AntoLC to return and review the PR. Thanks for keeping me posted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution, it is a great feature ! 🎉
Feel free to ask me if you need more details about the comments.
@@ -6,6 +6,8 @@ export * from './headingPDF'; | |||
export * from './imageDocx'; | |||
export * from './imagePDF'; | |||
export * from './paragraphPDF'; | |||
export * from './pdfDocx'; | |||
export * from './pdfPdf'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export * from './pdfPdf'; | |
export * from './pdfPDF'; |
<AddFileButton | ||
block={block} | ||
editor={editor as FileBlockEditor} | ||
buttonText="Add PDF" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be translatable.
showPreview: { default: true }, | ||
previewWidth: { default: undefined, type: 'number' }, | ||
}, | ||
isFileBlock: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To target only pdf files:
isFileBlock: true, | |
isFileBlock: true, | |
fileBlockAccept: ['application/pdf'], |
block={block} | ||
editor={editor as FileBlockEditor} | ||
buttonText="Add PDF" | ||
buttonIcon={<Icon iconName="upload" $size="18px" />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default the size seems to be "24px", it is the size on the others blocks, if you put lower directly on the icon, the icon will look not centered anymore.
If you want to put it at "18px", you should modify ".bn-add-file-button-icon".
buttonIcon={<Icon iconName="upload" $size="18px" />} | |
buttonIcon={<Icon iconName="upload" />} |
const { wrapperRef, pdfWidth, handlePointerDown } = usePdfResizer( | ||
block.props.previewWidth ?? 100, | ||
handleResizeEnd, | ||
); | ||
|
||
return ( | ||
<div ref={contentRef} className="bn-file-block-content-wrapper"> | ||
{pdfUrl === '' ? ( | ||
<AddFileButton | ||
block={block} | ||
editor={editor as FileBlockEditor} | ||
buttonText="Add PDF" | ||
buttonIcon={<Icon iconName="upload" $size="18px" />} | ||
/> | ||
) : ( | ||
<FileBlockWrapper block={block} editor={editor as FileBlockEditor}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should leverage ResizableFileBlockWrapper
, it will simplify your component a lot.
ResizableFileBlockWrapper
includes the resizing logic, plus it includes the part when the url is not defined yet.
You can see how to use it here: https://github.com/TypeCellOS/BlockNote/blob/7a66f11fd8a21ce3c1ffcb87590ae44b7f877ed6/packages/react/src/blocks/ImageBlockContent/ImageBlockContent.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be in another PR, but make ResizableFileBlockWrapper
sizable on height as well will be great !
<Box | ||
$display="flex" | ||
$align="center" | ||
$justify="center" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to have some drag and drop issue with the embed tag, not sure why.
-.Docs.1.webm
<View | ||
style={{ | ||
marginVertical: 10, | ||
padding: 10, | ||
border: '1px solid #ccc', | ||
borderRadius: 4, | ||
backgroundColor: '#f9f9f9', | ||
}} | ||
> | ||
<Text style={{ fontSize: 12, fontWeight: 'bold', marginBottom: 5 }}> | ||
📄 {pdfName} | ||
</Text> | ||
{pdfUrl && ( | ||
<Text style={{ fontSize: 10, color: '#666' }}>Source: {pdfUrl}</Text> | ||
)} | ||
<Text style={{ fontSize: 10, color: '#999', marginTop: 5 }}> | ||
[PDF content cannot be embedded in exported PDF] | ||
</Text> | ||
</View> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is not supported we should just fallback on what is made already, same for "Docx":
https://github.com/TypeCellOS/BlockNote/blob/7a66f11fd8a21ce3c1ffcb87590ae44b7f877ed6/packages/xl-pdf-exporter/src/pdf/defaultSchema/blocks.tsx#L205-L218

It is on the roadmap to improve the design export.
}, | ||
aliases: ['pdf', 'document', 'embed', 'file'], | ||
group, | ||
icon: <Icon iconName="upload" $size="18px" />, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about picture_as_pdf
icon instead ?
proxy_hide_header Content-Disposition; | ||
add_header Content-Disposition "inline"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure to understand why it is necessary, seems to work fine with the embed
tag without changing to "inline" ?
Is there a browser where you get a problem maybe ?
Hi @AntoLC, thank you for your reviews! I will work on these. |
Purpose
Added an option for users to upload and preview PDF files in the editor. This PR addresses #348. It is a duplicate of PR-795 because I couldn't reopen the PR as I lost my fork.
pdf-embed.webm
Proposal
Added the option for users to upload and preview PDF files within the editor.
Description: