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.
feat(blocks): add plain text block adapter for embed link block (toev…
- Loading branch information
1 parent
9c85bbc
commit cb349e7
Showing
19 changed files
with
232 additions
and
5 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/affine/block-embed/src/common/adapters/plain-text.ts
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,40 @@ | ||
import type { BlockPlainTextAdapterMatcher } from '@blocksuite/affine-shared/adapters'; | ||
|
||
export function createEmbedBlockPlainTextAdapterMatcher( | ||
flavour: string, | ||
{ | ||
toMatch = () => false, | ||
fromMatch = o => o.node.flavour === flavour, | ||
toBlockSnapshot = {}, | ||
fromBlockSnapshot = { | ||
enter: (o, context) => { | ||
const { textBuffer } = context; | ||
// Parse as link | ||
if ( | ||
typeof o.node.props.title !== 'string' || | ||
typeof o.node.props.url !== 'string' | ||
) { | ||
return; | ||
} | ||
const buffer = `[${o.node.props.title}](${o.node.props.url})`; | ||
if (buffer.length > 0) { | ||
textBuffer.content += buffer; | ||
textBuffer.content += '\n'; | ||
} | ||
}, | ||
}, | ||
}: { | ||
toMatch?: BlockPlainTextAdapterMatcher['toMatch']; | ||
fromMatch?: BlockPlainTextAdapterMatcher['fromMatch']; | ||
toBlockSnapshot?: BlockPlainTextAdapterMatcher['toBlockSnapshot']; | ||
fromBlockSnapshot?: BlockPlainTextAdapterMatcher['fromBlockSnapshot']; | ||
} = {} | ||
): BlockPlainTextAdapterMatcher { | ||
return { | ||
flavour, | ||
toMatch, | ||
fromMatch, | ||
toBlockSnapshot, | ||
fromBlockSnapshot, | ||
}; | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/affine/block-embed/src/embed-figma-block/adapters/index.ts
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,2 @@ | ||
export * from './markdown.js'; | ||
export * from './plain-text.js'; |
10 changes: 10 additions & 0 deletions
10
packages/affine/block-embed/src/embed-figma-block/adapters/plain-text.ts
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,10 @@ | ||
import { EmbedFigmaBlockSchema } from '@blocksuite/affine-model'; | ||
import { BlockPlainTextAdapterExtension } from '@blocksuite/affine-shared/adapters'; | ||
|
||
import { createEmbedBlockPlainTextAdapterMatcher } from '../../common/adapters/plain-text.js'; | ||
|
||
export const embedFigmaBlockPlainTextAdapterMatcher = | ||
createEmbedBlockPlainTextAdapterMatcher(EmbedFigmaBlockSchema.model.flavour); | ||
|
||
export const EmbedFigmaBlockPlainTextAdapterExtension = | ||
BlockPlainTextAdapterExtension(embedFigmaBlockPlainTextAdapterMatcher); |
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
2 changes: 2 additions & 0 deletions
2
packages/affine/block-embed/src/embed-github-block/adapters/index.ts
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,2 @@ | ||
export * from './markdown.js'; | ||
export * from './plain-text.js'; |
10 changes: 10 additions & 0 deletions
10
packages/affine/block-embed/src/embed-github-block/adapters/plain-text.ts
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,10 @@ | ||
import { EmbedGithubBlockSchema } from '@blocksuite/affine-model'; | ||
import { BlockPlainTextAdapterExtension } from '@blocksuite/affine-shared/adapters'; | ||
|
||
import { createEmbedBlockPlainTextAdapterMatcher } from '../../common/adapters/plain-text.js'; | ||
|
||
export const embedGithubBlockPlainTextAdapterMatcher = | ||
createEmbedBlockPlainTextAdapterMatcher(EmbedGithubBlockSchema.model.flavour); | ||
|
||
export const EmbedGithubBlockPlainTextAdapterExtension = | ||
BlockPlainTextAdapterExtension(embedGithubBlockPlainTextAdapterMatcher); |
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
2 changes: 2 additions & 0 deletions
2
packages/affine/block-embed/src/embed-loom-block/adapters/index.ts
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,2 @@ | ||
export * from './markdown.js'; | ||
export * from './plain-text.js'; |
10 changes: 10 additions & 0 deletions
10
packages/affine/block-embed/src/embed-loom-block/adapters/plain-text.ts
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,10 @@ | ||
import { EmbedLoomBlockSchema } from '@blocksuite/affine-model'; | ||
import { BlockPlainTextAdapterExtension } from '@blocksuite/affine-shared/adapters'; | ||
|
||
import { createEmbedBlockPlainTextAdapterMatcher } from '../../common/adapters/plain-text.js'; | ||
|
||
export const embedLoomBlockPlainTextAdapterMatcher = | ||
createEmbedBlockPlainTextAdapterMatcher(EmbedLoomBlockSchema.model.flavour); | ||
|
||
export const EmbedLoomBlockPlainTextAdapterExtension = | ||
BlockPlainTextAdapterExtension(embedLoomBlockPlainTextAdapterMatcher); |
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
2 changes: 2 additions & 0 deletions
2
packages/affine/block-embed/src/embed-youtube-block/adapters/index.ts
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,2 @@ | ||
export * from './markdown.js'; | ||
export * from './plain-text.js'; |
12 changes: 12 additions & 0 deletions
12
packages/affine/block-embed/src/embed-youtube-block/adapters/plain-text.ts
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,12 @@ | ||
import { EmbedYoutubeBlockSchema } from '@blocksuite/affine-model'; | ||
import { BlockPlainTextAdapterExtension } from '@blocksuite/affine-shared/adapters'; | ||
|
||
import { createEmbedBlockPlainTextAdapterMatcher } from '../../common/adapters/plain-text.js'; | ||
|
||
export const embedYoutubeBlockPlainTextAdapterMatcher = | ||
createEmbedBlockPlainTextAdapterMatcher( | ||
EmbedYoutubeBlockSchema.model.flavour | ||
); | ||
|
||
export const EmbedYoutubeBlockPlainTextAdapterExtension = | ||
BlockPlainTextAdapterExtension(embedYoutubeBlockPlainTextAdapterMatcher); |
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,2 @@ | ||
export * from './markdown.js'; | ||
export * from './plain-text.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,9 @@ | ||
import { createEmbedBlockPlainTextAdapterMatcher } from '@blocksuite/affine-block-embed'; | ||
import { BookmarkBlockSchema } from '@blocksuite/affine-model'; | ||
import { BlockPlainTextAdapterExtension } from '@blocksuite/affine-shared/adapters'; | ||
|
||
export const bookmarkBlockPlainTextAdapterMatcher = | ||
createEmbedBlockPlainTextAdapterMatcher(BookmarkBlockSchema.model.flavour); | ||
|
||
export const BookmarkBlockPlainTextAdapterExtension = | ||
BlockPlainTextAdapterExtension(bookmarkBlockPlainTextAdapterMatcher); |
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,3 +1,3 @@ | ||
export * from './adapters/markdown.js'; | ||
export * from './adapters/index.js'; | ||
export * from './bookmark-block.js'; | ||
export * from './bookmark-service.js'; |