refactor(editor): rename block-std to std (#11250)

Closes: BS-2946
This commit is contained in:
Saul-Mirone
2025-03-28 07:20:34 +00:00
parent 4498676a96
commit 205cd7a86d
1029 changed files with 1580 additions and 1698 deletions
@@ -0,0 +1,51 @@
import { DisposableGroup } from '@blocksuite/global/disposable';
import { Signal } from '@preact/signals-core';
import type { BlockStdScope } from '../scope/std-scope.js';
export class KeyboardController {
private readonly _disposable = new DisposableGroup();
shiftKey$ = new Signal<boolean>(false);
spaceKey$ = new Signal<boolean>(false);
constructor(readonly std: BlockStdScope) {
this._init();
}
private _init() {
this._disposable.add(
this._listenKeyboard('keydown', evt => {
this.shiftKey$.value = evt.shiftKey && evt.key === 'Shift';
this.spaceKey$.value = evt.code === 'Space';
})
);
this._disposable.add(
this._listenKeyboard('keyup', evt => {
this.shiftKey$.value =
evt.shiftKey && evt.key === 'Shift' ? true : false;
if (evt.code === 'Space') {
this.spaceKey$.value = false;
}
})
);
}
private _listenKeyboard(
event: 'keydown' | 'keyup',
callback: (keyboardEvt: KeyboardEvent) => void
) {
document.addEventListener(event, callback, false);
return () => {
document.removeEventListener(event, callback, false);
};
}
dispose() {
this._disposable.dispose();
}
}