mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 05:25:53 +08:00
refactor(editor): extract notion html adapter to shared (#9341)
This commit is contained in:
@@ -33,6 +33,9 @@ export {
|
||||
BlockNotionHtmlAdapterMatcherIdentifier,
|
||||
type InlineDeltaToNotionHtmlAdapterMatcher,
|
||||
type NotionHtml,
|
||||
NotionHtmlAdapter,
|
||||
NotionHtmlAdapterFactoryExtension,
|
||||
NotionHtmlAdapterFactoryIdentifier,
|
||||
NotionHtmlASTToDeltaExtension,
|
||||
type NotionHtmlASTToDeltaMatcher,
|
||||
NotionHtmlASTToDeltaMatcherIdentifier,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './block-adapter.js';
|
||||
export * from './delta-converter.js';
|
||||
export * from './type.js';
|
||||
export * from './notion-html.js';
|
||||
|
||||
+17
-11
@@ -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';
|
||||
@@ -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;
|
||||
@@ -1 +0,0 @@
|
||||
export type NotionHtml = string;
|
||||
@@ -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,
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
HtmlAdapterFactoryExtension,
|
||||
NotionHtmlAdapterFactoryExtension,
|
||||
PlainTextAdapterFactoryExtension,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import type { ExtensionType } from '@blocksuite/block-std';
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import '@shoelace-style/shoelace/dist/themes/dark.css';
|
||||
import './left-side-panel.js';
|
||||
import './side-panel.js';
|
||||
|
||||
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import { ShadowlessElement } from '@blocksuite/block-std';
|
||||
import {
|
||||
@@ -35,7 +36,6 @@ import {
|
||||
HtmlTransformer,
|
||||
MarkdownAdapterFactoryIdentifier,
|
||||
MarkdownTransformer,
|
||||
NotionHtmlAdapter,
|
||||
NotionHtmlTransformer,
|
||||
openFileOrFiles,
|
||||
PlainTextAdapterFactoryIdentifier,
|
||||
@@ -435,7 +435,7 @@ export class StarterDebugMenu extends ShadowlessElement {
|
||||
collection: this.collection,
|
||||
middlewares: [defaultImageProxyMiddleware],
|
||||
});
|
||||
const htmlAdapter = new NotionHtmlAdapter(job);
|
||||
const htmlAdapter = new NotionHtmlAdapter(job, this.editor.std.provider);
|
||||
await htmlAdapter.toDoc({
|
||||
file: await file.text(),
|
||||
pageId: this.collection.idGenerator(),
|
||||
|
||||
Reference in New Issue
Block a user