chore: merge blocksuite source code (#9213)

This commit is contained in:
Mirone
2024-12-20 15:38:06 +08:00
committed by GitHub
parent 2c9ef916f4
commit 30200ff86d
2031 changed files with 238888 additions and 229 deletions
@@ -0,0 +1,69 @@
import { EMBED_BLOCK_FLAVOUR_LIST } from '@blocksuite/affine-shared/consts';
import {
getNextContentBlock,
matchFlavours,
} from '@blocksuite/affine-shared/utils';
import type { BlockStdScope } from '@blocksuite/block-std';
export function forwardDelete(std: BlockStdScope) {
const { doc, host } = std;
const text = std.selection.find('text');
if (!text) return;
const isCollapsed = text.isCollapsed();
const model = doc.getBlock(text.from.blockId)?.model;
if (!model || !matchFlavours(model, ['affine:paragraph'])) return;
const isEnd = isCollapsed && text.from.index === model.text.length;
if (!isEnd) return;
const parent = doc.getParent(model);
if (!parent) return;
const nextSibling = doc.getNext(model);
const ignoreForwardDeleteFlavourList: BlockSuite.Flavour[] = [
'affine:attachment',
'affine:bookmark',
// @ts-expect-error TODO: should be fixed after database model is migrated to affine-models
'affine:database',
'affine:code',
'affine:image',
'affine:divider',
...EMBED_BLOCK_FLAVOUR_LIST,
];
if (matchFlavours(nextSibling, ignoreForwardDeleteFlavourList)) {
std.selection.setGroup('note', [
std.selection.create('block', { blockId: nextSibling.id }),
]);
return true;
}
if (nextSibling?.text) {
model.text.join(nextSibling.text);
if (nextSibling.children) {
const parent = doc.getParent(nextSibling);
if (!parent) return false;
doc.moveBlocks(nextSibling.children, parent, model, false);
}
doc.deleteBlock(nextSibling);
return true;
}
const nextBlock = getNextContentBlock(host, model);
if (nextBlock?.text) {
model.text.join(nextBlock.text);
if (nextBlock.children) {
const parent = doc.getParent(nextBlock);
if (!parent) return false;
doc.moveBlocks(nextBlock.children, parent, doc.getParent(model), false);
}
doc.deleteBlock(nextBlock);
return true;
}
if (nextBlock) {
std.selection.setGroup('note', [
std.selection.create('block', { blockId: nextBlock.id }),
]);
}
return true;
}