Accept hex pubkeys/npubs/nprofiles in ProfileMultiSelect
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import * as nip19 from "nostr-tools/nip19"
|
||||||
import {writable} from "svelte/store"
|
import {writable} from "svelte/store"
|
||||||
import type {Writable} from "svelte/store"
|
import type {Writable} from "svelte/store"
|
||||||
import {type Instance} from "tippy.js"
|
import {type Instance} from "tippy.js"
|
||||||
@@ -35,6 +36,26 @@
|
|||||||
value = remove(pubkey, value)
|
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) => {
|
const onKeyDown = (e: Event) => {
|
||||||
if (instance.onKeyDown(e)) {
|
if (instance.onKeyDown(e)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -80,6 +101,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Search for profiles..."
|
placeholder="Search for profiles..."
|
||||||
bind:value={$term}
|
bind:value={$term}
|
||||||
|
oninput={onInput}
|
||||||
onkeydown={onKeyDown} />
|
onkeydown={onKeyDown} />
|
||||||
</label>
|
</label>
|
||||||
<Tippy
|
<Tippy
|
||||||
|
|||||||
@@ -76,9 +76,8 @@
|
|||||||
onclick={stopPropagation(preventDefault(() => select(value)))}>
|
onclick={stopPropagation(preventDefault(() => select(value)))}>
|
||||||
<Component {value}></Component>
|
<Component {value}></Component>
|
||||||
</button>
|
</button>
|
||||||
|
{:else}
|
||||||
|
<div class="tiptap-suggestions__item">No results</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{#if items.length === 0}
|
|
||||||
<div class="tiptap-suggestions__empty">No results</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user