mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-23 13:02:21 +08:00
refactor(editor): unify directories naming (#11516)
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import type { MarkdownAST } from '@blocksuite/affine-shared/adapters';
|
||||
|
||||
import {
|
||||
ElementModelAdapter,
|
||||
type ElementModelAdapterContext,
|
||||
} from '../../type.js';
|
||||
import type { ElementToMarkdownAdapterMatcher } from './type.js';
|
||||
|
||||
export class MarkdownElementModelAdapter extends ElementModelAdapter<
|
||||
MarkdownAST,
|
||||
MarkdownAST
|
||||
> {
|
||||
constructor(
|
||||
readonly elementModelMatchers: ElementToMarkdownAdapterMatcher[]
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
fromElementModel(
|
||||
element: Record<string, unknown>,
|
||||
context: ElementModelAdapterContext<MarkdownAST>
|
||||
) {
|
||||
const markdownAST: MarkdownAST | null = null;
|
||||
for (const matcher of this.elementModelMatchers) {
|
||||
if (matcher.match(element)) {
|
||||
return matcher.toAST(element, context);
|
||||
}
|
||||
}
|
||||
return markdownAST;
|
||||
}
|
||||
}
|
||||
|
||||
export * from './type.js';
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { ExtensionType } from '@blocksuite/affine/store';
|
||||
import type { MarkdownAST } from '@blocksuite/affine-shared/adapters';
|
||||
import {
|
||||
createIdentifier,
|
||||
type ServiceIdentifier,
|
||||
} from '@blocksuite/global/di';
|
||||
|
||||
import type { ElementModelMatcher } from '../../type.js';
|
||||
|
||||
export type ElementToMarkdownAdapterMatcher = ElementModelMatcher<MarkdownAST>;
|
||||
|
||||
export const ElementToMarkdownAdapterMatcherIdentifier =
|
||||
createIdentifier<ElementToMarkdownAdapterMatcher>(
|
||||
'elementToMarkdownAdapterMatcher'
|
||||
);
|
||||
|
||||
export function ElementToMarkdownAdapterExtension(
|
||||
matcher: ElementToMarkdownAdapterMatcher
|
||||
): ExtensionType & {
|
||||
identifier: ServiceIdentifier<ElementToMarkdownAdapterMatcher>;
|
||||
} {
|
||||
const identifier = ElementToMarkdownAdapterMatcherIdentifier(matcher.name);
|
||||
return {
|
||||
setup: di => {
|
||||
di.addImpl(identifier, () => matcher);
|
||||
},
|
||||
identifier,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user