mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(editor): transform to draftmodel first when get snapshot (#10477)
This commit is contained in:
@@ -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,
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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)];
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user