mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 03:56:23 +08:00
refactor(editor): rename job to transformer (#9639)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { DEFAULT_IMAGE_PROXY_ENDPOINT } from '@blocksuite/affine-shared/consts';
|
||||
import type { JobMiddleware } from '@blocksuite/store';
|
||||
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||
|
||||
export const customImageProxyMiddleware = (
|
||||
imageProxyURL: string
|
||||
): JobMiddleware => {
|
||||
): TransformerMiddleware => {
|
||||
return ({ adapterConfigs }) => {
|
||||
adapterConfigs.set('imageProxy', imageProxyURL);
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { JobMiddleware } from '@blocksuite/store';
|
||||
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||
|
||||
export const newIdCrossDoc =
|
||||
(std: BlockStdScope): JobMiddleware =>
|
||||
(std: BlockStdScope): TransformerMiddleware =>
|
||||
({ slots }) => {
|
||||
let samePage = false;
|
||||
slots.beforeImport.on(payload => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { correctNumberedListsOrderToPrev } from '@blocksuite/affine-block-list';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { JobMiddleware } from '@blocksuite/store';
|
||||
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||
|
||||
export const reorderList =
|
||||
(std: BlockStdScope): JobMiddleware =>
|
||||
(std: BlockStdScope): TransformerMiddleware =>
|
||||
({ slots }) => {
|
||||
slots.afterImport.on(payload => {
|
||||
if (payload.type === 'block') {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { JobMiddleware } from '@blocksuite/store';
|
||||
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||
|
||||
export const surfaceRefToEmbed =
|
||||
(std: BlockStdScope): JobMiddleware =>
|
||||
(std: BlockStdScope): TransformerMiddleware =>
|
||||
({ slots }) => {
|
||||
let pageId: string | null = null;
|
||||
slots.beforeImport.on(payload => {
|
||||
|
||||
@@ -545,7 +545,7 @@ export class DragEventWatcher {
|
||||
|
||||
private _getJob() {
|
||||
const std = this._std;
|
||||
return std.getJob([
|
||||
return std.getTransformer([
|
||||
newIdCrossDoc(std),
|
||||
reorderList(std),
|
||||
surfaceRefToEmbed(std),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Container } from '@blocksuite/global/di';
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DocSnapshot,
|
||||
JobMiddleware,
|
||||
TransformerMiddleware,
|
||||
} from '@blocksuite/store';
|
||||
import { AssetsManager, MemoryBlobCRUD } from '@blocksuite/store';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
@@ -1514,7 +1514,7 @@ describe('snapshot to html', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const middleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
const middleware: TransformerMiddleware = ({ adapterConfigs }) => {
|
||||
adapterConfigs.set('title:4T5ObMgEIMII-4Bexyta1', 'Test Doc');
|
||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||
};
|
||||
|
||||
@@ -4,8 +4,8 @@ import { Container } from '@blocksuite/global/di';
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DocSnapshot,
|
||||
JobMiddleware,
|
||||
SliceSnapshot,
|
||||
TransformerMiddleware,
|
||||
} from '@blocksuite/store';
|
||||
import { AssetsManager, MemoryBlobCRUD } from '@blocksuite/store';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
@@ -1931,7 +1931,7 @@ hhh
|
||||
|
||||
hhh
|
||||
`;
|
||||
const middleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
const middleware: TransformerMiddleware = ({ adapterConfigs }) => {
|
||||
adapterConfigs.set('title:deadbeef', 'test');
|
||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||
};
|
||||
@@ -3847,7 +3847,7 @@ hhh
|
||||
},
|
||||
],
|
||||
};
|
||||
const middleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
const middleware: TransformerMiddleware = ({ adapterConfigs }) => {
|
||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||
};
|
||||
const mdAdapter = new MarkdownAdapter(createJob([middleware]), provider);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Container } from '@blocksuite/global/di';
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DocSnapshot,
|
||||
JobMiddleware,
|
||||
TransformerMiddleware,
|
||||
} from '@blocksuite/store';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
@@ -573,7 +573,7 @@ describe('snapshot to plain text', () => {
|
||||
},
|
||||
],
|
||||
};
|
||||
const middleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
const middleware: TransformerMiddleware = ({ adapterConfigs }) => {
|
||||
adapterConfigs.set('title:deadbeef', 'test');
|
||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||
};
|
||||
@@ -756,7 +756,7 @@ describe('snapshot to plain text', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const middleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
const middleware: TransformerMiddleware = ({ adapterConfigs }) => {
|
||||
adapterConfigs.set('title:4T5ObMgEIMII-4Bexyta1', 'test');
|
||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||
};
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||
import { Job, type JobMiddleware, Schema } from '@blocksuite/store';
|
||||
import {
|
||||
Schema,
|
||||
Transformer,
|
||||
type TransformerMiddleware,
|
||||
} from '@blocksuite/store';
|
||||
import { TestWorkspace } from '@blocksuite/store/test';
|
||||
|
||||
import { defaultImageProxyMiddleware } from '../../_common/transformers/middlewares.js';
|
||||
@@ -17,7 +21,7 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
export function createJob(middlewares?: JobMiddleware[]) {
|
||||
export function createJob(middlewares?: TransformerMiddleware[]) {
|
||||
window.happyDOM.settings.fetch.disableSameOriginPolicy = true;
|
||||
const testMiddlewares = middlewares ?? [];
|
||||
testMiddlewares.push(defaultImageProxyMiddleware);
|
||||
@@ -25,7 +29,7 @@ export function createJob(middlewares?: JobMiddleware[]) {
|
||||
const docCollection = new TestWorkspace({ schema });
|
||||
docCollection.storeExtensions = [FeatureFlagService];
|
||||
docCollection.meta.initialize();
|
||||
return new Job({
|
||||
return new Transformer({
|
||||
schema,
|
||||
blobCRUD: docCollection.blobSync,
|
||||
middlewares: testMiddlewares,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { HtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
import { sha } from '@blocksuite/global/utils';
|
||||
import type { Store, Workspace } from '@blocksuite/store';
|
||||
import { extMimeMap, Job } from '@blocksuite/store';
|
||||
import { extMimeMap, Transformer } from '@blocksuite/store';
|
||||
|
||||
import { defaultBlockHtmlAdapterMatchers } from '../adapters/html/block-matcher.js';
|
||||
import { htmlInlineToDeltaMatchers } from '../adapters/html/delta-converter/html-inline.js';
|
||||
@@ -44,7 +44,7 @@ const provider = container.provider();
|
||||
* @returns A Promise that resolves when the export is complete.
|
||||
*/
|
||||
async function exportDoc(doc: Store) {
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: doc.schema,
|
||||
blobCRUD: doc.blobSync,
|
||||
docCRUD: {
|
||||
@@ -99,7 +99,7 @@ async function importHTMLToDoc({
|
||||
html,
|
||||
fileName,
|
||||
}: ImportHTMLToDocOptions) {
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
@@ -161,7 +161,7 @@ async function importHTMLZip({ collection, imported }: ImportHTMLZipOptions) {
|
||||
await Promise.all(
|
||||
htmlBlobs.map(async ([fileName, blob]) => {
|
||||
const fileNameWithoutExt = fileName.replace(/\.[^/.]+$/, '');
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Container } from '@blocksuite/global/di';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { assertExists, sha } from '@blocksuite/global/utils';
|
||||
import type { Store, Workspace } from '@blocksuite/store';
|
||||
import { extMimeMap, Job } from '@blocksuite/store';
|
||||
import { extMimeMap, Transformer } from '@blocksuite/store';
|
||||
|
||||
import { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js';
|
||||
import { inlineDeltaToMarkdownAdapterMatchers } from '../adapters/markdown/delta-converter/inline-delta.js';
|
||||
@@ -50,7 +50,7 @@ type ImportMarkdownZipOptions = {
|
||||
* @returns A Promise that resolves when the export is complete
|
||||
*/
|
||||
async function exportDoc(doc: Store) {
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: doc.schema,
|
||||
blobCRUD: doc.blobSync,
|
||||
docCRUD: {
|
||||
@@ -109,7 +109,7 @@ async function importMarkdownToBlock({
|
||||
markdown,
|
||||
blockId,
|
||||
}: ImportMarkdownToBlockOptions) {
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: doc.schema,
|
||||
blobCRUD: doc.blobSync,
|
||||
docCRUD: {
|
||||
@@ -154,7 +154,7 @@ async function importMarkdownToDoc({
|
||||
markdown,
|
||||
fileName,
|
||||
}: ImportMarkdownToDocOptions) {
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
@@ -218,7 +218,7 @@ async function importMarkdownZip({
|
||||
await Promise.all(
|
||||
markdownBlobs.map(async ([fileName, blob]) => {
|
||||
const fileNameWithoutExt = fileName.replace(/\.[^/.]+$/, '');
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -8,10 +8,14 @@ import type {
|
||||
} from '@blocksuite/affine-model';
|
||||
import { DEFAULT_IMAGE_PROXY_ENDPOINT } from '@blocksuite/affine-shared/consts';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { DeltaOperation, DocMeta, JobMiddleware } from '@blocksuite/store';
|
||||
import type {
|
||||
DeltaOperation,
|
||||
DocMeta,
|
||||
TransformerMiddleware,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
export const replaceIdMiddleware =
|
||||
(idGenerator: () => string): JobMiddleware =>
|
||||
(idGenerator: () => string): TransformerMiddleware =>
|
||||
({ slots, docCRUD }) => {
|
||||
const idMap = new Map<string, string>();
|
||||
slots.afterImport.on(payload => {
|
||||
@@ -202,7 +206,7 @@ export const replaceIdMiddleware =
|
||||
|
||||
export const customImageProxyMiddleware = (
|
||||
imageProxyURL: string
|
||||
): JobMiddleware => {
|
||||
): TransformerMiddleware => {
|
||||
return ({ adapterConfigs }) => {
|
||||
adapterConfigs.set('imageProxy', imageProxyURL);
|
||||
};
|
||||
@@ -211,7 +215,7 @@ export const customImageProxyMiddleware = (
|
||||
const customDocLinkBaseUrlMiddleware = (
|
||||
baseUrl: string,
|
||||
collectionId: string
|
||||
): JobMiddleware => {
|
||||
): TransformerMiddleware => {
|
||||
return ({ adapterConfigs }) => {
|
||||
const docLinkBaseUrl = baseUrl
|
||||
? `${baseUrl}/workspace/${collectionId}`
|
||||
@@ -221,7 +225,7 @@ const customDocLinkBaseUrlMiddleware = (
|
||||
};
|
||||
|
||||
export const titleMiddleware =
|
||||
(metas: DocMeta[]): JobMiddleware =>
|
||||
(metas: DocMeta[]): TransformerMiddleware =>
|
||||
({ slots, adapterConfigs }) => {
|
||||
slots.beforeExport.on(() => {
|
||||
for (const meta of metas) {
|
||||
@@ -273,13 +277,13 @@ export const defaultImageProxyMiddleware =
|
||||
defaultImageProxyMiddlewarBuilder.get();
|
||||
|
||||
export const embedSyncedDocMiddleware =
|
||||
(type: 'content'): JobMiddleware =>
|
||||
(type: 'content'): TransformerMiddleware =>
|
||||
({ adapterConfigs }) => {
|
||||
adapterConfigs.set('embedSyncedDocExportType', type);
|
||||
};
|
||||
|
||||
export const fileNameMiddleware =
|
||||
(fileName?: string): JobMiddleware =>
|
||||
(fileName?: string): TransformerMiddleware =>
|
||||
({ slots }) => {
|
||||
slots.beforeImport.on(payload => {
|
||||
if (payload.type !== 'page') {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
||||
import { Container } from '@blocksuite/global/di';
|
||||
import { sha } from '@blocksuite/global/utils';
|
||||
import { extMimeMap, Job, type Workspace } from '@blocksuite/store';
|
||||
import { extMimeMap, Transformer, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import { defaultBlockNotionHtmlAdapterMatchers } from '../adapters/notion-html/block-matcher.js';
|
||||
import { notionHtmlInlineToDeltaMatchers } from '../adapters/notion-html/delta-converter/html-inline.js';
|
||||
@@ -117,7 +117,7 @@ async function importNotionZip({
|
||||
pendingAssets.set(key, new File([blob], fileName, { type: mime }));
|
||||
}
|
||||
const pagePromises = Array.from(pagePaths).map(async path => {
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { sha } from '@blocksuite/global/utils';
|
||||
import type { DocSnapshot, Store, Workspace } from '@blocksuite/store';
|
||||
import { extMimeMap, getAssetName, Job } from '@blocksuite/store';
|
||||
import { extMimeMap, getAssetName, Transformer } from '@blocksuite/store';
|
||||
|
||||
import { download, Unzip, Zip } from '../transformers/utils.js';
|
||||
import { replaceIdMiddleware, titleMiddleware } from './middlewares.js';
|
||||
|
||||
async function exportDocs(collection: Workspace, docs: Store[]) {
|
||||
const zip = new Zip();
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
@@ -77,7 +77,7 @@ async function importDocs(collection: Workspace, imported: Blob) {
|
||||
}
|
||||
}
|
||||
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -58,8 +58,8 @@ import {
|
||||
type BlockSnapshot,
|
||||
BlockSnapshotSchema,
|
||||
fromJSON,
|
||||
Job,
|
||||
type SliceSnapshot,
|
||||
Transformer,
|
||||
} from '@blocksuite/store';
|
||||
import DOMPurify from 'dompurify';
|
||||
import * as Y from 'yjs';
|
||||
@@ -369,7 +369,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
if (mayBeSurfaceDataJson !== undefined) {
|
||||
const elementsRawData = JSON.parse(mayBeSurfaceDataJson);
|
||||
const { snapshot, blobs } = elementsRawData;
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: this.std.workspace.schema,
|
||||
blobCRUD: this.std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
@@ -1373,7 +1373,7 @@ export async function prepareClipboardData(
|
||||
selectedAll: BlockSuite.EdgelessModel[],
|
||||
std: BlockStdScope
|
||||
) {
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: std.workspace.schema,
|
||||
blobCRUD: std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -15,8 +15,8 @@ import {
|
||||
type BlockSnapshot,
|
||||
type DocSnapshot,
|
||||
DocSnapshotSchema,
|
||||
Job,
|
||||
type SnapshotNode,
|
||||
Transformer,
|
||||
} from '@blocksuite/store';
|
||||
import type * as Y from 'yjs';
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ export class TemplateJob {
|
||||
|
||||
private _template: DocSnapshot | null = null;
|
||||
|
||||
job: Job;
|
||||
job: Transformer;
|
||||
|
||||
model: SurfaceBlockModel;
|
||||
|
||||
@@ -90,7 +90,7 @@ export class TemplateJob {
|
||||
type: TemplateType;
|
||||
|
||||
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
||||
this.job = new Job({
|
||||
this.job = new Transformer({
|
||||
schema: model.doc.workspace.schema,
|
||||
blobCRUD: model.doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
isGfxGroupCompatibleModel,
|
||||
type SerializedElement,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { type BlockSnapshot, Job } from '@blocksuite/store';
|
||||
import { type BlockSnapshot, Transformer } from '@blocksuite/store';
|
||||
|
||||
/**
|
||||
* return all elements in the tree of the elements
|
||||
@@ -39,7 +39,7 @@ export function getSortedCloneElements(elements: GfxModel[]) {
|
||||
|
||||
export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
||||
elements = sortEdgelessElements(elements);
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: std.workspace.schema,
|
||||
blobCRUD: std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
@@ -58,7 +58,7 @@ export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
||||
export function serializeElement(
|
||||
element: GfxModel,
|
||||
elements: GfxModel[],
|
||||
job: Job
|
||||
job: Transformer
|
||||
) {
|
||||
if (element instanceof GfxBlockElementModel) {
|
||||
const snapshot = job.blockToSnapshot(element);
|
||||
|
||||
@@ -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[];
|
||||
|
||||
+12
-7
@@ -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';
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
} from '@blocksuite/blocks';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import { type DocSnapshot, Job } from '@blocksuite/store';
|
||||
import { type DocSnapshot, Transformer } from '@blocksuite/store';
|
||||
import { effect } from '@preact/signals-core';
|
||||
import type SlTabPanel from '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
|
||||
import { css, html, type PropertyValues } from 'lit';
|
||||
@@ -101,7 +101,7 @@ export class AdaptersPanel extends WithDisposable(ShadowlessElement) {
|
||||
}
|
||||
|
||||
private _createJob() {
|
||||
return new Job({
|
||||
return new Transformer({
|
||||
schema: this.doc.collection.schema,
|
||||
blobCRUD: this.doc.collection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -50,7 +50,7 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import type { SerializedXYWH } from '@blocksuite/global/utils';
|
||||
import type { DeltaInsert } from '@blocksuite/inline/types';
|
||||
import { AffineEditorContainer, type CommentPanel } from '@blocksuite/presets';
|
||||
import { Job, Text, type Workspace } from '@blocksuite/store';
|
||||
import { Text, Transformer, type Workspace } from '@blocksuite/store';
|
||||
import type { SlDropdown } from '@shoelace-style/shoelace';
|
||||
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js';
|
||||
import { css, html } from 'lit';
|
||||
@@ -241,7 +241,7 @@ export class StarterDebugMenu extends ShadowlessElement {
|
||||
|
||||
private async _exportFile(config: AdapterConfig) {
|
||||
const doc = this.editor.doc;
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: this.collection.schema,
|
||||
blobCRUD: this.collection.blobSync,
|
||||
docCRUD: {
|
||||
@@ -442,7 +442,7 @@ export class StarterDebugMenu extends ShadowlessElement {
|
||||
multiple: false,
|
||||
});
|
||||
if (!file) return;
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: this.collection.schema,
|
||||
blobCRUD: this.collection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
import type { EditorHost } from '@blocksuite/block-std';
|
||||
import type { TestUtils } from '@blocksuite/blocks';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { BlockSchema, Blocks, Workspace, Job } from '@blocksuite/store';
|
||||
import type { BlockSchema, Blocks, Workspace, Transformer } from '@blocksuite/store';
|
||||
import type { z } from 'zod';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
@@ -17,7 +17,7 @@ declare global {
|
||||
doc: Blocks;
|
||||
collection: Workspace;
|
||||
blockSchemas: z.infer<typeof BlockSchema>[];
|
||||
job: Job;
|
||||
job: Transformer;
|
||||
Y: typeof Y;
|
||||
std: typeof std;
|
||||
testUtils: TestUtils;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AffineSchemas, SpecProvider, TestUtils } from '@blocksuite/blocks';
|
||||
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
||||
import { Job, nanoid, Schema } from '@blocksuite/store';
|
||||
import { nanoid, Schema, Transformer } from '@blocksuite/store';
|
||||
import {
|
||||
createAutoIncrementIdGenerator,
|
||||
type DocCollectionOptions,
|
||||
@@ -81,7 +81,7 @@ export function createStarterDocCollection() {
|
||||
// debug info
|
||||
window.collection = collection;
|
||||
window.blockSchemas = AffineSchemas;
|
||||
window.job = new Job({
|
||||
window.job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { replaceIdMiddleware } from '@blocksuite/blocks';
|
||||
import { type DocSnapshot, Job, type Workspace } from '@blocksuite/store';
|
||||
import {
|
||||
type DocSnapshot,
|
||||
Transformer,
|
||||
type Workspace,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
export async function importFromSnapshot(
|
||||
collection: Workspace,
|
||||
snapshot: DocSnapshot
|
||||
) {
|
||||
const job = new Job({
|
||||
const job = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { effects as blocksEffects } from '@blocksuite/blocks/effects';
|
||||
import type { Job, Store } from '@blocksuite/store';
|
||||
import type { Store, Transformer } from '@blocksuite/store';
|
||||
|
||||
import { effects } from '../../effects.js';
|
||||
|
||||
@@ -113,11 +113,11 @@ declare global {
|
||||
const editor: AffineEditorContainer;
|
||||
const doc: Store;
|
||||
const collection: TestWorkspace;
|
||||
const job: Job;
|
||||
const job: Transformer;
|
||||
interface Window {
|
||||
editor: AffineEditorContainer;
|
||||
doc: Store;
|
||||
job: Job;
|
||||
job: Transformer;
|
||||
collection: TestWorkspace;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,12 @@ import type {
|
||||
} from '@blocksuite/block-std';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { StarterDebugMenu } from '@playground/apps/_common/components/starter-debug-menu.js';
|
||||
import type { BlockModel, Blocks, Job, Workspace } from '@store/index.js';
|
||||
import type {
|
||||
BlockModel,
|
||||
Blocks,
|
||||
Transformer,
|
||||
Workspace,
|
||||
} from '@store/index.js';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -43,6 +48,6 @@ declare global {
|
||||
editor: AffineEditorContainer;
|
||||
host: EditorHost;
|
||||
testUtils: TestUtils;
|
||||
job: Job;
|
||||
job: Transformer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import {
|
||||
titleMiddleware,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Container } from '@blocksuite/affine/global/di';
|
||||
import { Job } from '@blocksuite/affine/store';
|
||||
import { Transformer } from '@blocksuite/affine/store';
|
||||
import { App as CapacitorApp } from '@capacitor/app';
|
||||
import { Browser } from '@capacitor/browser';
|
||||
import { Haptics } from '@capacitor/haptics';
|
||||
@@ -181,7 +181,7 @@ const frameworkProvider = framework.provider();
|
||||
try {
|
||||
const blockSuiteDoc = doc.blockSuiteDoc;
|
||||
|
||||
const job = new Job({
|
||||
const transformer = new Transformer({
|
||||
schema: blockSuiteDoc.workspace.schema,
|
||||
blobCRUD: blockSuiteDoc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
@@ -194,7 +194,7 @@ const frameworkProvider = framework.provider();
|
||||
titleMiddleware(blockSuiteDoc.workspace.meta.docMetas),
|
||||
],
|
||||
});
|
||||
const snapshot = job.docToSnapshot(blockSuiteDoc);
|
||||
const snapshot = transformer.docToSnapshot(blockSuiteDoc);
|
||||
|
||||
const container = new Container();
|
||||
[
|
||||
@@ -206,14 +206,14 @@ const frameworkProvider = framework.provider();
|
||||
});
|
||||
const provider = container.provider();
|
||||
|
||||
const adapter = new MarkdownAdapter(job, provider);
|
||||
const adapter = new MarkdownAdapter(transformer, provider);
|
||||
if (!snapshot) {
|
||||
return;
|
||||
}
|
||||
|
||||
const markdownResult = await adapter.fromDocSnapshot({
|
||||
snapshot,
|
||||
assets: job.assetsManager,
|
||||
assets: transformer.assetsManager,
|
||||
});
|
||||
return markdownResult.file;
|
||||
} finally {
|
||||
|
||||
@@ -20,10 +20,10 @@ import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import type {
|
||||
ExtensionType,
|
||||
JobMiddleware,
|
||||
Query,
|
||||
Schema,
|
||||
Store,
|
||||
TransformerMiddleware,
|
||||
} from '@blocksuite/affine/store';
|
||||
import { css, html, nothing, type PropertyValues } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
@@ -85,7 +85,7 @@ export type TextRendererOptions = {
|
||||
maxHeight?: number;
|
||||
customHeading?: boolean;
|
||||
extensions?: ExtensionType[];
|
||||
additionalMiddlewares?: JobMiddleware[];
|
||||
additionalMiddlewares?: TransformerMiddleware[];
|
||||
};
|
||||
|
||||
// todo: refactor it for more general purpose usage instead of AI only?
|
||||
|
||||
@@ -19,13 +19,13 @@ import type {
|
||||
BlockModel,
|
||||
BlockSnapshot,
|
||||
DraftModel,
|
||||
JobMiddleware,
|
||||
Schema,
|
||||
Slice,
|
||||
SliceSnapshot,
|
||||
Store,
|
||||
TransformerMiddleware,
|
||||
} from '@blocksuite/affine/store';
|
||||
import { Job } from '@blocksuite/affine/store';
|
||||
import { Transformer } from '@blocksuite/affine/store';
|
||||
|
||||
const updateSnapshotText = (
|
||||
point: TextRangePoint,
|
||||
@@ -79,7 +79,7 @@ export async function getContentFromSlice(
|
||||
slice: Slice,
|
||||
type: 'markdown' | 'plain-text' = 'markdown'
|
||||
) {
|
||||
const job = new Job({
|
||||
const transformer = new Transformer({
|
||||
schema: host.std.store.workspace.schema,
|
||||
blobCRUD: host.std.store.workspace.blobSync,
|
||||
docCRUD: {
|
||||
@@ -92,24 +92,24 @@ export async function getContentFromSlice(
|
||||
embedSyncedDocMiddleware('content'),
|
||||
],
|
||||
});
|
||||
const snapshot = job.sliceToSnapshot(slice);
|
||||
const snapshot = transformer.sliceToSnapshot(slice);
|
||||
if (!snapshot) {
|
||||
return '';
|
||||
}
|
||||
processTextInSnapshot(snapshot, host);
|
||||
const adapter =
|
||||
type === 'markdown'
|
||||
? new MarkdownAdapter(job, host.std.provider)
|
||||
: new PlainTextAdapter(job, host.std.provider);
|
||||
? new MarkdownAdapter(transformer, host.std.provider)
|
||||
: new PlainTextAdapter(transformer, host.std.provider);
|
||||
const content = await adapter.fromSliceSnapshot({
|
||||
snapshot,
|
||||
assets: job.assetsManager,
|
||||
assets: transformer.assetsManager,
|
||||
});
|
||||
return content.file;
|
||||
}
|
||||
|
||||
export async function getPlainTextFromSlice(host: EditorHost, slice: Slice) {
|
||||
const job = new Job({
|
||||
const transformer = new Transformer({
|
||||
schema: host.std.store.workspace.schema,
|
||||
blobCRUD: host.std.store.workspace.blobSync,
|
||||
docCRUD: {
|
||||
@@ -119,15 +119,15 @@ export async function getPlainTextFromSlice(host: EditorHost, slice: Slice) {
|
||||
},
|
||||
middlewares: [titleMiddleware(host.std.store.workspace.meta.docMetas)],
|
||||
});
|
||||
const snapshot = job.sliceToSnapshot(slice);
|
||||
const snapshot = transformer.sliceToSnapshot(slice);
|
||||
if (!snapshot) {
|
||||
return '';
|
||||
}
|
||||
processTextInSnapshot(snapshot, host);
|
||||
const plainTextAdapter = new PlainTextAdapter(job, host.std.provider);
|
||||
const plainTextAdapter = new PlainTextAdapter(transformer, host.std.provider);
|
||||
const plainText = await plainTextAdapter.fromSliceSnapshot({
|
||||
snapshot,
|
||||
assets: job.assetsManager,
|
||||
assets: transformer.assetsManager,
|
||||
});
|
||||
return plainText.file;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ export const markdownToSnapshot = async (
|
||||
markdown: string,
|
||||
host: EditorHost
|
||||
) => {
|
||||
const job = new Job({
|
||||
const transformer = new Transformer({
|
||||
schema: host.std.store.workspace.schema,
|
||||
blobCRUD: host.std.store.workspace.blobSync,
|
||||
docCRUD: {
|
||||
@@ -146,10 +146,10 @@ export const markdownToSnapshot = async (
|
||||
},
|
||||
middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)],
|
||||
});
|
||||
const markdownAdapter = new MixTextAdapter(job, host.std.provider);
|
||||
const markdownAdapter = new MixTextAdapter(transformer, host.std.provider);
|
||||
const payload = {
|
||||
file: markdown,
|
||||
assets: job.assetsManager,
|
||||
assets: transformer.assetsManager,
|
||||
workspaceId: host.std.store.workspace.id,
|
||||
pageId: host.std.store.id,
|
||||
};
|
||||
@@ -159,7 +159,7 @@ export const markdownToSnapshot = async (
|
||||
|
||||
return {
|
||||
snapshot,
|
||||
job,
|
||||
transformer,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -170,14 +170,14 @@ export async function insertFromMarkdown(
|
||||
parent?: string,
|
||||
index?: number
|
||||
) {
|
||||
const { snapshot, job } = await markdownToSnapshot(markdown, host);
|
||||
const { snapshot, transformer } = await markdownToSnapshot(markdown, host);
|
||||
|
||||
const snapshots = snapshot.content.flatMap(x => x.children);
|
||||
|
||||
const models: BlockModel[] = [];
|
||||
for (let i = 0; i < snapshots.length; i++) {
|
||||
const blockSnapshot = snapshots[i];
|
||||
const model = await job.snapshotToBlock(
|
||||
const model = await transformer.snapshotToBlock(
|
||||
blockSnapshot,
|
||||
doc,
|
||||
parent,
|
||||
@@ -198,15 +198,15 @@ export async function replaceFromMarkdown(
|
||||
parent?: string,
|
||||
index?: number
|
||||
) {
|
||||
const { snapshot, job } = await markdownToSnapshot(markdown, host);
|
||||
await job.snapshotToSlice(snapshot, host.doc, parent, index);
|
||||
const { snapshot, transformer } = await markdownToSnapshot(markdown, host);
|
||||
await transformer.snapshotToSlice(snapshot, host.doc, parent, index);
|
||||
}
|
||||
|
||||
export async function markDownToDoc(
|
||||
provider: ServiceProvider,
|
||||
schema: Schema,
|
||||
answer: string,
|
||||
additionalMiddlewares?: JobMiddleware[]
|
||||
additionalMiddlewares?: TransformerMiddleware[]
|
||||
) {
|
||||
// Should not create a new doc in the original collection
|
||||
const collection = new WorkspaceImpl({
|
||||
@@ -217,7 +217,7 @@ export async function markDownToDoc(
|
||||
if (additionalMiddlewares) {
|
||||
middlewares.push(...additionalMiddlewares);
|
||||
}
|
||||
const job = new Job({
|
||||
const transformer = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
@@ -227,10 +227,10 @@ export async function markDownToDoc(
|
||||
},
|
||||
middlewares,
|
||||
});
|
||||
const mdAdapter = new MarkdownAdapter(job, provider);
|
||||
const mdAdapter = new MarkdownAdapter(transformer, provider);
|
||||
const doc = await mdAdapter.toDoc({
|
||||
file: answer,
|
||||
assets: job.assetsManager,
|
||||
assets: transformer.assetsManager,
|
||||
});
|
||||
if (!doc) {
|
||||
console.error('Failed to convert markdown to doc');
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import { Job, Schema, type Store } from '@blocksuite/affine/store';
|
||||
import { Schema, type Store, Transformer } from '@blocksuite/affine/store';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
@@ -236,7 +236,7 @@ export const markdownToMindmap = (
|
||||
provider: ServiceProvider
|
||||
) => {
|
||||
let result: Node | null = null;
|
||||
const job = new Job({
|
||||
const transformer = new Transformer({
|
||||
schema: doc.workspace.schema,
|
||||
blobCRUD: doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
@@ -245,7 +245,7 @@ export const markdownToMindmap = (
|
||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const markdown = new MarkdownAdapter(job, provider);
|
||||
const markdown = new MarkdownAdapter(transformer, provider);
|
||||
const ast: Root = markdown['_markdownToAst'](answer);
|
||||
const traverse = (
|
||||
markdownNode: Unpacked<(typeof ast)['children']>,
|
||||
|
||||
@@ -108,8 +108,8 @@ export const replace = async (
|
||||
|
||||
if (textSelection) {
|
||||
host.std.command.exec('deleteText', { textSelection });
|
||||
const { snapshot, job } = await markdownToSnapshot(content, host);
|
||||
await job.snapshotToSlice(
|
||||
const { snapshot, transformer } = await markdownToSnapshot(content, host);
|
||||
await transformer.snapshotToSlice(
|
||||
snapshot,
|
||||
host.doc,
|
||||
firstBlockParent.model.id,
|
||||
|
||||
+4
-2
@@ -19,7 +19,7 @@ import {
|
||||
} from '@affine/core/modules/workspace';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import track from '@affine/track';
|
||||
import type { JobMiddleware } from '@blocksuite/affine/store';
|
||||
import type { TransformerMiddleware } from '@blocksuite/affine/store';
|
||||
import { ToggleDownIcon } from '@blocksuite/icons/rc';
|
||||
import * as Collapsible from '@radix-ui/react-collapsible';
|
||||
import {
|
||||
@@ -198,7 +198,9 @@ export const BacklinkGroups = () => {
|
||||
|
||||
const backlinkGroups = useBacklinkGroups();
|
||||
const textRendererOptions = useMemo(() => {
|
||||
const docLinkBaseURLMiddleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
const docLinkBaseURLMiddleware: TransformerMiddleware = ({
|
||||
adapterConfigs,
|
||||
}) => {
|
||||
adapterConfigs.set(
|
||||
'docLinkBaseUrl',
|
||||
`/workspace/${workspaceService.workspace.id}`
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
ZipTransformer,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
||||
import { Job, type Store } from '@blocksuite/affine/store';
|
||||
import { type Store, Transformer } from '@blocksuite/affine/store';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { nanoid } from 'nanoid';
|
||||
@@ -58,7 +58,7 @@ async function exportDoc(
|
||||
std: BlockStdScope,
|
||||
config: AdapterConfig
|
||||
) {
|
||||
const job = new Job({
|
||||
const transformer = new Transformer({
|
||||
schema: doc.workspace.schema,
|
||||
blobCRUD: doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
@@ -74,7 +74,7 @@ async function exportDoc(
|
||||
});
|
||||
|
||||
const adapterFactory = std.provider.get(config.identifier);
|
||||
const adapter = adapterFactory.get(job);
|
||||
const adapter = adapterFactory.get(transformer);
|
||||
const result = (await adapter.fromDoc(doc)) as AdapterResult;
|
||||
|
||||
if (!result || (!result.file && !result.assetsIds.length)) {
|
||||
@@ -88,10 +88,10 @@ async function exportDoc(
|
||||
let name: string;
|
||||
|
||||
if (result.assetsIds.length > 0) {
|
||||
if (!job.assets) {
|
||||
if (!transformer.assets) {
|
||||
throw new Error('No assets found');
|
||||
}
|
||||
const zip = await createAssetsArchive(job.assets, result.assetsIds);
|
||||
const zip = await createAssetsArchive(transformer.assets, result.assetsIds);
|
||||
await zip.file(config.indexFileName, contentBlob);
|
||||
downloadBlob = await zip.generate();
|
||||
name = `${docTitle}.zip`;
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace';
|
||||
import { AffineSchemas } from '@blocksuite/affine/blocks';
|
||||
import type { DocSnapshot, Store } from '@blocksuite/affine/store';
|
||||
import { Job, Schema } from '@blocksuite/affine/store';
|
||||
import { Schema, Transformer } from '@blocksuite/affine/store';
|
||||
|
||||
const getCollection = (() => {
|
||||
let collection: WorkspaceImpl | null = null;
|
||||
@@ -79,7 +79,7 @@ export async function getDocByName(name: DocName) {
|
||||
async function initDoc(name: DocName) {
|
||||
const snapshot = (await loaders[name]()) as DocSnapshot;
|
||||
const collection = await getCollection();
|
||||
const job = new Job({
|
||||
const transformer = new Transformer({
|
||||
schema: collection.schema,
|
||||
blobCRUD: collection.blobSync,
|
||||
docCRUD: {
|
||||
@@ -90,5 +90,5 @@ async function initDoc(name: DocName) {
|
||||
middlewares: [],
|
||||
});
|
||||
|
||||
return await job.snapshotToDoc(snapshot);
|
||||
return await transformer.snapshotToDoc(snapshot);
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ import { Container } from '@blocksuite/affine/global/di';
|
||||
import {
|
||||
createYProxy,
|
||||
type DraftModel,
|
||||
Job,
|
||||
type JobMiddleware,
|
||||
Transformer,
|
||||
type TransformerMiddleware,
|
||||
type YBlock,
|
||||
} from '@blocksuite/affine/store';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
@@ -155,7 +155,7 @@ function generateMarkdownPreviewBuilder(
|
||||
};
|
||||
}
|
||||
|
||||
const titleMiddleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
const titleMiddleware: TransformerMiddleware = ({ adapterConfigs }) => {
|
||||
const pages = yRootDoc.getMap('meta').get('pages');
|
||||
if (!(pages instanceof YArray)) {
|
||||
return;
|
||||
@@ -176,7 +176,9 @@ function generateMarkdownPreviewBuilder(
|
||||
return `${baseUrl}/${docId}?${searchParams.toString()}`;
|
||||
}
|
||||
|
||||
const docLinkBaseURLMiddleware: JobMiddleware = ({ adapterConfigs }) => {
|
||||
const docLinkBaseURLMiddleware: TransformerMiddleware = ({
|
||||
adapterConfigs,
|
||||
}) => {
|
||||
adapterConfigs.set('docLinkBaseUrl', baseUrl);
|
||||
};
|
||||
|
||||
@@ -191,7 +193,7 @@ function generateMarkdownPreviewBuilder(
|
||||
|
||||
const provider = container.provider();
|
||||
const markdownAdapter = new MarkdownAdapter(
|
||||
new Job({
|
||||
new Transformer({
|
||||
schema: markdownPreviewDocCollection.schema,
|
||||
blobCRUD: markdownPreviewDocCollection.blobSync,
|
||||
docCRUD: {
|
||||
|
||||
Reference in New Issue
Block a user