@atmo-dev/kit 0.12.0 → 0.13.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.
Files changed (39) hide show
  1. package/dist/components/RichText.svelte +17 -1
  2. package/dist/components/RichText.svelte.d.ts +8 -0
  3. package/dist/components/SembleCollectionPicker.svelte +221 -0
  4. package/dist/components/SembleCollectionPicker.svelte.d.ts +14 -0
  5. package/dist/components/SembleCollectionView.svelte +153 -0
  6. package/dist/components/SembleCollectionView.svelte.d.ts +10 -0
  7. package/dist/events/EventComments.svelte +15 -2
  8. package/dist/events/EventView.svelte +74 -7
  9. package/dist/events/editor/LinkedRecordsPicker.svelte +44 -3
  10. package/dist/events/editor/LinksSection.svelte +29 -9
  11. package/dist/events/event-view/EventLinkEmbed.svelte +49 -0
  12. package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +14 -0
  13. package/dist/events/event-view/PostLinkEmbed.svelte +71 -0
  14. package/dist/events/event-view/PostLinkEmbed.svelte.d.ts +11 -0
  15. package/dist/events/event-view/ProfileLinkEmbed.svelte +67 -0
  16. package/dist/events/event-view/ProfileLinkEmbed.svelte.d.ts +11 -0
  17. package/dist/events/linked-records.d.ts +20 -0
  18. package/dist/events/linked-records.js +32 -2
  19. package/dist/index.d.ts +7 -1
  20. package/dist/index.js +5 -1
  21. package/dist/richtext/document.d.ts +9 -0
  22. package/dist/richtext/document.js +35 -0
  23. package/dist/richtext.d.ts +1 -1
  24. package/dist/richtext.js +1 -1
  25. package/dist/semble/types.d.ts +46 -0
  26. package/dist/semble/types.js +1 -0
  27. package/dist/semble/urls.d.ts +2 -0
  28. package/dist/semble/urls.js +43 -0
  29. package/dist/semble/xrpc.d.ts +3 -0
  30. package/dist/semble/xrpc.js +131 -0
  31. package/dist/semble.d.ts +3 -0
  32. package/dist/semble.js +2 -0
  33. package/dist/social/posts.d.ts +7 -0
  34. package/dist/social/posts.js +21 -0
  35. package/dist/social/urls.d.ts +10 -0
  36. package/dist/social/urls.js +43 -1
  37. package/dist/social.d.ts +3 -1
  38. package/dist/social.js +2 -1
  39. package/package.json +5 -1
@@ -1,7 +1,9 @@
1
1
  <script lang="ts">
2
+ import type { Snippet } from 'svelte';
2
3
  import {
3
4
  inlineHref,
4
5
  inlineText,
6
+ paragraphParts,
5
7
  MAX_RENDER_DEPTH,
6
8
  type RichTextDocument,
7
9
  type RichTextLinkOptions
@@ -20,6 +22,13 @@
20
22
  detectLinks?: boolean;
21
23
  /** Added to Markdown heading levels, e.g. 1 renders `#` as h2 below a page's h1. */
22
24
  headingOffset?: number;
25
+ /**
26
+ * Markdown only: whether a bare link alone on its line is shown with `linkEmbed`
27
+ * instead of as a link.
28
+ */
29
+ embedLink?: (url: string) => boolean;
30
+ /** Renders such a link. The second argument renders the ordinary link, e.g. while loading. */
31
+ linkEmbed?: Snippet<[url: string, fallback: Snippet]>;
23
32
  class?: string;
24
33
  };
25
34
 
@@ -31,6 +40,8 @@
31
40
  socialClient,
32
41
  mentionUrl,
33
42
  headingOffset = 0,
43
+ embedLink,
44
+ linkEmbed,
34
45
  class: className
35
46
  }: RichTextProps = $props();
36
47
 
