@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.
Files changed (95) hide show
  1. package/dist/components/ExternalEmbed.svelte +30 -29
  2. package/dist/components/ExternalEmbed.svelte.d.ts +8 -0
  3. package/dist/components/InlineEditor.svelte +15 -95
  4. package/dist/components/InlineEditor.svelte.d.ts +1 -1
  5. package/dist/components/LinkCard.svelte +54 -25
  6. package/dist/components/LinkCard.svelte.d.ts +2 -0
  7. package/dist/components/LinkEmbed.svelte +75 -0
  8. package/dist/components/LinkEmbed.svelte.d.ts +13 -0
  9. package/dist/components/PostContent.svelte +12 -3
  10. package/dist/components/PostContent.svelte.d.ts +3 -0
  11. package/dist/components/RichText.svelte +47 -5
  12. package/dist/components/RichText.svelte.d.ts +5 -2
  13. package/dist/components/RichTextEditor.svelte +272 -0
  14. package/dist/components/RichTextEditor.svelte.d.ts +44 -0
  15. package/dist/components/composer/AltText.svelte +63 -0
  16. package/dist/components/composer/AltText.svelte.d.ts +11 -0
  17. package/dist/components/composer/CharRing.svelte +39 -0
  18. package/dist/components/composer/CharRing.svelte.d.ts +7 -0
  19. package/dist/components/composer/ComposerPost.svelte +321 -0
  20. package/dist/components/composer/ComposerPost.svelte.d.ts +29 -0
  21. package/dist/components/composer/Drafts.svelte +82 -0
  22. package/dist/components/composer/Drafts.svelte.d.ts +9 -0
  23. package/dist/components/composer/EmojiPicker.svelte +55 -0
  24. package/dist/components/composer/EmojiPicker.svelte.d.ts +7 -0
  25. package/dist/components/composer/GifPicker.svelte +118 -0
  26. package/dist/components/composer/GifPicker.svelte.d.ts +11 -0
  27. package/dist/components/composer/PostComposer.svelte +599 -0
  28. package/dist/components/composer/PostComposer.svelte.d.ts +71 -0
  29. package/dist/components/composer/PostComposerDialog.svelte +75 -0
  30. package/dist/components/composer/PostComposerDialog.svelte.d.ts +10 -0
  31. package/dist/components/composer/ReplySettings.svelte +150 -0
  32. package/dist/components/composer/ReplySettings.svelte.d.ts +18 -0
  33. package/dist/components/login/search.d.ts +29 -1
  34. package/dist/components/login/search.js +31 -3
  35. package/dist/editor/EditorLinkEmbed.svelte +35 -0
  36. package/dist/editor/EditorLinkEmbed.svelte.d.ts +12 -0
  37. package/dist/editor/detect-plugin.d.ts +5 -0
  38. package/dist/editor/detect-plugin.js +51 -0
  39. package/dist/editor/document.d.ts +17 -0
  40. package/dist/editor/document.js +269 -0
  41. package/dist/editor/link-embed-node.d.ts +17 -0
  42. package/dist/editor/link-embed-node.js +96 -0
  43. package/dist/editor/markdown-extensions.d.ts +6 -0
  44. package/dist/editor/markdown-extensions.js +42 -0
  45. package/dist/editor/markdown.d.ts +3 -0
  46. package/dist/editor/markdown.js +4 -0
  47. package/dist/embeds/PlayerLinkEmbed.svelte +9 -0
  48. package/dist/embeds/PlayerLinkEmbed.svelte.d.ts +7 -0
  49. package/dist/{events/event-view → embeds}/PostLinkEmbed.svelte +7 -7
  50. package/dist/{events/event-view → embeds}/PostLinkEmbed.svelte.d.ts +1 -1
  51. package/dist/{events/event-view → embeds}/ProfileLinkEmbed.svelte +7 -7
  52. package/dist/{events/event-view → embeds}/ProfileLinkEmbed.svelte.d.ts +1 -1
  53. package/dist/embeds/context.d.ts +10 -0
  54. package/dist/embeds/context.js +20 -0
  55. package/dist/embeds/defaults.d.ts +27 -0
  56. package/dist/embeds/defaults.js +38 -0
  57. package/dist/embeds/resolve.d.ts +9 -0
  58. package/dist/embeds/resolve.js +27 -0
  59. package/dist/embeds/types.d.ts +39 -0
  60. package/dist/embeds/types.js +1 -0
  61. package/dist/events/EventEditor.svelte +29 -6
  62. package/dist/events/EventView.svelte +21 -38
  63. package/dist/events/PostToBlueskyModal.svelte +12 -4
  64. package/dist/events/event-link-embed.d.ts +22 -0
  65. package/dist/events/event-link-embed.js +15 -0
  66. package/dist/events/event-view/EventLinkEmbed.svelte +12 -30
  67. package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -12
  68. package/dist/events.d.ts +2 -0
  69. package/dist/events.js +1 -0
  70. package/dist/index.d.ts +16 -2
  71. package/dist/index.js +10 -2
  72. package/dist/richtext/detect.js +1 -1
  73. package/dist/richtext/document.d.ts +10 -0
  74. package/dist/richtext/document.js +44 -4
  75. package/dist/richtext/markdown.js +9 -8
  76. package/dist/richtext/serialize.d.ts +11 -0
  77. package/dist/richtext/serialize.js +462 -0
  78. package/dist/richtext/vendor/markdown-tree.d.ts +5 -0
  79. package/dist/richtext/vendor/markdown-tree.js +11032 -0
  80. package/dist/richtext.d.ts +1 -0
  81. package/dist/richtext.js +1 -0
  82. package/dist/social/MentionOptions.svelte +30 -0
  83. package/dist/social/MentionOptions.svelte.d.ts +12 -0
  84. package/dist/social/composer.d.ts +143 -0
  85. package/dist/social/composer.js +141 -0
  86. package/dist/social/{mention-suggestions.d.ts → mention-suggestions.svelte.d.ts} +1 -1
  87. package/dist/social/{mention-suggestions.js → mention-suggestions.svelte.js} +36 -46
  88. package/dist/social/richtext.js +2 -0
  89. package/dist/social.d.ts +2 -0
  90. package/dist/social.js +1 -0
  91. package/dist/styles.d.ts +5 -0
  92. package/dist/styles.js +5 -0
  93. package/package.json +8 -4
  94. package/dist/components/PostComposer.svelte +0 -41
  95. package/dist/components/PostComposer.svelte.d.ts +0 -16
