@atmo-dev/kit 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/RichText.svelte +17 -9
- package/dist/components/RichTextEditor.svelte +67 -11
- package/dist/components/RichTextEditor.svelte.d.ts +0 -2
- package/dist/components/StreamplacePicker.svelte +2 -2
- package/dist/components/StreamplacePicker.svelte.d.ts +1 -1
- package/dist/components/composer/EmojiPanel.svelte +55 -0
- package/dist/components/composer/EmojiPanel.svelte.d.ts +6 -0
- package/dist/components/composer/EmojiPicker.svelte +2 -38
- package/dist/components/data/DataLabel.svelte +120 -0
- package/dist/components/data/DataLabel.svelte.d.ts +10 -0
- package/dist/components/data/issues.d.ts +5 -0
- package/dist/components/data/issues.js +52 -0
- package/dist/components/data/types.d.ts +28 -0
- package/dist/components/data/types.js +1 -0
- package/dist/components/data/visibility.d.ts +7 -0
- package/dist/components/data/visibility.js +15 -0
- package/dist/components/legal/links.js +1 -0
- package/dist/components/legal/types.d.ts +1 -1
- package/dist/components/notifications/NotificationList.svelte +137 -0
- package/dist/components/notifications/NotificationList.svelte.d.ts +19 -0
- package/dist/components/notifications/NotificationPushToggle.svelte +76 -0
- package/dist/components/notifications/NotificationPushToggle.svelte.d.ts +19 -0
- package/dist/components/notifications/NotificationSettings.svelte +125 -0
- package/dist/components/notifications/NotificationSettings.svelte.d.ts +16 -0
- package/dist/components/notifications/types.d.ts +37 -0
- package/dist/components/notifications/types.js +1 -0
- package/dist/editor/ImageDialog.svelte +87 -0
- package/dist/editor/ImageDialog.svelte.d.ts +16 -0
- package/dist/editor/image-node.d.ts +6 -2
- package/dist/editor/image-node.js +36 -37
- package/dist/events/EventCard.svelte +6 -1
- package/dist/events/VodPlayer.svelte +1 -1
- package/dist/events/atmo-rsvp.d.ts +6 -0
- package/dist/events/atmo-rsvp.js +34 -0
- package/dist/events/atproto-helpers.d.ts +1 -0
- package/dist/events/atproto-helpers.js +3 -0
- package/dist/events/event-link-embed.d.ts +7 -3
- package/dist/events/event-link-embed.js +11 -5
- package/dist/events/event-view/StreamPlacePlayer.svelte +14 -108
- package/dist/events/linked-records.d.ts +1 -1
- package/dist/events/linked-records.js +2 -2
- package/dist/events-card.d.ts +9 -0
- package/dist/events-card.js +7 -0
- package/dist/events-data.d.ts +1 -0
- package/dist/events-data.js +1 -0
- package/dist/gestures.d.ts +5 -1
- package/dist/gestures.js +6 -3
- package/dist/grain/xrpc.js +11 -4
- package/dist/index.d.ts +13 -1
- package/dist/index.js +7 -1
- package/dist/legal.d.ts +3 -0
- package/dist/legal.js +2 -0
- package/dist/richtext/serialize.js +13 -8
- package/dist/streamplace/StreamCard.svelte +184 -0
- package/dist/streamplace/StreamCard.svelte.d.ts +24 -0
- package/dist/streamplace/StreamLinkEmbed.svelte +59 -0
- package/dist/streamplace/StreamLinkEmbed.svelte.d.ts +5 -0
- package/dist/streamplace/StreamPlayer.svelte +539 -0
- package/dist/streamplace/StreamPlayer.svelte.d.ts +42 -0
- package/dist/streamplace/VideoCard.svelte +159 -0
- package/dist/streamplace/VideoCard.svelte.d.ts +17 -0
- package/dist/streamplace/api.d.ts +74 -0
- package/dist/streamplace/api.js +182 -0
- package/dist/streamplace/broadcast.d.ts +3 -0
- package/dist/streamplace/broadcast.js +110 -0
- package/dist/streamplace/channel.svelte.d.ts +74 -0
- package/dist/streamplace/channel.svelte.js +515 -0
- package/dist/streamplace/chat/Composer.svelte +232 -0
- package/dist/streamplace/chat/Composer.svelte.d.ts +15 -0
- package/dist/streamplace/chat/Embeds.svelte +135 -0
- package/dist/streamplace/chat/Embeds.svelte.d.ts +13 -0
- package/dist/streamplace/chat/Message.svelte +303 -0
- package/dist/streamplace/chat/Message.svelte.d.ts +25 -0
- package/dist/streamplace/chat/StreamChat.svelte +463 -0
- package/dist/streamplace/chat/StreamChat.svelte.d.ts +33 -0
- package/dist/streamplace/chat/StreamChatPopups.svelte +151 -0
- package/dist/streamplace/chat/StreamChatPopups.svelte.d.ts +15 -0
- package/dist/streamplace/chat/UserCard.svelte +76 -0
- package/dist/streamplace/chat/UserCard.svelte.d.ts +12 -0
- package/dist/streamplace/chat/color.d.ts +7 -0
- package/dist/streamplace/chat/color.js +33 -0
- package/dist/streamplace/chat/links.d.ts +10 -0
- package/dist/streamplace/chat/links.js +29 -0
- package/dist/streamplace/facets.d.ts +15 -0
- package/dist/streamplace/facets.js +112 -0
- package/dist/streamplace/link-embed.d.ts +13 -0
- package/dist/streamplace/link-embed.js +16 -0
- package/dist/streamplace/links.d.ts +6 -0
- package/dist/streamplace/links.js +1 -0
- package/dist/streamplace/reactions.d.ts +21 -0
- package/dist/streamplace/reactions.js +46 -0
- package/dist/streamplace/types.d.ts +200 -0
- package/dist/streamplace/types.js +1 -0
- package/dist/streamplace-data.d.ts +11 -0
- package/dist/streamplace-data.js +10 -0
- package/dist/streamplace.d.ts +14 -6
- package/dist/streamplace.js +11 -1
- package/dist/{events/event-view → video}/Player.svelte +69 -21
- package/dist/video/Player.svelte.d.ts +38 -0
- package/dist/video/engines.d.ts +59 -0
- package/dist/video/engines.js +647 -0
- package/package.json +11 -1
- package/dist/events/event-view/Player.svelte.d.ts +0 -24
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LinkEmbed } from '../../embeds/types.js';
|
|
2
|
+
import type { ComposerLinkPreview } from '../../social/composer.js';
|
|
3
|
+
import { type Reaction } from '../reactions.js';
|
|
4
|
+
import type { ChatMessage } from '../types.js';
|
|
5
|
+
export type MessageAction = 'reply' | 'pin' | 'hide' | 'ban' | 'delete' | 'user' | 'jump' | 'emoji';
|
|
6
|
+
type $$ComponentProps = {
|
|
7
|
+
message: ChatMessage;
|
|
8
|
+
viewerDid?: string;
|
|
9
|
+
streamerDid?: string;
|
|
10
|
+
highlight?: boolean;
|
|
11
|
+
/** The current time, shared so all messages age together. */
|
|
12
|
+
now?: number;
|
|
13
|
+
reactions?: Reaction[];
|
|
14
|
+
/** Show the first link of a message as an embed, image or card. */
|
|
15
|
+
previews?: boolean;
|
|
16
|
+
times?: boolean;
|
|
17
|
+
embeds?: readonly LinkEmbed[];
|
|
18
|
+
linkPreview?: ComposerLinkPreview;
|
|
19
|
+
mentionUrl?: (actor: string) => string;
|
|
20
|
+
onreact: (message: ChatMessage, emoji: string) => void;
|
|
21
|
+
onaction: (action: MessageAction, message: ChatMessage, anchor?: HTMLElement) => void;
|
|
22
|
+
};
|
|
23
|
+
declare const Message: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
24
|
+
type Message = ReturnType<typeof Message>;
|
|
25
|
+
export default Message;
|
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { LinkEmbed } from '../../embeds/types.js';
|
|
4
|
+
import type { ComposerLinkPreview } from '../../social/composer.js';
|
|
5
|
+
import type { Channel } from '../channel.svelte.js';
|
|
6
|
+
import type { ChatMessage, Viewer } from '../types.js';
|
|
7
|
+
|
|
8
|
+
export type StreamChatProps = {
|
|
9
|
+
/** Connected by the app; the chat only reads it and calls its actions. */
|
|
10
|
+
channel: Channel;
|
|
11
|
+
/** The signed-in account. Without it the chat is read-only and offers `onsignin`. */
|
|
12
|
+
viewer?: Viewer | null;
|
|
13
|
+
/** Asked for when a signed-out visitor wants to write or react. */
|
|
14
|
+
onsignin?: () => void;
|
|
15
|
+
/** Show links as embeds, images and cards. Remembered by the app. */
|
|
16
|
+
previews?: boolean;
|
|
17
|
+
/** Show each message's age. Remembered by the app. */
|
|
18
|
+
times?: boolean;
|
|
19
|
+
/** Which links become embeds: the app's link embeds by default, or a list. */
|
|
20
|
+
embeds?: readonly LinkEmbed[];
|
|
21
|
+
/** Looks up title and image for ordinary links, e.g. `blueskyLinkPreview`. */
|
|
22
|
+
linkPreview?: ComposerLinkPreview;
|
|
23
|
+
/** Where a chatter's name and mentions lead; stream.place by default. */
|
|
24
|
+
channelUrl?: (actor: string) => string;
|
|
25
|
+
/** Adds an "open in a new window" button for the chat on its own. */
|
|
26
|
+
popoutHref?: string;
|
|
27
|
+
/** A message to scroll to and mark, e.g. one picked from a popup. Cleared once shown. */
|
|
28
|
+
focus?: string;
|
|
29
|
+
/** More rows for the settings menu. */
|
|
30
|
+
settings?: Snippet;
|
|
31
|
+
class?: string;
|
|
32
|
+
};
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<script lang="ts">
|
|
36
|
+
import { tick } from 'svelte';
|
|
37
|
+
import { ArrowDown, ExternalLink, Pin, Settings, X } from '@sketchyicons/svelte';
|
|
38
|
+
import Button from '../../components/Button.svelte';
|
|
39
|
+
import Checkbox from '../../components/Checkbox.svelte';
|
|
40
|
+
import Icon from '../../components/Icon.svelte';
|
|
41
|
+
import Label from '../../components/Label.svelte';
|
|
42
|
+
import Modal from '../../components/Modal.svelte';
|
|
43
|
+
import Popover from '../../components/Popover.svelte';
|
|
44
|
+
import EmojiPanel from '../../components/composer/EmojiPanel.svelte';
|
|
45
|
+
import { linkEmbedOptions, selectLinkEmbeds } from '../../embeds/context.js';
|
|
46
|
+
import { cn } from '../../utils.js';
|
|
47
|
+
import { handleOf } from '../api.js';
|
|
48
|
+
import { shortHandle } from './color.js';
|
|
49
|
+
import Composer from './Composer.svelte';
|
|
50
|
+
import Message, { type MessageAction } from './Message.svelte';
|
|
51
|
+
import UserCard from './UserCard.svelte';
|
|
52
|
+
|
|
53
|
+
let {
|
|
54
|
+
channel,
|
|
55
|
+
viewer,
|
|
56
|
+
onsignin,
|
|
57
|
+
previews = $bindable(true),
|
|
58
|
+
times = $bindable(true),
|
|
59
|
+
embeds,
|
|
60
|
+
linkPreview,
|
|
61
|
+
channelUrl = (actor) => `https://stream.place/${encodeURIComponent(actor)}`,
|
|
62
|
+
popoutHref,
|
|
63
|
+
focus = $bindable(),
|
|
64
|
+
settings,
|
|
65
|
+
class: className
|
|
66
|
+
}: StreamChatProps = $props();
|
|
67
|
+
|
|
68
|
+
const embedOptions = linkEmbedOptions();
|
|
69
|
+
const embedList = $derived(embeds ?? selectLinkEmbeds(true, embedOptions()));
|
|
70
|
+
const streamerDid = $derived(channel.profile?.did ?? channel.livestream?.author.did);
|
|
71
|
+
const canModerate = $derived(!!viewer && viewer.did === streamerDid);
|
|
72
|
+
|
|
73
|
+
let list = $state<HTMLDivElement>();
|
|
74
|
+
let content = $state<HTMLDivElement>();
|
|
75
|
+
let input = $state<HTMLTextAreaElement>();
|
|
76
|
+
let composer = $state<Composer>();
|
|
77
|
+
let draft = $state('');
|
|
78
|
+
let atBottom = $state(true);
|
|
79
|
+
let unread = $state(0);
|
|
80
|
+
/** Messages already on screen while following the chat, so deletions do not skew `unread`. */
|
|
81
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- bookkeeping; `unread` drives UI
|
|
82
|
+
let seen = new Set<string>();
|
|
83
|
+
let replyTo = $state.raw<ChatMessage | null>(null);
|
|
84
|
+
let notice = $state('');
|
|
85
|
+
let settingsOpen = $state(false);
|
|
86
|
+
let card = $state.raw<{ message: ChatMessage; anchor: HTMLElement } | null>(null);
|
|
87
|
+
let cardOpen = $state(false);
|
|
88
|
+
// One emoji picker for the whole chat, opened next to the message being reacted to.
|
|
89
|
+
let reacting = $state.raw<{ message: ChatMessage; anchor: HTMLElement } | null>(null);
|
|
90
|
+
let reactingOpen = $state(false);
|
|
91
|
+
let pinDismissed = $state<string>();
|
|
92
|
+
let banning = $state.raw<ChatMessage | null>(null);
|
|
93
|
+
let banOpen = $state(false);
|
|
94
|
+
|
|
95
|
+
// One clock for every message's "2m".
|
|
96
|
+
let now = $state(Date.now());
|
|
97
|
+
$effect(() => {
|
|
98
|
+
const timer = setInterval(() => (now = Date.now()), 5000);
|
|
99
|
+
return () => clearInterval(timer);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
let pinnedHeight = 0;
|
|
103
|
+
function toBottom() {
|
|
104
|
+
if (!list) return;
|
|
105
|
+
pinnedHeight = list.scrollHeight;
|
|
106
|
+
list.scrollTo({ top: pinnedHeight });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Follow new messages while at the bottom; count them while reading history.
|
|
110
|
+
$effect(() => {
|
|
111
|
+
const messages = channel.messages;
|
|
112
|
+
if (atBottom) {
|
|
113
|
+
seen.clear();
|
|
114
|
+
for (const message of messages) seen.add(message.uri);
|
|
115
|
+
unread = 0;
|
|
116
|
+
void tick().then(toBottom);
|
|
117
|
+
} else {
|
|
118
|
+
let count = 0;
|
|
119
|
+
for (const message of messages) if (!seen.has(message.uri)) count += 1;
|
|
120
|
+
unread = count;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Previews and images change height after they load.
|
|
125
|
+
$effect(() => {
|
|
126
|
+
if (!content) return;
|
|
127
|
+
const observer = new ResizeObserver(() => atBottom && toBottom());
|
|
128
|
+
observer.observe(content);
|
|
129
|
+
return () => observer.disconnect();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
function onscroll() {
|
|
133
|
+
if (!list || jumping) return;
|
|
134
|
+
// Scroll events arrive a frame late. If the content grew in the meantime (a preview
|
|
135
|
+
// loaded), the distance is not the reader scrolling away: stay at the bottom.
|
|
136
|
+
if (atBottom && list.scrollHeight > pinnedHeight) return toBottom();
|
|
137
|
+
atBottom = list.scrollHeight - list.scrollTop - list.clientHeight < 48;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function act(action: MessageAction, message: ChatMessage, anchor?: HTMLElement) {
|
|
141
|
+
notice = '';
|
|
142
|
+
try {
|
|
143
|
+
if (action === 'emoji' && anchor) {
|
|
144
|
+
reacting = { message, anchor };
|
|
145
|
+
reactingOpen = true;
|
|
146
|
+
} else if (action === 'jump') {
|
|
147
|
+
if (message.replyTo) jumpTo(message.replyTo.uri);
|
|
148
|
+
} else if (action === 'user' && anchor) {
|
|
149
|
+
card = { message, anchor };
|
|
150
|
+
cardOpen = true;
|
|
151
|
+
} else if (action === 'reply') {
|
|
152
|
+
replyTo = message;
|
|
153
|
+
input?.focus();
|
|
154
|
+
} else if (action === 'delete') await channel.remove(message.uri);
|
|
155
|
+
else if (action === 'hide') await channel.hide(message.uri);
|
|
156
|
+
else if (action === 'pin') await channel.pin(message.uri);
|
|
157
|
+
else if (action === 'ban') {
|
|
158
|
+
// A ban blocks the account everywhere, so it is confirmed first.
|
|
159
|
+
cardOpen = false;
|
|
160
|
+
banning = message;
|
|
161
|
+
banOpen = true;
|
|
162
|
+
}
|
|
163
|
+
} catch (cause) {
|
|
164
|
+
notice = cause instanceof Error ? cause.message : 'That did not work';
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function react(message: ChatMessage, emoji: string) {
|
|
169
|
+
if (!viewer) return onsignin?.();
|
|
170
|
+
notice = '';
|
|
171
|
+
try {
|
|
172
|
+
await channel.react(message, emoji, viewer);
|
|
173
|
+
} catch (cause) {
|
|
174
|
+
notice = cause instanceof Error ? cause.message : 'Could not react';
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function ban(message: ChatMessage) {
|
|
179
|
+
banOpen = false;
|
|
180
|
+
notice = '';
|
|
181
|
+
try {
|
|
182
|
+
await channel.ban(message.author.did);
|
|
183
|
+
} catch (cause) {
|
|
184
|
+
notice = cause instanceof Error ? cause.message : 'Could not ban';
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function unpin() {
|
|
189
|
+
try {
|
|
190
|
+
await channel.unpin();
|
|
191
|
+
} catch (cause) {
|
|
192
|
+
notice = cause instanceof Error ? cause.message : 'Could not unpin';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function mention(message: ChatMessage) {
|
|
197
|
+
cardOpen = false;
|
|
198
|
+
if (!viewer) return;
|
|
199
|
+
void composer?.insert(`@${handleOf(message.author)} `);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Jumping to the message a reply answers marks it for a moment.
|
|
203
|
+
let flash = $state<string>();
|
|
204
|
+
let flashTimer: ReturnType<typeof setTimeout> | undefined;
|
|
205
|
+
let jumping = false;
|
|
206
|
+
let jumpTimer: ReturnType<typeof setTimeout> | undefined;
|
|
207
|
+
$effect(() => () => {
|
|
208
|
+
clearTimeout(jumpTimer);
|
|
209
|
+
clearTimeout(flashTimer);
|
|
210
|
+
});
|
|
211
|
+
function jumpTo(uri: string) {
|
|
212
|
+
const target = [...(content?.children ?? [])].find(
|
|
213
|
+
(element) => (element as HTMLElement).dataset.uri === uri
|
|
214
|
+
);
|
|
215
|
+
if (!target) return void (notice = 'That message is no longer in this chat');
|
|
216
|
+
// Reading history: stop following new messages. The first frames of the animated
|
|
217
|
+
// scroll are still near the bottom and must not be read as "back at the bottom".
|
|
218
|
+
atBottom = false;
|
|
219
|
+
jumping = true;
|
|
220
|
+
clearTimeout(jumpTimer);
|
|
221
|
+
jumpTimer = setTimeout(() => (jumping = false), 700);
|
|
222
|
+
target.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
223
|
+
flash = uri;
|
|
224
|
+
clearTimeout(flashTimer);
|
|
225
|
+
flashTimer = setTimeout(() => (flash = undefined), 2500);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
$effect(() => {
|
|
229
|
+
const uri = focus;
|
|
230
|
+
if (!uri || !content) return;
|
|
231
|
+
// After the first scroll to the bottom, and once the panel has opened.
|
|
232
|
+
const timer = setTimeout(() => {
|
|
233
|
+
focus = undefined;
|
|
234
|
+
jumpTo(uri);
|
|
235
|
+
}, 320);
|
|
236
|
+
return () => clearTimeout(timer);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// A message that was hidden or deleted is no longer something to reply to.
|
|
240
|
+
$effect(() => {
|
|
241
|
+
const target = replyTo;
|
|
242
|
+
if (target && !channel.messages.some((message) => message.uri === target.uri)) replyTo = null;
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Handles typed into the message box mark everything those people wrote.
|
|
246
|
+
const marked = $derived.by(() => {
|
|
247
|
+
const typed = new Set(
|
|
248
|
+
[...draft.matchAll(/(?:^|\s)@([a-z0-9.-]+)/gi)].map((match) => match[1].toLowerCase())
|
|
249
|
+
);
|
|
250
|
+
// A new set per evaluation; nothing mutates it after it is returned.
|
|
251
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
252
|
+
const dids = new Set<string>();
|
|
253
|
+
if (!typed.size) return dids;
|
|
254
|
+
for (const [did, author] of channel.authors) {
|
|
255
|
+
const handle = author.handle.toLowerCase();
|
|
256
|
+
if (typed.has(handle) || typed.has(shortHandle(handle))) dids.add(did);
|
|
257
|
+
}
|
|
258
|
+
return dids;
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const pinned = $derived(
|
|
262
|
+
channel.pinned?.message && channel.pinned.uri !== pinDismissed ? channel.pinned : null
|
|
263
|
+
);
|
|
264
|
+
</script>
|
|
265
|
+
|
|
266
|
+
<section
|
|
267
|
+
class={cn(
|
|
268
|
+
'flex h-full min-h-0 flex-col bg-base-50 text-base-950 dark:bg-base-925 dark:text-base-50',
|
|
269
|
+
className
|
|
270
|
+
)}
|
|
271
|
+
aria-label="Chat"
|
|
272
|
+
>
|
|
273
|
+
<header
|
|
274
|
+
class="flex h-11 shrink-0 items-center gap-1 border-b border-base-300 pr-1.5 pl-3.5 dark:border-base-800"
|
|
275
|
+
>
|
|
276
|
+
<h2 class="flex-1 text-[13px] font-semibold">Chat</h2>
|
|
277
|
+
{#if !channel.connected}
|
|
278
|
+
<span class="mr-1 text-xs text-base-600 dark:text-base-400" role="status">Connecting…</span>
|
|
279
|
+
{/if}
|
|
280
|
+
{#if popoutHref}
|
|
281
|
+
<a
|
|
282
|
+
href={popoutHref}
|
|
283
|
+
target="_blank"
|
|
284
|
+
rel="noopener"
|
|
285
|
+
class="grid size-8 place-items-center rounded-lg text-base-600 hover:bg-base-200/60 hover:text-base-950 max-sm:hidden dark:text-base-400 dark:hover:bg-base-800/50 dark:hover:text-base-50"
|
|
286
|
+
aria-label="Open chat in a new window"
|
|
287
|
+
title="Open chat in a new window"
|
|
288
|
+
onclick={(event) => {
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
window.open(event.currentTarget.href, '_blank', 'popup,noopener,width=380,height=720');
|
|
291
|
+
}}
|
|
292
|
+
>
|
|
293
|
+
<Icon img={ExternalLink} size={16} />
|
|
294
|
+
</a>
|
|
295
|
+
{/if}
|
|
296
|
+
<Popover bind:open={settingsOpen} side="bottom" align="end" aria-label="Chat settings">
|
|
297
|
+
{#snippet trigger({ props })}
|
|
298
|
+
<button
|
|
299
|
+
{...props}
|
|
300
|
+
type="button"
|
|
301
|
+
class="grid size-8 place-items-center rounded-lg text-base-600 hover:bg-base-200/60 hover:text-base-950 dark:text-base-400 dark:hover:bg-base-800/50 dark:hover:text-base-50"
|
|
302
|
+
aria-label="Chat settings"
|
|
303
|
+
title="Chat settings"
|
|
304
|
+
>
|
|
305
|
+
<Icon img={Settings} size={16} />
|
|
306
|
+
</button>
|
|
307
|
+
{/snippet}
|
|
308
|
+
<div class="grid gap-3 text-[13px]">
|
|
309
|
+
<Label class="flex items-center gap-2 font-normal">
|
|
310
|
+
<Checkbox bind:checked={previews} />Link previews
|
|
311
|
+
</Label>
|
|
312
|
+
<Label class="flex items-center gap-2 font-normal">
|
|
313
|
+
<Checkbox bind:checked={times} />Message times
|
|
314
|
+
</Label>
|
|
315
|
+
{@render settings?.()}
|
|
316
|
+
</div>
|
|
317
|
+
</Popover>
|
|
318
|
+
</header>
|
|
319
|
+
|
|
320
|
+
{#if pinned?.message}
|
|
321
|
+
<div
|
|
322
|
+
class="flex items-start gap-2 border-b border-base-300 bg-base-100 px-3.5 py-2 text-[13px] dark:border-base-800 dark:bg-base-950"
|
|
323
|
+
>
|
|
324
|
+
<Icon img={Pin} size={14} class="mt-0.5 shrink-0 text-accent-700 dark:text-accent-300" />
|
|
325
|
+
<p class="min-w-0 flex-1 wrap-anywhere">
|
|
326
|
+
<span class="font-semibold">{shortHandle(handleOf(pinned.message.author))}</span>
|
|
327
|
+
{pinned.message.record.text}
|
|
328
|
+
</p>
|
|
329
|
+
<button
|
|
330
|
+
type="button"
|
|
331
|
+
class="shrink-0 text-base-600 hover:text-base-950 dark:text-base-400 dark:hover:text-base-50"
|
|
332
|
+
aria-label={canModerate ? 'Unpin' : 'Hide pinned message'}
|
|
333
|
+
title={canModerate ? 'Unpin' : 'Hide'}
|
|
334
|
+
onclick={() => (canModerate ? unpin() : (pinDismissed = pinned.uri))}
|
|
335
|
+
>
|
|
336
|
+
<Icon img={X} size={14} />
|
|
337
|
+
</button>
|
|
338
|
+
</div>
|
|
339
|
+
{/if}
|
|
340
|
+
|
|
341
|
+
<div class="relative min-h-0 flex-1">
|
|
342
|
+
<!-- A scrolling region has to be reachable by keyboard to be scrolled with it. -->
|
|
343
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
344
|
+
<div
|
|
345
|
+
bind:this={list}
|
|
346
|
+
{onscroll}
|
|
347
|
+
class="h-full overflow-y-auto overscroll-contain px-1.5 pt-5 pb-2"
|
|
348
|
+
role="log"
|
|
349
|
+
tabindex="0"
|
|
350
|
+
aria-label="Chat messages"
|
|
351
|
+
aria-live="off"
|
|
352
|
+
>
|
|
353
|
+
<div bind:this={content}>
|
|
354
|
+
{#each channel.messages as message (message.uri)}
|
|
355
|
+
<Message
|
|
356
|
+
{message}
|
|
357
|
+
viewerDid={viewer?.did}
|
|
358
|
+
{previews}
|
|
359
|
+
{times}
|
|
360
|
+
embeds={embedList}
|
|
361
|
+
{linkPreview}
|
|
362
|
+
mentionUrl={channelUrl}
|
|
363
|
+
{streamerDid}
|
|
364
|
+
{now}
|
|
365
|
+
reactions={channel.reactions.get(message.uri)}
|
|
366
|
+
onreact={react}
|
|
367
|
+
highlight={message.uri === flash || marked.has(message.author.did)}
|
|
368
|
+
onaction={act}
|
|
369
|
+
/>
|
|
370
|
+
{:else}
|
|
371
|
+
{#if channel.connected}
|
|
372
|
+
<p class="px-2 py-6 text-center text-[13px] text-base-600 dark:text-base-400">
|
|
373
|
+
No messages yet
|
|
374
|
+
</p>
|
|
375
|
+
{/if}
|
|
376
|
+
{/each}
|
|
377
|
+
</div>
|
|
378
|
+
</div>
|
|
379
|
+
{#if !atBottom}
|
|
380
|
+
<button
|
|
381
|
+
type="button"
|
|
382
|
+
class="absolute bottom-2 left-1/2 flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-base-300 bg-base-50 px-3 py-1.5 text-xs font-medium shadow-md hover:bg-base-200/60 dark:border-base-800 dark:bg-base-925 dark:hover:bg-base-800/50"
|
|
383
|
+
onclick={() => {
|
|
384
|
+
atBottom = true;
|
|
385
|
+
toBottom();
|
|
386
|
+
}}
|
|
387
|
+
>
|
|
388
|
+
<Icon img={ArrowDown} size={13} />
|
|
389
|
+
{unread ? `${unread} new ${unread === 1 ? 'message' : 'messages'}` : 'Latest messages'}
|
|
390
|
+
</button>
|
|
391
|
+
{/if}
|
|
392
|
+
</div>
|
|
393
|
+
|
|
394
|
+
{#if notice}
|
|
395
|
+
<p
|
|
396
|
+
class="border-t border-base-300 px-3.5 py-1.5 text-xs text-accent-700 dark:border-base-800 dark:text-accent-300"
|
|
397
|
+
role="alert"
|
|
398
|
+
>
|
|
399
|
+
{notice}
|
|
400
|
+
</p>
|
|
401
|
+
{/if}
|
|
402
|
+
<Composer
|
|
403
|
+
bind:this={composer}
|
|
404
|
+
{channel}
|
|
405
|
+
{viewer}
|
|
406
|
+
{onsignin}
|
|
407
|
+
bind:text={draft}
|
|
408
|
+
bind:replyTo
|
|
409
|
+
bind:input
|
|
410
|
+
/>
|
|
411
|
+
</section>
|
|
412
|
+
|
|
413
|
+
<Popover
|
|
414
|
+
bind:open={cardOpen}
|
|
415
|
+
customAnchor={card?.anchor}
|
|
416
|
+
side="left"
|
|
417
|
+
align="start"
|
|
418
|
+
aria-label="Chatter"
|
|
419
|
+
>
|
|
420
|
+
{#snippet trigger({ props })}<span {...props} hidden></span>{/snippet}
|
|
421
|
+
{#if card}
|
|
422
|
+
{@const message = card.message}
|
|
423
|
+
<UserCard
|
|
424
|
+
{message}
|
|
425
|
+
canModerate={canModerate && message.author.did !== viewer?.did}
|
|
426
|
+
channelHref={channelUrl(handleOf(message.author))}
|
|
427
|
+
onmention={viewer ? () => mention(message) : undefined}
|
|
428
|
+
onban={() => act('ban', message)}
|
|
429
|
+
/>
|
|
430
|
+
{/if}
|
|
431
|
+
</Popover>
|
|
432
|
+
|
|
433
|
+
<Popover
|
|
434
|
+
bind:open={reactingOpen}
|
|
435
|
+
customAnchor={reacting?.anchor}
|
|
436
|
+
side="left"
|
|
437
|
+
align="start"
|
|
438
|
+
class="p-0"
|
|
439
|
+
aria-label="React with an emoji"
|
|
440
|
+
>
|
|
441
|
+
{#snippet trigger({ props })}<span {...props} hidden></span>{/snippet}
|
|
442
|
+
{#if reacting}
|
|
443
|
+
{@const message = reacting.message}
|
|
444
|
+
<EmojiPanel
|
|
445
|
+
onselect={(emoji) => {
|
|
446
|
+
reactingOpen = false;
|
|
447
|
+
void react(message, emoji);
|
|
448
|
+
}}
|
|
449
|
+
/>
|
|
450
|
+
{/if}
|
|
451
|
+
</Popover>
|
|
452
|
+
|
|
453
|
+
<Modal
|
|
454
|
+
bind:open={banOpen}
|
|
455
|
+
title={banning ? `Ban @${handleOf(banning.author)}?` : 'Ban'}
|
|
456
|
+
description="This blocks the account everywhere, not only in your chat."
|
|
457
|
+
class="max-w-sm"
|
|
458
|
+
>
|
|
459
|
+
<div class="flex justify-end gap-2">
|
|
460
|
+
<Button variant="secondary" onclick={() => (banOpen = false)}>Cancel</Button>
|
|
461
|
+
<Button onclick={() => banning && ban(banning)}>Ban</Button>
|
|
462
|
+
</div>
|
|
463
|
+
</Modal>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { LinkEmbed } from '../../embeds/types.js';
|
|
3
|
+
import type { ComposerLinkPreview } from '../../social/composer.js';
|
|
4
|
+
import type { Channel } from '../channel.svelte.js';
|
|
5
|
+
import type { Viewer } from '../types.js';
|
|
6
|
+
export type StreamChatProps = {
|
|
7
|
+
/** Connected by the app; the chat only reads it and calls its actions. */
|
|
8
|
+
channel: Channel;
|
|
9
|
+
/** The signed-in account. Without it the chat is read-only and offers `onsignin`. */
|
|
10
|
+
viewer?: Viewer | null;
|
|
11
|
+
/** Asked for when a signed-out visitor wants to write or react. */
|
|
12
|
+
onsignin?: () => void;
|
|
13
|
+
/** Show links as embeds, images and cards. Remembered by the app. */
|
|
14
|
+
previews?: boolean;
|
|
15
|
+
/** Show each message's age. Remembered by the app. */
|
|
16
|
+
times?: boolean;
|
|
17
|
+
/** Which links become embeds: the app's link embeds by default, or a list. */
|
|
18
|
+
embeds?: readonly LinkEmbed[];
|
|
19
|
+
/** Looks up title and image for ordinary links, e.g. `blueskyLinkPreview`. */
|
|
20
|
+
linkPreview?: ComposerLinkPreview;
|
|
21
|
+
/** Where a chatter's name and mentions lead; stream.place by default. */
|
|
22
|
+
channelUrl?: (actor: string) => string;
|
|
23
|
+
/** Adds an "open in a new window" button for the chat on its own. */
|
|
24
|
+
popoutHref?: string;
|
|
25
|
+
/** A message to scroll to and mark, e.g. one picked from a popup. Cleared once shown. */
|
|
26
|
+
focus?: string;
|
|
27
|
+
/** More rows for the settings menu. */
|
|
28
|
+
settings?: Snippet;
|
|
29
|
+
class?: string;
|
|
30
|
+
};
|
|
31
|
+
declare const StreamChat: import("svelte").Component<StreamChatProps, {}, "focus" | "previews" | "times">;
|
|
32
|
+
type StreamChat = ReturnType<typeof StreamChat>;
|
|
33
|
+
export default StreamChat;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import { fade, fly } from 'svelte/transition';
|
|
4
|
+
import { handleOf } from '../api.js';
|
|
5
|
+
import type { Channel } from '../channel.svelte.js';
|
|
6
|
+
import type { ChatMessage } from '../types.js';
|
|
7
|
+
import { cn } from '../../utils.js';
|
|
8
|
+
import { nameColor, shortHandle } from './color.js';
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
channel,
|
|
12
|
+
active,
|
|
13
|
+
viewerDid,
|
|
14
|
+
class: className,
|
|
15
|
+
onopen
|
|
16
|
+
}: {
|
|
17
|
+
channel: Channel;
|
|
18
|
+
/** Whether new messages should pop up: the chat is hidden and popups are wanted. */
|
|
19
|
+
active: boolean;
|
|
20
|
+
/** Their own messages do not pop up. */
|
|
21
|
+
viewerDid?: string;
|
|
22
|
+
/** Position; the bottom right corner of the window by default. */
|
|
23
|
+
class?: string;
|
|
24
|
+
onopen: (message: ChatMessage) => void;
|
|
25
|
+
} = $props();
|
|
26
|
+
|
|
27
|
+
const SHOWN_FOR = 7000;
|
|
28
|
+
let popups = $state.raw<ChatMessage[]>([]);
|
|
29
|
+
let hovering = false;
|
|
30
|
+
// Bookkeeping that must not re-render anything; `popups` is what the list reads.
|
|
31
|
+
/* eslint-disable svelte/prefer-svelte-reactivity */
|
|
32
|
+
const known = new Set<string>();
|
|
33
|
+
const timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
34
|
+
/* eslint-enable svelte/prefer-svelte-reactivity */
|
|
35
|
+
|
|
36
|
+
const reducedMotion = () =>
|
|
37
|
+
typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
38
|
+
|
|
39
|
+
function clearTimers() {
|
|
40
|
+
for (const pending of timers.values()) clearTimeout(pending);
|
|
41
|
+
timers.clear();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// The history that arrives on connecting (or when switching channels) is not news.
|
|
45
|
+
// Derived so unrelated prop updates (e.g. toggling `active`) never reset `ready`.
|
|
46
|
+
const currentChannel = $derived(channel);
|
|
47
|
+
let ready = $state(false);
|
|
48
|
+
$effect(() => {
|
|
49
|
+
void currentChannel;
|
|
50
|
+
ready = false;
|
|
51
|
+
hovering = false;
|
|
52
|
+
known.clear();
|
|
53
|
+
clearTimers();
|
|
54
|
+
popups = [];
|
|
55
|
+
const timer = setTimeout(() => (ready = true), 3000);
|
|
56
|
+
return () => {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
clearTimers();
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function expire(uri: string) {
|
|
63
|
+
// A message being read stays until the pointer leaves.
|
|
64
|
+
if (hovering)
|
|
65
|
+
return void timers.set(
|
|
66
|
+
uri,
|
|
67
|
+
setTimeout(() => expire(uri), 1500)
|
|
68
|
+
);
|
|
69
|
+
timers.delete(uri);
|
|
70
|
+
const next = popups.filter((message) => message.uri !== uri);
|
|
71
|
+
popups = next;
|
|
72
|
+
if (!next.length) hovering = false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
$effect(() => {
|
|
76
|
+
const fresh: ChatMessage[] = [];
|
|
77
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- rebuilt on every run
|
|
78
|
+
const present = new Set<string>();
|
|
79
|
+
for (const message of channel.messages) {
|
|
80
|
+
present.add(message.uri);
|
|
81
|
+
if (known.has(message.uri)) continue;
|
|
82
|
+
known.add(message.uri);
|
|
83
|
+
if (ready && active && !message.pending && message.author.did !== viewerDid) {
|
|
84
|
+
fresh.push(message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!active) {
|
|
88
|
+
hovering = false;
|
|
89
|
+
clearTimers();
|
|
90
|
+
popups = [];
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const current = untrack(() => popups);
|
|
94
|
+
let next = fresh.length ? [...current, ...fresh].slice(-3) : current;
|
|
95
|
+
// A message hidden or deleted while its popup is up goes with it.
|
|
96
|
+
next = next.filter((message) => present.has(message.uri));
|
|
97
|
+
const kept = new Set(next.map((message) => message.uri));
|
|
98
|
+
for (const [uri, pending] of timers) {
|
|
99
|
+
if (!kept.has(uri)) {
|
|
100
|
+
clearTimeout(pending);
|
|
101
|
+
timers.delete(uri);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for (const message of next) {
|
|
105
|
+
if (!timers.has(message.uri)) {
|
|
106
|
+
timers.set(
|
|
107
|
+
message.uri,
|
|
108
|
+
setTimeout(() => expire(message.uri), SHOWN_FOR)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (next !== current && (next.length !== current.length || fresh.length)) {
|
|
113
|
+
popups = next;
|
|
114
|
+
if (!next.length) hovering = false;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
{#if popups.length}
|
|
120
|
+
{@const reduced = reducedMotion()}
|
|
121
|
+
<ul
|
|
122
|
+
class={cn(
|
|
123
|
+
'fixed right-3 bottom-16 z-30 flex w-80 max-w-[calc(100vw-1.5rem)] flex-col gap-1.5 max-sm:bottom-20',
|
|
124
|
+
className
|
|
125
|
+
)}
|
|
126
|
+
aria-label="New chat messages"
|
|
127
|
+
onpointerenter={() => (hovering = true)}
|
|
128
|
+
onpointerleave={() => (hovering = false)}
|
|
129
|
+
>
|
|
130
|
+
{#each popups as message (message.uri)}
|
|
131
|
+
<li
|
|
132
|
+
in:fly={{ y: reduced ? 0 : 12, duration: reduced ? 0 : 180 }}
|
|
133
|
+
out:fade={{ duration: reduced ? 0 : 400 }}
|
|
134
|
+
>
|
|
135
|
+
<button
|
|
136
|
+
type="button"
|
|
137
|
+
class="block w-full rounded-xl border border-white/30 bg-black/75 px-3 py-2 text-left text-[13px] leading-snug text-white shadow-lg backdrop-blur-sm hover:bg-black/90"
|
|
138
|
+
onclick={() => onopen(message)}
|
|
139
|
+
>
|
|
140
|
+
<span class="line-clamp-2 wrap-anywhere">
|
|
141
|
+
<span
|
|
142
|
+
class="font-semibold"
|
|
143
|
+
style:color={nameColor(message.author.did, message.chatProfile?.color, 'dark')}
|
|
144
|
+
>{shortHandle(handleOf(message.author))}</span
|
|
145
|
+
>{message.system ? ' ' : ': '}{message.record.text}
|
|
146
|
+
</span>
|
|
147
|
+
</button>
|
|
148
|
+
</li>
|
|
149
|
+
{/each}
|
|
150
|
+
</ul>
|
|
151
|
+
{/if}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Channel } from '../channel.svelte.js';
|
|
2
|
+
import type { ChatMessage } from '../types.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
channel: Channel;
|
|
5
|
+
/** Whether new messages should pop up: the chat is hidden and popups are wanted. */
|
|
6
|
+
active: boolean;
|
|
7
|
+
/** Their own messages do not pop up. */
|
|
8
|
+
viewerDid?: string;
|
|
9
|
+
/** Position; the bottom right corner of the window by default. */
|
|
10
|
+
class?: string;
|
|
11
|
+
onopen: (message: ChatMessage) => void;
|
|
12
|
+
};
|
|
13
|
+
declare const StreamChatPopups: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
14
|
+
type StreamChatPopups = ReturnType<typeof StreamChatPopups>;
|
|
15
|
+
export default StreamChatPopups;
|