@atmo-dev/kit 0.18.0 → 0.19.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 (114) hide show
  1. package/dist/articles/ArticleCard.svelte +97 -0
  2. package/dist/articles/ArticleCard.svelte.d.ts +20 -0
  3. package/dist/articles/ArticleCodeBlock.svelte +121 -0
  4. package/dist/articles/ArticleCodeBlock.svelte.d.ts +11 -0
  5. package/dist/articles/ArticleEditor.svelte +340 -0
  6. package/dist/articles/ArticleEditor.svelte.d.ts +48 -0
  7. package/dist/articles/ArticleLinkEmbed.svelte +50 -0
  8. package/dist/articles/ArticleLinkEmbed.svelte.d.ts +5 -0
  9. package/dist/articles/ArticleView.svelte +128 -0
  10. package/dist/articles/ArticleView.svelte.d.ts +46 -0
  11. package/dist/articles/PublicationIcon.svelte +37 -0
  12. package/dist/articles/PublicationIcon.svelte.d.ts +10 -0
  13. package/dist/articles/article-link-embed.d.ts +36 -0
  14. package/dist/articles/article-link-embed.js +29 -0
  15. package/dist/articles/dates.d.ts +2 -0
  16. package/dist/articles/dates.js +12 -0
  17. package/dist/articles/images.d.ts +5 -0
  18. package/dist/articles/images.js +44 -0
  19. package/dist/articles/markdown.d.ts +15 -0
  20. package/dist/articles/markdown.js +52 -0
  21. package/dist/articles/paste.d.ts +11 -0
  22. package/dist/articles/paste.js +27 -0
  23. package/dist/articles/records.d.ts +166 -0
  24. package/dist/articles/records.js +423 -0
  25. package/dist/articles/styles.d.ts +4 -0
  26. package/dist/articles/styles.js +14 -0
  27. package/dist/articles-data.d.ts +8 -0
  28. package/dist/articles-data.js +8 -0
  29. package/dist/articles.d.ts +10 -0
  30. package/dist/articles.js +8 -0
  31. package/dist/components/ExternalEmbed.svelte +16 -2
  32. package/dist/components/ExternalEmbed.svelte.d.ts +6 -0
  33. package/dist/components/IconMaker.svelte +119 -0
  34. package/dist/components/IconMaker.svelte.d.ts +9 -0
  35. package/dist/components/IconRail.svelte +9 -6
  36. package/dist/components/IconRail.svelte.d.ts +2 -0
  37. package/dist/components/LinkEmbed.svelte +24 -21
  38. package/dist/components/LinkEmbed.svelte.d.ts +3 -2
  39. package/dist/components/PaletteApply.svelte +62 -0
  40. package/dist/components/PaletteApply.svelte.d.ts +9 -0
  41. package/dist/components/PalettePicker.svelte +92 -0
  42. package/dist/components/PalettePicker.svelte.d.ts +13 -0
  43. package/dist/components/PostComments.svelte +129 -0
  44. package/dist/components/PostComments.svelte.d.ts +15 -0
  45. package/dist/components/RichText.svelte +199 -9
  46. package/dist/components/RichText.svelte.d.ts +17 -0
  47. package/dist/components/RichTextEditor.svelte +155 -13
  48. package/dist/components/RichTextEditor.svelte.d.ts +26 -3
  49. package/dist/components/composer/ComposerPost.svelte +20 -4
  50. package/dist/components/composer/ComposerPost.svelte.d.ts +3 -1
  51. package/dist/components/composer/PostComposer.svelte +29 -3
  52. package/dist/components/composer/PostComposer.svelte.d.ts +12 -1
  53. package/dist/editor/EditorMenus.svelte +438 -0
  54. package/dist/editor/EditorMenus.svelte.d.ts +9 -0
  55. package/dist/editor/SlashOptions.svelte +45 -0
  56. package/dist/editor/SlashOptions.svelte.d.ts +12 -0
  57. package/dist/editor/article-commands.d.ts +44 -0
  58. package/dist/editor/article-commands.js +289 -0
  59. package/dist/editor/article-extensions.d.ts +8 -0
  60. package/dist/editor/article-extensions.js +315 -0
  61. package/dist/editor/article-menus.d.ts +2 -0
  62. package/dist/editor/article-menus.js +3 -0
  63. package/dist/editor/document.d.ts +5 -0
  64. package/dist/editor/document.js +163 -12
  65. package/dist/editor/image-node.d.ts +8 -0
  66. package/dist/editor/image-node.js +75 -0
  67. package/dist/editor/markdown-extensions.d.ts +1 -5
  68. package/dist/editor/markdown-extensions.js +37 -2
  69. package/dist/editor/slash-menu.svelte.d.ts +9 -0
  70. package/dist/editor/slash-menu.svelte.js +134 -0
  71. package/dist/embeds/PlayerLinkEmbed.svelte +9 -1
  72. package/dist/embeds/PostLinkEmbed.svelte +12 -29
  73. package/dist/embeds/PostLinkEmbed.svelte.d.ts +3 -0
  74. package/dist/embeds/ProfileLinkEmbed.svelte +12 -17
  75. package/dist/embeds/ProfileLinkEmbed.svelte.d.ts +3 -0
  76. package/dist/embeds/defaults.d.ts +4 -2
  77. package/dist/embeds/defaults.js +7 -3
  78. package/dist/embeds/load.d.ts +44 -0
  79. package/dist/embeds/load.js +139 -0
  80. package/dist/embeds/types.d.ts +18 -3
  81. package/dist/events/EventComments.svelte +4 -101
  82. package/dist/events/EventComments.svelte.d.ts +1 -1
  83. package/dist/events/EventView.svelte +5 -0
  84. package/dist/events/EventView.svelte.d.ts +3 -0
  85. package/dist/events/event-link-embed.d.ts +4 -1
  86. package/dist/events/event-link-embed.js +9 -1
  87. package/dist/events/event-view/EventLinkEmbed.svelte +8 -8
  88. package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -2
  89. package/dist/icon-maker/artwork.d.ts +11 -0
  90. package/dist/icon-maker/artwork.js +25 -0
  91. package/dist/icon-maker/index.d.ts +12 -0
  92. package/dist/icon-maker/index.js +73 -0
  93. package/dist/index.d.ts +10 -3
  94. package/dist/index.js +7 -1
  95. package/dist/palettes.d.ts +20 -0
  96. package/dist/palettes.js +37 -0
  97. package/dist/richtext/article-styles.d.ts +10 -0
  98. package/dist/richtext/article-styles.js +28 -0
  99. package/dist/richtext/document.d.ts +63 -1
  100. package/dist/richtext/document.js +54 -0
  101. package/dist/richtext/markdown.d.ts +19 -4
  102. package/dist/richtext/markdown.js +223 -18
  103. package/dist/richtext/serialize.d.ts +5 -1
  104. package/dist/richtext/serialize.js +163 -31
  105. package/dist/richtext/vendor/markdown-tree.d.ts +4 -3
  106. package/dist/richtext/vendor/markdown-tree.js +2584 -26
  107. package/dist/richtext.d.ts +7 -5
  108. package/dist/richtext.js +1 -1
  109. package/dist/social/external-embeds.d.ts +5 -0
  110. package/dist/social/external-embeds.js +6 -1
  111. package/dist/social/posts.d.ts +2 -0
  112. package/dist/social/posts.js +43 -2
  113. package/dist/social/profile.js +2 -1
  114. package/package.json +28 -2
