Skip to content

Commit

Permalink
fix(editor): transform to draftmodel first when get snapshot (#10477)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Feb 27, 2025
1 parent 1fd3d61 commit d57ef5c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions blocksuite/framework/store/src/transformer/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BlockModel } from '../model/block/block-model';
import type { DraftModel } from '../model/block/draft';
import { BlockModel } from '../model/block/block-model';
import { type DraftModel, toDraftModel } from '../model/block/draft';
import {
type InternalPrimitives,
internalPrimitives,
Expand All @@ -20,7 +20,7 @@ export type FromSnapshotPayload = {
};

export type ToSnapshotPayload<Props extends object> = {
model: DraftModel<BlockModel<Props>>;
model: DraftModel<BlockModel<Props>> | BlockModel<Props>;
assets: AssetsManager;
};

Expand All @@ -42,10 +42,16 @@ export class BaseBlockTransformer<Props extends object = object> {
) as Props;
}

protected _propsToSnapshot(model: DraftModel) {
protected _propsToSnapshot(model: DraftModel | BlockModel) {
let draftModel: DraftModel;
if (model instanceof BlockModel) {
draftModel = toDraftModel(model);
} else {
draftModel = model;
}
return Object.fromEntries(
model.keys.map(key => {
const value = model[key as keyof typeof model];
draftModel.keys.map(key => {
const value = draftModel[key as keyof typeof draftModel];
return [key, toJSON(value)];
})
);
Expand Down

0 comments on commit d57ef5c

Please sign in to comment.