@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.
Files changed (93) 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 +271 -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 +7 -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 +5 -1
  76. package/dist/richtext/serialize.d.ts +11 -0
  77. package/dist/richtext/serialize.js +462 -0
  78. package/dist/richtext.d.ts +1 -0
  79. package/dist/richtext.js +1 -0
  80. package/dist/social/MentionOptions.svelte +30 -0
  81. package/dist/social/MentionOptions.svelte.d.ts +12 -0
  82. package/dist/social/composer.d.ts +143 -0
  83. package/dist/social/composer.js +141 -0
  84. package/dist/social/{mention-suggestions.d.ts → mention-suggestions.svelte.d.ts} +1 -1
  85. package/dist/social/{mention-suggestions.js → mention-suggestions.svelte.js} +36 -46
  86. package/dist/social/richtext.js +2 -0
  87. package/dist/social.d.ts +2 -0
  88. package/dist/social.js +1 -0
  89. package/dist/styles.d.ts +5 -0
  90. package/dist/styles.js +5 -0
  91. package/package.json +4 -1
  92. package/dist/components/PostComposer.svelte +0 -41
  93. package/dist/components/PostComposer.svelte.d.ts +0 -16
@@ -0,0 +1,269 @@
1
+ import { detectTokens } from '../richtext/detect.js';
2
+ import { paragraphParts, safeWebUrl } from '../richtext/document.js';
3
+ export const LINK_EMBED = 'linkEmbed';
4
+ const MAX_DEPTH = 32;
5
+ const MARKS = { strong: 'bold', emphasis: 'italic', delete: 'strike' };
6
+ const STYLES = { bold: 'strong', italic: 'emphasis', strike: 'delete' };
7
+ function labelOf(nodes, depth = 0) {
8
+ if (depth > MAX_DEPTH)
9
+ return '';
10
+ return nodes
11
+ .map((node) => node.type === 'text' || node.type === 'code'
12
+ ? node.value
13
+ : node.type === 'break'
14
+ ? '\n'
15
+ : node.type === 'mention' || node.type === 'tag'
16
+ ? node.text
17
+ : labelOf(node.children, depth + 1))
18
+ .join('');
19
+ }
20
+ /** A URL alone, e.g. the whole text of a line; undefined for anything else. */
21
+ export function bareUrl(text) {
22
+ const trimmed = text.trim();
23
+ return /^https?:\/\/\S+$/i.test(trimmed) ? safeWebUrl(trimmed) : undefined;
24
+ }
25
+ function inlineContent(nodes, marks, depth = 0) {
26
+ if (depth > MAX_DEPTH)
27
+ return [];
28
+ const text = (value) => value
29
+ .split('\n')
30
+ .flatMap((line, index) => [
31
+ ...(index ? [{ type: 'hardBreak' }] : []),
32
+ ...(line ? [{ type: 'text', text: line, ...(marks.length ? { marks } : {}) }] : [])
33
+ ]);
34
+ return nodes.flatMap((node) => {
35
+ switch (node.type) {
36
+ case 'text':
37
+ return text(node.value);
38
+ case 'break':
39
+ return [{ type: 'hardBreak' }];
40
+ case 'code':
41
+ // Inline code carries no other formatting in the editor.
42
+ return node.value
43
+ ? [{ type: 'text', text: node.value.replace(/\n/g, ' '), marks: [{ type: 'code' }] }]
44
+ : [];
45
+ case 'mention':
46
+ return node.actor.startsWith('did:')
47
+ ? [{ type: 'mention', attrs: { id: node.actor, label: node.text.replace(/^[@@]/, '') } }]
48
+ : text(node.text);
49
+ case 'tag':
50
+ return text(node.text);
51
+ case 'link': {
52
+ // A link labeled with its own address is typed as plain text and detected again.
53
+ const label = labelOf(node.children);
54
+ if (label === node.url || bareUrl(label) === node.url)
55
+ return text(label);
56
+ return inlineContent(node.children, marks.some((mark) => mark.type === 'link')
57
+ ? marks
58
+ : [...marks, { type: 'link', attrs: { href: node.url } }], depth + 1);
59
+ }
60
+ case 'strong':
61
+ case 'emphasis':
62
+ case 'delete':
63
+ return inlineContent(node.children, marks.some((mark) => mark.type === MARKS[node.type])
64
+ ? marks
65
+ : [...marks, { type: MARKS[node.type] }], depth + 1);
66
+ default:
67
+ return [];
68
+ }
69
+ });
70
+ }
71
+ function paragraphContent(children, isEmbed) {
72
+ return paragraphParts(children, isEmbed).map((part) => part.embed
73
+ ? { type: LINK_EMBED, attrs: { url: part.embed } }
74
+ : { type: 'paragraph', content: inlineContent(part.children, []) });
75
+ }
76
+ function blockContent(blocks, isEmbed, depth = 0) {
77
+ if (depth > MAX_DEPTH)
78
+ return [];
79
+ return blocks.flatMap((block) => {
80
+ switch (block.type) {
81
+ case 'paragraph':
82
+ return paragraphContent(block.children, isEmbed);
83
+ case 'heading':
84
+ return [
85
+ {
86
+ type: 'heading',
87
+ attrs: { level: Math.min(6, Math.max(1, Math.trunc(block.depth) || 1)) },
88
+ content: inlineContent(block.children, []).map((node) => node.type === 'hardBreak' ? { type: 'text', text: ' ' } : node)
89
+ }
90
+ ];
91
+ case 'blockquote':
92
+ return [
93
+ {
94
+ type: 'blockquote',
95
+ content: atLeastOne(blockContent(block.children, isEmbed, depth + 1))
96
+ }
97
+ ];
98
+ case 'list':
99
+ return [
100
+ {
101
+ type: block.ordered ? 'orderedList' : 'bulletList',
102
+ ...(block.ordered ? { attrs: { start: block.start ?? 1 } } : {}),
103
+ content: block.items.map((item) => {
104
+ const content = blockContent(item, isEmbed, depth + 1);
105
+ // A list item starts with a paragraph.
106
+ return {
107
+ type: 'listItem',
108
+ content: content[0]?.type === 'paragraph' ? content : [{ type: 'paragraph' }, ...content]
109
+ };
110
+ })
111
+ }
112
+ ];
113
+ case 'codeBlock':
114
+ return [
115
+ {
116
+ type: 'codeBlock',
117
+ attrs: { language: block.lang ?? null },
118
+ ...(block.value ? { content: [{ type: 'text', text: block.value }] } : {})
119
+ }
120
+ ];
121
+ case 'thematicBreak':
122
+ return [{ type: 'horizontalRule' }];
123
+ default:
124
+ return [];
125
+ }
126
+ });
127
+ }
128
+ function atLeastOne(content) {
129
+ return content.length ? content : [{ type: 'paragraph' }];
130
+ }
131
+ /** One paragraph per line, as plain-text fields have no blocks. */
132
+ function plainContent(document, isEmbed) {
133
+ const inline = document.children.flatMap((block) => 'children' in block && block.type === 'paragraph' ? inlineContent(block.children, []) : []);
134
+ const lines = [[]];
135
+ for (const node of inline) {
136
+ if (node.type === 'hardBreak')
137
+ lines.push([]);
138
+ else
139
+ lines.at(-1).push({ ...node, marks: undefined });
140
+ }
141
+ return lines.map((content) => {
142
+ const url = isEmbed && content.length === 1 && content[0].type === 'text'
143
+ ? bareUrl(content[0].text ?? '')
144
+ : undefined;
145
+ return url && isEmbed(url)
146
+ ? { type: LINK_EMBED, attrs: { url } }
147
+ : { type: 'paragraph', content };
148
+ });
149
+ }
150
+ /** A parsed document as editor content. Links that would be shown as embeds become embed blocks. */
151
+ export function documentToEditor(document, isEmbed) {
152
+ return {
153
+ type: 'doc',
154
+ content: atLeastOne(document.markdown ? blockContent(document.children, isEmbed) : plainContent(document, isEmbed))
155
+ };
156
+ }
157
+ function inlineNodes(content) {
158
+ return (content ?? []).flatMap((node) => {
159
+ if (node.type === 'hardBreak')
160
+ return [{ type: 'break' }];
161
+ if (node.type === 'mention') {
162
+ const actor = String(node.attrs?.id ?? '');
163
+ return [{ type: 'mention', actor, text: `@${node.attrs?.label ?? actor}` }];
164
+ }
165
+ if (node.type !== 'text' || !node.text)
166
+ return [];
167
+ const marks = node.marks ?? [];
168
+ let inline = marks.some((mark) => mark.type === 'code')
169
+ ? { type: 'code', value: node.text }
170
+ : { type: 'text', value: node.text };
171
+ for (const mark of marks) {
172
+ const style = STYLES[mark.type];
173
+ if (style)
174
+ inline = { type: style, children: [inline] };
175
+ }
176
+ const href = safeWebUrl(marks.find((mark) => mark.type === 'link')?.attrs?.href);
177
+ return [href ? { type: 'link', url: href, children: [inline] } : inline];
178
+ });
179
+ }
180
+ function blockNodes(content, depth = 0) {
181
+ if (depth > MAX_DEPTH)
182
+ return [];
183
+ return (content ?? []).flatMap((node) => {
184
+ switch (node.type) {
185
+ case 'paragraph':
186
+ return [{ type: 'paragraph', children: inlineNodes(node.content) }];
187
+ case LINK_EMBED: {
188
+ const url = safeWebUrl(node.attrs?.url);
189
+ return url ? [{ type: 'paragraph', children: [{ type: 'text', value: url }] }] : [];
190
+ }
191
+ case 'heading':
192
+ return [
193
+ {
194
+ type: 'heading',
195
+ depth: Math.min(6, Math.max(1, Number(node.attrs?.level) || 1)),
196
+ children: inlineNodes(node.content)
197
+ }
198
+ ];
199
+ case 'blockquote':
200
+ return [{ type: 'blockquote', children: blockNodes(node.content, depth + 1) }];
201
+ case 'bulletList':
202
+ case 'orderedList': {
203
+ const start = Number(node.attrs?.start);
204
+ return [
205
+ {
206
+ type: 'list',
207
+ ordered: node.type === 'orderedList',
208
+ ...(node.type === 'orderedList' && Number.isInteger(start) && start !== 1
209
+ ? { start }
210
+ : {}),
211
+ items: (node.content ?? []).map((item) => blockNodes(item.content, depth + 1))
212
+ }
213
+ ];
214
+ }
215
+ case 'codeBlock': {
216
+ const lang = typeof node.attrs?.language === 'string' ? node.attrs.language : '';
217
+ return [
218
+ {
219
+ type: 'codeBlock',
220
+ value: (node.content ?? []).map((child) => child.text ?? '').join(''),
221
+ ...(lang ? { lang } : {})
222
+ }
223
+ ];
224
+ }
225
+ case 'horizontalRule':
226
+ return [{ type: 'thematicBreak' }];
227
+ default:
228
+ return [];
229
+ }
230
+ });
231
+ }
232
+ /** Editor content as a Markdown document, ready for `richTextToMarkdown`. */
233
+ export function editorToDocument(json) {
234
+ return { version: 1, markdown: true, children: blockNodes(json.content) };
235
+ }
236
+ function mentionDids(node, dids = new Map()) {
237
+ if (node.type === 'mention') {
238
+ const { id, label } = node.attrs ?? {};
239
+ if (typeof id === 'string' && id.startsWith('did:') && typeof label === 'string')
240
+ dids.set(label.toLowerCase(), id);
241
+ }
242
+ node.content?.forEach((child) => mentionDids(child, dids));
243
+ return dids;
244
+ }
245
+ /**
246
+ * Facets for Markdown source: links and hashtags found in the text, and mentions picked from
247
+ * the suggestions (typed handles have no DID yet; resolve those before saving).
248
+ */
249
+ export function markdownFacets(text, json) {
250
+ const dids = mentionDids(json);
251
+ const bytes = (value) => new TextEncoder().encode(value).length;
252
+ const facets = [];
253
+ let byteStart = 0;
254
+ for (const token of detectTokens(text)) {
255
+ const byteEnd = byteStart + bytes(token.raw);
256
+ const index = { byteStart, byteEnd };
257
+ if (token.type === 'autolink')
258
+ facets.push({ index, features: [{ $type: 'app.bsky.richtext.facet#link', uri: token.url }] });
259
+ else if (token.type === 'topic')
260
+ facets.push({ index, features: [{ $type: 'app.bsky.richtext.facet#tag', tag: token.name }] });
261
+ else if (token.type === 'mention') {
262
+ const did = dids.get(token.handle.toLowerCase());
263
+ if (did)
264
+ facets.push({ index, features: [{ $type: 'app.bsky.richtext.facet#mention', did }] });
265
+ }
266
+ byteStart = byteEnd;
267
+ }
268
+ return facets;
269
+ }
@@ -0,0 +1,17 @@
1
+ import { Node, type Editor } from '@tiptap/core';
2
+ import type { LinkEmbedOptions } from '../embeds/types.js';
3
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
4
+ export type LinkEmbedNodeOptions = {
5
+ isEmbed: (url: string) => boolean;
6
+ /** Read when an embed is shown, so the editor's current options apply. */
7
+ embedOptions: () => LinkEmbedOptions & {
8
+ socialClient?: PreferredSocialClient | null;
9
+ };
10
+ };
11
+ /** Turn the paragraph the cursor is in into an embed when it is nothing but an embeddable link. */
12
+ export declare function embedCurrentParagraph(editor: Editor, isEmbed: (url: string) => boolean): boolean;
13
+ /**
14
+ * A link shown as its embed. It is not stored as anything special: in the text it is the URL
15
+ * alone on its line, which the viewer shows as the same embed.
16
+ */
17
+ export declare const LinkEmbedNode: Node<LinkEmbedNodeOptions, any>;
@@ -0,0 +1,96 @@
1
+ import { Node } from '@tiptap/core';
2
+ import { closeHistory } from '@tiptap/pm/history';
3
+ import { TextSelection } from '@tiptap/pm/state';
4
+ import { mount, unmount } from 'svelte';
5
+ import { safeHttpUrl } from '../urls.js';
6
+ import { bareUrl, LINK_EMBED } from './document.js';
7
+ import EditorLinkEmbed from './EditorLinkEmbed.svelte';
8
+ /** Turn the paragraph the cursor is in into an embed when it is nothing but an embeddable link. */
9
+ export function embedCurrentParagraph(editor, isEmbed) {
10
+ const { state } = editor;
11
+ const { $from, empty } = state.selection;
12
+ const paragraph = $from.parent;
13
+ const type = state.schema.nodes[LINK_EMBED];
14
+ if (!type ||
15
+ !empty ||
16
+ $from.depth < 1 ||
17
+ paragraph.type.name !== 'paragraph' ||
18
+ paragraph.childCount !== 1 ||
19
+ !paragraph.firstChild?.isText ||
20
+ paragraph.firstChild.marks.length)
21
+ return false;
22
+ const url = bareUrl(paragraph.textContent);
23
+ if (!url || !isEmbed(url))
24
+ return false;
25
+ const depth = $from.depth;
26
+ const index = $from.index(depth - 1);
27
+ if (!$from.node(depth - 1).canReplaceWith(index, index + 1, type))
28
+ return false;
29
+ const from = $from.before(depth);
30
+ // Its own undo step, so that undo turns the embed back into the link.
31
+ const tr = closeHistory(state.tr).replaceWith(from, $from.after(depth), [
32
+ type.create({ url }),
33
+ state.schema.nodes.paragraph.create()
34
+ ]);
35
+ tr.setSelection(TextSelection.create(tr.doc, from + 2));
36
+ editor.view.dispatch(tr.scrollIntoView());
37
+ return true;
38
+ }
39
+ /**
40
+ * A link shown as its embed. It is not stored as anything special: in the text it is the URL
41
+ * alone on its line, which the viewer shows as the same embed.
42
+ */
43
+ export const LinkEmbedNode = Node.create({
44
+ name: LINK_EMBED,
45
+ group: 'block',
46
+ atom: true,
47
+ selectable: true,
48
+ addOptions: () => ({ isEmbed: () => false, embedOptions: () => ({}) }),
49
+ addAttributes: () => ({ url: { default: '' } }),
50
+ parseHTML: () => [
51
+ {
52
+ tag: 'div[data-link-embed]',
53
+ getAttrs: (element) => {
54
+ const url = safeHttpUrl(element.getAttribute('data-link-embed'));
55
+ return url ? { url } : false;
56
+ }
57
+ }
58
+ ],
59
+ renderHTML: ({ node }) => ['div', { 'data-link-embed': node.attrs.url }, node.attrs.url],
60
+ renderText: ({ node }) => node.attrs.url,
61
+ addKeyboardShortcuts() {
62
+ return { Enter: ({ editor }) => embedCurrentParagraph(editor, this.options.isEmbed) };
63
+ },
64
+ addNodeView() {
65
+ return ({ node, editor, getPos }) => {
66
+ const dom = document.createElement('div');
67
+ dom.dataset.linkEmbed = node.attrs.url;
68
+ dom.contentEditable = 'false';
69
+ const component = mount(EditorLinkEmbed, {
70
+ target: dom,
71
+ props: {
72
+ url: node.attrs.url,
73
+ options: this.options.embedOptions,
74
+ onremove: () => {
75
+ const pos = getPos();
76
+ if (typeof pos !== 'number' || editor.isDestroyed || !editor.isEditable)
77
+ return;
78
+ editor
79
+ .chain()
80
+ .focus()
81
+ .deleteRange({ from: pos, to: pos + node.nodeSize })
82
+ .run();
83
+ }
84
+ }
85
+ });
86
+ return {
87
+ dom,
88
+ update: (next) => next.type === node.type && next.attrs.url === node.attrs.url,
89
+ // The embed handles its own clicks (play buttons, links); keys still reach the editor.
90
+ stopEvent: (event) => !/^key/.test(event.type),
91
+ ignoreMutation: () => true,
92
+ destroy: () => void unmount(component)
93
+ };
94
+ };
95
+ }
96
+ });
@@ -0,0 +1,6 @@
1
+ import { type AnyExtension } from '@tiptap/core';
2
+ /**
3
+ * The blocks and formatting of the kit's Markdown: headings, lists, quotes, code, rules, bold,
4
+ * italic, strikethrough, inline code and links, with their usual typing shortcuts.
5
+ */
6
+ export declare function markdownExtensions(): AnyExtension[];
@@ -0,0 +1,42 @@
1
+ import { Extension, InputRule } from '@tiptap/core';
2
+ import StarterKit from '@tiptap/starter-kit';
3
+ import { safeHttpUrl } from '../urls.js';
4
+ /** Typing `[label](https://…)` makes a link, like the other Markdown shortcuts. */
5
+ const MarkdownLink = Extension.create({
6
+ name: 'markdownLink',
7
+ addInputRules() {
8
+ return [
9
+ new InputRule({
10
+ find: /\[([^[\]\n]+)\]\((https?:\/\/[^\s()]+)\)$/,
11
+ handler: ({ state, range, match }) => {
12
+ const href = safeHttpUrl(match[2]);
13
+ const link = state.schema.marks.link;
14
+ if (!href || !link)
15
+ return null;
16
+ state.tr
17
+ .replaceWith(range.from, range.to, state.schema.text(match[1], [link.create({ href })]))
18
+ .removeStoredMark(link);
19
+ }
20
+ })
21
+ ];
22
+ }
23
+ });
24
+ /**
25
+ * The blocks and formatting of the kit's Markdown: headings, lists, quotes, code, rules, bold,
26
+ * italic, strikethrough, inline code and links, with their usual typing shortcuts.
27
+ */
28
+ export function markdownExtensions() {
29
+ return [
30
+ StarterKit.configure({
31
+ underline: false,
32
+ link: {
33
+ openOnClick: false,
34
+ autolink: false,
35
+ linkOnPaste: false,
36
+ isAllowedUri: (url) => !!safeHttpUrl(url),
37
+ HTMLAttributes: { rel: 'noopener noreferrer nofollow ugc', target: '_blank' }
38
+ }
39
+ }),
40
+ MarkdownLink
41
+ ];
42
+ }
@@ -0,0 +1,3 @@
1
+ export { markdownExtensions } from './markdown-extensions.js';
2
+ export { parseMarkdown } from '../richtext/markdown.js';
3
+ export { richTextToMarkdown } from '../richtext/serialize.js';
@@ -0,0 +1,4 @@
1
+ // Everything only the Markdown editor needs, loaded on demand as one module.
2
+ export { markdownExtensions } from './markdown-extensions.js';
3
+ export { parseMarkdown } from '../richtext/markdown.js';
4
+ export { richTextToMarkdown } from '../richtext/serialize.js';
@@ -0,0 +1,9 @@
1
+ <script lang="ts">
2
+ import ExternalEmbed from '../components/ExternalEmbed.svelte';
3
+ import type { ExternalEmbedProvider } from '../social/external-embeds.js';
4
+ import type { LinkEmbedProps } from './types.js';
5
+
6
+ let { url, ref }: LinkEmbedProps<{ provider: ExternalEmbedProvider }> = $props();
7
+ </script>
8
+
9
+ <ExternalEmbed embed={{ type: 'external', uri: url, title: '' }} providers={[ref.provider]} />
@@ -0,0 +1,7 @@
1
+ import type { ExternalEmbedProvider } from '../social/external-embeds.js';
2
+ import type { LinkEmbedProps } from './types.js';
3
+ declare const PlayerLinkEmbed: import("svelte").Component<LinkEmbedProps<{
4
+ provider: ExternalEmbedProvider;
5
+ }>, {}, "">;
6
+ type PlayerLinkEmbed = ReturnType<typeof PlayerLinkEmbed>;
7
+ export default PlayerLinkEmbed;
@@ -1,17 +1,17 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
- import NestedComments from '../../components/NestedComments.svelte';
4
- import Surface from '../../components/Surface.svelte';
3
+ import NestedComments from '../components/NestedComments.svelte';
4
+ import Surface from '../components/Surface.svelte';
5
5
  import {
6
6
  blueskyPostToPostData,
7
7
  hasModerationLabel,
8
8
  type BlueskyPostView,
9
9
  type PostData
10
- } from '../../social/posts.js';
11
- import type { PreferredSocialClient } from '../../social/preferred-client.js';
12
- import { parseSocialPostUrl, socialPostUrl } from '../../social/urls.js';
13
- import { safeHttpUrl } from '../../urls.js';
14
- import { appviewUrl } from '../atproto-helpers.js';
10
+ } from '../social/posts.js';
11
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
12
+ import { parseSocialPostUrl, socialPostUrl } from '../social/urls.js';
13
+ import { safeHttpUrl } from '../urls.js';
14
+ import { appviewUrl } from '../events/atproto-helpers.js';
15
15
 