@@ -2,41 +2,36 @@
2
2
  import type { Snippet } from 'svelte';
3
3
  import Avatar from '../components/Avatar.svelte';
4
4
  import Surface from '../components/Surface.svelte';
5
- import { blueskyProfileToProfileData, type ProfileData } from '../social/profile.js';
5
+ import type { ProfileData } from '../social/profile.js';
6
6
  import type { PreferredSocialClient } from '../social/preferred-client.js';
7
7
  import { parseSocialProfileUrl, socialProfileUrl } from '../social/urls.js';
8
8
  import { focus } from '../styles.js';
9
- import { appviewUrl } from '../events/atproto-helpers.js';
9
+ import { loadProfileEmbed } from './load.js';
10
10
 
11
11
  let {
12
12
  url,
13
+ data,
13
14
  fallback,
14
15
  socialClient
15
16
  }: {
16
17
  url: string;
18
+ /** The profile, when it was loaded ahead; `null` when there is none to show. */
19
+ data?: ProfileData | null;
17
20
  /** The ordinary link, shown until the profile loads and whenever it can't be shown. */
18
21
  fallback: Snippet;
19
22
  socialClient?: PreferredSocialClient | null;
20
23
  } = $props();
21
24
 
22
- let profile = $state<ProfileData | null>(null);
25
+ let found = $state<{ url: string; profile: ProfileData | null }>();
26
+ let profile = $derived(data !== undefined ? data : found?.url === url ? found.profile : null);
23
27
  $effect(() => {
24
- const ref = parseSocialProfileUrl(url);
25
- profile = null;
28
+ const ref = data === undefined ? parseSocialProfileUrl(url) : null;
26
29
  if (!ref) return;
30
+ const link = url;
27
31
  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;
32
+ loadProfileEmbed(ref, { signal: controller.signal })
33
+ .then((loaded) => {
34
+ if (!controller.signal.aborted) found = { url: link, profile: loaded };
40
35
  })
41
36
  .catch(() => {});
42
37
  return () => controller.abort();
@@ -1,7 +1,10 @@
1
1
  import type { Snippet } from 'svelte';
2
+ import type { ProfileData } from '../social/profile.js';
2
3
  import type { PreferredSocialClient } from '../social/preferred-client.js';
3
4
  type $$ComponentProps = {
4
5
  url: string;
6
+ /** The profile, when it was loaded ahead; `null` when there is none to show. */
7
+ data?: ProfileData | null;
5
8
  /** The ordinary link, shown until the profile loads and whenever it can't be shown. */
6
9
  fallback: Snippet;
7
10
  socialClient?: PreferredSocialClient | null;
@@ -1,15 +1,17 @@
1
1
  import { type ExternalEmbedProvider } from '../social/external-embeds.js';
2
+ import type { PostData } from '../social/posts.js';
3
+ import type { ProfileData } from '../social/profile.js';
2
4
  import type { LinkEmbed } from './types.js';
3
5
  /** A post on Bluesky or another listed client, shown as the post itself. */
4
6
  export declare const postLinkEmbed: LinkEmbed<{
5
7
  actor: string;
6
8
  rkey: string;
7
9
  uri: string;
8
- }>;
10
+ }, PostData>;
9
11
  /** A profile on Bluesky or another listed client, shown as a small profile card. */
10
12
  export declare const profileLinkEmbed: LinkEmbed<{
11
13
  actor: string;
12
- }>;
14
+ }, ProfileData>;
13
15
  /**
14
16
  * Show links a media provider recognizes in the kit's player. Iframe players wait for their
15
17
  * play button, so pass `requests: 'click'` for them.
@@ -1,19 +1,23 @@
1
1
  import { klipyEmbedProvider, youtubeEmbedProvider } from '../social/external-embeds.js';
2
2
  import { parseSocialPostUrl, parseSocialProfileUrl } from '../social/urls.js';
3
+ import { loadPostEmbed, loadProfileEmbed } from './load.js';
3
4
  /** A post on Bluesky or another listed client, shown as the post itself. */
4
5
  export const postLinkEmbed = {
5
6
  id: 'post',
6
7
  label: 'post',
7
8
  match: (url) => parseSocialPostUrl(url.href),
8
- load: () => import('./PostLinkEmbed.svelte')
9
+ load: () => import('./PostLinkEmbed.svelte'),
10
+ data: loadPostEmbed
9
11
  };
10
12
  /** A profile on Bluesky or another listed client, shown as a small profile card. */
11
13
  export const profileLinkEmbed = {
12
14
  id: 'profile',
13
15
  label: 'profile',
14
16
  match: (url) => parseSocialProfileUrl(url.href),
15
- load: () => import('./ProfileLinkEmbed.svelte')
17
+ load: () => import('./ProfileLinkEmbed.svelte'),
18
+ data: loadProfileEmbed
16
19
  };
20
+ const loadPlayer = () => import('./PlayerLinkEmbed.svelte');
17
21
  /**
18
22
  * Show links a media provider recognizes in the kit's player. Iframe players wait for their
19
23
  * play button, so pass `requests: 'click'` for them.
@@ -23,7 +27,7 @@ export function playerLinkEmbed(provider, requests = 'mount') {
23
27
  id: provider.id,
24
28
  label: provider.label,
25
29
  match: (url) => provider.resolve(url, { type: 'external', uri: url.href, title: '' }) ? { provider } : null,
26
- load: () => import('./PlayerLinkEmbed.svelte'),
30
+ load: loadPlayer,
27
31
  requests
28
32
  };
29
33
  }
@@ -0,0 +1,44 @@
1
+ import { type PostData } from '../social/posts.js';
2
+ import { type ProfileData } from '../social/profile.js';
3
+ import { type RichTextDocument } from '../richtext/document.js';
4
+ import type { LinkEmbed, LinkEmbedLoadOptions, LinkEmbedOptions, LinkEmbedProps } from './types.js';
5
+ import type { Component } from 'svelte';
6
+ /** A public post from the AppView; null when it is missing, hidden or labeled. */
7
+ export declare function loadPostEmbed(ref: {
8
+ uri: string;
9
+ }, options?: LinkEmbedLoadOptions): Promise<PostData | null>;
10
+ /** A public profile from the AppView; null when it is missing, hidden or labeled. */
11
+ export declare function loadProfileEmbed(ref: {
12
+ actor: string;
13
+ }, options?: LinkEmbedLoadOptions): Promise<ProfileData | null>;
14
+ /** The component of an embed, when it has been loaded already. */
15
+ export declare function loadedLinkEmbed(embed: LinkEmbed): Component<LinkEmbedProps> | undefined;
16
+ export declare function loadLinkEmbed(embed: LinkEmbed): Promise<Component<LinkEmbedProps>>;
17
+ /** What was loaded ahead for the embeds of a text, by link. `null`: there is nothing to show. */
18
+ export type LinkEmbedData = Record<string, unknown>;
19
+ /** The links of a document that `RichText` shows as embeds, in order and once each. */
20
+ export declare function linkEmbedUrls(document: RichTextDocument | null | undefined, embeds: readonly LinkEmbed[]): string[];
21
+ /**
22
+ * Load, on the server, what the embeds of a document show, to pass to `RichText` as
23
+ * `embedData`: the embeds are then part of the page instead of appearing after it and moving
24
+ * the text below. An embed that cannot say in time is left out, and loads in the browser.
25
+ *
26
+ * Nothing is loaded for an embed that waits for a click: one with `requests: 'click'`, or any
27
+ * the app puts behind a load button. Pass the same `clickToLoad` as to `setLinkEmbeds`.
28
+ */
29
+ export declare function loadLinkEmbedData(document: RichTextDocument | null | undefined, embeds: readonly LinkEmbed[], options?: {
30
+ /** The request's `fetch`. */
31
+ fetch?: typeof fetch;
32
+ /** How long to wait for all of them, in milliseconds. Defaults to 1500. */
33
+ timeout?: number;
34
+ /** Embeds beyond this many load in the browser. Defaults to 20. */
35
+ limit?: number;
36
+ /** The app's setting: embeds behind a load button are loaded by that button. */
37
+ clickToLoad?: LinkEmbedOptions['clickToLoad'];
38
+ }): Promise<LinkEmbedData>;
39
+ /**
40
+ * Load the components of a document's embeds before the page is drawn, so that they are there
41
+ * from the first paint. Call it in a universal `load`, which runs on the server and in the
42
+ * browser.
43
+ */
44
+ export declare function preloadLinkEmbeds(document: RichTextDocument | null | undefined, embeds: readonly LinkEmbed[]): Promise<void>;
@@ -0,0 +1,139 @@
1
+ import { appviewUrl } from '../events/atproto-helpers.js';
2
+ import { blueskyPostToPostData, hasModerationLabel } from '../social/posts.js';
3
+ import { blueskyProfileToProfileData } from '../social/profile.js';
4
+ import { paragraphParts, plainTextParts, MAX_RENDER_DEPTH } from '../richtext/document.js';
5
+ import { isClickToLoad, resolveLinkEmbed } from './resolve.js';
6
+ /** A public post from the AppView; null when it is missing, hidden or labeled. */
7
+ export async function loadPostEmbed(ref, options = {}) {
8
+ const response = await (options.fetch ?? fetch)(`${appviewUrl()}/xrpc/app.bsky.feed.getPostThread?uri=${encodeURIComponent(ref.uri)}&depth=0&parentHeight=0`, { signal: options.signal });
9
+ // Missing posts answer 400; anything else may work later.
10
+ if (!response.ok) {
11
+ if (response.status === 400 || response.status === 404)
12
+ return null;
13
+ throw new Error('Could not load the post.');
14
+ }
15
+ const data = (await response.json());
16
+ const view = data?.thread?.post;
17
+ if (data?.thread?.$type !== 'app.bsky.feed.defs#threadViewPost' ||
18
+ !view?.uri ||
19
+ !view.author?.did ||
20
+ hasModerationLabel(view))
21
+ return null;
22
+ return blueskyPostToPostData(view);
23
+ }
24
+ /** A public profile from the AppView; null when it is missing, hidden or labeled. */
25
+ export async function loadProfileEmbed(ref, options = {}) {
26
+ const response = await (options.fetch ?? fetch)(`${appviewUrl()}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(ref.actor)}`, { signal: options.signal });
27
+ if (!response.ok) {
28
+ if (response.status === 400 || response.status === 404)
29
+ return null;
30
+ throw new Error('Could not load the profile.');
31
+ }
32
+ const view = (await response.json());
33
+ // The same rule as for posts: a label an account gives itself that is not about moderation,
34
+ // such as `bot`, hides nothing.
35
+ if (hasModerationLabel({ labels: view?.labels }))
36
+ return null;
37
+ return blueskyProfileToProfileData(view) ?? null;
38
+ }
39
+ // Loaded components are kept, so later embeds of the same kind render without a flash. Kept by
40
+ // the `load` function: embeds made anew for each page (`eventLinkEmbed({ … })`) share theirs.
41
+ const components = new WeakMap();
42
+ /** The component of an embed, when it has been loaded already. */
43
+ export function loadedLinkEmbed(embed) {
44
+ return components.get(embed.load);
45
+ }
46
+ export async function loadLinkEmbed(embed) {
47
+ const known = components.get(embed.load);
48
+ if (known)
49
+ return known;
50
+ const component = (await embed.load()).default;
51
+ components.set(embed.load, component);
52
+ return component;
53
+ }
54
+ /** The links of a document that `RichText` shows as embeds, in order and once each. */
55
+ export function linkEmbedUrls(document, embeds) {
56
+ const urls = new Set();
57
+ const isEmbed = (url) => !!resolveLinkEmbed(url, embeds);
58
+ const add = (parts) => {
59
+ for (const part of parts)
60
+ if (part.embed)
61
+ urls.add(part.embed);
62
+ };
63
+ const walk = (value, depth) => {
64
+ if (depth > MAX_RENDER_DEPTH || value === null || typeof value !== 'object')
65
+ return;
66
+ if (Array.isArray(value))
67
+ return value.forEach((item) => walk(item, depth + 1));
68
+ const node = value;
69
+ if (node.type === 'paragraph')
70
+ return add(paragraphParts(node.children, isEmbed));
71
+ walk(node.children, depth + 1);
72
+ walk(node.items, depth + 1);
73
+ };
74
+ if (document?.markdown)
75
+ walk(document.children, 0);
76
+ else
77
+ add(plainTextParts(document, isEmbed));
78
+ return [...urls];
79
+ }
80
+ /**
81
+ * Load, on the server, what the embeds of a document show, to pass to `RichText` as
82
+ * `embedData`: the embeds are then part of the page instead of appearing after it and moving
83
+ * the text below. An embed that cannot say in time is left out, and loads in the browser.
84
+ *
85
+ * Nothing is loaded for an embed that waits for a click: one with `requests: 'click'`, or any
86
+ * the app puts behind a load button. Pass the same `clickToLoad` as to `setLinkEmbeds`.
87
+ */
88
+ export async function loadLinkEmbedData(document, embeds, options = {}) {
89
+ const data = {};
90
+ const wanted = linkEmbedUrls(document, embeds).flatMap((url) => {
91
+ const match = resolveLinkEmbed(url, embeds);
92
+ const load = match?.embed.data;
93
+ return match &&
94
+ load &&
95
+ match.embed.requests !== 'click' &&
96
+ !isClickToLoad(match.embed, options.clickToLoad)
97
+ ? [{ url, load, ref: match.ref }]
98
+ : [];
99
+ });
100
+ if (!wanted.length)
101
+ return data;
102
+ const controller = new AbortController();
103
+ const timer = setTimeout(() => controller.abort(), options.timeout ?? 1500);
104
+ const expired = new Promise((resolve) => controller.signal.addEventListener('abort', () => resolve()));
105
+ try {
106
+ await Promise.race([
107
+ expired,
108
+ Promise.all(wanted.slice(0, options.limit ?? 20).map(async ({ url, load, ref }) => {
109
+ try {
110
+ const loaded = await load(ref, { fetch: options.fetch, signal: controller.signal });
111
+ if (!controller.signal.aborted)
112
+ data[url] = loaded ?? null;
113
+ }
114
+ catch {
115
+ // Left to the browser.
116
+ }
117
+ }))
118
+ ]);
119
+ }
120
+ finally {
121
+ clearTimeout(timer);
122
+ controller.abort();
123
+ }
124
+ return { ...data };
125
+ }
126
+ /**
127
+ * Load the components of a document's embeds before the page is drawn, so that they are there
128
+ * from the first paint. Call it in a universal `load`, which runs on the server and in the
129
+ * browser.
130
+ */
131
+ export async function preloadLinkEmbeds(document, embeds) {
132
+ const used = new Map();
133
+ for (const url of linkEmbedUrls(document, embeds)) {
134
+ const match = resolveLinkEmbed(url, embeds);
135
+ if (match)
136
+ used.set(match.embed.load, match.embed);
137
+ }
138
+ await Promise.all([...used.values()].map((embed) => loadLinkEmbed(embed).catch(() => { })));
139
+ }
@@ -1,9 +1,14 @@
1
1
  import type { Component, Snippet } from 'svelte';
2
2
  import type { PreferredSocialClient } from '../social/preferred-client.js';
3
- export type LinkEmbedProps<Ref = unknown> = {
3
+ export type LinkEmbedProps<Ref = unknown, Data = unknown> = {
4
4
  url: string;
5
5
  /** What `match` extracted from the link. */
6
6
  ref: Ref;
7
+ /**
8
+ * What the embed's `data` loaded ahead, e.g. on the server: show it right away instead of
9
+ * loading. `null` means there is nothing to show; `undefined` that nothing was loaded.
10
+ */
11
+ data?: Data | null;
7
12
  /** The ordinary link. Render it until the content has loaded and whenever it can't be shown. */
8
13
  fallback: Snippet;
9
14
  socialClient?: PreferredSocialClient | null;
@@ -12,7 +17,11 @@ export type LinkEmbedProps<Ref = unknown> = {
12
17
  * A richer rendering for links to a particular kind of page or record. Matching uses the URL
13
18
  * alone and performs no network IO, so it is safe on the server and for untrusted text.
14
19
  */
15
- export type LinkEmbed<Ref = any> = {
20
+ export type LinkEmbedLoadOptions = {
21
+ fetch?: typeof fetch;
22
+ signal?: AbortSignal;
23
+ };
24
+ export type LinkEmbed<Ref = any, Data = any> = {
16
25
  id: string;
17
26
  /** Names the content in a load button, e.g. "Bluesky post". */
18
27
  label: string;
@@ -20,8 +29,14 @@ export type LinkEmbed<Ref = any> = {
20
29
  match: (url: URL) => Ref | null;
21
30
  /** Loaded on first use, so an embed costs nothing until one is on screen. */
22
31
  load: () => Promise<{
23
- default: Component<LinkEmbedProps<Ref>>;
32
+ default: Component<LinkEmbedProps<Ref, Data>>;
24
33
  }>;
34
+ /**
35
+ * What the component shows, as plain data that can be sent with a page. With it, a server
36
+ * can load an embed ahead (`loadLinkEmbedData`) so that it does not appear after the page.
37
+ * Resolve to `null` when there is nothing to show; throw when it could not be found out.
38
+ */
39
+ data?: (ref: Ref, options: LinkEmbedLoadOptions) => Promise<Data | null>;
25
40
  /**
26
41
  * When the embed contacts other servers: as soon as it is shown (the default), or only
27
42
  * after its own play or load button is clicked, as video players do.
@@ -1,14 +1,8 @@
1
1
  <script lang="ts">
2
- import {
3
- NestedComments,
4
- blueskyPostToPostData,
5
- hasModerationLabel,
6
- type PostData
7
- } from '../index.js';
8
- import { appviewUrl } from './atproto-helpers.js';
9
-
10
- import { socialClientInfo, socialPostUrl, type PreferredSocialClient } from '../social.js';
2
+ import PostComments from '../components/PostComments.svelte';
3
+ import type { PreferredSocialClient } from '../social.js';
11
4
 
5
+ // An event's comments are the replies to the post announcing it.
12
6
  let {
13
7
  postUri,
14
8
  socialClient
@@ -16,97 +10,6 @@
16
10
  postUri: string;
17
11
  socialClient?: PreferredSocialClient | null;
18
12
  } = $props();
19
-
20
- let comments = $state<PostData[]>([]);
21
- let loading = $state(true);
22
- let errorMessage = $state<string | null>(null);
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
- */
29
- const DEPTH = 6;
30
- function threadToComments(replies: unknown[], level = 1): PostData[] {
31
- return (replies as Array<{ $type?: string; post?: unknown; replies?: unknown[] }>)
32
- .filter(
33
- (r) =>
34
- r.$type === 'app.bsky.feed.defs#threadViewPost' && r.post && !hasModerationLabel(r.post)
35
- )
36
- .map((r) => {
37
- const postData = blueskyPostToPostData(
38
- r.post as Parameters<typeof blueskyPostToPostData>[0]
39
- );
40
- // Below the requested depth nothing was loaded; the comment links to the rest instead.
41
- if (level < DEPTH) postData.replies = threadToComments(r.replies ?? [], level + 1);
42
- return postData;
43
- });
44
- }
45
-
46
- async function loadThread(uri: string, signal: AbortSignal) {
47
- loading = true;
48
- errorMessage = null;
49
- try {
50
- const res = await fetch(
51
- `${appviewUrl()}/xrpc/app.bsky.feed.getPostThread?uri=${encodeURIComponent(uri)}&depth=${DEPTH}`,
52
- { signal }
53
- );
54
- if (!res.ok) throw new Error(`Failed to load thread (${res.status})`);
55
- const data = (await res.json()) as { thread?: { replies?: unknown[] } };
56
- const thread = data.thread;
57
- if (!signal.aborted)
58
- comments = thread?.replies?.length ? threadToComments(thread.replies) : [];
59
- } catch (err) {
60
- if (signal.aborted) return;
61
- console.error('EventComments: load failed', err);
62
- errorMessage = err instanceof Error ? err.message : 'Failed to load comments';
63
- comments = [];
64
- } finally {
65
- if (!signal.aborted) loading = false;
66
- }
67
- }
68
-
69
- // Only a new thread URI should refetch; changing the viewer's client just changes links.
70
- let threadUri = $derived(postUri);
71
- $effect(() => {
72
- const controller = new AbortController();
73
- if (threadUri) loadThread(threadUri, controller.signal);
74
- return () => controller.abort();
75
- });
76
-
77
- let replyUrl = $derived(socialPostUrl(postUri, socialClient));
78
- let clientLabel = $derived(socialClientInfo(socialClient).label);
79
13
  </script>
80
14
 
81
- <div>
82
- {#if replyUrl}
83
- <div class="mb-4 text-sm">
84
- <a
85
- href={replyUrl}
86
- target="_blank"
87
- rel="noopener noreferrer"
88
- class="font-medium text-accent-600 hover:text-accent-700 dark:text-accent-400 dark:hover:text-accent-300"
89
- >
90
- Add a comment on {clientLabel} &rarr;
91
- </a>
92
- </div>
93
- {/if}
94
-
95
- {#if loading}
96
- <p class="text-sm text-base-600 dark:text-base-400">Loading comments…</p>
97
- {:else if errorMessage}
98
- <p class="text-sm text-base-600 dark:text-base-400">{errorMessage}</p>
99
- {:else if comments.length === 0}
100
- <p class="text-sm text-base-600 dark:text-base-400">No comments yet.</p>
101
- {:else}
102
- <div class="not-prose comments-no-divider">
103
- <NestedComments {comments} {socialClient} />
104
- </div>
105
- {/if}
106
- </div>
107
-
108
- <style>
109
- .comments-no-divider :global(> div) {
110
- border-top-width: 0;
111
- }
112
- </style>
15
+ <PostComments {postUri} {socialClient} />
@@ -1,4 +1,4 @@
1
- import { type PreferredSocialClient } from '../social.js';
1
+ import type { PreferredSocialClient } from '../social.js';
2
2
  type $$ComponentProps = {
3
3
  postUri: string;
4
4
  socialClient?: PreferredSocialClient | null;
@@ -49,6 +49,7 @@
49
49
  extraActions,
50
50
  attendeeActions,
51
51
  loadAttendees,
52
+ embedData,
52
53
  mediaUrl = getCDNImageBlobUrl
53
54
  }: {
54
55
  data: EventViewData;
@@ -71,6 +72,9 @@
71
72
  /** Fetches the complete attendee lists the first time one is opened, when
72
73
  * `data.attendees` holds only a sample of the counted RSVPs. */
73
74
  loadAttendees?: AttendeeListLoader;
75
+ /** What `loadLinkEmbedData` loaded for the description's embeds, so that they are shown
76
+ * with the page instead of appearing after it. */
77
+ embedData?: Record<string, unknown>;
74
78
  /** Where the page loads the event's own images from; the public CDN by default. */
75
79
  mediaUrl?: EventMediaUrl;
76
80
  } = $props();
@@ -488,6 +492,7 @@
488
492
  detectLinks
489
493
  headingOffset={1}
490
494
  embeds={descriptionEmbeds}
495
+ {embedData}
491
496
  class="text-base-700 dark:text-base-300"
492
497
  />
493
498
  {:else if activeTab === 'comments' && eventData.bskyPostRef?.uri}
@@ -25,6 +25,9 @@ type $$ComponentProps = {
25
25
  /** Fetches the complete attendee lists the first time one is opened, when
26
26
  * `data.attendees` holds only a sample of the counted RSVPs. */
27
27
  loadAttendees?: AttendeeListLoader;
28
+ /** What `loadLinkEmbedData` loaded for the description's embeds, so that they are shown
29
+ * with the page instead of appearing after it. */
30
+ embedData?: Record<string, unknown>;
28
31
  /** Where the page loads the event's own images from; the public CDN by default. */
29
32
  mediaUrl?: EventMediaUrl;
30
33
  };
@@ -1,4 +1,5 @@
1
1
  import type { LinkEmbed } from '../embeds/types.js';
2
+ import type { FlatEventRecord } from './contrail.js';
2
3
  import { type LinkedRecordsClient } from './linked-records.js';
3
4
  export type EventLinkEmbedRef = {
4
5
  actor: string;
@@ -7,6 +8,8 @@ export type EventLinkEmbedRef = {
7
8
  local: boolean;
8
9
  loadEvent: NonNullable<LinkedRecordsClient['getEvent']>;
9
10
  };
11
+ /** The event a link points to; null when there is none to show. */
12
+ export declare function loadLinkedEvent(ref: EventLinkEmbedRef): Promise<FlatEventRecord | null>;
10
13
  /** Links to event pages on the given origins, shown as event cards. */
11
14
  export declare function eventLinkEmbed(options: {
12
15
  loadEvent: NonNullable<LinkedRecordsClient['getEvent']>;
@@ -19,4 +22,4 @@ export declare function eventLinkEmbed(options: {
19
22
  actor: string;
20
23
  rkey: string;
21
24
  }) => boolean;
22
- }): LinkEmbed<EventLinkEmbedRef>;
25
+ }): LinkEmbed<EventLinkEmbedRef, FlatEventRecord>;
@@ -1,4 +1,11 @@
1
1
  import { parseEventLink } from './linked-records.js';
2
+ /** The event a link points to; null when there is none to show. */
3
+ export async function loadLinkedEvent(ref) {
4
+ const result = await ref.loadEvent(ref.actor, ref.rkey);
5
+ return result?.rkey === ref.rkey && result.startsAt ? result : null;
6
+ }
7
+ // One function for every such embed, so that its component is loaded once.
8
+ const load = () => import('./event-view/EventLinkEmbed.svelte');
2
9
  /** Links to event pages on the given origins, shown as event cards. */
3
10
  export function eventLinkEmbed(options) {
4
11
  return {
@@ -10,6 +17,7 @@ export function eventLinkEmbed(options) {
10
17
  ? { ...link, local: !!options.local, loadEvent: options.loadEvent }
11
18
  : null;
12
19
  },
13
- load: () => import('./event-view/EventLinkEmbed.svelte')
20
+ load,
21
+ data: loadLinkedEvent
14
22
  };
15
23
  }
@@ -3,19 +3,19 @@
3
3
  import type { LinkEmbedProps } from '../../embeds/types.js';
4
4
  import EventCard from '../EventCard.svelte';
5
5
  import type { FlatEventRecord } from '../contrail.js';
6
- import type { EventLinkEmbedRef } from '../event-link-embed.js';
6
+ import { loadLinkedEvent, type EventLinkEmbedRef } from '../event-link-embed.js';
7
7
 
8
- let { url, ref, fallback }: LinkEmbedProps<EventLinkEmbedRef> = $props();
8
+ let { url, ref, data, fallback }: LinkEmbedProps<EventLinkEmbedRef, FlatEventRecord> = $props();
9
9
 
10
- let event = $state<FlatEventRecord | null>(null);
10
+ let found = $state<{ url: string; event: FlatEventRecord | null }>();
11
+ let event = $derived(data !== undefined ? data : found?.url === url ? found.event : null);
11
12
  $effect(() => {
12
- const { actor, rkey, loadEvent } = ref;
13
+ if (data !== undefined) return;
14
+ const link = url;
13
15
  let current = true;
14
- event = null;
15
- void Promise.resolve()
16
- .then(() => loadEvent(actor, rkey))
16
+ void loadLinkedEvent(ref)
17
17
  .then((result) => {
18
- if (current && result?.rkey === rkey && result.startsAt) event = result;
18
+ if (current) found = { url: link, event: result };
19
19
  })
20
20
  .catch(() => {});
21
21
  return () => {
@@ -1,5 +1,6 @@
1
1
  import type { LinkEmbedProps } from '../../embeds/types.js';
2
- import type { EventLinkEmbedRef } from '../event-link-embed.js';
3
- declare const EventLinkEmbed: import("svelte").Component<LinkEmbedProps<EventLinkEmbedRef>, {}, "">;
2
+ import type { FlatEventRecord } from '../contrail.js';
3
+ import { type EventLinkEmbedRef } from '../event-link-embed.js';
4
+ declare const EventLinkEmbed: import("svelte").Component<LinkEmbedProps<EventLinkEmbedRef, FlatEventRecord>, {}, "">;
4
5
  type EventLinkEmbed = ReturnType<typeof EventLinkEmbed>;
5
6
  export default EventLinkEmbed;
@@ -0,0 +1,11 @@
1
+ import type { IconNode } from '@sketchyicons/svelte';
2
+ export type MakerIcon = {
3
+ /** Its export name in `@sketchyicons/svelte`. */
4
+ name: string;
5
+ /** "Alarm clock check". */
6
+ label: string;
7
+ /** Everything it can be found by, lower case. */
8
+ terms: string;
9
+ node: IconNode;
10
+ };
11
+ export declare const icons: MakerIcon[];
@@ -0,0 +1,25 @@
1
+ // Kept behind a dynamic import: the complete artwork loads only when the picker opens.
2
+ import * as collection from '@sketchyicons/svelte';
3
+ const words = (name) => name
4
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
5
+ .replace(/([A-Za-z])([0-9])/g, '$1 $2')
6
+ .toLowerCase();
7
+ // Some icons are exported under several names; each is listed once and found by all of them.
8
+ const byNode = new Map();
9
+ for (const [name, value] of Object.entries(collection)) {
10
+ if (!Array.isArray(value))
11
+ continue;
12
+ const node = value;
13
+ byNode.set(node, [...(byNode.get(node) ?? []), name]);
14
+ }
15
+ export const icons = [...byNode].map(([node, names]) => {
16
+ // The longest name is the canonical one; the others are older, shorter aliases.
17
+ const name = names.reduce((a, b) => (b.length > a.length ? b : a));
18
+ const label = words(name);
19
+ return {
20
+ name,
21
+ label: label[0].toUpperCase() + label.slice(1),
22
+ terms: names.map((alias) => `${alias.toLowerCase()} ${words(alias)}`).join(' '),
23
+ node
24
+ };
25
+ });
@@ -0,0 +1,12 @@
1
+ import type { IconNode } from '@sketchyicons/svelte';
2
+ import type { MakerIcon } from './artwork.js';
3
+ export type { MakerIcon };
4
+ /** Every icon, loaded once on first use. */
5
+ export declare function loadMakerIcons(): Promise<MakerIcon[]>;
6
+ export declare function matchingIcons(icons: readonly MakerIcon[], query: string, limit: number): MakerIcon[];
7
+ /** Tailwind's 500 shades, as plain colors: the icon is an image, shown outside the app too. */
8
+ export declare const iconColors: readonly [readonly ["Red", "#fb2c36"], readonly ["Orange", "#ff6900"], readonly ["Amber", "#fe9a00"], readonly ["Yellow", "#f0b100"], readonly ["Lime", "#7ccf00"], readonly ["Green", "#00c950"], readonly ["Emerald", "#00bc7d"], readonly ["Teal", "#00bba7"], readonly ["Cyan", "#00b8db"], readonly ["Sky", "#00a6f4"], readonly ["Blue", "#2b7fff"], readonly ["Indigo", "#615fff"], readonly ["Violet", "#8e51ff"], readonly ["Purple", "#ad46ff"], readonly ["Fuchsia", "#e12afb"], readonly ["Pink", "#f6339a"], readonly ["Rose", "#ff2056"]];
9
+ /** A square of the color with the icon drawn on it in white, as SVG. */
10
+ export declare function iconSvg(color: string, icon?: IconNode): string;
11
+ /** The same as a 512×512 PNG. Browser only. */
12
+ export declare function iconPng(color: string, icon?: IconNode): Promise<Blob>;