@atmo-dev/kit 0.18.1 → 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 +10 -0
- package/dist/components/composer/ComposerPost.svelte.d.ts +3 -1
- package/dist/components/composer/PostComposer.svelte +28 -2
- 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
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../utils.js';
|
|
4
|
+
import { formatArticleDate } from './dates.js';
|
|
5
|
+
import type { ArticleSummary } from './records.js';
|
|
6
|
+
|
|
7
|
+
// An article in a list or grid: its cover, title, description and date. Stacked, it is as
|
|
8
|
+
// wide as its container, so that decides how large the cover is. As a row, the cover is a
|
|
9
|
+
// thumbnail beside the text.
|
|
10
|
+
let {
|
|
11
|
+
article,
|
|
12
|
+
href,
|
|
13
|
+
cover,
|
|
14
|
+
external = false,
|
|
15
|
+
layout = 'stack',
|
|
16
|
+
site = true,
|
|
17
|
+
byline,
|
|
18
|
+
class: className
|
|
19
|
+
}: {
|
|
20
|
+
article: Pick<ArticleSummary, 'title' | 'description' | 'publishedAt'>;
|
|
21
|
+
href: string;
|
|
22
|
+
/** Address of the cover image. */
|
|
23
|
+
cover?: string;
|
|
24
|
+
/** The article is read on another site: opens in a new tab and names that site. */
|
|
25
|
+
external?: boolean;
|
|
26
|
+
/** `row` puts a small cover beside the text, for a list down the page. */
|
|
27
|
+
layout?: 'stack' | 'row';
|
|
28
|
+
/** Name the site of an external article. Off where the list already says it. */
|
|
29
|
+
site?: boolean;
|
|
30
|
+
/** After the date: an author or publication. */
|
|
31
|
+
byline?: Snippet;
|
|
32
|
+
class?: string;
|
|
33
|
+
} = $props();
|
|
34
|
+
|
|
35
|
+
let row = $derived(layout === 'row');
|
|
36
|
+
let host = $derived.by(() => {
|
|
37
|
+
if (!external) return '';
|
|
38
|
+
try {
|
|
39
|
+
return new URL(href).hostname.replace(/^www\./, '');
|
|
40
|
+
} catch {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<a
|
|
47
|
+
{href}
|
|
48
|
+
target={external ? '_blank' : undefined}
|
|
49
|
+
rel={external ? 'noopener noreferrer' : undefined}
|
|
50
|
+
class={cn('group rounded-sm', row ? 'flex items-start gap-5 sm:gap-8' : 'block', className)}
|
|
51
|
+
>
|
|
52
|
+
{#if cover && !row}
|
|
53
|
+
<img
|
|
54
|
+
src={cover}
|
|
55
|
+
alt=""
|
|
56
|
+
loading="lazy"
|
|
57
|
+
class="mb-3 aspect-[16/9] w-full rounded-lg bg-base-200 object-cover dark:bg-base-800"
|
|
58
|
+
/>
|
|
59
|
+
{/if}
|
|
60
|
+
<span class="block min-w-0 flex-1">
|
|
61
|
+
<span
|
|
62
|
+
class={[
|
|
63
|
+
'block leading-snug font-semibold text-base-950 group-hover:text-accent-700 dark:text-base-50 dark:group-hover:text-accent-300',
|
|
64
|
+
row ? 'text-xl tracking-tight text-balance' : 'text-lg'
|
|
65
|
+
]}
|
|
66
|
+
>
|
|
67
|
+
{article.title}
|
|
68
|
+
</span>
|
|
69
|
+
{#if article.description}
|
|
70
|
+
<span
|
|
71
|
+
class={[
|
|
72
|
+
'line-clamp-2 text-base font-normal text-base-600 dark:text-base-400',
|
|
73
|
+
row ? 'mt-1.5' : 'mt-1'
|
|
74
|
+
]}>{article.description}</span
|
|
75
|
+
>
|
|
76
|
+
{/if}
|
|
77
|
+
<span
|
|
78
|
+
class={[
|
|
79
|
+
'flex flex-wrap items-center gap-x-1.5 text-sm font-normal text-base-500',
|
|
80
|
+
row ? 'mt-3' : 'mt-2'
|
|
81
|
+
]}
|
|
82
|
+
>
|
|
83
|
+
<time datetime={article.publishedAt}>{formatArticleDate(article.publishedAt)}</time>
|
|
84
|
+
{#if byline}<span aria-hidden="true">·</span>{@render byline()}{/if}
|
|
85
|
+
{#if host && site}<span aria-hidden="true">·</span><span>{host} ↗</span>
|
|
86
|
+
{:else if external}<span aria-hidden="true">↗</span>{/if}
|
|
87
|
+
</span>
|
|
88
|
+
</span>
|
|
89
|
+
{#if cover && row}
|
|
90
|
+
<img
|
|
91
|
+
src={cover}
|
|
92
|
+
alt=""
|
|
93
|
+
loading="lazy"
|
|
94
|
+
class="aspect-[4/3] w-24 shrink-0 rounded-lg bg-base-200 object-cover sm:aspect-[3/2] sm:w-44 dark:bg-base-800"
|
|
95
|
+
/>
|
|
96
|
+
{/if}
|
|
97
|
+
</a>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ArticleSummary } from './records.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
article: Pick<ArticleSummary, 'title' | 'description' | 'publishedAt'>;
|
|
5
|
+
href: string;
|
|
6
|
+
/** Address of the cover image. */
|
|
7
|
+
cover?: string;
|
|
8
|
+
/** The article is read on another site: opens in a new tab and names that site. */
|
|
9
|
+
external?: boolean;
|
|
10
|
+
/** `row` puts a small cover beside the text, for a list down the page. */
|
|
11
|
+
layout?: 'stack' | 'row';
|
|
12
|
+
/** Name the site of an external article. Off where the list already says it. */
|
|
13
|
+
site?: boolean;
|
|
14
|
+
/** After the date: an author or publication. */
|
|
15
|
+
byline?: Snippet;
|
|
16
|
+
class?: string;
|
|
17
|
+
};
|
|
18
|
+
declare const ArticleCard: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
19
|
+
type ArticleCard = ReturnType<typeof ArticleCard>;
|
|
20
|
+
export default ArticleCard;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Check, Copy } from '@sketchyicons/svelte';
|
|
3
|
+
import Icon from '../components/Icon.svelte';
|
|
4
|
+
import IconButton from '../components/IconButton.svelte';
|
|
5
|
+
|
|
6
|
+
// A code block with a copy button. Highlighting is the app's: pass its markup as `html`.
|
|
7
|
+
let {
|
|
8
|
+
value,
|
|
9
|
+
html
|
|
10
|
+
}: {
|
|
11
|
+
value: string;
|
|
12
|
+
/**
|
|
13
|
+
* Highlighted markup of `value`, inserted as is. Only pass a highlighter's output, which
|
|
14
|
+
* escapes the code: highlight.js class names (`hljs-keyword`, …) are styled here.
|
|
15
|
+
*/
|
|
16
|
+
html?: string;
|
|
17
|
+
} = $props();
|
|
18
|
+
let copied = $state(false);
|
|
19
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
20
|
+
|
|
21
|
+
async function copy() {
|
|
22
|
+
try {
|
|
23
|
+
await navigator.clipboard.writeText(value);
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
copied = true;
|
|
28
|
+
clearTimeout(timer);
|
|
29
|
+
timer = setTimeout(() => (copied = false), 1500);
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
{#snippet code()}
|
|
34
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- app-rendered highlighter output -->
|
|
35
|
+
{#if html}{@html html}{:else}{value}{/if}
|
|
36
|
+
{/snippet}
|
|
37
|
+
|
|
38
|
+
<div class="group relative">
|
|
39
|
+
<!-- prettier-ignore -->
|
|
40
|
+
<pre
|
|
41
|
+
class="overflow-x-auto rounded-lg bg-base-100 p-4 font-mono text-sm leading-relaxed dark:bg-base-950"><code class="article-code">{@render code()}</code></pre>
|
|
42
|
+
<IconButton
|
|
43
|
+
label={copied ? 'Copied' : 'Copy code'}
|
|
44
|
+
variant="ghost"
|
|
45
|
+
onclick={copy}
|
|
46
|
+
class="absolute top-1.5 right-1.5 size-8 bg-base-100 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 dark:bg-base-950 pointer-coarse:opacity-100"
|
|
47
|
+
>
|
|
48
|
+
<Icon img={copied ? Check : Copy} size={16} />
|
|
49
|
+
</IconButton>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<style>
|
|
53
|
+
/* GitHub's light and dark themes, on the neutral background. */
|
|
54
|
+
.article-code
|
|
55
|
+
:global(
|
|
56
|
+
:is(
|
|
57
|
+
.hljs-keyword,
|
|
58
|
+
.hljs-doctag,
|
|
59
|
+
.hljs-meta .hljs-keyword,
|
|
60
|
+
.hljs-template-tag,
|
|
61
|
+
.hljs-template-variable,
|
|
62
|
+
.hljs-type,
|
|
63
|
+
.hljs-variable.language_
|
|
64
|
+
)
|
|
65
|
+
) {
|
|
66
|
+
color: light-dark(#d73a49, #ff7b72);
|
|
67
|
+
}
|
|
68
|
+
.article-code :global(:is(.hljs-title, .hljs-title.class_, .hljs-title.function_)) {
|
|
69
|
+
color: light-dark(#6f42c1, #d2a8ff);
|
|
70
|
+
}
|
|
71
|
+
.article-code
|
|
72
|
+
:global(
|
|
73
|
+
:is(
|
|
74
|
+
.hljs-attr,
|
|
75
|
+
.hljs-attribute,
|
|
76
|
+
.hljs-literal,
|
|
77
|
+
.hljs-meta,
|
|
78
|
+
.hljs-number,
|
|
79
|
+
.hljs-operator,
|
|
80
|
+
.hljs-variable,
|
|
81
|
+
.hljs-selector-attr,
|
|
82
|
+
.hljs-selector-class,
|
|
83
|
+
.hljs-selector-id
|
|
84
|
+
)
|
|
85
|
+
) {
|
|
86
|
+
color: light-dark(#005cc5, #79c0ff);
|
|
87
|
+
}
|
|
88
|
+
.article-code :global(:is(.hljs-regexp, .hljs-string, .hljs-meta .hljs-string)) {
|
|
89
|
+
color: light-dark(#032f62, #a5d6ff);
|
|
90
|
+
}
|
|
91
|
+
.article-code :global(:is(.hljs-built_in, .hljs-symbol)) {
|
|
92
|
+
color: light-dark(#e36209, #ffa657);
|
|
93
|
+
}
|
|
94
|
+
.article-code :global(:is(.hljs-comment, .hljs-code, .hljs-formula)) {
|
|
95
|
+
color: light-dark(#6a737d, #8b949e);
|
|
96
|
+
}
|
|
97
|
+
.article-code :global(:is(.hljs-name, .hljs-quote, .hljs-selector-tag, .hljs-selector-pseudo)) {
|
|
98
|
+
color: light-dark(#22863a, #7ee787);
|
|
99
|
+
}
|
|
100
|
+
.article-code :global(.hljs-section) {
|
|
101
|
+
color: light-dark(#005cc5, #1f6feb);
|
|
102
|
+
font-weight: 600;
|
|
103
|
+
}
|
|
104
|
+
.article-code :global(.hljs-bullet) {
|
|
105
|
+
color: light-dark(#735c0f, #f2cc60);
|
|
106
|
+
}
|
|
107
|
+
.article-code :global(.hljs-emphasis) {
|
|
108
|
+
font-style: italic;
|
|
109
|
+
}
|
|
110
|
+
.article-code :global(.hljs-strong) {
|
|
111
|
+
font-weight: 600;
|
|
112
|
+
}
|
|
113
|
+
.article-code :global(.hljs-addition) {
|
|
114
|
+
color: light-dark(#22863a, #aff5b4);
|
|
115
|
+
background-color: light-dark(#f0fff4, #033a16);
|
|
116
|
+
}
|
|
117
|
+
.article-code :global(.hljs-deletion) {
|
|
118
|
+
color: light-dark(#b31d28, #ffdcd7);
|
|
119
|
+
background-color: light-dark(#ffeef0, #67060c);
|
|
120
|
+
}
|
|
121
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
value: string;
|
|
3
|
+
/**
|
|
4
|
+
* Highlighted markup of `value`, inserted as is. Only pass a highlighter's output, which
|
|
5
|
+
* escapes the code: highlight.js class names (`hljs-keyword`, …) are styled here.
|
|
6
|
+
*/
|
|
7
|
+
html?: string;
|
|
8
|
+
};
|
|
9
|
+
declare const ArticleCodeBlock: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
|
+
type ArticleCodeBlock = ReturnType<typeof ArticleCodeBlock>;
|
|
11
|
+
export default ArticleCodeBlock;
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { Editor } from '@tiptap/core';
|
|
4
|
+
import type { ActorSearch } from '../components/login/types.js';
|
|
5
|
+
import type { LinkEmbed } from '../embeds/types.js';
|
|
6
|
+
|
|
7
|
+
/** How the images of an article being written are stored and loaded. */
|
|
8
|
+
export type ArticleEditorImages = {
|
|
9
|
+
/**
|
|
10
|
+
* Store a pasted, dropped or picked file and return the destination to write: a URL, or
|
|
11
|
+
* the app's own reference such as `local:1`. `kind` tells a cover from an image in the
|
|
12
|
+
* text. Throw an `Error` to show its message.
|
|
13
|
+
*/
|
|
14
|
+
upload: (file: File, kind: 'image' | 'cover') => Promise<string>;
|
|
15
|
+
/** The address to load a destination from, for those that are not HTTP(S). */
|
|
16
|
+
src?: (url: string) => string | undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ArticleEditorProps = {
|
|
20
|
+
title?: string;
|
|
21
|
+
/** Empty for the automatic one. */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** Article Markdown. */
|
|
24
|
+
text?: string;
|
|
25
|
+
/** Destination of the cover image, as `images.upload` returned it. */
|
|
26
|
+
cover?: string;
|
|
27
|
+
/** Without it, images and a cover cannot be added. */
|
|
28
|
+
images?: ArticleEditorImages;
|
|
29
|
+
/** After any edit by the author. */
|
|
30
|
+
onchange?: () => void;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
/** Bare links on their own line as embeds: the app's, a list, or none. */
|
|
33
|
+
embeds?: boolean | readonly LinkEmbed[];
|
|
34
|
+
/** Enables @-mention suggestions. */
|
|
35
|
+
searchActors?: ActorSearch;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
/** A short note in the toolbar, such as "Saved in this browser". */
|
|
38
|
+
status?: string;
|
|
39
|
+
/** Shown under the toolbar. */
|
|
40
|
+
error?: string;
|
|
41
|
+
/** Start of the toolbar, e.g. which publication the article goes into. */
|
|
42
|
+
leading?: Snippet;
|
|
43
|
+
/** End of the toolbar, e.g. Publish. */
|
|
44
|
+
actions?: Snippet;
|
|
45
|
+
class?: string;
|
|
46
|
+
};
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<script lang="ts">
|
|
50
|
+
import { ImagePlus } from '@sketchyicons/svelte';
|
|
51
|
+
import Button from '../components/Button.svelte';
|
|
52
|
+
import Icon from '../components/Icon.svelte';
|
|
53
|
+
import IconButton from '../components/IconButton.svelte';
|
|
54
|
+
import RichTextEditor from '../components/RichTextEditor.svelte';
|
|
55
|
+
import { safeHttpUrl } from '../urls.js';
|
|
56
|
+
import { cn } from '../utils.js';
|
|
57
|
+
import { readPastedArticle } from './paste.js';
|
|
58
|
+
import { ARTICLE_LIMITS } from './records.js';
|
|
59
|
+
import { articleEditorClass } from './styles.js';
|
|
60
|
+
|
|
61
|
+
// The writing surface of an article: cover, title, description and the text. Saving,
|
|
62
|
+
// drafts and publishing are the app's.
|
|
63
|
+
let {
|
|
64
|
+
title = $bindable(''),
|
|
65
|
+
description = $bindable(''),
|
|
66
|
+
text = $bindable(''),
|
|
67
|
+
cover = $bindable(),
|
|
68
|
+
images,
|
|
69
|
+
onchange,
|
|
70
|
+
placeholder = 'Start typing.',
|
|
71
|
+
embeds = true,
|
|
72
|
+
searchActors,
|
|
73
|
+
disabled = false,
|
|
74
|
+
status = '',
|
|
75
|
+
error = '',
|
|
76
|
+
leading,
|
|
77
|
+
actions,
|
|
78
|
+
class: className
|
|
79
|
+
}: ArticleEditorProps = $props();
|
|
80
|
+
|
|
81
|
+
let problem = $state('');
|
|
82
|
+
let editor = $state<ReturnType<typeof RichTextEditor>>();
|
|
83
|
+
let body = $state<Editor | null>(null);
|
|
84
|
+
let picker = $state<HTMLInputElement>();
|
|
85
|
+
let coverPicker = $state<HTMLInputElement>();
|
|
86
|
+
let titleField = $state<HTMLTextAreaElement>();
|
|
87
|
+
let descriptionField = $state<HTMLTextAreaElement>();
|
|
88
|
+
let host = $state<HTMLElement>();
|
|
89
|
+
|
|
90
|
+
const src = (url: string) => safeHttpUrl(url) ?? images?.src?.(url);
|
|
91
|
+
const failed = (reason: unknown) =>
|
|
92
|
+
(problem = reason instanceof Error ? reason.message : 'Could not add this image.');
|
|
93
|
+
function changed() {
|
|
94
|
+
problem = '';
|
|
95
|
+
onchange?.();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function upload(file: File): Promise<string> {
|
|
99
|
+
try {
|
|
100
|
+
return await images!.upload(file, 'image');
|
|
101
|
+
} catch (reason) {
|
|
102
|
+
failed(reason);
|
|
103
|
+
throw reason;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function pickCover() {
|
|
107
|
+
const file = coverPicker?.files?.[0];
|
|
108
|
+
if (coverPicker) coverPicker.value = '';
|
|
109
|
+
if (!file || !images) return;
|
|
110
|
+
problem = '';
|
|
111
|
+
try {
|
|
112
|
+
cover = await images.upload(file, 'cover');
|
|
113
|
+
onchange?.();
|
|
114
|
+
} catch (reason) {
|
|
115
|
+
failed(reason);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Add image files to the text, at the cursor. */
|
|
120
|
+
export function insertImages(files: File[]) {
|
|
121
|
+
return editor?.insertImages(files);
|
|
122
|
+
}
|
|
123
|
+
/** Put the cursor in the title. */
|
|
124
|
+
export function focusTitle() {
|
|
125
|
+
titleField?.focus();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function fit(field: HTMLTextAreaElement | undefined) {
|
|
129
|
+
if (!field) return;
|
|
130
|
+
field.style.height = 'auto';
|
|
131
|
+
field.style.height = `${field.scrollHeight}px`;
|
|
132
|
+
}
|
|
133
|
+
$effect(() => {
|
|
134
|
+
void title;
|
|
135
|
+
fit(titleField);
|
|
136
|
+
});
|
|
137
|
+
$effect(() => {
|
|
138
|
+
void description;
|
|
139
|
+
fit(descriptionField);
|
|
140
|
+
});
|
|
141
|
+
const focusBody = () => {
|
|
142
|
+
if (body) body.commands.focus('start');
|
|
143
|
+
else host?.querySelector<HTMLElement>('[role="textbox"], [role="combobox"]')?.focus();
|
|
144
|
+
};
|
|
145
|
+
function focusEnd(field: HTMLTextAreaElement | undefined) {
|
|
146
|
+
field?.focus();
|
|
147
|
+
field?.setSelectionRange(field.value.length, field.value.length);
|
|
148
|
+
}
|
|
149
|
+
/** Title, description and text are written as one page: Enter and the arrows move on. */
|
|
150
|
+
function move(event: KeyboardEvent, down: () => void, up?: () => void) {
|
|
151
|
+
const field = event.currentTarget as HTMLTextAreaElement;
|
|
152
|
+
if (event.isComposing || event.shiftKey || event.altKey || event.metaKey || event.ctrlKey)
|
|
153
|
+
return;
|
|
154
|
+
const collapsed = field.selectionStart === field.selectionEnd;
|
|
155
|
+
const forward =
|
|
156
|
+
event.key === 'Enter' ||
|
|
157
|
+
(event.key === 'ArrowDown' && collapsed && field.selectionEnd === field.value.length);
|
|
158
|
+
const back = !!up && event.key === 'ArrowUp' && collapsed && field.selectionStart === 0;
|
|
159
|
+
if (!forward && !back) return;
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
(forward ? down : up!)();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* From the very start of the text, up and Backspace on an empty line lead back. An open menu
|
|
165
|
+
* keeps the keys: it names its chosen row on the editor.
|
|
166
|
+
*/
|
|
167
|
+
function leaveBody(event: KeyboardEvent) {
|
|
168
|
+
if (!body || event.isComposing || event.shiftKey || event.altKey) return;
|
|
169
|
+
if (event.key !== 'ArrowUp' && event.key !== 'Backspace') return;
|
|
170
|
+
if (!(event.target instanceof Node) || !body.view.dom.contains(event.target)) return;
|
|
171
|
+
if (body.view.dom.hasAttribute('aria-activedescendant')) return;
|
|
172
|
+
// Read from the page: after a quick arrow key the editor has not caught up yet.
|
|
173
|
+
const selection = window.getSelection();
|
|
174
|
+
if (!selection?.isCollapsed || !selection.anchorNode) return;
|
|
175
|
+
if (!body.view.dom.contains(selection.anchorNode)) return;
|
|
176
|
+
let from;
|
|
177
|
+
try {
|
|
178
|
+
from = body.state.doc.resolve(
|
|
179
|
+
body.view.posAtDOM(selection.anchorNode, selection.anchorOffset)
|
|
180
|
+
);
|
|
181
|
+
} catch {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const first = body.state.doc.firstChild;
|
|
185
|
+
if (from.depth !== 1 || from.index(0) !== 0 || from.parentOffset !== 0) return;
|
|
186
|
+
if (first?.type.name !== 'paragraph') return;
|
|
187
|
+
if (event.key === 'Backspace' && first.content.size) return;
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
focusEnd(descriptionField);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// A pasted file brings its title along; the editor gets the text.
|
|
193
|
+
let forwarding = false;
|
|
194
|
+
function pasted(event: ClipboardEvent) {
|
|
195
|
+
const data = event.clipboardData;
|
|
196
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
197
|
+
const source = data?.getData('text/plain');
|
|
198
|
+
if (forwarding || !source || data?.files.length || !target || target.closest('input')) return;
|
|
199
|
+
const read = readPastedArticle(source, !!title.trim());
|
|
200
|
+
if (read.text === source.replace(/\r\n?/g, '\n')) return;
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
event.stopPropagation();
|
|
203
|
+
if (read.title) title = read.title.slice(0, ARTICLE_LIMITS.title);
|
|
204
|
+
const forwarded = new DataTransfer();
|
|
205
|
+
forwarded.setData('text/plain', read.text);
|
|
206
|
+
forwarding = true;
|
|
207
|
+
try {
|
|
208
|
+
target.dispatchEvent(
|
|
209
|
+
new ClipboardEvent('paste', { clipboardData: forwarded, bubbles: true, cancelable: true })
|
|
210
|
+
);
|
|
211
|
+
} finally {
|
|
212
|
+
forwarding = false;
|
|
213
|
+
}
|
|
214
|
+
changed();
|
|
215
|
+
}
|
|
216
|
+
$effect(() => {
|
|
217
|
+
if (!host) return;
|
|
218
|
+
const element = host;
|
|
219
|
+
element.addEventListener('paste', pasted, true);
|
|
220
|
+
element.addEventListener('keydown', leaveBody);
|
|
221
|
+
return () => {
|
|
222
|
+
element.removeEventListener('paste', pasted, true);
|
|
223
|
+
element.removeEventListener('keydown', leaveBody);
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const field =
|
|
228
|
+
'block w-full resize-none overflow-hidden border-0 bg-transparent p-0 placeholder:text-base-400 focus:ring-0 focus:outline-none dark:placeholder:text-base-600';
|
|
229
|
+
</script>
|
|
230
|
+
|
|
231
|
+
<div class={cn('w-full', className)}>
|
|
232
|
+
<div class="flex items-center gap-1">
|
|
233
|
+
<div class="mr-auto min-w-0">{@render leading?.()}</div>
|
|
234
|
+
{#if status}
|
|
235
|
+
<span class="mr-2 text-xs text-base-500 max-sm:hidden" aria-live="polite">{status}</span>
|
|
236
|
+
{/if}
|
|
237
|
+
{#if images}
|
|
238
|
+
<input
|
|
239
|
+
bind:this={picker}
|
|
240
|
+
type="file"
|
|
241
|
+
accept="image/*"
|
|
242
|
+
multiple
|
|
243
|
+
class="hidden"
|
|
244
|
+
onchange={() => {
|
|
245
|
+
if (picker?.files?.length) void insertImages(Array.from(picker.files));
|
|
246
|
+
if (picker) picker.value = '';
|
|
247
|
+
}}
|
|
248
|
+
/>
|
|
249
|
+
<input
|
|
250
|
+
bind:this={coverPicker}
|
|
251
|
+
type="file"
|
|
252
|
+
accept="image/*"
|
|
253
|
+
class="hidden"
|
|
254
|
+
onchange={pickCover}
|
|
255
|
+
/>
|
|
256
|
+
<IconButton label="Add image" variant="ghost" {disabled} onclick={() => picker?.click()}>
|
|
257
|
+
<Icon img={ImagePlus} size={20} />
|
|
258
|
+
</IconButton>
|
|
259
|
+
{/if}
|
|
260
|
+
{@render actions?.()}
|
|
261
|
+
</div>
|
|
262
|
+
{#if error || problem}
|
|
263
|
+
<p role="alert" class="mt-3 text-sm text-red-700 dark:text-red-400">{error || problem}</p>
|
|
264
|
+
{/if}
|
|
265
|
+
|
|
266
|
+
<div class="mt-8">
|
|
267
|
+
{#if cover}
|
|
268
|
+
<div class="relative mb-8">
|
|
269
|
+
<img src={src(cover)} alt="" class="w-full rounded-xl" />
|
|
270
|
+
<div class="absolute top-2 right-2 flex gap-1">
|
|
271
|
+
{#if images}
|
|
272
|
+
<Button variant="secondary" size="sm" {disabled} onclick={() => coverPicker?.click()}>
|
|
273
|
+
Change
|
|
274
|
+
</Button>
|
|
275
|
+
{/if}
|
|
276
|
+
<Button
|
|
277
|
+
variant="secondary"
|
|
278
|
+
size="sm"
|
|
279
|
+
{disabled}
|
|
280
|
+
onclick={() => {
|
|
281
|
+
cover = undefined;
|
|
282
|
+
changed();
|
|
283
|
+
}}>Remove</Button
|
|
284
|
+
>
|
|
285
|
+
</div>
|
|
286
|
+
</div>
|
|
287
|
+
{:else if images}
|
|
288
|
+
<Button
|
|
289
|
+
variant="ghost"
|
|
290
|
+
size="sm"
|
|
291
|
+
class="mb-3 -ml-3"
|
|
292
|
+
{disabled}
|
|
293
|
+
onclick={() => coverPicker?.click()}
|
|
294
|
+
>
|
|
295
|
+
<Icon img={ImagePlus} size={16} />Add cover
|
|
296
|
+
</Button>
|
|
297
|
+
{/if}
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
<textarea
|
|
301
|
+
bind:this={titleField}
|
|
302
|
+
bind:value={title}
|
|
303
|
+
rows="1"
|
|
304
|
+
maxlength={ARTICLE_LIMITS.title}
|
|
305
|
+
placeholder="Title"
|
|
306
|
+
aria-label="Title"
|
|
307
|
+
{disabled}
|
|
308
|
+
oninput={changed}
|
|
309
|
+
onkeydown={(event) => move(event, () => focusEnd(descriptionField))}
|
|
310
|
+
class="{field} text-4xl leading-tight font-semibold tracking-tight sm:text-5xl"></textarea>
|
|
311
|
+
<textarea
|
|
312
|
+
bind:this={descriptionField}
|
|
313
|
+
bind:value={description}
|
|
314
|
+
rows="1"
|
|
315
|
+
maxlength={ARTICLE_LIMITS.description}
|
|
316
|
+
placeholder="Description (optional)"
|
|
317
|
+
aria-label="Description"
|
|
318
|
+
{disabled}
|
|
319
|
+
oninput={changed}
|
|
320
|
+
onkeydown={(event) => move(event, focusBody, () => focusEnd(titleField))}
|
|
321
|
+
class="{field} mt-4 text-xl text-base-600 dark:text-base-400"></textarea>
|
|
322
|
+
|
|
323
|
+
<div bind:this={host} class="mt-8">
|
|
324
|
+
<RichTextEditor
|
|
325
|
+
bind:this={editor}
|
|
326
|
+
bind:editor={body}
|
|
327
|
+
bind:value={text}
|
|
328
|
+
label="Text"
|
|
329
|
+
menus
|
|
330
|
+
{placeholder}
|
|
331
|
+
markdown="article"
|
|
332
|
+
{embeds}
|
|
333
|
+
images={images ? { upload, src: images.src } : undefined}
|
|
334
|
+
{searchActors}
|
|
335
|
+
{disabled}
|
|
336
|
+
onupdate={changed}
|
|
337
|
+
class="focus-within:outline-0 {articleEditorClass}"
|
|
338
|
+
/>
|
|
339
|
+
</div>
|
|
340
|
+
</div>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { ActorSearch } from '../components/login/types.js';
|
|
3
|
+
import type { LinkEmbed } from '../embeds/types.js';
|
|
4
|
+
/** How the images of an article being written are stored and loaded. */
|
|
5
|
+
export type ArticleEditorImages = {
|
|
6
|
+
/**
|
|
7
|
+
* Store a pasted, dropped or picked file and return the destination to write: a URL, or
|
|
8
|
+
* the app's own reference such as `local:1`. `kind` tells a cover from an image in the
|
|
9
|
+
* text. Throw an `Error` to show its message.
|
|
10
|
+
*/
|
|
11
|
+
upload: (file: File, kind: 'image' | 'cover') => Promise<string>;
|
|
12
|
+
/** The address to load a destination from, for those that are not HTTP(S). */
|
|
13
|
+
src?: (url: string) => string | undefined;
|
|
14
|
+
};
|
|
15
|
+
export type ArticleEditorProps = {
|
|
16
|
+
title?: string;
|
|
17
|
+
/** Empty for the automatic one. */
|
|
18
|
+
description?: string;
|
|
19
|
+
/** Article Markdown. */
|
|
20
|
+
text?: string;
|
|
21
|
+
/** Destination of the cover image, as `images.upload` returned it. */
|
|
22
|
+
cover?: string;
|
|
23
|
+
/** Without it, images and a cover cannot be added. */
|
|
24
|
+
images?: ArticleEditorImages;
|
|
25
|
+
/** After any edit by the author. */
|
|
26
|
+
onchange?: () => void;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/** Bare links on their own line as embeds: the app's, a list, or none. */
|
|
29
|
+
embeds?: boolean | readonly LinkEmbed[];
|
|
30
|
+
/** Enables @-mention suggestions. */
|
|
31
|
+
searchActors?: ActorSearch;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
/** A short note in the toolbar, such as "Saved in this browser". */
|
|
34
|
+
status?: string;
|
|
35
|
+
/** Shown under the toolbar. */
|
|
36
|
+
error?: string;
|
|
37
|
+
/** Start of the toolbar, e.g. which publication the article goes into. */
|
|
38
|
+
leading?: Snippet;
|
|
39
|
+
/** End of the toolbar, e.g. Publish. */
|
|
40
|
+
actions?: Snippet;
|
|
41
|
+
class?: string;
|
|
42
|
+
};
|
|
43
|
+
declare const ArticleEditor: import("svelte").Component<ArticleEditorProps, {
|
|
44
|
+
insertImages: (files: File[]) => Promise<void> | undefined;
|
|
45
|
+
focusTitle: () => void;
|
|
46
|
+
}, "text" | "title" | "description" | "cover">;
|
|
47
|
+
type ArticleEditor = ReturnType<typeof ArticleEditor>;
|
|
48
|
+
export default ArticleEditor;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Surface from '../components/Surface.svelte';
|
|
3
|
+
import type { LinkEmbedProps } from '../embeds/types.js';
|
|
4
|
+
import { getCDNImageBlobUrl } from '../events/atproto-helpers.js';
|
|
5
|
+
import ArticleCard from './ArticleCard.svelte';
|
|
6
|
+
import {
|
|
7
|
+
loadLinkedArticle,
|
|
8
|
+
type ArticleLinkEmbedRef,
|
|
9
|
+
type LinkedArticle
|
|
10
|
+
} from './article-link-embed.js';
|
|
11
|
+
|
|
12
|
+
let { url, ref, data, fallback }: LinkEmbedProps<ArticleLinkEmbedRef, LinkedArticle> = $props();
|
|
13
|
+
|
|
14
|
+
let found = $state<{ url: string; linked: LinkedArticle | null }>();
|
|
15
|
+
let linked = $derived(data !== undefined ? data : found?.url === url ? found.linked : null);
|
|
16
|
+
$effect(() => {
|
|
17
|
+
if (data !== undefined) return;
|
|
18
|
+
const link = url;
|
|
19
|
+
let current = true;
|
|
20
|
+
void loadLinkedArticle(ref)
|
|
21
|
+
.then((result) => {
|
|
22
|
+
if (current) found = { url: link, linked: result };
|
|
23
|
+
})
|
|
24
|
+
.catch(() => {});
|
|
25
|
+
return () => {
|
|
26
|
+
current = false;
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const coverOf = ({ did, article }: LinkedArticle) =>
|
|
31
|
+
article.cover
|
|
32
|
+
? ref.cover
|
|
33
|
+
? ref.cover(did, article.cover)
|
|
34
|
+
: getCDNImageBlobUrl({ did, blob: { $type: 'blob', ref: { $link: article.cover } } })
|
|
35
|
+
: undefined;
|
|
36
|
+
let by = $derived([linked?.author, linked?.publication].filter(Boolean).join(' · '));
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
{#if linked}
|
|
40
|
+
<Surface class="max-w-sm p-4">
|
|
41
|
+
<ArticleCard
|
|
42
|
+
article={linked.article}
|
|
43
|
+
href={linked.article.url ?? (ref.local ? ref.path : url)}
|
|
44
|
+
external={!!linked.article.url}
|
|
45
|
+
cover={coverOf(linked)}
|
|
46
|
+
>
|
|
47
|
+
{#snippet byline()}{#if by}<span>{by}</span>{/if}{/snippet}
|
|
48
|
+
</ArticleCard>
|
|
49
|
+
</Surface>
|
|
50
|
+
{:else}{@render fallback()}{/if}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LinkEmbedProps } from '../embeds/types.js';
|
|
2
|
+
import { type ArticleLinkEmbedRef, type LinkedArticle } from './article-link-embed.js';
|
|
3
|
+
declare const ArticleLinkEmbed: import("svelte").Component<LinkEmbedProps<ArticleLinkEmbedRef, LinkedArticle>, {}, "">;
|
|
4
|
+
type ArticleLinkEmbed = ReturnType<typeof ArticleLinkEmbed>;
|
|
5
|
+
export default ArticleLinkEmbed;
|