refactor(editor): extract adapters to shared (#9344)

Extract AttachmentAdapter, ImageAdapter, NotionTextAdapter to shared.
This commit is contained in:
donteatfriedrice
2024-12-27 08:52:03 +00:00
parent 153c1b2c55
commit fee86304ae
9 changed files with 30 additions and 18 deletions

View File

@@ -1,4 +1,3 @@
import { AdapterFactoryIdentifier } from '@blocksuite/affine-shared/adapters';
import type { ExtensionType } from '@blocksuite/block-std'; import type { ExtensionType } from '@blocksuite/block-std';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { sha } from '@blocksuite/global/utils'; import { sha } from '@blocksuite/global/utils';
@@ -20,6 +19,8 @@ import {
type ToDocSnapshotPayload, type ToDocSnapshotPayload,
} from '@blocksuite/store'; } from '@blocksuite/store';
import { AdapterFactoryIdentifier } from './types/adapter';
export type Attachment = File[]; export type Attachment = File[];
type AttachmentToSliceSnapshotPayload = { type AttachmentToSliceSnapshotPayload = {

View File

@@ -1,4 +1,3 @@
import { AdapterFactoryIdentifier } from '@blocksuite/affine-shared/adapters';
import type { ExtensionType } from '@blocksuite/block-std'; import type { ExtensionType } from '@blocksuite/block-std';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { sha } from '@blocksuite/global/utils'; import { sha } from '@blocksuite/global/utils';
@@ -20,6 +19,8 @@ import {
type ToDocSnapshotPayload, type ToDocSnapshotPayload,
} from '@blocksuite/store'; } from '@blocksuite/store';
import { AdapterFactoryIdentifier } from './types/adapter';
export type Image = File[]; export type Image = File[];
type ImageToSliceSnapshotPayload = { type ImageToSliceSnapshotPayload = {

View File

@@ -1,3 +1,4 @@
export * from './attachment';
export { export {
BlockHtmlAdapterExtension, BlockHtmlAdapterExtension,
type BlockHtmlAdapterMatcher, type BlockHtmlAdapterMatcher,
@@ -14,6 +15,7 @@ export {
type InlineDeltaToHtmlAdapterMatcher, type InlineDeltaToHtmlAdapterMatcher,
InlineDeltaToHtmlAdapterMatcherIdentifier, InlineDeltaToHtmlAdapterMatcherIdentifier,
} from './html'; } from './html';
export * from './image';
export { export {
BlockMarkdownAdapterExtension, BlockMarkdownAdapterExtension,
type BlockMarkdownAdapterMatcher, type BlockMarkdownAdapterMatcher,
@@ -41,6 +43,7 @@ export {
NotionHtmlASTToDeltaMatcherIdentifier, NotionHtmlASTToDeltaMatcherIdentifier,
NotionHtmlDeltaConverter, NotionHtmlDeltaConverter,
} from './notion-html'; } from './notion-html';
export * from './notion-text';
export { export {
BlockPlainTextAdapterExtension, BlockPlainTextAdapterExtension,
type BlockPlainTextAdapterMatcher, type BlockPlainTextAdapterMatcher,

View File

@@ -1,6 +1,4 @@
import { DEFAULT_NOTE_BACKGROUND_COLOR } from '@blocksuite/affine-model'; import { DEFAULT_NOTE_BACKGROUND_COLOR } from '@blocksuite/affine-model';
import { AdapterFactoryIdentifier } from '@blocksuite/affine-shared/adapters';
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
import type { ExtensionType } from '@blocksuite/block-std'; import type { ExtensionType } from '@blocksuite/block-std';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { DeltaInsert } from '@blocksuite/inline'; import type { DeltaInsert } from '@blocksuite/inline';
@@ -17,6 +15,9 @@ import {
type SliceSnapshot, type SliceSnapshot,
} from '@blocksuite/store'; } from '@blocksuite/store';
import type { AffineTextAttributes } from '../types';
import { AdapterFactoryIdentifier } from './types/adapter';
type NotionEditingStyle = { type NotionEditingStyle = {
0: string; 0: string;
}; };

View File

@@ -1,8 +1,8 @@
import { DEFAULT_NOTE_BACKGROUND_COLOR } from '@blocksuite/affine-model'; import { DEFAULT_NOTE_BACKGROUND_COLOR } from '@blocksuite/affine-model';
import { NotionTextAdapter } from '@blocksuite/affine-shared/adapters';
import type { SliceSnapshot } from '@blocksuite/store'; import type { SliceSnapshot } from '@blocksuite/store';
import { describe, expect, test } from 'vitest'; import { describe, expect, test } from 'vitest';
import { NotionTextAdapter } from '../../_common/adapters/notion-text.js';
import { nanoidReplacement } from '../../_common/test-utils/test-utils.js'; import { nanoidReplacement } from '../../_common/test-utils/test-utils.js';
import { createJob } from '../utils/create-job.js'; import { createJob } from '../utils/create-job.js';

View File

@@ -1,18 +1,18 @@
import { import {
AttachmentAdapterFactoryExtension,
HtmlAdapterFactoryExtension, HtmlAdapterFactoryExtension,
ImageAdapterFactoryExtension,
NotionHtmlAdapterFactoryExtension, NotionHtmlAdapterFactoryExtension,
NotionTextAdapterFactoryExtension,
PlainTextAdapterFactoryExtension, PlainTextAdapterFactoryExtension,
} from '@blocksuite/affine-shared/adapters'; } from '@blocksuite/affine-shared/adapters';
import type { ExtensionType } from '@blocksuite/block-std'; import type { ExtensionType } from '@blocksuite/block-std';
import { AttachmentAdapterFactoryExtension } from './attachment.js';
import { htmlInlineToDeltaMatchers } from './html/delta-converter/html-inline.js'; import { htmlInlineToDeltaMatchers } from './html/delta-converter/html-inline.js';
import { inlineDeltaToHtmlAdapterMatchers } from './html/delta-converter/inline-delta.js'; import { inlineDeltaToHtmlAdapterMatchers } from './html/delta-converter/inline-delta.js';
import { ImageAdapterFactoryExtension } from './image.js';
import { MarkdownAdapterFactoryExtension } from './markdown/markdown.js'; import { MarkdownAdapterFactoryExtension } from './markdown/markdown.js';
import { MixTextAdapterFactoryExtension } from './mix-text.js'; import { MixTextAdapterFactoryExtension } from './mix-text.js';
import { notionHtmlInlineToDeltaMatchers } from './notion-html/delta-converter/html-inline.js'; import { notionHtmlInlineToDeltaMatchers } from './notion-html/delta-converter/html-inline.js';
import { NotionTextAdapterFactoryExtension } from './notion-text.js';
import { inlineDeltaToPlainTextAdapterMatchers } from './plain-text/delta-converter/inline-delta.js'; import { inlineDeltaToPlainTextAdapterMatchers } from './plain-text/delta-converter/inline-delta.js';
export const AdapterFactoryExtensions: ExtensionType[] = [ export const AdapterFactoryExtensions: ExtensionType[] = [

View File

@@ -1,7 +1,4 @@
export * from './attachment.js';
export * from './extension.js'; export * from './extension.js';
export * from './image.js';
export * from './markdown/index.js'; export * from './markdown/index.js';
export * from './mix-text.js'; export * from './mix-text.js';
export * from './notion-html/index.js'; export * from './notion-html/index.js';
export * from './notion-text.js';

View File

@@ -100,9 +100,18 @@ export {
} from '@blocksuite/affine-components/toolbar'; } from '@blocksuite/affine-components/toolbar';
export * from '@blocksuite/affine-model'; export * from '@blocksuite/affine-model';
export { export {
AttachmentAdapter,
AttachmentAdapterFactoryExtension,
AttachmentAdapterFactoryIdentifier,
HtmlAdapter, HtmlAdapter,
HtmlAdapterFactoryExtension, HtmlAdapterFactoryExtension,
HtmlAdapterFactoryIdentifier, HtmlAdapterFactoryIdentifier,
ImageAdapter,
ImageAdapterFactoryExtension,
ImageAdapterFactoryIdentifier,
NotionTextAdapter,
NotionTextAdapterFactoryExtension,
NotionTextAdapterFactoryIdentifier,
PlainTextAdapter, PlainTextAdapter,
PlainTextAdapterFactoryExtension, PlainTextAdapterFactoryExtension,
PlainTextAdapterFactoryIdentifier, PlainTextAdapterFactoryIdentifier,

View File

@@ -1,14 +1,14 @@
import { HtmlAdapter } from '@blocksuite/affine-shared/adapters'; import {
AttachmentAdapter,
HtmlAdapter,
ImageAdapter,
NotionTextAdapter,
} from '@blocksuite/affine-shared/adapters';
import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std'; import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std';
import { DisposableGroup } from '@blocksuite/global/utils'; import { DisposableGroup } from '@blocksuite/global/utils';
import type { BlockSnapshot, Doc } from '@blocksuite/store'; import type { BlockSnapshot, Doc } from '@blocksuite/store';
import { import { MixTextAdapter } from '../../_common/adapters/index.js';
AttachmentAdapter,
ImageAdapter,
MixTextAdapter,
NotionTextAdapter,
} from '../../_common/adapters/index.js';
import { import {
defaultImageProxyMiddleware, defaultImageProxyMiddleware,
replaceIdMiddleware, replaceIdMiddleware,