mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 22:07:09 +08:00
chore(editor): cleanup dead code (#9359)
This commit is contained in:
@@ -87,7 +87,6 @@ import {
|
|||||||
} from '../utils/query.js';
|
} from '../utils/query.js';
|
||||||
|
|
||||||
const BLOCKSUITE_SURFACE = 'blocksuite/surface';
|
const BLOCKSUITE_SURFACE = 'blocksuite/surface';
|
||||||
const IMAGE_PNG = 'image/png';
|
|
||||||
|
|
||||||
const { GROUP, MINDMAP, CONNECTOR } = CanvasElementType;
|
const { GROUP, MINDMAP, CONNECTOR } = CanvasElementType;
|
||||||
const IMAGE_PADDING = 5; // for rotated shapes some padding is needed
|
const IMAGE_PADDING = 5; // for rotated shapes some padding is needed
|
||||||
@@ -1200,42 +1199,6 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async copyAsPng(
|
|
||||||
blocks: BlockSuite.EdgelessBlockModelType[],
|
|
||||||
shapes: BlockSuite.SurfaceModel[]
|
|
||||||
) {
|
|
||||||
const blocksLen = blocks.length;
|
|
||||||
const shapesLen = shapes.length;
|
|
||||||
|
|
||||||
if (blocksLen + shapesLen === 0) return;
|
|
||||||
const canvas = await this.toCanvas(blocks, shapes);
|
|
||||||
assertExists(canvas);
|
|
||||||
// @ts-expect-error FIXME: ts error
|
|
||||||
if (window.apis?.clipboard?.copyAsImageFromString) {
|
|
||||||
// @ts-expect-error FIXME: ts error
|
|
||||||
await window.apis.clipboard?.copyAsImageFromString(
|
|
||||||
canvas.toDataURL(IMAGE_PNG)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
const blob: Blob = await new Promise((resolve, reject) =>
|
|
||||||
canvas.toBlob(
|
|
||||||
blob => (blob ? resolve(blob) : reject('Canvas can not export blob')),
|
|
||||||
IMAGE_PNG
|
|
||||||
)
|
|
||||||
);
|
|
||||||
assertExists(blob);
|
|
||||||
|
|
||||||
this.std.clipboard
|
|
||||||
.writeToClipboard(_items => {
|
|
||||||
return {
|
|
||||||
..._items,
|
|
||||||
[IMAGE_PNG]: blob,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.catch(console.error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async createElementsFromClipboardData(
|
async createElementsFromClipboardData(
|
||||||
elementsRawData: (SerializedElement | BlockSnapshot)[],
|
elementsRawData: (SerializedElement | BlockSnapshot)[],
|
||||||
pasteCenter?: IVec
|
pasteCenter?: IVec
|
||||||
|
|||||||
@@ -1312,7 +1312,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
override firstUpdated() {
|
override firstUpdated() {
|
||||||
const { _disposables, edgelessSlots, block, selection, gfx } = this;
|
const { _disposables, block, selection, gfx } = this;
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
// viewport zooming / scrolling
|
// viewport zooming / scrolling
|
||||||
@@ -1331,15 +1331,6 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
this.doc.slots.blockUpdated.on(this._updateOnElementChange)
|
this.doc.slots.blockUpdated.on(this._updateOnElementChange)
|
||||||
);
|
);
|
||||||
|
|
||||||
_disposables.add(
|
|
||||||
edgelessSlots.pressShiftKeyUpdated.on(pressed => {
|
|
||||||
this._shiftKey = pressed;
|
|
||||||
this._resizeManager.onPressShiftKey(pressed);
|
|
||||||
this._updateSelectedRect();
|
|
||||||
this._updateMode();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
_disposables.add(selection.slots.updated.on(this._updateOnSelectionChange));
|
_disposables.add(selection.slots.updated.on(this._updateOnSelectionChange));
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
@@ -1355,6 +1346,39 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
_disposables.add(() => {
|
_disposables.add(() => {
|
||||||
this._propDisposables.forEach(disposable => disposable.dispose());
|
this._propDisposables.forEach(disposable => disposable.dispose());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.block.handleEvent(
|
||||||
|
'keyDown',
|
||||||
|
ctx => {
|
||||||
|
const event = ctx.get('defaultState').event;
|
||||||
|
if (event instanceof KeyboardEvent) {
|
||||||
|
this._shift(event);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ global: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
this.block.handleEvent(
|
||||||
|
'keyUp',
|
||||||
|
ctx => {
|
||||||
|
const event = ctx.get('defaultState').event;
|
||||||
|
if (event instanceof KeyboardEvent) {
|
||||||
|
this._shift(event);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ global: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _shift(event: KeyboardEvent) {
|
||||||
|
if (event.repeat) return;
|
||||||
|
|
||||||
|
const pressed = event.key.toLowerCase() === 'shift' && event.shiftKey;
|
||||||
|
|
||||||
|
this._shiftKey = pressed;
|
||||||
|
this._resizeManager.onPressShiftKey(pressed);
|
||||||
|
this._updateSelectedRect();
|
||||||
|
this._updateMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
import {
|
import {
|
||||||
ConnectorElementModel,
|
ConnectorElementModel,
|
||||||
ConnectorMode,
|
ConnectorMode,
|
||||||
@@ -163,7 +162,6 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
|
|||||||
const std = this.rootComponent.std;
|
const std = this.rootComponent.std;
|
||||||
if (
|
if (
|
||||||
std.selection.getGroup('note').length > 0 ||
|
std.selection.getGroup('note').length > 0 ||
|
||||||
// eslint-disable-next-line
|
|
||||||
std.selection.find('text') ||
|
std.selection.find('text') ||
|
||||||
Boolean(std.selection.find('surface')?.editing)
|
Boolean(std.selection.find('surface')?.editing)
|
||||||
) {
|
) {
|
||||||
@@ -430,35 +428,9 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this._bindShiftKey();
|
|
||||||
this._bindToggleHand();
|
this._bindToggleHand();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _bindShiftKey() {
|
|
||||||
this.rootComponent.handleEvent(
|
|
||||||
'keyDown',
|
|
||||||
ctx => {
|
|
||||||
const event = ctx.get('defaultState').event;
|
|
||||||
if (event instanceof KeyboardEvent) {
|
|
||||||
this._shift(event);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ global: true }
|
|
||||||
);
|
|
||||||
this.rootComponent.handleEvent(
|
|
||||||
'keyUp',
|
|
||||||
ctx => {
|
|
||||||
const event = ctx.get('defaultState').event;
|
|
||||||
if (event instanceof KeyboardEvent) {
|
|
||||||
this._shift(event);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
global: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _bindToggleHand() {
|
private _bindToggleHand() {
|
||||||
this.rootComponent.handleEvent(
|
this.rootComponent.handleEvent(
|
||||||
'keyDown',
|
'keyDown',
|
||||||
@@ -685,21 +657,6 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _shift(event: KeyboardEvent) {
|
|
||||||
const edgeless = this.rootComponent;
|
|
||||||
|
|
||||||
if (event.repeat) return;
|
|
||||||
|
|
||||||
const shiftKeyPressed =
|
|
||||||
event.key.toLowerCase() === 'shift' && event.shiftKey;
|
|
||||||
|
|
||||||
if (shiftKeyPressed) {
|
|
||||||
edgeless.slots.pressShiftKeyUpdated.emit(true);
|
|
||||||
} else {
|
|
||||||
edgeless.slots.pressShiftKeyUpdated.emit(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private _space(event: KeyboardEvent) {
|
private _space(event: KeyboardEvent) {
|
||||||
/*
|
/*
|
||||||
Call this function with a check for !event.repeat to consider only the first keydown (not repeat). This way, you can use onPressSpaceBar in a tool to determine if the space bar is pressed or not.
|
Call this function with a check for !event.repeat to consider only the first keydown (not repeat). This way, you can use onPressSpaceBar in a tool to determine if the space bar is pressed or not.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import type {
|
|||||||
SurfaceBlockModel,
|
SurfaceBlockModel,
|
||||||
} from '@blocksuite/affine-block-surface';
|
} from '@blocksuite/affine-block-surface';
|
||||||
import { CommonUtils } from '@blocksuite/affine-block-surface';
|
import { CommonUtils } from '@blocksuite/affine-block-surface';
|
||||||
import { toast } from '@blocksuite/affine-components/toast';
|
|
||||||
import type {
|
import type {
|
||||||
RootBlockModel,
|
RootBlockModel,
|
||||||
ShapeElementModel,
|
ShapeElementModel,
|
||||||
@@ -320,7 +319,7 @@ export class EdgelessRootBlockComponent extends BlockComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _initSlotEffects() {
|
private _initSlotEffects() {
|
||||||
const { disposables, slots } = this;
|
const { disposables } = this;
|
||||||
|
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
this.std.get(ThemeProvider).theme$.subscribe(() => this.surface.refresh())
|
this.std.get(ThemeProvider).theme$.subscribe(() => this.surface.refresh())
|
||||||
@@ -331,22 +330,6 @@ export class EdgelessRootBlockComponent extends BlockComponent<
|
|||||||
this.style.cursor = this.gfx.cursor$.value;
|
this.style.cursor = this.gfx.cursor$.value;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
let canCopyAsPng = true;
|
|
||||||
disposables.add(
|
|
||||||
slots.copyAsPng.on(({ blocks, shapes }) => {
|
|
||||||
if (!canCopyAsPng) return;
|
|
||||||
canCopyAsPng = false;
|
|
||||||
|
|
||||||
this.clipboardController
|
|
||||||
.copyAsPng(blocks, shapes)
|
|
||||||
.then(() => toast(this.host, 'Copied to clipboard'))
|
|
||||||
.catch(() => toast(this.host, 'Failed to copy as PNG'))
|
|
||||||
.finally(() => {
|
|
||||||
canCopyAsPng = true;
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _initViewport() {
|
private _initViewport() {
|
||||||
|
|||||||
@@ -60,13 +60,7 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
|
|||||||
elementRenderers: Record<string, ElementRenderer> = elementRenderers;
|
elementRenderers: Record<string, ElementRenderer> = elementRenderers;
|
||||||
|
|
||||||
slots = {
|
slots = {
|
||||||
pressShiftKeyUpdated: new Slot<boolean>(),
|
|
||||||
copyAsPng: new Slot<{
|
|
||||||
blocks: BlockSuite.EdgelessBlockModelType[];
|
|
||||||
shapes: BlockSuite.SurfaceModel[];
|
|
||||||
}>(),
|
|
||||||
readonlyUpdated: new Slot<boolean>(),
|
readonlyUpdated: new Slot<boolean>(),
|
||||||
draggingAreaUpdated: new Slot(),
|
|
||||||
navigatorSettingUpdated: new Slot<{
|
navigatorSettingUpdated: new Slot<{
|
||||||
hideToolbar?: boolean;
|
hideToolbar?: boolean;
|
||||||
blackBackground?: boolean;
|
blackBackground?: boolean;
|
||||||
|
|||||||
@@ -243,12 +243,6 @@ export class EdgelessWatcher {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
disposables.add(
|
|
||||||
edgelessSlots.draggingAreaUpdated.on(() => {
|
|
||||||
this.checkTopLevelBlockSelection();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
disposables.add(
|
disposables.add(
|
||||||
edgelessSlots.elementResizeStart.on(() => {
|
edgelessSlots.elementResizeStart.on(() => {
|
||||||
this.widget.hide();
|
this.widget.hide();
|
||||||
|
|||||||
Reference in New Issue
Block a user