@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,9 +1,17 @@
1
1
  <script lang="ts">
2
- import { Button, Icon, Popover, GrainAlbumPicker, StreamplacePicker } from '../../index.js';
3
- import { Camera, Plus, Video } from '@sketchyicons/svelte';
2
+ import {
3
+ Button,
4
+ Icon,
5
+ Popover,
6
+ GrainAlbumPicker,
7
+ SembleCollectionPicker,
8
+ StreamplacePicker
9
+ } from '../../index.js';
10
+ import { Bookmark, Camera, Plus, Video } from '@sketchyicons/svelte';
11
+ import type { SembleCollection } from '../../semble.js';
4
12
  import type { GrainAlbum } from '../../grain.js';
5
13
  import type { EditorAdapter, EditorViewer } from './adapter.js';
6
- import { eventStreamLink, parseGrainLink } from '../linked-records.js';
14
+ import { eventStreamLink, parseGrainLink, parseSembleLink } from '../linked-records.js';
7
15
 
8
16
  let {
9
17
  links = $bindable(),
@@ -17,6 +25,7 @@
17
25
  let menuOpen = $state(false);
18
26
  let grainOpen = $state(false);
19
27
  let streamOpen = $state(false);
28
+ let sembleOpen = $state(false);
20
29
  let session = 0;
21
30
  let stream = $derived(links.find((link) => eventStreamLink(link.uri)));
22
31
  function added(album: GrainAlbum) {
@@ -51,6 +60,20 @@
51
60
  if (current !== session || !grainOpen) return;
52
61
  links = [...links, { uri: album.url, name: album.title }];
53
62
  }
63
+ function collectionAdded(collection: SembleCollection) {
64
+ return links.some((link) => {
65
+ const ref = parseSembleLink(link.uri);
66
+ return (
67
+ ref?.atUri === collection.uri ||
68
+ (ref?.actor === collection.creator.handle &&
69
+ ref?.rkey === parseSembleLink(collection.uri)?.rkey)
70
+ );
71
+ });
72
+ }
73
+ function attachCollection(collection: SembleCollection) {
74
+ if (collectionAdded(collection)) return 'This collection is already added.';
75
+ links = [...links, { uri: collection.url, name: collection.name }];
76
+ }
54
77
  </script>
55
78
 
56
79
  <Popover
@@ -80,6 +103,16 @@
80
103
  streamOpen = true;
81
104
  }}><Icon img={Video} size={16} />Streamplace stream</Button
82
105
  >
106
+ {#if adapter.linkedRecords?.getSembleCollection}
107
+ <Button
108
+ variant="ghost"
109
+ class="w-full justify-start"
110
+ onclick={() => {
111
+ menuOpen = false;
112
+ sembleOpen = true;
113
+ }}><Icon img={Bookmark} size={16} />Semble collection</Button
114
+ >
115
+ {/if}
83
116
  </Popover>
84
117
 
85
118
  <GrainAlbumPicker
@@ -90,6 +123,14 @@
90
123
  isSelected={added}
91
124
  onselect={attachAlbum}
92
125
  />
126
+ <SembleCollectionPicker
127
+ bind:open={sembleOpen}
128
+ actor={viewer.did}
129
+ listCollections={adapter.linkedRecords?.listSembleCollections}
130
+ loadCollection={adapter.linkedRecords?.getSembleCollection}
131
+ isSelected={collectionAdded}
132
+ onselect={attachCollection}
133
+ />
93
134
  <StreamplacePicker
94
135
  bind:open={streamOpen}
95
136
  actor={viewer.handle && viewer.handle !== 'handle.invalid' ? viewer.handle : viewer.did}
@@ -1,8 +1,13 @@
1
1
  <script lang="ts">
2
- import { Camera, Link as LinkIcon, Plus, Video, X } from '@sketchyicons/svelte';
2
+ import { Bookmark, Camera, Link as LinkIcon, Plus, Video, X } from '@sketchyicons/svelte';
3
3
  import { Button, Icon, Input, Popover } from '../../index.js';
4
4
  import { validateLink } from '../cal/helper.js';
5
- import { eventStreamLink, isLinkedRecord, parseGrainLink } from '../linked-records.js';
5
+ import {
6
+ eventStreamLink,
7
+ isLinkedRecord,
8
+ parseGrainLink,
9
+ parseSembleLink
10
+ } from '../linked-records.js';
6
11
  import type { EditorAdapter, EditorViewer } from './adapter.js';
7
12
  import LinkedRecordsPicker from './LinkedRecordsPicker.svelte';
8
13
 
@@ -32,6 +37,7 @@
32
37
  return;
33
38
  }
