refactor(editor): unify directories naming (#11516)

**Directory Structure Changes**

- Renamed multiple block-related directories by removing the "block-" prefix:
  - `block-attachment` → `attachment`
  - `block-bookmark` → `bookmark`
  - `block-callout` → `callout`
  - `block-code` → `code`
  - `block-data-view` → `data-view`
  - `block-database` → `database`
  - `block-divider` → `divider`
  - `block-edgeless-text` → `edgeless-text`
  - `block-embed` → `embed`
This commit is contained in:
Saul-Mirone
2025-04-07 12:34:40 +00:00
parent e1bd2047c4
commit 1f45cc5dec
893 changed files with 439 additions and 460 deletions
@@ -0,0 +1,94 @@
import {
AttachmentBlockModel,
BookmarkBlockModel,
CalloutBlockModel,
CodeBlockModel,
DatabaseBlockModel,
DividerBlockModel,
ImageBlockModel,
ListBlockModel,
ParagraphBlockModel,
} from '@blocksuite/affine-model';
import { EMBED_BLOCK_MODEL_LIST } from '@blocksuite/affine-shared/consts';
import {
getNextContentBlock,
matchModels,
} from '@blocksuite/affine-shared/utils';
import {
BlockSelection,
type BlockStdScope,
TextSelection,
} from '@blocksuite/std';
export function forwardDelete(std: BlockStdScope) {
const { store, host } = std;
const text = std.selection.find(TextSelection);
if (!text) return;
const isCollapsed = text.isCollapsed();
const model = store.getBlock(text.from.blockId)?.model;
if (
!model ||
!matchModels(model, [ParagraphBlockModel]) ||
matchModels(model.parent, [CalloutBlockModel])
)
return;
const isEnd = isCollapsed && text.from.index === model.props.text.length;
if (!isEnd) return;
const parent = store.getParent(model);
if (!parent) return;
const nextSibling = store.getNext(model);
if (
matchModels(nextSibling, [
AttachmentBlockModel,
BookmarkBlockModel,
DatabaseBlockModel,
CodeBlockModel,
ImageBlockModel,
DividerBlockModel,
...EMBED_BLOCK_MODEL_LIST,
] as const)
) {
std.selection.setGroup('note', [
std.selection.create(BlockSelection, { blockId: nextSibling.id }),
]);
return true;
}
if (matchModels(nextSibling, [ParagraphBlockModel, ListBlockModel])) {
model.props.text.join(nextSibling.props.text);
if (nextSibling.children) {
const parent = store.getParent(nextSibling);
if (!parent) return false;
store.moveBlocks(nextSibling.children, parent, model, false);
}
store.deleteBlock(nextSibling);
return true;
}
const nextBlock = getNextContentBlock(host, model);
if (nextBlock?.text) {
model.props.text.join(nextBlock.text);
if (nextBlock.children) {
const parent = store.getParent(nextBlock);
if (!parent) return false;
store.moveBlocks(
nextBlock.children,
parent,
store.getParent(model),
false
);
}
store.deleteBlock(nextBlock);
return true;
}
if (nextBlock) {
std.selection.setGroup('note', [
std.selection.create(BlockSelection, { blockId: nextBlock.id }),
]);
}
return true;
}
@@ -0,0 +1,162 @@
import {
AttachmentBlockModel,
BookmarkBlockModel,
CalloutBlockModel,
CodeBlockModel,
DatabaseBlockModel,
DividerBlockModel,
EdgelessTextBlockModel,
ImageBlockModel,
ListBlockModel,
ParagraphBlockModel,
type RootBlockModel,
} from '@blocksuite/affine-model';
import {
asyncSetInlineRange,
focusTextModel,
} from '@blocksuite/affine-rich-text';
import { EMBED_BLOCK_MODEL_LIST } from '@blocksuite/affine-shared/consts';
import type { ExtendedModel } from '@blocksuite/affine-shared/types';
import {
focusTitle,
getDocTitleInlineEditor,
getPrevContentBlock,
matchModels,
} from '@blocksuite/affine-shared/utils';
import { BlockSelection, type EditorHost } from '@blocksuite/std';
import type { BlockModel, Text } from '@blocksuite/store';
/**
* Merge the paragraph with prev block
*
* Before press backspace
* - line1
* - line2
* - |aaa
* - line3
*
* After press backspace
* - line1
* - line2|aaa
* - line3
*/
export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
const doc = model.doc;
const parent = doc.getParent(model);
if (!parent) return false;
if (matchModels(parent, [EdgelessTextBlockModel])) {
return true;
}
const prevBlock = getPrevContentBlock(editorHost, model);
if (!prevBlock) {
return handleNoPreviousSibling(editorHost, model);
}
const modelIndex = parent.children.indexOf(model);
const prevSibling = doc.getPrev(model);
if (matchModels(prevSibling, [CalloutBlockModel])) {
editorHost.selection.setGroup('note', [
editorHost.selection.create(BlockSelection, {
blockId: prevSibling.id,
}),
]);
return true;
}
if (matchModels(prevBlock, [ParagraphBlockModel, ListBlockModel])) {
if (
(modelIndex === -1 || modelIndex === parent.children.length - 1) &&
parent.role === 'content'
)
return false;
const lengthBeforeJoin = prevBlock.props.text?.length ?? 0;
prevBlock.props.text.join(model.text as Text);
doc.deleteBlock(model, {
bringChildrenTo: parent,
});
asyncSetInlineRange(editorHost.std, prevBlock, {
index: lengthBeforeJoin,
length: 0,
}).catch(console.error);
return true;
}
if (
matchModels(prevBlock, [
AttachmentBlockModel,
BookmarkBlockModel,
CodeBlockModel,
ImageBlockModel,
DividerBlockModel,
...EMBED_BLOCK_MODEL_LIST,
])
) {
const selection = editorHost.selection.create(BlockSelection, {
blockId: prevBlock.id,
});
editorHost.selection.setGroup('note', [selection]);
if (model.text?.length === 0) {
doc.deleteBlock(model, {
bringChildrenTo: parent,
});
}
return true;
}
if (matchModels(parent, [DatabaseBlockModel])) {
doc.deleteBlock(model);
focusTextModel(editorHost.std, prevBlock.id, prevBlock.text?.yText.length);
return true;
}
return false;
}
function handleNoPreviousSibling(editorHost: EditorHost, model: ExtendedModel) {
const doc = model.doc;
const text = model.text;
const parent = doc.getParent(model);
if (!parent) return false;
const titleEditor = getDocTitleInlineEditor(editorHost);
// Probably no title, e.g. in edgeless mode
if (!titleEditor) {
if (
matchModels(parent, [EdgelessTextBlockModel]) ||
model.children.length > 0
) {
doc.deleteBlock(model, {
bringChildrenTo: parent,
});
return true;
}
return false;
}
const rootModel = model.doc.root as RootBlockModel;
const title = rootModel.props.title;
doc.captureSync();
let textLength = 0;
if (text) {
textLength = text.length;
title.join(text);
}
// Preserve at least one block to be able to focus on container click
if (doc.getNext(model) || model.children.length > 0) {
const parent = doc.getParent(model);
if (!parent) return false;
doc.deleteBlock(model, {
bringChildrenTo: parent,
});
} else {
text?.clear();
}
focusTitle(editorHost, title.length - textLength);
return true;
}