mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
refactor(editor): rename job to transformer (#9639)
This commit is contained in:
@@ -3,10 +3,10 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import type {
|
||||
BaseAdapter,
|
||||
BlockSnapshot,
|
||||
Job,
|
||||
JobMiddleware,
|
||||
Slice,
|
||||
Store,
|
||||
Transformer,
|
||||
TransformerMiddleware,
|
||||
} from '@blocksuite/store';
|
||||
import DOMPurify from 'dompurify';
|
||||
import type { RootContentMap } from 'hast';
|
||||
@@ -17,8 +17,8 @@ import { unified } from 'unified';
|
||||
import { LifeCycleWatcher } from '../extension/index.js';
|
||||
|
||||
type AdapterConstructor<T extends BaseAdapter> =
|
||||
| { new (job: Job): T }
|
||||
| (new (job: Job, provider: ServiceProvider) => T);
|
||||
| { new (job: Transformer): T }
|
||||
| (new (job: Transformer, provider: ServiceProvider) => T);
|
||||
|
||||
type AdapterMap = Map<
|
||||
string,
|
||||
@@ -155,7 +155,7 @@ export class Clipboard extends LifeCycleWatcher {
|
||||
return null;
|
||||
};
|
||||
|
||||
private _jobMiddlewares: JobMiddleware[] = [];
|
||||
private _jobMiddlewares: TransformerMiddleware[] = [];
|
||||
|
||||
copy = async (slice: Slice) => {
|
||||
return this.copySlice(slice);
|
||||
@@ -257,11 +257,11 @@ export class Clipboard extends LifeCycleWatcher {
|
||||
this._adapterMap.delete(mimeType);
|
||||
};
|
||||
|
||||
unuse = (middleware: JobMiddleware) => {
|
||||
unuse = (middleware: TransformerMiddleware) => {
|
||||
this._jobMiddlewares = this._jobMiddlewares.filter(m => m !== middleware);
|
||||
};
|
||||
|
||||
use = (middleware: JobMiddleware) => {
|
||||
use = (middleware: TransformerMiddleware) => {
|
||||
this._jobMiddlewares.push(middleware);
|
||||
};
|
||||
|
||||
@@ -285,7 +285,7 @@ export class Clipboard extends LifeCycleWatcher {
|
||||
}
|
||||
|
||||
private _getJob() {
|
||||
return this.std.getJob(this._jobMiddlewares);
|
||||
return this.std.getTransformer(this._jobMiddlewares);
|
||||
}
|
||||
|
||||
readFromClipboard(clipboardData: DataTransfer) {
|
||||
|
||||
@@ -2,10 +2,10 @@ import { Container, type ServiceProvider } from '@blocksuite/global/di';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import {
|
||||
type ExtensionType,
|
||||
Job,
|
||||
type JobMiddleware,
|
||||
type Store,
|
||||
StoreSelectionExtension,
|
||||
Transformer,
|
||||
type TransformerMiddleware,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { Clipboard } from '../clipboard/index.js';
|
||||
@@ -161,8 +161,8 @@ export class BlockStdScope {
|
||||
return this.getOptional(BlockViewIdentifier(flavour));
|
||||
}
|
||||
|
||||
getJob(middlewares: JobMiddleware[] = []) {
|
||||
return new Job({
|
||||
getTransformer(middlewares: TransformerMiddleware[] = []) {
|
||||
return new Transformer({
|
||||
schema: this.workspace.schema,
|
||||
blobCRUD: this.workspace.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { BlockSuiteError } from '@blocksuite/global/exceptions';
|
||||
|
||||
import type { DraftModel, Store } from '../model/index.js';
|
||||
import type { AssetsManager } from '../transformer/assets.js';
|
||||
import type { Job, Slice } from '../transformer/index.js';
|
||||
import type { Slice, Transformer } from '../transformer/index.js';
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DocSnapshot,
|
||||
@@ -62,13 +62,13 @@ export function wrapFakeNote(snapshot: SliceSnapshot) {
|
||||
}
|
||||
|
||||
export abstract class BaseAdapter<AdapterTarget = unknown> {
|
||||
job: Job;
|
||||
job: Transformer;
|
||||
|
||||
get configs() {
|
||||
return this.job.adapterConfigs;
|
||||
}
|
||||
|
||||
constructor(job: Job) {
|
||||
constructor(job: Transformer) {
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
|
||||
import type { BlobCRUD } from './type.js';
|
||||
import type { BlobCRUD } from './type';
|
||||
|
||||
type AssetsManagerConfig = {
|
||||
blob: BlobCRUD;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { BlockModel } from '../model/block/block-model.js';
|
||||
import type { DraftModel } from '../model/block/draft.js';
|
||||
import type { BlockModel } from '../model/block/block-model';
|
||||
import type { DraftModel } from '../model/block/draft';
|
||||
import {
|
||||
type InternalPrimitives,
|
||||
internalPrimitives,
|
||||
} from '../model/block/zod.js';
|
||||
import type { AssetsManager } from './assets.js';
|
||||
import { fromJSON, toJSON } from './json.js';
|
||||
import type { BlockSnapshot } from './type.js';
|
||||
} from '../model/block/zod';
|
||||
import type { AssetsManager } from './assets';
|
||||
import { fromJSON, toJSON } from './json';
|
||||
import type { BlockSnapshot } from './type';
|
||||
|
||||
export type BlockSnapshotLeaf = Pick<
|
||||
BlockSnapshot,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export * from './assets.js';
|
||||
export * from './base.js';
|
||||
export * from './job.js';
|
||||
export * from './json.js';
|
||||
export * from './middleware.js';
|
||||
export * from './slice.js';
|
||||
export * from './type.js';
|
||||
export * from './assets';
|
||||
export * from './base';
|
||||
export * from './json';
|
||||
export * from './middleware';
|
||||
export * from './slice';
|
||||
export * from './transformer';
|
||||
export * from './type';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NATIVE_UNIQ_IDENTIFIER, TEXT_UNIQ_IDENTIFIER } from '../consts.js';
|
||||
import { Boxed } from '../reactive/boxed.js';
|
||||
import { isPureObject } from '../reactive/index.js';
|
||||
import { Text } from '../reactive/text.js';
|
||||
import { NATIVE_UNIQ_IDENTIFIER, TEXT_UNIQ_IDENTIFIER } from '../consts';
|
||||
import { Boxed } from '../reactive/boxed';
|
||||
import { isPureObject } from '../reactive/index';
|
||||
import { Text } from '../reactive/text';
|
||||
|
||||
export function toJSON(value: unknown): unknown {
|
||||
if (value instanceof Boxed) {
|
||||
|
||||
@@ -71,18 +71,20 @@ export type FinalPayload =
|
||||
type: 'info';
|
||||
};
|
||||
|
||||
export type JobSlots = {
|
||||
export type TransformerSlots = {
|
||||
beforeImport: Slot<BeforeImportPayload>;
|
||||
afterImport: Slot<FinalPayload>;
|
||||
beforeExport: Slot<BeforeExportPayload>;
|
||||
afterExport: Slot<FinalPayload>;
|
||||
};
|
||||
|
||||
type JobMiddlewareOptions = {
|
||||
type TransformerMiddlewareOptions = {
|
||||
assetsManager: AssetsManager;
|
||||
slots: JobSlots;
|
||||
slots: TransformerSlots;
|
||||
docCRUD: DocCRUD;
|
||||
adapterConfigs: Map<string, string>;
|
||||
};
|
||||
|
||||
export type JobMiddleware = (options: JobMiddlewareOptions) => void;
|
||||
export type TransformerMiddleware = (
|
||||
options: TransformerMiddlewareOptions
|
||||
) => void;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { DraftModel, Store } from '../model/index.js';
|
||||
import type { DraftModel, Store } from '../model/index';
|
||||
|
||||
type SliceData = {
|
||||
content: DraftModel[];
|
||||
|
||||
@@ -14,8 +14,8 @@ import type {
|
||||
BeforeExportPayload,
|
||||
BeforeImportPayload,
|
||||
FinalPayload,
|
||||
JobMiddleware,
|
||||
JobSlots,
|
||||
TransformerMiddleware,
|
||||
TransformerSlots,
|
||||
} from './middleware.js';
|
||||
import { Slice } from './slice.js';
|
||||
import type {
|
||||
@@ -31,11 +31,11 @@ import {
|
||||
SliceSnapshotSchema,
|
||||
} from './type.js';
|
||||
|
||||
export type JobConfig = {
|
||||
export type TransformerOptions = {
|
||||
schema: Schema;
|
||||
blobCRUD: BlobCRUD;
|
||||
docCRUD: DocCRUD;
|
||||
middlewares?: JobMiddleware[];
|
||||
middlewares?: TransformerMiddleware[];
|
||||
};
|
||||
|
||||
interface FlatSnapshot {
|
||||
@@ -53,7 +53,7 @@ interface DraftBlockTreeNode {
|
||||
// The number of blocks to insert in one batch
|
||||
const BATCH_SIZE = 100;
|
||||
|
||||
export class Job {
|
||||
export class Transformer {
|
||||
private readonly _adapterConfigs = new Map<string, string>();
|
||||
|
||||
private readonly _assetsManager: AssetsManager;
|
||||
@@ -62,7 +62,7 @@ export class Job {
|
||||
|
||||
private readonly _docCRUD: DocCRUD;
|
||||
|
||||
private readonly _slots: JobSlots = {
|
||||
private readonly _slots: TransformerSlots = {
|
||||
beforeImport: new Slot<BeforeImportPayload>(),
|
||||
afterImport: new Slot<FinalPayload>(),
|
||||
beforeExport: new Slot<BeforeExportPayload>(),
|
||||
@@ -338,7 +338,12 @@ export class Job {
|
||||
return this._docCRUD;
|
||||
}
|
||||
|
||||
constructor({ blobCRUD, schema, docCRUD, middlewares = [] }: JobConfig) {
|
||||
constructor({
|
||||
blobCRUD,
|
||||
schema,
|
||||
docCRUD,
|
||||
middlewares = [],
|
||||
}: TransformerOptions) {
|
||||
this._assetsManager = new AssetsManager({ blob: blobCRUD });
|
||||
this._schema = schema;
|
||||
this._docCRUD = docCRUD;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { Store } from '../model/store/store.js';
|
||||
import type { DocMeta, DocsPropertiesMeta } from '../model/workspace-meta.js';
|
||||
import type { Store } from '../model/store/store';
|
||||
import type { DocMeta, DocsPropertiesMeta } from '../model/workspace-meta';
|
||||
|
||||
export type BlockSnapshot = {
|
||||
type: 'block';
|
||||
|
||||
Reference in New Issue
Block a user