mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
feat: add preloading template (#2655)
Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
53
packages/env/src/blocksuite/index.ts
vendored
53
packages/env/src/blocksuite/index.ts
vendored
@@ -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 });
|
||||
}
|
||||
|
||||
1
packages/env/src/config.ts
vendored
1
packages/env/src/config.ts
vendored
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user