feat(editor): unify block props api (#10888)

Closes: [BS-2707](https://linear.app/affine-design/issue/BS-2707/统一使用props获取和更新block-prop)
This commit is contained in:
Saul-Mirone
2025-03-16 05:48:34 +00:00
parent 8f9e5bf0aa
commit 26285f7dcb
193 changed files with 1019 additions and 891 deletions
@@ -25,7 +25,7 @@ const handlePoint = (
if (isRootDraftModel(model)) {
if (length === 0) return;
(snapshot.props.title as Record<string, unknown>).delta =
model.title.sliceToDelta(index, length + index);
model.props.title.sliceToDelta(index, length + index);
return;
}
@@ -485,7 +485,7 @@ class PasteTr {
if (this.firstSnapshot!.props.type) {
this.firstSnapshot!.props.type = (
this.pointState.model as ParagraphBlockModel
).type;
).props.type;
}
}
@@ -19,10 +19,10 @@ export const replaceIdMiddleware =
payload.snapshot.flavour === 'affine:database'
) {
const model = payload.model as DatabaseBlockModel;
Object.keys(model.cells).forEach(cellId => {
Object.keys(model.props.cells).forEach(cellId => {
if (idMap.has(cellId)) {
model.cells[idMap.get(cellId)!] = model.cells[cellId];
delete model.cells[cellId];
model.props.cells[idMap.get(cellId)!] = model.props.cells[cellId];
delete model.props.cells[cellId];
}
});
}
@@ -35,7 +35,7 @@ export const replaceIdMiddleware =
const model = payload.model as ParagraphBlockModel | ListBlockModel;
let prev = 0;
const delta: DeltaOperation[] = [];
for (const d of model.text.toDelta()) {
for (const d of model.props.text.toDelta()) {
if (d.attributes?.reference?.pageId) {
const newId = idMap.get(d.attributes.reference.pageId);
if (!newId) {
@@ -62,7 +62,7 @@ export const replaceIdMiddleware =
}
}
if (delta.length > 0) {
model.text.applyDelta(delta);
model.props.text.applyDelta(delta);
}
}
@@ -71,20 +71,20 @@ export const replaceIdMiddleware =
payload.snapshot.flavour === 'affine:surface-ref'
) {
const model = payload.model as SurfaceRefBlockModel;
const original = model.reference;
const original = model.props.reference;
// If there exists a replacement, replace the reference with the new id.
// Otherwise,
// 1. If the reference is an affine:frame not in doc, generate a new id.
// 2. If the reference is graph, keep the original id.
if (idMap.has(original)) {
model.reference = idMap.get(original)!;
model.props.reference = idMap.get(original)!;
} else if (
model.refFlavour === 'affine:frame' &&
model.props.refFlavour === 'affine:frame' &&
!model.doc.hasBlock(original)
) {
const newId = idGenerator();
idMap.set(original, newId);
model.reference = newId;
model.props.reference = newId;
}
}
@@ -98,16 +98,16 @@ export const replaceIdMiddleware =
const model = payload.model as
| EmbedLinkedDocModel
| EmbedSyncedDocModel;
const original = model.pageId;
const original = model.props.pageId;
// If the pageId is not in the doc, generate a new id.
// If we already have a replacement, use it.
if (!docCRUD.get(original)) {
if (idMap.has(original)) {
model.pageId = idMap.get(original)!;
model.props.pageId = idMap.get(original)!;
} else {
const newId = idGenerator();
idMap.set(original, newId);
model.pageId = newId;
model.props.pageId = newId;
}
}
}