client: improve export

This commit is contained in:
fantasticit 2022-07-14 22:18:57 +08:00
parent 5f773ec988
commit bd6e63d80c
6 changed files with 20 additions and 3 deletions

View File

@ -30,6 +30,10 @@ export const DocumentExporter: React.FC<IProps> = ({ document, render }) => {
editable: false, editable: false,
extensions: AllExtensions, extensions: AllExtensions,
content: '', content: '',
editorProps: {
// @ts-ignore
print: true,
},
}); });
}, []); }, []);
@ -132,6 +136,7 @@ export const DocumentExporter: React.FC<IProps> = ({ document, render }) => {
); );
useEffect(() => { useEffect(() => {
console.log('doc', editor, document);
const c = safeJSONParse(document && document.content); const c = safeJSONParse(document && document.content);
const json = c.default || c; const json = c.default || c;
editor.commands.setContent(json); editor.commands.setContent(json);

View File

@ -46,6 +46,7 @@ import { Superscript } from 'tiptap/core/extensions/superscript';
import { Table } from 'tiptap/core/extensions/table'; import { Table } from 'tiptap/core/extensions/table';
import { TableCell } from 'tiptap/core/extensions/table-cell'; import { TableCell } from 'tiptap/core/extensions/table-cell';
import { TableHeader } from 'tiptap/core/extensions/table-header'; import { TableHeader } from 'tiptap/core/extensions/table-header';
import { TableOfContents } from 'tiptap/core/extensions/table-of-contents';
import { TableRow } from 'tiptap/core/extensions/table-row'; import { TableRow } from 'tiptap/core/extensions/table-row';
import { TaskItem } from 'tiptap/core/extensions/task-item'; import { TaskItem } from 'tiptap/core/extensions/task-item';
import { TaskList } from 'tiptap/core/extensions/task-list'; import { TaskList } from 'tiptap/core/extensions/task-list';
@ -94,6 +95,7 @@ export const AllExtensions = [
TableCell, TableCell,
TableHeader, TableHeader,
TableRow, TableRow,
TableOfContents,
Text, Text,
TextAlign, TextAlign,
TextStyle, TextStyle,

View File

@ -20,7 +20,6 @@
code { code {
width: 100%; width: 100%;
max-height: 370px;
padding: 0; padding: 0;
margin: 8px; margin: 8px;
overflow: auto; overflow: auto;

View File

@ -12,4 +12,10 @@
margin-right: 8px; margin-right: 8px;
} }
} }
&.maxHeight {
code {
max-height: 370px;
}
}
} }

View File

@ -11,11 +11,16 @@ import styles from './index.module.scss';
export const CodeBlockWrapper = ({ editor, node: { attrs }, updateAttributes, extension }) => { export const CodeBlockWrapper = ({ editor, node: { attrs }, updateAttributes, extension }) => {
const isEditable = editor.isEditable; const isEditable = editor.isEditable;
const isPrint = editor?.options?.editorProps?.print;
const { language: defaultLanguage } = attrs; const { language: defaultLanguage } = attrs;
const $container = useRef<HTMLPreElement>(); const $container = useRef<HTMLPreElement>();
return ( return (
<DragableWrapper editor={editor} extensionName={CodeBlock.name} className={cls(styles.wrap, 'render-wrapper')}> <DragableWrapper
editor={editor}
extensionName={CodeBlock.name}
className={cls(styles.wrap, !isPrint && styles.maxHeight, 'render-wrapper')}
>
<div className={styles.handleWrap}> <div className={styles.handleWrap}>
<Select <Select
size="small" size="small"

View File

@ -68,7 +68,7 @@ const nodeSerializer = {
state.closeBlock(node); state.closeBlock(node);
}, },
[CodeBlock.name](state, node) { [CodeBlock.name](state, node) {
state.renderInline(node.content?.content ?? ''); state.renderContent(node);
state.closeBlock(node); state.closeBlock(node);
}, },
[Status.name](state, node) { [Status.name](state, node) {