mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-24 05:07:06 +08:00
refactor(editor): rename job to transformer (#9639)
This commit is contained in:
@@ -12,11 +12,11 @@ import {
|
||||
type FromDocSnapshotResult,
|
||||
type FromSliceSnapshotPayload,
|
||||
type FromSliceSnapshotResult,
|
||||
type Job,
|
||||
nanoid,
|
||||
type SliceSnapshot,
|
||||
type ToBlockSnapshotPayload,
|
||||
type ToDocSnapshotPayload,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { AdapterFactoryIdentifier } from './types/adapter';
|
||||
@@ -132,7 +132,7 @@ export const AttachmentAdapterFactoryIdentifier =
|
||||
export const AttachmentAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(AttachmentAdapterFactoryIdentifier, () => ({
|
||||
get: (job: Job) => new AttachmentAdapter(job),
|
||||
get: (job: Transformer) => new AttachmentAdapter(job),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,11 +14,11 @@ import {
|
||||
type FromDocSnapshotResult,
|
||||
type FromSliceSnapshotPayload,
|
||||
type FromSliceSnapshotResult,
|
||||
type Job,
|
||||
nanoid,
|
||||
type SliceSnapshot,
|
||||
type ToBlockSnapshotPayload,
|
||||
type ToDocSnapshotPayload,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
import type { Root } from 'hast';
|
||||
import rehypeParse from 'rehype-parse';
|
||||
@@ -172,7 +172,7 @@ export class HtmlAdapter extends BaseAdapter<Html> {
|
||||
|
||||
readonly blockMatchers: BlockHtmlAdapterMatcher[];
|
||||
|
||||
constructor(job: Job, provider: ServiceProvider) {
|
||||
constructor(job: Transformer, provider: ServiceProvider) {
|
||||
super(job);
|
||||
const blockMatchers = Array.from(
|
||||
provider.getAll(BlockHtmlAdapterMatcherIdentifier).values()
|
||||
|
||||
@@ -12,11 +12,11 @@ import {
|
||||
type FromDocSnapshotResult,
|
||||
type FromSliceSnapshotPayload,
|
||||
type FromSliceSnapshotResult,
|
||||
type Job,
|
||||
nanoid,
|
||||
type SliceSnapshot,
|
||||
type ToBlockSnapshotPayload,
|
||||
type ToDocSnapshotPayload,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { AdapterFactoryIdentifier } from './types/adapter';
|
||||
@@ -123,7 +123,7 @@ export const ImageAdapterFactoryIdentifier = AdapterFactoryIdentifier('Image');
|
||||
export const ImageAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(ImageAdapterFactoryIdentifier, () => ({
|
||||
get: (job: Job) => new ImageAdapter(job),
|
||||
get: (job: Transformer) => new ImageAdapter(job),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,11 +14,11 @@ import {
|
||||
type FromDocSnapshotResult,
|
||||
type FromSliceSnapshotPayload,
|
||||
type FromSliceSnapshotResult,
|
||||
type Job,
|
||||
nanoid,
|
||||
type SliceSnapshot,
|
||||
type ToBlockSnapshotPayload,
|
||||
type ToDocSnapshotPayload,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
import type { Root } from 'mdast';
|
||||
import remarkMath from 'remark-math';
|
||||
@@ -171,7 +171,7 @@ export class MarkdownAdapter extends BaseAdapter<Markdown> {
|
||||
readonly blockMatchers: BlockMarkdownAdapterMatcher[];
|
||||
|
||||
constructor(
|
||||
job: Job,
|
||||
job: Transformer,
|
||||
readonly provider: ServiceProvider
|
||||
) {
|
||||
super(job);
|
||||
@@ -456,7 +456,7 @@ export const MarkdownAdapterFactoryIdentifier =
|
||||
export const MarkdownAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(MarkdownAdapterFactoryIdentifier, provider => ({
|
||||
get: (job: Job) => new MarkdownAdapter(job, provider),
|
||||
get: (job: Transformer) => new MarkdownAdapter(job, provider),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DraftModel,
|
||||
JobMiddleware,
|
||||
JobSlots,
|
||||
TransformerMiddleware,
|
||||
TransformerSlots,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from '../../utils';
|
||||
@@ -33,7 +33,7 @@ const handlePoint = (
|
||||
model.text?.sliceToDelta(index, length + index);
|
||||
};
|
||||
|
||||
const sliceText = (slots: JobSlots, std: EditorHost['std']) => {
|
||||
const sliceText = (slots: TransformerSlots, std: EditorHost['std']) => {
|
||||
slots.afterExport.on(payload => {
|
||||
if (payload.type === 'block') {
|
||||
const snapshot = payload.snapshot;
|
||||
@@ -52,7 +52,7 @@ const sliceText = (slots: JobSlots, std: EditorHost['std']) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const copyMiddleware = (std: BlockStdScope): JobMiddleware => {
|
||||
export const copyMiddleware = (std: BlockStdScope): TransformerMiddleware => {
|
||||
return ({ slots }) => {
|
||||
sliceText(slots, std);
|
||||
};
|
||||
|
||||
@@ -19,9 +19,9 @@ import {
|
||||
type BlockSnapshot,
|
||||
type DeltaOperation,
|
||||
fromJSON,
|
||||
type JobMiddleware,
|
||||
type SliceSnapshot,
|
||||
type Text,
|
||||
type TransformerMiddleware,
|
||||
} from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
@@ -505,7 +505,9 @@ function flatNote(snapshot: SliceSnapshot) {
|
||||
}
|
||||
}
|
||||
|
||||
export const pasteMiddleware = (std: EditorHost['std']): JobMiddleware => {
|
||||
export const pasteMiddleware = (
|
||||
std: EditorHost['std']
|
||||
): TransformerMiddleware => {
|
||||
return ({ slots }) => {
|
||||
let tr: PasteTr | undefined;
|
||||
slots.beforeImport.on(payload => {
|
||||
|
||||
@@ -15,11 +15,11 @@ import {
|
||||
type FromDocSnapshotResult,
|
||||
type FromSliceSnapshotPayload,
|
||||
type FromSliceSnapshotResult,
|
||||
type Job,
|
||||
nanoid,
|
||||
type SliceSnapshot,
|
||||
type ToBlockSnapshotPayload,
|
||||
type ToDocSnapshotPayload,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { MarkdownAdapter } from './markdown/markdown';
|
||||
@@ -37,7 +37,7 @@ type MixTextToSliceSnapshotPayload = {
|
||||
export class MixTextAdapter extends BaseAdapter<MixText> {
|
||||
private readonly _markdownAdapter: MarkdownAdapter;
|
||||
|
||||
constructor(job: Job, provider: ServiceProvider) {
|
||||
constructor(job: Transformer, provider: ServiceProvider) {
|
||||
super(job);
|
||||
this._markdownAdapter = new MarkdownAdapter(job, provider);
|
||||
}
|
||||
@@ -354,7 +354,7 @@ export const MixTextAdapterFactoryIdentifier =
|
||||
export const MixTextAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(MixTextAdapterFactoryIdentifier, provider => ({
|
||||
get: (job: Job) => new MixTextAdapter(job, provider),
|
||||
get: (job: Transformer) => new MixTextAdapter(job, provider),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,9 +14,9 @@ import {
|
||||
type FromDocSnapshotResult,
|
||||
type FromSliceSnapshotPayload,
|
||||
type FromSliceSnapshotResult,
|
||||
type Job,
|
||||
nanoid,
|
||||
type SliceSnapshot,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
import rehypeParse from 'rehype-parse';
|
||||
import { unified } from 'unified';
|
||||
@@ -115,7 +115,7 @@ export class NotionHtmlAdapter extends BaseAdapter<NotionHtml> {
|
||||
|
||||
readonly blockMatchers: BlockNotionHtmlAdapterMatcher[];
|
||||
|
||||
constructor(job: Job, provider: ServiceProvider) {
|
||||
constructor(job: Transformer, provider: ServiceProvider) {
|
||||
super(job);
|
||||
const blockMatchers = Array.from(
|
||||
provider.getAll(BlockNotionHtmlAdapterMatcherIdentifier).values()
|
||||
@@ -294,7 +294,7 @@ export const NotionHtmlAdapterFactoryIdentifier =
|
||||
export const NotionHtmlAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(NotionHtmlAdapterFactoryIdentifier, provider => ({
|
||||
get: (job: Job) => new NotionHtmlAdapter(job, provider),
|
||||
get: (job: Transformer) => new NotionHtmlAdapter(job, provider),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -10,9 +10,9 @@ import {
|
||||
type FromBlockSnapshotResult,
|
||||
type FromDocSnapshotResult,
|
||||
type FromSliceSnapshotResult,
|
||||
type Job,
|
||||
nanoid,
|
||||
type SliceSnapshot,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import type { AffineTextAttributes } from '../types';
|
||||
@@ -164,7 +164,7 @@ export const NotionTextAdapterFactoryIdentifier =
|
||||
export const NotionTextAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(NotionTextAdapterFactoryIdentifier, () => ({
|
||||
get: (job: Job) => new NotionTextAdapter(job),
|
||||
get: (job: Transformer) => new NotionTextAdapter(job),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,11 +14,11 @@ import {
|
||||
type FromDocSnapshotResult,
|
||||
type FromSliceSnapshotPayload,
|
||||
type FromSliceSnapshotResult,
|
||||
type Job,
|
||||
nanoid,
|
||||
type SliceSnapshot,
|
||||
type ToBlockSnapshotPayload,
|
||||
type ToDocSnapshotPayload,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
@@ -50,7 +50,7 @@ export class PlainTextAdapter extends BaseAdapter<PlainText> {
|
||||
readonly blockMatchers: BlockPlainTextAdapterMatcher[];
|
||||
|
||||
constructor(
|
||||
job: Job,
|
||||
job: Transformer,
|
||||
readonly provider: ServiceProvider
|
||||
) {
|
||||
super(job);
|
||||
@@ -321,7 +321,7 @@ export const PlainTextAdapterFactoryIdentifier =
|
||||
export const PlainTextAdapterFactoryExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(PlainTextAdapterFactoryIdentifier, provider => ({
|
||||
get: (job: Job) => new PlainTextAdapter(job, provider),
|
||||
get: (job: Transformer) => new PlainTextAdapter(job, provider),
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
type BaseAdapter,
|
||||
type BlockSnapshot,
|
||||
BlockSnapshotSchema,
|
||||
type Job,
|
||||
type NodeProps,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import type { AffineTextAttributes } from '../../types/index.js';
|
||||
@@ -35,7 +35,7 @@ export type AdapterContext<
|
||||
walker: ASTWalker<ONode, TNode>;
|
||||
walkerContext: ASTWalkerContext<TNode>;
|
||||
configs: Map<string, string>;
|
||||
job: Job;
|
||||
job: Transformer;
|
||||
deltaConverter: TConverter;
|
||||
textBuffer: TextBuffer;
|
||||
provider?: ServiceProvider;
|
||||
@@ -174,7 +174,7 @@ export type ASTToDeltaMatcher<AST> = {
|
||||
|
||||
export type AdapterFactory = {
|
||||
// TODO(@chen): Make it return the specific adapter type
|
||||
get: (job: Job) => BaseAdapter;
|
||||
get: (job: Transformer) => BaseAdapter;
|
||||
};
|
||||
|
||||
export const AdapterFactoryIdentifier =
|
||||
|
||||
@@ -36,7 +36,7 @@ export class DNDAPIExtension extends Extension {
|
||||
const { docId, flavour = 'affine:embed-linked-doc', blockId } = options;
|
||||
|
||||
const slice = Slice.fromModels(this.std.store, []);
|
||||
const job = this.std.getJob();
|
||||
const job = this.std.getTransformer();
|
||||
const snapshot = job.sliceToSnapshot(slice);
|
||||
if (!snapshot) {
|
||||
console.error('Failed to convert slice to snapshot');
|
||||
|
||||
Reference in New Issue
Block a user