Skip to content

Commit

Permalink
refactor(editor): extrac adapters to shared
Browse files Browse the repository at this point in the history
  • Loading branch information
donteatfriedrice committed Dec 27, 2024
1 parent 47c7e2f commit 807f008
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,6 +19,8 @@ import {
type ToDocSnapshotPayload,
} from '@blocksuite/store';

import { AdapterFactoryIdentifier } from './types/adapter';

export type Attachment = File[];

type AttachmentToSliceSnapshotPayload = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,6 +19,8 @@ import {
type ToDocSnapshotPayload,
} from '@blocksuite/store';

import { AdapterFactoryIdentifier } from './types/adapter';

export type Image = File[];

type ImageToSliceSnapshotPayload = {
Expand Down
3 changes: 3 additions & 0 deletions blocksuite/affine/shared/src/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './attachment';
export {
BlockHtmlAdapterExtension,
type BlockHtmlAdapterMatcher,
Expand All @@ -14,6 +15,7 @@ export {
type InlineDeltaToHtmlAdapterMatcher,
InlineDeltaToHtmlAdapterMatcherIdentifier,
} from './html';
export * from './image';
export {
BlockMarkdownAdapterExtension,
type BlockMarkdownAdapterMatcher,
Expand Down Expand Up @@ -41,6 +43,7 @@ export {
NotionHtmlASTToDeltaMatcherIdentifier,
NotionHtmlDeltaConverter,
} from './notion-html';
export * from './notion-text';
export {
BlockPlainTextAdapterExtension,
type BlockPlainTextAdapterMatcher,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,6 +15,9 @@ import {
type SliceSnapshot,
} from '@blocksuite/store';

import type { AffineTextAttributes } from '../types';
import { AdapterFactoryIdentifier } from './types/adapter';

type NotionEditingStyle = {
0: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
6 changes: 3 additions & 3 deletions blocksuite/blocks/src/_common/adapters/extension.ts
Original file line number Diff line number Diff line change
@@ -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[] = [
Expand Down
3 changes: 0 additions & 3 deletions blocksuite/blocks/src/_common/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -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';
9 changes: 9 additions & 0 deletions blocksuite/blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions blocksuite/blocks/src/root-block/clipboard/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { HtmlAdapter } 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,
HtmlAdapter,
ImageAdapter,
MixTextAdapter,
NotionTextAdapter,
} from '../../_common/adapters/index.js';
} 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 { MixTextAdapter } from '../../_common/adapters/index.js';
import {
defaultImageProxyMiddleware,
replaceIdMiddleware,
Expand Down

0 comments on commit 807f008

Please sign in to comment.