fix(editor): block can be null in widget (#10959)
Closes: [BS-2826](https://linear.app/affine-design/issue/BS-2826/typeerror-thisblock-is-null)
This commit is contained in:
@@ -161,6 +161,8 @@ export class PointerEventWatcher {
|
||||
if (this.widget.isGfxDragHandleVisible) return;
|
||||
|
||||
const point = new Point(state.raw.x, state.raw.y);
|
||||
if (!this.widget.rootComponent) return;
|
||||
|
||||
const closestBlock = getClosestBlockByPoint(
|
||||
this.widget.host,
|
||||
this.widget.rootComponent,
|
||||
@@ -246,6 +248,8 @@ export class PointerEventWatcher {
|
||||
// When pointer on drag handle, should do nothing
|
||||
if (element.closest('.affine-drag-handle-container')) return;
|
||||
|
||||
if (!this.widget.rootComponent) return;
|
||||
|
||||
// When pointer out of note block hover area or inside database, should hide drag handle
|
||||
const point = new Point(state.raw.x, state.raw.y);
|
||||
|
||||
|
||||
@@ -284,6 +284,9 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
|
||||
}
|
||||
|
||||
private _initLabels() {
|
||||
if (!this.block) {
|
||||
return;
|
||||
}
|
||||
const { service } = this.block;
|
||||
const surfaceRefs = service.doc
|
||||
.getBlocksByFlavour('affine:surface-ref')
|
||||
|
||||
@@ -144,6 +144,10 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {
|
||||
}
|
||||
|
||||
private _getCursorRect(selections: BaseSelection[]): SelectionRect | null {
|
||||
if (!this.block) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.block.model.flavour !== 'affine:page') {
|
||||
console.error('remote selection widget must be used in page component');
|
||||
return null;
|
||||
@@ -208,6 +212,10 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {
|
||||
private readonly _getSelectionRect = (
|
||||
selections: BaseSelection[]
|
||||
): SelectionRect[] => {
|
||||
if (!this.block) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (this.block.model.flavour !== 'affine:page') {
|
||||
console.error('remote selection widget must be used in page component');
|
||||
return [];
|
||||
|
||||
@@ -105,7 +105,7 @@ export class AffineSlashMenuWidget extends WidgetComponent {
|
||||
}
|
||||
};
|
||||
|
||||
if (this.block.model.flavour !== 'affine:page') {
|
||||
if (this.block?.model.flavour !== 'affine:page') {
|
||||
console.error('SlashMenuWidget should be used in RootBlock');
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user