/
githubmirror
/
halo
Обзор
Документация
Войти
/
githubmirror
/
halo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ui/packages/editor/src/utils/node-view.ts
35 строк
1 KB
Takagi
refactor: rebuild editor gap cursor (#10203)
05 авг 2026, 06:39
Не верифицирован
05 авг 2026, 06:39
fb3037b
Код
Авторство
О чём код?
import type { EditorView } from "@/tiptap/pm"; /** * Resolves a ProseMirror node view DOM reference to its nearest HTML element. * * @remarks * ProseMirror node views may expose a non-element DOM node. In that case, this * helper returns its parent element. * * @param view - The ProseMirror editor view containing the node view. * @param pos - The document position at which the node starts. * @returns The node view element, its parent element, or `null` when no element * can be resolved. * * @example * ```ts * import { getEditorNodeElement } from "@halo-dev/richtext-editor"; * * const firstNodeElement = getEditorNodeElement(editor.view, 0); * firstNodeElement?.scrollIntoView({ block: "nearest" }); * ``` */ export function getEditorNodeElement( view: EditorView, pos: number ): HTMLElement | null { const nodeDOM = view.nodeDOM(pos); if (nodeDOM instanceof HTMLElement) { return nodeDOM; } if (nodeDOM?.parentElement instanceof HTMLElement) { return nodeDOM.parentElement; } return null; }