34
39
  const grain = parseGrainLink(uri),
40
+ semble = parseSembleLink(uri),
35
41
  stream = eventStreamLink(uri);
36
42
  // Keep one stream even when it was added through the generic URL input.
37
43
  if (stream && links.some((l) => eventStreamLink(l.uri))) {
@@ -44,7 +50,13 @@
44
50
  uri,
45
51
  name:
46
52
  newName.trim() ||
47
- (grain ? 'Grain photo album' : stream ? `Streamplace · ${stream.actor}` : '')
53
+ (grain
54
+ ? 'Grain photo album'
55
+ : semble
56
+ ? 'Semble collection'
57
+ : stream
58
+ ? `Streamplace · ${stream.actor}`
59
+ : '')
48
60
  }
49
61
  ];
50
62
  cancel();
@@ -60,10 +72,16 @@
60
72
  }
61
73
  </script>
62
74
 
63
- {#snippet row(link: Link, provider?: 'grain' | 'stream')}
75
+ {#snippet row(link: Link, provider?: 'grain' | 'semble' | 'stream')}
64
76
  <div class="group flex items-center gap-2">
65
77
  <Icon
66
- img={provider === 'grain' ? Camera : provider === 'stream' ? Video : LinkIcon}
78
+ img={provider === 'grain'
79
+ ? Camera
80
+ : provider === 'semble'
81
+ ? Bookmark
82
+ : provider === 'stream'
83
+ ? Video
84
+ : LinkIcon}
67
85
  size={16}
68
86
  class="shrink-0 text-base-600 dark:text-base-400"
69
87
  />
@@ -72,9 +90,11 @@
72
90
  {link.name ||
73
91
  (provider === 'grain'
74
92
  ? 'Grain photo album'
75
- : provider === 'stream'
76
- ? eventStreamLink(link.uri)?.actor
77
- : link.uri.replace(/^https?:\/\//, ''))}
93
+ : provider === 'semble'
94
+ ? 'Semble collection'
95
+ : provider === 'stream'
96
+ ? eventStreamLink(link.uri)?.actor
97
+ : link.uri.replace(/^https?:\/\//, ''))}
78
98
  </p>
79
99
  </div>
80
100
  <Button
@@ -103,7 +123,7 @@
103
123
  <div class="mb-4 space-y-3">
104
124
  {#each linked as link, i (i)}{@render row(
105
125
  link,
106
- parseGrainLink(link.uri) ? 'grain' : 'stream'
126
+ parseGrainLink(link.uri) ? 'grain' : parseSembleLink(link.uri) ? 'semble' : 'stream'
107
127
  )}{/each}
108
128
  </div>
109
129
  {/if}
@@ -0,0 +1,49 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import Surface from '../../components/Surface.svelte';
4
+ import EventCard from '../EventCard.svelte';
5
+ import type { FlatEventRecord } from '../contrail.js';
6
+ import { parseEventLink, type LinkedRecordsClient } from '../linked-records.js';
7
+
8
+ let {
9
+ url,
10
+ origins,
11
+ local,
12
+ loadEvent,
13
+ fallback
14
+ }: {
15
+ url: string;
16
+ origins: readonly string[];
17
+ /** Whether this app serves event pages itself; otherwise the card opens the linked URL. */
18
+ local: boolean;
19
+ loadEvent: NonNullable<LinkedRecordsClient['getEvent']>;
20
+ /** The ordinary link, shown until the event loads and whenever it can't be shown. */
21
+ fallback: Snippet;
22
+ } = $props();
23
+
24
+ let ref = $derived(parseEventLink(url, origins));
25
+ let event = $state<FlatEventRecord | null>(null);
26
+ $effect(() => {
27
+ const link = parseEventLink(url, origins);
28
+ const transport = loadEvent;
29
+ let current = true;
30
+ event = null;
31
+ if (link) {
32
+ void Promise.resolve()
33
+ .then(() => transport(link.actor, link.rkey))
34
+ .then((result) => {
35
+ if (current && result?.rkey === link.rkey && result.startsAt) event = result;
36
+ })
37
+ .catch(() => {});
38
+ }
39
+ return () => {
40
+ current = false;
41
+ };
42
+ });
43
+ </script>
44
+
45
+ {#if event && ref}
46
+ <Surface class="p-4"
47
+ ><EventCard {event} actor={ref.actor} href={local ? ref.path : url} /></Surface
48
+ >
49
+ {:else}{@render fallback()}{/if}
@@ -0,0 +1,14 @@
1
+ import type { Snippet } from 'svelte';
2
+ import { type LinkedRecordsClient } from '../linked-records.js';
3
+ type $$ComponentProps = {
4
+ url: string;
5
+ origins: readonly string[];
6
+ /** Whether this app serves event pages itself; otherwise the card opens the linked URL. */
7
+ local: boolean;
8
+ loadEvent: NonNullable<LinkedRecordsClient['getEvent']>;
9
+ /** The ordinary link, shown until the event loads and whenever it can't be shown. */
10
+ fallback: Snippet;
11
+ };
12
+ declare const EventLinkEmbed: import("svelte").Component<$$ComponentProps, {}, "">;
13
+ type EventLinkEmbed = ReturnType<typeof EventLinkEmbed>;
14
+ export default EventLinkEmbed;
@@ -0,0 +1,71 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import NestedComments from '../../components/NestedComments.svelte';
4
+ import Surface from '../../components/Surface.svelte';
5
+ import {
6
+ blueskyPostToPostData,
7
+ hasModerationLabel,
8
+ type BlueskyPostView,
9
+ type PostData
10
+ } from '../../social/posts.js';
11
+ import type { PreferredSocialClient } from '../../social/preferred-client.js';
12
+ import { parseSocialPostUrl, socialPostUrl } from '../../social/urls.js';
13
+ import { safeHttpUrl } from '../../urls.js';
14
+ import { appviewUrl } from '../atproto-helpers.js';
15
+
16
+ let {
17
+ url,
18
+ fallback,
19
+ socialClient
20
+ }: {
21
+ url: string;
22
+ /** The ordinary link, shown until the post loads and whenever it can't be shown. */
23
+ fallback: Snippet;
24
+ socialClient?: PreferredSocialClient | null;
25
+ } = $props();
26
+
27
+ /** Without the viewer's moderation preferences, labeled posts stay plain links. */
28
+ type ThreadPost = BlueskyPostView & { author: { did?: string } };
29
+
30
+ let post = $state<PostData | null>(null);
31
+ $effect(() => {
32
+ const ref = parseSocialPostUrl(url);
33
+ post = null;
34
+ if (!ref) return;
35
+ const controller = new AbortController();
36
+ fetch(
37
+ `${appviewUrl()}/xrpc/app.bsky.feed.getPostThread?uri=${encodeURIComponent(ref.uri)}&depth=0&parentHeight=0`,
38
+ { signal: controller.signal }
39
+ )
40
+ .then((response) => (response.ok ? response.json() : null))
41
+ .then((data: { thread?: { $type?: string; post?: ThreadPost } } | null) => {
42
+ const view = data?.thread?.post;
43
+ if (
44
+ controller.signal.aborted ||
45
+ data?.thread?.$type !== 'app.bsky.feed.defs#threadViewPost' ||
46
+ !view?.uri ||
47
+ !view.author?.did ||
48
+ hasModerationLabel(view)
49
+ )
50
+ return;
51
+ post = blueskyPostToPostData(view);
52
+ })
53
+ .catch(() => {});
54
+ return () => controller.abort();
55
+ });
56
+
57
+ /** Clicking anywhere on the post opens it; links, media and selected text keep their own behavior. */
58
+ function open(event: MouseEvent) {
59
+ if (!post || event.defaultPrevented || window.getSelection()?.toString()) return;
60
+ if ((event.target as Element).closest('a, button, video, iframe, [role="button"]')) return;
61
+ const href = socialPostUrl(post.uri, socialClient) ?? safeHttpUrl(post.href);
62
+ if (href) window.open(href, '_blank', 'noopener,noreferrer');
63
+ }
64
+ </script>
65
+
66
+ {#if post}
67
+ <!-- Pointer convenience only: the author, date and count links inside open the same post. -->
68
+ <Surface onclick={open} class="cursor-pointer p-4">
69
+ <NestedComments comments={[post]} {socialClient} />
70
+ </Surface>
71
+ {:else}{@render fallback()}{/if}
@@ -0,0 +1,11 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { PreferredSocialClient } from '../../social/preferred-client.js';
3
+ type $$ComponentProps = {
4
+ url: string;
5
+ /** The ordinary link, shown until the post loads and whenever it can't be shown. */
6
+ fallback: Snippet;
7
+ socialClient?: PreferredSocialClient | null;
8
+ };
9
+ declare const PostLinkEmbed: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type PostLinkEmbed = ReturnType<typeof PostLinkEmbed>;
11
+ export default PostLinkEmbed;
@@ -0,0 +1,67 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import Avatar from '../../components/Avatar.svelte';
4
+ import Surface from '../../components/Surface.svelte';
5
+ import { blueskyProfileToProfileData, type ProfileData } from '../../social/profile.js';
6
+ import type { PreferredSocialClient } from '../../social/preferred-client.js';
7
+ import { parseSocialProfileUrl, socialProfileUrl } from '../../social/urls.js';
8
+ import { focus } from '../../styles.js';
9
+ import { appviewUrl } from '../atproto-helpers.js';
10
+
11
+ let {
12
+ url,
13
+ fallback,
14
+ socialClient
15
+ }: {
16
+ url: string;
17
+ /** The ordinary link, shown until the profile loads and whenever it can't be shown. */
18
+ fallback: Snippet;
19
+ socialClient?: PreferredSocialClient | null;
20
+ } = $props();
21
+
22
+ let profile = $state<ProfileData | null>(null);
23
+ $effect(() => {
24
+ const ref = parseSocialProfileUrl(url);
25
+ profile = null;
26
+ if (!ref) return;
27
+ const controller = new AbortController();
28
+ fetch(`${appviewUrl()}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(ref.actor)}`, {
29
+ signal: controller.signal
30
+ })
31
+ .then((response) => (response.ok ? response.json() : null))
32
+ .then((view: { labels?: { neg?: boolean }[] } | null) => {
33
+ // Profiles with a moderation label, or hidden from logged-out viewers, stay plain links.
34
+ if (
35
+ controller.signal.aborted ||
36
+ (Array.isArray(view?.labels) && view.labels.some((label) => !label?.neg))
37
+ )
38
+ return;
39
+ profile = blueskyProfileToProfileData(view) ?? null;
40
+ })
41
+ .catch(() => {});
42
+ return () => controller.abort();
43
+ });
44
+ let name = $derived(profile?.displayName || profile?.handle || profile?.did || '');
45
+ </script>
46
+
47
+ {#if profile}
48
+ <a
49
+ href={socialProfileUrl(profile.did, socialClient)}
50
+ target="_blank"
51
+ rel="noopener noreferrer"
52
+ class={`group block w-fit max-w-full rounded-panel no-underline ${focus}`}
53
+ >
54
+ <Surface class="flex items-center gap-3 py-3 pr-5 pl-3">
55
+ <Avatar {name} src={profile.avatar} size={40} />
56
+ <span class="min-w-0">
57
+ <span
58
+ class="block truncate text-sm font-medium group-hover:text-accent-700 dark:group-hover:text-accent-300"
59
+ ><bdi>{name}</bdi></span
60
+ >
61
+ {#if profile.handle}<span class="block truncate text-xs text-base-600 dark:text-base-400"
62
+ ><bdi>@{profile.handle}</bdi></span
63
+ >{/if}
64
+ </span>
65
+ </Surface>
66
+ </a>
67
+ {:else}{@render fallback()}{/if}
@@ -0,0 +1,11 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { PreferredSocialClient } from '../../social/preferred-client.js';
3
+ type $$ComponentProps = {
4
+ url: string;
5
+ /** The ordinary link, shown until the profile loads and whenever it can't be shown. */
6
+ fallback: Snippet;
7
+ socialClient?: PreferredSocialClient | null;
8
+ };
9
+ declare const ProfileLinkEmbed: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type ProfileLinkEmbed = ReturnType<typeof ProfileLinkEmbed>;
11
+ export default ProfileLinkEmbed;
@@ -1,7 +1,11 @@
1
1
  import { type GrainClient } from '../grain.js';
2
+ import type { FlatEventRecord } from './contrail.js';
3
+ import { type SembleClient } from '../semble.js';
2
4
  export { parseGrainLink, isLinkedActor } from '../grain.js';
5
+ export { parseSembleLink } from '../semble.js';
3
6
  export { parseStreamplaceLink } from '../streamplace.js';
4
7
  export type { GrainReference, GrainAlbum, GrainPhoto, GrainGallery, GrainAlbumPage } from '../grain.js';
8
+ export type { SembleReference, SembleCard, SembleCollection, SembleCollectionPage, SembleCollectionList } from '../semble.js';
5
9
  export type EventLink = {
6
10
  uri: string;
7
11
  name?: string;
@@ -9,10 +13,26 @@ export type EventLink = {
9
13
  export type LinkedRecordsClient = {
10
14
  getGrainGallery: GrainClient['getGallery'];
11
15
  listGrainAlbums: GrainClient['listAlbums'];
16
+ /** Optional: without these, Semble collections stay links and can only be pasted. */
17
+ getSembleCollection?: SembleClient['getCollection'];
18
+ listSembleCollections?: SembleClient['listCollections'];
19
+ /** Optional: a public event by handle or DID and record key, for event links in descriptions. */
20
+ getEvent?: (actor: string, rkey: string) => Promise<FlatEventRecord>;
12
21
  };
22
+ /**
23
+ * Recognize a link to an event page, `/p/<handle or DID>/e/<rkey>`, on one of the given origins.
24
+ * Syntax only; the event may not exist.
25
+ */
26
+ export declare function parseEventLink(value: string, origins?: readonly string[]): {
27
+ actor: string;
28
+ rkey: string;
29
+ path: string;
30
+ } | null;
13
31
  /** Recognize event stream URLs, not arbitrary bare handles in `uris`. */
14
32
  export declare function eventStreamLink(uri: string): {
15
33
  actor: string;
16
34
  url: string;
17
35
  } | null;
36
+ /** Links shown in the event's own tabs rather than its link list. */
37
+ export declare function eventTabLink(uri: string): 'photos' | 'collections' | null;
18
38
  export declare function isLinkedRecord(link: EventLink): boolean;
@@ -1,11 +1,41 @@
1
- import { parseGrainLink } from '../grain.js';
1
+ import { isLinkedActor, parseGrainLink } from '../grain.js';
2
+ import { parseSembleLink } from '../semble.js';
2
3
  import { parseStreamplaceLink } from '../streamplace.js';
3
4
  export { parseGrainLink, isLinkedActor } from '../grain.js';
5
+ export { parseSembleLink } from '../semble.js';
4
6
  export { parseStreamplaceLink } from '../streamplace.js';
7
+ /**
8
+ * Recognize a link to an event page, `/p/<handle or DID>/e/<rkey>`, on one of the given origins.
9
+ * Syntax only; the event may not exist.
10
+ */
11
+ export function parseEventLink(value, origins = ['https://atmo.rsvp']) {
12
+ try {
13
+ const url = new URL(value);
14
+ if (!origins.includes(url.origin) || url.username || url.password)
15
+ return null;
16
+ const match = /^\/p\/([^/]+)\/e\/([^/]+)\/?$/.exec(url.pathname);
17
+ if (!match)
18
+ return null;
19
+ let actor = decodeURIComponent(match[1]);
20
+ const rkey = decodeURIComponent(match[2]);
21
+ if (!isLinkedActor(actor) || !/^[A-Za-z0-9._~:-]{1,512}$/.test(rkey) || rkey.startsWith('.'))
22
+ return null;
23
+ if (!actor.startsWith('did:'))
24
+ actor = actor.toLowerCase();
25
+ return { actor, rkey, path: `/p/${actor.replaceAll('%', '%25')}/e/${rkey}` };
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ }
5
31
  /** Recognize event stream URLs, not arbitrary bare handles in `uris`. */
6
32
  export function eventStreamLink(uri) {
7
33
  return /^https?:\/\//i.test(uri) ? parseStreamplaceLink(uri) : null;
8
34
  }
35
+ /** Links shown in the event's own tabs rather than its link list. */
36
+ export function eventTabLink(uri) {
37
+ return parseGrainLink(uri) ? 'photos' : parseSembleLink(uri) ? 'collections' : null;
38
+ }
9
39
  export function isLinkedRecord(link) {
10
- return !!parseGrainLink(link.uri) || !!eventStreamLink(link.uri);
40
+ return !!eventTabLink(link.uri) || !!eventStreamLink(link.uri);
11
41
  }
package/dist/index.d.ts CHANGED
@@ -38,7 +38,12 @@ export { default as GrainAlbumView } from './components/GrainAlbumView.svelte';
38
38
  export type { GrainAlbumViewProps } from './components/GrainAlbumView.svelte';
39
39
  export { default as StreamplacePicker } from './components/StreamplacePicker.svelte';
40
40
  export type { StreamplacePickerProps } from './components/StreamplacePicker.svelte';
41
+ export { default as SembleCollectionPicker } from './components/SembleCollectionPicker.svelte';
42
+ export type { SembleCollectionPickerProps } from './components/SembleCollectionPicker.svelte';
43
+ export { default as SembleCollectionView } from './components/SembleCollectionView.svelte';
44
+ export type { SembleCollectionViewProps } from './components/SembleCollectionView.svelte';
41
45
  export * from './grain.js';
46
+ export * from './semble.js';
42
47
  export * from './streamplace.js';
43
48
  export { default as InsetImage } from './components/InsetImage.svelte';
44
49
  export { default as Badge } from './components/Badge.svelte';
@@ -89,7 +94,8 @@ export type { RichTextDocument, RichTextLinkOptions } from './richtext/document.
89
94
  export { default as ExternalEmbed } from './components/ExternalEmbed.svelte';
90
95
  export { defaultExternalEmbedProviders, youtubeEmbedProvider, klipyEmbedProvider, resolveExternalEmbed } from './social/external-embeds.js';
91
96
  export type { ExternalPostEmbed, ExternalEmbedProvider, ExternalEmbedPlayer } from './social/external-embeds.js';
92
- export { blueskyPostToPostData } from './social/posts.js';
97
+ export { blueskyPostToPostData, hasModerationLabel } from './social/posts.js';
98
+ export { parseSocialPostUrl, parseSocialProfileUrl } from './social/urls.js';
93
99
  export type { PostData, PostEmbed, BlueskyPostView } from './social/posts.js';
94
100
  export { editorJsonToBlueskyPost, textToDoc, graphemeLength } from './social/richtext.js';
95
101
  export type { Facet, RichTextOptions, RichTextSegment } from './social/richtext.js';
package/dist/index.js CHANGED
@@ -26,7 +26,10 @@ export { default as PhotoGrid } from './components/PhotoGrid.svelte';
26
26
  export { default as GrainAlbumPicker } from './components/GrainAlbumPicker.svelte';
27
27
  export { default as GrainAlbumView } from './components/GrainAlbumView.svelte';
28
28
  export { default as StreamplacePicker } from './components/StreamplacePicker.svelte';
29
+ export { default as SembleCollectionPicker } from './components/SembleCollectionPicker.svelte';
30
+ export { default as SembleCollectionView } from './components/SembleCollectionView.svelte';
29
31
  export * from './grain.js';
32
+ export * from './semble.js';
30
33
  export * from './streamplace.js';
31
34
  export { default as InsetImage } from './components/InsetImage.svelte';
32
35
  export { default as Badge } from './components/Badge.svelte';
@@ -61,7 +64,8 @@ export { safeHttpUrl, safeLinkHref } from './urls.js';
61
64
  export { default as RichText } from './components/RichText.svelte';
62
65
  export { default as ExternalEmbed } from './components/ExternalEmbed.svelte';
63
66
  export { defaultExternalEmbedProviders, youtubeEmbedProvider, klipyEmbedProvider, resolveExternalEmbed } from './social/external-embeds.js';
64
- export { blueskyPostToPostData } from './social/posts.js';
67
+ export { blueskyPostToPostData, hasModerationLabel } from './social/posts.js';
68
+ export { parseSocialPostUrl, parseSocialProfileUrl } from './social/urls.js';
65
69
  export { editorJsonToBlueskyPost, textToDoc, graphemeLength } from './social/richtext.js';
66
70
  export { launchConfetti } from './confetti.js';
67
71
  export { cn } from './utils.js';
@@ -68,6 +68,15 @@ export declare function mentionHref(actor: unknown, options: RichTextLinkOptions
68
68
  export declare function tagHref(tag: unknown, options: RichTextLinkOptions): string | undefined;
69
69
  /** Validated destination of a link, mention or tag node; undefined for anything else. */
70
70
  export declare function inlineHref(node: unknown, options: RichTextLinkOptions): string | undefined;
71
+ export type ParagraphPart = {
72
+ children: Record<string, unknown>[];
73
+ embed?: string;
74
+ };
75
+ /**
76
+ * Split a paragraph into runs of lines, so that a bare link alone on its line can be shown as
77
+ * an embed. Labeled links and links inside a sentence stay ordinary links.
78
+ */
79
+ export declare function paragraphParts(children: unknown, isEmbed?: (url: string) => boolean): ParagraphPart[];
71
80
  /** Documents from the parser nest far less; deeper (tampered) nodes are cut off. */
72
81
  export declare const MAX_RENDER_DEPTH = 32;
73
82
  /** Text content of any node, including unknown ones. */
@@ -46,6 +46,41 @@ function nodes(value) {
46
46
  function string(value) {
47
47
  return typeof value === 'string' ? value : '';
48
48
  }
49
+ /**
50
+ * Split a paragraph into runs of lines, so that a bare link alone on its line can be shown as
51
+ * an embed. Labeled links and links inside a sentence stay ordinary links.
52
+ */
53
+ export function paragraphParts(children, isEmbed) {
54
+ const all = nodes(children);
55
+ if (!isEmbed)
56
+ return [{ children: all }];
57
+ const parts = [];
58
+ let text;
59
+ for (let start = 0; start <= all.length; start++) {
60
+ let end = start;
61
+ while (end < all.length && all[end].type !== 'break')
62
+ end++;
63
+ const line = all.slice(start, end);
64
+ const content = line.filter((node) => node.type !== 'text' || string(node.value).trim());
65
+ const link = content.length === 1 && content[0].type === 'link' ? content[0] : undefined;
66
+ const label = link && nodes(link.children);
67
+ const url = link && label?.length === 1 && label[0].type === 'text' && label[0].value === link.url
68
+ ? safeWebUrl(link.url)
69
+ : undefined;
70
+ if (url && isEmbed(url)) {
71
+ parts.push({ children: line, embed: url });
72
+ text = undefined;
73
+ }
74
+ else if (text) {
75
+ text.children.push({ type: 'break' }, ...line);
76
+ }
77
+ else if (line.length || end < all.length) {
78
+ parts.push((text = { children: line }));
79
+ }
80
+ start = end;
81
+ }
82
+ return parts;
83
+ }
49
84
  /** Documents from the parser nest far less; deeper (tampered) nodes are cut off. */
50
85
  export const MAX_RENDER_DEPTH = 32;
51
86
  /** Text content of any node, including unknown ones. */
@@ -11,7 +11,7 @@ export type RichTextParseOptions = PlainTextOptions & {
11
11
  };
12
12
  export declare function parseRichText(text: string, options?: RichTextParseOptions): RichTextDocument;
13
13
  export { parseMarkdown, parsePlainText };
14
- export { richTextToPlainText, safeWebUrl } from './richtext/document.js';
14
+ export { richTextToPlainText, safeWebUrl, paragraphParts } from './richtext/document.js';
15
15
  export type { RichTextDocument, RichTextBlock, RichTextInline, RichTextLinkOptions } from './richtext/document.js';
16
16
  export type { PlainTextOptions };
17
17
  export { detectTokens, type DetectedToken } from './richtext/detect.js';
package/dist/richtext.js CHANGED
@@ -8,5 +8,5 @@ export function parseRichText(text, options = {}) {
8
8
  return options.markdown ? parseMarkdown(text, options) : parsePlainText(text, options);
9
9
  }
10
10
  export { parseMarkdown, parsePlainText };
11
- export { richTextToPlainText, safeWebUrl } from './richtext/document.js';
11
+ export { richTextToPlainText, safeWebUrl, paragraphParts } from './richtext/document.js';
12
12
  export { detectTokens } from './richtext/detect.js';
@@ -0,0 +1,46 @@
1
+ export type SembleReference = {
2
+ actor: string;
3
+ rkey: string;
4
+ atUri: string;
5
+ url: string;
6
+ };
7
+ export type SembleActor = {
8
+ did: string;
9
+ handle: string;
10
+ displayName?: string;
11
+ };
12
+ export type SembleCollection = {
13
+ uri: string;
14
+ url: string;
15
+ name: string;
16
+ description?: string;
17
+ creator: SembleActor;
18
+ cardCount: number;
19
+ };
20
+ export type SembleCard = {
21
+ id: string;
22
+ url: string;
23
+ title: string;
24
+ /** Host name of `url`, or the page's own site name. */
25
+ site: string;
26
+ description?: string;
27
+ /** The page's own preview image, on any HTTPS host. */
28
+ image?: string;
29
+ note?: string;
30
+ /** Set when someone other than the collection's creator added the card. */
31
+ addedBy?: SembleActor;
32
+ };
33
+ /** A collection with its most recently updated cards; `cardCount` can exceed `cards.length`. */
34
+ export type SembleCollectionPage = SembleCollection & {
35
+ cards: SembleCard[];
36
+ };
37
+ export type SembleCollectionList = {
38
+ collections: SembleCollection[];
39
+ cursor?: string;
40
+ };
41
+ /** Normalized public reads. Implement with Semble's API, or another index of the same records. */
42
+ export type SembleClient = {
43
+ getCollection(reference: string): Promise<SembleCollectionPage>;
44
+ listCollections(actor: string, cursor?: string): Promise<SembleCollectionList>;
45
+ };
46
+ export type SembleSelection = (collection: SembleCollection) => void | string | Promise<void | string>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { SembleReference } from './types.js';
2
+ export declare function parseSembleLink(input: string): SembleReference | null;