import type { MountedEditorView } from '@admin/utils/editor/mounted-editor-view' import type { Editor } from '@tiptap/react' import { getTableElement } from '@admin/utils/editor/get-table-element' export function getTablePositionForElement( editor: Editor, view: MountedEditorView, tableElement: HTMLTableElement ): number | null { let tablePos: number | null = null editor.state.doc.descendants((node, pos) => { if (node.type.name !== 'table') return true if (getTableElement(view.nodeDOM(pos)) === tableElement) { tablePos = pos return false } return true }) return tablePos }