mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 02:13:00 +08:00
refactor(editor): improve page viewport implementation (#11090)
This commit is contained in:
@@ -12,7 +12,6 @@ import {
|
|||||||
PageViewportService,
|
PageViewportService,
|
||||||
ViewportElementProvider,
|
ViewportElementProvider,
|
||||||
} from '@blocksuite/affine-shared/services';
|
} from '@blocksuite/affine-shared/services';
|
||||||
import type { Viewport } from '@blocksuite/affine-shared/types';
|
|
||||||
import {
|
import {
|
||||||
focusTitle,
|
focusTitle,
|
||||||
getClosestBlockComponentByPoint,
|
getClosestBlockComponentByPoint,
|
||||||
@@ -158,33 +157,16 @@ export class PageRootBlockComponent extends BlockComponent<
|
|||||||
return getScrollContainer(this);
|
return getScrollContainer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
get viewport(): Viewport | null {
|
get viewportProvider() {
|
||||||
if (!this.viewportElement) {
|
return this.std.get(ViewportElementProvider);
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
const {
|
get viewport() {
|
||||||
scrollLeft,
|
return this.viewportProvider.viewport;
|
||||||
scrollTop,
|
|
||||||
scrollWidth,
|
|
||||||
scrollHeight,
|
|
||||||
clientWidth,
|
|
||||||
clientHeight,
|
|
||||||
} = this.viewportElement;
|
|
||||||
const { top, left } = this.viewportElement.getBoundingClientRect();
|
|
||||||
return {
|
|
||||||
top,
|
|
||||||
left,
|
|
||||||
scrollLeft,
|
|
||||||
scrollTop,
|
|
||||||
scrollWidth,
|
|
||||||
scrollHeight,
|
|
||||||
clientWidth,
|
|
||||||
clientHeight,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get viewportElement(): HTMLElement {
|
get viewportElement(): HTMLElement {
|
||||||
return this.std.get(ViewportElementProvider).viewportElement;
|
return this.viewportProvider.viewportElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createDefaultNoteBlock() {
|
private _createDefaultNoteBlock() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { NoteBlockModel, RootBlockModel } from '@blocksuite/affine-model';
|
import { NoteBlockModel, RootBlockModel } from '@blocksuite/affine-model';
|
||||||
|
import { ViewportElementProvider } from '@blocksuite/affine-shared/services';
|
||||||
import {
|
import {
|
||||||
autoScroll,
|
autoScroll,
|
||||||
getScrollContainer,
|
getScrollContainer,
|
||||||
@@ -15,8 +16,6 @@ import { html, nothing } from 'lit';
|
|||||||
import { state } from 'lit/decorators.js';
|
import { state } from 'lit/decorators.js';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
import type { PageRootBlockComponent } from '../../index.js';
|
|
||||||
|
|
||||||
type Rect = {
|
type Rect = {
|
||||||
left: number;
|
left: number;
|
||||||
top: number;
|
top: number;
|
||||||
@@ -32,10 +31,7 @@ type BlockInfo = {
|
|||||||
export const AFFINE_PAGE_DRAGGING_AREA_WIDGET =
|
export const AFFINE_PAGE_DRAGGING_AREA_WIDGET =
|
||||||
'affine-page-dragging-area-widget';
|
'affine-page-dragging-area-widget';
|
||||||
|
|
||||||
export class AffinePageDraggingAreaWidget extends WidgetComponent<
|
export class AffinePageDraggingAreaWidget extends WidgetComponent<RootBlockModel> {
|
||||||
RootBlockModel,
|
|
||||||
PageRootBlockComponent
|
|
||||||
> {
|
|
||||||
static excludeFlavours: string[] = ['affine:note', 'affine:surface'];
|
static excludeFlavours: string[] = ['affine:note', 'affine:surface'];
|
||||||
|
|
||||||
private _dragging = false;
|
private _dragging = false;
|
||||||
@@ -167,9 +163,7 @@ export class AffinePageDraggingAreaWidget extends WidgetComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get _viewport() {
|
private get _viewport() {
|
||||||
const rootComponent = this.block;
|
return this.std.get(ViewportElementProvider).viewport;
|
||||||
if (!rootComponent) return;
|
|
||||||
return rootComponent.viewport;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private get scrollContainer() {
|
private get scrollContainer() {
|
||||||
|
|||||||
@@ -5,14 +5,9 @@ import { state } from 'lit/decorators.js';
|
|||||||
import { classMap } from 'lit/directives/class-map.js';
|
import { classMap } from 'lit/directives/class-map.js';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
import type { PageRootBlockComponent } from '../../index.js';
|
|
||||||
|
|
||||||
export const AFFINE_VIEWPORT_OVERLAY_WIDGET = 'affine-viewport-overlay-widget';
|
export const AFFINE_VIEWPORT_OVERLAY_WIDGET = 'affine-viewport-overlay-widget';
|
||||||
|
|
||||||
export class AffineViewportOverlayWidget extends WidgetComponent<
|
export class AffineViewportOverlayWidget extends WidgetComponent<RootBlockModel> {
|
||||||
RootBlockModel,
|
|
||||||
PageRootBlockComponent
|
|
||||||
> {
|
|
||||||
static override styles = css`
|
static override styles = css`
|
||||||
.affine-viewport-overlay-widget {
|
.affine-viewport-overlay-widget {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
Reference in New Issue
Block a user