Compare commits

...

3 Commits

Author SHA1 Message Date
zzj3720
0ef01002b4 fix(editor): slice to snapshot supports flat data structures 2025-02-27 15:29:17 +08:00
Saul-Mirone
b7598ff177 chore: optimize code 2025-02-27 12:57:09 +08:00
zzj3720
b07eb5678d fix(editor): toDraftModal supports flat data structures 2025-02-27 12:39:20 +08:00
2 changed files with 13 additions and 3 deletions

View File

@@ -15,10 +15,14 @@ export function toDraftModel<Model extends BlockModel = BlockModel>(
origin: Model
): DraftModel<Model> {
const { id, version, flavour, role, keys, text, children } = origin;
const isFlatData = origin.schema.model.isFlatData;
const props = origin.keys.reduce((acc, key) => {
const target = isFlatData ? origin.props : origin;
const value = target[key as keyof typeof target];
return {
...acc,
[key]: origin[key as keyof Model],
[key]: value,
};
}, {} as ModelProps<Model>);

View File

@@ -1,4 +1,4 @@
import type { BlockModel } from '../model/block/block-model';
import { BlockModel } from '../model/block/block-model';
import type { DraftModel } from '../model/block/draft';
import {
type InternalPrimitives,
@@ -43,9 +43,15 @@ export class BaseBlockTransformer<Props extends object = object> {
}
protected _propsToSnapshot(model: DraftModel) {
const props =
model instanceof BlockModel
? model.schema.model.isFlatData
? model.props
: model
: model;
return Object.fromEntries(
model.keys.map(key => {
const value = model[key as keyof typeof model];
const value = props[key as keyof typeof model];
return [key, toJSON(value)];
})
);