@atmo-dev/kit 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ExternalEmbed.svelte +30 -29
- package/dist/components/ExternalEmbed.svelte.d.ts +8 -0
- package/dist/components/InlineEditor.svelte +15 -95
- package/dist/components/InlineEditor.svelte.d.ts +1 -1
- package/dist/components/LinkCard.svelte +54 -25
- package/dist/components/LinkCard.svelte.d.ts +2 -0
- package/dist/components/LinkEmbed.svelte +75 -0
- package/dist/components/LinkEmbed.svelte.d.ts +13 -0
- package/dist/components/PostContent.svelte +12 -3
- package/dist/components/PostContent.svelte.d.ts +3 -0
- package/dist/components/RichText.svelte +47 -5
- package/dist/components/RichText.svelte.d.ts +5 -2
- package/dist/components/RichTextEditor.svelte +271 -0
- package/dist/components/RichTextEditor.svelte.d.ts +44 -0
- package/dist/components/composer/AltText.svelte +63 -0
- package/dist/components/composer/AltText.svelte.d.ts +11 -0
- package/dist/components/composer/CharRing.svelte +39 -0
- package/dist/components/composer/CharRing.svelte.d.ts +7 -0
- package/dist/components/composer/ComposerPost.svelte +321 -0
- package/dist/components/composer/ComposerPost.svelte.d.ts +29 -0
- package/dist/components/composer/Drafts.svelte +82 -0
- package/dist/components/composer/Drafts.svelte.d.ts +9 -0
- package/dist/components/composer/EmojiPicker.svelte +55 -0
- package/dist/components/composer/EmojiPicker.svelte.d.ts +7 -0
- package/dist/components/composer/GifPicker.svelte +118 -0
- package/dist/components/composer/GifPicker.svelte.d.ts +11 -0
- package/dist/components/composer/PostComposer.svelte +599 -0
- package/dist/components/composer/PostComposer.svelte.d.ts +71 -0
- package/dist/components/composer/PostComposerDialog.svelte +75 -0
- package/dist/components/composer/PostComposerDialog.svelte.d.ts +10 -0
- package/dist/components/composer/ReplySettings.svelte +150 -0
- package/dist/components/composer/ReplySettings.svelte.d.ts +18 -0
- package/dist/components/login/search.d.ts +29 -1
- package/dist/components/login/search.js +31 -3
- package/dist/editor/EditorLinkEmbed.svelte +35 -0
- package/dist/editor/EditorLinkEmbed.svelte.d.ts +12 -0
- package/dist/editor/detect-plugin.d.ts +5 -0
- package/dist/editor/detect-plugin.js +51 -0
- package/dist/editor/document.d.ts +17 -0
- package/dist/editor/document.js +269 -0
- package/dist/editor/link-embed-node.d.ts +17 -0
- package/dist/editor/link-embed-node.js +96 -0
- package/dist/editor/markdown-extensions.d.ts +6 -0
- package/dist/editor/markdown-extensions.js +42 -0
- package/dist/editor/markdown.d.ts +3 -0
- package/dist/editor/markdown.js +4 -0
- package/dist/embeds/PlayerLinkEmbed.svelte +9 -0
- package/dist/embeds/PlayerLinkEmbed.svelte.d.ts +7 -0
- package/dist/{events/event-view → embeds}/PostLinkEmbed.svelte +7 -7
- package/dist/{events/event-view → embeds}/PostLinkEmbed.svelte.d.ts +1 -1
- package/dist/{events/event-view → embeds}/ProfileLinkEmbed.svelte +7 -7
- package/dist/{events/event-view → embeds}/ProfileLinkEmbed.svelte.d.ts +1 -1
- package/dist/embeds/context.d.ts +10 -0
- package/dist/embeds/context.js +20 -0
- package/dist/embeds/defaults.d.ts +27 -0
- package/dist/embeds/defaults.js +38 -0
- package/dist/embeds/resolve.d.ts +9 -0
- package/dist/embeds/resolve.js +27 -0
- package/dist/embeds/types.d.ts +39 -0
- package/dist/embeds/types.js +1 -0
- package/dist/events/EventEditor.svelte +7 -6
- package/dist/events/EventView.svelte +21 -38
- package/dist/events/PostToBlueskyModal.svelte +12 -4
- package/dist/events/event-link-embed.d.ts +22 -0
- package/dist/events/event-link-embed.js +15 -0
- package/dist/events/event-view/EventLinkEmbed.svelte +12 -30
- package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -12
- package/dist/events.d.ts +2 -0
- package/dist/events.js +1 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +10 -2
- package/dist/richtext/detect.js +1 -1
- package/dist/richtext/document.d.ts +10 -0
- package/dist/richtext/document.js +44 -4
- package/dist/richtext/markdown.js +5 -1
- package/dist/richtext/serialize.d.ts +11 -0
- package/dist/richtext/serialize.js +462 -0
- package/dist/richtext.d.ts +1 -0
- package/dist/richtext.js +1 -0
- package/dist/social/MentionOptions.svelte +30 -0
- package/dist/social/MentionOptions.svelte.d.ts +12 -0
- package/dist/social/composer.d.ts +143 -0
- package/dist/social/composer.js +141 -0
- package/dist/social/{mention-suggestions.d.ts → mention-suggestions.svelte.d.ts} +1 -1
- package/dist/social/{mention-suggestions.js → mention-suggestions.svelte.js} +36 -46
- package/dist/social/richtext.js +2 -0
- package/dist/social.d.ts +2 -0
- package/dist/social.js +1 -0
- package/dist/styles.d.ts +5 -0
- package/dist/styles.js +5 -0
- package/package.json +4 -1
- package/dist/components/PostComposer.svelte +0 -41
- package/dist/components/PostComposer.svelte.d.ts +0 -16
|
@@ -10,14 +10,28 @@
|
|
|
10
10
|
import { focus } from '../styles.js';
|
|
11
11
|
import Icon from './Icon.svelte';
|
|
12
12
|
import LinkCard from './LinkCard.svelte';
|
|
13
|
+
import LinkEmbed from './LinkEmbed.svelte';
|
|
14
|
+
import { linkEmbedOptions, selectLinkEmbeds } from '../embeds/context.js';
|
|
15
|
+
import type { LinkEmbed as LinkEmbedDefinition } from '../embeds/types.js';
|
|
16
|
+
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
13
17
|
|
|
14
18
|
let {
|
|
15
19
|
embed,
|
|
16
|
-
providers
|
|
20
|
+
providers,
|
|
21
|
+
embeds = false,
|
|
22
|
+
socialClient
|
|
17
23
|
}: {
|
|
18
24
|
embed: ExternalPostEmbed;
|
|
19
25
|
providers?: readonly ExternalEmbedProvider[];
|
|
26
|
+
/**
|
|
27
|
+
* Show links that are not media as link embeds: `true` for the app's embeds (see
|
|
28
|
+
* `setLinkEmbeds`), or a list. Off by default, so links stay cards.
|
|
29
|
+
*/
|
|
30
|
+
embeds?: boolean | readonly LinkEmbedDefinition[];
|
|
31
|
+
socialClient?: PreferredSocialClient | null;
|
|
20
32
|
} = $props();
|
|
33
|
+
const context = linkEmbedOptions();
|
|
34
|
+
let linkEmbeds = $derived(selectLinkEmbeds(embeds, context()));
|
|
21
35
|
let match = $derived(resolveExternalEmbed(embed, providers));
|
|
22
36
|
// Consent belongs to this resolved player, not to its position in the feed.
|
|
23
37
|
// A changed URL/provider/source never inherits an earlier click, even for one render.
|
|
@@ -38,8 +52,7 @@
|
|
|
38
52
|
match !== null && (activated === match || (autoplay && !reducedMotion && paused !== match))
|
|
39
53
|
);
|
|
40
54
|
let label = $derived(embed.title || `${match?.provider.label ?? 'External'} media`);
|
|
41
|
-
let
|
|
42
|
-
let stopButton = $state<HTMLButtonElement | null>(null);
|
|
55
|
+
let frame = $state<HTMLIFrameElement | null>(null);
|
|
43
56
|
let animationButton = $state<HTMLButtonElement | null>(null);
|
|
44
57
|
let video = $state<HTMLVideoElement | null>(null);
|
|
45
58
|
$effect(() => {
|
|
@@ -51,13 +64,14 @@
|
|
|
51
64
|
paused = null;
|
|
52
65
|
activated = match;
|
|
53
66
|
await tick();
|
|
54
|
-
|
|
67
|
+
// The play button is gone; keyboard users continue in the player.
|
|
68
|
+
(autoplay ? animationButton : frame)?.focus({ preventScroll: true });
|
|
55
69
|
}
|
|
56
70
|
async function stop() {
|
|
57
71
|
paused = match;
|
|
58
72
|
activated = null;
|
|
59
73
|
await tick();
|
|
60
|
-
|
|
74
|
+
animationButton?.focus({ preventScroll: true });
|
|
61
75
|
}
|
|
62
76
|
</script>
|
|
63
77
|
|
|
@@ -68,6 +82,7 @@
|
|
|
68
82
|
{#if active || (autoplay && match.player.type === 'video' && paused === match)}
|
|
69
83
|
{#if match.player.type === 'iframe'}
|
|
70
84
|
<iframe
|
|
85
|
+
bind:this={frame}
|
|
71
86
|
src={safeWebUrl(match.player.src)}
|
|
72
87
|
title={label}
|
|
73
88
|
allow="autoplay; encrypted-media; fullscreen; picture-in-picture"
|
|
@@ -119,11 +134,10 @@
|
|
|
119
134
|
</div>
|
|
120
135
|
{:else}
|
|
121
136
|
<button
|
|
122
|
-
bind:this={previewButton}
|
|
123
137
|
type="button"
|
|
124
138
|
aria-label={`Play ${label} on ${match.provider.label}`}
|
|
125
139
|
onclick={play}
|
|
126
|
-
class={`relative flex max-h-[32rem] w-full items-center justify-center overflow-hidden bg-
|
|
140
|
+
class={`group/play relative flex max-h-[32rem] w-full cursor-pointer items-center justify-center overflow-hidden bg-black ${focus}`}
|
|
127
141
|
style:aspect-ratio={match.player.aspectRatio ?? 16 / 9}
|
|
128
142
|
>
|
|
129
143
|
{#if safeWebUrl(embed.image)}<img
|
|
@@ -133,9 +147,9 @@
|
|
|
133
147
|
class="absolute inset-0 size-full object-cover"
|
|
134
148
|
/>{/if}
|
|
135
149
|
<span
|
|
136
|
-
class="relative
|
|
150
|
+
class="relative grid size-14 place-items-center rounded-full bg-black/60 text-white transition-transform duration-150 group-hover/play:scale-105 motion-reduce:transition-none"
|
|
137
151
|
>
|
|
138
|
-
<Icon img={Play} size={
|
|
152
|
+
<Icon img={Play} size={24} />
|
|
139
153
|
</span>
|
|
140
154
|
</button>
|
|
141
155
|
{/if}
|
|
@@ -150,28 +164,15 @@
|
|
|
150
164
|
class={`absolute right-2 bottom-2 inline-flex size-8 items-center justify-center rounded-full bg-black/60 text-white transition-colors hover:bg-black/80 ${focus}`}
|
|
151
165
|
><Icon img={active ? Pause : Play} size={16} /></button
|
|
152
166
|
>
|
|
153
|
-
{
|
|
154
|
-
<div class="flex items-center justify-between gap-3 p-3 text-xs">
|
|
155
|
-
<a
|
|
156
|
-
href={safeWebUrl(embed.uri)}
|
|
157
|
-
target="_blank"
|
|
158
|
-
rel="noopener noreferrer"
|
|
159
|
-
class={`min-w-0 truncate rounded-ui text-base-600 hover:text-accent-700 dark:text-base-400 dark:hover:text-accent-300 ${focus}`}
|
|
160
|
-
>{embed.title || `Open on ${match.provider.label}`}</a
|
|
161
|
-
>
|
|
162
|
-
{#if active}<button
|
|
163
|
-
type="button"
|
|
164
|
-
bind:this={stopButton}
|
|
165
|
-
onclick={stop}
|
|
166
|
-
aria-label={`Stop ${match.provider.label} embed`}
|
|
167
|
-
class={`shrink-0 rounded-ui text-base-600 hover:text-accent-700 dark:text-base-400 dark:hover:text-accent-300 ${focus}`}
|
|
168
|
-
>Stop</button
|
|
169
|
-
>{/if}
|
|
170
|
-
</div>{/if}
|
|
167
|
+
{/if}
|
|
171
168
|
</div>
|
|
172
|
-
{:else}
|
|
169
|
+
{:else if linkEmbeds.length}
|
|
170
|
+
<LinkEmbed url={embed.uri} embeds={linkEmbeds} fallback={card} {socialClient} />
|
|
171
|
+
{:else}{@render card()}{/if}
|
|
172
|
+
|
|
173
|
+
{#snippet card()}
|
|
173
174
|
<LinkCard
|
|
174
175
|
href={embed.uri}
|
|
175
176
|
meta={{ title: embed.title, description: embed.description, image: embed.image }}
|
|
176
177
|
/>
|
|
177
|
-
{/
|
|
178
|
+
{/snippet}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { type ExternalEmbedProvider, type ExternalPostEmbed } from '../social/external-embeds.js';
|
|
2
|
+
import type { LinkEmbed as LinkEmbedDefinition } from '../embeds/types.js';
|
|
3
|
+
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
2
4
|
type $$ComponentProps = {
|
|
3
5
|
embed: ExternalPostEmbed;
|
|
4
6
|
providers?: readonly ExternalEmbedProvider[];
|
|
7
|
+
/**
|
|
8
|
+
* Show links that are not media as link embeds: `true` for the app's embeds (see
|
|
9
|
+
* `setLinkEmbeds`), or a list. Off by default, so links stay cards.
|
|
10
|
+
*/
|
|
11
|
+
embeds?: boolean | readonly LinkEmbedDefinition[];
|
|
12
|
+
socialClient?: PreferredSocialClient | null;
|
|
5
13
|
};
|
|
6
14
|
declare const ExternalEmbed: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
15
|
type ExternalEmbed = ReturnType<typeof ExternalEmbed>;
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import { Editor, type JSONContent } from '@tiptap/core';
|
|
4
|
-
import Document from '@tiptap/extension-document';
|
|
5
|
-
import Paragraph from '@tiptap/extension-paragraph';
|
|
6
|
-
import Text from '@tiptap/extension-text';
|
|
7
|
-
import HardBreak from '@tiptap/extension-hard-break';
|
|
8
|
-
import History from '@tiptap/extension-history';
|
|
9
|
-
import Placeholder from '@tiptap/extension-placeholder';
|
|
10
|
-
import Mention from '@tiptap/extension-mention';
|
|
2
|
+
import type { Editor, JSONContent } from '@tiptap/core';
|
|
11
3
|
import type { ActorSearch } from './login/types.js';
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
import RichTextEditor from './RichTextEditor.svelte';
|
|
5
|
+
|
|
6
|
+
// The plain-text editor for titles and posts; `RichTextEditor` adds Markdown and embeds.
|
|
15
7
|
let {
|
|
16
8
|
value = $bindable(''),
|
|
17
9
|
editor = $bindable<Editor | null>(null),
|
|
@@ -33,88 +25,16 @@
|
|
|
33
25
|
onupdate?: (content: { text: string; json: JSONContent }) => void;
|
|
34
26
|
class?: string;
|
|
35
27
|
} = $props();
|
|
36
|
-
const id = $props.id();
|
|
37
|
-
let host: HTMLDivElement;
|
|
38
|
-
let element: HTMLDivElement;
|
|
39
|
-
onMount(() => {
|
|
40
|
-
const instance = new Editor({
|
|
41
|
-
element,
|
|
42
|
-
extensions: [
|
|
43
|
-
Document,
|
|
44
|
-
Paragraph,
|
|
45
|
-
Text,
|
|
46
|
-
HardBreak,
|
|
47
|
-
History,
|
|
48
|
-
Placeholder.configure({ placeholder }),
|
|
49
|
-
...(searchActors
|
|
50
|
-
? [
|
|
51
|
-
Mention.configure({
|
|
52
|
-
HTMLAttributes: { class: 'text-accent-700 dark:text-accent-300' },
|
|
53
|
-
suggestion: mentionSuggestions(searchActors, () => host)
|
|
54
|
-
})
|
|
55
|
-
]
|
|
56
|
-
: [])
|
|
57
|
-
],
|
|
58
|
-
content: textToDoc(untrack(() => value)),
|
|
59
|
-
editable: !disabled,
|
|
60
|
-
editorProps: {
|
|
61
|
-
attributes: {
|
|
62
|
-
id,
|
|
63
|
-
role: searchActors ? 'combobox' : 'textbox',
|
|
64
|
-
'aria-label': label,
|
|
65
|
-
...(searchActors
|
|
66
|
-
? { 'aria-autocomplete': 'list', 'aria-expanded': 'false', 'aria-haspopup': 'listbox' }
|
|
67
|
-
: { 'aria-multiline': String(!singleLine) }),
|
|
68
|
-
class:
|
|
69
|
-
'min-h-[1.5em] outline-none whitespace-pre-wrap break-words [&_p.is-editor-empty:first-child]:before:content-[attr(data-placeholder)] [&_p.is-editor-empty:first-child]:before:text-base-600 dark:[&_p.is-editor-empty:first-child]:before:text-base-400 [&_p.is-editor-empty:first-child]:before:float-left [&_p.is-editor-empty:first-child]:before:pointer-events-none [&_p.is-editor-empty:first-child]:before:h-0'
|
|
70
|
-
},
|
|
71
|
-
handleKeyDown: (view, event) =>
|
|
72
|
-
singleLine &&
|
|
73
|
-
event.key === 'Enter' &&
|
|
74
|
-
!event.isComposing &&
|
|
75
|
-
!view.dom.getAttribute('aria-activedescendant'),
|
|
76
|
-
transformPastedText: (text) => (singleLine ? text.replace(/[\r\n]+/g, ' ') : text),
|
|
77
|
-
// Accept plain text only, preserving the editor's deliberately small schema.
|
|
78
|
-
handlePaste: (_view, event) => {
|
|
79
|
-
const text = event.clipboardData?.getData('text/plain');
|
|
80
|
-
if (text === undefined) return false;
|
|
81
|
-
event.preventDefault();
|
|
82
|
-
if (singleLine) {
|
|
83
|
-
const cleaned = text.replace(/[\r\n]+/g, ' ');
|
|
84
|
-
if (cleaned) instance.commands.insertContent({ type: 'text', text: cleaned });
|
|
85
|
-
} else instance.commands.insertContent(textToDoc(text).content ?? []);
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
onUpdate: ({ editor: current }) => {
|
|
90
|
-
const json = current.getJSON();
|
|
91
|
-
value = editorJsonToBlueskyPost(json).text;
|
|
92
|
-
onupdate?.({ text: value, json });
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
editor = instance;
|
|
96
|
-
return () => {
|
|
97
|
-
instance.destroy();
|
|
98
|
-
editor = null;
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
$effect(() => {
|
|
102
|
-
if (editor && editorJsonToBlueskyPost(editor.getJSON()).text !== value)
|
|
103
|
-
editor.commands.setContent(textToDoc(value), { emitUpdate: false });
|
|
104
|
-
});
|
|
105
|
-
$effect(() => {
|
|
106
|
-
editor?.setEditable(!disabled, false);
|
|
107
|
-
editor?.view.dom.setAttribute('aria-disabled', String(disabled));
|
|
108
|
-
});
|
|
109
28
|
</script>
|
|
110
29
|
|
|
111
|
-
<
|
|
112
|
-
bind:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
30
|
+
<RichTextEditor
|
|
31
|
+
bind:value
|
|
32
|
+
bind:editor
|
|
33
|
+
{label}
|
|
34
|
+
{placeholder}
|
|
35
|
+
{singleLine}
|
|
36
|
+
{disabled}
|
|
37
|
+
{searchActors}
|
|
38
|
+
{onupdate}
|
|
39
|
+
class={className}
|
|
40
|
+
/>
|
|
@@ -1,49 +1,78 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLAnchorAttributes } from 'svelte/elements';
|
|
3
3
|
import { cn } from '../utils.js';
|
|
4
|
-
import { focus } from '../styles.js';
|
|
4
|
+
import { action, focus, line, muted, recess } from '../styles.js';
|
|
5
5
|
import { safeHttpUrl as safeWebUrl } from '../urls.js';
|
|
6
6
|
let {
|
|
7
7
|
href,
|
|
8
|
+
localHref,
|
|
8
9
|
meta,
|
|
9
10
|
class: className,
|
|
10
11
|
...rest
|
|
11
12
|
}: Omit<HTMLAnchorAttributes, 'href' | 'children'> & {
|
|
12
13
|
href: string;
|
|
14
|
+
/** A path in this app to open in the same tab instead; `href` still names the site. */
|
|
15
|
+
localHref?: string;
|
|
13
16
|
meta: { title?: string; description?: string; image?: string };
|
|
14
17
|
} = $props();
|
|
18
|
+
let host = $derived.by(() => {
|
|
19
|
+
try {
|
|
20
|
+
return new URL(href).hostname.replace(/^www\./, '');
|
|
21
|
+
} catch {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
// Only paths: anything else could leave the app or run script.
|
|
26
|
+
let local = $derived(localHref && /^\/(?!\/)/.test(localHref) ? localHref : undefined);
|
|
27
|
+
// A broken image leaves the text card, not an empty black frame.
|
|
28
|
+
let failed = $state<string>();
|
|
29
|
+
let image = $derived(meta.image === failed ? undefined : safeWebUrl(meta.image));
|
|
15
30
|
</script>
|
|
16
31
|
|
|
17
32
|
<a
|
|
33
|
+
target={local ? undefined : '_blank'}
|
|
34
|
+
rel={local ? undefined : 'noopener noreferrer'}
|
|
18
35
|
{...rest}
|
|
19
|
-
href={safeWebUrl(href)}
|
|
20
|
-
target="_blank"
|
|
21
|
-
rel="noopener noreferrer"
|
|
36
|
+
href={local ?? safeWebUrl(href)}
|
|
22
37
|
class={cn(
|
|
23
|
-
'block overflow-hidden rounded-ui border
|
|
38
|
+
'relative block overflow-hidden rounded-ui border text-base-950 no-underline dark:text-base-50',
|
|
39
|
+
line,
|
|
40
|
+
image ? 'aspect-[1.91/1] bg-black' : recess,
|
|
24
41
|
focus,
|
|
25
42
|
className
|
|
26
43
|
)}
|
|
27
44
|
>
|
|
28
|
-
{#if
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<strong class="block text-sm font-medium">{meta.title || href}</strong>
|
|
40
|
-
{#if meta.description}<p
|
|
41
|
-
class="mt-1 line-clamp-2 text-xs leading-relaxed text-base-600 dark:text-base-400"
|
|
42
|
-
>
|
|
43
|
-
{meta.description}
|
|
44
|
-
</p>{/if}
|
|
45
|
-
<span class="mt-1 block truncate text-[.6875rem] text-base-600 dark:text-base-400"
|
|
46
|
-
>{href.replace(/^https?:\/\//, '')}</span
|
|
45
|
+
{#if image}
|
|
46
|
+
<img
|
|
47
|
+
src={image}
|
|
48
|
+
alt=""
|
|
49
|
+
loading="lazy"
|
|
50
|
+
decoding="async"
|
|
51
|
+
class="absolute inset-0 size-full object-cover"
|
|
52
|
+
onerror={() => (failed = meta.image)}
|
|
53
|
+
/>
|
|
54
|
+
<span
|
|
55
|
+
class="absolute inset-x-0 bottom-0 flex flex-col gap-1 bg-linear-to-t from-black/85 via-black/55 to-transparent px-4 pt-14 pb-3.5"
|
|
47
56
|
>
|
|
48
|
-
|
|
57
|
+
{#if host}<span class="truncate text-xs font-semibold text-accent-300">{host}</span>{/if}
|
|
58
|
+
<span class="line-clamp-2 text-[15px] leading-snug font-semibold text-white"
|
|
59
|
+
>{meta.title || host || href}</span
|
|
60
|
+
>
|
|
61
|
+
</span>
|
|
62
|
+
{:else}
|
|
63
|
+
<span class="flex flex-col gap-1 px-4 py-3.5">
|
|
64
|
+
{#if host}<span class={cn('truncate text-xs font-semibold', action)}>{host}</span>{/if}
|
|
65
|
+
<span class="line-clamp-2 text-[15px] leading-snug font-semibold wrap-anywhere"
|
|
66
|
+
>{meta.title || href}</span
|
|
67
|
+
>
|
|
68
|
+
{#if meta.description}<span class={cn('line-clamp-2 text-sm leading-snug', muted)}
|
|
69
|
+
>{meta.description}</span
|
|
70
|
+
>{/if}
|
|
71
|
+
</span>
|
|
72
|
+
{/if}
|
|
73
|
+
<!-- Recessed edge, drawn above the image. -->
|
|
74
|
+
<span
|
|
75
|
+
class="pointer-events-none absolute inset-0 rounded-[inherit] shadow-[inset_0_2px_5px_rgb(0_0_0/0.22),inset_0_0_0_1px_rgb(0_0_0/0.08)] dark:shadow-[inset_0_2px_6px_rgb(0_0_0/0.5),inset_0_0_0_1px_rgb(0_0_0/0.25)]"
|
|
76
|
+
aria-hidden="true"
|
|
77
|
+
></span>
|
|
49
78
|
</a>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { HTMLAnchorAttributes } from 'svelte/elements';
|
|
2
2
|
type $$ComponentProps = Omit<HTMLAnchorAttributes, 'href' | 'children'> & {
|
|
3
3
|
href: string;
|
|
4
|
+
/** A path in this app to open in the same tab instead; `href` still names the site. */
|
|
5
|
+
localHref?: string;
|
|
4
6
|
meta: {
|
|
5
7
|
title?: string;
|
|
6
8
|
description?: string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Component } from 'svelte';
|
|
3
|
+
// Not imported as `LinkEmbed`: the generated types would give that name to the import
|
|
4
|
+
// instead of this component, leaving consumers with a type-only export.
|
|
5
|
+
import type { LinkEmbed as Definition, LinkEmbedProps } from '../embeds/types.js';
|
|
6
|
+
|
|
7
|
+
// Loaded components are kept, so later embeds of the same kind render without a flash.
|
|
8
|
+
const loaded = new WeakMap<Definition, Component<LinkEmbedProps>>();
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import type { Snippet } from 'svelte';
|
|
13
|
+
import { linkEmbedOptions, selectLinkEmbeds } from '../embeds/context.js';
|
|
14
|
+
import { isClickToLoad, resolveLinkEmbed } from '../embeds/resolve.js';
|
|
15
|
+
import type { LinkEmbedOptions } from '../embeds/types.js';
|
|
16
|
+
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
17
|
+
import { safeHttpUrl } from '../urls.js';
|
|
18
|
+
import Button from './Button.svelte';
|
|
19
|
+
|
|
20
|
+
export type LinkEmbedComponentProps = LinkEmbedOptions & {
|
|
21
|
+
url: string;
|
|
22
|
+
/** Shown until the content has loaded and whenever it can't be shown. Defaults to a link. */
|
|
23
|
+
fallback?: Snippet;
|
|
24
|
+
socialClient?: PreferredSocialClient | null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
let { url, embeds, clickToLoad, fallback, socialClient }: LinkEmbedComponentProps = $props();
|
|
28
|
+
|
|
29
|
+
const context = linkEmbedOptions();
|
|
30
|
+
let match = $derived(resolveLinkEmbed(url, embeds ?? selectLinkEmbeds(true, context())));
|
|
31
|
+
let gated = $derived(!!match && isClickToLoad(match.embed, clickToLoad ?? context().clickToLoad));
|
|
32
|
+
// Consent belongs to this link, not to its position on the page.
|
|
33
|
+
let accepted = $state<string>();
|
|
34
|
+
let component = $state.raw<Component<LinkEmbedProps>>();
|
|
35
|
+
$effect(() => {
|
|
36
|
+
const embed = match?.embed;
|
|
37
|
+
component = embed && loaded.get(embed);
|
|
38
|
+
if (!embed || component || (gated && accepted !== match?.url)) return;
|
|
39
|
+
let current = true;
|
|
40
|
+
embed
|
|
41
|
+
.load()
|
|
42
|
+
.then((module) => {
|
|
43
|
+
loaded.set(embed, module.default);
|
|
44
|
+
if (current) component = module.default;
|
|
45
|
+
})
|
|
46
|
+
.catch(() => {});
|
|
47
|
+
return () => {
|
|
48
|
+
current = false;
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
let href = $derived(safeHttpUrl(url));
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
{#snippet link()}
|
|
55
|
+
{#if fallback}{@render fallback()}
|
|
56
|
+
{:else if href}<p class="wrap-anywhere">
|
|
57
|
+
<a
|
|
58
|
+
{href}
|
|
59
|
+
target="_blank"
|
|
60
|
+
rel="noopener noreferrer nofollow ugc"
|
|
61
|
+
class="text-accent-700 underline decoration-accent-700/40 underline-offset-2 hover:decoration-accent-700 dark:text-accent-300 dark:decoration-accent-300/40 dark:hover:decoration-accent-300"
|
|
62
|
+
>{url}</a
|
|
63
|
+
>
|
|
64
|
+
</p>{/if}
|
|
65
|
+
{/snippet}
|
|
66
|
+
|
|
67
|
+
{#if match && gated && accepted !== match.url}
|
|
68
|
+
{@render link()}
|
|
69
|
+
<Button variant="secondary" size="sm" onclick={() => (accepted = match?.url)}
|
|
70
|
+
>Load {match.embed.label}</Button
|
|
71
|
+
>
|
|
72
|
+
{:else if match && component}
|
|
73
|
+
{@const Embed = component}
|
|
74
|
+
<Embed url={match.url} ref={match.ref} fallback={link} {socialClient} />
|
|
75
|
+
{:else}{@render link()}{/if}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Component } from 'svelte';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { LinkEmbedOptions } from '../embeds/types.js';
|
|
4
|
+
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
5
|
+
export type LinkEmbedComponentProps = LinkEmbedOptions & {
|
|
6
|
+
url: string;
|
|
7
|
+
/** Shown until the content has loaded and whenever it can't be shown. Defaults to a link. */
|
|
8
|
+
fallback?: Snippet;
|
|
9
|
+
socialClient?: PreferredSocialClient | null;
|
|
10
|
+
};
|
|
11
|
+
declare const LinkEmbed: Component<LinkEmbedComponentProps, {}, "">;
|
|
12
|
+
type LinkEmbed = ReturnType<typeof LinkEmbed>;
|
|
13
|
+
export default LinkEmbed;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import RichText from './RichText.svelte';
|
|
10
10
|
import type { ExternalEmbedProvider } from '../social/external-embeds.js';
|
|
11
11
|
import ExternalEmbed from './ExternalEmbed.svelte';
|
|
12
|
+
import type { LinkEmbed } from '../embeds/types.js';
|
|
12
13
|
import PostVideo from './PostVideo.svelte';
|
|
13
14
|
import PostImages from './PostImages.svelte';
|
|
14
15
|
import Avatar from './Avatar.svelte';
|
|
@@ -16,12 +17,15 @@
|
|
|
16
17
|
let {
|
|
17
18
|
post,
|
|
18
19
|
socialClient,
|
|
19
|
-
embedProviders
|
|
20
|
+
embedProviders,
|
|
21
|
+
linkEmbeds = false
|
|
20
22
|
}: {
|
|
21
23
|
post: PostData;
|
|
22
24
|
socialClient?: PreferredSocialClient | null;
|
|
23
25
|
/** Defaults to YouTube and Klipy. Pass [] to render only ordinary link cards. */
|
|
24
26
|
embedProviders?: readonly ExternalEmbedProvider[];
|
|
27
|
+
/** Show links to posts, profiles and other known pages as embeds instead of cards. */
|
|
28
|
+
linkEmbeds?: boolean | readonly LinkEmbed[];
|
|
25
29
|
} = $props();
|
|
26
30
|
const recordKinds = {
|
|
27
31
|
feed: { label: 'Feed', icon: Radio },
|
|
@@ -34,7 +38,12 @@
|
|
|
34
38
|
{#if post.text}<RichText text={post.text} facets={post.facets} class="text-sm" />{/if}
|
|
35
39
|
{#each post.embeds ?? [] as embed, index (index)}
|
|
36
40
|
<div class={post.text || index ? 'mt-2.5' : ''}>
|
|
37
|
-
{#if embed.type === 'external'}<ExternalEmbed
|
|
41
|
+
{#if embed.type === 'external'}<ExternalEmbed
|
|
42
|
+
{embed}
|
|
43
|
+
providers={embedProviders}
|
|
44
|
+
embeds={linkEmbeds}
|
|
45
|
+
{socialClient}
|
|
46
|
+
/>
|
|
38
47
|
{:else if embed.type === 'images'}<PostImages images={embed.images} />
|
|
39
48
|
{:else if embed.type === 'video'}<PostVideo
|
|
40
49
|
playlist={embed.playlist}
|
|
@@ -88,7 +97,7 @@
|
|
|
88
97
|
>
|
|
89
98
|
@{embed.post.author.handle}</span
|
|
90
99
|
></a
|
|
91
|
-
><PostContent post={embed.post} {socialClient} {embedProviders} />{:else}<p
|
|
100
|
+
><PostContent post={embed.post} {socialClient} {embedProviders} {linkEmbeds} />{:else}<p
|
|
92
101
|
class="text-xs text-base-600 dark:text-base-400"
|
|
93
102
|
>
|
|
94
103
|
{embed.reason === 'blocked'
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { PostData } from '../social/posts.js';
|
|
2
2
|
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
3
3
|
import type { ExternalEmbedProvider } from '../social/external-embeds.js';
|
|
4
|
+
import type { LinkEmbed } from '../embeds/types.js';
|
|
4
5
|
import PostContent from './PostContent.svelte';
|
|
5
6
|
type $$ComponentProps = {
|
|
6
7
|
post: PostData;
|
|
7
8
|
socialClient?: PreferredSocialClient | null;
|
|
8
9
|
/** Defaults to YouTube and Klipy. Pass [] to render only ordinary link cards. */
|
|
9
10
|
embedProviders?: readonly ExternalEmbedProvider[];
|
|
11
|
+
/** Show links to posts, profiles and other known pages as embeds instead of cards. */
|
|
12
|
+
linkEmbeds?: boolean | readonly LinkEmbed[];
|
|
10
13
|
};
|
|
11
14
|
declare const PostContent: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
12
15
|
type PostContent = ReturnType<typeof PostContent>;
|
|
@@ -3,12 +3,18 @@
|
|
|
3
3
|
import {
|
|
4
4
|
inlineHref,
|
|
5
5
|
inlineText,
|
|
6
|
+
lineBreaks,
|
|
6
7
|
paragraphParts,
|
|
8
|
+
trimBreaks,
|
|
7
9
|
MAX_RENDER_DEPTH,
|
|
8
10
|
type RichTextDocument,
|
|
9
11
|
type RichTextLinkOptions
|
|
10
12
|
} from '../richtext/document.js';
|
|
11
13
|
import { parsePlainText } from '../richtext/plain.js';
|
|
14
|
+
import { linkEmbedOptions, selectLinkEmbeds } from '../embeds/context.js';
|
|
15
|
+
import { resolveLinkEmbed } from '../embeds/resolve.js';
|
|
16
|
+
import type { LinkEmbed as LinkEmbedDefinition } from '../embeds/types.js';
|
|
17
|
+
import LinkEmbed from './LinkEmbed.svelte';
|
|
12
18
|
import { cn } from '../utils.js';
|
|
13
19
|
|
|
14
20
|
export type RichTextProps = RichTextLinkOptions & {
|
|
@@ -23,9 +29,11 @@
|
|
|
23
29
|
/** Added to Markdown heading levels, e.g. 1 renders `#` as h2 below a page's h1. */
|
|
24
30
|
headingOffset?: number;
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
32
|
+
* Show a bare link alone on its line as an embed: `true` for the app's embeds (see
|
|
33
|
+
* `setLinkEmbeds`, by default posts, profiles, YouTube and GIFs) or an explicit list.
|
|
28
34
|
*/
|
|
35
|
+
embeds?: boolean | readonly LinkEmbedDefinition[];
|
|
36
|
+
/** Custom matching instead of `embeds`; requires `linkEmbed`. */
|
|
29
37
|
embedLink?: (url: string) => boolean;
|
|
30
38
|
/** Renders such a link. The second argument renders the ordinary link, e.g. while loading. */
|
|
31
39
|
linkEmbed?: Snippet<[url: string, fallback: Snippet]>;
|
|
@@ -40,6 +48,7 @@
|
|
|
40
48
|
socialClient,
|
|
41
49
|
mentionUrl,
|
|
42
50
|
headingOffset = 0,
|
|
51
|
+
embeds,
|
|
43
52
|
embedLink,
|
|
44
53
|
linkEmbed,
|
|
45
54
|
class: className
|
|
@@ -47,6 +56,22 @@
|
|
|
47
56
|
|
|
48
57
|
let doc = $derived(content ?? parsePlainText(text, { facets, detectLinks }));
|
|
49
58
|
|
|
59
|
+
const embedOptions = linkEmbedOptions();
|
|
60
|
+
let embedList = $derived(selectLinkEmbeds(embeds, embedOptions()));
|
|
61
|
+
let isEmbed = $derived(
|
|
62
|
+
linkEmbed && embedLink
|
|
63
|
+
? embedLink
|
|
64
|
+
: embedList.length
|
|
65
|
+
? (url: string) => !!resolveLinkEmbed(url, embedList)
|
|
66
|
+
: undefined
|
|
67
|
+
);
|
|
68
|
+
/** Plain text is one paragraph; with embeds it is split around the embedded lines. */
|
|
69
|
+
let plainParts = $derived(
|
|
70
|
+
isEmbed && !doc.markdown
|
|
71
|
+
? nodes(doc.children).flatMap((block) => paragraphParts(lineBreaks(block.children), isEmbed))
|
|
72
|
+
: []
|
|
73
|
+
);
|
|
74
|
+
|
|
50
75
|
type Node = Record<string, unknown>;
|
|
51
76
|
|
|
52
77
|
function isNode(value: unknown): value is Node {
|
|
@@ -107,14 +132,19 @@
|
|
|
107
132
|
{/each}
|
|
108
133
|
{/snippet}
|
|
109
134
|
|
|
135
|
+
{#snippet embedOr(url: string | undefined, paragraph: Snippet)}
|
|
136
|
+
{#if !url}{@render paragraph()}
|
|
137
|
+
{:else if linkEmbed && embedLink}{@render linkEmbed(url, paragraph)}
|
|
138
|
+
{:else}<LinkEmbed {url} embeds={embedList} fallback={paragraph} {socialClient} />{/if}
|
|
139
|
+
{/snippet}
|
|
140
|
+
|
|
110
141
|
{#snippet blocks(children: unknown, depth: number)}
|
|
111
142
|
{#each nodes(children) as node, index (index)}
|
|
112
143
|
{#if depth > MAX_RENDER_DEPTH}<p>{inlineText(node, depth)}</p>
|
|
113
144
|
{:else if node.type === 'paragraph'}
|
|
114
|
-
{#each paragraphParts(node.children,
|
|
145
|
+
{#each paragraphParts(node.children, isEmbed) as part, partIndex (partIndex)}
|
|
115
146
|
{#snippet paragraph()}<p>{@render inlines(part.children, false, depth + 1)}</p>{/snippet}
|
|
116
|
-
{
|
|
117
|
-
{:else}{@render paragraph()}{/if}
|
|
147
|
+
{@render embedOr(part.embed, paragraph)}
|
|
118
148
|
{/each}
|
|
119
149
|
{:else if node.type === 'heading'}<svelte:element
|
|
120
150
|
this={heading(node.depth)}
|
|
@@ -158,6 +188,18 @@
|
|
|
158
188
|
>
|
|
159
189
|
{@render blocks(doc.children, 0)}
|
|
160
190
|
</div>
|
|
191
|
+
{:else if plainParts.some((part) => part.embed)}
|
|
192
|
+
<div
|
|
193
|
+
class={cn('space-y-3 leading-relaxed wrap-anywhere text-base-950 dark:text-base-50', className)}
|
|
194
|
+
>
|
|
195
|
+
{#each plainParts as part, index (index)}
|
|
196
|
+
{@const children = trimBreaks(part.children)}
|
|
197
|
+
{#snippet paragraph()}<p class="whitespace-pre-wrap">
|
|
198
|
+
{@render inlines(children, false, 1)}
|
|
199
|
+
</p>{/snippet}
|
|
200
|
+
{#if part.embed || children.length}{@render embedOr(part.embed, paragraph)}{/if}
|
|
201
|
+
{/each}
|
|
202
|
+
</div>
|
|
161
203
|
{:else}
|
|
162
204
|
<p
|
|
163
205
|
class={cn(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import { type RichTextDocument, type RichTextLinkOptions } from '../richtext/document.js';
|
|
3
|
+
import type { LinkEmbed as LinkEmbedDefinition } from '../embeds/types.js';
|
|
3
4
|
export type RichTextProps = RichTextLinkOptions & {
|
|
4
5
|
/** From `parseRichText`, usually on the server. Takes precedence over `text`. */
|
|
5
6
|
content?: RichTextDocument | null;
|
|
@@ -12,9 +13,11 @@ export type RichTextProps = RichTextLinkOptions & {
|
|
|
12
13
|
/** Added to Markdown heading levels, e.g. 1 renders `#` as h2 below a page's h1. */
|
|
13
14
|
headingOffset?: number;
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* Show a bare link alone on its line as an embed: `true` for the app's embeds (see
|
|
17
|
+
* `setLinkEmbeds`, by default posts, profiles, YouTube and GIFs) or an explicit list.
|
|
17
18
|
*/
|
|
19
|
+
embeds?: boolean | readonly LinkEmbedDefinition[];
|
|
20
|
+
/** Custom matching instead of `embeds`; requires `linkEmbed`. */
|
|
18
21
|
embedLink?: (url: string) => boolean;
|
|
19
22
|
/** Renders such a link. The second argument renders the ordinary link, e.g. while loading. */
|
|
20
23
|
linkEmbed?: Snippet<[url: string, fallback: Snippet]>;
|