From 6b517a47ef6262195f66b35fcef524e9db963687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 19 Jan 2021 12:28:33 +0100 Subject: [PATCH] refactoring --- docs/src/demos/Nodes/Mention/index.vue | 4 ++-- packages/suggestion/src/getVirtualNode.ts | 15 --------------- packages/suggestion/src/index.ts | 1 - packages/suggestion/src/suggestion.ts | 9 +++------ 4 files changed, 5 insertions(+), 24 deletions(-) delete mode 100644 packages/suggestion/src/getVirtualNode.ts diff --git a/docs/src/demos/Nodes/Mention/index.vue b/docs/src/demos/Nodes/Mention/index.vue index 1aafe52dd..2596a9a9f 100644 --- a/docs/src/demos/Nodes/Mention/index.vue +++ b/docs/src/demos/Nodes/Mention/index.vue @@ -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) { diff --git a/packages/suggestion/src/getVirtualNode.ts b/packages/suggestion/src/getVirtualNode.ts deleted file mode 100644 index 1b6a5c735..000000000 --- a/packages/suggestion/src/getVirtualNode.ts +++ /dev/null @@ -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, - } -} diff --git a/packages/suggestion/src/index.ts b/packages/suggestion/src/index.ts index 6a8d7a35d..5e319dd40 100644 --- a/packages/suggestion/src/index.ts +++ b/packages/suggestion/src/index.ts @@ -1,7 +1,6 @@ import { Suggestion } from './suggestion' export * from './findSuggestionMatch' -export * from './getVirtualNode' export * from './suggestion' export default Suggestion diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index 2d73511bc..17c30152f 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -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) {