mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
refactoring
This commit is contained in:
parent
a97c07dc73
commit
19c3599605
@ -46,7 +46,7 @@ export default {
|
||||
})
|
||||
|
||||
popup = tippy('body', {
|
||||
getReferenceClientRect: () => props.virtualNode.getBoundingClientRect(),
|
||||
getReferenceClientRect: () => props.clientRect,
|
||||
appendTo: () => document.body,
|
||||
content: component.element,
|
||||
showOnCreate: true,
|
||||
@ -59,7 +59,7 @@ export default {
|
||||
component.updateProps(props)
|
||||
|
||||
popup[0].setProps({
|
||||
getReferenceClientRect: () => props.virtualNode.getBoundingClientRect(),
|
||||
getReferenceClientRect: () => props.clientRect,
|
||||
})
|
||||
},
|
||||
onKeyDown(props) {
|
||||
|
@ -1,15 +0,0 @@
|
||||
export interface VirtualNode {
|
||||
getBoundingClientRect: () => DOMRect,
|
||||
clientWidth: number,
|
||||
clientHeight: number,
|
||||
}
|
||||
|
||||
export function getVirtualNode(node: Element): VirtualNode {
|
||||
return {
|
||||
getBoundingClientRect() {
|
||||
return node.getBoundingClientRect()
|
||||
},
|
||||
clientWidth: node.clientWidth,
|
||||
clientHeight: node.clientHeight,
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
import { Suggestion } from './suggestion'
|
||||
|
||||
export * from './findSuggestionMatch'
|
||||
export * from './getVirtualNode'
|
||||
export * from './suggestion'
|
||||
|
||||
export default Suggestion
|
||||
|
@ -2,7 +2,6 @@ import { Editor, Range, AnyObject } from '@tiptap/core'
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view'
|
||||
import { findSuggestionMatch } from './findSuggestionMatch'
|
||||
import { getVirtualNode, VirtualNode } from './getVirtualNode'
|
||||
|
||||
export interface SuggestionOptions {
|
||||
editor: Editor,
|
||||
@ -28,7 +27,7 @@ export interface SuggestionProps {
|
||||
items: any[],
|
||||
command: (attributes: AnyObject) => void,
|
||||
decorationNode: Element | null,
|
||||
virtualNode: VirtualNode | null,
|
||||
clientRect: DOMRect | null,
|
||||
}
|
||||
|
||||
export interface SuggestionKeyDownProps {
|
||||
@ -87,11 +86,9 @@ export function Suggestion({
|
||||
command({ range: state.range, attributes })
|
||||
},
|
||||
decorationNode,
|
||||
// build a virtual node for popper.js or tippy.js
|
||||
// virtual node for popper.js or tippy.js
|
||||
// this can be used for building popups without a DOM node
|
||||
virtualNode: decorationNode
|
||||
? getVirtualNode(decorationNode)
|
||||
: null,
|
||||
clientRect: decorationNode?.getBoundingClientRect() || null,
|
||||
}
|
||||
|
||||
if (handleStart) {
|
||||
|
Loading…
Reference in New Issue
Block a user