mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
refactor(editor): remove redundant getOptional for gfx (#10142)
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
|||||||
TextSelection,
|
TextSelection,
|
||||||
WidgetComponent,
|
WidgetComponent,
|
||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import { GfxController } from '@blocksuite/block-std/gfx';
|
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||||
import { throttle } from '@blocksuite/global/utils';
|
import { throttle } from '@blocksuite/global/utils';
|
||||||
import type { BaseSelection, UserInfo } from '@blocksuite/store';
|
import type { BaseSelection, UserInfo } from '@blocksuite/store';
|
||||||
import { computed, effect } from '@preact/signals-core';
|
import { computed, effect } from '@preact/signals-core';
|
||||||
@@ -308,8 +308,7 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const gfx = this.std.getOptional(GfxController);
|
const gfx = this.std.get(GfxControllerIdentifier);
|
||||||
if (!gfx) return;
|
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
gfx.viewport.viewportUpdated.on(() => {
|
gfx.viewport.viewportUpdated.on(() => {
|
||||||
const selections = this._remoteSelections.peek();
|
const selections = this._remoteSelections.peek();
|
||||||
|
|||||||
@@ -68,9 +68,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
|
|||||||
);
|
);
|
||||||
|
|
||||||
#getBoundsInEdgeless() {
|
#getBoundsInEdgeless() {
|
||||||
const controller = this.std.getOptional(GfxControllerIdentifier);
|
const controller = this.std.get(GfxControllerIdentifier);
|
||||||
if (!controller) return;
|
|
||||||
|
|
||||||
const bounds = this.anchorBounds$.peek();
|
const bounds = this.anchorBounds$.peek();
|
||||||
if (!bounds) return;
|
if (!bounds) return;
|
||||||
|
|
||||||
@@ -96,9 +94,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#moveToAnchorInEdgeless(id: string) {
|
#moveToAnchorInEdgeless(id: string) {
|
||||||
const controller = this.std.getOptional(GfxControllerIdentifier);
|
const controller = this.std.get(GfxControllerIdentifier);
|
||||||
if (!controller) return;
|
|
||||||
|
|
||||||
const surface = controller.surface;
|
const surface = controller.surface;
|
||||||
if (!surface) return;
|
if (!surface) return;
|
||||||
|
|
||||||
@@ -194,12 +190,10 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// In edgeless
|
// In edgeless
|
||||||
const controler = this.std.getOptional(GfxControllerIdentifier);
|
const controler = this.std.get(GfxControllerIdentifier);
|
||||||
if (controler) {
|
this.disposables.add(
|
||||||
this.disposables.add(
|
controler.viewport.viewportUpdated.on(this.#requestUpdateFn)
|
||||||
controler.viewport.viewportUpdated.on(this.#requestUpdateFn)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
this.anchor$.subscribe(anchor => {
|
this.anchor$.subscribe(anchor => {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
|||||||
import { getViewportElement } from '@blocksuite/affine-shared/utils';
|
import { getViewportElement } from '@blocksuite/affine-shared/utils';
|
||||||
import type { BlockComponent } from '@blocksuite/block-std';
|
import type { BlockComponent } from '@blocksuite/block-std';
|
||||||
import { BLOCK_ID_ATTR, WidgetComponent } from '@blocksuite/block-std';
|
import { BLOCK_ID_ATTR, WidgetComponent } from '@blocksuite/block-std';
|
||||||
import { GfxController } from '@blocksuite/block-std/gfx';
|
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||||
import { IS_MOBILE } from '@blocksuite/global/env';
|
import { IS_MOBILE } from '@blocksuite/global/env';
|
||||||
import {
|
import {
|
||||||
INLINE_ROOT_ATTR,
|
INLINE_ROOT_ATTR,
|
||||||
@@ -197,8 +197,7 @@ export class AffineLinkedDocWidget extends WidgetComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _watchViewportChange() {
|
private _watchViewportChange() {
|
||||||
const gfx = this.std.getOptional(GfxController);
|
const gfx = this.std.get(GfxControllerIdentifier);
|
||||||
if (!gfx) return;
|
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
gfx.viewport.viewportUpdated.on(() => {
|
gfx.viewport.viewportUpdated.on(() => {
|
||||||
this._updateInputRects();
|
this._updateInputRects();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
getViewportElement,
|
getViewportElement,
|
||||||
} from '@blocksuite/affine-shared/utils';
|
} from '@blocksuite/affine-shared/utils';
|
||||||
import { PropTypes, requiredProperties } from '@blocksuite/block-std';
|
import { PropTypes, requiredProperties } from '@blocksuite/block-std';
|
||||||
import { GfxController } from '@blocksuite/block-std/gfx';
|
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||||
import {
|
import {
|
||||||
SignalWatcher,
|
SignalWatcher,
|
||||||
throttle,
|
throttle,
|
||||||
@@ -341,10 +341,8 @@ export class LinkedDocPopover extends SignalWatcher(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const gfx = this.context.std.getOptional(GfxController);
|
const gfx = this.context.std.get(GfxControllerIdentifier);
|
||||||
if (gfx) {
|
this.disposables.add(gfx.viewport.viewportUpdated.on(updatePosition));
|
||||||
this.disposables.add(gfx.viewport.viewportUpdated.on(updatePosition));
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePosition();
|
updatePosition();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user