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"}}> replyTo(event) const onEdit = () => edit?.() const showInfo = () => { - popover.hide() + tippy.hide() pushModal(EventInfo, {event}) } diff --git a/src/app/components/CurrencyInput.svelte b/src/app/components/CurrencyInput.svelte index ffea2edb..a1c4ce11 100644 --- a/src/app/components/CurrencyInput.svelte +++ b/src/app/components/CurrencyInput.svelte @@ -1,9 +1,10 @@ @@ -82,9 +82,7 @@ {/if} import type {Snippet} from "svelte" - import type {Instance} from "tippy.js" + import type {Maybe} from "@welshman/lib" import type {NativeEmoji} from "emoji-picker-element/shared" import type {TrustedEvent} from "@welshman/util" import {tagSpec, tagValue} from "@welshman/util" @@ -9,6 +9,7 @@ import MenuDots from "@assets/icons/menu-dots.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 EmojiButton from "@lib/components/EmojiButton.svelte" import ZapButton from "@app/components/ZapButton.svelte" @@ -28,7 +29,9 @@ const shouldProtect = $relays.hasNip(url, 70) - const hidePopover = () => popover?.hide() + const showPopover = () => tippy?.show() + + const hidePopover = () => tippy?.hide() const onEmoji = async (emoji: NativeEmoji) => { const protect = await shouldProtect @@ -45,8 +48,7 @@ return command.publishToRelays([url]) } - let popover: Instance | undefined = $state() - let showPopover: () => void = $state(() => {}) + let tippy: Maybe = $state() @@ -60,8 +62,7 @@ diff --git a/src/app/components/ProfileMenu.svelte b/src/app/components/ProfileMenu.svelte index 47e9d1de..258be1c6 100644 --- a/src/app/components/ProfileMenu.svelte +++ b/src/app/components/ProfileMenu.svelte @@ -1,9 +1,10 @@ diff --git a/src/app/components/ProfileMultiSelect.svelte b/src/app/components/ProfileMultiSelect.svelte index 98911451..70ff4e7a 100644 --- a/src/app/components/ProfileMultiSelect.svelte +++ b/src/app/components/ProfileMultiSelect.svelte @@ -3,12 +3,14 @@ import type {Writable} from "svelte/store" import {type Instance} from "tippy.js" import {append, remove, uniq} from "@welshman/lib" + import type {Maybe} from "@welshman/lib" import {decodePubkey} from "@lib/util" import Suggestions from "@lib/components/Suggestions.svelte" import CloseCircle from "@assets/icons/close-circle.svg?dataurl" 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 Badge from "@lib/components/Badge.svelte" import ProfileSuggestion from "@app/editor/ProfileSuggestion.svelte" @@ -31,7 +33,7 @@ const selectPubkey = (pubkey: string) => { term.set("") - popover?.hide() + tippy?.hide() value = uniq(append(pubkey, value)) } @@ -48,24 +50,22 @@ } const onKeyDown = (e: Event) => { - if (instance?.onKeyDown(e)) { + if (tippy?.content?.onKeyDown(e)) { e.preventDefault() } } let label: Element | undefined = $state() - let popover: Instance | undefined = $state() - let showPopover: () => void = $state(() => {}) - let instance: any = $state() + let tippy: Maybe = $state() $effect(() => { // @ts-ignore oninput?.($term) if ($term) { - showPopover() + tippy?.show() } else { - popover?.hide() + tippy?.hide() } }) @@ -97,9 +97,7 @@ onkeydown={onKeyDown} /> - import type {Instance} from "tippy.js" import {writable} from "svelte/store" + import type {Maybe} from "@welshman/lib" import type {EventContent} from "@welshman/util" import {isMobile, preventDefault} from "@lib/html" import GallerySend from "@assets/icons/gallery-send.svg?dataurl" @@ -9,6 +9,7 @@ import Icon from "@lib/components/Icon.svelte" import Button from "@lib/components/Button.svelte" import Tippy from "@lib/components/Tippy.svelte" + import type {TippyController} from "@lib/components/Tippy.svelte" import Spinner from "@lib/components/Spinner.svelte" import ComposeMenu from "@app/components/ComposeMenu.svelte" import EditorContent from "@app/editor/EditorContent.svelte" @@ -52,7 +53,9 @@ const uploadFiles = () => editor.then(ed => ed.chain().selectFiles().run()) - const hidePopover = () => popover?.hide() + const showPopover = () => tippy?.show() + + const hidePopover = () => tippy?.hide() const submit = async () => { if ($uploading) return @@ -67,8 +70,7 @@ ed.chain().clearContent().run() } - let popover: Instance | undefined = $state() - let showPopover: () => void = $state(() => {}) + let tippy: Maybe = $state() let content = $state( initialValues?.type === "text" ? initialValues.value : (draftKey?.get()?.content ?? ""), ) @@ -124,8 +126,7 @@ onclick={showPopover} class="join-item h-10 w-10 min-w-10 button button-neutral"> diff --git a/src/app/components/RoomItemMenuButton.svelte b/src/app/components/RoomItemMenuButton.svelte index 1d142fed..182b7686 100644 --- a/src/app/components/RoomItemMenuButton.svelte +++ b/src/app/components/RoomItemMenuButton.svelte @@ -1,48 +1,42 @@ - + + params={{trigger: "manual", interactive: true}}> 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() - + + params={{trigger: "manual", interactive: true, ...tippyParams}}> {@render props.children?.()} 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 @@ diff --git a/src/lib/components/Tippy.svelte b/src/lib/components/Tippy.svelte index 555f6961..65c86b30 100644 --- a/src/lib/components/Tippy.svelte +++ b/src/lib/components/Tippy.svelte @@ -1,3 +1,16 @@ + +