@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
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
active?: boolean;
|
|
8
8
|
primary?: boolean;
|
|
9
9
|
badge?: boolean | number;
|
|
10
|
+
/** For this item alone, e.g. `max-sm:hidden` to leave it out of the mobile bar. */
|
|
11
|
+
class?: string;
|
|
10
12
|
};
|
|
11
13
|
</script>
|
|
12
14
|
|
|
@@ -91,7 +93,8 @@
|
|
|
91
93
|
item.primary && 'mt-3',
|
|
92
94
|
item.primary &&
|
|
93
95
|
(!item.variant || item.variant === 'ghost') &&
|
|
94
|
-
'text-accent-700 dark:text-accent-300'
|
|
96
|
+
'text-accent-700 dark:text-accent-300',
|
|
97
|
+
item.class
|
|
95
98
|
)}
|
|
96
99
|
>
|
|
97
100
|
<Icon img={item.icon} size={22} />
|
|
@@ -122,9 +125,8 @@
|
|
|
122
125
|
className
|
|
123
126
|
)}
|
|
124
127
|
>
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
>
|
|
128
|
+
<!-- In the mobile bar the items and the footer are spaced as one row. -->
|
|
129
|
+
<div class="flex flex-col items-center gap-3 max-sm:contents">
|
|
128
130
|
{#each items as item (item.label)}
|
|
129
131
|
<Tooltip.Root disabled={item.disabled ?? false}
|
|
130
132
|
><Tooltip.Trigger onclick={item.onclick}
|
|
@@ -148,7 +150,8 @@
|
|
|
148
150
|
'text-accent-700 hover:text-accent-700 dark:text-accent-300 dark:hover:text-accent-300',
|
|
149
151
|
backed &&
|
|
150
152
|
(!item.variant || item.variant === 'ghost') &&
|
|
151
|
-
'bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))]/45 hover:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))]/75 dark:bg-base-950/45 dark:hover:bg-base-950/75'
|
|
153
|
+
'bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))]/45 hover:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))]/75 dark:bg-base-950/45 dark:hover:bg-base-950/75',
|
|
154
|
+
item.class
|
|
152
155
|
)}
|
|
153
156
|
>
|
|
154
157
|
<Icon img={item.icon} size={22} />{#if item.badge}<span
|
|
@@ -168,7 +171,7 @@
|
|
|
168
171
|
>
|
|
169
172
|
{/each}
|
|
170
173
|
</div>
|
|
171
|
-
{#if footer}<div class="mt-auto max-sm:mt-0
|
|
174
|
+
{#if footer}<div class="mt-auto max-sm:mt-0">
|
|
172
175
|
{@render footer({ expanded: false, close })}
|
|
173
176
|
</div>{/if}
|
|
174
177
|
</nav>
|
|
@@ -6,6 +6,8 @@ export type IconRailItem = Pick<ButtonProps, 'href' | 'onclick' | 'disabled' | '
|
|
|
6
6
|
active?: boolean;
|
|
7
7
|
primary?: boolean;
|
|
8
8
|
badge?: boolean | number;
|
|
9
|
+
/** For this item alone, e.g. `max-sm:hidden` to leave it out of the mobile bar. */
|
|
10
|
+
class?: string;
|
|
9
11
|
};
|
|
10
12
|
import { type Snippet } from 'svelte';
|
|
11
13
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import type { Component } from 'svelte';
|
|
3
|
-
// Not imported as `LinkEmbed`: the generated types would give that name to the import
|
|
4
|
-
// instead of this component, leaving consumers with a type-only export.
|
|
5
|
-
import type { LinkEmbed as Definition, LinkEmbedProps } from '../embeds/types.js';
|
|
6
|
-
|
|
7
|
-
// Loaded components are kept, so later embeds of the same kind render without a flash.
|
|
8
|
-
const loaded = new WeakMap<Definition, Component<LinkEmbedProps>>();
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
1
|
<script lang="ts">
|
|
12
|
-
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { Component, Snippet } from 'svelte';
|
|
13
3
|
import { linkEmbedOptions, selectLinkEmbeds } from '../embeds/context.js';
|
|
14
4
|
import { isClickToLoad, resolveLinkEmbed } from '../embeds/resolve.js';
|
|
15
|
-
import
|
|
5
|
+
import { loadLinkEmbed, loadedLinkEmbed } from '../embeds/load.js';
|
|
6
|
+
// Not imported as `LinkEmbed`: the generated types would give that name to the import
|
|
7
|
+
// instead of this component, leaving consumers with a type-only export.
|
|
8
|
+
import type {
|
|
9
|
+
LinkEmbed as Definition,
|
|
10
|
+
LinkEmbedOptions,
|
|
11
|
+
LinkEmbedProps
|
|
12
|
+
} from '../embeds/types.js';
|
|
16
13
|
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
17
14
|
import { safeHttpUrl } from '../urls.js';
|
|
18
15
|
import Button from './Button.svelte';
|
|
19
16
|
|
|
20
17
|
export type LinkEmbedComponentProps = LinkEmbedOptions & {
|
|
21
18
|
url: string;
|
|
19
|
+
/** What the embed's `data` loaded ahead; see `loadLinkEmbedData`. */
|
|
20
|
+
data?: unknown;
|
|
22
21
|
/** Shown until the content has loaded and whenever it can't be shown. Defaults to a link. */
|
|
23
22
|
fallback?: Snippet;
|
|
24
23
|
socialClient?: PreferredSocialClient | null;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
let { url, embeds, clickToLoad, fallback, socialClient }: LinkEmbedComponentProps =
|
|
26
|
+
let { url, data, embeds, clickToLoad, fallback, socialClient }: LinkEmbedComponentProps =
|
|
27
|
+
$props();
|
|
28
28
|
|
|
29
29
|
const context = linkEmbedOptions();
|
|
30
30
|
let match = $derived(resolveLinkEmbed(url, embeds ?? selectLinkEmbeds(true, context())));
|
|
31
31
|
let gated = $derived(!!match && isClickToLoad(match.embed, clickToLoad ?? context().clickToLoad));
|
|
32
32
|
// Consent belongs to this link, not to its position on the page.
|
|
33
33
|
let accepted = $state<string>();
|
|
34
|
-
let
|
|
34
|
+
let arrived = $state.raw<{ embed: Definition; component: Component<LinkEmbedProps> }>();
|
|
35
|
+
// Known without waiting when it was loaded before, also on the server.
|
|
36
|
+
let component = $derived(
|
|
37
|
+
match &&
|
|
38
|
+
(loadedLinkEmbed(match.embed) ??
|
|
39
|
+
(arrived?.embed === match.embed ? arrived.component : undefined))
|
|
40
|
+
);
|
|
35
41
|
$effect(() => {
|
|
36
42
|
const embed = match?.embed;
|
|
37
|
-
component = embed && loaded.get(embed);
|
|
38
43
|
if (!embed || component || (gated && accepted !== match?.url)) return;
|
|
39
44
|
let current = true;
|
|
40
|
-
embed
|
|
41
|
-
.
|
|
42
|
-
|
|
43
|
-
loaded.set(embed, module.default);
|
|
44
|
-
if (current) component = module.default;
|
|
45
|
+
loadLinkEmbed(embed)
|
|
46
|
+
.then((loaded) => {
|
|
47
|
+
if (current) arrived = { embed, component: loaded };
|
|
45
48
|
})
|
|
46
49
|
.catch(() => {});
|
|
47
50
|
return () => {
|
|
@@ -71,5 +74,5 @@
|
|
|
71
74
|
>
|
|
72
75
|
{:else if match && component}
|
|
73
76
|
{@const Embed = component}
|
|
74
|
-
<Embed url={match.url} ref={match.ref} fallback={link} {socialClient} />
|
|
77
|
+
<Embed url={match.url} ref={match.ref} {data} fallback={link} {socialClient} />
|
|
75
78
|
{:else}{@render link()}{/if}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { Component } from 'svelte';
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
1
|
+
import type { Component, Snippet } from 'svelte';
|
|
3
2
|
import type { LinkEmbedOptions } from '../embeds/types.js';
|
|
4
3
|
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
5
4
|
export type LinkEmbedComponentProps = LinkEmbedOptions & {
|
|
6
5
|
url: string;
|
|
6
|
+
/** What the embed's `data` loaded ahead; see `loadLinkEmbedData`. */
|
|
7
|
+
data?: unknown;
|
|
7
8
|
/** Shown until the content has loaded and whenever it can't be shown. Defaults to a link. */
|
|
8
9
|
fallback?: Snippet;
|
|
9
10
|
socialClient?: PreferredSocialClient | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { accentColors, baseColors, isAccentColor, isBaseColor } from '../palettes.js';
|
|
3
|
+
|
|
4
|
+
// Gives the whole document a palette, e.g. the colors a publication or an event chose, for
|
|
5
|
+
// as long as it is mounted. Dialogs and other portaled content follow, as they are in the
|
|
6
|
+
// document too. Light and dark stay the app's.
|
|
7
|
+
let {
|
|
8
|
+
accent,
|
|
9
|
+
base
|
|
10
|
+
}: {
|
|
11
|
+
/** One of `accentColors`; anything else leaves the document's accent as it is. */
|
|
12
|
+
accent?: string;
|
|
13
|
+
/** One of `baseColors`; anything else leaves the document's base as it is. */
|
|
14
|
+
base?: string;
|
|
15
|
+
} = $props();
|
|
16
|
+
|
|
17
|
+
let chosen = $derived({
|
|
18
|
+
accent: isAccentColor(accent) ? accent : undefined,
|
|
19
|
+
base: isBaseColor(base) ? base : undefined
|
|
20
|
+
});
|
|
21
|
+
const all = [...accentColors, ...baseColors];
|
|
22
|
+
/** Where the document's own palette is noted before the first change, to go back to. */
|
|
23
|
+
const OWN = 'data-atmo-own-palette';
|
|
24
|
+
// Runs before the page is drawn, so that a page from the server does not flash the app's
|
|
25
|
+
// own colors first. The names come only from the kit's palettes, never from the props as text.
|
|
26
|
+
let script = $derived(
|
|
27
|
+
chosen.accent || chosen.base
|
|
28
|
+
? `<script>(function(){var e=document.documentElement,c=e.classList;if(!e.hasAttribute(${JSON.stringify(OWN)}))e.setAttribute(${JSON.stringify(OWN)},${JSON.stringify(all)}.filter(function(n){return c.contains(n)}).join(" "));${
|
|
29
|
+
chosen.accent
|
|
30
|
+
? `${JSON.stringify(accentColors)}.forEach(function(n){c.remove(n)});c.add(${JSON.stringify(chosen.accent)});`
|
|
31
|
+
: ''
|
|
32
|
+
}${
|
|
33
|
+
chosen.base
|
|
34
|
+
? `${JSON.stringify(baseColors)}.forEach(function(n){c.remove(n)});c.add(${JSON.stringify(chosen.base)});`
|
|
35
|
+
: ''
|
|
36
|
+
}})()<` + '/script>'
|
|
37
|
+
: ''
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
$effect(() => {
|
|
41
|
+
const root = document.documentElement;
|
|
42
|
+
const classes = root.classList;
|
|
43
|
+
if (!root.hasAttribute(OWN))
|
|
44
|
+
root.setAttribute(OWN, all.filter((name) => classes.contains(name)).join(' '));
|
|
45
|
+
const own = (root.getAttribute(OWN) ?? '').split(' ');
|
|
46
|
+
const set = (names: readonly string[], wanted?: string) => {
|
|
47
|
+
classes.remove(...names);
|
|
48
|
+
classes.add(...(wanted ? [wanted] : own.filter((name) => names.includes(name))));
|
|
49
|
+
};
|
|
50
|
+
set(accentColors, chosen.accent);
|
|
51
|
+
set(baseColors, chosen.base);
|
|
52
|
+
return () => {
|
|
53
|
+
set(accentColors);
|
|
54
|
+
set(baseColors);
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<svelte:head>
|
|
60
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- names from the kit's own palettes -->
|
|
61
|
+
{@html script}
|
|
62
|
+
</svelte:head>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type $$ComponentProps = {
|
|
2
|
+
/** One of `accentColors`; anything else leaves the document's accent as it is. */
|
|
3
|
+
accent?: string;
|
|
4
|
+
/** One of `baseColors`; anything else leaves the document's base as it is. */
|
|
5
|
+
base?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const PaletteApply: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type PaletteApply = ReturnType<typeof PaletteApply>;
|
|
9
|
+
export default PaletteApply;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { accentColors, baseColors, type AccentColor, type BaseColor } from '../palettes.js';
|
|
3
|
+
import { cn } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
// Choosing an accent and a base color from the kit's palettes.
|
|
6
|
+
let {
|
|
7
|
+
accent = $bindable('pink'),
|
|
8
|
+
base = $bindable('zinc'),
|
|
9
|
+
onchange,
|
|
10
|
+
class: className
|
|
11
|
+
}: {
|
|
12
|
+
accent?: AccentColor;
|
|
13
|
+
base?: BaseColor;
|
|
14
|
+
onchange?: (palette: { accent: AccentColor; base: BaseColor }) => void;
|
|
15
|
+
class?: string;
|
|
16
|
+
} = $props();
|
|
17
|
+
|
|
18
|
+
// Written out in full so that Tailwind finds them.
|
|
19
|
+
const accentClass: Record<AccentColor, string> = {
|
|
20
|
+
red: 'bg-red-500',
|
|
21
|
+
orange: 'bg-orange-500',
|
|
22
|
+
amber: 'bg-amber-500',
|
|
23
|
+
yellow: 'bg-yellow-500',
|
|
24
|
+
lime: 'bg-lime-500',
|
|
25
|
+
green: 'bg-green-500',
|
|
26
|
+
emerald: 'bg-emerald-500',
|
|
27
|
+
teal: 'bg-teal-500',
|
|
28
|
+
cyan: 'bg-cyan-500',
|
|
29
|
+
sky: 'bg-sky-500',
|
|
30
|
+
blue: 'bg-blue-500',
|
|
31
|
+
indigo: 'bg-indigo-500',
|
|
32
|
+
violet: 'bg-violet-500',
|
|
33
|
+
purple: 'bg-purple-500',
|
|
34
|
+
fuchsia: 'bg-fuchsia-500',
|
|
35
|
+
pink: 'bg-pink-500',
|
|
36
|
+
rose: 'bg-rose-500'
|
|
37
|
+
};
|
|
38
|
+
const baseClass: Record<BaseColor, string> = {
|
|
39
|
+
gray: 'bg-gray-500',
|
|
40
|
+
zinc: 'bg-zinc-500',
|
|
41
|
+
neutral: 'bg-neutral-500',
|
|
42
|
+
stone: 'bg-stone-500',
|
|
43
|
+
slate: 'bg-slate-500',
|
|
44
|
+
mist: 'bg-mist-500',
|
|
45
|
+
mauve: 'bg-mauve-500',
|
|
46
|
+
olive: 'bg-olive-500',
|
|
47
|
+
taupe: 'bg-taupe-500'
|
|
48
|
+
};
|
|
49
|
+
const swatch =
|
|
50
|
+
'size-7 cursor-pointer rounded-full outline-none transition-shadow duration-(--atmo-duration) motion-reduce:transition-none hover:ring-2 hover:ring-base-400 hover:ring-offset-2 hover:ring-offset-base-50 focus-visible:ring-2 focus-visible:ring-accent-700 focus-visible:ring-offset-2 focus-visible:ring-offset-base-50 aria-pressed:ring-2 aria-pressed:ring-base-950 aria-pressed:ring-offset-2 aria-pressed:ring-offset-base-50 dark:hover:ring-base-600 dark:hover:ring-offset-base-925 dark:focus-visible:ring-accent-300 dark:focus-visible:ring-offset-base-925 dark:aria-pressed:ring-base-50 dark:aria-pressed:ring-offset-base-925';
|
|
51
|
+
const legend = 'mb-2.5 text-sm font-medium text-base-950 dark:text-base-50';
|
|
52
|
+
const name = (color: string) => color[0].toUpperCase() + color.slice(1);
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<div class={cn('grid gap-5', className)} data-slot="palette-picker">
|
|
56
|
+
<fieldset>
|
|
57
|
+
<legend class={legend}>Accent color</legend>
|
|
58
|
+
<div class="flex flex-wrap gap-2.5">
|
|
59
|
+
{#each accentColors as color (color)}
|
|
60
|
+
<button
|
|
61
|
+
type="button"
|
|
62
|
+
aria-label={name(color)}
|
|
63
|
+
title={name(color)}
|
|
64
|
+
aria-pressed={accent === color}
|
|
65
|
+
class={[swatch, accentClass[color]]}
|
|
66
|
+
onclick={() => {
|
|
67
|
+
accent = color;
|
|
68
|
+
onchange?.({ accent, base });
|
|
69
|
+
}}
|
|
70
|
+
></button>
|
|
71
|
+
{/each}
|
|
72
|
+
</div>
|
|
73
|
+
</fieldset>
|
|
74
|
+
<fieldset>
|
|
75
|
+
<legend class={legend}>Base color</legend>
|
|
76
|
+
<div class="flex flex-wrap gap-2.5">
|
|
77
|
+
{#each baseColors as color (color)}
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
aria-label={name(color)}
|
|
81
|
+
title={name(color)}
|
|
82
|
+
aria-pressed={base === color}
|
|
83
|
+
class={[swatch, baseClass[color]]}
|
|
84
|
+
onclick={() => {
|
|
85
|
+
base = color;
|
|
86
|
+
onchange?.({ accent, base });
|
|
87
|
+
}}
|
|
88
|
+
></button>
|
|
89
|
+
{/each}
|
|
90
|
+
</div>
|
|
91
|
+
</fieldset>
|
|
92
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type AccentColor, type BaseColor } from '../palettes.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
accent?: AccentColor;
|
|
4
|
+
base?: BaseColor;
|
|
5
|
+
onchange?: (palette: {
|
|
6
|
+
accent: AccentColor;
|
|
7
|
+
base: BaseColor;
|
|
8
|
+
}) => void;
|
|
9
|
+
class?: string;
|
|
10
|
+
};
|
|
11
|
+
declare const PalettePicker: import("svelte").Component<$$ComponentProps, {}, "accent" | "base">;
|
|
12
|
+
type PalettePicker = ReturnType<typeof PalettePicker>;
|
|
13
|
+
export default PalettePicker;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { appviewUrl } from '../events/atproto-helpers.js';
|
|
3
|
+
import { blueskyPostToPostData, hasModerationLabel, type PostData } from '../social/posts.js';
|
|
4
|
+
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
5
|
+
import { socialClientInfo } from '../social/preferred-client.js';
|
|
6
|
+
import { socialPostUrl } from '../social/urls.js';
|
|
7
|
+
import Button from './Button.svelte';
|
|
8
|
+
import NestedComments from './NestedComments.svelte';
|
|
9
|
+
|
|
10
|
+
// The replies to a Bluesky post, shown as the comments of whatever that post announces.
|
|
11
|
+
let {
|
|
12
|
+
postUri,
|
|
13
|
+
socialClient,
|
|
14
|
+
oncomment,
|
|
15
|
+
refresh
|
|
16
|
+
}: {
|
|
17
|
+
postUri: string;
|
|
18
|
+
socialClient?: PreferredSocialClient | null;
|
|
19
|
+
/**
|
|
20
|
+
* Write a comment here, e.g. by opening a composer. Without it, commenting is a link to
|
|
21
|
+
* the post in the viewer's client.
|
|
22
|
+
*/
|
|
23
|
+
oncomment?: () => void;
|
|
24
|
+
/** Load the thread again whenever this changes, e.g. after the viewer commented. */
|
|
25
|
+
refresh?: unknown;
|
|
26
|
+
} = $props();
|
|
27
|
+
|
|
28
|
+
let comments = $state<PostData[]>([]);
|
|
29
|
+
let loading = $state(true);
|
|
30
|
+
let errorMessage = $state<string | null>(null);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Comments are shown to everyone without their moderation preferences, so a reply that carries
|
|
34
|
+
* a moderation label (itself, its author, or a post it quotes) is left out, with the replies
|
|
35
|
+
* beneath it.
|
|
36
|
+
*/
|
|
37
|
+
const DEPTH = 6;
|
|
38
|
+
function threadToComments(replies: unknown[], level = 1): PostData[] {
|
|
39
|
+
return (replies as Array<{ $type?: string; post?: unknown; replies?: unknown[] }>)
|
|
40
|
+
.filter(
|
|
41
|
+
(r) =>
|
|
42
|
+
r.$type === 'app.bsky.feed.defs#threadViewPost' && r.post && !hasModerationLabel(r.post)
|
|
43
|
+
)
|
|
44
|
+
.map((r) => {
|
|
45
|
+
const postData = blueskyPostToPostData(
|
|
46
|
+
r.post as Parameters<typeof blueskyPostToPostData>[0]
|
|
47
|
+
);
|
|
48
|
+
// Below the requested depth nothing was loaded; the comment links to the rest instead.
|
|
49
|
+
if (level < DEPTH) postData.replies = threadToComments(r.replies ?? [], level + 1);
|
|
50
|
+
return postData;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function loadThread(uri: string, signal: AbortSignal, quiet: boolean) {
|
|
55
|
+
// Loading again keeps the comments on screen until the new ones arrive.
|
|
56
|
+
if (!quiet) loading = true;
|
|
57
|
+
errorMessage = null;
|
|
58
|
+
try {
|
|
59
|
+
const res = await fetch(
|
|
60
|
+
`${appviewUrl()}/xrpc/app.bsky.feed.getPostThread?uri=${encodeURIComponent(uri)}&depth=${DEPTH}`,
|
|
61
|
+
{ signal }
|
|
62
|
+
);
|
|
63
|
+
if (!res.ok) throw new Error(`Failed to load thread (${res.status})`);
|
|
64
|
+
const data = (await res.json()) as { thread?: { replies?: unknown[] } };
|
|
65
|
+
const thread = data.thread;
|
|
66
|
+
if (!signal.aborted)
|
|
67
|
+
comments = thread?.replies?.length ? threadToComments(thread.replies) : [];
|
|
68
|
+
} catch (err) {
|
|
69
|
+
if (signal.aborted) return;
|
|
70
|
+
console.error('PostComments: load failed', err);
|
|
71
|
+
errorMessage = err instanceof Error ? err.message : 'Failed to load comments';
|
|
72
|
+
comments = [];
|
|
73
|
+
} finally {
|
|
74
|
+
if (!signal.aborted) loading = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Only a new thread or `refresh` should refetch; changing the viewer's client just changes links.
|
|
79
|
+
let threadUri = $derived(postUri);
|
|
80
|
+
let loaded = '';
|
|
81
|
+
$effect(() => {
|
|
82
|
+
void refresh;
|
|
83
|
+
const uri = threadUri;
|
|
84
|
+
const controller = new AbortController();
|
|
85
|
+
if (uri) void loadThread(uri, controller.signal, loaded === uri);
|
|
86
|
+
loaded = uri;
|
|
87
|
+
return () => controller.abort();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
let replyUrl = $derived(socialPostUrl(postUri, socialClient));
|
|
91
|
+
let clientLabel = $derived(socialClientInfo(socialClient).label);
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<div>
|
|
95
|
+
{#if oncomment}
|
|
96
|
+
<div class="mb-4">
|
|
97
|
+
<Button variant="secondary" size="sm" onclick={oncomment}>Add a comment</Button>
|
|
98
|
+
</div>
|
|
99
|
+
{:else if replyUrl}
|
|
100
|
+
<div class="mb-4 text-sm">
|
|
101
|
+
<a
|
|
102
|
+
href={replyUrl}
|
|
103
|
+
target="_blank"
|
|
104
|
+
rel="noopener noreferrer"
|
|
105
|
+
class="font-medium text-accent-600 hover:text-accent-700 dark:text-accent-400 dark:hover:text-accent-300"
|
|
106
|
+
>
|
|
107
|
+
Add a comment on {clientLabel} →
|
|
108
|
+
</a>
|
|
109
|
+
</div>
|
|
110
|
+
{/if}
|
|
111
|
+
|
|
112
|
+
{#if loading}
|
|
113
|
+
<p class="text-sm text-base-600 dark:text-base-400">Loading comments…</p>
|
|
114
|
+
{:else if errorMessage}
|
|
115
|
+
<p class="text-sm text-base-600 dark:text-base-400">{errorMessage}</p>
|
|
116
|
+
{:else if comments.length === 0}
|
|
117
|
+
<p class="text-sm text-base-600 dark:text-base-400">No comments yet.</p>
|
|
118
|
+
{:else}
|
|
119
|
+
<div class="not-prose comments-no-divider">
|
|
120
|
+
<NestedComments {comments} {socialClient} />
|
|
121
|
+
</div>
|
|
122
|
+
{/if}
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<style>
|
|
126
|
+
.comments-no-divider :global(> div) {
|
|
127
|
+
border-top-width: 0;
|
|
128
|
+
}
|
|
129
|
+
</style>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PreferredSocialClient } from '../social/preferred-client.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
postUri: string;
|
|
4
|
+
socialClient?: PreferredSocialClient | null;
|
|
5
|
+
/**
|
|
6
|
+
* Write a comment here, e.g. by opening a composer. Without it, commenting is a link to
|
|
7
|
+
* the post in the viewer's client.
|
|
8
|
+
*/
|
|
9
|
+
oncomment?: () => void;
|
|
10
|
+
/** Load the thread again whenever this changes, e.g. after the viewer commented. */
|
|
11
|
+
refresh?: unknown;
|
|
12
|
+
};
|
|
13
|
+
declare const PostComments: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
14
|
+
type PostComments = ReturnType<typeof PostComments>;
|
|
15
|
+
export default PostComments;
|