mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
fix: preview page (#1355)
This commit is contained in:
@@ -97,16 +97,18 @@ export const BlockSuiteEditor = (props: EditorProps) => {
|
|||||||
if (!editor || !container || !page) {
|
if (!editor || !container || !page) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (page.awarenessStore.getFlag('enable_block_hub')) {
|
||||||
|
editor.createBlockHub().then(blockHub => {
|
||||||
|
if (blockHubRef.current) {
|
||||||
|
blockHubRef.current.remove();
|
||||||
|
}
|
||||||
|
blockHubRef.current = blockHub;
|
||||||
|
const toolWrapper = document.querySelector('#toolWrapper');
|
||||||
|
assertExists(toolWrapper);
|
||||||
|
toolWrapper.appendChild(blockHub);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
editor.createBlockHub().then(blockHub => {
|
|
||||||
if (blockHubRef.current) {
|
|
||||||
blockHubRef.current.remove();
|
|
||||||
}
|
|
||||||
blockHubRef.current = blockHub;
|
|
||||||
const toolWrapper = document.querySelector('#toolWrapper');
|
|
||||||
assertExists(toolWrapper);
|
|
||||||
toolWrapper.appendChild(blockHub);
|
|
||||||
});
|
|
||||||
container.appendChild(editor);
|
container.appendChild(editor);
|
||||||
return () => {
|
return () => {
|
||||||
blockHubRef.current?.remove();
|
blockHubRef.current?.remove();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export type BlockSuiteEditorHeaderProps = React.PropsWithChildren<{
|
|||||||
blockSuiteWorkspace: BlockSuiteWorkspace;
|
blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||||
pageId: string;
|
pageId: string;
|
||||||
isPublic?: boolean;
|
isPublic?: boolean;
|
||||||
|
isPreview?: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const BlockSuiteEditorHeader: React.FC<BlockSuiteEditorHeaderProps> = ({
|
export const BlockSuiteEditorHeader: React.FC<BlockSuiteEditorHeaderProps> = ({
|
||||||
@@ -28,6 +29,7 @@ export const BlockSuiteEditorHeader: React.FC<BlockSuiteEditorHeaderProps> = ({
|
|||||||
pageId,
|
pageId,
|
||||||
children,
|
children,
|
||||||
isPublic,
|
isPublic,
|
||||||
|
isPreview,
|
||||||
}) => {
|
}) => {
|
||||||
const page = blockSuiteWorkspace.getPage(pageId);
|
const page = blockSuiteWorkspace.getPage(pageId);
|
||||||
// fixme(himself65): remove this atom and move it to props
|
// fixme(himself65): remove this atom and move it to props
|
||||||
@@ -46,7 +48,7 @@ export const BlockSuiteEditorHeader: React.FC<BlockSuiteEditorHeaderProps> = ({
|
|||||||
<Header
|
<Header
|
||||||
rightItems={
|
rightItems={
|
||||||
// fixme(himself65): other right items not supported in public mode
|
// fixme(himself65): other right items not supported in public mode
|
||||||
isPublic
|
isPublic || isPreview
|
||||||
? ['themeModeSwitch']
|
? ['themeModeSwitch']
|
||||||
: isTrash
|
: isTrash
|
||||||
? ['trashButtonGroup']
|
? ['trashButtonGroup']
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { BlockSuiteEditorHeader } from './blocksuite/header';
|
|||||||
|
|
||||||
export type PageDetailEditorProps = {
|
export type PageDetailEditorProps = {
|
||||||
isPublic?: boolean;
|
isPublic?: boolean;
|
||||||
|
isPreview?: boolean;
|
||||||
blockSuiteWorkspace: BlockSuiteWorkspace;
|
blockSuiteWorkspace: BlockSuiteWorkspace;
|
||||||
pageId: string;
|
pageId: string;
|
||||||
onInit?: (page: Page, editor: Readonly<EditorContainer>) => void;
|
onInit?: (page: Page, editor: Readonly<EditorContainer>) => void;
|
||||||
@@ -34,6 +35,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
|
|||||||
onLoad,
|
onLoad,
|
||||||
header,
|
header,
|
||||||
isPublic,
|
isPublic,
|
||||||
|
isPreview,
|
||||||
}) => {
|
}) => {
|
||||||
const page = blockSuiteWorkspace.getPage(pageId);
|
const page = blockSuiteWorkspace.getPage(pageId);
|
||||||
if (!page) {
|
if (!page) {
|
||||||
@@ -51,6 +53,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
|
|||||||
</Helmet>
|
</Helmet>
|
||||||
<BlockSuiteEditorHeader
|
<BlockSuiteEditorHeader
|
||||||
isPublic={isPublic}
|
isPublic={isPublic}
|
||||||
|
isPreview={isPreview}
|
||||||
blockSuiteWorkspace={blockSuiteWorkspace}
|
blockSuiteWorkspace={blockSuiteWorkspace}
|
||||||
pageId={pageId}
|
pageId={pageId}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -5,11 +5,15 @@ import {
|
|||||||
NextPage,
|
NextPage,
|
||||||
} from 'next';
|
} from 'next';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { PageDetailEditor } from '../../components/page-detail-editor';
|
import { PageDetailEditor } from '../../components/page-detail-editor';
|
||||||
import { PageLoading } from '../../components/pure/loading';
|
import { PageLoading } from '../../components/pure/loading';
|
||||||
import { StyledPage, StyledWrapper } from '../../layouts/styles';
|
import {
|
||||||
|
StyledPage,
|
||||||
|
StyledToolWrapper,
|
||||||
|
StyledWrapper,
|
||||||
|
} from '../../layouts/styles';
|
||||||
import { BlockSuiteWorkspace } from '../../shared';
|
import { BlockSuiteWorkspace } from '../../shared';
|
||||||
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
||||||
|
|
||||||
@@ -52,6 +56,7 @@ const PreviewPage: NextPage<PreviewPageProps> = ({
|
|||||||
<StyledPage>
|
<StyledPage>
|
||||||
<StyledWrapper>
|
<StyledWrapper>
|
||||||
<PageDetailEditor
|
<PageDetailEditor
|
||||||
|
isPreview
|
||||||
blockSuiteWorkspace={blockSuiteWorkspace}
|
blockSuiteWorkspace={blockSuiteWorkspace}
|
||||||
pageId="preview"
|
pageId="preview"
|
||||||
onInit={(page, editor) => {
|
onInit={(page, editor) => {
|
||||||
@@ -71,6 +76,12 @@ const PreviewPage: NextPage<PreviewPageProps> = ({
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<StyledToolWrapper>
|
||||||
|
{/* fixme(himself65): remove this */}
|
||||||
|
<div id="toolWrapper" style={{ marginBottom: '12px' }}>
|
||||||
|
{/* Slot for block hub */}
|
||||||
|
</div>
|
||||||
|
</StyledToolWrapper>
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
</StyledPage>
|
</StyledPage>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user