mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(editor): remove assertExists (#10615)
This commit is contained in:
@@ -15,7 +15,6 @@ import {
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import {
|
||||
type BlockModel,
|
||||
type BlockSnapshot,
|
||||
@@ -64,9 +63,14 @@ const findLast = (snapshot: SliceSnapshot): BlockSnapshot | null => {
|
||||
};
|
||||
|
||||
class PointState {
|
||||
private readonly _blockFromPath = (path: string) => {
|
||||
const block = this.std.view.getBlock(path);
|
||||
assertExists(block);
|
||||
private readonly _blockFromPath = (id: string) => {
|
||||
const block = this.std.view.getBlock(id);
|
||||
if (!block) {
|
||||
throw new BlockSuiteError(
|
||||
ErrorCode.TransformerError,
|
||||
`Block not found when pasting: ${id}`
|
||||
);
|
||||
}
|
||||
return block;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
ParagraphBlockModel,
|
||||
SurfaceRefBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { BlockSuiteError } from '@blocksuite/global/exceptions';
|
||||
import type { DeltaOperation, TransformerMiddleware } from '@blocksuite/store';
|
||||
|
||||
export const replaceIdMiddleware =
|
||||
@@ -166,13 +166,23 @@ export const replaceIdMiddleware =
|
||||
let connection = value.source as Record<string, string>;
|
||||
if (idMap.has(connection.id)) {
|
||||
const newId = idMap.get(connection.id);
|
||||
assertExists(newId, 'reference id must exist');
|
||||
if (!newId) {
|
||||
throw new BlockSuiteError(
|
||||
BlockSuiteError.ErrorCode.TransformerError,
|
||||
`reference id must exist: ${connection.id}`
|
||||
);
|
||||
}
|
||||
connection.id = newId;
|
||||
}
|
||||
connection = value.target as Record<string, string>;
|
||||
if (idMap.has(connection.id)) {
|
||||
const newId = idMap.get(connection.id);
|
||||
assertExists(newId, 'reference id must exist');
|
||||
if (!newId) {
|
||||
throw new BlockSuiteError(
|
||||
BlockSuiteError.ErrorCode.TransformerError,
|
||||
`reference id must exist: ${connection.id}`
|
||||
);
|
||||
}
|
||||
connection.id = newId;
|
||||
}
|
||||
break;
|
||||
@@ -184,7 +194,12 @@ export const replaceIdMiddleware =
|
||||
if (idMap.has(key)) {
|
||||
delete json[key];
|
||||
const newKey = idMap.get(key);
|
||||
assertExists(newKey, 'reference id must exist');
|
||||
if (!newKey) {
|
||||
throw new BlockSuiteError(
|
||||
BlockSuiteError.ErrorCode.TransformerError,
|
||||
`reference id must exist: ${key}`
|
||||
);
|
||||
}
|
||||
json[newKey] = value;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user