mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
close: BS-2122, BS-2125, BS-2124, BS-2420, PD-2073, BS-2126, BS-2469, BS-2470, BS-2478, BS-2471
36 lines
980 B
TypeScript
36 lines
980 B
TypeScript
import type { BlockComponent } from '@blocksuite/block-std';
|
|
import { autoUpdate } from '@floating-ui/dom';
|
|
import { signal } from '@preact/signals-core';
|
|
import type { ReactiveController } from 'lit';
|
|
|
|
import { DocModeProvider } from '../services/doc-mode-service';
|
|
|
|
export class VirtualPaddingController implements ReactiveController {
|
|
public readonly virtualPadding$ = signal(0);
|
|
constructor(private readonly block: BlockComponent) {
|
|
block.addController(this);
|
|
}
|
|
|
|
get std() {
|
|
return this.host.std;
|
|
}
|
|
|
|
get host() {
|
|
return this.block.host;
|
|
}
|
|
|
|
hostConnected(): void {
|
|
if (this.std.get(DocModeProvider).getEditorMode() === 'edgeless') {
|
|
return;
|
|
}
|
|
this.block.disposables.add(
|
|
autoUpdate(this.host, this.block, () => {
|
|
const padding =
|
|
this.block.getBoundingClientRect().left -
|
|
this.host.getBoundingClientRect().left;
|
|
this.virtualPadding$.value = Math.max(0, padding - 72);
|
|
})
|
|
);
|
|
}
|
|
}
|