mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 00:37:05 +08:00
refactor(editor): remove assertExists (#10615)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type {
|
||||
BlockSnapshot,
|
||||
DocSnapshot,
|
||||
@@ -50,7 +49,12 @@ export class ClipboardAdapter extends BaseAdapter<string> {
|
||||
): Promise<FromSliceSnapshotResult<string>> {
|
||||
const snapshot = payload.snapshot;
|
||||
const assets = payload.assets;
|
||||
assertExists(assets);
|
||||
if (!assets) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.ValueNotExists,
|
||||
'ClipboardAdapter.fromSliceSnapshot: assets is not found'
|
||||
);
|
||||
}
|
||||
const map = assets.getAssets();
|
||||
const blobs: Record<string, FileSnapshot> = await encodeClipboardBlobs(map);
|
||||
return {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { toast } from '@blocksuite/affine-components/toast';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
|
||||
import type { FileSnapshot } from './adapter.js';
|
||||
|
||||
@@ -113,12 +112,17 @@ export function decodeClipboardBlobs(
|
||||
blobs: Record<string, FileSnapshot>,
|
||||
map: Map<string, Blob> | undefined
|
||||
) {
|
||||
if (!map) {
|
||||
console.error(
|
||||
`Trying to decode clipboard blobs, but the map is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
Object.entries<FileSnapshot>(blobs).forEach(([sourceId, file]) => {
|
||||
const blob = new Blob([decode(file.content)]);
|
||||
const f = new File([blob], file.name, {
|
||||
type: file.type,
|
||||
});
|
||||
assertExists(map);
|
||||
map.set(sourceId, f);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user