16
16
  let {
17
17
  url,
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { PreferredSocialClient } from '../../social/preferred-client.js';
2
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
3
3
  type $$ComponentProps = {
4
4
  url: string;
5
5
  /** The ordinary link, shown until the post loads and whenever it can't be shown. */
@@ -1,12 +1,12 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
- import Avatar from '../../components/Avatar.svelte';
4
- import Surface from '../../components/Surface.svelte';
5
- import { blueskyProfileToProfileData, type ProfileData } from '../../social/profile.js';
6
- import type { PreferredSocialClient } from '../../social/preferred-client.js';
7
- import { parseSocialProfileUrl, socialProfileUrl } from '../../social/urls.js';
8
- import { focus } from '../../styles.js';
9
- import { appviewUrl } from '../atproto-helpers.js';
3
+ import Avatar from '../components/Avatar.svelte';
4
+ import Surface from '../components/Surface.svelte';
5
+ import { blueskyProfileToProfileData, type ProfileData } from '../social/profile.js';
6
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
7
+ import { parseSocialProfileUrl, socialProfileUrl } from '../social/urls.js';
8
+ import { focus } from '../styles.js';
9
+ import { appviewUrl } from '../events/atproto-helpers.js';
10
10
 
11
11
  let {
12
12
  url,
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { PreferredSocialClient } from '../../social/preferred-client.js';
2
+ import type { PreferredSocialClient } from '../social/preferred-client.js';
3
3
  type $$ComponentProps = {
4
4
  url: string;
5
5
  /** The ordinary link, shown until the profile loads and whenever it can't be shown. */
@@ -0,0 +1,10 @@
1
+ import type { LinkEmbed, LinkEmbedOptions } from './types.js';
2
+ /**
3
+ * Choose the link embeds for every `RichText`, `RichTextEditor` and `LinkEmbed` below this
4
+ * component, e.g. once in the root layout. Pass a function to keep the options reactive.
5
+ */
6
+ export declare function setLinkEmbeds(options: LinkEmbedOptions | (() => LinkEmbedOptions)): void;
7
+ /** The options from the nearest `setLinkEmbeds`; call during component initialization. */
8
+ export declare function linkEmbedOptions(): () => LinkEmbedOptions;
9
+ /** `true` selects the app's embeds, a list replaces them and anything else turns embeds off. */
10
+ export declare function selectLinkEmbeds(embeds: boolean | readonly LinkEmbed[] | undefined, options: LinkEmbedOptions): readonly LinkEmbed[];
@@ -0,0 +1,20 @@
1
+ import { getContext, hasContext, setContext } from 'svelte';
2
+ import { defaultLinkEmbeds } from './defaults.js';
3
+ const key = Symbol('atmo-kit-link-embeds');
4
+ /**
5
+ * Choose the link embeds for every `RichText`, `RichTextEditor` and `LinkEmbed` below this
6
+ * component, e.g. once in the root layout. Pass a function to keep the options reactive.
7
+ */
8
+ export function setLinkEmbeds(options) {
9
+ setContext(key, typeof options === 'function' ? options : () => options);
10
+ }
11
+ /** The options from the nearest `setLinkEmbeds`; call during component initialization. */
12
+ export function linkEmbedOptions() {
13
+ return hasContext(key) ? getContext(key) : () => ({});
14
+ }
15
+ /** `true` selects the app's embeds, a list replaces them and anything else turns embeds off. */
16
+ export function selectLinkEmbeds(embeds, options) {
17
+ if (Array.isArray(embeds))
18
+ return embeds;
19
+ return embeds === true ? (options.embeds ?? defaultLinkEmbeds) : [];
20
+ }
@@ -0,0 +1,27 @@
1
+ import { type ExternalEmbedProvider } from '../social/external-embeds.js';
2
+ import type { LinkEmbed } from './types.js';
3
+ /** A post on Bluesky or another listed client, shown as the post itself. */
4
+ export declare const postLinkEmbed: LinkEmbed<{
5
+ actor: string;
6
+ rkey: string;
7
+ uri: string;
8
+ }>;
9
+ /** A profile on Bluesky or another listed client, shown as a small profile card. */
10
+ export declare const profileLinkEmbed: LinkEmbed<{
11
+ actor: string;
12
+ }>;
13
+ /**
14
+ * Show links a media provider recognizes in the kit's player. Iframe players wait for their
15
+ * play button, so pass `requests: 'click'` for them.
16
+ */
17
+ export declare function playerLinkEmbed(provider: ExternalEmbedProvider, requests?: LinkEmbed['requests']): LinkEmbed<{
18
+ provider: ExternalEmbedProvider;
19
+ }>;
20
+ export declare const youtubeLinkEmbed: LinkEmbed<{
21
+ provider: ExternalEmbedProvider;
22
+ }>;
23
+ export declare const klipyLinkEmbed: LinkEmbed<{
24
+ provider: ExternalEmbedProvider;
25
+ }>;
26
+ /** Ordered, explicit list. Apps add their own embeds before or after these. */
27
+ export declare const defaultLinkEmbeds: readonly LinkEmbed[];
@@ -0,0 +1,38 @@
1
+ import { klipyEmbedProvider, youtubeEmbedProvider } from '../social/external-embeds.js';
2
+ import { parseSocialPostUrl, parseSocialProfileUrl } from '../social/urls.js';
3
+ /** A post on Bluesky or another listed client, shown as the post itself. */
4
+ export const postLinkEmbed = {
5
+ id: 'post',
6
+ label: 'post',
7
+ match: (url) => parseSocialPostUrl(url.href),
8
+ load: () => import('./PostLinkEmbed.svelte')
9
+ };
10
+ /** A profile on Bluesky or another listed client, shown as a small profile card. */
11
+ export const profileLinkEmbed = {
12
+ id: 'profile',
13
+ label: 'profile',
14
+ match: (url) => parseSocialProfileUrl(url.href),
15
+ load: () => import('./ProfileLinkEmbed.svelte')
16
+ };
17
+ /**
18
+ * Show links a media provider recognizes in the kit's player. Iframe players wait for their
19
+ * play button, so pass `requests: 'click'` for them.
20
+ */
21
+ export function playerLinkEmbed(provider, requests = 'mount') {
22
+ return {
23
+ id: provider.id,
24
+ label: provider.label,
25
+ match: (url) => provider.resolve(url, { type: 'external', uri: url.href, title: '' }) ? { provider } : null,
26
+ load: () => import('./PlayerLinkEmbed.svelte'),
27
+ requests
28
+ };
29
+ }
30
+ export const youtubeLinkEmbed = playerLinkEmbed(youtubeEmbedProvider, 'click');
31
+ export const klipyLinkEmbed = playerLinkEmbed(klipyEmbedProvider);
32
+ /** Ordered, explicit list. Apps add their own embeds before or after these. */
33
+ export const defaultLinkEmbeds = [
34
+ postLinkEmbed,
35
+ profileLinkEmbed,
36
+ youtubeLinkEmbed,
37
+ klipyLinkEmbed
38
+ ];
@@ -0,0 +1,9 @@
1
+ import type { LinkEmbed } from './types.js';
2
+ export type LinkEmbedMatch = {
3
+ embed: LinkEmbed;
4
+ ref: unknown;
5
+ url: string;
6
+ };
7
+ /** The first embed that can render this link. Syntax only; nothing is fetched. */
8
+ export declare function resolveLinkEmbed(value: unknown, embeds: readonly LinkEmbed[]): LinkEmbedMatch | null;
9
+ export declare function isClickToLoad(embed: LinkEmbed, clickToLoad: boolean | ((embed: LinkEmbed) => boolean) | undefined): boolean;