mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 18:40:00 +08:00
refactor(editor): job should not rely on doc collection directly (#9488)
This commit is contained in:
@@ -59,8 +59,12 @@ export class PageClipboard {
|
||||
const paste = pasteMiddleware(this._std);
|
||||
this._std.clipboard.use(copy);
|
||||
this._std.clipboard.use(paste);
|
||||
this._std.clipboard.use(replaceIdMiddleware);
|
||||
this._std.clipboard.use(titleMiddleware);
|
||||
this._std.clipboard.use(
|
||||
replaceIdMiddleware(this._std.doc.collection.idGenerator)
|
||||
);
|
||||
this._std.clipboard.use(
|
||||
titleMiddleware(this._std.doc.collection.meta.docMetas)
|
||||
);
|
||||
this._std.clipboard.use(defaultImageProxyMiddleware);
|
||||
|
||||
this._disposables.add({
|
||||
@@ -80,8 +84,12 @@ export class PageClipboard {
|
||||
this._std.clipboard.unregisterAdapter('*/*');
|
||||
this._std.clipboard.unuse(copy);
|
||||
this._std.clipboard.unuse(paste);
|
||||
this._std.clipboard.unuse(replaceIdMiddleware);
|
||||
this._std.clipboard.unuse(titleMiddleware);
|
||||
this._std.clipboard.unuse(
|
||||
replaceIdMiddleware(this._std.doc.collection.idGenerator)
|
||||
);
|
||||
this._std.clipboard.unuse(
|
||||
titleMiddleware(this._std.doc.collection.meta.docMetas)
|
||||
);
|
||||
this._std.clipboard.unuse(defaultImageProxyMiddleware);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -369,7 +369,15 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
if (mayBeSurfaceDataJson !== undefined) {
|
||||
const elementsRawData = JSON.parse(mayBeSurfaceDataJson);
|
||||
const { snapshot, blobs } = elementsRawData;
|
||||
const job = new Job({ collection: this.std.collection });
|
||||
const job = new Job({
|
||||
schema: this.std.collection.schema,
|
||||
blobCRUD: this.std.collection.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => this.std.collection.createDoc({ id }),
|
||||
get: (id: string) => this.std.collection.getDoc(id),
|
||||
delete: (id: string) => this.std.collection.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const map = job.assetsManager.getAssets();
|
||||
decodeClipboardBlobs(blobs, map);
|
||||
for (const blobId of map.keys()) {
|
||||
@@ -1366,7 +1374,13 @@ export async function prepareClipboardData(
|
||||
std: BlockStdScope
|
||||
) {
|
||||
const job = new Job({
|
||||
collection: std.collection,
|
||||
schema: std.collection.schema,
|
||||
blobCRUD: std.collection.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => std.collection.createDoc({ id }),
|
||||
get: (id: string) => std.collection.getDoc(id),
|
||||
delete: (id: string) => std.collection.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const selected = await Promise.all(
|
||||
selectedAll.map(async selected => {
|
||||
|
||||
@@ -87,7 +87,16 @@ export class TemplateJob {
|
||||
type: TemplateType;
|
||||
|
||||
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
||||
this.job = new Job({ collection: model.doc.collection, middlewares: [] });
|
||||
this.job = new Job({
|
||||
schema: model.doc.collection.schema,
|
||||
blobCRUD: model.doc.collection.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => model.doc.collection.createDoc({ id }),
|
||||
get: (id: string) => model.doc.collection.getDoc(id),
|
||||
delete: (id: string) => model.doc.collection.removeDoc(id),
|
||||
},
|
||||
middlewares: [],
|
||||
});
|
||||
this.model = model;
|
||||
this.type = TEMPLATE_TYPES.includes(type as TemplateType)
|
||||
? (type as TemplateType)
|
||||
|
||||
@@ -40,7 +40,13 @@ export function getSortedCloneElements(elements: GfxModel[]) {
|
||||
export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
||||
elements = sortEdgelessElements(elements);
|
||||
const job = new Job({
|
||||
collection: std.collection,
|
||||
schema: std.collection.schema,
|
||||
blobCRUD: std.collection.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => std.collection.createDoc({ id }),
|
||||
get: (id: string) => std.collection.getDoc(id),
|
||||
delete: (id: string) => std.collection.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const res = elements.map(element => {
|
||||
const data = serializeElement(element, elements, job);
|
||||
|
||||
Reference in New Issue
Block a user