@atmo-dev/kit 0.13.2 → 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/NestedComments.svelte +205 -52
- package/dist/components/NestedComments.svelte.d.ts +49 -6
- package/dist/components/PostContent.svelte +26 -25
- package/dist/components/PostContent.svelte.d.ts +3 -0
- package/dist/components/PostImages.svelte +85 -0
- package/dist/components/PostImages.svelte.d.ts +9 -0
- package/dist/components/PostVideo.svelte +16 -2
- package/dist/components/PostVideo.svelte.d.ts +4 -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/EventComments.svelte +5 -5
- 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/posts.d.ts +10 -0
- package/dist/social/posts.js +5 -1
- 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
|
@@ -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]>;
|
|
@@ -0,0 +1,271 @@
|
|
|
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
|
+
const markdownClass =
|
|
154
|
+
'space-y-3 leading-relaxed whitespace-pre-wrap [&_strong]:font-semibold [&_h1]:text-xl [&_h2]:text-lg [&_:is(h1,h2,h3,h4,h5,h6)]:leading-snug [&_:is(h1,h2,h3,h4,h5,h6)]:font-semibold [&_blockquote]:space-y-3 [&_blockquote]:border-l-2 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 dark:[&_blockquote]:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] [&_:is(ul,ol)]:space-y-1 [&_:is(ul,ol)]:pl-6 [&_ul]:list-disc [&_ol]:list-decimal [&_li]:space-y-3 [&_:not(pre)>code]:rounded [&_:not(pre)>code]:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] [&_:not(pre)>code]:px-1 [&_:not(pre)>code]:py-0.5 [&_:not(pre)>code]:font-mono [&_:not(pre)>code]:text-[0.875em] dark:[&_:not(pre)>code]:bg-base-950 [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] [&_pre]:p-3 [&_pre]:font-mono [&_pre]:text-[0.875em] dark:[&_pre]:bg-base-950 [&_hr]:border-base-300 dark:[&_hr]:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] [&_a]:text-accent-700 [&_a]:underline [&_a]:decoration-accent-700/40 [&_a]:underline-offset-2 dark:[&_a]:text-accent-300 dark:[&_a]:decoration-accent-300/40';
|
|
155
|
+
|
|
156
|
+
onMount(() => {
|
|
157
|
+
let instance: Editor | undefined;
|
|
158
|
+
let destroyed = false;
|
|
159
|
+
const create = () => {
|
|
160
|
+
if (destroyed) return;
|
|
161
|
+
const created = new Editor({
|
|
162
|
+
element,
|
|
163
|
+
extensions: [
|
|
164
|
+
...(markdownTools
|
|
165
|
+
? markdownTools.markdownExtensions()
|
|
166
|
+
: ([Document, Paragraph, Text, HardBreak, History] as AnyExtension[])),
|
|
167
|
+
Placeholder.configure({ placeholder }),
|
|
168
|
+
DetectedTokens.configure({ class: linkClass }),
|
|
169
|
+
...(embeds && !singleLine
|
|
170
|
+
? [
|
|
171
|
+
LinkEmbedNode.configure({
|
|
172
|
+
isEmbed,
|
|
173
|
+
embedOptions: () => ({
|
|
174
|
+
embeds: embedList,
|
|
175
|
+
clickToLoad: embedContext().clickToLoad,
|
|
176
|
+
socialClient
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
]
|
|
180
|
+
: []),
|
|
181
|
+
// Stored mentions are always shown; suggestions need a search.
|
|
182
|
+
Mention.configure({
|
|
183
|
+
HTMLAttributes: { class: linkClass },
|
|
184
|
+
suggestion: searchActors
|
|
185
|
+
? mentionSuggestions(searchActors, () => host)
|
|
186
|
+
: { allow: () => false }
|
|
187
|
+
})
|
|
188
|
+
],
|
|
189
|
+
content: load(
|
|
190
|
+
untrack(() => value),
|
|
191
|
+
untrack(() => facets)
|
|
192
|
+
),
|
|
193
|
+
editable: !disabled,
|
|
194
|
+
editorProps: {
|
|
195
|
+
attributes: {
|
|
196
|
+
id,
|
|
197
|
+
role: searchActors ? 'combobox' : 'textbox',
|
|
198
|
+
'aria-label': label,
|
|
199
|
+
...(searchActors
|
|
200
|
+
? {
|
|
201
|
+
'aria-autocomplete': 'list',
|
|
202
|
+
'aria-expanded': 'false',
|
|
203
|
+
'aria-haspopup': 'listbox'
|
|
204
|
+
}
|
|
205
|
+
: { 'aria-multiline': String(!singleLine) }),
|
|
206
|
+
class: cn(
|
|
207
|
+
editorClass,
|
|
208
|
+
markdownTools ? markdownClass : 'whitespace-pre-wrap [&_[data-link-embed]]:my-3'
|
|
209
|
+
)
|
|
210
|
+
},
|
|
211
|
+
handleKeyDown: (view, event) =>
|
|
212
|
+
singleLine &&
|
|
213
|
+
event.key === 'Enter' &&
|
|
214
|
+
!event.isComposing &&
|
|
215
|
+
!view.dom.getAttribute('aria-activedescendant'),
|
|
216
|
+
transformPastedText: (text) => (singleLine ? text.replace(/[\r\n]+/g, ' ') : text),
|
|
217
|
+
// Accept text only, read as Markdown where the editor supports it.
|
|
218
|
+
handlePaste: (_view, event) => {
|
|
219
|
+
const text = event.clipboardData?.getData('text/plain');
|
|
220
|
+
if (text === undefined) return false;
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
paste(created, text);
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
onUpdate: ({ editor: updated }) => {
|
|
227
|
+
const content = read(updated.getJSON());
|
|
228
|
+
current = content.text;
|
|
229
|
+
value = content.text;
|
|
230
|
+
onupdate?.(content);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
instance = created;
|
|
234
|
+
editor = created;
|
|
235
|
+
};
|
|
236
|
+
if (markdown)
|
|
237
|
+
void import('../editor/markdown.js').then((module) => {
|
|
238
|
+
markdownTools = module;
|
|
239
|
+
create();
|
|
240
|
+
});
|
|
241
|
+
else create();
|
|
242
|
+
return () => {
|
|
243
|
+
destroyed = true;
|
|
244
|
+
instance?.destroy();
|
|
245
|
+
editor = null;
|
|
246
|
+
};
|
|
247
|
+
});
|
|
248
|
+
$effect(() => {
|
|
249
|
+
const facetsKey = JSON.stringify(facets ?? null);
|
|
250
|
+
if (editor && (value !== current || facetsKey !== currentFacets)) {
|
|
251
|
+
current = value;
|
|
252
|
+
currentFacets = facetsKey;
|
|
253
|
+
editor.commands.setContent(load(value, facets), { emitUpdate: false });
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
$effect(() => {
|
|
257
|
+
editor?.setEditable(!disabled, false);
|
|
258
|
+
editor?.view.dom.setAttribute('aria-disabled', String(disabled));
|
|
259
|
+
});
|
|
260
|
+
</script>
|
|
261
|
+
|
|
262
|
+
<div
|
|
263
|
+
bind:this={host}
|
|
264
|
+
class={cn(
|
|
265
|
+
'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',
|
|
266
|
+
className
|
|
267
|
+
)}
|
|
268
|
+
data-slot="rich-text-editor"
|
|
269
|
+
>
|
|
270
|
+
<div bind:this={element}></div>
|
|
271
|
+
</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>
|