-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: default style of new document does not follow AFFiNE settings (#…
…8291) Close issue [BS-1377](https://linear.app/affine-design/issue/BS-1377). ### What changed? - Add `initDocFromProps` function to initialize the document with specific props. - Extract `docProps` from editor settings and pass it to `docsService.createDoc` function. <div class='graphite__hidden'> <div>🎥 Video uploaded on Graphite:</div> <a href="https://app.graphite.dev/media/video/sJGviKxfE3Ap685cl5bj/8082a8bd-ab3d-432c-9d3e-2f1d1a8398eb.mov"> <img src="https://app.graphite.dev/api/v1/graphite/video/thumbnail/sJGviKxfE3Ap685cl5bj/8082a8bd-ab3d-432c-9d3e-2f1d1a8398eb.mov"> </a> </div> <video src="https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/sJGviKxfE3Ap685cl5bj/8082a8bd-ab3d-432c-9d3e-2f1d1a8398eb.mov">录屏2024-09-18 16.13.43.mov</video>
- Loading branch information
Showing
6 changed files
with
91 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,45 @@ | ||
import type { Doc } from '@blocksuite/store'; | ||
import type { SurfaceBlockProps } from '@blocksuite/block-std/gfx'; | ||
import { | ||
NoteDisplayMode, | ||
type NoteProps, | ||
type ParagraphProps, | ||
type RootBlockProps, | ||
} from '@blocksuite/blocks'; | ||
import { type Doc, Text } from '@blocksuite/store'; | ||
|
||
export function initEmptyPage(page: Doc, title?: string) { | ||
page.load(() => { | ||
const pageBlockId = page.addBlock( | ||
'affine:page' as keyof BlockSuite.BlockModels, | ||
{ | ||
title: new page.Text(title ?? ''), | ||
} | ||
); | ||
page.addBlock( | ||
'affine:surface' as keyof BlockSuite.BlockModels, | ||
{}, | ||
pageBlockId | ||
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('') } | ||
); | ||
const noteBlockId = page.addBlock( | ||
'affine:note' as keyof BlockSuite.BlockModels, | ||
{}, | ||
doc.addBlock('affine:surface', props?.surface || {}, pageBlockId); | ||
const noteBlockId = doc.addBlock( | ||
'affine:note', | ||
{ | ||
...props?.note, | ||
displayMode: NoteDisplayMode.DocAndEdgeless, | ||
}, | ||
pageBlockId | ||
); | ||
page.addBlock( | ||
'affine:paragraph' as keyof BlockSuite.BlockModels, | ||
{}, | ||
noteBlockId | ||
); | ||
page.history.clear(); | ||
doc.addBlock('affine:paragraph', props?.paragraph || {}, noteBlockId); | ||
doc.history.clear(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters