@atmo-dev/kit 0.18.1 → 0.19.1

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 (115) 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 +164 -13
  48. package/dist/components/RichTextEditor.svelte.d.ts +26 -3
  49. package/dist/components/composer/ComposerPost.svelte +10 -0
  50. package/dist/components/composer/ComposerPost.svelte.d.ts +3 -1
  51. package/dist/components/composer/PostComposer.svelte +28 -2
  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/mention-suggestions.svelte.js +18 -7
  112. package/dist/social/posts.d.ts +2 -0
  113. package/dist/social/posts.js +43 -2
  114. package/dist/social/profile.js +2 -1
  115. package/package.json +28 -2
@@ -0,0 +1,75 @@
1
+ import { Node } from '@tiptap/core';
2
+ import { IMAGE } from './document.js';
3
+ /** An image on its own line, written to Markdown as `![alt](url)`. */
4
+ export const ImageNode = Node.create({
5
+ name: IMAGE,
6
+ group: 'block',
7
+ atom: true,
8
+ selectable: true,
9
+ draggable: true,
10
+ addOptions: () => ({ src: () => undefined, altLabel: 'Alt text' }),
11
+ addAttributes: () => ({ url: { default: '' }, alt: { default: '' }, title: { default: '' } }),
12
+ parseHTML: () => [{ tag: 'div[data-image]' }],
13
+ renderHTML: ({ node }) => ['div', { 'data-image': '' }, node.attrs.alt || ''],
14
+ renderText: ({ node }) => node.attrs.alt || '',
15
+ addNodeView() {
16
+ return ({ node, editor, getPos }) => {
17
+ let current = node;
18
+ const dom = document.createElement('div');
19
+ dom.dataset.image = '';
20
+ dom.contentEditable = 'false';
21
+ const img = document.createElement('img');
22
+ img.draggable = false;
23
+ const input = document.createElement('input');
24
+ input.type = 'text';
25
+ input.placeholder = this.options.altLabel;
26
+ input.setAttribute('aria-label', this.options.altLabel);
27
+ dom.append(img, input);
28
+ const show = () => {
29
+ const src = this.options.src(current.attrs.url) ?? '';
30
+ if (img.getAttribute('src') !== src)
31
+ img.setAttribute('src', src);
32
+ img.alt = current.attrs.alt || '';
33
+ if (current.attrs.title)
34
+ img.title = current.attrs.title;
35
+ else
36
+ img.removeAttribute('title');
37
+ if (document.activeElement !== input)
38
+ input.value = current.attrs.alt || '';
39
+ input.readOnly = !editor.isEditable;
40
+ };
41
+ show();
42
+ input.addEventListener('input', () => {
43
+ const pos = getPos();
44
+ if (typeof pos !== 'number' || !editor.isEditable)
45
+ return;
46
+ editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...current.attrs, alt: input.value }));
47
+ });
48
+ input.addEventListener('keydown', (event) => {
49
+ if (event.key !== 'Enter' && event.key !== 'Escape')
50
+ return;
51
+ event.preventDefault();
52
+ const pos = getPos();
53
+ if (typeof pos === 'number')
54
+ editor
55
+ .chain()
56
+ .focus()
57
+ .setTextSelection(pos + current.nodeSize)
58
+ .run();
59
+ });
60
+ return {
61
+ dom,
62
+ update: (next) => {
63
+ if (next.type !== current.type)
64
+ return false;
65
+ current = next;
66
+ show();
67
+ return true;
68
+ },
69
+ // Typing in the description stays there.
70
+ stopEvent: (event) => event.target === input,
71
+ ignoreMutation: () => true
72
+ };
73
+ };
74
+ }
75
+ });
@@ -1,6 +1,2 @@
1
1
  import { type AnyExtension } from '@tiptap/core';
2
- /**
3
- * The blocks and formatting of the kit's Markdown: headings, lists, quotes, code, rules, bold,
4
- * italic, strikethrough, inline code and links, with their usual typing shortcuts.
5
- */
6
- export declare function markdownExtensions(): AnyExtension[];
2
+ export declare function markdownExtensions(article?: boolean): AnyExtension[];
@@ -1,6 +1,8 @@
1
1
  import { Extension, InputRule } from '@tiptap/core';
2
2
  import StarterKit from '@tiptap/starter-kit';
3
+ import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';
3
4
  import { safeHttpUrl } from '../urls.js';
5
+ import { articleExtensions } from './article-extensions.js';
4
6
  /** Typing `[label](https://…)` makes a link, like the other Markdown shortcuts. */
5
7
  const MarkdownLink = Extension.create({
6
8
  name: 'markdownLink',
@@ -25,10 +27,42 @@ const MarkdownLink = Extension.create({
25
27
  * The blocks and formatting of the kit's Markdown: headings, lists, quotes, code, rules, bold,
26
28
  * italic, strikethrough, inline code and links, with their usual typing shortcuts.
27
29
  */
28
- export function markdownExtensions() {
30
+ const align = {
31
+ align: {
32
+ default: null,
33
+ parseHTML: (element) => element.style.textAlign || null,
34
+ renderHTML: (attributes) => attributes.align ? { style: `text-align: ${attributes.align}` } : {}
35
+ }
36
+ };
37
+ /** Tables as Markdown has them: one line of text per cell, no merged or resized cells. */
38
+ function tableExtensions() {
39
+ return [
40
+ Table.configure({ resizable: false, allowTableNodeSelection: true }),
41
+ TableRow,
42
+ // The inherited colspan, rowspan and colwidth stay: the table map is built from them.
43
+ TableHeader.extend({
44
+ content: 'paragraph',
45
+ addAttributes() {
46
+ return { ...this.parent?.(), ...align };
47
+ }
48
+ }),
49
+ TableCell.extend({
50
+ content: 'paragraph',
51
+ addAttributes() {
52
+ return { ...this.parent?.(), ...align };
53
+ }
54
+ })
55
+ ];
56
+ }
57
+ export function markdownExtensions(article = false) {
29
58
  return [
30
59
  StarterKit.configure({
31
60
  underline: false,
61
+ // Article Markdown brings a list item that can carry a task's box, and its own quote
62
+ // and code block.
63
+ ...(article
64
+ ? { listItem: false, blockquote: false, codeBlock: false }
65
+ : {}),
32
66
  link: {
33
67
  openOnClick: false,
34
68
  autolink: false,
@@ -37,6 +71,7 @@ export function markdownExtensions() {
37
71
  HTMLAttributes: { rel: 'noopener noreferrer nofollow ugc', target: '_blank' }
38
72
  }
39
73
  }),
40
- MarkdownLink
74
+ MarkdownLink,
75
+ ...(article ? [...tableExtensions(), ...articleExtensions()] : [])
41
76
  ];
42
77
  }
@@ -0,0 +1,9 @@
1
+ import { Extension } from '@tiptap/core';
2
+ import { type ArticleCommandContext } from './article-commands.js';
3
+ export type SlashMenuOptions = {
4
+ /** The element the menu is put in; positioned ancestors place it. */
5
+ layer: HTMLElement;
6
+ context: ArticleCommandContext;
7
+ };
8
+ /** Typing `/` lists the blocks and insertions; typing on filters them. */
9
+ export declare function slashMenu(options: SlashMenuOptions): Extension<any, any>;
@@ -0,0 +1,134 @@
1
+ import { Extension } from '@tiptap/core';
2
+ import { PluginKey } from '@tiptap/pm/state';
3
+ import { flip, shift } from '@floating-ui/dom';
4
+ import Suggestion, {} from '@tiptap/suggestion';
5
+ import { mount, unmount } from 'svelte';
6
+ import { findCommands, runCommand } from './article-commands.js';
7
+ import SlashOptions from './SlashOptions.svelte';
8
+ /** Typing `/` lists the blocks and insertions; typing on filters them. */
9
+ export function slashMenu(options) {
10
+ return Extension.create({
11
+ name: 'slashMenu',
12
+ addProseMirrorPlugins() {
13
+ const editor = this.editor;
14
+ return [
15
+ Suggestion({
16
+ editor,
17
+ pluginKey: new PluginKey('atmoSlashMenu'),
18
+ char: '/',
19
+ allowSpaces: true,
20
+ container: options.layer,
21
+ offset: { mainAxis: 8 },
22
+ // On a touch screen the toolbar lies along the bottom.
23
+ flip: false,
24
+ floatingUi: {
25
+ middleware: [
26
+ flip({
27
+ padding: {
28
+ top: 8,
29
+ bottom: window.matchMedia('(pointer: coarse)').matches ? 64 : 8
30
+ }
31
+ }),
32
+ shift({ padding: 8 })
33
+ ]
34
+ },
35
+ // Not in code, where a slash is a slash.
36
+ allow: ({ state, range }) => {
37
+ const parent = state.doc.resolve(range.from).parent;
38
+ return editor.isEditable && parent.isTextblock && !parent.type.spec.code;
39
+ },
40
+ items: ({ query }) => findCommands(query, editor, options.context),
41
+ command: ({ range, props }) => {
42
+ editor.chain().focus().deleteRange(range).run();
43
+ runCommand(editor, props, options.context);
44
+ },
45
+ render: () => {
46
+ let menu;
47
+ let rows;
48
+ let release;
49
+ let current;
50
+ const state = $state({
51
+ id: '',
52
+ items: [],
53
+ selected: 0,
54
+ choose: (index) => {
55
+ const item = current.items[index];
56
+ if (item)
57
+ current.command(item);
58
+ }
59
+ });
60
+ const dom = () => current.editor.view.dom;
61
+ const close = () => {
62
+ release?.();
63
+ release = undefined;
64
+ if (rows)
65
+ void unmount(rows);
66
+ rows = undefined;
67
+ menu?.remove();
68
+ menu = undefined;
69
+ dom().removeAttribute('aria-controls');
70
+ dom().removeAttribute('aria-activedescendant');
71
+ };
72
+ const draw = () => {
73
+ if (!menu)
74
+ return;
75
+ state.items = current.items;
76
+ // Nothing matches: stay out of the way instead of saying so.
77
+ menu.hidden = !current.items.length;
78
+ if (menu.hidden) {
79
+ dom().removeAttribute('aria-controls');
80
+ dom().removeAttribute('aria-activedescendant');
81
+ return;
82
+ }
83
+ dom().setAttribute('aria-controls', menu.id);
84
+ dom().setAttribute('aria-activedescendant', `${menu.id}-${state.selected}`);
85
+ };
86
+ const open = (props) => {
87
+ current = props;
88
+ state.selected = 0;
89
+ if (!menu) {
90
+ const element = document.createElement('div');
91
+ element.id = `${dom().id}-commands`;
92
+ element.role = 'listbox';
93
+ element.setAttribute('aria-label', 'Commands');
94
+ element.className =
95
+ 'absolute top-0 left-0 z-60 max-h-80 w-64 max-w-[calc(100vw-1rem)] overflow-y-auto overscroll-contain rounded-ui border border-base-300 bg-base-50 p-1.5 font-sans text-sm leading-normal text-base-950 transition-opacity duration-100 motion-reduce:transition-none dark:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] dark:bg-base-900 dark:text-base-50 starting:opacity-0';
96
+ state.id = element.id;
97
+ menu = element;
98
+ rows = mount(SlashOptions, { target: element, props: { state } });
99
+ release = props.mount(element, {
100
+ onPosition: ({ x, y }) => {
101
+ element.style.left = `${x}px`;
102
+ element.style.top = `${y}px`;
103
+ }
104
+ });
105
+ }
106
+ draw();
107
+ };
108
+ return {
109
+ onStart: open,
110
+ onUpdate: open,
111
+ onKeyDown: ({ event }) => {
112
+ if (!menu || menu.hidden || event.isComposing)
113
+ return false;
114
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
115
+ state.selected =
116
+ (state.selected + (event.key === 'ArrowDown' ? 1 : -1) + current.items.length) %
117
+ current.items.length;
118
+ draw();
119
+ return true;
120
+ }
121
+ if (event.key === 'Enter' || event.key === 'Tab') {
122
+ state.choose(state.selected);
123
+ return true;
124
+ }
125
+ return false;
126
+ },
127
+ onExit: close
128
+ };
129
+ }
130
+ })
131
+ ];
132
+ }
133
+ });
134
+ }
@@ -1,9 +1,17 @@
1
1
  <script lang="ts">
2
2
  import ExternalEmbed from '../components/ExternalEmbed.svelte';
3
3
  import type { ExternalEmbedProvider } from '../social/external-embeds.js';
4
+ import { linkEmbedOptions } from './context.js';
4
5
  import type { LinkEmbedProps } from './types.js';
5
6
 
6
7
  let { url, ref }: LinkEmbedProps<{ provider: ExternalEmbedProvider }> = $props();
8
+ // A bare link has no thumbnail of its own. The provider's is used unless the app asked that
9
+ // nothing load before a click.
10
+ const options = linkEmbedOptions();
7
11
  </script>
8
12
 
9
- <ExternalEmbed embed={{ type: 'external', uri: url, title: '' }} providers={[ref.provider]} />
13
+ <ExternalEmbed
14
+ embed={{ type: 'external', uri: url, title: '' }}
15
+ providers={[ref.provider]}
16
+ providerPoster={!options().clickToLoad}
17
+ />
@@ -2,53 +2,36 @@
2
2
  import type { Snippet } from 'svelte';
3
3
  import NestedComments from '../components/NestedComments.svelte';
4
4
  import Surface from '../components/Surface.svelte';
5
- import {
6
- blueskyPostToPostData,
7
- hasModerationLabel,
8
- type BlueskyPostView,
9
- type PostData
10
- } from '../social/posts.js';
5
+ import type { PostData } from '../social/posts.js';
11
6
  import type { PreferredSocialClient } from '../social/preferred-client.js';
12
7
  import { parseSocialPostUrl, socialPostUrl } from '../social/urls.js';
13
8
  import { safeHttpUrl } from '../urls.js';
14
- import { appviewUrl } from '../events/atproto-helpers.js';
9
+ import { loadPostEmbed } from './load.js';
15
10
 
16
11
  let {
17
12
  url,
13
+ data,
18
14
  fallback,
19
15
  socialClient
20
16
  }: {
21
17
  url: string;
18
+ /** The post, when it was loaded ahead; `null` when there is none to show. */
19
+ data?: PostData | null;
22
20
  /** The ordinary link, shown until the post loads and whenever it can't be shown. */
23
21
  fallback: Snippet;
24
22
  socialClient?: PreferredSocialClient | null;
25
23
  } = $props();
26
24
 
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);
25
+ let found = $state<{ url: string; post: PostData | null }>();
26
+ let post = $derived(data !== undefined ? data : found?.url === url ? found.post : null);
31
27
  $effect(() => {
32
- const ref = parseSocialPostUrl(url);
33
- post = null;
28
+ const ref = data === undefined ? parseSocialPostUrl(url) : null;
34
29
  if (!ref) return;
30
+ const link = url;
35
31
  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);
32
+ loadPostEmbed(ref, { signal: controller.signal })
33
+ .then((loaded) => {
34
+ if (!controller.signal.aborted) found = { url: link, post: loaded };
52
35
  })
53
36
  .catch(() => {});
54
37
  return () => controller.abort();
@@ -1,7 +1,10 @@
1
1
  import type { Snippet } from 'svelte';
2
+ import type { PostData } from '../social/posts.js';
2
3
  import type { PreferredSocialClient } from '../social/preferred-client.js';
3
4
  type $$ComponentProps = {
4
5
  url: string;
6
+ /** The post, when it was loaded ahead; `null` when there is none to show. */
7
+ data?: PostData | null;
5
8
  /** The ordinary link, shown until the post loads and whenever it can't be shown. */
6
9
  fallback: Snippet;
7
10
  socialClient?: PreferredSocialClient | null;
@@ -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>;