@@ -0,0 +1,272 @@
1
+ <script lang="ts">
2
+ import { onMount, untrack } from 'svelte';
3
+ import { Editor, type AnyExtension, 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';
11
+ import type { ActorSearch } from './login/types.js';
12
+ import { DetectedTokens } from '../editor/detect-plugin.js';
13
+ import {
14
+ bareUrl,
15
+ documentToEditor,
16
+ editorToDocument,
17
+ LINK_EMBED,
18
+ markdownFacets
19
+ } from '../editor/document.js';
20
+ import { embedCurrentParagraph, LinkEmbedNode } from '../editor/link-embed-node.js';
21
+ import { linkEmbedOptions, selectLinkEmbeds } from '../embeds/context.js';
22
+ import { resolveLinkEmbed } from '../embeds/resolve.js';
23
+ import type { LinkEmbed } from '../embeds/types.js';
24
+ import { parsePlainText } from '../richtext/plain.js';
25
+ import { mentionSuggestions } from '../social/mention-suggestions.svelte.js';
26
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
27
+ import { editorJsonToBlueskyPost, type Facet } from '../social/richtext.js';
28
+ import { cn } from '../utils.js';
29
+
30
+ export type RichTextEditorContent = {
31
+ /** The text to store: Markdown source with `markdown`, otherwise plain text. */
32
+ text: string;
33
+ /**
34
+ * Links, hashtags and the mentions picked from suggestions, as byte ranges of `text`.
35
+ * Handles typed without picking a suggestion have no DID yet.
36
+ */
37
+ facets: Facet[];
38
+ json: JSONContent;
39
+ };
40
+
41
+ export type RichTextEditorProps = {
42
+ /** Markdown source with `markdown`, otherwise plain text. */
43
+ value?: string;
44
+ /** The stored facets of `value`, so that existing mentions keep their DIDs. */
45
+ facets?: unknown;
46
+ editor?: Editor | null;
47
+ label: string;
48
+ placeholder?: string;
49
+ /**
50
+ * Notion-like editing of the kit's Markdown: type `# `, `- `, `> `, `**bold**` and so on
51
+ * and see the result. Without it the text is plain, as in a post.
52
+ */
53
+ markdown?: boolean;
54
+ /**
55
+ * Show an embeddable link alone on its line as its embed, as `RichText` does: `true` for
56
+ * the app's embeds (see `setLinkEmbeds`) or an explicit list.
57
+ */
58
+ embeds?: boolean | readonly LinkEmbed[];
59
+ singleLine?: boolean;
60
+ disabled?: boolean;
61
+ /** Enables @-mention suggestions. */
62
+ searchActors?: ActorSearch;
63
+ socialClient?: PreferredSocialClient | null;
64
+ onupdate?: (content: RichTextEditorContent) => void;
65
+ class?: string;
66
+ };
67
+
68
+ let {
69
+ value = $bindable(''),
70
+ facets,
71
+ editor = $bindable<Editor | null>(null),
72
+ label,
73
+ placeholder = '',
74
+ markdown = false,
75
+ embeds = false,
76
+ singleLine = false,
77
+ disabled = false,
78
+ searchActors,
79
+ socialClient,
80
+ onupdate,
81
+ class: className
82
+ }: RichTextEditorProps = $props();
83
+
84
+ const id = $props.id();
85
+ const embedContext = linkEmbedOptions();
86
+ let embedList = $derived(singleLine ? [] : selectLinkEmbeds(embeds, embedContext()));
87
+ const isEmbed = (url: string) => !!resolveLinkEmbed(url, embedList);
88
+
89
+ let host: HTMLDivElement;
90
+ let element: HTMLDivElement;
91
+ /** The text the editor's content stands for; `value` differing from it is an outside change. */
92
+ let current = untrack(() => value);
93
+ /** The facets the content was loaded with, to notice when they arrive or change later. */
94
+ let currentFacets = untrack(() => JSON.stringify(facets ?? null));
95
+ /** Loaded with the Markdown blocks, so plain-text editors never download them. */
96
+ let markdownTools: typeof import('../editor/markdown.js') | undefined;
97
+
98
+ function load(text: string, textFacets?: unknown): JSONContent {
99
+ const document = markdownTools
100
+ ? markdownTools.parseMarkdown(text, { facets: textFacets, detectLinks: true })
101
+ : parsePlainText(text, { facets: textFacets });
102
+ const content = documentToEditor(document, embedList.length ? isEmbed : undefined);
103
+ // Leave somewhere to type after a trailing embed.
104
+ if (content.content?.at(-1)?.type === LINK_EMBED) content.content.push({ type: 'paragraph' });
105
+ return content;
106
+ }
107
+
108
+ function read(json: JSONContent): RichTextEditorContent {
109
+ if (!markdownTools) return { ...editorJsonToBlueskyPost(json), json };
110
+ const text = markdownTools.richTextToMarkdown(editorToDocument(json));
111
+ return { text, facets: markdownFacets(text, json), json };
112
+ }
113
+
114
+ function paste(instance: Editor, text: string): void {
115
+ if (singleLine) {
116
+ const cleaned = text.replace(/[\r\n]+/g, ' ');
117
+ if (cleaned) instance.commands.insertContent({ type: 'text', text: cleaned });
118
+ return;
119
+ }
120
+ const normalized = text.replace(/\r\n?/g, '\n');
121
+ if (instance.isActive('codeBlock')) {
122
+ instance.view.dispatch(instance.state.tr.insertText(normalized));
123
+ return;
124
+ }
125
+ const url = bareUrl(normalized);
126
+ const { empty, $from: from } = instance.state.selection;
127
+ if (url && !empty && instance.schema.marks.link) {
128
+ instance.commands.setLink({ href: url });
129
+ return;
130
+ }
131
+ if (url && empty && !from.parent.content.size && embedList.length && isEmbed(url)) {
132
+ // Typed first, so that undo turns the embed back into its link.
133
+ instance.view.dispatch(instance.state.tr.insertText(url));
134
+ embedCurrentParagraph(instance, isEmbed);
135
+ return;
136
+ }
137
+ if (url) {
138
+ // Inside a sentence a link stays a link.
139
+ instance.commands.insertContent({ type: 'text', text: normalized.trim() });
140
+ return;
141
+ }
142
+ const content = load(normalized).content ?? [];
143
+ // Text for the current line joins it instead of splitting it.
144
+ instance.commands.insertContent(
145
+ content.length === 1 && content[0].type === 'paragraph' ? (content[0].content ?? []) : content
146
+ );
147
+ }
148
+
149
+ const linkClass = 'text-accent-700 dark:text-accent-300';
150
+ const editorClass =
151
+ 'min-h-[1.5em] outline-none 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 [&_[data-link-embed]]:whitespace-normal [&_.ProseMirror-selectednode]:rounded-ui [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-offset-2 [&_.ProseMirror-selectednode]:outline-accent-700 dark:[&_.ProseMirror-selectednode]:outline-accent-300';
152
+ // The same look as `RichText`, so that what is typed is what will be shown.
153
+ // Nothing here reaches into an embed, which brings its own lists, links and code.
154
+ const markdownClass =
155
+ 'space-y-3 leading-relaxed whitespace-pre-wrap [&_strong:not([data-link-embed]_*)]:font-semibold [&_h1:not([data-link-embed]_*)]:text-xl [&_h2:not([data-link-embed]_*)]:text-lg [&_:is(h1,h2,h3,h4,h5,h6):not([data-link-embed]_*)]:leading-snug [&_:is(h1,h2,h3,h4,h5,h6):not([data-link-embed]_*)]:font-semibold [&_blockquote:not([data-link-embed]_*)]:space-y-3 [&_blockquote:not([data-link-embed]_*)]:border-l-2 [&_blockquote:not([data-link-embed]_*)]:border-base-300 [&_blockquote:not([data-link-embed]_*)]:pl-4 dark:[&_blockquote:not([data-link-embed]_*)]:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] [&_:is(ul,ol):not([data-link-embed]_*)]:space-y-1 [&_:is(ul,ol):not([data-link-embed]_*)]:pl-6 [&_ul:not([data-link-embed]_*)]:list-disc [&_ol:not([data-link-embed]_*)]:list-decimal [&_li:not([data-link-embed]_*)]:space-y-3 [&_:not(pre)>code:not([data-link-embed]_*)]:rounded [&_:not(pre)>code:not([data-link-embed]_*)]:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] [&_:not(pre)>code:not([data-link-embed]_*)]:px-1 [&_:not(pre)>code:not([data-link-embed]_*)]:py-0.5 [&_:not(pre)>code:not([data-link-embed]_*)]:font-mono [&_:not(pre)>code:not([data-link-embed]_*)]:text-[0.875em] dark:[&_:not(pre)>code:not([data-link-embed]_*)]:bg-base-950 [&_pre:not([data-link-embed]_*)]:overflow-x-auto [&_pre:not([data-link-embed]_*)]:rounded-md [&_pre:not([data-link-embed]_*)]:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] [&_pre:not([data-link-embed]_*)]:p-3 [&_pre:not([data-link-embed]_*)]:font-mono [&_pre:not([data-link-embed]_*)]:text-[0.875em] dark:[&_pre:not([data-link-embed]_*)]:bg-base-950 [&_hr:not([data-link-embed]_*)]:border-base-300 dark:[&_hr:not([data-link-embed]_*)]:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] [&_a:not([data-link-embed]_*)]:text-accent-700 [&_a:not([data-link-embed]_*)]:underline [&_a:not([data-link-embed]_*)]:decoration-accent-700/40 [&_a:not([data-link-embed]_*)]:underline-offset-2 dark:[&_a:not([data-link-embed]_*)]:text-accent-300 dark:[&_a:not([data-link-embed]_*)]:decoration-accent-300/40';
156
+
157
+ onMount(() => {
158
+ let instance: Editor | undefined;
159
+ let destroyed = false;
160
+ const create = () => {
161
+ if (destroyed) return;
162
+ const created = new Editor({
163
+ element,
164
+ extensions: [
165
+ ...(markdownTools
166
+ ? markdownTools.markdownExtensions()
167
+ : ([Document, Paragraph, Text, HardBreak, History] as AnyExtension[])),
168
+ Placeholder.configure({ placeholder }),
169
+ DetectedTokens.configure({ class: linkClass }),
170
+ ...(embeds && !singleLine
171
+ ? [
172
+ LinkEmbedNode.configure({
173
+ isEmbed,
174
+ embedOptions: () => ({
175
+ embeds: embedList,
176
+ clickToLoad: embedContext().clickToLoad,
177
+ socialClient
178
+ })
179
+ })
180
+ ]
181
+ : []),
182
+ // Stored mentions are always shown; suggestions need a search.
183
+ Mention.configure({
184
+ HTMLAttributes: { class: linkClass },
185
+ suggestion: searchActors
186
+ ? mentionSuggestions(searchActors, () => host)
187
+ : { allow: () => false }
188
+ })
189
+ ],
190
+ content: load(
191
+ untrack(() => value),
192
+ untrack(() => facets)
193
+ ),
194
+ editable: !disabled,
195
+ editorProps: {
196
+ attributes: {
197
+ id,
198
+ role: searchActors ? 'combobox' : 'textbox',
199
+ 'aria-label': label,
200
+ ...(searchActors
201
+ ? {
202
+ 'aria-autocomplete': 'list',
203
+ 'aria-expanded': 'false',
204
+ 'aria-haspopup': 'listbox'
205
+ }
206
+ : { 'aria-multiline': String(!singleLine) }),
207
+ class: cn(
208
+ editorClass,
209
+ markdownTools ? markdownClass : 'whitespace-pre-wrap [&_[data-link-embed]]:my-3'
210
+ )
211
+ },
212
+ handleKeyDown: (view, event) =>
213
+ singleLine &&
214
+ event.key === 'Enter' &&
215
+ !event.isComposing &&
216
+ !view.dom.getAttribute('aria-activedescendant'),
217
+ transformPastedText: (text) => (singleLine ? text.replace(/[\r\n]+/g, ' ') : text),
218
+ // Accept text only, read as Markdown where the editor supports it.
219
+ handlePaste: (_view, event) => {
220
+ const text = event.clipboardData?.getData('text/plain');
221
+ if (text === undefined) return false;
222
+ event.preventDefault();
223
+ paste(created, text);
224
+ return true;
225
+ }
226
+ },
227
+ onUpdate: ({ editor: updated }) => {
228
+ const content = read(updated.getJSON());
229
+ current = content.text;
230
+ value = content.text;
231
+ onupdate?.(content);
232
+ }
233
+ });
234
+ instance = created;
235
+ editor = created;
236
+ };
237
+ if (markdown)
238
+ void import('../editor/markdown.js').then((module) => {
239
+ markdownTools = module;
240
+ create();
241
+ });
242
+ else create();
243
+ return () => {
244
+ destroyed = true;
245
+ instance?.destroy();
246
+ editor = null;
247
+ };
248
+ });
249
+ $effect(() => {
250
+ const facetsKey = JSON.stringify(facets ?? null);
251
+ if (editor && (value !== current || facetsKey !== currentFacets)) {
252
+ current = value;
253
+ currentFacets = facetsKey;
254
+ editor.commands.setContent(load(value, facets), { emitUpdate: false });
255
+ }
256
+ });
257
+ $effect(() => {
258
+ editor?.setEditable(!disabled, false);
259
+ editor?.view.dom.setAttribute('aria-disabled', String(disabled));
260
+ });
261
+ </script>
262
+
263
+ <div
264
+ bind:this={host}
265
+ class={cn(
266
+ 'relative min-w-0 rounded-sm focus-within:outline-2 focus-within:outline-offset-4 focus-within:outline-accent-700 dark:focus-within:outline-accent-300',
267
+ className
268
+ )}
269
+ data-slot="rich-text-editor"
270
+ >
271
+ <div bind:this={element}></div>
272
+ </div>
@@ -0,0 +1,44 @@
1
+ import { Editor, type JSONContent } from '@tiptap/core';
2
+ import type { ActorSearch } from './login/types.js';
3
+ import type { LinkEmbed } from '../embeds/types.js';
4
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
5
+ import { type Facet } from '../social/richtext.js';
6
+ export type RichTextEditorContent = {
7
+ /** The text to store: Markdown source with `markdown`, otherwise plain text. */
8
+ text: string;
9
+ /**
10
+ * Links, hashtags and the mentions picked from suggestions, as byte ranges of `text`.
11
+ * Handles typed without picking a suggestion have no DID yet.
12
+ */
13
+ facets: Facet[];
14
+ json: JSONContent;
15
+ };
16
+ export type RichTextEditorProps = {
17
+ /** Markdown source with `markdown`, otherwise plain text. */
18
+ value?: string;
19
+ /** The stored facets of `value`, so that existing mentions keep their DIDs. */
20
+ facets?: unknown;
21
+ editor?: Editor | null;
22
+ label: string;
23
+ placeholder?: string;
24
+ /**
25
+ * Notion-like editing of the kit's Markdown: type `# `, `- `, `> `, `**bold**` and so on
26
+ * and see the result. Without it the text is plain, as in a post.
27
+ */
28
+ markdown?: boolean;
29
+ /**
30
+ * Show an embeddable link alone on its line as its embed, as `RichText` does: `true` for
31
+ * the app's embeds (see `setLinkEmbeds`) or an explicit list.
32
+ */
33
+ embeds?: boolean | readonly LinkEmbed[];
34
+ singleLine?: boolean;
35
+ disabled?: boolean;
36
+ /** Enables @-mention suggestions. */
37
+ searchActors?: ActorSearch;
38
+ socialClient?: PreferredSocialClient | null;
39
+ onupdate?: (content: RichTextEditorContent) => void;
40
+ class?: string;
41
+ };
42
+ declare const RichTextEditor: import("svelte").Component<RichTextEditorProps, {}, "value" | "editor">;
43
+ type RichTextEditor = ReturnType<typeof RichTextEditor>;
44
+ export default RichTextEditor;
@@ -0,0 +1,63 @@
1
+ <script lang="ts">
2
+ import { action, muted, recess } from '../../styles.js';
3
+ import { graphemeLength } from '../../social/richtext.js';
4
+ import Button from '../Button.svelte';
5
+ import Modal from '../Modal.svelte';
6
+ import Textarea from '../Textarea.svelte';
7
+
8
+ let {
9
+ open = $bindable(false),
10
+ value = $bindable(''),
11
+ preview,
12
+ video = false,
13
+ max = 2000
14
+ }: {
15
+ open?: boolean;
16
+ value?: string;
17
+ /** Shown next to the field, so the media can be described while looking at it. */
18
+ preview?: string;
19
+ video?: boolean;
20
+ max?: number;
21
+ } = $props();
22
+
23
+ let text = $state('');
24
+ let wasOpen = false;
25
+ $effect(() => {
26
+ if (open && !wasOpen) text = value;
27
+ wasOpen = open;
28
+ });
29
+ let length = $derived(graphemeLength(text));
30
+ </script>
31
+
32
+ <Modal bind:open title="Description" class="max-w-md">
33
+ <form
34
+ class="grid gap-4"
35
+ onsubmit={(e) => {
36
+ e.preventDefault();
37
+ value = text.trim();
38
+ open = false;
39
+ }}
40
+ >
41
+ {#if preview}
42
+ {#if video}
43
+ <video src={preview} class="max-h-56 w-full rounded-ui bg-black object-contain" muted
44
+ ></video>
45
+ {:else}
46
+ <img src={preview} alt="" class="max-h-56 w-full rounded-ui object-contain {recess}" />
47
+ {/if}
48
+ {/if}
49
+ <Textarea
50
+ bind:value={text}
51
+ rows={4}
52
+ placeholder="Describe this for people who can't see it"
53
+ aria-label="Description"
54
+ data-autofocus
55
+ />
56
+ <div class="flex items-center justify-between gap-3">
57
+ <span class="text-xs tabular-nums {length > max ? `red ${action}` : muted}"
58
+ >{length} / {max}</span
59
+ >
60
+ <Button type="submit" disabled={length > max}>Save</Button>
61
+ </div>
62
+ </form>
63
+ </Modal>
@@ -0,0 +1,11 @@
1
+ type $$ComponentProps = {
2
+ open?: boolean;
3
+ value?: string;
4
+ /** Shown next to the field, so the media can be described while looking at it. */
5
+ preview?: string;
6
+ video?: boolean;
7
+ max?: number;
8
+ };
9
+ declare const AltText: import("svelte").Component<$$ComponentProps, {}, "value" | "open">;
10
+ type AltText = ReturnType<typeof AltText>;
11
+ export default AltText;
@@ -0,0 +1,39 @@
1
+ <script lang="ts">
2
+ import { action, muted } from '../../styles.js';
3
+ let { length, max }: { length: number; max: number } = $props();
4
+
5
+ const R = 9;
6
+ const C = 2 * Math.PI * R;
7
+ let ratio = $derived(Math.min(1, length / max));
8
+ let left = $derived(max - length);
9
+ let over = $derived(left < 0);
10
+ </script>
11
+
12
+ <span
13
+ class="flex items-center gap-1.5 text-xs tabular-nums {over ? `red ${action}` : muted}"
14
+ role="status"
15
+ aria-label="{left} characters left"
16
+ >
17
+ {#if left <= 20}{left}{/if}
18
+ <svg width="22" height="22" viewBox="0 0 22 22" aria-hidden="true" class="-rotate-90">
19
+ <circle
20
+ cx="11"
21
+ cy="11"
22
+ r={R}
23
+ fill="none"
24
+ stroke-width="2.5"
25
+ class="stroke-base-300 dark:stroke-base-700"
26
+ />
27
+ <circle
28
+ cx="11"
29
+ cy="11"
30
+ r={R}
31
+ fill="none"
32
+ stroke-width="2.5"
33
+ stroke-linecap="round"
34
+ stroke-dasharray={C}
35
+ stroke-dashoffset={C * (1 - ratio)}
36
+ class={over ? 'stroke-accent-600 dark:stroke-accent-400' : 'stroke-accent-500'}
37
+ />
38
+ </svg>
39
+ </span>
@@ -0,0 +1,7 @@
1
+ type $$ComponentProps = {
2
+ length: number;
3
+ max: number;
4
+ };
5
+ declare const CharRing: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type CharRing = ReturnType<typeof CharRing>;
7
+ export default CharRing;