Skip to content

Commit

Permalink
refactor(editor): extract notion html adapter to shared
Browse files Browse the repository at this point in the history
  • Loading branch information
donteatfriedrice committed Dec 26, 2024
1 parent 6afa1d5 commit 2998336
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 21 deletions.
3 changes: 3 additions & 0 deletions blocksuite/affine/shared/src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export {
BlockNotionHtmlAdapterMatcherIdentifier,
type InlineDeltaToNotionHtmlAdapterMatcher,
type NotionHtml,
NotionHtmlAdapter,
NotionHtmlAdapterFactoryExtension,
NotionHtmlAdapterFactoryIdentifier,
NotionHtmlASTToDeltaExtension,
type NotionHtmlASTToDeltaMatcher,
NotionHtmlASTToDeltaMatcherIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion blocksuite/affine/shared/src/adapters/notion-html/index.ts
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 './notion-html.js';
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ import {
DEFAULT_NOTE_BACKGROUND_COLOR,
NoteDisplayMode,
} from '@blocksuite/affine-model';
import {
type AdapterContext,
AdapterFactoryIdentifier,
type BlockNotionHtmlAdapterMatcher,
BlockNotionHtmlAdapterMatcherIdentifier,
HastUtils,
type HtmlAST,
type NotionHtml,
NotionHtmlASTToDeltaMatcherIdentifier,
NotionHtmlDeltaConverter,
} from '@blocksuite/affine-shared/adapters';
import type { ExtensionType } from '@blocksuite/block-std';
import type { ServiceProvider } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
Expand All @@ -35,6 +24,23 @@ import {
import rehypeParse from 'rehype-parse';
import { unified } from 'unified';

import {
type AdapterContext,
AdapterFactoryIdentifier,
} from '../types/adapter';
import type { HtmlAST } from '../types/hast';
import { HastUtils } from '../utils/hast';
import {
type BlockNotionHtmlAdapterMatcher,
BlockNotionHtmlAdapterMatcherIdentifier,
} from './block-adapter';
import {
NotionHtmlASTToDeltaMatcherIdentifier,
NotionHtmlDeltaConverter,
} from './delta-converter';

export type NotionHtml = string;

type NotionHtmlToSliceSnapshotPayload = {
file: NotionHtml;
assets?: AssetsManager;
Expand Down
1 change: 0 additions & 1 deletion blocksuite/affine/shared/src/adapters/notion-html/type.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
DEFAULT_NOTE_BACKGROUND_COLOR,
NoteDisplayMode,
} from '@blocksuite/affine-model';
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
import { Container } from '@blocksuite/global/di';
import {
AssetsManager,
Expand All @@ -12,7 +13,6 @@ import { describe, expect, test } from 'vitest';

import { defaultBlockNotionHtmlAdapterMatchers } from '../../_common/adapters/notion-html/block-matcher.js';
import { notionHtmlInlineToDeltaMatchers } from '../../_common/adapters/notion-html/delta-converter/html-inline.js';
import { NotionHtmlAdapter } from '../../_common/adapters/notion-html/notion-html.js';
import { nanoidReplacement } from '../../_common/test-utils/test-utils.js';
import { createJob } from '../utils/create-job.js';

Expand Down
2 changes: 1 addition & 1 deletion blocksuite/blocks/src/_common/adapters/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
HtmlAdapterFactoryExtension,
NotionHtmlAdapterFactoryExtension,
PlainTextAdapterFactoryExtension,
} from '@blocksuite/affine-shared/adapters';
import type { ExtensionType } from '@blocksuite/block-std';
Expand All @@ -11,7 +12,6 @@ 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 { NotionHtmlAdapterFactoryExtension } from './notion-html/notion-html.js';
import { NotionTextAdapterFactoryExtension } from './notion-text.js';
import { inlineDeltaToPlainTextAdapterMatchers } from './plain-text/delta-converter/inline-delta.js';

Expand Down
6 changes: 1 addition & 5 deletions blocksuite/blocks/src/_common/adapters/notion-html/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
export { defaultBlockNotionHtmlAdapterMatchers } from './block-matcher.js';
export {
NotionHtmlAdapter,
NotionHtmlAdapterFactoryExtension,
NotionHtmlAdapterFactoryIdentifier,
} from './notion-html.js';
export { notionHtmlInlineToDeltaMatchers } from './delta-converter/html-inline.js';
2 changes: 1 addition & 1 deletion blocksuite/blocks/src/_common/transformers/notion-html.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
import { Container } from '@blocksuite/global/di';
import { sha } from '@blocksuite/global/utils';
import { type DocCollection, extMimeMap, Job } from '@blocksuite/store';

import { defaultBlockNotionHtmlAdapterMatchers } from '../adapters/notion-html/block-matcher.js';
import { notionHtmlInlineToDeltaMatchers } from '../adapters/notion-html/delta-converter/html-inline.js';
import { NotionHtmlAdapter } from '../adapters/notion-html/notion-html.js';
import { defaultImageProxyMiddleware } from './middlewares.js';
import { Unzip } from './utils.js';

Expand Down
3 changes: 3 additions & 0 deletions blocksuite/blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export {
HtmlAdapter,
HtmlAdapterFactoryExtension,
HtmlAdapterFactoryIdentifier,
NotionHtmlAdapter,
NotionHtmlAdapterFactoryExtension,
NotionHtmlAdapterFactoryIdentifier,
PlainTextAdapter,
PlainTextAdapterFactoryExtension,
PlainTextAdapterFactoryIdentifier,
Expand Down

0 comments on commit 2998336

Please sign in to comment.