feat: add preloading template

This commit is contained in:
Flrande
2023-06-07 17:31:54 +08:00
committed by himself65
parent ead106b940
commit e6cd2ace7d
67 changed files with 6732 additions and 385 deletions

View File

@@ -49,12 +49,12 @@
"rxjs": "^7.8.1"
},
"devDependencies": {
"@blocksuite/blocks": "0.0.0-20230601122821-16196c35-nightly",
"@blocksuite/editor": "0.0.0-20230601122821-16196c35-nightly",
"@blocksuite/global": "0.0.0-20230601122821-16196c35-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-20230601122821-16196c35-nightly",
"@blocksuite/store": "0.0.0-20230601122821-16196c35-nightly",
"@blocksuite/lit": "0.0.0-20230606130340-805f430b-nightly",
"@blocksuite/store": "0.0.0-20230606130340-805f430b-nightly",
"@types/react": "^18.2.6",
"@types/react-dnd": "^3.0.2",
"@types/react-dom": "18.2.4",

View File

@@ -5,7 +5,7 @@
"module": "./src/index.ts",
"devDependencies": {
"@affine/templates": "workspace:*",
"@blocksuite/global": "0.0.0-20230601122821-16196c35-nightly",
"@blocksuite/global": "0.0.0-20230606130340-805f430b-nightly",
"next": "=13.4.2",
"react": "18.3.0-canary-16d053d59-20230506",
"react-dom": "18.3.0-canary-16d053d59-20230506",

View File

@@ -1,57 +1,16 @@
import markdownTemplate from '@affine/templates/AFFiNE-beta-0.5.4.md';
import { ContentParser } from '@blocksuite/blocks/content-parser';
import type { Page } from '@blocksuite/store';
declare global {
interface Window {
lastImportedMarkdown: string;
}
export async function initPageWithPreloading(page: Page) {
const workspace = page.workspace;
const { data } = await import('@affine/templates/preloading.json');
await workspace.importPageSnapshot(data['space:Qmo9-1SGTB'], page.id);
}
const markdown = markdownTemplate as unknown as string;
const demoTitle = markdown
.split('\n')
.splice(0, 1)
.join('')
.replaceAll('#', '')
.trim();
const demoText = markdown.split('\n').slice(1).join('\n');
export function initPage(page: Page): void {
console.debug('initEmptyPage', page.id);
// Add page block and surface block at root level
const isFirstPage = page.meta.init === true;
if (isFirstPage) {
page.workspace.setPageMeta(page.id, {
init: false,
});
_initPageWithDemoMarkdown(page);
} else {
_initEmptyPage(page);
}
page.resetHistory();
}
export function _initEmptyPage(page: Page, title?: string): void {
export function initEmptyPage(page: Page): void {
const pageBlockId = page.addBlock('affine:page', {
title: new page.Text(title ?? ''),
title: new page.Text(''),
});
page.addBlock('affine:surface', {}, pageBlockId);
const frameId = page.addBlock('affine:frame', {}, pageBlockId);
page.addBlock('affine:paragraph', {}, frameId);
}
export function _initPageWithDemoMarkdown(page: Page): void {
console.debug('initPageWithDefaultMarkdown', page.id);
const pageBlockId = page.addBlock('affine:page', {
title: new page.Text(demoTitle),
});
page.addBlock('affine:surface', {}, pageBlockId);
const frameId = page.addBlock('affine:frame', {}, pageBlockId);
page.addBlock('affine:paragraph', {}, frameId);
const contentParser = new ContentParser(page);
contentParser.importMarkdown(demoText, frameId);
page.workspace.setPageMeta(page.id, { title: demoTitle });
}

View File

@@ -21,6 +21,7 @@ export const buildFlagsSchema = z.object({
enableDebugPage: z.boolean(),
enableLegacyCloud: z.boolean(),
changelogUrl: z.string(),
enablePreloading: z.boolean(),
});
export const blockSuiteFeatureFlags = z.object({

View File

@@ -3,7 +3,7 @@
*/
import 'fake-indexeddb/auto';
import { initPage } from '@affine/env/blocksuite';
import { initEmptyPage } from '@affine/env/blocksuite';
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
import { Workspace } from '@blocksuite/store';
import { renderHook } from '@testing-library/react';
@@ -20,9 +20,9 @@ beforeEach(() => {
})
.register(AffineSchemas)
.register(__unstableSchemas);
initPage(blockSuiteWorkspace.createPage({ id: 'page0' }));
initPage(blockSuiteWorkspace.createPage({ id: 'page1' }));
initPage(blockSuiteWorkspace.createPage({ id: 'page2' }));
initEmptyPage(blockSuiteWorkspace.createPage({ id: 'page0' }));
initEmptyPage(blockSuiteWorkspace.createPage({ id: 'page1' }));
initEmptyPage(blockSuiteWorkspace.createPage({ id: 'page2' }));
});
describe('useBlockSuiteWorkspaceHelper', () => {
@@ -50,7 +50,7 @@ describe('useBlockSuiteWorkspaceHelper', () => {
);
await helperHook.result.current.markMilestone('test');
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(3);
initPage(helperHook.result.current.createPage('page4'));
initEmptyPage(helperHook.result.current.createPage('page4'));
expect(blockSuiteWorkspace.meta.pageMetas.length).toBe(4);
expect(await helperHook.result.current.listMilestone()).toHaveProperty(
'test'

View File

@@ -16,8 +16,6 @@ declare module '@blocksuite/store' {
updatedDate?: number;
mode?: 'page' | 'edgeless';
jumpOnce?: boolean;
// whether to create the page with the default template
init?: boolean;
// todo: support `number` in the future
isPublic?: boolean;
}

View File

@@ -7,11 +7,11 @@
"jotai": "^2.1.1"
},
"devDependencies": {
"@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/lit": "0.0.0-20230601101714-0d24ba91-nightly",
"@blocksuite/store": "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/lit": "0.0.0-20230606130340-805f430b-nightly",
"@blocksuite/store": "0.0.0-20230606130340-805f430b-nightly",
"lottie-web": "^5.12.0"
},
"peerDependencies": {

View File

@@ -13,11 +13,11 @@
"@affine/component": "workspace:*",
"@affine/env": "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/lit": "0.0.0-20230601101714-0d24ba91-nightly",
"@blocksuite/store": "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/lit": "0.0.0-20230606130340-805f430b-nightly",
"@blocksuite/store": "0.0.0-20230606130340-805f430b-nightly"
},
"devDependencies": {
"jotai": "^2.1.1"

View File

@@ -1,6 +1,6 @@
import { BlockSuiteEditor } from '@affine/component/block-suite-editor';
import { ImagePreviewModal } from '@affine/component/image-preview-modal';
import { initPage } from '@affine/env/blocksuite';
import { initEmptyPage } from '@affine/env/blocksuite';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
import type { Meta } from '@storybook/react';
@@ -15,7 +15,7 @@ const workspace = createEmptyBlockSuiteWorkspace(
WorkspaceFlavour.LOCAL
);
const page = workspace.createPage('page0');
initPage(page);
initEmptyPage(page);
fetch(new URL('@affine-test/fixtures/large-image.png', import.meta.url))
.then(res => res.arrayBuffer())
.then(async buffer => {
@@ -49,7 +49,7 @@ export const Default = () => {
overflow: 'auto',
}}
>
<BlockSuiteEditor mode="page" page={page} onInit={initPage} />
<BlockSuiteEditor mode="page" page={page} onInit={initEmptyPage} />
</div>
<div
style={{

View File

@@ -3,7 +3,8 @@
"private": true,
"sideEffect": false,
"exports": {
"./*.md": "./src/*.md"
"./*.md": "./*.md",
"./preloading.json": "./preloading.json"
},
"version": "0.6.0"
}

File diff suppressed because it is too large Load Diff

View File

@@ -28,8 +28,8 @@
"idb": "^7.1.1"
},
"devDependencies": {
"@blocksuite/blocks": "0.0.0-20230601101714-0d24ba91-nightly",
"@blocksuite/store": "0.0.0-20230601101714-0d24ba91-nightly",
"@blocksuite/blocks": "0.0.0-20230606130340-805f430b-nightly",
"@blocksuite/store": "0.0.0-20230606130340-805f430b-nightly",
"vite": "^4.3.9",
"vite-plugin-dts": "^2.3.0",
"y-indexeddb": "^9.0.11"

View File

@@ -3,7 +3,7 @@
*/
import 'fake-indexeddb/auto';
import { initPage } from '@affine/env/blocksuite';
import { initEmptyPage } from '@affine/env/blocksuite';
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
import { assertExists, uuidv4, Workspace } from '@blocksuite/store';
import { openDB } from 'idb';
@@ -375,7 +375,7 @@ describe('milestone', () => {
describe('utils', () => {
test('download binary', async () => {
const page = workspace.createPage('page0');
initPage(page);
initEmptyPage(page);
const provider = createIndexedDBProvider(
workspace.id,
workspace.doc,