From a6bf8742806be61044310b1169682b2134071a3d Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Sat, 29 Aug 2026 10:20:39 -0700 Subject: [PATCH] Simplify tippy api --- src/app/components/ChatMessage.svelte | 31 +++------- src/app/components/ChatMessageMenu.svelte | 4 +- src/app/components/CurrencyInput.svelte | 20 +++---- src/app/components/EventActions.svelte | 13 +++-- src/app/components/ProfileMenu.svelte | 13 +++-- src/app/components/ProfileMultiSelect.svelte | 18 +++--- src/app/components/RoomCompose.svelte | 13 +++-- src/app/components/RoomItemMenuButton.svelte | 32 +++++----- src/app/components/TopicMultiSelect.svelte | 20 +++---- src/lib/components/EmojiButton.svelte | 34 +++++------ src/lib/components/IconPickerButton.svelte | 23 ++++---- src/lib/components/MenuButton.svelte | 13 +++-- src/lib/components/Tippy.svelte | 61 ++++++++++++++++---- 13 files changed, 149 insertions(+), 146 deletions(-) diff --git a/src/app/components/ChatMessage.svelte b/src/app/components/ChatMessage.svelte index 2e036a74..e205ef51 100644 --- a/src/app/components/ChatMessage.svelte +++ b/src/app/components/ChatMessage.svelte @@ -1,7 +1,7 @@ @@ -71,20 +64,10 @@ class={cx("group flex items-center justify-end gap-1 px-2", {"flex-row-reverse": !isOwn})}> {#if !isMobile} + props={{event, pubkeys, tippy, replyTo, edit}} + params={{interactive: true, trigger: "manual"}}> diff --git a/src/app/components/TopicMultiSelect.svelte b/src/app/components/TopicMultiSelect.svelte index 54d370cd..6a0156bc 100644 --- a/src/app/components/TopicMultiSelect.svelte +++ b/src/app/components/TopicMultiSelect.svelte @@ -3,6 +3,7 @@ import type {Writable} from "svelte/store" import type {Instance} from "tippy.js" import {remove, reject, spec, uniq} from "@welshman/lib" + import type {Maybe} from "@welshman/lib" import {Topics, createSearch} from "@welshman/app" import {normalizeTopic} from "@lib/util" import Suggestions from "@lib/components/Suggestions.svelte" @@ -10,6 +11,7 @@ import Magnifier from "@assets/icons/magnifier.svg?dataurl" import Icon from "@lib/components/Icon.svelte" import Tippy from "@lib/components/Tippy.svelte" + import type {TippyController} from "@lib/components/Tippy.svelte" import Button from "@lib/components/Button.svelte" import TopicSuggestion from "@app/components/TopicSuggestion.svelte" import {app} from "@app/core" @@ -41,7 +43,7 @@ } term.set("") - popover?.hide() + tippy?.hide() } const removeTopic = (topic: string) => { @@ -49,7 +51,7 @@ } const onKeyDown = (e: KeyboardEvent) => { - if (instance?.onKeyDown(e)) { + if (tippy?.content?.onKeyDown(e)) { e.preventDefault() return } @@ -62,19 +64,17 @@ const onBlur = () => { term.set("") - popover?.hide() + tippy?.hide() } let label: Element | undefined = $state() - let popover: Instance | undefined = $state() - let showPopover: () => void = $state(() => {}) - let instance: any = $state() + let tippy: Maybe = $state() $effect(() => { if ($term.trim()) { - showPopover() + tippy?.show() } else { - popover?.hide() + tippy?.hide() } }) @@ -101,9 +101,7 @@ onblur={onBlur} /> - import {type Instance} from "tippy.js" import type {NativeEmoji} from "emoji-picker-element/shared" import {between, throttle} from "@welshman/lib" + import type {Maybe} from "@welshman/lib" import Button from "@lib/components/Button.svelte" import Tippy from "@lib/components/Tippy.svelte" + import type {TippyController} from "@lib/components/Tippy.svelte" import EmojiPicker from "@lib/components/EmojiPicker.svelte" const {tippyParams = {}, ...props} = $props() + const open = () => tippy?.show() + const onClick = (emoji: NativeEmoji) => { props.onEmoji(emoji) - popover?.hide() - } - - const onShow = () => { - visible = true - } - - const onHidden = () => { - visible = false + tippy?.hide() } const onMouseMove = throttle(300, ({clientX, clientY}: MouseEvent) => { - if (popover) { - const {x, y, width, height} = popover.popper.getBoundingClientRect() + const rect = tippy?.rect() + + if (rect) { + const {x, y, width, height} = rect if (!between([x, x + width], clientX) || !between([y - 100, y + height + 100], clientY)) { - popover.hide() + tippy!.hide() } } }) - let popover: Instance | undefined = $state() - let open: () => void = $state(() => {}) - let visible = $state(false) + let tippy: Maybe = $state() - + diff --git a/src/lib/components/IconPickerButton.svelte b/src/lib/components/IconPickerButton.svelte index f3dcf7f5..0764151c 100644 --- a/src/lib/components/IconPickerButton.svelte +++ b/src/lib/components/IconPickerButton.svelte @@ -1,9 +1,10 @@ diff --git a/src/lib/components/MenuButton.svelte b/src/lib/components/MenuButton.svelte index aa944e2a..2832d71b 100644 --- a/src/lib/components/MenuButton.svelte +++ b/src/lib/components/MenuButton.svelte @@ -1,9 +1,10 @@