@atmo-dev/kit 0.14.0 → 0.15.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.
- 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 +272 -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 +29 -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 +9 -8
- package/dist/richtext/serialize.d.ts +11 -0
- package/dist/richtext/serialize.js +462 -0
- package/dist/richtext/vendor/markdown-tree.d.ts +5 -0
- package/dist/richtext/vendor/markdown-tree.js +11032 -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 +8 -4
- package/dist/components/PostComposer.svelte +0 -41
- package/dist/components/PostComposer.svelte.d.ts +0 -16
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
ComposerContent,
|
|
5
|
+
ComposerContentWarning,
|
|
6
|
+
ComposerDrafts,
|
|
7
|
+
ComposerFeatures,
|
|
8
|
+
ComposerGifSearch,
|
|
9
|
+
ComposerLabels,
|
|
10
|
+
ComposerLimits,
|
|
11
|
+
ComposerLinkPreview,
|
|
12
|
+
ComposerPost as Post,
|
|
13
|
+
ComposerReplyRule
|
|
14
|
+
} from '../../social/composer.js';
|
|
15
|
+
import type { ActorSearch } from '../login/types.js';
|
|
16
|
+
|
|
17
|
+
export type PostComposerProps = {
|
|
18
|
+
/**
|
|
19
|
+
* Publish the posts. Report progress through `status`; throw to show an error and keep
|
|
20
|
+
* the content. The composer clears once this resolves.
|
|
21
|
+
*/
|
|
22
|
+
onsubmit: (content: ComposerContent, status: (text: string) => void) => Promise<void>;
|
|
23
|
+
/** Adds a Cancel button. Called once the content is discarded, saved or was empty. */
|
|
24
|
+
oncancel?: () => void;
|
|
25
|
+
/** Shown beside each post. */
|
|
26
|
+
author?: { name: string; avatar?: string };
|
|
27
|
+
/** The post being replied to. Replies have no reply rules and no drafts. */
|
|
28
|
+
replyTo?: { name: string; text?: string };
|
|
29
|
+
/** The quoted post, rendered under the first post. A quote can be posted without text. */
|
|
30
|
+
quote?: Snippet;
|
|
31
|
+
/** Put the cursor in the text once the composer appears. */
|
|
32
|
+
autofocus?: boolean;
|
|
33
|
+
/** Starting text and files. */
|
|
34
|
+
text?: string;
|
|
35
|
+
files?: Iterable<File>;
|
|
36
|
+
languages?: string[];
|
|
37
|
+
/** Language codes offered in the picker. */
|
|
38
|
+
languageOptions?: readonly string[];
|
|
39
|
+
replyRules?: ComposerReplyRule[];
|
|
40
|
+
allowQuotes?: boolean;
|
|
41
|
+
/** Lists that can be allowed to reply. */
|
|
42
|
+
replyLists?: { uri: string; name: string }[] | (() => Promise<{ uri: string; name: string }[]>);
|
|
43
|
+
/** Adds "Save as default" to the interaction settings. */
|
|
44
|
+
onsavedefault?: (rules: ComposerReplyRule[] | undefined, allowQuotes: boolean) => Promise<void>;
|
|
45
|
+
/** Every image needs a description before posting. */
|
|
46
|
+
requireAlt?: boolean;
|
|
47
|
+
features?: Partial<ComposerFeatures>;
|
|
48
|
+
limits?: Partial<ComposerLimits>;
|
|
49
|
+
labels?: Partial<ComposerLabels>;
|
|
50
|
+
contentWarnings?: readonly ComposerContentWarning[];
|
|
51
|
+
searchActors?: ActorSearch;
|
|
52
|
+
/** Enables the GIF button, e.g. `blueskyGifSearch`. */
|
|
53
|
+
searchGifs?: ComposerGifSearch;
|
|
54
|
+
gifCredit?: string;
|
|
55
|
+
/** Enables link preview cards, e.g. `blueskyLinkPreview`. */
|
|
56
|
+
linkPreview?: ComposerLinkPreview;
|
|
57
|
+
/** Enables drafts. */
|
|
58
|
+
drafts?: ComposerDrafts;
|
|
59
|
+
/** More toolbar buttons, after the built-in ones. */
|
|
60
|
+
actions?: Snippet<[{ post: Post; insert: (text: string) => void; disabled: boolean }]>;
|
|
61
|
+
class?: string;
|
|
62
|
+
};
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<script lang="ts">
|
|
66
|
+
import { tick, untrack } from 'svelte';
|
|
67
|
+
import type { Editor } from '@tiptap/core';
|
|
68
|
+
import { Film, Globe, Image as ImageIcon, Languages, Plus, Sticker } from '@sketchyicons/svelte';
|
|
69
|
+
import {
|
|
70
|
+
blankComposerPost,
|
|
71
|
+
browserLanguage,
|
|
72
|
+
defaultComposerLanguages,
|
|
73
|
+
defaultComposerLimits,
|
|
74
|
+
defaultContentWarnings,
|
|
75
|
+
releaseComposerPosts,
|
|
76
|
+
videoDimensions,
|
|
77
|
+
type ComposerDraftSummary,
|
|
78
|
+
type ComposerGif
|
|
79
|
+
} from '../../social/composer.js';
|
|
80
|
+
import { graphemeLength } from '../../social/richtext.js';
|
|
81
|
+
import { action, hoverRecess, line, muted } from '../../styles.js';
|
|
82
|
+
import { cn } from '../../utils.js';
|
|
83
|
+
import Button from '../Button.svelte';
|
|
84
|
+
import Checkbox from '../Checkbox.svelte';
|
|
85
|
+
import Icon from '../Icon.svelte';
|
|
86
|
+
import IconButton from '../IconButton.svelte';
|
|
87
|
+
import Modal from '../Modal.svelte';
|
|
88
|
+
import Popover from '../Popover.svelte';
|
|
89
|
+
import Select from '../Select.svelte';
|
|
90
|
+
import CharRing from './CharRing.svelte';
|
|
91
|
+
import ComposerPost from './ComposerPost.svelte';
|
|
92
|
+
import Drafts from './Drafts.svelte';
|
|
93
|
+
import EmojiPicker from './EmojiPicker.svelte';
|
|
94
|
+
import GifPicker from './GifPicker.svelte';
|
|
95
|
+
import ReplySettings from './ReplySettings.svelte';
|
|
96
|
+
|
|
97
|
+
let {
|
|
98
|
+
onsubmit,
|
|
99
|
+
oncancel,
|
|
100
|
+
author,
|
|
101
|
+
replyTo,
|
|
102
|
+
quote,
|
|
103
|
+
autofocus = false,
|
|
104
|
+
text = '',
|
|
105
|
+
files,
|
|
106
|
+
languages = $bindable([browserLanguage()]),
|
|
107
|
+
languageOptions = defaultComposerLanguages,
|
|
108
|
+
replyRules = $bindable(),
|
|
109
|
+
allowQuotes = $bindable(true),
|
|
110
|
+
replyLists,
|
|
111
|
+
onsavedefault,
|
|
112
|
+
requireAlt = false,
|
|
113
|
+
features = {},
|
|
114
|
+
limits: limitOverrides = {},
|
|
115
|
+
labels = {},
|
|
116
|
+
contentWarnings = defaultContentWarnings,
|
|
117
|
+
searchActors,
|
|
118
|
+
searchGifs,
|
|
119
|
+
gifCredit,
|
|
120
|
+
linkPreview,
|
|
121
|
+
drafts: draftStore,
|
|
122
|
+
actions,
|
|
123
|
+
class: className
|
|
124
|
+
}: PostComposerProps = $props();
|
|
125
|
+
|
|
126
|
+
let limits = $derived({ ...defaultComposerLimits, ...limitOverrides });
|
|
127
|
+
const on = (feature: keyof ComposerFeatures) => features[feature] !== false;
|
|
128
|
+
let reply = $derived(!!replyTo);
|
|
129
|
+
let canDraft = $derived(!!draftStore && on('drafts') && !reply);
|
|
130
|
+
|
|
131
|
+
let posts = $state<Post[]>([blankComposerPost(untrack(() => text))]);
|
|
132
|
+
// Text editors by post id.
|
|
133
|
+
let editors = $state.raw<Record<string, Editor | null>>({});
|
|
134
|
+
let active = $state(0);
|
|
135
|
+
let draft = $state.raw<ComposerDraftSummary>();
|
|
136
|
+
let busy = $state(false);
|
|
137
|
+
let status = $state('');
|
|
138
|
+
let error = $state('');
|
|
139
|
+
let gifsOpen = $state(false);
|
|
140
|
+
let interactionsOpen = $state(false);
|
|
141
|
+
let draftsOpen = $state(false);
|
|
142
|
+
let leaving = $state(false);
|
|
143
|
+
let dragging = $state(false);
|
|
144
|
+
let imageInput = $state<HTMLInputElement>();
|
|
145
|
+
let videoInput = $state<HTMLInputElement>();
|
|
146
|
+
const message = (e: unknown) => (e instanceof Error ? e.message : 'Something went wrong');
|
|
147
|
+
|
|
148
|
+
$effect(() => {
|
|
149
|
+
const initial = untrack(() => files);
|
|
150
|
+
if (initial) void addFiles(initial);
|
|
151
|
+
return () => releaseComposerPosts(untrack(() => posts));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// The editor is created after the composer mounts, so focus follows it.
|
|
155
|
+
let focused = false;
|
|
156
|
+
$effect(() => {
|
|
157
|
+
const editor = editors[posts[0].id];
|
|
158
|
+
if (!autofocus || focused || !editor) return;
|
|
159
|
+
focused = true;
|
|
160
|
+
editor.commands.focus('end');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
let current = $derived(posts[Math.min(active, posts.length - 1)]);
|
|
164
|
+
const lengthOf = (post: Post) => graphemeLength(post.text.trim());
|
|
165
|
+
const hasMedia = (post: Post) => post.images.length > 0 || !!post.video || !!post.gif;
|
|
166
|
+
const isEmpty = (post: Post, index: number) =>
|
|
167
|
+
!lengthOf(post) && !hasMedia(post) && !(index === 0 && quote);
|
|
168
|
+
let dirty = $derived(posts.some((post, index) => !isEmpty(post, index) || !!post.link));
|
|
169
|
+
let missingAlt = $derived(
|
|
170
|
+
requireAlt && posts.some((p) => p.images.some((image) => !image.alt.trim()))
|
|
171
|
+
);
|
|
172
|
+
let canPost = $derived(
|
|
173
|
+
!busy &&
|
|
174
|
+
!missingAlt &&
|
|
175
|
+
posts.some((post, index) => !isEmpty(post, index)) &&
|
|
176
|
+
posts.every((post) => lengthOf(post) <= limits.length)
|
|
177
|
+
);
|
|
178
|
+
let replyLabel = $derived(
|
|
179
|
+
!replyRules ? 'Anyone can reply' : replyRules.length ? 'Some people can reply' : 'Replies off'
|
|
180
|
+
);
|
|
181
|
+
const names =
|
|
182
|
+
typeof Intl.DisplayNames === 'function'
|
|
183
|
+
? new Intl.DisplayNames(undefined, { type: 'language' })
|
|
184
|
+
: undefined;
|
|
185
|
+
function languageName(code: string) {
|
|
186
|
+
try {
|
|
187
|
+
return names?.of(code) ?? code;
|
|
188
|
+
} catch {
|
|
189
|
+
return code;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Attach images or a video to the post being written. */
|
|
194
|
+
export async function addFiles(added: Iterable<File>) {
|
|
195
|
+
error = '';
|
|
196
|
+
const post = current;
|
|
197
|
+
for (const file of added) {
|
|
198
|
+
if (file.type.startsWith('image/') && file.type !== 'image/gif') {
|
|
199
|
+
if (!on('images') || post.video || post.gif) continue;
|
|
200
|
+
if (post.images.length >= limits.images) {
|
|
201
|
+
error = `A post can have up to ${limits.images} images`;
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
post.images.push({
|
|
205
|
+
id: crypto.randomUUID(),
|
|
206
|
+
file,
|
|
207
|
+
url: URL.createObjectURL(file),
|
|
208
|
+
alt: ''
|
|
209
|
+
});
|
|
210
|
+
} else if (file.type.startsWith('video/') || file.type === 'image/gif') {
|
|
211
|
+
if (!on('video') || post.images.length || post.video || post.gif) continue;
|
|
212
|
+
if (file.size > limits.videoBytes) {
|
|
213
|
+
error = `Videos can be up to ${Math.round(limits.videoBytes / 1_000_000)} MB`;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
post.video = {
|
|
217
|
+
file,
|
|
218
|
+
url: URL.createObjectURL(file),
|
|
219
|
+
alt: '',
|
|
220
|
+
captions: [],
|
|
221
|
+
...(await videoDimensions(file))
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function paste(event: ClipboardEvent) {
|
|
227
|
+
const pasted = [...(event.clipboardData?.files ?? [])];
|
|
228
|
+
if (!pasted.length) return;
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
void addFiles(pasted);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const hasFiles = (event: DragEvent) => event.dataTransfer?.types.includes('Files') ?? false;
|
|
234
|
+
let dragDepth = 0;
|
|
235
|
+
function dragEnter(event: DragEvent) {
|
|
236
|
+
if (!hasFiles(event)) return;
|
|
237
|
+
dragDepth++;
|
|
238
|
+
dragging = true;
|
|
239
|
+
}
|
|
240
|
+
function dragLeave(event: DragEvent) {
|
|
241
|
+
if (!hasFiles(event)) return;
|
|
242
|
+
if (--dragDepth <= 0) dragging = false;
|
|
243
|
+
}
|
|
244
|
+
function drop(event: DragEvent) {
|
|
245
|
+
if (!hasFiles(event)) return;
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
event.stopPropagation();
|
|
248
|
+
dragDepth = 0;
|
|
249
|
+
dragging = false;
|
|
250
|
+
const dropped = [...(event.dataTransfer?.files ?? [])].filter((f) =>
|
|
251
|
+
/^(image|video)\//.test(f.type)
|
|
252
|
+
);
|
|
253
|
+
if (dropped.length && !busy) void addFiles(dropped);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function addPost() {
|
|
257
|
+
if (posts.length >= limits.posts) return;
|
|
258
|
+
posts.splice(active + 1, 0, blankComposerPost());
|
|
259
|
+
active++;
|
|
260
|
+
await tick();
|
|
261
|
+
editors[posts[active].id]?.commands.focus('end');
|
|
262
|
+
}
|
|
263
|
+
function removePost(index: number) {
|
|
264
|
+
releaseComposerPosts([posts[index]]);
|
|
265
|
+
posts.splice(index, 1);
|
|
266
|
+
active = Math.max(0, Math.min(active, posts.length - 1));
|
|
267
|
+
}
|
|
268
|
+
function setGif(gif: ComposerGif) {
|
|
269
|
+
if (current.images.length || current.video) return;
|
|
270
|
+
current.gif = gif;
|
|
271
|
+
current.link = undefined;
|
|
272
|
+
}
|
|
273
|
+
function toggleLanguage(code: string, checked: boolean) {
|
|
274
|
+
languages = checked
|
|
275
|
+
? [...languages, code].slice(0, limits.languages)
|
|
276
|
+
: languages.filter((c) => c !== code);
|
|
277
|
+
}
|
|
278
|
+
const insert = (inserted: string) =>
|
|
279
|
+
editors[current.id]?.chain().focus().insertContent(inserted).run();
|
|
280
|
+
|
|
281
|
+
const content = (list: Post[]): ComposerContent => ({
|
|
282
|
+
posts: list,
|
|
283
|
+
languages: [...languages],
|
|
284
|
+
replyRules: replyRules && [...replyRules],
|
|
285
|
+
allowQuotes
|
|
286
|
+
});
|
|
287
|
+
function reset() {
|
|
288
|
+
releaseComposerPosts(posts);
|
|
289
|
+
posts = [blankComposerPost()];
|
|
290
|
+
active = 0;
|
|
291
|
+
draft = undefined;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function submit() {
|
|
295
|
+
if (!canPost) return;
|
|
296
|
+
busy = true;
|
|
297
|
+
error = '';
|
|
298
|
+
try {
|
|
299
|
+
const thread = posts
|
|
300
|
+
.filter((post, index) => !isEmpty(post, index))
|
|
301
|
+
// Leading whitespace shifts facet offsets, so only trailing whitespace is trimmed.
|
|
302
|
+
.map((post) => ({ ...$state.snapshot(post), text: post.text.trimEnd() }) as Post);
|
|
303
|
+
await onsubmit(content(thread), (value) => (status = value));
|
|
304
|
+
if (draft) void draftStore?.delete(draft).catch(() => {});
|
|
305
|
+
reset();
|
|
306
|
+
} catch (e) {
|
|
307
|
+
error = message(e);
|
|
308
|
+
} finally {
|
|
309
|
+
busy = false;
|
|
310
|
+
status = '';
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Leave the composer, asking first when there is something to lose. */
|
|
315
|
+
export function cancel() {
|
|
316
|
+
if (busy) return;
|
|
317
|
+
if (dirty) leaving = true;
|
|
318
|
+
else oncancel?.();
|
|
319
|
+
}
|
|
320
|
+
function discard() {
|
|
321
|
+
leaving = false;
|
|
322
|
+
reset();
|
|
323
|
+
oncancel?.();
|
|
324
|
+
}
|
|
325
|
+
async function keep() {
|
|
326
|
+
if (!draftStore) return;
|
|
327
|
+
busy = true;
|
|
328
|
+
try {
|
|
329
|
+
await draftStore.save(content($state.snapshot(posts) as Post[]), draft);
|
|
330
|
+
discard();
|
|
331
|
+
} catch (e) {
|
|
332
|
+
leaving = false;
|
|
333
|
+
error = message(e);
|
|
334
|
+
} finally {
|
|
335
|
+
busy = false;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async function openDraft(summary: ComposerDraftSummary) {
|
|
339
|
+
if (!draftStore) return;
|
|
340
|
+
busy = true;
|
|
341
|
+
error = '';
|
|
342
|
+
try {
|
|
343
|
+
const loaded = await draftStore.load(summary);
|
|
344
|
+
releaseComposerPosts(posts);
|
|
345
|
+
posts = loaded.posts.length ? loaded.posts : [blankComposerPost()];
|
|
346
|
+
active = 0;
|
|
347
|
+
if (loaded.languages.length) languages = loaded.languages;
|
|
348
|
+
replyRules = loaded.replyRules;
|
|
349
|
+
allowQuotes = loaded.allowQuotes;
|
|
350
|
+
draft = summary;
|
|
351
|
+
} catch (e) {
|
|
352
|
+
error = message(e);
|
|
353
|
+
} finally {
|
|
354
|
+
busy = false;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// Menus and suggestion lists take Escape first. Whether one is open has to be read before
|
|
358
|
+
// they handle the key, and the editor claims Escape either way.
|
|
359
|
+
let menuOpen = false;
|
|
360
|
+
function keydownCapture(event: KeyboardEvent) {
|
|
361
|
+
if (event.key === 'Escape')
|
|
362
|
+
menuOpen = !!document.querySelector('[data-bits-floating-content-wrapper], [role=listbox]');
|
|
363
|
+
}
|
|
364
|
+
function keydown(event: KeyboardEvent) {
|
|
365
|
+
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
|
|
366
|
+
event.preventDefault();
|
|
367
|
+
void submit();
|
|
368
|
+
} else if (event.key === 'Escape' && oncancel && !menuOpen) {
|
|
369
|
+
// After this event, or the confirmation would take the same Escape and close again.
|
|
370
|
+
setTimeout(cancel);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
</script>
|
|
374
|
+
|
|
375
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
376
|
+
<div
|
|
377
|
+
class={cn('relative flex min-h-0 flex-1 flex-col', className)}
|
|
378
|
+
onpaste={paste}
|
|
379
|
+
onkeydowncapture={keydownCapture}
|
|
380
|
+
onkeydown={keydown}
|
|
381
|
+
ondragenter={dragEnter}
|
|
382
|
+
ondragleave={dragLeave}
|
|
383
|
+
ondragover={(e) => hasFiles(e) && e.preventDefault()}
|
|
384
|
+
ondrop={drop}
|
|
385
|
+
>
|
|
386
|
+
<div class="flex shrink-0 items-center gap-2 px-3 py-2.5">
|
|
387
|
+
{#if oncancel}
|
|
388
|
+
<Button variant="ghost" size="sm" onclick={cancel} disabled={busy}>
|
|
389
|
+
{labels.cancel ?? 'Cancel'}
|
|
390
|
+
</Button>
|
|
391
|
+
{/if}
|
|
392
|
+
<span class="min-w-0 flex-1 truncate text-right text-xs {muted}" aria-live="polite"
|
|
393
|
+
>{status}</span
|
|
394
|
+
>
|
|
395
|
+
{#if canDraft}
|
|
396
|
+
<Button variant="ghost" size="sm" onclick={() => (draftsOpen = true)} disabled={busy}>
|
|
397
|
+
Drafts
|
|
398
|
+
</Button>
|
|
399
|
+
{/if}
|
|
400
|
+
<Button size="sm" class="min-w-16" onclick={submit} disabled={!canPost} loading={busy}>
|
|
401
|
+
{posts.length > 1
|
|
402
|
+
? (labels.submitAll ?? 'Post all')
|
|
403
|
+
: (labels.submit ?? (reply ? 'Reply' : 'Post'))}
|
|
404
|
+
</Button>
|
|
405
|
+
</div>
|
|
406
|
+
|
|
407
|
+
<div class="min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 pt-2">
|
|
408
|
+
{#if replyTo}
|
|
409
|
+
<div class="mb-3 flex gap-3 border-b pb-3 {line}">
|
|
410
|
+
{#if author}<span class="w-10 shrink-0"></span>{/if}
|
|
411
|
+
<div class="min-w-0 text-sm">
|
|
412
|
+
<p class="truncate {muted}">Replying to {replyTo.name}</p>
|
|
413
|
+
{#if replyTo.text}<p class="line-clamp-3 wrap-anywhere">{replyTo.text}</p>{/if}
|
|
414
|
+
</div>
|
|
415
|
+
</div>
|
|
416
|
+
{/if}
|
|
417
|
+
|
|
418
|
+
{#each posts as post, index (post.id)}
|
|
419
|
+
<ComposerPost
|
|
420
|
+
bind:post={posts[index]}
|
|
421
|
+
oneditor={(editor) => (editors = { ...editors, [post.id]: editor })}
|
|
422
|
+
placeholder={index > 0
|
|
423
|
+
? (labels.threadPlaceholder ?? 'Add another post')
|
|
424
|
+
: (labels.placeholder ?? (reply ? 'Write your reply' : 'What’s up?'))}
|
|
425
|
+
active={index === active}
|
|
426
|
+
line={index < posts.length - 1}
|
|
427
|
+
disabled={busy}
|
|
428
|
+
{author}
|
|
429
|
+
quote={index === 0 ? quote : undefined}
|
|
430
|
+
language={languages[0] ?? browserLanguage()}
|
|
431
|
+
{limits}
|
|
432
|
+
{searchActors}
|
|
433
|
+
linkPreview={on('linkPreviews') ? linkPreview : undefined}
|
|
434
|
+
onfocus={() => (active = index)}
|
|
435
|
+
onremove={posts.length > 1 ? () => removePost(index) : undefined}
|
|
436
|
+
/>
|
|
437
|
+
{/each}
|
|
438
|
+
|
|
439
|
+
{#if error}<p class="red mb-3 text-sm {action}" role="alert">{error}</p>{/if}
|
|
440
|
+
{#if missingAlt}
|
|
441
|
+
<p class="mb-3 text-sm {muted}">Add a description to every image to post.</p>
|
|
442
|
+
{/if}
|
|
443
|
+
</div>
|
|
444
|
+
|
|
445
|
+
{#if on('interactions') || (on('contentWarnings') && contentWarnings.length && hasMedia(current))}
|
|
446
|
+
<div class="flex shrink-0 flex-wrap items-center gap-2 px-4 pb-1.5">
|
|
447
|
+
{#if on('interactions')}
|
|
448
|
+
<Button
|
|
449
|
+
variant="secondary"
|
|
450
|
+
size="sm"
|
|
451
|
+
class="rounded-full"
|
|
452
|
+
disabled={busy}
|
|
453
|
+
onclick={() => (interactionsOpen = true)}
|
|
454
|
+
>
|
|
455
|
+
<Icon img={Globe} size={15} />
|
|
456
|
+
{reply ? (allowQuotes ? 'Quotes allowed' : 'Quotes off') : replyLabel}
|
|
457
|
+
</Button>
|
|
458
|
+
{/if}
|
|
459
|
+
{#if on('contentWarnings') && contentWarnings.length && hasMedia(current)}
|
|
460
|
+
<Select
|
|
461
|
+
bind:value={current.label}
|
|
462
|
+
aria-label="Content warning"
|
|
463
|
+
wrapperClass="w-auto"
|
|
464
|
+
class="min-h-8.5 rounded-full py-1 pr-8 text-xs sm:text-xs"
|
|
465
|
+
>
|
|
466
|
+
<option value="">No content warning</option>
|
|
467
|
+
{#each contentWarnings as warning (warning.value)}
|
|
468
|
+
<option value={warning.value}>{warning.label}</option>
|
|
469
|
+
{/each}
|
|
470
|
+
</Select>
|
|
471
|
+
{/if}
|
|
472
|
+
</div>
|
|
473
|
+
{/if}
|
|
474
|
+
|
|
475
|
+
<div class="flex shrink-0 items-center gap-0.5 border-t px-2 py-1.5 {line}">
|
|
476
|
+
{#if on('images')}
|
|
477
|
+
<input
|
|
478
|
+
bind:this={imageInput}
|
|
479
|
+
type="file"
|
|
480
|
+
accept="image/*"
|
|
481
|
+
multiple
|
|
482
|
+
hidden
|
|
483
|
+
onchange={(e) => {
|
|
484
|
+
void addFiles([...(e.currentTarget.files ?? [])]);
|
|
485
|
+
e.currentTarget.value = '';
|
|
486
|
+
}}
|
|
487
|
+
/>
|
|
488
|
+
<IconButton
|
|
489
|
+
label="Add images"
|
|
490
|
+
disabled={busy ||
|
|
491
|
+
!!current.video ||
|
|
492
|
+
!!current.gif ||
|
|
493
|
+
current.images.length >= limits.images}
|
|
494
|
+
onclick={() => imageInput?.click()}><Icon img={ImageIcon} /></IconButton
|
|
495
|
+
>
|
|
496
|
+
{/if}
|
|
497
|
+
{#if on('video')}
|
|
498
|
+
<input
|
|
499
|
+
bind:this={videoInput}
|
|
500
|
+
type="file"
|
|
501
|
+
accept="video/mp4,video/quicktime,video/webm,video/mpeg,image/gif"
|
|
502
|
+
hidden
|
|
503
|
+
onchange={(e) => {
|
|
504
|
+
void addFiles([...(e.currentTarget.files ?? [])]);
|
|
505
|
+
e.currentTarget.value = '';
|
|
506
|
+
}}
|
|
507
|
+
/>
|
|
508
|
+
<IconButton
|
|
509
|
+
label="Add video"
|
|
510
|
+
disabled={busy || hasMedia(current)}
|
|
511
|
+
onclick={() => videoInput?.click()}><Icon img={Film} /></IconButton
|
|
512
|
+
>
|
|
513
|
+
{/if}
|
|
514
|
+
{#if searchGifs && on('gifs')}
|
|
515
|
+
<IconButton
|
|
516
|
+
label="Add GIF"
|
|
517
|
+
disabled={busy || hasMedia(current)}
|
|
518
|
+
onclick={() => (gifsOpen = true)}
|
|
519
|
+
>
|
|
520
|
+
<Icon img={Sticker} />
|
|
521
|
+
</IconButton>
|
|
522
|
+
{/if}
|
|
523
|
+
{#if on('emoji')}<EmojiPicker disabled={busy} onselect={insert} />{/if}
|
|
524
|
+
{@render actions?.({ post: current, insert, disabled: busy })}
|
|
525
|
+
|
|
526
|
+
<span class="flex-1"></span>
|
|
527
|
+
|
|
528
|
+
{#if on('languages')}
|
|
529
|
+
<Popover class="max-h-80 w-56 overflow-y-auto p-2" align="end">
|
|
530
|
+
{#snippet trigger({ props })}
|
|
531
|
+
<Button
|
|
532
|
+
{...props}
|
|
533
|
+
variant="ghost"
|
|
534
|
+
size="sm"
|
|
535
|
+
class="gap-1.5 uppercase"
|
|
536
|
+
disabled={busy}
|
|
537
|
+
aria-label="Post language"
|
|
538
|
+
>
|
|
539
|
+
<Icon img={Languages} size={16} />
|
|
540
|
+
{languages.join(', ') || '—'}
|
|
541
|
+
</Button>
|
|
542
|
+
{/snippet}
|
|
543
|
+
<p class="px-2 pt-1 pb-2 text-xs {muted}">
|
|
544
|
+
Post language{limits.languages > 1 ? `, up to ${limits.languages}` : ''}
|
|
545
|
+
</p>
|
|
546
|
+
{#each [...new Set([...languages, ...languageOptions])] as code (code)}
|
|
547
|
+
{@const checked = languages.includes(code)}
|
|
548
|
+
<label
|
|
549
|
+
class="flex cursor-pointer items-center gap-2.5 rounded-ui px-2 py-1.5 text-sm {hoverRecess}"
|
|
550
|
+
>
|
|
551
|
+
<Checkbox
|
|
552
|
+
{checked}
|
|
553
|
+
disabled={!checked && languages.length >= limits.languages}
|
|
554
|
+
onchange={(e) => toggleLanguage(code, e.currentTarget.checked)}
|
|
555
|
+
/>
|
|
556
|
+
{languageName(code)}
|
|
557
|
+
</label>
|
|
558
|
+
{/each}
|
|
559
|
+
</Popover>
|
|
560
|
+
{/if}
|
|
561
|
+
<CharRing length={lengthOf(current)} max={limits.length} />
|
|
562
|
+
{#if limits.posts > 1}
|
|
563
|
+
<IconButton
|
|
564
|
+
label="Add post to thread"
|
|
565
|
+
disabled={busy || posts.length >= limits.posts || isEmpty(current, active)}
|
|
566
|
+
onclick={addPost}><Icon img={Plus} /></IconButton
|
|
567
|
+
>
|
|
568
|
+
{/if}
|
|
569
|
+
</div>
|
|
570
|
+
|
|
571
|
+
{#if dragging}
|
|
572
|
+
<div
|
|
573
|
+
class="pointer-events-none absolute inset-2 z-10 grid place-items-center rounded-panel border-2 border-dashed border-accent-500 bg-base-50/85 text-lg font-semibold dark:bg-base-925/85"
|
|
574
|
+
>
|
|
575
|
+
Drop to attach
|
|
576
|
+
</div>
|
|
577
|
+
{/if}
|
|
578
|
+
</div>
|
|
579
|
+
|
|
580
|
+
{#if searchGifs}
|
|
581
|
+
<GifPicker bind:open={gifsOpen} search={searchGifs} credit={gifCredit} onselect={setGif} />
|
|
582
|
+
{/if}
|
|
583
|
+
<ReplySettings
|
|
584
|
+
bind:open={interactionsOpen}
|
|
585
|
+
bind:rules={replyRules}
|
|
586
|
+
bind:allowQuotes
|
|
587
|
+
{reply}
|
|
588
|
+
lists={replyLists}
|
|
589
|
+
{onsavedefault}
|
|
590
|
+
/>
|
|
591
|
+
{#if draftStore}<Drafts bind:open={draftsOpen} store={draftStore} onselect={openDraft} />{/if}
|
|
592
|
+
|
|
593
|
+
<Modal bind:open={leaving} title="Discard post?" class="max-w-sm">
|
|
594
|
+
<div class="grid gap-2">
|
|
595
|
+
{#if canDraft}<Button onclick={keep} loading={busy}>Save draft</Button>{/if}
|
|
596
|
+
<Button variant="secondary" class="red" disabled={busy} onclick={discard}>Discard</Button>
|
|
597
|
+
<Button variant="ghost" disabled={busy} onclick={() => (leaving = false)}>Keep editing</Button>
|
|
598
|
+
</div>
|
|
599
|
+
</Modal>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ComposerContent, ComposerContentWarning, ComposerDrafts, ComposerFeatures, ComposerGifSearch, ComposerLabels, ComposerLimits, ComposerLinkPreview, ComposerPost as Post, ComposerReplyRule } from '../../social/composer.js';
|
|
3
|
+
import type { ActorSearch } from '../login/types.js';
|
|
4
|
+
export type PostComposerProps = {
|
|
5
|
+
/**
|
|
6
|
+
* Publish the posts. Report progress through `status`; throw to show an error and keep
|
|
7
|
+
* the content. The composer clears once this resolves.
|
|
8
|
+
*/
|
|
9
|
+
onsubmit: (content: ComposerContent, status: (text: string) => void) => Promise<void>;
|
|
10
|
+
/** Adds a Cancel button. Called once the content is discarded, saved or was empty. */
|
|
11
|
+
oncancel?: () => void;
|
|
12
|
+
/** Shown beside each post. */
|
|
13
|
+
author?: {
|
|
14
|
+
name: string;
|
|
15
|
+
avatar?: string;
|
|
16
|
+
};
|
|
17
|
+
/** The post being replied to. Replies have no reply rules and no drafts. */
|
|
18
|
+
replyTo?: {
|
|
19
|
+
name: string;
|
|
20
|
+
text?: string;
|
|
21
|
+
};
|
|
22
|
+
/** The quoted post, rendered under the first post. A quote can be posted without text. */
|
|
23
|
+
quote?: Snippet;
|
|
24
|
+
/** Put the cursor in the text once the composer appears. */
|
|
25
|
+
autofocus?: boolean;
|
|
26
|
+
/** Starting text and files. */
|
|
27
|
+
text?: string;
|
|
28
|
+
files?: Iterable<File>;
|
|
29
|
+
languages?: string[];
|
|
30
|
+
/** Language codes offered in the picker. */
|
|
31
|
+
languageOptions?: readonly string[];
|
|
32
|
+
replyRules?: ComposerReplyRule[];
|
|
33
|
+
allowQuotes?: boolean;
|
|
34
|
+
/** Lists that can be allowed to reply. */
|
|
35
|
+
replyLists?: {
|
|
36
|
+
uri: string;
|
|
37
|
+
name: string;
|
|
38
|
+
}[] | (() => Promise<{
|
|
39
|
+
uri: string;
|
|
40
|
+
name: string;
|
|
41
|
+
}[]>);
|
|
42
|
+
/** Adds "Save as default" to the interaction settings. */
|
|
43
|
+
onsavedefault?: (rules: ComposerReplyRule[] | undefined, allowQuotes: boolean) => Promise<void>;
|
|
44
|
+
/** Every image needs a description before posting. */
|
|
45
|
+
requireAlt?: boolean;
|
|
46
|
+
features?: Partial<ComposerFeatures>;
|
|
47
|
+
limits?: Partial<ComposerLimits>;
|
|
48
|
+
labels?: Partial<ComposerLabels>;
|
|
49
|
+
contentWarnings?: readonly ComposerContentWarning[];
|
|
50
|
+
searchActors?: ActorSearch;
|
|
51
|
+
/** Enables the GIF button, e.g. `blueskyGifSearch`. */
|
|
52
|
+
searchGifs?: ComposerGifSearch;
|
|
53
|
+
gifCredit?: string;
|
|
54
|
+
/** Enables link preview cards, e.g. `blueskyLinkPreview`. */
|
|
55
|
+
linkPreview?: ComposerLinkPreview;
|
|
56
|
+
/** Enables drafts. */
|
|
57
|
+
drafts?: ComposerDrafts;
|
|
58
|
+
/** More toolbar buttons, after the built-in ones. */
|
|
59
|
+
actions?: Snippet<[{
|
|
60
|
+
post: Post;
|
|
61
|
+
insert: (text: string) => void;
|
|
62
|
+
disabled: boolean;
|
|
63
|
+
}]>;
|
|
64
|
+
class?: string;
|
|
65
|
+
};
|
|
66
|
+
declare const PostComposer: import("svelte").Component<PostComposerProps, {
|
|
67
|
+
addFiles: (added: Iterable<File>) => Promise<void>;
|
|
68
|
+
cancel: () => void;
|
|
69
|
+
}, "allowQuotes" | "languages" | "replyRules">;
|
|
70
|
+
type PostComposer = ReturnType<typeof PostComposer>;
|
|
71
|
+
export default PostComposer;
|