Accept hex pubkeys/npubs/nprofiles in ProfileMultiSelect

This commit is contained in:
Jon Staab
2026-01-06 10:17:17 -08:00
parent 0d6b4591f1
commit 986973a605
2 changed files with 24 additions and 3 deletions
@@ -1,4 +1,5 @@
<script lang="ts">
import * as nip19 from "nostr-tools/nip19"
import {writable} from "svelte/store"
import type {Writable} from "svelte/store"
import {type Instance} from "tippy.js"
@@ -35,6 +36,26 @@
value = remove(pubkey, value)
}
const onInput = (e: any) => {
if (e.target.value.match(/^[a-f0-9]{64}$/)) {
selectPubkey(e.target.value)
}
try {
const {type, data} = nip19.decode(e.target.value) as any
if (type === "npub") {
selectPubkey(data)
}
if (type === "nprofile") {
selectPubkey(data.pubkey)
}
} catch (e) {
// pass
}
}
const onKeyDown = (e: Event) => {
if (instance.onKeyDown(e)) {
e.preventDefault()
@@ -80,6 +101,7 @@
type="text"
placeholder="Search for profiles..."
bind:value={$term}
oninput={onInput}
onkeydown={onKeyDown} />
</label>
<Tippy
+2 -3
View File
@@ -76,9 +76,8 @@
onclick={stopPropagation(preventDefault(() => select(value)))}>
<Component {value}></Component>
</button>
{:else}
<div class="tiptap-suggestions__item">No results</div>
{/each}
</div>
{#if items.length === 0}
<div class="tiptap-suggestions__empty">No results</div>
{/if}
</div>