refactor(editor): refactor page note empty checker (#9570)

Close [BS-2320](https://linear.app/affine-design/issue/BS-2320/内容为空的状态判断)
This commit is contained in:
L-Sun
2025-01-07 11:24:40 +00:00
parent 482b534a90
commit 440239809c
11 changed files with 187 additions and 18 deletions
@@ -22,6 +22,22 @@ export class RootBlockModel extends BlockModel<RootBlockProps> {
});
});
}
/**
* A page is empty if it only contains one empty note and the canvas is empty
*/
override isEmpty() {
let numNotes = 0;
let empty = true;
for (const child of this.children) {
empty = empty && child.isEmpty();
if (child.flavour === 'affine:note') numNotes++;
if (numNotes > 1) return false;
}
return empty;
}
}
export const RootBlockSchema = defineBlockSchema({