refactor(editor): job should not rely on doc collection directly (#9488)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user