fix: pdf export in client and hide png export (#2604)

This commit is contained in:
fourdim
2023-06-01 21:26:57 +08:00
committed by GitHub
parent 7af5bd3894
commit 89a566a645
3 changed files with 128 additions and 71 deletions

View File

@@ -4,7 +4,7 @@ export const waterMarkStyle = style({
display: 'none', display: 'none',
'@media': { '@media': {
print: { print: {
position: 'absolute', position: 'fixed',
bottom: '0', bottom: '0',
right: '20px', right: '20px',
zIndex: 100, zIndex: 100,

View File

@@ -1,30 +1,27 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { PageBlockModel } from '@blocksuite/blocks';
import { ContentParser } from '@blocksuite/blocks/content-parser'; import { ContentParser } from '@blocksuite/blocks/content-parser';
import { import {
ArrowRightSmallIcon, ArrowRightSmallIcon,
ExportIcon, ExportIcon,
ExportToHtmlIcon, ExportToHtmlIcon,
ExportToMarkdownIcon, ExportToMarkdownIcon,
ExportToPdfIcon,
} from '@blocksuite/icons'; } from '@blocksuite/icons';
import { useRef } from 'react'; import { useRef } from 'react';
import { Menu, MenuItem } from '../../..'; import { Menu, MenuItem } from '../../..';
import type { CommonMenuItemProps } from './types'; import type { CommonMenuItemProps } from './types';
export const Export = ({ const ExportToPdfMenuItem = ({
onSelect, onSelect,
onItemClick, }: CommonMenuItemProps<{ type: 'pdf' }>) => {
}: CommonMenuItemProps<{ type: 'markdown' | 'html' | 'pdf' | 'png' }>) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const contentParserRef = useRef<ContentParser>(); const contentParserRef = useRef<ContentParser>();
return ( return (
<Menu
width={248}
placement="left"
trigger="click"
content={
<> <>
{/* <MenuItem {globalThis.currentEditor!.mode === 'page' && (
<MenuItem
data-testid="export-to-pdf" data-testid="export-to-pdf"
onClick={async () => { onClick={async () => {
if (!contentParserRef.current) { if (!contentParserRef.current) {
@@ -46,7 +43,19 @@ export const Export = ({
icon={<ExportToPdfIcon />} icon={<ExportToPdfIcon />}
> >
{t['Export to PDF']()} {t['Export to PDF']()}
</MenuItem> */} </MenuItem>
)}
</>
);
};
const ExportToHtmlMenuItem = ({
onSelect,
}: CommonMenuItemProps<{ type: 'html' }>) => {
const t = useAFFiNEI18N();
const contentParserRef = useRef<ContentParser>();
return (
<>
<MenuItem <MenuItem
data-testid="export-to-html" data-testid="export-to-html"
onClick={() => { onClick={() => {
@@ -62,21 +71,45 @@ export const Export = ({
> >
{t['Export to HTML']()} {t['Export to HTML']()}
</MenuItem> </MenuItem>
{/* <MenuItem </>
data-testid="export-to-png"
onClick={() => {
if (!contentParserRef.current) {
contentParserRef.current = new ContentParser(
globalThis.currentEditor!.page
); );
} };
contentParserRef.current.exportPng();
onSelect?.({ type: 'png' }); // const ExportToPngMenuItem = ({
}} // onSelect,
icon={<ExportToPngIcon />} // }: CommonMenuItemProps<{ type: 'png' }>) => {
> // const t = useAFFiNEI18N();
{t['Export to PNG']()} // const contentParserRef = useRef<ContentParser>();
</MenuItem> */} // return (
// <>
// {globalThis.currentEditor!.mode === 'page' && (
// <MenuItem
// data-testid="export-to-png"
// onClick={() => {
// if (!contentParserRef.current) {
// contentParserRef.current = new ContentParser(
// globalThis.currentEditor!.page
// );
// }
// contentParserRef.current.exportPng();
// onSelect?.({ type: 'png' });
// }}
// icon={<ExportToPngIcon />}
// >
// {t['Export to PNG']()}
// </MenuItem>
// )}
// </>
// );
// };
const ExportToMarkdownMenuItem = ({
onSelect,
}: CommonMenuItemProps<{ type: 'markdown' }>) => {
const t = useAFFiNEI18N();
const contentParserRef = useRef<ContentParser>();
return (
<>
<MenuItem <MenuItem
data-testid="export-to-markdown" data-testid="export-to-markdown"
onClick={() => { onClick={() => {
@@ -93,6 +126,25 @@ export const Export = ({
{t['Export to Markdown']()} {t['Export to Markdown']()}
</MenuItem> </MenuItem>
</> </>
);
};
export const Export = ({
onItemClick,
}: CommonMenuItemProps<{ type: 'markdown' | 'html' | 'pdf' | 'png' }>) => {
const t = useAFFiNEI18N();
return (
<Menu
width={248}
placement="left"
trigger="click"
content={
<>
<ExportToPdfMenuItem></ExportToPdfMenuItem>
<ExportToHtmlMenuItem></ExportToHtmlMenuItem>
{/* <ExportToPngMenuItem></ExportToPngMenuItem> */}
<ExportToMarkdownMenuItem></ExportToMarkdownMenuItem>
</>
} }
> >
<MenuItem <MenuItem

View File

@@ -58,6 +58,11 @@ export const mainContainerStyle = style({
borderRadius: '8px', borderRadius: '8px',
overflow: 'hidden', overflow: 'hidden',
boxShadow: 'var(--affine-shadow-1)', boxShadow: 'var(--affine-shadow-1)',
'@media': {
print: {
overflow: 'visible',
},
},
}, },
}, },
}); });