@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
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack, type Snippet } from 'svelte';
|
|
3
|
+
import type { Editor } from '@tiptap/core';
|
|
4
|
+
import { Captions, X } from '@sketchyicons/svelte';
|
|
5
|
+
import type {
|
|
6
|
+
ComposerLimits,
|
|
7
|
+
ComposerLinkPreview,
|
|
8
|
+
ComposerPost as Post
|
|
9
|
+
} from '../../social/composer.js';
|
|
10
|
+
import { editorJsonToBlueskyPost } from '../../social/richtext.js';
|
|
11
|
+
import { action, line as border, muted, recess } from '../../styles.js';
|
|
12
|
+
import Avatar from '../Avatar.svelte';
|
|
13
|
+
import Icon from '../Icon.svelte';
|
|
14
|
+
import IconButton from '../IconButton.svelte';
|
|
15
|
+
import InlineEditor from '../InlineEditor.svelte';
|
|
16
|
+
import LinkCard from '../LinkCard.svelte';
|
|
17
|
+
import type { ActorSearch } from '../login/types.js';
|
|
18
|
+
import AltText from './AltText.svelte';
|
|
19
|
+
|
|
20
|
+
// One post of the thread: its text and whatever is attached to it.
|
|
21
|
+
let {
|
|
22
|
+
post = $bindable(),
|
|
23
|
+
oneditor,
|
|
24
|
+
placeholder,
|
|
25
|
+
active,
|
|
26
|
+
line = false,
|
|
27
|
+
disabled = false,
|
|
28
|
+
author,
|
|
29
|
+
quote,
|
|
30
|
+
language,
|
|
31
|
+
limits,
|
|
32
|
+
searchActors,
|
|
33
|
+
linkPreview,
|
|
34
|
+
onfocus,
|
|
35
|
+
onremove
|
|
36
|
+
}: {
|
|
37
|
+
post: Post;
|
|
38
|
+
/** Receives the text editor once it exists, and null when it is gone. */
|
|
39
|
+
oneditor: (editor: Editor | null) => void;
|
|
40
|
+
placeholder: string;
|
|
41
|
+
active: boolean;
|
|
42
|
+
/** Draw the thread line down to the next post. */
|
|
43
|
+
line?: boolean;
|
|
44
|
+
disabled?: boolean;
|
|
45
|
+
author?: { name: string; avatar?: string };
|
|
46
|
+
quote?: Snippet;
|
|
47
|
+
/** Language for new caption files. */
|
|
48
|
+
language: string;
|
|
49
|
+
limits: ComposerLimits;
|
|
50
|
+
searchActors?: ActorSearch;
|
|
51
|
+
linkPreview?: ComposerLinkPreview;
|
|
52
|
+
onfocus: () => void;
|
|
53
|
+
onremove?: () => void;
|
|
54
|
+
} = $props();
|
|
55
|
+
|
|
56
|
+
let editor = $state<Editor | null>(null);
|
|
57
|
+
$effect(() => {
|
|
58
|
+
const instance = editor;
|
|
59
|
+
// The parent's bookkeeping must not become a dependency of this effect.
|
|
60
|
+
untrack(() => oneditor(instance));
|
|
61
|
+
return () => untrack(() => oneditor(null));
|
|
62
|
+
});
|
|
63
|
+
let hasMedia = $derived(post.images.length > 0 || !!post.video || !!post.gif);
|
|
64
|
+
let editing = $state<{ kind: 'image'; id: string } | { kind: 'video' } | { kind: 'gif' } | null>(
|
|
65
|
+
null
|
|
66
|
+
);
|
|
67
|
+
let altOpen = $state(false);
|
|
68
|
+
let captionInput = $state<HTMLInputElement>();
|
|
69
|
+
|
|
70
|
+
// Offer a preview card for the first link, unless other media takes the embed slot.
|
|
71
|
+
let dismissed = $state('');
|
|
72
|
+
let loadingLink = $state(false);
|
|
73
|
+
let firstLink = $derived(post.facets.flatMap((f) => f.features).find((f) => f.uri)?.uri ?? '');
|
|
74
|
+
$effect(() => {
|
|
75
|
+
const uri = firstLink;
|
|
76
|
+
const preview = linkPreview;
|
|
77
|
+
if (!preview || hasMedia || !uri || uri === dismissed) {
|
|
78
|
+
if (post.link && (!preview || hasMedia || post.link.uri !== uri)) post.link = undefined;
|
|
79
|
+
loadingLink = false;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (untrack(() => post.link?.uri) === uri) return;
|
|
83
|
+
const controller = new AbortController();
|
|
84
|
+
const timer = setTimeout(async () => {
|
|
85
|
+
loadingLink = true;
|
|
86
|
+
const card = await preview(uri, controller.signal).catch(() => undefined);
|
|
87
|
+
if (controller.signal.aborted) return;
|
|
88
|
+
loadingLink = false;
|
|
89
|
+
post.link = card;
|
|
90
|
+
}, 500);
|
|
91
|
+
return () => {
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
controller.abort();
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
function removeImage(id: string) {
|
|
98
|
+
const index = post.images.findIndex((image) => image.id === id);
|
|
99
|
+
if (index < 0) return;
|
|
100
|
+
URL.revokeObjectURL(post.images[index].url);
|
|
101
|
+
post.images.splice(index, 1);
|
|
102
|
+
}
|
|
103
|
+
function describe(target: NonNullable<typeof editing>) {
|
|
104
|
+
editing = target;
|
|
105
|
+
altOpen = true;
|
|
106
|
+
}
|
|
107
|
+
let altImage = $derived.by(() => {
|
|
108
|
+
const target = editing;
|
|
109
|
+
return target?.kind === 'image'
|
|
110
|
+
? post.images.find((image) => image.id === target.id)
|
|
111
|
+
: undefined;
|
|
112
|
+
});
|
|
113
|
+
const remove =
|
|
114
|
+
'absolute top-1.5 right-1.5 grid size-7 cursor-pointer place-items-center rounded-full bg-black/65 text-white hover:bg-black/85';
|
|
115
|
+
const badge =
|
|
116
|
+
'absolute bottom-1.5 left-1.5 cursor-pointer rounded bg-black/65 px-1.5 py-0.5 text-[11px] font-semibold tracking-wide text-white hover:bg-black/85';
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<div class="flex gap-3 {active ? '' : 'opacity-60'}" onfocusin={onfocus}>
|
|
120
|
+
{#if author}
|
|
121
|
+
<div class="flex shrink-0 flex-col items-center">
|
|
122
|
+
<Avatar name={author.name} src={author.avatar} size={40} />
|
|
123
|
+
{#if line}<div class="mt-1.5 w-0.5 flex-1 bg-base-300 dark:bg-base-700"></div>{/if}
|
|
124
|
+
</div>
|
|
125
|
+
{/if}
|
|
126
|
+
|
|
127
|
+
<div class="min-w-0 flex-1 pb-4">
|
|
128
|
+
<div class="flex items-start gap-2">
|
|
129
|
+
<InlineEditor
|
|
130
|
+
bind:value={post.text}
|
|
131
|
+
bind:editor
|
|
132
|
+
label="Post text"
|
|
133
|
+
{placeholder}
|
|
134
|
+
{searchActors}
|
|
135
|
+
{disabled}
|
|
136
|
+
onupdate={({ json }) => (post.facets = editorJsonToBlueskyPost(json).facets)}
|
|
137
|
+
class="min-h-[4.5rem] flex-1 pt-1.5 text-[17px] leading-snug focus-within:outline-none"
|
|
138
|
+
/>
|
|
139
|
+
{#if onremove}
|
|
140
|
+
<IconButton label="Remove post" size="sm" {disabled} onclick={onremove}>
|
|
141
|
+
<Icon img={X} size={16} />
|
|
142
|
+
</IconButton>
|
|
143
|
+
{/if}
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
{#if post.images.length}
|
|
147
|
+
{@const single = post.images.length === 1}
|
|
148
|
+
<div
|
|
149
|
+
class="mt-2 grid gap-1.5 {single
|
|
150
|
+
? ''
|
|
151
|
+
: post.images.length <= 4
|
|
152
|
+
? 'grid-cols-2'
|
|
153
|
+
: 'grid-cols-3'}"
|
|
154
|
+
>
|
|
155
|
+
{#each post.images as image (image.id)}
|
|
156
|
+
<div
|
|
157
|
+
class="relative overflow-hidden rounded-ui border {border} {recess} {single
|
|
158
|
+
? 'max-h-80'
|
|
159
|
+
: 'aspect-square'}"
|
|
160
|
+
>
|
|
161
|
+
<img
|
|
162
|
+
src={image.url}
|
|
163
|
+
alt={image.alt}
|
|
164
|
+
class="size-full {single ? 'max-h-80 object-contain' : 'object-cover'}"
|
|
165
|
+
/>
|
|
166
|
+
<button
|
|
167
|
+
type="button"
|
|
168
|
+
class={badge}
|
|
169
|
+
{disabled}
|
|
170
|
+
aria-label={image.alt ? 'Edit image description' : 'Add image description'}
|
|
171
|
+
onclick={() => describe({ kind: 'image', id: image.id })}
|
|
172
|
+
>
|
|
173
|
+
{image.alt ? 'ALT ✓' : '+ ALT'}
|
|
174
|
+
</button>
|
|
175
|
+
<button
|
|
176
|
+
type="button"
|
|
177
|
+
class={remove}
|
|
178
|
+
aria-label="Remove image"
|
|
179
|
+
{disabled}
|
|
180
|
+
onclick={() => removeImage(image.id)}><Icon img={X} size={15} /></button
|
|
181
|
+
>
|
|
182
|
+
</div>
|
|
183
|
+
{/each}
|
|
184
|
+
</div>
|
|
185
|
+
{/if}
|
|
186
|
+
|
|
187
|
+
{#if post.video}
|
|
188
|
+
{@const video = post.video}
|
|
189
|
+
<div class="relative mt-2 overflow-hidden rounded-ui border bg-black {border}">
|
|
190
|
+
<!-- svelte-ignore a11y_media_has_caption -->
|
|
191
|
+
<video src={video.url} controls class="max-h-80 w-full"></video>
|
|
192
|
+
<button
|
|
193
|
+
type="button"
|
|
194
|
+
class={remove}
|
|
195
|
+
aria-label="Remove video"
|
|
196
|
+
{disabled}
|
|
197
|
+
onclick={() => {
|
|
198
|
+
URL.revokeObjectURL(video.url);
|
|
199
|
+
post.video = undefined;
|
|
200
|
+
}}><Icon img={X} size={15} /></button
|
|
201
|
+
>
|
|
202
|
+
</div>
|
|
203
|
+
<div class="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[13px]">
|
|
204
|
+
<button
|
|
205
|
+
type="button"
|
|
206
|
+
class="cursor-pointer hover:underline {action}"
|
|
207
|
+
onclick={() => describe({ kind: 'video' })}
|
|
208
|
+
>
|
|
209
|
+
{video.alt ? 'Edit description' : 'Add description'}
|
|
210
|
+
</button>
|
|
211
|
+
<button
|
|
212
|
+
type="button"
|
|
213
|
+
class="flex cursor-pointer items-center gap-1 hover:underline {action}"
|
|
214
|
+
onclick={() => captionInput?.click()}
|
|
215
|
+
>
|
|
216
|
+
<Icon img={Captions} size={15} /> Add captions (.vtt)
|
|
217
|
+
</button>
|
|
218
|
+
{#each video.captions as caption, index (index)}
|
|
219
|
+
<span class="flex items-center gap-1 {muted}">
|
|
220
|
+
{caption.lang}: {caption.file.name}
|
|
221
|
+
<button
|
|
222
|
+
type="button"
|
|
223
|
+
class="cursor-pointer hover:text-base-950 dark:hover:text-base-50"
|
|
224
|
+
aria-label="Remove captions"
|
|
225
|
+
onclick={() => video.captions.splice(index, 1)}><Icon img={X} size={13} /></button
|
|
226
|
+
>
|
|
227
|
+
</span>
|
|
228
|
+
{/each}
|
|
229
|
+
<input
|
|
230
|
+
bind:this={captionInput}
|
|
231
|
+
type="file"
|
|
232
|
+
accept=".vtt,text/vtt"
|
|
233
|
+
hidden
|
|
234
|
+
onchange={(e) => {
|
|
235
|
+
const file = e.currentTarget.files?.[0];
|
|
236
|
+
e.currentTarget.value = '';
|
|
237
|
+
if (file && file.size <= limits.captionBytes)
|
|
238
|
+
video.captions.push({ lang: language, file });
|
|
239
|
+
}}
|
|
240
|
+
/>
|
|
241
|
+
</div>
|
|
242
|
+
{/if}
|
|
243
|
+
|
|
244
|
+
{#if post.gif}
|
|
245
|
+
{@const gif = post.gif}
|
|
246
|
+
<div
|
|
247
|
+
class="relative mt-2 max-h-80 overflow-hidden rounded-ui border {border} {recess}"
|
|
248
|
+
style="aspect-ratio:{gif.width}/{gif.height}"
|
|
249
|
+
>
|
|
250
|
+
<img src={gif.preview} alt={gif.alt || gif.title} class="size-full object-cover" />
|
|
251
|
+
<button
|
|
252
|
+
type="button"
|
|
253
|
+
class={badge}
|
|
254
|
+
{disabled}
|
|
255
|
+
aria-label={gif.alt ? 'Edit GIF description' : 'Add GIF description'}
|
|
256
|
+
onclick={() => describe({ kind: 'gif' })}
|
|
257
|
+
>
|
|
258
|
+
{gif.alt ? 'ALT ✓' : '+ ALT'}
|
|
259
|
+
</button>
|
|
260
|
+
<button
|
|
261
|
+
type="button"
|
|
262
|
+
class={remove}
|
|
263
|
+
aria-label="Remove GIF"
|
|
264
|
+
{disabled}
|
|
265
|
+
onclick={() => (post.gif = undefined)}><Icon img={X} size={15} /></button
|
|
266
|
+
>
|
|
267
|
+
</div>
|
|
268
|
+
{/if}
|
|
269
|
+
|
|
270
|
+
{#if post.link && !hasMedia}
|
|
271
|
+
{@const link = post.link}
|
|
272
|
+
<div class="relative mt-2">
|
|
273
|
+
<LinkCard
|
|
274
|
+
href={link.uri}
|
|
275
|
+
meta={{ title: link.title, image: link.image }}
|
|
276
|
+
class="[&>span:first-of-type]:pr-12"
|
|
277
|
+
/>
|
|
278
|
+
<button
|
|
279
|
+
type="button"
|
|
280
|
+
class={remove}
|
|
281
|
+
aria-label="Remove link preview"
|
|
282
|
+
{disabled}
|
|
283
|
+
onclick={() => {
|
|
284
|
+
dismissed = link.uri;
|
|
285
|
+
post.link = undefined;
|
|
286
|
+
}}><Icon img={X} size={15} /></button
|
|
287
|
+
>
|
|
288
|
+
</div>
|
|
289
|
+
{:else if loadingLink}
|
|
290
|
+
<div
|
|
291
|
+
class="mt-2 h-16 animate-pulse rounded-ui border motion-reduce:animate-none {border} {recess}"
|
|
292
|
+
></div>
|
|
293
|
+
{/if}
|
|
294
|
+
|
|
295
|
+
{#if quote}<div class="pointer-events-none mt-2">{@render quote()}</div>{/if}
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
|
|
299
|
+
{#if editing?.kind === 'image' && altImage}
|
|
300
|
+
<AltText
|
|
301
|
+
bind:open={altOpen}
|
|
302
|
+
bind:value={altImage.alt}
|
|
303
|
+
preview={altImage.url}
|
|
304
|
+
max={limits.altLength}
|
|
305
|
+
/>
|
|
306
|
+
{:else if editing?.kind === 'video' && post.video}
|
|
307
|
+
<AltText
|
|
308
|
+
bind:open={altOpen}
|
|
309
|
+
bind:value={post.video.alt}
|
|
310
|
+
preview={post.video.url}
|
|
311
|
+
video
|
|
312
|
+
max={limits.altLength}
|
|
313
|
+
/>
|
|
314
|
+
{:else if editing?.kind === 'gif' && post.gif}
|
|
315
|
+
<AltText
|
|
316
|
+
bind:open={altOpen}
|
|
317
|
+
bind:value={post.gif.alt}
|
|
318
|
+
preview={post.gif.preview}
|
|
319
|
+
max={limits.altLength}
|
|
320
|
+
/>
|
|
321
|
+
{/if}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { Editor } from '@tiptap/core';
|
|
3
|
+
import type { ComposerLimits, ComposerLinkPreview, ComposerPost as Post } from '../../social/composer.js';
|
|
4
|
+
import type { ActorSearch } from '../login/types.js';
|
|
5
|
+
type $$ComponentProps = {
|
|
6
|
+
post: Post;
|
|
7
|
+
/** Receives the text editor once it exists, and null when it is gone. */
|
|
8
|
+
oneditor: (editor: Editor | null) => void;
|
|
9
|
+
placeholder: string;
|
|
10
|
+
active: boolean;
|
|
11
|
+
/** Draw the thread line down to the next post. */
|
|
12
|
+
line?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
author?: {
|
|
15
|
+
name: string;
|
|
16
|
+
avatar?: string;
|
|
17
|
+
};
|
|
18
|
+
quote?: Snippet;
|
|
19
|
+
/** Language for new caption files. */
|
|
20
|
+
language: string;
|
|
21
|
+
limits: ComposerLimits;
|
|
22
|
+
searchActors?: ActorSearch;
|
|
23
|
+
linkPreview?: ComposerLinkPreview;
|
|
24
|
+
onfocus: () => void;
|
|
25
|
+
onremove?: () => void;
|
|
26
|
+
};
|
|
27
|
+
declare const ComposerPost: import("svelte").Component<$$ComponentProps, {}, "post">;
|
|
28
|
+
type ComposerPost = ReturnType<typeof ComposerPost>;
|
|
29
|
+
export default ComposerPost;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { LoaderCircle, Trash2 } from '@sketchyicons/svelte';
|
|
3
|
+
import type { ComposerDraftSummary, ComposerDrafts } from '../../social/composer.js';
|
|
4
|
+
import { hoverRecess, muted } from '../../styles.js';
|
|
5
|
+
import Icon from '../Icon.svelte';
|
|
6
|
+
import IconButton from '../IconButton.svelte';
|
|
7
|
+
import Modal from '../Modal.svelte';
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
open = $bindable(false),
|
|
11
|
+
store,
|
|
12
|
+
onselect
|
|
13
|
+
}: {
|
|
14
|
+
open?: boolean;
|
|
15
|
+
store: ComposerDrafts;
|
|
16
|
+
onselect: (draft: ComposerDraftSummary) => void;
|
|
17
|
+
} = $props();
|
|
18
|
+
|
|
19
|
+
let drafts = $state.raw<ComposerDraftSummary[]>([]);
|
|
20
|
+
let loading = $state(false);
|
|
21
|
+
let error = $state('');
|
|
22
|
+
const message = (e: unknown) => (e instanceof Error ? e.message : 'Something went wrong');
|
|
23
|
+
|
|
24
|
+
$effect(() => {
|
|
25
|
+
if (!open) return;
|
|
26
|
+
loading = true;
|
|
27
|
+
error = '';
|
|
28
|
+
void store
|
|
29
|
+
.list()
|
|
30
|
+
.then((list) => (drafts = list))
|
|
31
|
+
.catch((e) => (error = message(e)))
|
|
32
|
+
.finally(() => (loading = false));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
async function remove(draft: ComposerDraftSummary) {
|
|
36
|
+
try {
|
|
37
|
+
await store.delete(draft);
|
|
38
|
+
drafts = drafts.filter((d) => d.id !== draft.id);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
error = message(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const dates = new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
|
44
|
+
function when(value: string | Date | undefined) {
|
|
45
|
+
const date = value ? new Date(value) : undefined;
|
|
46
|
+
return date && !Number.isNaN(date.getTime()) ? dates.format(date) : '';
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<Modal bind:open title="Drafts" class="max-w-md">
|
|
51
|
+
{#if loading && !drafts.length}
|
|
52
|
+
<div class="flex justify-center py-6 {muted}" role="status" aria-label="Loading">
|
|
53
|
+
<Icon img={LoaderCircle} size={20} class="animate-spin motion-reduce:animate-none" />
|
|
54
|
+
</div>
|
|
55
|
+
{:else if error}
|
|
56
|
+
<p class="text-sm {muted}" role="alert">{error}</p>
|
|
57
|
+
{:else if !drafts.length}
|
|
58
|
+
<p class="text-sm {muted}">No drafts</p>
|
|
59
|
+
{:else}
|
|
60
|
+
<ul class="-mx-2 grid gap-1">
|
|
61
|
+
{#each drafts as draft (draft.id)}
|
|
62
|
+
{@const detail = [when(draft.updatedAt), draft.detail].filter(Boolean).join(' · ')}
|
|
63
|
+
<li class="flex items-center gap-1">
|
|
64
|
+
<button
|
|
65
|
+
type="button"
|
|
66
|
+
class="min-w-0 flex-1 cursor-pointer rounded-ui px-2 py-2 text-left {hoverRecess}"
|
|
67
|
+
onclick={() => {
|
|
68
|
+
onselect(draft);
|
|
69
|
+
open = false;
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
<span class="line-clamp-2 text-sm wrap-anywhere">{draft.text || 'Empty draft'}</span>
|
|
73
|
+
{#if detail}<span class="mt-0.5 block text-xs {muted}">{detail}</span>{/if}
|
|
74
|
+
</button>
|
|
75
|
+
<IconButton label="Delete draft" size="sm" onclick={() => remove(draft)}>
|
|
76
|
+
<Icon img={Trash2} size={17} />
|
|
77
|
+
</IconButton>
|
|
78
|
+
</li>
|
|
79
|
+
{/each}
|
|
80
|
+
</ul>
|
|
81
|
+
{/if}
|
|
82
|
+
</Modal>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ComposerDraftSummary, ComposerDrafts } from '../../social/composer.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
open?: boolean;
|
|
4
|
+
store: ComposerDrafts;
|
|
5
|
+
onselect: (draft: ComposerDraftSummary) => void;
|
|
6
|
+
};
|
|
7
|
+
declare const Drafts: import("svelte").Component<$$ComponentProps, {}, "open">;
|
|
8
|
+
type Drafts = ReturnType<typeof Drafts>;
|
|
9
|
+
export default Drafts;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Smile } from '@sketchyicons/svelte';
|
|
3
|
+
import { muted } from '../../styles.js';
|
|
4
|
+
import Icon from '../Icon.svelte';
|
|
5
|
+
import IconButton from '../IconButton.svelte';
|
|
6
|
+
import Popover from '../Popover.svelte';
|
|
7
|
+
|
|
8
|
+
let { onselect, disabled = false }: { onselect: (emoji: string) => void; disabled?: boolean } =
|
|
9
|
+
$props();
|
|
10
|
+
|
|
11
|
+
let open = $state(false);
|
|
12
|
+
let ready = $state(false);
|
|
13
|
+
// The picker and its emoji data are only fetched when first opened.
|
|
14
|
+
$effect(() => {
|
|
15
|
+
if (open && !ready) void import('emoji-picker-element').then(() => (ready = true));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function attach(node: HTMLElement) {
|
|
19
|
+
const pick = (event: Event) => {
|
|
20
|
+
const detail = (event as CustomEvent<{ unicode?: string }>).detail;
|
|
21
|
+
if (detail.unicode) onselect(detail.unicode);
|
|
22
|
+
};
|
|
23
|
+
node.addEventListener('emoji-click', pick);
|
|
24
|
+
return () => node.removeEventListener('emoji-click', pick);
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<Popover bind:open class="overflow-hidden p-0" align="start">
|
|
29
|
+
{#snippet trigger({ props })}
|
|
30
|
+
<IconButton {...props} label="Emoji" {disabled}><Icon img={Smile} /></IconButton>
|
|
31
|
+
{/snippet}
|
|
32
|
+
{#if ready}
|
|
33
|
+
<emoji-picker
|
|
34
|
+
{@attach attach}
|
|
35
|
+
class="emoji [--button-active-background:var(--base-300)] [--button-hover-background:var(--base-200)] [--input-border-color:var(--base-300)] [--input-font-color:var(--base-950)] [--input-placeholder-color:var(--base-600)] dark:[--button-active-background:var(--base-700)] dark:[--button-hover-background:var(--base-800)] dark:[--input-border-color:var(--base-800)] dark:[--input-font-color:var(--base-50)] dark:[--input-placeholder-color:var(--base-400)]"
|
|
36
|
+
></emoji-picker>
|
|
37
|
+
{:else}
|
|
38
|
+
<div class="grid h-80 w-80 place-items-center text-sm {muted}">Loading…</div>
|
|
39
|
+
{/if}
|
|
40
|
+
</Popover>
|
|
41
|
+
|
|
42
|
+
<style>
|
|
43
|
+
.emoji {
|
|
44
|
+
--background: transparent;
|
|
45
|
+
--border-size: 0;
|
|
46
|
+
--border-color: transparent;
|
|
47
|
+
--indicator-color: var(--accent-500);
|
|
48
|
+
--outline-color: var(--accent-500);
|
|
49
|
+
--num-columns: 8;
|
|
50
|
+
--emoji-size: 1.35rem;
|
|
51
|
+
width: 21rem;
|
|
52
|
+
height: 22rem;
|
|
53
|
+
max-width: calc(100vw - 2rem);
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { LoaderCircle } from '@sketchyicons/svelte';
|
|
3
|
+
import type { ComposerGif, ComposerGifResult, ComposerGifSearch } from '../../social/composer.js';
|
|
4
|
+
import { muted, recess } from '../../styles.js';
|
|
5
|
+
import Button from '../Button.svelte';
|
|
6
|
+
import Icon from '../Icon.svelte';
|
|
7
|
+
import Input from '../Input.svelte';
|
|
8
|
+
import Modal from '../Modal.svelte';
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
open = $bindable(false),
|
|
12
|
+
search,
|
|
13
|
+
credit,
|
|
14
|
+
onselect
|
|
15
|
+
}: {
|
|
16
|
+
open?: boolean;
|
|
17
|
+
search: ComposerGifSearch;
|
|
18
|
+
/** Attribution the GIF service asks for. */
|
|
19
|
+
credit?: string;
|
|
20
|
+
onselect: (gif: ComposerGif) => void;
|
|
21
|
+
} = $props();
|
|
22
|
+
|
|
23
|
+
let q = $state('');
|
|
24
|
+
let results = $state.raw<ComposerGifResult[]>([]);
|
|
25
|
+
let next = $state<string>();
|
|
26
|
+
let loading = $state(false);
|
|
27
|
+
let error = $state('');
|
|
28
|
+
|
|
29
|
+
// Featured GIFs for an empty query; search follows typing after a short pause.
|
|
30
|
+
$effect(() => {
|
|
31
|
+
if (!open) return;
|
|
32
|
+
const term = q.trim();
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
const timer = setTimeout(
|
|
35
|
+
async () => {
|
|
36
|
+
loading = true;
|
|
37
|
+
error = '';
|
|
38
|
+
try {
|
|
39
|
+
const page = await search(term, undefined, controller.signal);
|
|
40
|
+
results = page.gifs;
|
|
41
|
+
next = page.cursor;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
if (!controller.signal.aborted) error = (e as Error).message;
|
|
44
|
+
} finally {
|
|
45
|
+
if (!controller.signal.aborted) loading = false;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
term ? 250 : 0
|
|
49
|
+
);
|
|
50
|
+
return () => {
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
controller.abort();
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
$effect(() => {
|
|
56
|
+
if (!open) q = '';
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
async function more() {
|
|
60
|
+
if (!next || loading) return;
|
|
61
|
+
loading = true;
|
|
62
|
+
try {
|
|
63
|
+
const page = await search(q.trim(), next);
|
|
64
|
+
results = [...results, ...page.gifs];
|
|
65
|
+
next = page.cursor;
|
|
66
|
+
} catch {
|
|
67
|
+
next = undefined;
|
|
68
|
+
} finally {
|
|
69
|
+
loading = false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<Modal bind:open title="GIFs" class="max-w-xl p-5 sm:p-6 [&>header]:mb-4">
|
|
75
|
+
<Input
|
|
76
|
+
type="search"
|
|
77
|
+
bind:value={q}
|
|
78
|
+
placeholder="Search GIFs"
|
|
79
|
+
aria-label="Search GIFs"
|
|
80
|
+
data-autofocus
|
|
81
|
+
/>
|
|
82
|
+
<div class="mt-4 min-h-64">
|
|
83
|
+
{#if error}
|
|
84
|
+
<p class="py-10 text-center text-sm {muted}">{error}</p>
|
|
85
|
+
{:else}
|
|
86
|
+
<div class="columns-2 gap-2 sm:columns-3">
|
|
87
|
+
{#each results as gif (gif.id)}
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
class="mb-2 block w-full cursor-pointer overflow-hidden rounded-ui focus-visible:outline-2 focus-visible:outline-accent-500 {recess}"
|
|
91
|
+
style="aspect-ratio:{gif.width}/{gif.height}"
|
|
92
|
+
aria-label={gif.title}
|
|
93
|
+
onclick={() => {
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- the id is the picker's
|
|
95
|
+
const { id, ...picked } = gif;
|
|
96
|
+
onselect(picked);
|
|
97
|
+
open = false;
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
<img src={gif.preview} alt="" loading="lazy" class="size-full object-cover" />
|
|
101
|
+
</button>
|
|
102
|
+
{/each}
|
|
103
|
+
</div>
|
|
104
|
+
{#if loading}
|
|
105
|
+
<div class="flex justify-center py-6 {muted}" role="status" aria-label="Loading">
|
|
106
|
+
<Icon img={LoaderCircle} size={20} class="animate-spin motion-reduce:animate-none" />
|
|
107
|
+
</div>
|
|
108
|
+
{:else if next}
|
|
109
|
+
<div class="flex justify-center py-3">
|
|
110
|
+
<Button variant="secondary" size="sm" onclick={more}>More</Button>
|
|
111
|
+
</div>
|
|
112
|
+
{:else if !results.length}
|
|
113
|
+
<p class="py-10 text-center text-sm {muted}">No GIFs found</p>
|
|
114
|
+
{/if}
|
|
115
|
+
{/if}
|
|
116
|
+
</div>
|
|
117
|
+
{#if credit}<p class="mt-3 text-center text-[11px] {muted}">{credit}</p>{/if}
|
|
118
|
+
</Modal>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComposerGif, ComposerGifSearch } from '../../social/composer.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
open?: boolean;
|
|
4
|
+
search: ComposerGifSearch;
|
|
5
|
+
/** Attribution the GIF service asks for. */
|
|
6
|
+
credit?: string;
|
|
7
|
+
onselect: (gif: ComposerGif) => void;
|
|
8
|
+
};
|
|
9
|
+
declare const GifPicker: import("svelte").Component<$$ComponentProps, {}, "open">;
|
|
10
|
+
type GifPicker = ReturnType<typeof GifPicker>;
|
|
11
|
+
export default GifPicker;
|