@@ -99,7 +110,12 @@
99
110
  {#snippet blocks(children: unknown, depth: number)}
100
111
  {#each nodes(children) as node, index (index)}
101
112
  {#if depth > MAX_RENDER_DEPTH}<p>{inlineText(node, depth)}</p>
102
- {:else if node.type === 'paragraph'}<p>{@render inlines(node.children, false, depth + 1)}</p>
113
+ {:else if node.type === 'paragraph'}
114
+ {#each paragraphParts(node.children, linkEmbed && embedLink) as part, partIndex (partIndex)}
115
+ {#snippet paragraph()}<p>{@render inlines(part.children, false, depth + 1)}</p>{/snippet}
116
+ {#if part.embed && linkEmbed}{@render linkEmbed(part.embed, paragraph)}
117
+ {:else}{@render paragraph()}{/if}
118
+ {/each}
103
119
  {:else if node.type === 'heading'}<svelte:element
104
120
  this={heading(node.depth)}
105
121
  class="{node.depth === 1
@@ -1,3 +1,4 @@
1
+ import type { Snippet } from 'svelte';
1
2
  import { type RichTextDocument, type RichTextLinkOptions } from '../richtext/document.js';
2
3
  export type RichTextProps = RichTextLinkOptions & {
3
4
  /** From `parseRichText`, usually on the server. Takes precedence over `text`. */
@@ -10,6 +11,13 @@ export type RichTextProps = RichTextLinkOptions & {
10
11
  detectLinks?: boolean;
11
12
  /** Added to Markdown heading levels, e.g. 1 renders `#` as h2 below a page's h1. */
12
13
  headingOffset?: number;
14
+ /**
15
+ * Markdown only: whether a bare link alone on its line is shown with `linkEmbed`
16
+ * instead of as a link.
17
+ */
18
+ embedLink?: (url: string) => boolean;
19
+ /** Renders such a link. The second argument renders the ordinary link, e.g. while loading. */
20
+ linkEmbed?: Snippet<[url: string, fallback: Snippet]>;
13
21
  class?: string;
14
22
  };
15
23
  declare const RichText: import("svelte").Component<RichTextProps, {}, "">;
@@ -0,0 +1,221 @@
1
+ <script lang="ts">
2
+ import { untrack } from 'svelte';
3
+ import { Bookmark } from '@sketchyicons/svelte';
4
+ import Button from './Button.svelte';
5
+ import Icon from './Icon.svelte';
6
+ import Input from './Input.svelte';
7
+ import Modal from './Modal.svelte';
8
+ import { parseSembleLink } from '../semble/urls.js';
9
+ import type { SembleClient, SembleCollection, SembleSelection } from '../semble/types.js';
10
+
11
+ export type SembleCollectionPickerProps = {
12
+ open?: boolean;
13
+ actor?: string | null;
14
+ listCollections?: SembleClient['listCollections'];
15
+ loadCollection?: SembleClient['getCollection'];
16
+ selectedUris?: string[];
17
+ isSelected?: (collection: SembleCollection) => boolean;
18
+ onselect: SembleSelection;
19
+ class?: string;
20
+ };
21
+ let {
22
+ open = $bindable(false),
23
+ actor,
24
+ listCollections,
25
+ loadCollection,
26
+ selectedUris = [],
27
+ isSelected,
28
+ onselect,
29
+ class: className
30
+ }: SembleCollectionPickerProps = $props();
31
+ let input = $state('');
32
+ let error = $state('');
33
+ let listError = $state('');
34
+ let busy = $state(false);
35
+ let listing = $state(false);
36
+ let collections: SembleCollection[] = $state([]);
37
+ let cursor = $state<string | undefined>();
38
+ let preview: SembleCollection | null = $state(null);
39
+ let previewInput = $state('');
40
+ let generation = 0;
41
+ function count(collection: SembleCollection) {
42
+ return `${collection.cardCount} ${collection.cardCount === 1 ? 'link' : 'links'}`;
43
+ }
44
+ function added(collection: SembleCollection) {
45
+ return selectedUris.includes(collection.uri) || !!isSelected?.(collection);
46
+ }
47
+
48
+ $effect(() => {
49
+ void actor;
50
+ void listCollections;
51
+ void loadCollection;
52
+ const shown = open;
53
+ generation++;
54
+ input = '';
55
+ error = '';
56
+ listError = '';
57
+ busy = false;
58
+ listing = false;
59
+ collections = [];
60
+ cursor = undefined;
61
+ preview = null;
62
+ if (shown)
63
+ untrack(() => {
64
+ void loadPage();
65
+ });
66
+ return () => {
67
+ generation++;
68
+ };
69
+ });
70
+ async function choose(collection: SembleCollection) {
71
+ if (busy || added(collection)) return;
72
+ const id = generation;
73
+ busy = true;
74
+ error = '';
75
+ try {
76
+ const message = await onselect(collection);
77
+ if (id !== generation) return;
78
+ if (message) error = message;
79
+ else open = false;
80
+ } catch {
81
+ if (id === generation) error = 'Couldn’t add that collection. Please try again.';
82
+ } finally {
83
+ if (id === generation) busy = false;
84
+ }
85
+ }
86
+ async function loadPage(more = false) {
87
+ if (!actor || !listCollections || listing) return;
88
+ const id = generation;
89
+ const previous = more ? cursor : undefined;
90
+ listing = true;
91
+ listError = '';
92
+ try {
93
+ const page = await listCollections(actor, previous);
94
+ if (id !== generation) return;
95
+ collections = [
96
+ ...new Map(
97
+ (more ? [...collections, ...page.collections] : page.collections).map((collection) => [
98
+ collection.uri,
99
+ collection
100
+ ])
101
+ ).values()
102
+ ];
103
+ cursor = page.cursor !== previous ? page.cursor : undefined;
104
+ } catch {
105
+ if (id === generation)
106
+ listError = 'Couldn’t load your collections. You can still paste a link.';
107
+ } finally {
108
+ if (id === generation) listing = false;
109
+ }
110
+ }
111
+ async function previewCollection() {
112
+ if (busy) return;
113
+ const ref = parseSembleLink(input);
114
+ if (!ref) {
115
+ error = 'Enter a Semble collection link.';
116
+ return;
117
+ }
118
+ if (!loadCollection) {
119
+ error = 'Collection previews aren’t available in this app.';
120
+ return;
121
+ }
122
+ const id = generation,
123
+ requested = input;
124
+ busy = true;
125
+ error = '';
126
+ preview = null;
127
+ try {
128
+ const result = await loadCollection(ref.atUri);
129
+ if (id === generation && input === requested) {
130
+ preview = result;
131
+ previewInput = requested;
132
+ }
133
+ } catch {
134
+ if (id === generation) error = 'Couldn’t load that collection. Check the link and try again.';
135
+ } finally {
136
+ if (id === generation) busy = false;
137
+ }
138
+ }
139
+ </script>
140
+
141
+ <Modal bind:open title="Add collection" class={className}>
142
+ <div class="flex flex-col gap-2 sm:flex-row">
143
+ <Input
144
+ aria-label="Semble collection link"
145
+ placeholder="Paste a Semble collection link…"
146
+ bind:value={input}
147
+ class="min-w-0 flex-1"
148
+ oninput={() => {
149
+ preview = null;
150
+ error = '';
151
+ }}
152
+ onkeydown={(event) => {
153
+ if (event.key === 'Enter') {
154
+ event.preventDefault();
155
+ void previewCollection();
156
+ }
157
+ }}
158
+ />
159
+ <Button disabled={busy || !input.trim()} onclick={previewCollection}
160
+ >{busy ? 'Loading…' : 'Preview'}</Button
161
+ >
162
+ </div>
163
+ {#if preview && input === previewInput}
164
+ <div class="mt-4 flex items-center gap-3">
165
+ <div class="min-w-0 flex-1">
166
+ <p class="truncate font-medium">{preview.name}</p>
167
+ <p class="text-sm break-words text-base-600 dark:text-base-400">
168
+ @{preview.creator.handle} · {count(preview)}
169
+ </p>
170
+ </div>
171
+ <Button disabled={busy || added(preview)} onclick={() => preview && choose(preview)}
172
+ >{added(preview) ? 'Added' : 'Add collection'}</Button
173
+ >
174
+ </div>
175
+ {/if}
176
+ {#if actor && listCollections}
177
+ <p class="mt-6 mb-2 text-sm font-medium">Your collections</p>
178
+ <div class="space-y-1">
179
+ {#each collections as collection (collection.uri)}
180
+ <button
181
+ type="button"
182
+ class="flex w-full items-center gap-3 rounded-lg p-2 text-left hover:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] disabled:opacity-50 dark:hover:bg-base-950"
183
+ disabled={busy || added(collection)}
184
+ onclick={() => choose(collection)}
185
+ aria-label={`${added(collection) ? 'Added' : 'Add'} ${collection.name}`}
186
+ >
187
+ <span
188
+ class="flex size-10 shrink-0 items-center justify-center rounded-md bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] dark:bg-base-950"
189
+ ><Icon img={Bookmark} size={18} /></span
190
+ >
191
+ <span class="min-w-0 flex-1"
192
+ ><span class="block truncate font-medium">{collection.name}</span><span
193
+ class="text-sm text-base-600 dark:text-base-400">{count(collection)}</span
194
+ ></span
195
+ >
196
+ {#if added(collection)}<span class="text-xs text-base-600 dark:text-base-400">Added</span
197
+ >{/if}
198
+ </button>
199
+ {/each}
200
+ </div>
201
+ {#if listing}<p class="mt-3 text-sm text-base-600 dark:text-base-400" role="status">
202
+ Loading collections…
203
+ </p>{:else if listError}<p
204
+ class="mt-3 text-sm text-base-600 dark:text-base-400"
205
+ role="status"
206
+ >
207
+ {listError}
208
+ </p>
209
+ <Button variant="ghost" size="sm" onclick={() => loadPage(!!cursor)}>Try again</Button
210
+ >{:else if !collections.length}<p class="text-sm text-base-600 dark:text-base-400">
211
+ No collections yet.
212
+ </p>{/if}
213
+ {#if cursor && !listError}<Button
214
+ variant="ghost"
215
+ class="mt-3"
216
+ disabled={listing}
217
+ onclick={() => loadPage(true)}>Load more</Button
218
+ >{/if}
219
+ {/if}
220
+ {#if error}<p class="mt-3 text-sm text-red-600 dark:text-red-400" role="alert">{error}</p>{/if}
221
+ </Modal>
@@ -0,0 +1,14 @@
1
+ import type { SembleClient, SembleCollection, SembleSelection } from '../semble/types.js';
2
+ export type SembleCollectionPickerProps = {
3
+ open?: boolean;
4
+ actor?: string | null;
5
+ listCollections?: SembleClient['listCollections'];
6
+ loadCollection?: SembleClient['getCollection'];
7
+ selectedUris?: string[];
8
+ isSelected?: (collection: SembleCollection) => boolean;
9
+ onselect: SembleSelection;
10
+ class?: string;
11
+ };
12
+ declare const SembleCollectionPicker: import("svelte").Component<SembleCollectionPickerProps, {}, "open">;
13
+ type SembleCollectionPicker = ReturnType<typeof SembleCollectionPicker>;
14
+ export default SembleCollectionPicker;
@@ -0,0 +1,153 @@
1
+ <script lang="ts">
2
+ import { Link } from '@sketchyicons/svelte';
3
+ import { SvelteSet } from 'svelte/reactivity';
4
+ import Button from './Button.svelte';
5
+ import Icon from './Icon.svelte';
6
+ import { parseSembleLink } from '../semble/urls.js';
7
+ import type { SembleClient, SembleCollectionPage } from '../semble/types.js';
8
+ import { safeHttpUrl } from '../urls.js';
9
+ import { focus } from '../styles.js';
10
+ import { cn } from '../utils.js';
11
+
12
+ export type SembleCollectionViewProps = {
13
+ reference: string;
14
+ title?: string;
15
+ loadCollection?: SembleClient['getCollection'];
16
+ class?: string;
17
+ };
18
+ let { reference, title, loadCollection, class: className }: SembleCollectionViewProps = $props();
19
+ let ref = $derived(parseSembleLink(reference));
20
+ let collection = $state<SembleCollectionPage | null>(null);
21
+ let loading = $state(false);
22
+ let failed = $state(false);
23
+ let retry = $state(0);
24
+ // Preview images are hotlinked from the linked pages and often fail.
25
+ const broken = new SvelteSet<string>();
26
+ let name = $derived(collection?.name || title || 'Collection');
27
+ let url = $derived(collection?.url || ref?.url);
28
+ $effect(() => {
29
+ const input = parseSembleLink(reference)?.atUri ?? reference;
30
+ const transport = loadCollection;
31
+ void retry;
32
+ let current = true;
33
+ collection = null;
34
+ failed = false;
35
+ loading = !!transport;
36
+ if (transport) {
37
+ void Promise.resolve()
38
+ .then(() => transport(input))
39
+ .then((result) => {
40
+ if (current) collection = result;
41
+ })
42
+ .catch(() => {
43
+ if (current) failed = true;
44
+ })
45
+ .finally(() => {
46
+ if (current) loading = false;
47
+ });
48
+ }
49
+ return () => {
50
+ current = false;
51
+ };
52
+ });
53
+ </script>
54
+
55
+ <section aria-label={name} class={cn(className)}>
56
+ <div class="mb-3 flex flex-wrap items-start justify-between gap-2">
57
+ <div class="min-w-0">
58
+ <h2 class="font-medium break-words">{name}</h2>
59
+ {#if collection}<p class="text-sm break-words text-base-600 dark:text-base-400">
60
+ <a
61
+ href={`https://semble.so/profile/${encodeURIComponent(collection.creator.did)}`}
62
+ target="_blank"
63
+ rel="noopener noreferrer"
64
+ class="hover:text-accent-700 dark:hover:text-accent-300"
65
+ >{collection.creator.displayName || collection.creator.handle}</a
66
+ >
67
+ · {collection.cardCount}
68
+ {collection.cardCount === 1 ? 'link' : 'links'}
69
+ </p>{/if}
70
+ </div>
71
+ {#if url}<a
72
+ href={url}
73
+ target="_blank"
74
+ rel="noopener noreferrer"
75
+ class="text-sm text-accent-700 hover:underline dark:text-accent-300">Open on Semble</a
76
+ >{/if}
77
+ </div>
78
+ {#if loading}<p class="py-6 text-sm text-base-600 dark:text-base-400" role="status">
79
+ Loading links…
80
+ </p>
81
+ {:else if failed || !loadCollection}<p
82
+ class="mb-2 text-sm text-base-600 dark:text-base-400"
83
+ role="status"
84
+ >
85
+ Links are unavailable. You can still open the collection on Semble.
86
+ </p>
87
+ {#if loadCollection}<Button variant="ghost" size="sm" onclick={() => retry++}>Try again</Button
88
+ >{/if}
89
+ {:else if collection}
90
+ {#if collection.description}<p
91
+ class="mb-3 text-sm break-words whitespace-pre-line text-base-600 dark:text-base-400"
92
+ >
93
+ {collection.description}
94
+ </p>{/if}
95
+ {#if !collection.cards.length}<p class="py-4 text-sm text-base-600 dark:text-base-400">
96
+ No links in this collection yet.
97
+ </p>
98
+ {:else}
99
+ <!-- Masonry: preview images keep their wide format and cards without one stay compact. -->
100
+ <ul class="gap-3 sm:columns-2">
101
+ {#each collection.cards as card (card.id)}
102
+ <li class="mb-3 break-inside-avoid">
103
+ <a
104
+ href={safeHttpUrl(card.url)}
105
+ target="_blank"
106
+ rel="noopener noreferrer nofollow ugc"
107
+ class={`group block overflow-hidden rounded-panel border border-base-300 bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] text-base-950 no-underline shadow-[inset_0_2px_4px_color-mix(in_srgb,var(--base-950)_8%,transparent),inset_0_5px_12px_color-mix(in_srgb,var(--base-950)_2%,transparent)] transition-colors hover:border-base-400 motion-reduce:transition-none dark:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] dark:bg-base-950 dark:text-base-50 dark:shadow-[inset_0_2px_4px_#0006,inset_0_5px_12px_#0002] dark:hover:border-base-700 ${focus}`}
108
+ >
109
+ {#if card.image && !broken.has(card.id)}<span class="relative block"
110
+ ><img
111
+ src={card.image}
112
+ alt=""
113
+ loading="lazy"
114
+ referrerpolicy="no-referrer"
115
+ class="aspect-[1.91/1] w-full object-cover"
116
+ onerror={() => broken.add(card.id)}
117
+ /><span
118
+ class="pointer-events-none absolute inset-0 shadow-[inset_0_2px_5px_color-mix(in_srgb,var(--base-950)_12%,transparent)] dark:shadow-[inset_0_2px_5px_#0006]"
119
+ ></span></span
120
+ >{/if}
121
+ <span class="block p-3">
122
+ <span class="flex items-center gap-1.5 text-xs text-base-600 dark:text-base-400"
123
+ ><Icon img={Link} size={12} class="shrink-0" /><span class="truncate"
124
+ >{card.site}{card.addedBy ? ` · @${card.addedBy.handle}` : ''}</span
125
+ ></span
126
+ >
127
+ <span
128
+ class="mt-1 line-clamp-3 text-sm leading-snug font-medium break-words group-hover:text-accent-700 dark:group-hover:text-accent-300"
129
+ >{card.title}</span
130
+ >
131
+ {#if card.description}<span
132
+ class="mt-1 line-clamp-2 text-xs leading-relaxed break-words text-base-600 dark:text-base-400"
133
+ >{card.description}</span
134
+ >{/if}
135
+ {#if card.note}<span
136
+ class="mt-2 line-clamp-4 border-l-2 border-accent-700/40 pl-2 text-xs leading-relaxed break-words whitespace-pre-line dark:border-accent-300/40"
137
+ >{card.note}</span
138
+ >{/if}
139
+ </span>
140
+ </a>
141
+ </li>
142
+ {/each}
143
+ </ul>
144
+ {#if collection.cardCount > collection.cards.length && url}<a
145
+ href={url}
146
+ target="_blank"
147
+ rel="noopener noreferrer"
148
+ class="mt-3 inline-block text-sm text-accent-700 hover:underline dark:text-accent-300"
149
+ >See all {collection.cardCount} on Semble</a
150
+ >{/if}
151
+ {/if}
152
+ {/if}
153
+ </section>
@@ -0,0 +1,10 @@
1
+ import type { SembleClient } from '../semble/types.js';
2
+ export type SembleCollectionViewProps = {
3
+ reference: string;
4
+ title?: string;
5
+ loadCollection?: SembleClient['getCollection'];
6
+ class?: string;
7
+ };
8
+ declare const SembleCollectionView: import("svelte").Component<SembleCollectionViewProps, {}, "">;
9
+ type SembleCollectionView = ReturnType<typeof SembleCollectionView>;
10
+ export default SembleCollectionView;
@@ -1,5 +1,10 @@
1
1
  <script lang="ts">
2
- import { NestedComments, blueskyPostToPostData, type PostData } from '../index.js';
2
+ import {
3
+ NestedComments,
4
+ blueskyPostToPostData,
5
+ hasModerationLabel,
6
+ type PostData
7
+ } from '../index.js';
3
8
  import { appviewUrl } from './atproto-helpers.js';
4
9
 
5
10
  import { socialClientInfo, socialPostUrl, type PreferredSocialClient } from '../social.js';
@@ -16,9 +21,17 @@
16
21
  let loading = $state(true);
17
22
  let errorMessage = $state<string | null>(null);
18
23
 
24
+ /**
25
+ * Comments are shown to everyone without their moderation preferences, so a reply that carries
26
+ * a moderation label (itself, its author, or a post it quotes) is left out, with the replies
27
+ * beneath it.
28
+ */
19
29
  function threadToComments(replies: unknown[]): PostData[] {
20
30
  return (replies as Array<{ $type?: string; post?: unknown; replies?: unknown[] }>)
21
- .filter((r) => r.$type === 'app.bsky.feed.defs#threadViewPost' && r.post)
31
+ .filter(
32
+ (r) =>
33
+ r.$type === 'app.bsky.feed.defs#threadViewPost' && r.post && !hasModerationLabel(r.post)
34
+ )
22
35
  .map((r) => {
23
36
  const postData = blueskyPostToPostData(
24
37
  r.post as Parameters<typeof blueskyPostToPostData>[0]
@@ -27,11 +27,20 @@
27
27
  import EventLocationMap from './event-view/EventLocationMap.svelte';
28
28
  import EventHostedBy from './event-view/EventHostedBy.svelte';
29
29
  import EventLinksList from './event-view/EventLinksList.svelte';
30
- import { GrainAlbumView } from '../index.js';
31
- import { eventStreamLink, parseGrainLink } from './linked-records.js';
30
+ import { GrainAlbumView, SembleCollectionView } from '../index.js';
31
+ import {
32
+ eventStreamLink,
33
+ eventTabLink,
34
+ parseEventLink,
35
+ parseSembleLink
36
+ } from './linked-records.js';
32
37
  import AddToCalendarButton from './event-view/AddToCalendarButton.svelte';
33
38
  import ExternalRsvpNotice from './event-view/ExternalRsvpNotice.svelte';
34
39
  import RichText from '../components/RichText.svelte';
40
+ import PostLinkEmbed from './event-view/PostLinkEmbed.svelte';
41
+ import EventLinkEmbed from './event-view/EventLinkEmbed.svelte';
42
+ import ProfileLinkEmbed from './event-view/ProfileLinkEmbed.svelte';
43
+ import { parseSocialPostUrl, parseSocialProfileUrl } from '../social/urls.js';
35
44
  import { richTextToPlainText } from '../richtext/document.js';
36
45
  import { resolveEventUrls } from './urls.js';
37
46
  import { getLocations, resolveGeoLocation, type GeoLocation } from './event-view/locations.js';
@@ -124,20 +133,49 @@
124
133
  let hasComments = $derived(!!eventData.bskyPostRef?.showComments && !!eventData.bskyPostRef?.uri);
125
134
  let hasDescription = $derived(!!eventData.description?.trim());
126
135
  let aboutCommentsTab = $state<string>('about');
127
- let photoLinks = $derived(eventData.uris?.filter((link) => parseGrainLink(link.uri)) ?? []);
136
+ let photoLinks = $derived(eventData.uris?.filter((l) => eventTabLink(l.uri) === 'photos') ?? []);
137
+ // Without a loader the collection stays an ordinary link.
138
+ let showCollections = $derived(!!adapter.linkedRecords?.getSembleCollection);
139
+ let collectionLinks = $derived(
140
+ showCollections
141
+ ? (eventData.uris?.filter((l) => eventTabLink(l.uri) === 'collections') ?? [])
142
+ : []
143
+ );
144
+ // Links without a tab of their own. A collection that can't be loaded stays a link, by its web
145
+ // address: the list shows only HTTP(S) destinations, and the record may hold an AT URI.
146
+ let sidebarLinks = $derived(
147
+ eventData.uris?.flatMap((link) => {
148
+ const tab = eventTabLink(link.uri);
149
+ if (tab === 'photos' || (tab === 'collections' && showCollections)) return [];
150
+ return [tab === 'collections' ? { ...link, uri: parseSembleLink(link.uri)!.url } : link];
151
+ })
152
+ );
128
153
  let contentTabs = $derived([
129
154
  ...(hasDescription ? [{ value: 'about', label: 'About' }] : []),
130
155
  ...(hasComments ? [{ value: 'comments', label: 'Comments' }] : []),
131
- ...(photoLinks.length ? [{ value: 'photos', label: 'Photos' }] : [])
156
+ ...(photoLinks.length ? [{ value: 'photos', label: 'Photos' }] : []),
157
+ ...(collectionLinks.length ? [{ value: 'collections', label: 'Collections' }] : [])
132
158
  ]);
133
159
  let activeTab = $derived(
134
160
  contentTabs.some((tab) => tab.value === aboutCommentsTab)
135
161
  ? aboutCommentsTab
136
162
  : contentTabs[0]?.value
137
163
  );
164
+ // Event links are recognized on the canonical site and on this page's own origin.
165
+ let eventOrigins = $derived([...new Set(['https://atmo.rsvp', pageUrl.origin])]);
166
+ let loadEvent = $derived(adapter.linkedRecords?.getEvent);
167
+ /** A link to another event, when the host can load it. */
168
+ function otherEvent(url: string): boolean {
169
+ const link = loadEvent && parseEventLink(url, eventOrigins);
170
+ return (
171
+ !!link && !(link.rkey === rkey && (link.actor === did || link.actor === hostProfile?.handle))
172
+ );
173
+ }
138
174
  let photosOpened = $state(false);
175
+ let collectionsOpened = $state(false);
139
176
  $effect(() => {
140
177
  if (activeTab === 'photos') photosOpened = true;
178
+ if (activeTab === 'collections') collectionsOpened = true;
141
179
  });
142
180
 
143
181
  onMount(() => {
@@ -406,7 +444,7 @@
406
444
  </div>
407
445
  {/if}
408
446
 
409
- <!-- About, comments and linked photo albums -->
447
+ <!-- About, comments, linked photo albums and link collections -->
410
448
  {#if contentTabs.length}
411
449
  <div class="mt-8 mb-8">
412
450
  {#if contentTabs.length > 1}
@@ -442,8 +480,28 @@
442
480
  socialClient={viewer.preferredSocialClient}
443
481
  detectLinks
444
482
  headingOffset={1}
483
+ embedLink={(url) =>
484
+ !!parseSocialPostUrl(url) || !!parseSocialProfileUrl(url) || otherEvent(url)}
445
485
  class="text-base-700 dark:text-base-300"
446
- />
486
+ >
487
+ {#snippet linkEmbed(url, fallback)}
488
+ {#if loadEvent && otherEvent(url)}<EventLinkEmbed
489
+ {url}
490
+ origins={eventOrigins}
491
+ local={!embedMode}
492
+ {loadEvent}
493
+ {fallback}
494
+ />{:else if parseSocialProfileUrl(url)}<ProfileLinkEmbed
495
+ {url}
496
+ {fallback}
497
+ socialClient={viewer.preferredSocialClient}
498
+ />{:else}<PostLinkEmbed
499
+ {url}
500
+ {fallback}
501
+ socialClient={viewer.preferredSocialClient}
502
+ />{/if}
503
+ {/snippet}
504
+ </RichText>
447
505
  {:else if activeTab === 'comments' && eventData.bskyPostRef?.uri}
448
506
  <EventComments
449
507
  postUri={eventData.bskyPostRef.uri}
@@ -459,6 +517,15 @@
459
517
  />{/each}
460
518
  </div>
461
519
  {/if}
520
+ {#if collectionsOpened && collectionLinks.length}
521
+ <div hidden={activeTab !== 'collections'} class="space-y-8">
522
+ {#each collectionLinks as link, i (`${link.uri}-${i}`)}<SembleCollectionView
523
+ reference={link.uri}
524
+ title={link.name}
525
+ loadCollection={adapter.linkedRecords?.getSembleCollection}
526
+ />{/each}
527
+ </div>
528
+ {/if}
462
529
  </div>
463
530
  {/if}
464
531
 
@@ -487,7 +554,7 @@
487
554
  <div class="order-3 space-y-6 md:order-0 md:col-start-1">
488
555
  <EventHostedBy {hostProfile} {hostUrl} {did} {speakers} />
489
556
 
490
- <EventLinksList uris={eventData.uris?.filter((link) => !parseGrainLink(link.uri))} />
557
+ <EventLinksList uris={sidebarLinks} />
491
558
 
492
559
  <AddToCalendarButton {eventData} {eventUri} pageHref={pageUrl.href} />
493
560
  {@render extraActions?.()}