Files
Momento/memento-note/lib/editor/block-at-drag-handle.ts
Antigravity a623454347
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m32s
CI / Deploy production (on server) (push) Has been skipped
perf: memo GridCard, fuse save fns, fix slash tab active color
2026-06-14 14:06:05 +00:00

26 lines
958 B
TypeScript

import type { Editor } from '@tiptap/core'
import type { Node as PMNode } from '@tiptap/pm/model'
export const BLOCK_DRAG_HANDLE_ID = 'notion-block-drag-handle'
export const BLOCK_DRAG_HANDLE_WIDTH = 20
/** Même logique de résolution de bloc que tiptap-extension-global-drag-handle */
export function resolveBlockAtDragHandle(editor: Editor): { node: PMNode; pos: number } | null {
const handle = document.getElementById(BLOCK_DRAG_HANDLE_ID)
if (!handle || editor.isDestroyed) return null
const rect = handle.getBoundingClientRect()
const coords = editor.view.posAtCoords({
left: rect.right + 50 + BLOCK_DRAG_HANDLE_WIDTH,
top: rect.top + rect.height / 2,
})
if (coords?.pos == null) return null
const $pos = editor.state.doc.resolve(coords.pos)
const blockPos = $pos.depth > 0 ? $pos.before($pos.depth) : coords.pos
const node = editor.state.doc.nodeAt(blockPos)
if (!node) return null
return { node, pos: blockPos }
}