-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(editor): extensionalize plain text adapter (#9330)
- Loading branch information
1 parent
45acdbd
commit cadb921
Showing
27 changed files
with
226 additions
and
120 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
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,4 @@ | ||
export { | ||
EdgelessSurfaceBlockAdapterExtensions, | ||
SurfaceBlockAdapterExtensions, | ||
} from './extension.js'; |
8 changes: 4 additions & 4 deletions
8
blocksuite/affine/block-surface/src/adapters/plain-text/element-adapter/elements/brush.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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import type { ElementModelToPlainTextAdapterMatcher } from '../type.js'; | ||
import { ElementToPlainTextAdapterExtension } from '../type.js'; | ||
|
||
export const brushToPlainTextAdapterMatcher: ElementModelToPlainTextAdapterMatcher = | ||
{ | ||
export const brushToPlainTextAdapterMatcher = | ||
ElementToPlainTextAdapterExtension({ | ||
name: 'brush', | ||
match: elementModel => elementModel.type === 'brush', | ||
toAST: () => { | ||
const content = `Brush Stroke`; | ||
return { content }; | ||
}, | ||
}; | ||
}); |
8 changes: 4 additions & 4 deletions
8
...ksuite/affine/block-surface/src/adapters/plain-text/element-adapter/elements/connector.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { getConnectorText } from '../../../utils/text.js'; | ||
import type { ElementModelToPlainTextAdapterMatcher } from '../type.js'; | ||
import { ElementToPlainTextAdapterExtension } from '../type.js'; | ||
|
||
export const connectorToPlainTextAdapterMatcher: ElementModelToPlainTextAdapterMatcher = | ||
{ | ||
export const connectorToPlainTextAdapterMatcher = | ||
ElementToPlainTextAdapterExtension({ | ||
name: 'connector', | ||
match: elementModel => elementModel.type === 'connector', | ||
toAST: elementModel => { | ||
const text = getConnectorText(elementModel); | ||
const content = `Connector, with text label "${text}"`; | ||
return { content }; | ||
}, | ||
}; | ||
}); |
8 changes: 4 additions & 4 deletions
8
blocksuite/affine/block-surface/src/adapters/plain-text/element-adapter/elements/group.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { getGroupTitle } from '../../../utils/text.js'; | ||
import type { ElementModelToPlainTextAdapterMatcher } from '../type.js'; | ||
import { ElementToPlainTextAdapterExtension } from '../type.js'; | ||
|
||
export const groupToPlainTextAdapterMatcher: ElementModelToPlainTextAdapterMatcher = | ||
{ | ||
export const groupToPlainTextAdapterMatcher = | ||
ElementToPlainTextAdapterExtension({ | ||
name: 'group', | ||
match: elementModel => elementModel.type === 'group', | ||
toAST: elementModel => { | ||
const title = getGroupTitle(elementModel); | ||
const content = `Group, with title "${title}"`; | ||
return { content }; | ||
}, | ||
}; | ||
}); |
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
8 changes: 4 additions & 4 deletions
8
blocksuite/affine/block-surface/src/adapters/plain-text/element-adapter/elements/mindmap.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { getMindMapTreeText } from '../../../utils/text.js'; | ||
import type { ElementModelToPlainTextAdapterMatcher } from '../type.js'; | ||
import { ElementToPlainTextAdapterExtension } from '../type.js'; | ||
|
||
export const mindmapToPlainTextAdapterMatcher: ElementModelToPlainTextAdapterMatcher = | ||
{ | ||
export const mindmapToPlainTextAdapterMatcher = | ||
ElementToPlainTextAdapterExtension({ | ||
name: 'mindmap', | ||
match: elementModel => elementModel.type === 'mindmap', | ||
toAST: (elementModel, context) => { | ||
const mindMapContent = getMindMapTreeText(elementModel, context.elements); | ||
return { content: mindMapContent }; | ||
}, | ||
}; | ||
}); |
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
7 changes: 4 additions & 3 deletions
7
blocksuite/affine/block-surface/src/adapters/plain-text/element-adapter/elements/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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { getTextElementText } from '../../../utils/text.js'; | ||
import type { ElementModelToPlainTextAdapterMatcher } from '../type.js'; | ||
import { ElementToPlainTextAdapterExtension } from '../type.js'; | ||
|
||
export const textToPlainTextAdapterMatcher: ElementModelToPlainTextAdapterMatcher = | ||
export const textToPlainTextAdapterMatcher = ElementToPlainTextAdapterExtension( | ||
{ | ||
name: 'text', | ||
match: elementModel => elementModel.type === 'text', | ||
toAST: elementModel => { | ||
const content = getTextElementText(elementModel); | ||
return { content }; | ||
}, | ||
}; | ||
} | ||
); |
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
27 changes: 25 additions & 2 deletions
27
blocksuite/affine/block-surface/src/adapters/plain-text/element-adapter/type.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 |
---|---|---|
@@ -1,6 +1,29 @@ | ||
import type { TextBuffer } from '@blocksuite/affine-shared/adapters'; | ||
import type { ExtensionType } from '@blocksuite/block-std'; | ||
import { | ||
createIdentifier, | ||
type ServiceIdentifier, | ||
} from '@blocksuite/global/di'; | ||
|
||
import type { ElementModelMatcher } from '../../type.js'; | ||
|
||
export type ElementModelToPlainTextAdapterMatcher = | ||
ElementModelMatcher<TextBuffer>; | ||
export type ElementToPlainTextAdapterMatcher = ElementModelMatcher<TextBuffer>; | ||
|
||
export const ElementToPlainTextAdapterMatcherIdentifier = | ||
createIdentifier<ElementToPlainTextAdapterMatcher>( | ||
'elementToPlainTextAdapterMatcher' | ||
); | ||
|
||
export function ElementToPlainTextAdapterExtension( | ||
matcher: ElementToPlainTextAdapterMatcher | ||
): ExtensionType & { | ||
identifier: ServiceIdentifier<ElementToPlainTextAdapterMatcher>; | ||
} { | ||
const identifier = ElementToPlainTextAdapterMatcherIdentifier(matcher.name); | ||
return { | ||
setup: di => { | ||
di.addImpl(identifier, () => matcher); | ||
}, | ||
identifier, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './block-adapter.js'; | ||
export * from './delta-converter.js'; | ||
export * from './type.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
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.