-
Notifications
You must be signed in to change notification settings - Fork 407
✨(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
Merged
+247
−64
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/PdfBlock.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint-disable react-hooks/rules-of-hooks */ | ||
import { insertOrUpdateBlock } from '@blocknote/core'; | ||
import { | ||
AddFileButton, | ||
ResizableFileBlockWrapper, | ||
createReactBlockSpec, | ||
} from '@blocknote/react'; | ||
import { TFunction } from 'i18next'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { createGlobalStyle } from 'styled-components'; | ||
|
||
import { Box, Icon } from '@/components'; | ||
|
||
import { DocsBlockNoteEditor } from '../../types'; | ||
|
||
const PDFBlockStyle = createGlobalStyle` | ||
.bn-block-content[data-content-type="pdf"] { | ||
width: fit-content; | ||
} | ||
`; | ||
|
||
type FileBlockEditor = Parameters<typeof AddFileButton>[0]['editor']; | ||
|
||
export const PdfBlock = createReactBlockSpec( | ||
{ | ||
type: 'pdf', | ||
content: 'none', | ||
propSchema: { | ||
name: { default: '' as const }, | ||
url: { default: '' as const }, | ||
caption: { default: '' as const }, | ||
showPreview: { default: true }, | ||
previewWidth: { default: undefined, type: 'number' }, | ||
}, | ||
isFileBlock: true, | ||
AntoLC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fileBlockAccept: ['application/pdf'], | ||
}, | ||
{ | ||
render: ({ editor, block, contentRef }) => { | ||
const { t } = useTranslation(); | ||
const pdfUrl = block.props.url; | ||
|
||
return ( | ||
<Box ref={contentRef} className="bn-file-block-content-wrapper"> | ||
<PDFBlockStyle /> | ||
<ResizableFileBlockWrapper | ||
buttonIcon={<Icon iconName="upload" />} | ||
block={block} | ||
editor={editor as unknown as FileBlockEditor} | ||
buttonText={t('Add PDF')} | ||
> | ||
<Box | ||
className="bn-visual-media" | ||
role="presentation" | ||
as="embed" | ||
$width="100%" | ||
$height="450px" | ||
type="application/pdf" | ||
src={pdfUrl} | ||
contentEditable={false} | ||
draggable={false} | ||
onClick={() => editor.setTextCursorPosition(block)} | ||
/> | ||
</ResizableFileBlockWrapper> | ||
</Box> | ||
); | ||
}, | ||
}, | ||
); | ||
|
||
export const getPdfReactSlashMenuItems = ( | ||
editor: DocsBlockNoteEditor, | ||
t: TFunction<'translation', undefined>, | ||
group: string, | ||
) => [ | ||
{ | ||
title: t('PDF'), | ||
onItemClick: () => { | ||
insertOrUpdateBlock(editor, { type: 'pdf' }); | ||
}, | ||
aliases: [t('pdf'), t('document'), t('embed'), t('file')], | ||
group, | ||
icon: <Icon iconName="picture_as_pdf" $size="18px" />, | ||
subtext: t('Embed a PDF file'), | ||
}, | ||
]; |
34 changes: 34 additions & 0 deletions
34
.../apps/impress/src/features/docs/doc-editor/components/custom-blocks/UploadLoaderBlock.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createReactBlockSpec } from '@blocknote/react'; | ||
|
||
import { Box, Text } from '@/components'; | ||
|
||
import Loader from '../../assets/loader.svg'; | ||
import Warning from '../../assets/warning.svg'; | ||
|
||
export const UploadLoaderBlock = createReactBlockSpec( | ||
{ | ||
type: 'uploadLoader', | ||
propSchema: { | ||
information: { default: '' as const }, | ||
type: { | ||
default: 'loading' as const, | ||
values: ['loading', 'warning'] as const, | ||
}, | ||
}, | ||
content: 'none', | ||
}, | ||
{ | ||
render: ({ block }) => { | ||
return ( | ||
<Box className="bn-visual-media-wrapper" $direction="row" $gap="0.5rem"> | ||
{block.props.type === 'warning' ? ( | ||
<Warning /> | ||
) : ( | ||
<Loader style={{ animation: 'spin 1.5s linear infinite' }} /> | ||
)} | ||
<Text>{block.props.information}</Text> | ||
</Box> | ||
); | ||
}, | ||
}, | ||
); |
2 changes: 2 additions & 0 deletions
2
src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './AccessibleImageBlock'; | ||
export * from './CalloutBlock'; | ||
export * from './DividerBlock'; | ||
export * from './PdfBlock'; | ||
export * from './UploadLoaderBlock'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/frontend/apps/impress/src/features/docs/doc-export/blocks-mapping/uploadLoaderDocx.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Paragraph, TextRun } from 'docx'; | ||
|
||
import { DocsExporterDocx } from '../types'; | ||
|
||
export const blockMappingUploadLoaderDocx: DocsExporterDocx['mappings']['blockMapping']['uploadLoader'] = | ||
(block) => { | ||
return new Paragraph({ | ||
children: [ | ||
new TextRun(block.props.type === 'loading' ? '⏳' : '⚠️'), | ||
new TextRun(' '), | ||
new TextRun(block.props.information), | ||
], | ||
}); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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 either.