forked from coracle/flotilla
Show active links in compose
This commit is contained in:
@@ -5,19 +5,23 @@
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
import {NostrExtension} from 'nostr-editor'
|
||||
import type {StampedEvent} from '@welshman/util'
|
||||
import {LinkExtension} from '@lib/tiptap'
|
||||
import {LinkExtension, Mention, Topic} from '@lib/tiptap'
|
||||
import GroupComposeMention from '@app/components/GroupComposeMention.svelte'
|
||||
import GroupComposeEvent from '@app/components/GroupComposeEvent.svelte'
|
||||
import GroupComposeImage from '@app/components/GroupComposeImage.svelte'
|
||||
import GroupComposeBolt11 from '@app/components/GroupComposeBolt11.svelte'
|
||||
import GroupComposeVideo from '@app/components/GroupComposeVideo.svelte'
|
||||
import GroupComposeLink from '@app/components/GroupComposeLink.svelte'
|
||||
import GroupComposeSuggestions from '@app/components/GroupComposeSuggestions.svelte'
|
||||
import GroupComposeTopicSuggestion from '@app/components/GroupComposeTopicSuggestion.svelte'
|
||||
import GroupComposeProfileSuggestion from '@app/components/GroupComposeProfileSuggestion.svelte'
|
||||
import {signer} from '@app/base'
|
||||
import {searchProfiles, searchTopics, displayProfileByPubkey} from '@app/state'
|
||||
|
||||
let editor: Readable<Editor>
|
||||
|
||||
const asInline = (extend: Record<string, any>) =>
|
||||
({inline: true, group: 'inline', draggable: false, ...extend})
|
||||
({inline: true, group: 'inline', ...extend})
|
||||
|
||||
onMount(() => {
|
||||
editor = createEditor({
|
||||
@@ -56,12 +60,57 @@
|
||||
onDrop() {
|
||||
// setPending(true)
|
||||
},
|
||||
onComplete(currentEditor: Editor) {
|
||||
onComplete(currentEditor: any) {
|
||||
console.log('Upload Completed', currentEditor.getText())
|
||||
// setPending(false)
|
||||
},
|
||||
},
|
||||
}),
|
||||
Mention.configure(
|
||||
(() => {
|
||||
let suggestions: GroupComposeSuggestions
|
||||
|
||||
const mapProps = (props: any) => ({
|
||||
term: props.query,
|
||||
select: (id: string) => props.command({id}),
|
||||
search: searchProfiles,
|
||||
component: GroupComposeProfileSuggestion,
|
||||
})
|
||||
|
||||
return {
|
||||
getLabel: displayProfileByPubkey,
|
||||
tippyOptions: {arrow: false, theme: "transparent"},
|
||||
onStart: ({target, props}) => {
|
||||
suggestions = new GroupComposeSuggestions({target, props: mapProps(props)})
|
||||
},
|
||||
onUpdate: ({props}) => suggestions.$set(mapProps(props)),
|
||||
onKeyDown: ({event}) => suggestions.onKeyDown(event),
|
||||
onExit: () => suggestions.$destroy(),
|
||||
}
|
||||
})(),
|
||||
),
|
||||
Topic.configure(
|
||||
(() => {
|
||||
let suggestions: GroupComposeSuggestions
|
||||
|
||||
const mapProps = (props: any) => ({
|
||||
term: props.query,
|
||||
select: (id: string) => props.command({id}),
|
||||
search: searchTopics,
|
||||
component: GroupComposeTopicSuggestion,
|
||||
})
|
||||
|
||||
return {
|
||||
tippyOptions: {arrow: false, theme: "transparent"},
|
||||
onStart: ({target, props}) => {
|
||||
suggestions = new GroupComposeSuggestions({target, props: mapProps(props)})
|
||||
},
|
||||
onUpdate: ({props}) => suggestions.$set(mapProps(props)),
|
||||
onKeyDown: ({event}) => suggestions.onKeyDown(event),
|
||||
onExit: () => suggestions.$destroy(),
|
||||
}
|
||||
})(),
|
||||
),
|
||||
],
|
||||
content: '',
|
||||
onUpdate: () => {
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
import cx from 'classnames'
|
||||
import type {NodeViewProps} from '@tiptap/core'
|
||||
import {NodeViewWrapper} from 'svelte-tiptap'
|
||||
import {stripProtocol} from '@welshman/lib'
|
||||
import {displayUrl} from '@welshman/lib'
|
||||
import Icon from '@lib/components/Icon.svelte'
|
||||
import Link from '@lib/components/Link.svelte'
|
||||
|
||||
export let node: NodeViewProps['node']
|
||||
export let selected: NodeViewProps['selected']
|
||||
</script>
|
||||
|
||||
<NodeViewWrapper class="inline">
|
||||
<Link external href={node.attrs.url} class="link-content">
|
||||
<Link external href={node.attrs.url} class={cx("link-content", {'link-content-selected': selected})}>
|
||||
<Icon icon="link-round" size={3} class="inline-block translate-y-px" />
|
||||
{stripProtocol(node.attrs.url)}
|
||||
{displayUrl(node.attrs.url)}
|
||||
</Link>
|
||||
</NodeViewWrapper>
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<script lang="ts">
|
||||
export let value
|
||||
</script>
|
||||
|
||||
<div>
|
||||
@{value}
|
||||
</div>
|
||||
@@ -0,0 +1,80 @@
|
||||
<svelte:options accessors />
|
||||
|
||||
<script lang="ts">
|
||||
import {throttle} from "throttle-debounce"
|
||||
import {slide} from "svelte/transition"
|
||||
import {clamp} from "@welshman/lib"
|
||||
|
||||
export let term
|
||||
export let search
|
||||
export let select
|
||||
export let component
|
||||
export let loading = false
|
||||
|
||||
let index = 0
|
||||
let element: Element
|
||||
let items: string[] = []
|
||||
|
||||
$: populateItems(term)
|
||||
|
||||
const populateItems = throttle(300, term => {
|
||||
items = $search.searchValues(term).slice(0, 30)
|
||||
})
|
||||
|
||||
const setIndex = (newIndex: number, block: ScrollLogicalPosition) => {
|
||||
index = clamp([0, items.length - 1], newIndex)
|
||||
element.querySelector(`button:nth-child(${index})`)?.scrollIntoView({block})
|
||||
}
|
||||
|
||||
export const onKeyDown = (e: any) => {
|
||||
if (e.code === "Enter") {
|
||||
const value = items[index]
|
||||
|
||||
if (value) {
|
||||
select(value)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if (e.code === "ArrowUp") {
|
||||
setIndex(index - 1, "start")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
if (e.code === "ArrowDown") {
|
||||
setIndex(index + 1, "start")
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if items.length > 0}
|
||||
<div
|
||||
bind:this={element}
|
||||
transition:slide|local={{duration: 100}}
|
||||
class="mt-2 flex max-h-[350px] flex-col overflow-y-auto overflow-x-hidden border border-solid border-neutral-600">
|
||||
{#each items as value, i (value)}
|
||||
<button
|
||||
class="cursor-pointer border-l-2 border-solid px-4 py-2 text-left text-neutral-100 hover:border-accent hover:bg-tinted-700"
|
||||
class:bg-neutral-800={index !== i}
|
||||
class:bg-tinted-700={index === i}
|
||||
class:border-transparent={index !== i}
|
||||
class:border-accent={index === i}
|
||||
on:mousedown|preventDefault
|
||||
on:click|preventDefault={() => select(value)}>
|
||||
<svelte:component this={component} {value} />
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{#if loading}
|
||||
<div transition:slide|local class="flex gap-2 bg-tinted-700 px-4 py-2 text-neutral-200">
|
||||
<div>
|
||||
<i class="fa fa-circle-notch fa-spin" />
|
||||
</div>
|
||||
Loading more options...
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -0,0 +1,7 @@
|
||||
<script lang="ts">
|
||||
export let value
|
||||
</script>
|
||||
|
||||
<div>
|
||||
#{value}
|
||||
</div>
|
||||
@@ -3,11 +3,11 @@
|
||||
import {readable} from "svelte/store"
|
||||
import {hash} from "@welshman/lib"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {GROUP_REPLY, getAncestorTags, displayProfile, displayPubkey} from "@welshman/util"
|
||||
import {GROUP_REPLY, getAncestorTags, displayPubkey} from "@welshman/util"
|
||||
import {fly} from "@lib/transition"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Avatar from "@lib/components/Avatar.svelte"
|
||||
import {deriveProfile, deriveEvent} from "@app/state"
|
||||
import {deriveProfile, deriveProfileDisplay, deriveEvent} from "@app/state"
|
||||
|
||||
export let event: TrustedEvent
|
||||
export let showPubkey: boolean
|
||||
@@ -35,6 +35,7 @@
|
||||
]
|
||||
|
||||
const profile = deriveProfile(event.pubkey)
|
||||
const profileDisplay = deriveProfileDisplay(event.pubkey)
|
||||
const {replies} = getAncestorTags(event.tags)
|
||||
const parentId = replies[0]?.[1]
|
||||
const parentHints = [replies[0]?.[2]].filter(Boolean)
|
||||
@@ -43,6 +44,7 @@
|
||||
|
||||
$: parentPubkey = $parentEvent?.pubkey || replies[0]?.[4]
|
||||
$: parentProfile = deriveProfile(parentPubkey)
|
||||
$: parentProfileDisplay = deriveProfileDisplay(parentPubkey)
|
||||
</script>
|
||||
|
||||
<div in:fly class="group relative flex flex-col gap-1 p-2 transition-colors hover:bg-base-300">
|
||||
@@ -50,7 +52,7 @@
|
||||
<div class="flex items-center gap-1 pl-12 text-xs">
|
||||
<Icon icon="arrow-right" />
|
||||
<Avatar src={$parentProfile?.picture} size={4} />
|
||||
<p class="text-primary">{displayProfile($parentProfile, displayPubkey(parentPubkey))}</p>
|
||||
<p class="text-primary">{$parentProfileDisplay}</p>
|
||||
<p></p>
|
||||
<p
|
||||
class="flex cursor-pointer items-center gap-1 overflow-hidden text-ellipsis whitespace-nowrap opacity-75 hover:underline">
|
||||
@@ -67,8 +69,7 @@
|
||||
{/if}
|
||||
<div class="-mt-1">
|
||||
{#if showPubkey}
|
||||
<strong class="text-sm" style="color: {colorValue}" data-color={colorName}
|
||||
>{displayProfile($profile, displayPubkey(event.pubkey))}</strong>
|
||||
<strong class="text-sm" style="color: {colorValue}" data-color={colorName}>{$profileDisplay}</strong>
|
||||
{/if}
|
||||
<p class="text-sm">{event.content}</p>
|
||||
</div>
|
||||
|
||||
+57
-1
@@ -1,3 +1,4 @@
|
||||
import {throttle} from 'throttle-debounce'
|
||||
import type {Readable} from "svelte/store"
|
||||
import type {FuseResult} from "fuse.js"
|
||||
import {get, writable, readable, derived} from "svelte/store"
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
indexBy,
|
||||
now,
|
||||
Worker,
|
||||
inc,
|
||||
} from "@welshman/lib"
|
||||
import {
|
||||
getIdFilters,
|
||||
@@ -32,6 +34,8 @@ import {
|
||||
readProfile,
|
||||
readList,
|
||||
asDecryptedEvent,
|
||||
displayProfile,
|
||||
displayPubkey,
|
||||
GROUP_JOIN,
|
||||
GROUP_ADD_USER,
|
||||
} from "@welshman/util"
|
||||
@@ -39,7 +43,7 @@ import type {SignedEvent, HashedEvent, EventTemplate, TrustedEvent, PublishedPro
|
||||
import type {SubscribeRequest, PublishRequest} from "@welshman/net"
|
||||
import {publish as basePublish, subscribe as baseSubscribe, PublishStatus} from "@welshman/net"
|
||||
import {decrypt, stamp, own, hash} from "@welshman/signer"
|
||||
import {deriveEvents, deriveEventsMapped, getter, withGetter} from "@welshman/store"
|
||||
import {custom, deriveEvents, deriveEventsMapped, getter, withGetter} from "@welshman/store"
|
||||
import {createSearch} from "@lib/util"
|
||||
import type {Handle, Relay} from "@app/types"
|
||||
import {INDEXER_RELAYS, DUFFLEPUD_URL, repository, pk, getSession, getSigner} from "@app/base"
|
||||
@@ -244,6 +248,43 @@ export const ensurePlaintext = async (e: TrustedEvent) => {
|
||||
return getPlaintext(e)
|
||||
}
|
||||
|
||||
// Topics
|
||||
|
||||
export type Topic = {
|
||||
name: string
|
||||
count: number
|
||||
}
|
||||
|
||||
export const topics = custom<Topic[]>(setter => {
|
||||
const getTopics = () => {
|
||||
const topics = new Map<string, number>()
|
||||
for (const tagString of repository.eventsByTag.keys()) {
|
||||
if (tagString.startsWith('t:')) {
|
||||
const topic = tagString.slice(2).toLowerCase()
|
||||
|
||||
topics.set(topic, inc(topics.get(topic)))
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(topics.entries()).map(([name, count]) => ({name, count}))
|
||||
}
|
||||
|
||||
setter(getTopics())
|
||||
|
||||
const onUpdate = throttle(3000, () => setter(getTopics()))
|
||||
|
||||
repository.on("update", onUpdate)
|
||||
|
||||
return () => repository.off("update", onUpdate)
|
||||
})
|
||||
|
||||
export const searchTopics = derived(topics, $topics =>
|
||||
createSearch($topics, {
|
||||
getValue: (topic: Topic) => topic.name,
|
||||
fuseOptions: {keys: ["name"]},
|
||||
}),
|
||||
)
|
||||
|
||||
// Relay info
|
||||
|
||||
export const relays = writable<Relay[]>([])
|
||||
@@ -331,6 +372,21 @@ export const {
|
||||
}),
|
||||
})
|
||||
|
||||
export const searchProfiles = derived(profiles, $profiles =>
|
||||
createSearch($profiles, {
|
||||
getValue: (profile: PublishedProfile) => profile.event.pubkey,
|
||||
fuseOptions: {
|
||||
keys: ["name", "display_name", {name: "about", weight: 0.3}],
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
export const displayProfileByPubkey = (pubkey: string, profile?: PublishedProfile) =>
|
||||
displayProfile(profile, pubkey ? displayPubkey(pubkey) : undefined)
|
||||
|
||||
export const deriveProfileDisplay = (pubkey: string) =>
|
||||
derived(deriveProfile(pubkey), $profile => displayProfileByPubkey(pubkey, $profile))
|
||||
|
||||
// Relay selections
|
||||
|
||||
export const getReadRelayUrls = (event?: TrustedEvent): string[] =>
|
||||
|
||||
Reference in New Issue
Block a user