refactor(editor): job should not rely on doc collection directly (#9488)

This commit is contained in:
Saul-Mirone
2025-01-02 10:50:15 +00:00
parent f2906bc6d0
commit edb5e1d87a
34 changed files with 565 additions and 337 deletions

View File

@@ -3,14 +3,14 @@ import type { JobMiddleware } from '@blocksuite/store';
export const newIdCrossDoc =
(std: BlockStdScope): JobMiddleware =>
({ slots, collection }) => {
({ slots }) => {
let samePage = false;
slots.beforeImport.on(payload => {
if (payload.type === 'slice') {
samePage = payload.snapshot.pageId === std.doc.id;
}
if (payload.type === 'block' && !samePage) {
payload.snapshot.id = collection.idGenerator();
payload.snapshot.id = std.collection.idGenerator();
}
});
};

View File

@@ -3,7 +3,7 @@ import type { JobMiddleware } from '@blocksuite/store';
export const surfaceRefToEmbed =
(std: BlockStdScope): JobMiddleware =>
({ slots, collection }) => {
({ slots }) => {
let pageId: string | null = null;
slots.beforeImport.on(payload => {
if (payload.type === 'slice') {
@@ -18,7 +18,7 @@ export const surfaceRefToEmbed =
!std.doc.hasBlock(payload.snapshot.id)
) {
const id = payload.snapshot.id;
payload.snapshot.id = collection.idGenerator();
payload.snapshot.id = std.collection.idGenerator();
payload.snapshot.flavour = 'affine:embed-linked-doc';
payload.snapshot.props = {
blockId: id,

View File

@@ -30,7 +30,7 @@ import {
} from '@blocksuite/block-std';
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
import { Bound, Point } from '@blocksuite/global/utils';
import { Job, Slice, type SliceSnapshot } from '@blocksuite/store';
import { Slice, type SliceSnapshot } from '@blocksuite/store';
import { DropIndicator } from '../components/drop-indicator.js';
import { AFFINE_DRAG_HANDLE_WIDGET } from '../consts.js';
@@ -544,14 +544,11 @@ export class DragEventWatcher {
private _getJob() {
const std = this._std;
return new Job({
collection: std.collection,
middlewares: [
newIdCrossDoc(std),
reorderList(std),
surfaceRefToEmbed(std),
],
});
return std.getJob([
newIdCrossDoc(std),
reorderList(std),
surfaceRefToEmbed(std),
]);
}
private _serializeData(slice: Slice, state: DndEventState) {