mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 00:26:51 +08:00
11aa6f63b2
[BS-898](https://linear.app/affine-design/issue/BS-898/move-ai-chat-block-to-affine) Should be merged after https://github.com/toeverything/blocksuite/pull/8420 merged and bumped.
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import type { SurfaceBlockProps } from '@blocksuite/affine/block-std/gfx';
|
|
import {
|
|
NoteDisplayMode,
|
|
type NoteProps,
|
|
type ParagraphProps,
|
|
type RootBlockProps,
|
|
} from '@blocksuite/affine/blocks';
|
|
import { type Doc, Text } from '@blocksuite/affine/store';
|
|
|
|
export interface DocProps {
|
|
page?: Partial<RootBlockProps>;
|
|
surface?: Partial<SurfaceBlockProps>;
|
|
note?: Partial<NoteProps>;
|
|
paragraph?: Partial<ParagraphProps>;
|
|
}
|
|
|
|
export function initEmptyDoc(doc: Doc, title?: string) {
|
|
doc.load(() => {
|
|
initDocFromProps(doc, {
|
|
page: {
|
|
title: new Text(title),
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
export function initDocFromProps(doc: Doc, props?: DocProps) {
|
|
doc.load(() => {
|
|
const pageBlockId = doc.addBlock(
|
|
'affine:page',
|
|
props?.page || { title: new Text('') }
|
|
);
|
|
doc.addBlock('affine:surface' as never, props?.surface || {}, pageBlockId);
|
|
const noteBlockId = doc.addBlock(
|
|
'affine:note',
|
|
{
|
|
...props?.note,
|
|
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
},
|
|
pageBlockId
|
|
);
|
|
doc.addBlock('affine:paragraph', props?.paragraph || {}, noteBlockId);
|
|
doc.history.clear();
|
|
});
|
|
}
|