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