Files
flotilla/src/app/components/ProfileMultiSelect.svelte
T
hodlbod 9df8cee501 Migrate to new @welshman/domain + instance-based @welshman/app API
Adopts the rewritten welshman API: the removed @welshman/util helpers
(Profile/List/Room/Handler/Encryptable) are now Reader/Builder classes in
@welshman/domain, and @welshman/app dropped its global singletons for an App
instance + app.use(Plugin) registry.

- src/app/welshman.ts is now the app bootstrap + session-state module (one shared
  App instance, multi-account sessions/login, app-wide reactive views) rather than
  a compat shim re-exporting the old globals.
- Rewrote ~100 callers to use app.use(Plugin) directly (thunks, profiles, relays,
  rooms, zaps, tags, wot, feeds, sync); thunk helpers are now thunk methods.
- Added @welshman/domain dependency.
- Resolved residual gaps (storage hydration via plugin.onItem/wrapManager/Plaintext,
  relay-list mutators, search-relay list, outbox #d filter).

Best-effort: no toolchain/linking available, so this is not build- or
type-checked. Remaining judgment calls are flagged with TODO(welshman-migration).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BsMjvv7krpZeHK1Njeneru
2026-06-20 14:55:06 +00:00

129 lines
3.5 KiB
Svelte

<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"
import {append, remove, uniq} from "@welshman/lib"
import {profileSearch} from "@app/welshman"
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 Button from "@lib/components/Button.svelte"
import ProfileSuggestion from "@app/editor/ProfileSuggestion.svelte"
import ProfileName from "@app/components/ProfileName.svelte"
import ProfileDetail from "@app/components/ProfileDetail.svelte"
import {pushModal} from "@app/modal"
interface Props {
value: string[]
autofocus?: boolean
term?: Writable<string>
}
let {value = $bindable(), term = writable(""), autofocus = false}: Props = $props()
const search = (term: string) => $profileSearch.searchValues(term)
const selectPubkey = (pubkey: string) => {
term.set("")
popover?.hide()
value = uniq(append(pubkey, value))
}
const removePubkey = (pubkey: string) => {
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()
}
}
let label: Element | undefined = $state()
let popover: Instance | undefined = $state()
let instance: any = $state()
$effect(() => {
// @ts-ignore
oninput?.($term)
if ($term) {
popover?.show()
} else {
popover?.hide()
}
})
</script>
<div class="flex flex-col gap-2">
<div>
{#each value as pubkey (pubkey)}
{@const onClick = () => pushModal(ProfileDetail, {pubkey})}
<div class="flex-inline badge badge-neutral mr-1 gap-1">
<Button class="flex items-center" onclick={() => removePubkey(pubkey)}>
<Icon icon={CloseCircle} size={4} class="-ml-1 mt-px" />
</Button>
<Button onclick={onClick}>
<ProfileName {pubkey} />
</Button>
</div>
{/each}
</div>
<label class="input input-bordered flex w-full items-center gap-2" bind:this={label}>
<Icon icon={Magnifier} />
<!-- svelte-ignore a11y_autofocus -->
<input
{autofocus}
class="grow"
type="text"
placeholder="Search for profiles..."
bind:value={$term}
oninput={onInput}
onkeydown={onKeyDown} />
</label>
<Tippy
bind:popover
bind:instance
component={Suggestions}
props={{
term,
search,
select: selectPubkey,
component: ProfileSuggestion,
class: "rounded-box",
style: `left: 4px; width: ${label?.clientWidth + 12}px`,
}}
params={{
trigger: "manual",
interactive: true,
placement: "bottom",
getReferenceClientRect: () => label!.getBoundingClientRect(),
onShow: (instance: Instance) => {
instance.popper.style.width = `${label!.getBoundingClientRect().width + 8}px`
},
}} />
</div>