refactoring: rename posToClientRect to posToDOMRect

This commit is contained in:
Philipp Kühn
2021-04-16 14:44:10 +02:00
parent c4e0010656
commit 89b72b8608
4 changed files with 18 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
import { EditorView } from 'prosemirror-view'
import coordsAtPos from './coordsAtPos'
export default function posToClientRect(view: EditorView, from: number, to: number): ClientRect {
export default function posToDOMRect(view: EditorView, from: number, to: number): DOMRect {
const start = coordsAtPos(view, from)
const end = coordsAtPos(view, to, true)
const top = Math.min(start.top, end.top)
@@ -10,13 +10,21 @@ export default function posToClientRect(view: EditorView, from: number, to: numb
const right = Math.max(start.right, end.right)
const width = right - left
const height = bottom - top
return {
width,
height,
const x = left
const y = top
const data = {
top,
bottom,
left,
right,
width,
height,
x,
y,
}
return {
...data,
toJSON: () => data,
}
}

View File

@@ -27,7 +27,7 @@ export { default as isNodeActive } from './helpers/isNodeActive'
export { default as isNodeEmpty } from './helpers/isNodeEmpty'
export { default as isNodeSelection } from './helpers/isNodeSelection'
export { default as isTextSelection } from './helpers/isTextSelection'
export { default as posToClientRect } from './helpers/posToClientRect'
export { default as posToDOMRect } from './helpers/posToDOMRect'
export interface Commands {}

View File

@@ -1,4 +1,4 @@
import { Editor, posToClientRect } from '@tiptap/core'
import { Editor, posToDOMRect } from '@tiptap/core'
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import tippy, { Instance, Props } from 'tippy.js'
@@ -97,7 +97,7 @@ export class BubbleMenuView {
}
this.tippy.setProps({
getReferenceClientRect: () => posToClientRect(view, from, to),
getReferenceClientRect: () => posToDOMRect(view, from, to),
})
this.show()

View File

@@ -1,4 +1,4 @@
import { Editor, isNodeEmpty, posToClientRect } from '@tiptap/core'
import { Editor, isNodeEmpty, posToDOMRect } from '@tiptap/core'
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import tippy, { Instance, Props } from 'tippy.js'
@@ -106,7 +106,7 @@ export class FloatingMenuView {
}
this.tippy.setProps({
getReferenceClientRect: () => posToClientRect(view, from, to),
getReferenceClientRect: () => posToDOMRect(view, from, to),
})
this.show()