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 { DEFAULT_IMAGE_PROXY_ENDPOINT } from '@blocksuite/affine-shared/consts';
|
||||||
import type { JobMiddleware } from '@blocksuite/store';
|
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||||
|
|
||||||
export const customImageProxyMiddleware = (
|
export const customImageProxyMiddleware = (
|
||||||
imageProxyURL: string
|
imageProxyURL: string
|
||||||
): JobMiddleware => {
|
): TransformerMiddleware => {
|
||||||
return ({ adapterConfigs }) => {
|
return ({ adapterConfigs }) => {
|
||||||
adapterConfigs.set('imageProxy', imageProxyURL);
|
adapterConfigs.set('imageProxy', imageProxyURL);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ import {
|
|||||||
type FromDocSnapshotResult,
|
type FromDocSnapshotResult,
|
||||||
type FromSliceSnapshotPayload,
|
type FromSliceSnapshotPayload,
|
||||||
type FromSliceSnapshotResult,
|
type FromSliceSnapshotResult,
|
||||||
type Job,
|
|
||||||
nanoid,
|
nanoid,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
type ToBlockSnapshotPayload,
|
type ToBlockSnapshotPayload,
|
||||||
type ToDocSnapshotPayload,
|
type ToDocSnapshotPayload,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import { AdapterFactoryIdentifier } from './types/adapter';
|
import { AdapterFactoryIdentifier } from './types/adapter';
|
||||||
@@ -132,7 +132,7 @@ export const AttachmentAdapterFactoryIdentifier =
|
|||||||
export const AttachmentAdapterFactoryExtension: ExtensionType = {
|
export const AttachmentAdapterFactoryExtension: ExtensionType = {
|
||||||
setup: di => {
|
setup: di => {
|
||||||
di.addImpl(AttachmentAdapterFactoryIdentifier, () => ({
|
di.addImpl(AttachmentAdapterFactoryIdentifier, () => ({
|
||||||
get: (job: Job) => new AttachmentAdapter(job),
|
get: (job: Transformer) => new AttachmentAdapter(job),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ import {
|
|||||||
type FromDocSnapshotResult,
|
type FromDocSnapshotResult,
|
||||||
type FromSliceSnapshotPayload,
|
type FromSliceSnapshotPayload,
|
||||||
type FromSliceSnapshotResult,
|
type FromSliceSnapshotResult,
|
||||||
type Job,
|
|
||||||
nanoid,
|
nanoid,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
type ToBlockSnapshotPayload,
|
type ToBlockSnapshotPayload,
|
||||||
type ToDocSnapshotPayload,
|
type ToDocSnapshotPayload,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import type { Root } from 'hast';
|
import type { Root } from 'hast';
|
||||||
import rehypeParse from 'rehype-parse';
|
import rehypeParse from 'rehype-parse';
|
||||||
@@ -172,7 +172,7 @@ export class HtmlAdapter extends BaseAdapter<Html> {
|
|||||||
|
|
||||||
readonly blockMatchers: BlockHtmlAdapterMatcher[];
|
readonly blockMatchers: BlockHtmlAdapterMatcher[];
|
||||||
|
|
||||||
constructor(job: Job, provider: ServiceProvider) {
|
constructor(job: Transformer, provider: ServiceProvider) {
|
||||||
super(job);
|
super(job);
|
||||||
const blockMatchers = Array.from(
|
const blockMatchers = Array.from(
|
||||||
provider.getAll(BlockHtmlAdapterMatcherIdentifier).values()
|
provider.getAll(BlockHtmlAdapterMatcherIdentifier).values()
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ import {
|
|||||||
type FromDocSnapshotResult,
|
type FromDocSnapshotResult,
|
||||||
type FromSliceSnapshotPayload,
|
type FromSliceSnapshotPayload,
|
||||||
type FromSliceSnapshotResult,
|
type FromSliceSnapshotResult,
|
||||||
type Job,
|
|
||||||
nanoid,
|
nanoid,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
type ToBlockSnapshotPayload,
|
type ToBlockSnapshotPayload,
|
||||||
type ToDocSnapshotPayload,
|
type ToDocSnapshotPayload,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import { AdapterFactoryIdentifier } from './types/adapter';
|
import { AdapterFactoryIdentifier } from './types/adapter';
|
||||||
@@ -123,7 +123,7 @@ export const ImageAdapterFactoryIdentifier = AdapterFactoryIdentifier('Image');
|
|||||||
export const ImageAdapterFactoryExtension: ExtensionType = {
|
export const ImageAdapterFactoryExtension: ExtensionType = {
|
||||||
setup: di => {
|
setup: di => {
|
||||||
di.addImpl(ImageAdapterFactoryIdentifier, () => ({
|
di.addImpl(ImageAdapterFactoryIdentifier, () => ({
|
||||||
get: (job: Job) => new ImageAdapter(job),
|
get: (job: Transformer) => new ImageAdapter(job),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ import {
|
|||||||
type FromDocSnapshotResult,
|
type FromDocSnapshotResult,
|
||||||
type FromSliceSnapshotPayload,
|
type FromSliceSnapshotPayload,
|
||||||
type FromSliceSnapshotResult,
|
type FromSliceSnapshotResult,
|
||||||
type Job,
|
|
||||||
nanoid,
|
nanoid,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
type ToBlockSnapshotPayload,
|
type ToBlockSnapshotPayload,
|
||||||
type ToDocSnapshotPayload,
|
type ToDocSnapshotPayload,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import type { Root } from 'mdast';
|
import type { Root } from 'mdast';
|
||||||
import remarkMath from 'remark-math';
|
import remarkMath from 'remark-math';
|
||||||
@@ -171,7 +171,7 @@ export class MarkdownAdapter extends BaseAdapter<Markdown> {
|
|||||||
readonly blockMatchers: BlockMarkdownAdapterMatcher[];
|
readonly blockMatchers: BlockMarkdownAdapterMatcher[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
job: Job,
|
job: Transformer,
|
||||||
readonly provider: ServiceProvider
|
readonly provider: ServiceProvider
|
||||||
) {
|
) {
|
||||||
super(job);
|
super(job);
|
||||||
@@ -456,7 +456,7 @@ export const MarkdownAdapterFactoryIdentifier =
|
|||||||
export const MarkdownAdapterFactoryExtension: ExtensionType = {
|
export const MarkdownAdapterFactoryExtension: ExtensionType = {
|
||||||
setup: di => {
|
setup: di => {
|
||||||
di.addImpl(MarkdownAdapterFactoryIdentifier, provider => ({
|
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 {
|
import type {
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
DraftModel,
|
DraftModel,
|
||||||
JobMiddleware,
|
TransformerMiddleware,
|
||||||
JobSlots,
|
TransformerSlots,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import { matchFlavours } from '../../utils';
|
import { matchFlavours } from '../../utils';
|
||||||
@@ -33,7 +33,7 @@ const handlePoint = (
|
|||||||
model.text?.sliceToDelta(index, length + index);
|
model.text?.sliceToDelta(index, length + index);
|
||||||
};
|
};
|
||||||
|
|
||||||
const sliceText = (slots: JobSlots, std: EditorHost['std']) => {
|
const sliceText = (slots: TransformerSlots, std: EditorHost['std']) => {
|
||||||
slots.afterExport.on(payload => {
|
slots.afterExport.on(payload => {
|
||||||
if (payload.type === 'block') {
|
if (payload.type === 'block') {
|
||||||
const snapshot = payload.snapshot;
|
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 }) => {
|
return ({ slots }) => {
|
||||||
sliceText(slots, std);
|
sliceText(slots, std);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ import {
|
|||||||
type BlockSnapshot,
|
type BlockSnapshot,
|
||||||
type DeltaOperation,
|
type DeltaOperation,
|
||||||
fromJSON,
|
fromJSON,
|
||||||
type JobMiddleware,
|
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
type Text,
|
type Text,
|
||||||
|
type TransformerMiddleware,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import * as Y from 'yjs';
|
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 }) => {
|
return ({ slots }) => {
|
||||||
let tr: PasteTr | undefined;
|
let tr: PasteTr | undefined;
|
||||||
slots.beforeImport.on(payload => {
|
slots.beforeImport.on(payload => {
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ import {
|
|||||||
type FromDocSnapshotResult,
|
type FromDocSnapshotResult,
|
||||||
type FromSliceSnapshotPayload,
|
type FromSliceSnapshotPayload,
|
||||||
type FromSliceSnapshotResult,
|
type FromSliceSnapshotResult,
|
||||||
type Job,
|
|
||||||
nanoid,
|
nanoid,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
type ToBlockSnapshotPayload,
|
type ToBlockSnapshotPayload,
|
||||||
type ToDocSnapshotPayload,
|
type ToDocSnapshotPayload,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import { MarkdownAdapter } from './markdown/markdown';
|
import { MarkdownAdapter } from './markdown/markdown';
|
||||||
@@ -37,7 +37,7 @@ type MixTextToSliceSnapshotPayload = {
|
|||||||
export class MixTextAdapter extends BaseAdapter<MixText> {
|
export class MixTextAdapter extends BaseAdapter<MixText> {
|
||||||
private readonly _markdownAdapter: MarkdownAdapter;
|
private readonly _markdownAdapter: MarkdownAdapter;
|
||||||
|
|
||||||
constructor(job: Job, provider: ServiceProvider) {
|
constructor(job: Transformer, provider: ServiceProvider) {
|
||||||
super(job);
|
super(job);
|
||||||
this._markdownAdapter = new MarkdownAdapter(job, provider);
|
this._markdownAdapter = new MarkdownAdapter(job, provider);
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ export const MixTextAdapterFactoryIdentifier =
|
|||||||
export const MixTextAdapterFactoryExtension: ExtensionType = {
|
export const MixTextAdapterFactoryExtension: ExtensionType = {
|
||||||
setup: di => {
|
setup: di => {
|
||||||
di.addImpl(MixTextAdapterFactoryIdentifier, provider => ({
|
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 FromDocSnapshotResult,
|
||||||
type FromSliceSnapshotPayload,
|
type FromSliceSnapshotPayload,
|
||||||
type FromSliceSnapshotResult,
|
type FromSliceSnapshotResult,
|
||||||
type Job,
|
|
||||||
nanoid,
|
nanoid,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import rehypeParse from 'rehype-parse';
|
import rehypeParse from 'rehype-parse';
|
||||||
import { unified } from 'unified';
|
import { unified } from 'unified';
|
||||||
@@ -115,7 +115,7 @@ export class NotionHtmlAdapter extends BaseAdapter<NotionHtml> {
|
|||||||
|
|
||||||
readonly blockMatchers: BlockNotionHtmlAdapterMatcher[];
|
readonly blockMatchers: BlockNotionHtmlAdapterMatcher[];
|
||||||
|
|
||||||
constructor(job: Job, provider: ServiceProvider) {
|
constructor(job: Transformer, provider: ServiceProvider) {
|
||||||
super(job);
|
super(job);
|
||||||
const blockMatchers = Array.from(
|
const blockMatchers = Array.from(
|
||||||
provider.getAll(BlockNotionHtmlAdapterMatcherIdentifier).values()
|
provider.getAll(BlockNotionHtmlAdapterMatcherIdentifier).values()
|
||||||
@@ -294,7 +294,7 @@ export const NotionHtmlAdapterFactoryIdentifier =
|
|||||||
export const NotionHtmlAdapterFactoryExtension: ExtensionType = {
|
export const NotionHtmlAdapterFactoryExtension: ExtensionType = {
|
||||||
setup: di => {
|
setup: di => {
|
||||||
di.addImpl(NotionHtmlAdapterFactoryIdentifier, provider => ({
|
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 FromBlockSnapshotResult,
|
||||||
type FromDocSnapshotResult,
|
type FromDocSnapshotResult,
|
||||||
type FromSliceSnapshotResult,
|
type FromSliceSnapshotResult,
|
||||||
type Job,
|
|
||||||
nanoid,
|
nanoid,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import type { AffineTextAttributes } from '../types';
|
import type { AffineTextAttributes } from '../types';
|
||||||
@@ -164,7 +164,7 @@ export const NotionTextAdapterFactoryIdentifier =
|
|||||||
export const NotionTextAdapterFactoryExtension: ExtensionType = {
|
export const NotionTextAdapterFactoryExtension: ExtensionType = {
|
||||||
setup: di => {
|
setup: di => {
|
||||||
di.addImpl(NotionTextAdapterFactoryIdentifier, () => ({
|
di.addImpl(NotionTextAdapterFactoryIdentifier, () => ({
|
||||||
get: (job: Job) => new NotionTextAdapter(job),
|
get: (job: Transformer) => new NotionTextAdapter(job),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ import {
|
|||||||
type FromDocSnapshotResult,
|
type FromDocSnapshotResult,
|
||||||
type FromSliceSnapshotPayload,
|
type FromSliceSnapshotPayload,
|
||||||
type FromSliceSnapshotResult,
|
type FromSliceSnapshotResult,
|
||||||
type Job,
|
|
||||||
nanoid,
|
nanoid,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
type ToBlockSnapshotPayload,
|
type ToBlockSnapshotPayload,
|
||||||
type ToDocSnapshotPayload,
|
type ToDocSnapshotPayload,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -50,7 +50,7 @@ export class PlainTextAdapter extends BaseAdapter<PlainText> {
|
|||||||
readonly blockMatchers: BlockPlainTextAdapterMatcher[];
|
readonly blockMatchers: BlockPlainTextAdapterMatcher[];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
job: Job,
|
job: Transformer,
|
||||||
readonly provider: ServiceProvider
|
readonly provider: ServiceProvider
|
||||||
) {
|
) {
|
||||||
super(job);
|
super(job);
|
||||||
@@ -321,7 +321,7 @@ export const PlainTextAdapterFactoryIdentifier =
|
|||||||
export const PlainTextAdapterFactoryExtension: ExtensionType = {
|
export const PlainTextAdapterFactoryExtension: ExtensionType = {
|
||||||
setup: di => {
|
setup: di => {
|
||||||
di.addImpl(PlainTextAdapterFactoryIdentifier, provider => ({
|
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 BaseAdapter,
|
||||||
type BlockSnapshot,
|
type BlockSnapshot,
|
||||||
BlockSnapshotSchema,
|
BlockSnapshotSchema,
|
||||||
type Job,
|
|
||||||
type NodeProps,
|
type NodeProps,
|
||||||
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import type { AffineTextAttributes } from '../../types/index.js';
|
import type { AffineTextAttributes } from '../../types/index.js';
|
||||||
@@ -35,7 +35,7 @@ export type AdapterContext<
|
|||||||
walker: ASTWalker<ONode, TNode>;
|
walker: ASTWalker<ONode, TNode>;
|
||||||
walkerContext: ASTWalkerContext<TNode>;
|
walkerContext: ASTWalkerContext<TNode>;
|
||||||
configs: Map<string, string>;
|
configs: Map<string, string>;
|
||||||
job: Job;
|
job: Transformer;
|
||||||
deltaConverter: TConverter;
|
deltaConverter: TConverter;
|
||||||
textBuffer: TextBuffer;
|
textBuffer: TextBuffer;
|
||||||
provider?: ServiceProvider;
|
provider?: ServiceProvider;
|
||||||
@@ -174,7 +174,7 @@ export type ASTToDeltaMatcher<AST> = {
|
|||||||
|
|
||||||
export type AdapterFactory = {
|
export type AdapterFactory = {
|
||||||
// TODO(@chen): Make it return the specific adapter type
|
// TODO(@chen): Make it return the specific adapter type
|
||||||
get: (job: Job) => BaseAdapter;
|
get: (job: Transformer) => BaseAdapter;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AdapterFactoryIdentifier =
|
export const AdapterFactoryIdentifier =
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export class DNDAPIExtension extends Extension {
|
|||||||
const { docId, flavour = 'affine:embed-linked-doc', blockId } = options;
|
const { docId, flavour = 'affine:embed-linked-doc', blockId } = options;
|
||||||
|
|
||||||
const slice = Slice.fromModels(this.std.store, []);
|
const slice = Slice.fromModels(this.std.store, []);
|
||||||
const job = this.std.getJob();
|
const job = this.std.getTransformer();
|
||||||
const snapshot = job.sliceToSnapshot(slice);
|
const snapshot = job.sliceToSnapshot(slice);
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
console.error('Failed to convert slice to snapshot');
|
console.error('Failed to convert slice to snapshot');
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||||
import type { JobMiddleware } from '@blocksuite/store';
|
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||||
|
|
||||||
export const newIdCrossDoc =
|
export const newIdCrossDoc =
|
||||||
(std: BlockStdScope): JobMiddleware =>
|
(std: BlockStdScope): TransformerMiddleware =>
|
||||||
({ slots }) => {
|
({ slots }) => {
|
||||||
let samePage = false;
|
let samePage = false;
|
||||||
slots.beforeImport.on(payload => {
|
slots.beforeImport.on(payload => {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { correctNumberedListsOrderToPrev } from '@blocksuite/affine-block-list';
|
import { correctNumberedListsOrderToPrev } from '@blocksuite/affine-block-list';
|
||||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||||
import type { JobMiddleware } from '@blocksuite/store';
|
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||||
|
|
||||||
export const reorderList =
|
export const reorderList =
|
||||||
(std: BlockStdScope): JobMiddleware =>
|
(std: BlockStdScope): TransformerMiddleware =>
|
||||||
({ slots }) => {
|
({ slots }) => {
|
||||||
slots.afterImport.on(payload => {
|
slots.afterImport.on(payload => {
|
||||||
if (payload.type === 'block') {
|
if (payload.type === 'block') {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||||
import type { JobMiddleware } from '@blocksuite/store';
|
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||||
|
|
||||||
export const surfaceRefToEmbed =
|
export const surfaceRefToEmbed =
|
||||||
(std: BlockStdScope): JobMiddleware =>
|
(std: BlockStdScope): TransformerMiddleware =>
|
||||||
({ slots }) => {
|
({ slots }) => {
|
||||||
let pageId: string | null = null;
|
let pageId: string | null = null;
|
||||||
slots.beforeImport.on(payload => {
|
slots.beforeImport.on(payload => {
|
||||||
|
|||||||
@@ -545,7 +545,7 @@ export class DragEventWatcher {
|
|||||||
|
|
||||||
private _getJob() {
|
private _getJob() {
|
||||||
const std = this._std;
|
const std = this._std;
|
||||||
return std.getJob([
|
return std.getTransformer([
|
||||||
newIdCrossDoc(std),
|
newIdCrossDoc(std),
|
||||||
reorderList(std),
|
reorderList(std),
|
||||||
surfaceRefToEmbed(std),
|
surfaceRefToEmbed(std),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Container } from '@blocksuite/global/di';
|
|||||||
import type {
|
import type {
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
DocSnapshot,
|
DocSnapshot,
|
||||||
JobMiddleware,
|
TransformerMiddleware,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import { AssetsManager, MemoryBlobCRUD } from '@blocksuite/store';
|
import { AssetsManager, MemoryBlobCRUD } from '@blocksuite/store';
|
||||||
import { describe, expect, test } from 'vitest';
|
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('title:4T5ObMgEIMII-4Bexyta1', 'Test Doc');
|
||||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { Container } from '@blocksuite/global/di';
|
|||||||
import type {
|
import type {
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
DocSnapshot,
|
DocSnapshot,
|
||||||
JobMiddleware,
|
|
||||||
SliceSnapshot,
|
SliceSnapshot,
|
||||||
|
TransformerMiddleware,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import { AssetsManager, MemoryBlobCRUD } from '@blocksuite/store';
|
import { AssetsManager, MemoryBlobCRUD } from '@blocksuite/store';
|
||||||
import { describe, expect, test } from 'vitest';
|
import { describe, expect, test } from 'vitest';
|
||||||
@@ -1931,7 +1931,7 @@ hhh
|
|||||||
|
|
||||||
hhh
|
hhh
|
||||||
`;
|
`;
|
||||||
const middleware: JobMiddleware = ({ adapterConfigs }) => {
|
const middleware: TransformerMiddleware = ({ adapterConfigs }) => {
|
||||||
adapterConfigs.set('title:deadbeef', 'test');
|
adapterConfigs.set('title:deadbeef', 'test');
|
||||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
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');
|
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||||
};
|
};
|
||||||
const mdAdapter = new MarkdownAdapter(createJob([middleware]), provider);
|
const mdAdapter = new MarkdownAdapter(createJob([middleware]), provider);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Container } from '@blocksuite/global/di';
|
|||||||
import type {
|
import type {
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
DocSnapshot,
|
DocSnapshot,
|
||||||
JobMiddleware,
|
TransformerMiddleware,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import { describe, expect, test } from 'vitest';
|
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('title:deadbeef', 'test');
|
||||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
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('title:4T5ObMgEIMII-4Bexyta1', 'test');
|
||||||
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
adapterConfigs.set('docLinkBaseUrl', 'https://example.com');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
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 { TestWorkspace } from '@blocksuite/store/test';
|
||||||
|
|
||||||
import { defaultImageProxyMiddleware } from '../../_common/transformers/middlewares.js';
|
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;
|
window.happyDOM.settings.fetch.disableSameOriginPolicy = true;
|
||||||
const testMiddlewares = middlewares ?? [];
|
const testMiddlewares = middlewares ?? [];
|
||||||
testMiddlewares.push(defaultImageProxyMiddleware);
|
testMiddlewares.push(defaultImageProxyMiddleware);
|
||||||
@@ -25,7 +29,7 @@ export function createJob(middlewares?: JobMiddleware[]) {
|
|||||||
const docCollection = new TestWorkspace({ schema });
|
const docCollection = new TestWorkspace({ schema });
|
||||||
docCollection.storeExtensions = [FeatureFlagService];
|
docCollection.storeExtensions = [FeatureFlagService];
|
||||||
docCollection.meta.initialize();
|
docCollection.meta.initialize();
|
||||||
return new Job({
|
return new Transformer({
|
||||||
schema,
|
schema,
|
||||||
blobCRUD: docCollection.blobSync,
|
blobCRUD: docCollection.blobSync,
|
||||||
middlewares: testMiddlewares,
|
middlewares: testMiddlewares,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { HtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
|||||||
import { Container } from '@blocksuite/global/di';
|
import { Container } from '@blocksuite/global/di';
|
||||||
import { sha } from '@blocksuite/global/utils';
|
import { sha } from '@blocksuite/global/utils';
|
||||||
import type { Store, Workspace } from '@blocksuite/store';
|
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 { defaultBlockHtmlAdapterMatchers } from '../adapters/html/block-matcher.js';
|
||||||
import { htmlInlineToDeltaMatchers } from '../adapters/html/delta-converter/html-inline.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.
|
* @returns A Promise that resolves when the export is complete.
|
||||||
*/
|
*/
|
||||||
async function exportDoc(doc: Store) {
|
async function exportDoc(doc: Store) {
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: doc.schema,
|
schema: doc.schema,
|
||||||
blobCRUD: doc.blobSync,
|
blobCRUD: doc.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -99,7 +99,7 @@ async function importHTMLToDoc({
|
|||||||
html,
|
html,
|
||||||
fileName,
|
fileName,
|
||||||
}: ImportHTMLToDocOptions) {
|
}: ImportHTMLToDocOptions) {
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -161,7 +161,7 @@ async function importHTMLZip({ collection, imported }: ImportHTMLZipOptions) {
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
htmlBlobs.map(async ([fileName, blob]) => {
|
htmlBlobs.map(async ([fileName, blob]) => {
|
||||||
const fileNameWithoutExt = fileName.replace(/\.[^/.]+$/, '');
|
const fileNameWithoutExt = fileName.replace(/\.[^/.]+$/, '');
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Container } from '@blocksuite/global/di';
|
|||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import { assertExists, sha } from '@blocksuite/global/utils';
|
import { assertExists, sha } from '@blocksuite/global/utils';
|
||||||
import type { Store, Workspace } from '@blocksuite/store';
|
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 { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js';
|
||||||
import { inlineDeltaToMarkdownAdapterMatchers } from '../adapters/markdown/delta-converter/inline-delta.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
|
* @returns A Promise that resolves when the export is complete
|
||||||
*/
|
*/
|
||||||
async function exportDoc(doc: Store) {
|
async function exportDoc(doc: Store) {
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: doc.schema,
|
schema: doc.schema,
|
||||||
blobCRUD: doc.blobSync,
|
blobCRUD: doc.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -109,7 +109,7 @@ async function importMarkdownToBlock({
|
|||||||
markdown,
|
markdown,
|
||||||
blockId,
|
blockId,
|
||||||
}: ImportMarkdownToBlockOptions) {
|
}: ImportMarkdownToBlockOptions) {
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: doc.schema,
|
schema: doc.schema,
|
||||||
blobCRUD: doc.blobSync,
|
blobCRUD: doc.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -154,7 +154,7 @@ async function importMarkdownToDoc({
|
|||||||
markdown,
|
markdown,
|
||||||
fileName,
|
fileName,
|
||||||
}: ImportMarkdownToDocOptions) {
|
}: ImportMarkdownToDocOptions) {
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -218,7 +218,7 @@ async function importMarkdownZip({
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
markdownBlobs.map(async ([fileName, blob]) => {
|
markdownBlobs.map(async ([fileName, blob]) => {
|
||||||
const fileNameWithoutExt = fileName.replace(/\.[^/.]+$/, '');
|
const fileNameWithoutExt = fileName.replace(/\.[^/.]+$/, '');
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -8,10 +8,14 @@ import type {
|
|||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import { DEFAULT_IMAGE_PROXY_ENDPOINT } from '@blocksuite/affine-shared/consts';
|
import { DEFAULT_IMAGE_PROXY_ENDPOINT } from '@blocksuite/affine-shared/consts';
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
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 =
|
export const replaceIdMiddleware =
|
||||||
(idGenerator: () => string): JobMiddleware =>
|
(idGenerator: () => string): TransformerMiddleware =>
|
||||||
({ slots, docCRUD }) => {
|
({ slots, docCRUD }) => {
|
||||||
const idMap = new Map<string, string>();
|
const idMap = new Map<string, string>();
|
||||||
slots.afterImport.on(payload => {
|
slots.afterImport.on(payload => {
|
||||||
@@ -202,7 +206,7 @@ export const replaceIdMiddleware =
|
|||||||
|
|
||||||
export const customImageProxyMiddleware = (
|
export const customImageProxyMiddleware = (
|
||||||
imageProxyURL: string
|
imageProxyURL: string
|
||||||
): JobMiddleware => {
|
): TransformerMiddleware => {
|
||||||
return ({ adapterConfigs }) => {
|
return ({ adapterConfigs }) => {
|
||||||
adapterConfigs.set('imageProxy', imageProxyURL);
|
adapterConfigs.set('imageProxy', imageProxyURL);
|
||||||
};
|
};
|
||||||
@@ -211,7 +215,7 @@ export const customImageProxyMiddleware = (
|
|||||||
const customDocLinkBaseUrlMiddleware = (
|
const customDocLinkBaseUrlMiddleware = (
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
collectionId: string
|
collectionId: string
|
||||||
): JobMiddleware => {
|
): TransformerMiddleware => {
|
||||||
return ({ adapterConfigs }) => {
|
return ({ adapterConfigs }) => {
|
||||||
const docLinkBaseUrl = baseUrl
|
const docLinkBaseUrl = baseUrl
|
||||||
? `${baseUrl}/workspace/${collectionId}`
|
? `${baseUrl}/workspace/${collectionId}`
|
||||||
@@ -221,7 +225,7 @@ const customDocLinkBaseUrlMiddleware = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const titleMiddleware =
|
export const titleMiddleware =
|
||||||
(metas: DocMeta[]): JobMiddleware =>
|
(metas: DocMeta[]): TransformerMiddleware =>
|
||||||
({ slots, adapterConfigs }) => {
|
({ slots, adapterConfigs }) => {
|
||||||
slots.beforeExport.on(() => {
|
slots.beforeExport.on(() => {
|
||||||
for (const meta of metas) {
|
for (const meta of metas) {
|
||||||
@@ -273,13 +277,13 @@ export const defaultImageProxyMiddleware =
|
|||||||
defaultImageProxyMiddlewarBuilder.get();
|
defaultImageProxyMiddlewarBuilder.get();
|
||||||
|
|
||||||
export const embedSyncedDocMiddleware =
|
export const embedSyncedDocMiddleware =
|
||||||
(type: 'content'): JobMiddleware =>
|
(type: 'content'): TransformerMiddleware =>
|
||||||
({ adapterConfigs }) => {
|
({ adapterConfigs }) => {
|
||||||
adapterConfigs.set('embedSyncedDocExportType', type);
|
adapterConfigs.set('embedSyncedDocExportType', type);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fileNameMiddleware =
|
export const fileNameMiddleware =
|
||||||
(fileName?: string): JobMiddleware =>
|
(fileName?: string): TransformerMiddleware =>
|
||||||
({ slots }) => {
|
({ slots }) => {
|
||||||
slots.beforeImport.on(payload => {
|
slots.beforeImport.on(payload => {
|
||||||
if (payload.type !== 'page') {
|
if (payload.type !== 'page') {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
||||||
import { Container } from '@blocksuite/global/di';
|
import { Container } from '@blocksuite/global/di';
|
||||||
import { sha } from '@blocksuite/global/utils';
|
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 { defaultBlockNotionHtmlAdapterMatchers } from '../adapters/notion-html/block-matcher.js';
|
||||||
import { notionHtmlInlineToDeltaMatchers } from '../adapters/notion-html/delta-converter/html-inline.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 }));
|
pendingAssets.set(key, new File([blob], fileName, { type: mime }));
|
||||||
}
|
}
|
||||||
const pagePromises = Array.from(pagePaths).map(async path => {
|
const pagePromises = Array.from(pagePaths).map(async path => {
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { sha } from '@blocksuite/global/utils';
|
import { sha } from '@blocksuite/global/utils';
|
||||||
import type { DocSnapshot, Store, Workspace } from '@blocksuite/store';
|
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 { download, Unzip, Zip } from '../transformers/utils.js';
|
||||||
import { replaceIdMiddleware, titleMiddleware } from './middlewares.js';
|
import { replaceIdMiddleware, titleMiddleware } from './middlewares.js';
|
||||||
|
|
||||||
async function exportDocs(collection: Workspace, docs: Store[]) {
|
async function exportDocs(collection: Workspace, docs: Store[]) {
|
||||||
const zip = new Zip();
|
const zip = new Zip();
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -77,7 +77,7 @@ async function importDocs(collection: Workspace, imported: Blob) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ import {
|
|||||||
type BlockSnapshot,
|
type BlockSnapshot,
|
||||||
BlockSnapshotSchema,
|
BlockSnapshotSchema,
|
||||||
fromJSON,
|
fromJSON,
|
||||||
Job,
|
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
|
Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
@@ -369,7 +369,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
if (mayBeSurfaceDataJson !== undefined) {
|
if (mayBeSurfaceDataJson !== undefined) {
|
||||||
const elementsRawData = JSON.parse(mayBeSurfaceDataJson);
|
const elementsRawData = JSON.parse(mayBeSurfaceDataJson);
|
||||||
const { snapshot, blobs } = elementsRawData;
|
const { snapshot, blobs } = elementsRawData;
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: this.std.workspace.schema,
|
schema: this.std.workspace.schema,
|
||||||
blobCRUD: this.std.workspace.blobSync,
|
blobCRUD: this.std.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -1373,7 +1373,7 @@ export async function prepareClipboardData(
|
|||||||
selectedAll: BlockSuite.EdgelessModel[],
|
selectedAll: BlockSuite.EdgelessModel[],
|
||||||
std: BlockStdScope
|
std: BlockStdScope
|
||||||
) {
|
) {
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: std.workspace.schema,
|
schema: std.workspace.schema,
|
||||||
blobCRUD: std.workspace.blobSync,
|
blobCRUD: std.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import {
|
|||||||
type BlockSnapshot,
|
type BlockSnapshot,
|
||||||
type DocSnapshot,
|
type DocSnapshot,
|
||||||
DocSnapshotSchema,
|
DocSnapshotSchema,
|
||||||
Job,
|
|
||||||
type SnapshotNode,
|
type SnapshotNode,
|
||||||
|
Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import type * as Y from 'yjs';
|
import type * as Y from 'yjs';
|
||||||
/**
|
/**
|
||||||
@@ -72,7 +72,7 @@ export class TemplateJob {
|
|||||||
|
|
||||||
private _template: DocSnapshot | null = null;
|
private _template: DocSnapshot | null = null;
|
||||||
|
|
||||||
job: Job;
|
job: Transformer;
|
||||||
|
|
||||||
model: SurfaceBlockModel;
|
model: SurfaceBlockModel;
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ export class TemplateJob {
|
|||||||
type: TemplateType;
|
type: TemplateType;
|
||||||
|
|
||||||
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
||||||
this.job = new Job({
|
this.job = new Transformer({
|
||||||
schema: model.doc.workspace.schema,
|
schema: model.doc.workspace.schema,
|
||||||
blobCRUD: model.doc.workspace.blobSync,
|
blobCRUD: model.doc.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
isGfxGroupCompatibleModel,
|
isGfxGroupCompatibleModel,
|
||||||
type SerializedElement,
|
type SerializedElement,
|
||||||
} from '@blocksuite/block-std/gfx';
|
} 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
|
* 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) {
|
export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
||||||
elements = sortEdgelessElements(elements);
|
elements = sortEdgelessElements(elements);
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: std.workspace.schema,
|
schema: std.workspace.schema,
|
||||||
blobCRUD: std.workspace.blobSync,
|
blobCRUD: std.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -58,7 +58,7 @@ export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
|||||||
export function serializeElement(
|
export function serializeElement(
|
||||||
element: GfxModel,
|
element: GfxModel,
|
||||||
elements: GfxModel[],
|
elements: GfxModel[],
|
||||||
job: Job
|
job: Transformer
|
||||||
) {
|
) {
|
||||||
if (element instanceof GfxBlockElementModel) {
|
if (element instanceof GfxBlockElementModel) {
|
||||||
const snapshot = job.blockToSnapshot(element);
|
const snapshot = job.blockToSnapshot(element);
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
|||||||
import type {
|
import type {
|
||||||
BaseAdapter,
|
BaseAdapter,
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
Job,
|
|
||||||
JobMiddleware,
|
|
||||||
Slice,
|
Slice,
|
||||||
Store,
|
Store,
|
||||||
|
Transformer,
|
||||||
|
TransformerMiddleware,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
import type { RootContentMap } from 'hast';
|
import type { RootContentMap } from 'hast';
|
||||||
@@ -17,8 +17,8 @@ import { unified } from 'unified';
|
|||||||
import { LifeCycleWatcher } from '../extension/index.js';
|
import { LifeCycleWatcher } from '../extension/index.js';
|
||||||
|
|
||||||
type AdapterConstructor<T extends BaseAdapter> =
|
type AdapterConstructor<T extends BaseAdapter> =
|
||||||
| { new (job: Job): T }
|
| { new (job: Transformer): T }
|
||||||
| (new (job: Job, provider: ServiceProvider) => T);
|
| (new (job: Transformer, provider: ServiceProvider) => T);
|
||||||
|
|
||||||
type AdapterMap = Map<
|
type AdapterMap = Map<
|
||||||
string,
|
string,
|
||||||
@@ -155,7 +155,7 @@ export class Clipboard extends LifeCycleWatcher {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
private _jobMiddlewares: JobMiddleware[] = [];
|
private _jobMiddlewares: TransformerMiddleware[] = [];
|
||||||
|
|
||||||
copy = async (slice: Slice) => {
|
copy = async (slice: Slice) => {
|
||||||
return this.copySlice(slice);
|
return this.copySlice(slice);
|
||||||
@@ -257,11 +257,11 @@ export class Clipboard extends LifeCycleWatcher {
|
|||||||
this._adapterMap.delete(mimeType);
|
this._adapterMap.delete(mimeType);
|
||||||
};
|
};
|
||||||
|
|
||||||
unuse = (middleware: JobMiddleware) => {
|
unuse = (middleware: TransformerMiddleware) => {
|
||||||
this._jobMiddlewares = this._jobMiddlewares.filter(m => m !== middleware);
|
this._jobMiddlewares = this._jobMiddlewares.filter(m => m !== middleware);
|
||||||
};
|
};
|
||||||
|
|
||||||
use = (middleware: JobMiddleware) => {
|
use = (middleware: TransformerMiddleware) => {
|
||||||
this._jobMiddlewares.push(middleware);
|
this._jobMiddlewares.push(middleware);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ export class Clipboard extends LifeCycleWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _getJob() {
|
private _getJob() {
|
||||||
return this.std.getJob(this._jobMiddlewares);
|
return this.std.getTransformer(this._jobMiddlewares);
|
||||||
}
|
}
|
||||||
|
|
||||||
readFromClipboard(clipboardData: DataTransfer) {
|
readFromClipboard(clipboardData: DataTransfer) {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import { Container, type ServiceProvider } from '@blocksuite/global/di';
|
|||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import {
|
import {
|
||||||
type ExtensionType,
|
type ExtensionType,
|
||||||
Job,
|
|
||||||
type JobMiddleware,
|
|
||||||
type Store,
|
type Store,
|
||||||
StoreSelectionExtension,
|
StoreSelectionExtension,
|
||||||
|
Transformer,
|
||||||
|
type TransformerMiddleware,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import { Clipboard } from '../clipboard/index.js';
|
import { Clipboard } from '../clipboard/index.js';
|
||||||
@@ -161,8 +161,8 @@ export class BlockStdScope {
|
|||||||
return this.getOptional(BlockViewIdentifier(flavour));
|
return this.getOptional(BlockViewIdentifier(flavour));
|
||||||
}
|
}
|
||||||
|
|
||||||
getJob(middlewares: JobMiddleware[] = []) {
|
getTransformer(middlewares: TransformerMiddleware[] = []) {
|
||||||
return new Job({
|
return new Transformer({
|
||||||
schema: this.workspace.schema,
|
schema: this.workspace.schema,
|
||||||
blobCRUD: this.workspace.blobSync,
|
blobCRUD: this.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { BlockSuiteError } from '@blocksuite/global/exceptions';
|
|||||||
|
|
||||||
import type { DraftModel, Store } from '../model/index.js';
|
import type { DraftModel, Store } from '../model/index.js';
|
||||||
import type { AssetsManager } from '../transformer/assets.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 {
|
import type {
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
DocSnapshot,
|
DocSnapshot,
|
||||||
@@ -62,13 +62,13 @@ export function wrapFakeNote(snapshot: SliceSnapshot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export abstract class BaseAdapter<AdapterTarget = unknown> {
|
export abstract class BaseAdapter<AdapterTarget = unknown> {
|
||||||
job: Job;
|
job: Transformer;
|
||||||
|
|
||||||
get configs() {
|
get configs() {
|
||||||
return this.job.adapterConfigs;
|
return this.job.adapterConfigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(job: Job) {
|
constructor(job: Transformer) {
|
||||||
this.job = job;
|
this.job = job;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
|
|
||||||
import type { BlobCRUD } from './type.js';
|
import type { BlobCRUD } from './type';
|
||||||
|
|
||||||
type AssetsManagerConfig = {
|
type AssetsManagerConfig = {
|
||||||
blob: BlobCRUD;
|
blob: BlobCRUD;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import type { BlockModel } from '../model/block/block-model.js';
|
import type { BlockModel } from '../model/block/block-model';
|
||||||
import type { DraftModel } from '../model/block/draft.js';
|
import type { DraftModel } from '../model/block/draft';
|
||||||
import {
|
import {
|
||||||
type InternalPrimitives,
|
type InternalPrimitives,
|
||||||
internalPrimitives,
|
internalPrimitives,
|
||||||
} from '../model/block/zod.js';
|
} from '../model/block/zod';
|
||||||
import type { AssetsManager } from './assets.js';
|
import type { AssetsManager } from './assets';
|
||||||
import { fromJSON, toJSON } from './json.js';
|
import { fromJSON, toJSON } from './json';
|
||||||
import type { BlockSnapshot } from './type.js';
|
import type { BlockSnapshot } from './type';
|
||||||
|
|
||||||
export type BlockSnapshotLeaf = Pick<
|
export type BlockSnapshotLeaf = Pick<
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export * from './assets.js';
|
export * from './assets';
|
||||||
export * from './base.js';
|
export * from './base';
|
||||||
export * from './job.js';
|
export * from './json';
|
||||||
export * from './json.js';
|
export * from './middleware';
|
||||||
export * from './middleware.js';
|
export * from './slice';
|
||||||
export * from './slice.js';
|
export * from './transformer';
|
||||||
export * from './type.js';
|
export * from './type';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { NATIVE_UNIQ_IDENTIFIER, TEXT_UNIQ_IDENTIFIER } from '../consts.js';
|
import { NATIVE_UNIQ_IDENTIFIER, TEXT_UNIQ_IDENTIFIER } from '../consts';
|
||||||
import { Boxed } from '../reactive/boxed.js';
|
import { Boxed } from '../reactive/boxed';
|
||||||
import { isPureObject } from '../reactive/index.js';
|
import { isPureObject } from '../reactive/index';
|
||||||
import { Text } from '../reactive/text.js';
|
import { Text } from '../reactive/text';
|
||||||
|
|
||||||
export function toJSON(value: unknown): unknown {
|
export function toJSON(value: unknown): unknown {
|
||||||
if (value instanceof Boxed) {
|
if (value instanceof Boxed) {
|
||||||
|
|||||||
@@ -71,18 +71,20 @@ export type FinalPayload =
|
|||||||
type: 'info';
|
type: 'info';
|
||||||
};
|
};
|
||||||
|
|
||||||
export type JobSlots = {
|
export type TransformerSlots = {
|
||||||
beforeImport: Slot<BeforeImportPayload>;
|
beforeImport: Slot<BeforeImportPayload>;
|
||||||
afterImport: Slot<FinalPayload>;
|
afterImport: Slot<FinalPayload>;
|
||||||
beforeExport: Slot<BeforeExportPayload>;
|
beforeExport: Slot<BeforeExportPayload>;
|
||||||
afterExport: Slot<FinalPayload>;
|
afterExport: Slot<FinalPayload>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type JobMiddlewareOptions = {
|
type TransformerMiddlewareOptions = {
|
||||||
assetsManager: AssetsManager;
|
assetsManager: AssetsManager;
|
||||||
slots: JobSlots;
|
slots: TransformerSlots;
|
||||||
docCRUD: DocCRUD;
|
docCRUD: DocCRUD;
|
||||||
adapterConfigs: Map<string, string>;
|
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 = {
|
type SliceData = {
|
||||||
content: DraftModel[];
|
content: DraftModel[];
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import type {
|
|||||||
BeforeExportPayload,
|
BeforeExportPayload,
|
||||||
BeforeImportPayload,
|
BeforeImportPayload,
|
||||||
FinalPayload,
|
FinalPayload,
|
||||||
JobMiddleware,
|
TransformerMiddleware,
|
||||||
JobSlots,
|
TransformerSlots,
|
||||||
} from './middleware.js';
|
} from './middleware.js';
|
||||||
import { Slice } from './slice.js';
|
import { Slice } from './slice.js';
|
||||||
import type {
|
import type {
|
||||||
@@ -31,11 +31,11 @@ import {
|
|||||||
SliceSnapshotSchema,
|
SliceSnapshotSchema,
|
||||||
} from './type.js';
|
} from './type.js';
|
||||||
|
|
||||||
export type JobConfig = {
|
export type TransformerOptions = {
|
||||||
schema: Schema;
|
schema: Schema;
|
||||||
blobCRUD: BlobCRUD;
|
blobCRUD: BlobCRUD;
|
||||||
docCRUD: DocCRUD;
|
docCRUD: DocCRUD;
|
||||||
middlewares?: JobMiddleware[];
|
middlewares?: TransformerMiddleware[];
|
||||||
};
|
};
|
||||||
|
|
||||||
interface FlatSnapshot {
|
interface FlatSnapshot {
|
||||||
@@ -53,7 +53,7 @@ interface DraftBlockTreeNode {
|
|||||||
// The number of blocks to insert in one batch
|
// The number of blocks to insert in one batch
|
||||||
const BATCH_SIZE = 100;
|
const BATCH_SIZE = 100;
|
||||||
|
|
||||||
export class Job {
|
export class Transformer {
|
||||||
private readonly _adapterConfigs = new Map<string, string>();
|
private readonly _adapterConfigs = new Map<string, string>();
|
||||||
|
|
||||||
private readonly _assetsManager: AssetsManager;
|
private readonly _assetsManager: AssetsManager;
|
||||||
@@ -62,7 +62,7 @@ export class Job {
|
|||||||
|
|
||||||
private readonly _docCRUD: DocCRUD;
|
private readonly _docCRUD: DocCRUD;
|
||||||
|
|
||||||
private readonly _slots: JobSlots = {
|
private readonly _slots: TransformerSlots = {
|
||||||
beforeImport: new Slot<BeforeImportPayload>(),
|
beforeImport: new Slot<BeforeImportPayload>(),
|
||||||
afterImport: new Slot<FinalPayload>(),
|
afterImport: new Slot<FinalPayload>(),
|
||||||
beforeExport: new Slot<BeforeExportPayload>(),
|
beforeExport: new Slot<BeforeExportPayload>(),
|
||||||
@@ -338,7 +338,12 @@ export class Job {
|
|||||||
return this._docCRUD;
|
return this._docCRUD;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor({ blobCRUD, schema, docCRUD, middlewares = [] }: JobConfig) {
|
constructor({
|
||||||
|
blobCRUD,
|
||||||
|
schema,
|
||||||
|
docCRUD,
|
||||||
|
middlewares = [],
|
||||||
|
}: TransformerOptions) {
|
||||||
this._assetsManager = new AssetsManager({ blob: blobCRUD });
|
this._assetsManager = new AssetsManager({ blob: blobCRUD });
|
||||||
this._schema = schema;
|
this._schema = schema;
|
||||||
this._docCRUD = docCRUD;
|
this._docCRUD = docCRUD;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import type { Store } from '../model/store/store.js';
|
import type { Store } from '../model/store/store';
|
||||||
import type { DocMeta, DocsPropertiesMeta } from '../model/workspace-meta.js';
|
import type { DocMeta, DocsPropertiesMeta } from '../model/workspace-meta';
|
||||||
|
|
||||||
export type BlockSnapshot = {
|
export type BlockSnapshot = {
|
||||||
type: 'block';
|
type: 'block';
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import { WithDisposable } from '@blocksuite/global/utils';
|
import { WithDisposable } from '@blocksuite/global/utils';
|
||||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
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 { effect } from '@preact/signals-core';
|
||||||
import type SlTabPanel from '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
|
import type SlTabPanel from '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
|
||||||
import { css, html, type PropertyValues } from 'lit';
|
import { css, html, type PropertyValues } from 'lit';
|
||||||
@@ -101,7 +101,7 @@ export class AdaptersPanel extends WithDisposable(ShadowlessElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _createJob() {
|
private _createJob() {
|
||||||
return new Job({
|
return new Transformer({
|
||||||
schema: this.doc.collection.schema,
|
schema: this.doc.collection.schema,
|
||||||
blobCRUD: this.doc.collection.blobSync,
|
blobCRUD: this.doc.collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
|||||||
import type { SerializedXYWH } from '@blocksuite/global/utils';
|
import type { SerializedXYWH } from '@blocksuite/global/utils';
|
||||||
import type { DeltaInsert } from '@blocksuite/inline/types';
|
import type { DeltaInsert } from '@blocksuite/inline/types';
|
||||||
import { AffineEditorContainer, type CommentPanel } from '@blocksuite/presets';
|
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 type { SlDropdown } from '@shoelace-style/shoelace';
|
||||||
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js';
|
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js';
|
||||||
import { css, html } from 'lit';
|
import { css, html } from 'lit';
|
||||||
@@ -241,7 +241,7 @@ export class StarterDebugMenu extends ShadowlessElement {
|
|||||||
|
|
||||||
private async _exportFile(config: AdapterConfig) {
|
private async _exportFile(config: AdapterConfig) {
|
||||||
const doc = this.editor.doc;
|
const doc = this.editor.doc;
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: this.collection.schema,
|
schema: this.collection.schema,
|
||||||
blobCRUD: this.collection.blobSync,
|
blobCRUD: this.collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -442,7 +442,7 @@ export class StarterDebugMenu extends ShadowlessElement {
|
|||||||
multiple: false,
|
multiple: false,
|
||||||
});
|
});
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: this.collection.schema,
|
schema: this.collection.schema,
|
||||||
blobCRUD: this.collection.blobSync,
|
blobCRUD: this.collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
4
blocksuite/playground/apps/env.d.ts
vendored
4
blocksuite/playground/apps/env.d.ts
vendored
@@ -1,7 +1,7 @@
|
|||||||
import type { EditorHost } from '@blocksuite/block-std';
|
import type { EditorHost } from '@blocksuite/block-std';
|
||||||
import type { TestUtils } from '@blocksuite/blocks';
|
import type { TestUtils } from '@blocksuite/blocks';
|
||||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
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 { z } from 'zod';
|
||||||
import type * as Y from 'yjs';
|
import type * as Y from 'yjs';
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ declare global {
|
|||||||
doc: Blocks;
|
doc: Blocks;
|
||||||
collection: Workspace;
|
collection: Workspace;
|
||||||
blockSchemas: z.infer<typeof BlockSchema>[];
|
blockSchemas: z.infer<typeof BlockSchema>[];
|
||||||
job: Job;
|
job: Transformer;
|
||||||
Y: typeof Y;
|
Y: typeof Y;
|
||||||
std: typeof std;
|
std: typeof std;
|
||||||
testUtils: TestUtils;
|
testUtils: TestUtils;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AffineSchemas, SpecProvider, TestUtils } from '@blocksuite/blocks';
|
import { AffineSchemas, SpecProvider, TestUtils } from '@blocksuite/blocks';
|
||||||
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
||||||
import { Job, nanoid, Schema } from '@blocksuite/store';
|
import { nanoid, Schema, Transformer } from '@blocksuite/store';
|
||||||
import {
|
import {
|
||||||
createAutoIncrementIdGenerator,
|
createAutoIncrementIdGenerator,
|
||||||
type DocCollectionOptions,
|
type DocCollectionOptions,
|
||||||
@@ -81,7 +81,7 @@ export function createStarterDocCollection() {
|
|||||||
// debug info
|
// debug info
|
||||||
window.collection = collection;
|
window.collection = collection;
|
||||||
window.blockSchemas = AffineSchemas;
|
window.blockSchemas = AffineSchemas;
|
||||||
window.job = new Job({
|
window.job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import { replaceIdMiddleware } from '@blocksuite/blocks';
|
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(
|
export async function importFromSnapshot(
|
||||||
collection: Workspace,
|
collection: Workspace,
|
||||||
snapshot: DocSnapshot
|
snapshot: DocSnapshot
|
||||||
) {
|
) {
|
||||||
const job = new Job({
|
const job = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { effects as blocksEffects } from '@blocksuite/blocks/effects';
|
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';
|
import { effects } from '../../effects.js';
|
||||||
|
|
||||||
@@ -113,11 +113,11 @@ declare global {
|
|||||||
const editor: AffineEditorContainer;
|
const editor: AffineEditorContainer;
|
||||||
const doc: Store;
|
const doc: Store;
|
||||||
const collection: TestWorkspace;
|
const collection: TestWorkspace;
|
||||||
const job: Job;
|
const job: Transformer;
|
||||||
interface Window {
|
interface Window {
|
||||||
editor: AffineEditorContainer;
|
editor: AffineEditorContainer;
|
||||||
doc: Store;
|
doc: Store;
|
||||||
job: Job;
|
job: Transformer;
|
||||||
collection: TestWorkspace;
|
collection: TestWorkspace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,12 @@ import type {
|
|||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||||
import type { StarterDebugMenu } from '@playground/apps/_common/components/starter-debug-menu.js';
|
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 {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -43,6 +48,6 @@ declare global {
|
|||||||
editor: AffineEditorContainer;
|
editor: AffineEditorContainer;
|
||||||
host: EditorHost;
|
host: EditorHost;
|
||||||
testUtils: TestUtils;
|
testUtils: TestUtils;
|
||||||
job: Job;
|
job: Transformer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import {
|
|||||||
titleMiddleware,
|
titleMiddleware,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { Container } from '@blocksuite/affine/global/di';
|
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 { App as CapacitorApp } from '@capacitor/app';
|
||||||
import { Browser } from '@capacitor/browser';
|
import { Browser } from '@capacitor/browser';
|
||||||
import { Haptics } from '@capacitor/haptics';
|
import { Haptics } from '@capacitor/haptics';
|
||||||
@@ -181,7 +181,7 @@ const frameworkProvider = framework.provider();
|
|||||||
try {
|
try {
|
||||||
const blockSuiteDoc = doc.blockSuiteDoc;
|
const blockSuiteDoc = doc.blockSuiteDoc;
|
||||||
|
|
||||||
const job = new Job({
|
const transformer = new Transformer({
|
||||||
schema: blockSuiteDoc.workspace.schema,
|
schema: blockSuiteDoc.workspace.schema,
|
||||||
blobCRUD: blockSuiteDoc.workspace.blobSync,
|
blobCRUD: blockSuiteDoc.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -194,7 +194,7 @@ const frameworkProvider = framework.provider();
|
|||||||
titleMiddleware(blockSuiteDoc.workspace.meta.docMetas),
|
titleMiddleware(blockSuiteDoc.workspace.meta.docMetas),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
const snapshot = job.docToSnapshot(blockSuiteDoc);
|
const snapshot = transformer.docToSnapshot(blockSuiteDoc);
|
||||||
|
|
||||||
const container = new Container();
|
const container = new Container();
|
||||||
[
|
[
|
||||||
@@ -206,14 +206,14 @@ const frameworkProvider = framework.provider();
|
|||||||
});
|
});
|
||||||
const provider = container.provider();
|
const provider = container.provider();
|
||||||
|
|
||||||
const adapter = new MarkdownAdapter(job, provider);
|
const adapter = new MarkdownAdapter(transformer, provider);
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const markdownResult = await adapter.fromDocSnapshot({
|
const markdownResult = await adapter.fromDocSnapshot({
|
||||||
snapshot,
|
snapshot,
|
||||||
assets: job.assetsManager,
|
assets: transformer.assetsManager,
|
||||||
});
|
});
|
||||||
return markdownResult.file;
|
return markdownResult.file;
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
|
|||||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||||
import type {
|
import type {
|
||||||
ExtensionType,
|
ExtensionType,
|
||||||
JobMiddleware,
|
|
||||||
Query,
|
Query,
|
||||||
Schema,
|
Schema,
|
||||||
Store,
|
Store,
|
||||||
|
TransformerMiddleware,
|
||||||
} from '@blocksuite/affine/store';
|
} from '@blocksuite/affine/store';
|
||||||
import { css, html, nothing, type PropertyValues } from 'lit';
|
import { css, html, nothing, type PropertyValues } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
@@ -85,7 +85,7 @@ export type TextRendererOptions = {
|
|||||||
maxHeight?: number;
|
maxHeight?: number;
|
||||||
customHeading?: boolean;
|
customHeading?: boolean;
|
||||||
extensions?: ExtensionType[];
|
extensions?: ExtensionType[];
|
||||||
additionalMiddlewares?: JobMiddleware[];
|
additionalMiddlewares?: TransformerMiddleware[];
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo: refactor it for more general purpose usage instead of AI only?
|
// todo: refactor it for more general purpose usage instead of AI only?
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ import type {
|
|||||||
BlockModel,
|
BlockModel,
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
DraftModel,
|
DraftModel,
|
||||||
JobMiddleware,
|
|
||||||
Schema,
|
Schema,
|
||||||
Slice,
|
Slice,
|
||||||
SliceSnapshot,
|
SliceSnapshot,
|
||||||
Store,
|
Store,
|
||||||
|
TransformerMiddleware,
|
||||||
} from '@blocksuite/affine/store';
|
} from '@blocksuite/affine/store';
|
||||||
import { Job } from '@blocksuite/affine/store';
|
import { Transformer } from '@blocksuite/affine/store';
|
||||||
|
|
||||||
const updateSnapshotText = (
|
const updateSnapshotText = (
|
||||||
point: TextRangePoint,
|
point: TextRangePoint,
|
||||||
@@ -79,7 +79,7 @@ export async function getContentFromSlice(
|
|||||||
slice: Slice,
|
slice: Slice,
|
||||||
type: 'markdown' | 'plain-text' = 'markdown'
|
type: 'markdown' | 'plain-text' = 'markdown'
|
||||||
) {
|
) {
|
||||||
const job = new Job({
|
const transformer = new Transformer({
|
||||||
schema: host.std.store.workspace.schema,
|
schema: host.std.store.workspace.schema,
|
||||||
blobCRUD: host.std.store.workspace.blobSync,
|
blobCRUD: host.std.store.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -92,24 +92,24 @@ export async function getContentFromSlice(
|
|||||||
embedSyncedDocMiddleware('content'),
|
embedSyncedDocMiddleware('content'),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
const snapshot = job.sliceToSnapshot(slice);
|
const snapshot = transformer.sliceToSnapshot(slice);
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
processTextInSnapshot(snapshot, host);
|
processTextInSnapshot(snapshot, host);
|
||||||
const adapter =
|
const adapter =
|
||||||
type === 'markdown'
|
type === 'markdown'
|
||||||
? new MarkdownAdapter(job, host.std.provider)
|
? new MarkdownAdapter(transformer, host.std.provider)
|
||||||
: new PlainTextAdapter(job, host.std.provider);
|
: new PlainTextAdapter(transformer, host.std.provider);
|
||||||
const content = await adapter.fromSliceSnapshot({
|
const content = await adapter.fromSliceSnapshot({
|
||||||
snapshot,
|
snapshot,
|
||||||
assets: job.assetsManager,
|
assets: transformer.assetsManager,
|
||||||
});
|
});
|
||||||
return content.file;
|
return content.file;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPlainTextFromSlice(host: EditorHost, slice: Slice) {
|
export async function getPlainTextFromSlice(host: EditorHost, slice: Slice) {
|
||||||
const job = new Job({
|
const transformer = new Transformer({
|
||||||
schema: host.std.store.workspace.schema,
|
schema: host.std.store.workspace.schema,
|
||||||
blobCRUD: host.std.store.workspace.blobSync,
|
blobCRUD: host.std.store.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -119,15 +119,15 @@ export async function getPlainTextFromSlice(host: EditorHost, slice: Slice) {
|
|||||||
},
|
},
|
||||||
middlewares: [titleMiddleware(host.std.store.workspace.meta.docMetas)],
|
middlewares: [titleMiddleware(host.std.store.workspace.meta.docMetas)],
|
||||||
});
|
});
|
||||||
const snapshot = job.sliceToSnapshot(slice);
|
const snapshot = transformer.sliceToSnapshot(slice);
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
processTextInSnapshot(snapshot, host);
|
processTextInSnapshot(snapshot, host);
|
||||||
const plainTextAdapter = new PlainTextAdapter(job, host.std.provider);
|
const plainTextAdapter = new PlainTextAdapter(transformer, host.std.provider);
|
||||||
const plainText = await plainTextAdapter.fromSliceSnapshot({
|
const plainText = await plainTextAdapter.fromSliceSnapshot({
|
||||||
snapshot,
|
snapshot,
|
||||||
assets: job.assetsManager,
|
assets: transformer.assetsManager,
|
||||||
});
|
});
|
||||||
return plainText.file;
|
return plainText.file;
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ export const markdownToSnapshot = async (
|
|||||||
markdown: string,
|
markdown: string,
|
||||||
host: EditorHost
|
host: EditorHost
|
||||||
) => {
|
) => {
|
||||||
const job = new Job({
|
const transformer = new Transformer({
|
||||||
schema: host.std.store.workspace.schema,
|
schema: host.std.store.workspace.schema,
|
||||||
blobCRUD: host.std.store.workspace.blobSync,
|
blobCRUD: host.std.store.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -146,10 +146,10 @@ export const markdownToSnapshot = async (
|
|||||||
},
|
},
|
||||||
middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)],
|
middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)],
|
||||||
});
|
});
|
||||||
const markdownAdapter = new MixTextAdapter(job, host.std.provider);
|
const markdownAdapter = new MixTextAdapter(transformer, host.std.provider);
|
||||||
const payload = {
|
const payload = {
|
||||||
file: markdown,
|
file: markdown,
|
||||||
assets: job.assetsManager,
|
assets: transformer.assetsManager,
|
||||||
workspaceId: host.std.store.workspace.id,
|
workspaceId: host.std.store.workspace.id,
|
||||||
pageId: host.std.store.id,
|
pageId: host.std.store.id,
|
||||||
};
|
};
|
||||||
@@ -159,7 +159,7 @@ export const markdownToSnapshot = async (
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
snapshot,
|
snapshot,
|
||||||
job,
|
transformer,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -170,14 +170,14 @@ export async function insertFromMarkdown(
|
|||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
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 snapshots = snapshot.content.flatMap(x => x.children);
|
||||||
|
|
||||||
const models: BlockModel[] = [];
|
const models: BlockModel[] = [];
|
||||||
for (let i = 0; i < snapshots.length; i++) {
|
for (let i = 0; i < snapshots.length; i++) {
|
||||||
const blockSnapshot = snapshots[i];
|
const blockSnapshot = snapshots[i];
|
||||||
const model = await job.snapshotToBlock(
|
const model = await transformer.snapshotToBlock(
|
||||||
blockSnapshot,
|
blockSnapshot,
|
||||||
doc,
|
doc,
|
||||||
parent,
|
parent,
|
||||||
@@ -198,15 +198,15 @@ export async function replaceFromMarkdown(
|
|||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) {
|
) {
|
||||||
const { snapshot, job } = await markdownToSnapshot(markdown, host);
|
const { snapshot, transformer } = await markdownToSnapshot(markdown, host);
|
||||||
await job.snapshotToSlice(snapshot, host.doc, parent, index);
|
await transformer.snapshotToSlice(snapshot, host.doc, parent, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function markDownToDoc(
|
export async function markDownToDoc(
|
||||||
provider: ServiceProvider,
|
provider: ServiceProvider,
|
||||||
schema: Schema,
|
schema: Schema,
|
||||||
answer: string,
|
answer: string,
|
||||||
additionalMiddlewares?: JobMiddleware[]
|
additionalMiddlewares?: TransformerMiddleware[]
|
||||||
) {
|
) {
|
||||||
// Should not create a new doc in the original collection
|
// Should not create a new doc in the original collection
|
||||||
const collection = new WorkspaceImpl({
|
const collection = new WorkspaceImpl({
|
||||||
@@ -217,7 +217,7 @@ export async function markDownToDoc(
|
|||||||
if (additionalMiddlewares) {
|
if (additionalMiddlewares) {
|
||||||
middlewares.push(...additionalMiddlewares);
|
middlewares.push(...additionalMiddlewares);
|
||||||
}
|
}
|
||||||
const job = new Job({
|
const transformer = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -227,10 +227,10 @@ export async function markDownToDoc(
|
|||||||
},
|
},
|
||||||
middlewares,
|
middlewares,
|
||||||
});
|
});
|
||||||
const mdAdapter = new MarkdownAdapter(job, provider);
|
const mdAdapter = new MarkdownAdapter(transformer, provider);
|
||||||
const doc = await mdAdapter.toDoc({
|
const doc = await mdAdapter.toDoc({
|
||||||
file: answer,
|
file: answer,
|
||||||
assets: job.assetsManager,
|
assets: transformer.assetsManager,
|
||||||
});
|
});
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
console.error('Failed to convert markdown to doc');
|
console.error('Failed to convert markdown to doc');
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
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 { css, html, LitElement, nothing } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
import { repeat } from 'lit/directives/repeat.js';
|
import { repeat } from 'lit/directives/repeat.js';
|
||||||
@@ -236,7 +236,7 @@ export const markdownToMindmap = (
|
|||||||
provider: ServiceProvider
|
provider: ServiceProvider
|
||||||
) => {
|
) => {
|
||||||
let result: Node | null = null;
|
let result: Node | null = null;
|
||||||
const job = new Job({
|
const transformer = new Transformer({
|
||||||
schema: doc.workspace.schema,
|
schema: doc.workspace.schema,
|
||||||
blobCRUD: doc.workspace.blobSync,
|
blobCRUD: doc.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -245,7 +245,7 @@ export const markdownToMindmap = (
|
|||||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
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 ast: Root = markdown['_markdownToAst'](answer);
|
||||||
const traverse = (
|
const traverse = (
|
||||||
markdownNode: Unpacked<(typeof ast)['children']>,
|
markdownNode: Unpacked<(typeof ast)['children']>,
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ export const replace = async (
|
|||||||
|
|
||||||
if (textSelection) {
|
if (textSelection) {
|
||||||
host.std.command.exec('deleteText', { textSelection });
|
host.std.command.exec('deleteText', { textSelection });
|
||||||
const { snapshot, job } = await markdownToSnapshot(content, host);
|
const { snapshot, transformer } = await markdownToSnapshot(content, host);
|
||||||
await job.snapshotToSlice(
|
await transformer.snapshotToSlice(
|
||||||
snapshot,
|
snapshot,
|
||||||
host.doc,
|
host.doc,
|
||||||
firstBlockParent.model.id,
|
firstBlockParent.model.id,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
} from '@affine/core/modules/workspace';
|
} from '@affine/core/modules/workspace';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import track from '@affine/track';
|
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 { ToggleDownIcon } from '@blocksuite/icons/rc';
|
||||||
import * as Collapsible from '@radix-ui/react-collapsible';
|
import * as Collapsible from '@radix-ui/react-collapsible';
|
||||||
import {
|
import {
|
||||||
@@ -198,7 +198,9 @@ export const BacklinkGroups = () => {
|
|||||||
|
|
||||||
const backlinkGroups = useBacklinkGroups();
|
const backlinkGroups = useBacklinkGroups();
|
||||||
const textRendererOptions = useMemo(() => {
|
const textRendererOptions = useMemo(() => {
|
||||||
const docLinkBaseURLMiddleware: JobMiddleware = ({ adapterConfigs }) => {
|
const docLinkBaseURLMiddleware: TransformerMiddleware = ({
|
||||||
|
adapterConfigs,
|
||||||
|
}) => {
|
||||||
adapterConfigs.set(
|
adapterConfigs.set(
|
||||||
'docLinkBaseUrl',
|
'docLinkBaseUrl',
|
||||||
`/workspace/${workspaceService.workspace.id}`
|
`/workspace/${workspaceService.workspace.id}`
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
ZipTransformer,
|
ZipTransformer,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
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 { useLiveData, useService } from '@toeverything/infra';
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
@@ -58,7 +58,7 @@ async function exportDoc(
|
|||||||
std: BlockStdScope,
|
std: BlockStdScope,
|
||||||
config: AdapterConfig
|
config: AdapterConfig
|
||||||
) {
|
) {
|
||||||
const job = new Job({
|
const transformer = new Transformer({
|
||||||
schema: doc.workspace.schema,
|
schema: doc.workspace.schema,
|
||||||
blobCRUD: doc.workspace.blobSync,
|
blobCRUD: doc.workspace.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -74,7 +74,7 @@ async function exportDoc(
|
|||||||
});
|
});
|
||||||
|
|
||||||
const adapterFactory = std.provider.get(config.identifier);
|
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;
|
const result = (await adapter.fromDoc(doc)) as AdapterResult;
|
||||||
|
|
||||||
if (!result || (!result.file && !result.assetsIds.length)) {
|
if (!result || (!result.file && !result.assetsIds.length)) {
|
||||||
@@ -88,10 +88,10 @@ async function exportDoc(
|
|||||||
let name: string;
|
let name: string;
|
||||||
|
|
||||||
if (result.assetsIds.length > 0) {
|
if (result.assetsIds.length > 0) {
|
||||||
if (!job.assets) {
|
if (!transformer.assets) {
|
||||||
throw new Error('No assets found');
|
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);
|
await zip.file(config.indexFileName, contentBlob);
|
||||||
downloadBlob = await zip.generate();
|
downloadBlob = await zip.generate();
|
||||||
name = `${docTitle}.zip`;
|
name = `${docTitle}.zip`;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace';
|
import { WorkspaceImpl } from '@affine/core/modules/workspace/impls/workspace';
|
||||||
import { AffineSchemas } from '@blocksuite/affine/blocks';
|
import { AffineSchemas } from '@blocksuite/affine/blocks';
|
||||||
import type { DocSnapshot, Store } from '@blocksuite/affine/store';
|
import type { DocSnapshot, Store } from '@blocksuite/affine/store';
|
||||||
import { Job, Schema } from '@blocksuite/affine/store';
|
import { Schema, Transformer } from '@blocksuite/affine/store';
|
||||||
|
|
||||||
const getCollection = (() => {
|
const getCollection = (() => {
|
||||||
let collection: WorkspaceImpl | null = null;
|
let collection: WorkspaceImpl | null = null;
|
||||||
@@ -79,7 +79,7 @@ export async function getDocByName(name: DocName) {
|
|||||||
async function initDoc(name: DocName) {
|
async function initDoc(name: DocName) {
|
||||||
const snapshot = (await loaders[name]()) as DocSnapshot;
|
const snapshot = (await loaders[name]()) as DocSnapshot;
|
||||||
const collection = await getCollection();
|
const collection = await getCollection();
|
||||||
const job = new Job({
|
const transformer = new Transformer({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
blobCRUD: collection.blobSync,
|
blobCRUD: collection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
@@ -90,5 +90,5 @@ async function initDoc(name: DocName) {
|
|||||||
middlewares: [],
|
middlewares: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
return await job.snapshotToDoc(snapshot);
|
return await transformer.snapshotToDoc(snapshot);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import { Container } from '@blocksuite/affine/global/di';
|
|||||||
import {
|
import {
|
||||||
createYProxy,
|
createYProxy,
|
||||||
type DraftModel,
|
type DraftModel,
|
||||||
Job,
|
Transformer,
|
||||||
type JobMiddleware,
|
type TransformerMiddleware,
|
||||||
type YBlock,
|
type YBlock,
|
||||||
} from '@blocksuite/affine/store';
|
} from '@blocksuite/affine/store';
|
||||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
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');
|
const pages = yRootDoc.getMap('meta').get('pages');
|
||||||
if (!(pages instanceof YArray)) {
|
if (!(pages instanceof YArray)) {
|
||||||
return;
|
return;
|
||||||
@@ -176,7 +176,9 @@ function generateMarkdownPreviewBuilder(
|
|||||||
return `${baseUrl}/${docId}?${searchParams.toString()}`;
|
return `${baseUrl}/${docId}?${searchParams.toString()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const docLinkBaseURLMiddleware: JobMiddleware = ({ adapterConfigs }) => {
|
const docLinkBaseURLMiddleware: TransformerMiddleware = ({
|
||||||
|
adapterConfigs,
|
||||||
|
}) => {
|
||||||
adapterConfigs.set('docLinkBaseUrl', baseUrl);
|
adapterConfigs.set('docLinkBaseUrl', baseUrl);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -191,7 +193,7 @@ function generateMarkdownPreviewBuilder(
|
|||||||
|
|
||||||
const provider = container.provider();
|
const provider = container.provider();
|
||||||
const markdownAdapter = new MarkdownAdapter(
|
const markdownAdapter = new MarkdownAdapter(
|
||||||
new Job({
|
new Transformer({
|
||||||
schema: markdownPreviewDocCollection.schema,
|
schema: markdownPreviewDocCollection.schema,
|
||||||
blobCRUD: markdownPreviewDocCollection.blobSync,
|
blobCRUD: markdownPreviewDocCollection.blobSync,
|
||||||
docCRUD: {
|
docCRUD: {
|
||||||
|
|||||||
Reference in New Issue
Block a user