forked from toeverything/blocksuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: render spec poc (toeverything#6051)
- Loading branch information
1 parent
0f60e5d
commit 55f5733
Showing
13 changed files
with
139 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { noop } from '@blocksuite/global/utils'; | ||
|
||
import { SyncedBlockComponent } from './synced-block.js'; | ||
|
||
noop(SyncedBlockComponent); | ||
|
||
export * from './synced-block.js'; | ||
export * from './synced-model.js'; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { assertExists } from '@blocksuite/global/utils'; | ||
import { BlockElement } from '@blocksuite/lit'; | ||
import { css, html } from 'lit'; | ||
import { customElement } from 'lit/decorators.js'; | ||
|
||
import { DocEditorBlockSpecs } from '../_specs/_specs.js'; | ||
import type { SyncedBlockModel } from './synced-model.js'; | ||
|
||
@customElement('affine-synced') | ||
export class SyncedBlockComponent extends BlockElement<SyncedBlockModel> { | ||
static override styles = css` | ||
.affine-synced-block.selected { | ||
outline: 2px solid var(--affine-brand-color); | ||
outline-offset: -2px; | ||
} | ||
`; | ||
override render() { | ||
const page = this.std.workspace.getPage(this.model.pageId); | ||
assertExists(page); | ||
const selected = this.selected?.is('block'); | ||
return html`<div class="affine-synced-block ${selected ? 'selected' : ''}"> | ||
${this.host.renderSpecPortal(page, DocEditorBlockSpecs)} | ||
</div>`; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BlockModel, defineBlockSchema } from '@blocksuite/store'; | ||
|
||
export type SyncedBlockProps = { | ||
pageId: string; | ||
}; | ||
|
||
export const SyncedBlockSchema = defineBlockSchema({ | ||
flavour: 'affine:synced', | ||
props: (): SyncedBlockProps => ({ | ||
pageId: '', | ||
}), | ||
metadata: { | ||
version: 1, | ||
role: 'content', | ||
parent: ['affine:note'], | ||
}, | ||
}); | ||
|
||
export class SyncedBlockModel extends BlockModel<SyncedBlockProps> {} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { BlockSpec } from '@blocksuite/block-std'; | ||
import { literal } from 'lit/static-html.js'; | ||
|
||
import { SyncedBlockSchema } from './synced-model.js'; | ||
|
||
export const SyncedBlockSpec: BlockSpec = { | ||
schema: SyncedBlockSchema, | ||
view: { | ||
component: literal`affine-synced`, | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Text, type Workspace } from '@blocksuite/store'; | ||
|
||
import { type InitFn } from './utils'; | ||
|
||
export const synced: InitFn = async (workspace: Workspace, id: string) => { | ||
const pageA = workspace.getPage(id) ?? workspace.createPage({ id }); | ||
const pageB = workspace.createPage({ id: 'pageB' }); | ||
pageA.clear(); | ||
pageB.clear(); | ||
|
||
let syncedBlockId = ''; | ||
|
||
await pageB.load(() => { | ||
// Add page block and surface block at root level | ||
const pageBlockId = pageB.addBlock('affine:page', { | ||
title: new Text('Page B'), | ||
}); | ||
|
||
pageB.addBlock('affine:surface', {}, pageBlockId); | ||
|
||
// Add note block inside page block | ||
const noteId = pageB.addBlock('affine:note', {}, pageBlockId); | ||
// Add paragraph block inside note block | ||
pageB.addBlock('affine:paragraph', { text: new Text('QAQ') }, noteId); | ||
syncedBlockId = noteId; | ||
}); | ||
|
||
await pageA.load(() => { | ||
// Add page block and surface block at root level | ||
const pageBlockId = pageA.addBlock('affine:page', { | ||
title: new Text(), | ||
}); | ||
|
||
pageA.addBlock('affine:surface', {}, pageBlockId); | ||
const noteId = pageA.addBlock('affine:note', {}, pageBlockId); | ||
|
||
pageA.addBlock( | ||
'affine:synced', | ||
{ | ||
pageId: 'pageB', | ||
blockId: syncedBlockId, | ||
}, | ||
noteId | ||
); | ||
}); | ||
|
||
pageB.resetHistory(); | ||
pageA.resetHistory(); | ||
}; | ||
|
||
synced.id = 'synced'; | ||
synced.displayName = 'Synced block demo'; | ||
synced.description = 'A simple demo for synced block'; |
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