diff --git a/blocksuite/affine/block-embed/src/embed-html-block/components/fullscreen-toolbar.ts b/blocksuite/affine/block-embed/src/embed-html-block/components/fullscreen-toolbar.ts index 5a64af26d50e4..7eda881411344 100644 --- a/blocksuite/affine/block-embed/src/embed-html-block/components/fullscreen-toolbar.ts +++ b/blocksuite/affine/block-embed/src/embed-html-block/components/fullscreen-toolbar.ts @@ -68,7 +68,7 @@ export class EmbedHtmlFullscreenToolbar extends LitElement { } `; - private _popSettings = () => { + private readonly _popSettings = () => { this._popperVisible = true; popMenu(popupTargetFromElement(this._fullScreenToolbarContainer), { options: { diff --git a/blocksuite/affine/block-embed/src/embed-linked-doc-block/embed-linked-doc-block.ts b/blocksuite/affine/block-embed/src/embed-linked-doc-block/embed-linked-doc-block.ts index 83fcf51cc24f4..4c830ff00d175 100644 --- a/blocksuite/affine/block-embed/src/embed-linked-doc-block/embed-linked-doc-block.ts +++ b/blocksuite/affine/block-embed/src/embed-linked-doc-block/embed-linked-doc-block.ts @@ -48,7 +48,7 @@ import { getEmbedLinkedDocIcons } from './utils.js'; export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent { static override styles = styles; - private _load = async () => { + private readonly _load = async () => { const { loading = true, isError = false, @@ -103,7 +103,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent { + private readonly _selectBlock = () => { const selectionManager = this.host.selection; const blockSelection = selectionManager.create('block', { blockId: this.blockId, @@ -111,7 +111,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent { + private readonly _setDocUpdatedAt = () => { const meta = this.doc.collection.meta.getDocMeta(this.model.pageId); if (meta) { const date = meta.updatedDate || meta.createDate; diff --git a/blocksuite/affine/block-embed/src/embed-synced-doc-block/embed-synced-doc-block.ts b/blocksuite/affine/block-embed/src/embed-synced-doc-block/embed-synced-doc-block.ts index cef87d17082f8..5335445076057 100644 --- a/blocksuite/affine/block-embed/src/embed-synced-doc-block/embed-synced-doc-block.ts +++ b/blocksuite/affine/block-embed/src/embed-synced-doc-block/embed-synced-doc-block.ts @@ -55,7 +55,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent { + private readonly _initEdgelessFitEffect = () => { const fitToContent = () => { if (this.isPageMode) return; @@ -99,7 +99,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent {}); }; - private _pageFilter: Query = { + private readonly _pageFilter: Query = { mode: 'loose', match: [ { diff --git a/blocksuite/affine/block-list/src/list-block.ts b/blocksuite/affine/block-list/src/list-block.ts index 880d101777669..22a076468bdfb 100644 --- a/blocksuite/affine/block-list/src/list-block.ts +++ b/blocksuite/affine/block-list/src/list-block.ts @@ -36,7 +36,7 @@ export class ListBlockComponent extends CaptionedBlockComponent< private _inlineRangeProvider: InlineRangeProvider | null = null; - private _onClickIcon = (e: MouseEvent) => { + private readonly _onClickIcon = (e: MouseEvent) => { e.stopPropagation(); if (this.model.type === 'toggle') { diff --git a/blocksuite/affine/block-paragraph/src/paragraph-block.ts b/blocksuite/affine/block-paragraph/src/paragraph-block.ts index b6151681de92d..169ca49b03ad4 100644 --- a/blocksuite/affine/block-paragraph/src/paragraph-block.ts +++ b/blocksuite/affine/block-paragraph/src/paragraph-block.ts @@ -34,13 +34,13 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent< > { static override styles = paragraphBlockStyles; - private _composing = signal(false); + private readonly _composing = signal(false); - private _displayPlaceholder = signal(false); + private readonly _displayPlaceholder = signal(false); private _inlineRangeProvider: InlineRangeProvider | null = null; - private _isInDatabase = () => { + private readonly _isInDatabase = () => { let parent = this.parentElement; while (parent && parent !== document.body) { if (parent.tagName.toLowerCase() === 'affine-database') { diff --git a/blocksuite/affine/block-surface/src/managers/connector-manager.ts b/blocksuite/affine/block-surface/src/managers/connector-manager.ts index 7cbfc3c0174f0..f9e4ddbaac0b5 100644 --- a/blocksuite/affine/block-surface/src/managers/connector-manager.ts +++ b/blocksuite/affine/block-surface/src/managers/connector-manager.ts @@ -1149,7 +1149,7 @@ export class PathGenerator { export class ConnectorPathGenerator extends PathGenerator { constructor( - private options: { + private readonly options: { getElementById: (id: string) => GfxModel | null; } ) { diff --git a/blocksuite/affine/block-surface/src/renderer/canvas-renderer.ts b/blocksuite/affine/block-surface/src/renderer/canvas-renderer.ts index 3c1e242e070d4..68578c1cf6361 100644 --- a/blocksuite/affine/block-surface/src/renderer/canvas-renderer.ts +++ b/blocksuite/affine/block-surface/src/renderer/canvas-renderer.ts @@ -42,9 +42,9 @@ type RendererOptions = { export class CanvasRenderer { private _container!: HTMLElement; - private _disposables = new DisposableGroup(); + private readonly _disposables = new DisposableGroup(); - private _overlays = new Set(); + private readonly _overlays = new Set(); private _refreshRafId: number | null = null; diff --git a/blocksuite/affine/block-surface/src/surface-block.ts b/blocksuite/affine/block-surface/src/surface-block.ts index f52975088a3fc..6b8558c4a2bee 100644 --- a/blocksuite/affine/block-surface/src/surface-block.ts +++ b/blocksuite/affine/block-surface/src/surface-block.ts @@ -100,7 +100,7 @@ export class SurfaceBlockComponent extends BlockComponent< private _cachedViewport = new Bound(); - private _initThemeObserver = () => { + private readonly _initThemeObserver = () => { const theme = this.std.get(ThemeProvider); this.disposables.add(theme.theme$.subscribe(() => this.requestUpdate())); }; diff --git a/blocksuite/affine/block-surface/src/surface-model.ts b/blocksuite/affine/block-surface/src/surface-model.ts index 30e99abff68d5..586999132490e 100644 --- a/blocksuite/affine/block-surface/src/surface-model.ts +++ b/blocksuite/affine/block-surface/src/surface-model.ts @@ -34,7 +34,7 @@ export const SurfaceBlockSchema = defineBlockSchema({ export type SurfaceMiddleware = (surface: SurfaceBlockModel) => () => void; export class SurfaceBlockModel extends BaseSurfaceModel { - private _disposables: DisposableGroup = new DisposableGroup(); + private readonly _disposables: DisposableGroup = new DisposableGroup(); override _init() { this._extendElement(elementsCtorMap); diff --git a/blocksuite/affine/block-surface/src/utils/a-star.ts b/blocksuite/affine/block-surface/src/utils/a-star.ts index bee00280d04c8..ce56976a3f9f9 100644 --- a/blocksuite/affine/block-surface/src/utils/a-star.ts +++ b/blocksuite/affine/block-surface/src/utils/a-star.ts @@ -33,24 +33,27 @@ function pointAlmostEqual(a: IVec3, b: IVec3): boolean { } export class AStarRunner { - private _cameFrom = new Map(); + private readonly _cameFrom = new Map< + IVec3, + { from: IVec3[]; indexs: number[] } + >(); private _complete = false; - private _costSoFar = new Map(); + private readonly _costSoFar = new Map(); private _current: IVec3 | null = null; - private _diagonalCount = new Map(); + private readonly _diagonalCount = new Map(); private _frontier!: PriorityQueue< IVec3, [diagonalCount: number, pointPriority: number, distCost: number] >; - private _graph: Graph; + private readonly _graph: Graph; - private _pointPriority = new Map(); + private readonly _pointPriority = new Map(); get path() { const result: IVec3[] = []; @@ -72,9 +75,9 @@ export class AStarRunner { constructor( points: IVec3[], - private _sp: IVec3, - private _ep: IVec3, - private _originalSp: IVec3, + private readonly _sp: IVec3, + private readonly _ep: IVec3, + private readonly _originalSp: IVec3, private _originalEp: IVec3, blocks: Bound[] = [], expandBlocks: Bound[] = [] diff --git a/blocksuite/affine/block-surface/src/utils/graph.ts b/blocksuite/affine/block-surface/src/utils/graph.ts index 1440f7879d489..3d57875960b37 100644 --- a/blocksuite/affine/block-surface/src/utils/graph.ts +++ b/blocksuite/affine/block-surface/src/utils/graph.ts @@ -27,15 +27,15 @@ function arrayAlmostEqual(point: IVec | IVec3, point2: IVec | IVec3) { } export class Graph { - private _xMap = new Map(); + private readonly _xMap = new Map(); - private _yMap = new Map(); + private readonly _yMap = new Map(); constructor( - private points: V[], - private blocks: Bound[] = [], - private expandedBlocks: Bound[] = [], - private excludedPoints: V[] = [] + private readonly points: V[], + private readonly blocks: Bound[] = [], + private readonly expandedBlocks: Bound[] = [], + private readonly excludedPoints: V[] = [] ) { const xMap = this._xMap; const yMap = this._yMap; diff --git a/blocksuite/affine/block-surface/src/utils/priority-queue.ts b/blocksuite/affine/block-surface/src/utils/priority-queue.ts index 842e709fdb78e..a5df2b5c034b2 100644 --- a/blocksuite/affine/block-surface/src/utils/priority-queue.ts +++ b/blocksuite/affine/block-surface/src/utils/priority-queue.ts @@ -6,7 +6,7 @@ type PriorityQueueNode = { export class PriorityQueue { heap: PriorityQueueNode[] = []; - constructor(private _compare: (a: K, b: K) => number) {} + constructor(private readonly _compare: (a: K, b: K) => number) {} bubbleDown(): void { let index = 0; diff --git a/blocksuite/affine/block-surface/src/utils/rough/canvas.ts b/blocksuite/affine/block-surface/src/utils/rough/canvas.ts index 0a23cb33a53b0..bc990a36bbfbc 100644 --- a/blocksuite/affine/block-surface/src/utils/rough/canvas.ts +++ b/blocksuite/affine/block-surface/src/utils/rough/canvas.ts @@ -9,11 +9,11 @@ import { RoughGenerator } from './generator.js'; import type { Point } from './geometry.js'; export class RoughCanvas { - private canvas: HTMLCanvasElement; + private readonly canvas: HTMLCanvasElement; - private ctx: CanvasRenderingContext2D; + private readonly ctx: CanvasRenderingContext2D; - private gen: RoughGenerator; + private readonly gen: RoughGenerator; get generator(): RoughGenerator { return this.gen; diff --git a/blocksuite/affine/block-surface/src/utils/rough/fillers/dashed-filler.ts b/blocksuite/affine/block-surface/src/utils/rough/fillers/dashed-filler.ts index 3b698a7cacd64..20c113ced2f15 100644 --- a/blocksuite/affine/block-surface/src/utils/rough/fillers/dashed-filler.ts +++ b/blocksuite/affine/block-surface/src/utils/rough/fillers/dashed-filler.ts @@ -5,7 +5,7 @@ import type { PatternFiller, RenderHelper } from './filler-interface.js'; import { polygonHachureLines } from './scan-line-hachure.js'; export class DashedFiller implements PatternFiller { - private helper: RenderHelper; + private readonly helper: RenderHelper; constructor(helper: RenderHelper) { this.helper = helper; diff --git a/blocksuite/affine/block-surface/src/utils/rough/fillers/dot-filler.ts b/blocksuite/affine/block-surface/src/utils/rough/fillers/dot-filler.ts index b208f350f635d..bb08033499632 100644 --- a/blocksuite/affine/block-surface/src/utils/rough/fillers/dot-filler.ts +++ b/blocksuite/affine/block-surface/src/utils/rough/fillers/dot-filler.ts @@ -5,7 +5,7 @@ import type { PatternFiller, RenderHelper } from './filler-interface.js'; import { polygonHachureLines } from './scan-line-hachure.js'; export class DotFiller implements PatternFiller { - private helper: RenderHelper; + private readonly helper: RenderHelper; constructor(helper: RenderHelper) { this.helper = helper; diff --git a/blocksuite/affine/block-surface/src/utils/rough/fillers/hachure-filler.ts b/blocksuite/affine/block-surface/src/utils/rough/fillers/hachure-filler.ts index a9cacdd336646..b4492b6db4dd0 100644 --- a/blocksuite/affine/block-surface/src/utils/rough/fillers/hachure-filler.ts +++ b/blocksuite/affine/block-surface/src/utils/rough/fillers/hachure-filler.ts @@ -4,7 +4,7 @@ import type { PatternFiller, RenderHelper } from './filler-interface.js'; import { polygonHachureLines } from './scan-line-hachure.js'; export class HachureFiller implements PatternFiller { - private helper: RenderHelper; + private readonly helper: RenderHelper; constructor(helper: RenderHelper) { this.helper = helper; diff --git a/blocksuite/affine/block-surface/src/utils/rough/fillers/zigzag-line-filler.ts b/blocksuite/affine/block-surface/src/utils/rough/fillers/zigzag-line-filler.ts index 3b9c847d8b59e..797578a856f18 100644 --- a/blocksuite/affine/block-surface/src/utils/rough/fillers/zigzag-line-filler.ts +++ b/blocksuite/affine/block-surface/src/utils/rough/fillers/zigzag-line-filler.ts @@ -5,7 +5,7 @@ import type { PatternFiller, RenderHelper } from './filler-interface.js'; import { polygonHachureLines } from './scan-line-hachure.js'; export class ZigZagLineFiller implements PatternFiller { - private helper: RenderHelper; + private readonly helper: RenderHelper; constructor(helper: RenderHelper) { this.helper = helper; diff --git a/blocksuite/affine/block-surface/src/utils/rough/generator.ts b/blocksuite/affine/block-surface/src/utils/rough/generator.ts index d123b701b04cc..e7e1da2a7ca92 100644 --- a/blocksuite/affine/block-surface/src/utils/rough/generator.ts +++ b/blocksuite/affine/block-surface/src/utils/rough/generator.ts @@ -28,7 +28,7 @@ import { const NOS = 'none'; export class RoughGenerator { - private config: Config; + private readonly config: Config; defaultOptions: ResolvedOptions = { maxRandomnessOffset: 2, diff --git a/blocksuite/affine/block-surface/src/utils/rough/svg.ts b/blocksuite/affine/block-surface/src/utils/rough/svg.ts index 3c754fca47045..47412708569d1 100644 --- a/blocksuite/affine/block-surface/src/utils/rough/svg.ts +++ b/blocksuite/affine/block-surface/src/utils/rough/svg.ts @@ -10,9 +10,9 @@ import { RoughGenerator } from './generator.js'; import type { Point } from './geometry.js'; export class RoughSVG { - private gen: RoughGenerator; + private readonly gen: RoughGenerator; - private svg: SVGSVGElement; + private readonly svg: SVGSVGElement; get generator(): RoughGenerator { return this.gen; diff --git a/blocksuite/affine/block-surface/src/view/mindmap.ts b/blocksuite/affine/block-surface/src/view/mindmap.ts index f38194f8f8daf..be6cff91c5ac2 100644 --- a/blocksuite/affine/block-surface/src/view/mindmap.ts +++ b/blocksuite/affine/block-surface/src/view/mindmap.ts @@ -15,7 +15,7 @@ import { handleLayout } from '../utils/mindmap/utils.js'; export class MindMapView extends GfxElementModelView { static override type = 'mindmap'; - private _collapseButtons = new Map(); + private readonly _collapseButtons = new Map(); private _hoveredState = new Map< string, diff --git a/blocksuite/affine/components/src/context-menu/input.ts b/blocksuite/affine/components/src/context-menu/input.ts index dfe47cb56f5bd..d60af8500e980 100644 --- a/blocksuite/affine/components/src/context-menu/input.ts +++ b/blocksuite/affine/components/src/context-menu/input.ts @@ -45,17 +45,17 @@ export class MenuInput extends MenuFocusable { } `; - private onCompositionEnd = () => { + private readonly onCompositionEnd = () => { this.data.onChange?.(this.inputRef.value); }; - private onInput = (e: InputEvent) => { + private readonly onInput = (e: InputEvent) => { e.stopPropagation(); if (e.isComposing) return; this.data.onChange?.(this.inputRef.value); }; - private onKeydown = (e: KeyboardEvent) => { + private readonly onKeydown = (e: KeyboardEvent) => { e.stopPropagation(); if (e.isComposing) return; if (e.key === 'Escape') { @@ -71,7 +71,7 @@ export class MenuInput extends MenuFocusable { } }; - private stopPropagation = (e: Event) => { + private readonly stopPropagation = (e: Event) => { e.stopPropagation(); }; @@ -140,17 +140,17 @@ export class MobileMenuInput extends MenuFocusable { } `; - private onCompositionEnd = () => { + private readonly onCompositionEnd = () => { this.data.onChange?.(this.inputRef.value); }; - private onInput = (e: InputEvent) => { + private readonly onInput = (e: InputEvent) => { e.stopPropagation(); if (e.isComposing) return; this.data.onChange?.(this.inputRef.value); }; - private stopPropagation = (e: Event) => { + private readonly stopPropagation = (e: Event) => { e.stopPropagation(); }; diff --git a/blocksuite/affine/components/src/context-menu/menu-renderer.ts b/blocksuite/affine/components/src/context-menu/menu-renderer.ts index 1677e258a3603..848f168429c27 100644 --- a/blocksuite/affine/components/src/context-menu/menu-renderer.ts +++ b/blocksuite/affine/components/src/context-menu/menu-renderer.ts @@ -83,13 +83,13 @@ export class MenuComponent } `; - private _clickContainer = (e: MouseEvent) => { + private readonly _clickContainer = (e: MouseEvent) => { e.stopPropagation(); this.focusInput(); this.menu.closeSubMenu(); }; - private searchRef = createRef(); + private readonly searchRef = createRef(); override firstUpdated() { const input = this.searchRef.value; diff --git a/blocksuite/affine/components/src/context-menu/menu.ts b/blocksuite/affine/components/src/context-menu/menu.ts index e968ce16010f9..3011f4c0b49cb 100644 --- a/blocksuite/affine/components/src/context-menu/menu.ts +++ b/blocksuite/affine/components/src/context-menu/menu.ts @@ -57,9 +57,9 @@ export function onMenuOpen(listener: MenuOpenListener) { export class Menu { private _cleanupFns: Array<() => void> = []; - private _currentFocused$ = signal(); + private readonly _currentFocused$ = signal(); - private _subMenu$ = signal(); + private readonly _subMenu$ = signal(); closed = false; diff --git a/blocksuite/affine/components/src/date-picker/date-picker.ts b/blocksuite/affine/components/src/date-picker/date-picker.ts index ef10c8c5d8b35..6810ceb8bb34b 100644 --- a/blocksuite/affine/components/src/date-picker/date-picker.ts +++ b/blocksuite/affine/components/src/date-picker/date-picker.ts @@ -54,9 +54,9 @@ export class DatePicker extends WithDisposable(LitElement) { /** current active month */ private _cursor = new Date(); - private _maxYear = 2099; + private readonly _maxYear = 2099; - private _minYear = 1970; + private readonly _minYear = 1970; get _cardStyle() { return { diff --git a/blocksuite/affine/components/src/date-picker/utils.ts b/blocksuite/affine/components/src/date-picker/utils.ts index e8a7e0182cff0..3616e380680d6 100644 --- a/blocksuite/affine/components/src/date-picker/utils.ts +++ b/blocksuite/affine/components/src/date-picker/utils.ts @@ -68,6 +68,6 @@ export function getMonthMatrix(maybeDate: MaybeDate) { } export function clamp(num1: number, num2: number, value: number) { - const [min, max] = [num1, num2].sort(); + const [min, max] = [num1, num2].sort((a, b) => a - b); return Math.min(Math.max(value, min), max); } diff --git a/blocksuite/affine/components/src/peek/controller.ts b/blocksuite/affine/components/src/peek/controller.ts index b47f6bda76054..53fffb50ef3fa 100644 --- a/blocksuite/affine/components/src/peek/controller.ts +++ b/blocksuite/affine/components/src/peek/controller.ts @@ -4,7 +4,7 @@ import { PeekViewProvider } from './service.js'; import type { PeekableClass, PeekViewService } from './type.js'; export class PeekableController { - private _getPeekViewService = (): PeekViewService | null => { + private readonly _getPeekViewService = (): PeekViewService | null => { return this.target.std.getOptional(PeekViewProvider); }; @@ -25,7 +25,7 @@ export class PeekableController { } constructor( - private target: T, - private enable?: (e: T) => boolean + private readonly target: T, + private readonly enable?: (e: T) => boolean ) {} } diff --git a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/link-node/affine-link.ts b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/link-node/affine-link.ts index 69674cd18a753..d8f74b89009f2 100644 --- a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/link-node/affine-link.ts +++ b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/link-node/affine-link.ts @@ -30,7 +30,7 @@ export class AffineLink extends ShadowlessElement { private _identified: boolean = false; // see https://github.com/toeverything/AFFiNE/issues/1540 - private _onMouseUp = () => { + private readonly _onMouseUp = () => { const anchorElement = this.querySelector('a'); if (!anchorElement || !anchorElement.isContentEditable) return; anchorElement.contentEditable = 'false'; @@ -58,7 +58,7 @@ export class AffineLink extends ShadowlessElement { refNodeSlotsProvider.docLinkClicked.emit(referenceInfo); }; - private _whenHover = new HoverController( + private readonly _whenHover = new HoverController( this, ({ abortController }) => { if (this.block?.doc.readonly) { diff --git a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/link-node/link-popup/link-popup.ts b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/link-node/link-popup/link-popup.ts index f4e1445f91b11..b3b1bd4616cac 100644 --- a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/link-node/link-popup/link-popup.ts +++ b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/link-node/link-popup/link-popup.ts @@ -49,7 +49,7 @@ export class LinkPopup extends WithDisposable(LitElement) { private _bodyOverflowStyle = ''; - private _createTemplate = () => { + private readonly _createTemplate = () => { this.updateComplete .then(() => { this.linkInput?.focus(); @@ -74,14 +74,14 @@ export class LinkPopup extends WithDisposable(LitElement) { `; }; - private _delete = () => { + private readonly _delete = () => { if (this.inlineEditor.isValidInlineRange(this.targetInlineRange)) { this.inlineEditor.deleteText(this.targetInlineRange); } this.abortController.abort(); }; - private _edit = () => { + private readonly _edit = () => { if (!this.host) return; this.type = 'edit'; @@ -89,7 +89,7 @@ export class LinkPopup extends WithDisposable(LitElement) { track(this.host.std, 'OpenedAliasPopup', { control: 'edit' }); }; - private _editTemplate = () => { + private readonly _editTemplate = () => { this.updateComplete .then(() => { if ( @@ -139,7 +139,7 @@ export class LinkPopup extends WithDisposable(LitElement) { private _embedOptions: EmbedOptions | null = null; - private _openLink = () => { + private readonly _openLink = () => { if (this.openLink) { this.openLink(); return; @@ -154,7 +154,7 @@ export class LinkPopup extends WithDisposable(LitElement) { this.abortController.abort(); }; - private _removeLink = () => { + private readonly _removeLink = () => { if (this.inlineEditor.isValidInlineRange(this.targetInlineRange)) { this.inlineEditor.formatText(this.targetInlineRange, { link: null, @@ -163,7 +163,7 @@ export class LinkPopup extends WithDisposable(LitElement) { this.abortController.abort(); }; - private _toggleViewSelector = (e: Event) => { + private readonly _toggleViewSelector = (e: Event) => { if (!this.host) return; const opened = (e as CustomEvent).detail; @@ -172,7 +172,7 @@ export class LinkPopup extends WithDisposable(LitElement) { track(this.host.std, 'OpenedViewSelector', { control: 'switch view' }); }; - private _trackViewSelected = (type: string) => { + private readonly _trackViewSelected = (type: string) => { if (!this.host) return; track(this.host.std, 'SelectedView', { @@ -181,7 +181,7 @@ export class LinkPopup extends WithDisposable(LitElement) { }); }; - private _viewTemplate = () => { + private readonly _viewTemplate = () => { if (!this.currentLink) return; this._embedOptions = diff --git a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-alias-popup.ts b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-alias-popup.ts index 1abdb3f3f2026..8a50f49327be6 100644 --- a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-alias-popup.ts +++ b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-alias-popup.ts @@ -89,7 +89,7 @@ export class ReferenceAliasPopup extends SignalWatcher( } `; - private _onSave = () => { + private readonly _onSave = () => { const title = this.title$.value.trim(); if (!title) { this.remove(); @@ -103,7 +103,7 @@ export class ReferenceAliasPopup extends SignalWatcher( this.remove(); }; - private _updateTitle = (e: InputEvent) => { + private readonly _updateTitle = (e: InputEvent) => { const target = e.target as HTMLInputElement; const value = target.value; this.title$.value = value; diff --git a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-node.ts b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-node.ts index 6879b51c2c6a0..10cf460568267 100644 --- a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-node.ts +++ b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-node.ts @@ -68,7 +68,7 @@ export class AffineReference extends WithDisposable(ShadowlessElement) { } `; - private _updateRefMeta = (doc: Doc) => { + private readonly _updateRefMeta = (doc: Doc) => { const refAttribute = this.delta.attributes?.reference; if (!refAttribute) { return; @@ -88,7 +88,7 @@ export class AffineReference extends WithDisposable(ShadowlessElement) { @state() accessor refMeta: DocMeta | undefined = undefined; - private _whenHover: HoverController = new HoverController( + private readonly _whenHover: HoverController = new HoverController( this, ({ abortController }) => { if ( diff --git a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-popup.ts b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-popup.ts index d85675de9f80a..cc55aa43b2dda 100644 --- a/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-popup.ts +++ b/blocksuite/affine/components/src/rich-text/inline/presets/nodes/reference-node/reference-popup.ts @@ -50,7 +50,7 @@ import { styles } from './styles.js'; export class ReferencePopup extends WithDisposable(LitElement) { static override styles = styles; - private _copyLink = () => { + private readonly _copyLink = () => { const url = this.std .getOptional(GenerateDocUrlProvider) ?.generateDocUrl(this.referenceInfo.pageId, this.referenceInfo.params); @@ -65,13 +65,13 @@ export class ReferencePopup extends WithDisposable(LitElement) { track(this.std, 'CopiedLink', { control: 'copy link' }); }; - private _openDoc = () => { + private readonly _openDoc = () => { this.std .getOptional(RefNodeSlotsProvider) ?.docLinkClicked.emit(this.referenceInfo); }; - private _openEditPopup = (e: MouseEvent) => { + private readonly _openEditPopup = (e: MouseEvent) => { e.stopPropagation(); if (document.body.querySelector('reference-alias-popup')) { @@ -102,14 +102,14 @@ export class ReferencePopup extends WithDisposable(LitElement) { track(std, 'OpenedAliasPopup', { control: 'edit' }); }; - private _toggleViewSelector = (e: Event) => { + private readonly _toggleViewSelector = (e: Event) => { const opened = (e as CustomEvent).detail; if (!opened) return; track(this.std, 'OpenedViewSelector', { control: 'switch view' }); }; - private _trackViewSelected = (type: string) => { + private readonly _trackViewSelected = (type: string) => { track(this.std, 'SelectedView', { control: 'select view', type: `${type} view`, diff --git a/blocksuite/affine/components/src/rich-text/rich-text.ts b/blocksuite/affine/components/src/rich-text/rich-text.ts index 4427ceaaf2d4c..bed5e2c136fa2 100644 --- a/blocksuite/affine/components/src/rich-text/rich-text.ts +++ b/blocksuite/affine/components/src/rich-text/rich-text.ts @@ -60,7 +60,7 @@ export class RichText extends WithDisposable(ShadowlessElement) { private _inlineEditor: AffineInlineEditor | null = null; - private _onCopy = (e: ClipboardEvent) => { + private readonly _onCopy = (e: ClipboardEvent) => { const inlineEditor = this.inlineEditor; if (!inlineEditor) return; @@ -77,7 +77,7 @@ export class RichText extends WithDisposable(ShadowlessElement) { e.stopPropagation(); }; - private _onCut = (e: ClipboardEvent) => { + private readonly _onCut = (e: ClipboardEvent) => { const inlineEditor = this.inlineEditor; if (!inlineEditor) return; @@ -99,7 +99,7 @@ export class RichText extends WithDisposable(ShadowlessElement) { e.stopPropagation(); }; - private _onPaste = (e: ClipboardEvent) => { + private readonly _onPaste = (e: ClipboardEvent) => { const inlineEditor = this.inlineEditor; if (!inlineEditor) return; @@ -121,14 +121,18 @@ export class RichText extends WithDisposable(ShadowlessElement) { e.stopPropagation(); }; - private _onStackItemAdded = (event: { stackItem: RichTextStackItem }) => { + private readonly _onStackItemAdded = (event: { + stackItem: RichTextStackItem; + }) => { const inlineRange = this.inlineEditor?.getInlineRange(); if (inlineRange) { event.stackItem.meta.set('richtext-v-range', inlineRange); } }; - private _onStackItemPopped = (event: { stackItem: RichTextStackItem }) => { + private readonly _onStackItemPopped = (event: { + stackItem: RichTextStackItem; + }) => { const inlineRange = event.stackItem.meta.get('richtext-v-range'); if (inlineRange && this.inlineEditor?.isValidInlineRange(inlineRange)) { this.inlineEditor?.setInlineRange(inlineRange); diff --git a/blocksuite/affine/components/src/toolbar/tooltip.ts b/blocksuite/affine/components/src/toolbar/tooltip.ts index 9cc12e15d234c..6eb2c7c1166c6 100644 --- a/blocksuite/affine/components/src/toolbar/tooltip.ts +++ b/blocksuite/affine/components/src/toolbar/tooltip.ts @@ -125,7 +125,7 @@ export class Tooltip extends LitElement { private _hoverController!: HoverController; - private _setUpHoverController = () => { + private readonly _setUpHoverController = () => { this._hoverController = new HoverController( this, () => { diff --git a/blocksuite/affine/components/src/virtual-keyboard/controller.ts b/blocksuite/affine/components/src/virtual-keyboard/controller.ts index b9bf58a6318a7..7e99c209e5e3a 100644 --- a/blocksuite/affine/components/src/virtual-keyboard/controller.ts +++ b/blocksuite/affine/components/src/virtual-keyboard/controller.ts @@ -13,13 +13,13 @@ export type VirtualKeyboardControllerConfig = { }; export class VirtualKeyboardController implements ReactiveController { - private _disposables = new DisposableGroup(); + private readonly _disposables = new DisposableGroup(); private readonly _keyboardHeight$ = signal(0); private readonly _keyboardOpened$ = signal(false); - private _storeInitialInputElementAttributes = () => { + private readonly _storeInitialInputElementAttributes = () => { const { inputElement } = this.config; if (navigator.virtualKeyboard) { const { overlaysContent } = navigator.virtualKeyboard; diff --git a/blocksuite/affine/data-view/src/core/component/tags/multi-tag-select.ts b/blocksuite/affine/data-view/src/core/component/tags/multi-tag-select.ts index d38dc1f358a7a..9c12fbef21743 100644 --- a/blocksuite/affine/data-view/src/core/component/tags/multi-tag-select.ts +++ b/blocksuite/affine/data-view/src/core/component/tags/multi-tag-select.ts @@ -150,7 +150,7 @@ class TagManager { return this.ops.value; } - constructor(private ops: TagManagerOptions) {} + constructor(private readonly ops: TagManagerOptions) {} deleteTag(id: string) { this.ops.onChange(this.value.value.filter(item => item !== id)); @@ -180,7 +180,7 @@ export class MultiTagSelect extends SignalWatcher( ) { static override styles = styles; - private _clickItemOption = (e: MouseEvent, id: string) => { + private readonly _clickItemOption = (e: MouseEvent, id: string) => { e.stopPropagation(); const option = this.options.value.find(v => v.id === id); if (!option) { @@ -235,11 +235,11 @@ export class MultiTagSelect extends SignalWatcher( }); }; - private _onInput = (event: KeyboardEvent) => { + private readonly _onInput = (event: KeyboardEvent) => { this.tagManager.text.value = (event.target as HTMLInputElement).value; }; - private _onInputKeydown = (event: KeyboardEvent) => { + private readonly _onInputKeydown = (event: KeyboardEvent) => { event.stopPropagation(); const inputValue = this.text.value.trim(); if (event.key === 'Backspace' && inputValue === '') { @@ -257,9 +257,9 @@ export class MultiTagSelect extends SignalWatcher( } }; - private tagManager = new TagManager(this); + private readonly tagManager = new TagManager(this); - private selectedTag$ = computed(() => { + private readonly selectedTag$ = computed(() => { return this.tagManager.filteredOptions$.value[this.selectedIndex]; }); diff --git a/blocksuite/affine/data-view/src/core/data-view.ts b/blocksuite/affine/data-view/src/core/data-view.ts index 8cc56bc00c8bf..ad8e938189747 100644 --- a/blocksuite/affine/data-view/src/core/data-view.ts +++ b/blocksuite/affine/data-view/src/core/data-view.ts @@ -63,14 +63,14 @@ export class DataViewRenderer extends SignalWatcher( } `; - private _view = createRef<{ + private readonly _view = createRef<{ expose: DataViewInstance; }>(); @property({ attribute: false }) accessor config!: DataViewRendererConfig; - private currentViewId$ = computed(() => { + private readonly currentViewId$ = computed(() => { return this.config.dataSource.viewManager.currentViewId$.value; }); @@ -218,7 +218,7 @@ declare global { } export class DataView { - private _ref = createRef(); + private readonly _ref = createRef(); get expose() { return this._ref.value?.view?.expose; diff --git a/blocksuite/affine/data-view/src/core/detail/field.ts b/blocksuite/affine/data-view/src/core/detail/field.ts index 2531a1bf12861..effe05fb70a88 100644 --- a/blocksuite/affine/data-view/src/core/detail/field.ts +++ b/blocksuite/affine/data-view/src/core/detail/field.ts @@ -109,7 +109,7 @@ export class RecordField extends SignalWatcher( } `; - private _cell = createRef(); + private readonly _cell = createRef(); _click = (e: MouseEvent) => { e.stopPropagation(); diff --git a/blocksuite/affine/data-view/src/core/detail/selection.ts b/blocksuite/affine/data-view/src/core/detail/selection.ts index aa300050a06b8..a0ab39daf25b5 100644 --- a/blocksuite/affine/data-view/src/core/detail/selection.ts +++ b/blocksuite/affine/data-view/src/core/detail/selection.ts @@ -49,7 +49,7 @@ export class DetailSelection { } } - constructor(private viewEle: RecordDetail) {} + constructor(private readonly viewEle: RecordDetail) {} blur(selection: DetailViewSelection) { const container = this.getFocusCellContainer(selection); diff --git a/blocksuite/affine/data-view/src/core/group-by/renderer/number-group.ts b/blocksuite/affine/data-view/src/core/group-by/renderer/number-group.ts index da3917f1e76c2..be9f840eb7090 100644 --- a/blocksuite/affine/data-view/src/core/group-by/renderer/number-group.ts +++ b/blocksuite/affine/data-view/src/core/group-by/renderer/number-group.ts @@ -21,7 +21,7 @@ export class NumberGroupView extends BaseGroup, number> { } `; - private _click = () => { + private readonly _click = () => { if (this.readonly) { return; } diff --git a/blocksuite/affine/data-view/src/core/group-by/renderer/select-group.ts b/blocksuite/affine/data-view/src/core/group-by/renderer/select-group.ts index 2d6b45589b12b..ad36f6f483034 100644 --- a/blocksuite/affine/data-view/src/core/group-by/renderer/select-group.ts +++ b/blocksuite/affine/data-view/src/core/group-by/renderer/select-group.ts @@ -42,7 +42,7 @@ export class SelectGroupView extends BaseGroup< } `; - private _click = (e: MouseEvent) => { + private readonly _click = (e: MouseEvent) => { if (this.readonly) { return; } diff --git a/blocksuite/affine/data-view/src/core/group-by/renderer/string-group.ts b/blocksuite/affine/data-view/src/core/group-by/renderer/string-group.ts index 8d1f6df0c68bc..cb39355c3f4c8 100644 --- a/blocksuite/affine/data-view/src/core/group-by/renderer/string-group.ts +++ b/blocksuite/affine/data-view/src/core/group-by/renderer/string-group.ts @@ -21,7 +21,7 @@ export class StringGroupView extends BaseGroup, string> { } `; - private _click = () => { + private readonly _click = () => { if (this.readonly) { return; } diff --git a/blocksuite/affine/data-view/src/core/group-by/trait.ts b/blocksuite/affine/data-view/src/core/group-by/trait.ts index 25c785558d773..699b8f009583b 100644 --- a/blocksuite/affine/data-view/src/core/group-by/trait.ts +++ b/blocksuite/affine/data-view/src/core/group-by/trait.ts @@ -103,7 +103,7 @@ export class GroupTrait { return groupMap; }); - private _groupsDataList$ = computed(() => { + private readonly _groupsDataList$ = computed(() => { const groupMap = this.groupDataMap$.value; if (!groupMap) { return; @@ -143,9 +143,9 @@ export class GroupTrait { } constructor( - private groupBy$: ReadonlySignal, + private readonly groupBy$: ReadonlySignal, public view: SingleView, - private ops: { + private readonly ops: { groupBySet: (groupBy: GroupBy | undefined) => void; sortGroup: (keys: string[]) => string[]; sortRow: (groupKey: string, rowIds: string[]) => string[]; diff --git a/blocksuite/affine/data-view/src/core/logical/data-type.ts b/blocksuite/affine/data-view/src/core/logical/data-type.ts index 91c2ddabe2402..feeaaa96b9121 100644 --- a/blocksuite/affine/data-view/src/core/logical/data-type.ts +++ b/blocksuite/affine/data-view/src/core/logical/data-type.ts @@ -50,9 +50,9 @@ export class DataType< > implements TypeDefinition { constructor( - private name: Name, + private readonly name: Name, _dataSchema: DataSchema, - private valueSchema: ValueSchema + private readonly valueSchema: ValueSchema ) {} instance(literal?: Zod.TypeOf) { diff --git a/blocksuite/affine/data-view/src/core/logical/matcher.ts b/blocksuite/affine/data-view/src/core/logical/matcher.ts index 1ca41326a7292..5c1db06ba8e2f 100644 --- a/blocksuite/affine/data-view/src/core/logical/matcher.ts +++ b/blocksuite/affine/data-view/src/core/logical/matcher.ts @@ -14,8 +14,8 @@ export class MatcherCreator { export class Matcher { constructor( - private list: MatcherData[], - private _match: (type: Type, target: TypeInstance) => boolean = ( + private readonly list: MatcherData[], + private readonly _match: (type: Type, target: TypeInstance) => boolean = ( type, target ) => typeSystem.unify(target, type) diff --git a/blocksuite/affine/data-view/src/core/logical/type-system.ts b/blocksuite/affine/data-view/src/core/logical/type-system.ts index 0222727d6186e..acf71d34f3576 100644 --- a/blocksuite/affine/data-view/src/core/logical/type-system.ts +++ b/blocksuite/affine/data-view/src/core/logical/type-system.ts @@ -32,7 +32,7 @@ const getMap2 = ( }; export class TypeSystem { - private _unify: Unify = ( + private readonly _unify: Unify = ( ctx: TypeVarContext, left: TypeInstance | undefined, right: TypeInstance | undefined diff --git a/blocksuite/affine/data-view/src/core/sort/manager.ts b/blocksuite/affine/data-view/src/core/sort/manager.ts index 976be11ce5055..a89147855d31d 100644 --- a/blocksuite/affine/data-view/src/core/sort/manager.ts +++ b/blocksuite/affine/data-view/src/core/sort/manager.ts @@ -34,7 +34,7 @@ export class SortManager { constructor( readonly sort$: ReadonlySignal, readonly view: SingleView, - private ops: { + private readonly ops: { setSortList: (sortList: Sort) => void; } ) {} diff --git a/blocksuite/affine/data-view/src/core/utils/wc-dnd/dnd-context.ts b/blocksuite/affine/data-view/src/core/utils/wc-dnd/dnd-context.ts index 0d761c801d3b1..80598a9a09e52 100644 --- a/blocksuite/affine/data-view/src/core/utils/wc-dnd/dnd-context.ts +++ b/blocksuite/affine/data-view/src/core/utils/wc-dnd/dnd-context.ts @@ -56,20 +56,20 @@ const defaultCoordinates: Coordinates = { }; export class DndContext { - private dragMove = (coordinates: Coordinates) => { + private readonly dragMove = (coordinates: Coordinates) => { this.activationCoordinates$.value = coordinates; this.autoScroll(); }; - private droppableNodes$ = signal(new Map()); + private readonly droppableNodes$ = signal(new Map()); - private initialCoordinates$ = signal(); + private readonly initialCoordinates$ = signal(); - private initScrollOffset$ = signal(defaultCoordinates); + private readonly initScrollOffset$ = signal(defaultCoordinates); - private session$ = signal(); + private readonly session$ = signal(); - private startSession = ( + private readonly startSession = ( id: UniqueIdentifier, activeNode: HTMLElement, sessionCreator: DndSessionCreator @@ -96,7 +96,7 @@ export class DndContext { activationCoordinates$ = signal(); - private translate$ = computed(() => { + private readonly translate$ = computed(() => { const init = this.initialCoordinates$.value; const current = this.activationCoordinates$.value; if (!init || !current) { diff --git a/blocksuite/affine/data-view/src/core/utils/wc-dnd/sensors/mouse.ts b/blocksuite/affine/data-view/src/core/utils/wc-dnd/sensors/mouse.ts index c34837de79d52..5057feca7cba7 100644 --- a/blocksuite/affine/data-view/src/core/utils/wc-dnd/sensors/mouse.ts +++ b/blocksuite/affine/data-view/src/core/utils/wc-dnd/sensors/mouse.ts @@ -192,8 +192,8 @@ export class MouseSession implements DndSession { constructor( event: Event, - private sessionProps: DndSessionProps, - private props: MouseSensorProps + private readonly sessionProps: DndSessionProps, + private readonly props: MouseSensorProps ) { this.initialCoordinates = getEventCoordinates(event) ?? defaultCoordinates; this.attach(); diff --git a/blocksuite/affine/data-view/src/core/utils/wc-dnd/utils/listeners.ts b/blocksuite/affine/data-view/src/core/utils/wc-dnd/utils/listeners.ts index 4550e615ae1aa..2ead5cf79089a 100644 --- a/blocksuite/affine/data-view/src/core/utils/wc-dnd/utils/listeners.ts +++ b/blocksuite/affine/data-view/src/core/utils/wc-dnd/utils/listeners.ts @@ -1,5 +1,5 @@ export class Listeners { - private listeners: [ + private readonly listeners: [ string, EventListenerOrEventListenerObject | null, AddEventListenerOptions | boolean | undefined, diff --git a/blocksuite/affine/data-view/src/core/view-manager/single-view.ts b/blocksuite/affine/data-view/src/core/view-manager/single-view.ts index 65f7630f67eea..84520c178fa35 100644 --- a/blocksuite/affine/data-view/src/core/view-manager/single-view.ts +++ b/blocksuite/affine/data-view/src/core/view-manager/single-view.ts @@ -139,9 +139,9 @@ export abstract class SingleViewBase< ViewData extends DataViewDataType = DataViewDataType, > implements SingleView { - private searchString = signal(''); + private readonly searchString = signal(''); - private traitMap = new Map(); + private readonly traitMap = new Map(); data$ = computed(() => { return this.dataSource.viewDataGet(this.id) as ViewData | undefined; diff --git a/blocksuite/affine/data-view/src/property-presets/date/cell-renderer.ts b/blocksuite/affine/data-view/src/property-presets/date/cell-renderer.ts index 3df9503b9187e..e4a131b9b6149 100644 --- a/blocksuite/affine/data-view/src/property-presets/date/cell-renderer.ts +++ b/blocksuite/affine/data-view/src/property-presets/date/cell-renderer.ts @@ -66,7 +66,7 @@ export class DateCellEditing extends BaseCellRenderer { private _prevPortalAbortController: AbortController | null = null; - private openDatePicker = () => { + private readonly openDatePicker = () => { if ( this._prevPortalAbortController && !this._prevPortalAbortController.signal.aborted @@ -168,7 +168,7 @@ height: 46px; } }; - private updateValue = () => { + private readonly updateValue = () => { const tempValue = this.tempValue$.value; const currentValue = this.value; diff --git a/blocksuite/affine/data-view/src/property-presets/multi-select/cell-renderer.ts b/blocksuite/affine/data-view/src/property-presets/multi-select/cell-renderer.ts index f46a266745fde..5e67b252e8f3c 100644 --- a/blocksuite/affine/data-view/src/property-presets/multi-select/cell-renderer.ts +++ b/blocksuite/affine/data-view/src/property-presets/multi-select/cell-renderer.ts @@ -28,7 +28,7 @@ export class MultiSelectCellEditing extends BaseCellRenderer< string[], SelectPropertyData > { - private popTagSelect = () => { + private readonly popTagSelect = () => { const value = signal(this._value); this._disposables.add({ dispose: popTagSelect( diff --git a/blocksuite/affine/data-view/src/property-presets/number/cell-renderer.ts b/blocksuite/affine/data-view/src/property-presets/number/cell-renderer.ts index 5d753bd620e96..dd21a2005261b 100644 --- a/blocksuite/affine/data-view/src/property-presets/number/cell-renderer.ts +++ b/blocksuite/affine/data-view/src/property-presets/number/cell-renderer.ts @@ -95,7 +95,7 @@ export class NumberCellEditing extends BaseCellRenderer< } `; - private _getFormattedString = (value: number) => { + private readonly _getFormattedString = (value: number) => { const enableNewFormatting = this.view.featureFlags$.value.enable_number_formatting; const decimals = this.property.data$.value.decimal ?? 0; @@ -106,7 +106,7 @@ export class NumberCellEditing extends BaseCellRenderer< : value.toString(); }; - private _keydown = (e: KeyboardEvent) => { + private readonly _keydown = (e: KeyboardEvent) => { const ctrlKey = IS_MAC ? e.metaKey : e.ctrlKey; if (e.key.toLowerCase() === 'z' && ctrlKey) { @@ -121,7 +121,7 @@ export class NumberCellEditing extends BaseCellRenderer< } }; - private _setValue = (str: string = this._inputEle.value) => { + private readonly _setValue = (str: string = this._inputEle.value) => { if (!str) { this.onChange(undefined); return; diff --git a/blocksuite/affine/data-view/src/property-presets/select/cell-renderer.ts b/blocksuite/affine/data-view/src/property-presets/select/cell-renderer.ts index ae3347ee3926a..bfdf9ba89afa5 100644 --- a/blocksuite/affine/data-view/src/property-presets/select/cell-renderer.ts +++ b/blocksuite/affine/data-view/src/property-presets/select/cell-renderer.ts @@ -28,7 +28,7 @@ export class SelectCellEditing extends BaseCellRenderer< string, SelectPropertyData > { - private popTagSelect = () => { + private readonly popTagSelect = () => { const value = signal(this._value); this._disposables.add({ dispose: popTagSelect( diff --git a/blocksuite/affine/data-view/src/property-presets/text/cell-renderer.ts b/blocksuite/affine/data-view/src/property-presets/text/cell-renderer.ts index 7102f7a53e08e..40149a999f6f2 100644 --- a/blocksuite/affine/data-view/src/property-presets/text/cell-renderer.ts +++ b/blocksuite/affine/data-view/src/property-presets/text/cell-renderer.ts @@ -70,7 +70,7 @@ export class TextCellEditing extends BaseCellRenderer { } `; - private _keydown = (e: KeyboardEvent) => { + private readonly _keydown = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.isComposing) { this._setValue(); setTimeout(() => { @@ -79,7 +79,7 @@ export class TextCellEditing extends BaseCellRenderer { } }; - private _setValue = (str: string = this._inputEle.value) => { + private readonly _setValue = (str: string = this._inputEle.value) => { this._inputEle.value = `${this.value ?? ''}`; this.onChange(str); }; diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/mobile/card.ts b/blocksuite/affine/data-view/src/view-presets/kanban/mobile/card.ts index 66380a02a1414..8c1f7f5b61423 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/mobile/card.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/mobile/card.ts @@ -91,7 +91,7 @@ export class MobileKanbanCard extends SignalWatcher( ) { static override styles = styles; - private clickCenterPeek = (e: MouseEvent) => { + private readonly clickCenterPeek = (e: MouseEvent) => { e.stopPropagation(); this.dataViewEle.openDetailPanel({ view: this.view, @@ -99,7 +99,7 @@ export class MobileKanbanCard extends SignalWatcher( }); }; - private clickMore = (e: MouseEvent) => { + private readonly clickMore = (e: MouseEvent) => { e.stopPropagation(); popCardMenu( popupTargetFromElement(e.currentTarget as HTMLElement), diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/mobile/cell.ts b/blocksuite/affine/data-view/src/view-presets/kanban/mobile/cell.ts index e30e48446cc93..70723432524ae 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/mobile/cell.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/mobile/cell.ts @@ -51,7 +51,7 @@ export class MobileKanbanCell extends SignalWatcher( ) { static override styles = styles; - private _cell = createRef(); + private readonly _cell = createRef(); isEditing$ = computed(() => { const selection = this.kanban?.props.selection$.value; diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/mobile/group.ts b/blocksuite/affine/data-view/src/view-presets/kanban/mobile/group.ts index b01a99c3f170f..52dd078648c0f 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/mobile/group.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/mobile/group.ts @@ -60,15 +60,15 @@ export class MobileKanbanGroup extends SignalWatcher( ) { static override styles = styles; - private clickAddCard = () => { + private readonly clickAddCard = () => { this.view.addCard('end', this.group.key); }; - private clickAddCardInStart = () => { + private readonly clickAddCardInStart = () => { this.view.addCard('start', this.group.key); }; - private clickGroupOptions = (e: MouseEvent) => { + private readonly clickGroupOptions = (e: MouseEvent) => { const ele = e.currentTarget as HTMLElement; popFilterableSimpleMenu(popupTargetFromElement(ele), [ menu.group({ diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/card.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/card.ts index 0009d590e8984..bcfcb0b2cc6ff 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/card.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/card.ts @@ -125,7 +125,7 @@ export class KanbanCard extends SignalWatcher( ) { static override styles = styles; - private clickEdit = (e: MouseEvent) => { + private readonly clickEdit = (e: MouseEvent) => { e.stopPropagation(); const selection = this.getSelection(); if (selection) { @@ -133,7 +133,7 @@ export class KanbanCard extends SignalWatcher( } }; - private clickMore = (e: MouseEvent) => { + private readonly clickMore = (e: MouseEvent) => { e.stopPropagation(); const selection = this.getSelection(); const ele = e.currentTarget as HTMLElement; @@ -156,7 +156,7 @@ export class KanbanCard extends SignalWatcher( } }; - private contextMenu = (e: MouseEvent) => { + private readonly contextMenu = (e: MouseEvent) => { e.stopPropagation(); e.preventDefault(); const selection = this.getSelection(); diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/cell.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/cell.ts index 1c10e99c828ba..8deef53dae4eb 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/cell.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/cell.ts @@ -59,7 +59,7 @@ export class KanbanCell extends SignalWatcher( ) { static override styles = styles; - private _cell = createRef(); + private readonly _cell = createRef(); selectCurrentCell = (editing: boolean) => { const selectionView = this.closest( diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/clipboard.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/clipboard.ts index 8fe68fc462602..d45206ea98e20 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/clipboard.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/clipboard.ts @@ -5,7 +5,7 @@ import type { KanbanViewSelectionWithType } from '../../types.js'; import type { DataViewKanban } from '../kanban-view.js'; export class KanbanClipboardController implements ReactiveController { - private _onCopy = ( + private readonly _onCopy = ( _context: UIEventStateContext, _kanbanSelection: KanbanViewSelectionWithType ) => { @@ -13,7 +13,7 @@ export class KanbanClipboardController implements ReactiveController { return true; }; - private _onPaste = (_context: UIEventStateContext) => { + private readonly _onPaste = (_context: UIEventStateContext) => { // todo return true; }; diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/drag.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/drag.ts index e585112433b40..74c216a134311 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/drag.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/drag.ts @@ -140,7 +140,7 @@ export class KanbanDragController implements ReactiveController { return scrollContainer; } - constructor(private host: DataViewKanban) { + constructor(private readonly host: DataViewKanban) { this.host.addController(this); } diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/hotkeys.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/hotkeys.ts index 1c74cf59fe2cd..57b38508f26c1 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/hotkeys.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/hotkeys.ts @@ -7,7 +7,7 @@ export class KanbanHotkeysController implements ReactiveController { return !!this.host.selectionController.selection; } - constructor(private host: DataViewKanban) { + constructor(private readonly host: DataViewKanban) { this.host.addController(this); } diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/selection.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/selection.ts index 1bf0df1f0c8da..a2cc30058dce6 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/selection.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/controller/selection.ts @@ -79,7 +79,7 @@ export class KanbanSelectionController implements ReactiveController { return this.host.props.view; } - constructor(private host: DataViewKanban) { + constructor(private readonly host: DataViewKanban) { this.host.addController(this); } diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/group.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/group.ts index 7544f32fd0b5e..be27e1114c3f3 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/group.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/group.ts @@ -96,7 +96,7 @@ export class KanbanGroup extends SignalWatcher( ) { static override styles = styles; - private clickAddCard = () => { + private readonly clickAddCard = () => { const id = this.view.addCard('end', this.group.key); requestAnimationFrame(() => { const kanban = this.closest('affine-data-view-kanban'); @@ -114,7 +114,7 @@ export class KanbanGroup extends SignalWatcher( }); }; - private clickAddCardInStart = () => { + private readonly clickAddCardInStart = () => { const id = this.view.addCard('start', this.group.key); requestAnimationFrame(() => { const kanban = this.closest('affine-data-view-kanban'); @@ -132,7 +132,7 @@ export class KanbanGroup extends SignalWatcher( }); }; - private clickGroupOptions = (e: MouseEvent) => { + private readonly clickGroupOptions = (e: MouseEvent) => { const ele = e.currentTarget as HTMLElement; popFilterableSimpleMenu(popupTargetFromElement(ele), [ menu.action({ diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/header.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/header.ts index d4378246e4652..ebf21f4ad3a88 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/header.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/header.ts @@ -35,7 +35,7 @@ export class KanbanHeader extends SignalWatcher( ) { static override styles = styles; - private clickGroup = (e: MouseEvent) => { + private readonly clickGroup = (e: MouseEvent) => { const groupTrait = this.view.traitGet(groupTraitKey); if (!groupTrait) { return; diff --git a/blocksuite/affine/data-view/src/view-presets/kanban/pc/kanban-view.ts b/blocksuite/affine/data-view/src/view-presets/kanban/pc/kanban-view.ts index 83a55978b2e7f..5c55c8fd0d78c 100644 --- a/blocksuite/affine/data-view/src/view-presets/kanban/pc/kanban-view.ts +++ b/blocksuite/affine/data-view/src/view-presets/kanban/pc/kanban-view.ts @@ -100,7 +100,7 @@ export class DataViewKanban extends DataViewBase< > { static override styles = styles; - private dragController = new KanbanDragController(this); + private readonly dragController = new KanbanDragController(this); clipboardController = new KanbanClipboardController(this); diff --git a/blocksuite/affine/data-view/src/view-presets/table/mobile/cell.ts b/blocksuite/affine/data-view/src/view-presets/table/mobile/cell.ts index 41d0c436d333c..a55f9f66197cd 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/mobile/cell.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/mobile/cell.ts @@ -36,7 +36,7 @@ export class MobileTableCell extends SignalWatcher( } `; - private _cell = createRef(); + private readonly _cell = createRef(); @property({ attribute: false }) accessor column!: TableColumn; diff --git a/blocksuite/affine/data-view/src/view-presets/table/mobile/column-header.ts b/blocksuite/affine/data-view/src/view-presets/table/mobile/column-header.ts index 0a8cfed8c765b..ed3a1f3cf0bfd 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/mobile/column-header.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/mobile/column-header.ts @@ -53,7 +53,7 @@ export class MobileTableColumnHeader extends SignalWatcher( } `; - private _clickColumn = () => { + private readonly _clickColumn = () => { if (this.tableViewManager.readonly$.value) { return; } diff --git a/blocksuite/affine/data-view/src/view-presets/table/mobile/group.ts b/blocksuite/affine/data-view/src/view-presets/table/mobile/group.ts index cff0ad8f4da4f..0911f6fbabfbe 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/mobile/group.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/mobile/group.ts @@ -50,7 +50,7 @@ export class MobileTableGroup extends SignalWatcher( ) { static override styles = styles; - private clickAddRow = () => { + private readonly clickAddRow = () => { this.view.rowAdd('end', this.group?.key); requestAnimationFrame(() => { const selectionController = this.viewEle.selectionController; @@ -68,7 +68,7 @@ export class MobileTableGroup extends SignalWatcher( }); }; - private clickAddRowInStart = () => { + private readonly clickAddRowInStart = () => { this.view.rowAdd('start', this.group?.key); requestAnimationFrame(() => { const selectionController = this.viewEle.selectionController; @@ -86,7 +86,7 @@ export class MobileTableGroup extends SignalWatcher( }); }; - private clickGroupOptions = (e: MouseEvent) => { + private readonly clickGroupOptions = (e: MouseEvent) => { const group = this.group; if (!group) { return; @@ -111,7 +111,7 @@ export class MobileTableGroup extends SignalWatcher( ]); }; - private renderGroupHeader = () => { + private readonly renderGroupHeader = () => { if (!this.group) { return null; } diff --git a/blocksuite/affine/data-view/src/view-presets/table/mobile/header.ts b/blocksuite/affine/data-view/src/view-presets/table/mobile/header.ts index 8e0fc2eaba861..f453d7a7b6693 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/mobile/header.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/mobile/header.ts @@ -23,7 +23,7 @@ export class MobileTableHeader extends SignalWatcher( } `; - private _onAddColumn = () => { + private readonly _onAddColumn = () => { if (this.readonly) return; this.tableViewManager.propertyAdd('end'); this.editLastColumnTitle(); diff --git a/blocksuite/affine/data-view/src/view-presets/table/mobile/table-view.ts b/blocksuite/affine/data-view/src/view-presets/table/mobile/table-view.ts index 65f546dbcec01..ab8c9abf2b980 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/mobile/table-view.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/mobile/table-view.ts @@ -45,7 +45,7 @@ export class MobileDataViewTable extends DataViewBase< } `; - private _addRow = ( + private readonly _addRow = ( tableViewManager: TableSingleView, position: InsertToPosition | number ) => { diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/cell.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/cell.ts index 7f199616e82cd..7508728f8d1a2 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/cell.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/cell.ts @@ -43,7 +43,7 @@ export class DatabaseCellContainer extends SignalWatcher( } `; - private _cell = createRef(); + private readonly _cell = createRef(); @property({ attribute: false }) accessor column!: TableColumn; diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/controller/clipboard.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/controller/clipboard.ts index 688a430e1372a..6151fc8fa34ee 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/controller/clipboard.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/controller/clipboard.ts @@ -16,7 +16,7 @@ type JsonAreaData = string[][]; const TEXT = 'text/plain'; export class TableClipboardController implements ReactiveController { - private _onCopy = ( + private readonly _onCopy = ( tableSelection: TableViewSelectionWithType, isCut = false ) => { @@ -72,11 +72,11 @@ export class TableClipboardController implements ReactiveController { return true; }; - private _onCut = (tableSelection: TableViewSelectionWithType) => { + private readonly _onCut = (tableSelection: TableViewSelectionWithType) => { this._onCopy(tableSelection, true); }; - private _onPaste = async (_context: UIEventStateContext) => { + private readonly _onPaste = async (_context: UIEventStateContext) => { const event = _context.get('clipboardState').raw; event.stopPropagation(); const view = this.host; diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/controller/drag.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/controller/drag.ts index 3d6d2b09faf2d..fb91a1c56c1db 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/controller/drag.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/controller/drag.ts @@ -128,7 +128,7 @@ export class TableDragController implements ReactiveController { return position; }; - constructor(private host: DataViewTable) { + constructor(private readonly host: DataViewTable) { this.host.addController(this); } diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/controller/hotkeys.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/controller/hotkeys.ts index a0bb910a15cd0..293147e1a4bcd 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/controller/hotkeys.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/controller/hotkeys.ts @@ -10,7 +10,7 @@ export class TableHotkeysController implements ReactiveController { return this.host.selectionController; } - constructor(private host: DataViewTable) { + constructor(private readonly host: DataViewTable) { this.host.addController(this); } diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/controller/selection.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/controller/selection.ts index 61733ed79fb18..e541dfb3a0eae 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/controller/selection.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/controller/selection.ts @@ -29,7 +29,7 @@ import { export class TableSelectionController implements ReactiveController { private _tableViewSelection?: TableViewSelectionWithType; - private getFocusCellContainer = () => { + private readonly getFocusCellContainer = () => { if ( !this._tableViewSelection || this._tableViewSelection.selectionType !== 'area' diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/group.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/group.ts index 0474c20e87eba..c427c2c55205f 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/group.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/group.ts @@ -67,7 +67,7 @@ export class TableGroup extends SignalWatcher( ) { static override styles = styles; - private clickAddRow = () => { + private readonly clickAddRow = () => { this.view.rowAdd('end', this.group?.key); requestAnimationFrame(() => { const selectionController = this.viewEle.selectionController; @@ -85,7 +85,7 @@ export class TableGroup extends SignalWatcher( }); }; - private clickAddRowInStart = () => { + private readonly clickAddRowInStart = () => { this.view.rowAdd('start', this.group?.key); requestAnimationFrame(() => { const selectionController = this.viewEle.selectionController; @@ -103,7 +103,7 @@ export class TableGroup extends SignalWatcher( }); }; - private clickGroupOptions = (e: MouseEvent) => { + private readonly clickGroupOptions = (e: MouseEvent) => { const group = this.group; if (!group) { return; @@ -128,7 +128,7 @@ export class TableGroup extends SignalWatcher( ]); }; - private renderGroupHeader = () => { + private readonly renderGroupHeader = () => { if (!this.group) { return null; } diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/header/column-header.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/header/column-header.ts index 1a81a50d4b752..e446d524c72f6 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/header/column-header.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/header/column-header.ts @@ -19,7 +19,7 @@ export class DatabaseColumnHeader extends SignalWatcher( ) { static override styles = styles; - private _onAddColumn = (e: MouseEvent) => { + private readonly _onAddColumn = (e: MouseEvent) => { if (this.readonly) return; this.tableViewManager.propertyAdd('end'); const ele = e.currentTarget as HTMLElement; diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/header/database-header-column.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/header/database-header-column.ts index bac236a2b3356..b518e13e5b74d 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/header/database-header-column.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/header/database-header-column.ts @@ -63,14 +63,14 @@ export class DatabaseHeaderColumn extends SignalWatcher( } `; - private _clickColumn = () => { + private readonly _clickColumn = () => { if (this.tableViewManager.readonly$.value) { return; } this.popMenu(); }; - private _clickTypeIcon = (event: MouseEvent) => { + private readonly _clickTypeIcon = (event: MouseEvent) => { if (this.tableViewManager.readonly$.value) { return; } @@ -96,7 +96,7 @@ export class DatabaseHeaderColumn extends SignalWatcher( }); }; - private _contextMenu = (e: MouseEvent) => { + private readonly _contextMenu = (e: MouseEvent) => { if (this.tableViewManager.readonly$.value) { return; } @@ -104,7 +104,7 @@ export class DatabaseHeaderColumn extends SignalWatcher( this.popMenu(e.currentTarget as HTMLElement); }; - private _enterWidthDragBar = () => { + private readonly _enterWidthDragBar = () => { if (this.tableViewManager.readonly$.value) { return; } @@ -115,13 +115,13 @@ export class DatabaseHeaderColumn extends SignalWatcher( this.drawWidthDragBar(); }; - private _leaveWidthDragBar = () => { + private readonly _leaveWidthDragBar = () => { cancelAnimationFrame(this.drawWidthDragBarTask); this.drawWidthDragBarTask = 0; getVerticalIndicator().remove(); }; - private drawWidthDragBar = () => { + private readonly drawWidthDragBar = () => { const rect = getTableGroupRect(this); if (!rect) { return; @@ -136,7 +136,7 @@ export class DatabaseHeaderColumn extends SignalWatcher( private drawWidthDragBarTask = 0; - private widthDragBar = createRef(); + private readonly widthDragBar = createRef(); editTitle = () => { this._clickColumn(); diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/header/number-format-bar.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/header/number-format-bar.ts index fde8520079d2e..16c83f54d3ff2 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/header/number-format-bar.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/header/number-format-bar.ts @@ -87,14 +87,14 @@ export class DatabaseNumberFormatBar extends WithDisposable(LitElement) { } `; - private _decrementDecimalPlaces = () => { + private readonly _decrementDecimalPlaces = () => { this.column.dataUpdate(data => ({ decimal: Math.max(((data.decimal as number) ?? 0) - 1, 0), })); this.requestUpdate(); }; - private _incrementDecimalPlaces = () => { + private readonly _incrementDecimalPlaces = () => { this.column.dataUpdate(data => ({ decimal: Math.min(((data.decimal as number) ?? 0) + 1, 8), })); diff --git a/blocksuite/affine/data-view/src/view-presets/table/pc/row/row.ts b/blocksuite/affine/data-view/src/view-presets/table/pc/row/row.ts index 0bf5465bf6bae..dc2f635b8dfd8 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/pc/row/row.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/pc/row/row.ts @@ -114,7 +114,7 @@ export class TableRow extends SignalWatcher(WithDisposable(ShadowlessElement)) { } `; - private _clickDragHandler = () => { + private readonly _clickDragHandler = () => { if (this.view.readonly$.value) { return; } diff --git a/blocksuite/affine/data-view/src/view-presets/table/table-view-manager.ts b/blocksuite/affine/data-view/src/view-presets/table/table-view-manager.ts index 6b34fdb89dbab..1c2f7da0ee671 100644 --- a/blocksuite/affine/data-view/src/view-presets/table/table-view-manager.ts +++ b/blocksuite/affine/data-view/src/view-presets/table/table-view-manager.ts @@ -39,7 +39,7 @@ export class TableSingleView extends SingleViewBase { return result; }); - private computedColumns$ = computed(() => { + private readonly computedColumns$ = computed(() => { return this.propertiesWithoutFilter$.value.map(id => { const column = this.propertyGet(id); return { @@ -51,19 +51,19 @@ export class TableSingleView extends SingleViewBase { }); }); - private filter$ = computed(() => { + private readonly filter$ = computed(() => { return this.data$.value?.filter ?? emptyFilterGroup; }); - private groupBy$ = computed(() => { + private readonly groupBy$ = computed(() => { return this.data$.value?.groupBy; }); - private sortList$ = computed(() => { + private readonly sortList$ = computed(() => { return this.data$.value?.sort; }); - private sortManager = this.traitSet( + private readonly sortManager = this.traitSet( sortTraitKey, new SortManager(this.sortList$, this, { setSortList: sortList => { @@ -385,7 +385,7 @@ export class TableColumn extends PropertyBase { } constructor( - private tableView: TableSingleView, + private readonly tableView: TableSingleView, columnId: string ) { super(tableView as SingleView, columnId); diff --git a/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/condition-view.ts b/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/condition-view.ts index d835c78d8ab72..ccc9717a4190d 100644 --- a/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/condition-view.ts +++ b/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/condition-view.ts @@ -82,13 +82,13 @@ export class FilterConditionView extends SignalWatcher(ShadowlessElement) { } `; - private onClickButton = (evt: Event) => { + private readonly onClickButton = (evt: Event) => { this.popConditionEdit( popupTargetFromElement(evt.currentTarget as HTMLElement) ); }; - private popConditionEdit = (target: PopupTarget) => { + private readonly popConditionEdit = (target: PopupTarget) => { const type = this.leftVar$.value?.type; if (!type) { return; diff --git a/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/group-panel-view.ts b/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/group-panel-view.ts index 2b7312126d114..db4bda2b344c8 100644 --- a/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/group-panel-view.ts +++ b/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/group-panel-view.ts @@ -184,7 +184,7 @@ export class FilterGroupView extends SignalWatcher(ShadowlessElement) { } `; - private _addNew = (e: MouseEvent) => { + private readonly _addNew = (e: MouseEvent) => { if (this.isMaxDepth) { this.onChange({ ...this.filterGroup.value, @@ -202,7 +202,7 @@ export class FilterGroupView extends SignalWatcher(ShadowlessElement) { }); }; - private _selectOp = (event: MouseEvent) => { + private readonly _selectOp = (event: MouseEvent) => { popFilterableSimpleMenu( popupTargetFromElement(event.currentTarget as HTMLElement), [ @@ -228,7 +228,7 @@ export class FilterGroupView extends SignalWatcher(ShadowlessElement) { ); }; - private _setFilter = (index: number, filter: Filter) => { + private readonly _setFilter = (index: number, filter: Filter) => { this.onChange({ ...this.filterGroup.value, conditions: this.filterGroup.value.conditions.map((v, i) => @@ -237,7 +237,7 @@ export class FilterGroupView extends SignalWatcher(ShadowlessElement) { }); }; - private opMap = { + private readonly opMap = { and: 'And', or: 'Or', }; diff --git a/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/list-view.ts b/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/list-view.ts index 412fba0a0b9c6..97741b0a2ce25 100644 --- a/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/list-view.ts +++ b/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/list-view.ts @@ -77,7 +77,7 @@ export class FilterBar extends SignalWatcher(ShadowlessElement) { } `; - private _setFilter = (index: number, filter: Filter) => { + private readonly _setFilter = (index: number, filter: Filter) => { this.onChange({ ...this.filterGroup.value, conditions: this.filterGroup.value.conditions.map((v, i) => @@ -86,7 +86,7 @@ export class FilterBar extends SignalWatcher(ShadowlessElement) { }); }; - private addFilter = (e: MouseEvent) => { + private readonly addFilter = (e: MouseEvent) => { const element = popupTargetFromElement(e.target as HTMLElement); popCreateFilter(element, { vars: this.vars, @@ -103,7 +103,7 @@ export class FilterBar extends SignalWatcher(ShadowlessElement) { }); }; - private expandGroup = (position: PopupTarget, i: number) => { + private readonly expandGroup = (position: PopupTarget, i: number) => { if (this.filterGroup.value.conditions[i]?.type !== 'group') { return; } diff --git a/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/root-panel-view.ts b/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/root-panel-view.ts index 5e89c10b73b2f..083f80e96cab2 100644 --- a/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/root-panel-view.ts +++ b/blocksuite/affine/data-view/src/widget-presets/quick-setting-bar/filter/root-panel-view.ts @@ -158,7 +158,7 @@ export class FilterRootView extends SignalWatcher(ShadowlessElement) { } `; - private _setFilter = (index: number, filter: Filter) => { + private readonly _setFilter = (index: number, filter: Filter) => { this.onChange({ ...this.filterGroup.value, conditions: this.filterGroup.value.conditions.map((v, i) => @@ -167,7 +167,7 @@ export class FilterRootView extends SignalWatcher(ShadowlessElement) { }); }; - private expandGroup = (position: PopupTarget, i: number) => { + private readonly expandGroup = (position: PopupTarget, i: number) => { if (this.filterGroup.value.conditions[i]?.type !== 'group') { return; } diff --git a/blocksuite/affine/data-view/src/widget-presets/tools/presets/search/search.ts b/blocksuite/affine/data-view/src/widget-presets/tools/presets/search/search.ts index e7b2d8991a3ab..ed751f1abd7aa 100644 --- a/blocksuite/affine/data-view/src/widget-presets/tools/presets/search/search.ts +++ b/blocksuite/affine/data-view/src/widget-presets/tools/presets/search/search.ts @@ -93,7 +93,7 @@ export class DataViewHeaderToolsSearch extends WidgetBase< > { static override styles = styles; - private _clearSearch = () => { + private readonly _clearSearch = () => { this._searchInput.value = ''; this.view.setSearch(''); this.preventBlur = true; @@ -102,25 +102,25 @@ export class DataViewHeaderToolsSearch extends WidgetBase< }); }; - private _clickSearch = (e: MouseEvent) => { + private readonly _clickSearch = (e: MouseEvent) => { e.stopPropagation(); this.showSearch = true; }; - private _onSearch = (event: InputEvent) => { + private readonly _onSearch = (event: InputEvent) => { const el = event.target as HTMLInputElement; const inputValue = el.value.trim(); this.view.setSearch(inputValue); }; - private _onSearchBlur = () => { + private readonly _onSearchBlur = () => { if (this._searchInput.value || this.preventBlur) { return; } this.showSearch = false; }; - private _onSearchKeydown = (event: KeyboardEvent) => { + private readonly _onSearchKeydown = (event: KeyboardEvent) => { if (event.key === 'Escape') { if (this._searchInput.value) { this._searchInput.value = ''; diff --git a/blocksuite/affine/data-view/src/widget-presets/tools/presets/table-add-row/add-row.ts b/blocksuite/affine/data-view/src/widget-presets/tools/presets/table-add-row/add-row.ts index 159ad672525a7..01577e0c5c572 100644 --- a/blocksuite/affine/data-view/src/widget-presets/tools/presets/table-add-row/add-row.ts +++ b/blocksuite/affine/data-view/src/widget-presets/tools/presets/table-add-row/add-row.ts @@ -19,7 +19,7 @@ const styles = css` export class DataViewHeaderToolsAddRow extends WidgetBase { static override styles = styles; - private _onAddNewRecord = () => { + private readonly _onAddNewRecord = () => { if (this.readonly) return; this.viewMethods.addRow?.('start'); }; diff --git a/blocksuite/affine/model/src/elements/mindmap/mindmap.ts b/blocksuite/affine/model/src/elements/mindmap/mindmap.ts index 8316b0abf5f76..9be393e3c511e 100644 --- a/blocksuite/affine/model/src/elements/mindmap/mindmap.ts +++ b/blocksuite/affine/model/src/elements/mindmap/mindmap.ts @@ -151,7 +151,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel(); + private readonly _stashedNode = new Set(); private _tree!: MindmapRoot; diff --git a/blocksuite/affine/model/src/elements/mindmap/style.ts b/blocksuite/affine/model/src/elements/mindmap/style.ts index 3c72c03c8ad23..08e88aed41d25 100644 --- a/blocksuite/affine/model/src/elements/mindmap/style.ts +++ b/blocksuite/affine/model/src/elements/mindmap/style.ts @@ -77,7 +77,7 @@ export abstract class MindmapStyleGetter { } export class StyleOne extends MindmapStyleGetter { - private _colorOrders = [ + private readonly _colorOrders = [ LineColor.Purple, LineColor.Magenta, LineColor.Orange, @@ -188,7 +188,7 @@ export class StyleOne extends MindmapStyleGetter { export const styleOne = new StyleOne(); export class StyleTwo extends MindmapStyleGetter { - private _colorOrders = [ + private readonly _colorOrders = [ ShapeFillColor.Blue, '#7ae2d5', ShapeFillColor.Yellow, @@ -298,7 +298,11 @@ export class StyleTwo extends MindmapStyleGetter { export const styleTwo = new StyleTwo(); export class StyleThree extends MindmapStyleGetter { - private _strokeColor = [LineColor.Yellow, LineColor.Green, LineColor.Teal]; + private readonly _strokeColor = [ + LineColor.Yellow, + LineColor.Green, + LineColor.Teal, + ]; readonly root = { radius: 10, @@ -402,7 +406,7 @@ export class StyleThree extends MindmapStyleGetter { export const styleThree = new StyleThree(); export class StyleFour extends MindmapStyleGetter { - private _colors = [ + private readonly _colors = [ ShapeFillColor.Purple, ShapeFillColor.Magenta, ShapeFillColor.Orange, diff --git a/blocksuite/affine/shared/src/services/edit-props-store.ts b/blocksuite/affine/shared/src/services/edit-props-store.ts index d5353723408f1..9c083adbac160 100644 --- a/blocksuite/affine/shared/src/services/edit-props-store.ts +++ b/blocksuite/affine/shared/src/services/edit-props-store.ts @@ -78,9 +78,9 @@ function customizer(_target: unknown, source: unknown) { export class EditPropsStore extends LifeCycleWatcher { static override key = 'EditPropsStore'; - private _disposables = new DisposableGroup(); + private readonly _disposables = new DisposableGroup(); - private innerProps$: Signal> = signal({}); + private readonly innerProps$: Signal> = signal({}); lastProps$: Signal; diff --git a/blocksuite/affine/shared/src/services/embed-option-service.ts b/blocksuite/affine/shared/src/services/embed-option-service.ts index 356a5659c2eb0..3762a99e21f43 100644 --- a/blocksuite/affine/shared/src/services/embed-option-service.ts +++ b/blocksuite/affine/shared/src/services/embed-option-service.ts @@ -23,7 +23,7 @@ export class EmbedOptionService extends Extension implements EmbedOptionProvider { - private _embedBlockRegistry = new Set(); + private readonly _embedBlockRegistry = new Set(); getEmbedBlockOptions = (url: string): EmbedOptions | null => { const entries = this._embedBlockRegistry.entries(); diff --git a/blocksuite/affine/shared/src/services/theme-service.ts b/blocksuite/affine/shared/src/services/theme-service.ts index 734ea3164bb02..5c789f74c4b9f 100644 --- a/blocksuite/affine/shared/src/services/theme-service.ts +++ b/blocksuite/affine/shared/src/services/theme-service.ts @@ -61,7 +61,7 @@ export class ThemeService extends Extension { return isInsideEdgelessEditor(this.std.host) ? this.edgeless$ : this.app$; } - constructor(private std: BlockStdScope) { + constructor(private readonly std: BlockStdScope) { super(); const extension = this.std.getOptional(ThemeExtensionIdentifier); this.app$ = extension?.getAppTheme?.() || getThemeObserver().theme$; @@ -172,7 +172,7 @@ export class ThemeService extends Extension { } export class ThemeObserver { - private observer: MutationObserver; + private readonly observer: MutationObserver; theme$ = signal(ColorScheme.Light); diff --git a/blocksuite/affine/shared/src/utils/spec/spec-provider.ts b/blocksuite/affine/shared/src/utils/spec/spec-provider.ts index ac635db1d1f30..d81b4363b6377 100644 --- a/blocksuite/affine/shared/src/utils/spec/spec-provider.ts +++ b/blocksuite/affine/shared/src/utils/spec/spec-provider.ts @@ -6,7 +6,7 @@ import { SpecBuilder } from './spec-builder.js'; export class SpecProvider { static instance: SpecProvider; - private specMap = new Map(); + private readonly specMap = new Map(); private constructor() {} diff --git a/blocksuite/affine/widget-scroll-anchoring/src/scroll-anchoring.ts b/blocksuite/affine/widget-scroll-anchoring/src/scroll-anchoring.ts index 432576be3ace0..e96632eadb197 100644 --- a/blocksuite/affine/widget-scroll-anchoring/src/scroll-anchoring.ts +++ b/blocksuite/affine/widget-scroll-anchoring/src/scroll-anchoring.ts @@ -54,9 +54,11 @@ export class AffineScrollAnchoringWidget extends WidgetComponent { #listened = false; - #requestUpdateFn = () => this.requestUpdate(); + readonly #requestUpdateFn = () => this.requestUpdate(); - #resizeObserver: ResizeObserver = new ResizeObserver(this.#requestUpdateFn); + readonly #resizeObserver: ResizeObserver = new ResizeObserver( + this.#requestUpdateFn + ); anchor$ = signal(null); diff --git a/blocksuite/blocks/src/_common/adapters/html-adapter/html.ts b/blocksuite/blocks/src/_common/adapters/html-adapter/html.ts index 373e5b2e00374..6c77f8054d200 100644 --- a/blocksuite/blocks/src/_common/adapters/html-adapter/html.ts +++ b/blocksuite/blocks/src/_common/adapters/html-adapter/html.ts @@ -51,11 +51,11 @@ type HtmlToSliceSnapshotPayload = { }; export class HtmlAdapter extends BaseAdapter { - private _astToHtml = (ast: Root) => { + private readonly _astToHtml = (ast: Root) => { return unified().use(rehypeStringify).stringify(ast); }; - private _traverseHtml = async ( + private readonly _traverseHtml = async ( html: HtmlAST, snapshot: BlockSnapshot, assets?: AssetsManager @@ -108,7 +108,7 @@ export class HtmlAdapter extends BaseAdapter { return walker.walk(html, snapshot); }; - private _traverseSnapshot = async ( + private readonly _traverseSnapshot = async ( snapshot: BlockSnapshot, html: HtmlAST, assets?: AssetsManager diff --git a/blocksuite/blocks/src/_common/adapters/markdown/markdown.ts b/blocksuite/blocks/src/_common/adapters/markdown/markdown.ts index 1a0acba7bcdf0..36805f19f08b1 100644 --- a/blocksuite/blocks/src/_common/adapters/markdown/markdown.ts +++ b/blocksuite/blocks/src/_common/adapters/markdown/markdown.ts @@ -50,7 +50,7 @@ type MarkdownToSliceSnapshotPayload = { }; export class MarkdownAdapter extends BaseAdapter { - private _traverseMarkdown = ( + private readonly _traverseMarkdown = ( markdown: MarkdownAST, snapshot: BlockSnapshot, assets?: AssetsManager @@ -105,7 +105,7 @@ export class MarkdownAdapter extends BaseAdapter { return walker.walk(markdown, snapshot); }; - private _traverseSnapshot = async ( + private readonly _traverseSnapshot = async ( snapshot: BlockSnapshot, markdown: MarkdownAST, assets?: AssetsManager diff --git a/blocksuite/blocks/src/_common/adapters/mix-text.ts b/blocksuite/blocks/src/_common/adapters/mix-text.ts index a1aa791acfa31..f082fa742940b 100644 --- a/blocksuite/blocks/src/_common/adapters/mix-text.ts +++ b/blocksuite/blocks/src/_common/adapters/mix-text.ts @@ -38,7 +38,7 @@ type MixTextToSliceSnapshotPayload = { }; export class MixTextAdapter extends BaseAdapter { - private _markdownAdapter: MarkdownAdapter; + private readonly _markdownAdapter: MarkdownAdapter; constructor(job: Job) { super(job); diff --git a/blocksuite/blocks/src/_common/adapters/notion-html/notion-html.ts b/blocksuite/blocks/src/_common/adapters/notion-html/notion-html.ts index 6f34641b3ef9a..885da785cc619 100644 --- a/blocksuite/blocks/src/_common/adapters/notion-html/notion-html.ts +++ b/blocksuite/blocks/src/_common/adapters/notion-html/notion-html.ts @@ -54,7 +54,7 @@ type NotionHtmlToDocSnapshotPayload = { type NotionHtmlToBlockSnapshotPayload = NotionHtmlToDocSnapshotPayload; export class NotionHtmlAdapter extends BaseAdapter { - private _traverseNotionHtml = async ( + private readonly _traverseNotionHtml = async ( html: HtmlAST, snapshot: BlockSnapshot, assets?: AssetsManager, diff --git a/blocksuite/blocks/src/_common/components/ai-item/ai-item-list.ts b/blocksuite/blocks/src/_common/components/ai-item/ai-item-list.ts index 75c3e717fe156..e76a82454da61 100644 --- a/blocksuite/blocks/src/_common/components/ai-item/ai-item-list.ts +++ b/blocksuite/blocks/src/_common/components/ai-item/ai-item-list.ts @@ -48,7 +48,7 @@ export class AIItemList extends WithDisposable(LitElement) { private _activeSubMenuItem: AIItemConfig | null = null; - private _closeSubMenu = () => { + private readonly _closeSubMenu = () => { if (this._abortController) { this._abortController.abort(); this._abortController = null; @@ -56,11 +56,11 @@ export class AIItemList extends WithDisposable(LitElement) { this._activeSubMenuItem = null; }; - private _itemClassName = (item: AIItemConfig) => { + private readonly _itemClassName = (item: AIItemConfig) => { return 'ai-item-' + item.name.split(' ').join('-').toLocaleLowerCase(); }; - private _openSubMenu = (item: AIItemConfig) => { + private readonly _openSubMenu = (item: AIItemConfig) => { if (!item.subItem || item.subItem.length === 0) { this._closeSubMenu(); return; diff --git a/blocksuite/blocks/src/_common/components/ai-item/ai-sub-item-list.ts b/blocksuite/blocks/src/_common/components/ai-item/ai-sub-item-list.ts index fc62784dcb172..4be353ac18174 100644 --- a/blocksuite/blocks/src/_common/components/ai-item/ai-sub-item-list.ts +++ b/blocksuite/blocks/src/_common/components/ai-item/ai-sub-item-list.ts @@ -45,7 +45,7 @@ export class AISubItemList extends WithDisposable(LitElement) { ${menuItemStyles} `; - private _handleClick = (subItem: AISubItemConfig) => { + private readonly _handleClick = (subItem: AISubItemConfig) => { this.onClick?.(); if (subItem.handler) { // TODO: add parameters to ai handler diff --git a/blocksuite/blocks/src/_common/components/embed-card/modal/embed-card-create-modal.ts b/blocksuite/blocks/src/_common/components/embed-card/modal/embed-card-create-modal.ts index 54da070ca63d1..014ad07abdf58 100644 --- a/blocksuite/blocks/src/_common/components/embed-card/modal/embed-card-create-modal.ts +++ b/blocksuite/blocks/src/_common/components/embed-card/modal/embed-card-create-modal.ts @@ -22,11 +22,11 @@ import { embedCardModalStyles } from './styles.js'; export class EmbedCardCreateModal extends WithDisposable(ShadowlessElement) { static override styles = embedCardModalStyles; - private _onCancel = () => { + private readonly _onCancel = () => { this.remove(); }; - private _onConfirm = () => { + private readonly _onConfirm = () => { const url = this.input.value; if (!isValidUrl(url)) { @@ -91,7 +91,7 @@ export class EmbedCardCreateModal extends WithDisposable(ShadowlessElement) { this.remove(); }; - private _onDocumentKeydown = (e: KeyboardEvent) => { + private readonly _onDocumentKeydown = (e: KeyboardEvent) => { e.stopPropagation(); if (e.key === 'Enter' && !e.isComposing) { this._onConfirm(); diff --git a/blocksuite/blocks/src/_common/components/embed-card/modal/embed-card-edit-modal.ts b/blocksuite/blocks/src/_common/components/embed-card/modal/embed-card-edit-modal.ts index c4639d0ba4ebd..2bdc565ed3c50 100644 --- a/blocksuite/blocks/src/_common/components/embed-card/modal/embed-card-edit-modal.ts +++ b/blocksuite/blocks/src/_common/components/embed-card/modal/embed-card-edit-modal.ts @@ -144,11 +144,11 @@ export class EmbedCardEditModal extends SignalWatcher( private _blockComponent: BlockComponent | null = null; - private _hide = () => { + private readonly _hide = () => { this.remove(); }; - private _onKeydown = (e: KeyboardEvent) => { + private readonly _onKeydown = (e: KeyboardEvent) => { e.stopPropagation(); if (e.key === 'Enter' && !(e.isComposing || e.shiftKey)) { this._onSave(); @@ -159,7 +159,7 @@ export class EmbedCardEditModal extends SignalWatcher( } }; - private _onReset = () => { + private readonly _onReset = () => { const blockComponent = this._blockComponent; if (!blockComponent) { @@ -186,7 +186,7 @@ export class EmbedCardEditModal extends SignalWatcher( this.remove(); }; - private _onSave = () => { + private readonly _onSave = () => { const blockComponent = this._blockComponent; if (!blockComponent) { @@ -224,12 +224,12 @@ export class EmbedCardEditModal extends SignalWatcher( this.remove(); }; - private _updateDescription = (e: InputEvent) => { + private readonly _updateDescription = (e: InputEvent) => { const target = e.target as HTMLTextAreaElement; this.description$.value = target.value; }; - private _updateTitle = (e: InputEvent) => { + private readonly _updateTitle = (e: InputEvent) => { const target = e.target as HTMLInputElement; this.title$.value = target.value; }; diff --git a/blocksuite/blocks/src/_common/components/file-drop-manager.ts b/blocksuite/blocks/src/_common/components/file-drop-manager.ts index 1acb9b24e997e..07d515c8310fd 100644 --- a/blocksuite/blocks/src/_common/components/file-drop-manager.ts +++ b/blocksuite/blocks/src/_common/components/file-drop-manager.ts @@ -31,13 +31,13 @@ export type FileDropOptions = { export class FileDropManager { private static _dropResult: DropResult | null = null; - private _blockService: BlockService; + private readonly _blockService: BlockService; - private _fileDropOptions: FileDropOptions; + private readonly _fileDropOptions: FileDropOptions; - private _indicator!: DragIndicator; + private readonly _indicator!: DragIndicator; - private _onDrop = (event: DragEvent) => { + private readonly _onDrop = (event: DragEvent) => { this._indicator.rect = null; const { onDrop } = this._fileDropOptions; diff --git a/blocksuite/blocks/src/_common/components/smooth-corner.ts b/blocksuite/blocks/src/_common/components/smooth-corner.ts index 803237d47101e..71ffde7bdb79f 100644 --- a/blocksuite/blocks/src/_common/components/smooth-corner.ts +++ b/blocksuite/blocks/src/_common/components/smooth-corner.ts @@ -64,7 +64,7 @@ export class SmoothCorner extends LitElement { } `; - private _resizeObserver: ResizeObserver | null = null; + private readonly _resizeObserver: ResizeObserver | null = null; get _path() { return getFigmaSquircleSvgPath({ diff --git a/blocksuite/blocks/src/_common/configs/quick-action/config.ts b/blocksuite/blocks/src/_common/configs/quick-action/config.ts index 1c9f408071edc..dacc63414361a 100644 --- a/blocksuite/blocks/src/_common/configs/quick-action/config.ts +++ b/blocksuite/blocks/src/_common/configs/quick-action/config.ts @@ -137,16 +137,18 @@ export const quickActionConfig: QuickActionConfig[] = [ const doc = host.doc; const autofill = getTitleFromSelectedModels(selectedModels); - void promptDocTitle(host, autofill).then(title => { - if (title === null) return; - convertSelectedBlocksToLinkedDoc( - host.std, - doc, - draftedModels, - title - ).catch(console.error); - notifyDocCreated(host, doc); - }); + promptDocTitle(host, autofill) + .then(title => { + if (title === null) return; + convertSelectedBlocksToLinkedDoc( + host.std, + doc, + draftedModels, + title + ).catch(console.error); + notifyDocCreated(host, doc); + }) + .catch(console.error); }, }, ]; diff --git a/blocksuite/blocks/src/_common/export-manager/export-manager.ts b/blocksuite/blocks/src/_common/export-manager/export-manager.ts index b5b2bfabd618d..a22f4f522dfeb 100644 --- a/blocksuite/blocks/src/_common/export-manager/export-manager.ts +++ b/blocksuite/blocks/src/_common/export-manager/export-manager.ts @@ -44,11 +44,11 @@ export type ExportOptions = { imageProxyEndpoint: string; }; export class ExportManager { - private _exportOptions: ExportOptions = { + private readonly _exportOptions: ExportOptions = { imageProxyEndpoint: DEFAULT_IMAGE_PROXY_ENDPOINT, }; - private _replaceRichTextWithSvgElement = (element: HTMLElement) => { + private readonly _replaceRichTextWithSvgElement = (element: HTMLElement) => { const richList = Array.from(element.querySelectorAll('.inline-editor')); richList.forEach(rich => { const svgEle = this._elementToSvgElement( diff --git a/blocksuite/blocks/src/_common/transformers/utils.ts b/blocksuite/blocks/src/_common/transformers/utils.ts index cf3256156398c..1c8cd19b5bc01 100644 --- a/blocksuite/blocks/src/_common/transformers/utils.ts +++ b/blocksuite/blocks/src/_common/transformers/utils.ts @@ -8,7 +8,7 @@ export class Zip { private finalized = false; - private zip = new fflate.Zip((err, chunk, final) => { + private readonly zip = new fflate.Zip((err, chunk, final) => { if (!err) { const temp = new Uint8Array(this.compressed.length + chunk.length); temp.set(this.compressed); diff --git a/blocksuite/blocks/src/attachment-block/attachment-service.ts b/blocksuite/blocks/src/attachment-block/attachment-service.ts index 3e01be68fd18f..d4d7ec14ef7a2 100644 --- a/blocksuite/blocks/src/attachment-block/attachment-service.ts +++ b/blocksuite/blocks/src/attachment-block/attachment-service.ts @@ -26,7 +26,7 @@ import { addSiblingAttachmentBlocks } from './utils.js'; export class AttachmentBlockService extends BlockService { static override readonly flavour = AttachmentBlockSchema.model.flavour; - private _fileDropOptions: FileDropOptions = { + private readonly _fileDropOptions: FileDropOptions = { flavour: this.flavour, onDrop: async ({ files, targetModel, place, point }) => { if (!files.length) return false; diff --git a/blocksuite/blocks/src/attachment-block/embed.ts b/blocksuite/blocks/src/attachment-block/embed.ts index 3eb19541ac1af..2f5d492e16f68 100644 --- a/blocksuite/blocks/src/attachment-block/embed.ts +++ b/blocksuite/blocks/src/attachment-block/embed.ts @@ -67,7 +67,7 @@ export class AttachmentEmbedService extends Extension { return this.configs.values(); } - constructor(private configs: Map) { + constructor(private readonly configs: Map) { super(); } diff --git a/blocksuite/blocks/src/data-view-block/data-source.ts b/blocksuite/blocks/src/data-view-block/data-source.ts index 1a6ee03831147..cd337f5d3de70 100644 --- a/blocksuite/blocks/src/data-view-block/data-source.ts +++ b/blocksuite/blocks/src/data-view-block/data-source.ts @@ -24,9 +24,12 @@ export type BlockQueryDataSourceConfig = { // @ts-expect-error FIXME: ts error export class BlockQueryDataSource extends DataSourceBase { - private columnMetaMap = new Map>(); + private readonly columnMetaMap = new Map< + string, + PropertyMetaConfig + >(); - private meta: BlockMeta; + private readonly meta: BlockMeta; blockMap = new Map(); @@ -60,8 +63,8 @@ export class BlockQueryDataSource extends DataSourceBase { } constructor( - private host: EditorHost, - private block: DataViewBlockModel, + private readonly host: EditorHost, + private readonly block: DataViewBlockModel, config: BlockQueryDataSourceConfig ) { super(); diff --git a/blocksuite/blocks/src/data-view-block/data-view-block.ts b/blocksuite/blocks/src/data-view-block/data-view-block.ts index 3135d5347eb3a..6c14a174cc2dc 100644 --- a/blocksuite/blocks/src/data-view-block/data-view-block.ts +++ b/blocksuite/blocks/src/data-view-block/data-view-block.ts @@ -92,7 +92,7 @@ export class DataViewBlockComponent extends CaptionedBlockComponent { + private readonly _clickDatabaseOps = (e: MouseEvent) => { popMenu(popupTargetFromElement(e.currentTarget as HTMLElement), { options: { items: [ @@ -136,7 +136,7 @@ export class DataViewBlockComponent extends CaptionedBlockComponent { return { diff --git a/blocksuite/blocks/src/database-block/components/title/index.ts b/blocksuite/blocks/src/database-block/components/title/index.ts index 67eeb70a907ef..b71bbb9b94a9d 100644 --- a/blocksuite/blocks/src/database-block/components/title/index.ts +++ b/blocksuite/blocks/src/database-block/components/title/index.ts @@ -70,29 +70,29 @@ export class DatabaseTitle extends WithDisposable(ShadowlessElement) { } `; - private compositionEnd = () => { + private readonly compositionEnd = () => { this.titleText.replace(0, this.titleText.length, this.input.value); }; - private onBlur = () => { + private readonly onBlur = () => { this.isFocus = false; }; - private onFocus = () => { + private readonly onFocus = () => { this.isFocus = true; if (this.database?.viewSelection$?.value) { this.database?.setSelection(undefined); } }; - private onInput = (e: InputEvent) => { + private readonly onInput = (e: InputEvent) => { this.text = this.input.value; if (!e.isComposing) { this.titleText.replace(0, this.titleText.length, this.input.value); } }; - private onKeyDown = (event: KeyboardEvent) => { + private readonly onKeyDown = (event: KeyboardEvent) => { event.stopPropagation(); if (event.key === 'Enter' && !event.isComposing) { event.preventDefault(); diff --git a/blocksuite/blocks/src/database-block/database-block.ts b/blocksuite/blocks/src/database-block/database-block.ts index b649c16880ff2..cd1fe8d5a13f1 100644 --- a/blocksuite/blocks/src/database-block/database-block.ts +++ b/blocksuite/blocks/src/database-block/database-block.ts @@ -106,7 +106,7 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent< } `; - private _clickDatabaseOps = (e: MouseEvent) => { + private readonly _clickDatabaseOps = (e: MouseEvent) => { const options = this.optionsConfig.configure(this.model, { items: [ menu.input({ @@ -156,9 +156,9 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent< private _dataSource?: DatabaseBlockDataSource; - private dataView = new DataView(); + private readonly dataView = new DataView(); - private renderTitle = (dataViewMethod: DataViewInstance) => { + private readonly renderTitle = (dataViewMethod: DataViewInstance) => { const addRow = () => dataViewMethod.addRow?.('start'); return html` { } `; - private _onClick = (event: Event) => { + private readonly _onClick = (event: Event) => { event.stopPropagation(); const value = this.value ?? ''; @@ -102,7 +102,7 @@ export class LinkCell extends BaseCellRenderer { } }; - private _onEdit = (e: Event) => { + private readonly _onEdit = (e: Event) => { e.stopPropagation(); this.selectCurrentCell(true); }; @@ -199,13 +199,13 @@ export class LinkCellEditing extends BaseCellRenderer { } `; - private _focusEnd = () => { + private readonly _focusEnd = () => { const end = this._container.value.length; this._container.focus(); this._container.setSelectionRange(end, end); }; - private _onKeydown = (e: KeyboardEvent) => { + private readonly _onKeydown = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.isComposing) { this._setValue(); setTimeout(() => { @@ -214,7 +214,7 @@ export class LinkCellEditing extends BaseCellRenderer { } }; - private _setValue = (value: string = this._container.value) => { + private readonly _setValue = (value: string = this._container.value) => { let url = value; if (isValidUrl(value)) { url = normalizeUrl(value); diff --git a/blocksuite/blocks/src/database-block/properties/rich-text/cell-renderer.ts b/blocksuite/blocks/src/database-block/properties/rich-text/cell-renderer.ts index be5809fbe5472..eac5cbff52360 100644 --- a/blocksuite/blocks/src/database-block/properties/rich-text/cell-renderer.ts +++ b/blocksuite/blocks/src/database-block/properties/rich-text/cell-renderer.ts @@ -205,7 +205,7 @@ export class RichTextCellEditing extends BaseCellRenderer { } `; - private _handleKeyDown = (event: KeyboardEvent) => { + private readonly _handleKeyDown = (event: KeyboardEvent) => { if (event.key !== 'Escape') { if (event.key === 'Tab') { event.preventDefault(); @@ -274,12 +274,12 @@ export class RichTextCellEditing extends BaseCellRenderer { } }; - private _initYText = (text?: string) => { + private readonly _initYText = (text?: string) => { const yText = new Text(text); this.onChange(yText); }; - private _onSoftEnter = () => { + private readonly _onSoftEnter = () => { if (this.value && this.inlineEditor) { const inlineRange = this.inlineEditor.getInlineRange(); assertExists(inlineRange); diff --git a/blocksuite/blocks/src/database-block/properties/title/text.ts b/blocksuite/blocks/src/database-block/properties/title/text.ts index 00345d32fbf52..2e74c82cca677 100644 --- a/blocksuite/blocks/src/database-block/properties/title/text.ts +++ b/blocksuite/blocks/src/database-block/properties/title/text.ts @@ -205,7 +205,7 @@ export class HeaderAreaTextCell extends BaseTextCell { } export class HeaderAreaTextCellEditing extends BaseTextCell { - private _onCopy = (e: ClipboardEvent) => { + private readonly _onCopy = (e: ClipboardEvent) => { const inlineEditor = this.inlineEditor; assertExists(inlineEditor); @@ -222,7 +222,7 @@ export class HeaderAreaTextCellEditing extends BaseTextCell { e.stopPropagation(); }; - private _onCut = (e: ClipboardEvent) => { + private readonly _onCut = (e: ClipboardEvent) => { const inlineEditor = this.inlineEditor; assertExists(inlineEditor); @@ -244,7 +244,7 @@ export class HeaderAreaTextCellEditing extends BaseTextCell { e.stopPropagation(); }; - private _onPaste = (e: ClipboardEvent) => { + private readonly _onPaste = (e: ClipboardEvent) => { const inlineEditor = this.inlineEditor; const inlineRange = inlineEditor?.getInlineRange(); if (!inlineRange) return; diff --git a/blocksuite/blocks/src/edgeless-text-block/edgeless-text-block.ts b/blocksuite/blocks/src/edgeless-text-block/edgeless-text-block.ts index ed041542eb1f6..a6c82d4624041 100644 --- a/blocksuite/blocks/src/edgeless-text-block/edgeless-text-block.ts +++ b/blocksuite/blocks/src/edgeless-text-block/edgeless-text-block.ts @@ -31,7 +31,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent { + private readonly _resizeObserver = new ResizeObserver(() => { if (this.doc.readonly) { return; } diff --git a/blocksuite/blocks/src/image-block/image-service.ts b/blocksuite/blocks/src/image-block/image-service.ts index 90a91e952a825..f4c8f5d67c388 100644 --- a/blocksuite/blocks/src/image-block/image-service.ts +++ b/blocksuite/blocks/src/image-block/image-service.ts @@ -28,7 +28,7 @@ export class ImageBlockService extends BlockService { static setImageProxyURL = setImageProxyMiddlewareURL; - private _fileDropOptions: FileDropOptions = { + private readonly _fileDropOptions: FileDropOptions = { flavour: this.flavour, onDrop: async ({ files, targetModel, place, point }) => { const imageFiles = files.filter(file => file.type.startsWith('image/')); diff --git a/blocksuite/blocks/src/note-block/note-service.ts b/blocksuite/blocks/src/note-block/note-service.ts index 90651284a538e..a18dfcc9f0cdc 100644 --- a/blocksuite/blocks/src/note-block/note-service.ts +++ b/blocksuite/blocks/src/note-block/note-service.ts @@ -22,7 +22,7 @@ export class NoteBlockService extends BlockService { private _anchorSel: BlockSelection | null = null; - private _bindMoveBlockHotKey = () => { + private readonly _bindMoveBlockHotKey = () => { return moveBlockConfigs.reduce( (acc, config) => { const keys = config.hotkey.reduce( @@ -46,7 +46,7 @@ export class NoteBlockService extends BlockService { ); }; - private _bindQuickActionHotKey = () => { + private readonly _bindQuickActionHotKey = () => { return quickActionConfig .filter(config => config.hotkey) .reduce( @@ -65,7 +65,7 @@ export class NoteBlockService extends BlockService { ); }; - private _bindTextConversionHotKey = () => { + private readonly _bindTextConversionHotKey = () => { return textConversionConfigs .filter(item => item.hotkey) .reduce( @@ -131,7 +131,7 @@ export class NoteBlockService extends BlockService { private _focusBlock: BlockComponent | null = null; - private _getClosestNoteByBlockId = (blockId: string) => { + private readonly _getClosestNoteByBlockId = (blockId: string) => { const doc = this._std.doc; let parent = doc.getBlock(blockId)?.model ?? null; while (parent) { @@ -143,7 +143,7 @@ export class NoteBlockService extends BlockService { return null; }; - private _onArrowDown = (ctx: UIEventStateContext) => { + private readonly _onArrowDown = (ctx: UIEventStateContext) => { const event = ctx.get('defaultState').event; const [result] = this._std.command @@ -240,7 +240,7 @@ export class NoteBlockService extends BlockService { return result; }; - private _onArrowUp = (ctx: UIEventStateContext) => { + private readonly _onArrowUp = (ctx: UIEventStateContext) => { const event = ctx.get('defaultState').event; const [result] = this._std.command @@ -336,7 +336,7 @@ export class NoteBlockService extends BlockService { return result; }; - private _onBlockShiftDown = (cmd: BlockSuite.CommandChain) => { + private readonly _onBlockShiftDown = (cmd: BlockSuite.CommandChain) => { return cmd .getBlockSelections() .inline<'currentSelectionPath' | 'anchorBlock'>((ctx, next) => { @@ -376,7 +376,7 @@ export class NoteBlockService extends BlockService { .selectBlocksBetween({ tail: true }); }; - private _onBlockShiftUp = (cmd: BlockSuite.CommandChain) => { + private readonly _onBlockShiftUp = (cmd: BlockSuite.CommandChain) => { return cmd .getBlockSelections() .inline<'currentSelectionPath' | 'anchorBlock'>((ctx, next) => { @@ -414,7 +414,7 @@ export class NoteBlockService extends BlockService { .selectBlocksBetween({ tail: false }); }; - private _onEnter = (ctx: UIEventStateContext) => { + private readonly _onEnter = (ctx: UIEventStateContext) => { const event = ctx.get('defaultState').event; const [result] = this._std.command .chain() @@ -461,7 +461,7 @@ export class NoteBlockService extends BlockService { return result; }; - private _onEsc = () => { + private readonly _onEsc = () => { const [result] = this._std.command .chain() .getBlockSelections() @@ -482,7 +482,7 @@ export class NoteBlockService extends BlockService { return result; }; - private _onSelectAll: UIEventHandler = ctx => { + private readonly _onSelectAll: UIEventHandler = ctx => { const selection = this._std.selection; const block = selection.find('block'); if (!block) { @@ -506,7 +506,7 @@ export class NoteBlockService extends BlockService { }); }; - private _onShiftArrowDown = () => { + private readonly _onShiftArrowDown = () => { const [result] = this._std.command .chain() .try(cmd => [ @@ -518,7 +518,7 @@ export class NoteBlockService extends BlockService { return result; }; - private _onShiftArrowUp = () => { + private readonly _onShiftArrowUp = () => { const [result] = this._std.command .chain() .try(cmd => [ @@ -530,7 +530,7 @@ export class NoteBlockService extends BlockService { return result; }; - private _reset = () => { + private readonly _reset = () => { this._anchorSel = null; this._focusBlock = null; }; diff --git a/blocksuite/blocks/src/root-block/clipboard/index.ts b/blocksuite/blocks/src/root-block/clipboard/index.ts index 1b502bc5e7438..75b7d651d83c2 100644 --- a/blocksuite/blocks/src/root-block/clipboard/index.ts +++ b/blocksuite/blocks/src/root-block/clipboard/index.ts @@ -18,7 +18,7 @@ import { ClipboardAdapter } from './adapter.js'; import { copyMiddleware, pasteMiddleware } from './middlewares/index.js'; export class PageClipboard { - private _copySelected = (onCopy?: () => void) => { + private readonly _copySelected = (onCopy?: () => void) => { return this._std.command .chain() .with({ onCopy }) diff --git a/blocksuite/blocks/src/root-block/clipboard/middlewares/paste.ts b/blocksuite/blocks/src/root-block/clipboard/middlewares/paste.ts index 6160bc1eebedd..ba91e9930beec 100644 --- a/blocksuite/blocks/src/root-block/clipboard/middlewares/paste.ts +++ b/blocksuite/blocks/src/root-block/clipboard/middlewares/paste.ts @@ -57,7 +57,7 @@ const findLast = (snapshot: SliceSnapshot): BlockSnapshot | null => { }; class PointState { - private _blockFromPath = (path: string) => { + private readonly _blockFromPath = (path: string) => { const block = this.std.view.getBlock(path); assertExists(block); return block; @@ -88,7 +88,7 @@ class PointState { } class PasteTr { - private _getDeltas = () => { + private readonly _getDeltas = () => { const firstTextSnapshot = this._textFromSnapshot(this.firstSnapshot!); const lastTextSnapshot = this._textFromSnapshot(this.lastSnapshot!); const fromDelta = this.pointState.text.sliceToDelta( @@ -111,7 +111,7 @@ class PasteTr { }; }; - private _mergeCode = () => { + private readonly _mergeCode = () => { const deltas: DeltaOperation[] = [{ retain: this.pointState.point.index }]; this.snapshot.content.forEach((blockSnapshot, i) => { if (blockSnapshot.props.text) { @@ -126,7 +126,7 @@ class PasteTr { this.snapshot.content = []; }; - private _mergeMultiple = () => { + private readonly _mergeMultiple = () => { this._updateFlavour(); const { lastTextSnapshot, toDelta, firstDelta, lastDelta } = @@ -152,7 +152,7 @@ class PasteTr { lastTextSnapshot.delta = [...lastDelta, ...toDelta]; }; - private _mergeSingle = () => { + private readonly _mergeSingle = () => { this._updateFlavour(); const { firstDelta } = this._getDeltas(); const { index, length } = this.pointState.point; @@ -172,14 +172,14 @@ class PasteTr { this._updateSnapshot(); }; - private _textFromSnapshot = (snapshot: BlockSnapshot) => { + private readonly _textFromSnapshot = (snapshot: BlockSnapshot) => { return (snapshot.props.text ?? { delta: [] }) as Record< 'delta', DeltaOperation[] >; }; - private _updateSnapshot = () => { + private readonly _updateSnapshot = () => { if (this.snapshot.content.length === 0) { this.firstSnapshot = this.lastSnapshot = undefined; return; @@ -192,7 +192,7 @@ class PasteTr { private readonly firstSnapshotIsPlainText: boolean; - private lastIndex: number; + private readonly lastIndex: number; private lastSnapshot?: BlockSnapshot; diff --git a/blocksuite/blocks/src/root-block/edgeless/clipboard/clipboard.ts b/blocksuite/blocks/src/root-block/edgeless/clipboard/clipboard.ts index 506f29c456238..7e491364a1ad7 100644 --- a/blocksuite/blocks/src/root-block/edgeless/clipboard/clipboard.ts +++ b/blocksuite/blocks/src/root-block/edgeless/clipboard/clipboard.ts @@ -123,9 +123,9 @@ interface BlockConfig { } export class EdgelessClipboardController extends PageClipboard { - private _blockConfigs: BlockConfig[] = []; + private readonly _blockConfigs: BlockConfig[] = []; - private _initEdgelessClipboard = () => { + private readonly _initEdgelessClipboard = () => { this.host.handleEvent( 'copy', ctx => { @@ -156,7 +156,7 @@ export class EdgelessClipboardController extends PageClipboard { ); }; - private _onCopy = async ( + private readonly _onCopy = async ( _context: UIEventStateContext, surfaceSelection: SurfaceSelection[] ) => { @@ -184,7 +184,7 @@ export class EdgelessClipboardController extends PageClipboard { }); }; - private _onCut = async (_context: UIEventStateContext) => { + private readonly _onCut = async (_context: UIEventStateContext) => { const { surfaceSelections, selectedElements } = this.selectionManager; if (selectedElements.length === 0) return; @@ -214,7 +214,7 @@ export class EdgelessClipboardController extends PageClipboard { }); }; - private _onPaste = async (_context: UIEventStateContext) => { + private readonly _onPaste = async (_context: UIEventStateContext) => { if ( document.activeElement instanceof HTMLInputElement || document.activeElement instanceof HTMLTextAreaElement diff --git a/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/edgeless-auto-complete.ts b/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/edgeless-auto-complete.ts index 90ffe81c8470e..14acc7b094d13 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/edgeless-auto-complete.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/edgeless-auto-complete.ts @@ -162,7 +162,7 @@ export class EdgelessAutoComplete extends WithDisposable(LitElement) { private _autoCompleteOverlay!: AutoCompleteOverlay; - private _onPointerDown = (e: PointerEvent, type: Direction) => { + private readonly _onPointerDown = (e: PointerEvent, type: Direction) => { const { service } = this.edgeless; const viewportRect = service.viewport.boundingClientRect; const start = service.viewport.toModelCoord( diff --git a/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/utils.ts b/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/utils.ts index 190f57f24a7ad..0b15186381f73 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/utils.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/utils.ts @@ -80,7 +80,7 @@ export class AutoCompleteTextOverlay extends AutoCompleteTargetOverlay { } export class AutoCompleteNoteOverlay extends AutoCompleteTargetOverlay { - private _background: string; + private readonly _background: string; constructor(gfx: GfxController, xywh: XYWH, background: string) { super(gfx, xywh); @@ -110,7 +110,7 @@ export class AutoCompleteNoteOverlay extends AutoCompleteTargetOverlay { } export class AutoCompleteFrameOverlay extends AutoCompleteTargetOverlay { - private _strokeColor; + private readonly _strokeColor; constructor(gfx: GfxController, xywh: XYWH, strokeColor: string) { super(gfx, xywh); @@ -151,7 +151,7 @@ export class AutoCompleteFrameOverlay extends AutoCompleteTargetOverlay { } export class AutoCompleteShapeOverlay extends Overlay { - private _shape: Shape; + private readonly _shape: Shape; constructor( gfx: GfxController, diff --git a/blocksuite/blocks/src/root-block/edgeless/components/color-picker/button.ts b/blocksuite/blocks/src/root-block/edgeless/components/color-picker/button.ts index cb243155cc874..dad904d91bc2c 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/color-picker/button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/color-picker/button.ts @@ -17,7 +17,7 @@ import { keepColor, preprocessColor } from './utils.js'; type Type = 'normal' | 'custom'; export class EdgelessColorPickerButton extends WithDisposable(LitElement) { - #select = (e: ColorEvent) => { + readonly #select = (e: ColorEvent) => { this.#pick({ palette: e.detail }); }; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/color-picker/color-picker.ts b/blocksuite/blocks/src/root-block/edgeless/components/color-picker/color-picker.ts index 1620790d068dd..9e92317922495 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/color-picker/color-picker.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/color-picker/color-picker.ts @@ -49,7 +49,7 @@ export class EdgelessColorPicker extends SignalWatcher( #alphaRect = new DOMRect(); - #editAlpha = (e: InputEvent) => { + readonly #editAlpha = (e: InputEvent) => { const target = e.target as HTMLInputElement; const orignalValue = target.value; let value = orignalValue.trim().replace(/[^0-9]/, ''); @@ -71,7 +71,7 @@ export class EdgelessColorPicker extends SignalWatcher( this.#pick(); }; - #editHex = (e: KeyboardEvent) => { + readonly #editHex = (e: KeyboardEvent) => { e.stopPropagation(); const target = e.target as HTMLInputElement; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/frame/frame-preview.ts b/blocksuite/blocks/src/root-block/edgeless/components/frame/frame-preview.ts index e583a650744d5..374a75dbe0783 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/frame/frame-preview.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/frame/frame-preview.ts @@ -61,12 +61,12 @@ const styles = css` export class FramePreview extends WithDisposable(ShadowlessElement) { static override styles = styles; - private _clearFrameDisposables = () => { + private readonly _clearFrameDisposables = () => { this._frameDisposables?.dispose(); this._frameDisposables = null; }; - private _docFilter: Query = { + private readonly _docFilter: Query = { mode: 'loose', match: [ { @@ -80,9 +80,10 @@ export class FramePreview extends WithDisposable(ShadowlessElement) { private _previewDoc: Doc | null = null; - private _previewSpec = SpecProvider.getInstance().getSpec('edgeless:preview'); + private readonly _previewSpec = + SpecProvider.getInstance().getSpec('edgeless:preview'); - private _updateFrameViewportWH = () => { + private readonly _updateFrameViewportWH = () => { const [, , w, h] = deserializeXYWH(this.frame.xywh); let scale = 1; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/panel/line-width-panel.ts b/blocksuite/blocks/src/root-block/edgeless/components/panel/line-width-panel.ts index b6b4a47737cc5..c5b7ce815a897 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/panel/line-width-panel.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/panel/line-width-panel.ts @@ -107,7 +107,10 @@ export class EdgelessLineWidthPanel extends WithDisposable(LitElement) { private _dragConfig: DragConfig | null = null; - private _getDragHandlePosition = (e: PointerEvent, config: DragConfig) => { + private readonly _getDragHandlePosition = ( + e: PointerEvent, + config: DragConfig + ) => { const x = e.clientX; const { boundLeft, bottomLineWidth, stepWidth, containerWidth } = config; @@ -128,7 +131,7 @@ export class EdgelessLineWidthPanel extends WithDisposable(LitElement) { return dragHandlerPosition; }; - private _onPointerDown = (e: PointerEvent) => { + private readonly _onPointerDown = (e: PointerEvent) => { e.preventDefault(); if (this.disable) return; const { left, width } = this._lineWidthPanel.getBoundingClientRect(); @@ -142,7 +145,7 @@ export class EdgelessLineWidthPanel extends WithDisposable(LitElement) { this._onPointerMove(e); }; - private _onPointerMove = (e: PointerEvent) => { + private readonly _onPointerMove = (e: PointerEvent) => { e.preventDefault(); if (!this._dragConfig) return; const dragHandlerPosition = this._getDragHandlePosition( @@ -154,7 +157,7 @@ export class EdgelessLineWidthPanel extends WithDisposable(LitElement) { this._updateIconsColor(); }; - private _onPointerOut = (e: PointerEvent) => { + private readonly _onPointerOut = (e: PointerEvent) => { // If the pointer is out of the line width panel // Stop dragging and update the selected size by nearest size. e.preventDefault(); @@ -167,7 +170,7 @@ export class EdgelessLineWidthPanel extends WithDisposable(LitElement) { this._dragConfig = null; }; - private _onPointerUp = (e: PointerEvent) => { + private readonly _onPointerUp = (e: PointerEvent) => { e.preventDefault(); if (!this._dragConfig) return; const dragHandlerPosition = this._getDragHandlePosition( @@ -178,7 +181,7 @@ export class EdgelessLineWidthPanel extends WithDisposable(LitElement) { this._dragConfig = null; }; - private _updateIconsColor = () => { + private readonly _updateIconsColor = () => { if (!this._dragHandle.offsetParent) { requestConnectedFrame(() => this._updateIconsColor(), this); return; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/panel/scale-panel.ts b/blocksuite/blocks/src/root-block/edgeless/components/panel/scale-panel.ts index 8cedd56957aab..ac7105bee2f6b 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/panel/scale-panel.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/panel/scale-panel.ts @@ -45,7 +45,7 @@ export class EdgelessScalePanel extends LitElement { } `; - private _onKeydown = (e: KeyboardEvent) => { + private readonly _onKeydown = (e: KeyboardEvent) => { e.stopPropagation(); if (e.key === 'Enter' && !e.isComposing) { diff --git a/blocksuite/blocks/src/root-block/edgeless/components/panel/size-panel.ts b/blocksuite/blocks/src/root-block/edgeless/components/panel/size-panel.ts index d2dd0becaf01e..277098508ce83 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/panel/size-panel.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/panel/size-panel.ts @@ -54,7 +54,7 @@ export class EdgelessSizePanel extends LitElement { } `; - private _onKeydown = (e: KeyboardEvent) => { + private readonly _onKeydown = (e: KeyboardEvent) => { e.stopPropagation(); if (e.key === 'Enter' && !e.isComposing) { diff --git a/blocksuite/blocks/src/root-block/edgeless/components/rects/edgeless-selected-rect.ts b/blocksuite/blocks/src/root-block/edgeless/components/rects/edgeless-selected-rect.ts index 1c87fded91308..0decab312a7f3 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/rects/edgeless-selected-rect.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/rects/edgeless-selected-rect.ts @@ -451,7 +451,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< private _dragEndCallback: (() => void)[] = []; - private _initSelectedSlot = () => { + private readonly _initSelectedSlot = () => { this._propDisposables.forEach(disposable => disposable.dispose()); this._propDisposables = []; @@ -466,7 +466,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< }); }; - private _onDragEnd = () => { + private readonly _onDragEnd = () => { this.slots.dragEnd.emit(); this.doc.transact(() => { @@ -488,7 +488,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< this.frameOverlay.clear(); }; - private _onDragMove = ( + private readonly _onDragMove = ( newBounds: Map< string, { @@ -561,7 +561,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< }); }; - private _onDragRotate = (center: IPoint, delta: number) => { + private readonly _onDragRotate = (center: IPoint, delta: number) => { this.slots.dragRotate.emit(); const { selection } = this; @@ -606,7 +606,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< this._updateMode(); }; - private _onDragStart = () => { + private readonly _onDragStart = () => { this.slots.dragStart.emit(); const rotation = this._resizeManager.rotation; @@ -651,9 +651,9 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< private _propDisposables: Disposable[] = []; - private _resizeManager: HandleResizeManager; + private readonly _resizeManager: HandleResizeManager; - private _updateCursor = ( + private readonly _updateCursor = ( dragging: boolean, options?: { type: 'resize' | 'rotate'; @@ -711,7 +711,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< this.gfx.cursor$.value = cursor; }; - private _updateMode = () => { + private readonly _updateMode = () => { if (this._cursorRotate) { this._mode = 'rotate'; return; @@ -738,7 +738,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< } }; - private _updateOnElementChange = ( + private readonly _updateOnElementChange = ( element: string | { id: string }, fromRemote: boolean = false ) => { @@ -754,7 +754,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< } }; - private _updateOnSelectionChange = () => { + private readonly _updateOnSelectionChange = () => { this._initSelectedSlot(); this._updateSelectedRect(); this._updateResizeManagerState(true); @@ -763,7 +763,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< this._updateMode(); }; - private _updateOnViewportChange = () => { + private readonly _updateOnViewportChange = () => { if (this.selection.empty) { return; } @@ -775,7 +775,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< /** * @param refresh indicate whether to completely refresh the state of resize manager, otherwise only update the position */ - private _updateResizeManagerState = (refresh: boolean) => { + private readonly _updateResizeManagerState = (refresh: boolean) => { const { _resizeManager, _selectedRect, @@ -813,7 +813,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< borderStyle: 'solid', }; - private _updateSelectedRect = requestThrottledConnectedFrame(() => { + private readonly _updateSelectedRect = requestThrottledConnectedFrame(() => { const { zoom, selection, gfx } = this; const elements = selection.selectedElements; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/resize/resize-manager.ts b/blocksuite/blocks/src/root-block/edgeless/components/resize/resize-manager.ts index 9c0890541a733..2f2ab2b8e688e 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/resize/resize-manager.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/resize/resize-manager.ts @@ -64,13 +64,13 @@ export class HandleResizeManager { private _locked = false; - private _onDragEnd: DragEndHandler; + private readonly _onDragEnd: DragEndHandler; - private _onDragStart: DragStartHandler; + private readonly _onDragStart: DragStartHandler; - private _onResizeMove: ResizeMoveHandler; + private readonly _onResizeMove: ResizeMoveHandler; - private _onRotateMove: RotateMoveHandler; + private readonly _onRotateMove: RotateMoveHandler; private _origin: { x: number; y: number } = { x: 0, y: 0 }; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-connector-label-editor.ts b/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-connector-label-editor.ts index 8a44ca273e080..3d5af296ae5f9 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-connector-label-editor.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-connector-label-editor.ts @@ -67,7 +67,7 @@ export class EdgelessConnectorLabelEditor extends WithDisposable( private _resizeObserver: ResizeObserver | null = null; - private _updateLabelRect = () => { + private readonly _updateLabelRect = () => { const { connector, edgeless } = this; if (!connector || !edgeless) return; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-text-editor.ts b/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-text-editor.ts index d2cf079cb4c50..942ea21555d86 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-text-editor.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-text-editor.ts @@ -69,7 +69,7 @@ export class EdgelessTextEditor extends WithDisposable(ShadowlessElement) { private _keeping = false; - private _updateRect = () => { + private readonly _updateRect = () => { const edgeless = this.edgeless; const element = this.element; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/brush/brush-menu.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/brush/brush-menu.ts index ef9745e3122f4..b96401ec3e108 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/brush/brush-menu.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/brush/brush-menu.ts @@ -36,7 +36,7 @@ export class EdgelessBrushMenu extends EdgelessToolbarToolMixin( } `; - private _props$ = computed(() => { + private readonly _props$ = computed(() => { const { color, lineWidth } = this.edgeless.std.get(EditPropsStore).lastProps$.value.brush; return { diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/brush/brush-tool-button.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/brush/brush-tool-button.ts index 84624a51353c1..79d76eeffa736 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/brush/brush-tool-button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/brush/brush-tool-button.ts @@ -43,7 +43,7 @@ export class EdgelessBrushToolButton extends EdgelessToolbarToolMixin( } `; - private _color$ = computed(() => { + private readonly _color$ = computed(() => { const theme = this.edgeless.std.get(ThemeProvider).theme$.value; return this.edgeless.std .get(ThemeProvider) diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/connector/connector-menu.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/connector/connector-menu.ts index 8cc0d321e35eb..1abaf2e9adcbf 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/connector/connector-menu.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/connector/connector-menu.ts @@ -97,7 +97,7 @@ export class EdgelessConnectorMenu extends EdgelessToolbarToolMixin( } `; - private _props$ = computed(() => { + private readonly _props$ = computed(() => { const { mode, stroke, strokeWidth } = this.edgeless.std.get(EditPropsStore).lastProps$.value.connector; return { mode, stroke, strokeWidth }; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/connector/connector-tool-button.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/connector/connector-tool-button.ts index a21496878388f..7a626db5e72f8 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/connector/connector-tool-button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/connector/connector-tool-button.ts @@ -39,7 +39,7 @@ export class EdgelessConnectorToolButton extends QuickToolMixin( } `; - private _mode$ = computed(() => { + private readonly _mode$ = computed(() => { return this.edgeless.std.get(EditPropsStore).lastProps$.value.connector .mode; }); diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/edgeless-toolbar.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/edgeless-toolbar.ts index 6a6dd13ba745a..cba68fd9574ad 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/edgeless-toolbar.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/edgeless-toolbar.ts @@ -229,7 +229,7 @@ export class EdgelessToolbarWidget extends WidgetComponent< @state() accessor containerWidth = 1920; - private _onContainerResize = debounce(({ w }: { w: number }) => { + private readonly _onContainerResize = debounce(({ w }: { w: number }) => { if (!this.isConnected) return; this.slots.resize.emit({ w, h: TOOLBAR_HEIGHT }); @@ -262,17 +262,17 @@ export class EdgelessToolbarWidget extends WidgetComponent< private _resizeObserver: ResizeObserver | null = null; - private _slotsProvider = new ContextProvider(this, { + private readonly _slotsProvider = new ContextProvider(this, { context: edgelessToolbarSlotsContext, initialValue: { resize: new Slot() } satisfies EdgelessToolbarSlots, }); - private _themeProvider = new ContextProvider(this, { + private readonly _themeProvider = new ContextProvider(this, { context: edgelessToolbarThemeContext, initialValue: ColorScheme.Light, }); - private _toolbarProvider = new ContextProvider(this, { + private readonly _toolbarProvider = new ContextProvider(this, { context: edgelessToolbarContext, initialValue: this, }); diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/lasso/lasso-tool-button.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/lasso/lasso-tool-button.ts index caf7a397fb838..9c266ede2aded 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/lasso/lasso-tool-button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/lasso/lasso-tool-button.ts @@ -33,7 +33,7 @@ export class EdgelessLassoToolButton extends QuickToolMixin( } `; - private _changeTool = () => { + private readonly _changeTool = () => { const tool = this.edgelessTool; if (tool.type !== 'lasso') { this.setEdgelessTool({ type: 'lasso', mode: this.curMode }); diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/mindmap/mindmap-menu.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/mindmap/mindmap-menu.ts index 1de0a532fc473..a63c4cd5e69f5 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/mindmap/mindmap-menu.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/mindmap/mindmap-menu.ts @@ -95,7 +95,7 @@ export class EdgelessMindmapMenu extends EdgelessToolbarToolMixin( } `; - private _style$ = computed(() => { + private readonly _style$ = computed(() => { const { style } = this.edgeless.std.get(EditPropsStore).lastProps$.value.mindmap; return style; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/mindmap/mindmap-tool-button.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/mindmap/mindmap-tool-button.ts index dd060e2efad6c..12284ff2fb6b5 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/mindmap/mindmap-tool-button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/mindmap/mindmap-tool-button.ts @@ -124,7 +124,7 @@ export class EdgelessMindmapToolButton extends EdgelessToolbarToolMixin( } `; - private _style$ = computed(() => { + private readonly _style$ = computed(() => { const { style } = this.edgeless.std.get(EditPropsStore).lastProps$.value.mindmap; return style; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/note/note-senior-button.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/note/note-senior-button.ts index 98356b4dd465a..3fa0ca888f4ed 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/note/note-senior-button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/note/note-senior-button.ts @@ -125,7 +125,7 @@ export class EdgelessNoteSeniorButton extends EdgelessToolbarToolMixin( } `; - private _noteBg$ = computed(() => { + private readonly _noteBg$ = computed(() => { return this.edgeless.std .get(ThemeProvider) .generateColorProperty( @@ -134,7 +134,7 @@ export class EdgelessNoteSeniorButton extends EdgelessToolbarToolMixin( ); }); - private _states = ['childFlavour', 'childType', 'tip'] as const; + private readonly _states = ['childFlavour', 'childType', 'tip'] as const; override enableActiveBackground = true; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/note/note-tool-button.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/note/note-tool-button.ts index a1cc1fe75caa7..bd6a5966a8b1b 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/note/note-tool-button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/note/note-tool-button.ts @@ -27,7 +27,7 @@ export class EdgelessNoteToolButton extends QuickToolMixin(LitElement) { private _noteMenu: MenuPopper | null = null; - private _states = ['childFlavour', 'childType', 'tip'] as const; + private readonly _states = ['childFlavour', 'childType', 'tip'] as const; override type: GfxToolsFullOptionValue['type'] = 'affine:note'; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/present/navigator-setting-button.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/present/navigator-setting-button.ts index 2cb5365ddef64..cadb90c64f407 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/present/navigator-setting-button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/present/navigator-setting-button.ts @@ -71,7 +71,7 @@ export class EdgelessNavigatorSettingButton extends WithDisposable(LitElement) { typeof createButtonPopper > | null = null; - private _onBlackBackgroundChange = (checked: boolean) => { + private readonly _onBlackBackgroundChange = (checked: boolean) => { this.blackBackground = checked; this.edgeless.slots.navigatorSettingUpdated.emit({ blackBackground: this.blackBackground, diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-menu.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-menu.ts index f4a74136f1026..24e8d934374a5 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-menu.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-menu.ts @@ -59,12 +59,12 @@ export class EdgelessShapeMenu extends SignalWatcher( } `; - private _shapeName$: Signal = signal(ShapeType.Rect); + private readonly _shapeName$: Signal = signal(ShapeType.Rect); @property({ attribute: false }) accessor edgeless!: EdgelessRootBlockComponent; - private _props$ = computed(() => { + private readonly _props$ = computed(() => { const shapeName: ShapeName = this._shapeName$.value; const { shapeStyle, fillColor, strokeColor, radius } = this.edgeless.std.get(EditPropsStore).lastProps$.value[ @@ -79,7 +79,7 @@ export class EdgelessShapeMenu extends SignalWatcher( }; }); - private _setFillColor = (fillColor: ShapeFillColor) => { + private readonly _setFillColor = (fillColor: ShapeFillColor) => { const filled = !isTransparent(fillColor); let strokeColor = fillColor.replace( SHAPE_COLOR_PREFIX, @@ -101,7 +101,7 @@ export class EdgelessShapeMenu extends SignalWatcher( this.onChange(shapeName); }; - private _setShapeStyle = (shapeStyle: ShapeStyle) => { + private readonly _setShapeStyle = (shapeStyle: ShapeStyle) => { const { shapeName } = this._props$.value; this.edgeless.std .get(EditPropsStore) diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-tool-button.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-tool-button.ts index be79d5e3e66c7..fa425a0cc8c99 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-tool-button.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-tool-button.ts @@ -23,14 +23,14 @@ export class EdgelessShapeToolButton extends EdgelessToolbarToolMixin( } `; - private _handleShapeClick = (shape: DraggableShape) => { + private readonly _handleShapeClick = (shape: DraggableShape) => { this.setEdgelessTool(this.type, { shapeName: shape.name, }); if (!this.popper) this._toggleMenu(); }; - private _handleWrapperClick = () => { + private readonly _handleWrapperClick = () => { if (this.tryDisposePopper()) return; this.setEdgelessTool(this.type, { diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-tool-element.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-tool-element.ts index 0b7d0719e9cfe..81e577de9fe46 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-tool-element.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/shape/shape-tool-element.ts @@ -67,7 +67,7 @@ export class EdgelessShapeToolElement extends WithDisposable(LitElement) { } `; - private _addShape = (coord: Coord, padding: Coord) => { + private readonly _addShape = (coord: Coord, padding: Coord) => { const width = 100; const height = 100; const { x: edgelessX, y: edgelessY } = @@ -85,7 +85,7 @@ export class EdgelessShapeToolElement extends WithDisposable(LitElement) { }); }; - private _onDragEnd = async (coord: Coord) => { + private readonly _onDragEnd = async (coord: Coord) => { if (this._startCoord.x === coord.x && this._startCoord.y === coord.y) { this.handleClick(); this._dragging = false; @@ -118,7 +118,7 @@ export class EdgelessShapeToolElement extends WithDisposable(LitElement) { } }; - private _onDragMove = (coord: Coord) => { + private readonly _onDragMove = (coord: Coord) => { if (!this._dragging) { return; } @@ -153,7 +153,7 @@ export class EdgelessShapeToolElement extends WithDisposable(LitElement) { this._isOutside = isOut; }; - private _onDragStart = (coord: Coord) => { + private readonly _onDragStart = (coord: Coord) => { this._startCoord = { x: coord.x, y: coord.y }; if (this.order !== 1) { return; @@ -162,20 +162,20 @@ export class EdgelessShapeToolElement extends WithDisposable(LitElement) { this._shapeElement.classList.add('dragging'); }; - private _onMouseMove = (event: MouseEvent) => { + private readonly _onMouseMove = (event: MouseEvent) => { if (!this._dragging) { return; } this._onDragMove({ x: event.clientX, y: event.clientY }); }; - private _onMouseUp = (event: MouseEvent) => { + private readonly _onMouseUp = (event: MouseEvent) => { this._onDragEnd({ x: event.clientX, y: event.clientY }).catch( console.error ); }; - private _onTouchEnd = (event: TouchEvent) => { + private readonly _onTouchEnd = (event: TouchEvent) => { if (!event.changedTouches.length) return; this._onDragEnd({ @@ -185,7 +185,7 @@ export class EdgelessShapeToolElement extends WithDisposable(LitElement) { }).catch(console.error); }; - private _touchMove = (event: TouchEvent) => { + private readonly _touchMove = (event: TouchEvent) => { if (!this._dragging) { return; } @@ -195,7 +195,7 @@ export class EdgelessShapeToolElement extends WithDisposable(LitElement) { }); }; - private _transformMap: TransformMap = { + private readonly _transformMap: TransformMap = { z1: { x: 0, y: 5, scale: 1.1, origin: '50% 100%' }, z2: { x: -15, y: 0, scale: 0.75, origin: '20% 20%' }, z3: { x: 15, y: 0, scale: 0.75, origin: '80% 20%' }, diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/template/overlay-scrollbar.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/template/overlay-scrollbar.ts index 0009cdf73f2ec..2b9b0fa35650c 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/template/overlay-scrollbar.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/template/overlay-scrollbar.ts @@ -50,7 +50,7 @@ export class OverlayScrollbar extends LitElement { } `; - private _disposable = new DisposableGroup(); + private readonly _disposable = new DisposableGroup(); private _handleVisible = false; diff --git a/blocksuite/blocks/src/root-block/edgeless/edgeless-root-block.ts b/blocksuite/blocks/src/root-block/edgeless/edgeless-root-block.ts index c7698d4fa5c7c..39df706ecfc74 100644 --- a/blocksuite/blocks/src/root-block/edgeless/edgeless-root-block.ts +++ b/blocksuite/blocks/src/root-block/edgeless/edgeless-root-block.ts @@ -98,21 +98,24 @@ export class EdgelessRootBlockComponent extends BlockComponent< } `; - private _refreshLayerViewport = requestThrottledConnectedFrame(() => { - const { zoom, translateX, translateY } = this.gfx.viewport; - const { gap } = getBackgroundGrid(zoom, true); - - if (this.backgroundElm) { - this.backgroundElm.style.setProperty( - 'background-position', - `${translateX}px ${translateY}px` - ); - this.backgroundElm.style.setProperty( - 'background-size', - `${gap}px ${gap}px` - ); - } - }, this); + private readonly _refreshLayerViewport = requestThrottledConnectedFrame( + () => { + const { zoom, translateX, translateY } = this.gfx.viewport; + const { gap } = getBackgroundGrid(zoom, true); + + if (this.backgroundElm) { + this.backgroundElm.style.setProperty( + 'background-position', + `${translateX}px ${translateY}px` + ); + this.backgroundElm.style.setProperty( + 'background-size', + `${gap}px ${gap}px` + ); + } + }, + this + ); private _resizeObserver: ResizeObserver | null = null; diff --git a/blocksuite/blocks/src/root-block/edgeless/edgeless-root-preview-block.ts b/blocksuite/blocks/src/root-block/edgeless/edgeless-root-preview-block.ts index a57acf510f2e4..475429c4f10f9 100644 --- a/blocksuite/blocks/src/root-block/edgeless/edgeless-root-preview-block.ts +++ b/blocksuite/blocks/src/root-block/edgeless/edgeless-root-preview-block.ts @@ -64,16 +64,19 @@ export class EdgelessRootPreviewBlockComponent extends BlockComponent< @query('.edgeless-background') accessor background!: HTMLDivElement; - private _refreshLayerViewport = requestThrottledConnectedFrame(() => { - const { zoom, translateX, translateY } = this.service.viewport; - const { gap } = getBackgroundGrid(zoom, true); - - this.background.style.setProperty( - 'background-position', - `${translateX}px ${translateY}px` - ); - this.background.style.setProperty('background-size', `${gap}px ${gap}px`); - }, this); + private readonly _refreshLayerViewport = requestThrottledConnectedFrame( + () => { + const { zoom, translateX, translateY } = this.service.viewport; + const { gap } = getBackgroundGrid(zoom, true); + + this.background.style.setProperty( + 'background-position', + `${translateX}px ${translateY}px` + ); + this.background.style.setProperty('background-size', `${gap}px ${gap}px`); + }, + this + ); private _resizeObserver: ResizeObserver | null = null; diff --git a/blocksuite/blocks/src/root-block/edgeless/edgeless-root-service.ts b/blocksuite/blocks/src/root-block/edgeless/edgeless-root-service.ts index d7c2ae115dbc4..32b37fff9dcc9 100644 --- a/blocksuite/blocks/src/root-block/edgeless/edgeless-root-service.ts +++ b/blocksuite/blocks/src/root-block/edgeless/edgeless-root-service.ts @@ -56,7 +56,7 @@ import { export class EdgelessRootService extends RootService implements SurfaceContext { static override readonly flavour = RootBlockSchema.model.flavour; - private _surface: SurfaceBlockModel; + private readonly _surface: SurfaceBlockModel; elementRenderers: Record = elementRenderers; diff --git a/blocksuite/blocks/src/root-block/edgeless/frame-manager.ts b/blocksuite/blocks/src/root-block/edgeless/frame-manager.ts index e0183a694fae7..1c671fd5469f6 100644 --- a/blocksuite/blocks/src/root-block/edgeless/frame-manager.ts +++ b/blocksuite/blocks/src/root-block/edgeless/frame-manager.ts @@ -37,7 +37,7 @@ export class FrameOverlay extends Overlay { private _innerElements = new Set(); - private _prevXYWH: SerializedXYWH | null = null; + private readonly _prevXYWH: SerializedXYWH | null = null; private get _frameManager() { return this.gfx.std.get( @@ -132,7 +132,7 @@ export class FrameOverlay extends Overlay { export class EdgelessFrameManager extends GfxExtension { static override key = 'frame-manager'; - private _disposable = new DisposableGroup(); + private readonly _disposable = new DisposableGroup(); /** * Get all sorted frames by presentation orderer, diff --git a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/brush-tool.ts b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/brush-tool.ts index 83345dc2f4dbd..67390bd508531 100644 --- a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/brush-tool.ts +++ b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/brush-tool.ts @@ -19,7 +19,7 @@ export class BrushTool extends BaseTool { private _lastPopLength = 0; - private _pressureSupportedPointerIds = new Set(); + private readonly _pressureSupportedPointerIds = new Set(); private _straightLineType: 'horizontal' | 'vertical' | null = null; diff --git a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/default-tool-ext/mind-map-ext/mind-map-ext.ts b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/default-tool-ext/mind-map-ext/mind-map-ext.ts index 6ad04ebb68059..50e3fade1b1eb 100644 --- a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/default-tool-ext/mind-map-ext/mind-map-ext.ts +++ b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/default-tool-ext/mind-map-ext/mind-map-ext.ts @@ -36,7 +36,7 @@ type DragMindMapCtx = { }; export class MindMapExt extends DefaultToolExt { - private _responseAreaUpdated = new Set(); + private readonly _responseAreaUpdated = new Set(); override supportedDragTypes: DefaultModeDragType[] = [ DefaultModeDragType.ContentMoving, diff --git a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/default-tool.ts b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/default-tool.ts index 35408569d74fa..9e14cd128a740 100644 --- a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/default-tool.ts +++ b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/default-tool.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { ConnectorUtils, OverlayIdentifier, @@ -79,14 +78,14 @@ export class DefaultTool extends BaseTool { private _autoPanTimer: number | null = null; - private _clearDisposable = () => { + private readonly _clearDisposable = () => { if (this._disposables) { this._disposables.dispose(); this._disposables = null; } }; - private _clearSelectingState = () => { + private readonly _clearSelectingState = () => { this._stopAutoPanning(); this._clearDisposable(); @@ -110,13 +109,13 @@ export class DefaultTool extends BaseTool { private _lock = false; - private _panViewport = (delta: IVec) => { + private readonly _panViewport = (delta: IVec) => { this._accumulateDelta[0] += delta[0]; this._accumulateDelta[1] += delta[1]; this.gfx.viewport.applyDeltaCenter(delta[0], delta[1]); }; - private _pendingUpdates = new Map< + private readonly _pendingUpdates = new Map< GfxBlockModel | GfxPrimitiveElementModel, Partial >(); @@ -139,7 +138,7 @@ export class DefaultTool extends BaseTool { endY: number; } = null; - private _startAutoPanning = (delta: IVec) => { + private readonly _startAutoPanning = (delta: IVec) => { this._panViewport(delta); this._updateSelectingState(delta); this._stopAutoPanning(); @@ -150,7 +149,7 @@ export class DefaultTool extends BaseTool { }, 30); }; - private _stopAutoPanning = () => { + private readonly _stopAutoPanning = () => { if (this._autoPanTimer) { clearTimeout(this._autoPanTimer); this._autoPanTimer = null; @@ -159,7 +158,7 @@ export class DefaultTool extends BaseTool { private _toBeMoved: GfxModel[] = []; - private _updateSelectingState = (delta: IVec = [0, 0]) => { + private readonly _updateSelectingState = (delta: IVec = [0, 0]) => { const { gfx } = this; if (gfx.keyboard.spaceKey$.peek() && this._selectionRectTransition) { @@ -943,6 +942,7 @@ export class DefaultTool extends BaseTool { } } + // eslint-disable-next-line @typescript-eslint/no-misused-promises override async dragStart(e: PointerEventState) { if (this.edgelessSelectionManager.editing) return; // Determine the drag type based on the current state and event diff --git a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/eraser-tool.ts b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/eraser-tool.ts index 82edd249b78f0..c752c7f465d65 100644 --- a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/eraser-tool.ts +++ b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/eraser-tool.ts @@ -30,9 +30,9 @@ export class EraserTool extends BaseTool { private _eraserPoints: IVec[] = []; - private _eraseTargets = new Set(); + private readonly _eraseTargets = new Set(); - private _loop = () => { + private readonly _loop = () => { const now = Date.now(); const elapsed = now - this._timestamp; @@ -62,7 +62,7 @@ export class EraserTool extends BaseTool { this._timer = requestAnimationFrame(this._loop); }; - private _overlay = new EraserOverlay(this.gfx); + private readonly _overlay = new EraserOverlay(this.gfx); private _prevEraserPoint: IVec = [0, 0]; diff --git a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/lasso-tool.ts b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/lasso-tool.ts index 084b3048939c1..99ff427a0d62d 100644 --- a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/lasso-tool.ts +++ b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/lasso-tool.ts @@ -68,7 +68,7 @@ export class LassoTool extends BaseTool { private _lastPoint: IVec = [0, 0]; - private _loop = () => { + private readonly _loop = () => { const path = this.activatedOption.mode === LassoMode.FreeHand ? CommonUtils.getSvgPathFromStroke(this._lassoPoints) @@ -79,7 +79,7 @@ export class LassoTool extends BaseTool { this._raf = requestAnimationFrame(this._loop); }; - private _overlay = new LassoOverlay(this.gfx); + private readonly _overlay = new LassoOverlay(this.gfx); private _raf = 0; diff --git a/blocksuite/blocks/src/root-block/keyboard/keyboard-manager.ts b/blocksuite/blocks/src/root-block/keyboard/keyboard-manager.ts index 04e4fcb84a9d0..849370d0bf436 100644 --- a/blocksuite/blocks/src/root-block/keyboard/keyboard-manager.ts +++ b/blocksuite/blocks/src/root-block/keyboard/keyboard-manager.ts @@ -11,7 +11,7 @@ import { } from '../../_common/utils/render-linked-doc.js'; export class PageKeyboardManager { - private _handleDelete = () => { + private readonly _handleDelete = () => { const blockSelections = this._currentSelection.filter(sel => sel.is('block') ); @@ -117,16 +117,18 @@ export class PageKeyboardManager { const doc = rootComponent.host.doc; const autofill = getTitleFromSelectedModels(selectedModels); - void promptDocTitle(rootComponent.host, autofill).then(title => { - if (title === null) return; - convertSelectedBlocksToLinkedDoc( - this.rootComponent.std, - doc, - draftedModels, - title - ).catch(console.error); - notifyDocCreated(rootComponent.host, doc); - }); + promptDocTitle(rootComponent.host, autofill) + .then(title => { + if (title === null) return; + convertSelectedBlocksToLinkedDoc( + this.rootComponent.std, + doc, + draftedModels, + title + ).catch(console.error); + notifyDocCreated(rootComponent.host, doc); + }) + .catch(console.error); } private _deleteBlocksBySelection(selections: BlockSelection[]) { diff --git a/blocksuite/blocks/src/root-block/remote-color-manager/color-picker.ts b/blocksuite/blocks/src/root-block/remote-color-manager/color-picker.ts index e20e8f7307f24..f1165596f1ec9 100644 --- a/blocksuite/blocks/src/root-block/remote-color-manager/color-picker.ts +++ b/blocksuite/blocks/src/root-block/remote-color-manager/color-picker.ts @@ -1,7 +1,7 @@ class RandomPicker { private _copyArray: T[]; - private _originalArray: T[]; + private readonly _originalArray: T[]; constructor(array: T[]) { this._originalArray = [...array]; diff --git a/blocksuite/blocks/src/root-block/root-service.ts b/blocksuite/blocks/src/root-block/root-service.ts index df6bc81f025ac..fe51a1f38841b 100644 --- a/blocksuite/blocks/src/root-block/root-service.ts +++ b/blocksuite/blocks/src/root-block/root-service.ts @@ -16,7 +16,7 @@ import type { RootBlockComponent } from './types.js'; export abstract class RootService extends BlockService { static override readonly flavour = RootBlockSchema.model.flavour; - private _fileDropOptions: FileDropOptions = { + private readonly _fileDropOptions: FileDropOptions = { flavour: this.flavour, }; diff --git a/blocksuite/blocks/src/root-block/widgets/ai-panel/ai-panel.ts b/blocksuite/blocks/src/root-block/widgets/ai-panel/ai-panel.ts index 0fe64e061d7af..ff992cf2d6323 100644 --- a/blocksuite/blocks/src/root-block/widgets/ai-panel/ai-panel.ts +++ b/blocksuite/blocks/src/root-block/widgets/ai-panel/ai-panel.ts @@ -84,18 +84,18 @@ export class AffineAIPanelWidget extends WidgetComponent { private _answer: string | null = null; - private _cancelCallback = () => { + private readonly _cancelCallback = () => { this.focus(); }; - private _clearDiscardModal = () => { + private readonly _clearDiscardModal = () => { if (this._discardModalAbort) { this._discardModalAbort.abort(); this._discardModalAbort = null; } }; - private _clickOutside = () => { + private readonly _clickOutside = () => { switch (this.state) { case 'hidden': return; @@ -112,21 +112,21 @@ export class AffineAIPanelWidget extends WidgetComponent { } }; - private _discardCallback = () => { + private readonly _discardCallback = () => { this.hide(); this.config?.discardCallback?.(); }; private _discardModalAbort: AbortController | null = null; - private _inputFinish = (text: string) => { + private readonly _inputFinish = (text: string) => { this._inputText = text; this.generate(); }; private _inputText: string | null = null; - private _onDocumentClick = (e: MouseEvent) => { + private readonly _onDocumentClick = (e: MouseEvent) => { if ( this.state !== 'hidden' && e.target !== this && @@ -139,7 +139,7 @@ export class AffineAIPanelWidget extends WidgetComponent { return false; }; - private _onKeyDown = (event: KeyboardEvent) => { + private readonly _onKeyDown = (event: KeyboardEvent) => { event.stopPropagation(); const { state } = this; if (state !== 'generating' && state !== 'input') { @@ -157,7 +157,7 @@ export class AffineAIPanelWidget extends WidgetComponent { } }; - private _resetAbortController = () => { + private readonly _resetAbortController = () => { if (this.state === 'generating') { this._abortController.abort(); } diff --git a/blocksuite/blocks/src/root-block/widgets/ai-panel/components/state/error.ts b/blocksuite/blocks/src/root-block/widgets/ai-panel/components/state/error.ts index 7dbd1e3556127..c073b5cb1467e 100644 --- a/blocksuite/blocks/src/root-block/widgets/ai-panel/components/state/error.ts +++ b/blocksuite/blocks/src/root-block/widgets/ai-panel/components/state/error.ts @@ -127,7 +127,7 @@ export class AIPanelError extends WithDisposable(LitElement) { } `; - private _getResponseGroup = () => { + private readonly _getResponseGroup = () => { let responseGroup: AIItemGroupConfig[] = []; const errorType = this.config.error?.type; if (errorType && errorType !== AIErrorType.GeneralNetworkError) { diff --git a/blocksuite/blocks/src/root-block/widgets/ai-panel/components/state/input.ts b/blocksuite/blocks/src/root-block/widgets/ai-panel/components/state/input.ts index 0e57647890e9b..e9c6dbcba6bb5 100644 --- a/blocksuite/blocks/src/root-block/widgets/ai-panel/components/state/input.ts +++ b/blocksuite/blocks/src/root-block/widgets/ai-panel/components/state/input.ts @@ -84,7 +84,7 @@ export class AIPanelInput extends WithDisposable(LitElement) { } `; - private _onInput = () => { + private readonly _onInput = () => { this.textarea.style.height = 'auto'; this.textarea.style.height = this.textarea.scrollHeight + 'px'; @@ -99,14 +99,14 @@ export class AIPanelInput extends WithDisposable(LitElement) { } }; - private _onKeyDown = (e: KeyboardEvent) => { + private readonly _onKeyDown = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) { e.preventDefault(); this._sendToAI(); } }; - private _sendToAI = () => { + private readonly _sendToAI = () => { const value = this.textarea.value.trim(); if (value.length === 0) return; diff --git a/blocksuite/blocks/src/root-block/widgets/code-toolbar/components/lang-button.ts b/blocksuite/blocks/src/root-block/widgets/code-toolbar/components/lang-button.ts index 147c1f4c8c9c0..f4e41ecf507a2 100644 --- a/blocksuite/blocks/src/root-block/widgets/code-toolbar/components/lang-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/code-toolbar/components/lang-button.ts @@ -47,7 +47,7 @@ export class LanguageListButton extends WithDisposable( private _abortController?: AbortController; - private _clickLangBtn = () => { + private readonly _clickLangBtn = () => { if (this.blockComponent.doc.readonly) return; if (this._abortController) { // Close the language list if it's already opened. diff --git a/blocksuite/blocks/src/root-block/widgets/code-toolbar/index.ts b/blocksuite/blocks/src/root-block/widgets/code-toolbar/index.ts index eda4c8b359d8e..20d74152da4a7 100644 --- a/blocksuite/blocks/src/root-block/widgets/code-toolbar/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/code-toolbar/index.ts @@ -24,7 +24,7 @@ export class AffineCodeToolbarWidget extends WidgetComponent< private _isActivated = false; - private _setHoverController = () => { + private readonly _setHoverController = () => { this._hoverController = null; this._hoverController = new HoverController( this, diff --git a/blocksuite/blocks/src/root-block/widgets/doc-remote-selection/doc-remote-selection.ts b/blocksuite/blocks/src/root-block/widgets/doc-remote-selection/doc-remote-selection.ts index fd57a054aa989..d1fdd79187bc2 100644 --- a/blocksuite/blocks/src/root-block/widgets/doc-remote-selection/doc-remote-selection.ts +++ b/blocksuite/blocks/src/root-block/widgets/doc-remote-selection/doc-remote-selection.ts @@ -34,11 +34,11 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent { } `; - private _abortController = new AbortController(); + private readonly _abortController = new AbortController(); private _remoteColorManager: RemoteColorManager | null = null; - private _remoteSelections = computed(() => { + private readonly _remoteSelections = computed(() => { const status = this.doc.awarenessStore.getStates(); return [...this.std.selection.remoteSelections.entries()].map( ([id, selections]) => { @@ -51,7 +51,7 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent { ); }); - private _resizeObserver: ResizeObserver = new ResizeObserver(() => { + private readonly _resizeObserver: ResizeObserver = new ResizeObserver(() => { this.requestUpdate(); }); diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/config.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/config.ts index 745b6ecb8d142..f711948df0e19 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/config.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/config.ts @@ -31,7 +31,7 @@ export type DropResult = { }; export class DragHandleOptionsRunner { - private optionMap = new Map(); + private readonly optionMap = new Map(); get options(): DragHandleOption[] { return Array.from(this.optionMap.keys()); diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/drag-handle.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/drag-handle.ts index b2d23cd67c812..84f117d3d8136 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/drag-handle.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/drag-handle.ts @@ -58,16 +58,18 @@ export class AffineDragHandleWidget extends WidgetComponent { private _anchorModelDisposables: DisposableGroup | null = null; - private _dragEventWatcher = new DragEventWatcher(this); + private readonly _dragEventWatcher = new DragEventWatcher(this); - private _getBlockView = (blockId: string) => { + private readonly _getBlockView = (blockId: string) => { return this.host.view.getBlock(blockId); }; /** * When dragging, should update indicator position and target drop block id */ - private _getDropResult = (state: DndEventState): DropResult | null => { + private readonly _getDropResult = ( + state: DndEventState + ): DropResult | null => { const point = new Point(state.raw.x, state.raw.y); const closestBlock = getClosestBlockByPoint( this.host, @@ -137,22 +139,22 @@ export class AffineDragHandleWidget extends WidgetComponent { return dropIndicator; }; - private _handleEventWatcher = new HandleEventWatcher(this); + private readonly _handleEventWatcher = new HandleEventWatcher(this); - private _keyboardEventWatcher = new KeyboardEventWatcher(this); + private readonly _keyboardEventWatcher = new KeyboardEventWatcher(this); - private _legacyDragEventWatcher = new LegacyDragEventWatcher(this); + private readonly _legacyDragEventWatcher = new LegacyDragEventWatcher(this); - private _pageWatcher = new PageWatcher(this); + private readonly _pageWatcher = new PageWatcher(this); - private _removeDropIndicator = () => { + private readonly _removeDropIndicator = () => { if (this.dropIndicator) { this.dropIndicator.remove(); this.dropIndicator = null; } }; - private _reset = () => { + private readonly _reset = () => { this.draggingElements = []; this.dropBlockId = ''; this.dropType = null; @@ -173,17 +175,17 @@ export class AffineDragHandleWidget extends WidgetComponent { this._resetCursor(); }; - private _resetCursor = () => { + private readonly _resetCursor = () => { document.documentElement.classList.remove('affine-drag-preview-grabbing'); }; - private _resetDropResult = () => { + private readonly _resetDropResult = () => { this.dropBlockId = ''; this.dropType = null; if (this.dropIndicator) this.dropIndicator.rect = null; }; - private _updateDropResult = (dropResult: DropResult | null) => { + private readonly _updateDropResult = (dropResult: DropResult | null) => { if (!this.dropIndicator) return; this.dropBlockId = dropResult?.dropBlockId ?? ''; this.dropType = dropResult?.dropType ?? null; diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/helpers/preview-helper.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/helpers/preview-helper.ts index bc90963c54fcc..4e82df2a8e641 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/helpers/preview-helper.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/helpers/preview-helper.ts @@ -11,7 +11,7 @@ import { DragPreview } from '../components/drag-preview.js'; import type { AffineDragHandleWidget } from '../drag-handle.js'; export class PreviewHelper { - private _calculatePreviewOffset = ( + private readonly _calculatePreviewOffset = ( blocks: BlockComponent[], state: DndEventState ) => { @@ -20,7 +20,7 @@ export class PreviewHelper { return previewOffset; }; - private _calculateQuery = (selectedIds: string[]): Query => { + private readonly _calculateQuery = (selectedIds: string[]): Query => { const ids: Array<{ id: string; viewType: BlockViewType }> = selectedIds.map( id => ({ id, diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/helpers/rect-helper.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/helpers/rect-helper.ts index 0db43c3939382..6562ecf97262e 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/helpers/rect-helper.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/helpers/rect-helper.ts @@ -15,7 +15,7 @@ import { } from '../utils.js'; export class RectHelper { - private _getHoveredBlocks = (): BlockComponent[] => { + private readonly _getHoveredBlocks = (): BlockComponent[] => { if (!this.widget.isHoverDragHandleVisible || !this.widget.anchorBlockId) return []; diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/drag-event-watcher.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/drag-event-watcher.ts index d82b55d232bc7..f35a1eb1ee0b5 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/drag-event-watcher.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/drag-event-watcher.ts @@ -44,7 +44,7 @@ import { surfaceRefToEmbed } from '../middleware/surface-ref-to-embed.js'; import { containBlock, includeTextSelection } from '../utils.js'; export class DragEventWatcher { - private _computeEdgelessBound = ( + private readonly _computeEdgelessBound = ( x: number, y: number, width: number, @@ -70,19 +70,19 @@ export class DragEventWatcher { ); }; - private _createDropIndicator = () => { + private readonly _createDropIndicator = () => { if (!this.widget.dropIndicator) { this.widget.dropIndicator = new DropIndicator(); this.widget.rootComponent.append(this.widget.dropIndicator); } }; - private _dragEndHandler: UIEventHandler = () => { + private readonly _dragEndHandler: UIEventHandler = () => { this.widget.clearRaf(); this.widget.hide(true); }; - private _dragMoveHandler: UIEventHandler = ctx => { + private readonly _dragMoveHandler: UIEventHandler = ctx => { if ( this.widget.isHoverDragHandleVisible || this.widget.isTopLevelDragHandleVisible @@ -104,7 +104,7 @@ export class DragEventWatcher { /** * When start dragging, should set dragging elements and create drag preview */ - private _dragStartHandler: UIEventHandler = ctx => { + private readonly _dragStartHandler: UIEventHandler = ctx => { const state = ctx.get('dndState'); // If not click left button to start dragging, should do nothing const { button } = state.raw; @@ -115,14 +115,14 @@ export class DragEventWatcher { return this._onDragStart(state); }; - private _dropHandler = (context: UIEventStateContext) => { + private readonly _dropHandler = (context: UIEventStateContext) => { this._onDrop(context); this._std.selection.setGroup('gfx', []); this.widget.clearRaf(); this.widget.hide(true); }; - private _onDragMove = (state: DndEventState) => { + private readonly _onDragMove = (state: DndEventState) => { this.widget.clearRaf(); this.widget.rafID = requestAnimationFrame(() => { @@ -132,7 +132,7 @@ export class DragEventWatcher { return true; }; - private _onDragStart = (state: DndEventState) => { + private readonly _onDragStart = (state: DndEventState) => { // Get current hover block element by path const hoverBlock = this.widget.anchorBlockComponent.peek(); if (!hoverBlock) return false; @@ -234,7 +234,7 @@ export class DragEventWatcher { return true; }; - private _onDrop = (context: UIEventStateContext) => { + private readonly _onDrop = (context: UIEventStateContext) => { const state = context.get('dndState'); const event = state.raw; @@ -280,7 +280,7 @@ export class DragEventWatcher { this._deserializeData(state, parent.id, index).catch(console.error); }; - private _onDropNoteOnNote = ( + private readonly _onDropNoteOnNote = ( snapshot: SliceSnapshot, parent?: string, index?: number @@ -305,7 +305,7 @@ export class DragEventWatcher { .catch(console.error); }; - private _onDropOnEdgelessCanvas = (context: UIEventStateContext) => { + private readonly _onDropOnEdgelessCanvas = (context: UIEventStateContext) => { const state = context.get('dndState'); // If drop a note, should do nothing const snapshot = this._deserializeSnapshot(state); @@ -405,7 +405,7 @@ export class DragEventWatcher { this._deserializeData(state, newNoteId).catch(console.error); }; - private _startDragging = ( + private readonly _startDragging = ( blocks: BlockComponent[], state: DndEventState, dragPreviewEl?: HTMLElement, @@ -435,7 +435,7 @@ export class DragEventWatcher { this._serializeData(slice, state); }; - private _trackLinkedDocCreated = (id: string) => { + private readonly _trackLinkedDocCreated = (id: string) => { const isNewBlock = !this._std.doc.hasBlock(id); if (!isNewBlock) { return; diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/edgeless-watcher.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/edgeless-watcher.ts index fd4f84aa95ab7..efdb1d37a0236 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/edgeless-watcher.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/edgeless-watcher.ts @@ -24,7 +24,9 @@ import { import type { AffineDragHandleWidget } from '../drag-handle.js'; export class EdgelessWatcher { - private _handleEdgelessToolUpdated = (newTool: GfxToolsFullOptionValue) => { + private readonly _handleEdgelessToolUpdated = ( + newTool: GfxToolsFullOptionValue + ) => { if (newTool.type === 'default') { this.checkTopLevelBlockSelection(); } else { @@ -32,7 +34,7 @@ export class EdgelessWatcher { } }; - private _handleEdgelessViewPortUpdated = ({ + private readonly _handleEdgelessViewPortUpdated = ({ zoom, center, }: { @@ -60,7 +62,7 @@ export class EdgelessWatcher { } }; - private _showDragHandleOnTopLevelBlocks = async () => { + private readonly _showDragHandleOnTopLevelBlocks = async () => { if (this.widget.mode === 'page') return; const { edgelessRoot } = this; await edgelessRoot.surface.updateComplete; @@ -99,13 +101,13 @@ export class EdgelessWatcher { this.widget.isTopLevelDragHandleVisible = true; }; - private _updateDragHoverRectTopLevelBlock = () => { + private readonly _updateDragHoverRectTopLevelBlock = () => { if (!this.widget.dragHoverRect) return; this.widget.dragHoverRect = this.hoverAreaRectTopLevelBlock; }; - private _updateDragPreviewOnViewportUpdate = () => { + private readonly _updateDragPreviewOnViewportUpdate = () => { if (this.widget.dragPreview && this.widget.lastDragPointerState) { this.updateDragPreviewPosition(this.widget.lastDragPointerState); } diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/handle-event-watcher.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/handle-event-watcher.ts index 6ed86e01cb97c..d0bb58dee2e95 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/handle-event-watcher.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/handle-event-watcher.ts @@ -6,14 +6,14 @@ import { import type { AffineDragHandleWidget } from '../drag-handle.js'; export class HandleEventWatcher { - private _onDragHandlePointerDown = () => { + private readonly _onDragHandlePointerDown = () => { if (!this.widget.isHoverDragHandleVisible || !this.widget.anchorBlockId) return; this.widget.dragHoverRect = this.widget.draggingAreaRect.value; }; - private _onDragHandlePointerEnter = () => { + private readonly _onDragHandlePointerEnter = () => { const container = this.widget.dragHandleContainer; const grabber = this.widget.dragHandleGrabber; if (!container || !grabber) return; @@ -42,7 +42,7 @@ export class HandleEventWatcher { } }; - private _onDragHandlePointerLeave = () => { + private readonly _onDragHandlePointerLeave = () => { this.widget.isDragHandleHovered = false; this.widget.dragHoverRect = null; @@ -53,7 +53,7 @@ export class HandleEventWatcher { this.widget.pointerEventWatcher.showDragHandleOnHoverBlock(); }; - private _onDragHandlePointerUp = () => { + private readonly _onDragHandlePointerUp = () => { if (!this.widget.isHoverDragHandleVisible) return; this.widget.dragHoverRect = null; }; diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/keyboard-event-watcher.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/keyboard-event-watcher.ts index 13845aab7fa14..2507fd91f8e1d 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/keyboard-event-watcher.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/keyboard-event-watcher.ts @@ -3,7 +3,7 @@ import type { UIEventHandler } from '@blocksuite/block-std'; import type { AffineDragHandleWidget } from '../drag-handle.js'; export class KeyboardEventWatcher { - private _keyboardHandler: UIEventHandler = ctx => { + private readonly _keyboardHandler: UIEventHandler = ctx => { if (!this.widget.dragging || !this.widget.dragPreview) { return; } diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/legacy-drag-event-watcher.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/legacy-drag-event-watcher.ts index 2fba127016f32..97aa5f3673eb3 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/legacy-drag-event-watcher.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/legacy-drag-event-watcher.ts @@ -30,11 +30,11 @@ import { } from '../utils.js'; export class LegacyDragEventWatcher { - private _changeCursorToGrabbing = () => { + private readonly _changeCursorToGrabbing = () => { document.documentElement.classList.add('affine-drag-preview-grabbing'); }; - private _createDropIndicator = () => { + private readonly _createDropIndicator = () => { if (!this.widget.dropIndicator) { this.widget.dropIndicator = new DropIndicator(); this.widget.rootComponent.append(this.widget.dropIndicator); @@ -44,7 +44,7 @@ export class LegacyDragEventWatcher { /** * When drag end, should move blocks to drop position */ - private _dragEndHandler: UIEventHandler = ctx => { + private readonly _dragEndHandler: UIEventHandler = ctx => { this.widget.clearRaf(); if (!this.widget.dragging || !this.widget.dragPreview) return false; if (this.widget.draggingElements.length === 0 || this.widget.doc.readonly) { @@ -96,7 +96,7 @@ export class LegacyDragEventWatcher { * Update indicator position * Update drop block id */ - private _dragMoveHandler: UIEventHandler = ctx => { + private readonly _dragMoveHandler: UIEventHandler = ctx => { if ( this.widget.isHoverDragHandleVisible || this.widget.isTopLevelDragHandleVisible @@ -130,7 +130,7 @@ export class LegacyDragEventWatcher { /** * When start dragging, should set dragging elements and create drag preview */ - private _dragStartHandler: UIEventHandler = ctx => { + private readonly _dragStartHandler: UIEventHandler = ctx => { const state = ctx.get('pointerState'); // If not click left button to start dragging, should do nothing const { button } = state.raw; @@ -156,7 +156,7 @@ export class LegacyDragEventWatcher { return this._onDragStart(state); }; - private _onDragEnd = (state: PointerEventState) => { + private readonly _onDragEnd = (state: PointerEventState) => { const targetBlockId = this.widget.dropBlockId; const dropType = this.widget.dropType; const draggingElements = this.widget.draggingElements; @@ -306,7 +306,7 @@ export class LegacyDragEventWatcher { return true; }; - private _onDragMove = (state: PointerEventState) => { + private readonly _onDragMove = (state: PointerEventState) => { this.widget.clearRaf(); this.widget.rafID = requestAnimationFrame(() => { @@ -318,7 +318,7 @@ export class LegacyDragEventWatcher { return true; }; - private _onDragStart = (state: PointerEventState) => { + private readonly _onDragStart = (state: PointerEventState) => { // Get current hover block element by path const hoverBlock = this.widget.anchorBlockComponent.peek(); if (!hoverBlock) return false; @@ -432,7 +432,7 @@ export class LegacyDragEventWatcher { return true; }; - private _startDragging = ( + private readonly _startDragging = ( blocks: BlockComponent[], state: PointerEventState, dragPreviewEl?: HTMLElement, diff --git a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/pointer-event-watcher.ts b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/pointer-event-watcher.ts index 584fa3493130f..3c7b6363076ca 100644 --- a/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/pointer-event-watcher.ts +++ b/blocksuite/blocks/src/root-block/widgets/drag-handle/watchers/pointer-event-watcher.ts @@ -30,7 +30,7 @@ import { } from '../utils.js'; export class PointerEventWatcher { - private _canEditing = (noteBlock: BlockComponent) => { + private readonly _canEditing = (noteBlock: BlockComponent) => { if (noteBlock.doc.id !== this.widget.doc.id) return false; if (this.widget.mode === 'page') return true; @@ -50,7 +50,7 @@ export class PointerEventWatcher { * Should select the block and show slash menu if current block is not selected * Should clear selection if current block is the first selected block */ - private _clickHandler: UIEventHandler = ctx => { + private readonly _clickHandler: UIEventHandler = ctx => { if (!this.widget.isHoverDragHandleVisible) return; const state = ctx.get('pointerState'); @@ -90,7 +90,7 @@ export class PointerEventWatcher { }; // Need to consider block padding and scale - private _getTopWithBlockComponent = (block: BlockComponent) => { + private readonly _getTopWithBlockComponent = (block: BlockComponent) => { const computedStyle = getComputedStyle(block); const { top } = block.getBoundingClientRect(); const paddingTop = @@ -102,7 +102,7 @@ export class PointerEventWatcher { ); }; - private _containerStyle = computed(() => { + private readonly _containerStyle = computed(() => { const draggingAreaRect = this.widget.draggingAreaRect.value; if (!draggingAreaRect) return null; @@ -135,7 +135,7 @@ export class PointerEventWatcher { }; }); - private _grabberStyle = computed(() => { + private readonly _grabberStyle = computed(() => { const scaleInNote = this.widget.scaleInNote.value; return { width: `${DRAG_HANDLE_GRABBER_WIDTH * scaleInNote}px`, @@ -151,7 +151,7 @@ export class PointerEventWatcher { * When pointer move on block, should show drag handle * And update hover block id and path */ - private _pointerMoveOnBlock = (state: PointerEventState) => { + private readonly _pointerMoveOnBlock = (state: PointerEventState) => { if (this.widget.isTopLevelDragHandleVisible) return; const point = new Point(state.raw.x, state.raw.y); @@ -190,7 +190,7 @@ export class PointerEventWatcher { } }; - private _pointerOutHandler: UIEventHandler = ctx => { + private readonly _pointerOutHandler: UIEventHandler = ctx => { const state = ctx.get('pointerState'); state.raw.preventDefault(); @@ -214,57 +214,60 @@ export class PointerEventWatcher { } }; - private _throttledPointerMoveHandler = throttle(ctx => { - if ( - this.widget.doc.readonly || - this.widget.dragging || - !this.widget.isConnected - ) { - this.widget.hide(); - return; - } - if (this.widget.isTopLevelDragHandleVisible) return; - - const state = ctx.get('pointerState'); - const { target } = state.raw; - const element = captureEventTarget(target); - // When pointer not on block or on dragging, should do nothing - if (!element) return; - - // When pointer on drag handle, should do nothing - if (element.closest('.affine-drag-handle-container')) 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); - - const closestNoteBlock = getClosestNoteBlock( - this.widget.host, - this.widget.rootComponent, - point - ) as NoteBlockComponent | null; - - this.widget.noteScale.value = - this.widget.mode === 'page' - ? 1 - : (closestNoteBlock?.model.edgeless.scale ?? 1); - - if ( - closestNoteBlock && - this._canEditing(closestNoteBlock) && - !isOutOfNoteBlock( + private readonly _throttledPointerMoveHandler = throttle( + ctx => { + if ( + this.widget.doc.readonly || + this.widget.dragging || + !this.widget.isConnected + ) { + this.widget.hide(); + return; + } + if (this.widget.isTopLevelDragHandleVisible) return; + + const state = ctx.get('pointerState'); + const { target } = state.raw; + const element = captureEventTarget(target); + // When pointer not on block or on dragging, should do nothing + if (!element) return; + + // When pointer on drag handle, should do nothing + if (element.closest('.affine-drag-handle-container')) 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); + + const closestNoteBlock = getClosestNoteBlock( this.widget.host, - closestNoteBlock, - point, - this.widget.scaleInNote.peek() - ) - ) { - this._pointerMoveOnBlock(state); - return true; - } + this.widget.rootComponent, + point + ) as NoteBlockComponent | null; + + this.widget.noteScale.value = + this.widget.mode === 'page' + ? 1 + : (closestNoteBlock?.model.edgeless.scale ?? 1); + + if ( + closestNoteBlock && + this._canEditing(closestNoteBlock) && + !isOutOfNoteBlock( + this.widget.host, + closestNoteBlock, + point, + this.widget.scaleInNote.peek() + ) + ) { + this._pointerMoveOnBlock(state); + return true; + } - this.widget.hide(); - return false; - }, 1000 / 60); + this.widget.hide(); + return false; + }, + 1000 / 60 + ); // Multiple blocks: drag handle should show on the vertical middle of all blocks showDragHandleOnHoverBlock = () => { diff --git a/blocksuite/blocks/src/root-block/widgets/edgeless-auto-connect/edgeless-auto-connect.ts b/blocksuite/blocks/src/root-block/widgets/edgeless-auto-connect/edgeless-auto-connect.ts index 984aa7834f4bb..23a666430a6c9 100644 --- a/blocksuite/blocks/src/root-block/widgets/edgeless-auto-connect/edgeless-auto-connect.ts +++ b/blocksuite/blocks/src/root-block/widgets/edgeless-auto-connect/edgeless-auto-connect.ts @@ -172,7 +172,7 @@ export class EdgelessAutoConnectWidget extends WidgetComponent< } `; - private _updateLabels = () => { + private readonly _updateLabels = () => { const service = this.service; if (!service.doc.root) return; diff --git a/blocksuite/blocks/src/root-block/widgets/edgeless-copilot-panel/toolbar-entry.ts b/blocksuite/blocks/src/root-block/widgets/edgeless-copilot-panel/toolbar-entry.ts index bdf447ca43792..e5fc90cfdaf0a 100644 --- a/blocksuite/blocks/src/root-block/widgets/edgeless-copilot-panel/toolbar-entry.ts +++ b/blocksuite/blocks/src/root-block/widgets/edgeless-copilot-panel/toolbar-entry.ts @@ -21,7 +21,7 @@ export class EdgelessCopilotToolbarEntry extends WithDisposable(LitElement) { } `; - private _onClick = () => { + private readonly _onClick = () => { this.onClick?.(); this._showCopilotPanel(); }; diff --git a/blocksuite/blocks/src/root-block/widgets/edgeless-remote-selection/index.ts b/blocksuite/blocks/src/root-block/widgets/edgeless-remote-selection/index.ts index c690045275db7..1232667bf11a2 100644 --- a/blocksuite/blocks/src/root-block/widgets/edgeless-remote-selection/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/edgeless-remote-selection/index.ts @@ -81,14 +81,16 @@ export class EdgelessRemoteSelectionWidget extends WidgetComponent< private _remoteColorManager: RemoteColorManager | null = null; - private _updateOnElementChange = (element: string | { id: string }) => { + private readonly _updateOnElementChange = ( + element: string | { id: string } + ) => { const id = typeof element === 'string' ? element : element.id; if (this.isConnected && this.selection.hasRemote(id)) this._updateRemoteRects(); }; - private _updateRemoteCursor = () => { + private readonly _updateRemoteCursor = () => { const remoteCursors: EdgelessRemoteSelectionWidget['_remoteCursors'] = new Map(); const status = this.doc.awarenessStore.getStates(); @@ -106,7 +108,7 @@ export class EdgelessRemoteSelectionWidget extends WidgetComponent< this._remoteCursors = remoteCursors; }; - private _updateRemoteRects = () => { + private readonly _updateRemoteRects = () => { const { selection, block } = this; const remoteSelectionsMap = selection.remoteSurfaceSelectionsMap; const remoteRects: EdgelessRemoteSelectionWidget['_remoteRects'] = @@ -148,7 +150,7 @@ export class EdgelessRemoteSelectionWidget extends WidgetComponent< this._remoteRects = remoteRects; }; - private _updateTransform = requestThrottledConnectedFrame(() => { + private readonly _updateTransform = requestThrottledConnectedFrame(() => { const { translateX, translateY, zoom } = this.edgeless.service.viewport; this.style.setProperty('--v-zoom', `${zoom}`); diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/add-frame-button.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/add-frame-button.ts index bab88940de7e5..e0f583c2d73a8 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/add-frame-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/add-frame-button.ts @@ -14,7 +14,7 @@ export class EdgelessAddFrameButton extends WithDisposable(LitElement) { } `; - private _createFrame = () => { + private readonly _createFrame = () => { const frame = this.edgeless.service.frame.createFrameOnSelected(); if (!frame) return; this.edgeless.std diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/add-group-button.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/add-group-button.ts index 8a89ed07e753e..61fb223481868 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/add-group-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/add-group-button.ts @@ -16,7 +16,7 @@ export class EdgelessAddGroupButton extends WithDisposable(LitElement) { } `; - private _createGroup = () => { + private readonly _createGroup = () => { this.edgeless.service.createGroupFromSelected(); }; diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-attachment-button.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-attachment-button.ts index 2268b1351cc4b..d835d3e836e33 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-attachment-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-attachment-button.ts @@ -23,11 +23,11 @@ import { attachmentViewToggleMenu } from '../../../attachment-block/index.js'; import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js'; export class EdgelessChangeAttachmentButton extends WithDisposable(LitElement) { - private _download = () => { + private readonly _download = () => { this._block?.download(); }; - private _setCardStyle = (style: EmbedCardStyle) => { + private readonly _setCardStyle = (style: EmbedCardStyle) => { const bounds = Bound.deserialize(this.model.xywh); bounds.w = EMBED_CARD_WIDTH[style]; bounds.h = EMBED_CARD_HEIGHT[style]; @@ -35,7 +35,7 @@ export class EdgelessChangeAttachmentButton extends WithDisposable(LitElement) { this.model.doc.updateBlock(this.model, { style, xywh }); }; - private _showCaption = () => { + private readonly _showCaption = () => { this._block?.captionEditor?.show(); }; diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-brush-button.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-brush-button.ts index a50b6f146e460..c4db36174e781 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-brush-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-brush-button.ts @@ -44,12 +44,12 @@ function notEqual(key: K, value: BrushProps[K]) { } export class EdgelessChangeBrushButton extends WithDisposable(LitElement) { - private _setBrushColor = ({ detail: color }: ColorEvent) => { + private readonly _setBrushColor = ({ detail: color }: ColorEvent) => { this._setBrushProp('color', color); this._selectedColor = color; }; - private _setLineWidth = ({ detail: lineWidth }: LineWidthEvent) => { + private readonly _setLineWidth = ({ detail: lineWidth }: LineWidthEvent) => { this._setBrushProp('lineWidth', lineWidth); this._selectedSize = lineWidth; }; diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-embed-card-button.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-embed-card-button.ts index c67a849f48611..dd6287d6943c0 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-embed-card-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-embed-card-button.ts @@ -112,7 +112,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { } `; - private _convertToCardView = () => { + private readonly _convertToCardView = () => { if (this._isCardView) { return; } @@ -162,7 +162,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { this._doc.deleteBlock(this.model); }; - private _convertToEmbedView = () => { + private readonly _convertToEmbedView = () => { if (this._isEmbedView) { return; } @@ -217,7 +217,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { this._doc.deleteBlock(this.model); }; - private _copyUrl = () => { + private readonly _copyUrl = () => { let url!: ReturnType; if ('url' in this.model) { @@ -241,7 +241,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { private _embedOptions: EmbedOptions | null = null; - private _getScale = () => { + private readonly _getScale = () => { if ('scale' in this.model) { return this.model.scale ?? 1; } else if (isEmbedHtmlBlock(this.model)) { @@ -252,11 +252,11 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { return bound.h / EMBED_CARD_HEIGHT[this.model.style]; }; - private _open = () => { + private readonly _open = () => { this._blockComponent?.open(); }; - private _openEditPopup = (e: MouseEvent) => { + private readonly _openEditPopup = (e: MouseEvent) => { e.stopPropagation(); if (isEmbedHtmlBlock(this.model)) return; @@ -277,12 +277,12 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { }); }; - private _peek = () => { + private readonly _peek = () => { if (!this._blockComponent) return; peek(this._blockComponent); }; - private _setCardStyle = (style: EmbedCardStyle) => { + private readonly _setCardStyle = (style: EmbedCardStyle) => { const bounds = Bound.deserialize(this.model.xywh); bounds.w = EMBED_CARD_WIDTH[style]; bounds.h = EMBED_CARD_HEIGHT[style]; @@ -295,7 +295,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { }); }; - private _setEmbedScale = (scale: number) => { + private readonly _setEmbedScale = (scale: number) => { if (isEmbedHtmlBlock(this.model)) return; const bound = Bound.deserialize(this.model.xywh); @@ -320,7 +320,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { }); }; - private _toggleCardScaleSelector = (e: Event) => { + private readonly _toggleCardScaleSelector = (e: Event) => { const opened = (e as CustomEvent).detail; if (!opened) return; @@ -329,7 +329,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { }); }; - private _toggleCardStyleSelector = (e: Event) => { + private readonly _toggleCardStyleSelector = (e: Event) => { const opened = (e as CustomEvent).detail; if (!opened) return; @@ -338,7 +338,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { }); }; - private _toggleViewSelector = (e: Event) => { + private readonly _toggleViewSelector = (e: Event) => { const opened = (e as CustomEvent).detail; if (!opened) return; @@ -347,7 +347,7 @@ export class EdgelessChangeEmbedCardButton extends WithDisposable(LitElement) { }); }; - private _trackViewSelected = (type: string) => { + private readonly _trackViewSelected = (type: string) => { track(this.std, this.model, this._viewType, 'SelectedView', { control: 'select view', type: `${type} view`, diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-image-button.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-image-button.ts index 45f685cd7cc95..aa0ac93c7a344 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-image-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-image-button.ts @@ -9,12 +9,12 @@ import { downloadImageBlob } from '../../../image-block/utils.js'; import type { EdgelessRootBlockComponent } from '../../edgeless/edgeless-root-block.js'; export class EdgelessChangeImageButton extends WithDisposable(LitElement) { - private _download = () => { + private readonly _download = () => { if (!this._blockComponent) return; downloadImageBlob(this._blockComponent).catch(console.error); }; - private _showCaption = () => { + private readonly _showCaption = () => { this._blockComponent?.captionEditor?.show(); }; diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-mindmap-button.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-mindmap-button.ts index 40f20e94ea753..c7d114125beca 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-mindmap-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-mindmap-button.ts @@ -155,7 +155,7 @@ export class EdgelessChangeMindmapLayoutPanel extends LitElement { } export class EdgelessChangeMindmapButton extends WithDisposable(LitElement) { - private _updateLayoutType = (layoutType: LayoutType) => { + private readonly _updateLayoutType = (layoutType: LayoutType) => { this.edgeless.std.get(EditPropsStore).recordLastProps('mindmap', { layoutType, }); @@ -166,7 +166,7 @@ export class EdgelessChangeMindmapButton extends WithDisposable(LitElement) { this.layoutType = layoutType; }; - private _updateStyle = (style: MindmapStyle) => { + private readonly _updateStyle = (style: MindmapStyle) => { this.edgeless.std.get(EditPropsStore).recordLastProps('mindmap', { style }); this._mindmaps.forEach(element => (element.style = style)); }; diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-note-button.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-note-button.ts index ab5a56793300f..23aa1e8b64e71 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-note-button.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-note-button.ts @@ -78,7 +78,7 @@ function getMostCommonBackground( } export class EdgelessChangeNoteButton extends WithDisposable(LitElement) { - private _setBorderRadius = (borderRadius: number) => { + private readonly _setBorderRadius = (borderRadius: number) => { this.notes.forEach(note => { const props = { edgeless: { @@ -92,7 +92,7 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) { }); }; - private _setNoteScale = (scale: number) => { + private readonly _setNoteScale = (scale: number) => { this.notes.forEach(note => { this.doc.updateBlock(note, () => { const bound = Bound.deserialize(note.xywh); diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-text-menu.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-text-menu.ts index f7a6c1479bc53..e207b5b35edbd 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-text-menu.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/change-text-menu.ts @@ -176,7 +176,7 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) { } `; - private _setFontFamily = (fontFamily: FontFamily) => { + private readonly _setFontFamily = (fontFamily: FontFamily) => { const currentFontWeight = getMostCommonFontWeight(this.elements); const fontWeight = TextUtils.isFontWeightSupported( fontFamily, @@ -199,7 +199,7 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) { }); }; - private _setFontSize = (fontSize: number) => { + private readonly _setFontSize = (fontSize: number) => { const props = { fontSize }; this.elements.forEach(element => { this.service.updateElement(element.id, buildProps(element, props)); @@ -207,7 +207,7 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) { }); }; - private _setFontWeightAndStyle = ( + private readonly _setFontWeightAndStyle = ( fontWeight: FontWeight, fontStyle: FontStyle ) => { @@ -218,21 +218,23 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) { }); }; - private _setTextAlign = (textAlign: TextAlign) => { + private readonly _setTextAlign = (textAlign: TextAlign) => { const props = { textAlign }; this.elements.forEach(element => { this.service.updateElement(element.id, buildProps(element, props)); }); }; - private _setTextColor = ({ detail: color }: ColorEvent) => { + private readonly _setTextColor = ({ detail: color }: ColorEvent) => { const props = { color }; this.elements.forEach(element => { this.service.updateElement(element.id, buildProps(element, props)); }); }; - private _updateElementBound = (element: BlockSuite.EdgelessTextModelType) => { + private readonly _updateElementBound = ( + element: BlockSuite.EdgelessTextModelType + ) => { const elementType = this.elementType; if (elementType === 'text' && element instanceof TextElementModel) { // the change of font family will change the bound of the text diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/index.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/index.ts index 810a14654a395..e41a0381a030e 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/index.ts @@ -112,7 +112,7 @@ export class EdgelessElementToolbarWidget extends WidgetComponent< } `; - private _quickConnect = ({ x, y }: MouseEvent) => { + private readonly _quickConnect = ({ x, y }: MouseEvent) => { const element = this.selection.selectedElements[0]; const point = this.edgeless.service.viewport.toViewCoordFromClientCoord([ x, @@ -127,7 +127,9 @@ export class EdgelessElementToolbarWidget extends WidgetComponent< ctc.quickConnect(point, element); }; - private _updateOnSelectedChange = (element: string | { id: string }) => { + private readonly _updateOnSelectedChange = ( + element: string | { id: string } + ) => { const id = typeof element === 'string' ? element : element.id; if (this.isConnected && !this._dragging && this.selection.has(id)) { diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/more-menu/context.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/more-menu/context.ts index d1a3b1eeaacdc..a90d46201761a 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/more-menu/context.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/more-menu/context.ts @@ -20,13 +20,13 @@ import { } from '../../../edgeless/utils/query.js'; export class ElementToolbarMoreMenuContext extends MenuContext { - #empty = true; + readonly #empty = true; - #includedFrame = false; + readonly #includedFrame = false; - #multiple = false; + readonly #multiple = false; - #single = false; + readonly #single = false; edgeless!: EdgelessRootBlockComponent; diff --git a/blocksuite/blocks/src/root-block/widgets/embed-card-toolbar/embed-card-toolbar.ts b/blocksuite/blocks/src/root-block/widgets/embed-card-toolbar/embed-card-toolbar.ts index 8cc1ee0aad149..1e3a3becbef80 100644 --- a/blocksuite/blocks/src/root-block/widgets/embed-card-toolbar/embed-card-toolbar.ts +++ b/blocksuite/blocks/src/root-block/widgets/embed-card-toolbar/embed-card-toolbar.ts @@ -82,7 +82,7 @@ export class EmbedCardToolbar extends WidgetComponent< private _abortController = new AbortController(); - private _copyUrl = () => { + private readonly _copyUrl = () => { const model = this.focusModel; if (!model) return; @@ -109,7 +109,7 @@ export class EmbedCardToolbar extends WidgetComponent< private _embedOptions: EmbedOptions | null = null; - private _openEditPopup = (e: MouseEvent) => { + private readonly _openEditPopup = (e: MouseEvent) => { e.stopPropagation(); const model = this.focusModel; @@ -126,12 +126,12 @@ export class EmbedCardToolbar extends WidgetComponent< }); }; - private _resetAbortController = () => { + private readonly _resetAbortController = () => { this._abortController.abort(); this._abortController = new AbortController(); }; - private _showCaption = () => { + private readonly _showCaption = () => { const focusBlock = this.focusBlock; if (!focusBlock) { return; @@ -151,7 +151,7 @@ export class EmbedCardToolbar extends WidgetComponent< }); }; - private _toggleCardStyleSelector = (e: Event) => { + private readonly _toggleCardStyleSelector = (e: Event) => { const opened = (e as CustomEvent).detail; if (!opened) return; @@ -163,7 +163,7 @@ export class EmbedCardToolbar extends WidgetComponent< }); }; - private _toggleViewSelector = (e: Event) => { + private readonly _toggleViewSelector = (e: Event) => { const opened = (e as CustomEvent).detail; if (!opened) return; @@ -175,7 +175,7 @@ export class EmbedCardToolbar extends WidgetComponent< }); }; - private _trackViewSelected = (type: string) => { + private readonly _trackViewSelected = (type: string) => { const model = this.focusModel; if (!model) return; diff --git a/blocksuite/blocks/src/root-block/widgets/format-bar/config.ts b/blocksuite/blocks/src/root-block/widgets/format-bar/config.ts index 42722a3ebf45e..1b115d4058001 100644 --- a/blocksuite/blocks/src/root-block/widgets/format-bar/config.ts +++ b/blocksuite/blocks/src/root-block/widgets/format-bar/config.ts @@ -209,28 +209,30 @@ export function toolbarDefaultConfig(toolbar: AffineFormatBarWidget) { const doc = host.doc; const autofill = getTitleFromSelectedModels(selectedModels); - void promptDocTitle(host, autofill).then(async title => { - if (title === null) return; - await convertSelectedBlocksToLinkedDoc( - host.std, - doc, - draftedModels, - title - ); - notifyDocCreated(host, doc); - host.std.getOptional(TelemetryProvider)?.track('DocCreated', { - control: 'create linked doc', - page: 'doc editor', - module: 'format toolbar', - type: 'embed-linked-doc', - }); - host.std.getOptional(TelemetryProvider)?.track('LinkedDocCreated', { - control: 'create linked doc', - page: 'doc editor', - module: 'format toolbar', - type: 'embed-linked-doc', - }); - }); + promptDocTitle(host, autofill) + .then(async title => { + if (title === null) return; + await convertSelectedBlocksToLinkedDoc( + host.std, + doc, + draftedModels, + title + ); + notifyDocCreated(host, doc); + host.std.getOptional(TelemetryProvider)?.track('DocCreated', { + control: 'create linked doc', + page: 'doc editor', + module: 'format toolbar', + type: 'embed-linked-doc', + }); + host.std.getOptional(TelemetryProvider)?.track('LinkedDocCreated', { + control: 'create linked doc', + page: 'doc editor', + module: 'format toolbar', + type: 'embed-linked-doc', + }); + }) + .catch(console.error); }, showWhen: chain => { const [_, ctx] = chain diff --git a/blocksuite/blocks/src/root-block/widgets/image-toolbar/index.ts b/blocksuite/blocks/src/root-block/widgets/image-toolbar/index.ts index 8cb066fdcce6b..c16a69d45245a 100644 --- a/blocksuite/blocks/src/root-block/widgets/image-toolbar/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/image-toolbar/index.ts @@ -25,7 +25,7 @@ export class AffineImageToolbarWidget extends WidgetComponent< private _isActivated = false; - private _setHoverController = () => { + private readonly _setHoverController = () => { this._hoverController = null; this._hoverController = new HoverController( this, diff --git a/blocksuite/blocks/src/root-block/widgets/keyboard-toolbar/index.ts b/blocksuite/blocks/src/root-block/widgets/keyboard-toolbar/index.ts index 87d083b213779..610bd7422deb7 100644 --- a/blocksuite/blocks/src/root-block/widgets/keyboard-toolbar/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/keyboard-toolbar/index.ts @@ -16,7 +16,7 @@ export class AffineKeyboardToolbarWidget extends WidgetComponent< RootBlockModel, PageRootBlockComponent > { - private _close = (blur: boolean) => { + private readonly _close = (blur: boolean) => { if (blur) { if (document.activeElement === this._docTitle) { this._docTitle?.blur(); diff --git a/blocksuite/blocks/src/root-block/widgets/keyboard-toolbar/keyboard-toolbar.ts b/blocksuite/blocks/src/root-block/widgets/keyboard-toolbar/keyboard-toolbar.ts index 38d3d4e214977..0950954fd99a6 100644 --- a/blocksuite/blocks/src/root-block/widgets/keyboard-toolbar/keyboard-toolbar.ts +++ b/blocksuite/blocks/src/root-block/widgets/keyboard-toolbar/keyboard-toolbar.ts @@ -90,7 +90,7 @@ export class AffineKeyboardToolbar extends SignalWatcher( private readonly _path$ = signal([]); - private scrollCurrentBlockIntoView = () => { + private readonly scrollCurrentBlockIntoView = () => { const { std } = this.rootComponent; std.command .chain() diff --git a/blocksuite/blocks/src/root-block/widgets/linked-doc/import-doc/import-doc.ts b/blocksuite/blocks/src/root-block/widgets/linked-doc/import-doc/import-doc.ts index 864fb12b5412c..accd158c096a2 100644 --- a/blocksuite/blocks/src/root-block/widgets/linked-doc/import-doc/import-doc.ts +++ b/blocksuite/blocks/src/root-block/widgets/linked-doc/import-doc/import-doc.ts @@ -30,10 +30,10 @@ export class ImportDoc extends WithDisposable(LitElement) { static override styles = styles; constructor( - private collection: DocCollection, - private onSuccess?: OnSuccessHandler, - private onFail?: OnFailHandler, - private abortController = new AbortController() + private readonly collection: DocCollection, + private readonly onSuccess?: OnSuccessHandler, + private readonly onFail?: OnFailHandler, + private readonly abortController = new AbortController() ) { super(); diff --git a/blocksuite/blocks/src/root-block/widgets/linked-doc/index.ts b/blocksuite/blocks/src/root-block/widgets/linked-doc/index.ts index 4dda0483074a2..2d0bb508e0aab 100644 --- a/blocksuite/blocks/src/root-block/widgets/linked-doc/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/linked-doc/index.ts @@ -68,7 +68,7 @@ export class AffineLinkedDocWidget extends WidgetComponent< private _inlineEditor: AffineInlineEditor | null = null; - private _observeInputRects = () => { + private readonly _observeInputRects = () => { if (!this._inlineEditor) return; const updateInputRects = () => { diff --git a/blocksuite/blocks/src/root-block/widgets/linked-doc/linked-doc-popover.ts b/blocksuite/blocks/src/root-block/widgets/linked-doc/linked-doc-popover.ts index 4b391844d7b26..f8c9ff9ce2250 100644 --- a/blocksuite/blocks/src/root-block/widgets/linked-doc/linked-doc-popover.ts +++ b/blocksuite/blocks/src/root-block/widgets/linked-doc/linked-doc-popover.ts @@ -32,7 +32,7 @@ export class LinkedDocPopover extends SignalWatcher( ) { static override styles = linkedDocPopoverStyles; - private _abort = () => { + private readonly _abort = () => { // remove popover dom this.context.close(); // clear input query @@ -43,9 +43,9 @@ export class LinkedDocPopover extends SignalWatcher( ); }; - private _expanded = new Map(); + private readonly _expanded = new Map(); - private _updateLinkedDocGroup = async () => { + private readonly _updateLinkedDocGroup = async () => { const query = this._query; if (this._updateLinkedDocGroupAbortController) { this._updateLinkedDocGroupAbortController.abort(); diff --git a/blocksuite/blocks/src/root-block/widgets/linked-doc/mobile-linked-doc-menu.ts b/blocksuite/blocks/src/root-block/widgets/linked-doc/mobile-linked-doc-menu.ts index 7ce603c4e7fd3..34d7e4e055121 100644 --- a/blocksuite/blocks/src/root-block/widgets/linked-doc/mobile-linked-doc-menu.ts +++ b/blocksuite/blocks/src/root-block/widgets/linked-doc/mobile-linked-doc-menu.ts @@ -45,7 +45,7 @@ export class AffineMobileLinkedDocMenu extends SignalWatcher( private readonly _linkedDocGroup$ = signal([]); - private _renderGroup = (group: LinkedMenuGroup) => { + private readonly _renderGroup = (group: LinkedMenuGroup) => { let items = resolveSignal(group.items); const isOverflow = !!group.maxDisplay && items.length > group.maxDisplay; @@ -90,7 +90,7 @@ export class AffineMobileLinkedDocMenu extends SignalWatcher( `; }; - private _scrollInputToTop = () => { + private readonly _scrollInputToTop = () => { const { inlineEditor } = this.context; const { scrollContainer, scrollTopOffset } = this.context.config.mobile; diff --git a/blocksuite/blocks/src/root-block/widgets/page-dragging-area/page-dragging-area.ts b/blocksuite/blocks/src/root-block/widgets/page-dragging-area/page-dragging-area.ts index eed66f81726e2..cbb068ab95d5a 100644 --- a/blocksuite/blocks/src/root-block/widgets/page-dragging-area/page-dragging-area.ts +++ b/blocksuite/blocks/src/root-block/widgets/page-dragging-area/page-dragging-area.ts @@ -60,7 +60,7 @@ export class AffinePageDraggingAreaWidget extends WidgetComponent< private _rafID = 0; - private _updateDraggingArea = ( + private readonly _updateDraggingArea = ( state: PointerEventState, shouldAutoScroll: boolean ) => { diff --git a/blocksuite/blocks/src/root-block/widgets/pie-menu/index.ts b/blocksuite/blocks/src/root-block/widgets/pie-menu/index.ts index 6bee2823d728f..cab17eb6de1ce 100644 --- a/blocksuite/blocks/src/root-block/widgets/pie-menu/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/pie-menu/index.ts @@ -23,13 +23,13 @@ noop(PieNodeChild); export const AFFINE_PIE_MENU_WIDGET = 'affine-pie-menu-widget'; export class AffinePieMenuWidget extends WidgetComponent { - private _handleCursorPos = (ctx: UIEventStateContext) => { + private readonly _handleCursorPos = (ctx: UIEventStateContext) => { const ev = ctx.get('pointerState'); const { x, y } = ev.point; this.mouse = [x, y]; }; - private _handleKeyUp = (ctx: UIEventStateContext) => { + private readonly _handleKeyUp = (ctx: UIEventStateContext) => { if (!this.currentMenu) return; const ev = ctx.get('keyboardState'); const { trigger } = this.currentMenu.schema; diff --git a/blocksuite/blocks/src/root-block/widgets/pie-menu/menu.ts b/blocksuite/blocks/src/root-block/widgets/pie-menu/menu.ts index 1b98182316d7a..d914a5330685c 100644 --- a/blocksuite/blocks/src/root-block/widgets/pie-menu/menu.ts +++ b/blocksuite/blocks/src/root-block/widgets/pie-menu/menu.ts @@ -32,7 +32,7 @@ const { toDegree, toRadian } = CommonUtils; export class PieMenu extends WithDisposable(LitElement) { static override styles = pieMenuStyles; - private _handleKeyDown = (ev: KeyboardEvent) => { + private readonly _handleKeyDown = (ev: KeyboardEvent) => { const { key } = ev; if (key === 'Escape') { return this.abortController.abort(); @@ -49,7 +49,7 @@ export class PieMenu extends WithDisposable(LitElement) { } }; - private _handlePointerMove = (ev: PointerEvent) => { + private readonly _handlePointerMove = (ev: PointerEvent) => { const { clientX, clientY } = ev; const { ACTIVATE_THRESHOLD_MIN } = PieManager.settings; @@ -73,7 +73,7 @@ export class PieMenu extends WithDisposable(LitElement) { private _openSubmenuTimeout?: NodeJS.Timeout; - private selectChildWithIndex = (index: number) => { + private readonly selectChildWithIndex = (index: number) => { const activeNode = this.activeNode; if (!activeNode || isNaN(index)) return; diff --git a/blocksuite/blocks/src/root-block/widgets/pie-menu/node.ts b/blocksuite/blocks/src/root-block/widgets/pie-menu/node.ts index b2c473ff0a9c8..69cd37e4a9a8f 100644 --- a/blocksuite/blocks/src/root-block/widgets/pie-menu/node.ts +++ b/blocksuite/blocks/src/root-block/widgets/pie-menu/node.ts @@ -18,19 +18,19 @@ import { export class PieNode extends WithDisposable(LitElement) { static override styles = pieNodeStyles; - private _handleChildNodeClick = () => { + private readonly _handleChildNodeClick = () => { this.select(); if (isCommandNode(this.model)) this.menu.close(); }; - private _handleGoBack = () => { + private readonly _handleGoBack = () => { // If the node is not active and if it is hovered then we can go back to that node if (this.menu.activeNode !== this) { this.menu.popSelectionChainTo(this); } }; - private _onPointerAngleUpdated = (angle: number | null) => { + private readonly _onPointerAngleUpdated = (angle: number | null) => { this._rotatorAngle = angle; this.menu.activeNode.requestUpdate(); diff --git a/blocksuite/blocks/src/root-block/widgets/pie-menu/pie-manager.ts b/blocksuite/blocks/src/root-block/widgets/pie-menu/pie-manager.ts index dacaecaa270b5..31e4c203ea82e 100644 --- a/blocksuite/blocks/src/root-block/widgets/pie-menu/pie-manager.ts +++ b/blocksuite/blocks/src/root-block/widgets/pie-menu/pie-manager.ts @@ -12,7 +12,7 @@ import type { PieMenuSchema } from './base.js'; export class PieManager { private static registeredSchemas: Record = {}; - private static schemas = new Set(); + private static readonly schemas = new Set(); static settings = { /** diff --git a/blocksuite/blocks/src/root-block/widgets/slash-menu/config.ts b/blocksuite/blocks/src/root-block/widgets/slash-menu/config.ts index 09c3be0fa83b9..2fb9a43e88915 100644 --- a/blocksuite/blocks/src/root-block/widgets/slash-menu/config.ts +++ b/blocksuite/blocks/src/root-block/widgets/slash-menu/config.ts @@ -588,12 +588,14 @@ export const defaultSlashMenuConfig: SlashMenuConfig = { ); const dataViewModel = rootComponent.doc.getBlock(id)!; - Promise.resolve().then(() => { - const dataView = rootComponent.std.view.getBlock( - dataViewModel.id - ) as DataViewBlockComponent | null; - dataView?.dataSource.viewManager.viewAdd('table'); - }); + Promise.resolve() + .then(() => { + const dataView = rootComponent.std.view.getBlock( + dataViewModel.id + ) as DataViewBlockComponent | null; + dataView?.dataSource.viewManager.viewAdd('table'); + }) + .catch(console.error); tryRemoveEmptyLine(model); }, }, diff --git a/blocksuite/blocks/src/root-block/widgets/slash-menu/index.ts b/blocksuite/blocks/src/root-block/widgets/slash-menu/index.ts index 79d201c2685fe..e177f22039171 100644 --- a/blocksuite/blocks/src/root-block/widgets/slash-menu/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/slash-menu/index.ts @@ -108,7 +108,9 @@ export const AFFINE_SLASH_MENU_WIDGET = 'affine-slash-menu-widget'; export class AffineSlashMenuWidget extends WidgetComponent { static DEFAULT_CONFIG = defaultSlashMenuConfig; - private _getInlineEditor = (evt: KeyboardEvent | CompositionEvent) => { + private readonly _getInlineEditor = ( + evt: KeyboardEvent | CompositionEvent + ) => { if (evt.target instanceof HTMLElement) { const editor = ( evt.target.closest('.inline-editor') as { @@ -129,7 +131,7 @@ export class AffineSlashMenuWidget extends WidgetComponent { return getInlineEditorByModel(this.host, model); }; - private _handleInput = ( + private readonly _handleInput = ( inlineEditor: InlineEditor, isCompositionEnd: boolean ) => { @@ -192,7 +194,7 @@ export class AffineSlashMenuWidget extends WidgetComponent { }); }; - private _onCompositionEnd = (ctx: UIEventStateContext) => { + private readonly _onCompositionEnd = (ctx: UIEventStateContext) => { const event = ctx.get('defaultState').event as CompositionEvent; if ( @@ -208,7 +210,7 @@ export class AffineSlashMenuWidget extends WidgetComponent { this._handleInput(inlineEditor, true); }; - private _onKeyDown = (ctx: UIEventStateContext) => { + private readonly _onKeyDown = (ctx: UIEventStateContext) => { const eventState = ctx.get('keyboardState'); const event = eventState.raw; diff --git a/blocksuite/blocks/src/root-block/widgets/slash-menu/slash-menu-popover.ts b/blocksuite/blocks/src/root-block/widgets/slash-menu/slash-menu-popover.ts index a57f61be3838b..c879fff1b6a16 100644 --- a/blocksuite/blocks/src/root-block/widgets/slash-menu/slash-menu-popover.ts +++ b/blocksuite/blocks/src/root-block/widgets/slash-menu/slash-menu-popover.ts @@ -46,7 +46,7 @@ type InnerSlashMenuContext = SlashMenuContext & { export class SlashMenu extends WithDisposable(LitElement) { static override styles = styles; - private _handleClickItem = (item: SlashMenuActionItem) => { + private readonly _handleClickItem = (item: SlashMenuActionItem) => { // Need to remove the search string // We must to do clean the slash string before we do the action // Otherwise, the action may change the model and cause the slash string to be changed @@ -64,7 +64,7 @@ export class SlashMenu extends WithDisposable(LitElement) { .catch(console.error); }; - private _initItemPathMap = () => { + private readonly _initItemPathMap = () => { const traverse = (item: SlashMenuStaticItem, path: number[]) => { this._itemPathMap.set(item, [...path]); if (isSubMenuItem(item)) { @@ -79,13 +79,13 @@ export class SlashMenu extends WithDisposable(LitElement) { private _innerSlashMenuContext!: InnerSlashMenuContext; - private _itemPathMap = new Map(); + private readonly _itemPathMap = new Map(); private _queryState: 'off' | 'on' | 'no_result' = 'off'; - private _startRange = this.inlineEditor.getInlineRange(); + private readonly _startRange = this.inlineEditor.getInlineRange(); - private _updateFilteredItems = () => { + private readonly _updateFilteredItems = () => { const query = this._query; if (query === null) { this.abortController.abort(); @@ -152,8 +152,8 @@ export class SlashMenu extends WithDisposable(LitElement) { } constructor( - private inlineEditor: AffineInlineEditor, - private abortController = new AbortController() + private readonly inlineEditor: AffineInlineEditor, + private readonly abortController = new AbortController() ) { super(); } @@ -301,7 +301,7 @@ export class SlashMenu extends WithDisposable(LitElement) { export class InnerSlashMenu extends WithDisposable(LitElement) { static override styles = styles; - private _closeSubMenu = () => { + private readonly _closeSubMenu = () => { this._subMenuAbortController?.abort(); this._subMenuAbortController = null; this._currentSubMenu = null; @@ -309,7 +309,7 @@ export class InnerSlashMenu extends WithDisposable(LitElement) { private _currentSubMenu: SlashSubMenu | null = null; - private _openSubMenu = (item: SlashSubMenu) => { + private readonly _openSubMenu = (item: SlashSubMenu) => { if (item === this._currentSubMenu) return; const itemElement = this.shadowRoot?.querySelector( @@ -351,7 +351,7 @@ export class InnerSlashMenu extends WithDisposable(LitElement) { subMenuElement.focus(); }; - private _renderActionItem = (item: SlashMenuActionItem) => { + private readonly _renderActionItem = (item: SlashMenuActionItem) => { const { name, icon, description, tooltip, customTemplate } = item; const hover = item === this._activeItem; @@ -387,11 +387,11 @@ export class InnerSlashMenu extends WithDisposable(LitElement) { `; }; - private _renderGroupItem = (item: SlashMenuGroupDivider) => { + private readonly _renderGroupItem = (item: SlashMenuGroupDivider) => { return html`
${item.groupName}
`; }; - private _renderItem = (item: SlashMenuStaticItem) => { + private readonly _renderItem = (item: SlashMenuStaticItem) => { if (isGroupDivider(item)) return this._renderGroupItem(item); else if (isActionItem(item)) return this._renderActionItem(item); else if (isSubMenuItem(item)) return this._renderSubMenuItem(item); @@ -402,7 +402,7 @@ export class InnerSlashMenu extends WithDisposable(LitElement) { } }; - private _renderSubMenuItem = (item: SlashSubMenu) => { + private readonly _renderSubMenuItem = (item: SlashSubMenu) => { const { name, icon, description } = item; const hover = item === this._activeItem; diff --git a/blocksuite/blocks/src/root-block/widgets/surface-ref-toolbar/surface-ref-toolbar.ts b/blocksuite/blocks/src/root-block/widgets/surface-ref-toolbar/surface-ref-toolbar.ts index cce075508adaa..a3615a16da577 100644 --- a/blocksuite/blocks/src/root-block/widgets/surface-ref-toolbar/surface-ref-toolbar.ts +++ b/blocksuite/blocks/src/root-block/widgets/surface-ref-toolbar/surface-ref-toolbar.ts @@ -42,7 +42,7 @@ export class AffineSurfaceRefToolbar extends WidgetComponent< moreGroups: MenuItemGroup[] = cloneGroups(BUILT_IN_GROUPS); - private _hoverController = new HoverController( + private readonly _hoverController = new HoverController( this, ({ abortController }) => { const surfaceRefBlock = this.block; diff --git a/blocksuite/blocks/src/surface-ref-block/surface-ref-block.ts b/blocksuite/blocks/src/surface-ref-block/surface-ref-block.ts index 98d7a21ddc987..8c6b3cfffd8e4 100644 --- a/blocksuite/blocks/src/surface-ref-block/surface-ref-block.ts +++ b/blocksuite/blocks/src/surface-ref-block/surface-ref-block.ts @@ -239,7 +239,8 @@ export class SurfaceRefBlockComponent extends BlockComponent< private _previewDoc: Doc | null = null; - private _previewSpec = SpecProvider.getInstance().getSpec('edgeless:preview'); + private readonly _previewSpec = + SpecProvider.getInstance().getSpec('edgeless:preview'); private _referencedModel: BlockSuite.EdgelessModel | null = null; @@ -459,7 +460,7 @@ export class SurfaceRefBlockComponent extends BlockComponent< class FrameGroupViewWatcher extends LifeCycleWatcher { static override readonly key = 'surface-ref-group-view-watcher'; - private _disposable = new DisposableGroup(); + private readonly _disposable = new DisposableGroup(); override mounted() { const edgelessService = this.std.get(EdgelessRootService); diff --git a/blocksuite/framework/block-std/src/clipboard/index.ts b/blocksuite/framework/block-std/src/clipboard/index.ts index 48aee32dc5404..a1d8295e9b9b1 100644 --- a/blocksuite/framework/block-std/src/clipboard/index.ts +++ b/blocksuite/framework/block-std/src/clipboard/index.ts @@ -60,10 +60,10 @@ export function onlyContainImgElement( export class Clipboard extends LifeCycleWatcher { static override readonly key = 'clipboard'; - private _adapterMap: AdapterMap = new Map(); + private readonly _adapterMap: AdapterMap = new Map(); // Need to be cloned to a map for later use - private _getDataByType = (clipboardData: DataTransfer) => { + private readonly _getDataByType = (clipboardData: DataTransfer) => { const data = new Map(); for (const type of clipboardData.types) { if (type === 'Files') { @@ -105,7 +105,7 @@ export class Clipboard extends LifeCycleWatcher { }; }; - private _getSnapshotByPriority = async ( + private readonly _getSnapshotByPriority = async ( getItem: (type: string) => string | File[], doc: Doc, parent?: string, diff --git a/blocksuite/framework/block-std/src/command/manager.ts b/blocksuite/framework/block-std/src/command/manager.ts index 974bfb22a33c0..a5078d8ea2e4e 100644 --- a/blocksuite/framework/block-std/src/command/manager.ts +++ b/blocksuite/framework/block-std/src/command/manager.ts @@ -128,9 +128,9 @@ import type { export class CommandManager extends LifeCycleWatcher { static override readonly key = 'commandManager'; - private _commands = new Map(); + private readonly _commands = new Map(); - private _createChain = ( + private readonly _createChain = ( methods: Record, _cmds: Command[] ): Chain => { @@ -239,7 +239,7 @@ export class CommandManager extends LifeCycleWatcher { } as Chain; }; - private _getCommandCtx = (): InitCommandCtx => { + private readonly _getCommandCtx = (): InitCommandCtx => { return { std: this.std, }; diff --git a/blocksuite/framework/block-std/src/event/control/clipboard.ts b/blocksuite/framework/block-std/src/event/control/clipboard.ts index 0f746e85f4898..2993a61178f4a 100644 --- a/blocksuite/framework/block-std/src/event/control/clipboard.ts +++ b/blocksuite/framework/block-std/src/event/control/clipboard.ts @@ -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( diff --git a/blocksuite/framework/block-std/src/event/control/keyboard.ts b/blocksuite/framework/block-std/src/event/control/keyboard.ts index e3e70d63cf9c6..38d590e98bf30 100644 --- a/blocksuite/framework/block-std/src/event/control/keyboard.ts +++ b/blocksuite/framework/block-std/src/event/control/keyboard.ts @@ -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( diff --git a/blocksuite/framework/block-std/src/event/control/pointer.ts b/blocksuite/framework/block-std/src/event/control/pointer.ts index a4e4458f9d496..78a98b7179d73 100644 --- a/blocksuite/framework/block-std/src/event/control/pointer.ts +++ b/blocksuite/framework/block-std/src/event/control/pointer.ts @@ -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(); + private readonly _lastStates = new Map(); - 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(); + private readonly _startStates = new Map(); - 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), diff --git a/blocksuite/framework/block-std/src/event/control/range.ts b/blocksuite/framework/block-std/src/event/control/range.ts index c70bcb68782db..51ab67e09972f 100644 --- a/blocksuite/framework/block-std/src/event/control/range.ts +++ b/blocksuite/framework/block-std/src/event/control/range.ts @@ -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); diff --git a/blocksuite/framework/block-std/src/event/dispatcher.ts b/blocksuite/framework/block-std/src/event/dispatcher.ts index 05502bc409907..5f77628087072 100644 --- a/blocksuite/framework/block-std/src/event/dispatcher.ts +++ b/blocksuite/framework/block-std/src/event/dispatcher.ts @@ -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] => [name, []]) ) as Record>; - private _keyboardControl: KeyboardControl; + private readonly _keyboardControl: KeyboardControl; - private _pointerControl: PointerControl; + private readonly _pointerControl: PointerControl; - private _rangeControl: RangeControl; + private readonly _rangeControl: RangeControl; bindHotkey = (...args: Parameters) => this._keyboardControl.bindHotkey(...args); diff --git a/blocksuite/framework/block-std/src/gfx/controller.ts b/blocksuite/framework/block-std/src/gfx/controller.ts index c62ad73c24907..4a4a707fd0239 100644 --- a/blocksuite/framework/block-std/src/gfx/controller.ts +++ b/blocksuite/framework/block-std/src/gfx/controller.ts @@ -35,7 +35,7 @@ import { Viewport } from './viewport.js'; export class GfxController extends LifeCycleWatcher { static override key = gfxControllerKey; - private _disposables: DisposableGroup = new DisposableGroup(); + private readonly _disposables: DisposableGroup = new DisposableGroup(); private _surface: SurfaceBlockModel | null = null; diff --git a/blocksuite/framework/block-std/src/gfx/grid.ts b/blocksuite/framework/block-std/src/gfx/grid.ts index e997cccd84cfc..12df95ab19604 100644 --- a/blocksuite/framework/block-std/src/gfx/grid.ts +++ b/blocksuite/framework/block-std/src/gfx/grid.ts @@ -66,16 +66,22 @@ const typeFilters = { type FilterFunc = (model: GfxModel | GfxLocalElementModel) => boolean; export class GridManager { - private _elementToGrids = new Map< + private readonly _elementToGrids = new Map< GfxModel | GfxLocalElementModel, Set> >(); - private _externalElementToGrids = new Map>>(); + private readonly _externalElementToGrids = new Map< + GfxModel, + Set> + >(); - private _externalGrids = new Map>(); + private readonly _externalGrids = new Map>(); - private _grids = new Map>(); + private readonly _grids = new Map< + string, + Set + >(); get isEmpty() { return this._grids.size === 0; diff --git a/blocksuite/framework/block-std/src/gfx/keyboard.ts b/blocksuite/framework/block-std/src/gfx/keyboard.ts index 0eda0e4196ce6..c6428ae5a0a18 100644 --- a/blocksuite/framework/block-std/src/gfx/keyboard.ts +++ b/blocksuite/framework/block-std/src/gfx/keyboard.ts @@ -4,7 +4,7 @@ import { Signal } from '@preact/signals-core'; import type { BlockStdScope } from '../scope/block-std-scope.js'; export class KeyboardController { - private _disposable = new DisposableGroup(); + private readonly _disposable = new DisposableGroup(); shiftKey$ = new Signal(false); diff --git a/blocksuite/framework/block-std/src/gfx/layer.ts b/blocksuite/framework/block-std/src/gfx/layer.ts index c77a7f8f02b54..b314faa2d0123 100644 --- a/blocksuite/framework/block-std/src/gfx/layer.ts +++ b/blocksuite/framework/block-std/src/gfx/layer.ts @@ -71,7 +71,7 @@ export type Layer = BlockLayer | CanvasLayer; export class LayerManager { static INITIAL_INDEX = 'a0'; - private _disposable = new DisposableGroup(); + private readonly _disposable = new DisposableGroup(); blocks: GfxBlockElementModel[] = []; @@ -100,7 +100,7 @@ export class LayerManager { }; constructor( - private _doc: Doc, + private readonly _doc: Doc, private _surface: SurfaceBlockModel | null, options: { watch: boolean; diff --git a/blocksuite/framework/block-std/src/gfx/model/surface/element-model.ts b/blocksuite/framework/block-std/src/gfx/model/surface/element-model.ts index 1c5a1c5d25969..bd88ca488a7d3 100644 --- a/blocksuite/framework/block-std/src/gfx/model/surface/element-model.ts +++ b/blocksuite/framework/block-std/src/gfx/model/surface/element-model.ts @@ -388,7 +388,7 @@ export abstract class GfxGroupLikeElementModel< { private _childIds: string[] = []; - private _mutex = createMutex(); + private readonly _mutex = createMutex(); abstract children: Y.Map; diff --git a/blocksuite/framework/block-std/src/gfx/model/surface/local-element-model.ts b/blocksuite/framework/block-std/src/gfx/model/surface/local-element-model.ts index 31f7638b2ad64..aa6b7a1bf696f 100644 --- a/blocksuite/framework/block-std/src/gfx/model/surface/local-element-model.ts +++ b/blocksuite/framework/block-std/src/gfx/model/surface/local-element-model.ts @@ -39,7 +39,7 @@ export function prop() { } export abstract class GfxLocalElementModel implements GfxCompatibleInterface { - private _mutex: mutex.mutex = mutex.createMutex(); + private readonly _mutex: mutex.mutex = mutex.createMutex(); protected _local = new Map(); diff --git a/blocksuite/framework/block-std/src/gfx/tool/tool-controller.ts b/blocksuite/framework/block-std/src/gfx/tool/tool-controller.ts index 7d72e95d64be3..0e74036af815a 100644 --- a/blocksuite/framework/block-std/src/gfx/tool/tool-controller.ts +++ b/blocksuite/framework/block-std/src/gfx/tool/tool-controller.ts @@ -83,15 +83,15 @@ export const eventTarget = Symbol('eventTarget'); export class ToolController extends GfxExtension { static override key = 'ToolController'; - private _builtInHookSlot = new Slot(); + private readonly _builtInHookSlot = new Slot(); - private _disposableGroup = new DisposableGroup(); + private readonly _disposableGroup = new DisposableGroup(); - private _toolOption$ = new Signal( + private readonly _toolOption$ = new Signal( {} as GfxToolsFullOptionValue ); - private _tools = new Map(); + private readonly _tools = new Map(); readonly currentToolName$ = new Signal(); diff --git a/blocksuite/framework/block-std/src/gfx/view/view-manager.ts b/blocksuite/framework/block-std/src/gfx/view/view-manager.ts index d3484a3401fff..b7d92bd4ef046 100644 --- a/blocksuite/framework/block-std/src/gfx/view/view-manager.ts +++ b/blocksuite/framework/block-std/src/gfx/view/view-manager.ts @@ -15,11 +15,11 @@ import { export class ViewManager extends GfxExtension { static override key = 'viewManager'; - private _disposable = new DisposableGroup(); + private readonly _disposable = new DisposableGroup(); - private _viewCtorMap = new Map(); + private readonly _viewCtorMap = new Map(); - private _viewMap = new Map(); + private readonly _viewMap = new Map(); constructor(gfx: GfxController) { super(gfx); diff --git a/blocksuite/framework/block-std/src/gfx/view/view.ts b/blocksuite/framework/block-std/src/gfx/view/view.ts index 8dac129765caf..63e89bc1e3b9c 100644 --- a/blocksuite/framework/block-std/src/gfx/view/view.ts +++ b/blocksuite/framework/block-std/src/gfx/view/view.ts @@ -40,7 +40,10 @@ export class GfxElementModelView< { static type: string; - private _handlers = new Map void)[]>(); + private readonly _handlers = new Map< + keyof EventsHandlerMap, + ((evt: any) => void)[] + >(); private _isConnected = true; diff --git a/blocksuite/framework/block-std/src/gfx/viewport-element.ts b/blocksuite/framework/block-std/src/gfx/viewport-element.ts index 438a2abe6be17..ec36a49969f83 100644 --- a/blocksuite/framework/block-std/src/gfx/viewport-element.ts +++ b/blocksuite/framework/block-std/src/gfx/viewport-element.ts @@ -46,7 +46,7 @@ export class GfxViewportElement extends WithDisposable(ShadowlessElement) { } `; - private _hideOutsideBlock = requestThrottledConnectedFrame(() => { + private readonly _hideOutsideBlock = requestThrottledConnectedFrame(() => { if (this.getModelsInViewport && this.host) { const host = this.host; const modelsInViewport = this.getModelsInViewport(); @@ -77,12 +77,12 @@ export class GfxViewportElement extends WithDisposable(ShadowlessElement) { private _lastVisibleModels?: Set; - private _pendingChildrenUpdates: { + private readonly _pendingChildrenUpdates: { id: string; resolve: () => void; }[] = []; - private _refreshViewport = requestThrottledConnectedFrame(() => { + private readonly _refreshViewport = requestThrottledConnectedFrame(() => { this._hideOutsideBlock(); }, this); diff --git a/blocksuite/framework/block-std/src/range/range-binding.ts b/blocksuite/framework/block-std/src/range/range-binding.ts index fd66f9ca492b4..d7c9d704da541 100644 --- a/blocksuite/framework/block-std/src/range/range-binding.ts +++ b/blocksuite/framework/block-std/src/range/range-binding.ts @@ -15,7 +15,7 @@ export class RangeBinding { | ((event: CompositionEvent) => Promise) | null = null; - private _computePath = (modelId: string) => { + private readonly _computePath = (modelId: string) => { const block = this.host.std.doc.getBlock(modelId)?.model; if (!block) return []; @@ -29,7 +29,7 @@ export class RangeBinding { return path; }; - private _onBeforeInput = (event: InputEvent) => { + private readonly _onBeforeInput = (event: InputEvent) => { const selection = this.selectionManager.find('text'); if (!selection) return; @@ -85,7 +85,7 @@ export class RangeBinding { this.selectionManager.setGroup('note', [newSelection]); }; - private _onCompositionEnd = (event: CompositionEvent) => { + private readonly _onCompositionEnd = (event: CompositionEvent) => { if (this._compositionStartCallback) { event.preventDefault(); event.stopPropagation(); @@ -94,7 +94,7 @@ export class RangeBinding { } }; - private _onCompositionStart = () => { + private readonly _onCompositionStart = () => { const selection = this.selectionManager.find('text'); if (!selection) return; @@ -166,7 +166,7 @@ export class RangeBinding { }; }; - private _onNativeSelectionChanged = async () => { + private readonly _onNativeSelectionChanged = async () => { if (this.isComposing) return; if (!this.host) return; // Unstable when switching views, card <-> embed @@ -246,7 +246,7 @@ export class RangeBinding { this.rangeManager?.syncRangeToTextSelection(range, isRangeReversed); }; - private _onStdSelectionChanged = (selections: BaseSelection[]) => { + private readonly _onStdSelectionChanged = (selections: BaseSelection[]) => { const text = selections.find((selection): selection is TextSelection => selection.is('text') diff --git a/blocksuite/framework/block-std/src/selection/manager.ts b/blocksuite/framework/block-std/src/selection/manager.ts index 8678510f02ddd..c499068a2f754 100644 --- a/blocksuite/framework/block-std/src/selection/manager.ts +++ b/blocksuite/framework/block-std/src/selection/manager.ts @@ -18,20 +18,20 @@ export interface SelectionConstructor { export class SelectionManager extends LifeCycleWatcher { static override readonly key = 'selectionManager'; - private _id: string; + private readonly _id: string; - private _itemAdded = (event: { stackItem: StackItem }) => { + private readonly _itemAdded = (event: { stackItem: StackItem }) => { event.stackItem.meta.set('selection-state', this.value); }; - private _itemPopped = (event: { stackItem: StackItem }) => { + private readonly _itemPopped = (event: { stackItem: StackItem }) => { const selection = event.stackItem.meta.get('selection-state'); if (selection) { this.set(selection as BaseSelection[]); } }; - private _jsonToSelection = (json: Record) => { + private readonly _jsonToSelection = (json: Record) => { const ctor = this._selectionConstructors[json.type as string]; if (!ctor) { throw new BlockSuiteError( @@ -42,11 +42,13 @@ export class SelectionManager extends LifeCycleWatcher { return ctor.fromJSON(json); }; - private _remoteSelections = signal>(new Map()); + private readonly _remoteSelections = signal>( + new Map() + ); private _selectionConstructors: Record = {}; - private _selections = signal([]); + private readonly _selections = signal([]); disposables = new DisposableGroup(); diff --git a/blocksuite/framework/block-std/src/view/element/block-component.ts b/blocksuite/framework/block-std/src/view/element/block-component.ts index 1c1c87e3b5984..e085356a868ce 100644 --- a/blocksuite/framework/block-std/src/view/element/block-component.ts +++ b/blocksuite/framework/block-std/src/view/element/block-component.ts @@ -35,7 +35,7 @@ export class BlockComponent< @consume({ context: stdContext }) accessor std!: BlockStdScope; - private _selected = computed(() => { + private readonly _selected = computed(() => { const selection = this.std.selection.value.find(selection => { return selection.blockId === this.model?.id; }); diff --git a/blocksuite/framework/block-std/src/view/element/gfx-block-component.ts b/blocksuite/framework/block-std/src/view/element/gfx-block-component.ts index 031f9696a7322..38b776292fceb 100644 --- a/blocksuite/framework/block-std/src/view/element/gfx-block-component.ts +++ b/blocksuite/framework/block-std/src/view/element/gfx-block-component.ts @@ -108,13 +108,13 @@ export abstract class GfxBlockComponent< const parent = this.parentElement; if (this.hasUpdated || !parent || !('scheduleUpdateChildren' in parent)) { - super.scheduleUpdate(); + return super.scheduleUpdate(); } else { await (parent.scheduleUpdateChildren as (id: string) => Promise)( this.model.id ); - super.scheduleUpdate(); + return super.scheduleUpdate(); } } @@ -207,13 +207,13 @@ export function toGfxBlockComponent< const parent = this.parentElement; if (this.hasUpdated || !parent || !('scheduleUpdateChildren' in parent)) { - super.scheduleUpdate(); + return super.scheduleUpdate(); } else { await (parent.scheduleUpdateChildren as (id: string) => Promise)( this.model.id ); - super.scheduleUpdate(); + return super.scheduleUpdate(); } } diff --git a/blocksuite/framework/block-std/src/view/element/lit-host.ts b/blocksuite/framework/block-std/src/view/element/lit-host.ts index 0cc55bd25b9e1..6f8203ef7b943 100644 --- a/blocksuite/framework/block-std/src/view/element/lit-host.ts +++ b/blocksuite/framework/block-std/src/view/element/lit-host.ts @@ -41,7 +41,7 @@ export class EditorHost extends SignalWatcher( } `; - private _renderModel = (model: BlockModel): TemplateResult => { + private readonly _renderModel = (model: BlockModel): TemplateResult => { const { flavour } = model; const block = this.doc.getBlock(model.id); if (!block || block.blockViewType === BlockViewType.Hidden) { diff --git a/blocksuite/framework/block-std/src/view/view-store.ts b/blocksuite/framework/block-std/src/view/view-store.ts index 7ea9a34b5311a..fccdab75bed83 100644 --- a/blocksuite/framework/block-std/src/view/view-store.ts +++ b/blocksuite/framework/block-std/src/view/view-store.ts @@ -6,7 +6,7 @@ export class ViewStore extends LifeCycleWatcher { private readonly _blockMap = new Map(); - private _fromId = ( + private readonly _fromId = ( blockId: string | undefined | null ): BlockComponent | null => { const id = blockId ?? this.std.doc.root?.id; diff --git a/blocksuite/framework/inline/src/inline-editor.ts b/blocksuite/framework/inline/src/inline-editor.ts index 5cbf3b29f1049..64235164eb12d 100644 --- a/blocksuite/framework/inline/src/inline-editor.ts +++ b/blocksuite/framework/inline/src/inline-editor.ts @@ -140,7 +140,7 @@ export class InlineEditor< return this._rootElement; } - private _inlineRangeProviderOverride = false; + private readonly _inlineRangeProviderOverride = false; get inlineRangeProviderOverride() { return this._inlineRangeProviderOverride; } diff --git a/blocksuite/framework/inline/src/services/event.ts b/blocksuite/framework/inline/src/services/event.ts index 966a5e19c77b4..732dca566273c 100644 --- a/blocksuite/framework/inline/src/services/event.ts +++ b/blocksuite/framework/inline/src/services/event.ts @@ -15,7 +15,7 @@ export class EventService { private _isComposing = false; - private _isRangeCompletelyInRoot = (range: Range) => { + private readonly _isRangeCompletelyInRoot = (range: Range) => { if (range.commonAncestorContainer.ownerDocument !== document) return false; const rootElement = this.editor.rootElement; @@ -38,7 +38,7 @@ export class EventService { } }; - private _onBeforeInput = (event: InputEvent) => { + private readonly _onBeforeInput = (event: InputEvent) => { const range = this.editor.rangeService.getNativeRange(); if ( this.editor.isReadonly || @@ -119,7 +119,7 @@ export class EventService { this.editor.slots.inputting.emit(); }; - private _onClick = (event: MouseEvent) => { + private readonly _onClick = (event: MouseEvent) => { // select embed element when click on it if (event.target instanceof Node && isInEmbedElement(event.target)) { const selection = document.getSelection(); @@ -138,7 +138,7 @@ export class EventService { } }; - private _onCompositionEnd = async (event: CompositionEvent) => { + private readonly _onCompositionEnd = async (event: CompositionEvent) => { this._isComposing = false; if (!this.editor.rootElement.isConnected) return; @@ -179,7 +179,7 @@ export class EventService { this.editor.slots.inputting.emit(); }; - private _onCompositionStart = () => { + private readonly _onCompositionStart = () => { this._isComposing = true; // embeds is not editable and it will break IME const embeds = this.editor.rootElement.querySelectorAll( @@ -197,7 +197,7 @@ export class EventService { } }; - private _onCompositionUpdate = () => { + private readonly _onCompositionUpdate = () => { if (!this.editor.rootElement.isConnected) return; const range = this.editor.rangeService.getNativeRange(); @@ -211,7 +211,7 @@ export class EventService { this.editor.slots.inputting.emit(); }; - private _onKeyDown = (event: KeyboardEvent) => { + private readonly _onKeyDown = (event: KeyboardEvent) => { const inlineRange = this.editor.getInlineRange(); if (!inlineRange) return; @@ -270,7 +270,7 @@ export class EventService { } }; - private _onSelectionChange = () => { + private readonly _onSelectionChange = () => { const rootElement = this.editor.rootElement; const previousInlineRange = this.editor.getInlineRange(); if (this._isComposing) { diff --git a/blocksuite/framework/inline/src/services/render.ts b/blocksuite/framework/inline/src/services/render.ts index 5ae4600117aab..60dda4c05188d 100644 --- a/blocksuite/framework/inline/src/services/render.ts +++ b/blocksuite/framework/inline/src/services/render.ts @@ -11,7 +11,10 @@ import type { BaseTextAttributes } from '../utils/base-attributes.js'; import { deltaInsertsToChunks } from '../utils/delta-convert.js'; export class RenderService { - private _onYTextChange = (_: Y.YTextEvent, transaction: Y.Transaction) => { + private readonly _onYTextChange = ( + _: Y.YTextEvent, + transaction: Y.Transaction + ) => { this.editor.slots.textChange.emit(); const yText = this.editor.yText; diff --git a/blocksuite/framework/store/src/adapter/base.ts b/blocksuite/framework/store/src/adapter/base.ts index a84e0f5a2b5ef..9cf8b779902ef 100644 --- a/blocksuite/framework/store/src/adapter/base.ts +++ b/blocksuite/framework/store/src/adapter/base.ts @@ -218,7 +218,7 @@ export class ASTWalker { private _leave: WalkerFn | undefined; - private _visit = async (o: NodeProps) => { + private readonly _visit = async (o: NodeProps) => { if (!o.node) return; this.context._skipChildrenNum = 0; this.context._skip = false; @@ -277,7 +277,7 @@ export class ASTWalker { } }; - private context: ASTWalkerContext; + private readonly context: ASTWalkerContext; setEnter = (fn: WalkerFn) => { this._enter = fn; diff --git a/blocksuite/framework/store/src/adapter/context.ts b/blocksuite/framework/store/src/adapter/context.ts index d351ab202dd51..9a484e7b4af1d 100644 --- a/blocksuite/framework/store/src/adapter/context.ts +++ b/blocksuite/framework/store/src/adapter/context.ts @@ -5,7 +5,7 @@ export class ASTWalkerContext { private _globalContext: Record = Object.create(null); - private _stack: { + private readonly _stack: { node: TNode; prop: Keyof; context: Record; diff --git a/blocksuite/framework/store/src/reactive/proxy.ts b/blocksuite/framework/store/src/reactive/proxy.ts index 26877d77eaea0..3bc9d6c637f4f 100644 --- a/blocksuite/framework/store/src/reactive/proxy.ts +++ b/blocksuite/framework/store/src/reactive/proxy.ts @@ -17,7 +17,7 @@ export class ReactiveYArray extends BaseReactiveYData< unknown[], YArray > { - private _observer = (event: YArrayEvent) => { + private readonly _observer = (event: YArrayEvent) => { this._onObserve(event, () => { let retain = 0; event.changes.delta.forEach(change => { @@ -159,7 +159,7 @@ export class ReactiveYArray extends BaseReactiveYData< } export class ReactiveYMap extends BaseReactiveYData> { - private _observer = (event: YMapEvent) => { + private readonly _observer = (event: YMapEvent) => { this._onObserve(event, () => { event.keysChanged.forEach(key => { const type = event.changes.keys.get(key); diff --git a/blocksuite/framework/store/src/reactive/text.ts b/blocksuite/framework/store/src/reactive/text.ts index 9fb8af5105cc9..758161f34e405 100644 --- a/blocksuite/framework/store/src/reactive/text.ts +++ b/blocksuite/framework/store/src/reactive/text.ts @@ -16,9 +16,9 @@ export type DeltaOperation = { export type OnTextChange = (data: Y.Text) => void; export class Text { - private _deltas$: Signal; + private readonly _deltas$: Signal; - private _length$: Signal; + private readonly _length$: Signal; private _onChange?: OnTextChange; diff --git a/blocksuite/framework/store/src/schema/base.ts b/blocksuite/framework/store/src/schema/base.ts index a22204f9df0e5..6059dc38483d9 100644 --- a/blocksuite/framework/store/src/schema/base.ts +++ b/blocksuite/framework/store/src/schema/base.ts @@ -155,14 +155,14 @@ export class BlockModel< Props extends object = object, PropsSignal extends object = SignaledProps, > extends MagicProps() { - private _children = signal([]); + private readonly _children = signal([]); /** * @deprecated use doc instead */ page!: Doc; - private _childModels = computed(() => { + private readonly _childModels = computed(() => { const value: BlockModel[] = []; this._children.value.forEach(id => { const block = this.page.getBlock$(id); @@ -173,9 +173,9 @@ export class BlockModel< return value; }); - private _onCreated: Disposable; + private readonly _onCreated: Disposable; - private _onDeleted: Disposable; + private readonly _onDeleted: Disposable; childMap = computed(() => this._children.value.reduce((map, id, index) => { diff --git a/blocksuite/framework/store/src/store/doc/block-collection.ts b/blocksuite/framework/store/src/store/doc/block-collection.ts index 8c9f2110422f3..4893c95af2a8c 100644 --- a/blocksuite/framework/store/src/store/doc/block-collection.ts +++ b/blocksuite/framework/store/src/store/doc/block-collection.ts @@ -47,27 +47,27 @@ export class BlockCollection { private readonly _docCRUD: DocCRUD; - private _docMap = { + private readonly _docMap = { undefined: new Map(), true: new Map(), false: new Map(), }; // doc/space container. - private _handleYEvents = (events: Y.YEvent[]) => { + private readonly _handleYEvents = (events: Y.YEvent[]) => { events.forEach(event => this._handleYEvent(event)); }; private _history!: Y.UndoManager; - private _historyObserver = () => { + private readonly _historyObserver = () => { this._updateCanUndoRedoSignals(); this.slots.historyUpdated.emit(); }; private readonly _idGenerator: IdGenerator; - private _initSubDoc = () => { + private readonly _initSubDoc = () => { let subDoc = this.rootDoc.spaces.get(this.id); if (!subDoc) { subDoc = new Y.Doc({ @@ -86,9 +86,13 @@ export class BlockCollection { private _loaded!: boolean; - private _onLoadSlot = new Slot(); + private readonly _onLoadSlot = new Slot(); - private _onSubdocEvent = ({ loaded }: { loaded: Set }): void => { + private readonly _onSubdocEvent = ({ + loaded, + }: { + loaded: Set; + }): void => { const result = Array.from(loaded).find( doc => doc.guid === this._ySpaceDoc.guid ); @@ -105,7 +109,7 @@ export class BlockCollection { private _shouldTransact = true; - private _updateCanUndoRedoSignals = () => { + private readonly _updateCanUndoRedoSignals = () => { const canRedo = this.readonly ? false : this._history.canRedo(); const canUndo = this.readonly ? false : this._history.canUndo(); if (this._canRedo$.peek() !== canRedo) { diff --git a/blocksuite/framework/store/src/store/doc/block/index.ts b/blocksuite/framework/store/src/store/doc/block/index.ts index 82126de1a1afe..a58e36320521f 100644 --- a/blocksuite/framework/store/src/store/doc/block/index.ts +++ b/blocksuite/framework/store/src/store/doc/block/index.ts @@ -7,7 +7,7 @@ import type { BlockOptions, YBlock } from './types.js'; export * from './types.js'; export class Block { - private _syncController: SyncController; + private readonly _syncController: SyncController; blockViewType: BlockViewType = BlockViewType.Display; diff --git a/blocksuite/framework/store/src/store/doc/doc.ts b/blocksuite/framework/store/src/store/doc/doc.ts index 8502b319d6e2b..5232ac37389fc 100644 --- a/blocksuite/framework/store/src/store/doc/doc.ts +++ b/blocksuite/framework/store/src/store/doc/doc.ts @@ -20,7 +20,7 @@ type DocOptions = { }; export class Doc { - private _runQuery = (block: Block) => { + private readonly _runQuery = (block: Block) => { runQuery(this._query, block); }; diff --git a/blocksuite/framework/store/src/store/meta.ts b/blocksuite/framework/store/src/store/meta.ts index 930ceea8f0f5d..2fbb2980e4f7a 100644 --- a/blocksuite/framework/store/src/store/meta.ts +++ b/blocksuite/framework/store/src/store/meta.ts @@ -36,7 +36,7 @@ export type DocCollectionMetaState = { }; export class DocCollectionMeta { - private _handleDocCollectionMetaEvents = ( + private readonly _handleDocCollectionMetaEvents = ( events: Y.YEvent | Y.Text | Y.Map>[] ) => { events.forEach(e => { diff --git a/blocksuite/framework/store/src/yjs/awareness.ts b/blocksuite/framework/store/src/yjs/awareness.ts index ad0268fa15f96..59662e2e43060 100644 --- a/blocksuite/framework/store/src/yjs/awareness.ts +++ b/blocksuite/framework/store/src/yjs/awareness.ts @@ -32,9 +32,9 @@ export interface AwarenessEvent< } export class AwarenessStore { - private _flags: Signal; + private readonly _flags: Signal; - private _onAwarenessChange = (diff: { + private readonly _onAwarenessChange = (diff: { added: number[]; removed: number[]; updated: number[]; diff --git a/blocksuite/framework/store/src/yjs/doc.ts b/blocksuite/framework/store/src/yjs/doc.ts index 66598cece241e..9abb9731b56d2 100644 --- a/blocksuite/framework/store/src/yjs/doc.ts +++ b/blocksuite/framework/store/src/yjs/doc.ts @@ -10,7 +10,7 @@ export type BlockSuiteDocAllowedValue = export type BlockSuiteDocData = Record; export class BlockSuiteDoc extends Y.Doc { - private _spaces: Y.Map = this.getMap('spaces'); + private readonly _spaces: Y.Map = this.getMap('spaces'); get spaces() { return this._spaces; diff --git a/blocksuite/framework/sync/src/doc/impl/broadcast.ts b/blocksuite/framework/sync/src/doc/impl/broadcast.ts index 7e48814102994..96b3246cb007e 100644 --- a/blocksuite/framework/sync/src/doc/impl/broadcast.ts +++ b/blocksuite/framework/sync/src/doc/impl/broadcast.ts @@ -14,7 +14,7 @@ type ChannelMessage = }; export class BroadcastChannelDocSource implements DocSource { - private _onMessage = (event: MessageEvent) => { + private readonly _onMessage = (event: MessageEvent) => { if (event.data.type === 'init') { for (const [docId, data] of this.docMap) { this.channel.postMessage({ diff --git a/blocksuite/playground/apps/_common/components/attachment-viewer-panel.ts b/blocksuite/playground/apps/_common/components/attachment-viewer-panel.ts index d9ea46ac86fb1..30c941ffde295 100644 --- a/blocksuite/playground/apps/_common/components/attachment-viewer-panel.ts +++ b/blocksuite/playground/apps/_common/components/attachment-viewer-panel.ts @@ -112,13 +112,13 @@ export class AttachmentViewerPanel extends SignalWatcher( } `; - #cursor = signal(0); + readonly #cursor = signal(0); - #docInfo = signal(null); + readonly #docInfo = signal(null); - #fileInfo = signal(null); + readonly #fileInfo = signal(null); - #state = signal(State.Connecting); + readonly #state = signal(State.Connecting); #worker: Worker | null = null; diff --git a/blocksuite/playground/apps/_common/components/collab-debug-menu.ts b/blocksuite/playground/apps/_common/components/collab-debug-menu.ts index 5dae352157370..8ca89f09ff314 100644 --- a/blocksuite/playground/apps/_common/components/collab-debug-menu.ts +++ b/blocksuite/playground/apps/_common/components/collab-debug-menu.ts @@ -65,21 +65,21 @@ export class CollabDebugMenu extends SignalWatcher(ShadowlessElement) { } `; - private _darkModeChange = (e: MediaQueryListEvent) => { + private readonly _darkModeChange = (e: MediaQueryListEvent) => { this._setThemeMode(!!e.matches); }; - private _handleDocsPanelClose = () => { + private readonly _handleDocsPanelClose = () => { this.leftSidePanel.toggle(this.docsPanel); }; - private _keydown = (e: KeyboardEvent) => { + private readonly _keydown = (e: KeyboardEvent) => { if (e.key === 'F1') { this._switchEditorMode(); } }; - private _startCollaboration = async () => { + private readonly _startCollaboration = async () => { if (window.wsProvider) { notify('There is already a websocket provider exists', 'neutral').catch( console.error diff --git a/blocksuite/playground/apps/_common/components/starter-debug-menu.ts b/blocksuite/playground/apps/_common/components/starter-debug-menu.ts index 78c220fdf0c6b..b15130d8c2770 100644 --- a/blocksuite/playground/apps/_common/components/starter-debug-menu.ts +++ b/blocksuite/playground/apps/_common/components/starter-debug-menu.ts @@ -188,11 +188,11 @@ export class StarterDebugMenu extends ShadowlessElement { } `; - private _darkModeChange = (e: MediaQueryListEvent) => { + private readonly _darkModeChange = (e: MediaQueryListEvent) => { this._setThemeMode(!!e.matches); }; - private _handleDocsPanelClose = () => { + private readonly _handleDocsPanelClose = () => { this.leftSidePanel.toggle(this.docsPanel); }; diff --git a/blocksuite/playground/apps/_common/sync/websocket/awareness.ts b/blocksuite/playground/apps/_common/sync/websocket/awareness.ts index 1229da661cb24..0f9a631483975 100644 --- a/blocksuite/playground/apps/_common/sync/websocket/awareness.ts +++ b/blocksuite/playground/apps/_common/sync/websocket/awareness.ts @@ -11,7 +11,10 @@ import type { WebSocketMessage } from './types'; type AwarenessChanges = Record<'added' | 'updated' | 'removed', number[]>; export class WebSocketAwarenessSource implements AwarenessSource { - private _onAwareness = (changes: AwarenessChanges, origin: unknown) => { + private readonly _onAwareness = ( + changes: AwarenessChanges, + origin: unknown + ) => { if (origin === 'remote') return; const changedClients = Object.values(changes).reduce((res, cur) => @@ -31,7 +34,7 @@ export class WebSocketAwarenessSource implements AwarenessSource { ); }; - private _onWebSocket = (event: MessageEvent) => { + private readonly _onWebSocket = (event: MessageEvent) => { const data = JSON.parse(event.data) as WebSocketMessage; if (data.channel !== 'awareness') return; diff --git a/blocksuite/playground/apps/_common/sync/websocket/doc.ts b/blocksuite/playground/apps/_common/sync/websocket/doc.ts index a7fdd73f77805..37c1094cafdd4 100644 --- a/blocksuite/playground/apps/_common/sync/websocket/doc.ts +++ b/blocksuite/playground/apps/_common/sync/websocket/doc.ts @@ -5,7 +5,7 @@ import { diffUpdate, encodeStateVectorFromUpdate, mergeUpdates } from 'yjs'; import type { WebSocketMessage } from './types'; export class WebSocketDocSource implements DocSource { - private _onMessage = (event: MessageEvent) => { + private readonly _onMessage = (event: MessageEvent) => { const data = JSON.parse(event.data) as WebSocketMessage; if (data.channel !== 'doc') return; diff --git a/blocksuite/playground/scripts/hmr-plugin/fine-tune.ts b/blocksuite/playground/scripts/hmr-plugin/fine-tune.ts index dfa6bc8599bee..b547c93fde7d9 100644 --- a/blocksuite/playground/scripts/hmr-plugin/fine-tune.ts +++ b/blocksuite/playground/scripts/hmr-plugin/fine-tune.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ +/* eslint-disable import-x/no-extraneous-dependencies */ import path from 'node:path'; import { init, parse } from 'es-module-lexer'; diff --git a/blocksuite/presets/src/editors/editor-container.ts b/blocksuite/presets/src/editors/editor-container.ts index 68cc89a41575d..e3fc77f4fe3a2 100644 --- a/blocksuite/presets/src/editors/editor-container.ts +++ b/blocksuite/presets/src/editors/editor-container.ts @@ -88,28 +88,30 @@ export class AffineEditorContainer } `; - private _doc = signal(); + private readonly _doc = signal(); - private _edgelessSpecs = signal(EdgelessEditorBlockSpecs); + private readonly _edgelessSpecs = signal( + EdgelessEditorBlockSpecs + ); - private _mode = signal('page'); + private readonly _mode = signal('page'); - private _pageSpecs = signal(PageEditorBlockSpecs); + private readonly _pageSpecs = signal(PageEditorBlockSpecs); - private _specs = computed(() => + private readonly _specs = computed(() => this._mode.value === 'page' ? this._pageSpecs.value : this._edgelessSpecs.value ); - private _std = computed(() => { + private readonly _std = computed(() => { return new BlockStdScope({ doc: this.doc, extensions: this._specs.value, }); }); - private _editorTemplate = computed(() => { + private readonly _editorTemplate = computed(() => { return this._std.value.render(); }); diff --git a/blocksuite/presets/src/fragments/comment/comment-input.ts b/blocksuite/presets/src/fragments/comment/comment-input.ts index e6975aaecce9d..65073ee81fc78 100644 --- a/blocksuite/presets/src/fragments/comment/comment-input.ts +++ b/blocksuite/presets/src/fragments/comment/comment-input.ts @@ -41,11 +41,11 @@ export class CommentInput extends WithDisposable(ShadowlessElement) { } `; - private _cancel = () => { + private readonly _cancel = () => { this.remove(); }; - private _submit = (textSelection: TextSelection) => { + private readonly _submit = (textSelection: TextSelection) => { const deltas = this._editor.inlineEditor?.yTextDeltas; if (!deltas) { this.remove(); diff --git a/blocksuite/presets/src/fragments/doc-meta-tags/backlink-popover.ts b/blocksuite/presets/src/fragments/doc-meta-tags/backlink-popover.ts index b79388c7b4e3b..3fdf7885c496f 100644 --- a/blocksuite/presets/src/fragments/doc-meta-tags/backlink-popover.ts +++ b/blocksuite/presets/src/fragments/doc-meta-tags/backlink-popover.ts @@ -79,10 +79,10 @@ export class BacklinkButton extends WithDisposable(LitElement) { ${scrollbarStyle('.backlink-popover .group')} `; - private _backlinks: BacklinkData[]; + private readonly _backlinks: BacklinkData[]; // Handle click outside - private _onClickAway = (e: Event) => { + private readonly _onClickAway = (e: Event) => { if (e.target === this) return; if (!this._showPopover) return; this._showPopover = false; diff --git a/blocksuite/presets/src/fragments/doc-title/doc-title.ts b/blocksuite/presets/src/fragments/doc-title/doc-title.ts index a404403a880fd..88b9aa1f28745 100644 --- a/blocksuite/presets/src/fragments/doc-title/doc-title.ts +++ b/blocksuite/presets/src/fragments/doc-title/doc-title.ts @@ -59,7 +59,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) { } `; - private _onTitleKeyDown = (event: KeyboardEvent) => { + private readonly _onTitleKeyDown = (event: KeyboardEvent) => { if (event.isComposing || this.doc.readonly) return; const hasContent = !this.doc.isEmpty; @@ -83,7 +83,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) { } }; - private _updateTitleInMeta = () => { + private readonly _updateTitleInMeta = () => { this.doc.collection.setDocMeta(this.doc.id, { title: this._rootModel.title.toString(), }); diff --git a/blocksuite/presets/src/fragments/frame-panel/body/frame-panel-body.ts b/blocksuite/presets/src/fragments/frame-panel/body/frame-panel-body.ts index cd90e8ec43226..92595a2cd1a34 100644 --- a/blocksuite/presets/src/fragments/frame-panel/body/frame-panel-body.ts +++ b/blocksuite/presets/src/fragments/frame-panel/body/frame-panel-body.ts @@ -91,7 +91,7 @@ export class FramePanelBody extends SignalWatcher( ) { static override styles = styles; - private _clearDocDisposables = () => { + private readonly _clearDocDisposables = () => { this._docDisposables?.dispose(); this._docDisposables = null; }; @@ -99,7 +99,7 @@ export class FramePanelBody extends SignalWatcher( /** * click at blank area to clear selection */ - private _clickBlank = (e: MouseEvent) => { + private readonly _clickBlank = (e: MouseEvent) => { e.stopPropagation(); // check if click at frame-card, if not, set this._selected to empty if ( @@ -126,7 +126,7 @@ export class FramePanelBody extends SignalWatcher( private _lastEdgelessRootId = ''; - private _selectFrame = (e: SelectEvent) => { + private readonly _selectFrame = (e: SelectEvent) => { const { selected, id, multiselect } = e.detail; if (!selected) { @@ -144,7 +144,7 @@ export class FramePanelBody extends SignalWatcher( }); }; - private _updateFrameItems = () => { + private readonly _updateFrameItems = () => { this._frameItems = this.frames.map((frame, idx) => ({ frame, frameIndex: frame.presentationIndex ?? frame.index, diff --git a/blocksuite/presets/src/fragments/frame-panel/card/frame-card-title-editor.ts b/blocksuite/presets/src/fragments/frame-panel/card/frame-card-title-editor.ts index 7974857cb6fa6..4a95ce714488b 100644 --- a/blocksuite/presets/src/fragments/frame-panel/card/frame-card-title-editor.ts +++ b/blocksuite/presets/src/fragments/frame-panel/card/frame-card-title-editor.ts @@ -16,7 +16,7 @@ export const AFFINE_FRAME_TITLE_EDITOR = 'affine-frame-card-title-editor'; export class FrameCardTitleEditor extends WithDisposable(ShadowlessElement) { static override styles = styles; - private _isComposing = false; + private readonly _isComposing = false; get inlineEditor() { return this.richText.inlineEditor; diff --git a/blocksuite/presets/src/fragments/frame-panel/card/frame-card-title.ts b/blocksuite/presets/src/fragments/frame-panel/card/frame-card-title.ts index de93d03f83411..bdf619fd6410a 100644 --- a/blocksuite/presets/src/fragments/frame-panel/card/frame-card-title.ts +++ b/blocksuite/presets/src/fragments/frame-panel/card/frame-card-title.ts @@ -59,12 +59,12 @@ export const AFFINE_FRAME_CARD_TITLE = 'affine-frame-card-title'; export class FrameCardTitle extends WithDisposable(ShadowlessElement) { static override styles = styles; - private _clearTitleDisposables = () => { + private readonly _clearTitleDisposables = () => { this._titleDisposables?.dispose(); this._titleDisposables = null; }; - private _mountTitleEditor = (e: MouseEvent) => { + private readonly _mountTitleEditor = (e: MouseEvent) => { e.stopPropagation(); const titleEditor = new FrameCardTitleEditor(); @@ -78,7 +78,7 @@ export class FrameCardTitle extends WithDisposable(ShadowlessElement) { private _titleDisposables: DisposableGroup | null = null; - private _updateElement = () => { + private readonly _updateElement = () => { this.requestUpdate(); }; diff --git a/blocksuite/presets/src/fragments/frame-panel/header/frame-panel-header.ts b/blocksuite/presets/src/fragments/frame-panel/header/frame-panel-header.ts index a74881b293fa9..43be03979cc0f 100644 --- a/blocksuite/presets/src/fragments/frame-panel/header/frame-panel-header.ts +++ b/blocksuite/presets/src/fragments/frame-panel/header/frame-panel-header.ts @@ -105,14 +105,14 @@ export const AFFINE_FRAME_PANEL_HEADER = 'affine-frame-panel-header'; export class FramePanelHeader extends WithDisposable(LitElement) { static override styles = styles; - private _clearEdgelessDisposables = () => { + private readonly _clearEdgelessDisposables = () => { this._edgelessDisposables?.dispose(); this._edgelessDisposables = null; }; private _edgelessDisposables: DisposableGroup | null = null; - private _enterPresentationMode = () => { + private readonly _enterPresentationMode = () => { if (!this._edgelessRootService) { this.editorHost.std.get(DocModeProvider).setEditorMode('edgeless'); } @@ -131,7 +131,7 @@ export class FramePanelHeader extends WithDisposable(LitElement) { private _navigatorMode: NavigatorMode = 'fit'; - private _setEdgelessDisposables = () => { + private readonly _setEdgelessDisposables = () => { if (!this._edgelessRootService) return; this._clearEdgelessDisposables(); diff --git a/blocksuite/presets/src/fragments/frame-panel/header/frames-setting-menu.ts b/blocksuite/presets/src/fragments/frame-panel/header/frames-setting-menu.ts index ba6d0ff734e91..4482a11120af3 100644 --- a/blocksuite/presets/src/fragments/frame-panel/header/frames-setting-menu.ts +++ b/blocksuite/presets/src/fragments/frame-panel/header/frames-setting-menu.ts @@ -72,14 +72,14 @@ export const AFFINE_FRAMES_SETTING_MENU = 'affine-frames-setting-menu'; export class FramesSettingMenu extends WithDisposable(LitElement) { static override styles = styles; - private _onBlackBackgroundChange = (checked: boolean) => { + private readonly _onBlackBackgroundChange = (checked: boolean) => { this.blackBackground = checked; this._edgelessRootService?.slots.navigatorSettingUpdated.emit({ blackBackground: this.blackBackground, }); }; - private _onFillScreenChange = (checked: boolean) => { + private readonly _onFillScreenChange = (checked: boolean) => { this.fillScreen = checked; this._edgelessRootService?.slots.navigatorSettingUpdated.emit({ fillScreen: this.fillScreen, @@ -87,7 +87,7 @@ export class FramesSettingMenu extends WithDisposable(LitElement) { this._editPropsStore.setStorage('presentFillScreen', this.fillScreen); }; - private _onHideToolBarChange = (checked: boolean) => { + private readonly _onHideToolBarChange = (checked: boolean) => { this.hideToolbar = checked; this._edgelessRootService?.slots.navigatorSettingUpdated.emit({ hideToolbar: this.hideToolbar, diff --git a/blocksuite/presets/src/fragments/outline/body/outline-panel-body.ts b/blocksuite/presets/src/fragments/outline/body/outline-panel-body.ts index d77ba98892942..c04c62bad14a7 100644 --- a/blocksuite/presets/src/fragments/outline/body/outline-panel-body.ts +++ b/blocksuite/presets/src/fragments/outline/body/outline-panel-body.ts @@ -120,7 +120,7 @@ export class OutlinePanelBody extends SignalWatcher( ) { static override styles = styles; - private _activeHeadingId$ = signal(null); + private readonly _activeHeadingId$ = signal(null); private _changedFlag = false; diff --git a/blocksuite/presets/src/fragments/outline/outline-panel.ts b/blocksuite/presets/src/fragments/outline/outline-panel.ts index ce096f2befe87..122ffde3b28fe 100644 --- a/blocksuite/presets/src/fragments/outline/outline-panel.ts +++ b/blocksuite/presets/src/fragments/outline/outline-panel.ts @@ -55,7 +55,7 @@ export const AFFINE_OUTLINE_PANEL = 'affine-outline-panel'; export class OutlinePanel extends SignalWatcher(WithDisposable(LitElement)) { static override styles = styles; - private _setNoticeVisibility = (visibility: boolean) => { + private readonly _setNoticeVisibility = (visibility: boolean) => { this._noticeVisible = visibility; }; @@ -64,12 +64,12 @@ export class OutlinePanel extends SignalWatcher(WithDisposable(LitElement)) { enableSorting: false, }; - private _toggleNotesSorting = () => { + private readonly _toggleNotesSorting = () => { this._enableNotesSorting = !this._enableNotesSorting; this._updateAndSaveSettings({ enableSorting: this._enableNotesSorting }); }; - private _toggleShowPreviewIcon = (on: boolean) => { + private readonly _toggleShowPreviewIcon = (on: boolean) => { this._showPreviewIcon = on; this._updateAndSaveSettings({ showIcons: on }); }; diff --git a/blocksuite/presets/src/fragments/outline/outline-viewer.ts b/blocksuite/presets/src/fragments/outline/outline-viewer.ts index 93296c2a1a1e5..e7aad26c0f168 100644 --- a/blocksuite/presets/src/fragments/outline/outline-viewer.ts +++ b/blocksuite/presets/src/fragments/outline/outline-viewer.ts @@ -140,13 +140,13 @@ export class OutlineViewer extends SignalWatcher(WithDisposable(LitElement)) { } `; - private _activeHeadingId$ = signal(null); + private readonly _activeHeadingId$ = signal(null); private _highlightMaskDisposable = () => {}; private _lockActiveHeadingId = false; - private _scrollPanel = () => { + private readonly _scrollPanel = () => { this._activeItem?.scrollIntoView({ behavior: 'instant', block: 'center',