import type { MountedEditorView } from '@admin/utils/editor/mounted-editor-view' import type { Editor } from '@tiptap/react' import { getTableWrapperElement } from '@admin/utils/editor/get-table-wrapper-element' import { findTable } from '@tiptap/pm/tables' export function getSelectionTable( editor: Editor, view: MountedEditorView ): { pos: number; wrapper: HTMLElement } | null { const table = findTable(editor.state.selection.$from) if (!table) return null const wrapper = getTableWrapperElement(view.nodeDOM(table.pos)) if (!wrapper) return null return { pos: table.pos, wrapper } }