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 { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { sha } from '@blocksuite/global/utils';
@@ -20,6 +19,8 @@ import {
type ToDocSnapshotPayload,
} from '@blocksuite/store';
import { AdapterFactoryIdentifier } from './types/adapter';
export type Attachment = File[];
type AttachmentToSliceSnapshotPayload = {

View File

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

View File

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

View File

@@ -1,6 +1,4 @@
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 { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { DeltaInsert } from '@blocksuite/inline';
@@ -17,6 +15,9 @@ import {
type SliceSnapshot,
} from '@blocksuite/store';
import type { AffineTextAttributes } from '../types';
import { AdapterFactoryIdentifier } from './types/adapter';
type NotionEditingStyle = {
0: string;
};

View File

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

View File

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

View File

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

View File

@@ -100,9 +100,18 @@ export {
} from '@blocksuite/affine-components/toolbar';
export * from '@blocksuite/affine-model';
export {
AttachmentAdapter,
AttachmentAdapterFactoryExtension,
AttachmentAdapterFactoryIdentifier,
HtmlAdapter,
HtmlAdapterFactoryExtension,
HtmlAdapterFactoryIdentifier,
ImageAdapter,
ImageAdapterFactoryExtension,
ImageAdapterFactoryIdentifier,
NotionTextAdapter,
NotionTextAdapterFactoryExtension,
NotionTextAdapterFactoryIdentifier,
PlainTextAdapter,
PlainTextAdapterFactoryExtension,
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 { DisposableGroup } from '@blocksuite/global/utils';
import type { BlockSnapshot, Doc } from '@blocksuite/store';
import {
AttachmentAdapter,
ImageAdapter,
MixTextAdapter,
NotionTextAdapter,
} from '../../_common/adapters/index.js';
import { MixTextAdapter } from '../../_common/adapters/index.js';
import {
defaultImageProxyMiddleware,
replaceIdMiddleware,