mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
feat: add preloading template
This commit is contained in:
@@ -19,12 +19,12 @@
|
||||
"@affine/jotai": "workspace:*",
|
||||
"@affine/templates": "workspace:*",
|
||||
"@affine/workspace": "workspace:*",
|
||||
"@blocksuite/blocks": "0.0.0-20230601101714-0d24ba91-nightly",
|
||||
"@blocksuite/editor": "0.0.0-20230601101714-0d24ba91-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230601101714-0d24ba91-nightly",
|
||||
"@blocksuite/blocks": "0.0.0-20230606130340-805f430b-nightly",
|
||||
"@blocksuite/editor": "0.0.0-20230606130340-805f430b-nightly",
|
||||
"@blocksuite/global": "0.0.0-20230606130340-805f430b-nightly",
|
||||
"@blocksuite/icons": "^2.1.19",
|
||||
"@blocksuite/lit": "0.0.0-20230601101714-0d24ba91-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230601101714-0d24ba91-nightly",
|
||||
"@blocksuite/lit": "0.0.0-20230606130340-805f430b-nightly",
|
||||
"@blocksuite/store": "0.0.0-20230606130340-805f430b-nightly",
|
||||
"@dnd-kit/core": "^6.0.8",
|
||||
"@dnd-kit/sortable": "^7.0.2",
|
||||
"@emotion/cache": "^11.11.0",
|
||||
|
||||
@@ -41,4 +41,8 @@ export const buildFlags = {
|
||||
),
|
||||
changelogUrl:
|
||||
process.env.CHANGELOG_URL ?? 'http://affine.pro/blog/whats-new-affine-0601',
|
||||
enablePreloading:
|
||||
process.env.ENABLE_PRELOADING === undefined
|
||||
? true
|
||||
: process.env.ENABLE_PRELOADING === 'true',
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* please use new affine cloud instead.
|
||||
*/
|
||||
import { AFFINE_STORAGE_KEY, config } from '@affine/env';
|
||||
import { initPage } from '@affine/env/blocksuite';
|
||||
import { initEmptyPage } from '@affine/env/blocksuite';
|
||||
import { PageNotFoundError } from '@affine/env/constant';
|
||||
import { currentAffineUserAtom } from '@affine/workspace/affine/atom';
|
||||
import {
|
||||
@@ -330,7 +330,7 @@ export const AffineAdapter: WorkspaceAdapter<WorkspaceFlavour.AFFINE> = {
|
||||
<PageDetailEditor
|
||||
pageId={currentPageId}
|
||||
workspace={currentWorkspace}
|
||||
onInit={initPage}
|
||||
onInit={initEmptyPage}
|
||||
onLoad={onLoadEditor}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import {
|
||||
config,
|
||||
DEFAULT_HELLO_WORLD_PAGE_ID,
|
||||
DEFAULT_WORKSPACE_NAME,
|
||||
} from '@affine/env';
|
||||
import { initPage } from '@affine/env/blocksuite';
|
||||
import { initEmptyPage, initPageWithPreloading } from '@affine/env/blocksuite';
|
||||
import { PageNotFoundError } from '@affine/env/constant';
|
||||
import {
|
||||
CRUD,
|
||||
@@ -17,8 +18,8 @@ import {
|
||||
} from '@affine/workspace/type';
|
||||
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
|
||||
import { nanoid } from '@blocksuite/store';
|
||||
import React from 'react';
|
||||
|
||||
import { setEditorFlags } from '../../utils/editor-flag';
|
||||
import {
|
||||
BlockSuitePageList,
|
||||
PageDetailEditor,
|
||||
@@ -43,10 +44,12 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
|
||||
const page = blockSuiteWorkspace.createPage({
|
||||
id: DEFAULT_HELLO_WORLD_PAGE_ID,
|
||||
});
|
||||
blockSuiteWorkspace.setPageMeta(page.id, {
|
||||
init: true,
|
||||
});
|
||||
initPage(page);
|
||||
setEditorFlags(blockSuiteWorkspace);
|
||||
if (config.enablePreloading) {
|
||||
initPageWithPreloading(page);
|
||||
} else {
|
||||
initEmptyPage(page);
|
||||
}
|
||||
blockSuiteWorkspace.setPageMeta(page.id, {
|
||||
jumpOnce: true,
|
||||
});
|
||||
@@ -78,7 +81,7 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
|
||||
<>
|
||||
<PageDetailEditor
|
||||
pageId={currentPageId}
|
||||
onInit={initPage}
|
||||
onInit={initEmptyPage}
|
||||
onLoad={onLoadEditor}
|
||||
workspace={currentWorkspace}
|
||||
/>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { initPage } from '@affine/env/blocksuite';
|
||||
import { initEmptyPage } from '@affine/env/blocksuite';
|
||||
import {
|
||||
rootCurrentWorkspaceIdAtom,
|
||||
rootWorkspacesMetadataAtom,
|
||||
@@ -32,7 +32,7 @@ describe('currentWorkspace atom', () => {
|
||||
WorkspaceFlavour.LOCAL
|
||||
);
|
||||
const page = workspace.createPage({ id: 'page0' });
|
||||
initPage(page);
|
||||
initEmptyPage(page);
|
||||
const frameId = page.getBlockByFlavour('affine:frame').at(0)
|
||||
?.id as string;
|
||||
id = page.addBlock(
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { initEmptyPage } from '@affine/env/blocksuite';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { Generator } from '@blocksuite/store';
|
||||
import type React from 'react';
|
||||
import { useCallback, useRef } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { BlockSuiteEditor } from '../../blocksuite/block-suite-editor';
|
||||
|
||||
@@ -18,19 +19,7 @@ const blockSuiteWorkspace = createEmptyBlockSuiteWorkspace(
|
||||
|
||||
const page = blockSuiteWorkspace.createPage({ id: 'page0' });
|
||||
|
||||
const Editor: React.FC<{
|
||||
onInit: (page: Page, editor: Readonly<EditorContainer>) => void;
|
||||
testType: 'empty' | 'importMarkdown';
|
||||
}> = ({ onInit, testType }) => {
|
||||
const onceRef = useRef(false);
|
||||
if (!onceRef.current) {
|
||||
if (testType === 'importMarkdown') {
|
||||
page.workspace.meta.setPageMeta(page.id, {
|
||||
init: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const Editor: React.FC = () => {
|
||||
const onLoad = useCallback((page: Page, editor: EditorContainer) => {
|
||||
// @ts-ignore
|
||||
globalThis.page = page;
|
||||
@@ -43,7 +32,12 @@ const Editor: React.FC<{
|
||||
return <>loading...</>;
|
||||
}
|
||||
return (
|
||||
<BlockSuiteEditor page={page} mode="page" onInit={onInit} onLoad={onLoad} />
|
||||
<BlockSuiteEditor
|
||||
page={page}
|
||||
mode="page"
|
||||
onInit={initEmptyPage}
|
||||
onLoad={onLoad}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { initPage } from '@affine/env/blocksuite';
|
||||
import { initEmptyPage } from '@affine/env/blocksuite';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import type { PageBlockModel } from '@blocksuite/blocks';
|
||||
import { PlusIcon } from '@blocksuite/icons';
|
||||
@@ -41,7 +41,7 @@ export const Footer: React.FC<FooterProps> = ({
|
||||
const id = nanoid();
|
||||
const page = createPage(id);
|
||||
assertEquals(page.id, id);
|
||||
initPage(page);
|
||||
initEmptyPage(page);
|
||||
const block = page.getBlockByFlavour(
|
||||
'affine:page'
|
||||
)[0] as PageBlockModel;
|
||||
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
WorkspaceFallback,
|
||||
} from '@affine/component/workspace';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { DEFAULT_HELLO_WORLD_PAGE_ID } from '@affine/env';
|
||||
import { initPage } from '@affine/env/blocksuite';
|
||||
import { config, DEFAULT_HELLO_WORLD_PAGE_ID } from '@affine/env';
|
||||
import { initEmptyPage, initPageWithPreloading } from '@affine/env/blocksuite';
|
||||
import { setUpLanguage, useI18N } from '@affine/i18n';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { createAffineGlobalChannel } from '@affine/workspace/affine/sync';
|
||||
@@ -64,6 +64,7 @@ import {
|
||||
} from '../providers/modal-provider';
|
||||
import { pathGenerator, publicPathGenerator } from '../shared';
|
||||
import { toast } from '../utils';
|
||||
import { setEditorFlags } from '../utils/editor-flag';
|
||||
|
||||
const QuickSearchModal = lazy(() =>
|
||||
import('../components/pure/quick-search-modal').then(module => ({
|
||||
@@ -305,10 +306,12 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
|
||||
id: pageId,
|
||||
});
|
||||
assertEquals(page.id, pageId);
|
||||
currentWorkspace.blockSuiteWorkspace.setPageMeta(page.id, {
|
||||
init: true,
|
||||
});
|
||||
initPage(page);
|
||||
setEditorFlags(currentWorkspace.blockSuiteWorkspace);
|
||||
if (config.enablePreloading) {
|
||||
initPageWithPreloading(page);
|
||||
} else {
|
||||
initEmptyPage(page);
|
||||
}
|
||||
if (!router.query.pageId) {
|
||||
setCurrentPageId(pageId);
|
||||
void jumpToPage(currentWorkspace.id, pageId);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { AppContainer, MainContainer } from '@affine/component/workspace';
|
||||
import { initPage } from '@affine/env/blocksuite';
|
||||
import { useRouter } from 'next/router';
|
||||
import { lazy, Suspense } from 'react';
|
||||
|
||||
@@ -16,17 +15,12 @@ const InitPagePage: NextPageWithLayout = () => {
|
||||
if (!router.isReady) {
|
||||
return <>loading...</>;
|
||||
}
|
||||
let testType: 'empty' | 'importMarkdown' = 'empty';
|
||||
if (router.query.type === 'importMarkdown') {
|
||||
testType = 'importMarkdown';
|
||||
} else if (router.query.type === 'empty') {
|
||||
testType = 'empty';
|
||||
}
|
||||
|
||||
return (
|
||||
<AppContainer>
|
||||
<MainContainer>
|
||||
<Suspense>
|
||||
<Editor onInit={initPage} testType={testType} />
|
||||
<Editor />
|
||||
</Suspense>
|
||||
<div id="toolWrapper" />
|
||||
</MainContainer>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Breadcrumbs, displayFlex, styled } from '@affine/component';
|
||||
import { initPage } from '@affine/env/blocksuite';
|
||||
import { initEmptyPage } from '@affine/env/blocksuite';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { PageIcon } from '@blocksuite/icons';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
@@ -107,7 +107,7 @@ const PublicWorkspaceDetailPageInner = (): ReactElement => {
|
||||
dispose.dispose();
|
||||
};
|
||||
}}
|
||||
onInit={initPage}
|
||||
onInit={initEmptyPage}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { PageDetailSkeleton } from '@affine/component/page-detail-skeleton';
|
||||
import type { BlockSuiteFeatureFlags } from '@affine/env';
|
||||
import { config } from '@affine/env';
|
||||
import { rootCurrentPageIdAtom } from '@affine/workspace/atom';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
@@ -9,7 +7,7 @@ import { useBlockSuiteWorkspacePage } from '@toeverything/hooks/use-block-suite-
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useRouter } from 'next/router';
|
||||
import type React from 'react';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { getUIAdapter } from '../../../adapters/workspace';
|
||||
import { rootCurrentWorkspaceAtom } from '../../../atoms/root';
|
||||
@@ -17,16 +15,7 @@ import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspac
|
||||
import { useSyncRecentViewsWithRouter } from '../../../hooks/use-recent-views';
|
||||
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||
import { WorkspaceLayout } from '../../../layouts/workspace-layout';
|
||||
import type { BlockSuiteWorkspace, NextPageWithLayout } from '../../../shared';
|
||||
|
||||
function setEditorFlags(blockSuiteWorkspace: BlockSuiteWorkspace) {
|
||||
Object.entries(config.editorFlags).forEach(([key, value]) => {
|
||||
blockSuiteWorkspace.awarenessStore.setFlag(
|
||||
key as keyof BlockSuiteFeatureFlags,
|
||||
value
|
||||
);
|
||||
});
|
||||
}
|
||||
import type { NextPageWithLayout } from '../../../shared';
|
||||
|
||||
const WorkspaceDetail: React.FC = () => {
|
||||
const router = useRouter();
|
||||
@@ -50,12 +39,6 @@ const WorkspaceDetail: React.FC = () => {
|
||||
[blockSuiteWorkspace.id, openPage]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentWorkspace) {
|
||||
setEditorFlags(currentWorkspace.blockSuiteWorkspace);
|
||||
}
|
||||
}, [currentWorkspace]);
|
||||
|
||||
const { PageDetail, Header } = getUIAdapter(currentWorkspace.flavour);
|
||||
return (
|
||||
<>
|
||||
|
||||
12
apps/web/src/utils/editor-flag.ts
Normal file
12
apps/web/src/utils/editor-flag.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { type BlockSuiteFeatureFlags, config } from '@affine/env';
|
||||
|
||||
import type { BlockSuiteWorkspace } from '../shared';
|
||||
|
||||
export function setEditorFlags(blockSuiteWorkspace: BlockSuiteWorkspace) {
|
||||
Object.entries(config.editorFlags).forEach(([key, value]) => {
|
||||
blockSuiteWorkspace.awarenessStore.setFlag(
|
||||
key as keyof BlockSuiteFeatureFlags,
|
||||
value
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user