Skip to content

Commit

Permalink
fix: paste synced doc (#8355)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Sep 13, 2024
1 parent e81c4cc commit f87af5f
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions packages/blocks/src/_common/transformers/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,22 @@ export const replaceIdMiddleware: JobMiddleware = ({ slots, collection }) => {
// TODO(@fundon): process linked block/element
if (
payload.type === 'block' &&
payload.snapshot.flavour === 'affine:embed-linked-doc'
['affine:embed-linked-doc', 'affine:embed-synced-doc'].includes(
payload.snapshot.flavour
)
) {
const model = payload.model as EmbedLinkedDocModel;
const model = payload.model as EmbedLinkedDocModel | EmbedSyncedDocModel;
const original = model.pageId;
if (idMap.has(original)) {
model.pageId = idMap.get(original)!;
} else {
const newId = collection.idGenerator();
idMap.set(original, newId);
model.pageId = newId;
}
}

if (
payload.type === 'block' &&
payload.snapshot.flavour === 'affine:embed-synced-doc'
) {
const model = payload.model as EmbedSyncedDocModel;
const original = model.pageId;
if (idMap.has(original)) {
model.pageId = idMap.get(original)!;
} else {
const newId = collection.idGenerator();
idMap.set(original, newId);
model.pageId = newId;
// If the pageId is not in the doc, generate a new id.
// If we already have a replacement, use it.
if (!collection.getDoc(original)) {
if (idMap.has(original)) {
model.pageId = idMap.get(original)!;
} else {
const newId = collection.idGenerator();
idMap.set(original, newId);
model.pageId = newId;
}
}
}
});
Expand Down

0 comments on commit f87af5f

Please sign in to comment.