-
Notifications
You must be signed in to change notification settings - Fork 0
Issue/improve export spacings #1
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { css } from 'styled-components'; | ||
|
|
||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The media query uses the invalid syntax
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The styled-components template literal is not closed properly; the closing backtick and curly brace are missing, which will cause a syntax error. |
||
| export const cssEditor = (readonly: boolean) => css` | ||
| &, | ||
| & > .bn-container, | ||
| & .ProseMirror { | ||
| height: 100%; | ||
|
|
||
| .bn-side-menu[data-block-type='heading'][data-level='1'] { | ||
| height: 50px; | ||
| } | ||
| .bn-side-menu[data-block-type='heading'][data-level='2'] { | ||
| height: 43px; | ||
| } | ||
| .bn-side-menu[data-block-type='heading'][data-level='3'] { | ||
| height: 35px; | ||
| } | ||
| h1 { | ||
| font-size: 1.875rem; | ||
| } | ||
| h2 { | ||
| font-size: 1.5rem; | ||
| } | ||
| h3 { | ||
| font-size: 1.25rem; | ||
| } | ||
| a { | ||
| color: var(--c--theme--colors--greyscale-500); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The conditional expression |
||
| cursor: pointer; | ||
| } | ||
| .bn-block-group | ||
| .bn-block-group | ||
| .bn-block-outer:not([data-prev-depth-changed]):before { | ||
| border-left: none; | ||
| } | ||
| } | ||
|
|
||
| .bn-editor { | ||
| color: var(--c--theme--colors--greyscale-700); | ||
| } | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The media query uses the invalid syntax |
||
|
|
||
| .bn-block-outer:not(:first-child) { | ||
| &:has(h1) { | ||
| padding-top: 32px; | ||
| } | ||
| &:has(h2) { | ||
| padding-top: 24px; | ||
| } | ||
| &:has(h3) { | ||
| padding-top: 16px; | ||
| } | ||
| } | ||
|
|
||
| & .bn-inline-content code { | ||
| background-color: gainsboro; | ||
| padding: 2px; | ||
| border-radius: 4px; | ||
| } | ||
|
|
||
| @media screen and (width <= 560px) { | ||
| & .bn-editor { | ||
| ${readonly && `padding-left: 10px;`} | ||
| } | ||
| .bn-side-menu[data-block-type='heading'][data-level='1'] { | ||
| height: 46px; | ||
| } | ||
| .bn-side-menu[data-block-type='heading'][data-level='2'] { | ||
| height: 40px; | ||
| } | ||
| .bn-side-menu[data-block-type='heading'][data-level='3'] { | ||
| height: 40px; | ||
| } | ||
| & .bn-editor h1 { | ||
| font-size: 1.6rem; | ||
| } | ||
| & .bn-editor h2 { | ||
| font-size: 1.35rem; | ||
| } | ||
| & .bn-editor h3 { | ||
| font-size: 1.2rem; | ||
| } | ||
| .bn-block-content[data-is-empty-and-focused][data-content-type='paragraph'] | ||
| .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child)::before { | ||
| font-size: 14px; | ||
| } | ||
| } | ||
| `; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { Block, DefaultProps, ExporterOptions } from '@blocknote/core'; | ||
| import { | ||
| PDFExporter, | ||
| pdfDefaultSchemaMappings, | ||
| } from '@blocknote/xl-pdf-exporter'; | ||
| import { Font } from '@react-pdf/renderer'; | ||
|
|
||
| import { | ||
| DocsBlockNoteSchema, | ||
| DocsBlockSchema, | ||
| DocsInlineContentSchema, | ||
| DocsStyleSchema, | ||
| } from '@/features/docs/doc-editor'; | ||
|
|
||
| type Options = ExporterOptions & { | ||
| emojiSource: false | ReturnType<typeof Font.getEmojiSource>; | ||
| }; | ||
|
|
||
| type DocsDefaultProps = DefaultProps & { | ||
| level?: number; | ||
| }; | ||
|
|
||
| export class DocsPDFExporter extends PDFExporter< | ||
| DocsBlockSchema, | ||
| DocsStyleSchema, | ||
| DocsInlineContentSchema | ||
| > { | ||
| constructor( | ||
| protected readonly schemaMappings: DocsBlockNoteSchema, | ||
| options?: Partial<Options>, | ||
| ) { | ||
| super(schemaMappings, pdfDefaultSchemaMappings, options); | ||
| } | ||
|
|
||
| /** | ||
| * Breaklines are not displayed in PDFs, by adding a space we ensure that the line is not ignored | ||
| * @param blocks | ||
| * @param nestingLevel | ||
| * @returns | ||
| */ | ||
| public transformBlocks( | ||
| blocks: Block<DocsBlockSchema, DocsInlineContentSchema, DocsStyleSchema>[], // Or BlockFromConfig<B[keyof B], I, S>? | ||
| nestingLevel?: number, | ||
| ) { | ||
| blocks.forEach((block) => { | ||
| if (Array.isArray(block.content)) { | ||
| block.content.forEach((content) => { | ||
| if (content.type === 'text' && !content.text) { | ||
| content.text = ' '; | ||
| } | ||
| }); | ||
|
|
||
| if (!block.content.length) { | ||
| block.content.push({ | ||
| styles: {}, | ||
| text: ' ', | ||
| type: 'text', | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return super.transformBlocks(blocks, nestingLevel); | ||
| } | ||
|
|
||
| /** | ||
| * Override the method to add our custom styles | ||
| * @param props | ||
| * @returns | ||
| */ | ||
| public blocknoteDefaultPropsToReactPDFStyle( | ||
| props: Partial<DocsDefaultProps>, | ||
| ) { | ||
| let styles = super.blocknoteDefaultPropsToReactPDFStyle(props); | ||
|
|
||
| // Add margin to headings | ||
| if (props.level) { | ||
| styles = { | ||
| marginTop: 15, | ||
| marginBottom: 15, | ||
| ...styles, | ||
| }; | ||
| } | ||
|
|
||
| return styles; | ||
| } | ||
| } |
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.
The conditional expression
${readonly &&padding-left: 10px;}injects the boolean valuefalseinto the CSS whenreadonlyis false, producing invalid CSS. Use${readonly ? 'padding-left: 10px;' : ''}instead.