refactor(editor): job should not rely on doc collection directly (#9488)
This commit is contained in:
@@ -27,7 +27,7 @@ export const embedSyncedDocBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher = {
|
||||
|
||||
if (type === 'content') {
|
||||
const syncedDocId = o.node.props.pageId as string;
|
||||
const syncedDoc = job.collection.getDoc(syncedDocId);
|
||||
const syncedDoc = job.docCRUD.get(syncedDocId);
|
||||
walkerContext.setGlobalContext('hast:html-root-doc', false);
|
||||
if (!syncedDoc) return;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export const embedSyncedDocBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatc
|
||||
|
||||
if (type === 'content') {
|
||||
const syncedDocId = o.node.props.pageId as string;
|
||||
const syncedDoc = job.collection.getDoc(syncedDocId);
|
||||
const syncedDoc = job.docCRUD.get(syncedDocId);
|
||||
if (!syncedDoc) return;
|
||||
|
||||
if (counter === 1) {
|
||||
|
||||
@@ -31,7 +31,7 @@ export const embedSyncedDocBlockPlainTextAdapterMatcher: BlockPlainTextAdapterMa
|
||||
|
||||
if (type === 'content') {
|
||||
const syncedDocId = o.node.props.pageId as string;
|
||||
const syncedDoc = job.collection.getDoc(syncedDocId);
|
||||
const syncedDoc = job.docCRUD.get(syncedDocId);
|
||||
if (!syncedDoc) return;
|
||||
|
||||
if (counter === 1) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
StdIdentifier,
|
||||
} from '@blocksuite/block-std';
|
||||
import { type Container, createIdentifier } from '@blocksuite/global/di';
|
||||
import { Job, Slice, type SliceSnapshot } from '@blocksuite/store';
|
||||
import { Slice, type SliceSnapshot } from '@blocksuite/store';
|
||||
|
||||
export const DndApiExtensionIdentifier = createIdentifier<DNDAPIExtension>(
|
||||
'AffineDndApiIdentifier'
|
||||
@@ -40,7 +40,7 @@ export class DNDAPIExtension extends Extension {
|
||||
const { docId, flavour = 'affine:embed-linked-doc', blockId } = options;
|
||||
|
||||
const slice = Slice.fromModels(this.std.doc, []);
|
||||
const job = new Job({ collection: this.std.collection });
|
||||
const job = this.std.getJob();
|
||||
const snapshot = job.sliceToSnapshot(slice);
|
||||
if (!snapshot) {
|
||||
console.error('Failed to convert slice to snapshot');
|
||||
|
||||
@@ -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