mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 02:20:19 +08: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 { BlockModel } from '../model/block/block-model';
|
||||||
import type { DraftModel } from '../model/block/draft';
|
import { type DraftModel, toDraftModel } from '../model/block/draft';
|
||||||
import {
|
import {
|
||||||
type InternalPrimitives,
|
type InternalPrimitives,
|
||||||
internalPrimitives,
|
internalPrimitives,
|
||||||
@@ -20,7 +20,7 @@ export type FromSnapshotPayload = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type ToSnapshotPayload<Props extends object> = {
|
export type ToSnapshotPayload<Props extends object> = {
|
||||||
model: DraftModel<BlockModel<Props>>;
|
model: DraftModel<BlockModel<Props>> | BlockModel<Props>;
|
||||||
assets: AssetsManager;
|
assets: AssetsManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,10 +42,16 @@ export class BaseBlockTransformer<Props extends object = object> {
|
|||||||
) as Props;
|
) 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(
|
return Object.fromEntries(
|
||||||
model.keys.map(key => {
|
draftModel.keys.map(key => {
|
||||||
const value = model[key as keyof typeof model];
|
const value = draftModel[key as keyof typeof draftModel];
|
||||||
return [key, toJSON(value)];
|
return [key, toJSON(value)];
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user