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,32 @@
import type { EditorHost } from '@blocksuite/block-std';
import type { InlineEditor } from '@blocksuite/inline';
function getDocTitleByEditorHost(editorHost: EditorHost): HTMLElement | null {
const docViewport = editorHost.closest('.affine-page-viewport');
if (!docViewport) return null;
return docViewport.querySelector('doc-title');
}
export function getDocTitleInlineEditor(
editorHost: EditorHost
): InlineEditor | null {
const docTitle = getDocTitleByEditorHost(editorHost);
if (!docTitle) return null;
const titleRichText = docTitle.querySelector<
HTMLElement & { inlineEditor: InlineEditor }
>('rich-text');
if (!titleRichText || !titleRichText.inlineEditor) return null;
return titleRichText.inlineEditor;
}
export function focusTitle(editorHost: EditorHost, index = Infinity, len = 0) {
const titleInlineEditor = getDocTitleInlineEditor(editorHost);
if (!titleInlineEditor) {
return;
}
if (index > titleInlineEditor.yText.length) {
index = titleInlineEditor.yText.length;
}
titleInlineEditor.setInlineRange({ index, length: len });
}