import type { MountedEditorView } from '@admin/utils/editor/mounted-editor-view' import type { Editor } from '@tiptap/react' import { getTableFromWrapper } from '@admin/utils/editor/get-table-from-wrapper' import { TABLE_WRAPPER_CLASS } from '@admin/utils/editor/table-wrapper-class' export function getTableFromEventTarget( editor: Editor, view: MountedEditorView, target: EventTarget | null ): { pos: number; wrapper: HTMLElement } | null { if (!(target instanceof HTMLElement)) return null const wrapper = target.closest(`.${TABLE_WRAPPER_CLASS}`) if (!(wrapper instanceof HTMLElement) || !view.dom.contains(wrapper)) { return null } return getTableFromWrapper(editor, view, wrapper) }