mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
chore: fix eslint in blocksuite (#9232)
This commit is contained in:
@@ -4,7 +4,7 @@ import { ClipboardEventState } from '../state/clipboard.js';
|
||||
import { EventScopeSourceType, EventSourceState } from '../state/source.js';
|
||||
|
||||
export class ClipboardControl {
|
||||
private _copy = (event: ClipboardEvent) => {
|
||||
private readonly _copy = (event: ClipboardEvent) => {
|
||||
const clipboardEventState = new ClipboardEventState({
|
||||
event,
|
||||
});
|
||||
@@ -14,7 +14,7 @@ export class ClipboardControl {
|
||||
);
|
||||
};
|
||||
|
||||
private _cut = (event: ClipboardEvent) => {
|
||||
private readonly _cut = (event: ClipboardEvent) => {
|
||||
const clipboardEventState = new ClipboardEventState({
|
||||
event,
|
||||
});
|
||||
@@ -24,7 +24,7 @@ export class ClipboardControl {
|
||||
);
|
||||
};
|
||||
|
||||
private _paste = (event: ClipboardEvent) => {
|
||||
private readonly _paste = (event: ClipboardEvent) => {
|
||||
const clipboardEventState = new ClipboardEventState({
|
||||
event,
|
||||
});
|
||||
@@ -35,7 +35,7 @@ export class ClipboardControl {
|
||||
);
|
||||
};
|
||||
|
||||
constructor(private _dispatcher: UIEventDispatcher) {}
|
||||
constructor(private readonly _dispatcher: UIEventDispatcher) {}
|
||||
|
||||
private _createContext(event: Event, clipboardState: ClipboardEventState) {
|
||||
return UIEventStateContext.from(
|
||||
|
||||
@@ -11,7 +11,7 @@ import { KeyboardEventState } from '../state/index.js';
|
||||
import { EventScopeSourceType, EventSourceState } from '../state/source.js';
|
||||
|
||||
export class KeyboardControl {
|
||||
private _down = (event: KeyboardEvent) => {
|
||||
private readonly _down = (event: KeyboardEvent) => {
|
||||
if (!this._shouldTrigger(event)) {
|
||||
return;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ export class KeyboardControl {
|
||||
);
|
||||
};
|
||||
|
||||
private _shouldTrigger = (event: KeyboardEvent) => {
|
||||
private readonly _shouldTrigger = (event: KeyboardEvent) => {
|
||||
if (event.isComposing) {
|
||||
return false;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ export class KeyboardControl {
|
||||
return true;
|
||||
};
|
||||
|
||||
private _up = (event: KeyboardEvent) => {
|
||||
private readonly _up = (event: KeyboardEvent) => {
|
||||
if (!this._shouldTrigger(event)) {
|
||||
return;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export class KeyboardControl {
|
||||
|
||||
private composition = false;
|
||||
|
||||
constructor(private _dispatcher: UIEventDispatcher) {}
|
||||
constructor(private readonly _dispatcher: UIEventDispatcher) {}
|
||||
|
||||
private _createContext(event: Event, keyboardState: KeyboardEventState) {
|
||||
return UIEventStateContext.from(
|
||||
|
||||
@@ -39,7 +39,7 @@ abstract class PointerControllerBase {
|
||||
}
|
||||
|
||||
class PointerEventForward extends PointerControllerBase {
|
||||
private _down = (event: PointerEvent) => {
|
||||
private readonly _down = (event: PointerEvent) => {
|
||||
const { pointerId } = event;
|
||||
|
||||
const pointerState = new PointerEventState({
|
||||
@@ -54,9 +54,9 @@ class PointerEventForward extends PointerControllerBase {
|
||||
this._dispatcher.run('pointerDown', createContext(event, pointerState));
|
||||
};
|
||||
|
||||
private _lastStates = new Map<PointerId, PointerEventState>();
|
||||
private readonly _lastStates = new Map<PointerId, PointerEventState>();
|
||||
|
||||
private _move = (event: PointerEvent) => {
|
||||
private readonly _move = (event: PointerEvent) => {
|
||||
const { pointerId } = event;
|
||||
|
||||
const start = this._startStates.get(pointerId) ?? null;
|
||||
@@ -74,9 +74,9 @@ class PointerEventForward extends PointerControllerBase {
|
||||
this._dispatcher.run('pointerMove', createContext(event, state));
|
||||
};
|
||||
|
||||
private _startStates = new Map<PointerId, PointerEventState>();
|
||||
private readonly _startStates = new Map<PointerId, PointerEventState>();
|
||||
|
||||
private _upOrOut = (up: boolean) => (event: PointerEvent) => {
|
||||
private readonly _upOrOut = (up: boolean) => (event: PointerEvent) => {
|
||||
const { pointerId } = event;
|
||||
|
||||
const start = this._startStates.get(pointerId) ?? null;
|
||||
@@ -109,7 +109,7 @@ class PointerEventForward extends PointerControllerBase {
|
||||
}
|
||||
|
||||
class ClickController extends PointerControllerBase {
|
||||
private _down = (event: PointerEvent) => {
|
||||
private readonly _down = (event: PointerEvent) => {
|
||||
// disable for secondary pointer
|
||||
if (event.isPrimary === false) return;
|
||||
|
||||
@@ -137,7 +137,7 @@ class ClickController extends PointerControllerBase {
|
||||
|
||||
private _pointerDownCount = 0;
|
||||
|
||||
private _up = (event: PointerEvent) => {
|
||||
private readonly _up = (event: PointerEvent) => {
|
||||
if (!this._downPointerState) return;
|
||||
|
||||
if (isFarEnough(this._downPointerState.raw, event)) {
|
||||
@@ -177,7 +177,7 @@ class ClickController extends PointerControllerBase {
|
||||
}
|
||||
|
||||
class DragController extends PointerControllerBase {
|
||||
private _down = (event: PointerEvent) => {
|
||||
private readonly _down = (event: PointerEvent) => {
|
||||
if (this._nativeDragging) return;
|
||||
|
||||
if (!event.isPrimary) {
|
||||
@@ -209,7 +209,7 @@ class DragController extends PointerControllerBase {
|
||||
|
||||
private _lastPointerState: PointerEventState | null = null;
|
||||
|
||||
private _move = (event: PointerEvent) => {
|
||||
private readonly _move = (event: PointerEvent) => {
|
||||
if (
|
||||
this._startPointerState === null ||
|
||||
this._startPointerState.raw.pointerId !== event.pointerId
|
||||
@@ -243,7 +243,7 @@ class DragController extends PointerControllerBase {
|
||||
}
|
||||
};
|
||||
|
||||
private _nativeDragEnd = (event: DragEvent) => {
|
||||
private readonly _nativeDragEnd = (event: DragEvent) => {
|
||||
this._nativeDragging = false;
|
||||
const dndEventState = new DndEventState({ event });
|
||||
this._dispatcher.run(
|
||||
@@ -254,7 +254,7 @@ class DragController extends PointerControllerBase {
|
||||
|
||||
private _nativeDragging = false;
|
||||
|
||||
private _nativeDragMove = (event: DragEvent) => {
|
||||
private readonly _nativeDragMove = (event: DragEvent) => {
|
||||
const dndEventState = new DndEventState({ event });
|
||||
this._dispatcher.run(
|
||||
'nativeDragMove',
|
||||
@@ -262,7 +262,7 @@ class DragController extends PointerControllerBase {
|
||||
);
|
||||
};
|
||||
|
||||
private _nativeDragStart = (event: DragEvent) => {
|
||||
private readonly _nativeDragStart = (event: DragEvent) => {
|
||||
this._reset();
|
||||
this._nativeDragging = true;
|
||||
const dndEventState = new DndEventState({ event });
|
||||
@@ -272,7 +272,7 @@ class DragController extends PointerControllerBase {
|
||||
);
|
||||
};
|
||||
|
||||
private _nativeDrop = (event: DragEvent) => {
|
||||
private readonly _nativeDrop = (event: DragEvent) => {
|
||||
this._reset();
|
||||
this._nativeDragging = false;
|
||||
const dndEventState = new DndEventState({ event });
|
||||
@@ -282,7 +282,7 @@ class DragController extends PointerControllerBase {
|
||||
);
|
||||
};
|
||||
|
||||
private _reset = () => {
|
||||
private readonly _reset = () => {
|
||||
this._dragging = false;
|
||||
this._startPointerState = null;
|
||||
this._lastPointerState = null;
|
||||
@@ -293,7 +293,7 @@ class DragController extends PointerControllerBase {
|
||||
|
||||
private _startPointerState: PointerEventState | null = null;
|
||||
|
||||
private _up = (event: PointerEvent) => {
|
||||
private readonly _up = (event: PointerEvent) => {
|
||||
if (
|
||||
!this._startPointerState ||
|
||||
this._startPointerState.raw.pointerId !== event.pointerId
|
||||
@@ -358,7 +358,7 @@ class DragController extends PointerControllerBase {
|
||||
}
|
||||
|
||||
abstract class DualDragControllerBase extends PointerControllerBase {
|
||||
private _down = (event: PointerEvent) => {
|
||||
private readonly _down = (event: PointerEvent) => {
|
||||
// Another pointer down
|
||||
if (
|
||||
this._startPointerStates.primary !== null &&
|
||||
@@ -394,7 +394,7 @@ abstract class DualDragControllerBase extends PointerControllerBase {
|
||||
secondary: null,
|
||||
};
|
||||
|
||||
private _move = (event: PointerEvent) => {
|
||||
private readonly _move = (event: PointerEvent) => {
|
||||
if (
|
||||
this._startPointerStates.primary === null ||
|
||||
this._startPointerStates.secondary === null
|
||||
@@ -440,7 +440,7 @@ abstract class DualDragControllerBase extends PointerControllerBase {
|
||||
};
|
||||
};
|
||||
|
||||
private _reset = () => {
|
||||
private readonly _reset = () => {
|
||||
this._startPointerStates = {
|
||||
primary: null,
|
||||
secondary: null,
|
||||
@@ -459,7 +459,7 @@ abstract class DualDragControllerBase extends PointerControllerBase {
|
||||
secondary: null,
|
||||
};
|
||||
|
||||
private _upOrOut = (event: PointerEvent) => {
|
||||
private readonly _upOrOut = (event: PointerEvent) => {
|
||||
const { pointerId } = event;
|
||||
if (
|
||||
pointerId === this._startPointerStates.primary?.raw.pointerId ||
|
||||
@@ -542,7 +542,7 @@ class PanController extends DualDragControllerBase {
|
||||
export class PointerControl {
|
||||
private _cachedRect: DOMRect | null = null;
|
||||
|
||||
private _getRect = () => {
|
||||
private readonly _getRect = () => {
|
||||
if (this._cachedRect === null) {
|
||||
this._updateRect();
|
||||
}
|
||||
@@ -553,9 +553,9 @@ export class PointerControl {
|
||||
// due to potential performance issues
|
||||
private _pollingInterval: number | null = null;
|
||||
|
||||
private controllers: PointerControllerBase[];
|
||||
private readonly controllers: PointerControllerBase[];
|
||||
|
||||
constructor(private _dispatcher: UIEventDispatcher) {
|
||||
constructor(private readonly _dispatcher: UIEventDispatcher) {
|
||||
this.controllers = [
|
||||
new PointerEventForward(_dispatcher, this._getRect),
|
||||
new ClickController(_dispatcher, this._getRect),
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
import { EventScopeSourceType, EventSourceState } from '../state/source.js';
|
||||
|
||||
export class RangeControl {
|
||||
private _buildScope = (eventName: EventName) => {
|
||||
private readonly _buildScope = (eventName: EventName) => {
|
||||
let scope: EventHandlerRunner[] | undefined;
|
||||
const selection = document.getSelection();
|
||||
if (selection && selection.rangeCount > 0) {
|
||||
@@ -23,19 +23,19 @@ export class RangeControl {
|
||||
return scope;
|
||||
};
|
||||
|
||||
private _compositionEnd = (event: Event) => {
|
||||
private readonly _compositionEnd = (event: Event) => {
|
||||
const scope = this._buildScope('compositionEnd');
|
||||
|
||||
this._dispatcher.run('compositionEnd', this._createContext(event), scope);
|
||||
};
|
||||
|
||||
private _compositionStart = (event: Event) => {
|
||||
private readonly _compositionStart = (event: Event) => {
|
||||
const scope = this._buildScope('compositionStart');
|
||||
|
||||
this._dispatcher.run('compositionStart', this._createContext(event), scope);
|
||||
};
|
||||
|
||||
private _compositionUpdate = (event: Event) => {
|
||||
private readonly _compositionUpdate = (event: Event) => {
|
||||
const scope = this._buildScope('compositionUpdate');
|
||||
|
||||
this._dispatcher.run(
|
||||
@@ -47,7 +47,7 @@ export class RangeControl {
|
||||
|
||||
private _prev: Range | null = null;
|
||||
|
||||
private _selectionChange = (event: Event) => {
|
||||
private readonly _selectionChange = (event: Event) => {
|
||||
const selection = document.getSelection();
|
||||
if (!selection) return;
|
||||
|
||||
@@ -59,7 +59,7 @@ export class RangeControl {
|
||||
this._dispatcher.run('selectionChange', this._createContext(event), scope);
|
||||
};
|
||||
|
||||
constructor(private _dispatcher: UIEventDispatcher) {}
|
||||
constructor(private readonly _dispatcher: UIEventDispatcher) {}
|
||||
|
||||
private _buildEventScopeByNativeRange(name: EventName, range: Range) {
|
||||
const blockIds = this._findBlockComponentPath(range);
|
||||
|
||||
@@ -80,17 +80,17 @@ export class UIEventDispatcher extends LifeCycleWatcher {
|
||||
|
||||
private _active = false;
|
||||
|
||||
private _clipboardControl: ClipboardControl;
|
||||
private readonly _clipboardControl: ClipboardControl;
|
||||
|
||||
private _handlersMap = Object.fromEntries(
|
||||
eventNames.map((name): [EventName, Array<EventHandlerRunner>] => [name, []])
|
||||
) as Record<EventName, Array<EventHandlerRunner>>;
|
||||
|
||||
private _keyboardControl: KeyboardControl;
|
||||
private readonly _keyboardControl: KeyboardControl;
|
||||
|
||||
private _pointerControl: PointerControl;
|
||||
private readonly _pointerControl: PointerControl;
|
||||
|
||||
private _rangeControl: RangeControl;
|
||||
private readonly _rangeControl: RangeControl;
|
||||
|
||||
bindHotkey = (...args: Parameters<KeyboardControl['bindHotkey']>) =>
|
||||
this._keyboardControl.bindHotkey(...args);
|
||||
|
||||
Reference in New Issue
Block a user