@atmo-dev/kit 0.18.0 → 0.19.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/articles/ArticleCard.svelte +97 -0
- package/dist/articles/ArticleCard.svelte.d.ts +20 -0
- package/dist/articles/ArticleCodeBlock.svelte +121 -0
- package/dist/articles/ArticleCodeBlock.svelte.d.ts +11 -0
- package/dist/articles/ArticleEditor.svelte +340 -0
- package/dist/articles/ArticleEditor.svelte.d.ts +48 -0
- package/dist/articles/ArticleLinkEmbed.svelte +50 -0
- package/dist/articles/ArticleLinkEmbed.svelte.d.ts +5 -0
- package/dist/articles/ArticleView.svelte +128 -0
- package/dist/articles/ArticleView.svelte.d.ts +46 -0
- package/dist/articles/PublicationIcon.svelte +37 -0
- package/dist/articles/PublicationIcon.svelte.d.ts +10 -0
- package/dist/articles/article-link-embed.d.ts +36 -0
- package/dist/articles/article-link-embed.js +29 -0
- package/dist/articles/dates.d.ts +2 -0
- package/dist/articles/dates.js +12 -0
- package/dist/articles/images.d.ts +5 -0
- package/dist/articles/images.js +44 -0
- package/dist/articles/markdown.d.ts +15 -0
- package/dist/articles/markdown.js +52 -0
- package/dist/articles/paste.d.ts +11 -0
- package/dist/articles/paste.js +27 -0
- package/dist/articles/records.d.ts +166 -0
- package/dist/articles/records.js +423 -0
- package/dist/articles/styles.d.ts +4 -0
- package/dist/articles/styles.js +14 -0
- package/dist/articles-data.d.ts +8 -0
- package/dist/articles-data.js +8 -0
- package/dist/articles.d.ts +10 -0
- package/dist/articles.js +8 -0
- package/dist/components/ExternalEmbed.svelte +16 -2
- package/dist/components/ExternalEmbed.svelte.d.ts +6 -0
- package/dist/components/IconMaker.svelte +119 -0
- package/dist/components/IconMaker.svelte.d.ts +9 -0
- package/dist/components/IconRail.svelte +9 -6
- package/dist/components/IconRail.svelte.d.ts +2 -0
- package/dist/components/LinkEmbed.svelte +24 -21
- package/dist/components/LinkEmbed.svelte.d.ts +3 -2
- package/dist/components/PaletteApply.svelte +62 -0
- package/dist/components/PaletteApply.svelte.d.ts +9 -0
- package/dist/components/PalettePicker.svelte +92 -0
- package/dist/components/PalettePicker.svelte.d.ts +13 -0
- package/dist/components/PostComments.svelte +129 -0
- package/dist/components/PostComments.svelte.d.ts +15 -0
- package/dist/components/RichText.svelte +199 -9
- package/dist/components/RichText.svelte.d.ts +17 -0
- package/dist/components/RichTextEditor.svelte +155 -13
- package/dist/components/RichTextEditor.svelte.d.ts +26 -3
- package/dist/components/composer/ComposerPost.svelte +20 -4
- package/dist/components/composer/ComposerPost.svelte.d.ts +3 -1
- package/dist/components/composer/PostComposer.svelte +29 -3
- package/dist/components/composer/PostComposer.svelte.d.ts +12 -1
- package/dist/editor/EditorMenus.svelte +438 -0
- package/dist/editor/EditorMenus.svelte.d.ts +9 -0
- package/dist/editor/SlashOptions.svelte +45 -0
- package/dist/editor/SlashOptions.svelte.d.ts +12 -0
- package/dist/editor/article-commands.d.ts +44 -0
- package/dist/editor/article-commands.js +289 -0
- package/dist/editor/article-extensions.d.ts +8 -0
- package/dist/editor/article-extensions.js +315 -0
- package/dist/editor/article-menus.d.ts +2 -0
- package/dist/editor/article-menus.js +3 -0
- package/dist/editor/document.d.ts +5 -0
- package/dist/editor/document.js +163 -12
- package/dist/editor/image-node.d.ts +8 -0
- package/dist/editor/image-node.js +75 -0
- package/dist/editor/markdown-extensions.d.ts +1 -5
- package/dist/editor/markdown-extensions.js +37 -2
- package/dist/editor/slash-menu.svelte.d.ts +9 -0
- package/dist/editor/slash-menu.svelte.js +134 -0
- package/dist/embeds/PlayerLinkEmbed.svelte +9 -1
- package/dist/embeds/PostLinkEmbed.svelte +12 -29
- package/dist/embeds/PostLinkEmbed.svelte.d.ts +3 -0
- package/dist/embeds/ProfileLinkEmbed.svelte +12 -17
- package/dist/embeds/ProfileLinkEmbed.svelte.d.ts +3 -0
- package/dist/embeds/defaults.d.ts +4 -2
- package/dist/embeds/defaults.js +7 -3
- package/dist/embeds/load.d.ts +44 -0
- package/dist/embeds/load.js +139 -0
- package/dist/embeds/types.d.ts +18 -3
- package/dist/events/EventComments.svelte +4 -101
- package/dist/events/EventComments.svelte.d.ts +1 -1
- package/dist/events/EventView.svelte +5 -0
- package/dist/events/EventView.svelte.d.ts +3 -0
- package/dist/events/event-link-embed.d.ts +4 -1
- package/dist/events/event-link-embed.js +9 -1
- package/dist/events/event-view/EventLinkEmbed.svelte +8 -8
- package/dist/events/event-view/EventLinkEmbed.svelte.d.ts +3 -2
- package/dist/icon-maker/artwork.d.ts +11 -0
- package/dist/icon-maker/artwork.js +25 -0
- package/dist/icon-maker/index.d.ts +12 -0
- package/dist/icon-maker/index.js +73 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +7 -1
- package/dist/palettes.d.ts +20 -0
- package/dist/palettes.js +37 -0
- package/dist/richtext/article-styles.d.ts +10 -0
- package/dist/richtext/article-styles.js +28 -0
- package/dist/richtext/document.d.ts +63 -1
- package/dist/richtext/document.js +54 -0
- package/dist/richtext/markdown.d.ts +19 -4
- package/dist/richtext/markdown.js +223 -18
- package/dist/richtext/serialize.d.ts +5 -1
- package/dist/richtext/serialize.js +163 -31
- package/dist/richtext/vendor/markdown-tree.d.ts +4 -3
- package/dist/richtext/vendor/markdown-tree.js +2584 -26
- package/dist/richtext.d.ts +7 -5
- package/dist/richtext.js +1 -1
- package/dist/social/external-embeds.d.ts +5 -0
- package/dist/social/external-embeds.js +6 -1
- package/dist/social/posts.d.ts +2 -0
- package/dist/social/posts.js +43 -2
- package/dist/social/profile.js +2 -1
- package/package.json +28 -2
package/dist/editor/document.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import { detectTokens } from '../richtext/detect.js';
|
|
2
|
-
import { paragraphParts, safeWebUrl } from '../richtext/document.js';
|
|
2
|
+
import { isCallout, paragraphParts, safeWebUrl } from '../richtext/document.js';
|
|
3
3
|
export const LINK_EMBED = 'linkEmbed';
|
|
4
|
+
export const IMAGE = 'image';
|
|
5
|
+
export const MATH = 'math';
|
|
6
|
+
export const FOOTNOTE_REFERENCE = 'footnoteReference';
|
|
7
|
+
export const FOOTNOTE_DEFINITION = 'footnoteDefinition';
|
|
4
8
|
const MAX_DEPTH = 32;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
9
|
+
export const HIGHLIGHT = 'highlight';
|
|
10
|
+
const MARKS = {
|
|
11
|
+
strong: 'bold',
|
|
12
|
+
emphasis: 'italic',
|
|
13
|
+
delete: 'strike',
|
|
14
|
+
highlight: HIGHLIGHT
|
|
15
|
+
};
|
|
16
|
+
const STYLES = {
|
|
17
|
+
bold: 'strong',
|
|
18
|
+
italic: 'emphasis',
|
|
19
|
+
strike: 'delete',
|
|
20
|
+
highlight: 'highlight'
|
|
21
|
+
};
|
|
7
22
|
function labelOf(nodes, depth = 0) {
|
|
8
23
|
if (depth > MAX_DEPTH)
|
|
9
24
|
return '';
|
|
10
25
|
return nodes
|
|
11
|
-
.map((node) => node.type === 'text' || node.type === 'code'
|
|
26
|
+
.map((node) => node.type === 'text' || node.type === 'code' || node.type === 'math'
|
|
12
27
|
? node.value
|
|
13
28
|
: node.type === 'break'
|
|
14
29
|
? '\n'
|
|
15
30
|
: node.type === 'mention' || node.type === 'tag'
|
|
16
31
|
? node.text
|
|
17
|
-
:
|
|
32
|
+
: node.type === 'footnoteReference'
|
|
33
|
+
? ''
|
|
34
|
+
: labelOf(node.children, depth + 1))
|
|
18
35
|
.join('');
|
|
19
36
|
}
|
|
20
37
|
/** A URL alone, e.g. the whole text of a line; undefined for anything else. */
|
|
@@ -42,6 +59,12 @@ function inlineContent(nodes, marks, depth = 0) {
|
|
|
42
59
|
return node.value
|
|
43
60
|
? [{ type: 'text', text: node.value.replace(/\n/g, ' '), marks: [{ type: 'code' }] }]
|
|
44
61
|
: [];
|
|
62
|
+
case 'math':
|
|
63
|
+
return node.value
|
|
64
|
+
? [{ type: 'text', text: node.value.replace(/\n/g, ' '), marks: [{ type: MATH }] }]
|
|
65
|
+
: [];
|
|
66
|
+
case 'footnoteReference':
|
|
67
|
+
return [{ type: FOOTNOTE_REFERENCE, attrs: { id: node.id } }];
|
|
45
68
|
case 'mention':
|
|
46
69
|
return node.actor.startsWith('did:')
|
|
47
70
|
? [{ type: 'mention', attrs: { id: node.actor, label: node.text.replace(/^[@@]/, '') } }]
|
|
@@ -60,6 +83,7 @@ function inlineContent(nodes, marks, depth = 0) {
|
|
|
60
83
|
case 'strong':
|
|
61
84
|
case 'emphasis':
|
|
62
85
|
case 'delete':
|
|
86
|
+
case 'highlight':
|
|
63
87
|
return inlineContent(node.children, marks.some((mark) => mark.type === MARKS[node.type])
|
|
64
88
|
? marks
|
|
65
89
|
: [...marks, { type: MARKS[node.type] }], depth + 1);
|
|
@@ -92,24 +116,58 @@ function blockContent(blocks, isEmbed, depth = 0) {
|
|
|
92
116
|
return [
|
|
93
117
|
{
|
|
94
118
|
type: 'blockquote',
|
|
119
|
+
...(isCallout(block.callout) ? { attrs: { callout: block.callout } } : {}),
|
|
120
|
+
content: atLeastOne(blockContent(block.children, isEmbed, depth + 1))
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
case 'math':
|
|
124
|
+
// Edited as a code block in the language "math".
|
|
125
|
+
return [
|
|
126
|
+
{
|
|
127
|
+
type: 'codeBlock',
|
|
128
|
+
attrs: { language: MATH },
|
|
129
|
+
...(block.value ? { content: [{ type: 'text', text: block.value }] } : {})
|
|
130
|
+
}
|
|
131
|
+
];
|
|
132
|
+
case 'footnoteDefinition':
|
|
133
|
+
return [
|
|
134
|
+
{
|
|
135
|
+
type: FOOTNOTE_DEFINITION,
|
|
136
|
+
attrs: { id: block.id },
|
|
95
137
|
content: atLeastOne(blockContent(block.children, isEmbed, depth + 1))
|
|
96
138
|
}
|
|
97
139
|
];
|
|
98
|
-
case 'list':
|
|
140
|
+
case 'list': {
|
|
141
|
+
const checked = block.checked ?? [];
|
|
142
|
+
const isTask = (index) => typeof checked[index] === 'boolean';
|
|
143
|
+
// A task list is a bulleted one whose items are all tasks.
|
|
144
|
+
if (!block.ordered && block.items.length && block.items.every((_, index) => isTask(index)))
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
type: 'taskList',
|
|
148
|
+
content: block.items.map((item, index) => ({
|
|
149
|
+
type: 'taskItem',
|
|
150
|
+
attrs: { checked: checked[index] === true },
|
|
151
|
+
content: startsWithParagraph(blockContent(item, isEmbed, depth + 1))
|
|
152
|
+
}))
|
|
153
|
+
}
|
|
154
|
+
];
|
|
99
155
|
return [
|
|
100
156
|
{
|
|
101
157
|
type: block.ordered ? 'orderedList' : 'bulletList',
|
|
102
158
|
...(block.ordered ? { attrs: { start: block.start ?? 1 } } : {}),
|
|
103
|
-
content: block.items.map((item) => {
|
|
104
|
-
const content = blockContent(item, isEmbed, depth + 1);
|
|
105
|
-
// A
|
|
159
|
+
content: block.items.map((item, index) => {
|
|
160
|
+
const content = startsWithParagraph(blockContent(item, isEmbed, depth + 1));
|
|
161
|
+
// A task among other items, or in a numbered list, keeps its box on the item.
|
|
106
162
|
return {
|
|
107
163
|
type: 'listItem',
|
|
108
|
-
|
|
164
|
+
...(isTask(index) ? { attrs: { checked: checked[index] } } : {}),
|
|
165
|
+
content
|
|
109
166
|
};
|
|
110
167
|
})
|
|
111
168
|
}
|
|
112
169
|
];
|
|
170
|
+
}
|
|
113
171
|
case 'codeBlock':
|
|
114
172
|
return [
|
|
115
173
|
{
|
|
@@ -120,11 +178,41 @@ function blockContent(blocks, isEmbed, depth = 0) {
|
|
|
120
178
|
];
|
|
121
179
|
case 'thematicBreak':
|
|
122
180
|
return [{ type: 'horizontalRule' }];
|
|
181
|
+
case 'image':
|
|
182
|
+
return [
|
|
183
|
+
{
|
|
184
|
+
type: IMAGE,
|
|
185
|
+
attrs: { url: block.url, alt: block.alt ?? '', title: block.title ?? '' }
|
|
186
|
+
}
|
|
187
|
+
];
|
|
188
|
+
case 'table':
|
|
189
|
+
return [
|
|
190
|
+
{
|
|
191
|
+
type: 'table',
|
|
192
|
+
content: block.rows.map((row, rowIndex) => ({
|
|
193
|
+
type: 'tableRow',
|
|
194
|
+
content: row.map((cell, index) => ({
|
|
195
|
+
type: rowIndex ? 'tableCell' : 'tableHeader',
|
|
196
|
+
attrs: { align: block.align[index] ?? null },
|
|
197
|
+
content: [
|
|
198
|
+
{
|
|
199
|
+
type: 'paragraph',
|
|
200
|
+
content: inlineContent(cell, []).map((node) => node.type === 'hardBreak' ? { type: 'text', text: ' ' } : node)
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
}))
|
|
204
|
+
}))
|
|
205
|
+
}
|
|
206
|
+
];
|
|
123
207
|
default:
|
|
124
208
|
return [];
|
|
125
209
|
}
|
|
126
210
|
});
|
|
127
211
|
}
|
|
212
|
+
/** A list item starts with a paragraph. */
|
|
213
|
+
function startsWithParagraph(content) {
|
|
214
|
+
return content[0]?.type === 'paragraph' ? content : [{ type: 'paragraph' }, ...content];
|
|
215
|
+
}
|
|
128
216
|
function atLeastOne(content) {
|
|
129
217
|
return content.length ? content : [{ type: 'paragraph' }];
|
|
130
218
|
}
|
|
@@ -162,9 +250,15 @@ function inlineNodes(content) {
|
|
|
162
250
|
const actor = String(node.attrs?.id ?? '');
|
|
163
251
|
return [{ type: 'mention', actor, text: `@${node.attrs?.label ?? actor}` }];
|
|
164
252
|
}
|
|
253
|
+
if (node.type === FOOTNOTE_REFERENCE) {
|
|
254
|
+
const id = typeof node.attrs?.id === 'string' ? node.attrs.id : '';
|
|
255
|
+
return id ? [{ type: 'footnoteReference', id }] : [];
|
|
256
|
+
}
|
|
165
257
|
if (node.type !== 'text' || !node.text)
|
|
166
258
|
return [];
|
|
167
259
|
const marks = node.marks ?? [];
|
|
260
|
+
if (marks.some((mark) => mark.type === MATH))
|
|
261
|
+
return [{ type: 'math', value: node.text }];
|
|
168
262
|
let inline = marks.some((mark) => mark.type === 'code')
|
|
169
263
|
? { type: 'code', value: node.text }
|
|
170
264
|
: { type: 'text', value: node.text };
|
|
@@ -197,7 +291,13 @@ function blockNodes(content, depth = 0) {
|
|
|
197
291
|
}
|
|
198
292
|
];
|
|
199
293
|
case 'blockquote':
|
|
200
|
-
return [
|
|
294
|
+
return [
|
|
295
|
+
{
|
|
296
|
+
type: 'blockquote',
|
|
297
|
+
children: blockNodes(node.content, depth + 1),
|
|
298
|
+
...(isCallout(node.attrs?.callout) ? { callout: node.attrs.callout } : {})
|
|
299
|
+
}
|
|
300
|
+
];
|
|
201
301
|
case 'bulletList':
|
|
202
302
|
case 'orderedList': {
|
|
203
303
|
const start = Number(node.attrs?.start);
|
|
@@ -208,12 +308,35 @@ function blockNodes(content, depth = 0) {
|
|
|
208
308
|
...(node.type === 'orderedList' && Number.isInteger(start) && start !== 1
|
|
209
309
|
? { start }
|
|
210
310
|
: {}),
|
|
211
|
-
items: (node.content ?? []).map((item) => blockNodes(item.content, depth + 1))
|
|
311
|
+
items: (node.content ?? []).map((item) => blockNodes(item.content, depth + 1)),
|
|
312
|
+
...((node.content ?? []).some((item) => typeof item.attrs?.checked === 'boolean')
|
|
313
|
+
? {
|
|
314
|
+
checked: (node.content ?? []).map((item) => typeof item.attrs?.checked === 'boolean' ? item.attrs.checked : null)
|
|
315
|
+
}
|
|
316
|
+
: {})
|
|
212
317
|
}
|
|
213
318
|
];
|
|
214
319
|
}
|
|
320
|
+
case 'taskList':
|
|
321
|
+
return [
|
|
322
|
+
{
|
|
323
|
+
type: 'list',
|
|
324
|
+
ordered: false,
|
|
325
|
+
items: (node.content ?? []).map((item) => blockNodes(item.content, depth + 1)),
|
|
326
|
+
checked: (node.content ?? []).map((item) => item.attrs?.checked === true)
|
|
327
|
+
}
|
|
328
|
+
];
|
|
329
|
+
case FOOTNOTE_DEFINITION: {
|
|
330
|
+
const id = typeof node.attrs?.id === 'string' ? node.attrs.id : '';
|
|
331
|
+
return id
|
|
332
|
+
? [{ type: 'footnoteDefinition', id, children: blockNodes(node.content, depth + 1) }]
|
|
333
|
+
: [];
|
|
334
|
+
}
|
|
215
335
|
case 'codeBlock': {
|
|
216
336
|
const lang = typeof node.attrs?.language === 'string' ? node.attrs.language : '';
|
|
337
|
+
const value = (node.content ?? []).map((child) => child.text ?? '').join('');
|
|
338
|
+
if (lang === MATH)
|
|
339
|
+
return [{ type: 'math', value }];
|
|
217
340
|
return [
|
|
218
341
|
{
|
|
219
342
|
type: 'codeBlock',
|
|
@@ -224,6 +347,34 @@ function blockNodes(content, depth = 0) {
|
|
|
224
347
|
}
|
|
225
348
|
case 'horizontalRule':
|
|
226
349
|
return [{ type: 'thematicBreak' }];
|
|
350
|
+
case IMAGE: {
|
|
351
|
+
const url = typeof node.attrs?.url === 'string' ? node.attrs.url : '';
|
|
352
|
+
const alt = typeof node.attrs?.alt === 'string' ? node.attrs.alt : '';
|
|
353
|
+
const title = typeof node.attrs?.title === 'string' ? node.attrs.title : '';
|
|
354
|
+
return url
|
|
355
|
+
? [{ type: 'image', url, ...(alt ? { alt } : {}), ...(title ? { title } : {}) }]
|
|
356
|
+
: [];
|
|
357
|
+
}
|
|
358
|
+
case 'table': {
|
|
359
|
+
const rows = (node.content ?? []).map((row) => (row.content ?? []).map((cell) => (cell.content ?? []).flatMap((child, index) => [
|
|
360
|
+
...(index ? [{ type: 'text', value: ' ' }] : []),
|
|
361
|
+
...inlineNodes(child.content)
|
|
362
|
+
])));
|
|
363
|
+
if (!rows.length)
|
|
364
|
+
return [];
|
|
365
|
+
const width = Math.max(1, ...rows.map((row) => row.length));
|
|
366
|
+
const first = node.content?.[0]?.content ?? [];
|
|
367
|
+
return [
|
|
368
|
+
{
|
|
369
|
+
type: 'table',
|
|
370
|
+
align: Array.from({ length: width }, (_, index) => {
|
|
371
|
+
const align = first[index]?.attrs?.align;
|
|
372
|
+
return align === 'left' || align === 'center' || align === 'right' ? align : null;
|
|
373
|
+
}),
|
|
374
|
+
rows: rows.map((row) => Array.from({ length: width }, (_, index) => row[index] ?? []))
|
|
375
|
+
}
|
|
376
|
+
];
|
|
377
|
+
}
|
|
227
378
|
default:
|
|
228
379
|
return [];
|
|
229
380
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
export type ImageNodeOptions = {
|
|
3
|
+
/** The address to load a destination from; undefined when it cannot be shown. */
|
|
4
|
+
src: (url: string) => string | undefined;
|
|
5
|
+
altLabel: string;
|
|
6
|
+
};
|
|
7
|
+
/** An image on its own line, written to Markdown as ``. */
|
|
8
|
+
export declare const ImageNode: Node<ImageNodeOptions, any>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
import { IMAGE } from './document.js';
|
|
3
|
+
/** An image on its own line, written to Markdown as ``. */
|
|
4
|
+
export const ImageNode = Node.create({
|
|
5
|
+
name: IMAGE,
|
|
6
|
+
group: 'block',
|
|
7
|
+
atom: true,
|
|
8
|
+
selectable: true,
|
|
9
|
+
draggable: true,
|
|
10
|
+
addOptions: () => ({ src: () => undefined, altLabel: 'Alt text' }),
|
|
11
|
+
addAttributes: () => ({ url: { default: '' }, alt: { default: '' }, title: { default: '' } }),
|
|
12
|
+
parseHTML: () => [{ tag: 'div[data-image]' }],
|
|
13
|
+
renderHTML: ({ node }) => ['div', { 'data-image': '' }, node.attrs.alt || ''],
|
|
14
|
+
renderText: ({ node }) => node.attrs.alt || '',
|
|
15
|
+
addNodeView() {
|
|
16
|
+
return ({ node, editor, getPos }) => {
|
|
17
|
+
let current = node;
|
|
18
|
+
const dom = document.createElement('div');
|
|
19
|
+
dom.dataset.image = '';
|
|
20
|
+
dom.contentEditable = 'false';
|
|
21
|
+
const img = document.createElement('img');
|
|
22
|
+
img.draggable = false;
|
|
23
|
+
const input = document.createElement('input');
|
|
24
|
+
input.type = 'text';
|
|
25
|
+
input.placeholder = this.options.altLabel;
|
|
26
|
+
input.setAttribute('aria-label', this.options.altLabel);
|
|
27
|
+
dom.append(img, input);
|
|
28
|
+
const show = () => {
|
|
29
|
+
const src = this.options.src(current.attrs.url) ?? '';
|
|
30
|
+
if (img.getAttribute('src') !== src)
|
|
31
|
+
img.setAttribute('src', src);
|
|
32
|
+
img.alt = current.attrs.alt || '';
|
|
33
|
+
if (current.attrs.title)
|
|
34
|
+
img.title = current.attrs.title;
|
|
35
|
+
else
|
|
36
|
+
img.removeAttribute('title');
|
|
37
|
+
if (document.activeElement !== input)
|
|
38
|
+
input.value = current.attrs.alt || '';
|
|
39
|
+
input.readOnly = !editor.isEditable;
|
|
40
|
+
};
|
|
41
|
+
show();
|
|
42
|
+
input.addEventListener('input', () => {
|
|
43
|
+
const pos = getPos();
|
|
44
|
+
if (typeof pos !== 'number' || !editor.isEditable)
|
|
45
|
+
return;
|
|
46
|
+
editor.view.dispatch(editor.state.tr.setNodeMarkup(pos, undefined, { ...current.attrs, alt: input.value }));
|
|
47
|
+
});
|
|
48
|
+
input.addEventListener('keydown', (event) => {
|
|
49
|
+
if (event.key !== 'Enter' && event.key !== 'Escape')
|
|
50
|
+
return;
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
const pos = getPos();
|
|
53
|
+
if (typeof pos === 'number')
|
|
54
|
+
editor
|
|
55
|
+
.chain()
|
|
56
|
+
.focus()
|
|
57
|
+
.setTextSelection(pos + current.nodeSize)
|
|
58
|
+
.run();
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
dom,
|
|
62
|
+
update: (next) => {
|
|
63
|
+
if (next.type !== current.type)
|
|
64
|
+
return false;
|
|
65
|
+
current = next;
|
|
66
|
+
show();
|
|
67
|
+
return true;
|
|
68
|
+
},
|
|
69
|
+
// Typing in the description stays there.
|
|
70
|
+
stopEvent: (event) => event.target === input,
|
|
71
|
+
ignoreMutation: () => true
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
@@ -1,6 +1,2 @@
|
|
|
1
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[];
|
|
2
|
+
export declare function markdownExtensions(article?: boolean): AnyExtension[];
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Extension, InputRule } from '@tiptap/core';
|
|
2
2
|
import StarterKit from '@tiptap/starter-kit';
|
|
3
|
+
import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';
|
|
3
4
|
import { safeHttpUrl } from '../urls.js';
|
|
5
|
+
import { articleExtensions } from './article-extensions.js';
|
|
4
6
|
/** Typing `[label](https://…)` makes a link, like the other Markdown shortcuts. */
|
|
5
7
|
const MarkdownLink = Extension.create({
|
|
6
8
|
name: 'markdownLink',
|
|
@@ -25,10 +27,42 @@ const MarkdownLink = Extension.create({
|
|
|
25
27
|
* The blocks and formatting of the kit's Markdown: headings, lists, quotes, code, rules, bold,
|
|
26
28
|
* italic, strikethrough, inline code and links, with their usual typing shortcuts.
|
|
27
29
|
*/
|
|
28
|
-
|
|
30
|
+
const align = {
|
|
31
|
+
align: {
|
|
32
|
+
default: null,
|
|
33
|
+
parseHTML: (element) => element.style.textAlign || null,
|
|
34
|
+
renderHTML: (attributes) => attributes.align ? { style: `text-align: ${attributes.align}` } : {}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** Tables as Markdown has them: one line of text per cell, no merged or resized cells. */
|
|
38
|
+
function tableExtensions() {
|
|
39
|
+
return [
|
|
40
|
+
Table.configure({ resizable: false, allowTableNodeSelection: true }),
|
|
41
|
+
TableRow,
|
|
42
|
+
// The inherited colspan, rowspan and colwidth stay: the table map is built from them.
|
|
43
|
+
TableHeader.extend({
|
|
44
|
+
content: 'paragraph',
|
|
45
|
+
addAttributes() {
|
|
46
|
+
return { ...this.parent?.(), ...align };
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
TableCell.extend({
|
|
50
|
+
content: 'paragraph',
|
|
51
|
+
addAttributes() {
|
|
52
|
+
return { ...this.parent?.(), ...align };
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
export function markdownExtensions(article = false) {
|
|
29
58
|
return [
|
|
30
59
|
StarterKit.configure({
|
|
31
60
|
underline: false,
|
|
61
|
+
// Article Markdown brings a list item that can carry a task's box, and its own quote
|
|
62
|
+
// and code block.
|
|
63
|
+
...(article
|
|
64
|
+
? { listItem: false, blockquote: false, codeBlock: false }
|
|
65
|
+
: {}),
|
|
32
66
|
link: {
|
|
33
67
|
openOnClick: false,
|
|
34
68
|
autolink: false,
|
|
@@ -37,6 +71,7 @@ export function markdownExtensions() {
|
|
|
37
71
|
HTMLAttributes: { rel: 'noopener noreferrer nofollow ugc', target: '_blank' }
|
|
38
72
|
}
|
|
39
73
|
}),
|
|
40
|
-
MarkdownLink
|
|
74
|
+
MarkdownLink,
|
|
75
|
+
...(article ? [...tableExtensions(), ...articleExtensions()] : [])
|
|
41
76
|
];
|
|
42
77
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { type ArticleCommandContext } from './article-commands.js';
|
|
3
|
+
export type SlashMenuOptions = {
|
|
4
|
+
/** The element the menu is put in; positioned ancestors place it. */
|
|
5
|
+
layer: HTMLElement;
|
|
6
|
+
context: ArticleCommandContext;
|
|
7
|
+
};
|
|
8
|
+
/** Typing `/` lists the blocks and insertions; typing on filters them. */
|
|
9
|
+
export declare function slashMenu(options: SlashMenuOptions): Extension<any, any>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { PluginKey } from '@tiptap/pm/state';
|
|
3
|
+
import { flip, shift } from '@floating-ui/dom';
|
|
4
|
+
import Suggestion, {} from '@tiptap/suggestion';
|
|
5
|
+
import { mount, unmount } from 'svelte';
|
|
6
|
+
import { findCommands, runCommand } from './article-commands.js';
|
|
7
|
+
import SlashOptions from './SlashOptions.svelte';
|
|
8
|
+
/** Typing `/` lists the blocks and insertions; typing on filters them. */
|
|
9
|
+
export function slashMenu(options) {
|
|
10
|
+
return Extension.create({
|
|
11
|
+
name: 'slashMenu',
|
|
12
|
+
addProseMirrorPlugins() {
|
|
13
|
+
const editor = this.editor;
|
|
14
|
+
return [
|
|
15
|
+
Suggestion({
|
|
16
|
+
editor,
|
|
17
|
+
pluginKey: new PluginKey('atmoSlashMenu'),
|
|
18
|
+
char: '/',
|
|
19
|
+
allowSpaces: true,
|
|
20
|
+
container: options.layer,
|
|
21
|
+
offset: { mainAxis: 8 },
|
|
22
|
+
// On a touch screen the toolbar lies along the bottom.
|
|
23
|
+
flip: false,
|
|
24
|
+
floatingUi: {
|
|
25
|
+
middleware: [
|
|
26
|
+
flip({
|
|
27
|
+
padding: {
|
|
28
|
+
top: 8,
|
|
29
|
+
bottom: window.matchMedia('(pointer: coarse)').matches ? 64 : 8
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
shift({ padding: 8 })
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
// Not in code, where a slash is a slash.
|
|
36
|
+
allow: ({ state, range }) => {
|
|
37
|
+
const parent = state.doc.resolve(range.from).parent;
|
|
38
|
+
return editor.isEditable && parent.isTextblock && !parent.type.spec.code;
|
|
39
|
+
},
|
|
40
|
+
items: ({ query }) => findCommands(query, editor, options.context),
|
|
41
|
+
command: ({ range, props }) => {
|
|
42
|
+
editor.chain().focus().deleteRange(range).run();
|
|
43
|
+
runCommand(editor, props, options.context);
|
|
44
|
+
},
|
|
45
|
+
render: () => {
|
|
46
|
+
let menu;
|
|
47
|
+
let rows;
|
|
48
|
+
let release;
|
|
49
|
+
let current;
|
|
50
|
+
const state = $state({
|
|
51
|
+
id: '',
|
|
52
|
+
items: [],
|
|
53
|
+
selected: 0,
|
|
54
|
+
choose: (index) => {
|
|
55
|
+
const item = current.items[index];
|
|
56
|
+
if (item)
|
|
57
|
+
current.command(item);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const dom = () => current.editor.view.dom;
|
|
61
|
+
const close = () => {
|
|
62
|
+
release?.();
|
|
63
|
+
release = undefined;
|
|
64
|
+
if (rows)
|
|
65
|
+
void unmount(rows);
|
|
66
|
+
rows = undefined;
|
|
67
|
+
menu?.remove();
|
|
68
|
+
menu = undefined;
|
|
69
|
+
dom().removeAttribute('aria-controls');
|
|
70
|
+
dom().removeAttribute('aria-activedescendant');
|
|
71
|
+
};
|
|
72
|
+
const draw = () => {
|
|
73
|
+
if (!menu)
|
|
74
|
+
return;
|
|
75
|
+
state.items = current.items;
|
|
76
|
+
// Nothing matches: stay out of the way instead of saying so.
|
|
77
|
+
menu.hidden = !current.items.length;
|
|
78
|
+
if (menu.hidden) {
|
|
79
|
+
dom().removeAttribute('aria-controls');
|
|
80
|
+
dom().removeAttribute('aria-activedescendant');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
dom().setAttribute('aria-controls', menu.id);
|
|
84
|
+
dom().setAttribute('aria-activedescendant', `${menu.id}-${state.selected}`);
|
|
85
|
+
};
|
|
86
|
+
const open = (props) => {
|
|
87
|
+
current = props;
|
|
88
|
+
state.selected = 0;
|
|
89
|
+
if (!menu) {
|
|
90
|
+
const element = document.createElement('div');
|
|
91
|
+
element.id = `${dom().id}-commands`;
|
|
92
|
+
element.role = 'listbox';
|
|
93
|
+
element.setAttribute('aria-label', 'Commands');
|
|
94
|
+
element.className =
|
|
95
|
+
'absolute top-0 left-0 z-60 max-h-80 w-64 max-w-[calc(100vw-1rem)] overflow-y-auto overscroll-contain rounded-ui border border-base-300 bg-base-50 p-1.5 font-sans text-sm leading-normal text-base-950 transition-opacity duration-100 motion-reduce:transition-none dark:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] dark:bg-base-900 dark:text-base-50 starting:opacity-0';
|
|
96
|
+
state.id = element.id;
|
|
97
|
+
menu = element;
|
|
98
|
+
rows = mount(SlashOptions, { target: element, props: { state } });
|
|
99
|
+
release = props.mount(element, {
|
|
100
|
+
onPosition: ({ x, y }) => {
|
|
101
|
+
element.style.left = `${x}px`;
|
|
102
|
+
element.style.top = `${y}px`;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
draw();
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
onStart: open,
|
|
110
|
+
onUpdate: open,
|
|
111
|
+
onKeyDown: ({ event }) => {
|
|
112
|
+
if (!menu || menu.hidden || event.isComposing)
|
|
113
|
+
return false;
|
|
114
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
115
|
+
state.selected =
|
|
116
|
+
(state.selected + (event.key === 'ArrowDown' ? 1 : -1) + current.items.length) %
|
|
117
|
+
current.items.length;
|
|
118
|
+
draw();
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (event.key === 'Enter' || event.key === 'Tab') {
|
|
122
|
+
state.choose(state.selected);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
},
|
|
127
|
+
onExit: close
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import ExternalEmbed from '../components/ExternalEmbed.svelte';
|
|
3
3
|
import type { ExternalEmbedProvider } from '../social/external-embeds.js';
|
|
4
|
+
import { linkEmbedOptions } from './context.js';
|
|
4
5
|
import type { LinkEmbedProps } from './types.js';
|
|
5
6
|
|
|
6
7
|
let { url, ref }: LinkEmbedProps<{ provider: ExternalEmbedProvider }> = $props();
|
|
8
|
+
// A bare link has no thumbnail of its own. The provider's is used unless the app asked that
|
|
9
|
+
// nothing load before a click.
|
|
10
|
+
const options = linkEmbedOptions();
|
|
7
11
|
</script>
|
|
8
12
|
|
|
9
|
-
<ExternalEmbed
|
|
13
|
+
<ExternalEmbed
|
|
14
|
+
embed={{ type: 'external', uri: url, title: '' }}
|
|
15
|
+
providers={[ref.provider]}
|
|
16
|
+
providerPoster={!options().clickToLoad}
|
|
17
|
+
/>
|
|
@@ -2,53 +2,36 @@
|
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import NestedComments from '../components/NestedComments.svelte';
|
|
4
4
|
import Surface from '../components/Surface.svelte';
|
|
5
|
-
import {
|
|
6
|
-
blueskyPostToPostData,
|
|
7
|
-
hasModerationLabel,
|
|
8
|
-
type BlueskyPostView,
|
|
9
|
-
type PostData
|
|
10
|
-
} from '../social/posts.js';
|
|
5
|
+
import type { PostData } from '../social/posts.js';
|
|
11
6
|
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
12
7
|
import { parseSocialPostUrl, socialPostUrl } from '../social/urls.js';
|
|
13
8
|
import { safeHttpUrl } from '../urls.js';
|
|
14
|
-
import {
|
|
9
|
+
import { loadPostEmbed } from './load.js';
|
|
15
10
|
|
|
16
11
|
let {
|
|
17
12
|
url,
|
|
13
|
+
data,
|
|
18
14
|
fallback,
|
|
19
15
|
socialClient
|
|
20
16
|
}: {
|
|
21
17
|
url: string;
|
|
18
|
+
/** The post, when it was loaded ahead; `null` when there is none to show. */
|
|
19
|
+
data?: PostData | null;
|
|
22
20
|
/** The ordinary link, shown until the post loads and whenever it can't be shown. */
|
|
23
21
|
fallback: Snippet;
|
|
24
22
|
socialClient?: PreferredSocialClient | null;
|
|
25
23
|
} = $props();
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let post = $state<PostData | null>(null);
|
|
25
|
+
let found = $state<{ url: string; post: PostData | null }>();
|
|
26
|
+
let post = $derived(data !== undefined ? data : found?.url === url ? found.post : null);
|
|
31
27
|
$effect(() => {
|
|
32
|
-
const ref = parseSocialPostUrl(url);
|
|
33
|
-
post = null;
|
|
28
|
+
const ref = data === undefined ? parseSocialPostUrl(url) : null;
|
|
34
29
|
if (!ref) return;
|
|
30
|
+
const link = url;
|
|
35
31
|
const controller = new AbortController();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
.then((response) => (response.ok ? response.json() : null))
|
|
41
|
-
.then((data: { thread?: { $type?: string; post?: ThreadPost } } | null) => {
|
|
42
|
-
const view = data?.thread?.post;
|
|
43
|
-
if (
|
|
44
|
-
controller.signal.aborted ||
|
|
45
|
-
data?.thread?.$type !== 'app.bsky.feed.defs#threadViewPost' ||
|
|
46
|
-
!view?.uri ||
|
|
47
|
-
!view.author?.did ||
|
|
48
|
-
hasModerationLabel(view)
|
|
49
|
-
)
|
|
50
|
-
return;
|
|
51
|
-
post = blueskyPostToPostData(view);
|
|
32
|
+
loadPostEmbed(ref, { signal: controller.signal })
|
|
33
|
+
.then((loaded) => {
|
|
34
|
+
if (!controller.signal.aborted) found = { url: link, post: loaded };
|
|
52
35
|
})
|
|
53
36
|
.catch(() => {});
|
|
54
37
|
return () => controller.abort();
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { PostData } from '../social/posts.js';
|
|
2
3
|
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
3
4
|
type $$ComponentProps = {
|
|
4
5
|
url: string;
|
|
6
|
+
/** The post, when it was loaded ahead; `null` when there is none to show. */
|
|
7
|
+
data?: PostData | null;
|
|
5
8
|
/** The ordinary link, shown until the post loads and whenever it can't be shown. */
|
|
6
9
|
fallback: Snippet;
|
|
7
10
|
socialClient?: PreferredSocialClient | null;
|